database.php 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * Contains the SQL for the tickets management plugin database structure
  5. */
  6. $objPlugin = TicketPlugin::create();
  7. $table = Database::get_main_table(TABLE_TICKET_ASSIGNED_LOG);
  8. $sql = "CREATE TABLE IF NOT EXISTS ".$table." (
  9. id int UNSIGNED NOT NULL AUTO_INCREMENT,
  10. ticket_id int UNSIGNED DEFAULT NULL,
  11. user_id int UNSIGNED DEFAULT NULL,
  12. assigned_date datetime DEFAULT NULL,
  13. sys_insert_user_id int UNSIGNED DEFAULT NULL,
  14. PRIMARY KEY PK_ticket_assigned_log (id),
  15. KEY FK_ticket_assigned_log (ticket_id))";
  16. Database::query($sql);
  17. //Category
  18. $table = Database::get_main_table(TABLE_TICKET_CATEGORY);
  19. $sql = "CREATE TABLE IF NOT EXISTS ".$table." (
  20. id int UNSIGNED NOT NULL AUTO_INCREMENT,
  21. category_id char(3) NOT NULL,
  22. project_id char(3) NOT NULL,
  23. name varchar(100) NOT NULL,
  24. description varchar(255) NOT NULL,
  25. total_tickets int UNSIGNED NOT NULL DEFAULT '0',
  26. course_required char(1) NOT NULL,
  27. sys_insert_user_id int UNSIGNED DEFAULT NULL,
  28. sys_insert_datetime datetime DEFAULT NULL,
  29. sys_lastedit_user_id int UNSIGNED DEFAULT NULL,
  30. sys_lastedit_datetime datetime DEFAULT NULL,
  31. PRIMARY KEY (id))";
  32. Database::query($sql);
  33. //Default Categories
  34. $categoRow = array(
  35. $objPlugin->get_lang('Enrollment') => $objPlugin->get_lang('TicketsAboutEnrollment'),
  36. $objPlugin->get_lang('GeneralInformation') => $objPlugin->get_lang('TicketsAboutGeneralInformation'),
  37. $objPlugin->get_lang('RequestAndPapework') => $objPlugin->get_lang('TicketsAboutRequestAndPapework'),
  38. $objPlugin->get_lang('AcademicIncidence') => $objPlugin->get_lang('TicketsAboutAcademicIncidence'),
  39. $objPlugin->get_lang('VirtualCampus') => $objPlugin->get_lang('TicketsAboutVirtualCampus'),
  40. $objPlugin->get_lang('OnlineEvaluation') => $objPlugin->get_lang('TicketsAboutOnlineEvaluation')
  41. );
  42. $i = 1;
  43. foreach ($categoRow as $category => $description) {
  44. //Online evaluation requires a course
  45. if ($i == 6) {
  46. $attributes = array(
  47. 'id' => $i,
  48. 'category_id' => $i,
  49. 'name' => $category,
  50. 'description' => $description,
  51. 'project_id' => 1,
  52. 'course_required' => 1
  53. );
  54. } else {
  55. $attributes = array(
  56. 'id' => $i,
  57. 'category_id' => $i,
  58. 'project_id' => 1,
  59. 'description' => $description,
  60. 'name' => $category
  61. );
  62. }
  63. Database::insert($table, $attributes);
  64. $i++;
  65. }
  66. $table = Database::get_main_table(TABLE_TICKET_MESSAGE);
  67. $sql = "CREATE TABLE IF NOT EXISTS ".$table." (
  68. id int UNSIGNED NOT NULL AUTO_INCREMENT,
  69. message_id int UNSIGNED NOT NULL,
  70. ticket_id int UNSIGNED NOT NULL,
  71. subject varchar(150) DEFAULT NULL,
  72. message text NOT NULL,
  73. status char(3) NOT NULL,
  74. ip_address varchar(16) DEFAULT NULL,
  75. sys_insert_user_id int UNSIGNED DEFAULT NULL,
  76. sys_insert_datetime datetime DEFAULT NULL,
  77. sys_lastedit_user_id int UNSIGNED DEFAULT NULL,
  78. sys_lastedit_datetime datetime DEFAULT NULL,
  79. PRIMARY KEY (id),
  80. KEY FK_tick_message (ticket_id) )";
  81. Database::query($sql);
  82. $table = Database::get_main_table(TABLE_TICKET_MESSAGE_ATTACHMENTS);
  83. $sql = "CREATE TABLE IF NOT EXISTS ".$table." (
  84. id int UNSIGNED NOT NULL AUTO_INCREMENT,
  85. message_attch_id char(2) NOT NULL,
  86. message_id char(2) NOT NULL,
  87. ticket_id int UNSIGNED NOT NULL,
  88. path varchar(255) NOT NULL,
  89. filename varchar(255) NOT NULL,
  90. size varchar(25) DEFAULT NULL,
  91. sys_insert_user_id int UNSIGNED DEFAULT NULL,
  92. sys_insert_datetime datetime DEFAULT NULL,
  93. sys_lastedit_user_id int UNSIGNED DEFAULT NULL,
  94. sys_lastedit_datetime datetime DEFAULT NULL,
  95. PRIMARY KEY (id),
  96. KEY ticket_message_id_fk (message_id))";
  97. Database::query($sql);
  98. //Priority
  99. $table = Database::get_main_table(TABLE_TICKET_PRIORITY);
  100. $sql = "CREATE TABLE IF NOT EXISTS ".$table." (
  101. id int UNSIGNED NOT NULL AUTO_INCREMENT,
  102. priority_id char(3) NOT NULL,
  103. priority varchar(20) DEFAULT NULL,
  104. priority_desc varchar(250) DEFAULT NULL,
  105. priority_color varchar(25) DEFAULT NULL,
  106. priority_urgency tinyint DEFAULT NULL,
  107. sys_insert_user_id int UNSIGNED DEFAULT NULL,
  108. sys_insert_datetime datetime DEFAULT NULL,
  109. sys_lastedit_user_id int UNSIGNED DEFAULT NULL,
  110. sys_lastedit_datetime datetime DEFAULT NULL,
  111. PRIMARY KEY (id))";
  112. Database::query($sql);
  113. //Default Priorities
  114. $defaultPriorities = array(
  115. 'NRM' => $objPlugin->get_lang('PriorityNormal'),
  116. 'HGH' => $objPlugin->get_lang('PriorityHigh'),
  117. 'LOW' => $objPlugin->get_lang('PriorityLow')
  118. );
  119. $i = 1;
  120. foreach ($defaultPriorities as $pId => $priority) {
  121. $attributes = array(
  122. 'id' => $i,
  123. 'priority_id' => $pId,
  124. 'priority' => $priority,
  125. 'priority_desc' => $priority
  126. );
  127. Database::insert($table, $attributes);
  128. $i++;
  129. }
  130. $table = Database::get_main_table(TABLE_TICKET_PROJECT);
  131. $sql = "CREATE TABLE IF NOT EXISTS ".$table." (
  132. id int UNSIGNED NOT NULL AUTO_INCREMENT,
  133. project_id char(3) NOT NULL,
  134. name varchar(50) DEFAULT NULL,
  135. description varchar(250) DEFAULT NULL,
  136. email varchar(50) DEFAULT NULL,
  137. other_area tinyint NOT NULL DEFAULT '0',
  138. sys_insert_user_id int UNSIGNED DEFAULT NULL,
  139. sys_insert_datetime datetime DEFAULT NULL,
  140. sys_lastedit_user_id int UNSIGNED DEFAULT NULL,
  141. sys_lastedit_datetime datetime DEFAULT NULL,
  142. PRIMARY KEY (id))";
  143. Database::query($sql);
  144. //Default Project Table Ticket
  145. $attributes = array(
  146. 'id' => 1,
  147. 'project_id' => 1,
  148. 'name' => 'Ticket System'
  149. );
  150. Database::insert($table, $attributes);
  151. //STATUS
  152. $table = Database::get_main_table(TABLE_TICKET_STATUS);
  153. $sql = "CREATE TABLE IF NOT EXISTS ".$table." (
  154. id int UNSIGNED NOT NULL AUTO_INCREMENT,
  155. status_id char(3) NOT NULL,
  156. name varchar(100) NOT NULL,
  157. description varchar(255) DEFAULT NULL,
  158. PRIMARY KEY (id))";
  159. Database::query($sql);
  160. //Default status
  161. $defaultStatus = array(
  162. 'NAT' => $objPlugin->get_lang('StatusNew'),
  163. 'PND' => $objPlugin->get_lang('StatusPending'),
  164. 'XCF' => $objPlugin->get_lang('StatusUnconfirmed'),
  165. 'CLS' => $objPlugin->get_lang('StatusClose'),
  166. 'REE' => $objPlugin->get_lang('StatusForwarded')
  167. );
  168. $i = 1;
  169. foreach ($defaultStatus as $abr => $status) {
  170. $attributes = array(
  171. 'id' => $i,
  172. 'status_id' => $abr,
  173. 'name' => $status
  174. );
  175. Database::insert($table, $attributes);
  176. $i ++;
  177. }
  178. $table = Database::get_main_table(TABLE_TICKET_TICKET);
  179. $sql = "CREATE TABLE IF NOT EXISTS ".$table." (
  180. ticket_id int UNSIGNED NOT NULL AUTO_INCREMENT,
  181. ticket_code char(12) DEFAULT NULL,
  182. project_id char(3) DEFAULT NULL,
  183. category_id char(3) NOT NULL,
  184. priority_id char(3) NOT NULL,
  185. course_id int UNSIGNED NOT NULL,
  186. session_id int UNSIGNED NOT NULL DEFAULT '0',
  187. request_user int UNSIGNED NOT NULL,
  188. personal_email varchar(150) DEFAULT NULL,
  189. assigned_last_user int UNSIGNED NOT NULL DEFAULT '0',
  190. status_id char(3) NOT NULL,
  191. total_messages int UNSIGNED NOT NULL DEFAULT '0',
  192. keyword varchar(250) DEFAULT NULL,
  193. source char(3) NOT NULL,
  194. start_date datetime NOT NULL,
  195. end_date datetime DEFAULT NULL,
  196. sys_insert_user_id int UNSIGNED DEFAULT NULL,
  197. sys_insert_datetime datetime DEFAULT NULL,
  198. sys_lastedit_user_id int UNSIGNED DEFAULT NULL,
  199. sys_lastedit_datetime datetime DEFAULT NULL,
  200. PRIMARY KEY (ticket_id),
  201. UNIQUE KEY UN_ticket_code (ticket_code),
  202. KEY FK_ticket_priority (priority_id),
  203. KEY FK_ticket_category (project_id,category_id))";
  204. Database::query($sql);
  205. $table = Database::get_main_table(TABLE_TICKET_CATEGORY_REL_USER);
  206. $sql = "CREATE TABLE IF NOT EXISTS ".$table." (
  207. id int UNSIGNED PRIMARY KEY NOT NULL AUTO_INCREMENT,
  208. category_id INT NOT NULL,
  209. user_id INT NOT NULL
  210. )";
  211. //Menu main tabs
  212. $rsTab = $objPlugin->addTab('Ticket', 'plugin/ticket/src/myticket.php');
  213. if ($rsTab) {
  214. echo "<script>location.href = '" . $_SERVER['REQUEST_URI'] . "';</script>";
  215. }