| Server IP : 172.67.201.108 / Your IP : 216.73.217.64 Web Server : Apache/2.4.68 (Amazon Linux) OpenSSL/3.5.5 System : Linux ip-172-31-69-123.ec2.internal 6.1.176-223.369.amzn2023.x86_64 #1 SMP PREEMPT_DYNAMIC Fri Jul 24 13:34:27 UTC 2026 x86_64 User : ec2-user ( 1000) PHP Version : 8.4.23 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : OFF | Sudo : ON | Pkexec : ON Directory : /home/connectionsdev/mod/ |
Upload File : |
<?php
require_once('_constants.php');
require_once('_permissions.php');
require_once('_password.php');
include_once __DIR__ . '../../vendor/autoload.php';
spl_autoload_register(function ($class) {
$class = str_replace('\\', '/', $class);
if (file_exists($class . '.php')) {
include $class . '.php';
return;
}
if (file_exists('classes/lib/' . $class . '.php')) {
include'classes/lib/' . $class . '.php';
return;
}
$file = __DIR__ . '/../' . $class . '.php';
if (file_exists($file)) {
include $file;
}
});
/*
set_error_handler(function($errno, $errstr, $errfile, $errline) {
if (
str_starts_with($errstr, 'Undefined array key')
|| str_starts_with($errstr, 'Undefined variable')
) :
//throw new ErrorException($errstr, 0, E_NOTICE, $errfile, $errline);
trigger_error($errstr . ' in ' . $errfile . ' on line ' . $errline, E_USER_NOTICE);
return true;
else :
return false; //default error handler
endif;
}, E_WARNING);
*/
const APP_CONCIERGE_SERVICES = array('Abigail Michaels', 'NYGuest', 'AA Jacks', 'City Experts', 'CGS', 'Luxury Attache');
const APP_HOTEL_RETAIL_VISITOR_CTR = array('Hotel', 'Retail', 'Visitor Center', 'Other');
function parse_uri($parm = 'IX', $offset = 0, $default = 'home', $force_slug = false) {
if (isset($_GET[$parm])) :
return $_GET[$parm];
endif;
global $ar_pagecontrol;
$result = '';
$url = strtok($_SERVER['REQUEST_URI'],'?');
//$ar_uri = explode('/', $_SERVER['REQUEST_URI']);
$ar_uri = explode('/', $url);
if ($offset >= 0) :
$offset = $offset + APP_URI_OFFSET;
else :
$offset = count($ar_uri) + $offset;
endif;
if ($offset > count($ar_uri) + 1 || $offset < APP_URI_OFFSET) :
return $default;
endif;
$slug = $ar_uri[$offset];
$item = null;
foreach($ar_pagecontrol as $key=>$value) :
if (isset($value['slug']) && !is_array($value['slug']) && $value['slug'] > ' ' && $slug == $value['slug']) :
$item = $key;
break;
elseif (isset($value['slug']) && is_array($value['slug']) && count($value['slug']) > 0) : //** for landing pages **
foreach ($value['slug'] as $slug_base) :
if (strtolower(substr($slug, 0, strlen($slug_base))) == strtolower($slug_base)) :
$item = $key;
break 2;
endif;
endforeach;
endif;
endforeach;
if ($force_slug) :
$result = $slug;
elseif ($item) :
$result = $key;
elseif ($parm != 'IX') :
$result = $slug;
endif;
return $result;
}
$ar_ftype = array();
$ar_ffields = array();
$ar_fupdate = array();
$ar_finsert = array();
$ar_fretrieve = array();
function is_assoc_array($arr)
{
return array_keys($arr) !== range(0, count($arr) - 1);
}
function form_field($fname, $ftype = 'text', $fsize = '50', $frows = 0, $frequired = false, $disabled = false, $readonly = false, $fstyle = "", $fclass = "", $fdbname = "", $flabel = "", $ar_group = [], $onchange = "", $onblur = "", $qtip = "", $datatype = '', $err_message = '', $filter_options = null, $echo = true, $maxlength = '', $horizontal_layout = false, $form_id = NULL, $placeholder = '' )
{
global $ar_err;
global $xform_fid;
global $curr_tab;
if (is_array(func_get_arg(0))) :
$ar_args = func_get_arg(0);
$fname = (isset($ar_args['fname']) ? $ar_args['fname'] : $fname);
$ftype = (isset($ar_args['ftype']) ? $ar_args['ftype'] : $ftype);
$fsize = (isset($ar_args['fsize']) ? $ar_args['fsize'] : $fsize);
$frows = (isset($ar_args['frows']) ? $ar_args['frows'] : $frows);
$frequired = (isset($ar_args['frequired']) ? $ar_args['frequired'] : $frequired);
$disabled = (isset($ar_args['disabled']) ? $ar_args['disabled'] : $disabled);
$readonly = (isset($ar_args['readonly']) ? $ar_args['readonly'] : $readonly);
$fstyle = (isset($ar_args['fstyle']) ? $ar_args['fstyle'] : $fstyle);
$fclass = (isset($ar_args['fclass']) ? $ar_args['fclass'] : $fclass);
$fdbname = (isset($ar_args['fdbname']) ? $ar_args['fdbname'] : $fdbname);
$flabel = (isset($ar_args['flabel']) ? $ar_args['flabel'] : $flabel);
$ar_group = (isset($ar_args['ar_group']) ? $ar_args['ar_group'] : $ar_group);
$onchange = (isset($ar_args['onchange']) ? $ar_args['onchange'] : $onchange);
$onblur = (isset($ar_args['onblur']) ? $ar_args['onblur'] : $onblur);
$qtip = (isset($ar_args['qtip']) ? $ar_args['qtip'] : $qtip);
$datatype = (isset($ar_args['datatype']) ? $ar_args['datatype'] : $datatype);
$err_message = (isset($ar_args['err_message']) ? $ar_args['err_message'] : $err_message);
$filter_options = (isset($ar_args['filter_options']) ? $ar_args['filter_options'] : $filter_options);
$echo = (isset($ar_args['echo']) ? $ar_args['echo'] : $echo);
$maxlength = (isset($ar_args['maxlength']) ? $ar_args['maxlength'] : $maxlength);
$horizontal_layout = (isset($ar_args['horizontal_layout']) ? $ar_args['horizontal_layout'] : $horizontal_layout);
$form_id = (isset($ar_args['form_id']) ? $ar_args['form_id'] : $form_id);
$placeholder = (isset($ar_args['placeholder']) ? $ar_args['placeholder'] : $placeholder);
endif;
$GLOBALS['ar_fields_'.$xform_fid][$fname] = array('ftype'=>$ftype, 'datatype'=>$datatype, 'filter_options'=>$filter_options, 'fsize'=>$fsize, 'frequired'=>$frequired, 'disabled'=>$disabled, 'readonly'=>$readonly, 'fdbname'=>$fdbname, 'tab'=>$curr_tab, 'err_message'=>$err_message);
if (empty($fdbname)) :
$fdbname = $fname;
endif;
if (!empty($fstyle)) :
$style = ' style="'.$fstyle.'" ';
endif;
if ($frequired) :
$fclass .= ' required';
endif;
if (!empty($ar_err[$fname])) :
$fclass .= ' inerror';
endif;
if ($ftype == 'image' || $ftype == 'file') :
$fclass .= ' photo_label';
endif;
if (!empty($fclass)) :
$class = ' class="'.trim($fclass).'" ';
endif;
$fid = $fname;
if (!empty($form_id)) :
$fid = $fid . '_' . $form_id;
$form_id = ' form="'.trim($form_id).'" ';
endif;
if ($disabled) :
$disabled = ' disabled="disabled" ';
endif;
if ($readonly) :
$readonly = ' readonly="readonly" ';
endif;
if (!empty($onchange)) :
if ($ftype == 'radiogroup') :
$onchange = 'if ($(this).prop(\'checked\')) {'.$onchange.'}';
endif;
$onchange = ' onchange="'.trim($onchange).'" ';
endif;
if ($ftype == 'autocomplete') :
$onblur .= ' lcs_autocomplete_close(\''.$fname.'\'); ';
endif;
if (!empty($onblur)) :
$onblur = ' onblur="'.trim($onblur).'" ';
endif;
if (!empty($placeholder)) :
$placeholder = ' placeholder="'.trim($placeholder).'" ';
endif;
$group_break = '<br />';
if ($horizontal_layout) :
$group_break = ' ';
endif;
$attributes = ($style ?? NULL).($class ?? NULL).($form_id ?? NULL).$disabled.$readonly.$placeholder.$onchange.$onblur;
$attributes_rc = ($form_id ?? NULL).$disabled.$readonly.$onchange.$onblur;
$ar_err[$fname] = $ar_err[$fname] ?? NULL;
$_POST[$fname] = $_POST[$fname] ?? NULL;
switch ($ftype) :
case "text" :
case "password" :
echo '<div class="input_field">';
echo '<label for="'.$fid.'">'.$flabel.'</label>';
echo '<input name="'.$fname.'" id="'.$fid.'" type="'.$ftype.'" maxlength="'.$fsize.'" value="'.$_POST[$fname].'" '.$attributes.' />';
show_form_error($ar_err[$fname]);
$ar_ftype[] = $ftype;
$ar_ffields[] = $fdbname;
$ar_fupdate[] = $fdbname;
echo '</div>';
break;
case "select":
echo '<div class="input_field">';
echo '<label for="'.$fid.'">'.$flabel.'</label>';
echo '<select name="'.$fname.'" id="'.$fid.'" '.$attributes.'>';
$selected = '';
if ($readonly || $disabled) :
$selected = ' disabled="disabled" ';
endif;
echo '<option value="" '.$selected.' >Select...</option>';
if (is_assoc_array($ar_group)) :
foreach ($ar_group as $key => $value) :
$selected = '';
if ((string)$_POST[$fname] == (string)$key) :
$selected = ' selected="selected" ';
elseif ($readonly || $disabled) :
$selected = ' disabled="disabled" ';
endif;
if (is_array($value)) :
echo '<option data-value="'.$value[0][2].'" value="'.$key.'" '.$selected.' /> '.$value[0][1].'</option>';
else :
echo '<option value="'.$key.'" '.$selected.' /> '.$value.'</option>';
endif;
endforeach;
else :
foreach ($ar_group as $value) :
$selected = '';
if ((string)$_POST[$fname] == (string)$value) :
$selected = ' selected="selected" ';
elseif ($readonly || $disabled) :
$selected = ' disabled="disabled" ';
endif;
echo '<option value="'.$value.'" '.$selected.' /> '.$value.'</option>';
endforeach;
endif;
echo '</select>';
show_form_error($ar_err[$fname]);
echo '</div>';
break;
case "autocomplete":
echo '<div class="input_field">';
echo '<label for="'.$fid.'">'.$flabel.'</label>';
echo '<input name="'.$fname.'" id="'.$fid.'" type="text" maxlength="'.$fsize.'" value="'.$_POST[$fname].'" '.$attributes.' onfocus="lcs_autocomplete_open(\''.$fid.'\')" onkeyup="lcs_autocomplete_filter(\''.$fid.'\')" />';
echo '<div id="'.$fid.'_autocomplete" class="autocomplete"><ul>';
foreach ($ar_group as $value) :
echo '<li onclick="lcs_autocomplete_pick(this, \''.$fid.'\');">'.$value.'</li>';
endforeach;
echo '</ul></div>';
show_form_error($ar_err[$fname]);
echo '</div>';
break;
case "radiogroup":
echo '<div class="input_field">';
echo '<label for="'.$fid.'">'.$flabel.'</label>';
echo '<fieldset id="'.$fid.'" '.$attributes.'>';
if (is_assoc_array($ar_group)) :
foreach ($ar_group as $key => $value) :
$checked = '';
if (isset($_POST[$fname]) && $_POST[$fname] == $key) :
$checked = ' checked="checked" ';
endif;
echo '<div class="rc_text"><label><input type="radio" name="'.$fname.'" value="'.$key.'" '.$checked.' '.$attributes_rc.' /> '.$value.'</label></div>'.$group_break;
//echo '<input type="radio" name="'.$fname.'" value="'.$key.'" '.$checked.' '.$attributes.' /> '.$value.$group_break;
//echo $key.' '.$value.'<br />';
endforeach;
else :
foreach ($ar_group as $value) :
$checked = '';
if ($_POST[$fname] == $value) :
$checked = ' checked="checked" ';
endif;
echo '<div class="rc_text"><label><input type="radio" name="'.$fname.'" value="'.$value.'" '.$checked.' '.$attributes_rc.' /> '.$value.'</label></div>'.$group_break;
//echo '<input type="radio" name="'.$fname.'" value="'.$value.'" '.$checked.' '.$attributes.' /> '.$value.$group_break;
//echo $value.'<br />';
endforeach;
endif;
echo '</fieldset>';
show_form_error($ar_err[$fname], false);
echo '</div>';
break;
case "checkgroup":
echo '<div class="input_field">';
echo '<label for="'.$fid.'">'.$flabel.'</label>';
echo '<fieldset id="'.$fid.'" '.$attributes.'>';
if (is_assoc_array($ar_group)) :
foreach ($ar_group as $key => $value) :
$checked = '';
if (is_array($_POST[$fname]) && in_array($key, $_POST[$fname])) :
$checked = ' checked="checked" ';
endif;
echo '<div class="rc_text"><label><input type="checkbox" name="'.$fname.'[]" value="'.$key.'" '.$checked.' '.$attributes_rc.' /> '.$value.'</label></div>'.$group_break;
//echo '<input type="checkbox" name="'.$fname.'[]" value="'.$key.'" '.$checked.' '.$attributes.' /> '.$value.$group_break;
//echo $key.' '.$value.'<br />';
endforeach;
else :
foreach ($ar_group as $value) :
$checked = '';
if (is_array($_POST[$fname]) && in_array($value, $_POST[$fname])) :
$checked = ' checked="checked" ';
endif;
echo '<div class="rc_text"><label><input type="checkbox" name="'.$fname.'[]" value="'.$value.'" '.$checked.' '.$attributes_rc.' /> '.$value.'</label></div>'.$group_break;
//echo '<input type="checkbox" name="'.$fname.'[]" value="'.$value.'" '.$checked.' '.$attributes.' /> '.$value.$group_break;
//echo $value.'<br />';
endforeach;
endif;
echo '</fieldset>';
show_form_error($ar_err[$fname], false);
echo '</div>';
break;
case "checkbox":
case "radio":
echo '<div class="input_field">';
$checked = '';
if ('1' == $_POST[$fname]) :
$checked = ' checked="checked" ';
endif;
echo '<div class="rc_text"><label><input type="'.$ftype.'" name="'.$fname.'" id="'.$fid.'" value="1" '.$checked.' '.$attributes_rc.' /> '.$flabel.'</label></div>';
//echo '<input type="'.$ftype.'" name="'.$fname.'" id="'.$fname.'" value="1" '.$checked.' '.$attributes.' /> '.$flabel;
show_form_error($ar_err[$fname]);
echo '</div>';
break;
case "textarea" :
echo '<div class="input_field">';
echo '<label for="'.$fid.'">'.$flabel.'</label>';
echo '<textarea name="'.$fname.'" id="'.$fid.'" cols="'.$fsize.'" rows="'.$frows.'" ';
if ($readonly || $disabled) :
echo ' disabled="disabled" readonly="readonly" ';
endif;
if (!empty($maxlength)) :
echo ' maxlength="'.$maxlength.'" ';
endif;
if (!empty($fstyle)) :
echo ' style="'.$fstyle.'" ';
endif;
if (!empty($fclass)) :
echo ' class="'.$fclass.'" ';
endif;
echo ' >';
echo $_POST[$fname];
echo '</textarea>';
show_form_error($ar_err[$fname]);
echo '</div>';
break;
case "date" :
echo '<div class="input_field">';
echo '<label for="'.$fid.'">'.$flabel.'</label>';
echo '<input name="'.$fname.'" id="'.$fid.'" type="text" maxlength="'.$fsize.'" value="'.nzdate_display($_POST[$fname]).'" '.$attributes.' />';
show_form_error($ar_err[$fname]);
echo '</div>';
break;
case "datetime" :
echo '<div class="input_field">';
echo '<label for="'.$fid.'">'.$flabel.'</label>';
echo '<input name="'.$fname.'" id="'.$fid.'" type="text" maxlength="'.$fsize.'" value="'.nzdate_display_datetime($_POST[$fname]).'" '.$attributes.' />';
show_form_error($ar_err[$fname]);
echo '</div>';
break;
case "htmlarea" :
echo '<div class="input_field">';
echo '<label for="'.$fid.'">'.$flabel.'</label>';
echo '<div name="'.$fname.'" id="'.$fid.'" class="form_htmlarea" '.$attributes.' >';
echo $_POST[$fname];
echo '</div>';
show_form_error($ar_err[$fname]);
echo '</div>';
break;
case "file" :
echo '<div class="input_field">';
echo '<label for="'.$fid.'_label">'.$flabel.'</label>';
echo '<label for="'.$fid.'" '.$attributes.' >';
echo 'Click/Touch here to upload a file<br />';
echo '<input name="'.$fname.'" id="'.$fid.'" type="file" />';
echo '</label>';
echo '<input name="'.$fname.'_filename" id="'.$fid.'_filename" type="hidden" maxlength="255" value="'.$_POST[$fname.'_filename'].'" />';
show_form_error($ar_err[$fname], false);
echo '</div>';
break;
case "image" :
echo '<div class="input_field">';
echo '<label for="'.$fid.'_label">'.$flabel.'</label>';
echo '<label for="'.$fid.'" '.$attributes.' >';
echo 'Click/Touch here to upload or snap a photo<br />';
echo '<input name="'.$fname.'" id="'.$fid.'" type="file" accept="image/*" capture="camera" />';
echo '</label>';
echo '<input name="'.$fname.'_filename" id="'.$fid.'_filename" type="hidden" maxlength="255" value="'.$_POST[$fname.'_filename'].'" />';
show_form_error($ar_err[$fname], false);
echo '</div>';
break;
endswitch;
}
function form_validate($field, $valtype, $required = false, $tab = 'basic_info', $message = '') {
global $ar_err;
global $err_flag;
global $err_tab;
if ($required && trim($_POST[$field]) == '') :
if (empty($message)) :
$message = 'Required!';
endif;
$ar_err[$field] = $message;
$err_flag = true;
$err_tab = $tab;
return;
endif;
if (trim($_POST[$field]) != '') :
if (empty($message)) :
$message = 'Invalid!';
endif;
switch ($valtype) :
case 'string' :
break;
case 'email' :
if (filter_var($_POST[$field], FILTER_VALIDATE_EMAIL) === false) :
$ar_err[$field] = $message;
$err_flag = true;
$err_tab = $tab;
endif;
break;
case 'url' :
if (filter_var($_POST[$field], FILTER_VALIDATE_URL) === false) :
$ar_err[$field] = $message;
$err_flag = true;
$err_tab = $tab;
endif;
break;
case 'int' :
if (filter_var($_POST[$field], FILTER_VALIDATE_INT) === false) :
$ar_err[$field] = $message;
$err_flag = true;
$err_tab = $tab;
endif;
break;
case 'float' :
if (filter_var($_POST[$field], FILTER_VALIDATE_FLOAT) === false) :
$ar_err[$field] = $message;
$err_flag = true;
$err_tab = $tab;
endif;
break;
case "captcha" :
$verifyResponse = file_get_contents('https://www.google.com/recaptcha/api/siteverify?secret='.APP_RECAPTCHA_SECRET_KEY.'&response='.$_POST[$field]);
$responseData = json_decode($verifyResponse);
if (!$responseData->success) :
$ar_err[$field] = $message;
$err_flag = true;
$err_tab = $tab;
endif;
break;
endswitch;
endif;
return;
}
function form_validate_all($exclusions = []) {
global $err_flag;
global $xform_fid;
if (is_array($_SESSION['ar_fields_'.$xform_fid]) && count($_SESSION['ar_fields_'.$xform_fid]) > 0) :
foreach($_SESSION['ar_fields_'.$xform_fid] as $key => $value) :
if (!in_array($key, $exclusions)) :
$datatype = (!empty($value['datatype']) ? $value['datatype'] : $value['ftype'] );
form_validate($key, $datatype, $value['frequired'], $value['tab'], '', $value['filter_options']);
endif;
endforeach;
else :
$err_flag = true;
endif;
}
function form_generate_set(bool $include_read_only = false) {
global $db;
global $xform_fid;
if (is_array($_SESSION['ar_fields_'.$xform_fid]) && count($_SESSION['ar_fields_'.$xform_fid]) > 0) :
$ar_set = array();
foreach($_SESSION['ar_fields_'.$xform_fid] as $key => $value) :
if (!empty($value['fdbname'])) :
if (($include_read_only && $value['readonly']) || (!$value['readonly'])) :
$datatype = (!empty($value['datatype']) ? $value['datatype'] : $value['ftype'] );
switch ($datatype) :
case 'text' :
case 'string' :
case 'password' :
case 'autocomplete' :
case 'radiogroup' :
case 'radio' :
case 'checkbox' :
case 'select' :
case 'colorpick' :
case 'textarea' :
case 'url' :
case 'email' :
$ar_set[] = $value['fdbname']." = ".$db->quote($_POST[$key]);
break;
case 'checkgroup' :
$ar_set[] = $value['fdbname']." = ".$db->quote(implode(',', $_POST[$key]));
break;
case 'date' :
$ar_set[] = $value['fdbname']." = ".nzdate($_POST[$key]);
break;
case 'datetime' :
$ar_set[] = $value['fdbname']." = ".nzdatetime($_POST[$key]);
break;
case 'int' :
$ar_set[] = $value['fdbname']." = ".nz($_POST[$key], '0');
break;
case 'float' :
$ar_set[] = $value['fdbname']." = ".nzfloat($_POST[$key], '0.00');
break;
case 'image' :
$ar_set[] = $value['fdbname']." = ".$db->quote($_POST[$key.'_filename']);
break;
endswitch;
endif;
endif;
endforeach;
$set = ' '.implode(', ', $ar_set).' ';
return $set;
else :
echo form_fatal_error('Error - Unable to generate database SQL!');
die();
endif;
}
function form_button_strip($location, $ar_args = [], $show_create_update = true, $extra_class = '') {
global $ar_pagecontrol;
global $xform_uid;
global $xform_fid;
$defaults = [
'save' => ['show' => true, 'caption' => 'Save', 'js' => "sheet_dirty = false; this.form.submit();"],
'save_close' => ['show' => true, 'caption' => 'Save & Close', 'js' => "sheet_dirty = false; document.getElementById('xsubmit').value = this.value; this.form.submit();"],
'save_new' => ['show' => true, 'caption' => 'Save & New', 'js' => "sheet_dirty = false; document.getElementById('xsubmit').value = this.value; this.form.submit();"],
'cancel' => ['show' => true, 'caption' => 'Cancel', 'js' => "sheet_dirty = false; appstack_pop();"],
];
$ar_args = array_merge($defaults, $ar_args);
echo '<div class="form_strip ' . $extra_class . '">';
if (strtolower($location) == 'bottom' && $show_create_update) :
show_create_update();
endif;
foreach ($ar_args as $key => $value) :
if ($value['show']) :
if ($key == 'cancel' || empty($ar_pagecontrol[$_GET['IX']]['update_roles']) || role_match($ar_pagecontrol[$_GET['IX']]['update_roles'], get_roles())) :
echo '<input type="button" value="'.$value['caption'].'" onclick="'.$value['js'].'" />';
endif;
endif;
endforeach;
if (strtolower($location) == 'bottom') :
echo '<input type="hidden" name="xsubmit" id="xsubmit" />';
echo '<input type="hidden" name="xform_uid" id="xform_uid" value="'.$xform_uid.'" />';
if (!empty($xform_fid)) :
$_SESSION['ar_fields_'.$xform_fid] = $GLOBALS['ar_fields_'.$xform_fid];
endif;
endif;
echo '</div>';
}
function form_prep($default_ref = '', $default_tab = '', $frm_id = '', $login_required = true) {
global $action;
global $active_tab;
global $xform_uid;
global $xform_fid;
global $form_message;
$form_message = '';
if ($login_required) :
if (isset($_SESSION['user_id'])) :
if (isset($_REQUEST['id']) && is_numeric($_REQUEST['id'])) :
$action = "Edit";
else :
$action = "Add New";
endif;
else :
exit('Not Authorized!');
endif;
endif;
if (empty($_REQUEST['ref'])) :
$_REQUEST['ref'] = $default_ref;
endif;
if (empty($_REQUEST['tab'])) :
$active_tab = $default_tab;
else :
$active_tab = $_REQUEST['tab'];
endif;
$xform_uid = generate_random_string();
$_SESSION[$xform_uid] = true;
$xform_fid = $_GET['IX'].'_'.$frm_id;
$GLOBALS['ar_fields_'.$xform_fid] = array();
}
function form_prep_submit() {
if ($_SESSION[$_POST['xform_uid']] !== true) :
echo form_fatal_error('Invalid Operation - perhaps you tried to reload the page, use the browser "Back" button, or your session has expired.');
exit();
endif;
global $active_tab;
if (isset($_POST['active_tab'])) :
$active_tab = $_POST['active_tab'];
else :
$active_tab = 'basic_info';
endif;
$GLOBALS['ar_err'] = array();
}
function form_uid_reset()
{
$_SESSION[$_POST['xform_uid']] = false;
}
function form_reload_check()
{
if ($_SESSION[$_POST['xform_uid']] !== true) :
echo form_fatal_error('Invalid Operation - you tried to reload the page!');
exit();
endif;
}
function generate_random_string($length = 16)
{
$characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
$random_string = '';
for ($i = 0; $i < $length; $i++) :
$random_string .= $characters[rand(0, strlen($characters) - 1)];
endfor;
return $random_string;
}
function auto_complete($fname, $value, $text, $fsql, $limit_to_list = null, $w = null, $h = null, $tab_index = null, $change_js = null, $class = null)
{
// For DB query, the first field of the SQL statement must be the actual value, second is the display value
// For list of items, they must be in pairs separated by semicolon and separated by comma within the pair, no spaces. Ex: r,red;b,blue;w,white
global $db;
if (is_null($limit_to_list)) :
$limit_to_list = false;
endif;
if (is_null($w)) :
$w = 300;
endif;
if (is_null($h)) :
$h = 16;
endif;
if (is_null($tab_index)) :
$tab_index = 0;
endif;
if (is_null($change_js)) :
$change_js = '';
endif;
if (is_null($class)) :
$class = '';
endif;
//echo 'AC parms: Width: '.$w.' Height: '.$h;
$hdiv = $h + 4;
$wdiv = $w + 4;
if ($limit_to_list == true) :
$limit_list = 'true';
else :
$limit_list = 'false';
endif;
$tab = '';
if ($tab_index > 0) :
$tab = 'tabindex="'.$tab_index.'"';
endif;
echo '<div class="autocomplete" id="ac_wrap_'.$fname.'" style="width:'.$wdiv.'px; height:'.$hdiv.'px;">';
echo '<input type="hidden" id="'.$fname.'" name="'.$fname.'" value="'.$value.'" />';
//echo '<input type="text" '.$tab.' class="autocomplete" style="width:'.$w.'px; height:'.$h.'px;" id="'.$fname.'_mask" name="'.$fname.'_mask" value="'.$text.'" onfocus="autocomplete_open(\''.$fname.'\')" onblur="autocomplete_close(\''.$fname.'\','.$limit_list.');'.$change_js.'" onkeyup="autocomplete_filter(\''.$fname.'\')" />';
//echo '<input type="text" '.$tab.' class="autocomplete" style="width:'.$w.'px; height:'.$h.'px;" id="'.$fname.'_mask" name="'.$fname.'_mask" value="'.$text.'" onfocus="autocomplete_open(\''.$fname.'\', '.$limit_list.')" onblur="'.$change_js.'" onkeyup="autocomplete_filter(\''.$fname.'\'); ac_filter = 1;" onmouseup="autocomplete_toggle(\''.$fname.'\', '.$limit_list.');" />';
echo '<input type="text" '.$tab.' class="autocomplete '.$class.'" style="width:'.$w.'px; height:'.$h.'px;" id="'.$fname.'_mask" name="'.$fname.'_mask" value="'.$text.'" onfocus="autocomplete_open(\''.$fname.'\', '.$limit_list.')" onblur="'.$change_js.'" onkeyup="autocomplete_filter(event, \''.$fname.'\'); ac_filter = 1;" />';
echo '<a href="javascript:autocomplete_toggle(\''.$fname.'\', '.$limit_list.');" ><img class="ac_dropdown" src="img/arrow_down.png" /></a>';
echo '<div class="autocomplete_items" style="width:'.$w.'px;" id="'.$fname.'_items" >';
if (substr(trim(strtoupper($fsql)),0,6) == 'SELECT') :
$result = $db->query($fsql);
echo '<ul class="autocomplete_list" id="'.$fname.'_items_ul" style="list-style-type: none; padding:0; margin:0;">';
while ($row = $result->fetch(PDO::FETCH_NUM)):
echo '<li ac_value="'.$row[0].'" onclick="autocomplete_pick(\''.$fname.'\', \''.$row[0].'\', \''.$row[1].'\', '.$limit_list.');" >'.$row[1].'</li>';
endwhile;
echo '</ul>';
else :
endif;
echo '</div>';
echo '</div>';
}
function form_tab_header($id, $title, $roles = '') {
if (role_match(get_roles(), $roles) || empty($roles)) :
echo '<div class="tab_header" id="tab_'.$id.'" onclick="switch_tab(\''.$id.'\');">';
echo $title;
echo '</div>';
endif;
}
function form_tab_start($tab, $title, $display = true) {
$GLOBALS['tab_display_control_'.$tab] = $display;
if ($display === true) :
$GLOBALS['curr_tab'] = $tab;
echo '<div class="tab_content" id="tab_content_'.$tab.'">';
echo '<div class="form_header">';
echo $title;
echo '</div>';
endif;
}
function form_tab_end() {
$display = $GLOBALS['tab_display_control_'.$GLOBALS['curr_tab']];
if ($display === true) :
echo '</div>';
endif;
}
function form_column_start($style = '') {
echo '<div class="input_column" style="' . $style . '">';
}
function form_column_end() {
echo '</div>';
}
function form_tab_strip_start($style = '') {
echo '<div class="tab_strip" style="' . $style . '">';
}
function form_tab_strip_end() {
echo '
</div>
<div class="cleardiv">
</div>
';
}
function form_message($form_message = '') {
if (!empty($form_message)) :
echo '<div class="form_message">'.$form_message.'</div>';
endif;
}
function form_fatal_error($form_message = '') {
if (!empty($form_message)) :
echo '<div class="form_message" style="color:#ff0000; font-weight:bold;">';
echo $form_message.'<br /><br />';
//echo '<input type="button" value="Back" onclick="window.history.back()" />';
echo '<input type="button" value="Back" onclick="appstack_pop();" />';
echo '</div>';
endif;
}
function form_tab_revisions(string $table_name, int|null|string $id_value, string $id_field = 'id'): void {
if (empty($id_value)) :
return;
endif;
global $db;
form_tab_start('revisions', 'Revision History');
db_navigator_bar(['table_id' => 'db_grid_revisions', 'form' => '', 'btn_addnew'=>'false', 'print_section' => 'db_grid_revisions', 'call' => 'revisions_ajax', 'sort_col' => '1', 'sort_order' => '1', 'subtab' => 'true', 'parm1' => " AND r.table_name = " . $db->quote($table_name) . " AND r.id_value = " . nz($id_value, '0') . " ", 'func' => 'grid']);
form_tab_end();
?>
<div id="grid_popup" class="grid_popup" style="padding:18px!important;">
<div style="position:absolute; right:0; top:0; padding:8px;">
<a href="javascript:hide_revision_details();">X</a>
</div>
<b><br>Revision Details:</b> <br />
<div id="grid_popup_contents">
</div>
</div>
<?php
}
function last_id() {
global $db;
$last_id = $db->lastInsertId();
//$_SESSION['appstack'][count($_SESSION['appstack']) - 1]['id'] = $last_id;
echo '<script>';
echo 'appstack_switch_param("id", "'.$last_id.'");';
echo '</script>';
return $last_id;
}
function next_id($table_name) {
global $db;
$result = $db->query("SHOW TABLE STATUS LIKE '".$table_name."'");
$row = $row = $result->fetch(PDO::FETCH_ASSOC);
$next_id = $row['Auto_increment'];
return $next_id;
}
function db_quote($string)
{
global $db;
$result = $db->quote($string);
$result = substr($result, 1, strlen($result) - 2);
return $result;
}
function get_row_to_post($sql, $assign_unique_col_name = false) {
global $db;
global $result;
global $row;
$result = $db->query($sql) or die('Database Error!');
if ($result->rowCount() > 0) :
$row = $result->fetch(PDO::FETCH_NAMED);
foreach ($row as $key => $value) :
if ($assign_unique_col_name && is_array($value)) :
foreach ($value as $sub_key => $sub_value) :
$_POST[$key . '_' . $sub_key] = $sub_value;
endforeach;
else :
$_POST[$key] = $value;
endif;
endforeach;
post_set_load_create_update($assign_unique_col_name);
return true;
else :
return false;
endif;
}
function var_dump_pre($obj)
{
echo '<pre>';
var_dump($obj);
echo '</pre>';
}
function nz($arg, $null_value = '')
{
if (empty($arg)) :
return $null_value;
else :
$arg = trim($arg);
$arg = str_replace(',', '', $arg);
return intval($arg);
endif;
}
function nzfloat($arg, $null_value = '')
{
if (empty($arg)) :
return $null_value;
else :
$arg = trim($arg);
$arg = str_replace(',', '', $arg);
return floatval($arg);
endif;
}
function nzdate($arg, $null_value = 'NULL')
{
global $db;
if (empty($arg)) :
return $null_value;
else :
return $db->quote(date('Y-m-d', strtotime(str_replace('-', '/',trim($arg)))));
endif;
}
function nzdate_display($arg, $null_value = '')
{
if (empty($arg)) :
return $null_value;
else :
return date("m/d/Y", strtotime($arg));
endif;
}
function nzdatetime($arg, $null_value = 'NULL', $quotes = true)
{
global $db;
if (empty($arg)) :
return $null_value;
else :
if ($quotes):
return $db->quote(date('Y-m-d H:i:s', strtotime(str_replace('-', '/',trim($arg)))));
else :
return date('Y-m-d H:i:s', strtotime(str_replace('-', '/',trim($arg))));
endif;
endif;
}
function nzdate_display_datetime($arg, $null_value = '')
{
if (empty($arg)) :
return $null_value;
else :
return date("m/d/Y h:i:s a", strtotime($arg));
endif;
}
function nztime($arg, $null_value = 'NULL')
{
if (empty($arg)) :
return $null_value;
else :
return $db->quote(date('h:i A', strtotime(str_replace('-', '/',trim($arg)))));
endif;
}
function nztime_display($arg, $null_value = '')
{
if (empty($arg)) :
return $null_value;
else :
return date("g:i A", strtotime($arg));
endif;
}
function nz_string($arg, $null_value = '')
{
if (!isset($arg) || trim($arg) === '') :
return $null_value;
else :
return $arg;
endif;
}
function db_err_rollback($e, $die = true) {
global $db;
global $sql;
$db->rollBack();
error_log('Database error - Index: '.$_GET['IX'].' Error: '.$e->getMessage().PHP_EOL.$e->getTraceAsString() . PHP_EOL . $sql);
if ($die) :
die('Database error! Please contact the web site administrator.');
endif;
}
function save_db_revision(string $table_name, int|null $id_value = null, string $id_field = 'id'): void {
global $db;
if (is_null($id_value)) :
$id_value = $_REQUEST['id'];
endif;
$sql = "SELECT * FROM " . sql_safe_object($table_name) . " WHERE " . sql_safe_object($id_field) . " = :id_value";
$stmt = $db->prepare($sql);
$stmt->execute([
':id_value' => $id_value,
]);
$row = $stmt->fetch(PDO::FETCH_ASSOC);
if ($row) :
$revision_json = json_encode($row,);
$sql = "INSERT INTO revisions SET
table_name = :table_name,
id_field = :id_field,
id_value = :id_value,
revision_json = :revision_json
";
$stmt = $db->prepare($sql);
$stmt->execute([
':table_name' => $table_name,
':id_field' => $id_field,
':id_value' => $id_value,
':revision_json' => $revision_json,
]);
endif;
}
function form_success($extra_parms = null) {
global $form_message;
$form_message = "Saved sucessfully!";
form_uid_reset();
if ($_POST['xsubmit'] == 'Save & Close') :
echo "<SCRIPT>";
echo "appstack_pop()";
echo "</SCRIPT>";
endif;
$url_parms = '';
if (is_array($extra_parms)) :
foreach($extra_parms as $key => $value) :
$url_parms .= '&'.$key.'='.urlencode($value);
endforeach;
endif;
if ($_POST['xsubmit'] == 'Save & New') :
echo "<SCRIPT>";
echo "window.location.href = 'index.php?IX=".$_GET['IX'].$url_parms."&ref=".urlencode($_REQUEST['ref'])."'";
echo "</SCRIPT>";
endif;
}
function vert_text2($text,$size = 10,$color = array(253,128,46))
{
$dir = APP_ROOT_DIR."/tmp";
$filename = "$dir/" . base64_encode($text.'_'.$size.'_'.$color[0].'_'.$color[1].'_'.$color[2]);
//if(!file_exists($filename)):
$color_white = array(253,128,46);
$font = APP_ROOT_DIR."/fonts/arial.ttf";
$box = imagettfbbox($size,90,$font,$text);
$w = -$box[4] + $box[2];
$h = -$box[3];
$w_factor = $w - $box[6];
$h_factor = $h * 1;
$im = imagecreatetruecolor($w_factor,$h_factor);
$white = imagecolorallocate($im,$color_white[0],$color_white[1],$color_white[2]);
//$black = imagecolorallocate($im, 0x00, 0x00, 0x00);
$black = imagecolorallocate($im, $color[0],$color[1],$color[2]);
imagecolortransparent($im,$white);
imagefilledrectangle($im, 0, 0, $w_factor, $h_factor, $white);
imagettftext($im,$size,90,$w + $box[0],$h,$black,$font,$text);
@mkdir($dir);
imagepng($im,$filename);
imagedestroy($im);
//endif;
$data = base64_encode(file_get_contents($filename));
var_dump($box);
return "<img src='data:image/png;base64,$data'>";
}
function vert_text($text,$size = 10,$color = array(253,128,46))
{
$dir = APP_ROOT_DIR."/tmp";
$filename = "$dir/" . base64_encode($text.'_'.$size.'_'.$color[0].'_'.$color[1].'_'.$color[2]);
if(!file_exists($filename)):
//$color_white = array(253,128,46);
//$color_white = array(233,63,134);
$color_white = array(120,120,120);
$font = APP_ROOT_DIR."/fonts/arial.ttf";
$box = imagettfbbox($size,90,$font,$text);
$textwidth = abs($box[4] - $box[0]);
$textheight = abs($box[5] - $box[1]);
$imagewidth = ceil($textwidth * 1.3) + 1;
$imageheight = ceil($textheight * 1.0 + 5);
$xcord = ceil(($imagewidth/2)+($textwidth/2)-1);
$ycord = ceil(($imageheight/2)+($textheight/2));
$im = imagecreatetruecolor($imagewidth,$imageheight);
$white = imagecolorallocate($im,$color_white[0],$color_white[1],$color_white[2]);
//$black = imagecolorallocate($im, 0x00, 0x00, 0x00);
$black = imagecolorallocate($im, $color[0],$color[1],$color[2]);
imagecolortransparent($im,$white);
imagefilledrectangle($im, 0, 0, $imagewidth, $imageheight, $white);
imagettftext($im,$size,90,$xcord,$ycord,$black,$font,$text);
@mkdir($dir);
imagepng($im,$filename);
imagedestroy($im);
endif;
$data = base64_encode(file_get_contents($filename));
//echo 'w: '.$textwidth.' h: '.$textheight.' iw: '.$imagewidth.' ih: '.$imageheight.' xc: '.$xcord.' yc: '.$ycord;
//echo 'data: '.$data.' filename: '.$filename.' root dir '.APP_ROOT_DIR;
//var_dump($box);
return "<img src='data:image/png;base64,$data'>";
}
function show_form_error($err_text, $break = true) {
if (!empty($err_text)) :
if ($break) :
echo '<br />';
endif;
echo '<span class="form_error">'.$err_text.'</span>';
endif;
}
function format_http($link)
{
if (!empty($link)) :
//echo 'Point 1';
if (strtolower(substr($link, 0, 7)) != 'http://' && strtolower(substr($link, 0, 8)) != 'https://') :
$link = 'http://'.$link;
endif;
endif;
return $link;
}
function IsDate($date) {
return (strtotime($date) !== false);
}
function nl_remove($string)
{
$search = array("\r\n", "\n");
$new_string = str_replace($search, ' ', $string);
$new_string = str_replace(' ', ' ', $new_string);
return $new_string;
}
function write_log($log_type, $user_id, $log_text)
{
global $db;
$sql = "INSERT INTO log set ".
"user_id = ".nz(trim($user_id), '0').", ".
"log_type = ".$db->quote(trim($log_type)).", ".
"log_text = ".$db->quote(trim($log_text)).", ".
"ip = '".$_SERVER['REMOTE_ADDR']."' ";
$db->query($sql) or die('Database error - Log failure! Please contact the web site administrator.');
}
function get_page_title($ix)
{
global $ar_pagecontrol;
$title = $ar_pagecontrol[$ix]['page_title'];
return $title;
}
function get_roles()
{
$return_result = '';
if (($_SESSION['logged_in'] ?? NULL) == 1) :
$db = $GLOBALS['db'];
$sql = "SELECT roles FROM sys_users WHERE user_id = ".nz($_SESSION['user_id'], '0')." AND active = 1 ";
$result = $db->query($sql) or die('Database Error!');
if ($result->rowCount() > 0) :
$row = $result->fetch(PDO::FETCH_OBJ);
$return_result = $row->roles;
endif;
endif;
return $return_result;
}
function has_role($role)
{
$return_result = false;
if (($_SESSION['logged_in'] ?? NULL) == 1) :
$ar1 = explode(',',get_roles());
foreach ($ar1 as $ar1_value) :
if (strtoupper($role) == strtoupper($ar1_value)) :
$return_result = true;
endif;
endforeach;
endif;
return $return_result;
}
function page_allowed($ix)
{
global $ar_pagecontrol;
$return_result = false;
if (!empty($ar_pagecontrol[$ix])) :
$bln_show_menu = false;
if (($_SESSION['logged_in'] ?? NULL) == true && $ar_pagecontrol[$ix]['show_state'] == 1) :
$bln_show_menu = true;
endif;
if (($_SESSION['logged_in'] ?? NULL) != true && $ar_pagecontrol[$ix]['show_state'] == 2) :
$bln_show_menu = true;
endif;
if ($ar_pagecontrol[$ix]['show_state'] == 0) :
$bln_show_menu = true;
endif;
if ($bln_show_menu) :
if (empty($ar_pagecontrol[$ix]['view_roles']) || role_match($ar_pagecontrol[$ix]['view_roles'], get_roles())) :
$return_result = true;
endif;
endif;
endif;
return $return_result;
}
function page_secure($ix)
{
global $ar_pagecontrol;
$return_result = false;
if (!empty($ar_pagecontrol[$ix]))
{
if ($ar_pagecontrol[$ix]['secure'] == 1)
{
$return_result = true;
}
}
return $return_result;
}
function curr_page_url()
{
if (!isset($_SERVER['REQUEST_URI'])) {
$_SERVER['REQUEST_URI'] = substr($_SERVER['PHP_SELF'],0 );
if (isset($_SERVER['QUERY_STRING'])) {
$_SERVER['REQUEST_URI'].='?'.$_SERVER['QUERY_STRING'];
}
}
$page_url = 'http';
if (nz_string(($_SERVER["HTTPS"] ?? NULL), 'off') == "on" || nz_string(($_SERVER['HTTP_X_FORWARDED_PROTO'] ?? NULL), 'http') == 'https') {
$page_url .= "s";
}
$page_url .= "://";
/*
if ($_SERVER["SERVER_PORT"] != "80")
{
$page_url .= $_SERVER["SERVER_NAME"].":".$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"];
}
else
{
$page_url .= $_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"];
}
*/
$page_url .= $_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"];
return $page_url;
}
function curr_page_file()
{
$page_url = '';
$currentFile = $_SERVER["PHP_SELF"];
$parts = Explode('/', $currentFile);
$page_url = $parts[count($parts) - 1];
return $page_url;
}
function alternate_page_header($ix) {
global $ar_pagecontrol;
$return_result = false;
if (!empty($ar_pagecontrol[$ix])) :
if (!empty($ar_pagecontrol[$ix]['header'])) :
$return_result = $ar_pagecontrol[$ix]['header'];
endif;
endif;
return $return_result;
}
function alternate_page_footer($ix) {
global $ar_pagecontrol;
$return_result = false;
if (!empty($ar_pagecontrol[$ix])) :
if (!empty($ar_pagecontrol[$ix]['footer'])) :
$return_result = $ar_pagecontrol[$ix]['footer'];
endif;
endif;
return $return_result;
}
function stylesheet_overrides($ix): array {
global $ar_pagecontrol;
$result = [];
if (!empty($ar_pagecontrol[$ix])) :
if (!empty($ar_pagecontrol[$ix]['stylesheets']) && is_array($ar_pagecontrol[$ix]['stylesheets'])) :
$result = $ar_pagecontrol[$ix]['stylesheets'];
endif;
endif;
return $result;
}
function is_date( $str )
{
$stamp = strtotime( $str );
$month = date( 'm', $stamp );
$day = date( 'd', $stamp );
$year = date( 'Y', $stamp );
//echo 'is_date '.$stamp.' month '.$month.' day '.$day.' year '.$year;
if ($year > 1969)
return checkdate( $month, $day, $year );
else
return false;
}
function check_to_bool( $str )
{
if ($str == 'on' || $str == 'checked')
$result = '1';
else
$result = '0';
return $result;
}
function bool_to_check( $bool )
{
if ($bool == 1)
$result = 'checked';
else
$result = '';
return $result;
}
function bool_to_yesno( $bool )
{
if ($bool == 1)
$result = 'Yes';
else
$result = 'No';
return $result;
}
function yesno_to_bool( $str )
{
$str = strtoupper($str);
if ($str == 'ON' || $str == 'CHECKED' || $str == 'YES' || $str == 'Y')
$result = '1';
else
$result = '0';
return $result;
}
function role_match($str1 = null, $str2 = null)
{
$result = false;
if (empty($str1) || empty($str2))
return $result;
$ar1 = explode(',',$str1);
$ar2 = explode(',',$str2);
foreach ($ar1 as $ar1_value)
{
if (is_numeric(array_search($ar1_value,$ar2)))
$result = true;
}
return $result;
}
function get_event_field($event_id, $field_name)
{
global $db;
$sql = "SELECT * FROM events WHERE event_id = ".nz(trim($event_id),'0');
//echo '==='.$sql.'===';
$result = $db->query($sql);
if ($result->rowCount() > 0) :
$row = $result->fetch(PDO::FETCH_ASSOC);
return $row[$field_name];
else :
return 'Not Found!';
return '';
endif;
}
function uploadImage($subFolderName, $fileName, $maxSize, $maxW, $fullPath, $relPath, $colorR, $colorG, $colorB, $maxH = null){
$folder = $relPath;
$maxlimit = $maxSize;
$allowed_ext = "jpg,jpeg,gif,png,bmp";
$match = "";
$filesize = $_FILES[$fileName]['size'];
if($filesize > 0){
$filename = strtolower($_FILES[$fileName]['name']);
$filename = preg_replace('/\s/', '_', $filename);
if($filesize < 1){
$errorList[] = "File size is empty.";
}
if($filesize > $maxlimit){
$errorList[] = "File size is too big.";
}
if(count($errorList)<1){
$file_ext = preg_split("/\./",$filename);
$allowed_ext = preg_split("/\,/",$allowed_ext);
foreach($allowed_ext as $ext){
if($ext==end($file_ext)){
$match = "1"; // File is allowed
$NUM = time();
$front_name = substr($file_ext[0], 0, 15);
$newfilename = $front_name."_".$NUM.".".end($file_ext);
$filetype = end($file_ext);
$directory = $folder.$subFolderName;
if (!file_exists($directory))
{
mkdir($directory);
}
$save = $directory.'/'.$newfilename;
if(!file_exists($save)){
list($width_orig, $height_orig) = getimagesize($_FILES[$fileName]['tmp_name']);
if($maxH == null){
if($width_orig < $maxW){
$fwidth = $width_orig;
}else{
$fwidth = $maxW;
}
$ratio_orig = $width_orig/$height_orig;
$fheight = $fwidth/$ratio_orig;
$blank_height = $fheight;
$top_offset = 0;
}else{
if($width_orig <= $maxW && $height_orig <= $maxH){
$fheight = $height_orig;
$fwidth = $width_orig;
}else{
if($width_orig > $maxW){
$ratio = ($width_orig / $maxW);
$fwidth = $maxW;
$fheight = ($height_orig / $ratio);
if($fheight > $maxH){
$ratio = ($fheight / $maxH);
$fheight = $maxH;
$fwidth = ($fwidth / $ratio);
}
}
if($height_orig > $maxH){
$ratio = ($height_orig / $maxH);
$fheight = $maxH;
$fwidth = ($width_orig / $ratio);
if($fwidth > $maxW){
$ratio = ($fwidth / $maxW);
$fwidth = $maxW;
$fheight = ($fheight / $ratio);
}
}
}
if($fheight == 0 || $fwidth == 0 || $height_orig == 0 || $width_orig == 0){
die("FATAL ERROR REPORT ERROR CODE [add-pic-line-67-orig] to <a href='http://www.atwebresults.com'>AT WEB RESULTS</a>");
}
if($fheight < 45){
$blank_height = 45;
$top_offset = round(($blank_height - $fheight)/2);
}else{
$blank_height = $fheight;
}
}
switch($filetype){
case "gif":
$image = @imagecreatefromgif($_FILES[$fileName]['tmp_name']);
break;
case "jpg":
$image = @imagecreatefromjpeg($_FILES[$fileName]['tmp_name']);
break;
case "jpeg":
$image = @imagecreatefromjpeg($_FILES[$fileName]['tmp_name']);
break;
case "png":
$image = @imagecreatefrompng($_FILES[$fileName]['tmp_name']);
break;
}
//Auto rotate based on EXIF data
$exif = exif_read_data($_FILES[$fileName]['tmp_name']);
//var_dump($exif);
if(!empty($exif['Orientation'])) {
switch($exif['Orientation']) {
case 8:
$temp_dimension = $fwidth;
$fwidth = $blank_height;
$blank_height = $temp_dimension;
$fheight = $temp_dimension;
$temp_dimension = $width_orig;
$width_orig = $height_orig;
$height_orig = $temp_dimension;
$image = imagerotate($image,90,0);
break;
case 3:
$image = imagerotate($image,180,0);
break;
case 6:
$temp_dimension = $fwidth;
$fwidth = $blank_height;
$blank_height = $temp_dimension;
$fheight = $temp_dimension;
$temp_dimension = $width_orig;
$width_orig = $height_orig;
$height_orig = $temp_dimension;
$image = imagerotate($image,-90,0);
break;
}
}
//echo 'w '.$fwidth.' h '.$blank_height.' ow '.$width_orig.' oh '.$height_orig;
//*******************************
$image_p = imagecreatetruecolor($fwidth, $blank_height);
$white = imagecolorallocate($image_p, $colorR, $colorG, $colorB);
imagefill($image_p, 0, 0, $white);
@imagecopyresampled($image_p, $image, 0, $top_offset, 0, 0, $fwidth, $fheight, $width_orig, $height_orig);
switch($filetype){
case "gif":
if(!@imagegif($image_p, $save)){
$errorList[]= "PERMISSION DENIED [GIF] ".$save;
}
break;
case "jpg":
if(!@imagejpeg($image_p, $save, 100)){
$errorList[]= "PERMISSION DENIED [JPG] ".$save;
}
break;
case "jpeg":
if(!@imagejpeg($image_p, $save, 100)){
$errorList[]= "PERMISSION DENIED [JPEG] ".$save;
}
break;
case "png":
if(!@imagepng($image_p, $save, 0)){
$errorList[]= "PERMISSION DENIED [PNG] ".$save;
}
break;
}
@imagedestroy($filename);
}else{
$errorList[]= "CANNOT MAKE IMAGE IT ALREADY EXISTS";
}
}
}
}
}else{
$errorList[]= "NO FILE SELECTED";
}
if(!$match){
$errorList[]= "File type isn't allowed: $filename";
}
if(sizeof($errorList) == 0){
//return $fullPath.$subFolderName.'/'.$newfilename;
return $relPath.$subFolderName.'/'.$newfilename;
}else{
$eMessage = array();
for ($x=0; $x<sizeof($errorList); $x++){
$eMessage[] = $errorList[$x];
}
return $eMessage;
}
}
function sys_compress($data) {
return zlib_encode($data, ZLIB_ENCODING_RAW);
}
function sys_uncompress($data) {
return zlib_decode($data);
}
function sys_encrypt($string, $key) {
return @openssl_encrypt($string, 'AES-128-CFB', $key, OPENSSL_RAW_DATA | OPENSSL_ZERO_PADDING);
}
function sys_decrypt($string, $key) {
return @openssl_decrypt($string, 'AES-128-CFB', $key, OPENSSL_RAW_DATA | OPENSSL_ZERO_PADDING);
}
function sys_encrypt_string($string, $key = APP_CRYPTO_PWD) {
$iv_len = openssl_cipher_iv_length(APP_CRYPTO_ALGORITHM);
$iv = openssl_random_pseudo_bytes($iv_len);
$encrypted = bin2hex($iv) . openssl_encrypt($string, APP_CRYPTO_ALGORITHM, $key, 0, $iv);
return $encrypted;
}
function sys_decrypt_string($string, $key = APP_CRYPTO_PWD) {
$iv_len_hex = openssl_cipher_iv_length(APP_CRYPTO_ALGORITHM) * 2;
$iv = hex2bin(substr($string, 0, $iv_len_hex));
$encrypted = substr($string, $iv_len_hex);
$decrypted = openssl_decrypt($encrypted, APP_CRYPTO_ALGORITHM, $key, 0, $iv);
return $decrypted;
}
function xls_sql_encrypt($xls_sql) {
return urlencode(sys_encrypt(sys_compress($xls_sql), $_SESSION['rand_key']));
}
function xls_sql_decrypt($xls_sql) {
return sys_uncompress(sys_decrypt(urldecode($xls_sql), $_SESSION['rand_key']));
}
function sql_to_xls($sql, $file_name = 'php://output', $file_format = APP_EXCEL_FORMAT) {
//***************** generate file using PHPExcel *****************
global $db;
//require_once dirname(__FILE__) . '/../vendor_classes/PHPExcel.php';
$objPHPExcel = new \PhpOffice\PhpSpreadsheet\Spreadsheet();
$objPHPExcel->getProperties()->setCreator(APP_COMPANY)
->setLastModifiedBy(APP_COMPANY)
->setTitle(APP_COMPANY)
->setSubject(APP_TITLE)
->setDescription(APP_TITLE)
->setKeywords(APP_TITLE)
->setCategory(APP_TITLE);
$sheet = $objPHPExcel->getActiveSheet();
$sheet0 = $objPHPExcel->setActiveSheetIndex(0);
//$sql = gzuncompress(sys_decrypt($_GET['sql'], $_SESSION['rand_key']));
$result = $db->query($sql) or die('Database Error!');
if ($result->rowCount() > 0) :
$first_row = true;
$curr_row = 1; /* 3 for setups with 2 lines of headers */
$tot_cols = 1;
$ar_field_types = [];
$ar_field_names = [];
$i = 0;
//$table_fields = $result->fetchAll(PDO::FETCH_COLUMN);
while ($i < $result->columnCount()) :
$meta = $result->getColumnMeta($i);
if (!$meta) :
$ar_field_types[$i] = 'string';
$ar_field_names[$i] = 'N/A';
else :
/*
echo PDO::PARAM_INT;
echo PDO::PARAM_BOOL;
var_dump($meta);
echo '<br />';
*/
$ar_field_types[$i] = strtolower($meta['native_type']);
$ar_field_names[$i] = $meta['name'];
endif;
$i++;
endwhile;
//error_log(print_r($ar_field_types, true));
while ($row = $result->fetch(PDO::FETCH_NUM)) :
if ($first_row) :
$curr_col = 1;
//foreach($row as $key => $row_field) :
foreach($ar_field_names as $key) :
$sheet0->setCellValue([$curr_col, $curr_row], $key);
$sheet->getStyle([$curr_col, $curr_row])->applyFromArray([
'fill' => [
'fillType' => \PhpOffice\PhpSpreadsheet\Style\Fill::FILL_SOLID,
'startColor' => ['argb' => '3E4B62'],
],
'borders' => [
'allBorders' => [
'borderStyle' => \PhpOffice\PhpSpreadsheet\Style\Border::BORDER_MEDIUM,
'color' =>['argb' => \PhpOffice\PhpSpreadsheet\Style\Color::COLOR_WHITE]
]
],
'font' => [
'color' => ['argb' => \PhpOffice\PhpSpreadsheet\Style\Color::COLOR_WHITE],
],
'alignment' =>['horizontal' => \PhpOffice\PhpSpreadsheet\Style\Alignment::HORIZONTAL_CENTER],
]);
$sheet->getColumnDimension('B')->setAutoSize(true);
$curr_col = $curr_col + 1;
endforeach;
$tot_cols = $curr_col;
$curr_row = $curr_row + 1;
$first_row = false;
endif;
$max_col = \PhpOffice\PhpSpreadsheet\Cell\Coordinate::stringFromColumnIndex($tot_cols - 1);
$curr_col = 1;
foreach($row as $row_field) :
$row_field = utf8_encode($row_field);
//echo $curr_col.' === '.$ar_field_types[$curr_col].' === <br />';
//if ($ar_field_types[$curr_col] == 'long' || $ar_field_types[$curr_col] == 'longlong' || $ar_field_types[$curr_col] == 'newdecimal' || $ar_field_types[$curr_col] == 'float' || $ar_field_types[$curr_col] == 'tiny') :
if (in_array($ar_field_types[$curr_col], ['long', 'longlong', 'newdecimal', 'float', 'tiny']) && is_numeric($row_field)) :
$sheet0->setCellValueExplicit([$curr_col, $curr_row], html_entity_decode($row_field, ENT_QUOTES), \PhpOffice\PhpSpreadsheet\Cell\DataType::TYPE_NUMERIC);
/*
elseif ($ar_field_types[$curr_col] == 'float') :
$sheet0->setCellValueExplicitByColumnAndRow($curr_col, $curr_row, html_entity_decode($row_field, ENT_QUOTES), PHPExcel_Cell_DataType::TYPE_NUMERIC);
*/
else :
$sheet0->setCellValueExplicit([$curr_col, $curr_row], html_entity_decode($row_field, ENT_QUOTES), \PhpOffice\PhpSpreadsheet\Cell\DataType::TYPE_STRING);
if (strtolower(substr($row_field,0,7)) == 'http://' || strtolower(substr($row_field,0,8)) == 'https://') :
//$url = str_replace('http://', '', $link);
//$sheet0->getCellByColumnAndRow($curr_col, $curr_row)->getHyperlink()->setUrl('http://www.'.$url);
$parts = parse_url($row_field);
parse_str($parts['query'], $query);
//echo $query['email'];
$query['mslink'] = 'true';
$url = $parts['scheme'].'://'.$parts['host'].$parts['path'].'?'.http_build_query($query);
$sheet0->getCell([$curr_col, $curr_row])->getHyperlink()->setUrl($url);
$sheet->getStyle([$curr_col, $curr_row])->applyFromArray(
array ( 'font' => array('color' => array('argb' => \PhpOffice\PhpSpreadsheet\Style\Color::COLOR_BLUE)),
)
);
endif;
endif;
$curr_col = $curr_col + 1;
endforeach;
$curr_row = $curr_row + 1;
endwhile;
//die();
$max_row = $curr_row - 1;
if ($max_row > 3) :
$i = 0;
while ($i < $result->columnCount()) :
if ($ar_field_types[$i] == 'long' || $ar_field_types[$i] == 'longlong' || $ar_field_types[$i] == 'tiny') :
$sheet->getStyle(\PhpOffice\PhpSpreadsheet\Cell\Coordinate::stringFromColumnIndex($i + 1).'2:'.\PhpOffice\PhpSpreadsheet\Cell\Coordinate::stringFromColumnIndex($i + 1).$max_row)->applyFromArray(
array ('alignment' => array('horizontal' => \PhpOffice\PhpSpreadsheet\Style\Alignment::HORIZONTAL_RIGHT) )
);
elseif ($ar_field_types[$i] == 'newdecimal' || $ar_field_types[$i] == 'float') :
$sheet->getStyle(\PhpOffice\PhpSpreadsheet\Cell\Coordinate::stringFromColumnIndex($i + 1).'2:'.\PhpOffice\PhpSpreadsheet\Cell\Coordinate::stringFromColumnIndex($i + 1).$max_row)->applyFromArray(
array ('alignment' => array('horizontal' => \PhpOffice\PhpSpreadsheet\Style\Alignment::HORIZONTAL_RIGHT) )
);
$sheet->getStyle(\PhpOffice\PhpSpreadsheet\Cell\Coordinate::stringFromColumnIndex($i + 1).'2:'.\PhpOffice\PhpSpreadsheet\Cell\Coordinate::stringFromColumnIndex($i + 1).$max_row)->getNumberFormat()->setFormatCode(\PhpOffice\PhpSpreadsheet\Style\NumberFormat::FORMAT_NUMBER_COMMA_SEPARATED1);
else :
$sheet->getStyle(\PhpOffice\PhpSpreadsheet\Cell\Coordinate::stringFromColumnIndex($i + 1).'2:'.\PhpOffice\PhpSpreadsheet\Cell\Coordinate::stringFromColumnIndex($i + 1).$max_row)->applyFromArray(
array ('alignment' => array('horizontal' => \PhpOffice\PhpSpreadsheet\Style\Alignment::HORIZONTAL_LEFT) )
);
endif;
$i++;
endwhile;
$sheet->getStyle('A2:'.$max_col.$max_row)->applyFromArray([
'fill' => [
'fillType' => \PhpOffice\PhpSpreadsheet\Style\Fill::FILL_SOLID,
'color' => ['argb' => 'ECEDEF'],
],
'borders' => [
'allBorders' => [
'borderStyle' => \PhpOffice\PhpSpreadsheet\Style\Border::BORDER_MEDIUM,
'color' => ['argb' => \PhpOffice\PhpSpreadsheet\Style\Color::COLOR_WHITE],
]
]
]);
endif;
foreach (range(0, $tot_cols - 1) as $col) :
$sheet->getColumnDimensionByColumn($col)->setAutoSize(true);
endforeach;
else :
$sheet0->setCellValue([1, 1], 'No records found.');
endif;
// Rename worksheet
$sheet->setTitle('exportfile');
// Set active sheet index to the first sheet, so Excel opens this as the first sheet
$sheet0;
/*
*/
if ($file_name == 'php://output') :
if ($file_format == 'xls') :
// Redirect output to a client’s web browser (Excel5)
header('Content-Type: application/vnd.ms-excel');
header('Content-Disposition: attachment;filename="exportfile.xls"');
elseif ($file_format == 'xlsx') :
header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
header('Content-Disposition: attachment;filename="exportfile.xlsx"');
endif;
header('Cache-Control: max-age=0');
// If you're serving to IE 9, then the following may be needed
header('Cache-Control: max-age=1');
// If you're serving to IE over SSL, then the following may be needed
header ('Expires: Mon, 26 Jul 1997 05:00:00 GMT'); // Date in the past
header ('Last-Modified: '.gmdate('D, d M Y H:i:s').' GMT'); // always modified
header ('Cache-Control: cache, must-revalidate'); // HTTP/1.1
header ('Pragma: public'); // HTTP/1.0
endif;
//PHPExcel_Calculation::getInstance($objPHPExcel)->clearCalculationCache();
if ($file_format == 'xls') :
$objWriter = \PhpOffice\PhpSpreadsheet\IOFactory::createWriter($objPHPExcel, 'Xls');
//$objWriter->setOffice2003Compatibility(true);
elseif ($file_format == 'xlsx') :
$objWriter = \PhpOffice\PhpSpreadsheet\IOFactory::createWriter($objPHPExcel, 'Xlsx');
endif;
//$objWriter->save('php://output');
$objWriter->save($file_name);
return $result->rowCount();
}
function db_navigator_bar($ar_args)
{
global $ar_pagecontrol;
$defaults = array(
'subtab' => 'false',
'parm1' => '',
'parm2' => '',
'parm3' => '',
'filter_cols' => '',
'btn_addnew' => 'true',
'btn_print' => 'true',
'btn_excel' => 'true',
'btn_pdf' => 'true',
'record_count' => 'true',
'extra_buttons' => [],
'multi_filter' => [],
'callback' => 'null',
'lazy_callback' => 'null',
);
$ar_args = array_merge($defaults, $ar_args);
//var_dump($ar_args);
$ar_args['parm1'] = xls_sql_encrypt($ar_args['parm1']);
$ar_args['parm2'] = xls_sql_encrypt($ar_args['parm2']);
$ar_args['parm3'] = xls_sql_encrypt($ar_args['parm3']);
$table_id = $ar_args["table_id"];
$call = $ar_args["call"];
$func = $ar_args["func"];
$ix_form = $ar_args["form"];
$print_section = $ar_args["print_section"];
if (empty($_GET['scol_'.$table_id])) :
$sort_col = $ar_args["sort_col"];
else :
$sort_col = nz($_GET['scol_'.$table_id], '0');
endif;
if (!isset($_GET['sorder_'.$table_id]) || ($_GET['sorder_'.$table_id] !== '0' && $_GET['sorder_'.$table_id] !== '1')) :
$sort_order = $ar_args["sort_order"];
else :
$sort_order = nz($_GET['sorder_'.$table_id], '0');
endif;
if (empty($_GET['fcols_'.$table_id])) :
$filter_cols = $ar_args["filter_cols"];
else :
$filter_cols = trim($_GET['fcols_'.$table_id]);
endif;
if (empty($_GET['multi_filter_'.$table_id])) :
$multi_filter = $ar_args["multi_filter"];
else :
$multi_filter = trim($_GET['multi_filter_'.$table_id]);
endif;
$parm1 = $ar_args["parm1"];
$parm2 = $ar_args["parm2"];
$parm3 = $ar_args["parm3"];
$subtab = $ar_args["subtab"];
$callback = $ar_args["callback"];
$lazy_callback = $ar_args["lazy_callback"];
?>
<div class="db_nav">
<?php if ($ar_args['btn_addnew'] == 'true' && (empty($ar_pagecontrol[$call]['update_roles']) || role_match($ar_pagecontrol[$call]['update_roles'], get_roles()))) : ?>
<input type="button" class="mini" value="Add New" onclick="window.location.href = 'index.php?IX=<?php echo $ix_form; ?>';" />
<?php endif; ?>
<div class="search_box" id="<?php echo $table_id; ?>_search_box">
<input type="text" name="<?php echo $table_id; ?>_strSearch" id="<?php echo $table_id; ?>_strSearch" class="input-box-var search" size=30 maxlength="30" value="<?php echo trim($_GET['search_'.$table_id] ?? NULL); ?>" >
<a href="javascript:clear_search_box('<?php echo $table_id; ?>_strSearch');"></a>
</div>
<?php if ($ar_args['btn_excel'] == 'true') : ?>
<input type="button" class="mini" value="Excel ®" onclick="exportExcel(<?php echo $table_id; ?>_xls_sql);" />
<?php endif; ?>
<?php if ($ar_args['btn_print'] == 'true') : ?>
<input type="button" class="mini" value="Print" onclick="printSection('<?php echo $print_section; ?>');" />
<?php endif; ?>
<?php if ($ar_args['btn_pdf'] == 'true') : ?>
<input type="button" class="mini" value="PDF" onclick="pdfSection('<?php echo $print_section; ?>');" />
<?php endif; ?>
<?php
foreach ($ar_args['extra_buttons'] as $btn) :
echo '<input id="'.$btn['id'].'" type="button" class="mini" style="'.$btn['style'].'" value="'.$btn['title'].'" onclick="'.$btn['action'].'" />';
endforeach;
?>
 
<?php if ($ar_args['record_count'] == 'true') : ?>
Records: <div style="width:50px; text-align:right; display:inline-block;" id="<?php echo $table_id; ?>_total_count"></div>
<?php endif; ?>
<div style="width:auto; margin-left:15px; text-align:left; display:inline-block;" id="<?php echo $table_id; ?>_extra_data"></div>
<div style="width:auto; margin-left:15px; text-align:left; display:inline-block;" id="<?php echo $table_id; ?>_diag"></div>
</div>
<div class="db-grid" id="<?php echo $table_id; ?>">
</div>
<script>
print_header = '<div id="header"><h1>Davler Media - <?=APP_TITLE?></h1></div>';
print_footer = '<div id="footer"><p class="page">Page </p></div>';
var <?php echo $table_id; ?>_xls_sql;
var <?php echo $table_id; ?>_timeout;
var <?php echo $table_id; ?>_subtab = <?php echo $subtab; ?>;
ar_lcs_db_loaded['<?php echo $table_id; ?>'] = false;
ar_lcs_db_load['<?php echo $table_id; ?>'] = function()
{
lcs_db_load('<?php echo $table_id; ?>', '<?php echo $call; ?>', '<?php echo $func; ?>', '<?php echo $ix_form; ?>', '<?php echo $sort_col; ?>',
'<?php echo $sort_order; ?>', '<?php echo trim($_GET['search_'.$table_id] ?? NULL); ?>', "<?php echo $parm1; ?>", "<?php echo $parm2; ?>", "<?php echo $parm3; ?>", '<?php echo $filter_cols; ?>', <?php echo json_encode($multi_filter) ?>, <?php echo $callback; ?>, <?php echo $lazy_callback; ?> );
ar_lcs_db_loaded['<?php echo $table_id; ?>'] = true;
$('#<?php echo $table_id; ?>_strSearch').on( 'keyup', function () {
clearTimeout(<?php echo $table_id; ?>_timeout);
<?php echo $table_id; ?>_timeout = setTimeout(function()
{
lcs_db_load('<?php echo $table_id; ?>','<?php echo $call; ?>', '<?php echo $func; ?>', '<?php echo $ix_form; ?>',
<?php echo $table_id; ?>_sort_col, <?php echo $table_id; ?>_sort_order, $('#<?php echo $table_id; ?>_strSearch').val(),
"<?php echo $parm1; ?>", "<?php echo $parm2; ?>", "<?php echo $parm3; ?>", <?php echo $table_id; ?>_filter_cols, <?php echo $table_id; ?>_multi_filter, <?php echo $table_id; ?>_callback, <?php echo $table_id; ?>_lazy_callback);
}
,500);
if (this.value > ' ')
{
$('#<?php echo $table_id; ?>_strSearch').removeClass('search');
$('#<?php echo $table_id; ?>_strSearch').addClass('search_cancel');
$('#<?php echo $table_id; ?>_search_box a').show();
}
else
{
$('#<?php echo $table_id; ?>_strSearch').removeClass('search_cancel');
$('#<?php echo $table_id; ?>_strSearch').addClass('search');
$('#<?php echo $table_id; ?>_search_box a').hide();
}
} );
}
$(document).ready(function()
{
if (!<?php echo $table_id; ?>_subtab)
{
ar_lcs_db_load['<?php echo $table_id; ?>']();
}
if ($('#<?php echo $table_id; ?>_strSearch').val() > ' ')
{
$('#<?php echo $table_id; ?>_strSearch').removeClass('search');
$('#<?php echo $table_id; ?>_strSearch').addClass('search_cancel');
$('#<?php echo $table_id; ?>_search_box a').show();
}
});
</script>
<?php
}
function db_navigator_bar_old($ar_args)
{
$table_id = $ar_args["table_id"];
$ix_form = $ar_args["form"];
$xls_sql = $ar_args["xls_sql"];
$print_section = $ar_args["print_section"];
?>
<table align="center" cellpadding="2" cellspacing="5" border="0" >
<tr>
<td align="center" >
<input type="button" class="mini" value="Add New" onclick="window.location.href = 'index.php?IX=<?php echo $ix_form; ?>';" />
</td>
<td colspan="1" align="right" class="data-label">
Find:
</td>
<td colspan="2">
<div class="search_box" id="<?php echo $table_id; ?>_search_box">
<input type="text" name="<?php echo $table_id; ?>_strSearch" id="<?php echo $table_id; ?>_strSearch" class="input-box-var search" size=30 maxlength="30" >
<a href="javascript:clear_search_box('<?php echo $table_id; ?>_strSearch');"></a>
</div>
</td>
<td align="center" >
<input type="button" class="mini" value="Excel ®" onclick="exportExcel('<?php echo urlencode(sys_encrypt(sys_compress($xls_sql), $_SESSION['rand_key'])); ?>');" />
</td>
<td align="center" >
<input type="button" class="mini" value="Print" onclick="printSection('<?php echo $print_section; ?>');" />
</td>
<td align="center" >
<input type="button" class="mini" value="PDF" onclick="pdfSection('<?php echo $print_section; ?>');" />
</td>
<td align="right" >
   
Records: <div style="width:60px; text-align:right; float:right;" id="<?php echo $table_id; ?>_total_count"></div>
</td>
</tr>
</table>
<?php
}
function sql_set_update($add_comma = false)
{
$str = "update_by = ".nz(trim($_SESSION['user_id']), 0).", ".
"update_date = '".date('Y-m-d H:i:s')."', ";
if ($add_comma) :
$str .= ', ';
endif;
return $str;
}
function sql_set_create()
{
$str = "create_by = ".nz(trim($_SESSION['user_id']), 0).", ".
"create_date = '".date('Y-m-d H:i:s')."', ";
return $str;
}
function post_set_update() {
$_POST['update_by'] = trim($_SESSION['user_id']);
$_POST['update_date'] = date('m/d/Y h:i:s a');
}
function post_set_create_update() {
$_POST['create_by'] = trim($_SESSION['user_id']);
$_POST['create_date'] = date('m/d/Y h:i:s a');
$_POST['update_by'] = trim($_SESSION['user_id']);
$_POST['update_date'] = date('m/d/Y h:i:s a');
}
function post_set_load_create_update($assign_unique_col_name = false) {
global $row;
$_POST['create_by'] = is_array($row['create_by']) ? $row['create_by'][0] : $row['create_by'];
$_POST['create_date'] = is_array($row['create_date']) ? nzdate_display_datetime($row['create_date'][0]) : nzdate_display_datetime($row['create_date']);
$_POST['update_by'] = is_array($row['update_by']) ? $row['update_by'][0] : $row['update_by'];
$_POST['update_date'] = is_array($row['update_date']) ? nzdate_display_datetime($row['update_date'][0]) : nzdate_display_datetime($row['update_date']);
}
function get_user($user_id) {
global $db;
$return_result = '';
$sql = "SELECT user_name FROM sys_users WHERE user_id = ".nz($user_id, '0');
$result = $db->query($sql) or die('Database Error!');
if ($result->rowCount() > 0) :
$row = $result->fetch(PDO::FETCH_OBJ);
$return_result = $row->user_name;
endif;
return $return_result;
}
function show_create_update()
{
?>
<div class="create_update">
<table cellpadding="2">
<tr>
<td>
Created:
</td>
<td>
<input name="create_by" id="create_by" type="hidden" readonly="readonly" value="<?php echo $_POST['create_by'] ?? NULL; ?>" />
<input name="create_by_display" id="create_by_display" type="text" readonly="readonly" class="create_update" style="width:100px;" value="<?php echo get_user($_POST['create_by'] ?? NULL); ?>" />
</td>
<td>
<input name="create_date" id="create_date" type="text" readonly="readonly" class="create_update" value="<?php echo $_POST['create_date'] ?? NULL; ?>" />
</td>
</tr>
<tr>
<td>
Updated:
</td>
<td>
<input name="update_by" id="update_by" type="hidden" readonly="readonly" value="<?php echo $_POST['update_by'] ?? NULL; ?>" />
<input name="update_by_display" id="update_by_display" type="text" readonly="readonly" class="create_update" style="width:100px;" value="<?php echo get_user($_POST['update_by'] ?? NULL); ?>" />
</td>
<td>
<input name="update_date" id="update_date" type="text" readonly="readonly" class="create_update" value="<?php echo $_POST['update_date'] ?? NULL; ?>" />
</td>
</tr>
</table>
</div>
<?php
}
function report_output_format($form_id = NULL) {
$form_attr = '';
if (!empty($form_id)) :
$form_attr = ' form="'.$form_id.'" ';
endif;
echo '<div class="input_column">';
$ar_output_formats = ['html'=>'Browser', 'pdf'=>'PDF', 'doc'=>'MS-Word<sup>®</sup>', 'xls'=>'MS-Excel<sup>®</sup>', 'csv'=>'CSV'];
$_POST['output_format['.$form_id.']'] = 'html';
form_field(['fname'=>'output_format['.$form_id.']', 'ftype'=>'radiogroup', 'fsize'=>10, 'frequired'=>false, 'fclass'=>'no_dirty', 'fdbname'=>'', 'ar_group'=>$ar_output_formats, 'flabel'=>'Output Format', 'form_id'=>$form_id]);
$ar_orientations = ['P'=>'Portrait', 'L'=>'Landscape'];
$_POST['orientation['.$form_id.']'] = 'P';
form_field(['fname'=>'orientation['.$form_id.']', 'ftype'=>'radiogroup', 'fsize'=>10, 'frequired'=>false, 'fclass'=>'no_dirty', 'fdbname'=>'', 'ar_group'=>$ar_orientations, 'flabel'=>'Orientation', 'form_id'=>$form_id]);
echo '<br><br><input type="submit" value="Submit" ' . $form_attr . '>';
echo '</div>';
}
function lookup_db_field(string $table, string $id_field, int|string $id_value, string|array $result_field): string|array {
global $db;
if (is_numeric($id_value)) :
$id_value = nz(trim($id_value),'0');
else :
$id_value = $db->quote($id_value);
endif;
if (is_array($result_field)) :
array_map('sql_safe_object', $result_field);
$field_list = implode(', ', $result_field);
else :
$field_list = sql_safe_object($result_field);
endif;
$sql = "SELECT " . $field_list . " FROM " . sql_safe_object($table) . " WHERE " . sql_safe_object($id_field) . " = ".$id_value;
//echo '==='.$sql.'===';
$result = $db->query($sql);
if ($result->rowCount() > 0) :
$row = $result->fetch(PDO::FETCH_ASSOC);
if (is_array($result_field)) :
return $row;
else :
return $row[$result_field];
endif;
else :
return '';
endif;
}
function sql_safe_object($str) {
$str = '`' . preg_replace( '/[^a-z0-9_ ]/i', '', $str) . '`';
return $str;
}
function sql_safe_string($str) {
$str = preg_replace( '/[^a-z0-9_]/i', '', $str);
return $str;
}
function get_client_ip() {
$ipaddress = '';
if ($_SERVER['HTTP_CF_CONNECTING_IP'])
$ipaddress = $_SERVER['HTTP_CF_CONNECTING_IP'];
else if ($_SERVER['HTTP_CLIENT_IP'])
$ipaddress = $_SERVER['HTTP_CLIENT_IP'];
else if($_SERVER['HTTP_X_FORWARDED_FOR'])
$ipaddress = $_SERVER['HTTP_X_FORWARDED_FOR'];
else if($_SERVER['HTTP_X_FORWARDED'])
$ipaddress = $_SERVER['HTTP_X_FORWARDED'];
else if($_SERVER['HTTP_FORWARDED_FOR'])
$ipaddress = $_SERVER['HTTP_FORWARDED_FOR'];
else if($_SERVER['HTTP_FORWARDED'])
$ipaddress = $_SERVER['HTTP_FORWARDED'];
else if($_SERVER['REMOTE_ADDR'])
$ipaddress = $_SERVER['REMOTE_ADDR'];
else
$ipaddress = 'UNKNOWN';
return $ipaddress;
}
function send_mail_queue($job_id, $subject, $to, $cc, $bcc, $body, $attachments = [], $replacements = [], $from = APP_MAIL_FROM, $reply_name = '', $reply_address = '') {
global $db;
$sql = "INSERT INTO mail_queue SET";
}
function send_mail($subject, $to, $cc, $bcc, $body, $attachments = [], $replacements = [], $from = APP_MAIL_FROM, $reply_name = '', $reply_address = '') {
$mail = new PHPMailer\PHPMailer\PHPMailer();
//$mail->SMTPDebug = 3; // Enable verbose debug output 1-4
$mail->isSMTP();
$mail->Host = APP_MAIL_SMTP; // get_cfg_var('SMTP')
$mail->SMTPAuth = APP_MAIL_SMTP_AUTH; // false
$mail->Username = APP_MAIL_SMTP_USERNAME; // ''
$mail->Password = APP_MAIL_SMTP_PASSWORD; // ''
$mail->SMTPSecure = APP_MAIL_SMTP_SECURE; // 'tls' or 'ssl'
$mail->Port = APP_MAIL_SMTP_PORT; // get_cfg_var(smtp_port) 587 for secure
$mail->SMTPOptions = APP_MAIL_SMTP_OPTIONS;
if (!empty($reply_name) && !empty($reply_address)) :
//$mail->clearReplyTos();
//$mail->addReplyTo($reply_address, $reply_name);
$mail->From = $reply_address;
$mail->FromName = $reply_name;
else :
$mail->setFrom($from);
endif;
$ar_to = array_map('trim', explode(',', $to));
foreach ($ar_to as $value) :
$mail->addAddress($value);
endforeach;
//$mail->addAddress('[email protected]');
//$mail->addReplyTo('[email protected]', 'Information');
//$mail->addCC('[email protected]');
if (!empty($cc)) :
$ar_cc = array_map('trim', explode(',', $cc));
foreach ($ar_cc as $value) :
$mail->addCC($value);
endforeach;
endif;
if (!empty($bcc)) :
$ar_bcc = array_map('trim', explode(',', $bcc));
foreach ($ar_bcc as $value) :
$mail->addBCC($value);
endforeach;
endif;
foreach ($attachments as $file_name) :
$mail->addAttachment($file_name);
endforeach;
foreach ($replacements as $placeholder => $value) :
$body = str_ireplace('['.$placeholder.']', $value, $body);
endforeach;
$body = str_ireplace(PHP_EOL, '<br>', $body);
//$mail->addAttachment('/tmp/image.jpg', 'new.jpg');
$mail->isHTML(true);
$mail->Subject = $subject;
$mail_body = '<html><head>'.
'<style>body {font-family:Arial, Helvetica, sans-serif; font-size:14px;} table {font-size:14px;}</style>'.
'</head><body>'.
$body.
'</body></html>';
$mail->Body = $mail_body;
$mail_body_plain = str_ireplace('</p>', "\n\r", $mail_body);
$mail_body_plain = str_ireplace('<br>', "\n\r", $mail_body_plain);
$mail_body_plain = str_ireplace('<br />', "\n\r", $mail_body_plain);
$mail->AltBody = strip_tags($mail_body_plain);
if(!$mail->send()) :
//echo '<p>Message could not be sent.</p>';
//echo '<p>Mailer Error: '.$mail->ErrorInfo.'</p>';
write_log('E', 0, 'Error sending mail - '.$_GET['IX'].' - '.$mail->ErrorInfo);
global $app_mail_error_status;
$app_mail_error_status = $mail->ErrorInfo;
return false;
else :
//echo '<p>Message has been sent</p>';
return true;
endif;
}
function spam_count_exceeded($max_tries, $table) {
global $db;
$sql = "SELECT COUNT(*) AS ip_count FROM `{$table}` WHERE submitted_ip = " . $db->quote(get_client_ip());
$result = $db->query($sql);
$row = $result->fetch(PDO::FETCH_ASSOC);
$tries = $row['ip_count'];
if ($tries > $max_tries) :
return true;
else :
return false;
endif;
}
function snake_case($string) {
$string = strtolower(preg_replace("/[^A-Za-z0-9]/", '_', $string));
$string = preg_replace('~[_]+~', '_', $string);
$string = trim($string, '_');
return $string;
}