public function actionIndex($confirm = 0) { $this->layout = '//layouts/column1'; if ($confirm) { $this->render('cvconfirm'); } else { $formModel = new JobForm(); $cvModel = new JobCv(); $job = new Job(); $jobProvider = new CActiveDataProvider('Job', array('criteria' => array('condition' => 'active = 1', 'order' => 'category_id ASC, title ASC'), 'pagination' => false)); $jobCategory = JobCategory::model()->findAll(); foreach ($jobProvider->getData() as $data) { $formModel->{$data['id']} = null; } if (isset($_POST['JobForm'])) { $listJob = '<ul>'; $oneChecked = false; foreach ($_POST['JobForm'] as $key => $item) { if (is_numeric($key) && $item == '1') { $oneChecked = true; $jobChecked = Job::model()->findByPk($key); $listJob .= '<li>' . $jobChecked->title . ' (' . $jobChecked->category->name . ')</li>'; } } $listJob .= '</ul>'; $cvModel->date = date('Y-m-d H:i:s'); $cvModel->cv = $_POST['JobCv']['cv']; if (!$oneChecked) { $cvModel->addError('cv', Yii::t('jobModule.common', 'Vous devez cocher au moins un emploi')); } elseif ($cvModel->save()) { foreach ($_POST['JobForm'] as $attribute => $value) { if (is_numeric($attribute) && $value == '1') { $jobId = (int) $attribute; Yii::app()->db->createCommand('INSERT INTO job_job_cv (job_id, job_cv_id) VALUES (:job_id, :job_cv_id)')->execute(array(':job_id' => $jobId, ':job_cv_id' => $cvModel->id)); } } $subject = 'Postulation pour une offre d’emploi'; $body = ' <p>Bonjour,<br/><br/> Vous avez reçu une candidature pour un ou plusieurs emplois à partir du site Web d`Arianne Phosphate Inc.<br/> ' . $listJob . '<br/> <a href="' . $this->createAbsoluteUrl('admincv/read', array('id' => $cvModel->id)) . '">Voir les détails de la candidature</a><br/><br/> </p> '; $attachment = "./" . $cvModel->cvHandler->dir . "/" . Helper::encodeFileName($cvModel->cv); if (($mailerError = Helper::sendMail($this->module->cvEmail, $subject, $body, $attachment)) !== true) { throw new CHttpException(500, $mailerError); } $this->redirect($this->createUrl('index', array('confirm' => 1))); } } $this->render('index', array('jobProvider' => $jobProvider, 'categories' => $jobCategory, 'formModel' => $formModel, 'cvModel' => $cvModel)); } }
?> <?php echo $form->error($model, 'title' . $suffix); ?> </div> <?php } ?> <div class="row"> <?php echo $form->labelEx($model, 'category_id'); ?> <?php echo $form->dropDownList($model, 'category_id', CHtml::listData(JobCategory::model()->findAll(array('order' => 'name ASC')), 'id', 'name'), array('empty' => '')); ?> <?php echo $form->error($model, 'category_id'); ?> </div> <div class="row"> <?php echo $form->labelEx($model, 'type'); ?> <?php echo $form->dropDownList($model, 'type', array(1 => Yii::t('jobModule.admin', 'Permanent'), 2 => Yii::t('jobModule.admin', 'Temps partiel'), 3 => Yii::t('jobModule.admin', 'Saisonnier'), 4 => 'Banque de candidatures'), array('empty' => '')); ?> <?php echo $form->error($model, 'type');
/** * Returns the data model based on the primary key given in the GET variable. * If the data model is not found, an HTTP exception will be raised. * @param integer the ID of the model to be loaded */ public function loadModel($id, $ml = false) { if ($ml && Yii::app()->languageManager->multilang) { $model = JobCategory::model()->multilang()->findByPk($id); } else { $model = JobCategory::model()->findByPk($id); } if ($model === null) { throw new CHttpException(404, 'The requested page does not exist.'); } return $model; }