1 <?php
3 class divListUsers extends MultiSelectWindow
4 {
6 /* Current base */
7 var $selectedBase = "";
8 var $departments = array();
10 /* Regex */
11 var $Regex = "*";
13 /* CheckBoxes */
14 var $ShowTemplates ;
15 var $ShowFunctionalUsers;
16 var $ShowUnixUsers;
17 var $ShowMailUsers;
18 var $ShowSambaUsers;
19 var $ShowProxyUsers;
21 /* Subsearch checkbox */
22 var $SubSearch = false;
24 var $parent ;
25 var $ui ;
27 function divListUsers ($config,$parent)
28 {
29 MultiSelectWindow::MultiSelectWindow($config, "Users", "users");
31 $this->parent = $parent;
32 $this->ui = get_userinfo();
34 /* Set list strings */
35 $this->SetTitle(_("List of users"));
36 $this->SetSummary(_("List of users"));
38 /* Result page will look like a headpage */
39 $this->SetHeadpageMode();
40 $this->SetInformation(_("This menu allows you to create, edit and delete selected users. Having a great number of users, you may want to use the range selectors on top of the user list."));
42 $this->EnableAplhabet (true);
44 /* Disable buttonsm */
45 $this->EnableCloseButton(false);
46 $this->EnableSaveButton (false);
48 /* Dynamic action col, depending on snapshot icons */
49 $action_col_size = 104;
50 if($this->parent->snapshotEnabled()){
51 $action_col_size += 38;
52 }
54 /* set Page header */
55 $this->AddHeader(array("string"=>" ", "attach"=>"style='width:20px;'"));
56 $this->AddHeader(array("string"=>_("Username")." / "._("Department")));
57 $this->AddHeader(array("string"=>_("Properties"), "attach" => "style='width:152px;'"));
58 $this->AddHeader(array("string"=>_("Actions"), "attach" => "style='width:".$action_col_size."px;border-right:0px;text-align:right;'"));
60 $this->AddCheckBox("ShowTemplates" ,_("Select to see template pseudo users") ,_("Show templates") , false);
61 $this->AddCheckBox("ShowFunctionalUsers",_("Select to see users that have only a GOsa object"),_("Show functional users") , true);
62 $this->AddCheckBox("ShowUnixUsers" ,_("Select to see users that have posix settings") ,_("Show unix users") , true);
63 $this->AddCheckBox("ShowMailUsers" ,_("Select to see users that have mail settings") ,_("Show mail users") , true);
64 $this->AddCheckBox("ShowSambaUsers" ,_("Select to see users that have samba settings") ,_("Show samba users") , true);
65 $this->AddCheckBox("ShowProxyUsers" ,_("Select to see users that have proxy settings") ,_("Show proxy users") , true);
67 /* Add SubSearch checkbox */
68 $this->AddCheckBox(SEPERATOR);
69 $this->AddCheckBox("SubSearch", _("Select to search within subtrees"), _("Ignore subtrees"), false);
71 /* Name ,Text ,Default , Connect with alphabet */
72 $this->AddRegex ("Regex", _("Display users matching"),"*" , true);
73 }
76 function GenHeader()
77 {
78 /* Prepare departments,
79 which are shown in the listbox on top of the listbox
80 */
81 $options= "";
83 /* Get all departments within this subtree */
84 $base = $this->config->current['BASE'];
85 $deps= get_list("(&(|(ou=*)(description=*))(objectClass=gosaDepartment))", $this->module, $base,
86 array("ou", "description"), GL_SIZELIMIT | GL_SUBSEARCH);
88 /* Load possible departments */
89 $ui= get_userinfo();
90 $tdeps= $ui->get_module_departments("users");
92 $ids = $this->config->idepartments;
94 foreach($deps as $dep){
95 if(isset($ids[$dep['dn']]) && in_array_ics($dep['dn'], $tdeps)){
97 $value = $ids[$dep['dn']];
98 if ($this->selectedBase == $dep['dn']){
99 $options.= "<option selected='selected' value='".$dep['dn']."'>$value</option>";
100 } else {
101 $options.= "<option value='".$dep['dn']."'>$value</option>";
102 }
103 }
104 }
106 /* Get copy & paste icon */
107 $acl_all = $ui->has_complete_category_acls($this->selectedBase,"users/user") ;
108 $acl = $ui->get_permissions($this->selectedBase,"users/user");
109 if(preg_match("/(c.*w|w.*c)/",$acl_all) && $this->parent->CopyPasteHandler){
110 $Copy_Paste = $this->parent->CopyPasteHandler->generatePasteIcon();
111 }else{
112 $Copy_Paste ="";
113 }
115 /* Create header with selected base */
116 $listhead = "<div style='background:#F0F0F9;padding:5px;'>".
117 " <input class='center' type='image' src='images/list_root.png' align='middle'
118 title='"._("Go to root department")."' name='dep_root' alt='"._("Root")."'> ".
119 " <input class='center' type='image' align='middle' src='images/list_back.png'
120 title='"._("Go up one department")."' alt='"._("Up")."' name='dep_back'> ".
121 " <input class='center' type='image' align='middle' src='images/list_home.png'
122 title='"._("Go to users department")."' alt='"._("Home")."' name='dep_home'> ".
123 " <input class='center' type='image' src='images/list_reload.png' align='middle'
124 title='"._("Reload list")."' name='submit_department' alt='"._("Submit")."'> ".
125 " <img class='center' src='images/list_seperator.png' align='middle' alt='-' height='16' width='1'> ";
128 if(preg_match("/(c.*w|w.*c)/",$acl_all)){
129 $listhead .= $this->get_snapshot_header($this->selectedBase);
130 }
132 if(preg_match("/c/",$acl)) {
133 $listhead .= " <input class='center' type='image' align='middle' src='images/list_new_user.png'
134 title='"._("Create new user")."' alt='"._("New user")."' name='user_new'> ";
135 $listhead .= " <input class='center' type='image' align='middle' src='images/list_new.png'
136 title='"._("Create new template")."' alt='"._("New template")."' name='user_tplnew'> ";
137 }
139 $listhead .= $Copy_Paste;
141 $listhead .=
142 _("Base")." <select name='CurrentMainBase' onChange='mainform.submit()' class='center'>$options</select>".
143 " <input class='center' type='image' src='images/list_submit.png' align='middle'
144 title='"._("Submit department")."' name='submit_department' alt='". _("Submit")."'> ".
145 "</div>";
147 $this->SetListHeader($listhead);
148 }
150 /* so some basic settings */
151 function execute()
152 {
153 $this->ClearElementsList();
154 $this->GenHeader();
155 }
157 function setEntries($list)
158 {
159 /********************
160 Variable init
161 ********************/
163 /* Variable initialation */
164 $enviro = $posix = $maila = $faxac = $samba = $netatalk = "";
165 $empty = "<img class='center' src='images/empty.png' style='width:16px;height:16px;' alt='-'>";
166 $userimg = "<img class='center' src='images/select_user.png' alt='User' title='%s'>";
167 $tplimg = "<img class='center' src='images/select_template.png' alt='Template' title='%s'>";
168 $editlink = "<a href='?plug=".validate($_GET['plug'])."&id=%s&act=edit_entry'>%s</a>";
170 /* Dynamic action col, depending on snapshot icons */
171 $action_col_size = 104;
172 if($this->parent->snapshotEnabled()){
173 $action_col_size += 38;
174 }
176 /* Possilbe objectClass image combinations */
177 $possibleAccounts = array(
178 "posixAccount" => array("VAR"=>"posix" ,"IMG"=>"posiximg"),
179 "gotoEnvironment" => array("VAR"=>"enviro" ,"IMG"=>"eviroimg"),
180 "gosaMailAccount" => array("VAR"=>"maila" ,"IMG"=>"mailimg"),
181 "goFaxAccount" => array("VAR"=>"faxac" ,"IMG"=>"faximg"),
182 "sambaSamAccount" => array("VAR"=>"samba" ,"IMG"=>"sambaimg"),
183 "apple-user" => array("VAR"=>"netatalk" ,"IMG"=>"netatalkimg"));
185 /* Pictures for Extensions */
186 $usrimg ="<input class='center' type='image' src='images/select_user.png' alt='"._("GOsa")."'
187 name='user_edit_%KEY%-user' title='"._("Edit generic properties")."'>";
188 $posiximg = "<input class='center' type='image' src='images/penguin.png' alt='"._("Posix")."'
189 name='user_edit_%KEY%-posixAccount' title='"._("Edit UNIX properties")."'>";
190 $eviroimg = "<input class='center' type='image' src='images/smallenv.png' alt='"._("Environment")."'
191 name='user_edit_%KEY%-environment' title='"._("Edit environment properties")."'>";
192 $mailimg = "<input class='center' type='image' src='images/mailto.png' alt='"._("Mail")."'
193 name='user_edit_%KEY%-mailAccount' title='"._("Edit mail properties")."'>";
194 $fonimg = "<input class='center' type='image' src='images/%image%' alt='"._("Phone")."'
195 name='user_edit_%KEY%-phoneAccount' title='"._("Edit phone properties")."%title%'>";
196 $faximg = "<input class='center' type='image' src='images/fax_small.png' alt='"._("Fax")."'
197 name='user_edit_%KEY%-gofaxAccount' title='"._("Edit fax properies")."'>";
198 $sambaimg = "<input class='center' type='image' src='images/select_winstation.png' alt='"._("Samba")."'
199 name='user_edit_%KEY%-sambaAccount' title='"._("Edit samba properties")."'>";
200 $netatalkimg = "<input class='center' type='image' src='images/select_netatalk.png' alt='"._("Netatalk")."'
201 name='user_edit_%KEY%-netatalk' title='"._("Edit netatalk properties")."'>";
202 $tplcreateuserimg = "<input type='image' class='center' src='images/list_new.png' alt='"._("Create user from template")."'
203 name='userfrom_tpl_%KEY%' title='"._("Create user with this template")."'>";
205 /********************
206 END :: Variable init
207 ********************/
209 /* Get Configuration for goFon DB (if it is set), to connect to the asterisk tables.
210 * Read Sip Table for specified account (for each user with phoneAccount).
211 * Check the attributes ip port and regseconds.
212 * If regseconds is set and >0 , the phone is logged in.
213 * Else the phone is currently not logged.
214 * If we can't read any Data from the DB or there is no goFon DB specified
215 * show old style without status icons.
216 */
217 $r_db =false;
218 $r_con =false;
219 if (isset($_SESSION['config']->data['SERVERS']['FON'])){
220 $a_SETUP= $_SESSION['config']->data['SERVERS']['FON'];
221 $r_con = false;
222 $r_db = false;
223 if(is_callable("mysql_pconnect")){
224 $r_con= @mysql_pconnect($a_SETUP['SERVER'],$a_SETUP['LOGIN'],$a_SETUP['PASSWORD']);
225 // Check if we are connected correctly
226 if($r_con){
227 $r_db = @mysql_select_db($a_SETUP['DB'],$r_con);
228 }
229 }
230 }
233 /********************
234 Append entries to divlist
235 ********************/
237 $ui = get_userinfo();
239 // Test Every Entry and generate divlist Array
240 foreach($list as $key => $val){
242 /* Create action icons */
243 $action= "";
245 /* Add copy & cut icons */
246 $acl_all = $ui->has_complete_category_acls($this->selectedBase,"users/user") ;
247 $acl = $ui->get_permissions($val['dn'],"users/user");
248 if(preg_match("/(c.*w|w.*c)/",$acl_all) && $this->parent->CopyPasteHandler){
249 $action .= "<input class='center' type='image'
250 src='images/editcut.png' alt='"._("cut")."' name='cut_%KEY%' title='"._("Cut this entry")."'> ";
251 $action.= "<input class='center' type='image'
252 src='images/editcopy.png' alt='"._("copy")."' name='copy_%KEY%' title='"._("Copy this entry")."'> ";
253 }
255 /* Generate edit icon */
256 $action.= "<input class='center' type='image' src='images/edit.png' alt='"._("edit")."'
257 name='user_edit_%KEY%' title='"._("Edit user")."'>";
259 /* Add Password change icon, if we are able to write users/password */
260 if(!in_array_ics("gosaUserTemplate",$val['objectClass']) && preg_match("/w/",$ui->get_permissions($val['dn'],"users/password"))) {
261 $action.= "<input class='center' type='image' src='images/list_password.png' alt='"._("password")."'
262 name='user_chgpw_%KEY%' title='"._("Change password")."'>";
263 }else{
264 $action.= "<img class='center' src='images/empty.png' alt=' '
265 title='"._("You are not allowed to change the password for this user.")."'>";
266 }
268 /* Add snapshot icon */
269 if(preg_match("/(c.*w|w.*c)/",$acl_all)){
270 $action.= $this->GetSnapShotActions($val['dn']);
271 }
273 /* Add remove icon, if we are allowed to remove the current user */
274 if(preg_match("/d/",$ui->get_permissions($val['dn'],"users/user"))) {
275 $action.= "<input class='center' type='image' src='images/edittrash.png' alt='"._("delete")."'
276 name='user_del_%KEY%' title='"._("Delete user")."'>";
277 }else{
278 $action.= "<img class='center' src='images/empty.png' alt=' '
279 title='"._("You are not allowed to remove this user.")."'>";
280 }
282 /* Create phonaccopunt informationm, if conencted && is phoneAccount */
283 $connected = ""; // This string represents timestamp or offline status
284 $ip_port = ""; // String that will represent ip : port of the connected phone
285 if((in_array("goFonAccount" ,$val['objectClass']))){
287 /* Set defaults */
288 $fonac = preg_replace("/%image%/", "select_phone.png", $fonimg);
289 $fonac = preg_replace("/%KEY%/", "$key", $fonac);
290 $fonac = preg_replace("/%title%/", "", $fonac);
292 /* Database connection is ok ?*/
293 if(($r_db)&&(is_callable("mysql_query"))){
294 $res= @mysql_query("SELECT regseconds,name,port,ipaddr FROM ".$a_SETUP['SIP_TABLE']." WHERE (name='".$val['uid'][0]."')");
295 $mysql_entry = @mysql_fetch_row($res);
296 if(is_array($mysql_entry)){
297 if((isset($mysql_entry[0]))&&($mysql_entry[0]>1)){
298 $connected = " | "._("Online")." : ".gmdate("d.m.Y H:i:s",($mysql_entry[0]+(60*60)));
299 $fonac = preg_replace("/%image%/", "select_phone_connected.png", $fonimg);
300 $fonac = preg_replace("/%KEY%/", "$key", $fonac);
301 $fonac = preg_replace("/%title%/", $connected, $fonac);
302 #$ip_port= " - ".$mysql_entry[3].":".$mysql_entry[2];
303 }
304 if((isset($mysql_entry[0]))&&($mysql_entry[0]==0)){
305 $connected = " | "._("Offline");
306 $fonac = preg_replace("/%image%/", "select_phone.png", $fonimg);
307 $fonac = preg_replace("/%KEY%/", "$key", $fonac);
308 $fonac = preg_replace("/%title%/", $connected, $fonac);
309 }
310 }
311 }
312 }else{
313 $fonac=$empty;
314 }
316 /* Set images for different types of objectClasses */
317 foreach($possibleAccounts as $objectClass => $Settigns){
318 if(in_array($objectClass ,$val['objectClass'])){
319 $$Settigns['VAR'] = preg_replace("/%KEY%/", "$key", $$Settigns['IMG']);
320 }else{
321 $$Settigns['VAR'] = $empty;
322 }
323 }
325 /* Create userimg */
326 if(in_array("gosaUserTemplate",$val['objectClass'])){
327 $tpl = preg_replace("/%KEY%/", "$key", $tplimg);
328 $s_img_create_from_template = preg_replace("/%KEY%/", "$key", $tplcreateuserimg);
329 }else{
330 $s_img_create_from_template = "";
331 $tpl = $userimg;
332 }
334 /* Insert key into userimg */
335 $usrimg2 = preg_replace("/%KEY%/", "$key", $usrimg);
337 // Generate caption for rows
338 if (isset($val["sn"]) && isset($val["givenName"])){
339 $display= $val["sn"][0].", ".$val["givenName"][0]." [".$val["uid"][0]."]";
340 } else {
341 $display= "[".$val["uid"][0]."]";
342 }
344 /* Connect all images */
345 $UseImg = $usrimg2." ".$posix." ".$enviro." ".$maila." ".$fonac." ".$faxac." ".$samba." ".$netatalk;
347 /* Create each field */
348 $field1 = array("string" => sprintf($tpl,$val['dn']), "attach" => "style='text-align:center;width:20px;'");
349 $field2 = array("string" => sprintf($editlink,$key,$display).$ip_port, "attach" => "style='' title='".preg_replace('/ /', ' ', @LDAP::fix($val['dn']))."'");
350 $field3 = array("string" => $UseImg, "attach" => "style='width:152px;'");
351 $field4 = array("string" => $s_img_create_from_template.preg_replace("/%KEY%/", "$key", $action),
352 "attach" => "style='width:".$action_col_size."px;border-right:0px; text-align:right;'");
353 /* Add to list */
354 $add = array($field1,$field2,$field3,$field4);
355 $this->AddElement($add);
357 // Template or User
358 if(in_array("gosaUserTemplate",$val['objectClass'])){
359 $tpls[strtolower( $val['sn']['0'].$val['uid']['0'])]=$add;
360 }else{
361 $users[strtolower( $val['sn']['0'].$val['uid']['0'])]=$add;
362 }
363 }
365 /* close database connection, if it was opened */
366 if(isset($r_con)){
367 if((is_callable("mysql_close"))&&($r_con)){
368 @mysql_close($r_con);
369 }
370 }
372 }
374 function Save()
375 {
376 MultiSelectWindow :: Save();
377 }
379 function save_object()
380 {
381 /* Save automatic created POSTs like regex, checkboxes */
382 MultiSelectWindow::save_object();
383 }
384 }
385 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
386 ?>