<?php
include("xls.class.php");
error_reporting(0);
function con(){
global $globalConfig;
$db=new DB($globalConfig['dbase'], $globalConfig['dbhost'],$globalConfig['dbuser'], $globalConfig['dbpass']);
return $db;
}
// debug message: 1 = info 2 = congratulation 3 = error
function debug_message($message, $kind, $width = false){
	if(!$width){
		$width = '80';
	}
	switch($kind){
		case 1:
			$message_box = '<div class="note" align="center" style="padding:6px;" style="margin:20px auto ; padding: 0 .7em; width:'.$width.'%;"> 
<p >'.$message.'</p>
</div>';
		break;
		
		case 2:
			$message_box = '<div class="congratulation" align="center" style="margin:20px auto ; padding: 0 .7em; width:'.$width.'%;"> 
<p >'.$message.'</p>
</div>';
		break;

		case 3:
			$message_box = '<div class="warning" align="center" style="margin:20px auto ; padding: 0 .7em; width:'.$width.'%;"> 
<p >'.$message.'</p>
</div>';
		break;
	}
return $message_box;
}
function show_error($error){
global $globalConfig;
switch((int)$error){
		case 1:
			$message =$globalConfig['errorNoCookies'];
		break;
		
		case 2:
			$message =$globalConfig['errorDelay'];
		break;
		
		case 3:
			$message =$globalConfig['errorNoAdmin'];
		break;
		
		case 4:
			$message =$globalConfig['errorNoGroup'];
		break;
		
		case 5:
			$message =$globalConfig['errorNoLogin'];
		break;		
		
		case 6:
			$message =$globalConfig['errorInvalid'];
		break;
	}
return '<div dir="rtl" style="color:red; background-color:#FFC4C4; width:100%; border-bottom:1px solid #F30; border-top:1px solid #F30; text-align:left; heigh:40px; font-size:14px; font-family:tahoma;">&nbsp;&nbsp;&nbsp;&nbsp;'.$message.'&nbsp;&nbsp;&nbsp;&nbsp;</div>';
}
//download
function download_file($id,$tableid,$nametable,$file,$sorce){
      $query="select * from $nametable where $tableid=$id";
      $result=mysql_query($query) or die ("Bad Query<br>".$query);  
      $row=mysql_fetch_array($result);
	  $filename=$row[$file];
          //  $filename = realpath($filename);
            $file_extension = strtolower(substr(strrchr($filename,"."),1));
			switch ($file_extension) {
                case "pdf": $ctype="application/pdf"; break;
                case "exe": $ctype="application/octet-stream"; break;
                case "zip": $ctype="application/zip"; break;
                case "doc": $ctype="application/msword"; break;
                case "doc": case "docx":
                case "doc": $ctype="application/msword"; break;
			    case "xls": $ctype="application/vnd.ms-excel"; break;
                case "ppt": $ctype="application/vnd.ms-powerpoint"; break;
                case "gif": $ctype="image/gif"; break;
                case "png": $ctype="image/png"; break;
                case "jpe": case "jpeg":
                case "jpg": $ctype="image/jpg"; break;
                default: $ctype="application/force-download";
            }
			header("Pragma: public");
            header("Expires: 0");
            header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
            header("Cache-Control: private",false);
            header("Content-Type: $ctype");
            header("Content-Disposition: attachment; filename=\"".basename($filename)."\";");
            header("Content-Transfer-Encoding: binary");
            header("Content-Length: ".@filesize('adminsms2010/upfiles/'.$filename));
            set_time_limit(0);
            @readfile("$sorce/$filename") or die("File not found.");
//download			
	  }
// send mail
function send_mail($user_id, $subject, $message){
	$db = con();
	$from = '<info@motormarket.com> Motor Market ';
	$email = 'info@motormarket.com';
	$sql = $db->query("select email from u_users where ID = '".(int)$user_id."'");
	$res = $db->fetchNextArray($sql);
	$to = $res['email'];
	$header  = "MIME-Version: 1.0\r\n";
	$header .= "Content-type: text/html; charset=utf-8\r\n";
	$header .= "To: ".$to."\r\n";
	$header .= "From: ".$from." <".$email.">\r\n";
	$header .= "Cc: \r\n";
	$messagebody ='<div style="width:700px; margin:auto;">
	<div class="body" style="background: none repeat scroll 0 0 #FF6600;
    border: 2px solid #DDDDDD;
    border-radius: 6px 6px 6px 6px;
    bottom: 4px;
    box-shadow: 0 0 6px #000000;
    color: #FFFFFF;
    direction: rtl;
    font-family: tahoma;
    font-size: 12px;
    height: auto;
    line-height: 18px;
    margin-left: 0;
    margin-top: -1px;
    padding: 4px 8px;
    text-align: right;
    width: 500px;">
	'.$message.'
	</div>
	</div>';
	@mail($to, $subject, $messagebody, $header);
}
function direct_mail($email, $subject, $message){
	$db = con();
	$from = 'شرکت بهینه سازی ارتباطات و اطلاعات دانا پژوه';
	$email = 'info@e-learningcenter.ir';
	$to = $email;
	$header  = "MIME-Version: 1.0\r\n";
	$header .= "Content-type: text/html; charset=utf-8\r\n";
	$header .= "To: ".$to."\r\n";
	$header .= "From: ".$from." <".$email.">\r\n";
	$header .= "Cc: \r\n";
	$message .='<br><span style="font-family:Tahoma, Arial; font-size:12px;">'.date("l d F Y").'</span>';
	@mail($to, $subject, $message, $header);
}
//==========================================================
// send mail test email
function send_mail_test($code,$email_recpies){
	$db = con();
	$from = 'chitasms';
	$email = 'info@chitasms.com';
	$to = $email_recpies;
	$header  = "MIME-Version: 1.0\r\n";
	$header .= "Content-type: text/html; charset=utf-8\r\n";
	$header .= "To: ".$to."\r\n";
	$header .= "From: ".$from." <".$email.">\r\n";
	$header .= "Cc: \r\n";
	$subject = 'ارسال اس ام اس رایگان';
	$message .='<div style="direction:rtl;text-align:right;">با سلام <br/>برای ارسال پیامک تستی روی لینک زیر کلیک کنید<br/><a href="http://chitasms.com/test_sending.php?act=second_step&code='.$code.'">http://chitasms.com/test_sending.php?act=second_step&code='.$code.'</a><br/>با تشکر تیم چیتا اس ام اس<br><span style="font-family:Tahoma, Arial; font-size:12px;">'.date("l d F Y").'</span>';
	mail($to, $subject, $message, $header);
}
//name user==================================================
function name_user($ID){
	global $db;
      $query="select * from u_users where ID='".(int)$ID."'";
      $result=$db->query($query) ;  
      $row=$db->fetchNextArray($result);
	  return $row['userName'];
}
//name user==================================================
function name_user_lastName($ID){
	global $db;
      $query="select * from u_users where ID='".(int)$ID."'";
      $result=$db->query($query) ;  
      $row=$db->fetchNextArray($result);
	  return $row['name'] . ' ' .$row['lastName'] ;
}
//tell user
function tell_user($ID){
	global $db;
      $query="select tell from u_users where ID='".$ID."'";
      $result=$db->query($query) ;  
      $row=$db->fetchNextArray($result);
	  return $row['tell'];
}
//mobile user
function mobile_user($ID){
	global $db;
      $query="select mobile from u_users where ID='".$ID."'";
      $result=$db->query($query) ;  
      $row=$db->fetchNextArray($result);
	  return $row['mobile'];
}
//email user
function email_user($ID){
	global $db;
      $query="select email from u_users where ID='".$ID."'";
      $result=$db->query($query) ;  
      $row=$db->fetchNextArray($result);
	  return $row['email'];
}
//address user
function address_user($ID){
	global $db;
      $query="select address from u_users where ID='".$ID."'";
      $result=$db->query($query) ;  
      $row=$db->fetchNextArray($result);
	  return $row['address'];
}

