<?php
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
// +----------------------------------------------------------------------+
// | file to define the global variables needed in the application        |
// | File name : globals.php                                                 |
// | PHP version >= 5.2                                                   |
// | Created On 19 Dec 2011                                               |
// +----------------------------------------------------------------------+
// | Author: JINSON MATHEW <jinson.m@armiasystems.com>                    |
// +----------------------------------------------------------------------+
// | Copyrights Armia Systems ? 2011                                      |
// | All rights reserved                                                  |
// +----------------------------------------------------------------------+
// | This script may not be distributed, sold, given away for free to     |
// | third party, or used as a part of any internet services such as      |
// | webdesign etc.                                                       |
// +----------------------------------------------------------------------+
 
require_once('public/recaptcha/recaptchalib.php');

define('TEMPLATE_ADMIN',BASE_URL.'theme/netdreams/');
define('TEMPLATE_MERCHANT',BASE_URL.'theme/netdreams/');



define('CATEGORY_IMAGE','uploads/category/');
define('OFFER_IMAGE',	'uploads/offers/');
define('SITE_LOGO_PATH','uploads/logo/');
define('CURRENCY_SYMBOL','$');

// Recaptcha Global Key
define('RECAPTCHA_PUBLICKEY','6LfryNQSAAAAAHh7zgGqZUYgp7oJDDmq49tBj9Rz');
define('RECAPTCHA_PRIVATEKEY','6LfryNQSAAAAAEQGT_gjWxwxVAlfRu37pDR3sR1f');

 
	
 $dateMonth 	= array ("1" => "Jan",
						 "2" => "Feb",
						 "3" => "Mar",
						 "4" => "Apr",
						 "5" => "May",
						 "6" => "Jun",
						 "7" => "Jul",
						 "8" => "AUg",
						 "9" => "Sep",
						 "10" => "Oct",
						 "11" => "Nov",
						 "12" => "Dec");
						 
$dateStartYear	= 2012;
$dateEndYear	= 2018;
		 
       $wishMinPrice   = array("1"=>"100",
                      "2"=>"500",
                      "3"=>"1000",
                      "4"=>"2000");



$internalMsg   =  array("1" => " A Merchant has set an offer for your wish",
                        "2" => " Your joined offer has been settled",
                        "3" => " User who was following a wish settled by you accepted your offer",
                        "4" => " User who was following a wish settled by you rejected your offer",
                        "5" => " A user requested to merge his wish with your wish",
                        "6" => " A user accepted the request for merge wish",
                        "7" => " A matching offer has been found for your wish",
                        "8" => " A new wish has been added",
                        "9" => " A new user joined in the wish you joined",
                        "10" =>" A new user started following the offer you are following",
                        "11" =>" A new user started following your offer");




      $wishMaxPrice   =  array("1"=>"100",
                      "2"=>"500",
                      "3"=>"1000",
                       "4"=>"2000");


/* image sizes using in moboffer  */
define('MAX_UPLOAD_OFFER_IMAGE',5);
define('WIDTH_OFFER_IMAGE',	600);
define('WIDTH_CATEGORY_IMAGE',	300);




     $msg_user_status  =  array("0"	=> "Not Confirmed",
                              "1"	=> "Active",
							  "2"	=> "BLocked");




/*
message status is used for showing the messages in the user dashboard
*/
     $messageStatus  =  array("1"	=> "Unread",
                              "2"	=> "Deleted",
							  "3"	=> "Accepted",
							  "4"	=> "Rejected");



