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 /* Set government mode */
83 $smarty= get_smarty();
85 if (isset($_GET['show'])){
86 $dn= base64_decode($_GET['show']);
87 if (isset($this->fold["$dn"])){
88 unset($this->fold["$dn"]);
89 } else {
90 $this->fold["$dn"]= "$dn";
91 }
92 }
94 /* Fill array */
95 $this->reload();
96 $smarty->assign("objectList", $this->objectlist);
98 /* Show main page */
99 return ($smarty->fetch (get_template_path('contents.tpl', TRUE, dirname(__FILE__))));
100 }
102 function reload()
103 {
104 $ldap= $this->config->get_ldap_link();
105 $ldap->cd($this->config->current['BASE']);
107 $ldap->search(
108 "(|(gotoHotplugDeviceDN=".LDAP::prepare4filter($this->dn).")".
109 "(member=".LDAP::prepare4filter($this->dn).")(memberUid=".$this->uid."))",
110 array("memberUid","member","cn","description","objectClass"));
112 $cycle= array("F5F5F5", "ECECEC");
113 $id= 0;
114 $this->objectlist= "";
115 while ($attrs= $ldap->fetch()){
117 /* Add more information? */
118 $addon= "";
119 if (in_array($attrs['dn'], $this->fold)){
120 $memberattr= "";
121 if (isset($attrs['memberUid'])){
122 unset($attrs['memberUid']['count']);
123 $memberattr= "memberUid";
124 }
125 if (isset($attrs['member'])){
126 unset($attrs['member']['count']);
127 $memberattr= "member";
128 }
129 if ($memberattr == ""){
130 continue;
131 }
132 foreach ($attrs[$memberattr] as $uid){
133 $content= $this->getCacheObject($uid);
134 if ($content === NULL) {
135 continue;
136 }
137 $addon.=
138 ' <tr style="background-color:'.$cycle[$id&1].';"> '.
139 ' <td title="'.$attrs['cn'][0].'"> '.$content['name'].'</td>'.
140 ' <td>'.$content['description'].'</td>'.
141 ' <td>'.$content['type'].'</td> '.
142 ' </tr>';
143 }
144 }
146 /* Build final entry */
147 if (isset($attrs['description'])){
148 $description= $attrs['description'][0];
149 } else {
150 $description= "-";
151 }
152 $content= $this->createContentString($attrs['objectClass']);
153 if ($addon == ""){
154 $img= "images/lists/expand.png";
155 } else {
156 $img= "images/lists/sort-down.png";
157 }
159 $this->objectlist.=
160 ' <tr style="background-color:'.$cycle[$id&1].';"> '.
161 ' <td class="phonelist" title="'.$attrs['cn'][0].'"> '.
162 ' '.image($img).
163 ' <a href="main.php?plug='.$_GET['plug'].'&start=&show='.base64_encode($attrs['dn']).'"> '.
164 ' '.$attrs['cn'][0].
165 ' </a> '.
166 ' </td> '.
167 ' <td>'.
168 ' <a href="main.php?plug='.$_GET['plug'].'&start=&show='.base64_encode($attrs['dn']).'"> '.
169 $description.
170 ' </a> '.
171 ' </td> '.
172 ' <td>'.$content.'</td> '.
173 ' </tr>'.$addon;
174 $id++;
175 }
177 }
179 function getCacheObject($dn)
180 {
181 if (!isset($this->objectCache[$dn])){
182 $ldap= $this->config->get_ldap_link();
183 if (preg_match('/,/', $dn)){
184 $ldap->cat($dn, array("cn", "objectClass", "description","ou"));
185 } else {
186 $ldap->search("(uid=$dn)", array("cn", "objectClass", "description","ou"));
187 }
188 if ($ldap->count()){
189 $attrs= $ldap->fetch();
191 if(isset($attrs['ou']) && !isset($attrs['cn'])){
192 $attrs['cn'] = $attrs['ou'];
193 }
195 if (isset($attrs['description'])){
196 $description= $attrs['description'][0];
197 } else {
198 $description= "-";
199 }
200 $this->objectCache[$dn]= array( 'name' => $attrs['cn'][0],
201 'description' => "$description",
202 'type' => $this->createContentString($attrs['objectClass']));
203 } else {
204 return NULL;
205 }
206 }
207 return ($this->objectCache[$dn]);
208 }
210 function createContentString($classes)
211 {
212 $result= "";
213 if(!is_null($classes)) {
214 foreach ($classes as $class){
215 if (isset($this->obtypes[$class])){
216 $result.=
217 " ".image($this->obtypes[$class]['image']).
218 " <a>".
219 " ".$this->obtypes[$class]['text'].
220 " </a> ";
221 }
222 }
223 }
224 return (preg_replace('/ $/', '', $result));
225 }
227 }
229 ?>