<?php echo ucfirst($guardian->first_name) . ' ' . ucfirst($guardian->last_name); ?> </td> <td colspan="2"> </td> </tr> </tbody> </table> </div> <!-- END div class="profile_details"--> <!-- Document Area --> <div class="document_box"> <div class="document_table"> <?php $documents = StudentDocument::model()->findAllByAttributes(array('student_id' => $student->id)); // Retrieving documents of student with id $_REQUEST['id']; ?> <table width="100%" cellspacing="0" cellpadding="0"> <tbody> <tr> <th><?php echo Yii::t('students', 'Document Name'); ?> </th> </tr> </tbody> </table> <table width="100%" border="0" cellspacing="0" cellpadding="0" style="border-top:none;"> <?php
/** * 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) { $model = StudentDocument::model()->findByPk($id); if ($model === null) { throw new CHttpException(404, 'The requested page does not exist.'); } return $model; }
public function actionDocumentupdate() { $model = StudentDocument::model()->findByAttributes(array('id' => $_REQUEST['document_id'])); //Here $_REQUEST['id'] is student ID and $_REQUEST['document_id'] is document ID $old_model = $model->attributes; //var_dump($old_model);exit; $flag = 1; // If 1, no errors. If 0, some error is present. $valid_file_types = array('image/jpeg', 'image/png', 'application/pdf', 'application/msword', 'text/plain'); // Creating the array of valid file types // Uncomment the following line if AJAX validation is needed // $this->performAjaxValidation($model); if (isset($_POST['StudentDocument'])) { $list = $_POST['StudentDocument']; $model->student_id = $list['student_id']; $model->title = $list['title']; if ($model->title != $old_model['file'] or $_FILES['StudentDocument']['name']['file'] != NULL) { //echo 'dfsd';exit; $model->is_approved = 0; } if ($model->title != NULL and $model->student_id != NULL) { if ($_FILES['StudentDocument']['name']['file'] != NULL) { $extension = end(explode('.', $_FILES['StudentDocument']['name']['file'])); // Get extension of the file $model->file = $this->generateRandomString(rand(6, 10)) . '.' . $extension; // Generate random string as filename $model->file_type = $_FILES['StudentDocument']['type']['file']; $file_size = $_FILES['StudentDocument']['size']['file']; if (in_array($model->file_type, $valid_file_types)) { if ($file_size <= 5242880) { if (!is_dir('uploadedfiles/')) { mkdir('uploadedfiles/'); } if (!is_dir('uploadedfiles/student_document/')) { mkdir('uploadedfiles/student_document/'); } if (!is_dir('uploadedfiles/student_document/' . $model->student_id)) { mkdir('uploadedfiles/student_document/' . $model->student_id); } $temp_file_loc = $_FILES['StudentDocument']['tmp_name']['file']; $destination_file = 'uploadedfiles/student_document/' . $model->student_id . '/' . $model->file; if (move_uploaded_file($temp_file_loc, $destination_file)) { $flag = 1; } else { $flag = 0; Yii::app()->user->setFlash('errorMessage', UserModule::t("File " . $model->file . " was not saved. Please try again.")); } } else { $flag = 0; Yii::app()->user->setFlash('errorMessage', UserModule::t("File size must not exceed 5MB!")); } } else { $flag = 0; Yii::app()->user->setFlash('errorMessage', UserModule::t("Only files with these extensions are allowed: jpg, png, pdf, doc, txt.")); } } else { if ($old_model['file'] != NULL and $list['new_file_field'] == 1) { $flag = 0; Yii::app()->user->setFlash('errorMessage', UserModule::t("No file selected!")); } } } else { $flag = 0; Yii::app()->user->setFlash('errorMessage', UserModule::t("Document Name cannot be empty!")); } if ($flag == 1) { if ($model->save()) { if ($_FILES['StudentDocument']['name']['file'] != NULL) { $old_destination_file = 'uploadedfiles/student_document/' . $model->student_id . '/' . $old_model['file']; if (file_exists($old_destination_file)) { unlink($old_destination_file); } } $this->redirect(array('profile')); } else { Yii::app()->user->setFlash('errorMessage', UserModule::t("Cannot update the document now. Try again later.")); $this->redirect(array('documentupdate', 'id' => $model->student_id, 'document_id' => $_REQUEST['document_id'])); } } else { $this->redirect(array('documentupdate', 'id' => $model->student_id, 'document_id' => $_REQUEST['document_id'])); /*$this->render('update',array( 'model'=>$model,'student_id'=>$_REQUEST['id'] ));*/ } } $this->render('documents/documentupdate', array('model' => $model, 'student_id' => $_REQUEST['id'])); }
<?php } // END Display Error Flash Messages } ?> <div class="emp_tabwrapper"> <?php $this->renderPartial('tab'); ?> <div class="clear"></div> <div class="emp_cntntbx"> <div class="document_table"> <?php $documents = StudentDocument::model()->findAllByAttributes(array('student_id' => $_REQUEST['id'])); // Retrieving documents of student with id $_REQUEST['id']; ?> <table width="100%" cellspacing="0" cellpadding="0"> <tbody> <tr> <th><?php echo Yii::t('students', 'Document Name'); ?> </th> </tr> </tbody> </table> <table width="100%" border="0" cellspacing="0" cellpadding="0" style="border-top:none;"> <?php if ($documents) {