changed git call from https to git readonly
[atutor.git] / mods / wiki / plugins / auth-liveuser / liveuser_prefs_gui.php
1 <?php
2
3 /**
4  * Copyright (c) 2003, The Burgiss Group, LLC
5  * This source code is part of eWiki LiveUser Plugin.
6  *
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.
11  *
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
15  * for more details.
16  *
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
20  */
21
22 require_once(dirname(__FILE__).'/liveuser_aux.php');
23 require_once(dirname(__FILE__).'/pref_liveuser.php');
24
25 // ewiki callback for perms administration page
26 $ewiki_plugins['page']['AdminPrefs'] = 'ewiki_page_liveuser_admin_prefs';
27
28 /**
29  * admin gui for modifying LiveUser preferences
30  *
31  * @param string id
32  * @param mixed data
33  * @param string action
34  * @return string page output response
35  */
36 function ewiki_page_liveuser_admin_prefs($id, $data, $action)
37 {
38     global $liveuserDB;
39     
40     ob_start();
41     
42     echo ewiki_make_title($id, $id, 2);
43     
44     // delete or update preference fields
45     if (isset($_POST['changeprefs_submit'])) {
46         
47         // extract input fields
48         foreach ($_POST as $key => $value) {
49             list($prefix, $id) = explode('_', $key, 2);
50             
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>.';
55                 } else {
56                     echo '<p>An error occurred deleting field '.$id.'</p>';
57                 }
58             }
59             
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 />';
63             }
64             
65             if ($prefix == 'default' && is_numeric($id) && ($_POST['origdefault_'.$id] != $value)) {
66                 echo 'old value: '.$_POST['origdefault_'.$id].'new value: '.$value.'<br />';
67             }
68         }
69     }
70     
71     // Handle POSTed new rows
72     if (!empty($_POST['prefname_text'])) {    
73         $livewebpref = liveuser_pref_checkField($_POST['prefname_text']);
74                 
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']);                 
79             } else {
80                 $livewebpref = $_POST['public_chk'] ? liveuser_pref_setField($_POST['prefname_text'], true) :
81                     liveuser_pref_setField($_POST['prefname_text'], false);                 
82             }
83             
84             if ($livewebpref !== false ) {
85                 echo $_POST['prefname_text'].' was inserted into liveweb_prefs_fields...';
86             }
87         } else {
88             echo $_POST['prefname_text'].' could NOT be inserted into liveweb_prefs_fields...';
89         }   
90     }
91    
92     echo '<br /><br />';
93         
94     // Get list of prefs fields in liveuser system
95     $results = $liveuserDB->getAll('SELECT * FROM liveweb_prefs_fields');
96     
97     // show form for modifying preferences
98     if (is_array($results) && !empty($results)) {       
99         ?>
100             <form method="post" action="">
101             <h3>Modify Preference Fields</h3>
102             <table border="1">
103             <tr><th>Delete</th><th>ID</th><th>Preference</th><th>Public</th><th>Default Value</th></tr>
104         <?php
105         
106         foreach ($results as $result) {
107             ?>
108                 <tr>
109                     <td><input name="chk_<?=$result['field_id']?>" type="checkbox"></td><td><?=$result['field_id']?></td>
110                     <td><?=$result['field_name']?></td>
111                     <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>       
116                         </select>
117                     </td>
118                     <td>
119                         <input name="origdefault_<?=$result['field_id']?>" value="<?=$result['default_value']?>" type="hidden">
120                         <input name="default_<?=$result['field_id']?>" value="<?=$result['default_value']?>">
121                     </td>
122                 </tr>
123             <?php
124         }
125         
126         ?>
127             </table>
128             <input type="reset" text="Reset">
129             <input type="submit" name="changeprefs_submit">
130             </form>
131         <?php
132     } else {
133         echo '<p>No preference fields were found.</p>';
134     }
135
136     // show form for adding preferences
137     ?>
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">
147         </form>
148     <?php
149     
150     $o = ob_get_contents();
151     ob_end_clean();
152     return $o;
153 }
154
155 ?>