<?php
require_once "check.class.php";
class settings extends check{
	var $vName;
	var $vValue;
	
	var $dblink;
	
	var $adminuser;
	var $adminpassword;
	var $adminmail;
	var $site_normal_url;
	var $site_secure_url;
	var $background_check_amount;
	var $identity_verification_amount;
	var $membership_amount;
       
        var $freemium_period;
	var $featured_amount;
        var $credit_value;
	var $auth_demo;
	var $auth_email;
	var $auth_pass;
	var $auth_txnkey;
	var $auth_loginid;
	var $profile_approval;
	var $nSId;
	var $tellafriendmail;
	var $sitename;
	
	var $mobile_alert;
	var $sms_user;
	var $sms_pass;
	var $sms_api;
	var $bc_user;
	var $bc_password;
	var $bc_account;

	var $authorize_url;

	var $vTitle;
	var $vStatus;

	var $txtMaxImg;
	var $radEmailType;
	var $txtNoRec;
	var $txtImageTypes;
	var $radUPlan;
	var $txtKeyword;
	var $txtDescription;
	var $txtFeatureMessage;
	var $ddlCurrency;
	var $radTestimonial;
	var $ddlStyles;
	var $radGoogleAds;
	var $txtGoogleValue;
	var $radBookmark;
	var $txtBookmarkValue;
	var $radFeed;
        var $radCaptcha;
        var $radSearch;
	var $radAffiliate;
	var $radIdVeryf;
	var $radBChk;
	var $radPayMode;
	var $chkPaypal;
	var $chkSandbox;
	var $txtPaypalEmail;
	var $txtPaypalAuthToken;
	var $chkGoogle;
	var $chkGoogleSandbox;
	var $txtGoogleId;
	var $txtGoogleKey;
	var $ddlPaymentMethod;
	var $txtYourpayStoreId;
	var $txtUrPayDemo;
	var $frmpemyourfile2;
	var $radWorldPayDemo;
	var $txtWorldpayInstId;
	var $txtWorldpayEmail;
	var $radWTransactMethod;
	var $ddlValDaysMem;
        var $radPushNotify;
        var $iPhone_parse_phrase;

	function __construct ($db)
	{
		$this->dblink	= $db;
	}
	
