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 /* 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"), _("Ignore 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'];
90 $deps= get_list("(&(|(ou=*)(description=*))(objectClass=gosaDepartment))", $this->module, $base,
91 array("ou", "description"), GL_SIZELIMIT | GL_SUBSEARCH);
93 /* Load possible departments */
94 $ui= get_userinfo();
95 $tdeps= $ui->get_module_departments("users");
96 $ids = $this->config->idepartments;
97 $first = "";
98 $found = FALSE;
99 foreach($deps as $dep){
100 if(isset($ids[$dep['dn']]) && in_array_ics($dep['dn'], $tdeps)){
102 if(empty($first)) {
103 $first = $dep['dn'];
104 }
106 $value = $ids[$dep['dn']];
107 if ($this->selectedBase == $dep['dn']){
108 $found = TRUE;
109 $options.= "<option selected='selected' value='".$dep['dn']."'>$value</option>";
110 } else {
111 $options.= "<option value='".$dep['dn']."'>$value</option>";
112 }
113 }
114 }
115 if(!$found){
116 $this->selectedBase = $first;
117 }
119 /* Get copy & paste icon */
120 $acl_all = $ui->has_complete_category_acls($this->selectedBase,"users") ;
121 $acl = $ui->get_permissions($this->selectedBase,"users/user");
122 if(preg_match("/(c.*w|w.*c)/",$acl_all) && $this->parent->CopyPasteHandler){
123 $Copy_Paste = $this->parent->CopyPasteHandler->generatePasteIcon();
124 }else{
125 $Copy_Paste ="";
126 }
128 /* Add default header */
129 $listhead = MultiSelectWindow::get_default_header();
131 if(preg_match("/(c.*w|w.*c)/",$acl_all)){
132 $listhead .= $this->get_snapshot_header($this->selectedBase);
133 }
135 if(preg_match("/c/",$acl)) {
136 $listhead .= " <input class='center' type='image' align='middle' src='images/list_new_user.png'
137 title='"._("Create new user")."' alt='"._("New user")."' name='user_new'> ";
138 $listhead .= " <input class='center' type='image' align='middle' src='images/list_new.png'
139 title='"._("Create new template")."' alt='"._("New template")."' name='user_tplnew'> ";
140 }
142 $listhead .= $Copy_Paste;
144 $listhead .=
145 _("Base")." <select name='CurrentMainBase' onChange='mainform.submit()' class='center'>$options</select>".
146 " <input class='center' type='image' src='images/list_submit.png' align='middle'
147 title='"._("Submit department")."' name='submit_department' alt='". _("Submit")."'> ";
150 /* Multiple options */
151 $listhead .= " <input class='center' type='image' align='middle' src='images/edittrash.png'
152 title='"._("Remove selected user")."' alt='"._("Remove user")."' name='remove_multiple_users'> ";
154 $listhead .="</div>";;
155 $this->SetListHeader($listhead);
156 }
158 /* so some basic settings */
159 function execute()
160 {
161 $this->ClearElementsList();
162 $this->GenHeader();
163 }
165 function setEntries($list)
166 {
167 /********************
168 Variable init
169 ********************/
171 /* Variable initialation */
172 $enviro = $posix = $maila = $faxac = $samba = $netatalk = "";
173 $empty = "<img class='center' src='images/empty.png' style='width:16px;height:16px;' alt='-'>";
174 $userimg = "<img class='center' src='images/select_user.png' alt='User' title='%s'>";
175 $tplimg = "<img class='center' src='images/select_template.png' alt='Template' title='%s'>";
176 $editlink = "<a href='?plug=".validate($_GET['plug'])."&id=%s&act=edit_entry'>%s</a>";
178 /* Dynamic action col, depending on snapshot icons */
179 $action_col_size = 104;
180 if($this->parent->snapshotEnabled()){
181 $action_col_size += 38;
182 }
184 /* Possilbe objectClass image combinations */
185 $possibleAccounts = array(
186 "posixAccount" => array("VAR"=>"posix" ,"IMG"=>"posiximg"),
187 "gotoEnvironment" => array("VAR"=>"enviro" ,"IMG"=>"eviroimg"),
188 "gosaMailAccount" => array("VAR"=>"maila" ,"IMG"=>"mailimg"),
189 "goFaxAccount" => array("VAR"=>"faxac" ,"IMG"=>"faximg"),
190 "sambaSamAccount" => array("VAR"=>"samba" ,"IMG"=>"sambaimg"),
191 "apple-user" => array("VAR"=>"netatalk" ,"IMG"=>"netatalkimg"));
193 /* Pictures for Extensions */
194 $usrimg ="<input class='center' type='image' src='images/select_user.png' alt='"._("GOsa")."'
195 name='user_edit_%KEY%-user' title='"._("Edit generic properties")."'>";
196 $posiximg = "<input class='center' type='image' src='images/penguin.png' alt='"._("Posix")."'
197 name='user_edit_%KEY%-posixAccount' title='"._("Edit UNIX properties")."'>";
198 $eviroimg = "<input class='center' type='image' src='images/smallenv.png' alt='"._("Environment")."'
199 name='user_edit_%KEY%-environment' title='"._("Edit environment properties")."'>";
200 $mailimg = "<input class='center' type='image' src='images/mailto.png' alt='"._("Mail")."'
201 name='user_edit_%KEY%-mailAccount' title='"._("Edit mail properties")."'>";
202 $fonimg = "<input class='center' type='image' src='images/%image%' alt='"._("Phone")."'
203 name='user_edit_%KEY%-phoneAccount' title='"._("Edit phone properties")."%title%'>";
204 $faximg = "<input class='center' type='image' src='images/fax_small.png' alt='"._("Fax")."'
205 name='user_edit_%KEY%-gofaxAccount' title='"._("Edit fax properies")."'>";
206 $sambaimg = "<input class='center' type='image' src='images/select_winstation.png' alt='"._("Samba")."'
207 name='user_edit_%KEY%-sambaAccount' title='"._("Edit samba properties")."'>";
208 $netatalkimg = "<input class='center' type='image' src='images/select_netatalk.png' alt='"._("Netatalk")."'
209 name='user_edit_%KEY%-netatalk' title='"._("Edit netatalk properties")."'>";
210 $tplcreateuserimg = "<input type='image' class='center' src='images/list_new.png' alt='"._("Create user from template")."'
211 name='userfrom_tpl_%KEY%' title='"._("Create user with this template")."'>";
213 /********************
214 END :: Variable init
215 ********************/
218 /********************
219 Append entries to divlist
220 ********************/
222 $ui = get_userinfo();
224 // Test Every Entry and generate divlist Array
225 foreach($list as $key => $val){
227 /* Create action icons */
228 $action= "";
230 /* Add copy & cut icons */
231 $acl_all = $ui->has_complete_category_acls($this->selectedBase,"users") ;
232 $acl = $ui->get_permissions($val['dn'],"users/user");
233 if(preg_match("/(c.*w|w.*c)/",$acl_all) && $this->parent->CopyPasteHandler){
234 $action .= "<input class='center' type='image'
235 src='images/editcut.png' alt='"._("cut")."' name='cut_%KEY%' title='"._("Cut this entry")."'> ";
236 $action.= "<input class='center' type='image'
237 src='images/editcopy.png' alt='"._("copy")."' name='copy_%KEY%' title='"._("Copy this entry")."'> ";
238 }
240 /* Generate edit icon */
241 $action.= "<input class='center' type='image' src='images/edit.png' alt='"._("edit")."'
242 name='user_edit_%KEY%' title='"._("Edit user")."'>";
244 /* Add Password change icon, if we are able to write users/password */
245 if(!in_array_ics("gosaUserTemplate",$val['objectClass']) && preg_match("/w/",$ui->get_permissions($val['dn'],"users/password"))) {
246 $action.= "<input class='center' type='image' src='images/list_password.png' alt='"._("password")."'
247 name='user_chgpw_%KEY%' title='"._("Change password")."'>";
248 }else{
249 $action.= "<img class='center' src='images/empty.png' alt=' '
250 title='"._("You are not allowed to change the password for this user.")."'>";
251 }
253 /* Add snapshot icon */
254 if(preg_match("/(c.*w|w.*c)/",$acl_all)){
255 $action.= $this->GetSnapShotActions($val['dn']);
256 }
258 /* Add remove icon, if we are allowed to remove the current user */
259 if(preg_match("/d/",$ui->get_permissions($val['dn'],"users/user"))) {
260 $action.= "<input class='center' type='image' src='images/edittrash.png' alt='"._("delete")."'
261 name='user_del_%KEY%' title='"._("Delete user")."'>";
262 }else{
263 $action.= "<img class='center' src='images/empty.png' alt=' '
264 title='"._("You are not allowed to remove this user.")."'>";
265 }
267 /* Create phonaccopunt informationm, if conencted && is phoneAccount */
268 if((in_array("goFonAccount" ,$val['objectClass']))){
270 /* Set defaults */
271 $fonac = preg_replace("/%image%/", "select_phone.png", $fonimg);
272 $fonac = preg_replace("/%KEY%/", "$key", $fonac);
273 $fonac = preg_replace("/%title%/", "", $fonac);
275 }else{
276 $fonac=$empty;
277 }
279 /* Set images for different types of objectClasses */
280 foreach($possibleAccounts as $objectClass => $Settigns){
281 if(in_array($objectClass ,$val['objectClass'])){
282 $$Settigns['VAR'] = preg_replace("/%KEY%/", "$key", $$Settigns['IMG']);
283 }else{
284 $$Settigns['VAR'] = $empty;
285 }
286 }
288 /* Create userimg */
289 if(in_array("gosaUserTemplate",$val['objectClass'])){
290 $tpl = preg_replace("/%KEY%/", "$key", $tplimg);
291 $s_img_create_from_template = preg_replace("/%KEY%/", "$key", $tplcreateuserimg);
292 }else{
293 $s_img_create_from_template = "";
294 $tpl = $userimg;
295 }
297 /* Insert key into userimg */
298 $usrimg2 = preg_replace("/%KEY%/", "$key", $usrimg);
300 // Generate caption for rows
301 if (isset($val["sn"]) && isset($val["givenName"])){
302 $display= $val["sn"][0].", ".$val["givenName"][0]." [".$val["uid"][0]."]";
303 } else {
304 $display= "[".$val["uid"][0]."]";
305 }
307 /* Connect all images */
308 $UseImg = $usrimg2." ".$posix." ".$enviro." ".$maila." ".$fonac." ".$faxac." ".$samba." ".$netatalk;
310 /* Create each field */
311 $field0 = array("string" => "<input type='checkbox' id='item_selected_".$key."' name='item_selected_".$key."'>" ,
312 "attach" => "style='width:20px;'");
313 $field1 = array("string" => sprintf($tpl,$val['dn']), "attach" => "style='text-align:center;width:20px;'");
314 $field2 = array("string" => sprintf($editlink,$key,$display), "attach" => "style='' title='".preg_replace('/ /', ' ', @LDAP::fix($val['dn']))."'");
315 $field3 = array("string" => $UseImg, "attach" => "style='width:166px;'");
316 $field4 = array("string" => $s_img_create_from_template.preg_replace("/%KEY%/", "$key", $action),
317 "attach" => "style='width:".$action_col_size."px;border-right:0px; text-align:right;'");
318 /* Add to list */
319 $add = array($field0,$field1,$field2,$field3,$field4);
320 $this->AddElement($add);
322 // Template or User
323 if(in_array("gosaUserTemplate",$val['objectClass'])){
324 $tpls[strtolower( $val['sn']['0'].$val['uid']['0'])]=$add;
325 }else{
326 $users[strtolower( $val['sn']['0'].$val['uid']['0'])]=$add;
327 }
328 }
330 }
332 function Save()
333 {
334 MultiSelectWindow :: Save();
335 }
337 function save_object()
338 {
339 /* Save automatic created POSTs like regex, checkboxes */
340 MultiSelectWindow::save_object();
341 }
342 }
343 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
344 ?>