<?PHP

$title = $this->title;
$title->elem('a', $this->Language('Content list'))->href('?model=content&page=content_list');

$row = $this->menus->Rows[0];
$menu_image = $row['image'];
$menu_name = $row['name'];

$title->create($row['name']);


?>

<div id="tabs">
<ul>
	<li><a href="#tabs-1"><?=$this->Language('Sisu leht');?></a></li>
	<li><a href="#tabs-2"><?=$this->Language('Sisu detailid');?></a></li>
	<li><a href="#tabs-3"><?=$this->Language('Sisu pildid');?></a></li>
	<li><a href="#tabs-4"><?=$this->Language('Sisu failid');?></a></li>
</ul>

<form method="POST" enctype="multipart/form-data">
<input type="hidden" name="form_type" value="advanced">
<input type="hidden" name="prev_model_id" value="<?=$row['model_id'];?>">
<input type="hidden" name="related_id" value="<?=$_GET['id'];?>">
<input type="hidden" name="table_name" value="templates">
<input type="hidden" name="file_type" value="IMAGE">

<div id="tabs-1">

<?

while($row2 = $this->language_menus->Assoc()){

	$selected = $_GET['get_language'] == $row2['key'] ? 'background:lightgrey;' : '';
	$selected = !$_GET['get_language'] && $_SESSION['language'] == $row2['key'] ? 'background:lightgrey;' : $selected;

	echo '<a href="'.$this->appendLink('?get_language='.$row2['key']).'" style="padding-right:15px;'.$selected.'">'.$row2['language'].'</a>';
}
echo '<br/><br/>';

