Code

Moved goto partly
[gosa.git] / gosa-plugins / goto / admin / applications / class_divListApplication.inc
1 <?php
3 class divListApplication extends MultiSelectWindow
4 {
5   /* Current base */
6   var $selectedBase       = "";
7   var $selectedRelease    = "main";
8   var $AvailableReleases  = array();
9   var $departments        = array();
10   var $parent               ;
11   var $ui                   ;
13   /* Regex */
14   var $Regex           = "*";
16   /* Subsearch checkbox */
17   var $SubSearch;
19   var $SaveAdditionalVars = array("selectedRelease");
21   function divListApplication (&$config,&$parent)
22   {
23     MultiSelectWindow::MultiSelectWindow($config,"Application", "application");
24    
25     $this->selectedRelease = get_ou('applicationou').session::get('CurrentMainBase');
26  
27     $this->parent       = &$parent;
28     $this->ui           = get_userinfo();
30     /* Set list strings */
31     $this->SetTitle(_("List of Applications"));
32     $this->SetSummary(_("This table displays all applications in the selected tree."));
34     /* Result page will look like a headpage */
35     $this->SetHeadpageMode();
36     $this->SetInformation(_("This menu allows you to add, edit and remove selected applications. You may want to use the range selector on top of the application listbox, when working with a large number of applications."));
38     $this->EnableAplhabet(true);
39   
40     /* Disable buttonsm */
41     $this->EnableCloseButton(false);
42     $this->EnableSaveButton (false);
44     /* set Page header */
45     $action_col_size = 80;
46     if($this->parent->snapshotEnabled()){
47       $action_col_size += 38;
48     }
51     /* Toggle all selected / deselected */
52     $chk = "<input type='checkbox' id='select_all' name='select_all'
53                onClick='toggle_all_(\"^item_selected_[0-9]*$\",\"select_all\");' >";
55     /* set Page header */
56     $this->AddHeader(array("string"=> $chk,          "attach"=>"style='width:20px;'"));
57     $this->AddHeader(array("string" => "&nbsp;",                "attach" => "style='text-align:center;width:20px;'"));
58     $this->AddHeader(array("string" => _("Application name")." / "._("Department"), "attach" => "style=''"));
59     $this->AddHeader(array("string" => _("Actions"),            "attach" => "style='width:".$action_col_size."px;border-right:0px;text-align:right;'"));
61     /* Add SubSearch checkbox */
62     $this->AddCheckBox("SubSearch",  _("Select to search within subtrees"), _("Search in subtrees"), false);
64     /*                  Name                 ,Text                              ,Default  , Connect with alphabet  */
65     $this->AddRegex   ("Regex",     _("Display users matching"),"*" , true);
66   }
68   function AddUserBoxToFilter($position){
69     $str = "";
70     if(($position  == 2) && ($this->parent->IsReleaseManagementActivated($this->config))){
71       $smarty = get_smarty();
72       $smarty->assign("selectedRelease",$this->selectedRelease);
73       $smarty->assign("branchimage","images/branch.png");
74       $smarty->assign("releases",$this->AvailableReleases);
75       $str = $smarty->fetch(get_template_path('release_select.tpl', TRUE));
76     }
77     return($str);
78   }
80   function GenHeader()
81   {
82     /* Prepare departments,
83        which are shown in the listbox on top of the listbox
84     */
85     $options= "";
87     /* Get all departments within this subtree */
88     $base = $this->config->current['BASE'];
90     /* Add base */
91     $tmp = array();
92     $tmp[] = array("dn"=>$this->config->current['BASE']);
93     $tmp=  array_merge($tmp,get_list("(&(|(ou=*)(description=*))(objectClass=gosaDepartment))", $this->module, $base,
94                     array("ou", "description"), GL_SIZELIMIT | GL_SUBSEARCH));
96     $deps = array();
97     foreach($tmp as $tm){
98       $deps[$tm['dn']] = $tm['dn'];
99     }
101     /* Load possible departments */
102     $ui= get_userinfo();
103     $tdeps= $ui->get_module_departments("application");
104     $ids = $this->config->idepartments;
105     $first = "";
106     $found = FALSE;
107     foreach($ids as $dep => $name){
108       if(isset($deps[$dep]) && in_array_ics($dep, $tdeps)){
110         /* Keep first base dn in mind, we could need this
111          *  info if no valid base was found
112          */
113         if(empty($first)) {
114           $first = $dep['dn'];
115         }
117         $value = $ids[$dep];
118         if ($this->selectedBase == $dep){
119           $found = TRUE;
120           $options.= "<option selected='selected' value='".$dep."'>$value</option>";
121         } else {
122           $options.= "<option value='".$dep."'>$value</option>";
123         }
124       }
125     }
127     /* The currently used base is not visible with your acl setup.
128      * Set base to first useable base.
129      */
130     if(!$found){
131       $this->selectedBase = $first;
132     }
134     /* Get acls */
135     $ui       = get_userinfo();
136     $acl      = $ui->get_permissions("cn=dummy,".$this->selectedBase,"application/application");
137     $acl_all  = $ui->has_complete_category_acls($this->selectedBase,"application");
139     /* Add default header */
140     $listhead = MultiSelectWindow::get_default_header();
142     /* And the rest, a base selection box */
143     $listhead .= _("Base")."&nbsp;<select name='CurrentMainBase' onChange='mainform.submit()' class='center'>$options</select>".
144       " <input class='center' type='image' src='images/list_submit.png' align='middle' 
145         title='"._("Submit department")."' name='submit_department' alt='"._("Submit")."'>&nbsp;";
147     /* Create Layers menu */
148     $s  = ".|"._("Actions")."|\n";
149     $s .= "..|<img src='images/list_new.png' alt='' border='0' class='center'>".
150       "&nbsp;"._("Create")."|\n";
152     /* Append create options */
153     if(preg_match("/c/",$acl)) {
154       $s.= "...|<input class='center' type='image' src='images/list_new_app' alt=''>".
155         "&nbsp;"._("Application")."|appl_new|\n";
156     }
158     /* Multiple options */
159     $s.= "..|---|\n";
160     $s.= "..|<img src='images/edittrash.png' alt='' border='0' class='center'>".
161       "&nbsp;"._("Remove")."|"."remove_multiple|\n";
163     /* Add multiple copy & cut icons */
164     if(is_object($this->parent->CopyPasteHandler) && preg_match("/(c.*w|w.*c)/",$acl_all)){
165       $s.= "..|---|\n";
166       $s.= "..|<img src='images/editcopy.png' alt='' border='0' class='center'>".
167         "&nbsp;"._("Copy")."|"."multiple_copy_systems|\n";
168       $s.= "..|<img src='images/editcut.png' alt='' border='0' class='center'>".
169         "&nbsp;"._("Cut")."|"."multiple_cut_systems|\n";
171       if($this->parent->CopyPasteHandler->entries_queued()){
172         $img = "<img border='0' class='center' src='images/editpaste.png' alt=''>";
173         $s.="..|".$img."&nbsp;"._("Paste")."|editPaste|\n";
174       }else{
175         $img = "<img border='0' class='center' src='images/cant_editpaste.png' alt=''>";
176         $s.="..|".$img."&nbsp;"._("Paste")."\n";
177       }
178     }
180     /* Add snapshot icons */
181     if(preg_match("/(c.*w|w.*c)/",$acl_all)){
182       $s .= "..|---|\n";
183       $s .= $this->get_snapshot_header(TRUE);
184     }
186     $this->SetDropDownHeaderMenu($s);
187     $this->SetListHeader($listhead);
189     $this->SetListHeader($listhead);
190   }
192   /* so some basic settings */
193   function execute()
194   {
195     $this->ClearElementsList();
196     $this->GenHeader();
197     $this->AvailableReleases = $this->parent->getReleases($this->selectedBase);
198   }
200   function setEntries($list)
201   {
202     /********************
203       Variable init
204      ********************/
205   
206     /* Create links */
207     $linkopen = "<a href='?plug=".$_GET['plug']."&amp;act=dep_open&amp;dep_id=%s'>%s</a>";
208     $editlink = "<a href='?plug=".$_GET['plug']."&amp;id=%s&amp;act=edit_entry'>%s</a>";
209     $userimg  = "<img class='center' src='images/select_groups.png' alt='User'    title='%s'>";
210     $applimg  = "<img class='center' src='images/select_application.png' alt='A'  title='"._("Application")."'>";
211     $empty    = "<img class='center' src='images/empty.png' style='width:16px;height:16px;' alt=''>";
213     /* set Page header */
214     $action_col_size = 80;
215     if($this->parent->snapshotEnabled()){
216       $action_col_size += 38;
217     }
219     /********************
220       Attach objects
221      ********************/
222     
223     $ui = get_userinfo();
224     foreach($list as $key => $val){
226       $acl = $ui->get_permissions($val['dn'],"application/application");
227       $acl_all= $ui->has_complete_category_acls($val['dn'],"application");
229       /* Create action icons */
230       $actions= "";
232       /* Add Copy & Paste icon */
233       if(($this->parent->CopyPasteHandler) && preg_match("/(c.*w|w.*c)/",$acl_all)){
234         /* Only add cut icon, if we are allowed to move this user */
235         if(preg_match("/m/",$acl)){
236           $actions.= "<input class='center' type='image'
237             src='images/editcut.png' alt='"._("cut")."' name='cut_%KEY%' title='"._("Cut this entry")."'>&nbsp;";
239           $actions.= "<input class='center' type='image'
240             src='images/editcopy.png' alt='"._("copy")."' name='copy_%KEY%' title='"._("Copy this entry")."'>&nbsp;";
241         }
242       }
244       /* Add edit icon */
245       $actions.= "<input class='center' type='image'
246         src='images/edit.png' alt='"._("edit")."' name='appl_edit_%KEY%' title='"._("Edit this entry")."'>";
249       if(preg_match("/(c.*w|w.*c)/",$acl_all)){
250         $actions.= $this->GetSnapShotActions($val['dn']);
251       }
253       /* If we are allowed to remove the application account, display remove icon */
254       if(preg_match("/d/",$acl)){
255         $actions.= "<input class='center' type='image'
256           src='images/edittrash.png' alt='"._("delete")."' name='appl_del_%KEY%' title='"._("Delete this entry")."'>";
257       }else{
258         $actions.= "<img src='images/empty.png' alt='&nbsp;'>";
259       }
261       $title = "title='".preg_replace('/ /', '&nbsp;', @LDAP::fix($val['dn']))."'";
263       if(!isset($val['description'][0])){
264         $desc = "";
265       }else{
266         $desc = " - [ ".$val['description'][0]." ]";
267       }
269       /* Cutted objects should be displayed in light grey */
270       $display = $val['cn'][0].$desc;
271       if($this->parent->CopyPasteHandler){
272         foreach($this->parent->CopyPasteHandler->queue as $queue_key => $queue_data){
273           if($queue_data['dn'] == $val['dn']) {
274             $display = "<font color='#999999'>".$display."</font>";
275             break;
276           }
277         }
278       }
280       /* Create each field */
281       $field0 = array("string" => "<input type='checkbox' id='item_selected_".$key."' name='item_selected_".$key."'>" ,
282                       "attach" => "style='width:20px;'");
283       $field1 = array("string" => sprintf($applimg,$val['dn']), "attach" => "style='text-align:center;width:20px;'");
284       $field2 = array("string" => sprintf($editlink,$key,$display), "attach" => "style='' ".$title);
285       $field3 = array("string" => preg_replace("/%KEY%/", $key, $actions), "attach" => "style='width:".$action_col_size."px;border-right:0px;text-align:right;'");
286       $this->AddElement(array($field0,$field1,$field2,$field3));
287     }
289     /* Create summary string for list footer */
290     $num_deps=0;
291     if(!$this->SubSearch){
292       $num_deps = count($this->Added_Departments);
293     }
294     $num_apps = count($list);
296     $num_app_str = _("Number of listed applications");
297     $num_dep_str = _("Number of listed departments");
298   
299     $str = "<img class='center' src='images/select_application.png' 
300               title='".$num_app_str."' alt='".$num_app_str."'>&nbsp;".$num_apps."&nbsp;&nbsp;&nbsp;&nbsp;";
301     $str.= "<img class='center' src='images/folder.png' 
302               title='".$num_dep_str."' alt='".$num_dep_str."'>&nbsp;".$num_deps."&nbsp;&nbsp;&nbsp;&nbsp;";
304     $this->set_List_Bottom_Info($str);
305   }
307   function Save()
308   {
309     MultiSelectWindow::Save();  
310   }
312   function save_object()
313   {
314     /* Save automatic created POSTs like regex, checkboxes */
315     MultiSelectWindow::save_object(); 
316     $appfilter = session::get('appfilter');
317     $appfilter['release']  = $this->selectedRelease;
318     session::set('appfilter',$appfilter);
319   }
322 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
323 ?>