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 $fldvalue = trim(strip_escape_custom($_POST["form_$i"]));
70 setUserSetting($label,$fldvalue,$_SESSION['authId'],FALSE);
71 if ( $_POST["toggle_$i"] == "YES" ) {
72 removeUserSetting($label);
79 echo "<script type='text/javascript'>";
80 echo "parent.left_nav.location.reload();";
81 echo "parent.Title.location.reload();";
82 echo "if(self.name=='RTop'){";
83 echo "parent.RBot.location.reload();";
85 echo "parent.RTop.location.reload();";
87 echo "self.location.href='edit_globals.php?mode=user&unique=yes';";
91 // If we are saving main globals.
93 if ($_POST['form_save'] && $_GET['mode'] != "user") {
96 foreach ($GLOBALS_METADATA as $grpname => $grparr) {
97 foreach ($grparr as $fldid => $fldarr) {
98 list($fldname, $fldtype, $flddef, $flddesc) = $fldarr;
99 if($fldtype == 'pwd'){
100 $pass = sqlQuery("SELECT gl_value FROM globals WHERE gl_name = '$fldid'");
101 $fldvalueold = $pass['gl_value'];
103 sqlStatement("DELETE FROM globals WHERE gl_name = '$fldid'");
105 if (substr($fldtype, 0, 2) == 'm_') {
106 if (isset($_POST["form_$i"])) {
108 foreach ($_POST["form_$i"] as $fldvalue) {
109 $fldvalue = formDataCore($fldvalue, true);
110 sqlStatement("INSERT INTO globals ( gl_name, gl_index, gl_value ) " .
111 "VALUES ( '$fldid', '$fldindex', '$fldvalue' )");
117 if (isset($_POST["form_$i"])) {
118 $fldvalue = formData("form_$i", "P", true);
124 $fldvalue = $fldvalue ?
SHA1($fldvalue) : $fldvalueold;
126 sqlStatement("INSERT INTO globals ( gl_name, gl_index, gl_value ) " .
127 "VALUES ( '$fldid', '0', '$fldvalue' )");
135 echo "<script type='text/javascript'>";
136 echo "parent.left_nav.location.reload();";
137 echo "parent.Title.location.reload();";
138 echo "if(self.name=='RTop'){";
139 echo "parent.RBot.location.reload();";
141 echo "parent.RTop.location.reload();";
143 echo "self.location.href='edit_globals.php?unique=yes';";
148 <!-- supporting javascript code
-->
149 <script type
="text/javascript" src
="../../library/dialog.js"></script
>
150 <script type
="text/javascript" src
="../../library/js/jquery.1.3.2.js"></script
>
151 <script type
="text/javascript" src
="../../library/js/common.js"></script
>
152 <script type
="text/javascript" src
="../../library/js/fancybox/jquery.fancybox-1.2.6.js"></script
>
153 <link rel
="stylesheet" type
="text/css" href
="../../library/js/fancybox/jquery.fancybox-1.2.6.css" media
="screen" />
155 <link rel
="stylesheet" href
='<?php echo $css_header ?>' type
='text/css'>
156 <?php
if ($_GET['mode'] == "user") { ?
>
157 <title
><?php
xl('User Settings','e'); ?
></title
>
159 <title
><?php
xl('Global Settings','e'); ?
></title
>
163 tr
.head
{ font
-size
:10pt
; background
-color
:#cccccc; text-align:center; }
164 tr
.detail
{ font
-size
:10pt
; }
165 td
{ font
-size
:10pt
; }
166 input
{ font
-size
:10pt
; }
171 <body
class="body_top">
173 <?php
if ($_GET['mode'] == "user") { ?
>
174 <form method
='post' name
='theform' id
='theform' action
='edit_globals.php?mode=user' onsubmit
='return top.restoreSession()'>
176 <form method
='post' name
='theform' id
='theform' action
='edit_globals.php' onsubmit
='return top.restoreSession()'>
179 <?php
if ($_GET['mode'] == "user") { ?
>
180 <p
><b
><?php
xl('Edit User Settings','e'); ?
></b
>
182 <p
><b
><?php
xl('Edit Global Settings','e'); ?
></b
>
188 foreach ($GLOBALS_METADATA as $grpname => $grparr) {
189 if ( $_GET['mode'] != "user" ||
($_GET['mode'] == "user" && in_array($grpname, $USER_SPECIFIC_TABS)) ) {
190 echo " <li" . ($i ?
"" : " class='current'") .
191 "><a href='/play/javascript-tabbed-navigation/'>" .
192 xl($grpname) . "</a></li>\n";
199 <div
class="tabContainer">
202 foreach ($GLOBALS_METADATA as $grpname => $grparr) {
203 if ( $_GET['mode'] != "user" ||
($_GET['mode'] == "user" && in_array($grpname, $USER_SPECIFIC_TABS)) ) {
204 echo " <div class='tab" . ($i ?
"" : " current") .
205 "' style='height:auto;width:97%;'>\n";
209 if ($_GET['mode'] == "user") {
211 echo "<th> </th>";
212 echo "<th>" . htmlspecialchars( xl('User Specific Setting'), ENT_NOQUOTES
) . "</th>";
213 echo "<th>" . htmlspecialchars( xl('Default Setting'), ENT_NOQUOTES
) . "</th>";
214 echo "<th> </th>";
215 echo "<th>" . htmlspecialchars( xl('Set to Default'), ENT_NOQUOTES
) . "</th>";
219 foreach ($grparr as $fldid => $fldarr) {
220 if ( $_GET['mode'] != "user" ||
($_GET['mode'] == "user" && in_array($fldid, $USER_SPECIFIC_GLOBALS)) ) {
221 list($fldname, $fldtype, $flddef, $flddesc) = $fldarr;
223 // Most parameters will have a single value, but some will be arrays.
224 // Here we cater to both possibilities.
225 $glres = sqlStatement("SELECT gl_index, gl_value FROM globals WHERE " .
226 "gl_name = '$fldid' ORDER BY gl_index");
228 while ($glrow = sqlFetchArray($glres)) $glarr[] = $glrow;
230 // $fldvalue is meaningful only for the single-value cases.
231 $fldvalue = count($glarr) ?
$glarr[0]['gl_value'] : $flddef;
233 // Collect user specific setting if mode set to user
235 $settingDefault = "checked='checked'";
236 if ($_GET['mode'] == "user") {
237 $userSettingArray = sqlQuery("SELECT * FROM user_settings WHERE setting_user=? AND setting_label=?",array($_SESSION['authId'],"global:".$fldid));
238 $userSetting = $userSettingArray['setting_value'];
239 $globalValue = $fldvalue;
240 if (!empty($userSettingArray)) {
241 $fldvalue = $userSetting;
242 $settingDefault = "";
246 echo " <tr title='$flddesc'><td valign='top'><b>$fldname </b></td><td valign='top'>\n";
248 if (is_array($fldtype)) {
249 echo " <select name='form_$i' id='form_$i'>\n";
250 foreach ($fldtype as $key => $value) {
251 if ($_GET['mode'] == "user") {
252 if ($globalValue == $key) $globalTitle = $value;
254 echo " <option value='$key'";
255 if ($key == $fldvalue) echo " selected";
263 else if ($fldtype == 'bool') {
264 if ($_GET['mode'] == "user") {
265 if ($globalValue == 1) {
266 $globalTitle = htmlspecialchars( xl('Checked'), ENT_NOQUOTES
);
269 $globalTitle = htmlspecialchars( xl('Not Checked'), ENT_NOQUOTES
);
272 echo " <input type='checkbox' name='form_$i' id='form_$i' value='1'";
273 if ($fldvalue) echo " checked";
277 else if ($fldtype == 'num') {
278 if ($_GET['mode'] == "user") {
279 $globalTitle = $globalValue;
281 echo " <input type='text' name='form_$i' id='form_$i' " .
282 "size='6' maxlength='15' value='$fldvalue' />\n";
285 else if ($fldtype == 'text') {
286 if ($_GET['mode'] == "user") {
287 $globalTitle = $globalValue;
289 echo " <input type='text' name='form_$i' id='form_$i' " .
290 "size='50' maxlength='255' value='$fldvalue' />\n";
292 else if ($fldtype == 'pwd') {
293 if ($_GET['mode'] == "user") {
294 $globalTitle = $globalValue;
296 echo " <input type='password' name='form_$i' " .
297 "size='50' maxlength='255' value='' />\n";
300 else if ($fldtype == 'pass') {
301 if ($_GET['mode'] == "user") {
302 $globalTitle = $globalValue;
304 echo " <input type='password' name='form_$i' " .
305 "size='50' maxlength='255' value='$fldvalue' />\n";
308 else if ($fldtype == 'lang') {
309 $res = sqlStatement("SELECT * FROM lang_languages ORDER BY lang_description");
310 echo " <select name='form_$i' id='form_$i'>\n";
311 while ($row = sqlFetchArray($res)) {
312 echo " <option value='" . $row['lang_description'] . "'";
313 if ($row['lang_description'] == $fldvalue) echo " selected";
315 echo xl($row['lang_description']);
321 else if ($fldtype == 'm_lang') {
322 $res = sqlStatement("SELECT * FROM lang_languages ORDER BY lang_description");
323 echo " <select multiple name='form_{$i}[]' id='form_{$i}[]' size='3'>\n";
324 while ($row = sqlFetchArray($res)) {
325 echo " <option value='" . $row['lang_description'] . "'";
326 foreach ($glarr as $glrow) {
327 if ($glrow['gl_value'] == $row['lang_description']) {
333 echo xl($row['lang_description']);
339 else if ($fldtype == 'css') {
340 if ($_GET['mode'] == "user") {
341 $globalTitle = $globalValue;
343 $themedir = "$webserver_root/interface/themes";
344 $dh = opendir($themedir);
346 echo " <select name='form_$i' id='form_$i'>\n";
347 while (false !== ($tfname = readdir($dh))) {
348 // Only show files that contain style_ as options
349 // Skip style_blue.css since this is used for
350 // lone scripts such as setup.php
351 // Also skip style_pdf.css which is for PDFs and not screen output
352 if (!preg_match("/^style_.*\.css$/", $tfname) ||
353 $tfname == 'style_blue.css' ||
$tfname == 'style_pdf.css')
355 echo "<option value='$tfname'";
356 if ($tfname == $fldvalue) echo " selected";
366 else if ($fldtype == 'hour') {
367 if ($_GET['mode'] == "user") {
368 $globalTitle = $globalValue;
370 echo " <select name='form_$i' id='form_$i'>\n";
371 for ($h = 0; $h < 24; ++
$h) {
372 echo "<option value='$h'";
373 if ($h == $fldvalue) echo " selected";
375 if ($h == 0) echo "12 AM";
376 else if ($h < 12) echo "$h AM";
377 else if ($h == 12) echo "12 PM";
378 else echo ($h - 12) . " PM";
383 if ($_GET['mode'] == "user") {
385 echo "<td align='center' style='color:red;'>" . $globalTitle . "</td>\n";
386 echo "<td> </td>";
387 echo "<td align='center'><input type='checkbox' value='YES' name='toggle_" . $i . "' id='toggle_" . $i . "' " . $settingDefault . "/></td>\n";
388 echo "<input type='hidden' id='globaldefault_" . $i . "' value='" . $globalValue . "'>\n";
392 echo " </td></tr>\n";
405 <input type
='submit' name
='form_save' value
='<?php xl('Save
','e
'); ?>' />
413 <script language
="JavaScript">
415 $
(document
).ready(function(){
419 // Use the counter ($i) to make the form user friendly for user-specific globals use
420 <?php
if ($_GET['mode'] == "user") { ?
>
421 <?php
for ($j = 0; $j <= $i; $j++
) { ?
>
422 $
("#form_<?php echo $j ?>").change(function() {
423 $
("#toggle_<?php echo $j ?>").attr('checked',false);
425 $
("#toggle_<?php echo $j ?>").change(function() {
426 if ($
('#toggle_<?php echo $j ?>').attr('checked')) {
427 var defaultGlobal
= $
("#globaldefault_<?php echo $j ?>").val();
428 $
("#form_<?php echo $j ?>").val(defaultGlobal
);