/** * 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',); }
/** * Creates a new model. * If creation is successful, the browser will be redirected to the 'view' page. */ public function actionCreate() { $model = new AccountSubscription(); // Uncomment the following line if AJAX validation is needed // $this->performAjaxValidation($model); if (isset($_POST['AccountSubscription'])) { // $model->attributes=$_POST['AccountSubscription']; // if($model->save()) // $this->redirect(array('view','id'=>$model->account_subscription_id)); // if (isset($_GET['package_id'])) // { $package_id = 4; // check if this user is already subscribe to this package // if (AccountSubscription::model()->isAlreadySubscribedToPackage($package_id)) // { // $this->redirect(array('accountTeamMember/admin')); // } // add subscription $accountSubscription = new AccountSubscription(); $accountSubscription->account_id = Yii::app()->user->id; $accountSubscription->account_subscription_package_id = $package_id; $accountSubscription->account_subscription_start_date = date('Y-m-d H:i:s'); $accountSubscription->account_subscription_status_id = ACCOUNT_SUBSCRIPTION_STATUS_ACTIVE; $accountSubscription->subscription_name = $_POST['AccountSubscription']['subscription_name']; if ($accountSubscription->save()) { LBApplication::setCurrentlySelectedSubscription($accountSubscription->account_subscription_id); } $this->redirect(array('accountTeamMember/admin')); // } // // no package id, go to home // $this->redirect(array('project/index')); } $this->render('create', array('model' => $model)); }