20100507.sql //BLOGhh //mysql -u vandcoadmin -pQ45EJ1v vandcodb error_reporting(E_ERROR | E_WARNING | E_PARSE); $templates_dir='/usr/web/vandco.net/html/templates/'; //$includes_dir='/usr/web/vandco.net/html/templates/includes/'; define(IMAGES_DIR,'/usr/web/vandco.net/html/images/upload/'); define(IMAGES_WEB,'http://vandco.net/images/upload/'); define(IMAGES_SPECIALS_DIR,'/usr/web/vandco.net/html/images/specials/'); define(IMAGES_SPECIALS_WEB,'http://vandco.net/images/specials/'); define(IMAGES_PRODUCTS_DIR,'/usr/web/vandco.net/html/images/products/'); define(IMAGES_PRODUCTS_WEB,'http://vandco.net/images/products/'); define(IMAGES_BROCHURE_DIR,'/usr/web/vandco.net/html/images/brochure/'); define(IMAGES_BROCHURE_WEB,'http://vandco.net/images/brochure/'); $controller_dir='/usr/web/vandco.net/html/controller/'; $main_website='http://vandco.net'; //$admin_email='Fcantanese@vandco.net,Dwaterman@vandco.net,domains@hostservices.net'; $admin_email='summitinforelay@gmail.com,domains@hostservices.net'; // Fcantanese@vandco.net removed because of bounces require("/usr/web/vandco.net/html/controller/class.phpmailer.php"); $memcache=memConn(array('127.0.0.1:11211')); $mysqli=dbConn(); global $mysqli; global $memcache; //////////////////////////////// function memConn($servers) //////////////////////////////// { $mem=new Memcache; foreach ($servers as $loop) { list ($srv,$port)=preg_split("/:/",$loop); $mem->addServer($srv,$port); } return $mem; } //////////////////////////////// function dbConn() //////////////////////////////// { $db_host="localhost"; $db_user="vandco_db66"; $db_pass="JHSD3287y%%"; $db_db="vandco_db66"; $mysqli=mysqli_init(); if (!$mysqli) { fatalError('mysqli_init failed'); } if (!$mysqli->options(MYSQLI_INIT_COMMAND,'SET AUTOCOMMIT=0')) { fatalError('Setting MYSQLI_INIT_COMMAND failed'); } if (!$mysqli->options(MYSQLI_OPT_CONNECT_TIMEOUT, 5)) { fatalError('Setting MYSQLI_OPT_CONNECT_TIMEOUT failed'); } if (!$mysqli->real_connect($db_host, $db_user, $db_pass, $db_db)) { fatalError('Connect Error (' . mysqli_connect_errno() . ') ' . mysqli_connect_error()); } return $mysqli; } //////////////////////////// function fatalError($error) //////////////////////////// { $logFile="../logs/error_log"; $fp=fopen($logFile,"a"); fwrite($fp,date() . " $error\n"); fclose($fp); ///>> we exit on fatal errors exit; } /////////////////////////// function getTypes($types,$stmt) /////////////////////////// { $p=array(); $cnt=0; foreach ($types as $loop) { $tmp="param".$cnt; if (is_int($loop)) { $t='i'; } elseif (is_double($loop)) { $t='d'; } else { $t='s'; } $p[$tmp]=$t; $cnt++; } return $p; } //////////////////////////// function get_result($stmt) //////////////////////////// { $result=array(); $metadata=$stmt->result_metadata(); $fields=$metadata->fetch_fields(); $resultRows=0; for (;;) { $pointers=array(); $row=new stdClass(); $pointers[]=$stmt; foreach ($fields as $field) { $fieldname=$field->name; $pointers[]=&$row->$fieldname; } call_user_func_array(mysqli_stmt_bind_result, $pointers); if (!$stmt->fetch()) { break; } $col=0; foreach ($fields as $field) { $fieldName=$field->name; //fix single,double quotes $real_value=$row->$fieldName; $real_value=stripslashes($real_value); $result[$resultRows][$col]=$real_value; //$result[$resultRows][$col]=$row->$fieldName; $col++; } $resultRows++; } $metadata->free(); return $result; } /////////////////////////// function get_mysqli($sql_query,$binds,$save_memcache,$memcache_prefix,$memcache_expire,$send_array,$print_out) /////////////////////////// { global $mysqli; global $memcache; if ($print_out==1) { echo $sql_query.'
';
		print_r($binds);
		}
	
	if (preg_match("/^\s*((insert)|(delete)|(update))/i",$sql_query))
		{
		$save_memcache=0;
		$skip_return=1;
		//reset saved query, so we can actually see the change that was just made
		//////////??????????????  BUT HOW???  oh how indeed
		}
	
	$key=$memcache_prefix . "query-" . md5(preg_replace("/\s+/","",$sql_query . implode("",$binds)));

	if ($save_memcache)
                {
                if ($memVal=$memcache->get($key))
                        {
                        return $memVal;
                        }
                }

	$stmt=$mysqli->prepare($sql_query);
	$params=getTypes($binds,$stmt);
	
	$opts[]=$stmt;
	foreach (array_keys($params) as $loop)
                {
		$opts['type'].=$params[$loop];
		$opts[]=array_shift($binds);
                }
	call_user_func_array(mysqli_stmt_bind_param,$opts);

	$stmt->execute();

	if ($skip_return) {return 1;}

	$results=get_result($stmt);

	///>> if only one row of results send back one
	if (count($results)==1 && !$send_array)
		{
		if ($save_memcache)
    	{
      $memcache->set($key,$results[0],1,$memcache_expire);
      }

		return $results[0];	
		}
	else	{
		if ($save_memcache)
    	{
      $memcache->set($key,$results,1,$memcache_expire);
      }

		return $results;
		}
	
	}

