示例#1
0
 public function myAccountAction()
 {
     $identity = (array) Zend_Auth::getInstance()->getIdentity();
     switch ($identity['role']) {
         case Table_Abstract::ROLE_CENTER:
             $t = new Table_Centers();
             $a = $t->getById($identity['id'])->toArray();
             break;
         case Table_Abstract::ROLE_COMPANY:
             $t = new Table_Companies();
             $a = $t->getById($identity['id'])->toArray();
             break;
         case Table_Abstract::ROLE_STAFF:
             $t = new Table_Users();
             $a = $t->getById($identity['id'])->toArray();
             break;
         case Table_Abstract::ROLE_CLIENT:
             $t = new Table_Users();
             $a = $t->getById($identity['id'])->toArray();
             break;
         case Table_Abstract::ROLE_APPROVER:
             $t = new Table_Approvers();
             $a = $t->getById($identity['id'])->toArray();
             break;
     }
     $this->view->assign('a', $a);
 }
示例#2
0
 public function obMultipleAction()
 {
     $identity = (array) Zend_Auth::getInstance()->getIdentity();
     $params = $this->getRequest()->getParams();
     $this->view->assign('type', $params['type']);
     $center = $this->getCenters()->getById($identity['center_id']);
     $center = !is_null($center) ? $center->toArray() : array();
     $company = $this->getCompanies()->getById($identity['company_id']);
     $company = !is_null($company) ? $company->toArray() : array();
     $toEmailCenter = $center['email'];
     $toEmailCompany = $company['email'];
     // Submited request
     if (isset($params['process_ob'])) {
         $uid = mt_rand(100000, 999999);
         $date_created = date('Y-m-d H:i:s');
         $date_delivery = isset($params['date_delivery']) ? $params['date_delivery'] : date('d/m/Y');
         $date_delivery = convertUKtoUSdate($date_delivery);
         $company_id = $identity['company_id'];
         $center_id = $identity['center_id'];
         $customer_id = $identity['customer_id'];
         $amount = null;
         $uk_amount = $params['total'];
         $created_user_id = $identity['id'];
         $payment_type = $params['payment_type'];
         $traveller_name = $params['traveller_name'];
         $comment = $params['comment'];
         $type = $params['type'];
         $is_multiple = 1;
         $status = $company['with_check'] ? Table_Abstract::STATUS_PENDING : Table_Abstract::STATUS_UNPROCESSED;
         $ob = $this->getOrders()->createRow();
         $ob_id = $ob->setUid($uid)->setDateCreated($date_created)->setDateDelivery($date_delivery)->setCompanyId($company_id)->setCenterId($center_id)->setCustomerId($customer_id)->setAmount($amount)->setUkAmount($uk_amount)->setCreatedUserId($created_user_id)->setPaymentType($payment_type)->setTravellerName($traveller_name)->setComment($comment)->setType($type)->setIsMultiple($is_multiple)->setStatus($status)->save();
         // add to ob multiple
         foreach ($params['rate_id'] as $k => $rate_id) {
             $rate = $params['rate'][$k];
             $amount = $params['amount'][$k];
             $uk_amount = $params['uk_amount'][$k];
             $ob_multiple = $this->getObMultiple()->createRow();
             $ob_multiple->setObId($ob_id)->setRateId($rate_id)->setRate($rate)->setPaymentType($payment_type)->setAmount($amount)->setUkAmount($uk_amount)->save();
         }
         /**
          * Get order by uid
          * @var mixed
          */
         $ob = $this->getOrders()->getByUid($uid);
         $join_in = array(array('customers', 'customer_id'), array('companies', 'company_id'), array('centers', 'center_id'), array('rates', 'rate_id'), array('users', 'created_user_id'), array('users', 'response_user_id'));
         $ob = $this->_buildJoinTbl(array($ob), $join_in);
         $ob = $ob[0];
         $ob['company'] = $company;
         // Ob multiple
         $ob_multiple = array();
         $_ob_multiple = $this->getObMultiple()->geByOrderId($ob['id'])->toArray();
         foreach ($_ob_multiple as $obm) {
             $ob_multiple[$obm['id']] = $obm;
             $ob_multiple[$obm['id']]['rate_detail'] = $this->getRates()->getById($obm['rate_id'])->toArray();
         }
         $ob['multiple'] = $ob_multiple;
         /**
          * Send mail to processing center with order
          * @var NL_HtmlMailer
          */
         $is_error = false;
         $email = new NL_HtmlMailer();
         $email->sendOb($ob, $toEmailCenter);
         /** @var Send mail to approvers $approversTable */
         $approversTable = new Table_Approvers();
         $approvers = $approversTable->getByCompanyId($company['id']);
         foreach ($approvers->toArray() as $approver) {
             if (!is_null($approver['email']) && !empty($approver['email'])) {
                 $email->sendOb($ob, $approver['email']);
             }
         }
         /** send to company if with approve */
         if ($company['with_check']) {
             $email->sendOb($ob, $toEmailCompany);
         }
         // MESSAGE
         if (!$is_error) {
             // Success promotional message
             include APPLICATION_PATH . DIRECTORY_SEPARATOR . 'controllers' . DIRECTORY_SEPARATOR . 'AjaxObController.php';
             $out = AjaxObController::renderSuccessMessage($type, $uid, $payment_type, $is_multiple = true);
         } else {
             // error message
             $out = NL_Render::renderErrorMessage();
         }
         echo $out;
         $this->view->assign('show_view', false);
     } else {
         $this->view->assign('show_view', true);
     }
 }
