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");
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 /* set Page header */
49 $this->AddHeader(array("string"=>" ", "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:132px;border-right:0px;text-align:right;'"));
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 GetSnapShotActions($dn)
70 {
71 $str = "";
73 if($this->parent->snapshotEnabled()){
75 $str .="<input class='center' type='image' src='images/snapshot.png'
76 alt='"._("Create snapshot")."' name='CreateSnapShot_".base64_encode($dn)."' title='"._("Create a new snapshot from this object")."'> ";
78 if(count($this->parent->Available_SnapsShots($dn))){
79 $str .="<input class='center' type='image' src='images/restore.png'
80 alt='"._("Restore snapshot")."' name='RestoreSnapShot_".base64_encode($dn)."' title='"._("Restore snapshot")."'> ";
81 }else{
82 $str.= "<img src='images/empty.png' style='width:16px;' class='center'> ";
83 }
84 }
85 return($str);
86 }
89 function GenHeader()
90 {
91 /* Prepare departments,
92 which are shown in the listbox on top of the listbox
93 */
94 $options= "";
95 foreach ($this->config->idepartments as $key => $value){
96 if ($this->selectedBase == $key){
97 $options.= "<option selected='selected' value='$key'>$value</option>";
98 } else {
99 $options.= "<option value='$key'>$value</option>";
100 }
101 }
103 /* Get copy & paste icon */
104 if($this->parent->CopyPasteHandler){
105 $Copy_Paste = $this->parent->CopyPasteHandler->generatePasteIcon();
106 }else{
107 $Copy_Paste ="";
108 }
110 /* Create header with selected base */
111 $listhead = "<div style='background:#F0F0F9;padding:5px;'>".
112 " <input class='center' type='image' src='images/list_root.png' align='middle'
113 title='"._("Go to root department")."' name='dep_root' alt='"._("Root")."'> ".
114 " <input class='center' type='image' align='middle' src='images/list_back.png'
115 title='"._("Go up one department")."' alt='"._("Up")."' name='dep_back'> ".
116 " <input class='center' type='image' align='middle' src='images/list_home.png'
117 title='"._("Go to users department")."' alt='"._("Home")."' name='dep_home'> ".
118 " <input class='center' type='image' src='images/list_reload.png' align='middle'
119 title='"._("Reload list")."' name='submit_department' alt='". _("Submit")."'> ".
120 " <img class='center' src='images/list_seperator.png' align='middle' alt='' height='16' width='1'> ";
122 if($this->parent->snapshotEnabled()){
123 $listhead .= " <input class='center' type='image' align='middle' src='images/restore.png'
124 title='"._("Restore snapshopts of already deleted objects")."' alt='"._("Restore")."' name='RestoreDeletedSnapShot'>".
125 " <img class='center' src='images/list_seperator.png' align='middle' alt='' height='16' width='1'> ";
126 }
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 " <input class='center' type='image' align='middle' src='images/list_new.png'
131 title='"._("Create new template")."' alt='"._("New template")."' name='user_tplnew'> ".
132 $Copy_Paste.
133 " <img class='center' src='images/list_seperator.png' align='middle' alt='' height='16' width='1'> ".
134 _("Base")." <select name='CurrentMainBase' onChange='mainform.submit()' class='center'>$options</select>".
135 " <input class='center' type='image' src='images/list_submit.png' align='middle'
136 title='"._("Submit department")."' name='submit_department' alt='". _("Submit")."'> ".
137 "</div>";
139 $this->SetListHeader($listhead);
140 }
142 /* so some basic settings */
143 function execute()
144 {
145 $this->ClearElementsList();
146 $this->GenHeader();
147 }
149 function setEntries($list)
150 {
151 /********************
152 Variable init
153 ********************/
155 /* Variable initialation */
156 $enviro = $posix = $maila = $faxac = $samba = $netatalk = "";
157 $empty = "<img class='center' src='images/empty.png' style='width:16px;height:16px;' alt=''>";
158 $userimg = "<img class='center' src='images/select_user.png' alt='User' title='%s'>";
159 $tplimg = "<img class='center' src='images/select_template.png' alt='Template' title='%s'>";
160 $editlink = "<a href='?plug=".validate($_GET['plug'])."&id=%s&act=edit_entry'>%s</a>";
162 /* Possilbe objectClass image combinations */
163 $possibleAccounts = array(
164 "posixAccount" => array("VAR"=>"posix" ,"IMG"=>"posiximg"),
165 "gotoEnvironment" => array("VAR"=>"enviro" ,"IMG"=>"eviroimg"),
166 "gosaMailAccount" => array("VAR"=>"maila" ,"IMG"=>"mailimg"),
167 "goFaxAccount" => array("VAR"=>"faxac" ,"IMG"=>"faximg"),
168 "sambaSamAccount" => array("VAR"=>"samba" ,"IMG"=>"sambaimg"),
169 "apple-user" => array("VAR"=>"netatalk" ,"IMG"=>"netatalkimg"));
171 /* Pictures for Extensions */
172 $usrimg ="<input class='center' type='image' src='images/select_user.png' alt='"._("GOsa")."'
173 name='user_edit_%KEY%-user' title='"._("Edit generic properties")."'>";
174 $posiximg = "<input class='center' type='image' src='images/penguin.png' alt='"._("Posix")."'
175 name='user_edit_%KEY%-posixAccount' title='"._("Edit UNIX properties")."'>";
176 $eviroimg = "<input class='center' type='image' src='images/smallenv.png' alt='"._("Environment")."'
177 name='user_edit_%KEY%-environment' title='"._("Edit environment properties")."'>";
178 $mailimg = "<input class='center' type='image' src='images/mailto.png' alt='"._("Mail")."'
179 name='user_edit_%KEY%-mailAccount' title='"._("Edit mail properties")."'>";
180 $fonimg = "<input class='center' type='image' src='images/%image%' alt='"._("Phone")."'
181 name='user_edit_%KEY%-phoneAccount' title='"._("Edit phone properties")."%title%'>";
182 $faximg = "<input class='center' type='image' src='images/fax_small.png' alt='"._("Fax")."'
183 name='user_edit_%KEY%-gofaxAccount' title='"._("Edit fax properies")."'>";
184 $sambaimg = "<input class='center' type='image' src='images/select_winstation.png' alt='"._("Samba")."'
185 name='user_edit_%KEY%-sambaAccount' title='"._("Edit samba properties")."'>";
186 $netatalkimg = "<input class='center' type='image' src='images/select_netatalk.png' alt='"._("Netatalk")."'
187 name='user_edit_%KEY%-netatalk' title='"._("Edit netatalk properties")."'>";
188 $tplcreateuserimg = "<input type='image' class='center' src='images/list_new.png' alt='"._("Create user from template")."'
189 name='userfrom_tpl_%KEY%' title='"._("Create user with this template")."'>";
191 /********************
192 END :: Variable init
193 ********************/
195 /* Get Configuration for goFon DB (if it is set), to connect to the asterisk tables.
196 * Read Sip Table for specified account (for each user with phoneAccount).
197 * Check the attributes ip port and regseconds.
198 * If regseconds is set and >0 , the phone is logged in.
199 * Else the phone is currently not logged.
200 * If we can't read any Data from the DB or there is no goFon DB specified
201 * show old style without status icons.
202 */
203 $r_db =false;
204 $r_con =false;
205 if (isset($_SESSION['config']->data['SERVERS']['FON'])){
206 $a_SETUP= $_SESSION['config']->data['SERVERS']['FON'];
207 $r_con = false;
208 $r_db = false;
209 if(is_callable("mysql_pconnect")){
210 $r_con= @mysql_pconnect($a_SETUP['SERVER'],$a_SETUP['LOGIN'],$a_SETUP['PASSWORD']);
211 // Check if we are connected correctly
212 if($r_con){
213 $r_db = @mysql_select_db($a_SETUP['DB'],$r_con);
214 }
215 }
216 }
219 /********************
220 Append entries to divlist
221 ********************/
223 // Test Every Entry and generate divlist Array
224 foreach($list as $key => $val){
226 /* Create action icons */
227 $action = $this->GetSnapShotActions($val['dn']);
228 if($this->parent->CopyPasteHandler){
229 $action .= "<input class='center' type='image'
230 src='images/editcut.png' alt='"._("cut")."' name='cut_%KEY%' title='"._("Cut this entry")."'> ";
231 $action.= "<input class='center' type='image'
232 src='images/editcopy.png' alt='"._("copy")."' name='copy_%KEY%' title='"._("Copy this entry")."'> ";
233 }
234 $action.= "<input class='center' type='image' src='images/edit.png' alt='"._("edit")."'
235 name='user_edit_%KEY%' title='"._("Edit user")."'>";
236 $action.= "<input class='center' type='image' src='images/list_password.png' alt='"._("password")."'
237 name='user_chgpw_%KEY%' title='"._("Change password")."'>";
238 $action.= "<input class='center' type='image' src='images/edittrash.png' alt='"._("delete")."'
239 name='user_del_%KEY%' title='"._("Delete user")."'>";
242 /* Create phonaccopunt informationm, if conencted && is phoneAccount */
243 $connected = ""; // This string represents timestamp or offline status
244 $ip_port = ""; // String that will represent ip : port of the connected phone
245 if((in_array("goFonAccount" ,$val['objectClass']))){
247 /* Set defaults */
248 $fonac = preg_replace("/%image%/", "select_phone.png", $fonimg);
249 $fonac = preg_replace("/%KEY%/", "$key", $fonac);
250 $fonac = preg_replace("/%title%/", "", $fonac);
252 /* Database connection is ok ?*/
253 if(($r_db)&&(is_callable("mysql_query"))){
254 $res= @mysql_query("SELECT regseconds,name,port,ipaddr FROM ".$a_SETUP['SIP_TABLE']." WHERE (name='".$val['uid'][0]."')");
255 $mysql_entry = @mysql_fetch_row($res);
256 if(is_array($mysql_entry)){
257 if((isset($mysql_entry[0]))&&($mysql_entry[0]>1)){
258 $connected = " | "._("Online")." : ".gmdate("d.m.Y H:i:s",($mysql_entry[0]+(60*60)));
259 $fonac = preg_replace("/%image%/", "select_phone_connected.png", $fonimg);
260 $fonac = preg_replace("/%KEY%/", "$key", $fonac);
261 $fonac = preg_replace("/%title%/", $connected, $fonac);
262 $ip_port= " - ".$mysql_entry[3].":".$mysql_entry[2];
263 }
264 if((isset($mysql_entry[0]))&&($mysql_entry[0]==0)){
265 $connected = " | "._("Offline");
266 $fonac = preg_replace("/%image%/", "select_phone.png", $fonimg);
267 $fonac = preg_replace("/%KEY%/", "$key", $fonac);
268 $fonac = preg_replace("/%title%/", $connected, $fonac);
269 }
270 }
271 }
272 }else{
273 $fonac=$empty;
274 }
276 /* Set images for different types of objectClasses */
277 foreach($possibleAccounts as $objectClass => $Settigns){
278 if(in_array($objectClass ,$val['objectClass'])){
279 $$Settigns['VAR'] = preg_replace("/%KEY%/", "$key", $$Settigns['IMG']);
280 }else{
281 $$Settigns['VAR'] = $empty;
282 }
283 }
285 /* Create userimg */
286 if(in_array("gosaUserTemplate",$val['objectClass'])){
287 $tpl = preg_replace("/%KEY%/", "$key", $tplimg);
288 $s_img_create_from_template = preg_replace("/%KEY%/", "$key", $tplcreateuserimg);
289 }else{
290 $s_img_create_from_template = "";
291 $tpl = $userimg;
292 }
294 /* Insert key into userimg */
295 $usrimg2 = preg_replace("/%KEY%/", "$key", $usrimg);
297 // Generate caption for rows
298 if (isset($val["sn"]) && isset($val["givenName"])){
299 $display= $val["sn"][0].", ".$val["givenName"][0]." [".$val["uid"][0]."]";
300 } else {
301 $display= "[".$val["uid"][0]."]";
302 }
304 /* Connect all images */
305 $UseImg = $usrimg2." ".$posix." ".$enviro." ".$maila." ".$fonac." ".$faxac." ".$samba." ".$netatalk;
307 /* Create each field */
308 $field1 = array("string" => sprintf($tpl,$val['dn']), "attach" => "style='text-align:center;width:20px;'");
309 $field2 = array("string" => sprintf($editlink,$key,$display).$ip_port, "attach" => "style='' title='".preg_replace('/ /', ' ', @LDAP::fix($val['dn']))."'");
310 $field3 = array("string" => $UseImg, "attach" => "style='width:152px;'");
311 $field4 = array("string" => $s_img_create_from_template.preg_replace("/%KEY%/", "$key", $action),
312 "attach" => "style='width:132px;border-right:0px; text-align:right;'");
313 /* Add to list */
314 $add = array($field1,$field2,$field3,$field4);
315 $this->AddElement($add);
317 // Template or User
318 if(in_array("gosaUserTemplate",$val['objectClass'])){
319 $tpls[strtolower( $val['sn']['0'].$val['uid']['0'])]=$add;
320 }else{
321 $users[strtolower( $val['sn']['0'].$val['uid']['0'])]=$add;
322 }
323 }
325 /* close database connection, if it was opened */
326 if(isset($r_con)){
327 if((is_callable("mysql_close"))&&($r_con)){
328 @mysql_close($r_con);
329 }
330 }
332 }
334 function Save()
335 {
336 MultiSelectWindow :: Save();
337 }
339 function save_object()
340 {
341 /* Save automatic created POSTs like regex, checkboxes */
342 MultiSelectWindow::save_object();
343 }
344 }
345 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
346 ?>