<?php
/**
 * Content Templater Item View Template
 *
 * @package     Content Templater
 * @version     1.5.4
 *
 * @author      Peter van Westen <peter@nonumber.nl>
 * @link        http://www.nonumber.nl
 * @copyright   Copyright (C) 2010 NoNumber! All Rights Reserved
 * @license     http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL
 */

// No direct access
defined( '_JEXEC' ) or die( 'Restricted access' );

// Import modal
JHTML::_( 'behavior.modal' );
// Import html tooltips
JHTML::_( 'behavior.tooltip' );

jimport( 'joomla.html.pane' );
$pane =& JPane::getInstance( 'sliders', array( 'allowAllClose' => true, 'startOffset' => 0, 'startTransition' => true ) );

JPlugin::loadLanguage( 'com_content' );

$has_k2 = JFile::exists( JPATH_ADMINISTRATOR.DS.'components'.DS.'com_k2'.DS.'admin.k2.php' );
$has_mr = JFile::exists( JPATH_ADMINISTRATOR.DS.'components'.DS.'com_resource'.DS.'resource.php' );

$view_state = $this->detail->view_state;
if ( $view_state == -1 ) {
	$config =& JComponentHelper::getParams( 'com_contenttemplater' );
	$view_state = $config->get( 'view_state', 1 );
}

$document =& JFactory::getDocument();
$document->addScript( JURI::root( true ).'/plugins/system/nonumberelements/js/script.js' );
?>

<form action="<?php echo JRoute::_( $this->request_url ) ?>" method="post" name="adminForm" id="adminForm">
<input type="hidden" name="has_k2" value="<?php echo $has_k2; ?>" />
<input type="hidden" name="has_mr" value="<?php echo $has_mr; ?>" />

<div style="display:none;">
	<?php echo str_replace( 'value="'.$view_state.'"', 'value="'.$view_state.'" checked="checked"', str_replace( 'checked="checked"', '', $this->detail->_xml->render( 'params', 'view_state' ) ) ); ?>
</div>

<div class="view_state_<?php echo $view_state; ?>" id="view_state_div">
	<div class="button1 button_view_state"><div class="simple"><a onclick="NoNumberElementsChangeView( 0 );" class="hasTip" title="<?php echo JText::_( 'Simple' ).'::'.JText::_( 'Simple (description)' ); ?>"><?php echo JText::_( 'Simple' ); ?></a></div></div>
	<div class="button1 button_view_state"><div class="normal"><a onclick="NoNumberElementsChangeView( 1 );" class="hasTip" title="<?php echo JText::_( 'Normal' ).'::'.JText::_( 'Normal (description)' ); ?>"><?php echo JText::_( 'Normal' ); ?></a></div></div>
	<div class="button1 button_view_state"><div class="advanced"><a onclick="NoNumberElementsChangeView( 2 );" class="hasTip" title="<?php echo  JText::_( 'Advanced' ).'::'.JText::_( 'Advanced (description)' ); ?>"><?php echo JText::_( 'Advanced' ); ?></a></div></div>
</div>

<div class="clr"></div>

<p><?php echo JText::_( 'Item information' ); ?></p>

<div class="clr"></div>

