Location: PHPKode > projects > CorePHPAlbum > cpa-2.0.2/admin.php
<?php

/*   ========================================================
     =                                                      =
     = corePHPAlbum - web-based photo gallery               =
     =                                                      =
     = Official code                                        =
     = file release 2.0.2                                   =
     =                                                      =
     = http://sourceforge.net/projects/corephpalbum         =
     =                                                      =
     ======================================================== */

require_once('_res/sources/authentication.php');
require_once('_res/sources/encryption.php');
require_once('_res/sources/functions.php');
require_once('_res/sources/utilities.php');
require_once('_switches.php');

require_once('_res/admin/lang.php');
require_once('_res/admin/tools.php');
require_once('_res/sources/debug.php');
debug_init();

// Initialization
//
init_codetable();
$starttime = float_microtime();
$_coreconfig = array();
$_config = array();
$_info = array();

$logged_in = logged_in();
while (!$logged_in) {
	redirect_to_url('login.php');
}

if ( !session_id() ) {
	session_start();
}

switch($_GET['act'])
{
	case 'coresave':
		// step 0 save: branch level coreconfig.inc files
		//
		$thedir = ($_POST['currentdir'] == '' ? '_config/' : '_config/' . $_POST['currentdir'] . '/');
		$messages = '';

		if ($_switch['admin_demo_mode'] == 'ON') {
			$messages .= $lang['simulation_note'];
		} else {
			// config.inc
			$inc = $thedir . 'coreconfig.inc';
			$del = (array_key_exists('del_config', $_POST) && $_POST['del_config'] == 'on');
			$create = (array_key_exists('create_config', $_POST) && $_POST['create_config'] == 'on');
			if ($del) {
				$messages .= del_inc($inc);
			}	else if ($create || file_exists($inc)) {
				$messages .= save_coreconfig($inc);
			}
		}
		if ($messages != '') { $messages .= '<br/>'; }

		load_00($_POST['currentdir'], $messages);

		break;
	case 'admin':
		// step 1: folder administration
		//
		$current = curr_dir();

		load_10($current, '');
		break;
	case 'makefolder':
		// step 1 make folder: folder administration
		//
		$messages = '';
		$current = $_POST['currentdir'];

		if ($_switch['admin_demo_mode'] == 'ON') {
			$messages .= $lang['simulation_note'];
		} else if (array_key_exists('foldername', $_POST)) {
			$basedir = ($_POST['currentdir'] == '' ? '' : $_POST['currentdir'] . '/');
			$targetdir = '_photos/' . $basedir;
			$foldername = trim($_POST['foldername']);
			if ($foldername != '') {
				if (create_folder($targetdir . $foldername)) {
					$messages .= $basedir . $foldername . $lang['create_success'] . '<br/>';
					if (array_key_exists('chdir', $_POST)) {
						$current = $basedir . $foldername;
					}
				} else {
					$messages .= $basedir . $foldername . $lang['create_failed'] . '<br/>';
				}
			}
		}
		if ($messages != '') { $messages .= '<br/>'; }

		load_10($current, $messages);
		break;
	case 'uploadimage':
		// step 1 uploadimage: folder administration
		//
		$messages = '';

		if ($_switch['admin_demo_mode'] == 'ON') {
			$messages .= $lang['simulation_note'];
		} else if (array_key_exists('uploadimagefile', $_FILES)) {
			$nfiles = count($_FILES['uploadimagefile']['name']);
			for ($i=0; $i<$nfiles; $i++) {
				switch ($_FILES['uploadimagefile']['error'][$i])
				{
					case 0:
						$file_ext = substr($_FILES['uploadimagefile']['name'][$i], strlen($_FILES['uploadimagefile']['name'][$i]) -3);
						if ($file_ext == 'jpg') {
							$basedir = ($_POST['currentdir'] == '' ? '' : $_POST['currentdir'] . '/');
							$targetfile = preg_replace("/\s/", "", $_FILES['uploadimagefile']['name'][$i]);
							$targetdir = '_photos/' . $basedir;
							// WIP
							if(@copy($_FILES['uploadimagefile']['tmp_name'][$i], $targetdir . $targetfile)) {
								$messages .= $_FILES['uploadimagefile']['name'][$i] . $lang['upload_success'] . $targetdir . '.<br/>';
							}	else {
								$messages .= $_FILES['uploadimagefile']['name'][$i] . $lang['upload_failed'] . '<br/>';
							}
						} else {
							$messages .= $_FILES['uploadimagefile']['name'][$i] . $lang['image_not_supported'] . '<br/>';
						}
						break;
					case 1:
						$messages .= $_FILES['uploadimagefile']['name'][$i] . $lang['upload_error_01'] . '<br/>';
						break;
					case 2:
						$messages .= $_FILES['uploadimagefile']['name'][$i] . $lang['upload_error_02'] . '<br/>';
						break;
					case 3:
						$messages .= $_FILES['uploadimagefile']['name'][$i] . $lang['upload_error_03'] . '<br/>';
						break;
					case 4:
						// No file was uploaded, not an error.
						$messages .= '';
						break;
					case 6:
						$messages .= $_FILES['uploadimagefile']['name'][$i] . $lang['upload_error_06'] . '<br/>';
						break;
					case 7:
						$messages .= $_FILES['uploadimagefile']['name'][$i] . $lang['upload_error_07'] . '<br/>';
						break;
					default:
						$messages .= $_FILES['uploadimagefile']['name'][$i] . $lang['upload_error_xx'] . '<br/>';
						break;
				}
			}
		}
		if ($messages != '') { $messages .= '<br/>'; }

		load_10($_POST['currentdir'], $messages);
		break;
	case 'uploadvideo':
		// step 1 uploadvideo: folder administration
		// 
		$messages = '';

		if ($_switch['admin_demo_mode'] == 'ON') {
			$messages .= $lang['simulation_note'];
		} else if (array_key_exists('uploadvideofile', $_FILES)) {
			$nfiles = count($_FILES['uploadvideofile']['name']);
			for ($i=0; $i<$nfiles; $i++) {
				switch ($_FILES['uploadvideofile']['error'][$i])
				{
					case 0:
						$file_ext = substr($_FILES['uploadvideofile']['name'][$i], strlen($_FILES['uploadvideofile']['name'][$i]) -3);
						if ($file_ext == 'wmv') {
							$basedir = ($_POST['currentdir'] == '' ? '' : $_POST['currentdir'] . '/');
							$targetfile = preg_replace("/\s/", "", $_FILES['uploadvideofile']['name'][$i]);
							$targetdir = '_photos/' . $basedir;
							// WIP
							if(@copy($_FILES['uploadvideofile']['tmp_name'][$i], $targetdir . $targetfile)) {
								$messages .= $_FILES['uploadvideofile']['name'][$i] . $lang['upload_success'] . $targetdir . '.<br/>';
							}	else {
								$messages .= $_FILES['uploadvideofile']['name'][$i] . $lang['upload_failed'] . '<br/>';
							}
						} else {
							$messages .= $_FILES['uploadvideofile']['name'][$i] . $lang['video_not_supported'] . '<br/>';
						}
						break;
					case 1:
						$messages .= $_FILES['uploadvideofile']['name'][$i] . $lang['upload_error_01'] . '<br/>';
						break;
					case 2:
						$messages .= $_FILES['uploadvideofile']['name'][$i] . $lang['upload_error_08'] . '<br/>';
						break;
					case 3:
						$messages .= $_FILES['uploadvideofile']['name'][$i] . $lang['upload_error_03'] . '<br/>';
						break;
					case 4:
						// No file was uploaded, not an error.
						$messages .= '';
						break;
					case 6:
						$messages .= $_FILES['uploadvideofile']['name'][$i] . $lang['upload_error_06'] . '<br/>';
						break;
					case 7:
						$messages .= $_FILES['uploadvideofile']['name'][$i] . $lang['upload_error_07'] . '<br/>';
						break;
					default:
						$messages .= $_FILES['uploadvideofile']['name'][$i] . $lang['upload_error_xx'] . '<br/>';
						break;
				}
			}
		}
		if ($messages != '') { $messages .= '<br/>'; }

		load_10($_POST['currentdir'], $messages);
		break;
	case 'config':
		// step 2: Configuration for inc files
		//
		$current = curr_dir();

		load_20($current, '');
		break;
	case 'save':
		// step 2 save: inc files
		//
		$thedir = ($_POST['currentdir'] == '' ? '_config/' : '_config/' . $_POST['currentdir'] . '/');
		$messages = '';

		if ($_switch['admin_demo_mode'] == 'ON') {
			$messages .= $lang['simulation_note'];
		} else {
			// config.inc
			$inc = $thedir . 'config.inc';
			$del = (array_key_exists('del_config', $_POST) && $_POST['del_config'] == 'on');
			$create = (array_key_exists('create_config', $_POST) && $_POST['create_config'] == 'on');
			if ($del) {
				$messages .= del_inc($inc);
			}	else if ($create || file_exists($inc)) {
				$messages .= save_config($inc);
			}

			// info.inc
			$inc = $thedir . 'info.inc';
			$del = (array_key_exists('del_info', $_POST) && $_POST['del_info'] == 'on');
			$create = (array_key_exists('create_info', $_POST) && $_POST['create_info'] == 'on');
			if ($del) {
				$messages .= del_inc($inc);
			}	else if ($create || file_exists($inc)) {
				$messages .= save_info($inc, $_POST['currentdir']);
			}

			// filelist.inc
			$inc = $thedir . 'filelist.inc';
			$del = (array_key_exists('del_filelist', $_POST) && $_POST['del_filelist'] == 'on');
			$create = (array_key_exists('create_filelist', $_POST) && $_POST['create_filelist'] == 'on');
			if ($del) {
				$messages .= del_inc($inc);
			}	else if ($create || file_exists($inc)) {
				$messages .= save_filelist($inc);
			}
		}
		if ($messages != '') { $messages .= '<br/>'; }

		load_20($_POST['currentdir'], $messages);

		break;
	case 'list':
		// step 3: file administration
		//
		$current = curr_dir();

		load_30($current, '');
		break;
	case 'update':
		// step 3 update: file administration
		//
		$current = curr_dir();
		$messages = '';
		$updatedimage = FALSE;

		if ($_switch['admin_demo_mode'] == 'ON') {
			$messages .= $lang['simulation_note'];
		} else if (array_key_exists('entry', $_POST)) {
			$debug = import_config($current);
			foreach ($_POST['entry'] as $i => $v) {
				$full_entry = '_photos/' . $i;
				if (is_file($full_entry) && supported_video_format($full_entry)) {
					if ($_POST['globalaction'] == 2 || $_POST['globalaction'] == 3 || $v[action] == 2 ) {
						// Delete the video file
						$messages .= (del_sfile($i) ? $lang['deleted'] . $lang['a_file'] . $full_entry : '<span class="noted">' . $lang['dfailed'] . $lang['a_file'] . $i . '</span>' ) . "<br/>";
					} else {
						if ($_POST['globalaction'] == 1 || $v[action] == 1 ) {
							// Regenerate the video thumbnail
							$j = substr($i,  0, strlen($i)  - 3) . 'jpg';
							$success = create_thumbnail(basename($j), basename($j), dirname($j), $_config['video_thumbnail_width'], $_config['video_thumbnail_height'], $_config['video_thumbnail_frame']);
							$messages .= ($success ? $lang['generated'] . $lang['a_file'] . $i : '<span class="noted">' . $lang['gfailed_0'] . $lang['a_file'] . $i . '</span>' ) . "<br/>";
						}
						$messages .= save_note($i, $v);
					}
				} else if (is_file($full_entry)) {
					if ($_POST['globalaction'] == 2 || $_POST['globalaction'] == 3 || $v[action] == 2 ) {
						// Delete the file
						$messages .= (del_sfile($i) ? $lang['deleted'] . $lang['a_file'] . $full_entry : '<span class="noted">' . $lang['dfailed'] . $lang['a_file'] . $i . '</span>' ) . "<br/>";
					} else {
						if ($_POST['globalaction'] == 1 || $v[action] == 1 ) {
							// Regenerate the image thumbnail
							$success = create_thumbnail(basename($i), basename($i), dirname($i), $_config['thumbnail_width'], $_config['thumbnail_height'], $_config['thumbnail_frame']);
							$messages .= ($success ? $lang['generated'] . $lang['a_file'] . $i : '<span class="noted">' . $lang['gfailed_0'] . $lang['a_file'] . $i . '</span>' ) . "<br/>";
						}
						$messages .= save_note($i, $v);
					}
				} else {
					if ($_POST['globalaction'] == 3 || $v[action] == 2) {
						// Delete the folder
						$messages .= (del_sfolder($i) ? $lang['deleted'] . $lang['a_folder'] . $full_entry : '<span class="noted">' . $lang['dfailed'] . $lang['a_folder'] . $i . '</span>' ) . "<br/>";
					} else if ($_POST['globalaction'] == 1 || $v[action] == 1 ) {
							// Regenerate the image/video thumbnail
							if (read_info($i, 'folder_thumbnail') == '') {
								$messages .= $lang['gfailed_1'] . $lang['a_folder'] . $i . "<br/>";
							} else {
								$success = create_thumbnail(read_info($i, 'folder_thumbnail'), '_thumbnail.jpg', $i, $_config['folder_thumbnail_width'], $_config['folder_thumbnail_height'], $_config['folder_thumbnail_frame']);
								$messages .= ($success ? $lang['generated'] . $lang['a_folder'] . $i : '<span class="noted">' . $lang['gfailed_0'] . $lang['a_folder'] . $i . '</span>' ) . "<br/>";
							}
					}
				}
			}
			migrate_remarks($current);
		}

		if ($updatedimage) { $messages = $lang['update_note'] . '<br/><br/>' . $messages; }
		if ($messages != '') { $messages .= '<br/>'; }

		load_30($current, $messages);
		break;
	default:
	case 'bconfig':
		// step 0: Configuration for branch level coreconfig.inc files
		//
		$current = curr_dir();
		load_00($current, '');

		break;

}

