gunnar: server/php-kolab/Kolab_Webadmin/Webadmin webadmin.class.php, NONE, 1.1 form.class.php, 1.4, 1.5 locale.php, 1.2, 1.3

cvs at kolab.org cvs at kolab.org
Fri Aug 17 18:31:47 CEST 2007


Author: gunnar

Update of /kolabrepository/server/php-kolab/Kolab_Webadmin/Webadmin
In directory doto:/tmp/cvs-serv27283/Kolab_Webadmin/Webadmin

Modified Files:
	form.class.php locale.php 
Added Files:
	webadmin.class.php 
Log Message:
Provide the old mysmarty.php as a new background object for the web admin.

--- NEW FILE: webadmin.class.php ---
<?php
/*  
 *  COPYRIGHT
 *  ---------
 *
 *  See ../AUTHORS file
 *
 *
 *  LICENSE
 *  -------
 *
 *  This program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 2 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program; if not, write to the Free Software
 *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 *
 *  $Revision: 1.1 $
 *
 *  ABOUT
 *  -----
 *
 *  Main Kolab admin object.
 *
 */

/** This is based on smarty. */
require_once('smarty/Smarty.class.php');

/** Handles the generation of the menu. */
require_once('Kolab/Webadmin/menu.php');

/** Classes for authentication. */
require_once('Kolab/Webadmin/auth.class.php');
require_once('Kolab/Webadmin/ldap.class.php');

/** Provides functionality for locale handling. */
require_once('Kolab/Webadmin/locale.php');

/**
 * This class combines methods common to most pages of the Kolab web
 * admin frontend.
 *
 * $Header: /kolabrepository/server/php-kolab/Kolab_Webadmin/Webadmin/webadmin.class.php,v 1.1 2007/08/17 16:31:44 gunnar Exp $
 *
 * @author  Steffen Hansen <steffen at klaralvdalens-datakonsult.se>
 * @author  Gunnar Wrobel  <wrobel at pardus.de>
 * @package Kolab_Webadmin
 */
class KolabWebadmin extends Smarty {

    /**
     * A link to the object that handles our ldap connection.
     *
     * @var KolabLDAP
     */
    var $_ldap;

    /**
     * A link to the object that handles our authentication
     * information.
     *
     * @var KolabAuth
     */
    var $_auth;

    /**
     * An array of section accessible to the current user.
     *
     * @var array
     */
    var $_menuitems;

    /**
     * The current section selected by the user
     *
     * @var string
     */
    var $_section;

    /**
     * Initialize the web admin class
     *
     * @param array $config An array of basic configuration variables.
     *
     * @return KolabWebadmin The initialized KolabWebadmin object
     */
    function KolabWebadmin($config) 
    {
        // Start the session
        session_start();

        /* 
         * Prepare authentication.
         */

        $this->_ldap =& new KolabLDAP($config);
        $this->_auth =& new KolabAuth($this->_ldap, $config);

        /* 
         * Initialize Smarty.
         */

        // Call the parent initialization
        $this->Smarty();

        $basedir = $config['smarty_basedir'];
        $this->template_dir = $basedir . 'templates/';
        $this->compile_dir = $basedir . 'templates_c/';
        $this->config_dir = $basedir . 'configs/';
        $this->cache_dir = $basedir . 'cache/';

        $this->assign( 'topdir', $config['topdir'] );
        $this->assign( 'prefix', $config['webserver_web_prefix'] );
        $this->assign( 'self_url', $_SERVER['REQUEST_URI'] );

        /* 
         * Handle locale support.
         */

        // Check if the language should be changed
        if(!empty($_REQUEST["lang"])) {
            setLanguage($_REQUEST["lang"]);
        }

        // I18N support information
        $language = getLanguage();
        putenv("LANG=$language"); 
        putenv("LANGUAGE=$language"); 
        setlocale(LC_ALL, $language);

        $domain = "messages";

        bindtextdomain($domain, $locale_dir); 
        bind_textdomain_codeset($domain, "UTF-8");
        textdomain($domain);

        // Added for i18n management (Romain 05-03-03)
        $this->register_function("tr", "translate");

        $this->assign( 'currentlang', $language );
        $this->assign( 'languages', offered_languages());

        $cleanurl = preg_replace('/(\?|&)lang=(.*)(&|$)/', 
                                 '', 
                                 $_SERVER['REQUEST_URI']);
        $this->assign( 'lang_url', 
                       strpos($cleanurl, '?') === false ?
                       ($cleanurl . '?lang='):
                       ($cleanurl . '&lang=') 
        );

        /* 
         * Time to check our authentication status.
         */
        $authenticated = $this->auth->authenticate();

        // The user is not authenticated
        if ($authenticated == 0 || $authenticated == 2) {
            $this->assign( 'uid', '' );
            $this->assign( 'group', '' );
            $this->assign( 'menuitems', array() );
            // Show the login page
            $this->assign( 'maincontent', 'login.tpl' );
            if ($this->auth->error()) { 
                $this->assign( 'errors', $this->auth->error() );
            }
            if ($authenticated == 0) {
                $this->assign( 'page_title', _('Error') );
            } else {
                $this->assign( 'page_title', _('Login') );
            }
            // Display and exit
            $this->display('page.tpl');
            exit();
        }

        // User is authenticated
        $this->assign( 'uid', $this->auth->uid() );
        $this->assign( 'group', $this->auth->group() );

        // Get the menu the user is able to see
        $this->_menuitems = generate_menu($this->auth, $params['topdir']);

        // Leave it to the calling class to display stuff
    }

