extra_fields.php 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259
  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($obj->type . '_fields', $url, $columns, $column_model, $extra_params, array(), $action_links,
  40. 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. });
  80. </script>';
  81. // The header.
  82. Display::display_header($tool_name);
  83. // Action handling: Add
  84. switch ($action) {
  85. case 'add':
  86. if (api_get_session_id() != 0 && !api_is_allowed_to_session_edit(false, true)) {
  87. api_not_allowed();
  88. }
  89. $url = api_get_self() . '?type=' . $obj->type . '&action=' . Security::remove_XSS($_GET['action']);
  90. $form = $obj->return_form($url, 'add');
  91. // The validation or display
  92. if ($form->validate()) {
  93. //if ($check) {
  94. $values = $form->exportValues();
  95. $res = $obj->save($values);
  96. if ($res) {
  97. Display::display_confirmation_message(get_lang('ItemAdded'));
  98. }
  99. //}
  100. $obj->display();
  101. } else {
  102. echo '<div class="actions">';
  103. echo '<a href="' . api_get_self() . '?type=' . $obj->type . '">' .
  104. Display::return_icon('back.png', get_lang('Back'), '', ICON_SIZE_MEDIUM) . '</a>';
  105. echo '</div>';
  106. $form->addElement('hidden', 'sec_token');
  107. $form->setConstants(array('sec_token' => $token));
  108. $form->display();
  109. }
  110. break;
  111. case 'edit':
  112. // Action handling: Editing
  113. $url = api_get_self() . '?type=' . $obj->type . '&action=' . Security::remove_XSS($_GET['action']) . '&id=' . intval($_GET['id']);
  114. $form = $obj->return_form($url, 'edit');
  115. // The validation or display
  116. if ($form->validate()) {
  117. //if ($check) {
  118. $values = $form->exportValues();
  119. $res = $obj->update($values);
  120. Display::display_confirmation_message(sprintf(get_lang('ItemUpdated'), $values['field_variable']), false);
  121. //}
  122. $obj->display();
  123. } else {
  124. echo '<div class="actions">';
  125. echo '<a href="' . api_get_self() . '?type=' . $obj->type . '">' .
  126. Display::return_icon('back.png', get_lang('Back'), '', ICON_SIZE_MEDIUM) . '</a>';
  127. echo '</div>';
  128. $form->addElement('hidden', 'sec_token');
  129. $form->setConstants(array('sec_token' => $token));
  130. $form->display();
  131. }
  132. break;
  133. case 'delete':
  134. // Action handling: delete
  135. //if ($check) {
  136. $res = $obj->delete($_GET['id']);
  137. if ($res) {
  138. Display::display_confirmation_message(get_lang('ItemDeleted'));
  139. }
  140. //}
  141. $obj->display();
  142. break;
  143. default:
  144. $obj->display();
  145. break;
  146. }
  147. Display :: display_footer();
  148. /*
  149. CREATE TABLE IF NOT EXISTS lp_field(
  150. id INT NOT NULL auto_increment,
  151. field_type int NOT NULL DEFAULT 1,
  152. field_variable varchar(64) NOT NULL,
  153. field_display_text varchar(64),
  154. field_default_value text,
  155. field_order int,
  156. field_visible tinyint default 0,
  157. field_changeable tinyint default 0,
  158. field_filter tinyint default 0,
  159. tms DATETIME NOT NULL default '0000-00-00 00:00:00',
  160. PRIMARY KEY(id)
  161. );
  162. DROP TABLE IF EXISTS lp_field_options;
  163. CREATE TABLE IF NOT EXISTS lp_field_options (
  164. id int NOT NULL auto_increment,
  165. field_id int NOT NULL,
  166. option_value text,
  167. option_display_text varchar(64),
  168. option_order int,
  169. tms DATETIME NOT NULL default '0000-00-00 00:00:00',
  170. priority VARCHAR(255),
  171. priority_message VARCHAR(255),
  172. PRIMARY KEY (id)
  173. );
  174. DROP TABLE IF EXISTS lp_field_values;
  175. CREATE TABLE IF NOT EXISTS lp_field_values(
  176. id bigint NOT NULL auto_increment,
  177. lp_id int unsigned NOT NULL,
  178. field_id int NOT NULL,
  179. field_value text,
  180. comment VARCHAR(100) default '',
  181. user_id int,
  182. tms DATETIME NOT NULL default '0000-00-00 00:00:00',
  183. PRIMARY KEY(id)
  184. );
  185. ALTER TABLE lp_field_values ADD INDEX (lp_id, field_id);
  186. CREATE TABLE IF NOT EXISTS calendar_event_field(
  187. id INT NOT NULL auto_increment,
  188. field_type int NOT NULL DEFAULT 1,
  189. field_variable varchar(64) NOT NULL,
  190. field_display_text varchar(64),
  191. field_default_value text,
  192. field_order int,
  193. field_visible tinyint default 0,
  194. field_changeable tinyint default 0,
  195. field_filter tinyint default 0,
  196. tms DATETIME NOT NULL default '0000-00-00 00:00:00',
  197. PRIMARY KEY(id)
  198. );
  199. DROP TABLE IF EXISTS calendar_event_options;
  200. CREATE TABLE IF NOT EXISTS calendar_event_options (
  201. id int NOT NULL auto_increment,
  202. field_id int NOT NULL,
  203. option_value text,
  204. option_display_text varchar(64),
  205. option_order int,
  206. tms DATETIME NOT NULL default '0000-00-00 00:00:00',
  207. priority VARCHAR(255),
  208. priority_message VARCHAR(255),
  209. PRIMARY KEY (id)
  210. );
  211. DROP TABLE IF EXISTS calendar_event_values;
  212. CREATE TABLE IF NOT EXISTS calendar_event_values(
  213. id bigint NOT NULL auto_increment,
  214. calendar_event_id int unsigned NOT NULL,
  215. user_id int,
  216. field_id int NOT NULL,
  217. field_value text,
  218. comment VARCHAR(100) default '',
  219. tms DATETIME NOT NULL default '0000-00-00 00:00:00',
  220. PRIMARY KEY(id)
  221. );
  222. */