Code

Added spacing below list
[gosa.git] / gosa-core / include / class_baseSelectDialog.inc
1 <?php
2 /*
3  * This code is part of GOsa (http://www.gosa-project.org)
4  * Copyright (C) 2003-2008 GONICUS GmbH
5  *
6  * ID: $$Id$$
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 2 of the License, or
11  * (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program; if not, write to the Free Software
20  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
21  */
23 class baseSelectDialog extends management
24 {
25   // The plugin description
26   public $plugname      = "Base";
27   public $plIcon        = "plugins/departments/images/plugin.png";
28   public $plDescription = "Choose a base";
29   public $plHeadline    = "Base";
31   protected $skipHeader = TRUE;
32   protected $allowedBases = array();
34   // #FIXME  -  Updated plugins to use a function instead of the public class var. 
35   public $BaseToUse = "";
36   public $dialogClose = FALSE;
38   function __construct (&$config,$parent,$onlyAllowThisBases = array())
39   { 
40     $this->config = $config;
41     $this->ui = get_userinfo();
42     $this->allowedBases = $onlyAllowThisBases;
43     session::set('filterBaseSelect_WhiteList', $this->allowedBases);
45 #    // Build filter
46 #    if (session::global_is_set(get_class($this)."_filter")){
47 #      $filter= session::global_get(get_class($this)."_filter");
48 #    } else {
49   $filter = new filter(get_template_path("baseSelect-filter.xml"));
50 #    }
51   $this->setFilter($filter);
53   // Build headpage
54   $headpage = new listing(get_template_path("baseSelect-list.xml"));
55   $headpage->registerElementFilter("depLabel", "baseSelectDialog::filterDepLabel");
56   $headpage->setFilter($filter);
57   $this->registerAction("open","openEntry");
58   $this->registerAction("cancelBaseSelect","cancelBaseSelect");
59   parent::__construct($config, $this->ui, "departments", $headpage);
60   }
63   // An action handler which enables to switch into deparmtment by clicking the names.
64   function openEntry($action,$entry)
65   {
66     $headpage = $this->getHeadpage();
67     $headpage->setBase(array_pop($entry));
68   }
70   function execute()
71   {
72     $str = management::execute();
73     $str.= "<p class='separator'>&nbsp;</p>
74       <p style=\"text-align:right\">
75       <input type=submit name=\"cancelBaseSelect\" value=\"".msgPool::cancelButton()."\">
76       </p>";
77     return($str);
78   }
81   // A filter which allows to open a department by clicking on the departments name.
82   static function filterDepLabel($row,$dn,$params,$ou,$pid,$base)
83   {
84     $ou = $ou[0];
85     if($dn == $base){
86       $ou =".";
87     }
88     $dn= LDAP::fix(func_get_arg(1));
89     return("<a href='?plug=".$_GET['plug']."&amp;PID=$pid&amp;act=listing_open_$row' title='$dn'>$ou</a>");
90   }
93   function editEntry($action="",$target=array(),$all=array(), $altTabClass ="", $altTabType = "", $altAclCategory="")
94   {
95     if(count($target) == 1){
96       $this->BaseToUse = array_pop($target);
97     }
98   }
100   function save_object()
101   {
102     // Damn ... , we've to call post detection manually & thus twice ...
103     // #FIXME - We should fix the class handling in the plugins to match the class_management style.
104     //        - save_object isn't needed anymore, just call execute...
105     $this->handleActions($this->detectPostActions());
106   }
109   function isClosed()
110   {
111     return($this->dialogClose);
112   }
114   function isSelected() 
115   {
116     return($this->BaseToUse);
117   }
119   function setCurrentBase($base)
120   {
121     $headpage = $this->getHeadpage();
122     $headpage->setBase = $base;
123   }
125   function cancelBaseSelect()
126   {
127     $this->dialogClose = TRUE;
128   }
130   function detectPostActions()
131   {
132     $action = management::detectPostActions();
133     if(isset($_POST['cancelBaseSelect']))  $action['action'] = "cancelBaseSelect";
134     return($action);
135   } 
138 class filterBaseSelect extends filterLDAP
140   static function query($base, $scope, $filter, $attributes, $category, $objectStorage= "")
141   {
142     $res= filterLDAP::query($base, $scope, $filter, $attributes, $category, $objectStorage);
143     return(filterBaseSelect::filterEntries($res));
144   }
146   static function filterEntries($res)
147   {
148     if(!session::is_set('filterBaseSelect_WhiteList')) return $res;
149     $list = session::get('filterBaseSelect_WhiteList');
150     foreach($res as $key => $entry){
151       if(!isset($list[$entry['dn']])) unset($res[$key]);
152     }
153     return(array_values($res));
154   }
156 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
157 ?>