exit();

function curr_dir()
{
	return ($_GET['id'] == ''? (array_key_exists('currentdir', $_POST) ? $_POST['currentdir'] : '' ) : id_decrypt($_GET['id']));
}

// Load pages
//

function load_00($dir, $messages='')
{
	global $_coreconfig;
	
	$found = import_coreconfig($dir);

	$fp = @fopen("_res/admin/step00.html", "r");
	$data = @fread($fp, filesize("_res/admin/step00.html"));
	@fclose($fp);

	// base dir
	//
	$data = preg_replace("/{{currentdir}}/i", $dir, $data);
	if ($_info['folder_thumbnail'] == '') {
		$data = preg_replace("/{{img_thumbnail}}/i", '_res/sources/spacer.png', $data);
	} else {
		$data = preg_replace("/{{img_thumbnail}}/i", '_photos/' . ($dir == '' ? '' : $dir . '/' ) . $_info['folder_thumbnail'], $data);
	}
	
	// Frame samples
	$data = preg_replace("/{{img_thumbframe}}/i",  '_res/frames/' . $_coreconfig['thumbnail_frame'] . '/_sample.jpg', $data);
	$data = preg_replace("/{{img_folderframe}}/i", '_res/frames/' . $_coreconfig['folder_thumbnail_frame'] . '/_sample.jpg', $data);
	$data = preg_replace("/{{img_videoframe}}/i", '_res/frames/' . $_coreconfig['video_thumbnail_frame'] . '/_sample.jpg', $data);

	// create or delete checked box, and the base dir
	//
	$data = preg_replace("/{{messages}}/i", $messages, $data);
	$data = preg_replace("/{{existconfig}}/i", bconfigexistence($dir), $data);
	$data = preg_replace("/{{optionfolder}}/i", optionfolder($dir, '', TRUE), $data);
	$data = preg_replace("/{{sampledfrom}}/i", incfound($dir, 'coreconfig.inc', $found), $data);
	//
	// coreconfig.inc
	//
	$data = preg_replace("/{{optionlanguage}}/i", options('languages', $_coreconfig['language'], 'php'), $data);

	$data = preg_replace("/{{optiontemplate}}/i", options('templates', $_coreconfig['template'], 'html', TRUE), $data);
	$data = preg_replace("/{{optionindexmode}}/i", options('index_modes', $_coreconfig['index_mode'], 'php'), $data);
	$data = preg_replace("/{{optionindexcss}}/i", options('css', $_coreconfig['index_css'], 'css'), $data);
	$data = preg_replace("/{{optionindexbuttons}}/i", options('buttons', $_coreconfig['index_buttons'], '', FALSE), $data);
	$data = preg_replace("/{{optionslidemode}}/i", options('slide_modes', $_coreconfig['slide_mode'], 'php'), $data);
	$data = preg_replace("/{{optionslidecss}}/i", options('css', $_coreconfig['slide_css'], 'css'), $data);
	$data = preg_replace("/{{optionslidebuttons}}/i", options('buttons', $_coreconfig['slide_buttons'], '', FALSE), $data);
	$data = preg_replace("/{{optionthumbcolumn}}/i", optionsnum(1, 1, 15, $_coreconfig['num_column']), $data);
	$data = preg_replace("/{{optionthumbtotal}}/i", optionsnum(1, 1, 50, $_coreconfig['num_total']), $data);
	$data = preg_replace("/{{optionsortmode}}/i", optionsortmode($_coreconfig['sorting']), $data);
	$data = preg_replace("/{{optionshowfilename}}/i", optionyesno($_coreconfig['showfilename']), $data);
	$data = preg_replace("/{{optionshowindex}}/i", optionyesno($_coreconfig['showindex']), $data);
	$data = preg_replace("/{{valuehome}}/i", htmlentities($_coreconfig['home']), $data);
	$data = preg_replace("/{{valuehometitle}}/i", htmlentities($_coreconfig['home_title']), $data);
	$data = preg_replace("/{{valuecopyright}}/i", htmlentities($_coreconfig['copyright']), $data);
	$data = preg_replace("/{{optionthumbwidth}}/i", optionsnum(50, 10, 250, $_coreconfig['thumbnail_width']), $data);
	$data = preg_replace("/{{optionthumbheight}}/i", optionsnum(50, 10, 250, $_coreconfig['thumbnail_height']), $data);
	$data = preg_replace("/{{optionthumbframe}}/i", options('frames', $_coreconfig['thumbnail_frame'], '', FALSE), $data);
	$data = preg_replace("/{{valuethumbframe}}/i", $_coreconfig['thumbnail_frame'], $data);
	$data = preg_replace("/{{optionfolderwidth}}/i", optionsnum(50, 10, 250, $_coreconfig['folder_thumbnail_width']), $data);
	$data = preg_replace("/{{optionfolderheight}}/i", optionsnum(50, 10, 250, $_coreconfig['folder_thumbnail_height']), $data);
	$data = preg_replace("/{{optionfolderframe}}/i", options('frames', $_coreconfig['folder_thumbnail_frame'], '', FALSE), $data);
	$data = preg_replace("/{{valuefolderframe}}/i", $_coreconfig['folder_thumbnail_frame'], $data);
	$data = preg_replace("/{{optionplayerwidth}}/i", optionsnum(180, 15, 630, $_coreconfig['video_player_width']), $data);
	$data = preg_replace("/{{optionplayerheight}}/i", optionsnum(180, 15, 450, $_coreconfig['video_player_height']), $data);
	$data = preg_replace("/{{optionvideowidth}}/i", optionsnum(50, 10, 250, $_coreconfig['video_thumbnail_width']), $data);
	$data = preg_replace("/{{optionvideoheight}}/i", optionsnum(50, 10, 250, $_coreconfig['video_thumbnail_height']), $data);
	$data = preg_replace("/{{optionvideoframe}}/i", options('frames', $_coreconfig['video_thumbnail_frame'], '', FALSE), $data);
	$data = preg_replace("/{{valuevideoframe}}/i", $_coreconfig['video_thumbnail_frame'], $data);

	format_adminpage($data, commandbar(0, $dir));
}

