Happy 2014
[squirrelmail.git] / plugins / bug_report / functions.php
CommitLineData
c64dbf73 1<?php
2/**
3 * functions for bug_report plugin
4 *
701e7bee 5 * @copyright 2004-2014 The SquirrelMail Project Team
c64dbf73 6 * @license http://opensource.org/licenses/gpl-license.php GNU Public License
7 * @version $Id$
8 * @package plugins
9 * @subpackage bug_report
10 */
11
202bcbcc 12
13/**
1a219da9 14 * Initializes the Bug Report plugin
15 *
16 * @return boolean FALSE if the plugin is not correctly configured
17 * or an error in its setup is found; TRUE otherwise
18 *
19 * @since 1.5.2
20 *
202bcbcc 21 */
1a219da9 22function bug_report_init() {
c64dbf73 23
1a219da9 24 // Declare plugin configuration vars
25 //
26 global $bug_report_admin_email, $bug_report_allow_users;
c64dbf73 27
1a219da9 28 // Load default config
29 //
30 if (file_exists(SM_PATH . 'plugins/bug_report/config_default.php')) {
31 include_once (SM_PATH . 'plugins/bug_report/config_default.php');
32 } else {
33 // default config was removed.
34 $bug_report_admin_email = '';
35 $bug_report_allow_users = false;
36 }
37
38 // Load site config
39 //
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');
44 }
c64dbf73 45
c64dbf73 46}
47
1a219da9 48
c64dbf73 49/**
2329d86d 50 * Checks if user can use bug_report plugin
1a219da9 51 *
2329d86d 52 * @return boolean
1a219da9 53 *
2329d86d 54 * @since 1.5.1
1a219da9 55 *
c64dbf73 56 */
2329d86d 57function bug_report_check_user() {
58 global $username, $bug_report_allow_users, $bug_report_admin_email;
c64dbf73 59
1a219da9 60 bug_report_init();
61
2329d86d 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']);
74 } else {
75 $auth = false;
76 }
c64dbf73 77
2329d86d 78 if (! empty($bug_report_admin_email) && $bug_report_allow_users) {
79 $auth = true;
80 }
c64dbf73 81
2329d86d 82 return ($auth);
83}
c64dbf73 84
1a219da9 85
2329d86d 86/**
87 * Removes whitespace from array values
1a219da9 88 *
2329d86d 89 * @param string $value array value that has to be trimmed
90 * @param string $key array key
1a219da9 91 *
2329d86d 92 * @since 1.5.1
1a219da9 93 *
2329d86d 94 * @todo code reuse. create generic sm function.
1a219da9 95 *
2329d86d 96 * @access private
1a219da9 97 *
2329d86d 98 */
99function bug_report_array_trim(&$value,$key) {
1a219da9 100 $value = trim($value);
101}
102
103
104/**
105 * Show the button in the main bar
106 *
107 * @access private
108 *
109 */
110function bug_report_button_do() {
111 global $username, $data_dir;
112 $bug_report_visible = getPref($data_dir, $username, 'bug_report_visible', FALSE);
113
114 if (! $bug_report_visible || ! bug_report_check_user()) {
115 return;
116 }
117
118 global $oTemplate, $nbsp;
119 $output = makeInternalLink('plugins/bug_report/bug_report.php', _("Bug"), '')
120 . $nbsp . $nbsp;
121 return array('menuline' => $output);
122}
123
124
125/**
126 * Register bug report option block
127 *
128 * @since 1.5.1
129 *
130 * @access private
131 *
132 */
133function 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
146 );
147 $optpage_data['vals']['bug_report'] = $optionValues;
148 }
c64dbf73 149}
1a219da9 150
151