| Server IP : 188.114.97.2 / Your IP : 104.23.197.230 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
if (!defined('BASEPATH')) {
exit('No direct script access allowed');
}
class Parents extends NS_Controller
{
public function __construct()
{
parent::__construct(array('no_cache' => 1));
$this->load->helper('generator');
$this->load->model('users_model');
$this->load->model('profile_model');
$this->load->model('parent_model');
$this->load->model('course_student_model');
$this->load->model('event_model');
$this->load->model('address_model');
$this->load->database();
}
public function index()
{
$this->continueIfAllowed(['allowed' => ['admin','teacher']]);
$data['page_name'] = 'parent';
$data['language'] = $this->profile_model->language();
$data['page_title'] = get_phrase('parent');
$data['parents_list'] = $this->parent_model->listing_all_parents();
$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);
}
return $this->load->view('backend/index', $data);
}
public function loadTable()
{
$parents = $this->crud_model->get_parent_list();
foreach ($parents as $k => $p) {
$id = $p['parent_id'];
$name = $this->crud_model->get_parent_name($id);
if ($name == "" || $name == null || $name == " ") {
unset($parents[$k]);
} else {
$parents[$k]['name'] = $name;
$parents[$k]['mail'] = $this->crud_model->get_user_email($id);
$childs = $this->crud_model->get_parents_children($id);
$parents[$k]['childs'] = array();
$parents[$k]['childs_courses'] = array();
$course_array = array();
foreach ($childs as $key => $c) {
$parents[$k]['childs'][$c['student_id']] = $this->crud_model->get_student_name($c['student_id']);
$courses = $this->crud_model->get_student_courses($c['student_id']);
$course_array = array_unique(array_merge($course_array, $courses));
}
foreach ($course_array as $key => $c) {
$parents[$k]['childs_courses'][$c] = $this->crud_model->get_course_name($c);
}
}
}
echo json_encode($parents);
}
public function getParent()
{
$this->continueIfAllowed(array('allowed' => array('admin','teacher')));
$id = $this->input->post('id');
$parent = $this->crud_model->get_parent_info($id);
$user = $this->crud_model->get_user_info($id);
$address = $this->crud_model->get_user_address($parent[0]['residential_address_id']);
$jsonData = "{ \"user_id\":\"".$id."\",\"address_id\":\"".$parent[0]['residential_address_id']."\",\"email\" :\"".$user[0]['email']."\",\"lang\" :\"".$user[0]['lang']."\",\"firstName\" :\"".$user[0]['first_name']."\",\"lastName\" :\"".$user[0]['last_name']."\",\"phone\" :\"".$user[0]['phone']."\"";
$jsonData = $jsonData .",\"comment\" : \"".preg_replace('/\R/', '\n', $parent[0]['admin_comment'])."\",\"ispaid\" : \"".$parent[0]['is_paid']."\",\"dob\" : \"".$parent[0]['dob']."\"";
$jsonData = $jsonData .",\"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']."\"}";
echo $jsonData;
}
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','lang'));
$error = array();
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->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));
$error = array_filter($error);
if (empty($error)) {
//create user and get the user_id
$isoLang = $this->profile_model->intToIso($data['lang']);
$userId = $this->users_model->create_user($data['email'], $data['pass'], $data['name1'], $data['name2'], $data['phone'], '3', $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_parent($userId, $addressId, $data['comment'], $dob);
$this->event_model->trigger_user('Profile_Creation_Parent', $isoLang, $userId, $data['pass']);
echo "#1";
} else {
var_dump($error);
}
}
public function edit()
{
$this->continueIfAllowed(array('allowed' => array('admin')));
$data = $this->input->post(array('user_id','address_id','email','pass','name1','name2','pic','phone','dob','line_1','line_2','country','state','location','postcode','comment','statut','lang'));
$error = array();
if ($data['user_id'] == null || $data['user_id'] == "") {
array_push($error, "Error on processing : no id");
}
if ($data['address_id'] == null || $data['address_id'] == "") {
array_push($error, "Error on processing : no address 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)) {
//update user + parent + address
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;
}
$this->users_model->update_user_address($data['address_id'], $data['line_1'], $data['line_2'], $data['country'], $data['state'], $data['location'], $data['postcode']);
$this->users_model->update_parent($data['user_id'], $data['comment'], $dob);
echo "1";
} else {
var_dump($error);
}
}
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('parent', array('parent_id' => $data['userId']));
$this->db->delete('user', array('user_id' => $data['userId']));
$this->db->delete('address', array('address_id' => $data['addressId']));
echo "1";
}
}
public function edit_comment()
{
$this->continueIfAllowed(array('allowed' => array('admin')));
$data = ["admin_comment" => $this->input->post("txt")];
$this->db->set($data);
$this->db->where('parent_id', $this->input->post("id"));
$this->db->update('parent');
echo "1";
}
}