//====================================================
	function get_years ($selected, $name = 'year') {
		$from = 1391;
		$to = 1300;
		$text = '<select name="'.$name.'">';
		$text .= '<option value="0">سال</option>';
		for ($i=$from;$i>=$to; $i--) {
		$selected_text = '';
			if ($i == $selected) $selected_text = 'selected="selected"';
			if (($i == 1389) && ($selected == '')) $selected = 'selected="selected"';
			$text .= '<option value="'.$i.'" '.$selected_text.'>'.$i.'</option>';
		}
		$text .= '</select>';
	return $text;
	}
//====================================================
	function get_years2 ($selected, $name = 'year') {
		$from = 1391;
		$to = 1390;
		$text = '<select name="'.$name.'">';
		$text .= '<option value="0">سال</option>';
		for ($i=$from;$i>=$to; $i--) {
		$selected_text = '';
			if ($i == $selected) $selected_text = 'selected="selected"';
			if (($i == 1390) && ($selected == '')) $selected = 'selected="selected"';
			$text .= '<option value="'.$i.'" '.$selected_text.'>'.$i.'</option>';
		}
		$text .= '</select>';
	return $text;
	}
//====================================================
	function get_monthes ($selected, $name = 'month') {
		$from = 1;
		$to = 12;
		$text = '<select name="'.$name.'">';
		$text .= '<option value="0">ماه</option>';
		for ($i=$from;$i<=$to; $i++) {
		$selected_text = '';
			if ($i == $selected) $selected_text = 'selected="selected"';
			$text .= '<option value="'.$i.'" '.$selected_text.'>'.$i.'</option>';
		}
		$text .= '</select>';
	return $text;
	}
//====================================================
	function get_days ($selected, $name = 'day') {
		$from = 1;
		$to = 31;
		$text = '<select name="'.$name.'">';
		$text .= '<option value="0">روز</option>';
		for ($i=$from;$i<=$to; $i++) {
		$selected_text = '';
			if ($i == $selected) $selected_text = 'selected="selected"';
			$text .= '<option value="'.$i.'" '.$selected_text.'>'.$i.'</option>';
		}
		$text .= '</select>';
	return $text;
	}
//====================================================
	function get_hours ($selected, $name = 'hour') {
		$from = 1;
		$to = 24;
		$text = '<select name="'.$name.'">';
		for ($i=$from;$i<=$to; $i++) {
		$selected_text = '';
			if ($i == $selected) $selected_text = 'selected="selected"';
			$text .= '<option value="'.$i.'" '.$selected_text.'>'.$i.'</option>';
		}
		$text .= '</select>';
	return $text;
	}
//====================================================
	function get_minutes ($selected, $name = 'minute') {
		$from = 0;
		$to = 59;
		$text = '<select name="'.$name.'">';
		for ($i=$from;$i<=$to; $i++) {
		$selected_text = '';
			if ($i == $selected) $selected_text = 'selected="selected"';
			$text .= '<option value="'.$i.'" '.$selected_text.'>'.$i.'</option>';
		}
		$text .= '</select>';
	return $text;
	}
//====================================================
	function get_credit_amount($user_id){
		$db = con();
		$sql = $db->query("select amount from credit where user_id='".(int)$user_id."'");
		$res = $db->fetchNextArray($sql);
		
	return $res['amount'];
	}

	
//====================================================
	function decrease_from_credit_amount($user_id, $amount) {
		$db = con();
		$sql = $db->execute("update credit SET amount = amount - ".(int)$amount." where user_id='".(int)$user_id."'");
	return true;
	}
//====================================================
	function increase_credit_amount($user_id, $amount) {
		$db = con();
		$sql = $db->execute("update credit SET amount = amount + ".(int)$amount." where user_id='".(int)$user_id."'");
	return true;
	}
//====================================================
function get_bank_amount($user_id){
		$db = con();
		$sql = $db->query("select amount from bank where user_id='".(int)$user_id."'");
		$res = $db->fetchNextArray($sql);
	return $res['amount'];
}
//====================================================
function get_bank_x_amount($user_id){
		$db = con();
		global $credit_amount;
		$sql = $db->query("select amount_x from bank where user_id='".(int)$user_id."'");
		$res = $db->fetchNextArray($sql);
	return $res['amount_x'];
}
//====================================================
	function decrease_from_bank_amount($user_id, $amount) {
		$db = con();
		$sql = $db->execute("update bank SET amount = amount - ".(int)$amount." where user_id='".(int)$user_id."'");
	return true;
	}
//====================================================
	function increase_bank_amount($user_id, $amount) {
		$db = con();
		$sql = $db->execute("update bank SET amount = amount + ".(int)$amount." where user_id='".(int)$user_id."'");
	return true;
	}
//====================================================
	function get_parent_id ($parent_name) {
		$db = con();
		$sql = $db->query("SELECT ID FROM u_users WHERE userName = '".$db->safe_string($parent_name)."'");
		$res = $db->fetchNextArray($sql);
	return $res['ID'];
	}
	
//====================================================
	function get_user_name ($userID) {
		$db = con();
        $query="select userName from u_users where ID='".(int)$userID."'";
        $result=$db->query($query);  
        $row=$db->fetchNextArray($result);
	return $row['userName'];
	}
