[
'class' => AccessControl::class,
'rules' => [
[
'allow' => true,
'roles' => ['@'], // Authenticated users only
],
],
],
'verbs' => [
'class' => VerbFilter::class,
'actions' => [
'logout' => ['post'],
// Add other actions and their HTTP verbs if needed
],
],
];
}
/**
* Lists all TblProjectReports models.
*
* @return string
*/
public function actionIndex()
{
$dataProvider = new ActiveDataProvider([
'query' => TblProjectReports::find(),
'pagination' => [
'pageSize' => 50
],
'sort' => [
'defaultOrder' => [
'id' => SORT_DESC,
]
],
]);
return $this->render('index', [
'dataProvider' => $dataProvider,
]);
}
/**
* Displays a single TblProjectReports model.
* @param int $id ID
* @return string
* @throws NotFoundHttpException if the model cannot be found
*/
public function actionView($id)
{
return $this->render('view', [
'model' => $this->findModel($id),
]);
}
/**
* Creates a new TblProjectReports model.
* If creation is successful, the browser will be redirected to the 'view' page.
* @return string|\yii\web\Response
*/
public function actionCreate()
{
$model = new TblProjectReports();
$project = TblProject::find()->all();
$projectName = ArrayHelper::map($project, 'id', 'projectName');
$exams = TblExams::find()->all();
$examsName = ArrayHelper::map($exams, 'id', 'examName');
if ($this->request->isPost) {
$data = Yii::$app->request->post('TblProjectReports');
$uploadedFile1 = UploadedFile::getInstance($model, 'attech_file_1');
$uploadedFile2 = UploadedFile::getInstance($model, 'attech_file_2');
$user_id = Yii::$app->user->identity->id;
$project_id = $data['project_id'];
$exam_id = $data['exam_id'];
$title = $data['title'];
$description = $data['description'];
$status = $data['status'];
$created_by = Yii::$app->user->identity->id;
$created_at = date('Y-m-d H:i:s');
if ($model->load($this->request->post()) && $model->validate()) {
$filePath1='';
$filePath2='';
if ($uploadedFile1) {
$filePath1 = 'uploads/' . $uploadedFile1->baseName.time(). '_.' . $uploadedFile1->extension;
$uploadedFile1->saveAs($filePath1);
}
if ($uploadedFile2) {
$filePath2 = 'uploads/' . $uploadedFile2->baseName .time(). '_.' . $uploadedFile2->extension;
$uploadedFile2->saveAs($filePath2);
}
$return = Yii::$app->db->createCommand('exec insertCommonDataSP :fields, :values, :table')
->bindValue(':fields', 'user_id,project_id,exam_id,title,description,attech_file_1,attech_file_2,status,created_by,created_at,updated_at')
->bindValue(':values', "'$user_id','$project_id','$exam_id','$title','$description','$filePath1','$filePath2','$created_by','$status','$created_at'")
->bindValue(':table', 'tbl_project_reports')
->execute();
if ($return) {
$data['attech_file_1'] = $filePath1;
$data['attech_file_2'] = $filePath2;
$data['created_at'] = $created_at;
$data['created_by'] = $created_by;
$queryLog=json_encode($data);
CustomeHelper::logGenerate('project report ', 'create', "$queryLog");
Yii::$app->session->setFlash('success', 'Insert successful');
} else {
Yii::$app->session->setFlash('error', 'Insert failed: No rows affected');
}
} else {
Yii::$app->session->setFlash('error', 'Validation failed: ' . implode(', ', $model->getFirstErrors()));
}
} else {
$model->loadDefaultValues();
}
$examsName =[];
return $this->render('create', [
'model' => $model,
'projectName' => $projectName,
'examsName' => [],
]);
}
/**
* Updates an existing TblProjectReports model.
* If update is successful, the browser will be redirected to the 'view' page.
* @param int $id ID
* @return string|\yii\web\Response
* @throws NotFoundHttpException if the model cannot be found
*/
public function actionUpdate($id)
{
$model = $this->findModel($id);
$project = TblProject::find()->all();
$projectName = ArrayHelper::map($project, 'id', 'projectName');
$exams = TblExams::find()->all();
$examsName = ArrayHelper::map($exams, 'id', 'examName');
if ($this->request->isPost) {
$data = Yii::$app->request->post('TblProjectReports');
$user_id = Yii::$app->user->identity->id;
$project_id = $data['project_id'];
$exam_id = $data['exam_id'];
$title = $data['title'];
$description = $data['description'];
$status = $data['status'];
$updated_at = date('Y-m-d H:i:s');
$updated_by = Yii::$app->user->identity->id;
$uploadedFile1 = UploadedFile::getInstance($model, 'attech_file_1');
$uploadedFile2 = UploadedFile::getInstance($model, 'attech_file_2');
if ($model->load($this->request->post()) && $model->validate()) {
$fileFirst='';
$fileSecond='';
if ($uploadedFile1) {
$filePath1 = 'uploads/' . $uploadedFile1->baseName.time(). '_.' . $uploadedFile1->extension;
$uploadedFile1->saveAs($filePath1);
$fileFirst="attech_file_1='$filePath1',";
}
if ($uploadedFile2) {
$filePath2 = 'uploads/' . $uploadedFile2->baseName .time(). '_.' . $uploadedFile2->extension;
$uploadedFile2->saveAs($filePath2);
$fileSecond="attech_file_2='$filePath2',";
}
$sql = "EXEC updateCommonDataSP :updatefields, :where, :table";
<<<<<<< .mine
$return= Yii::$app->db->createCommand($sql, [
':updatefields' => "user_id = '$user_id', project_id = '$project_id',exam_id = '$exam_id',title = '$title' ,description = '$description',$fileFirst $fileSecond status = '$status',updated_at = '$updated_at',updated_by = '$updated_by'",
':where' => "WHERE id = $id",
':table' => 'tbl_project_reports'
])->execute();
if ($return) {
// $data['attech_file_1'] = $fileFirst;
// $data['attech_file_2'] = $fileSecond;
// $data['updated_at'] = $updated_at;
// $data['updated_by'] = $updated_by;
// $queryLog=json_encode($data);
// CustomeHelper::logGenerate('project report ', 'update', "$queryLog");
||||||| .r113
$return= Yii::$app->db->createCommand($sql, [
':updatefields' => "user_id = '$user_id', project_id = '$project_id',exam_id = '$exam_id',title = '$title' ,description = '$description',$fileFirst $fileSecond status = '$status',updated_at = '$updated_at',updated_by = '$updated_by'",
':where' => "WHERE id = $id",
':table' => 'tbl_project_reports'
])->execute();
if ($return) {
$data['attech_file_1'] = $fileFirst;
$data['attech_file_2'] = $fileSecond;
$data['updated_at'] = $updated_at;
$data['updated_by'] = $updated_by;
$queryLog=json_encode($data);
CustomeHelper::logGenerate('project report ', 'update', "$queryLog");
=======
if ($uploadedFile1 and $uploadedFile2 ) {
$return= Yii::$app->db->createCommand($sql, [
':updatefields' => "user_id = '$user_id', project_id = '$project_id', exam_id = '$exam_id', title = '$title', description = '$description', attech_file_1='$filePath1', attech_file_2='$filePath2', status = '$status',updated_at = '$updated_at',updated_by = '$updated_by'",
':where' => "WHERE id = $id",
':table' => 'tbl_project_reports'
])->execute();
}
elseif ($uploadedFile1) {
$return= Yii::$app->db->createCommand($sql, [
':updatefields' => "user_id = '$user_id', project_id = '$project_id', exam_id = '$exam_id', title = '$title', description = '$description', attech_file_1='$filePath1', status = '$status',updated_at = '$updated_at',updated_by = '$updated_by'",
':where' => "WHERE id = $id",
':table' => 'tbl_project_reports'
])->execute();
}
elseif ($uploadedFile2) {
$return= Yii::$app->db->createCommand($sql, [
':updatefields' => "user_id = '$user_id', project_id = '$project_id', exam_id = '$exam_id', title = '$title', description = '$description', attech_file_2='$filePath2', status = '$status',updated_at = '$updated_at',updated_by = '$updated_by'",
':where' => "WHERE id = $id",
':table' => 'tbl_project_reports'
])->execute();
}
else
{
$return= Yii::$app->db->createCommand($sql, [
':updatefields' => "user_id = '$user_id', project_id = '$project_id', exam_id = '$exam_id', title = '$title', description = '$description', status = '$status',updated_at = '$updated_at',updated_by = '$updated_by'",
':where' => "WHERE id = $id",
':table' => 'tbl_project_reports'
])->execute();
}
if ($return) {
$data['attech_file_1'] = isset($filePath1) ? $filePath1 : '';
$data['attech_file_2'] = isset($filePath2) ? $filePath2 : '';
$data['updated_at'] = $updated_at;
$data['updated_by'] = $updated_by;
$queryLog=json_encode($data);
CustomeHelper::logGenerate('project report ', 'update', "$queryLog");
>>>>>>> .r114
Yii::$app->session->setFlash('success', 'Insert successful');
Yii::$app->session->setFlash('success', 'Updated successful');
} else {
Yii::$app->session->setFlash('error', 'Updated failed: No rows affected');
}
} else {
Yii::$app->session->setFlash('error', 'Validation failed: ' . implode(', ', $model->getFirstErrors()));
}
} else {
$model->loadDefaultValues();
}
return $this->render('update', [
'model' => $model,
'projectName'=>$projectName,
'examsName'=>$examsName,
]);
}
/**
* Deletes an existing TblProjectReports model.
* If deletion is successful, the browser will be redirected to the 'index' page.
* @param int $id ID
* @return \yii\web\Response
* @throws NotFoundHttpException if the model cannot be found
*/
public function actionDelete($id)
{
$this->findModel($id)->delete();
return $this->redirect(['index']);
}
/**
* Finds the TblProjectReports model based on its primary key value.
* If the model is not found, a 404 HTTP exception will be thrown.
* @param int $id ID
* @return TblProjectReports the loaded model
* @throws NotFoundHttpException if the model cannot be found
*/
protected function findModel($id)
{
if (($model = TblProjectReports::findOne(['id' => $id])) !== null) {
return $model;
}
throw new NotFoundHttpException('The requested page does not exist.');
}
public function actionAjaxExams($id)
{
$data = "";
if (!empty($id)) {
$examsData = Yii::$app->db->createCommand("EXEC getCommonDataSP :select, :input, :table")
->bindValue(':select', 'id, examName') // Fixed: column names should be comma-separated
->bindValue(':input', "WHERE project_id=$id AND status=1")
->bindValue(':table', 'tbl_exams')
->queryAll();
if (!empty($examsData)) {
foreach ($examsData as $val) {
$data .= "";
}
}
}
return $data;
}
public function actionDeleteFile($id, $file)
{
$model = $this->findModel($id);
if ($model && $model->$file) {
$filePath = Yii::getAlias('@webroot') . '/' . $model->$file;
if (file_exists($filePath)) {
unlink($filePath); // Delete the file from the server
$model->$file = null; // Clear the file attribute in the model
$model->save(false); // Save the model without validation
}
}
return $this->redirect(['update', 'id' => $id]);
}
}