?>

	<table class="header" style="float:left;">
	<tbody>
	<tr>
		<th><?=$this->Language('Name');?></th>
		<td><input type="text" value="<?=$row['name'];?>" name="name"></td>
	</tr>
	<tr>
		<th><?=$this->Language('Title');?></th>
		<td><input type="text" value="<?=$row['title'];?>" name="title"></td>
	</tr>
	<tr>
		<th><?=$this->Language('Link');?></th>
		<td><a href="<?=_RootUrl.'/'.$row['redirect_url'];?>" target="blank"><?=$row['name'];?></a></td>
	</tr>
	<tr>
	<th><?=$this->Language('Parent menu');?></th>
	<td><select name="parent_id" style="max-width:270px;">
		<option value=""><?=$this->Language('select');?></option>
		<?
		while($row2 = $this->parent_menus->Assoc()){

			echo '<option value="'.$row2['id'].'" '.($row2['id'] == $row['parent_id'] ? 'selected="selected"' : '').'>'.$row2['name'].'</option>';
		}
		?>
		</select></td>
	</tr>
	<tr>
	<th><?=$this->Language('Menu Position');?></th><td><select name="position">
		<?
		$optgroup_start = false;
		$optgroup_end = false;
		foreach($this->position->get_position() as $row2){

			if(preg_match('/public/i', $row2['position'])){

				if($row2['position'] && !$row2['name'] && $optgroup_start == true){

					$optgroup_end = true;
				}

				if($row2['position'] && !$row2['name']){

					$optgroup_start = true;
					$optgroup_end = false;
				}

				if($optgroup_start == true){

					echo '<optgroup label="'.$row2['position'].'">';
					$optgroup_start = false;
				}
				if($optgroup_end == true){

					echo '</optgroup>';
				}

				if($row2['name']){

					echo '<option value="'.$row2['value'].'" '.($row2['value'] == $row['menu_position'] ? 'selected="selected"' : '').'>'.$row2['name'].'</option>';
				}
			}
		}
		?>
		</select>
		<a href="#name=position" class="view_positions"><?=$this->Language('View positions');?></a></td>
	</tr>
	<tr>
	<th><?=$this->Language('Content Position');?></th><td><select name="content_position">
		<?
		$optgroup_start = false;
		$optgroup_end = false;
		foreach($this->position->get_position() as $row2){

			if(preg_match('/public/i', $row2['position'])){

				if($row2['position'] && !$row2['name'] && $optgroup_start == true){

					$optgroup_end = true;
				}

				if($row2['position'] && !$row2['name']){

					$optgroup_start = true;
					$optgroup_end = false;
				}

				if($optgroup_start == true){

					echo '<optgroup label="'.$row2['position'].'">';
					$optgroup_start = false;
				}
				if($optgroup_end == true){

					echo '</optgroup>';
				}

				if($row2['name']){

					echo '<option value="'.$row2['value'].'" '.($row2['value'] == $row['content_position'] ? 'selected="selected"' : '').'>'.$row2['name'].'</option>';
				}
			}
		}
		?>
		</select>
		<a href="#name=content_position" class="view_positions"><?=$this->Language('View positions');?></a></td>
	</tr>
	<tr>
	<th><?=$this->Language('Is first page');?></th><td><input type="checkbox" <?=($row['is_first_page'] == 1 ? 'checked="ckecked"' : '');?> <?=($row['model_id'] > 0 ? 'disabled="disabled"' : '');?> value="1" name="is_first_page"></td>
	</tr>
	<tr>
	<th><?=$this->Language('Content is static');?></th><td><input type="checkbox" <?=($row['is_static'] == 1 ? 'checked="ckecked"' : '');?> value="1" name="is_static"></td>
	</tr>
	<tr>
	<th><?=$this->Language('Is menu active');?></th><td><input type="checkbox" <?=($row['is_enabled'] == 1 ? 'checked="ckecked"' : '');?> value="1" name="is_enabled" class="is_enabled"></td>
	</tr>
	<tr>
	<th><?=$this->Language('Is content active');?></th><td><input type="checkbox" <?=($row['is_active'] == 1 ? 'checked="ckecked"' : '');?> value="1" name="is_active" class="is_enabled"></td>
	</tr>
	<tr>
	<th></th><td><input type="submit" value="<?=$this->Language('Update');?>" name="update"> <input type="submit" value="<?=$this->Language('Update and out');?>" name="update_and_out"></td>
	</tr>
	</tbody></table>

	<table style="float:left;margin-left:10px;margin-top:-3px;">
	<tbody><tr>
	<td>
	<?PHP
	if($row['type'] == 'PAGE'){

		echo "<script>
		$('#content___Frame').css({'display' : 'block'});
		</script>";

		if($_SESSION['UserData']['type'] == 'SUPERADMIN'){

			echo '<a href="" id="content_source_link">'.$this->Language('Full source').'</a><br/><br>';
			echo '<div class="content_source">';
			echo '<input type="checkbox" name="clear_source" value="1"> '.$this->Language('Clear source').'<br/>';
			echo '<textarea name="content_source" style="width:745px;height:425px;">'.htmlspecialchars($row['content_source']).'</textarea>';
			echo '</div>';
		}

		if(!$row['content_source']){

			echo $this->Editor->ckeditor(750, 425, 'content', $row['content']);
		}
		if($row['content_source']){

			echo $this->Editor->ckeditor_source(750, 425, 'content_source_result', $row['content_source']);
		}
	}
	else{

		echo "<script>
		$('#content___Frame').css({'display' : 'none'});
		</script>";
	}
	?>
	</td>
	</tr>
	</tbody></table>
</div>

