<?php
 if(isset($_GET['delete'])){ 
    $db->query("DELETE from ".DB_PREFIX."homepage WHERE id = '".intval($_GET['delete'])."'");
	echo '<div class="msg-info">You deleted the home box with id : '.$_GET['delete'].'</div>';
	 }
if(isset($_POST['queries'])){ 
$insertvideo = $db->query("
Update ".DB_PREFIX."homepage SET title = '".toDb($_POST['title'])."', ident = '".toDb($_POST['ident'])."',
querystring = '".toDb($_POST['queries'])."', total = '".toDb($_POST['number'])."', mtype = '".toDb($_POST['type'])."' where id = '".intval($_GET['id'])."'");
}


echo '<div class="row-fluid">';


$box = $db->get_row("SELECT * FROM ".DB_PREFIX."homepage where id ='".intval($_GET['id'])."' order by `ord` ASC limit 0,1");
if($box) {
?>

<div class="box-element span6">
					<div class="box-head-light"><i class="icon-pencil"></i><h3>Editing '<?php echo _html($box->title); ?>'</h3></div>
					<div class="box-content">
<form id="validate" class="form-horizontal styled" action="<?php echo admin_url('edit-block').'&id='.intval($_GET['id']);  ?>" enctype="multipart/form-data" method="post">
		<input type="hidden" name="cid" value="<?php echo intval($_GET['id']); ?>">
	<div class="control-group">
	<label class="control-label">Block title</label>
	<div class="controls">
	<input type="text" id="title" name="title" class="span12" value="<?php echo _html($box->title); ?>">
	</div>
	</div>	
	<div class="control-group">
	<label class="control-label">Videos limit</label>
	<div class="controls">
	<input type="text" id="number" name="number" class="span4 validate[required]" value="<?php echo _html($box->total); ?>">
	<span class="help-block" id="limit-text">Number of videos per block. If you have 1 block, it will be the number of videos to load per scroll.</span>
	</div>
	</div>	
	<div class="control-group">
	<label class="control-label">Video query:</label>
	<div class="controls">
	<select data-placeholder="Select type" name="queries" id="queris" class="select validate[required]" tabindex="2">
	
	<option value="most_viewed" <?php if($box->querystring == "most_viewed") { echo 'checked="checked" selected'; } ?>>Most viewed </option>
<option value="top_rated" <?php if($box->querystring == "top_rated") { echo 'checked="checked" selected'; } ?>>Most liked</option>
<option value="viral" <?php if($box->querystring == "viral") { echo 'checked="checked" selected'; } ?>>Recent</option>
<option value="featured" <?php if($box->querystring == "featured") { echo 'checked="checked" selected'; } ?>>Featured</option>
<option value="random" <?php if($box->querystring == "random") { echo 'checked="checked" selected'; } ?>>Random </option>

	</select>

	</div>
	</div>	
	<div class="control-group">
	<label class="control-label"><i class="icon-sort"></i>Media</label>
	<div class="controls">
	<label class="radio inline"><input type="radio" name="type" class="styled trigger" value="0" <?php if($box->mtype == "0") { echo 'checked'; } ?>>All</label>
	<label class="radio inline"><input type="radio" name="type" data-rel="1" class="styled trigger" value="1" <?php if($box->mtype == "1") { echo 'checked'; } ?>>Video</label>
	<label class="radio inline"><input type="radio" name="type" data-rel="2" class="styled trigger" value="2" <?php if($box->mtype == "2") { echo 'checked'; } ?>>Music</label>
	<label class="radio inline"><input type="radio" name="type" data-rel="3" class="styled trigger" value="3" <?php if($box->mtype == "3") { echo 'checked'; } ?>>Images</label>
	</div>
	</div>	
<?php echo '
<div class="control-group">
	<label class="control-label">'._lang("Category:").'</label>
	<div class="controls">
	<select data-placeholder="'._lang("Choose a category:").'" name="ident" id="ident clear-results" class="select" tabindex="2">
	';
$categories = $db->get_results("SELECT cat_id as id, cat_name as name FROM  ".DB_PREFIX."channels order by cat_name asc limit 0,10000");
if($categories) {
$i = 0;
foreach ($categories as $cat) {	
if($box->ident == $cat->id) { $ss = "selected"; $i++; } else { $ss ="";}
echo '<option value="'.intval($cat->id).'" '.$ss.'>'._html($cat->name).'</option>';
$ss ="";
}
}  
if($i > 0 ) {
echo '<option value="">-- ALL --</option>'; 
} else {
echo '<option value="" selected>-- ALL --</option>'; 
}
echo '	  
	  </select>
	  	<span class="help-block" id="limit-text"> Optional: Restrict video in block to a category.</span>
	  </div>             
	  </div>
';
echo '
 <div class="box-bottom clearfix"> <button class="btn btn-primary btn-mini pull-right">Save changes</button>  </div>
</form>
</div>
</div>';
} else {
echo '<div class="box-element span6">
Missing block? </div>
';
}
echo '<div class="box-element span6">	
<div class="box-head-light"><i class="icon-list-ol"></i><h3>Blocks</h3></div>
<div class="box-content">	
 <div id="easyhome">
<ul id="sortable" class="droptrue">
';
$boxes_sql = $db->get_results("SELECT * FROM ".DB_PREFIX."homepage order by `ord` ASC limit 0,1000000");
if($boxes_sql) {
foreach($boxes_sql as $box){ 
echo '
<li id="recordsArray_'.$box->id.'" class="sortable clearfix">
<div class="ns-row pull-left"><div class="ns-title"><i class="icon-sort" style="margin-right:8px;"></i>'._html($box->title).'</div>
<a style="padding:0 20px;" href="'.admin_url('edit-block').'&id='.$box->id.'" class="tipS delete-menu pull-right" title="Edit" ><i class="icon-pencil"></i></a>
<a href="'.admin_url('homepage').'&delete='.$box->id.'" class="tipS delete-menu pull-right" title="Delete"><i class="icon-trash"></i></a></div>
 
 </li>';
 }
}  

echo '
 </ul>
</div>	
<div id="respo" style="display:none;"></div>	
				</div>	
</div>';				
 ?>