Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php if (!defined('BASEPATH')) exit('No direct script access allowed');
- class Admin extends MX_Controller
- {
- /*****************************************************
- * Perfect controller methods
- *****************************************************/
- function __construct() {
- parent::__construct();
- $this->load->helper('url');
- $this->load->helper('form');
- $this->load->library('form_validation');
- $this->load->model('admin_mdl');
- $this->load->model('media/media_mdl');
- $this->load->model('pathways/pathways_mdl');
- $this->load->model('classes/classes_mdl');
- $this->load->model('parts/parts_mdl');
- $this->load->model('lessons/lessons_mdl');
- }
- function get($order_by){
- $this->load->model('mdl_perfectcontroller');
- $query = $this->mdl_perfectcontroller->get($order_by);
- return $query;
- }
- function get_with_limit($limit, $offset, $order_by) {
- $this->load->model('mdl_perfectcontroller');
- $query = $this->mdl_perfectcontroller->get_with_limit($limit, $offset, $order_by);
- return $query;
- }
- function get_where($id){
- $this->load->model('mdl_perfectcontroller');
- $query = $this->mdl_perfectcontroller->get_where($id);
- return $query;
- }
- function get_where_custom($col, $value) {
- $this->load->model('mdl_perfectcontroller');
- $query = $this->mdl_perfectcontroller->get_where_custom($col, $value);
- return $query;
- }
- function _insert($data){
- $this->load->model('mdl_perfectcontroller');
- $this->mdl_perfectcontroller->_insert($data);
- }
- function _update($id, $data){
- $this->load->model('mdl_perfectcontroller');
- $this->mdl_perfectcontroller->_update($id, $data);
- }
- function _delete($id){
- $this->load->model('mdl_perfectcontroller');
- $this->mdl_perfectcontroller->_delete($id);
- }
- function count_where($column, $value) {
- $this->load->model('mdl_perfectcontroller');
- $count = $this->mdl_perfectcontroller->count_where($column, $value);
- return $count;
- }
- function get_max() {
- $this->load->model('mdl_perfectcontroller');
- $max_id = $this->mdl_perfectcontroller->get_max();
- return $max_id;
- }
- function _custom_query($mysql_query) {
- $this->load->model('mdl_perfectcontroller');
- $query = $this->mdl_perfectcontroller->_custom_query($mysql_query);
- return $query;
- }
- /*****************************************************
- * Miscellaneous methods
- *****************************************************/
- //Get all pathways records names.
- function get_pathways_name() {
- $data = array('vdata_pathways' => $this->pathways_mdl->get_pathways_name());
- return $data;
- }
- //Get all classes records names WHERE pathid.
- function get_classes_name_pathid($pathwayid) {
- $data = array('vdata_classes' => $this->classes_mdl->get_classes_name_pathid($pathwayid));
- return $data;
- }
- //Get all classes records names WHERE pathid.
- function get_parts_name_classid($classid) {
- $data = array('vdata_parts' => $this->parts_mdl->get_parts_name_classid($classid));
- return $data;
- }
- //Get all classes records names WHERE pathid.
- function get_lessons_name_partid($partid) {
- $data = array('vdata_lessons' => $this->lessons_mdl->get_lessons_name_partid($partid));
- return $data;
- }
- //Get pathways records and display Admin Control Panel
- function cp() {
- $data_pathways = $this->get_pathways_name();
- $this->load->view('cpanel', $data_pathways);
- }
- function cp_proc() {
- //PATHWAYS
- //If pathways record is clicked.
- //Submit/Reload the page.
- //Capture Pathwayid
- //Get pathways records and store into array.
- //Get classid, nameclass related to pathwayid.
- //If record(s) exist store pathwayid into session.
- //Else empty pathwayid from session.
- //Fetch pathwayid from session
- //Combine arrays.
- //Display pathways records and classes records related to pathwayid
- //Capture Pathwayid
- $recordid = $this->uri->segment(3, 0);
- $division = $this->uri->segment(4, 0);
- //Get pathways records and store into array.
- $data_pathways = $this->get_pathways_name();
- //Initialize variable arrays
- $data_classes = array('' => '');
- $data_parts = array('' => '');
- $data_lessons = array('' => '');
- if($division == 'path') {
- //Store pathid into session
- $this->session->set_userdata('pathwayid', $recordid);
- //Fetch pathwayid from session
- $pathwayid = $this->session->userdata('pathwayid');
- //Get classes records related to pathwayid and store into array.
- $data_classes = $this->get_classes_name_pathid($pathwayid);
- //If record(s) exist delete partid, lessonid from session
- $this->session->set_userdata('partid', '');
- $this->session->set_userdata('lessonid', '');
- $data_part = array();
- $data_lessons = array();
- if($data_classes != FALSE) {
- $this->session->set_userdata('partid', '');
- $this->session->set_userdata('lessonid', '');
- $data_part = array();
- $data_lessons = array();
- $this->jaz_print_r($data_classes);
- } elseif($data_classes == FALSE) {
- //Else empty pathwayid from session.
- $this->jaz_print_r($data_classes);
- }
- } elseif ($division == 'class') {
- //CLASS division
- //Fetch pathwayid from session
- $pathwayid = $this->session->userdata('pathwayid');
- //Get classes records related to pathwayid and store into array.
- $data_classes = $this->get_classes_name_pathid($pathwayid);
- //PARTS division
- //Store classid into session
- $this->session->set_userdata('classid', $recordid);
- //Fetch classid from session
- $classid = $this->session->userdata('classid');
- //Get parts records related to classid and store into array.
- $data_parts = $this->get_parts_name_classid($classid);
- //If record(s) exist delete lessonid from session
- if($data_parts != FALSE) {
- $this->session->set_userdata('lessonid', '');
- $data_lessons = array();
- } else {
- //Else empty classid from session.
- //$this->session->set_userdata('classid', '');
- }
- } elseif ($division == 'part') {
- //CLASS division
- //Fetch pathwayid from session
- $pathwayid = $this->session->userdata('pathwayid');
- //Get classes records related to pathwayid and store into array.
- $data_classes = $this->get_classes_name_pathid($pathwayid);
- //PARTS division
- //Fetch classid from session
- $classid = $this->session->userdata('classid');
- //Get parts records related to classid and store into array.
- $data_parts = $this->get_parts_name_classid($classid);
- //LESSONS division
- //Store partid into session
- $this->session->set_userdata('partid', $recordid);
- //Fetch partid from session
- $partid = $this->session->userdata('partid');
- //Get lessons records related to partid and store into array.
- $data_lessons = $this->get_lessons_name_partid($partid);
- //If record(s) exist store partid into session.
- if($data_lessons != FALSE) {
- //do nothing
- } else {
- //Else empty classid from session.
- //$this->session->set_userdata('classid', '');
- }
- } elseif ($division == 'none') {
- //echo '<h3>No division is selected!</h3>';
- //Fetch pathwayid from session
- //Get classes records related to pathwayid and store into array.
- $pathwayid = $this->session->userdata('pathwayid');
- if($pathwayid != '') {
- $data_classes = $this->get_classes_name_pathid($pathwayid);
- }
- //Fetch classid from session
- //Get parts records related to classid and store into array.
- $classid = $this->session->userdata('classid');
- if($classid != '') {
- $data_parts = $this->get_parts_name_classid($classid);
- }
- //Fetch partid from session
- //Get lessons records related to partid and store into array.
- $partid = $this->session->userdata('partid');
- if($partid != '') {
- $data_lessons = $this->get_lessons_name_partid($partid);
- }
- }
- //Combine arrays.
- $data = array_merge((array)$data_pathways, (array)$data_classes, (array)$data_parts, (array)$data_lessons);
- //Display merged records
- $this->load->view('cpanel', $data);
- }
- function add_pathways() {
- //store into session
- $this->session->set_userdata('action', 'add');
- $this->load->view('pathways/addpathways_form');
- }
- function edit_pathways() {
- //catch pathwaysid
- $pathwayid = $this->uri->segment(3, 0);
- //store into session
- $this->session->set_userdata('rec_id', $pathwayid);
- $this->session->set_userdata('action', 'edit');
- //Get record related to pathwayid
- $data = $this->pathways_mdl->get_record_by_id($pathwayid);
- //Convert array into single dimensional array.
- $data_flat = $this->array_flatten($data);
- //$this->jaz_print_r($data_flat);
- $this->load->view('pathways/addpathways_form', $data_flat);
- }
- function add_classes() {
- //store into session
- $this->session->set_userdata('action', 'add');
- echo Modules::run('classes/addclasses');
- }
- function edit_classes() {
- //catch classsid
- $classid = $this->uri->segment(3, 0);
- //store into session
- $this->session->set_userdata('rec_id', $classid);
- $this->session->set_userdata('action', 'edit');
- //Get record related to classid
- $data_class = $this->classes_mdl->get_record_by_id($classid);
- //$data_pathway = array('vdata' => $this->pathways_mdl->get_pathways_name());
- //convert multi-dimentional array into single array.
- $data_class = $this->array_flatten($data_class);
- //get record by pathwayid
- $data_pathway = $this->pathways_mdl->get_record_by_id($data_class['pathwayid']);
- $data_pathway = $this->array_flatten($data_pathway);
- //Create new index in class array and assign 'namepathway'.
- $data_class['namepathway'] = $data_pathway['namepathway'];
- $this->load->view('classes/addclasses_form', $data_class);
- }
- function add_parts() {
- //store into session
- $this->session->set_userdata('action', 'add');
- echo Modules::run('parts/addparts');
- }
- function edit_parts() {
- //catch classsid
- $partid = $this->uri->segment(3, 0);
- //store into session
- $this->session->set_userdata('rec_id', $partid);
- $this->session->set_userdata('action', 'edit');
- //Get record related to classid
- $data_part = $this->parts_mdl->get_record_by_id($partid);
- //convert multi-dimentional array into single array.
- $data_part = $this->array_flatten($data_part);
- //get parent record by classid
- $data_class = $this->classes_mdl->get_record_by_id($data_part['classid']);
- $data_class = $this->array_flatten($data_class);
- //Create new index in part array and assign 'namepart'.
- $data_part['nameclass'] = $data_class['nameclass'];
- $this->load->view('parts/addparts_form', $data_part);
- /*
- echo 'Class:';
- $this->jaz_print_r($data_class);
- echo 'Part:';
- $this->jaz_print_r($data_part);
- */
- }
- function add_lessons() {
- //store into session
- $this->session->set_userdata('action', 'add');
- echo Modules::run('lessons/addlesson');
- }
- function edit_lessons() {
- //catch classsid
- $lessonid = $this->uri->segment(3, 0);
- //store into session
- $this->session->set_userdata('rec_id', $lessonid);
- $this->session->set_userdata('action', 'edit');
- //Get lesson record related to classid
- $data_lesson = $this->lessons_mdl->get_record_by_id($lessonid);
- $data_lesson = $this->array_flatten($data_lesson);
- //Get media record related to lessonid
- $data_media = $this->media_mdl->get_record_by_id($lessonid);
- $data_media = $this->array_flatten($data_media);
- //get parent part record by partid
- $data_part = $this->parts_mdl->get_record_by_id($data_lesson['partid']);
- $data_part = $this->array_flatten($data_part);
- //Create new index in lesson array and assign 'namepart'.
- $data_lesson['namepart'] = $data_part['namepart'];
- //Merge array
- $data_lesson = array_merge((array)$data_lesson, (array)$data_media);
- /*
- echo 'Media:';
- $this->jaz_print_r($data_media);
- echo 'Part:';
- $this->jaz_print_r($data_part);
- echo 'Lesson:';
- $this->jaz_print_r($data_lesson);
- */
- $this->load->view('lessons/addlesson_form', $data_lesson);
- }
- //These will delete four divisions Pathways, Classes, Parts and Lessons
- function del_divs() {
- //capture selected checkboxes
- //Determine right division
- //Delete records according to selected check boxes and division
- //Delete child records related to parent selected boxes
- //Display successfull message
- //Display Admin Panel again.
- if(!empty($_POST['pathway']) OR !empty($_POST['class']) OR !empty($_POST['part']) OR !empty($_POST['lesson'])) {
- //Process pathway check boxes
- if(isset($_POST['submitpathway'])) { //pathway button
- if(isset($_POST['pathway'])) { //pathway array
- foreach ($_POST['pathway'] as $id){
- //Check if children exist related to pathid in classes table
- $has_children = $this->classes_mdl->get_record_by_id2($id);
- //If it has no children then delete it.
- if($has_children == FALSE) {
- $del_result = $this->pathways_mdl->delete_pathwayid($id);
- }
- }
- //Display successful delete message.
- $msg = array(
- 'main_msg' => 'Pathways record(s) successfully deleted. <br>If the record(s) was not deleted, it means it has children.',
- 'url_txt' => 'Please click here to go back to Admin Panel.',
- 'url' => site_url("admin/cp/"),
- );
- echo Modules::run('tasks/message', $msg);
- }
- if(!isset($_POST['pathway'])) {
- //Display fail message
- $msg = array(
- 'main_msg' => 'Sorry, No Pathways check boxes was selected.',
- 'url_txt' => 'Please click here to go back to Admin Panel.',
- 'url' => site_url("admin/cp/"),
- );
- echo Modules::run('tasks/message', $msg);
- }
- }
- //Process class check boxes
- if(isset($_POST['submitclass'])) { //class button
- if(isset($_POST['class'])) { //class array
- foreach ($_POST['class'] as $id){
- //Check if children exist related to classid in parts table
- $has_children = $this->parts_mdl->get_record_by_id2($id);
- //If it has no children then delete it.
- if($has_children == FALSE) {
- $del_result = $this->classes_mdl->delete_classid($id);
- }
- }
- //Display successful delete message.
- $msg = array(
- 'main_msg' => 'Classes record(s) successfully deleted. <br>If the record(s) was not deleted, it means it has children.',
- 'url_txt' => 'Please click here to go back to Admin Panel.',
- 'url' => site_url("admin/cp/"),
- );
- echo Modules::run('tasks/message', $msg);
- }
- if(!isset($_POST['class'])) {
- //Display fail message
- $msg = array(
- 'main_msg' => 'Sorry, No Classes check boxes was selected.',
- 'url_txt' => 'Please click here to go back to Admin Panel.',
- 'url' => site_url("admin/cp/"),
- );
- echo Modules::run('tasks/message', $msg);
- }
- }
- //Process part check boxes
- if(isset($_POST['submitpart'])) { //part button
- if(isset($_POST['part'])) { //part array
- foreach ($_POST['part'] as $id){
- //Check if children exist related to partid from lessons table
- $has_children = $this->lessons_mdl->get_record_by_id2($id);
- //If it has no children then delete it.
- if($has_children == FALSE) {
- $del_result = $this->parts_mdl->delete_partid($id);
- }
- }
- //Display successful delete message.
- $msg = array(
- 'main_msg' => 'Parts record(s) successfully deleted. <br>If the record(s) was not deleted, it means it has children.',
- 'url_txt' => 'Please click here to go back to Admin Panel.',
- 'url' => site_url("admin/cp/"),
- );
- echo Modules::run('tasks/message', $msg);
- }
- if(!isset($_POST['part'])) {
- //Display fail message
- $msg = array(
- 'main_msg' => 'Sorry, No Parts check boxes was selected.',
- 'url_txt' => 'Please click here to go back to Admin Panel.',
- 'url' => site_url("admin/cp/"),
- );
- echo Modules::run('tasks/message', $msg);
- }
- }
- //Process lesson check boxes
- if(isset($_POST['submitlesson'])) { //lesson button
- if(isset($_POST['lesson'])) { //lesson array
- foreach ($_POST['lesson'] as $id){
- //Delete lesson related to $id
- $del_result = $this->lessons_mdl->delete_lessonid($id);
- //echo 'Result: '. $del_result .'<br>';
- }
- //Display successful delete message.
- $msg = array(
- 'main_msg' => 'Lessons record(s) successfully deleted!',
- 'url_txt' => 'Please click here to go back to Admin Panel.',
- 'url' => site_url("admin/cp/"),
- );
- echo Modules::run('tasks/message', $msg);
- }
- if(!isset($_POST['lesson'])) {
- //Display fail message
- $msg = array(
- 'main_msg' => 'Sorry, No Lessons check boxes was selected.',
- 'url_txt' => 'Please click here to go back to Admin Panel.',
- 'url' => site_url("admin/cp/"),
- );
- echo Modules::run('tasks/message', $msg);
- }
- }
- } else {
- //Display successfull saved message;
- $msg = array(
- 'main_msg' => 'No check boxes are selected!',
- 'url_txt' => 'Please click here to try again.',
- 'url' => site_url("admin/cp_proc/0/none/"),
- );
- echo Modules::run('tasks/message', $msg);
- }
- }
- /*****************************************************
- * Utility methods
- *****************************************************/
- //Test emptying array
- function empty_a() {
- $data = array('fruit' => 'apple', 'color' => 'green');
- echo 'Content: <br>';
- $this->jaz_print_r($data);
- echo '<br><br>';
- echo 'Empty: <br>';
- $data = array();
- $this->jaz_print_r($data);
- }
- function logic_test() {
- $tmp = $this->uri->segment(3, 0);
- if($tmp == 'a') {
- echo 'Cool a.';
- } elseif ($tmp == 'b') {
- echo 'Nice b.';
- } elseif ($tmp == 'c') {
- echo 'WoW!, c.';
- } elseif ($tmp == '') {
- echo 'Tmp is empty!';
- } elseif ($tmp == '0') {
- echo 'Tmp is zero string!';
- } elseif ($tmp == 0) {
- echo 'Tmp is zero integer!';
- } else {
- echo 'Ooops, none is selected!';
- }
- echo '<br><br>TMP: '. $tmp;
- }
- function jaz_print_r($data) {
- echo '<pre>';
- print_r($data);
- echo '</pre>';
- }
- function array_flatten($array) {
- if (!is_array($array)) {
- return FALSE;
- }
- $result = array();
- foreach ($array as $key => $value) {
- if (is_array($value)) {
- $result = array_merge($result, $this->array_flatten($value));
- }
- else {
- $result[$key] = $value;
- }
- }
- return $result;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement