403Webshell
Server IP : 104.21.21.239  /  Your IP : 216.73.216.11
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/mitzvahm/wwwdevplanner/mod/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ Back ]     

Current File : /home/mitzvahm/wwwdevplanner/mod/_functions.php
<?php

	$ar_ftype = array();
	$ar_ffields = array();
	$ar_fupdate = array();
	$ar_finsert = array();
	$ar_fretrieve = array();
	function add_form_field($fname, $ftype, $fsize, $frows = 0, $frequired = false, $fstyle = "", $fclass = "", $fdbname = "")
	{
		if (empty($fdbname)) :
			$fdbname = $fname;
		endif;
		switch ($ftype) :
			case "text" :
				echo '<input name="'.$fname.'" id="'.$fname.'" type="text" maxlength="'.$fsize.'" value="'.$_POST[$fname].'" ';
				if (!empty($fstyle)) :
					echo ' style="'.$fstyle.'" ';
				endif;
				if (!empty($fclass)) :
					echo ' class="'.$fclass.'" ';
				endif;
				echo '  />';
				show_form_error($ar_err[$fname]);
				$ar_ftype[] = $ftype;
				$ar_ffields[] = $fdbname;
				$ar_fupdate[] = $fdbname;
			case "textarea" :
			case "date" :
			case "select" :
		endswitch;
	}
	function form_field($fname, $ftype, $fsize, $frows = 0, $frequired = false, $fstyle = "", $fclass = "", $fdbname = "")
	{
		if (empty($fdbname)) :
			$fdbname = $fname;
		endif;
		switch ($ftype) :
			case "text" :
				echo '<input name="'.$fname.'" id="'.$fname.'" type="text" maxlength="'.$fsize.'" value="'.$_POST[$fname].'" ';
				if (!empty($fstyle)) :
					echo ' style="'.$fstyle.'" ';
				endif;
				if (!empty($fclass)) :
					echo ' class="'.$fclass.'" ';
				endif;
				echo '  />';
				show_form_error($ar_err[$fname]);
				$ar_ftype[] = $ftype;
				$ar_ffields[] = $fdbname;
				$ar_fupdate[] = $fdbname;
				break;
			case "textarea" :
				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]);
				break;
			case "date" :
				break;
			case "select" :
				break;
		endswitch;
	}
	
	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 format_guest_name($guest_id, $salutations = true)
	{
		$formatted_name = '';
		$sql = "SELECT * FROM guests WHERE id = ".mysqli_real_escape_string($GLOBALS['con'], $guest_id)." AND user_id = ".$_SESSION['user_id']."  AND event_id = ".$_SESSION['active_event']." ";
		$result = mysqli_query($GLOBALS['con'], $sql);
		if (mysqli_num_rows($result) > 0) :
			$row = mysqli_fetch_object($result);
			if (!empty($row->salutation) && $salutations) :
				$formatted_name = $formatted_name.' '.$row->salutation;
			endif;
			if (!empty($row->first_name)) :
				$formatted_name = $formatted_name.' '.$row->first_name;
			endif;
			if (!empty($row->last_name)) :
				$formatted_name = $formatted_name.' '.$row->last_name;
			endif;
			if (!empty($row->suffix) && $salutations) :
				$formatted_name = $formatted_name.' '.$row->suffix;
			endif;
		endif;
		$formatted_name = trim($formatted_name);
		return $formatted_name;
	}
	
	function format_guest_name_string($salutation, $first_name, $last_name, $suffix)
	{
		$formatted_name = '';
		if (!empty($salutation)) :
			$formatted_name = $formatted_name.' '.$salutation;
		endif;
		if (!empty($first_name)) :
			$formatted_name = $formatted_name.' '.$first_name;
		endif;
		if (!empty($last_name)) :
			$formatted_name = $formatted_name.' '.$last_name;
		endif;
		if (!empty($suffix)) :
			$formatted_name = $formatted_name.' '.$suffix;
		endif;
		$formatted_name = trim($formatted_name);
		return $formatted_name;
	}
	
	function format_address($invitation_text, $invitation_text2, $salutation, $first_name, $last_name, $suffix, $street, $street2, $city, $state, $zip, $country)
	{
		$str_result = '';
		if (!empty($invitation_text)) :
			$guest_text = $invitation_text;
		else :
			$guest_text = format_guest_name_string($salutation, $first_name, $last_name, $suffix);
		endif;
		$str_result .= $guest_text.'<br />';
		if (!empty($invitation_text2)):
			$str_result .= $invitation_text2.'<br />';
		endif;
		if (!empty($street)):
			$str_result .= $street.'<br />';
		endif;
		if (!empty($street2)):
			$str_result .= $street2.'<br />';
		endif;
		$city_state_zip = '';
		if (!empty($city)):
			$city_state_zip .= $city.', ';
		endif;
		if (!empty($state)):
			$city_state_zip .= $state.' ';
		endif;
		if (!empty($zip)):
			$city_state_zip .= ' '.$zip;
		endif;
		if (!empty($city_state_zip)):
			$str_result .= $city_state_zip.'<br />';
		endif;
		if (!empty($country)):
			$str_result .= $country;
		endif;
		return $str_result;
	}
	
	function auto_complete($fname, $value, $text, $fsql, $limit_to_list = null, $w = null, $h = null, $tab_index = null, $change_js = null, $ar_choices = array())
	{
		// 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;
		$change_js = 'autocomplete_blur(\''.$fname.'\', '.$limit_list.'); '.$change_js;
		$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' || substr(trim(strtoupper($fsql)),0,7) == '(SELECT') :
			//$sql = mysqli_real_escape_string($GLOBALS['con'], $fsql);
			$result = mysqli_query($GLOBALS['con'], $fsql);
			echo '<ul class="autocomplete_list" id="'.$fname.'_items_ul" style="list-style-type: none; padding:0; margin:0;">';
			while ($row = mysqli_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>';
		elseif (count($ar_choices) > 0) :
			echo '<ul class="autocomplete_list" id="'.$fname.'_items_ul" style="list-style-type: none; padding:0; margin:0;">';
			foreach ($ar_choices as $value):
				echo '<li ac_value="'.$value.'" onclick="autocomplete_pick(\''.$fname.'\', \''.$value.'\', \''.$value.'\', '.$limit_list.');" >'.$value.'</li>';
			endforeach;
			echo '</ul>';
		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 '</div>';
		endif;
	}
	
	function last_id()
	{
		$result_insert = mysqli_query($GLOBALS['con'], "SELECT LAST_INSERT_ID() AS LastID");
		$row_insert = mysqli_fetch_array($result_insert);
		$last_id = $row_insert['LastID'];
		return $last_id;
	}

	function next_id($table_name)
	{
		$result = mysqli_query($GLOBALS['con'], "SHOW TABLE STATUS LIKE '".$table_name."'");
		$row = mysqli_fetch_array($result);
		$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')
	{
		if (empty($arg)) :
			return $null_value;
		else :
			return "'".date('Y-m-d', strtotime(str_replace('-', '/',mysqli_real_escape_string($GLOBALS['con'], 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 vert_text2($text,$size = 10,$color = array(253,128,46))
	{
		$dir = $GLOBALS["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 = $GLOBALS["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 = $GLOBALS["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);
			$color_white = array(55,204,182);
			$font = $GLOBALS["app_root_dir"]."/fonts/Merriweather-Regular.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)
	{
		$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 '%".mysqli_real_escape_string($GLOBALS['con'], trim($token))."%')";
			else :
				$ar_search[$i] = "(CONCAT_WS(' ',".$str_fields.") LIKE '%".mysqli_real_escape_string($GLOBALS['con'], trim($token))."%' OR soundex_match('".mysqli_real_escape_string($GLOBALS['con'], trim($token))."', CONCAT_WS(' ',".$str_fields."), ' '))";
			endif;
		endforeach;
		$str_result = "(".implode(' AND ', $ar_search).")";
		return $str_result;
	}

	function venue_decode($venue, $event_id = 0)
	{
		$ret = $venue;
		if ($event_id == 0) :
			$event_id = $_SESSION['active_event'];
		endif;
		//$sql = "SELECT ".$venue."_rename AS venue_rename FROM events WHERE id = ".$_SESSION['active_event']." AND user_id = ".$_SESSION['user_id']." ";
		$sql = "SELECT ".$venue."_rename AS venue_rename FROM events WHERE id = ".$event_id." AND user_id = ".$_SESSION['user_id']." ";
		$result = mysqli_query($GLOBALS['con'], $sql);
		if (mysqli_num_rows($result) > 0) :
			$row = mysqli_fetch_object($result);
			$ret = $row->venue_rename;
		else :
			switch ($venue) :
				case 'temple' :
					$ret = 'Temple';
					break;
				case 'av' :
					$ret = 'Main Venue';
					break;
				case 'kv' :
					$ret = 'Kids Venue';
					break;
				case 'bv' :
					$ret = 'Brunch Venue';
					break;
				case 'dv' :
					$ret = 'Dinner Venue';
					break;
			endswitch;
		endif;
		/*
		*/
		return $ret;
	}

	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 get_reports($rpt_string = '')
	{
		$ar_reports = explode(',', $rpt_string);
		if (count($ar_reports) > 0) :
?>
			<div class="report_guide">
				<div class="report_icon">
					<input type="button" id="report_icon" class="mini" value="Reports..." onclick="toggleReports();" />
					<div id="report_select" class="report_select" style="display:none;">
						<div style="float:right; width:20%; text-align:right; cursor:pointer; font-family:Arial, Helvetica, sans-serif; font-size:16px; font-weight:bold;" onclick="toggleReports();">
							X
						</div>
						<div style="float:none; width:80%; text-align:left; font-style:italic;">
							Reports
						</div>
						<ul>
							<?php
								foreach ($ar_reports as $value) :
								$report_name = htmlspecialchars(get_report_name($value));
								$report_page = htmlspecialchars(get_report_page($value));
								if (empty($report_page)) :
									$report_page = 'report_options';
								endif;
							?>
									<a href="index.php?IX=<?php echo $report_page; ?>&rpt=<?php echo $value; ?>"><li><?php echo $report_name; ?></li></a>
							<?php
								endforeach;
							?>
						</ul>
					</div>
				</div>
			</div>
<?php
		endif;
	}

	function get_help_guide($ix)
	{
		echo '<div class="help_guide">';
		echo '<div class="help_icon" id="help_icon" onclick="toggleHelp('."'".$ix."'".');">';
		echo '?';
		echo '</div>';
		echo '<div class="help_text" id="help_section">';
		load_video_help($ix);
		//echo nl2br(get_text($ix));
		echo get_text($ix);
		echo '</div>';
		echo '</div>';
		echo '<div id="ajax_help" style="width:1px; height:1px; display:none;">';
		echo '</div>';
		$sql = "SELECT help_guide FROM users WHERE id = ".$_SESSION['user_id'];
		$result = mysqli_query($GLOBALS['con'], $sql);
		if (mysqli_num_rows($result) > 0) :	
			$row = mysqli_fetch_object($result);
			if ($row->help_guide == 1) :
				echo '<SCRIPT>';
				echo '$("#help_section").show();';
				echo "$('#help_icon').text('X').addClass('help_icon_open');";
				echo '</SCRIPT>';
			else :
				echo '<SCRIPT>';
				echo '$("#help_section").hide();';
				echo "$('#help_icon').text('?').removeClass('help_icon_open');";
				echo '</SCRIPT>';
			endif;
		endif;
	}
	
	function load_video_help($ix)
	{
		$video_ix = str_replace('help_', 'video_', $ix);
		//echo '==='.$ix.'===';
		if (get_text($video_ix) != 'Text not found') :
			echo '<img src="img/video_icon.png" align="right" style="cursor:pointer;" onclick="window_video(\'terms_window\',\''.$video_ix.'\')" />';
		else :
			// **** for videos that apply to all help tabs ****
			$ar_tabs = explode('_', $video_ix);
			unset($ar_tabs[count($ar_tabs) - 1]);
			$video_ix = implode('_', $ar_tabs);
			if (get_text($video_ix) != 'Text not found') :
				echo '<img src="img/video_icon.png" align="right" style="cursor:pointer;" onclick="window_video(\'terms_window\',\''.$video_ix.'\')" />';
			endif;
		endif;
	}
	
	function get_notes()
	{
		global $action;
		if (empty($_GET['id']) || is_numeric($_GET['id'])) :
			if ($action != 'Add New' || ($action == 'Add New' && is_numeric($_REQUEST['id']))) :
			//if (is_numeric($_REQUEST['id'])) :
			?>
				<div style="position:relative;">
					<div class="note_icon">
						<img id="note_icon_image" src="img/lg_note_icon_30x30.png" onclick="notes_load('<?php echo $_GET['IX']; ?>', <?php echo nz($_REQUEST['id'],0); ?>, true);" />
					</div>
					<div id="notes_ajax" style="display:none;">
					</div>
					<div class="note_window" id="note_window">
						<form>
							<span style="font-size:18px; font-weight:bold;">Notes<br /></span>
							<div class="note_text">
								<textarea style="width:100%; height:100%; " name="system_notes" id="system_notes"></textarea>
							</div>
							<div class="note_buttons">
								<table style="margin-bottom:10px;">
									<tr>
										<td width="150" align="left">
											Follow-up Date
										</td>
										<td width="210" align="left">
											<input name="notes_followup_date" id="notes_followup_date" class="date-pick dp-applied" readonly="readonly" type="text" maxlength="20" style="width:200px;"   />
										</td>
									</tr>
									<tr>
										<td align="left">
											Follow-up Complete
										</td>
										<td align="left">
											<input name="notes_followup_complete" id="notes_followup_complete" type="checkbox" value="1" />
										</td>
									</tr>
								</table>
								<input type="button" value="Save" onclick="notes_save('<?php echo $_GET['IX']; ?>', <?php echo nz($_REQUEST['id'],0); ?>); notes_load('<?php echo $_GET['IX']; ?>', <?php echo nz($_REQUEST['id'],0); ?>, false);" />
								&nbsp;&nbsp;
								<input type="button" value="Cancel" onclick="$('#note_window').hide();" />
							</div>
						</form>
					</div>
				</div>
				<script>
					$(document).ready(function()	
					{
						setTimeout(function() {notes_load('<?php echo $_GET['IX']; ?>', <?php echo nz($_REQUEST['id'],0); ?>, false)}, 500);
					})
				</script>
			<?php
			endif;
		endif;
	}

	function get_text($ix)
	{
		$result = mysqli_query($GLOBALS['con'], "SELECT * FROM texts WHERE text_key = '".mysqli_real_escape_string($GLOBALS['con'], trim($ix))."'");
		$num_rows = mysqli_num_rows($result);
		$row = mysqli_fetch_array($result);
		//echo $row['PageTitle'];
		if ($num_rows >= 1) :
			if ($row['text_type'] == 'HTML') : 
				$text = $row['text_string'];
			else :
				$text = nl2br(strip_tags($row['text_string']));
			endif;
		else :
			$text = 'Text not found';
		endif;
		return $text;
	}
		
	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 to get the client ip address
	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 write_log($log_type, $user_id, $log_text)
	{
		$sql = "INSERT INTO log set ".
			"user_id = ".mysqli_real_escape_string($GLOBALS['con'], trim($user_id)).", ".
			"log_type = '".mysqli_real_escape_string($GLOBALS['con'], trim($log_type))."', ".
			"log_text = '".mysqli_real_escape_string($GLOBALS['con'], trim($log_text))."', ".
			"ip = '".get_client_ip()."' ";
		mysqli_query($GLOBALS['con'], $sql) or die('Database error - Log failure! Please contact the web site administrator.');
	}
	
	function get_report_name($ix)
	{
		$result = mysqli_query($GLOBALS['con'], "SELECT * FROM reports WHERE report_key = '".mysqli_real_escape_string($GLOBALS['con'], trim($ix))."'");
		if (mysqli_num_rows($result) > 0) :
			$row = mysqli_fetch_array($result);
			$title = $row['report_name'];
		else :
			$title = 'Report title not found';
		endif;
		return $title;
	}
		
	function get_report_page($ix)
	{
		$result = mysqli_query($GLOBALS['con'], "SELECT * FROM reports WHERE report_key = '".mysqli_real_escape_string($GLOBALS['con'], trim($ix))."'");
		if (mysqli_num_rows($result) > 0) :
			$row = mysqli_fetch_array($result);
			$page = $row['report_page'];
		else :
			$page = 'Report title not found';
		endif;
		return $page;
	}
		
	function get_page_title($ix)
	{
		$result = mysqli_query($GLOBALS['con'], "SELECT * FROM pagecontrol WHERE PageIndex = '".mysqli_real_escape_string($GLOBALS['con'], trim($ix))."'");
		if (mysqli_num_rows($result) > 0) :
			$row = mysqli_fetch_array($result);
			$title = $row['PageTitle'];
		else :
			$title = 'Page title not found';
		endif;
		return $title;
	}
		
	function page_allowed($ix)
	{
		$return_result = false;
		$ix = mysqli_real_escape_string($GLOBALS['con'], trim($ix));
		$result = mysqli_query($GLOBALS['con'], "SELECT * FROM pagecontrol WHERE PageIndex = '".$ix."'");
		$num_rows = mysqli_num_rows($result);
		$row = mysqli_fetch_array($result);
		if ($num_rows >= 1)
		{
			$bln_show_menu = false;
			//var_dump($_SESSION);
			//var_dump($row);
			//die();
			if ($_SESSION['logged_in'] == 1 && $row['ShowState'] == 1)
				$bln_show_menu = true;
			if ($_SESSION['logged_in'] != 1 && $row['ShowState'] == 2)
				$bln_show_menu = true;
			if ($row['ShowState'] == 0)
				$bln_show_menu = true;
			if ($bln_show_menu)
			{
				if (empty($row['ShowRoles']) || role_match($row['ShowRoles'],$_SESSION['roles']))
				{
					$return_result = true;
				}
			}			
		}
		return $return_result;
	}
		
	function page_secure($ix)
	{
		$return_result = false;
		$ix = mysqli_real_escape_string($GLOBALS['con'], trim($ix));
		$result = mysqli_query($GLOBALS['con'], "SELECT * FROM pagecontrol WHERE PageIndex = '".$ix."'");
		$num_rows = mysqli_num_rows($result);
		$row = mysqli_fetch_array($result);
		if ($num_rows >= 1)
		{
			if ($row['secure'] == 1)
			{
				$return_result = true;
			}
		}
		return $return_result;
	}

	function nz_string($arg, $null_value = '')
	{
		if (!isset($arg) || trim($arg) === '') :
			return $null_value;
		else :
			return $arg;
		endif;
	}
		
	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 get_event_field($field_name)
	{
		$sql = "SELECT * FROM events WHERE user_id = ".mysqli_real_escape_string($GLOBALS['con'], $_SESSION['user_id'])." AND id = ".mysqli_real_escape_string($GLOBALS['con'], $_SESSION['active_event']);
		//echo '==='.$sql.'===';
		$result = mysqli_query($GLOBALS['con'], $sql);
		if (mysqli_num_rows($result) > 0) :
			$row = mysqli_fetch_array($result);
			return $row[$field_name];
		else :
			return 'Not Found!';
			return '';
		endif;
	}

	function get_rating($table_name, $key_id)
	{
		$result = 0;
		if ($str == 'on')
			$result = '1';
		else
			$result = '0';
		return $result;
	}

	function get_my_rating($table_name, $user_id, $key_id)
	{
		$result = 0;
		if ($str == 'on')
			$result = '1';
		else
			$result = '0';
		return $result;
	}

	function get_graphic_rating($rating)
	{
		$result = '';
		for ($i=1; $i<=5; $i++)
		{
			if ($i <= $rating)
				$result = $result.'<img src="img/star_filled_16.gif">';
			//else
				//$result =  $result.'<img src="img/star_hollow_16.gif">';
		}
		/*
		*/
		return $result;
	}

	function show_graphic_rating_form($rating)
	{
		$result = '';
		for ($i=1; $i<=5; $i++)
		{
			if ($i <= $rating)
				$result = $result.'<img src="../img/star_filled_16.gif">';
			//else
				//$result =  $result.'<img src="../img/star_hollow_16.gif">';
		}
		/*
		*/
		return $result;
	}

	function get_my_graphic_rating($table_id, $key_id)
	{
		$html = '';
		$rating = 0;
		global $_SESSION;
		$sql = "SELECT * FROM ratings WHERE TableID = ".$table_id." AND KeyID = ".$key_id." AND UserID = ".$_SESSION['user_id'];
		$result = mysqli_query($GLOBALS['con'], $sql);
		$num_rows = mysqli_num_rows($result);
		if ($num_rows > 0)
		{
			$row = mysqli_fetch_array($result);
			$rating = $row['Rating'];
		}
		//$html = $html.'<input type="hidden" id="'.$field_name.'" name="'.$field_name.'" value="'.$rating.'" />';
		//$html = $html.'<div id="rating_'.$field_name.'">';
		for ($i=1; $i<=5; $i++)
		{
			if ($i <= $rating)
				$html = $html.'<img src="img/star_filled_16.gif" >';
			//else
				//$html = $html.'<img src="img/star_hollow_16.gif" >';
		}
		$html = $html.'</div>';
		return $html;
	}

	function get_peer_graphic_rating($table_id, $key_id)
	{
		$html = '';
		$rating = 0;
		global $_SESSION;
		$sql = "SELECT ROUND(AVG(Rating)) AS PeerRating FROM ratings WHERE TableID = ".$table_id." AND KeyID = ".$key_id." AND UserID <> ".$_SESSION['user_id']." AND Rating <> 0";
		$result = mysqli_query($GLOBALS['con'], $sql);
		$num_rows = mysqli_num_rows($result);
		if ($num_rows > 0)
		{
			$row = mysqli_fetch_array($result);
			$rating = $row['PeerRating'];
		}
		for ($i=1; $i<=5; $i++)
		{
			if ($i <= $rating)
				$html = $html.'<img src="img/star_filled_16.gif" >';
			//else
				//$html = $html.'<img src="img/star_hollow_16.gif" >';
		}
		$html = $html.'</div>';
		return $html;
	}


	function get_peer_listing($table_id, $key_id)
	{
		$html = '';
		$rating = 0;
		global $_SESSION;
		$sql = "SELECT * FROM ratings INNER JOIN users on ratings.UserID = users.UserID WHERE TableID = ".$table_id." AND KeyID = ".$key_id." AND ratings.UserID <> ".$_SESSION['user_id']." ORDER BY CommentDate DESC";
		$result = mysqli_query($GLOBALS['con'], $sql);
		$num_rows = mysqli_num_rows($result);
		
		$html .= '<table border="0" cellspacing="3" cellpadding="0" style="text-align:left;" >';
		$html .= '<tr>';
		$html .= '<td>';
		$html .= '<div style="width:80px;">';
		$html .= '</div>';
		$html .= '</td>';
		$html .= '<td>';
		$html .= '<div style="width:140px;">';
		$html .= '</div>';
		$html .= '</td>';
		$html .= '<td>';
		$html .= '<div style="width:420px;">';
		$html .= '</div>';
		$html .= '</td>';
		$html .= '<td>';
		$html .= '<div style="width:90px;">';
		$html .= '</div>';
		$html .= '</td>';
		$html .= '</tr>';

		$html .= '<tr>';
		$html .= '<td colspan="4" align="center" class="form-header">';
		$html .= 'Network / Peer Feedback';
		$html .= '</td>';
		$html .= '</tr>';

		$html .= '<tr>';
		$html .= '<td align="center">';
		$html .= 'Date';
		$html .= '</td>';
		$html .= '<td align="center">';
		$html .= 'Screen Name';
		$html .= '</td>';
		$html .= '<td align="center">';
		$html .= 'Comment';
		$html .= '</td>';
		$html .= '<td align="center">';
		$html .= 'Rating';
		$html .= '</td>';
		$html .= '</tr>';


		while($row = mysqli_fetch_array($result))
		{
			$html .= '<tr>';
			$html .= '<td class="data-grid-var" valign="top">';
			$html .= date('m/d/Y',strtotime($row['CommentDate']));
			$html .= '</td>';
			$html .= '<td class="data-grid-var" valign="top">';
			$html .= $row['ScreenName'];
			//var_dump($row);
			$html .= '</td>';
			$html .= '<td class="data-grid-var" valign="top">';
			$html .= $row['Comment'];
			$html .= '</td>';
			$html .= '<td class="data-grid-var" valign="top">';
			$html .= show_graphic_rating_form($row['Rating']);
			$html .= '</td>';
			$html .= '</tr>';
		}

		$html .= '</table>';
		$html .= '<BR />';
		return $html;
	}

	function form_graphic_rating($table_id, $key_id, $user_id, $field_name)
	{
		$html = '';
		$rating = 0;
		$sql = "SELECT * FROM ratings WHERE TableID = ".$table_id." AND KeyID = ".$key_id." AND UserID = ".$user_id;
		$result = mysqli_query($GLOBALS['con'], $sql);
		$num_rows = mysqli_num_rows($result);
		if ($num_rows > 0)
		{
			$row = mysqli_fetch_array($result);
			$rating = $row['Rating'];
		}
		$html = $html.'<input type="hidden" id="'.$field_name.'" name="'.$field_name.'" value="'.$rating.'" />';
		$html = $html.'<div id="rating_'.$field_name.'">';
		for ($i=1; $i<=5; $i++)
		{
			$jscript = "'".$field_name."',".$i;
			//echo $jscript;
			if ($i <= $rating)
				$html = $html.'<img src="../img/star_filled_16.gif" style="cursor:pointer;" onclick="change_rating('.$jscript.');">';
			else
				$html = $html.'<img src="../img/star_hollow_16.gif" style="cursor:pointer;" onclick="change_rating('.$jscript.');">';
		}
		$html = $html.'</div>';
		/*
		*/
		return $html;
	}

	function graphic_rating_edit($rating, $field_name)
	{
		$html = '';
		$html = $html.'<input type="hidden" id="'.$field_name.'" name="'.$field_name.'" value="'.$rating.'" />';
		$html = $html.'<div id="rating_'.$field_name.'">';
		for ($i=1; $i<=5; $i++)
		{
			$jscript = "'".$field_name."',".$i;
			//echo $jscript;
			if ($i <= $rating)
				$html = $html.'<img src="img/star_filled_16.gif" style="cursor:pointer;" onclick="change_rating('.$jscript.');">';
			else
				$html = $html.'<img src="img/star_hollow_16.gif" style="cursor:pointer;" onclick="change_rating('.$jscript.');">';
		}
		$html = $html.'</div>';
		/*
		*/
		return $html;
	}

	function graphic_rating_show($rating)
	{
		$html = '';
		//$html = $html.'<input type="hidden" id="'.$field_name.'" name="'.$field_name.'" value="'.$rating.'" />';
		$html = $html.'<div>';
		for ($i=1; $i<=5; $i++)
		{
			$jscript = "'".$field_name."',".$i;
			//echo $jscript;
			if ($i <= $rating)
				$html = $html.'<img src="img/star_filled_16.gif" >';
			else
				$html = $html.'<img src="img/star_hollow_16.gif" >';
		}
		$html = $html.'</div>';
		/*
		*/
		return $html;
	}

	function form_comment($table_id, $key_id, $user_id, $field_name, $width, $class, $rows, $cols)
	{
		$html = '';
		$comment = '';
		$sql = "SELECT * FROM ratings WHERE TableID = ".$table_id." AND KeyID = ".$key_id." AND UserID = ".$user_id;
		$result = mysqli_query($GLOBALS['con'], $sql);
		$num_rows = mysqli_num_rows($result);
		if ($num_rows > 0)
		{
			$row = mysqli_fetch_array($result);
			$comment = $row['Comment'];
		}
		$html = $html.'<textarea id="'.$field_name.'" name="'.$field_name.'" class="'.$class.'" rows="'.$rows.'" cols="'.$cols.'" style="width:'.$width.'px;" />';
		$html = $html.$comment;
		$html = $html.'</textarea>';
		return $html;
	}



	function update_rating_comment($table_id, $key_id, $user_id, $rating, $comment)
	{
		$sql = "SELECT * FROM ratings WHERE TableID = ".$table_id." AND KeyID = ".$key_id." AND UserID = ".$user_id;
		$result_rating = mysqli_query($GLOBALS['con'], $sql);
		if (mysqli_num_rows($result_rating) > 0)			
		{
			//*** update rating ***
			$sql = "UPDATE ratings SET Rating = ".$rating.", Comment = '".$comment."', CommentDate = '".date('Y-m-d H:i:s')."' WHERE TableID = ".$table_id." AND KeyID = ".$key_id." AND UserID = ".$user_id;
			mysqli_query($GLOBALS['con'], $sql);
		}
		else
			//*** store rating ***
		{
			if ($rating != '0' || $comment != '')
			{
				$sql = "INSERT INTO ratings (TableID, KeyID, UserID, Rating, Comment, CommentDate) VALUES (".$table_id.", ".$key_id.", ".$user_id.", ".$rating.", '".$comment."', '".date('Y-m-d H:i:s')."')";
				mysqli_query($GLOBALS['con'], $sql);
				//echo ' SQL '.$sql;
			}
		}
	}


	function drop_down($name, $width, $class, $type_key, $curr_key)
	{
		$html = '';
		$sql = "SELECT * FROM lookups WHERE LookupType = ".$type_key." ORDER BY LookupValue";
		$result = mysqli_query($GLOBALS['con'], $sql);
		$html = '<SELECT id="'.$name.'" name="'.$name.'" class="'.$class.'" style="width:'.$width.';">';
		while($row = mysqli_fetch_array($result))
		{
			$html = $html.'<option value="'.$row['LookupKey'].'" ';
			if ($row['LookupKey'] == $curr_key)
			{
				$html = $html.' selected="selected" ';
			}
			$html = $html.' >'.$row['LookupValue'].'</option>';
		}
		$html = $html.'</SELECT>';
		return $html;
	}

	function drop_down_lookup($name, $width, $class, $value_field, $display_field, $curr_value, $sql)
	{
		$html = '';
		//$sql = "SELECT * FROM lookups WHERE LookupType = ".$type_key." ORDER BY LookupValue";
		$result = mysqli_query($GLOBALS['con'], $sql);
		$html = '<SELECT id="'.$name.'" name="'.$name.'" class="'.$class.'" style="width:'.$width.';">';
		$html .= '<option value="0" ';
		if ('0' == $curr_value)
		{
			$html .= ' selected="selected" ';
		}
		$html .= ' ></option>';
		while($row = mysqli_fetch_array($result))
		{
			$html .= '<option value="'.$row[$value_field].'" ';
			if ($row[$value_field] == $curr_value)
			{
				$html .= ' selected="selected" ';
			}
			$html .= ' >'.$row[$display_field].'</option>';
		}
		$html .= '</SELECT>';
		return $html;
	}

	function check_boxes($name, $cb_set, $cb_data)
	{
		$html = '';
		$ar_set = explode(', ',$cb_set);
		$ar_data = explode(', ',$cb_data);
		foreach ($ar_set as $ar_set_value)
		{
			$checked = '';
			if (is_numeric(array_search($ar_set_value, $ar_data)))
				$checked = 'checked="checked"';
			$html = $html.'<input type="checkbox" name="'.$name.'[]" value="'.$ar_set_value.'" '.$checked.' > '.$ar_set_value.'<br />';
		}
		return $html;
	}

	function radio_boxes($name, $cb_set, $cb_data)
	{
		$html = '';
		$ar_set = explode(', ',$cb_set);
		$ar_data = explode(', ',$cb_data);
		foreach ($ar_set as $ar_set_value)
		{
			$checked = '';
			if (is_numeric(array_search($ar_set_value, $ar_data)))
				$checked = 'checked="checked"';
			$html = $html.'<input type="radio" name="'.$name.'" value="'.$ar_set_value.'" '.$checked.' > '.$ar_set_value.'<br />';
		}
		return $html;
	}
	
	//-----------------------------------------------------------------------------------------------------
	
	function check_box($i, $text, $name, $value, $unchecked_img, $checked_img, $opt_js = '', $opt_values = '')
	{
		$checked = '';
		$curr_img = $unchecked_img;
		$ar_values = explode(',', $opt_values);
		if (in_array($value,$ar_values)) :
			$checked = 'checked="checked"';
			$curr_img = $checked_img;
		endif;
		echo '<span class="checkbox"><input name="'.$name.'" id="check_'.$i.'" type="checkbox" '.$checked.' value="'.$value.'" style="display:none;" /><img class="checkbox" id="check_img_'.$i.'" src="'.$curr_img.'" onclick="toggle_check_box('.$i.', \''.$unchecked_img.'\', \''.$checked_img.'\');'.addslashes($opt_js).'" />'.$text.'</span> ';
	}

	function radio_box($i, $text, $name, $value, $unchecked_img, $checked_img, $opt_js = '')
	{
		echo '<span class="checkbox"><input name="'.$name.'" id="radio_'.$name.'_'.$i.'" type="radio" value="'.$value.'" style="display:none;" /><img class="checkbox" id="radio_img_'.$name.'_'.$i.'" src="'.$unchecked_img.'" onclick="toggle_radio_box('.$i.',\''.$name.'\', \''.$unchecked_img.'\', \''.$checked_img.'\');'.addslashes($opt_js).'" />'.$text.'</span> ';
	}

	function rollover_button($base_img, $rollover_img, $cb_set, $cb_data)
	{
		$html = '';
		$ar_set = explode(', ',$cb_set);
		$ar_data = explode(', ',$cb_data);
		foreach ($ar_set as $ar_set_value)
		{
			$checked = '';
			if (is_numeric(array_search($ar_set_value, $ar_data)))
				$checked = 'checked="checked"';
			$html = $html.'<input type="radio" name="'.$name.'" value="'.$ar_set_value.'" '.$checked.' > '.$ar_set_value.'<br />';
		}
		return $html;
	}
	
	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 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 show_faq()
	{
		$sql = "SELECT * FROM faqs WHERE active = 1 ORDER by seq ASC ";
		$result = mysqli_query($GLOBALS['con'], $sql) or die('Database Error!');
		while ($row = mysqli_fetch_object($result)) :
			echo '<div class="faq_question">';
			echo '<a href="javascript:(function() { $(\'#faq_answer_'.$row->seq.'\').slideToggle(200); }) ()">'.nl2br($row->question).'</a>';
			echo '</div>';
			echo '<div class="faq_answer" id="faq_answer_'.$row->seq.'">';
			echo nl2br($row->answer);
			echo '</div>';
		endwhile;
	}
	
	function akismet_spam($comment , $func , $key)
	{
		$payload = http_build_query($comment);
		
		switch ($func) :
			case 'verify-key' :
				$call = '1.1/verify-key';
				$payload = "key={$key}&blog={$comment['blog']}";
				break;
			case 'check-spam' :
				$call = '1.1/comment-check';
				break;
			case 'submit-spam' :
				$call = '1.1/submit-spam';
				break;
			case 'submit-ham' :
				$call = '1.1/submit-ham';
				break;
			default:
				return 'Error: Invalid function!';
				break;
		endswitch;
		
		$curl = curl_init("http://{$key}.rest.akismet.com/{$call}");
		curl_setopt($curl, CURLOPT_USERAGENT, "Fuspam/1.3 | Akismet/1.11");
		curl_setopt($curl, CURLOPT_TIMEOUT, 5);
		curl_setopt($curl, CURLOPT_POSTFIELDS, $payload);
		curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
		$i = 0;
		$result = false;
		while (($i < 5) && ($result === false)) :  // retry up to 5 times
			$result = curl_exec($curl);
			if ($result === false) :
				sleep(1);  // wait 1 second before retrying
			endif;
			$i++;
		endwhile;
		
		if ($result === false) :
			$result = "Error: Repeat Failure";
		endif;
			
		return $result;
	}

?>

Youez - 2016 - github.com/yon3zu
LinuXploit