Location: PHPKode > projects > TVEz - Media Library > tvez-0.2.1/html/user/prefs.php
<?php
# ------------------------------------------------------------------------------
#
# This file contains the user preference functionality
# Cookies are used to store the preferences
#
# ------------------------------------------------------------------------------
#
# Copyright (C) 2003 Christian Eheim and Alex Pachikov
#
# This file is part of TVEz (tvez.sourceforge.net).
#
# TVEz is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# TVEz is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with TVEz; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
#
# ------------------------------------------------------------------------------
#
# Created on 02/12/2003 by Christian Eheim (hide@address.com)
#
# LAST MODIFIED:
# $Date: 2004/02/09 04:52:01 $
# $Revision: 1.10 $
# $Author: eheim $
#
# ------------------------------------------------------------------------------

$MYTHEME = get_theme();
$MYLANG = get_lang();
require "user/user_globals.inc";

if (isset($_REQUEST['setprefs'])) {
	$_SESSION['tvezTheme'] = $_REQUEST['theme'];
	$_SESSION['tvezLang'] = $_REQUEST['language'];
	$_SESSION['tvezMenu'] = $_REQUEST['menulocation'];
	$_SESSION['tvezLatest'] = $_REQUEST['newadditions'];

	if ($_REQUEST['selected_portlets']) {
		$_SESSION['tvezMoviePortlets'] = $_REQUEST['selected_portlets'];
	} else {
		$_SESSION['tvezMoviePortlets'] = array();
	}

	list($page,$query) = split("\?",$_REQUEST['referer'],2);
	echo '
		<script type="text/javascript">
		// <!--
		if (self != top)
		   top.location.replace("index.php?'.$query.'");
		else
		   document.location.replace("index.php?'.$query.'");
		// -->
		</script>
	';
	exit;
}

#require "locale/localize.php";
#$TRANSLATED_TEXT = get_translation("locale/languages");
#$MYTHEME = (isset($_SESSION['tvezTheme'])) ? $_SESSION['tvezTheme'] : "default";
#$MYLANG = get_lang();


# Get the available themes
$themes = array();
$dh = opendir("themes");
while ($dir = readdir($dh)) {
	if ( preg_match("/(^\.|^CVS$|^lost\+)/i",$dir) )
		continue;
	if (is_dir("themes/$dir"))
		array_push($themes,$dir);
}

# Get the available languages
$langs = array();
$dh = opendir("locale/languages");
while ($file = readdir($dh)) {
	if ( preg_match("/(^\.|^CVS$|^lost\+|template$)/i",$file) )
		continue;
	if ( is_dir("locale/languages/$file")) {
#		list($dic,$lang) = split("\.",$file);
		array_push($langs,$file);
	}
}

# Valid menu positions
$menuLocs = array(
	"right"		=> localize_string("right"),
	"left"		=> localize_string("left")
	);

$referer = $_SERVER['HTTP_REFERER'];

