Exemple #1
0
 public static function getAll()
 {
     global $lC_Database, $lC_Language, $_module;
     $media = $_GET['media'];
     $result = array('aaData' => array());
     /* Total Records */
     $QresultTotal = $lC_Database->query('SELECT count(customers_id) as total from :table_customers');
     $QresultTotal->bindTable(':table_customers', TABLE_CUSTOMERS);
     $QresultTotal->execute();
     $result['iTotalRecords'] = $QresultTotal->valueInt('total');
     $QresultTotal->freeResult();
     /* Paging */
     $sLimit = " LIMIT 0,25 ";
     if (isset($_GET['iDisplayStart'])) {
         if ($_GET['iDisplayLength'] != -1) {
             $sLimit = " LIMIT " . $_GET['iDisplayStart'] . ", " . $_GET['iDisplayLength'];
         }
     }
     /* Ordering */
     if (isset($_GET['iSortCol_0'])) {
         $sOrder = " ORDER BY ";
         for ($i = 0; $i < (int) $_GET['iSortingCols']; $i++) {
             $sOrder .= lC_Customers_Admin::fnColumnToField($_GET['iSortCol_' . $i]) . " " . $_GET['sSortDir_' . $i] . ", ";
         }
         $sOrder = substr_replace($sOrder, "", -2);
     }
     /* Filtering */
     $sWhere = "";
     if ($_GET['sSearch'] != "") {
         $sWhere = " WHERE c.customers_lastname LIKE '%" . $_GET['sSearch'] . "%' OR " . "c.customers_firstname LIKE '%" . $_GET['sSearch'] . "%' OR " . "c.customers_email_address LIKE '%" . $_GET['sSearch'] . "%' ";
     } else {
         if (isset($_GET['cSearch']) && $_GET['cSearch'] != null) {
             $sWhere = " WHERE c.customers_id = '" . $_GET['cSearch'] . "' ";
         }
     }
     /* Total Filtered Records */
     $QresultFilterTotal = $lC_Database->query("SELECT count(c.customers_id) as total, c.customers_id, c.customers_group_id, c.customers_gender, c.customers_lastname, c.customers_firstname, c.customers_email_address, c.customers_status, c.customers_ip_address, c.date_account_created, c.date_account_last_modified, c.date_last_logon, c.number_of_logons, a.entry_country_id\n                                                 from :table_customers c\n                                               LEFT JOIN :table_address_book a\n                                                 on (c.customers_id = a.customers_id and c.customers_default_address_id = a.address_book_id) " . $sWhere . $sOrder);
     $QresultFilterTotal->bindTable(':table_customers', TABLE_CUSTOMERS);
     $QresultFilterTotal->bindTable(':table_address_book', TABLE_ADDRESS_BOOK);
     $QresultFilterTotal->execute();
     $result['iTotalDisplayRecords'] = $QresultFilterTotal->valueInt('total');
     $QresultFilterTotal->freeResult();
     /* Main Listing Query */
     $Qcustomers = $lC_Database->query("SELECT c.customers_id, c.customers_group_id, c.customers_gender, c.customers_lastname, c.customers_firstname, c.customers_email_address, c.customers_status, c.customers_ip_address, c.date_account_created, c.date_account_last_modified, c.date_last_logon, c.number_of_logons, c.customers_default_address_id, a.entry_country_id\n                                         from :table_customers c\n                                       LEFT JOIN :table_address_book a\n                                         on (c.customers_id = a.customers_id and c.customers_default_address_id = a.address_book_id) " . $sWhere . $sOrder . $sLimit);
     $Qcustomers->bindTable(':table_customers', TABLE_CUSTOMERS);
     $Qcustomers->bindTable(':table_address_book', TABLE_ADDRESS_BOOK);
     $Qcustomers->execute();
     $cnt = 1;
     $tagArr = array();
     while ($Qcustomers->next()) {
         $customer_icon = lc_icon_admin('people.png', 'cID[' . $Qcustomers->value('customers_id') . ']');
         //$customer_icon = '<span class="icon-user title="cID[' . $Qcustomers->value('customers_id') . ']"></span>';
         if (ACCOUNT_GENDER > -1) {
             switch ($Qcustomers->value('customers_gender')) {
                 case 'm':
                     $customer_icon = '<span style="cursor:pointer;" class="with-tooltip" title="cID[' . $Qcustomers->value('customers_id') . '] ' . $lC_Language->get('gender_male') . '">' . lc_icon_admin('male.png') . '</span>';
                     //$customer_icon = '<span class="icon-user icon-blue" title="cID[' . $Qcustomers->value('customers_id') . '] ' . $lC_Language->get('gender_male') . '"></span>';
                     break;
                 case 'f':
                     $customer_icon = '<span style="cursor:pointer;" class="with-tooltip" title="cID[' . $Qcustomers->value('customers_id') . '] ' . $lC_Language->get('gender_female') . '">' . lc_icon_admin('female.png') . '</span>';
                     //$customer_icon = '<span class="icon-user icon-red" title="cID[' . $Qcustomers->value('customers_id') . '] ' . $lC_Language->get('gender_female') . '"></span>';
                     break;
                 default:
                     //$customer_icon = lc_icon_admin('female.png', 'cID[' . $Qcustomers->value('customers_id') . '] ' . $lC_Language->get('gender_female'));
                     $customer_icon = '<span style="cursor:pointer;" class="icon-user icon-anthracite with-tooltip" title="cID[' . $Qcustomers->value('customers_id') . ']"></span>';
             }
         }
         if (!key_exists($Qcustomers->valueInt('customers_group_id'), $tagArr)) {
             $tagArr[$Qcustomers->valueInt('customers_group_id')] = self::nextColor($tagArr);
         }
         $tagColor = $tagArr[$Qcustomers->valueInt('customers_group_id')];
         $full = $Qcustomers->valueProtected('customers_firstname') . ' ' . $Qcustomers->valueProtected('customers_lastname');
         $check = '<td><input class="batch" type="checkbox" name="batch[]" value="' . $Qcustomers->valueInt('customers_id') . '" id="' . $Qcustomers->valueInt('customers_id') . '"></td>';
         $gender = '<td>' . $customer_icon . '</td>';
         $name = '<td>' . $Qcustomers->valueProtected('customers_firstname') . ' ' . $Qcustomers->valueProtected('customers_lastname') . '</td>';
         $Qcustomers_orders = $lC_Database->query("SELECT count(*) as order_count \n                                         from :table_orders \n                                         where customers_id = '" . $Qcustomers->valueInt('customers_id') . "'");
         $Qcustomers_orders->bindTable(':table_orders', TABLE_ORDERS);
         $Qcustomers_orders->execute();
         $order_count = '<td>' . $Qcustomers_orders->valueInt('order_count') . '</td>';
         $email = '<td>' . $Qcustomers->value('customers_email_address') . '</td>';
         $group = '<td><small class="tag ' . $tagColor . ' glossy">' . lc_get_customer_groups_name($Qcustomers->valueInt('customers_group_id')) . '</small></td>';
         $date = '<td>' . lC_DateTime::getShort($Qcustomers->value('date_account_created')) . '</td>';
         $action = '<td class="align-right vertical-center">
                <span class="button-group">
                  <a href="' . ((int) ($_SESSION['admin']['access'][$_module] < 3) ? '#' : 'javascript://" onclick="editCustomer(\'' . $Qcustomers->valueInt('customers_id') . '\')') . '" class="button icon-pencil' . ((int) ($_SESSION['admin']['access'][$_module] < 3) ? ' disabled' : NULL) . '">' . ($media === 'mobile-portrait' || $media === 'mobile-landscape' ? NULL : $lC_Language->get('icon_edit')) . '</a>
                  <a href="' . ((int) ($_SESSION['admin']['access'][$_module] < 3) ? '#' : 'javascript://" onclick="createOrder(\'' . $Qcustomers->valueInt('customers_id') . '\',\'' . $Qcustomers->valueInt('customers_default_address_id') . '\')') . '" class="button icon-plus-round with-tooltip' . ((int) ($_SESSION['admin']['access'][$_module] < 3) ? ' disabled' : NULL) . '" title="' . $lC_Language->get('icon_create_order') . '"></a>
                  <a href="javascript:void(0);" class="button icon-monitor with-tooltip' . ((int) ($_SESSION['admin']['access'][$_module] < 4) ? ' disabled' : NULL) . '" title="' . $lC_Language->get('icon_login_as_customer') . ' (PRO)"></a>
                </span>
                <span class="button-group">
                  <a href="' . ((int) ($_SESSION['admin']['access'][$_module] < 4) ? '#' : lc_href_link_admin(FILENAME_DEFAULT, 'orders&cID=' . $Qcustomers->valueInt('customers_id'))) . '" class="button icon-price-tag with-tooltip' . ((int) ($_SESSION['admin']['access'][$_module] < 4) ? ' disabled' : NULL) . '" title="' . $lC_Language->get('icon_view_orders') . '"></a>
                </span>
              </td>';
         $result['aaData'][] = array("{$check}", "{$gender}", "{$name}", "{$email}", "{$order_count}", "{$group}", "{$date}", "{$action}");
         $cnt++;
     }
     $result['sEcho'] = intval($_GET['sEcho']);
     $Qcustomers->freeResult();
     return $result;
 }