1c36e1b10f88c8efe4afc9ea20ccdfdda3901a66
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 reference extends plugin
24 {
25 /* attribute list for save action */
26 var $attributes= array();
27 var $objectclasses= array();
28 var $objectlist= "";
29 var $obtypes= array();
30 var $fold= array();
31 var $objectCache= array();
33 function reference (&$config, $dn= NULL)
34 {
35 /* Include config object */
36 $this->config= &$config;
37 $this->dn= $dn;
39 /* Fill translation array */
40 $this->obtypes= array(
41 "gosaAccount" => array( "text" => _("Generic"),
42 "image" => "images/penguin.png"),
43 "posixAccount" => array( "text" =>_("UNIX"),
44 "image" => "plugins/users/images/select_user.png"),
45 "gosaMailAccount" => array("text" => _("Mail"),
46 "image" => "images/mailto.png"),
47 "sambaSamAccount" => array("text" => _("Samba"),
48 "image" => "plugins/systems/images/select_winstation.png"),
49 "sambaAccount" => array( "text" => _("Samba"),
50 "image" => "plugins/sysmtes/images/select_winstation.png"),
51 "goFaxAccount" => array( "text" => _("FAX"),
52 "image" => "plugins/gofax/images/fax_small.png"),
53 "gosaProxyAccount" => array("text" => _("Proxy"),
54 "image" => "images/select_proxy.png"),
55 "PureFTPdUser" => array( "text" => _("FTP"),
56 "image" => "images/select_proxy.png"),
57 "posixGroup" => array( "text" => _("Group"),
58 "image" => "plugins/groups/images/select_group.png"),
59 "gosaDepartment" => array( "text" => _("Department"),
60 "image" => "images/select_department.png"),
61 "goFonHardware" => array( "text" => _("Phone"),
62 "image" => "plugins/systems/images/select_phone.png"),
63 "gosaApplication" => array("text" => _("Application"),
64 "image" => "plugins/goto/images/select_application.png"),
65 "goServer" => array( "text" => _("Server"),
66 "image" => "plugins/systems/images/select_server.png"),
67 "gotoTerminal" => array( "text" => _("Thin Client"),
68 "image" => "images/select_terminal.png"),
69 "gotoWorkstation" => array("text" => _("Workstation"),
70 "image" => "plugins/systems/images/select_workstation.png"),
71 "gosaGroupOfNames" => array("text" => _("Object group"),
72 "image" => "plugins/ogroups/images/select_ogroup.png"),
73 "gotoPrinter" => array( "text" => _("Printer"),
74 "image" => "plugins/systems/images/select_printer.png"));
75 }
77 function execute()
78 {
79 /* Call parent execute */
80 plugin::execute();
82 // ACL's we have
83 $ui = get_userinfo();
86 $r = new aclResolver($this->config, $this->dn, $this);
87 return($r->getReadableACL());
89 /* Set government mode */
90 $smarty= get_smarty();
92 if (isset($_GET['show'])){
93 $dn= base64_decode($_GET['show']);
94 if (isset($this->fold["$dn"])){
95 unset($this->fold["$dn"]);
96 } else {
97 $this->fold["$dn"]= "$dn";
98 }
99 }
101 /* Fill array */
102 $this->reload();
103 $smarty->assign("objectList", $this->objectlist);
105 /* Show main page */
106 return ($smarty->fetch (get_template_path('contents.tpl', TRUE, dirname(__FILE__))));
107 }
109 function reload()
110 {
111 $ldap= $this->config->get_ldap_link();
112 $ldap->cd($this->config->current['BASE']);
114 $ldap->search(
115 "(|(gotoHotplugDeviceDN=".LDAP::prepare4filter($this->dn).")".
116 "(member=".LDAP::prepare4filter($this->dn).")(memberUid=".$this->uid."))",
117 array("memberUid","member","cn","description","objectClass"));
119 $cycle= array("F5F5F5", "ECECEC");
120 $id= 0;
121 $this->objectlist= "";
122 while ($attrs= $ldap->fetch()){
124 /* Add more information? */
125 $addon= "";
126 if (in_array($attrs['dn'], $this->fold)){
127 $memberattr= "";
128 if (isset($attrs['memberUid'])){
129 unset($attrs['memberUid']['count']);
130 $memberattr= "memberUid";
131 }
132 if (isset($attrs['member'])){
133 unset($attrs['member']['count']);
134 $memberattr= "member";
135 }
136 if ($memberattr == ""){
137 continue;
138 }
139 foreach ($attrs[$memberattr] as $uid){
140 $content= $this->getCacheObject($uid);
141 if ($content === NULL) {
142 continue;
143 }
144 $addon.=
145 ' <tr style="background-color:'.$cycle[$id&1].';"> '.
146 ' <td title="'.$attrs['cn'][0].'"> '.$content['name'].'</td>'.
147 ' <td>'.$content['description'].'</td>'.
148 ' <td>'.$content['type'].'</td> '.
149 ' </tr>';
150 }
151 }
153 /* Build final entry */
154 if (isset($attrs['description'])){
155 $description= $attrs['description'][0];
156 } else {
157 $description= "-";
158 }
159 $content= $this->createContentString($attrs['objectClass']);
160 if ($addon == ""){
161 $img= "images/lists/expand.png";
162 } else {
163 $img= "images/lists/sort-down.png";
164 }
166 $this->objectlist.=
167 ' <tr style="background-color:'.$cycle[$id&1].';"> '.
168 ' <td class="phonelist" title="'.$attrs['cn'][0].'"> '.
169 ' '.image($img).
170 ' <a href="main.php?plug='.$_GET['plug'].'&start=&show='.base64_encode($attrs['dn']).'"> '.
171 ' '.$attrs['cn'][0].
172 ' </a> '.
173 ' </td> '.
174 ' <td>'.
175 ' <a href="main.php?plug='.$_GET['plug'].'&start=&show='.base64_encode($attrs['dn']).'"> '.
176 $description.
177 ' </a> '.
178 ' </td> '.
179 ' <td>'.$content.'</td> '.
180 ' </tr>'.$addon;
181 $id++;
182 }
184 }
186 function getCacheObject($dn)
187 {
188 if (!isset($this->objectCache[$dn])){
189 $ldap= $this->config->get_ldap_link();
190 if (preg_match('/,/', $dn)){
191 $ldap->cat($dn, array("cn", "objectClass", "description","ou"));
192 } else {
193 $ldap->search("(uid=$dn)", array("cn", "objectClass", "description","ou"));
194 }
195 if ($ldap->count()){
196 $attrs= $ldap->fetch();
198 if(isset($attrs['ou']) && !isset($attrs['cn'])){
199 $attrs['cn'] = $attrs['ou'];
200 }
202 if (isset($attrs['description'])){
203 $description= $attrs['description'][0];
204 } else {
205 $description= "-";
206 }
207 $this->objectCache[$dn]= array( 'name' => $attrs['cn'][0],
208 'description' => "$description",
209 'type' => $this->createContentString($attrs['objectClass']));
210 } else {
211 return NULL;
212 }
213 }
214 return ($this->objectCache[$dn]);
215 }
217 function createContentString($classes)
218 {
219 $result= "";
220 if(!is_null($classes)) {
221 foreach ($classes as $class){
222 if (isset($this->obtypes[$class])){
223 $result.=
224 " ".image($this->obtypes[$class]['image']).
225 " <a>".
226 " ".$this->obtypes[$class]['text'].
227 " </a> ";
228 }
229 }
230 }
231 return (preg_replace('/ $/', '', $result));
232 }
234 }
236 ?>