示例#3
0
 /**
  * Performs an authentication attempt
  *
  * @throws Zend_Auth_Adapter_Exception If authentication cannot be performed
  * @return Zend_Auth_Result
  */
 public function authenticate()
 {
     $code = Zend_Auth_Result::FAILURE_CREDENTIAL_INVALID;
     $errMessage = "Email / Username or password incorrect";
     // Log in by client
     // Log in by client
     // Log in by client
     if ($this->role == 'client') {
         $usersTable = new Table_Users();
         $user = $usersTable->getAuthUsernamePassword($this->username, $this->password);
         if (!is_null($user)) {
             if ($user->getStatus() == Table_Users::STATUS_ACTIVE && $user->getRole() == 'client') {
                 // convert to std-object
                 $oUser = (object) $user->toArray();
                 $result = new Zend_Auth_Result(Zend_Auth_Result::SUCCESS, $oUser, array());
                 return $result;
             }
             if ($user->getStatus() == Table_Users::STATUS_INACTIVE) {
                 $code = Zend_Auth_Result::FAILURE_CREDENTIAL_INVALID;
                 $errMessage = "Your account is currently inactive. Please contact us for detail";
             } elseif ($user->getStatus() == Table_Users::STATUS_DELETED) {
                 $errMessage = "Your account has been deleted. Please contact us for detail";
             }
         }
         // Log in by admin
         // Log in by admin
         // Log in by admin
     } elseif ($this->role == 'staff') {
         $usersTable = new Table_Users();
         $user = $usersTable->getAuthUsernamePassword($this->username, $this->password);
         if (!is_null($user)) {
             if ($user->getStatus() == Table_Users::STATUS_ACTIVE && $user->getRole() == 'staff') {
                 // convert to std-object
                 $oUser = (object) $user->toArray();
                 $result = new Zend_Auth_Result(Zend_Auth_Result::SUCCESS, $oUser, array());
                 return $result;
             }
             if ($user->getStatus() == Table_Users::STATUS_INACTIVE) {
                 $code = Zend_Auth_Result::FAILURE_CREDENTIAL_INVALID;
                 $errMessage = "Your account is currently inactive. Please contact us for detail";
             } elseif ($user->getStatus() == Table_Users::STATUS_DELETED) {
                 $errMessage = "Your account has been deleted. Please contact us for detail";
             }
         }
         // Log in by centers
         // Log in by centers
         // Log in by centers
     } elseif ($this->role == 'center') {
         $centersTable = new Table_Centers();
         $center = $centersTable->getAuthUsernamePassword($this->username, $this->password);
         if (!is_null($center)) {
             if ($center->getStatus() == Table_Users::STATUS_ACTIVE) {
                 // convert to std-object
                 $oUser = (object) $center->toArray();
                 $result = new Zend_Auth_Result(Zend_Auth_Result::SUCCESS, $oUser, array());
                 return $result;
             }
             if ($center->getStatus() == Table_Users::STATUS_INACTIVE) {
                 $code = Zend_Auth_Result::FAILURE_CREDENTIAL_INVALID;
                 $errMessage = "Your account is currently inactive. Please contact us for detail";
             } elseif ($center->getStatus() == Table_Users::STATUS_DELETED) {
                 $errMessage = "Your account has been deleted. Please contact us for detail";
             }
         }
         // Log in by companies
         // Log in by companies
         // Log in by companies
     } elseif ($this->role == 'company') {
         $companiesTable = new Table_Companies();
         $company = $companiesTable->getAuthUsernamePassword($this->username, $this->password);
         if (!is_null($company)) {
             if ($company->getStatus() == Table_Users::STATUS_ACTIVE && $company->getWithCheck() == 1) {
                 // convert to std-object
                 $oUser = (object) $company->toArray();
                 $result = new Zend_Auth_Result(Zend_Auth_Result::SUCCESS, $oUser, array());
                 return $result;
             }
             if ($company->getStatus() == Table_Users::STATUS_INACTIVE) {
                 $code = Zend_Auth_Result::FAILURE_CREDENTIAL_INVALID;
                 $errMessage = "Your account is currently inactive. Please contact us for detail";
             } elseif ($company->getStatus() == Table_Users::STATUS_DELETED) {
                 $errMessage = "Your account has been deleted. Please contact us for detail";
             } elseif ($company->getWithCheck() == 0) {
                 $errMessage = "Your account has been set to no checking orders / buybacks";
             }
         }
         // Log in by approvers
         // Log in by approvers
         // Log in by approvers
     } elseif ($this->role == 'approver') {
         $approversTable = new Table_Approvers();
         $approver = $approversTable->getAuthUsernamePassword($this->username, $this->password);
         if (!is_null($approver)) {
             if ($approver->getStatus() == Table_Users::STATUS_ACTIVE) {
                 // convert to std-object
                 $oUser = (object) $approver->toArray();
                 $result = new Zend_Auth_Result(Zend_Auth_Result::SUCCESS, $oUser, array());
                 return $result;
             }
             if ($approver->getStatus() == Table_Users::STATUS_INACTIVE) {
                 $code = Zend_Auth_Result::FAILURE_CREDENTIAL_INVALID;
                 $errMessage = "Your account is currently inactive. Please contact us for detail";
             } elseif ($approver->getStatus() == Table_Users::STATUS_DELETED) {
                 $errMessage = "Your account has been deleted. Please contact us for detail";
             }
         }
     }
     $result = new Zend_Auth_Result($code, null, array($errMessage));
     return $result;
 }
