Example #1
0
 public function actionSaveproject()
 {
     header('Access-Control-Allow-Origin: *');
     $rows = array();
     if (Homeowners::model()->countByAttributes(array('email' => $_POST['email'])) == 0) {
         if (Homeowners::model()->countByAttributes(array('username' => $_POST['username'])) == 0) {
             $password = Yii::app()->Ini->generate_password();
             $huser = new Homeowners();
             $huser->firstname = $_POST['firstname'];
             $huser->lastname = $_POST['lastname'];
             $huser->email = $_POST['email'];
             $huser->phone_number = $_POST['phone_number'];
             $huser->username = $_POST['username'];
             $huser->password = $password;
             if ($huser->save()) {
                 Yii::app()->Ini->savetovnoc($_POST['email']);
                 $owner_id = Yii::app()->db->getLastInsertId();
                 Yii::app()->Ini->savetoaffiliate($owner_id, 'homeowner');
                 $this->SendMailAfterSignUp($owner_id);
                 $proj = new Projects();
                 $proj->project_type_id = $_POST['projecttype'];
                 $proj->description = $_POST['projectdesc'];
                 $proj->start_date = $_POST['projectstart'];
                 $proj->status_for_project = $_POST['projectstatus'];
                 $proj->time_frame = $_POST['projecttimeframe'];
                 $proj->owned_property = $_POST['won_pro'];
                 $proj->address = $_POST['projectaddress'];
                 $proj->state_id = $_POST['projectstate'];
                 $proj->city = $_POST['city'];
                 $proj->zipcode = $_POST['zip_code'];
                 $proj->budget = $_POST['projectbudget'];
                 $proj->homeowner_id = $owner_id;
                 if ($proj->save()) {
                     $proj_id = Yii::app()->db->getLastInsertId();
                     $this->SendMailAfterProject($proj_id);
                     Yii::app()->Ini->renovationapi($proj_id);
                     $this->renderRequest(array('success' => true));
                 } else {
                     $this->renderRequest(false, $proj->getErrors());
                 }
             } else {
                 $this->renderRequest(false, $huser->getErrors());
             }
         } else {
             $this->renderRequest(false, 'Username already exists');
         }
     } else {
         $this->renderRequest(false, 'Email already exists');
     }
 }
 public function saveproject($post)
 {
     $indicator = $post['indicator'];
     $status = true;
     $return['indicator'] = $indicator;
     if ($indicator == 2) {
         if (Homeowners::model()->countByAttributes(array('email' => $post['homeown_email'])) == 0) {
             if (Homeowners::model()->countByAttributes(array('username' => $post['howeown_pname'])) == 0) {
                 $password = Yii::app()->Ini->generate_password();
                 $huser = new Homeowners();
                 $huser->firstname = $post['homeown_fname'];
                 $huser->lastname = $post['homeown_lname'];
                 $huser->email = $post['homeown_email'];
                 $huser->phone_number = $post['homeown_phone'];
                 $huser->username = $post['howeown_pname'];
                 $huser->password = $password;
                 if ($huser->save()) {
                     Yii::app()->Ini->savetovnoc($post['homeown_email']);
                     $owner_id = Yii::app()->db->getLastInsertId();
                     Yii::app()->Ini->savetoaffiliate($owner_id, 'homeowner');
                     Yii::app()->Ini->savetocampaign($huser->email, $huser->firstname . ' ' . $huser->lastname);
                     $this->SendMailAfterSignUp($owner_id);
                     $refer_id = $post['refer_id'];
                     if ($refer_id != '') {
                         $ref = new Referral();
                         $ref->userid = $owner_id;
                         $ref->user_type = 'homeowner';
                         $ref->referred_by = $refer_id;
                         $ref->referred_by_type = 'contractor';
                         $ref->save();
                     }
                 } else {
                     $status = false;
                     $return['message'] = $huser->getErrors();
                 }
             } else {
                 $status = false;
                 $return['message'] = "Username already exists.";
             }
         } else {
             $status = false;
             $return['message'] = "Email already exists.";
         }
     } elseif ($indicator == 3) {
         $status = true;
         $owner_id = Yii::app()->user->getId();
     } else {
         $identity = new UserIdentity($post['home_loginEmail'], $post['home_loginPassword'], 'homeowner');
         if ($identity->authenticate()) {
             Yii::app()->user->login($identity);
             $owner_id = Yii::app()->user->getId();
         } else {
             $status = false;
             $return['message'] = $identity->errorMessage;
         }
     }
     if ($status) {
         //saving to project
         $proj = new Projects();
         $proj->project_type_id = $post['projecttype'];
         $proj->description = $post['projectdesc'];
         $proj->start_date = $post['projectstart'];
         $proj->status_for_project = $post['projectstatus'];
         $proj->time_frame = $post['projecttimeframe'];
         $proj->owned_property = $post['won_pro'];
         $proj->address = $post['projectaddress'];
         $proj->state_id = $post['projectstate'];
         $proj->city = $post['city'];
         $proj->zipcode = $post['zip_code'];
         $proj->budget = $post['projectbudget'];
         $proj->homeowner_id = $owner_id;
         if ($proj->save()) {
             $proj_id = Yii::app()->db->getLastInsertId();
             $this->SendMailAfterProject($proj_id);
             Yii::app()->Ini->renovationapi($proj_id);
             if ($indicator == 3) {
                 $return['message'] = $this->renderPartial('successpost', array(), true);
             } else {
                 if ($indicator == 2) {
                     //echo $password;
                     //echo $post['homeown_email'];
                     //$return['message'] = $this->renderPartial('success', array(), true);
                     $return['projectid'] = $proj_id;
                     $identity = new UserIdentity($post['homeown_email'], $password, 'homeowner');
                     if ($identity->authenticate()) {
                         Yii::app()->user->login($identity);
                         $owner_id = Yii::app()->user->getId();
                         $return['message'] = $this->renderPartial('success', array(), true);
                     } else {
                         $status = false;
                         $return['message'] = $identity->errorMessage;
                     }
                 } else {
                     $return['message'] = $this->renderPartial('success', array(), true);
                 }
             }
         } else {
             $status = false;
             $return['message'] = $proj->getErrors();
         }
     }
     $return['status'] = $status;
     $this->renderJSON($return, $status);
 }