| 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
/*********************
*********************
Template : "communication.php"
Controller : "Communication.php"
=> Chat and messagenger controller
-> chat
-> notification
->Controller
->History
-> message
->histoyr
->sender
Creation 29/11/2019
Aernout Guillaume
http://codes.solutions
*********************
*********************/
if (!defined('BASEPATH'))
exit('No direct script access allowed');
class Communication extends NS_Controller {
function __construct() {
parent::__construct(array('no_cache'=>1));
if ($this->session->userdata('admin_login') != 1){
$this->error('restricted admin');
//$this->redirect(base_url(), 'refresh');
}
$this->load->helper('generator');
$this->load->model('crud_model');
$this->load->model('mbox_model');
$this->load->model('notification_model');
$this->load->model('email_model');
$this->load->database();
}
////////////////////////
// Fonction controller
////////////////////////
function index($arg = "") {
$mailParser = new \ZBateson\MailMimeParser\MailMimeParser();
$data['page_name'] = 'communication';
$data['page_title'] = get_phrase('Communication Control Center');
//$data['message_list'] = $this->message_list();
$data['discution_list'] = $this->mbox_model->get_email_list();//$this->mbox_model->get_mbox_list();
$this->load->view('backend/index', $data);
}
function set_readed_notification(){
$this->continueIfAllowed(array('allowed'=>array('admin')));
$mail_id = $this->input->post('mail_id');
$user_id = $this->session->userdata('userID');
$mail = $this->input->post('mail');
$current_snapshot = $this->mbox_model->get_mail_snapshot($mail);
//echo "ici debug $current_snapshot";
echo $this->notification_model->store_mail_snapshot($user_id,$mail_id,$current_snapshot);
}
function refresh_notification($mail_id ="",$mail=""){
$this->continueIfAllowed(array('allowed'=>array('admin')));
$user_id = $this->session->userdata('userID');
if($mail_id == "" && $mail ==""){
$mail_id = $this->input->post('mail_id');
$mail = $this->input->post('mail');
$function = "no";
}
else{
$function = "yes";
}
//echo $mail;
$current_snapshot = $this->mbox_model->get_mail_snapshot($mail);
//var_dump($current_snapshot);
if($this->notification_model->is_new_mail($user_id,$mail_id,$current_snapshot)){
if($function == "no"){
echo "True"; // not new
}else{
return False; // not new
}
}
else{
if($function == "no"){
echo "False"; // new
}else{
return True; //new
}
}
}
function refresh_all_notifications(){
return;
$mails = $this->mbox_model->get_email_list();
foreach ($mails as $key => $mail) {
//var_dump($this->refresh_notification($mail['id_email'],$mail['course_email']));
if($this->refresh_notification($mail['id_email'],$mail['course_email'])){
//echo $mail['id_email'].":".$mail['course_email'];
echo "True";
return; // new mail
}
}
echo False; // no new mail
}
function get_messages(){
$this->continueIfAllowed(array('allowed'=>array('admin')));
$name = $this->input->post('name');
$admin_id = $this->input->post('admin');
$mail_dir = "/home/vmail/ecoledelangues.be/".$name."/";
$mail_list = $this->mbox_model->get_m_list($mail_dir);
$mails_array = array();
foreach ($mail_list as $key => $mail) {
//echo ">>".$mail_dir."new/".$mail;
$mail_array = array();
if(file_exists($mail_dir."new/".$mail)){
$data = file_get_contents($mail_dir."new/".$mail);
$message = \ZBateson\MailMimeParser\Message::from($data);
$to = $message->getHeader('To');
$dest = '';
if($to != Null){
foreach ($to->getAddresses() as $addr) {
$toName = $addr->getName();
$toEmail = $addr->getEmail();
if($toName == ''){
$toName = $toEmail;
}
$dest = $dest."<span data-toggle=\"toggle\" title=\"".$toEmail."\">".$toName."</span>;";
}
}
else{
$dest ='empty from';
}
$attachments = array();
$parts = $message->getAttachmentCount();
for($n = 0 ; $n <= $parts ;$n++){
$part_name = $this->get_attachment_name(($mail_dir."new/".$mail),$n);
if($part_name != False){
$attachment = array(
"id" => $n,
"name" => $part_name
);
array_push($attachments, $attachment);
}
//echo $message->getAttachmentPart($n);
}
//var_dump($attachments);
/*
$mail_array = array(
"debug" => "1",
);
*/
$mail_array = array(
"id" =>$message->getHeaderValue('Message-ID'),
"reply" => $message->getHeaderValue('In-Reply-To'),
"debug" => "1",
"admin" => $this->mbox_model->is_admin($admin_id,$message->getHeaderValue('from')),
"dest" => $dest,
"orig" => $message->getHeaderValue('from'),
"date" => $message->getHeader('Date'),
"subject" => $message->getHeaderValue('Subject'),
"body" => $message->getHtmlContent(),
"origin" => $mail_dir."new/".$mail,
"attachment" => $attachments
);
array_push($mails_array,$mail_array);
//var_dump($mail_array);
}
}
echo json_encode($mails_array);
}
function get_forms(){
$this->continueIfAllowed(array('allowed'=>array('admin')));
$id = $this->input->post('course');
$studentList = $this->crud_model->get_course_students_n($id);
$adminList = $this->crud_model->get_admin_list();
//var_dump($studentList);
$from = array();
foreach ($adminList as $key => $admin) {
$current_from = array(
"id" => $admin['user_id'],
"name" => $admin['first_name'],//. " " . $admin['last_name'],
"email" => $admin['email']
);
array_push($from,$current_from);
}
$to = array();
foreach ($studentList as $key => $student) {
$studentName = $this->crud_model->get_student_name($student);
$studentEmail = $this->email_model->get_master_email($student);
$current_to = array(
"id" => $student,
"name" => $studentName,
"email" => $studentEmail
);
array_push($to,$current_to);
}
//var_dump($to);
$course = $this->crud_model->get_course_info($id);
$note = $course[0]['CourseDescription'];
$forms = array(
'default'=> $this->mbox_model->generate_mail($id,'1'),
'note' => $note,
'from' => $from,
'to' => $to
);
echo json_encode($forms);
}
function edit_note(){
$this->continueIfAllowed(array('allowed'=>array('admin')));
$id = $this->input->post('course');
$content = $this->input->post('content');
$sql = array(
"CourseDescription"=>$content,
);
$this->db->set($sql);
$this->db->where('ID',$id);
$this->db->update('course_new');
}
function get_picture(){
$mailParser = new \ZBateson\MailMimeParser\MailMimeParser();
$this->continueIfAllowed(array('allowed'=>array('admin')));
$mail = $this->input->post('origin');
$id = $this->input->post('id');
// $mail = "/home/vmail/ecoledelangues.be/[email protected]/new/";
$data = file_get_contents ($mail);//file_get_contents ($mail.'1587224716.M369265P10053.EDL-STRETCH,S=1661570,W=1683172');
$message = \ZBateson\MailMimeParser\Message::from($data);
$picture = explode("\n",$message->getPartByContentId($id));//('1718df6a1064d0bb05d1'));
unset($picture[0]);unset($picture[1]);unset($picture[2]);unset($picture[3]);unset($picture[4]);unset($picture[5]);//unset($picture[6]);
//var_dump($picture);
$base64pic = implode($picture);
echo $base64pic;
//header("Content-type: image/gif");
//echo base64_decode($base64pic);
}
/*
function get_attachment(){
$mailParser = new \ZBateson\MailMimeParser\MailMimeParser();
$this->continueIfAllowed(array('allowed'=>array('admin')));
$mail = $this->input->post('source');
$part = $this->input->post('part');
$name = $this->input->post('name');
//$mail = "/home/vmail/ecoledelangues.be/[email protected]/new/1587387473.M316034P15800.EDL-STRETCH,S=211590,W=214367";
//echo "$mail => $part";
$data = file_get_contents ($mail);
$message = \ZBateson\MailMimeParser\Message::from($data);
$attachment_array = explode("\n",$message->getPartByMimeType('application/pdf',$part));
unset($attachment_array[0]);unset($attachment_array[1]);unset($attachment_array[2]);unset($attachment_array[3]);unset($attachment_array[4]);unset($attachment_array[5]);//unset($picture[6]);
$base64pdf = implode($attachment_array);
//echo $base64pdf;
$pdf = base64_decode($base64pdf);
//echo $base64pdf;
header('Content-Type: application/pdf');
header('Content-Length: '.strlen( $pdf ));
header('Content-disposition: inline; filename="' . $name . '"');
header('Cache-Control: public, must-revalidate, max-age=0');
header('Pragma: public');
header('Expires: Sat, 26 Jul 1997 05:00:00 GMT');
header('Last-Modified: '.gmdate('D, d M Y H:i:s').' GMT');
echo $pdf;
}
*/
function get_attachment(){
$mailParser = new \ZBateson\MailMimeParser\MailMimeParser();
$this->continueIfAllowed(array('allowed'=>array('admin')));
$mail = $this->input->post('source');
$part = $this->input->post('part');
$name = $this->input->post('name');
//$mail = "/home/vmail/ecoledelangues.be/[email protected]/new/1587387473.M316034P15800.EDL-STRETCH,S=211590,W=214367";
//echo "$mail => $part";
$data = file_get_contents ($mail);
$message = \ZBateson\MailMimeParser\Message::from($data);
$attachment_array = explode("\n",$message->getAttachmentPart($part));
$type =substr($attachment_array[0],(strpos($attachment_array[0],"Content-Type:")+13),(strpos($attachment_array[0],";")+1));
unset($attachment_array[0]);unset($attachment_array[1]);unset($attachment_array[2]);unset($attachment_array[3]);unset($attachment_array[4]);unset($attachment_array[5]);//unset($picture[6]);
$base64 = implode($attachment_array);
//echo $base64pdf;
$content = base64_decode($base64);
//echo $base64pdf;
header('Content-Type:'.$type);
header('Content-Length: '.strlen( $content ));
header('Content-disposition: inline; filename="' . $name . '"');
header('Cache-Control: public, must-revalidate, max-age=0');
header('Pragma: public');
header('Expires: Sat, 26 Jul 1997 05:00:00 GMT');
header('Last-Modified: '.gmdate('D, d M Y H:i:s').' GMT');
echo $content;
}
function get_attachment_name($mail,$part){
$mailParser = new \ZBateson\MailMimeParser\MailMimeParser();
$data = file_get_contents ($mail);
$message = \ZBateson\MailMimeParser\Message::from($data);
$attachment_array = explode("\n",$message->getAttachmentPart($part));
//$attachment_array = explode("\n",$message->getPartByMimeType('application/pdf',$part));
$attachment_name = substr($attachment_array[0],(strpos($attachment_array[0],"name=\"")+6),-1);
return $attachment_name;
}
function send_message(){
$this->continueIfAllowed(array('allowed'=>array('admin')));
$from = $this->input->post('from');
$to = json_decode($this->input->post('to'));
$subject = $this->input->post('subject');
$message = $this->input->post('message');
$option = $this->input->post('option');
$course_id = $this->input->post('course');
/*$from_mails = array();
foreach ($from as $key => $id) {
array_push($from_mails,$this->email_model->get_master_email($id));
}*/
//var_dump($from);
if($from != '0' && $from != ''){
$from_email = $this->email_model->get_master_email($from);
}
else{
$from_email = $this->mbox_model->generate_mail($course_id,'1');
}
$to_mails = array();
foreach ($to as $key => $id) {
array_push($to_mails,$this->email_model->get_master_email($id));
}
//$to_mails = array("[email protected]","[email protected]"); // debug : to comment in prod
array_push($to_mails,$course_email); //hook course email to destinatairs
//array_push($from_mails,$course_email);
$message = $message ."<input type='hidden' value='".$option."' name='mail_type'/>";
//var_dump($message,$subject,implode(',',$to_mails),$from_email,$option);
echo ($this->email_model->do_email($message,$subject,implode(',',$to_mails),$from_email,$option));
}
}