database.php 9.0 KB

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