?
Current Path : /home1/savoy/public_html/savoyglobal.net/koaladraft/application/models/ |
Linux gator3171.hostgator.com 4.19.286-203.ELK.el7.x86_64 #1 SMP Wed Jun 14 04:33:55 CDT 2023 x86_64 |
Current File : /home1/savoy/public_html/savoyglobal.net/koaladraft/application/models/smsmodel.php |
<?php if (!defined('BASEPATH')) exit('No direct script access allowed'); class Smsmodel extends CI_Model { function __construct() { // Call the Model constructor parent::__construct(); } function search_send_sms() { $data = array(); $data['startpage'] = ''; $data['endpage'] = ''; $data['count'] = ''; $data['results'] = ''; return $data; } function insert_send_sms($postdata) { $data = array(); $data['resfunction'] = 'search_send_sms'; $smsdata = $this->mastermodel->getdatas('smssettings'); foreach ($smsdata as $smsinfo) { $username = $smsinfo['username']; $password = $smsinfo['password']; $domain = $smsinfo['domain']; } $datetime = date("Y-m-d H:i:s"); $message = $postdata['message']; $sender = $postdata['sender_id']; $split = explode(',', $postdata['numbers']); $method = "POST"; $username = urlencode($username); $password = urlencode($password); $sender = urlencode($sender); $message = urlencode($message); if ($username == '' || $password == '' || $domain == '') { $data['res'] = 0; $data['msg'] = "SMS settings not configured"; return $data; } else { $this->db->trans_begin(); $masterid = $this->mastermodel->insertmasterdata(); $tbl1Values = array( 'sms_id' => $masterid, 'sms_contents' => $postdata['message'], 'sms_date' => date("Y-m-d"), 'sender_id' => $postdata['sender_id' ], ); $this->db->insert('smsreport', $tbl1Values); for ($i = 0; $i < sizeof($split); $i++) { $numbers = $split[$i]; $numbers=$this->add_areacode($numbers); if ($postdata['status'] == "Sent") { $opts = array( 'http' => array( 'method' => "$method", 'content' => "username=$username&password=$password&type=5&dlr=1&destination=$numbers&message=$message&source=$sender", 'header' => "Accept-language: en\r\n" . "Content-type: application/x-www-form-urlencoded\r\n" . "Cookie: foo=bar\r\n" ) ); $context = stream_context_create($opts); $fp = fopen("$domain", "r", false, $context); $response = @stream_get_contents($fp); // echo $response; if (strpos($response,'1701') !== false) $status = "Sent"; else $status = "Not Sent"; fpassthru($fp); fclose($fp); } else { $status = "Saved"; } $tbl1Values = array( 'sms_id' => $masterid, 'numbers' => $numbers, 'status' => $status, 'datetime' => $datetime); $this->db->insert('sendsms', $tbl1Values); } if ($this->db->trans_status() === FALSE) { $this->db->trans_rollback(); $data['res'] = 0; $data['msg'] = 'Error On Adding Record'; return $data; } else { $this->db->trans_commit(); $data['res'] = 1; $data['msg'] = 'Record Added Successfully'; return $data; } } } function search_bulk_sms() { $data = array(); $data['startpage'] = ''; $data['endpage'] = ''; $data['count'] = ''; $data['results'] = ''; return $data; } function loadsmslist($postdata) { $data = array(); $sql = ""; if ((isset($postdata['teacher_id']) != 'on') && (isset($postdata['parent_id']) != 'on') && (isset($postdata['staff_id']) != 'on')) { $data['results'] = ""; } else { if (isset($postdata['teacher_id']) == 'on') { $teacher = array(); if (isset($postdata['teacher_class_name_id'])) { for ($i = 0; $i < count($postdata['teacher_class_name_id']); $i++) { $c_id = $postdata['teacher_class_name_id'][$i]; $teacher[] = $c_id; } } if (count($teacher) > 0) { $sql.="select master_id as sort_id,master_id ,menu_id,employee_name as name, employee_no as reg, nationality.nationality_name as nationality, employee_gender as gender, employee.employee_mobile_no as mobile_no, 'Teacher' as type,class_name_code from employee join nationality on employee.employee_nationality_id=nationality.nationality_id left join class_teacher on class_teacher.teacher_id=employee.employee_id left join class_name on class_name.class_name_id=class_teacher.class_name_id join master on master.master_id= employee.employee_id WHERE class_name.class_name_id in (" . join(',', $teacher) . ") AND `employee_teacher`=1 GROUP BY teacher_id"; if ((isset($postdata['parent_id']) == 'on') || (isset($postdata['staff_id']) == 'on')) $sql.=" union "; } } if (isset($postdata['parent_id']) == 'on') { $parent = array(); if (isset($postdata['parent_class_name_id'])) { for ($i = 0; $i < count($postdata['parent_class_name_id']); $i++) { $c_id = $postdata['parent_class_name_id'][$i]; $parent[] = $c_id; } } if (count($parent) > 0) { $sql.="(select parent.parent_id as sort_id,master_id,menu_id,CONCAT (parent.father_name,' - ',student.first_name,' ',student.last_name) as name,student.reg_no as reg, nationality.nationality_name as nationality, student.gender as gender, parent.father_mobile_no as mobile_no, 'Father' as type,class_name_code from student_class join class_name on class_name.class_name_id=student_class.class_name_id join student on student.student_id=student_class.student_id join nationality on student.nationality_id=nationality.nationality_id join parent_student on parent_student.student_id=student_class.student_id join parent on parent.parent_id=parent_student.parent_id join master on master.master_id= parent.parent_id left join student_cancellation on student_cancellation.student_class_id=student_class.student_class_id WHERE class_name.class_name_id in (" . join(',', $parent) . ") AND cancellation_id is null GROUP BY parent.parent_id ORDER BY student.student_id )"; $sql.="UNION (select parent.parent_id as sort_id,master_id,menu_id,CONCAT (parent.mother_name,' - ',student.first_name,' ',student.last_name) as name,student.reg_no as reg, nationality.nationality_name as nationality, student.gender as gender, parent.mother_mobile_no as mobile_no, 'Mother' as type,class_name_code from student_class join class_name on class_name.class_name_id=student_class.class_name_id join student on student.student_id=student_class.student_id join nationality on student.nationality_id=nationality.nationality_id join parent_student on parent_student.student_id=student_class.student_id join parent on parent.parent_id=parent_student.parent_id join master on master.master_id= parent.parent_id left join student_cancellation on student_cancellation.student_class_id=student_class.student_class_id WHERE class_name.class_name_id in (" . join(',', $parent) . ") AND cancellation_id is null GROUP BY parent.parent_id ORDER BY student.student_id )"; if (isset($postdata['staff_id']) == 'on') $sql.=" union "; } } if (isset($postdata['staff_id']) == 'on') { $sql.= "(select master_id as sort_id, master_id ,menu_id,employee_name as name, employee_no as reg, nationality.nationality_name as nationality, employee_gender as gender, employee.employee_mobile_no as mobile_no, 'Employee' as type,'' class_name_code from employee join nationality on employee.employee_nationality_id=nationality.nationality_id join master on master.master_id= employee.employee_id where `employee_teacher`=0 GROUP BY employee.employee_id"; if (isset($postdata['department_id'])) { $ids = join(',', $postdata['department_id']); $sql.=" and employee_department_id in (" . $ids . "))"; } } if($sql!=''){ $sql.=" ORDER BY sort_id ASC "; $data['results'] = $this->db->query($sql); } else $data['results'] = ""; return $data; } } function insertbulksms($postdata) { $data = array(); $data['resfunction'] = 'search_bulk_sms'; $smsdata = $this->mastermodel->getdatas('smssettings'); foreach ($smsdata as $smsinfo) { $username = $smsinfo['username']; $password = $smsinfo['password']; $domain = $smsinfo['domain']; } $message = $postdata['message']; $sender = $postdata['sender_id']; $method = "POST"; $username = urlencode($username); $password = urlencode($password); $sender = urlencode($sender); $message = urlencode($message); $datetime = date("Y-m-d H:i:s"); if ($username == '' || $password == '' || $domain == '') { $data['res'] = 0; $data['msg'] = 'Configure SMS Settings'; return $data; } else { $this->db->trans_begin(); $masterid = $this->mastermodel->insertmasterdata(); $tbl1Values = array( 'sms_id' => $masterid, 'sms_contents' => $postdata['message'], 'sms_date' => date("Y-m-d"), 'sender_id' => $postdata['sender_id'], ); $this->db->insert('smsreport', $tbl1Values); for ($i = 1; $i <= $postdata['moblen']; $i++) { if (isset($postdata['check_mobile_' . $i]) == "on") { if ($postdata['status'] == "Sent") { $numbers = $postdata['check_mobile_' . $i]; $numbers=$this->add_areacode($numbers); $opts = array( 'http' => array( 'method' => "$method", 'content' => "username=$username&password=$password&type=5&dlr=1&destination=$numbers&message=$message&source=$sender", 'header' => "Accept-language: en\r\n" . "Content-type: application/x-www-form-urlencoded\r\n" . "Cookie: foo=bar\r\n" ) ); $context = stream_context_create($opts); $fp = fopen("$domain", "r", false, $context); $response = @stream_get_contents($fp); if (strpos($response,'1701') !== false) $status = "Sent"; else $status = "Not Sent"; fpassthru($fp); fclose($fp); } else { $status = "Saved"; } $tbl1Values = array( 'sms_id' => $masterid, 'receipent_type' => $postdata['receipent_type_' . $i], 'receipent_name' => $postdata['receipent_name_' . $i], 'numbers' => $postdata['check_mobile_' . $i], 'status' => $status, 'datetime' => $datetime); $this->db->insert('sendsms', $tbl1Values); } } if ($this->db->trans_status() === FALSE) { $this->db->trans_rollback(); $data['res'] = 0; $data['msg'] = 'Error On Adding Record'; return $data; } else { $this->db->trans_commit(); $data['res'] = 1; $data['msg'] = 'Record Added Successfully'; return $data; } } } function search_sms_settings() { $data = array(); $this->db->select('*'); $this->db->from('smssettings'); $data['results'] = $this->db->get(); return $data; } function insert_sms_settings($postdata) { $data = array(); $this->db->trans_begin(); $this->db->truncate('smssettings'); $tbl1Values = array( 'username' => $postdata['username'], 'domain' => $postdata['domain'], 'password' => $postdata['password']); $this->db->insert('smssettings', $tbl1Values); $data['resfunction'] = 'search_sms_settings'; if ($this->db->trans_status() === FALSE) { $this->db->trans_rollback(); $data['res'] = 0; $data['msg'] = 'Error On Adding Record'; return $data; } else { $this->db->trans_commit(); $data['res'] = 1; $data['msg'] = 'Record Added Successfully'; return $data; } } function search_sms_reports() { $data = array(); $this->db->select('*'); $this->db->from('smsreport'); $this->db->order_by('sms_id', 'desc'); $data['results'] = $this->db->get(); return $data; // $data = array(); // $this->db->select('*'); // $this->db->from('sendsms'); // $this->db->order_by('datetime', "desc"); // $data['results'] = $this->db->get(); // return $data; } function search_sms_draft() { $data = array(); $this->db->select('*'); $this->db->from('sendsms'); $this->db->where('status', 'Saved'); $this->db->order_by('datetime', "desc"); $data['results'] = $this->db->get(); return $data; } function senddraft($smsid) { $data = array(); $datetime = date("Y-m-d H:i:s"); $smsdata = $this->mastermodel->getdatas('smssettings'); $data['resfunction'] = 'search_sms_draft'; foreach ($smsdata as $smsinfo) { $username = $smsinfo['username']; $password = $smsinfo['password']; $domain = $smsinfo['domain']; } $draft = $this->mastermodel->get_data_srow('sendsms', $smsid, 'id'); $message = $draft->message; $sender = $draft->sender_id; $numbers = $draft->numbers; $numbers=$this->add_areacode($numbers); $method = "POST"; $username = urlencode($username); $password = urlencode($password); $sender = urlencode($sender); $message = urlencode($message); if ($username == '' || $password == '' || $domain == '') { return 0; } else { $this->db->trans_begin(); $opts = array( 'http' => array( 'method' => "$method", 'content' => "username=$username&password=$password&type=5&dlr=1&destination=$numbers&message=$message&source=$sender", 'header' => "Accept-language: en\r\n" . "Content-type: application/x-www-form-urlencoded\r\n" . "Cookie: foo=bar\r\n" ) ); $context = stream_context_create($opts); $fp = fopen("$domain", "r", false, $context); $response = @stream_get_contents($fp); if (strpos($response,'1701') !== false) { $status = "Sent"; } else { $status = "Not Sent"; return 0; } fpassthru($fp); fclose($fp); $tbl1Values = array( 'sender_id' => $draft->sender_id, 'message' => $draft->message, 'numbers' => $numbers, 'status' => $status, 'datetime' => $datetime); $this->db->where('id', $smsid); $this->db->update('sendsms', $tbl1Values); if ($this->db->trans_status() === FALSE) { $this->db->trans_rollback(); return 0; } else { $this->db->trans_commit(); return 1; } } } function search_sms_template() { $data = array(); $this->db->select('*'); $this->db->from('template'); $data['results'] = $this->db->get(); return $data; } function insert_sms_template($postdata) { $data = array(); $this->db->trans_begin(); $tbl1Values = array( 'template_title' => $postdata['template_title'], 'content' => $postdata['content']); $this->db->insert('template', $tbl1Values); $data['resfunction'] = 'search_sms_template'; if ($this->db->trans_status() === FALSE) { $this->db->trans_rollback(); $data['res'] = 0; $data['msg'] = 'Error On Adding Record'; return $data; } else { $this->db->trans_commit(); $data['res'] = 1; $data['msg'] = 'Record Added Successfully'; return $data; } } function update_sms_template($postdata) { $data = array(); $this->db->trans_begin(); $tbl1Values = array( 'template_title' => $postdata['template_title'], 'content' => $postdata['content']); $this->db->where('template_id', $postdata['template_id']); $this->db->update('template', $tbl1Values); $data['resfunction'] = 'search_sms_template'; if ($this->db->trans_status() === FALSE) { $this->db->trans_rollback(); $data['res'] = 0; $data['msg'] = 'Error On Updating Record'; return $data; } else { $this->db->trans_commit(); $data['res'] = 1; $data['msg'] = 'Record Updated Successfully'; return $data; } } function add_areacode($number) { if (!preg_match("~^(?:t)974~i", $number)) { $number = "974" . $number; } return $number; } } ?>