<?php


class subPage_ extends common 
{
	
	public $params=array();
	public $conn=null;
	public $belka=array();
	private $dzial = null;
	private $limit = 5;
	
	function subPage()
	{
		$this->conn = $GLOBALS['portal']->conn;
		$this->params = &$GLOBALS['portal']->params;
		$this->belka = &$GLOBALS['portal']->belka;
	}
	
	
	function getSideHeader($id_dzialu)
	{
		$html='';
		$sql="select * from dzialy where id_dzialu_pk=$id_dzialu";
		if($row=$this->getOneRowFromSql($sql))
		{
			$this->dzial = array($this->decode($row['nazwa']), $this->getlink(array(PART_ID=>PART_SUBPAGE,CATEGORY=>$row['id_dzialu_pk'])), $row['id_foto_fk']);
			$poddzialy=$this->getPoddzialy($row['id_dzialu_pk']);
			
			if(!($this->params[PRINTER] == 1))
			{
			$html.='<div class="siteHeader">';
				$html.='<h2><a title="'.$this->dzial[0].'" href="'.$this->dzial[1].'">'.$this->dzial[0].'</a></h2>';
				if($row['alternatywa_poddzialow'])
				{
					$html.= '<span style="margin-left:10px">' . $this->decode($row['alternatywa_poddzialow']) . '</span>';
				}
				else 
				{
					$html.='<div id="hContent">';
						$i=0;
						foreach ($poddzialy as $key=>$poddzial)
						{
							if($i>=$row['ile_box_kategorie']) break;
							
							$href=$this->getlink(array(
								PART_ID=>PART_SUBPAGE,
								CATEGORY=>$row['id_dzialu_pk'],
								SUBCATEGORY=>$key,
							));
							if($i) $html.='|';
							$html.='<a title="'.$poddzial['nazwa'].'" href="'.$href.'">'.$poddzial['nazwa'].'</a>';
							$i++;
						}
					$html.='</div>';
					$html.='<div class="clearfix"></div>';
				}
			$html.='</div><!--siteheder -->';
			}
		}
		return $html;
	}
	
	function DrawAdv($art)
	{
		$html = '';
		$match = array();
		$i = 1;
		if(preg_match_all("|%REKLAMA:[0-9]+%|", $art, $match))
		{
			foreach($match as $advert)
			{
				foreach($advert as $adv) {
					$pos = strpos($adv, ":");
					$id = substr(str_replace("%", '', $adv), $pos, (strlen($adv) - $pos + 1));
					ob_start();
					include ('http://www.zdrowemiasto.pl/_adv/eadv.php?zone=' . $id);
					$banner = ob_get_contents();
					ob_end_clean();
					$str = '';
					if($banner != 'adverror' && $banner != '') {
						$str = '<table cellpadding="0" cellspacing="0" border="0">';
						$str .= '<tr><td width="33%">&nbsp;</td>';
						$str .= '<td width="33%"><div style="font-size:small;color:#999999;font-style:normal">REKLAMA</div></td>';
						$str .= '<td width="33%"><div style="text-align:right;"><a href="#dalej' . $i . '" class="readAfterAdv" style="text-decoration:none">czytaj dalej</a><img src="design_img/arrow.jpg" style="vertical-align: middle; height: 18px;margin-left: 4px;" alt="czytaj dalej" border="0" /></div></td></tr>';
						$str .= '<tr><td width="33%">&nbsp;</td>';
						$str .= '<td width="33%">';
						$str .= $banner;
						$str .= '</td>';
						$str .= '<td width="33%">&nbsp;</td></tr>';
						$str .= '</table>';
						$str .= '<a name="dalej' . $i++ . '"></a>';
					}
					$pos = strpos($art, $adv);
					$art = substr_replace($art, $str, $pos, strlen($adv));
				}
			}
		}
		return $art;
	}
	
