| Server IP : 188.114.96.2 / Your IP : 104.23.243.201 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/controllers/BO/ |
Upload File : |
<?php
/*********************
*********************
Indian Helper : "old_course.php"
helper fix 19 mars 2019
Aernout Guillaume
*********************
*********************/
if (!defined('BASEPATH'))
exit('No direct script access allowed');
class Courses extends NS_Controller {
function __construct() {
parent::__construct();
if ($this->session->userdata('admin_login') != 1){
$this->error('restricted admin');
//$this->redirect(base_url(), 'refresh');
}
$this->load->helper('generator');
$this->load->model('archive_model');
$this->load->model('security_model');
$this->load->database();
//$this->output->cache(10);
}
////////////////////////
// Fonction controller
////////////////////////
function index($arg) {
//$this->output->cache(10);
$data['page_name'] = 'course';
$data['page_title'] = get_phrase('courses');
$data['course_list'] = $this->crud_model->get_courses();
$data['course_language_list'] = $this->get_course_language_list();
if(isset($arg)){
if(is_numeric($arg)){
$data['course_from_dash'] = $arg;
}
else{
$data['add_course'] = true;
}
//echo $arg;
}
$this->load->view('backend/index', $data);
}
//return all Courses + Lessons
function courseStatuts(){
$this->continueIfAllowed(array('allowed'=>array('admin','teacher','student','parent')));
$id = $this->input->post('id');
$data = $this->crud_model->get_course($id);
$hours = $this->crud_model->get_course_scheduled($id);
$address = $this->crud_model->get_course_address($id);
$jsonHours = "";
foreach ($hours as $key => $row) {
$jsonHours = $jsonHours . "\"". $key ."\":{\"id\":\"".$row['ID']."\",\"name\":\"".$row['LessonName']."\",\"date\":\"".date("d/m/Y",strtotime($row['LessonDate']))."\",\"start\":\"".substr($row['LessonStart'],0,5)."\",\"end\":\"".substr($row['LessonEnd'],0,5)."\",\"done\":\"".$row['LessonDone']."\",\"comment\":\"".$row['LessonComment']."\"},";
}
$jsonHours = "\"hours\" : {".rtrim($jsonHours,',')."}";
//$this->error(print_r($jsonHours));
$jsonData = "{ \"id\":\"".$id."\",\"name\" :\"".$data[0]['CourseName']."\",\"certificate\" :\"".$data[0]['CourseCertificate']."\"";
$jsonData = $jsonData .", \"lan\" : ".$data[0]['CourseLanguage'].", \"lvl\" : ".$data[0]['CourseLevel'];
$jsonData = $jsonData .", \"type\" : ".$data[0]['CourseType'].", \"local\" : ".$data[0]['CourseLocal'].", \"society\" : ".$data[0]['CourseSociety'].",\"contract\" : ".$data[0]['CourseContract'];
if(!empty($address)){
$jsonData = $jsonData .",\"l1\" : \"".$address[0]['course_l1']."\",\"l2\" : \"".$address[0]['course_l2']."\",\"coun\" : \"".$address[0]['course_country']."\",\"post\" : \"".$address[0]['course_pc']."\",\"loca\" : \"".$address[0]['course_city']."\"";
}
$jsonData = $jsonData .",\"desc\" : \"".$this->security_model->clean_json($data[0]['CourseDescription'])."\",\"price\" : \"".$data[0]['CoursePrice']."\",\"vat\" : \"".$data[0]['CourseVat']."\",\"group\" : \"".str_replace('"', "'",$this->crud_model->get_course_students($id))."\", $jsonHours}";
$this->error(print_r($jsonData));
}
//archive Course
function archive(){
$this->continueIfAllowed(array('allowed'=>array('admin')));
$data = $this->input->post('id');
$this->archive_model->archive_course($data);
echo "1";
}
function courseContract(){
$this->continueIfAllowed(array('allowed'=>array('admin','teacher','student','parent')));
$id = $this->input->post('id');
$teachers = $this->crud_model->get_teachers_list($id);
$data = array();
foreach ($teachers as $key => $teacher) {
$currentData = array();
$contract = $this->crud_model->get_course_contract($id);
$currentArray = array(
'teacher_id' => $teacher,
'teacher_name' => $this->crud_model->get_teacher_name($teacher),
'course_id' => $id,
'course_name' => $this->crud_model->get_course_name($id),
'course_hours' => $contract,
'course_price' => round($this->crud_model->get_course_price($id)* $contract),
'teacher_price' => $this->crud_model->get_teacher_contract($id,$teacher)
);
array_push($data,$currentArray);
}
echo json_encode($data);
}
//Confirm lesson controller
function confirm(){
$this->continueIfAllowed(array('allowed'=>array('admin')));
$data = $this->input->post(array('id','statut','comment'));
if(isset($data)){
$sql = array(
'CourseDone' => $data['statut'],
'CourseComment' => $data['comment']
);
$this->error(var_dump($sql));
$this->db->set($sql);
$this->db->where('ID',$data['id']);
$this->db->update('course_scheduled_new');
}
}
//Delete course + lesson controller
function delete(){
$this->continueIfAllowed(array('allowed'=>array('admin')));
$data = $this->input->post('id');
//$this->error(var_dump($data));
if(isset($data)){
$this->db->delete('course_new',array('ID' => $data));
$this->db->delete('course_scheduled_new',array('CourseID' => $data));
$this->db->delete('course_teacher',array('course_id' => $data));
$this->db->delete('course_student_new',array('course_id' => $data));
}
}
function deleteLesson(){
$this->continueIfAllowed(array('allowed'=>array('admin','teacher')));
$data = $this->input->post('lessonId');
$this->db->delete('course_scheduled_new',array('ID' => $data['lessonId']));
}
//Edit course + lesson controller
function edit(){
$this->continueIfAllowed(array('allowed'=>array('admin','teacher')));
$data = $this->input->post(array('id','name','certificate','course_language_id','course_level_id','course_type_id','course_local_id','course_society_id','hours_planned','course_contract','description','client_price','vat_option','course_l1','course_l2','course_country','course_pc','course_city'));
$error = array();
if ($data['name'] == null || $data['name'] == "" ) { array_push($error,"Please enter the course name");}
if ($data['certificate'] == null || $data['certificate'] == "" ) { array_push($error,"Please enter the course certificate name");}
if ($data['course_language_id'] == null || $data['course_language_id'] == "" ) { array_push($error,"Please select the course language");}
if ($data['course_level_id'] == null || $data['course_level_id'] == "" ) { array_push($error,"Please select the course level");}
if ($data['course_type_id'] == null || $data['course_type_id'] == "" ) { array_push($error,"Please select the course type");}
if ($data['course_contract'] == null || $data['course_contract'] == "" ) { array_push($error,"Please enter contract hours");}
if(count($error) == 0) {
$courseSql = array(
'CourseName' => $data['name'],
'CourseCertificate' => $data['certificate'],
'CourseLanguage' => $data['course_language_id'],
'CourseLevel' => $data['course_level_id'],
'CourseType' => $data['course_type_id'],
'CourseLocal' => $data['course_local_id'],
'CourseSociety' => $data['course_society_id'],
'CourseContract' => $data['course_contract'],
'CourseDescription' => $data['description'],
'CoursePrice' => $data['client_price'],
'CourseVat' => $data['vat_option']
);
//$this->error(var_dump($data['id']));
$this->db->set($courseSql);
$this->db->where('ID',$data['id']);
$this->db->update('course_new');
if($data['course_l1'] != null && $data['course_pc'] != null){
$addressSql = array(
'course_id' => $data['id'],
'course_l1' => $data['course_l1'],
'course_l2' => $data['course_l2'],
'course_country' =>$data['course_country'],
'course_pc' => $data['course_pc'],
'course_city' => $data['course_city']
);
$query = $this->db->get_where('course_address', array('course_id' => $data['id']));
$count = $query->num_rows();
if($count != "0"){
$this->db->set($addressSql);
$this->db->where('course_id',$data['id']);
$this->db->update('course_address');
}
else{
$this->db->insert('course_address',$addressSql);
}
}
$json_data = json_decode($data['hours_planned'],true);
foreach($json_data as $row){
if(!isset($row['done'])){
$row['done'] = "";
}
if(!isset($row['id'])){
$lessonSql = array(
'CourseID' => $data['id'],
'CourseDate' => $row['date'],
'CourseStart' => $row['start'],
'CourseEnd' => $row['end'],
'CourseDone' => $row['done']
);
$this->db->insert('course_scheduled_new', $lessonSql);
//print_r($this->db->last_query());
}
else{
$lessonSql = array(
'CourseDate' => $row['date'],
'CourseStart' => $row['start'],
'CourseEnd' => $row['end'],
'CourseDone' => $row['done']
);
$this->db->set($lessonSql);
$this->db->where(array('ID' => $data['id'],'CourseId' => $row['id']));
$this->db->update('course_scheduled_new');
//print_r($this->db->last_query());
}
}
echo "1";
}
else{
$this->error(var_dump($error));
}
}
//Create course (+lesson) controller
function save(){
$this->continueIfAllowed(array('allowed'=>array('admin')));
$data = $this->input->post(array('name','certificate','course_language_id','course_level_id','course_type_id','course_local_id','course_society_id','course_contract','hours_planned','description','client_price','vat_option','course_l1','course_l2','course_country','course_pc','course_city'));
$error = array();
if ($data['name'] == null || $data['name'] == "" ) { array_push($error,"Please enter the course name");}
if ($data['certificate'] == null || $data['certificate'] == "" ) { array_push($error,"Please enter the course certificate name");}
if ($data['course_language_id'] == null || $data['course_language_id'] == "" ) { array_push($error,"Please select the course language");}
if ($data['course_level_id'] == null || $data['course_level_id'] == "" ) { array_push($error,"Please select the course level");}
if ($data['course_type_id'] == null || $data['course_type_id'] == "" ) { array_push($error,"Please select the course type");}
if ($data['course_contract'] == null || $data['course_contract'] == "" ) { array_push($error,"Please enter contract hours");}
if(count($error) == 0) {
$courseSql = array(
'ID' => '',
'CourseName' => $data['name'],
'CourseCertificate' => $data['certificate'],
'CourseLanguage' => $data['course_language_id'],
'CourseLevel' => $data['course_level_id'],
'CourseType' => $data['course_type_id'],
'CourseLocal' => $data['course_local_id'],
'CourseSociety' => $data['course_society_id'],
'CourseContract' => $data['course_contract'],
'CourseDescription' => $data['description'],
'CoursePrice' => $data['client_price'],
'CourseVat' => $data['vat_option']
);
$this->db->insert('course_new',$courseSql);
$id = $this->db->insert_id();
if($data['course_l1'] != null && $data['course_pc'] != null && isset($id)){
$addressSql = array(
'course_id' => $id,
'course_l1' => $data['course_l1'],
'course_l2' => $data['course_l2'],
'course_country' =>$data['course_country'],
'course_pc' => $data['course_pc'],
'course_city' => $data['course_city']
);
$this->db->insert('course_address',$addressSql);
}
echo $id;
// for each lesson in json
$json_data = json_decode($data['hours_planned'],true);
foreach($json_data as $row){
$lessonSql = array(
'ID' => '',
'CourseID' => $id,
'CourseDate' => $row['date'],
'CourseStart' => $row['start'],
'CourseEnd' => $row['end']
);
$this->db->insert('course_scheduled_new',$lessonSql);
}
// echo "1";
}
else{
$this->error(var_dump($error));
}
}
function updateContract(){
$this->continueIfAllowed(array('allowed'=>array('admin')));
$data = $this->input->post(array('teacher_id','course_id','price'));
$price = (int) filter_var($data['price'], FILTER_SANITIZE_NUMBER_INT);
$q = $this->db->get_where('teacher_contract',array('Teacher_ID' => $data['teacher_id'],'Course_ID' => $data['course_id']));
if ( $q->num_rows() > 0 )
{
$this->db->set('Price',$price);
$this->db->where(array('Teacher_ID' => $data['teacher_id'],'Course_ID' => $data['course_id']));
$this->db->update('teacher_contract');
echo "1";
} else {
$sql = array(
'Teacher_ID' => $data['teacher_id'],
'Course_ID' => $data['course_id'],
'Price' => $price
);
$this->db->insert('teacher_contract', $sql);
//echo $this->db->insert_id();
echo "1";
}
}
////////////////////////
// Fonctions simple
////////////////////////
// -> should use crud_model
function get_course(){
$this->db->order_by('ID', 'DESC');
$data = $this->db->select('*')->get('course_new')->result_array();
$x = 0;
return $data;
}
function get_course_language_list(){
$data = $this->db->get('course_language')->result_array();
return $data;
}
function get_student_list($id){
$data = $this->db->get_where('course_student',array('course_id' => $id));
return $data;
}
}
?>