<?

/*
FlexCMS (http://www.flexcms.com)
Flexible, Powerful, Affordable.

Contents of this file are protected by the copyright
notice found at http://www.flexcms.com/flex/pages/copyright.html,
and its usage is subject to the terms of the licensing agreement 
available at http://www.flexcms.com/flex/pages/license.html
*/



	// ========================================================================================
	// photo galleries administration
	// ========================================================================================
	
	$PageTitle = '<img src="'.$ImagesURL.'/admin/admincp_photo.gif" width="28" height="22"> '.$MsgText[3][2];
	$BrowserTitle = $MsgText[3][2];
	$LocationBar = '<a href="'.$IndexURL.'">'.$MsgText[0][1].'</a> > <a href="' . $MainURL . '/options.html">'.$MsgText[0][4].'</a> > '.$MsgText[3][2];
	
	if ($LoggedIn == 'y') {
		
		ReadPermissions();
		Global $Permissions;
		
		if ($Permissions[301] == 'y') {
		
		
		$query = "select * from `".$Settings['DBPrefix']."pg-Settings`";
		$result = mysql_query($query) or die (mysql_error());
		while ($row = mysql_fetch_array($result)) {
			$pgSettings[$row['Name']] = $row['Value'];
		}
		if ($pgSettings['StorageLocationHTTP'] == '') {
			$pgSettings['StorageLocationHTTP'] = $BaseURL.'/pg_images';
		}
		if ($pgSettings['StorageLocationLocal'] == '') {
			$pgSettings['StorageLocationLocal'] = './pg_images';
		}
		
		
		$query = "select * from `".$Settings['DBPrefix']."pg-Galleries` where MinLevel<='".$UserLevel."' and MinEditLevel<='".$UserLevel."' ORDER BY GalleryTitle ASC, RecordNumber ASC";
		$result = mysql_query($query) or die (mysql_error());
		
		$GalleriesFound = 'n';
		if (mysql_num_rows($result) != 0) {
			$GalleriesFound = 'y';
			while ($row = mysql_fetch_array($result)) {
							
				$GalleriesListPrint .= '<option value="'.$row['RecordNumber'].'"> '.$row['GalleryTitle'].'</option>';
				$GalleryTitles[$row['RecordNumber']] = $row['GalleryTitle'];
				$GalleryAllowed[$row['RecordNumber']] = 'y';
				
				
				if ($row['GalleryDescription'] != '') {
					$row['GalleryDescription'] = '<br><font size="1">'.$row['GalleryDescription'].'</font>';
				}
				
				
				$ItemsCount++;
				$CatsPrint .= '<img src="'.$ImagesURL.'/admin/spacer.gif" width="1" height="4" alt="" border="0"><br><table border="0" cellpadding="0" cellspacing="0"><tr><td><font size="2" face="Arial" color="'.$Colors['Text'].'">&nbsp;&nbsp;&nbsp;&nbsp;<a href="javascript:ExpandCollapse(\''.$ItemsCount.'\');" style="text-decoration: none;"><img id="img'.$ItemsCount.'" src="'.$ImagesURL.'/admin/minus.gif" border="0" width="9" height="9" alt=""></a><font size="2" face="Arial" color="'.$Colors['Text'].'">&nbsp;</font></td><td><a href="javascript:ExpandCollapse(\''.$ItemsCount.'\');" style="text-decoration: none;"><font size="2" face="Arial" color="'.$Colors['Text'].'"><b>'.$row['GalleryTitle'].'</b></a>'.$CatEditLink.'<font size="1">'.$row['GalleryDescription'].'</font></font></td></tr></table><img src="'.$ImagesURL.'/admin/spacer.gif" width="1" height="4" alt="" border="0"><br><div id="div'.$ItemsCount.'"><table width="100%" border="0" cellpadding="0" cellspacing="0"><tr><td width="40"><img src="'.$ImagesURL.'/admin/spacer.gif" width="40" height="1" alt="" border="0"></td><td width="100%">';
				
				
				$query2 = "select * from `".$Settings['DBPrefix']."pg-Images` where GalleryNumber='".$row['RecordNumber']."' ORDER BY ImageTitle ASC, RecordNumber ASC";
				$result2 = mysql_query($query2) or die (mysql_error());
				while ($row2 = mysql_fetch_array($result2)) {
				
					if ($row2['ImageDescription'] != '') {
							
						if (strlen($row2['ImageDescription']) > 70) {
							$row2['ImageDescription'] = str_replace('<','&lt;',substr($row2['ImageDescription'],0,70)).'...';
						}
						
						$row2['ImageDescription'] = '<br><font size="1">'.str_replace('<','&lt;',$row2['ImageDescription']).'</font>';
					}				
				
				
					$CatsPrint .= '<img src="'.$ImagesURL.'/admin/spacer.gif" width="1" height="4" alt="" border="0"><br><table border="0" cellpadding="0" cellspacing="0"><tr><td width="20"><img src="'.$ImagesURL.'/admin/spacer.gif" width="20" height="1" alt="" border="0"></td><td width="1" bgcolor="'.$Colors['Text'].'"><img src="'.$ImagesURL.'/admin/spacer.gif" width="1" height="1" alt="" border="0"></td><td width="10"><img src="'.$ImagesURL.'/admin/spacer.gif" width="10" height="1" alt="" border="0"></td><td><font size="2" face="Arial" color="'.$Colors['Link'].'"><a href="'.$MainURL.'/admin/photos_edit/'.$row2['RecordNumber'].'" style="text-decoration: none;"><b>'.$row2['ImageTitle'].'</b></a>'.$row2['ImageDescription'].'</font></td><td><img src="'.$ImagesURL.'/admin/spacer.gif" width="20" height="1" alt="" border="0"></td><td align="center"><font size="1" face="Arial"><a href="'.$MainURL.'/photos/image/'.$row2['RecordNumber'].'.html" target="_blank"><img src="'.$ImagesURL.'/admin/pages_view.gif" border="0" width="16" height="16" alt=""><br>'.$MsgText[0][249].'</font></a></td><td width="12"><img src="'.$ImagesURL.'/admin/spacer.gif" width="12" height="1" alt="" border="0"></td><td align="center"><font size="1" face="Arial"><a href="'.$MainURL.'/admin/photos_edit/'.$row2['RecordNumber'].'"><img src="'.$ImagesURL.'/admin/pages_edit.gif" border="0" width="16" height="16" alt=""><br>'.$MsgText[0][155].'</a></td><td width="12"><img src="'.$ImagesURL.'/admin/spacer.gif" width="12" height="1" alt="" border="0"></td><td align="center"><font size="1" face="Arial"><a href="'.$MainURL.'/admin/photos_delete/'.$row2['RecordNumber'].'"><img src="'.$ImagesURL.'/admin/pages_delete.gif" border="0" width="16" height="16" alt=""><br>'.$MsgText[0][156].'</font></a></td></tr></table><img src="'.$ImagesURL.'/admin/spacer.gif" width="1" height="4" alt="" border="0"><br>';
				
				}
		
				
				
				
				$CatsPrint .= '</td></tr></table><img src="'.$ImagesURL.'/admin/spacer.gif" width="1" height="4" alt="" border="0"></div><img src="'.$ImagesURL.'/admin/spacer.gif" width="1" height="10" alt="" border="0"><br>';
			
			}
		}
		
		
		$PageContents = '<br><a href="'.$MainURL.'/admin/photos_galleries.html"><b>'.$MsgText[3][3].'</b></a><br><br><a href="#new">'.$MsgText[3][52].'</a><br><br><br><b>'.$MsgText[3][53].':</b><br>'. $CatsPrint;
		
	
		
		$PageContents .= '<script>

var ItemsCount = '.number_format($ItemsCount,0,'','').';

function CollapseAll() {

	for (x=1; x<=ItemsCount; x++) {
	
		var ElementID = document.getElementById("div"+x);
		var ImgElementID = document.getElementById("img"+x);
		
		ElementID.style.display = "none"
		ImgElementID.src = "'.$ImagesURL.'/admin/plus.gif";
	
	}

}

function ExpandCollapse(IDNumber) {

	var ElementID = document.getElementById("div"+IDNumber);
	var ImgElementID = document.getElementById("img"+IDNumber);
	
	if (ElementID.style.display != "none") {
		ElementID.style.display = "none"
		ImgElementID.src = "'.$ImagesURL.'/admin/plus.gif";
	}
	else {
		ElementID.style.display = ""
		ImgElementID.src = "'.$ImagesURL.'/admin/minus.gif";
	}

}

CollapseAll();

</script>';
			
		
		if ($GalleriesFound == 'y') {
		
		
			if (function_exists("gd_info")) {
				$GDInfo = @gd_info();
			}
			if ($GDInfo['GIF Create Support'] == true) {
				$MsgText[3][59] = str_replace('JPEG/PNG','GIF/JPEG/PNG',$MsgText[3][59]);
			}
		
		
			$RandomNumber = sprintf("%03d", rand(0,999)) . sprintf("%02d", rand(0,99));
		
			$PageContents .= '<br><br><a name="new"></a><b>'.$MsgText[3][52].':</b><br><br><form name="ImageForm" action="'.$MainURL.'/admin/photos_upload" method="post" enctype="multipart/form-data"><input type="hidden" name="RandomNumber" value="'.$RandomNumber.'">

<table width="500" border="0" cellpadding="3" cellspacing="3">

<tr><td width="120"><font face="'.$FontFace.'" size="'.$FontSize.'"><b>'.$MsgText[3][55].':</b></td><td>
<select name="Gallery">'.$GalleriesListPrint.'</select></td></tr>

<tr><td><font face="'.$FontFace.'" size="'.$FontSize.'"><b>'.$MsgText[3][75].':</b></td><td>
<select name="NumImages" onClick="UpdateDivs(this.value);" onChange="UpdateDivs(this.value);">
<option value="1"> 1</option>
<option value="2"> 2</option>
<option value="3"> 3</option>
<option value="4"> 4</option>
<option value="5"> 5</option>
<option value="6"> 6</option>
<option value="7"> 7</option>
<option value="8"> 8</option>
<option value="9"> 9</option>
<option value="10"> 10</option>
</select></td></tr>

<tr><td><img src="'.$ImagesURL.'/admin/spacer.gif" width="1" height="10" alt="" border="0"></td></tr>';


			for ($x = 1; $x <= 10; $x++) {
				$PageContents .= '<div id="PhotoDiv'.$x.'">
<table width="500" border="0" cellpadding="3" cellspacing="3">
<tr><td><font face="'.$FontFace.'" size="'.$FontSize.'"><b>'.$MsgText[3][35].':</b></td><td><input type="text" name="Title'.$x.'" size="30" maxlength="255" value=""></td></tr>

<tr><td><font face="'.$FontFace.'" size="'.$FontSize.'"><b>'.$MsgText[3][36].':</b></td><td><textarea name="Description'.$x.'" cols="40" rows="3"></textarea><!-- <br><font face="'.$FontFace.'" size="'.($FontSize-1).'">(Optional) --></td></tr>

<tr><td><font face="'.$FontFace.'" size="'.$FontSize.'"><b>'.$MsgText[3][68].':</b></td><td><input type="file" name="FileData'.$x.'"><br><font face="'.$FontFace.'" size="'.($FontSize-1).'">('.$MsgText[3][59].' '.number_format($pgSettings['MaxFileSize'],0,'','').' KBytes)</td></tr>


<tr><td><img src="'.$ImagesURL.'/admin/spacer.gif" width="1" height="10" alt="" border="0"></td></tr>
</table>
</div>';
			}



			$PageContents .= '<script>

function UpdateDivs(DivsCount) {
	
	for (x = 1; x <= 10; x++) {
	
		var ElementID = document.getElementById("PhotoDiv"+x);
		
		if (x <= DivsCount) {
			//alert(x+"show");
			ElementID.style.display = "";
		}
		else {
			//alert(x+"hide");
			ElementID.style.display = "none";
		}
		
	}
}



UpdateDivs(document.forms["ImageForm"].elements["NumImages"].value);

</script>

<!-- <tr><td><font face="'.$FontFace.'" size="'.$FontSize.'"><b>'.$MsgText[3][60].':</b></td><td><font face="'.$FontFace.'" size="'.$FontSize.'"><input type="checkbox" name="HidePoster" value="y"> '.$MsgText[0][118].'</td></tr> -->

<table width="500" border="0" cellpadding="3" cellspacing="3">

<tr><td colspan="2"><font face="'.$FontFace.'" size="'.$FontSize.'"><b>'.$MsgText[0][323].'</b></td></tr>
</table><br><br><input type="hidden" name="MAX_FILE_SIZE" value="'.number_format(($pgSettings['MaxFileSize']*1024),0,'','').'"><input name="SubmitButton" type="submit" value="'.$MsgText[0][324].'"></form>';

		} // end if galleries exist
		else {
		
			$PageContents = '<br><br><b>'.$MsgText[3][61] .'<br><br><a href="'.$MainURL.'/admin/photos_galleries.html">'.$MsgText[3][29].'</a></b>';
		
		} // end if no galleries exist
		
				
		
		} // end if permissions are sufficient
		else {
		
			$PageContents = $MsgText[0][97];
		
		}

	}
	else {
	
		RedirectToLogin();
	
	}

	// ========================================================================================




?>