	function artykul($id)
	{
		
		$html='';
		
		$sql="
			select a.*,p.id_dzialu_fk,p.id_poddzialu_pk,p.nazwa as poddzial,d.nazwa as dzial
			from artykuly as a
			inner join poddzialy as p on a.id_poddzialu_fk=p.id_poddzialu_pk
			inner join dzialy as d on p.id_dzialu_fk=d.id_dzialu_pk
			where a.id_artykulu_pk=$id
		";
		if($article=$this->getOneRowFromSql($sql))
		{
			$html.='<div id="content" ';
			if($this->params[PRINTER] == 1) $html .= 'style="width:582px; text-align:left;">';
			else $html .= '>';
					$html.=$this->getSideHeader($article['id_dzialu_fk']);
				
				#
				$this->belka[BELKA_DZIAL][0]=$this->decode($article['dzial']);
				$this->belka[BELKA_DZIAL][1]=$this->getlink(array(PART_ID=>PART_SUBPAGE,CATEGORY=>$article['id_dzialu_fk']));
				$this->belka[BELKA_PODDZIAL][0]=$this->decode($article['poddzial']);
				$this->belka[BELKA_PODDZIAL][1]=$this->getlink(array(PART_ID=>PART_SUBPAGE,CATEGORY=>$article['id_dzialu_fk'],SUBCATEGORY=>$article['id_poddzialu_fk']));
				$this->belka[BELKA_KATEGORIA][0]=$this->shortenText($this->decode($article['tytul']),50);
				$this->belka[BELKA_KATEGORIA][1]='';
				#
				if($article['meta_title'])
					$GLOBALS['ZM']['title'] = $article['meta_title'];
				if($article['meta_description'])
					$GLOBALS['ZM']['description'] = $article['meta_description'];
				if($article['meta_keywords'])
					$GLOBALS['ZM']['keywords'] = $article['meta_keywords'];
	
				$html.='<div>';
					$html.='<h3>'.$this->decode($article['tytul']).'</h3>';
					$html.='<p class="subtitle">'.$this->decode($article['podtytul']).'</p>';
					if($article['autor']) $html.='<p class="author">'.$this->decode($article['autor']).'</p>';
					$html.='<div id="newsPre2" style="clear:both">';
						$html.='<div id="source">';
							if($img=$this->getImgPathDB($article['id_zrodlo_foto_fk'],$x=40,$y=0)) $html .= '<img src="' . $img . '" alt="' . $article['zrodlo'] . '" style="vertical-align: middle;margin: 0px 5px 0px 0px;padding: 0px;" />';
							if($article['zrodlo']) $html.=$this->decode($article['zrodlo']).' | ';
							$html.='dodane '.$this->showDate($article['data']);
						$html.='</div>';
						if(!($this->params[PRINTER] == 1))
							$html.='<div id="fixFont"><a class="normal" href="javascript:void(0)" onclick="setActiveStyleSheet(\'A\')" title="12">A</a><a class="large" href="javascript:void(0)" onclick="setActiveStyleSheet(\'A+\')" title="13">A</a><a class="larger" href="javascript:void(0)" onclick="setActiveStyleSheet(\'A++\')" title="14">A</a></div>';
					$html.='</div>';
				$html.='</div>';
				$html.='<div style="clear:both"></div>';
				if($img=$this->getImgPathDB($article['id_foto_fk'],$x=180,$y=0))
				{
					$html.='<div class="contentImg" style="width:180px"><img src="'.$img.'" alt="" style="width:180px"/>';
						if($article['foto_podpis'])
						{
							$html.='<br />'.$this->decode($article['foto_podpis']).'<br />&nbsp;';
						}
					$html.='</div>';
				}
//				$html.='<p id="contentTopic"><strong>'.$this->decode($article['skrot']).'</strong></p>';
				if(false === strpos($this->decode($article['tresc']), '%PAGE%')) {
					$html.='<div id="contentText">'.$this->DrawAdv($this->decode($article['tresc'])).'</div>';
				} else {
					if(!($this->params[PRINTER] == 1)) {
						$pages = explode('%PAGE%', $this->decode($article['tresc']));
						$page = $this->params[PAGE_ID];
						if($page >= 1 && $page <= count($pages)) {
							if(0 == strpos($pages[$page-1], '<br'))
								$pages[$page-1] = substr($pages[$page-1], strpos($pages[$page-1], '>')+1);
							$html.='<div id="contentText">'.$this->DrawAdv($pages[$page - 1]).'</div>';
							$html.=$this->get_paging(count($pages));
						} else { 
							if(0 == strpos($pages[0], '<br'))
								$pages[0] = substr($pages[0], strpos($pages[0], '>')+1);
							$html.='<div id="contentText">'.$this->DrawAdv($pages[0]).'</div>';
						} 
					} else {
							$html.='<div id="contentText">'.str_replace('%PAGE%', '<br />', $this->decode($article['tresc'])).'</div>';
					}
				}
				if($article['autor'])
				{
					$html.='<div id="authorSignature"><br />'.$this->decode($article['autor']).', '.$this->showDate($article['data']);
					if($article['zrodlo']) $html.=', ' . $this->decode($article['zrodlo']);
//					if($img=$this->getImgPathDB($article['id_zrodlo_foto_fk'],$x=40,$y=0)) $html .= '<img src="' . $img . '" alt="' . $article['zrodlo'] . '" style="vertical-align: middle;margin: 0px 0px 0px 5px;padding: 0px;" />';
					$html .= '</div>';
				}
				if(!($this->params[PRINTER] == 1)) {
		  		$html.='<div id="contentBottom">';
	  				$html.='<ul>';
  						$recommend_href=$this->getlink(array(PART_ID=>PART_RECOMMEND,ID=>$article['id_artykulu_pk']));
	  					$html.='<li><a href="javascript:fullwindow(525,470,\''.$recommend_href.'\');" class="sendLink">Wyślij link</a></li>';
		  				$print_href = $this->getlink(array(PART_ID=>$this->params[PART_ID],ID=>$this->params[ID],SUBCATEGORY=>$this->params[SUBCATEGORY],CATEGORY=>$this->params[CATEGORY],PRINTER=>1));
			  			$html.='<li><a href="#" class="print" onclick="window.open(\'' . $print_href . '\',\'Drukowanie\',\'menubar=no,toolbar=no,scrollbars=yes,width=620,height=700\'); return false;">Drukuj</a></li>';
	  					$html.='<li><a href="#" class="pageUp">Do góry</a></li>';
		  			$html.='</ul>';
			  		$html.='<div class="clearfix"></div>';
				  $html.='</div>';
				}
				if($article['encyklopedia'])
				{
					if(!($this->params[PRINTER] == 1)) $html.='<div id="worthToKnow">';
					else $html.='<div id="worthToKnowPrint">';
						$html.='<h3>Warto wiedzieć</h3>';
						$html.=''.$this->decode($article['encyklopedia']).'';
						//$html.='<div id="worthToKnowSigniature">ZdroweMiasto.PL, 28.02.2008</div>';
					$html.='</div>';
				}
				if($article['included_class'])
				{
					$html.=$this->customClass($article['included_class']);
				}
				if(1 == $this->params[PRINTER])	
					$html .= '<input type="button" value="drukuj" onclick="window.print(); return false;" style="float: right" />';	
				$sql="
					select a.id_artykulu_pk,a.id_foto_fk,a.tytul,a.foto_podpis,a.id_poddzialu_fk
					from artykuly as a
					inner join poddzialy as p on a.id_poddzialu_fk=p.id_poddzialu_pk and p.id_dzialu_fk={$article['id_dzialu_fk']}
					where a.ukryty=0 and a.id_poddzialu_fk={$article['id_poddzialu_fk']} and a.id_artykulu_pk<>{$article['id_artykulu_pk']}
					order by data desc, id_artykulu_pk desc
					limit 0,10
				";
				//echo $sql;
				$res2=mysql_query($sql,$this->conn); //echo mysql_error();
				if($res2 && !($this->params[PRINTER] == 1))
				{
					if(mysql_num_rows($res2))
					{
						$html.='<div id="otherInTheSection">';
							$html.='<h3>Inne w tym dziale:</h3>';
							$html.='<ul>';
								while ($article2=mysql_fetch_assoc($res2))
								{
									$article_href=$this->getlink(array(
										PART_ID=>PART_SUBPAGE,
										CATEGORY=>$article['id_dzialu_fk'],
										SUBCATEGORY=>$article2['id_poddzialu_fk'],
										ID=>$article2['id_artykulu_pk']
									));
									$html.='<li><a href="'.$article_href.'">'.$article2['tytul'].'</a></li>';
								}
								$href=$this->getlink(array(
									PART_ID=>PART_SUBPAGE,
									CATEGORY=>$article['id_dzialu_fk'],
									SUBCATEGORY=>$article['id_poddzialu_fk'],
								));
								$html.='<li class="lastElement"><a href="'.$href.'" >Wszystkie w tym dziale</a></li>';
							$html.='</ul>';
		
						$html.='</div>';
						
					}
				}
				if(!($this->params[PRINTER] == 1))
				$html.=$this->contentFooter($article['id_dzialu_fk']);
				
			$html.='</div><!-- content-->';
		}
		return $html;
	}
	
