Esempio n. 1
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 actionProfile()
 {
     $this->tabs = true;
     $user_id = Yii::app()->user->id;
     $model = $this->loadModel($user_id);
     $model->scenario = 'useredit';
     // Uncomment the following line if AJAX validation is needed
     // $this->performAjaxValidation($model);
     if (isset($_POST['User'])) {
         $model->attributes = $_POST['User'];
         if (isset($_POST['user_image']) && !empty($_POST['user_image'])) {
             $oldimage = $model->u_image != '' ? $model->u_image : NULL;
             $model->u_image = $this->UploadImage($_POST['user_image'], 'user', $oldimage);
         }
         unset($model->u_last_login_date);
         unset($model->u_created);
         if ($model->save()) {
             Yii::app()->user->setFlash('success', 'Profile updated successfully.');
             $this->refresh();
         } else {
             Yii::app()->user->setFlash('error', 'Please verify all the fields.');
         }
     }
     $orderModel = new Cart();
     $orderModel->cart_user_id = $user_id;
     $criteria = new CDbCriteria();
     $criteria->order = 'cnt_name ASC';
     $userAddressModel = new UserAddress();
     $countriesData = Countries::model()->findAll($criteria);
     $countries = CHtml::listData($countriesData, 'cnt_id', 'cnt_name');
     $states1 = array();
     $states2 = array();
     $criteria1 = new CDbCriteria();
     $criteria1->condition = "uad_user_id=:uad_user_id";
     $criteria1->params = array(':uad_user_id' => $user_id);
     $userAddress = UserAddress::model()->findAll();
     $address = array();
     if (!empty($userAddress)) {
         foreach ($userAddress as $key => $arr) {
             $uad_type = $arr->uad_type;
             $address[$uad_type]['uad_id'] = $arr->uad_id;
             $address[$uad_type]['uad_add1'] = $arr->uad_add1;
             $address[$uad_type]['uad_add2'] = $arr->uad_add2;
             $address[$uad_type]['uad_country_id'] = $arr->uad_country_id;
             $address[$uad_type]['uad_state_id'] = $arr->uad_state_id;
             $address[$uad_type]['uad_city'] = $arr->uad_city;
             $address[$uad_type]['uad_zipcode'] = $arr->uad_zipcode;
             $address[$uad_type]['uad_mobile'] = $arr->uad_mobile;
         }
     }
     $criteria = new CDbCriteria();
     $criteria->order = "st_name ASC";
     $criteria->condition = "st_cnt_id=:st_cnt_id";
     if (!empty($address[1]['uad_country_id'])) {
         $criteria->params = array(':st_cnt_id' => $address[1]['uad_country_id']);
         $statesData = States::model()->findAll($criteria);
         $states1 = CHtml::listData($statesData, 'st_id', 'st_name');
     }
     if (!empty($address[2]['uad_country_id'])) {
         $criteria->params = array(':st_cnt_id' => $address[2]['uad_country_id']);
         $statesData = States::model()->findAll($criteria);
         $states2 = CHtml::listData($statesData, 'st_id', 'st_name');
     }
     $criteria1 = new CDbCriteria();
     $criteria1->condition = "umr_user_id=:umr_user_id";
     $criteria1->params = array(':umr_user_id' => $user_id);
     $userMesurementData = UserMeasurements::model()->findAll($criteria1);
     $userMesurements = array();
     if (!empty($userMesurementData)) {
         foreach ($userMesurementData as $umKey => $umArr) {
             $umType = $umArr->umr_type;
             $userMesurements[$umType][] = $umArr;
         }
     }
     $this->render('profile', array('model' => $model, 'orderModel' => $orderModel, 'userAddressModel' => $userAddressModel, 'countries' => $countries, 'states1' => $states1, 'states2' => $states2, 'address' => $address, 'userMesurements' => $userMesurements));
 }
Esempio n. 2
0
 public function actionViewaddress($id)
 {
     $criteria = new CDbCriteria();
     $criteria->order = 'uad_type ASC';
     $criteria->condition = 'uad_user_id=:uad_user_id';
     $criteria->params = array(':uad_user_id' => $id);
     $model = UserAddress::model()->findAll($criteria);
     if ($model === null) {
         throw new CHttpException(404, 'The requested page does not exist.');
     }
     $this->render('viewaddress', array('model' => $model));
 }