extra_fields.php 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262
  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. $cidReset = true;
  10. require_once '../inc/global.inc.php';
  11. $extraFieldType = isset($_REQUEST['type']) ? $_REQUEST['type'] : null;
  12. $this_section = SECTION_PLATFORM_ADMIN;
  13. api_protect_admin_script();
  14. //Add the JS needed to use the jqgrid
  15. $htmlHeadXtra[] = api_get_jqgrid_js();
  16. // setting breadcrumbs
  17. $interbreadcrumb[]=array('url' => 'index.php','name' => get_lang('PlatformAdmin'));
  18. $tool_name = null;
  19. $action = isset($_GET['action']) ? $_GET['action'] : null;
  20. if (!in_array($extraFieldType, ExtraField::getValidExtraFieldTypes())) {
  21. api_not_allowed();
  22. }
  23. $check = Security::check_token('request');
  24. $token = Security::get_token();
  25. $obj = new ExtraField($extraFieldType);
  26. $obj->setupBreadcrumb($interbreadcrumb, $action);
  27. //jqgrid will use this URL to do the selects
  28. $url = api_get_path(WEB_AJAX_PATH).'model.ajax.php?a=get_extra_fields&type='.$extraFieldType;
  29. //The order is important you need to check the the $column variable in the model.ajax.php file
  30. $columns = $obj->getJqgridColumnNames();
  31. //Column config
  32. $column_model = $obj->getJqgridColumnModel();
  33. //Autowidth
  34. $extra_params['autowidth'] = 'true';
  35. //height auto
  36. $extra_params['height'] = 'auto';
  37. $extra_params['sortname'] = 'field_order';
  38. $action_links = $obj->getJqgridActionLinks($token);
  39. $htmlHeadXtra[]='<script>
  40. $(function() {
  41. // grid definition see the $obj->display() function
  42. '.Display::grid_js($obj->type.'_fields', $url, $columns, $column_model, $extra_params, array(), $action_links, true).'
  43. $("#field_type").on("change", function() {
  44. id = $(this).val();
  45. switch(id) {
  46. case "1":
  47. $("#example").html("'.addslashes(Display::return_icon('userfield_text.png')).'");
  48. break;
  49. case "2":
  50. $("#example").html("'.addslashes(Display::return_icon('userfield_text_area.png')).'");
  51. break;
  52. case "3":
  53. $("#example").html("'.addslashes(Display::return_icon('add_user_field_howto.png')).'");
  54. break;
  55. case "4":
  56. $("#example").html("'.addslashes(Display::return_icon('userfield_drop_down.png')).'");
  57. break;
  58. case "5":
  59. $("#example").html("'.addslashes(Display::return_icon('userfield_multidropdown.png')).'");
  60. break;
  61. case "6":
  62. $("#example").html("'.addslashes(Display::return_icon('userfield_data.png')).'");
  63. break;
  64. case "7":
  65. $("#example").html("'.addslashes(Display::return_icon('userfield_date_time.png')).'");
  66. break;
  67. case "8":
  68. $("#example").html("'.addslashes(Display::return_icon('userfield_doubleselect.png')).'");
  69. break;
  70. case "9":
  71. $("#example").html("'.addslashes(Display::return_icon('userfield_divider.png')).'");
  72. break;
  73. case "10":
  74. $("#example").html("'.addslashes(Display::return_icon('userfield_user_tag.png')).'");
  75. break;
  76. case "11":
  77. $("#example").html("'.addslashes(Display::return_icon('userfield_data.png')).'");
  78. break;
  79. }
  80. });
  81. });
  82. </script>';
  83. // The header.
  84. Display::display_header($tool_name);
  85. // Action handling: Add
  86. switch ($action) {
  87. case 'add':
  88. if (api_get_session_id() != 0 && !api_is_allowed_to_session_edit(false, true)) {
  89. api_not_allowed();
  90. }
  91. $url = api_get_self().'?type='.$obj->type.'&action='.Security::remove_XSS($_GET['action']);
  92. $form = $obj->return_form($url, 'add');
  93. // The validation or display
  94. if ($form->validate()) {
  95. //if ($check) {
  96. $values = $form->exportValues();
  97. $res = $obj->save($values);
  98. if ($res) {
  99. Display::display_confirmation_message(get_lang('ItemAdded'));
  100. }
  101. //}
  102. $obj->display();
  103. } else {
  104. echo '<div class="actions">';
  105. echo '<a href="'.api_get_self().'?type='.$obj->type.'">'.
  106. Display::return_icon('back.png',get_lang('Back'),'',ICON_SIZE_MEDIUM).'</a>';
  107. echo '</div>';
  108. $form->addElement('hidden', 'sec_token');
  109. $form->setConstants(array('sec_token' => $token));
  110. $form->display();
  111. }
  112. break;
  113. case 'edit':
  114. // Action handling: Editing
  115. $url = api_get_self().'?type='.$obj->type.'&action='.Security::remove_XSS($_GET['action']).'&id='.intval($_GET['id']);
  116. $form = $obj->return_form($url, 'edit');
  117. // The validation or display
  118. if ($form->validate()) {
  119. //if ($check) {
  120. $values = $form->exportValues();
  121. $res = $obj->update($values);
  122. Display::display_confirmation_message(sprintf(get_lang('ItemUpdated'), $values['field_variable']), false);
  123. //}
  124. $obj->display();
  125. } else {
  126. echo '<div class="actions">';
  127. echo '<a href="'.api_get_self().'?type='.$obj->type.'">'.
  128. Display::return_icon('back.png',get_lang('Back'),'',ICON_SIZE_MEDIUM).'</a>';
  129. echo '</div>';
  130. $form->addElement('hidden', 'sec_token');
  131. $form->setConstants(array('sec_token' => $token));
  132. $form->display();
  133. }
  134. break;
  135. case 'delete':
  136. // Action handling: delete
  137. //if ($check) {
  138. $res = $obj->delete($_GET['id']);
  139. if ($res) {
  140. Display::display_confirmation_message(get_lang('ItemDeleted'));
  141. }
  142. //}
  143. $obj->display();
  144. break;
  145. default:
  146. $obj->display();
  147. break;
  148. }
  149. Display :: display_footer();
  150. /*
  151. CREATE TABLE IF NOT EXISTS lp_field(
  152. id INT NOT NULL auto_increment,
  153. field_type int NOT NULL DEFAULT 1,
  154. field_variable varchar(64) NOT NULL,
  155. field_display_text varchar(64),
  156. field_default_value text,
  157. field_order int,
  158. field_visible tinyint default 0,
  159. field_changeable tinyint default 0,
  160. field_filter tinyint default 0,
  161. tms DATETIME NOT NULL default '0000-00-00 00:00:00',
  162. PRIMARY KEY(id)
  163. );
  164. DROP TABLE IF EXISTS lp_field_options;
  165. CREATE TABLE IF NOT EXISTS lp_field_options (
  166. id int NOT NULL auto_increment,
  167. field_id int NOT NULL,
  168. option_value text,
  169. option_display_text varchar(64),
  170. option_order int,
  171. tms DATETIME NOT NULL default '0000-00-00 00:00:00',
  172. priority VARCHAR(255),
  173. priority_message VARCHAR(255),
  174. PRIMARY KEY (id)
  175. );
  176. DROP TABLE IF EXISTS lp_field_values;
  177. CREATE TABLE IF NOT EXISTS lp_field_values(
  178. id bigint NOT NULL auto_increment,
  179. lp_id int unsigned NOT NULL,
  180. field_id int NOT NULL,
  181. field_value text,
  182. comment VARCHAR(100) default '',
  183. user_id int,
  184. tms DATETIME NOT NULL default '0000-00-00 00:00:00',
  185. PRIMARY KEY(id)
  186. );
  187. ALTER TABLE lp_field_values ADD INDEX (lp_id, field_id);
  188. CREATE TABLE IF NOT EXISTS calendar_event_field(
  189. id INT NOT NULL auto_increment,
  190. field_type int NOT NULL DEFAULT 1,
  191. field_variable varchar(64) NOT NULL,
  192. field_display_text varchar(64),
  193. field_default_value text,
  194. field_order int,
  195. field_visible tinyint default 0,
  196. field_changeable tinyint default 0,
  197. field_filter tinyint default 0,
  198. tms DATETIME NOT NULL default '0000-00-00 00:00:00',
  199. PRIMARY KEY(id)
  200. );
  201. DROP TABLE IF EXISTS calendar_event_options;
  202. CREATE TABLE IF NOT EXISTS calendar_event_options (
  203. id int NOT NULL auto_increment,
  204. field_id int NOT NULL,
  205. option_value text,
  206. option_display_text varchar(64),
  207. option_order int,
  208. tms DATETIME NOT NULL default '0000-00-00 00:00:00',
  209. priority VARCHAR(255),
  210. priority_message VARCHAR(255),
  211. PRIMARY KEY (id)
  212. );
  213. DROP TABLE IF EXISTS calendar_event_values;
  214. CREATE TABLE IF NOT EXISTS calendar_event_values(
  215. id bigint NOT NULL auto_increment,
  216. calendar_event_id int unsigned NOT NULL,
  217. user_id int,
  218. field_id int NOT NULL,
  219. field_value text,
  220. comment VARCHAR(100) default '',
  221. tms DATETIME NOT NULL default '0000-00-00 00:00:00',
  222. PRIMARY KEY(id)
  223. );
  224. */