changed git call from https to git readonly
[atutor.git] / mods / wiki / plugins / auth-liveuser / liveuser_addusers_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 user/group administration page
26 $ewiki_plugins['page']['AdminAddUsers'] = 'ewiki_page_liveuser_admin_add_users';
27
28 /**
29  * simple admin gui for adding user accounts.
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_add_users($id, $data, $action)
37 {
38     global $liveuserAuthAdmin, $liveuserPermAdmin;
39
40     ob_start();
41     
42     echo ewiki_make_title($id, $id, 2);
43     
44     // add a user
45     if (isset($_POST['submit_addusers'])) {
46       if (empty($_POST['text_E-Mail_Address']) || empty($_POST['group_list'])) {
47         echo '<p>Invalid form input was provided. Please ensure that the email and group fields are set and not empty.</p>';
48         $o = ob_get_contents();
49         ob_end_clean();
50         return $o;
51       }
52         
53         
54     if (strlen($_POST['text_E-Mail_Address']) > 255) {
55       echo '<p>The email field input is too long. Please ensure that it is 255 characters or less.</p>';
56       $o = ob_get_contents();
57       ob_end_clean();
58       return $o;     
59     }
60         
61     if(!empty($_POST['username_text'])){
62       $username=$_POST['username_text'];
63     } else {
64       $username=$_POST['text_E-Mail_Address'];
65     }
66         
67         // ensure user does not already exist
68     if (($auth_id = liveuser_checkEntity('user', $username)) === false) {
69       
70       $pwd=liveuser_generate_password();
71       
72       if (($auth_id = liveuser_addEntity('user', array($username, $pwd))) !== false) {
73         echo '<p>User '.$username.' was inserted into the database.<br />The following password has been set for this user: '.$pwd.'</p>';
74         //set preferences on successful creation                
75         foreach($_POST as $post_key => $post_value){
76           if(strstr($post_key, "text_")){ //only work on fields with the text_ prefix
77             $varname=substr($post_key,5); //remove the text_ prefix
78             if(!ewiki_set_uservar($varname, $post_value, $username)){ //set appropriate data
79               echo '<p>An error occurred while setting the additional preferences for the user.</p>';
80             }
81           } 
82         }                
83         if (is_numeric($group_id = liveuser_checkEntity('group', $_POST['group_list'])) &&
84         $liveuserPermAdmin->addUserToGroup($auth_id, $group_id) === true) {
85         echo '<p>User '.$username.' was added into the group: '.$_POST['group_list'].'</p>';
86         } else {
87           echo '<p>An error occurred while adding the user to the group: '.$_POST['group_list'].'</p>';
88         }
89       } else {
90         echo '<p>An error occurred while creating the user.</p>';
91       }
92     } else {
93       echo '<p>User '.$username.' already exists and will not be created or modified.</p>';
94     }   
95   }  
96   
97     // show form
98     ?>
99         <form method="post" action="">
100         <h3>Add a User</h3>
101         <table>
102   <tr><td><label for="email_text">E-Mail Address</label></td>
103   <td><input name="text_E-Mail Address" type="text" maxlength="255" /><br /></td></tr>
104   <tr><td><label for="username">User Name (if different from E-mail Address)</td>
105   <td><input id="username_text" name="username_text" type="text" /></td></tr>   
106         <tr><td><label for="group_list">Group</label></td>
107         <td><select id="group_list" name="group_list">
108     <?php
109         foreach ($liveuserPermAdmin->getGroups() as $group) {
110             echo '<option value="'.$group['name'].'">'.$group['name'].'</option>';
111         }        
112     ?>
113     </select></tr></td>
114     <tr><td><label for="firstname_text">First Name</label></td> 
115     <td><input name="text_First Name" type="text" /></td></tr>
116     <tr><td><label for="middlename_text">Middle Name</label></td>       
117     <td><input name="text_Middle Name" type="text" /></td></tr>
118     <tr><td><label for="lastname_text">Last Name</label></td>   
119     <td><input name="text_Last Name" type="text" /></td></tr>
120     <tr><td><label for="title_text">Title</label></td>  
121     <td><input name="text_Title" type="text" /></td></tr>
122     <tr><td><label for="comp_text">Company</label></td> 
123     <td><input name="text_Company" type="text" /></td></tr>
124     <tr><td><label for="phone_text">Phone</label></td>
125     <td><input name="text_Phone Number" type="text" /></td></tr>
126     <tr><td><label for="addr_text">Address</label></td>
127     <td><input name="text_Address"  type="text" /></td></tr>
128     <tr><td><label for="city_text">City</label></td>
129     <td><input name="text_City" type="text" /></td></tr>
130     <tr><td><label for="state_text">State</label></td>
131     <td><input name="text_State" type="text" /></td></tr>
132     <tr><td><label for="zipcode_text">Zip Code</label></td>
133     <td><input name="text_Zip Code"  type="text" /></td></tr>
134     <tr><td><label for="country_text">Country</label></td>
135     <td><input name="text_Country" type="text" /></td></tr>
136   </table>
137         <input type="submit" name="submit_addusers" />
138         </form>
139     <?php
140     
141     $o = ob_get_contents();
142     ob_end_clean();
143     return $o;     
144 }
145
146 ?>