Code

19536565e0cacca7a74a16b58808d175ce3052e1
[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();
37     $this->EnableAplhabet(true);
38   
39     /* Disable buttonsm */
40     $this->EnableCloseButton(false);
41     $this->EnableSaveButton (false);
43     /* set Page header */
44     $action_col_size = 80;
45     if($this->parent->snapshotEnabled()){
46       $action_col_size += 38;
47     }
50     /* Toggle all selected / deselected */
51     $chk = "<input type='checkbox' id='select_all' name='select_all'
52                onClick='toggle_all_(\"^item_selected_[0-9]*$\",\"select_all\");' >";
54     /* set Page header */
55     $this->AddHeader(array("string"=> $chk,          "attach"=>"style='width:20px;'"));
56     $this->AddHeader(array("string" => "&nbsp;",                "attach" => "style='text-align:center;width:20px;'"));
57     $this->AddHeader(array("string" => _("Application name")." / "._("Department"), "attach" => "style=''"));
58     $this->AddHeader(array("string" => _("Actions"),            "attach" => "style='width:".$action_col_size."px;border-right:0px;text-align:right;'"));
60     /* Add SubSearch checkbox */
61     $this->AddCheckBox("SubSearch",  msgPool::selectToView("","subsearch"), msgPool::selectToView("","subsearch_small"), false);
63     /*                  Name                 ,Text                              ,Default  , Connect with alphabet  */
64     $this->AddRegex   ("Regex",     _("Display users matching"),"*" , true);
65   }
67   function AddUserBoxToFilter($position){
68     $str = "";
69     if(($position  == 2) && ($this->parent->IsReleaseManagementActivated($this->config))){
70       $smarty = get_smarty();
71       $smarty->assign("selectedRelease",$this->selectedRelease);
72       $smarty->assign("branchimage","images/branch.png");
73       $smarty->assign("releases",$this->AvailableReleases);
74       $str = $smarty->fetch(get_template_path('release_select.tpl', TRUE));
75     }
76     return($str);
77   }
79   function GenHeader()
80   {
81     /* Prepare departments,
82        which are shown in the listbox on top of the listbox
83     */
84     $options= "";
86     /* Get all departments within this subtree */
87     $base = $this->config->current['BASE'];
89     /* Add base */
90     $tmp = array();
91     $tmp[] = array("dn"=>$this->config->current['BASE']);
92     $tmp=  array_merge($tmp,get_list("(&(|(ou=*)(description=*))(objectClass=gosaDepartment))", $this->module, $base,
93                     array("ou", "description"), GL_SIZELIMIT | GL_SUBSEARCH));
95     $deps = array();
96     foreach($tmp as $tm){
97       $deps[$tm['dn']] = $tm['dn'];
98     }
100     /* Load possible departments */
101     $ui= get_userinfo();
102     $tdeps= $ui->get_module_departments("application");
103     $ids = $this->config->idepartments;
104     $first = "";
105     $found = FALSE;
106     foreach($ids as $dep => $name){
107       if(isset($deps[$dep]) && in_array_ics($dep, $tdeps)){
109         /* Keep first base dn in mind, we could need this
110          *  info if no valid base was found
111          */
112         if(empty($first)) {
113           $first = $dep['dn'];
114         }
116         $value = $ids[$dep];
117         if ($this->selectedBase == $dep){
118           $found = TRUE;
119           $options.= "<option selected='selected' value='".$dep."'>$value</option>";
120         } else {
121           $options.= "<option value='".$dep."'>$value</option>";
122         }
123       }
124     }
126     /* The currently used base is not visible with your acl setup.
127      * Set base to first useable base.
128      */
129     if(!$found){
130       $this->selectedBase = $first;
131     }
133     /* Get acls */
134     $ui       = get_userinfo();
135     $acl      = $ui->get_permissions("cn=dummy,".$this->selectedBase,"application/application");
136     $acl_all  = $ui->has_complete_category_acls($this->selectedBase,"application");
138     /* Add default header */
139     $listhead = MultiSelectWindow::get_default_header();
141     /* And the rest, a base selection box */
142     $listhead .= _("Base")."&nbsp;<select name='CurrentMainBase' onChange='mainform.submit()' class='center'>$options</select>".
143       " <input class='center' type='image' src='images/list_submit.png' align='middle' 
144         title='"._("Submit department")."' name='submit_department' alt='"._("Submit")."'>&nbsp;";
146     /* Create Layers menu */
147     $s  = ".|"._("Actions")."|\n";
148     $s .= "..|<img src='images/list_new.png' alt='' border='0' class='center'>".
149       "&nbsp;"._("Create")."|\n";
151     /* Append create options */
152     if(preg_match("/c/",$acl)) {
153       $s.= "...|<input class='center' type='image' src='images/list_new_app' alt=''>".
154         "&nbsp;"._("Application")."|appl_new|\n";
155     }
157     /* Multiple options */
158     $s.= "..|---|\n";
159     $s.= "..|<img src='images/lists/trash.png' alt='' border='0' class='center'>".
160       "&nbsp;"._("Remove")."|"."remove_multiple|\n";
162     /* Add multiple copy & cut icons */
163     if(is_object($this->parent->CopyPasteHandler) && preg_match("/(c.*w|w.*c)/",$acl_all)){
164       $s.= "..|---|\n";
165       $s.= "..|<img src='images/lists/copy.png' alt='' border='0' class='center'>".
166         "&nbsp;"._("Copy")."|"."multiple_copy_systems|\n";
167       $s.= "..|<img src='images/lists/cut.png' alt='' border='0' class='center'>".
168         "&nbsp;"._("Cut")."|"."multiple_cut_systems|\n";
170       if($this->parent->CopyPasteHandler->entries_queued()){
171         $img = "<img border='0' class='center' src='images/lists/paste.png' alt=''>";
172         $s.="..|".$img."&nbsp;"._("Paste")."|editPaste|\n";
173       }else{
174         $img = "<img border='0' class='center' src='images/lists/paste.png' alt=''>";
175         $s.="..|".$img."&nbsp;"._("Paste")."\n";
176       }
177     }
179     /* Add snapshot icons */
180     if(preg_match("/(c.*w|w.*c)/",$acl_all)){
181       $s .= "..|---|\n";
182       $s .= $this->get_snapshot_header(TRUE);
183     }
185     $this->SetDropDownHeaderMenu($s);
186     $this->SetListHeader($listhead);
188     $this->SetListHeader($listhead);
189   }
191   /* so some basic settings */
192   function execute()
193   {
194     $this->ClearElementsList();
195     $this->GenHeader();
196     $this->AvailableReleases = $this->parent->getReleases($this->selectedBase);
197   }
199   function setEntries($list)
200   {
201     /********************
202       Variable init
203      ********************/
204   
205     /* Create links */
206     $linkopen = "<a href='?plug=".$_GET['plug']."&amp;act=dep_open&amp;dep_id=%s'>%s</a>";
207     $editlink = "<a href='?plug=".$_GET['plug']."&amp;id=%s&amp;act=edit_entry'>%s</a>";
208     $userimg  = "<img class='center' src='images/select_groups.png' alt='User'    title='%s'>";
209     $applimg  = "<img class='center' src='images/select_application.png' alt='A'  title='"._("Application")."'>";
210     $empty    = "<img class='center' src='images/empty.png' style='width:16px;height:16px;' alt=''>";
212     /* set Page header */
213     $action_col_size = 80;
214     if($this->parent->snapshotEnabled()){
215       $action_col_size += 38;
216     }
218     /********************
219       Attach objects
220      ********************/
221     
222     $ui = get_userinfo();
223     foreach($list as $key => $val){
225       $acl = $ui->get_permissions($val['dn'],"application/application");
226       $acl_all= $ui->has_complete_category_acls($val['dn'],"application");
228       /* Create action icons */
229       $actions= "";
231       /* Add Copy & Paste icon */
232       if(($this->parent->CopyPasteHandler) && preg_match("/(c.*w|w.*c)/",$acl_all)){
233         /* Only add cut icon, if we are allowed to move this user */
234         if(preg_match("/m/",$acl)){
235           $actions.= "<input class='center' type='image'
236             src='images/lists/cut.png' alt='"._("cut")."' name='cut_%KEY%' title='"._("Cut this entry")."'>&nbsp;";
238           $actions.= "<input class='center' type='image'
239             src='images/lists/copy.png' alt='"._("copy")."' name='copy_%KEY%' title='"._("Copy this entry")."'>&nbsp;";
240         }
241       }
243       /* Add edit icon */
244       $actions.= "<input class='center' type='image'
245         src='images/edit.png' alt='"._("edit")."' name='appl_edit_%KEY%' title='"._("Edit this entry")."'>";
248       if(preg_match("/(c.*w|w.*c)/",$acl_all)){
249         $actions.= $this->GetSnapShotActions($val['dn']);
250       }
252       /* If we are allowed to remove the application account, display remove icon */
253       if(preg_match("/d/",$acl)){
254         $actions.= "<input class='center' type='image'
255           src='images/lists/trash.png' alt='"._("delete")."' name='appl_del_%KEY%' title='"._("Delete this entry")."'>";
256       }else{
257         $actions.= "<img src='images/empty.png' alt='&nbsp;'>";
258       }
260       $title = "title='".preg_replace('/ /', '&nbsp;', @LDAP::fix($val['dn']))."'";
262       if(!isset($val['description'][0])){
263         $desc = "";
264       }else{
265         $desc = " - [ ".$val['description'][0]." ]";
266       }
268       /* Cutted objects should be displayed in light grey */
269       $display = $val['cn'][0].$desc;
270       if($this->parent->CopyPasteHandler){
271         foreach($this->parent->CopyPasteHandler->queue as $queue_key => $queue_data){
272           if($queue_data['dn'] == $val['dn']) {
273             $display = "<font color='#999999'>".$display."</font>";
274             break;
275           }
276         }
277       }
279       /* Create each field */
280       $field0 = array("string" => "<input type='checkbox' id='item_selected_".$key."' name='item_selected_".$key."'>" ,
281                       "attach" => "style='width:20px;'");
282       $field1 = array("string" => sprintf($applimg,$val['dn']), "attach" => "style='text-align:center;width:20px;'");
283       $field2 = array("string" => sprintf($editlink,$key,$display), "attach" => "style='' ".$title);
284       $field3 = array("string" => preg_replace("/%KEY%/", $key, $actions), "attach" => "style='width:".$action_col_size."px;border-right:0px;text-align:right;'");
285       $this->AddElement(array($field0,$field1,$field2,$field3));
286     }
288     /* Create summary string for list footer */
289     $num_deps=0;
290     if(!$this->SubSearch){
291       $num_deps = count($this->Added_Departments);
292     }
293     $num_apps = count($list);
295     $num_app_str = _("Number of listed applications");
296     $num_dep_str = _("Number of listed departments");
297   
298     $str = "<img class='center' src='images/select_application.png' 
299               title='".$num_app_str."' alt='".$num_app_str."'>&nbsp;".$num_apps."&nbsp;&nbsp;&nbsp;&nbsp;";
300     $str.= "<img class='center' src='images/folder.png' 
301               title='".$num_dep_str."' alt='".$num_dep_str."'>&nbsp;".$num_deps."&nbsp;&nbsp;&nbsp;&nbsp;";
303     $this->set_List_Bottom_Info($str);
304   }
306   function Save()
307   {
308     MultiSelectWindow::Save();  
309   }
311   function save_object()
312   {
313     /* Save automatic created POSTs like regex, checkboxes */
314     MultiSelectWindow::save_object(); 
315     $appfilter = session::get('appfilter');
316     $appfilter['release']  = $this->selectedRelease;
317     session::set('appfilter',$appfilter);
318   }
321 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
322 ?>