public function actionIndex()
 {
     $messages = "";
     $error_type = "";
     $success = "";
     $name = "";
     $email = "";
     $description = "";
     $error = false;
     if (Yii::app()->getRequest()->ispostRequest) {
         $name = Yii::app()->request->getParam('name');
         $email = Yii::app()->request->getParam('email');
         $description = Yii::app()->request->getParam('description');
         if (empty($name)) {
             $error = true;
             $error_type = 'name';
             $messages = "Vui lòng nhập họ tên!";
         } elseif (!EmailHelper::isEmailAddress($email)) {
             $error = true;
             $error_type = 'email';
             $messages = "Email không hợp lệ!";
         } elseif (empty($description)) {
             $error = true;
             $error_type = 'description';
             $messages = "Vui lòng nhập thông tin liên hệ !";
         } else {
             $contact = new ContactModel();
             $contact->name = $name;
             $contact->content = $description;
             $contact->email = $email;
             $contact->project_des = !empty(Yii::app()->session['project_des']) ? Yii::app()->session['project_des'] : '';
             $contact->project_name = !empty(Yii::app()->session['project_name']) ? Yii::app()->session['project_name'] : '';
             $contact->project_pirce = !empty(Yii::app()->session['project_price']) ? Yii::app()->session['project_price'] : '';
             $contact->project_type = !empty(Yii::app()->session['project_type']) ? Yii::app()->session['project_type'] : '';
             $contact->project_time = !empty(Yii::app()->session['project_time']) ? Yii::app()->session['project_time'] : '';
             $contact->created_time = date('Y-m-d H:i:s');
             $contact->save();
             $success = true;
             $messages = "Quý khách đã gửi liên hệ thành công, chúng tôi sẽ liên hệ lại trong thời gian sớm nhất!";
         }
     }
     $this->render('index', compact('error', 'messages', 'error_type', 'name', 'email', 'description', 'success'));
 }
 public function actionView()
 {
     $is_3g = $this->is3g;
     if (Yii::app()->user->isGuest) {
         $this->redirect($this->createUrl("/account/login"));
         return;
     }
     $error = $error2 = $error_success = "";
     //$user_id = Yii::app()->user->id;
     $phone = yii::app()->user->getState('msisdn');
     $user = UserModel::model()->findByAttributes(array('phone' => $phone));
     $user_id = $user->id;
     $cri = new CDbCriteria();
     $cri->condition = " user_phone = {$phone} AND status=1";
     $user_sub = WapUserSubscribeModel::model()->find($cri);
     $user_extra = UserExtraModel::model()->findbyPK($user->id);
     $forcus = "";
     if (Yii::app()->request->isPostRequest) {
         if (isset($_POST['Profile'])) {
             $error = '';
             $forcus = '';
             $error_code = 0;
             if (empty($_POST['Profile']['username'])) {
                 $error = Yii::t("wap", "Họ tên không được để trống");
                 $forcus = "username";
                 $error_code = 1;
             }
             $playlist_name = ucwords($_POST['Profile']['username']);
             if (preg_match('/[\'\\/~`\\!@#\\$%\\^&\\*\\(\\)_\\-\\+=\\{\\}\\[\\]\\|;:"\\<\\>,\\.\\?\\\\]/', $playlist_name)) {
                 $error = Yii::t("wap", "Họ tên không được chứa ký tự đặc biệt");
                 $forcus = "username";
                 $error_code = 1;
             }
             if (!empty($_POST['Profile']['email']) && !EmailHelper::isEmailAddress($_POST['Profile']['email'])) {
                 $error = Yii::t("wap", "Email incorrect");
                 $forcus = "email";
                 $error_code = 1;
             }
             $birthday = implode('-', array_reverse(explode('/', $_POST['Profile_birthday'])));
             $date = DateTime::createFromFormat("Y-m-d", $birthday);
             if (!$date && !empty($_POST['Profile_birthday'])) {
                 $error = Yii::t("wap", "Date of birth incorrect!");
                 $forcus = "birthday";
                 $error_code = 1;
             }
             if ($error_code == 0) {
                 if (empty($user)) {
                     $password = Common::randomPassword(6);
                     $user = new UserModel();
                     $user->username = $_POST['Profile']['username'];
                     $user->password = $password["encoderPass"];
                     $user->fullname = Yii::app()->user->getState('msisdn');
                     $user->phone = Yii::app()->user->getState('msisdn');
                     $user->gender = 0;
                     $user->status = UserModel::ACTIVE;
                     $user->validate_phone = 1;
                     $user->created_time = date('Y-m-d H:i:s');
                     $user->updated_time = date('Y-m-d H:i:s');
                     $user->email = $_POST['Profile']['email'];
                     $user->address = $_POST['Profile']['address'];
                     $user->gender = (int) $_POST['Profile']['genre'];
                     $ret = $user->save();
                 } else {
                     $user->username = $_POST['Profile']['username'];
                     $user->email = $_POST['Profile']['email'];
                     $user->address = $_POST['Profile']['address'];
                     $user->gender = (int) $_POST['Profile']['genre'];
                     $ret = $user->save();
                 }
                 if ($ret) {
                     if (!empty($user_extra)) {
                         $user_extra->birthday = !empty($birthday) ? $birthday : new CDbExpression('NULL');
                         $user_extra->save();
                     } else {
                         $user_extra = new UserExtraModel();
                         $user_extra->user_id = $user_id;
                         $user_extra->birthday = !empty($birthday) ? $birthday : new CDbExpression('NULL');
                         $user_extra->save();
                     }
                     $error_success = "Cập nhật thành công";
                 } else {
                     $error = Yii::t("wap", "An error occurred. Please try again later.");
                 }
             }
         }
         if (isset($_POST['Profile2'])) {
             $post = $_POST['Profile2'];
             if (empty($post['password'])) {
                 $error2 = Yii::t("wap", "Please input old password");
                 $forcus = "password";
             } elseif ($user['password'] == Common::endcoderPassword($post['password'])) {
                 if (empty($post['password_new'])) {
                     $error2 = Yii::t("wap", "Please input new password");
                 } elseif ($post['password_new'] == $post['password_new_retype']) {
                     $lengPassword = strlen($post['password_new']);
                     if ($lengPassword < 6) {
                         $error2 = Yii::t("wap", "Password required more than 6 characters!");
                         $forcus = "password";
                     } else {
                         $user->password = Common::endcoderPassword($post['password_new']);
                         $ret = $user->save();
                         if ($ret) {
                             Yii::app()->user->setFlash('change_pass_status', Yii::t("wap", "Your password was successfully changed"));
                             $this->redirect($this->createUrl("/account/view"));
                         } else {
                             $error2 = Yii::t("wap", "An error occurred. Please try again later.");
                         }
                     }
                 } else {
                     $error2 = Yii::t("wap", "Repassword not match");
                     $forcus = "password_new_retype";
                 }
             } else {
                 $error2 = Yii::t("wap", "Old password not match");
                 $forcus = "password_new";
             }
         }
     }
     $this->render('view', compact('user', 'user_sub', 'user_extra', 'error', 'error2', 'forcus', 'error_success', 'is_3g'));
 }