PageRenderTime 47ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 0ms

/opencart_v1.4/upload/admin/controller/common/home.php

http://coderstalk.googlecode.com/
PHP | 255 lines | 199 code | 56 blank | 0 comment | 28 complexity | bd16a889aac7a7c7cb2a222d5f97db78 MD5 | raw file
Possible License(s): GPL-3.0, LGPL-2.1, AGPL-3.0
  1. <?php
  2. class ControllerCommonHome extends Controller {
  3. public function index() {
  4. $this->load->language('common/home');
  5. $this->document->title = $this->language->get('heading_title');
  6. $this->data['heading_title'] = $this->language->get('heading_title');
  7. $this->data['text_overview'] = $this->language->get('text_overview');
  8. $this->data['text_statistics'] = $this->language->get('text_statistics');
  9. $this->data['text_latest_10_orders'] = $this->language->get('text_latest_10_orders');
  10. $this->data['text_total_sale'] = $this->language->get('text_total_sale');
  11. $this->data['text_total_sale_year'] = $this->language->get('text_total_sale_year');
  12. $this->data['text_total_order'] = $this->language->get('text_total_order');
  13. $this->data['text_total_customer'] = $this->language->get('text_total_customer');
  14. $this->data['text_total_customer_approval'] = $this->language->get('text_total_customer_approval');
  15. $this->data['text_total_product'] = $this->language->get('text_total_product');
  16. $this->data['text_total_review'] = $this->language->get('text_total_review');
  17. $this->data['text_total_review_approval'] = $this->language->get('text_total_review_approval');
  18. $this->data['text_day'] = $this->language->get('text_day');
  19. $this->data['text_week'] = $this->language->get('text_week');
  20. $this->data['text_month'] = $this->language->get('text_month');
  21. $this->data['text_year'] = $this->language->get('text_year');
  22. $this->data['text_no_results'] = $this->language->get('text_no_results');
  23. $this->data['column_order'] = $this->language->get('column_order');
  24. $this->data['column_name'] = $this->language->get('column_name');
  25. $this->data['column_status'] = $this->language->get('column_status');
  26. $this->data['column_date_added'] = $this->language->get('column_date_added');
  27. $this->data['column_total'] = $this->language->get('column_total');
  28. $this->data['column_firstname'] = $this->language->get('column_firstname');
  29. $this->data['column_lastname'] = $this->language->get('column_lastname');
  30. $this->data['column_action'] = $this->language->get('column_action');
  31. $this->data['entry_range'] = $this->language->get('entry_range');
  32. $this->document->breadcrumbs = array();
  33. $this->document->breadcrumbs[] = array(
  34. 'href' => $this->url->https('common/home'),
  35. 'text' => $this->language->get('text_home'),
  36. 'separator' => FALSE
  37. );
  38. $this->load->model('sale/order');
  39. $this->data['total_sale'] = $this->currency->format($this->model_sale_order->getTotalSales(), $this->config->get('config_currency'));
  40. $this->data['total_sale_year'] = $this->currency->format($this->model_sale_order->getTotalSalesByYear(date('Y')), $this->config->get('config_currency'));
  41. $this->data['total_order'] = $this->model_sale_order->getTotalOrders();
  42. $this->load->model('sale/customer');
  43. $this->data['total_customer'] = $this->model_sale_customer->getTotalCustomers();
  44. $this->data['total_customer_approval'] = $this->model_sale_customer->getTotalCustomersAwatingApproval();
  45. $this->load->model('catalog/product');
  46. $this->data['total_product'] = $this->model_catalog_product->getTotalProducts();
  47. $this->load->model('catalog/review');
  48. $this->data['total_review'] = $this->model_catalog_review->getTotalReviews();
  49. $this->data['total_review_approval'] = $this->model_catalog_review->getTotalReviewsAwatingApproval();
  50. $this->data['orders'] = array();
  51. $data = array(
  52. 'sort' => 'o.date_added',
  53. 'order' => 'DESC',
  54. 'start' => 0,
  55. 'limit' => 10
  56. );
  57. $results = $this->model_sale_order->getOrders($data);
  58. foreach ($results as $result) {
  59. $action = array();
  60. $action[] = array(
  61. 'text' => $this->language->get('text_edit'),
  62. 'href' => $this->url->https('sale/order/update&order_id=' . $result['order_id'])
  63. );
  64. $this->data['orders'][] = array(
  65. 'order_id' => $result['order_id'],
  66. 'name' => $result['name'],
  67. 'status' => $result['status'],
  68. 'date_added' => date($this->language->get('date_format_short'), strtotime($result['date_added'])),
  69. 'total' => $this->currency->format($result['total'], $result['currency'], $result['value']),
  70. 'action' => $action
  71. );
  72. }
  73. if ($this->config->get('config_currency_auto')) {
  74. $this->load->model('localisation/currency');
  75. $this->model_localisation_currency->updateCurrencies();
  76. }
  77. $this->template = 'common/home.tpl';
  78. $this->children = array(
  79. 'common/header',
  80. 'common/footer'
  81. );
  82. $this->response->setOutput($this->render(TRUE), $this->config->get('config_compression'));
  83. }
  84. public function chart() {
  85. $this->load->language('common/home');
  86. $data = array();
  87. $data['order'] = array();
  88. $data['customer'] = array();
  89. $data['xaxis'] = array();
  90. $data['order']['label'] = $this->language->get('text_order');
  91. $data['customer']['label'] = $this->language->get('text_customer');
  92. if (isset($this->request->get['range'])) {
  93. $range = $this->request->get['range'];
  94. } else {
  95. $range = 'month';
  96. }
  97. switch ($range) {
  98. case 'day':
  99. for ($i = 0; $i <= 23; $i++) {
  100. $query = $this->db->query("SELECT COUNT(*) AS total FROM `" . DB_PREFIX . "order` WHERE order_status_id > '0' AND (DATE(date_added) = DATE(NOW()) AND HOUR(date_added) = '" . (int)$i . "') GROUP BY HOUR(date_added) ORDER BY date_added ASC");
  101. if ($query->num_rows) {
  102. $data['order']['data'][] = array(date('G', strtotime('-' . (int)$i . ' hour')), (int)$query->row['total']);
  103. } else {
  104. $data['order']['data'][] = array(date('G', strtotime('-' . (int)$i . ' hour')), 0);
  105. }
  106. $query = $this->db->query("SELECT COUNT(*) AS total FROM " . DB_PREFIX . "customer WHERE DATE(date_added) = DATE(NOW()) AND HOUR(date_added) = '" . (int)$i . "' GROUP BY HOUR(date_added) ORDER BY date_added ASC");
  107. if ($query->num_rows) {
  108. $data['customer']['data'][] = array(date('G', strtotime('-' . (int)$i . ' hour')), (int)$query->row['total']);
  109. } else {
  110. $data['customer']['data'][] = array(date('G', strtotime('-' . (int)$i . ' hour')), 0);
  111. }
  112. $data['xaxis'][] = array(date('G', strtotime('-' . (int)$i . ' hour')), date('H', strtotime('-' . (int)$i . ' hour')));
  113. }
  114. break;
  115. case 'week':
  116. $week = mktime(0, 0, 0, date('m'), date('d') - date('w'), date('Y'));
  117. for ($i = 0; $i < 7; $i++) {
  118. $query = $this->db->query("SELECT COUNT(*) AS total FROM `" . DB_PREFIX . "order` WHERE order_status_id > '0' AND DATE(date_added) = DATE('" . date('Y-m-d', $week + ($i * 86400)) . "') GROUP BY DAY(date_added)");
  119. if ($query->num_rows) {
  120. $data['order']['data'][] = array(date('d', strtotime('-' . (int)$i . ' day')), (int)$query->row['total']);
  121. } else {
  122. $data['order']['data'][] = array(date('d', strtotime('-' . (int)$i . ' day')), 0);
  123. }
  124. $query = $this->db->query("SELECT COUNT(*) AS total FROM " . DB_PREFIX . "customer WHERE DATE(date_added) = DATE('" . date('Y-m-d', $week + ($i * 86400)) . "') GROUP BY DAY(date_added)");
  125. if ($query->num_rows) {
  126. $data['customer']['data'][] = array(date('d', strtotime('-' . (int)$i . ' day')), (int)$query->row['total']);
  127. } else {
  128. $data['customer']['data'][] = array(date('d', strtotime('-' . (int)$i . ' day')), 0);
  129. }
  130. $data['xaxis'][] = array(date('d', strtotime('-' . (int)$i . ' day')), date('d/m', strtotime('-' . (int)$i . ' day')));
  131. }
  132. break;
  133. default:
  134. case 'month':
  135. $last_day_of_the_month = mktime(23, 59, 59, date('m'), 0, date('Y'));
  136. for ($i = 1; $i <= date('j', $last_day_of_the_month); $i++) {
  137. $query = $this->db->query("SELECT COUNT(*) AS total FROM `" . DB_PREFIX . "order` WHERE order_status_id > '0' AND (DATE(date_added) = '" . date('Y-m-d', strtotime('-' . (int)$i . ' day')) . "') GROUP BY DAY(date_added)");
  138. if ($query->num_rows) {
  139. $data['order']['data'][] = array(date('d', strtotime('-' . (int)$i . ' day')), (int)$query->row['total']);
  140. } else {
  141. $data['order']['data'][] = array(date('d', strtotime('-' . (int)$i . ' day')), 0);
  142. }
  143. $query = $this->db->query("SELECT COUNT(*) AS total FROM " . DB_PREFIX . "customer WHERE DATE(date_added) = '" . date('Y-m-d', strtotime('-' . (int)$i . ' day')) . "' GROUP BY DAY(date_added)");
  144. if ($query->num_rows) {
  145. $data['customer']['data'][] = array(date('d', strtotime('-' . (int)$i . ' day')), (int)$query->row['total']);
  146. } else {
  147. $data['customer']['data'][] = array(date('d', strtotime('-' . (int)$i . ' day')), 0);
  148. }
  149. $data['xaxis'][] = array(date('d', strtotime('-' . (int)$i . ' day')), date('d/m', strtotime('-' . (int)$i . ' day')));
  150. }
  151. break;
  152. case 'year':
  153. for ($i = 0; $i < date('n'); $i++) {
  154. $query = $this->db->query("SELECT COUNT(*) AS total FROM `" . DB_PREFIX . "order` WHERE order_status_id > '0' AND (YEAR(date_added) = '" . date('Y') . "' AND MONTH(date_added) = '" . date('m', strtotime('-' . $i . ' month')) . "') GROUP BY MONTH(date_added)");
  155. if ($query->num_rows) {
  156. $data['order']['data'][] = array(date('n', strtotime('-' . (int)$i . ' month')), (int)$query->row['total']);
  157. } else {
  158. $data['order']['data'][] = array(date('n', strtotime('-' . (int)$i . ' month')), 0);
  159. }
  160. $query = $this->db->query("SELECT COUNT(*) AS total FROM " . DB_PREFIX . "customer WHERE YEAR(date_added) = '" . date('Y') . "' AND MONTH(date_added) = '" . date('m', strtotime('-' . $i . ' month')) . "' GROUP BY MONTH(date_added)");
  161. if ($query->num_rows) {
  162. $data['customer']['data'][] = array(date('n', strtotime('-' . (int)$i . ' month')), (int)$query->row['total']);
  163. } else {
  164. $data['customer']['data'][] = array(date('n', strtotime('-' . (int)$i . ' month')), 0);
  165. }
  166. $data['xaxis'][] = array(date('n', strtotime('-' . (int)$i . ' month')), date('m', strtotime('-' . (int)$i . ' month')));
  167. }
  168. break;
  169. }
  170. $this->load->library('json');
  171. $this->response->setOutput(Json::encode($data));
  172. }
  173. public function login() {
  174. if (!$this->user->isLogged()) {
  175. return $this->forward('common/login');
  176. }
  177. }
  178. public function permission() {
  179. if (isset($this->request->get['route'])) {
  180. $route = $this->request->get['route'];
  181. $part = explode('/', $route);
  182. $ignore = array(
  183. 'common/home',
  184. 'common/login',
  185. 'common/logout',
  186. 'common/filemanager',
  187. 'common/permission',
  188. 'error/error_403',
  189. 'error/error_404'
  190. );
  191. if (!in_array(@$part[0] . '/' . @$part[1], $ignore)) {
  192. if (!$this->user->hasPermission('access', @$part[0] . '/' . @$part[1])) {
  193. return $this->forward('error/permission');
  194. }
  195. }
  196. }
  197. }
  198. }
  199. ?>