function load_10($dir, $messages='')
{
	$fp = @fopen("_res/admin/step10.html", "r");
	$data = @fread($fp, filesize("_res/admin/step10.html"));
	@fclose($fp);

	$data = preg_replace("/{{currentdir}}/i", $dir, $data);
	$data = preg_replace("/{{messages}}/i", $messages, $data);
	$data = preg_replace("/{{optionfolder}}/i", optionfolder($dir), $data);

	format_adminpage($data, commandbar(10, $dir));
}

function load_20($dir, $messages='')
{
	global $_config, $_info;
	
	$found = import_config($dir);
	import_info($dir);
	
	$fp = @fopen("_res/admin/step20.html", "r");
	$data = @fread($fp, filesize("_res/admin/step20.html"));
	@fclose($fp);

	// base dir
	//
	$data = preg_replace("/{{currentdir}}/i", $dir, $data);
	if ($_info['folder_thumbnail'] == '') {
		$data = preg_replace("/{{img_thumbnail}}/i", '_res/sources/spacer.png', $data);
	} else {
		$data = preg_replace("/{{img_thumbnail}}/i", '_photos/' . ($dir == '' ? '' : $dir . '/' ) . $_info['folder_thumbnail'], $data);
	}
	
	// Frame samples
	$data = preg_replace("/{{img_thumbframe}}/i",  '_res/frames/' . $_config['thumbnail_frame'] . '/_sample.jpg', $data);
	$data = preg_replace("/{{img_folderframe}}/i", '_res/frames/' . $_config['folder_thumbnail_frame'] . '/_sample.jpg', $data);
	$data = preg_replace("/{{img_videoframe}}/i", '_res/frames/' . $_config['video_thumbnail_frame'] . '/_sample.jpg', $data);

	// create or delete checked box, and the base dir
	//
	$data = preg_replace("/{{messages}}/i", $messages, $data);
	$data = preg_replace("/{{existconfig}}/i", configexistence($dir), $data);
	$data = preg_replace("/{{existinfo}}/i", infoexistence($dir), $data);
	$data = preg_replace("/{{existfilelist}}/i", filelistexistence($dir), $data);
	$data = preg_replace("/{{optionfolder}}/i", optionfolder($dir), $data);
	$data = preg_replace("/{{sampledfrom}}/i", incfound($dir, 'config.inc', $found), $data);
	//
	// config.inc
	//
	$data = preg_replace("/{{optionlanguage}}/i", options('languages', $_config['language'], 'php'), $data);

	$data = preg_replace("/{{optiontemplate}}/i", options('templates', $_config['template'], 'html', TRUE), $data);
	$data = preg_replace("/{{optionindexmode}}/i", options('index_modes', $_config['index_mode'], 'php'), $data);
	$data = preg_replace("/{{optionindexcss}}/i", options('css', $_config['index_css'], 'css'), $data);
	$data = preg_replace("/{{optionindexbuttons}}/i", options('buttons', $_config['index_buttons'], '', FALSE), $data);
	$data = preg_replace("/{{optionslidemode}}/i", options('slide_modes', $_config['slide_mode'], 'php'), $data);
	$data = preg_replace("/{{optionslidecss}}/i", options('css', $_config['slide_css'], 'css'), $data);
	$data = preg_replace("/{{optionslidebuttons}}/i", options('buttons', $_config['slide_buttons'], '', FALSE), $data);
	$data = preg_replace("/{{optionthumbcolumn}}/i", optionsnum(1, 1, 15, $_config['num_column']), $data);
	$data = preg_replace("/{{optionthumbtotal}}/i", optionsnum(1, 1, 50, $_config['num_total']), $data);
	$data = preg_replace("/{{optionsortmode}}/i", optionsortmode($_config['sorting']), $data);
	$data = preg_replace("/{{optionshowfilename}}/i", optionyesno($_config['showfilename']), $data);
	$data = preg_replace("/{{optionshowindex}}/i", optionyesno($_config['showindex']), $data);
	$data = preg_replace("/{{valuehome}}/i", htmlentities($_config['home']), $data);
	$data = preg_replace("/{{valuehometitle}}/i", htmlentities($_config['home_title']), $data);
	$data = preg_replace("/{{valuecopyright}}/i", htmlentities($_config['copyright']), $data);
	$data = preg_replace("/{{optionthumbwidth}}/i", optionsnum(50, 10, 250, $_config['thumbnail_width']), $data);
	$data = preg_replace("/{{optionthumbheight}}/i", optionsnum(50, 10, 250, $_config['thumbnail_height']), $data);
	$data = preg_replace("/{{optionthumbframe}}/i", options('frames', $_config['thumbnail_frame'], '', FALSE), $data);
	$data = preg_replace("/{{valuethumbframe}}/i", $_config['thumbnail_frame'], $data);
	$data = preg_replace("/{{optionfolderwidth}}/i", optionsnum(50, 10, 250, $_config['folder_thumbnail_width']), $data);
	$data = preg_replace("/{{optionfolderheight}}/i", optionsnum(50, 10, 250, $_config['folder_thumbnail_height']), $data);
	$data = preg_replace("/{{optionfolderframe}}/i", options('frames', $_config['folder_thumbnail_frame'], '', FALSE), $data);
	$data = preg_replace("/{{valuefolderframe}}/i", $_config['folder_thumbnail_frame'], $data);
	$data = preg_replace("/{{optionplayerwidth}}/i", optionsnum(180, 15, 630, $_config['video_player_width']), $data);
	$data = preg_replace("/{{optionplayerheight}}/i", optionsnum(180, 15, 450, $_config['video_player_height']), $data);
	$data = preg_replace("/{{optionvideowidth}}/i", optionsnum(50, 10, 250, $_config['video_thumbnail_width']), $data);
	$data = preg_replace("/{{optionvideoheight}}/i", optionsnum(50, 10, 250, $_config['video_thumbnail_height']), $data);
	$data = preg_replace("/{{optionvideoframe}}/i", options('frames', $_config['video_thumbnail_frame'], '', FALSE), $data);
	$data = preg_replace("/{{valuevideoframe}}/i", $_config['video_thumbnail_frame'], $data);
	//
	// info.inc
	//
	$data = preg_replace("/{{valuefolderid}}/i", htmlentities($_info['folder_id']), $data);
	$data = preg_replace("/{{valuetitle}}/i", htmlentities($_info['title']), $data);
	$data = preg_replace("/{{valueheader}}/i", formattext($_info['header']), $data);
	$data = preg_replace("/{{valuefooter}}/i", formattext($_info['footer']), $data);
	$data = preg_replace("/{{optionfolderthumbnail}}/i", optionthumbnail($dir), $data);
	//
	// filelist.inc
	//
	$data = preg_replace("/{{valuefilelist}}/i", formatfilelist($dir), $data);
	$data = preg_replace("/{{completefilelist}}/i", completefilelist($dir), $data);

	format_adminpage($data, commandbar(20, $dir));
}