echo '
	<br><br>
	<form method="POST" action="'.$_SERVER['PHP_SELF'].'" name="prefs">
	<input type="hidden" name="content" value="user">
	<input type="hidden" name="page" value="prefs">
	<input type="hidden" name="referer" value="'.$referer.'">
	<table align="center" border="0">
		<tr>
			<td colspan="2" align="center">
	<h1>'.localize_string("User Preferences").'</h1>
			</td>
		</tr>
		<tr>
			<td colspan="2" align="center">
	COOKIES! '.localize_string("For this to work you must have cookies enabled in your browser").' COOKIES!
	<br><br>
			</td>
		</tr>

		<tr>
			<td align="right">
	<b><a href="tvez.php?content=user&page=profile">'.localize_string("Edit your Profile").'</a></b>&nbsp;&nbsp;
			</td>
			<td>
			</td>
		</tr>
		<tr>
			<td align="right">
	'.localize_string("Select your theme").'&nbsp;&nbsp;
			</td>
			<td>
	<select name="theme">
		';
		foreach ($themes as $theme) {
			if ($MYTHEME == $theme)
				echo "<option value=\"$theme\" selected>$theme</option>\n";
			else
				echo "<option value=\"$theme\">$theme</option>\n";
		}
		echo '
	</select>
			</td>
		</tr>
		<tr>
			<td align="right">
	'.localize_string("Select your language").'&nbsp;&nbsp;
			</td>
			<td>
	<select name="language">
		';
		foreach ($langs as $lang) {
			if ($MYLANG == $lang)
				echo "<option value=\"$lang\" selected>$lang</option>\n";
			else
				echo "<option value=\"$lang\">$lang</option>\n";
		}
		echo '
	</select>
			</td>
		</tr>
		<tr>
			<td align="right">
	'.localize_string("Select the menu position").'&nbsp;&nbsp;
			</td>
			<td>
	<select name="menulocation">
		';
		foreach ($menuLocs as $key => $value) {
			if ($_SESSION['tvezMenu'] == $key)
				echo "<option value=\"$key\" selected>$value</option>\n";
			else
				echo "<option value=\"$key\">$value</option>\n";
		}
	echo '
	</select>
			</td>
		</tr>
		<tr>
			<td align="center" colspan="2">
			<br><h2>'.localize_string("Movie Front Page").'</h2>
			</td>
		</tr>
		<tr>
			<td align="right">
	'.localize_string("New Additions").'&nbsp;&nbsp;
			</td>
			<td>
	<select name="newadditions">
		';
		for ($latest=3;$latest<16;$latest++) {
			if ( ($_SESSION['tvezLatest'] == $latest) || 
					( !isset($_SESSION['tvezLatest']) && $latest==5 ) )
				echo "<option value=\"$latest\" selected>$latest</option>\n";
			else
				echo "<option value=\"$latest\">$latest</option>\n";
		}
		echo '
	</select>
			</td>
		</tr>
		<tr>
			<td align="right">
	'.localize_string("Movie Portlets").'&nbsp;&nbsp;
			</td>
			<td>
	<a href="javascript:restore_defaults(document.prefs);">'.localize_string("Restore Defaults").'</a>
			</td>
		</tr>
		<tr>
			<td align="right" colspan="2">
			';
			?>

			<script language="javascript">
			// <!--
			function restore_defaults(form) {
				var defaults = new Array (
					<?php
					foreach ($defaultMoviePortlets as $portlet) {
						echo '"'.$portlet.'"';
						if ($portlet != end($defaultMoviePortlets))	echo ',';
					}
					?>
				);
				del_portlets(form.elements['selected_portlets[]'],form.available_portlets);
				for (var i=0; i<defaults.length; i++) {
					for (var j=0; j<form.available_portlets.length; j++) {
						if (form.available_portlets[j].value == defaults[i]) {
							form.available_portlets[j].selected = true;
							move_portlet(form.available_portlets,form.elements['selected_portlets[]']);
						}
					}
				}
			}
			function move_portlet(src,dest) {
				for (var i=0; i<src.length; i++) {
					if (src[i].selected) {
						if (src[i].value != '') {
							dest.options.add(new Option(src[i].text,src[i].value) );
							src.options[i] = null;
							i--;
						}
					}
				}
			}
			function del_portlets(src,dest) {
				sel_portlets(src);
				move_portlet(src,dest);
			}
			function sel_portlets(src) {
				for (var i=0; i<src.length; i++) {
					if (src[i].value != '')
						src[i].selected = true;
				}
			}
			function swap_options(src,from,to) {
				var obj = src.options;
				var fromSelected = obj[from].selected;
				var toSelected = obj[to].selected;
				var temp = new Option(obj[from].text, obj[from].value, obj[from].defaultSelected, obj[from].selected);
				var temp2= new Option(obj[to].text, obj[to].value, obj[to].defaultSelected, obj[to].selected);
				obj[from] = temp2;
				obj[to] = temp;
				obj[from].selected = toSelected;
				obj[to].selected = fromSelected;
			}
			function move_up(src) {
				for (i=0; i<src.options.length; i++) { 
					if( src.options[i].selected) {
						if(i > 1 && !src.options[i-1].selected) {
							swap_options(src,i,i-1);
							src.options[i-1].selected = true;
						}
					}
				}
			}
			function move_down(src) {
				for(i=src.options.length-1; i>0; i--) {
					if(src.options[i].selected) {
						if(i !=(src.options.length-1) && ! src.options[i+1].selected) {
							swap_options(src,i,i+1);
							src.options[i+1].selected = true;
						}
					}
				}
			}
			// -->
			</script>

			<?php
			echo '
			<table><tr><td>
			<select name="available_portlets" size="10" multiple="yes">
			<option value=""> ----- Available Portlets ----- </option>
				';
			if (isset($_SESSION['tvezMoviePortlets'])) {
				foreach ($moviePortlets as $key => $value) {
					if (! in_array($key,$_SESSION['tvezMoviePortlets']))
						echo '<option value="'.$key.'">'.$value.'</option>';
				}
			} else {
				foreach ($moviePortlets as $key => $value) {
					if (! in_array($key,$defaultMoviePortlets))
						echo '<option value="'.$key.'">'.$value.'</option>';
				}
			}
				echo '
			</select>
			</td>
			<td align="center" valign="middle">
			<input type="button" value="--&gt;" onclick="javascript:move_portlet(this.form.available_portlets,this.form.elements[\'selected_portlets[]\'])"><br><input type="button" value="&lt;--" onclick="javascript:move_portlet(this.form.elements[\'selected_portlets[]\'],this.form.available_portlets)">
			</td>
			<td align="right">
			<select name="selected_portlets[]" size="10" multiple="yes">
			<option value=""> ----- Selected Portlets ----- </option>
				';
			if (isset($_SESSION['tvezMoviePortlets'])) {
				foreach ($_SESSION['tvezMoviePortlets'] as $key) {
					echo '<option value="'.$key.'">'.$moviePortlets[$key].'</option>';
				}
			} else {
				foreach ($defaultMoviePortlets as $key) {
					echo '<option value="'.$key.'">'.$moviePortlets[$key].'</option>';
				}
			}
				echo '
			</select>
			</td></tr>
		<tr>
			<td colspan="3" align="right">
<input type="button" value="Delete All" onclick="javascript:del_portlets(this.form.elements[\'selected_portlets[]\'],this.form.available_portlets)">
			</td>
		</tr>
		<tr>
			<td colspan="3" align="right">
 <input type="button" value="Move Up" onclick="javascript:move_up(this.form.elements[\'selected_portlets[]\'])">
<input type="button" value="Move Down" onclick="javascript:move_down(this.form.elements[\'selected_portlets[]\'])">
			</td>
		</tr>
			</table>
			</td>
		<tr>
			<td colspan="2" align="right">
	<br>
	<input type="submit" name="setprefs" value="'.localize_string("Set Preferences").'" onclick="javascript:return sel_portlets(this.form.elements[\'selected_portlets[]\'])">
			</td>
		</tr>
	</table>
	</form>
	';
?>
Return current item: TVEz - Media Library