<?php

/**

* @version		1.1

* @package		DJ Classifieds

* @subpackage	DJ Classifieds Component

* @copyright	Copyright (C) 2010 Blue Constant Media LTD, All rights reserved.

* @license		http://www.gnu.org/licenses GNU/GPL

* @autor url    http://design-joomla.eu

* @autor email  contact@design-joomla.eu

* @Developer    Lukasz Ciastek - lukasz.ciastek@design-joomla.eu

* 

* 

* DJ Classifieds is free software: you can redistribute it and/or modify

* it under the terms of the GNU General Public License as published by

* the Free Software Foundation, either version 3 of the License, or

* (at your option) any later version.

*

* DJ Classifieds is distributed in the hope that it will be useful,

* but WITHOUT ANY WARRANTY; without even the implied warranty of

* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the

* GNU General Public License for more details.

*

* You should have received a copy of the GNU General Public License

* along with DJ Classifieds. If not, see <http://www.gnu.org/licenses/>.

* 

*/

defined ('_JEXEC') or die('Restricted access');

require_once(dirname(__FILE__).DS.'helper.php');

JHTML::_('behavior.mootools');

$main_id= JRequest::getVar('cid','0','int');

$par =& $mainframe->getParams('com_djclassifieds');

$limit	= JRequest::getVar('limit', $par->get('limit_djitem_show'), '', 'int');

$limitstart	= JRequest::getVar('limitstart', 0, '', 'int');

$order = JRequest::getVar('order', 'name', '', 'string');

$lista_count_items = 0;

$sw = JRequest::getVar('search', '', '', 'string');

$uid	= JRequest::getVar('uid', 0, '', 'int');



$Itemid = JRequest::getVar('Itemid', 0, 'int');

$menus	= &JSite::getMenu();

foreach($menus->_items as $m){

	if($m->link == 'index.php?option=com_djclassifieds&view=show&cid=0'){

		$Itemid=$m->id;

		break;

	}

}



?>

<div id="dj-classifieds" class="clearfix">

	<?php $modules_breadcrumb = &JModuleHelper::getModules('dj_breadcrumb');

			if(count($modules_breadcrumb)>0){

				echo '<div class="dj_breadcrumb clearfix">';

				foreach (array_keys($modules_breadcrumb) as $m){

					echo JModuleHelper::renderModule($modules_breadcrumb[$m]);

				}

				echo'</div>';		

			}

				

		if($sw!='' || $uid>0){

			$style=" hide";

		}else{

			$style="";

		}

	

	?>			

			

	<table class="dj-category<?php echo $style;?>" width="100%">

	<tr><th colspan="3">

		<?php

		if($this->main_name == ""){

			echo JText::_('Categories');

		}else{

			echo $this->main_name;	

		}

		?> 

	</th></tr>

	<tr class="row0">

	<?php

	$all_cat = Array();

	$ii=0;

	$row=0;

	foreach($this->cat_list as $c){

		if($c->parent_id==$main_id){

			$_list = new TreeHelper();

			$lists = $_list->getList($c->id,$this->cat_list);

	

			if(count($lists)>1){

				if($ii%3==0 && $ii!=0){

					$row==0 ? $row=1 : $row=0;

					echo '</tr><tr class="row'.$row.'"><td class="cat" >';	

				}else{

					echo '<td class="cat" >';

				}

				

				foreach($lists as $l){

					$all_cat[]=$l;

				}

				$count_items=$this->model->getCountCategories($lists);

				$lista_count_items = $lista_count_items + $count_items;

				echo '<div class="title">';

				if($c->icon_url){

					echo '<img src="'.JURI::base().'/components/com_djclassifieds/images/'.$c->icon_url.'.ths.jpg"  />';

				}

				echo '<a href="index.php?option=com_djclassifieds&view=show&cid='.$c->id.'&Itemid='.$Itemid.'">';

				

				if($this->par->get('show_adsn_cat')){

					echo $c->name.'<span>('.$count_items.')</span></a></div>';	

				}else{

					echo $c->name.'</a></div>';	

				}				

				echo '<div class="cat_desc">'.$c->description.'</div>';

				echo '</td>';

			}else{

				if($ii%3==0 && $ii!=0){

					$row==0 ? $row=1 : $row=0;

					echo '</tr><tr class="row'.$row.'"><td class="cat" >';				

				}else{

					echo '<td class="cat" >';

				}

				$all_cat[] = $lists[0];

				$count_items=$this->model->getCountCategories($lists);

				$lista_count_items = $lista_count_items + $count_items;	

				echo '<div class="title">';			

				if($c->icon_url){

					echo '<img src="'.JURI::base().'/components/com_djclassifieds/images/'.$c->icon_url.'.ths.jpg"  />';

				}

				echo '<a href="index.php?option=com_djclassifieds&view=showlist&cid='.$c->id.'&Itemid='.$Itemid.'">';

				if($this->par->get('show_adsn_cat')){

					echo $c->name.'<span>('.$count_items.')</span></a></div>';	

				}else{

					echo $c->name.'</a></div>';	

				}				

				echo '<div class="cat_desc">'.$c->description.'</div>';

				echo '</td>';			

			}		

		$ii++;	

		}

	}

	

	if($ii%3==1){

		echo '<td class="cat" ></td><td class="cat" ></td>';

	}

	if($ii%3==2){

		echo '<td class="cat" ></td>';

	}

	

	

	

	if($main_id=='0'){

		$items = $this->model->getAllElements();

		$lista_count_items = $this->model->getCountAllElements();

	}else{

		$all_cat[]=$main_id;

		$items = $this->model->getElements($all_cat);

		$lista_count_items = $this->model->getCountCategories($all_cat);

	}

