<?php
/*
* @name simplerating 1.01
* Created By Chris grVulture Michaelides
* http://www.axxis.gr
* @copyright  Copyright (C) 2010,2011  AXXIS INTERNET SOLUTIONS / All rights reserved.
* @license http://www.gnu.org/copyleft/gpl.html GNU/GPL, see LICENSE.php
*/

defined('_JEXEC') or die(dirname(__FILE__).DS.'Restricted access');
        $version = new JVersion;
        $joomla = $version->getShortVersion();
        switch (substr($joomla,0,3)) {
            case '1.5':
              define('_GRSITE',JURI::base()."images/");
              define('_TICK',"<img src='".JURI::base()."images/tick.png' />");
              define('_PUB_X',"<img src='".JURI::base()."images/publish_x.png' />");
                break;
            default:
              define('_GRSITE',JURI::base()."templates/bluestork/images/admin/");
              define('_TICK',"<img src='".JURI::base()."templates/bluestork/images/admin/tick.png' />");
              define('_PUB_X',"<img src='".JURI::base()."templates/bluestork/images/admin/publish_x.png' />");
                break;
        }
$document =& JFactory::getDocument();
$document->addStyleDeclaration("div.current label, div.current span.faux-label {
    display: inline !important;
    float: none !important;
}
 div.current input, div.current textarea, div.current select {
    float: none !important;
}");

class HTML_simplerating{

function create_pulldown_menu($attribute_name , $selected_value, $options_array = false){
	$default_options_array = array(0,3,5,8);
	$selected='';
	$selection_string = "<SELECT name=$attribute_name>";
	if (!$options_array || count($options_array)==0){
		$options_array = $default_options_array;
	}
	foreach($options_array as $value){
		if($selected_value->$attribute_name==$value)
		{
			$selected='selected';
		}else{
			$selected='';
		}
		$selection_string=$selection_string.'<OPTION value='.$value.' '.$selected.'>'.$value.'</option>';
	}
	$selection_string=$selection_string."</select>";
	return $selection_string;
}

function listreviews( $option, &$rows, &$pageNav, &$navBar ) {
	$db=JFactory::getDBO();
	$search = JRequest::getCmd( 'search' );
	$cpath = JRequest::getCmd( 'cpath' );
  $controller = new simpleratingController();
	HTML_simplerating::ListReviewsToolbar();
	?>
	<table cellpadding="4" cellspacing="0" border="0" width="100%" class="adminlist">
		<tr>
			<th width="20">
			 <a class="free-download smallfont" href="http://www.axxis.gr/media/AXXIS_Simple_Rating.pdf" target="_blank">Documentation</a>
			</th>
		</tr>
	</table>
	<form action="index.php" method="post" name="adminForm" id="adminForm">
	<table cellpadding="4" cellspacing="0" border="0" width="100%" class="adminlist">
		<tr>
			<th width="20">
			<input type="checkbox" name="toggle" value="" onclick="checkAll(<?php echo count($rows); ?>);" />
			</th>
			<th width="20">ID</th>
			<th>Date</th>
			<th>Reviewed Item</th>
			<th>Rating</th>
			<th width="20"><a href='index.php?option=com_simplerating&act=reviews&task=published'>Published</a></th>
		</tr>
	
	<?php
	$k = 0;
	for($i=0; $i < count( $rows ); $i++) {
		$row = $rows[$i];
		//echo "<pre>";print_r($row);echo "</pre>";
		$owner = stripslashes($row->name.' ('.$row->username.')');
		$review_text= stripslashes($row->review_text);
		if ($row->option=='com_comprofiler') {
		  $cb_itemid = $controller->getItemid($row->option);
		  $itemlink = JURI::root()."index.php?option=com_comprofiler&amp;task=userProfile&amp;user=".$row->extra_id.$cb_itemid;
  		$db->setQuery("SELECT name, username FROM #__users WHERE id=".$row->extra_id);
  		$reviewer=$db->loadObject();
  		$reviewer=stripslashes($reviewer->name." (".$reviewer->username.")");
		  $owner_link = JURI::root()."index.php?option=com_comprofiler&amp;task=userProfile&amp;user=".$row->user_id.$cb_itemid;
  		$db->setQuery("SELECT name, username FROM #__users WHERE id=".$row->user_id);
  		$owner=$db->loadObject();
  		$owner=stripslashes($owner->name." (".$owner->username.")");
		}
		if ($row->option=='com_content') {
		  $cb_itemid = $controller->getItemid($row->option,'&view=article&id='.$row->extra_id);
		  $itemlink = JURI::root()."index.php?option=com_content&view=article&id=".$row->extra_id.$cb_itemid;
  		$db->setQuery("SELECT title FROM #__content WHERE id=".$row->extra_id);
  		$reviewer=$db->loadObject();
  		$reviewer=stripslashes($reviewer->title);
		  $owner_link = JURI::root()."index.php?option=com_comprofiler&amp;task=userProfile&amp;user=".$row->user_id.$cb_itemid;
  		$db->setQuery("SELECT name, username FROM #__users WHERE id=".$row->user_id);
  		$owner=$db->loadObject();
  		$owner=stripslashes($owner->name." (".$owner->username.")");
		}
		?>
		<tr class="<?php echo "row$k"; ?>">
			<td><input type="checkbox" id="cb<?php echo $i;?>" name="cid[]" value="<?php echo $row->id; ?>" onclick="isChecked(this.checked);" /></td>
			<td><?php echo $row->id; ?></td>
			<td><?php echo date('l jS\, F Y h:i',strtotime($row->date)); ?></td>
			<td><?php echo '<a target="_blank" href="'.$itemlink.'">'.$reviewer.'</a>'; ?></td>
    	<td><table><tr><td><big><b><?php echo $row->rating_sum; ?></b></big></b>&nbsp;&nbsp;Submitted by: <?php echo '<a target="_blank" href="'.$owner_link.'">'.$owner.'</a>'; ?></a></td></tr></table>
			<?php echo $review_text; ?></td>
			<td><div id='publishsimplerating_extravote<?php echo $row->id; ?>'><a href="javascript:publish(<?php if ($row->published==1) echo $row->id.",0,'simplerating_extravote'"; else echo $row->id.",1,'simplerating_extravote'"; ?>)"><?php if ($row->published==1) echo _TICK; else echo _PUB_X; ?></div></td>
		<?php $k = 1 - $k; ?>
		</tr>
		<?php 
	} 
	?>
	<tfoot>
	<tr>
	<td colspan="8"><?php echo $pageNav->getListFooter(); ?></td>
	</tr>
	</tfoot>
	</table>
	<input type="hidden" id="grsite" value="<?php echo _GRSITE; ?>" />
	<input type="hidden" id="grroot" value="<?php echo JURI::base(); ?>" />
	<input type="hidden" name="option" value="<?php echo $option; ?>" />
	<input type="hidden" name="act" value="reviews" />
	<?php if(strlen($search)>0){?><input type="hidden" name="search" value="<?php echo $search;?>" /><?php }?>
	<?php if(strlen($cpath)>0){?><input type="hidden" name="cpath" value="<?php echo $cpath;?>" /><?php }?>
	<input type="hidden" name="task" value="" />
	<input type="hidden" name="boxchecked" value="0" />
	</form> 
<?php 
} 


function listreports( $option, &$rows, &$pageNav, &$navBar ) {
	$db=JFactory::getDBO();
	$search = JRequest::getCmd( 'search' );
	$cpath = JRequest::getCmd( 'cpath' );
  $controller = new simpleratingController();

	HTML_simplerating::ListreportsToolbar();
	?>
	<table cellpadding="4" cellspacing="0" border="0" width="100%" class="adminlist">
		<tr>
			<th width="20">
			 <a class="free-download smallfont" href="http://www.axxis.gr/media/AXXIS_Simple_Rating.pdf" target="_blank">Documentation</a>
			</th>
		</tr>
	</table>
	<form action="index.php" method="post" name="adminForm" id="adminForm">
	<table cellpadding="4" cellspacing="0" border="0" width="100%" class="adminlist">
		<tr>
			<th width="20">
			<input type="checkbox" name="toggle" value="" onclick="checkAll(<?php echo count($rows); ?>);" />
			</th>
			<th width="20">ID</th>
			<th>Date</th>
      <th>Report</th>
			<th>Reviewed Item</th>
		</tr>
	
	<?php
	$k = 0;
	for($i=0; $i < count( $rows ); $i++) {
		$row = $rows[$i];
		//echo "<pre>";print_r($row);echo "</pre>";
		if ($row->option=='com_comprofiler') {
		  $cb_itemid = $controller->getItemid($row->option);
		  $reporter_link = JURI::root()."index.php?option=com_comprofiler&amp;task=userProfile&amp;user=".$row->report_user.$cb_itemid;
  		$db->setQuery("SELECT name, username FROM #__users WHERE id=".$row->report_user);
  		$reviewer=$db->loadObject();
  		$rowname=stripslashes($reviewer->name." (".$reviewer->username.")");
		  $reviewer_link = JURI::root()."index.php?option=com_comprofiler&amp;task=userProfile&amp;user=".$row->user_id.$cb_itemid;
  		$db->setQuery("SELECT name, username FROM #__users WHERE id=".$row->user_id);
  		$reviewer=$db->loadObject();
  		$reviewer=stripslashes($reviewer->name." (".$reviewer->username.")");
		  $reviewed_link = JURI::root()."index.php?option=com_comprofiler&amp;task=userProfile&amp;user=".$row->extra_id.$cb_itemid;
  		$db->setQuery("SELECT name, username FROM #__users WHERE id=".$row->extra_id);
  		$reviewed=$db->loadObject();
  		$reviewed=stripslashes($reviewed->name." (".$reviewed->username.")");
		}
		if ($row->option=='com_content') {
		  $cb_itemid = $controller->getItemid('com_comprofiler');
		  $reporter_link = JURI::root()."index.php?option=com_comprofiler&amp;task=userProfile&amp;user=".$row->report_user.$cb_itemid;
  		$db->setQuery("SELECT name, username FROM #__users WHERE id=".$row->report_user);
  		$reviewer=$db->loadObject();
  		$rowname=stripslashes($reviewer->name." (".$reviewer->username.")");
		  $reviewer_link = JURI::root()."index.php?option=com_comprofiler&amp;task=userProfile&amp;user=".$row->user_id.$cb_itemid;
  		$db->setQuery("SELECT name, username FROM #__users WHERE id=".$row->user_id);
  		$reviewer=$db->loadObject();
  		$reviewer=stripslashes($reviewer->name." (".$reviewer->username.")");
		  $cb_itemid = $controller->getItemid($row->option,'&view=article&id='.$row->extra_id);
		  $reviewed_link = JURI::root()."index.php?option=com_content&view=article&id=".$row->extra_id.$cb_itemid;
  		$db->setQuery("SELECT title FROM #__content WHERE id=".$row->extra_id);
  		$reviewed=$db->loadObject();
  		$reviewed=stripslashes($reviewed->title);
		}
		$rowdescription = stripslashes($row->report_text);
		$thumbnail = $row->thumbnail;
		$review_text= stripslashes($row->review_text);
		$db->setQuery("SELECT name, username FROM #__users WHERE id=".$row->user_id);
		$owner=$db->loadObject();
		$owner=$owner->name." (".$owner->username.")";
		?>
		<tr class="<?php echo "row$k"; ?>">
			<td><input type="checkbox" id="cb<?php echo $i;?>" name="cid[]" value="<?php echo $row->id; ?>" onclick="isChecked(this.checked);" /></td>
			<td><?php echo $row->id; ?></td>
			<td><?php echo date('l jS\, F Y h:i',$row->date); ?></td>
			<td><table><tr><td>Submitted by: <?php echo '<a target="_blank" href="'.$reporter_link.'">'.$rowname.'</a>'; ?></td></tr></table>
			<?php echo $rowdescription; ?></td>
    	<td><table><tr><td><h3><?php echo '<a target="_blank" href="'.$reviewed_link.'">'.$reviewed.'</a>'; ?></h3><big><b><?php echo $row->rating_sum; ?></b></big>&nbsp;&nbsp;Submitted by: <?php echo '<a target="_blank" href="'.$reviewer_link.'">'.$reviewer.'</a>'; ?></td></tr></table>
			<?php echo $review_text; ?></td>
		<?php $k = 1 - $k; ?>
		</tr>
		<?php 
	} 
	?>
	<tfoot>
	<tr>
	<td colspan="8"><?php echo $pageNav->getListFooter(); ?></td>
	</tr>
	</tfoot>
	</table>
	<input type="hidden" name="option" value="<?php echo $option; ?>" />
	<input type="hidden" name="act" value="reports" />
	<?php if(strlen($search)>0){?><input type="hidden" name="search" value="<?php echo $search;?>" /><?php }?>
	<?php if(strlen($cpath)>0){?><input type="hidden" name="cpath" value="<?php echo $cpath;?>" /><?php }?>
	<input type="hidden" name="task" value="" />
	<input type="hidden" name="boxchecked" value="0" />
	</form> 
<?php 
} 


	function ListReviewsToolbar()
	{
		JToolBarHelper::title('AXXIS Simple Rating (and Reviews) :: Reviews List', 'generic.png');
		JToolBarHelper::deleteList('Are you sure you want to delete the selected reviews?','delete_review_confirm');
	}
	
	function ListreportsToolbar()
	{
		JToolBarHelper::title('AXXIS Simple Rating (and Reviews) :: Reviews Reported', 'generic.png');
		JToolBarHelper::deleteList('Are you sure you want to delete the selected reviews?','delete_review_confirm');
	}
	
}

?>
