Advertisement
reignsly

MY_Controller ng PC Req of Antony

Nov 22nd, 2016
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 30.33 KB | None | 0 0
  1. <?php
  2.  
  3. class MY_Controller Extends CI_Controller
  4. {
  5.     protected $layout_view = 'application';
  6.     protected $welcome_view = 'welcome';
  7.     protected $content_view ='';
  8.     protected $view_data = array();
  9.     protected $user;
  10.     protected $userlogin;
  11.     protected $departments;
  12.     protected $user_menus = array();
  13.     protected $disable_layout = FALSE;
  14.     protected $disable_menus = FALSE;
  15.     protected $disable_views = FALSE; //DISABLE THE LOADING OF VIEW - FOR AJAX PURPOSE DEC 11 2013
  16.    
  17.     public function __construct()
  18.     {
  19.         parent::__construct();
  20.        
  21.         $this->output->enable_profiler(ENVIRONMENT == 'development' ? true : false);
  22.                     if(!$this->db_connection->check(true)){
  23.             //update database via browser url : localhost/system/sylver
  24.             show_error('Database Connection Error.');
  25.         }
  26.  
  27.         if(file_exists(BASEPATH . 'core/checkMAC' . EXT) AND file_exists(APPPATH . 'core/checkMAC' . EXT))
  28.         {
  29.             require_once(APPPATH . 'core/checkMAC' . EXT);
  30.            
  31.             /*
  32.              * Check
  33.             */
  34.             if (file_exists(BASEPATH.'core/checkMAC.php'))
  35.             {
  36.                 if (function_exists("getMacLinux") == TRUE)
  37.                 {
  38.                     if(getMacLinux() == "bc:ee:7b:9c:97:0c")
  39.                     {
  40.                
  41.                     }else{
  42.                         die('No direct script access allowed');
  43.                     }
  44.                 }
  45.             }else{
  46.                 die('No direct script access allowed');
  47.             }
  48.         }else{
  49.             exit('The application environment is not set correctly.');
  50.         }
  51.  
  52.         /**
  53.          * Autoload Models
  54.          */
  55.  
  56.         $this->load->model(array(
  57.             'M_settings',
  58.             'M_menus',
  59.             'M_grading_periods',
  60.             'M_departments',
  61.             'M_sys_par',
  62.             'M_open_semesters',
  63.             'M_core_model',
  64.             'M_student_payment_record',
  65.             'M_block_section_settings',
  66.             'M_courses'
  67.         ));  
  68.        
  69.         $this->user = $this->session->userdata('userType');
  70.         $this->userlogin = $this->session->userdata('userlogin');
  71.         $this->userid = $this->session->userdata('userid');
  72.         $this->islogin = $this->session->userdata("logged_in") ? TRUE : FALSE;
  73.         $this->isadmin = strtolower($this->session->userdata('userType')) === "admin" ? TRUE : FALSE;
  74.         $this->view_data['global_message'] = array();
  75.        
  76.         $this->check_system_settings(); // Check the necessary tables to run
  77.         //check system page login if demo
  78.         $this->secure_system_page();
  79.        
  80.         $this->setting  = $this->M_settings->get_settings();
  81.         $this->syspar   = $this->M_sys_par->get_sys_par();
  82.  
  83.         # check if system is turn off
  84.         if($this->syspar->activate_system == "0"){
  85.             echo $this->load->view('welcome/system_off',$this->view_data, true);
  86.             exit(0);
  87.         }
  88.  
  89.         $this->layout_view =  $this->syspar->application_layout ? $this->syspar->application_layout : 'application';
  90.         $this->welcome_view = $this->syspar->welcome_layout ? $this->syspar->welcome_layout : 'welcome';
  91.  
  92.         $this->current_open_semester = $this->cos = $this->M_open_semesters->get_current_semesters();
  93.         $this->set_open_semester(); // `````` set user open semester - used by old codes
  94.  
  95.         $this->departments  = $this->M_departments->get_departments($this->user);
  96.         $this->user_menus = $this->M_menus->get_all_menus($this->user);
  97.         $this->current_grading_period = $this->M_grading_periods->get_current_grading_period();
  98.         $this->view_data['system_message'] = $this->_msg = $this->session->flashdata('system_message');
  99.         $this->view_data['user_menus'] = $um = $this->user_menus;
  100.         $this->view_data['mydepartment'] = $md = $this->departments;
  101.         if($md !== FALSE):
  102.         $this->view_data['restrict_access'] = $this->M_departments->get_restrict_access(@$md->id);
  103.         endif;
  104.         $this->view_data['cheques'] = $this->M_student_payment_record->get_number_of_checks();
  105.  
  106.         $this->view_data['sy_sem_block_sections'] = function ($course_id = false, $year_id = false) { return $this->M_block_section_settings->get_all_block_setions($course_id, $year_id); };
  107.        
  108.         $this->view_data['sy_sem_course'] = function ($year_id = false) { return $this->M_courses->get_courses_with_cf($year_id); };
  109.  
  110.         //Notification
  111.         $this->get_system_notification();
  112.     }
  113.    
  114.     public function _output($output)
  115.   {
  116.         $this->view_data['user_menus'] = $this->user_menus;
  117.         $this->view_data['elapsed_time'] = $this->benchmark->elapsed_time('total_execution_time_start', 'total_execution_time_end');
  118.         $this->view_data['memory_usage'] = ( ! function_exists('memory_get_usage')) ? '0' : round(memory_get_usage()/1024/1024, 2).'MB';
  119.        
  120.     if($this->content_view !== FALSE && empty($this->content_view)){
  121.             $this->content_view = $this->router->class . '/' . $this->router->method;
  122.     }
  123.        
  124.         $yield = file_exists(APPPATH . 'views/' . $this->content_view . EXT) ? $this->load->view($this->content_view, $this->view_data, TRUE) : FALSE ;
  125.        
  126.         if($this->disable_layout == FALSE)
  127.         {
  128.             if($this->layout_view)
  129.             {
  130.                 $this->view_data['yield'] = $yield;
  131.                 $this->view_data['disable_menus'] = $this->disable_menus;
  132.                 if($this->disable_views == false){
  133.                     echo $this->load->view('layouts/' . $this->layout_view, $this->view_data, TRUE);
  134.                 }
  135.             }else{
  136.                 if($this->disable_views == false){
  137.                     echo $yield;
  138.                 }
  139.             }
  140.         }else{
  141.             if($this->disable_views == false){
  142.                 echo $this->load->view($this->content_view, $this->view_data, TRUE);
  143.             }
  144.         }
  145.        
  146.         if($this->disable_views == false){
  147.             //output profiler
  148.             echo $output;
  149.         }
  150.   }
  151.    
  152.     // CHECK SYSTEM SETTINGS AND SYSPAR
  153.     private function check_system_settings(){
  154.  
  155.         if($this->db->table_exists('settings') == false){
  156.             show_error('System settings is missing, please contact your provider');
  157.         }
  158.  
  159.         if($this->db->table_exists('sys_par') == false){
  160.             show_error('System Parameter is missing, please contact your provider');   
  161.         }
  162.  
  163.         #load models
  164.         $this->load->model(array('M_settings','M_menus','M_grading_periods','M_departments','M_sys_par','M_open_semesters','M_academic_years','M_semesters'));
  165.  
  166.         if($this->M_sys_par->get_sys_par() == false){
  167.             show_error('System Parameter is not properly configured, please contact your provider');   
  168.         }
  169.  
  170.         #check if usertype / department active - additional security
  171.         if(isset($this->session->userdata['logged_in']) && $this->session->userdata['logged_in']){
  172.             $role = $this->M_departments->pull(array('department'=>$this->user),'visible');
  173.  
  174.             if($role && $role->visible == "1"){
  175.                
  176.             }else{
  177.                 $this->session->sess_destroy();
  178.                 redirect('auth/logout');
  179.             }
  180.  
  181.             unset($get);
  182.             $get['fields'] = "id";
  183.             $get['single'] = true;
  184.            
  185.             //Check academic year
  186.             if(!$this->M_academic_years->get_record(false, $get)){
  187.                 $this->view_data['global_message'][] = "No record for 'Academic Year or School Year' found.";
  188.             }
  189.  
  190.             //Check M_semesters
  191.             if(!$this->M_semesters->get_record(false, $get)){
  192.                 $this->view_data['global_message'][] = "No record for 'Semester' found.";
  193.             }
  194.  
  195.             //Check M_grading_periods
  196.             if(!$this->M_grading_periods->get_record(false, $get)){
  197.                 $this->view_data['global_message'][] = "No record for 'Grading Period' found.";
  198.             }else{
  199.                 //check if there is current grading period set
  200.                 if(!$this->M_grading_periods->get_current_grading_period()){
  201.                     // $this->view_data['global_message'][] = "No 'Current Grading Period' set.";
  202.                 }
  203.             }
  204.  
  205.             //Check M_open_semesters
  206.             if(!$this->M_open_semesters->get_record(false, $get)){
  207.                 $this->view_data['global_message'][] = "No record for 'Open Semester' found.";
  208.             }else{
  209.                 //check if there is open semester set
  210.                 if(!$this->M_open_semesters->get_current_semesters()->system){
  211.                     $this->view_data['global_message'][] = "No current 'Open Semester Set'.";
  212.                 }
  213.             }
  214.         }
  215.     }
  216.  
  217.     /**
  218.      * Get System Notifications
  219.      */
  220.     public function get_system_notification()
  221.     {
  222.         $n = false;
  223.  
  224.         // $n = array(
  225.         //      'title' => '',
  226.         //      'muted' => '',
  227.         //      'url' => '',
  228.         //      'msg' => ''
  229.         //  );
  230.  
  231.         //check if enrollment open - for admin only
  232.         if($this->islogin && $this->isadmin){
  233.            
  234.             if($this->cos->enrollment){
  235.                 $e = $this->cos->enrollment;
  236.                 $n[] = array(
  237.                         'title' => "Enrollment",
  238.                         'muted' => "Reminder",
  239.                         'msg'   => "Enrollment is currently Open for <strong> School Year $e->school_year , $e->semester </strong>",
  240.                         'url'   => site_url('open_semester')
  241.                     );
  242.             }
  243.         }
  244.  
  245.         //check if user open semester is equal to the system open semester
  246.         if($this->islogin){
  247.             $s = $this->cos->system;
  248.             $u = $this->cos->user;
  249.            
  250.             if($u && $s && ($u->open_semester_id != $s->open_semester_id)){
  251.                 $n[] = array(
  252.                         'title' => "Open Semester",
  253.                         'muted' => "Warning",
  254.                         'url'       => site_url('open_semester_employee_settings'),
  255.                         'msg'   => "Please note that <strong>your open semester</strong> is <i>different</i> from the <strong>system open semester</strong>."
  256.                     );
  257.                 $this->view_data['global_message'][] = "You are currently viewing S.Y. $u->year_from - $u->year_to, $u->semester.";
  258.             }
  259.         }
  260.  
  261.         $this->view_data['bar_notification'] = $n;
  262.     }
  263.  
  264.     function issue_count($user_id)
  265.     {
  266.       $count = 0;
  267.         $this->load->model(array('M_issues'));
  268.       // Count Issues
  269.       $issues = $this->M_issues->count_all_by_user_id($user_id);
  270.       if (!empty($issues)) {
  271.         $count += intval($issues) ;
  272.       }
  273.      
  274.       $this->view_data['total_issues'] = $count;
  275.     }
  276.    
  277.     function pagination_style()
  278.     {
  279.         // Style
  280.       $config['full_tag_open'] = '<ul class="pagination pagination-sm">';
  281.       $config['full_tag_close'] = '</ul>';
  282.       $config['prev_link'] = '&lt; Prev';
  283.       $config['prev_tag_open'] = '<li>';
  284.       $config['prev_tag_close'] = '</li>';
  285.       $config['next_link'] = 'Next &gt;';
  286.       $config['next_tag_open'] = '<li>';
  287.       $config['next_tag_close'] = '</li>';
  288.       $config['cur_tag_open'] = '<li class="active"><a href="#">';
  289.       $config['cur_tag_close'] = '</a></li>';
  290.       $config['num_tag_open'] = '<li>';
  291.       $config['num_tag_close'] = '</li>';
  292.       $config['first_link'] = FALSE;
  293.       $config['last_link'] = FALSE;
  294.      
  295.       return $config;
  296.      
  297.     }
  298.    
  299.     /*
  300.         CHECK IF CURRENT URL IS INCLUDED IN THE MENU LIST ACCESIBLE BY THE DEPARTMENT
  301.         OVER_RIDE (controller/method/param)  - ADD ACCESS IF THE GIVEN STRING OR ARRAY IS IN THE DEPARTMENT (controller) MENU LIST
  302.         This method should not be in the construct method of your controller
  303.         Put specific menu or the over_ride
  304.     */
  305.     function menu_access_checker($over_ride = false)
  306.     {  
  307.         $pass = false;
  308.        
  309.         $this->session_checker->check_if_alive();
  310.        
  311.         if($this->user_menus)
  312.         {
  313.  
  314.             $pass = $this->check_department_menu_list();
  315.            
  316.             if($pass)
  317.             {              
  318.                 //PAGE IS ACCESIBLE
  319.             }
  320.             else
  321.             {
  322.                 //CHECK OVER_RIDE
  323.                 if($over_ride)
  324.                 {
  325.                     $pass = $this->check_over_ride_menu_list($over_ride);
  326.                 }
  327.             }
  328.         }
  329.         // vd($over_ride);
  330.         if(!$pass)
  331.         {
  332.             show_error("<div class='' style='color:red'><h4><span class = 'glyphicon glyphicon-ban-circle'></span>&nbsp;  Sorry, you dont have access to this page.</h4></div>", 404);
  333.         }
  334.     }
  335.    
  336.    
  337.     /*
  338.         @uri_string - contains controll/method/param
  339.     */
  340.     function check_over_ride_menu_list($over_ride = false)
  341.     {
  342.         $pass = false;
  343.        
  344.         if(!$over_ride) { return false; }
  345.        
  346.         if(is_array($over_ride)){
  347.             foreach($this->user_menus as $menu){
  348.                 $controller = $menu->controller;
  349.                 $arr_con = explode('/', $menu->controller);
  350.                 if(count($arr_con) == 1){
  351.                     $controller .= "/index";
  352.                 }
  353.                 foreach($over_ride as $val){
  354.  
  355.                     $arr_con2 = explode('/', $val);
  356.                     if(count($arr_con2) == 1){
  357.                         $val .= "/index";
  358.                     }
  359.  
  360.                     if($val == $controller){
  361.                         $pass = true;
  362.                         break;
  363.                     }
  364.                 }
  365.                 if($pass){
  366.                     break;
  367.                 }
  368.             }
  369.         }
  370.         else if(is_string($over_ride))
  371.         {
  372.             foreach($this->user_menus as $menu){               
  373.  
  374.                 $controller = $menu->controller;
  375.                 $arr_con = explode('/', $menu->controller);
  376.                 if(count($arr_con) == 1){
  377.                     $controller .= "/index";
  378.                 }
  379.  
  380.                 $arr_con2 = explode('/', $over_ride);
  381.                 if(count($arr_con2) == 1){
  382.                     $over_ride .= "/index";
  383.                 }
  384.  
  385.                 if($over_ride == $controller){
  386.                     $pass = true;
  387.                     break;
  388.                 }
  389.             }
  390.         }
  391.        
  392.         return $pass;
  393.     }
  394.    
  395.     function check_department_menu_list()
  396.     {
  397.         $pass = false;
  398.         // vd($this->uri);
  399.         // vd($this->router);
  400.         foreach($this->user_menus as $menu)
  401.         {
  402.             if($menu->visible == 1 && $menu->menu_lvl == 2)
  403.             {
  404.                 $arr_con = explode('/', $menu->controller);
  405.                
  406.                 switch(count($arr_con))
  407.                 {
  408.                     case 1:
  409.                         //MEANS METHOD IS INDEX
  410.                         if($arr_con[0] == $this->router->class
  411.                         && "index" == $this->router->method){
  412.                             $pass = true;
  413.                         }
  414.                     break;
  415.                     case 2:
  416.                         if($arr_con[0] == $this->router->class
  417.                         && $arr_con[1] == $this->router->method){
  418.                             $pass = true;
  419.                         }
  420.                     break;
  421.                     case 3:
  422.                         if($arr_con[0] == $this->router->class
  423.                         && $arr_con[1] == $this->router->method
  424.                         && $arr_con[2] == $this->uri->segment(3)){
  425.                             $pass = true;
  426.                         }
  427.                     break;
  428.                    
  429.                 }
  430.                
  431.                 if($pass)
  432.                 {
  433.                     break;
  434.                 }
  435.             }
  436.         }
  437.        
  438.         return $pass;
  439.     }
  440.  
  441.  
  442.     function check_the_active_menu($controller = false)
  443.     {
  444.         if($controller)
  445.         {
  446.             $pass = false;
  447.  
  448.             $arr_con = explode('/', $controller);
  449.                    
  450.             switch(count($arr_con))
  451.             {
  452.                 case 1:
  453.                     //MEANS METHOD IS INDEX
  454.                     if($arr_con[0] == $this->router->class){
  455.                         $pass = true;
  456.                     }
  457.                 break;
  458.                 case 2:
  459.                     if($arr_con[0] == $this->router->class
  460.                     && $arr_con[1] == $this->router->method){
  461.                         $pass = true;
  462.                     }
  463.                 break;
  464.                 case 3:
  465.                     if($arr_con[0] == $this->router->class
  466.                     && $arr_con[1] == $this->router->method
  467.                     && $arr_con[2] == $this->uri->segment(3)){
  468.                         $pass = true;
  469.                     }
  470.                 break;
  471.                
  472.             }
  473.            
  474.             if($pass)
  475.             {
  476.                 break;
  477.             }
  478.         }
  479.        
  480.         return $pass;
  481.     }
  482.    
  483.     /*
  484.         SLY
  485.         @PARAM - string LIKE profile, grade,
  486.         CHECKS WHETHER THE DEPARTMENT HAS ACCESS TO STUDENT DATA GIVEN IN THE PARAMETER
  487.     */
  488.     function check_student_profile_access($par = false)
  489.     {
  490.         $xfld = "";
  491.         $xaccess = 0;
  492.         if($par)
  493.         {
  494.             switch($par)
  495.             {
  496.                 case "profile":
  497.                     $xaccess = $this->departments->stud_profile;
  498.                 break;
  499.                 case "grade":
  500.                     $xaccess = $this->departments->stud_grade;
  501.                 break;
  502.                 case "fees":
  503.                     $xaccess = $this->departments->stud_fees;
  504.                 break;
  505.                 case "transcript":
  506.                 case "otr":
  507.                     $xaccess = $this->departments->stud_otr;
  508.                 break;
  509.                 case "issues":
  510.                     $xaccess = $this->departments->stud_issues;
  511.                 break;
  512.                 default:
  513.                     $xaccess = 0;
  514.                 break;
  515.             }
  516.         }
  517.        
  518.         if($xaccess == 0)
  519.         {
  520.             show_error("<div class='' style='color:red'><h4><span class = 'glyphicon glyphicon-ban-circle'></span>&nbsp;  Sorry, you dont have access to this page. Go back to <a class='btn btn-info' href='".base_url()."home'>HOME</a></h4></div>", 404);
  521.         }
  522.     }
  523.  
  524.     /**
  525.      * Check Department Access to Student Profile
  526.      * @param string $field Field in the database to check
  527.      */
  528.     public function check_stud_access($field)
  529.     {
  530.         if(isset($this->departments->$field)){
  531.             if($this->departments->$field !== "1"){
  532.                 show_error("<div class='' style='color:red'><h4><span class = 'glyphicon glyphicon-ban-circle'></span>&nbsp;  Sorry, you dont have access to this page. Go back to <a class='btn btn-info' href='".base_url()."home'>HOME</a></h4></div>", 404);
  533.             }
  534.         }else{
  535.             show_404();
  536.         }
  537.     }
  538.  
  539.     /**
  540.      * Check User Access To Student Profile Menus (Profile, Grade, View Fees, Transcript, Issues, Subjects)
  541.      */
  542.     public function check_access_studentprofile_menu()
  543.     {
  544.         $this->menu_access_checker(array(
  545.             'search/search_student',
  546.             'search/student',
  547.             'enrollees/daily_enrollees',
  548.             'search/master_list_by_course',
  549.             'search/search_enrollee',
  550.             'search/list_students/paid',
  551.             'search/list_students/unpaid',
  552.             'search/list_students/fullpaid',
  553.             'search/list_students/partialpaid',
  554.             'fees/view_fees',
  555.         ));
  556.     }
  557.  
  558.     /**
  559.      * Check or get id of a hash string usually a table id
  560.      * @param string $hash
  561.      * @param bool $show_error - show_404 if false
  562.      */
  563.     public function check_hash($hash, $show_error = true){
  564.         $x = $this->hs->decrypt($hash);
  565.        
  566.         if($x){
  567.             return $x[0];
  568.         }
  569.         else{
  570.             if($show_error === true){
  571.                 show_404();
  572.             }else{
  573.                 return false;
  574.             }
  575.         }
  576.     }
  577.  
  578.     /**
  579.      * Check Record - usually used to validate if record or id passed in url has data
  580.      */
  581.     public function check_rec($rec)
  582.     {
  583.         if($rec){}
  584.         else{show_404();}
  585.     }
  586.  
  587.     function _msg($type = FALSE,$message = FALSE,$redirect = FALSE,$var_name = 'system_message')
  588.     {
  589.         $template = "";
  590.         $type = strtolower(trim($type));
  591.         switch($type)
  592.         {
  593.             case $type == 'e':
  594.                 $template = "<div class='alert alert-danger'><h4><i class='fa fa-warning'></i> Error!</h4> <span style='padding-left:2em'>".$message."</span><span style='float:right;' class='glyphicon glyphicon-remove sys_m_close'></span></div>";
  595.             break;
  596.             case $type == 's':
  597.                 $template = "<div class='alert alert-success'><h4><i class='fa fa-check'></i> Success!</h4> <span style='padding-left:2em'>".$message."</span><span style='float:right;' class='glyphicon glyphicon-remove sys_m_close'></span></div>";
  598.             break;
  599.             case $type == 'w':
  600.                 $template = "<div class='alert alert-warning'><h4><i class='fa fa-warning'></i> Warning!</h4> <span style='padding-left:2em'>".$message."</span><span style='float:right;' class='glyphicon glyphicon-remove sys_m_close'></span></div>";      
  601.             break;
  602.             case $type == 'n':
  603.                 $template = "<div class='alert alert-info'><i class='fa fa-check'></i>&nbsp; ".$message."<span style='float:right;' class='glyphicon glyphicon-remove sys_m_close'></span></div>";
  604.             break;
  605.             case $type == 'p':
  606.                 $template = $message;
  607.             break;
  608.             case $type === FALSE;
  609.                 $template = $message;
  610.             break;
  611.         }
  612.        
  613.         if($type AND $message AND $redirect)
  614.         {
  615.             $this->session->set_flashdata($var_name,$template);
  616.             redirect($redirect);
  617.         }elseif($type AND $message AND $redirect == FALSE){
  618.             return $template;
  619.         }
  620.        
  621.         if($redirect == FALSE AND $message == FALSE AND $redirect == FALSE)
  622.         {
  623.             return $this->session->flashdata($var_name);
  624.         }
  625.     }
  626.  
  627.     /**
  628.      * Redirect with MSG
  629.      * Eliminate the if else
  630.      * @param boolean $status true/false - success or failed
  631.      * @param string $url - redirect to
  632.      * @param string $s_msg - success msg
  633.      * @param string $f_msg - fail message
  634.      * @param array $log - Save activity log
  635.      */
  636.     public function __msg($status, $url, $s_msg, $f_msg = false, $log = false)
  637.     {
  638.         $f_msg = $f_msg ? $f_msg : "Transaction failed, please try again";
  639.         $msg = $status ? $s_msg : $f_msg;
  640.         $code = $status ? "s" : 'e';
  641.  
  642.         //save activity log
  643.         if($log){
  644.             $log = (object)$log;
  645.             activity_log($log->activity, false, $log->log);
  646.         }
  647.  
  648.         $this->_msg($code, $msg, $url);
  649.     }
  650.  
  651.     function check_if_already_logged_in()
  652.     {
  653.         if($this->islogin === TRUE)
  654.         {
  655.             redirect('home');
  656.         }
  657.     }
  658.  
  659.     /**
  660.         * CLONE SCHOOL YEAR RECORD - Copy and change the academic year id of the ff: subjects, room, block_sections
  661.         * @new_sy_id = new academic_year_id
  662.         * @prev_sy_id = copy from this academic_year_id, if false it will detect
  663.         */
  664.     function clone_sy_data($new_sy_id = false, $prev_sy_id = false){
  665.             $this->load->model(array('M_academic_years','M_rooms','M_subjects',"M_block_section_settings",'M_open_semesters','M_coursefinances'));
  666.  
  667.             $this->M_rooms->cloned_rooms_from_previous_sy($new_sy_id, $prev_sy_id);
  668.             // $this->M_subjects->cloned_subjects_from_previous_sy($new_sy_id,$prev_sy_id);
  669.             // $this->M_block_section_settings->cloned_blocks_from_previous_sy($new_sy_id, $prev_sy_id);
  670.             $this->M_coursefinances->cloned_coursefinance_from_previous_sy($new_sy_id, $prev_sy_id);
  671.     }
  672.  
  673.     /* ARRANGE RECORD TO ALPHABETICAL
  674.         @record - data list to be arrange
  675.         @field - what field will be arrange
  676.         @order - desc or asc, default is asc
  677.         result will look like this
  678.         $result['0'][0]
  679.         $result['1'][0]
  680.         $result['a'][0]
  681.         $result['b'][0]
  682.         $result['c'][0] etc etc
  683.      */
  684.     function sort_data_alpha($record = false, $field = false, $order = 'ASC'){
  685.  
  686.             $alphabet = array('0','1','2','3','4','5','6','7','8','9','a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z');
  687.    
  688.             $alphabet_array = array();
  689.             //GENERATE AND ARRANGE ARRAY OF SUBJECTS
  690.             if($record){
  691.                     foreach($record as $key => $value){
  692.                         if($value != null){
  693.                             $word = trim($value->$field);
  694.                            
  695.                         if($word != ""){
  696.                             $f_letter = strtolower($word[0]);
  697.                             $pass = 0;
  698.                             $pass2 = 0;
  699.                             if($order == "ASC"){
  700.                                 foreach($alphabet as $letter)
  701.                                 {
  702.                                     $pass2++;
  703.                                     if($letter == $f_letter)
  704.                                     {
  705.                                         $alphabet_array[$letter][$key] = $value;
  706.                                         $pass++;
  707.                                         break;
  708.                                     }
  709.                                 }
  710.                             }
  711.                             // if($order == "DESC"){
  712.  
  713.                             //  for($x = count($alphabet); $x >=0; $x--){
  714.                             //      $pass2++;
  715.  
  716.                             //      if(isset($alphabet[$x])){
  717.  
  718.                             //          if($alphabet[$x] == $f_letter){
  719.  
  720.                             //              $alphabet_array[$alphabet[$x]][$key] = $value;
  721.                             //              $pass++;
  722.                             //              break;
  723.                             //          }
  724.                             //      }
  725.                             //  }
  726.                             // }
  727.                             //NO Category
  728.                             if($pass == 0 && $pass2 > 0){
  729.                                 $alphabet_array['others'][$key] = $value;
  730.                             }
  731.                         }
  732.                     }
  733.                 }
  734.             }
  735.             ksort($alphabet_array);
  736.             // vd($alphabet_array);
  737.             return $alphabet_array;
  738.     }
  739.  
  740.     /**
  741.      * Set Open Semester Variable
  742.      * Used by old codes
  743.      */
  744.     public function set_open_semester()
  745.     {
  746.         unset($os);
  747.         $os['id'] = 0;
  748.         $os['year_from'] = "";
  749.         $os['year_to'] = "";
  750.  
  751.         if($this->cos->user){
  752.            
  753.             $os['id'] = $this->cos->user->open_semester_id;
  754.             $os['open_semester_id'] = $this->cos->user->open_semester_id;
  755.             $os['semester_id'] = $this->cos->user->semester_id;
  756.             $os['academic_year_id'] = $this->cos->user->academic_year_id;
  757.             $os['year_from'] = $this->cos->user->year_from;
  758.             $os['year_to'] = $this->cos->user->year_to;        
  759.             $os['name'] = $this->cos->user->semester;          
  760.         }
  761.         $this->open_semester = (object)$os;
  762.     }
  763.  
  764.     /**
  765.      * Secure system page if demo
  766.      */
  767.     public function secure_system_page()
  768.     {
  769.         if($this->session->userdata("logged_in") == FALSE){
  770.             if($this->router->class != "logout" && $this->router->class != "auth" && $this->router->class != "welcome"){
  771.                 $this->session->set_flashdata('system_message', 'Please login.');
  772.                 redirect('logout');
  773.             }
  774.         }
  775.        
  776.         if(ENVIRONMENT === "demo"){
  777.            
  778.             if(isset($this->session->userdata['system_logged_in']) && $this->session->userdata['system_logged_in'] === TRUE){
  779.  
  780.                 $this->load->model('M_system_users');
  781.                 $u = $this->M_system_users->get_user($this->session->userdata['system_userid']);
  782.                 if(!$u){
  783.                     redirect('system_page_auth/logout');
  784.                 }
  785.                 $expiration = $u->expiration ? "(Expiration : ".date('M d, Y g:i a',strtotime($u->expiration)).")" : "";
  786.                 $this->load->helper(['time']);
  787.  
  788.                 //check if expired
  789.                 if($u->expiration){
  790.                     if(_check_time_expired($u->expiration)){
  791.  
  792.                         $this->session->set_flashdata('system_message','You demo account has already expired. Thank you for using our demo school system.');
  793.                         redirect('system_page_auth/logout');
  794.                     }
  795.                 }
  796.  
  797.                 $this->view_data['logo_message'] = "<i class='fa fa-user'></i>&nbsp; <strong>".$u->username." - </strong><span>This is a demo account <span style='color:red;font-weight:bold'>{$expiration}</span></span>";
  798.                 $this->view_data['demo_account'] = TRUE;
  799.             }else{
  800.                 $this->_msg('e','Please consider to re-login','system_page_auth/login');
  801.  
  802.                 // $this->session->set_flashdata('system_message','Please consider to re-login.');
  803.                 // redirect('system_page_auth/login');
  804.             }
  805.         }
  806.     }
  807. }
  808.  
  809. class Systemlogin_Controller Extends CI_Controller
  810. {
  811.     protected $layout_view = 'blank';
  812.     protected $content_view ='';
  813.     public $loggin = false;
  814.    
  815.     public function __construct()
  816.     {
  817.         parent::__construct();
  818.         $this->load->helper(array('form','my_dropdown'));
  819.         $this->load->library('form_validation');
  820.         $this->load->library('session');
  821.         if(!$this->db_connection->check(true)){
  822.             //update database via browser url : localhost/system/sylver
  823.             show_error('Database Connection Error.');
  824.         }
  825.  
  826.         $this->view_data['system_message'] = $this->_msg = $this->session->flashdata('system_message');
  827.  
  828.         $this->load->model(['M_settings']);
  829.         $this->setting  = $this->M_settings->get_settings();
  830.     }
  831.  
  832.     public function _output($output)
  833.   {
  834.         if($this->content_view !== FALSE && empty($this->content_view)){
  835.             $this->content_view = $this->router->class . '/' . $this->router->method;
  836.         }
  837.        
  838.         $yield = file_exists(APPPATH . 'views/' . $this->content_view . EXT) ? $this->load->view($this->content_view, $this->view_data, TRUE) : FALSE ;
  839.        
  840.         if($this->layout_view)
  841.         {
  842.             $this->view_data['yield'] = $yield;
  843.             echo $this->load->view('layouts/' . $this->layout_view, $this->view_data, TRUE);
  844.         }else{
  845.             echo $yield;
  846.         }
  847.  
  848.         echo $output;
  849.   }
  850.  
  851.     public function _msg($type = FALSE,$message = FALSE,$redirect = FALSE,$var_name = 'system_message')
  852.     {
  853.         $template = "";
  854.         $type = strtolower(trim($type));
  855.         switch($type)
  856.         {
  857.             case $type == 'e':
  858.                 $template = "<div class='alert alert-danger'><h4><i class='fa fa-warning'></i> Error!</h4> <span style='padding-left:2em'>".$message."</span><span style='float:right;' class='glyphicon glyphicon-remove sys_m_close'></span></div>";
  859.             break;
  860.             case $type == 's':
  861.                 $template = "<div class='alert alert-success'><h4><i class='fa fa-check'></i> Success!</h4> <span style='padding-left:2em'>".$message."</span><span style='float:right;' class='glyphicon glyphicon-remove sys_m_close'></span></div>";
  862.             break;
  863.             case $type == 'w':
  864.                 $template = "<div class='alert alert-warning'><h4><i class='fa fa-warning'></i> Warning!</h4> <span style='padding-left:2em'>".$message."</span><span style='float:right;' class='glyphicon glyphicon-remove sys_m_close'></span></div>";      
  865.             break;
  866.             case $type == 'n':
  867.                 $template = "<div id='focusme' class='alert alert-info'><i class='fa fa-check'></i>&nbsp; ".$message."<span style='float:right;' class='glyphicon glyphicon-remove sys_m_close'></span></div>";
  868.             break;
  869.             case $type == 'p':
  870.                 $template = $message;
  871.             break;
  872.             case $type === FALSE;
  873.                 $template = $message;
  874.             break;
  875.         }
  876.        
  877.         if($type AND $message AND $redirect)
  878.         {
  879.             $this->session->set_flashdata($var_name,$template);
  880.             redirect($redirect);
  881.         }elseif($type AND $message AND $redirect == FALSE){
  882.             return $template;
  883.         }
  884.        
  885.         if($redirect == FALSE AND $message == FALSE AND $redirect == FALSE)
  886.         {
  887.             return $this->session->flashdata($var_name);
  888.         }
  889.     }
  890. }
  891.  
  892. class Backend_Controller Extends CI_Controller
  893. {
  894.     protected $layout_view = 'bower_bootstrap_application';
  895.     protected $content_view ='';
  896.     public $loggin = false;
  897.    
  898.     public function __construct()
  899.     {
  900.         parent::__construct();
  901.         $this->load->library(['form_validation','hs']);
  902.         $this->load->helper(array('form','my_dropdown','url_encrypt'));
  903.         $this->load->library('session');
  904.         $this->output->enable_profiler(true);
  905.         $this->view_data['system_message'] = $this->_msg = $this->session->flashdata('system_message');
  906.  
  907.         /** If Database Connection is invalid redirect to edit connection ***/
  908.         if(!$this->db_connection->check(true)){ redirect('sylver');}
  909.  
  910.         $this->load->model(['M_settings']);
  911.  
  912.         $this->loggin = $this->view_data['login'] = $this->session->userdata('gopanel_logged_in') == TRUE ? true : false;
  913.         $this->form_validation->set_error_delimiters('<div class="alert alert-danger">', '</div>');
  914.         $this->setting  = $this->M_settings->get_settings();
  915.  
  916.         //check if logged in
  917.         $this->secure_page();
  918.     }
  919.  
  920.     public function _output($output)
  921.   {
  922.     if($this->content_view !== FALSE && empty($this->content_view)){
  923.             $this->content_view = $this->router->class . '/' . $this->router->method;
  924.     }
  925.        
  926.     $yield = file_exists(APPPATH . 'views/' . $this->content_view . EXT) ? $this->load->view($this->content_view, $this->view_data, TRUE) : FALSE ;
  927.        
  928.         if($this->layout_view)
  929.         {
  930.             $this->view_data['yield'] = $yield;
  931.             echo $this->load->view('layouts/' . $this->layout_view, $this->view_data, TRUE);
  932.         }else{
  933.             echo $yield;
  934.         }
  935.  
  936.         // echo $output;
  937.   }
  938.  
  939.     public function _msg($type = FALSE,$message = FALSE,$redirect = FALSE,$var_name = 'system_message')
  940.     {
  941.         $template = "";
  942.         $type = strtolower(trim($type));
  943.         switch($type)
  944.         {
  945.             case $type == 'e':
  946.                 $template = "<div class='alert alert-danger'><h4><i class='fa fa-warning'></i> Error!</h4> <span style='padding-left:2em'>".$message."</span><span style='float:right;' class='glyphicon glyphicon-remove sys_m_close'></span></div>";
  947.             break;
  948.             case $type == 's':
  949.                 $template = "<div class='alert alert-success'><h4><i class='fa fa-check'></i> Success!</h4> <span style='padding-left:2em'>".$message."</span><span style='float:right;' class='glyphicon glyphicon-remove sys_m_close'></span></div>";
  950.             break;
  951.             case $type == 'w':
  952.                 $template = "<div class='alert alert-warning'><h4><i class='fa fa-warning'></i> Warning!</h4> <span style='padding-left:2em'>".$message."</span><span style='float:right;' class='glyphicon glyphicon-remove sys_m_close'></span></div>";      
  953.             break;
  954.             case $type == 'n':
  955.                 $template = "<div id='focusme' class='alert alert-info'><i class='fa fa-check'></i>&nbsp; ".$message."<span style='float:right;' class='glyphicon glyphicon-remove sys_m_close'></span></div>";
  956.             break;
  957.             case $type == 'p':
  958.                 $template = $message;
  959.             break;
  960.             case $type === FALSE;
  961.                 $template = $message;
  962.             break;
  963.         }
  964.        
  965.         if($type AND $message AND $redirect)
  966.         {
  967.             $this->session->set_flashdata($var_name,$template);
  968.             redirect($redirect);
  969.         }elseif($type AND $message AND $redirect == FALSE){
  970.             return $template;
  971.         }
  972.        
  973.         if($redirect == FALSE AND $message == FALSE AND $redirect == FALSE)
  974.         {
  975.             return $this->session->flashdata($var_name);
  976.         }
  977.     }
  978.  
  979.     public function pagination_style()
  980.     {
  981.       $config['full_tag_open'] = '<ul class="pagination">';
  982.     $config['full_tag_close'] = '</ul>';
  983.     $config['prev_link'] = '&lt; Prev';
  984.     $config['prev_tag_open'] = '<li>';
  985.     $config['prev_tag_close'] = '</li>';
  986.     $config['next_link'] = 'Next &gt;';
  987.     $config['next_tag_open'] = '<li>';
  988.     $config['next_tag_close'] = '</li>';
  989.     $config['cur_tag_open'] = '<li class="active"><a href="#">';
  990.     $config['cur_tag_close'] = '</a></li>';
  991.     $config['num_tag_open'] = '<li>';
  992.     $config['num_tag_close'] = '</li>';
  993.     $config['first_link'] = FALSE;
  994.     $config['last_link'] = FALSE;
  995.    
  996.     return $config;  
  997.     }
  998.  
  999.     /**
  1000.      * Secure GoPanel Page
  1001.      */
  1002.     public function secure_page()
  1003.     {
  1004.         if($this->session->userdata('gopanel_logged_in') == TRUE)
  1005.         {
  1006.            
  1007.         }
  1008.         else{
  1009.             // vd($this->router->class);
  1010.             if($this->router->class != "gopanel_auth"){
  1011.                 redirect('backend');
  1012.             }
  1013.         }
  1014.     }
  1015. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement