PageRenderTime 49ms CodeModel.GetById 16ms RepoModel.GetById 1ms app.codeStats 0ms

/www/shop/engine/core/class/sTicketSystem.php

https://bitbucket.org/weberlars/sot-shopware
PHP | 1011 lines | 679 code | 151 blank | 181 comment | 80 complexity | e9740ef6cd38f593fa57152b85c34f84 MD5 | raw file
Possible License(s): AGPL-3.0, MIT, BSD-3-Clause, LGPL-2.1, LGPL-3.0
  1. <?php
  2. /**
  3. * Shopware 4.0
  4. * Copyright © 2012 shopware AG
  5. *
  6. * According to our dual licensing model, this program can be used either
  7. * under the terms of the GNU Affero General Public License, version 3,
  8. * or under a proprietary license.
  9. *
  10. * The texts of the GNU Affero General Public License with an additional
  11. * permission and of our proprietary license can be found at and
  12. * in the LICENSE file you have received along with this program.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU Affero General Public License for more details.
  18. *
  19. * "Shopware" is a registered trademark of shopware AG.
  20. * The licensing of the program under the AGPLv3 does not imply a
  21. * trademark license. Therefore any rights, title and interest in
  22. * our trademarks remain entirely with us.
  23. *
  24. * @category Shopware
  25. * @package Shopware_Core
  26. * @subpackage Class
  27. * @copyright Copyright (c) 2012, shopware AG (http://www.shopware.de)
  28. * @version $Id$
  29. * @author Stefan Hamann
  30. * @author $Author$
  31. */
  32. /**
  33. * Deprecated Shopware Class that provide crm features to shopware
  34. *
  35. * todo@all: Documentation
  36. */
  37. class sTicketSystem
  38. {
  39. /**
  40. * Pointer to Shopware-Core-Functions
  41. */
  42. var $sSYSTEM;
  43. /**
  44. * Sets the default DB connector (mysql|adodb)
  45. */
  46. public $sDbType;
  47. /**
  48. * Class-constructor
  49. */
  50. public function sTicketSystem()
  51. {
  52. //Set the Database default typ
  53. $this->sDbType = "mysql";
  54. }
  55. /**
  56. * Returns all support tickets as an associative array
  57. *
  58. * @access public
  59. * @author Dennis Scharfenberg
  60. * @version 1.0
  61. *
  62. * @param string $sort the first part of the SQL-LIMIT
  63. * @param string $dir
  64. * @param int $start the start value of SQL-LIMIT
  65. * @param int $limit the limit value of SQL-LIMIT
  66. * @param string $search Search
  67. * @param string $where Additional SQL-Where
  68. * @return array
  69. */
  70. public function getTicketSupportStore($sort="receipt", $dir="DESC", $start=0, $limit=25, $search="", $where="", $aFilter="")
  71. {
  72. /*
  73. * ESCAPE
  74. */
  75. $start = intval($start);
  76. $limit = intval($limit);
  77. $search = mysql_real_escape_string(stripcslashes($search));
  78. foreach ($aFilter as $filterKey => $filterVal)
  79. {
  80. $aFilter[$filterKey] = mysql_real_escape_string(stripcslashes($aFilter[$filterKey]));
  81. }
  82. /*
  83. * SORTFILED MAPPING
  84. */
  85. switch ($sort)
  86. {
  87. case "receipt":
  88. $sort = "ts.receipt";
  89. break;
  90. case "last_contact":
  91. $sort = "ts.last_contact";
  92. break;
  93. case "id":
  94. $sort = "ts.id";
  95. break;
  96. case "ticketID":
  97. $sort = "ts.id";
  98. break;
  99. case "contact":
  100. $sort = "ub.lastname";
  101. break;
  102. case "company":
  103. $sort = "ub.company";
  104. break;
  105. case "ticket_type":
  106. $sort = "tst.name";
  107. break;
  108. }
  109. /*
  110. * FILTER OPTIONS
  111. */
  112. $filter_add = "";
  113. if(!empty($aFilter['filter_status']) && $aFilter['filter_status'] != -1)
  114. {
  115. $filter_add .= "AND ts.statusID = '{$aFilter['filter_status']}'";
  116. }
  117. if($aFilter['filter_employee'] != "" && $aFilter['filter_employee'] != -1)
  118. {
  119. $filter_add .= "AND ts.employeeID = '{$aFilter['filter_employee']}'";
  120. }
  121. //create where statement for hide all closed status
  122. $hide_closed_status = "";
  123. if($aFilter['filter_status'] != -1)
  124. {
  125. if($aFilter['filter_status'] == 4)
  126. {
  127. $sql_clo = "SELECT `id` , `description`
  128. FROM `s_ticket_support_status`
  129. WHERE `closed` = 0";
  130. }else{
  131. $sql_clo = "SELECT `id` , `description`
  132. FROM `s_ticket_support_status`
  133. WHERE `closed` = 1";
  134. }
  135. $q_clo = mysql_query($sql_clo);
  136. if(mysql_num_rows($q_clo) != 0)
  137. {
  138. $hide_closed_status = "AND ts.statusID NOT IN (";
  139. $st_ids = array();
  140. while ($st = mysql_fetch_assoc($q_clo)) {
  141. if($st['id'] != $aFilter['filter_status']){
  142. $st_ids[] = $st['id'];
  143. }
  144. }
  145. $hide_closed_status = sprintf("AND ts.statusID NOT IN (%s)", implode(",", $st_ids));
  146. }
  147. }
  148. /*
  149. * SEARCH SETTINGS
  150. */
  151. $search = trim($search);
  152. if(!empty($search))
  153. {
  154. $search_qr = "AND (ub.lastname LIKE '%{$search}%'
  155. OR ub.firstname LIKE '%{$search}%'
  156. OR CONCAT_WS(', ',ub.lastname, ub.firstname) LIKE '%{$search}%'
  157. OR CONCAT_WS(' ',ub.firstname, ub.lastname) LIKE '%{$search}%'
  158. OR ts.id LIKE '%{$search}%'
  159. OR CONCAT('#',ts.id) LIKE '%{$search}%'
  160. OR ts.message LIKE '%{$search}%'
  161. OR ub.company LIKE '%{$search}%'
  162. )";
  163. }
  164. /*
  165. * FETCH TICKET ARRAY
  166. */
  167. //seconds sort param
  168. if($sort == "statusID")
  169. {
  170. $secSort = ", `receipt` DESC";
  171. }
  172. $sql = "
  173. SELECT
  174. ts.*,
  175. DATE_FORMAT(ts.receipt, '%d.%m.%Y - %H:%i') AS receipt_f,
  176. DATE_FORMAT(ts.last_contact, '%d.%m.%Y - %H:%i') AS last_contact_f,
  177. CONCAT_WS(', ',ub.lastname, ub.firstname) AS contact,
  178. ub.company ,
  179. st.description as status,
  180. st.color as status_color,
  181. tst.name as tickettyp_name,
  182. tst.gridcolor as tickettyp_gridcolor
  183. FROM `s_ticket_support` AS ts
  184. LEFT JOIN `s_user_billingaddress` AS ub ON(ub.userID = ts.userID)
  185. LEFT JOIN `s_ticket_support_status` AS st ON(st.id = ts.statusID)
  186. LEFT JOIN `s_ticket_support_types` AS tst ON(tst.id = ts.ticket_typeID)
  187. WHERE 1=1
  188. {$hide_closed_status}
  189. {$where}
  190. {$search_qr}
  191. {$filter_add}
  192. ORDER BY {$sort} {$dir} {$secSort}
  193. LIMIT {$start},{$limit}";
  194. if($this->sDbType == "mysql")
  195. {
  196. $result = mysql_query($sql);
  197. $fetchTickets = array();
  198. while ($fetch = mysql_fetch_assoc($result))
  199. {
  200. $fetchTickets[] = $fetch;
  201. }
  202. }elseif ($this->sDbType == "adodb")
  203. {
  204. $fetchTickets = $this->sSYSTEM->sDB_CONNECTION->GetAll($sql);
  205. }
  206. $aResults = array();
  207. $aResults['data'] = array();
  208. foreach ($fetchTickets as $fetch)
  209. {
  210. $data = array();
  211. $data['ticketID'] = $fetch['id'];
  212. /*
  213. * Highlighht Search
  214. */
  215. if(!empty($search))
  216. {
  217. $search_highlight = sprintf("<span style='background-color:yellow'>%s</span>", $search);
  218. $fetch['message'] = str_replace($search, $search_highlight, $fetch['message']);
  219. $fetch['contact'] = str_replace($search, $search_highlight, $fetch['contact']);
  220. $data['ticketID'] = str_replace($search, $search_highlight, $data['ticketID']);
  221. }
  222. $data['id'] = $fetch['id'];
  223. $data['userID'] = $fetch['userID'];
  224. $data['employeeID'] = $fetch['employeeID'];
  225. $data['ticket_type'] = utf8_encode($fetch['tickettyp_name']);
  226. $data['ticket_typeID'] = $fetch['ticket_type'];
  227. $data['ticket_gridcolor'] = "<div style=\"background-color:{$fetch['tickettyp_gridcolor']};\">&nbsp;</div>";
  228. $data['contact'] = utf8_encode($fetch['contact']);
  229. $data['email'] = $fetch['email'];
  230. $data['status'] = $fetch['status'];
  231. $data['statusID'] = $fetch['statusID'];
  232. $data['status_color'] = $fetch['status_color'];
  233. $data['company'] = utf8_encode($fetch['company']);
  234. $data['message'] = utf8_encode($fetch['message']);
  235. $data['receipt'] = $fetch['receipt_f'];
  236. $data['last_contact'] = $fetch['last_contact_f'];
  237. $data['isocode'] = strtoupper($fetch['isocode']);
  238. if(!empty($data['contact']))
  239. {
  240. $data['display_name'] = $data['contact'];
  241. }else{
  242. $data['display_name'] = $data['email'];
  243. }
  244. $aResults['data'][] = $data;
  245. }
  246. /*
  247. * FETCH TOTAL COUNT
  248. */
  249. $sql_total = "
  250. SELECT
  251. COUNT(*) AS total
  252. FROM `s_ticket_support` AS ts
  253. LEFT JOIN `s_user_billingaddress` AS ub ON(ub.userID = ts.userID)
  254. LEFT JOIN `s_ticket_support_status` AS st ON(st.id = ts.statusID)
  255. WHERE 1=1
  256. {$where}
  257. {$hide_closed_status}
  258. {$search_qr}
  259. {$filter_add}";
  260. $result_total = mysql_query($sql_total);
  261. $aResults['total'] = mysql_result($result_total, 0, "total");
  262. return $aResults;
  263. }
  264. public function getTicketCountries()
  265. {
  266. $sqlQ = mysql_query("SELECT DISTINCT tsm.`isocode`, m.name
  267. FROM `s_ticket_support_mails` AS tsm
  268. LEFT JOIN `s_core_multilanguage` AS m
  269. ON tsm.isocode = m.isocode
  270. ORDER BY tsm.`isocode`");
  271. $aResults = array();
  272. $aResults['data'] = array();
  273. while ($fetch = mysql_fetch_assoc($sqlQ)) {
  274. $data = array();
  275. $data['iso'] = strtoupper($fetch["isocode"]);
  276. $data['name'] = $fetch["name"];
  277. $aResults['data'][] = $data;
  278. }
  279. return $aResults;
  280. }
  281. public function getTicketMissingCountries()
  282. {
  283. $sqlQ = mysql_query("SELECT `isocode`, name
  284. FROM `s_core_multilanguage`
  285. WHERE `isocode` NOT
  286. IN (
  287. SELECT DISTINCT `isocode`
  288. FROM `s_ticket_support_mails`
  289. )
  290. ORDER BY `isocode`");
  291. $aResults = array();
  292. $aResults['data'] = array();
  293. while ($fetch = mysql_fetch_assoc($sqlQ)) {
  294. $data = array();
  295. $data['iso'] = strtoupper($fetch["isocode"]);
  296. $data['name'] = utf8_decode($fetch["name"]);
  297. $aResults['data'][] = $data;
  298. }
  299. return $aResults;
  300. }
  301. /**
  302. * Deletes a ticket and its historys entries by ID
  303. *
  304. * @param int $ticketID s_ticket_support.id
  305. */
  306. public function deleteTicketByID($ticketID)
  307. {
  308. //Escape
  309. $ticketID = intval($ticketID);
  310. $sql1 = "DELETE FROM `s_ticket_support` WHERE `id` = '{$ticketID}' LIMIT 1";
  311. mysql_query($sql1);
  312. $sql2 = "DELETE FROM `s_ticket_support_history` WHERE `ticketID` = '{$ticketID}'";
  313. mysql_query($sql2);
  314. }
  315. public function deleteTicketTypeByID($typeID)
  316. {
  317. //Escape
  318. $typeID = intval($typeID);
  319. $sql1 = "DELETE FROM `s_ticket_support_types` WHERE `id` = '{$typeID}' LIMIT 1";
  320. return mysql_query($sql1);
  321. }
  322. /**
  323. * Returns all TicketMails in an ExtJS store format
  324. *
  325. * @return array
  326. */
  327. public function getTicketMailStore($ticketID)
  328. {
  329. //Escape
  330. $ticketID = intval($ticketID);
  331. $data = array();
  332. $standard = array();
  333. $sql = "
  334. SELECT * FROM `s_ticket_support_mails`
  335. WHERE `isocode` =
  336. (
  337. SELECT isocode FROM `s_ticket_support` WHERE id = '{$ticketID}'
  338. )
  339. ORDER BY `description`";
  340. $query = mysql_query($sql);
  341. while ($fetch = mysql_fetch_array($query)) {
  342. $fetch['subject'] = $this->replaceTicketMailBB($ticketID, $fetch['subject']);
  343. $fetch['content'] = $this->replaceTicketMailBB($ticketID, $fetch['content']);
  344. $fetch['contentHTML'] = $this->replaceTicketMailBB($ticketID, $fetch['contentHTML']);
  345. $fetch['subject'] = utf8_encode($fetch['subject']);
  346. $fetch['content'] = nl2br($fetch['content']);
  347. $fetch['contentHTML'] = $fetch['contentHTML'];
  348. if($fetch['name'] == "sSTANDARD"){
  349. $standard = $fetch;
  350. $fetch['standard'] = 1;
  351. }
  352. $data[$fetch['id']] = $fetch;
  353. }
  354. return array("data"=>$data, "standard"=>$standard);
  355. }
  356. public function getTicketMailItem($id, $ticketID)
  357. {
  358. //Escape
  359. $id = intval($id);
  360. $ticketID = intval($ticketID);
  361. $sql = "SELECT * FROM `s_ticket_support_mails` WHERE `id` = '{$id}'";
  362. if($this->sDbType == "adodb")
  363. {
  364. $fetch = $this->sSYSTEM->sDB_CONNECTION->GetRow($sql);
  365. }else
  366. {
  367. $query = mysql_query($sql);
  368. $fetch = mysql_fetch_array($query);
  369. }
  370. $fetch['subject'] = $this->replaceTicketMailBB($ticketID, $fetch['subject']);
  371. $fetch['content'] = $this->replaceTicketMailBB($ticketID, $fetch['content']);
  372. $fetch['contentHTML'] = $this->replaceTicketMailBB($ticketID, $fetch['contentHTML']);
  373. $fetch['subject'] = utf8_encode($fetch['subject']);
  374. $fetch['content'] = utf8_encode($fetch['content']);
  375. $fetch['contentHTML'] = utf8_encode($fetch['contentHTML']);
  376. $fetch['content'] = nl2br($fetch['content']);
  377. return $fetch;
  378. }
  379. public function replaceTicketMailBB($ticketID, $string)
  380. {
  381. //Escape
  382. $ticketID = intval($ticketID);
  383. if(empty($this->sSYSTEM->sCONFIG))
  384. {
  385. //Load Config Data
  386. $query = mysql_query("SELECT `name`, `value` FROM `s_core_config`");
  387. $sCONFIG = array();
  388. while ($confData = mysql_fetch_assoc($query)) {
  389. $sCONFIG[$confData['name']] = $confData['value'];
  390. }
  391. }
  392. else
  393. {
  394. $sCONFIG = $this->sSYSTEM->sCONFIG;
  395. }
  396. //SSL CHECK
  397. $sCONFIG['sUSESSL'] == 1 ? $http = "https://" : $http = "http://";
  398. $ticketData = $this->getTicketSupportById($ticketID);
  399. $string = str_replace("{sTicketID}", "#".$ticketID, $string);
  400. //Get Shopshop URL
  401. $sql = "SELECT *
  402. FROM `s_core_multilanguage`
  403. WHERE `isocode` LIKE '{$ticketData['isocode']}'";
  404. if($this->sDbType == "adodb")
  405. {
  406. $result = $this->sSYSTEM->sDB_CONNECTION->GetAll($sql);
  407. $url = $result[0];
  408. }else
  409. {
  410. $result = mysql_query($sql);
  411. $url = mysql_fetch_assoc($result);
  412. }
  413. //iso missing
  414. if(empty($url['domainaliase']))
  415. {
  416. $sql = "SELECT *
  417. FROM `s_core_multilanguage`
  418. WHERE `default` = 1";
  419. if($this->sDbType == "adodb")
  420. {
  421. $result = $this->sSYSTEM->sDB_CONNECTION->GetAll($sql);
  422. $url = $result[0];
  423. }else
  424. {
  425. $result = mysql_query($sql);
  426. $url = mysql_fetch_assoc($result);
  427. }
  428. }
  429. //Split
  430. $url_conf = explode("\n", $url['domainaliase']);
  431. //sCONFIG nicht verf?gbar!!!
  432. $temp = str_replace($sCONFIG["sHOST"],$url_conf[0],$sCONFIG["sBASEPATH"]);
  433. $temp = str_replace("\n","",$temp);
  434. $temp = str_replace("\r","",$temp);
  435. $string = str_replace("{sTicketDirectUrl}", "http://".$temp."/shopware.php?sViewport=ticketdirect&sAID=".$ticketData['uniqueID'], $string);
  436. return $string;
  437. }
  438. /**
  439. * Returns one support tickets as an associative array
  440. *
  441. * @access public
  442. * @author Dennis Scharfenberg
  443. * @version 1.0
  444. *
  445. * @param int $ticketID s_ticket_support.id
  446. * @param int $userID BenutzerID (sollte aus Sicherheitsgr?nden ?bergeben werden)
  447. * @return array
  448. */
  449. public function getTicketSupportById($ticketID, $userID=0)
  450. {
  451. //Escape
  452. $ticketID = intval($ticketID);
  453. $userID = intval($userID);
  454. if(!empty($userID))
  455. {
  456. $whereAdd = "AND ts.`userID` = ".$userID;
  457. }
  458. /*
  459. * FETCH TICKET ARRAY
  460. */
  461. $sql = "SELECT
  462. ts.*,
  463. u.email AS user_email,
  464. ts.email AS ticket_email,
  465. DATE_FORMAT(ts.receipt, '%d.%m.%Y - %H:%i') AS receipt_f,
  466. DATE_FORMAT(ts.receipt, '%d.%m.%Y') AS receipt_date_f,
  467. DATE_FORMAT(ts.last_contact, '%d.%m.%Y - %H:%i') AS last_contact_f,
  468. CONCAT_WS(', ',ub.lastname, ub.firstname) AS contact,
  469. ub.company,
  470. st.responsible,
  471. st.closed
  472. FROM `s_ticket_support` AS ts
  473. LEFT JOIN `s_user_billingaddress` AS ub ON(ub.userID = ts.userID)
  474. LEFT JOIN `s_user` AS u ON(u.id = ts.userID)
  475. LEFT JOIN `s_ticket_support_status` AS st ON(st.id = ts.statusID)
  476. WHERE ts.id = '{$ticketID}'
  477. {$whereAdd}";
  478. if($this->sDbType == "mysql")
  479. {
  480. $result = mysql_query($sql);
  481. $fetch = mysql_fetch_assoc($result);
  482. }elseif ($this->sDbType == "adodb")
  483. {
  484. $fetch = $this->sSYSTEM->sDB_CONNECTION->GetRow($sql);
  485. }
  486. $aResults = array();
  487. $aResults['id'] = $fetch['id'];
  488. $aResults['userID'] = $fetch['userID'];
  489. $aResults['ticket_type'] = $fetch['ticket_type'];
  490. $aResults['contact'] = $fetch['contact'];
  491. $aResults['statusID'] = $fetch['statusID'];
  492. $aResults['company'] = $fetch['company'];
  493. $aResults['subject'] = $fetch['subject'];
  494. $aResults['message'] = $fetch['message'];
  495. //$aResults['message'] = nl2br($fetch['message']);
  496. $aResults['receipt'] = $fetch['receipt_f'];
  497. $aResults['receipt_date'] = $fetch['receipt_date_f'];
  498. $aResults['last_contact'] = $fetch['last_contact_f'];
  499. $aResults['user_email'] = $fetch['user_email'];
  500. $aResults['ticket_email'] = $fetch['ticket_email'];
  501. $aResults['additional'] = $fetch['additional'];
  502. $aResults['responsible'] = $fetch['responsible'];
  503. $aResults['closed'] = $fetch['closed'];
  504. $aResults['uniqueID'] = $fetch['uniqueID'];
  505. $aResults['isocode'] = $fetch['isocode'];
  506. return $aResults;
  507. }
  508. /**
  509. * Returns the last message of this ticket of the tickethistory
  510. *
  511. * @param int $ticketID s_ticket_support.id
  512. * @return array of ticketData
  513. */
  514. public function getLastHistoryEntryByTicketId($ticketID)
  515. {
  516. return array();
  517. }
  518. /**
  519. * Returns all support stat?s as an associative array
  520. *
  521. * @access public
  522. * @author Dennis Scharfenberg
  523. * @version 1.0
  524. *
  525. * @return array
  526. */
  527. public function getTicketStatusStore($filterStore=false)
  528. {
  529. $sql = "SELECT * FROM `s_ticket_support_status`";
  530. $result = mysql_query($sql);
  531. $aResults = array();
  532. //Add to filter store
  533. if($filterStore)
  534. {
  535. $data['id'] = 0;
  536. $data['description'] = "Filter deaktivieren";
  537. $aResults['data'][] = $data;
  538. $data['id'] = -1;
  539. $data['description'] = "Alle anzeigen";
  540. $aResults['data'][] = $data;
  541. }
  542. while ($fetch = mysql_fetch_assoc($result))
  543. {
  544. $data = array();
  545. $data['id'] = $fetch['id'];
  546. $data['description'] = $fetch['description'];
  547. $aResults['data'][] = $data;
  548. }
  549. return $aResults;
  550. }
  551. /**
  552. * Update the ticket with the values of an array
  553. *
  554. * @param int $ticketID s_ticket_support.id
  555. * @param array $aUpdates an associative arrray of update values
  556. */
  557. public function updateTicketDataById($ticketID, $aUpdates)
  558. {
  559. //Escape
  560. $ticketID = intval($ticketID);
  561. $sep = false;
  562. if($this->sDbType == "mysql")
  563. {
  564. $sql = "UPDATE `s_ticket_support` SET ";
  565. foreach ($aUpdates as $field => $value)
  566. {
  567. //Escape
  568. $field = mysql_real_escape_string(stripcslashes($field));
  569. $value = mysql_real_escape_string(stripcslashes($value));
  570. if($sep) $sql .= ", ";
  571. $sql .= sprintf("`%s` = '%s'", $field, $value);
  572. $sep=true;
  573. }
  574. $sql .= sprintf(" WHERE `id` = '%s'", $ticketID);
  575. return mysql_query($sql);
  576. }else {
  577. foreach ($aUpdates as $field => $value)
  578. {
  579. $updateSQL[] = "$field = ".$this->sSYSTEM->sDB_CONNECTION->qstr($value);
  580. }
  581. $sql = "UPDATE `s_ticket_support` SET ".implode(",",$updateSQL)." WHERE `id` = ?";
  582. return $this->sSYSTEM->sDB_CONNECTION->Execute($sql,array($ticketID));
  583. }
  584. }
  585. /**
  586. * Saves a new entry in s_ticket_support_history
  587. *
  588. * @param array $aInsert An associative array of s_ticket_support_history values
  589. */
  590. public function insertTicketHistoryEntry($aInsert)
  591. {
  592. if($aInsert['direction'] == "OUT"){
  593. if(!empty($this->sSYSTEM->_SESSION['sName'])){
  594. $aInsert['user'] = $this->sSYSTEM->_SESSION['sName'];
  595. }else{
  596. $aInsert['user'] = $this->sSYSTEM->_SESSION['sUsername'];
  597. }
  598. }else{
  599. $aInsert['user'] = "";
  600. }
  601. if($this->sDbType == "mysql")
  602. {
  603. //Escape
  604. $aInsert['ticketID'] = intval($aInsert['ticketID']);
  605. $aInsert['message'] = mysql_real_escape_string(stripcslashes($aInsert['message']));
  606. $aInsert['support_type'] = mysql_real_escape_string(stripcslashes($aInsert['support_type']));
  607. $aInsert['subject'] = mysql_real_escape_string(stripcslashes($aInsert['subject']));
  608. $aInsert['direction'] = mysql_real_escape_string(stripcslashes($aInsert['direction']));
  609. $aInsert['user'] = mysql_real_escape_string(stripcslashes($aInsert['user']));
  610. // todo@all $sw_user is undefined ?
  611. $sql = "INSERT INTO `s_ticket_support_history`
  612. (`ticketID`, `swUser`, `message`, `support_type`, `subject`, `receipt`, `direction`) VALUES
  613. ('{$aInsert['ticketID']}', '{$sw_user}', '{$aInsert['message']}', '{$aInsert['support_type']}', '{$aInsert['subject']}', NOW() , '{$aInsert['direction']}')";
  614. //Letzter Kontakt aktualisieren
  615. $sqlUp = "UPDATE `s_ticket_support` SET `last_contact` = NOW( ) WHERE `id` = '{$aInsert['ticketID']}' LIMIT 1";
  616. mysql_query($sql);
  617. mysql_query($sqlUp);
  618. }
  619. else
  620. {
  621. $sql = "INSERT INTO `s_ticket_support_history`
  622. (`ticketID`, `swUser`, `message`, `support_type`, `subject`, `receipt`, `direction`) VALUES
  623. (?, ?, ?, ?, ?, NOW(), ?)";
  624. $this->sSYSTEM->sDB_CONNECTION->Execute($sql, array($aInsert['ticketID'], $aInsert['user'], $aInsert['message'], $aInsert['support_type'], $aInsert['subject'], $aInsert['direction']));
  625. //Letzter Kontakt aktualisieren
  626. $sqlUp = "UPDATE `s_ticket_support` SET `last_contact` = NOW() WHERE `id` = ? LIMIT 1";
  627. $this->sSYSTEM->sDB_CONNECTION->Execute($sqlUp, array($aInsert['ticketID']));
  628. }
  629. }
  630. /**
  631. * returns all tickets and answers for one user
  632. *
  633. * @param int $ticketID The ticket ID
  634. * @param int $userID The id of the user
  635. * @return associative array
  636. */
  637. public function getTicketHistoryStore($ticketID, $userID)
  638. {
  639. $pre = ""; $post = "";
  640. //Escape
  641. $ticketID = intval($ticketID);
  642. $userID = intval($userID);
  643. if(!empty($userID))
  644. {
  645. $whereAdd = "OR `userID` = '{$userID}'";
  646. }
  647. $tasks = mysql_query("
  648. SELECT
  649. ts.*,
  650. DATE_FORMAT(ts.receipt, '%d.%m.%Y') AS date,
  651. DATE_FORMAT(ts.receipt, '%H:%i') AS time
  652. FROM `s_ticket_support` AS ts
  653. WHERE
  654. `id` = '{$ticketID}'
  655. {$whereAdd}
  656. ORDER BY `id` DESC, ts.receipt DESC
  657. ");
  658. if(mysql_num_rows($tasks) != 0)
  659. {
  660. while ($fetch = mysql_fetch_array($tasks)) {
  661. if($fetch['id'] == $ticketID){
  662. $current = 1;
  663. }else{
  664. $current = 0;
  665. }
  666. $data_f = array();
  667. $data_f['id'] = $fetch['id'];
  668. $data_f['ticketID'] = $fetch['id'];
  669. $data_f['send_to'] = 'Support';
  670. $data_f['subject'] = utf8_encode($fetch['subject']);
  671. $data_f['message'] = $pre.utf8_encode($fetch['message']).$post;
  672. $data_f['message'] = nl2br($data_f['message']);
  673. $data_f['sUser'] = $pre."<b>Ursprungsnachricht</b>".$post;
  674. $data_f['date'] = $fetch['date'];
  675. $data_f['time'] = $fetch['time'];
  676. $data_f['current'] = $current;
  677. $tasks_history = mysql_query("
  678. SELECT
  679. th.*,
  680. DATE_FORMAT(th.receipt, '%d.%m.%Y') AS date,
  681. DATE_FORMAT(th.receipt, '%H:%i') AS time
  682. FROM `s_ticket_support_history` AS th
  683. WHERE
  684. `ticketID` = '{$data_f['id']}'
  685. ORDER BY `receipt` DESC
  686. ");
  687. while ($fetch2 = mysql_fetch_array($tasks_history)) {
  688. if($fetch2['direction'] == "IN"){
  689. $username = $fetch['email'];
  690. }else{
  691. $username = $fetch2['swUser'];
  692. }
  693. $data = array();
  694. $data['id'] = $fetch2['id'];
  695. $data['direction'] = $fetch2['direction'];
  696. $data['ticketID'] = $fetch2['ticketID'];
  697. $data['subject'] = utf8_encode($fetch2['subject']);
  698. $data['message'] = utf8_encode($fetch2['message']);
  699. $data['message'] = nl2br($data['message']);
  700. $data['sUser'] = $pre.utf8_encode($username).$post;
  701. $data['date'] = $fetch2['date'];
  702. $data['time'] = $fetch2['time'];
  703. $data['current'] = $current;
  704. $ret[] = $data;
  705. }
  706. //add ticket enquiry
  707. $ret[] = $data_f;
  708. }
  709. }else{
  710. $data['id'] = 0;
  711. $ret[] = $data;
  712. }
  713. return array("data"=>$ret);
  714. }
  715. /**
  716. * returns the history of one ticket
  717. *
  718. * @param int $ticketID The ticket ID
  719. * @return associative array
  720. */
  721. public function getSingleTicketHistoryStore($ticketID)
  722. {
  723. //Escape
  724. $pre = "";
  725. $post = "";
  726. $ret = array();
  727. $ticketID = intval($ticketID);
  728. $sql = "
  729. SELECT
  730. th.*,
  731. DATE_FORMAT(th.receipt, '%d.%m.%Y') AS date,
  732. DATE_FORMAT(th.receipt, '%H:%i') AS time
  733. FROM `s_ticket_support_history` AS th
  734. WHERE
  735. `ticketID` = '{$ticketID}'
  736. ORDER BY `receipt` ASC
  737. ";
  738. if($this->sDbType == "mysql")
  739. {
  740. $fetchHistory = array();
  741. $result = mysql_query($sql);
  742. if($result&&mysql_num_rows($result))
  743. while ($fetch = mysql_fetch_assoc($result))
  744. {
  745. $fetchHistory[] = $fetch;
  746. }
  747. }elseif ($this->sDbType == "adodb")
  748. {
  749. $fetchHistory = $this->sSYSTEM->sDB_CONNECTION->GetAll($sql);
  750. }
  751. foreach ($fetchHistory as $fetch2)
  752. {
  753. $data['id'] = $fetch2['id'];
  754. $data['ticketID'] = $fetch2['ticketID'];
  755. $data['subject'] = $fetch2['subject'];
  756. $data['message'] = $fetch2['message'];
  757. $data['message'] = nl2br($fetch2['message']);
  758. $data['sUser'] = $pre."Kundenanfrage".$post;
  759. $data['date'] = $fetch2['date'];
  760. $data['time'] = $fetch2['time'];
  761. $data['direction'] = $fetch2['direction'];
  762. $data['current'] = 0;
  763. $ret[] = $data;
  764. }
  765. return array("data"=>$ret);
  766. }
  767. public function getTicketIdByUniqueID($uniqueID)
  768. {
  769. $sql = "SELECT
  770. id
  771. FROM `s_ticket_support`
  772. WHERE
  773. `uniqueID` = ?
  774. ORDER BY `id` DESC
  775. LIMIT 1";
  776. $fetch_tmp = $this->sSYSTEM->sDB_CONNECTION->GetRow($sql,array($uniqueID));
  777. return $fetch_tmp['id'];
  778. }
  779. /**
  780. * send notification by new or answered tickets
  781. *
  782. * @param int $ticketID
  783. * @param bool $newticket true=new ticket; false=ticket answer
  784. */
  785. function sendNotifyEmail($ticketID, $newticket=true)
  786. {
  787. $this->sDbType = "adodb";
  788. //Escape
  789. $ticketID = intval($ticketID);
  790. $isocode = $this->getTicketIsoCodeByTicketID($ticketID);
  791. if($newticket)
  792. {
  793. $sTICKETNOTIFYMAIL_ID = $this->getTicketMailItemIdByName("sTICKETNOTIFYMAILNEW", $isocode);
  794. }else{
  795. $sTICKETNOTIFYMAIL_ID = $this->getTicketMailItemIdByName("sTICKETNOTIFYMAILANS", $isocode);
  796. }
  797. if(!empty($this->sSYSTEM->sCONFIG["sTICKETNOTIFYEMAIL"]) && !empty($sTICKETNOTIFYMAIL_ID))
  798. {
  799. $notifyTpl = $this->getTicketMailItem($sTICKETNOTIFYMAIL_ID, $ticketID);
  800. $mail = $this->sSYSTEM->sMailer;
  801. if (!$mail) die("PHPMAILER failure");
  802. $mail->IsHTML(1);
  803. $mail->From = $notifyTpl["frommail"] ? $notifyTpl["frommail"] : $this->sSYSTEM->sCONFIG["sMAIL"];
  804. $mail->FromName = $notifyTpl["fromname"] ? $notifyTpl["fromname"] : $this->sSYSTEM->sCONFIG["sSHOPNAME"];
  805. $mail->Subject = $notifyTpl["subject"];
  806. if(empty($notifyTpl["ishtml"]))
  807. {
  808. $mail->Body = utf8_decode(nl2br($notifyTpl["content"]));
  809. }else{
  810. $mail->Body = $notifyTpl["contentHTML"];
  811. }
  812. $mail->ClearAddresses();
  813. $explMails = explode(";", $this->sSYSTEM->sCONFIG["sTICKETNOTIFYEMAIL"]);
  814. foreach ($explMails as $explMail)
  815. {
  816. $mail->AddAddress($explMail, "");
  817. }
  818. $mail->Send();
  819. }
  820. //notify costumer
  821. if(!empty($this->sSYSTEM->sCONFIG["sTICKETNOTIFYMAILCOSTUMER"]) && $newticket == true)
  822. {
  823. //Fetch Ticket Details
  824. $ticketData = $this->getTicketSupportById($ticketID);
  825. //Fetch mail template
  826. $sTICKETNOTIFYMAIL_ID = $this->getTicketMailItemIdByName("sTICKETNOTIFYMAILCOSTUMER", $isocode);
  827. $notifyTpl = $this->getTicketMailItem($sTICKETNOTIFYMAIL_ID, $ticketID);
  828. $mail = $this->sSYSTEM->sMailer;
  829. if (!$mail) die("PHPMAILER failure");
  830. $mail->IsHTML(1);
  831. $mail->From = $notifyTpl["frommail"] ? $notifyTpl["frommail"] : $this->sSYSTEM->sCONFIG["sMAIL"];
  832. $mail->FromName = $notifyTpl["fromname"] ? $notifyTpl["fromname"] : $this->sSYSTEM->sCONFIG["sSHOPNAME"];
  833. $mail->Subject = $notifyTpl["subject"];
  834. if(empty($notifyTpl["ishtml"]))
  835. {
  836. $mail->Body = utf8_decode(nl2br($notifyTpl["content"]));
  837. }else{
  838. $mail->Body = $notifyTpl["contentHTML"];
  839. }
  840. $ticketData['ticket_email'] = $ticketData['ticket_email'] ? $ticketData['ticket_email'] : $this->sSYSTEM->sCONFIG["sMAIL"];
  841. $mail->ClearAddresses();
  842. $mail->AddAddress($ticketData['ticket_email'], "");
  843. $mail->Send();
  844. }
  845. }
  846. function getTicketMailItemIdByName($name, $isocode="de")
  847. {
  848. //Escape
  849. $fetch = $this->sSYSTEM->sDB_CONNECTION->GetAll("SELECT id FROM `s_ticket_support_mails` WHERE `name` = ? AND `isocode` = ? LIMIT 1", array($name, $isocode));
  850. return $fetch[0]["id"];
  851. }
  852. function getTicketIsoCodeByTicketID($ticketID)
  853. {
  854. //Escape
  855. $ticketID = intval($ticketID);
  856. $fetch = $this->sSYSTEM->sDB_CONNECTION->GetAll("SELECT `isocode` FROM `s_ticket_support` WHERE `id` = '{$ticketID}' LIMIT 1");
  857. return $fetch[0]["isocode"];
  858. }
  859. }
  860. ?>