openrat-cms

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs

commit 23ebe2df6ad4a0dcaa63be71d23637face28976b
parent 5eff407c84cd0a3329f65bdbbaa9922823a03322
Author: dankert <devnull@localhost>
Date:   Wed, 10 Nov 2004 23:36:45 +0100

Laden von Projektklassen und Lesen/Schreiben von/nach Session

Diffstat:
actionClasses/IndexAction.class.php | 594++++++++++++++++++++++++++++++++++++++++++-------------------------------------
1 file changed, 317 insertions(+), 277 deletions(-)

diff --git a/actionClasses/IndexAction.class.php b/actionClasses/IndexAction.class.php @@ -1,279 +1,319 @@ -<?php -// --------------------------------------------------------------------------- -// $Id$ -// --------------------------------------------------------------------------- -// OpenRat Content Management System -// Copyright (C) 2002 Jan Dankert, jandankert@jandankert.de -// -// 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. -// --------------------------------------------------------------------------- +<?php +// --------------------------------------------------------------------------- +// $Id$ +// --------------------------------------------------------------------------- +// OpenRat Content Management System +// Copyright (C) 2002 Jan Dankert, jandankert@jandankert.de +// +// 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +// --------------------------------------------------------------------------- // $Log$ -// Revision 1.2 2004-05-02 14:49:37 dankert -// Einfügen package-name (@package) -// -// Revision 1.1 2004/04/24 15:14:52 dankert -// Initiale Version -// -// --------------------------------------------------------------------------- - - -/** - * Action-Klasse fuer die Start-Action - * @author $Author$ - * @version $Revision$ - * @package openrat.actions - */ - -class IndexAction extends Action -{ - var $defaultSubAction = 'show'; - - - function checkLogin( $name,$pw,$db ) - { - Logger::debug( "user $name wants to log in at database $db" ); - - global $conf; - global $SESS; - - unset( $SESS['user'] ); - - - $db = db_connection(); - - $ip = getenv("REMOTE_ADDR"); - - $user = new User(); - $user->name = $name; - - $ok = $user->checkPassword( $pw ); - - // Falls Login erfolgreich - if ( $ok ) - { - // Login war erfolgreich! - $user->load(); - $user->setCurrent(); - -// // Gruppen lesen -// $sql = new Sql('SELECT groupid FROM {t_usergroup} '. -// 'WHERE userid={userid}'); -// $sql->setInt('userid',$SESS['user']['id']); -// $groups = $db->getCol( $sql->query ); -// -// $SESS['user']['projects'] = array(); -// -// -// // Alle ACLs zum Benutzer (und seinen Gruppen) werden gelesen und -// // dem Benutzer in der aktuellen Session hinzugefügt. -// foreach( Acl::getACLsFromUserId($user->userid) as $aclid ) -// { -// $user->addACL( $aclid ); -// } -// -// foreach( $user->getGroupIds() as $groupid ) -// { -// foreach( Acl::getACLsFromGroupId($groupid) as $aclid ) -// { -// $user->addACL( $aclid ); -// } -// } - - // print_r( $SESS['user']['rights'] ); - - // $SESS['rights'] = array(); - - // $sql = new Sql('SELECT * FROM {t_acl} WHERE userid={userid}'); - // $sql->setInt('userid',$SESS['user']['id']); - // $res = $db->query( $sql->query ); - // - // while( $row = $res->fetchRow() ) - // { - // $f = new Folder( $row['folderid'] ); - // $f->projectid = $row['projectid']; - // $f->addrights( $row ); - // unset( $f ); - // } - - // foreach( $groups as $groupid ) - // { - // $sql = new Sql('SELECT * FROM {t_acl} WHERE groupid={groupid}'); - // $sql->setInt('groupid',$groupid); - // $res = $db->query( $sql->query ); - // - // while( $row = $res->fetchRow() ) - // { - // $f = new Folder( $row['folderid'] ); - // $f->projectid = $row['projectid']; - // $f->addrights( $row ); - // unset( $f ); - // } - // } - - // Wenn keine Berechtigung vorhanden, dann kein Login möglich -// if ( count($SESS['user']) == 0 && $SESS['user']['is_admin']!='1' ) -// { -// unset($SESS['user']); -// } -// else -// { -// if ( $SESS['user']['is_admin']=='1' ) -// { -// // Für Administratoren einfach das 1.vorhandene Projekt auswählen -// $sql = new SQL('SELECT id FROM {t_project} ORDER BY name'); -// $SESS['projectid'] = $db->getOne( $sql->query ); -// //echo "fuck, verdammt".$SESS['projectid']; -// } -// else -// { -// // Wenn noch kein Projekt in der Session vorhanden, dann -// // das erste Projekt starten -// if ( !is_numeric($SESS['projectid']) ) -// { -// $projects = array_keys( $SESS['rights'] ); -// $SESS['projectid'] = $projects[0]; -// } -// } -// } - } - - if ( isset($SESS['user']) ) - { - Logger::info( 'login successful' ); - } - else - { - Logger::info( "login for user $name failed" ); - - $SESS['loginmessage'] = lang('LOGIN_FAILED'); - } - } - - - function login() - { - global $SESS; - # Ein Benutzer versucht sich anzumelden - # - unset( $SESS['user'] ); - - $SESS['dbid'] = $this->getRequestVar('dbid'); - - $this->checkLogin( $this->getRequestVar('login_name' ), - $this->getRequestVar('login_password'), - $this->getRequestVar('dbid' ) ); - - - $this->callSubAction('show'); - } - - - function logout() - { - global $SESS; - unset( $SESS['user'] ); - - $this->callSubAction('show'); - } - - - function show() - { - global $SESS,$conf; - - if ( !isset($SESS['lang']) ) - { - language_read(); - } - - - // Authorization über HTTP - // - if ( $conf['auth']['type'] == 'http' ) - { - if ( isset($PHP_AUTH_USER) ) - { - login( $PHP_AUTH_USER,$PHP_AUTH_PW,$db ); - } - - # Falls Benutzer nicht angemeldet, dann Login-Maske präsentieren - # - if ( !isset($sess_user) ) - { - header( 'WWW-Authenticate: Basic realm="Login"' ); - header( 'HTTP/1.0 401 Unauthorized' ); - echo 'Authorization Required!'; - exit; - } - } - - - $title = $conf['global']['title'].' '.$conf['global']['version']; - - if (!isset($SESS['user'])) - { - $this->setTemplateVar( 'title',lang('NOT_LOGGED_IN').' - '.$title ); - $this->setTemplateVar( 'frame_src_main',Html::url( array('action'=>'main', - 'callAction'=>'login', - 'callSubaction'=>'login' )) ); - } - else - { - $this->setTemplateVar( 'title',$SESS['user']['name'].' @'.$conf['database_'.$SESS['dbid']]['comment'].' - '.$title ); - - if ( $this->getSessionVar('objectid') != '' ) - { - $object = new Object( $this->getSessionVar('objectid') ); - $object->load(); - $this->setSessionVar('projectid',$object->projectid); - - $this->setTemplateVar( 'frame_src_main' ,Html::url( array('action'=>'main', - 'callAction'=>$object->getType() )) ); - } - else - { - if ( $this->getSessionVar('projectid') != '' ) - { - $project = new Project( $this->getSessionVar('projectid') ); - $objectid = $project->getRootObjectId(); - $this->setSessionVar('objectid',$objectid); - - $this->setTemplateVar( 'frame_src_main' ,Html::url( array('action'=>'main', - 'callAction'=>'folder' )) ); - } - else - { - $this->setTemplateVar( 'frame_src_main' ,Html::url( array('action'=>'main', - 'callAction'=>'login', - 'callSubaction'=>'blank' )) ); - } - } - } - - $this->setTemplateVar( 'frame_src_title' ,Html::url( array('action'=>'title' )) ); - $this->setTemplateVar( 'frame_src_treemenu',Html::url( array('action'=>'treemenu')) ); - $this->setTemplateVar( 'frame_src_tree' ,Html::url( array('action'=>'tree', - 'subaction'=>'reload')) ); - - // Breite des Baums ermitteln - if (isset($SESS['user'])) - $this->setTemplateVar( 'tree_width',$conf['global']['tree_width'] ); - else $this->setTemplateVar( 'tree_width','0' ); - - $this->forward( 'frameset' ); - } -} - +// Revision 1.3 2004-11-10 22:36:45 dankert +// Laden von Projektklassen und Lesen/Schreiben von/nach Session +// +// Revision 1.2 2004/05/02 14:49:37 dankert +// Einf?gen package-name (@package) +// +// Revision 1.1 2004/04/24 15:14:52 dankert +// Initiale Version +// +// --------------------------------------------------------------------------- + + +/** + * Action-Klasse fuer die Start-Action + * @author $Author$ + * @version $Revision$ + * @package openrat.actions + */ + +class IndexAction extends Action +{ + var $defaultSubAction = 'show'; + + + function checkForDb() + { + global $conf; + $dbid = $this->getRequestVar('dbid'); + + if ( $dbid != '' ) + { + $db = new DB( $conf['database_'.$dbid] ); + $db->id = $dbid; + $db->setFetchMode( DB_FETCHMODE_ASSOC ); + Session::setDatabase( $db ); + } + } + + + + function checkLogin( $name,$pw ) + { + Logger::debug( "login user $name" ); + + global $conf; + global $SESS; + + unset( $SESS['user'] ); + + + $db = db_connection(); + + $ip = getenv("REMOTE_ADDR"); + + $user = new User(); + $user->name = $name; + + $ok = $user->checkPassword( $pw ); + + // Falls Login erfolgreich + if ( $ok ) + { + // Login war erfolgreich! + $user->load(); + $user->loadProjects(); + //$user->loadRights(); + $user->setCurrent(); + Session::setUser( $user ); + Logger::info( 'login successful' ); + + return true; + } + else + { + Logger::info( "login for user $name failed" ); + $SESS['loginmessage'] = lang('LOGIN_FAILED'); + + return false; + } + } + + + function showlogin() + { + global $conf; + + + $databases = explode(',',$conf['database']['databases']); + $dbids = array(); + + foreach( $databases as $db ) + { + if ( !isset($conf['database_'.$db]) ) + $this->message( '',"configuration for 'database_$db' not defined in config.ini.php"); + + $dbids[$db] = $conf['database_'.$db]['comment']; + } + + $this->setTemplateVar( 'dbids',$dbids ); + + if ( $this->getSessionVar('dbid') != '' ) + $this->setTemplateVar('actdbid',$this->getSessionVar('dbid')); + $this->setTemplateVar('actdbid',$conf['database']['default']); + + $this->setTemplateVar('loginmessage',$this->getSessionVar('loginmessage')); + $this->setSessionVar('loginmessage',''); + + $this->forward('login'); + } + + function showmenu() + { + $user = Session::getUser(); + $projects = $user->projects; + + // Administrator sieht Administrationsbereich + if ( $user->isAdmin ) + $projects = array("-1"=>lang('ADMINISTRATION')) + $projects; + + // Projekte ermitteln + + $list = array(); + foreach( $projects as $id=>$name ) + { + $list[$id] = array(); + $list[$id]['url' ] = Html::url(array('action'=>'index','subaction'=>'show','projectid'=>$id)); + $list[$id]['name'] = $name; + } + $this->setTemplateVar('el',$list); + + $this->forward('project_select'); + } + + function login() + { + global $SESS; + global $conf; + # Ein Benutzer versucht sich anzumelden + # + $this->checkForDb(); + unset( $SESS['user'] ); + Session::setUser(''); + + $this->checkLogin( $this->getRequestVar('login_name' ), + $this->getRequestVar('login_password') ); + + $this->callSubAction('show'); + } + + + function logout() + { + global $SESS; + unset( $SESS['user'] ); + Session::setUser(''); + + $this->callSubAction('show'); + } + + + function show() + { + global $conf; + + if ( Session::getLanguage() === '' ) + language_read(); + + $user = Session::getUser(); + if ( ! is_object($user) ) + { + // Authorization ueber HTTP + // + if ( $conf['auth']['type'] == 'http' ) + { + if ( isset($PHP_AUTH_USER) ) + { + $this->checkLogin( $PHP_AUTH_USER,$PHP_AUTH_PW ); + } + else + { + header( 'WWW-Authenticate: Basic realm="OpenRat Content Management System - Login"' ); + header( 'HTTP/1.0 401 Unauthorized' ); + echo 'Authorization Required!'; + exit; + } + } + + // Benutzer ist nicht angemeldet + $this->callSubAction( 'showlogin' ); // Anzeigen der Login-Maske + } + + $title = $conf['global']['title'].' '.$conf['global']['version']; + + + $projectid = intval( $this->getRequestVar('projectid' ) ); + $languageid = intval( $this->getRequestVar('languageid') ); + $objectid = intval( $this->getRequestVar('objectid' ) ); + + if ( $objectid > 0 ) + { + $objectid = new Object( $objectid ); + $object->objectLoadRaw(); + Session::setObject( $object ); + + $project = new Project( $object->projectid ); + $project->load(); + Session::setProject( $project ); + + $language = new Language( $project->getDefaultLanguageId() ); + $language->load(); + Session::setProjectLanguage( $language ); + + $model = new Model( $project->getDefaultModelId() ); + $model->load(); + Session::setProjectModel( $model ); + + $user->loadRights( $project->projectid,$language->languageid ); + Session::setUser( $user ); + } + elseif ( $languageid > 0 ) + { + $language = new Language( $languageid ); + $language->load(); + Session::setProjectLanguage( $language ); + + $project = new Project( $language->projectid ); + $project->load(); + Session::setProject( $project ); + + $model = new Model( $project->getDefaultModelId() ); + $model->load(); + Session::setProjectModel( $model ); + + $object = new Object( $project->getRootObjectId() ); + $object->objectLoadRaw(); + Session::setObject( $object ); + + $user->loadRights( $project->projectid,$language->languageid ); + Session::setUser( $user ); + } + elseif ( $projectid > 0 ) + { + $project = new Project( $projectid ); + $project->load(); + Session::setProject( $project ); + + $language = new Language( $project->getDefaultLanguageId() ); + $language->load(); + Session::setProjectLanguage( $language ); + + $model = new Model( $project->getDefaultModelId() ); + $model->load(); + Session::setProjectModel( $model ); + + $object = new Object( $project->getRootObjectId() ); + $object->objectLoadRaw(); + Session::setObject( $object ); + + $user->loadRights( $project->projectid,$language->languageid ); + Session::setUser( $user ); + } + + + $db = Session::getDatabase(); + $this->setTemplateVar( 'title',$user->name.' @'.$db->conf['comment'].' - '.$title ); + + $object = Session::getObject(); + $project = Session::getProject(); + + if ( is_object($object) ) + { + $this->setTemplateVar( 'frame_src_main' ,Html::url( array('action' =>'main', + 'callAction'=>$object->getType() )) ); + } + elseif ( is_object($project) ) + { + + $this->setTemplateVar( 'frame_src_main' ,Html::url( array('action'=>'main', + 'callAction'=>'folder' )) ); + } + else + { + $this->callSubAction( 'showmenu' ); + } + + $this->setTemplateVar( 'frame_src_title' ,Html::url( array('action'=>'title' )) ); + $this->setTemplateVar( 'frame_src_treemenu',Html::url( array('action'=>'treemenu')) ); + $this->setTemplateVar( 'frame_src_tree' ,Html::url( array('action'=>'tree', + 'subaction'=>'load')) ); + + $this->setTemplateVar( 'tree_width',$conf['global']['tree_width'] ); + + $this->forward( 'frameset' ); + } +} + ?> \ No newline at end of file