function load_30($dir, $messages='')
{
	global $_config, $_info;

 	$f_flist  = ($dir == '' ? '_config/filelist.inc' : '_config/' . $dir . '/filelist.inc');
 	$f_flist  = (file_exists($f_flist) ? $f_flist : '');

	$f_config = import_config($dir);
	$f_info   = import_info($dir);
	$list = admin_thumbnail_list($dir);

	$fp = @fopen("_res/admin/step30.html", "r");
	$data = @fread($fp, filesize("_res/admin/step30.html"));
	@fclose($fp);

	$data = preg_replace("/{{id}}/i", id_encrypt($dir), $data);
	$data = preg_replace("/{{messages}}/i", $messages, $data);
	$data = preg_replace("/{{route}}/i", admin_routemap($dir), $data);
	$data = preg_replace("/{{list}}/i", admin_index_made($list, $f_config, $f_info, $f_flist), $data);

	format_adminpage($data, commandbar(30, $dir));
}

function formattext($text)
{
	$res = str_replace("\x5c", "\x5c\x5c\x5c", $text);
	$res = str_replace("<br/>", "\r\n", $res);
	
	return $res;
}

function formatfilelist($dir)
{
	
	$filelist = import_filelist($dir);
	$res = '';
	foreach ($filelist as $k => $v) {
		$res .= $v . "\r\n";
	}
	
	return $res;
}

