shop.balmet.com

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README

customer_approval.php (4131B)


      1 <?php
      2 class ModelCustomerCustomerApproval extends Model {
      3 	public function getCustomerApprovals($data = array()) {
      4 		$sql = "SELECT *, CONCAT(c.`firstname`, ' ', c.`lastname`) AS name, cgd.`name` AS customer_group, ca.`type` FROM `" . DB_PREFIX . "customer_approval` ca LEFT JOIN `" . DB_PREFIX . "customer` c ON (ca.`customer_id` = c.`customer_id`) LEFT JOIN `" . DB_PREFIX . "customer_group_description` cgd ON (c.`customer_group_id` = cgd.`customer_group_id`) WHERE cgd.`language_id` = '" . (int)$this->config->get('config_language_id') . "'";
      5 
      6 		if (!empty($data['filter_name'])) {
      7 			$sql .= " AND CONCAT(c.`firstname`, ' ', c.`lastname`) LIKE '%" . $this->db->escape($data['filter_name']) . "%'";
      8 		}
      9 
     10 		if (!empty($data['filter_email'])) {
     11 			$sql .= " AND c.`email` LIKE '" . $this->db->escape($data['filter_email']) . "%'";
     12 		}
     13 		
     14 		if (!empty($data['filter_customer_group_id'])) {
     15 			$sql .= " AND c.`customer_group_id` = '" . (int)$data['filter_customer_group_id'] . "'";
     16 		}
     17 		
     18 		if (!empty($data['filter_type'])) {
     19 			$sql .= " AND ca.`type` = '" . $this->db->escape($data['filter_type']) . "'";
     20 		}
     21 		
     22 		if (!empty($data['filter_date_added'])) {
     23 			$sql .= " AND DATE(c.`date_added`) = DATE('" . $this->db->escape($data['filter_date_added']) . "')";
     24 		}
     25 
     26 		$sql .= " ORDER BY c.`date_added` DESC";
     27 
     28 		if (isset($data['start']) || isset($data['limit'])) {
     29 			if ($data['start'] < 0) {
     30 				$data['start'] = 0;
     31 			}
     32 
     33 			if ($data['limit'] < 1) {
     34 				$data['limit'] = 20;
     35 			}
     36 
     37 			$sql .= " LIMIT " . (int)$data['start'] . "," . (int)$data['limit'];
     38 		}
     39 
     40 		$query = $this->db->query($sql);
     41 
     42 		return $query->rows;
     43 	}
     44 	
     45 	public function getCustomerApproval($customer_approval_id) {
     46 		$query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "customer_approval` WHERE `customer_approval_id` = '" . (int)$customer_approval_id . "'");
     47 		
     48 		return $query->row;
     49 	}
     50 	
     51 	public function getTotalCustomerApprovals($data = array()) {
     52 		$sql = "SELECT COUNT(*) AS total FROM `" . DB_PREFIX . "customer_approval` ca LEFT JOIN `" . DB_PREFIX . "customer` c ON (ca.`customer_id` = c.`customer_id`)";
     53 
     54 		$implode = array();
     55 
     56 		if (!empty($data['filter_name'])) {
     57 			$implode[] = "CONCAT(c.`firstname`, ' ', c.`lastname`) LIKE '%" . $this->db->escape($data['filter_name']) . "%'";
     58 		}
     59 
     60 		if (!empty($data['filter_email'])) {
     61 			$implode[] = "c.`email` LIKE '" . $this->db->escape($data['filter_email']) . "%'";
     62 		}
     63 
     64 		if (!empty($data['filter_customer_group_id'])) {
     65 			$implode[] = "c.`customer_group_id` = '" . (int)$data['filter_customer_group_id'] . "'";
     66 		}
     67 		
     68 		if (!empty($data['filter_type'])) {
     69 			$implode[] = "ca.`type` = '" . $this->db->escape($data['filter_type']) . "'";
     70 		}
     71 		
     72 		if (!empty($data['filter_date_added'])) {
     73 			$implode[] = "DATE(ca.`date_added`) = DATE('" . $this->db->escape($data['filter_date_added']) . "')";
     74 		}
     75 
     76 		if ($implode) {
     77 			$sql .= " WHERE " . implode(" AND ", $implode);
     78 		}
     79 
     80 		$query = $this->db->query($sql);
     81 
     82 		return $query->row['total'];
     83 	}
     84 	
     85 	public function approveCustomer($customer_id) {
     86 		$this->db->query("UPDATE `" . DB_PREFIX . "customer` SET status = '1' WHERE customer_id = '" . (int)$customer_id . "'");
     87 		$this->db->query("DELETE FROM `" . DB_PREFIX . "customer_approval` WHERE customer_id = '" . (int)$customer_id . "' AND `type` = 'customer'");
     88 	}
     89 
     90 	public function denyCustomer($customer_id) {
     91 		$this->db->query("DELETE FROM `" . DB_PREFIX . "customer_approval` WHERE customer_id = '" . (int)$customer_id . "' AND `type` = 'customer'");
     92 	}
     93 
     94 	public function approveAffiliate($customer_id) {
     95 		$this->db->query("UPDATE `" . DB_PREFIX . "customer_affiliate` SET status = '1' WHERE customer_id = '" . (int)$customer_id . "'");
     96 		$this->db->query("DELETE FROM `" . DB_PREFIX . "customer_approval` WHERE customer_id = '" . (int)$customer_id . "' AND `type` = 'affiliate'");
     97 	}
     98 	
     99 	public function denyAffiliate($customer_id) {
    100 		$this->db->query("DELETE FROM `" . DB_PREFIX . "customer_approval` WHERE customer_id = '" . (int)$customer_id . "' AND `type` = 'affiliate'");
    101 	}	
    102 }