/application/controllers/school.php

https://gitlab.com/exabyte-lab/tiffinbox · PHP · 275 lines · 194 code · 67 blank · 14 comment · 23 complexity · f199808a7d51bc9d699a68ae02cd3edb MD5 · raw file

  1. <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
  2. class School extends CI_Controller {
  3. public function __construct(){
  4. parent:: __construct();
  5. $this->load->model('school_model');
  6. $this->load->library('session');
  7. if(!$this->session->userdata('is_logged')){
  8. redirect('welcome');
  9. }
  10. }
  11. public function index(){
  12. $data['page_title'] = 'Schools :: School management system';
  13. $data['schools']=$this->school_model->getAllschools();
  14. $this->load->view('include/header',$data);
  15. $this->load->view('school/index');
  16. $this->load->view('include/footer');
  17. }
  18. public function create(){
  19. $data['page_title'] = 'Create School :: School management system';
  20. $this->load->view('include/header',$data);
  21. $this->load->view('school/create');
  22. $this->load->view('include/footer');
  23. }
  24. public function insert(){
  25. $this->form_validation->set_rules('schoolName', 'School Name', 'trim|required|xss_clean');
  26. //check is form data valid of not
  27. if ($this->form_validation->run() == FALSE):
  28. $this->session->set_flashdata('status_wrong',validation_errors() );
  29. $this->create();
  30. else:
  31. if($this->school_model->CreateNewSchool($this->input->post())):
  32. $this->session->set_flashdata('status_right', 'Successfully create new school!');
  33. redirect('school/index');
  34. else:
  35. $this->session->set_flashdata('status_wrong', 'Sorry system is unable to preserve this info!');
  36. redirect('school/create');
  37. endif;
  38. endif;
  39. }
  40. public function update($id=Null){
  41. $data['page_title'] = 'Update Section :: School management system';
  42. $data['school'] = $this->school_model->getSchoolById($id);
  43. $this->load->view('include/header',$data);
  44. $this->load->view('school/update');
  45. $this->load->view('include/footer');
  46. }
  47. public function edit(){
  48. $this->form_validation->set_rules('schoolName', 'School Name', 'trim|required|xss_clean');
  49. //check is form data valid of not
  50. if ($this->form_validation->run() == FALSE):
  51. $this->session->set_flashdata('status_wrong',validation_errors() );
  52. //redirect('school/update/'.);
  53. $this->update($this->input->post('id'));
  54. else:
  55. if($this->school_model->UpdateSchoolById($this->input->post())):
  56. $this->session->set_flashdata('status_right', 'Successfully update section!');
  57. redirect('school/index');
  58. else:
  59. $this->session->set_flashdata('status_wrong', 'There is nothing to update!');
  60. redirect('school/index');
  61. endif;
  62. endif;
  63. }
  64. public function delete($id){
  65. $schoolLogo = $this->db->get_where('schools', array('Id'=>$id))->row()->schoolLogo;
  66. $this->db->delete('schools',array('Id'=>$id));
  67. if($this->db->affected_rows()):
  68. $dir ='./media/schools/'.$schoolLogo;
  69. @unlink($dir);
  70. //remove original file:
  71. $dir ='./media/schools/'.str_replace("_thumb","",$schoolLogo);
  72. @unlink($dir);
  73. $this->session->set_flashdata('status_right', 'Successfully deleted school information!');
  74. redirect('school/index');
  75. else:
  76. $this->session->set_flashdata('status_wrong', 'Sorry system is unable to preserve this info!');
  77. redirect('school/index');
  78. endif;
  79. }
  80. /***
  81. * Branches Part
  82. */
  83. public function branches(){
  84. $data['page_title'] = 'School Branchs :: School management system';
  85. $data['branches'] = $this->school_model->getAllBranches();
  86. $this->load->view('include/header',$data);
  87. $this->load->view('school/branches');
  88. $this->load->view('include/footer');
  89. }
  90. public function createbranch(){
  91. $data['page_title'] = 'Create Branch :: School management system';
  92. $this->load->view('include/header',$data);
  93. $this->load->view('school/createbranch');
  94. $this->load->view('include/footer');
  95. }
  96. public function insertbranch(){
  97. $this->form_validation->set_rules('branchName', 'Branch Name', 'trim|required|xss_clean');
  98. //check is form data valid of not
  99. if ($this->form_validation->run() == FALSE):
  100. $this->session->set_flashdata('status_wrong',validation_errors() );
  101. $this->createbranch();
  102. else:
  103. if($this->school_model->CreateNewBranch($this->input->post())):
  104. $this->session->set_flashdata('status_right', 'Successfully create new branch!');
  105. redirect('school/branches');
  106. else:
  107. $this->session->set_flashdata('status_wrong', 'Sorry system is unable to preserve this info!');
  108. redirect('school/branches');
  109. endif;
  110. endif;
  111. }
  112. public function updatebranch($id){
  113. $data['page_title'] = 'Update Branch :: School management system';
  114. $data['branch'] = $this->school_model->getBranchById($id);
  115. $this->load->view('include/header',$data);
  116. $this->load->view('school/updatebranch');
  117. $this->load->view('include/footer');
  118. }
  119. public function editbranch(){
  120. $this->form_validation->set_rules('branchName', 'Branch Name', 'trim|required|xss_clean');
  121. //check is form data valid of not
  122. if ($this->form_validation->run() == FALSE):
  123. $this->session->set_flashdata('status_wrong',validation_errors() );
  124. $this->updatebranch($this->input->post('id'));
  125. else:
  126. if($this->school_model->updateBranch($this->input->post())):
  127. $this->session->set_flashdata('status_right', 'Successfully update branch!');
  128. redirect('school/branches');
  129. else:
  130. $this->session->set_flashdata('status_wrong', 'Sorry system is unable to preserve this info!');
  131. redirect('school/branches');
  132. endif;
  133. endif;
  134. }
  135. public function deletebranch($id){
  136. if($this->db->delete('branches',array('Id'=>$id))):
  137. $this->session->set_flashdata('status_right', 'Successfully deleted school information!');
  138. redirect('school/branches');
  139. else:
  140. $this->session->set_flashdata('status_wrong', 'Sorry system is unable to preserve this info!');
  141. redirect('school/branches');
  142. endif;
  143. }
  144. /***
  145. * Batch Part
  146. */
  147. public function batch(){
  148. $data['page_title'] = 'School Branchs :: School management system';
  149. $data['batch'] = $this->school_model->getAllBatch();
  150. $this->load->view('include/header',$data);
  151. $this->load->view('school/batch');
  152. $this->load->view('include/footer');
  153. }
  154. public function createbatch(){
  155. $data['page_title'] = 'Create Branch :: School management system';
  156. $this->load->view('include/header',$data);
  157. $this->load->view('school/createbatch');
  158. $this->load->view('include/footer');
  159. }
  160. public function insertbatch(){
  161. $this->form_validation->set_rules('batchYear', 'Batch year', 'trim|required|xss_clean');
  162. //check is form data valid of not
  163. if ($this->form_validation->run() == FALSE):
  164. $this->session->set_flashdata('status_wrong',validation_errors() );
  165. $this->createbatch();
  166. else:
  167. if($this->school_model->CreateNewBatch($this->input->post())):
  168. $this->session->set_flashdata('status_right', 'Successfully create new batch!');
  169. redirect('school/batch');
  170. else:
  171. $this->session->set_flashdata('status_wrong', 'Sorry system is unable to preserve this info!');
  172. redirect('school/batch');
  173. endif;
  174. endif;
  175. }
  176. public function updatebatch($id){
  177. $data['page_title'] = 'Update Batch :: School management system';
  178. $data['batch'] = $this->school_model->getBatchById($id);
  179. $this->load->view('include/header',$data);
  180. $this->load->view('school/updatebatch');
  181. $this->load->view('include/footer');
  182. }
  183. public function editbatch(){
  184. $this->form_validation->set_rules('batchYear', 'Branch year', 'trim|required|xss_clean');
  185. //check is form data valid of not
  186. if ($this->form_validation->run() == FALSE):
  187. $this->session->set_flashdata('status_wrong',validation_errors() );
  188. $this->updatebatch($this->input->post('id'));
  189. else:
  190. if($this->school_model->updateBatch($this->input->post())):
  191. $this->session->set_flashdata('status_right', 'Successfully update batch!');
  192. redirect('school/batch');
  193. else:
  194. $this->session->set_flashdata('status_wrong', 'Sorry system is unable to preserve this info!');
  195. redirect('school/batch');
  196. endif;
  197. endif;
  198. }
  199. public function deletebatch($id){
  200. if($this->db->delete('branches',array('Id'=>$id))):
  201. $this->session->set_flashdata('status_right', 'Successfully deleted school information!');
  202. redirect('school/branches');
  203. else:
  204. $this->session->set_flashdata('status_wrong', 'Sorry system is unable to preserve this info!');
  205. redirect('school/branches');
  206. endif;
  207. }
  208. }