extra_field_options.php 6.9 KB

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