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/nicolasj/www/sms.formationlangues.be/application/controllers/BO/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ Back ]     

Current File : /home/nicolasj/www/sms.formationlangues.be/application/controllers/BO/Teacher.php
<?php

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

class Teacher extends NS_Controller
{
    public function __construct()
    {
        parent::__construct(array('no_cache' => 1));

        $this->load->helper('generator');
        $this->load->model('users_model');
        $this->load->model('email_model');
        $this->load->model('event_model');
        $this->load->model('address_model');
        $this->load->model('profile_model');
        $this->load->model('teacher_model');
        $this->load->database();
    }

    public function index()
    {
        $this->continueIfAllowed(array('allowed' => array('admin','teacher','parent')));
        $this->load->helper('url');
        $param = $this->uri->segment(3);

        if($param == "edit") {
            $data['edit'] = $this->uri->segment(4);
        } elseif($param == "presence") {
            $data['presence'] = $this->uri->segment(4);
        }

        $data['page_name'] = 'teacher';
        $data['language'] = $this->profile_model->language();
        $data['page_title'] = get_phrase('teacher');
        if ($this->session->userdata('login_type') == "parent") {
            $students = $this->crud_model->get_parent_child($this->session->userdata('userID'));
            $teachers = [];
            foreach ($students as $key => $s) {
                $courses = $this->crud_model->get_student_courses($s);
                foreach ($courses as $key => $c) {
                    $teachers = array_merge($teachers, $this->crud_model->get_course_teacher_2($c));
                }
            }
            $teachers = (array_unique($teachers));
            $data['teacher_list'] = $this->crud_model->get_teachers($teachers);
        } else {
            $data['teacher_list'] = $this->crud_model->get_all_teachers();
        }

        $data['languages'] = $this->crud_model->get_languages();
        $this->load->view('backend/index', $data);
    }

    /** SECURITY !! 
     * Everyone can cal this function (sensitive data)
     */
    public function loadTable()
    {
        $filters = $this->input->post('filters');

        $teachers_raw = $this->crud_model->get_all_teachers();
        $teachers = [];
        foreach ($teachers_raw as $k => $t) {
            $teachers[$k] = [
                'email' => $t['email'],
                'user_id' => (int) $t['user_id'],
                'teacher_id' => (int) $t['teacher_id'],
                'first_name' => (string) $t['first_name'],
                'last_name' => (string) $t['last_name'],
                'admin_comment' => $t['admin_comment'],
            ];
            $teachers[$k]['contract'] = $this->crud_model->get_teacher_contract_state_2($t['teacher_id']);
            $teachers[$k]['address'] =  $this->crud_model->get_user_address($t['address_id']);
            $courses =  $this->crud_model->get_teachers_course($t['teacher_id']);
            foreach ($courses as $key => $c) {
                $teachers[$k]['courses'][$c]['name'] = $this->crud_model->get_course_name($c);
            }

            $langs = $this->crud_model->get_teacher_lang($t['teacher_id']);
            foreach ($langs as $key => $l) {
                $langs[$key]['course_language_name'] = $this->crud_model->get_language_name($l['course_language_id']);
            }


            $teachers[$k]['lang'] = $langs;
            $langArray = array();

            foreach ($langs as $key => $lang) {
                array_push($langArray, $lang['course_language_id']);
            }

            if ($filters['lang'] != "0") {
                if (!in_array($filters['lang'], $langArray)) {
                    unset($teachers[$k]);
                }
            }

            if($filters['contract'] != $teachers[$k]['admin_contract'] && $filters['contract'] != "0") {
                unset($teachers[$k]);
            }
            if($filters['diplome'] != $teachers[$k]['admin_diplome'] && $filters['diplome'] != "0") {
                unset($teachers[$k]);
            }

            $pub = ['a_public_social','a_public_kid','a_public_ado','a_public_b2b'];
            if($pub[$filters['public']] != $teachers[$k]['admin_public'] && $filters['public'] != "0") {
                unset($teachers[$k]);
            }
        }
        echo json_encode($teachers);
    }

