1 | <?php |
---|
2 | /** |
---|
3 | * TimeSheet - Admin-, Preferences- and SideboxMenu-Hooks |
---|
4 | * |
---|
5 | * @link http://www.egroupware.org |
---|
6 | * @author Ralf Becker <RalfBecker-AT-outdoor-training.de> |
---|
7 | * @package timesheet |
---|
8 | * @copyright (c) 2005 by Ralf Becker <RalfBecker-AT-outdoor-training.de> |
---|
9 | * @license http://opensource.org/licenses/gpl-license.php GPL - GNU General Public License |
---|
10 | * @version $Id: class.ts_admin_prefs_sidebox_hooks.inc.php 23493 2007-03-08 11:22:57Z lkneschke $ |
---|
11 | */ |
---|
12 | |
---|
13 | if (!defined('TIMESHEET_APP')) |
---|
14 | { |
---|
15 | define('TIMESHEET_APP','timesheet'); |
---|
16 | } |
---|
17 | |
---|
18 | class ts_admin_prefs_sidebox_hooks |
---|
19 | { |
---|
20 | var $public_functions = array( |
---|
21 | // 'check_set_default_prefs' => true, |
---|
22 | ); |
---|
23 | var $config = array(); |
---|
24 | |
---|
25 | function pm_admin_prefs_sidebox_hooks() |
---|
26 | { |
---|
27 | $config =& CreateObject('phpgwapi.config',TIMESHEET_APP); |
---|
28 | $config->read_repository(); |
---|
29 | $this->config =& $config->config_data; |
---|
30 | unset($config); |
---|
31 | } |
---|
32 | |
---|
33 | /** |
---|
34 | * hooks to build projectmanager's sidebox-menu plus the admin and preferences sections |
---|
35 | * |
---|
36 | * @param string/array $args hook args |
---|
37 | */ |
---|
38 | function all_hooks($args) |
---|
39 | { |
---|
40 | $appname = TIMESHEET_APP; |
---|
41 | $location = is_array($args) ? $args['location'] : $args; |
---|
42 | //echo "<p>ts_admin_prefs_sidebox_hooks::all_hooks(".print_r($args,True).") appname='$appname', location='$location'</p>\n"; |
---|
43 | |
---|
44 | if ($location == 'sidebox_menu') |
---|
45 | { |
---|
46 | $file = array( |
---|
47 | ); |
---|
48 | display_sidebox($appname,$GLOBALS['phpgw_info']['apps'][$appname]['title'].' '.lang('Menu'),$file); |
---|
49 | } |
---|
50 | |
---|
51 | if ($GLOBALS['phpgw_info']['user']['apps']['preferences'] && $location != 'admin') |
---|
52 | { |
---|
53 | $file = array( |
---|
54 | // 'Preferences' => $GLOBALS['phpgw']->link('/index.php','menuaction=preferences.uisettings.index&appname='.$appname), |
---|
55 | 'Grant Access' => $GLOBALS['phpgw']->link('/index.php','menuaction=preferences.uiaclprefs.index&acl_app='.$appname), |
---|
56 | 'Edit Categories' => $GLOBALS['phpgw']->link('/index.php','menuaction=preferences.uicategories.index&cats_app=' . $appname . '&cats_level=True&global_cats=True') |
---|
57 | ); |
---|
58 | if ($location == 'preferences') |
---|
59 | { |
---|
60 | display_section($appname,$file); |
---|
61 | } |
---|
62 | else |
---|
63 | { |
---|
64 | display_sidebox($appname,lang('Preferences'),$file); |
---|
65 | } |
---|
66 | } |
---|
67 | |
---|
68 | if ($GLOBALS['phpgw_info']['user']['apps']['admin'] && $location != 'preferences') |
---|
69 | { |
---|
70 | $file = Array( |
---|
71 | 'Site Configuration' => $GLOBALS['phpgw']->link('/index.php','menuaction=admin.uiconfig.index&appname=' . $appname), |
---|
72 | // 'Custom fields' => $GLOBALS['phpgw']->link('/index.php','menuaction=admin.customfields.edit&appname='.$appname), |
---|
73 | 'Global Categories' => $GLOBALS['phpgw']->link('/index.php',array( |
---|
74 | 'menuaction' => 'admin.uicategories.index', |
---|
75 | 'appname' => $appname, |
---|
76 | 'global_cats'=> True)), |
---|
77 | 'Custom fields' => $GLOBALS['phpgw']->link('/index.php',array( |
---|
78 | 'menuaction' => 'timesheet.uicustomfields.edit', |
---|
79 | 'appname' => $appname)), |
---|
80 | ); |
---|
81 | if ($location == 'admin') |
---|
82 | { |
---|
83 | display_section($appname,$file); |
---|
84 | } |
---|
85 | else |
---|
86 | { |
---|
87 | display_sidebox($appname,lang('Admin'),$file); |
---|
88 | } |
---|
89 | } |
---|
90 | } |
---|
91 | |
---|
92 | /** |
---|
93 | * populates $GLOBALS['settings'] for the preferences |
---|
94 | */ |
---|
95 | function settings() |
---|
96 | { |
---|
97 | $this->check_set_default_prefs(); |
---|
98 | |
---|
99 | return true; // otherwise prefs say it cant find the file ;-) |
---|
100 | } |
---|
101 | |
---|
102 | /** |
---|
103 | * Check if reasonable default preferences are set and set them if not |
---|
104 | * |
---|
105 | * It sets a flag in the app-session-data to be called only once per session |
---|
106 | */ |
---|
107 | function check_set_default_prefs() |
---|
108 | { |
---|
109 | if ($GLOBALS['phpgw']->session->appsession('default_prefs_set',TIMESHEET_APP)) |
---|
110 | { |
---|
111 | return; |
---|
112 | } |
---|
113 | $GLOBALS['phpgw']->session->appsession('default_prefs_set',TIMESHEET_APP,'set'); |
---|
114 | |
---|
115 | $default_prefs =& $GLOBALS['phpgw']->preferences->default[TIMESHEET_APP]; |
---|
116 | |
---|
117 | $defaults = array( |
---|
118 | ); |
---|
119 | foreach($defaults as $var => $default) |
---|
120 | { |
---|
121 | if (!isset($default_prefs[$var]) || $default_prefs[$var] === '') |
---|
122 | { |
---|
123 | $GLOBALS['phpgw']->preferences->add(TIMESHEET_APP,$var,$default,'default'); |
---|
124 | $need_save = True; |
---|
125 | } |
---|
126 | } |
---|
127 | if ($need_save) |
---|
128 | { |
---|
129 | $GLOBALS['phpgw']->preferences->save_repository(False,'default'); |
---|
130 | } |
---|
131 | } |
---|
132 | } |
---|