	function set_values($arr=array())
	{ 
                $this->adminuser					= isset($arr['adminuser'])						?	stripslashes(trim($arr['adminuser']))						:	"";
		$this->adminpassword				= isset($arr['adminpassword'])					?	stripslashes(trim($arr['adminpassword']))					:	"";
		$this->adminmail					= isset($arr['adminmail'])						?	stripslashes(trim($arr['adminmail']))						:	"";
		$this->site_normal_url				= isset($arr['site_normal_url'])				?	stripslashes(trim($arr['site_normal_url']))					:	"";
		$this->site_secure_url				= isset($arr['site_secure_url'])				?	stripslashes(trim($arr['site_secure_url']))					:	"";
		$this->background_check_amount		= isset($arr['background_check_amount'])		?	stripslashes(trim($arr['background_check_amount']))			:	"";
                $this->propay_demo					= isset($arr['propay_demo'])					?	stripslashes(trim($arr['propay_demo']))						:	"";
		$this->propay_billerid				= isset($arr['propay_billerid'])				?	stripslashes(trim($arr['propay_billerid']))						:	"";
                $this->propay_token					= isset($arr['propay_token'])					?	stripslashes(trim($arr['propay_token']))					:	"";
		$this->identity_verification_amount	= isset($arr['identity_verification_amount'])	?	stripslashes(trim($arr['identity_verification_amount']))	:	"";
		$this->membership_amount			= isset($arr['membership_amount'])				?	stripslashes(trim($arr['membership_amount']))				:	"";
		$this->freemium_period			= isset($arr['freemium_period'])				?	stripslashes(trim($arr['freemium_period']))				:	"";
                $this->featured_amount				= isset($arr['featured_amount'])				?	stripslashes(trim($arr['featured_amount']))					:	"";
		$this->credit_value				= isset($arr['credit_value'])				?	stripslashes(trim($arr['credit_value']))					:	"";
                $this->auth_demo					= isset($arr['auth_demo'])						?	stripslashes(trim($arr['auth_demo']))						:	"YES";
		$this->auth_email					= isset($arr['auth_email'])						?	stripslashes(trim($arr['auth_email']))						:	"";
		$this->auth_pass					= isset($arr['auth_pass'])						?	stripslashes(trim($arr['auth_pass']))						:	"";
		$this->auth_txnkey					= isset($arr['auth_txnkey'])					?	stripslashes(trim($arr['auth_txnkey']))						:	"";
		$this->auth_loginid					= isset($arr['auth_loginid'])					?	stripslashes(trim($arr['auth_loginid']))					:	"";
		$this->profile_approval				= isset($arr['profile_approval'])				?	stripslashes(trim($arr['profile_approval']))				:	"";
		$this->nSId							= isset($arr['nSId'])							?	stripslashes(trim($arr['nSId']))							:	"1";
		$this->tellafriendmail				= isset($arr['tellafriendmail'])				?	stripslashes(trim($arr['tellafriendmail']))					:	"";
		$this->licensekey					= isset($arr['vLicenceKey'])					?	stripslashes(trim($arr['vLicenceKey']))						:	"";
		$this->sitename						= isset($arr['sitename'])						?	stripslashes(trim($arr['sitename']))						:	"";
		$this->mobile_alert					= isset($arr['mobile_alert'])					?	stripslashes(trim($arr['mobile_alert']))					:	"NO";
		$this->sms_user						= isset($arr['sms_user'])						?	stripslashes(trim($arr['sms_user']))						:	"";
		$this->sms_pass						= isset($arr['sms_pass'])						?	stripslashes(trim($arr['sms_pass']))						:	"";
		$this->sms_api						= isset($arr['sms_api'])						?	stripslashes(trim($arr['sms_api']))							:	"";
		$this->bc_user						= isset($arr['bc_user'])						?	stripslashes(trim($arr['bc_user']))							:	"";
		$this->bc_password					= isset($arr['bc_password'])					?	stripslashes(trim($arr['bc_password']))						:	"";
		$this->bc_account					= isset($arr['bc_account'])						?	stripslashes(trim($arr['bc_account']))						:	"";
		$this->txtMaxImg					= isset($arr['txtMaxImg'])						?	stripslashes(trim($arr['txtMaxImg']))						:	"";
		$this->radEmailType					= isset($arr['radEmailType'])					?	stripslashes(trim($arr['radEmailType']))					:	"";
		$this->txtNoRec					    = isset($arr['txtNoRec'])					    ?	stripslashes(trim($arr['txtNoRec']))						:	"";
		$this->txtImageTypes			    = isset($arr['txtImageTypes'])					?	stripslashes(trim($arr['txtImageTypes']))					:	"";
		$this->radUPlan			            = isset($arr['radUPlan'])					    ?	stripslashes(trim($arr['radUPlan']))						:	"";
		$this->txtKeyword			        = isset($arr['txtKeyword'])					    ?	stripslashes(trim($arr['txtKeyword']))						:	"";
		$this->txtRecaptchaPublicKey			    = isset($arr['txtRecaptchaPublicKey'])					?	stripslashes(trim($arr['txtRecaptchaPublicKey']))					:	"";
                $this->txtRecaptchaPrivateKey			    = isset($arr['txtRecaptchaPrivateKey'])					?	stripslashes(trim($arr['txtRecaptchaPrivateKey']))					:	"";
		$this->radPushNotify					= isset($arr['radPushNotify'])					?	stripslashes(trim($arr['radPushNotify']))					:	"N";
		$this->iPhone_parse_phrase				= isset($arr['iPhone_parse_phrase'])				?	stripslashes(trim($arr['iPhone_parse_phrase']))					:	"";
		$this->txtFeatureMessage		   = isset($arr['txtFeatureMessage'])				?	stripslashes(trim($arr['txtFeatureMessage']))				:	"";
		
		$this->ddlCurrency			        = isset($arr['ddlCurrency'])					?	stripslashes(trim($arr['ddlCurrency']))						:	"";
		$this->radTestimonial			    = isset($arr['radTestimonial'])					?	stripslashes(trim($arr['radTestimonial']))					:	"";
		$this->ddlStyles			        = isset($arr['ddlStyles'])					    ?	stripslashes(trim($arr['ddlStyles']))						:	"";
		$this->radGoogleAds			        = isset($arr['radGoogleAds'])					?	stripslashes(trim($arr['radGoogleAds']))					:	"";
		$this->txtGoogleValue			    = isset($arr['txtGoogleValue'])					?	stripslashes(trim($arr['txtGoogleValue']))					:	"";
		$this->radBookmark			        = isset($arr['radBookmark'])					?	stripslashes(trim($arr['radBookmark']))						:	"";
		$this->txtBookmarkValue			    = isset($arr['txtBookmarkValue'])			    ?	stripslashes(trim($arr['txtBookmarkValue']))				:	"";
		$this->radFeed			            = isset($arr['radFeed'])			            ?	stripslashes(trim($arr['radFeed']))							:	"";
                $this->enable_same_sex_search			            = isset($arr['enable_same_sex_search'])			            ?	stripslashes(trim($arr['enable_same_sex_search']))							:	"";
                $this->facebook_app_id			            = isset($arr['facebook_app_id'])			            ?	stripslashes(trim($arr['facebook_app_id']))							:	"";
                $this->facebook_secret_id			            = isset($arr['facebook_secret_id'])			            ?	stripslashes(trim($arr['facebook_secret_id']))							:	"";
                $this->radCaptcha			            = isset($arr['radCaptcha'])			            ?	stripslashes(trim($arr['radCaptcha']))							:	"";
                $this->radSearch			            = isset($arr['radSearch'])			            ?	stripslashes(trim($arr['radSearch']))							:	"";
		$this->radAffiliate			        = isset($arr['radAffiliate'])			        ?	stripslashes(trim($arr['radAffiliate']))					:	"";
		$this->radIdVeryf			        = isset($arr['radIdVeryf'])			            ?	stripslashes(trim($arr['radIdVeryf']))						:	"";
		$this->radBChk			            = isset($arr['radBChk'])			            ?	stripslashes(trim($arr['radBChk']))							:	"";
		$this->radPayMode			        = isset($arr['radPayMode'])			            ?	stripslashes(trim($arr['radPayMode']))						:	"";
		$this->chkPaypal			        = isset($arr['chkPaypal'])			            ?	stripslashes(trim($arr['chkPaypal']))						:	"";
		$this->chkSandbox			        = isset($arr['chkSandbox'])			            ?	stripslashes(trim($arr['chkSandbox']))						:	"";
		$this->txtPaypalEmail			    = isset($arr['txtPaypalEmail'])			        ?	stripslashes(trim($arr['txtPaypalEmail']))					:	"";
		$this->txtPaypalAuthToken			= isset($arr['txtPaypalAuthToken'])			    ?	stripslashes(trim($arr['txtPaypalAuthToken']))				:	"";
		$this->chkGoogle			        = isset($arr['chkGoogle'])			            ?	stripslashes(trim($arr['chkGoogle']))						:	"";
		$this->chkGoogleSandbox			    = isset($arr['chkGoogleSandbox'])			    ?	stripslashes(trim($arr['chkGoogleSandbox']))				:	"";
		$this->txtGoogleId			        = isset($arr['txtGoogleId'])			        ?	stripslashes(trim($arr['txtGoogleId']))						:	"";
		$this->txtGoogleKey			        = isset($arr['txtGoogleKey'])			        ?	stripslashes(trim($arr['txtGoogleKey']))					:	"";
		$this->ddlPaymentMethod			    = isset($arr['ddlPaymentMethod'])			    ?	stripslashes(trim($arr['ddlPaymentMethod']))				:	"";
		$this->txtYourpayStoreId			= isset($arr['txtYourpayStoreId'])			    ?	stripslashes(trim($arr['txtYourpayStoreId']))				:	"";
		$this->txtUrPayDemo			        = isset($arr['txtUrPayDemo'])			        ?	stripslashes(trim($arr['txtUrPayDemo']))					:	"";
		$this->frmpemyourfile2			    = isset($arr['frmpemyourfile2'])			    ?	stripslashes(trim($arr['frmpemyourfile2']))					:	"";
		$this->radWorldPayDemo			    = isset($arr['radWorldPayDemo'])			    ?	stripslashes(trim($arr['radWorldPayDemo']))					:	"";
		$this->txtWorldpayInstId			= isset($arr['txtWorldpayInstId'])			    ?	stripslashes(trim($arr['txtWorldpayInstId']))				:	"";
		$this->txtWorldpayEmail			    = isset($arr['txtWorldpayEmail'])			    ?	stripslashes(trim($arr['txtWorldpayEmail']))				:	"";
		$this->radWTransactMethod			= isset($arr['radWTransactMethod'])			    ?	stripslashes(trim($arr['radWTransactMethod']))				:	"";
		$this->ddlValDaysMem				= isset($arr['ddlValDaysMem'])			    	?	stripslashes(trim($arr['ddlValDaysMem']))					:	"";
                $this->ValidityDayMembership				= isset($arr['ValidityDayMembership'])			    	?	stripslashes(trim($arr['ValidityDayMembership']))					:	"";
                
	}
	
	function set_variables()
	{
		$array	= $this->select();
		$this->set_values($array);
		if ($this->auth_demo == "YES")
			$this->authorize_url	= "https://test.authorize.net/gateway/transact.dll";
		else
			$this->authorize_url	= "https://secure.authorize.net/gateway/transact.dll";
	}

	public function set_authorize_url($flag=true)
	{
		if (!$flag)
			$this->authorize_url	= "https://test.authorize.net/gateway/transact.dll";
		else
			$this->authorize_url	= "https://secure.authorize.net/gateway/transact.dll";
			
			
	}

	public function get_authorize_url()
	{
		return $this->authorize_url;
	}

