Example #1
0
 public function actionReply($userId)
 {
     Yii::beginProfile('messageReply');
     $pmbMessage = new PmbMessages();
     $user = UserApi::getUser($userId);
     if (!$user) {
         throw new CHttpException(404, 'The requested page does not exist.');
     }
     $pmbMessage->to_user_id = $userId;
     $pmbMessage->from_user_id = Yii::app()->user->id;
     $userName = UserApi::getNameByUserId($userId);
     if (isset($_POST['submit'])) {
         $pmbMessage->attributes = $_POST['PmbMessages'];
         if ($pmbMessage->save()) {
             $data = array();
             $user = UserApi::getUserById($pmbMessage->to_user_id);
             $user ? $data["user"] = $user->id : null;
             $data["message"] = $pmbMessage->id;
             EmailApi::sendEmail($user->email_id, "ACTIVITY.MESSAGE.NEW", $data);
             $this->redirect('/messages/sent');
         }
     }
     $this->render('reply', array('pmbMessage' => $pmbMessage, 'user' => $user, 'userName' => $userName));
     Yii::endProfile('messageReply');
 }
Example #2
0
 /**
  * Creates a new model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  */
 public function actionCreate()
 {
     $credentialsModel = new UserCredentials('register');
     $profilesModel = new UserProfiles();
     // Uncomment the following line if AJAX validation is needed
     // $this->performAjaxValidation($model);
     if (isset($_POST['UserCredentials']) && isset($_POST['UserProfiles'])) {
         $data = $_POST;
         $credentialsModel->attributes = $_POST['UserCredentials'];
         $profilesModel->attributes = $_POST['UserProfiles'];
         $data['UserCredentials']['verified_by'] = Yii::app()->user->id;
         $id = UserApi::createUser($credentialsModel, $profilesModel);
         if ($id) {
             $data["temp_password"] = $credentialsModel->password;
             EmailApi::sendEmail($credentialsModel->email_id, "REGISTRATION.SUCCESS", $data);
             $this->redirect(array('view', 'id' => $id['credential']->id));
         } else {
             $credentialsModel->attributes = $data['UserCredentials'];
             $credentialsModel->validate(array('email_id', 'password', 'password2', 'status'));
             $profilesModel->attributes = $data['UserProfiles'];
             $profilesModel->validate(array('first_name', 'last_name'));
         }
     }
     $this->render('create', array('credentialsModel' => $credentialsModel, 'profilesModel' => $profilesModel));
 }
Example #3
0
 static function getSmtp()
 {
     if (!self::$_smtp) {
         require_once 'Mail.php';
         require_once 'Mail/mime.php';
         $host = Yii::app()->params["smtpHostName"];
         $username = Yii::app()->params["smtpUserName"];
         $password = Yii::app()->params["smtpPassword"];
         self::$_smtp = Mail::factory('smtp', array('host' => $host, 'auth' => true, 'username' => $username, 'password' => $password, 'persist' => true));
     }
     return self::$_smtp;
 }
Example #4
0
 public function actionindex()
 {
     $model = new Feedback();
     if (isset($_POST['Feedback'])) {
         $model->attributes = $_POST['Feedback'];
         if ($model->validate()) {
             $imagePath = ImageUtils::uploadImage($model, 'image');
             if ($imagePath) {
                 $model->image = FeedbackImagesApi::addImage($imagePath);
             }
             if ($model->save()) {
                 EmailApi::sendEmail($model->email_id, "FEEDBACK.SUCCESS");
                 $this->redirect('/feedback/thanks');
             }
         }
     }
     $feedbackTopics = new FeedbackTopic();
     $this->renderPartial('index', array('model' => $model, 'feedbackTopics' => $feedbackTopics));
 }
Example #5
0
 public function actionSend($frequency = 55)
 {
     $endTime = time() + $frequency;
     // Check if a previous job has been running for the past 10 minutes.
     if (!DaemonUtils::checkForSync('EMAIL')) {
         DaemonUtils::closeJobForSync('EMAIL');
         die;
     }
     $job = DaemonUtils::addJob('EMAIL');
     try {
         $count = 0;
         while (($emails = EmailQueue::model()->findAll('sent=:sent', array(':sent' => '0'))) && !empty($emails) && time() < $endTime) {
             foreach ($emails as $email) {
                 if (time() < $endTime) {
                     if (!$email->sent) {
                         $result = EmailApi::sendSmtpEmail($email);
                         if ($result == 1) {
                             $email->sent = 1;
                         } else {
                             $email->attempts++;
                         }
                         $email->save();
                         $count++;
                     }
                 } else {
                     break;
                 }
             }
         }
         /*while(!empty($emails) && time()<$endTime){
         			$result = EmailApi::sendSmtpEmails($emails);
         		}*/
         $message = "{$count} email(s) were processed.";
         // $message = count($emails) . " email(s) were processed.";
         DaemonUtils::endJob($job, $message);
     } catch (Exception $e) {
         $message = $e->getMessage();
         DaemonUtils::endJob($job, $message, 'ERROR');
     }
 }
