Code

d4f158e9e1711a89bb73fc56720c0695989e0dfe
[gosa.git] / gosa-core / plugins / generic / infoPage / class_infoPage.inc
1 <?php
3 class infoPage extends plugin
4 {
5     private $ui;
6     private $managers;
9     /*! \brief
10      */
11     function __construct($config)
12     {
13         $this->config = &$config;
14         $this->ui = get_userinfo();
15         plugin::plugin($config, $this->ui->dn);
17         // Detect managers for the current user.
18         $this->managers = $this->detectManagers();
20         // Get plugin list
21         $this->plugins = $this->getPluginList();
22     }
25     /*! \brief  Returns a HTML string which respresent a list of plugins the user can access.
26      *          Only accessible plugins will be rendered.
27      *  @return String  HTML content
28      */
29     function getPluginList()
30     {
31         $plist = session::get('plist');
32         $myAccountID = array_search('MyAccount',$plist->pluginList);
33         $str = "";
34         foreach($this->config->data['TABS']['MYACCOUNTTABS'] as $pluginData){
35             $plugin = $pluginData['CLASS'];
37             if(!$this->checkAccess($plugin)) continue;
39             list($index, $title, $desc, $icon) = $plist->getPlugData($plugin);
40             $str.= "\n        <div class='icon-menu-item' style='width: 20%;' onclick='openPlugin(\"{$myAccountID}\",\"{$plugin}\")'>";
41             $str.= "\n          ".image($icon);
42             $str.= "\n          <div class='dsc'>";
43             $str.= "\n            <h1>{$title}</h1>";
44             $str.= "\n            <p>{$desc}</p>";
45             $str.= "\n          </div>";
46             $str.= "\n        </div>";
48         }
49         return($str);
50     }
53     /*! \brief  Check if we've access to a given class/plugin of GOsa. 
54      *  @param  String  The class name to check for.
55      *  @return Boolean     True on success else FALSE.
56      */
57     function checkAccess($class)
58     {
59         foreach($this->ui->ocMapping as $cat => $aclClasses){
60             if(in_array($class, $aclClasses)){
61                 if(preg_match('/[rw]/',$this->ui->get_permissions($this->ui->dn, "{$cat}/{$class}", ''))){
62                     return(TRUE);
63                 }
64             }
65         }
66         return(FALSE);
67     }
70     /*! \brief  Prepares an array which contains info about the users
71      *           managers. The personal manager and the next
72      *           manager defined for a department.
73      *  @return Array   An array with resolved manager dns.
74      */
75     function detectManagers()
76     {
78         // Check if we've an own manager set
79         $ldap = $this->config->get_ldap_link(); 
80         $ldap->cd($this->config->current['BASE']);
81         $ldap->cat($this->dn, array('manager'));
82         $attrs = $ldap->fetch();
83         $dns = array();
84         if(isset($attrs['manager'][0])){
85             $dns['PERSONAL'] = $attrs['manager'][0];
86         }
88         // Get next department manager dn
89         $dn = $this->dn;
90         $max = 4;
91         while(strlen($dn) >= strlen($this->config->current['BASE']) && $max--){
92             $dn = preg_replace("/^[^,]+,/","",$dn);
93             $ldap->cat($dn, array('manager'));
94             $attrs = $ldap->fetch();
95             if(isset($attrs['manager'][0])){
96                 $dns['DEPARTMENT'] = $attrs['manager'][0];
97             }
98         }
100         // Resolve collected manager dns
101         $managers = array();
102         foreach($dns as $type => $dn){
103             $ldap->cat($dn,array('sn','givenName','mail','telephoneNumber'));
104             $managers[$dn] = $ldap->fetch();
105             $managers[$dn]['type'] = $type;
106             $name = $phone = $mail = "";
107             $name = "<tr><td colspan='2' style='background-color:#F0F0F0'><b>".set_post($managers[$dn]['givenName'][0])." ".set_post($managers[$dn]['sn'][0])."</b></td></tr>";
108             if(isset($managers[$dn]['telephoneNumber'][0])){
109                 $phone = "<tr><td>&nbsp;"._("Phone number").":</td><td><i>".set_post($managers[$dn]['telephoneNumber'][0])."</i></td></tr>";
110             }
111             if(isset($managers[$dn]['mail'][0])){
112                 $mail = "<tr><td>&nbsp;"._("Mail").":</td><td><i><a href='mailto:".set_post($managers[$dn]['mail'][0])."'>".set_post($managers[$dn]['mail'][0])."</i></td></tr>";
113             }
114             $managers[$dn]['str'] = "<table cellpadding='2' style='border:1px solid #CCC'>{$name}{$phone}{$mail}</table>";
115         }
116         return($managers);
117     }
120     /*! \brief  Renders the plugin UI in HTML.
121      *  @return String  HTML content of the plugin.
122      */
123     function execute()
124     {
125         $smarty = get_smarty();
126         $personalInfoAllowed = FALSE;
127         foreach(array("uid","sn","givenName","mail","street","l","o","ou","jpegPhoto","personalTitle",
128                     "academicTitle","dateOfBirth","homePostalAddress","homePhone","departmentNumber",
129                     "employeeNumber","employeeType") as $attr){
130             $smarty->assign($attr, "");
131             if(preg_match("/r/", $this->ui->get_permissions($this->ui->dn,"users/user", $attr))
132                     && isset($this->attrs[$attr][0])){
133                 $smarty->assign($attr, set_post($this->attrs[$attr][0]));
134                 $personalInfoAllowed = TRUE;
135             }
136         }
138         // Convert address
139         if(preg_match("/r/", $this->ui->get_permissions($this->ui->dn,"users/user", "homePostalAddress")) && 
140                 isset($this->attrs['homePostalAddress'][0])){
141             $smarty->assign("homePostalAddress", preg_replace("/\n/", "<br>", $this->attrs['homePostalAddress'][0]));
142         }else{
143             $smarty->assign("homePostalAddress", "");
144         }
146         // Assign JPEG Photo only if it is set and if we are allowed to view it.
147         $smarty->assign("jpegPhoto", "");
148         if(preg_match("/r/", $this->ui->get_permissions($this->ui->dn,"users/user", "userPicture")) && 
149                 isset($this->attrs['jpegPhoto'][0])){
150             session::set('binary',$this->attrs['jpegPhoto'][0]);
151             session::set('binarytype',"image/jpeg");
152             $smarty->assign("jpegPhoto", $this->attrs['jpegPhoto']);
153         }
155         // Set date of birth
156         if(preg_match("/r/", $this->ui->get_permissions($this->ui->dn,"users/user", "dateOfBirth")) && 
157                 isset($this->attrs['dateOfBirth'][0])){
158             $smarty->assign("dateOfBirth", date('d.m.Y',strtotime($this->attrs['dateOfBirth'][0])));
159         }else{
160             $smarty->assign("dateOfBirth","");
161         }
163         $smarty->assign("rand", rand(0, 99999999));
164         $smarty->assign("personalInfoAllowed", $personalInfoAllowed);
165         $smarty->assign("managers", $this->managers);
166         $smarty->assign("plugins", $this->plugins);
167         $smarty->assign("managersCnt", count($this->managers));
168         $smarty->assign("revision", get_gosa_version());
169         $smarty->assign("year", date("Y"));
170         return($smarty->fetch(get_template_path("infoPage.tpl")));
171     }
174 ?>