diff --git a/main/admin/extra_field_options.php b/main/admin/extra_field_options.php index 5b637a8a4a..5627896705 100644 --- a/main/admin/extra_field_options.php +++ b/main/admin/extra_field_options.php @@ -25,67 +25,69 @@ $tool_name = null; $action = isset($_GET['action']) ? $_GET['action'] : null; $field_id = isset($_GET['field_id']) ? $_GET['field_id'] : null; -$type = 'session'; +$type = isset($_REQUEST['type']) ? $_REQUEST['type'] : null; if (empty($field_id)) { api_not_allowed(); } +if (!in_array($type, ExtraField::getValidExtraFieldTypes())) { + api_not_allowed(); +} $extra_field = new ExtraField($type); $extra_field_info = $extra_field->get($field_id); - $check = Security::check_token('request'); -$token = Security::get_token(); +$token = Security::get_token(); if ($action == 'add') { - $interbreadcrumb[]=array('url' => 'session_fields.php','name' => get_lang('ExtraFields')); - $interbreadcrumb[]=array('url' => 'session_fields.php?action=edit&id='.$extra_field_info['id'],'name' => $extra_field_info['field_display_text']); - $interbreadcrumb[]=array('url' => 'extra_field_options.php?type='.$type.'&field_id='.$extra_field_info['id'], 'name' => get_lang('EditExtraFieldOptions')); + $interbreadcrumb[]=array('url' => 'extra_fields.php?type='.$extra_field->type,'name' => get_lang('ExtraFields')); + $interbreadcrumb[]=array('url' => 'extra_fields.php?type='.$extra_field->type.'&action=edit&id='.$extra_field_info['id'],'name' => $extra_field_info['field_display_text']); + $interbreadcrumb[]=array('url' => 'extra_field_options.php?type='.$extra_field->type.'&field_id='.$extra_field_info['id'], 'name' => get_lang('EditExtraFieldOptions')); $interbreadcrumb[]=array('url' => '#','name' => get_lang('Add')); } elseif ($action == 'edit') { - $interbreadcrumb[]=array('url' => 'session_fields.php','name' => get_lang('ExtraFields')); - $interbreadcrumb[]=array('url' => 'session_fields.php?action=edit&id='.$extra_field_info['id'],'name' => $extra_field_info['field_display_text']); - $interbreadcrumb[]=array('url' => 'extra_field_options.php?type='.$type.'&field_id='.$extra_field_info['id'], 'name' => get_lang('EditExtraFieldOptions')); - + $interbreadcrumb[]=array('url' => 'extra_fields.php?type='.$extra_field->type,'name' => get_lang('ExtraFields')); + $interbreadcrumb[]=array('url' => 'extra_fields.php?type='.$extra_field->type.'&action=edit&id='.$extra_field_info['id'],'name' => $extra_field_info['field_display_text']); + $interbreadcrumb[]=array('url' => 'extra_field_options.php?type='.$extra_field->type.'&field_id='.$extra_field_info['id'], 'name' => get_lang('EditExtraFieldOptions')); + $interbreadcrumb[]=array('url' => '#','name' => get_lang('Edit')); } else { - $interbreadcrumb[]=array('url' => 'session_fields.php','name' => get_lang('ExtraFields')); - $interbreadcrumb[]=array('url' => 'session_fields.php?action=edit&id='.$extra_field_info['id'],'name' => $extra_field_info['field_display_text']); + $interbreadcrumb[]=array('url' => 'extra_fields.php?type='.$extra_field->type,'name' => get_lang('ExtraFields')); + $interbreadcrumb[]=array('url' => 'extra_fields.php?type='.$extra_field->type.'&action=edit&id='.$extra_field_info['id'],'name' => $extra_field_info['field_display_text']); $interbreadcrumb[]=array('url' => '#','name' => get_lang('EditExtraFieldOptions')); } //jqgrid will use this URL to do the selects -$params = 'field_id='.$field_id.'&type='.$type; +$params = 'field_id='.$field_id.'&type='.$extra_field->type; $url = api_get_path(WEB_AJAX_PATH).'model.ajax.php?a=get_extra_field_options&'.$params; -//The order is important you need to check the the $column variable in the model.ajax.php file +//The order is important you need to check the the $column variable in the model.ajax.php file $columns = array(get_lang('Name'), get_lang('Value'), get_lang('Order'), get_lang('Actions')); - + //Column config $column_model = array( - array('name'=>'option_display_text', 'index'=>'option_display_text', 'width'=>'180', 'align'=>'left'), - array('name'=>'option_value', 'index'=>'option_value', 'width'=>'', 'align'=>'left','sortable'=>'false'), - array('name'=>'option_order', 'index'=>'option_order', 'width'=>'', 'align'=>'left','sortable'=>'false'), - array('name'=>'actions', 'index'=>'actions', 'width'=>'100', 'align'=>'left','formatter'=>'action_formatter','sortable'=>'false') - ); -//Autowidth + array('name'=>'option_display_text', 'index'=>'option_display_text', 'width'=>'180', 'align'=>'left'), + array('name'=>'option_value', 'index'=>'option_value', 'width'=>'', 'align'=>'left','sortable'=>'false'), + array('name'=>'option_order', 'index'=>'option_order', 'width'=>'', 'align'=>'left','sortable'=>'false'), + array('name'=>'actions', 'index'=>'actions', 'width'=>'100', 'align'=>'left','formatter'=>'action_formatter','sortable'=>'false') +); +//Autowidth $extra_params['autowidth'] = 'true'; -//height auto -$extra_params['height'] = 'auto'; +//height auto +$extra_params['height'] = 'auto'; //With this function we can add actions to the jgrid (edit, delete, etc) $action_links = 'function action_formatter(cellvalue, options, rowObject) { - return \''.Display::return_icon('edit.png',get_lang('Edit'),'',ICON_SIZE_SMALL).''. - ' '.Display::return_icon('delete.png',get_lang('Delete'),'',ICON_SIZE_SMALL).''. - '\'; - }'; + return \''.Display::return_icon('edit.png',get_lang('Edit'),'',ICON_SIZE_SMALL).''. + ' '.Display::return_icon('delete.png',get_lang('Delete'),'',ICON_SIZE_SMALL).''. + '\'; + }'; $htmlHeadXtra[]=' '; @@ -94,7 +96,7 @@ Display::display_header($tool_name); echo Display::page_header($extra_field_info['field_display_text']); -$obj = new ExtraFieldOption($type); +$obj = new ExtraFieldOption($extra_field->type); $obj->field_id = $field_id; // Action handling: Add @@ -102,7 +104,7 @@ switch ($action) { case 'add': if (api_get_session_id() != 0 && !api_is_allowed_to_session_edit(false, true)) { api_not_allowed(); - } + } $url = api_get_self().'?action='.Security::remove_XSS($_GET['action']).'&'.$params; $form = $obj->return_form($url, 'add'); @@ -110,11 +112,11 @@ switch ($action) { if ($form->validate()) { if ($check) { $values = $form->exportValues(); - $res = $obj->save_one_item($values); + $res = $obj->save_one_item($values); if ($res) { Display::display_confirmation_message(get_lang('ItemAdded')); } - } + } $obj->display(); } else { /*echo '
'; @@ -126,17 +128,17 @@ switch ($action) { } break; case 'edit': - // Action handling: Editing + // Action handling: Editing $url = api_get_self().'?action='.Security::remove_XSS($_GET['action']).'&id='.intval($_GET['id']).'&'.$params; - $form = $obj->return_form($url, 'edit'); + $form = $obj->return_form($url, 'edit'); // The validation or display - if ($form->validate()) { + if ($form->validate()) { if ($check) { - $values = $form->exportValues(); - $res = $obj->update($values); - Display::display_confirmation_message(sprintf(get_lang('ItemUpdated'), $values['name']), false); - } + $values = $form->exportValues(); + $res = $obj->update($values); + Display::display_confirmation_message(sprintf(get_lang('ItemUpdated'), $values['name']), false); + } $obj->display(); } else { /*echo '
'; @@ -158,7 +160,7 @@ switch ($action) { $obj->display(); break; default: - $obj->display(); + $obj->display(); break; } Display :: display_footer(); \ No newline at end of file diff --git a/main/admin/extra_fields.php b/main/admin/extra_fields.php new file mode 100644 index 0000000000..9094366553 --- /dev/null +++ b/main/admin/extra_fields.php @@ -0,0 +1,185 @@ + 'index.php','name' => get_lang('PlatformAdmin')); + +$tool_name = null; + +$action = isset($_GET['action']) ? $_GET['action'] : null; + +$extraFieldType = isset($_REQUEST['type']) ? $_REQUEST['type'] : null; + +if (!in_array($extraFieldType, ExtraField::getValidExtraFieldTypes())) { + api_not_allowed(); +} + +$check = Security::check_token('request'); +$token = Security::get_token(); + +$obj = new ExtraField($extraFieldType); + +$obj->setupBreadcrumb($interbreadcrumb, $action); + +//jqgrid will use this URL to do the selects +$url = api_get_path(WEB_AJAX_PATH).'model.ajax.php?a=get_extra_fields&type='.$extraFieldType; + +//The order is important you need to check the the $column variable in the model.ajax.php file +$columns = $obj->getJqgridColumnNames(); + +//Column config +$column_model = $obj->getJqgridColumnModel(); + +//Autowidth +$extra_params['autowidth'] = 'true'; +//height auto +$extra_params['height'] = 'auto'; +$extra_params['sortname'] = 'field_order'; + +$action_links = $obj->getJqgridActionLinks($token); + +$htmlHeadXtra[]=''; + +// The header. +Display::display_header($tool_name); + +// Action handling: Add + +switch ($action) { + case 'add': + if (api_get_session_id() != 0 && !api_is_allowed_to_session_edit(false, true)) { + api_not_allowed(); + } + $url = api_get_self().'?type='.$obj->type.'&action='.Security::remove_XSS($_GET['action']); + $form = $obj->return_form($url, 'add'); + + // The validation or display + if ($form->validate()) { + if ($check) { + $values = $form->exportValues(); + $res = $obj->save($values); + if ($res) { + Display::display_confirmation_message(get_lang('ItemAdded')); + } + } + $obj->display(); + } else { + echo ''; + $form->addElement('hidden', 'sec_token'); + $form->setConstants(array('sec_token' => $token)); + $form->display(); + } + break; + case 'edit': + // Action handling: Editing + $url = api_get_self().'?type='.$obj->type.'&action='.Security::remove_XSS($_GET['action']).'&id='.intval($_GET['id']); + $form = $obj->return_form($url, 'edit'); + + // The validation or display + if ($form->validate()) { + if ($check) { + $values = $form->exportValues(); + $res = $obj->update($values); + Display::display_confirmation_message(sprintf(get_lang('ItemUpdated'), $values['name']), false); + } + $obj->display(); + } else { + echo ''; + $form->addElement('hidden', 'sec_token'); + $form->setConstants(array('sec_token' => $token)); + $form->display(); + } + break; + case 'delete': + // Action handling: delete + if ($check) { + $res = $obj->delete($_GET['id']); + if ($res) { + Display::display_confirmation_message(get_lang('ItemDeleted')); + } + } + $obj->display(); + break; + default: + $obj->display(); + break; +} +Display :: display_footer(); \ No newline at end of file diff --git a/main/admin/index.php b/main/admin/index.php index 9aa93f3442..f99ff0303b 100644 --- a/main/admin/index.php +++ b/main/admin/index.php @@ -120,6 +120,11 @@ if (api_is_platform_admin()) { $items[] = array('url'=>'subscribe_user2course.php', 'label' => get_lang('AddUsersToACourse')); $items[] = array('url'=>'course_user_import.php', 'label' => get_lang('ImportUsersToACourse')); + $items[] = array('url'=>'extra_fields.php?type=course', 'label' => get_lang('ManageCourseFields')); + + $items[] = array('url'=>'extra_fields.php?type=question', 'label' => get_lang('ManageQuestionFields')); + + if (api_get_setting('gradebook_enable_grade_model') == 'true') { $items[] = array('url'=>'grade_models.php', 'label' => get_lang('GradeModel')); } @@ -203,7 +208,7 @@ if (api_is_platform_admin()) { } $items[] = array('url'=>'usergroups.php', 'label' => get_lang('Classes')); -$items[] = array('url'=>'session_fields.php', 'label' => get_lang('ManageSessionFields')); +$items[] = array('url'=>'extra_fields.php?type=session', 'label' => get_lang('ManageSessionFields')); $blocks['sessions']['items'] = $items; $blocks['sessions']['extra'] = null; diff --git a/main/admin/session_fields.php b/main/admin/session_fields.php deleted file mode 100644 index fcddf44f9d..0000000000 --- a/main/admin/session_fields.php +++ /dev/null @@ -1,200 +0,0 @@ - 'index.php','name' => get_lang('PlatformAdmin')); - -$tool_name = null; - -$action = isset($_GET['action']) ? $_GET['action'] : null; - -$check = Security::check_token('request'); -$token = Security::get_token(); - -if ($action == 'add') { - $interbreadcrumb[]=array('url' => 'session_fields.php','name' => get_lang('SessionFields')); - $interbreadcrumb[]=array('url' => '#','name' => get_lang('Add')); -} elseif ($action == 'edit') { - $interbreadcrumb[]=array('url' => 'session_fields.php','name' => get_lang('SessionFields')); - $interbreadcrumb[]=array('url' => '#','name' => get_lang('Edit')); -} else { - $interbreadcrumb[]=array('url' => '#','name' => get_lang('SessionFields')); -} - -//jqgrid will use this URL to do the selects -$url = api_get_path(WEB_AJAX_PATH).'model.ajax.php?a=get_extra_fields&type=session'; - -//The order is important you need to check the the $column variable in the model.ajax.php file -$columns = array(get_lang('Name'), get_lang('FieldLabel'), get_lang('Type'), get_lang('FieldChangeability'), get_lang('Visibility'), get_lang('Filter'), get_lang('FieldOrder'), get_lang('Actions')); - -//Column config -$column_model = array( - array('name'=>'field_display_text', 'index'=>'field_display_text', 'width'=>'180', 'align'=>'left'), - array('name'=>'field_variable', 'index'=>'field_variable', 'width'=>'', 'align'=>'left','sortable'=>'true'), - array('name'=>'field_type', 'index'=>'field_type', 'width'=>'', 'align'=>'left','sortable'=>'true'), - array('name'=>'field_changeable', 'index'=>'field_changeable', 'width'=>'50', 'align'=>'left','sortable'=>'true'), - array('name'=>'field_visible', 'index'=>'field_visible', 'width'=>'40', 'align'=>'left','sortable'=>'true'), - array('name'=>'field_filter', 'index'=>'field_filter', 'width'=>'30', 'align'=>'left','sortable'=>'true'), - array('name'=>'field_order', 'index'=>'field_order', 'width'=>'40', 'align'=>'left','sortable'=>'true'), - array('name'=>'actions', 'index'=>'actions', 'width'=>'100', 'align'=>'left','formatter'=>'action_formatter','sortable'=>'false') -); - -//Autowidth -$extra_params['autowidth'] = 'true'; -//height auto -$extra_params['height'] = 'auto'; -$extra_params['sortname'] = 'field_order'; - -//With this function we can add actions to the jgrid (edit, delete, etc) -$action_links = 'function action_formatter(cellvalue, options, rowObject) { - return \''.Display::return_icon('edit.png',get_lang('Edit'),'',ICON_SIZE_SMALL).''. - ' '.Display::return_icon('delete.png',get_lang('Delete'),'',ICON_SIZE_SMALL).''. - '\'; - }'; -$htmlHeadXtra[]=' -'; - -// The header. -Display::display_header($tool_name); - -$obj = new SessionField(); - -// Action handling: Add -switch ($action) { - case 'add': - if (api_get_session_id() != 0 && !api_is_allowed_to_session_edit(false, true)) { - api_not_allowed(); - } - $url = api_get_self().'?action='.Security::remove_XSS($_GET['action']); - $form = $obj->return_form($url, 'add'); - - // The validation or display - if ($form->validate()) { - if ($check) { - $values = $form->exportValues(); - $res = $obj->save($values); - if ($res) { - Display::display_confirmation_message(get_lang('ItemAdded')); - } - } - $obj->display(); - } else { - echo ''; - $form->addElement('hidden', 'sec_token'); - $form->setConstants(array('sec_token' => $token)); - $form->display(); - } - break; - case 'edit': - // Action handling: Editing - $url = api_get_self().'?action='.Security::remove_XSS($_GET['action']).'&id='.intval($_GET['id']); - $form = $obj->return_form($url, 'edit'); - - // The validation or display - if ($form->validate()) { - if ($check) { - $values = $form->exportValues(); - $res = $obj->update($values); - Display::display_confirmation_message(sprintf(get_lang('ItemUpdated'), $values['name']), false); - } - $obj->display(); - } else { - echo ''; - $form->addElement('hidden', 'sec_token'); - $form->setConstants(array('sec_token' => $token)); - $form->display(); - } - break; - case 'delete': - // Action handling: delete - if ($check) { - $res = $obj->delete($_GET['id']); - if ($res) { - Display::display_confirmation_message(get_lang('ItemDeleted')); - } - } - $obj->display(); - break; - default: - $obj->display(); - break; -} -Display :: display_footer(); \ No newline at end of file diff --git a/main/inc/lib/database.constants.inc.php b/main/inc/lib/database.constants.inc.php index 3f73bed309..e8fe52cb96 100644 --- a/main/inc/lib/database.constants.inc.php +++ b/main/inc/lib/database.constants.inc.php @@ -105,6 +105,11 @@ define('TABLE_MAIN_SESSION_FIELD', 'session_field'); define('TABLE_MAIN_SESSION_FIELD_OPTIONS', 'session_field_options'); define('TABLE_MAIN_SESSION_FIELD_VALUES', 'session_field_values'); +define('TABLE_MAIN_QUESTION_FIELD', 'question_field'); +define('TABLE_MAIN_QUESTION_FIELD_OPTIONS', 'question_field_options'); +define('TABLE_MAIN_QUESTION_FIELD_VALUES', 'question_field_values'); + + // Message define('TABLE_MAIN_MESSAGE', 'message'); diff --git a/main/inc/lib/extra_field.lib.php b/main/inc/lib/extra_field.lib.php index 475841f5b6..0174cdbcfa 100644 --- a/main/inc/lib/extra_field.lib.php +++ b/main/inc/lib/extra_field.lib.php @@ -32,6 +32,8 @@ class ExtraField extends Model public $type = 'user'; //or session or course public $handler_id = 'user_id'; + public $pageName; + public $pageUrl; function __construct($type) { @@ -61,7 +63,26 @@ class ExtraField extends Model $this->table = Database::get_main_table(TABLE_MAIN_SESSION_FIELD); $this->handler_id = 'session_id'; break; + case 'question': + $this->table_field_options = Database::get_main_table(TABLE_MAIN_QUESTION_FIELD_OPTIONS); + $this->table_field_values = Database::get_main_table(TABLE_MAIN_QUESTION_FIELD_VALUES); + + //Used for the model + $this->table = Database::get_main_table(TABLE_MAIN_QUESTION_FIELD); + $this->handler_id = 'question_id'; + break; } + $this->pageUrl = 'extra_fields.php?type='.$this->type; + $this->pageName = get_lang(ucwords($this->type).'Fields'); // Example QuestionFields + } + + static function getValidExtraFieldTypes() { + return array( + 'user', + 'course', + 'session', + 'question' + ); } public function get_count() @@ -760,4 +781,149 @@ EOF; return $return; } + + function setupBreadcrumb(&$breadcrumb, $action) + { + if ($action == 'add') { + $breadcrumb[]=array('url' => $this->pageUrl,'name' => $this->pageName); + $breadcrumb[]=array('url' => '#','name' => get_lang('Add')); + } elseif ($action == 'edit') { + $breadcrumb[]=array('url' => $this->pageUrl,'name' => $this->pageName); + $breadcrumb[]=array('url' => '#','name' => get_lang('Edit')); + } else { + $breadcrumb[]=array('url' => '#','name' => $this->pageName); + } + } + + + /** + * Displays the title + grid + */ + public function display() + { + // action links + echo ''; + echo Display::grid_html($this->type.'_fields'); + } + + public function getJqgridColumnNames() { + return array(get_lang('Name'), get_lang('FieldLabel'), get_lang('Type'), get_lang('FieldChangeability'), get_lang('Visibility'), get_lang('Filter'), get_lang('FieldOrder'), get_lang('Actions')); + } + + public function getJqgridColumnModel() { + return array( + array('name'=>'field_display_text', 'index'=>'field_display_text', 'width'=>'180', 'align'=>'left'), + array('name'=>'field_variable', 'index'=>'field_variable', 'width'=>'', 'align'=>'left','sortable'=>'true'), + array('name'=>'field_type', 'index'=>'field_type', 'width'=>'', 'align'=>'left','sortable'=>'true'), + array('name'=>'field_changeable', 'index'=>'field_changeable', 'width'=>'50', 'align'=>'left','sortable'=>'true'), + array('name'=>'field_visible', 'index'=>'field_visible', 'width'=>'40', 'align'=>'left','sortable'=>'true'), + array('name'=>'field_filter', 'index'=>'field_filter', 'width'=>'30', 'align'=>'left','sortable'=>'true'), + array('name'=>'field_order', 'index'=>'field_order', 'width'=>'40', 'align'=>'left','sortable'=>'true'), + array('name'=>'actions', 'index'=>'actions', 'width'=>'100', 'align'=>'left','formatter'=>'action_formatter','sortable'=>'false') + ); + + } + + + public function return_form($url, $action) + { + $form = new FormValidator($this->type.'_field', 'post', $url); + + $form->addElement('hidden', 'type', $this->type); + $id = isset($_GET['id']) ? intval($_GET['id']) : null; + $form->addElement('hidden', 'id', $id); + + // Setting the form elements + $header = get_lang('Add'); + $defaults = array(); + + if ($action == 'edit') { + $header = get_lang('Modify'); + // Setting the defaults + $defaults = $this->get($id); + } + + $form->addElement('header', $header); + $form->addElement('text', 'field_display_text', get_lang('Name'), array('class' => 'span5')); + + // Field type + $types = self::get_field_types(); + + $form->addElement('select', 'field_type', get_lang('FieldType'), $types, array('id' => 'field_type', 'class' => 'chzn-select', 'data-placeholder' => get_lang('Select'))); + $form->addElement('label', get_lang('Example'), '
-
'); + + //$form->addElement('advanced_settings',''.get_lang('AdvancedParameters').''); + //$form->addElement('html',''; - echo Display::grid_html('session_fields'); - } - - public function return_form($url, $action) { - $form = new FormValidator('session_field', 'post', $url); - $id = isset($_GET['id']) ? intval($_GET['id']) : null; - $form->addElement('hidden', 'id', $id); - - // Settting the form elements - $header = get_lang('Add'); - $defaults = array(); - - if ($action == 'edit') { - $header = get_lang('Modify'); - // Setting the defaults - $defaults = $this->get($id); - } - - $form->addElement('header', $header); - $form->addElement('text', 'field_display_text', get_lang('Name'), array('class' => 'span5')); - - // Field type - $types = self::get_field_types(); - - $form->addElement('select', 'field_type', get_lang('FieldType'), $types, array('id' => 'field_type', 'class' => 'chzn-select', 'data-placeholder' => get_lang('Select'))); - $form->addElement('label', get_lang('Example'), '
-
'); - - //$form->addElement('advanced_settings',''.get_lang('AdvancedParameters').''); - //$form->addElement('html','