api.ticketing.php 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721
  1. <?php
  2. /**
  3. * Returns all tickets list
  4. *
  5. * @return array
  6. */
  7. function zb_TicketsGetAll() {
  8. $query = "SELECT * from `ticketing` WHERE `to` IS NULL AND `replyid` IS NULL ORDER BY `date` DESC";
  9. $result = simple_queryall($query);
  10. return ($result);
  11. }
  12. /**
  13. * Returns available tickets count
  14. *
  15. * @return int
  16. */
  17. function zb_TicketsGetCount() {
  18. $query = "SELECT COUNT(`id`) from `ticketing` WHERE `to` IS NULL AND `replyid` IS NULL";
  19. $result = simple_query($query);
  20. $result = $result['COUNT(`id`)'];
  21. return ($result);
  22. }
  23. /**
  24. * Returns tickets limited from-to
  25. *
  26. * @param int $from
  27. * @param int $to
  28. * @return array
  29. */
  30. function zb_TicketsGetLimited($from, $to) {
  31. $query = "SELECT * from `ticketing` WHERE `to` IS NULL AND `replyid` IS NULL ORDER BY `date` DESC LIMIT " . $from . "," . $to . ";";
  32. $result = simple_queryall($query);
  33. return ($result);
  34. }
  35. /**
  36. * Returns count of new opened tickets
  37. *
  38. * @return int
  39. */
  40. function zb_TicketsGetAllNewCount() {
  41. $query = "SELECT COUNT(`id`) from `ticketing` WHERE `to` IS NULL AND `replyid` IS NULL AND `status`='0' ORDER BY `date` DESC";
  42. $result = simple_query($query);
  43. $result = $result['COUNT(`id`)'];
  44. return ($result);
  45. }
  46. /**
  47. * Returns all tickets by some existing usrname
  48. *
  49. * @param string $login
  50. * @return array
  51. */
  52. function zb_TicketsGetAllByUser($login) {
  53. $login = vf($login);
  54. $query = "SELECT `id`,`date`,`status` from `ticketing` WHERE `to` IS NULL AND `replyid` IS NULL AND `from`='" . $login . "' ORDER BY `date` DESC";
  55. $result = simple_queryall($query);
  56. return ($result);
  57. }
  58. /**
  59. * Returns tickets data by its ID
  60. *
  61. * @param int $ticketid
  62. * @return array
  63. */
  64. function zb_TicketGetData($ticketid) {
  65. $ticketid = vf($ticketid, 3);
  66. $query = "SELECT * from `ticketing` WHERE `id`='" . $ticketid . "'";
  67. $result = simple_query($query);
  68. return ($result);
  69. }
  70. /**
  71. * Returns array of replies by some existing ticket
  72. *
  73. * @param int $ticketid
  74. * @return array
  75. */
  76. function zb_TicketGetReplies($ticketid) {
  77. $ticketid = vf($ticketid, 3);
  78. $query = "SELECT * from `ticketing` WHERE `replyid`='" . $ticketid . "' ORDER by `id` ASC";
  79. $result = simple_queryall($query);
  80. return ($result);
  81. }
  82. /**
  83. * Deletes ticket from database
  84. *
  85. * @param int $ticketid
  86. *
  87. * @return void
  88. */
  89. function zb_TicketDelete($ticketid) {
  90. $ticketid = vf($ticketid, 3);
  91. $query = "DELETE FROM `ticketing` WHERE `id`='" . $ticketid . "'";
  92. nr_query($query);
  93. log_register("TICKET DELETE [" . $ticketid . "]");
  94. }
  95. /**
  96. * Deletes all of ticket replies followed by some ticket
  97. *
  98. * @param int $ticketid
  99. *
  100. * @return void
  101. */
  102. function zb_TicketDeleteReplies($ticketid) {
  103. $ticketid = vf($ticketid, 3);
  104. $query = "DELETE FROM `ticketing` WHERE `replyid`='" . $ticketid . "'";
  105. nr_query($query);
  106. log_register("TICKET REPLIES DELETE [" . $ticketid . "]");
  107. }
  108. /**
  109. * Deletes ticket reply from database
  110. *
  111. * @param int $replyid
  112. *
  113. * @return void
  114. */
  115. function zb_TicketDeleteReply($replyid) {
  116. $replyid = vf($replyid, 3);
  117. $query = "DELETE FROM `ticketing` WHERE `id`='" . $replyid . "'";
  118. nr_query($query);
  119. log_register("TICKET REPLY DELETE [" . $replyid . "]");
  120. }
  121. /**
  122. * Updates reply text by its ID
  123. *
  124. * @param int $replyid
  125. * @param string $newtext
  126. *
  127. * @return void
  128. */
  129. function zb_TicketUpdateReply($replyid, $newtext) {
  130. $replyid = vf($replyid, 3);
  131. $newtext = strip_tags($newtext);
  132. simple_update_field('ticketing', 'text', $newtext, "WHERE `id`='" . $replyid . "'");
  133. log_register("TICKET REPLY EDIT [" . $replyid . "]");
  134. }
  135. /**
  136. * Creates new ticket into database
  137. *
  138. * @param string $from
  139. * @param string $to
  140. * @param string $text
  141. * @param int $replyto
  142. * @param string $admin
  143. *
  144. * @return void
  145. */
  146. function zb_TicketCreate($from, $to, $text, $replyto = 'NULL', $admin = '') {
  147. $from = mysql_real_escape_string($from);
  148. $to = mysql_real_escape_string($to);
  149. $admin = mysql_real_escape_string($admin);
  150. $text = mysql_real_escape_string(strip_tags($text));
  151. $date = curdatetime();
  152. $replyto = vf($replyto);
  153. $query = "INSERT INTO `ticketing` (`id` , `date` , `replyid` , `status` ,`from` , `to` , `text`, `admin`) "
  154. . "VALUES (NULL , '" . $date . "', " . $replyto . ", '0', '" . $from . "', '" . $to . "', '" . $text . "', '" . $admin . "');";
  155. nr_query($query);
  156. $logreplyto = (empty($replyto)) ? '' : 'REPLY TO [' . $replyto . ']';
  157. log_register("TICKET CREATE (" . $to . ") " . $logreplyto);
  158. }
  159. /**
  160. * Marks ticket as closed in database
  161. *
  162. * @param int $ticketid
  163. *
  164. * @return void
  165. */
  166. function zb_TicketSetDone($ticketid) {
  167. $ticketid = vf($ticketid, 3);
  168. simple_update_field('ticketing', 'status', '1', "WHERE `id`='" . $ticketid . "'");
  169. log_register("TICKET CLOSE [" . $ticketid . "]");
  170. }
  171. /**
  172. * Marks ticket as unreviewed in database
  173. *
  174. * @param int $ticketid
  175. *
  176. * @return void
  177. */
  178. function zb_TicketSetUnDone($ticketid) {
  179. $ticketid = vf($ticketid, 3);
  180. simple_update_field('ticketing', 'status', '0', "WHERE `id`='" . $ticketid . "'");
  181. log_register("TICKET OPEN [" . $ticketid . "]");
  182. }
  183. /**
  184. * Renders available tickets list with controls
  185. *
  186. * @global object $ubillingConfig
  187. * @return string
  188. */
  189. function web_TicketsShow() {
  190. global $ubillingConfig;
  191. $alterconf = $ubillingConfig->getAlter();
  192. //pagination section
  193. $totalcount = zb_TicketsGetCount();
  194. $perpage = $alterconf['TICKETS_PERPAGE'];
  195. if (!isset($_GET['page'])) {
  196. $current_page = 1;
  197. } else {
  198. $current_page = vf($_GET['page'], 3);
  199. }
  200. if ($totalcount > $perpage) {
  201. $paginator = wf_pagination($totalcount, $perpage, $current_page, "?module=ticketing", 'ubButton', 16);
  202. $alltickets = zb_TicketsGetLimited($perpage * ($current_page - 1), $perpage);
  203. } else {
  204. $paginator = '';
  205. $alltickets = zb_TicketsGetAll();
  206. }
  207. $tablecells = wf_TableCell(__('ID'));
  208. $tablecells .= wf_TableCell(__('Date'));
  209. $tablecells .= wf_TableCell(__('From'));
  210. $tablecells .= wf_TableCell(__('Real Name'));
  211. $tablecells .= wf_TableCell(__('Full address'));
  212. $tablecells .= wf_TableCell(__('IP'));
  213. $tablecells .= wf_TableCell(__('Tariff'));
  214. $tablecells .= wf_TableCell(__('Balance'));
  215. $tablecells .= wf_TableCell(__('Credit'));
  216. $tablecells .= wf_TableCell(__('Processed'));
  217. $tablecells .= wf_TableCell(__('Actions'));
  218. $tablerows = wf_TableRow($tablecells, 'row1');
  219. if (!empty($alltickets)) {
  220. $allrealnames = zb_UserGetAllRealnames();
  221. $alladdress = zb_AddressGetFulladdresslist();
  222. $alltariffs = zb_TariffsGetAllUsers();
  223. $allcash = zb_CashGetAllUsers();
  224. $allcredits = zb_CreditGetAllUsers();
  225. $alluserips = zb_UserGetAllIPs();
  226. foreach ($alltickets as $io => $eachticket) {
  227. $tablecells = wf_TableCell($eachticket['id']);
  228. $tablecells .= wf_TableCell($eachticket['date']);
  229. $fromlink = wf_Link('?module=userprofile&username=' . $eachticket['from'], web_profile_icon() . ' ' . $eachticket['from']);
  230. $tablecells .= wf_TableCell($fromlink);
  231. $tablecells .= wf_TableCell(@$allrealnames[$eachticket['from']]);
  232. $tablecells .= wf_TableCell(@$alladdress[$eachticket['from']]);
  233. $tablecells .= wf_TableCell(@$alluserips[$eachticket['from']]);
  234. $tablecells .= wf_TableCell(@$alltariffs[$eachticket['from']]);
  235. $tablecells .= wf_TableCell(@$allcash[$eachticket['from']]);
  236. $tablecells .= wf_TableCell(@$allcredits[$eachticket['from']]);
  237. $tablecells .= wf_TableCell(web_bool_led($eachticket['status']), '', '', 'sorttable_customkey="' . $eachticket['status'] . '"');
  238. $actionlink = wf_Link('?module=ticketing&showticket=' . $eachticket['id'], wf_img_sized('skins/icon_search_small.gif', '', '12') . ' ' . __('Show'), false, 'ubButton');
  239. $tablecells .= wf_TableCell($actionlink);
  240. $tablerows .= wf_TableRow($tablecells, 'row3');
  241. }
  242. }
  243. $result = wf_TableBody($tablerows, '100%', '0', 'sortable');
  244. $result .= $paginator;
  245. return ($result);
  246. }
  247. /**
  248. * Returns typical answer preset creation form
  249. *
  250. * @return string
  251. */
  252. function web_TicketsTAPAddForm() {
  253. $inputs = wf_HiddenInput('createnewtap', 'true');
  254. $inputs .= wf_TextArea('newtaptext', '', '', true, '60x10');
  255. $inputs .= wf_Submit(__('Create'));
  256. $result = wf_Form('', "POST", $inputs, 'glamour');
  257. return ($result);
  258. }
  259. /**
  260. * Returns typical answer preset edit form
  261. *
  262. * @param string $keyname
  263. * @param string $text
  264. *
  265. * @return string
  266. */
  267. function web_TicketsTAPEditForm($keyname, $text) {
  268. $inputs = wf_HiddenInput('edittapkey', $keyname);
  269. $inputs .= wf_TextArea('edittaptext', '', $text, true, '60x10');
  270. $inputs .= wf_Submit(__('Save'));
  271. $result = wf_Form('', 'POST', $inputs, 'glamour');
  272. return ($result);
  273. }
  274. /**
  275. * Creates new typical answer preset in database
  276. *
  277. * @param string $taptext
  278. *
  279. * @return void
  280. */
  281. function zb_TicketsTAPCreate($taptext) {
  282. $keyName = 'HELPDESKTAP_' . zb_rand_string(8);
  283. $storeData = base64_encode($taptext);
  284. zb_StorageSet($keyName, $storeData);
  285. log_register('TICKET TAP CREATE `' . $keyName . '`');
  286. }
  287. /**
  288. * Deletes existing typical answer preset from database
  289. *
  290. * @param string $keyname
  291. *
  292. * @return void
  293. */
  294. function zb_TicketsTAPDelete($keyname) {
  295. $keyname = mysql_real_escape_string($keyname);
  296. $query = "DELETE from `ubstorage` WHERE `key`='" . $keyname . "'";
  297. nr_query($query);
  298. log_register('TICKET TAP DELETE `' . $keyname . '`');
  299. }
  300. /**
  301. * Changes existing typical answer preset data in database
  302. *
  303. * @param string $key
  304. * @param string $text
  305. *
  306. * @return void
  307. */
  308. function zb_TicketsTAPEdit($key, $text) {
  309. $storeData = base64_encode($text);
  310. zb_StorageSet($key, $storeData);
  311. log_register('TICKET TAP CHANGE `' . $key . '`');
  312. }
  313. /**
  314. * Returns all available typical answer presets array
  315. *
  316. * @return array
  317. */
  318. function zb_TicketsTAPgetAll() {
  319. $result = array();
  320. $query = "SELECT * from `ubstorage` WHERE `key` LIKE 'HELPDESKTAP_%' ORDER BY `id` ASC";
  321. $all = simple_queryall($query);
  322. if (!empty($all)) {
  323. foreach ($all as $io => $each) {
  324. @$tmpData = base64_decode($each['value']);
  325. @$tmpData = str_replace("'", '`', $tmpData);
  326. $result[$each['key']] = $tmpData;
  327. }
  328. }
  329. return ($result);
  330. }
  331. /**
  332. * Renders available typical answer presets list with controls
  333. *
  334. * @return string
  335. */
  336. function web_TicketsTapShowAvailable() {
  337. $all = zb_TicketsTAPgetAll();
  338. $cells = wf_TableCell(__('Text'), '90%');
  339. $cells .= wf_TableCell(__('Actions'));
  340. $rows = wf_TableRow($cells, 'row1');
  341. if (!empty($all)) {
  342. foreach ($all as $io => $each) {
  343. $cells = wf_TableCell($each);
  344. $actlinks = wf_JSAlert('?module=ticketing&settings=true&deletetap=' . $io, web_delete_icon(), __('Removing this may lead to irreparable results'));
  345. $actlinks .= wf_modalAuto(web_edit_icon(), __('Edit'), web_TicketsTAPEditForm($io, $each), '');
  346. $cells .= wf_TableCell($actlinks);
  347. $rows .= wf_TableRow($cells, 'row3');
  348. }
  349. }
  350. $result = wf_TableBody($rows, '100%', '0', 'sortable');
  351. return ($result);
  352. }
  353. /**
  354. * Returns typical answer preset insertion form
  355. *
  356. * @return string
  357. */
  358. function web_TicketsTAPLister() {
  359. $result = '';
  360. $maxLen = 50;
  361. $allReplies = zb_TicketsTAPgetAll();
  362. if (!empty($allReplies)) {
  363. $result .= wf_delimiter() . wf_tag('h3') . __('Typical answers presets') . wf_tag('h3', true);
  364. $result .= wf_tag('ul', false);
  365. foreach ($allReplies as $io => $each) {
  366. $randId = wf_InputId();
  367. $rawText = trim($each);
  368. $result .= wf_tag('script', false, '', 'language="javascript" type="text/javascript"');
  369. $encodedReply = json_encode($rawText);
  370. $encodedReply = rtrim($encodedReply, '"');
  371. $encodedReply = ltrim($encodedReply, '"');
  372. $result .= '
  373. function jsAddReplyText_' . $randId . '() {
  374. var replytext=\'' . $encodedReply . '\';
  375. $("#ticketreplyarea").val(replytext);
  376. }
  377. ';
  378. $result .= wf_tag('script', true);
  379. $linkText = htmlspecialchars($rawText);
  380. if (mb_strlen($linkText, 'UTF-8') > $maxLen) {
  381. $linkText = mb_substr($rawText, 0, $maxLen, 'UTF-8') . '..';
  382. } else {
  383. $linkText = $rawText;
  384. }
  385. $result .= wf_tag('li') . wf_tag('a', false, '', 'href="#" onClick="jsAddReplyText_' . $randId . '();"') . $linkText . wf_tag('a', true) . wf_tag('li', true);
  386. }
  387. $result .= wf_tag('ul', true);
  388. }
  389. return ($result);
  390. }
  391. /**
  392. * Returns ticket reply form with typical answer presets if its available
  393. *
  394. * @param int $ticketid
  395. *
  396. * @return string
  397. */
  398. function web_TicketReplyForm($ticketid) {
  399. $ticketid = vf($ticketid, 3);
  400. $ticketdata = zb_TicketGetData($ticketid);
  401. $ticketstate = $ticketdata['status'];
  402. if (!$ticketstate) {
  403. $replyinputs = wf_HiddenInput('postreply', $ticketid);
  404. $replyinputs .= wf_tag('textarea', false, '', 'name="replytext" cols="60" rows="10" id="ticketreplyarea"') . wf_tag('textarea', true) . wf_tag('br');
  405. ;
  406. $replyinputs .= wf_Submit('Reply');
  407. $replyform = wf_Form('', 'POST', $replyinputs, 'glamour');
  408. $replyform .= web_TicketsTAPLister();
  409. } else {
  410. $replyform = __('Ticket is closed');
  411. }
  412. //ajax background render
  413. if (wf_CheckGet(array('ajevents'))) {
  414. $currentTicketEvents = wf_tag('h3') . __('Events for ticket') . ' ' . $ticketid . wf_tag('h3', true);
  415. $currentTicketEvents .= getTicketEvents($ticketid, true);
  416. die($currentTicketEvents);
  417. }
  418. //previous ticket events
  419. $replyform .= wf_AjaxLoader();
  420. $replyform .= wf_delimiter();
  421. $replyform .= wf_AjaxLink('?module=ticketing&showticket=' . $ticketid . '&ajevents=true', wf_img('skins/log_icon_small.png') . ' ' . __('Show ticket events'), 'ajticketevents', false, 'ubButton');
  422. $replyform .= wf_AjaxContainer('ajticketevents', '', '');
  423. return ($replyform);
  424. }
  425. /**
  426. * Returns reply edit form
  427. *
  428. * @param int $replyid
  429. *
  430. * @return string
  431. */
  432. function web_TicketReplyEditForm($replyid) {
  433. $replyid = vf($replyid, 3);
  434. $ticketdata = zb_TicketGetData($replyid);
  435. $replytext = $ticketdata['text'];
  436. $inputs = wf_HiddenInput('editreply', $replyid);
  437. $inputs .= wf_TextArea('editreplytext', '', $replytext, true, '60x10');
  438. $inputs .= wf_Submit('Save');
  439. $form = wf_Form('', 'POST', $inputs, 'glamour');
  440. return ($form);
  441. }
  442. /**
  443. * Renders ticket, all of replies and all needed controls/forms for they
  444. *
  445. * @param int $ticketid
  446. *
  447. * @return string
  448. */
  449. function web_TicketDialogue($ticketid) {
  450. $ticketid = vf($ticketid, 3);
  451. $ticketdata = zb_TicketGetData($ticketid);
  452. $ticketreplies = zb_TicketGetReplies($ticketid);
  453. @$employeeNames = unserialize(ts_GetAllEmployeeLoginsCached());
  454. $result = wf_tag('p', false, '', 'align="right"') . wf_BackLink('?module=ticketing', 'Back to tickets list', true) . wf_tag('p', true);
  455. if (!empty($ticketdata)) {
  456. $userLogin = $ticketdata['from'];
  457. $userAddress = zb_UserGetFullAddress($userLogin);
  458. //this data not used cache, to be 100% actual
  459. $userRealName = zb_UserGetRealName($userLogin);
  460. $userData = zb_UserGetStargazerData($userLogin);
  461. $userIp = $userData['IP'];
  462. $userCredit = $userData['Credit'];
  463. $userCash = $userData['Cash'];
  464. $userTariff = $userData['Tariff'];
  465. if ($ticketdata['status']) {
  466. $actionlink = wf_Link('?module=ticketing&openticket=' . $ticketdata['id'], wf_img('skins/icon_unlock.png') . ' ' . __('Open'), false, 'ubButton');
  467. } else {
  468. $actionlink = wf_Link('?module=ticketing&closeticket=' . $ticketdata['id'], wf_img('skins/icon_lock.png') . ' ' . __('Close'), false, 'ubButton');
  469. }
  470. $tablecells = wf_TableCell(__('ID'));
  471. $tablecells .= wf_TableCell(__('Date'));
  472. $tablecells .= wf_TableCell(__('Login'));
  473. $tablecells .= wf_TableCell(__('Real Name'));
  474. $tablecells .= wf_TableCell(__('Full address'));
  475. $tablecells .= wf_TableCell(__('IP'));
  476. $tablecells .= wf_TableCell(__('Tariff'));
  477. $tablecells .= wf_TableCell(__('Balance'));
  478. $tablecells .= wf_TableCell(__('Credit'));
  479. $tablecells .= wf_TableCell(__('Processed'));
  480. $tablerows = wf_TableRow($tablecells, 'row1');
  481. $tablecells = wf_TableCell($ticketdata['id']);
  482. $tablecells .= wf_TableCell($ticketdata['date']);
  483. $profilelink = wf_Link('?module=userprofile&username=' . $ticketdata['from'], web_profile_icon() . ' ' . $ticketdata['from']);
  484. $tablecells .= wf_TableCell($profilelink);
  485. $tablecells .= wf_TableCell($userRealName);
  486. $tablecells .= wf_TableCell($userAddress);
  487. $tablecells .= wf_TableCell($userIp);
  488. $tablecells .= wf_TableCell($userTariff);
  489. $tablecells .= wf_TableCell($userCash);
  490. $tablecells .= wf_TableCell($userCredit);
  491. $tablecells .= wf_TableCell(web_bool_led($ticketdata['status']));
  492. $tablerows .= wf_TableRow($tablecells, 'row3');
  493. $result .= wf_TableBody($tablerows, '100%', '0');
  494. //ticket body
  495. $tickettext = strip_tags($ticketdata['text']);
  496. $tickettext = nl2br($tickettext);
  497. $tablecells = wf_TableCell('', '20%');
  498. $tablecells .= wf_TableCell($ticketdata['date']);
  499. $tablerows = wf_TableRow($tablecells, 'row2');
  500. $ticketauthor = wf_tag('center') . wf_tag('b') . @$allrealnames[$ticketdata['from']] . wf_tag('b', true) . wf_tag('center', true);
  501. $ticketavatar = wf_tag('center') . wf_img('skins/userava.png') . wf_tag('center', true);
  502. $ticketpanel = $ticketauthor . wf_tag('br') . $ticketavatar;
  503. $tablecells = wf_TableCell($ticketpanel);
  504. $tablecells .= wf_TableCell($tickettext);
  505. $tablerows .= wf_TableRow($tablecells, 'row3');
  506. $result .= wf_TableBody($tablerows, '100%', '0', 'glamour');
  507. $result .= $actionlink;
  508. }
  509. if (!empty($ticketreplies)) {
  510. $result .= wf_tag('h2') . __('Replies') . wf_tag('h2', true);
  511. $result .= wf_CleanDiv();
  512. foreach ($ticketreplies as $io => $eachreply) {
  513. //reply
  514. if ($eachreply['admin']) {
  515. $adminRealName = (isset($employeeNames[$eachreply['admin']])) ? $employeeNames[$eachreply['admin']] : $eachreply['admin'];
  516. $replyauthor = wf_tag('center') . wf_tag('b') . $adminRealName . wf_tag('b', true) . wf_tag('center', true);
  517. $replyavatar = wf_tag('center') . gravatar_ShowAdminAvatar($eachreply['admin'], '64') . wf_tag('center', true);
  518. } else {
  519. $replyauthor = wf_tag('center') . wf_tag('b') . @$allrealnames[$eachreply['from']] . wf_tag('b', true) . wf_tag('center', true);
  520. $replyavatar = wf_tag('center') . wf_img('skins/userava.png') . wf_tag('center', true);
  521. }
  522. $replyactions = wf_tag('center');
  523. $replyactions .= wf_JSAlert('?module=ticketing&showticket=' . $ticketdata['id'] . '&deletereply=' . $eachreply['id'], web_delete_icon(), 'Removing this may lead to irreparable results') . ' ';
  524. $replyactions .= wf_JSAlert('?module=ticketing&showticket=' . $ticketdata['id'] . '&editreply=' . $eachreply['id'], web_edit_icon(), 'Are you serious');
  525. $replyactions .= wf_tag('center', true);
  526. // reply body
  527. if (isset($_GET['editreply'])) {
  528. if ($_GET['editreply'] == $eachreply['id']) {
  529. //is this reply editing?
  530. $replytext = web_TicketReplyEditForm($eachreply['id']);
  531. } else {
  532. //not this ticket edit
  533. $replytext = strip_tags($eachreply['text']);
  534. }
  535. } else {
  536. //normal text by default
  537. $replytext = strip_tags($eachreply['text']);
  538. $replytext = nl2br($replytext);
  539. }
  540. $replypanel = $replyauthor . wf_tag('br') . $replyavatar . wf_tag('br') . $replyactions;
  541. $tablecells = wf_TableCell('', '20%');
  542. $tablecells .= wf_TableCell($eachreply['date']);
  543. $tablerows = wf_TableRow($tablecells, 'row2');
  544. $tablecells = wf_TableCell($replypanel);
  545. $tablecells .= wf_TableCell($replytext);
  546. $tablerows .= wf_TableRow($tablecells, 'row3');
  547. $result .= wf_TableBody($tablerows, '100%', '0', 'glamour');
  548. $result .= wf_CleanDiv();
  549. }
  550. }
  551. //reply form and previous tickets
  552. $allprevious = zb_TicketsGetAllByUser($ticketdata['from']);
  553. $previoustickets = '';
  554. if (!empty($allprevious)) {
  555. $previoustickets = wf_tag('h2') . __('All tickets by this user') . wf_tag('h2', true);
  556. foreach ($allprevious as $io => $eachprevious) {
  557. $tablecells = wf_TableCell($eachprevious['date']);
  558. $tablecells .= wf_TableCell(web_bool_led($eachprevious['status']));
  559. $prevaction = wf_Link('?module=ticketing&showticket=' . $eachprevious['id'], wf_img_sized('skins/icon_search_small.gif', '', '12') . ' ' . __('Show'), false, 'ubButton');
  560. $tablecells .= wf_TableCell($prevaction);
  561. $tablerows = wf_TableRow($tablecells, 'row3');
  562. $previoustickets .= wf_TableBody($tablerows, '100%', '0');
  563. }
  564. }
  565. $tablecells = wf_TableCell(web_TicketReplyForm($ticketid), '50%', '', 'valign="top"');
  566. $tablecells .= wf_TableCell($previoustickets, '50%', '', 'valign="top"');
  567. $tablerows = wf_TableRow($tablecells);
  568. $result .= wf_TableBody($tablerows, '100%', '0', 'glamour');
  569. $result .= wf_CleanDiv();
  570. return ($result);
  571. }
  572. /**
  573. * Renders tickets calendar view widget
  574. *
  575. * @return string
  576. */
  577. function web_TicketsCalendar() {
  578. $query = "SELECT * from `ticketing` WHERE `to` IS NULL AND `replyid` IS NULL ORDER BY `date` ASC";
  579. $all = simple_queryall($query);
  580. $allAddress = zb_AddressGetFulladdresslistCached();
  581. $result = '';
  582. $calendarData = '';
  583. if (!empty($all)) {
  584. foreach ($all as $io => $each) {
  585. $timestamp = strtotime($each['date']);
  586. $date = date("Y, n-1, j", $timestamp);
  587. $rawTime = date("H:i:s", $timestamp);
  588. if ($each['status'] == 0) {
  589. $coloring = "className : 'undone',";
  590. } else {
  591. $coloring = '';
  592. }
  593. $calendarData .= "
  594. {
  595. title: '" . $rawTime . ' ' . @$allAddress[$each['from']] . "',
  596. url: '?module=ticketing&showticket=" . $each['id'] . "',
  597. start: new Date(" . $date . "),
  598. end: new Date(" . $date . "),
  599. " . $coloring . "
  600. },
  601. ";
  602. }
  603. }
  604. $result = wf_FullCalendar($calendarData);
  605. return ($result);
  606. }
  607. /**
  608. * Returns previous ticket events parsed from log.
  609. *
  610. * @param int $TicketID
  611. * @param bool $ReturnHTML
  612. *
  613. * @return array/string
  614. */
  615. function getTicketEvents($TicketID, $ReturnHTML = false) {
  616. $QResult = array();
  617. $HTMLStr = '';
  618. $tQuery = "SELECT * FROM `weblogs` WHERE `event` LIKE 'TICKET%[" . $TicketID . "]' ORDER BY `date` DESC";
  619. $QResult = simple_queryall($tQuery);
  620. if ($ReturnHTML and !empty($QResult)) {
  621. $TableCells = wf_TableCell(__('ID'));
  622. $TableCells .= wf_TableCell(__('Date'));
  623. $TableCells .= wf_TableCell(__('Admin'));
  624. $TableCells .= wf_TableCell(__('IP'));
  625. $TableCells .= wf_TableCell(__('Event'));
  626. $TableRows = wf_TableRow($TableCells, 'row1');
  627. foreach ($QResult as $Rec) {
  628. $Event = htmlspecialchars($Rec['event']);
  629. $TableCells = wf_TableCell($Rec['id']);
  630. $TableCells .= wf_TableCell($Rec['date']);
  631. $TableCells .= wf_TableCell($Rec['admin']);
  632. $TableCells .= wf_TableCell($Rec['ip']);
  633. $TableCells .= wf_TableCell($Event);
  634. $TableRows .= wf_TableRow($TableCells, 'row3');
  635. }
  636. $HTMLStr .= wf_TableBody($TableRows, '100%', 0, 'sortable');
  637. }
  638. return ( ($ReturnHTML) ? $HTMLStr : $QResult );
  639. }
  640. ?>