示例#4
0
 /**
  * The final step in which we save the order
  * and send email to processing center to deal with it
  */
 public function obStep3Action()
 {
     $out = '';
     $params = $this->getRequest()->getParams();
     // Set params
     $identity = (array) Zend_Auth::getInstance()->getIdentity();
     $created_user_id = $identity['id'];
     $type = $params['type'];
     $payment_type = $params['payment_type'];
     $rate_id = $params['rate_id'];
     $amount = $params['amount'];
     $uk_amount = $params['uk_amount'];
     $traveller_name = $params['traveller_name'];
     $comment = $params['comment'];
     $uid = mt_rand(100000, 999999);
     $date_created = date('Y-m-d H:i:s');
     $date_delivery = isset($params['date_delivery']) ? $params['date_delivery'] : date('d/m/Y');
     // format date_delivery
     $date_delivery = convertUKtoUSdate($date_delivery);
     $user = $this->getUsers()->getById($created_user_id);
     $user = !is_null($user) ? $user->toArray() : array();
     if (!empty($user)) {
         $company = $this->getCompanies()->getById($user['company_id']);
         $company = !is_null($company) ? $company->toArray() : array();
     }
     $ordersTable = new Table_Orders();
     $o = $ordersTable->createRow();
     // Save in db
     $o->setUid($uid)->setDateCreated($date_created)->setDateDelivery($date_delivery)->setAmount($amount)->setUkAmount($uk_amount)->setRateId($rate_id)->setCreatedUserId($created_user_id)->setPaymentType($payment_type)->setTravellerName($traveller_name)->setComment($comment)->setCompanyId($user['company_id'])->setCenterId($user['center_id'])->setCustomerId($user['customer_id'])->setType($type);
     if ($company['with_check'] == 1) {
         $o->setStatus(Table_Abstract::STATUS_PENDING);
     }
     // Get email in which to send
     $identity = (array) Zend_Auth::getInstance()->getIdentity();
     $center = $this->getCenters()->getById($identity['center_id']);
     $center = !is_null($center) ? $center->toArray() : array();
     $toEmailCenter = $center['email'];
     $toEmailCompany = $company['email'];
     // If saves the order in db
     $is_error = false;
     if ($o->save()) {
         $user = (array) Zend_Auth::getInstance()->getIdentity();
         $company = $this->getCompanies()->getById($user['company_id']);
         $company = !is_null($company) ? $company->toArray() : array();
         /**
          * Get order by uid
          * @var mixed
          */
         $ob = $this->getOrders()->getByUid($uid);
         $join_in = array(array('customers', 'customer_id'), array('companies', 'company_id'), array('centers', 'center_id'), array('rates', 'rate_id'), array('users', 'created_user_id'), array('users', 'response_user_id'));
         $ob = $this->_buildJoinTbl(array($ob), $join_in);
         $ob = $ob[0];
         $ob['margins'] = $this->getMargins()->getFeeByRateCode($ob['rate']['c_code']);
         $ob['company'] = $company;
         /**
          * Send mail to processing center with order
          * @var NL_HtmlMailer
          */
         $is_error = false;
         $email = new NL_HtmlMailer();
         $email->sendOb($ob, $toEmailCenter);
         /** send to company if with approve */
         if ($company['with_check']) {
             $email->sendOb($ob, $toEmailCompany);
         }
         /** @var Send mail to approvers $approversTable */
         $approversTable = new Table_Approvers();
         $approvers = $approversTable->getByCompanyId($company['id']);
         foreach ($approvers->toArray() as $approver) {
             if (!is_null($approver['email']) && !empty($approver['email'])) {
                 $email->sendOb($ob, $approver['email']);
             }
         }
     } else {
         $is_error = true;
     }
     // MESSAGE
     if (!$is_error) {
         // Success promotional message
         $out = self::renderSuccessMessage($type, $uid, $params['payment_type'], $is_multiple = false);
     } else {
         // error message
         $out = NL_Render::renderErrorMessage();
     }
     echo $out;
 }