<?php
ob_start();
//phpinfo();
@session_start();
error_reporting(0);
$tmp = dirname(__FILE__);
$tmp = str_replace('\\' ,'/',$tmp);
//$tmp = substr($tmp, 0, strrpos($tmp, '/'));

define('SITE_DIR_PATH', $tmp);
define('SITE_FS_PATH', $tmp);

define('SITE_SUB_PATH', '/homesalon');

//define('SITE_URL_PATH', 'http://'.$_SERVER['HTTP_HOST']);
define('SITE_URL_PATH', 'http://'.$_SERVER['HTTP_HOST'].SITE_SUB_PATH);
define('WEBSITE_NAME', 'Home Salon');
//himanshu@weblinkindia.net
//weblink.saransh@gmail.com
//manish87.jain@gmail.com

//define('ADMINMAIL', 'akayali@uniquegrouphotels.com');
define('ADMINMAIL_CC', 'homesalon.service11@gmail.com');


function send_email($fromPerson, $fromEmail, $to, $subject, $message) {
	$headers = "From: $fromPerson<$fromEmail> \n";
	$headers .= "Reply-To: $fromEmail \r\n";
	$headers .= "X-Mailer: PHP/". phpversion();
	$headers .= "X-Priority: 3 \n";
	$headers .= "MIME-version: 1.0\n";
	$headers .= "Content-Type: text/html; charset=UTF-8\n";
	$msg=$message;
	@mail($to, $subject, $msg, $headers);
}

function dynamic_check_form_values($elements_arr, $validation_arr) {
	$alert_message="";
	$retuned_val="";
	foreach($elements_arr as $key => $val) {
		$expld_name=explode("-",$key);
		$req_prob_st=trim("$expld_name[0]");
		$req_prob_id=trim("$expld_name[1]");
		$alert=trim("$expld_name[2]");
		$val=trim("$val");
		$html_head='<table><tr><td valign="top"><div><div style="color: #ff0000; font: normal 18px Arial, Helvetica, sans-serif; padding: 10px 15px 0px 5px;">ERROR!</div><div style="font:bold 12px arial; padding-left:50px; color:#bf0000;"><ul style="margin:4px; padding:2px;">';
		$html_foot='</ul></div></td></tr></table><br /><br />';

		if(!strlen($val)>0 and ($req_prob_st=="r" or $req_prob_st=="rp")) {
			$alert_message .= "<li style='color:red;'>$alert</li>";
		}
		if(strlen($val)>0 and ($req_prob_st=="p" or $req_prob_st=="rp")) {
   			$exploded_exp=@explode("^~~^", $validation_arr[$req_prob_id]);
   			$allowed_exp="$exploded_exp[0]";
			if (!preg_match("/$allowed_exp/", $val)) {   
				$alert_message .="<li style='color:red;'>$alert, $exploded_exp[1]</li>";
			}
		}
	}
	if(strlen($alert_message)>0) {
		$msg=$alert_message;
		return $msg;
	}
	else {
		return "";
	}
}
function htmFooter() {
	?>
	</body>
	</html>
	<?php
}

	
function html_head(){
	$var='<table width="100%" cellspacing="0" cellpadding="0" border="0"><tr><td valign="top"><div style="color: #ff0000; font: normal 18px Arial, Helvetica, sans-serif; padding: 10px 15px 0px 5px;">ERROR!</div><div style="font:bold 12px arial; padding-left:50px; color:#bf0000;"><ul style="margin:4px; padding:2px;color:red;">';
	return $var;
}


function html_foot(){
	$var='</ul></div></td></tr></table><br />';
	return $var;
}
  

$validation_ans_arr = array(
'1'=> '^([0-9])+$^~~^allowed characters are 0 to 9',
'2'=>'^([a-zA-Z\s])+([\s])*([a-zA-Z\s])*$^~~^allowed characters are a to z',
'3'=>'^([a-zA-Z0-9\s])+$^~~^allowed alphanumeric characters are 0-9, a to z, A -Z',
'4'=>'^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$^~~^allowed format email@website.com', 
'5'=>'^(\+)*([0-9])+([-\/\.])+([0-9])+([-\/\.])+([0-9])+$^~~^allowed format +91-011-21566456', 
'6'=>'^(http):\/\/(www\.)?([a-zA-Z])+\.(com|net|org)$^~~^allowed format http://www.indianyellowpages.com',  
'7'=>'^([0-9])+(\/|-){1}([0-9])+(\/|-)([0-9]){4}$^~~^allowed format  dd/mm/yyyy or dd-mm-yyyy',
'8'=>'^([0-9])+$^~~^allowed characters are 0 to 9',
'9'=>'^([0-9])+(\.)+([0-9])+$^~~^allowed format  7.5',
'10'=>'^([a-zA-Z0-9\s])+([&\-\.])*([a-zA-Z0-9\s])*$^~~^allowed characters are 0 to 9, a to z, dot, &, hiphen',
'11'=>'^([a-zA-Z0-9\s])+([&\-\.,\(\)\/])*([a-zA-Z0-9\s&\-\.,\(\)\/])*^~~^allowed characters are 0 to 9, a to z, &, comma, hiphen, dot, brackets',
'12'=>'^(\+)*([0-9])+([-\/\.])*([0-9])+([-\/\.])*([0-9])+$^~~^allowed characters are 0 to 9, +, /, -',
'13'=>'^(\+)*([0-9])+([-\/])*([0-9])+([-\/])*([0-9])+$^~~^allowed characters are 0 to 9, -, / and format could be +9891854673 or 91-011-9891854673 ',
'14'=>'^([1-9])+([0-9])*$^~~^must be greater than 0',
'15'=>'^([0-9]){2}(:){1}([0-5]){1}([0-9]){1}$^~~^must be in format of 01:20      01(Hours), 20(Minutes and limit is up to 59)',
'16'=>'^([0-9\.])*([0-9])+([0-9\.])*$^~~^allowed characters are 0 to 9',
'17'=>'^([0-9]{1})([0-9]{1})(\/|-{1})([0-9]{1})([0-9]{1})(\/|-{1})([1-9]{1})([0-9]{3})$^~~^allowed format dd-mm-yyyy',
'18'=>'^[0-9A-Za-z\s_ -]+(.[jJ][pP][gG]|.[gG][iI][fF]|.[jJ][pP][eE][gG])$^~~^',
'19'=>'^([0-9]){4}+(\/|-){1}([0-9]){2}+(\/|-)([0-9]){2}$^~~^allowed format  yyyy/mm/dd or yyyy-mm-dd'
);