    public function getTeacher()
    {
        $this->continueIfAllowed(array('allowed' => array('admin','teacher')));
        $id = $this->input->post('id');
        $teacher = $this->crud_model->get_teacher_info($id);
        $teacherLang = $this->crud_model->get_teacher_lang($id);
        $user = $this->crud_model->get_user_info($id);
        $address = $this->crud_model->get_user_address($teacher[0]['address_id']);

        $teacher_lang = [];
        foreach ($teacherLang as $key => $row) {
            $teacherLan = $this->crud_model->get_language_name($row['course_language_id']);
            $teacher_lang[$key] = ['lanId' => $row['course_language_id'], 'lanName' => $teacherLan];
        }

        $teacher_data = [
            'user_id' => $id,
            'address_id' => $teacher[0]['address_id'],
            "email" => $user[0]['email'],
            "lang" => $user[0]['lang'],
            "firstName" => $user[0]['first_name'],
            "lastName" => $user[0]['last_name'],
            "phone" => $user[0]['phone'],
            "comment" => $teacher[0]['admin_comment'],
            "ispaid" => $teacher[0]['is_paid'],
            "a_s" => $teacher[0]['admin_state'],
            "a_p" => $teacher[0]['admin_public'],
            "a_l" => $teacher[0]['admin_localisation'],
            "a_d" => $teacher[0]['admin_diplome'],
            "a_c" => $teacher[0]['admin_contract'],
            "lan" => $teacher_lang,
            "dob" => $teacher[0]['dob'],
            "line1" => $address[0]['line_1'],
            "line2" => $address[0]['line_2'],
            "state" => $address[0]['state'],
            "location" => $address[0]['location'],
            "postcode" => $address[0]['postcode'],
            "country" => $address[0]['country'],
            "iban" => $teacher[0]['iban'],
            "register_number" => $teacher[0]['register_number'],
            "coaching" => (int) $teacher[0]['coaching'],
        ];
        echo json_encode($teacher_data);
    }

    public function showLessons()
    {
        $this->continueIfAllowed(array('allowed' => array('admin')));
        $id = $this->input->post('id');

        $query = $this->db->get_where('course_teacher', array('teacher_id' => $id));
        $query = $query->result_array();

        $jsonSchedule = "{";
        foreach ($query as $key => $row) {
            $courseName = $this->crud_model->get_course_name($row['course_id']);
            if($courseName == "") {
                $courseName = "db conflict";
            }
            $jsonSchedule = $jsonSchedule . "\"". $key ."\":{\"courseId\":\"".$row['course_id']."\",\"courseName\":\"".$courseName."\",\"lessonId\":\"".$row['lesson_id']."\",\"lessonName\":\"".$this->crud_model->get_lesson_name($row['lesson_id'])."\",\"lessonInfo\":\"".$this->crud_model->get_lesson_info($row['lesson_id'])."\",\"teacherId\":\"".$id."\",\"teacherName\":\"".$this->crud_model->get_teacher_name($id)."\",\"statusId\":\"".$row['status_id']."\"},";
        }
        $jsonSchedule = rtrim($jsonSchedule, ',') ."}";
        echo $jsonSchedule;
        return true;
    }

