/**
  * Displays the register page
  */
 public function actionRegister()
 {
     $model = new User();
     $vars = array();
     if (isset($_POST['User'])) {
         $model->attributes = $_POST['User'];
         $model->scenario = 'register';
         if ($model->save()) {
             $Customer = new Customer();
             $Customer->attributes = $_POST['Customer'];
             $Customer->save();
             if (!$Customer->Location->is_pickup) {
                 $CustLoc = new UserLocation();
                 $CustLoc->user_id = $Customer->user_id;
                 $CustLoc->location_id = $Customer->location_id;
                 $CustLoc->address = $model->user_address;
                 $CustLoc->address2 = $model->user_address2;
                 $CustLoc->suburb = $model->user_suburb;
                 $CustLoc->state = $model->user_state;
                 $CustLoc->postcode = $model->user_postcode;
                 $CustLoc->phone = !empty($model->user_phone) ? $model->user_phone : $model->user_mobile;
                 $CustLoc->save(false);
             }
             $model->user_id = $Customer->user_id;
             $model->update(array('user_id'));
             $Auth = Yii::app()->authManager;
             $Auth->assign('customer', $model->id);
             //Send email
             $adminEmail = SnapUtil::config('boxomatic/adminEmail');
             $adminEmailFromName = SnapUtil::config('boxomatic/adminEmailFromName');
             $message = new YiiMailMessage('Welcome to ' . Yii::app()->name);
             $message->view = 'welcome';
             $message->setBody(array('User' => $model, 'newPassword' => $_POST['User']['password']), 'text/html');
             $message->addTo($adminEmail);
             $message->addTo($model->email);
             $message->setFrom(array($adminEmail => $adminEmailFromName));
             if (!@Yii::app()->mail->send($message)) {
                 $mailError = true;
             }
             $identity = new UserIdentity($model->email, $_POST['User']['password']);
             $identity->authenticate();
             Yii::app()->user->login($identity);
             User::model()->updateByPk($identity->id, array('last_login_time' => new CDbExpression('NOW()')));
             $this->redirect(array('customer/welcome'));
         }
     }
     $model->password = '';
     $model->password_repeat = '';
     $vars['model'] = $model;
     // $this->render('register',array('model'=>$model));
     $this->render('register', $vars);
 }
 /**
  * Returns the data model based on the primary key given in the GET variable.
  * If the data model is not found, an HTTP exception will be raised.
  * @param integer the ID of the model to be loaded
  */
 public function loadModel($id)
 {
     $model = UserLocation::model()->findByPk($id);
     if ($model === null) {
         throw new CHttpException(404, 'The requested page does not exist.');
     }
     return $model;
 }
示例#3
0
 public function createDefault($id = 0)
 {
     // creates default UserLocation entry for a user if not exists
     $x = UserLocation::model()->findByAttributes(array('user_id' => $id));
     if ($x === null) {
         $ul = new UserLocation();
         $ul->neighborhood_id = 0;
         // default
         $ul->user_id = $id;
         $ul->gps = new CDbExpression("GeomFromText('Point(0 0)')");
         // default
         $ul->address = '';
         $ul->address_ext = '';
         $ul->save();
     }
 }
示例#4
0
 /**
  * Updates a particular model.
  * If update is successful, the browser will be redirected to the 'view' page.
  * @param integer $id the ID of the model to be updated
  */
 public function actionUpdate($id)
 {
     $Customer = $this->loadModel($id);
     if ($Customer->id !== Yii::app()->user->id) {
         throw new CHttpException(403, 'You are not authorized to perform this action.');
     }
     if (isset($_POST['role']) && $_POST['role'] == 'customer') {
         $UserLoc = new UserLocation();
         $UserLoc->user_id = $Customer->user_id;
         $UserLoc->location_id = $Customer->location_id;
         $UserLoc->address = $Customer->user_address;
         $UserLoc->address2 = $Customer->user_address2;
         $UserLoc->suburb = $Customer->user_suburb;
         $UserLoc->state = $Customer->user_state;
         $UserLoc->postcode = $Customer->user_postcode;
         $UserLoc->phone = !empty($Customer->user_phone) ? $Customer->user_phone : $Customer->user_mobile;
         $UserLoc->save();
         $Customer->user_id = $Customer->user_id;
         $Customer->update(array('user_id'));
     }
     $allSaved = true;
     if (isset($_POST['Supplier'])) {
         $Supplier = $Customer->Supplier;
         $Supplier->attributes = $_POST['Supplier'];
         if (!$Supplier->update()) {
             $allSaved = false;
         }
     }
     if (isset($_POST['role'])) {
         $Customer->setRole($_POST['role']);
     }
     if (isset($_POST['BoxomaticUser'])) {
         $oldLocation = $Customer->location_id;
         $oldDeliveryDay = $Customer->delivery_day;
         $Customer->attributes = $_POST['BoxomaticUser'];
         $locationId = $_POST['BoxomaticUser']['delivery_location_key'];
         $custLocationId = new CDbExpression('NULL');
         if (strpos($locationId, '-')) {
             //has a customer location
             $parts = explode('-', $locationId);
             $locationId = $parts[1];
             $custLocationId = $parts[0];
         }
         $Customer->location_id = $locationId;
         $Customer->user_location_id = $custLocationId;
         $Customer->validate();
         if (!$Customer->update()) {
             $allSaved = false;
         }
         //Update the cart to prevent ordering on an unavailable day
         $BoxoCart = new BoxoCart();
         $BoxoCart->delivery_day = $Customer->delivery_day;
         $BoxoCart->setLocation_id($Customer->location_id);
         $BoxoCart->setDelivery_date_id($BoxoCart->getNextDeliveryDate()->id);
         //The frontend system currently doesn't handle ordering from multiple locations
         //so delete all orders if changing location
         if ($Customer->location_id != $oldLocation || $Customer->delivery_day != $oldDeliveryDay) {
             $deleted = false;
             foreach ($Customer->getFutureOrders() as $Order) {
                 $Order->delete();
                 $deleted = true;
             }
             $BoxoCart->emptyCart();
             if ($deleted) {
                 Yii::app()->user->setFlash('warning', 'All future orders removed.');
             }
         }
         if ($allSaved) {
             $this->redirect(array('user/update', 'id' => $Customer->id));
         }
     }
     $custLocDataProvider = null;
     $custLocDataProvider = new CActiveDataProvider('UserLocation', array('criteria' => array('condition' => 'user_id=' . $Customer->id)));
     $this->render('update', array('model' => $Customer, 'custLocDataProvider' => $custLocDataProvider));
 }
