4 * Copyright (c) 2003, The Burgiss Group, LLC
5 * This source code is part of eWiki LiveUser Plugin.
7 * eWiki LiveUser Plugin is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU Lesser General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or (at your
10 * option) any later version.
12 * eWiki LiveUser Plugin is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
17 * You should have received a copy of the GNU Lesser General Public License
18 * along with Wiki LiveUser Plugin; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 require_once(dirname(__FILE__).'/liveuser_aux.php');
23 require_once(dirname(__FILE__).'/pref_liveuser.php');
25 // ewiki callback for perms administration page
26 $ewiki_plugins['page']['AdminPrefs'] = 'ewiki_page_liveuser_admin_prefs';
29 * admin gui for modifying LiveUser preferences
33 * @param string action
34 * @return string page output response
36 function ewiki_page_liveuser_admin_prefs($id, $data, $action)
42 echo ewiki_make_title($id, $id, 2);
44 // delete or update preference fields
45 if (isset($_POST['changeprefs_submit'])) {
47 // extract input fields
48 foreach ($_POST as $key => $value) {
49 list($prefix, $id) = explode('_', $key, 2);
51 // deleted checked preferences
52 if ($prefix == 'chk' && is_numeric($id) && $value == 'on') {
53 if (liveuser_pref_removeField($id)) {
54 echo '<p>Field '.$id.' was successfully deleted</p>.';
56 echo '<p>An error occurred deleting field '.$id.'</p>';
60 // update preference fields for differing new/old values
61 if ($prefix == 'public' && is_numeric($id) && ($_POST['origpublic_'.$id] != $value)) {
62 echo 'old value: '.$_POST['origpublic_'.$id].'new value: '.$value.'<br />';
65 if ($prefix == 'default' && is_numeric($id) && ($_POST['origdefault_'.$id] != $value)) {
66 echo 'old value: '.$_POST['origdefault_'.$id].'new value: '.$value.'<br />';
71 // Handle POSTed new rows
72 if (!empty($_POST['prefname_text'])) {
73 $livewebpref = liveuser_pref_checkField($_POST['prefname_text']);
75 if ($livewebpref === false) {
76 if (!empty($_POST['default_text'])) {
77 $livewebpref = $_POST['public_chk'] ? liveuser_pref_setField($_POST['prefname_text'], true, $_POST['default_text']) :
78 liveuser_pref_setField($_POST['prefname_text'], false, $_POST['default_text']);
80 $livewebpref = $_POST['public_chk'] ? liveuser_pref_setField($_POST['prefname_text'], true) :
81 liveuser_pref_setField($_POST['prefname_text'], false);
84 if ($livewebpref !== false ) {
85 echo $_POST['prefname_text'].' was inserted into liveweb_prefs_fields...';
88 echo $_POST['prefname_text'].' could NOT be inserted into liveweb_prefs_fields...';
94 // Get list of prefs fields in liveuser system
95 $results = $liveuserDB->getAll('SELECT * FROM liveweb_prefs_fields');
97 // show form for modifying preferences
98 if (is_array($results) && !empty($results)) {
100 <form method="post" action="">
101 <h3>Modify Preference Fields</h3>
103 <tr><th>Delete</th><th>ID</th><th>Preference</th><th>Public</th><th>Default Value</th></tr>
106 foreach ($results as $result) {
109 <td><input name="chk_<?=$result['field_id']?>" type="checkbox"></td><td><?=$result['field_id']?></td>
110 <td><?=$result['field_name']?></td>
112 <input name="origpublic_<?=$result['field_id']?>" value="<?=$result['public']?>" type="hidden">
113 <select id="public_<?=$result['field_id']?>" name="public_<?=$result['field_id']?>">
114 <option value="1" <?=(($result['public'] == 1) ? 'selected="selected"' : '')?>>Y</option>
115 <option value="0" <?=(($result['public'] == 0) ? 'selected="selected"' : '')?>>N</option>
119 <input name="origdefault_<?=$result['field_id']?>" value="<?=$result['default_value']?>" type="hidden">
120 <input name="default_<?=$result['field_id']?>" value="<?=$result['default_value']?>">
128 <input type="reset" text="Reset">
129 <input type="submit" name="changeprefs_submit">
133 echo '<p>No preference fields were found.</p>';
136 // show form for adding preferences
138 <form method="post" action="">
139 <h3>Add a Preference Field</h3>
140 <label for="prefname_text">Preference Name</label>
141 <input id="prefname_text" name="prefname_text" type="text"><br />
142 <label for="public_chk">Public</label>
143 <input id="public_chk" name="public_chk" type="checkbox"><br />
144 <label for="default_text">Default Value</label>
145 <input id="default_text" name="default_text" type="text"><br />
146 <input type="submit" name="addprefs_submit">
150 $o = ob_get_contents();