745212572c
24012023
348 lines
9.2 KiB
PHP
348 lines
9.2 KiB
PHP
<?php
|
|
defined('BASEPATH') OR exit('No direct script access allowed');
|
|
|
|
class Subject extends CI_Controller {
|
|
|
|
public function __construct()
|
|
{
|
|
parent::__construct();
|
|
$this->load->model('Subject_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 subject_list()
|
|
{
|
|
$data['subject']=$this->Subject_model->list_subject();
|
|
$this->load->view('subject/subject_list',$data);
|
|
}
|
|
|
|
public function viewSubject($id)
|
|
{
|
|
if($this->session->userdata('id')==""){redirect('');}
|
|
|
|
$data['viewSubject']=$this->Subject_model->viewSubject($id);
|
|
//echo $this->db->last_query();exit;
|
|
$this->load->view('subject/view_subject',$data);
|
|
}
|
|
|
|
function add_subject()
|
|
{
|
|
$data['degree']=$this->Subject_model->degreeList();
|
|
$data['faculty']=$this->Subject_model->facultyList();
|
|
|
|
|
|
if($this->input->post('submit'))
|
|
{
|
|
$code=$this->input->post('subjectCode');
|
|
$subject=$this->input->post('subject');
|
|
$degree=$this->input->post('degree');
|
|
//$target['tar'] = $this->input->post('tar');
|
|
$faculty=$this->input->post('faculty');
|
|
$description=$this->input->post('description');
|
|
|
|
$faculties = implode(",", (array)$faculty);
|
|
//echo $faculties;exit;
|
|
if (!is_dir('uploads/subject')) {
|
|
mkdir('./uploads/subject', 0777, TRUE);
|
|
}
|
|
|
|
if(file_exists($_FILES['profileImage']['tmp_name']))
|
|
{
|
|
$temp_user_img=$_FILES['profileImage']['tmp_name'];
|
|
$user_img=str_replace(' ', '_', $_FILES["profileImage"]["name"]);
|
|
$allowed = array('png,jpeg,jpg');
|
|
$extension1 = pathinfo($user_img, PATHINFO_EXTENSION);
|
|
$user_img=date('ymdhis').'.'.$extension1;
|
|
$targetPath='./uploads/subject/';
|
|
$targetFile=$targetPath.$user_img;
|
|
move_uploaded_file($temp_user_img, $targetFile);
|
|
}
|
|
|
|
|
|
$table="subject";
|
|
$values=array('code'=>$code,
|
|
'name'=>$subject,
|
|
'degreeId'=>$degree,
|
|
'facultyId'=>$faculties,
|
|
'image'=>$user_img,
|
|
'description'=>$description,
|
|
'createdOn'=>date('Y-m-d'),
|
|
'createdBy'=>1,
|
|
'status'=>1);
|
|
$result=$this->Commonsql_model->insert_table($table,$values);
|
|
|
|
$subjectId=$this->db->insert_id();
|
|
|
|
//Image table insert
|
|
$title = $this->input->post('title');
|
|
|
|
foreach($title as $key=>$value)
|
|
{
|
|
if($_FILES['profileimage']['tmp_name'])
|
|
{
|
|
if (!is_dir('uploads/subject')) {
|
|
mkdir('./uploads/subject', 0777, TRUE);
|
|
}
|
|
$temp_vehicle_doc=$_FILES['profileimage']['tmp_name'][$key];
|
|
$projectImage=str_replace(' ', '_', $_FILES["profileimage"]["name"][$key]);
|
|
$extension1 = pathinfo($projectImage, PATHINFO_EXTENSION);
|
|
$pImage=$subjectId.'.'.$projectImage;
|
|
$document='uploads/subject/'.$pImage;
|
|
|
|
$targetPath = './uploads/subject/';
|
|
$targetFile=$targetPath.$pImage;
|
|
|
|
|
|
if(move_uploaded_file($temp_vehicle_doc, $targetFile))
|
|
{
|
|
$tablename='subjectdetail';
|
|
$data=array('subjectId'=>$subjectId,
|
|
'title'=>$title[$key],
|
|
'image'=>$pImage,
|
|
'status'=>1);
|
|
|
|
$subject=$this->Commonsql_model->insert_table($tablename,$data);
|
|
//echo $this->db->last_query();
|
|
|
|
}
|
|
}
|
|
}
|
|
//exit;
|
|
if($result & $subject)
|
|
{
|
|
$this->session->set_userdata('suc','successfully added');
|
|
redirect('subject');
|
|
|
|
}
|
|
else
|
|
{
|
|
$this->session->set_userdata('err','Please try again');
|
|
redirect('subject');
|
|
}
|
|
|
|
}
|
|
$this->load->view('subject/add_subject',$data);
|
|
}
|
|
|
|
|
|
|
|
function editSubject($id)
|
|
{
|
|
$data['sub']=$this->Subject_model->get_sub($id);
|
|
$data['degree']=$this->Subject_model->degreeList();
|
|
$data['faculty']=$this->Subject_model->facultyList();
|
|
|
|
$data['getMultipleImage']=$this->Subject_model->getMultipleImage($id);
|
|
///echo $this->db->last_query();exit;
|
|
|
|
if($this->input->post('submit'))
|
|
{
|
|
|
|
$code=$this->input->post('code');
|
|
$sub=$this->input->post('subject');
|
|
$degreeId=$this->input->post('degree');
|
|
$semester=$this->input->post('semester');
|
|
$faculty=$this->input->post('faculty');
|
|
$description=$this->input->post('description');
|
|
$image=$this->input->post('image');
|
|
$hiddenImage=$this->input->post('hiddenImage');
|
|
|
|
//print_r ($faculty);
|
|
$faculties = implode(",", (array)$faculty);
|
|
//echo $faculties;exit;
|
|
|
|
if($image==""){$newImage=$hiddenImage;}
|
|
|
|
|
|
if(file_exists($_FILES['image']['tmp_name']))
|
|
{
|
|
$temp_user_img=$_FILES['image']['tmp_name'];
|
|
$newImage=str_replace(' ', '_', $_FILES["image"]["name"]);
|
|
$allowed = array('png,jpeg,jpg');
|
|
$extension1 = pathinfo($newImage, PATHINFO_EXTENSION);
|
|
$newImage=date('ymdhis').'.'.$extension1;
|
|
$targetPath='./uploads/subject/';
|
|
$targetFile=$targetPath.$newImage;
|
|
move_uploaded_file($temp_user_img, $targetFile);
|
|
}
|
|
|
|
$table="subject";
|
|
$where=array("id"=>$id);
|
|
$values=array('code'=>$code,
|
|
'name'=>$sub,
|
|
'degreeId'=>$degreeId,
|
|
'facultyId'=>$faculties,
|
|
'description'=>$description,
|
|
'image'=>$newImage,
|
|
'updatedOn'=>date('Y-m-d'),
|
|
'updatedBy'=>1);
|
|
|
|
$result=$this->Commonsql_model->updateTable($table,$where,$values);
|
|
//echo $this->db->last_query();exit;
|
|
|
|
//Image Multiple
|
|
$title = $this->input->post('title');
|
|
$profileimage = $this->input->post('profileimage');
|
|
$subjectDetailId = $this->input->post('subjectDetailName');
|
|
$oldImage = $this->input->post('profileimageOld');
|
|
//print_r ($subjectDetailId);exit;
|
|
|
|
//Update old datas
|
|
foreach($title as $key=>$value)
|
|
{
|
|
|
|
if($subjectDetailId[$key]!="")
|
|
{
|
|
|
|
if($_FILES['profileimage']['name'][$key])
|
|
{
|
|
$temp_file=$_FILES['profileimage']['tmp_name'][$key];
|
|
$business_doc=str_replace(' ', '_', $_FILES["profileimage"]["name"][$key]);
|
|
$extension1 = pathinfo($business_doc, PATHINFO_EXTENSION);
|
|
$newImage=$id.'.'.$business_doc;
|
|
$document='uploads/subject/'.$newImage;
|
|
|
|
$targetPath = './uploads/subject/';
|
|
$targetFile=$targetPath.$newImage;
|
|
|
|
|
|
if(move_uploaded_file($temp_file, $targetFile))
|
|
{ }
|
|
}
|
|
else{
|
|
$newImage=$oldImage[$key];
|
|
}
|
|
$tablename='subjectdetail';
|
|
$data=array('title'=>$title[$key],
|
|
'image'=>$newImage);
|
|
$where=array('id'=>$subjectDetailId[$key]);
|
|
$result=$this->Commonsql_model->updateTable($tablename,$where,$data);
|
|
//echo $this->db->last_query();
|
|
|
|
}
|
|
}
|
|
//Remove Existing One
|
|
$existingRow=$this->Subject_model->getMultipleImage($id);
|
|
//echo $this->db->last_query();
|
|
if($existingRow->num_rows()>0)
|
|
{
|
|
//echo "test";exit;
|
|
$primaryId=array();
|
|
foreach($existingRow->result() as $list)
|
|
{
|
|
$primaryId[]=$list->id ;
|
|
}
|
|
}
|
|
//Remove Row
|
|
$diff=array_diff($primaryId,$subjectDetailId);
|
|
//print_r ($diff);exit;
|
|
if($diff>0)
|
|
{
|
|
//echo "sdsds";exit;
|
|
foreach($diff as $value)
|
|
{
|
|
$where=array('id'=>$value);
|
|
$tablename="subjectdetail";
|
|
$values=array('status'=>0);
|
|
if($subjectDetailId[$key]!=""){
|
|
$result=$this->Commonsql_model->updateTable($tablename,$where,$values);}
|
|
//echo $this->db->last_query();
|
|
}
|
|
}
|
|
//New Row Insertion
|
|
if($subjectDetailId[$key]=="")
|
|
{
|
|
|
|
if($_FILES['profileimage']['tmp_name'])
|
|
{
|
|
$tempDocument=$_FILES['profileimage']['tmp_name'][$key];
|
|
$getImage=str_replace(' ', '_', $_FILES["profileimage"]["name"][$key]);
|
|
$extension1 = pathinfo($getImage, PATHINFO_EXTENSION);
|
|
$image=$id.'.'.$getImage;
|
|
//$document='uploads/subject/'.$business_document;
|
|
$targetPath = './uploads/subject/';
|
|
$targetFile=$targetPath.$image;
|
|
|
|
|
|
if(move_uploaded_file($tempDocument, $targetFile))
|
|
{
|
|
$tablename='subjectdetail';
|
|
$data=array('subjectId'=>$id,
|
|
'title'=>$title[$key],
|
|
'image'=>$image,
|
|
'status'=>1);
|
|
|
|
$result=$this->Commonsql_model->insert_table($tablename,$data);
|
|
}
|
|
}
|
|
|
|
}
|
|
if($result)
|
|
{
|
|
$this->session->set_userdata('suc','successfully Updated');
|
|
redirect('subject');
|
|
}
|
|
else
|
|
{
|
|
$this->session->set_userdata('err','Please try again');
|
|
redirect('subject');
|
|
}
|
|
}
|
|
|
|
$this->load->view('subject/edit_subject',$data);
|
|
|
|
}
|
|
|
|
|
|
|
|
function deleteSubject()
|
|
{
|
|
if($this->input->post('submit'))
|
|
{
|
|
$subjectId=$this->input->post('subjectId');
|
|
|
|
$table="subject";
|
|
$where=array("id"=>$subjectId);
|
|
$values=array('status'=>0);
|
|
|
|
$dTable="subjectdetail";
|
|
$dWhere=array("subjectId"=>$subjectId);
|
|
$dValue=array('status'=>0);
|
|
|
|
$result=$this->Commonsql_model->updateTable($table,$where,$values);
|
|
if($result)
|
|
{
|
|
$this->session->set_userdata('suc','successfully deleted');
|
|
redirect('subject');
|
|
|
|
}
|
|
else
|
|
{
|
|
$this->session->set_userdata('err','Please try again');
|
|
redirect('subject');
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|