public function actionSave($j_id, $c_id) { if (Yii::app()->session['role'] == 1) { if (!(isset($_POST['cv_id']) && isset($j_id) && isset($c_id))) { Yii::app()->user->setFlash('error', 'Error'); $this->redirect(array('index')); } $studinfo = Student::model()->findByPk(Yii::App()->user->id); $dept = $studinfo->getAttribute("dept"); $cpi = $studinfo->getAttribute("cpi"); $sqlcount = Yii::app()->db->createCommand("select count(*) from job_profile_branches as jpb where j_id =\n " . $j_id . " and c_id = " . $c_id . " and dept = '" . $dept . "'")->queryScalar(); $jobinfo = JobProfile::model()->find('j_id = ? and c_id = ? and CURRENT_TIMESTAMP<deadline', array($j_id, $c_id)); if (count($jobinfo)) { $cutoff = $jobinfo->getAttribute("cpi_cutoff"); if ($sqlcount && $cpi >= $cutoff) { try { $st_id = Yii::App()->user->id; $connection = Yii::App()->db; $sql = "INSERT INTO apply (j_id,c_id,cv_id,st_id) values(:j_id,:c_id,:cv_id,:st_id)"; $command = $connection->createCommand($sql); $command->bindParam(":j_id", $j_id, PDO::PARAM_STR); $command->bindParam(":c_id", $c_id, PDO::PARAM_STR); $command->bindParam(":cv_id", $_POST['cv_id'], PDO::PARAM_STR); $command->bindParam(":st_id", $st_id, PDO::PARAM_STR); $command->execute(); Yii::app()->user->setFlash('success', 'Successfully Applied '); } catch (Exception $e) { Yii::app()->user->setFlash('error', 'You are trying to reapply'); } } else { Yii::app()->user->setFlash('error', 'CPI cutoff not satisfied '); } } else { Yii::app()->user->setFlash('error', 'Deadline has been expired'); } $this->redirect(array('site/index')); } }
public function actionCreate() { $model = new JobProfile(); // uncomment the following code to enable ajax-based validation /* if(isset($_POST['ajax']) && $_POST['ajax']==='job-profile-_form-form') { echo CActiveForm::validate($model); Yii::app()->end(); } */ if (isset($_POST['JobProfile'])) { $model->attributes = $_POST['JobProfile']; echo strtotime($model->deadline); /*echo "<pre>"; print_r($_POST['checkbox_list_name']); echo "</pre>";*/ $model->c_id = Yii::App()->user->id; if ($model->validate()) { // form inputs are valid, do something here $model->save(); $lastTemp = Yii::app()->db->getLastInsertID(); echo $lastTemp; foreach ($_POST['checkbox_list_name'] as $dept) { $model1 = new JobProfileBranches(); $model1->j_id = $lastTemp; $model1->c_id = $model->c_id; $model1->dept = $dept; $model1->save(); } Yii::app()->user->setFlash('success', 'Job Profile Successfully Created. Pending Approval From ADMIN'); $this->redirect(array('company/viewjobprofiles')); return; } } $this->render('_form', array('model' => $model)); }