/**
  * Creates a new model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  */
 public function actionCreate()
 {
     $model = new AccountProfile();
     // Uncomment the following line if AJAX validation is needed
     // $this->performAjaxValidation($model);
     if (isset($_POST['AccountProfile'])) {
         $model->attributes = $_POST['AccountProfile'];
         if ($model->save()) {
             $this->redirect(array('view', 'id' => $model->account_profile_id));
         }
     }
     $this->render('create', array('model' => $model));
 }
Esempio n. 2
0
 /**
  * Creates a new model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  */
 public function actionCreate()
 {
     // if user is already logged in
     // redirect to dash board
     if (!Yii::app()->user->isGuest) {
         $this->redirect(array('project/index'));
     }
     $model = new Account();
     //$companyModel = new Company();
     //$companyContactModel = new CompanyContact();
     $accountSubscriptionModel = new AccountSubscription();
     $accountProfile = new AccountProfile();
     // Uncomment the following line if AJAX validation is needed
     // $this->performAjaxValidation($model);
     /**
      * Process form's submission
      * param's name must be in this format, e.g. "Account[account_email]"
      */
     if (isset($_POST['Account'])) {
         $model->attributes = $_POST['Account'];
         $model->account_id = null;
         //$companyModel->attributes = $_POST['Company'];
         //$companyContactModel->attributes = $_POST['CompanyContact'];
         $accountSubscriptionModel->attributes = $_POST['AccountSubscription'];
         $accountProfile->attributes = $_POST['AccountProfile'];
         /**
         			$model->account_company_name = $companyModel->company_name;
         			$model->account_contact_surname = $companyContactModel->contact_surname;
         			$model->account_contact_given_name = $companyContactModel->contact_given_name;
         			$model->account_subscription_package_id = $accountSubscriptionModel->account_subscription_package_id;
         			**/
         // SAVE ACCOUNT
         //$model->account_password = $model->hashPassword($model->account_password);
         $model->account_status = ACCOUNT_STATUS_ACTIVATED;
         // ACCOUNT_STATUS_NOT_ACTIVATED;
         $save_result = '';
         // save user account record to database
         $save_result = $model->save();
         if ($save_result) {
             // create/update subscription record
             $accountSubscriptionModel->account_id = $model->account_id;
             $accountSubscriptionModel->account_subscription_start_date = date('Y-m-d H:i');
             $accountSubscriptionModel->account_subscription_status_id = 1;
             $accountSubscriptionModel->save();
             // create account profile
             $accountProfile->account_id = $model->account_id;
             $accountProfile->account_profile_preferred_display_name = $accountProfile->account_profile_given_name . ' ' . $accountProfile->account_profile_surname;
             $accountProfile->save();
             /**
             				// create company record
             				$companyModel->company_master_account_id = $model->account_id;
             				$companyModel->company_is_master = COMPANY_IS_MASTER;
             			
             				// save company record to database,
             				// if successful, create contact record
             				if ($companyModel->save()) {
             					// create contact record
             					$companyContactModel->contact_email1 = $model->account_email;
             					$companyContactModel->company_id = $companyModel->company_id;
             					$companyContactModel->account_id = $model->account_id;
             					// save contact record to database
             					$companyContactModel->save();
             				}**/
             // notify user through email
             $model->sendSuccessfulSignupEmailNotification();
         }
         // redirect to view
         if ($save_result) {
             //$this->redirect(array('view','id'=>$model->account_id));
             $this->redirect(Yii::app()->baseUrl . '/product/signup-success.php');
         }
     }
     /** 
      * otherwise just show creation form
      */
     $active_subscription_packages = SubscriptionPackage::getActivePackages();
     $active_subscription_package_names = array();
     foreach ($active_subscription_packages as $item) {
         $active_subscription_package_names[$item->subscription_package_id] = $item->subscription_package_name;
     }
     $data = array('model' => $model, 'accountProfileModel' => $accountProfile, 'accountSubscriptionModel' => $accountSubscriptionModel, 'active_subscription_packages' => $active_subscription_package_names);
     LBApplication::render($this, 'create', $data);
     //$this->render('create',);
 }
 public function actionAccept($id, $key)
 {
     // must not be logged in user
     if (!Yii::app()->user->isGuest) {
         $this->redirect(array('site/page', 'view' => 'must_log_out'));
     }
     $model = $this->loadModel($id);
     // must match both id and random key
     if (!$model) {
         echo "Hi. Somehow this invitation is missing or removed. Please contact the person who invited you.";
         return;
     }
     if ($model->account_invitation_rand_key != $key) {
         echo "Hi there. Looks like your invitation is no longer valid. Please contact the person who invited you.";
         return;
     }
     if ($model->account_invitation_status == 1) {
         echo "Looks like you already accepted this invitation.";
         return;
     }
     $account = new Account();
     // SUBMISSION PROCESS
     // Get account invitation record that has this unique key
     // 1. Update invitation status to accepted
     // 2. Create new account for this user
     // 3. Put this user under team member of the master account
     if (isset($_POST['Account']['account_password'])) {
         $model->account_invitation_status = 1;
         if ($model->save()) {
             $account->account_email = $model->account_invitation_to_email;
             $account->account_password = $_POST['Account']['account_password'];
             $account->account_status = ACCOUNT_STATUS_ACTIVATED;
             if ($account->save()) {
                 // create account profile
                 $accountProfile = new AccountProfile();
                 $accountProfile->account_id = $account->account_id;
                 $accountProfile->account_profile_surname = $_POST['AccountProfile']['account_profile_surname'];
                 $accountProfile->account_profile_given_name = $_POST['AccountProfile']['account_profile_given_name'];
                 $accountProfile->account_profile_preferred_display_name = $accountProfile->account_profile_given_name . ' ' . $accountProfile->account_profile_surname;
                 if ($accountProfile->save()) {
                     // create team member record
                     $teamMember = new AccountTeamMember();
                     $teamMember->accepting_invitation = true;
                     $teamMember->master_account_id = $model->account_invitation_master_id;
                     $teamMember->member_account_id = $account->account_id;
                     $teamMember->account_subscription_id = $model->account_invitation_subscription_id;
                     $teamMember->is_active = AccountTeamMember::ACCOUNT_TEAM_MEMBER_IS_ACTIVE;
                     if ($model->account_invitation_type == AccountInvitation::ACCOUNT_INVITATION_TYPE_CUSTOMER) {
                         $teamMember->is_customer = ACCOUNT_TEAM_MEMBER_IS_CUSTOMER;
                     } else {
                         $teamMember->is_customer = 0;
                     }
                     if ($teamMember->save()) {
                         //$companyContact =
                         // create project member record if any
                         if ($model->account_invitation_project > 0) {
                             $projectMember = new ProjectMember();
                             $projectMember->project_id = $model->account_invitation_project;
                             $projectMember->account_id = $account->account_id;
                             $projectMember->project_member_start_date = date('Y-m-d H:i:s');
                             $projectMember->project_member_is_manager = PROJECT_MEMBER_IS_NOT_MANAGER;
                             $projectMember->accepting_invitation = true;
                             $projectMember->save();
                         }
                         $this->redirect(array('site/page', 'view' => 'account_activated'));
                     }
                 }
             }
         }
     }
     // SHOW VIEW
     // show acceptance form, where user has to enter password
     $this->render('accept', array('model' => $model, 'account' => $account));
 }