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.

install.php 27KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626
  1. <?php
  2. /*******************************************************************************
  3. * Title: Help Desk Software HESK
  4. * Version: 2.6.8 from 10th August 2016
  5. * Author: Klemen Stirn
  6. * Website: https://www.hesk.com
  7. ********************************************************************************
  8. * COPYRIGHT AND TRADEMARK NOTICE
  9. * Copyright 2005-2015 Klemen Stirn. All Rights Reserved.
  10. * HESK is a registered trademark of Klemen Stirn.
  11. * The HESK may be used and modified free of charge by anyone
  12. * AS LONG AS COPYRIGHT NOTICES AND ALL THE COMMENTS REMAIN INTACT.
  13. * By using this code you agree to indemnify Klemen Stirn from any
  14. * liability that might arise from it's use.
  15. * Selling the code for this program, in part or full, without prior
  16. * written consent is expressly forbidden.
  17. * Using this code, in part or full, to create derivate work,
  18. * new scripts or products is expressly forbidden. Obtain permission
  19. * before redistributing this software over the Internet or in
  20. * any other medium. In all cases copyright and header must remain intact.
  21. * This Copyright is in full effect in any country that has International
  22. * Trade Agreements with the United States of America or
  23. * with the European Union.
  24. * Removing any of the copyright notices without purchasing a license
  25. * is expressly forbidden. To remove HESK copyright notice you must purchase
  26. * a license for this script. For more information on how to obtain
  27. * a license please visit the page below:
  28. * https://www.hesk.com/buy.php
  29. *******************************************************************************/
  30. define('IN_SCRIPT',1);
  31. define('HESK_PATH','../');
  32. define('INSTALL_PAGE', 'install.php');
  33. require(HESK_PATH . 'install/install_functions.inc.php');
  34. // If no step is defined, start with step 1
  35. if ( ! isset($_SESSION['step']) )
  36. {
  37. $_SESSION['step']=1;
  38. }
  39. // Check if the license has been agreed to and verify sessions are working
  40. elseif ($_SESSION['step']==1)
  41. {
  42. $agree = hesk_POST('agree', '');
  43. if ($agree == 'YES')
  44. {
  45. // Are sessions working?
  46. if ( empty($_SESSION['works']) )
  47. {
  48. hesk_iSessionError();
  49. }
  50. // All OK, continue
  51. $_SESSION['license_agree']=1;
  52. $_SESSION['step']=2;
  53. }
  54. else
  55. {
  56. $_SESSION['step']=1;
  57. }
  58. }
  59. // Test database connection?
  60. if ($_SESSION['step'] == 3 && isset($_POST['dbtest']))
  61. {
  62. // Username
  63. $_SESSION['admin_user'] = hesk_input( hesk_POST('admin_user') );
  64. if ( strlen($_SESSION['admin_user']) == 0 )
  65. {
  66. $_SESSION['admin_user'] = 'Administrator';
  67. }
  68. // Password
  69. $_SESSION['admin_pass'] = hesk_input( hesk_POST('admin_pass') );
  70. if ( strlen($_SESSION['admin_pass']) == 0 )
  71. {
  72. $_SESSION['admin_pass'] = substr(str_shuffle("23456789abcdefghijkmnpqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"), 0, mt_rand(8,12) );
  73. }
  74. // Password hash for the database
  75. $_SESSION['admin_hash'] = hesk_Pass2Hash($_SESSION['admin_pass']);
  76. $hesk_db_link = hesk_iTestDatabaseConnection();
  77. // Get table prefix, don't allow any special chars
  78. $hesk_settings['db_pfix'] = preg_replace('/[^0-9a-zA-Z_]/', '', hesk_POST('pfix', 'hesk_') );
  79. // Generate HESK table names
  80. $hesk_tables = array(
  81. $hesk_settings['db_pfix'].'attachments',
  82. $hesk_settings['db_pfix'].'banned_emails',
  83. $hesk_settings['db_pfix'].'banned_ips',
  84. $hesk_settings['db_pfix'].'categories',
  85. $hesk_settings['db_pfix'].'kb_articles',
  86. $hesk_settings['db_pfix'].'kb_attachments',
  87. $hesk_settings['db_pfix'].'kb_categories',
  88. $hesk_settings['db_pfix'].'logins',
  89. $hesk_settings['db_pfix'].'mail',
  90. $hesk_settings['db_pfix'].'notes',
  91. $hesk_settings['db_pfix'].'online',
  92. $hesk_settings['db_pfix'].'pipe_loops',
  93. $hesk_settings['db_pfix'].'replies',
  94. $hesk_settings['db_pfix'].'reply_drafts',
  95. $hesk_settings['db_pfix'].'reset_password',
  96. $hesk_settings['db_pfix'].'service_messages',
  97. $hesk_settings['db_pfix'].'std_replies',
  98. $hesk_settings['db_pfix'].'tickets',
  99. $hesk_settings['db_pfix'].'ticket_templates',
  100. $hesk_settings['db_pfix'].'users',
  101. );
  102. // Check if any of the HESK tables exists
  103. $res = hesk_dbQuery('SHOW TABLES FROM `'.hesk_dbEscape($hesk_settings['db_name']).'`');
  104. while ($row = hesk_dbFetchRow($res))
  105. {
  106. if (in_array($row[0],$hesk_tables))
  107. {
  108. hesk_iDatabase(2);
  109. }
  110. }
  111. // All ok, let's save settings
  112. hesk_iSaveSettings();
  113. // Now install HESK database tables
  114. hesk_iTables();
  115. // And move to the next step
  116. $_SESSION['step']=4;
  117. }
  118. // Which step are we at?
  119. switch ($_SESSION['step'])
  120. {
  121. case 2:
  122. hesk_iCheckSetup();
  123. break;
  124. case 3:
  125. hesk_iDatabase();
  126. break;
  127. case 4:
  128. hesk_iFinish();
  129. break;
  130. default:
  131. hesk_iStart();
  132. }
  133. // ******* FUNCTIONS ******* //
  134. function hesk_iFinish()
  135. {
  136. global $hesk_settings;
  137. hesk_iHeader();
  138. ?>
  139. <div class="row">
  140. <div class="col-md-4">
  141. <div class="panel panel-default">
  142. <div class="panel-heading">
  143. <p>Summary</p>
  144. </div>
  145. <div class="panel-body">
  146. <p>Congratulations, you have successfully completed HESK database setup!</p>
  147. </div>
  148. </div>
  149. </div>
  150. <div class="col-md-8">
  151. <div class="alert alert-success"><strong>Success!</strong> HESK Successfully installed</div>
  152. <div class="h3">Next Steps:<br/><br/></div>
  153. <ol>
  154. <li><span style="color:#ff0000">Don't forget to run the <a href="<?php echo HESK_PATH . 'install/mods-for-hesk/modsForHesk.php'; ?>">Mods for HESK Installation</a>!</li>
  155. <li>Remember your login details:<br />
  156. <pre style="font-size: 1.17em">
  157. Username: <span style="color:red; font-weight:bold"><?php echo stripslashes($_SESSION['admin_user']); ?></span>
  158. Password: <span style="color:red; font-weight:bold"><?php echo stripslashes($_SESSION['admin_pass']); ?></span>
  159. </pre>
  160. </li>
  161. </ol>
  162. <form action="<?php echo HESK_PATH; ?>admin/index.php" method="post">
  163. <input type="hidden" name="a" value="do_login" />
  164. <input type="hidden" name="remember_user" value="JUSTUSER" />
  165. <input type="hidden" name="user" value="<?php echo stripslashes($_SESSION['admin_user']); ?>" />
  166. <input type="hidden" name="pass" value="<?php echo stripslashes($_SESSION['admin_pass']); ?>" />
  167. <input type="hidden" name="goto" value="admin_settings.php" />
  168. <center><button type="submit" class="btn btn-default btn-lg">Login</button></center>
  169. </form>
  170. </div>
  171. </div>
  172. <?php
  173. hesk_iFooter();
  174. } // End hesk_iFinish()
  175. function hesk_iTables()
  176. {
  177. global $hesk_settings;
  178. // -> Attachments
  179. hesk_dbQuery("
  180. CREATE TABLE `".hesk_dbEscape($hesk_settings['db_pfix'])."attachments` (
  181. `att_id` mediumint(8) unsigned NOT NULL AUTO_INCREMENT,
  182. `ticket_id` varchar(13) COLLATE utf8_unicode_ci NOT NULL DEFAULT '',
  183. `saved_name` varchar(255) COLLATE utf8_unicode_ci NOT NULL DEFAULT '',
  184. `real_name` varchar(255) COLLATE utf8_unicode_ci NOT NULL DEFAULT '',
  185. `size` int(10) unsigned NOT NULL DEFAULT '0',
  186. `type` enum('0','1') COLLATE utf8_unicode_ci NOT NULL DEFAULT '0',
  187. PRIMARY KEY (`att_id`),
  188. KEY `ticket_id` (`ticket_id`)
  189. ) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci
  190. ");
  191. // -> Banned emails
  192. hesk_dbQuery("
  193. CREATE TABLE `".hesk_dbEscape($hesk_settings['db_pfix'])."banned_emails` (
  194. `id` smallint(5) unsigned NOT NULL AUTO_INCREMENT,
  195. `email` varchar(255) NOT NULL,
  196. `banned_by` smallint(5) unsigned NOT NULL,
  197. `dt` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
  198. PRIMARY KEY (`id`),
  199. KEY `email` (`email`)
  200. ) ENGINE=MyISAM DEFAULT CHARSET=utf8
  201. ");
  202. // -> Banned IPs
  203. hesk_dbQuery("
  204. CREATE TABLE `".hesk_dbEscape($hesk_settings['db_pfix'])."banned_ips` (
  205. `id` smallint(5) unsigned NOT NULL AUTO_INCREMENT,
  206. `ip_from` int(10) unsigned NOT NULL DEFAULT '0',
  207. `ip_to` int(10) unsigned NOT NULL DEFAULT '0',
  208. `ip_display` varchar(100) NOT NULL,
  209. `banned_by` smallint(5) unsigned NOT NULL,
  210. `dt` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
  211. PRIMARY KEY (`id`)
  212. ) ENGINE=MyISAM DEFAULT CHARSET=utf8
  213. ");
  214. // -> Categories
  215. hesk_dbQuery("
  216. CREATE TABLE `".hesk_dbEscape($hesk_settings['db_pfix'])."categories` (
  217. `id` smallint(5) unsigned NOT NULL AUTO_INCREMENT,
  218. `name` varchar(60) COLLATE utf8_unicode_ci NOT NULL DEFAULT '',
  219. `cat_order` smallint(5) unsigned NOT NULL DEFAULT '0',
  220. `autoassign` enum('0','1') COLLATE utf8_unicode_ci NOT NULL DEFAULT '1',
  221. `type` enum('0','1') COLLATE utf8_unicode_ci NOT NULL DEFAULT '0',
  222. `priority` enum('0','1','2','3') COLLATE utf8_unicode_ci NOT NULL DEFAULT '3',
  223. PRIMARY KEY (`id`),
  224. KEY `type` (`type`)
  225. ) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci
  226. ");
  227. // ---> Insert default category
  228. hesk_dbQuery("INSERT INTO `".hesk_dbEscape($hesk_settings['db_pfix'])."categories` (`id`, `name`, `cat_order`) VALUES (1, 'General', 10)");
  229. // -> KB Articles
  230. hesk_dbQuery("
  231. CREATE TABLE `".hesk_dbEscape($hesk_settings['db_pfix'])."kb_articles` (
  232. `id` smallint(5) unsigned NOT NULL AUTO_INCREMENT,
  233. `catid` smallint(5) unsigned NOT NULL,
  234. `dt` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
  235. `author` smallint(5) unsigned NOT NULL,
  236. `subject` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
  237. `content` mediumtext COLLATE utf8_unicode_ci NOT NULL,
  238. `keywords` mediumtext COLLATE utf8_unicode_ci NOT NULL,
  239. `rating` float NOT NULL DEFAULT '0',
  240. `votes` mediumint(8) unsigned NOT NULL DEFAULT '0',
  241. `views` mediumint(8) unsigned NOT NULL DEFAULT '0',
  242. `type` enum('0','1','2') COLLATE utf8_unicode_ci NOT NULL DEFAULT '0',
  243. `html` enum('0','1') COLLATE utf8_unicode_ci NOT NULL DEFAULT '0',
  244. `sticky` enum('0','1') COLLATE utf8_unicode_ci NOT NULL DEFAULT '0',
  245. `art_order` smallint(5) unsigned NOT NULL DEFAULT '0',
  246. `history` mediumtext COLLATE utf8_unicode_ci NOT NULL,
  247. `attachments` mediumtext COLLATE utf8_unicode_ci NOT NULL,
  248. PRIMARY KEY (`id`),
  249. KEY `catid` (`catid`),
  250. KEY `sticky` (`sticky`),
  251. KEY `type` (`type`),
  252. FULLTEXT KEY `subject` (`subject`,`content`,`keywords`)
  253. ) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci
  254. ");
  255. // -> KB Attachments
  256. hesk_dbQuery("
  257. CREATE TABLE `".hesk_dbEscape($hesk_settings['db_pfix'])."kb_attachments` (
  258. `att_id` mediumint(8) unsigned NOT NULL AUTO_INCREMENT,
  259. `saved_name` varchar(255) COLLATE utf8_unicode_ci NOT NULL DEFAULT '',
  260. `real_name` varchar(255) COLLATE utf8_unicode_ci NOT NULL DEFAULT '',
  261. `size` int(10) unsigned NOT NULL DEFAULT '0',
  262. PRIMARY KEY (`att_id`)
  263. ) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci
  264. ");
  265. // -> KB Categories
  266. hesk_dbQuery("
  267. CREATE TABLE `".hesk_dbEscape($hesk_settings['db_pfix'])."kb_categories` (
  268. `id` smallint(5) unsigned NOT NULL AUTO_INCREMENT,
  269. `name` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
  270. `parent` smallint(5) unsigned NOT NULL,
  271. `articles` smallint(5) unsigned NOT NULL DEFAULT '0',
  272. `articles_private` smallint(5) unsigned NOT NULL DEFAULT '0',
  273. `articles_draft` smallint(5) unsigned NOT NULL DEFAULT '0',
  274. `cat_order` smallint(5) unsigned NOT NULL,
  275. `type` enum('0','1') COLLATE utf8_unicode_ci NOT NULL DEFAULT '0',
  276. PRIMARY KEY (`id`),
  277. KEY `type` (`type`),
  278. KEY `parent` (`parent`)
  279. ) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci
  280. ");
  281. // ---> Insert default KB category
  282. hesk_dbQuery("INSERT INTO `".hesk_dbEscape($hesk_settings['db_pfix'])."kb_categories` (`id`, `name`, `parent`, `cat_order`, `type`) VALUES (1, 'Knowledgebase', 0, 10, '0')");
  283. // -> Login attempts
  284. hesk_dbQuery("
  285. CREATE TABLE `".hesk_dbEscape($hesk_settings['db_pfix'])."logins` (
  286. `ip` varchar(45) COLLATE utf8_unicode_ci NOT NULL,
  287. `number` tinyint(3) unsigned NOT NULL DEFAULT '1',
  288. `last_attempt` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  289. UNIQUE KEY `ip` (`ip`)
  290. ) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci
  291. ");
  292. // -> Private messages
  293. hesk_dbQuery("
  294. CREATE TABLE `".hesk_dbEscape($hesk_settings['db_pfix'])."mail` (
  295. `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  296. `from` smallint(5) unsigned NOT NULL,
  297. `to` smallint(5) unsigned NOT NULL,
  298. `subject` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
  299. `message` mediumtext COLLATE utf8_unicode_ci NOT NULL,
  300. `dt` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
  301. `read` enum('0','1') COLLATE utf8_unicode_ci NOT NULL DEFAULT '0',
  302. `deletedby` smallint(5) unsigned NOT NULL DEFAULT '0',
  303. PRIMARY KEY (`id`),
  304. KEY `from` (`from`),
  305. KEY `to` (`to`,`read`,`deletedby`)
  306. ) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci
  307. ");
  308. // ---> Insert rate this script email
  309. hesk_dbQuery("INSERT INTO `".hesk_dbEscape($hesk_settings['db_pfix'])."mail` (`id`, `from`, `to`, `subject`, `message`, `dt`, `read`, `deletedby`) VALUES (1, 9999, 1, 'Rate this script', '<div style=\"text-align:justify;padding:3px\">\r\n\r\n<p style=\"color:green;font-weight:bold\">Enjoy using HESK? Please let others know!</p>\r\n\r\n<p>You are invited to rate HESK or even write a short review here:<br />&nbsp;<br /><img src=\"../img/link.png\" width=\"16\" height=\"16\" border=\"0\" alt=\"\" style=\"vertical-align:text-bottom\" /> <a href=\"http://www.hotscripts.com/Detailed/46973.html\" target=\"_blank\">Rate this script @ Hot Scripts</a><br />&nbsp;<br /><img src=\"../img/link.png\" width=\"16\" height=\"16\" border=\"0\" alt=\"\" style=\"vertical-align:text-bottom\" /> <a href=\"http://php.resourceindex.com/detail/04946.html\" target=\"_blank\">Rate this script @ The PHP Resource Index</a></p>\r\n\r\n<p>Thank you,<br />&nbsp;<br />Klemen,<br />\r\n<a href=\"https://www.hesk.com/\" target=\"_blank\">www.hesk.com</a>\r\n\r\n<p>&nbsp;</p>', NOW(), '0', 9999)");
  310. // ---> Insert welcome email
  311. hesk_dbQuery("INSERT INTO `".hesk_dbEscape($hesk_settings['db_pfix'])."mail` (`id`, `from`, `to`, `subject`, `message`, `dt`, `read`, `deletedby`) VALUES (2, 9999, 1, 'Welcome to HESK! Here are some quick tips...', '<p style=\"color:green;font-weight:bold\">HESK quick &quot;Getting Started&quot; tips:<br />&nbsp;</p>\r\n\r\n<ol style=\"padding-left:20px;padding-right:10px;text-align:justify\">\r\n<li>Click the Profile link to set your name, email, signature and password.<br />&nbsp;</li>\r\n<li>Click the Settings link in the top menu to get to the Settings page. For additional information about each setting, click the [?] link.<br />&nbsp;</li>\r\n<li>Add new categories (departments) on the Categories page. The default category cannot be deleted, but it can be renamed.<br />&nbsp;</li>\r\n<li>Create new staff accounts on the Users page. You can give them unlimited (Administrator) or restricted (Staff) access.<br />&nbsp;</li>\r\n<li>Use the integrated Knowledgebase. A comprehensive and well-written knowledgebase can drastically reduce the number of support tickets you receive and save a lot of your time in the long run.<br />&nbsp;</li>\r\n<li>You can create response and new ticket templates on the Canned page.<br />&nbsp;</li>\r\n<li>Subscribe to the <a href=\"https://www.hesk.com/newsletter.php\" target=\"_blank\">HESK Newsletter</a> to be notified of updates and new versions.<br />&nbsp;</li>\r\n<li>You should follow HESK on Twitter <a href=\"https://twitter.com/HESKdotCOM\" target=\"_blank\">here</a>.<br />&nbsp;</li>\r\n<li>To remove the &quot;<span class=\"smaller\">Powered by Help Desk Software HESK</span>&quot; links from the bottom of your help desk <a href=\"https://www.hesk.com/buy.php\" target=\"_blank\">buy a license here</a>.<br />&nbsp;</li></ol>\r\n\r\n<p>Enjoy using HESK and please feel free to share your constructive feedback and feature suggestions.</p>\r\n\r\n<p>Klemen Stirn<br />\r\nHESK owner and author<br />\r\n<a href=\"https://www.hesk.com/\" target=\"_blank\">www.hesk.com</a>', NOW(), '0', 9999)");
  312. // -> Notes
  313. hesk_dbQuery("
  314. CREATE TABLE `".hesk_dbEscape($hesk_settings['db_pfix'])."notes` (
  315. `id` mediumint(8) unsigned NOT NULL AUTO_INCREMENT,
  316. `ticket` mediumint(8) unsigned NOT NULL,
  317. `who` smallint(5) unsigned NOT NULL,
  318. `dt` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
  319. `message` mediumtext COLLATE utf8_unicode_ci NOT NULL,
  320. `attachments` mediumtext COLLATE utf8_unicode_ci NOT NULL,
  321. PRIMARY KEY (`id`),
  322. KEY `ticketid` (`ticket`)
  323. ) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci
  324. ");
  325. // -> Online
  326. hesk_dbQuery("
  327. CREATE TABLE `".hesk_dbEscape($hesk_settings['db_pfix'])."online` (
  328. `user_id` smallint(5) unsigned NOT NULL,
  329. `dt` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  330. `tmp` int(11) unsigned NOT NULL DEFAULT '0',
  331. UNIQUE KEY `user_id` (`user_id`),
  332. KEY `dt` (`dt`)
  333. ) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci
  334. ");
  335. // -> Pipe loops
  336. hesk_dbQuery("
  337. CREATE TABLE `".hesk_dbEscape($hesk_settings['db_pfix'])."pipe_loops` (
  338. `email` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
  339. `hits` smallint(1) unsigned NOT NULL DEFAULT '0',
  340. `message_hash` char(32) COLLATE utf8_unicode_ci NOT NULL,
  341. `dt` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
  342. KEY `email` (`email`,`hits`)
  343. ) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci
  344. ");
  345. // -> Replies
  346. hesk_dbQuery("
  347. CREATE TABLE `".hesk_dbEscape($hesk_settings['db_pfix'])."replies` (
  348. `id` mediumint(8) unsigned NOT NULL AUTO_INCREMENT,
  349. `replyto` mediumint(8) unsigned NOT NULL DEFAULT '0',
  350. `name` varchar(50) COLLATE utf8_unicode_ci NOT NULL DEFAULT '',
  351. `message` mediumtext COLLATE utf8_unicode_ci NOT NULL,
  352. `dt` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
  353. `attachments` mediumtext COLLATE utf8_unicode_ci,
  354. `staffid` smallint(5) unsigned NOT NULL DEFAULT '0',
  355. `rating` enum('1','5') COLLATE utf8_unicode_ci DEFAULT NULL,
  356. `read` enum('0','1') COLLATE utf8_unicode_ci NOT NULL DEFAULT '0',
  357. PRIMARY KEY (`id`),
  358. KEY `replyto` (`replyto`),
  359. KEY `dt` (`dt`),
  360. KEY `staffid` (`staffid`)
  361. ) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci
  362. ");
  363. // -> Reply drafts
  364. hesk_dbQuery("
  365. CREATE TABLE `".hesk_dbEscape($hesk_settings['db_pfix'])."reply_drafts` (
  366. `owner` smallint(5) unsigned NOT NULL,
  367. `ticket` mediumint(8) unsigned NOT NULL,
  368. `message` mediumtext CHARACTER SET utf8 NOT NULL,
  369. `dt` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
  370. KEY `owner` (`owner`),
  371. KEY `ticket` (`ticket`)
  372. ) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci
  373. ");
  374. // -> Reset password
  375. hesk_dbQuery("
  376. CREATE TABLE `".hesk_dbEscape($hesk_settings['db_pfix'])."reset_password` (
  377. `id` mediumint(8) unsigned NOT NULL AUTO_INCREMENT,
  378. `user` smallint(5) unsigned NOT NULL,
  379. `hash` char(40) NOT NULL,
  380. `ip` varchar(45) NOT NULL,
  381. `dt` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
  382. PRIMARY KEY (`id`),
  383. KEY `user` (`user`)
  384. ) ENGINE=MyISAM DEFAULT CHARSET=utf8;
  385. ");
  386. // -> Service messages
  387. hesk_dbQuery("
  388. CREATE TABLE `".hesk_dbEscape($hesk_settings['db_pfix'])."service_messages` (
  389. `id` smallint(5) unsigned NOT NULL AUTO_INCREMENT,
  390. `dt` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
  391. `author` smallint(5) unsigned NOT NULL,
  392. `title` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
  393. `message` mediumtext COLLATE utf8_unicode_ci NOT NULL,
  394. `style` enum('0','1','2','3','4') COLLATE utf8_unicode_ci NOT NULL DEFAULT '0',
  395. `type` enum('0','1') COLLATE utf8_unicode_ci NOT NULL DEFAULT '0',
  396. `order` smallint(5) unsigned NOT NULL DEFAULT '0',
  397. PRIMARY KEY (`id`),
  398. KEY `type` (`type`)
  399. ) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
  400. ");
  401. // -> Canned Responses
  402. hesk_dbQuery("
  403. CREATE TABLE `".hesk_dbEscape($hesk_settings['db_pfix'])."std_replies` (
  404. `id` smallint(5) unsigned NOT NULL AUTO_INCREMENT,
  405. `title` varchar(100) COLLATE utf8_unicode_ci NOT NULL DEFAULT '',
  406. `message` mediumtext COLLATE utf8_unicode_ci NOT NULL,
  407. `reply_order` smallint(5) unsigned NOT NULL DEFAULT '0',
  408. PRIMARY KEY (`id`)
  409. ) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci
  410. ");
  411. // -> Tickets
  412. hesk_dbQuery("
  413. CREATE TABLE `".hesk_dbEscape($hesk_settings['db_pfix'])."tickets` (
  414. `id` mediumint(8) unsigned NOT NULL AUTO_INCREMENT,
  415. `trackid` varchar(13) COLLATE utf8_unicode_ci NOT NULL,
  416. `name` varchar(50) COLLATE utf8_unicode_ci NOT NULL DEFAULT '',
  417. `email` varchar(1000) COLLATE utf8_unicode_ci NOT NULL DEFAULT '',
  418. `category` smallint(5) unsigned NOT NULL DEFAULT '1',
  419. `priority` enum('0','1','2','3') COLLATE utf8_unicode_ci NOT NULL DEFAULT '3',
  420. `subject` varchar(70) COLLATE utf8_unicode_ci NOT NULL DEFAULT '',
  421. `message` mediumtext COLLATE utf8_unicode_ci NOT NULL,
  422. `dt` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00',
  423. `lastchange` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  424. `firstreply` timestamp NULL DEFAULT NULL,
  425. `closedat` timestamp NULL DEFAULT NULL,
  426. `articles` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL,
  427. `ip` varchar(45) COLLATE utf8_unicode_ci NOT NULL DEFAULT '',
  428. `language` varchar(50) COLLATE utf8_unicode_ci DEFAULT NULL,
  429. `status` enum('0','1','2','3','4','5') COLLATE utf8_unicode_ci NOT NULL DEFAULT '0',
  430. `openedby` smallint(5) unsigned DEFAULT '0',
  431. `firstreplyby` smallint(8) unsigned DEFAULT NULL,
  432. `closedby` smallint(5) unsigned DEFAULT NULL,
  433. `replies` smallint(5) unsigned NOT NULL DEFAULT '0',
  434. `staffreplies` smallint(5) unsigned NOT NULL DEFAULT '0',
  435. `owner` smallint(5) unsigned NOT NULL DEFAULT '0',
  436. `time_worked` time NOT NULL DEFAULT '00:00:00',
  437. `lastreplier` enum('0','1') COLLATE utf8_unicode_ci NOT NULL DEFAULT '0',
  438. `replierid` smallint(5) unsigned DEFAULT NULL,
  439. `archive` enum('0','1') COLLATE utf8_unicode_ci NOT NULL DEFAULT '0',
  440. `locked` enum('0','1') COLLATE utf8_unicode_ci NOT NULL DEFAULT '0',
  441. `attachments` mediumtext COLLATE utf8_unicode_ci NOT NULL,
  442. `merged` mediumtext COLLATE utf8_unicode_ci NOT NULL,
  443. `history` mediumtext COLLATE utf8_unicode_ci NOT NULL,
  444. `custom1` mediumtext COLLATE utf8_unicode_ci NOT NULL,
  445. `custom2` mediumtext COLLATE utf8_unicode_ci NOT NULL,
  446. `custom3` mediumtext COLLATE utf8_unicode_ci NOT NULL,
  447. `custom4` mediumtext COLLATE utf8_unicode_ci NOT NULL,
  448. `custom5` mediumtext COLLATE utf8_unicode_ci NOT NULL,
  449. `custom6` mediumtext COLLATE utf8_unicode_ci NOT NULL,
  450. `custom7` mediumtext COLLATE utf8_unicode_ci NOT NULL,
  451. `custom8` mediumtext COLLATE utf8_unicode_ci NOT NULL,
  452. `custom9` mediumtext COLLATE utf8_unicode_ci NOT NULL,
  453. `custom10` mediumtext COLLATE utf8_unicode_ci NOT NULL,
  454. `custom11` mediumtext COLLATE utf8_unicode_ci NOT NULL,
  455. `custom12` mediumtext COLLATE utf8_unicode_ci NOT NULL,
  456. `custom13` mediumtext COLLATE utf8_unicode_ci NOT NULL,
  457. `custom14` mediumtext COLLATE utf8_unicode_ci NOT NULL,
  458. `custom15` mediumtext COLLATE utf8_unicode_ci NOT NULL,
  459. `custom16` mediumtext COLLATE utf8_unicode_ci NOT NULL,
  460. `custom17` mediumtext COLLATE utf8_unicode_ci NOT NULL,
  461. `custom18` mediumtext COLLATE utf8_unicode_ci NOT NULL,
  462. `custom19` mediumtext COLLATE utf8_unicode_ci NOT NULL,
  463. `custom20` mediumtext COLLATE utf8_unicode_ci NOT NULL,
  464. PRIMARY KEY (`id`),
  465. KEY `trackid` (`trackid`),
  466. KEY `archive` (`archive`),
  467. KEY `categories` (`category`),
  468. KEY `statuses` (`status`),
  469. KEY `owner` (`owner`),
  470. KEY `openedby` (`openedby`,`firstreplyby`,`closedby`),
  471. KEY `dt` (`dt`)
  472. ) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci
  473. ");
  474. // -> Ticket templates
  475. hesk_dbQuery("
  476. CREATE TABLE `".hesk_dbEscape($hesk_settings['db_pfix'])."ticket_templates` (
  477. `id` smallint(5) unsigned NOT NULL AUTO_INCREMENT,
  478. `title` varchar(100) COLLATE utf8_unicode_ci NOT NULL DEFAULT '',
  479. `message` mediumtext COLLATE utf8_unicode_ci NOT NULL,
  480. `tpl_order` smallint(5) unsigned NOT NULL DEFAULT '0',
  481. PRIMARY KEY (`id`)
  482. ) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci
  483. ");
  484. // -> Users
  485. hesk_dbQuery("
  486. CREATE TABLE `".hesk_dbEscape($hesk_settings['db_pfix'])."users` (
  487. `id` smallint(5) unsigned NOT NULL AUTO_INCREMENT,
  488. `user` varchar(20) COLLATE utf8_unicode_ci NOT NULL DEFAULT '',
  489. `pass` char(40) COLLATE utf8_unicode_ci NOT NULL,
  490. `isadmin` enum('0','1') COLLATE utf8_unicode_ci NOT NULL DEFAULT '0',
  491. `name` varchar(50) COLLATE utf8_unicode_ci NOT NULL DEFAULT '',
  492. `email` varchar(255) COLLATE utf8_unicode_ci NOT NULL DEFAULT '',
  493. `signature` varchar(1000) COLLATE utf8_unicode_ci NOT NULL DEFAULT '',
  494. `language` varchar(50) COLLATE utf8_unicode_ci DEFAULT NULL,
  495. `categories` varchar(500) COLLATE utf8_unicode_ci NOT NULL DEFAULT '',
  496. `afterreply` enum('0','1','2') COLLATE utf8_unicode_ci NOT NULL DEFAULT '0',
  497. `autostart` enum('0','1') COLLATE utf8_unicode_ci NOT NULL DEFAULT '1',
  498. `notify_customer_new` enum('0','1') COLLATE utf8_unicode_ci NOT NULL DEFAULT '1',
  499. `notify_customer_reply` enum('0','1') COLLATE utf8_unicode_ci NOT NULL DEFAULT '1',
  500. `show_suggested` enum('0','1') COLLATE utf8_unicode_ci NOT NULL DEFAULT '1',
  501. `notify_new_unassigned` enum('0','1') COLLATE utf8_unicode_ci NOT NULL DEFAULT '1',
  502. `notify_new_my` enum('0','1') COLLATE utf8_unicode_ci NOT NULL DEFAULT '1',
  503. `notify_reply_unassigned` enum('0','1') COLLATE utf8_unicode_ci NOT NULL DEFAULT '1',
  504. `notify_reply_my` enum('0','1') COLLATE utf8_unicode_ci NOT NULL DEFAULT '1',
  505. `notify_assigned` enum('0','1') COLLATE utf8_unicode_ci NOT NULL DEFAULT '1',
  506. `notify_pm` enum('0','1') COLLATE utf8_unicode_ci NOT NULL DEFAULT '1',
  507. `notify_note` enum('0','1') COLLATE utf8_unicode_ci NOT NULL DEFAULT '1',
  508. `default_list` varchar(255) COLLATE utf8_unicode_ci NOT NULL DEFAULT '',
  509. `autoassign` enum('0','1') COLLATE utf8_unicode_ci NOT NULL DEFAULT '1',
  510. `heskprivileges` varchar(1000) COLLATE utf8_unicode_ci DEFAULT NULL,
  511. `ratingneg` mediumint(8) unsigned NOT NULL DEFAULT '0',
  512. `ratingpos` mediumint(8) unsigned NOT NULL DEFAULT '0',
  513. `rating` float NOT NULL DEFAULT '0',
  514. `replies` mediumint(8) unsigned NOT NULL DEFAULT '0',
  515. PRIMARY KEY (`id`),
  516. KEY `autoassign` (`autoassign`)
  517. ) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci
  518. ");
  519. hesk_dbQuery("INSERT INTO `".hesk_dbEscape($hesk_settings['db_pfix'])."users` (`id`, `user`, `pass`, `isadmin`, `name`, `email`, `heskprivileges`) VALUES (1, '".hesk_dbEscape($_SESSION['admin_user'])."', '".hesk_dbEscape($_SESSION['admin_hash'])."', '1', 'Your name', 'you@me.com', '')");
  520. return true;
  521. } // End hesk_iTables()
  522. function hesk_iSaveSettings()
  523. {
  524. global $hesk_settings, $hesklang;
  525. $spam_question = hesk_generate_SPAM_question();
  526. $hesk_settings['secimg_use'] = empty($_SESSION['set_captcha']) ? 0 : 1;
  527. $hesk_settings['use_spamq'] = empty($_SESSION['use_spamq']) ? 0 : 1;
  528. $hesk_settings['question_ask'] = $spam_question[0];
  529. $hesk_settings['question_ans'] = $spam_question[1];
  530. $hesk_settings['set_attachments'] = empty($_SESSION['set_attachments']) ? 0 : 1;
  531. $hesk_settings['hesk_version'] = HESK_NEW_VERSION;
  532. if (isset($_SERVER['HTTP_HOST']))
  533. {
  534. $hesk_settings['site_url']='http://' . $_SERVER['HTTP_HOST'];
  535. if (isset($_SERVER['REQUEST_URI']))
  536. {
  537. $hesk_settings['hesk_url']='http://' . $_SERVER['HTTP_HOST'] . str_replace('/install/install.php','',$_SERVER['REQUEST_URI']);
  538. }
  539. }
  540. /* Encode and escape characters */
  541. $set = $hesk_settings;
  542. foreach ($hesk_settings as $k=> $v)
  543. {
  544. if (is_array($v))
  545. {
  546. continue;
  547. }
  548. $set[$k] = addslashes($v);
  549. }
  550. $set['debug_mode'] = 0;
  551. $set['email_providers'] = count($set['email_providers']) ? "'" . implode("','", $set['email_providers']) . "'" : '';
  552. $set['notify_spam_tags'] = count($set['notify_spam_tags']) ? "'" . implode("','", $set['notify_spam_tags']) . "'" : '';
  553. // Check if PHP version is 5.2.3+
  554. $set['db_vrsn'] = (version_compare(PHP_VERSION, '5.2.3') >= 0) ? 1 : 0;
  555. hesk_iSaveSettingsFile($set);
  556. return true;
  557. } // End hesk_iSaveSettings()
  558. ?>