Exemplo n.º 1
0
/**
 * Function to display the "video manage" page
 */
function tnt_video_manage()
{
    ?>
		<div class="wrap">
			<?php 
    screen_icon('upload');
    ?>
			<h2>Video Manage</h2>
			<hr />
			<?php 
    //Get var filter
    $catID = isset($_GET["vCat"]) ? $_GET["vCat"] : 0;
    $typeID = isset($_GET["vLinkType"]) ? $_GET["vLinkType"] : 0;
    $orderBy = isset($_GET["orderBy"]) ? $_GET["orderBy"] : null;
    $order = isset($_GET["order"]) ? $_GET["order"] : null;
    $tntVideos = TNT_Video::tntGetVideos(array('catID' => $catID, 'typeID' => $typeID));
    $items = count($tntVideos);
    //Get Plugin Options
    $tntOptions = get_option('tntVideoManageOptions');
    $numLimit = $tntOptions['limitAdminPerPage'];
    if ($items > $numLimit) {
        $p = new TNT_Pagination();
        $p->items($items);
        $p->limit($numLimit);
        // Limit entries per page
        $p->target($_SERVER["REQUEST_URI"]);
        $p->calculate();
        // Calculates what to show
        $p->parameterName('paged');
        $p->adjacents(1);
        //No. of page away from the current page
        if (!isset($_GET['paged'])) {
            $p->page = 1;
        } else {
            $p->page = $_GET['paged'];
        }
        $p->currentPage($p->page);
        // Gets and validates the current page
        //Query for limit paging
        $limit = "LIMIT " . ($p->page - 1) * $p->limit . ", " . $p->limit;
    } else {
        $limit = "LIMIT 0, 10";
    }
    ?>
			<!-- Filter -->
			<form method="GET" action="">
				<input type="hidden" name="page" value="tnt_video_manage_page" />	
				<table width="100%">
					<tr>
						<td width="33%">			
							Filter by Category: <?php 
    echo TNT_VideoCat::tntDisplayListCat($catID);
    ?>
	
						</td>
						<td width="33%">
							Filter by Type: <?php 
    echo TNT_VideoType::tntDisplayListType($typeID);
    ?>
						</td>
						<td width="34%">
							Order by: 
							<select name="orderBy">
								<option <?php 
    echo $orderBy == 'date_created' ? "selected" : "";
    ?>
 value="date_created">Created Date</option>
								<option <?php 
    echo $orderBy == 'date_modified' ? "selected" : "";
    ?>
 value="date_modified">Editing Date</option>
								<option <?php 
    echo $orderBy == 'video_title' ? "selected" : "";
    ?>
 value="video_title">Title</option>
								<option <?php 
    echo $orderBy == 'video_link_type' ? "selected" : "";
    ?>
 value="video_link_type">Type</option>
								<option <?php 
    echo $orderBy == 'video_status' ? "selected" : "";
    ?>
 value="video_status">Status</option>
								<option <?php 
    echo $orderBy == 'video_order' ? "selected" : "";
    ?>
 value="video_order">Order Number</option>
							</select>
							<select name="order">
								<option <?php 
    echo $order == 'ASC' ? "selected" : "";
    ?>
 value="ASC">Ascending</option>
								<option <?php 
    echo $order == 'DESC' ? "selected" : "";
    ?>
 value="DESC">Descending</option>
							</select>
							<input type="submit" value="Filter" class="button-secondary" />
						</td>
					</tr>
				</table>
			</form>
			<!-- Filter -->
			<!-- Message -->
			<div class='<?php 
    echo $items > 0 ? "updated" : "error";
    ?>
'><p><?php 
    echo $items;
    ?>
 Result(s) found!</p></div>    
			<!--End  Message -->

			<form method="POST" action="">
			<table>
				<tr>
					<td align="left" width="70">Actions</td>
					<td align="left" width="95">
						<select name="tntActions">
							<option value="1">Publish</option>
							<option value="2">Unpublish</option>
							<option value="3">Delete</option>
						</select>
					</td>
					<td align="left" width="120"><input type="submit" class="button-secondary btnAct" name="tntBtnAct" value="Update" /></td>	
				</tr>
			</table>
			<?php 
    //show message
    if (isset($_GET["m"])) {
        $m = $_GET["m"];
        if ($m) {
            showMessage("Your video(s) updated successfully!", $m);
        } else {
            showMessage("Your video(s) updated failed!", $m);
        }
    }
    ?>
			<!-- List Video -->
			<table class="tntTable widefat">
				<thead>
					<tr>
						<td><input type="checkbox" name="tntChkAll" class="tntChkAll" /></td>
						<th>ID</th>
						<th>Title</th>
						<th>Category</th>
						<th>Type</th>
						<th>Link</th>
						<th>Status</th>
						<th width="50">Order Num</th>
						<th width="100">Created Date (GMT + 0:00)</th>
						<th width="100">Last Modified (GMT + 0:00)</th>
						<th>Action</th>
					</tr>
				</thead>
				<tfoot>
					<tr>
						<th></th>
						<th>ID</th>
						<th>Title</th>
						<th>Category</th>
						<th>Type</th>
						<th>Link</th>
						<th>Status</th>
						<th>Order Num</th>
						<th>Created Date (GMT +0)</th>
						<th>Last Modified (GMT +0)</th>
						<th>Action</th>
					</tr>
				</tfoot>
				<tbody>
					<?php 
    $tntVideos = TNT_Video::tntGetVideos(array('catID' => $catID, 'typeID' => $typeID, 'limitText' => $limit, 'orderBy' => $orderBy, 'order' => $order));
    foreach ($tntVideos as $tntV) {
        ?>
							<tr>
								<td><input type="checkbox" name="tntChkVideos[]" class="tntSubChk" value="<?php 
        echo $tntV->video_id;
        ?>
" /></td>
								<td><a href="<?php 
        echo admin_url();
        ?>
admin.php?page=tnt_video_edit_page&videoID=<?php 
        echo $tntV->video_id;
        ?>
"><b><?php 
        echo $tntV->video_id;
        ?>
</b></a></td>
								<td><b><a href="<?php 
        echo admin_url();
        ?>
admin.php?page=tnt_video_edit_page&videoID=<?php 
        echo $tntV->video_id;
        ?>
"><?php 
        echo $tntV->video_title;
        ?>
</a></b></td>
								<td><?php 
        echo $tntV->video_cat_title;
        ?>
</td>
								<td>
									<?php 
        switch ($tntV->video_type_title) {
            case 'DailyMotion':
                echo '<img src="' . TNT_IMG_URL . '/dailymotion.gif" alt="' . $tntV->video_type_title . '" title="' . $tntV->video_type_title . '" />';
                break;
            case 'Vimeo':
                echo '<img src="' . TNT_IMG_URL . '/vimeo.gif" alt="' . $tntV->video_type_title . '" title="' . $tntV->video_type_title . '" />';
                break;
            default:
                echo '<img src="' . TNT_IMG_URL . '/utube.gif" alt="' . $tntV->video_type_title . '" title="' . $tntV->video_type_title . '" />';
                break;
        }
        ?>
								</td>
								<td><a href="<?php 
        echo $tntV->video_link;
        ?>
" target=_blank>Click to watch</a></td>
								<td><?php 
        echo $tntV->video_status ? '<img src="' . TNT_IMG_URL . '/publish.gif" alt="Published" />' : '<img src="' . TNT_IMG_URL . '/unpublish.gif" alt="Unpublished" />';
        ?>
</td>
								<td><?php 
        echo $tntV->video_order;
        ?>
</td>
								<td><?php 
        echo date('Y-m-d H:i:s', $tntV->date_created);
        ?>
</td>
								<td><?php 
        echo date('Y-m-d H:i:s', $tntV->date_modified);
        ?>
</td>
								<td>
									<a href="<?php 
        echo admin_url();
        ?>
admin.php?page=tnt_video_edit_page&videoID=<?php 
        echo $tntV->video_id;
        ?>
" class="button-secondary">Edit</a> 
									<a href="<?php 
        echo admin_url();
        ?>
admin.php?page=tnt_video_del_page&videoID=<?php 
        echo $tntV->video_id;
        ?>
" class="button-secondary">Delete</a>
								</td>
							</tr>
					 <?php 
    }
    ?>
				</tbody>
			</table><!-- List Video -->

			<?php 
    if ($items > $numLimit) {
        ?>
				<div class="tablenav">
				    <div class='tablenav-pages'>
				        <?php 
        echo $p->show();
        // Echo out the list of paging.
        ?>
				    </div>
				</div>				
			<?php 
    }
    ?>
			</form>
		</div>

		<script type="text/javascript">
			jQuery(document).ready(function($){

				//check if have any videos checked
				$(".btnAct").click(function(e){
					var rs = false;

					$('.tntTable tr').each (function ()
					{
						var checkbox = $(this).find(".tntSubChk");
						if (checkbox.is (':checked'))
						{
							rs = true;
						}
					});

					if(rs == false)
					{
						alert("No Items checked");
						e.preventDefault();	
					}
				});

				$(".tntChkAll").click(function(){
					if($(this).is(":checked"))
					{
						$('.tntTable tr').each (function ()
						{
							var checkbox = $(this).find(".tntSubChk");
							checkbox.attr("checked", "checked");
						});
					}
					else
					{
						$('.tntTable tr').each (function ()
						{
							var checkbox = $(this).find(".tntSubChk");
							checkbox.removeAttr("checked");
						});	
					}
				});
			});	
		</script>
	<?php 
}