/**
  * Creates a new MedicalCertificate model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $model = new MedicalCertificate();
     if ($model->load(Yii::$app->request->post())) {
         //send email before saving in DB
         //get student info
         $student_id = $model->student_id;
         $student = Student::findOne($student_id);
         //get student's program
         $program = Program::findOne($student->program_id);
         //get Clinic that produce the Medical Certificate
         $clinic = Clinic::findOne($model->clinic_id);
         //get authorizer info
         $auth = Authorizer::findOne($model->au_id);
         $staff = Staff::findOne($auth->staff_id);
         $value = Yii::$app->mail->compose()->setFrom(array('*****@*****.**' => 'imaprog'))->setTo('*****@*****.**')->setSubject('Medical Certificate')->setHtmlBody('
                 Serial Number: ' . $model->mc_serial . '
                 Student Name: ' . $student->student_name . '
                 Student Matrix: ' . $student->student_matrix . '
                 Student Faculty: ' . $program->program_name . '
                 Problem/Diesease: ' . $model->mc_problem . '
                 Valid From: ' . $model->mc_startdate . '
                 Till: ' . $model->mc_enddate . '
                 Appointmet On: ' . $model->mc_appdate . '
                 Produced By: ' . $clinic->clinic_name . '
                 Authorize By: ' . $staff->staff_name)->send();
         //save into DB
         $model->save();
         //return to view, then proceed with sending email to the lecturers, NotifyEmailController.php
         return $this->redirect(['view', 'id' => $model->mc_id]);
     } else {
         return $this->renderAjax('create', ['model' => $model]);
     }
 }
 /**
  * Creates a new NotifyEmail model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $model = new NotifyEmail();
     if ($model->load(Yii::$app->request->post())) {
         //recepients info
         $rcpt = Staff::findOne($model->staff_id);
         $mc = MedicalCertificate::findOne($model->mc_id);
         $student = Student::findOne($mc->student_id);
         //get student's program
         $program = Program::findOne($student->program_id);
         //get Clinic that produce the Medical Certificate
         $clinic = Clinic::findOne($mc->clinic_id);
         //get authorizer info
         $auth = Authorizer::findOne($mc->au_id);
         $staff = Staff::findOne($auth->staff_id);
         //upload the attachment
         $model->attachment = UploadedFile::getInstance($model, 'attachment');
         if ($model->attachment) {
             $time = time();
             $model->attachment->saveAs('attachments/' . $time . '.' . $model->attachment->extension);
             $model->attachment = 'attachments/' . $time . '.' . $model->attachment->extension;
         }
         if ($model->attachment) {
             //send email with attachment
             $value = Yii::$app->mail->compose()->setFrom(array('*****@*****.**' => 'imaprog'))->setTo('*****@*****.**')->setSubject('Medical Certificate')->setHtmlBody('
                 Dear ' . $rcpt->staff_name . '
                 Your Student Has a Medical Certificate,
                 Serial Number: ' . $mc->mc_serial . '
                 Student Name: ' . $student->student_name . '
                 Student Matrix: ' . $student->student_matrix . '
                 Student Faculty: ' . $program->program_name . '
                 Problem/Diesease: ' . $mc->mc_problem . '
                 Valid From: ' . $mc->mc_startdate . '
                 Till: ' . $mc->mc_enddate . '
                 Appointmet On: ' . $mc->mc_appdate . '
                 Produced By: ' . $clinic->clinic_name . '
                 Authorize By: ' . $staff->staff_name)->attach($model->attachment)->send();
         } else {
             //send email without attachment
             $value = Yii::$app->mail->compose()->setFrom(array('*****@*****.**' => 'imaprog'))->setTo('*****@*****.**')->setSubject('Medical Certificate')->setHtmlBody('
                 Dear ' . $rcpt->staff_name . '
                 Your Student Has a Medical Certificate,
                 Serial Number: ' . $mc->mc_serial . '
                 Student Name: ' . $student->student_name . '
                 Student Matrix: ' . $student->student_matrix . '
                 Student Faculty: ' . $program->program_name . '
                 Problem/Diesease: ' . $mc->mc_problem . '
                 Valid From: ' . $mc->mc_startdate . '
                 Till: ' . $mc->mc_enddate . '
                 Appointmet On: ' . $mc->mc_appdate . '
                 Produced By: ' . $clinic->clinic_name . '
                 Authorize By: ' . $staff->staff_name)->send();
         }
         $model->save();
         return $this->redirect(['view', 'id' => $model->ne_id]);
     } else {
         return $this->render('create', ['model' => $model]);
     }
 }
Esempio n. 3
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = Student::find();
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     $this->load($params);
     if (!$this->validate()) {
         // uncomment the following line if you do not want to return any records when validation fails
         // $query->where('0=1');
         return $dataProvider;
     }
     $query->andFilterWhere(['student_id' => $this->student_id, 'program_id' => $this->program_id, 'campus_id' => $this->campus_id]);
     $query->andFilterWhere(['like', 'student_matrix', $this->student_matrix])->andFilterWhere(['like', 'student_name', $this->student_name])->andFilterWhere(['like', 'student_phone', $this->student_phone])->andFilterWhere(['like', 'student_email', $this->student_email]);
     return $dataProvider;
 }
Esempio n. 4
0
/* @var $model backend\models\MedicalCertificate */
/* @var $form yii\widgets\ActiveForm */
?>

<div class="medical-certificate-form">

    <?php 
$form = ActiveForm::begin();
?>

    <?php 
echo $form->field($model, 'mc_serial')->textInput(['maxlength' => true], ['value' => 'mc_serial']);
?>

    <?php 
echo $form->field($model, 'student_id')->widget(Select2::classname(), ['data' => ArrayHelper::map(Student::find()->all(), 'student_id', 'student_matrix', 'program.program_name'), 'language' => 'en', 'options' => ['placeholder' => 'Insert Student Matrix Number', 'id' => 'matrixNumber'], 'pluginOptions' => ['allowClear' => true]]);
?>

     <?php 
echo "<input type='text' name='show1' id='student_name' size='40' /> ";
?>

     <?php 
echo "<input type='text' name='show2' id='student_email' size='40' /> ";
?>

    <?php 
echo $form->field($model, 'mc_problem')->textInput(['maxlength' => true]);
?>

    <?php 
Esempio n. 5
0
 public function getStudent()
 {
     //a medical certificate has one student
     return $this->hasOne(Student::className(), ['student_id' => 'student_id']);
 }
Esempio n. 6
0
 public function getStudent()
 {
     return $this->hasOne(Student::className(), ['student_id' => 'student_id']);
 }
Esempio n. 7
0
 public function getStudent()
 {
     return $this->hasMany(Student::className(), ['program_id' => 'program_id']);
 }
Esempio n. 8
0
 /**
  * Finds the Student model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return Student the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = Student::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }
Esempio n. 9
0
 public function getStudent()
 {
     return $this->hasMany(Student::className(), ['campus_id' => 'campus_id']);
 }