	function get_paging($pageCount) {
		$prev = ''; $next = ''; $html = ''; $html2 = '';
		if(!$this->params[PAGE_ID]) $this->params[PAGE_ID] = 1;
		if($pageCount) {
			for($i=1; $i<=$pageCount; $i++) {
				if($this->params[PAGE_ID] == $i) {
					if($i > 1) {
						$href=$this->getlink(array(
							PART_ID=>$this->params[PART_ID],
							CATEGORY=>$this->params[CATEGORY],
							SUBCATEGORY=>$this->params[SUBCATEGORY],
							ID=>$this->params[ID],
							PAGE_ID=> ($i == 1 ? 1 : $i - 1)
						));
						$prev = '<a href="' . $href . '" >poprzednia</a>';
					} else {
						$prev = '';
					}
					
					if($i < $pageCount) {
						$href=$this->getlink(array(
							PART_ID=>$this->params[PART_ID],
							CATEGORY=>$this->params[CATEGORY],
							SUBCATEGORY=>$this->params[SUBCATEGORY],
							ID=>$this->params[ID],
							PAGE_ID=> ($i == $pageCount ? $pageCount : $i + 1)
						));
						$next = '<a href="' . $href . '">następna</a>';
					} else {
						$next = '';
					}
						
					$href=$this->getlink(array(
						PART_ID=>$this->params[PART_ID],
						CATEGORY=>$this->params[CATEGORY],
						SUBCATEGORY=>$this->params[SUBCATEGORY],
						ID=>$this->params[ID],
						PAGE_ID=> $i
					));
					$html .= ' <a href="' . $href . '" class="active">' . $i . '</a> ';
				} else {
					$href=$this->getlink(array(
						PART_ID=>$this->params[PART_ID],
						CATEGORY=>$this->params[CATEGORY],
						SUBCATEGORY=>$this->params[SUBCATEGORY],
						ID=>$this->params[ID],
						PAGE_ID=> $i
					));
					$html .= ' <a href="' . $href . '">' . $i . '</a> ';
				}
					
			}
			$html2 .= '<div class="articlePaging">';
			$html2 .= $prev;
			$html2 .= $html;
			$html2 .= $next;
			$html2 .= '</div>';

			return $html2;
		}
	}
	
