PageRenderTime 29ms CodeModel.GetById 17ms RepoModel.GetById 1ms app.codeStats 0ms

/modules/storecommander/ead6f6fce09/SC/lib/cusm/cusm_discussion_answer.php

https://gitlab.com/ptisky/API_prestashop
PHP | 458 lines | 366 code | 45 blank | 47 comment | 41 complexity | 9ace62c592fa66e28ab3fdc0ef70eabc MD5 | raw file
  1. <?php
  2. /**
  3. * Store Commander
  4. *
  5. * @category administration
  6. * @author Store Commander - support@storecommander.com
  7. * @version 2015-09-15
  8. * @uses Prestashop modules
  9. * @since 2009
  10. * @copyright Copyright &copy; 2009-2015, Store Commander
  11. * @license commercial
  12. * All rights reserved! Copying, duplication strictly prohibited
  13. *
  14. * *****************************************
  15. * * STORE COMMANDER *
  16. * * http://www.StoreCommander.com *
  17. * * V 2015-09-15 *
  18. * *****************************************
  19. *
  20. * Compatibility: PS version: 1.1 to 1.6.1
  21. *
  22. **/
  23. /**
  24. * Store Commander
  25. *
  26. * @category administration
  27. * @author Store Commander - support@storecommander.com
  28. * @version 2015-09-15
  29. * @uses Prestashop modules
  30. * @since 2009
  31. * @copyright Copyright &copy; 2009-2015, Store Commander
  32. * @license commercial
  33. * All rights reserved! Copying, duplication strictly prohibited
  34. *
  35. * *****************************************
  36. * * STORE COMMANDER *
  37. * * http://www.StoreCommander.com *
  38. * * V 2015-09-15 *
  39. * *****************************************
  40. *
  41. * Compatibility: PS version: 1.1 to 1.6.1
  42. *
  43. **/
  44. $id_discussion=intval(Tools::getValue('id',0));
  45. $id_lang=intval(Tools::getValue('id_lang',0));
  46. $errors = array();
  47. $success = false;
  48. function displayMessageEmail($message_infos)
  49. {
  50. $return = "";
  51. if(!empty($message_infos["message"]))
  52. {
  53. $name = $message_infos['customer_name']." ("._l("Customer").")";
  54. if(!empty($message_infos['id_employee']))
  55. {
  56. $name = $message_infos['employee_name']." ("._l("Advisor").")";
  57. }
  58. $message_infos['message'] = preg_replace(
  59. '/(https?:\/\/[a-z0-9#%&_=\(\)\.\? \+\-@\/]{6,1000})([\s\n<])/Uui',
  60. '<a href="\1">\1</a>\2',
  61. html_entity_decode($message_infos['message'],
  62. ENT_NOQUOTES, 'UTF-8')
  63. );
  64. $return .= '<p><strong>'.$name.'</strong> ('.$message_infos["date_add"].') : '.$message_infos["message"].'</p><br/>';
  65. }
  66. return $return;
  67. }
  68. if(isset($_POST["submitSend"]))
  69. {
  70. if(empty($_POST["message"]))
  71. $errors[] = _l('You must write a message to send an answer');
  72. if(version_compare(_PS_VERSION_, '1.5.0.0', '>=') && !empty($_POST["private"]))
  73. $private = $_POST["private"];
  74. if(!empty($_POST["id_employee"]))
  75. $transert_to = $_POST["id_employee"];
  76. if (isset($_FILES) && !empty($_FILES['file']['name']) && $_FILES['file']['error'] != 0)
  77. $errors[] = _l('An error occured during file upload. Please try again.');
  78. else
  79. {
  80. $file_attachment = null;
  81. if (!empty($_FILES['file']['name']))
  82. {
  83. $file_attachment['content'] = file_get_contents($_FILES['file']['tmp_name']);
  84. $file_attachment['name'] = $_FILES['file']['name'];
  85. $file_attachment['mime'] = $_FILES['file']['type'];
  86. }
  87. }
  88. if(empty($errors))
  89. {
  90. // REPONSE NORMALE
  91. if(empty($transert_to))
  92. {
  93. $ct = new CustomerThread($id_discussion);
  94. $cm = new CustomerMessage();
  95. $cm->id_employee = (int)$sc_agent->id_employee;
  96. $cm->id_customer_thread = $ct->id;
  97. $cm->message = Tools::htmlentitiesutf8(Tools::getValue('message'));
  98. $cm->ip_address = ip2long($_SERVER['REMOTE_ADDR']);
  99. if(version_compare(_PS_VERSION_, '1.5.0.0', '>='))
  100. $cm->private = (int)$private;
  101. $customer = new Customer($ct->id_customer);
  102. if ($cm->add())
  103. {
  104. $link = new Link();
  105. if(version_compare(_PS_VERSION_, '1.5.0.0', '>='))
  106. {
  107. $params = array(
  108. '{reply}' => nl2br(Tools::getValue('message')),
  109. '{link}' => Tools::url(
  110. $link->getPageLink('contact', true),
  111. 'id_customer_thread='.(int)$ct->id.'&token='.$ct->token
  112. ),
  113. '{firstname}' => $customer->firstname,
  114. '{lastname}' => $customer->lastname
  115. );
  116. }
  117. else
  118. {
  119. $params = array(
  120. '{reply}' => nl2br(Tools::getValue('message')),
  121. '{link}' => $link->getPageLink('contact', true),
  122. 'id_customer_thread='.(int)$ct->id.'&token='.$ct->token
  123. );
  124. }
  125. // Envoi du message au client
  126. $to_update = false;
  127. if($cm->private)
  128. $to_update=true;
  129. else
  130. {
  131. $send_email = true;
  132. if(version_compare(_PS_VERSION_, '1.6.0.0', '>=') && SCI::getConfigurationValue("PS_MAIL_METHOD")==3)
  133. $send_email = false;
  134. if($send_email)
  135. {
  136. if(!SCMS)
  137. {
  138. $to_update=Mail::Send(
  139. (int)$ct->id_lang,
  140. 'reply_msg',
  141. sprintf(Mail::l('An answer to your message is available #ct%1$s #tc%2$s', $ct->id_lang), $ct->id, $ct->token),
  142. $params,
  143. $ct->email,
  144. null,
  145. null,
  146. null,
  147. $file_attachment,
  148. null,
  149. _PS_MAIL_DIR_,
  150. true);
  151. }
  152. else
  153. {
  154. $to_update=Mail::Send(
  155. (int)$ct->id_lang,
  156. 'reply_msg',
  157. sprintf(Mail::l('An answer to your message is available #ct%1$s #tc%2$s', $ct->id_lang), $ct->id, $ct->token),
  158. $params,
  159. $ct->email,
  160. null,
  161. null,
  162. null,
  163. $file_attachment,
  164. null,
  165. _PS_MAIL_DIR_,
  166. true,
  167. SCI::getSelectedShop());
  168. }
  169. }
  170. else
  171. {
  172. $to_update=true;
  173. }
  174. }
  175. if ($to_update)
  176. {
  177. //$ct->status = 'closed';
  178. $ct->update();
  179. $success = true;
  180. }
  181. }
  182. }
  183. // TRANSFERT A UN EMPLOYEE
  184. elseif(!empty($transert_to))
  185. {
  186. $messages = Db::getInstance()->executeS('
  187. SELECT ct.*, cm.*, cl.name subject, CONCAT(e.firstname, \' \', e.lastname) employee_name,
  188. CONCAT(c.firstname, \' \', c.lastname) customer_name, c.firstname
  189. FROM '._DB_PREFIX_.'customer_thread ct
  190. LEFT JOIN '._DB_PREFIX_.'customer_message cm
  191. ON (ct.id_customer_thread = cm.id_customer_thread)
  192. LEFT JOIN '._DB_PREFIX_.'contact_lang cl
  193. ON (cl.id_contact = ct.id_contact AND cl.id_lang = '.(int)$id_lang.')
  194. LEFT OUTER JOIN '._DB_PREFIX_.'employee e
  195. ON e.id_employee = cm.id_employee
  196. LEFT OUTER JOIN '._DB_PREFIX_.'customer c
  197. ON (c.email = ct.email)
  198. WHERE ct.id_customer_thread = '.(int)$id_discussion.'
  199. ORDER BY cm.date_add DESC
  200. ');
  201. $output = '';
  202. foreach ($messages as $message)
  203. {
  204. $output .= displayMessageEmail($message);
  205. }
  206. $cm = new CustomerMessage();
  207. $cm->id_employee = (int)$sc_agent->id_employee;
  208. $cm->id_customer_thread = (int)$id_discussion;
  209. $cm->ip_address = ip2long($_SERVER['REMOTE_ADDR']);
  210. $current_employee = $sc_agent;
  211. $id_employee = (int)$transert_to;
  212. $employee = new Employee($id_employee);
  213. $email = $employee->email;
  214. if ($id_employee && $employee && Validate::isLoadedObject($employee))
  215. {
  216. $to_update = false;
  217. $send_email = true;
  218. if(version_compare(_PS_VERSION_, '1.6.0.0', '>=') && SCI::getConfigurationValue("PS_MAIL_METHOD")==3)
  219. $send_email = false;
  220. if($send_email)
  221. {
  222. if(version_compare(_PS_VERSION_, '1.6.0.0', '>='))
  223. {
  224. $params = array(
  225. '{messages}' => stripslashes($output),
  226. '{employee}' => $current_employee->firstname.' '.$current_employee->lastname,
  227. '{comment}' => stripslashes(Tools::nl2br($_POST['message'])),
  228. '{firstname}' => $employee->firstname,
  229. '{lastname}' => $employee->lastname,
  230. );
  231. }
  232. else
  233. {
  234. $params = array(
  235. '{messages}' => nl2br(stripslashes($output)),
  236. '{employee}' => $current_employee->firstname.' '.$current_employee->lastname,
  237. '{comment}' => stripslashes($_POST['message']));
  238. }
  239. $to_update = Mail::Send(
  240. $id_lang,
  241. 'forward_msg',
  242. Mail::l('Fwd: Customer message', $id_lang),
  243. $params,
  244. $employee->email,
  245. $employee->firstname.' '.$employee->lastname,
  246. $current_employee->email,
  247. $current_employee->firstname.' '.$current_employee->lastname,
  248. $file_attachment,
  249. null,
  250. _PS_MAIL_DIR_,
  251. true);
  252. }
  253. else
  254. $to_update=true;
  255. if ($to_update)
  256. {
  257. if(version_compare(_PS_VERSION_, '1.5.0.0', '>='))
  258. $cm->private = 1;
  259. $cm->message = _l('Message forwarded to').' '.$employee->firstname.' '.$employee->lastname."\n"._l('Comment:').' '.$_POST['message'];
  260. $cm->add();
  261. $success = true;
  262. }
  263. }
  264. }
  265. }
  266. }
  267. ?><!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
  268. <html>
  269. <head>
  270. <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  271. <title>SC - Affiliation</title>
  272. <style type="text/css">
  273. html, body, div, span, applet, object, iframe,
  274. h1, h2, h3, h4, h5, h6, p, blockquote, pre,
  275. a, abbr, acronym, address, big, cite, code,
  276. del, dfn, em, img, ins, kbd, q, s, samp,
  277. small, strike, strong, sub, sup, tt, var,
  278. b, u, i, center,
  279. dl, dt, dd, ol, ul, li,
  280. fieldset, form, label, legend,
  281. table, caption, tbody, tfoot, thead, tr, th, td,
  282. article, aside, canvas, details, embed,
  283. figure, figcaption, footer, header, hgroup,
  284. menu, nav, output, ruby, section, summary,
  285. time, mark, audio, video {
  286. margin: 0;
  287. padding: 0;
  288. border: 0;
  289. font-size: 100%;
  290. font: inherit;
  291. vertical-align: baseline;
  292. }
  293. /* HTML5 display-role reset for older browsers */
  294. article, aside, details, figcaption, figure,
  295. footer, header, hgroup, menu, nav, section {
  296. display: block;
  297. }
  298. body {
  299. line-height: 1;
  300. color: #000000;
  301. font-family: Tahoma;
  302. }
  303. ol, ul {
  304. list-style: none;
  305. }
  306. blockquote, q {
  307. quotes: none;
  308. }
  309. blockquote:before, blockquote:after,
  310. q:before, q:after {
  311. content: '';
  312. content: none;
  313. }
  314. table {
  315. border-collapse: collapse;
  316. border-spacing: 0;
  317. }
  318. label {
  319. width: 130px;
  320. font-size: 11px;
  321. color: #000000;
  322. font-weight: bold;
  323. float: left;
  324. line-height: 20px;
  325. }
  326. .btn {
  327. background: linear-gradient(#e2efff, #d3e7ff) repeat scroll 0 0 rgba(0, 0, 0, 0);
  328. border: 1px solid #a4bed4;
  329. color: #34404b;
  330. font-size: 11px;
  331. height: 27px;
  332. overflow: hidden;
  333. position: relative;
  334. font-weight: bold;
  335. cursor: pointer;
  336. }
  337. .btn.submit {float: right; margin-left: 20px;}
  338. .left {float: left;}
  339. .right {float: right; margin-left: 20px; height: 27px; line-height: 27px;}
  340. .error {
  341. padding: 10px;
  342. border: 1px solid #ce0000;
  343. color: #ce0000;
  344. background: #ffe4e4;
  345. margin: 10px;
  346. font-size: 11px;
  347. }
  348. </style>
  349. <script type="text/javascript" src="<?php echo SC_JQUERY;?>"></script>
  350. <script type="text/javascript">
  351. <?php if($success) { ?>
  352. parent.successAnswer();
  353. <?php } ?>
  354. function orderOverwriteMessage(sl, text)
  355. {
  356. var $zone = $('#txt_msg');
  357. var sl_value = sl.options[sl.selectedIndex].value;
  358. if (sl_value != '0')
  359. {
  360. if ($zone.val().length > 0 && !confirm(text))
  361. return ;
  362. $zone.val(sl_value);
  363. }
  364. }
  365. </script>
  366. </head>
  367. <body>
  368. <form method="post" action="" enctype="multipart/form-data">
  369. <?php
  370. if(!empty($errors))
  371. {
  372. echo '<div class="error">';
  373. foreach($errors as $error)
  374. {
  375. echo $error.'<br/>';
  376. }
  377. echo '</div>';
  378. }
  379. ?>
  380. <textarea name="message" id="txt_msg" style="height: 5em; width: 95%; margin-bottom: 1em;"></textarea>
  381. <label><?php echo _l('Attachment')?></label><input type="file" name="file" value="" />
  382. <button type="submit" name="submitSend" class="btn submit"><?php echo _l('Send')?></button>
  383. <?php if(version_compare(_PS_VERSION_, '1.5.0.0', '>=')) { ?>
  384. <label class="right" style="width: auto; margin-left: 5px;"><?php echo _l('Private')?></label>
  385. <input type="checkbox" name="private" value="1" class="right" />
  386. <?php } ?>
  387. <select name="id_employee" class="right">
  388. <option value=""><?php echo _l('Transfer to...')?></option>
  389. <?php
  390. $employees = Employee::getEmployees();
  391. foreach ($employees as $employee)
  392. {
  393. if(version_compare(_PS_VERSION_, '1.5.0.0', '>='))
  394. echo '<option value="'.$employee["id_employee"].'">'.$employee["firstname"].' '.$employee["lastname"].'</option>';
  395. else
  396. echo '<option value="'.$employee["id_employee"].'">'.$employee["name"].'</option>';
  397. }
  398. ?>
  399. </select>
  400. <select name="order_message" id="order_message" onchange="orderOverwriteMessage(this, '<?php echo _l('Do you want to overwrite your existing message?')?>')" class="right">
  401. <option value=""><?php echo _l('Choose a standard message')?></option>
  402. <?php
  403. $orderMessages = OrderMessage::getOrderMessages((int)$id_lang);
  404. foreach ($orderMessages as $orderMessage)
  405. {
  406. echo '<option value="'.strip_tags($orderMessage['message']).'">'.$orderMessage['name'].'</option>';
  407. }
  408. ?>
  409. </select>
  410. <div style="clear: both;"></div>
  411. </form>
  412. </body>
  413. </html>