source: contrib/ProjectManager/inc/class.pm_admin_prefs_sidebox_hooks.inc.php @ 3594

Revision 3594, 13.8 KB checked in by afernandes, 13 years ago (diff)

Ticket #1416 - Disponibilizado o módulo ProjectManager? para a comunidade

  • Property svn:executable set to *
Line 
1<?php
2/**************************************************************************\
3* eGroupWare - ProjectManager: Admin-, Preferences- and SideboxMenu-Hooks  *
4* http://www.eGroupWare.org                                                *
5* Written and (c) 2005 by Ralf Becker <RalfBecker@outdoor-training.de>     *
6* -------------------------------------------------------                  *
7*  This program is free software; you can redistribute it and/or modify it *
8*  under the terms of the GNU General Public License as published by the   *
9*  Free Software Foundation; either version 2 of the License, or (at your  *
10*  option) any later version.                                              *
11\**************************************************************************/
12
13/* $Id: class.pm_admin_prefs_sidebox_hooks.inc.php 23852 2007-05-09 16:29:32Z lkneschke $ */
14
15class pm_admin_prefs_sidebox_hooks
16{
17        var $public_functions = array(
18//              'check_set_default_prefs' => true,
19        );
20        var $weekdays = array(
21                1 => 'monday',
22                2 => 'tuesday',
23                3 => 'wednesday',
24                4 => 'thursday',
25                5 => 'friday',
26                6 => 'saturday',
27                0 => 'sunday',
28        );
29        var $config = array();
30
31        function pm_admin_prefs_sidebox_hooks()
32        {
33                $config =& CreateObject('phpgwapi.config','projectmanager');
34                $config->read_repository();
35                $this->config =& $config->config_data;
36                unset($config);
37        }
38
39        /**
40         * hooks to build projectmanager's sidebox-menu plus the admin and preferences sections
41         *
42         * @param string/array $args hook args
43         */
44        function all_hooks($args)
45        {
46                $appname = 'projectmanager';
47                $location = is_array($args) ? $args['location'] : $args;
48                //echo "<p>ranking_admin_prefs_sidebox_hooks::all_hooks(".print_r($args,True).") appname='$appname', location='$location'</p>\n";
49
50                if ($location == 'sidebox_menu')
51                {
52                        // project-dropdown in sidebox menu
53                        if (!is_object($GLOBALS['phpgw']->html))
54                        {
55                                $GLOBALS['phpgw']->html =& CreateObject('phpgwapi.html');
56                        }
57                        if (!is_object($GLOBALS['boprojectmanager']))
58                        {
59                                // dont assign it to $GLOBALS['boprojectmanager'], as the constructor does it!!!
60                                CreateObject('projectmanager.uiprojectmanager');
61                        }
62                        if (isset($_REQUEST['pm_id']))
63                        {
64                                $GLOBALS['phpgw']->session->appsession('pm_id','projectmanager',$pm_id = (int) $_REQUEST['pm_id']);
65                        }
66                        else
67                        {
68                                $pm_id = (int) $GLOBALS['phpgw']->session->appsession('pm_id','projectmanager');
69                        }
70                        $file = array(
71                                'Projectlist' => $GLOBALS['phpgw']->link('/index.php',array(
72                                        'menuaction' => 'projectmanager.uiprojectmanager.index' )),
73                                array(
74                                        'text' => 'Elementlist',
75                                        'link' => $pm_id ? $GLOBALS['phpgw']->link('/index.php',array(
76                                                'menuaction' => 'projectmanager.uiprojectelements.index',
77                                        )) : False,
78                                ),
79                                array(
80                                        'text' => 'Ganttchart',
81                                        'link' => $pm_id ? $GLOBALS['phpgw']->link('/index.php',array(
82                                                'menuaction' => 'projectmanager.ganttchart.show',
83                                        )) : False,
84                                ),
85                        );
86                        // show pricelist menuitem only if we use pricelists
87                        if (!$this->config['accounting_types'] || in_array('pricelist',explode(',',$this->config['accounting_types'])))
88                        {
89                                // menuitem links to project-spezific priclist only if user has rights and it is used
90                                // to not always instanciate the priclist class, this code dublicats bopricelist::check_acl(PHPGW_ACL_READ),
91                                // specialy the always existing READ right for the general pricelist!!!
92                                $file['Pricelist'] = $GLOBALS['phpgw']->link('/index.php',array(
93                                        'menuaction' => 'projectmanager.uipricelist.index',
94                                        'pm_id' => $pm_id && $GLOBALS['boprojectmanager']->check_acl(PHPGW_ACL_BUDGET,$pm_id) &&
95                                                 $GLOBALS['boprojectmanager']->data['pm_accounting_type'] == 'pricelist' ? $pm_id : 0,
96                                ));
97                        }
98
99                        // include the filter of the projectlist into the projectlist, eg. if you watch the list of templates, include them in the tree
100                        $filter = array('pm_status' => 'active');
101                        $list_filter = $GLOBALS['phpgw']->session->appsession('project_list','projectmanager');
102                        if ($_GET['menuaction'] == 'projectmanager.uiprojectmanager.index' && isset($_POST['exec']['nm']['filter2']))
103                        {
104                                //echo "<p align=right>set pm_status={$_POST['exec']['nm']['filter2']}</p>\n";
105                                $list_filter['pm_status'] = $_POST['exec']['nm']['filter2'];    // necessary as uiprojectmanager::get_rows is not yet executed
106                        }
107                        if(in_array($list_filter['filter2'],array('nonactive','archive','template')))
108                        {
109                                $filter['pm_status'] = array('active',$list_filter['filter2']);
110                        }
111                        switch($_GET['menuaction'])
112                        {
113                                case 'projectmanager.ganttchart.show':
114                                case 'projectmanager.uipricelist.index':
115                                        $selbox_action = $_GET['menuaction'];
116                                        break;
117                                default:
118                                        $selbox_action = 'projectmanager.uiprojectelements.index';
119                                        break;
120                        }
121                        $select_link = $GLOBALS['phpgw']->link('/index.php',array('menuaction' => $selbox_action)).'&pm_id=';
122                       
123                        // show the project-selection as tree or -selectbox
124                        // $_POST['user']['show_projectselection'] is used to give the user immediate feedback, if he changes the prefs
125                        $type = isset($_POST['user']['show_projectselection']) ? $_POST['user']['show_projectselection'] :
126                                $GLOBALS['phpgw_info']['user']['preferences']['projectmanager']['show_projectselection'];
127                        if (substr($type,-5) == 'title')
128                        {
129                                $label = 'pm_title';
130                                $title = 'pm_number';
131                        }
132                        else
133                        {
134                                $label = 'pm_number';
135                                $title = 'pm_title';
136                        }
137                        if (substr($type,0,9) == 'selectbox')
138                        {
139                                $projectlist =& $this->_project_selectbox($pm_id,$filter,$select_link,$label,$title);
140                        }
141                        else
142                        {
143                                $projectlist =& $this->_project_tree($pm_id,$filter,$select_link,$label,$title);
144                        }
145                        if ($projectlist) $file[] =& $projectlist;
146
147                        display_sidebox($appname,$GLOBALS['phpgw_info']['apps'][$appname]['title'].' '.lang('Menu'),$file);
148                }
149
150                if ($GLOBALS['phpgw_info']['user']['apps']['preferences'] && $location != 'admin')
151                {
152                        $file = array(
153                                'Preferences'     => $GLOBALS['phpgw']->link('/index.php','menuaction=preferences.uisettings.index&appname='.$appname),
154                                'Grant Access'    => $GLOBALS['phpgw']->link('/index.php','menuaction=preferences.uiaclprefs.index&acl_app='.$appname),
155                                'Edit Categories' => $GLOBALS['phpgw']->link('/index.php','menuaction=preferences.uicategories.index&cats_app=' . $appname . '&cats_level=True&global_cats=True')
156                        );
157                        if ($location == 'preferences')
158                        {
159                                display_section($appname,$file);
160                        }
161                        else
162                        {
163                                display_sidebox($appname,lang('Preferences'),$file);
164                        }
165                }
166
167                if ($GLOBALS['phpgw_info']['user']['apps']['admin'] && $location != 'preferences')
168                {
169                        $file = Array(
170                                'Site configuration' => $GLOBALS['phpgw']->link('/index.php','menuaction=projectmanager.admin.config'),
171                                'Custom fields' => $GLOBALS['phpgw']->link('/index.php','menuaction=admin.customfields.edit&appname=projectmanager'),
172                                'Global Categories'  => $GLOBALS['phpgw']->link('/index.php',array(
173                                        'menuaction' => 'admin.uicategories.index',
174                                        'appname'    => $appname,
175                                        'global_cats'=> True)),
176                        );
177                        if ($location == 'admin')
178                        {
179                                display_section($appname,$file);
180                        }
181                        else
182                        {
183                                display_sidebox($appname,lang('Admin'),$file);
184                        }
185                }
186        }
187       
188        /**
189         * Show the project-selection as tree
190         *
191         * @param int $pm_id current active project
192         * @param array $filter filter for the project-list
193         * @param string $select_link link to load the elementslist of an appended project (pm_id)
194         * @param string $label column to use as label
195         * @param string $title column to use as title (tooltip)
196         * @return array suitable for the sidebox-menu
197         */
198        function &_project_tree($pm_id,$filter,$select_link,$label,$title)
199        {
200                $selected_project = false;
201                $projects = array();
202                foreach($GLOBALS['boprojectmanager']->get_project_tree($filter) as $project)
203                {
204                        $projects[$project['path']] = array(
205                                'label' => $project[$label],
206                                'title' => $project[$title],
207                        );
208                        if (!$selected_project && $pm_id == $project['pm_id']) $selected_project = $project['path'];
209                }
210                if ($_GET['menuaction'] == 'projectmanager.uipricelist.index')
211                {
212                        $projects['general'] = array(
213                                'label' => lang('General pricelist'),
214                                'image' => 'kfm_home.png',
215                        );
216                        if (!$pm_id) $selected_project = 'general';     
217                }
218                if (!$projects) // show project-tree only if it's not empty
219                {
220                        return null;
221                }
222                $tree = $GLOBALS['phpgw']->html->tree($projects,$selected_project,false,'load_project');
223                // hack for stupid ie (cant set it as a class!)
224                if ($GLOBALS['phpgw']->html->user_agent == 'msie') $tree = str_replace('id="foldertree"','id="foldertree" style="overflow: auto; width: 198px;"',$tree);
225               
226                return array(
227                        'text' => "<script>function load_project(_nodeId) { location.href='$select_link'+_nodeId.substr(_nodeId.lastIndexOf('/')+1,99); }</script>\n".$tree,
228                        'no_lang' => True,
229                        'link' => False,
230                        'icon' => False,
231                );
232        }
233       
234        /**
235         * Show the project-selection as selectbox
236         *
237         * @param int $pm_id current active project
238         * @param array $filter filter for the project-list
239         * @param string $select_link link to load the elementslist of an appended project (pm_id)
240         * @param string $label column to use as label
241         * @param string $title column to use as title (tooltip)
242         * @return array suitable for the sidebox-menu
243         */
244        function &_project_selectbox($pm_id,$filter,$select_link,$label,$title)
245        {
246                $projects = array();
247                foreach((array)$GLOBALS['boprojectmanager']->search(array(
248                        'pm_status' => 'active',
249                        'pm_id'     => $pm_id,        // active or the current one
250                ),$GLOBALS['boprojectmanager']->table_name.'.pm_id AS pm_id,pm_number,pm_title','pm_number','','',False,'OR') as $project)
251                {
252                        $projects[$project['pm_id']] = $project[$label].($label == 'pm_number' ? ': '.$project[$title] : ' ('.$project[$title].')');
253                }
254                if ($_GET['menuaction'] == 'projectmanager.uipricelist.index')
255                {
256                        $projects[0] = lang('General pricelist');
257                }
258                elseif (!$pm_id)
259                {
260                        $projects[0] = lang('Select a project');
261                }
262                return array(
263                        'text' => $GLOBALS['phpgw']->html->select('pm_id',$pm_id,$projects,true,' style="width: 100%;"'.
264                                ' onchange="location.href=\''.$select_link.'\'+this.value;" title="'.$GLOBALS['phpgw']->html->htmlspecialchars(
265                                $pm_id && isset($projects[$pm_id]) ? $projects[$pm_id] : lang('Select a project')).'"'),
266                        'no_lang' => True,
267                        'link' => False
268                );
269        }
270       
271        /**
272         * populates $GLOBALS['settings'] for the preferences
273         */
274        function settings()
275        {
276                $this->check_set_default_prefs();
277               
278                $start = array();
279                for($i = 0; $i < 24*60; $i += 30)
280                {
281                        if ($GLOBALS['phpgw_info']['user']['preferences']['common']['timeformat'] == 12)
282                        {
283                                if (!($hour = ($i / 60) % 12))
284                                {
285                                        $hour = 12;
286                                }
287                                $start[$i] = sprintf('%01d:%02d %s',$hour,$i % 60,$i < 12*60 ? 'am' : 'pm');
288                        }
289                        else
290                        {
291                                $start[$i] = sprintf('%01d:%02d',$i/60,$i % 60);
292                        }
293                }
294                $duration = array(0 => lang('not working'));
295                for($i = 30; $i <= 24*60; $i += 30)
296                {
297                        $duration[$i] = sprintf('%3.1lf',$i / 60.0).' '.lang('hours');
298                }
299                foreach($this->weekdays as $day => $label)
300                {
301                        $GLOBALS['settings']['duration_'.$day] = array(
302                                'type'   => 'select',
303                                'label'  => lang('Working duration on %1',lang($label)),
304                                'run_lang' => -1,
305                                'name'   => 'duration_'.$day,
306                                'values' => $duration,
307                                'help'   => 'How long do you work on the given day.',
308                                'xmlrpc' => True,
309                                'admin'  => !$this->config['allow_change_workingtimes'],
310                        );
311                        $GLOBALS['settings']['start_'.$day] = array(
312                                'type'   => 'select',
313                                'label'  => lang('Start working on %1',lang($label)),
314                                'run_lang' => -1,
315                                'name'   => 'start_'.$day,
316                                'values' => $start,
317                                'help'   => 'At which time do you start working on the given day.',
318                                'xmlrpc' => True,
319                                'admin'  => !$this->config['allow_change_workingtimes'],
320                        );
321                }
322                $GLOBALS['settings']['show_custom_app_icons'] = array(
323                        'type'   => 'check',
324                        'label'  => 'Show status icons of the datasources',
325                        'name'   => 'show_custom_app_icons',
326                        'help'   => 'Should Projectmanager display the status icons of the datasource (eg. InfoLog) or just a progressbar with the numerical status (faster).',
327                        'xmlrpc' => True,
328                        'admin'  => False,
329                );
330                $GLOBALS['settings']['show_projectselection'] = array(
331                        'type'   => 'select',
332                        'label'  => 'Show the project selection as',
333                        'name'   => 'show_projectselection',
334                        'values' => array(
335                                'tree_with_number'      => lang('Tree with %1',lang('Project ID')),
336                                'tree_with_title'       => lang('Tree with %1',lang('Title')),
337                                'selectbox_with_number' => lang('Selectbox with %1',lang('Project ID').': '.lang('Title')),
338                                'selectbox_with_title'  => lang('Selectbox with %1',lang('Title').' ('.lang('Project ID').')'),
339                        ),
340                        'help'   => 'How should the project selection in the menu be displayed: A tree gives a better overview, a selectbox might perform better.',
341                        'xmlrpc' => True,
342                        'admin'  => False,
343                );
344                return true;    // otherwise prefs say it cant find the file ;-)
345        }
346       
347        /**
348         * Check if reasonable default preferences are set and set them if not
349         *
350         * It sets a flag in the app-session-data to be called only once per session
351         */
352        function check_set_default_prefs()
353        {
354                if ($GLOBALS['phpgw']->session->appsession('default_prefs_set','projectmanager'))
355                {
356                        return;
357                }
358                $GLOBALS['phpgw']->session->appsession('default_prefs_set','projectmanager','set');
359
360                $default_prefs =& $GLOBALS['phpgw']->preferences->default['projectmanager'];
361
362                $defaults = array(
363                        'start_1' => 9*60,
364                        'duration_1' => 8*60,
365                        'start_2' => 9*60,
366                        'duration_2' => 8*60,
367                        'start_3' => 9*60,
368                        'duration_3' => 8*60,
369                        'start_4' => 9*60,
370                        'duration_4' => 8*60,
371                        'start_5' => 9*60,
372                        'duration_5' => 6*60,
373                        'duration_6' => 0,
374                        'duration_0' => 0,
375                        'show_custom_app_icons' => '0',
376                        'show_tree'  => 'pm_number',
377                );
378                foreach($defaults as $var => $default)
379                {
380                        if (!isset($default_prefs[$var]) || (string)$default_prefs[$var] === '')
381                        {
382                                $GLOBALS['phpgw']->preferences->add('projectmanager',$var,$default,'default');
383                                $need_save = True;
384                        }
385                }
386                if ($need_save)
387                {
388                        $GLOBALS['phpgw']->preferences->save_repository(False,'default');
389                }
390        }
391}
Note: See TracBrowser for help on using the repository browser.