$productNames=array();
$productNames[0]='PRIMA 6010';
$productNames[1]='PRIMA 6011';
$productNames[2]='PRIMA 6012';
$productNames[3]='PRIMA 6013';
$productNames[4]='PRIMA 6013 S';
$productNames[5]='PRIMA 6013 SS ';
$productNames[6]='PRIMA 7014'; 
$productNames[7]='PRIMA 7024';
$productNames[8]='PRIMA 7016';
$productNames[9]='PRIMA 7018';
$productNames[10]='PRIMA 7018-1';
$productNames[11]='PRIMA 7018-1 H4R';
$productNames[12]='PRIMA 8018 W';
$productNames[13]='PRIMA 11018';
$productNames[14]='PRIMA 7016-A1';
$productNames[15]='PRIMA 7018-A1';
$productNames[16]='PRIMA 8018-B2';
$productNames[17]='PRIMA 8016-C1';
$productNames[18]='PRIMA 8018-C1';
$productNames[19]='PRIMA 8016-C2';
$productNames[20]='PRIMA 8018-C2';
$productNames[20]='PRIMA 8016-C3';
$productNames[22]='PRIMA 8018-C3';
$productNames[23]='STALOY 1A';
$productNames[24]='STALOY 1A(L)';
$productNames[25]='STALOY 2D';
$productNames[26]='STALOY 2D – 15';
$productNames[27]='STALOY 2D – Mo';
$productNames[28]='STALOY CW';
$productNames[29]='STALOY 312';
$productNames[30]='STALOY 2A(L)';
$productNames[31]='STALOY 347 (L)';
$productNames[32]='STALOY 410 – 15';
$productNames[33]='PRIMA CAST ALLOY';
$productNames[34]='PRIMA NIKELOY';
$productNames[35]='PRIMA CAST ALLOY MONEL';
$productNames[35]='PRIMA CAST ALLOY (Non Machine able)';
$productNames[37]='PRIMA ENiCrFe-2';
$productNames[38]='PRIMA ENiCrFe-3';
$productNames[39]='PRIMA HARD - I';
$productNames[40]='PRIMA HARD - II';
$productNames[41]='PRIMA HARD - III';
$productNames[40]='PRIMA HARD - IIILH';
$productNames[43]='PRIMA HARD - V';
$productNames[44]='PRIMA HARD - Mn';
$productNames[45]='PRIMA CUT ALLOY';
$productNames[46]='PRIMA GOUGING';
$productNames[47]='PRIMA BRONZE ALLOY';
$productNames[48]='PRIMA GL';
$productNames[49]='PRIMA 70S2';
$productNames[50]='PRIMA 70S4';
$productNames[51]='PRIMA 70S6';
$productNames[52]='PRIMA 70SG';
$productNames[53]='PRIMA 80SG';
$productNames[54]='PRIMA 308L';
$productNames[55]='PRIMA 309L';
$productNames[56]='PRIMA 310';
$productNames[57]='PRIMA 312';
$productNames[58]='PRIMA 316L';
$productNames[59]='PRIMA 410';
$productNames[60]='PRIMA EL 8';
$productNames[61]='PRIMA EM 12K';


function getExtension($str) {
	$i = strrpos($str,".");
	if (!$i) { return ""; }
	$l = strlen($str) - $i;
	$ext = substr($str,$i+1,$l);
	return $ext;
}


function upload_file($file_name,$image,$folder) {
	 $folder=SITE_DIR_PATH."/".$folder;
	
	if (!file_exists($folder)) {
		mkdir($folder, 0777);
		chmod($folder, 0777);
	}
	if($_FILES[$image]['name']!="") {
		$extension=getExtension($_FILES[$image]['name']);
		$image_name=$file_name.".".$extension;
		$uploadedfile=$_FILES[$image]['tmp_name'];
		$tmp_imagename=$_FILES[$image]['name'];
		if($tmp_imagename<>"" && $uploadedfile<>"" && $image_name<>"") {
			move_uploaded_file($uploadedfile, $folder."/".$image_name);
		}
	}
	return $image_name;
}

function trace()
	{
		list($callee) = debug_backtrace();
		$arguments = func_get_args();
		$total_arguments = count($arguments);

		echo '<fieldset style="background: #fefefe !important; border:3px red solid; padding:5px; font-family:Courier New,Courier, monospace;font-size:12px">';
	    echo '<legend style="background:lightgrey; padding:6px;">'.$callee['file'].' @ line: '.$callee['line'].'</legend><pre>';
	    $i = 0;
	    foreach ($arguments as $argument)
	    {
			echo '<br/><strong>Debug #'.(++$i).' of '.$total_arguments.'</strong>: ';

			if ( (is_array($argument) || is_object($argument)) && count($argument))
			{
				print_r($argument);
			}
			else
			{
				var_dump($argument);
			}
		}

		echo '</pre>' . PHP_EOL;
		echo '</fieldset>' . PHP_EOL;
	
	}