Example #6
0
 public function actionForgotPassword()
 {
     if (!Yii::app()->user->isGuest) {
         $this->redirect('/home');
     }
     $model = new ForgotPasswordForm();
     if (isset($_POST) && isset($_POST['ForgotPasswordForm'])) {
         $model->attributes = $_POST['ForgotPasswordForm'];
         if ($model->validate()) {
             // Generate Password here and redirect
             $tempPass = SecurityUtils::generateRandomString(8);
             $user = UserCredentials::model()->find('email_id=:email', array(':email' => $model->email));
             if ($user) {
                 $user->salt = SecurityUtils::generateSalt($user->email_id);
                 $user->password = SecurityUtils::encryptPassword($tempPass, $user->salt);
                 if ($user->save()) {
                     $data['temp_password'] = $tempPass;
                     $data['user'] = $user->id;
                     EmailApi::sendEmail($model->email, "ACCOUNT.RESET.PASSWORD", $data);
                     Yii::app()->user->setFlash('success', "We have sent you a new password to your email.\n\t\t\t\t\t\t<br/> Please add " . Yii::app()->params['adminEmail'] . " to your whitelist.");
                     $this->redirect('/home');
                 }
             }
         }
     }
     $this->render('forgotPassword', array('model' => $model));
 }
Example #7
0
 public function actionPost()
 {
     Yii::beginProfile('project_post');
     $model = new Projects();
     $modelCity = new GeoCity();
     $modelState = new GeoState();
     $modelAmenities = new ProjectAmenities();
     $modelImages = new ProjectImages();
     $amenities = null;
     if (isset($_POST['submit'])) {
         $model->attributes = $_POST['Projects'];
         $modelImages->attributes = $_POST['ProjectImages'];
         $amenities = isset($_POST['amenity_id']) ? $_POST['amenity_id'] : null;
         /*if($amenities){
         	 $amenity_data = null;
         	 foreach($amenities as $i=>$amenity){
         	 if($i!=0)
         	 $amenity_data.=',';
         	 $amenity_data.=$amenity;
         	 }
         	 $amenities = $amenity_data;
         	 }*/
         $valid = true;
         $model->user_id = Yii::app()->user->id;
         $valid = $valid && $model->validate();
         if ($amenities == null) {
             $modelAmenities->addError('amenity_id', 'Amenities cannot be blank.');
             $valid = false;
         }
         $modelImages->image = CUploadedFile::getInstance($modelImages, 'image');
         if ($modelImages->image == "") {
             $modelImages->addError('image', 'Image cannot be blank.');
             $valid = false;
         }
         if ($valid) {
             $data = $_POST['Projects'];
             $project = ProjectApi::createProject('1', $data);
             if (!$project->hasErrors()) {
                 $amenities = ProjectAmenitiesApi::addAmenitiesForProject($project->id, $_POST['amenity_id']);
                 $imagePath = ImageUtils::uploadImage($modelImages, 'image');
                 if ($amenities && $imagePath) {
                     $image = ProjectImagesApi::addImage($project->id, $imagePath);
                     if (!$image) {
                         ProjectApi::deleteProjectById($project->id);
                         ProjectAmenitiesApi::deleteAllAmenitiesForProject($project->id);
                     }
                     if (file_exists($imagePath)) {
                         unlink($imagePath);
                     }
                     $data = array();
                     $user = UserApi::getUserById($project->user_id);
                     $user ? $data["user"] = $user->id : null;
                     $data["project"] = $project->id;
                     EmailApi::sendEmail($user->email_id, "ACTIVITY.PROJECT.NEW", $data);
                     $this->redirect('/project/' . $project->id);
                 } else {
                     ProjectApi::deleteProjectById($project->id);
                     ProjectAmenitiesApi::deleteAllAmenitiesForProject($project->id);
                 }
             } else {
                 if (isset($property->id)) {
                     ProjectApi::deleteProjectById($property->id);
                 }
             }
         }
     }
     $this->render('post', array('model' => $model, 'modelState' => $modelState, 'modelCity' => $modelCity, 'modelAmenities' => $modelAmenities, 'modelImages' => $modelImages, 'amenities' => $amenities));
     Yii::endProfile('project_post');
 }
