<?php
	defined('_JEXEC') or die('Restricted access');
	
	JHTML::_('behavior.tooltip');
	
	JToolBarHelper::title( JText::_( 'Charts Manager' ), 'charts.png' );
	JToolBarHelper::deleteListX(JText::_('Are you sure to delete selected charts?'));
	JToolBarHelper::editListX();    
	JToolBarHelper::addNewX('create');
	JToolBarHelper::preferences(ARTIOFUSIONCHARTS_OPTION,600);
	
	if(($isPlugin = JRequest::getInt('plugin')) == 1){
		$eName = JRequest::getVar('e_name');
		$eName = preg_replace( '#[^A-Z0-9\-\_\[\]]#i', '', $eName );
		ARTIOFusionChartsHelper::importChartJS();
	}
	
	//require_once (JPATH_COMPONENT_ADMINISTRATOR . '/views/spalashscreen/index.php');
?>
<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 $this->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.getElementById('filter_categories').value='0';this.form.getElementById('filter_types').value=0;this.form.submit();"><?php echo JText::_( 'Reset' ); ?></button>
			</td>
			<td nowrap="nowrap">
				<?php
					echo $this->lists['filter_categories'];
					echo $this->lists['filter_types'];
				?>
			</td>
		</tr>
	</table>
	<div id="editcell">
		<table class="adminlist">
			<thead>
				<tr>
					<th width="3%">
						<?php echo JText::_( 'NUM' ); ?>
					</th>
					<th width="2%">
						<input type="checkbox" name="toggle" value="" onclick="checkAll(<?php echo count( $this->items ); ?>);" />
					</th>
					<th class="title">
						<?php echo JHTML::_('grid.sort',  'Title', 'title', $this->lists['order_Dir'], $this->lists['order'] ); ?>
					</th>
					<th class="title">
						<?php echo JHTML::_('grid.sort',  'Category', 'category', $this->lists['order_Dir'], $this->lists['order'] ); ?>
					</th>
					<th class="title">
						<?php echo JHTML::_('grid.sort',  'Type', 'type', $this->lists['order_Dir'], $this->lists['order'] ); ?>
					</th>
					<th class="title">
						<?php echo JHTML::_('grid.sort',  'Create', 'created', $this->lists['order_Dir'], $this->lists['order'] ); ?>
					</th>
					<th class="title">
						<?php echo JHTML::_('grid.sort',  'Created by', 'created_by', $this->lists['order_Dir'], $this->lists['order'] ); ?>
					</th>
					<th class="title">
						<?php echo JHTML::_('grid.sort',  'Modified', 'modified', $this->lists['order_Dir'], $this->lists['order'] ); ?>
					</th>
					<th class="title">
						<?php echo JHTML::_('grid.sort',  'Modified by', 'modified_by', $this->lists['order_Dir'], $this->lists['order'] ); ?>
					</th>
					<th width="5%" nowrap="nowrap">
						<?php echo JHTML::_('grid.sort',  'ID', 'id', $this->lists['order_Dir'], $this->lists['order'] ); ?>
					</th>
				</tr>
			</thead>
			<tfoot>
				<tr>
					<td colspan="10" align="center">
						<?php echo $this->pagination->getListFooter(); ?>
					</td>
				</tr>
			</tfoot>
			<tbody>
				<?php foreach ($this->items as $i=>$row){ ?>
					<tr class="row<?php echo $i%2; ?>">
						<td>
							<?php echo $row->offset; ?>
						</td>
						<td>
							<?php echo $row->checked; ?>
						</td>
						<td>
							<?php
								if($isPlugin){
							?>		
								<a href="javascript:Chart.insertChart('<?php echo $row->id;?>','<?php echo $row->title;?>','<?php echo $eName; ?>')" title="<?php echo JText::_('Click To Insert Chart Into Article'); ?>"/><?php echo $row->title; ?></a>							
							<?php
								} elseif (  $row->isChecked ) {
									echo $row->title;
								} else {
							?>
									<span class="editlinktip hasTip" title="<?php echo JText::_( 'Edit Chart' );?>::<?php echo $row->title; ?>">
										<a href="<?php echo $row->link; ?>">
											<?php echo $row->title; ?>
										</a>
									</span>
							<?php } ?>
						</td>
						<td align="center">
							<?php echo $row->category; ?>
						</td>
						<td align="center">
							<?php echo $row->type; ?>
						</td>
						<td align="center">
						    <?php echo JHTML::_('date',  $row->created, JText::_('DATE_FORMAT_LC4') ); ?>
						</td>
						<td align="center">
							<?php if (is_object($row->created_by)) { ?>
								<a href="<?php echo $row->created_by->link; ?>" title="" target="_blank"><?php echo $row->created_by->name; ?></a>
							<?php } else { echo '-'; }?>
						</td>
						<td align="center">
							<?php if($row->modified){?>
							<?php echo JHTML::_('date',  $row->modified, JText::_('DATE_FORMAT_LC4') ); ?>
							<?php } else { ?>
							<?php echo '-'; ?>
							<?php } ?>
						</td>
						<td align="center">
							<?php if (is_object($row->modified_by)) { ?>
								<a href="<?php echo $row->modified_by->link; ?>" title="" target="_blank"><?php echo $row->modified_by->name; ?></a>
							<?php } else { echo '-'; }?>
						</td>
						<td align="center">
							<?php echo number_format($row->id,0,'',' '); ?>
						</td>
					</tr>
				<?php } ?>
			</tbody>
		</table>
	</div>
	<input type="hidden" name="option" value="<?php echo ARTIOFUSIONCHARTS_OPTION; ?>" />
	<input type="hidden" name="task" value="" />
	<?php if($isPlugin) { ?>
		<input type="hidden" name="plugin" value="1" />
		<input type="hidden" name="tmpl" value="component" />
		<input type="hidden" name="e_name" value="<?php echo $eName; ?>" />
	<?php } ?>
	<input type="hidden" name="boxchecked" value="0" />
	<input type="hidden" name="filter_order" value="<?php echo $this->lists['order']; ?>" />
	<input type="hidden" name="filter_order_Dir" value="<?php echo $this->lists['order_Dir']; ?>" />
	<?php echo JHTML::_( 'form.token' ); ?>
</form>