<?php

include_once("../inc/content.inc.php");


class Filiations extends Content
{

public function __construct()
	{
	Content::__construct("Филиалы");
	$this->images=array();
	$this->functions=<<<EOS
function map(x){window.open('map.php?id='+x, x,'toolbar=no, caption=no, location=no, directories=no, status=no, menubar=no,scrollbars=no, resizable=no,left=20,top=20, height=600, width=900');}
function choose(x){window.open('filiation.php?city='+x,'_self');window.parent.city=x; window.parent.Title();}
EOS;

	if(!isset($this->img)) $this->img=0;
	}

protected function Selectors()
        {
        $txt="<fieldset><legend>Посмотреть объявления для городa</legend>\n";
        $txt.="<table  width='100%'><tr><td width=33%>\n";
        $txt.=$this->CitySelector($this->city,"choose(value)");
        $txt.="</table>";
        $txt.=$this->Local();
        $txt.="</fieldset>\n";
        return $txt;
        }


public function Address($row)
	{
	$this->txt.="<li><a href='javascript:map({$row['id']})'>{$row['address']}</a>\n";
	}

protected function Addresses()
	{
	$txt="<ul>Адреса\n";
	$this->txt="";
	$this->fox->Select("select id,address from addresses where city=$this->city","Address");
	$txt.="$this->txt</ul>\n";
	return $txt;
	}

public function User($row)
   	{
	$this->txt.="<li><a href=../homes/home.php?id={$row['id']}>{$row['name']} - {$row['position']}</a>\n";
   	}

protected function Users()
	{
	$txt="<ul>Сотрудники\n";
	$this->txt="";
	$this->fox->Select("select id,concat(lname,' ',fname,' ',mname) as name,position from users where admin=1 and city=$this->city  order by name","User");
	$txt.="$this->txt</ul>\n";
	return $txt;
	}

public function Image($row)
	{
	$this->images[$row['id']]=$row['path'];
	}


protected function Face1()
	{
	foreach( $this->images as $value) break;
	if($this->img) $value=$this->images[$this->img]; 

//	$txt="<div class='face'>\n";
	if(isset($value))$txt="<img border=0  class='face' id=='tbl' src='preview.php?height=350&path=../../../cities/{$this->city}/{$value}'>\n";
//	$txt.="</div>\n";
	return $txt;
	}

protected function Images()
	{
	$txt="";
if(sizeof($this->images))
	{

	$i=0;
	foreach( $this->images as $key=>$value)
		{   
			$txt.="<td><a href=filiation.php?img={$key}&city={$this->city}>\n";
			$txt.="<img border=0 class='face' SRC='preview.php?width=150&path=../../../cities/{$this->city}/{$value}'>\n";
	 		$txt.="</a></td>\n";
		
		$i++;	if(!($i%2))$txt.="</tr>";

		}

	$txt.="</div>\n";
	}
return $txt;

}


protected function Main()
	{
	$txt=$this->Selectors();
	$this->fox->Select("select * from cities_img where city=$this->city order by id","Image");

	$cols=sizeof($this->images);  $x=(int)($cols/2); $y=$cols-$x; if(!$x)$x=1; if(!$y)$y=1;
	$txt.="<table width='100%'>";
	$txt.="<tr>";
	$txt.="<td colspan=2 rowspan=4>";
	$txt.=$this->Face1();
	$txt.=$this->Images();
	$txt.="</tr>";
	$txt.="</table>";
	$txt.=$this->Addresses();
	$txt.=$this->Users();

	return $txt;
	}
}

$x=new Filiations(); $x->Type();
?>
