HTTP_SERVER_SERVER should be HTTP_SERVER_VARS, but since
[squirrelmail.git] / plugins / bug_report / functions.php
1 <?php
2 /**
3 * functions for bug_report plugin
4 *
5 * @copyright &copy; 2004-2007 The SquirrelMail Project Team
6 * @license http://opensource.org/licenses/gpl-license.php GNU Public License
7 * @version $Id$
8 * @package plugins
9 * @subpackage bug_report
10 */
11
12
13 /**
14 * do not allow to call this file directly
15 */
16 if (isset($_SERVER['SCRIPT_FILENAME']) && $_SERVER['SCRIPT_FILENAME'] == __FILE__) {
17 header("Location: ../../src/login.php");
18 die();
19 }
20
21 /** Declare plugin configuration vars */
22 global $bug_report_admin_email, $bug_report_allow_users;
23
24 /** Load default config */
25 if (file_exists(SM_PATH . 'plugins/bug_report/config_default.php')) {
26 include_once (SM_PATH . 'plugins/bug_report/config_default.php');
27 } else {
28 // default config was removed.
29 $bug_report_admin_email = '';
30 $bug_report_allow_users = false;
31 }
32
33 /** Load site config */
34 if (file_exists(SM_PATH . 'config/bug_report_config.php')) {
35 include_once (SM_PATH . 'config/bug_report_config.php');
36 } elseif (file_exists(SM_PATH . 'plugins/bug_report/config.php')) {
37 include_once (SM_PATH . 'plugins/bug_report/config.php');
38 }
39
40 /**
41 * Checks if user can use bug_report plugin
42 * @return boolean
43 * @since 1.5.1
44 */
45 function bug_report_check_user() {
46 global $username, $bug_report_allow_users, $bug_report_admin_email;
47
48 if (file_exists(SM_PATH . 'plugins/bug_report/admins')) {
49 $auths = file(SM_PATH . 'plugins/bug_report/admins');
50 array_walk($auths, 'bug_report_array_trim');
51 $auth = in_array($username, $auths);
52 } else if (file_exists(SM_PATH . 'config/admins')) {
53 $auths = file(SM_PATH . 'config/admins');
54 array_walk($auths, 'bug_report_array_trim');
55 $auth = in_array($username, $auths);
56 } else if (($adm_id = fileowner(SM_PATH . 'config/config.php')) &&
57 function_exists('posix_getpwuid')) {
58 $adm = posix_getpwuid( $adm_id );
59 $auth = ($username == $adm['name']);
60 } else {
61 $auth = false;
62 }
63
64 if (! empty($bug_report_admin_email) && $bug_report_allow_users) {
65 $auth = true;
66 }
67
68 return ($auth);
69 }
70
71 /**
72 * Removes whitespace from array values
73 * @param string $value array value that has to be trimmed
74 * @param string $key array key
75 * @since 1.5.1
76 * @todo code reuse. create generic sm function.
77 * @access private
78 */
79 function bug_report_array_trim(&$value,$key) {
80 $value=trim($value);
81 }