Esempio n. 1
0
 public function actionRegiterAmember()
 {
     $this->pageTitle = Lang::t('New Member Sign Up');
     $user_model = new Users(Users::SCENARIO_SIGNUP);
     $person_model = new Person();
     $person_address = new PersonAddress();
     $contribution = new ContributionsByMembers();
     $contribution->receiptno = empty($contribution->receiptno) ? NextReceiptNo::model()->receiptNo() : $contribution->receiptno;
     $user_model->activation_code = Common::generateHash(microtime());
     $user_model->user_level = UserLevels::LEVEL_MEMBER;
     $user_model->timezone = SettingsTimezone::DEFAULT_TIME_ZONE;
     if (Yii::app()->request->isPostRequest) {
         $verifyPhoneCode = isset($_POST['verifyPhoneCode']) ? $_POST['verifyPhoneCode'] : null;
         $verifyMailCode = isset($_POST['verifyMailCode']) ? $_POST['verifyMailCode'] : null;
         if (isset($_POST['Person'])) {
             $person_model = Person::model()->find('idno=:idno', array(':idno' => $_POST['Person']['idno']));
             $person_model = empty($person_model) ? new Person() : $person_model;
             $person_model->attributes = $_POST['Person'];
             $person_model->married = 'n';
             $person_model->havechildren = 'n';
             $person_model->validate();
         }
         if (isset($_POST['Users'])) {
             if (!$person_model->isNewRecord) {
                 $user_model = Users::model()->findByPk($person_model->id);
                 if (empty($user_model)) {
                     $user_model = new Users(Users::SCENARIO_SIGNUP);
                     $user_model->id = $person_model->id;
                 }
             }
             $user_model->attributes = $_POST['Users'];
             $user_model->status = 'Active';
             $user_model->answer = strtoupper($user_model->answer);
             $user_model->validate();
         }
         if (isset($_POST['PersonAddress'])) {
             if (!empty($person_model->id)) {
                 $person_address = PersonAddress::model()->find('person_id=:id', array(':id' => $person_model->id));
             }
             $person_address = empty($person_address) ? new PersonAddress() : $person_address;
             $person_address->attributes = $_POST['PersonAddress'];
             $person_address->validate(array('phone1'));
         }
         if (isset($_POST['ContributionsByMembers'])) {
             $contribution->attributes = $_POST['ContributionsByMembers'];
             $contribution->contribution_type = 1;
             $contribution->date = date('Y') . '-' . date('m') . '-' . date('d');
             $contribution->validate(array('amount', 'receiptno', 'date', 'payment_mode', 'transaction_no'));
         }
         if (!$user_model->hasErrors() && !$person_model->hasErrors() && !$person_address->hasErrors() && !$contribution->hasErrors()) {
             if ($user_model->save(false)) {
                 if (true == ($personNewModel = $person_model->isNewRecord)) {
                     $person_model->id = $user_model->id;
                 }
                 $person_model->save(false);
                 $person_address->person_id = $person_model->id;
                 $person_address->save(false);
                 $contribution->member = $person_model->id;
                 $contribution->rowsToCreate($contribution, $contribution->member, $contribution->contribution_type, $contribution->amount, $contribution->date, $contribution->receiptno, array());
                 if (!$personNewModel) {
                     $withdrawal = MemberWithdrawal::model()->find('member=:id', array(':id' => $person_model->id));
                     $withdrawal->status = 'Yes';
                     $withdrawal->update(array('status'));
                 }
                 Yii::app()->user->setFlash('success', Lang::t('Account created. Click login at bottom of the page to proceed.'));
                 $this->refresh();
             }
         }
     }
     $this->render('application.modules.users.views.default.default', array('model' => null, 'others' => array('user_model' => $user_model, 'person_model' => $person_model, 'person_address' => $person_address, 'verifyPhoneCode' => isset($verifyPhoneCode) ? $verifyPhoneCode : null, 'verifyMailCode' => isset($verifyMailCode) ? $verifyMailCode : null, 'contribution' => $contribution, 'render' => 'application.modules.auth.views.register.index'), 'user_model' => Users::model()->loadModel(Yii::app()->user->id), 'person_model' => Person::model()->loadModel(Yii::app()->user->id), 'title' => 'New Account SignUp', 'render' => 'application.modules.users.views.default._createAnotherUser'));
 }