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'> ".
95 " <input class='center' type='image' align='middle' src='images/list_back.png'
96 title='"._("Go up one department")."' alt='"._("Up")."' name='RestoreDeletedSnapShot'>".
97 " <img class='center' src='images/list_seperator.png' align='middle' alt='' height='16' width='1'> ".
98 " <input class='center' type='image' align='middle' src='images/select_new_terminal.png'
99 name='newsystem_terminal' alt='"._("New Terminal template")."' title='"._("New Terminal")."'>".
100 " <input class='center' type='image' align='middle' src='images/select_new_workstation.png'
101 name='newsystem_workstation' alt='"._("New Workstation template")."' title='"._("New Workstation")."'>".
102 " <input class='center' type='image' align='middle' src='images/select_new_server.png' name='newsystem_server' alt='"._("New Server")."'
103 title='"._("New Server")."'>".
104 " <input class='center' type='image' align='middle' src='images/select_new_printer.png' name='newsystem_printer' alt='"._("New Printer")."'
105 title='"._("New Printer")."'>".
106 " <input class='center' type='image' align='middle' src='images/select_new_phone.png' name='newsystem_phone' alt='"._("New Phone")."'
107 title='"._("New Phone")."'>".
108 " <input class='center' type='image' align='middle' src='images/select_new_component.png' name='newsystem_component' alt='"._("New Component")."'
109 title='"._("New Component")."'>".
110 " <img class='center' src='images/list_seperator.png' align='middle' alt='' height='16' width='1'> "._("Base")." ".
111 " <select name='CurrentMainBase' onChange='mainform.submit()' class='center'>$options</select>".
112 " <input class='center' type='image' src='images/list_submit.png' align='middle'
113 title='"._("Submit department")."' name='submit_department' alt='". _("Submit")."'> ".
114 "</div>";
115 $this->SetListHeader($listhead);
116 }
118 function execute()
119 {
120 $this->ClearElementsList();
121 $this->GenHeader();
122 }
125 function GetSnapShotActions($dn)
126 {
127 $str = "";
128 $str .="<input class='center' type='image' src='images/snapshot.png'
129 alt='"._("Create snapshot")."' name='CreateSnapShot_".base64_encode($dn)."' title='"._("Create snapshot")."'> ";
131 if(count($this->parent->Available_SnapsShots($dn))){
132 $str .="<input class='center' type='image' src='images/restore.png'
133 alt='"._("Restore snapshot")."' name='RestoreSnapShot_".base64_encode($dn)."' title='"._("Restore snapshot")."'> ";
134 }else{
135 $str.= "<img src='images/empty.png' style='width:16px;' class='center'> ";
136 }
137 return($str);
138 }
140 function setEntries($terminals)
141 {
142 $img1 = "<img class='center' src='images/printer.png' alt='C' title='"._("Cups Server") ."'>";
143 $img2 = "<img class='center' src='images/scanner.png' alt='L' title='"._("Log Db") ."'>";
144 $img3 = "<img class='center' src='images/select_terminal.png' alt='L' title='"._("Syslog Server") ."'>";
145 $img4 = "<img class='center' src='images/mailto.png' alt='M' title='"._("Mail Server") ."'>";
146 $img5 = "<img class='center' src='images/select_phone.png' alt='I' title='"._("Imap Server") ."'>";
147 $img6 = "<img class='center' src='images/fax_small.png' alt='F' title='"._("Nfs Server") ."'>";
148 $img7 = "<img class='center' src='images/select_winstation.png' alt='K' title='"._("Kerberos Server") ."'>";
149 $img8 = "<img class='center' src='images/select_phone.png' alt='A' title='"._("Asterisk Server") ."'>";
150 $img9 = "<img class='center' src='images/fax_small.png' alt='F' title='"._("Fax Server") ."'>";
151 $img10 = "<img class='center' src='images/save.png' alt='L' title='"._("Ldap Server") ."'>";
153 $empty =" ";
155 // User and Template Images
156 $editlink = "<a href='?plug=".$_GET['plug']."&id=%s&act=edit_entry'>%s</a>";
158 // Test Every Entry and generate divlist Array
159 foreach($terminals as $key => $val){
161 $action = $this->GetSnapShotActions($val['dn']);
162 $action.= "<input class='center' type='image' src='images/edit.png' alt='"._("edit")."' name='user_edit_%KEY%' title='"._("Edit system")."'>";
163 $action.= "<input class='center' type='image' src='images/edittrash.png' alt='"._("delete")."' name='user_del_%KEY%' title='"._("Delete system")."'>";
165 /* Generate picture list, which is currently disabled */
166 if(in_array("goCupsServer" ,$val['objectClass'])) $cups = $img1; else $cups =$empty;
167 if(in_array("goLogDBServer" ,$val['objectClass'])) $logdb = $img2; else $logdb =$empty;
168 if(in_array("goSyslogServer" ,$val['objectClass'])) $syslog = $img3; else $syslog=$empty;
169 if(in_array("goImapServer" ,$val['objectClass'])) $imap = $img4; else $imap =$empty;
170 if(in_array("sambaSamAccount" ,$val['objectClass'])) $samba = $img5; else $samba =$empty;
171 if(in_array("goShareServer" ,$val['objectClass'])) $nfs = $img6; else $nfs =$empty;
172 if(in_array("goKrbServer" ,$val['objectClass'])) $krb = $img7; else $krb =$empty;
173 if(in_array("goFonServer" ,$val['objectClass'])) $fon = $img8; else $fon =$empty;
174 if(in_array("goFaxServer" ,$val['objectClass'])) $fax = $img9; else $fax =$empty;
175 if(in_array("goLdapServer" ,$val['objectClass'])) $ldap = $img10; else $ldap =$empty;
177 $pics = $cups.$logdb.$syslog.$imap.$samba.$nfs.$krb.$fon.$fax.$ldap;
178 $pics = ""; // Pictures currently hidden
180 $val['cn'][0]= preg_replace('/\$$/', '', $val['cn'][0]);
182 // Generate Array to Add
183 $dsc= "";
184 if (isset($val['description'][0])){
185 $dsc= " [".$val['description'][0]."]";
186 }
187 if((isset($val['is_new']))&&(!empty($val['is_new']))){
188 $display= $val["cn"][0]." ".$val['is_new'].$dsc;
189 }else{
190 $display= $val["cn"][0].$dsc;
191 }
193 if((in_array("gotoTerminal",$val['objectClass']))||(in_array("gotoWorkstation",$val['objectClass']))){
194 $action2 = "<input class='center' type='image' src='images/certs.png' alt='"._("Password")."' name='user_setpwd_%KEY%' title='"._("Set root password")."'>";
195 }else{
196 $action2 = "";
197 }
199 if(isset($val['message'])){
200 $display.= " (".$val['message']." '".$this->config->idepartments[$_SESSION['CurrentMainBase']]."' )";
201 }
203 $img = $this->parent->convert_list($val);
204 $field1 = array("string" => sprintf($img['img'],$val['dn']), "attach" => "style='text-align:center;width:20px;'");
205 $field2 = array("string" => sprintf($editlink,$key,$display), "attach" => "style='' title='".preg_replace('/ /', ' ', @LDAP::fix($val['dn']))."'");
206 $field3 = array("string" => preg_replace("/%KEY%/", "$key", $action2.$action), "attach" => "style='width:90px;border-right:0px;text-align:right;'");
207 $this->AddElement( array($field1,$field2,$field3));
208 }
210 }
213 function Save()
214 {
215 MultiSelectWindow :: Save();
216 }
219 function save_object()
220 {
221 /* Save automatic created POSTs like regex, checkboxes */
222 MultiSelectWindow :: save_object();
225 /* check for posts */
226 $once = true;
227 foreach($_POST as $name => $value){
229 /* Create a new snapshot, display a dialog */
230 if(preg_match("/^CreateSnapShot_/",$name) && $once){
231 $once = false;
232 $entry = preg_replace("/^CreateSnapShot_/","",$name);
233 $entry = base64_decode(preg_replace("/_[xy]$/","",$entry));
234 $this->parent->systab = new SnapShotDialog($this->config,$entry,$this->parent);
235 }
237 /* Restore a snapshot, display a dialog with all snapshots of the current object */
238 if(preg_match("/^RestoreSnapShot_/",$name) && $once){
239 $once = false;
240 $entry = preg_replace("/^RestoreSnapShot_/","",$name);
241 $entry = base64_decode(preg_replace("/_[xy]$/","",$entry));
242 $this->parent->systab = new SnapShotDialog($this->config,$entry,$this->parent);
243 $this->parent->systab->Restore = true;
244 }
246 /* Restore one of the already deleted objects */
247 if(preg_match("/^RestoreDeletedSnapShot_/",$name) && $once){
248 $once = false;
249 $entry = "ou=systems,".$this->selectedBase;
250 $this->parent->systab = new SnapShotDialog($this->config,$entry,$this->parent);
251 $this->parent->systab->Restore = true;
252 $this->parent->systab->DeletedOnes = true;
253 }
254 }
256 /* Create a new snapshot requested, check
257 the given attributes and create the snapshot*/
258 if(isset($_POST['CreateSnapshot'])){
259 $this->parent->systab->save_object();
260 $msgs = $this->parent->systab->check();
261 if(count($msgs)){
262 foreach($msgs as $msg){
263 print_red($msg);
264 }
265 }else{
266 $this->parent->dn = $this->parent->systab->dn;
267 $this->parent->create_snapshot("snapshot",$this->parent->systab->CurrentDescription);
268 $this->parent->systab = NULL;
269 }
270 }
272 /* Restore is requested, restore the object with the posted dn .*/
273 if((isset($_POST['RestoreSnapshot'])) && (isset($_POST['SnapShot']))){
274 $entry = base64_decode($_POST['SnapShot']);
275 $this->parent->restore_snapshot($entry);
276 $this->parent->systab = NULL;
277 }
278 }
279 }
280 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
281 ?>