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 = 122;
50 if($this->parent->snapshotEnabled()){
51 $action_col_size += 38;
52 }
54 /* Toggle all selected / deselected */
55 $chk = "<input type='checkbox' id='select_all' name='select_all'
56 onClick='toggle_all_(\"^item_selected_[0-9]*$\",\"select_all\");' >";
58 /* set Page header */
59 $this->AddHeader(array("string"=> $chk, "attach"=>"style='width:20px;'"));
60 $this->AddHeader(array("string"=> " ", "attach"=>"style='width:20px;'"));
61 $this->AddHeader(array("string"=>_("Username")." / "._("Department")));
62 $this->AddHeader(array("string"=>_("Properties"), "attach" => "style='width:166px;'"));
63 $this->AddHeader(array("string"=>_("Actions"), "attach" => "style='width:".$action_col_size."px;border-right:0px;text-align:right;'"));
65 $this->AddCheckBox("ShowTemplates" ,_("Select to see template pseudo users") ,_("Show templates") , false);
66 $this->AddCheckBox("ShowFunctionalUsers",_("Select to see users that have only a GOsa object"),_("Show functional users") , true);
67 $this->AddCheckBox("ShowUnixUsers" ,_("Select to see users that have posix settings") ,_("Show unix users") , true);
68 $this->AddCheckBox("ShowMailUsers" ,_("Select to see users that have mail settings") ,_("Show mail users") , true);
69 $this->AddCheckBox("ShowSambaUsers" ,_("Select to see users that have samba settings") ,_("Show samba users") , true);
70 $this->AddCheckBox("ShowProxyUsers" ,_("Select to see users that have proxy settings") ,_("Show proxy users") , true);
72 /* Add SubSearch checkbox */
73 $this->AddCheckBox(SEPERATOR);
74 $this->AddCheckBox("SubSearch", _("Select to search within subtrees"), _("Search in subtrees"), false);
76 /* Name ,Text ,Default , Connect with alphabet */
77 $this->AddRegex ("Regex", _("Display users matching"),"*" , true);
78 }
81 function GenHeader()
82 {
83 /* Prepare departments,
84 which are shown in the listbox on top of the listbox
85 */
86 $options= "";
88 /* Get all departments within this subtree */
89 $base = $this->config->current['BASE'];
91 /* Add base */
92 $tmp = array();
93 $tmp[] = array("dn"=>$this->config->current['BASE']);
94 $tmp= array_merge($tmp,get_list("(&(|(ou=*)(description=*))(objectClass=gosaDepartment))", $this->module, $base,
95 array("ou", "description"), GL_SIZELIMIT | GL_SUBSEARCH));
97 $deps = array();
98 foreach($tmp as $tm){
99 $deps[$tm['dn']] = $tm['dn'];
100 }
103 /* Load possible departments */
104 $ui= get_userinfo();
105 $tdeps= $ui->get_module_departments("users");
106 $ids = $this->config->idepartments;
107 $first = "";
108 $found = FALSE;
109 foreach($ids as $dep => $name){
110 if(isset($deps[$dep]) && in_array_ics($dep, $tdeps)){
112 /* Keep first base dn in mind, we could need this
113 * info if no valid base was found
114 */
115 if(empty($first)) {
116 $first = $dep['dn'];
117 }
119 $value = $ids[$dep];
120 if ($this->selectedBase == $dep){
121 $found = TRUE;
122 $options.= "<option selected='selected' value='".$dep."'>$value</option>";
123 } else {
124 $options.= "<option value='".$dep."'>$value</option>";
125 }
126 }
127 }
129 /* The currently used base is not visible with your acl setup.
130 * Set base to first useable base.
131 */
132 if(!$found){
133 $this->selectedBase = $first;
134 }
136 /* Get copy & paste icon */
137 $acl_all = $ui->has_complete_category_acls($this->selectedBase,"users") ;
138 $acl = $ui->get_permissions($this->selectedBase,"users/user");
140 /* Add default header */
141 $listhead = MultiSelectWindow::get_default_header();
142 $listhead .=
143 _("Base")." <select name='CurrentMainBase' onChange='mainform.submit()' class='center'>$options</select>".
144 " <input class='center' type='image' src='images/list_submit.png' align='middle'
145 title='"._("Submit department")."' name='submit_department' alt='". _("Submit")."'> ";
148 /* Create Layers menu */
149 $s = ".|"._("Actions")."|\n";
150 $s .= "..|<img src='images/list_new.png' alt='' border='0' class='center'>".
151 " "._("Create")."|\n";
153 /* Append create options */
154 if(preg_match("/c/",$acl)) {
155 $s.= "...|<input class='center' type='image' src='images/list_new_user.png' alt=''>".
156 " "._("User")."|user_new|\n";
157 $s.= "...|<input class='center' type='image' src='images/list_new.png' alt=''>".
158 " "._("Template")."|user_tplnew|\n";
159 }
161 /* Multiple options */
162 $s.= "..|---|\n";
163 $s.= "..|<img src='images/edit.png' alt='' border='0' class='center'>".
164 " "._("Edit")."|"."multiple_edit|\n";
165 $s.= "..|<img src='images/list_password.png' alt='' border='0' class='center'>".
166 " "._("Change password")."|"."multiple_password_change|\n";
167 $s.= "..|<img src='images/edittrash.png' alt='' border='0' class='center'>".
168 " "._("Remove")."|"."remove_multiple|\n";
170 if(class_available("DaemonEvent_notify")){
171 $events = DaemonEvent::get_event_types();
172 $event = $events['BY_CLASS']['DaemonEvent_notify'];
173 $s.= "..|---|\n";
174 $s.= "..|".$event['MenuImage']." ".$event['s_Menu_Name']."|trigger_event_DaemonEvent_notify\n";
175 }
177 /* Add multiple copy & cut icons */
178 if(is_object($this->parent->CopyPasteHandler) && preg_match("/(c.*w|w.*c)/",$acl_all)){
179 $s.= "..|---|\n";
180 $s.= "..|<img src='images/editcopy.png' alt='' border='0' class='center'>".
181 " "._("Copy")."|"."multiple_copy_systems|\n";
182 $s.= "..|<img src='images/editcut.png' alt='' border='0' class='center'>".
183 " "._("Cut")."|"."multiple_cut_systems|\n";
185 if($this->parent->CopyPasteHandler->entries_queued()){
186 $img = "<img border='0' class='center' src='images/editpaste.png' alt=''>";
187 $s.="..|".$img." "._("Paste")."|editPaste|\n";
188 }else{
189 $img = "<img border='0' class='center' src='images/cant_editpaste.png' alt=''>";
190 $s.="..|".$img." "._("Paste")."\n";
191 }
192 }
194 /* Add snapshot icons */
195 if(preg_match("/(c.*w|w.*c)/",$acl_all)){
196 $s .= "..|---|\n";
197 $s .= $this->get_snapshot_header(TRUE);
198 }
200 $this->SetDropDownHeaderMenu($s);
201 $this->SetListHeader($listhead);
202 }
204 /* so some basic settings */
205 function execute()
206 {
207 $this->ClearElementsList();
208 $this->GenHeader();
209 }
211 function setEntries($list)
212 {
213 /********************
214 Variable init
215 ********************/
217 $num_users = 0;
218 $num_templates = 0;
220 /* Variable initialation */
221 $enviro = $posix = $maila = $faxac = $samba = $netatalk = "";
222 $empty = "<img class='center' src='images/empty.png' style='width:16px;height:16px;' alt='-'>";
223 $userimg = "<img class='center' src='images/select_user.png' alt='User' title='%s'>";
224 $tplimg = "<img class='center' src='images/select_template.png' alt='Template' title='%s'>";
225 $editlink = "<a href='?plug=".validate($_GET['plug'])."&id=%s&act=edit_entry'>%s</a>";
227 /* Dynamic action col, depending on snapshot icons */
228 $action_col_size = 122;
229 if($this->parent->snapshotEnabled()){
230 $action_col_size += 38;
231 }
233 /* Possilbe objectClass image combinations */
234 $possibleAccounts = array(
235 "posixAccount" => array("VAR"=>"posix" ,"IMG"=>"posiximg"),
236 "gotoEnvironment" => array("VAR"=>"enviro" ,"IMG"=>"eviroimg"),
237 "gosaMailAccount" => array("VAR"=>"maila" ,"IMG"=>"mailimg"),
238 "goFaxAccount" => array("VAR"=>"faxac" ,"IMG"=>"faximg"),
239 "sambaSamAccount" => array("VAR"=>"samba" ,"IMG"=>"sambaimg"),
240 "apple-user" => array("VAR"=>"netatalk" ,"IMG"=>"netatalkimg"));
242 /* Pictures for Extensions */
243 $usrimg ="<input class='center' type='image' src='images/select_user.png' alt='"._("GOsa")."'
244 name='user_edit_%KEY%-user' title='"._("Edit generic properties")."'>";
245 $posiximg = "<input class='center' type='image' src='images/penguin.png' alt='"._("Posix")."'
246 name='user_edit_%KEY%-posixAccount' title='"._("Edit UNIX properties")."'>";
247 $eviroimg = "<input class='center' type='image' src='images/smallenv.png' alt='"._("Environment")."'
248 name='user_edit_%KEY%-environment' title='"._("Edit environment properties")."'>";
249 $mailimg = "<input class='center' type='image' src='images/mailto.png' alt='"._("Mail")."'
250 name='user_edit_%KEY%-mailAccount' title='"._("Edit mail properties")."'>";
251 $fonimg = "<input class='center' type='image' src='images/%image%' alt='"._("Phone")."'
252 name='user_edit_%KEY%-phoneAccount' title='"._("Edit phone properties")."%title%'>";
253 $faximg = "<input class='center' type='image' src='images/fax_small.png' alt='"._("Fax")."'
254 name='user_edit_%KEY%-gofaxAccount' title='"._("Edit fax properies")."'>";
255 $sambaimg = "<input class='center' type='image' src='images/select_winstation.png' alt='"._("Samba")."'
256 name='user_edit_%KEY%-sambaAccount' title='"._("Edit samba properties")."'>";
257 $netatalkimg = "<input class='center' type='image' src='images/select_netatalk.png' alt='"._("Netatalk")."'
258 name='user_edit_%KEY%-netatalk' title='"._("Edit netatalk properties")."'>";
259 $tplcreateuserimg = "<input type='image' class='center' src='images/list_new.png' alt='"._("Create user from template")."'
260 name='userfrom_tpl_%KEY%' title='"._("Create user with this template")."'>";
262 /********************
263 END :: Variable init
264 ********************/
267 /********************
268 Append entries to divlist
269 ********************/
271 $ui = get_userinfo();
273 // Test Every Entry and generate divlist Array
274 foreach($list as $key => $val){
276 /* Create action icons */
277 $action= "";
279 /* Add copy & cut icons */
280 $acl_all = $ui->has_complete_category_acls($this->selectedBase,"users") ;
281 $acl = $ui->get_permissions($val['dn'],"users/user");
282 if(preg_match("/(c.*w|w.*c)/",$acl_all) && $this->parent->CopyPasteHandler){
283 $action .= "<input class='center' type='image'
284 src='images/editcut.png' alt='"._("cut")."' name='cut_%KEY%' title='"._("Cut this entry")."'> ";
285 $action.= "<input class='center' type='image'
286 src='images/editcopy.png' alt='"._("copy")."' name='copy_%KEY%' title='"._("Copy this entry")."'> ";
287 }
289 /* Add deactivate status */
290 $lock_status = "";
292 if(isset($val['userPassword'][0]) && preg_match("/^\{[^\}]/",$val['userPassword'][0])){
293 if(preg_match("/^[^\}]*+\}!/",$val['userPassword'][0])){
294 $lock_status = "<input class='center' type='image' src='images/closedlock.png'
295 alt='"._("Deactivated")."' name='toggle_lock_status_%KEY%'>";
296 }else{
297 $lock_status = "<input class='center' type='image' src='images/openlock.png'
298 alt='"._("Active")."' name='toggle_lock_status_%KEY%'>";
299 }
300 }else{
301 $lock_status = "<img src='images/empty.png' alt=' ' class='center'>";
302 }
304 /* Generate edit icon */
305 $action.= "<input class='center' type='image' src='images/edit.png' alt='"._("edit")."'
306 name='user_edit_%KEY%' title='"._("Edit user")."'>";
308 /* Add deactivate status if we are allowed to */
309 if (preg_match("/w/",$acl_all)){
310 $action.= $lock_status;
311 }
313 /* Add Password change icon, if we are able to write users/password */
314 if(!in_array_ics("gosaUserTemplate",$val['objectClass']) && preg_match("/w/",$ui->get_permissions($val['dn'],"users/password"))) {
315 $action.= "<input class='center' type='image' src='images/list_password.png' alt='"._("password")."'
316 name='user_chgpw_%KEY%' title='"._("Change password")."'>";
317 }else{
318 $action.= "<img class='center' src='images/empty.png' alt=' '
319 title='"._("You are not allowed to change the password for this user.")."'>";
320 }
322 /* Add snapshot icon */
323 if(preg_match("/(c.*w|w.*c)/",$acl_all)){
324 $action.= $this->GetSnapShotActions($val['dn']);
325 }
327 /* Add remove icon, if we are allowed to remove the current user */
328 if(preg_match("/d/",$ui->get_permissions($val['dn'],"users/user"))) {
329 $action.= "<input class='center' type='image' src='images/edittrash.png' alt='"._("delete")."'
330 name='user_del_%KEY%' title='"._("Delete user")."'>";
331 }else{
332 $action.= "<img class='center' src='images/empty.png' alt=' '
333 title='"._("You are not allowed to remove this user.")."'>";
334 }
336 /* Create phonaccopunt informationm, if conencted && is phoneAccount */
337 if((in_array("goFonAccount" ,$val['objectClass']))){
339 /* Set defaults */
340 $fonac = preg_replace("/%image%/", "select_phone.png", $fonimg);
341 $fonac = preg_replace("/%KEY%/", "$key", $fonac);
342 $fonac = preg_replace("/%title%/", "", $fonac);
344 }else{
345 $fonac=$empty;
346 }
348 /* Set images for different types of objectClasses */
349 foreach($possibleAccounts as $objectClass => $Settigns){
350 if(in_array($objectClass ,$val['objectClass'])){
351 $$Settigns['VAR'] = preg_replace("/%KEY%/", "$key", $$Settigns['IMG']);
352 }else{
353 $$Settigns['VAR'] = $empty;
354 }
355 }
357 /* Create userimg */
358 if(in_array("gosaUserTemplate",$val['objectClass'])){
359 $tpl = preg_replace("/%KEY%/", "$key", $tplimg);
360 $s_img_create_from_template = preg_replace("/%KEY%/", "$key", $tplcreateuserimg);
361 $num_templates ++;
362 }else{
363 $s_img_create_from_template = "";
364 $tpl = $userimg;
365 $num_users ++;
366 }
368 /* Insert key into userimg */
369 $usrimg2 = preg_replace("/%KEY%/", "$key", $usrimg);
371 // Generate caption for rows
372 if (isset($val["sn"]) && isset($val["givenName"])){
373 $display= $val["sn"][0].", ".$val["givenName"][0]." [".$val["uid"][0]."]";
374 } else {
375 $display= "[".$val["uid"][0]."]";
376 }
378 /* Connect all images */
379 $UseImg = $usrimg2." ".$posix." ".$enviro." ".$maila." ".$fonac." ".$faxac." ".$samba." ".$netatalk;
381 /* Cutted objects should be displayed in light grey */
382 if($this->parent->CopyPasteHandler){
383 foreach($this->parent->CopyPasteHandler->queue as $queue_key => $queue_data){
384 if($queue_data['dn'] == $val['dn']) {
385 $display = "<font color='#999999'>".$display."</font>";
386 break;
387 }
388 }
389 }
391 /* Create each field */
392 $field0 = array("string" => "<input type='checkbox' id='item_selected_".$key."' name='item_selected_".$key."'>" ,
393 "attach" => "style='width:20px;'");
394 $field1 = array("string" => sprintf($tpl,$val['dn']), "attach" => "style='text-align:center;width:20px;'");
395 $field2 = array("string" => sprintf($editlink,$key,$display), "attach" => "style='' title='".preg_replace('/ /', ' ', @LDAP::fix($val['dn']))."'");
396 $field3 = array("string" => $UseImg, "attach" => "style='width:166px;'");
397 $field4 = array("string" => $s_img_create_from_template.preg_replace("/%KEY%/", "$key", $action),
398 "attach" => "style='width:".$action_col_size."px;border-right:0px; text-align:right;'");
399 /* Add to list */
400 $add = array($field0,$field1,$field2,$field3,$field4);
401 $this->AddElement($add);
403 // Template or User
404 if(in_array("gosaUserTemplate",$val['objectClass'])){
405 $tpls[strtolower( $val['sn']['0'].$val['uid']['0'])]=$add;
406 }else{
407 $users[strtolower( $val['sn']['0'].$val['uid']['0'])]=$add;
408 }
409 }
412 /* Create summary string for list footer */
413 $num_deps=0;
414 if(!$this->SubSearch){
415 $num_deps = count($this->Added_Departments);
416 }
417 $num_users = count($list);
419 $num_user_str = _("Number of listed users");
420 $num_dep_str = _("Number of listed departments");
422 $str = "<img class='center' src='images/select_user.png'
423 title='".$num_user_str."' alt='".$num_user_str."'> ".$num_users." ";
424 $str.= "<img class='center' src='images/folder.png'
425 title='".$num_dep_str."' alt='".$num_dep_str."'> ".$num_deps." ";
427 $this->set_List_Bottom_Info($str);
428 }
430 function Save()
431 {
432 MultiSelectWindow :: Save();
433 }
435 function save_object()
436 {
437 /* Save automatic created POSTs like regex, checkboxes */
438 MultiSelectWindow::save_object();
439 }
440 }
441 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
442 ?>