Code

59ca111bdb2dd310a6913ba6418e5bca28a5ddc7
[gosa.git] / plugins / admin / systems / class_divListSystem.inc
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 */
15   var $ShowServers        = true;
16   var $ShowTerminals      = true;
17   var $ShowWorkstations   = true;
18   var $ShowWinWorkstations= true;
19   var $ShowPrinters       = true;
20   var $ShowDevices        = true;
21   var $ShowPhones         = true;
23   var $parent             ;
24   var $ui                 ;
26   function divListSystem ($config,$parent)
27   {
28     MultiSelectWindow::MultiSelectWindow($config,"System");
29     
30     $this->parent       = $parent;
31     $this->ui           = get_userinfo();
33     /* Set default base */
34     if(!isset($_SESSION['CurrentMainBase'])){
35       $_SESSION['CurrentMainBase'] = $this->config->current['BASE'];
36     }
37     $this->selectedBase = $_SESSION['CurrentMainBase'];
39     /* Set list strings */
40     $this->SetTitle(_("List of systems"));
41     $this->SetSummary(_("List of systems"));
43     /* Result page will look like a headpage */
44     $this->SetHeadpageMode();
45     $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."));
47     $this->EnableAplhabet   (true);
48   
49     /* Disable buttonsm */
50     $this->EnableCloseButton(false);
51     $this->EnableSaveButton (false);
53     /* set Page header */
54     $this->AddHeader(array("string"=>"&nbsp;","attach"=>"style='width:20px;'"));
55     $this->AddHeader(array("string"=>_("System / Department")));
56     $this->AddHeader(array("string"=>_("Actions"),"attach"=>"style='width:60px;border-right:0px;'"));
58     /*                  Text        ,Value    ,Name         ,Is selected */
59     $this->AddCheckBox("ShowServers",         _("Select to see servers"),            _("Show servers"),          true);
60     $this->AddCheckBox("ShowTerminals",       _("Select to see Linux terminals"),    _("Show terminals") ,       true);
61     $this->AddCheckBox("ShowWorkstations",    _("Select to see Linux workstations"), _("Show workstations"),     true);
62     $this->AddCheckBox("ShowWinWorkstations", _("Select to see MicroSoft Windows based workstations"), _("Show windows based workstations"),true);
63     $this->AddCheckBox("ShowPrinters",        _("Select to see network printers"),    _("Show network printers") ,true);
64     $this->AddCheckBox("ShowPhones",          _("Select to see VOIP phones"),         _("Show phones") ,          true);
65     $this->AddCheckBox("ShowDevices",         _("Select to see network devices"),     _("Show network devices"),  true);
67     /*                  Name                 ,Text                              ,Default  , Connect with alphabet  */
68     $this->AddRegex   ("Regex",     _("Display systems matching"),"*" , true);
69     $this->AddRegex   ("UserRegex", _("Display systems of user"), "*" , false, "images/search_user.png");
70   }
72   function GenHeader()
73   {
74     /* Prepare departments,
75        which are shown in the listbox on top of the listbox
76      */
77     $options= "";
78     foreach ($this->config->idepartments as $key => $value){
79       if ($this->selectedBase == $key){
80         $options.= "<option selected='selected' value='$key'>$value</option>";
81       } else {
82         $options.= "<option value='$key'>$value</option>";
83       }
84     }
85     $listhead = "<div style='background:#F0F0F9;padding:5px;'>".
86     " <input class='center' type='image' src='images/list_root.png' align='middle'
87         title='"._("Go to root department")."' name='dep_root' alt='"._("Root")."'>&nbsp;".
88     " <input class='center' type='image' align='middle' src='images/list_back.png'
89         title='"._("Go up one department")."' alt='"._("Up")."' name='dep_back'>&nbsp;".
90     " <input class='center' type='image' align='middle' src='images/list_home.png'
91         title='"._("Go to users department")."' alt='"._("Home")."'                     name='dep_home'>&nbsp;".
92     " <input class='center' type='image' src='images/list_reload.png' align='middle' title='"._("Reload list")."' name='submit_department' alt='".          _("Submit")."'>&nbsp;".
93     " <img class='center' src='images/list_seperator.png' align='middle' alt='' height='16' width='1'>&nbsp;".
94     " <input class='center' type='image' align='middle' src='images/select_new_terminal.png'
95         name='newsystem_terminal'    alt='"._("New Terminal template")."' title='"._("New Terminal")."'>".
96     " <input class='center' type='image' align='middle' src='images/select_new_workstation.png'
97         name='newsystem_workstation' alt='"._("New Workstation template")."' title='"._("New Workstation")."'>".
98     " <input class='center' type='image' align='middle' src='images/select_new_server.png'     name='newsystem_server'      alt='"._("New Server")."'
99         title='"._("New Server")."'>".
100     " <input class='center' type='image' align='middle' src='images/select_new_printer.png'    name='newsystem_printer'     alt='"._("New Printer")."'
101         title='"._("New Printer")."'>".
102     " <input class='center' type='image' align='middle' src='images/select_new_phone.png'      name='newsystem_phone'       alt='"._("New Phone")."'
103         title='"._("New Phone")."'>".
104     " <input class='center' type='image' align='middle' src='images/select_new_component.png'  name='newsystem_component'   alt='"._("New Component")."'
105         title='"._("New Component")."'>".
106     " <img class='center' src='images/list_seperator.png' align='middle' alt='' height='16' width='1'>&nbsp;"._("Base")."&nbsp;".
107     " <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>";
111     $this->SetListHeader($listhead);
112   }
114   function execute()
115   {
116     $this->ClearElementsList();
117     $this->GenHeader();
118     $this->AddDepartments($this->selectedBase);
119   }
121   function setEntries($terminals)
122   {
123     $img1  = "<img class='center' src='images/printer.png'            alt='C' title='"._("Cups Server")  ."'>";
124     $img2  = "<img class='center' src='images/scanner.png'            alt='L' title='"._("Log Db") ."'>";
125     $img3  = "<img class='center' src='images/select_terminal.png'    alt='L' title='"._("Syslog Server") ."'>";
126     $img4  = "<img class='center' src='images/mailto.png'             alt='M' title='"._("Mail Server")  ."'>";
127     $img5  = "<img class='center' src='images/select_phone.png'       alt='I' title='"._("Imap Server") ."'>";
128     $img6  = "<img class='center' src='images/fax_small.png'          alt='F' title='"._("Nfs Server")   ."'>";
129     $img7  = "<img class='center' src='images/select_winstation.png'  alt='K' title='"._("Kerberos Server") ."'>";
130     $img8  = "<img class='center' src='images/select_phone.png'       alt='A' title='"._("Asterisk Server") ."'>";
131     $img9  = "<img class='center' src='images/fax_small.png'          alt='F' title='"._("Fax Server") ."'>";
132     $img10 = "<img class='center' src='images/save.png'               alt='L' title='"._("Ldap Server") ."'>";
134     $empty    ="&nbsp;";
135     $action= "<input class='center' type='image' src='images/edit.png' alt='"._("edit")."'     name='user_edit_%KEY%' title='"._("Edit system")."'>";
136     $action.= "<input class='center' type='image' src='images/edittrash.png' alt='"._("delete")."'   name='user_del_%KEY%' title='"._("Delete system")."'>";
138     // User and Template  Images
139     $editlink = "<a href='?plug=".$_GET['plug']."&amp;id=%s&amp;act=edit_entry'>%s</a>";
141     // Test Every Entry and generate divlist Array
142     foreach($terminals as $key => $val){
143  
144       /* Generate picture list, which is currently disabled */
145       if(in_array("goCupsServer"    ,$val['objectClass'])) $cups    = $img1;   else $cups  =$empty;
146       if(in_array("goLogDBServer"   ,$val['objectClass'])) $logdb   = $img2;   else $logdb =$empty;
147       if(in_array("goSyslogServer"  ,$val['objectClass'])) $syslog  = $img3;   else $syslog=$empty;
148       if(in_array("goImapServer"    ,$val['objectClass'])) $imap    = $img4;   else $imap  =$empty;
149       if(in_array("sambaSamAccount" ,$val['objectClass'])) $samba   = $img5;   else $samba =$empty;
150       if(in_array("goShareServer"   ,$val['objectClass'])) $nfs     = $img6;   else $nfs   =$empty;
151       if(in_array("goKrbServer"     ,$val['objectClass'])) $krb     = $img7;   else $krb   =$empty;
152       if(in_array("goFonServer"     ,$val['objectClass'])) $fon     = $img8;   else $fon   =$empty;
153       if(in_array("goFaxServer"     ,$val['objectClass'])) $fax     = $img9;   else $fax   =$empty;
154       if(in_array("goLdapServer"    ,$val['objectClass'])) $ldap     = $img10;   else $ldap   =$empty;
155       
156       $pics = $cups.$logdb.$syslog.$imap.$samba.$nfs.$krb.$fon.$fax.$ldap;
157       $pics = ""; // Pictures currently hidden
159       $val['cn'][0]= preg_replace('/\$$/', '', $val['cn'][0]);
161       // Generate Array to Add
162       if((isset($val['is_new']))&&(!empty($val['is_new']))){
163         $display= "".$val["cn"][0]." ".$val['is_new'];
164       }else{
165         $display= "".$val["cn"][0]."";
166       }
168       if((in_array("gotoTerminal",$val['objectClass']))||(in_array("gotoWorkstation",$val['objectClass']))){
169         $action2 = "<input class='center' type='image' src='images/certs.png' alt='"._("Password")."'   name='user_setpwd_%KEY%' title='"._("Set root       password")."'>";
170       }else{
171         $action2 = "";
172       }
174       if(isset($val['message'])){
175         $display.= "  (".$val['message']." '".$this->config->idepartments[$_SESSION['CurrentMainBase']]."'  )";
176       }
178       $img    = $this->parent->convert_list($val);
179       $field1 = array("string" => sprintf($img['img'],$val['dn']), "attach" => "style='text-align:center;width:20px;'");
180       $field2 = array("string" => sprintf($editlink,$key,$display), "attach" => "style='' title='".@LDAP::fix($val['dn'])."'");
181       $field3 = array("string" => preg_replace("/%KEY%/", "$key", $action2.$action), "attach" => "style='width:60px;border-right:0px;text-align:right;'");
182       $this->AddElement( array($field1,$field2,$field3));
183     }
185   }
187   function Save()
188   {
189     MultiSelectWindow :: Save();  
190   }
192   function save_object()
193   {
194     /* Save automatic created POSTs like regex, checkboxes */
195     MultiSelectWindow::save_object();   
197     $s_action ="";
198     foreach($_POST as $key => $value){
199       if(preg_match("/^dep_back.*/i",$key)){
200         $s_action="back";
201       }elseif(preg_match("/^dep_root.*/",$key)){
202         $s_action="root";
203       }elseif(preg_match("/^dep_home.*/i",$key)){
204         $s_action="home";
205       }
206     }
207    
208     /* Save base selection from headpage selectbox*/ 
209     if(isset($_POST['CurrentMainBase'])){
210       $this->selectedBase = $_POST['CurrentMainBase'];
211     }
213     /* Homebutton is posted */
214     if($s_action=="home"){
215       $ui= get_userinfo();
216       $this->selectedBase=(preg_replace("/^[^,]+,/","",$ui->dn));
217       $this->selectedBase=(preg_replace("/^[^,]+,/","",$this->selectedBase));
218     }
220     /* Open selected department 
221        this is posted by the parent class MultiSelectWindow */
222     if(isset($_GET['act'])&& ($_GET['act'] == "dep_open")){
223       $s_entry = base64_decode($_GET['dep_id']);
224       $this->selectedBase = $this->config->departments[trim($s_entry)];
225     }
227     /* back to the roots ^^ */
228     if($s_action=="root"){
229       $this->selectedBase=($this->config->current['BASE']);
230     }
232     /* If Backbutton is Posted */
233     if($s_action=="back"){
234       $base_back          = preg_replace("/^[^,]+,/","",$this->selectedBase);
235       $base_back          = convert_department_dn($base_back);
236       if(isset($this->config->departments[trim($base_back)])){
237         $this->selectedBase= $this->config->departments[trim($base_back)];
238       }else{
239         $this->selectedBase= $this->config->departments["/"];
240       }
241     }
243     $_SESSION['CurrentMainBase']  = $this->selectedBase;
244   }
246 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
247 ?>