<?php

include_once("../inc/content.inc.php");

class Seminars extends Content
{

public function __construct()
	{
	Content::__construct();
	if(!isset($this->year)) $this->year=0;
	if(!isset($this->step)) $this->step=0;
	if(!isset($this->instr)) $this->instr=0;

	$this->functions=<<<EOS
var param='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 details(x)
	{
	window.open('{$this->folder}/details.php?id='+x,'details',param);
	}
function remark(x)
	{
	window.open('{$this->folder}/remark.php?id='+x,'details',param);
	}
function choose(x,y,z)
	{
	  window.open('{$this->self}?year=$this->year&instr='+y+'&step='+z+'&city='+x,'_self');
	}
EOS;
	$this->functions.=$this->ActivityFunction();
	$this->onload="ActivityChanged({$this->step})";
	}

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,$this->instr,$this->step)");
        $txt.="<td width=33%>\n";
        $txt.=$this->UserSelector($this->instr,"choose({$this->city},value,{$this->step})",1,0,1);
        $txt.="<td width=33%>\n";
        $txt.=$this->ActivitySelector("choose({$this->city},{$this->instr},value)");
        $txt.="</table>\n";
        $txt.=$this->Local();
        $txt.="</fieldset>\n";
        return $txt;

        }

public function Row($x)
{

$x['time']=substr($x['time'],0,-3);
$date=translate_date_array($x['date']);
$txt="";
if($date['year']!=$this->year1||$date['month']!=$this->month)
	{
	 if($this->year1!="")$txt="</table>";
	 $this->year1=$date['year']; $this->month=$date['month']; $month=Selectors::$Months[$this->month];
	 $txt.="<p><h2>{$month} $this->year1</h2>\n";
	 $txt.="<table width='100%' id='setup'>\n";
	 $txt.="<tr><td>Число</td>\n";
	 if(!$this->city)$txt.="<td>Город</td>\n";
	 $txt.="<td>Ступень</td><td>Начало</td>\n";
	 if(!$this->instr)$txt.="<td>Инструктор</td>\n";
	 $txt.="<td>Детали</td></tr>\n";
	}
 $txt.="<tr><td>{$date['day']}</td>\n";



 if(!$this->city)
	 {
	 $city=$this->cities[$row['city']]['name'];
	 $txt.= "<td><a target='_new' href='/static/ru/filiations/filiation.php'><nobr>$city</a></nobr></td>";
	}
 $txt.="<td><nobr><a target='_new' href='/static/ru/qigong/{$row['ref']}'>{$x['step']}</nobr></a></td>".
	"<td><nobr>{$x['time']}</nobr></td>";
 if(!$this->instr)
	 {
	 $y=$this->users[$x['uid']]; $user="{$y['lname']} {$y['fname']} {$y['mname']}";
	  $txt.="<td><nobr><a target='_new' href='/static/ru/homes/home.php?id={$x['uid']}'>{$user}</a></nobr></td>";
	 }


 $txt.= "<td><a href='javascript:details({$x['id']})'>смотреть</a></td>\n";
$txt.= "</tr>\n";
$this->txt.=$txt;
}

public function Str($x)
	{
	$this->str.="{$x['id']},";
	}
protected function Main()
	{

	 $txt=$this->Selectors();
	  $str="select seminars.id as id,min(date) as date,time,city,act_name(activities.id) as step,activities.ref as ref,uid,text from activities,seminars left join days on sid=seminars.id where activities.id=activity and date>SUBDATE(now(),INTERVAL {$this->year}+1 year)";
	  if($this->year) $str.=" and days.date<SUBDATE(now(),INTERVAL $this->year year)";
	  if($this->city) $str.=" and city=$this->city";
	  if($this->instr) $str.=" and uid=$this->instr";
	  if($this->step)
		{
		 $this->str="";
		// echo "select id from activities where is_desc_act(id,{$this->step})";	
		 $this->fox->Select("select id from activities where is_desc_act(id,{$this->step})","Str");	
		 $this->str=substr($this->str,0,strlen($this->str)-1);
		 $str.=" and activities.id in({$this->str}) ";
		}
	
	  $str.=" group by sid order by min(date) desc, time desc";
	 	
	 $this->year1=""; $this->month="";

	 $this->fox->Select($str,"Row");

	$txt.=$this->txt;

	$txt.= "</table>\n";
	
	$txt.="<p><table width='100%'><tr><td>\n";
	$year=$this->year-1; if($year>=0)$txt.= "<a href='{$this->self}?instr=$this->instr&year=$year&step=$this->step'>следующие</a>"; else $txt.="___________";
	$txt.="</td><td>\n";
	$year=$this->year+2; $txt.= "<a href='{$this->self}?instr=$this->instr&year=$year&step=$this->step'>предыдущие</a>";
	$txt.="</td></tr></table>\n";

	return $txt;

	}

}

$x=new Seminars(); $x->Type();
?>
