403Webshell
Server IP : 104.21.21.239  /  Your IP : 216.73.217.73
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/nymp/www/mod/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ Back ]     

Current File : /home/nymp/www/mod/_functions.php
<?php

	require_once('_permissions.php');
	require_once('_password.php');

	$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, $fsize, $frows = 0, $frequired = false, $disabled = false, $readonly = false, $fstyle = "", $fclass = "", $fdbname = "", $flabel = "", $ar_group = array(), $onchange = "", $onblur = "" )
	{
		global $ar_err;
		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 (!empty($fclass)) :
			$class = ' class="'.trim($fclass).'" ';
		endif;
		if ($disabled) :
			$disabled = ' disabled="disabled" ';
		endif;
		if ($readonly) :
			$readonly = ' readonly="readonly" ';
		endif;
		if (!empty($onchange)) :
			$onchange = ' onchange="'.trim($onchange).'" ';
		endif;
		if ($ftype == 'autocomplete') :
			$onblur .= ' lcs_autocomplete_close(\''.$fname.'\'); ';
		endif;
		if (!empty($onblur)) :
			$onblur = ' onblur="'.trim($onblur).'" ';
		endif;
		$attributes = $style.$class.$disabled.$readonly.$onchange.$onblur;
		switch ($ftype) :
			case "text" :
			case "password" :
				echo '<div class="input_field">';
				echo '<label for="'.$fname.'">'.$flabel.'</label>';
				echo '<input name="'.$fname.'" id="'.$fname.'" 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="'.$fname.'">'.$flabel.'</label>';
				echo '<select name="'.$fname.'" id="'.$fname.'" '.$attributes.'>';
				echo '<option value="">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;
						echo '<option value="'.$key.'" '.$selected.' /> '.$value.'</option>';
					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="'.$fname.'">'.$flabel.'</label>';
				echo '<input name="'.$fname.'" id="'.$fname.'" type="text" maxlength="'.$fsize.'" value="'.$_POST[$fname].'" '.$attributes.' onfocus="lcs_autocomplete_open(\''.$fname.'\')" onkeyup="lcs_autocomplete_filter(\''.$fname.'\')" />';
				echo '<div id="'.$fname.'_autocomplete" class="autocomplete"><ul>';
				foreach ($ar_group as $value) :
					echo '<li onclick="lcs_autocomplete_pick(this, \''.$fname.'\');">'.$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="'.$fname.'">'.$flabel.'</label>';
				echo '<fieldset id="'.$fname.'" '.$attributes.'>';
				if (is_assoc_array($ar_group)) :
					foreach ($ar_group as $key => $value) :
						$checked = '';
						if ($_POST[$fname] == $key) :
							$checked = ' checked="checked" ';
						endif;
						echo '<input type="radio" name="'.$fname.'" value="'.$key.'" '.$checked.' '.$attributes.' /> '.$value.'<br />';
						//echo $key.' '.$value.'<br />';
					endforeach;
				else :
					foreach ($ar_group as $value) :
						$checked = '';
						if ($_POST[$fname] == $value) :
							$checked = ' checked="checked" ';
						endif;
						echo '<input type="radio" name="'.$fname.'" value="'.$value.'" '.$checked.' '.$attributes.' /> '.$value.'<br />';
						//echo $value.'<br />';
					endforeach;
				endif;
				echo '</fieldset>';
				show_form_error($ar_err[$fname]);
				echo '</div>';
				break;
			case "checkgroup":
				echo '<div class="input_field">';
				echo '<label for="'.$fname.'">'.$flabel.'</label>';
				echo '<fieldset id="'.$fname.'" '.$attributes.'>';
				if (is_assoc_array($ar_group)) :
					foreach ($ar_group as $key => $value) :
						$checked = '';
						if (in_array($key, $_POST[$fname])) :
							$checked = ' checked="checked" ';
						endif;
						echo '<input type="checkbox" name="'.$fname.'[]" value="'.$key.'" '.$checked.' '.$attributes.' /> '.$value.'<br />';
						//echo $key.' '.$value.'<br />';
					endforeach;
				else :
					foreach ($ar_group as $value) :
						$checked = '';
						if (in_array($value, $_POST[$fname])) :
							$checked = ' checked="checked" ';
						endif;
						echo '<input type="checkbox" name="'.$fname.'[]" value="'.$value.'" '.$checked.' '.$attributes.' /> '.$value.'<br />';
						//echo $value.'<br />';
					endforeach;
				endif;
				echo '</fieldset>';
				show_form_error($ar_err[$fname]);
				echo '</div>';
				break;
			case "checkbox":
			case "radio":
				echo '<div class="input_field">';
				$checked = '';
				if ('1' == $_POST[$fname]) :
					$checked = ' checked="checked" ';
				endif;
				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="'.$fname.'">'.$flabel.'</label>';
				echo '<textarea name="'.$fname.'" id="'.$fname.'" cols="'.$fsize.'" rows="'.$frows.'"  ';
				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" :
				break;
		endswitch;
	}
	
	function form_button_strip($location, $ar_args = array(), $show_create_update = true)
	{
		global $xform_uid;
		$defaults = array(
							'save'				=> array('show' => true, 'caption' => 'Save', 'js' => "sheet_dirty = false; this.form.submit();"),
							'save_close'		=> array('show' => true, 'caption' => 'Save & Close', 'js' => "sheet_dirty = false; document.getElementById('xsubmit').value = this.value; this.form.submit();"),
							'save_new'			=> array('show' => true, 'caption' => 'Save & New', 'js' => "sheet_dirty = false; document.getElementById('xsubmit').value = this.value; this.form.submit();"),
							'cancel'			=> array('show' => true, 'caption' => 'Cancel', 'js' => "sheet_dirty = false; appstack_pop();"),
						);
		$ar_args = array_merge($defaults, $ar_args);
		echo '<div class="form_strip">';
		if (strtolower($location) == 'bottom' && $show_create_update) :
			show_create_update();
		endif;
		foreach ($ar_args as $key => $value) :
			if ($value['show']) :
				echo '<input type="button" value="'.$value['caption'].'" onclick="'.$value['js'].'" />';
			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.'" />';
		endif;
		echo '</div>';
	}
	
	function form_prep($default_ref = '', $default_tab = '')
	{
		global $action;
		global $active_tab;
		global $xform_uid;
		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;
		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;
	}
	
	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)
	{
		// 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
		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;
		//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" 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') :
			//$sql = mysql_real_escape_string($fsql);
			$result = mysql_query($fsql);
			echo '<ul class="autocomplete_list" id="'.$fname.'_items_ul" style="list-style-type: none; padding:0; margin:0;">';
			while ($row = mysql_fetch_array($result)):
				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_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 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->queryquery("SHOW TABLE STATUS LIKE '".$table_name."'");
		$row = $result->fetch(PDO::FETCH_ASSOC);
		$next_id = $row['Auto_increment'];
		return $next_id;
	}

	function nz($arg, $null_value = '')
	{
		if (empty($arg)) :
			return $null_value;
		else :
			$arg = str_replace(',', '', $arg);
			return intval($arg);
		endif;
	}

	function nzfloat($arg, $null_value = '')
	{
		if (empty($arg)) :
			return $null_value;
		else :
			$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')
	{
		global $db;
		if (empty($arg)) :
			return $null_value;
		else :
			return $db->quote(date('Y-m-d H:i:s', strtotime(str_replace('-', '/',trim($arg)))));
		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')
	{
		global $db;
		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 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));
		//echo 'data: '.$data.' filename: '.$filename.' root dir '.APP_ROOT_DIR;
		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 search_sql($str_search, $str_fields)
	{
		global $db;
		$ar_tokens = preg_split('/((^\p{P}+)|(\p{P}*\s+\p{P}*)|(\p{P}+$))/', $str_search, -1, PREG_SPLIT_NO_EMPTY);
		$ar_search = array();
		$i = 0;
		foreach ($ar_tokens as $token) :
			$i++;
			if (is_numeric($token)) :
				$ar_search[$i] = "(CONCAT_WS(' ',".$str_fields.") LIKE ".$db->quote("%".trim($token)."%").")";
			else :
				$ar_search[$i] = "(CONCAT_WS(' ',".$str_fields.") LIKE ".$db->quote("%".trim($token)."%")." OR soundex_match(".$db->quote(trim($token)).", CONCAT_WS(' ',".$str_fields."), ' '))";
			endif;
		endforeach;
		$str_result = "(".implode(' AND ', $ar_search).")";
		return $str_result;
	}

	function show_form_error($err_text)
	{
		if (!empty($err_text)) :
			echo '<br /><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)
	{
		$db = $GLOBALS['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)
{
		$title = $ar_pagecontrol[$ix]['page_title'];
		return $title;
	}
	
	function get_roles()
	{
		$return_result = '';
		if ($_SESSION['logged_in'] == 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 get_regions()
	{
		$return_result = '';
		if ($_SESSION['logged_in'] == 1) :
			$db = $GLOBALS['db'];
			$sql = "SELECT regions 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->regions;
			endif;
		endif;
		if (empty($return_result)) :
			$return_result = '0';
		endif;
		return $return_result;
	}
	
	function has_role($role)
	{
		$return_result = false;
		if ($_SESSION['logged_in'] == 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'] == 1 && $ar_pagecontrol[$ix]['show_state'] == 1)
				$bln_show_menu = true;
			if ($_SESSION['logged_in'] != 1 && $ar_pagecontrol[$ix]['show_state'] == 2)
				$bln_show_menu = true;
			if ($ar_pagecontrol[$ix]['show_state'] == 0)
				$bln_show_menu = true;
			if ($bln_show_menu)
			{
				if (empty($ar_pagecontrol[$ix]['view_roles']) || role_match($ar_pagecontrol[$ix]['view_roles'], get_roles()))
				{
					$return_result = true;
				}
			}			
		}
		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"], 'off') == "on" || nz_string($_SERVER['HTTP_X_FORWARDED_PROTO'], '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 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 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_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 xls_sql_encrypt($xls_sql)
	{
		return urlencode(sys_encrypt(gzcompress($xls_sql,6), $_SESSION['rand_key']));
	}

	function xls_sql_decrypt($xls_sql)
	{
		return gzuncompress(sys_decrypt(urldecode($xls_sql), $_SESSION['rand_key']));
	}

	function db_navigator_bar($ar_args)
	{
		$defaults = array(
							'subtab'			=> 'false',
							'parm1'				=> '',
							'parm2'				=> '',
							'parm3'				=> '',
							'btn_addnew'		=> 'true',
							'btn_print' 		=> 'true',
							'btn_excel' 		=> 'true',
							'btn_pdf'	 		=> 'true',
						);
		$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;
		$parm1 = $ar_args["parm1"];
		$parm2 = $ar_args["parm2"];
		$parm3 = $ar_args["parm3"];
		$subtab = $ar_args["subtab"];
?>
		<div class="db_nav">
			<?php if ($ar_args['btn_addnew'] == 'true') : ?>
				<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]); ?>" >
				<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 &reg;" 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; ?>
			&emsp;
			Records: <div style="width:50px; text-align:right; display:inline-block;" id="<?php echo $table_id; ?>_total_count"></div>
			<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 - New York Metro Parents</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]); ?>', "<?php echo $parm1; ?>", "<?php echo $parm2; ?>", "<?php echo $parm3; ?>", '<?php echo $filter_cols; ?>' );
				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);
											}
									,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 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']; ?>"  />
						<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']); ?>"  />
					</td>
					<td>
						<input name="create_date" id="create_date" type="text" readonly="readonly" class="create_update" value="<?php echo $_POST['create_date']; ?>"  />
					</td>
				</tr>
				<tr>
					<td>
						Updated:
					</td>
					<td>
						<input name="update_by" id="update_by" type="hidden" readonly="readonly" value="<?php echo $_POST['update_by']; ?>"  />
						<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']); ?>"  />
					</td>
					<td>
						<input name="update_date" id="update_date" type="text" readonly="readonly" class="create_update" value="<?php echo $_POST['update_date']; ?>"  />
					</td>
				</tr>
			</table>
		</div>
<?php
	}

?>

Youez - 2016 - github.com/yon3zu
LinuXploit