Esempio n. 1
0
 /**
  * Creates a new model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  */
 public function actionCreate()
 {
     $model = new Projects();
     // Uncomment the following line if AJAX validation is needed
     // $this->performAjaxValidation($model);
     if (isset($_POST['Projects'])) {
         $model->attributes = $_POST['Projects'];
         if ($model->save()) {
             $this->redirect(array('view', 'id' => $model->id));
         }
     }
     $this->render('create', array('model' => $model));
 }
Esempio n. 2
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');
     }
 }
Esempio n. 3
0
 /**
  * New Project action
  */
 public function actionNew()
 {
     $model = new Projects();
     if (isset($_POST['Projects'])) {
         $model->setAttributes($_POST['Projects']);
         if ($model->save()) {
             Functions::setFlash(Yii::t('projects', 'Project Created.'));
             $this->redirect(array('/projects'));
         }
     }
     // Add title
     $this->pageTitle[] = Yii::t('projects', 'Creating New Project');
     $this->render('new', array('model' => $model));
 }
 /**
  * Store a newly created resource in storage.
  *
  * @return Response
  */
 public function store()
 {
     // Get input fields from Create Form
     $name = Input::get('name');
     $subject = Input::get('subject');
     $url = Input::get('url');
     $description = Input::get('description');
     // Create a new Project from Projects() Model.
     $project = new Projects();
     $project->name = $name;
     $project->subject = $subject;
     $project->url = $url;
     $project->description = $description;
     $project->save();
     // Redirects to Public Portfolio
     return Redirect::route('portfolio.index');
 }
 public function actionStart()
 {
     $model = new Projects();
     // uncomment the following code to enable ajax-based validation
     /*
     if(isset($_POST['ajax']) && $_POST['ajax']==='projects-start-form')
     {
     	echo CActiveForm::validate($model);
     	Yii::app()->end();
     }
     */
     if (isset($_POST['Projects'])) {
         $model->attributes = $_POST['Projects'];
         $model->creationDateTime = date('Y-m-d H:i:s');
         if ($model->validate()) {
             $model->save();
             $this->redirect('industry/index');
         }
     }
     $this->render('start', array('model' => $model));
 }
Esempio n. 6
0
 /**
  * This method accepts user's id and an array of data and creates the model.
  * Returns model if successfully created.
  * Returns the error validated model if validation fails.
  *
  * data array may have the following hash keys -
  * 1. user_id
  * 2. project_name
  * 3. description
  * 4. ownership_types_id
  * 5. locality_id
  * 6. jackpot_investment
  * 7. bedrooms
  * 8. features
  * 9. cover_area
  * 10.land_area
  * 11. min_price
  * 12. max_price
  * 13. price_starting_from
  * 14. per_unit_price
  * 15. area_type
  * 16. display_price
  * 17. price_negotiable
  * 18. landmarks
  * 19. tax_fees
  * 20. terms_and_conditions
  * 21. views
  * 22. recently_viewed
  *
  * @param array $data,string $userId
  * @return model || model with errors
  */
 public static function createProject($userId, $data)
 {
     $project = new Projects();
     $project->attributes = $data;
     $project->user_id = $userId;
     $project->save();
     return $project;
 }
Esempio n. 7
0
 public function actionCreate()
 {
     $data = $_POST;
     //will be empty if CSRF authentication fails
     if (!empty($data)) {
         $data['name'] = trim($data['name']);
         $data['code'] = trim($data['code']);
         $data['description'] = trim($data['description']);
         $data['production_date'] = trim($data['production_date']);
         //FORM VALIDATION HERE
         $errors = array();
         //name is required
         if (strlen($data['name']) == 0) {
             array_push($errors, 'NAME_ERROR: Name is required');
         }
         //code is required
         if (strlen($data['code']) == 0) {
             array_push($errors, 'CODE_ERROR: Code is required');
             //code must be at least 5 characters long
         } else {
             if (strlen($data['code']) != 5) {
                 array_push($errors, 'CODE_ERROR: Project code must be 5 characters');
                 //check if code is alphanumeric
             } else {
                 if (!ctype_alnum($data['code'])) {
                     array_push($errors, 'CODE_ERROR: Code must be alphanumeric');
                     //check if project code already exists
                 } else {
                     if (Projects::model()->exists('code = :code', array(":code" => $data['code']))) {
                         array_push($errors, 'CODE_ERROR: Code already taken');
                     }
                 }
             }
         }
         //data is good
         if (count($errors) == 0) {
             $project = new Projects();
             $project->name = $data['name'];
             $project->code = strtoupper($data['code']);
             $project->description = substr($data['description'], 0, 255);
             $project->status = 'ACTIVE';
             $project->production_date = $data['production_date'];
             $project->termination_date = '0000-00-00';
             $project->date_created = date("Y-m-d H:i:s");
             $project->date_updated = '0000-00-00 00:00:00';
             $project->created_by = Yii::app()->user->name;
             $project->save();
             echo CJSON::encode(array('type' => 'success', 'data' => ''));
         } else {
             echo CJSON::encode(array('type' => 'error', 'data' => implode(',', $errors)));
         }
     } else {
         echo CJSON::encode(array('type' => 'error', 'data' => 'CSRF_ERROR: CSRF Token did not match'));
     }
 }