	function select()
	{
		$array	= array();
		$sql	= "SELECT * FROM ".TABLEPREFIX."lookup";
		$res	= @mysql_query($sql, $this->dblink);
		if (@mysql_num_rows($res) > 0) {
			while ($row = @mysql_fetch_array($res)) {
				$array[$row['vName']]	= $row['vValue'];
			}
		}
		@mysql_free_result($res);
		if(ISCRIPTSCLOUD)
		{
			
			if (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off'|| $_SERVER['SERVER_PORT'] == 443) 
				{
                     $array['site_secure_url']="https://".$_SERVER['HTTP_HOST'];
                     $array['site_normal_url']="https://".$_SERVER['HTTP_HOST'];
				}
			else
				{
					$array['site_secure_url']="http://".$_SERVER['HTTP_HOST'];
                    $array['site_normal_url']="http://".$_SERVER['HTTP_HOST'];
				}
		}
		
		return $array;
	}
	
	public function getone($name="tellafriendmail")
	{
		$string	= "";
		$con=mysqli_connect(DB_HOST,DB_USER,DB_PASSWORD,DB_DATABASE);
		
		$sql	= "SELECT * FROM ".TABLEPREFIX."lookup WHERE vName = '{$name}'";
		$res	= mysqli_query($con,$sql);

		while ($array = mysqli_fetch_array($res))  
       	{
         
            $string = $array['vValue'];
        }
        mysqli_close($con);
        
		if(ISCRIPTSCLOUD)
		{
			if($name==="site_normal_url" || $name==="site_secure_url")
				{
					if (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off'|| $_SERVER['SERVER_PORT'] == 443)
					{
						$string="https://".$_SERVER['HTTP_HOST'];
						
					}
					else
					{
						$string="http://".$_SERVER['HTTP_HOST'];
					}
				}
			
		}
		
		return $string;
	}

	function login($fromcloud=false)
	{
		$msg	= "";
		$sql	= "SELECT * FROM ".TABLEPREFIX."lookup
				   WHERE vName LIKE 'adminuser' AND vValue LIKE '".addslashes($this->adminuser)."'";
		$res	= @mysql_query($sql, $this->dblink);
		if (@mysql_num_rows($res) <= 0) {
			$msg	= "Incorrect username.<br>";
		}
		$sql	= "SELECT * FROM ".TABLEPREFIX."lookup
				   WHERE vName LIKE 'adminpassword' AND vValue LIKE '".addslashes(md5($this->adminpassword))."'";
		$res	= @mysql_query($sql, $this->dblink);
		if (@mysql_num_rows($res) <= 0) {
			$msg	.= "Incorrect password.<br>";
		}
		if ($msg == "" || $fromcloud) {
			$_SESSION['adminlogged']  = "YES";
		}
		return $msg;
	}
	
	function update($name='adminuser', $value='value', $pflag="0")
	{
		if ($pflag)
			$value	= md5($value);
		$sql	= "UPDATE ".TABLEPREFIX."lookup
				   SET vValue = '".addslashes($value)."'
				   WHERE vName = '{$name}'";
		$res	= @mysql_query($sql, $this->dblink);
	}
	
	function configure()
	{
		$message= $this->check();
		if ($message == "") {
			$this->update('site_normal_url', $this->site_normal_url);
			$this->update('site_secure_url', $this->site_secure_url);
			if($this->radIdVeryf=='Yes')
			{
				$this->update('identity_verification_amount', $this->identity_verification_amount);
			}//end if
			$this->update('featured_amount', $this->featured_amount);
                        $this->update('credit_value', $this->credit_value);
			$this->update('profile_approval', $this->profile_approval);
			$this->update('nSId', $this->nSId);
			$this->update('sitename', $this->sitename);
                        $this->update('enable_pushbk_notification', $this->radPushNotify); 
                        $this->update('iPhone_parse_phrase', $this->iPhone_parse_phrase);
			$this->update('mobile_alert', $this->mobile_alert);
			$this->update('sms_user', $this->sms_user);
			$this->update('sms_pass', $this->sms_pass);
			$this->update('sms_api', $this->sms_api);
			if($_FILES['userfile']['name']!='')
			{
				$logoName = $_FILES['userfile']['name'];
				$logoName=str_replace("'",'_',$logoName);
				$logoName=str_replace(" ",'_',$logoName);

				$this->update('sitelogo', $logoName);
			}//end if
			$this->update('maximgupload', $this->txtMaxImg);
			$this->update('emailtype', $this->radEmailType);
			$this->update('numberofrecords', $this->txtNoRec);
			$this->update('allowedimagetypes', $this->txtImageTypes);
			$this->update('userplans', $this->radUPlan);
			$this->update('metatagKey', $this->txtKeyword);
			$this->update('metatagDes', $this->txtDescription);
			$this->update('recaptcha_public_key', $this->txtRecaptchaPublicKey);
                        $this->update('recaptcha_private_key', $this->txtRecaptchaPrivateKey);
			$this->update('profFeatureText', $this->txtFeatureMessage);
			
			$this->update('currencycode', $this->ddlCurrency);
			$this->update('currency', $this->CurrencyCodeCheck($this->ddlCurrency));
			$this->update('testimonialmode', $this->radTestimonial);
			$this->update('styles', $this->ddlStyles);
			$this->update('googleaddemo', $this->radGoogleAds);
			$this->update('googleadvalue', $this->txtGoogleValue);
			$this->update('bookmark_enable', $this->radBookmark);
			$this->update('bookmark_value', $this->txtBookmarkValue);
			$this->update('userfeed', $this->radFeed);
                        $this->update('enable_same_sex_search', $this->enable_same_sex_search);
                        $this->update('facebook_app_id', $this->facebook_app_id);
                        $this->update('facebook_secret_id', $this->facebook_secret_id);
                        $this->update('enable_captcha', $this->radCaptcha);
                        $this->update('enable_user_search', $this->radSearch);
			$this->update('affiliates', $this->radAffiliate);
			$this->update('id_veryfy', $this->radIdVeryf);
			$this->update('bcheck', $this->radBChk);
			$message='<font color="green">Settings updated successfully</font>';
		}
		return $message;
	}
	
	//for admin profile
	function configure2()
	{
		$message= $this->check2();
		if ($message == "") 
		{
			$this->update('adminuser', $this->adminuser);
			if($this->adminpassword!='')
			{
				$this->update('adminpassword', $this->adminpassword,true);
			}//end if
			$this->update('adminmail', $this->adminmail);
			$message='<font color="green">Settings updated successfully</font>';
		}
		return $message;
	}

	function configure3()
	{
		$message= $this->check3();
		if ($message == "") {
			$this->update('membership_amount', $this->membership_amount);
                        $this->update('freemium_period', $this->freemium_period);
			$this->update('regmode', $this->radPayMode);
			$this->update('ValidityDayMembership', $this->ddlValDaysMem);
			$message='<font color="green">Settings updated successfully</font>';
		}
		return $message;
	}

	function configure4()
	{
		$message= $this->check4();
		if ($message == "") 
		{

			//enable/disable paypal
			if ($this->chkPaypal) 
			{
				$this->chkPaypal = "Y";
			}//end if
			else 
			{
				$this->chkPaypal = "N";
			}//end else
			
			//enable/disable live/test mode
			if ($this->chkSandbox) 
			{
				$this->chkSandbox = "N";
			}//end if
			else 
			{
				$this->chkSandbox = "Y";
			}//end else


			//google enable
			if ($this->chkGoogle) 
			{
				$this->chkGoogle = "Y";
			}//end if 
			else 
			{
				$this->chkGoogle = "N";
			}//end else
			
			//google sandbox
			if ($this->chkGoogleSandbox) 
			{
				$this->chkGoogleSandbox = "NO";
			}//end if 
			else 
			{
				$this->chkGoogleSandbox = "YES";
			}//end else

			//for yourpay demo
			if ($this->txtUrPayDemo) 
			{
				$this->txtUrPayDemo = "NO";
			}//end if 
			else 
			{
				$this->txtUrPayDemo = "YES";
			}//end else

			//for worldpay demo
			if ($this->radWorldPayDemo) 
			{
				$this->radWorldPayDemo = "NO";
			}//end if 
			else 
			{
				$this->radWorldPayDemo = "YES";
			}//end else

			$this->update('enablepaypal', $this->chkPaypal);
			$this->update('enablepaypalsandbox', $this->chkSandbox);
			$this->update('paypalemail', $this->txtPaypalEmail);
			$this->update('paypalauthtokenid', $this->txtPaypalAuthToken);
			$this->update('enablegoogle', $this->chkGoogle);
			$this->update('enablegooglesandbox', $this->chkGoogleSandbox);
			$this->update('googleid', $this->txtGoogleId);
			$this->update('googlekey', $this->txtGoogleKey);

			if($this->ddlPaymentMethod=='CC')
			{
				$this->update('auth_demo', $this->auth_demo);
				$this->update('auth_email', $this->auth_email);
				$this->update('auth_pass', $this->auth_pass);
				$this->update('auth_txnkey', $this->auth_txnkey);
				$this->update('auth_loginid', $this->auth_loginid);
			}//end if
                        if($this->ddlPaymentMethod=='PRO')
			{
				$this->update('propay_demo', $this->propay_demo);
				$this->update('propay_token', $this->propay_token);
				$this->update('propay_billerid', $this->propay_billerid);
				//$this->update('auth_txnkey', $this->auth_txnkey);
				//$this->update('auth_loginid', $this->auth_loginid);
			}

			//your pay pem file
			if($_FILES['frmpemyourfile']['name']!='')
			{
				$this->frmpemyourfile2=$_FILES['frmpemyourfile']['name'];
			}//end if
			else
			{
				$this->frmpemyourfile2=$this->frmpemyourfile2;
			}//end else

			$this->update('paymentmethod', $this->ddlPaymentMethod);
			$this->update('urpaystoreid', $this->txtYourpayStoreId);
			$this->update('urpaydemo', $this->txtUrPayDemo);
			$this->update('pemfolder', $this->frmpemyourfile2);

			$this->update('worldpaydemo', $this->radWorldPayDemo);
			$this->update('worldpayid', $this->txtWorldpayInstId);
			$this->update('worldpayemail', $this->txtWorldpayEmail);
			$this->update('worldpaytransmode', $this->radWTransactMethod);
			$message='<font color="green">Settings updated successfully</font>';
		}
		return $message;
	}
	function configure5()
	{
		$message= $this->check5();
		if ($message == "") {
			$this->update('tellafriendmail', $this->tellafriendmail);
			$message='<font color="green">Settings updated successfully</font>';
		}
		return $message;
	}

	function configure7()
	{
		$message= $this->check7();
		if ($message == "") {
			$this->update('background_check_amount', $this->background_check_amount);
			$this->update('bc_user', $this->bc_user);
			$this->update('bc_password', $this->bc_password);
			$this->update('bc_account', $this->bc_account);
			$message='<font color="green">Settings updated successfully</font>';
		}
		return $message;
	}

	function configure8()
	{
		$message= '';
		if ($message == "") 
		{
			$this->update_rows(TABLEPREFIX.'SignUpField',"vActive='0'",'');
			foreach ($_POST['chkSteps'] as $val)
			{
				$this->update_rows(TABLEPREFIX.'SignUpField',"vActive='1'","where nSId='".$val."'");
			}//end foreach
			$message='<font color="green">Updated successfully</font>';
		}//end if
		return $message;
	}//end fucntion

	function check()
	{
		$message	= "";
		if ($this->sitename == "")
			$message	.= "Please enter name of the site.<br>";
		if ($this->site_normal_url == "")
			$message	.= "Please enter the url of the site.<br>";
		if ($this->site_secure_url == "")
			$message	.= "Please enter the secure url of the site.<br>";
		if($this->radIdVeryf=='Yes')
		{
			if ($this->identity_verification_amount == "")
				$message	.= "Please enter amount for the identity verification.<br>";
			if (!$this->check_amount($this->identity_verification_amount))
				$message	.= "Please enter valid amount for the identity verification.<br>";
		}//end if
		if ($this->featured_amount == "")
			$message	.= "Please enter amount for the featured membership.<br>";
                if ($this->credit_value == "")
			$message	.= "Please enter a valid credit value.<br>";
		if (!$this->check_amount($this->featured_amount))
			$message	.= "Please enter valid amount for the featured membership.<br>";
		if ($this->profile_approval == "")
			$message	.= "Please select any of the method for profile approval.<br>";
		if ($this->nSId == "")
			$message	.= "Please select any of the style for the site.<br>";
		if ($this->mobile_alert == "YES") {
			if ($this->sms_user == "")
				$message	.= "Please enter username of sms gateway account.<br>";
			if ($this->sms_pass == "")
				$message	.= "Please enter password of sms gateway account.<br>";
			if ($this->sms_api == "")
				$message	.= "Please enter API ID of HTTP(S) connection of sms gateway account.<br>";
		}
		return $message;			
	}

	function check2()
	{
		$message	= "";
		if ($this->adminuser == "")
			$message	.= "Please enter the username of the administrator.<br>";
		if ($this->adminmail == "")
			$message	.= "Please enter the mail for the administrator.<br>";
		if (!$this->check_email($this->adminmail))
			$message	.= "The address ".$this->adminmail." is not valid.<br>";
		return $message;			
	}

	function check3()
	{
		$message	= "";
		if ($this->membership_amount == "")
			$message	.= "Please enter amount for the membership.<br>";
		if (!$this->check_amount($this->membership_amount))
			$message	.= "Please enter valid amount for the membership.<br>";
                if($this->radPayMode==REGISTRATION_FREEMIUM_MODE)
                {                    
                    if (!$this->check_amount($this->freemium_period))
                    $message	.= "Please enter freemium period.<br>";
                }
		return $message;			
	}

	function check4()
	{
		$message	= "";
		
		//for paypal
		if($this->chkPaypal=='Y')
		{
			if ($this->txtPaypalEmail == "")
				$message	.= "Please enter mail address of paypal account.<br>";
			if (!$this->check_email($this->txtPaypalEmail))
				$message	.= "The address ".$this->txtPaypalEmail." is not valid.<br>";
			
			if ($this->txtPaypalAuthToken == "")
				$message	.= "Please enter identity token of paypal account.<br>";
		}//end if
		
		//for google checkout
		if($this->enablegoogle=='Y')
		{
			if ($this->txtGoogleId == "")
				$message	.= "Please enter merchant ID of google account.<br>";
			if ($this->txtGoogleKey == "")
				$message	.= "Please enter merchant key of google account.<br>";
		}//end if

		//for authorize.net
		if($this->ddlPaymentMethod=='CC')
		{
			if ($this->auth_email == "")
				$message	.= "Please enter mail address of authorize account.<br>";
			if (!$this->check_email($this->auth_email))
				$message	.= "The address ".$this->auth_email." is not valid.<br>";
			
			if ($this->auth_txnkey == "")
				$message	.= "Please enter transaction key of authorize account.<br>";
			if ($this->auth_loginid == "")
				$message	.= "Please enter login id of authorize account.<br>";
		}//end if

		return $message;			
	}

	function check5()
	{
		$message	= "";
		if ($this->tellafriendmail == "")
			$message	.= "Please enter template of Tell A Friend Mail content for the site.<br>";
		if (strpos($this->tellafriendmail, "{TONAME}") === false)
			$message	.= "Template should contain the text <b>{TONAME}</b>, which is used to replace with reciever's name.<br>";
		if (strpos($this->tellafriendmail, "{FROMNAME}") === false)
			$message	.= "Template should contain the text <b>{FROMNAME}</b>, which is used to replace with sender's name.<br>";
		return $message;			
	}

	function check7()
	{
		$message	= "";
                if ($this->background_check_amount == "")
			$message	.= "Please enter amount for the background checking.<br>";
		if (!$this->check_amount($this->background_check_amount))
			$message	.= "Please enter valid amount for the background checking.<br>";
		if ($this->bc_user == "")
			$message	.= "Please enter username of backgroundcheck account.<br>";
		if ($this->bc_password == "")
			$message	.= "Please enter password of backgroundcheck account.<br>";
		if ($this->bc_account == "")
			$message	.= "Please enter account number of background account.<br>";
		return $message;			
	}

	function clear_chat_table()
	{
		$date	= date("Y-m-d");
/*		$array	= array();
		$sql	= "SELECT * FROM ".TABLEPREFIX."chats
				   WHERE dDate >= '{$date}' OR vStatus LIKE 'N'";
		$res	= @mysql_query($sql, $this->dblink);
		if (@mysql_num_rows($res) > 0) {
			while($row=@mysql_fetch_array($res)) {
				$array[]	= $row;
			}
		}

		$sql	= "TRUNCATE TABLE ".TABLEPREFIX."chats";
		$res	= @mysql_query($sql, $this->dblink);

		if (!empty($array)) {
			foreach ($array as $key => $value) {
				$sql	= "INSERT INTO ".TABLEPREFIX."chats (nUser_Id_To, nUser_Id_From,
								  tMessage, tTimeOf, vStatus, dDate)
						   VALUES ('".$value['nUser_Id_To']."', '".$value['nUser_Id_From']."',
								   '".$value['tMessage']."', '".$value['tTimeOf']."',
								   '".$value['vStatus']."', '".$value['dDate']."')";
				$res	= @mysql_query($sql, $this->dblink);
			}
		}
*/
// CHAT TABLE
		$sql	= "INSERT INTO ".TABLEPREFIX."chats_back (nUser_Id_To, nUser_Id_From,
								tMessage, tTimeOf, vStatus, dDate)
				   SELECT nUser_Id_To, nUser_Id_From,tMessage,
				          tTimeOf, vStatus, dDate
				  FROM ".TABLEPREFIX."chats
				  WHERE dDate >= '{$date}' OR vStatus LIKE 'N'";
		$res	= @mysql_query($sql, $this->dblink);

		$sql	= "TRUNCATE TABLE ".TABLEPREFIX."chats";
		$res	= @mysql_query($sql, $this->dblink);

		$sql	= "INSERT INTO ".TABLEPREFIX."chats (nUser_Id_To, nUser_Id_From,
								tMessage, tTimeOf, vStatus, dDate)
				   SELECT nUser_Id_To, nUser_Id_From,tMessage,
				          tTimeOf, vStatus, dDate
				  FROM ".TABLEPREFIX."chats_back";
		$res	= @mysql_query($sql, $this->dblink);

		$sql	= "TRUNCATE TABLE ".TABLEPREFIX."chats_back";
		$res	= @mysql_query($sql, $this->dblink);

// IM FRIENDS TABLE
		$sql	= "INSERT INTO ".TABLEPREFIX."imfriends_back (nUser_Id, nUser_Id_Friend,
								vLogin_Friend, vName_Friend, vStatus)
				   SELECT nUser_Id, nUser_Id_Friend, vLogin_Friend,
						  vName_Friend, vStatus
				  FROM ".TABLEPREFIX."imfriends
				  WHERE vStatus NOT LIKE 'R%'";
		$res	= @mysql_query($sql, $this->dblink);