    /**
     * Check if all domains have been correctly initialized.
     *
     * @return boolean true if all domains have the necessary
     * distribution lists
     */
    function domains_valid() 
    {
        $domains = $this->ldap->domains();
        foreach( $domains as $domain ) {
            if( !$this->ldap->exists_group( 'hostmaster@' . $domain ) ||
                !$this->ldap->exists_group( 'postmaster@' . $domain ) ||
                !$this->ldap->exists_group( 'abuse@' . $domain ) ||
                !$this->ldap->exists_group( 'virusalert@' . $domain ) ||
                !$this->ldap->exists_group( 'MAILER-DAEMON@' . $domain ) ) {
                return false;
            }
        }
        return true;
    }
    
    /**
     * Produce the page headers.
     */
    function output_headers()
    {
        header("Content-Type: text/html; charset=UTF-8");
        header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
        header("Cache-Control: no-cache, must-revalidate");
        header("Pragma: no-cache");
    }

    /**
     * Set the page content template.
     *
     * @param string $content The content of the page
     */
    function render($contenttemplate)
    {
        $this->assign( 'maincontent', $contenttemplate );
    }

    /**
     * Set the page title.
     *
     * @param string $title The title of the page
     */
    function setTitle($title)
    {
        $this->assign( 'page_title', $title );
    }

    /**
     * Set the web admin section
     *
     * @param string $section The section of the web admin
     */
    function setSection($section = '')
    {
        $this->_section = $section;

        $title = 'Kolab';
        $submenu = array();

        if (isset($this->_menuitems[$section])) {
            $this->_menuitems[$section]['selected'] = 'selected';
            if (isset($this->_menuitems[$section]['title'])) {
                $title = $this->_menuitems[$section]['title'];
            }
            if (isset($this->_menuitems[$section]['submenu'])) {
                $submenu = $this->_menuitems[$section]['submenu'];
            }
        }

        $this->assign( 'page_title', $title);
        $this->assign( 'submenu', $submenu);
    }

    /**
     * Render a page.
     *
     * @param string $template Name of the template to display
     */
    function render($template = 'page.tpl')
    {
        $this->output_headers();

        // Set the visible menu
        $this->assign( 'menuitems', $this->menuitems );

        // Render the page
        $this->display($template);
        
    }
    
    /**
     * Check if the current user is the site admin.
     *
     * @return boolean true if the current user is the site admin
     */
    function isAdmin()
    {
        return $this->auth->group() == 'admin';
    }
};

/*
  Local variables:
  mode: php
  indent-tabs-mode: f
  tab-width: 4
  buffer-file-coding-system: utf-8
  End:
  vim:encoding=utf-8:
 */
?>

Index: form.class.php
===================================================================
RCS file: /kolabrepository/server/php-kolab/Kolab_Webadmin/Webadmin/form.class.php,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -d -r1.4 -r1.5
--- form.class.php	17 Aug 2007 08:48:50 -0000	1.4
+++ form.class.php	17 Aug 2007 16:31:44 -0000	1.5
@@ -32,14 +32,6 @@
  *
  */
 