Esempio n. 8
0
    /**
     * Create Empty company without users
     * @param $fedId
     * @param $newCompanyName
     * @param $impVendorInfo
     * @return Clients
     */
    public static function createEmptyCompany($fedId, $newCompanyName, $impVendorInfo = null)
    {
        $client = new Clients;

        // begin transaction
        $transaction = Yii::app()->db->beginTransaction();
        try {
            $company = new Companies;
            $project = new Projects;
            $companyAdreses = new CompanyAddresses;
            //$usersClientList = new UsersClientList;

            $company->Company_Name = $newCompanyName;
            $company->Company_Fed_ID = $fedId;
            if (preg_match('/^(\d{2}\-\d{7})|(\d{3}\-\d{2}\-\d{4})$/', $company->Company_Fed_ID)) {
                //usual w9 do nothing
            }

            if (preg_match('/^(IN[-]\d{7})$/', $company->Company_Fed_ID)) {
            //international w9
                $company->Temp_Fed_ID_Flag = 'N';

            }
            if (preg_match('/^(T0[-]\d{7})$/', $company->Company_Fed_ID)) {
                //international w9
                $company->Temp_Fed_ID_Flag = 'T';
            }

            $company->Auth_Code = Helper::generatePassword();

            $company->save();


            $company_adress = new Addresses;

            if ($impVendorInfo) {
                $company_adress = new Addresses;
                $company_adress->Address1 = $impVendorInfo['address'];
                $company_adress->City = $impVendorInfo['city'];
                $company_adress->State = $impVendorInfo['state'];
                $company_adress->ZIP = $impVendorInfo['zip'];
                if ($company_adress->validate()) {
                    $company_adress->save();
                } else {
                    $company_adress = new Addresses;
                    $company_adress->save();
                }
            }

            $company_adress->save();

            $companyAdreses->Company_ID = $company->Company_ID;
            $companyAdreses->Address_ID = $company_adress->Address_ID ? $company_adress->Address_ID : 0;
            $companyAdreses->save();

            $client->Company_ID = $company->Company_ID;
            $client->Client_Type = 1;
            $client->Client_Number = 1;
            $client->save();

            //create client project
            $project->Client_ID = $client->Client_ID;
            $project->Project_Name = "Corporate";
            $project->Project_Description = "Description of the Project";
            $project->PO_Starting_Number = Projects::DEFAULT_PO_STARTING_NUMBER;
            $project->Ck_Req_Starting_Numb = Projects::DEFAULT_CKRQ_STARTING_NUMBER;
            $project->save();

            $transaction->commit();
        } catch(Exception $e) {
            $transaction->rollback();
        }

        return $client;
    }
 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);
 }
 /**
  * Creates a new model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  */
 public function actionCreateProject()
 {
     // check if user has permissions to createProjects
     if (Yii::app()->user->checkAccess('createProjects') && Yii::app()->user->checkAccess('permissionsConfiguration') && Yii::app()->user->IsAdministrator) {
         // create Projects Object
         $model = new Projects();
         // if Projects form exist
         if (isset($_POST['Projects'])) {
             // set form elements to Projects model attributes
             $model->attributes = $_POST['Projects'];
             // validate and save
             if ($model->save()) {
                 // Create relation between user and project (this user will be first manager)
                 $modelForm = new ProjectsHasUsersForm();
                 $modelForm->project_id = $model->primaryKey;
                 $modelForm->user_id = Yii::app()->user->id;
                 $modelForm->isManager = 1;
                 $modelForm->saveUser();
                 // Select current project has default selection project
                 Yii::app()->user->setState('project_selected', $model->primaryKey);
                 Yii::app()->user->setState('project_selectedName', $model->project_name);
                 // save log
                 $attributes = array('log_date' => date("Y-m-d G:i:s"), 'log_activity' => 'ProjectCreated', 'log_resourceid' => $model->primaryKey, 'log_type' => Logs::LOG_ASSIGNED, 'user_id' => Yii::app()->user->id, 'module_id' => Yii::app()->controller->id, 'project_id' => $model->primaryKey);
                 Logs::model()->saveLog($attributes);
                 // to prevent F5 keypress, redirect to create page
                 Yii::app()->controller->redirect(Yii::app()->createUrl('projects/view', array('id' => $model->primaryKey)));
             }
         }
         $this->layout = 'column2';
         // output create page
         $this->render('../projects/create', array('model' => $model, 'companies' => Companies::model()->findCompanyList(Yii::app()->user->id), 'currencies' => Currencies::model()->findAll()));
     } else {
         throw new CHttpException(403, Yii::t('site', '403_Error'));
     }
 }