session_fields.php 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  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. $check = Security::check_token('request');
  19. $token = Security::get_token();
  20. if ($action == 'add') {
  21. $interbreadcrumb[]=array('url' => 'session_fields.php','name' => get_lang('SessionFields'));
  22. $interbreadcrumb[]=array('url' => '#','name' => get_lang('Add'));
  23. } elseif ($action == 'edit') {
  24. $interbreadcrumb[]=array('url' => 'session_fields.php','name' => get_lang('SessionFields'));
  25. $interbreadcrumb[]=array('url' => '#','name' => get_lang('Edit'));
  26. } else {
  27. $interbreadcrumb[]=array('url' => '#','name' => get_lang('SessionFields'));
  28. }
  29. //jqgrid will use this URL to do the selects
  30. $url = api_get_path(WEB_AJAX_PATH).'model.ajax.php?a=get_extra_fields&type=session';
  31. //The order is important you need to check the the $column variable in the model.ajax.php file
  32. $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'));
  33. //Column config
  34. $column_model = array(
  35. array('name'=>'field_display_text', 'index'=>'field_display_text', 'width'=>'180', 'align'=>'left'),
  36. array('name'=>'field_variable', 'index'=>'field_variable', 'width'=>'', 'align'=>'left','sortable'=>'true'),
  37. array('name'=>'field_type', 'index'=>'field_type', 'width'=>'', 'align'=>'left','sortable'=>'true'),
  38. array('name'=>'field_changeable', 'index'=>'field_changeable', 'width'=>'50', 'align'=>'left','sortable'=>'true'),
  39. array('name'=>'field_visible', 'index'=>'field_visible', 'width'=>'40', 'align'=>'left','sortable'=>'true'),
  40. array('name'=>'field_filter', 'index'=>'field_filter', 'width'=>'30', 'align'=>'left','sortable'=>'true'),
  41. array('name'=>'field_order', 'index'=>'field_order', 'width'=>'40', 'align'=>'left','sortable'=>'true'),
  42. array('name'=>'actions', 'index'=>'actions', 'width'=>'100', 'align'=>'left','formatter'=>'action_formatter','sortable'=>'false')
  43. );
  44. //Autowidth
  45. $extra_params['autowidth'] = 'true';
  46. //height auto
  47. $extra_params['height'] = 'auto';
  48. $extra_params['sortname'] = 'field_order';
  49. //With this function we can add actions to the jgrid (edit, delete, etc)
  50. $action_links = 'function action_formatter(cellvalue, options, rowObject) {
  51. return \'<a href="?action=edit&id=\'+options.rowId+\'">'.Display::return_icon('edit.png',get_lang('Edit'),'',ICON_SIZE_SMALL).'</a>'.
  52. '&nbsp;<a onclick="javascript:if(!confirm('."\'".addslashes(api_htmlentities(get_lang("ConfirmYourChoice"),ENT_QUOTES))."\'".')) return false;" href="?sec_token='.$token.'&action=delete&id=\'+options.rowId+\'">'.Display::return_icon('delete.png',get_lang('Delete'),'',ICON_SIZE_SMALL).'</a>'.
  53. '\';
  54. }';
  55. $htmlHeadXtra[]='
  56. <script>
  57. $(function() {
  58. // grid definition see the $obj->display() function
  59. '.Display::grid_js('session_fields', $url, $columns, $column_model, $extra_params, array(), $action_links,true).'
  60. $("#field_type").on("change", function() {
  61. id = $(this).val();
  62. switch(id) {
  63. case "1":
  64. $("#example").html("'.addslashes(Display::return_icon('userfield_text.png')).'");
  65. break;
  66. case "2":
  67. $("#example").html("'.addslashes(Display::return_icon('userfield_text_area.png')).'");
  68. break;
  69. case "3":
  70. $("#example").html("'.addslashes(Display::return_icon('add_user_field_howto.png')).'");
  71. break;
  72. case "4":
  73. $("#example").html("'.addslashes(Display::return_icon('userfield_drop_down.png')).'");
  74. break;
  75. case "5":
  76. $("#example").html("'.addslashes(Display::return_icon('userfield_multidropdown.png')).'");
  77. break;
  78. case "6":
  79. $("#example").html("'.addslashes(Display::return_icon('userfield_data.png')).'");
  80. break;
  81. case "7":
  82. $("#example").html("'.addslashes(Display::return_icon('userfield_date_time.png')).'");
  83. break;
  84. case "8":
  85. $("#example").html("'.addslashes(Display::return_icon('userfield_doubleselect.png')).'");
  86. break;
  87. case "9":
  88. $("#example").html("'.addslashes(Display::return_icon('userfield_divider.png')).'");
  89. break;
  90. case "10":
  91. $("#example").html("'.addslashes(Display::return_icon('userfield_user_tag.png')).'");
  92. break;
  93. case "11":
  94. $("#example").html("'.addslashes(Display::return_icon('userfield_data.png')).'");
  95. break;
  96. }
  97. });
  98. var value = 1;
  99. $("#advanced_parameters").on("click", function() {
  100. $("#options").toggle(function() {
  101. if (value == 1) {
  102. $("#advanced_parameters").addClass("btn-hide");
  103. value = 0;
  104. } else {
  105. $("#advanced_parameters").removeClass("btn-hide");
  106. value = 1;
  107. }
  108. });
  109. });
  110. });
  111. </script>';
  112. // The header.
  113. Display::display_header($tool_name);
  114. $obj = new SessionField();
  115. // Action handling: Add
  116. switch ($action) {
  117. case 'add':
  118. if (api_get_session_id() != 0 && !api_is_allowed_to_session_edit(false, true)) {
  119. api_not_allowed();
  120. }
  121. $url = api_get_self().'?action='.Security::remove_XSS($_GET['action']);
  122. $form = $obj->return_form($url, 'add');
  123. // The validation or display
  124. if ($form->validate()) {
  125. if ($check) {
  126. $values = $form->exportValues();
  127. $res = $obj->save($values);
  128. if ($res) {
  129. Display::display_confirmation_message(get_lang('ItemAdded'));
  130. }
  131. }
  132. $obj->display();
  133. } else {
  134. echo '<div class="actions">';
  135. echo '<a href="'.api_get_self().'">'.Display::return_icon('back.png',get_lang('Back'),'',ICON_SIZE_MEDIUM).'</a>';
  136. echo '</div>';
  137. $form->addElement('hidden', 'sec_token');
  138. $form->setConstants(array('sec_token' => $token));
  139. $form->display();
  140. }
  141. break;
  142. case 'edit':
  143. // Action handling: Editing
  144. $url = api_get_self().'?action='.Security::remove_XSS($_GET['action']).'&id='.intval($_GET['id']);
  145. $form = $obj->return_form($url, 'edit');
  146. // The validation or display
  147. if ($form->validate()) {
  148. if ($check) {
  149. $values = $form->exportValues();
  150. $res = $obj->update($values);
  151. Display::display_confirmation_message(sprintf(get_lang('ItemUpdated'), $values['name']), false);
  152. }
  153. $obj->display();
  154. } else {
  155. echo '<div class="actions">';
  156. echo '<a href="'.api_get_self().'">'.Display::return_icon('back.png',get_lang('Back'),'',ICON_SIZE_MEDIUM).'</a>';
  157. echo '</div>';
  158. $form->addElement('hidden', 'sec_token');
  159. $form->setConstants(array('sec_token' => $token));
  160. $form->display();
  161. }
  162. break;
  163. case 'delete':
  164. // Action handling: delete
  165. if ($check) {
  166. $res = $obj->delete($_GET['id']);
  167. if ($res) {
  168. Display::display_confirmation_message(get_lang('ItemDeleted'));
  169. }
  170. }
  171. $obj->display();
  172. break;
  173. default:
  174. $obj->display();
  175. break;
  176. }
  177. Display :: display_footer();