McGansWebsite/admin/application/controllers/Semester.php

256 lines
6.5 KiB
PHP
Raw Permalink Normal View History

2023-01-05 12:19:39 +00:00
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class Semester extends CI_Controller {
public function __construct()
{
parent::__construct();
$this->load->model('Semester_model');
$this->load->model('Commonsql_model');
}
/**
* Index Page for this controller.
*
* Maps to the following URL
* http://example.com/index.php/welcome
* - or -
* http://example.com/index.php/welcome/index
* - or -
* Since this controller is set as the default controller in
* config/routes.php, it's displayed at http://example.com/
*
* So any other public methods not prefixed with an underscore will
* map to /index.php/welcome/<method_name>
* @see https://codeigniter.com/user_guide/general/urls.html
*/
public function semester_list()
{
if($this->session->userdata('id')==""){redirect('');}
$data['semester']=$this->Semester_model->list_semester();
$this->load->view('semester/semester_list',$data);
2023-01-05 12:19:39 +00:00
}
public function viewSemester($id)
{
if($this->session->userdata('id')==""){redirect('');}
$data['viewSemester']=$this->Semester_model->viewSemester($id);
//echo $this->db->last_query();exit;
$this->load->view('semester/view_semester',$data);
}
2023-01-05 12:19:39 +00:00
function add_semester()
{
if($this->session->userdata('id')==""){redirect('');}
$currentUser=$this->session->userdata('id');
$data['subject']=$this->Semester_model->listSubject();
$data['department']=$this->Semester_model->listDepartment();
$data['degree']=$this->Semester_model->listDegree();
2023-01-05 12:19:39 +00:00
2023-01-06 07:23:42 +00:00
//$this->load->view('semester/add_semester');
2023-01-05 12:19:39 +00:00
if($this->input->post('submit'))
{
$name=$this->input->post('name');
$year=$this->input->post('year');
2023-01-25 12:47:55 +00:00
//echo $subjectIdd;exit;
//echo $degreeId;
2023-01-05 12:19:39 +00:00
$table="semester";
2023-01-25 12:47:55 +00:00
$values=array( 'name'=>$name,
'year'=>$year,
'createdOn'=>date('Y-m-d'),
'createdBy'=>$currentUser,
2023-01-25 12:47:55 +00:00
'status'=>1);
2023-01-05 12:19:39 +00:00
$result=$this->Commonsql_model->insert_table($table,$values);
2023-01-25 12:47:55 +00:00
$semesterId=$this->db->insert_id();
//echo $this->db->last_query();exit;
2023-01-25 12:47:55 +00:00
$subjectId=$this->input->post('subjectId');
$degreeId=$this->input->post('degreeId');
foreach($subjectId as $key=>$value)
{
$SUBJECTID=$subjectId[$key];
$DEGREEID=$degreeId[$key];
$SUBID = implode(",", (array)$SUBJECTID);
//echo $SUBID;
$tablename='semesterdetail';
$data=array('semesterId'=>$semesterId,
'degreeId'=>$DEGREEID,
'subjectId'=>$SUBID,
'status'=>1);
$result=$this->Commonsql_model->insert_table($tablename,$data);
}
//exit;
2023-01-05 12:19:39 +00:00
if($result)
2023-01-25 12:47:55 +00:00
{
$this->session->set_userdata('suc','successfully added');
redirect('semester');
}
else
{
$this->session->set_userdata('err','Please try again');
redirect('semester');
}
2023-01-05 12:19:39 +00:00
}
$this->load->view('semester/add_semester',$data);
2023-01-05 12:19:39 +00:00
}
function editSemester($id)
2023-01-05 12:19:39 +00:00
{
if($this->session->userdata('id')==""){redirect('');}
$currentUser=$this->session->userdata('id');
2023-01-25 12:47:55 +00:00
$data['subject']=$this->Semester_model->listSubject();
$data['degree']=$this->Semester_model->listDegree();
$data['getData']=$this->Semester_model->getSemester($id);
$data['getSemesterDetail']=$this->Semester_model->getSemesterDetail($id);
//echo $this->db->last_query();exit;
2023-01-05 12:19:39 +00:00
if($this->input->post('submit'))
{
$name=$this->input->post('name');
$year=$this->input->post('year');
2023-01-05 12:19:39 +00:00
2023-01-05 12:19:39 +00:00
$table="semester";
$where=array("id"=>$id);
$values=array( 'name'=>$name,
'year'=>$year,
'updatedOn'=>date('Y-m-d'),
'updatedby'=>$currentUser);
2023-01-05 12:19:39 +00:00
$result=$this->Commonsql_model->updateTable($table,$where,$values);
//echo $this->db->last_query();exit;
2023-01-25 12:47:55 +00:00
//Update Old One
$degreeId=$this->input->post('degreeId');
$subjectId=$this->input->post('subjectId');
$semesterDetailId=$this->input->post('semesterDetailName');
foreach($subjectId as $key=>$value)
{
$DEGREEID=$degreeId[$key];
$SEMESTERDETAILID=$semesterDetailId[$key];
$SUBJECTID=$subjectId[$key];
$SUBID = implode(",", (array)$SUBJECTID);
//echo $SUBID;
$tablename='semesterdetail';
$data=array('degreeId'=>$DEGREEID,
'subjectId'=>$SUBID);
$where=array('id'=>$SEMESTERDETAILID);
$result=$this->Commonsql_model->updateTable($tablename,$where,$data);
//Remove Existing One
$existingRow=$this->Semester_model->getSemesterDetail($id);
//echo $this->db->last_query();exit;
if($existingRow->num_rows()>0)
{
//echo "test";exit;
$primaryId=array();
foreach($existingRow->result() as $list)
{
$primaryId[]=$list->id ;
}
}
//Remove Row
$diff=array_diff($primaryId,$semesterDetailId);
//print_r ($diff);exit;
if($diff>0)
{
//echo "sdsds";exit;
foreach($diff as $value)
{
$where=array('id'=>$value);
$tablename="semesterdetail";
$values=array('status'=>0);
if($SEMESTERDETAILID!=""){
$result=$this->Commonsql_model->updateTable($tablename,$where,$values);}
//echo $this->db->last_query();
}
}
//New Row Insertion
if($SEMESTERDETAILID=="")
{
$tablename='semesterdetail';
$data=array('semesterId'=>$id,
'degreeId'=>$DEGREEID,
'subjectId'=>$SUBID,
'status'=>1);
$result=$this->Commonsql_model->insert_table($tablename,$data);
}
}
2023-01-05 12:19:39 +00:00
if($result)
{
$this->session->set_userdata('suc','successfully Updated');
redirect('semester');
}
else
{
$this->session->set_userdata('err','Please try again');
redirect('semester');
}
2023-01-05 12:19:39 +00:00
}
2023-01-25 12:47:55 +00:00
$this->load->view('semester/edit_semester',$data);
2023-01-05 12:19:39 +00:00
}
function deleteSemester()
2023-01-05 12:19:39 +00:00
{
if($this->session->userdata('id')==""){redirect('');}
$currentUser=$this->session->userdata('id');
2023-01-05 12:19:39 +00:00
if($this->input->post('submit'))
{
$semesterId=$this->input->post('semesterId');
2023-01-05 12:19:39 +00:00
$table="semester";
$where=array("id"=>$semesterId);
$values=array('status'=>0,'updatedOn'=>date('Y-m-d'),'updatedBy'=>$currentUser);
2023-01-05 12:19:39 +00:00
$result=$this->Commonsql_model->updateTable($table,$where,$values);
2023-01-25 12:47:55 +00:00
$table="semesterdetail";
$where=array("semesterId"=>$semesterId);
$values=array('status'=>0);
$result=$this->Commonsql_model->updateTable($table,$where,$values);
//echo $this->db->last_query();exit;
2023-01-05 12:19:39 +00:00
if($result)
{
$this->session->set_userdata('suc','successfully deleted');
redirect('semester');
}
else
{
$this->session->set_userdata('err','Please try again');
redirect('semester');
}
2023-01-05 12:19:39 +00:00
}
}
}