<?php
defined('_JEXEC') or die('Restricted access');
jimport ( 'joomla.html.pane' );
JHTML::_('behavior.tooltip');
JHTML::_('behavior.modal');
JHTML::_('behavior.mootools');
ARTIOFusionChartsHelper::importJoomlaToolsJS();
ARTIOFusionChartsHelper::importFusionJS();
ARTIOFusionChartsHelper::importChartJS();
ARTIOFusionChartsHelper::importLang();
ARTIOFusionChartsHelper::importColorPicker();
ARTIOFusionChartsHelper::importColorsToJS();
$pane = &JPane::getInstance ( 'sliders', array ('allowAllClose' => true ) );
$edit = JRequest::getVar('edit',true);
$text = !$edit ? JText::_( 'New' ) : JText::_( 'Edit' );
JToolBarHelper::title(   JText::_( 'Chart' ).': <small><small>[ ' . $text.' ]</small></small>', 'charts.png' );
JToolBarHelper::save();
JToolBarHelper::apply();
JToolBarHelper::cancel( 'cancel', 'Close' );
JToolBarHelper::addNewX('create');
if($this->chart->id){
    JToolBarHelper::deleteListX(JText::_('Are you sure to delete this chart?'));
}
?>
<form action="index.php" method="post" name="adminForm" id="adminForm">
	<table cellspacing="0" cellpadding="0" border="0">
		<tr>
			<td valign="top" colspan="2">
				<?php require_once (dirname(__FILE__).DS.'main.php'); ?>
			</td>
		</tr>
		<tr>
			<td valign="top" colspan="2">
			<?php 
			    if($this->chart->chartType == 1){ //single series 
    				require_once (dirname(__FILE__).DS.'sets.php');
    			}	    		
			    if($this->chart->chartType == 2){ //multi
					require_once (dirname(__FILE__).DS.'datasets.php');
			    }
			    //single series treadlines 
			    if($this->chart->chartSetting['useTrendLines']){
			        require_once (dirname(__FILE__).DS.'lines.php');
			    }
			?>
		</td>
	</tr>
		<tr>
			<td valign="top" style="width: 75%;">
    			<fieldset class="adminform" style="text-align: center;">
    				<legend><?php echo JText::_('Chart Preview'); ?></legend>
    					<div style="margin: 20px; text-align: center;">
    						<?php $function = ( $this->chart->chartType == 1 ) ? 'renderSingle()' : 'renderMulti()'; ?>
    						<button onclick="Chart.<?php echo $function; ?>;return false;"><?php echo JText::_('Render Chart'); ?></button>
    					</div>
    					<div style="text-align: center; width: 900px; overflow: auto">
    						<div id="chartdiv"></div>
    						<script type="text/javascript">
    							//<![CDATA[ 
    						    var chartObj = null;
    							window.addEvent('load', function() {
    								chartObj = new ARTIOFusionCharts("<?php echo $this->chart->chart; ?>", "ChartId", "<?php echo $this->chart->width; ?>", "<?php echo $this->chart->height; ?>", "0", "0");
    								var xml = "<?php echo $this->chart->xml; ?>";
    								chartObj.setDataXML(xml);		   
    								chartObj.render("chartdiv");
    							});
    							//]]>
    						</script>
    					</div>
    			</fieldset> 
			</td>
			<td valign="top" style="width: 25%">
				<fieldset class="adminform">
    				<legend><?php echo JText::_('Chart Parameters'); ?></legend>
    				<?php
    					echo $pane->startPane ( "content-pane" );
    					echo $pane->startPanel ( JText::_ ( 'Sizes' ), "sizes-page" );
    				?>
    					<table width="100%" class="paramlist admintable" cellspacing="1">
    						<tr>
    							<td width="40%" class="paramlist_key">
    								<span class="editlinktip">
    									<label id="width-lbl" for="width"><?php echo JText::_('Width'); ?></label>
    								</span>
    							</td>
    							<td class="paramlist_value">
    								<input type="text" name="width" id="width" value="<?php echo $this->chart->width; ?>" class="text_area" size="20" />
    							</td>
    						</tr>
    						<tr>
    							<td width="40%" class="paramlist_key">
    								<span class="editlinktip">
    									<label id="height-lbl" for="height"><?php echo JText::_('Height'); ?></label>
    								</span>
    							</td>
    							<td class="paramlist_value">
    								<input type="text" name="height" id="height" value="<?php echo $this->chart->height; ?>" class="text_area" size="20" />
    							</td>
    						</tr>
    					</table>
    				<?php
    					echo $pane->endPanel ();
    					$groups = $this->chart->form->getGroups();
    					foreach ($groups as $name=>$count){
    						echo $pane->startPanel ( JText::_ ( $name ), JFilterOutput::stringURLSafe($name) );
    						echo $this->chart->form->render ( 'params', $name );
    						echo $pane->endPanel ();
    					}
    					echo $pane->endPane ();
    				?>
				</fieldset>
			</td>
		</tr>
	</table>
	<input type="hidden" name="option" value="<?php echo ARTIOFUSIONCHARTS_OPTION; ?>" />
	<input type="hidden" name="cid[]" value="<?php echo $this->chart->id; ?>"/>
	<input type="hidden" id="selectedCategory" name="selectedCategory" value="<?php echo $this->chart->category; ?>"/>
	<input type="hidden" name="task" value="" />
	<input type="hidden" name="view" value="chart" />
	<input type="hidden" name="boxchecked" value="1" />
	
	<?php if($this->chart->chartType == 2){ //multi ?>
		<input type="hidden" name="lastCategoryID" id="lastCategoryID" value="<?php echo count($this->chart->categories); ?>" />
		<input type="hidden" name="lastDatasetID" id="lastDatasetID" value="<?php echo count($this->chart->datasets); ?>" />
	<?php } ?>
	<?php echo JHTML::_( 'form.token' ); ?>
</form>