diff --git a/main/admin/user_fields.php b/main/admin/user_fields.php index f0d02efa33..bb5bb89554 100644 --- a/main/admin/user_fields.php +++ b/main/admin/user_fields.php @@ -67,7 +67,7 @@ if(1) case 'show_field' : if (api_is_platform_admin() && !empty($_GET['field_id']) && UserManager :: update_extra_field($_GET['field_id'],array('field_visible'=>'1'))) { - Display :: display_normal_message(get_lang('FieldShown')); + Display :: display_confirmation_message(get_lang('FieldShown')); } else { @@ -77,7 +77,7 @@ if(1) case 'hide_field' : if (api_is_platform_admin() && !empty($_GET['field_id']) && UserManager :: update_extra_field($_GET['field_id'],array('field_visible'=>'0'))) { - Display :: display_normal_message(get_lang('FieldHidden')); + Display :: display_confirmation_message(get_lang('FieldHidden')); } else { @@ -87,7 +87,7 @@ if(1) case 'thaw_field' : if (api_is_platform_admin() && !empty($_GET['field_id']) && UserManager :: update_extra_field($_GET['field_id'],array('field_changeable'=>'1'))) { - Display :: display_normal_message(get_lang('FieldMadeChangeable')); + Display :: display_confirmation_message(get_lang('FieldMadeChangeable')); } else { @@ -97,13 +97,36 @@ if(1) case 'freeze_field' : if (api_is_platform_admin() && !empty($_GET['field_id']) && UserManager :: update_extra_field($_GET['field_id'],array('field_changeable'=>'0'))) { - Display :: display_normal_message(get_lang('FieldMadeUnchangeable')); + Display :: display_confirmation_message(get_lang('FieldMadeUnchangeable')); } else { Display :: display_error_message(get_lang('CannotMakeFieldUnchangeable')); } break; + case 'moveup' : + if (api_is_platform_admin() && !empty($_GET['field_id'])) + { + if (move_user_field('moveup', $_GET['field_id'])) + { + Display :: display_confirmation_message(get_lang('FieldMovedUp')); + } + else + { + Display :: display_error_message(get_lang('CannotMoveField')); + } + } + break; + case 'movedown' : + if (move_user_field('movedown', $_GET['field_id'])) + { + Display :: display_confirmation_message(get_lang('FieldMovedDown')); + } + else + { + Display :: display_error_message(get_lang('CannotMoveField')); + } + break; } Security::clear_token(); } @@ -139,6 +162,8 @@ if(1) $column_show = array(1,1,1,1,1,1,1,1,0); $column_order = array(1,2,3,4,5,6,7,8,9); $extra_fields = UserManager::get_extra_fields(0,50,5,'ASC'); + $number_of_extra_fields = count($extra_fields); + $table = new SortableTableFromArrayConfig($extra_fields, 5, 50, '', $column_show, $column_order, 'ASC'); $table->set_additional_parameters($parameters); @@ -150,8 +175,11 @@ if(1) $table->set_header(5, get_lang('FieldOrder')); $table->set_header(6, get_lang('FieldVisibility')); $table->set_header(7, get_lang('FieldChangeability')); + $table->set_header(8, get_lang('Modify')); + $table->set_column_filter(5, 'order_filter'); $table->set_column_filter(6, 'modify_visibility'); $table->set_column_filter(7, 'modify_changeability'); + $table->set_column_filter(8, 'edit_filter'); $table->display(); } @@ -172,6 +200,40 @@ function get_extra_fields($f,$n,$o,$d) { return UserManager::get_extra_fields($f,$n,$o,$d); } +/** + * Modify the display order field into up and down arrows + * + * @param unknown_type $field_order + * @param array Url parameters + * @param array The results row + * @return string The link + * + * @author Patrick Cool , Ghent University, Belgium + * @version July 2008 + * @since Dokeos 1.8.6 + */ +function order_filter($field_order,$url_params,$row) +{ + global $number_of_extra_fields; + + // the up icon only has to appear when the row can be moved up (all but the first row) + if ($row[5]<>1) + { + $return .= ''.Display::return_icon('up.gif', get_lang('Up')).''; + } + else + { + $return .= Display::return_icon('blank.gif','',array('width'=>'21px')); + } + + // the down icon only has to appear when the row can be moved down (all but the last row) + if ($row[5]<>$number_of_extra_fields) + { + $return .= ''.Display::return_icon('down.gif', get_lang('Down')).''; + } + + return $return; +} /** * Modify the visible field to show links and icons * @param int The current visibility @@ -194,4 +256,68 @@ function modify_changeability($visibility,$url_params,$row) { return ($visibility?''.get_lang('MakeUnchangeable').'':''.get_lang('MakeChangeable').''); } + +function edit_filter() +{ + +} +/** + * Move a user defined field up or down + * + * @param string $direction the direction we have to move the field to (up or down) + * @param unknown_type $field_id + * + * @author Patrick Cool , Ghent University, Belgium + * @version July 2008 + * @since Dokeos 1.8.6 + */ +function move_user_field($direction,$field_id) +{ + // Databse table definitions + $table_user_field = Database::get_main_table(TABLE_MAIN_USER_FIELD); + + // check the parameters + if (!in_array($direction,array('moveup','movedown')) OR !is_numeric($field_id)) + { + return false; + } + + // determine the SQL sort direction + if ($direction == 'moveup') + { + $sortdirection = 'DESC'; + } + else + { + $sortdirection = 'ASC'; + } + + $found = false; + + $sql = "SELECT id, field_order FROM $table_user_field ORDER BY field_order $sortdirection"; + $result = api_sql_query($sql,__FILE__,__LINE__); + while($row = Database::fetch_array($result)) + { + if ($found) + { + $next_id = $row['id']; + $next_order = $row['field_order']; + break; + } + + if ($field_id == $row['id']) + { + $this_id = $row['id']; + $this_order = $row['field_order']; + $found = true; + } + } + + $sql1 = "UPDATE ".$table_user_field." SET field_order = '".Database::escape_string($next_order)."' WHERE id = '".Database::escape_string($this_id)."'"; + $sql2 = "UPDATE ".$table_user_field." SET field_order = '".Database::escape_string($this_order)."' WHERE id = '".Database::escape_string($next_id)."'"; + api_sql_query($sql1,__FILE__,__LINE__); + api_sql_query($sql2,__FILE__,__LINE__); + + return true; +} ?> \ No newline at end of file