extra_fields.php 6.1 KB

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