McGansWebsite/application/controllers/Student.php

154 lines
3.5 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 Student extends CI_Controller {
public function __construct()
{
parent::__construct();
$this->load->model('Student_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 Student_list()
{
$data['stu']=$this->Student_model->list_stu();
$this->load->view('student/Student_list',$data);
}
function add_student()
{
$this->load->view('student/add_student');
if($this->input->post('submit'))
{
$name=$this->input->post('name');
$number=$this->input->post('number');
$address=$this->input->post('address');
$department=$this->input->post('department');
$gender=$this->input->post('gender');
2023-01-06 07:23:42 +00:00
$s_img=$this->input->post('image');
2023-01-05 12:19:39 +00:00
$table="student";
$values=array('name'=>$name,
'number'=>$number,
'address'=>$address,
'department'=>$department,
'gender'=>$gender,
2023-01-06 07:23:42 +00:00
'image'=>$s_img,
2023-01-05 12:19:39 +00:00
'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('student');
}
else
{
$this->session->set_userdata('err','Please try again');
redirect('student');
}
}
}
function edit_student($id)
{
$data['stu']=$this->Student_model->get_stu($id);
$this->load->view('student/edit_student',$data);
if($this->input->post('submit'))
{
$name=$this->input->post('name');
$number=$this->input->post('number');
$address=$this->input->post('address');
$department=$this->input->post('department');
$gender=$this->input->post('gender');
2023-01-06 07:23:42 +00:00
$s_img=$this->input->post('image');
2023-01-05 12:19:39 +00:00
$table="student";
$where=array("id"=>$id);
$values=array('name'=>$name,
'number'=>$number,
'address'=>$address,
'department'=>$department,
'gender'=>$gender,
2023-01-06 07:23:42 +00:00
'image'=>$s_img,
2023-01-05 12:19:39 +00:00
//'update_on'=>date('Y-m-d'),
// 'update_by'=>1,
'status'=>1);
$result=$this->Commonsql_model->updateTable($table,$where,$values);
if($result)
{
$this->session->set_userdata('suc','successfully Updated');
redirect('student');
}
else
{
$this->session->set_userdata('err','Please try again');
redirect('student');
}
}
//echo "sdsd";exit;
//echo $this->db->last_query();exit;
}
function deleted_student()
{
if($this->input->post('submit'))
{
$id=$this->input->post('hiddenpass');
$table="student";
$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('student');
}
else
{
$this->session->set_userdata('err','Please try again');
redirect('student');
}
}
}
}