/**
  * Returns customer detail if given token exists and is published
  * otherwise return false
  */
 function getCustomerDetailForToken($token)
 {
     if (strlen($token) != 32) {
         return false;
     }
     $token_escaped = pg_escape_string($token);
     $result = $this->listing("token = '{$token_escaped}' AND publish = 1");
     if ($result[0]['customer_id'] > 0) {
         require_once 'models/client/client_customer.php';
         $Customer = new client_customer();
         $Customer->setCacheable(false);
         $customer_detail = $Customer->detail($result[0]['customer_id']);
         return $customer_detail;
     }
     return false;
 }
Exemple #2
0
 /**
  * main action
  */
 public function mainAction()
 {
     require_once 'models/common/common_session.php';
     require_once 'models/common/common_session_archive.php';
     $Session = new common_session();
     $Session_archive = new common_session_archive();
     $Session->setCacheable(false);
     require_once 'models/client/client_customer.php';
     // filter
     if (isset($this->GET['filter'])) {
         $_SESSION['filter'] = $this->GET['filter'];
     }
     $filter = $_SESSION['filter'];
     if ($filter['active'] == 1) {
         $this->tpl->assign('ACTIVE_selected_1', "selected='selected'");
     } else {
         $this->tpl->assign('ACTIVE_selected_0', "selected='selected'");
     }
     if (!is_numeric($filter['customer_id']) || $filter['customer_id'] < 0) {
         $filter['customer_id'] = '';
     }
     $this->tpl->assign("FILTER", $filter);
     $session_ttl = round($Session->conf['ttl'] / 3600, 1);
     $this->tpl->assign('SESSION_TTL', $session_ttl);
     $Customer = new client_customer();
     $Customer->setCacheable(false);
     //pagination
     if (is_numeric($this->GET['limit_from']) && is_numeric($this->GET['limit_per_page'])) {
         $from = $this->GET['limit_from'];
         $per_page = $this->GET['limit_per_page'];
     } else {
         $from = 0;
         $per_page = 5;
     }
     $limit = "{$from},{$per_page}";
     if (is_numeric($filter['customer_id'])) {
         $where = "customer_id = {$filter['customer_id']}";
     } else {
         $where = '';
     }
     $count_active = $Session->count($where);
     $count_archive = $Session_archive->count($where);
     if ($filter['active'] == 1) {
         $sessions = $Session->listing($where, 'modified DESC', $limit);
         $count = $count_active;
     } else {
         $session_active = $Session->listing($where, 'modified DESC', $limit);
         //pagination must be handled differently
         if (count($session_active) < $per_page) {
             //start to show archive, but use different "from"
             $from_archived = $from + count($session_active) - $count_active;
             $session_archive = $Session_archive->listing($where, 'modified DESC', "{$from_archived},{$per_page}");
             $sessions = array_merge($session_active, $session_archive);
         } else {
             $sessions = $session_active;
         }
         $count = $count_active + $count_archive;
     }
     foreach ($sessions as $s) {
         $s['session_data'] = $this->unserialize_session_data($s['session_data']);
         if ($s['http_referer'] == '') {
             $link_block = "referer_na";
         } else {
             $link_block = "referer_link";
         }
         if (!is_array($s['session_data']['history'])) {
             $s['session_data']['history'] = array();
         }
         foreach ($s['session_data']['history'] as $history) {
             //temp
             if (!is_array($history)) {
                 $history = array('time' => 'n/a', 'uri' => $history);
             } else {
                 $history['time'] = strftime('%H:%M', $history['time']);
             }
             $this->tpl->assign('HISTORY', $history);
             $this->tpl->parse('content.item.history');
         }
         $s['time_diff'] = strtotime($s['modified']) - strtotime($s['created']);
         $s['time_diff'] = round($s['time_diff'] / 60);
         $s['created'] = strftime('%d/%m/%Y&nbsp;%H:%M', strtotime($s['created']));
         $s['modified'] = strftime('%d/%m/%Y&nbsp;%H:%M', strtotime($s['modified']));
         if ($s['customer_id'] > 0) {
             $this->tpl->assign('CUSTOMER', $Customer->detail($s['customer_id']));
         } else {
             $this->tpl->assign('CUSTOMER', '');
         }
         // show messages
         if (ONXSHOP_DEBUG_OUTPUT_FILE) {
             $messages_file = ONXSHOP_PROJECT_DIR . "var/log/messages/{$s['ip_address']}-{$s['session_id']}.log";
             if (file_exists($messages_file)) {
                 $s['messages'] = file_get_contents($messages_file);
             }
         }
         $this->tpl->assign('SESSION', $s);
         $this->tpl->parse("content.item.{$link_block}");
         if ($s['messages'] != '') {
             $this->tpl->parse('content.item.session_messages');
         }
         $this->tpl->parse('content.item');
     }
     //pagination
     //$link = "/backoffice/advanced/logs";
     $link = $_SERVER['REDIRECT_URL'];
     $_Onxshop_Request = new Onxshop_Request("component/pagination~limit_from={$from}:limit_per_page={$per_page}:count={$count}:link={$link}:option_show_all=1:option_per_page=1~");
     $this->tpl->assign('PAGINATION', $_Onxshop_Request->getContent());
     return true;
 }
