<?

/*
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
*/



	// ========================================================================================
	// Switch Templates
	// ========================================================================================
	
	$PageTitle = '<img src="'.$ImagesURL.'/admin/admincp_settings.gif" width="23" height="20"> '.$MsgText[0][63];
	$BrowserTitle = $MsgText[0][63];
	$LocationBar = '<a href="'.$IndexURL.'">'.$MsgText[0][1].'</a> > <a href="'.$MainURL. '/options.html">'.$MsgText[0][4].'</a> > '.$MsgText[0][63];
	
	if ($LoggedIn == 'y') {
		
		ReadPermissions();
		Global $Permissions;
		
		if ($Permissions[16] == 'y') {
	
			for ($i = 0; $i < count($TBlocks); $i++) {
				if ($BlocksString == '') {
					$BlocksString = $BlockLocationDescription[$TBlocks[$i]];
				}
				else {
					$BlocksString .= ', ' . $BlockLocationDescription[$TBlocks[$i]];
				}
			}
			
			/*if ($TNotes != '') {
				$TNotes = '<br><br>Notes: ' . $TNotes;
			}
			
			if ($TCreatorLink != '') {
				$TCreator = '<a href="'.$TCreatorLink.'" target="_blank">'.$TCreator.'</a>';
			}*/
			$PageContents = '<br>'.$MsgText[0][479].': <a href="'.$Settings['SPURL'].'" target="_blank">'.$Settings['SPURL'].'</a>.</b><br><br><br>';

						
				
			
			
			if ($dir = @opendir('./templates')) {
				$Counter = 0;
				while (($file = readdir($dir)) !== false) {
		   			if (is_dir('./templates/'.$file) && $file != '.' && $file != '..') {
						$TemplateCodes[] = $file;
						
						$TNotes = ''; $TVersion = ''; $TCode = ''; $TName = ''; $TDate = ''; 
						$TBlocks = ''; $TCreator = ''; $TCreatorLink = ''; $TCopyright = '';
						$BlocksString = '';
										
						include('./templates/'.$file.'/template_info.php');
						
						
						$TemplateNames[$file] = $TName;
						$TemplateVersions[$file] = $TVersion;
						$TemplateDates[$file] = $TDate;
						$TemplateNotes[$file] = $TNotes;
						$TemplateBlocks[$file] = $TBlocks;
						$TemplateCreators[$file] = $TCreator;
						$TemplateCreatorLinks[$file] = $TCreatorLink;
						$TemplateCopyrights[$file] = $TCopyright;
						
						//$Counter++;
						//print $file.'<br>';
        			}
				}
				closedir($dir);
			}
			
			
			for ($i = 0; $i < count($TemplateCodes); $i++) {
				for ($j = 0; $j < (count($TemplateCodes)-1); $j++) {

					if ($TemplateNames[$TemplateCodes[$j]] > $TemplateNames[$TemplateCodes[$j+1]]) {
					
						$Swap1 = $TemplateCodes[$j];
						
						$TemplateCodes[$j] = $TemplateCodes[$j+1];
						
						$TemplateCodes[$j+1] = $Swap1;
					
					} 
				
				}
			}
			
			
			for ($i = 0; $i <= count($TemplateCodes); $i++) {
				
				//$HiddenFields .= '<input type="hidden" name="TemplateCode'.$i.'" value="'.$TemplateCodes[$i].'">';
				
				if ($TemplateCodes[$i] == $Settings['TemplateCode']) { $CurrentTemplateFoundAt = $i; }
				
			}
			

			if (count($TemplateCodes) > 0) {
			
			
				$PageContents .= '<script language="JavaScript">
				
				function ViewLargePreview(TemplateCode) {
					var ImageLocation = \''.$BaseURL.'/templates/\'+TemplateCode+\'/template_preview_large.gif\';

					var WindowCode = window.open(ImageLocation,\'LargeTemplatePreview\',\'width=408,height=318\');
				}				
					
				</script>';
			
			
			
				for ($a = 0; $a < count($TemplateCodes); $a++) {
				
					$TNotes = ''; $TVersion = '';$TCode = ''; $TName = ''; $TDate = '';
					$TBlocks = ''; $TCreator = ''; $TCreatorLink = ''; $TCopyright = '';
					$BlocksString = '';
				
					$TName = $TemplateNames[$TemplateCodes[$a]];
					$TVersion = $TemplateVersions[$TemplateCodes[$a]];
					$TDate = $TemplateDates[$TemplateCodes[$a]];
					$TNotes = $TemplateNotes[$TemplateCodes[$a]];
					$TBlocks = $TemplateBlocks[$TemplateCodes[$a]];
					$TCreator = $TemplateCreators[$TemplateCodes[$a]];
					$TCreatorLink = $TemplateCreatorLinks[$TemplateCodes[$a]];
					$TCopyright = $TemplateCopyrights[$TemplateCodes[$a]];
				
										
					for ($i = 0; $i < count($TBlocks); $i++) {
						if ($BlocksString == '') {
							$BlocksString = $BlockLocationDescription[$TBlocks[$i]];
						}
						else {
							$BlocksString .= ', ' . $BlockLocationDescription[$TBlocks[$i]];
						}
					}
					
					if ($a == $CurrentTemplateFoundAt) {
						$SelectionButton = '<input type="radio" name="TemplateSelection" value="'.$TemplateCodes[$a].'" checked>';
					}
					else {
						$SelectionButton = '<input type="radio" name="TemplateSelection" value="'.$TemplateCodes[$a].'">';
					}
					
					if ($Permissions[18] == 'y' && $TemplatePreview != 'y') {
						$PreviewLink = '<br><a href="'.$MainURL.'/template_preview/'.$TemplateCodes[$a].'" target="_blank"><b>'.$MsgText[0][482].'</b></a>';
					}
					else {
						$PreviewLink = '';
					}
					
					if ($TNotes != '') {
						$TNotes = '<br>Notes: ' . $TNotes;
					}
					
					if ($TCreatorLink != '') {
						$TemplateDescription = '<font size="2"><b>'.$TName.'</b> '.$MsgText[0][480].' '.$TVersion.' ('.$TDate.')<br>'.$MsgText[0][481].': <a href="'.$TCreatorLink.'" target="_blank">'.$TCreator.'</a><br>'.$PreviewLink.'<br><font size="1">'.$TNotes;
					}
					else {
						$TemplateDescription = '<font size="2"><b>'.$TName.'</b> '.$MsgText[0][480].' '.$TVersion.' ('.$TDate.')<br>'.$MsgText[0][481].': '.$TCreator.'<br>'.$PreviewLink.'<br><font size="1">'.$TNotes;
					}
					
					
					
					$TemplatesList .= '<table border="0" cellpadding="7" cellspacing="0">
						<tr>
							<td align="center">'.$SelectionButton.'</td>
							<td align="center"><a href="JavaScript:ViewLargePreview(\''.$TemplateCodes[$a].'\');"><img src="'.$BaseURL.'/templates/'.$TemplateCodes[$a].'/template_preview.gif" width="128" height="96" alt="'.$TName.' '.$MsgText[0][480].' '.$TVersion.'" border="0"></td>
							<td><font face="'.$FontFace.'" size="'.$FontSize.'">'.$TemplateDescription.'</font></td>
						</tr>
						</table>';
					
					
				} // end loop
				
				
			} // if templates found
				
				
				$OverridesArray = explode('%%',$Settings['Overrides']);
				// fontface, fontsize, bgcolor, text, link, vlink, alink, btext, blink, bvlink, balink
				
								
				
				
				$PageContents .= '<form name="TemplateSelection" action="'.$MainURL . '/admin/templates-save" method="post">'.$TemplatesList.'<br><br><br><input type="submit" value="'.$MsgText[0][123].'"></form>
</div>
<br>';
			
			
			
			
			
			
			include('./templates/'.$Settings['TemplateCode'].'/template_info.php');

		}
		else {
		
			$PageContents = $MsgText[0][97];
		
		}

	}
	else {
	
		RedirectToLogin();
	
	}

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




?>
