<?php session_start();
include ('dbf.php');
include ('classhead.php');
class search {
function output($head,$ars,$ar1,$ar2,$c_ars,$tab,$width,$s_f,$s,$page,$id,$se,$where,$c,$tb){
   include("dbf.php");
   include ('funcs.php');
	  $fp=fopen("$tb.xls","w");
	  		$value="ردیف";
			$data1=ecode($value.chr(9));
			fwrite($fp,$data1);
					for($i=0;$i<count($ar1);$i++){
						  $s1=$ar1[$i];
               			  $data1=ecode($s1.chr(9));
				 		  fwrite($fp,$data1);
                		}
                		$data1=ecode(chr(13));
		  				fwrite($fp,$data1);
							 if($tab=='dio'){
							 	if($s_f!="")
							     	$fg=mysql_query("select * from $tab where  ($s_f LIKE'%{$s}%') order by $tab.$id ");
								 else
							     	$fg=mysql_query("select * from $tab  order by $tab.$id ");
							 	}
							 elseif(($tab=='matn') && ($se=='1')){
							 	$fg=mysql_query("select * from $tab  $where ");
							 	}
							 elseif(($tab=='ketab') && ($se=='2')){
									$fg=mysql_query("select * from $tab $where ");
							 }
							 //($s_f LIKE'%{$s}%') and
							 elseif($tab=='amanat'){
							 		if($c=='0')
							 			$fg=mysql_query("select * from amanat where (date_in=0 and city='{$_SESSION[city]}') order by amanat.id_ozv");
							 		elseif($c=='1')
										$fg=mysql_query("select * from amanat where (city='{$_SESSION[city]}') order by amanat.id_ozv");
							 		elseif($c=='2')
										$fg=mysql_query("select * from amanat where (city='{$_SESSION[city]}') order by amanat.id_ozv");
							 		elseif($c=='3')
										$fg=mysql_query("select * from amanat where (city='{$_SESSION[city]}') order by amanat.id_ozv");
							  		elseif($c=='4')
							 			$fg=mysql_query("select * from amanat where ( date_in=0 and city='{$_SESSION[city]}') order by amanat.id_ozv")or die(mysql_error());
							 }
							 else{
							 	if($s_f!="")
						   	 	{
						   	 	//echo $s;
							     	$fg=mysql_query("select * from $tab where (city='{$_SESSION[city]}' and  ($s_f LIKE'%{$s}%') ) order by $tab.$id ");
								}
								else
							     	$fg=mysql_query("select * from $tab where (city='{$_SESSION[city]}' ) order by $tab.$id ");
							 	}
							 $k=1;
						 while($v=mysql_fetch_assoc($fg)){
								if($tab=='matn'){
							 		$gg=mysql_query("select * from ketab where (id='{$v['id']}')");
									$vj=mysql_fetch_assoc($gg);
									}
								elseif(($tab=='ketab') && ($se=='1')){
									$gg=mysql_query("select * from ketab where (ketab.id='{$v['id']}') order by ketab.name)");
									$vj=mysql_fetch_assoc($gg);
									}
								     $data1=ecode($k.chr(9));
				 		 			 fwrite($fp,$data1);
								   for($j=0;$j<count($ar2);$j++){
 								  	   if($tab=='matn' && $j=='1'){
 								  	   		$data1=ecode($vj[$ar2[$j]].chr(9));
				 		 			 		fwrite($fp,$data1);
 								  	   }else{
										  	$data1=ecode($v[$ar2[$j]].chr(9));
				 		 			 		fwrite($fp,$data1);
										  }
										}
								  $data1=ecode(chr(13));
		  						  fwrite($fp,$data1);
								  $k++;
								}
							$return.="</table>";
				$return.="</td></tr></table>";
	return $return;
}
}
?>