public function loadModel($j_id, $c_id)
 {
     $model = JobProfile::model()->findByPk(array('j_id' => $j_id, 'c_id' => $c_id));
     if ($model == null) {
         throw new CHttpException(404, 'The requested page does not exist.');
     }
     return $model;
 }
 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'));
     }
 }