extra_field_options.php 6.9 KB

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