1 <?php
3 class divListSystem extends MultiSelectWindow
4 {
6 /* Current base */
7 var $selectedBase = "";
8 var $departments = array();
10 /* Regex */
11 var $Regex = "*";
12 var $UserRegex = "*";
14 /* CheckBoxes, to change default values modify $this->AddCheckBox */
15 var $ShowServers;
16 var $ShowTerminals;
17 var $ShowWorkstations;
18 var $ShowWinWorkstations;
19 var $ShowPrinters;
20 var $ShowDevices;
21 var $ShowPhones;
23 /* Subsearch checkbox */
24 var $SubSearch;
26 var $parent ;
27 var $ui ;
29 function divListSystem ($config,$parent)
30 {
31 MultiSelectWindow::MultiSelectWindow($config,"System");
33 $this->parent = $parent;
34 $this->ui = get_userinfo();
36 /* Set list strings */
37 $this->SetTitle(_("List of systems"));
38 $this->SetSummary(_("List of systems"));
40 /* Result page will look like a headpage */
41 $this->SetHeadpageMode();
42 $this->SetInformation(_("This menu allows you to add, remove and change the properties of specific systems. You can only add systems which have already been started once."));
44 $this->EnableAplhabet (true);
46 /* Disable buttonsm */
47 $this->EnableCloseButton(false);
48 $this->EnableSaveButton (false);
50 /* set Page header */
51 $this->AddHeader(array("string"=>" ","attach"=>"style='width:20px;'"));
52 $this->AddHeader(array("string"=>_("System / Department")));
53 $this->AddHeader(array("string"=>_("Actions"),"attach"=>"style='width:90px;border-right:0px;'"));
55 /* Text ,Value ,Name ,Is selected */
56 $this->AddCheckBox("ShowServers", _("Select to see servers"), _("Show servers"), true);
57 $this->AddCheckBox("ShowTerminals", _("Select to see Linux terminals"), _("Show terminals") , true);
58 $this->AddCheckBox("ShowWorkstations", _("Select to see Linux workstations"), _("Show workstations"), true);
59 $this->AddCheckBox("ShowWinWorkstations", _("Select to see MicroSoft Windows based workstations"), _("Show windows based workstations"),true);
60 $this->AddCheckBox("ShowPrinters", _("Select to see network printers"), _("Show network printers") ,true);
61 $this->AddCheckBox("ShowPhones", _("Select to see VOIP phones"), _("Show phones") , true);
62 $this->AddCheckBox("ShowDevices", _("Select to see network devices"), _("Show network devices"), true);
64 /* Add SubSearch checkbox */
65 $this->AddCheckBox(SEPERATOR);
66 $this->AddCheckBox("SubSearch", _("Select to search within subtrees"), _("Ignore subtrees"), false);
68 /* Name ,Text ,Default , Connect with alphabet */
69 $this->AddRegex ("Regex", _("Display systems matching"),"*" , true);
70 $this->AddRegex ("UserRegex", _("Display systems of user"), "*" , false, "images/search_user.png");
71 }
73 function GenHeader()
74 {
75 /* Prepare departments,
76 which are shown in the listbox on top of the listbox
77 */
78 $options= "";
79 foreach ($this->config->idepartments as $key => $value){
80 if ($this->selectedBase == $key){
81 $options.= "<option selected='selected' value='$key'>$value</option>";
82 } else {
83 $options.= "<option value='$key'>$value</option>";
84 }
85 }
86 $listhead = "<div style='background:#F0F0F9;padding:5px;'>".
87 " <input class='center' type='image' src='images/list_root.png' align='middle'
88 title='"._("Go to root department")."' name='dep_root' alt='"._("Root")."'> ".
89 " <input class='center' type='image' align='middle' src='images/list_back.png'
90 title='"._("Go up one department")."' alt='"._("Up")."' name='dep_back'> ".
91 " <input class='center' type='image' align='middle' src='images/list_home.png'
92 title='"._("Go to users department")."' alt='"._("Home")."' name='dep_home'> ".
93 " <input class='center' type='image' src='images/list_reload.png' align='middle' title='"._("Reload list")."' name='submit_department' alt='". _("Submit")."'> ".
94 " <img class='center' src='images/list_seperator.png' align='middle' alt='' height='16' width='1'> ";
96 if($this->parent->snapshotEnabled()){
97 $listhead .= " <input class='center' type='image' align='middle' src='images/restore.png'
98 title='"._("Restore objects")."' alt='"._("Up")."' name='RestoreDeletedSnapShot'>".
99 " <img class='center' src='images/list_seperator.png' align='middle' alt='' height='16' width='1'> ";
100 }
102 $listhead .= " <input class='center' type='image' align='middle' src='images/select_new_terminal.png'
103 name='newsystem_terminal' alt='"._("New Terminal template")."' title='"._("New Terminal")."'>".
104 " <input class='center' type='image' align='middle' src='images/select_new_workstation.png'
105 name='newsystem_workstation' alt='"._("New Workstation template")."' title='"._("New Workstation")."'>".
106 " <input class='center' type='image' align='middle' src='images/select_new_server.png' name='newsystem_server' alt='"._("New Server")."'
107 title='"._("New Server")."'>".
108 " <input class='center' type='image' align='middle' src='images/select_new_printer.png' name='newsystem_printer' alt='"._("New Printer")."'
109 title='"._("New Printer")."'>".
110 " <input class='center' type='image' align='middle' src='images/select_new_phone.png' name='newsystem_phone' alt='"._("New Phone")."'
111 title='"._("New Phone")."'>".
112 " <input class='center' type='image' align='middle' src='images/select_new_component.png' name='newsystem_component' alt='"._("New Component")."'
113 title='"._("New Component")."'>".
114 " <img class='center' src='images/list_seperator.png' align='middle' alt='' height='16' width='1'> "._("Base")." ".
115 " <select name='CurrentMainBase' onChange='mainform.submit()' class='center'>$options</select>".
116 " <input class='center' type='image' src='images/list_submit.png' align='middle'
117 title='"._("Submit department")."' name='submit_department' alt='". _("Submit")."'> ".
118 "</div>";
119 $this->SetListHeader($listhead);
120 }
122 function execute()
123 {
124 $this->ClearElementsList();
125 $this->GenHeader();
126 }
129 function GetSnapShotActions($dn)
130 {
131 $str = "";
133 if($this->parent->snapshotEnabled()){
135 $str .="<input class='center' type='image' src='images/snapshot.png'
136 alt='"._("Create snapshot")."' name='CreateSnapShot_".base64_encode($dn)."' title='"._("Create snapshot")."'> ";
138 if(count($this->parent->Available_SnapsShots($dn))){
139 $str .="<input class='center' type='image' src='images/restore.png'
140 alt='"._("Restore snapshot")."' name='RestoreSnapShot_".base64_encode($dn)."' title='"._("Restore snapshot")."'> ";
141 }else{
142 $str.= "<img src='images/empty.png' style='width:16px;' class='center'> ";
143 }
144 }
145 return($str);
146 }
148 function setEntries($terminals)
149 {
150 $img1 = "<img class='center' src='images/printer.png' alt='C' title='"._("Cups Server") ."'>";
151 $img2 = "<img class='center' src='images/scanner.png' alt='L' title='"._("Log Db") ."'>";
152 $img3 = "<img class='center' src='images/select_terminal.png' alt='L' title='"._("Syslog Server") ."'>";
153 $img4 = "<img class='center' src='images/mailto.png' alt='M' title='"._("Mail Server") ."'>";
154 $img5 = "<img class='center' src='images/select_phone.png' alt='I' title='"._("Imap Server") ."'>";
155 $img6 = "<img class='center' src='images/fax_small.png' alt='F' title='"._("Nfs Server") ."'>";
156 $img7 = "<img class='center' src='images/select_winstation.png' alt='K' title='"._("Kerberos Server") ."'>";
157 $img8 = "<img class='center' src='images/select_phone.png' alt='A' title='"._("Asterisk Server") ."'>";
158 $img9 = "<img class='center' src='images/fax_small.png' alt='F' title='"._("Fax Server") ."'>";
159 $img10 = "<img class='center' src='images/save.png' alt='L' title='"._("Ldap Server") ."'>";
161 $empty =" ";
163 // User and Template Images
164 $editlink = "<a href='?plug=".$_GET['plug']."&id=%s&act=edit_entry'>%s</a>";
166 // Test Every Entry and generate divlist Array
167 foreach($terminals as $key => $val){
169 $action = $this->GetSnapShotActions($val['dn']);
170 $action.= "<input class='center' type='image' src='images/edit.png' alt='"._("edit")."' name='user_edit_%KEY%' title='"._("Edit system")."'>";
171 $action.= "<input class='center' type='image' src='images/edittrash.png' alt='"._("delete")."' name='user_del_%KEY%' title='"._("Delete system")."'>";
173 /* Generate picture list, which is currently disabled */
174 if(in_array("goCupsServer" ,$val['objectClass'])) $cups = $img1; else $cups =$empty;
175 if(in_array("goLogDBServer" ,$val['objectClass'])) $logdb = $img2; else $logdb =$empty;
176 if(in_array("goSyslogServer" ,$val['objectClass'])) $syslog = $img3; else $syslog=$empty;
177 if(in_array("goImapServer" ,$val['objectClass'])) $imap = $img4; else $imap =$empty;
178 if(in_array("sambaSamAccount" ,$val['objectClass'])) $samba = $img5; else $samba =$empty;
179 if(in_array("goShareServer" ,$val['objectClass'])) $nfs = $img6; else $nfs =$empty;
180 if(in_array("goKrbServer" ,$val['objectClass'])) $krb = $img7; else $krb =$empty;
181 if(in_array("goFonServer" ,$val['objectClass'])) $fon = $img8; else $fon =$empty;
182 if(in_array("goFaxServer" ,$val['objectClass'])) $fax = $img9; else $fax =$empty;
183 if(in_array("goLdapServer" ,$val['objectClass'])) $ldap = $img10; else $ldap =$empty;
185 $pics = $cups.$logdb.$syslog.$imap.$samba.$nfs.$krb.$fon.$fax.$ldap;
186 $pics = ""; // Pictures currently hidden
188 $val['cn'][0]= preg_replace('/\$$/', '', $val['cn'][0]);
190 // Generate Array to Add
191 $dsc= "";
192 if (isset($val['description'][0])){
193 $dsc= " [".$val['description'][0]."]";
194 }
195 if((isset($val['is_new']))&&(!empty($val['is_new']))){
196 $display= $val["cn"][0]." ".$val['is_new'].$dsc;
197 }else{
198 $display= $val["cn"][0].$dsc;
199 }
201 if((in_array("gotoTerminal",$val['objectClass']))||(in_array("gotoWorkstation",$val['objectClass']))){
202 $action2 = "<input class='center' type='image' src='images/certs.png' alt='"._("Password")."' name='user_setpwd_%KEY%' title='"._("Set root password")."'>";
203 }else{
204 $action2 = "";
205 }
207 if(isset($val['message'])){
208 $display.= " (".$val['message']." '".$this->config->idepartments[$_SESSION['CurrentMainBase']]."' )";
209 }
211 $img = $this->parent->convert_list($val);
212 $field1 = array("string" => sprintf($img['img'],$val['dn']), "attach" => "style='text-align:center;width:20px;'");
213 $field2 = array("string" => sprintf($editlink,$key,$display), "attach" => "style='' title='".preg_replace('/ /', ' ', @LDAP::fix($val['dn']))."'");
214 $field3 = array("string" => preg_replace("/%KEY%/", "$key", $action2.$action), "attach" => "style='width:90px;border-right:0px;text-align:right;'");
215 $this->AddElement( array($field1,$field2,$field3));
216 }
218 }
221 function Save()
222 {
223 MultiSelectWindow :: Save();
224 }
227 function save_object()
228 {
229 /* Save automatic created POSTs like regex, checkboxes */
230 MultiSelectWindow :: save_object();
233 /* check for posts */
234 $once = true;
235 foreach($_POST as $name => $value){
237 /* Create a new snapshot, display a dialog */
238 if(preg_match("/^CreateSnapShot_/",$name) && $once){
239 $once = false;
240 $entry = preg_replace("/^CreateSnapShot_/","",$name);
241 $entry = base64_decode(preg_replace("/_[xy]$/","",$entry));
242 $this->parent->systab = new SnapShotDialog($this->config,$entry,$this->parent);
243 }
245 /* Restore a snapshot, display a dialog with all snapshots of the current object */
246 if(preg_match("/^RestoreSnapShot_/",$name) && $once){
247 $once = false;
248 $entry = preg_replace("/^RestoreSnapShot_/","",$name);
249 $entry = base64_decode(preg_replace("/_[xy]$/","",$entry));
250 $this->parent->systab = new SnapShotDialog($this->config,$entry,$this->parent);
251 $this->parent->systab->Restore = true;
252 }
254 /* Restore one of the already deleted objects */
255 if(preg_match("/^RestoreDeletedSnapShot_/",$name) && $once){
256 $once = false;
257 $entry = "ou=systems,".$this->selectedBase;
258 $this->parent->systab = new SnapShotDialog($this->config,$entry,$this->parent);
259 $this->parent->systab->Restore = true;
260 $this->parent->systab->DeletedOnes = true;
261 }
262 }
264 /* Create a new snapshot requested, check
265 the given attributes and create the snapshot*/
266 if(isset($_POST['CreateSnapshot'])){
267 $this->parent->systab->save_object();
268 $msgs = $this->parent->systab->check();
269 if(count($msgs)){
270 foreach($msgs as $msg){
271 print_red($msg);
272 }
273 }else{
274 $this->parent->dn = $this->parent->systab->dn;
275 $this->parent->create_snapshot("snapshot",$this->parent->systab->CurrentDescription);
276 $this->parent->systab = NULL;
277 }
278 }
280 /* Restore is requested, restore the object with the posted dn .*/
281 if((isset($_POST['RestoreSnapshot'])) && (isset($_POST['SnapShot']))){
282 $entry =trim($_POST['SnapShot']);
283 if(!empty($entry)){
284 $entry = base64_decode($entry);
285 $this->parent->restore_snapshot($entry);
286 $this->parent->systab = NULL;
287 }
288 }
289 }
290 }
291 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
292 ?>