<?
/*
 * This file is part of a larger software package. Please read the License file 
 * in the root of this installation for terms of usage and distribution.
 * 
 * @author The Web Pro Miami, Inc. <info@thewebpro.com>
 * @copyright The Web Pro Miami, Inc. <info@thewebpro.com>, http://www.thewebpro.com/
 * 
 * CORE: manage/library_images.php - version 1.0
*/

$nSecureMe = 1;

// Secure and connect
require("../inc/dbconnect.php");
require("inc/secure_page.php");
require("../inc/tracker.php");

// Includes
require("../inc/config.php");
require("inc/lang.php");

$nMainLibraryName = nGetFirstImageLibraryName();
if(!$nMainLibraryName){ $nMainLibraryName = "Content"; }

// Override to show "Content" library first
$nMainLibraryName = "Content";
?>
<?php include("inc/nav/header.php"); ?>

<div id="titlediv">
    <div class="clearfix container" id="pattern">
        <div class="row">
            <div class="col_12">
                <ul class="breadcrumbs hor-list">
                    <li><a href="home.php"><?php echo _("Dashboard"); ?></a></li>
                    <li><a href="library_images.php"><?php echo _("Image Library"); ?></a></li>
                </ul>
                <h1><?php echo _("Image Library"); ?></h1>
            </div>
        </div>
    </div>
</div>

<div class="container" id="actualbody">

	<div class="row clearfix">
	    <div class="widget clearfix">
			<div class="view-switcher">
			    <h2><span id="ajaxImagesTitle"><?=$nMainLibraryName;?></span><a href="javascript:;">&darr;</a></h2>
			    <ul>
					<?=nGetImageLibraries();?>
			    </ul>
			</div>
			<div class="widget_inside">
	            <span id="notify" class="notification done" style="display:none;"></span>
				<div class="col_12" id="ajaxImages"></div>
	        </div>
	    </div>
	</div>
    
</div>

<script>
// load external content
function nLoadAjaxImages(){
	loadContentToID("#ajaxImages","list/images.php?t=<?=$nMainLibraryName;?>");
}
$(function(){
	nLoadAjaxImages();
});
// Handle image callbacks
editImage = function(id){
	var xURL = "dialog/image_edit.php?id="+id;
	var xTitle = "Edit Image";
	$.colorbox({ href:xURL, title:xTitle, overlayClose:false, opacity:0.4, maxWidth:850, initialWidth:80, initialHeight:80 });
}
unlinkImage = function(id){
	var xURL = "dialog/image_unlink.php?id="+id;
	var xTitle = "Unlink Image";
	$.colorbox({ href:xURL, title:xTitle, overlayClose:false, opacity:0.4, maxWidth:850, initialWidth:80, initialHeight:80 });
}
deleteImage = function(id){
	var xURL = "dialog/image_delete.php?id="+id;
	var xTitle = "Delete Image";
	$.colorbox({ href:xURL, title:xTitle, overlayClose:false, opacity:0.4, maxWidth:850, initialWidth:80, initialHeight:80 });
}
</script>

<?php include("inc/nav/footer.php") ?>
<?php
function nGetImageLibraries(){
	global $DBName, $Link;
	$nTable = "";
	$Query = "SELECT nID,nName FROM nLibrary ORDER BY nName";
	mysql_select_db($DBName); $Result = mysql_query($Query,$Link);
	while ($Row = mysql_fetch_array($Result)){
		$nLibraryID = $Row["nID"];
		$nName = $Row["nName"];
		$nNameToPass = str_replace(" ","%20",$nName); // required for passing via AJAX
		$nTable.="<li><a href=\"javascript:;\" onClick=\"loadTable('#ajaxImages','list/images.php?t=$nNameToPass','$nName');\">$nName</a></li>";
	}
	return $nTable;
}
function nGetFirstImageLibraryName(){
	global $DBName, $Link;
	$nName = "";
	$Query = "SELECT nID,nName FROM nLibrary ORDER BY nName";
	mysql_select_db($DBName); $Result = mysql_query($Query,$Link);
	if($Row = mysql_fetch_array($Result)){
		$nName = $Row["nName"];
	}
	return $nName;
}
?>
<?
// disconnect from mysql
mysql_close($Link);
?>