    public function save()
    {
        $this->continueIfAllowed(array('allowed' => array('admin')));
        $data = $this->input->post(array('email','pass','name1','name2','pic','phone','dob','line_1','line_2','country','state','location','postcode','comment','statut','rate','language','send_param','lang','pattern_param','a_contract','a_state','a_public','a_loc','a_diplome'));
        $error = array();

        if(empty($data['email']) || $this->users_model->check_email_format($data['email']) === false) {
            array_push($error, "Please enter a valid email");
        }
        if($this->users_model->email_exist($data['email']) == true) {
            array_push($error, "email already exist");
        }
        if($this->users_model->check_pass($data['pass']) != true || ($data['pass'] == null || $data['pass'] == "")) {
            array_push($error, "Password should be at least 6 characters in length and should include at least one upper case letter, one number, and one special character");
        }
        if($this->users_model->check_name($data['name1']) != true || ($data['name1'] == null || $data['name1'] == "")) {
            array_push($error, "Please enter a correct name");
        }
        if($this->users_model->check_name($data['name2']) != true || ($data['name2'] == null || $data['name2'] == "")) {
            array_push($error, "Please enter a correct name");
        }
        if($this->users_model->check_phone($data['phone']) != true || ($data['phone'] == null || $data['phone'] == "")) {
            array_push($error, "Please enter a correct phone number");
        }
        $dob = str_replace('/', '-', $data['dob']);
        $dob = date('Y-m-d', strtotime($dob));

        if($this->users_model->check_dob($dob) != true || ($data['dob'] == null || $data['dob'] == "")) {
            array_push($error, "Please enter a correct date of birth");
        }

        if (empty($error)) {
            //create user and get the user_id
            $userId = $this->users_model->create_user($data['email'], $data['pass'], $data['name1'], $data['name2'], $data['phone'], '2', $data['lang']);
            $addressId = $this->users_model->create_user_address($data['line_1'], $data['line_2'], $data['country'], $data['state'], $data['location'], $data['postcode']);
            $this->users_model->create_teacher($userId, $addressId, $data['comment'], $dob, $data['rate'], $data['a_contract'], $data['a_state'], $data['a_public'], $data['a_loc'], $data['a_diplome']);
            //language qualif
            $lanList = $data['language'];

            $arrlength = count($lanList);
            for($x = 0; $x < $arrlength; $x++) {
                $this->users_model->create_teacher_lang($userId, $lanList[$x]);
            }

            if($data['send_param'] == "true") {
                $name = $data['name1']." ". $data['name2'];
                $lang = $this->crud_model->get_user_lang($userId);
                $isoLang = $this->profile_model->intToIso($lang);
                $this->event_model->trigger_user('Profile_Creation_Teacher', $isoLang, $userId, $data['pass']);
            }

            echo json_encode([
                'success' => true,
                'user_id' => (int) $userId
            ]);
            return;
        }

        echo json_encode([
            'success' => false,
            'errors' => $error
        ]);
        return;
    }

    /**
     * Create an user and teacher with mail and password.
     * The teacher must be fill his profile before use his account.
     * Ajax function
     * DELETEME: Fake credentials: [email protected] // uumKGTpq
     *
     * @return void
     */
    public function create_teacher_account()
    {
        $this->continueIfAllowed(['allowed' => ['admin']]);

        // Validation teacher form
        $user_data = $this->input->post(['email', 'pass']);
        if(empty($user_data['email']) || $this->users_model->check_email_format($user_data['email']) === false) {
            array_push($error, "email must be present and valid");
        } elseif($this->users_model->email_exist($user_data['email'])) {
            array_push($error, "email already exist");
        }
        if(empty($user_data['pass']) || $this->users_model->check_pass($user_data['pass']) === false) {
            array_push($error, "Password should be at least 6 characters in length and should include at least one upper case letter, one number, and one special character");
        }

        // Create user and teacher
        if (empty($error) && $this->users_model->create_teacher_account($user_data['email'], $user_data['pass'])) {
            // Send notification for teacher
            $user = $this->users_model->get_entry_by(['email' => $user_data['email']]);
            $iso_lang = $this->profile_model->intToIso($this->crud_model->get_user_lang((int) $user->user_id));
            $this->event_model->trigger_user('Profile_Creation_Teacher', $iso_lang, (int) $user->user_id, $user_data['pass']);
            echo json_encode(['success' => true, 'user_id' => (int) $user->user_id]);
            return;
        }

        echo json_encode([
            'success' => false,
            'errors' => $error
        ]);
        return;
    }