<div id="tabs-2">

	<table class="header" style="float:left;">
	<tbody>
	<tr>
	<th><?=$this->Language('Url');?> <span style="font-size:10px;"><?=$this->Language('(if not default)');?></span></th><td><input type="text" value="<?=($row['url'] ? $row['url'] : 'http://');?>" name="url"></td>
	</tr>
	<tr>
	<th><?=$this->Language('Meta description');?></th><td><textarea name="meta_description" style="width:400px;"><?=$row['meta_description'];?></textarea></td>
	</tr>
	<tr>
	<th><?=$this->Language('Meta keywords');?></th><td><textarea name="meta_keywords" style="width:400px;"><?=$row['meta_keywords'];?></textarea></td>
	</tr>
	<!--<tr>
	<th><?=$this->Language('Template');?></th><td><select name="template">
		<option value=""></option>
		<?
		foreach($this->File->Files as $row2){

			$file_name = str_replace('.php', '', $row2['file']);
			echo '<option value="'.$file_name.'" '.($file_name == $row['template'] ? 'selected="selected"' : '').'>'.$file_name.'</option>';
		}
		?>
		</select></td>
	</tr>-->
	<tr>
	<th><?=$this->Language('Permissions');?></th><td><select multiple="multiple" name="permissions[]">
				<?
				foreach($this->roles->Rows as $row2){
				?>
				<option value="<?=$row2['value'];?>" <?=(in_array($row2['value'], $this->perm) ? 'selected="selected"' : '')?>"><?=$row2['name'];?></option>
				<?
				}
				?>
				</select></td>
	</tr>
	<?
	if($this->models->Numrows > 0){
	?>
	<tr>
	<th><?=$this->Language('Model');?></th><td><select name="model_id">
		<option value=""></option>
		<?
		foreach($this->models->Rows as $row2){
		?>
		<option value="<?=$row2['value'];?>" <?=($row2['value'] == $row['model_id'] ? 'selected="selected"' : '')?>><?=$row2['name'];?></option>
		<?
		}
		?>
		</select></td>
	</tr>
	<?
	}
	if(!empty($this->plugins)){
	?>
	<tr>
	<th><?=$this->Language('Plugins');?></th><td><select name="plugin_id">
		<option value=""></option>
		<?
		foreach($this->plugins as $row2){
		?>
		<option value="<?=$row2;?>"><?=$row2;?></option>
		<?
		}
		?>
		</select>
		<input type="text" name="plugin_code" style="width:250px;"/>
		</td>
	</tr>
	<?
	}
	?>
	<tr>
	<th><?=$this->Language('To next menu');?></th><td><input type="checkbox" <?=($row['to_next_menu'] == 1 ? 'checked="ckecked"' : '');?> value="1" name="to_next_menu"></td>
	</tr>
	<tr>
	<th><?=$this->Language('Name key');?></th><td><input type="text" value="<?=$row['name_key'];?>" name="name_key"></td>
	</tr>
	<!--<tr>
	<th><?=$this->Language('show sub as listing');?></th><td><input type="checkbox" <?=($row['show_sub_as_listing'] == 1 ? 'checked="ckecked"' : '');?> value="1" name="show_sub_as_listing"></td>
	</tr>
	<tr>
	<th><?=$this->Language('is big');?></th><td><input type="checkbox" <?=($row['is_big'] == 1 ? 'checked="ckecked"' : '');?> value="1" name="is_big"></td>
	</tr>
	<tr>
	<th><?=$this->Language('Is link');?></th><td><input type="checkbox" <?=($row['is_link'] == 1 ? 'checked="ckecked"' : '');?> value="1" name="is_link"></td>
	</tr>-->
	<tr>
	<th></th><td><input type="submit" value="<?=$this->Language('Update');?>" name="update_details"></td>
	</tr>
	</tbody></table>

</div>