//====================================================
	function get_member_days ($userID) {
		$db = con();
		$today = g_days_of_year(date("m"),date("d"),date("Y"));
		$query="select date from u_users where ID='".(int)$userID."'";
        $result=$db->query($query) ;  
        $row=$db->fetchNextArray($result);
		$member_date = explode("-",$row['date']);
		$first_day = g_days_of_year($member_date[1], $member_date[2], $member_date[0]);
		if($member_date[0] == date("Y")){
			$days = $today - $first_day;
		}elseif((date("Y") - $member_date[0]) == 1){
			$days = ($today + (365 - $first_day));
		}
		return $days;
	}
//====================================================
	function get_member_name ($userID) {
		$db = con();
        $query="select name_lastname from u_users where ID='".(int)$userID."'";
        $result=$db->query($query);  
        $row=$db->fetchNextArray($result);
	return $row['name_lastname'];
	}
//====================================================
	function get_user_level ($userID) {
		$db = con();
        $query="select status from u_users where ID='".(int)$userID."'";
        $result=$db->query($query);  
        $row=$db->fetchNextArray($result);
	return (int)$row['status'];
	}
//======================================================
	function get_message_counter ($userID) {
		$db = con();
		$sql = $db->query("SELECT * FROM messages_user WHERE r_m_user = '".(int)$userID."' and dell_r = '0'");
		$num = $db->numRows($sql);
	return $num;
	}
//======================================================
function generatePassword($length = 8){

  // start with a blank password
  $password = "";

  // define possible characters
  $possible = "0123456789bcdfghjkmnpqrstvwxyz"; 
    
  // set up a counter
  $i = 0; 
    
  // add random characters to $password until $length is reached
  while ($i < $length) { 

    // pick a random character from the possible ones
    $char = substr($possible, mt_rand(0, strlen($possible)-1), 1);
        
    // we don't want this character if it's already in the password
    if (!strstr($password, $char)) { 
      $password .= $char;
      $i++;
    }

  }

  // done!
  return $password;

}
//==============================================
	function getFlagID($countryID){
		$db = con();
		$sql = $db->query("SELECT flag_id FROM country WHERE country_id = '".(int)$countryID."'");
		$res = $db->fetchNextArray($sql);
		return $res['flag_id'];
	}
//==============================================

	
	function sql2XLS($fileName, $tableName, $fields, $names, $whereClaus = '', $orderBy = '', $limit = ''){
		$db =con();
		$xl = new xls();
		$selects = "";
		$selectNum = count($fields);
		$i = 1;
		foreach($fields as $field){
			$selects .= "$field AS ".$names[$i];
			if($i < $selectNum){
				$selects .= ", ";
			}
			$i++;
		}
		$sql = $db->query("SELECT $selects FROM $tableName $whereClaus $limit");
		$k = 1;
		foreach($fields as $field){
			$xl->add_cell("1:$k", $names[$k]);
			$j = 2;
			while($res = $db->fetchNextArray($sql)){
				$xl->add_cell("$k:$j",$res [$names[$k]]);
				$j++;
			}
			$k++;
		}
		$xl->execute("$fileName.xls");
	}
//==================================================

	function getDiff ($a, $b) {
		if($a >= $b) {
			if(($a - $b) < 10) {
				return true;
			}else{
				return false;
			}
		}elseif($a < $b) {
			if(($b - $a) < 10) {
				return true;
			}else{
				return false;
			}
		}
	}

