Initial Commit
This commit is contained in:
+388
@@ -0,0 +1,388 @@
|
||||
<?php
|
||||
|
||||
/*===============================================*\
|
||||
|| ############################################# ||
|
||||
|| # JAKWEB.CH / Version 2.0.6 # ||
|
||||
|| # ----------------------------------------- # ||
|
||||
|| # Copyright 2022 JAKWEB All Rights Reserved # ||
|
||||
|| ############################################# ||
|
||||
\*===============================================*/
|
||||
|
||||
$cron_url_orig = dirname(__file__) . DIRECTORY_SEPARATOR;
|
||||
$cron_url = str_replace("cron".DIRECTORY_SEPARATOR, "", $cron_url_orig);
|
||||
|
||||
if (!file_exists($cron_url.'include/db.php')) die('[cron.php] db.php not exist');
|
||||
require_once $cron_url.'include/db.php';
|
||||
|
||||
if (!file_exists($cron_url.'class/class.db.php')) die('class/[cron.php] class.db.php not exist');
|
||||
require_once $cron_url.'class/class.db.php';
|
||||
|
||||
if (!file_exists($cron_url.'class/class.jakbase.php')) die('class/[cron.php] class.jakbase.php not exist');
|
||||
require_once $cron_url.'class/class.jakbase.php';
|
||||
|
||||
use JAKWEB\JAKsql;
|
||||
|
||||
// Database connection
|
||||
$jakdb = new JAKsql([
|
||||
// required
|
||||
'database_type' => JAKDB_DBTYPE,
|
||||
'database_name' => JAKDB_NAME,
|
||||
'server' => JAKDB_HOST,
|
||||
'username' => JAKDB_USER,
|
||||
'password' => JAKDB_PASS,
|
||||
'charset' => 'utf8',
|
||||
'port' => JAKDB_PORT,
|
||||
'prefix' => JAKDB_PREFIX,
|
||||
|
||||
// [optional] driver_option for connection, read more from http://www.php.net/manual/en/pdo.setattribute.php
|
||||
'option' => [PDO::ATTR_CASE => PDO::CASE_NATURAL]
|
||||
]);
|
||||
|
||||
// Check if we have a database connection
|
||||
if ($jakdb) {
|
||||
|
||||
// Select all accounts that need a welcome email.
|
||||
$upduser = $jakdb->select("user", ["id", "email", "username"], ["AND" => ["opid" => 0, "autoupdate" => 1, "autodelete" => 0]]);
|
||||
|
||||
if (isset($upduser) && !empty($upduser) && is_array($upduser)) foreach ($upduser as $row) {
|
||||
# code...
|
||||
|
||||
// First we update the status back to zero so we do not send emails twice
|
||||
$jakdb->update("user", ["autoupdate" => 0], ["id" => $row["id"]]);
|
||||
|
||||
// Database connection to main site
|
||||
$jakdb1 = new JAKsql([
|
||||
// required
|
||||
'database_type' => JAKDB_MAIN_DBTYPE,
|
||||
'database_name' => JAKDB_MAIN_NAME,
|
||||
'server' => JAKDB_MAIN_HOST,
|
||||
'username' => JAKDB_MAIN_USER,
|
||||
'password' => JAKDB_MAIN_PASS,
|
||||
'charset' => 'utf8',
|
||||
'port' => JAKDB_MAIN_PORT,
|
||||
'prefix' => JAKDB_MAIN_PREFIX,
|
||||
|
||||
// [optional] driver_option for connection, read more from http://www.php.net/manual/en/pdo.setattribute.php
|
||||
'option' => [PDO::ATTR_CASE => PDO::CASE_NATURAL]
|
||||
]);
|
||||
|
||||
// Now get the user information to update the table
|
||||
$activeuser = $jakdb1->get("users", ["id", "email", "username", "password", "paidtill"], ["AND" => ["opid" => $row["id"], "locationid" => JAK_MAIN_LOC]]);
|
||||
|
||||
if (isset($activeuser) && !empty($activeuser)) {
|
||||
|
||||
// let's update the user credential
|
||||
$jakdb->update("user", [
|
||||
"password" => $activeuser["password"],
|
||||
"username" => $activeuser["username"],
|
||||
"email" => $activeuser["email"]], ["id" => $row["id"]]);
|
||||
|
||||
// let's update the membership
|
||||
$jakdb->update("subscriptions", ["paidtill" => $activeuser["paidtill"]], ["opid" => $row["id"]]);
|
||||
|
||||
// Now let us delete the define cache file
|
||||
$cachewidget = $cron_url.JAK_CACHE_DIRECTORY.'/opcache'.$row["id"].'.php';
|
||||
if (file_exists($cachewidget)) {
|
||||
@unlink($cachewidget);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// Select all accounts that need to be removed
|
||||
$deluser = $jakdb->select("user", ["id", "email", "username"], ["AND" => ["opid" => 0, "autoupdate" => 0, "autodelete" => 1]]);
|
||||
|
||||
if (isset($deluser) && !empty($deluser) && is_array($deluser)) foreach ($deluser as $row2) {
|
||||
# code...
|
||||
|
||||
// Remove all settings
|
||||
$jakdb->delete("settings", ["opid" => $row2["id"]]);
|
||||
|
||||
// Remove all clients
|
||||
$clientid = $jakdb->select("clients", "id", ["opid" => $row2["id"]]);
|
||||
if (!empty($clientid) && is_array($clientid)) foreach ($clientid as $cl) {
|
||||
$jakdb->delete("taken_credits", ["clientid" => $cl]);
|
||||
}
|
||||
$jakdb->delete("clients", ["opid" => $row2["id"]]);
|
||||
$chatwidgetid = $jakdb->select("chatwidget", "id", ["opid" => $row2["id"]]);
|
||||
if (!empty($chatwidgetid) && is_array($chatwidgetid)) foreach ($chatwidgetid as $cw) {
|
||||
$jakdb->delete("checkstatus", ["convid" => $cw]);
|
||||
}
|
||||
$jakdb->delete("chatwidget", ["opid" => $row2["id"]]);
|
||||
|
||||
$sessionid = $jakdb->select("sessions", "id", ["opid" => $row2["id"]]);
|
||||
if (!empty($sessionid) && is_array($sessionid)) foreach ($sessionid as $s) {
|
||||
$jakdb->delete("transcript", ["convid" => $s]);
|
||||
}
|
||||
$jakdb->delete("chatcustomfields", ["opid" => $row2["id"]]);
|
||||
$jakdb->delete("chatsettings", ["opid" => $row2["id"]]);
|
||||
$gcid = $jakdb->get("groupchat", "id", ["opid" => $row2["id"]]);
|
||||
$jakdb->delete("groupchat", ["opid" => $row2["id"]]);
|
||||
$jakdb->delete("groupchatmsg", ["groupchatid" => $gcid]);
|
||||
$jakdb->delete("operatorchat", ["opid" => $row2["id"]]);
|
||||
$jakdb->delete("sessions", ["opid" => $row2["id"]]);
|
||||
|
||||
$contactid = $jakdb->select("contacts", "id", ["opid" => $row2["id"]]);
|
||||
if (!empty($contactid) && is_array($contactid)) foreach ($contactid as $c) {
|
||||
$jakdb->delete("contactsreply", ["contactid" => $c]);
|
||||
}
|
||||
$jakdb->delete("contacts", ["opid" => $row2["id"]]);
|
||||
$jakdb->delete("answers", ["opid" => $row2["id"]]);
|
||||
$jakdb->delete("bot_question", ["opid" => $row2["id"]]);
|
||||
$jakdb->delete("responses", ["opid" => $row2["id"]]);
|
||||
$jakdb->delete("autoproactive", ["opid" => $row2["id"]]);
|
||||
$jakdb->delete("subscriptions", ["opid" => $row2["id"]]);
|
||||
$jakdb->delete("subscriptions_client", ["opid" => $row2["id"]]);
|
||||
$jakdb->delete("departments", ["opid" => $row2["id"]]);
|
||||
$jakdb->delete("support_departments", ["opid" => $row2["id"]]);
|
||||
$jakdb->delete("support_responses", ["opid" => $row2["id"]]);
|
||||
|
||||
$supportid = $jakdb->select("support_tickets", "id", ["opid" => $row2["id"]]);
|
||||
if (!empty($supportid) && is_array($supportid)) foreach ($supportid as $su) {
|
||||
$jakdb->delete("ticket_answers", ["ticketid" => $su]);
|
||||
}
|
||||
$jakdb->delete("support_tickets", ["opid" => $row2["id"]]);
|
||||
$jakdb->delete("ticketoptions", ["opid" => $row2["id"]]);
|
||||
$jakdb->delete("ticketpriority", ["opid" => $row2["id"]]);
|
||||
$jakdb->delete("ticket_rating", ["opid" => $row2["id"]]);
|
||||
$jakdb->delete("urlblacklist", ["opid" => $row2["id"]]);
|
||||
$jakdb->delete("translations", ["opid" => $row2["id"]]);
|
||||
$jakdb->delete("php_imap", ["opid" => $row2["id"]]);
|
||||
$jakdb->delete("faq_article", ["opid" => $row2["id"]]);
|
||||
$jakdb->delete("faq_categories", ["opid" => $row2["id"]]);
|
||||
$jakdb->delete("customfields", ["opid" => $row2["id"]]);
|
||||
$jakdb->delete("customfields_data", ["opid" => $row2["id"]]);
|
||||
$jakdb->delete("cms_pages", ["opid" => $row2["id"]]);
|
||||
$jakdb->delete("billing_packages", ["opid" => $row2["id"]]);
|
||||
$jakdb->delete("files", ["opid" => $row2["id"]]);
|
||||
$jakdb->delete("files_archive", ["opid" => $row2["id"]]);
|
||||
$jakdb->delete("events", ["opid" => $row2["id"]]);
|
||||
$jakdb->delete("blog", ["opid" => $row2["id"]]);
|
||||
$jakdb->delete("blogcomments", ["opid" => $row2["id"]]);
|
||||
$jakdb->delete("push_notification_devices", ["userid" => $row2["id"]]);
|
||||
$jakdb->delete("user", ["opid" => $row2["id"]]);
|
||||
$result = $jakdb->delete("user", ["id" => $row2["id"]]);
|
||||
|
||||
// Delete Avatar and folder
|
||||
$targetPath = $cron_url.JAK_FILES_DIRECTORY.'/'.$row2["id"].'/';
|
||||
$removedouble = str_replace("//","/",$targetPath);
|
||||
foreach(glob($removedouble.'*.*') as $jak_unlink) {
|
||||
|
||||
@unlink($jak_unlink);
|
||||
|
||||
@unlink($targetPath);
|
||||
|
||||
}
|
||||
|
||||
// Delete buttons
|
||||
$targetPathb = $cron_url.JAK_FILES_DIRECTORY.'/buttons/'.$row2["id"].'/';
|
||||
$removedoubleb = str_replace("//","/",$targetPathb);
|
||||
foreach(glob($removedoubleb.'*.*') as $jak_unlinkb) {
|
||||
|
||||
@unlink($jak_unlinkb);
|
||||
|
||||
@unlink($targetPathb);
|
||||
|
||||
}
|
||||
|
||||
// Delete slideup images
|
||||
$targetPaths = $cron_url.JAK_FILES_DIRECTORY.'/slideimg/'.$row2["id"].'/';
|
||||
$removedoubles = str_replace("//","/",$targetPaths);
|
||||
foreach(glob($removedoubles.'*.*') as $jak_unlinks) {
|
||||
|
||||
@unlink($jak_unlinks);
|
||||
|
||||
@unlink($targetPaths);
|
||||
|
||||
}
|
||||
|
||||
// Delete the editor images and files
|
||||
$editorfolder = $cron_url.JAK_EDITOR_PATH.$row2["id"].'/';
|
||||
$removedoublet = str_replace("//","/",$editorfolder);
|
||||
foreach(glob($removedoublet.'*.*') as $jak_unlinkt) {
|
||||
|
||||
@unlink($jak_unlinkt);
|
||||
|
||||
@unlink($editorfolder);
|
||||
|
||||
}
|
||||
|
||||
// Delete the editor images and files (thumb)
|
||||
$editorfoldert = $cron_url.JAK_EDITOR_PATH_THUMBS.$row2["id"].'/';
|
||||
$removedoubleet = str_replace("//","/",$editorfoldert);
|
||||
foreach(glob($removedoubleet.'*.*') as $jak_unlinket) {
|
||||
|
||||
@unlink($jak_unlinket);
|
||||
|
||||
@unlink($editorfoldert);
|
||||
|
||||
}
|
||||
|
||||
// Delete the widget
|
||||
$cachewidget = $cron_url.JAK_CACHE_DIRECTORY.'/opcache'.$row2["id"].'.php';
|
||||
if (file_exists($cachewidget)) {
|
||||
@unlink($cachewidget);
|
||||
}
|
||||
|
||||
// Finally delete the user storage
|
||||
$alluserfiles = CLIENT_UPLOAD_DIR.'/'.$row2["id"].'/';
|
||||
$msfi = glob($alluserfiles."*");
|
||||
if ($msfi) foreach ($msfi as $filen) {
|
||||
if (is_dir($filen)) {
|
||||
rmdir($filen);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// Select entries older than
|
||||
$subs = $jakdb->select("subscriptions", ["opid", "chatwidgets", "groupchats", "operatorchat", "departments", "chathistory", "subscribed", "paygateid", "paidhow", "subscribeid", "paidwhen", "paidtill"], ["active" => 1]);
|
||||
|
||||
if (isset($subs) && !empty($subs)) {
|
||||
|
||||
// Current date
|
||||
$loc_date_now = new DateTime();
|
||||
$JAK_CURRENT_DATE = $loc_date_now->format('Y-m-d H:i:s');
|
||||
|
||||
foreach ($subs as $v) {
|
||||
|
||||
// We make a clean up for expired stuff.
|
||||
if ($v["paidtill"] < $JAK_CURRENT_DATE && $v["paidhow"] == "canceled") {
|
||||
|
||||
// Payment expired, let's reset the access
|
||||
$jakdb->update("subscriptions", ["packageid" => 0, "operators" => 1, "chatwidgets" => 1, "groupchats" => 0, "operatorchat" => 0, "operators" => 1, "departments" => 1, "tickets" => 0, "blog" => 0, "faq" => 0, "files" => 0, "activechats" => 3, "chathistory" => 30, "phpimap" => 0, "clients" => 0, "islc3" => 0, "ishd3" => 0, "validfor" => 0, "paygateid" => $v["paygateid"], "subscribeid" => 0, "subscribed" => 0, "planid" => "", "amount" => 0, "currency" => "", "paidhow" => "expired", "paidwhen" => $jakdb->raw("NOW()"), "paidtill" => $v["paidtill"], "trial" => 0, "active" => 0], ["opid" => $v["opid"]]);
|
||||
|
||||
if ($v["subscribed"] && $v["subscribeid"]) {
|
||||
|
||||
// Database connection to main site
|
||||
$jakdb1 = new JAKsql([
|
||||
// required
|
||||
'database_type' => JAKDB_MAIN_DBTYPE,
|
||||
'database_name' => JAKDB_MAIN_NAME,
|
||||
'server' => JAKDB_MAIN_HOST,
|
||||
'username' => JAKDB_MAIN_USER,
|
||||
'password' => JAKDB_MAIN_PASS,
|
||||
'charset' => 'utf8',
|
||||
'port' => JAKDB_MAIN_PORT,
|
||||
'prefix' => JAKDB_MAIN_PREFIX,
|
||||
|
||||
// [optional] driver_option for connection, read more from http://www.php.net/manual/en/pdo.setattribute.php
|
||||
'option' => [PDO::ATTR_CASE => PDO::CASE_NATURAL]
|
||||
]);
|
||||
|
||||
$jakdb1->update("subscriptions", ["subscribeid" => 0, "subscribed" => 0, "active" => 0], ["AND" => ["locationid" => JAK_MAIN_LOC, "userid" => $v["opid"], "subscribeid" => $v["subscribeid"]]]);
|
||||
}
|
||||
}
|
||||
|
||||
// The time we have to go back
|
||||
$deleteold = strtotime("-".$v['chathistory']." days");
|
||||
|
||||
// Delete Leads older then
|
||||
$sessionid = $jakdb->select("sessions", "id", ["AND" => ["opid" => $v['opid'], "ended[<]" => $deleteold]]);
|
||||
if (isset($sessionid) && !empty($sessionid)) foreach ($sessionid as $s) {
|
||||
// Remove stuff
|
||||
$jakdb->delete("transcript", ["convid" => $s]);
|
||||
$jakdb->delete("checkstatus", ["convid" => $s]);
|
||||
$jakdb->delete("sessions", ["id" => $s]);
|
||||
}
|
||||
|
||||
// Mysql nice format for other tables
|
||||
$deleteoldmysql = date('Y-m-d H:i:s', $deleteold);
|
||||
|
||||
// Delete Contacts older then
|
||||
$contactid = $jakdb->select("contacts", "id", ["AND" => ["opid" => $v['opid'], "sent[<]" => $deleteoldmysql]]);
|
||||
if (isset($contactid) && !empty($contactid)) foreach ($contactid as $c) {
|
||||
$jakdb->delete("contactsreply", ["contactid" => $c]);
|
||||
$jakdb->delete("contacts", ["id" => $c]);
|
||||
}
|
||||
|
||||
// We need online user list clean up
|
||||
$jakdb->delete("buttonstats", ["AND" => ["opid" => $v['opid'], "lasttime[<]" => $deleteoldmysql]]);
|
||||
|
||||
// We need to clean up the push notifications table if entries are older than one month
|
||||
$jakdb->delete("push_notification_devices", ["lastedit[<]" => $deleteoldmysql]);
|
||||
|
||||
// Remove all expired accounts older than 1 Month and subtract it from the op settings.
|
||||
if ($jakdb->has("subscriptions", "id", ["AND" => ["opid" => $v['opid'], "extraoperators[!]" => 0]])) {
|
||||
|
||||
// The time we have to go back
|
||||
$deleteoldop = strtotime("-1 month");
|
||||
// Mysql nice format for other tables
|
||||
$deleteoldmysqlop = date('Y-m-d H:i:s', $deleteoldop);
|
||||
|
||||
$oldops = $jakdb->select("user", ["id", "opid"], ["AND" => ["extraop" => 1, "validtill[<]" => $deleteoldmysqlop, "opid" => $v['opid']]]);
|
||||
if (isset($oldops) && !empty($oldops)) foreach ($oldops as $o) {
|
||||
// Remove and update stuff
|
||||
$jakdb->delete("user", ["id" => $o["id"]]);
|
||||
$jakdb->delete("push_notification_devices", ["userid" => $o["id"]]);
|
||||
$jakdb->delete("user_stats", ["userid" => $o["id"]]);
|
||||
$jakdb->update("subscriptions", ["extraoperators[-]" => 1], ["opid" => $o["opid"]]);
|
||||
|
||||
// Delete the widget
|
||||
$cachewidget = $cron_url.JAK_CACHE_DIRECTORY.'/opcache'.$o["opid"].'.php';
|
||||
if (file_exists($cachewidget)) {
|
||||
@unlink($cachewidget);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// We remove old entries due a downgrade
|
||||
$twidget = $jakdb->count("chatwidget", ["opid" => $v["opid"]]);
|
||||
$tgroupwidget = $jakdb->count("groupchat", ["opid" => $v["opid"]]);
|
||||
$tdepartment = $jakdb->count("departments", ["opid" => $v["opid"]]);
|
||||
|
||||
// We remove the chat widgets if
|
||||
if (isset($twidget) && $twidget > 1 && $v["chatwidgets"] < $twidget) {
|
||||
|
||||
// We calculate how many we have to delete
|
||||
if ($v['chatwidgets'] == 0) {
|
||||
$delW = $twidget - 1;
|
||||
} else {
|
||||
$delW = $twidget - $v['chatwidgets'];
|
||||
}
|
||||
// We delete the newest ones
|
||||
$jakdb->delete("chatwidget", ["opid" => $v["opid"], "ORDER" => ["created" => "DESC"], "LIMIT" => $delW]);
|
||||
}
|
||||
|
||||
// We remove the group chats if
|
||||
if (isset($tgroupwidget) && $tgroupwidget > 1 && $v["groupchats"] < $tgroupwidget) {
|
||||
|
||||
// We calculate how many we have to delete
|
||||
if ($v['groupchats'] == 0) {
|
||||
$delGW = $tgroupwidget - 1;
|
||||
} else {
|
||||
$delGW = $tgroupwidget - $v['groupchats'];
|
||||
}
|
||||
// We delete the newest ones
|
||||
$jakdb->delete("groupchat", ["opid" => $v["opid"], "ORDER" => ["created" => "DESC"], "LIMIT" => $delGW]);
|
||||
}
|
||||
|
||||
// We remove the chat widgets if
|
||||
if (isset($tdepartment) && $tdepartment > 1 && $v["departments"] < $tdepartment) {
|
||||
|
||||
// We calculate how many we have to delete
|
||||
if ($v['departments'] == 0) {
|
||||
$delDep = $tdepartment - 1;
|
||||
} else {
|
||||
$delDep = $tdepartment - $v['departments'];
|
||||
}
|
||||
// We delete the newest ones
|
||||
$jakdb->delete("departments", ["opid" => $v["opid"], "ORDER" => ["time" => "DESC"], "LIMIT" => $delDep]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Finally run the optimisation of all tables
|
||||
$tables = $jakdb->query('SHOW TABLES')->fetchAll();
|
||||
|
||||
foreach ($tables as $db => $tablename) {
|
||||
$jakdb->query('OPTIMIZE TABLE '.$tablename[0]);
|
||||
}
|
||||
|
||||
// Write the log file each time someone tries to login before
|
||||
JAK_base::jakWhatslog('System', 0, 0, 0, 38, 0, '', 'Cron Job', 'cron/cron.php', 0, 'Cron');
|
||||
|
||||
}
|
||||
?>
|
||||
+1397
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,357 @@
|
||||
<?php
|
||||
|
||||
/*===============================================*\
|
||||
|| ############################################# ||
|
||||
|| # JAKWEB.CH / Version 2.0.5 # ||
|
||||
|| # ----------------------------------------- # ||
|
||||
|| # Copyright 2022 JAKWEB All Rights Reserved # ||
|
||||
|| ############################################# ||
|
||||
\*===============================================*/
|
||||
|
||||
// This Cron Job should run twice a day, to make sure there is no interruption
|
||||
|
||||
$cron_url_orig = dirname(__file__) . DIRECTORY_SEPARATOR;
|
||||
$cron_url = str_replace("cron".DIRECTORY_SEPARATOR, "", $cron_url_orig);
|
||||
|
||||
if (!file_exists($cron_url.'include/db.php')) die('cron/[cron.php] db.php not exist');
|
||||
require_once $cron_url.'include/db.php';
|
||||
|
||||
if (!file_exists($cron_url.'class/class.db.php')) die('cron/[cron.php] class.db.php not exist');
|
||||
require_once $cron_url.'class/class.db.php';
|
||||
|
||||
if (!file_exists($cron_url.'class/class.jakbase.php')) die('cron/[cron.php] class.jakbase.php not exist');
|
||||
require_once $cron_url.'class/class.jakbase.php';
|
||||
|
||||
// Include the payment class
|
||||
include_once($cron_url.'class/class.payment.php');
|
||||
|
||||
use YooKassa\Client;
|
||||
|
||||
use JAKWEB\JAKsql;
|
||||
|
||||
// Now we finally initate the payment module
|
||||
$JAK_payment = new JAK_payment();
|
||||
|
||||
// Database connection
|
||||
$jakdb = new JAKsql([
|
||||
// required
|
||||
'database_type' => JAKDB_DBTYPE,
|
||||
'database_name' => JAKDB_NAME,
|
||||
'server' => JAKDB_HOST,
|
||||
'username' => JAKDB_USER,
|
||||
'password' => JAKDB_PASS,
|
||||
'charset' => 'utf8',
|
||||
'port' => JAKDB_PORT,
|
||||
'prefix' => JAKDB_PREFIX,
|
||||
|
||||
// [optional] driver_option for connection, read more from http://www.php.net/manual/en/pdo.setattribute.php
|
||||
'option' => [PDO::ATTR_CASE => PDO::CASE_NATURAL]
|
||||
]);
|
||||
|
||||
// Check if we have a database connection
|
||||
if ($jakdb) {
|
||||
|
||||
// We start with the clients to make sure there service does not get interrupted
|
||||
$sc = $jakdb->select("subscriptions_client", ["id", "opid", "clientid", "amount", "currency", "paidhow", "subscribed", "package", "planid", "paidtill", "gatewaycheck"], ["AND" => ["success" => 1, "active" => 1]]);
|
||||
|
||||
// Current date
|
||||
$loc_date_now = new DateTime();
|
||||
$JAK_CURRENT_DATE = $loc_date_now->format('Y-m-d H:i:s');
|
||||
|
||||
if (isset($sc) && !empty($sc) && is_array($sc)) foreach ($sc as $row) {
|
||||
# code...
|
||||
|
||||
// We have some users let's go
|
||||
$allFailed = true;
|
||||
|
||||
// First get the package
|
||||
$pack = $jakdb->get("billing_packages", ["title", "paidtill"], ["id" => $row["package"]]);
|
||||
|
||||
// Check the date and how many times we have checked the payment gateway
|
||||
if ($row["paidtill"] < $JAK_CURRENT_DATE) {
|
||||
|
||||
// Now we have a subscription we like to extend it
|
||||
if ($row["subscribed"] && $row["gatewaycheck"] < 4) {
|
||||
|
||||
// Now let's find out if the subscription has been paid.
|
||||
$subsuccess = false;
|
||||
|
||||
// Go trought the payment gateways
|
||||
switch ($row['paidhow']) {
|
||||
case 'stripe':
|
||||
// code...
|
||||
|
||||
$subsuccess = $JAK_payment->JAK_pay("stripe", "", "", $row["planid"], $row["paidtill"], "recurring", "check_plan", "", "", JAK_STRIPE_SECRET_KEY, JAK_STRIPE_PUBLISH_KEY, JAK_SANDBOX_MODE);
|
||||
|
||||
break;
|
||||
|
||||
case 'paypal':
|
||||
// code...
|
||||
|
||||
$subsuccess = $JAK_payment->JAK_pay("paypal", "", "", $row["planid"], $row["paidtill"], "recurring", "check_plan", "", "", JAK_PAYPAL_CLIENT, JAK_PAYPAL_SECRET, JAK_SANDBOX_MODE);
|
||||
|
||||
break;
|
||||
|
||||
case 'verifone':
|
||||
// code...
|
||||
|
||||
|
||||
|
||||
break;
|
||||
|
||||
case 'authorize.net':
|
||||
// code...
|
||||
|
||||
|
||||
|
||||
break;
|
||||
|
||||
case 'yoomoney':
|
||||
// code...
|
||||
|
||||
// We will need to manually charge the client because YooKassa does not support automatic billing.
|
||||
$subsuccess = $JAK_payment->JAK_pay("yoomoney", $row["amount"], $row["currency"], $row["planid"], $pack["title"], "recurring", "charge", "", "", JAK_YOOKASSA_ID, JAK_YOOKASSA_SECRET, JAK_SANDBOX_MODE);
|
||||
|
||||
|
||||
break;
|
||||
|
||||
case 'paystack':
|
||||
// code...
|
||||
|
||||
$subsuccess = $JAK_payment->JAK_pay("paystack", "", "", $row["planid"], $row["paidtill"], "check_plan", "", "", "", JAK_PAYSTACK_SECRET, "", JAK_SANDBOX_MODE);
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
// Now let's figure out what we found out
|
||||
if ($subsuccess) {
|
||||
|
||||
// Juheee we have a success the customer has been charged and everything is safe and sound
|
||||
|
||||
// Get the new date
|
||||
$paidunix = strtotime($pack["paidtill"]);
|
||||
|
||||
// Now if we have a subscription we add 48 hours to the client table to make sure it get's not expired
|
||||
$paidunix2 = strtotime('+2 days', $paidunix);
|
||||
$paidtill2 = date('Y-m-d H:i:s', $paidunix2);
|
||||
|
||||
// We call back in
|
||||
$paidtill = date('Y-m-d H:i:s', $paidunix);
|
||||
|
||||
// Update the subscription period for the client
|
||||
$jakdb->update("clients", ["paid_until" => $paidtill2], ["AND" => ["id" => $row["clientid"], "opid" => $row['opid']]]);
|
||||
|
||||
// Update the subscription table itself
|
||||
$jakdb->update("subscriptions_client", ["active" => 0, "subscribed" => 0], ["id" => $row["id"]]);
|
||||
|
||||
// Payment details insert // new ones because we like to count
|
||||
$jakdb->insert("subscriptions_client", ["opid" => $row['opid'],
|
||||
"clientid" => $row["clientid"],
|
||||
"amount" => $row["amount"],
|
||||
"paidhow" => $row["paidhow"],
|
||||
"currency" => $row["currency"],
|
||||
"package" => $row["package"],
|
||||
"subscribed" => 1,
|
||||
"planid" => $row["planid"],
|
||||
"paidwhen" => $jakdb->raw("NOW()"),
|
||||
"paidtill" => $paidtill,
|
||||
"success" => 1,
|
||||
"active" => 1]);
|
||||
|
||||
// We try again, do not change anything below
|
||||
$allFailed = false;
|
||||
|
||||
|
||||
} else {
|
||||
|
||||
// We try in 12 hours again
|
||||
$jakdb->update("subscriptions_client", ["gatewaycheck[+]" => 1], ["id" => $row["id"]]);
|
||||
|
||||
// We try again, do not change anything below
|
||||
$allFailed = false;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// Nothing worked out we cancel everything
|
||||
if ($allFailed) {
|
||||
|
||||
// We have tried everything 4 times to be exact. Let's cancel the subscription and make the customer normal again.
|
||||
$jakdb->update("subscriptions_client", ["active" => 0, "subscribed" => 0], ["id" => $row["id"]]);
|
||||
|
||||
// We move the user back to the standard departments
|
||||
$jakdb->update("clients", ["chat_dep" => JAK_STANDARD_CHAT_DEP, "support_dep" => JAK_STANDARD_SUPPORT_DEP, "faq_cat" => JAK_STANDARD_FAQ_CAT], ["AND" => ["id" => $row["clientid"], "opid" => $row['opid']]]);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// Now if we have multi site we have fully automated process
|
||||
if (!empty(JAKDB_MAIN_NAME) && JAK_MAIN_LOC && JAK_MAIN_LOC) {
|
||||
|
||||
// Database connection to the main site
|
||||
$jakdb1 = new JAKsql([
|
||||
// required
|
||||
'database_type' => JAKDB_MAIN_DBTYPE,
|
||||
'database_name' => JAKDB_MAIN_NAME,
|
||||
'server' => JAKDB_MAIN_HOST,
|
||||
'username' => JAKDB_MAIN_USER,
|
||||
'password' => JAKDB_MAIN_PASS,
|
||||
'charset' => 'utf8',
|
||||
'port' => JAKDB_MAIN_PORT,
|
||||
'prefix' => JAKDB_MAIN_PREFIX,
|
||||
|
||||
// [optional] driver_option for connection, read more from http://www.php.net/manual/en/pdo.setattribute.php
|
||||
'option' => [PDO::ATTR_CASE => PDO::CASE_NATURAL]
|
||||
]);
|
||||
|
||||
// Now we get the subscriptions
|
||||
$usrsub = $jakdb1->select("subscriptions", ["id", "packageid", "userid", "amount", "currency", "paidfor", "paidhow", "subscribed", "subscribeid", "subscribetoken", "paidwhen", "paidtill", "active", "success"], ["AND" => ["locationid" => JAK_MAIN_LOC, "active" => 1]]);
|
||||
|
||||
// Current date
|
||||
$loc_date_now = new DateTime();
|
||||
$JAK_CURRENT_DATE = $loc_date_now->format('Y-m-d H:i:s');
|
||||
|
||||
// Run the client subscriptions
|
||||
if (isset($usrsub) && !empty($usrsub) && is_array($usrsub)) foreach ($usrsub as $row1) {
|
||||
|
||||
// We have some users let's go
|
||||
$allFailed2 = true;
|
||||
|
||||
// Check the date and how many times we have checked the payment gateway
|
||||
if ($row1["paidtill"] < $JAK_CURRENT_DATE) {
|
||||
|
||||
// Now we have a subscription we like to extend it
|
||||
if ($row1["subscribed"] && $row1["active"] == 1) {
|
||||
|
||||
// Now let's find out if the subscription has been paid.
|
||||
$subsuccess = false;
|
||||
|
||||
// Go trought the payment gateways
|
||||
switch ($row['paidhow']) {
|
||||
case 'stripe':
|
||||
// code...
|
||||
|
||||
$subsuccess = $JAK_payment->JAK_pay("stripe", "", "", $row1["subscribetoken"], $row1["paidtill"], "recurring", "check_plan", "", "", JAK_STRIPE_SECRET_KEY, JAK_STRIPE_PUBLISH_KEY, JAK_SANDBOX_MODE);
|
||||
|
||||
break;
|
||||
|
||||
case 'paypal':
|
||||
// code...
|
||||
|
||||
$subsuccess = $JAK_payment->JAK_pay("paypal", "", "", $row1["subscribetoken"], $row1["paidtill"], "recurring", "check_plan", "", "", JAK_PAYPAL_CLIENT, JAK_PAYPAL_SECRET, JAK_SANDBOX_MODE);
|
||||
|
||||
break;
|
||||
|
||||
case 'verifone':
|
||||
// code...
|
||||
|
||||
|
||||
|
||||
break;
|
||||
|
||||
case 'authorize.net':
|
||||
// code...
|
||||
|
||||
|
||||
|
||||
break;
|
||||
|
||||
case 'yoomoney':
|
||||
// code...
|
||||
|
||||
// We will need to manually charge the client because YooKassa does not support automatic billing.
|
||||
$subsuccess = $JAK_payment->JAK_pay("yoomoney", $row1["amount"], $row1["currency"], $row1["subscribetoken"], $row1["paidfor"], "recurring", "charge", "", "", JAK_YOOKASSA_ID, JAK_YOOKASSA_SECRET, JAK_SANDBOX_MODE);
|
||||
|
||||
|
||||
break;
|
||||
|
||||
case 'paystack':
|
||||
// code...
|
||||
|
||||
$subsuccess = $JAK_payment->JAK_pay("paystack", "", "", $row1["subscribetoken"], $row1["paidtill"], "check_plan", "", "", "", JAK_PAYSTACK_SECRET, "", JAK_SANDBOX_MODE);
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
// Now let's figure out what we found out
|
||||
if ($subsuccess) {
|
||||
|
||||
// Juheee we have a success the customer has been charged and everything is safe and sound
|
||||
|
||||
// Get the new date
|
||||
$paidunix = strtotime($pack["paidtill"]);
|
||||
|
||||
// We call back in
|
||||
$paidtill = date('Y-m-d H:i:s', $paidunix);
|
||||
|
||||
// is there any open subscription
|
||||
$jakdb1->update("subscriptions", ["subscribeid" => 0, "subscribed" => 0, "active" => 0], ["AND" => ["locationid" => JAK_MAIN_LOC, "userid" => $custom[0], "subscribeid" => $subs["subscribeid"]]]);
|
||||
|
||||
// We insert the subscription into the main table for that user.
|
||||
$jakdb1->insert("subscriptions", ["packageid" => $row1["packageid"],
|
||||
"locationid" => JAK_MAIN_LOC,
|
||||
"userid" => $row1["userid"],
|
||||
"amount" => $row1["amount"],
|
||||
"currency" => $row1["currency"],
|
||||
"paidfor" => $row1["paidfor"],
|
||||
"paidhow" => $row1["paidhow"],
|
||||
"subscribed" => $row1["subscribed"],
|
||||
"paygateid" => $row1["packageid"],
|
||||
"subscribeid" => $row1["subscribeid"],
|
||||
"subscribetoken" => $row1["subscribetoken"],
|
||||
"paidwhen" => $jakdb->raw("NOW()"),
|
||||
"paidtill" => $paidtill,
|
||||
"active" => 1,
|
||||
"success" => 1]);
|
||||
|
||||
// finally update the main database
|
||||
$jakdb1->update("users", ["paidtill" => $paidtill], ["AND" => ["opid" => $row1["userid"], "locationid" => JAK_MAIN_LOC]]);
|
||||
|
||||
// Finally update the subscription table
|
||||
$jakdb->update("subscriptions", ["paidwhen" => $jakdb->raw("NOW()"), "paidtill" => $paidtill], ["opid" => $row1["userid"]]);
|
||||
|
||||
// Now let us delete the define cache file
|
||||
$cachewidget = $cron_url.JAK_CACHE_DIRECTORY.'opcache'.$row1["userid"].'.php';
|
||||
if (file_exists($cachewidget)) {
|
||||
unlink($cachewidget);
|
||||
}
|
||||
|
||||
// We try again, do not change anything below
|
||||
$allFailed2 = false;
|
||||
|
||||
|
||||
} else {
|
||||
|
||||
// We try again, do not change anything below
|
||||
$allFailed2 = false;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
// Nothing worked out we cancel everything
|
||||
if ($allFailed2) {
|
||||
|
||||
// We have tried everything 4 times to be exact. Let's cancel the subscription and make the customer normal again.
|
||||
$jakdb1->update("subscriptions", ["active" => 0, "subscribed" => 0], ["id" => $row1["id"]]);
|
||||
|
||||
// We update the main table
|
||||
$jakdb->update("subscriptions", ["subscribeid" => 0, "subscribed" => 0, "planid" => "", "paidhow" => "canceled"], ["opid" => $row1["userid"]]);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// Write the log file each time someone tries to login before
|
||||
JAK_base::jakWhatslog('System', 0, 0, 0, 38, 0, '', 'Cron Job - Subscriptions', 'cron/subscribe.php', 0, 'subscriptions');
|
||||
|
||||
}
|
||||
?>
|
||||
@@ -0,0 +1,505 @@
|
||||
<?php
|
||||
/*===============================================*\
|
||||
|| ############################################# ||
|
||||
|| # JAKWEB.CH / Version 2.1.1 # ||
|
||||
|| # ----------------------------------------- # ||
|
||||
|| # Copyright 2023 JAKWEB All Rights Reserved # ||
|
||||
|| ############################################# ||
|
||||
\*===============================================*/
|
||||
|
||||
$cron_url_orig = dirname(__FILE__) . DIRECTORY_SEPARATOR;
|
||||
$cron_url = str_replace("cron" . DIRECTORY_SEPARATOR, "", $cron_url_orig);
|
||||
|
||||
if (!file_exists($cron_url . "include/db.php"))
|
||||
{
|
||||
die("cron/[cron.php] db.php not exist");
|
||||
}
|
||||
require_once $cron_url . "include/db.php";
|
||||
|
||||
if (!file_exists($cron_url . "class/class.db.php"))
|
||||
{
|
||||
die("cron/[cron.php] class.db.php not exist");
|
||||
}
|
||||
require_once $cron_url . "class/class.db.php";
|
||||
|
||||
if (!file_exists($cron_url . "class/class.jakbase.php"))
|
||||
{
|
||||
die("cron/[cron.php] class.jakbase.php not exist");
|
||||
}
|
||||
require_once $cron_url . "class/class.jakbase.php";
|
||||
|
||||
use JAKWEB\JAKsql;
|
||||
|
||||
//Import the PHPMailer class into the global namespace
|
||||
use PHPMailer\PHPMailer\PHPMailer;
|
||||
use PHPMailer\PHPMailer\SMTP;
|
||||
use PHPMailer\PHPMailer\OAuth;
|
||||
//@see https://github.com/thephpleague/oauth2-google
|
||||
use League\OAuth2\Client\Provider\Google;
|
||||
//@see https://github.com/stevenmaguire/oauth2-microsoft
|
||||
use Stevenmaguire\OAuth2\Client\Provider\Microsoft;
|
||||
//@see https://github.com/greew/oauth2-azure-provider
|
||||
use Greew\OAuth2\Client\Provider\Azure;
|
||||
//@see https://packagist.org/packages/hayageek/oauth2-yahoo
|
||||
use Hayageek\OAuth2\Client\Provider\Yahoo;
|
||||
|
||||
// Database connection
|
||||
$jakdb = new JAKsql([
|
||||
// required
|
||||
"database_type" => JAKDB_DBTYPE, "database_name" => JAKDB_NAME, "server" => JAKDB_HOST, "username" => JAKDB_USER, "password" => JAKDB_PASS, "charset" => "utf8", "port" => JAKDB_PORT, "prefix" => JAKDB_PREFIX,
|
||||
|
||||
// [optional] driver_option for connection, read more from http://www.php.net/manual/en/pdo.setattribute.php
|
||||
"option" => [PDO::ATTR_CASE => PDO::CASE_NATURAL], ]);
|
||||
|
||||
// Get the necessary classes
|
||||
include_once str_replace("cron/", "", $cron_url . "include/functions.php");
|
||||
include_once str_replace("cron/", "", $cron_url . "class/class.browser.php");
|
||||
require_once str_replace("cron/", "", $cron_url . "vendor/autoload.php");
|
||||
|
||||
// We need the correct url to filter either from web or cron
|
||||
$sapi_type = php_sapi_name();
|
||||
if (substr($sapi_type, 0, 3) == "cli" || empty($_SERVER["REMOTE_ADDR"]))
|
||||
{
|
||||
$path_parts = pathinfo($cron_url);
|
||||
$url_filter = $cron_url;
|
||||
$url_replace = "/" . basename($path_parts["dirname"]) . "/";
|
||||
}
|
||||
else
|
||||
{
|
||||
$url_filter = "/cron/";
|
||||
$url_replace = "/";
|
||||
}
|
||||
|
||||
// Tables
|
||||
$jaktable = "support_tickets";
|
||||
$jaktable1 = "tickets_answer";
|
||||
$jaktable2 = "php_imap";
|
||||
|
||||
$ops = [];
|
||||
|
||||
// Write the log file each time we run the ticket cron job
|
||||
JAK_base::jakWhatslog("System", 0, 0, 0, 38, 0, "", "Cron Job - Tickets", "cron/tickets.php", 0, "tickets");
|
||||
|
||||
// Get the BASE_URL if not wildcard
|
||||
if (!JAK_WILDCARD_SUBDOMAIN)
|
||||
{
|
||||
// We have no wildcard subdomain, just go normal
|
||||
$BASE_URL = (JAK_SITEHTTPS ? "https://" : "http://") . FULL_SITE_DOMAIN . SITE_SUBFOLDER . "/";
|
||||
}
|
||||
|
||||
// Select all accounts that need a welcome email.
|
||||
$upduser = $jakdb->select("user", ["id", "email", "username"], ["AND" => ["opid" => 0, "access" => 1]]);
|
||||
|
||||
if (isset($upduser) && !empty($upduser) && is_array($upduser))
|
||||
{
|
||||
foreach ($upduser as $usr)
|
||||
{
|
||||
$datasett = $jakdb->select("settings", ["varname", "used_value"], ["opid" => $usr["id"]]);
|
||||
foreach ($datasett as $row)
|
||||
{
|
||||
// Now check if sting contains html and do something about it!
|
||||
if (!empty($row["used_value"]) && strlen($row["used_value"]) != strlen(filter_var($row["used_value"], FILTER_SANITIZE_FULL_SPECIAL_CHARS)))
|
||||
{
|
||||
$defvar = htmlspecialchars($row["used_value"]);
|
||||
}
|
||||
else
|
||||
{
|
||||
$defvar = $row["used_value"];
|
||||
}
|
||||
|
||||
$ops["JAK_" . strtoupper($row["varname"]) ] = $defvar;
|
||||
}
|
||||
|
||||
// Now we will need the correct URL if wildcard
|
||||
if (JAK_WILDCARD_SUBDOMAIN)
|
||||
{
|
||||
$subdomain = $jakdb->get("subscriptions", "business", ["opid" => $usr["id"], ]);
|
||||
if (isset($subdomain) && !empty($subdomain))
|
||||
{
|
||||
// We will need to define the URL
|
||||
$BASE_URL = (JAK_SITEHTTPS ? "https://" : "http://") . $subdomain . "." . FULL_SITE_DOMAIN . SITE_SUBFOLDER . "/";
|
||||
}
|
||||
else
|
||||
{
|
||||
// We have no wildcard subdomain or could not find it, just go normal
|
||||
$BASE_URL = (JAK_SITEHTTPS ? "https://" : "http://") . FULL_SITE_DOMAIN . SITE_SUBFOLDER . "/";
|
||||
}
|
||||
}
|
||||
|
||||
// Connect to the correct language
|
||||
include str_replace("cron/", "", $cron_url . "lang/" . $ops["JAK_LANG"] . ".php");
|
||||
|
||||
// Calculate which tickets we have to reminder
|
||||
$ticketreminder = time() - $ops["JAK_TICKET_REMINDER"] * 86400;
|
||||
|
||||
// First check if we need to send a ticket reminder
|
||||
$result = $jakdb->select($jaktable, ["[>]clients" => ["clientid" => "id"]], ["support_tickets.id", "support_tickets.depid", "support_tickets.name", "support_tickets.email", "support_tickets.subject", "clients.credits", "clients.paid_until", ], ["AND" => ["support_tickets.ended" => 0, "support_tickets.reminder" => 0, "support_tickets.updated[<]" => $ticketreminder, ], ]);
|
||||
|
||||
if (isset($result) && !empty($result))
|
||||
{
|
||||
foreach ($result as $row)
|
||||
{
|
||||
// Dashboard URL
|
||||
$ticketurl = str_replace($url_filter, $url_replace, JAK_rewrite::jakParseurl($ops["JAK_SUPPORT_URL"], "t", $row["id"], JAK_rewrite::jakCleanurl($row["subject"])));
|
||||
|
||||
// Let's check if we have an imap
|
||||
$answeremail = $ticktext = "";
|
||||
$check_imap = $jakdb->get($jaktable2, "emailanswer", ["depid" => $row["depid"], ]);
|
||||
if ($check_imap)
|
||||
{
|
||||
$answeremail = $check_imap;
|
||||
}
|
||||
|
||||
// Get the ticket answer template
|
||||
if (!empty($HD_ANSWERS) && is_array($HD_ANSWERS))
|
||||
{
|
||||
foreach ($HD_ANSWERS as $v)
|
||||
{
|
||||
if ($v["msgtype"] == 22 && $v["lang"] == $ops["JAK_LANG"])
|
||||
{
|
||||
$phold = ["{url}", "{title}", "{cemail}", "{cname}", "{credits}", "{paid_until}", "{ticket}", "{subject}", "{ticketurl}", "{email}", ];
|
||||
$replace = [str_replace($cron_url, "", $BASE_URL) , $ops["JAK_TITLE"], $row["email"], $row["name"], $row["credits"], $row["paid_until"], "#" . $row["id"], $row["subject"], $ticketurl, $answeremail, ];
|
||||
$ticktext = str_replace($phold, $replace, $v["message"]);
|
||||
break;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
if (!empty($ticktext))
|
||||
{
|
||||
$ticktext = '<p style="color:#c1c1c1;">-------------## Do Not Remove ##-------------</p>' . $ticktext;
|
||||
|
||||
// Get the email template
|
||||
$nlhtml = file_get_contents(str_replace("cron/", "", $cron_url . "template/" . $ops["JAK_FRONT_TEMPLATE"] . "/email/index.html"));
|
||||
|
||||
// Change fake vars into real ones.
|
||||
$cssAtt = ["{emailcontent}", "{weburl}", "{title}", "{emailtpllogo}", "{emailtplcopy}", ];
|
||||
$cssUrl = [$ticktext, str_replace($cron_url, "", $BASE_URL) , $ops["JAK_TITLE"], $ops["JAK_EMAILTPLLOGO"], $ops["JAK_EMAILTPLCOPY"], ];
|
||||
$nlcontent = str_replace($cssAtt, $cssUrl, $nlhtml);
|
||||
|
||||
$body = str_ireplace("[\]", "", $nlcontent);
|
||||
|
||||
$mail = new PHPMailer(); // defaults to using php "mail()" or optional SMTP
|
||||
if ($ops["JAK_SMTP_MAIL"] == 1)
|
||||
{
|
||||
$mail->IsSMTP(); // telling the class to use SMTP
|
||||
$mail->Host = $ops["JAK_SMTPHOST"];
|
||||
$mail->SMTPAuth = $ops["JAK_SMTP_AUTH"] ? true : false; // enable SMTP authentication
|
||||
$mail->SMTPSecure = $ops["JAK_SMTP_PREFIX"]; // sets the prefix to the server
|
||||
$mail->SMTPAutoTLS = false;
|
||||
$mail->SMTPKeepAlive = $ops["JAK_SMTP_ALIVE"] ? true : false; // SMTP connection will not close after each email sent
|
||||
$mail->Port = $ops["JAK_SMTPPORT"]; // set the SMTP port for the GMAIL server
|
||||
$mail->Username = $ops["JAK_SMTPUSERNAME"]; // SMTP account username
|
||||
$mail->Password = $ops["JAK_SMTPPASSWORD"]; // SMTP account password
|
||||
|
||||
}
|
||||
elseif ($ops["JAK_SMTP_MAIL"] == 2)
|
||||
{
|
||||
//Tell PHPMailer to use SMTP
|
||||
$mail->isSMTP();
|
||||
//Whether to use SMTP authentication
|
||||
$mail->SMTPAuth = true;
|
||||
//Set AuthType to use XOAUTH2
|
||||
$mail->AuthType = "XOAUTH2";
|
||||
|
||||
$oauth_params = ["clientId" => $ops["JAK_OAUTH_CLIENTID"], "clientSecret" => $ops["JAK_OAUTH_SECRET"], ];
|
||||
|
||||
switch ($ops["JAK_OAUTH_PROVIDER"])
|
||||
{
|
||||
case "Google":
|
||||
$mail->Host = "smtp.gmail.com";
|
||||
$mail->Port = 465;
|
||||
$mail->SMTPSecure = PHPMailer::ENCRYPTION_SMTPS;
|
||||
$provider = new Google($oauth_params);
|
||||
break;
|
||||
case "Yahoo":
|
||||
$mail->Host = "smtp.mail.yahoo.com";
|
||||
$mail->Port = 465;
|
||||
$mail->SMTPSecure = PHPMailer::ENCRYPTION_SMTPS;
|
||||
$provider = new Yahoo($oauth_params);
|
||||
break;
|
||||
case "Microsoft":
|
||||
$mail->Host = "smtp.office365.com";
|
||||
$mail->Port = 587;
|
||||
$mail->SMTPSecure = PHPMailer::ENCRYPTION_STARTTLS;
|
||||
$provider = new Microsoft($oauth_params);
|
||||
break;
|
||||
case "Azure":
|
||||
$mail->Host = "smtp.office365.com";
|
||||
$mail->Port = 587;
|
||||
$mail->SMTPSecure = PHPMailer::ENCRYPTION_STARTTLS;
|
||||
$params["tenantId"] = $ops["JAK_OAUTH_TENANTID"];
|
||||
$provider = new Azure($oauth_params);
|
||||
break;
|
||||
}
|
||||
if ($provider)
|
||||
{
|
||||
$mail->setOAuth(new OAuth(["provider" => $provider, "clientId" => $ops["JAK_OAUTH_CLIENTID"], "clientSecret" => $ops["JAK_OAUTH_SECRET"], "refreshToken" => $ops["JAK_OAUTH_REFRESH"], "userName" => $ops["JAK_SMTP_SENDER"], ]));
|
||||
}
|
||||
}
|
||||
|
||||
// Finally send the email
|
||||
$mail->SetFrom($ops["JAK_SMTP_SENDER"]);
|
||||
$mail->addAddress($row["email"]);
|
||||
$mail->Subject = $ops["JAK_TITLE"] . " - RE:" . $row["subject"];
|
||||
$mail->MsgHTML($body);
|
||||
|
||||
$mail->Send();
|
||||
}
|
||||
|
||||
// Now we update the ticket table
|
||||
$jakdb->update($jaktable, ["reminder" => 1], ["id" => $row["id"]]);
|
||||
};
|
||||
}
|
||||
|
||||
// Calculate which tickets we have to close
|
||||
if ($ops["JAK_TICKET_CLOSE_C"] != 0)
|
||||
{
|
||||
$ticketclose = time() - $ops["JAK_TICKET_CLOSE_C"] * 86400;
|
||||
|
||||
// First check if we need to send a ticket reminder
|
||||
$result = $jakdb->select($jaktable, ["[>]clients" => ["clientid" => "id"]], ["support_tickets.id", "support_tickets.depid", "support_tickets.name", "support_tickets.email", "support_tickets.subject", "clients.credits", "clients.paid_until", ], ["AND" => ["support_tickets.ended" => 0, "support_tickets.updated[<]" => $ticketclose, ], ]);
|
||||
|
||||
if (isset($result) && !empty($result))
|
||||
{
|
||||
foreach ($result as $row)
|
||||
{
|
||||
// Send email to customers if set so.
|
||||
if ($ops["JAK_TICKET_CLOSE_R"] == 1)
|
||||
{
|
||||
// Dashboard URL
|
||||
$ticketurl = str_replace($url_filter, $url_replace, JAK_rewrite::jakParseurl($ops["JAK_SUPPORT_URL"], "t", $row["id"], JAK_rewrite::jakCleanurl($row["subject"])));
|
||||
|
||||
// Let's check if we have an imap
|
||||
$answeremail = $ticktext = "";
|
||||
$check_imap = $jakdb->get($jaktable2, "emailanswer", ["depid" => $row["depid"], ]);
|
||||
if ($check_imap)
|
||||
{
|
||||
$answeremail = $check_imap;
|
||||
}
|
||||
|
||||
// Get the ticket answer template
|
||||
if (!empty($HD_ANSWERS) && is_array($HD_ANSWERS))
|
||||
{
|
||||
foreach ($HD_ANSWERS as $v)
|
||||
{
|
||||
if ($v["msgtype"] == 23 && $v["lang"] == $ops["JAK_LANG"])
|
||||
{
|
||||
$phold = ["{url}", "{title}", "{cemail}", "{cname}", "{credits}", "{paid_until}", "{ticket}", "{subject}", "{ticketurl}", "{email}", ];
|
||||
$replace = [str_replace($cron_url, "", $BASE_URL) , $ops["JAK_TITLE"], $row["email"], $row["name"], $row["credits"], $row["paid_until"], "#" . $row["id"], $row["subject"], $ticketurl, $answeremail, ];
|
||||
$ticktext = str_replace($phold, $replace, $v["message"]);
|
||||
break;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
// Get the email template
|
||||
if (!empty($ticktext))
|
||||
{
|
||||
$nlhtml = file_get_contents(str_replace("cron/", "", $cron_url . "template/" . $ops["JAK_FRONT_TEMPLATE"] . "/email/index.html"));
|
||||
|
||||
// Change fake vars into real ones.
|
||||
$cssAtt = ["{emailcontent}", "{weburl}", "{title}", "{emailtpllogo}", "{emailtplcopy}", ];
|
||||
$cssUrl = [$ticktext, str_replace($cron_url, "", $BASE_URL) , $ops["JAK_TITLE"], $ops["JAK_EMAILTPLLOGO"], $ops["JAK_EMAILTPLCOPY"], ];
|
||||
$nlcontent = str_replace($cssAtt, $cssUrl, $nlhtml);
|
||||
|
||||
$body = str_ireplace("[\]", "", $nlcontent);
|
||||
|
||||
$mail = new PHPMailer(); // defaults to using php "mail()" or optional SMTP
|
||||
if ($ops["JAK_SMTP_MAIL"] == 1)
|
||||
{
|
||||
$mail->IsSMTP(); // telling the class to use SMTP
|
||||
$mail->Host = $ops["JAK_SMTPHOST"];
|
||||
$mail->SMTPAuth = $ops["JAK_SMTP_AUTH"] ? true : false; // enable SMTP authentication
|
||||
$mail->SMTPSecure = $ops["JAK_SMTP_PREFIX"]; // sets the prefix to the server
|
||||
$mail->SMTPAutoTLS = false;
|
||||
$mail->SMTPKeepAlive = $ops["JAK_SMTP_ALIVE"] ? true : false; // SMTP connection will not close after each email sent
|
||||
$mail->Port = $ops["JAK_SMTPPORT"]; // set the SMTP port for the GMAIL server
|
||||
$mail->Username = $ops["JAK_SMTPUSERNAME"]; // SMTP account username
|
||||
$mail->Password = $ops["JAK_SMTPPASSWORD"]; // SMTP account password
|
||||
|
||||
}
|
||||
elseif ($ops["JAK_SMTP_MAIL"] == 2)
|
||||
{
|
||||
//Tell PHPMailer to use SMTP
|
||||
$mail->isSMTP();
|
||||
//Whether to use SMTP authentication
|
||||
$mail->SMTPAuth = true;
|
||||
//Set AuthType to use XOAUTH2
|
||||
$mail->AuthType = "XOAUTH2";
|
||||
|
||||
$oauth_params = ["clientId" => $ops["JAK_OAUTH_CLIENTID"], "clientSecret" => $ops["JAK_OAUTH_SECRET"], ];
|
||||
|
||||
switch ($ops["JAK_OAUTH_PROVIDER"])
|
||||
{
|
||||
case "Google":
|
||||
$mail->Host = "smtp.gmail.com";
|
||||
$mail->Port = 465;
|
||||
$mail->SMTPSecure = PHPMailer::ENCRYPTION_SMTPS;
|
||||
$provider = new Google($oauth_params);
|
||||
break;
|
||||
case "Yahoo":
|
||||
$mail->Host = "smtp.mail.yahoo.com";
|
||||
$mail->Port = 465;
|
||||
$mail->SMTPSecure = PHPMailer::ENCRYPTION_SMTPS;
|
||||
$provider = new Yahoo($oauth_params);
|
||||
break;
|
||||
case "Microsoft":
|
||||
$mail->Host = "smtp.office365.com";
|
||||
$mail->Port = 587;
|
||||
$mail->SMTPSecure = PHPMailer::ENCRYPTION_STARTTLS;
|
||||
$provider = new Microsoft($oauth_params);
|
||||
break;
|
||||
case "Azure":
|
||||
$mail->Host = "smtp.office365.com";
|
||||
$mail->Port = 587;
|
||||
$mail->SMTPSecure = PHPMailer::ENCRYPTION_STARTTLS;
|
||||
$params["tenantId"] = $ops["JAK_OAUTH_TENANTID"];
|
||||
$provider = new Azure($oauth_params);
|
||||
break;
|
||||
}
|
||||
if ($provider)
|
||||
{
|
||||
$mail->setOAuth(new OAuth(["provider" => $provider, "clientId" => $ops["JAK_OAUTH_CLIENTID"], "clientSecret" => $ops["JAK_OAUTH_SECRET"], "refreshToken" => $ops["JAK_OAUTH_REFRESH"], "userName" => $ops["JAK_SMTP_SENDER"], ]));
|
||||
}
|
||||
}
|
||||
|
||||
// Finally send the email
|
||||
$mail->SetFrom($ops["JAK_SMTP_SENDER"]);
|
||||
$mail->addAddress($row["email"]);
|
||||
$mail->Subject = $ops["JAK_TITLE"] . " - " . sprintf($jkl["hd101"], $row["subject"]);
|
||||
$mail->MsgHTML($body);
|
||||
|
||||
// Send email to customer
|
||||
$mail->Send();
|
||||
}
|
||||
} // end sending closed message
|
||||
// Now we update the ticket table
|
||||
$jakdb->update($jaktable, ["ended" => time() , "status" => 3], ["id" => $row["id"]]);
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
// Calculate which tickets we will send a rating email
|
||||
$ticketrating = time() - $ops["JAK_TICKET_REOPEN"] * 86400;
|
||||
|
||||
// Send some ticket ratings emails which cannot be reopen again.
|
||||
$restr = $jakdb->select($jaktable, ["[>]clients" => ["clientid" => "id"]], ["support_tickets.id", "support_tickets.depid", "support_tickets.name", "support_tickets.email", "support_tickets.subject", "support_tickets.initiated", "clients.credits", "clients.paid_until", ], ["AND" => ["support_tickets.status[>]" => 2, "support_tickets.reminder" => 1, "support_tickets.ended[<]" => $ticketrating, ], ]);
|
||||
|
||||
if (isset($restr) && !empty($restr))
|
||||
{
|
||||
foreach ($restr as $rowtr)
|
||||
{
|
||||
// Dashboard URL
|
||||
$ticketratingurl = str_replace($url_filter, $url_replace, JAK_rewrite::jakParseurl($ops["JAK_CLIENT_URL"], "rt", $rowtr["id"], $rowtr["initiated"]));
|
||||
|
||||
// Let's check if we have an imap
|
||||
$answeremail = $ticktext = "";
|
||||
$check_imap = $jakdb->get($jaktable2, "emailanswer", ["depid" => $rowtr["depid"], ]);
|
||||
if ($check_imap)
|
||||
{
|
||||
$answeremail = $check_imap;
|
||||
}
|
||||
|
||||
// Get the ticket answer template
|
||||
if (!empty($HD_ANSWERS) && is_array($HD_ANSWERS))
|
||||
{
|
||||
foreach ($HD_ANSWERS as $v)
|
||||
{
|
||||
if ($v["msgtype"] == 25 && $v["lang"] == $ops["JAK_LANG"])
|
||||
{
|
||||
$phold = ["{url}", "{title}", "{cemail}", "{cname}", "{credits}", "{paid_until}", "{ticket}", "{subject}", "{ticketurl}", "{email}", ];
|
||||
$replace = [str_replace($cron_url, "", $BASE_URL) , $ops["JAK_TITLE"], $rowtr["email"], $rowtr["name"], $rowtr["credits"], $rowtr["paid_until"], "#" . $rowtr["id"], $rowtr["subject"], $ticketratingurl, $answeremail, ];
|
||||
$ticktext = str_replace($phold, $replace, $v["message"]);
|
||||
break;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
if (!empty($ticktext))
|
||||
{
|
||||
// Get the email template
|
||||
$nlhtml = file_get_contents(str_replace("cron/", "", $cron_url . "template/" . $ops["JAK_FRONT_TEMPLATE"] . "/email/index.html"));
|
||||
|
||||
// Change fake vars into real ones.
|
||||
$cssAtt = ["{emailcontent}", "{weburl}", "{title}", "{emailtpllogo}", "{emailtplcopy}", ];
|
||||
$cssUrl = [$ticktext, str_replace($cron_url, "", $BASE_URL) , $ops["JAK_TITLE"], $ops["JAK_EMAILTPLLOGO"], $ops["JAK_EMAILTPLCOPY"], ];
|
||||
$nlcontent = str_replace($cssAtt, $cssUrl, $nlhtml);
|
||||
|
||||
$body = str_ireplace("[\]", "", $nlcontent);
|
||||
|
||||
$mail = new PHPMailer(); // defaults to using php "mail()" or optional SMTP
|
||||
if ($ops["JAK_SMTP_MAIL"] == 1)
|
||||
{
|
||||
$mail->IsSMTP(); // telling the class to use SMTP
|
||||
$mail->Host = $ops["JAK_SMTPHOST"];
|
||||
$mail->SMTPAuth = $ops["JAK_SMTP_AUTH"] ? true : false; // enable SMTP authentication
|
||||
$mail->SMTPSecure = $ops["JAK_SMTP_PREFIX"]; // sets the prefix to the server
|
||||
$mail->SMTPAutoTLS = false;
|
||||
$mail->SMTPKeepAlive = $ops["JAK_SMTP_ALIVE"] ? true : false; // SMTP connection will not close after each email sent
|
||||
$mail->Port = $ops["JAK_SMTPPORT"]; // set the SMTP port for the GMAIL server
|
||||
$mail->Username = $ops["JAK_SMTPUSERNAME"]; // SMTP account username
|
||||
$mail->Password = $ops["JAK_SMTPPASSWORD"]; // SMTP account password
|
||||
|
||||
}
|
||||
elseif ($ops["JAK_SMTP_MAIL"] == 2)
|
||||
{
|
||||
//Tell PHPMailer to use SMTP
|
||||
$mail->isSMTP();
|
||||
//Whether to use SMTP authentication
|
||||
$mail->SMTPAuth = true;
|
||||
//Set AuthType to use XOAUTH2
|
||||
$mail->AuthType = "XOAUTH2";
|
||||
|
||||
$oauth_params = ["clientId" => $ops["JAK_OAUTH_CLIENTID"], "clientSecret" => $ops["JAK_OAUTH_SECRET"], ];
|
||||
|
||||
switch ($ops["JAK_OAUTH_PROVIDER"])
|
||||
{
|
||||
case "Google":
|
||||
$mail->Host = "smtp.gmail.com";
|
||||
$mail->Port = 465;
|
||||
$mail->SMTPSecure = PHPMailer::ENCRYPTION_SMTPS;
|
||||
$provider = new Google($oauth_params);
|
||||
break;
|
||||
case "Yahoo":
|
||||
$mail->Host = "smtp.mail.yahoo.com";
|
||||
$mail->Port = 465;
|
||||
$mail->SMTPSecure = PHPMailer::ENCRYPTION_SMTPS;
|
||||
$provider = new Yahoo($oauth_params);
|
||||
break;
|
||||
case "Microsoft":
|
||||
$mail->Host = "smtp.office365.com";
|
||||
$mail->Port = 587;
|
||||
$mail->SMTPSecure = PHPMailer::ENCRYPTION_STARTTLS;
|
||||
$provider = new Microsoft($oauth_params);
|
||||
break;
|
||||
case "Azure":
|
||||
$mail->Host = "smtp.office365.com";
|
||||
$mail->Port = 587;
|
||||
$mail->SMTPSecure = PHPMailer::ENCRYPTION_STARTTLS;
|
||||
$params["tenantId"] = $ops["JAK_OAUTH_TENANTID"];
|
||||
$provider = new Azure($oauth_params);
|
||||
break;
|
||||
}
|
||||
if ($provider)
|
||||
{
|
||||
$mail->setOAuth(new OAuth(["provider" => $provider, "clientId" => $ops["JAK_OAUTH_CLIENTID"], "clientSecret" => $ops["JAK_OAUTH_SECRET"], "refreshToken" => $ops["JAK_OAUTH_REFRESH"], "userName" => $ops["JAK_SMTP_SENDER"], ]));
|
||||
}
|
||||
}
|
||||
|
||||
// Finally send the email
|
||||
$mail->SetFrom($ops["JAK_SMTP_SENDER"]);
|
||||
$mail->addAddress($rowtr["email"]);
|
||||
$mail->Subject = $ops["JAK_TITLE"] . " - " . $jkl["g29"] . ": " . $rowtr["subject"];
|
||||
$mail->MsgHTML($body);
|
||||
|
||||
$mail->Send();
|
||||
}
|
||||
|
||||
// Now we update the ticket table
|
||||
$jakdb->update($jaktable, ["reminder" => 2], ["id" => $rowtr["id"]]);
|
||||
};
|
||||
}
|
||||
};
|
||||
}
|
||||
?>
|
||||
Reference in New Issue
Block a user