/*


NOTIFICATION table details
	param1  = a user joins in my wish: 		
  	param2	= a user quit from my wish 		
  	param3	= a merchant settle my wish 		
  	param4	= activate the offer i am following 		
  	param5	= merchant settle the offer 
	

*/
 
     $offereStatus  =  array(	"0"	=> "Created",
	 							"1"	=> "Active",
                              	"2"	=> "Inactive",
							  	"3"	=> "Expired",
							  	"4"	=> "Settled");

















     $postVisibility  =  array("1"=>"Public",
                                     "2"=>"Private"
                                     );
    $countries	=  array(
  "US" => "United States",
  "GB" => "United Kingdom",
  "AF" => "Afghanistan",
  "AL" => "Albania",
  "DZ" => "Algeria",
  "AS" => "American Samoa",
  "AD" => "Andorra",
  "AO" => "Angola",
  "AI" => "Anguilla",
  "AQ" => "Antarctica",
  "AG" => "Antigua And Barbuda",
  "AR" => "Argentina",
  "AM" => "Armenia",
  "AW" => "Aruba",
  "AU" => "Australia",
  "AT" => "Austria",
  "AZ" => "Azerbaijan",
  "BS" => "Bahamas",
  "BH" => "Bahrain",
  "BD" => "Bangladesh",
  "BB" => "Barbados",
  "BY" => "Belarus",
  "BE" => "Belgium",
  "BZ" => "Belize",
  "BJ" => "Benin",
  "BM" => "Bermuda",
  "BT" => "Bhutan",
  "BO" => "Bolivia",
  "BA" => "Bosnia And Herzegowina",
  "BW" => "Botswana",
  "BV" => "Bouvet Island",
  "BR" => "Brazil",
  "IO" => "British Indian Ocean Territory",
  "BN" => "Brunei Darussalam",
  "BG" => "Bulgaria",
  "BF" => "Burkina Faso",
  "BI" => "Burundi",
  "KH" => "Cambodia",
  "CM" => "Cameroon",
  "CA" => "Canada",
  "CV" => "Cape Verde",
  "KY" => "Cayman Islands",
  "CF" => "Central African Republic",
  "TD" => "Chad",
  "CL" => "Chile",
  "CN" => "China",
  "CX" => "Christmas Island",
  "CC" => "Cocos (Keeling) Islands",
  "CO" => "Colombia",
  "KM" => "Comoros",
  "CG" => "Congo",
  "CD" => "Congo, The Democratic Republic Of The",
  "CK" => "Cook Islands",
  "CR" => "Costa Rica",
  "CI" => "Cote D'Ivoire",
  "HR" => "Croatia (Local Name: Hrvatska)",
  "CU" => "Cuba",
  "CY" => "Cyprus",
  "CZ" => "Czech Republic",
  "DK" => "Denmark",
  "DJ" => "Djibouti",
  "DM" => "Dominica",
  "DO" => "Dominican Republic",
  "TP" => "East Timor",
  "EC" => "Ecuador",
  "EG" => "Egypt",
  "SV" => "El Salvador",
  "GQ" => "Equatorial Guinea",
  "ER" => "Eritrea",
  "EE" => "Estonia",
  "ET" => "Ethiopia",
  "FK" => "Falkland Islands (Malvinas)",
  "FO" => "Faroe Islands",
  "FJ" => "Fiji",
  "FI" => "Finland",
  "FR" => "France",
  "FX" => "France, Metropolitan",
  "GF" => "French Guiana",
  "PF" => "French Polynesia",
  "TF" => "French Southern Territories",
  "GA" => "Gabon",
  "GM" => "Gambia",
  "GE" => "Georgia",
  "DE" => "Germany",
  "GH" => "Ghana",
  "GI" => "Gibraltar",
  "GR" => "Greece",
  "GL" => "Greenland",
  "GD" => "Grenada",
  "GP" => "Guadeloupe",
  "GU" => "Guam",
  "GT" => "Guatemala",
  "GN" => "Guinea",
  "GW" => "Guinea-Bissau",
  "GY" => "Guyana",
  "HT" => "Haiti",
  "HM" => "Heard And Mc Donald Islands",
  "VA" => "Holy See (Vatican City State)",
  "HN" => "Honduras",
  "HK" => "Hong Kong",
  "HU" => "Hungary",
  "IS" => "Iceland",
  "IN" => "India",
  "ID" => "Indonesia",
  "IR" => "Iran (Islamic Republic Of)",
  "IQ" => "Iraq",
  "IE" => "Ireland",
  "IL" => "Israel",
  "IT" => "Italy",
  "JM" => "Jamaica",
  "JP" => "Japan",
  "JO" => "Jordan",
  "KZ" => "Kazakhstan",
  "KE" => "Kenya",
  "KI" => "Kiribati",
  "KP" => "Korea, Democratic People's Republic Of",
  "KR" => "Korea, Republic Of",
  "KW" => "Kuwait",
  "KG" => "Kyrgyzstan",
  "LA" => "Lao People's Democratic Republic",
  "LV" => "Latvia",
  "LB" => "Lebanon",
  "LS" => "Lesotho",
  "LR" => "Liberia",
  "LY" => "Libyan Arab Jamahiriya",
  "LI" => "Liechtenstein",
  "LT" => "Lithuania",
  "LU" => "Luxembourg",
  "MO" => "Macau",
  "MK" => "Macedonia, Former Yugoslav Republic Of",
  "MG" => "Madagascar",
  "MW" => "Malawi",
  "MY" => "Malaysia",
  "MV" => "Maldives",
  "ML" => "Mali",
  "MT" => "Malta",
  "MH" => "Marshall Islands",
  "MQ" => "Martinique",
  "MR" => "Mauritania",
  "MU" => "Mauritius",
  "YT" => "Mayotte",
  "MX" => "Mexico",
  "FM" => "Micronesia, Federated States Of",
  "MD" => "Moldova, Republic Of",
  "MC" => "Monaco",
  "MN" => "Mongolia",
  "MS" => "Montserrat",
  "MA" => "Morocco",
  "MZ" => "Mozambique",
  "MM" => "Myanmar",
  "NA" => "Namibia",
  "NR" => "Nauru",
  "NP" => "Nepal",
  "NL" => "Netherlands",
  "AN" => "Netherlands Antilles",
  "NC" => "New Caledonia",
  "NZ" => "New Zealand",
  "NI" => "Nicaragua",
  "NE" => "Niger",
  "NG" => "Nigeria",
  "NU" => "Niue",
  "NF" => "Norfolk Island",
  "MP" => "Northern Mariana Islands",
  "NO" => "Norway",
  "OM" => "Oman",
  "PK" => "Pakistan",
  "PW" => "Palau",
  "PA" => "Panama",
  "PG" => "Papua New Guinea",
  "PY" => "Paraguay",
  "PE" => "Peru",
  "PH" => "Philippines",
  "PN" => "Pitcairn",
  "PL" => "Poland",
  "PT" => "Portugal",
  "PR" => "Puerto Rico",
  "QA" => "Qatar",
  "RE" => "Reunion",
  "RO" => "Romania",
  "RU" => "Russian Federation",
  "RW" => "Rwanda",
  "KN" => "Saint Kitts And Nevis",
  "LC" => "Saint Lucia",
  "VC" => "Saint Vincent And The Grenadines",
  "WS" => "Samoa",
  "SM" => "San Marino",
  "ST" => "Sao Tome And Principe",
  "SA" => "Saudi Arabia",
  "SN" => "Senegal",
  "SC" => "Seychelles",
  "SL" => "Sierra Leone",
  "SG" => "Singapore",
  "SK" => "Slovakia (Slovak Republic)",
  "SI" => "Slovenia",
  "SB" => "Solomon Islands",
  "SO" => "Somalia",
  "ZA" => "South Africa",
  "GS" => "South Georgia, South Sandwich Islands",
  "ES" => "Spain",
  "LK" => "Sri Lanka",
  "SH" => "St. Helena",
  "PM" => "St. Pierre And Miquelon",
  "SD" => "Sudan",
  "SR" => "Suriname",
  "SJ" => "Svalbard And Jan Mayen Islands",
  "SZ" => "Swaziland",
  "SE" => "Sweden",
  "CH" => "Switzerland",
  "SY" => "Syrian Arab Republic",
  "TW" => "Taiwan",
  "TJ" => "Tajikistan",
  "TZ" => "Tanzania, United Republic Of",
  "TH" => "Thailand",
  "TG" => "Togo",
  "TK" => "Tokelau",
  "TO" => "Tonga",
  "TT" => "Trinidad And Tobago",
  "TN" => "Tunisia",
  "TR" => "Turkey",
  "TM" => "Turkmenistan",
  "TC" => "Turks And Caicos Islands",
  "TV" => "Tuvalu",
  "UG" => "Uganda",
  "UA" => "Ukraine",
  "AE" => "United Arab Emirates",
  "UM" => "United States Minor Outlying Islands",
  "UY" => "Uruguay",
  "UZ" => "Uzbekistan",
  "VU" => "Vanuatu",
  "VE" => "Venezuela",
  "VN" => "Viet Nam",
  "VG" => "Virgin Islands (British)",
  "VI" => "Virgin Islands (U.S.)",
  "WF" => "Wallis And Futuna Islands",
  "EH" => "Western Sahara",
  "YE" => "Yemen",
  "YU" => "Yugoslavia",
  "ZM" => "Zambia",
  "ZW" => "Zimbabwe"
);