    public function edit_by_user()
    {
        $this->continueIfAllowed(array('allowed' => array('admin', 'teacher')));
        $data = [
            'page_name' => 'teacher',
            'language' => $this->profile_model->language(),
            'page_title' => get_phrase('teacher')
        ];

        $this->load->view('backend/index', $data);
    }

    public function edit()
    {
        $this->continueIfAllowed(['allowed' => ['admin']]);
        $data = $this->input->post([
            'user_id','address_id','email','pass','name1','name2','pic','phone','dob','line_1','line_2',
            'country','state','location','postcode','comment','statut','rate','language','send_param',
            'lang','pattern_param','a_contract','a_state','a_public','a_loc','a_diplome',
            'iban', 'register_number', 'coaching'
        ]);
        $error = array();        

        if($data['user_id'] == null || $data['user_id'] == "") {
            array_push($error, "Error on processing : no id");
        }
        $user = $this->users_model->get_entry((int) $data['user_id']);
        $teacher = $this->teacher_model->get_entry((int) $data['user_id']);

        if(empty($teacher)) {
            $error[] = "Error on processing : no teacher with this ID";
        }

        if($this->users_model->check_email_format($data['email']) != true || ($data['email'] == null || $data['email'] == "")) {
            array_push($error, "Please enter a valid email");
        }
        if($this->users_model->check_name($data['name1']) != true || ($data['name1'] == null || $data['name1'] == "")) {
            array_push($error, "Please enter a correct name");
        }
        if($this->users_model->check_name($data['name2']) != true || ($data['name2'] == null || $data['name2'] == "")) {
            array_push($error, "Please enter a correct name");
        }
        if($this->users_model->check_phone($data['phone']) != true || ($data['phone'] == null || $data['phone'] == "")) {
            array_push($error, "Please enter a correct phone number");
        }
        $dob = str_replace('/', '-', $data['dob']);
        $dob = date('Y-m-d', strtotime($dob));
        if($this->users_model->check_dob($dob) != true || ($data['dob'] == null || $data['dob'] == "")) {
            array_push($error, "Please enter a correct date of birth");
        }

        $error = array_filter($error);

        if (empty($error)) {
            if(!$this->users_model->update_user($data['user_id'], $data['email'], $data['pass'], $data['name1'], $data['name2'], $data['phone'], $data['lang'])) {
                echo "email already exit or sql crash";
                return false;
            }

            if(!empty($teacher->address_id) && !empty($this->address_model->get_entry((int) $teacher->address_id))) {
                $this->users_model->update_user_address($teacher->address_id, $data['line_1'], $data['line_2'], $data['country'], $data['state'], $data['location'], $data['postcode']);
            } else {
                $address_id = $this->users_model->create_user_address($data['line_1'], $data['line_2'], $data['country'], $data['state'], $data['location'], $data['postcode']);
                $this->teacher_model->update_entry($user->user_id, ['address_id' => (int) $address_id]);
            }

            $this->users_model->update_user_address($data['address_id'], $data['line_1'], $data['line_2'], $data['country'], $data['state'], $data['location'], $data['postcode']);
            $this->teacher_model->update_entry((int) $data['user_id'], [
                'admin_comment' => $data['comment'],
                'dob' => $data['dob'],
                'rate' => $data['rate'],
                'admin_contract' => $data['a_contract'],
                'admin_state' => $data['a_state'],
                'admin_state' => $data['a_state'],
                'admin_localisation' => $data['a_loc'],
                'admin_diplome' => $data['a_diplome'],
                'iban' => $data['iban'],
                'register_number' => $data['register_number'],
                'coaching' => (int) $data['coaching'],
            ]);

            if (in_array((int) $teacher->admin_state, [0, 3]) || in_array((int) $data['a_state'], [0, 3])) {
                $this->teacher_model->update_entry((int) $teacher->teacher_id, ['locked_profile' => false]);
            }

            $lanList = $data['language'];
            $arrlength = count($lanList);
            $this->users_model->clean_teacher_lang($data['user_id']);

            for($x = 0; $x < $arrlength; $x++) {
                $this->users_model->update_teacher_lang($data['user_id'], $lanList[$x]);
            }

            if($data['send_param'] == "true") {
                $name = $data['name1']." ". $data['name2'];
                $lang = $this->crud_model->get_user_lang($data['user_id']);
                $isoLang = $this->profile_model->intToIso($lang);
                if($data['pattern_param'] == "notif") {
                    $this->email_model->password_notification_email($isoLang, $data['pass'], $name, $data['email'], $data['user_id']);
                } elseif($data['pattern_param'] == "opening") {
                    $this->email_model->account_opening_email($isoLang, 'teacher', $name, $data['email'], $data['pass'], $data['user_id']);
                }
            }
            echo "1";
        }
    }