-function output_headers()
-{
-    header("Content-Type: text/html; charset=UTF-8");
-    header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
-    header("Cache-Control: no-cache, must-revalidate");
-    header("Pragma: no-cache");
-}
-
 //FIXME: Does not work like this
 function checkuniquealias( $form, $key, $value, $ldap, $action, $dn, $base_dn ) {
   $excludedn = false;

Index: locale.php
===================================================================
RCS file: /kolabrepository/server/php-kolab/Kolab_Webadmin/Webadmin/locale.php,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -d -r1.2 -r1.3
--- locale.php	16 Aug 2007 15:52:01 -0000	1.2
+++ locale.php	17 Aug 2007 16:31:44 -0000	1.3
@@ -28,12 +28,59 @@
  *  ABOUT
  *  -----
  *
- *  Provides functions for language detection.
+ *  Provides functions for locale support.
  *
  */
 
-function supported_lang($lang) {
+/**
+ * This function returns the languages supported by the Kolab web
+ * admin.  If you add a translation, add the new language here
+ *
+ * $Header$
+ *
+ * @author  Steffen Hansen   <steffen at klaralvdalens-datakonsult.se>
+ * @author  Romain Pokrzywka <romain at kdab.net>
+ * @author  Gunnar Wrobel    <wrobel at pardus.de>
+ * @package Kolab_Webadmin
+ */
+function offered_languages() 
+{
+	return array( 
+		array( 
+			'name' => 'Deutsch',
+			'code' => 'de_DE' ),
+		array( 
+			'name' => 'English',
+			'code' => 'en_US' ),
+		array( 
+			'name' => 'Français',
+			'code' => 'fr_FR' ),
+		array( 
+			'name' => 'Italiano',
+			'code' => 'it_IT' ),
+		array( 
+			'name' => 'Nederlands',
+			'code' => 'nl_NL' ),
+		array( 
+			'name' => 'Español',
+			'code' => 'es_ES' ),
+	);
+
+}
 
+/**
+ * This function converts a language identifier into the Kolab web
+ * admin language id.  If you add a translation, add the new language
+ * here
+ *
+ * $Header$
+ *
+ * @author  Steffen Hansen   <steffen at klaralvdalens-datakonsult.se>
+ * @author  Romain Pokrzywka <romain at kdab.net>
+ * @package Kolab_Webadmin
+ */
+function supported_lang($lang) 
+{
     // REMEMBER TO UPDATE THIS WHEN ADDING NEW LANGUAGES
     $a = array("de"    => "de_DE",
 			   "de_de" => "de_DE",
@@ -50,12 +97,23 @@
 			   "es_es" => "es_ES");
 
     // Locales must be in the format xx_YY to be recognized by xgettext
-    $lang = strtolower(str_replace('-','_',$lang));
-    if( !array_key_exists( $lang, $a ) ) return false;
-    else return $a[$lang];
+    $lang = strtolower(str_replace('-', '_', $lang));
+    if( !array_key_exists( $lang, $a ) ) {
+		return false;
+	} else {
+		return $a[$lang];
+	}
 }
 
-// This function is called in templates my Smarty
+/**
+ * Translates a string into the current language
+ *
+ * $Header$
+ *
+ * @author  Steffen Hansen   <steffen at klaralvdalens-datakonsult.se>
+ * @author  Romain Pokrzywka <romain at kdab.net>
+ * @package Kolab_Webadmin
+ */
 function translate($params) 
 {
     $msg = $params["msg"];
@@ -67,11 +125,18 @@
     }
 }
 
-# Returns the currently selected language
+/**
+ * Returns the currently selected language.
+ *
+ * $Header$
+ *
+ * @author  Steffen Hansen   <steffen at klaralvdalens-datakonsult.se>
+ * @author  Romain Pokrzywka <romain at kdab.net>
+ * @package Kolab_Webadmin
+ */
 function getLanguage()
 {
-    if(empty($_SESSION["lang"])) 
-    {
+    if(empty($_SESSION["lang"])) {
 	    $acceptList = $_SERVER["HTTP_ACCEPT_LANGUAGE"];
         if(empty($acceptList)) {
 			$lang = "en";
@@ -90,13 +155,23 @@
 				}
 			}
         }
-		if( !$lang ) $lang = "en";
+		if( !$lang ) {
+			$lang = "en";
+		}
         setLanguage($lang);
     }    
     return supported_lang($_SESSION["lang"]);
 }
 
-# Allows languages to be set by users
+/**
+ * Set the current language.
+ *
+ * $Header$
+ *
+ * @author  Steffen Hansen   <steffen at klaralvdalens-datakonsult.se>
+ * @author  Romain Pokrzywka <romain at kdab.net>
+ * @package Kolab_Webadmin
+ */
 function setLanguage($lang)
 {   
     $lang = supported_lang($lang);





More information about the commits mailing list