Exemple #3
0
 /**
  * main action
  */
 public function mainAction()
 {
     $customer_id = $_SESSION['client']['customer']['id'];
     if (!is_numeric($customer_id)) {
         msg("Address management requires active customer ID");
         return true;
     }
     /**
      * initialize
      */
     require_once 'models/client/client_customer.php';
     require_once 'models/client/client_address.php';
     require_once 'models/international/international_country.php';
     $Customer = new client_customer();
     $Address = new client_address();
     $Country = new international_country();
     $Customer->setCacheable(false);
     $Address->setCacheable(false);
     /**
      * add address
      */
     if ($_POST['add_address']) {
         $_POST['client']['address']['customer_id'] = $customer_id;
         if ($address_id = $Address->insert($_POST['client']['address'])) {
             msg('New address added to your list.');
         } else {
             msg('Address is not valid', 'error');
         }
     }
     /**
      * select address
      */
     if ($_POST['select_address']) {
         $customer_detail = $Customer->detail($customer_id);
         $customer_detail["{$this->GET['type']}_address_id"] = $_POST['select_address'];
         if ($Customer->update($customer_detail)) {
             $_SESSION['client']['customer'] = $customer_detail;
             onxshopGoTo($_SESSION['referer'], 2);
         } else {
             msg("Cannot select this address", 'error');
         }
     }
     /**
      * remove address
      */
     if (is_numeric($_POST['remove_address'])) {
         $address_id_to_remove = $_POST['remove_address'];
         $address_detail = $Address->detail($address_id_to_remove);
         if ($address_detail['customer_id'] == $customer_id) {
             if ($Address->deleteAddress($address_id_to_remove)) {
                 msg('Address has been removed');
             } else {
                 msg('Cannot remove address', 'error');
             }
         } else {
             msg("This is not your address!", 'error');
         }
     }
     /**
      * address list
      */
     $addresses = $Address->listing("customer_id = {$customer_id} AND is_deleted IS NOT TRUE", "id DESC");
     $current_invoices = $_SESSION['client']['customer']['invoices_address_id'];
     $current_delivery = $_SESSION['client']['customer']['delivery_address_id'];
     foreach ($addresses as $addr) {
         $country_detail = $Country->detail($addr['country_id']);
         $addr['country'] = $country_detail;
         $this->tpl->assign('address', $addr);
         if ($addr['line_2'] != '') {
             $this->tpl->parse('content.address.line_2');
         }
         if ($addr['line_3'] != '') {
             $this->tpl->parse('content.address.line_3');
         }
         if ($this->GET['type'] != '') {
             $this->tpl->parse('content.address.select');
         } else {
             if ($addr['id'] != $current_invoices && $addr['id'] != $current_delivery) {
                 $this->tpl->parse('content.address.delete');
             }
         }
         if ($current_invoices == $addr['id']) {
             $this->tpl->parse('content.address.is_invoices');
         }
         if ($current_delivery == $addr['id']) {
             $this->tpl->parse('content.address.is_delivery');
         }
         $this->tpl->parse('content.address');
     }
     /**
      * country list
      */
     $countries = $Country->listing("", "name ASC");
     if (!isset($_POST['client']['address']['country_id'])) {
         $_POST['client']['address']['country_id'] = $Country->conf['default_id'];
     }
     foreach ($countries as $c) {
         if ($c['publish'] == 1) {
             if ($c['id'] == $_POST['client']['address']['country_id']) {
                 $c['selected'] = "selected='selected'";
             } else {
                 $c['selected'] = '';
             }
             $this->tpl->assign('country', $c);
             $this->tpl->parse('content.country.item');
         }
     }
     $this->tpl->parse('content.country');
     /**
      * assign to template
      */
     $this->tpl->assign('client', $_POST['client']);
     return true;
 }