e2bb1839b89e5f6f70ad30273293245b43ea0597
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( "gosaAccount" => array( "text" => _("Generic"),
41 "image" => "penguin.png"),
42 "posixAccount" => array( "text" =>_("UNIX"),
43 "image" => "select_user.png"),
44 "gosaMailAccount" => array("text" => _("Mail"),
45 "image" => "mailto.png"),
46 "sambaSamAccount" => array("text" => _("Samba"),
47 "image" => "select_winstation.png"),
48 "sambaAccount" => array( "text" => _("Samba"),
49 "image" => "select_winstation.png"),
50 "goFaxAccount" => array( "text" => _("FAX"),
51 "image" => "fax_small.png"),
52 "gosaProxyAccount" => array("text" => _("Proxy"),
53 "image" => "select_proxy.png"),
54 "PureFTPdUser" => array( "text" => _("FTP"),
55 "image" => "select_proxy.png"),
56 "posixGroup" => array( "text" => _("Group"),
57 "image" => "select_groups.png"),
58 "gosaDepartment" => array( "text" => _("Department"),
59 "image" => "select_department.png"),
60 "goFonHardware" => array( "text" => _("Phone"),
61 "image" => "select_phone.png"),
62 "gosaApplication" => array("text" => _("Application"),
63 "image" => "select_application.png"),
64 "goServer" => array( "text" => _("Server"),
65 "image" => "select_server.png"),
66 "gotoTerminal" => array( "text" => _("Thin Client"),
67 "image" => "select_terminal.png"),
68 "gotoWorkstation" => array("text" => _("Workstation"),
69 "image" => "select_workstation.png"),
70 "gosaGroupOfNames" => array("text" => _("Object group"),
71 "image" => "select_ogroup.png"),
72 "gotoPrinter" => array( "text" => _("Printer"),
73 "image" => "select_printer.png"));
74 }
76 function execute()
77 {
78 /* Call parent execute */
79 plugin::execute();
81 /* Set government mode */
82 $smarty= get_smarty();
84 if (isset($_GET['show'])){
85 $dn= base64_decode($_GET['show']);
86 if (isset($this->fold["$dn"])){
87 unset($this->fold["$dn"]);
88 } else {
89 $this->fold["$dn"]= "$dn";
90 }
91 }
93 /* Fill array */
94 $this->reload();
95 $smarty->assign("objectList", $this->objectlist);
97 /* Show main page */
98 return ($smarty->fetch (get_template_path('contents.tpl', TRUE, dirname(__FILE__))));
99 }
101 function reload()
102 {
103 $ldap= $this->config->get_ldap_link();
104 $ldap->cd($this->config->current['BASE']);
106 $ldap->search("(|(member=".LDAP::prepare4filter($this->dn).")(memberUid=".$this->uid."))",array("memberUid","member","cn","description","objectClass"));
108 $cycle= array("F5F5F5", "ECECEC");
109 $id= 0;
110 $this->objectlist= "";
111 while ($attrs= $ldap->fetch()){
113 /* Add more information? */
114 $addon= "";
115 if (in_array($attrs['dn'], $this->fold)){
116 $memberattr= "";
117 if (isset($attrs['memberUid'])){
118 unset($attrs['memberUid']['count']);
119 $memberattr= "memberUid";
120 }
121 if (isset($attrs['member'])){
122 unset($attrs['member']['count']);
123 $memberattr= "member";
124 }
125 if ($memberattr == ""){
126 continue;
127 }
128 foreach ($attrs[$memberattr] as $uid){
129 $content= $this->getCacheObject($uid);
130 if ($content === NULL) {
131 continue;
132 }
133 $addon.= '<tr style="background-color:'.$cycle[$id&1].';"><td title="'.$attrs['cn'][0].'"> '.$content['name'].'</td><td>'.$content['description'].'</td><td>'.$content['type'].'</td> </tr>';
134 }
135 }
137 /* Build final entry */
138 if (isset($attrs['description'])){
139 $description= $attrs['description'][0];
140 } else {
141 $description= "-";
142 }
143 $content= $this->createContentString($attrs['objectClass']);
144 if ($addon == ""){
145 $img= "images/expand.png";
146 } else {
147 $img= "images/lists/sort-down.png";
148 }
149 $this->objectlist.= '<tr style="background-color:'.$cycle[$id&1].';"><td class="phonelist" title="'.$attrs['cn'][0].'"><a href="main.php?plug='.$_GET['plug'].'&start=&show='.base64_encode($attrs['dn']).'"><img alt="" src="'.$img.'" border=0> '.$attrs['cn'][0].'</a></td><td>'.$description.'</td><td>'.$content.'</td> </tr>'.$addon;
151 $id++;
152 }
154 }
156 function getCacheObject($dn)
157 {
158 if (!isset($this->objectCache[$dn])){
159 $ldap= $this->config->get_ldap_link();
160 if (preg_match('/,/', $dn)){
161 $ldap->cat($dn, array("cn", "objectClass", "description","ou"));
162 } else {
163 $ldap->search("(uid=$dn)", array("cn", "objectClass", "description","ou"));
164 }
165 if ($ldap->count()){
166 $attrs= $ldap->fetch();
168 if(isset($attrs['ou']) && !isset($attrs['cn'])){
169 $attrs['cn'] = $attrs['ou'];
170 }
172 if (isset($attrs['description'])){
173 $description= $attrs['description'][0];
174 } else {
175 $description= "-";
176 }
177 $this->objectCache[$dn]= array( 'name' => $attrs['cn'][0],
178 'description' => "$description",
179 'type' => $this->createContentString($attrs['objectClass']));
180 } else {
181 return NULL;
182 }
183 }
184 return ($this->objectCache[$dn]);
185 }
187 function createContentString($classes)
188 {
189 $result= "";
190 if(!is_null($classes)) {
191 foreach ($classes as $class){
192 if (isset($this->obtypes[$class])){
193 $result.= "<a><img alt=\"\" border=0 src='images/".$this->obtypes[$class]['image']."'> ".$this->obtypes[$class]['text']."</a> ";
194 }
195 }
196 }
197 return (preg_replace('/ $/', '', $result));
198 }
200 }
202 ?>