| 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 : |
<?php
/*********************
*********************
Template : "forms_student.php"
FrontEnd : "hello_student.php"
Controller : "Forms_student.php"
Creation 25/07/2019
Aernout Guillaume
https://codes.solutions
*********************
*********************/
if (!defined('BASEPATH')) {
exit('No direct script access allowed');
}
class Attestation extends NS_Controller
{
public function __construct()
{
parent::__construct(array('no_cache' => 1));
if ($this->session->userdata('admin_login') != 1) {
$this->error('restricted admin');
}
$this->load->helper('generator');
$this->load->model('customer_model');
$this->load->model('profile_model');
$this->load->model('users_model');
$this->load->database();
}
public function index()
{
$data['attestations'] = [];
if($this->userInfo['role'] == 'parent') {
$childs = $this->crud_model->get_parent_child($this->session->userdata('userID'));
foreach ($childs as $key => $child) {
if($this->wallet_model->wallet_balance($child) >= 0 && $this->profile_model->check_nrn($child) == true) {
$data['attestations'][$key] = $this->compute_student($child, false, null);
}
}
} elseif($this->userInfo['role'] == 'student') {
$user = $this->session->userdata('userID');
if($this->wallet_model->wallet_balance($user) == 0) {
$data['attestations'][0] = $this->compute_student($user, false, null);
}
} elseif($this->userInfo['role'] == 'admin') {
$this->db->select('*');
$this->db->from('course_scheduled_new');
$this->db->where('LessonDate <=', date('Y-m-d', strtotime(date('Y') . "-12-31 - 1 year")));
$this->db->where('LessonDate >', date('Y-m-d', strtotime(date('Y') . "-12-31 - 2 year")));
$this->db->where('CourseSociety', '2');
$this->db->where('dob >', date('Y-m-d', strtotime(date('Y') . "-12-31 - 16 year")));
$this->db->join('sms.course_student_new', 'course_scheduled_new.ID = course_student_new.lesson_id');
$this->db->join('course_new', 'course_scheduled_new.CourseId = course_new.ID');
$this->db->join('sms.student', 'course_student_new.student_id = student.student_id');
$this->db->group_by('CourseId');
$data['courses'] = $this->db->get()->result_array();
}
$data['page_name'] = 'attestation';
$data['page_title'] = get_phrase('attestation');
$this->load->view('backend/index', $data);
}
public function compute_student($student_id = "", $xml = false, $course_list = '')
{
$this->db->select('*');
$this->db->from('course_scheduled_new');
$this->db->join('sms.course_student_new', 'course_scheduled_new.CourseID = course_student_new.course_id');
$this->db->join('sms.course_new', 'course_scheduled_new.CourseID = course_new.ID');
$this->db->group_by('course_scheduled_new.ID');
$this->db->where('LessonDate <=', date('Y-m-d', strtotime(date('Y') . "-12-31 - 1 year")));
$this->db->where('LessonDate >', date('Y-m-d', strtotime(date('Y') . "-12-31 - 2 year"))); // not included
$this->db->where('student_id', $student_id);
$this->db->where('CourseSociety', '2'); // propulse
if (($course_list != '' || $course_list != null || $course_list != '[]') && strlen($course_list) != 0) {
$this->db->where_in('course_scheduled_new.CourseID', $course_list);
}
$this->db->distinct('course_scheduled_new.CourseID');
$this->db->order_by('LessonDate', 'ASC');
$data = $this->db->get()->result_array();
$courses = [];
$age = $this->crud_model->get_student_age($student_id);
$age = $age - 1; // one y in past
$dob = $this->crud_model->get_student_birthdate($student_id);
$discount_applied = false;
$n = 0;
$lesson_nb = 0;
$lesson_prev_date;
foreach ($data as $key => $d) {
if(date('Y') == '2021') {
} else {
$permitted = false;
if($age < 14) {
$permitted = true;
} elseif ($age == 14 && (substr($dob, 5) > substr($d['LessonDate'], 5))) { // dd/mm > dd /mm focus on birthdate
$permitted = true;
} else {
$permitted = false;
}
}
if($permitted == true) {
$hours = (float) abs((strtotime("1999-12-12 " . $d['LessonEnd']) - strtotime("1999-12-12 " . $d['LessonStart']))) / (60 * 60) ;
if(array_key_exists($d['CourseID'], $courses)) {
$courses[$d['CourseID']]['course_hours'] = $courses[$d['CourseID']]['course_hours'] + $hours;
if($lesson_prev_date != $d['LessonDate']) {
$courses[$d['CourseID']]['course_lessons']++;
$lesson_prev_date = $d['LessonDate'];
}
$courses[$d['CourseID']]['course_end'] = $d['LessonDate'];
$courses[$d['CourseID']]['period_course_total'] = round($courses[$d['CourseID']]['course_hours'] * $courses[$d['CourseID']]['course_price'], 2, PHP_ROUND_HALF_UP);
} else {
$vat = "21"; // set vat in db
$grandTotal = "0";
if($discount_applied == false) {
$discount = $this->wallet_model->get_discount($student_id);
//no period rules
$discount_applied = true; // applied onetime for every courses
} else {
$discount = 0;
}
if($d['CourseFactured'] == 1) {
$total = $d['CoursePrice'] * $d['CourseContract'];
//vat check
if($d['CourseVat'] == "yes") {
$vatPrice = (($total / 100) * $vat);
$total = $vatPrice + $total;
}
$grandTotal = round(($grandTotal + $total), 0);
}
$wallet_payment = $this->get_period_wallet($student_id, "");
$flagged = false;
if($period_course_total != $grandTotal) {
$flagged = true;
}
$parent = $this->crud_model->get_child_parent($student_id);
$p_info = $this->profile_model->data_profile($parent, 'parent');
$p_address = $this->crud_model->get_user_address($this->crud_model->get_parent_info($parent)[0]['residential_address_id']);
$s_address = $this->crud_model->get_user_address($this->crud_model->get_student_info($student_id)[0]['residential_address_id']);
$s_info = $this->crud_model->get_user_info($student_id);
$p_address_short = $p_address[0]['line_1'] . ",<br>" . $p_address[0]['postcode'] . ",<br>" . $p_address[0]['location'];
$period_course_total = (int) $d['CoursePrice'];
if($xml) {
$control = 'passed'; //passed,error
$controls = array();
$warning = 'no';
$errors = array();
//check wallet
if($this->wallet_model->wallet_balance($student_id) < 0) {
$control = 'error';
array_push($controls, 'error');
array_push($errors, 'parameter : student wallet unsold [Error]');
}
// check name student & parent
if(strlen($s_info[0]['first_name']) < 2 && strlen($s_info[0]['last_name']) < 2 && strlen($p_info['FirstName']) < 2 && strlen($s_info[0]['LastName']) < 2) {
$control = 'error';
array_push($controls, 'error');
array_push($errors, 'parameter : name [Error]');
}
//check dob student & parent
if($dob == "" || $dob == "0000-00-00" || $dob > date('Y-m-d', strtotime(date('Y') . "-12-31 - 3 year"))) {
$control = 'error';
array_push($controls, 'error');
array_push($errors, 'parameter : dob student [Error]');
}
if($p_info['dob'] == "" || $p_info['dob'] == "0000-00-00" || $p_info['dob'] > date('Y-m-d', strtotime(date('Y') . "-12-31 - 3 year"))) {
$control = 'error';
array_push($controls, 'error');
array_push($errors, 'parameter : dob parent [Error]');
}
//check parent address
if(strlen($p_info['l1']) < 2 || strlen($p_info['location']) < 2 || strlen($p_info['pc']) < 4 || is_numeric($p_info['pc']) == false) {
$control = 'error';
array_push($controls, 'error');
array_push($errors, 'parameter : address parent [Error]');
}
//check student address
if(strlen($s_address[0]['line_1']) < 2 || strlen($s_address[0]['location']) < 2 || strlen($s_address[0]['postcode']) < 4 || is_numeric($s_address[0]['postcode']) == false) {
$warning = 'yes';
array_push($controls, 'warning');
array_push($errors, 'parameter : address student [Warning]');
//bypass
$s_address[0]['l1'] = $p_info['l1'];
$s_address[0]['postcode'] = $p_info['pc'];
$s_address[0]['location'] = $p_info['location'];
}
//register
if(strlen($p_info['register_number']) != 11) {
$warning = 'yes';
array_push($controls, 'warning');
array_push($errors, 'parameter : parent register number [Warning]');
}
if(strlen($p_info['register_number']) != 11 || strlen($this->crud_model->get_student_register_number($student_id)) != 11) {
$warning = 'yes';
array_push($controls, 'warning');
array_push($errors, 'parameter : student register number [Warning]');
}
if($wallet_payment < 0 || $grandTotal < 0) {
$warning = 'yes';
array_push($controls, 'warning');
array_push($errors, 'parameter : suspect ammount [Warning]');
}
if($d['CoursePrice'] < 0) {
$warning = 'yes';
array_push($controls, 'warning');
array_push($errors, 'parameter : suspect course price [Warning]');
}
$courses[$d['CourseID']] = array(
"id" => $d['CourseID'],
"control" => $control,
"controls" => array_unique($controls),
"warning" => $warning,
"errors" => json_encode($errors),
"course_name" => $d['CourseName'],
"course_hours" => $hours,
"course_lessons" => 1,
"course_lessons_nb" => $lesson_nb ,
"course_price" => $d['CoursePrice'],
"course_contract" => $d['CourseContract'],
"period_course_total" => $period_course_total,
"complete_course_total" => $grandTotal,
"course_discount" => $discount,
"total_paid" => $wallet_payment,
"flagged" => $flagged,
"student" => $student_id,
"s_name" => $this->crud_model->get_student_name($student_id),
"s_first_name" => $s_info[0]['first_name'],
"s_last_name" => $s_info[0]['last_name'],
"s_register_number" => $this->crud_model->get_student_register_number($student_id),
"s_dob" => $dob,
"s_add_line1" => addslashes(str_replace('"', " ", str_replace("'", " ", $s_address[0]['line_1']))),
"s_add_pc" => $s_address[0]['postcode'],
"s_add_location" => $s_address[0]['location'],
"parent_id" => $parent,
"parent" => $p_info,
"p_name" => $this->crud_model->get_parent_name($parent),
"p_address" => addslashes(str_replace('"', " ", str_replace("'", " ", $p_address_short))),
"p_add_line1" => addslashes(str_replace('"', " ", str_replace("'", " ", $p_address[0]['line_1']))),
"p_add_pc" => $p_address[0]['postcode'],
"p_add_location" => $p_address[0]['location'],
"course_start" => $d['LessonDate'],
"course_end" => $d['LessonDate'],
"ref" => date('Y', strtotime(date() . " - 1 year")) . "-" . str_pad($d['CourseID'], 4, '0', STR_PAD_LEFT) . "" . strtoupper($this->crud_model->get_parent_lastname($this->crud_model->get_child_parent($student_id))), //"EDL-".date('Y',strtotime(date()." - 1 year"))."-".str_pad($d['CourseID'], 4, '0', STR_PAD_LEFT)."-".strtoupper($this->crud_model->get_parent_lastname($this->crud_model->get_child_parent($student_id))),
);
} else {
$courses[$d['CourseID']] = array(
"id" => $d['CourseID'],
"course_name" => $d['CourseName'],
"course_hours" => $hours,
"course_lessons" => 1,
"course_lessons_nb" => $lesson_nb ,
"course_price" => $d['CoursePrice'],
"course_contract" => $d['CourseContract'],
"period_course_total" => $period_course_total,
"complete_course_total" => $grandTotal,
"course_discount" => $discount,
"total_paid" => $wallet_payment,
"flagged" => $flagged,
"student" => $student_id,
"s_name" => $this->crud_model->get_student_name($student_id),
"s_first_name" => $s_info[0]['first_name'],
"s_last_name" => $s_info[0]['last_name'],
"s_register_number" => $this->crud_model->get_student_register_number($student_id),
"s_dob" => $dob,
"s_add_line1" => addslashes(str_replace('"', " ", str_replace("'", " ", $s_address[0]['line_1']))),
"s_add_pc" => $s_address[0]['postcode'],
"s_add_location" => $s_address[0]['location'],
"parent" => $parent,
"p_name" => $this->crud_model->get_parent_name($parent),
"p_address" => addslashes(str_replace('"', " ", str_replace("'", " ", $p_address_short))),
"p_add_line1" => addslashes(str_replace('"', " ", str_replace("'", " ", $p_address[0]['line_1']))),
"p_add_pc" => $p_address[0]['postcode'],
"p_add_location" => $p_address[0]['location'],
"course_start" => $d['LessonDate'],
"course_end" => $d['LessonDate'],
"ref" => "EDL-" . date('Y', strtotime(date() . " - 1 year")) . "-" . str_pad($d['CourseID'], 4, '0', STR_PAD_LEFT) . "-" . strtoupper($this->crud_model->get_parent_lastname($this->crud_model->get_child_parent($student_id))),
);
}
$n++;
}
}
}
return $courses;
}
public function get_period_wallet($student_id, $course_id = "")
{
$this->db->select('*');
$this->db->from('wallet');
$this->db->where('Date <=', date('Y-m-d', strtotime(date('Y') . "-12-31 - 1 year")));
$this->db->where('Date >', date('Y-m-d', strtotime(date('Y') . "-12-31 - 2 year")));
$this->db->where('Student_ID', $student_id);
$data = $this->db->get()->result_array();
// echo $this->db->last_query();
$total;
if($course_id == "") {
foreach ($data as $key => $d) {
//var_dump($d);
$total = $d['Payment_amount'] + $total;
}
} else {
//check linked course
}
//echo $total;
return $total;
}
public function xml_generator()
{
if($this->userInfo['role'] == 'parent') {
$childs = $this->crud_model->get_parent_child($this->session->userdata('userID'));
foreach ($childs as $key => $child) {
//echo ">>$child";
if($this->wallet_model->wallet_balance($child) == 0 && $this->profile_model->check_nrn($child) == true) {
$data['attestations'][$key] = $this->compute_student($child, true);
//var_dump($this->compute_student($child));
} elseif ($this->wallet_model->wallet_balance($child) != 0) {
//echo "balance";
} elseif ($this->profile_model->check_nrn($child) == false) {
//echo "nrn";
} else {
}
}
} elseif($this->userInfo['role'] == 'student') {
$user = $this->session->userdata('userID');
$parent_id = $this->crud_model->get_child_parent($user);
$data['parent'] = $this->profile_model->data_profile($parent_id, 'parent');
if($this->wallet_model->wallet_balance($user) == 0) {
$data['attestations'][0] = $this->compute_student($user, true);
}
} else {
$stream = $this->input->post('stream');
$course_target = $this->input->post('course');
$course_list = $this->input->post('course_list');
$lvl = $this->input->post('level');
//admin
$this->db->select('*');
$this->db->from('course_scheduled_new');
$this->db->where('LessonDate <=', date('Y-m-d', strtotime(date('Y') . "-12-31 - 1 year")));
$this->db->where('LessonDate >', date('Y-m-d', strtotime(date('Y') . "-12-31 - 2 year"))); // not included
$this->db->where('dob >', date('Y-m-d', strtotime(date('Y') . "-12-31 - 16 year")));
$passed_target;
if($course_target != '' && $course_target != null) {
$this->db->where('CourseId', $course_target);
$passed_target = array();
array_push($passed_target, $course_target);
} elseif ($course_list != '' && $course_list != null && $course_list != '[]') {
$list = json_decode($course_list);
$this->db->where_in('CourseId', $list);
$passed_target = array();
$passed_target = $list;
}
$this->db->join('sms.course_student_new', 'course_scheduled_new.ID = course_student_new.lesson_id');
$this->db->join('sms.student', 'course_student_new.student_id = student.student_id');
$this->db->join('course_new', 'course_scheduled_new.CourseId = course_new.ID');
$this->db->group_by('course_student_new.student_id');
$this->db->distinct('course_student_new.student_id');
$data = $this->db->get()->result_array();
$students = array();
$n = 0;
$limit = ['0','100000'];
foreach ($data as $key => $r) {
//echo $key;
if($r['student_id'] != '0' && $key >= $limit[0] && $key < $limit[1]) {
//echo $r['student_id'];
if($this->wallet_model->wallet_balance($r['student_id']) >= 0) {
//echo $r['student_id'];
//array_push($students,$r['student_id']);
$computed = $this->compute_student($r['student_id'], true, $passed_target);
if(count($computed) > 0) {
$data['attestations'][$n] = $computed;
$n++;
}
}
}
}
}
$data['level'] = $lvl;
$data['stream'] = $stream;
$data['attestation_name'] = "attestation-" . implode('|', $passed_target) . ".xml";
if(strpos(json_encode($data), "passed") === false && $lvl == "clear") {
echo "[No Stream] Invalid attestation or no attestation, please take a look on warnings and errors";
} else {
$this->load->view('xml/attestation', $data);
}
//$stream = 'download';
//
}
}