Files
fusionpbx/app/email_queue/resources/command/send.php
FusionPBX 7f9064fadb Update boolean toggle and the database boolean type (#7522)
* Change the data type to boolean

* Use boolean values in SQL and Conditional Statements

* Schema Data Types: Drop views so that alter tables statements complete

* Update settings.php

* Add extension for call_screen_enabled

* Gateway handle boolean
Add the boolean toggle
- distinct_to
- caller_id_in_from
- supress_cng
- extension_in_contact
- contact_in_ping

* Update gateways.php

* Update voicemail_edit.php

* Replace the ${caller_id_name} with the extensions caller id name

* Phrase - Edit: Update slide toggle with new select beneath.

* Update the input toggle style

* Set the input_toggle_style_switch as boolean

* Update the input toggle style

* Theme: Adjust CSS to wrap description text on form fields.

* Add domain_uuid and domain_name to the SQL SELECT

* Unset the parameters to fix the next query

* Gateway: Integrate new slide toggle switch.

* Dashboard: Update the input toggle style (#7499)

* Dashboard: Update the input toggle style

* Update dashboard_widget_edit.php

* Update dashboard_edit.php

* Inbound Route - Add: Integrate new slide toggle switch and boolean.

* User Settings: Integrate new slide toggle switch.

* Call Block Edit: Update the input toggle style (#7500)

* Bridge Edit: Update the input toggle style (#7501)

* Update phrases.php

* Update domain_edit.php

* Domain Settings Edit: Update the input toggle style

* User Edit: Update the input toggle style

* Update install.php

* Remove fields marked as deprecated

* Use boolean in the select statement

* Streams: New slide toggle and boolean.

* Streams: Remove unnecessary default.

* Queues (FIFO): New slide toggle.

* Call Detail Records: Update the input toggle style (#7503)

* Call Detail Records: Update the input toggle style

* Update xml_cdr_extension_summary.php

* Update xml_cdr_extension_summary.php

* Update xml_cdr_extension_summary.php

* Call Centers: Update the input toggle style (#7502)

* Call Centers: Update the input toggle style

* Update call_center_agent_edit.php

* Conference Centers: Update the input toggle style (#7506)

* Conference Centers: Update the input toggle style

* Update app_config.php

* Update conference_center_edit.php

* Use boolean data type (#7505)

* Call Flow Edit: Update the input toggle style (#7504)

* Devices: Update the input toggle style

* IVR Menus: New slide toggle.

* IVR Menu: Remove deprected file.

* SIP Profile - Edit: New slide toggle.

* Device Profiles: Update the input toggle style

* Ring Groups - List: Fix syntax.

* Theme: Fire onchange event when switching slide toggle control.

* Device Vendors: Update the input toggle style

* Update enabled boolean

* Update device_edit.php

* Ring Groups: New slide toggle.

* Update domain_edit.php

* Email Templates: Update the input toggle style

* Header: Correct default value on input toggle style.

* Default/Domain/User Settings: Adjust Select option label for better clarity.

* Use true boolean types for switch theme toggle or drop-down box (#7507)

* Groups: Update the input toggle style

* Conference Controls: Update the input toggle style (#7509)

* Conference Controls: Update the input toggle style

* Update conference_control_edit.php

* Update conference_control_details.php

* Update conference_control_detail_edit.php

* Conferences: Update the input toggle style (#7511)

* Use true boolean types for switch theme toggle or drop-down box (#7513)

* Dialplans: Update the input toggle style
Also updated outbound route add

* Ring Group: Only adjust ring group forward destination top margin when slide toggle enabled.

* Default/Domain/User Settings - List: Adjust for new 'Select Box' label on input_toggle_style value.

* Use true boolean types for switch theme toggle or drop-down box (#7514)

* Call Forward / Follow Me: Minor javascript adjustments to mirror previous behavior.

* Ring Groups [Dashboard]: New slide toggle.

* Get the contacts details with a seperate SQL Query

* Remove debug info

* Destinations: Update the input toggle style

* Conference Profiles: Update the input toggle style (#7515)

* Conference Profiles: Update the input toggle style

* Update conference_profiles.php

* Update conference_profile_params.php

* Update conference_profile_param_edit.php

* Update conference_profile_edit.php

* Extensions: Update the input toggle style

* Contacts: Update the input toggle style (#7517)

* Contacts: Update the input toggle style

* Update contact_address_edit.php

* Update contact_attachment_edit.php

* Update contact_edit.php

* Update contact_email_edit.php

* Update contact_phone_edit.php

* Update contact_relation_edit.php

* Update contact_setting_edit.php

* Update contact_url_edit.php

* Update contacts.php

* Voicemails: New slide toggle.

* Voicemail Greeting: New slide toggle.

* Modules: New slide toggle.

* Recordings: New slide toggle

* Variables: New slide toggle.

* Time Conditions: New slide toggle.

* Extensions - List: Remove invalid column name.

* Extension Settings: New slide toggle.

* Number Translations: New slide toggle and boolean.

* Sofia global settings: Update the input toggle style

* Update alter table convert to boolean

* Fix contact relation search (#7518)

* Sip Profile Edit: Fix setting enabled labels (#7519)

* Sip Profile Edit: Fix setting enabled labels

* Update sip_profile_edit.php

* Update dialplan_edit.php (#7520)

* Update SQL queries to use true/false for contact primary settings (#7521)

* Update SQL queries to use true/false for contact primary settings

* Update contacts_vcard.php

* Update email.php

* Update totp.php

* Update contact_url_edit.php

* Update contact_email_edit.php

* Update contact_address_edit.php

* Update contact_attachment_edit.php

* Update contact_phone_edit.php

* Add a database views method

* Add database view groups

* Add database users view

* Add database call_recordings view

* Update users.php

* Add  database view call block

* Update schema to use the database views method

* Update conference.conf.lua boolean

* Update directory.lua boolean

* Update callcenter.conf.lua agent_status boolean

* Update sofia.conf.lua boolean

* Update number translations lua boolean

* Update directory.lua boolean

* Update group_call.lua fix the cache

* Update reverse-auth-lookup.lua boolean

* Update directory.lua boolean

* Use concat instead of ||

* Update index.lua

---------

Co-authored-by: fusionate <nate@fusionpbx.com>
Co-authored-by: Alex <alex@fusionpbx.com>
Co-authored-by: frytimo <tim@fusionpbx.com>
2025-09-20 18:42:05 -06:00

257 lines
7.4 KiB
PHP

<?php
/*
Copyright (c) 2023 Mark J Crane <markjcrane@fusionpbx.com>
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
SUCH DAMAGE.
*/
//check the permission
if (defined('STDIN')) {
//includes files
require_once dirname(__DIR__, 4) . "/resources/require.php";
}
else {
exit;
}
//increase limits
set_time_limit(0);
//ini_set('max_execution_time',1800); //30 minutes
ini_set('memory_limit', '512M');
//save the arguments to variables
$script_name = $argv[0];
if (!empty($argv[1])) {
parse_str($argv[1], $_GET);
}
//define the short options
// : required, :: optional, no colon no value
//$short_options = "a"; // email address
//$short_options .= "l:"; // template language
//$short_options .= "c:"; // template_category
//$short_options .= "s:"; // template_subcategory
//$short_options .= "t::"; // template_type
//$short_options .= "D::"; // domain
//define the long options
$long_options = array(
"email_address:",
"email_attachment::",
"template_language:",
"template_category:",
"template_subcategory:",
"template_type:",
"domain_name:",
"debug:"
);
//get the email attachment allowed paths
if (isset($conf['email.attachments.0.path'])) {
$i = 0;
while(true) {
if (isset($conf['email.attachments.'.$i.'.path'])) {
$attachment_allowed_paths[] = $conf['email.attachments.'.$i.'.path'];
}
else {
break;
}
$i++;
}
}
//get the command line parameters
$options = getopt(null, $long_options);
//set the values from the command line parameters
foreach($options as $option_key => $option_value) {
switch ($option_key) {
case 'email_address':
if (is_array($option_value)) {
$email_array = $option_value;
}
else {
$email_array[] = $option_value;
}
break;
case 'email_attachment':
if (is_array($option_value)) {
$email_attachment_array = $option_value;
}
else {
$email_attachment_array[] = $option_value;
}
break;
case 'template_language':
$template_language = $option_value;
break;
case 'template_category':
$template_category = $option_value;
break;
case 'template_subcategory':
$template_subcategory = $option_value;
break;
case 'template_type':
$template_type = $option_value;
break;
case 'domain_name':
$domain_name = $option_value;
break;
case 'debug':
$debug = $option_value;
break;
}
}
//set default values
if (empty($template_language)) {
$template_language = 'en-us';
}
if (empty($template_type)) {
$template_type = 'html';
}
//prepare the email attachment
$i = 0;
foreach($email_attachment_array as $email_attachment) {
foreach($attachment_allowed_paths as $allowed_path) {
if ($allowed_path == dirname($email_attachment) && file_exists($email_attachment)) {
$email_attachments[$i]['path'] = dirname($email_attachment);
$email_attachments[$i]['name'] = basename($email_attachment);
}
$i++;
}
}
//get the domain_uuid
$sql = "select domain_uuid from v_domains ";
$sql .= "where domain_name = :domain_name ";
$parameters['domain_name'] = $domain_name;
$database = new database;
$domain_uuid = $database->select($sql, $parameters, 'column');
unset($parameters);
//get the email queue settings
$smtp_from = $settings->get('email', 'smtp_from');
$smtp_from_name = $settings->get('email', 'smtp_from_name', $smtp_from);
$save_response = $settings->get('email_queue', 'save_response');
//debug information
if (!empty($debug) && $debug == 'true') {
echo "email_address: "; print_r($email_array);
echo "template_language: ".$template_language."\n";
echo "template_category: ".$template_category."\n";
echo "template_subcategory: ".$template_subcategory."\n";
echo "template_type: ".$template_type."\n";
echo "domain_name: ".$domain_name."\n";
echo "debug: ".$debug."\n";
echo "smtp_from: $smtp_from\n";
echo "smtp_from_name: $smtp_from_name\n";
}
//define the message variable
$message = '';
//show required details
if (empty($smtp_from)) {
$message .= "smtp_from needs to be set in Default Settings\n";
}
if (!is_array($email_array)) {
$message .= "email_address\n";
}
if (empty($smtp_from)) {
$message .= "template_category\n";
}
if (empty($template_subcategory)) {
$message .= "template_subcategory\n";
}
if (empty($domain_name)) {
$message .= "domain_name\n";
}
if (!empty($message)) {
echo "Following parameters are required\n";
echo $message;
exit;
}
//get the email template from the database
$sql = "select template_subject, template_body from v_email_templates ";
$sql .= "where template_enabled = true ";
$sql .= "and template_language = :template_language ";
$sql .= "and template_category = :template_category ";
$sql .= "and template_subcategory = :template_subcategory ";
$sql .= "and template_type = :template_type ";
$sql .= "and (domain_uuid = :domain_uuid or domain_uuid is null) ";
$parameters['domain_uuid'] = $domain_uuid;
$parameters['template_language'] = $template_language;
$parameters['template_category'] = $template_category;
$parameters['template_subcategory'] = $template_subcategory;
$parameters['template_type'] = $template_type;
$database = new database;
$row = $database->select($sql, $parameters, 'row');
if (is_array($row)) {
$email_subject = $row['template_subject'];
$email_body = $row['template_body'];
}
unset($sql, $parameters);
//replace variables in email subject
if (!empty($email_subject)) {
$email_subject = str_replace('${domain_name}', $domain_name, $email_subject);
}
//replace variables in email body
if (!empty($email_body)) {
$email_body = str_replace('${domain_name}', $domain_name, $email_body);
}
//more debug information
if (!empty($debug) && $debug == 'true') {
echo "email_subject: $email_subject\n";
echo "email_body: ";
echo $email_body."\n";
}
//create the email object
$email = new email;
//send email
foreach ($email_array as $email_address) {
$email->recipients = $email_address;
$email->subject = $email_subject;
$email->body = $email_body;
$email->from_address = $smtp_from;
$email->from_name = $smtp_from_name;
if (isset($email_attachments)) {
$email->attachments = $email_attachments;
}
$email->debug_level = 3;
$email_response = $email->send();
if (!empty($debug) && $debug == 'true') {
echo $email_response;
}
}
?>