These files shouldn't be executables.
[squirrelmail.git] / plugins / bug_report / functions.php
index e524057c5c2ca0ea0a4c4777b243eb5ee53e58d0..dcae47222ada02568e01d91f0b4741da2b248a92 100644 (file)
@@ -2,7 +2,7 @@
 /**
  * functions for bug_report plugin
  *
- * @copyright © 2004-2006 The SquirrelMail Project Team
+ * @copyright © 2004-2008 The SquirrelMail Project Team
  * @license http://opensource.org/licenses/gpl-license.php GNU Public License
  * @version $Id$
  * @package plugins
 
 
 /**
- * do not allow to call this file directly
+ * Initializes the Bug Report plugin
+ *
+ * @return boolean FALSE if the plugin is not correctly configured
+ *         or an error in its setup is found; TRUE otherwise
+ *
+ * @since 1.5.2
+ *
  */
-if ((isset($_SERVER) && $_SERVER['SCRIPT_FILENAME'] == __FILE__) ||
-     (isset($HTTP_SERVER_SERVER) && $HTTP_SERVER_SERVER['SCRIPT_FILENAME'] == __FILE__) ) {
-    header("Location: ../../src/login.php");
-    die();
-}
+function bug_report_init() {
 
-/** Declare plugin configuration vars */
-global $bug_report_admin_email, $bug_report_allow_users;
+    // Declare plugin configuration vars
+    //
+    global $bug_report_admin_email, $bug_report_allow_users;
 
-/** Load default config */
-if (file_exists(SM_PATH . 'plugins/bug_report/config_default.php')) {
-    include_once (SM_PATH . 'plugins/bug_report/config_default.php');
-} else {
-    // default config was removed.
-    $bug_report_admin_email = '';
-    $bug_report_allow_users = false;
-}
+    // Load default config
+    //
+    if (file_exists(SM_PATH . 'plugins/bug_report/config_default.php')) {
+        include_once (SM_PATH . 'plugins/bug_report/config_default.php');
+    } else {
+        // default config was removed.
+        $bug_report_admin_email = '';
+        $bug_report_allow_users = false;
+    }
+
+    // Load site config
+    //
+    if (file_exists(SM_PATH . 'config/bug_report_config.php')) {
+        include_once (SM_PATH . 'config/bug_report_config.php');
+    } elseif (file_exists(SM_PATH . 'plugins/bug_report/config.php')) {
+        include_once (SM_PATH . 'plugins/bug_report/config.php');
+    }
 
-/** Load site config */
-if (file_exists(SM_PATH . 'config/bug_report_config.php')) {
-    include_once (SM_PATH . 'config/bug_report_config.php');
-} elseif (file_exists(SM_PATH . 'plugins/bug_report/config.php')) {
-    include_once (SM_PATH . 'plugins/bug_report/config.php');
 }
 
+
 /**
  * Checks if user can use bug_report plugin
+ *
  * @return boolean
+ *
  * @since 1.5.1
+ *
  */
 function bug_report_check_user() {
     global $username, $bug_report_allow_users, $bug_report_admin_email;
 
+    bug_report_init();
+
     if (file_exists(SM_PATH . 'plugins/bug_report/admins')) {
         $auths = file(SM_PATH . 'plugins/bug_report/admins');
         array_walk($auths, 'bug_report_array_trim');
@@ -69,16 +82,70 @@ function bug_report_check_user() {
     return ($auth);
 }
 
+
 /**
  * Removes whitespace from array values
+ *
  * @param string $value array value that has to be trimmed
  * @param string $key array key
+ *
  * @since 1.5.1
+ *
  * @todo code reuse. create generic sm function.
+ *
  * @access private
+ *
  */
 function bug_report_array_trim(&$value,$key) {
-    $value=trim($value);
+    $value = trim($value);
 }
 
-?>
\ No newline at end of file
+
+/**
+ * Show the button in the main bar
+ *
+ * @access private
+ *
+ */
+function bug_report_button_do() {
+    global $username, $data_dir;
+    $bug_report_visible = getPref($data_dir, $username, 'bug_report_visible', FALSE);
+
+    if (! $bug_report_visible || ! bug_report_check_user()) {
+        return;
+    }
+
+    global $oTemplate, $nbsp;
+    $output = makeInternalLink('plugins/bug_report/bug_report.php', _("Bug"), '')
+            . $nbsp . $nbsp;
+    return array('menuline' => $output);
+}
+
+
+/**
+ * Register bug report option block
+ *
+ * @since 1.5.1
+ *
+ * @access private
+ *
+ */
+function bug_report_block_do() {
+    if (bug_report_check_user()) {
+        global $username, $data_dir, $optpage_data, $bug_report_visible;
+        $bug_report_visible = getPref($data_dir, $username, 'bug_report_visible', FALSE);
+        $optpage_data['grps']['bug_report'] = _("Bug Reports");
+        $optionValues = array();
+// FIXME: option needs refresh in SMOPT_REFRESH_RIGHT (menulinks are built before options are saved/loaded)
+        $optionValues[] = array(
+            'name'    => 'bug_report_visible',
+            'caption' => _("Show button in toolbar"),
+            'type'    => SMOPT_TYPE_BOOLEAN,
+            'refresh' => SMOPT_REFRESH_ALL,
+            'initial_value' => false
+            );
+        $optpage_data['vals']['bug_report'] = $optionValues;
+    }
+}
+
+