function completefilelist($dir)
{
	$filelist = import_filelist($dir, FALSE);
	$res = '';
	foreach ($filelist as $k => $v) {
		$res .= $v . "\r\n";
	}
	
	return $res;
}

// Check existence of inc file
//

function bconfigexistence($dir)
{
	global $lang;
	
	$file = ($dir == '' ? '_config/coreconfig.inc' : '_config/' . $dir . '/coreconfig.inc');
	if (file_exists($file)) {
		return ' (' . $lang['del_inc'] . '&nbsp;<input type="checkbox" name="del_config" onkeypress="return handleEnter(event, this)"/>)';
	} else {
		return ' (' . $lang['create_inc'] . '&nbsp;<input type="checkbox" name="create_config" onkeypress="return handleEnter(event, this)"/>)';
	}
}

function configexistence($dir)
{
	global $lang;
	
	$file = ($dir == '' ? '_config/config.inc' : '_config/' . $dir . '/config.inc');
	if (file_exists($file)) {
		return ' (' . $lang['del_inc'] . '&nbsp;<input type="checkbox" name="del_config" onkeypress="return handleEnter(event, this)"/>)';
	} else {
		return ' (' . $lang['create_inc'] . '&nbsp;<input type="checkbox" name="create_config" onkeypress="return handleEnter(event, this)"/>)';
	}
}

