Created
November 8, 2016 07:26
-
-
Save mirahtadi/9eb734b25d9d1dee2ee21b145f8fc981 to your computer and use it in GitHub Desktop.
Jobs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
application/x-httpd-php JobController.php | |
C++ source, ASCII text | |
<?php | |
class JobController extends Controller { | |
public function filters() { | |
return array( | |
'accessControl - login', | |
); | |
} | |
public function accessRules() { | |
return array( | |
array('allow', | |
'users' => array('*'), | |
'actions' => array('index', 'success', 'error', 'email'), | |
), | |
array('allow', | |
'users' => array('*'), | |
'actions' => array('logout'), | |
), | |
array('deny', | |
'users' => array('*'), | |
) | |
); | |
} | |
public function actionIndex() { | |
$applicant = new Applicant(); | |
if( isset($_POST['Applicant']) ){ | |
$applicant->attributes = $_POST['Applicant']; | |
if($applicant->validate()){ | |
$applicant->save(); | |
$image=CUploadedFile::getInstance($applicant,'image'); | |
// Sending Mail | |
$emailHrd = Yii::app()->params['emailHrd']; | |
$devEmail = Yii::app()->params['emailDeveloper']; | |
$to = "{$applicant->email},{$emailHrd}"; | |
$subject = 'New Application'; | |
$message = $this->renderPartial('/mail/job-success', array('applicant'=>$applicant), true); | |
$headers = 'MIME-Version: 1.0' . "\r\n"; | |
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n"; | |
//$headers .= "To: {$to}". "\r\n"; | |
$headers .= "From: Rip Curl School of Surf <$emailHrd>" . "\r\n"; | |
// attachment | |
$content = file_get_contents($image); | |
$content = chunk_split(base64_encode($content)); | |
// a random hash will be necessary to send mixed content | |
$separator = md5(time()); | |
// carriage return type (RFC) | |
$eol = "\r\n"; | |
$message .= "--" . $separator . $eol; | |
$message .= "Content-Type: application/octet-stream; name=\"" . $image . "\"" . $eol; | |
$message .= "Content-Transfer-Encoding: base64" . $eol; | |
$message .= "Content-Disposition: attachment" . $eol; | |
$message .= $content . $eol; | |
$message .= "--" . $separator . "--"; | |
mail($to, $subject, $message, $headers); | |
$this->redirect($this->createUrl('success')); | |
} | |
} | |
$this->render('index', array( | |
'applicant' => $applicant | |
)); | |
} | |
public function actionSuccess(){ | |
$this->render('success'); | |
} | |
public function actionError() { | |
if ($error = Yii::app()->errorHandler->error) { | |
if (Yii::app()->request->isAjaxRequest) | |
echo $error['message']; | |
else | |
$this->render('error', $error); | |
} | |
} | |
/** | |
* | |
* @param int $id Applicant ID | |
*/ | |
public function actionEmail($id){ | |
$applicant = Applicant::model()->findByPk($id); | |
/* @var $applicant Applicant */ | |
$message = new YiiMailMessage; | |
$message->view = 'booking-success'; | |
$message->setBody(array('applicant'=>$applicant), 'text/html'); | |
$message->addTo($applicant->email, $applicant->firstName); | |
$message->addTo('[email protected]', 'RCSOS Admin'); | |
$message->from = '[email protected]'; | |
Yii::app()->mail->send($message); | |
$this->renderPartial('/mail/job-success', array('applicant'=>$applicant)); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment