2 // Copyright (C) 2010 Rod Roark <rod@sunsetsystems.com>
4 // This program is free software; you can redistribute it and/or
5 // modify it under the terms of the GNU General Public License
6 // as published by the Free Software Foundation; either version 2
7 // of the License, or (at your option) any later version.
9 require_once("../globals.php");
10 require_once("$srcdir/acl.inc");
11 require_once("$srcdir/formdata.inc.php");
12 require_once("$srcdir/globals.inc.php");
13 require_once("$srcdir/user.inc");
15 if ($_GET['mode'] != "user") {
16 // Check authorization.
17 $thisauth = acl_check('admin', 'super');
18 if (!$thisauth) die(xl('Not authorized'));
21 // If we are saving user_specific globals.
23 if ($_POST['form_save'] && $_GET['mode'] == "user") {
25 foreach ($GLOBALS_METADATA as $grpname => $grparr) {
26 if (in_array($grpname, $USER_SPECIFIC_TABS)) {
27 foreach ($grparr as $fldid => $fldarr) {
28 if (in_array($fldid, $USER_SPECIFIC_GLOBALS)) {
29 list($fldname, $fldtype, $flddef, $flddesc) = $fldarr;
30 $label = "global:".$fldid;
31 if (isset($_POST["form_$i"])) {
32 $fldvalue = trim(strip_escape_custom($_POST["form_$i"]));
33 setUserSetting($label,$fldvalue,$_SESSION['authId'],FALSE);
35 if ( $_POST["toggle_$i"] == "YES" ) {
36 removeUserSetting($label);
43 echo "<script type='text/javascript'>";
44 echo "parent.left_nav.location.reload();";
45 echo "parent.Title.location.reload();";
46 echo "if(self.name=='RTop'){";
47 echo "parent.RTop.location.href='edit_globals.php?mode=user';";
48 echo "parent.RBot.location.reload();";
50 echo "parent.RBot.location.href='edit_globals.php?mode=user';";
51 echo "parent.RTop.location.reload();";
55 // If we are saving main globals.
57 if ($_POST['form_save'] && $_GET['mode'] != "user") {
60 foreach ($GLOBALS_METADATA as $grpname => $grparr) {
61 foreach ($grparr as $fldid => $fldarr) {
62 list($fldname, $fldtype, $flddef, $flddesc) = $fldarr;
63 sqlStatement("DELETE FROM globals WHERE gl_name = '$fldid'");
65 if (substr($fldtype, 0, 2) == 'm_') {
66 if (isset($_POST["form_$i"])) {
68 foreach ($_POST["form_$i"] as $fldvalue) {
69 $fldvalue = formDataCore($fldvalue, true);
70 sqlStatement("INSERT INTO globals ( gl_name, gl_index, gl_value ) " .
71 "VALUES ( '$fldid', '$fldindex', '$fldvalue' )");
77 if (isset($_POST["form_$i"])) {
78 $fldvalue = formData("form_$i", "P", true);
83 sqlStatement("INSERT INTO globals ( gl_name, gl_index, gl_value ) " .
84 "VALUES ( '$fldid', '0', '$fldvalue' )");
90 echo "<script type='text/javascript'>";
91 echo "parent.left_nav.location.reload();";
92 echo "parent.Title.location.reload();";
93 echo "if(self.name=='RTop'){";
94 echo "parent.RTop.location.href='edit_globals.php';";
95 echo "parent.RBot.location.reload();";
97 echo "parent.RBot.location.href='edit_globals.php';";
98 echo "parent.RTop.location.reload();";
105 <?php
html_header_show();?
>
107 <!-- supporting javascript code
-->
108 <script type
="text/javascript" src
="../../library/dialog.js"></script
>
109 <script type
="text/javascript" src
="../../library/js/jquery.1.3.2.js"></script
>
110 <script type
="text/javascript" src
="../../library/js/common.js"></script
>
111 <script type
="text/javascript" src
="../../library/js/fancybox/jquery.fancybox-1.2.6.js"></script
>
112 <link rel
="stylesheet" type
="text/css" href
="../../library/js/fancybox/jquery.fancybox-1.2.6.css" media
="screen" />
114 <link rel
="stylesheet" href
='<?php echo $css_header ?>' type
='text/css'>
115 <?php
if ($_GET['mode'] == "user") { ?
>
116 <title
><?php
xl('User Settings','e'); ?
></title
>
118 <title
><?php
xl('Global Settings','e'); ?
></title
>
122 tr
.head
{ font
-size
:10pt
; background
-color
:#cccccc; text-align:center; }
123 tr
.detail
{ font
-size
:10pt
; }
124 td
{ font
-size
:10pt
; }
125 input
{ font
-size
:10pt
; }
130 <body
class="body_top">
132 <?php
if ($_GET['mode'] == "user") { ?
>
133 <form method
='post' name
='theform' id
='theform' action
='edit_globals.php?mode=user' onsubmit
='return top.restoreSession()'>
135 <form method
='post' name
='theform' id
='theform' action
='edit_globals.php' onsubmit
='return top.restoreSession()'>
138 <?php
if ($_GET['mode'] == "user") { ?
>
139 <p
><b
><?php
xl('Edit User Settings','e'); ?
></b
>
141 <p
><b
><?php
xl('Edit Global Settings','e'); ?
></b
>
147 foreach ($GLOBALS_METADATA as $grpname => $grparr) {
148 if ( $_GET['mode'] != "user" ||
($_GET['mode'] == "user" && in_array($grpname, $USER_SPECIFIC_TABS)) ) {
149 echo " <li" . ($i ?
"" : " class='current'") .
150 "><a href='/play/javascript-tabbed-navigation/'>" .
151 xl($grpname) . "</a></li>\n";
158 <div
class="tabContainer">
161 foreach ($GLOBALS_METADATA as $grpname => $grparr) {
162 if ( $_GET['mode'] != "user" ||
($_GET['mode'] == "user" && in_array($grpname, $USER_SPECIFIC_TABS)) ) {
163 echo " <div class='tab" . ($i ?
"" : " current") .
164 "' style='height:auto;width:97%;'>\n";
168 if ($_GET['mode'] == "user") {
170 echo "<th> </th>";
171 echo "<th>" . htmlspecialchars( xl('User Specific Setting'), ENT_NOQUOTES
) . "</th>";
172 echo "<th>" . htmlspecialchars( xl('Default Setting'), ENT_NOQUOTES
) . "</th>";
173 echo "<th> </th>";
174 echo "<th>" . htmlspecialchars( xl('Set to Default'), ENT_NOQUOTES
) . "</th>";
178 foreach ($grparr as $fldid => $fldarr) {
179 if ( $_GET['mode'] != "user" ||
($_GET['mode'] == "user" && in_array($fldid, $USER_SPECIFIC_GLOBALS)) ) {
180 list($fldname, $fldtype, $flddef, $flddesc) = $fldarr;
182 // Most parameters will have a single value, but some will be arrays.
183 // Here we cater to both possibilities.
184 $glres = sqlStatement("SELECT gl_index, gl_value FROM globals WHERE " .
185 "gl_name = '$fldid' ORDER BY gl_index");
187 while ($glrow = sqlFetchArray($glres)) $glarr[] = $glrow;
189 // $fldvalue is meaningful only for the single-value cases.
190 $fldvalue = count($glarr) ?
$glarr[0]['gl_value'] : $flddef;
192 // Collect user specific setting if mode set to user
194 $settingDefault = "checked='checked'";
195 if ($_GET['mode'] == "user") {
196 $userSettingArray = sqlQuery("SELECT * FROM user_settings WHERE setting_user=? AND setting_label=?",array($_SESSION['authId'],"global:".$fldid));
197 $userSetting = $userSettingArray['setting_value'];
198 $globalValue = $fldvalue;
199 if (!empty($userSetting) ||
$userSetting === "0" ) {
200 $fldvalue = $userSetting;
201 $settingDefault = "";
205 echo " <tr title='$flddesc'><td valign='top'><b>$fldname </b></td><td valign='top'>\n";
207 if (is_array($fldtype)) {
208 echo " <select name='form_$i' id='form_$i'>\n";
209 foreach ($fldtype as $key => $value) {
210 if ($_GET['mode'] == "user") {
211 if ($globalValue == $key) $globalTitle = $value;
213 echo " <option value='$key'";
214 if ($key == $fldvalue) echo " selected";
222 else if ($fldtype == 'bool') {
223 if ($_GET['mode'] == "user") {
224 if ($globalValue == 1) {
225 $globalTitle = htmlspecialchars( xl('Checked'), ENT_NOQUOTES
);
228 $globalTitle = htmlspecialchars( xl('Not Checked'), ENT_NOQUOTES
);
231 echo " <input type='checkbox' name='form_$i' id='form_$i' value='1'";
232 if ($fldvalue) echo " checked";
236 else if ($fldtype == 'num') {
237 if ($_GET['mode'] == "user") {
238 $globalTitle = $globalValue;
240 echo " <input type='text' name='form_$i' id='form_$i' " .
241 "size='6' maxlength='15' value='$fldvalue' />\n";
244 else if ($fldtype == 'text') {
245 if ($_GET['mode'] == "user") {
246 $globalTitle = $globalValue;
248 echo " <input type='text' name='form_$i' id='form_$i' " .
249 "size='50' maxlength='255' value='$fldvalue' />\n";
252 else if ($fldtype == 'pass') {
253 if ($_GET['mode'] == "user") {
254 $globalTitle = $globalValue;
256 echo " <input type='password' name='form_$i' " .
257 "size='50' maxlength='255' value='$fldvalue' />\n";
260 else if ($fldtype == 'lang') {
261 $res = sqlStatement("SELECT * FROM lang_languages ORDER BY lang_description");
262 echo " <select name='form_$i' id='form_$i'>\n";
263 while ($row = sqlFetchArray($res)) {
264 echo " <option value='" . $row['lang_description'] . "'";
265 if ($row['lang_description'] == $fldvalue) echo " selected";
267 echo xl($row['lang_description']);
273 else if ($fldtype == 'm_lang') {
274 $res = sqlStatement("SELECT * FROM lang_languages ORDER BY lang_description");
275 echo " <select multiple name='form_{$i}[]' id='form_{$i}[]' size='3'>\n";
276 while ($row = sqlFetchArray($res)) {
277 echo " <option value='" . $row['lang_description'] . "'";
278 foreach ($glarr as $glrow) {
279 if ($glrow['gl_value'] == $row['lang_description']) {
285 echo xl($row['lang_description']);
291 else if ($fldtype == 'css') {
292 if ($_GET['mode'] == "user") {
293 $globalTitle = $globalValue;
295 $themedir = "$webserver_root/interface/themes";
296 $dh = opendir($themedir);
298 echo " <select name='form_$i' id='form_$i'>\n";
299 while (false !== ($tfname = readdir($dh))) {
300 // Only show files that contain style_ as options
301 // Skip style_blue.css since this is used for
302 // lone scripts such as setup.php
303 if (!preg_match("/^style_.*\.css$/", $tfname) ||
$tfname == 'style_blue.css') { continue; }
304 echo "<option value='$tfname'";
305 if ($tfname == $fldvalue) echo " selected";
315 else if ($fldtype == 'hour') {
316 if ($_GET['mode'] == "user") {
317 $globalTitle = $globalValue;
319 echo " <select name='form_$i' id='form_$i'>\n";
320 for ($h = 0; $h < 24; ++
$h) {
321 echo "<option value='$h'";
322 if ($h == $fldvalue) echo " selected";
324 if ($h == 0) echo "12 AM";
325 else if ($h < 12) echo "$h AM";
326 else if ($h == 12) echo "12 PM";
327 else echo ($h - 12) . " PM";
332 if ($_GET['mode'] == "user") {
334 echo "<td align='center' style='color:red;'>" . $globalTitle . "</td>\n";
335 echo "<td> </td>";
336 echo "<td align='center'><input type='checkbox' value='YES' name='toggle_" . $i . "' id='toggle_" . $i . "' " . $settingDefault . "/></td>\n";
337 echo "<input type='hidden' id='globaldefault_" . $i . "' value='" . $globalValue . "'>\n";
341 echo " </td></tr>\n";
354 <input type
='submit' name
='form_save' value
='<?php xl('Save
','e
'); ?>' />
362 <script language
="JavaScript">
364 $
(document
).ready(function(){
368 // Use the counter ($i) to make the form user friendly for user-specific globals use
369 <?php
if ($_GET['mode'] == "user") { ?
>
370 <?php
for ($j = 0; $j <= $i; $j++
) { ?
>
371 $
("#form_<?php echo $j ?>").change(function() {
372 $
("#toggle_<?php echo $j ?>").attr('checked',false);
374 $
("#toggle_<?php echo $j ?>").change(function() {
375 if ($
('#toggle_<?php echo $j ?>').attr('checked')) {
376 var defaultGlobal
= $
("#globaldefault_<?php echo $j ?>").val();
377 $
("#form_<?php echo $j ?>").val(defaultGlobal
);