function infoexistence($dir)
{
	global $lang;
	
	$file = ($dir == '' ? '_config/info.inc' : '_config/' . $dir . '/info.inc');
	if (file_exists($file)) {
		return ' (' . $lang['del_inc'] . '&nbsp;<input type="checkbox" name="del_info" onkeypress="return handleEnter(event, this)"/>)';
	} else {
		return ' (' . $lang['create_inc'] . '&nbsp;<input type="checkbox" name="create_info" onkeypress="return handleEnter(event, this)"/>)';
	}
}

function filelistexistence($dir)
{
	global $lang;
	
	$file = ($dir == '' ? '_config/filelist.inc' : '_config/' . $dir . '/filelist.inc');
	if (file_exists($file)) {
		return ' (' . $lang['del_inc'] . '&nbsp;<input type="checkbox" name="del_filelist" onkeypress="return handleEnter(event, this)"/>)';
	} else {
		return ' (' . $lang['create_inc'] . '&nbsp;<input type="checkbox" name="create_filelist" onkeypress="return handleEnter(event, this)"/>)';
	}
}

// Functions that will retrieve the available options
//

function optionthumbnail($basedir='', $sub='', $level=0)
{
	global $_info, $lang;
	
	$options = '';
	$subdirs = array();

	$load_dir = '_photos' . ($basedir == '' ? '' : '/' . $basedir) . ($sub == '' ? '' : '/' . $sub);
	$dhandle = @opendir($load_dir);
	if ($dhandle) {
		$dir_entry = readdir( $dhandle );
		while ($dir_entry) {
			$base_entry = ($sub == '' ? '' : $sub . '/') . $dir_entry;
			$full_entry = $load_dir . '/' . $dir_entry;
			if (is_file($full_entry) && supported_image_format($full_entry)) {
				$options .= '<option value ="' . $base_entry . '"';
				$options .= ($base_entry == $_info['folder_thumbnail'] ? 'selected="selected"' : '');
				$options .= '>' . $base_entry . '</option>';
			} else if ($level < 2 && is_dir($full_entry) && nothidden_dir($dir_entry)) {
				$subdirs[] = $base_entry;
			}
			$dir_entry = readdir( $dhandle );
		}
	}
	@closedir($dhandle);
	
	foreach ($subdirs as $k => $v) {
		$options .= optionthumbnail($basedir, $v, $level+1);
	}

	if ($level == 0) {
		$options = ($options == '' ? "<option value ='" . $lang['none'] . "'>none available</option>" : "<option value ='" . $lang['none'] . "'>not selected yet</option>" . $options );
	}

	return $options;
}

function options($type, $selection, $ext, $isfile=TRUE)
{
	global $_config;
	
	$options = '';
	$trim = strlen($ext);

	$dhandle = @opendir('_res/' . $type);
	if ($dhandle) {
		$dir_entry = readdir( $dhandle );
		while ($dir_entry) {
			$full_entry = '_res/' . $type . '/' . $dir_entry;
			if ($isfile && is_file($full_entry) && nothidden_file($dir_entry) && substr($dir_entry, -$trim, $trim) == $ext) {
				$key = substr($dir_entry, 0, strlen($dir_entry)-$trim-1);
				$options .= '<option value ="' . $key . '"';
				$options .= ($key == $selection ? 'selected="selected"' : '');
				$options .= '>' . $key . '</option>';
			} else if (!$isfile && is_dir($full_entry) && nothidden_dir($dir_entry)) {
				$key = $dir_entry;
				$options .= '<option value ="' . $key . '"';
				$options .= ($key == $selection ? 'selected="selected"' : '');
				$options .= '>' . $key . '</option>';
			}
			$dir_entry = readdir( $dhandle );
		}
	}
	@closedir($dhandle);

	return $options;
}