$usStates = array('AL'=>"Alabama",
			'AK'=>"Alaska",
			'AZ'=>"Arizona",
			'AR'=>"Arkansas",
			'CA'=>"California",
			'CO'=>"Colorado",
			'CT'=>"Connecticut",
			'DE'=>"Delaware",
			'DC'=>"District Of Columbia",
			'FL'=>"Florida",
			'GA'=>"Georgia",
			'HI'=>"Hawaii",
			'ID'=>"Idaho",
			'IL'=>"Illinois",
			'IN'=>"Indiana",
			'IA'=>"Iowa",
			'KS'=>"Kansas",
			'KY'=>"Kentucky",
			'LA'=>"Louisiana",
			'ME'=>"Maine",
			'MD'=>"Maryland",
			'MA'=>"Massachusetts",
			'MI'=>"Michigan",
			'MN'=>"Minnesota",
			'MS'=>"Mississippi",
			'MO'=>"Missouri",
			'MT'=>"Montana",
			'NE'=>"Nebraska",
			'NV'=>"Nevada",
			'NH'=>"New Hampshire",
			'NJ'=>"New Jersey",
			'NM'=>"New Mexico",
			'NY'=>"New York",
			'NC'=>"North Carolina",
			'ND'=>"North Dakota",
			'OH'=>"Ohio",
			'OK'=>"Oklahoma",
			'OR'=>"Oregon",
			'PA'=>"Pennsylvania",
			'RI'=>"Rhode Island",
			'SC'=>"South Carolina",
			'SD'=>"South Dakota",
			'TN'=>"Tennessee",
			'TX'=>"Texas",
			'UT'=>"Utah",
			'VT'=>"Vermont",
			'VA'=>"Virginia",
			'WA'=>"Washington",
			'WV'=>"West Virginia",
			'WI'=>"Wisconsin",
			'WY'=>"Wyoming");

						
 $orderStatus   =   array("1"=>"Pending",
                         "2"=>"Cancelled",
                         "3"=>"Shipped",
                         "4"=>"Delivered",
                         "5"=>"Returned to Seller",
                         "6"=>"Seller Received Back");



 $noImage       = BASE_URL."uploads/noimage.png";

							  
function DisplayLookUp($name) {
    $sql = mysqli_query($connection,"select set_value from " . MYSQL_TABLE_PREFIX . "settings where set_name='" . addslashes($name) . "'") or die(mysqli_error($connection));
    if (mysqli_num_rows($sql) > 0) {
        return (mysqli_result($sql, 0, 'set_value'));
    }//end if
}	
	
function updateSettings($param,$value) 
{
	if($param!= '' && $value!= '')
	{
		 $sql = mysqli_query($connection,"UPDATE " . MYSQL_TABLE_PREFIX . "settings SET set_value = '" . addslashes($value) . "' WHERE set_name='" . addslashes($param) . "'") or die(mysqli_error($connection));

	}
}



/*

Function to print the array
*/
function echopre($printArray)
{
	echo "<pre>";
	print_r($printArray);
	echo "</pre>";
}
function echopre1($printArray)
{
	echo "<pre>";
	print_r($printArray);
	echo "</pre>";
	exit();
}


function fdate($dateval)
{
	if($dateval != '')
		return date('m-d-Y',$dateval);
		
}



function msg_green($text)
{
		return '<div id="message-green">
				<table border="0" width="100%" cellpadding="0" cellspacing="0">
				<tr>
					<td class="green-left">'.$text.'</td>
					<td class="green-right"><a class="close-green"><img src="'.TEMPLATE_ADMIN.'images/table/icon_close_green.gif"   alt="" /></a></td>
				</tr>
				</table>
				</div>';
}



