extra_fields.php 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  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. unset($values['id']);
  106. $res = $obj->save($values);
  107. if ($res) {
  108. Display::display_confirmation_message(get_lang('ItemAdded'));
  109. }
  110. //}
  111. $obj->display();
  112. } else {
  113. echo '<div class="actions">';
  114. echo '<a href="' . api_get_self() . '?type=' . $obj->type . '">' .
  115. 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. $values = $form->exportValues();
  129. $res = $obj->update($values);
  130. Display::display_confirmation_message(
  131. sprintf(get_lang('ItemUpdated'), $values['variable']),
  132. false
  133. );
  134. $obj->display();
  135. } else {
  136. echo '<div class="actions">';
  137. echo '<a href="' . api_get_self() . '?type=' . $obj->type . '">' .
  138. Display::return_icon('back.png', get_lang('Back'), '', ICON_SIZE_MEDIUM) . '</a>';
  139. echo '</div>';
  140. $form->addElement('hidden', 'sec_token');
  141. $form->setConstants(array('sec_token' => $token));
  142. $form->display();
  143. }
  144. break;
  145. case 'delete':
  146. // Action handling: delete
  147. //if ($check) {
  148. $res = $obj->delete($_GET['id']);
  149. if ($res) {
  150. Display::display_confirmation_message(get_lang('ItemDeleted'));
  151. }
  152. //}
  153. $obj->display();
  154. break;
  155. default:
  156. $obj->display();
  157. break;
  158. }
  159. Display :: display_footer();