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 if(preg_match("/w/",$ui->get_permissions($this->selectedBase,"users/user")) && $this->parent->CopyPasteHandler){
108 $Copy_Paste = $this->parent->CopyPasteHandler->generatePasteIcon();
109 }else{
110 $Copy_Paste ="";
111 }
113 /* Create header with selected base */
114 $listhead = "<div style='background:#F0F0F9;padding:5px;'>".
115 " <input class='center' type='image' src='images/list_root.png' align='middle'
116 title='"._("Go to root department")."' name='dep_root' alt='"._("Root")."'> ".
117 " <input class='center' type='image' align='middle' src='images/list_back.png'
118 title='"._("Go up one department")."' alt='"._("Up")."' name='dep_back'> ".
119 " <input class='center' type='image' align='middle' src='images/list_home.png'
120 title='"._("Go to users department")."' alt='"._("Home")."' name='dep_home'> ".
121 " <input class='center' type='image' src='images/list_reload.png' align='middle'
122 title='"._("Reload list")."' name='submit_department' alt='"._("Submit")."'> ".
123 " <img class='center' src='images/list_seperator.png' align='middle' alt='-' height='16' width='1'> ";
124 $listhead .= $this->get_snapshot_header($this->selectedBase);
126 $acls = $ui->get_permissions($this->selectedBase,"users/user");
127 if(preg_match("/c/",$acls)) {
128 $listhead .= " <input class='center' type='image' align='middle' src='images/list_new_user.png'
129 title='"._("Create new user")."' alt='"._("New user")."' name='user_new'> ";
130 $listhead .= " <input class='center' type='image' align='middle' src='images/list_new.png'
131 title='"._("Create new template")."' alt='"._("New template")."' name='user_tplnew'> ";
132 # $listhead .= " <img class='center' src='images/list_seperator.png' align='middle' alt='-' height='16' width='1'> ";
133 }
135 $listhead .=
136 $Copy_Paste.
137 _("Base")." <select name='CurrentMainBase' onChange='mainform.submit()' class='center'>$options</select>".
138 " <input class='center' type='image' src='images/list_submit.png' align='middle'
139 title='"._("Submit department")."' name='submit_department' alt='". _("Submit")."'> ".
140 "</div>";
142 $this->SetListHeader($listhead);
143 }
145 /* so some basic settings */
146 function execute()
147 {
148 $this->ClearElementsList();
149 $this->GenHeader();
150 }
152 function setEntries($list)
153 {
154 /********************
155 Variable init
156 ********************/
158 /* Variable initialation */
159 $enviro = $posix = $maila = $faxac = $samba = $netatalk = "";
160 $empty = "<img class='center' src='images/empty.png' style='width:16px;height:16px;' alt='-'>";
161 $userimg = "<img class='center' src='images/select_user.png' alt='User' title='%s'>";
162 $tplimg = "<img class='center' src='images/select_template.png' alt='Template' title='%s'>";
163 $editlink = "<a href='?plug=".validate($_GET['plug'])."&id=%s&act=edit_entry'>%s</a>";
165 /* Dynamic action col, depending on snapshot icons */
166 $action_col_size = 104;
167 if($this->parent->snapshotEnabled()){
168 $action_col_size += 38;
169 }
171 /* Possilbe objectClass image combinations */
172 $possibleAccounts = array(
173 "posixAccount" => array("VAR"=>"posix" ,"IMG"=>"posiximg"),
174 "gotoEnvironment" => array("VAR"=>"enviro" ,"IMG"=>"eviroimg"),
175 "gosaMailAccount" => array("VAR"=>"maila" ,"IMG"=>"mailimg"),
176 "goFaxAccount" => array("VAR"=>"faxac" ,"IMG"=>"faximg"),
177 "sambaSamAccount" => array("VAR"=>"samba" ,"IMG"=>"sambaimg"),
178 "apple-user" => array("VAR"=>"netatalk" ,"IMG"=>"netatalkimg"));
180 /* Pictures for Extensions */
181 $usrimg ="<input class='center' type='image' src='images/select_user.png' alt='"._("GOsa")."'
182 name='user_edit_%KEY%-user' title='"._("Edit generic properties")."'>";
183 $posiximg = "<input class='center' type='image' src='images/penguin.png' alt='"._("Posix")."'
184 name='user_edit_%KEY%-posixAccount' title='"._("Edit UNIX properties")."'>";
185 $eviroimg = "<input class='center' type='image' src='images/smallenv.png' alt='"._("Environment")."'
186 name='user_edit_%KEY%-environment' title='"._("Edit environment properties")."'>";
187 $mailimg = "<input class='center' type='image' src='images/mailto.png' alt='"._("Mail")."'
188 name='user_edit_%KEY%-mailAccount' title='"._("Edit mail properties")."'>";
189 $fonimg = "<input class='center' type='image' src='images/%image%' alt='"._("Phone")."'
190 name='user_edit_%KEY%-phoneAccount' title='"._("Edit phone properties")."%title%'>";
191 $faximg = "<input class='center' type='image' src='images/fax_small.png' alt='"._("Fax")."'
192 name='user_edit_%KEY%-gofaxAccount' title='"._("Edit fax properies")."'>";
193 $sambaimg = "<input class='center' type='image' src='images/select_winstation.png' alt='"._("Samba")."'
194 name='user_edit_%KEY%-sambaAccount' title='"._("Edit samba properties")."'>";
195 $netatalkimg = "<input class='center' type='image' src='images/select_netatalk.png' alt='"._("Netatalk")."'
196 name='user_edit_%KEY%-netatalk' title='"._("Edit netatalk properties")."'>";
197 $tplcreateuserimg = "<input type='image' class='center' src='images/list_new.png' alt='"._("Create user from template")."'
198 name='userfrom_tpl_%KEY%' title='"._("Create user with this template")."'>";
200 /********************
201 END :: Variable init
202 ********************/
204 /* Get Configuration for goFon DB (if it is set), to connect to the asterisk tables.
205 * Read Sip Table for specified account (for each user with phoneAccount).
206 * Check the attributes ip port and regseconds.
207 * If regseconds is set and >0 , the phone is logged in.
208 * Else the phone is currently not logged.
209 * If we can't read any Data from the DB or there is no goFon DB specified
210 * show old style without status icons.
211 */
212 $r_db =false;
213 $r_con =false;
214 if (isset($_SESSION['config']->data['SERVERS']['FON'])){
215 $a_SETUP= $_SESSION['config']->data['SERVERS']['FON'];
216 $r_con = false;
217 $r_db = false;
218 if(is_callable("mysql_pconnect")){
219 $r_con= @mysql_pconnect($a_SETUP['SERVER'],$a_SETUP['LOGIN'],$a_SETUP['PASSWORD']);
220 // Check if we are connected correctly
221 if($r_con){
222 $r_db = @mysql_select_db($a_SETUP['DB'],$r_con);
223 }
224 }
225 }
228 /********************
229 Append entries to divlist
230 ********************/
232 $ui = get_userinfo();
234 // Test Every Entry and generate divlist Array
235 foreach($list as $key => $val){
237 /* Create action icons */
238 $action= "";
240 /* Add copy & cut icons */
241 if($this->parent->CopyPasteHandler && preg_match("/w/",$ui->get_category_permissions($val['dn'],"users"))) {
242 $action .= "<input class='center' type='image'
243 src='images/editcut.png' alt='"._("cut")."' name='cut_%KEY%' title='"._("Cut this entry")."'> ";
244 $action.= "<input class='center' type='image'
245 src='images/editcopy.png' alt='"._("copy")."' name='copy_%KEY%' title='"._("Copy this entry")."'> ";
246 }
248 /* Generate edit icon */
249 $action.= "<input class='center' type='image' src='images/edit.png' alt='"._("edit")."'
250 name='user_edit_%KEY%' title='"._("Edit user")."'>";
252 /* Add Password change icon, if we are able to write users/password */
253 if(preg_match("/w/",$ui->get_permissions($val['dn'],"users/password"))) {
254 $action.= "<input class='center' type='image' src='images/list_password.png' alt='"._("password")."'
255 name='user_chgpw_%KEY%' title='"._("Change password")."'>";
256 }else{
257 $action.= "<img class='center' src='images/empty.png' alt=' '
258 title='"._("You are not allowed to change the password for this user.")."'>";
259 }
261 /* Add snapshot icon */
262 $action.= $this->GetSnapShotActions($val['dn']);
264 /* Add remove icon, if we are allowed to remove the current user */
265 if(preg_match("/d/",$ui->get_permissions($val['dn'],"users/user"))) {
266 $action.= "<input class='center' type='image' src='images/edittrash.png' alt='"._("delete")."'
267 name='user_del_%KEY%' title='"._("Delete user")."'>";
268 }else{
269 $action.= "<img class='center' src='images/empty.png' alt=' '
270 title='"._("You are not allowed to remove this user.")."'>";
271 }
273 /* Create phonaccopunt informationm, if conencted && is phoneAccount */
274 $connected = ""; // This string represents timestamp or offline status
275 $ip_port = ""; // String that will represent ip : port of the connected phone
276 if((in_array("goFonAccount" ,$val['objectClass']))){
278 /* Set defaults */
279 $fonac = preg_replace("/%image%/", "select_phone.png", $fonimg);
280 $fonac = preg_replace("/%KEY%/", "$key", $fonac);
281 $fonac = preg_replace("/%title%/", "", $fonac);
283 /* Database connection is ok ?*/
284 if(($r_db)&&(is_callable("mysql_query"))){
285 $res= @mysql_query("SELECT regseconds,name,port,ipaddr FROM ".$a_SETUP['SIP_TABLE']." WHERE (name='".$val['uid'][0]."')");
286 $mysql_entry = @mysql_fetch_row($res);
287 if(is_array($mysql_entry)){
288 if((isset($mysql_entry[0]))&&($mysql_entry[0]>1)){
289 $connected = " | "._("Online")." : ".gmdate("d.m.Y H:i:s",($mysql_entry[0]+(60*60)));
290 $fonac = preg_replace("/%image%/", "select_phone_connected.png", $fonimg);
291 $fonac = preg_replace("/%KEY%/", "$key", $fonac);
292 $fonac = preg_replace("/%title%/", $connected, $fonac);
293 $ip_port= " - ".$mysql_entry[3].":".$mysql_entry[2];
294 }
295 if((isset($mysql_entry[0]))&&($mysql_entry[0]==0)){
296 $connected = " | "._("Offline");
297 $fonac = preg_replace("/%image%/", "select_phone.png", $fonimg);
298 $fonac = preg_replace("/%KEY%/", "$key", $fonac);
299 $fonac = preg_replace("/%title%/", $connected, $fonac);
300 }
301 }
302 }
303 }else{
304 $fonac=$empty;
305 }
307 /* Set images for different types of objectClasses */
308 foreach($possibleAccounts as $objectClass => $Settigns){
309 if(in_array($objectClass ,$val['objectClass'])){
310 $$Settigns['VAR'] = preg_replace("/%KEY%/", "$key", $$Settigns['IMG']);
311 }else{
312 $$Settigns['VAR'] = $empty;
313 }
314 }
316 /* Create userimg */
317 if(in_array("gosaUserTemplate",$val['objectClass'])){
318 $tpl = preg_replace("/%KEY%/", "$key", $tplimg);
319 $s_img_create_from_template = preg_replace("/%KEY%/", "$key", $tplcreateuserimg);
320 }else{
321 $s_img_create_from_template = "";
322 $tpl = $userimg;
323 }
325 /* Insert key into userimg */
326 $usrimg2 = preg_replace("/%KEY%/", "$key", $usrimg);
328 // Generate caption for rows
329 if (isset($val["sn"]) && isset($val["givenName"])){
330 $display= $val["sn"][0].", ".$val["givenName"][0]." [".$val["uid"][0]."]";
331 } else {
332 $display= "[".$val["uid"][0]."]";
333 }
335 /* Connect all images */
336 $UseImg = $usrimg2." ".$posix." ".$enviro." ".$maila." ".$fonac." ".$faxac." ".$samba." ".$netatalk;
338 /* Create each field */
339 $field1 = array("string" => sprintf($tpl,$val['dn']), "attach" => "style='text-align:center;width:20px;'");
340 $field2 = array("string" => sprintf($editlink,$key,$display).$ip_port, "attach" => "style='' title='".preg_replace('/ /', ' ', @LDAP::fix($val['dn']))."'");
341 $field3 = array("string" => $UseImg, "attach" => "style='width:152px;'");
342 $field4 = array("string" => $s_img_create_from_template.preg_replace("/%KEY%/", "$key", $action),
343 "attach" => "style='width:".$action_col_size."px;border-right:0px; text-align:right;'");
344 /* Add to list */
345 $add = array($field1,$field2,$field3,$field4);
346 $this->AddElement($add);
348 // Template or User
349 if(in_array("gosaUserTemplate",$val['objectClass'])){
350 $tpls[strtolower( $val['sn']['0'].$val['uid']['0'])]=$add;
351 }else{
352 $users[strtolower( $val['sn']['0'].$val['uid']['0'])]=$add;
353 }
354 }
356 /* close database connection, if it was opened */
357 if(isset($r_con)){
358 if((is_callable("mysql_close"))&&($r_con)){
359 @mysql_close($r_con);
360 }
361 }
363 }
365 function Save()
366 {
367 MultiSelectWindow :: Save();
368 }
370 function save_object()
371 {
372 /* Save automatic created POSTs like regex, checkboxes */
373 MultiSelectWindow::save_object();
374 }
375 }
376 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
377 ?>