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");
14 require_once("$srcdir/classes/CouchDB.class.php");
16 if ($_GET['mode'] != "user") {
17 // Check authorization.
18 $thisauth = acl_check('admin', 'super');
19 if (!$thisauth) die(xl('Not authorized'));
22 function checkCreateCDB(){
23 $globalsres = sqlStatement("SELECT gl_name, gl_index, gl_value FROM globals WHERE gl_name IN
24 ('couchdb_host','couchdb_user','couchdb_pass','couchdb_port','couchdb_dbase','document_storage_method')");
26 while($globalsrow = sqlFetchArray($globalsres)){
27 $GLOBALS[$globalsrow['gl_name']] = $globalsrow['gl_value'];
29 $directory_created = false;
30 if($GLOBALS['document_storage_method'] != 0){
31 // /documents/temp/ folder is required for CouchDB
32 if(!is_dir($GLOBALS['OE_SITE_DIR'] . '/documents/temp/')){
33 $directory_created = mkdir($GLOBALS['OE_SITE_DIR'] . '/documents/temp/',0777,true);
34 if(!$directory_created){
35 echo htmlspecialchars( xl("Failed to create temporary folder. CouchDB will not work."),ENT_NOQUOTES
);
38 $couch = new CouchDB();
39 if(!$couch->check_connection()) {
40 echo "<script type='text/javascript'>alert('".addslashes(xl("CouchDB Connection Failed."))."');</script>";
43 if($GLOBALS['couchdb_host'] ||
$GLOBALS['couchdb_port'] ||
$GLOBALS['couchdb_dbase']){
44 $couch->createDB($GLOBALS['couchdb_dbase']);
45 $couch->createView($GLOBALS['couchdb_dbase']);
59 // If we are saving user_specific globals.
61 if ($_POST['form_save'] && $_GET['mode'] == "user") {
63 foreach ($GLOBALS_METADATA as $grpname => $grparr) {
64 if (in_array($grpname, $USER_SPECIFIC_TABS)) {
65 foreach ($grparr as $fldid => $fldarr) {
66 if (in_array($fldid, $USER_SPECIFIC_GLOBALS)) {
67 list($fldname, $fldtype, $flddef, $flddesc) = $fldarr;
68 $label = "global:".$fldid;
69 if (isset($_POST["form_$i"])) {
70 $fldvalue = trim(strip_escape_custom($_POST["form_$i"]));
71 setUserSetting($label,$fldvalue,$_SESSION['authId'],FALSE);
73 if ( $_POST["toggle_$i"] == "YES" ) {
74 removeUserSetting($label);
81 echo "<script type='text/javascript'>";
82 echo "parent.left_nav.location.reload();";
83 echo "parent.Title.location.reload();";
84 echo "if(self.name=='RTop'){";
85 echo "parent.RBot.location.reload();";
87 echo "parent.RTop.location.reload();";
89 echo "self.location.href='edit_globals.php?mode=user&unique=yes';";
93 // If we are saving main globals.
95 if ($_POST['form_save'] && $_GET['mode'] != "user") {
98 foreach ($GLOBALS_METADATA as $grpname => $grparr) {
99 foreach ($grparr as $fldid => $fldarr) {
100 list($fldname, $fldtype, $flddef, $flddesc) = $fldarr;
101 if($fldtype == 'pwd'){
102 $pass = sqlQuery("SELECT gl_value FROM globals WHERE gl_name = '$fldid'");
103 $fldvalueold = $pass['gl_value'];
105 sqlStatement("DELETE FROM globals WHERE gl_name = '$fldid'");
107 if (substr($fldtype, 0, 2) == 'm_') {
108 if (isset($_POST["form_$i"])) {
110 foreach ($_POST["form_$i"] as $fldvalue) {
111 $fldvalue = formDataCore($fldvalue, true);
112 sqlStatement("INSERT INTO globals ( gl_name, gl_index, gl_value ) " .
113 "VALUES ( '$fldid', '$fldindex', '$fldvalue' )");
119 if (isset($_POST["form_$i"])) {
120 $fldvalue = formData("form_$i", "P", true);
126 $fldvalue = $fldvalue ?
SHA1($fldvalue) : $fldvalueold;
128 sqlStatement("INSERT INTO globals ( gl_name, gl_index, gl_value ) " .
129 "VALUES ( '$fldid', '0', '$fldvalue' )");
137 echo "<script type='text/javascript'>";
138 echo "parent.left_nav.location.reload();";
139 echo "parent.Title.location.reload();";
140 echo "if(self.name=='RTop'){";
141 echo "parent.RBot.location.reload();";
143 echo "parent.RTop.location.reload();";
145 echo "self.location.href='edit_globals.php?unique=yes';";
150 <!-- supporting javascript code
-->
151 <script type
="text/javascript" src
="../../library/dialog.js"></script
>
152 <script type
="text/javascript" src
="../../library/js/jquery.1.3.2.js"></script
>
153 <script type
="text/javascript" src
="../../library/js/common.js"></script
>
154 <script type
="text/javascript" src
="../../library/js/fancybox/jquery.fancybox-1.2.6.js"></script
>
155 <link rel
="stylesheet" type
="text/css" href
="../../library/js/fancybox/jquery.fancybox-1.2.6.css" media
="screen" />
157 <link rel
="stylesheet" href
='<?php echo $css_header ?>' type
='text/css'>
158 <?php
if ($_GET['mode'] == "user") { ?
>
159 <title
><?php
xl('User Settings','e'); ?
></title
>
161 <title
><?php
xl('Global Settings','e'); ?
></title
>
165 tr
.head
{ font
-size
:10pt
; background
-color
:#cccccc; text-align:center; }
166 tr
.detail
{ font
-size
:10pt
; }
167 td
{ font
-size
:10pt
; }
168 input
{ font
-size
:10pt
; }
173 <body
class="body_top">
175 <?php
if ($_GET['mode'] == "user") { ?
>
176 <form method
='post' name
='theform' id
='theform' action
='edit_globals.php?mode=user' onsubmit
='return top.restoreSession()'>
178 <form method
='post' name
='theform' id
='theform' action
='edit_globals.php' onsubmit
='return top.restoreSession()'>
181 <?php
if ($_GET['mode'] == "user") { ?
>
182 <p
><b
><?php
xl('Edit User Settings','e'); ?
></b
>
184 <p
><b
><?php
xl('Edit Global Settings','e'); ?
></b
>
190 foreach ($GLOBALS_METADATA as $grpname => $grparr) {
191 if ( $_GET['mode'] != "user" ||
($_GET['mode'] == "user" && in_array($grpname, $USER_SPECIFIC_TABS)) ) {
192 echo " <li" . ($i ?
"" : " class='current'") .
193 "><a href='/play/javascript-tabbed-navigation/'>" .
194 xl($grpname) . "</a></li>\n";
201 <div
class="tabContainer">
204 foreach ($GLOBALS_METADATA as $grpname => $grparr) {
205 if ( $_GET['mode'] != "user" ||
($_GET['mode'] == "user" && in_array($grpname, $USER_SPECIFIC_TABS)) ) {
206 echo " <div class='tab" . ($i ?
"" : " current") .
207 "' style='height:auto;width:97%;'>\n";
211 if ($_GET['mode'] == "user") {
213 echo "<th> </th>";
214 echo "<th>" . htmlspecialchars( xl('User Specific Setting'), ENT_NOQUOTES
) . "</th>";
215 echo "<th>" . htmlspecialchars( xl('Default Setting'), ENT_NOQUOTES
) . "</th>";
216 echo "<th> </th>";
217 echo "<th>" . htmlspecialchars( xl('Set to Default'), ENT_NOQUOTES
) . "</th>";
221 foreach ($grparr as $fldid => $fldarr) {
222 if ( $_GET['mode'] != "user" ||
($_GET['mode'] == "user" && in_array($fldid, $USER_SPECIFIC_GLOBALS)) ) {
223 list($fldname, $fldtype, $flddef, $flddesc) = $fldarr;
225 // Most parameters will have a single value, but some will be arrays.
226 // Here we cater to both possibilities.
227 $glres = sqlStatement("SELECT gl_index, gl_value FROM globals WHERE " .
228 "gl_name = '$fldid' ORDER BY gl_index");
230 while ($glrow = sqlFetchArray($glres)) $glarr[] = $glrow;
232 // $fldvalue is meaningful only for the single-value cases.
233 $fldvalue = count($glarr) ?
$glarr[0]['gl_value'] : $flddef;
235 // Collect user specific setting if mode set to user
237 $settingDefault = "checked='checked'";
238 if ($_GET['mode'] == "user") {
239 $userSettingArray = sqlQuery("SELECT * FROM user_settings WHERE setting_user=? AND setting_label=?",array($_SESSION['authId'],"global:".$fldid));
240 $userSetting = $userSettingArray['setting_value'];
241 $globalValue = $fldvalue;
242 if (!empty($userSetting) ||
$userSetting === "0" ) {
243 $fldvalue = $userSetting;
244 $settingDefault = "";
248 echo " <tr title='$flddesc'><td valign='top'><b>$fldname </b></td><td valign='top'>\n";
250 if (is_array($fldtype)) {
251 echo " <select name='form_$i' id='form_$i'>\n";
252 foreach ($fldtype as $key => $value) {
253 if ($_GET['mode'] == "user") {
254 if ($globalValue == $key) $globalTitle = $value;
256 echo " <option value='$key'";
257 if ($key == $fldvalue) echo " selected";
265 else if ($fldtype == 'bool') {
266 if ($_GET['mode'] == "user") {
267 if ($globalValue == 1) {
268 $globalTitle = htmlspecialchars( xl('Checked'), ENT_NOQUOTES
);
271 $globalTitle = htmlspecialchars( xl('Not Checked'), ENT_NOQUOTES
);
274 echo " <input type='checkbox' name='form_$i' id='form_$i' value='1'";
275 if ($fldvalue) echo " checked";
279 else if ($fldtype == 'num') {
280 if ($_GET['mode'] == "user") {
281 $globalTitle = $globalValue;
283 echo " <input type='text' name='form_$i' id='form_$i' " .
284 "size='6' maxlength='15' value='$fldvalue' />\n";
287 else if ($fldtype == 'text') {
288 if ($_GET['mode'] == "user") {
289 $globalTitle = $globalValue;
291 echo " <input type='text' name='form_$i' id='form_$i' " .
292 "size='50' maxlength='255' value='$fldvalue' />\n";
294 else if ($fldtype == 'pwd') {
295 if ($_GET['mode'] == "user") {
296 $globalTitle = $globalValue;
298 echo " <input type='password' name='form_$i' " .
299 "size='50' maxlength='255' value='' />\n";
302 else if ($fldtype == 'pass') {
303 if ($_GET['mode'] == "user") {
304 $globalTitle = $globalValue;
306 echo " <input type='password' name='form_$i' " .
307 "size='50' maxlength='255' value='$fldvalue' />\n";
310 else if ($fldtype == 'lang') {
311 $res = sqlStatement("SELECT * FROM lang_languages ORDER BY lang_description");
312 echo " <select name='form_$i' id='form_$i'>\n";
313 while ($row = sqlFetchArray($res)) {
314 echo " <option value='" . $row['lang_description'] . "'";
315 if ($row['lang_description'] == $fldvalue) echo " selected";
317 echo xl($row['lang_description']);
323 else if ($fldtype == 'm_lang') {
324 $res = sqlStatement("SELECT * FROM lang_languages ORDER BY lang_description");
325 echo " <select multiple name='form_{$i}[]' id='form_{$i}[]' size='3'>\n";
326 while ($row = sqlFetchArray($res)) {
327 echo " <option value='" . $row['lang_description'] . "'";
328 foreach ($glarr as $glrow) {
329 if ($glrow['gl_value'] == $row['lang_description']) {
335 echo xl($row['lang_description']);
341 else if ($fldtype == 'css') {
342 if ($_GET['mode'] == "user") {
343 $globalTitle = $globalValue;
345 $themedir = "$webserver_root/interface/themes";
346 $dh = opendir($themedir);
348 echo " <select name='form_$i' id='form_$i'>\n";
349 while (false !== ($tfname = readdir($dh))) {
350 // Only show files that contain style_ as options
351 // Skip style_blue.css since this is used for
352 // lone scripts such as setup.php
353 if (!preg_match("/^style_.*\.css$/", $tfname) ||
$tfname == 'style_blue.css') { continue; }
354 echo "<option value='$tfname'";
355 if ($tfname == $fldvalue) echo " selected";
365 else if ($fldtype == 'hour') {
366 if ($_GET['mode'] == "user") {
367 $globalTitle = $globalValue;
369 echo " <select name='form_$i' id='form_$i'>\n";
370 for ($h = 0; $h < 24; ++
$h) {
371 echo "<option value='$h'";
372 if ($h == $fldvalue) echo " selected";
374 if ($h == 0) echo "12 AM";
375 else if ($h < 12) echo "$h AM";
376 else if ($h == 12) echo "12 PM";
377 else echo ($h - 12) . " PM";
382 if ($_GET['mode'] == "user") {
384 echo "<td align='center' style='color:red;'>" . $globalTitle . "</td>\n";
385 echo "<td> </td>";
386 echo "<td align='center'><input type='checkbox' value='YES' name='toggle_" . $i . "' id='toggle_" . $i . "' " . $settingDefault . "/></td>\n";
387 echo "<input type='hidden' id='globaldefault_" . $i . "' value='" . $globalValue . "'>\n";
391 echo " </td></tr>\n";
404 <input type
='submit' name
='form_save' value
='<?php xl('Save
','e
'); ?>' />
412 <script language
="JavaScript">
414 $
(document
).ready(function(){
418 // Use the counter ($i) to make the form user friendly for user-specific globals use
419 <?php
if ($_GET['mode'] == "user") { ?
>
420 <?php
for ($j = 0; $j <= $i; $j++
) { ?
>
421 $
("#form_<?php echo $j ?>").change(function() {
422 $
("#toggle_<?php echo $j ?>").attr('checked',false);
424 $
("#toggle_<?php echo $j ?>").change(function() {
425 if ($
('#toggle_<?php echo $j ?>').attr('checked')) {
426 var defaultGlobal
= $
("#globaldefault_<?php echo $j ?>").val();
427 $
("#form_<?php echo $j ?>").val(defaultGlobal
);