//-----------------------------------------------------
function user_location($userID){
	$db =con();
	$res_gorooh = $db->fetchNextArray($db->query("SELECT * FROM goroohe_karbaran WHERE user_id = '".$userID."'"));
	$location = $res_gorooh['location'];
	if($location==1){
		$return_location='اعتبار شما به اتمام رسیده است برای استفاده از خدمات سایت ، پلن مورد نظر خود را خریداری نمایید';
	}elseif($location==2){
		$return_location='مدت عضویت شما به اتمام رسیده است برای استفاده از خدمات سایت ، پلن مورد نظر خود را خریداری نمایید';
	}elseif($location==3){
		$return_location='اعتبار شما به اتمام رسیده است  برای استفاده از خدمات سایت ، پلن مورد نظر خود را خریداری نمایید';
	}
	return $return_location;
}
//=================================
function categoryNameLa($cat,$la){
	$db = con();
	$query=$db->query("select categoriesName from categoriesdescription where categoriesID='".$cat."' and languagesID = '".$la."'");	
	$row=$db->fetchNextArray($query);
	return $row['categoriesName'];
}
//=================================
function productName($products_id){
	$db = con();
	$query=$db->query("select name from ads where id='".$products_id."' ");	
	$row=$db->fetchNextArray($query);
	return $row['name'];
}
//=================================
function productDescription($products_id){
	$db = con();
	$query=$db->query("select descriptions from ads where id='".$products_id."' ");	
	$row=$db->fetchNextArray($query);
	return $row['descriptions'];
}
//=================================
function productPrice($products_id){
	$db = con();
	$query=$db->query("select price from ads where id='".$products_id."' ");	
	$row=$db->fetchNextArray($query);
	return $row['price'];
}
//=================================
function returnConfig($fild){
	$db = con();
	$query=$db->query("select * from configuration where id=1");
	$res=$db->fetchNextArray($query);
	return $res[$fild];
}
//=================================
function returnConfigPortal($fild){
	$db = con();
	$query=$db->query("select * from chitaportal where portalID=1");
	$res=$db->fetchNextArray($query);
	return $res[$fild];
}
//=================================
function returnConfigAd($fild){
	$db = con();
	$query=$db->query("select * from config where config_id =1");
	$res=$db->fetchNextArray($query);
	return $res[$fild];
}
//==================================
function sendSms($urltopost,$user,$pass,$msgBody,$recNums,$smsid=0){
	$db = con();
		$query=$db->query("select * from configuration where id =1");
			$res=$db->fetchNextArray($query);
			$urltopost = $urltopost;
			$fullmsg = $msgBody;
			$datatopost = array (
			"login" => 'motormarket',
			"pass" =>'chitasoft',
			"msgBody" => $fullmsg,
			"recNums" => $recNums,
			"senderNum" => '9830004526210516',
			"getsmsid" => $smsid,
			"send" => 'submit'
			);
		$ch = curl_init ();
		curl_setopt($ch, CURLOPT_URL, "http://www.chitasms.com/sendByPost.php");
		curl_setopt ($ch, CURLOPT_POSTFIELDS, $datatopost);
		curl_setopt ($ch, CURLOPT_RETURNTRANSFER, true);
		curl_setopt ($ch, CURLOPT_FOLLOWLOCATION, 1);
		$returndata = curl_exec ($ch);
}
//=================================
function smsInsert($userID,$from_num,$to_num,$text_message ,$date=''){
	$db = con();
	$db->execute("INSERT INTO sms_records SET user_id = '".(int)$userID."',
											  from_num = '".$from_num."',
											  to_num = '".$to_num."',
											  text_message='".$text_message."' ,
											  date = now()");
}
//=================================
function make_menu($usergroup, $parentid){
	global $db;
    $result = $db->query("SELECT * FROM m_user_menu where usergroup = '".$usergroup."' and parent = '" . $parentid . "' AND position=2  order BY id ASC");
	$num=$db->numRows($result);
	if($num){
		if ($parentid == 0){
			echo '
				<div class="menu-base">
					<ul id="jsddm">'."\n";
		}else{ echo '	<ul >'."\n";}
		$i=1;
			while ($r = $db->fetchNextArray($result)){
				if($i==8){
					$menu_base= 'class="menu-base"';
					$last= 'class="last"';
					$div= '</ul><div><ul>';
				}elseif($i==15){
					$last= 'class="last"';
				}else{
					$menu_base= '';
					$div='';
					$last='';
					//$div= '</ul></div>';
				}
				$cn = $r["title"];
				$ci = $r["id"];
				$link = $r["link"];
				echo '		<li '.$last.'> <a href="'.$link.'">'.$cn.'</a> '."\n";
						make_menu($usergroup, $ci);
				echo '		</li>'."\n";
				echo $div;
				$i++;
			}
		echo '</ul>'."\n";
	}
}
//=================================
function make_menuFooter($usergroup, $parentid){
	global $db;
    $result = $db->query("SELECT * FROM m_user_menu where usergroup = '".$usergroup."' and parent = '" . $parentid . "' AND position=2  order BY id ASC");
	$num=$db->numRows($result);
	if($num){
		if ($parentid == 0){
			echo '
				<div  class="footer-link-base">
					<ul >'."\n";
		}else{ echo '	<ul>'."\n";}
		$i=1;
			while ($r = $db->fetchNextArray($result)){
				if($i==8){
					$menu_base= '';
					$div= '</ul><ul>';
				}
				elseif($i==15){
					$menu_base= '';
				}else{
					$menu_base= '';
					$div='';
					//$div= '</ul></div>';
				}
				$cn = $r["title"];
				$ci = $r["id"];
				$link = $r["link"];
				echo '		<li '.$menu_base.'> <a href="'.$link.'">'.$cn.'</a> '."\n";
						make_menu($usergroup, $ci);
				echo '		</li>'."\n";
				echo $div;
				$i++;
			}
		echo '</ul></div>'."\n";
	}
}
//=================================
function make_menuMap($usergroup, $parentid){
	global $db;
    $result = $db->query("SELECT * FROM m_user_menu where usergroup = '".$usergroup."' and parent = '" . $parentid . "' AND position=2  order BY id ASC");
	$num=$db->numRows($result);
	if($num){
		if ($parentid == 0){
			echo '
				<div  class="">
					<ul >'."\n";
		}else{ echo '	<ul>'."\n";}
		$i=1;
			while ($r = $db->fetchNextArray($result)){
				if($i==8){
					$menu_base= '';
					$div= '</ul><ul>';
				}
				elseif($i==15){
					$menu_base= '';
				}else{
					$menu_base= '';
					$div='';
					//$div= '</ul></div>';
				}
				$cn = $r["title"];
				$ci = $r["id"];
				$link = $r["link"];
				echo '		<li '.$menu_base.'> <a href="'.$link.'">'.$cn.'</a> '."\n";
						make_menu($usergroup, $ci);
				echo '		</li>'."\n";
				echo $div;
				$i++;
			}
		echo '</ul></div>'."\n";
	}
}

//====================================================
function make_menuControlPanel($usergroup, $parentid,$condition=''){
	global $db;

    $result = $db->query("SELECT * FROM m_user_menu where usergroup = '".$usergroup."' and parent = '" . $parentid . "' AND position=1 $condition  order BY id ASC");
	$num=$db->numRows($result);
	if($num){
		if ($parentid == 0){
			echo '<ul id="nav1">'."\n";
		}else{ echo '	<ul>'."\n";}
	
			while ($r = $db->fetchNextArray($result)){
				$cn = $r["title"];
				$ci = $r["id"];
				$link = $r["link"];
				echo '		<li><span class="dir"><a href="'.$link.'">'.$cn.'</a> '."\n";;
						make_menuControlPanel($usergroup, $ci);
				echo '		</span></li>'."\n";
			}
		echo '	</ul>'."\n";
	}
	
}
//---------------------------------------------------------
function getsuffix($filename){

    return end(explode('.', $filename));
}
//-----------------------------------------------------
function user_group($userID){
	$db =con();
	$res = $db->fetchNextArray($db->query("SELECT * FROM u_users WHERE ID = '".$userID."'"));
	$userGroup = $res['userGroup'];
	return $userGroup;
}
//=================================
function getTypeusecatName($catID){
	$db = con();
	$query=$db->query("select nameCat from typeusecat where catID='".$catID."'");	
	$row=$db->fetchNextArray($query);
	return $row['nameCat'];
}
//=================================
function getProvinceName($ProvinceID){
	$db = con();
	$query=$db->query("select ProvinceName from province where ProvinceID ='".$ProvinceID."'");	
	$row=$db->fetchNextArray($query);
	return $row['ProvinceName'];
}
//=================================
function getCityName($CityID){
	$db = con();
	$query=$db->query("select CityName from city where CityID ='".$CityID."'");	
	$row=$db->fetchNextArray($query);
	return $row['CityName'];
}
//================================================
function get_status_payment($status){
			if($status == 1){$Pstatus = '<font color="#FF9900"> پرداخت آنلاین</font>';}
			elseif($status == 2){$Pstatus = '<font color="#009900"> واریز به حساب</font>';}
			elseif($status == 3){$Pstatus = '<font color="#FF0000"> پرداخت در محل </font>';}
			elseif($status == 4){$Pstatus = '<font color="#006600">پرداخت در محل </font>';}
			else{$Pstatus = '<font color="#000">پرداخت نشده</font>';}
return $Pstatus;
}
//=================================
function detailOid($orderId){
	$db=con();
	$query=$db->query("select * from orders_products where orders_id='".$orderId."' ");
		while($row=$db->fetchNextArray($query)){
		     $product .= '<div dir="rtl"> » ( '.$row['products_id'].' ) '.$row['products_name'].'</div>';	
		}
	return $product;	
			
}
//================================================
function get_status_orders($status){
			if($status == 1){$Pstatus = '<font color="#FF0000">لغو </font>';}
			if($status == 2){$Pstatus = '<font color="#FF9900">در انتظار</font>';}
			if($status == 3){$Pstatus = '<font color="#663300">در حال پردازش </font>';}
			if($status == 5){$Pstatus = '<font color="#006600">ارسال شده </font>';}
			if($status == 6){$Pstatus = '<font color="#006600">تحویل شده </b></font>';}
return $Pstatus;
}
//==============================
function stateEpaye($orderID){
		$db=con();
		$sql =$db->query("select * from orders where order_id ='".$orderID."' ");
        $row = $db->fetchNextArray($sql);
		 if($row['payment']=='1'){
			$stateEpaye= 'پرداخت شده';
		}else{
			$stateEpaye ='<a style="color:#000" href="epay.php?orderID='.$orderID.'">
			پرداخت نشده   <img src="images/dolar.gif" alt="پرداخت هزینه سفارش" title="پرداخت هزینه سفارش" ></a>';
		}
	return $stateEpaye;
}
//==============================
function stateEpayFactor($orderID){
		$db=con();
		$sql =$db->query("select * from orders where order_id ='".$orderID."' ");
        $row = $db->fetchNextArray($sql);
		$num = $db->fetchNextArray($sql);
         if($row['payment']=='1'){
			 $stateEpaye= 'پرداخت شده';
		}else{
			$stateEpaye ='پرداخت نشده ';
		}
	return $stateEpaye;
}
//==================================
function stateNaja($userID){
	$db = con();
	$query=$db->query("select * from u_users where ID='".$userID."'");	
	$res=$db->fetchNextArray($query);
	if($res['statusNaja']==0){
		return 'تایید نشده';
	}elseif($res['statusNaja']==1){
		return 'تایید شده';	
	}
}

//==================================
function stateCompany($userID){
	$db = con();
	$query=$db->query("select * from u_users where ID='".$userID."'");	
	$res=$db->fetchNextArray($query);
	if($res['statusCompany']==0){
		return 'تایید نشده';
	}elseif($res['statusCompany']==1){
		return 'تایید شده';	
	}
}
//==================================
function getReturnNemayandeh($userID){
	$db = con();
	$query=$db->query("select * from u_users where ID='".$userID."'");	
	$res=$db->fetchNextArray($query);
	if($res['parent_id']){
		return 'کد : ' .$res['parent_id'] .' | نام : '.name_user_lastName($res['parent_id']) ;
	}else{
		return 'شرکت';	
	}
}
//==================================
function getAmountSettelَََ($settle_id ){
	$db = con();
	$query=$db->query("select * from settle where settle_id='".$settle_id."'");	
	$res=$db->fetchNextArray($query);
	return $res['amount'];
}
//====================================
function returnPriceMojavez($productID,$countProduct){
$db=con();
	$query=$db->query("select * from products where productID='".$productID."'");	
	$res=$db->fetchNextArray($query);
	$License=$res['License'];
	$countLicense=$res['countLicense'];
	$priceLicense=$res['priceLicense'];								
	if($License==1){
		if($countProduct <= $countLicense){
			$FpriceLicense=$priceLicense;
		}else{
			$countMojavez = $countProduct / $countLicense;
			$Rcount = $countProduct % $countLicense;
			if($Rcount >0){
				$FcountMojavez=1+ (int)$countMojavez;
			}else{
				$FcountMojavez= (int)$countMojavez;
			}
			$FpriceLicense=(int)$FcountMojavez * $priceLicense;
		}
	}else{
		$FpriceLicense=0;	
	}
	return $FpriceLicense;
}
//=====================================
function orderName($oID){
	$db=con();
	$sql=$db->query("select * from orders where order_id = '".$oID."'");
	$res=$db->fetchNextArray($sql);
	return name_user_lastName($res['userID']);
}
//---------------------------------------------------------------------------------------
function getExpireDate ($aFromDate,$aAddDays){
	// aFromDate on the format YYmd, like 20040212
	$from_year=substr($aFromDate,0,4);
	$from_month=substr($aFromDate,4,2);
	$from_day=substr($aFromDate,6,2);
	$expire_date_conv = formatDate(date ("Ymd", mktime (date("H"),date("i"),date("s"),$from_month,$from_day+$aAddDays,$from_year)));  
	return $expire_date_conv;
}
//----------------------------------------------------------------------------------------
function formatDate($aDate){
	// aDate should have Ymd format
	$date_format="y-m-d";
	$year=substr($aDate,0,4);
	$month=substr($aDate,4,2);
	$day=substr($aDate,6,2);
	// Date_format grabbed from settings...
	$date_added_1 = $date_format;
	$date_added_1 = ereg_replace("d", "$day", $date_added_1);
	$date_added_1 = ereg_replace("m", "$month", $date_added_1);
	$date_added_1 = ereg_replace("y", "$year", $date_added_1);
	$sitedate1 = $date_added_1;
	return $sitedate1;
}
//---------------------------------------------------------------------------------------
function getNumDaysRemain ($aFromDate,$aAddDays){
	// aFromDate on the format YYmd, like 20040212
	$from_year=substr($aFromDate,0,4);
	$from_month=substr($aFromDate,4,2);
	$from_day=substr($aFromDate,6,2);
	$expire_date_coded = mktime (date("H"),date("i"),date("s"),$from_month,$from_day+$aAddDays,$from_year);
	$today_date_coded = mktime (date("H"),date("i"),date("s"),date("m"),date("d"),date("Y"));
	$difference = round(($expire_date_coded-$today_date_coded) / 86400);
	return $difference;
}
//-------------------------------------------------------
function getNumDaysRemain2 ($aFromDate,$aAddDays){
	// aFromDate on the format YYmd, like 20040212
	$from_year=substr($aFromDate,0,4);
	$from_month=substr($aFromDate,5,2);
	$from_day=substr($aFromDate,8,2);
	$expire_date_coded = mktime (date("H"),date("i"),date("s"),$from_month,$from_day+$aAddDays,$from_year);
	$today_date_coded = mktime (date("H"),date("i"),date("s"),date("m"),date("d"),date("Y"));
	$difference = round(($expire_date_coded-$today_date_coded) / 172800);
	return $difference;
}
//-----------------------------------------------------
function num_ads($num_days){
if($num_days<=0){ $num_days1= 'اتمام';}else{$num_days1= $num_days. 'روز بعد';}
return $num_days1;
}
function Noimage($adID,$filename){
return '<img src="images/'.$filename.'" valign="right" border="0" title="'.$filename.'" alt="'.$filename.'"  />';
}
//========================CalcTotalCost
function CalcTotalCost($star,$expire_days){
	if($expier_days=='30'){
		$pric=$star * returnConfigAd('ad2_amount_1') * 30;
	}elseif($expire_days=='90'){
		$pric=$star * returnConfigAd('ad2_amount_2') * 90;
	}elseif($expire_days=='180'){
		$pric=$star * returnConfigAd('ad2_amount_3') * 180;
	}elseif($expire_days=='365'){
		$pric=$star * returnConfigAd('ad2_amount_12') * 365;
	}
	return $pric;
}
//------------------------------
function getOneImage_ad_k($adID,$aDescription,$aMaxSize,$aID){
	$db = con();
	$sql_picture = "select * from picture where siteid=$adID limit 1";
    $res = $db->query($sql_picture);
	$row = $db->fetchNextArray($res);
	$filename = $row["pic_name"];
	
	if($filename){
	$image = '<img src="upload/images_ad/thumb_'.$filename.'" valign="right" border="0" title="'.$aDescription.'" alt="'.$aDescription.'"  />';
	}else{$image = Noimage($adID,'k_image.png');}

return $image;
}
//------------------------------
function getOneImage_ad_m($adID,$aDescription,$aMaxSize,$aID){
	$db = con();
	$sql_picture = "select * from picture where siteid=$adID limit 1";
    $res = $db->query($sql_picture);
	$row = $db->fetchNextArray($res);
	$filename = $row["pic_name"];
	
	if($filename){
	$image = '<img src="upload/images_ad/m_'.$filename.'" valign="right" border="0" title="'.$aDescription.'" alt="'.$aDescription.'"  />';
	}else{$image = Noimage($adID,'m_no_image.jpg');}

return $image;
}
//------------------------------
function getOneImage_product_k($adID,$aDescription,$aMaxSize,$aID){
	$db = con();
	$sql_picture = "select * from products_pictures where siteid=$adID limit 1";
    $res = $db->query($sql_picture);
	$row = $db->fetchNextArray($res);
	$filename = $row["pic_name"];
	
	if($filename){
	$image = '<img src="upload/images_products/thumb_'.$filename.'" valign="right" border="0" title="'.$aDescription.'" alt="'.$aDescription.'"  />';
	}else{$image = Noimage($adID,'k_image.png');}

return $image;
}
//------------------------------
function getOneImage_product_m($adID,$aDescription,$aMaxSize,$aID){
	$db = con();
	$sql_picture = "select * from products_pictures where siteid=$adID limit 1";
    $res = $db->query($sql_picture);
	$row = $db->fetchNextArray($res);
	$filename = $row["pic_name"];
	
	if($filename){
	$image = '<img src="upload/images_products/m_'.$filename.'" valign="right" border="0" title="'.$aDescription.'" alt="'.$aDescription.'"  />';
	}else{$image = Noimage($adID,'m_no_image.jpg');}

return $image;
}
//-----------------------------
function count_orderUser($userID){
		$db=con();
	$sql=$db->query("select * from orders where userID = '".$userID."'");
	$num=$db->numRows($sql);
	return $num ;
}
//==================================getSoudCat
function getSoudCat($productCat){
	$db = con();
	$sql=$db->query("select * from categories where categoriesID  ='".$productCat."'");
	$res=$db->fetchNextArray($sql);
	$soudCat = $res['soudCat'];
	if($res['parentID']==0){
		return $soudCat;
	}else{
		getSoudCat($res['parentID']);
	}
}
//==================================returnSoudCat
function returnSoudCat($productID){
	$db = con();
	$sql=$db->query("select productCat from products where productID ='".$productID."'");
	$res=$db->fetchNextArray($sql);
	$productCat = $res['productCat'];
	$soudCat=getSoudCat($productCat);
	return $soudCat;
}
//==================================returnSoudNemayandeh
function returnSoudNemayandeh($userID,$productID){
	$db = con();
	$soudCat = returnSoudCat($productID);
	$soudPortal = returnConfigPortal('soudPortal');
	
	$sql3=$db->query("select * from u_users  where ID  ='".$userID."'");
	$res3=$db->fetchNextArray($sql3);
	$soudUser = $res3['soud'];
	
	$allSoud=$soudUser + $soudPortal + $soudCat;
	return $allSoud;
}
//==================================returnSoudNemayandeh
function returnDarsadNemayandeh($userID){
	$db = con();
	$sql3=$db->query("select * from u_users  where ID  ='".$userID."'");
	$res3=$db->fetchNextArray($sql3);
	$soudUser = $res3['soud'];
	return $soudUser;
}
//==================================getReturnNemayandehID
function getReturnNemayandehID($userID){
	$db = con();
	$query=$db->query("select * from u_users where ID='".$userID."'");	
	$res=$db->fetchNextArray($query);
	if($res['parent_id']){
		return $res['parent_id'];
	}else{
		return 0;	
	}
}
//-----------------------------------------
function get_user_available(){
		global $db;
		$sql = $db->query("SELECT * from u_users WHERE ID='".$_SESSION['userID']."'");
		$res = $db->fetchNextArray($sql);
		$statusNaja=$res['statusNaja'];
		$statusCompany =$res['statusCompany'];
		if($statusNaja==1 and $statusCompany==1){
			return 1;
		}else{
			return 0;
		}
}

//-----------------------------------------
function return_install_product($productID){
		global $db;
		$sql = $db->query("SELECT products_price2 from products WHERE productID='".$productID."'");
		$res = $db->fetchNextArray($sql);
		$products_price2=$res['products_price2'];
		return $products_price2;
}
//================================================
function planName($plan){
			if($plan == 1){$Pplan = '<font color="#999999"><b> برنزه </b></font>';}
			if($plan == 2){$Pplan = '<font color="#C0C0C0"><b> نقره ای </b></font>';}
			if($plan == 3){$Pplan = '<font color="#FF9900"><b> طلایی </b></font>';}
			if($plan == 0){$Pplan = '<font color="#006600">رایگان  </font>';}
return $Pplan;
}
//===================================================	
function dell_ads($siteid){
		$db = con();
		  $filename = "SELECT * FROM ad WHERE adID = '".$siteid."'";
		  $sql = $db->query($filename) ;
          $array = $db->fetchNextArray($sql);
		  
			  $sql = "SELECT * FROM picture WHERE siteid = '".$siteid."'";
			  $query = $db->query($sql) ;
			  while($res = $db->fetchNextArray($query)){
			  
					  if($res['pic_name']!=''){
					     unlink('upload/images_ad/big_'.$res['pic_name']);
					     unlink('upload/images_ad/m_'.$res['pic_name']);
					     unlink('upload/images_ad/thumb_'.$res['pic_name']);
	                   }
					   $db->query("delete from picture where siteid='".$siteid."'");      
			  }
 $db->query("delete from ad where adID='".$siteid."'");     
}
//===================================================	
function dell_products($siteid){
		$db = con();
		  $filename = "SELECT * FROM products WHERE pID = '".$siteid."'";
		  $sql = $db->query($filename) ;
          $array = $db->fetchNextArray($sql);
		  
			  $sql = "SELECT * FROM products_pictures WHERE siteid = '".$siteid."'";
			  $query = $db->query($sql) ;
			  while($res = $db->fetchNextArray($query)){
			  
					  if($res['pic_name']!=''){
					     unlink('upload/images_products/big_'.$res['pic_name']);
					     unlink('upload/images_products/m_'.$res['pic_name']);
					     unlink('upload/images_products/thumb_'.$res['pic_name']);
	                   }
					   $db->query("delete from products_pictures where siteid='".$siteid."'");      
			  }
 $db->query("delete from products where pID='".$siteid."'");     
}
//--------------------------------------------
function updateExpireAds_expire_days($debug){
	$db = con();
	$upd_sql = "select * from ad where Fexpire_days < now() and emailValid=0 and valid=1  ";
	$upd_result = $db->query ($upd_sql);
	  while($upd_row = $db->fetchNextArray($upd_result)){
	  $adID = $upd_row["adID"];
	  $upd_datestamp = $upd_row["datestamp"];
	  $upd_expire_days = $upd_row["expire_days"];


		$db->execute("update ad set emailValid=1 , star=0 , price =0  where adID='".$adID."'" );

	$msg = '<span style="font-family:Tahoma, Arial; font-size:12px; direction:rtl; float:right;"><span style="font-weight:bold; color:#090"> اتمام زمان آگهی : </span>  <br /> زمان فعالیت آگهی شما در سایت www.pishsakhteh.com به اتمام رسیده است جهت بروز رسانی به لینک <a href="http://www.pishsakhteh.com"></a> مراجعه کنید .	
	<br /><br /> با تشکر <br /> واحدپشتیبانی pishsakhteh.com <br /><br /> ';
	send_mail($upd_row["ad_username"], "اتمام زمان آگهی  ", $msg);
		if(mobile_user($upd_row["ad_username"])){
		sendSms(returnConfig('linkSms'),returnConfig('userNameSms'),returnConfig('passSms'),'زمان فعالیت آگهی شما در سایت www.pishsakhteh.com به اتمام رسیده است جهت بروز رسانی به سایت مراجعه نمایید  .',mobile_user($upd_row["ad_username"]));	
		smsInsert($_GET['uid'],returnConfig('smsNumber'),mobile_user($upd_row["ad_username"]),'زمان فعالیت آگهی شما در سایت www.pishsakhteh.com به اتمام رسیده است جهت بروز رسانی به سایت مراجعه نمایید  .');
		}		
	}
}
//--------------------------------------------
function usercredit($id){
	$db = con();
	 $sql = "SELECT * FROM credit WHERE user_id = '".$id."'";
			  $query = $db->query($sql) ;
			  $array=$db->fetchNextArray($query);
			   return $array['amount'];
}
function userinfo($field,$id){
	$db = con();
	 $sql = "SELECT * FROM u_users WHERE ID = '".$id."'";
			  $query = $db->query($sql) ;
			  $array=$db->fetchNextArray($query);
			   return $array[$field];
}
function seourl($kind,$id){
	$db = con();
	// we have two different kind of argomans in this function. 
	if($kind=='post'){
		
	 $sql = "SELECT * FROM parts WHERE id = '".$id."'";
			  $query = $db->query($sql) ;
			  $array=$db->fetchNextArray($query);
			  if($array['category']==11){
			 	  return 'products/'.urlencode($array['slug']); 
			  }
			 
			  else{
				  return urlencode($array['slug']); 
				  }
			  }
	if($kind=='category'){
		
	 $sql = "SELECT * FROM categories WHERE id = '".$id."'";
			  $query = $db->query($sql) ;
			  $array=$db->fetchNextArray($query);
			 	  return 'category/'.urlencode($array['slug']); 
			  }
if($kind=='doctors'){
		
	 $sql = "SELECT * FROM parts WHERE id = '".$id."'";
			  $query = $db->query($sql) ;
			  $array=$db->fetchNextArray($query);
			  if($array['category']==13){
			 	  return 'doctors/'.urlencode($array['slug']); 
			  }
			 
			  else{
				  return urlencode($array['slug']); 
				  }
			  }
			   if($kind=='tag'){
	 $sql = "SELECT * FROM tags WHERE id = '".$id."'";
			  $query = $db->query($sql) ;
			  $array=$db->fetchNextArray($query);
			 	  return 'tag/'.urlencode($array['slug']); 
			  }	

}
	function seourl1($kind,$category,$id){
	$db = con();
	// we have two different kind of argomans in this function. 
	if($kind=='ads'){
		
	 $sql = "SELECT * FROM parts WHERE id = '".$id."' ";
			  $query = $db->query($sql) ;
			  $array=$db->fetchNextArray($query);
			  
	 $sql2 = "SELECT * FROM categories WHERE id = '".$array['procat']."'";
			  $query2 = $db->query($sql2) ;
			  $array2=$db->fetchNextArray($query2);
			 
				  return 'displayproduct/'.urlencode($array2['name']).'/'.urlencode($array['name']).'/'.$array['id'];}
	
			  
				
			
	if($kind=='pages'){}
	if($kind=='displayproduct'){}

}

	//check email
	function isValid( $what, $data ) {

	switch( $what ) {

		// validate a phone number
		case 'phone':
			$pattern = "/^[0-9]{1,}$/";
		break;

		// validate email address
		case 'email':
			$pattern = "/^[_a-z0-9-]+(.[_a-z0-9-]+)*@[a-z0-9-]+(.[a-z0-9-]+)*(.[a-z]{2,3})$/i";
		break;

		default:
			return false;
		break;

	}

	return preg_match($pattern, $data) ? true : false;

}
function generatenumber ($length =15)
  {

    // start with a blank password
    $password = "";

    // define possible characters - any character in this string can be
    // picked for use in the password, so if you want to put vowels back in
    // or add special characters such as exclamation marks, this is where
    // you should do it
    $possible = "1234678912345678ABCDEFGHIJKLMNOPQRSTUVWXYZ";

    // we refer to the length of $possible a few times, so let's grab it now
    $maxlength = strlen($possible);
  
    // check for length overflow and truncate if necessary
    if ($length > $maxlength) {
      $length = $maxlength;
    }
	
    // set up a counter for how many characters are in the password so far
    $i = 0; 
    
    // add random characters to $password until $length is reached
    while ($i < $length) { 

      // pick a random character from the possible ones
      $char = substr($possible, mt_rand(0, $maxlength-1), 1);
        
      // have we already used this character in $password?
      
        // no, so it's OK to add it onto the end of whatever we've already got...
        $password .= $char;
        // ... and increase the counter by one
        $i++;
    

    }

    // done!
    return $password;

  }
  function image($pos,$width,$height){
		$image_width=$width+20;
		$image_height=$height+20;
		global $db;
	global $globalConfig;
		echo '
		<div class="kadr" align="center">
<img width="'.$width.'" height="'.$height.'" src="include/image.php/name.jpg?parameters=@width='.$image_width.'@height='.$image_height.'@cropratio=1:1@quality=100@image='.$globalConfig['baseurl'].'/'.$pos.'" />		
       </div>';
		}

function adspic($adpic,$width,$height){
	$db = con();
	global $globalConfig;
	$newwidth = $width + 10;
	$newheight = $height + 20;
    $epad = $db->query("SELECT * FROM pictures WHERE adid = '".$adpic."' && profile=1");
						$count=mysql_num_rows($epad);
						if($count>0){
						  $apd = $db->fetchNextArray($epad);?>
                        <img width="<?php echo $width;?>" height="<?php echo $height;?>" src="include/image.php/name.jpg?parameters=@width=<?php echo $newwidth;?>@height=<?php echo $newheight;?>@cropratio=1:1@quality=100@image=<?php echo $globalConfig['baseurl'].'/'.$apd['file']; ?>" />
                        <?php }else { ?>
                        <img width="<?php echo $width;?>" height="<?php echo $height;?>" src="images/nophoto.gif" />
                        <?php } 
    
	};

function newspic($adpic,$width,$height){
	$db = con();
	global $globalConfig;
	$newwidth = $width + 10;
	$newheight = $height + 20;
    $epad = $db->query("SELECT * FROM picturespart WHERE adid = '".$adpic."' && profile=1");
						$count=mysql_num_rows($epad);
						if($count>0){
						  $apd = $db->fetchNextArray($epad);?>
                        <img width="<?php echo $width;?>" height="<?php echo $height;?>" src="include/image.php/name.jpg?parameters=@width=<?php echo $newwidth;?>@height=<?php echo $newheight;?>@cropratio=1:1@quality=100@image=<?php echo $globalConfig['baseurl'].'/'.$apd['file']; ?>" />
                        <?php }else { ?>
                        <img width="<?php echo $width;?>" height="<?php echo $height;?>" src="images/nophoto.gif" />
                        <?php } 
    
	};
function posttitle($id){
	$db = con();
	global $globalConfig;
    $epad = $db->query("SELECT * FROM parts WHERE id = '".$id."'");
	$return=$db->fetchNextArray($epad);
	 echo $return['name'];
    
	};
	function posttitleen($id){
	$db = con();
	global $globalConfig;
    $epad = $db->query("SELECT * FROM parts WHERE id = '".$id."'");
	$return=$db->fetchNextArray($epad);
	 echo $return['nameen'];
    
	};
function postdescription($id){
	$db = con();
	global $globalConfig;
    $epad = $db->query("SELECT * FROM parts WHERE id = '".$id."'");
	$return=$db->fetchNextArray($epad);
	 echo nl2br($return['description']);
    
	};
function postmaindescription($id){
	$db = con();
	global $globalConfig;
    $epad = $db->query("SELECT * FROM parts WHERE id = '".$id."'");
	$return=$db->fetchNextArray($epad);
	 echo stripslashes($return['des']);
    
	};
function tags($id){
	$db = con();
	global $globalConfig;
	$epad = $db->query("SELECT * FROM tags_relations where post_id='".$id."' GROUP BY tag_id");
	$count = mysql_num_rows($epad);
	if($count > 0){
	?>
    <div class="welltag">
     <div class="tags">

    <?php
    
	while($return=$db->fetchNextArray($epad)){
		 $etagname = $db->query("SELECT * FROM tags WHERE id = '".$return['tag_id']."'");
		 $tagname=$db->fetchNextArray($etagname); ?>
         <a href="<?php echo seourl('tag',$return['tag_id']);?>" title="<?php echo $tagname['name']?>"><?php echo $tagname['name']?></a>
         <?php
		}
	?>
     <div class="clear"></div>
   </div>
   <div class="clear"></div>
    </div>
    <?php
	}
	};
function breadcrumb($kind,$id){
	?>
   <ul id="breadcrumb">
        <li><a title="خانه" href="#">خانه</a></li>

    <?php
	$db = con();
	// we have two different kind of argomans in this function. 
	if($kind=='post'){
		
	 $sql = "SELECT * FROM parts WHERE id = '".$id."'";
			  $query = $db->query($sql) ;
			  $array=$db->fetchNextArray($query);
			  if($array['category']==8){
			 	 ?>
        <li><a title="وبلاگ نارنج" href="/blog">وبلاگ نارنج</a></li>
 		<li><?php echo $array['name']?></li>
                 <?php
			  }
			  elseif($array['category']==9){
			     ?>
        <li><a title="پکیج ها" href="/packages">پکیج ها</a></li>
 		<li><?php echo $array['name']?></li>
                 <?php
				  }
			  elseif($array['category']==10){
			      ?>
        <li><a title="تیم نارنج سیستم" href="/team">تیم نارنج سیستم</a></li>
 		<li><?php echo $array['name']?></li>
                 <?php
				  }
			  else{
				  ?>
 		<li><?php echo $array['name']?></li>
                 <?php
				  }
			  }

	if($kind=='portfolio'){
	 $sql = "SELECT * FROM ads WHERE id = '".$id."'";
			  $query = $db->query($sql) ;
			  $array=$db->fetchNextArray($query);
			  ?>
        <li><a title="نمونه کارها" href="/portfolio">نمونه کارها</a></li>
 		<li><?php echo $array['name']?></li>
                 <?php }
?>
        
    </ul>
<?php

	};
?>