    public function delete()
    {
        $this->continueIfAllowed(array('allowed' => array('admin')));
        $data = $this->input->post(array('userId','addressId'));

        if(isset($data['userId']) && isset($data['addressId'])) {
            $this->db->delete('teacher', array('teacher_id' => $data['userId']));
            $this->db->delete('user', array('user_id' => $data['userId']));
            $this->db->delete('address', array('address_id' => $data['addressId']));
            $this->db->delete('course_teacher', array('teacher_id' => $data['userId']));
            $this->db->delete('teacher_course_language', array('teacher_id' => $data['userId']));
            echo "1";
        }
    }

    /**
     * Validate teacher profile, generate contracts and trigger mail
     * Ajax function
     *
     * @return void
     */
    public function ajax_generate_contract()
    {
        $this->continueIfAllowed(['allowed' => ['admin', 'teacher']]);
        $user_id = (int) $this->session->userdata('userID');
        if (empty($user_id)) {
            echo json_encode(['success' => false, 'errors' => ['Bad user id']]);
            return;
        }
        if ($this->teacher_model->teacher_available_to_generate_contract($user_id) === false) {
            echo json_encode(['success' => false, 'errors' => ['Teacher not allowed to generate contract']]);
            return;
        }
        $user = $this->users_model->get_entry($user_id);
        $teacher = $this->teacher_model->get_entry($user_id);

        // Generate contract into pdf file
        $pdf_uniq_name = $this->users_model->uniq_user_hash((int) $user->user_id);
        $pdf_tpl_name = (int) $teacher->admin_contract === 1 ? 'convention_volontariat' : 'contrat_collaboration';
        $this->load->library('pdf');
        $this->pdf->load_view("pdf/contracts/$pdf_tpl_name", [
            'teacher' => $teacher,
            'user' => $user,
            'address' => $this->address_model->get_entry($teacher->address_id),
            'signature' => false,
        ]);
        $this->pdf->render();
        if (file_put_contents(APPPATH . "../uploads/contracts/$pdf_uniq_name.pdf", $this->pdf->output()) === false) {
            echo json_encode(['success' => false, 'errors' => ['Error when creating pdf']]);
            return;
        }

        // Send contracts in a mail
        $event_name = "Teacher_Creation_Pre-Signed_" . ((int) $teacher->admin_contract === 1 ? 'Benevole' : 'Independant') . "_Contract_to_Teacher";
        $this->event_model->trigger_generic_notification($event_name, 'fr', $user->email, [
            'link_contract'    => base_url() . "uploads/contracts/$pdf_uniq_name.pdf",
            'teacher_contract' => (int) $teacher->admin_contract === 1 ? 'Bénévole' : 'Indépendant',
            'user_name' => strtoupper($user->last_name) . " " . ucfirst($user->first_name),
            'type_contract' => (int) $teacher->admin_contract === 1 ? 'Bénévolat' : 'Collaboration'
        ]);

        // Set teacher status to "waiting"
        $this->teacher_model->update_entry($user_id, ['admin_state' => 2, 'locked_profile' => true]);
        $this->session->set_flashdata('success', 'Vos contrats ont été générés.');

        echo json_encode(['success' => true]);
    }

