Adding template for error box.
[squirrelmail.git] / plugins / bug_report / functions.php
CommitLineData
c64dbf73 1<?php
2/**
3 * functions for bug_report plugin
4 *
47ccfad4 5 * @copyright &copy; 2004-2006 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
2329d86d 12/** @ignore */
13if (! defined('SM_PATH')) define('SM_PATH','../../');
c64dbf73 14
2329d86d 15/** Declare plugin configuration vars */
16global $bug_report_admin_email, $bug_report_allow_users;
c64dbf73 17
2329d86d 18/** Load default config */
19if (file_exists(SM_PATH . 'plugins/bug_report/config_default.php')) {
20 include_once (SM_PATH . 'plugins/bug_report/config_default.php');
21} else {
22 // default config was removed.
23 $bug_report_admin_email = '';
24 $bug_report_allow_users = false;
25}
c64dbf73 26
2329d86d 27/** Load site config */
28if (file_exists(SM_PATH . 'config/bug_report_config.php')) {
29 include_once (SM_PATH . 'config/bug_report_config.php');
30} elseif (file_exists(SM_PATH . 'plugins/bug_report/config.php')) {
31 include_once (SM_PATH . 'plugins/bug_report/config.php');
c64dbf73 32}
33
34/**
2329d86d 35 * Checks if user can use bug_report plugin
36 * @return boolean
37 * @since 1.5.1
c64dbf73 38 */
2329d86d 39function bug_report_check_user() {
40 global $username, $bug_report_allow_users, $bug_report_admin_email;
c64dbf73 41
2329d86d 42 if (file_exists(SM_PATH . 'plugins/bug_report/admins')) {
43 $auths = file(SM_PATH . 'plugins/bug_report/admins');
44 array_walk($auths, 'bug_report_array_trim');
45 $auth = in_array($username, $auths);
46 } else if (file_exists(SM_PATH . 'config/admins')) {
47 $auths = file(SM_PATH . 'config/admins');
48 array_walk($auths, 'bug_report_array_trim');
49 $auth = in_array($username, $auths);
50 } else if (($adm_id = fileowner(SM_PATH . 'config/config.php')) &&
51 function_exists('posix_getpwuid')) {
52 $adm = posix_getpwuid( $adm_id );
53 $auth = ($username == $adm['name']);
54 } else {
55 $auth = false;
56 }
c64dbf73 57
2329d86d 58 if (! empty($bug_report_admin_email) && $bug_report_allow_users) {
59 $auth = true;
60 }
c64dbf73 61
2329d86d 62 return ($auth);
63}
c64dbf73 64
2329d86d 65/**
66 * Removes whitespace from array values
67 * @param string $value array value that has to be trimmed
68 * @param string $key array key
69 * @since 1.5.1
70 * @todo code reuse. create generic sm function.
71 * @access private
72 */
73function bug_report_array_trim(&$value,$key) {
74 $value=trim($value);
c64dbf73 75}
2329d86d 76
e50f5ac2 77?>