extra_field_options.php 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * @package chamilo.admin
  5. */
  6. // Language files that need to be included.
  7. $language_file = array('admin');
  8. $cidReset = true;
  9. require_once '../inc/global.inc.php';
  10. $this_section = SECTION_PLATFORM_ADMIN;
  11. $type = isset($_REQUEST['type']) ? $_REQUEST['type'] : null;
  12. if ($type == 'question') {
  13. if (!(api_is_platform_admin() || api_is_question_manager())) {
  14. api_not_allowed(true);
  15. }
  16. } else {
  17. api_protect_admin_script();
  18. }
  19. //Add the JS needed to use the jqgrid
  20. $htmlHeadXtra[] = api_get_jqgrid_js();
  21. // setting breadcrumbs
  22. $interbreadcrumb[]=array('url' => 'index.php','name' => get_lang('PlatformAdmin'));
  23. $tool_name = null;
  24. $action = isset($_GET['action']) ? $_GET['action'] : null;
  25. $field_id = isset($_GET['field_id']) ? $_GET['field_id'] : null;
  26. if (empty($field_id)) {
  27. api_not_allowed();
  28. }
  29. if (!in_array($type, ExtraField::getValidExtraFieldTypes())) {
  30. api_not_allowed();
  31. }
  32. $extra_field = new ExtraField($type);
  33. $extra_field_info = $extra_field->get($field_id);
  34. $check = Security::check_token('request');
  35. $token = Security::get_token();
  36. if ($action == 'add') {
  37. $interbreadcrumb[]=array('url' => 'extra_fields.php?type='.$extra_field->type,'name' => $extra_field->pageName);
  38. $interbreadcrumb[]=array('url' => 'extra_fields.php?type='.$extra_field->type.'&action=edit&id='.$extra_field_info['id'],'name' => $extra_field_info['field_display_text']);
  39. $interbreadcrumb[]=array('url' => 'extra_field_options.php?type='.$extra_field->type.'&field_id='.$extra_field_info['id'], 'name' => get_lang('EditExtraFieldOptions'));
  40. $interbreadcrumb[]=array('url' => '#','name' => get_lang('Add'));
  41. } elseif ($action == 'edit') {
  42. $interbreadcrumb[]=array('url' => 'extra_fields.php?type='.$extra_field->type,'name' => $extra_field->pageName);
  43. $interbreadcrumb[]=array('url' => 'extra_fields.php?type='.$extra_field->type.'&action=edit&id='.$extra_field_info['id'],'name' => $extra_field_info['field_display_text']);
  44. $interbreadcrumb[]=array('url' => 'extra_field_options.php?type='.$extra_field->type.'&field_id='.$extra_field_info['id'], 'name' => get_lang('EditExtraFieldOptions'));
  45. $interbreadcrumb[]=array('url' => '#','name' => get_lang('Edit'));
  46. } else {
  47. $interbreadcrumb[]=array('url' => 'extra_fields.php?type='.$extra_field->type,'name' => $extra_field->pageName);
  48. $interbreadcrumb[]=array('url' => 'extra_fields.php?type='.$extra_field->type.'&action=edit&id='.$extra_field_info['id'],'name' => $extra_field_info['field_display_text']);
  49. $interbreadcrumb[]=array('url' => '#','name' => get_lang('EditExtraFieldOptions'));
  50. }
  51. //jqgrid will use this URL to do the selects
  52. $params = 'field_id='.$field_id.'&type='.$extra_field->type;
  53. $url = api_get_path(WEB_AJAX_PATH).'model.ajax.php?a=get_extra_field_options&'.$params;
  54. //The order is important you need to check the the $column variable in the model.ajax.php file
  55. $columns = array(get_lang('Name'), get_lang('Value'), get_lang('Order'), get_lang('Actions'));
  56. //Column config
  57. $column_model = array(
  58. array('name'=>'option_display_text', 'index'=>'option_display_text', 'width'=>'180', 'align'=>'left'),
  59. array('name'=>'option_value', 'index'=>'option_value', 'width'=>'', 'align'=>'left','sortable'=>'false'),
  60. array('name'=>'option_order', 'index'=>'option_order', 'width'=>'', 'align'=>'left','sortable'=>'false'),
  61. array('name'=>'actions', 'index'=>'actions', 'width'=>'100', 'align'=>'left','formatter'=>'action_formatter','sortable'=>'false')
  62. );
  63. //Autowidth
  64. $extra_params['autowidth'] = 'true';
  65. //height auto
  66. $extra_params['height'] = 'auto';
  67. //With this function we can add actions to the jgrid (edit, delete, etc)
  68. $action_links = 'function action_formatter(cellvalue, options, rowObject) {
  69. return \'<a href="?action=edit&'.$params.'&id=\'+options.rowId+\'">'.Display::return_icon('edit.png',get_lang('Edit'),'',ICON_SIZE_SMALL).'</a>'.
  70. '&nbsp;<a onclick="javascript:if(!confirm('."\'".addslashes(api_htmlentities(get_lang("ConfirmYourChoice"),ENT_QUOTES))."\'".')) return false;" href="?sec_token='.$token.'&action=delete&'.$params.'&id=\'+options.rowId+\'">'.Display::return_icon('delete.png',get_lang('Delete'),'',ICON_SIZE_SMALL).'</a>'.
  71. '\';
  72. }';
  73. $htmlHeadXtra[]='
  74. <script>
  75. $(function() {
  76. // grid definition see the $obj->display() function
  77. '.Display::grid_js('extra_field_options', $url, $columns, $column_model, $extra_params, array(), $action_links, true).'
  78. });
  79. </script>';
  80. // The header.
  81. Display::display_header($tool_name);
  82. echo Display::page_header($extra_field_info['field_display_text']);
  83. $obj = new ExtraFieldOption($extra_field->type);
  84. $obj->field_id = $field_id;
  85. // Action handling: Add
  86. switch ($action) {
  87. case 'add':
  88. if (api_get_session_id() != 0 && !api_is_allowed_to_session_edit(false, true)) {
  89. api_not_allowed();
  90. }
  91. $url = api_get_self().'?action='.Security::remove_XSS($_GET['action']).'&'.$params;
  92. $form = $obj->return_form($url, 'add');
  93. // The validation or display
  94. if ($form->validate()) {
  95. if ($check) {
  96. $values = $form->exportValues();
  97. $res = $obj->save_one_item($values);
  98. if ($res) {
  99. Display::display_confirmation_message(get_lang('ItemAdded'));
  100. }
  101. }
  102. $obj->display();
  103. } else {
  104. /*echo '<div class="actions">';
  105. echo '<a href="'.api_get_self().'">'.Display::return_icon('back.png',get_lang('Back'),'',ICON_SIZE_MEDIUM).'</a>';
  106. echo '</div>'; */
  107. $form->addElement('hidden', 'sec_token');
  108. $form->setConstants(array('sec_token' => $token));
  109. $form->display();
  110. }
  111. break;
  112. case 'edit':
  113. // Action handling: Editing
  114. $url = api_get_self().'?action='.Security::remove_XSS($_GET['action']).'&id='.intval($_GET['id']).'&'.$params;
  115. $form = $obj->return_form($url, 'edit');
  116. // The validation or display
  117. if ($form->validate()) {
  118. if ($check) {
  119. $values = $form->exportValues();
  120. $res = $obj->update($values);
  121. Display::display_confirmation_message(sprintf(get_lang('ItemUpdated'), $values['name']), false);
  122. }
  123. $obj->display();
  124. } else {
  125. /*echo '<div class="actions">';
  126. echo '<a href="'.api_get_self().'">'.Display::return_icon('back.png',get_lang('Back'),'',ICON_SIZE_MEDIUM).'</a>';
  127. echo '</div>';*/
  128. $form->addElement('hidden', 'sec_token');
  129. $form->setConstants(array('sec_token' => $token));
  130. $form->display();
  131. }
  132. break;
  133. case 'delete':
  134. // Action handling: delete
  135. if ($check) {
  136. $res = $obj->delete($_GET['id']);
  137. if ($res) {
  138. Display::display_confirmation_message(get_lang('ItemDeleted'));
  139. }
  140. }
  141. $obj->display();
  142. break;
  143. default:
  144. $obj->display();
  145. break;
  146. }
  147. Display :: display_footer();