function optionsnum($start, $step, $max, $selection)
{
	for ($i=$start; $i<=$max; $i+=$step) {
				$options .= '<option value ="' . $i . '"';
				$options .= ($i == $selection ? 'selected="selected"' : '');
				$options .= '>' . $i . '</option>';
	}

	return $options;
}

function optionsortmode($selection=1)
{
	
	$choice[0] = "dummy";
	$choice[1] = "1 - folders first, then sorted by filename";
	$choice[2] = "2 - folders first, then sorted by filename reversely";
	$choice[3] = "3 - sorted all folders and files by name";
	$choice[4] = "4 - sorted all folders and files by name reversely";
	
	$options = '';
	for ($i=1; $i<count($choice); $i++) {
				$options .= '<option value ="' . $i . '"';
				$options .= ($i == $selection ? 'selected="selected"' : '');
				$options .= '>' . $choice[$i] . '</option>';
	}

	return $options;
}

function optionyesno($selection)
{
	$choice[0] = "yes";
	$choice[1] = "no";
	
	$options = '';
	for ($i=0; $i<count($choice); $i++) {
				$options .= '<option value ="' . $choice[$i] . '"';
				$options .= ($choice[$i] == $selection ? 'selected="selected"' : '');
				$options .= '>' . $choice[$i] . '</option>';
	}

	return $options;
}

// Functions that will save changes or delete files
//

function save_coreconfig($inc)
{
	global $lang;

	$dir = dirname($inc);
	if (create_folder($dir)) {
		$fp = @fopen($inc, "w");
		@fwrite($fp , 'language=' . format4inc($_POST['language']) . "\r\n");
		@fwrite($fp , 'template=' . format4inc($_POST['template']) . "\r\n");
		@fwrite($fp , 'index_mode=' . format4inc($_POST['index_mode']) . "\r\n");
		@fwrite($fp , 'index_css=' . format4inc($_POST['index_css']) . "\r\n");
		@fwrite($fp , 'index_buttons=' . format4inc($_POST['index_buttons']) . "\r\n");
		@fwrite($fp , 'slide_mode=' . format4inc($_POST['slide_mode']) . "\r\n");
		@fwrite($fp , 'slide_css=' . format4inc($_POST['slide_css']) . "\r\n");
		@fwrite($fp , 'slide_buttons=' . format4inc($_POST['slide_buttons']) . "\r\n");
		@fwrite($fp , 'num_column=' . $_POST['num_column'] . "\r\n");
		@fwrite($fp , 'num_total=' . $_POST['num_total'] . "\r\n\r\n");
		@fwrite($fp , 'sorting=' . $_POST['sorting'] . "\r\n");
		@fwrite($fp , 'showfilename=' . $_POST['showfilename'] . "\r\n");
		@fwrite($fp , 'showindex=' . $_POST['showindex'] . "\r\n");
		@fwrite($fp , 'home=' . $_POST['home'] . "\r\n");
		@fwrite($fp , 'home_title=' . format4inc($_POST['home_title']) . "\r\n");
		@fwrite($fp , 'copyright=' . format4inc($_POST['copyright']) . "\r\n\r\n");
		@fwrite($fp , 'thumbnail_width=' . $_POST['thumbnail_width'] . "\r\n");
		@fwrite($fp , 'thumbnail_height=' . $_POST['thumbnail_height'] . "\r\n");
		@fwrite($fp , 'thumbnail_frame=' . $_POST['thumb_frame'] . "\r\n");
		@fwrite($fp , 'folder_thumbnail_width=' . $_POST['folder_thumbnail_width'] . "\r\n");
		@fwrite($fp , 'folder_thumbnail_height=' . $_POST['folder_thumbnail_height'] . "\r\n");
		@fwrite($fp , 'folder_thumbnail_frame=' . $_POST['folder_frame'] . "\r\n");
		@fwrite($fp , 'video_player_width=' . $_POST['video_player_width'] . "\r\n");
		@fwrite($fp , 'video_player_height=' . $_POST['video_player_height'] . "\r\n");
		@fwrite($fp , 'video_thumbnail_width=' . $_POST['video_thumbnail_width'] . "\r\n");
		@fwrite($fp , 'video_thumbnail_height=' . $_POST['video_thumbnail_height'] . "\r\n");
		@fwrite($fp , 'video_thumbnail_frame=' . $_POST['video_frame'] . "\r\n");
		@fclose($fp);
	}

	return (file_exists($inc) ? $lang['updated'] : $lang['ufailed'] ) . $inc . "<br/>";
}

