McGansWebsite/application/controllers/Subject.php

149 lines
3.3 KiB
PHP
Raw Normal View History

2023-01-05 12:19:39 +00:00
<?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['sub']=$this->Subject_model->list_sub();
$this->load->view('subject/subject_list',$data);
}
function add_subject()
{
$this->load->view('subject/add_subject');
if($this->input->post('submit'))
{
$code=$this->input->post('code');
$sub=$this->input->post('subject');
$dep=$this->input->post('department');
$semester=$this->input->post('semester');
$table="subject";
$values=array('code'=>$code,
'subject'=>$sub,
'department'=>$dep,
'semester'=>$semester,
'created_on'=>date('Y-m-d'),
'created_by'=>1,
'status'=>1);
$result=$this->Commonsql_model->insert_table($table,$values);
if($result)
{
$this->session->set_userdata('suc','successfully added');
redirect('subject');
}
else
{
$this->session->set_userdata('err','Please try again');
redirect('subject');
}
}
}
function edit_subject($id)
{
$data['sub']=$this->Subject_model->get_sub($id);
//echo $this->db->last_query();exit;
$this->load->view('subject/edit_subject',$data);
if($this->input->post('submit'))
{
$code=$this->input->post('code');
$sub=$this->input->post('subject');
$dep=$this->input->post('department');
$semester=$this->input->post('semester');
$table="subject";
$where=array("id"=>$id);
$values=array('code'=>$code,
'subject'=>$sub,
'department'=>$dep,
'semester'=>$semester,
'updated_on'=>date('Y-m-d'),
//'update_by'=>1,
'status'=>1);
$result=$this->Commonsql_model->updateTable($table,$where,$values);
//echo $this->db->last_query();exit;
if($result)
{
$this->session->set_userdata('suc','successfully Updated');
redirect('subject');
}
else
{
$this->session->set_userdata('err','Please try again');
redirect('subject');
}
}
}
function deleted_subject()
{
if($this->input->post('submit'))
{
$id=$this->input->post('hiddenpass');
$table="subject";
$where=array("id"=>$id);
$values=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');
}
}
}
}