// Check IP before we allow them into the site
run_ip_check($_ENV['REMOTE_ADDR']);

//mysql
$con = mysql_connect('localhost','vandco_db66','JHSD3287y%%');
if (!$con) {die('Could not connect: ' . mysql_error());}
mysql_select_db('vandco_db66', $con);

///////////////////////////
function get_mysql($sql_query,$type) {  
///////////////////////////
$sth=mysql_query("$sql_query");
if ($type=="manyrows")
        {
        for ($i=0;$i $totalpages)
                {
                $currentpage=$totalpages;
                }

        if ($currentpage < 1)
                {
                $currentpage = 1;
                }

        $offset=($currentpage - 1) * $rowsperpage;

        $limit_statement=" LIMIT $offset, $rowsperpage";

        if ($currentpage > 1)
                {
                $pagination.=" << ";
                $prevpage = $currentpage - 1;
                $pagination.=" < ";
                }

        for ($x = ($currentpage - $page_range); $x < (($currentpage + $page_range) + 1); $x++)
                {
                if (($x > 0) && ($x <= $totalpages))
                        {
                        if ($x == $currentpage)
                                {
                                //$pagination.=''.$x.' | ';
                                $pagination.=''.$x.' | ';
                                $realPage='?currentpage='.$x;
                                }
                        else    {
                                $pagination.=" $x | ";
                                }
                        }
                }
				$pagination=preg_replace("/\s+\|\s+$/","",$pagination);
        if ($currentpage != $totalpages)
                {
                $nextpage = $currentpage + 1;
                $pagination.=" > ";
                $pagination.=" >> ";
                }

        return array($limit_statement,$pagination,$realPage);
        }
////////////////////////////
function getFileContents($fileName)
////////////////////////////
        {
        if (!is_file($fileName)) 
        	{
        	$fileName="../".$fileName;
        	}
        if (!is_file($fileName))
        	{
        		return false;
        	}
        $fp=fopen($fileName, "r");
        while (!feof ($fp))
                {
                $buffer=fgets($fp, 4096);
                $pageContents.=$buffer;
                }

        ///>> stupid include crap
        if (preg_match("//",$pageContents))
                {
                $pageContents=preg_replace("//ie",
                        "''.getFileContents('\\1').''",$pageContents);
                }

        if (preg_match("//i",$pageContents))
                {
								$pageContents=preg_replace("//ie",
                        "''.getFileContents('\\1').''",$pageContents);
                }


        return $pageContents;
        }
////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////
function upload_photo($image,$image_tmp,$image_size,$did,$type)
////////////////////////////////////////////////////////////////////////////////////////
				{
				if ($image_size > "1024000000")
	 				{
	  			$error="File too large, please reformat!";	
	  			}
				else {
			 			 preg_match("/\.\S[^\.]+$/",$image,$ext);
			 			 if ($type=='products')
			 			 	 {
			 			 	 $image_uploaded_name=$type.'_'.$did.$ext[0];
			 			 	 move_uploaded_file($image_tmp, IMAGES_PRODUCTS_DIR.$image_uploaded_name);	 
			 			 	 chmod(IMAGES_PRODUCTS_DIR.$image_uploaded_name, 0767); 
			 			 	 get_mysqli('update products set product_image=? where product_id=?',array($image_uploaded_name,$did));
			 			 	 }
			 			 elseif ($type=='specials')
			 			 	 {
			 			 	 $image_uploaded_name=$type.'_'.$did.$ext[0];
			 			 	 move_uploaded_file($image_tmp, IMAGES_SPECIALS_DIR.$image_uploaded_name);	 
			 			 	 chmod(IMAGES_SPECIALS_DIR.$image_uploaded_name, 0644); 
			 			 	 get_mysqli('update specials set special_image=? where special_id=?',array($image_uploaded_name,$did));
			 			 	 }
			 			 elseif ($type=='brochure')
			 			 	 {
			 			 	 $image_uploaded_name=$type.'_'.$did.$ext[0];
			 			 	 move_uploaded_file($image_tmp, IMAGES_BROCHURE_DIR.$image_uploaded_name);	 
			 			 	 chmod(IMAGES_BROCHURE_DIR.$image_uploaded_name, 0644); 
			 			 	 get_mysqli('update products set product_bro=? where product_id=?',array($image_uploaded_name,$did));
			 			 	 }	 
			 			 }
			  
			  return array($image_uploaded_name,$error);
			  }
////////////////////////////
function genweirdkey()
////////////////////////////
        {
        $rccap=array(A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z);
        $rcsmall=array(a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z);
        $rcnumbers=array(1,2,3,4,5,6,7,8,9,0,9,8,7,6,5,4,3,2,1);
        $rccrap=array("!","%");

        ###>> how many of each we're going to get
	$get1=intval(rand(0,7)); $get1+=4; $get2=intval(rand(0,7)); $get2+=4; $get3=intval(rand(0,7)); $get3+=4; $get4=intval(rand(0,7)); $get4+=4;

        for ($i=1;$i<=$get1;$i++)
                {
                $getcrap=intval(rand(0,25)); $letcap[$count1]=$rccap[$getcrap];  $count1++;
                }
        for ($i=1;$i<=$get2;$i++)
                {
                $getcrap=intval(rand(0,25)); $letsm[$count2]=$rcsmall[$getcrap]; $count2++;
                }
        for ($i=1;$i<=$get3;$i++)
                {
                $getcrap=intval(rand(0,18)); $num[$count3]=$rcnumbers[$getcrap]; $count3++;
                }
        for ($i=1;$i<=$get4;$i++)
                {
                $getcrap=intval(rand(0,9)); $let[$count4]=$rccrap[$getcrap]; $count4++;
                }
        $final=implode(" ", $letcap); $final.=implode(" ", $letsm); $final.=implode(" ", $num); $final.=implode(" ", $let);
        $final=preg_replace("/\s/","",$final); $scrambled=$final;

        for ($i=1;$i<=20;$i++)
                {
                $length=strlen($scrambled); $length--;
                $finder=intval(rand(0,$length));
                $first=substr($scrambled,$finder,2);
                $scrambled=ereg_replace($first,'',$scrambled);
                $scrambled.=$first;

                $length=strlen($scrambled); $length--;
                $finder2=intval(rand(0,$length));
                $second=substr($scrambled,$finder2,2);
                $scrambled=ereg_replace($second,'',$scrambled);
                $scrambled.=$second;
                }
        
        $lovely=substr($scrambled,0,8);
        
        return $lovely;
        }


///////////////////////////////////
function get_curl($url,$post,$params,$cookies,$ref)
///////////////////////////////////
	{
	//echo "url: $url
// post: $post
// params: $params
// cookies: $cookies
// ref: $ref
// -------------------------------

"; //Host products.wackerneuson.com //User-Agent //Accept text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8 //Accept-Language en-us,en;q=0.5 //Accept-Encoding gzip, deflate //Accept-Charset ISO-8859-1,utf-8;q=0.7,*;q=0.7 //Connection keep-alive //Referer http://products.wackerneuson.com/webapp/ecomm/itemDisplay?page=6&partNbr=0610010 //Cookie JSESSIONID=0000xtxLdPOzFZukC2um8QzHUDy:-1; test_cookie=test_cookie //$user_agent='Mozilla/5.0 (X11; U; Linux i686 (x86_64); en-US; rv:1.9.2.17) Gecko/20110420 Firefox/3.6.17'; $user_agent='Mozilla/5.0 (Windows NT 6.0; rv:7.0.1) Gecko/20100101 Firefox/7.0.1'; global $ch; curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_COOKIESESSION, TRUE); curl_setopt($ch, CURLOPT_HEADER, TRUE); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 0); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_COOKIE, $cookies); curl_setopt($ch, CURLOPT_USERAGENT, $user_agent); if ($ref) { curl_setopt($ch, CURLOPT_REFERER, $ref); } if ($post) { curl_setopt($ch, CURLOPT_POST, TRUE); curl_setopt($ch, CURLOPT_POSTFIELDS, $params); } elseif ($params) { foreach (preg_split("/&/",$params) as $param) { list ($k,$v)=preg_split("/=/",$param); $opts[$k]=$v; } curl_setopt_array($ch,$opts); } $result = curl_exec($ch); //curl_close($ch); return $result; } /////////////////////////////////// function get_cookies($file) /////////////////////////////////// { $cookies=""; $handle=fopen($file,'r'); if ($handle) { while (($buffer = fgets($handle, 4096)) !== false) { if (preg_match("/JESSIONID/",$buffer)) { list ($dom,$ssl,$dir,$huh,$sess,$sess_name,$session_id)=preg_split("/\s+/",$buffer); $cookies.="$sess_name=$session_id"; } } if (!feof($handle)) { return 0; } fclose($handle); } return $cookies; } ////////////////////////////////////// function get_session($text) ////////////////////////////////////// { if (preg_match("/JSESSIONID=(\S+);Path/",$text,$match)) { return $match[1]; } } function has_children($cat_id,$type_ren_pur) { $cnt=get_mysqli("select count(*) from categories where parent_id=? && category_active<>'2' && category_purchase_rent rlike ?",array($cat_id,$type_ren_pur),0,"",0,1); return $cnt[0][0]; } //recursive function that prints categories as a nested html unorderd list function generate_menu($parent,$type_ren_pur,$prod_cat_page) { $has_childs = false; global $cat_ul; $results_categories=get_mysqli('select category_id,category_name,parent_id from categories where parent_id=? && category_active<>"2" && category_purchase_rent rlike ? order by category_name',array($parent,$type_ren_pur),0,"",0,1); if ($prod_cat_page<>'prod_cat') { foreach ($results_categories as $loop) { list($category_id,$category_name,$parent_id)=$loop; $menu_array[$category_id] = array('name' => $category_name,'parent' => $parent_id); } } else { list($category_id,$category_name)=get_mysqli('select category_id,category_name FROM categories where category_id=? && category_active<>"2" && category_purchase_rent rlike ?',array($parent,$type_ren_pur),0,"",0,0); $menu_array[$category_id] = array('name' => $category_name,'parent' => $parent); } foreach($menu_array as $key => $value) { if ($value['parent'] == $parent) { //if this is the first child print '