Example #8
0
 public function actionStarRatingAjax($userId, $builderId)
 {
     $ratingAjax = isset($_POST['rate']) ? $_POST['rate'] : 0;
     BuilderRatingApi::addRating($builderId, $userId, $ratingAjax);
     $data = array();
     $userId = BuilderProfileApi::getBuilderProfileById($builderId)->user_id;
     $user = UserApi::getUserById($userId);
     $user ? $data["user"] = $user->id : null;
     $data["builder"] = $builderId;
     EmailApi::sendEmail($user->email_id, "ACTIVITY.BUILDER.RATING", $data);
     echo 'Your Rating is ' . $ratingAjax;
 }
Example #9
0
 public function actionStarRatingAjax($userId, $agentId)
 {
     $ratingAjax = isset($_POST['rate']) ? $_POST['rate'] : 0;
     AgentRatingApi::addRating($agentId, $userId, $ratingAjax);
     $data = array();
     $userId = AgentProfileApi::getAgentProfileById($agentId)->user_id;
     $user = UserApi::getUserById($userId);
     $user ? $data["user"] = $user->id : null;
     $data["agent"] = $agentId;
     EmailApi::sendEmail($user->email_id, "ACTIVITY.AGENT.RATING", $data);
     echo 'Your Rating is ' . $ratingAjax;
 }
Example #10
0
 public function actionStarRatingAjax($userId, $specialistId)
 {
     $ratingAjax = isset($_POST['rate']) ? $_POST['rate'] : 0;
     SpecialistRatingApi::addRating($userId, $specialistId, $ratingAjax);
     $data = array();
     $userId = SpecialistProfileApi::getSpecialistProfileById($specialistId)->user_id;
     $user = UserApi::getUserById($userId);
     $user ? $data["user"] = $user->id : null;
     $data["specialist"] = $specialistId;
     EmailApi::sendEmail($user->email_id, "ACTIVITY.SPECIALIST.RATING", $data);
     echo 'Your Rating is ' . $ratingAjax;
 }
Example #11
0
 public function actionView($id)
 {
     Yii::beginProfile('jukebox_view');
     if (isset($_GET['attributeidC'])) {
         JukeboxAnswersApi::undoCorrectAnswer($_GET['attributeidC']);
     }
     if (isset($_GET['attributeidW'])) {
         JukeboxAnswersApi::undoWrongAnswer($_GET['attributeidW']);
     }
     $jukeboxQuestion = '';
     $userProfile = '';
     $geoCity = '';
     $jukeboxAnswers = '';
     $userdata = '';
     $jukeboxRating = '';
     $juckboxRatingEnable = false;
     $modelJukeboxQuestions = new JukeboxQuestions();
     $jukeboxNewAnswers = new JukeboxAnswers();
     $jukeboxQuestion = JukeboxQuestionsApi::getJukeboxQuestionById($id);
     $userProfile = UserApi::getUserProfileDetails($jukeboxQuestion->user_id);
     $juckboxRatingReadOnly = JukeboxRatingApi::checkUserRating($jukeboxQuestion->id, Yii::app()->user->id);
     if ($userProfile) {
         if (!$juckboxRatingReadOnly) {
             if ($userProfile->id == Yii::app()->user->id) {
                 $juckboxRatingReadOnly = true;
             } else {
                 $juckboxRatingReadOnly = false;
             }
         } else {
             $juckboxRatingReadOnly = true;
         }
     }
     if ($jukeboxQuestion) {
         if (isset($_POST['submit'])) {
             $model = new JukeboxAnswers();
             $model->attributes = $_POST['JukeboxAnswers'];
             $data = JukeboxAnswersApi::addJukeboxAnswer(Yii::app()->user->id, $jukeboxQuestion->id, $model);
             if ($data) {
                 $emailData = array();
                 $user = UserApi::getUserById(Yii::app()->user->id);
                 $user ? $emailData["user"] = $user->id : null;
                 $emailData["answer"] = $data->id;
                 EmailApi::sendEmail($user->email_id, "ACTIVITY.JUKEBOX.RESPONSE", $emailData);
             }
         }
         $geoCity = GeoCityApi::getCitynameByID($userProfile->city_id);
         $jukeboxAnswers = JukeboxAnswersApi::getJukeboxAnswers($jukeboxQuestion->id);
         if ($jukeboxAnswers) {
             foreach ($jukeboxAnswers as $answers) {
                 $jukeboxAnswersID[] = $answers->user_id;
             }
             $criteria = new CDbCriteria();
             $criteria->addInCondition('user_id', $jukeboxAnswersID);
             $users = UserProfiles::model()->findAll($criteria);
             $user_data = '';
             foreach ($users as $user) {
                 $userdata[$user->user_id] = $user->first_name;
             }
         }
         $jukeboxRating = JukeboxRatingApi::getRating($jukeboxQuestion->id);
     } else {
         $jukeboxQuestion->question = "No Questions have been posted by user";
         $jukeboxQuestion->description = '';
         $jukeboxQuestion->id = '';
     }
     $this->render('view', array('modelJukeboxQuestions' => $modelJukeboxQuestions, 'jukeboxNewAnswers' => $jukeboxNewAnswers, 'jukeboxQuestion' => $jukeboxQuestion, 'userProfile' => $userProfile, 'geoCity' => $geoCity, 'jukeboxAnswers' => $jukeboxAnswers, 'userdata' => $userdata, 'jukeboxRating' => $jukeboxRating, 'juckboxRatingReadOnly' => $juckboxRatingReadOnly));
     Yii::endProfile('jukebox_view');
 }
