Bootswatch, Summernote, and Captcheck mods for Mods for HESK (mods-for-hesk.com). In use at support.netsyms.com.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

database-validation.php 14KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257
  1. <?php
  2. define('IN_SCRIPT', 1);
  3. define('HESK_PATH', '../../');
  4. require(HESK_PATH . 'install/install_functions.inc.php');
  5. require(HESK_PATH . 'hesk_settings.inc.php');
  6. hesk_dbConnect();
  7. ?>
  8. <html>
  9. <head>
  10. <title>Mods For HESK Database Validation</title>
  11. <link href="../../hesk_style.css?<?php echo HESK_NEW_VERSION; ?>" type="text/css" rel="stylesheet"/>
  12. <link href="<?php echo HESK_PATH; ?>css/bootstrap.css?v=<?php echo $hesk_settings['hesk_version']; ?>"
  13. type="text/css" rel="stylesheet"/>
  14. <link href="<?php echo HESK_PATH; ?>css/bootstrap-theme.css?v=<?php echo $hesk_settings['hesk_version']; ?>"
  15. type="text/css" rel="stylesheet"/>
  16. <link href="//netdna.bootstrapcdn.com/font-awesome/4.3.0/css/font-awesome.min.css" rel="stylesheet">
  17. <link href="../../css/hesk_newStyle.css" type="text/css" rel="stylesheet"/>
  18. <script src="<?php echo HESK_PATH; ?>js/jquery-1.10.2.min.js"></script>
  19. <script language="Javascript" type="text/javascript" src="<?php echo HESK_PATH; ?>js/bootstrap.min.js"></script>
  20. <script language="Javascript" type="text/javascript"
  21. src="<?php echo HESK_PATH; ?>js/modsForHesk-javascript.js"></script>
  22. </head>
  23. <body>
  24. <div class="headersm">Mods for HESK Database Validation</div>
  25. <div class="container">
  26. <div class="page-header">
  27. <h1>Mods for HESK Database Validation</h1>
  28. <p>The database validation tool will check your database setup to ensure that everything is set up correctly.
  29. As of this time, the database validator assumes you are running the latest version of Mods for HESK (<?php echo MODS_FOR_HESK_NEW_VERSION; ?>)</p>
  30. </div>
  31. <div class="panel panel-success" id="all-good" style="display: none">
  32. <div class="panel-heading">
  33. <h4>Success</h4>
  34. </div>
  35. <div class="panel-body text-center">
  36. <i class="fa fa-check-circle fa-4x" style="color: green"></i><br>
  37. <h4>Your database is valid</h4>
  38. </div>
  39. </div>
  40. <div class="panel panel-danger" id="not-good" style="display: none">
  41. <div class="panel-heading">
  42. <h4>Failure</h4>
  43. </div>
  44. <div class="panel-body text-center">
  45. <i class="fa fa-times-circle fa-4x" style="color: red"></i><br>
  46. <h4>One or more columns / tables are not properly configured in your database. Please open a topic at the
  47. <a href="http://developers.phpjunkyard.com/viewforum.php?f=19" target="_blank">PHP Junkyard Forums</a> with this information for assistance.</h4>
  48. </div>
  49. </div>
  50. <div class="panel panel-default">
  51. <div class="panel-heading">
  52. <h4>Results</h4>
  53. </div>
  54. <table class="table table-striped">
  55. <thead>
  56. <tr>
  57. <th>Database Change</th>
  58. <th>Status</th>
  59. </tr>
  60. </thead>
  61. <tbody>
  62. <?php
  63. $all_good = true;
  64. output_header_row('1.0.0 - 1.3.x');
  65. $all_good = run_table_check('statuses');
  66. $all_good = $all_good & run_column_check('statuses', 'ID');
  67. $all_good = $all_good & run_column_check('statuses', 'TextColor');
  68. $all_good = $all_good & run_column_check('statuses', 'IsNewTicketStatus');
  69. $all_good = $all_good & run_column_check('statuses', 'IsClosed');
  70. $all_good = $all_good & run_column_check('statuses', 'IsClosedByClient');
  71. $all_good = $all_good & run_column_check('statuses', 'IsCustomerReplyStatus');
  72. $all_good = $all_good & run_column_check('statuses', 'IsStaffClosedOption');
  73. $all_good = $all_good & run_column_check('statuses', 'IsStaffReopenedStatus');
  74. $all_good = $all_good & run_column_check('statuses', 'IsDefaultStaffReplyStatus');
  75. $all_good = $all_good & run_column_check('statuses', 'LockedTicketStatus');
  76. $all_good = $all_good & run_column_check('statuses', 'IsAutocloseOption');
  77. $all_good = $all_good & run_column_check('statuses', 'Closable');
  78. output_header_row('1.5.0');
  79. $all_good = $all_good & run_column_check('users', 'active');
  80. $all_good = $all_good & run_column_check('users', 'notify_note_unassigned');
  81. output_header_row('1.6.0');
  82. $all_good = $all_good & run_table_check('settings');
  83. output_header_row('1.7.0');
  84. $all_good = $all_good & run_table_check('verified_emails');
  85. $all_good = $all_good & run_table_check('pending_verification_emails');
  86. $all_good = $all_good & run_table_check('stage_tickets');
  87. output_header_row('2.3.0');
  88. $all_good = $all_good & run_column_check('service_messages', 'icon');
  89. $all_good = $all_good & run_column_check('statuses', 'Key');
  90. $all_good = $all_good & run_column_check('tickets', 'latitude');
  91. $all_good = $all_good & run_column_check('tickets', 'longitude');
  92. $all_good = $all_good & run_column_check('stage_tickets', 'latitude');
  93. $all_good = $all_good & run_column_check('stage_tickets', 'longitude');
  94. $all_good = $all_good & run_column_check('categories', 'manager');
  95. $all_good = $all_good & run_column_check('users', 'permission_template');
  96. $all_good = $all_good & run_table_check('permission_templates');
  97. $all_good = $all_good & run_column_check('permission_templates', 'id');
  98. $all_good = $all_good & run_column_check('permission_templates', 'name');
  99. $all_good = $all_good & run_column_check('permission_templates', 'heskprivileges');
  100. $all_good = $all_good & run_column_check('permission_templates', 'categories');
  101. output_header_row('2.4.0');
  102. $all_good = $all_good & run_table_check('quick_help_sections');
  103. $all_good = $all_good & run_column_check('quick_help_sections', 'id');
  104. $all_good = $all_good & run_column_check('quick_help_sections', 'location');
  105. $all_good = $all_good & run_column_check('quick_help_sections', 'show');
  106. $all_good = $all_good & run_table_check('text_to_status_xref');
  107. $all_good = $all_good & run_column_check('text_to_status_xref', 'id');
  108. $all_good = $all_good & run_column_check('text_to_status_xref', 'language');
  109. $all_good = $all_good & run_column_check('text_to_status_xref', 'text');
  110. $all_good = $all_good & run_column_check('text_to_status_xref', 'status_id');
  111. $all_good = $all_good & run_column_check('statuses', 'sort');
  112. $all_good = $all_good & run_column_check('attachments', 'download_count');
  113. $all_good = $all_good & run_column_check('kb_attachments', 'download_count');
  114. $all_good = $all_good & run_column_check('tickets', 'html');
  115. $all_good = $all_good & run_column_check('stage_tickets', 'html');
  116. $all_good = $all_good & run_column_check('replies', 'html');
  117. output_header_row('2.5.0');
  118. $all_good = $all_good & run_column_check('tickets', 'user_agent');
  119. $all_good = $all_good & run_column_check('tickets', 'screen_resolution_width');
  120. $all_good = $all_good & run_column_check('tickets', 'screen_resolution_height');
  121. $all_good = $all_good & run_column_check('stage_tickets', 'user_agent');
  122. $all_good = $all_good & run_column_check('stage_tickets', 'screen_resolution_width');
  123. $all_good = $all_good & run_column_check('stage_tickets', 'screen_resolution_height');
  124. output_header_row('2.6.0');
  125. $all_good = $all_good & run_table_check('logging');
  126. $all_good = $all_good & run_column_check('logging', 'id');
  127. $all_good = $all_good & run_column_check('logging', 'username');
  128. $all_good = $all_good & run_column_check('logging', 'message');
  129. $all_good = $all_good & run_column_check('logging', 'severity');
  130. $all_good = $all_good & run_column_check('logging', 'location');
  131. $all_good = $all_good & run_column_check('logging', 'timestamp');
  132. $all_good = $all_good & run_table_check('user_api_tokens');
  133. $all_good = $all_good & run_column_check('user_api_tokens', 'id');
  134. $all_good = $all_good & run_column_check('user_api_tokens', 'user_id');
  135. $all_good = $all_good & run_column_check('user_api_tokens', 'token');
  136. $all_good = $all_good & run_table_check('temp_attachment');
  137. $all_good = $all_good & run_column_check('temp_attachment', 'id');
  138. $all_good = $all_good & run_column_check('temp_attachment', 'file_name');
  139. $all_good = $all_good & run_column_check('temp_attachment', 'saved_name');
  140. $all_good = $all_good & run_column_check('temp_attachment', 'size');
  141. $all_good = $all_good & run_column_check('temp_attachment', 'type');
  142. $all_good = $all_good & run_column_check('temp_attachment', 'date_uploaded');
  143. $all_good = $all_good & run_table_check('calendar_event');
  144. $all_good = $all_good & run_column_check('calendar_event', 'id');
  145. $all_good = $all_good & run_column_check('calendar_event', 'start');
  146. $all_good = $all_good & run_column_check('calendar_event', 'end');
  147. $all_good = $all_good & run_column_check('calendar_event', 'all_day');
  148. $all_good = $all_good & run_column_check('calendar_event', 'name');
  149. $all_good = $all_good & run_column_check('calendar_event', 'location');
  150. $all_good = $all_good & run_column_check('calendar_event', 'comments');
  151. $all_good = $all_good & run_column_check('calendar_event', 'category');
  152. $all_good = $all_good & run_table_check('calendar_event_reminder');
  153. $all_good = $all_good & run_column_check('calendar_event_reminder', 'id');
  154. $all_good = $all_good & run_column_check('calendar_event_reminder', 'user_id');
  155. $all_good = $all_good & run_column_check('calendar_event_reminder', 'event_id');
  156. $all_good = $all_good & run_column_check('calendar_event_reminder', 'amount');
  157. $all_good = $all_good & run_column_check('calendar_event_reminder', 'unit');
  158. $all_good = $all_good & run_column_check('calendar_event_reminder', 'email_sent');
  159. $all_good = $all_good & run_column_check('tickets', 'due_date');
  160. $all_good = $all_good & run_column_check('tickets', 'overdue_email_sent');
  161. $all_good = $all_good & run_column_check('categories', 'usage');
  162. $all_good = $all_good & run_column_check('users', 'notify_overdue_unassigned');
  163. $all_good = $all_good & run_column_check('users', 'default_calendar_view');
  164. output_header_row('2.6.2');
  165. $all_good = $all_good & run_column_check('stage_tickets', 'due_date');
  166. $all_good = $all_good & run_column_check('stage_tickets', 'overdue_email_sent');
  167. output_header_row('3.1.0');
  168. $all_good = $all_good & run_column_check('categories', 'background_color');
  169. $all_good = $all_good & run_column_check('categories', 'foreground_color');
  170. $all_good = $all_good & run_column_check('categories', 'display_border_outline');
  171. $all_good = $all_good & run_column_check('logging', 'stack_trace');
  172. $all_good = $all_good & run_table_check('custom_nav_element');
  173. $all_good = $all_good & run_column_check('custom_nav_element', 'id');
  174. $all_good = $all_good & run_column_check('custom_nav_element', 'image_url');
  175. $all_good = $all_good & run_column_check('custom_nav_element', 'font_icon');
  176. $all_good = $all_good & run_column_check('custom_nav_element', 'place');
  177. $all_good = $all_good & run_column_check('custom_nav_element', 'url');
  178. $all_good = $all_good & run_column_check('custom_nav_element', 'sort');
  179. $all_good = $all_good & run_table_check('custom_nav_element_to_text');
  180. $all_good = $all_good & run_column_check('custom_nav_element_to_text', 'id');
  181. $all_good = $all_good & run_column_check('custom_nav_element_to_text', 'nav_element_id');
  182. $all_good = $all_good & run_column_check('custom_nav_element_to_text', 'language');
  183. $all_good = $all_good & run_column_check('custom_nav_element_to_text', 'text');
  184. $all_good = $all_good & run_column_check('custom_nav_element_to_text', 'subtext');
  185. if ($all_good) {
  186. echo "<script>$('#all-good').show()</script>";
  187. } else {
  188. echo "<script>$('#not-good').show()</script>";
  189. }
  190. ?>
  191. </tbody>
  192. </table>
  193. </div>
  194. </div>
  195. </body>
  196. </html>
  197. <?php
  198. function run_table_check($table_name) {
  199. return run_column_check($table_name, '1');
  200. }
  201. function run_column_check($table_name, $column_name) {
  202. global $hesk_settings;
  203. if ($column_name == '1') {
  204. $all_good = run_check('SELECT ' . $column_name . ' FROM `' . $hesk_settings['db_pfix'] . $table_name . '` LIMIT 1');
  205. output_result('<b>Table Exists</b>: ' . $table_name,
  206. $all_good);
  207. } else {
  208. $all_good = run_check('SELECT `' . $column_name . '` FROM `' . $hesk_settings['db_pfix'] . $table_name . '` LIMIT 1');
  209. output_result('<b>Column Exists</b>: ' . $table_name . '.' . $column_name,
  210. $all_good);
  211. }
  212. return $all_good !== false;
  213. }
  214. function run_check($sql) {
  215. global $hesk_last_query;
  216. global $hesk_db_link;
  217. if (function_exists('mysqli_connect')) {
  218. if (!$hesk_db_link && !hesk_dbConnect()) {
  219. return false;
  220. }
  221. $hesk_last_query = $sql;
  222. return @mysqli_query($hesk_db_link, $sql);
  223. } else {
  224. if (!$hesk_db_link && !hesk_dbConnect()) {
  225. return false;
  226. }
  227. $hesk_last_query = $sql;
  228. return $res = @mysql_query($sql, $hesk_db_link);
  229. }
  230. }
  231. function output_result($change_title, $success) {
  232. $css_color = 'green';
  233. $text = '<span data-toggle="tooltip" title="This looks good!"><i class="fa fa-check-circle"></i> Success</span>';
  234. if (!$success) {
  235. $css_color = 'red';
  236. $text = '<span data-toggle="tooltip" title="Oh no! Something isn\'t right."><i class="fa fa-times-circle"></i> Failure</span>';
  237. }
  238. $formatted_text = sprintf('<tr><td>%s</td><td style="color: %s">%s</td></tr>', $change_title, $css_color, $text);
  239. echo $formatted_text;
  240. }
  241. function output_header_row($text) {
  242. echo '<tr><td colspan="2" style="font-size: 1.2em"><i class="fa fa-chevron-right"></i> ' . $text . '</td></tr>';
  243. }