<table width="100%">
	<tr>
		<td valign="top">
			<div class="col" style="width:100%;">
				<fieldset class="adminform">
					<legend><?php echo JText::_( 'Details' ); ?></legend>
					<?php echo $this->detail->_xml->render(); ?>
				</fieldset>

				<fieldset class="adminform">
					<legend><?php echo JText::_( 'Content' ); ?></legend>
					<?php echo $this->detail->_xml->render( 'params', '-editor' ); ?>
				</fieldset>
			</div><div class="clr"></div>
		</td>
		<td valign="top">
			<div class="col">
				<div id="<?php echo rand( 1000000, 9999999 ); ?>___view_state.1___view_state.2" class="nntoggler nntoggler_horizontal nntoggler_overlay" style="visibility: hidden;">
				<div id="<?php echo rand( 1000000, 9999999 ); ?>___view_state.1___view_state.2" class="nntoggler nntoggler_nofx" style="visibility: hidden;">
					<div style="width:500px;">
						<fieldset class="adminform">
							<legend><?php echo JText::_( 'Publishing Settings' ); ?></legend>
							<div id="nn_param_preloader_container">
								<center><img src="<?php echo JURI::root( true ); ?>/plugins/system/nonumberelements/images/loading.gif" align="middle" alt="" /></center>
							</div>
						</fieldset>

						<fieldset class="adminform">
							<legend><?php echo JText::_( 'Content Settings' ); ?></legend>
							<?php echo $this->detail->_xml->render( 'params', 'override' ); ?>
							<?php
								echo $pane->startPane( "content-pane" );

									$title = JText::_( 'Main Settings' );
									echo $pane->startPanel( $title, "detail-page" );
									echo $this->detail->_xml->render( 'params', '-settings' );
									echo $pane->endPanel();

									echo '<div id="'.rand( 1000000, 9999999 ).'___view_state.2" class="nntoggler" style="visibility: hidden;">';

										$title = JText::_( 'Parameters - Article' );
										echo $pane->startPanel( $title, "detail-page" );
										echo $this->detail->_xml->render( 'params', '-details' );
										echo $pane->endPanel();

										$title = JText::_( 'Parameters - Advanced' );
										echo $pane->startPanel( $title, "params-page" );
										echo $this->detail->_xml->render( 'params', '-advanced' );
										echo $pane->endPanel();

										$title = JText::_( 'Metadata Information' );
										echo $pane->startPanel( $title, "metadata-page" );
										echo $this->detail->_xml->render( 'params', '-metadata' );
										echo $pane->endPanel();

										$title = JText::_( 'Custom Fields' );
										echo $pane->startPanel( $title, "customfields-page" );
										echo $this->detail->_xml->render( 'params', '-customfields' );
										echo $pane->endPanel();

									echo '</div>';

								echo $pane->endPane();
							?>
						</fieldset>
					</div>
				</div></div>
			</div>
			<div class="clr"></div>
		</td>
	</tr>
</table>

<div class="clr"></div>

<input type="hidden" name="cid[]" value="<?php echo $this->detail->id; ?>" />
<input type="hidden" name="task" value="" />
<input type="hidden" name="controller" value="item" />


<div id="nn_param_preloader" style="visibility: hidden;">
	<div class="col">
	<?php
		echo $pane->startPane( 'contenttemplater_pane' );
			echo '<fieldset class="adminform">';
			echo '<legend>'.JText::_( 'Editor Button List' ).'</legend>';
				echo $this->detail->_xml->render( 'params', 'editorbutton' );
				echo '<div id="'.rand( 1000000, 9999999 ).'___view_state.2___button_enabled.1___button_enabled.2___button_use_assignments.1" class="nntoggler nntoggler_and" style="visibility: hidden;">';
					echo $pane->startPanel( JText::_( '-Publishing Assignments' ), 'editorbutton-page' );
						echo $this->detail->_xml->render( 'params', 'editorbutton_assignments' );
					echo $pane->endPanel();
				echo '</div>';
			echo '</fieldset>';

			echo '<fieldset class="adminform">';
			echo '<legend>'.JText::_( 'Load by Default' ).'</legend>';
				echo $this->detail->_xml->render( 'params', 'load' );
				echo '<div id="'.rand( 1000000, 9999999 ).'___view_state.2___load_enabled.1___load_use_assignments.1" class="nntoggler nntoggler_and" style="visibility: hidden;">';
					echo $pane->startPanel( JText::_( '-Publishing Assignments' ), 'default-page' );
						echo $this->detail->_xml->render( 'params', 'load_assignments' );
					echo $pane->endPanel();
				echo '</div>';
			echo '</fieldset>';

			echo '<div id="'.rand( 1000000, 9999999 ).'___view_state.2" class="nntoggler" style="visibility: hidden;">';
			echo '<fieldset class="adminform">';
			echo '<legend>'.JText::_( 'Load by URL' ).'</legend>';
				echo $this->detail->_xml->render( 'params', 'url' );
				echo '<div id="'.rand( 1000000, 9999999 ).'___url_enabled.1___url_use_assignments.1" class="nntoggler nntoggler_and" style="visibility: hidden;">';
					echo $pane->startPanel( JText::_( '-Publishing Assignments' ), 'url-page' );
						echo $this->detail->_xml->render( 'params', 'url_assignments' );
					echo $pane->endPanel();
				echo '</div>';
			echo '</fieldset>';
			echo '</div>';
		echo $pane->endPane();
	?>
	</div>
</div>
</form>

<script language="javascript" type="text/javascript">
	function submitbutton( pressbutton )
	{
		var form = document.adminForm;
		if ( pressbutton == 'cancel' ) {
			submitform( pressbutton );
			return;
		}

		// do field validation
		if ( form['params[name]'].value == "" ) {
			alert( "<?php echo JText::_( 'The item must have a name', true ); ?>" );
		} else {
			submitform( pressbutton );
		}
	}
</script>