3 * functions for bug_report plugin
5 * @copyright 2004-2013 The SquirrelMail Project Team
6 * @license http://opensource.org/licenses/gpl-license.php GNU Public License
9 * @subpackage bug_report
14 * Initializes the Bug Report plugin
16 * @return boolean FALSE if the plugin is not correctly configured
17 * or an error in its setup is found; TRUE otherwise
22 function bug_report_init() {
24 // Declare plugin configuration vars
26 global $bug_report_admin_email, $bug_report_allow_users;
28 // Load default config
30 if (file_exists(SM_PATH
. 'plugins/bug_report/config_default.php')) {
31 include_once (SM_PATH
. 'plugins/bug_report/config_default.php');
33 // default config was removed.
34 $bug_report_admin_email = '';
35 $bug_report_allow_users = false;
40 if (file_exists(SM_PATH
. 'config/bug_report_config.php')) {
41 include_once (SM_PATH
. 'config/bug_report_config.php');
42 } elseif (file_exists(SM_PATH
. 'plugins/bug_report/config.php')) {
43 include_once (SM_PATH
. 'plugins/bug_report/config.php');
50 * Checks if user can use bug_report plugin
57 function bug_report_check_user() {
58 global $username, $bug_report_allow_users, $bug_report_admin_email;
62 if (file_exists(SM_PATH
. 'plugins/bug_report/admins')) {
63 $auths = file(SM_PATH
. 'plugins/bug_report/admins');
64 array_walk($auths, 'bug_report_array_trim');
65 $auth = in_array($username, $auths);
66 } else if (file_exists(SM_PATH
. 'config/admins')) {
67 $auths = file(SM_PATH
. 'config/admins');
68 array_walk($auths, 'bug_report_array_trim');
69 $auth = in_array($username, $auths);
70 } else if (($adm_id = fileowner(SM_PATH
. 'config/config.php')) &&
71 function_exists('posix_getpwuid')) {
72 $adm = posix_getpwuid( $adm_id );
73 $auth = ($username == $adm['name']);
78 if (! empty($bug_report_admin_email) && $bug_report_allow_users) {
87 * Removes whitespace from array values
89 * @param string $value array value that has to be trimmed
90 * @param string $key array key
94 * @todo code reuse. create generic sm function.
99 function bug_report_array_trim(&$value,$key) {
100 $value = trim($value);
105 * Show the button in the main bar
110 function bug_report_button_do() {
111 global $username, $data_dir;
112 $bug_report_visible = getPref($data_dir, $username, 'bug_report_visible', FALSE);
114 if (! $bug_report_visible ||
! bug_report_check_user()) {
118 global $oTemplate, $nbsp;
119 $output = makeInternalLink('plugins/bug_report/bug_report.php', _("Bug"), '')
121 return array('menuline' => $output);
126 * Register bug report option block
133 function bug_report_block_do() {
134 if (bug_report_check_user()) {
135 global $username, $data_dir, $optpage_data, $bug_report_visible;
136 $bug_report_visible = getPref($data_dir, $username, 'bug_report_visible', FALSE);
137 $optpage_data['grps']['bug_report'] = _("Bug Reports");
138 $optionValues = array();
139 // FIXME: option needs refresh in SMOPT_REFRESH_RIGHT (menulinks are built before options are saved/loaded)
140 $optionValues[] = array(
141 'name' => 'bug_report_visible',
142 'caption' => _("Show button in toolbar"),
143 'type' => SMOPT_TYPE_BOOLEAN
,
144 'refresh' => SMOPT_REFRESH_ALL
,
145 'initial_value' => false
147 $optpage_data['vals']['bug_report'] = $optionValues;