PageRenderTime 52ms CodeModel.GetById 13ms RepoModel.GetById 0ms app.codeStats 1ms

/upload/catalog/controller/account/return.php

https://github.com/opencartlite/opencart
PHP | 615 lines | 477 code | 138 blank | 0 comment | 100 complexity | c2b1ea6c3d02c4d85f213200b50d6596 MD5 | raw file
Possible License(s): MPL-2.0-no-copyleft-exception, GPL-3.0
  1. <?php
  2. class ControllerAccountReturn extends Controller {
  3. private $error = array();
  4. public function index() {
  5. if (!$this->customer->isLogged()) {
  6. $this->session->data['redirect'] = $this->url->link('account/return', '', 'SSL');
  7. $this->redirect($this->url->link('account/login', '', 'SSL'));
  8. }
  9. $this->data += $this->language->load('account/return');
  10. $this->document->setTitle($this->language->get('heading_title'));
  11. $this->data['breadcrumbs'] = array();
  12. $this->data['breadcrumbs'][] = array(
  13. 'text' => $this->language->get('text_home'),
  14. 'href' => $this->url->link('common/home')
  15. );
  16. $this->data['breadcrumbs'][] = array(
  17. 'text' => $this->language->get('text_account'),
  18. 'href' => $this->url->link('account/account', '', 'SSL')
  19. );
  20. $url = '';
  21. if (isset($this->request->get['page'])) {
  22. $url .= '&page=' . $this->request->get['page'];
  23. }
  24. $this->data['breadcrumbs'][] = array(
  25. 'text' => $this->language->get('heading_title'),
  26. 'href' => $this->url->link('account/return', $url, 'SSL')
  27. );
  28. $this->load->model('account/return');
  29. if (isset($this->request->get['page'])) {
  30. $page = $this->request->get['page'];
  31. } else {
  32. $page = 1;
  33. }
  34. $this->data['returns'] = array();
  35. $return_total = $this->model_account_return->getTotalReturns();
  36. $results = $this->model_account_return->getReturns(($page - 1) * 10, 10);
  37. foreach ($results as $result) {
  38. $this->data['returns'][] = array(
  39. 'return_id' => $result['return_id'],
  40. 'order_id' => $result['order_id'],
  41. 'name' => $result['firstname'] . ' ' . $result['lastname'],
  42. 'status' => $result['status'],
  43. 'date_added' => date($this->language->get('date_format_short'), strtotime($result['date_added'])),
  44. 'href' => $this->url->link('account/return/info', 'return_id=' . $result['return_id'] . $url, 'SSL')
  45. );
  46. }
  47. $pagination = new Pagination();
  48. $pagination->total = $return_total;
  49. $pagination->page = $page;
  50. $pagination->limit = $this->config->get('config_catalog_limit');
  51. $pagination->text = $this->language->get('text_pagination');
  52. $pagination->url = $this->url->link('account/history', 'page={page}', 'SSL');
  53. $this->data['pagination'] = $pagination->render();
  54. $this->data['continue'] = $this->url->link('account/account', '', 'SSL');
  55. if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/account/return_list.tpl')) {
  56. $this->template = $this->config->get('config_template') . '/template/account/return_list.tpl';
  57. } else {
  58. $this->template = 'default/template/account/return_list.tpl';
  59. }
  60. $this->children = array(
  61. 'common/column_left',
  62. 'common/column_right',
  63. 'common/content_top',
  64. 'common/content_bottom',
  65. 'common/footer',
  66. 'common/header'
  67. );
  68. $this->response->setOutput($this->render());
  69. }
  70. public function info() {
  71. $this->data += $this->language->load('account/return');
  72. if (isset($this->request->get['return_id'])) {
  73. $return_id = $this->request->get['return_id'];
  74. } else {
  75. $return_id = 0;
  76. }
  77. if (!$this->customer->isLogged()) {
  78. $this->session->data['redirect'] = $this->url->link('account/return/info', 'return_id=' . $return_id, 'SSL');
  79. $this->redirect($this->url->link('account/login', '', 'SSL'));
  80. }
  81. $this->load->model('account/return');
  82. $return_info = $this->model_account_return->getReturn($return_id);
  83. if ($return_info) {
  84. $this->document->setTitle($this->language->get('text_return'));
  85. $this->data['breadcrumbs'] = array();
  86. $this->data['breadcrumbs'][] = array(
  87. 'text' => $this->language->get('text_home'),
  88. 'href' => $this->url->link('common/home', '', 'SSL')
  89. );
  90. $this->data['breadcrumbs'][] = array(
  91. 'text' => $this->language->get('text_account'),
  92. 'href' => $this->url->link('account/account', '', 'SSL')
  93. );
  94. $url = '';
  95. if (isset($this->request->get['page'])) {
  96. $url .= '&page=' . $this->request->get['page'];
  97. }
  98. $this->data['breadcrumbs'][] = array(
  99. 'text' => $this->language->get('heading_title'),
  100. 'href' => $this->url->link('account/return', $url, 'SSL')
  101. );
  102. $this->data['breadcrumbs'][] = array(
  103. 'text' => $this->language->get('text_return'),
  104. 'href' => $this->url->link('account/return/info', 'return_id=' . $this->request->get['return_id'] . $url, 'SSL')
  105. );
  106. $this->data['heading_title'] = $this->language->get('text_return');
  107. $this->data['return_id'] = $return_info['return_id'];
  108. $this->data['order_id'] = $return_info['order_id'];
  109. $this->data['date_ordered'] = date($this->language->get('date_format_short'), strtotime($return_info['date_ordered']));
  110. $this->data['date_added'] = date($this->language->get('date_format_short'), strtotime($return_info['date_added']));
  111. $this->data['firstname'] = $return_info['firstname'];
  112. $this->data['lastname'] = $return_info['lastname'];
  113. $this->data['email'] = $return_info['email'];
  114. $this->data['telephone'] = $return_info['telephone'];
  115. $this->data['product'] = $return_info['product'];
  116. $this->data['model'] = $return_info['model'];
  117. $this->data['quantity'] = $return_info['quantity'];
  118. $this->data['reason'] = $return_info['reason'];
  119. $this->data['opened'] = $return_info['opened'] ? $this->language->get('text_yes') : $this->language->get('text_no');
  120. $this->data['comment'] = nl2br($return_info['comment']);
  121. $this->data['action'] = $return_info['action'];
  122. $this->data['histories'] = array();
  123. $results = $this->model_account_return->getReturnHistories($this->request->get['return_id']);
  124. foreach ($results as $result) {
  125. $this->data['histories'][] = array(
  126. 'date_added' => date($this->language->get('date_format_short'), strtotime($result['date_added'])),
  127. 'status' => $result['status'],
  128. 'comment' => nl2br($result['comment'])
  129. );
  130. }
  131. $this->data['continue'] = $this->url->link('account/return', $url, 'SSL');
  132. if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/account/return_info.tpl')) {
  133. $this->template = $this->config->get('config_template') . '/template/account/return_info.tpl';
  134. } else {
  135. $this->template = 'default/template/account/return_info.tpl';
  136. }
  137. $this->children = array(
  138. 'common/column_left',
  139. 'common/column_right',
  140. 'common/content_top',
  141. 'common/content_bottom',
  142. 'common/footer',
  143. 'common/header'
  144. );
  145. $this->response->setOutput($this->render());
  146. } else {
  147. $this->document->setTitle($this->language->get('text_return'));
  148. $this->data['breadcrumbs'] = array();
  149. $this->data['breadcrumbs'][] = array(
  150. 'text' => $this->language->get('text_home'),
  151. 'href' => $this->url->link('common/home')
  152. );
  153. $this->data['breadcrumbs'][] = array(
  154. 'text' => $this->language->get('text_account'),
  155. 'href' => $this->url->link('account/account', '', 'SSL')
  156. );
  157. $this->data['breadcrumbs'][] = array(
  158. 'text' => $this->language->get('heading_title'),
  159. 'href' => $this->url->link('account/return', '', 'SSL')
  160. );
  161. $url = '';
  162. if (isset($this->request->get['page'])) {
  163. $url .= '&page=' . $this->request->get['page'];
  164. }
  165. $this->data['breadcrumbs'][] = array(
  166. 'text' => $this->language->get('text_return'),
  167. 'href' => $this->url->link('account/return/info', 'return_id=' . $return_id . $url, 'SSL')
  168. );
  169. $this->data['heading_title'] = $this->language->get('text_return');
  170. $this->data['continue'] = $this->url->link('account/return', '', 'SSL');
  171. if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/error/not_found.tpl')) {
  172. $this->template = $this->config->get('config_template') . '/template/error/not_found.tpl';
  173. } else {
  174. $this->template = 'default/template/error/not_found.tpl';
  175. }
  176. $this->children = array(
  177. 'common/column_left',
  178. 'common/column_right',
  179. 'common/content_top',
  180. 'common/content_bottom',
  181. 'common/footer',
  182. 'common/header'
  183. );
  184. $this->response->setOutput($this->render());
  185. }
  186. }
  187. public function insert() {
  188. $this->data += $this->language->load('account/return');
  189. $this->load->model('account/return');
  190. if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validate()) {
  191. $this->model_account_return->addReturn($this->request->post);
  192. $this->redirect($this->url->link('account/return/success', '', 'SSL'));
  193. }
  194. $this->document->setTitle($this->language->get('heading_title'));
  195. $this->document->addScript('catalog/view/javascript/jquery/colorbox/jquery.colorbox-min.js');
  196. $this->document->addStyle('catalog/view/javascript/jquery/colorbox/colorbox.css');
  197. $this->data['breadcrumbs'] = array();
  198. $this->data['breadcrumbs'][] = array(
  199. 'text' => $this->language->get('text_home'),
  200. 'href' => $this->url->link('common/home')
  201. );
  202. $this->data['breadcrumbs'][] = array(
  203. 'text' => $this->language->get('text_account'),
  204. 'href' => $this->url->link('account/account', '', 'SSL')
  205. );
  206. $this->data['breadcrumbs'][] = array(
  207. 'text' => $this->language->get('heading_title'),
  208. 'href' => $this->url->link('account/return/insert', '', 'SSL')
  209. );
  210. if (isset($this->error['warning'])) {
  211. $this->data['error_warning'] = $this->error['warning'];
  212. } else {
  213. $this->data['error_warning'] = '';
  214. }
  215. if (isset($this->error['order_id'])) {
  216. $this->data['error_order_id'] = $this->error['order_id'];
  217. } else {
  218. $this->data['error_order_id'] = '';
  219. }
  220. if (isset($this->error['firstname'])) {
  221. $this->data['error_firstname'] = $this->error['firstname'];
  222. } else {
  223. $this->data['error_firstname'] = '';
  224. }
  225. if (isset($this->error['lastname'])) {
  226. $this->data['error_lastname'] = $this->error['lastname'];
  227. } else {
  228. $this->data['error_lastname'] = '';
  229. }
  230. if (isset($this->error['email'])) {
  231. $this->data['error_email'] = $this->error['email'];
  232. } else {
  233. $this->data['error_email'] = '';
  234. }
  235. if (isset($this->error['telephone'])) {
  236. $this->data['error_telephone'] = $this->error['telephone'];
  237. } else {
  238. $this->data['error_telephone'] = '';
  239. }
  240. if (isset($this->error['product'])) {
  241. $this->data['error_product'] = $this->error['product'];
  242. } else {
  243. $this->data['error_product'] = '';
  244. }
  245. if (isset($this->error['model'])) {
  246. $this->data['error_model'] = $this->error['model'];
  247. } else {
  248. $this->data['error_model'] = '';
  249. }
  250. if (isset($this->error['reason'])) {
  251. $this->data['error_reason'] = $this->error['reason'];
  252. } else {
  253. $this->data['error_reason'] = '';
  254. }
  255. if (isset($this->error['captcha'])) {
  256. $this->data['error_captcha'] = $this->error['captcha'];
  257. } else {
  258. $this->data['error_captcha'] = '';
  259. }
  260. $this->data['action'] = $this->url->link('account/return/insert', '', 'SSL');
  261. $this->load->model('account/order');
  262. if (isset($this->request->get['order_id'])) {
  263. $order_info = $this->model_account_order->getOrder($this->request->get['order_id']);
  264. }
  265. $this->load->model('catalog/product');
  266. if (isset($this->request->get['product_id'])) {
  267. $product_info = $this->model_catalog_product->getProduct($this->request->get['product_id']);
  268. }
  269. if (isset($this->request->post['order_id'])) {
  270. $this->data['order_id'] = $this->request->post['order_id'];
  271. } elseif (!empty($order_info)) {
  272. $this->data['order_id'] = $order_info['order_id'];
  273. } else {
  274. $this->data['order_id'] = '';
  275. }
  276. if (isset($this->request->post['date_ordered'])) {
  277. $this->data['date_ordered'] = $this->request->post['date_ordered'];
  278. } elseif (!empty($order_info)) {
  279. $this->data['date_ordered'] = date('Y-m-d', strtotime($order_info['date_added']));
  280. } else {
  281. $this->data['date_ordered'] = '';
  282. }
  283. if (isset($this->request->post['firstname'])) {
  284. $this->data['firstname'] = $this->request->post['firstname'];
  285. } elseif (!empty($order_info)) {
  286. $this->data['firstname'] = $order_info['firstname'];
  287. } else {
  288. $this->data['firstname'] = $this->customer->getFirstName();
  289. }
  290. if (isset($this->request->post['lastname'])) {
  291. $this->data['lastname'] = $this->request->post['lastname'];
  292. } elseif (!empty($order_info)) {
  293. $this->data['lastname'] = $order_info['lastname'];
  294. } else {
  295. $this->data['lastname'] = $this->customer->getLastName();
  296. }
  297. if (isset($this->request->post['email'])) {
  298. $this->data['email'] = $this->request->post['email'];
  299. } elseif (!empty($order_info)) {
  300. $this->data['email'] = $order_info['email'];
  301. } else {
  302. $this->data['email'] = $this->customer->getEmail();
  303. }
  304. if (isset($this->request->post['telephone'])) {
  305. $this->data['telephone'] = $this->request->post['telephone'];
  306. } elseif (!empty($order_info)) {
  307. $this->data['telephone'] = $order_info['telephone'];
  308. } else {
  309. $this->data['telephone'] = $this->customer->getTelephone();
  310. }
  311. if (isset($this->request->post['product'])) {
  312. $this->data['product'] = $this->request->post['product'];
  313. } elseif (!empty($product_info)) {
  314. $this->data['product'] = $product_info['name'];
  315. } else {
  316. $this->data['product'] = '';
  317. }
  318. if (isset($this->request->post['model'])) {
  319. $this->data['model'] = $this->request->post['model'];
  320. } elseif (!empty($product_info)) {
  321. $this->data['model'] = $product_info['model'];
  322. } else {
  323. $this->data['model'] = '';
  324. }
  325. if (isset($this->request->post['quantity'])) {
  326. $this->data['quantity'] = $this->request->post['quantity'];
  327. } else {
  328. $this->data['quantity'] = 1;
  329. }
  330. if (isset($this->request->post['opened'])) {
  331. $this->data['opened'] = $this->request->post['opened'];
  332. } else {
  333. $this->data['opened'] = false;
  334. }
  335. if (isset($this->request->post['return_reason_id'])) {
  336. $this->data['return_reason_id'] = $this->request->post['return_reason_id'];
  337. } else {
  338. $this->data['return_reason_id'] = '';
  339. }
  340. $this->load->model('localisation/return_reason');
  341. $this->data['return_reasons'] = $this->model_localisation_return_reason->getReturnReasons();
  342. if (isset($this->request->post['comment'])) {
  343. $this->data['comment'] = $this->request->post['comment'];
  344. } else {
  345. $this->data['comment'] = '';
  346. }
  347. if (isset($this->request->post['captcha'])) {
  348. $this->data['captcha'] = $this->request->post['captcha'];
  349. } else {
  350. $this->data['captcha'] = '';
  351. }
  352. if ($this->config->get('config_return_id')) {
  353. $this->load->model('catalog/information');
  354. $information_info = $this->model_catalog_information->getInformation($this->config->get('config_return_id'));
  355. if ($information_info) {
  356. $this->data['text_agree'] = sprintf($this->language->get('text_agree'), $this->url->link('information/information/info', 'information_id=' . $this->config->get('config_return_id'), 'SSL'), $information_info['title'], $information_info['title']);
  357. } else {
  358. $this->data['text_agree'] = '';
  359. }
  360. } else {
  361. $this->data['text_agree'] = '';
  362. }
  363. if (isset($this->request->post['agree'])) {
  364. $this->data['agree'] = $this->request->post['agree'];
  365. } else {
  366. $this->data['agree'] = false;
  367. }
  368. $this->data['back'] = $this->url->link('account/account', '', 'SSL');
  369. if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/account/return_form.tpl')) {
  370. $this->template = $this->config->get('config_template') . '/template/account/return_form.tpl';
  371. } else {
  372. $this->template = 'default/template/account/return_form.tpl';
  373. }
  374. $this->children = array(
  375. 'common/column_left',
  376. 'common/column_right',
  377. 'common/content_top',
  378. 'common/content_bottom',
  379. 'common/footer',
  380. 'common/header'
  381. );
  382. $this->response->setOutput($this->render());
  383. }
  384. public function success() {
  385. $this->data += $this->language->load('account/return');
  386. $this->document->setTitle($this->language->get('heading_title'));
  387. $this->data['breadcrumbs'] = array();
  388. $this->data['breadcrumbs'][] = array(
  389. 'text' => $this->language->get('text_home'),
  390. 'href' => $this->url->link('common/home')
  391. );
  392. $this->data['breadcrumbs'][] = array(
  393. 'text' => $this->language->get('heading_title'),
  394. 'href' => $this->url->link('account/return', '', 'SSL')
  395. );
  396. $this->data['continue'] = $this->url->link('common/home');
  397. if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/common/success.tpl')) {
  398. $this->template = $this->config->get('config_template') . '/template/common/success.tpl';
  399. } else {
  400. $this->template = 'default/template/common/success.tpl';
  401. }
  402. $this->children = array(
  403. 'common/column_left',
  404. 'common/column_right',
  405. 'common/content_top',
  406. 'common/content_bottom',
  407. 'common/footer',
  408. 'common/header'
  409. );
  410. $this->response->setOutput($this->render());
  411. }
  412. protected function validate() {
  413. if (!$this->request->post['order_id']) {
  414. $this->error['order_id'] = $this->language->get('error_order_id');
  415. }
  416. if ((utf8_strlen($this->request->post['firstname']) < 1) || (utf8_strlen($this->request->post['firstname']) > 32)) {
  417. $this->error['firstname'] = $this->language->get('error_firstname');
  418. }
  419. if ((utf8_strlen($this->request->post['lastname']) < 1) || (utf8_strlen($this->request->post['lastname']) > 32)) {
  420. $this->error['lastname'] = $this->language->get('error_lastname');
  421. }
  422. if ((utf8_strlen($this->request->post['email']) > 96) || !preg_match('/^[^\@]+@.*\.[a-z]{2,6}$/i', $this->request->post['email'])) {
  423. $this->error['email'] = $this->language->get('error_email');
  424. }
  425. if ((utf8_strlen($this->request->post['telephone']) < 3) || (utf8_strlen($this->request->post['telephone']) > 32)) {
  426. $this->error['telephone'] = $this->language->get('error_telephone');
  427. }
  428. if ((utf8_strlen($this->request->post['product']) < 1) || (utf8_strlen($this->request->post['product']) > 255)) {
  429. $this->error['product'] = $this->language->get('error_product');
  430. }
  431. if ((utf8_strlen($this->request->post['model']) < 1) || (utf8_strlen($this->request->post['model']) > 64)) {
  432. $this->error['model'] = $this->language->get('error_model');
  433. }
  434. if (empty($this->request->post['return_reason_id'])) {
  435. $this->error['reason'] = $this->language->get('error_reason');
  436. }
  437. if (empty($this->session->data['captcha']) || ($this->session->data['captcha'] != $this->request->post['captcha'])) {
  438. $this->error['captcha'] = $this->language->get('error_captcha');
  439. }
  440. if ($this->config->get('config_return_id')) {
  441. $this->load->model('catalog/information');
  442. $information_info = $this->model_catalog_information->getInformation($this->config->get('config_return_id'));
  443. if ($information_info && !isset($this->request->post['agree'])) {
  444. $this->error['warning'] = sprintf($this->language->get('error_agree'), $information_info['title']);
  445. }
  446. }
  447. if (!$this->error) {
  448. return true;
  449. } else {
  450. return false;
  451. }
  452. }
  453. public function captcha() {
  454. $this->session->data['captcha'] = substr(sha1(mt_rand()), 17, 6);
  455. $image = imagecreatetruecolor(150, 35);
  456. $width = imagesx($image);
  457. $height = imagesy($image);
  458. $black = imagecolorallocate($image, 0, 0, 0);
  459. $white = imagecolorallocate($image, 255, 255, 255);
  460. $red = imagecolorallocatealpha($image, 255, 0, 0, 75);
  461. $green = imagecolorallocatealpha($image, 0, 255, 0, 75);
  462. $blue = imagecolorallocatealpha($image, 0, 0, 255, 75);
  463. imagefilledrectangle($image, 0, 0, $width, $height, $white);
  464. imagefilledellipse($image, ceil(rand(5, 145)), ceil(rand(0, 35)), 30, 30, $red);
  465. imagefilledellipse($image, ceil(rand(5, 145)), ceil(rand(0, 35)), 30, 30, $green);
  466. imagefilledellipse($image, ceil(rand(5, 145)), ceil(rand(0, 35)), 30, 30, $blue);
  467. imagefilledrectangle($image, 0, 0, $width, 0, $black);
  468. imagefilledrectangle($image, $width - 1, 0, $width - 1, $height - 1, $black);
  469. imagefilledrectangle($image, 0, 0, 0, $height - 1, $black);
  470. imagefilledrectangle($image, 0, $height - 1, $width, $height - 1, $black);
  471. imagestring($image, 10, intval(($width - (strlen($this->session->data['captcha']) * 9)) / 2), intval(($height - 15) / 2), $this->session->data['captcha'], $black);
  472. header('Content-type: image/jpeg');
  473. imagejpeg($image);
  474. imagedestroy($image);
  475. }
  476. }
  477. ?>