    /**
     * Validate teacher profile, generate contracts and trigger mail
     * Ajax function
     *
     * @return void
     */
    public function ajax_sign_contract()
    {
        $this->continueIfAllowed(['allowed' => ['admin', 'teacher']]);
        $user_id = (int) $this->session->userdata('userID');
        if (empty($user_id)) {
            echo json_encode(['success' => false]);
            return;
        }
        if ($this->teacher_model->teacher_available_to_sign_contract($user_id) === false) {
            echo json_encode(['success' => false]);
            return;
        }
        $user = $this->users_model->get_entry($user_id);
        $teacher = $this->teacher_model->get_entry($user_id);

        // Generate contract into pdf file
        $pdf_uniq_name = $this->users_model->uniq_user_hash((int) $user->user_id);
        $pdf_tpl_name = (int) $teacher->admin_contract === 1 ? 'convention_volontariat' : 'contrat_collaboration';

        $this->load->library('pdf');
        $this->pdf->load_view("pdf/contracts/$pdf_tpl_name", [
            'teacher' => $teacher,
            'user' => $user,
            'address' => $this->address_model->get_entry($teacher->address_id),
            'signature' => true,
        ]);
        $this->pdf->render();
        if (file_put_contents(APPPATH . "../uploads/contracts/$pdf_uniq_name-signed.pdf", $this->pdf->output()) === false) {
            echo json_encode(['success' => false]);
            return;
        }

        // Send contracts in a mail
        $event_name = "Teacher_Creation_Signed_Contract_to_Teacher";
        $this->event_model->trigger_generic_notification($event_name, 'fr', $user->email, [
            'link_contract'    => base_url() . "uploads/contracts/$pdf_uniq_name-signed.pdf",
            'teacher_contract' => (int) $teacher->admin_contract === 1 ? 'Bénévole' : 'Indépendant',
            'user_name' => strtoupper($user->last_name) . " " . ucfirst($user->first_name),
            'type_contract' => (int) $teacher->admin_contract === 1 ? 'Bénévolat' : 'Collaboration'
        ]);

        // Set teacher status to "order"
        $this->teacher_model->update_entry($user_id, ['admin_state' => 1, 'signed_at' => date_create()->format('Y-m-d H:i:s')]);
        $this->session->set_flashdata('success', 'Vos contrats ont été signés.');

        echo json_encode(['success' => true]);
    }

    public function assign()
    {
        //keep in mind to avoid duplicate content :√
        $this->continueIfAllowed(array('allowed' => array('admin')));
        $data = $this->input->post(array('teacherId','courseId','lessonId'));
        $teacherId = $data['teacherId'];
        $courseId = $data['courseId'];
        $lessonId = $data['lessonId'];
        $assigned = $this->users_model->checkAssignedTeacher($teacherId, $courseId, $lessonId);
        var_dump($assigned);

        if(isset($teacherId) && isset($courseId) && isset($lessonId) && ($assigned == 'false')) {

            $sql = array(
              'course_id' => "$courseId",
              'lesson_id' => "$lessonId",
              'teacher_id' => "$teacherId"
            );
            $this->db->insert('course_teacher', $this->crud_model->cleanArray($sql));
            echo "assigned $lessonId";
            return true;
        } else {
            return false;
        }
    }

