database.php 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225
  1. <?php
  2. /**
  3. * Contains the SQL for the tickets management plugin database structure
  4. */
  5. $objPlugin = TicketPlugin::create();
  6. $table = Database::get_main_table(TABLE_TICKET_ASSIGNED_LOG);
  7. $sql = "CREATE TABLE IF NOT EXISTS ".$table." (
  8. id int UNSIGNED NOT NULL AUTO_INCREMENT,
  9. ticket_id int UNSIGNED DEFAULT NULL,
  10. user_id int UNSIGNED DEFAULT NULL,
  11. assigned_date datetime DEFAULT NULL,
  12. sys_insert_user_id int UNSIGNED DEFAULT NULL,
  13. PRIMARY KEY PK_ticket_assigned_log (id),
  14. KEY FK_ticket_assigned_log (ticket_id))";
  15. Database::query($sql);
  16. //Category
  17. $table = Database::get_main_table(TABLE_TICKET_CATEGORY);
  18. $sql = "CREATE TABLE IF NOT EXISTS ".$table." (
  19. id int UNSIGNED NOT NULL AUTO_INCREMENT,
  20. category_id char(3) NOT NULL,
  21. project_id char(3) NOT NULL,
  22. name varchar(100) NOT NULL,
  23. description varchar(255) NOT NULL,
  24. total_tickets int UNSIGNED NOT NULL DEFAULT '0',
  25. course_required char(1) NOT NULL,
  26. sys_insert_user_id int UNSIGNED DEFAULT NULL,
  27. sys_insert_datetime datetime DEFAULT NULL,
  28. sys_lastedit_user_id int UNSIGNED DEFAULT NULL,
  29. sys_lastedit_datetime datetime DEFAULT NULL,
  30. PRIMARY KEY (id))";
  31. Database::query($sql);
  32. //Default Categories
  33. $categoRow = array(
  34. $objPlugin->get_lang('Enrollment') => $objPlugin->get_lang('TicketsAboutEnrollment'),
  35. $objPlugin->get_lang('GeneralInformation') => $objPlugin->get_lang('TicketsAboutGeneralInformation'),
  36. $objPlugin->get_lang('RequestAndPapework') => $objPlugin->get_lang('TicketsAboutRequestAndPapework'),
  37. $objPlugin->get_lang('AcademicIncidence') => $objPlugin->get_lang('TicketsAboutAcademicIncidence'),
  38. $objPlugin->get_lang('VirtualCampus') => $objPlugin->get_lang('TicketsAboutVirtualCampus'),
  39. $objPlugin->get_lang('OnlineEvaluation') => $objPlugin->get_lang('TicketsAboutOnlineEvaluation')
  40. );
  41. $i = 1;
  42. foreach ($categoRow as $category => $description) {
  43. //Online evaluation requires a course
  44. if ($i == 6) {
  45. $attributes = array(
  46. 'id' => $i,
  47. 'category_id' => $i,
  48. 'name' => $category,
  49. 'description' => $description,
  50. 'project_id' => 1,
  51. 'course_required' => 1
  52. );
  53. } else {
  54. $attributes = array(
  55. 'id' => $i,
  56. 'category_id' => $i,
  57. 'project_id' => 1,
  58. 'description' => $description,
  59. 'name' => $category
  60. );
  61. }
  62. Database::insert($table, $attributes);
  63. $i++;
  64. }
  65. //END default categories
  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. //End
  131. $table = Database::get_main_table(TABLE_TICKET_PROJECT);
  132. $sql = "CREATE TABLE IF NOT EXISTS ".$table." (
  133. id int UNSIGNED NOT NULL AUTO_INCREMENT,
  134. project_id char(3) NOT NULL,
  135. name varchar(50) DEFAULT NULL,
  136. description varchar(250) DEFAULT NULL,
  137. email varchar(50) DEFAULT NULL,
  138. other_area tinyint NOT NULL DEFAULT '0',
  139. sys_insert_user_id int UNSIGNED DEFAULT NULL,
  140. sys_insert_datetime datetime DEFAULT NULL,
  141. sys_lastedit_user_id int UNSIGNED DEFAULT NULL,
  142. sys_lastedit_datetime datetime DEFAULT NULL,
  143. PRIMARY KEY (id))";
  144. Database::query($sql);
  145. //Default Project Table Ticket
  146. $attributes = array(
  147. 'id' => 1,
  148. 'project_id' => 1,
  149. 'name' => 'Ticket System'
  150. );
  151. Database::insert($table, $attributes);
  152. //END
  153. //STATUS
  154. $table = Database::get_main_table(TABLE_TICKET_STATUS);
  155. $sql = "CREATE TABLE IF NOT EXISTS ".$table." (
  156. id int UNSIGNED NOT NULL AUTO_INCREMENT,
  157. status_id char(3) NOT NULL,
  158. name varchar(100) NOT NULL,
  159. description varchar(255) DEFAULT NULL,
  160. PRIMARY KEY (id))";
  161. Database::query($sql);
  162. //Default status
  163. $defaultStatus = array(
  164. 'NAT' => $objPlugin->get_lang('StatusNew'),
  165. 'PND' => $objPlugin->get_lang('StatusPending'),
  166. 'XCF' => $objPlugin->get_lang('StatusUnconfirmed'),
  167. 'CLS' => $objPlugin->get_lang('StatusClose'),
  168. 'REE' => $objPlugin->get_lang('StatusForwarded')
  169. );
  170. $i = 1;
  171. foreach ($defaultStatus as $abr => $status) {
  172. $attributes = array(
  173. 'id' => $i,
  174. 'status_id' => $abr,
  175. 'name' => $status
  176. );
  177. Database::insert($table, $attributes);
  178. $i ++;
  179. }
  180. //END
  181. $table = Database::get_main_table(TABLE_TICKET_TICKET);
  182. $sql = "CREATE TABLE IF NOT EXISTS ".$table." (
  183. ticket_id int UNSIGNED NOT NULL AUTO_INCREMENT,
  184. ticket_code char(12) DEFAULT NULL,
  185. project_id char(3) DEFAULT NULL,
  186. category_id char(3) NOT NULL,
  187. priority_id char(3) NOT NULL,
  188. course_id int UNSIGNED NOT NULL,
  189. session_id int UNSIGNED NOT NULL DEFAULT '0',
  190. request_user int UNSIGNED NOT NULL,
  191. personal_email varchar(150) DEFAULT NULL,
  192. assigned_last_user int UNSIGNED NOT NULL DEFAULT '0',
  193. status_id char(3) NOT NULL,
  194. total_messages int UNSIGNED NOT NULL DEFAULT '0',
  195. keyword varchar(250) DEFAULT NULL,
  196. source char(3) NOT NULL,
  197. start_date datetime NOT NULL,
  198. end_date datetime DEFAULT NULL,
  199. sys_insert_user_id int UNSIGNED DEFAULT NULL,
  200. sys_insert_datetime datetime DEFAULT NULL,
  201. sys_lastedit_user_id int UNSIGNED DEFAULT NULL,
  202. sys_lastedit_datetime datetime DEFAULT NULL,
  203. PRIMARY KEY (ticket_id),
  204. UNIQUE KEY UN_ticket_code (ticket_code),
  205. KEY FK_ticket_priority (priority_id),
  206. KEY FK_ticket_category (project_id,category_id))";
  207. Database::query($sql);
  208. //Menu main tabs
  209. $rsTab = $objPlugin->addTab('Ticket', 'plugin/ticket/src/myticket.php');
  210. if ($rsTab) {
  211. echo "<script>location.href = '" . $_SERVER['REQUEST_URI'] . "';</script>";
  212. }