function save_config($inc)
{
	global $lang;

	$dir = dirname($inc);
	if (create_folder($dir)) {
		$fp = @fopen($inc, "w");
		@fwrite($fp , 'language=' . format4inc($_POST['language']) . "\r\n");
		@fwrite($fp , 'template=' . format4inc($_POST['template']) . "\r\n");
		@fwrite($fp , 'index_mode=' . format4inc($_POST['index_mode']) . "\r\n");
		@fwrite($fp , 'index_css=' . format4inc($_POST['index_css']) . "\r\n");
		@fwrite($fp , 'index_buttons=' . format4inc($_POST['index_buttons']) . "\r\n");
		@fwrite($fp , 'slide_mode=' . format4inc($_POST['slide_mode']) . "\r\n");
		@fwrite($fp , 'slide_css=' . format4inc($_POST['slide_css']) . "\r\n");
		@fwrite($fp , 'slide_buttons=' . format4inc($_POST['slide_buttons']) . "\r\n");
		@fwrite($fp , 'num_column=' . $_POST['num_column'] . "\r\n");
		@fwrite($fp , 'num_total=' . $_POST['num_total'] . "\r\n\r\n");
		@fwrite($fp , 'sorting=' . $_POST['sorting'] . "\r\n");
		@fwrite($fp , 'showfilename=' . $_POST['showfilename'] . "\r\n");
		@fwrite($fp , 'showindex=' . $_POST['showindex'] . "\r\n");
		@fwrite($fp , 'home=' . $_POST['home'] . "\r\n");
		@fwrite($fp , 'home_title=' . format4inc($_POST['home_title']) . "\r\n");
		@fwrite($fp , 'copyright=' . format4inc($_POST['copyright']) . "\r\n\r\n");
		@fwrite($fp , 'thumbnail_width=' . $_POST['thumbnail_width'] . "\r\n");
		@fwrite($fp , 'thumbnail_height=' . $_POST['thumbnail_height'] . "\r\n");
		@fwrite($fp , 'thumbnail_frame=' . $_POST['thumb_frame'] . "\r\n");
		@fwrite($fp , 'folder_thumbnail_width=' . $_POST['folder_thumbnail_width'] . "\r\n");
		@fwrite($fp , 'folder_thumbnail_height=' . $_POST['folder_thumbnail_height'] . "\r\n");
		@fwrite($fp , 'folder_thumbnail_frame=' . $_POST['folder_frame'] . "\r\n");
		@fwrite($fp , 'video_player_width=' . $_POST['video_player_width'] . "\r\n");
		@fwrite($fp , 'video_player_height=' . $_POST['video_player_height'] . "\r\n");
		@fwrite($fp , 'video_thumbnail_width=' . $_POST['video_thumbnail_width'] . "\r\n");
		@fwrite($fp , 'video_thumbnail_height=' . $_POST['video_thumbnail_height'] . "\r\n");
		@fwrite($fp , 'video_thumbnail_frame=' . $_POST['video_frame'] . "\r\n");
		@fclose($fp);
	}

	return (file_exists($inc) ? $lang['updated'] : $lang['ufailed'] ) . $inc . "<br/>";
}

function save_info($inc, $path)
{
	global $lang, $_info;
	
	// Import the existing info.inc file
	import_info($path);
	
	// Reopen the inc file for writing
	$dir = dirname($inc);
	if (create_folder($dir)) {
		$fp = @fopen($inc, "w");

		foreach ($_info as $k => $v) {
			$value = (array_key_exists($k, $_POST)? format4inc($_POST[$k]) : $v );
			switch ($k) {
				case 'folder_thumbnail':
					@fwrite($fp , 'folder_thumbnail=' . ($value == $lang['none'] ? '' : $value) . "\r\n");
					break;
				default:
					@fwrite($fp , $k . '=' . format4inc($value) . "\r\n");
			}
		}

		@fclose($fp);
	}

	return (file_exists($inc) ? $lang['updated'] : $lang['ufailed'] ) . $inc . "<br/>";
}

function save_filelist($inc)
{
	global $lang;
	
	$dir = dirname($inc);
	if (create_folder($dir)) {
		$fp = @fopen($inc, "w");
		@fwrite($fp , $_POST['filelist']);
		@fclose($fp);
	}

	return (file_exists($inc) ? $lang['updated'] : $lang['ufailed'] ) . $inc . "<br/>";
}

function del_inc($inc)
{
	global $lang;

	return (del_afile($inc) ? $lang['deleted'] : $lang['dfailed'] ) . $inc . "<br/>";
}

function optionfolder($current_select, $dir='', $root=TRUE)
{
	$i = 0;
	
	if ($dir == '' && $root) {
		$options .= '<option value="" ' . ($current_select == '' ? ' selected="selected"' : '' ) . ">The uppest level folder</option>";
	}

	$load_dir = ($dir == '' ? '_photos' : '_photos/' . $dir);
	$dhandle = @opendir($load_dir);
	if ($dhandle) {
		$dir_entry = readdir( $dhandle );
		while ($dir_entry) {
			$base_entry = ($dir == '' ? $dir_entry : $dir . '/' . $dir_entry);
			$full_entry = '_photos/' . $base_entry;
			if (is_dir($full_entry) && nothidden_dir($dir_entry)) {
				$options .= '<option value ="' . $base_entry . '"';
				$options .= ($base_entry == $current_select ? ' selected="selected"' : '');
				$options .= '>' . $base_entry . '</option>';
				$options  .= optionfolder($current_select, $base_entry, $root);
			}
			$dir_entry = readdir( $dhandle );
		}
	}
	@closedir($dhandle);

	return $options;
}

function incfound($dir, $inc, $found)
{
	global $lang;

	$expected = ($dir == '' ? '_config' : '_config/' . $dir) . '/' . $inc;
	if ($found == $expected) {
		return '';
	} else {
		return ' ' . ($found == '' ? $lang['loadedfrom_00'] : $lang['loadedfrom_01'] . $found);
	}
}

?>
Return current item: CorePHPAlbum