extra_fields.php 5.9 KB

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