	function lista()
	{
		$html='';
		$html.='<div id="content">';
			$sql="
				select id_dzialu_pk,nazwa,id_foto_fk
				from dzialy
				where ukryty=0 and id_dzialu_pk={$this->params[CATEGORY]}
			";
			if ($dzial=$this->getOneRowFromSql($sql)) 
			{
				$this->dzial = array($this->decode($dzial['nazwa']), $this->getlink(array(PART_ID=>PART_SUBPAGE,CATEGORY=>$dzial['id_dzialu_pk'])), $dzial['id_foto_fk']);
								
				$href=$this->getlink(array(PART_ID=>PART_SUBPAGE,CATEGORY=>$dzial['id_dzialu_pk']));
	
				
				$this->belka[BELKA_DZIAL][0]=$this->decode($dzial['nazwa']);
				$this->belka[BELKA_DZIAL][1]=$href;
				
				#$html.='<div class="siteHeader">';
				#	$html.='<h2><a title="'.$this->decode($dzial['nazwa']).'" href="'.$href.'">'.$this->decode($dzial['nazwa']).'</a></h2>';
				#$html.='</div><!--siteheder -->';

				if($this->params[SUBCATEGORY])
				{
					$this->limit = 15;
					$poddzialy=$this->getPoddzial($this->params[SUBCATEGORY]);
					
					foreach ($poddzialy as $poddzial)
					{
						$this->belka[BELKA_PODDZIAL][0]=$this->decode($poddzial['nazwa']);
						$this->belka[BELKA_PODDZIAL][1]=$this->getlink(array(PART_ID=>PART_SUBPAGE,CATEGORY=>$dzial['id_dzialu_pk'],SUBCATEGORY=>$this->params[SUBCATEGORY]));
						break;
					}
					reset($poddzialy);
				}
				else 
				{
					$poddzialy=$this->getPoddzialy($dzial['id_dzialu_pk']);
				}
			
				foreach ($poddzialy as $key=>$poddzial)
				{
//					if($poddzial['glowny_box_dzialu']==1)
					{
						$sql="
							select id_artykulu_pk,id_foto_fk,tytul,foto_podpis,skrot
							from artykuly as a
							where id_poddzialu_fk=$key and ukryty=0
							order by data desc, id_artykulu_pk desc
						";
						$ile = $this->count_records($sql);
						$sql .= $this->stronicowanie_limit($this->limit);

						$res=mysql_query($sql,$this->conn);
						if(mysql_num_rows($res))
						{
							$poddzial_href=$this->getlink(array(
								PART_ID=>PART_SUBPAGE,
								CATEGORY=>$dzial['id_dzialu_pk'],
								SUBCATEGORY=>$key,
							));
	
							$html.='<div class="siteHeader">';
								$html.='<h2><a title="'.$this->decode($poddzial['nazwa']).'" href="'.$poddzial_href.'">'.$this->decode($poddzial['nazwa']).'</a></h2>';
							$html.='</div><!--siteheder -->';
	
							
							while($article=mysql_fetch_assoc($res))
							{
								$article_href=$this->getlink(array(
									PART_ID=>PART_SUBPAGE,
									CATEGORY=>$dzial['id_dzialu_pk'],
									SUBCATEGORY=>$key,
									ID=>$article['id_artykulu_pk']
								));
						
								$html.='<h3 class="firsth"><a href="'.$article_href.'" class="firsth">'.$this->decode($article['tytul']).'</a></h3>';
						 		$html.='<p>'.$this->decode($article['skrot']).' <a href="'.$article_href.'">więcej&nbsp;&raquo;</a></p>';
						 	}
						 	if($this->params[SUBCATEGORY])
							 	$html .= $this->stronicowanie($this->params, $ile, $this->limit);
							else if($ile > $this->limit)
						 		$html.='<p style="text-align:right;width: 100%"><a href="'.$poddzial_href.'">Wszystkie w tym dziale&nbsp;&raquo;</a></p>';
								$html .= '';
						}
					}
				}
				
			//	$html.='<p>&nbsp;</p>';
				$html.=$this->contentFooter($dzial['id_dzialu_pk']);
			}	
		$html.='</div><!-- content -->';
		return $html;
		
	}
	