?>

</tr><tr class="last"><td colspan="3"></td></tr></table>

		<?php $modules = &JModuleHelper::getModules('banner_items');

			if(count($modules)>0){

				echo '<div class="banner_items clearfix">';

				$i=1;

				foreach (array_keys($modules) as $m){

					echo '<div class="banner'.$i++.'">';

					echo JModuleHelper::renderModule($modules[$m]);

					echo '</div>';

				}

				echo'</div>';		

			}

			?>

<?php 



if($sw){?>

<div class="searchword">

	<?php echo JText::_('Results for').' : <span>'.$sw.'</span>'; ?>

</div>

<?php } 

if($uid!='0'){	?>

<div class="user_items">

	<?php echo JText::_('Results for').' : <span>'.$this->model->getUserName($uid).' ('.$lista_count_items.')</span>'; ?>

</div>

<?php } ?>

<div class="items">

<?php	

	$r=TRUE;

	?>

	<table class="dj-items" width="100%">

	<tr class="main_title">

		<th colspan="2" class="name">

			<?php if($order=="name"){$class="active";}else{$class="normal";}?><a class="<?php echo $class; ?>" href="index.php?option=com_djclassifieds&view=show&cid=<?php echo $main_id; ?>&order=title<?php if($sw){ echo '&search='.$sw; };if($uid){ echo '&uid='.$uid; }?>"><?php echo JText::_('Title');?></a> 

		</th>

		<th>

			<?php if($order=="category"){$class="active";}else{$class="normal";}?><a class="<?php echo $class; ?>" href="index.php?option=com_djclassifieds&view=show&cid=<?php echo $main_id; ?>&order=category<?php if($sw){ echo '&search='.$sw; };if($uid){ echo '&uid='.$uid; }?>"><?php echo JText::_('Category');?></a> 

		</th>

		<th>

			<?php if($order=="description"){$class="active";}else{$class="normal";}?><a class="<?php echo $class; ?>" href="index.php?option=com_djclassifieds&view=show&cid=<?php echo $main_id; ?>&order=description<?php if($sw){ echo '&search='.$sw; };if($uid){ echo '&uid='.$uid; }?>"><?php echo JText::_('Description');?></a>			 

		</th>

		<th>

			<?php if($order=="date"){$class="active";}else{$class="normal";}?><a class="<?php echo $class; ?>" href="index.php?option=com_djclassifieds&view=show&cid=<?php echo $main_id; ?>&order=date<?php if($sw){ echo '&search='.$sw; };if($uid){ echo '&uid='.$uid; }?>"><?php echo JText::_('Added');?></a> 

		</th>		

		<th>

			<?php if($order=="display"){$class="active";}else{$class="normal";}?><a class="<?php echo $class; ?>" href="index.php?option=com_djclassifieds&view=show&cid=<?php echo $main_id; ?>&order=display<?php if($sw){ echo '&search='.$sw; };if($uid){ echo '&uid='.$uid; }?>"><?php echo JText::_('Displayed');?></a>			 

		</th>

	</tr>		

	<?php

	if($this->par->get('showitem_jump',0)){

		$anch = '#dj-classifieds';

	}else{

		$anch='';

	}

	foreach($items as $i){

		$row = $r==TRUE ? '0' : '1';

		$r=!$r;

		if($i->special==1){$row.=' special';}

		echo '<tr class="row'.$row.'">';

		echo '<td class="icon">';

		if($i->image_url!=''){

			$images=explode(';',$i->image_url);	

			if((int)$par->get('tooltip_img','1')){				

				echo '<a href="index.php?option=com_djclassifieds&view=showitem&cid='.$i->cat_id.'&id='.$i->id.'&Itemid='.$Itemid.$anch.'">';								

				$tip_title=str_ireplace('"',"'",$i->name);

				$tip_cont = '<div class=\'title\'>'.JText::_('Description').'</div><div class=\'desc\'>'.str_ireplace('"',"'",strip_tags($i->description)).'</div>';

				if((int)$par->get('showcontact','1')){

					$tip_cont .= '<div class=\'title\'>'.JText::_('Contact').'</div><div class=\'contact\'>'.$i->contact.'</div>';

				}

				if((int)$par->get('showprice','1')){

					$tip_cont .= '<div class=\'title\'>'.JText::_('Price').'</div><div class=\'price\'>'.$i->price.'</div>';

				}

				if($i->image_url!=''){

					$tip_cont .= '<div class=\'title\'>'.JText::_('Images').'</div><div class=\'images_box\'>';

					$images = explode(";",$i->image_url);

					

					for($ii=0; $ii<count($images)-1;$ii++ ){  				

	   	        		$tip_cont .= '<img src=\''.JURI::base().'components/com_djclassifieds/images/'.$images[$ii].'.ths.jpg\' />';   				

					}

					$tip_cont .= '</div>';

				}

				echo '<img src="'.JURI::base().'/components/com_djclassifieds/images/'.$images[0].'.ths.jpg" alt="" class="Tips1" title="'.$tip_title.' :: '.$tip_cont.'" />';

				echo '</a>';

			}else{

				echo '<a href="index.php?option=com_djclassifieds&view=showitem&cid='.$i->cat_id.'&id='.$i->id.'&Itemid='.$Itemid.$anch.'">';					

				echo '<img src="'.JURI::base().'/components/com_djclassifieds/images/'.$images[0].'.ths.jpg"  />';

				echo '</a>';

				

			}

	

	

		}else{

			if((int)$par->get('tooltip_img','1')){

				echo '<a href="index.php?option=com_djclassifieds&view=showitem&cid='.$i->cat_id.'&id='.$i->id.'&Itemid='.$Itemid.$anch.'">';

			

					$tip_title=str_ireplace('"',"'",$i->name);

					$tip_cont = '<div class=\'title\'>'.JText::_('Description').'</div><div class=\'desc\'>'.str_ireplace('"',"'",strip_tags($i->description)).'</div>';

					if((int)$par->get('showcontact','1')){

						$tip_cont .= '<div class=\'title\'>'.JText::_('Contact').'</div><div class=\'contact\'>'.$i->contact.'</div>';

					}

					if((int)$par->get('showprice','1')){

						$tip_cont .= '<div class=\'title\'>'.JText::_('Price').'</div><div class=\'price\'>'.$i->price.'</div>';

					}

					echo '<img src="'.JURI::base().'/components/com_djclassifieds/images/no-image.png" alt="" class="Tips1" title="'.$tip_title.' :: '.$tip_cont.'" />';

				echo '</a>';		

			}else{

				echo '<a href="index.php?option=com_djclassifieds&view=showitem&cid='.$i->cat_id.'&id='.$i->id.'&Itemid='.$Itemid.$anch.'">';

				echo '<img src="'.JURI::base().'/components/com_djclassifieds/images/no-image.png"  />';

				echo '</a>';	

			}

		}

		echo '</td>';

		echo '<td class="name">';

		

		if((int)$par->get('tooltip_title','1')){

			echo '<a class="title Tips1" href="index.php?option=com_djclassifieds&view=showitem&cid='.$i->cat_id.'&id='.$i->id.'&Itemid='.$Itemid.$anch.'" title="'.$tip_title.' :: '.$tip_cont.'" >'.$i->name.'</a>';

		}else{

			echo '<a class="title" href="index.php?option=com_djclassifieds&view=showitem&cid='.$i->cat_id.'&id='.$i->id.'&Itemid='.$Itemid.$anch.'" >'.$i->name.'</a>';

		}

		echo '</td>';

		echo '<td class="cat_name">'.$i->c_name.'</td>';

		echo '<td class="description"><a class="title" href="index.php?option=com_djclassifieds&view=showitem&cid='.$i->cat_id.'&id='.$i->id.'&Itemid='.$Itemid.$anch.'">'.$i->intro_desc.'</a></td>';

		echo '<td class="date_start">'.$i->date_start.'</td>';

		echo '<td class="date_exp" align="center">'.$i->display.'</td>';	

		echo '</tr>';

	}

	?>	

	<?php

		$row = $r==TRUE ? '0' : '1';

		echo '<tr class="row'.$row.'"><td class="pag" colspan="6" >';	     

			$pagination = new JPagination($lista_count_items, $limitstart, $limit);

			echo $pagination->getPagesLinks(); 

		echo '</td></tr>';

	?>

	</table>



</div>	

</div>



<script type="text/javascript">

	var Tips1 = new Tips($$('.Tips1'),{className:'djcf'});

</script>