		$sql	= "TRUNCATE TABLE ".TABLEPREFIX."imfriends";
		$res	= @mysql_query($sql, $this->dblink);

		$sql	= "INSERT INTO ".TABLEPREFIX."imfriends (nUser_Id, nUser_Id_Friend,
								vLogin_Friend, vName_Friend, vStatus)
				   SELECT nUser_Id, nUser_Id_Friend, vLogin_Friend,
						  vName_Friend, vStatus
				  FROM ".TABLEPREFIX."imfriends_back";
		$res	= @mysql_query($sql, $this->dblink);

		$sql	= "TRUNCATE TABLE ".TABLEPREFIX."imfriends_back";
		$res	= @mysql_query($sql, $this->dblink);

	}

	function isValidWebImageType($mimetype)
	{
		if(($mimetype=="image/pjpeg") || ($mimetype=="image/jpeg") || ($mimetype=="image/x-png")|| ($mimetype=="image/png")|| ($mimetype=="image/gif")|| 
			($mimetype=="image/x-windows-bmp")|| ($mimetype=="image/bmp") )
		{
			return true;
		}//end if
		else
		{
			return false;
		}//end else
	}//end function
        function isValid($var_domain,$table){
                if($this->checkChars($var_domain))
                        return true;
                $var_domain		=	$this->getDomain($var_domain);
                $var_licencekey = 	$this->getLicense($table);

                $first_domain 	= 	substr($var_domain, 0, 3);
                $last_domain 	= 	substr($var_domain, -3,3);

                $var_first		= 	substr($var_licencekey, 0, 3);
                $var_lic_first	= 	substr($var_licencekey, 3, 3);
                $var_lic_last 	= 	substr($var_licencekey, -3,3);

                $var_lic_first	=	$this->asc_shift($var_lic_first, 3);
                $var_lic_last	=	$this->asc_shift($var_lic_last, 3);

                $alphabet_array 	= array('A' => 1, 'B' => 2, 'C' => 3, 'D' => 4, 'E' => 5, 'F' => 6,
                                                                        'G' => 7, 'H' => 8, 'I' => 9, 'J' => 10,'K' => 11,'L' => 12,
                                                                        'M' => 13,'N' => 14,'O' => 15,'P' => 16,'Q' => 17,'R' => 18,
                                                                        'S' => 19,'T' => 20,'U' => 21,'V' => 22,'W' => 23,'X' => 24,
                                                                        'Y' => 25,'Z' => 26,'1' => 1, '2' => 2, '3' => 3, '4' => 4,
                                                                        '5' => 5, '6' => 6, '7' => 7, '8' => 8, '9' => 9);
                $j = mb_strlen($var_domain);
                $var_char_sum	=	0;
                for ($k = 0; $k < $j; $k++) {
                        $char = mb_substr($var_domain, $k, 1);
                        $var_char_sum	= $var_char_sum	+ $alphabet_array[$char];
                }
                if($var_char_sum != ($var_first - 23))
                        return false;
                else if(strcmp($first_domain,$var_lic_first) != 0)
                        return false;
                else if(strcmp($last_domain,$var_lic_last) != 0)
                        return false;
                else
                        return true;
        }
        function checkChars($domainName){
			if (preg_match("/^[0-9].+$/", $domainName)){
				return true;
			}else
				return false;
		}
        function getDomain($var_domain){
			preg_match("/^(http:\/\/)?([^\/]+)/i",$var_domain, $matches);
			$host = $matches[2];
			$var_dotexist	= 0;
			$j = mb_strlen($host);
			for ($k = 0; $k < $j; $k++) {
				$char = mb_substr($host, $k, 1);
				if($char == ".")
					$var_dotexist	=	$var_dotexist + 1;
			}
			$var_dot_count	=	explode('.',$host);
		
			if(count($var_dot_count) == 1){
				$var_org_domain	=	$host;
			}else if((count($var_dot_count) > 1) && (mb_strlen(substr($var_dot_count[count($var_dot_count)-2],0,38)) > 2)){
				preg_match("/[^\.\/]+\.[^\.\/]+$/", $host, $matches);
				$var_org_domain	=	$matches[0];
			}else{
				preg_match("/[^\.\/]+\.[^\.\/]+\.[^\.\/]+$/", $host, $matches);
				$var_org_domain	=	$matches[0];
			}
			$var_final_domain	=	explode('.',$var_org_domain);
			$main_domain 		=	strtoupper(trim($var_final_domain[0]));
			
			return $main_domain;
		}

	function ResizeImageTogivenWitdhAndHeight($file, $img_height, $img_width, $tosavefileas = null)
	{
		if (!isset($tosavefileas)) {
			$tosavefileas = $file;
		} 
	
		$img_temp = $this->NewimageCreatefromtype($file);
		$black = @imagecolorallocate ($img_temp, 0, 0, 0);
		$white = @imagecolorallocate ($img_temp, 255, 255, 255);
		$font = 2;
		$cuurentimagewidth = @imagesx($img_temp);
		$cuurentimageheight = @imagesy($img_temp);
	    $img_height = ($cuurentimageheight / $cuurentimagewidth) * $img_width;
		list($originalwidth, $originalheight, $originaltype) = getimagesize($file);
		if ($originaltype == "1") { // gif
			$newwidth = $img_width;
			$newheight = $img_height;
			$tpcolor = imagecolorat($img_temp, 0, 0); 
			// in the real world, you'd better test all four corners, not just one!
			$img_thumb = imagecreate($newwidth, $newheight); 
			// $dest automatically has a black fill...
			imagepalettecopy($img_thumb, $img_temp);
			imagecopyresized($img_thumb, $img_temp, 0, 0, 0, 0, $newwidth, $newheight,
				@imagesx ($img_temp), @imagesy($img_temp));
			$pixel_over_black = imagecolorat($img_thumb, 0, 0); 
			// ...but now make the fill white...
			$bg = imagecolorallocate($img_thumb, 255, 255, 255);
			imagefilledrectangle($img_thumb, 0, 0, $newwidth, $newheight, $bg);
			imagecopyresized($img_thumb, $img_temp, 0, 0, 0, 0, $newwidth, $newheight,
				@imagesx ($img_temp), @imagesy($img_temp));
			$pixel_over_white = imagecolorat($img_thumb, 0, 0); 
			// ...to test if transparency causes the fill color to show through:
			if ($pixel_over_black != $pixel_over_white) {
				// Background IS transparent
				imagefilledrectangle($img_thumb, 0, 0, $newwidth, $newheight,
					$tpcolor);
				imagecopyresized($img_thumb, $img_temp, 0, 0, 0, 0, $newwidth,
					$newheight, @imagesx ($img_temp), @imagesy($img_temp));
				imagecolortransparent($img_thumb, $tpcolor);
				imagegif($img_thumb, $tosavefileas);
			} else // Background (most probably) NOT transparent
				imagegif($img_thumb, $tosavefileas);
		}else if($originaltype == "3") { // png
			 $img_thumb = @imagecreatetruecolor($img_width, $img_height);
			 imagealphablending($img_thumb, false);
			 imagesavealpha($img_thumb,true);
			 $transparent = imagecolorallocatealpha($img_thumb, 255, 255, 255, 127);
			 imagefilledrectangle($img_thumb, 0, 0, $img_width, $img_height, $transparent);
			 @imagecopyresampled($img_thumb, $img_temp, 0, 0, 0, 0, $img_width, $img_height, @imagesx ($img_temp), @imagesy($img_temp));
			 $this->ReturnImagetype($img_thumb, $tosavefileas, $file);
		} else {
			$img_thumb = @imagecreatetruecolor($img_width, $img_height);
			@imagecopyresampled($img_thumb, $img_temp, 0, 0, 0, 0, $img_width, $img_height, @imagesx ($img_temp), @imagesy($img_temp));
			$this->ReturnImagetype($img_thumb, $tosavefileas, $file);
		} 
	}//end function

	function resizeImg2($imgPath, $maxWidth, $maxHeight, $directOutput = true, $quality = 90, $verbose,$imageType,$imgPath2)
	{
	   // get image size infos (0 width and 1 height,
	   //     2 is (1 = GIF, 2 = JPG, 3 = PNG)
	  
		 $size = @getimagesize($imgPath);
	
	   // break and return false if failed to read image infos
		 if(!$size){
		   if($verbose && !$directOutput)echo "<br />Not able to read image infos.<br />";
		   return false;
		 }
	
	   // relation: width/height
		 $relation = $size[0]/$size[1];
	   // maximal size (if parameter == false, no resizing will be made)
		 $maxSize = array($maxWidth?$maxWidth:$size[0],$maxHeight?$maxHeight:$size[1]);
	   // declaring array for new size (initial value = original size)
		 $newSize = $size;
	   // width/height relation
		 $relation = array($size[1]/$size[0], $size[0]/$size[1]);
	
	
		if(($newSize[0] > $maxWidth))
		{
			$newSize[0]=$maxSize[0];
			$newSize[1]=$newSize[0]*$relation[0];
		}
		
		
	
		/*
		if(($newSize[1] > $maxHeight))
		{
			$newSize[1]=$maxSize[1];
			$newSize[0]=$newSize[1]*$relation[1];
		}
		*/
		
		 // create image
	
		   switch($size[2])
		   {
			 case 1:
			   if(@function_exists("imagecreatefromgif"))
			   {
				 $originalImage = @imagecreatefromgif($imgPath);
			   }else{
				 if($verbose && !$directOutput)echo "<br />No GIF support in this php installation, sorry.<br />";
				 return false;
			   }
			   break;
			 case 2: $originalImage = @imagecreatefromjpeg($imgPath); break;
			 case 3: $originalImage = @imagecreatefrompng($imgPath); break;
			 default:
			   if($verbose && !$directOutput)echo "<br />No valid image type.<br />";
			   return false;
		   }
	
	
		 // create new image
	
		   $resizedImage = @imagecreatetruecolor($newSize[0], $newSize[1]); 
	
		   @imagecopyresampled($resizedImage, $originalImage,0, 0, 0, 0,$newSize[0], $newSize[1], $size[0], $size[1]);
	
		$rz=$imgPath;
	
		 // output or save
		   if($directOutput)
			{
			 @imagejpeg($resizedImage);
			 }
			 else
			{
				
				 $rz=preg_replace("/\.([a-zA-Z]{3,4})$/","".$imageType.".jpg",$imgPath2);
			 @imagejpeg($resizedImage, $rz, $quality);
			 }
		 // return true if successfull
		   return $rz;
	}//end function 

	function NewimageCreatefromtype($image)
	{
		list($width, $height, $type, $attr) = @getimagesize($image); 
		if ($type == "1") { // gif
			$returnimage = @imagecreatefromgif($image);
		} else if ($type == "2") { // jpeg
			$returnimage = @imagecreatefromjpeg($image);
		} else if ($type == "3") { // png
			$returnimage = @imagecreatefrompng($image);
		} else {
			$returnimage = "Not Supported";
		} 
		return $returnimage;
	}//end function 

	function ReturnImagetype($newImage, $newfile, $editimagefile)
	{
		list($width, $height, $type, $attr) = @getimagesize($editimagefile);
		$jpgCompression = "90";
		if ($type == "1") { // gif
			$returnimage = @imagegif($newImage, $newfile);
		} else if ($type == "2") { // jpeg
			$returnimage = @imagejpeg($newImage, $newfile, $jpgCompression);;
		} else if ($type == "3") { // png
			$returnimage = @imagepng($newImage, $newfile);
		} else {
			$returnimage = "Not Supported";
		} 
		return $returnimage;
	}//end function

	//fucntion for display file path nmae
	function ClientFilePathName($PhpSelf)
	{
		$fpath=explode("/",$PhpSelf);
		$fpath=$fpath[count($fpath)-1];
		return ($fpath);
	}//end function

	//currency code array
	function CurrencyCodeCheck($chkCur)
	{
		$crrencyArray=array("AUD"=>"A $","CAD"=>"C $","EUR"=>"&euro;","GBP"=>"&pound;","JPY"=>"&yen;","USD"=>"$","NZD"=>"$","HKD"=>"HK$","SGD"=>"$",
								"CZK"=>"Kc","DKK"=>"kr","HUF"=>"Ft","ILS"=>"&#8362;","MXN"=>"$","NOK"=>"kr","PLN"=>"zl","SEK"=>"kr","CHF"=>"CHF");
	
		foreach($crrencyArray as $ckey=>$cval)
		{
			if($ckey==$chkCur)
			{
				return ($cval);
			}//end if
		}//end foreach
	}//end function    

	//function for template preview
	function TemplatePreview($stylename)
	{
		$PreviewArray=array("red.css"=>"cybermatch.gif","green.css"=>"green.gif","blue.css"=>"blue.gif",
							 	"africa_ red.css"=>"africa-red.jpg","africa_brown.css"=>"africa-brown.jpg",
								"asia_green.css"=>"asia-green.jpg","asia_blue.css"=>"asia-blue.jpg",
								"india_red.css"=>"india-red.jpg","india_green.css"=>"india-green.jpg","india_orange.css"=>"india-orange.jpg");
								
	
		foreach($PreviewArray as $ckey=>$cval)
		{
			if($ckey==$stylename)
			{
				return ($cval);
			}//end if
		}//end foreach
	}//end function
	
	//fucntion for disaply style array
	function ShowTemplates($style)
	{
		$StylewArray=array("red.css"=>"Red Wine","green.css"=>"Angel Glow","blue.css"=>"Sunshine",
								"africa_ red.css"=>"Cheesy Love","africa_brown.css"=>"Hot Chocolate",
								"asia_green.css"=>"Eternal Desire","asia_blue.css"=>"Pacific Blue",
								"india_red.css"=>"Happy Ever After","india_green.css"=>"Couple's Delight","india_orange.css"=>"Happy Ending");
								
		asort($StylewArray);
		echo '<select name="ddlStyles" onChange="showHint(this.value);" class="textbox3">';
		foreach($StylewArray as $key=>$value)
		{
	?>
			<option value="<?php echo $key?>" <?php if($key==$style){echo 'selected';}?>><?php echo $value?></option>
	<?php
		}//end foreach
		echo '</select>';
	}//end function

	//function to select values from a table
	function select_rows($table,$fieldlist,$condition)
	{
		 $sql="select $fieldlist from $table $condition ";        
		 $resArray=$this->QueryResult($sql);
		 return ($resArray);
	}//end function
	
	function QueryResult($sql)
	{
		$rs=mysql_query($sql) or die(mysql_error());
		return $rs;
	}//end function
	
	//fuction for fetch result
	function fetchSingleValue($ResourceArray,$Field)
	{
		if(mysql_num_rows($ResourceArray)>0)
		{
			 return (mysql_result($ResourceArray,0,$Field));
		}//end if
	}//end function

	//function to update values in a table
	function update_rows($table, $fieldlist, $condition)
	{
		$sql="update $table set $fieldlist $condition";
		$resArray=$this->QueryResult($sql,'Update');
		return ($resArray);
	}//end function

	//function to insert values in a table
	function insert_fields($table, $in_fieldlist, $in_values)
	{
		$sql="insert into $table ($in_fieldlist) values ($in_values)";
		$resArray=$this->QueryResult($sql,'Insert');
		return ($resArray);
	}//end function

	//function for select box
	//$sOptionArray contains option vaalue array
	function select_tag($sName,$sClass,$sConditions,$sOptionArray,$chkValue)
	{
		$selctbox='<select class="'.$sClass.'" name="'.$sName.'" '.$sConditions.'>';
		//extract array
		foreach($sOptionArray as $key=>$val)
		{
			$selctbox.=$this->select_option_tag($key,$val,$chkValue);
		}//end for loop
		$selctbox.='</select>';
		return ($selctbox);
	}//end funciton
	
	//function for option
	function select_option_tag($key,$val,$chkValue)
	{
		//checking selected val
		switch($key)
		{
			case $chkValue:
				$selectd="selected";
			break;
			
			case " ":
				$selectd="";
			break;
			
			default:
				$selectd="";
			break;
			
		}//end switch
		
		$opt='<option value="'.$key.'" '.$selectd.'>'.$val.'</option>';
		return ($opt);
	}//end funciton

	//function to check uploaded image is is allowed type and also checking uploaded file is executable
	function CheckUploadFileType($allArray,$upFileType)
	{
		$blacklist = array(".php", ".phtml", ".php3", ".php4", ".js", ".shtml", ".pl" ,".py");

		$file_ext=explode('[.]', $_FILES['photo']['name']);
		$file='.'.$file_ext[1];

		if(!in_array($file,$blacklist))
		{
			if(is_array($allArray))
			{
				if(in_array($upFileType,$allArray))
				{
					$msg='';
				}//end if
				else
				{
					$msg='Image format not supported !!';
				}//end else
			}//end if
		}//end if
		else
		{
			$msg="ERROR: Uploading executable files Not Allowed\n";
		}//end else
		return ($msg);
	}//end function

	//ordering up
	function OrderUp($table,$oldId,$oldPosition,$PositionfieldName,$IdfieldName,$returnPath)
	{
		$sql=mysql_query("select min($PositionfieldName) as min from ".$table." where $PositionfieldName>$oldPosition") or die(mysql_error());
		$newPosition=mysql_result($sql,0,'min');
                if(!isset($newPosition)){
                    $newPosition = 0;
                }
               // echo "select * from ".$table." where $PositionfieldName=$newPosition"."<br>";
		$sqlId=mysql_query("select * from ".$table." where $PositionfieldName=$newPosition") or die(mysql_error());
		$newId=mysql_result($sqlId,0,$IdfieldName);
		mysql_query("update  ".$table." set $PositionfieldName='".$newPosition."' where $IdfieldName='".$oldId."'") or die(mysql_error());
		mysql_query("update  ".$table." set $PositionfieldName='".$oldPosition."' where $IdfieldName='".$newId."'") or die(mysql_error());
		if($_GET['ddlCategory']!='')
		{
			header($returnPath.'?ddlCategory='.$_GET['ddlCategory']);
		}//end else
		else
		{
			header($returnPath);
		}//end else
	}//end function
	
	//ordering down
	function OrderDown($table,$oldId,$oldPosition,$PositionfieldName,$IdfieldName,$returnPath)
	{
		$sql=mysql_query("select max($PositionfieldName) as max from $table where $PositionfieldName<$oldPosition") or die(mysql_error());
		$newPosition=mysql_result($sql,0,'max');
		$sqlId=mysql_query("select * from $table where $PositionfieldName=$newPosition") or die(mysql_error());
		$newId=mysql_result($sqlId,0,$IdfieldName);
		mysql_query("update  $table set $PositionfieldName='".$newPosition."' where $IdfieldName='".$oldId."'") or die(mysql_error());
		mysql_query("update  $table set $PositionfieldName='".$oldPosition."' where $IdfieldName='".$newId."'") or die(mysql_error());
		if($_GET['ddlCategory']!='')
		{
			header($returnPath.'?ddlCategory='.$_GET['ddlCategory']);
		}//end else
		else
		{
			header($returnPath);
		}//end else
	}//end fucntion

	function ImageType($image)
	{
		list($width, $height, $type, $attr) = @getimagesize($image);
		switch ($type) 
		{
			 case 1 :
					 $returntype = "gif";
					 break;
			case 2 :
					 $returntype = "jpg";
					 break;
			case 3 :
					 $returntype = "png";
					 break;
			case 4 :
					 $returntype = "swf";
					 break;
			case 5 :
					$returntype = "psd";
					break;
			case 6 :
					$returntype = "bmp";
					break;
			case 7 :
					$returntype = "tiff";
					break;
			case 8 :
					$returntype = "tiff";
					break;
			default :
					$returntype = "notsupportted" ;
					break;
		}//end switch 
	
		return $returntype . ":$width:$height";
	}//end function 

	function resizeImg($imgPath, $maxWidth, $maxHeight, $directOutput = true, $quality = 90, $verbose,$imageType)
	{
	   // get image size infos (0 width and 1 height,
	   //     2 is (1 = GIF, 2 = JPG, 3 = PNG)
	  
		 $size = getimagesize($imgPath);
	
	   // break and return false if failed to read image infos
		 if(!$size){
		   if($verbose && !$directOutput)echo "<br />Not able to read image infos.<br />";
		   return false;
		 }
	
	   // relation: width/height
		 $relation = $size[0]/$size[1];
	   // maximal size (if parameter == false, no resizing will be made)
		 $maxSize = array($maxWidth?$maxWidth:$size[0],$maxHeight?$maxHeight:$size[1]);
	   // declaring array for new size (initial value = original size)
		 $newSize = $size;
	   // width/height relation
		 $relation = array($size[1]/$size[0], $size[0]/$size[1]);
	
	
		if(($newSize[0] > $maxWidth))
		{
			$newSize[0]=$maxSize[0];
			$newSize[1]=$newSize[0]*$relation[0];
		}
		
		
	
		/*
		if(($newSize[1] > $maxHeight))
		{
			$newSize[1]=$maxSize[1];
			$newSize[0]=$newSize[1]*$relation[1];
		}
		*/
		
		 // create image
	
		   switch($size[2])
		   {
			 case 1:
			   if(function_exists("imagecreatefromgif"))
			   {
				 $originalImage = imagecreatefromgif($imgPath);
			   }else{
				 if($verbose && !$directOutput)echo "<br />No GIF support in this php installation, sorry.<br />";
				 return false;
			   }
			   break;
			 case 2: $originalImage = imagecreatefromjpeg($imgPath); break;
			 case 3: $originalImage = imagecreatefrompng($imgPath); break;
			 default:
			   if($verbose && !$directOutput)echo "<br />No valid image type.<br />";
			   return false;
		   }
	
	
		 // create new image
	
		   $resizedImage = imagecreatetruecolor($newSize[0], $newSize[1]); 
	
		   imagecopyresampled($resizedImage, $originalImage,0, 0, 0, 0,$newSize[0], $newSize[1], $size[0], $size[1]);
	
		$rz=$imgPath;
	
		 // output or save
		   if($directOutput)
			{
			 imagejpeg($resizedImage);
			 }
			 else
			{
				
				 $rz=preg_replace("/\.([a-zA-Z]{3,4})$/","".$imageType.".jpg",$imgPath);
			 imagejpeg($resizedImage, $rz, $quality);
			 }
		 // return true if successfull
		   return $rz;
		}
	}
?>