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/ * @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); } 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); } 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(); //$this->load->view('semester/add_semester'); if($this->input->post('submit')) { $name=$this->input->post('name'); $year=$this->input->post('year'); //echo $subjectIdd;exit; //echo $degreeId; $table="semester"; $values=array( 'name'=>$name, 'year'=>$year, 'createdOn'=>date('Y-m-d'), 'createdBy'=>$currentUser, 'status'=>1); $result=$this->Commonsql_model->insert_table($table,$values); $semesterId=$this->db->insert_id(); //echo $this->db->last_query();exit; $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; if($result) { $this->session->set_userdata('suc','successfully added'); redirect('semester'); } else { $this->session->set_userdata('err','Please try again'); redirect('semester'); } } $this->load->view('semester/add_semester',$data); } function editSemester($id) { if($this->session->userdata('id')==""){redirect('');} $currentUser=$this->session->userdata('id'); $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; if($this->input->post('submit')) { $name=$this->input->post('name'); $year=$this->input->post('year'); $table="semester"; $where=array("id"=>$id); $values=array( 'name'=>$name, 'year'=>$year, 'updatedOn'=>date('Y-m-d'), 'updatedby'=>$currentUser); $result=$this->Commonsql_model->updateTable($table,$where,$values); //echo $this->db->last_query();exit; //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); } } if($result) { $this->session->set_userdata('suc','successfully Updated'); redirect('semester'); } else { $this->session->set_userdata('err','Please try again'); redirect('semester'); } } $this->load->view('semester/edit_semester',$data); } function deleteSemester() { if($this->session->userdata('id')==""){redirect('');} $currentUser=$this->session->userdata('id'); if($this->input->post('submit')) { $semesterId=$this->input->post('semesterId'); $table="semester"; $where=array("id"=>$semesterId); $values=array('status'=>0,'updatedOn'=>date('Y-m-d'),'updatedBy'=>$currentUser); $result=$this->Commonsql_model->updateTable($table,$where,$values); $table="semesterdetail"; $where=array("semesterId"=>$semesterId); $values=array('status'=>0); $result=$this->Commonsql_model->updateTable($table,$where,$values); //echo $this->db->last_query();exit; if($result) { $this->session->set_userdata('suc','successfully deleted'); redirect('semester'); } else { $this->session->set_userdata('err','Please try again'); redirect('semester'); } } } }