Advertisement
xeon9

variable end bug?

Sep 13th, 2013
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 18.71 KB | None | 0 0
  1. <?php if (!defined('BASEPATH')) exit('No direct script access allowed');
  2.  
  3. class Admin extends MX_Controller
  4. {
  5.    
  6. /*****************************************************
  7.  * Perfect controller methods
  8.  *****************************************************/
  9.     function __construct() {
  10.         parent::__construct();
  11.        
  12.         $this->load->helper('url');
  13.         $this->load->helper('form');
  14.         $this->load->library('form_validation');
  15.         $this->load->model('admin_mdl');
  16.         $this->load->model('media/media_mdl');
  17.         $this->load->model('pathways/pathways_mdl');
  18.         $this->load->model('classes/classes_mdl');
  19.         $this->load->model('parts/parts_mdl');
  20.         $this->load->model('lessons/lessons_mdl');
  21.     }
  22.  
  23.     function get($order_by){
  24.         $this->load->model('mdl_perfectcontroller');
  25.         $query = $this->mdl_perfectcontroller->get($order_by);
  26.         return $query;
  27.      }
  28.    
  29.     function get_with_limit($limit, $offset, $order_by) {
  30.         $this->load->model('mdl_perfectcontroller');
  31.         $query = $this->mdl_perfectcontroller->get_with_limit($limit, $offset, $order_by);
  32.         return $query;
  33.      }
  34.    
  35.     function get_where($id){
  36.         $this->load->model('mdl_perfectcontroller');
  37.         $query = $this->mdl_perfectcontroller->get_where($id);
  38.         return $query;
  39.      }
  40.    
  41.     function get_where_custom($col, $value) {
  42.         $this->load->model('mdl_perfectcontroller');
  43.         $query = $this->mdl_perfectcontroller->get_where_custom($col, $value);
  44.         return $query;
  45.      }
  46.    
  47.     function _insert($data){
  48.         $this->load->model('mdl_perfectcontroller');
  49.         $this->mdl_perfectcontroller->_insert($data);
  50.      }
  51.    
  52.     function _update($id, $data){
  53.         $this->load->model('mdl_perfectcontroller');
  54.         $this->mdl_perfectcontroller->_update($id, $data);
  55.      }
  56.    
  57.     function _delete($id){
  58.         $this->load->model('mdl_perfectcontroller');
  59.         $this->mdl_perfectcontroller->_delete($id);
  60.      }
  61.    
  62.     function count_where($column, $value) {
  63.         $this->load->model('mdl_perfectcontroller');
  64.         $count = $this->mdl_perfectcontroller->count_where($column, $value);
  65.         return $count;
  66.      }
  67.    
  68.     function get_max() {
  69.         $this->load->model('mdl_perfectcontroller');
  70.         $max_id = $this->mdl_perfectcontroller->get_max();
  71.         return $max_id;
  72.      }
  73.    
  74.     function _custom_query($mysql_query) {
  75.         $this->load->model('mdl_perfectcontroller');
  76.         $query = $this->mdl_perfectcontroller->_custom_query($mysql_query);
  77.         return $query;
  78.      }
  79.  
  80.  
  81. /*****************************************************
  82.  * Miscellaneous methods
  83.  *****************************************************/
  84.     //Get all pathways records names.  
  85.     function get_pathways_name() {
  86.         $data = array('vdata_pathways' => $this->pathways_mdl->get_pathways_name());
  87.         return $data;
  88.      }         
  89.  
  90.     //Get all classes records names WHERE pathid.  
  91.     function get_classes_name_pathid($pathwayid) {
  92.         $data = array('vdata_classes' => $this->classes_mdl->get_classes_name_pathid($pathwayid));
  93.         return $data;
  94.      }         
  95.  
  96.     //Get all classes records names WHERE pathid.  
  97.     function get_parts_name_classid($classid) {
  98.         $data = array('vdata_parts' => $this->parts_mdl->get_parts_name_classid($classid));
  99.         return $data;
  100.      }         
  101.  
  102.     //Get all classes records names WHERE pathid.  
  103.     function get_lessons_name_partid($partid) {
  104.         $data = array('vdata_lessons' => $this->lessons_mdl->get_lessons_name_partid($partid));
  105.         return $data;
  106.      }         
  107.  
  108.     //Get pathways records and display Admin Control Panel
  109.     function cp() {
  110.         $data_pathways = $this->get_pathways_name();
  111.         $this->load->view('cpanel', $data_pathways);
  112.     }
  113.    
  114.     function cp_proc() {
  115.         //PATHWAYS
  116.         //If pathways record is clicked.
  117.         //Submit/Reload the page.
  118.         //Capture Pathwayid
  119.         //Get pathways records and store into array.
  120.         //Get classid, nameclass related to pathwayid.
  121.         //If record(s) exist store pathwayid into session.
  122.         //Else empty pathwayid from session.
  123.         //Fetch pathwayid from session
  124.         //Combine arrays.
  125.         //Display pathways records and classes records related to pathwayid    
  126.        
  127.         //Capture Pathwayid
  128.         $recordid = $this->uri->segment(3, 0);
  129.         $division = $this->uri->segment(4, 0);
  130.        
  131.         //Get pathways records and store into array.
  132.         $data_pathways  = $this->get_pathways_name();
  133.        
  134.         //Initialize variable arrays
  135.         $data_classes   = array('' => '');
  136.         $data_parts     = array('' => '');
  137.         $data_lessons   = array('' => '');
  138.        
  139.         if($division == 'path') {
  140.             //Store pathid into session
  141.             $this->session->set_userdata('pathwayid', $recordid);
  142.            
  143.             //Fetch pathwayid from session
  144.             $pathwayid = $this->session->userdata('pathwayid');
  145.            
  146.             //Get classes records related to pathwayid and store into array.
  147.             $data_classes = $this->get_classes_name_pathid($pathwayid);
  148.  
  149.             //If record(s) exist delete partid, lessonid from session
  150.                 $this->session->set_userdata('partid', '');
  151.                 $this->session->set_userdata('lessonid', '');
  152.                 $data_part = array();
  153.                 $data_lessons = array();
  154.            
  155.             if($data_classes != FALSE) {
  156.                 $this->session->set_userdata('partid', '');
  157.                 $this->session->set_userdata('lessonid', '');
  158.                 $data_part = array();
  159.                 $data_lessons = array();
  160.                 $this->jaz_print_r($data_classes);
  161.             } elseif($data_classes == FALSE) {
  162.             //Else empty pathwayid from session.
  163.                 $this->jaz_print_r($data_classes);
  164.             }
  165.         } elseif ($division == 'class') {
  166.             //CLASS division
  167.             //Fetch pathwayid from session
  168.             $pathwayid = $this->session->userdata('pathwayid');
  169.             //Get classes records related to pathwayid and store into array.
  170.             $data_classes = $this->get_classes_name_pathid($pathwayid);
  171.  
  172.             //PARTS division
  173.             //Store classid into session
  174.             $this->session->set_userdata('classid', $recordid);
  175.             //Fetch classid from session
  176.             $classid = $this->session->userdata('classid');
  177.             //Get parts records related to classid and store into array.
  178.             $data_parts = $this->get_parts_name_classid($classid);
  179.  
  180.             //If record(s) exist delete lessonid from session
  181.             if($data_parts != FALSE) {
  182.                 $this->session->set_userdata('lessonid', '');
  183.                 $data_lessons = array();
  184.             } else {
  185.             //Else empty classid from session.
  186.                 //$this->session->set_userdata('classid', '');
  187.             }
  188.         } elseif ($division == 'part') {
  189.             //CLASS division
  190.             //Fetch pathwayid from session
  191.             $pathwayid = $this->session->userdata('pathwayid');
  192.             //Get classes records related to pathwayid and store into array.
  193.             $data_classes = $this->get_classes_name_pathid($pathwayid);
  194.  
  195.             //PARTS division
  196.             //Fetch classid from session
  197.             $classid = $this->session->userdata('classid');
  198.             //Get parts records related to classid and store into array.
  199.             $data_parts = $this->get_parts_name_classid($classid);
  200.  
  201.             //LESSONS division
  202.             //Store partid into session
  203.             $this->session->set_userdata('partid', $recordid);
  204.             //Fetch partid from session
  205.             $partid = $this->session->userdata('partid');
  206.             //Get lessons records related to partid and store into array.
  207.             $data_lessons = $this->get_lessons_name_partid($partid);
  208.  
  209.             //If record(s) exist store partid into session.
  210.             if($data_lessons != FALSE) {
  211.                 //do nothing
  212.             } else {
  213.             //Else empty classid from session.
  214.                 //$this->session->set_userdata('classid', '');
  215.             }
  216.         } elseif ($division == 'none') {
  217.             //echo '<h3>No division is selected!</h3>';
  218.            
  219.             //Fetch pathwayid from session
  220.             //Get classes records related to pathwayid and store into array.
  221.             $pathwayid = $this->session->userdata('pathwayid');
  222.             if($pathwayid != '') {
  223.                 $data_classes = $this->get_classes_name_pathid($pathwayid);
  224.             }
  225.  
  226.             //Fetch classid from session
  227.             //Get parts records related to classid and store into array.
  228.             $classid = $this->session->userdata('classid');
  229.             if($classid != '') {
  230.                 $data_parts = $this->get_parts_name_classid($classid);
  231.             }
  232.  
  233.             //Fetch partid from session
  234.             //Get lessons records related to partid and store into array.
  235.             $partid = $this->session->userdata('partid');
  236.             if($partid != '') {
  237.                 $data_lessons = $this->get_lessons_name_partid($partid);
  238.             }
  239.         }
  240.  
  241.         //Combine arrays.
  242.         $data = array_merge((array)$data_pathways, (array)$data_classes, (array)$data_parts, (array)$data_lessons);
  243.  
  244.         //Display merged records
  245.         $this->load->view('cpanel', $data);
  246.     }
  247.  
  248.     function add_pathways() {
  249.         //store into session
  250.         $this->session->set_userdata('action', 'add');
  251.         $this->load->view('pathways/addpathways_form');
  252.     }      
  253.  
  254.     function edit_pathways() {
  255.         //catch pathwaysid
  256.         $pathwayid = $this->uri->segment(3, 0);
  257.        
  258.         //store into session
  259.         $this->session->set_userdata('rec_id', $pathwayid);
  260.         $this->session->set_userdata('action', 'edit');
  261.        
  262.         //Get record related to pathwayid  
  263.         $data = $this->pathways_mdl->get_record_by_id($pathwayid);
  264.  
  265.         //Convert array into single dimensional array.
  266.         $data_flat = $this->array_flatten($data);
  267.        
  268.         //$this->jaz_print_r($data_flat);
  269.         $this->load->view('pathways/addpathways_form', $data_flat);
  270.     }      
  271.  
  272.     function add_classes() {
  273.         //store into session
  274.         $this->session->set_userdata('action', 'add');
  275.         echo Modules::run('classes/addclasses');
  276.     }      
  277.  
  278.     function edit_classes() {
  279.         //catch classsid
  280.         $classid = $this->uri->segment(3, 0);
  281.        
  282.         //store into session
  283.         $this->session->set_userdata('rec_id', $classid);
  284.         $this->session->set_userdata('action', 'edit');
  285.        
  286.         //Get record related to classid
  287.         $data_class     = $this->classes_mdl->get_record_by_id($classid);
  288.         //$data_pathway     = array('vdata' => $this->pathways_mdl->get_pathways_name());
  289.  
  290.         //convert multi-dimentional array into single array.
  291.         $data_class = $this->array_flatten($data_class);       
  292.        
  293.         //get record by pathwayid
  294.         $data_pathway = $this->pathways_mdl->get_record_by_id($data_class['pathwayid']);
  295.         $data_pathway = $this->array_flatten($data_pathway);
  296.        
  297.         //Create new index in class array and assign 'namepathway'.
  298.         $data_class['namepathway'] = $data_pathway['namepathway'];
  299.        
  300.         $this->load->view('classes/addclasses_form', $data_class);
  301.     }
  302.  
  303.     function add_parts() {
  304.         //store into session
  305.         $this->session->set_userdata('action', 'add');
  306.         echo Modules::run('parts/addparts');
  307.     }
  308.  
  309.     function edit_parts() {
  310.         //catch classsid
  311.         $partid = $this->uri->segment(3, 0);
  312.        
  313.         //store into session
  314.         $this->session->set_userdata('rec_id', $partid);
  315.         $this->session->set_userdata('action', 'edit');
  316.        
  317.         //Get record related to classid
  318.         $data_part  = $this->parts_mdl->get_record_by_id($partid);
  319.  
  320.         //convert multi-dimentional array into single array.
  321.         $data_part = $this->array_flatten($data_part);
  322.        
  323.         //get parent record by classid
  324.         $data_class = $this->classes_mdl->get_record_by_id($data_part['classid']);
  325.         $data_class = $this->array_flatten($data_class);
  326.  
  327.         //Create new index in part array and assign 'namepart'.
  328.         $data_part['nameclass'] = $data_class['nameclass'];
  329.         $this->load->view('parts/addparts_form', $data_part);
  330.  
  331.         /*     
  332.         echo 'Class:';
  333.         $this->jaz_print_r($data_class);
  334.         echo 'Part:';
  335.         $this->jaz_print_r($data_part);
  336.         */
  337.     }      
  338.  
  339.     function add_lessons() {
  340.         //store into session
  341.         $this->session->set_userdata('action', 'add');
  342.         echo Modules::run('lessons/addlesson');    
  343.     }      
  344.  
  345.     function edit_lessons() {
  346.         //catch classsid
  347.         $lessonid = $this->uri->segment(3, 0);
  348.        
  349.         //store into session
  350.         $this->session->set_userdata('rec_id', $lessonid);
  351.         $this->session->set_userdata('action', 'edit');
  352.        
  353.         //Get lesson record related to classid
  354.         $data_lesson = $this->lessons_mdl->get_record_by_id($lessonid);
  355.         $data_lesson = $this->array_flatten($data_lesson);
  356.  
  357.         //Get media record related to lessonid
  358.         $data_media = $this->media_mdl->get_record_by_id($lessonid);
  359.         $data_media = $this->array_flatten($data_media);         
  360.        
  361.         //get parent part record by partid
  362.         $data_part = $this->parts_mdl->get_record_by_id($data_lesson['partid']);
  363.         $data_part = $this->array_flatten($data_part);
  364.  
  365.         //Create new index in lesson array and assign 'namepart'.
  366.         $data_lesson['namepart'] = $data_part['namepart'];
  367.        
  368.         //Merge array
  369.         $data_lesson = array_merge((array)$data_lesson, (array)$data_media);
  370.        
  371.         /*
  372.         echo 'Media:';
  373.         $this->jaz_print_r($data_media);
  374.         echo 'Part:';
  375.         $this->jaz_print_r($data_part);
  376.         echo 'Lesson:';
  377.         $this->jaz_print_r($data_lesson);
  378.         */
  379.  
  380.         $this->load->view('lessons/addlesson_form', $data_lesson);
  381.     }  
  382.  
  383.     //These will delete four divisions Pathways, Classes, Parts and Lessons
  384.     function del_divs() {
  385.         //capture selected checkboxes
  386.         //Determine right division
  387.         //Delete records according to selected check boxes and division
  388.         //Delete child records related to parent selected boxes
  389.         //Display successfull message
  390.         //Display Admin Panel again.
  391.  
  392.         if(!empty($_POST['pathway']) OR !empty($_POST['class']) OR !empty($_POST['part']) OR !empty($_POST['lesson'])) {
  393.             //Process pathway check boxes
  394.             if(isset($_POST['submitpathway'])) {    //pathway button
  395.                 if(isset($_POST['pathway'])) {  //pathway array
  396.                     foreach ($_POST['pathway'] as $id){
  397.                         //Check if children exist related to pathid in classes table
  398.                         $has_children = $this->classes_mdl->get_record_by_id2($id);
  399.                        
  400.                         //If it has no children then delete it.
  401.                         if($has_children == FALSE) {
  402.                             $del_result = $this->pathways_mdl->delete_pathwayid($id);
  403.                         }
  404.                     }
  405.                     //Display successful delete message.
  406.                     $msg = array(
  407.                         'main_msg' =>   'Pathways record(s) successfully deleted. <br>If the record(s) was not deleted, it means it has children.',
  408.                         'url_txt' =>    'Please click here to go back to Admin Panel.',
  409.                         'url' =>        site_url("admin/cp/"),
  410.                     );
  411.                     echo Modules::run('tasks/message', $msg);
  412.                 }
  413.                
  414.                 if(!isset($_POST['pathway'])) {
  415.                     //Display fail message
  416.                     $msg = array(
  417.                         'main_msg' =>   'Sorry, No Pathways check boxes was selected.',
  418.                         'url_txt' =>    'Please click here to go back to Admin Panel.',
  419.                         'url' =>        site_url("admin/cp/"),
  420.                     );
  421.                     echo Modules::run('tasks/message', $msg);
  422.                 }
  423.             }
  424.            
  425.    
  426.             //Process class check boxes
  427.             if(isset($_POST['submitclass'])) {  //class button
  428.                 if(isset($_POST['class'])) {    //class array          
  429.                     foreach ($_POST['class'] as $id){
  430.                         //Check if children exist related to classid in parts table
  431.                         $has_children = $this->parts_mdl->get_record_by_id2($id);
  432.                        
  433.                         //If it has no children then delete it.
  434.                         if($has_children == FALSE) {
  435.                             $del_result = $this->classes_mdl->delete_classid($id);
  436.                         }
  437.                     }
  438.                     //Display successful delete message.
  439.                     $msg = array(
  440.                         'main_msg' =>   'Classes record(s) successfully deleted. <br>If the record(s) was not deleted, it means it has children.',
  441.                         'url_txt' =>    'Please click here to go back to Admin Panel.',
  442.                         'url' =>        site_url("admin/cp/"),
  443.                     );
  444.                     echo Modules::run('tasks/message', $msg);
  445.                 }
  446.  
  447.                 if(!isset($_POST['class'])) {
  448.                     //Display fail message
  449.                     $msg = array(
  450.                         'main_msg' =>   'Sorry, No Classes check boxes was selected.',
  451.                         'url_txt' =>    'Please click here to go back to Admin Panel.',
  452.                         'url' =>        site_url("admin/cp/"),
  453.                     );
  454.                     echo Modules::run('tasks/message', $msg);
  455.                 }
  456.             }
  457.            
  458.    
  459.             //Process part check boxes
  460.             if(isset($_POST['submitpart'])) {   //part button
  461.                 if(isset($_POST['part'])) { //part array
  462.                     foreach ($_POST['part'] as $id){
  463.                         //Check if children exist related to partid from lessons table
  464.                         $has_children = $this->lessons_mdl->get_record_by_id2($id);
  465.                        
  466.                         //If it has no children then delete it.
  467.                         if($has_children == FALSE) {
  468.                             $del_result = $this->parts_mdl->delete_partid($id);
  469.                         }
  470.                     }
  471.                     //Display successful delete message.
  472.                     $msg = array(
  473.                         'main_msg' =>   'Parts record(s) successfully deleted. <br>If the record(s) was not deleted, it means it has children.',
  474.                         'url_txt' =>    'Please click here to go back to Admin Panel.',
  475.                         'url' =>        site_url("admin/cp/"),
  476.                     );
  477.                     echo Modules::run('tasks/message', $msg);
  478.                 }
  479.  
  480.                 if(!isset($_POST['part'])) {
  481.                     //Display fail message
  482.                     $msg = array(
  483.                         'main_msg' =>   'Sorry, No Parts check boxes was selected.',
  484.                         'url_txt' =>    'Please click here to go back to Admin Panel.',
  485.                         'url' =>        site_url("admin/cp/"),
  486.                     );
  487.                     echo Modules::run('tasks/message', $msg);
  488.                 }
  489.             }
  490.            
  491.    
  492.             //Process lesson check boxes
  493.             if(isset($_POST['submitlesson'])) { //lesson button
  494.                 if(isset($_POST['lesson'])) {   //lesson array         
  495.                     foreach ($_POST['lesson'] as $id){
  496.                         //Delete lesson related to $id
  497.                         $del_result = $this->lessons_mdl->delete_lessonid($id);
  498.                         //echo 'Result: '. $del_result .'<br>';
  499.                     }
  500.                     //Display successful delete message.
  501.                     $msg = array(
  502.                         'main_msg' =>   'Lessons record(s) successfully deleted!',
  503.                         'url_txt' =>    'Please click here to go back to Admin Panel.',
  504.                         'url' =>        site_url("admin/cp/"),
  505.                     );
  506.                     echo Modules::run('tasks/message', $msg);
  507.                 }
  508.  
  509.                 if(!isset($_POST['lesson'])) {
  510.                     //Display fail message
  511.                     $msg = array(
  512.                         'main_msg' =>   'Sorry, No Lessons check boxes was selected.',
  513.                         'url_txt' =>    'Please click here to go back to Admin Panel.',
  514.                         'url' =>        site_url("admin/cp/"),
  515.                     );
  516.                     echo Modules::run('tasks/message', $msg);
  517.                 }
  518.             }
  519.            
  520.  
  521.         } else {
  522.             //Display successfull saved message;
  523.             $msg = array(
  524.                 'main_msg' =>   'No check boxes are selected!',
  525.                 'url_txt' =>    'Please click here to try again.',
  526.                 'url' =>        site_url("admin/cp_proc/0/none/"),
  527.             );
  528.             echo Modules::run('tasks/message', $msg);
  529.         }
  530.  
  531.  
  532.        
  533.     }
  534.    
  535.    
  536. /*****************************************************
  537.  * Utility methods
  538.  *****************************************************/
  539.     //Test emptying array
  540.     function empty_a() {
  541.         $data = array('fruit' => 'apple', 'color' => 'green');
  542.        
  543.         echo 'Content: <br>';
  544.         $this->jaz_print_r($data);
  545.         echo '<br><br>';
  546.        
  547.         echo 'Empty: <br>';
  548.         $data = array();
  549.         $this->jaz_print_r($data);
  550.     }
  551.  
  552.  
  553.     function logic_test() {
  554.         $tmp = $this->uri->segment(3, 0);
  555.        
  556.         if($tmp == 'a') {
  557.             echo 'Cool a.';
  558.            
  559.         } elseif ($tmp == 'b') {
  560.             echo 'Nice b.';
  561.            
  562.         } elseif ($tmp == 'c') {
  563.             echo 'WoW!, c.';
  564.  
  565.         } elseif ($tmp == '') {
  566.             echo 'Tmp is empty!';
  567.  
  568.         } elseif ($tmp == '0') {
  569.             echo 'Tmp is zero string!';
  570.            
  571.         } elseif ($tmp == 0) {
  572.             echo 'Tmp is zero integer!';
  573.            
  574.         } else {
  575.             echo 'Ooops, none is selected!';
  576.         }
  577.         echo '<br><br>TMP: '. $tmp;
  578.     }
  579.  
  580.     function jaz_print_r($data) {
  581.         echo '<pre>';
  582.         print_r($data);
  583.         echo '</pre>';
  584.     }  
  585.    
  586.     function array_flatten($array) {
  587.       if (!is_array($array)) {
  588.         return FALSE;
  589.       }
  590.      
  591.       $result = array();
  592.       foreach ($array as $key => $value) {
  593.         if (is_array($value)) {
  594.           $result = array_merge($result, $this->array_flatten($value));
  595.         }
  596.         else {
  597.           $result[$key] = $value;
  598.         }
  599.       }
  600.       return $result;
  601.     }  
  602.    
  603. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement