<?php
/**
 * Pro Perfect Karousel
 *This program 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.
 *
 *This program 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 this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 *@author ProJoom
 *@copyright (C) 2008 - 2012 ProJoom
 *@link http://www.projoom.com/extensions/pro-perfect-karousel.html.html Official website
 **/
defined('_JEXEC') or die('No no nooo, you don`t love me and I know');
class PlaylistsViewCatgs
{
	function setCatgsToolbar()
	{
		JToolBarHelper::title( JText::_( 'Category Manager' ), 'generic.png' );
		JToolBarHelper::deleteList( 'Are you sure?', 'remove' );
		JToolBarHelper::editListX( 'edit' );
		JToolBarHelper::addNewX( 'add' );
	}
	function catgs( &$rows, &$pageNav, &$lists )
	{
		PlaylistsViewCatgs::setCatgsToolbar();
		$user =& JFactory::getUser();
		JHTML::_('behavior.tooltip');
		?>
		<form action="index.php" method="post" name="adminForm">
			<table>
			<tr>
				<td align="left" width="100%">
					<?php echo JText::_( 'Filter' ); ?>:
					<input type="text" name="search" id="search" value="<?php echo $lists['search'];?>" class="text_area" onchange="document.adminForm.submit();" />
					<button onclick="this.form.submit();"><?php echo JText::_( 'Go' ); ?></button>
					<button onclick="document.getElementById('search').value='';this.form.submit();"><?php echo JText::_( 'Reset' ); ?></button>
				</td>
				<td nowrap="nowrap">
				</td>
			</tr>
			</table>
			<table class="adminlist">
			<thead>
			<tr>
				<th width="20">
					<?php echo JText::_( 'Num' ); ?>
				</th>
				<th width="20">
					<input type="checkbox" name="toggle" value="" onclick="checkAll(<?php echo count( $rows ); ?>);" />
				</th>
				<th width="80%" nowrap="nowrap" class="title">
					<?php echo JHTML::_('grid.sort',   'Category Name', 'a.name', @$lists['order_Dir'], @$lists['order'] ); ?>
				</th>
				<th width="10%" align="center" nowrap="nowrap">
					<?php echo JHTML::_('grid.sort',   'Slides in this category', 'bid', @$lists['order_Dir'], @$lists['order'] ); ?>
				</th>
				<th width="10%" align="center" nowrap="nowrap">
					<?php echo JHTML::_('grid.sort',   'ID', 'a.cid', @$lists['order_Dir'], @$lists['order'] ); ?>
				</th>
			</tr>
			</thead>
			<tfoot>
			<tr>
				<td colspan="6">
				<?php echo $pageNav->getListFooter(); ?>
				</td>
			</tr>
			<tr>
				<td colspan="6">
				<center><a href="http://www.projoom.com/" target="_blank" title="Pro Perfect Karousel">Pro Perfect Karousel</a> © ProJoom</center>
				</td>
			</tr>
			</tfoot>
			<tbody>
			<?php
			$k = 0;
			for ($i=0, $n=count( $rows ); $i < $n; $i++) {
				$row = &$rows[$i];
				$row->id		= $row->cid;
				$link			= JRoute::_( 'index.php?option=com_novapc&c=catg&task=edit&cid[]='. $row->id );
				$checked		= JHTML::_('grid.checkedout',   $row, $i );
				?>
				<tr class="<?php echo "row$k"; ?>">
					<td align="center">
						<?php echo $pageNav->getRowOffset( $i ); ?>
					</td>
					<td>
						<?php echo $checked; ?>
					</td>
					<td align="center">
						<?php
						if (  JTable::isCheckedOut($user->get ('id'), $row->checked_out ) ) {
							echo $row->name;
						} else {
							?>
								<span class="editlinktip hasTip" title="<?php echo JText::_( 'Edit' );?>::<?php echo $row->name; ?>">
							<a href="<?php echo $link; ?>">
								<?php echo $row->name; ?></a>
								</span>
							<?php
						}
						?>
					</td>
					<td align="center">
						<?php echo $row->nplaylists;?>
					</td>
					<td align="center">
						<?php echo $row->cid; ?>
					</td>
				</tr>
				<?php
				$k = 1 - $k;
			}
			?>
			</tbody>
			</table>
		<input type="hidden" name="c" value="catg" />
		<input type="hidden" name="option" value="com_novapc" />
		<input type="hidden" name="task" value="" />
		<input type="hidden" name="boxchecked" value="0" />
		<input type="hidden" name="filter_order" value="<?php echo $lists['order']; ?>" />
		<input type="hidden" name="filter_order_Dir" value="<?php echo $lists['order_Dir']; ?>" />
		<?php echo JHTML::_( 'form.token' ); ?>
		</form>
		<?php
	}
	function setCatgToolbar()
	{
		$task = JRequest::getVar( 'task', '', 'method', 'string');
		JToolBarHelper::title( $task == 'add' ? JText::_( 'Playlist Category' ) . ': <small><small>[ '. JText::_( 'New' ) .' ]</small></small>' : JText::_( 'Playlist Category' ) . ': <small><small>[ '. JText::_( 'Edit' ) .' ]</small></small>', 'generic.png' );
		JToolBarHelper::save( 'save' );
		JToolBarHelper::apply('apply');
		JToolBarHelper::cancel( 'cancel' );
	}
	function catg( &$row )
	{
		PlaylistsViewCatgs::setCatgToolbar();
		JRequest::setVar( 'hidemainmenu', 1 );
		JFilterOutput::objectHTMLSafe( $row, ENT_QUOTES, 'extrainfo' );
		?>
		<script language="javascript" type="text/javascript">
		<!--
		function submitbutton(pressbutton)
		{
			var form = document.adminForm;
			if (pressbutton == 'cancel')
			{
				submitform( pressbutton );
				return;
			}
			if (form.name.value == "")
			{
				alert( "<?php echo JText::_( 'Please fill in the Category Name.', true ); ?>" );
			}
			else
			{
				submitform( pressbutton );
			}
		}
		//-->
		</script>
		<form action="index.php" method="post" name="adminForm">
		<div class="col width-20">
			<fieldset class="adminform">
				<legend><?php echo JText::_( 'Details' ); ?></legend>
				<table class="admintable">
					<tbody>
					<tr>
						<td width="10%" nowrap="nowrap">
							<label for="name">
								<?php echo JText::_( 'Category Name' ); ?>:
							</label>
						</td>
						<td>
							<input class="inputbox" type="text" name="name" id="name" size="40" maxlength="60" value="<?php echo $row->name; ?>" />
						</td>
					</tr>
					</table>
			</fieldset>
		</div>
		<div class="col width-80">
			<fieldset class="adminform">
				<legend><?php echo JText::_( 'Notes' ); ?></legend>
				<tr>
					<td width="80%" valign="top">
						<?php
					$editor =& JFactory::getEditor();
					echo $editor->display('extrainfo', $row->extrainfo, '550', '300', '60', '20', false);
					?>
					</td>
				</tr>
					</tbody>
				</table>
			</fieldset>
		</div>
		<div class="clr"></div>
		<input type="hidden" name="c" value="catg" />
		<input type="hidden" name="option" value="com_novapc" />
		<input type="hidden" name="cid" value="<?php echo $row->cid; ?>" />
		<input type="hidden" name="catg_id" value="<?php echo $row->cid; ?>" />
		<input type="hidden" name="task" value="" />
		<?php echo JHTML::_( 'form.token' ); ?>
		</form>
		<?php
	}
}
