2 /*******************************************************************************
3 * Copyright (C) 2007 Easter-eggs
4 * http://ldapsaisie.labs.libre-entreprise.org
6 * Author: See AUTHORS file in top-level directory.
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License version 2
10 * as published by the Free Software Foundation.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
21 ******************************************************************************/
24 * Object LSsearchEntry
26 * @author Benjamin Renard <brenard@easter-eggs.com>
30 // The LSsearch object
31 private $LSsearch=NULL;
33 // The LdapObject type of search
34 private $LSobject=NULL;
39 // The parameters of the search
40 private $params=array ();
42 // The hash of the search parameters
45 // The attributes values
46 private $attrs=array();
49 private $cache=array();
54 * @param[in] $LSobject string The LdapObject type of search
55 * @param[in] $params array Parameters of search
56 * @param[in] $hash array Parameters of search
57 * @param[in] $resultEntry array The data of the result entry
60 function LSsearchEntry(&$LSsearch,$LSobject,$params,$hash,&$result,$id) {
61 if (!LSsession :: loadLSobject($LSobject)) {
64 $this -> LSsearch = $LSsearch;
65 $this -> LSobject = $LSobject;
66 $this -> params = $params;
68 $this -> dn =& $result[$id]['dn'];
69 $this -> attrs =& $result[$id]['attrs'];
70 $this -> cache =& $result[$id]['cache'];
74 * Get text value of entry
76 * @param[in] $key string The name of the value
78 * @retval mixed The value
80 public function get($key) {
81 if (in_array($key,array_keys($this -> attrs))) {
82 return $this -> attrs[$key];
84 elseif ($key=='subDn' || $key=='subDnName') {
85 return $this -> subDn;
90 * Get formated text value of entry
92 * @param[in] $format string The format of the value
94 * @retval mixed The formated value
96 public function getFData($format) {
97 return getFData($format,$this,'get');
102 * Access to infos of the entry
104 * @param[in] $key string The name of the value
106 * @retval mixed The value
108 public function __get($key) {
109 if ($key=='displayName') {
110 if (isset($this -> cache['displayName'])) {
111 return $this -> cache['displayName'];
113 $this -> cache['displayName'] = $this -> getFData($this -> params['displayFormat']);
114 return $this -> cache['displayName'];
116 elseif ($key=='LSobject'||$key=='type_name'||$key=='type') {
117 return $this -> LSobject;
119 elseif ($key=='dn') {
122 elseif ($key=='subDn' || $key=='subDnName') {
123 if ($this -> cache['subDn']) {
124 return $this -> cache['subDn'];
126 if ($this -> LSsearch -> displaySubDn) {
127 $this -> cache['subDn'] = LSldapObject::getSubDnName($this -> dn);
128 return $this -> cache['subDn'];
131 elseif ($key=='actions') {
132 if (isset($this -> cache['actions'])) {
133 return $this -> cache['actions'];
135 $this -> cache['actions'] = array (
137 'label' => _('View'),
138 'url' =>'view.php?LSobject='.$this -> LSobject.'&dn='.$this -> dn,
143 if (LSsession :: canEdit($this -> LSobject,$this -> dn)) {
144 $this -> cache['actions'][]=array(
145 'label' => _('Modify'),
146 'url' => 'modify.php?LSobject='.$this -> LSobject.'&dn='.$this -> dn,
151 if ($this -> LSsearch -> canCopy) {
152 $this -> cache['actions'][] = array(
153 'label' => _('Copy'),
154 'url' =>'create.php?LSobject='.$this -> LSobject.'&load='.$this -> dn,
159 if (LSsession :: canRemove($this -> LSobject,$this -> dn)) {
160 $this -> cache['actions'][] = array (
161 'label' => _('Delete'),
162 'url' => 'remove.php?LSobject='.$this -> LSobject.'&dn='.$this -> dn,
166 $this -> LSsearch -> addResultToCache();
167 return $this -> cache['actions'];
169 elseif ($key=='LSselect') {
170 if (is_array($_SESSION['LSselect'][$this -> LSobject])) {
171 if(in_array($this -> dn,$_SESSION['LSselect'][$this -> LSobject])) {
177 elseif (in_array($key,array_keys($this -> attrs))) {
178 return $this -> attrs[$key];
180 elseif (array_key_exists($key,$this->params['customInfos'])) {
181 if(isset($this -> cache['customInfos'][$key])) {
182 return $this -> cache['customInfos'][$key];
184 if(is_array($this->params['customInfos'][$key]['function']) && is_string($this->params['customInfos'][$key]['function'][0])) {
185 LSsession::loadLSclass($this->params['customInfos'][$key]['function'][0]);
187 if(is_callable($this->params['customInfos'][$key]['function'])) {
188 $this -> cache['customInfos'][$key]=call_user_func($this->params['customInfos'][$key]['function'],$this,$this->params['customInfos'][$key]['args']);
189 return $this -> cache['customInfos'][$key];
193 LSlog('LSsearchEntry : '.$this -> dn.' => Unknown property '.$key.' !');
194 return __("Unknown property !");