	function contentFooter($id_dzialu)
	{
		$html='';
		
		/*
		$html.='<div id="contentFooter">';
			$html.='<ul>';
				if(is_array($this->dzial) && !$this->dzial[2])
					$html.='<li><a title="'.$this->dzial[0].'" href="'.$this->dzial[1].'" style="font-size:10px;font-weight: 600">'.$this->dzial[0].'</a> | </li>';
				if(is_array($this->dzial) && $this->dzial[2])
					$html.='<li><a title="'.$this->dzial[0].'" href="'.$this->dzial[1].'" style="border: 0px; text-decoration: none"><img src="' . $this->getImgPathDB($this->dzial[2], $x=0, $y=20) . '" alt="" border="0" style="text-align: center; margin-right:4px;" /></a></li>';
					$i=0;
				$poddzialy=$this->getPoddzialy($id_dzialu);
				foreach ($poddzialy as $key=>$poddzial)
				{
					$href=$this->getlink(array(
						PART_ID=>PART_SUBPAGE,
						CATEGORY=>$id_dzialu,
						SUBCATEGORY=>$key,
					));
					$html.='<li>';
					if($i) $html.=' | ';
					$html.='<a title="'.$poddzial['nazwa'].'" href="'.$href.'">'.$poddzial['nazwa'].'</a>';
					$html.='</li>';
					$i++;
				}
			$html.='</ul>';
		$html.='</div>';
		*/
		
		$html.='<div id="contentFooter">';
			$html.='';
				if(is_array($this->dzial) && !$this->dzial[2])
					$html.='<a title="'.$this->dzial[0].'" href="'.$this->dzial[1].'" style="font-size:10px;font-weight: 600; margin-left:30px;">'.$this->dzial[0].'</a> | ';
				if(is_array($this->dzial) && $this->dzial[2])
					$html.='<a title="'.$this->dzial[0].'" href="'.$this->dzial[1].'" style="border: 0px; text-decoration: none"><img src="' . $this->getImgPathDB($this->dzial[2], $x=0, $y=20) . '" alt="" border="0" style="text-align: center; margin:0 4px 0 30px;" /></a>';
					$i=0;
				$poddzialy=$this->getPoddzialy($id_dzialu);
				foreach ($poddzialy as $key=>$poddzial)
				{
					$href=$this->getlink(array(
						PART_ID=>PART_SUBPAGE,
						CATEGORY=>$id_dzialu,
						SUBCATEGORY=>$key,
					));
					$html.='';
					if($i) $html.=' | ';
					$html.='<a title="'.$poddzial['nazwa'].'" href="'.$href.'">'.$poddzial['nazwa'].'</a>';
					$html.='';
					$i++;
				}
			$html.='';
		$html.='</div>';
		
		return $html;
	}
	
	
	function content()
	{
		$html='';
		if($this->params[ID])
		{
			$html.=$this->artykul($this->params[ID]);
		}
		else 
		{
			$html.=$this->lista();
		}
		
		
		
		
		return $html;
	}

	
	
	
	function rightContent()
	{
		$html='';
		$n=0;
		
		if($this->params[ID]) {
			$sql="
			select a.id_artykulu_pk,a.id_foto_fk,a.tytul,a.foto_podpis,a.skrot, a.id_poddzialu_fk, p.id_dzialu_fk
			from artykuly as a left join poddzialy as p on a.id_poddzialu_fk = p.id_poddzialu_pk  
			where a.ukryty=0
			order by a.data desc, a.id_artykulu_pk desc
			limit 5
			";
			$res=mysql_query($sql,$this->conn);
			if(mysql_num_rows($res))
			{
				$html.='<div id="rightContentColumnArticleBox">';
				$html.='<h3><a>Najnowsze artykuły<a><img src="design_img/najnowsze.gif" border="0" alt="Najnowsze artykuły" style="margin-left: 5px;vertical-align:middle" /></h3>';
				$html.='<ul>';
					while($article=mysql_fetch_assoc($res))
					{
						$article_href=$this->getlink(array(
							PART_ID=>PART_SUBPAGE,
							CATEGORY=>$article['id_dzialu_fk'],
							SUBCATEGORY=>$article['id_poddzialu_fk'],
							ID=>$article['id_artykulu_pk']
						));
						$strong = date("Y-m-d") == $article['data'];
		  				$html.='<li><a href="'.$article_href.'">' . ($strong ? '<strong>' : '') . $this->decode($article['tytul']) . ($strong ? '</strong>' : '') . '</a></li>';
				 	}
				$html.='<li class="lastElement"><div class="clear"></div></li>';

				$html.='</ul>';
				$html.='</div>';
			}
		}
		
		
		
		if($this->params[CATEGORY])
		{
			$poddzialy=$this->getPoddzialy($this->params[CATEGORY]);
			
			$this->addPoddzialyPowiazane($poddzialy,$this->params[CATEGORY], $this->params[SUBCATEGORY]);
						
			foreach ($poddzialy as $key=>$poddzial)
			{
				$pokaz=0;
//				echo '<pre>';var_dump($poddzial);echo '</pre>';
				if($this->params[SUBCATEGORY])
				{
					if($key!=$this->params[SUBCATEGORY]) $pokaz=1;
				}
				else 
				{
					if($poddzial['glowny_box_dzialu']==0) $pokaz=1;
				}
				
				if($pokaz)
				{
					$sql="
						select a.id_artykulu_pk,a.id_foto_fk,a.tytul,a.foto_podpis,a.skrot
						from artykuly as a 
						where a.id_poddzialu_fk=$key and a.ukryty=0
						order by a.data desc, a.id_artykulu_pk desc
						limit 5
					";
					$res=mysql_query($sql,$this->conn);
					if(mysql_num_rows($res))
					{
						$href_poddzial=$this->getlink(array(
							PART_ID=>PART_SUBPAGE,
							CATEGORY=>$poddzial['id_dzialu'],
							SUBCATEGORY=>$key
						));
						
						$sql = "
							SELECT dk.nazwa_pliku 
							FROM dzialy_klasy as dk 
								left join dzialy as d on d.id_klasy_fk = dk.id_klasy_pk
								left join poddzialy as pd on pd.id_dzialu_fk = d.id_dzialu_pk
							WHERE id_poddzialu_pk = {$key}
							";
						if($klasaRes=mysql_query($sql,$this->conn))
						{
							$klasa = mysql_fetch_assoc($klasaRes);
							
							$class = $klasa['nazwa_pliku'];
					//		var_dump($class); echo '<br>';
							if(0 < ($pos = strpos($class, '_'))) {
								$class = substr($class, $pos + 1, strlen($class) - $pos - 3 -  strpos($class, '.'));
								$class = 'element' . strtoupper($class[0]) . substr($class, 1);
							} else {
								$class = 'elementClassic';
							}
							
					//		var_dump($class); echo '<br>';
						}
						
						
						
						$html.='<div id="rightContentColumnArticleBox">';
						$html.='<h3 class="' . $class . '"><a href="'.$href_poddzial.'">'.$poddzial['nazwa'].'</a></h3>';
						$html.='<ul class="' . $class . '">';
							$i=0;
							while($article=mysql_fetch_assoc($res))
							{
								$article_href=$this->getlink(array(
									PART_ID=>PART_SUBPAGE,
									CATEGORY=>$poddzial['id_dzialu'],
									SUBCATEGORY=>$key,
									ID=>$article['id_artykulu_pk']
								));
								$strong = date("Y-m-d") == $article['data'];
				  				$html.='<li><a href="'.$article_href.'">' . ($strong ? '<strong>' : '') . $this->decode($article['tytul']) . ($strong ? '</strong>' : '') . '</a></li>';

// 								if(!$i)
// 								{
// 									$html.='<li><a href="'.$article_href.'"><strong>'.$this->decode($article['tytul']).'</strong></a></li>';
// 								}
// 								else 
// 								{
// 									$html.='<li><a href="'.$article_href.'">'.$this->decode($article['tytul']).'</a></li>';
// 								}
								$i++;
						 	}
						 	
						 	$html.='<li class="lastElement"><a href="'.$href_poddzial.'">Wszystkie w tym dziale</a></li>';
						$html.='</ul>';
						$html.='</div>';
					}
					if (!$n)
					{
					  	$html.='<div id="rightContentColumnArticleBox">';
					  	  $html.='<div id="menuLeftTopCorner"></div>
                  			<div id="menuCenterTop2"></div>
        			          <div id="menuRightTopCorner"></div>
        			          <div class="clear"></div>
        			          <div id="menuCenter2"><a href="javascript:void(0)" onclick="show_hide(1)" class="panelLink">Wszystkie nasze działy &raquo;</a></div>
        			          <div class="clear"></div>
        			          <div id="menuLeftBottomCorner"></div>
        			          <div id="menuCenterBottom2"></div>
        			          <div id="menuRightBottomCorner"></div>
        			          <div class="clear"></div>
					              <div id="showHidePanel1" class="panel">
				 		              <ul>';
				 		              $sql = "SELECT * FROM dzialy WHERE ukryty=0 ORDER BY nazwa ASC";
				 		              if($res = mysql_query($sql, $this->conn))
				 		              while($rows[] = mysql_fetch_assoc($res)) ;
				 		              for($i=0; $rows[$i]; $i++) {
				 		                $href = $this->getlink(array(PART_ID=>PART_SUBPAGE, CATEGORY=> $rows[$i]['id_dzialu_pk']));
				 		                if($i == count($rows) - 2) $class = 'class="last"'; else $class = '';
					 		            $html .= '<li style="padding: 3px" ' . $class . '><a href="' . $href . '">' . $rows[$i]['nazwa'] . '</a></li>'; 
				 		              }
				 		      $html.='</ul>';
				 		    $html.='</div>';
				 		  $html.='</div>';
						$n++;
					}
				}
			}
		}
		if (!$n)
		{
					  	$html.='<div id="rightContentColumnArticleBox">';
					  	  $html.='<div id="menuLeftTopCorner"></div>
                  			<div id="menuCenterTop2"></div>
        			          <div id="menuRightTopCorner"></div>
        			          <div class="clear"></div>
        			          <div id="menuCenter2"><a href="javascript:void(0)" onclick="show_hide(1)" class="panelLink">Wszystkie nasze działy &raquo;</a></div>
        			          <div class="clear"></div>
        			          <div id="menuLeftBottomCorner"></div>
        			          <div id="menuCenterBottom2"></div>
        			          <div id="menuRightBottomCorner"></div>
        			          <div class="clear"></div>
					              <div id="showHidePanel1" class="panel">
				 		              <ul>';
				 		              $sql = "SELECT * FROM dzialy WHERE ukryty=0 ORDER BY nazwa ASC";
				 		              if($res = mysql_query($sql, $this->conn))
				 		              while($rows[] = mysql_fetch_assoc($res)) ;
				 		              for($i=0; $rows[$i]; $i++) {
				 		                $href = $this->getlink(array(PART_ID=>PART_SUBPAGE, CATEGORY=> $rows[$i]['id_dzialu_pk']));
				 		                if($i == count($rows) - 2) $class = 'class="last"'; else $class = '';
					 		            $html .= '<li style="padding: 3px" ' . $class . '><a href="' . $href . '">' . $rows[$i]['nazwa'] . '</a></li>'; 
				 		              }
				 		      $html.='</ul>';
				 		    $html.='</div>';
				 		  $html.='</div>';
			        $n++;
		}
		
		
		
		return $html;
		
		
	}
	
	
	
	function customClass($className)
	{
		$filePath=FILE_DIR.'../custom/'.$className.'.class.php';
		
		if(file_exists($filePath))
		{
			require_once($filePath);
			$customObj=new $className();
			return $customObj->content();
		}
	}
	
}


?>