EVOLUTION-NINJA
Edit File: cpd_main.php
<?php namespace App\Controllers\cpd; use App\Controllers\BaseController; use CodeIgniter\RESTful\ResourceController; use CodeIgniter\API\ResponseTrait; use App\Models\Cpd_portfolioModel; use App\Models\cpd_evidenceModel; use Dompdf\Dompdf; use Dompdf\Options; use ZipArchive; class cpd_main extends BaseController { use ResponseTrait; public function __construct() { helper(['form','url']); } public function index() { $dr_id = session()->get('dr_id'); if($dr_id){ return view('cpd/add_case.php'); } else{ return view('login'); } } public function zip() { return view('cpd/testing.php'); $dr_id = session()->get('dr_id'); if($dr_id){ $id = $this->request->getVar('id'); $model1 = new Cpd_portfolioModel(); //$model1->like('created_at','2023'); $model1->where('user_id',$dr_id); $model1->select('id'); $cpd_ids = $model1->get()->getResultArray(); if($cpd_ids){ $zip = new ZipArchive(); $name = 'public/uploads/cpd_data/cpd_evidence' . time() . '.zip'; foreach($cpd_ids as $val1){ $model = new cpd_evidenceModel(); $model->where('cpd_id',$val1['id']); $model->select('*'); $evidence_val = $model->get()->getResultArray(); foreach($evidence_val as $val){ if ($zip->open($name, ZipArchive::CREATE) === TRUE) { foreach($evidence_val as $val){ $filePath = 'public/uploads/cpd_data/'.$val['evidence_name']; $zip->addFile($filePath, 'cpd_data/'.$val['evidence_name']); } } else { echo 'Failed to create or open the ZIP archive.'; } } } } } } public function cpd_evidence_download() { $dr_id = session()->get('dr_id'); if($dr_id){ $year = $_GET['year']; $model1 = new Cpd_portfolioModel(); if($year != 'All'){ $model1->where('year',$year); } $model1->where('user_id',$dr_id); $model1->select('id'); $cpd_ids = $model1->get()->getResultArray(); if($cpd_ids){ $zip = new ZipArchive(); $name = 'public/uploads/cpd_data/cpd_evidence' .$year.time() . '.zip'; foreach($cpd_ids as $val1){ $model = new cpd_evidenceModel(); $model->where('cpd_id',$val1['id']); $model->select('*'); $evidence_val = $model->get()->getResultArray(); foreach($evidence_val as $val){ if ($zip->open($name, ZipArchive::CREATE) === TRUE) { foreach($evidence_val as $val){ $filePath = 'public/uploads/cpd_data/'.$val['evidence_name']; $zip->addFile($filePath, 'cpd_data/'.$val['evidence_name']); } } else { return json_encode(['success' => false]); } } } $zip->close(); return $this->response->download($name, null); } } } public function cpd_activity() { $dr_id = session()->get('dr_id'); $year = ''; if($this->request->getVar('year')){ $year = $this->request->getVar('year'); } else{ $year = 'this_year'; } $data['year'] = $year; if($dr_id){ return view('cpd/cpd_activity_v',$data); } else{ return view('login'); } } // public function cpd_activity() // { // $db = \Config\Database::connect(); // // Fetch data for the PDF from the 'categories' table // $query = $db->table('conference_attend_user')->get(); // $data = $query->getResultArray(); // // Load your HTML view with data // $html = view('cpd/pdf_template', ['data' => $data]); // // Use the Dompdf library to generate PDF // $dompdf = new Dompdf(); // $options = new Options(); // $options->set('isHtml5ParserEnabled', true); // $options->set('isPhpEnabled', true); // $dompdf->setOptions($options); // $dompdf->loadHtml($html); // // (Optional) Set the paper size and orientation // $dompdf->setPaper('A4', 'portrait'); // // Render the HTML as PDF // $dompdf->render(); // // Output the generated PDF (inline or attachment) // $dompdf->stream('downloaded_pdf.pdf', ['Attachment' => 0]); // } public function cpd_dashboard() { $dr_id = session()->get('dr_id'); $model = new Cpd_portfolioModel(); $model->orderBy('created_at','ASC'); $start_val = $model->where('user_id',$dr_id)->first(); $data['start_val'] = $start_val['created_at']; $dt = $start_val['created_at']; $data['start_val'] = date('d-m-Y',strtotime($dt)); $model1 = new Cpd_portfolioModel(); $model1->orderBy('created_at','DESC'); $end_val = $model1->where('user_id',$dr_id)->first(); $dt = $end_val['created_at']; $data['end_val'] = date('d-m-Y',strtotime($dt)); $model1 = new Cpd_portfolioModel(); $model1->select('count(id) as count'); $model1->where('user_id',$dr_id); $value = $model1->where('category','Practice Improvement Activity')->first(); $data['Practice_Improvement_Activity'] = $value['count']; // $lastQuery=$model1->getLastQuery(); // echo $lastQuery; // exit(); $model1 = new Cpd_portfolioModel(); $model1->select('count(id) as count'); $model1->where('user_id',$dr_id); $value = $model1->where('category','Emergency Response Activity')->first(); $data['Emergency_Response_Activity'] = $value['count']; $model1 = new Cpd_portfolioModel(); $model1->select('count(id) as count'); $model1->where('user_id',$dr_id); $value = $model1->where('category','Personal Educational & Skills Activity')->first(); $data['Personal_Educational'] = $value['count']; $model1 = new Cpd_portfolioModel(); $model1->select('count(id) as count'); $model1->where('user_id',$dr_id); $value = $model1->where('section','CNB/Labour/Obstetric Database')->first(); $data['c1'] = $value['count']; $model1 = new Cpd_portfolioModel(); $model1->select('count(id) as count'); $model1->where('user_id',$dr_id); $value = $model1->where('section','Reflective Anaesthesia Logbook')->first(); $data['c2'] = $value['count']; $model1 = new Cpd_portfolioModel(); $model1->select('count(id) as count'); $model1->where('user_id',$dr_id); $value = $model1->where('section','Clinical Audits')->first(); $data['c3'] = $value['count']; $model1 = new Cpd_portfolioModel(); $model1->select('count(id) as count'); $model1->where('user_id',$dr_id); $value = $model1->where('section','Patient Related Experience Measures (PREMs)')->first(); $data['c4'] = $value['count']; $model1 = new Cpd_portfolioModel(); $model1->select('count(id) as count'); $model1->where('user_id',$dr_id); $value = $model1->where('section','Patient Centered Outcome Measures (PCOMs)')->first(); $data['c5'] = $value['count']; $model1 = new Cpd_portfolioModel(); $model1->select('count(id) as count'); $model1->where('user_id',$dr_id); $value = $model1->where('section','PIA Others')->first(); $data['c6'] = $value['count']; $model1 = new Cpd_portfolioModel(); $model1->select('count(id) as count'); $model1->where('user_id',$dr_id); $value = $model1->where('section','Crisis Management Workshops')->first(); $data['d1'] = $value['count']; $model1 = new Cpd_portfolioModel(); $model1->select('count(id) as count'); $model1->where('user_id',$dr_id); $value = $model1->where('section','Emergency Response Seminars')->first(); $data['d2'] = $value['count']; $model1 = new Cpd_portfolioModel(); $model1->select('count(id) as count'); $model1->where('user_id',$dr_id); $value = $model1->where('section','ERA Others')->first(); $data['d3'] = $value['count']; $model1 = new Cpd_portfolioModel(); $model1->select('count(id) as count'); $model1->where('user_id',$dr_id); $value = $model1->where('section','Conferences & Seminars')->first(); $data['e1'] = $value['count']; $model1 = new Cpd_portfolioModel(); $model1->select('count(id) as count'); $model1->where('user_id',$dr_id); $value = $model1->where('section','Workshops')->first(); $data['e2'] = $value['count']; $model1 = new Cpd_portfolioModel(); $model1->select('count(id) as count'); $model1->where('user_id',$dr_id); $value = $model1->where('section','Learning Videos')->first(); $data['e3'] = $value['count']; $model1 = new Cpd_portfolioModel(); $model1->select('count(id) as count'); $model1->where('user_id',$dr_id); $value = $model1->where('section','Exams')->first(); $data['e4'] = $value['count']; $model1 = new Cpd_portfolioModel(); $model1->select('count(id) as count'); $model1->where('user_id',$dr_id); $value = $model1->where('section','Formal Courses')->first(); $data['e5'] = $value['count']; $model1 = new Cpd_portfolioModel(); $model1->select('count(id) as count'); $model1->where('user_id',$dr_id); $value = $model1->where('section','Journal Reading')->first(); $data['e6'] = $value['count']; $model1 = new Cpd_portfolioModel(); $model1->select('count(id) as count'); $model1->where('user_id',$dr_id); $value = $model1->where('section','Learning Sessions')->first(); $data['e7'] = $value['count']; $model1 = new Cpd_portfolioModel(); $model1->select('count(id) as count'); $model1->where('user_id',$dr_id); $value = $model1->where('section','Publications')->first(); $data['e8'] = $value['count']; $model1 = new Cpd_portfolioModel(); $model1->select('count(id) as count'); $model1->where('user_id',$dr_id); $value = $model1->where('section','Research')->first(); $data['e9'] = $value['count']; $model1 = new Cpd_portfolioModel(); $model1->select('count(id) as count'); $model1->where('user_id',$dr_id); $value = $model1->where('section','Presentations')->first(); $data['e10'] = $value['count']; $model1 = new Cpd_portfolioModel(); $model1->select('count(id) as count'); $model1->where('user_id',$dr_id); $value = $model1->where('section','Training and Development')->first(); $data['e11'] = $value['count']; // $model1 = new Cpd_portfolioModel(); // $model1->select('count(id) as count'); // $model1->where('user_id',$dr_id); // $value = $model1->where('section','Training and Development')->first(); // $data['e12'] = $value['count']; if($dr_id){ return view('cpd/cpd_dashboard_v',$data); } else{ return view('login'); } } public function cpd_data() { $db = \Config\Database::connect(); $dr_id = session()->get('dr_id'); $year = $this->request->getVar('year'); if($dr_id){ $model = new Cpd_portfolioModel(); $model->where('user_id',$dr_id); if($year == 'this_year'){ $year_new = date("Y"); // $model->where('year',$year_new); } else if($year != 'All'){ $model->where('year',$year); } $model->select('*'); $details1 = $model->get()->getResultArray(); // $lastQuery=$model->getLastQuery(); // echo $lastQuery; // exit(); $data = array(); foreach($details1 as $key=>$item){ $model1 = new cpd_evidenceModel(); $model1->where('cpd_id',$item['id']); $details2 = $model1->get()->getResultArray(); $evidence = ''; foreach($details2 as $val){ $evidence .= $val['evidence_name'].','; } $item['evidences'] = $evidence; $data[] = $item; } if($data) { return $this->response->setJSON($data); } else { return $this->response->setJSON("no data found"); } } else{ return view('login'); } } public function cpd_delete() { $id = $this->request->getVar('id'); $db = \Config\Database::connect(); $tableName = 'cpd_portfolio'; $query = $db->table($tableName)->where('id', $id); $query->delete(); $affectedRows = $db->affectedRows(); if($affectedRows){ return json_encode(array( 'result' => 1, 'message' => 'Deleted Successfully' )); } else{ return json_encode(array( 'result' => 0, 'message' => 'Error' )); } } public function cpd_evidence_delete() { $id = $this->request->getVar('id'); $db = \Config\Database::connect(); $tableName = 'cpd_evidence'; $query = $db->table($tableName)->where('id', $id); $query->delete(); $affectedRows = $db->affectedRows(); if($affectedRows){ return json_encode(array( 'result' => 1, 'message' => 'Deleted Successfully' )); } else{ return json_encode(array( 'result' => 0, 'message' => 'Error' )); } } public function my_cpd_portfolio() { $dr_id = session()->get('dr_id'); if($dr_id){ $model = new Cpd_portfolioModel(); $model->orderBy('year','ASC'); $start_val = $model->where('user_id',$dr_id)->first(); $data['start_val'] = $start_val['year']; $model1 = new Cpd_portfolioModel(); $model1->orderBy('year','DESC'); $end_val = $model1->where('user_id',$dr_id)->first(); $data['end_val'] = $end_val['year']; // $model2 = new Cpd_portfolioModel(); // $model2->groupBy('year'); // $model2->where('user_id',$dr_id); // $model2->select('year'); // $data['all_val'] = $model2->get()->getResultArray(); $db = \Config\Database::connect(); $builder = $db->table('cpd_portfolio'); $query = $builder->select("COUNT(cpd_evidence.id) as count,cpd_portfolio.year as year"); $query = $builder->join("cpd_evidence", "cpd_evidence.cpd_id = cpd_portfolio.id",'left'); $query = $builder->groupBy('cpd_portfolio.year'); $query = $builder->where('cpd_portfolio.user_id >=',$dr_id); $query = $builder->get(); $data['all_val'] = $query->getResultArray(); return view('cpd/my_cpd_portfolio',$data); } else{ return view('login'); } } public function cpd_edit_form() { $dr_id = session()->get('dr_id'); $cpd_id = $_GET['id']; if($dr_id){ $model = new Cpd_portfolioModel(); $model->where('id',$cpd_id); $data['portfolio_val'] = $model->where('id',$cpd_id)->first(); $model = new cpd_evidenceModel(); $model->where('cpd_id',$cpd_id); $model->select('*'); $data['evidence_val'] = $model->get()->getResultArray(); return view('cpd/edit_cpd_v',$data); } else{ return view('login'); } } public function supporting_evidence() { $dr_id = session()->get('dr_id'); $cpd_id = $_GET['id']; if($dr_id){ $model = new cpd_evidenceModel(); $model->where('cpd_id',$cpd_id); $model->select('*'); $details1 = $model->get()->getResultArray(); if($details1) { return $this->response->setJSON($details1); } else { return $this->response->setJSON("no data found"); } } else{ return view('login'); } } public function add_cpd() { $dr_id = session()->get('dr_id'); if($dr_id){ return view('cpd/add_new_cpd'); } else{ return view('login'); } } public function update_cpd_case(){ $dr_id = session()->get('dr_id'); if($dr_id){ $section_name = $this->request->getVar('section_name'); $category=''; $category_name = $this->request->getVar('category_name'); if($category_name==='Practice_Improvement_Activity'){ $category="Practice Improvement Activity"; } elseif($category_name==='Emergency_Response_Activity'){ $category="Emergency Response Activity"; } elseif($category_name==='Personal_Educational'){ $category="Personal Educational & Skills Activity"; } else { $category=""; } $title = $this->request->getVar('title'); $start_date = $this->request->getVar('start_date'); $end_date = $this->request->getVar('end_date'); $hours = $this->request->getVar('hours'); $cpd_points = $this->request->getVar('cpd_points'); $notes = $this->request->getVar('notes'); $id = $this->request->getVar('id'); $year_arr = explode("-",$this->request->getVar('start_date')); $year = $year_arr[0]; $file_up = $this->request->getFileMultiple('upload_file_data'); $cpd_data = array( 'user_id'=>$dr_id, 'section'=> $section_name, 'category'=> $category, 'title'=> $title, 'start_date'=> $start_date, 'end_date'=> $end_date, 'hours'=> $hours, 'cpd_points'=>$cpd_points, 'year'=>$year, 'notes' =>$notes, ); $model6 = new Cpd_portfolioModel(); $model6->set($cpd_data); $model6->where('id',$id); $updateID = $model6->update(); if($id){ foreach($file_up as $key=>$val){ if($file_up[$key]->getName() != ''){ $newName = $file_up[$key]->getName(); $path = 'public/uploads/cpd_data'; $file_up[$key]->move($path, $newName); $name = $file_up[$key]->getClientName(); $cpd_evidence = array( 'cpd_id'=>$id, 'evidence_name'=> $name, ); $model1 = new cpd_evidenceModel(); $model1->save($cpd_evidence); $insertedID1 = $model1->insertID(); } } return json_encode(array( 'result' => 1, 'message' => 'Cpd data updated Successfully.....', 'msg' => $insertedID )); } else{ return json_encode(array( 'result' => 0, 'message' => 'Something went wrong.....' )); } } else{ return view('login'); } } public function add_cpd_case(){ $dr_id = session()->get('dr_id'); if($dr_id){ $category=''; $category_name = $this->request->getVar('category_name'); if($category_name==='Practice_Improvement_Activity'){ $category="Practice Improvement Activity"; } elseif($category_name==='Emergency_Response_Activity'){ $category="Emergency Response Activity"; } elseif($category_name==='Personal_Educational'){ $category="Personal Educational & Skills Activity"; } else { $category=""; } $section_name = $this->request->getVar('section_name'); $title = $this->request->getVar('title'); $start_date = $this->request->getVar('start_date'); $end_date = $this->request->getVar('end_date'); $hours = $this->request->getVar('hours'); $cpd_points = $this->request->getVar('cpd_points'); $notes = $this->request->getVar('notes'); $year_arr = explode("-",$this->request->getVar('start_date')); $year = $year_arr[0]; $file_up = $this->request->getFileMultiple('upload_file_data'); $cpd_data = array( 'user_id'=>$dr_id, 'category'=> $category, 'section'=> $section_name, 'title'=> $title, 'start_date'=> $start_date, 'end_date'=> $end_date, 'hours'=> $hours, 'cpd_points'=>$cpd_points, 'year'=>$year, 'notes' =>$notes, ); $model = new Cpd_portfolioModel(); $model->save($cpd_data); $insertedID = $model->insertID(); if($insertedID){ foreach($file_up as $key=>$val){ if($file_up[$key]->getName() != ''){ $newName = $file_up[$key]->getName(); $path = 'public/uploads/cpd_data'; $file_up[$key]->move($path, $newName); $name = $file_up[$key]->getClientName(); // echo 'ello'; // die(); $cpd_evidence = array( 'cpd_id'=>$insertedID, 'evidence_name'=> $name, ); $model1 = new cpd_evidenceModel(); $model1->save($cpd_evidence); $insertedID1 = $model1->insertID(); } } return json_encode(array( 'result' => 1, 'message' => 'Cpd data Added Successfully.....', 'msg' => $insertedID )); } else{ return json_encode(array( 'result' => 0, 'message' => 'Something went wrong.....' )); } } else{ return view('login'); } } } ?>