<?php
include_once("../inc/content.inc.php");


class Classes extends Content
{
public function __construct()
	{
	Content::__construct("Расписание на неделю");

	if(!isset($this->date)) $this->date=time();
	if(!isset($this->city)) $this->city=1;
	if(!isset($this->day)) $this->day=0;
	if(!isset($this->instr)) $this->instr=0; 
	if(!isset($this->step)) $this->step=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=500, 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,w)
	{
	  window.open('{$this->self}?city='+x+'&instr='+z+'&day='+y+'&step='+w,'_self');
	}
function map(x)
	{
	window.open('{$this->folder}/map.php?id='+x, x,param);
	}
function music(x,y)
	{
	if(x>0) window.open("/static/ru/music/meditation1.php?day="+x," ",param);
	else	 window.open("/static/ru/music/meditation1.php?class="+y," ",param);
 	}

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=25%>\n";
        $txt.=$this->CitySelector($this->city,"choose(value,{$this->day},{$this->instr},{$this->step})");
        $txt.="<td width=25%>\n";
	$txt.=$this->UserSelector($this->instr,"choose({$this->city},{$this->day},value,{$this->step})",1,$this->city,1);
        $txt.="<td width=25%>\n";
	$txt.=$this->DaySelector($this->day,"choose({$this->city},value,{$this->instr},{$this->step})");
        $txt.="<td width=25%>\n";
	$txt.=$this->ActivitySelector("choose({$this->city},{$this->day},{$this->instr},value)");
	$txt.="</table>\n";
	$txt.=$this->Local();
        $txt.="</fieldset>\n";
        return $txt;

        }

protected  function Addons()
	{

	if($this->city==1||$this->city==4) 
	{
        $txt="<fieldset><legend>Дополнительная информация</legend>\n";
        $txt.="<a targe='_new' href='{$this->folder}/price.php?city=$this->city'>Система абонементов</a>\n";
	 $txt.="&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a target='_new' href='{$this->folder}/tmo.php'>Лечение</a>\n";
        $txt.="</fieldset>\n";
	}
	else $txt="";
	return $txt;
	}

public function Row($x)
	{
	$x['time']=substr($x['time'],0,-3);
	$x['time1']=substr($x['time1'],0,-3);
	if($x['uid1']&&!$x['uid']){$x['uid']=$x['uid1'];$x['uid1']=0;}
	if($x['address']!=$this->address)
		{
		 $this->address=$x['address'];
		 $txt="<tr><td colspan=3><a href='javascript:map($this->address)'><em>{$this->addresses[$this->address]['address']}</em></a></tr>\n";
		}
	else   $txt="<tr>\n";
	if($this->city==0) $txt.="<td width=10%><nobr>{$this->cities[$x['city']]['name']}</nobr></td>";
	$txt.=<<<EOS
<td width='15%'>{$x['time']} {$x['time1']}</td>
<td><span> <a target='_new' href='/static/ru/qigong/{$x['ref']}'>{$x['title']}</a></span>
EOS;
	if($x['classes']) $txt.="<a href='javascript:remark({$x['id']})'>прим.</a>"; 
	else $txt.="<a href='javascript:details({$x['id']})'>прим.</a>";
	 if($x['classes'])  $txt.=" <a href='javascript:music(0,{$x['day']})'>музыка</a></td>";
	 else $txt.=" <a href='javascript:music({$x['day']},0)'>музыка</a></td>";


	$txt.="<td width='35%'>\n";
	if($x['uid'])
		{
		   $y=&$this->users[$x['uid']];   $user="{$y['lname']} {$y['fname']} {$y['mname']}";
		 $txt.="<a target='_new' href='/static/ru/homes/home.php?id={$x['uid']}'>{$user}</a>";
		}
	 else $txt.="_\n";
	if($x['classes'])
		{
		if($x['uid1'])if($x['uid1']!=$x['uid'])
			{
			  $y=&$this->users[$x['uid1']];   $user="{$y['lname']} {$y['fname']} {$y['mname']}";
			 $txt.="<br><a target='_new' href='/static/ru/homes/home.php?id={$x['uid1']}'>{$user}</a>";
			}
		}
	$txt.="</td>\n";
	$txt.="</tr>\n";	 

$this->txt.=$txt;
}

public function Str($x)
        {
        $this->str.="{$x['id']},";
        }


protected function Schedule($day)
{

$today = getdate($this->date); $wday = $today['wday'];
$date=$this->date-($wday-$day)*24*60*60; $today=getdate($date); 
$mday=$today['mday']; $month=$today['mon']; $year=$today['year'];
$date=date("Y-m-d H:i:s",$date);

$str="select classes.id as id,act_name(activities.id) as title,activities.ref as ref ,text,city,classes.id as day,time,time1,address, uid,uid1, 1 as classes from classes,activities where activities.id=activity and day=$day and city=$this->city";
 if($this->instr!=0) $str.=" and (uid={$this->instr} or uid1={$this->instr} )"; 
if($this->step) $str.=" and is_desc_act(activity,$this->step)";
$str.=" union select seminars.id,act_name(activities.id) as title,activities.ref as ref ,text,city, days.id as day , days.time as time,".
" sec_to_time(time_to_sec(days.time)+dur*60) as time1, days.address as address,  uid, uid as uid1,0 as classes  from seminars,days,activities".
" where  activities.id=activity and days.date=date('$date') and days.sid=seminars.id  and city=$this->city"; if($this->instr!=0) $str.=" and uid={$this->instr}"; 
if($this->step) $str.=" and is_desc_act(activity,$this->step)";

$str.=" order by address,time";

 $txt="<caption><h2>";
 $month=Selectors::$Months1[$month];
 $day=Selectors::$Days[$day];
 $txt.="$day, $mday $month\n";
 $txt.="</h2></caption>";


$this->address=0;
$this->txt="";
$this->fox->Select($str,"Row");

	 $txt.="<table width='100%' id='setup'>\n";
	 $txt.="<tr>\n";
	 if($this->city==0) $txt.="<td>Город</td>";
	 $txt.="<td>Время</td><td>Название и пр.</td><td>Инструктор</td></tr>";

$txt.=$this->txt;
$txt.="</table>\n";
return $txt;

}


protected function Main()
{

$txt=$this->Selectors();
$txt.=$this->Addons();

$today = getdate($this->date); 
$wday = $today['wday']; $wday=$wday==0?7:$wday;

$mday=$today['mday'];
$month=$today['mon'];
$year=$today['year'];

$date1=$this->date-7*24*60*60;
$date2=$this->date+7*24*60*60;

$wday=Selectors::$Days[$wday];
$mon=Selectors::$Months1[$month];


$txt.="<h2><a href='{$this->folder}/classes.php?instr=$this->instr&day=$this->day&date=$date1'><<<<<</a>";
$txt.= "                     Сегодня - {$wday}, $mday {$mon} $year г. \n";
$txt.= "<a href='{$this->folder}/classes.php?instr=$this->instr&day=$this->day&date=$date2'>>>>>></a></h2>";


$count=0;

if($this->day==0) for($i=1;$i<=7;$i++) $txt.=$this->Schedule($i);
else $txt.=$this->Schedule($this->day);



return $txt;
}

}

$x=new Classes(); $x->Type();

?>