示例#5
0
 /**
  * Updates a particular model.
  * If update is successful, the browser will be redirected to the 'view' page.
  * @param integer $id the ID of the model to be updated
  */
 public function actionUpdate($id)
 {
     $model = $this->loadModel($id);
     // Uncomment the following line if AJAX validation is needed
     // $this->performAjaxValidation($model);
     if (isset($_POST['role']) && $_POST['role'] == 'customer') {
         if (empty($model->user_id)) {
             $Customer = new Customer();
         } else {
             $Customer = Customer::model()->findByPk($model->user_id);
         }
         $Customer->save(false);
         $CustLoc = new UserLocation();
         $CustLoc->user_id = $Customer->user_id;
         $CustLoc->location_id = $Customer->location_id;
         $CustLoc->address = $model->user_address;
         $CustLoc->address2 = $model->user_address2;
         $CustLoc->suburb = $model->user_suburb;
         $CustLoc->state = $model->user_state;
         $CustLoc->postcode = $model->user_postcode;
         $CustLoc->phone = !empty($model->user_phone) ? $model->user_phone : $model->user_mobile;
         $CustLoc->save();
         $model->user_id = $Customer->user_id;
         $model->update(array('user_id'));
     }
     $allSaved = true;
     /*
     		if(isset($_POST['Customer']))
     		{
     			$Customer=$model->Customer;
     			$locationId=$_POST['Customer']['delivery_location_key'];
     			$custLocationId=new CDbExpression('NULL');
     			if(strpos($locationId,'-'))
     			{ //has a customer location
     				$parts=explode('-',$locationId);
     				$locationId=$parts[1];
     				$custLocationId=$parts[0];
     			}
     
     			$Customer->location_id=$locationId;
     			$Customer->customer_location_id=$custLocationId;
     			$Customer->save();
     			
     			$Customer->attributes=$_POST['Customer'];
     			if(!$Customer->update())
     				$allSaved=false;
     				
     			$Customer->updateOrderDeliveryLocations();
     		}
     */
     if (isset($_POST['Supplier'])) {
         $Supplier = $model->Supplier;
         $Supplier->attributes = $_POST['Supplier'];
         if (!$Supplier->update()) {
             $allSaved = false;
         }
     }
     if (isset($_POST['role'])) {
         $model->setRole($_POST['role']);
     }
     if (isset($_POST['BoxomaticUser'])) {
         $model->attributes = $_POST['BoxomaticUser'];
         $model->validate();
         if (!$model->update()) {
             $allSaved = false;
         }
         if ($allSaved) {
             $this->redirect(array('customers'));
         }
     }
     $custLocDataProvider = null;
     $custLocDataProvider = new CActiveDataProvider('UserLocation', array('criteria' => array('condition' => 'user_id=' . $model->id)));
     $this->render('update', array('model' => $model, 'custLocDataProvider' => $custLocDataProvider));
 }
示例#6
0
 /**
  * @name UserLocation
  * @author zhys9
  * @desc ûڵתעcharset UTF-8
  * @require class.UserLocation.php
  * @param int/string $param /		½ṹ: 㶫ʡ||
  * @return string/int δintʱضӦĵ֮ص
  * <code>
  * $t = User::UserLocation("㶫ʡ||");
  * $s = User::UserLocation($t);
  * echo $t;
  * print_r($s);
  * </cdoe>
  *
  */
 public static function UserLocation($param)
 {
     if (is_numeric($param)) {
         return UserLocation::CodeToName($param);
     } else {
         $param = explode('|', $param);
         return UserLocation::NameToCode($param[0], $param[1], $param[2]);
     }
 }
示例#7
0
 public function loadModelByUser($id)
 {
     $model = UserLocation::model()->findByAttributes(array('user_id' => $id));
     if ($model === null) {
         throw new CHttpException(404, 'The requested page does not exist.');
     }
     return $model;
 }