Use compatibility_info() function if at all possible instead of compatibility_version()
[squirrelmail.git] / plugins / bug_report / functions.php
index 733bebe6ab693507c788e2101c4158fbbbbe5ff3..e078dfb9999b54c53358b179b7054dd5ff81a84a 100644 (file)
 /**
  * functions for bug_report plugin
  *
- * functions/forms.php and functions/html.php have to be loaded before including this file.
- *
- * @copyright (c) 2004 The SquirrelMail Project Team
+ * @copyright © 2004-2007 The SquirrelMail Project Team
  * @license http://opensource.org/licenses/gpl-license.php GNU Public License
  * @version $Id$
  * @package plugins
  * @subpackage bug_report
  */
 
+
 /**
- * Creates gmane search form
- *
- * Requires html v.4.0 compatible browser
- * @return string html formated form
+ * do not allow to call this file directly
  */
-function add_gmane_form() {
-  // Start form (need target="_blank" element)
-  $ret=addForm('http://search.gmane.org/search.php','get','mform');
+if ((isset($_SERVER['SCRIPT_FILENAME']) && $_SERVER['SCRIPT_FILENAME'] == __FILE__) ||
+     (isset($HTTP_SERVER_SERVER['SCRIPT_FILENAME']) && $HTTP_SERVER_SERVER['SCRIPT_FILENAME'] == __FILE__) ) {
+    header("Location: ../../src/login.php");
+    die();
+}
 
-  // Add visible options
-  $ret.=html_tag('table',
-                 html_tag('tr',
-                          html_tag('td',_("Search for words:"),'right') .
-                          html_tag('td',addInput('query','',50),'left')
-                          ) .
-                 html_tag('tr',
-                          html_tag('td',_("Written by:") . '<br />' . 
-                                   '<small>' . _("Email addresses only") . '</small>','right') .
-                          html_tag('td',addInput('email','',40),'left')
-                          ) .
-                 html_tag('tr',
-                          html_tag('td',_("Mailing list:"),'right') .
-                          html_tag('td',addSelect('group',array('gmane.mail.squirrelmail.user'
-                                                                => _("SquirrelMail users list"),
-                                                                'gmane.mail.squirrelmail.plugins'
-                                                                => _("SquirrelMail plugins list"),
-                                                                'gmane.mail.squirrelmail.devel'
-                                                                => _("SquirrelMail developers list"),
-                                                                'gmane.mail.squirrelmail.internationalization'
-                                                                => _("SquirrelMail internationalization list"))
-                                                  ,'gmane.mail.squirrelmail.user',true),'left')
-                          ) .
-                 html_tag('tr',
-                          html_tag('td',_("Sort by:"),'right') .
-                          html_tag('td',addSelect('sort',array('date' => _("Date"),
-                                                               'relevance' => _("Relevance"))
-                                                  ,'date',true),'left')
-                          ) .
-                html_tag('tr',
-                          html_tag('td',
-                                   '<button type="submit" name="submit" value="submit">' . _("Search Archives") . "</button>\n" .
-                                   '<button type="reset" name="reset" value="reset">' . _("Reset Form") . "</button>\n"
-                                   ,'center','','colspan="2"')
-                          ),
-                 'center');
+/** Declare plugin configuration vars */
+global $bug_report_admin_email, $bug_report_allow_users;
 
-  // Close form
-  $ret.="</form>\n";
+/** 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;
+}
 
-  // Return form
-  return $ret;
+/** 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');
 }
 
 /**
- * Creates SquirrelMail SF bugtracker search form
- *
- * Requires html v.4.0 compatible browser
- * @return string html formated form
+ * Checks if user can use bug_report plugin
+ * @return boolean
+ * @since 1.5.1
  */
-function add_sf_bug_form() {
-  // Start form
-  $ret=addForm('http://sourceforge.net/tracker/index.php','post');
+function bug_report_check_user() {
+    global $username, $bug_report_allow_users, $bug_report_admin_email;
 
-  // Add hidden options (some input fields are hidden from end user)
-  $ret.=addHidden('group_id','311') .
-    addHidden('atid','100311') .
-    addHidden('set','custom') .
-    addHidden('_assigned_to','0') .
-    addHidden('_status','100') .
-    addHidden('_category','100') .
-    addHidden('_group','100') .
-    addHidden('by_submitter','');
+    if (file_exists(SM_PATH . 'plugins/bug_report/admins')) {
+        $auths = file(SM_PATH . 'plugins/bug_report/admins');
+        array_walk($auths, 'bug_report_array_trim');
+        $auth = in_array($username, $auths);
+    } else if (file_exists(SM_PATH . 'config/admins')) {
+        $auths = file(SM_PATH . 'config/admins');
+        array_walk($auths, 'bug_report_array_trim');
+        $auth = in_array($username, $auths);
+    } else if (($adm_id = fileowner(SM_PATH . 'config/config.php')) &&
+               function_exists('posix_getpwuid')) {
+        $adm = posix_getpwuid( $adm_id );
+        $auth = ($username == $adm['name']);
+    } else {
+        $auth = false;
+    }
 
-  // Add visible input fields and buttons
-  $ret.=html_tag('table',
-                 html_tag('tr',
-                          html_tag('td',_("Summary keyword:"),'right') .
-                          html_tag('td',addInput('summary_keyword','',20,80),'left')
-                          ) .
-                 html_tag('tr',
-                          html_tag('td',_("Sort By:"),'right') .
-                          html_tag('td',
-                                   addSelect('order',array('artifact_id' => _("ID"),
-                                                           'priority' => _("Priority"),
-                                                           'summary' => _("Summary"),
-                                                           'open_date' => _("Open Date"),
-                                                           'close_date' => _("Close Date"),
-                                                           'submitted_by' => _("Submitter"),
-                                                           'assigned_to' => _("Assignee")),
-                                             'artifact_id',true),'left')
-                          ) .
-                 html_tag('tr',
-                          html_tag('td',_("Order:"),'right') .
-                          html_tag('td',
-                                   addSelect('sort',array('ASC'=>_("Ascending"),
-                                                          'DESC'=>_("Descending")),
-                                             'DESC',true),
-                                   'left')
-                          ) .
-                 html_tag('tr',
-                          html_tag('td',
-                                   '<button type="submit" name="submit" value="submit">' . _("Search Bugtracker") . "</button>\n" .
-                                   '<button type="reset" name="reset" value="reset">' . _("Reset Form") . "</button>\n"
-                                   ,'center','','colspan="2"')
-                          )
-                 ,'center');
+    if (! empty($bug_report_admin_email) && $bug_report_allow_users) {
+        $auth = true;
+    }
 
-  // Close form
-  $ret.="</form>\n";
+    return ($auth);
+}
 
-  // Return form
-  return $ret;
+/**
+ * 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);
 }
-?>
\ No newline at end of file