extra_fields.php 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218
  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.'">'.Display::return_icon('back.png',get_lang('Back'),'',ICON_SIZE_MEDIUM).'</a>';
  106. echo '</div>';
  107. $form->addElement('hidden', 'sec_token');
  108. $form->setConstants(array('sec_token' => $token));
  109. $form->display();
  110. }
  111. break;
  112. case 'edit':
  113. // Action handling: Editing
  114. $url = api_get_self().'?type='.$obj->type.'&action='.Security::remove_XSS($_GET['action']).'&id='.intval($_GET['id']);
  115. $form = $obj->return_form($url, 'edit');
  116. // The validation or display
  117. if ($form->validate()) {
  118. //if ($check) {
  119. $values = $form->exportValues();
  120. $res = $obj->update($values);
  121. Display::display_confirmation_message(sprintf(get_lang('ItemUpdated'), $values['field_variable']), false);
  122. //}
  123. $obj->display();
  124. } else {
  125. echo '<div class="actions">';
  126. echo '<a href="'.api_get_self().'?type='.$obj->type.'">'.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. tms DATETIME NOT NULL default '0000-00-00 00:00:00',
  182. PRIMARY KEY(id)
  183. );
  184. ALTER TABLE lp_field_values ADD INDEX (lp_id, field_id);
  185. */