Example #12
0
 public function actionAccount()
 {
     // Check if the user is not a guest. If member then redirect him to the dashboard here.
     // @todo Replace url to Dashboard url
     if (!Yii::app()->user->isGuest) {
         $this->redirect('/home');
     }
     // Create a new Front Login Form model.
     $loginModel = new FrontLoginForm();
     $this->performAjaxValidation($loginModel);
     // if it is ajax validation request
     if (isset($_POST['ajax'])) {
         //	var_dump($_POST['ajax']);die();
     }
     if (isset($_POST['ajax']) && $_POST['ajax'] === 'front-login-form') {
         echo CActiveForm::validate($loginModel);
         Yii::app()->end();
     }
     // collect user input data
     if (isset($_POST['FrontLoginForm'])) {
         $loginModel->attributes = $_POST['FrontLoginForm'];
         // validate user input and redirect to the previous page if valid
         if ($loginModel->validate() && $loginModel->login()) {
             $this->redirect(Yii::app()->user->returnUrl);
         }
     }
     /*
      * This means the user has either come here for the first time or is trying to create
      * a new account.
      */
     $credentialsModel = UserApi::populateCredentialsModel(null, 'register');
     $profilesModel = UserApi::populateProfilesModel(null, 'register');
     require_once Yii::app()->params["rootDir"] . '/library/facebook/src/facebook.php';
     $facebook = new Facebook(array('appId' => Yii::app()->params["fbAppId"], 'secret' => Yii::app()->params["fbSecret"]));
     $this->performAjaxValidation($profilesModel);
     /*
      * Check if the user has reached this page through a widget.
      */
     if (isset($_POST['UserCredentials']) && !isset($_POST['UserProfiles'])) {
         $credentialsModel = UserApi::populateCredentialsModel($_POST['UserCredentials'], 'register');
         $credentialsModel->validate(array('email_id', 'password', 'password_confirm'));
         $profilesModel = UserApi::populateProfilesModel(null, 'register');
         //	$this->render('account',array('credentialsModel'=>$credentialsModel,'profilesModel'=>$profilesModel,'login'=>$loginModel));
     } else {
         if (isset($_POST['UserCredentials']) && isset($_POST['UserProfiles'])) {
             // save here
             $credentialsModel = UserApi::populateCredentialsModel($_POST['UserCredentials'], 'register');
             $credResult = $credentialsModel->validate(array('email_id', 'password', 'password_confirm'));
             $profilesModel = UserApi::populateProfilesModel($_POST['UserProfiles'], 'register');
             $profResult = $profilesModel->validate(array('first_name', 'last_name', 'gender', 'address_line1', 'address_line2', 'country_id', 'state_id', 'city_id', 'zip', 'phone', 'alt_phone', 'agree'));
             if ($credResult && $profResult) {
                 $result = true;
                 $models = UserApi::createUser($credentialsModel, $profilesModel);
                 // Redirect to thanks page.
                 // @todo link to success page.
                 if ($models) {
                     $data = array();
                     $data["user"] = $models['credential']->id;
                     EmailApi::sendEmail($credentialsModel->email_id, "REGISTRATION.ACTIVATION", $data);
                     $session = new CHttpSession();
                     $session->open();
                     $session['registration-success'] = 'true';
                     $this->redirect(array('/account/thanks', 'email' => $models['credential']->email_id));
                 }
                 //	else
                 //		$this->render('account',array('credentialsModel'=>$credentialsModel,'profilesModel'=>$profilesModel,'login'=>$loginModel));
                 // save())
             }
         }
     }
     // else
     $this->render('account', array('credentialsModel' => $credentialsModel, 'profilesModel' => $profilesModel, 'login' => $loginModel));
 }