<?php
// ======================================================================== //
//                                                                          //
//   KooBI- Webportalsystem                                                 //
//   SCRiPTMAFiA 2005 - THE DiRTY HANDS ON YOUR SCRiPTS                     //
//                                                                          //
//   ====================================================================   //
//                                                                          //   
//   dream4 | webservices - Am Michelsgrund 7 - 69469 Weinheim - Germany    //    
//   tel. +49(0) 6201 - 980442 / fax. +49(0) 6201 - 64809                   //
//                                                                          //
// ======================================================================== //
if(!checkactive('manufacturer')) include(dirname(__FILE__)."/lib/notactive.php" );
$sname = simpletitle($lang['manufacturer']);
$tmpl->assign('lang', $lang);
$tmpl->assign('area', $area);

if (!permission("manufacturer")) {
	$EOUT = stderror("nopermission", $lang['nopermission_t'], str_replace("__URL__", "index.php", $lang['redirect']), "index.php", 1);
	$error = 1;
	$NOOUT = 1;
}

switch($_REQUEST['action']){
	// =========================================================================
	// <<-- DETAIL ANZEIGEN -->>
	// =========================================================================
	case "showdetails" :
	$sql = new dbc("UPDATE ".PREFIX."_manufacturer set hits=hits+1 where id='".escs($_REQUEST['id'])."'");
	$sql = new dbc("SELECT * FROM ".PREFIX."_manufacturer where id='".escs($_REQUEST['id'])."'");
	$row = $sql->fetchrow();
	
	if(is_file("uploads/manufacturer/" . $row->icon)){ $tmpl->assign('image', "uploads/manufacturer/" . $row->icon); }
	if($row->s_year < 1) { $syear = $lang['nothingset']; } else { $syear = $row->s_year; }
	
	// <<-- PRODUKTE -->>
	$sql = new dbc("SELECT title,id FROM ".PREFIX."_products WHERE manufacturer='".$row->id."' order by title asc");
	$products = array();
	while($row_p = $sql->fetchrow()){
		array_push($products,$row_p);
	}
	
	// <<-- WEITERE HERSTELLER -->>
	$sql = new dbc("SELECT id,name FROM ".PREFIX."_manufacturer WHERE area='$area' order by name asc");
	$items = array();
	while( $row_mf=$sql->fetchrow()){
		array_push($items,$row_mf);
	}
	
	// <<-- NEWS, DIE EVENTUELL DIESEM HERSTELLER ZUGEORDNET WURDEN -->>
	$sql = new dbc("SELECT manufacturer,title,newsid FROM ".PREFIX."_news WHERE manufacturer='".$_REQUEST['id']."'");
	$relatednews = array();
	while($row_rn = $sql->fetchrow()){
		array_push($relatednews,$row_rn);
	}
	
	$tmpl->assign('relatednews', $relatednews);
	$tmpl->assign('items', $items);
	$tmpl->assign('products', $products);
	$tmpl->assign('adress', nl2br($row->adress));
	$tmpl->assign('email',$row->email);
	$tmpl->assign('row',$row);
	$tmpl->assign('syear',$syear);
	$tmpl->assign('text',$row->descr);
	$tmpl->assign('fullname',$row->full_name);
	
	$sname .= $lang['f_navi_separator'].$row->name;
	$tmpl->assign("content", parsetrue("container/".container("manufacturer"), "<a class=\"boxnavi\" href=\"index.php?p=manufacturer&amp;area=$area\">".$lang['manufacturer'] . "</a>". $lang['f_navi_separator'] . $lang['manufacturer_details'], $tmpl->fetch("manufacturer/main.tpl")));
	break;
	
	// =========================================================================
	// <<-- WEITERLEITEN -->>
	// =========================================================================
	case "redir" :
	$sql = new dbc("SELECT url FROM ".PREFIX."_manufacturer where id='".escs($_REQUEST['id'])."'");
	$row = $sql->fetchrow();
	$sql = new dbc("UPDATE ".PREFIX."_manufacturer set hits=hits+1 where id='".escs($_REQUEST['id'])."'");
	
	$url = $row->url;
	$pos = strpos ($url, "http://");
	if ($pos === false) {
		$url = "http://".$url;
	}
	
	header("Location:$url");
	break;
	// =========================================================================
	// <<-- UEBERSICHT -->>
	// =========================================================================
	case "" :
	$sql = new dbc("SELECT * FROM ".PREFIX."_manufacturer WHERE area='$area'  order by ctime desc limit 20");
	$items = array();
	while( $row=$sql->fetchrow()){
		$row->added = $row->ctime;
		array_push($items,$row);
	}
	$tmpl->assign('items', $items);
	$tmpl->assign('row', $row);
	
	
	switch($_REQUEST['charakter']){
		case "1" :
		for($i=1;$i<10;$i++) { $loop .= " OR name  LIKE '".$i."%'"; }
		$dbquery = " WHERE(name LIKE '0%' $loop)";
		$tmpl->assign('charakter', '0-9');
		break;
		
		case "" :
		for($i=1;$i<10;$i++) { $loop .= " OR name  LIKE '".$i."%'"; }
		$dbquery = " WHERE(name LIKE '0%' $loop)";
		$tmpl->assign('charakter', '0-9');
		break;
		
		case "all" :
		$dbquery = "";
		$tmpl->assign('charakter', $lang['all']);
		break;
		
		default :
		$dbquery = " WHERE(name LIKE '".$_REQUEST['charakter']."%')";
		$tmpl->assign('charakter', strtoupper($_REQUEST['charakter']));
		break;
	}
	
	if($_REQUEST['search']==1){
		$dbquery = "WHERE name like '%".$_REQUEST['mf']."%'";
	}
	
	$andarea = ($dbquery) ? " AND area = '$area'" : " WHERE area = '$area'" ;
	
	$sql2 = new dbc("SELECT * FROM ".PREFIX."_manufacturer $dbquery $andarea order by name ASC");
	$items2 = array();
	while( $row2=$sql2->fetchrow()){
		$row2->added = $row2->ctime;
		array_push($items2,$row2);
	}
	
	$tmpl->assign('items2', $items2);
	$tmpl->assign('row2', $row2);
	
	// <<-- BELIEBTESTER HERSTELLER -->>
	$sql = new dbc("SELECT email,full_name,id,url,icon,name FROM ".PREFIX."_manufacturer WHERE area = '$area' order by hits desc limit 1");
	$row = $sql->fetchrow();
	if(is_file("uploads/manufacturer/" . $row->icon)){ $tmpl->assign('image', "uploads/manufacturer/" . $row->icon); }
	$tmpl->assign('row',$row);
	$tmpl->assign('email',$row->email);
	$tmpl->assign('fullname',$row->full_name);
	$tmpl->assign('name_top',$row->name);
	
	// <<-- NEUESTER HERSTELLER -->>
	$sql2 = new dbc("SELECT email,full_name,id,url,icon,name FROM ".PREFIX."_manufacturer WHERE area = '$area' order by ctime desc limit 1");
	$row_newest = $sql2->fetchrow();
	if(is_file("uploads/manufacturer/" . $row_newest->icon)){ $tmpl->assign('image_newest', "uploads/manufacturer/" . $row_newest->icon); }
	$tmpl->assign('row_newest',$row_newest);
	$tmpl->assign('fullname_newest',$row_newest->full_name);
	$tmpl->assign('email_newest',$row_newest->email);
	$tmpl->assign('name_newest',$row_newest->name);
	$tmpl->assign("content", parsetrue("container/".container("manufacturer"), $lang['manufacturer'], $tmpl->fetch("manufacturer/main.tpl")));
	break;
}


?>