<div id="tabs-3">

	<table class="content">
	<tr>
		<td><input type="file" name="image"/><!-- <?=$this->Language('OR IMAGE URL');?> <input type="text" name="image_url" value="" style="width:320px;"/>-->
		<!--<br/><br/>
		<input type="text" name="description" value="" style="width:500px;"/> <?=$this->Language('Description');?>-->
		</td>
		<!--<td><input type="checkbox" name="is_main" value="1"/></td>
		<td><input type="checkbox" name="is_visible" value="1" checked="checked"/></td>
		<td><input type="checkbox" name="is_menu_image" value="1"/></td>-->
		<td><input type="submit" name="insert_image" value="<?=$this->Language('Add image');?>"/></td>
	</tr>
	<tr>
		<th><?=$this->Language('Image');?></th>
		<!--<th><?=$this->Language('Is main');?></th>
		<th><?=$this->Language('Is visible in gallery');?></th>
		<th><?=$this->Language('Is menu image');?></th>-->
		<th></th>
	</tr>

	<?
	while($row = $this->files->Assoc()){

		if($row['file_type'] == 'IMAGE'){
		?>
		<tr>
			<td>
				<input type="hidden" name="current_file_name[<?=$row['id']?>]" value="<?=$row['file_name'];?>"/>
				<a href="<?='/files/page/'.$row['file_name'];?>" class="_blank"><img src="<?='/files/page/'.$row['file_name'];?>" style="max-width:150px;max-height:150px;" alt="<?=$menu_name;?>"/></a><br/><br/>
				<input type="text" name="copylink" value="<?='/files/page/'.$row['file_name'];?>" style="width:600px;background:#ff9b9b;"/> <?=$this->Language('URL');?><br/><br/>
				<input type="file" name="file_upload[<?=$row['id']?>]"/> <!--<?=$this->Language('OR IMAGE URL');?> <input type="text" name="file_upload_url[<?=$row['id']?>]" value="" style="width:320px;"/><br/><br/>
				<input type="text" name="description[<?=$row['id']?>]" value="<?=$row['description'];?>" style="width:500px;"/> <?=$this->Language('Description');?>-->
			</td>
			<!--<td><input type="checkbox" name="is_main_update[<?=$row['id']?>]" value="1" <?=($row['is_main'] == 1 ? 'checked="checked"' : '')?>/></td>
			<td><input type="checkbox" name="is_visible_update[<?=$row['id']?>]" value="1" <?=($row['is_visible'] == 1 ? 'checked="checked"' : '')?>/></td>
			<td><input type="checkbox" name="is_menu_image[<?=$row['id']?>]" value="1" <?=($row['file_name'] == $menu_image ? 'checked="checked"' : '')?>/></td>-->
			<td><input type="submit" name="update_image" value="<?=$this->Language('Update image');?>"/> <a href="<?=$this->appendLink('?action=delete_file&file_type=image&file_id='.$row['id']);?>" class="delete"><?=$this->Language('Delete');?></a></td>
		</tr>
		<?
		}
	}
	?>

	</table>
</div>



<div id="tabs-4">

	<table class="content">
	<tr>
		<td><input type="file" name="file"/> <?=$this->Language('OR FILE URL');?> <input type="text" name="file_url" value="" style="width:320px;"/></td>
		<td><input type="checkbox" name="is_main" value="1"/></td>
		<td><input type="submit" name="insert_file" value="<?=$this->Language('Add file');?>"/></td>
	</tr>
	<tr>
		<th><?=$this->Language('file');?></th>
		<th><?=$this->Language('Is main');?></th>
		<th></th>
	</tr>

	<?
	while($row = $this->files->Assoc()){

		if($row['file_type'] == 'FILE'){
		?>
		<tr>
			<td>
				<a href="<?='/files/page/'.$row['file_name'];?>" class="_blank"><?=$row['file_name'];?></a><br/><br/>
				<input type="text" name="copylink" value="<?='/files/page/'.$row['file_name'];?>" style="width:600px;background:#ff9b9b;"/><br/><br/>
				<input type="file" name="file_upload[<?=$row['id']?>]"/> <?=$this->Language('OR IMAGE URL');?> <input type="text" name="file_upload_url[<?=$row['id']?>]" value="" style="width:320px;"/>
			</td>
			<td><input type="hidden" name="is_visible_update[<?=$row['id']?>]" value="1" checked="checked"/><input type="checkbox" name="is_main_update[<?=$row['id']?>]" value="1" <?=($row['is_main'] == 1 ? 'checked="checked"' : '')?>/></td>
			<td><input type="submit" name="update_file" value="<?=$this->Language('Update file');?>"/> <a href="<?=$this->appendLink('?action=delete_file&file_type=file&file_id='.$row['id']);?>" class="delete"><?=$this->Language('Delete');?></a></td>
		</tr>
		<?
		}
	}
	?>
	</table>
</div>

</form>

<div style="clear:both;"></div>

</div>


<?
if($_POST['update'] || $_POST['update_and_out']){

	echo '<script type="text/javascript">select_level = 0;</script>';
}
if($_POST['update_details']){

	echo '<script type="text/javascript">select_level = 1;</script>';
}
if($_POST['insert_image'] || $_POST['update_image'] || $_GET['file_type'] == 'image'){

	echo '<script type="text/javascript">select_level = 2;</script>';
}
if($_POST['insert_file'] || $_POST['update_file'] || $_GET['file_type'] == 'file'){

	echo '<script type="text/javascript">select_level = 3;</script>';
}
?>