    public function removeAssign()
    {
        $this->continueIfAllowed(array('allowed' => array('admin')));
        $data = $this->input->post(array('idLesson','idCourse','idTeacher'));
        $il = $data['idLesson'];
        $ic = $data['idCourse'];
        $is = $data['idTeacher'];

        $sql = array(
          'lesson_id' => "$il",
          'course_id' => "$ic",
          'teacher_id' => "$is");
        //var_dump($sql);
        $this->db->delete('course_teacher', $sql);
        echo "1";
        return true;
    }
    public function presence()
    {
        $this->continueIfAllowed(array('allowed' => array('admin')));
        $data = $this->input->post(array('teacherId','courseId','lessonId','lessonStatut'));
        $studentId = $data['teacherId'];
        $courseId = $data['courseId'];
        $lessonId = $data['lessonId'];
        $statut = $data['lessonStatut'];
        // echo var_dump($data);

        $this->db->set('status_id', $statut);
        $this->db->where('course_id', $courseId);
        $this->db->where('lesson_id', $lessonId);
        $this->db->where('teacher_id', $studentId);
        $this->db->update('course_teacher');
        echo "1";
    }
    public function checkContract()
    {
        $this->continueIfAllowed(array('allowed' => array('admin')));
        $id =  $this->input->post('id');
        $teacher =  $this->input->post('teacher');
        $r = $this->crud_model->get_teacher_contract($id, $teacher);
        echo is_numeric($r);
    }

    public function get_teacher_map()
    {
        $this->continueIfAllowed(array('allowed' => array('admin')));
        $target =  $this->input->post('target');
        $option =  $this->input->post('option');

        if($option == "teachers") {
            $teachers = $this->crud_model->get_teachers();
            $array_teachers = array();
            foreach ($teachers as $key => $teacher) {
                $address = $this->crud_model->get_user_address($teacher['address_id']);
                $coordonate_info = $this->get_coordonate($address);
                $coordonate = $coordonate_info[0]->geometry;

                $array_teacher = array(
                "id" => $teacher['teacher_id'],
                "name" => $this->crud_model->get_teacher_name($teacher['teacher_id']),
                "lang" =>  $this->crud_model->get_teacher_lang($teacher['teacher_id']),
                "address" => $address,
                "coordonate" => $coordonate
              );
                array_push($array_teachers, $array_teacher);
            }
            echo json_encode($array_teachers);
        } elseif($option == "lang") {
            $teachers = $this->crud_model->get_teachers_by_lang($target);

            $array_teachers = array();
            foreach ($teachers as $key => $teacher) {
                $address = $this->crud_model->get_user_address($teacher['address_id']);
                $coordonate_info = $this->get_coordonate($address);
                $coordonate = $coordonate_info[0]->geometry;

                $array_teacher = array(
                "id" => $teacher['teacher_id'],
                "name" => $this->crud_model->get_teacher_name($teacher['teacher_id']),
                "lang" =>  $this->crud_model->get_teacher_lang($teacher['teacher_id']),
                "address" => $address,
                "coordonate" => $coordonate
              );
                array_push($array_teachers, $array_teacher);
            }
            echo json_encode($array_teachers);
        } else {
            $id = $target;
            $address = $this->crud_model->get_user_address($id);
            $coordonate_info = $this->get_coordonate($address);
            $coordonate = $coordonate_info[0]->geometry;
            $array_teachers = array();
            $array_teacher = array(
              "id" => $id,
              "name" => $this->crud_model->get_teacher_name($id),
              "lang" =>  $this->crud_model->get_teacher_lang($id),
              "address" => $address,
              "coordonate" => $coordonate
            );
            array_push($array_teachers, $array_teacher);
            echo json_encode($array_teacher); // not inclose in master array
        }
    }

    public function get_coordonate($array_address)
    {
        $key = 'a1903177a63d4bcf88045689f0fa679b';
        $request = $array_address[0]['line_1'] ." ". $array_address[0]['line_2'].", ". $array_address[0]['location'].", ".$array_address[0]['country'];

        $url = 'https://api.opencagedata.com/geocode/v1/json?q='.urlencode($request).'&key='.$key.'&language=fr&pretty=1';
        $brut_json = file_get_contents($url);
        $json = json_decode($brut_json);

        return $json->results;
    }

    public function edit_comment()
    {
        $this->continueIfAllowed(['allowed' => ['admin']]);

        $this->db->set(["admin_comment" => $this->input->post("txt")]);
        $this->db->where('teacher_id', $this->input->post("id"));
        $this->db->update('teacher');
        echo "1";
    }
}

Youez - 2016 - github.com/yon3zu
LinuXploit