/**
  * Creates a new model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  */
 public function actionCreate()
 {
     $model = new ApplicationPersonalMentor();
     // Uncomment the following line if AJAX validation is needed
     // $this->performAjaxValidation($model);
     if (isset($_POST['ApplicationPersonalMentor'])) {
         $model->attributes = $_POST['ApplicationPersonalMentor'];
         if ($model->save()) {
             $this->redirect(array('view', 'id' => $model->id));
         }
     }
     $this->render('create', array('model' => $model));
 }
 public function actionPersonal()
 {
     $model = new ApplicationPersonalMentor();
     $students = new User();
     $unis = array();
     if (Yii::app()->getRequest()->isPostRequest) {
         // on application submit
         $user = User::model()->getCurrentUser();
         // pull application data and save
         $model->attributes = $_POST['ApplicationPersonalMentor'];
         $model->status = 'Admin';
         $model->user_id = $user->id;
         $model->date_created = new CDbExpression('NOW()');
         if (!isset($model->university_id) || $model->university_id == 0) {
             $model->university_id = NULL;
         }
         $model->save(false);
         // save user picks
         $mypicks = $_POST['picks'];
         $mypicks = explode(',', $mypicks);
         foreach ($mypicks as $pick) {
             if ($pick > 0) {
                 $dbpick = new ApplicationPersonalMentorPick();
                 $dbpick->app_id = $model->id;
                 $dbpick->user_id = $pick;
                 $dbpick->approval_status = 'Proposed by Mentor';
                 $dbpick->save(false);
             }
         }
         // save system picks
         $systempicks = $_POST['systempicks'];
         $systempicks = explode(',', $systempicks);
         foreach ($systempicks as $pick) {
             if ($pick > 0) {
                 $dbpick = new ApplicationPersonalMentorPick();
                 $dbpick->app_id = $model->id;
                 $dbpick->user_id = $pick;
                 $dbpick->approval_status = 'Proposed by System';
                 $dbpick->save(false);
             }
         }
         // redirect to application portal
         $this->redirect("/coplat/index.php/application/portal");
     } else {
         // on initial load
         $students->unsetAttributes();
         $students->isMentee = 1;
         $student = User::model()->returnUsersForApp($students->searchNoPagination());
         $universities = University::model()->getUniversities();
         $unis[0] = 'Any';
         foreach ($universities as $uni) {
             $unis[$uni->id] = $uni->name;
         }
         $model->system_pick_amount = 0;
     }
     $error = '';
     $this->render('personal', array('model' => $model, 'user' => $students, 'universities' => $unis, 'students' => $student, 'error' => $error));
 }