Code

Removed Current main base settings
[gosa.git] / plugins / admin / users / class_divListUsers.inc
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");
30     
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);
43   
44     /* Disable buttonsm */
45     $this->EnableCloseButton(false);
46     $this->EnableSaveButton (false);
48     /* set Page header */
49     $this->AddHeader(array("string"=>"&nbsp;",          "attach"=>"style='width:20px;'"));
50     $this->AddHeader(array("string"=>_("Username")." / "._("Department")));
51     $this->AddHeader(array("string"=>_("Properties"),   "attach" => "style='width:152px;'"));
52     $this->AddHeader(array("string"=>_("Actions"),      "attach" => "style='width:102px;border-right:0px;text-align:right;'"));
53     
54     $this->AddCheckBox("ShowTemplates"      ,_("Select to see template pseudo users")               ,_("Show templates")        , false);
55     $this->AddCheckBox("ShowFunctionalUsers",_("Select to see users that have only a GOsa object"),_("Show functional users") , true);
56     $this->AddCheckBox("ShowUnixUsers"      ,_("Select to see users that have posix settings")      ,_("Show unix users")       , true);
57     $this->AddCheckBox("ShowMailUsers"      ,_("Select to see users that have mail settings")       ,_("Show mail users")       , true);
58     $this->AddCheckBox("ShowSambaUsers"     ,_("Select to see users that have samba settings")      ,_("Show samba users")      , true);
59     $this->AddCheckBox("ShowProxyUsers"     ,_("Select to see users that have proxy settings")      ,_("Show proxy users")      , true);
61     /* Add SubSearch checkbox */
62     $this->AddCheckBox(SEPERATOR);
63     $this->AddCheckBox("SubSearch",  _("Select to search within subtrees"), _("Ignore subtrees"), false);
65     /*                  Name                 ,Text                              ,Default  , Connect with alphabet  */
66     $this->AddRegex   ("Regex",     _("Display users matching"),"*" , true);
67   }
69   function GenHeader()
70   {
71     /* Prepare departments,
72        which are shown in the listbox on top of the listbox
73      */
74     $options= "";
75     foreach ($this->config->idepartments as $key => $value){
76       if ($this->selectedBase == $key){
77         $options.= "<option selected='selected' value='$key'>$value</option>";
78       } else {
79         $options.= "<option value='$key'>$value</option>";
80       }
81     }
83     /* Get copy & paste icon */ 
84     if($this->parent->CopyPasteHandler){
85       $Copy_Paste = $this->parent->CopyPasteHandler->generatePasteIcon();
86     }else{
87       $Copy_Paste ="";
88     }
90     /* Create header with selected base */
91     $listhead = "<div style='background:#F0F0F9;padding:5px;'>".
92       " <input class='center' type='image' src='images/list_root.png' align='middle' 
93       title='"._("Go to root department")."' name='dep_root' alt='"._("Root")."'>&nbsp;".
94       " <input class='center' type='image' align='middle' src='images/list_back.png' 
95       title='"._("Go up one department")."' alt='"._("Up")."'                name='dep_back'>&nbsp;".
96       " <input class='center' type='image' align='middle' src='images/list_home.png' 
97       title='"._("Go to users department")."' alt='"._("Home")."'            name='dep_home'>&nbsp;".
98       " <input class='center' type='image' src='images/list_reload.png' align='middle' 
99       title='"._("Reload list")."' name='submit_department' alt='".        _("Submit")."'>&nbsp;".
100       " <img   class='center' src='images/list_seperator.png' align='middle' alt='' height='16' width='1'>&nbsp;".
101       " <input class='center' type='image' align='middle' src='images/list_new_user.png' 
102       title='"._("Create new user")."' alt='"._("New user")."'           name='user_new'>&nbsp;".
103       " <input class='center' type='image' align='middle' src='images/list_new.png' 
104       title='"._("Create new template")."' alt='"._("New template")."'        name='user_tplnew'>&nbsp;".
105       $Copy_Paste.
106       " <img   class='center' src='images/list_seperator.png' align='middle' alt='' height='16' width='1'>&nbsp;".
107       _("Base")."&nbsp;<select name='CurrentMainBase' onChange='mainform.submit()' class='center'>$options</select>".
108       " <input class='center' type='image' src='images/list_submit.png' align='middle' 
109       title='"._("Submit department")."' name='submit_department' alt='".  _("Submit")."'>&nbsp;".
110       "</div>";
112     $this->SetListHeader($listhead);
113   }
115   /* so some basic settings */
116   function execute()
117   {
118     $this->ClearElementsList();
119     $this->GenHeader();
120   }
122   function setEntries($list)
123   {
124     /********************
125       Variable init
126      ********************/
128     /* Variable initialation */
129     $enviro     = $posix = $maila = $faxac = $samba = $netatalk = "";
130     $empty      = "<img class='center' src='images/empty.png' style='width:16px;height:16px;' alt=''>";
131     $userimg    = "<img class='center' src='images/select_user.png' alt='User' title='%s'>";
132     $tplimg     = "<img class='center' src='images/select_template.png' alt='Template' title='%s'>";
133     $editlink   = "<a href='?plug=".validate($_GET['plug'])."&amp;id=%s&amp;act=edit_entry'>%s</a>";
135     /* Create action icons */
136     $action = "";
137     if($this->parent->CopyPasteHandler){
138       $action .= "<input class='center' type='image'
139         src='images/editcut.png' alt='"._("cut")."' name='cut_%KEY%' title='"._("Cut this entry")."'>&nbsp;";
140       $action.= "<input class='center' type='image'
141         src='images/editcopy.png' alt='"._("copy")."' name='copy_%KEY%' title='"._("Copy this entry")."'>&nbsp;";
142     }
143     $action.= "<input class='center' type='image' src='images/edit.png' alt='"._("edit")."'
144       name='user_edit_%KEY%' title='"._("Edit user")."'>";
145     $action.= "<input class='center' type='image' src='images/list_password.png' alt='"._("password")."'
146       name='user_chgpw_%KEY%' title='"._("Change password")."'>";
147     $action.= "<input class='center' type='image' src='images/edittrash.png' alt='"._("delete")."'
148       name='user_del_%KEY%' title='"._("Delete user")."'>";
149     
150     /* Possilbe objectClass image combinations */  
151     $possibleAccounts = array(
152             "posixAccount"    => array("VAR"=>"posix"     ,"IMG"=>"posiximg"),
153             "gotoEnvironment" => array("VAR"=>"enviro"    ,"IMG"=>"eviroimg"),
154             "gosaMailAccount" => array("VAR"=>"maila"     ,"IMG"=>"mailimg"),
155             "goFaxAccount"    => array("VAR"=>"faxac"     ,"IMG"=>"faximg"),
156             "sambaSamAccount" => array("VAR"=>"samba"     ,"IMG"=>"sambaimg"),
157             "apple-user"      => array("VAR"=>"netatalk"  ,"IMG"=>"netatalkimg"));
159      /* Pictures for Extensions */
160     $usrimg   ="<input class='center' type='image' src='images/penguin.png' alt='"._("GOsa")."'
161                     name='user_edit_%KEY%-user' title='"._("Edit generic properties")."'>";
162     $posiximg = "<input class='center' type='image' src='images/select_user.png' alt='"._("Posix")."'
163                     name='user_edit_%KEY%-posixAccount' title='"._("Edit UNIX properties")."'>";
164     $eviroimg = "<input class='center' type='image' src='images/smallenv.png' alt='"._("Environment")."'
165                     name='user_edit_%KEY%-environment' title='"._("Edit environment properties")."'>";
166     $mailimg  = "<input class='center' type='image' src='images/mailto.png' alt='"._("Mail")."'
167                     name='user_edit_%KEY%-mailAccount' title='"._("Edit mail properties")."'>";
168     $fonimg   = "<input class='center' type='image' src='images/%image%' alt='"._("Phone")."'
169                     name='user_edit_%KEY%-phoneAccount' title='"._("Edit phone properties")."%title%'>";
170     $faximg   = "<input class='center' type='image' src='images/fax_small.png' alt='"._("Fax")."'
171                     name='user_edit_%KEY%-gofaxAccount' title='"._("Edit fax properies")."'>";
172     $sambaimg = "<input class='center' type='image' src='images/select_winstation.png' alt='"._("Samba")."'
173                     name='user_edit_%KEY%-sambaAccount' title='"._("Edit samba properties")."'>";
174     $netatalkimg = "<input class='center' type='image' src='images/select_netatalk.png' alt='"._("Netatalk")."'
175                     name='user_edit_%KEY%-netatalk' title='"._("Edit netatalk properties")."'>";
176     $tplcreateuserimg  = "<input type='image' class='center' src='images/list_new.png' alt='"._("Create user from template")."'
177                     name='userfrom_tpl_%KEY%' title='"._("Create user with this template")."'>";
179     /********************
180       END :: Variable init
181      ********************/
183     /* Get Configuration for goFon DB (if it is set), to connect to the asterisk tables.
184      * Read Sip Table for specified account (for each user with phoneAccount).
185      * Check the attributes ip port and regseconds.
186      * If regseconds is set and >0 , the phone is logged in.
187      * Else the phone is currently not logged.
188      * If we can't read any Data from the DB or there is no goFon DB specified
189      * show old style without status icons.
190      */
191     $r_db   =false;
192     $r_con  =false;
193     if (isset($_SESSION['config']->data['SERVERS']['FON'])){
194       $a_SETUP= $_SESSION['config']->data['SERVERS']['FON'];
195       $r_con = false;
196       $r_db  = false;
197       if(is_callable("mysql_pconnect")){
198         $r_con= @mysql_pconnect($a_SETUP['SERVER'],$a_SETUP['LOGIN'],$a_SETUP['PASSWORD']);
199         // Check if we are  connected correctly
200         if($r_con){
201           $r_db  =  @mysql_select_db($a_SETUP['DB'],$r_con);
202         }
203       }
204     }
205    
206  
207     /********************
208       Append entries to divlist 
209      ********************/
210  
211     // Test Every Entry and generate divlist Array
212     foreach($list as $key => $val){
214       /* Create phonaccopunt informationm, if conencted && is phoneAccount */ 
215       $connected  = ""; // This string represents timestamp or offline status
216       $ip_port    = ""; // String that will represent ip : port of the connected phone
217       if((in_array("goFonAccount"    ,$val['objectClass']))){
219         /* Set defaults */
220         $fonac = preg_replace("/%image%/", "select_phone.png", $fonimg);
221         $fonac = preg_replace("/%KEY%/", "$key", $fonac);
222         $fonac = preg_replace("/%title%/", "", $fonac);
224         /* Database connection is ok ?*/
225         if(($r_db)&&(is_callable("mysql_query"))){
226           $res= @mysql_query("SELECT regseconds,name,port,ipaddr FROM ".$a_SETUP['SIP_TABLE']." WHERE (name='".$val['uid'][0]."')");
227           $mysql_entry = @mysql_fetch_row($res);
228           if(is_array($mysql_entry)){
229             if((isset($mysql_entry[0]))&&($mysql_entry[0]>1)){
230               $connected = " | "._("Online")." : ".gmdate("d.m.Y H:i:s",($mysql_entry[0]+(60*60)));
231               $fonac = preg_replace("/%image%/", "select_phone_connected.png", $fonimg);
232               $fonac = preg_replace("/%KEY%/", "$key", $fonac);
233               $fonac = preg_replace("/%title%/", $connected, $fonac);
234               $ip_port= " - ".$mysql_entry[3].":".$mysql_entry[2];
235             }
236             if((isset($mysql_entry[0]))&&($mysql_entry[0]==0)){
237               $connected = " | "._("Offline");
238               $fonac = preg_replace("/%image%/", "select_phone.png", $fonimg);
239               $fonac = preg_replace("/%KEY%/", "$key", $fonac);
240               $fonac = preg_replace("/%title%/", $connected, $fonac);
241             }
242           }
243         }
244       }else{
245         $fonac=$empty;
246       }
248       /* Set images for different types of objectClasses */
249       foreach($possibleAccounts as $objectClass => $Settigns){ 
250         if(in_array($objectClass ,$val['objectClass'])){
251           $$Settigns['VAR'] = preg_replace("/%KEY%/", "$key", $$Settigns['IMG']);
252         }else{
253           $$Settigns['VAR'] = $empty;
254         }
255       }
257       /* Create userimg */
258       if(in_array("gosaUserTemplate",$val['objectClass'])){
259         $tpl                          = preg_replace("/%KEY%/", "$key", $tplimg);
260         $s_img_create_from_template   = preg_replace("/%KEY%/", "$key", $tplcreateuserimg);
261       }else{
262         $s_img_create_from_template   = "";
263         $tpl                          = $userimg;
264       }
266       /* Insert key into userimg */
267       $usrimg2 = preg_replace("/%KEY%/", "$key", $usrimg);
269       // Generate caption for rows
270       if (isset($val["sn"]) && isset($val["givenName"])){
271         $display= $val["sn"][0].", ".$val["givenName"][0]." [".$val["uid"][0]."]";
272       } else {
273         $display= "[".$val["uid"][0]."]";
274       }
276       /* Connect all images */
277       $UseImg = $usrimg2."&nbsp;".$posix."&nbsp;".$enviro."&nbsp;".$maila."&nbsp;".$fonac."&nbsp;".$faxac."&nbsp;".$samba."&nbsp".$netatalk;
279       /* Create each field */
280       $field1 = array("string" => sprintf($tpl,$val['dn']), "attach" => "style='text-align:center;width:20px;'");
281       $field2 = array("string" => sprintf($editlink,$key,$display).$ip_port, "attach" => "style='' title='dn:&nbsp;".@LDAP::fix($val['dn'])."'");
282       $field3 = array("string" => $UseImg, "attach" => "style='width:152px;'");
283       $field4 = array("string" => $s_img_create_from_template.preg_replace("/%KEY%/", "$key", $action),
284                       "attach" => "style='width:102px;border-right:0px;    text-align:right;'");
285       /* Add to list */
286       $add = array($field1,$field2,$field3,$field4);
287       $this->AddElement($add);
289       // Template or User
290       if(in_array("gosaUserTemplate",$val['objectClass'])){
291         $tpls[strtolower( $val['sn']['0'].$val['uid']['0'])]=$add;
292       }else{
293         $users[strtolower( $val['sn']['0'].$val['uid']['0'])]=$add;
294       }
295     }
296     
297     /* close database connection, if it was opened */
298     if(isset($r_con)){
299       if((is_callable("mysql_close"))&&($r_con)){
300         @mysql_close($r_con);
301       }
302     }
304   }
306   function Save()
307   {
308     MultiSelectWindow :: Save();  
309   }
311   function save_object()
312   {
313     /* Save automatic created POSTs like regex, checkboxes */
314     MultiSelectWindow::save_object();   
315   }
317 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
318 ?>