first commit

This commit is contained in:
ryanwong
2022-06-30 05:46:02 -04:00
commit a96eaec33b
859 changed files with 199842 additions and 0 deletions
+72
View File
@@ -0,0 +1,72 @@
<?php
use Aws\S3\S3Client;
class Aws_service
{
public $_image_model;
public $_s3;
public $_bucket;
public function set_s3 ($version, $region, $key, $secret)
{
$this->_s3 = new S3Client([
'version' => $version,
'region' => $region,
'credentials' => [
'key' => $key,
'secret' => $secret
]
]);
}
public function set_image_model ($image_model)
{
$this->_image_model = $image_model;
}
public function set_bucket ($bucket)
{
$this->_bucket = $bucket;
}
public function delete_image ($image_id)
{
try
{
$model = $this->_image_model->get($image_id);
$url = $model->url;
$this->delete_image_url($url);
$this->_image_model->real_delete($image_id);
return TRUE;
}
catch (AwsExceptionInterface $e)
{
// throw Exception\StorageException::deleteError($path, $e);
return FALSE;
}
}
public function delete_image_url ($url)
{
try
{
$matches = [];
$re = '/\/com.nds.*\//m';
preg_match_all($re, $url, $matches, PREG_SET_ORDER, 0);
if(count($matches) == 1 && count($matches[0]) == 1)
{
$bucket = str_replace('/','', $matches[0][0]);
$parts = explode('/', $url);
$key = $parts[count($parts) - 1];
$this->_s3->deleteObject(['Bucket' => $bucket, 'Key' => $key]);
}
return TRUE;
}
catch (AwsExceptionInterface $e)
{
// throw Exception\StorageException::deleteError($path, $e);
return FALSE;
}
}
}
+36
View File
@@ -0,0 +1,36 @@
<?php
/*Powered By: Manaknightdigital Inc. https://manaknightdigital.com/ Year: 2021*/
/**
* Barcode_service
*
* @copyright 2021 Manaknightdigital Inc.
* @link https://manaknightdigital.com
* @license Proprietary Software licensing
* @author Ryan Wong
*/
class Barcode_service
{
public function generate_png_barcode($barcode,$manual_text = null)
{
if($manual_text == null)
{
$barcode_image_name = '/uploads/' . $barcode . '-barcode.png';
}
else
{
$barcode_image_name = '/uploads/' . $barcode . '-' . $manual_text . '-barcode.png';
}
$generator = new Picqer\Barcode\BarcodeGeneratorPNG();
$black_color = [0, 0, 0];
$file_name = __DIR__ . '/../../../' . $barcode_image_name;
$barcode = $generator->getBarcode($barcode, $generator::TYPE_CODE_128 ,3 , 50, $black_color);
if(file_put_contents($file_name, $barcode))
{
return $barcode_image_name;
}
}
}
+81
View File
@@ -0,0 +1,81 @@
<?php
defined('BASEPATH') or exit('No direct script access allowed');
/*Powered By: Manaknightdigital Inc. https://manaknightdigital.com/ Year: 2021*/
/**
* Cache Class
*/
class Cache_service
{
public $_type = 'file';
/**
* Cache Adapter.
*
* @var mixed
*/
public $_adapter = null;
/**
* Cache time
*
* @var mixed
*/
public $_cache_time = 3600;
public function set_adapter($type, $cache_time=3600)
{
$this->_type = $type;
$this->_cache_time = $cache_time;
switch ($type)
{
case 'file':
$this->_adapter = null;
break;
default:
break;
}
}
/**
* Set cache Key
*
* @param string $key
* @param mixed $value
* @return void
*/
public function set($key, $value)
{
file_put_contents(__DIR__ . '/../config/' . md5($key) . '.json', json_encode($value));
}
public function get($key)
{
$file_path = __DIR__ . '/../config/' . md5($key) . '.json';
if (file_exists($file_path))
{
if (time() - $this->_cache_time < filemtime($file_path))
{
$data = file_get_contents($file_path);
return json_decode($data, TRUE);
}
else
{
unlink($file_path);
}
}
return NULL;
}
public function remove($key)
{
$file_path = __DIR__ . '/../config/' . md5($key) . '.json';
if (file_exists($file_path))
{
unlink($file_path);
return TRUE;
}
return NULL;
}
}
+265
View File
@@ -0,0 +1,265 @@
<?php defined('BASEPATH') OR exit('No direct script access allowed');
/*Powered By: Manaknightdigital Inc. https://manaknightdigital.com/ Year: 2021*/
/**
* CSV Import Service
* @copyright 2019 Manaknightdigital Inc.
* @link https://manaknightdigital.com
* @license Proprietary Software licensing
* @author Ryan Wong
*
*/
use Box\Spout\Reader\Common\Creator\ReaderEntityFactory;
class Csv_import_service
{
protected $_model;
protected $_model_name;
public function set_model($model, $model_name)
{
$this->_model = $model;
$this->_model_name = $model_name;
}
/**
* CSV File Exist
*
* @param array $files
* @return boolean
*/
public function csv_file_exist($files)
{
return !(isset($files) && count($files) > 0 && isset($files['file']));
}
/**
* Make the import insert query
* Steps:
* 1.Figure out the last id
* 2.Find out schema
* 3.Loop through each line and make sure schema match
* 4.Else return error
* 5.If everything correct, dump sql out
* 6.Insert sql into database
*
* @param [type] $file
* @return void
*/
public function make_query($file)
{
$last_id = $this->_model->get_last_id();
$schema = $this->_model->get_schema();
$insert_query_template_start = "INSERT INTO `{$this->_model_name}` (";
$insert_query_template_middle = ') VALUES ';
$line_num = 1;
$insert_query_list = [];
foreach ($schema as $field_num => $field)
{
$field_list[] = "`$field->name`";
}
$field_list_str = implode(',', $field_list);
$insert_query = "{$insert_query_template_start}{$field_list_str} {$insert_query_template_middle} ";
while (($getData = fgetcsv($file, 1000000, ';')) !== FALSE)
{
$valid = TRUE;
$field_list = [];
if(count($getData) > 0)
{
$new_id = (int) $getData[0];
}
else
{
return [
'status' => FALSE,
'message' => 'Missing ID on Line ' . $line_num
];
}
if (!$getData)
{
// error_log('LINE FAILED ON: ' . $line_num);
return [
'status' => FALSE,
'message' => 'Fail to get data on line ' . $line_num
];
}
foreach ($schema as $field_num => $field)
{
// error_log("{$field_num} {$field->type} $getData[$field_num]\n");
$valid = $valid && $this->_model->verify_field_type($getData[$field_num], $field->type);
if (!$valid)
{
return [
'status' => FALSE,
'message' => 'Fail to get data on line ' . $line_num . '. Field Type did not match ' . $field->name
];
}
}
if ($new_id < $last_id)
{
return [
'status' => FALSE,
'message' => 'Fail to get data on line ' . $line_num . '. Field ID conflict with another row ' . $new_id
];
}
if ($valid)
{
$insert_query_list []= "('" . implode('\',\'', $getData) . "')";
$field_list = [];
}
$line_num++;
}
return [
'status' => TRUE,
'message' => $insert_query . implode(',', $insert_query_list) . ';'
];
}
/**
* Take file, make array
*
* @param [type] $file
* @return void
*/
public function get_csv_data($file)
{
$line_num = 1;
$result = [];
$handle = fopen($file, "r");
while (($getData = fgetcsv($handle, 1000000, ';')) !== FALSE)
{
$valid = TRUE;
if(count($getData) > 0)
{
$new_id = (int) $getData[0];
}
else
{
return [
'status' => FALSE,
'message' => 'Missing ID on Line ' . $line_num
];
}
if (!$getData)
{
// error_log('LINE FAILED ON: ' . $line_num);
return [
'status' => FALSE,
'message' => 'Fail to get data on line ' . $line_num
];
}
if ($valid)
{
$result[] = $getData;
}
$line_num++;
}
return [
'status' => TRUE,
'data' => $result
];
}
public function import ($query)
{
return $this->_model->raw_no_error_query($query);
}
public function _import_data($file)
{
try
{
$reader = ReaderEntityFactory::createReaderFromFile( $file );
$reader->open($file);
$import_fields = $this->_model->get_import_fields();
if(empty($import_fields))
{
return false;
}
$payload = [];
foreach ($reader->getSheetIterator() as $sheet)
{
foreach($sheet->getRowIterator() as $row)
{
$cells = $row->getCells();
$temp = [];
for($i = 0; $i < count($cells); $i ++)
{
$temp[ $import_fields[$i] ] = $cells[$i]->getValue();
}
$payload[] = $temp;
}
}
if(!empty($payload))
{
return $this->_model->batch_insert($payload);
}
return FALSE;
}
catch(Exception $e)
{
return FALSE;
}
}
public function _get_file_data($file)
{
try
{
$reader = ReaderEntityFactory::createReaderFromFile( $file );
$reader->open($file);
$payload = [];
foreach ($reader->getSheetIterator() as $sheet)
{
foreach($sheet->getRowIterator() as $row)
{
$cells = $row->getCells();
$temp = [];
for($i = 0; $i < count($cells); $i ++)
{
$temp[] = $cells[$i]->getValue();
}
$payload[] = $temp;
}
}
return $payload;
}
catch(Exception $e)
{
return [];
}
}
}
+41
View File
@@ -0,0 +1,41 @@
<?php
class Helpers_service
{
private $_inventory_model;
/**
* setters
*/
public function set_inventory_model($inventory_model)
{
$this->_inventory_model = $inventory_model;
}
/**
* getters
*/
public function get_word_count($id)
{
$word_count = "N/A";
$check_data = $this->_inventory_model->get($id);
if (isset($check_data->word_count))
{
$word_count = $check_data->word_count;
}
return $word_count;
}
public function get_year($id)
{
$year = "N/A";
$check_data = $this->_inventory_model->get($id);
if (isset($check_data->year))
{
$year = $check_data->year;
}
return $year;
}
}
+165
View File
@@ -0,0 +1,165 @@
<?php
use Mailgun\Mailgun;
defined('BASEPATH') or exit('No direct script access allowed');
/*Powered By: Manaknightdigital Inc. https://manaknightdigital.com/ Year: 2021*/
class Mail_service
{
/**
* Mail Adapter.
*
* @var mixed
*/
public $_adapter = null;
/**
* Adapter selected.
*
* @var string
*/
public $_type = '';
/**
* Domain send from.
*
* @var string
*/
public $_domain = '';
/**
* Platform name.
*
* @var string
*/
public $_platform_name = '';
/**
* From name.
*
* @var string
*/
public $_from_name = '';
/**
* CI.
*
* @var mixed
*/
public $_ci = null;
/**
* Set mail service to correct way to send emails.
*
* @param string $type
*
* @throws Exception
*/
public function set_adapter($type)
{
$this->_type = $type;
$this->_ci = &get_instance();
$this->_platform_name = $this->_ci->config->item('platform_name');
switch ($type)
{
case 'mailgun':
$this->_adapter = Mailgun::create($this->_ci->config->item('mailgun_key'));
$this->_domain = $this->_ci->config->item('mail_domain');
break;
case 'test':
break;
case 'smtp':
default:
$this->_ci->load->library('email');
$settings = $this->_ci->config->item('email_smtp');
if (empty($settings))
{
throw new Exception('Email not setup');
}
$this->_from_name = $settings['smtp_name'];
$this->_adapter = $this->_ci->email->initialize($settings);
break;
}
}
/**
* Set domain to send from (mailgun exclusive).
*
* @param string $domain
*/
public function setDomain($domain)
{
$this->_domain = $domain;
}
/**
* Send email.
*
* @param string $from
* @param string $to
* @param string $subject
* @param string $html
*/
public function send($from, $to, $subject, $html, $reply_to = "")
{
switch ($this->_type) {
case 'mailgun':
return $this->_adapter->messages()->send($this->_domain, [
'from' => $from,
'to' => $to,
'subject' => $subject,
'html' => $html,
]);
break;
case 'test':
return [
'from' => $from,
'to' => $to,
'subject' => $subject,
'html' => $html
];
break;
case 'smtp':
default:
$this->_ci->load->library('encryption');
$this->_adapter->to($to);
$this->_adapter->from($from, $this->_from_name);
$this->_adapter->subject($subject);
if ($reply_to != "" || $this->_ci->session->userdata('email') )
{
$f_email = $this->_ci->session->userdata('email');
if ($f_email && !empty($f_email) )
{
$f_email = $this->_ci->session->userdata('email');
$this->_adapter->reply_to($f_email);
}else
{
$this->_adapter->reply_to($reply_to);
}
}
$this->_adapter->message($html);
$result = $this->_adapter->send();
if (!$result)
{
// echo "<pre>";
// // print_r($this->_adapter);
// print_r($this->_adapter->print_debugger());
// die();
error_log($this->_adapter->print_debugger());
}
return $result;
break;
}
}
}
+94
View File
@@ -0,0 +1,94 @@
<?php
defined('BASEPATH') or exit('No direct script access allowed');
/*Powered By: Manaknightdigital Inc. https://manaknightdigital.com/ Year: 2021*/
class Mime_service
{
protected $_types = [
'text/markdown' => '.md',
'audio/aac' => '.aac',
'application/x-abiword' => '.abw',
'application/x-freearc' => '.arc',
'video/x-msvideo' => '.avi',
'application/vnd.amazon.ebook' => '.azw',
'application/octet-stream' => '.bin',
'image/bmp' => '.bmp',
'application/x-bzip' => '.bz',
'application/x-bzip2' => '.bz2',
'application/x-csh' => '.csh',
'text/css' => '.css',
'text/csv' => '.csv',
'application/msword' => '.doc',
'application/vnd.openxmlformats-officedocument.wordprocessingml.document' => '.docx',
'application/vnd.ms-fontobject' => '.eot',
'application/epub+zip' => '.epub',
'image/gif' => '.gif',
'text/html' => '.html',
'image/vnd.microsoft.icon' => '.ico',
'text/calendar' => '.ics',
'application/java-archive' => '.jar',
'image/jpeg' => '.jpg',
'image/jpg' => '.jpg',
'text/javascript' => '.js',
'application/json' => '.json',
'application/ld+json' => '.jsonld',
'audio/midi' => '.mid',
'audio/x-midi' => '.midi',
'text/javascript' => '.javascript',
'audio/mp3' => '.mp3',
'audio/mp4' => '.mp3',
'audio/mpeg' => '.mp3',
'video/mpeg' => '.mpeg',
'application/vnd.apple.installer+xml' => '.mpkg',
'application/vnd.oasis.opendocument.presentation' => '.odp',
'application/vnd.oasis.opendocument.spreadsheet' => '.ods',
'application/vnd.oasis.opendocument.text' => '.odt',
'audio/ogg' => '.oga',
'video/ogg' => '.ogv',
'application/ogg' => '.ogx',
'font/otf' => '.otf',
'image/png' => '.png',
'application/pdf' => '.pdf',
'application/vnd.ms-powerpoint' => '.ppt',
'application/vnd.openxmlformats-officedocument.presentationml.presentation' => '.pptx',
'application/x-rar-compressed' => '.rar',
'application/rtf' => '.rtf',
'application/x-sh' => '.sh',
'image/svg+xml' => '.svg',
'application/x-shockwave-flash' => '.swf',
'application/x-tar' => '.tar',
'image/tiff' => '.tiff',
'video/mp2t' => '.ts',
'font/ttf' => '.ttf',
'text/plain' => '.txt',
'application/vnd.visio' => '.vsd',
'audio/wav' => '.wav',
'audio/webm' => '.weba',
'video/webm' => '.webm',
'image/webp' => '.webp',
'font/woff' => '.woff',
'font/woff2' => '.woff2',
'application/xhtml+xml' => '.xhtml',
'application/vnd.ms-excel' => '.xls',
'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet' => '.xlsx',
'application/xml' => '.xml',
'text/xml' => '.xml',
'application/vnd.mozilla.xul+xml' => '.xul',
'application/zip' => '.zip',
'video/3gpp' => '.3pg',
'audio/3gpp' => '.3gp',
'video/3gpp2' => '.3g2',
'audio/3gpp2' => '.3g2',
'application/x-7z-compressed' => '.7z',
'video/mp4' => '.mp4'
];
public function get_extension($type) {
if(in_array($type, array_keys($this->_types)))
{
return $this->_types[$type];
}
return str_replace('/', '', $type);
}
}
+98
View File
@@ -0,0 +1,98 @@
<?php
class Names_helper_service
{
private $_user_model;
private $_school_model;
private $_professor_model;
private $_classes_model;
private $_textbook_model;
/**
* setters
*/
public function set_user_model($user_model)
{
$this->_user_model = $user_model;
}
public function set_school_model($school_model)
{
$this->_school_model = $school_model;
}
public function set_professor_model($professor_model)
{
$this->_professor_model = $professor_model;
}
public function set_textbook_model($textbook_model)
{
$this->_textbook_model = $textbook_model;
}
public function set_classes_model($classes_model)
{
$this->_classes_model = $classes_model;
}
/**
* getters
*/
public function get_user_full_name($id)
{
$full_name = "N/A";
$check_data = $this->_user_model->get($id);
if (isset($check_data->first_name))
{
$full_name = $check_data->first_name . ' ' . $check_data->last_name;
}
return $full_name;
}
public function get_school_name($id)
{
$name = "N/A";
$check_data = $this->_school_model->get($id);
if (isset($check_data->name))
{
$name = $check_data->name;
}
return $name;
}
public function get_professor_name($id)
{
$name = "N/A";
$check_data = $this->_professor_model->get($id);
if (isset($check_data->name))
{
$name = $check_data->name;
}
return $name;
}
public function get_class_name($id)
{
$name = "N/A";
$check_data = $this->_classes_model->get($id);
if (isset($check_data->name))
{
$name = $check_data->name;
}
return $name;
}
public function get_textbook_name($id)
{
$name = "N/A";
$check_data = $this->_textbook_model->get($id);
if (isset($check_data->name))
{
$name = $check_data->name;
}
return $name;
}
}
File diff suppressed because it is too large Load Diff
+222
View File
@@ -0,0 +1,222 @@
<?php defined('BASEPATH') or exit('No direct script access allowed');
/*Powered By: Manaknightdigital Inc. https://manaknightdigital.com/ Year: 2021*/
/**
* Push Notification Service
*
* @copyright 2019 Manaknightdigital Inc.
* @link https://manaknightdigital.com
* @license Proprietary Software licensing
* @author Ryan Wong
*/
class Push_notification_service
{
/**
* Push Notification URL
*
* @var string
*/
private $_url;
/**
* Push Notification Server Key
*
* @var string
*/
private $_server_key;
/**
* Push Notification Project Id
*
* @var string
*/
private $_project_id;
/**
* CI.
*
* @var mixed
*/
public $_ci = null;
public function init()
{
$this->_url = 'https://fcm.googleapis.com/fcm/send';
$this->_ci = &get_instance();
$this->_server_key = $this->_ci->config->item('push_server_key');
$this->_project_id = $this->_ci->config->item('push_project_id');
}
/**
* Send push notification
* https://firebase.google.com/docs/cloud-messaging/admin/send-messages.
*
* @param string $device_type
* @param string $device_id
* @param string $title
* @param string $message
* @param string $image
*/
private function _send_request($fields)
{
$headers = [
'Content-Type:application/json', 'project_id:' . $this->_project_id,
'Authorization:key=' . $this->_server_key,
];
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $this->_url);
curl_setopt($ch, CURLOPT_POST, TRUE);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($fields));
curl_exec($ch);
curl_close($ch);
return $ch;
}
public function send($device_type, $device_id, $title, $message, $image = '', $data = [])
{
$payload = [];
$fields = [
'registration_ids' => [
$device_id
],
'notification' => [
'title' => $title,
'body' => $message
],
];
if ($device_type == 'ANDROID')
{
$fields = [
'registration_ids' => [
$device_id
],
'data' => [
'title' => $title,
'message' => $message,
'image' => $image,
"channelId" => "default",
"data" => $data
],
'notification' => [
'title' => $title,
'body' => $message
]
];
if(!empty($data) && is_array($data))
{
$fields['data'] = array_merge( $fields['data'], $data);
}
}
if($device_type == 'IOS')
{
$notification =[
'title' =>$title ,
'text' => $message,
'sound' => 'default',
'badge' => '0'
];
$fields = [
'to' => $device_id,
'notification' => $notification,
'priority' => 'high',
'data' => $data
];
}
$headers = [
'Content-Type:application/json', 'project_id:' . $this->_project_id,
'Authorization:key=' . $this->_server_key,
];
$payload['headers'] = $headers;
$payload['fields'] = $fields;
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $this->_url);
curl_setopt($ch, CURLOPT_POST, TRUE);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($fields));
curl_exec($ch);
curl_close($ch);
return $ch;
}
public function send_multiple($devices, $title, $message, $image = '', $data = [])
{
$ios_ids = [];
$android_ids = [];
foreach($devices as $device)
{
if($device['type'] == 'ANDROID')
{
$android_ids[] = $device['device_id'];
}
if($device['type'] == 'IOS')
{
$ios_ids[] = $device['device_id'];
}
}
if(count($android_ids) > 0)
{
$fields = [
'registration_ids' => $android_ids,
'data' => [
'title' => $title,
'message' => $message,
'image' => $image,
"channelId" => "default",
"data" => $data
],
'notification' => [
'title' => $title,
'body' => $message
]
];
if(!empty($data) && is_array($data))
{
$fields['data'] = array_merge($fields['data'], $data);
}
$this->_send_request($fields);
}
if(count($ios_ids) > 0)
{
$notification =[
'title' =>$title ,
'text' => $message,
'sound' => 'default',
'badge' => '0'
];
$fields = [
'to' => $ios_ids,
'notification' => $notification,
'priority' => 'high',
'data' => $data
];
$this->_send_request($fields);
}
}
}
+54
View File
@@ -0,0 +1,54 @@
<?php
/*Powered By: Manaknightdigital Inc. https://manaknightdigital.com/ Year: 2021*/
/**
* Barcode_service
*
* @copyright 2021 Manaknightdigital Inc.
* @link https://manaknightdigital.com
* @license Proprietary Software licensing
* @author Ryan Wong
*/
class Redirect_custom_service
{
private $_url_redirect_model;
public function set_url_redirect_model($url_redirect_model)
{
$this->_url_redirect_model = $url_redirect_model;
}
public function check_redirect()
{
$current_url = current_url();
$params = $_SERVER['QUERY_STRING'];
if(!empty($params))
{
$full_url = $current_url . '?' . $params;
}
else
{
$full_url = $current_url;
}
$check_data =$this->_url_redirect_model->get_by_fields([
'url' => $full_url
]);
if(!empty($check_data))
{
$rewrite_url = $this->add_http($check_data->rewrite_url);
return redirect($rewrite_url);
}
}
public function add_http($url)
{
if (!preg_match("~^(?:f|ht)tps?://~i", $url))
{
$url = 'https://' . $url;
}
return $url;
}
}
+20
View File
@@ -0,0 +1,20 @@
<?php
/*Powered By: Manaknightdigital Inc. https://manaknightdigital.com/ Year: 2021*/
/**
* Barcode_service
*
* @copyright 2021 Manaknightdigital Inc.
* @link https://manaknightdigital.com
* @license Proprietary Software licensing
* @author Ryan Wong
*/
class Slug_service
{
function create_slug($string)
{
$slug = trim($string);
$slug = strtolower($slug);
$slug = str_replace(' ', '-', $slug);
return $slug;
}
}
+236
View File
@@ -0,0 +1,236 @@
<?php if (! defined('BASEPATH')) exit('No direct script access allowed');
use Twilio\Rest\Client;
/*Powered By: Manaknightdigital Inc. https://manaknightdigital.com/ Year: 2021*/
/**
* Sms Service
*
* @copyright 2019 Manaknightdigital Inc.
* @link https://manaknightdigital.com
* @license Proprietary Software licensing
* @author Ryan Wong
*/
class Sms_service
{
/**
* Mail Adapter
*
* @var mixed
*/
public $_adapter = null;
/**
* Adapter selected
*
* @var string
*/
public $_type = '';
/**
* From Number
*
* @var string
*/
public $_from = '';
/**
* CI
*
* @var mixed
*/
public $_ci = null;
/**
* Set mail service to correct way to send emails
*
* @param string $type
* @throws Exception
*/
public function set_adapter ($type)
{
$this->_type = $type;
$this->_ci = &get_instance();
$this->_from = $this->_ci->config->item('twilio_phone_number');
switch ($type)
{
case 'sms':
$this->_adapter = new Client($this->_ci->config->item('twilio_sid'), $this->_ci->config->item('twilio_token'));
break;
case 'whatsapp':
// Your Account Sid and Auth Token from twilio.com/user/account
$this->_adapter = new Client($this->_ci->config->item('twilio_sid'), $this->_ci->config->item('twilio_token'));
case 'test':
break;
default:
break;
}
}
/**
* Send email
*
* @param string $to
* @param string $message
*/
public function send ($to, $message)
{
switch ($this->_type)
{
case 'sms':
try {
$result = $this->_adapter->messages->create(
"{$to}",
[
'from' => "{$this->_from}",
'body' => $message,
]
);
error_log('TO: ' . $to);
error_log('Message: ' . $message);
error_log('Result: ' . $result);
if (!$result || !$result->sid)
{
return NULL;
}
// error_log(print_r($result, TRUE));
return $result->sid;
} catch (Exception $e) {
error_log('TO: ' . $to);
error_log('Message: ' . $message);
error_log('SMS Error: ' . $e->getMessage());
return FALSE;
}
break;
case 'test':
return TRUE;
break;
case 'whatsapp':
try {
$result = $this->_adapter->messages->create(
"whatsapp:{$to}",
[
'from' => "whatsapp:{$this->_from}",
'body' => $message,
]
);
error_log('TO: ' . $to);
error_log('Message: ' . $message);
error_log('Result: ' . $result);
return TRUE;
} catch (Exception $e) {
error_log('TO: ' . $to);
error_log('Message: ' . $message);
error_log('SMS Error: ' . $e->getMessage());
return FALSE;
}
break;
default:
break;
}
}
/**
* Send email
*
* @param string $to
* @param string $message
*/
public function send_callback ($to, $message, $callback_url)
{
switch ($this->_type)
{
case 'sms':
try {
$result = $this->_adapter->messages->create(
"{$to}",
[
'from' => "{$this->_from}",
'body' => $message,
'statusCallback' => $callback_url
]
);
error_log('TO: ' . $to);
error_log('Message: ' . $message);
error_log('Result: ' . $result);
if (!$result || !$result->sid)
{
return NULL;
}
// error_log(print_r($result, TRUE));
return $result->sid;
} catch (Exception $e) {
error_log('TO: ' . $to);
error_log('Message: ' . $message);
error_log('SMS Error: ' . $e->getMessage());
return FALSE;
}
break;
case 'test':
return TRUE;
break;
case 'whatsapp':
try {
$result = $this->_adapter->messages->create(
"whatsapp:{$to}",
[
'from' => "whatsapp:{$this->_from}",
'body' => $message,
]
);
error_log('TO: ' . $to);
error_log('Message: ' . $message);
error_log('Result: ' . $result);
return TRUE;
} catch (Exception $e) {
error_log('TO: ' . $to);
error_log('Message: ' . $message);
error_log('SMS Error: ' . $e->getMessage());
return FALSE;
}
break;
default:
break;
}
}
public function retrieve_single_sms_log ($sid)
{
return $this->_adapter->messages($sid)->fetch();
}
public function add_country_code ($country_code=1, $phone_number)
{
$str_phone = (string) $phone_number;
if (substr($str_phone, 0, $country_code) === $country_code)
{
return '+' . $phone_number;
}
else
{
return '+' . $country_code . $phone_number;
}
}
public function add_custom_country_code ($country_code=1, $phone_number)
{
$str_phone = (string) $phone_number;
if (substr($str_phone, 0, $country_code) === $country_code)
{
return '+' . $phone_number;
}
else
{
return '+' . $country_code . $phone_number;
}
}
}
+105
View File
@@ -0,0 +1,105 @@
<?php
use \Stripe\Stripe;
use \Stripe\Customer;
use \Stripe\Charge;
use \Stripe\Refund;
use \Stripe\Plan;
use \Stripe\Coupon;
use \Stripe\Product;
use \Stripe\Subscription;
use \Stripe\Invoice;
use \Stripe\Error;
use \Stripe\Webhook;
use \Stripe\Source;
use \Stripe\Dispute;
use \Stripe\File;
use \Stripe\Exception;
use \Stripe\Event;
use \Stripe\InvoiceItem;
use \Stripe\PaymentMethod;
class Stripe_ach_invoice_service
{
protected $_config;
public function set_config($config)
{
$this->_config = $config;
}
public function send_ach_invoice_sale_order($customer_real_name, $customer_email, $customer_phone, $total, $days_until_due)
{
$stripe_secret_key = $this->_config->item('stripe_secret_key');
Stripe::setApiKey( $stripe_secret_key );
try
{
$customer = Customer::create([
'name' => $customer_real_name,
'email' => $customer_email,
'description' => $customer_phone,
]);
$amount = $total * 100;
try
{
$invoice_item = InvoiceItem::create([
'amount' => $amount,
'currency' => 'usd',
'customer' => $customer->id,
'description' => 'Sale Order Invoice'
]);
if ($invoice_item)
{
try
{
// pulls in invoice items
$invoice_detail = Invoice::create(array(
'customer' => $customer->id,
'collection_method' => 'send_invoice',
'days_until_due' => $days_until_due,
));
try
{
$output['invoice_id'] = $invoice_detail->id;
return $output;
// Invoice::sendInvoice(array($invoice_detail->id));
}
catch (Exception $e)
{
$output['error'] = $e;
return $output;
}
// # status (error: 0, success: 1)
// echo json_encode(['status' => 1]);
// exit();
} catch (Exception $e)
{
$output['error'] = $e;
return $output;
}
}
else
{
$output['error'] = $e;
return $output;
}
}
catch (Exception $e)
{
$output['error'] = $e;
return $output;
}
}
catch (Exception $e)
{
$output['error'] = $e;
return $output;
}
}
}
?>
File diff suppressed because it is too large Load Diff
+84
View File
@@ -0,0 +1,84 @@
<?php
use Twilio\Rest\Client;
class Twillo_service
{
private $_sid = '';
private $_from_number = '';
private $_api_token = '';
private $_twilio_verification_service = '';
protected $_client = NULL;
private $_ci = NULL;
public function __construct()
{
$this->_ci = &get_instance();
$this->_sid = $this->_ci->config->item('twilio_sid');
$this->_api_token = $this->_ci->config->item('twilio_token');
$this->_from_number = $this->_ci->config->item('twilio_phone_number');
$this->_twilio_verification_service = $this->_ci->config->item('twilio_verification_service');
try
{
$this->_client = new Client($this->_sid, $this->_api_token);
}
catch(Twilio\Exceptions\ConfigurationException $e)
{
die($e->getMessage()) ;
}
}
/**
* Send Message
*
* @param string $number
* @param string $message
* @return mixed
*/
public function send_message($number, $message)
{
return $this->_client->messages->create(
$number, // to
['body' => $message, 'from' => $this->_from_number]
);
}
/**
* Verify Number
*
* @see https://www.twilio.com/docs/verify/api/verification
* @param [type] $number
* @return void
*/
public function verify_number($number)
{
return $this->_client->verify->v2->services($this->_twilio_verification_service)->verifications->create($number, 'sms');
}
/**
* Fetch Verification
*
* @param string $seID
* @return mixed
*/
public function fetch_verification($seID)
{
return $this->_client->verify->v2->services($this->_twilio_verification_service)->verifications($seID)->fetch();
}
/**
* Check Verification Code
*
* @param string $code
* @param string $number
* @return mixed
*/
public function check_verification_code($code, $number)
{
return $this->_client->verify->v2->services($this->_twilio_verification_service)->verificationChecks->create($code, ['to' => $number]);
}
}
+22
View File
@@ -0,0 +1,22 @@
<?php defined('BASEPATH') OR exit('No direct script access allowed');
/*Powered By: Manaknightdigital Inc. https://manaknightdigital.com/ Year: 2021*/
class View_helper
{
public function time_format ($hour, $minute=0)
{
$final_minute = ($minute < 10) ? ('0' . $minute) : $minute;
$final_time = ($hour < 13) ? ($hour . ':' . $final_minute .' AM') : ( ($hour % 12) . ':' . $final_minute .' PM');
if ($hour == 12)
{
$final_time = 12 . ':' . $final_minute . ' PM';
}
if ($hour == 24)
{
$final_time = '12' . ':' . $final_minute .' AM';
}
return $final_time;
}
}
+11
View File
@@ -0,0 +1,11 @@
<!DOCTYPE html>
<html>
<head>
<title>403 Forbidden</title>
</head>
<body>
<p>Directory access is forbidden.</p>
</body>
</html>