/**
  * Creates a new model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  */
 public function actionCreate()
 {
     $model = new Roomrequest();
     // Uncomment the following line if AJAX validation is needed
     // $this->performAjaxValidation($model);
     if (isset($_POST['Roomrequest'])) {
         $model->attributes = $_POST['Roomrequest'];
         if ($model->save()) {
             $this->redirect(array('view', 'id' => $model->id));
         }
     }
     $this->render('create', array('model' => $model));
 }
 /**
  * Creates a new model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  */
 public function actionCreate()
 {
     $model = new Registration();
     $model_1 = new Room();
     //$err_msg = '';
     $err_flag = 0;
     $err_msg = Yii::t('hostel', 'Please fix the following errors.') . '<br/>';
     // Uncomment the following line if AJAX validation is needed
     // $this->performAjaxValidation($model);
     if (isset($_POST['Registration'])) {
         $roles = Rights::getAssignedRoles(Yii::app()->user->Id);
         // check for single role
         foreach ($roles as $role) {
             if (sizeof($roles) == 1 and $role->name == 'student') {
                 $request = new Roomrequest();
                 $model->student_id = $_POST['Registration']['student_id'];
                 $model->food_preference = $_POST['Registration']['food_preference'];
                 $model->status = 'C';
                 $request->student_id = $_POST['Registration']['student_id'];
                 $request->status = 'C';
                 $request->save();
                 $model->save();
                 $this->redirect(array('/hostel/registration/create'));
             } else {
                 if ($_POST['hostel'] == NULL) {
                     $err_flag = 1;
                     $err_msg = $err_msg . '- ' . Yii::t('hostel', 'Hostel cannot be blank') . '<br/>';
                 }
                 if ($_POST['floor'] == NULL) {
                     $err_flag = 1;
                     $err_msg = $err_msg . '- ' . Yii::t('hostel', 'Floor cannot be blank') . '<br/>';
                 }
                 if ($_POST['student_id'] == NULL) {
                     $err_flag = 1;
                     $err_msg = $err_msg . '- ' . Yii::t('hostel', 'Student cannot be blank') . '<br/>';
                 }
                 if ($_POST['Registration']['food_preference'] == NULL) {
                     $err_flag = 1;
                     $err_msg = $err_msg . '- ' . Yii::t('hostel', 'Food Preference cannot be blank') . '<br/>';
                 }
                 if ($err_flag == 0) {
                     $allot_erre = Allotment::model()->findByAttributes(array('student_id' => $_POST['student_id'], 'status' => 'S'));
                     $hostel_reg = Registration::model()->findByAttributes(array('student_id' => $_POST['student_id'], 'status' => 'S'));
                     $model->attributes = $_POST['Registration'];
                     $model->student_id = $_POST['student_id'];
                     if ($allot_erre != NULL and $hostel_reg != NULL) {
                         $this->redirect(array('error', 'student_id' => $_POST['student_id']));
                     }
                     $trans = Transportation::model()->findByAttributes(array('student_id' => $_POST['student_id']));
                     if ($trans->student_id != NULL) {
                         if ($trans->student_id == $_POST['student_id']) {
                             $this->redirect(array('warning', 'registration' => $_POST['Registration'], 'student_id' => $_POST['student_id'], 'floor_id' => $_POST['floor'], 'hostel' => $_POST['hostel']));
                         }
                     }
                     $register = Registration::model()->findByAttributes(array('student_id' => $_POST['student_id']));
                     //var_dump($register->attributes);exit;
                     if ($register != NULL) {
                         $request = Roomrequest::model()->findByAttributes(array('student_id' => $register->student_id, 'status' => 'C'));
                         if ($request != NULL) {
                             $request->status = 'S';
                             $request->save();
                         }
                         $register->status = 'S';
                         $register->save();
                     } else {
                         $model->food_preference = $_POST['Registration']['food_preference'];
                         $model->student_id = $_POST['student_id'];
                         $model->status = 'S';
                     }
                     if ($model->save()) {
                         //$bed_info=Allotment::model()->findAll('status=:x AND student_id=:y',array(':x'=>'C',':y'=>NULL));
                         $bed_info = Allotment::model()->findByAttributes(array('student_id' => NULL, 'status' => 'C'));
                         //var_dump($bed_info->attributes);exit;
                         if ($bed_info == NULL) {
                             $this->redirect(array('/hostel/allotment/roominfo/'));
                         } else {
                             $this->redirect(array('/hostel/room/roomlist', 'id' => $model->student_id, 'floor_id' => $_POST['floor']));
                         }
                     }
                 } else {
                     Yii::app()->user->setFlash('errorMessage', $err_msg);
                 }
             }
         }
     }
     $this->render('create', array('model' => $model));
 }
示例#3
0
 public function actionRoomrequest()
 {
     $model = new Roomrequest();
     if (isset($_REQUEST['studentid']) && isset($_REQUEST['allotid'])) {
         $model->student_id = $_REQUEST['studentid'];
         $model->allot_id = $_REQUEST['allotid'];
         $model->status = 'C';
         $model->created_at = date('Y-m-d H:i:s');
         $model->save();
     }
     $this->render('roomrequest', array('model' => $model, 'floor' => $_REQUEST['floor']));
 }