function msg_red($text)
{
		return '<div id="message-red">
				<table border="0" width="100%" cellpadding="0" cellspacing="0">
				<tr>
					<td class="red-left">'.$text.' <a href="">Please try again.</a></td>
					<td class="red-right"><a class="close-red"><img src="images/table/icon_close_red.gif"   alt="" /></a></td>
				</tr>
				</table>
				</div>
';
}

				
        /*Email validation*/
        function is_valid_email( $address )
        {
           $rx = "^[a-z0-9\\_\\.\\-]+\\@[a-z0-9\\-]+\\.[a-z0-9\\_\\.\\-]+\\.?[a-z]{1,4}$";
           return (preg_match("~".$rx."~i", $address));
        }


/*
	function to calculate the post age. It shows how old our details with the current time

	*/
	function time_elapsed_string($ptime) {
		$etime = time() - $ptime;

		if ($etime < 1) {
			return '0 seconds';
		}

		$a = array( 12 * 30 * 24 * 60 * 60  =>  'year',
					30 * 24 * 60 * 60       =>  'month',
					24 * 60 * 60            =>  'day',
					60 * 60                 =>  'hour',
					60                      =>  'minute',
					1                       =>  'second'
					);

		foreach ($a as $secs => $str) {
			$d = $etime / $secs;
			if ($d >= 1) {
				$r = round($d);
				return $r . ' ' . $str . ($r > 1 ? 's' : '').' ago';
			}
		}
	}

	/*
	
	mail sending function. It using phpmailer as mail sending application
	
	*/

	function sendMail($mailInfo,$toIds,$attachments='')
	{
	
		require_once('public/mailer/class.phpmailer.php');
		if(sizeof($mailInfo) > 0 && sizeof($toIds) > 0)
		{
			$mail            	= new PHPMailer(); // defaults to using php "mail()"
			$addrReply			= explode(':',$mailInfo['replyTo']);
			$addrFrom			= explode(':',$mailInfo['mailFrom']);
			$mail->AddReplyTo($addrReply[0],$addrReply[1]);
			$mail->SetFrom($addrFrom[0], $addrFrom[1]);
			$mail->Subject    	= $mailInfo['subject'];
			$mail->IsHTML(true);
			
			//echopre1($mailInfo);
			
			$mail->AltBody    	= $mailInfo['alt_body'];
			$mail->MsgHTML($mailInfo['msgBody']);
			foreach($toIds as $key=>$val)
			{
				$mail->AddAddress($key, $val);
			}
			
			
			
			/***************
			we can add the attachment section here
			****************/
			if(!$mail->Send()) {		// sending the mail
			  return "Mailer Error: " . $mail->ErrorInfo;
			} else {
			  return 1;					// mail sending success
			}
		}
 	}

      /** function to fetch categories **/
    function getCategories() {
        $categories =   array();
        $sql = mysqli_query($connection,"select * from " .MYSQL_TABLE_PREFIX. "categories ORDER BY cat_name ASC") or die(mysqli_error($connection));
        return $sql;
        /*if (mysqli_num_rows($sql) > 0) {
            $catCnt    =   0;
            while($row=mysqli_fetch_array($sql))
            {
                $categories[$catCnt]['id'] =   $row['cat_id'];
                $categories[$catCnt]['name'] =   $row['cat_name'];
                $catCnt++;
            }
            echopre($categories);
           return $categories;
        }//end if
       */
         
    }
	
	
	
	/*
	function to insert the message in to the table
	*/
	function addMessage($type,$to,$from,$offerid,$wishid,$message,$status)
	{
		//if($type!='' && $to!='' && $from!='' && $offerid!= '' && $wishid!='' && $status!='')
		        $sql = mysqli_query($connection,"INSERT INTO " .MYSQL_TABLE_PREFIX. "messages(msgtype,msgto,msgfrom,offerid,wishid,msg_time,	msg_message,msgstatus) VALUES('".$type."','".$to."','".$from."','".$offerid."','".$wishid."','".time()."','".$message."','".$status."')") or die(mysqli_error($connection));
                        return mysqli_insert_id($connection);
	}
	
	function rename_if_exists($dir, $filename) {
		$ext = strrchr($filename, '.');
		$prefix = substr($filename, 0, -strlen($ext));
		 
		$i = 0;
		while(file_exists($dir . $filename)) { // If file exists, add a number to it.
		$filename = $prefix . ++$i . $ext;
		}
		 
		return $filename;
    }


	/*
	function to check the session for the merchant
	*/
	function mLoginCheck()
	{
 		if(!isset($_SESSION['merchant']['m_id']))
	        header("Location:".ConfigUrl::base().'login');
		//else
		//	header("Location:".ConfigUrl::base().'merchant/dashboard');

		//echopre($_SESSION);
	}
	
	
	/*
	function to check the session for the user
	*/
	function uLoginCheck()
	{
 		if(!isset($_SESSION['user']['u_id']))
	        header("Location:".ConfigUrl::base().'login');


	}



	/*
	function to check the session for the user
	*/
	function adminLoginCheck()
	{
 		if(!isset($_SESSION['admin']))
	        header("Location:".ConfigUrl::base().'admin');


	}



	/*
	function to generate the breadcrumb
	*/
	function getBreadCrumb($links)
	{
 		if(sizeof($links)>0)
		{
			$breadcrumb = '';
			foreach($links as $title=>$link)
 				$breadcrumb.=($link!='')?'<a href="'.ConfigUrl::base().$link.'">'.stripslashes($title).'</a> &nbsp; -> &nbsp;':stripslashes($title);
			$breadcrumb = '<div class="breadcrumb"  style="padding:20px 0px 20px 0px;">'.$breadcrumb.'</div>';	
		}
 		return $breadcrumb;
	}


	/*
	This function post some details into the facebook wall of the user using the access token
	*/
	
	function postToFaceBookPageWall($post_url,$data,$page_id,$page_access_token)
    {   
  		$post_url 				= $post_url;
        $data['access_token'] 	= $page_access_token;
        $ch 					= curl_init();
        curl_setopt($ch, CURLOPT_URL, $post_url);
        curl_setopt($ch, CURLOPT_POST, 1);
        curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        // execute and close
        $return 				= curl_exec($ch);
        curl_close($ch);
		return $return;
   	}
    /*Export to Excel*/
        function exporttoexcel($fileName,$headArray='',$contentArray='')
        {
            require_once('public/excel/php-excel.class.php');
            // load library
            // create a simple 2-dimensional array
            /*
            $saleArray=array('Sl No.','Name','Google','','','Twitter','','');
            $saleValueArray[0] =   array('neutral','good','bad','neutral','good','bad','neutral','good','bad','neutral');
            $saleValueArray[1] =   array('1','2','0','0','0','567','7567','75','6','0');
            */
            //$conetent   =   implode(',',$saleValueArray);
            $data = array(1 =>$headArray);
            //$content = array(1 =>$saleValueArray[0]);
           // $contentA = implode(",", $saleValueArray);
            //$content = array(1 =>$contentA);
            // generate file (constructor parameters are optional)
            $xls = new Excel_XML('UTF-8', false,$fileName);
            $xls->addArray($data);
            foreach($contentArray as $content)
            $xls->addArray(array(1 =>$content));
            $excelName  =   date('Y-m-d').'_'.time().'_'.$fileName;
            $xls->generateXML($excelName);
        }







      /** function to fetch categories **/
    function getTrendingOffers($limit,$fileds) {
		$limitend = ($limit!='')?$limit:2;
		$fileds = ($fileds!='')?$fileds:'offer_id,offer_title,offer_image';
        $sql = mysqli_query($connection,"select ".$fileds." from " .MYSQL_TABLE_PREFIX. "offer WHERE offer_active =1 ORDER BY offer_id DESC LIMIT 0,".$limitend) or die(mysqli_error($connection));
       	return $sql;

    }
    function getUnreadMessages() {
        $sql = mysqli_query($connection,"select count(msgid) from " .MYSQL_TABLE_PREFIX. "messages WHERE msg_read=1 AND msgto='".$_SESSION['user']['u_id']."'") or die(mysqli_error($connection));
        $row = mysqli_fetch_row($sql);
        return $row[0];
    }
    function mailer($mailName,$arrReplace,$toArr)
    {
            // code to create the offer link
        $adminFromEmail  = DisplayLookUp('adfromemail');
        $adminReplyEmail = DisplayLookUp('adreplyemail');
        $adminName       = DisplayLookUp('adfromemailname');
		//echo "select * from " .MYSQL_TABLE_PREFIX. "cms WHERE cms_name='".$mailName."' AND cms_status=1";
        $sql = mysqli_query($connection,"select * from " .MYSQL_TABLE_PREFIX. "cms WHERE cms_name='".$mailName."' AND cms_status=1") or die(mysqli_error($connection));
        $mailTemp   =   mysqli_fetch_object($sql);
        if(sizeof($mailTemp) >0)
        {
            $arrTSearch     		= array("{SITE_NAME}","{SITE_URL}","{SITE_EMAIL}","{Name}","{Username}","{FirstName}","{LastName}","{Email}","{LoginLink}","{ActivationLink}","{ORDER_ID}","{ORDER_DATE}","{PRODUCT}","{ITEMPRICE_TOTAL}","{TOTAL_DISCOUNT}","{TOTAL_AMOUNT}","{OFFER_LINK}","{WISH_LINK}","{MESSAGE_LINK}","{MERGE_LINK}","{MERCHANT_COMMENT}","{USER_COMMENT}","{ADDRESS}","{CURRENCY_SYMBOL}","{Date}","{EMAIL_BODY}");
            $arrTReplace    		= array(SITE_NAME,ConfigUrl::base(),SITE_EMAIL,$arrReplace['name'],$arrReplace['username'],$arrReplace['firstName'],$arrReplace['lastName'],$arrReplace['email'],$arrReplace['loginLink'],$arrReplace['activationLink'],$arrReplace['orderId'],$arrReplace['orderDate'],$arrReplace['product'],$arrReplace['itemTotal'],$arrReplace['totalDiscount'],$arrReplace['totalAmount'],$arrReplace['offerLink'],$arrReplace['wishLink'],$arrReplace['messageLink'],$arrReplace['mergeLink'],$arrReplace['merchantComment'],$arrReplace['userComment'],$arrReplace['address'],$arrReplace['currencySymbol'],date('F d Y'),$arrReplace['emailbody']);
            $mainTextShow   		= str_replace($arrTSearch,$arrTReplace,stripslashes($mailTemp->cms_desc));
            $mailTitle			= str_replace('{SITE_NAME}',SITE_NAME,stripslashes($mailTemp->cms_title));
            $mailTitle			= str_replace('{OrderNo}',$orderId,$mailTitle);
            $arrEmail 			= array("mailFrom"	=> $adminFromEmail.":".$adminName,
                                                    "replyTo" 	=> $adminReplyEmail,
                                                    "subject" 	=> $mailTitle,
                                                    "alt_body"	=> '',
                                                    "msgBody" 	=> $mainTextShow);


                // check whether given email is valid
            // echopre($arrEmail);
                $arrToEmails =   array_keys($toArr);
                   
                if(sizeof($arrToEmails)>0)
                {
                    foreach($arrToEmails as $email)
                    {
                        //echo "verify".  verify_email($email);
                        if(verify_email($email))
                        {
                            try{
                                $sendmail = sendMail($arrEmail,$toArr);
                                }catch (Exception $e){}
                                /**Send Mail to Admin with client registration details***/
                        }
                     }
                 }
            }
    }
    

function verifyEmail($email){

  if(!preg_match('/^[_A-z0-9-]+((\.|\+)[_A-z0-9-]+)*@[A-z0-9-]+(\.[A-z0-9-]+)*(\.[A-z]{2,4})$/',$email)){
    return false;
   } else {
    return true;
   }
}



?>