openrat-cms

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

commit 42acf4d2ae5d97ec8825afe3e9c43365e6c7191f
parent 7b99827f71acc0960d6cc34063372822f74c4503
Author: dankert <devnull@localhost>
Date:   Mon, 27 Dec 2010 23:52:46 +0100

Objekt-Klassen verschieben: objectClasses -> model

Diffstat:
do.php | 2+-
model/.htaccess | 3+++
model/Acl.class.php | 510+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
model/Element.class.php | 523+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
model/File.class.php | 712+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
model/Folder.class.php | 827+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
model/Group.class.php | 355+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
model/Language.class.php | 287+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
model/Link.class.php | 172+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
model/Model.class.php | 283+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
model/Object.class.php | 1390+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
model/ObjectFactory.php | 58++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
model/Page.class.php | 881+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
model/Project.class.php | 729+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
model/Template.class.php | 426+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
model/User.class.php | 1130+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
model/Value.class.php | 1504+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
model/include.inc.php | 20++++++++++++++++++++
objectClasses/.htaccess | 3---
objectClasses/Acl.class.php | 510-------------------------------------------------------------------------------
objectClasses/Element.class.php | 523-------------------------------------------------------------------------------
objectClasses/File.class.php | 712-------------------------------------------------------------------------------
objectClasses/Folder.class.php | 827-------------------------------------------------------------------------------
objectClasses/Group.class.php | 355-------------------------------------------------------------------------------
objectClasses/Language.class.php | 287-------------------------------------------------------------------------------
objectClasses/Link.class.php | 172-------------------------------------------------------------------------------
objectClasses/Model.class.php | 283-------------------------------------------------------------------------------
objectClasses/Object.class.php | 1390-------------------------------------------------------------------------------
objectClasses/ObjectFactory.php | 58----------------------------------------------------------
objectClasses/Page.class.php | 881-------------------------------------------------------------------------------
objectClasses/Project.class.php | 729-------------------------------------------------------------------------------
objectClasses/Template.class.php | 426-------------------------------------------------------------------------------
objectClasses/User.class.php | 1130-------------------------------------------------------------------------------
objectClasses/Value.class.php | 1504-------------------------------------------------------------------------------
objectClasses/include.inc.php | 20--------------------
35 files changed, 9811 insertions(+), 9811 deletions(-)

diff --git a/do.php b/do.php @@ -42,7 +42,7 @@ define('OR_TYPE_FOLDER','folder'); define('OR_ACTIONCLASSES_DIR' ,'./action/' ); define('OR_FORMCLASSES_DIR' ,'./formClasses/' ); -define('OR_OBJECTCLASSES_DIR' ,'./objectClasses/' ); +define('OR_OBJECTCLASSES_DIR' ,'./model/' ); define('OR_SERVICECLASSES_DIR','./serviceClasses/' ); define('OR_LANGUAGE_DIR' ,'./language/' ); define('OR_DBCLASSES_DIR' ,'./db/' ); diff --git a/model/.htaccess b/model/.htaccess @@ -0,0 +1,2 @@ +order deny,allow +deny from all+ \ No newline at end of file diff --git a/model/Acl.class.php b/model/Acl.class.php @@ -0,0 +1,509 @@ +<?php +// OpenRat Content Management System +// Copyright (C) 2002-2009 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. + + + +// Definition der Berechtigungs-Bits +define('ACL_READ' ,1 ); +define('ACL_WRITE' ,2 ); +define('ACL_PROP' ,4 ); +define('ACL_DELETE' ,8 ); +define('ACL_RELEASE' ,16 ); +define('ACL_PUBLISH' ,32 ); +define('ACL_CREATE_FOLDER',64 ); +define('ACL_CREATE_FILE' ,128 ); +define('ACL_CREATE_LINK' ,256 ); +define('ACL_CREATE_PAGE' ,512 ); +define('ACL_GRANT' ,1024); +define('ACL_TRANSMIT' ,2048); + + + +/** + * Darstellen einer Berechtigung (ACL "Access Control List") + * Die Berechtigung zu einem Objekt wird mit einer Liste dieser Objekte dargestellt + * + * Falls es mehrere ACLs zu einem Objekt gibt, werden die Berechtigung-Flags addiert. + * + * @author Jan Dankert + * @package openrat.objects + */ +class Acl +{ + /** + * eindeutige ID dieser ACL + * @type Integer + */ + var $aclid; + + /** + * ID des Objektes, f?r das diese Berechtigung gilt + * @type Integer + */ + var $objectid = 0; + + /** + * ID des Benutzers + * ( = 0 falls die Berechtigung f?r eine Gruppe gilt) + * @type Integer + */ + var $userid = 0; + + /** + * ID der Gruppe + * ( = 0 falls die Berechtigung f?r einen Benutzer gilt) + * @type Integer + */ + var $groupid = 0; + + /** + * ID der Sprache + * @type Integer + */ + var $languageid = 0; + + /** + * Name der Sprache + * @type String + */ + var $languagename = ''; + + /** + * Es handelt sich um eine Standard-Berechtigung + * (Falls false, dann Zugriffs-Berechtigung) + * @type Boolean + */ + var $isDefault = false; + + /** + * Name des Benutzers, f?r den diese Berechtigung gilt + * @type String + */ + var $username = ''; + + /** + * Name der Gruppe, f?r die diese Berechtigung gilt + * @type String + */ + var $groupname = ''; + + /** + * Inhalt lesen (ist immer wahr) + * @type Boolean + */ + var $read = true; + + /** + * Inhalt bearbeiten + * @type Boolean + */ + var $write = false; + + /** + * Eigenschaften bearbeiten + * @type Boolean + */ + var $prop = false; + + /** + * Objekt l?schen + * @type Boolean + */ + var $delete = false; + + /** + * Objektinhalt freigeben + * @type Boolean + */ + var $release = false; + + /** + * Objekt ver?ffentlichen + * @type Boolean + */ + var $publish = false; + + /** + * Unterordner anlegen + * @type Boolean + */ + var $create_folder = false; + + /** + * Datei anlegen (bzw. hochladen) + * @type Boolean + */ + var $create_file = false; + + /** + * Verknuepfung anlegen + * @type Boolean + */ + var $create_link = false; + + /** + * Seite anlegen + * @type Boolean + */ + var $create_page = false; + + /** + * Berechtigungen vergeben + * @type Boolean + */ + var $grant = false; + + /** + * Berechtigungen an Unterobjekte vererben + * @type Boolean + */ + var $transmit = false; + + + /** + * Konstruktor. + * + * @param Integer Acl-ID + */ + function Acl( $aclid = 0 ) + { + if ( $aclid != 0 ) + $this->aclid = $aclid; + } + + + /** + * Laden einer ACL inklusive Benutzer-, Gruppen- und Sprachbezeichnungen. + * Zum einfachen Laden sollte #loadRaw() benutzt werden. + */ + function load() + { + $db = db_connection(); + + $sql = new Sql( 'SELECT {t_acl}.*,{t_user}.name as username,{t_group}.name as groupname,{t_language}.name as languagename'. + ' FROM {t_acl} '. + ' LEFT JOIN {t_user} ON {t_user}.id = {t_acl}.userid '. + ' LEFT JOIN {t_group} ON {t_group}.id = {t_acl}.groupid '. + ' LEFT JOIN {t_language} ON {t_language}.id = {t_acl}.languageid '. + ' WHERE {t_acl}.id={aclid}' ); + + $sql->setInt('aclid',$this->aclid); + + $row = $db->getRow( $sql ); + + $this->setDatabaseRow( $row ); + + if ( intval($this->languageid)==0 ) + $this->languagename = lang('GLOBAL_ALL_LANGUAGES'); + else $this->languagename = $row['languagename']; + $this->username = $row['username' ]; + $this->groupname = $row['groupname' ]; + } + + + /** + * Laden einer ACL (ohne verknuepfte Namen). + * Diese Methode ist schneller als #load(). + */ + function loadRaw() + { + $db = db_connection(); + + $sql = new Sql( 'SELECT * '. + ' FROM {t_acl} '. + ' WHERE {t_acl}.id={aclid}' ); + + $sql->setInt('aclid',$this->aclid); + + $row = $db->getRow( $sql ); + + $this->setDatabaseRow( $row ); + } + + + /** + * Setzt die Eigenschaften des Objektes mit einer Datenbank-Ergebniszeile. + * + * @param row Ergebniszeile aus ACL-Datenbanktabelle + */ + function setDatabaseRow( $row ) + { + $this->aclid = $row['id']; + + $this->write = ( $row['is_write' ] == '1' ); + $this->prop = ( $row['is_prop' ] == '1' ); + $this->delete = ( $row['is_delete' ] == '1' ); + $this->release = ( $row['is_release' ] == '1' ); + $this->publish = ( $row['is_publish' ] == '1' ); + $this->create_folder = ( $row['is_create_folder'] == '1' ); + $this->create_file = ( $row['is_create_file' ] == '1' ); + $this->create_page = ( $row['is_create_page' ] == '1' ); + $this->create_link = ( $row['is_create_link' ] == '1' ); + $this->grant = ( $row['is_grant' ] == '1' ); + $this->transmit = ( $row['is_transmit' ] == '1' ); + + $this->objectid = intval($row['objectid' ]); + $this->languageid = intval($row['languageid']); + $this->userid = intval($row['userid' ]); + $this->groupid = intval($row['groupid' ]); + } + + + /** + * Erzeugt eine Liste aller Berechtigungsbits dieser ACL. + * + * @return Array (Schluessel=Berechtigungstyp, Wert=boolean) + */ + function getProperties() + { + return Array( 'read' => true, + 'write' => $this->write, + 'prop' => $this->prop, + 'create_folder'=> $this->create_folder, + 'create_file' => $this->create_file, + 'create_link' => $this->create_link, + 'create_page' => $this->create_page, + 'delete' => $this->delete, + 'release' => $this->release, + 'publish' => $this->publish, + 'grant' => $this->grant, + 'transmit' => $this->transmit, + 'is_default' => $this->isDefault, + 'userid' => $this->userid, + 'username' => $this->username, + 'groupid' => $this->groupid, + 'groupname' => $this->groupname, + 'languageid' => $this->languageid, + 'languagename' => $this->languagename, + 'objectid' => $this->objectid ); + + } + + + /** + * Erzeugt eine Liste aller möglichen Berechtigungstypen. + * + * @return 0..n-Array + */ + function getAvailableRights() + { + return array( 'read', + 'write', + 'prop', + 'create_folder', + 'create_file', + 'create_link', + 'create_page', + 'delete', + 'release', + 'publish', + 'grant', + 'transmit' ); + + } + + + /** + * Erzeugt eine Bitmaske mit den Berechtigungen dieser ACL. + * + * @return Integer Bitmaske + */ + function getMask() + { + // intval(boolean) erzeugt numerisch 0 oder 1 :) + $this->mask = ACL_READ; // immer lesen + $this->mask += ACL_WRITE *intval($this->write ); + $this->mask += ACL_PROP *intval($this->prop ); + $this->mask += ACL_DELETE *intval($this->delete ); + $this->mask += ACL_RELEASE *intval($this->release ); + $this->mask += ACL_PUBLISH *intval($this->publish ); + $this->mask += ACL_CREATE_FOLDER *intval($this->create_folder); + $this->mask += ACL_CREATE_FILE *intval($this->create_file ); + $this->mask += ACL_CREATE_LINK *intval($this->create_link ); + $this->mask += ACL_CREATE_PAGE *intval($this->create_page ); + $this->mask += ACL_GRANT *intval($this->grant ); + $this->mask += ACL_TRANSMIT *intval($this->transmit ); + + Logger::trace('mask of acl '.$this->aclid.': '.$this->mask ); + return $this->mask; + } + + + /** + * Erzeugt eine Liste aller gesetzten Berechtigungstypen. + * Beispiel: Array (0:'read',1:'write',2:'transmit') + * + * @return 0..n-Array + */ + function getTrueProperties() + { + $erg = array('read'); + if ( $this->write ) $erg[] = 'write'; + if ( $this->prop ) $erg[] = 'prop'; + if ( $this->create_folder ) $erg[] = 'create_folder'; + if ( $this->create_file ) $erg[] = 'create_file'; + if ( $this->create_link ) $erg[] = 'create_link'; + if ( $this->create_page ) $erg[] = 'create_page'; + if ( $this->delete ) $erg[] = 'delete'; + if ( $this->release ) $erg[] = 'release'; + if ( $this->publish ) $erg[] = 'publish'; + if ( $this->grant ) $erg[] = 'grant'; + if ( $this->transmit ) $erg[] = 'transmit'; + + return $erg; + } + + + + /** + * ACL unwiderruflich loeschen. + */ + function delete() + { + $db = db_connection(); + + $sql = new Sql( 'DELETE FROM {t_acl} '. + ' WHERE id = {aclid} '. + ' AND objectid= {objectid}' ); + + $sql->setInt('aclid' ,$this->aclid ); + $sql->setInt('objectid',$this->objectid); + + $db->query( $sql ); + + $this->aclid = 0; + } + + + /** + * ACL der Datenbank hinzufügen. + */ + function add() + { + $db = db_connection(); + + if ( $this->delete ) + $this->prop = true; + + // Pruefen, ob die ACL schon existiert + $user_comp = intval($this->userid )>0?'=':'IS'; + $group_comp = intval($this->groupid )>0?'=':'IS'; + $language_comp = intval($this->languageid)>0?'=':'IS'; + + $sql = new Sql( <<<SQL + SELECT id FROM {t_acl} + WHERE userid $user_comp {userid} AND + groupid $group_comp {groupid} AND + languageid $language_comp {languageid} AND + objectid = {objectid} AND + is_write = {write} AND + is_prop = {prop} AND + is_create_folder = {create_folder} AND + is_create_file = {create_file} AND + is_create_link = {create_link} AND + is_create_page = {create_page} AND + is_delete = {delete} AND + is_release = {release} AND + is_publish = {publish} AND + is_grant = {grant} AND + is_transmit = {transmit} +SQL +); + + if ( intval($this->userid) == 0 ) + $sql->setNull('userid'); + else + $sql->setInt ('userid',$this->userid); + + if ( intval($this->groupid) == 0 ) + $sql->setNull('groupid'); + else + $sql->setInt ('groupid',$this->groupid); + + $sql->setInt('objectid',$this->objectid); + $sql->setBoolean('write' ,$this->write ); + $sql->setBoolean('prop' ,$this->prop ); + $sql->setBoolean('create_folder',$this->create_folder ); + $sql->setBoolean('create_file' ,$this->create_file ); + $sql->setBoolean('create_link' ,$this->create_link ); + $sql->setBoolean('create_page' ,$this->create_page ); + $sql->setBoolean('delete' ,$this->delete ); + $sql->setBoolean('release' ,$this->release ); + $sql->setBoolean('publish' ,$this->publish ); + $sql->setBoolean('grant' ,$this->grant ); + $sql->setBoolean('transmit' ,$this->transmit ); + + if ( intval($this->languageid) == 0 ) + $sql->setNull('languageid'); + else + $sql->setInt ('languageid',$this->languageid); + + $aclid = intval($db->getOne($sql)); + if ( $aclid > 0 ) + { + // Eine ACL existiert bereits, wir übernehmen diese ID + $this->aclid = $aclid; + return; + } + + + + + $sql = new Sql('SELECT MAX(id) FROM {t_acl}'); + $this->aclid = intval($db->getOne($sql))+1; + + $sql = new Sql( <<<SQL + INSERT INTO {t_acl} + (id,userid,groupid,objectid,is_write,is_prop,is_create_folder,is_create_file,is_create_link,is_create_page,is_delete,is_release,is_publish,is_grant,is_transmit,languageid) + VALUES( {aclid},{userid},{groupid},{objectid},{write},{prop},{create_folder},{create_file},{create_link},{create_page},{delete},{release},{publish},{grant},{transmit},{languageid} ) +SQL +); + + $sql->setInt('aclid' ,$this->aclid ); + + if ( intval($this->userid) == 0 ) + $sql->setNull('userid'); + else + $sql->setInt ('userid',$this->userid); + + if ( intval($this->groupid) == 0 ) + $sql->setNull('groupid'); + else + $sql->setInt ('groupid',$this->groupid); + + $sql->setInt('objectid',$this->objectid); + $sql->setBoolean('write' ,$this->write ); + $sql->setBoolean('prop' ,$this->prop ); + $sql->setBoolean('create_folder',$this->create_folder ); + $sql->setBoolean('create_file' ,$this->create_file ); + $sql->setBoolean('create_link' ,$this->create_link ); + $sql->setBoolean('create_page' ,$this->create_page ); + $sql->setBoolean('delete' ,$this->delete ); + $sql->setBoolean('release' ,$this->release ); + $sql->setBoolean('publish' ,$this->publish ); + $sql->setBoolean('grant' ,$this->grant ); + $sql->setBoolean('transmit' ,$this->transmit ); + + if ( intval($this->languageid) == 0 ) + $sql->setNull('languageid'); + else + $sql->setInt ('languageid',$this->languageid); + + $db->query( $sql ); + } +}+ \ No newline at end of file diff --git a/model/Element.class.php b/model/Element.class.php @@ -0,0 +1,522 @@ +<?php +// OpenRat Content Management System +// Copyright (C) 2002-2010 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. + + + +/** + * Diese Objektklasse stellt ein Element das. + * + * Ein Element ist ein Platzhalter in einem Template und kann verschiedenen + * Typs sein, z.B. Text oder ein Bild. + * + * @author Jan Dankert + * @package openrat.objects + */ +class Element +{ + /** + * Eindeutige ID dieses Elementes + * @type Integer + */ + var $elementid; + + /** + * Template-ID zu der dieses Elementes geh?rt + * @type Integer + */ + var $templateid; + + /** + * Typ des Elementes + * Folgende Typen sind moeglich: + * <ul> + * <li>text</li> + * <li>longtext</li> + * <li>select</li> + * <li>number</li> + * <li>link</li> + * <li>date</li> + * <li>insert</li> + * <li>linkinfo</li> + * <li>linkdate</li> + * <li>code</li> + * <li>info</li> + * <li>infodate</li> + * </ul> + * + * @type String + */ + var $type; + + /** + * Logischer Name dieses Elementes + * @type String + */ + var $name; + + /** + * Beschreibung zu diesem Element + * Zu jedem Element kann eine Beschreibung hinterlegt werden, die dem Redakteur bei der Bearbeitung + * der Inhalte als Bearbeitungshilfe dienen kann. + * @type String + */ + var $desc; + + /** + * Objekt-ID eines Ordners, aus diesem Ordner (samt Unterordner) + * k?nnen zu verlinkende Objekte ausgew?hlt werden + * @type Integer + */ + var $folderObjectId = 0; + + /** + * Vorausgew�hltes Objekt. + * @type Integer + */ + var $defaultObjectId = 0; + + /** + * Schalter ob dieses Element von Redakteuren bearbeiten werden kann + * @type Boolean + */ + var $writable; + + /** + * Schalter, ob dieses Element in allen Sprachen den gleichen Inhalt haben soll + * @type Boolean + */ + var $allLanguages; + + var $readonlyElementNames = array('copy','linkinfo','linkdate','info','infodate','code','dynamic'); + + /** + * Untertyp. + * + * @var String + */ + var $subtype = ''; + var $withIcon = false; + var $dateformat = 'r'; + var $wiki = false; + var $html = false; + var $decimals = 0; + var $decPoint = '.'; + var $thousandSep = ''; + var $code = ''; + var $defaultText = ''; + + + /** + * Im Konstruktor wird die Element-Id gesetzt + * @param Integer Element-Id + */ + function Element( $elementid=0 ) + { + if ( intval($elementid)!=0 ) + $this->elementid = $elementid; + } + + + /** + * Hinzuf?gen eines Elementes + * Das aktuelle Element wird in die Datenbank geschrieben. + */ + function add() + { + $db = db_connection(); + + $sql = new Sql('SELECT MAX(id) FROM {t_element}'); + $this->elementid = intval($db->getOne($sql))+1; + + $sql = new Sql( 'INSERT INTO {t_element}'. + ' (id,templateid,name,descr,type,writable) '. + " VALUES ( {elementid},{templateid},{name},{description},{type},{writable} ) " ); + + $sql->setInt ( 'elementid' ,$this->elementid ); + $sql->setString ( 'name' ,$this->name ); + $sql->setString ( 'type' ,$this->type ); + $sql->setInt ( 'templateid' ,$this->templateid ); + $sql->setBoolean( 'writable' ,$this->writable ); + $sql->setString ( 'description',$this->desc ); + + $db->query( $sql ); + } + + + +// function path_to_page( $pageid ) +// { +// return $this->page->path_to_object( $pageid ); +// } +// function path_to_object( $pageid ) +// { +// return $this->path_to_page( $pageid ); +// } + + + /** + * Lesen des Elementes aus der Datenbank + * Alle Eigenschaften des Elementes werden aus der Datenbank gelesen + */ + function load() + { + if ( intval($this->elementid) != 0 ) + { + $db = db_connection(); + $sql = new Sql( <<<SQL +SELECT * FROM {t_element} + WHERE id={elementid} +SQL +); + $sql->setInt( 'elementid',$this->elementid ); + $this->setDatabaseRow( $db->getRow( $sql ) ); + } + } + + + function setDatabaseRow( $prop ) + { + if ( count($prop) <= 0 ) + return; + + $this->elementid = $prop['id' ]; + $this->templateid = $prop['templateid']; + $this->name = $prop['name' ]; + $this->desc = $prop['descr' ]; + $this->type = $prop['type' ]; + $this->subtype = $prop['subtype' ]; + + $this->dateformat = $prop['dateformat']; + $this->wiki = ( $prop['wiki' ] == '1' ); + $this->withIcon = ( $prop['with_icon' ] == '1' ); + $this->html = ( $prop['html' ] == '1' ); + $this->allLanguages = ( $prop['all_languages'] == '1' ); + $this->writable = ( $prop['writable' ] == '1' ); + + if ( !$this->writable) + $this->withIcon = false; + + $this->decimals = intval( $prop['decimals' ] ); + $this->decPoint = strval( $prop['dec_point' ] ); + $this->thousandSep = strval( $prop['thousand_sep' ] ); + $this->code = strval( $prop['code' ] ); + $this->defaultText = strval( $prop['default_text' ] ); + $this->folderObjectId = intval( $prop['folderobjectid' ] ); + $this->defaultObjectId = intval( $prop['default_objectid'] ); + } + + + /** + * Abspeichern des Elementes + * Das aktuelle Element wird in der Datenbank gespeichert + */ + function save() + { + $db = db_connection(); + + $sql = new Sql( 'UPDATE {t_element}'. + ' SET templateid = {templateid},'. + ' name = {name},'. + ' descr = {desc},'. + ' type = {type},'. + ' subtype = {subtype},'. + ' with_icon = {withIcon},'. + ' dateformat = {dateformat},'. + ' wiki = {wiki},'. + ' html = {html},'. + ' all_languages = {allLanguages},'. + ' writable = {writable},'. + ' decimals = {decimals},'. + ' dec_point = {decPoint},'. + ' thousand_sep = {thousandSep},'. + ' code = {code},'. + ' default_text = {defaultText},'. + ' folderobjectid = {folderObjectId},'. + ' default_objectid= {defaultObjectId}'. + ' WHERE id={elementid}' ); + + $sql->setInt ( 'elementid' ,$this->elementid ); + $sql->setInt ( 'templateid' ,$this->templateid ); + $sql->setString ( 'name' ,$this->name ); + $sql->setString ( 'desc' ,$this->desc ); + $sql->setString ( 'type' ,$this->type ); + $sql->setString ( 'subtype' ,$this->subtype ); + $sql->setBoolean( 'withIcon' ,$this->withIcon ); + $sql->setString ( 'dateformat' ,$this->dateformat ); + $sql->setBoolean( 'wiki' ,$this->wiki ); + $sql->setBoolean( 'html' ,$this->html ); + $sql->setBoolean( 'writable' ,$this->writable ); + $sql->setBoolean( 'allLanguages' ,$this->allLanguages ); + $sql->setInt ( 'decimals' ,$this->decimals ); + $sql->setString ( 'decPoint' ,$this->decPoint ); + $sql->setString ( 'thousandSep' ,$this->thousandSep ); + $sql->setString ( 'code' ,$this->code ); + $sql->setString ( 'defaultText' ,$this->defaultText ); + + if ( intval($this->folderObjectId)==0 ) + $sql->setNull( 'folderObjectId' ); + else $sql->setInt ( 'folderObjectId' ,$this->folderObjectId ); + + if ( intval($this->defaultObjectId)==0 ) + $sql->setNull( 'defaultObjectId' ); + else $sql->setInt ( 'defaultObjectId' ,$this->defaultObjectId ); + + $db->query( $sql ); + } + + + + /** + * Setzt den Typ des Elementes und schreibt diesen sofort in die Datenbank. + * + * @param String Der neue Typ, siehe getAvailableTypes() f?r m?gliche Typen + * @see #type + */ + function setType( $type ) + { + $this->type = $type; + $db = db_connection(); + + $sql = new Sql( 'UPDATE {t_element}'. + ' SET type = {type}'. + ' WHERE id={elementid}' ); + + $sql->setInt ( 'elementid',$this->elementid ); + $sql->setString ( 'type' ,$this->type ); + + $db->query( $sql ); + } + + + /** + * Setzt ein Prefix vor den Elementnamen. + * @param String Prefix + */ + function setPrefix( $prefix ) + { + if ( strrpos($this->name,'%') === FALSE ) + $name = $this->name; + else + list( $oldprefix,$name ) = explode('%',$this->name.'%'); + + $this->name = $prefix.'%'.$name; + } + + + /** + * Loeschen des Elementes und aller Inhalte + */ + function delete() + { + $db = db_connection(); + + // Inhalte l?schen + $this->deleteValues(); + + // Element l?schen + $sql = new Sql('DELETE FROM {t_element} '. + ' WHERE id={elementid}' ); + $sql->setInt( 'elementid',$this->elementid ); + + $db->query( $sql ); + } + + + /** + * L?schen aller Seiteninhalte mit diesem Element + * Das Element wird nicht gel?scht. + */ + function deleteValues() + { + $db = db_connection(); + + // Alle Inhalte mit diesem Element l?schen + $sql = new Sql('DELETE FROM {t_value} '. + ' WHERE elementid={elementid}' ); + $sql->setInt( 'elementid',$this->elementid ); + $db->query( $sql ); + } + + + /** + * Abhaengig vom Element-Typ werden die zur Darstellung notwendigen Eigenschaften ermittelt. + * @return Array() + */ + function getRelatedProperties() + { + $prp = array('text' =>array('withIcon','allLanguages','writable','htmlwiki','defaultText'), + 'longtext'=>array('withIcon','allLanguages','writable','htmlwiki','defaultText'), + 'select' =>array('withIcon','allLanguages','writable','defaultText','code'), + 'number' =>array('withIcon','allLanguages','writable','decPoint','decimals','thousandSep'), + 'link' =>array('subtype','withIcon','allLanguages','writable','linktype','folderObjectId','defaultObjectId'), + 'date' =>array('withIcon','allLanguages','writable','dateformat','defaultText'), + 'list' =>array('subtype','withIcon','allLanguages','writable','folderObjectId','defaultObjectId'), + 'insert' =>array('subtype','withIcon','allLanguages','writable','folderObjectId','defaultObjectId'), + 'copy' =>array('prefix','name','defaultText'), + 'linkinfo'=>array('prefix','subtype','defaultText'), + 'linkdate'=>array('prefix','subtype','dateformat'), + 'code' =>array('code'), + 'dynamic' =>array('subtype','code'), + 'info' =>array('subtype'), + 'infodate'=>array('subtype','dateformat') ); + return $prp[ $this->type ]; + } + + + + function getDefaultValue() + { + switch( $this->type ) + { + case 'text': + case 'longtext': + return $this->defaultText; + + case 'number'; + return '0'; + + default: + } + + return lang('EL_TYPE_'.$this->type); + + } + + /** + * Ermitteln aller benutzbaren Elementtypen + * @return Array + */ + function getAvailableTypes() + { + return array('text', + 'longtext', + 'select', + 'number', + 'link', + 'date', + 'insert', + 'copy', + 'linkinfo', + 'linkdate', + 'code', + 'dynamic', + 'info', + 'infodate'); + } + + + /** + * Ermittelt die Klasse des Element-Typs.<br> + * Entweder "info", "text" oder "dynamic". + * + * @return String + */ + function getTypeClass() + { + switch( $this->type ) + { + case 'text': + case 'longtext': + case 'select': + case 'number': + case 'link': + case 'date': + case 'list': + case 'insert': + return 'text'; + + case 'code': + case 'dynamic': + return 'dynamic'; + + case 'copy': + case 'info': + case 'infodate': + case 'linkinfo': + case 'linkdate': + return 'info'; + } + } + + + function getSelectItems() + { + $parameters = explode( "\n",$this->code ); + $items = array(); + + foreach( $parameters as $it ) + { + $paar = explode( ":",$it,2 ); + $param_name = trim($paar[0]); + + if ( count($paar) > 1 ) + $param_value = trim($paar[1]); + else + $param_value = trim($paar[0]); + + // Wenn Inhalt mit "'" beginnt und mit "'" aufhoert, dann diese Zeichen abschneiden + if ( substr($param_value,0,1) == "'" && substr($param_value,strlen($param_value)-1,1) == "'" ) + $param_value = substr($param_value,1,strlen($param_value)-2); + + $items[$param_name] = $param_value; + } + return $items; + } + + + function getDynamicParameters() + { + $parameters = explode( "\n",$this->code ); + $items = array(); + + foreach( $parameters as $it ) + { + $paar = explode( ":",$it,2 ); + if ( count($paar) > 1 ) + { + $param_name = trim($paar[0]); + $param_value = trim($paar[1]); + +// // Wenn Inhalt mit "'" beginnt und mit "'" aufhoert, dann diese Zeichen abschneiden +// if ( substr($param_value,0,1) == "'" && substr($param_value,strlen($param_value)-1,1) == "'" ) +// $param_value = substr($param_value,1,strlen($param_value)-2); + + if ( !empty($param_value) ) + $items[$param_name] = $param_value; + } + } + return $items; + } + + + /** + * Ermittelt, ob das Element beschreibbar ist. + * Bestimmte Typen (z.B. Info-Felder) sind nie beschreibbar, dann wird immer false zur?ckgegeben. + * Ansonsten wird ermittelt, ob dieses Element als beschreibbar markiert ist. + */ + function isWritable() + { + // Bei bestimmten Feldern immer false zurueckgeben + if ( in_array($this->type,$this->readonlyElementNames) ) + return false; + + return $this->writable; + } +} + +?>+ \ No newline at end of file diff --git a/model/File.class.php b/model/File.class.php @@ -0,0 +1,711 @@ +<?php +// OpenRat Content Management System +// Copyright (C) 2002-2009 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. + + +// Standard Mime-Type +define('OR_FILE_DEFAULT_MIMETYPE','application/octet-stream'); + + +/** + * Datei. + * + * @author Jan Dankert + * @package openrat.objects + */ +class File extends Object +{ + var $fileid; + + var $size = 0; + var $value = ''; + var $extension = ''; + var $log_filenames = array(); + var $fullFilename = ''; + var $publish = null; + var $mime_type = ''; + + /** + * Breite eines Bildes. Ist nur verfuegbar, wenn vorher + * #getImageSize() aufgerufen wurde. + */ + var $width = null; + + /** + * Hoehe eines Bildes. Ist nur verfuegbar, wenn vorher + * #getImageSize() aufgerufen wurde. + */ + var $height = null; + + var $tmpfile; + + var $content_negotiation = false; + + + + /** + * Um Probleme mit BLOB-Feldern und Datenbank-Besonderheiten zu vermeiden, + * kann der Binaerinhalt BASE64-kodiert gespeichert werden. + * @type Boolean + */ + var $storeValueAsBase64 = false; + + + + /** + * Konstruktor + * + * @param Objekt-Id + */ + function File( $objectid='' ) + { + global $conf,$SESS; + + $db = Session::getDatabase(); + $this->storeValueAsBase64 = $db->conf['base64']; + + $this->Object( $objectid ); + $this->isFile = true; + } + + + + /** + * Ermitteln des Dateinamens dieser Datei + * + * @return String Kompletter Dateiname, z.B. '/pfad/datei.jpeg' + */ + function full_filename() + { + if ( !empty($this->fullFilename) ) + return $this->fullFilename; + + $filename = parent::full_filename(); + + if ( $this->content_negotiation && config('publish','negotiation','file_negotiate_type' ) ) + { + // Link auf Datei: Extension bleibt aufgrund Content-Negotiation leer + } + else + { + if ( !empty($this->extension) ) + $filename .= '.'.$this->extension; + } + + $this->fullFilename = $filename; + return $filename; + } + + + + /** + * Ermitteln des Dateinamens dieser Datei (ohne Pfadangabe) + * + * @return String Kompletter Dateiname, z.B. '/pfad/datei.jpeg' + */ + function filenameWithExtension() + { + if ( $this->extension != '' ) + return $this->filename.'.'.$this->extension; + else return $this->filename; + } + + + + /** + * Ermitteln aller Eigenschaften + * + * @return Array + */ + function getProperties() + { + return array_merge( parent::getProperties(), + array('full_filename'=>$this->fullFilename, + 'extension' =>$this->extension, + 'size' =>$this->size, + 'mimetype' =>$this->mimetype() ) ); + } + + + + /** + * @deprecated + */ + function getFileObjectIdsByExtension( $extension ) + { + global $SESS; + $db = db_connection(); + + $sqlquery = 'SELECT * FROM {t_object} '; + + if ( $extension != '' ) + { + $sqlquery .= " WHERE extension='"; + + $ext = explode(',',$extension); + $sqlquery .= implode( "' OR extension='",$ext ); + $sqlquery .= "' AND is_file=1 AND projectid={projectid}"; + } + else + { + $sqlquery .= " WHERE is_file=1 AND projectid={projectid}"; + } + + $sql = new Sql( $sqlquery ); + $sql->setInt( 'projectid',$SESS['projectid'] ); + + return $db->getCol( $sql ); + } + + + + /** + * Es werden Objekte zu einer Dateierweiterung ermittelt + * + * @param String Dateierweiterung ohne fuehrenden Punkt (z.B. 'jpeg') + * @return Array Liste der gefundenen Objekt-IDs + */ + function getObjectIdsByExtension( $extension ) + { + $db = db_connection(); + + $sql = new Sql( 'SELECT {t_file}.objectid FROM {t_file} '. + ' LEFT JOIN {t_object} '. + ' ON {t_object}.id={t_file}.objectid'. + ' WHERE {t_file}.extension={extension}'. + ' AND {t_object}.projectid={projectid}' ); + $sql->setInt ( 'projectid',$this->projectid ); + $sql->setString( 'extension',$extension ); + + return $db->getCol( $sql ); + } + + + + /** + * Ermittelt den Mime-Type zu dieser Datei + * + * @return String Mime-Type + */ + function mimeType() + { + if ( !empty( $this->mime_type ) ) + return $this->mime_type; + + global $conf; + $mime_types = $conf['mime-types']; + + + + $ext = strtolower( $this->getRealExtension() ); + + if ( !empty($mime_types[$ext]) ) + $this->mime_type = $mime_types[$ext]; + else + // Wenn kein Mime-Type gefunden, dann Standartwert setzen + $this->mime_type = OR_FILE_DEFAULT_MIMETYPE; + + return( $this->mime_type ); + } + + + + /** + * Ermittelt Breite und H�he des Bildes.<br> + * Die Werte lassen sich anschlie�end �ber die Eigenschaften "width" und "height" ermitteln. + */ + function getImageSize() + { + if ( is_null($this->width) ) + { + $this->write(); // Datei schreiben + + // Bildinformationen ermitteln + $size = getimagesize( $this->tmpfile() ); + + // Breite und Hoehe des aktuellen Bildes + $this->width = $size[0]; + $this->height = $size[1]; + } + } + + + + /** + * Veraendert die Bildgroesse eines Bildes + * + * Diese Methode sollte natuerlich nur bei Bildern ausgefuehrt werden. + * + * @param Neue Breite + * @param Neue Hoehe + * @param Bildgr��enfaktor + * @param Altes Format als Integer-Konstante IMG_xxx + * @param Neues Format als Integer-Konstante IMG_xxx + * @param Jpeg-Qualitaet (sofern neues Format = Jpeg) + */ + function imageResize( $newWidth,$newHeight,$factor,$oldformat,$newformat,$jpegquality ) + { + global $conf; + + $this->write(); // Datei schreiben + + // Bildinformationen ermitteln + $size = getimagesize( $this->tmpfile() ); + + // Breite und Hoehe des aktuellen Bildes + $oldWidth = $size[0]; + $oldHeight = $size[1]; + $aspectRatio = $oldHeight / $oldWidth; // Seitenverhaeltnis + + // Wenn Breite und Hoehe fehlen, dann Bildgroesse beibehalten + if ( $newWidth == 0 && $newHeight == 0) + { + if ( $factor != 0 && $factor != 1 ) + { + $newWidth = $oldWidth * $factor; + $newHeight = $oldHeight * $factor; + $resizing = true; + } + else + { + $newWidth = $oldWidth; + $newHeight = $oldHeight; + $resizing = false; + } + } + else + { + $resizing = true; + } + + // Wenn nur Breite oder Hoehe angegeben ist, dann + // das Seitenverhaeltnis beibehalten + if ( $newWidth == 0 ) + $newWidth = $newHeight / $aspectRatio; + + if ( $newHeight == 0 ) + $newHeight = $newWidth * $aspectRatio; + + + switch( $oldformat ) + { + case IMG_GIF: // GIF + + $oldImage = ImageCreateFromGIF( $this->tmpfile ); + break; + + case IMG_JPG: // JPEG + + $oldImage = ImageCreateFromJPEG($this->tmpfile); + break; + + case IMG_PNG: // PNG + + $oldImage = imagecreatefrompng($this->tmpfile); + break; + + default: + die('unsupported image format "'.$this->extension.'", cannot load image. resize failed'); + } + + // Ab Version 2 der GD-Bibliothek sind TrueColor-Umwandlungen moeglich. + global $conf; + $hasTrueColor = $conf['image']['truecolor']; + + switch( $newformat ) + { + case IMG_GIF: // GIF + + if ( $resizing ) + { + $newImage = ImageCreate($newWidth,$newHeight); + ImageCopyResized($newImage,$oldImage,0,0,0,0,$newWidth, + $newHeight,$oldWidth,$oldHeight); + } + else + { + $newImage = &$oldImage; + } + + ImageGIF($newImage, $this->tmpfile() ); + $this->extension = 'gif'; + + break; + + case IMG_JPG: // JPEG + + if ( !$resizing ) + { + $newImage = &$oldImage; + } + elseif ( $hasTrueColor ) + { + // Verwende TrueColor (GD2) + $newImage = imageCreateTrueColor( $newWidth,$newHeight ); + ImageCopyResampled($newImage,$oldImage,0,0,0,0,$newWidth, + $newHeight,$oldWidth,$oldHeight); + } + else + { + // GD Version 1.x unterstuetzt kein TrueColor + $newImage = ImageCreate($newWidth,$newHeight); + + ImageCopyResized($newImage,$oldImage,0,0,0,0,$newWidth, + $newHeight,$oldWidth,$oldHeight); + } + + ImageJPEG($newImage, $this->tmpfile,$jpegquality ); + $this->extension = 'jpeg'; + + break; + + case IMG_PNG: // PNG + + if ( !$resizing ) + { + $newImage = &$oldImage; + } + elseif ( $hasTrueColor ) + { + // Verwende TrueColor (GD2) + $newImage = imageCreateTrueColor( $newWidth,$newHeight ); + + ImageCopyResampled($newImage,$oldImage,0,0,0,0,$newWidth, + $newHeight,$oldWidth,$oldHeight); + } + else + { + // GD Version 1.x unterstuetzt kein TrueColor + $newImage = ImageCreate($newWidth,$newHeight); + + ImageCopyResized($newImage,$oldImage,0,0,0,0,$newWidth, + $newHeight,$oldWidth,$oldHeight); + } + + imagepng( $newImage,$this->tmpfile() ); + $this->extension = 'png'; + + break; + + default: + die('unsupported image format "'.$newformat.'", cannot resize'); + } + + $f = fopen( $this->tmpfile(), "r" ); + $this->value = fread( $f,filesize($this->tmpfile()) ); + fclose( $f ); + + imagedestroy( $oldImage ); + //imagedestroy( $newImage ); + } + + + /** + * Lesen der Datei aus der Datenbank. + * + * Es werden nur die Meta-Daten (Erweiterung, Gr��e) gelesen. Zum Lesen des + * Datei-Inhaltes muss #loadValue() aufgerufen werden. + */ + function load() + { + $db = db_connection(); + + $sql = new Sql( 'SELECT id,extension,size'. + ' FROM {t_file}'. + ' WHERE objectid={objectid}' ); + $sql->setInt( 'objectid',$this->objectid ); + $row = $db->getRow( $sql ); + + if ( count($row)!=0 ) + { + $this->fileid = $row['id' ]; + $this->extension = $row['extension']; + $this->size = $row['size' ]; + } + + $this->objectLoad(); + } + + + + /** + * Unwiderrufliches L�schen der Datei aus der Datenbank. + */ + function delete() + { + $db = db_connection(); + + // Datei l?schen + $sql = new Sql( 'DELETE FROM {t_file} '. + ' WHERE objectid={objectid}' ); + $sql->setInt( 'objectid',$this->objectid ); + $db->query( $sql ); + + $this->objectDelete(); + } + + + + /** + * Stellt anhand der Dateiendung fest, ob es sich bei dieser Datei um ein Bild handelt + */ + function isImage() + { + return substr($this->mimeType(),0,6)=='image/'; + } + + + + /** + * Ermittelt die Datei-Endung. + * + * @return String Datei-Endung + */ + function extension() + { + if ($this->extension != '') + return $this->extension; + + $this->load(); + return $this->extension; + } + + + /** + * Einen Dateinamen in Dateiname und Extension aufteilen. + * @param filename Dateiname + */ + function parse_filename($filename) + { + $filename = basename($filename); + + $p = strrpos($filename, '.'); + if ($p !== false) + { + $this->extension = substr($filename, $p +1); + $this->filename = substr($filename, 0, $p); + } + else + { + $this->extension = ''; + $this->filename = $filename; + } + } + + + /** + * Speichert die Datei-Informationen in der Datenbank. + */ + function save() + { + global $SESS; + $db = db_connection(); + + $sql = new Sql( <<<EOF +UPDATE {t_file} SET + size = {size}, + extension = {extension} + WHERE objectid={objectid} +EOF +); + $sql->setString('size' ,$this->size ); + $sql->setString('extension',$this->extension ); + $sql->setString('objectid' ,$this->objectid ); + $db->query( $sql ); + + $this->objectSave(); + } + + + /** + * Kopieren des Inhaltes von einer anderen Datei + * @param ID der Datei, von der der Inhalt kopiert werden soll + */ + function copyValueFromFile( $otherfileid ) + { + $of = new File( $otherfileid ); + $this->value = $of->loadValue(); + $this->saveValue(); + } + + + /** + * Lesen des Inhaltes der Datei aus der Datenbank. + * + * @return String Inhalt der Datei + */ + function loadValue() + { + if ( is_file($this->tmpfile())) + return implode('',file($this->tmpfile())); // From cache + + Logger::debug("preview 1"); + + $db = db_connection(); + + $sql = new Sql( 'SELECT size,value'. + ' FROM {t_file}'. + ' WHERE objectid={objectid}' ); + $sql->setInt( 'objectid',$this->objectid ); + $row = $db->getRow( $sql ); + + if ( count($row) != 0 ) + { + $this->value = $row['value']; + $this->size = $row['size' ]; + } + + if ( $this->storeValueAsBase64 ) + $this->value = base64_decode( $this->value ); + + // Store in cache. + $f = fopen( $this->tmpfile(),'w' ); + fwrite( $f,$this->value ); + fclose( $f ); + Logger::debug("preview 2:".$this->objectid.'/'.strlen($this->value)); + + return $this->value; + } + + + /** + * Speichert den Inhalt in der Datenbank. + */ + function saveValue( $value = '' ) + { + if ( is_file($this->tmpfile()) ) + @unlink( $this->tmpfile() ); + + $db = db_connection(); + + $sql = new Sql( 'UPDATE {t_file}'. + ' SET value={value}, '. + ' size={size} '. + ' WHERE objectid={objectid}' ); + $sql->setString( 'objectid' ,$this->objectid ); + $sql->setInt ( 'size' ,strlen($this->value) ); + + if ( $this->storeValueAsBase64 ) + $sql->setString( 'value',base64_encode($this->value) ); + else + $sql->setString( 'value',$this->value ); + + $db->query( $sql ); + } + + + /** + * Lesen der Datei aus der Datenbank und schreiben in temporaere Datei + */ + function write() + { + if ( !is_file($this->tmpfile()) ) + $this->loadValue(); + } + + + /** + * F�gt die Datei der Datenbank hinzu. + */ + function add() + { + $db = db_connection(); + + $this->objectAdd(); + + $sql = new Sql('SELECT MAX(id) FROM {t_file}'); + $this->fileid = intval($db->getOne($sql))+1; + + $sql = new Sql('INSERT INTO {t_file}'. + ' (id,objectid,extension,size,value)'. + " VALUES( {fileid},{objectid},{extension},0,'' )" ); + $sql->setInt ('fileid' ,$this->fileid ); + $sql->setInt ('objectid' ,$this->objectid ); + $sql->setString('extension',$this->extension ); + + $db->query( $sql ); + + $this->saveValue(); + } + + + function publish() + { + if ( ! is_object($this->publish) ) + $this->publish = new Publish(); + + $this->write(); + $this->publish->copy( $this->tmpfile(),$this->full_filename(),$this->lastchangeDate ); + + $this->publish->publishedObjects[] = $this->getProperties(); + } + + + /** + * Ermittelt einen tempor�ren Dateinamen f�r diese Datei. + */ + function tmpfile() + { + if ( $this->tmpfile == '' ) + { + $db = db_connection(); + $this->tmpfile = $this->getTempDir().'/openrat_db'.$db->id.'_'.$this->objectid.'.tmp'; + } + return $this->tmpfile; + } + + + /** + * Setzt den Zeitstempel der Datei auf die aktuelle Zeit. + * + * @see objectClasses/Object#setTimestamp() + */ + + function setTimestamp() + { + @unlink( $this->tmpfile() ); + + parent::setTimestamp(); + } + + + + /** + * Ermittelt die wirksame Datei-Endung. Diese kann sich + * in der Extra-Dateiendung, aber auch direkt im Dateiname + * befinden. + * + * @return Dateiendung + */ + function getRealExtension() + { + if ( !empty($this->extension)) + { + return $this->extension; + } + else + { + $pos = strrpos($this->filename,'.'); + if ( $pos === false ) + return ''; + else + return substr($this->filename,$pos+1); + } + } +} + +?>+ \ No newline at end of file diff --git a/model/Folder.class.php b/model/Folder.class.php @@ -0,0 +1,826 @@ +<?php +// OpenRat Content Management System +// Copyright (C) 2002-2010 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. + + +/** + * Darstellen eines Ordners + * + * @version $Revision$ + * @author $Author$ + * @package openrat.objects + */ +class Folder extends Object +{ + var $folderid; + var $projectid; + var $parentfolders = array(); + var $subfolders = array(); + var $filenames = true; + var $name = ''; + var $filename = ''; + var $desc = ''; + var $publish = null; + + + function Folder( $objectid='' ) + { + $this->Object( $objectid ); + $this->isFolder = true; + } + + + function add() + { + $this->objectAdd(); + + $db = db_connection(); + + $sql = new Sql('SELECT MAX(id) FROM {t_folder}'); + $this->folderid = intval($db->getOne($sql))+1; + + $sql = new Sql('INSERT INTO {t_folder}'. + ' (id,objectid)'. + ' VALUES( {folderid},{objectid} )' ); + $sql->setInt ('folderid' ,$this->folderid ); + $sql->setInt ('objectid' ,$this->objectid ); + + $db->query( $sql ); + } + + + + function getRootFolderId() + { + global $SESS; + $db = db_connection(); + + $sql = new SQL('SELECT id FROM {t_object}'. + ' WHERE parentid IS NULL'. + ' AND is_folder=1'. + ' AND projectid={projectid}' ); + + // Wenn Methode statisch aufgerufen wird, ist $this nicht vorhanden + if ( isset($this) && isset($this->projectid) ) + { + $sql->setInt('projectid',$this->projectid ); + } + else + { + $project = Session::getProject(); + $sql->setInt('projectid',$project->projectid ); + } + + // Datenbankabfrage ausfuehren + return $db->getOne( $sql ); + } + + + function hasFilename( $filename ) + { + $db = db_connection(); + + $sql = new Sql('SELECT COUNT(*) FROM {t_object}'.' WHERE parentid={objectid} AND filename={filename}'); + + if ( intval($this->objectid)== 0 ) + $sql->setNull('objectid'); + else + $sql->setString('objectid', $this->objectid); + + $sql->setString('filename', $filename ); + + return( $db->getOne($sql) > 0 ); + } + + + function load() + { +// $db = db_connection(); +// +// $sql = new Sql('SELECT * FROM {t_folder} WHERE objectid={objectid}'); +// $sql->setInt('objectid',$this->objectid); +// +// $row = $db->getRow( $sql ); +// + $this->objectLoad(); + +// $this->folderid = $row['id' ]; + } + + + + function save() + { + $this->objectSave(); + } + + + + function setOrderId( $orderid ) + { + $db = db_connection(); + + $sql = new Sql('UPDATE {t_folder} '. + ' SET orderid={orderid}'. + ' WHERE id={folderid}'); + $sql->setInt('folderid',$this->folderid); + $sql->setInt('orderid' ,$orderid ); + + $db->query( $sql ); + } + + + +// function getSubFolders() +// { +// global $SESS; +// $db = db_connection(); +// +// $sql = new Sql('SELECT id FROM {t_folder}'. +// ' WHERE parentid={folderid}'. +// ' AND projectid={projectid}'. +// ' ORDER BY orderid ASC' ); +// $sql->setInt('folderid' ,$SESS['folderid' ]); +// $sql->setInt('projectid',$SESS['projectid']); +// +// return( $db->getCol( $sql )); +// } + + + // Liest alle Objekte in diesem Ordner + function getObjectIds() + { + $db = db_connection(); + + $sql = new Sql('SELECT id FROM {t_object}'. + ' WHERE parentid={objectid}'. + ' ORDER BY orderid ASC' ); + $sql->setInt('objectid' ,$this->objectid ); + + return( $db->getCol( $sql ) ); + } + + + + /** + * Liest alle Objekte in diesem Ordner + * @return Array von Objekten + */ + function getObjects() + { + $db = db_connection(); + + $sql = new Sql('SELECT {t_object}.*,{t_name}.name,{t_name}.descr'. + ' FROM {t_object}'. + ' LEFT JOIN {t_name} '. + ' ON {t_object}.id={t_name}.objectid AND {t_name}.languageid={languageid} '. + ' WHERE parentid={objectid}'. + ' ORDER BY orderid ASC' ); + $sql->setInt('languageid',$this->languageid ); + $sql->setInt('objectid' ,$this->objectid ); + + $liste = array(); + $res = $db->getAll( $sql ); + foreach( $res as $row ) + { + $o = new Object( $row['id'] ); + $o->setDatabaseRow( $row ); + $liste[] = $o; + } + + return $liste; + } + + + // Liest alle Objekte in diesem Ordner + function getObjectIdsByType() + { + $db = db_connection(); + + $sql = new Sql('SELECT id FROM {t_object}'. + ' WHERE parentid={objectid}'. + ' ORDER BY is_link,is_page,is_file,is_folder,orderid ASC' ); + $sql->setInt('projectid',$this->projectid ); + $sql->setInt('objectid' ,$this->objectid ); + + return( $db->getCol( $sql ) ); + } + + + // Liest alle Objekte in diesem Ordner sortiert nach dem Namen (nicht Dateinamen!) + function getObjectIdsByName() + { + $db = db_connection(); + + $sql = new Sql('SELECT {t_object}.id FROM {t_object}'. + ' LEFT JOIN {t_name} ON {t_object}.id={t_name}.objectid AND {t_name}.languageid={languageid} '. + ' WHERE parentid={objectid}'. + ' ORDER BY {t_name}.name,{t_object}.filename ASC'); + $sql->setInt('objectid' , $this->objectid ); + $sql->setInt('languageid', $this->languageid); + return( $db->getCol( $sql ) ); + } + + + // Liest alle Objekte in diesem Ordner + function getObjectIdsByLastChange() + { + $db = db_connection(); + + $sql = new Sql('SELECT id FROM {t_object}'. + ' WHERE parentid={objectid}'. + ' ORDER BY lastchange_date,orderid ASC' ); + $sql->setInt('projectid',$this->projectid ); + $sql->setInt('objectid' ,$this->objectid ); + + return( $db->getCol( $sql ) ); + } + + + function publish( $withPages,$withFiles,$subdirs = false ) + { + if ( ! is_object($this->publish) ) + $this->publish = new Publish(); + + foreach( $this->getObjectIds() as $oid ) + { + $o = new Object( $oid ); + $o->objectLoadRaw(); + + if ( $o->isPage && $withPages ) + { + $p = new Page( $oid ); + $p->load(); + $p->publish = &$this->publish; + $p->publish(); + } + + if ( $o->isFile && $withFiles ) + { + $f = new File( $oid ); + $f->load(); + $f->publish = &$this->publish; + $f->publish(); + } + + if ( $o->isFolder && $subdirs ) + { + $f = new Folder( $oid ); + $f->load(); + $f->publish = &$this->publish; + $f->publish( $withPages,$withFiles,true ); + } + } + } + + + function getObjectIdByFileName( $filename ) + { + $db = db_connection(); + + $sql = new Sql('SELECT id FROM {t_object}'. + ' WHERE parentid={objectid}'. + ' AND filename={filename}' ); + $sql->setInt ('objectid' ,$this->objectid ); + $sql->setString('filename' ,$filename ); + + return( intval($db->getOne( $sql )) ); + } + + + + /** + * Ermittelt alle Objekte vom gewnschten Typ, die sic in + * diesem Projekt befinden. + * + * @see objectClasses/Object#getAllObjectIds() + * @param types Array + * @return Liste von Object-Ids + */ + function getAllObjectIds( $types=array('folder','page','link','file') ) + { +// Html::debug($types,'Typen'); + global $SESS; + $db = db_connection(); + + $sql = new Sql('SELECT id FROM {t_object}'. + ' WHERE projectid={projectid}'. + ' AND ( is_folder={is_folder}' . + ' OR is_file ={is_file}' . + ' OR is_page ={is_page}' . + ' OR is_link ={is_link} )' . + ' ORDER BY orderid ASC' ); + + if (isset($this->projectid)) + { + $projectid = $this->projectid; + } + else + { + $project = Session::getProject(); + $projectid = $project->projectid; + } + + $sql->setInt('projectid',$projectid); + $sql->setInt('is_folder',in_array('folder',$types)?1:2); + $sql->setInt('is_file' ,in_array('file' ,$types)?1:2); + $sql->setInt('is_page' ,in_array('page' ,$types)?1:2); + $sql->setInt('is_link' ,in_array('link' ,$types)?1:2); + + return( $db->getCol( $sql ) ); + } + + + function dgetRootObjectId() + { + global $SESS; + $db = db_connection(); + + $sql = new Sql('SELECT id FROM {t_object}'. + ' WHERE parentid IS NULL'. + ' AND projectid={projectid}' ); + + if ( isset($this->projectid) ) + $sql->setInt('projectid',$this->projectid ); + else $sql->setInt('projectid',$SESS['projectid'] ); + + return( $db->getOne( $sql ) ); + } + + + function getOtherFolders() + { + global $SESS; + $db = db_connection(); + + $sql = new Sql('SELECT id FROM {t_object}'. + ' WHERE is_folder=1'. + ' and id != {objectid} '. + ' AND projectid={projectid}' ); + $sql->setInt( 'projectid',$this->projectid ); + $sql->setInt( 'objectid' ,$this->objectid ); + + return( $db->getCol( $sql ) ); + } + + + function getAllFolders() + { + global $SESS; + $db = db_connection(); + + $sql = new Sql('SELECT id FROM {t_object}'. + ' WHERE is_folder=1'. + ' AND projectid={projectid}' ); + + if ( !isset($this->projectid) ) + { + $project = Session::getProject(); + $sql->setInt('projectid',$project->projectid); + } + else $sql->setInt( 'projectid',$this->projectid ); + + return( $db->getCol( $sql ) ); + } + + + function getPages() + { + $db = db_connection(); + + $sql = new Sql('SELECT id FROM {t_object} '. + ' WHERE parentid={objectid} AND is_page=1'. + ' ORDER BY orderid ASC' ); + $sql->setInt( 'objectid' ,$this->objectid ); + + return $db->getCol( $sql ); + } + + + /** + * Ermittelt die erste Seite oder Verkn�pfung in diesem Ordner. + * + * @return Object Objekt + */ + function getFirstPageOrLink() + { + $db = db_connection(); + + $sql = new Sql('SELECT id FROM {t_object} '. + ' WHERE parentid={objectid}'. + ' AND (is_page=1 OR is_link=1)'. + ' ORDER BY orderid ASC' ); + $sql->setInt( 'objectid' ,$this->objectid ); + + $oid = intval($db->getOne( $sql )); + + if ( $oid != 0 ) + $o = new Object($oid); + else + $o = null; + + return $o; + } + + + function getLastPageOrLink() + { + $db = db_connection(); + + $sql = new Sql('SELECT id FROM {t_object} '. + ' WHERE parentid={objectid}'. + ' AND (is_page=1 OR is_link=1)'. + ' ORDER BY orderid DESC' ); + $sql->setInt( 'objectid' ,$this->objectid ); + + $oid = intval($db->getOne( $sql )); + + if ( $oid != 0 ) + $o = new Object($oid); + else + $o = null; + + return $o; + } + + + function getFiles() + { + $db = db_connection(); + + $sql = new Sql('SELECT id FROM {t_object} '. + ' WHERE parentid={objectid} AND is_file=1'. + ' ORDER BY orderid ASC' ); + $sql->setInt( 'objectid' ,$this->objectid ); + + return $db->getCol( $sql ); + } + + + + /** + * Liefert eine Liste von allen Dateien in diesem Ordner. + * + * @return Array Schl�ssel=Objekt-Id, Wert=Dateiname + */ + function getFileFilenames() + { + $db = db_connection(); + + $sql = new Sql('SELECT id,filename FROM {t_object} '. + ' WHERE parentid={objectid} AND is_file=1'. + ' ORDER BY orderid ASC' ); + $sql->setInt( 'objectid' ,$this->objectid ); + + return $db->getAssoc( $sql ); + } + + + function getLinks() + { + $db = db_connection(); + + $sql = new Sql('SELECT id FROM {t_object} '. + ' WHERE parentid={objectid} AND is_link=1'. + ' ORDER BY orderid ASC' ); + $sql->setInt( 'objectid' ,$this->objectid ); + + return $db->getCol( $sql ); + } + + + // Rechte f?r diesen Ordner hinzuf?gen + function addrights( $rights,$inherit = true ) + { + global $SESS; + + $SESS['rights'][$rights['projectid']][$this->folderid]['show'] = true; + + if ($rights['read'] == '1') + $SESS['rights'][$rights['projectid']][$this->folderid]['read'] = 1; + if ($rights['write'] == '1') + $SESS['rights'][$rights['projectid']][$this->folderid]['write'] = 1; + if ($rights['create'] == '1') + $SESS['rights'][$rights['projectid']][$this->folderid]['create'] = 1; + if ($rights['delete'] == '1') + $SESS['rights'][$rights['projectid']][$this->folderid]['delete'] = 1; + if ($rights['publish'] == '1') + $SESS['rights'][$rights['projectid']][$this->folderid]['publish'] = 1; + + // Rechte auf Unterordner vererben + // sowie f?r ?bergeordnete Ordner die Anzeige erzwingen + if ( $inherit ) + { + // ?bergeordnete Ordner ermitteln + $parentfolder = $this->parentObjectFileNames(); + + // ?bergeordnete Ordner immer anzeigen (Schalter 'show'=true) + foreach( $parentfolder as $folderid=>$name ) + { + $f = new Folder( $folderid ); + $f->projectid = $this->projectid; + $f->addrights( array('projectid'=>$rights['projectid']),false ); + unset($f); + } + + $f = new Folder( 'null' ); + $f->projectid = $this->projectid; + $f->addrights( array('projectid'=>$rights['projectid']),false ); + unset($f); + + + // Unterordner ermitteln + //echo "Kurz vor subfolderberechnung, folderid ist ".$this->folderid.'<br>'; + $subfolder = $this->subfolder(); + + // Rechte weitergeben + foreach( $subfolder as $folderid=>$name ) + { + $f = new Folder( $folderid ); + $f->projectid = $this->projectid; + $f->addrights( $rights,false ); + unset($f); + } + } + } + + + function addParentFolder( $id,$name,$filename='' ) + { + if ( empty($name) ) + $name = $filename; + + if ( empty($name) ) + $name = "($id)"; + + if ( intval($id) != 0 ) + $this->parentfolders[ $id ] = $name; + } + + + function checkParentFolders( $with_root, $with_self ) + { + // Reihenfolge umdrehen + $this->parentfolders = array_reverse($this->parentfolders,true); + + // Ordner ist bereits hoechster Ordner +// if ( count($this->parentfolders) == 2 && $this->isRoot && $with_root && $with_self ) +// { +// array_pop ( $this->parentfolders ); +// return; +// } + + + if ( !$with_root ) + { + $keys = array_keys( $this->parentfolders ); + unset( $this->parentfolders[$keys[0]] ); + } + + if ( !$with_self ) + { + $keys = array_keys( $this->parentfolders ); + unset( $this->parentfolders[$keys[count($keys)-1]] ); + } + } + + + function parentObjectFileNames( $with_root = false, $with_self = false ) + { + $db = Session::getDatabase(); + + $foid = $this->id; + $idCache = array(); + + while( intval($foid)!=0 ) + { + $sql = new Sql( <<<SQL + +SELECT parentid,id,filename + FROM {t_object} + WHERE {t_object}.id={parentid} + +SQL + ); + $sql->setInt('parentid' ,$foid ); + + $row = $db->getRow( $sql ); + + if ( in_array($row['id'],$idCache)) + Http::serverError('fatal: parent-rekursion in object-id: '.$this->objectid.', double-parent-id: '.$row['id']); + else + $idCache[] = $row['id']; + + $this->addParentfolder( $row['id'],$row['filename'] ); + $foid = $row['parentid']; + } + + + $this->checkParentFolders($with_root,$with_self); + + return $this->parentfolders; + } + + function parentObjectNames( $with_root = false, $with_self = false ) + { + $db = Session::getDatabase(); + + $foid = $this->id; + $idCache = array(); + + while( intval($foid)!=0 ) + { + $sql = new Sql( <<<SQL + +SELECT {t_object}.parentid,{t_object}.id,{t_object}.filename,{t_name}.name FROM {t_object} + LEFT JOIN {t_name} + ON {t_object}.id = {t_name}.objectid + AND {t_name}.languageid = {languageid} + WHERE {t_object}.id={parentid} + +SQL + ); + $sql->setInt('languageid',$this->languageid); + $sql->setInt('parentid' ,$foid ); + + $row = $db->getRow( $sql ); + + if ( in_array($row['id'],$idCache)) + Http::serverError('fatal: parent-rekursion in object-id: '.$this->objectid.', double-parent-id: '.$row['id']); + else + $idCache[] = $row['id']; + + $this->addParentfolder( $row['id'],$row['name'],$row['filename'] ); + $foid = $row['parentid']; + } + + $this->checkParentFolders($with_root,$with_self); + + return $this->parentfolders; + } + + + // Ermitteln aller Unterordner + // + function subfolder() + { + $db = db_connection(); + + $sql = new Sql('SELECT id FROM {t_object} '. + ' WHERE parentid={objectid} AND is_folder=1'. + ' ORDER BY orderid ASC' ); + $sql->setInt( 'objectid' ,$this->objectid ); + + $this->subfolders = $db->getCol( $sql ); + + return $this->subfolders; + } + + + + function getSubfolderFilenames() + { + $db = db_connection(); + + $sql = new Sql('SELECT id,filename FROM {t_object} '. + ' WHERE parentid={objectid} AND is_folder=1'. + ' ORDER BY orderid ASC' ); + $sql->setInt( 'objectid' ,$this->objectid ); + + return $db->getAssoc( $sql ); + } + + + // Ermitteln aller Unterordner (rekursives Absteigen) + // + function getAllSubFolderIds() + { + global $SESS; + + $ids = array(); + + foreach( $this->getSubFolderIds() as $id ) + { +// echo "durchlaufe $id"; + $ids[] = $id; + + $f = new Folder( $id ); + if ( !empty($this->projectid) ) + $f->projectid = $this->projectid; + + foreach( $f->getAllSubFolderIds() as $xid ) + { + $ids[] = $xid; + } + } + +// print_r( $ids ); + return $ids; + } + + + /** + * Loeschen dieses Ordners. + * Der Ordner wird nur geloescht, wenn er keine Unterelemente mehr enth?lt. + * Zum Loeschen inklusive Unterelemente dient die Methode deleteAll() + */ + function delete() + { + $db = db_connection(); + + // Nur loeschen, wenn es keine Unterelemente gibt + if ( count( $this->getObjectIds() ) == 0 ) + { + $sql = new Sql( 'UPDATE {t_element} '. + ' SET folderobjectid=NULL '. + ' WHERE folderobjectid={objectid}' ); + $sql->setInt('objectid',$this->objectid); + $db->query( $sql ); + + $sql = new Sql( 'DELETE FROM {t_folder} '. + ' WHERE objectid={objectid}' ); + $sql->setInt('objectid',$this->objectid); + $db->query( $sql ); + + $this->objectDelete(); + } + } + + + /** + * Rekursives loeschen aller Inhalte + * + * Loeschen aller Inhalte dieses Ordners + * inclusive aller Unterelemente + */ + function deleteAll() + { + $db = db_connection(); + + // L?schen aller Unterordner + foreach( $this->subfolder() as $folderid ) + { + $folder = new Folder( $folderid ); + { + $folder->deleteAll(); + } + } + + // L?schen aller Seiten,Verknuepfungen und Dateien in + // diesem Ordner + foreach( $this->getObjectIds() as $oid ) + { + $object = new Object( $oid ); + { + $object->load(); + + if ( $object->isPage ) + { + $page = new Page( $oid ); + $page->load(); + $page->delete(); + } + + if ( $object->isLink ) + { + $link = new Link( $oid ); + $link->load(); + $link->delete(); + } + + if ( $object->isFile ) + { + $file = new File( $oid ); + $file->load(); + $file->delete(); + } + } + } + + // Zum Abschluss den aktuellen Ordner loeschen + $this->delete(); + } + + + function getSubFolderIds() + { + return $this->subfolder(); + } +} + + +?>+ \ No newline at end of file diff --git a/model/Group.class.php b/model/Group.class.php @@ -0,0 +1,354 @@ +<?php +// OpenRat Content Management System +// Copyright (C) 2002-2010 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. + + + +/** + * Darstellen einer Benutzergruppe. Eine Gruppe enthaelt beliebig viele Benutzer + * + * @version $Revision$ + * @author $Author$ + * @package openrat.objects + */ +class Group +{ + var $groupid = 0; + var $error = ''; + + var $name = ''; + var $fullname = ''; + var $ldap_dn; + var $tel; + var $mail; + var $desc; + var $style; + var $isAdmin; + + + // Konstruktor + function Group( $groupid='' ) + { + if ( is_numeric($groupid) ) + $this->groupid = $groupid; + } + + + // Lesen aller Gruppen aus der Datenbank + function getAll() + { + global $conf; + $db = db_connection(); + + $sql = new Sql( 'SELECT id,name FROM {t_group}' ); + + return $db->getAssoc( $sql ); + } + + + // Lesen Benutzer aus der Datenbank + function load() + { + $db = db_connection(); + + $sql = new Sql( 'SELECT * FROM {t_group}'. + ' WHERE id={groupid}' ); + $sql->setInt( 'groupid',$this->groupid ); + + $row = $db->getRow( $sql ); + if ( count($row) > 0 ) + $this->name = $row['name' ]; + else + $this->name = ''; + } + + + // Speichern Benutzer in der Datenbank + function save() + { + if ( empty($this->name) ) + $this->name = lang('GLOBAL_GROUP').' '.$this->groupid; + + $db = db_connection(); + + // Gruppe speichern + $sql = new Sql( 'UPDATE {t_group} '. + 'SET name = {name} '. + 'WHERE id={groupid}' ); + $sql->setString( 'name' ,$this->name ); + $sql->setInt ('groupid',$this->groupid ); + + // Datenbankabfrage ausfuehren + $db->query( $sql ); + } + + + /** + * Rueckgabe aller Eigenschaften + * @return Array + */ + function getProperties() + { + return Array( 'name' =>$this->name, + 'groupid'=>$this->groupid ); + } + + + // Gruppe hinzufuegen + function add( $name = '' ) + { + $db = db_connection(); + + if ( $name != '' ) + $this->name = $name; + + $sql = new Sql('SELECT MAX(id) FROM {t_group}'); + $this->groupid = intval($db->getOne($sql))+1; + + // Gruppe hinzuf?gen + $sql = new Sql( 'INSERT INTO {t_group} '. + '(id,name) VALUES( {groupid},{name} )'); + $sql->setInt ('groupid',$this->groupid ); + $sql->setString('name' ,$this->name ); + + // Datenbankbefehl ausfuehren + $db->query( $sql ); + } + + + // Gruppe entfernen + function delete() + { + $db = db_connection(); + + // Berechtigungen zu dieser Gruppe loeschen + $sql = new Sql( 'DELETE FROM {t_acl} '. + 'WHERE groupid={groupid}' ); + $sql->setInt ('groupid',$this->groupid ); + $db->query( $sql ); + + + // Alle Gruppenzugehoerigkeiten zu dieser Gruppe loeschen + $sql = new Sql( 'DELETE FROM {t_usergroup} '. + 'WHERE groupid={groupid}' ); + $sql->setInt ('groupid',$this->groupid ); + $db->query($sql); + + // Gruppe loeschen + $sql = new Sql( 'DELETE FROM {t_group} '. + 'WHERE id={groupid}' ); + $sql->setInt ('groupid',$this->groupid ); + $db->query($sql); + } + + + // Benutzer ermitteln, die Mitglied dieser Gruppe sind + function getUsers() + { + $db = db_connection(); + + $sql = new Sql( 'SELECT {t_user}.id,{t_user}.name FROM {t_user} '. + 'LEFT JOIN {t_usergroup} ON {t_usergroup}.userid={t_user}.id '. + 'WHERE {t_usergroup}.groupid={groupid}' ); + $sql->setInt('groupid',$this->groupid ); + + return $db->getAssoc( $sql ); + } + + + // Benutzer ermitteln, die *nicht* Mitglied dieser Gruppe sind + function getOtherUsers() + { + $db = db_connection(); + + $sql = new Sql( 'SELECT {t_user}.id,{t_user}.name FROM {t_user}'. + ' LEFT JOIN {t_usergroup} ON {t_usergroup}.userid={t_user}.id AND {t_usergroup}.groupid={groupid}'. + ' WHERE {t_usergroup}.groupid IS NULL' ); + $sql->setInt('groupid' ,$this->groupid ); + + return $db->getAssoc( $sql ); + } + + + // Benutzer einer Gruppe hinzufuegen + function addUser( $userid ) + { + $db = db_connection(); + + $sql = new Sql('SELECT MAX(id) FROM {t_usergroup}'); + $usergroupid = intval($db->getOne($sql))+1; + + $sql = new Sql( 'INSERT INTO {t_usergroup} '. + ' (id,userid,groupid) '. + ' VALUES( {usergroupid},{userid},{groupid} )' ); + $sql->setInt('usergroupid',$usergroupid ); + $sql->setInt('userid' ,$userid ); + $sql->setInt('groupid' ,$this->groupid ); + + $db->query( $sql ); + + } + + + // Benutzer aus Gruppe entfernen + function delUser( $userid ) + { + $db = db_connection(); + + $sql = new Sql( 'DELETE FROM {t_usergroup} '. + ' WHERE userid={userid} AND groupid={groupid}' ); + $sql->setInt ('userid' ,$userid ); + $sql->setInt ('groupid' ,$this->groupid ); + + $db->query( $sql ); + } + + + // Alle Berechtigungen ermitteln + function getRights() + { + global $SESS,$conf_php; + $db = db_connection(); + $var = array(); + + // Alle Projekte lesen + $sql = new Sql( 'SELECT id,name FROM {t_project}' ); + $projects = $db->getAssoc( $sql ); + + foreach( $projects as $projectid=>$projectname ) + { + $var[$projectid] = array(); + $var[$projectid]['name'] = $projectname; + $var[$projectid]['folders'] = array(); + $var[$projectid]['rights'] = array(); + + $sql = new Sql( 'SELECT {t_acl}.* FROM {t_acl}'. + ' LEFT JOIN {t_folder} ON {t_acl}.folderid = {t_folder}.id'. + ' WHERE {t_folder}.projectid={projectid}'. + ' AND {t_acl}.groupid={groupid}' ); + $sql->setInt('projectid',$projectid ); + $sql->setInt('groupid' ,$this->groupid ); + + $acls = $db->getAll( $sql ); + + foreach( $acls as $acl ) + { + $aclid = $acl['id']; + $folder = new Folder( $acl['folderid'] ); + $folder->load(); + $var[$projectid]['rights'][$aclid] = $acl; + $var[$projectid]['rights'][$aclid]['foldername'] = implode(' &raquo; ',$folder->parentfolder( false,true )); + $var[$projectid]['rights'][$aclid]['delete_url'] = 'user.'.$conf_php.'?useraction=delright&aclid='.$aclid; + } + + $sql = new Sql( 'SELECT id FROM {t_folder}'. + ' WHERE projectid={projectid}' ); + $sql->setInt('projectid',$projectid); + $folders = $db->getCol( $sql ); + + $var[$projectid]['folders'] = array(); + + foreach( $folders as $folderid ) + { + $folder = new Folder( $folderid ); + $folder->load(); + $var[$projectid]['folders'][$folderid] = implode(' &raquo; ',$folder->parentfolder( false,true )); + } + + asort( $var[$projectid]['folders'] ); + } + + return $var; + } + + + // Berechtigung der Gruppe hinzufuegen + function addRight( $data ) + { + global $REQ,$SESS; + $db = db_connection(); + + $sql = new SQL('INSERT INTO {t_acl} '. + '(userid,groupid,folderid,`read`,`write`,`create`,`delete`,publish) '. + 'VALUES({userid},{groupid},{folderid},{read},{write},{create},{delete},{publish})'); + + $sql->setNull('userid'); + $sql->setInt ('groupid',$this->groupid); + $sql->setInt ('projectid',$SESS['projectid']); + $sql->setInt ('folderid',$data['folderid']); + + $sql->setInt ('read' ,$data['read' ]); + $sql->setInt ('write' ,$data['write' ]); + $sql->setInt ('create' ,$data['create' ]); + $sql->setInt ('delete' ,$data['delete' ]); + $sql->setInt ('publish',$data['publish']); + + // Datenbankabfrage ausf?hren + $db->query( $sql ); + } + + + + /** + * Ermitteln aller Berechtigungen dieser Gruppe.<br> + * Diese Daten werden auf der Gruppenseite in der Administration angezeigt. + * + * @return unknown + */ + function getAllAcls() + { + $db = db_connection(); + $sql = new Sql( 'SELECT {t_acl}.*,{t_object}.projectid,{t_language}.name AS languagename FROM {t_acl}'. + ' LEFT JOIN {t_object} '. + ' ON {t_object}.id={t_acl}.objectid '. + ' LEFT JOIN {t_language} '. + ' ON {t_language}.id={t_acl}.languageid '. + ' WHERE ( {t_acl}.groupid={groupid} OR ({t_acl}.userid IS NULL AND {t_acl}.groupid IS NULL) )'. + ' ORDER BY {t_object}.projectid,{t_acl}.languageid' ); + $sql->setInt ( 'groupid' ,$this->groupid ); + + $aclList = array(); + + foreach( $db->getAll( $sql ) as $row ) + { + $acl = new Acl(); + $acl->setDatabaseRow( $row ); + $acl->projectid = $row['projectid' ]; + if ( intval($acl->languageid) == 0 ) + $acl->languagename = lang('GLOBAL_ALL_LANGUAGES'); + else + $acl->languagename = $row['languagename']; + $aclList[] = $acl; + } + + return $aclList; + } + + + + // Berechtigung entfernen + function delRight( $aclid ) + { + $sql = new SQL('DELETE FROM {t_acl} WHERE id={aclid}'); + $sql->setInt( 'aclid',$aclid ); + + // Datenbankabfrage ausf?hren + $db->query( $sql ); + } +} + +?>+ \ No newline at end of file diff --git a/model/Language.class.php b/model/Language.class.php @@ -0,0 +1,286 @@ +<?php +// OpenRat Content Management System +// Copyright (C) 2002-2010 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. + + +/** + * Darstellen einer Sprache. Jeder Seiteninhalt wird einer Sprache zugeordnet. + * + * @version $Revision$ + * @author $Author$ + * @package openrat.objects + */ +class Language +{ + var $languageid = 0; + var $error = ''; + var $projectid; + + var $name = ''; + var $isoCode = ''; + var $isDefault = false; + + + // Konstruktor + function Language( $languageid='' ) + { + global $SESS; + + if ( is_numeric($languageid) ) + $this->languageid = $languageid; + +// $this->projectid = $SESS['projectid']; + } + + + + /** + * Stellt fest, ob die angegebene Id existiert. + */ + function available( $id ) + { + $db = db_connection(); + + $sql = new Sql('SELECT 1 FROM {t_language} '. + ' WHERE id={id}'); + $sql->setInt('id' ,$id ); + + return intval($db->getOne($sql)) == 1; + } + + + + // Lesen aller Sprachen aus der Datenbank + function getAll() + { + global $SESS; + $db = db_connection(); + + $sql = new Sql( "SELECT id,name FROM {t_language} ". + " WHERE projectid = {projectid} ". + " ORDER BY name" ); + + if ( !empty($this->projectid) ) + $sql->setInt('projectid',$this->projectid ); + else + { + $project = Session::getProject(); + $sql->setInt('projectid',$project->projectid); + } + + return $db->getAssoc( $sql ); + } + + + /** + * Ermittelt die Anzahl aller Sprachen zum aktuellen Projekt. + */ + function count() + { + global $SESS; + $db = db_connection(); + + $sql = new Sql( <<<SQL + SELECT count(*) FROM {t_language} + WHERE projectid = {projectid} +SQL +); + + if ( !empty($this->projectid) ) + $sql->setInt('projectid',$this->projectid ); + else + { + $project = Session::getProject(); + $sql->setInt('projectid',$project->projectid); + } + + return $db->getOne( $sql ); + } + + + // Lesen aus der Datenbank + function load() + { + $db = Session::getDatabase(); + + $sql = new Sql( 'SELECT * FROM {t_language}'. + ' WHERE id={languageid}' ); + $sql->setInt( 'languageid',$this->languageid ); + + $row = $db->getRow( $sql ); + + if ( count($row) > 0 ) + { + $this->name = $row['name' ]; + $this->isoCode = $row['isocode' ]; + $this->projectid = intval( $row['projectid'] ); + + $this->isDefault = ( $row['is_default'] == '1' ); + } + } + + + // Speichern der Sprache in der Datenbank + function save() + { + $db = db_connection(); + + // Gruppe speichern + $sql = new Sql( 'UPDATE {t_language} '. + 'SET name = {name}, '. + ' isocode = {isocode} '. + 'WHERE id={languageid}' ); + $sql->setString( 'name' ,$this->name ); + $sql->setString( 'isocode' ,$this->isoCode ); + + $sql->setInt( 'languageid',$this->languageid ); + + // Datenbankabfrage ausfuehren + $db->query( $sql ); + } + + + /** + * Ermitteln aller Eigenschaften dieser Sprache + * @return Array + */ + function getProperties() + { + return Array( 'name' =>$this->name, + 'isocode'=>$this->isoCode ); + } + + + /** + * Neue Sprache hinzuf?gen + */ + function add( $isocode='' ) + { + global $SESS; + global $iso; + $db = db_connection(); + + if ( $isocode != '' ) + { + // Kleiner Trick, damit "no" (Norwegen) in der .ini-Datei stehen kann + $isocode = str_replace('_','',$isocode); + + $this->isocode = $isocode; + $codes = GlobalFunctions::getIsoCodes(); + $this->name = $codes[ $isocode ]; + } + + $sql = new Sql('SELECT MAX(id) FROM {t_language}'); + $this->languageid = intval($db->getOne($sql))+1; + + // Sprache hinzuf?gen + $sql = new Sql( 'INSERT INTO {t_language} '. + '(id,projectid,name,isocode,is_default) VALUES( {languageid},{projectid},{name},{isocode},0 )'); + $sql->setInt ('languageid',$this->languageid ); + $sql->setInt ('projectid' ,$this->projectid ); + $sql->setString('name' ,$this->name ); + $sql->setString('isocode' ,$this->isoCode ); + + // Datenbankbefehl ausfuehren + $db->query( $sql ); + } + + + // Diese Sprache als 'default' markieren. + function setDefault() + { + global $SESS; + $db = db_connection(); + + // Zuerst alle auf nicht-Standard setzen + $sql = new Sql( 'UPDATE {t_language} '. + ' SET is_default = 0 '. + ' WHERE projectid={projectid}' ); + $sql->setInt('projectid',$this->projectid ); + $db->query( $sql ); + + // Jetzt die gew?nschte Sprachvariante auf Standard setzen + $sql = new Sql( 'UPDATE {t_language} '. + ' SET is_default = 1 '. + ' WHERE id={languageid}' ); + $sql->setInt('languageid',$this->languageid ); + $db->query( $sql ); + } + + + function getDefaultId() + { + global $SESS; + $db = db_connection(); + + $sql = new Sql( 'SELECT id FROM {t_language} '. + ' WHERE projectid={projectid}'. + ' ORDER BY is_default DESC' ); + + if ( isset($this->projectid) ) + $sql->setInt('projectid',$this->projectid ); + else + { + $project = Session::getProject(); + $sql->setInt('projectid',$project->projectid); + } + + return $db->getOne( $sql ); + } + + + // Sprache entfernen + function delete() + { + $db = db_connection(); + + // Sprache l?schen +// $sql = new Sql( 'SELECT COUNT(*) FROM {t_language} WHERE projectid={projectid}' ); +// $sql->setInt( 'projectid',$this->projectid ); +// $count = $db->getOne( $sql ); +// +// // Nur l?schen, wenn es mindestens 2 Sprachen gibt +// if ( $count >= 2 ) +// { + // Inhalte mit dieser Sprache l?schen + $sql = new Sql( 'DELETE FROM {t_value} WHERE languageid={languageid}' ); + $sql->setInt( 'languageid',$this->languageid ); + $db->query( $sql ); + + // Inhalte mit dieser Sprache l?schen + $sql = new Sql( 'DELETE FROM {t_name} WHERE languageid={languageid}' ); + $sql->setInt( 'languageid',$this->languageid ); + $db->query( $sql ); + + // Sprache l?schen + $sql = new Sql( 'DELETE FROM {t_language} WHERE id={languageid}' ); + $sql->setInt( 'languageid',$this->languageid ); + $db->query( $sql ); + + // Andere Sprache auf "Default" setzen + $sql = new Sql( 'SELECT id FROM {t_language} WHERE projectid={projectid}' ); + $sql->setInt( 'projectid',$this->projectid ); + $new_default_languageid = $db->getOne( $sql ); + + $sql = new Sql( 'UPDATE {t_language} SET is_default=1 WHERE id={languageid}' ); + $sql->setInt( 'languageid',$new_default_languageid ); + $db->query( $sql ); +// } + } +} + +?>+ \ No newline at end of file diff --git a/model/Link.class.php b/model/Link.class.php @@ -0,0 +1,171 @@ +<?php +// OpenRat Content Management System +// Copyright (C) 2002-2004 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. + + + +/** + * Darstellen einer Verkn�pfung. Eine Verkn�pfung kann auf eine Objekt oder auf + * eine beliebige Url zeigen + * + * @version $Revision$ + * @author $Author$ + * @package openrat.objects + */ +class Link extends Object +{ + var $linkid; + var $linkedObjectId = 0; + var $url = ''; + var $isLinkToUrl = false; + var $isLinkToObject = false; + + function Link( $objectid='' ) + { + $this->Object( $objectid ); + $this->isLink = true; + $this->isLinkToObject = false; + } + + + // Lesen der Verkn�pfung aus der Datenbank + function load() + { + $db = db_connection(); + + $sql = new Sql( 'SELECT *'. + ' FROM {t_link}'. + ' WHERE objectid={objectid}' ); + $sql->setInt( 'objectid',$this->objectid ); + $row = $db->getRow( $sql ); + + if ( count($row ) != 0 ) + { + $this->url = $row['url']; + $this->linkedObjectId = $row['link_objectid']; + + if ( is_numeric( $this->linkedObjectId ) ) + { + $this->isLinkToUrl = false; + $this->isLinkToObject = true; + } + else + { + $this->isLinkToUrl = true; + $this->isLinkToObject = false; + } + } + + $this->objectLoad(); + } + + + + function delete() + { + $db = db_connection(); + + // Verkn�pfung l�schen + $sql = new Sql( 'DELETE FROM {t_link} '. + ' WHERE objectid={objectid}' ); + $sql->setInt( 'objectid',$this->objectid ); + + $db->query( $sql ); + + $this->objectDelete(); + } + + + + function save() + { + global $SESS; + $db = db_connection(); + + $sql = new Sql('UPDATE {t_link} SET '. + ' url = {url},'. + ' link_objectid = {linkobjectid}'. + ' WHERE objectid={objectid}' ); + $sql->setInt ('objectid' ,$this->objectid ); + + if ( $this->isLinkToObject ) + { + $sql->setInt ('linkobjectid',$this->linkedObjectId ); + $sql->setNull('url' ); + } + else + { + $sql->setNull ('linkobjectid'); + $sql->setString('url',$this->url ); + } + + $db->query( $sql ); + + $this->objectSave(); + } + + + function getProperties() + { + return array_merge( parent::getProperties(), + Array( 'objectid' =>$this->objectid, + 'linkobjectid' =>$this->linkedObjectId, + 'url' =>$this->url, + 'isLinkToUrl' =>$this->isLinkToUrl, + 'isLinkToObject' =>$this->isLinkToObject) ); + } + + + function getType() + { + if ( $this->isLinkToObject ) + return 'link'; + else return 'url'; + } + + + function add() + { + $this->objectAdd(); + + $db = db_connection(); + + $sql = new Sql('SELECT MAX(id) FROM {t_link}'); + $this->linkid = intval($db->getOne($sql))+1; + + $sql = new Sql('INSERT INTO {t_link}'. + ' (id,objectid,url,link_objectid)'. + ' VALUES( {linkid},{objectid},{url},{linkobjectid} )' ); + $sql->setInt ('linkid' ,$this->linkid ); + $sql->setInt ('objectid' ,$this->objectid ); + + if ( $this->isLinkToObject ) + { + $sql->setInt ('linkobjectid',$this->linkedObjectId ); + $sql->setNull('url' ); + } + else + { + $sql->setNull ('linkobjectid'); + $sql->setString('url',$this->url ); + } + + $db->query( $sql ); + } +} + +?>+ \ No newline at end of file diff --git a/model/Model.class.php b/model/Model.class.php @@ -0,0 +1,282 @@ +<?php +// OpenRat Content Management System +// Copyright (C) 2002-2010 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. + + + +/** + * Diese Klasse stellt ein Projektmodell dar. Ein Projektmodell ist eine Darstellungsart + * der Inhalte. Zu jedem Projektmodell gibt es einen anderen Templatequelltext. + * Beispiel: Neben HTML gibt es ein Projektmodell fuer WML oder XML. Die Inhalte sind gleich, + * aber die Art der Ausgabe ist jeweils anders. + * + * @package openrat.objects + * @author $Author$ + * @version $Rev: $ + */ +class Model +{ + var $modelid = 0; + var $error = ''; + var $projectid; + + var $name = ''; + var $isDefault = false; + + + /** + * Konstruktor + */ + function Model( $modelid='' ) + { + if ( is_numeric($modelid) ) + $this->modelid = $modelid; + } + + + /** + * Stellt fest, ob die angegebene Id existiert. + */ + function available( $id ) + { + $db = db_connection(); + + $sql = new Sql('SELECT 1 FROM {t_projectmodel} '. + ' WHERE id={id}'); + $sql->setInt('id' ,$id ); + + return intval($db->getOne($sql)) == 1; + } + + + + + /** + * Lesen aller Projektmodelle aus der Datenbank + */ + function getAll() + { + global $SESS; + $db = db_connection(); + + $sql = new Sql( "SELECT id,name FROM {t_projectmodel} ". + " WHERE projectid = {projectid} ". + " ORDER BY name" ); + + if ( !empty($this->projectid) ) + $sql->setInt('projectid',$this->projectid ); + else + { + $project = Session::getProject(); + $sql->setInt('projectid',$project->projectid); + } + + return $db->getAssoc( $sql ); + } + + + + /** + * Bestimmt die Anzahl aller Varianten fuer das aktuelle Projekt. + */ + function count() + { + global $SESS; + $db = db_connection(); + + $sql = new Sql( <<<SQL + SELECT count(*) FROM {t_projectmodel} + WHERE projectid = {projectid} +SQL +); + if ( isset($this) ) + $sql->setInt('projectid',$this->projectid ); + else $sql->setInt('projectid',$SESS['projectid'] ); + + return $db->getOne( $sql ); + } + + + /** + * Lesen aus der Datenbank + */ + function load() + { + $db = db_connection(); + + $sql = new Sql( 'SELECT * FROM {t_projectmodel}'. + ' WHERE id={modelid}' ); + $sql->setInt( 'modelid',$this->modelid ); + + $row = $db->getRow( $sql ); + + $this->name = $row['name' ]; + $this->projectid = $row['projectid']; + + if ( $row['is_default'] == '1' ) + $this->isDefault = true; + else $this->isDefault = false; + } + + + /** + * Speichern des Projektmodells + */ + function save() + { + $db = db_connection(); + + // Gruppe speichern + $sql = new Sql( 'UPDATE {t_projectmodel} '. + ' SET name = {name} '. + ' WHERE id={modelid}' ); + $sql->setString( 'name' ,$this->name ); + + $sql->setInt( 'modelid',$this->modelid ); + + // Datenbankabfrage ausfuehren + $db->query( $sql ); + } + + + /** + * Alle notwendigen Eigenschaften dieses Projektmodells + * werden als Array zurueckgegeben + * + * @return Array + */ + function getProperties() + { + return Array( 'modelid' =>$this->modelid, + 'projectid'=>$this->projectid, + 'isDefault'=>$this->isDefault, + 'name' =>$this->name ); + } + + + /** + * Modell hinzufuegen + * @param String Name des Modells (optional) + */ + function add( $name = '' ) + { + if ( $name != '' ) + $this->name = $name; + + $db = db_connection(); + + $sql = new Sql('SELECT MAX(id) FROM {t_projectmodel}'); + $this->modelid = intval($db->getOne($sql))+1; + + // Modell hinzuf?gen + $sql = new Sql( 'INSERT INTO {t_projectmodel} '. + "(id,projectid,name,extension,is_default) VALUES( {modelid},{projectid},{name},'',0 )"); + + $sql->setInt ('modelid' ,$this->modelid ); + $sql->setInt ('projectid',$this->projectid ); + $sql->setString('name' ,$this->name ); + + // Datenbankbefehl ausfuehren + $db->query( $sql ); + } + + + function getDefaultId() + { + global $SESS; + $db = db_connection(); + + $sql = new Sql( 'SELECT id FROM {t_projectmodel} '. + ' WHERE projectid={projectid}'. + ' ORDER BY is_default DESC' ); + if ( isset($this->projectid) ) + $sql->setInt('projectid',$this->projectid ); + else + { + $project = Session::getProject(); + $sql->setInt('projectid',$project->projectid); + } + + return $db->getOne( $sql ); + } + + + + // Diese Sprache als 'default' markieren. + function setDefault() + { + global $SESS; + $db = db_connection(); + + // Zuerst alle auf nicht-Standard setzen + $sql = new Sql( 'UPDATE {t_projectmodel} '. + ' SET is_default = 0 '. + ' WHERE projectid={projectid}' ); + $sql->setInt('projectid',$this->projectid ); + $db->query( $sql ); + + // Jetzt die gew?nschte Sprachvariante auf Standard setzen + $sql = new Sql( 'UPDATE {t_projectmodel} '. + ' SET is_default = 1 '. + ' WHERE id={modelid}' ); + $sql->setInt('modelid',$this->modelid ); + $db->query( $sql ); + } + + + /** + * Entfernen des Projektmodells aus der Datenbank + * Es wird dabei nicht geprueft, ob noch ein anders Projektmodell + * vorhanden ist. + */ + function delete() + { + $db = db_connection(); + + // Vorlagen zu dieseem Modell loeschen + $sql = new Sql( <<<SQL + DELETE FROM {t_templatemodel} + WHERE projectmodelid = {modelid} +SQL +); + $sql->setInt( 'modelid',$this->modelid ); + $db->query( $sql ); + + // Dieses Modell löschen + $sql = new Sql( <<<SQL + DELETE FROM {t_projectmodel} + WHERE id={modelid} +SQL +); + $sql->setInt( 'modelid',$this->modelid ); + $db->query( $sql ); + + // Anderes Modell auf "Default" setzen (sofern vorhanden) + if ( $this->isDefault ) + { + $sql = new Sql( 'SELECT id FROM {t_projectmodel} WHERE projectid={projectid}' ); + $sql->setInt( 'projectid',$this->projectid ); + $new_default_modelid = $db->getOne( $sql ); + + $sql = new Sql( 'UPDATE {t_projectmodel} SET is_default=1 WHERE id={modelid}' ); + $sql->setInt( 'modelid',$new_default_modelid ); + $db->query( $sql ); + } + } +} + +?>+ \ No newline at end of file diff --git a/model/Object.class.php b/model/Object.class.php @@ -0,0 +1,1389 @@ +<?php +// OpenRat Content Management System +// Copyright (C) 2002-2009 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. + +/** + * Superklasse fuer Objekte im Projektbaum. + * + * Dieses Objekt ist die Oberklasse fuer die 4 Klassen Ordner, Datei, + * Link oder Seite dar. + * + * @author Jan Dankert + * @package openrat.objects + */ +class Object +{ + /** eindeutige ID dieses Objektes + * @see #$objectid + * @type Integer + */ + var $id; + + /** eindeutige ID dieses Objektes + * @type Integer + */ + var $objectid; + + /** Objekt-ID des Ordners, in dem sich dieses Objekt befindet + * Kann "null" oder "0" sein, wenn es sich um den Wurzelordner des Projektes handelt + * @see #$isRoot + * @type Integer + */ + var $parentid; + + /** Physikalischer Dateiname des Objektes (bei Links nicht gef?llt) + * <em>enth?lt nicht die Dateinamen-Erweiterung</em> + * @type String + */ + var $filename = ''; + + /** Logischer (sprachabhaengiger) Name des Objektes + * (wird in Tabelle <code>name</code> abgelegt) + * @type String + */ + var $name = ''; + + /** Logische (sprachabhaengige) Beschreibung des Objektes + * (wird in Tabelle <code>name</code> abgelegt) + * @type String + */ + var $description = 'none'; + var $desc = ''; + + /** Zeitpunkt der Erstellung. Die Variable beinhaltet den Unix-Timestamp. + * @type Integer + */ + var $createDate; + + /** Zeitpunkt der letzten Aenderung. Die Variable beinhaltet den Unix-Timestamp. + * @type Integer + */ + var $lastchangeDate; + + /** Benutzer, welcher dieses Objekt erstellt hat. + * @type Integer + */ + var $createUser; + + /** Benutzer, welcher dieses Objekt zuletzt geaendert hat. + * @type Integer + */ + var $lastchangeUser; + + /** + * Kennzeichen, ob Objekt ein Ordner ist + * @type Boolean + */ + var $isFolder = false; + + /** + * Kennzeichen, ob Objekt eine binaere Datei ist + * @type Boolean + */ + var $isFile = false; + + /** + * Kennzeichen, ob Objekt eine Seite ist + * @type Boolean + */ + var $isPage = false; + + /** + * Kennzeichen, ob Objekt eine Verknuepfung (Link) ist + * @type Boolean + */ + var $isLink = false; + + /** + * Kennzeichnet den Typ dieses Objektes. + * Muss den Inhalt OR_FILE, OR_FOLDER, OR_PAGE oder OR_LINK haben. + * Vorbelegung mit <code>null</code>. + * @type Integer + */ + var $type = null; + + /** Kennzeichen ob Objekt den Wurzelordner des Projektes darstellt (parentid ist dann NULL) + * @type Boolean + */ + var $isRoot = false; + + /** Sprach-ID + * @see Language + * @type Integer + */ + var $languageid; + + /** + * Projektmodell-ID + * @see Projectmodel + * @type Integer + */ + var $modelid; + + /** + * Projekt-ID + * @see Project + * @type Integer + */ + var $projectid; + + /** + * Dateiname der temporaeren Datei + * @type String + */ + var $tmpfile; + + var $aclMask = null; + + /** <strong>Konstruktor</strong> + * F?llen des neuen Objektes mit Init-Werten + * Es werden die Standardwerte aus der Session benutzt, um + * Sprach-ID, Projektmodell-Id und Projekt-ID zu setzen + * + * @param Integer Objekt-ID (optional) + */ + function Object($objectid = '') + { + global $SESS; + + if ( is_numeric($objectid) ) + { + $this->objectid = $objectid; + $this->id = $objectid; + } + + + $language = Session::getProjectLanguage(); + if ( is_object($language) ) + $this->languageid = $language->languageid; + + $model = Session::getProjectModel(); + if ( is_object($model) ) + $this->modelid = $model->modelid; + + $project = Session::getProject(); + if ( is_object($project) ) + $this->projectid = $project->projectid; + } + + + /** + * Lesen aller Objekte aus dem aktuellen Projekt + * @return Array Alle Objekt-IDs des aktuellen Projektes + */ + function getAllObjectIds() + { + global $SESS; + $db = db_connection(); + + if ( ! isset($this->projectid) ) + { + $project = Session::getProject(); + $projectid = $project->projectid; + } + else + { + $projectid = $this->projectid; + } + + $sql = new Sql('SELECT id from {t_object} '. + ' WHERE projectid={projectid}'); + $sql->setInt('projectid', $projectid); + + return $db->getCol($sql); + } + + + // Kompletten Dateinamen des Objektes erzeugen + function full_filename() + { + $path = $this->path(); + + if ($path != '') + $path.= '/'; + + $path.= $this->filename(); + + return $path; + } + + /** + * Pr?fen einer Berechtigung zu diesem Objekt + */ + function checkRight( $type ) + { + return true; + } + + + /** + * Pruefen einer Berechtigung zu diesem Objekt + */ + function hasRight( $type ) + { + if ( is_null($this->aclMask) ) + { + $project = Session::getProject(); + $language = Session::getProjectLanguage(); + $user = Session::getUser(); + + if ( $user->isAdmin ) + { + // Administratoren erhalten eine Maske mit allen Rechten + $this->aclMask = ACL_READ + + ACL_WRITE + + ACL_PROP + + ACL_DELETE + + ACL_RELEASE + + ACL_PUBLISH + + ACL_CREATE_FOLDER + + ACL_CREATE_FILE + + ACL_CREATE_LINK + + ACL_CREATE_PAGE + + ACL_GRANT + + ACL_TRANSMIT; + } + else + { + $this->aclMask = 0; + + $sqlGroupClause = $user->getGroupClause(); + $sql = new Sql( <<<SQL +SELECT {t_acl}.* FROM {t_acl} + LEFT JOIN {t_object} + ON {t_object}.id={t_acl}.objectid + WHERE objectid={objectid} + AND ( languageid={languageid} OR languageid IS NULL ) + AND ( {t_acl}.userid={userid} OR $sqlGroupClause + OR ({t_acl}.userid IS NULL AND {t_acl}.groupid IS NULL) ) +SQL +); + + $sql->setInt ( 'languageid' ,$language->languageid ); + $sql->setInt ( 'objectid' ,$this->objectid ); + $sql->setInt ( 'userid' ,$user->userid ); + + $db = db_connection(); + foreach( $db->getAll( $sql ) as $row ) + { + $acl = new Acl(); + $acl->setDatabaseRow( $row ); + + $this->aclMask |= $acl->getMask(); + } + } + } + + if ( readonly() ) + // System ist im Nur-Lese-Zustand + return $type == ACL_READ && $this->aclMask & $type; + else + // Ermittelte Maske auswerten + return $this->aclMask & $type; + } + + + /** + * Typ des Objektes ermitteln + * + * @return String der Typ des Objektes entweder 'folder','file','page' oder 'link' + */ + function getType() + { + if ($this->isFolder) + return OR_TYPE_FOLDER; + if ($this->isFile) + return OR_TYPE_FILE; + if ($this->isPage) + return OR_TYPE_PAGE; + if ($this->isLink) + return OR_TYPE_LINK; + + return 'unknown'; + } + + + function getProperties() + { + return Array( 'id' =>$this->objectid, + 'objectid' =>$this->objectid, + 'parentid' =>$this->parentid, + 'filename' =>$this->filename, + 'name' =>$this->name, + 'desc' =>$this->desc, + 'description' =>$this->desc, + 'create_date' =>$this->createDate, + 'create_user' =>$this->createUser, + 'lastchange_date' =>$this->lastchangeDate, + 'lastchange_user' =>$this->lastchangeUser, + 'isFolder' =>$this->isFolder, + 'isFile' =>$this->isFile, + 'isLink' =>$this->isLink, + 'isPage' =>$this->isPage, + 'isRoot' =>$this->isRoot, + 'languageid' =>$this->languageid, + 'modelid' =>$this->modelid, + 'projectid' =>$this->projectid, + 'type' =>$this->getType() ); + } + + + /** + * Ermitteln des physikalischen Dateipfades, in dem sich das Objekt befindet + * @return String Pfadangabe, z.B. 'pfad/zu/objekt' + */ + function path() + { + $folder = new Folder($this->parentid); + + return implode('/', $folder->parentObjectFileNames(false, true)); + } + + + + /** + * Ueberpruft einen Dateinamen auf Gueltigkeit. + */ + function goodFilename( $filename ) + { + // Dateiname muss gueltig sein, + // ungueltige Zeichen werden entfernt + $gueltig = 'abcdefghijklmnopqrstuvwxyz0123456789.-_'; + $tmp = strtr($filename, $gueltig, str_repeat('#', strlen($gueltig))); + return( str_replace('-','',strtr($this->filename, $tmp, str_repeat('-', strlen($tmp)))) ); + } + + + + /** + * Ermitteln des Dateinamens und Rueckgabe desselben + * @return String Dateiname + */ + function filename() + { + + global $conf; + + if ( $conf['filename']['edit'] && $this->filename != '' && $this->filename != $this->objectid ) + { + $this->filename = $this->goodFilename(trim(strtolower($this->name))); + return $this->filename; + } + + if ( $this->type == OR_TYPE_FOLDER ) + { + $this->filename = $this->objectid; + } + elseif ( $this->orderid == 1 && + !empty($conf['filename']['default']) && + !$conf['filename']['edit'] ) + { + $this->filename = $conf['filename']['default']; + } + else + { + switch( $conf['filename']['style'] ) + { + case 'longid': + // Eine etwas laengere ID als Dateinamen benutzen + $this->filename = base_convert(str_pad($this->objectid,6,'a'),11,10); + break; + + case 'id': + // Einfach die Objekt-Id als Dateinamen verwenden. + $this->filename = $this->objectid; + break; + + case 'short': + // So kurz wie moeglich: Erhoehen der Basis vom 10 auf 36. + // Beispiele: + // 1 -> 1 + // 10 -> a + $this->filename = base_convert($this->objectid,10,36); + break; + +// case 'md5': +// $this->filename = md5(md5($this->objectid)); +// break; + case 'ss': + // Imitieren von "StoryServer" URLs. Wers braucht. + $this->filename = '0,'. + base_convert(str_pad($this->parentid,3,'a'),11,10). + ','. + base_convert(str_pad($this->objectid,7,'a'),11,10). + ',00'; + break; +// case 'title': +// $this->filename = $this->goodFilename(trim(strtolower($this->name))); +// break; + + default: + die('Unknown filename style: '.$conf['filename']['style'] ); + } + } + + return $this->filename; + } + + + + /** + * Stellt fest, ob das Objekt mit der angegebenen Id existiert. + */ + function available( $objectid ) + { + $db = db_connection(); + + // Vielleicht k�nnen wir uns den DB-Zugriff auch ganz sparen. + if ( !is_numeric($objectid) || $objectid <= 0 ) + return false; // Objekt-Id ung�ltig. + + $sql = new Sql('SELECT 1 FROM {t_object} '. + ' WHERE id={objectid}'); + $sql->setInt('objectid' , $objectid ); + + return intval($db->getOne($sql)) == 1; + } + + + /** + * Lesen der Eigenschaften aus der Datenbank + * Es werden + * - die sprachunabh?ngigen Daten wie Dateiname, Typ sowie Erstellungs- und ?nderungsdatum geladen + * - die sprachabh?ngigen Daten wie Name und Beschreibung geladen + */ + function objectLoad() + { + global $SESS; + $db = db_connection(); + + $sql = new Sql('SELECT {t_object}.*,' . + ' {t_name}.name,{t_name}.descr,'. + ' lastchangeuser.name as lastchange_username, '. + ' lastchangeuser.fullname as lastchange_userfullname, '. + ' lastchangeuser.mail as lastchange_usermail, '. + ' createuser.name as create_username, '. + ' createuser.fullname as create_userfullname, '. + ' createuser.mail as create_usermail '. + ' FROM {t_object}'. + ' LEFT JOIN {t_name} '. + ' ON {t_object}.id={t_name}.objectid AND {t_name}.languageid={languageid} '. + ' LEFT JOIN {t_user} as lastchangeuser '. + ' ON {t_object}.lastchange_userid=lastchangeuser.id '. + ' LEFT JOIN {t_user} as createuser '. + ' ON {t_object}.create_userid=createuser.id '. + ' WHERE {t_object}.id={objectid}'); + $sql->setInt('languageid', $this->languageid); + $sql->setInt('objectid' , $this->objectid ); + + $row = $db->getRow($sql); + + if (count($row) == 0) + { + $project = Session::getProject(); + + $this->name = lang('unknown'); + $this->parentid = $project->getRootObjectId(); + $this->projectid = $project->projectid; + $this->filename = ""; + $this->orderid = 0; + $this->isRoot = false; + $this->createDate = 0; + $this->lastchangeDate = 0; + $this->createUser = new User(); + $this->lastchangeUser = new User(); + } + else + $this->setDatabaseRow( $row ); + + + } + + + /** + * Lesen der Eigenschaften aus der Datenbank + * Es werden + * - die sprachunabhaengigen Daten wie Dateiname, Typ sowie Erstellungs- und Aenderungsdatum geladen + */ + function objectLoadRaw() + { + global $SESS; + $db = db_connection(); + + $sql = new Sql('SELECT * FROM {t_object}'. + ' WHERE {t_object}.id={objectid}'); + $sql->setInt('objectid' , $this->objectid ); + $row = $db->getRow($sql); + + if (count($row) == 0) + die('fatal: Object::objectLoadRaw(): objectid not found: '.$this->objectid.', SQL='.$sql->raw); + + $this->parentid = $row['parentid' ]; + $this->filename = $row['filename' ]; + $this->projectid = $row['projectid']; + + if ( intval($this->parentid) == 0 ) + $this->isRoot = true; + else + $this->isRoot = false; + + $this->name = 'n/a'; + + $this->create_date = $row['create_date']; + $this->create_userid = $row['create_userid']; + $this->lastchange_date = $row['lastchange_date']; + $this->lastchange_userid = $row['lastchange_userid']; + + + $this->isFolder = ( $row['is_folder'] == '1' ); + $this->isFile = ( $row['is_file' ] == '1' ); + $this->isPage = ( $row['is_page' ] == '1' ); + $this->isLink = ( $row['is_link' ] == '1' ); + } + + + /** + * Setzt die Eigenschaften des Objektes mit einer Datenbank-Ergebniszeile + * + * @param row Ergebniszeile aus Datenbanktabelle + */ + function setDatabaseRow( $row ) + { + if ( count($row)==0 ) + die('setDatabaseRow() got empty array, oid='.$this->objectid); + + $this->parentid = $row['parentid' ]; + $this->projectid = $row['projectid']; + $this->filename = $row['filename' ]; + $this->orderid = $row['orderid' ]; + + if ( intval($this->parentid) == 0 ) + $this->isRoot = true; + else $this->isRoot = false; + + $this->createDate = $row['create_date' ]; + $this->lastchangeDate = $row['lastchange_date']; + + $this->createUser = new User(); + $this->createUser->userid = $row['create_userid' ]; + if ( !empty($row['create_username']) ) + { + $this->createUser->name = $row['create_username' ]; + $this->createUser->fullname = $row['create_userfullname' ]; + $this->createUser->mail = $row['create_usermail' ]; + } + + $this->lastchangeUser = new User(); + $this->lastchangeUser->userid = $row['lastchange_userid' ]; + + if ( !empty($row['lastchange_username']) ) + { + $this->lastchangeUser->name = $row['lastchange_username' ]; + $this->lastchangeUser->fullname = $row['lastchange_userfullname']; + $this->lastchangeUser->mail = $row['lastchange_usermail' ]; + } + + $this->isFolder = ( $row['is_folder'] == '1' ); + $this->isFile = ( $row['is_file' ] == '1' ); + $this->isPage = ( $row['is_page' ] == '1' ); + $this->isLink = ( $row['is_link' ] == '1' ); + + if ( $this->isRoot ) + { + $project = Session::getProject(); + $this->name = $project->name; + $this->desc = ''; + $this->description = ''; + } + else + { + $this->name = $row['name' ]; + $this->desc = $row['descr']; + $this->description = $row['descr']; + } + + $this->checkName(); + } + + + + /** + * Laden des Objektes + * @deprecated bitte objectLoad() benutzen + */ + function load() + { + $this->objectLoad(); + } + + /** + * Lesen von logischem Namen und Beschreibung + * Diese Eigenschaften sind sprachabhaengig und stehen deswegen in einer + * separaten Tabelle + * @access private + */ + function objectLoadName() + { + die(); + global $SESS; + $db = db_connection(); + + $sql = new Sql('SELECT *'.' FROM {t_name}'.' WHERE objectid={objectid}'.' AND languageid={languageid}'); + $sql->setInt('objectid' , $this->objectid ); + $sql->setInt('languageid', $this->languageid); + $res = $db->query($sql); + + if ($res->numRows() == 0) + { + // Wenn Name in dieser Sprache nicht vorhanden, dann irgendeinen Namen lesen + $sql->setQuery('SELECT *'.' FROM {t_name}'.' WHERE objectid={objectid}'.' AND name != {blank}'); + $sql->setString('blank', ''); + $res = $db->query($sql); + } + $row = $res->fetchRow(); + + $this->name = $row['name']; + $this->desc = $row['description']; + + // Falls leer, id<objectnr> als Dateinamen verwenden + if ($this->name == '') + $this->name = $this->filename; + } + + /** + * Eigenschaften des Objektes in Datenbank speichern + */ + function objectSave( $withName = true ) + { + global $SESS; + $db = db_connection(); + + $this->checkFilename(); + + $sql = new Sql( <<<SQL +UPDATE {t_object} SET + parentid = {parentid}, + lastchange_date = {time} , + lastchange_userid = {userid} , + filename = {filename} + WHERE id={objectid} +SQL +); + + + if ( $this->isRoot ) + $sql->setNull('parentid'); + else $sql->setInt ('parentid',$this->parentid ); + + + $user = Session::getUser(); + $this->lastchangeUser = $user; + $this->lastchangeDate = now(); + $sql->setInt ('time' ,$this->lastchangeDate ); + $sql->setInt ('userid' ,$this->lastchangeUser->userid ); + $sql->setString('filename', $this->filename); + $sql->setInt ('objectid', $this->objectid); + + + $db->query($sql); + + // Nur wenn nicht Wurzelordner + if ( !$this->isRoot && $withName ) + { + if ( $this->name == '' ) + $this->name = $this->filename; + + $this->objectSaveName(); + } + } + + + + /** + * Aenderungsdatum auf Systemzeit setzen + */ + function setTimestamp() + { + $db = db_connection(); + + $sql = new Sql('UPDATE {t_object} SET '. + ' lastchange_date = {time} ,'. + ' lastchange_userid = {userid} '. + ' WHERE id={objectid}'); + + $user = Session::getUser(); + $this->lastchangeUser = $user; + $this->lastchangeDate = now(); + + $sql->setInt ('userid' ,$this->lastchangeUser->userid ); + $sql->setInt ('objectid',$this->objectid ); + $sql->setInt ('time' ,$this->lastchangeDate ); + + $db->query( $sql ); + + } + + + + /** + * Logischen Namen und Beschreibung des Objektes in Datenbank speichern + * (wird von objectSave() automatisch aufgerufen) + * + * @access private + */ + function ObjectSaveName() + { + global $SESS; + $db = db_connection(); + + $sql = new Sql(<<<SQL +SELECT COUNT(*) FROM {t_name} WHERE objectid ={objectid} AND languageid={languageid} +SQL +); + $sql->setInt( 'objectid' , $this->objectid ); + $sql->setInt( 'languageid', $this->languageid ); + $count = $db->getOne($sql); + + if ($count > 0) + { + $sql = new Sql( <<<SQL + UPDATE {t_name} SET + name = {name}, + descr = {desc} + WHERE objectid ={objectid} + AND languageid={languageid} +SQL +); + $sql->setString('name', $this->name); + $sql->setString('desc', $this->desc); + $sql->setInt( 'objectid' , $this->objectid ); + $sql->setInt( 'languageid', $this->languageid ); + $db->query($sql); + } + else + { + $sql = new Sql('SELECT MAX(id) FROM {t_name}'); + $nameid = intval($db->getOne($sql))+1; + + $sql->setQuery('INSERT INTO {t_name}'.' (id,objectid,languageid,name,descr)'.' VALUES( {nameid},{objectid},{languageid},{name},{desc} )'); + $sql->setInt ('objectid' , $this->objectid ); + $sql->setInt ('languageid', $this->languageid ); + $sql->setInt ('nameid', $nameid ); + $sql->setString('name' , $this->name); + $sql->setString('desc' , $this->desc); + $db->query($sql); + } + } + + /** + * Objekt loeschen. Es muss sichergestellt sein, dass auch das Unterobjekt geloeschet wird. + * Diese Methode wird daher normalerweise nur vom Unterobjekt augerufen + * @access protected + */ + function objectDelete() + { + $db = db_connection(); + + $sql = new Sql( 'UPDATE {t_element} '. + ' SET default_objectid=NULL '. + ' WHERE default_objectid={objectid}' ); + $sql->setInt('objectid',$this->objectid); + $db->query( $sql ); + + $sql = new Sql( 'UPDATE {t_value} '. + ' SET linkobjectid=NULL '. + ' WHERE linkobjectid={objectid}' ); + $sql->setInt('objectid',$this->objectid); + $db->query( $sql ); + + $sql = new Sql( 'UPDATE {t_link} '. + ' SET link_objectid=NULL '. + ' WHERE link_objectid={objectid}' ); + $sql->setInt('objectid',$this->objectid); + $db->query( $sql ); + + + // Objekt-Namen l?schen + $sql = new Sql('DELETE FROM {t_name} WHERE objectid={objectid}'); + $sql->setInt('objectid', $this->objectid); + $db->query($sql); + + // ACLs loeschen + $this->deleteAllACLs(); + + // Objekt l?schen + $sql = new Sql('DELETE FROM {t_object} WHERE id={objectid}'); + $sql->setInt('objectid', $this->objectid); + $db->query($sql); + } + + + /** + * Objekt hinzufuegen + */ + function objectAdd() + { + global $SESS; + $db = db_connection(); + + // Neue Objekt-Id bestimmen + $sql = new Sql('SELECT MAX(id) FROM {t_object}'); + $this->objectid = intval($db->getOne($sql))+1; + + $this->checkFilename(); + $sql = new Sql('INSERT INTO {t_object}'. + ' (id,parentid,projectid,filename,orderid,create_date,create_userid,lastchange_date,lastchange_userid,is_folder,is_file,is_page,is_link)'. + ' VALUES( {objectid},{parentid},{projectid},{filename},{orderid},{time},{userid},{time},{userid},{is_folder},{is_file},{is_page},{is_link} )'); + + if ( $this->isRoot ) + $sql->setNull('parentid'); + else $sql->setInt ('parentid',$this->parentid ); + + $sql->setInt ('objectid' , $this->objectid ); + $sql->setString('filename' , $this->filename ); + $sql->setString('projectid', $this->projectid); + $sql->setInt ('orderid' , 99999 ); + $sql->setInt ('time' , now() ); + $user = Session::getUser(); + $sql->setInt ('userid' , $user->userid ); + + $sql->setBoolean('is_folder',$this->isFolder); + $sql->setBoolean('is_file', $this->isFile); + $sql->setBoolean('is_page', $this->isPage); + $sql->setBoolean('is_link', $this->isLink); + + $db->query($sql); + + if ( !empty($this->name) ) + $this->objectSaveName(); + + // Standard-Rechte fuer dieses neue Objekt setzen. + // Der angemeldete Benutzer erhaelt Lese- und Schreibrechte auf + // das neue Objekt. + $acl = new Acl(); + $acl->userid = $user->userid; + $acl->objectid = $this->objectid; + + $acl->read = true; + $acl->write = true; + $acl->prop = true; + $acl->delete = true; + $acl->grant = true; + if ( $this->isFolder ) + { + $acl->create_file = true; + $acl->create_page = true; + $acl->create_folder = true; + $acl->create_link = true; + } + $acl->add(); + + // Aus dem Eltern-Ordner vererbbare Berechtigungen uebernehmen. + $folder = new Folder( $this->parentid ); + foreach( $folder->getAclIds() as $aclid ) + { + $acl = new Acl( $aclid ); + $acl->load(); + + if ( $acl->transmit ) // ACL is vererbbar, also kopieren. + { + $acl->objectid = $this->objectid; + $acl->add(); // ... und hinzufuegen. + } + } + } + + + /** + * Pruefung auf Gueltigkeit des Dateinamens + */ + function checkFilename() + { + if ( empty($this->filename) ) + $this->filename = $this->objectid; + +// $this->filename = trim(strtolower($this->filename)); + +// $this->filename = $this->goodFilename( $this->filename); + + if ( $this->isRoot ) + return; + + if ( !$this->filenameIsUnique( $this->filename ) ) + { +// $this->filename = $this->objectid; +// +// if ( !$this->filenameIsUnique( $this->filename ) ) + $this->filename = $this->filename.'.'.md5(microtime()); + } + } + + + function filenameIsUnique( $filename ) + { + $db = db_connection(); + + $sql = new Sql( <<<SQL +SELECT COUNT(*) FROM {t_object} + WHERE parentid={parentid} AND filename={filename} + AND NOT id = {objectid} +SQL +); + + $sql->setString('parentid', $this->parentid); + $sql->setString('filename', $filename ); + $sql->setString('objectid', $this->objectid); + + + return( intval($db->getOne($sql)) == 0 ); + } + + + /** + * Pruefung auf Gueltigkeit des logischen Namens + */ + function checkName() + { + if ( empty($this->name) ) + $this->name = $this->filename; + + if ( empty($this->name) ) + $this->name = $this->objectid; + } + + + function getAclIds() + { + $db = db_connection(); + + $sql = new Sql( 'SELECT id FROM {t_acl} '. + ' WHERE objectid={objectid}'. + ' AND ( languageid IS NULL OR '. + ' languageid = {languageid} )'. + ' ORDER BY userid,groupid ASC' ); + $sql->setInt('languageid',$this->languageid); + $sql->setInt('objectid' ,$this->objectid); + + return $db->getCol( $sql ); + } + + + function getAllAclIds() + { + $db = db_connection(); + + $sql = new Sql( 'SELECT id FROM {t_acl} '. + ' WHERE objectid={objectid}'. + ' ORDER BY userid,groupid ASC' ); + $sql->setInt('objectid' ,$this->objectid); + + return $db->getCol( $sql ); + } + + + function getInheritedAclIds() + { + $acls = array(); + + if ( $this->getType() == 'unknown' ) + $this->load(); + + // Root-Ordner erhaelt keine Vererbungen + if ( $this->isRoot ) + return $acls; + + $db = db_connection(); + $folder = new Folder( $this->parentid ); + + foreach( $folder->parentObjectFileNames(true,true) as $oid=>$filename ) + { + $sql = new Sql( 'SELECT id FROM {t_acl} '. + ' WHERE objectid={objectid}'. + ' AND is_transmit = 1'. + ' AND ( languageid IS NULL OR '. + ' languageid = {languageid} )'. + ' ORDER BY userid,groupid ASC' ); + $sql->setInt('objectid' ,$oid); + $sql->setInt('languageid',$this->languageid); + $acls = array_merge( $acls,$db->getCol( $sql ) ); + } + + return $acls; + } + + + function getAllInheritedAclIds() + { + $acls = array(); + + if ( $this->getType() == 'unknown' ) + $this->load(); + + // Root-Ordner erhaelt keine Vererbungen + if ( $this->isRoot ) + return $acls; + + $db = db_connection(); + $folder = new Folder( $this->parentid ); + + foreach( $folder->parentObjectFileNames(true,true) as $oid=>$filename ) + { + $sql = new Sql( 'SELECT id FROM {t_acl} '. + ' WHERE objectid={objectid}'. + ' AND is_transmit = 1'. + ' ORDER BY userid,groupid ASC' ); + $sql->setInt('objectid' ,$oid); + $acls = array_merge( $acls,$db->getCol( $sql ) ); + } + + return $acls; + } + + + /** + * Ermitteln aller Berechtigungsstufen, die fuer diesen Objekttyp wichtig sind + */ + function getRelatedAclTypes() + { + if ( $this->isFolder ) + return( array('read','write','delete','prop','release','publish','create_folder','create_file','create_page','create_link','grant','transmit') ); + if ( $this->isFile ) + return( array('read','write','delete','prop','release','publish','grant') ); + if ( $this->isPage ) + return( array('read','write','delete','prop','release','publish','grant') ); + if ( $this->isLink ) + return( array('read','write','delete','prop','grant') ); + } + + + /** + * Ermitteln aller Berechtigungsstufen, die fuer diesen Objekttyp wichtig sind + */ + function getAssocRelatedAclTypes() + { + $rights = array('read','write','delete','prop','release','publish','create_folder','create_file','create_page','create_link','grant','transmit'); + $types = array(); + foreach( $rights as $r ) + $types[$r] = false; + + foreach( $this->getRelatedAclTypes() as $t ) + $types[$t] = true; + + return $types; + } + + /** + * Entfernen aller ACLs zu diesem Objekt + * @access private + */ + function deleteAllACLs() + { + foreach( $this->getAllAclIds() as $aclid ) + { + $acl = new Acl( $aclid ); + $acl->load(); + $acl->delete(); + } + } + + + /** + * Dateinamen der temporaeren Datei bestimmen + */ + function tmpfileYYYYYY() + { + if ( isset($this->tmpfile) && $this->tmpfile != '' ) + return $this->tmpfile; // Tempor�rer Dateiname bereits vorhanden. + + global $conf; + + // 1. Versuch: Temp-Dir aus Konfiguration. + $tmpdir = @$conf['cache']['tmp_dir']; + if ( $this->tmpfile === FALSE ) + $this->tmpfile = @tempnam( $tmpdir,'openrat_tmp' ); + + // 2. Versuch: Temp-Dir aus "upload_tmp_dir". + if ( $this->tmpfile === FALSE ) + { + Html::debug($this->tmpfile,"nochmal"); + $tmpdir = ini_get('upload_tmp_dir'); + $this->tmpfile = @tempnam( $tmpdir,'openrat_tmp' ); + } + + elseif ( $this->tmpfile === FALSE ) + { + Html::debug($this->tmpfile,"nochmal"); + $this->tmpfile = @tempnam( '','openrat_tmp' ); + } + + Html::debug($this->tmpfile,"tmpfile in objekt"); + Logger::debug( 'creating temporary file: '.$this->tmpfile ); + + return $this->tmpfile; + } + + + /** + * Liefert einen Verzeichnisnamen fuer temporaere Dateien. + */ + function getTempDir() + { + global $conf; + $tmpdir = @$conf['cache']['tmp_dir']; + $tmpfile = @tempnam( $tmpdir,'openrat_tmp' ); + + // 2. Versuch: Temp-Dir aus "upload_tmp_dir". + if ( $tmpfile === FALSE ) + { + $tmpdir = ini_get('upload_tmp_dir'); + $tmpfile = @tempnam( $tmpdir,'openrat_tmp' ); + } + + elseif ( $tmpfile === FALSE ) + { + $tmpfile = @tempnam( '','openrat_tmp' ); + } + + $tmpdir = dirname($tmpfile); + @unlink($tmpfile); + + return $tmpdir; + } + + + + /** + * Liefert einen temporären Dateinamen. + * @param $attr Attribute fuer den Dateinamen, um diesen eindeutig zu gestalten. + * @return unknown_type + */ + function getTempFileName( $attr = array() ) + { + global $conf; + +// if ( $conf['cache']['enable_cache'] ) +// { + $filename = Object::getTempDir().'/openrat'; + foreach( $attr as $a=>$w ) + $filename .= '_'.$a.$w; + + $filename .= '.tmp'; + return $filename; +// } +// else +// { +// $tmpdir = @$conf['cache']['tmp_dir']; +// $tmpfile = tempnam( $tmpdir,'openrat_tmp' ); +// +// return $tmpfile; +// } + } + + + + /** + * Gibt ein fertiges Dateihandle fuer eine temporaere Datei zurück. + * @return Resource + */ + function getTempFile() + { + return tmpfile(); + } + + + + /** + * Reihenfolge-Sequenznr. dieses Objektes neu speichern + * die Nr. wird sofort in der Datenbank gespeichert. + * + * @param Integer neue Sequenz-Nr. + */ + function setOrderId( $orderid ) + { + $db = db_connection(); + + $sql = new Sql('UPDATE {t_object} '.' SET orderid={orderid}'.' WHERE id={objectid}'); + $sql->setInt('objectid', $this->objectid); + $sql->setInt('orderid', $orderid); + + $db->query($sql); + } + + + /** + * ?bergeordnete Objekt-ID dieses Objektes neu speichern + * die Nr. wird sofort in der Datenbank gespeichert. + * + * @param Integer ?bergeordnete Objekt-ID + */ + function setParentId( $parentid ) + { + $db = db_connection(); + + $sql = new Sql('UPDATE {t_object} '.' SET parentid={parentid}'.' WHERE id={objectid}'); + $sql->setInt('objectid', $this->objectid); + $sql->setInt('parentid', $parentid); + + $db->query($sql); + } + + + function getDependentObjectIds() + { + $db = db_connection(); + + $sql = new Sql( 'SELECT {t_page}.objectid FROM {t_value}'. + ' LEFT JOIN {t_page} '. + ' ON {t_value}.pageid = {t_page}.id '. + ' WHERE linkobjectid={objectid}' ); + $sql->setInt( 'objectid',$this->objectid ); + + return $db->getCol( $sql ); + } + + + /** + * Es werden Objekte mit einem bestimmten Namen ermittelt + * @param String Suchbegriff + * @return Array Liste der gefundenen Objekt-IDs + */ + function getObjectIdsByFileName( $text ) + { + $db = db_connection(); + + $sql = new Sql( 'SELECT id FROM {t_object} '. + ' WHERE filename LIKE {filename}'. + ' AND projectid={projectid}'. + ' ORDER BY lastchange_date DESC' ); + $sql->setInt ( 'projectid',$this->projectid ); + $sql->setString( 'filename','%'.$text.'%' ); + + return $db->getCol( $sql ); + } + + + /** + * Es werden Objekte mit einem Namen ermittelt + * @param String Suchbegriff + * @return Array Liste der gefundenen Objekt-IDs + */ + function getObjectIdsByName( $text ) + { + $db = db_connection(); + + $sql = new Sql( 'SELECT {t_object}.id FROM {t_object} '. + ' LEFT JOIN {t_name} '. + ' ON {t_object}.id={t_name}.objectid'. + ' WHERE {t_name}.name LIKE {name}'. + ' AND {t_name}.languageid={languageid}'. + ' AND {t_object}.projectid={projectid}'. + ' ORDER BY lastchange_date DESC' ); + $sql->setInt ( 'projectid' ,$this->projectid ); + $sql->setInt ( 'languageid',$this->languageid ); + $sql->setString( 'name' ,'%'.$text.'%' ); + + return $db->getCol( $sql ); + } + + + /** + * Es werden Objekte mit einer Beschreibung ermittelt + * @param String Suchbegriff + * @return Array Liste der gefundenen Objekt-IDs + */ + function getObjectIdsByDescription( $text ) + { + $db = db_connection(); + + $sql = new Sql( 'SELECT {t_object}.id FROM {t_object} '. + ' LEFT JOIN {t_name} '. + ' ON {t_object}.id={t_name}.objectid'. + ' WHERE {t_name}.descr LIKE {desc}'. + ' AND {t_name}.languageid={languageid}'. + ' AND {t_object}.projectid={projectid}'. + ' ORDER BY lastchange_date DESC' ); + $sql->setInt ( 'projectid' ,$this->projectid ); + $sql->setInt ( 'languageid',$this->languageid ); + $sql->setString( 'desc' ,'%'.$text.'%' ); + + return $db->getCol( $sql ); + } + + + /** + * Es werden Objekte mit einer UserId ermittelt + * @param Integer Benutzer-Id der Erstellung + * @return Array Liste der gefundenen Objekt-IDs + */ + function getObjectIdsByCreateUserId( $userid ) + { + $db = db_connection(); + + $sql = new Sql( 'SELECT id FROM {t_object} '. + ' WHERE create_userid={userid}'. + ' AND projectid={projectid}'. + ' ORDER BY lastchange_date DESC' ); + $sql->setInt ( 'projectid',$this->projectid ); + $sql->setInt ( 'userid' ,$userid ); + + return $db->getCol( $sql ); + } + + + /** + * Es werden Objekte mit einer UserId ermittelt + * @param Integer Benutzer-Id der letzten ?nderung + * @return Array Liste der gefundenen Objekt-IDs + */ + function getObjectIdsByLastChangeUserId( $userid ) + { + $db = db_connection(); + + $sql = new Sql( 'SELECT id FROM {t_object} '. + ' WHERE lastchange_userid={userid}'. + ' AND projectid={projectid}'. + ' ORDER BY lastchange_date DESC' ); + $sql->setInt ( 'projectid',$this->projectid ); + $sql->setInt ( 'userid' ,$userid ); + + return $db->getCol( $sql ); + } + + + /** + * Gibt true zur?ck, wenn die angegebene Objekt-ID existiert + * @param Integer Objekt-ID + * @return Boolean + */ + function isObjectId( $id ) + { + $db = db_connection(); + + $sql = new Sql( 'SELECT id FROM {t_object} '. + ' WHERE id={objectid}'. + ' AND projectid={projectid}' ); + $sql->setInt ( 'projectid' ,$this->projectid ); + $sql->setInt ( 'objectid' ,$id ); + + return ($db->getOne($sql) == intval($id) ); + } + + + +} + +?>+ \ No newline at end of file diff --git a/model/ObjectFactory.php b/model/ObjectFactory.php @@ -0,0 +1,57 @@ +<?php +// --------------------------------------------------------------------------- +// $Id$ +// --------------------------------------------------------------------------- +// DaCMS 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. +// --------------------------------------------------------------------------- + +class ObjectFactory +{ + function create( $objectid ) + { + $o = new Object( $objectid ); + + switch( $o->getType() ) + { + case OR_TYPE_FILE: + $x = new File( $objectid ); + break; + + case OR_TYPE_FOLDER: + $x = new Folder( $objectid ); + break; + + case OR_TYPE_PAGE: + $x = new Page( $objectid ); + break; + + case OR_TYPE_LINK: + $x = new Link( $objectid ); + break; + + default: + die( "Unknown Object-Typ: ".$o->getType() ); + debug_backtrace(); + } + + $x->load(); + return $x; + } +} + +?>+ \ No newline at end of file diff --git a/model/Page.class.php b/model/Page.class.php @@ -0,0 +1,880 @@ +<?php +// DaCMS 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. + + +/** + * Darstellen einer Seite + * + * @author Jan Dankert + * @package openrat.objects + */ + +class Page extends Object +{ + var $pageid; + var $templateid; + var $template; + + var $simple = false; + var $public = false; + + var $el = array(); + + /** + * Stellt fest, ob die Editier-Icons angezeigt werden sollen. Dies ist + * nur der Fall, wenn die Seite auch zum Bearbeiten generiert wird. + * Wird die Seite zum Veröffentlichen generiert, muss diese Eigenschaft + * natürlich "false" sein. + * @var boolean + */ + var $icons = false; + var $src = ''; + var $edit = false; + + var $content_negotiation = false; + var $cut_index = false; + var $default_language = false; + var $withLanguage = false; + var $withModel = false; + var $link = false; + var $fullFilename = ''; + + var $log_filenames = array(); + var $modelid = 0; + + var $publish = null; + var $up_path = ''; + + + function Page( $objectid='' ) + { + $this->Object( $objectid ); + $this->isPage = true; + } + + + /** + * Ermitteln der Objekt-ID (Tabelle object) anhand der Seiten-ID (Tablle page) + * + * @deprecated pageid sollte nicht mehr benutzt werden + * @return Integer objectid + */ + function getObjectIdFromPageId( $pageid ) + { + $db = db_connection(); + + $sql = new Sql( 'SELECT objectid FROM {t_page} '. + ' WHERE id={pageid}' ); + $sql->setInt('pageid',$pageid); + + return $db->getOne( $sql ); + } + + + /** + * Ermitteln der Seiten-ID anhand der Objekt-ID + * + * @deprecated pageid sollte nicht mehr benutzt werden + * @return Integer pageid + */ + function getPageIdFromObjectId( $objectid ) + { + $db = db_connection(); + + $sql = new Sql( 'SELECT id FROM {t_page} '. + ' WHERE objectid={objectid}' ); + $sql->setInt('objectid',$objectid); + + return $db->getOne( $sql ); + } + + + /** + * Ermitteln aller Eigenschaften + * + * @return Array + */ + function getProperties() + { + return array_merge( parent::getProperties(), + array('full_filename'=>$this->realFilename(), + 'pageid' =>$this->pageid, + 'templateid' =>$this->templateid, + 'mime_type' =>$this->mimeType() ) ); + } + + + /** + * Ermitteln der Ordner, in dem sich die Seite befindet + * @return Array + */ + function parentfolder() + { + $folder = new Folder(); + $folder->folderid = $this->folderid; + + return $folder->parentfolder( false,false ); + } + + +/* + function path_to_file( $fileid ) + { + global $conf_php; + + if ( $this->public ) + { + $inhalt = $this->up_path(); + + $file = new File(); + $file->fileid = $fileid; + $file->load(); + + $inhalt .= $file->full_filename(); + } + else + { + $inhalt = "file.$conf_php?fileaction=show&fileid=".$fileid; + $inhalt = sid($inhalt); + } + + return $inhalt; + } +*/ + + /** + * Ermittelt den Pfad zu einem beliebigen Objekt + * + * @param Integer Objekt-ID des Zielobjektes + * @return String Relative Link-angabe, Beispiel: '../../pfad/datei.jpeg' + */ + function path_to_object( $objectid ) + { + global $conf_php, + $SESS; + $inhalt = ''; + + if ( ! Object::available( $objectid) ) + return ''; + + $param = array('oid'=>'__OID__'.$objectid.'__'); + + $object = new Object( $objectid ); + $object->objectLoad(); + + $cut_index = ( is_object($this->publish) && $this->publish->cut_index ); + $content_negotiation = ( is_object($this->publish) && $this->publish->content_negotiation ); + + if ( $this->public ) + { + switch( $object->getType() ) + { + case 'file': + + $inhalt = $this->up_path(); + + $f = new File( $objectid ); + $f->content_negotiation = $content_negotiation; + $f->load(); + $inhalt .= $f->full_filename(); + break; + + case 'page': + + $inhalt = $this->up_path(); + + $p = new Page( $objectid ); + $p->languageid = $this->languageid; + $p->modelid = $this->modelid; + $p->cut_index = $cut_index; + $p->content_negotiation = $content_negotiation; + $p->withLanguage = $this->withLanguage; + $p->withModel = $this->withModel; + $p->load(); + $inhalt .= $p->full_filename(); + break; + + case 'link': + $link = new Link( $objectid ); + $link->load(); + + if ( $link->isLinkToObject ) + { + $linkedObject = new Object( $link->linkedObjectId ); + $linkedObject->load(); + + switch( $linkedObject->getType() ) + { + case 'file': + $f = new File( $link->linkedObjectId ); + $f->load(); + $inhalt = $this->up_path(); + $inhalt .= $f->full_filename(); + break; + + case 'page': + $p = new Page( $link->linkedObjectId ); + $p->languageid = $this->languageid; + $p->modelid = $this->modelid; + $p->cut_index = $cut_index; + $p->content_negotiation = $content_negotiation; + $p->load(); + $inhalt = $this->up_path(); + $inhalt .= $p->full_filename(); + break; + } + } + else + { + $inhalt = $link->url; + } + break; + } + } + else + { + // Interne Verlinkungen in der Seitenvorschau + switch( $object->getType() ) + { + case 'file': + $inhalt = Html::url('file','preview',$objectid,$param); + break; + + case 'page': + $inhalt = Html::url('page','preview',$objectid,$param); + break; + + case 'link': + $link = new Link( $objectid ); + $link->load(); + + if ( $link->isLinkToObject ) + { + $linkedObject = new Object( $link->linkedObjectId ); + $linkedObject->load(); + + switch( $linkedObject->getType() ) + { + case 'file': + $inhalt = Html::url('file','preview',$link->linkedObjectId,$param); + break; + + case 'page': + $inhalt = Html::url('page','preview',$link->linkedObjectId,$param); + break; + } + } + else + { + $inhalt = $link->url; + } + break; + } + } + + return $inhalt; + } + + + + /** + * Erzeugt Pr?fix f?r eine relative Pfadangabe + * Beispiel: Seite liegt in Ordner /pfad/pfad dann '../../' + * + * @return String Pfadangabe + * @access private + */ + function up_path() + { + global $conf; + + if ( $conf['filename']['url'] == 'absolute' ) + { + $this->up_path = '/'; + return $this->up_path; + } + + if ( $this->up_path != '' ) + return $this->up_path; + + $folder = new Folder( $this->parentid ); + $folder->load(); + $f = count( $folder->parentObjectFileNames(false,true) ); + + if ( $f == 0 ) + { + $this->up_path = './'; + } + else + { + $this->up_path = str_repeat( '../',$f ); + } + + return $this->up_path; + } + + + /** + * Eine Seite hinzufuegen + */ + function add() + { + $db = db_connection(); + + $this->objectAdd(); // Hinzuf?gen von Objekt (dabei wird Objekt-ID ermittelt) + + $sql = new Sql('SELECT MAX(id) FROM {t_page}'); + $this->pageid = intval($db->getOne($sql))+1; + + $sql = new Sql('INSERT INTO {t_page}'. + ' (id,objectid,templateid)'. + ' VALUES( {pageid},{objectid},{templateid} )' ); + $sql->setInt ('pageid' ,$this->pageid ); + $sql->setInt ('objectid' ,$this->objectid ); + $sql->setInt ('templateid',$this->templateid ); + + $db->query( $sql ); + } + + + /** + * Seite laden + */ + function load() + { + $db = db_connection(); + + $sql = new Sql( 'SELECT * FROM {t_page} '. + ' WHERE objectid={objectid}' ); + $sql->setInt('objectid',$this->objectid); + $row = $db->getRow( $sql ); + + $this->pageid = $row['id' ]; + $this->templateid = $row['templateid']; + + $this->objectLoad(); + } + + + function delete() + { + global $db; + + $sql = new Sql( 'DELETE FROM {t_value} '. + ' WHERE pageid={pageid}' ); + $sql->setInt('pageid',$this->pageid); + $db->query( $sql ); + + $sql = new Sql( 'DELETE FROM {t_page} '. + ' WHERE objectid={objectid}' ); + $sql->setInt('objectid',$this->objectid); + $db->query( $sql ); + + $this->objectDelete(); + } + + + /** + * Kopieren der Inhalts von einer anderen Seite + * @param ID der Seite, von der der Inhalt kopiert werden soll + */ + function copyValuesFromPage( $otherpageid ) + { + $this->load(); + + foreach( $this->getElementIds() as $elementid ) + { + foreach( Language::getAll() as $lid=>$lname ) + { + $val = new Value(); + $val->publish = false; + $val->element = new Element( $elementid ); + + $val->objectid = $otherpageid; + $val->pageid = Page::getPageIdFromObjectId( $otherpageid ); + $val->languageid = $lid; + $val->load(); + + // Inhalt nur speichern, wenn vorher vorhanden + if ( $val->valueid != 0 ) + { + $val->objectid = $this->objectid; + $val->pageid = Page::getPageIdFromObjectId( $this->objectid ); + $val->save(); + } + } + } + } + + + + + function save() + { + $db = db_connection(); + + $sql = new Sql('UPDATE {t_page}'. + ' SET templateid ={templateid}'. + ' WHERE objectid={objectid}' ); + $sql->setInt('templateid' ,$this->templateid); + $sql->setInt('objectid' ,$this->objectid ); + $db->query( $sql ); + + $this->objectSave(); + } + + + + function replaceTemplate( $newTemplateId,$replaceElementMap ) + { + $oldTemplateId = $this->templateid; + + $db = db_connection(); + + // Template-id dieser Seite aendern + $this->templateid = $newTemplateId; + + $sql = new Sql('UPDATE {t_page}'. + ' SET templateid ={templateid}'. + ' WHERE objectid={objectid}' ); + $sql->setInt('templateid' ,$this->templateid); + $sql->setInt('objectid' ,$this->objectid ); + $db->query( $sql ); + + + // Inhalte umschluesseln, d.h. die Element-Ids aendern + $template = new Template( $oldTemplateId ); + foreach( $template->getElementIds() as $oldElementId ) + { + if ( !isset($replaceElementMap[$oldElementId]) || + intval($replaceElementMap[$oldElementId]) < 1 ) + { + Logger::debug( 'deleting value of elementid '.$oldElementId ); + $sql = new Sql('DELETE FROM {t_value}'. + ' WHERE pageid={pageid}'. + ' AND elementid={elementid}' ); + $sql->setInt('pageid' ,$this->pageid); + $sql->setInt('elementid',$oldElementId ); + + $db->query( $sql ); + } + else + { + $newElementId = intval($replaceElementMap[$oldElementId]); + + Logger::debug( 'updating elementid '.$oldElementId.' -> '.$newElementId ); + $sql = new Sql('UPDATE {t_value}'. + ' SET elementid ={newelementid}'. + ' WHERE pageid ={pageid}'. + ' AND elementid={oldelementid}' ); + $sql->setInt('pageid' ,$this->pageid); + $sql->setInt('oldelementid',$oldElementId ); + $sql->setInt('newelementid',$newElementId ); + $db->query( $sql ); + } + } + } + + + + /** + * Ermitteln des Dateinamens dieser Seite. + * + * Wenn '$this->content_negotiation' auf 'true' steht, wird der Dateiname ggf. gekürzt, + * so wie er für HTML-Links verwendet wird. Sonst wird immer der echte Dateiname + * ermittelt. + * + * @return String Kompletter Dateiname, z.B. '/pfad/seite.en.html' + */ + function full_filename() + { + $filename = $this->path(); + + if ( !empty($filename) ) + $filename .= '/'; + + if ( $this->cut_index && $this->filename == config('publish','default') ) + { + // Link auf Index-Datei, der Dateiname bleibt leer. + } + else + { + $format = config('publish','format'); + $format = str_replace('{filename}',$this->filename(),$format ); + + if ( !$this->withLanguage || $this->content_negotiation && config('publish','negotiation','page_negotiate_language' ) ) + { + $format = str_replace('{language}' ,'',$format ); + $format = str_replace('{language_sep}','',$format ); + } + else + { + $l = new Language( $this->languageid ); + $l->load(); + $format = str_replace('{language}' ,$l->isoCode ,$format ); + $format = str_replace('{language_sep}',config('publish','language_sep'),$format ); + } + + if ( !$this->withModel || $this->content_negotiation && config('publish','negotiation','page_negotiate_type' ) ) + { + $format = str_replace('{type}' ,'',$format ); + $format = str_replace('{type_sep}','',$format ); + } + else + { + $t = new Template( $this->templateid ); + $t->modelid = $this->modelid; + $t->load(); + $format = str_replace('{type}' ,$t->extension ,$format ); + $format = str_replace('{type_sep}',config('publish','type_sep'),$format ); + } + $filename .= $format; + } + + $this->fullFilename = $filename; + return $filename; + } + + +// function language_filename() +// { +// global $SESS; +// +// $db = db_connection(); +// +// $sql = new Sql( 'SELECT COUNT(*) FROM {t_language}'. +// ' WHERE projectid={projectid}' ); +// $sql->setInt('projectid',$SESS['projectid']); +// +// if ( $db->getOne( $sql ) == 1 ) +// { +// // Wenn es nur eine Sprache gibt, keine Sprachangabe im Dateinamen +// return ''; +// } +// else +// { +// $sql = new Sql( 'SELECT isocode FROM {t_language}'. +// ' WHERE id={languageid}' ); +// $sql->setInt('languageid',$this->languageid); +// $isocode = $db->getOne( $sql ); +// +// return strtolower( $isocode ); +// } +// } + + + /** + * Erzeugen der Inhalte zu allen Elementen dieser Seite + * wird von generate() aufgerufen + * + * @access private + */ + function getElementIds() + { + $t = new Template( $this->templateid ); + + return $t->getElementIds(); + } + + + + /** + * Erzeugen der Inhalte zu allen Elementen dieser Seite + * wird von generate() aufgerufen + * + * @access private + */ + function getElements() + { + if ( !isset($this->template) ) + $this->template = new Template( $this->templateid ); + + return $this->template->getElements(); + } + + + + /** + * Erzeugen der Inhalte zu allen Elementen dieser Seite + * wird von generate() aufgerufen + * + * @access private + */ + function getWritableElements() + { + if ( !isset($this->template) ) + $this->template = new Template( $this->templateid ); + + return $this->template->getWritableElements(); + } + + + + /** + * Erzeugen der Inhalte zu allen Elementen dieser Seite + * wird von generate() aufgerufen + * + * @access private + */ + function generate_elements() + { + $this->values = array(); + + if ( $this->simple ) + $elements = $this->getWritableElements(); + else + $elements = $this->getElements(); + + foreach( $elements as $elementid=>$element ) + { + // neues Inhaltobjekt erzeugen + $val = new Value(); + $val->publish = $this->public; + $val->element = $element; + + $val->objectid = $this->objectid; + $val->pageid = $this->pageid; + $val->languageid = $this->languageid; + $val->simple = $this->simple; + $val->modelid = $this->modelid; + $val->page = $this; + $val->generate(); + $val->page = null; + $this->values[$elementid] = $val; + } + } + + + /** + * Erzeugen des Inhaltes der gesamten Seite. + * + * @return String Inhalt + */ + function generate() + { + global $conf; + + // Setzen der 'locale', damit sprachabhängige Systemausgaben (wie z.B. die + // Ausgabe von strftime()) in der korrekten Sprache dargestellt werden. + $language = new Language($this->languageid); + $language->load(); + + $locale_conf = $conf['i18n']['locale']; + if ( isset($locale_conf[strtolower($language->isoCode)]) ) + { + $locale = $locale_conf[strtolower($language->isoCode)]; + $locale_ok = setlocale(LC_ALL,$locale); + if ( !$locale_ok ) + // Hat nicht geklappt. Entweder ist das Mapping falsch oder die locale ist + // nicht korrekt installiert. + Logger::warn("Could not set locale '$locale', please check with 'locale -a' if it is installaled correctly"); + } + else + { + setlocale(LC_ALL,''); + } + + if ( $conf['cache']['enable_cache'] && is_file($this->tmpfile() )) + { + $this->value = implode('',file($this->tmpfile())); + return $this->value; + } + + $this->template = new Template( $this->templateid ); + $this->template->modelid = $this->modelid; + $this->template->load(); + $this->ext = $this->template->extension; + + $this->generate_elements(); + + $src = $this->template->src; + + // Ersetzen der Platzhalter durch die Element-Inhalte + + foreach( $this->values as $id=>$value ) + { + $inh = $value->value; + $src = str_replace( '{{'.$id.'}}',$inh,$src ); + + // Dynamische Bereiche ein- oder ausblenden + if ( $inh == '' ) + { + // Wenn Feld leer + $src = str_replace( '{{IFEMPTY:'.$id.':BEGIN}}','',$src ); + $src = str_replace( '{{IFEMPTY:'.$id.':END}}' ,'',$src ); + + $src = Text::entferneVonBis( $src,'{{IFNOTEMPTY:'.$id.':BEGIN}}','{{IFNOTEMPTY:'.$id.':END}}' ); + } + else + { + // Wenn Feld gefuellt + $src = str_replace( '{{IFNOTEMPTY:'.$id.':BEGIN}}','',$src ); + $src = str_replace( '{{IFNOTEMPTY:'.$id.':END}}' ,'',$src ); + + $src = Text::entferneVonBis( $src,'{{IFEMPTY:'.$id.':BEGIN}}','{{IFEMPTY:'.$id.':END}}' ); + } + + if ( $this->icons ) + $src = str_replace( '{{->'.$id.'}}','<a href="'.Html::url('pageelement','edit',$this->objectid,array('elementid'=>$id)).'" title="'.$value->element->desc.'" target="cms_main_main"><img src="'.OR_THEMES_EXT_DIR.$conf['interface']['theme'].'/images/icon_el_'.$value->element->type.IMG_ICON_EXT.'" border="0"></a>',$src ); + else + $src = str_replace( '{{->'.$id.'}}','',$src ); + } + + if ( config('publish','escape_8bit_characters') ) + if ( substr($this->mimeType(),-4) == 'html' ) + { + $src = htmlentities($src,ENT_NOQUOTES,charset()); + $src = str_replace('&lt;' , '<', $src); + $src = str_replace('&gt;' , '>', $src); + $src = str_replace('&amp;', '&', $src); + } + + $this->value = &$src; + + // Store in cache. + $f = fopen( $this->tmpfile(),'w' ); + fwrite( $f,$this->value ); + fclose( $f ); + + return $this->value; + } + + + /** + * Schreiben des Seiteninhaltes in die temporaere Datei + */ + function write() + { + if ( !is_file($this->tmpfile())) + $this->generate(); + } + + + /** + * Generieren dieser Seite in Dateisystem und/oder auf FTP-Server + */ + function publish() + { + global $SESS; + $db = db_connection(); + + if ( ! is_object($this->publish) ) + $this->publish = new Publish(); + + $this->public = true; + + $allLanguages = Language::getAll(); + $allModels = Model::getAll(); + + // Schleife ueber alle Sprachvarianten + foreach( $allLanguages as $languageid=>$x ) + { + $this->languageid = $languageid; + $this->withLanguage = count($allLanguages) > 1 || config('publish','filename_language') == 'always'; + $this->withModel = count($allModels ) > 1 || config('publish','filename_type' ) == 'always'; + + // Schleife ueber alle Projektvarianten + foreach( $allModels as $projectmodelid=>$x ) + { + $this->modelid = $projectmodelid; + + $this->load(); + $this->generate(); + $this->write(); + + // Vorlage ermitteln. + $t = new Template( $this->templateid ); + $t->modelid = $this->modelid; + $t->load(); + + // Nur wenn eine Datei-Endung vorliegt wird die Seite veroeffentlicht + if ( !empty($t->extension) ) + { + $this->publish->copy( $this->tmpfile(),$this->full_filename() ); + unlink( $this->tmpfile() ); + $this->publish->publishedObjects[] = $this->getProperties(); + } + } + } + + } + + + /** + * Ermittelt den Mime-Type zu dieser Seite + * + * @return String Mime-Type + */ + function mimeType() + { + if ( ! is_object($this->template) ) + { + $this->template = new Template( $this->templateid ); + $this->template->modelid = $this->modelid; + $this->template->load(); + } + + $this->mime_type = $this->template->mimeType(); + + return( $this->mime_type ); + } + + + + /** + * Ermittelt einen tempor�ren Dateinamen f�r diese Seite. + */ + function tmpfile() + { + $db = db_connection(); + $filename = $this->getTempFileName( array('db'=>$db->id, + 'o' =>$this->objectid, + 'l' =>$this->languageid, + 'm' =>$this->modelid, + 'p' =>intval($this->public), + 's' =>intval($this->simple) ) ); + return $filename; + } + + + + function setTimestamp() + { + $tmpFilename = $this->tmpfile(); + + if ( is_file($tmpFilename) ) + unlink( $tmpFilename); + + parent::setTimestamp(); + } + + + /** + * Ermittelt den Dateinamen dieser Seite, so wie sie auch im Dateisystem steht. + */ + function realFilename() + { + $this->withLanguage = config('publish','filename_language') == 'always' || count(Language::count()) > 1; + $this->withModel = config('publish','filename_type' ) == 'always' || count(Model::count() ) > 1; + + return $this->full_filename(); + } +} + + +?>+ \ No newline at end of file diff --git a/model/Project.class.php b/model/Project.class.php @@ -0,0 +1,728 @@ +<?php +// OpenRat Content Management System +// Copyright (C) 2002-2010 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. + + +/** + * Darstellen eines Projektes + * + * @version $Revision$ + * @author $Author$ + * @package openrat.objects + */ +class Project +{ + // Eigenschaften + var $projectid; + var $name; + var $target_dir; + var $ftp_url; + var $ftp_passive; + var $cmd_after_publish; + var $content_negotiation; + var $cut_index; + + var $log = array(); + + + // Konstruktor + function Project( $projectid='' ) + { + if ( intval($projectid) != 0 ) + $this->projectid = $projectid; + } + + + /** + * Stellt fest, ob die angegebene Id existiert. + */ + function available( $id ) + { + $db = db_connection(); + + $sql = new Sql('SELECT 1 FROM {t_project} '. + ' WHERE id={id}'); + $sql->setInt('id' ,$id ); + + return intval($db->getOne($sql)) == 1; + } + + + // Liefert alle verf?gbaren Projekte + function getAll() + { + return Project::getAllProjects(); + } + + + // Liefert alle verf?gbaren Projekte + function getAllProjects() + { + $db = db_connection(); + $sql = new Sql( 'SELECT id,name FROM {t_project} '. + ' ORDER BY name' ); + + return $db->getAssoc( $sql ); + } + + + // Liefert alle verf?gbaren Projekt-Ids + function getAllProjectIds() + { + $db = db_connection(); + $sql = new Sql( 'SELECT id FROM {t_project} '. + ' ORDER BY name' ); + + return $db->getCol( $sql ); + } + + + function getLanguages() + { + $db = db_connection(); + + $sql = new Sql( 'SELECT id,name FROM {t_language}'. + ' WHERE projectid={projectid} '. + ' ORDER BY name' ); + $sql->setInt ('projectid',$this->projectid); + + return $db->getAssoc( $sql ); + } + + + function getLanguageIds() + { + return array_keys( $this->getLanguages() ); + } + + + function getModels() + { + $db = db_connection(); + + $sql = new Sql( 'SELECT id,name FROM {t_projectmodel}'. + ' WHERE projectid= {projectid} '. + ' ORDER BY name' ); + $sql->setInt ('projectid',$this->projectid); + + return $db->getAssoc( $sql ); + } + + + function getModelIds() + { + return array_keys( $this->getModels() ); + } + + + function getTemplateIds() + { + $db = db_connection(); + + $sql = new Sql( 'SELECT id FROM {t_template}'. + ' WHERE projectid= {projectid} ' ); + $sql->setInt ('projectid',$this->projectid); + + return $db->getCol( $sql ); + } + + + function getTemplates() + { + $db = db_connection(); + + $sql = new Sql( 'SELECT id,name FROM {t_template}'. + ' WHERE projectid= {projectid} ' ); + $sql->setInt ('projectid',$this->projectid); + + return $db->getAssoc( $sql ); + } + + + /** + * Ermitteln des Wurzel-Ordners fuer dieses Projekt. + * + * Der Wurzelordner ist der einzige Ordnerhat in diesem + * Projekt, der kein Elternelement besitzt. + * + * @return Objekt-Id des Wurzelordners + */ + function getRootObjectId() + { + $db = db_connection(); + + $sql = new Sql('SELECT id FROM {t_object}'. + ' WHERE parentid IS NULL'. + ' AND projectid={projectid}' ); + + $sql->setInt('projectid',$this->projectid); + + return( $db->getOne( $sql ) ); + } + + + + // Laden + function load() + { + $db = db_connection(); + + $sql = new Sql( 'SELECT * FROM {t_project} '. + ' WHERE id={projectid}' ); + $sql->setInt( 'projectid',$this->projectid ); + + $row = $db->getRow( $sql ); + + $this->name = $row['name' ]; + $this->target_dir = $row['target_dir' ]; + $this->ftp_url = $row['ftp_url' ]; + $this->ftp_passive = $row['ftp_passive' ]; + $this->cmd_after_publish = $row['cmd_after_publish' ]; + $this->content_negotiation = $row['content_negotiation']; + $this->cut_index = $row['cut_index' ]; + } + + + // Laden + function loadByName() + { + $db = db_connection(); + + $sql = new Sql( 'SELECT * FROM {t_project} '. + ' WHERE name={projectname}' ); + $sql->setString( 'projectname',$this->name ); + + $row = $db->getRow( $sql ); + + $this->projectid = $row['id' ]; + $this->target_dir = $row['target_dir' ]; + $this->ftp_url = $row['ftp_url' ]; + $this->ftp_passive = $row['ftp_passive' ]; + $this->cmd_after_publish = $row['cmd_after_publish' ]; + $this->content_negotiation = $row['content_negotiation']; + $this->cut_index = $row['cut_index' ]; + } + + + // Speichern + function save() + { + $db = db_connection(); + + $sql = new Sql( <<<SQL + UPDATE {t_project} + SET name = {name}, + target_dir = {target_dir}, + ftp_url = {ftp_url}, + ftp_passive = {ftp_passive}, + cut_index = {cut_index}, + content_negotiation = {content_negotiation}, + cmd_after_publish = {cmd_after_publish} + WHERE id= {projectid} +SQL +); + + $sql->setString('ftp_url' ,$this->ftp_url ); + $sql->setString('name' ,$this->name ); + $sql->setString('target_dir' ,$this->target_dir ); + $sql->setInt ('ftp_passive' ,$this->ftp_passive ); + $sql->setString('cmd_after_publish' ,$this->cmd_after_publish ); + $sql->setInt ('content_negotiation',$this->content_negotiation ); + $sql->setInt ('cut_index' ,$this->cut_index ); + $sql->setInt ('projectid' ,$this->projectid ); + + $db->query( $sql ); + + $rootFolder = new Folder( $this->getRootObjectId() ); + $rootFolder->load(); + $rootFolder->filename = $this->name; + $rootFolder->save(); + } + + + // Speichern + function getProperties() + { + return Array( 'name' =>$this->name, + 'target_dir' =>$this->target_dir, + 'ftp_url' =>$this->ftp_url, + 'ftp_passive' =>$this->ftp_passive, + 'cmd_after_publish' =>$this->cmd_after_publish, + 'content_negotiation'=>$this->content_negotiation, + 'cut_index' =>$this->cut_index, + 'projectid' =>$this->projectid ); + } + + + // Projekt hinzufuegen + function add() + { + $db = db_connection(); + + $sql = new Sql('SELECT MAX(id) FROM {t_project}'); + $this->projectid = intval($db->getOne($sql))+1; + + + // Projekt hinzuf?gen + $sql = new Sql( 'INSERT INTO {t_project} (id,name,target_dir,ftp_url,ftp_passive,cmd_after_publish,content_negotiation,cut_index) '. + " VALUES( {projectid},{name},'','',0,'',0,0 ) " ); + $sql->setInt ('projectid',$this->projectid ); + $sql->setString('name' ,$this->name ); + + $db->query( $sql ); + + // Modell anlegen + $model = new Model(); + $model->projectid = $this->projectid; + $model->name = 'html'; + $model->add(); + + // Sprache anlegen + $language = new Language(); + $language->projectid = $this->projectid; + $language->isoCode = 'en'; + $language->name = 'english'; + $language->add(); + + // Haupt-Ordner anlegen + $folder = new Folder(); + $folder->isRoot = true; + $folder->projectid = $this->projectid; + $folder->languageid = $language->languageid; + $folder->filename = $this->name; + $folder->name = $this->name; + $folder->isRoot = true; + $folder->add(); + + // Template anlegen + $template = new Template(); + $template->projectid = $this->projectid; + $template->name = ''; + $template->modelid = $model->modelid; + $template->languageid = $language->languageid; + $template->extension = 'html'; + $template->src = '<html><body><h1>Hello world</h1><hr><p>Hello, World.</p></body></html>'; + $template->add(); + $template->save(); + + // Beispiel-Seite anlegen + $page = new Page(); + $page->parentid = $folder->objectid; + $page->projectid = $this->projectid; + $page->languageid = $language->languageid; + $page->templateid = $template->templateid; + $page->filename = ''; + $page->name = 'OpenRat'; + $page->add(); + } + + + // Projekt aus Datenbank entfernen + function delete() + { + $db = db_connection(); + + // Root-Ordner rekursiv samt Inhalten loeschen + $folder = new Folder( $this->getRootObjectId() ); + $folder->deleteAll(); + + + foreach( $this->getLanguageIds() as $languageid ) + { + $language = new Language( $languageid ); + $language->delete(); + } + + + foreach( $this->getTemplateIds() as $templateid ) + { + $template = new Template( $templateid ); + $template->delete(); + } + + + foreach( $this->getModelIds() as $modelid ) + { + $model = new Model( $modelid ); + $model->delete(); + } + + + // Projekt l?schen + $sql = new Sql( 'DELETE FROM {t_project}'. + ' WHERE id= {projectid} ' ); + $sql->setInt( 'projectid',$this->projectid ); + $db->query( $sql ); + } + + function getDefaultLanguageId() + { + $db = Session::getDatabase(); + + // ORDER BY deswegen, damit immer mind. eine Sprache + // gelesen wird + $sql = new Sql( 'SELECT id FROM {t_language} '. + ' WHERE projectid={projectid}'. + ' ORDER BY is_default DESC' ); + + $sql->setInt('projectid',$this->projectid ); + + return $db->getOne( $sql ); + } + + + function getDefaultModelId() + { + $db = Session::getDatabase(); + + // ORDER BY deswegen, damit immer mind. eine Sprache + // gelesen wird + $sql = new Sql( 'SELECT id FROM {t_projectmodel} '. + ' WHERE projectid={projectid}'. + ' ORDER BY is_default DESC' ); + $sql->setInt('projectid',$this->projectid ); + + return $db->getOne( $sql ); + } + + + + /** + * Entfernt nicht mehr notwendige Inhalte aus dem Archiv. + */ + function checkLimit() + { + $root = new Folder( $this->getRootObjectId() ); + $root->projectid = $this->projectid; + + $pages = $root->getAllObjectIds( array('page') ); + $languages = $this->getLanguageIds(); + + foreach( $pages as $objectid ) + { + $page = new Page( $objectid ); + $page->load(); + foreach( $page->getElementIds() as $eid ) + { + foreach( $languages as $lid ) + { + $value = new Value(); + $value->element = new Element($eid); + $value->pageid = $page->pageid; + $value->languageid = $lid; + + $value->checkLimit(); + } + } + } + + } + + + + function checkLostFiles() + { + $this->log = array(); + + $db = &Session::getDatabase(); + + $sql = new Sql( <<<EOF +SELECT thistab.id FROM {t_object} AS thistab + LEFT JOIN {t_object} AS parenttab + ON parenttab.id = thistab.parentid + WHERE thistab.projectid={projectid} AND thistab.parentid IS NOT NULL AND parenttab.id IS NULL +EOF +); + $sql->setInt('projectid',$this->projectid); + + $idList = $db->getCol($sql); + + if ( count( $idList ) > 0 ) + { + $lostAndFoundFolder = new Folder(); + $lostAndFoundFolder->projectid = $this->projectid; + $lostAndFoundFolder->languageid = $this->getDefaultLanguageId(); + $lostAndFoundFolder->filename = "lostandfound"; + $lostAndFoundFolder->name = 'Lost+found'; + $lostAndFoundFolder->parentid = $this->getRootObjectId(); + $lostAndFoundFolder->add(); + + foreach( $idList as $id ) + { + $this->log[] = 'Lost file! Moving '.$id.' to lost+found.'; + $obj = new Object( $id ); + $obj->setParentId( $lostAndFoundFolder->objectid ); + } + } + + } + + + /** + * Kopiert ein Projekt von einer Datenbank zu einer anderen.<br> + * <br> + * Alle Projektinhalte werden kopiert, die Fremdschluesselbeziehungen werden entsprechend angepasst.<br> + * <br> + * Alle Beziehungen zu Benutzern, z.B. "Zuletzt geaendert von", "angelegt von" sowie<br> + * alle Berechtigungsinformationen gehen verloren!<br> + * + * @param dbid_destination ID der Ziel-Datenbank + */ + function export( $dbid_destination ) + { + global $conf; + $zeit = date('Y-m-d\TH:i:sO'); + + $db_src = db_connection(); + $db_dest = new DB( $conf['database'][$dbid_destination] ); + $db_dest->id = $dbid_destination; + $db_dest->start(); + + $sameDB = ( $db_dest->id == $db_src->id ); + + // ------------------------------------------------------- + $mapping = array(); + $ids = array('project' => array('foreign_keys'=>array(), + 'primary_key' =>'id', + 'unique_idx' =>'name', + 'erase' =>array() + ), + 'language' => array('foreign_keys'=>array('projectid'=>'project'), + 'primary_key' =>'id' + ), + 'projectmodel' => array('foreign_keys'=>array('projectid'=>'project'), + 'primary_key' =>'id' + ), + 'template' => array('foreign_keys'=>array('projectid'=>'project'), + 'primary_key' =>'id' + ), + 'object' => array('foreign_keys'=>array('projectid' =>'project' ), + 'self_key' =>'parentid', + 'primary_key' =>'id', + 'erase' =>array('create_userid','lastchange_userid') + ), + 'element' => array('foreign_keys'=>array('templateid' =>'template', + 'folderobjectid' =>'object', + 'default_objectid'=>'object' ), + 'primary_key' =>'id' + ), + 'templatemodel'=> array('foreign_keys'=>array('projectmodelid'=>'projectmodel', + 'templateid' =>'template' ), + 'primary_key' =>'id', + 'replace' =>array('text'=>'element') + ), + 'name' => array('foreign_keys'=>array('objectid' =>'object', + 'languageid'=>'language' ), + 'primary_key' =>'id' + ), + 'page' => array('foreign_keys'=>array('objectid' =>'object', + 'templateid'=>'template' ), + 'primary_key' =>'id' + ), + 'value' => array('foreign_keys'=>array('pageid' =>'page', + 'languageid'=>'language', + 'elementid'=>'element', + 'linkobjectid'=>'object' ), + 'erase' =>array('lastchange_userid'), + 'replace' =>array('text'=>'object'), + 'primary_key' =>'id' + ), + 'link' => array('foreign_keys'=>array('objectid' =>'object', + 'link_objectid'=>'object' ), + 'primary_key' =>'id' + ), + 'folder' => array('foreign_keys'=>array('objectid' =>'object' ), + 'primary_key' =>'id' + ), + 'file' => array('foreign_keys'=>array('objectid' =>'object' ), + 'primary_key' =>'id', + 'binary' =>'value' + ), + + ); + + if ( $sameDB ) + $ids['acl'] = array('foreign_keys'=>array('objectid' => 'object', + 'languageid' => 'language' ), + 'primary_key' =>'id' + ); + + foreach( $ids as $tabelle=>$data ) + { + + $mapping[$tabelle] = array(); + $idcolumn = $data['primary_key']; + + // Naechste freie Id in der Zieltabelle ermitteln. + $sql = new Sql( 'SELECT MAX('.$idcolumn.') FROM {t_'.$tabelle.'}',$dbid_destination); + $maxid = intval($db_dest->getOne($sql)); + $nextid = $maxid; + + // Zu �bertragende IDs ermitteln. + if ( count($data['foreign_keys'])==0 ) + { + $where = ' WHERE id='.$this->projectid; + } + else + { + foreach( $data['foreign_keys'] as $fkey_column=>$target_tabelle ) + { + $where = ' WHERE '.$fkey_column.' IN ('.join(array_keys($mapping[$target_tabelle]),',').')'; + break; + } + } + $sql = new Sql( 'SELECT '.$idcolumn.' FROM {t_'.$tabelle.'} '.$where); + + foreach( $db_src->getCol($sql) as $srcid ) + { + $mapping[$tabelle][$srcid] = ++$nextid; + + $sql = new Sql( 'SELECT * FROM {t_'.$tabelle.'} WHERE id={id}'); + $sql->setInt('id',$srcid); + $row = $db_src->getRow( $sql ); + + // Wert des Prim�rschl�ssels �ndern. + $row[$idcolumn] = $mapping[$tabelle][$srcid]; + + // Fremdschl�sselbeziehungen auf neue IDn korrigieren. + foreach( $data['foreign_keys'] as $fkey_column=>$target_tabelle) + { + if ( intval($row[$fkey_column]) != 0 ) + $row[$fkey_column] = $mapping[$target_tabelle][$row[$fkey_column]]; + } + + foreach( array_keys($row) as $key ) + { + if ( isset($data['unique_idx']) && $key == $data['unique_idx'] ) + { + // Nachschauen, ob es einen UNIQUE-Key in der Zieltabelle schon gibt. + $sql = new Sql( 'SELECT 1 FROM {t_'.$tabelle.'} WHERE '.$key."='".$row[$key]."'",$dbid_destination); + + if ( intval($db_dest->getOne( $sql )) == 1 ) + $row[$key] = $row[$key].$zeit; + + } + + if ( !$sameDB && isset($data['erase']) && in_array($key,$data['erase']) ) + $row[$key] = null; + + if ( isset($data['self_key']) && $key == $data['self_key'] && intval($row[$key]) > 0 ) + $row[$key] = $row[$key]+$maxid; + } + + if ( isset($data['replace']) ) + { + foreach( $data['replace'] as $repl_column=>$repl_tabelle) + foreach( $mapping[$repl_tabelle] as $oldid=>$newid) + { + $row[$repl_column] = str_replace('{'.$oldid.'}','{'.$newid.'}' ,$row[$repl_column]); + $row[$repl_column] = str_replace('"'.$oldid.'"','"'.$newid.'"' ,$row[$repl_column]); + $row[$repl_column] = str_replace('->'.$oldid ,'->"'.$newid.'"',$row[$repl_column]); + } + } + + if ( isset($data['binary']) ) + { + if ( !$db_src->conf['base64'] && $db_dest->conf['base64'] ) + $row[$data['binary']] = base64_encode($row[$data['binary']]); + elseif ( $db_src->conf['base64'] && !$db_dest->conf['base64'] ) + $row[$data['binary']] = base64_decode($row[$data['binary']]); + } + + // Daten in Zieltabelle einf�gen. + $sql = new Sql( 'INSERT INTO {t_'.$tabelle.'} ('.join(array_keys($row),',').') VALUES({'.join(array_keys($row),'},{').'})',$dbid_destination); + foreach( $row as $key=>$value ) + { + if ( !$sameDB && isset($data['erase']) && in_array($key,$data['erase']) ) + $sql->setNull($key); + else + $sql->setVar($key,$value); + } + //$sql = new Sql( 'INSERT INTO {t_'.$tabelle.'} ('.join(array_keys($row),',').') VALUES('.join($row,',').')',$dbid_destination); + $db_dest->query( $sql ); + } + + if ( isset($data['self_key']) ) + { + foreach( $mapping[$tabelle] as $oldid=>$newid ) + { + $sql = new Sql( 'UPDATE {t_'.$tabelle.'} SET '.$data['self_key'].'='.$newid.' WHERE '.$data['self_key'].'='.($oldid+$maxid),$dbid_destination ); + $db_dest->query( $sql ); + } + } + } + + $db_dest->commit(); + } + + + + /** + * Ermittelt die Anzahl aller Objekte in diesem Projekt. + * @return int Anzahl + */ + function countObjects() + { + $db = db_connection(); + $sql = new Sql( 'SELECT COUNT(*) FROM {t_object} '. + ' WHERE projectid = {projectid}' ); + $sql->setInt( 'projectid', $this->projectid ); + + return $db->getOne( $sql ); + + } + + + + /** + * Ermittelt die Gr��e aller Dateien in diesem Projekt. + * @return int Summe aller Dateigroessen + */ + function size() + { + $db = db_connection(); + + $sql = new Sql( <<<SQL + SELECT SUM(size) FROM {t_file} + LEFT JOIN {t_object} + ON {t_file}.objectid = {t_object}.id + WHERE projectid = {projectid} +SQL +); + $sql->setInt( 'projectid', $this->projectid ); + + return $db->getOne( $sql ); + } + + + + /** + * Liefert alle verf?gbaren Projekt-Ids + */ + function info() + { + $info = array(); + + $info['count_objects'] = $this->countObjects(); + $info['sum_filesize' ] = $this->size(); + + + return $info; + } +} + +?>+ \ No newline at end of file diff --git a/model/Template.class.php b/model/Template.class.php @@ -0,0 +1,425 @@ +<?php +// OpenRat Content Management System +// Copyright (C) 2002-2010 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. + + +/** + * Logische Darstellung eines Templates + * + * @author: $Author$ + * @version: $Revision$ + * @package openrat.objects + */ +class Template +{ + /** + * ID dieses Templates + * @type Integer + */ + var $templateid = 0; + + /** + * Projekt-ID des aktuell ausgew?hlten Projektes + * @type Integer + */ + var $projectid = 0; + + /** + * Logischer Name + * @type String + */ + var $name = 'unnamed'; + + /** + * ID der Projektvariante + * @type Integer + */ + var $modelid = 0; + + /** + * Dateierweiterung dieses Templates (abh?ngig von der Projektvariante) + * @type String + */ + var $extension=''; + + /** + * Inhalt des Templates (abh?ngig von der Projektvariante) + * @type String + */ + var $src=''; + + // Konstruktor + function Template( $templateid='' ) + { + $model = Session::getProjectModel(); + $project = Session::getProject(); + if ( is_object($model) ) + $this->modelid = $model->modelid; + if ( is_object($project) ) + $this->projectid = $project->projectid; + + if ( is_numeric($templateid) ) + $this->templateid = $templateid; + } + + + /** + * Ermitteln aller Templates in dem aktuellen Projekt. + * @return Array mit Id:Name + */ + function getAll() + { + global $SESS; + $db = db_connection(); + + $sql = new Sql( 'SELECT id,name FROM {t_template}'. + ' WHERE projectid={projectid}'. + ' ORDER BY name ASC ' ); + if ( isset($this->projectid) ) + $sql->setInt( 'projectid',$this->projectid ); + else + { + $project = Session::getProject(); + $sql->setInt( 'projectid',$project->projectid ); + } + + return $db->getAssoc( $sql ); + } + + + /** + * Laden des Templates aus der Datenbank und f?llen der Objekteigenschaften + */ + function load() + { + global $SESS; + $db = db_connection(); + + $sql = new Sql( 'SELECT * FROM {t_template}'. + ' WHERE id={templateid}' ); + $sql->setInt( 'templateid',$this->templateid ); + $row = $db->getRow( $sql ); + + $this->name = $row['name' ]; + $this->projectid = $row['projectid']; + + $sql = new Sql( 'SELECT * FROM {t_templatemodel}'. + ' WHERE templateid={templateid}'. + ' AND projectmodelid={modelid}' ); + $sql->setInt( 'templateid',$this->templateid ); + $sql->setInt( 'modelid' ,$this->modelid ); + $row = $db->getRow( $sql ); + + if ( isset($row['extension']) ) + { + $this->extension = $row['extension']; + $this->src = $row['text']; + } + + } + + + /** + * Abspeichern des Templates in der Datenbank + */ + function save() + { + if ( $this->name == "" ) + $this->name = lang('GLOBAL_TEMPLATE').' #'.$this->templateid; + + $db = db_connection(); + + $sql = new Sql( 'UPDATE {t_template}'. + ' SET name={name}'. + ' WHERE id={templateid}' ); + $sql->setString( 'name' ,$this->name ); + $sql->setInt ( 'templateid',$this->templateid ); + $db->query( $sql ); + + $sql = new Sql( 'SELECT COUNT(*) FROM {t_templatemodel}'. + ' WHERE templateid={templateid}'. + ' AND projectmodelid={modelid}' ); + $sql->setInt ( 'templateid' ,$this->templateid ); + $sql->setInt ( 'modelid' ,$this->modelid ); + + if ( intval($db->getOne($sql)) > 0 ) + { + $sql = new Sql( 'UPDATE {t_templatemodel}'. + ' SET extension={extension},'. + ' text={src} '. + ' WHERE templateid={templateid}'. + ' AND projectmodelid={modelid}' ); + } + else + { + $sql = new Sql('SELECT MAX(id) FROM {t_templatemodel}'); + $nextid = intval($db->getOne($sql))+1; + $sql = new Sql( 'INSERT INTO {t_templatemodel}'. + ' (id,templateid,projectmodelid,extension,text) '. + ' VALUES ({id},{templateid},{modelid},{extension},{src}) '); + $sql->setInt ( 'id',$nextid ); + } + + $sql->setString( 'extension' ,$this->extension ); + $sql->setString( 'src' ,$this->src ); + $sql->setInt ( 'templateid' ,$this->templateid ); + $sql->setInt ( 'modelid' ,$this->modelid ); + + $db->query( $sql ); + } + + + /** + * Es werden Templates mit einem Inhalt gesucht + * @param String Suchbegriff + * @return Array Liste der gefundenen Template-IDs + */ + function getTemplateIdsByValue( $text ) + { + $db = db_connection(); + + $sql = new Sql( 'SELECT templateid FROM {t_templatemodel}'. + ' WHERE text LIKE {text} '. + ' AND projectmodelid={modelid}' ); + + $sql->setInt ( 'modelid',$this->modelid ); + $sql->setString( 'text' ,'%'.$text.'%' ); + + return $db->getCol( $sql ); + } + + + /** + * Ermitteln aller Elemente zu diesem Template + * Es wird eine Liste nur mit den Element-IDs ermittelt und zur?ckgegeben + * @return Array + */ + function getElementIds() + { + $db = db_connection(); + + $sql = new Sql( 'SELECT id FROM {t_element}'. + ' WHERE templateid={templateid}'. + ' ORDER BY name ASC' ); + $sql->setInt( 'templateid',$this->templateid ); + return $db->getCol( $sql ); + } + + + + /** + * Ermitteln aller Elemente zu diesem Template + * Es wird eine Liste mit den kompletten Elementen ermittelt und zurueckgegeben + * @return Array + */ + function getElements() + { + $list = array(); + $db = db_connection(); + + $sql = new Sql( 'SELECT * FROM {t_element}'. + ' WHERE templateid={templateid}'. + ' ORDER BY name ASC' ); + $sql->setInt( 'templateid',$this->templateid ); + foreach( $db->getAll( $sql ) as $row ) + { + $e = new Element( $row['id'] ); + $e->setDatabaseRow( $row ); + + $list[$e->elementid] = $e; + unset($e); + } + return $list; + } + + + + /** + * Ermitteln aller Elemente zu diesem Template + * Es wird eine Liste mit den kompletten Elementen ermittelt und zurueckgegeben + * @return Array + */ + function getWritableElements() + { + $list = array(); + $e = new Element(); + $readonlyList = "'".implode("','",$e->readonlyElementNames)."'"; + + $db = db_connection(); + + $sql = new Sql( <<<SQL +SELECT * FROM {t_element} + WHERE templateid={templateid} + AND writable=1 + AND type NOT IN ($readonlyList) + ORDER BY name ASC +SQL +); + $sql->setInt ( 'templateid' ,$this->templateid ); + foreach( $db->getAll( $sql ) as $row ) + { + $e = new Element( $row['id'] ); + $e->setDatabaseRow( $row ); + + $list[$e->elementid] = $e; + unset($e); + } + return $list; + } + + + + /** + * Ermitteln aller Elemente zu diesem Template + * Es wird eine Liste mit den Element-Namen zur?ckgegeben + * @return Array + */ + function getElementNames() + { + $db = db_connection(); + + $sql = new Sql( 'SELECT id,name FROM {t_element}'. + ' WHERE templateid={templateid}'. + ' ORDER BY name ASC' ); + $sql->setInt( 'templateid',$this->templateid ); + + return $db->getAssoc( $sql ); + } + + + /** + * Hinzuf?gen eines Elementes + * @param String Name des Elementes + */ + function addElement( $name,$description='',$type='text' ) + { + $element = new Element(); + $element->name = $name; + $element->desc = $description; + $element->type = $type; + $element->templateid = $this->templateid; + $element->wiki = true; + $element->writable = true; + $element->add(); + } + + + /** + * Hinzufuegen eines Templates + * @param String Name des Templates (optional) + */ + function add( $name='' ) + { + if ( !empty($name) ) + $this->name = $name; + + $db = db_connection(); + + $sql = new Sql('SELECT MAX(id) FROM {t_template}'); + $this->templateid = intval($db->getOne($sql))+1; + + $sql = new Sql( 'INSERT INTO {t_template}'. + ' (id,name,projectid)'. + ' VALUES({templateid},{name},{projectid})' ); + $sql->setInt ('templateid',$this->templateid ); + $sql->setString('name' ,$name ); + + // Wenn Projektid nicht vorhanden, dann aus Session lesen + if ( !isset($this->projectid) || intval($this->projectid) == 0 ) + { + $project = Session::getProject(); + $this->projectid = $project->projectid; + } + + $sql->setInt ('projectid' ,$this->projectid ); + + $db->query( $sql ); + } + + + /** + * Ermitteln alles Objekte (=Seiten), welche auf diesem Template basieren + * @return Array Liste von Objekt-IDs + */ + function getDependentObjectIds() + { + $db = db_connection(); + + $sql = new Sql( 'SELECT objectid FROM {t_page}'. + ' WHERE templateid={templateid}' ); + $sql->setInt( 'templateid',$this->templateid ); + + return $db->getCol( $sql ); + } + + + /** + * Loeschen des Templates + * + * Entfernen alle Templateinhalte und des Templates selber + */ + function delete() + { + $db = db_connection(); + + foreach( $this->getElementIds() as $elementid ) + { + $element = new Element( $elementid ); + $element->delete(); + } + + $sql = new Sql( 'DELETE FROM {t_templatemodel}'. + ' WHERE templateid={templateid}' ); + $sql->setInt( 'templateid',$this->templateid ); + $db->query( $sql ); + + $sql = new Sql( 'DELETE FROM {t_template}'. + ' WHERE id={templateid}' ); + $sql->setInt( 'templateid',$this->templateid ); + $db->query( $sql ); + } + + + /** + * Ermittelt den Mime-Type zu diesem Template. + * + * Es wird die Extension des Templates betrachtet und dann mit Hilfe der + * Konfigurationsdatei 'mime-types.ini' der Mime-Type bestimmt. + * + * @return String Mime-Type + */ + function mimeType() + { + global $conf; + $mime_types = $conf['mime-types']; + + // Nur den letzten Teil der Extension auswerten: + // Aus 'mobile.html' wird nur 'html' verwendet. + $extension = strtolower(array_pop(explode('.',$this->extension))); + + if ( !empty($mime_types[$extension]) ) + $this->mime_type = $mime_types[$extension]; + else + // Wenn kein Mime-Type gefunden, dann Standartwert setzen + $this->mime_type = 'application/octet-stream'; + + return( $this->mime_type ); + } + +} + +?>+ \ No newline at end of file diff --git a/model/User.class.php b/model/User.class.php @@ -0,0 +1,1129 @@ +<?php +// DaCMS 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. + + + +/** + * Darstellen eines Benutzers + * + * @version $Revision$ + * @author $Author$ + * @package openrat.objects + */ +class User +{ + var $userid = 0; + var $error = ''; + + var $name = ''; + var $fullname = ''; + var $ldap_dn; + var $tel; + var $mail; + var $desc; + var $style; + var $isAdmin; + var $projects; + var $rights; + var $loginDate = 0; + + var $mustChangePassword = false; + var $groups = null; + + // Konstruktor + function User( $userid='' ) + { + if ( is_numeric($userid) ) + $this->userid = $userid; + } + + + // Lesen Benutzer aus der Datenbank + function listAll() + { + global $conf; + $db = db_connection(); + + $sql = new Sql( 'SELECT id,name '. + ' FROM {t_user}'. + ' ORDER BY name' ); + + return $db->getAssoc( $sql ); + } + + + // Lesen Benutzer aus der Datenbank + function getAllUsers() + { + $list = array(); + $db = db_connection(); + + $sql = new Sql( 'SELECT * '. + ' FROM {t_user}'. + ' ORDER BY name' ); + + foreach( $db->getAll( $sql ) as $row ) + { + $user = new User(); + $user->setDatabaseRow( $row ); + + $list[] = $user; + } + + return $list; + } + + + /** + * Benutzer als aktiven Benutzer in die Session schreiben. + */ + function setCurrent() + { + $this->loadProjects(); + $this->loginDate = time(); + + Session::setUser( $this ); + } + + + /** + * Erzeugt eine WHERE-Bedingung zur Verwendung in einer SQL-Anfrage.<br> + * Es wird eine Oder-Liste mit allen Gruppen-Ids erzeugt. + * + * @return String SQL-WHERE-Bedingung + */ + function getGroupClause() + { + $groupIds = $this->getGroupIds(); + + if ( count($groupIds) > 0 ) + $groupclause = ' groupid='.implode(' OR groupid=',$groupIds ); + else + $groupclause = ' 1=0 '; + + return $groupclause; + } + + + // Prueft, ob der Benutzer fuer ein Projekt berechtigt ist + function hasProject( $projectid ) + { + $db = db_connection(); + + $sql = new Sql( 'SELECT COUNT(*)'. + ' FROM {t_acl}'. + ' LEFT JOIN {t_object} ON {t_object}.id={t_acl}.objectid '. + ' WHERE projectid={projectidid} AND '. + ' ( userid={userid} OR'. + ' '.$this->getGroupClause().' )' ); + $sql->setInt ( 'userid',$this->userid ); + + return $db->getOne( $sql ) > 0; + } + + + + /** + * Lesen aller Projekte, fuer die der Benutzer berechtigt ist. + * + * @return Array [Projekt-Id] = Projekt-Name + */ + function getReadableProjects() + { + $db = db_connection(); + + if ( $this->isAdmin ) + { + // Administratoren haben Rechte auf alle Projekte. + return Project::getAllProjects(); + } + else + { + $groupClause = $this->getGroupClause(); + $sql = new Sql(<<<SQL +SELECT DISTINCT {t_project}.id,{t_project}.name + FROM {t_object} + LEFT JOIN {t_acl} ON {t_object}.id = {t_acl}.objectid + LEFT JOIN {t_project} ON {t_project}.id = {t_object}.projectid + WHERE {t_object}.parentid IS NULL AND + {t_acl}.id IS NOT NULL AND + ( {t_acl}.userid={userid} OR + $groupClause OR + ({t_acl}.userid IS NULL AND {t_acl}.groupid IS NULL)) + ORDER BY {t_project}.name +SQL +); + $sql->setInt ( 'userid',$this->userid ); + + return $db->getAssoc( $sql ); + } + + } + + + + /** + * Ermittelt alls Projekte, fuer die der Benutzer berechtigt ist. + * @return Array [0..n] = Projekt-Id + */ + function getReadableProjectIds() + { + return array_keys( $this->getReadableProjects() ); + } + + + /** + * Lädt die Liste alle Projekte, fuer die der Benutzer berechtigt ist und + * speichert diese in diesem Benutzerobjekt. + */ + function loadProjects() + { + $this->projects = $this->getReadableProjects(); + } + + + + /** + * Lesen Benutzer aus der Datenbank. + */ + function load() + { + global $conf; + $db = db_connection(); + + $sql = new Sql( 'SELECT * FROM {t_user}'. + ' WHERE id={userid}' ); + $sql->setInt( 'userid',$this->userid ); + $row = $db->getRow( $sql ); + + $this->setDatabaseRow( $row ); + } + + + /** + * Benutzerobjekt �ber Benutzernamen ermitteln.<br> + * Liefert ein neues Benutzerobjekt zur�ck. + * + * @static + * @param name Benutzername + */ + function loadWithName( $name ) + { + global $conf; + $db = db_connection(); + + // Benutzer �ber Namen suchen + $sql = new Sql( 'SELECT id FROM {t_user}'. + ' WHERE name={name}' ); + //Html::debug($sql); + $sql->setString( 'name',$name ); + $userId = $db->getOne( $sql ); + + // Benutzer �ber Id instanziieren + $neuerUser = new User( $userId ); + $neuerUser->load(); + + return $neuerUser; + } + + + + /** + * Stellt fest, ob der Benutzer korrekt geladen ist. + */ + function isValid() + { + return intval($this->userid) > 0; + } + + + + // Lesen Benutzer aus der Datenbank + function setDatabaseRow( $row ) + { + global $conf; + + if ( count($row) > 1 ) + { + $this->userid = $row['id' ]; + $this->name = $row['name' ]; + $this->style = $row['style' ]; + $this->isAdmin = ( $row['is_admin'] == '1'); + $this->ldap_dn = $row['ldap_dn' ]; + $this->fullname = $row['fullname']; + $this->tel = $row['tel' ]; + $this->mail = $row['mail' ]; + $this->desc = $row['descr' ]; + + if ( $this->fullname == '' ) + $this->fullname = $this->name; + + if ( $this->style == '' ) + $this->style = $conf['interface']['style']['default']; + } + else + { + $this->userid = -99; + $this->name = lang('UNKNOWN'); + $this->style = $conf['interface']['style']['default']; + $this->isAdmin = false; + $this->ldap_dn = ''; + $this->fullname = lang('UNKNOWN'); + $this->tel = ''; + $this->mail = ''; + $this->desc = ''; + } + + /* vorerst unbenutzt: + if ( $row['use_ldap'] == '1' ) + { + // Daten aus LDAP-Verzeichnisdienst lesen + + // Verbindung zum LDAP-Server herstellen + $ldap_conn = @ldap_connect( $conf['ldap']['host'],$conf['ldap']['port'] ); + + if ( !$ldap_conn ) + { + logger( 'INFO','cannot connect to LDAP server '.$conf['ldap']['host'].' '.$conf['ldap']['port'] ); + $this->error = 'cannot connect to LDAP server'; + return false; + } + + // Anonymes LDAP-Login versuchen + $ldap_bind = @ldap_bind( $ldap_conn ); + + if ( $ldap_bind ) + { + // Login erfolgreich + $sr = ldap_read( $ldap_conn,$row['ldap_dn'],'(objectclass=*)' ); + + $daten = ldap_get_entries( $ldap_conn,$sr ); + + $this->fullname = $daten[0]['givenName'][0].' '.$daten[0]['sn'][0]; + $this->tel = $daten[0]['telephoneNumber'][0]; + $this->mail = $daten[0]['mail'][0]; + $this->desc = $daten[0]['description'][0]; + } + + } + */ + } + + + + /** + * Namen ermitteln.<br> + * Wenn "fullname" gefuellt, dann diesen benutzen, sonst den Benutzernamen. + */ + function getName() + { + if ( empty($this->fullname)) + return $this->name; + else + return $this->fullname; + } + + + + /** + * Liest einen Benutzernamen aus der Datenbank. + * + * @param int Benutzer-Id + * @return String Benutzername + */ + function getUserName( $userid ) + { + $db = db_connection(); + + $sql = new Sql( 'SELECT name FROM {t_user}'. + ' WHERE id={userid}' ); + $sql->setInt( 'userid',$userid ); + + $name = $db->getOne( $sql ); + + if ( $name == '' ) + return lang('UNKNOWN'); + else return $name; + } + + + /** + * Speichern Benutzer in der Datenbank. + */ + function save() + { + $db = db_connection(); + + $sql = new Sql( 'UPDATE {t_user}'. + ' SET name={name},'. + ' fullname={fullname},'. + ' ldap_dn ={ldap_dn} ,'. + ' tel ={tel} ,'. + ' descr ={desc} ,'. + ' mail ={mail} ,'. + ' style ={style} ,'. + ' is_admin={isAdmin} '. + ' WHERE id={userid}' ); + $sql->setString ( 'name' ,$this->name ); + $sql->setString ( 'fullname',$this->fullname); + $sql->setString ( 'ldap_dn' ,$this->ldap_dn ); + $sql->setString ( 'tel' ,$this->tel ); + $sql->setString ( 'desc' ,$this->desc ); + $sql->setString ( 'mail' ,$this->mail ); + $sql->setString ( 'style' ,$this->style ); + $sql->setBoolean( 'isAdmin' ,$this->isAdmin ); + $sql->setInt ( 'userid' ,$this->userid ); + + // Datenbankabfrage ausfuehren + $db->query( $sql ); + } + + + /** + * Benutzer hinzuf�gen + * + * @param String $name Benutzername + */ + function add( $name = '' ) + { + if ( $name != '' ) + $this->name = $name; + + $db = db_connection(); + + $sql = new Sql('SELECT MAX(id) FROM {t_user}'); + $this->userid = intval($db->getOne($sql))+1; + + $sql = new Sql('INSERT INTO {t_user}'. + ' (id,name,password,ldap_dn,fullname,tel,mail,descr,style,is_admin)'. + " VALUES( {userid},{name},'','','','','','','default',0 )" ); + $sql->setInt ('userid',$this->userid); + $sql->setString('name' ,$this->name ); + + // Datenbankbefehl ausfuehren + $db->query( $sql ); + + $this->addNewUserGroups(); // Neue Gruppen hinzufuegen. + } + + + + /** + * Zu einem neuen Benutzer automatisch Gruppen hinzufuegen. + * Diese Methode wird automatisch in "add()" aufgerufen. + */ + function addNewUserGroups() + { + global $conf; + $groupNames = explode(',',@$conf['security']['newuser']['groups']); + + if ( count($groupNames) == 0 ) + return; // Nichts zu tun. + + $db = db_connection(); + + $groupNames = "'".implode("','",$groupNames)."'"; + $sql = new Sql("SELECT id FROM {t_group} WHERE name IN($groupNames)"); + $groupIds = array_unique( $db->getCol($sql) ); + + // Wir brauchen hier nicht weiter pr�fen, ob der Benutzer eine Gruppe schon hat, denn + // - passiert dies nur bei der Neuanlage eines Benutzers + // - Enth�lt die Group-Id-Liste eine ID nur 1x. + + // Gruppen diesem Benutzer zuordnen. + foreach( $groupIds as $groupId ) + $this->addGroup( $groupId ); + } + + + /** + * Benutzer entfernen.<br> + * Vor dem Entfernen werden alle Referenzen auf diesen Benutzer entfernt:<br> + * - "Erzeugt von" f�r diesen Benutzer entfernen.<br> + * - "Letzte �nderung von" f�r diesen Benutzer entfernen<br> + * - Alle Archivdaten in Dateien mit diesem Benutzer entfernen<br> + * - Alle Berechtigungen dieses Benutzers l?schen<br> + * - Alle Gruppenzugehoerigkeiten dieses Benutzers l?schen<br> + * - Benutzer loeschen<br> + */ + function delete() + { + $db = db_connection(); + + // "Erzeugt von" f�r diesen Benutzer entfernen. + $sql = new Sql( 'UPDATE {t_object} '. + 'SET create_userid=null '. + 'WHERE create_userid={userid}' ); + $sql->setInt ('userid',$this->userid ); + $db->query( $sql ); + + // "Letzte �nderung von" f�r diesen Benutzer entfernen + $sql = new Sql( 'UPDATE {t_object} '. + 'SET lastchange_userid=null '. + 'WHERE lastchange_userid={userid}' ); + $sql->setInt ('userid',$this->userid ); + $db->query( $sql ); + + // Alle Archivdaten in Dateien mit diesem Benutzer entfernen + $sql = new Sql( 'UPDATE {t_value} '. + 'SET lastchange_userid=null '. + 'WHERE lastchange_userid={userid}' ); + $sql->setInt ('userid',$this->userid ); + $db->query( $sql ); + + // Alle Berechtigungen dieses Benutzers l?schen + $sql = new Sql( 'DELETE FROM {t_acl} '. + 'WHERE userid={userid}' ); + $sql->setInt ('userid',$this->userid ); + $db->query( $sql ); + + // Alle Gruppenzugehoerigkeiten dieses Benutzers l?schen + $sql = new Sql( 'DELETE FROM {t_usergroup} '. + 'WHERE userid={userid}' ); + $sql->setInt ('userid',$this->userid ); + $db->query( $sql ); + + // Benutzer loeschen + $sql = new Sql( 'DELETE FROM {t_user} '. + 'WHERE id={userid}' ); + $sql->setInt ('userid',$this->userid ); + $db->query( $sql ); + } + + + /** + * Ermitteln der Eigenschaften zu diesem Benutzer + * + * @return Array Liste der Eigenschaften als assoziatives Array + */ + function getProperties() + { + return Array( 'userid' => $this->userid, + 'id' => $this->userid, + 'fullname'=> $this->fullname, + 'name' => $this->name, + 'ldap_dn' => $this->ldap_dn, + 'tel' => $this->tel, + 'desc' => $this->desc, + 'mail' => $this->mail, + 'style' => $this->style, + 'is_admin'=> $this->isAdmin, + 'isAdmin' => $this->isAdmin ); + } + + + /** + * Ueberpruefen des Kennwortes. + * + * Das Kennwort wird ueber Datenbank oder ueber LDAP-Verzeichnisdienst geprueft. + * Wenn + * - ein LDAP-Dn ("distinghished-name") vorhanden ist, dann Pruefung ueber den LDAP-Server, + * - sonst ueber die Benutzertabelle in der Datenbank. + */ + function checkPassword( $password ) + { + global $conf; + + $db = db_connection(); + $this->mustChangePassword = false; + + // Lesen des Benutzers aus der DB-Tabelle + $sql = new Sql( <<<SQL +SELECT * FROM {t_user} + WHERE name={name} +SQL + ); + $sql->setString('name',$this->name); + + $row_user = $db->getRow( $sql ); + + $check = false; + $authType = $conf['security']['auth']['type']; // Entweder 'ldap', 'authdb', 'http', oder 'database' + + if ( !empty($row_user) ) + { + // Benutzername ist bereits in der Datenbank. + $this->userid = $row_user['id']; + $this->ldap_dn = $row_user['ldap_dn']; + $check = true; + $autoAdd = false; // Darf nicht hinzugef�gt werden, da schon vorhanden. + } + elseif( $authType == 'ldap' && $conf['ldap']['search']['add'] ) + { + // Benutzer noch nicht in der Datenbank vorhanden. + // Falls ein LDAP-Account gefunden wird, wird dieser �bernommen. + $check = true; + $autoAdd = true; + } + elseif( $authType == 'authdb' && $conf['security']['authdb']['add'] ) + { + $check = true; + $autoAdd = true; + } + elseif( $authType == 'http' && $conf['security']['http']['add'] ) + { + $check = true; + $autoAdd = true; + } + + if ( $check ) + { + // Falls benutzerspezifischer LDAP-dn vorhanden wird Benutzer per LDAP authentifiziert + if ( $conf['security']['auth']['userdn'] && !empty($this->ldap_dn ) ) + { + Logger::debug( 'checking login via ldap' ); + $ldap = new Ldap(); + $ldap->connect(); + + // Benutzer ist bereits in Datenbank + // LDAP-Login mit dem bereits vorhandenen DN versuchen + $ok = $ldap->bind( $this->ldap_dn, $password ); + + // Verbindung zum LDAP-Server brav beenden + $ldap->close(); + + return $ok; + } + elseif( $authType == 'ldap' ) + { + Logger::debug( 'checking login via ldap' ); + $ldap = new Ldap(); + $ldap->connect(); + + if ( empty($conf['ldap']['dn']) ) + { + // Der Benutzername wird im LDAP-Verzeichnis gesucht. + // Falls gefunden, wird der DN (=der eindeutige Schl�ssel im Verzeichnis) ermittelt. + $dn = $ldap->searchUser( $this->name ); + + if ( empty($dn) ) + { + Logger::debug( 'User not found in LDAP directory' ); + return false; // Kein LDAP-Account gefunden. + } + + Logger::debug( 'User found: '.$dn ); + } + else + { + $dn = str_replace( '{user}',$this->name,$conf['ldap']['dn'] ); + } + + // LDAP-Login versuchen + $ok = $ldap->bind( $dn, $password ); + + Logger::debug( 'LDAP bind: '.($ok?'success':'failed') ); + + if ( $ok && $conf['security']['authorize']['type'] == 'ldap' ) + { + $sucheAttribut = $conf['ldap']['authorize']['group_name']; + $sucheFilter = str_replace('{dn}',$dn,$conf['ldap']['authorize']['group_filter']); + + $ldap_groups = $ldap->searchAttribute( $sucheFilter, $sucheAttribut ); + $sql_ldap_groups = "'".implode("','",$ldap_groups)."'"; + + $sql = new Sql( <<<SQL +SELECT id,name FROM {t_group} + WHERE name IN($sql_ldap_groups) + ORDER BY name ASC +SQL + ); + $oldGroups = $this->getGroupIds(); + $this->groups = $db->getAssoc( $sql ); + + foreach( $this->groups as $groupid=>$groupname) + { + if ( ! in_array($groupid,$oldGroups)) + $this->addGroup($groupid); + } + foreach( $oldGroups as $groupid) + { + if ( !isset($this->groups[$groupid]) ) + $this->delGroup($groupid); + } + + + // Pr�fen, ob Gruppen fehlen. Diese dann ggf. in der OpenRat-Datenbank hinzuf�gen. + if ( $conf['ldap']['authorize']['auto_add'] ) + { + foreach( $ldap_groups as $group ) + { + if ( !in_array($group,$this->groups) ) // Gruppe schon da? + { + $g = new Group(); + $g->name = $group; + $g->add(); // Gruppe hinzuf�gen + + $this->groups[$g->groupid] = $group; + } + } + } +// Html::debug($this->groups,'Gruppen/Ids des Benutzers'); + } + + // Verbindung zum LDAP-Server brav beenden + $ldap->close(); + + if ( $ok && $autoAdd ) + { + // Falls die Authentifizierung geklappt hat, wird der + // LDAP-Account in die Datenbank �bernommen. + $this->ldap_dn = $dn; + $this->fullname = $this->name; + $this->add(); + $this->save(); + } + + return $ok; + } + elseif( $authType == 'database' ) + { + // Pruefen ob Kennwort mit Datenbank uebereinstimmt + if ( $row_user['password'] == $password ) + { + // Kennwort stimmt mit Datenbank �berein, aber nur im Klartext. + // Das Kennwort muss ge�ndert werden + $this->mustChangePassword = true; + + // Login nicht erfolgreich + return false; + } + elseif ( $row_user['password'] == md5( $this->saltPassword($password) ) ) + { + // Die Kennwort-Pr�fsumme stimmt mit dem aus der Datenbank �berein. + // Juchuu, Login ist erfolgreich. + return true; + } + else + { + // Kennwort stimmt garnicht �berein. + return false; + } + } + elseif( $authType == 'authdb' ) + { + $authdb = new DB( $conf['security']['authdb'] ); + $sql = new Sql( $conf['security']['authdb']['sql'] ); + $sql->setString('username',$this->name); + $sql->setString('password',$password); + $row = $authdb->getRow( $sql ); + $ok = !empty($row); + + if ( $ok && $autoAdd ) + { + // Falls die Authentifizierung geklappt hat, wird der + // Benutzername in der eigenen Datenbank eingetragen. + $this->fullname = $this->name; + $this->add(); + $this->save(); + } + // noch nicht implementiert: $authdb->close(); + + return $ok; + } + elseif( $authType == 'http' ) + { + $http = new Http( $conf['security']['http']['url'] ); + $http->method = 'HEAD'; + $http->setBasicAuthentication( $this->name, $password ); + + $ok = $http->request(); + + return $ok; + } + else + { + die( 'unknown authentication-type in configuration: '.$authType ); + } + } + + // Benutzername nicht in Datenbank. + return false; + } + + + /** + * Setzt ein neues Kennwort f�r diesen Benutzer. + * + * @param password Kennwortt + * @param always true, wenn Kennwort dauerhaft. + */ + function setPassword( $password, $always=true ) + { + $db = db_connection(); + + $sql = new Sql( 'UPDATE {t_user} SET password={password}'. + 'WHERE id={userid}' ); + + if ( $always ) + $sql->setString('password',md5($this->saltPassword($password)) ); + else + $sql->setString('password',$password ); + + $sql->setInt ('userid' ,$this->userid ); + + $db->query( $sql ); + } + + + /** + * Gruppen ermitteln, in denen der Benutzer Mitglied ist. + * + * @return Array mit Id:Name + */ + function getGroups() + { + if ( !is_array($this->groups) ) + { + $db = db_connection(); + + $sql = new Sql( 'SELECT {t_group}.id,{t_group}.name FROM {t_group} '. + 'LEFT JOIN {t_usergroup} ON {t_usergroup}.groupid={t_group}.id '. + 'WHERE {t_usergroup}.userid={userid}' ); + $sql->setInt('userid',$this->userid ); + $this->groups = $db->getAssoc( $sql ); + } + + return $this->groups; + } + + + // Gruppen ermitteln, in denen der Benutzer Mitglied ist + function getGroupIds() + { + return array_keys( $this->getGroups() ); + + /* + $db = db_connection(); + + $sql = new Sql( 'SELECT groupid FROM {t_usergroup} '. + 'WHERE userid={userid}' ); + $sql->setInt('userid',$this->userid ); + + return $db->getCol( $sql ); + */ + } + + + // Gruppen ermitteln, in denen der Benutzer *nicht* Mitglied ist + function getOtherGroups() + { + $db = db_connection(); + + $sql = new Sql( 'SELECT {t_group}.id,{t_group}.name FROM {t_group}'. + ' LEFT JOIN {t_usergroup} ON {t_usergroup}.groupid={t_group}.id AND {t_usergroup}.userid={userid}'. + ' WHERE {t_usergroup}.userid IS NULL' ); + $sql->setInt('userid' ,$this->userid ); + + return $db->getAssoc( $sql ); + } + + + // Benutzer einer Gruppe hinzufuegen + function addGroup( $groupid ) + { + $db = db_connection(); + + $sql = new Sql('SELECT MAX(id) FROM {t_usergroup}'); + $usergroupid = intval($db->getOne($sql))+1; + + $sql = new Sql( 'INSERT INTO {t_usergroup} '. + ' (id,userid,groupid) '. + ' VALUES( {usergroupid},{userid},{groupid} )' ); + $sql->setInt('usergroupid',$usergroupid ); + $sql->setInt('userid' ,$this->userid ); + $sql->setInt('groupid' ,$groupid ); + + $db->query( $sql ); + + } + + + // Benutzer aus Gruppe entfernen + function delGroup( $groupid ) + { + $db = db_connection(); + + $sql = new Sql( 'DELETE FROM {t_usergroup} '. + ' WHERE userid={userid} AND groupid={groupid}' ); + $sql->setInt ('userid' ,$this->userid ); + $sql->setInt ('groupid' ,$groupid ); + + $db->query( $sql ); + } + + + /** + * Ermitteln aller Rechte des Benutzers im aktuellen Projekt. + * + * @param Integer $projectid Projekt-Id + * @param Integer $languageid Sprache-Id + */ + function loadRights( $projectid,$languageid ) + { + } + + + /** + * Ermitteln aller Berechtigungen des Benutzers.<br> + * Diese Daten werden auf der Benutzerseite in der Administration angezeigt. + * + * @return unknown + */ + function getAllAcls() + { + + $this->delRights(); + + $db = db_connection(); + + $group_clause = $this->getGroupClause(); + + $sql = new Sql( 'SELECT {t_acl}.*,{t_object}.projectid,{t_language}.name AS languagename FROM {t_acl}'. + ' LEFT JOIN {t_object} '. + ' ON {t_object}.id={t_acl}.objectid '. + ' LEFT JOIN {t_language} '. + ' ON {t_language}.id={t_acl}.languageid '. + ' WHERE ( {t_acl}.userid={userid} OR '.$group_clause. + ' OR ({t_acl}.userid IS NULL AND {t_acl}.groupid IS NULL) )'. + ' ORDER BY {t_object}.projectid,{t_acl}.languageid' ); + $sql->setInt ( 'userid' ,$this->userid ); + + $aclList = array(); + + foreach( $db->getAll( $sql ) as $row ) + { + $acl = new Acl(); + $acl->setDatabaseRow( $row ); + $acl->projectid = $row['projectid' ]; + if ( intval($acl->languageid) == 0 ) + $acl->languagename = lang('GLOBAL_ALL_LANGUAGES'); + else + $acl->languagename = $row['languagename']; + $aclList[] = $acl; + } + + return $aclList; + } + + + /** + * Ermitteln aller Berechtigungen. + * @return Array Berechtigungen + */ + function getRights() + { + die('User.class::getRights()'); + +// $db = db_connection(); +// $var = array(); +// +// // Alle Projekte lesen +// $sql = new Sql( 'SELECT id,name FROM {t_project}' ); +// $projects = $db->getAssoc( $sql ); +// +// foreach( $projects as $projectid=>$projectname ) +// { +// $var[$projectid] = array(); +// $var[$projectid]['name'] = $projectname; +// $var[$projectid]['folders'] = array(); +// $var[$projectid]['rights'] = array(); +// +// $sql = new Sql( 'SELECT {t_acl}.* FROM {t_acl}'. +// ' LEFT JOIN {t_folder} ON {t_acl}.folderid = {t_folder}.id'. +// ' WHERE {t_folder}.projectid={projectid}'. +// ' AND {t_acl}.userid={userid}' ); +// $sql->setInt('projectid',$projectid ); +// $sql->setInt('userid' ,$this->userid ); +// +// $acls = $db->getAll( $sql ); +// +// foreach( $acls as $acl ) +// { +// $aclid = $acl['id']; +// $folder = new Folder( $acl['folderid'] ); +// $folder->load(); +// $var[$projectid]['rights'][$aclid] = $acl; +// $var[$projectid]['rights'][$aclid]['foldername'] = implode(' &raquo; ',$folder->parentfolder( false,true )); +// $var[$projectid]['rights'][$aclid]['delete_url'] = Html::url(array('action'=>'user','subaction'=>'delright','aclid'=>$aclid)); +// } +// +// $sql = new Sql( 'SELECT id FROM {t_folder}'. +// ' WHERE projectid={projectid}' ); +// $sql->setInt('projectid',$projectid); +// $folders = $db->getCol( $sql ); +// +// $var[$projectid]['folders'] = array(); +// +// foreach( $folders as $folderid ) +// { +// $folder = new Folder( $folderid ); +// $folder->load(); +// $var[$projectid]['folders'][$folderid] = implode(' &raquo; ',$folder->parentfolder( false,true )); +// } +// +// asort( $var[$projectid]['folders'] ); +// } +// +// return $var; + } + + + /** + * Entfernt alle Rechte aus diesem Benutzerobjekt. + */ + function delRights() + { + $this->rights = array(); + } + + + /** + * Ueberpruft, ob der Benutzer ein bestimmtes Recht hat + * + * @param $objectid Objekt-Id zu dem Objekt, dessen Rechte untersucht werden sollen + * @param $type Typ des Rechts (Lesen,Schreiben,...) als Konstante ACL_* + */ + function hasRight( $objectid,$type ) + { + global $conf; + if ( $this->isAdmin && !$conf['security']['readonly'] ) + return true; + + if ( $this->isAdmin && $type & ACL_READ ) + return true; + + if ( !isset($this->rights[$objectid]) ) + return false; + + return $this->rights[$objectid] & $type; + } + + + /** + * Berechtigung dem Benutzer hinzufuegen. + * + * @param objectid Objekt-Id, zu dem eine Berechtigung hinzugefuegt werden soll + * @param Art des Rechtes, welches hinzugefuegt werden soll + */ + function addRight( $objectid,$type ) + { + global $conf; + + if ( $conf['security']['readonly'] ) + if ( $type & ACL_READ ) + $type = ACL_READ; + else + $type = 0; + + if ( $type & ACL_PUBLISH && $conf['security']['nopublish'] ) + $type -= ACL_PUBLISH; + + + if ( !isset($this->rights[$objectid]) ) + $this->rights[$objectid] = 0; + + $this->rights[$objectid] = $this->rights[$objectid] | $type; + } + + + /** + * Ermitteln aller zur Verfuegung stehenden Stylesheets + */ + function getAvailableStyles() + { + global $conf_themedir; + + $allstyles = array(); + + // Theme-Verzeichnis nach "*.css"-Dateien durchsuchen. + $dir = $conf_themedir.'/css'; + $handle = @opendir( $dir ); + + if ( !is_resource($handle) ) + Http::serverError('Cannot open CSS dir: '.$dir); + + while ($file = readdir ($handle)) + { + if ( substr($file,-4)=='.css' && substr($file,0,4) != 'base' ) + { + $file = substr($file,0,-4); + $allstyles[$file] = ucwords($file); + } + } + closedir($handle); + + asort($allstyles); // Alphabetisch sortieren. + return $allstyles; + } + + + /** + * Erzeugt ein aussprechbares Kennwort. + * + * Inspired by http://www.phpbuilder.com/annotate/message.php3?id=1014451 + * + * @return String Zuf�lliges Kennwort + */ + function createPassword() + { + global $conf; + + $pw = ''; + $c = 'bcdfghjklmnprstvwz'; //consonants except hard to speak ones + $v = 'aeiou'; //vowels + $a = $c.$v; //both + + //use two syllables... + for ( $i=0; $i < intval($conf['security']['password']['min_length'])/3; $i++ ) + { + $pw .= $c[rand(0, strlen($c)-1)]; + $pw .= $v[rand(0, strlen($v)-1)]; + $pw .= $a[rand(0, strlen($a)-1)]; + } + //... and add a nice number + $pw .= rand(10,99); + + return $pw; + } + + + /** + * Das Kennwort "salzen". + * + * @param Kennwort + * @return Das gesalzene Kennwort + */ + function saltPassword( $pass ) + { + switch( config('security','password','salt') ) + { + case 'userid': + return $this->userid.$pass; + case 'username': + return $this->name.$pass; + case 'custom': + return config('security','password','salt_text').$pass; + default: + return $pass; + } + + } +} + +?>+ \ No newline at end of file diff --git a/model/Value.class.php b/model/Value.class.php @@ -0,0 +1,1503 @@ +<?php +// DaCMS 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. + + + +/** + * Darstellen einer Inhaltes + * + * @version $Revision$ + * @author $Author$ + * @package openrat.objects + */ + +class Value +{ + /** + * ID dieser Inhaltes + * @type Integer + */ + var $valueid=0; + + /** + * Seiten-Objekt der ?bergeordneten Seite + * @type Object + */ + var $page; + + /** + * Seiten-Id der uebergeordneten Seite + * @type Integer + */ + var $pageid; + + /** + * Kennzeichen, ob der Inhalt mit dem Inhalt einer anderern Seite verkn�pft wird. + * @type Object + */ + var $isLink = false; + + /** + * Objekt-ID, auf die verlinkt wird + * @type Integer + */ + var $linkToObjectId=0; + + /** + * Text-Inhalt + * @type String + */ + var $text=''; + + /** + * Zahl. Auch Flie?kommazahlen werden als Ganzzahl gespeichert + * @type Integer + */ + var $number=0; + + + /** + * Datum als Unix-Timestamp + * @type Integer + */ + var $date=0; + + /** + * Element-Objekt + * @type Object + */ + var $element; + + /** + * Element-Id + * @type Integer + */ + var $elementid; + + /** + * Der eigentliche Inhalt des Elementes + * @type String + */ + var $value; + + /** + * TimeStamp der letzten Aenderung + * @type Integer + */ + var $lastchangeTimeStamp; + + /** + * Benutzer-ID der letzten Aenderung + * @type Integer + */ + var $lastchangeUserId; + + /** + * Benutzername der letzten Aenderung + * @type Integer + */ + var $lastchangeUserName; + + /** + * Schalter, ob dieser Inhalt der aktive Inhalt ist + * @type Boolean + */ + var $active; + + /** + * Schalter, ob dieser Inhalt der Inhalt ist, der veroeffentlicht + * werden soll + * @type Boolean + */ + var $publish; + + /** + * Konstruktor + */ + function Value() + { + $this->lastchangeUserId = 0; + $this->lastchangeTimeStamp = 0; + + $language = Session::getProjectLanguage(); + if ( is_object($language) ) + $this->languageid = $language->languageid; + } + + + + + function path_to_page( $pageid ) + { + return $this->page->path_to_object( $pageid ); + } + function path_to_object( $pageid ) + { + return $this->path_to_page( $pageid ); + } + + + /** + * Laden des aktuellen Inhaltes aus der Datenbank + */ + function load() + { + $db = db_connection(); + + if ( $this->publish ) + $sql = new Sql( 'SELECT * FROM {t_value}'. + ' WHERE elementid ={elementid}'. + ' AND pageid ={pageid}'. + ' AND languageid={languageid}'. + ' AND publish=1' ); + else + $sql = new Sql( 'SELECT * FROM {t_value}'. + ' WHERE elementid ={elementid}'. + ' AND pageid ={pageid}'. + ' AND languageid={languageid}'. + ' AND active=1' ); + $sql->setInt( 'elementid' ,$this->element->elementid ); + $sql->setInt( 'pageid' ,$this->pageid ); + $sql->setInt( 'languageid',$this->languageid); + $row = $db->getRow( $sql ); + + if ( count($row) > 0 ) // Wenn Inhalt gefunden + { + $this->text = $row['text']; + $this->valueid = intval($row['id'] ); + $this->linkToObjectId = intval($row['linkobjectid']); + $this->number = intval($row['number' ]); + $this->date = intval($row['date' ]); + + $this->active = ( $row['active' ]=='1' ); + $this->publish = ( $row['publish']=='1' ); + + $this->lastchangeTimeStamp = intval($row['lastchange_date' ]); + $this->lastchangeUserId = intval($row['lastchange_userid']); + } + } + + + /** + * Laden eines bestimmten Inhaltes aus der Datenbank + */ + function loadWithId( $valueid=0 ) + { + if ( $valueid != 0 ) + $this->valueid = $valueid; + + $db = db_connection(); + + $sql = new Sql( 'SELECT {t_value}.*,{t_user}.name as lastchange_username'. + ' FROM {t_value}'. + ' LEFT JOIN {t_user} ON {t_user}.id={t_value}.lastchange_userid'. + ' WHERE {t_value}.id={valueid}' ); + $sql->setInt( 'valueid',$this->valueid); + $row = $db->getRow( $sql ); + + $this->text = $row['text' ]; + $this->pageid = intval($row['pageid' ]); + $this->elementid = intval($row['elementid' ]); + $this->languageid = intval($row['languageid' ]); + $this->valueid = intval($row['id' ]); + $this->linkToObjectId = intval($row['linkobjectid']); + $this->number = intval($row['number' ]); + $this->date = intval($row['date' ]); + + $this->active = ( $row['active' ]=='1' ); + $this->publish = ( $row['publish']=='1' ); + + $this->lastchangeTimeStamp = intval($row['lastchange_date' ]); + $this->lastchangeUserId = intval($row['lastchange_userid' ]); + $this->lastchangeUserName = $row['lastchange_username']; + } + + + /** + * Alle Versionen des aktuellen Inhaltes werden ermittelt + * @return Array + */ + function getVersionList() + { + $db = db_connection(); + + $sql = new Sql( 'SELECT {t_value}.*,{t_user}.name as lastchange_username'. + ' FROM {t_value}'. + ' LEFT JOIN {t_user} ON {t_user}.id={t_value}.lastchange_userid'. + ' WHERE elementid ={elementid}'. + ' AND pageid ={pageid}'. + ' AND languageid={languageid}'. + ' ORDER BY lastchange_date' ); + $sql->setInt( 'elementid' ,$this->element->elementid ); + $sql->setInt( 'pageid' ,$this->pageid ); + $sql->setInt( 'languageid',$this->languageid); + + $list = array(); + foreach( $db->getAll( $sql ) as $row ) + { + $val = new Value(); + $val->valueid = $row['id']; + + $val->text = $row['text']; + $val->valueid = intval($row['id'] ); + $val->linkToObjectId = intval($row['linkobjectid']); + $val->number = intval($row['number' ]); + $val->date = intval($row['date' ]); + + $val->active = ( $row['active' ]=='1' ); + $val->publish = ( $row['publish']=='1' ); + + $val->lastchangeTimeStamp = intval($row['lastchange_date' ]); + $val->lastchangeUserId = intval($row['lastchange_userid' ]); + $val->lastchangeUserName = $row['lastchange_username']; + $list[] = $val; + } + return $list; + } + + + /** + * Die Anzahl der Versionen des aktuellen Inhaltes wird ermittelt + * @return Array + */ + function getCountVersions() + { + $db = db_connection(); + + $sql = new Sql( 'SELECT COUNT(*) FROM {t_value}'. + ' WHERE elementid ={elementid}'. + ' AND pageid ={pageid}'. + ' AND languageid={languageid}' ); + $sql->setInt( 'elementid' ,$this->element->elementid ); + $sql->setInt( 'pageid' ,$this->pageid ); + $sql->setInt( 'languageid',$this->languageid); + + return $db->getOne( $sql ); + } + + + function getLastChangeTime() + { + $db = db_connection(); + + $sql = new Sql( +<<<SQL + SELECT lastchange_date FROM {t_value} + WHERE elementid ={elementid} + AND pageid ={pageid} + AND languageid={languageid} + ORDER BY id DESC +SQL + ); + $sql->setInt( 'elementid' ,$this->element->elementid ); + $sql->setInt( 'pageid' ,$this->pageid ); + $sql->setInt( 'languageid',$this->languageid); + + return $db->getOne( $sql ); + } + + + + /** + * Inhalt freigeben + */ + function release() + { + $db = db_connection(); + + $sql = new Sql( 'UPDATE {t_value}'. + ' SET publish=0'. + ' WHERE elementid ={elementid}'. + ' AND pageid ={pageid}'. + ' AND languageid={languageid}' ); + $sql->setInt( 'elementid' ,$this->elementid ); + $sql->setInt( 'pageid' ,$this->pageid ); + $sql->setInt( 'languageid',$this->languageid); + + $db->query( $sql ); + + $sql = new Sql( 'UPDATE {t_value}'. + ' SET publish=1'. + ' WHERE active = 1'. + ' AND elementid ={elementid}'. + ' AND pageid ={pageid}'. + ' AND languageid={languageid}' ); + $sql->setInt( 'elementid' ,$this->elementid ); + $sql->setInt( 'pageid' ,$this->pageid ); + $sql->setInt( 'languageid',$this->languageid); + + $db->query( $sql ); + } + + /** + * Inhalt speichern + */ + function save() + { + global $SESS; + $db = db_connection(); + + $sql = new Sql( 'UPDATE {t_value}'. + ' SET active=0'. + ' WHERE elementid ={elementid}'. + ' AND pageid ={pageid}'. + ' AND languageid={languageid}' ); + $sql->setInt( 'elementid' ,$this->element->elementid ); + $sql->setInt( 'pageid' ,$this->pageid ); + $sql->setInt( 'languageid',$this->languageid); + + $db->query( $sql ); + + if ( $this->publish ) + { + // Wenn Inhalt sofort veroeffentlicht werden kann, dann + // alle anderen Inhalte auf nicht-veroeffentlichen stellen + $sql = new Sql( 'UPDATE {t_value}'. + ' SET publish=0'. + ' WHERE elementid ={elementid}'. + ' AND pageid ={pageid}'. + ' AND languageid={languageid}' ); + $sql->setInt( 'elementid' ,$this->element->elementid ); + $sql->setInt( 'pageid' ,$this->pageid ); + $sql->setInt( 'languageid',$this->languageid); + + $db->query( $sql ); + } + + // Naechste ID aus Datenbank besorgen + $sql = new Sql('SELECT MAX(id) FROM {t_value}'); + $this->valueid = intval($db->getOne($sql))+1; + + $sql = new Sql( <<<SQL +INSERT INTO {t_value} + (id ,linkobjectid ,text ,number ,date ,elementid ,pageid ,languageid ,active,publish ,lastchange_date ,lastchange_userid ) + VALUES ({valueid},{linkobjectid},{text},{number},{date},{elementid},{pageid},{languageid},1 ,{publish},{lastchange_date},{lastchange_userid}) +SQL + ); + $sql->setInt( 'valueid' ,$this->valueid ); + $sql->setInt( 'elementid' ,$this->element->elementid ); + $sql->setInt( 'pageid' ,$this->pageid ); + $sql->setInt( 'languageid',$this->languageid ); + + if ( intval($this->linkToObjectId)==0) + $sql->setNull ( 'linkobjectid' ); + else $sql->setInt ( 'linkobjectid',$this->linkToObjectId ); + + if ( $this->text == '' ) + $sql->setNull ( 'text' ); + else $sql->setString( 'text',$this->text ); + + if ( intval($this->number)==0) + $sql->setNull ( 'number' ); + else $sql->setInt ( 'number',$this->number ); + + if ( intval($this->date)==0) + $sql->setNull ( 'date' ); + else $sql->setInt ( 'date',$this->date ); + + $sql->setBoolean( 'publish' ,$this->publish ); + $sql->setInt ( 'lastchange_date' ,now() ); + $user = Session::getUser(); + $sql->setInt ( 'lastchange_userid',$user->userid ); + + $db->query( $sql ); + + // Nur ausfuehren, wenn in Konfiguration aktiviert. + $limit = config('content','revision-limit'); + if ( isset($limit['enabled']) && $limit['enabled'] ) + $this->checkLimit(); + } + + + /** + * Pruefen, ob maximale Anzahl von Versionen erreicht. + * In diesem Fall die zu alten Versionen l�schen. + */ + function checkLimit() + { + $limit = config('content','revision-limit'); + + $db = db_connection(); + + $sql = new Sql( <<<SQL + SELECT id FROM {t_value} + WHERE elementid = {elementid} + AND pageid = {pageid} + AND languageid = {languageid} + AND active = 0 + AND publish = 0 + ORDER BY id +SQL + ); + $sql->setInt( 'elementid' ,$this->element->elementid ); + $sql->setInt( 'pageid' ,$this->pageid ); + $sql->setInt( 'languageid',$this->languageid ); + $values = $db->getCol( $sql ); + + if ( count($values) > $limit['min-revisions'] ) + { + $sql = new Sql( <<<SQL + DELETE FROM {t_value} + WHERE elementid = {elementid} + AND pageid = {pageid} + AND languageid = {languageid} + AND active = 0 + AND publish = 0 + AND lastchange_date < {min_date} + AND id < {min_id} +SQL + ); + $sql->setInt( 'elementid' ,$this->element->elementid ); + $sql->setInt( 'pageid' ,$this->pageid ); + $sql->setInt( 'languageid',$this->languageid ); + $sql->setInt( 'min_date' ,$limit['max-age']*24*60*60); + $sql->setInt( 'min_id' ,$values[count($values)-$limit['min-revisions']]); + $db->query($sql); + } + + if ( count($values) > $limit['max-revisions'] ) + { + $sql = new Sql( <<<SQL + DELETE FROM {t_value} + WHERE elementid = {elementid} + AND pageid = {pageid} + AND languageid = {languageid} + AND active = 0 + AND publish = 0 + AND lastchange_date < {min_date} + AND id < {min_id} +SQL + ); + $sql->setInt( 'elementid' ,$this->element->elementid ); + $sql->setInt( 'pageid' ,$this->pageid ); + $sql->setInt( 'languageid',$this->languageid ); + $sql->setInt( 'min_date' ,$limit['min-age']*24*60*60); + $sql->setInt( 'min_id' ,$values[count($values)-$limit['max-revisions']]); + $db->query($sql); + } + } + + + + /** + * Diesen Inhalt loeschen + */ + function delete() + { + $db = db_connection(); + $sql = new Sql( 'DELETE * FROM {t_value}'. + ' WHERE elementid ={elementid}'. + ' AND pageid ={pageid}'. + ' AND languageid={languageid}' ); + $sql->setInt( 'elementid' ,$this->element->elementid ); + $sql->setInt( 'pageid' ,$this->pageid ); + $sql->setInt( 'languageid',$this->languageid); + $row = $db->getRow( $sql ); + } + + + /** + * Hier findet die eigentliche Bereitstellung des Inhaltes statt, zu + * jedem Elementtyp wird ein Inhalt ermittelt. + * + * @return void (aber Eigenschaft 'value' wird gesetzt). + */ + function generate() + { + global $conf; + + if ( intval($this->valueid)==0 ) + $this->load(); + + $inhalt = ''; + + global $conf; + + if ( $conf['cache']['enable_cache'] && is_file( $this->tmpfile() )) + { + $this->value = implode('',file($this->tmpfile() )); // from cache. + return; + } + + // Inhalt ist mit anderer Seite verkn�pft. + if ( in_array($this->element->type,array('text','longtext','date','number')) && intval($this->linkToObjectId) != 0 && !$this->isLink ) + { + $p = new Page( $this->linkToObjectId ); + $p->load(); + + $v = new Value(); + $v->isLink = true; + $v->pageid = $p->pageid; + $v->page = $p; + $v->simple = $this->simple; + $v->element = $this->element; + $v->languageid = $this->languageid; + $v->modelid = $this->modelid; + $v->load(); + $v->generate(); + $this->value = $v->value; + return; + } + + switch( $this->element->type ) + { + case 'list' : // nur wg. R�ckw�rtskompabilit�t. + case 'insert': + + $objectid = $this->linkToObjectId; + + if ( intval($objectid) == 0 ) + $objectid = $this->element->defaultObjectId; + + if ( ! Object::available( $objectid) ) + return; + + $object = new Object( $objectid ); + $object->objectLoadRaw(); + + if ( $object->isFolder ) + { + if ( $this->simple ) + { + $f = new Folder( $objectid ); + $f->load(); + $inhalt = $f->name; + unset( $f ); + } + else + { + if ( $objectid != $this->page->objectid ) // Rekursion vermeiden + { + $f = new Folder( $objectid ); + foreach( $f->getObjectIds() as $oid ) + { + if ( $oid != $this->page->objectid ) // Rekursion vermeiden + { + switch( $this->element->subtype ) + { + case '': + case 'inline': + $o = new Object( $oid ); + $o->load(); + switch( $o->getType() ) + { + case OR_TYPE_PAGE: + $p = new Page( $oid ); + $p->public = $this->page->public; + $p->up_path = $this->page->up_path(); + $p->modelid = $this->page->modelid; + $p->languageid = $this->languageid; + $p->mime_type = $this->page->mimeType(); + $p->load(); + $p->generate(); + $inhalt .= $p->value; + unset( $p ); + break; + case OR_TYPE_LINK: + $l = new Link( $oid ); + $l->load(); + if ( $l->isLinkToObject ) + { + $op = new Object( $l->linkedObjectId ); + $op->load(); + if ( $op->isPage ) + { + $p = new Page( $l->linkedObjectId ); + $p->public = $this->page->public; + $p->up_path = $this->page->up_path(); + $p->modelid = $this->page->modelid; + $p->languageid = $this->languageid; + $p->load(); + $p->generate(); + $inhalt .= $p->value; + unset( $p ); + } + } + break; + } + break; + + case 'ssi': + $inhalt .= '<!--#include virtual="'.$this->page->path_to_object($oid).'" -->'; + break; + + default: + $inhalt = '?'.$this->element->subtype.'?'; + } + } + else die('FATAL: recursion detected'); + } + } + else die('FATAL: recursion detected'); + } + } + elseif ( $object->isPage ) + { + if ( $this->simple ) + { + $p = new Page( $objectid ); + $p->load(); + $inhalt = $p->name; + unset( $p ); + } + else + { + if ( $objectid != $this->page->objectid ) // Rekursion vermeiden + { + switch( $this->element->subtype ) + { + case '': + case 'inline': + $p = new Page( $objectid ); + $p->public = $this->page->public; + $p->up_path = $this->page->up_path(); + $p->modelid = $this->page->modelid; + $p->languageid = $this->languageid; + $p->mime_type = $this->page->mimeType(); + $p->load(); + $p->generate(); + $inhalt = $p->value; + unset( $p ); + break; + + case 'ssi': + $inhalt = '<!--#include virtual="'.$this->page->path_to_object($objectid).'" -->'; + break; + + default: + $inhalt = '?'.$this->element->subtype.'?'; + break; + } + } + else die('FATAL: recursion detected'); + } + } + + if ( $this->simple ) + { + $inhalt = strip_tags( $inhalt ); + $inhalt = str_replace( "\n",'',$inhalt ); + $inhalt = str_replace( "\r",'',$inhalt ); + } + + break; + + + case 'link': + + $objectid = $this->linkToObjectId; + + if ( intval($objectid) == 0 ) + $objectid = $this->element->defaultObjectId; + + if ( $objectid==0 ) + { + // Link noch nicht gefuellt + $inhalt = ''; + } + elseif ( ! Object::available($objectid) ) + { + $inhalt = $this->simple?'-':''; + } + elseif ( $this->simple ) + { + $o = new Object( $objectid ); + $o->load(); + $inhalt = $o->name; + } + elseif ($this->element->subtype == 'image_data_uri' ) + { + $file = new File($objectid); + $file->load(); + $inhalt = 'data:'.$file->mimeType().';base64,'.base64_encode($file->loadValue()); + } + else + { + $inhalt = $this->page->path_to_object( $objectid ); + } + + break; + + + case 'copy': + + list($linkElementName,$targetElementName) = explode('%',$this->element->name.'%'); + + if ( empty($targetElementName) ) + break; + + $element = new Element(); + $element->name = $linkElementName; + $element->load(); + + if ( intval($element->elementid)==0 ) + break; + + $linkValue = new Value(); + $linkValue->elementid = $element->elementid; + $linkValue->element = $element; + $linkValue->pageid = $this->pageid; + $linkValue->page = $this->page; + $linkValue->simple = $this->simple; + $linkValue->languageid = $this->languageid; + $linkValue->load(); + + if ( !Object::available( $linkValue->linkToObjectId ) ) + break; + + $linkedPage = new Page( $linkValue->linkToObjectId ); + $linkedPage->load(); + + $linkedPageTemplate = new Template( $linkedPage->templateid ); + $targetElementId = array_search( $targetElementName, $linkedPageTemplate->getElementNames() ); + + if ( intval($targetElementId)==0 ) + break; + + $targetValue = new Value(); + $targetValue->elementid = $targetElementId; + $targetValue->element = new Element($targetElementId); + $targetValue->element->load(); + $targetValue->pageid = $linkedPage->pageid; + $targetValue->page = $linkedPage; + $targetValue->simple = $this->simple; + $targetValue->generate(); + + $inhalt = $targetValue->value; + + break; + + + case 'linkinfo': + + @list( $linkElementName, $name ) = explode('%',$this->element->name); + if ( is_null($name) ) + break; + + $template = new Template( $this->page->templateid ); + $elementId = array_search( $linkElementName, $template->getElementNames() ); + + + $element = new Element($elementId); + $element->load(); + + $linkValue = new Value(); + $linkValue->elementid = $element->elementid; + $linkValue->element = $element; + $linkValue->pageid = $this->pageid; + $linkValue->languageid = $this->languageid; + $linkValue->load(); + + $objectid = $linkValue->linkToObjectId; + + if ( intval($objectid) == 0 ) + $objectid = $linkValue->element->defaultObjectId; + + if ( !Object::available( $objectid ) ) + break; + + $linkedObject = new Object( $objectid ); + $linkedObject->languageid = $this->languageid; + $linkedObject->load(); + + switch( $this->element->subtype ) + { + case 'width': + $f = new File( $objectid ); + $f->load(); + if ( $f->isImage() ) + { + $f->getImageSize(); + $inhalt = $f->width; + } + unset($f); + break; + + case 'height': + $f = new File( $objectid ); + $f->load(); + if ( $f->isImage() ) + { + $f->getImageSize(); + $inhalt = $f->height; + } + unset($f); + break; + + case 'id': + $inhalt = $objectid; + break; + + case 'name': + $inhalt = $linkedObject->name; + break; + + case 'description': + $inhalt = $linkedObject->description; + break; + + case 'create_user_desc': + $user = $linkedObject->createUser; + $user->load(); + $inhalt = $user->desc; + break; + + case 'create_user_fullname': + $user = $linkedObject->createUser; + $user->load(); + $inhalt = $user->fullname; + break; + + case 'create_user_mail': + $user = $linkedObject->createUser; + $user->load(); + $inhalt = $user->mail; + break; + + case 'create_user_tel': + $user = $linkedObject->createUser; + $user->load(); + $inhalt = $user->tel; + break; + + case 'create_user_username': + $user = $linkedObject->createUser; + $user->load(); + $inhalt = $user->name; + break; + + case 'lastch_user_desc': + $user = $linkedObject->lastchangeUser; + $user->load(); + $inhalt = $user->desc; + break; + + case 'lastch_user_fullname': + $user = $linkedObject->lastchangeUser; + $user->load(); + $inhalt = $user->fullname; + break; + + case 'lastch_user_mail': + $user = $linkedObject->lastchangeUser; + $user->load(); + $inhalt = $user->mail; + break; + + case 'lastch_user_tel': + $user = $linkedObject->lastchangeUser; + $user->load(); + $inhalt = $user->tel; + break; + + case 'lastch_user_username': + $user = $linkedObject->lastchangeUser; + $user->load(); + $inhalt = $user->name; + break; + + case 'mime-type': + if ( $linkedObject->isFile ) + { + $f = new File( $objectid ); + $f->load(); + $inhalt = $f->mimeType(); + unset($f); + } + break; + + case 'filename': + $inhalt = $linkedObject->filename(); + break; + + case 'full_filename': + $inhalt = $linkedObject->full_filename(); + break; + + default: + $inhalt = ''; + Logger::error('subtype for linkinfo not implemented:'.$this->element->subtype); + } + + break; + + case 'linkdate': + + @list( $linkElementName, $name ) = explode('%',$this->element->name); + if ( is_null($name) ) + break; + + $template = new Template( $this->page->templateid ); + $elementId = array_search( $linkElementName, $template->getElementNames() ); + + $element = new Element($elementId); + $element->load(); + + $linkValue = new Value(); + $linkValue->elementid = $element->elementid; + $linkValue->element = $element; + $linkValue->pageid = $this->pageid; + $linkValue->languageid = $this->languageid; + $linkValue->load(); + + $objectid = $linkValue->linkToObjectId; + + if ( intval($objectid) == 0 ) + $objectid = $linkValue->element->defaultObjectId; + + if ( !Object::available( $objectid ) ) + break; + + $linkedObject = new Object( $objectid ); + $linkedObject->load(); + + + switch( $this->element->subtype ) + { + case 'date_published': + // START_TIME wird zu Beginn im Controller gesetzt. + // So erh�lt jede Datei das gleiche Ver�ffentlichungsdatum. + $date = START_TIME; + break; + + case 'date_saved': + $date = $linkedObject->lastchangeDate; + break; + + case 'date_created': + $date = $linkedObject->createDate; + break; + + default: + Logger::warn('element:'.$this->element->name.', '. + 'type:'.$this->element->type.', '. + 'unknown subtype:'.$this->element->subtype); + $date = START_TIME; + } + + if ( strpos($this->element->dateformat,'%')!==FALSE ) + $inhalt = strftime( $this->element->dateformat,$date ); + else + $inhalt = date ( $this->element->dateformat,$date ); + break; + + case 'longtext': + case 'text': + case 'select': + + $inhalt = $this->text; + + // Wenn Inhalt leer, dann versuchen, den Inhalt der Default-Sprache zu laden. + if ( $inhalt == '' && $conf['content']['language']['use_default_language'] ) + { + $project = Session::getProject(); + $this->languageid = $project->getDefaultLanguageId(); + $this->load(); + $inhalt = $this->text; + } + + // Wenn Inhalt leer, dann Vorbelegung verwenden + if ( $inhalt == '' ) + $inhalt = $this->element->defaultText; + + // Wenn HTML nicht erlaubt und Wiki-Formatierung aktiv, dann einfache HTML-Tags in Wiki umwandeln + if ( !$this->element->html && $this->element->wiki && $conf['editor']['wiki']['convert_html'] && $this->page->mimeType()=='text/html' ) + $inhalt = Text::html2Wiki( $inhalt ); + + // Wenn Wiki-Formatierung aktiv, dann BB-Code umwandeln + if ( $this->element->wiki && $conf['editor']['wiki']['convert_bbcode'] ) + $inhalt = Text::bbCode2Wiki( $inhalt ); + + // Wenn HTML nicht erlaubt ist, dann die HTML-Tags ersetzen + if ( !$this->element->html && !$this->element->wiki && $this->page->mimeType()=='text/html') + $inhalt = Text::encodeHtml( $inhalt ); + + // Wenn HTML nicht erlaubt ist, dann Sonderzeichen in HTML �bersetzen + if ( !$this->element->wiki && !$this->element->wiki && $this->page->mimeType()=='text/html' ) + $inhalt = Text::encodeHtmlSpecialChars( $inhalt ); + + // Schnellformatierung ('Wiki') durchfuehren + if ( $this->element->wiki ) + { + $transformer = new Transformer(); + $transformer->text = $inhalt; + $transformer->page = $this->page; + $transformer->element = $this->element; + + $transformer->transform(); + $inhalt = $transformer->text; + } + + if ( $this->page->simple ) + { + $inhalt = strip_tags( $inhalt ); + $inhalt = str_replace( "\n",'',$inhalt ); + $inhalt = str_replace( "\r",'',$inhalt ); + } + + // "__OID__nnn__" ersetzen durch einen richtigen Link + foreach( Text::parseOID($inhalt) as $oid=>$t ) + { + $url = $this->page->path_to_object($oid); + $inhalt = str_replace($t,'"'.$url.'"',$inhalt); + } + + break; + + + // Zahl + // + // wird im entsprechenden Format angezeigt. + case 'number': + + if ( $this->number == 0 ) + { + // Zahl ist gleich 0, dann Default-Text + $inhalt = $this->element->defaultText; + break; + } + + $number = $this->number / pow(10,$this->element->decimals); + $inhalt = number_format( $number,$this->element->decimals,$this->element->decPoint,$this->element->thousandSep ); + + break; + + + // Datum + case 'date': + + $date = $this->date; + + if ( intval($date) == 0 ) + { + // Datum wurde noch nicht eingegeben + $inhalt = $this->element->defaultText; + break; + } + + // Datum gemaess Elementeinstellung formatieren + if ( strpos($this->element->dateformat,'%')!==FALSE ) + $inhalt = strftime( $this->element->dateformat,$date ); + else + $inhalt = date ( $this->element->dateformat,$date ); + break; + + + // Programmcode (PHP) + case 'code': + + if ( $this->page->simple ) + break; + + if ( $conf['security']['disable_dynamic_code'] ) + break; + + $this->page->load(); + + $code = new Code(); + $code->page = &$this->page; + $code->setObjectId( $this->page->objectid ); + $code->delOutput(); + $code->code = $this->element->code; + + // Jetzt ausfuehren des temporaeren PHP-Codes + $code->execute(); + + $inhalt = $code->getOutput(); + + break; + + + // Programmcode (PHP) + case 'dynamic': + + if ( $this->page->simple ) + break; + + $this->page->load(); + $className = $this->element->subtype; + $fileName = './dynamicClasses/'.$className.'.class.php'; + if ( is_file( $fileName ) ) + { + // Fuer den Fall, dass eine Dynamic-Klasse mehrmals pro Vorlage auftritt + if ( !class_exists($className) ) + require( $fileName ); + + if ( class_exists($className) ) + { + $dynEl = new $className; + $dynEl->page = &$this->page; + + if ( method_exists( $dynEl,'execute' ) ) + { + //$dynEl->delOutput(); + $dynEl->objectid = $this->page->objectid; + $dynEl->page = &$this->page; + + foreach( $this->element->getDynamicParameters() as $param_name=>$param_value ) + { + if ( isset( $dynEl->$param_name ) ) + { + Logger::debug("Setting parameter for dynamic Class $className, ".$param_name.':'.$param_value ); + $dynEl->$param_name = $param_value; + } + } + + $dynEl->execute(); + $inhalt = $dynEl->getOutput(); + } + else + { + Logger::warn('element:'.$this->element->name.', '. + 'class:'.$className.', no method: execute()'); + } + } + else + { + Logger::warn('element:'.$this->element->name.', '. + 'class not found:'.$className); + } + } + else + { + Logger::warn('element:'.$this->element->name.', '. + 'file not found:'.$fileName); + } + + // Wenn HTML-Ausgabe, dann Sonderzeichen in HTML �bersetzen + if ( $this->page->mimeType()=='text/html' ) + $inhalt = Text::encodeHtmlSpecialChars( $inhalt ); + + break; + + + // Info-Feld als Datum + case 'infodate': + + if ( $this->page->simple ) + break; + + switch( $this->element->subtype ) + { + case 'date_published': + // START_TIME wird zu Beginn im Controller gesetzt. + // So erh�lt jede Datei das gleiche Ver�ffentlichungsdatum. + $date = START_TIME; + break; + + case 'date_saved': + $date = $this->page->lastchangeDate; + break; + + case 'date_created': + $date = $this->page->createDate; + break; + + default: + Logger::warn('element:'.$this->element->name.', '. + 'type:'.$this->element->type.', '. + 'unknown subtype:'.$this->element->subtype); + } + + if ( strpos($this->element->dateformat,'%')!==FALSE ) + $inhalt = strftime( $this->element->dateformat,$date ); + else + $inhalt = date ( $this->element->dateformat,$date ); + + break; + + + // Info-Feld + case 'info': + + if ( $this->page->simple ) + break; + + $raw = false; + switch( $this->element->subtype ) + { + case 'db_id': + $inhalt = $SESS['dbid']; + break; + case 'db_name': + $inhalt = $conf['database_'.$SESS['dbid']]['comment']; + break; + case 'project_id': + $inhalt = $this->page->projectid; + break; + case 'project_name': + $project = new Project( $this->page->projectid ); + $project->load(); + $inhalt = $project->name; + break; + case 'language_id': + $inhalt = $this->page->languageid; + break; + case 'language_iso': + $language = new Language( $this->page->languageid ); + $language->load(); + $inhalt = $language->isoCode; + break; + case 'language_name': + $language = new Language( $this->page->languageid ); + $language->load(); + $inhalt = $language->name; + break; + case 'page_id': + $inhalt = $this->page->objectid; + break; + case 'page_name': + $inhalt = $this->page->name; + break; + case 'page_desc': + $inhalt = $this->page->desc; + break; + case 'page_fullfilename': + $inhalt = $this->page->full_filename(); + break; + case 'page_filename': + $inhalt = $this->page->filename(); + break; + case 'page_extension': + $inhalt = ''; + break; + case 'edit_url': + $raw = true; + $db = Session::getDatabase(); + $inhalt = Html::url('index','object',$this->page->objectid,array('dbid'=>$db->id)); + break; + case 'edit_fullurl': + $raw = true; + $inhalt = Http::getServer(); + $db = Session::getDatabase(); + $params = array('dbid' =>$db->id, + 'objectid' =>$this->page->objectid, + 'modelid' =>$this->page->modelid, + 'languageid'=>$this->page->languageid, + 'elementid' =>$this->element->elementid ); + $inhalt .= '/'.basename(Html::url('index','object',$this->page->objectid,$params)); + break; + case 'lastch_user_username': + $user = $this->page->lastchangeUser; + $user->load(); + $inhalt = $user->name; + break; + case 'lastch_user_fullname': + $user = $this->page->lastchangeUser; + $user->load(); + $inhalt = $user->fullname; + break; + case 'lastch_user_mail': + $user = $this->page->lastchangeUser; + $user->load(); + $inhalt = $user->mail; + break; + case 'lastch_user_desc': + $user = $this->page->lastchangeUser; + $user->load(); + $inhalt = $user->desc; + break; + case 'lastch_user_tel': + $user = $this->page->lastchangeUser; + $user->load(); + $inhalt = $user->tel; + break; + + case 'create_user_username': + $user = $this->page->createUser; + $user->load(); + $inhalt = $user->name; + break; + case 'create_user_fullname': + $user = $this->page->createUser; + $user->load(); + $inhalt = $user->fullname; + break; + case 'create_user_mail': + $user = $this->page->createUser; + $user->load(); + $inhalt = $user->mail; + break; + case 'create_user_desc': + $user = $this->page->createUser; + $user->load(); + $inhalt = $user->desc; + break; + case 'create_user_tel': + $user = $this->page->createUser; + $user->load(); + $inhalt = $user->tel; + break; + + case 'act_user_username': + $user = new User($SESS['user']['id']); + $user->load(); + $inhalt = $user->name; + break; + case 'act_user_fullname': + $user = new User($SESS['user']['id']); + $user->load(); + $inhalt = $user->fullname; + break; + case 'act_user_mail': + $user = new User($SESS['user']['id']); + $user->load(); + $inhalt = $user->mail; + break; + case 'act_user_desc': + $user = new User($SESS['user']['id']); + $user->load(); + $inhalt = $user->desc; + break; + case 'act_user_tel': + $user = new User($SESS['user']['id']); + $user->load(); + $inhalt = $user->tel; + break; + default: + Logger::warn('element:'.$this->element->name.', '. + 'type:'.$this->element->type.', '. + 'unknown subtype:'.$this->element->subtype); + // Keine Fehlermeldung in erzeugte Seite schreiben. + } + + if ( !$raw && $this->page->mimeType()=='text/html' ) + $inhalt = Text::encodeHtml( $inhalt ); + + // Wenn HTML-Ausgabe, dann Sonderzeichen in HTML �bersetzen + if ( $this->page->mimeType()=='text/html' ) + $inhalt = Text::encodeHtmlSpecialChars( $inhalt ); + + break; + + default: + // Unbekannte Elementtypen darf es nicht geben, daher ERROR loggen. + Logger::error('element:'.$this->element->name.', '. + 'unknown type:'.$this->element->type); + + } + + + if ( $this->page->icons && $this->element->withIcon ) + $inhalt = '<a href="'.Html::url('pageelement','edit',$this->page->objectid,array('elementid'=>$this->element->elementid)).'" title="'.$this->element->desc.'" target="cms_main_main"><img src="'.OR_THEMES_EXT_DIR.$conf['interface']['theme'].'/images/icon_el_'.$this->element->type.IMG_ICON_EXT.'" border="0" align="left"></a>'.$inhalt; + + $this->value = $inhalt; + + + // Store in cache. + $f = fopen( $this->tmpfile(),'w' ); + fwrite( $f,$this->value ); + fclose( $f ); + } + + + /** + * Es werden Objekte mit einem Inhalt gesucht. + * @param String Suchbegriff + * @return Array Liste der gefundenen Objekt-IDs + */ + function getObjectIdsByValue( $text ) + { + $db = db_connection(); + + $sql = new Sql( 'SELECT {t_object}.id FROM {t_value} '. + ' LEFT JOIN {t_page} '. + ' ON {t_page}.id={t_value}.pageid '. + ' LEFT JOIN {t_object} '. + ' ON {t_object}.id={t_page}.objectid '. + ' WHERE {t_value}.text LIKE {text}'. + ' AND {t_value}.languageid={languageid}'. + ' ORDER BY {t_object}.lastchange_date DESC' ); + + $sql->setInt ( 'languageid',$this->languageid ); + $sql->setString( 'text' ,'%'.$text.'%' ); + return $db->getCol( $sql ); + } + + + /** + * Es werden Objekte mit einer UserId ermittelt + * @param Integer Benutzer-Id der letzten ?nderung + * @return Array Liste der gefundenen Objekt-IDs + */ + function getObjectIdsByLastChangeUserId( $userid ) + { + + $db = db_connection(); + + $sql = new Sql( 'SELECT {t_object}.id FROM {t_value} '. + ' LEFT JOIN {t_page} '. + ' ON {t_page}.id={t_value}.pageid '. + ' LEFT JOIN {t_object} '. + ' ON {t_object}.id={t_page}.objectid '. + ' WHERE {t_value}.lastchange_userid={userid}'. + ' AND {t_value}.languageid={languageid}'. + ' ORDER BY {t_object}.lastchange_date DESC' ); + $sql->setInt ( 'languageid',$this->languageid ); + $sql->setInt ( 'userid' ,$userid ); + + return $db->getCol( $sql ); + } + + + + /** + * Es wird das Objekt ermittelt, welches der Benutzer zuletzt ge�ndert hat. + * + * @return Integer Objekt-Id + */ + function getLastChangedObjectByUserId( $userid ) + { + $db = db_connection(); + + $sql = new Sql( <<<SQL +SELECT {t_object}.id + FROM {t_value} + LEFT JOIN {t_page} + ON {t_page}.id={t_value}.pageid + LEFT JOIN {t_object} + ON {t_object}.id={t_page}.objectid + WHERE {t_value}.lastchange_userid={userid} + ORDER BY {t_value}.lastchange_date DESC +SQL +); + $sql->setInt ( 'userid' ,$userid ); + return $db->getOne( $sql ); + } + + + /** + * Ermittelt einen tempor�ren Dateinamen f�r diesen Inhalt. + */ + function tmpfile() + { + $db = db_connection(); + $filename = Object::getTempFileName( array('db'=>$db->id, + 'va'=>$this->valueid, + 'el'=>$this->element->elementid, + 'la'=>$this->languageid, + 'm' =>$this->page->modelid, + 'pu'=>intval($this->publish), + 'si'=>intval($this->page->simple) ) ); + return $filename; + } + + + + +}+ \ No newline at end of file diff --git a/model/include.inc.php b/model/include.inc.php @@ -0,0 +1,19 @@ +<?php + +// Diese Objekte stehen zeitweise in der Sitzung, daher muessen dieser immer geparst werden. +require_once( OR_OBJECTCLASSES_DIR."Value.class.".PHP_EXT ); +require_once( OR_OBJECTCLASSES_DIR."Acl.class.".PHP_EXT ); +require_once( OR_OBJECTCLASSES_DIR."Template.class.".PHP_EXT ); +require_once( OR_OBJECTCLASSES_DIR."Object.class.".PHP_EXT ); +require_once( OR_OBJECTCLASSES_DIR."Folder.class.".PHP_EXT ); +require_once( OR_OBJECTCLASSES_DIR."Link.class.".PHP_EXT ); +require_once( OR_OBJECTCLASSES_DIR."File.class.".PHP_EXT ); +require_once( OR_OBJECTCLASSES_DIR."User.class.".PHP_EXT ); +require_once( OR_OBJECTCLASSES_DIR."Group.class.".PHP_EXT ); +require_once( OR_OBJECTCLASSES_DIR."Project.class.".PHP_EXT ); +require_once( OR_OBJECTCLASSES_DIR."Page.class.".PHP_EXT ); +require_once( OR_OBJECTCLASSES_DIR."Language.class.".PHP_EXT ); +require_once( OR_OBJECTCLASSES_DIR."Model.class.".PHP_EXT ); +require_once( OR_OBJECTCLASSES_DIR."Element.class.".PHP_EXT ); + +?>+ \ No newline at end of file diff --git a/objectClasses/.htaccess b/objectClasses/.htaccess @@ -1,2 +0,0 @@ -order deny,allow -deny from all- \ No newline at end of file diff --git a/objectClasses/Acl.class.php b/objectClasses/Acl.class.php @@ -1,509 +0,0 @@ -<?php -// OpenRat Content Management System -// Copyright (C) 2002-2009 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. - - - -// Definition der Berechtigungs-Bits -define('ACL_READ' ,1 ); -define('ACL_WRITE' ,2 ); -define('ACL_PROP' ,4 ); -define('ACL_DELETE' ,8 ); -define('ACL_RELEASE' ,16 ); -define('ACL_PUBLISH' ,32 ); -define('ACL_CREATE_FOLDER',64 ); -define('ACL_CREATE_FILE' ,128 ); -define('ACL_CREATE_LINK' ,256 ); -define('ACL_CREATE_PAGE' ,512 ); -define('ACL_GRANT' ,1024); -define('ACL_TRANSMIT' ,2048); - - - -/** - * Darstellen einer Berechtigung (ACL "Access Control List") - * Die Berechtigung zu einem Objekt wird mit einer Liste dieser Objekte dargestellt - * - * Falls es mehrere ACLs zu einem Objekt gibt, werden die Berechtigung-Flags addiert. - * - * @author Jan Dankert - * @package openrat.objects - */ -class Acl -{ - /** - * eindeutige ID dieser ACL - * @type Integer - */ - var $aclid; - - /** - * ID des Objektes, f?r das diese Berechtigung gilt - * @type Integer - */ - var $objectid = 0; - - /** - * ID des Benutzers - * ( = 0 falls die Berechtigung f?r eine Gruppe gilt) - * @type Integer - */ - var $userid = 0; - - /** - * ID der Gruppe - * ( = 0 falls die Berechtigung f?r einen Benutzer gilt) - * @type Integer - */ - var $groupid = 0; - - /** - * ID der Sprache - * @type Integer - */ - var $languageid = 0; - - /** - * Name der Sprache - * @type String - */ - var $languagename = ''; - - /** - * Es handelt sich um eine Standard-Berechtigung - * (Falls false, dann Zugriffs-Berechtigung) - * @type Boolean - */ - var $isDefault = false; - - /** - * Name des Benutzers, f?r den diese Berechtigung gilt - * @type String - */ - var $username = ''; - - /** - * Name der Gruppe, f?r die diese Berechtigung gilt - * @type String - */ - var $groupname = ''; - - /** - * Inhalt lesen (ist immer wahr) - * @type Boolean - */ - var $read = true; - - /** - * Inhalt bearbeiten - * @type Boolean - */ - var $write = false; - - /** - * Eigenschaften bearbeiten - * @type Boolean - */ - var $prop = false; - - /** - * Objekt l?schen - * @type Boolean - */ - var $delete = false; - - /** - * Objektinhalt freigeben - * @type Boolean - */ - var $release = false; - - /** - * Objekt ver?ffentlichen - * @type Boolean - */ - var $publish = false; - - /** - * Unterordner anlegen - * @type Boolean - */ - var $create_folder = false; - - /** - * Datei anlegen (bzw. hochladen) - * @type Boolean - */ - var $create_file = false; - - /** - * Verknuepfung anlegen - * @type Boolean - */ - var $create_link = false; - - /** - * Seite anlegen - * @type Boolean - */ - var $create_page = false; - - /** - * Berechtigungen vergeben - * @type Boolean - */ - var $grant = false; - - /** - * Berechtigungen an Unterobjekte vererben - * @type Boolean - */ - var $transmit = false; - - - /** - * Konstruktor. - * - * @param Integer Acl-ID - */ - function Acl( $aclid = 0 ) - { - if ( $aclid != 0 ) - $this->aclid = $aclid; - } - - - /** - * Laden einer ACL inklusive Benutzer-, Gruppen- und Sprachbezeichnungen. - * Zum einfachen Laden sollte #loadRaw() benutzt werden. - */ - function load() - { - $db = db_connection(); - - $sql = new Sql( 'SELECT {t_acl}.*,{t_user}.name as username,{t_group}.name as groupname,{t_language}.name as languagename'. - ' FROM {t_acl} '. - ' LEFT JOIN {t_user} ON {t_user}.id = {t_acl}.userid '. - ' LEFT JOIN {t_group} ON {t_group}.id = {t_acl}.groupid '. - ' LEFT JOIN {t_language} ON {t_language}.id = {t_acl}.languageid '. - ' WHERE {t_acl}.id={aclid}' ); - - $sql->setInt('aclid',$this->aclid); - - $row = $db->getRow( $sql ); - - $this->setDatabaseRow( $row ); - - if ( intval($this->languageid)==0 ) - $this->languagename = lang('GLOBAL_ALL_LANGUAGES'); - else $this->languagename = $row['languagename']; - $this->username = $row['username' ]; - $this->groupname = $row['groupname' ]; - } - - - /** - * Laden einer ACL (ohne verknuepfte Namen). - * Diese Methode ist schneller als #load(). - */ - function loadRaw() - { - $db = db_connection(); - - $sql = new Sql( 'SELECT * '. - ' FROM {t_acl} '. - ' WHERE {t_acl}.id={aclid}' ); - - $sql->setInt('aclid',$this->aclid); - - $row = $db->getRow( $sql ); - - $this->setDatabaseRow( $row ); - } - - - /** - * Setzt die Eigenschaften des Objektes mit einer Datenbank-Ergebniszeile. - * - * @param row Ergebniszeile aus ACL-Datenbanktabelle - */ - function setDatabaseRow( $row ) - { - $this->aclid = $row['id']; - - $this->write = ( $row['is_write' ] == '1' ); - $this->prop = ( $row['is_prop' ] == '1' ); - $this->delete = ( $row['is_delete' ] == '1' ); - $this->release = ( $row['is_release' ] == '1' ); - $this->publish = ( $row['is_publish' ] == '1' ); - $this->create_folder = ( $row['is_create_folder'] == '1' ); - $this->create_file = ( $row['is_create_file' ] == '1' ); - $this->create_page = ( $row['is_create_page' ] == '1' ); - $this->create_link = ( $row['is_create_link' ] == '1' ); - $this->grant = ( $row['is_grant' ] == '1' ); - $this->transmit = ( $row['is_transmit' ] == '1' ); - - $this->objectid = intval($row['objectid' ]); - $this->languageid = intval($row['languageid']); - $this->userid = intval($row['userid' ]); - $this->groupid = intval($row['groupid' ]); - } - - - /** - * Erzeugt eine Liste aller Berechtigungsbits dieser ACL. - * - * @return Array (Schluessel=Berechtigungstyp, Wert=boolean) - */ - function getProperties() - { - return Array( 'read' => true, - 'write' => $this->write, - 'prop' => $this->prop, - 'create_folder'=> $this->create_folder, - 'create_file' => $this->create_file, - 'create_link' => $this->create_link, - 'create_page' => $this->create_page, - 'delete' => $this->delete, - 'release' => $this->release, - 'publish' => $this->publish, - 'grant' => $this->grant, - 'transmit' => $this->transmit, - 'is_default' => $this->isDefault, - 'userid' => $this->userid, - 'username' => $this->username, - 'groupid' => $this->groupid, - 'groupname' => $this->groupname, - 'languageid' => $this->languageid, - 'languagename' => $this->languagename, - 'objectid' => $this->objectid ); - - } - - - /** - * Erzeugt eine Liste aller möglichen Berechtigungstypen. - * - * @return 0..n-Array - */ - function getAvailableRights() - { - return array( 'read', - 'write', - 'prop', - 'create_folder', - 'create_file', - 'create_link', - 'create_page', - 'delete', - 'release', - 'publish', - 'grant', - 'transmit' ); - - } - - - /** - * Erzeugt eine Bitmaske mit den Berechtigungen dieser ACL. - * - * @return Integer Bitmaske - */ - function getMask() - { - // intval(boolean) erzeugt numerisch 0 oder 1 :) - $this->mask = ACL_READ; // immer lesen - $this->mask += ACL_WRITE *intval($this->write ); - $this->mask += ACL_PROP *intval($this->prop ); - $this->mask += ACL_DELETE *intval($this->delete ); - $this->mask += ACL_RELEASE *intval($this->release ); - $this->mask += ACL_PUBLISH *intval($this->publish ); - $this->mask += ACL_CREATE_FOLDER *intval($this->create_folder); - $this->mask += ACL_CREATE_FILE *intval($this->create_file ); - $this->mask += ACL_CREATE_LINK *intval($this->create_link ); - $this->mask += ACL_CREATE_PAGE *intval($this->create_page ); - $this->mask += ACL_GRANT *intval($this->grant ); - $this->mask += ACL_TRANSMIT *intval($this->transmit ); - - Logger::trace('mask of acl '.$this->aclid.': '.$this->mask ); - return $this->mask; - } - - - /** - * Erzeugt eine Liste aller gesetzten Berechtigungstypen. - * Beispiel: Array (0:'read',1:'write',2:'transmit') - * - * @return 0..n-Array - */ - function getTrueProperties() - { - $erg = array('read'); - if ( $this->write ) $erg[] = 'write'; - if ( $this->prop ) $erg[] = 'prop'; - if ( $this->create_folder ) $erg[] = 'create_folder'; - if ( $this->create_file ) $erg[] = 'create_file'; - if ( $this->create_link ) $erg[] = 'create_link'; - if ( $this->create_page ) $erg[] = 'create_page'; - if ( $this->delete ) $erg[] = 'delete'; - if ( $this->release ) $erg[] = 'release'; - if ( $this->publish ) $erg[] = 'publish'; - if ( $this->grant ) $erg[] = 'grant'; - if ( $this->transmit ) $erg[] = 'transmit'; - - return $erg; - } - - - - /** - * ACL unwiderruflich loeschen. - */ - function delete() - { - $db = db_connection(); - - $sql = new Sql( 'DELETE FROM {t_acl} '. - ' WHERE id = {aclid} '. - ' AND objectid= {objectid}' ); - - $sql->setInt('aclid' ,$this->aclid ); - $sql->setInt('objectid',$this->objectid); - - $db->query( $sql ); - - $this->aclid = 0; - } - - - /** - * ACL der Datenbank hinzufügen. - */ - function add() - { - $db = db_connection(); - - if ( $this->delete ) - $this->prop = true; - - // Pruefen, ob die ACL schon existiert - $user_comp = intval($this->userid )>0?'=':'IS'; - $group_comp = intval($this->groupid )>0?'=':'IS'; - $language_comp = intval($this->languageid)>0?'=':'IS'; - - $sql = new Sql( <<<SQL - SELECT id FROM {t_acl} - WHERE userid $user_comp {userid} AND - groupid $group_comp {groupid} AND - languageid $language_comp {languageid} AND - objectid = {objectid} AND - is_write = {write} AND - is_prop = {prop} AND - is_create_folder = {create_folder} AND - is_create_file = {create_file} AND - is_create_link = {create_link} AND - is_create_page = {create_page} AND - is_delete = {delete} AND - is_release = {release} AND - is_publish = {publish} AND - is_grant = {grant} AND - is_transmit = {transmit} -SQL -); - - if ( intval($this->userid) == 0 ) - $sql->setNull('userid'); - else - $sql->setInt ('userid',$this->userid); - - if ( intval($this->groupid) == 0 ) - $sql->setNull('groupid'); - else - $sql->setInt ('groupid',$this->groupid); - - $sql->setInt('objectid',$this->objectid); - $sql->setBoolean('write' ,$this->write ); - $sql->setBoolean('prop' ,$this->prop ); - $sql->setBoolean('create_folder',$this->create_folder ); - $sql->setBoolean('create_file' ,$this->create_file ); - $sql->setBoolean('create_link' ,$this->create_link ); - $sql->setBoolean('create_page' ,$this->create_page ); - $sql->setBoolean('delete' ,$this->delete ); - $sql->setBoolean('release' ,$this->release ); - $sql->setBoolean('publish' ,$this->publish ); - $sql->setBoolean('grant' ,$this->grant ); - $sql->setBoolean('transmit' ,$this->transmit ); - - if ( intval($this->languageid) == 0 ) - $sql->setNull('languageid'); - else - $sql->setInt ('languageid',$this->languageid); - - $aclid = intval($db->getOne($sql)); - if ( $aclid > 0 ) - { - // Eine ACL existiert bereits, wir übernehmen diese ID - $this->aclid = $aclid; - return; - } - - - - - $sql = new Sql('SELECT MAX(id) FROM {t_acl}'); - $this->aclid = intval($db->getOne($sql))+1; - - $sql = new Sql( <<<SQL - INSERT INTO {t_acl} - (id,userid,groupid,objectid,is_write,is_prop,is_create_folder,is_create_file,is_create_link,is_create_page,is_delete,is_release,is_publish,is_grant,is_transmit,languageid) - VALUES( {aclid},{userid},{groupid},{objectid},{write},{prop},{create_folder},{create_file},{create_link},{create_page},{delete},{release},{publish},{grant},{transmit},{languageid} ) -SQL -); - - $sql->setInt('aclid' ,$this->aclid ); - - if ( intval($this->userid) == 0 ) - $sql->setNull('userid'); - else - $sql->setInt ('userid',$this->userid); - - if ( intval($this->groupid) == 0 ) - $sql->setNull('groupid'); - else - $sql->setInt ('groupid',$this->groupid); - - $sql->setInt('objectid',$this->objectid); - $sql->setBoolean('write' ,$this->write ); - $sql->setBoolean('prop' ,$this->prop ); - $sql->setBoolean('create_folder',$this->create_folder ); - $sql->setBoolean('create_file' ,$this->create_file ); - $sql->setBoolean('create_link' ,$this->create_link ); - $sql->setBoolean('create_page' ,$this->create_page ); - $sql->setBoolean('delete' ,$this->delete ); - $sql->setBoolean('release' ,$this->release ); - $sql->setBoolean('publish' ,$this->publish ); - $sql->setBoolean('grant' ,$this->grant ); - $sql->setBoolean('transmit' ,$this->transmit ); - - if ( intval($this->languageid) == 0 ) - $sql->setNull('languageid'); - else - $sql->setInt ('languageid',$this->languageid); - - $db->query( $sql ); - } -}- \ No newline at end of file diff --git a/objectClasses/Element.class.php b/objectClasses/Element.class.php @@ -1,522 +0,0 @@ -<?php -// OpenRat Content Management System -// Copyright (C) 2002-2010 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. - - - -/** - * Diese Objektklasse stellt ein Element das. - * - * Ein Element ist ein Platzhalter in einem Template und kann verschiedenen - * Typs sein, z.B. Text oder ein Bild. - * - * @author Jan Dankert - * @package openrat.objects - */ -class Element -{ - /** - * Eindeutige ID dieses Elementes - * @type Integer - */ - var $elementid; - - /** - * Template-ID zu der dieses Elementes geh?rt - * @type Integer - */ - var $templateid; - - /** - * Typ des Elementes - * Folgende Typen sind moeglich: - * <ul> - * <li>text</li> - * <li>longtext</li> - * <li>select</li> - * <li>number</li> - * <li>link</li> - * <li>date</li> - * <li>insert</li> - * <li>linkinfo</li> - * <li>linkdate</li> - * <li>code</li> - * <li>info</li> - * <li>infodate</li> - * </ul> - * - * @type String - */ - var $type; - - /** - * Logischer Name dieses Elementes - * @type String - */ - var $name; - - /** - * Beschreibung zu diesem Element - * Zu jedem Element kann eine Beschreibung hinterlegt werden, die dem Redakteur bei der Bearbeitung - * der Inhalte als Bearbeitungshilfe dienen kann. - * @type String - */ - var $desc; - - /** - * Objekt-ID eines Ordners, aus diesem Ordner (samt Unterordner) - * k?nnen zu verlinkende Objekte ausgew?hlt werden - * @type Integer - */ - var $folderObjectId = 0; - - /** - * Vorausgew�hltes Objekt. - * @type Integer - */ - var $defaultObjectId = 0; - - /** - * Schalter ob dieses Element von Redakteuren bearbeiten werden kann - * @type Boolean - */ - var $writable; - - /** - * Schalter, ob dieses Element in allen Sprachen den gleichen Inhalt haben soll - * @type Boolean - */ - var $allLanguages; - - var $readonlyElementNames = array('copy','linkinfo','linkdate','info','infodate','code','dynamic'); - - /** - * Untertyp. - * - * @var String - */ - var $subtype = ''; - var $withIcon = false; - var $dateformat = 'r'; - var $wiki = false; - var $html = false; - var $decimals = 0; - var $decPoint = '.'; - var $thousandSep = ''; - var $code = ''; - var $defaultText = ''; - - - /** - * Im Konstruktor wird die Element-Id gesetzt - * @param Integer Element-Id - */ - function Element( $elementid=0 ) - { - if ( intval($elementid)!=0 ) - $this->elementid = $elementid; - } - - - /** - * Hinzuf?gen eines Elementes - * Das aktuelle Element wird in die Datenbank geschrieben. - */ - function add() - { - $db = db_connection(); - - $sql = new Sql('SELECT MAX(id) FROM {t_element}'); - $this->elementid = intval($db->getOne($sql))+1; - - $sql = new Sql( 'INSERT INTO {t_element}'. - ' (id,templateid,name,descr,type,writable) '. - " VALUES ( {elementid},{templateid},{name},{description},{type},{writable} ) " ); - - $sql->setInt ( 'elementid' ,$this->elementid ); - $sql->setString ( 'name' ,$this->name ); - $sql->setString ( 'type' ,$this->type ); - $sql->setInt ( 'templateid' ,$this->templateid ); - $sql->setBoolean( 'writable' ,$this->writable ); - $sql->setString ( 'description',$this->desc ); - - $db->query( $sql ); - } - - - -// function path_to_page( $pageid ) -// { -// return $this->page->path_to_object( $pageid ); -// } -// function path_to_object( $pageid ) -// { -// return $this->path_to_page( $pageid ); -// } - - - /** - * Lesen des Elementes aus der Datenbank - * Alle Eigenschaften des Elementes werden aus der Datenbank gelesen - */ - function load() - { - if ( intval($this->elementid) != 0 ) - { - $db = db_connection(); - $sql = new Sql( <<<SQL -SELECT * FROM {t_element} - WHERE id={elementid} -SQL -); - $sql->setInt( 'elementid',$this->elementid ); - $this->setDatabaseRow( $db->getRow( $sql ) ); - } - } - - - function setDatabaseRow( $prop ) - { - if ( count($prop) <= 0 ) - return; - - $this->elementid = $prop['id' ]; - $this->templateid = $prop['templateid']; - $this->name = $prop['name' ]; - $this->desc = $prop['descr' ]; - $this->type = $prop['type' ]; - $this->subtype = $prop['subtype' ]; - - $this->dateformat = $prop['dateformat']; - $this->wiki = ( $prop['wiki' ] == '1' ); - $this->withIcon = ( $prop['with_icon' ] == '1' ); - $this->html = ( $prop['html' ] == '1' ); - $this->allLanguages = ( $prop['all_languages'] == '1' ); - $this->writable = ( $prop['writable' ] == '1' ); - - if ( !$this->writable) - $this->withIcon = false; - - $this->decimals = intval( $prop['decimals' ] ); - $this->decPoint = strval( $prop['dec_point' ] ); - $this->thousandSep = strval( $prop['thousand_sep' ] ); - $this->code = strval( $prop['code' ] ); - $this->defaultText = strval( $prop['default_text' ] ); - $this->folderObjectId = intval( $prop['folderobjectid' ] ); - $this->defaultObjectId = intval( $prop['default_objectid'] ); - } - - - /** - * Abspeichern des Elementes - * Das aktuelle Element wird in der Datenbank gespeichert - */ - function save() - { - $db = db_connection(); - - $sql = new Sql( 'UPDATE {t_element}'. - ' SET templateid = {templateid},'. - ' name = {name},'. - ' descr = {desc},'. - ' type = {type},'. - ' subtype = {subtype},'. - ' with_icon = {withIcon},'. - ' dateformat = {dateformat},'. - ' wiki = {wiki},'. - ' html = {html},'. - ' all_languages = {allLanguages},'. - ' writable = {writable},'. - ' decimals = {decimals},'. - ' dec_point = {decPoint},'. - ' thousand_sep = {thousandSep},'. - ' code = {code},'. - ' default_text = {defaultText},'. - ' folderobjectid = {folderObjectId},'. - ' default_objectid= {defaultObjectId}'. - ' WHERE id={elementid}' ); - - $sql->setInt ( 'elementid' ,$this->elementid ); - $sql->setInt ( 'templateid' ,$this->templateid ); - $sql->setString ( 'name' ,$this->name ); - $sql->setString ( 'desc' ,$this->desc ); - $sql->setString ( 'type' ,$this->type ); - $sql->setString ( 'subtype' ,$this->subtype ); - $sql->setBoolean( 'withIcon' ,$this->withIcon ); - $sql->setString ( 'dateformat' ,$this->dateformat ); - $sql->setBoolean( 'wiki' ,$this->wiki ); - $sql->setBoolean( 'html' ,$this->html ); - $sql->setBoolean( 'writable' ,$this->writable ); - $sql->setBoolean( 'allLanguages' ,$this->allLanguages ); - $sql->setInt ( 'decimals' ,$this->decimals ); - $sql->setString ( 'decPoint' ,$this->decPoint ); - $sql->setString ( 'thousandSep' ,$this->thousandSep ); - $sql->setString ( 'code' ,$this->code ); - $sql->setString ( 'defaultText' ,$this->defaultText ); - - if ( intval($this->folderObjectId)==0 ) - $sql->setNull( 'folderObjectId' ); - else $sql->setInt ( 'folderObjectId' ,$this->folderObjectId ); - - if ( intval($this->defaultObjectId)==0 ) - $sql->setNull( 'defaultObjectId' ); - else $sql->setInt ( 'defaultObjectId' ,$this->defaultObjectId ); - - $db->query( $sql ); - } - - - - /** - * Setzt den Typ des Elementes und schreibt diesen sofort in die Datenbank. - * - * @param String Der neue Typ, siehe getAvailableTypes() f?r m?gliche Typen - * @see #type - */ - function setType( $type ) - { - $this->type = $type; - $db = db_connection(); - - $sql = new Sql( 'UPDATE {t_element}'. - ' SET type = {type}'. - ' WHERE id={elementid}' ); - - $sql->setInt ( 'elementid',$this->elementid ); - $sql->setString ( 'type' ,$this->type ); - - $db->query( $sql ); - } - - - /** - * Setzt ein Prefix vor den Elementnamen. - * @param String Prefix - */ - function setPrefix( $prefix ) - { - if ( strrpos($this->name,'%') === FALSE ) - $name = $this->name; - else - list( $oldprefix,$name ) = explode('%',$this->name.'%'); - - $this->name = $prefix.'%'.$name; - } - - - /** - * Loeschen des Elementes und aller Inhalte - */ - function delete() - { - $db = db_connection(); - - // Inhalte l?schen - $this->deleteValues(); - - // Element l?schen - $sql = new Sql('DELETE FROM {t_element} '. - ' WHERE id={elementid}' ); - $sql->setInt( 'elementid',$this->elementid ); - - $db->query( $sql ); - } - - - /** - * L?schen aller Seiteninhalte mit diesem Element - * Das Element wird nicht gel?scht. - */ - function deleteValues() - { - $db = db_connection(); - - // Alle Inhalte mit diesem Element l?schen - $sql = new Sql('DELETE FROM {t_value} '. - ' WHERE elementid={elementid}' ); - $sql->setInt( 'elementid',$this->elementid ); - $db->query( $sql ); - } - - - /** - * Abhaengig vom Element-Typ werden die zur Darstellung notwendigen Eigenschaften ermittelt. - * @return Array() - */ - function getRelatedProperties() - { - $prp = array('text' =>array('withIcon','allLanguages','writable','htmlwiki','defaultText'), - 'longtext'=>array('withIcon','allLanguages','writable','htmlwiki','defaultText'), - 'select' =>array('withIcon','allLanguages','writable','defaultText','code'), - 'number' =>array('withIcon','allLanguages','writable','decPoint','decimals','thousandSep'), - 'link' =>array('subtype','withIcon','allLanguages','writable','linktype','folderObjectId','defaultObjectId'), - 'date' =>array('withIcon','allLanguages','writable','dateformat','defaultText'), - 'list' =>array('subtype','withIcon','allLanguages','writable','folderObjectId','defaultObjectId'), - 'insert' =>array('subtype','withIcon','allLanguages','writable','folderObjectId','defaultObjectId'), - 'copy' =>array('prefix','name','defaultText'), - 'linkinfo'=>array('prefix','subtype','defaultText'), - 'linkdate'=>array('prefix','subtype','dateformat'), - 'code' =>array('code'), - 'dynamic' =>array('subtype','code'), - 'info' =>array('subtype'), - 'infodate'=>array('subtype','dateformat') ); - return $prp[ $this->type ]; - } - - - - function getDefaultValue() - { - switch( $this->type ) - { - case 'text': - case 'longtext': - return $this->defaultText; - - case 'number'; - return '0'; - - default: - } - - return lang('EL_TYPE_'.$this->type); - - } - - /** - * Ermitteln aller benutzbaren Elementtypen - * @return Array - */ - function getAvailableTypes() - { - return array('text', - 'longtext', - 'select', - 'number', - 'link', - 'date', - 'insert', - 'copy', - 'linkinfo', - 'linkdate', - 'code', - 'dynamic', - 'info', - 'infodate'); - } - - - /** - * Ermittelt die Klasse des Element-Typs.<br> - * Entweder "info", "text" oder "dynamic". - * - * @return String - */ - function getTypeClass() - { - switch( $this->type ) - { - case 'text': - case 'longtext': - case 'select': - case 'number': - case 'link': - case 'date': - case 'list': - case 'insert': - return 'text'; - - case 'code': - case 'dynamic': - return 'dynamic'; - - case 'copy': - case 'info': - case 'infodate': - case 'linkinfo': - case 'linkdate': - return 'info'; - } - } - - - function getSelectItems() - { - $parameters = explode( "\n",$this->code ); - $items = array(); - - foreach( $parameters as $it ) - { - $paar = explode( ":",$it,2 ); - $param_name = trim($paar[0]); - - if ( count($paar) > 1 ) - $param_value = trim($paar[1]); - else - $param_value = trim($paar[0]); - - // Wenn Inhalt mit "'" beginnt und mit "'" aufhoert, dann diese Zeichen abschneiden - if ( substr($param_value,0,1) == "'" && substr($param_value,strlen($param_value)-1,1) == "'" ) - $param_value = substr($param_value,1,strlen($param_value)-2); - - $items[$param_name] = $param_value; - } - return $items; - } - - - function getDynamicParameters() - { - $parameters = explode( "\n",$this->code ); - $items = array(); - - foreach( $parameters as $it ) - { - $paar = explode( ":",$it,2 ); - if ( count($paar) > 1 ) - { - $param_name = trim($paar[0]); - $param_value = trim($paar[1]); - -// // Wenn Inhalt mit "'" beginnt und mit "'" aufhoert, dann diese Zeichen abschneiden -// if ( substr($param_value,0,1) == "'" && substr($param_value,strlen($param_value)-1,1) == "'" ) -// $param_value = substr($param_value,1,strlen($param_value)-2); - - if ( !empty($param_value) ) - $items[$param_name] = $param_value; - } - } - return $items; - } - - - /** - * Ermittelt, ob das Element beschreibbar ist. - * Bestimmte Typen (z.B. Info-Felder) sind nie beschreibbar, dann wird immer false zur?ckgegeben. - * Ansonsten wird ermittelt, ob dieses Element als beschreibbar markiert ist. - */ - function isWritable() - { - // Bei bestimmten Feldern immer false zurueckgeben - if ( in_array($this->type,$this->readonlyElementNames) ) - return false; - - return $this->writable; - } -} - -?>- \ No newline at end of file diff --git a/objectClasses/File.class.php b/objectClasses/File.class.php @@ -1,711 +0,0 @@ -<?php -// OpenRat Content Management System -// Copyright (C) 2002-2009 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. - - -// Standard Mime-Type -define('OR_FILE_DEFAULT_MIMETYPE','application/octet-stream'); - - -/** - * Datei. - * - * @author Jan Dankert - * @package openrat.objects - */ -class File extends Object -{ - var $fileid; - - var $size = 0; - var $value = ''; - var $extension = ''; - var $log_filenames = array(); - var $fullFilename = ''; - var $publish = null; - var $mime_type = ''; - - /** - * Breite eines Bildes. Ist nur verfuegbar, wenn vorher - * #getImageSize() aufgerufen wurde. - */ - var $width = null; - - /** - * Hoehe eines Bildes. Ist nur verfuegbar, wenn vorher - * #getImageSize() aufgerufen wurde. - */ - var $height = null; - - var $tmpfile; - - var $content_negotiation = false; - - - - /** - * Um Probleme mit BLOB-Feldern und Datenbank-Besonderheiten zu vermeiden, - * kann der Binaerinhalt BASE64-kodiert gespeichert werden. - * @type Boolean - */ - var $storeValueAsBase64 = false; - - - - /** - * Konstruktor - * - * @param Objekt-Id - */ - function File( $objectid='' ) - { - global $conf,$SESS; - - $db = Session::getDatabase(); - $this->storeValueAsBase64 = $db->conf['base64']; - - $this->Object( $objectid ); - $this->isFile = true; - } - - - - /** - * Ermitteln des Dateinamens dieser Datei - * - * @return String Kompletter Dateiname, z.B. '/pfad/datei.jpeg' - */ - function full_filename() - { - if ( !empty($this->fullFilename) ) - return $this->fullFilename; - - $filename = parent::full_filename(); - - if ( $this->content_negotiation && config('publish','negotiation','file_negotiate_type' ) ) - { - // Link auf Datei: Extension bleibt aufgrund Content-Negotiation leer - } - else - { - if ( !empty($this->extension) ) - $filename .= '.'.$this->extension; - } - - $this->fullFilename = $filename; - return $filename; - } - - - - /** - * Ermitteln des Dateinamens dieser Datei (ohne Pfadangabe) - * - * @return String Kompletter Dateiname, z.B. '/pfad/datei.jpeg' - */ - function filenameWithExtension() - { - if ( $this->extension != '' ) - return $this->filename.'.'.$this->extension; - else return $this->filename; - } - - - - /** - * Ermitteln aller Eigenschaften - * - * @return Array - */ - function getProperties() - { - return array_merge( parent::getProperties(), - array('full_filename'=>$this->fullFilename, - 'extension' =>$this->extension, - 'size' =>$this->size, - 'mimetype' =>$this->mimetype() ) ); - } - - - - /** - * @deprecated - */ - function getFileObjectIdsByExtension( $extension ) - { - global $SESS; - $db = db_connection(); - - $sqlquery = 'SELECT * FROM {t_object} '; - - if ( $extension != '' ) - { - $sqlquery .= " WHERE extension='"; - - $ext = explode(',',$extension); - $sqlquery .= implode( "' OR extension='",$ext ); - $sqlquery .= "' AND is_file=1 AND projectid={projectid}"; - } - else - { - $sqlquery .= " WHERE is_file=1 AND projectid={projectid}"; - } - - $sql = new Sql( $sqlquery ); - $sql->setInt( 'projectid',$SESS['projectid'] ); - - return $db->getCol( $sql ); - } - - - - /** - * Es werden Objekte zu einer Dateierweiterung ermittelt - * - * @param String Dateierweiterung ohne fuehrenden Punkt (z.B. 'jpeg') - * @return Array Liste der gefundenen Objekt-IDs - */ - function getObjectIdsByExtension( $extension ) - { - $db = db_connection(); - - $sql = new Sql( 'SELECT {t_file}.objectid FROM {t_file} '. - ' LEFT JOIN {t_object} '. - ' ON {t_object}.id={t_file}.objectid'. - ' WHERE {t_file}.extension={extension}'. - ' AND {t_object}.projectid={projectid}' ); - $sql->setInt ( 'projectid',$this->projectid ); - $sql->setString( 'extension',$extension ); - - return $db->getCol( $sql ); - } - - - - /** - * Ermittelt den Mime-Type zu dieser Datei - * - * @return String Mime-Type - */ - function mimeType() - { - if ( !empty( $this->mime_type ) ) - return $this->mime_type; - - global $conf; - $mime_types = $conf['mime-types']; - - - - $ext = strtolower( $this->getRealExtension() ); - - if ( !empty($mime_types[$ext]) ) - $this->mime_type = $mime_types[$ext]; - else - // Wenn kein Mime-Type gefunden, dann Standartwert setzen - $this->mime_type = OR_FILE_DEFAULT_MIMETYPE; - - return( $this->mime_type ); - } - - - - /** - * Ermittelt Breite und H�he des Bildes.<br> - * Die Werte lassen sich anschlie�end �ber die Eigenschaften "width" und "height" ermitteln. - */ - function getImageSize() - { - if ( is_null($this->width) ) - { - $this->write(); // Datei schreiben - - // Bildinformationen ermitteln - $size = getimagesize( $this->tmpfile() ); - - // Breite und Hoehe des aktuellen Bildes - $this->width = $size[0]; - $this->height = $size[1]; - } - } - - - - /** - * Veraendert die Bildgroesse eines Bildes - * - * Diese Methode sollte natuerlich nur bei Bildern ausgefuehrt werden. - * - * @param Neue Breite - * @param Neue Hoehe - * @param Bildgr��enfaktor - * @param Altes Format als Integer-Konstante IMG_xxx - * @param Neues Format als Integer-Konstante IMG_xxx - * @param Jpeg-Qualitaet (sofern neues Format = Jpeg) - */ - function imageResize( $newWidth,$newHeight,$factor,$oldformat,$newformat,$jpegquality ) - { - global $conf; - - $this->write(); // Datei schreiben - - // Bildinformationen ermitteln - $size = getimagesize( $this->tmpfile() ); - - // Breite und Hoehe des aktuellen Bildes - $oldWidth = $size[0]; - $oldHeight = $size[1]; - $aspectRatio = $oldHeight / $oldWidth; // Seitenverhaeltnis - - // Wenn Breite und Hoehe fehlen, dann Bildgroesse beibehalten - if ( $newWidth == 0 && $newHeight == 0) - { - if ( $factor != 0 && $factor != 1 ) - { - $newWidth = $oldWidth * $factor; - $newHeight = $oldHeight * $factor; - $resizing = true; - } - else - { - $newWidth = $oldWidth; - $newHeight = $oldHeight; - $resizing = false; - } - } - else - { - $resizing = true; - } - - // Wenn nur Breite oder Hoehe angegeben ist, dann - // das Seitenverhaeltnis beibehalten - if ( $newWidth == 0 ) - $newWidth = $newHeight / $aspectRatio; - - if ( $newHeight == 0 ) - $newHeight = $newWidth * $aspectRatio; - - - switch( $oldformat ) - { - case IMG_GIF: // GIF - - $oldImage = ImageCreateFromGIF( $this->tmpfile ); - break; - - case IMG_JPG: // JPEG - - $oldImage = ImageCreateFromJPEG($this->tmpfile); - break; - - case IMG_PNG: // PNG - - $oldImage = imagecreatefrompng($this->tmpfile); - break; - - default: - die('unsupported image format "'.$this->extension.'", cannot load image. resize failed'); - } - - // Ab Version 2 der GD-Bibliothek sind TrueColor-Umwandlungen moeglich. - global $conf; - $hasTrueColor = $conf['image']['truecolor']; - - switch( $newformat ) - { - case IMG_GIF: // GIF - - if ( $resizing ) - { - $newImage = ImageCreate($newWidth,$newHeight); - ImageCopyResized($newImage,$oldImage,0,0,0,0,$newWidth, - $newHeight,$oldWidth,$oldHeight); - } - else - { - $newImage = &$oldImage; - } - - ImageGIF($newImage, $this->tmpfile() ); - $this->extension = 'gif'; - - break; - - case IMG_JPG: // JPEG - - if ( !$resizing ) - { - $newImage = &$oldImage; - } - elseif ( $hasTrueColor ) - { - // Verwende TrueColor (GD2) - $newImage = imageCreateTrueColor( $newWidth,$newHeight ); - ImageCopyResampled($newImage,$oldImage,0,0,0,0,$newWidth, - $newHeight,$oldWidth,$oldHeight); - } - else - { - // GD Version 1.x unterstuetzt kein TrueColor - $newImage = ImageCreate($newWidth,$newHeight); - - ImageCopyResized($newImage,$oldImage,0,0,0,0,$newWidth, - $newHeight,$oldWidth,$oldHeight); - } - - ImageJPEG($newImage, $this->tmpfile,$jpegquality ); - $this->extension = 'jpeg'; - - break; - - case IMG_PNG: // PNG - - if ( !$resizing ) - { - $newImage = &$oldImage; - } - elseif ( $hasTrueColor ) - { - // Verwende TrueColor (GD2) - $newImage = imageCreateTrueColor( $newWidth,$newHeight ); - - ImageCopyResampled($newImage,$oldImage,0,0,0,0,$newWidth, - $newHeight,$oldWidth,$oldHeight); - } - else - { - // GD Version 1.x unterstuetzt kein TrueColor - $newImage = ImageCreate($newWidth,$newHeight); - - ImageCopyResized($newImage,$oldImage,0,0,0,0,$newWidth, - $newHeight,$oldWidth,$oldHeight); - } - - imagepng( $newImage,$this->tmpfile() ); - $this->extension = 'png'; - - break; - - default: - die('unsupported image format "'.$newformat.'", cannot resize'); - } - - $f = fopen( $this->tmpfile(), "r" ); - $this->value = fread( $f,filesize($this->tmpfile()) ); - fclose( $f ); - - imagedestroy( $oldImage ); - //imagedestroy( $newImage ); - } - - - /** - * Lesen der Datei aus der Datenbank. - * - * Es werden nur die Meta-Daten (Erweiterung, Gr��e) gelesen. Zum Lesen des - * Datei-Inhaltes muss #loadValue() aufgerufen werden. - */ - function load() - { - $db = db_connection(); - - $sql = new Sql( 'SELECT id,extension,size'. - ' FROM {t_file}'. - ' WHERE objectid={objectid}' ); - $sql->setInt( 'objectid',$this->objectid ); - $row = $db->getRow( $sql ); - - if ( count($row)!=0 ) - { - $this->fileid = $row['id' ]; - $this->extension = $row['extension']; - $this->size = $row['size' ]; - } - - $this->objectLoad(); - } - - - - /** - * Unwiderrufliches L�schen der Datei aus der Datenbank. - */ - function delete() - { - $db = db_connection(); - - // Datei l?schen - $sql = new Sql( 'DELETE FROM {t_file} '. - ' WHERE objectid={objectid}' ); - $sql->setInt( 'objectid',$this->objectid ); - $db->query( $sql ); - - $this->objectDelete(); - } - - - - /** - * Stellt anhand der Dateiendung fest, ob es sich bei dieser Datei um ein Bild handelt - */ - function isImage() - { - return substr($this->mimeType(),0,6)=='image/'; - } - - - - /** - * Ermittelt die Datei-Endung. - * - * @return String Datei-Endung - */ - function extension() - { - if ($this->extension != '') - return $this->extension; - - $this->load(); - return $this->extension; - } - - - /** - * Einen Dateinamen in Dateiname und Extension aufteilen. - * @param filename Dateiname - */ - function parse_filename($filename) - { - $filename = basename($filename); - - $p = strrpos($filename, '.'); - if ($p !== false) - { - $this->extension = substr($filename, $p +1); - $this->filename = substr($filename, 0, $p); - } - else - { - $this->extension = ''; - $this->filename = $filename; - } - } - - - /** - * Speichert die Datei-Informationen in der Datenbank. - */ - function save() - { - global $SESS; - $db = db_connection(); - - $sql = new Sql( <<<EOF -UPDATE {t_file} SET - size = {size}, - extension = {extension} - WHERE objectid={objectid} -EOF -); - $sql->setString('size' ,$this->size ); - $sql->setString('extension',$this->extension ); - $sql->setString('objectid' ,$this->objectid ); - $db->query( $sql ); - - $this->objectSave(); - } - - - /** - * Kopieren des Inhaltes von einer anderen Datei - * @param ID der Datei, von der der Inhalt kopiert werden soll - */ - function copyValueFromFile( $otherfileid ) - { - $of = new File( $otherfileid ); - $this->value = $of->loadValue(); - $this->saveValue(); - } - - - /** - * Lesen des Inhaltes der Datei aus der Datenbank. - * - * @return String Inhalt der Datei - */ - function loadValue() - { - if ( is_file($this->tmpfile())) - return implode('',file($this->tmpfile())); // From cache - - Logger::debug("preview 1"); - - $db = db_connection(); - - $sql = new Sql( 'SELECT size,value'. - ' FROM {t_file}'. - ' WHERE objectid={objectid}' ); - $sql->setInt( 'objectid',$this->objectid ); - $row = $db->getRow( $sql ); - - if ( count($row) != 0 ) - { - $this->value = $row['value']; - $this->size = $row['size' ]; - } - - if ( $this->storeValueAsBase64 ) - $this->value = base64_decode( $this->value ); - - // Store in cache. - $f = fopen( $this->tmpfile(),'w' ); - fwrite( $f,$this->value ); - fclose( $f ); - Logger::debug("preview 2:".$this->objectid.'/'.strlen($this->value)); - - return $this->value; - } - - - /** - * Speichert den Inhalt in der Datenbank. - */ - function saveValue( $value = '' ) - { - if ( is_file($this->tmpfile()) ) - @unlink( $this->tmpfile() ); - - $db = db_connection(); - - $sql = new Sql( 'UPDATE {t_file}'. - ' SET value={value}, '. - ' size={size} '. - ' WHERE objectid={objectid}' ); - $sql->setString( 'objectid' ,$this->objectid ); - $sql->setInt ( 'size' ,strlen($this->value) ); - - if ( $this->storeValueAsBase64 ) - $sql->setString( 'value',base64_encode($this->value) ); - else - $sql->setString( 'value',$this->value ); - - $db->query( $sql ); - } - - - /** - * Lesen der Datei aus der Datenbank und schreiben in temporaere Datei - */ - function write() - { - if ( !is_file($this->tmpfile()) ) - $this->loadValue(); - } - - - /** - * F�gt die Datei der Datenbank hinzu. - */ - function add() - { - $db = db_connection(); - - $this->objectAdd(); - - $sql = new Sql('SELECT MAX(id) FROM {t_file}'); - $this->fileid = intval($db->getOne($sql))+1; - - $sql = new Sql('INSERT INTO {t_file}'. - ' (id,objectid,extension,size,value)'. - " VALUES( {fileid},{objectid},{extension},0,'' )" ); - $sql->setInt ('fileid' ,$this->fileid ); - $sql->setInt ('objectid' ,$this->objectid ); - $sql->setString('extension',$this->extension ); - - $db->query( $sql ); - - $this->saveValue(); - } - - - function publish() - { - if ( ! is_object($this->publish) ) - $this->publish = new Publish(); - - $this->write(); - $this->publish->copy( $this->tmpfile(),$this->full_filename(),$this->lastchangeDate ); - - $this->publish->publishedObjects[] = $this->getProperties(); - } - - - /** - * Ermittelt einen tempor�ren Dateinamen f�r diese Datei. - */ - function tmpfile() - { - if ( $this->tmpfile == '' ) - { - $db = db_connection(); - $this->tmpfile = $this->getTempDir().'/openrat_db'.$db->id.'_'.$this->objectid.'.tmp'; - } - return $this->tmpfile; - } - - - /** - * Setzt den Zeitstempel der Datei auf die aktuelle Zeit. - * - * @see objectClasses/Object#setTimestamp() - */ - - function setTimestamp() - { - @unlink( $this->tmpfile() ); - - parent::setTimestamp(); - } - - - - /** - * Ermittelt die wirksame Datei-Endung. Diese kann sich - * in der Extra-Dateiendung, aber auch direkt im Dateiname - * befinden. - * - * @return Dateiendung - */ - function getRealExtension() - { - if ( !empty($this->extension)) - { - return $this->extension; - } - else - { - $pos = strrpos($this->filename,'.'); - if ( $pos === false ) - return ''; - else - return substr($this->filename,$pos+1); - } - } -} - -?>- \ No newline at end of file diff --git a/objectClasses/Folder.class.php b/objectClasses/Folder.class.php @@ -1,826 +0,0 @@ -<?php -// OpenRat Content Management System -// Copyright (C) 2002-2010 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. - - -/** - * Darstellen eines Ordners - * - * @version $Revision$ - * @author $Author$ - * @package openrat.objects - */ -class Folder extends Object -{ - var $folderid; - var $projectid; - var $parentfolders = array(); - var $subfolders = array(); - var $filenames = true; - var $name = ''; - var $filename = ''; - var $desc = ''; - var $publish = null; - - - function Folder( $objectid='' ) - { - $this->Object( $objectid ); - $this->isFolder = true; - } - - - function add() - { - $this->objectAdd(); - - $db = db_connection(); - - $sql = new Sql('SELECT MAX(id) FROM {t_folder}'); - $this->folderid = intval($db->getOne($sql))+1; - - $sql = new Sql('INSERT INTO {t_folder}'. - ' (id,objectid)'. - ' VALUES( {folderid},{objectid} )' ); - $sql->setInt ('folderid' ,$this->folderid ); - $sql->setInt ('objectid' ,$this->objectid ); - - $db->query( $sql ); - } - - - - function getRootFolderId() - { - global $SESS; - $db = db_connection(); - - $sql = new SQL('SELECT id FROM {t_object}'. - ' WHERE parentid IS NULL'. - ' AND is_folder=1'. - ' AND projectid={projectid}' ); - - // Wenn Methode statisch aufgerufen wird, ist $this nicht vorhanden - if ( isset($this) && isset($this->projectid) ) - { - $sql->setInt('projectid',$this->projectid ); - } - else - { - $project = Session::getProject(); - $sql->setInt('projectid',$project->projectid ); - } - - // Datenbankabfrage ausfuehren - return $db->getOne( $sql ); - } - - - function hasFilename( $filename ) - { - $db = db_connection(); - - $sql = new Sql('SELECT COUNT(*) FROM {t_object}'.' WHERE parentid={objectid} AND filename={filename}'); - - if ( intval($this->objectid)== 0 ) - $sql->setNull('objectid'); - else - $sql->setString('objectid', $this->objectid); - - $sql->setString('filename', $filename ); - - return( $db->getOne($sql) > 0 ); - } - - - function load() - { -// $db = db_connection(); -// -// $sql = new Sql('SELECT * FROM {t_folder} WHERE objectid={objectid}'); -// $sql->setInt('objectid',$this->objectid); -// -// $row = $db->getRow( $sql ); -// - $this->objectLoad(); - -// $this->folderid = $row['id' ]; - } - - - - function save() - { - $this->objectSave(); - } - - - - function setOrderId( $orderid ) - { - $db = db_connection(); - - $sql = new Sql('UPDATE {t_folder} '. - ' SET orderid={orderid}'. - ' WHERE id={folderid}'); - $sql->setInt('folderid',$this->folderid); - $sql->setInt('orderid' ,$orderid ); - - $db->query( $sql ); - } - - - -// function getSubFolders() -// { -// global $SESS; -// $db = db_connection(); -// -// $sql = new Sql('SELECT id FROM {t_folder}'. -// ' WHERE parentid={folderid}'. -// ' AND projectid={projectid}'. -// ' ORDER BY orderid ASC' ); -// $sql->setInt('folderid' ,$SESS['folderid' ]); -// $sql->setInt('projectid',$SESS['projectid']); -// -// return( $db->getCol( $sql )); -// } - - - // Liest alle Objekte in diesem Ordner - function getObjectIds() - { - $db = db_connection(); - - $sql = new Sql('SELECT id FROM {t_object}'. - ' WHERE parentid={objectid}'. - ' ORDER BY orderid ASC' ); - $sql->setInt('objectid' ,$this->objectid ); - - return( $db->getCol( $sql ) ); - } - - - - /** - * Liest alle Objekte in diesem Ordner - * @return Array von Objekten - */ - function getObjects() - { - $db = db_connection(); - - $sql = new Sql('SELECT {t_object}.*,{t_name}.name,{t_name}.descr'. - ' FROM {t_object}'. - ' LEFT JOIN {t_name} '. - ' ON {t_object}.id={t_name}.objectid AND {t_name}.languageid={languageid} '. - ' WHERE parentid={objectid}'. - ' ORDER BY orderid ASC' ); - $sql->setInt('languageid',$this->languageid ); - $sql->setInt('objectid' ,$this->objectid ); - - $liste = array(); - $res = $db->getAll( $sql ); - foreach( $res as $row ) - { - $o = new Object( $row['id'] ); - $o->setDatabaseRow( $row ); - $liste[] = $o; - } - - return $liste; - } - - - // Liest alle Objekte in diesem Ordner - function getObjectIdsByType() - { - $db = db_connection(); - - $sql = new Sql('SELECT id FROM {t_object}'. - ' WHERE parentid={objectid}'. - ' ORDER BY is_link,is_page,is_file,is_folder,orderid ASC' ); - $sql->setInt('projectid',$this->projectid ); - $sql->setInt('objectid' ,$this->objectid ); - - return( $db->getCol( $sql ) ); - } - - - // Liest alle Objekte in diesem Ordner sortiert nach dem Namen (nicht Dateinamen!) - function getObjectIdsByName() - { - $db = db_connection(); - - $sql = new Sql('SELECT {t_object}.id FROM {t_object}'. - ' LEFT JOIN {t_name} ON {t_object}.id={t_name}.objectid AND {t_name}.languageid={languageid} '. - ' WHERE parentid={objectid}'. - ' ORDER BY {t_name}.name,{t_object}.filename ASC'); - $sql->setInt('objectid' , $this->objectid ); - $sql->setInt('languageid', $this->languageid); - return( $db->getCol( $sql ) ); - } - - - // Liest alle Objekte in diesem Ordner - function getObjectIdsByLastChange() - { - $db = db_connection(); - - $sql = new Sql('SELECT id FROM {t_object}'. - ' WHERE parentid={objectid}'. - ' ORDER BY lastchange_date,orderid ASC' ); - $sql->setInt('projectid',$this->projectid ); - $sql->setInt('objectid' ,$this->objectid ); - - return( $db->getCol( $sql ) ); - } - - - function publish( $withPages,$withFiles,$subdirs = false ) - { - if ( ! is_object($this->publish) ) - $this->publish = new Publish(); - - foreach( $this->getObjectIds() as $oid ) - { - $o = new Object( $oid ); - $o->objectLoadRaw(); - - if ( $o->isPage && $withPages ) - { - $p = new Page( $oid ); - $p->load(); - $p->publish = &$this->publish; - $p->publish(); - } - - if ( $o->isFile && $withFiles ) - { - $f = new File( $oid ); - $f->load(); - $f->publish = &$this->publish; - $f->publish(); - } - - if ( $o->isFolder && $subdirs ) - { - $f = new Folder( $oid ); - $f->load(); - $f->publish = &$this->publish; - $f->publish( $withPages,$withFiles,true ); - } - } - } - - - function getObjectIdByFileName( $filename ) - { - $db = db_connection(); - - $sql = new Sql('SELECT id FROM {t_object}'. - ' WHERE parentid={objectid}'. - ' AND filename={filename}' ); - $sql->setInt ('objectid' ,$this->objectid ); - $sql->setString('filename' ,$filename ); - - return( intval($db->getOne( $sql )) ); - } - - - - /** - * Ermittelt alle Objekte vom gewnschten Typ, die sic in - * diesem Projekt befinden. - * - * @see objectClasses/Object#getAllObjectIds() - * @param types Array - * @return Liste von Object-Ids - */ - function getAllObjectIds( $types=array('folder','page','link','file') ) - { -// Html::debug($types,'Typen'); - global $SESS; - $db = db_connection(); - - $sql = new Sql('SELECT id FROM {t_object}'. - ' WHERE projectid={projectid}'. - ' AND ( is_folder={is_folder}' . - ' OR is_file ={is_file}' . - ' OR is_page ={is_page}' . - ' OR is_link ={is_link} )' . - ' ORDER BY orderid ASC' ); - - if (isset($this->projectid)) - { - $projectid = $this->projectid; - } - else - { - $project = Session::getProject(); - $projectid = $project->projectid; - } - - $sql->setInt('projectid',$projectid); - $sql->setInt('is_folder',in_array('folder',$types)?1:2); - $sql->setInt('is_file' ,in_array('file' ,$types)?1:2); - $sql->setInt('is_page' ,in_array('page' ,$types)?1:2); - $sql->setInt('is_link' ,in_array('link' ,$types)?1:2); - - return( $db->getCol( $sql ) ); - } - - - function dgetRootObjectId() - { - global $SESS; - $db = db_connection(); - - $sql = new Sql('SELECT id FROM {t_object}'. - ' WHERE parentid IS NULL'. - ' AND projectid={projectid}' ); - - if ( isset($this->projectid) ) - $sql->setInt('projectid',$this->projectid ); - else $sql->setInt('projectid',$SESS['projectid'] ); - - return( $db->getOne( $sql ) ); - } - - - function getOtherFolders() - { - global $SESS; - $db = db_connection(); - - $sql = new Sql('SELECT id FROM {t_object}'. - ' WHERE is_folder=1'. - ' and id != {objectid} '. - ' AND projectid={projectid}' ); - $sql->setInt( 'projectid',$this->projectid ); - $sql->setInt( 'objectid' ,$this->objectid ); - - return( $db->getCol( $sql ) ); - } - - - function getAllFolders() - { - global $SESS; - $db = db_connection(); - - $sql = new Sql('SELECT id FROM {t_object}'. - ' WHERE is_folder=1'. - ' AND projectid={projectid}' ); - - if ( !isset($this->projectid) ) - { - $project = Session::getProject(); - $sql->setInt('projectid',$project->projectid); - } - else $sql->setInt( 'projectid',$this->projectid ); - - return( $db->getCol( $sql ) ); - } - - - function getPages() - { - $db = db_connection(); - - $sql = new Sql('SELECT id FROM {t_object} '. - ' WHERE parentid={objectid} AND is_page=1'. - ' ORDER BY orderid ASC' ); - $sql->setInt( 'objectid' ,$this->objectid ); - - return $db->getCol( $sql ); - } - - - /** - * Ermittelt die erste Seite oder Verkn�pfung in diesem Ordner. - * - * @return Object Objekt - */ - function getFirstPageOrLink() - { - $db = db_connection(); - - $sql = new Sql('SELECT id FROM {t_object} '. - ' WHERE parentid={objectid}'. - ' AND (is_page=1 OR is_link=1)'. - ' ORDER BY orderid ASC' ); - $sql->setInt( 'objectid' ,$this->objectid ); - - $oid = intval($db->getOne( $sql )); - - if ( $oid != 0 ) - $o = new Object($oid); - else - $o = null; - - return $o; - } - - - function getLastPageOrLink() - { - $db = db_connection(); - - $sql = new Sql('SELECT id FROM {t_object} '. - ' WHERE parentid={objectid}'. - ' AND (is_page=1 OR is_link=1)'. - ' ORDER BY orderid DESC' ); - $sql->setInt( 'objectid' ,$this->objectid ); - - $oid = intval($db->getOne( $sql )); - - if ( $oid != 0 ) - $o = new Object($oid); - else - $o = null; - - return $o; - } - - - function getFiles() - { - $db = db_connection(); - - $sql = new Sql('SELECT id FROM {t_object} '. - ' WHERE parentid={objectid} AND is_file=1'. - ' ORDER BY orderid ASC' ); - $sql->setInt( 'objectid' ,$this->objectid ); - - return $db->getCol( $sql ); - } - - - - /** - * Liefert eine Liste von allen Dateien in diesem Ordner. - * - * @return Array Schl�ssel=Objekt-Id, Wert=Dateiname - */ - function getFileFilenames() - { - $db = db_connection(); - - $sql = new Sql('SELECT id,filename FROM {t_object} '. - ' WHERE parentid={objectid} AND is_file=1'. - ' ORDER BY orderid ASC' ); - $sql->setInt( 'objectid' ,$this->objectid ); - - return $db->getAssoc( $sql ); - } - - - function getLinks() - { - $db = db_connection(); - - $sql = new Sql('SELECT id FROM {t_object} '. - ' WHERE parentid={objectid} AND is_link=1'. - ' ORDER BY orderid ASC' ); - $sql->setInt( 'objectid' ,$this->objectid ); - - return $db->getCol( $sql ); - } - - - // Rechte f?r diesen Ordner hinzuf?gen - function addrights( $rights,$inherit = true ) - { - global $SESS; - - $SESS['rights'][$rights['projectid']][$this->folderid]['show'] = true; - - if ($rights['read'] == '1') - $SESS['rights'][$rights['projectid']][$this->folderid]['read'] = 1; - if ($rights['write'] == '1') - $SESS['rights'][$rights['projectid']][$this->folderid]['write'] = 1; - if ($rights['create'] == '1') - $SESS['rights'][$rights['projectid']][$this->folderid]['create'] = 1; - if ($rights['delete'] == '1') - $SESS['rights'][$rights['projectid']][$this->folderid]['delete'] = 1; - if ($rights['publish'] == '1') - $SESS['rights'][$rights['projectid']][$this->folderid]['publish'] = 1; - - // Rechte auf Unterordner vererben - // sowie f?r ?bergeordnete Ordner die Anzeige erzwingen - if ( $inherit ) - { - // ?bergeordnete Ordner ermitteln - $parentfolder = $this->parentObjectFileNames(); - - // ?bergeordnete Ordner immer anzeigen (Schalter 'show'=true) - foreach( $parentfolder as $folderid=>$name ) - { - $f = new Folder( $folderid ); - $f->projectid = $this->projectid; - $f->addrights( array('projectid'=>$rights['projectid']),false ); - unset($f); - } - - $f = new Folder( 'null' ); - $f->projectid = $this->projectid; - $f->addrights( array('projectid'=>$rights['projectid']),false ); - unset($f); - - - // Unterordner ermitteln - //echo "Kurz vor subfolderberechnung, folderid ist ".$this->folderid.'<br>'; - $subfolder = $this->subfolder(); - - // Rechte weitergeben - foreach( $subfolder as $folderid=>$name ) - { - $f = new Folder( $folderid ); - $f->projectid = $this->projectid; - $f->addrights( $rights,false ); - unset($f); - } - } - } - - - function addParentFolder( $id,$name,$filename='' ) - { - if ( empty($name) ) - $name = $filename; - - if ( empty($name) ) - $name = "($id)"; - - if ( intval($id) != 0 ) - $this->parentfolders[ $id ] = $name; - } - - - function checkParentFolders( $with_root, $with_self ) - { - // Reihenfolge umdrehen - $this->parentfolders = array_reverse($this->parentfolders,true); - - // Ordner ist bereits hoechster Ordner -// if ( count($this->parentfolders) == 2 && $this->isRoot && $with_root && $with_self ) -// { -// array_pop ( $this->parentfolders ); -// return; -// } - - - if ( !$with_root ) - { - $keys = array_keys( $this->parentfolders ); - unset( $this->parentfolders[$keys[0]] ); - } - - if ( !$with_self ) - { - $keys = array_keys( $this->parentfolders ); - unset( $this->parentfolders[$keys[count($keys)-1]] ); - } - } - - - function parentObjectFileNames( $with_root = false, $with_self = false ) - { - $db = Session::getDatabase(); - - $foid = $this->id; - $idCache = array(); - - while( intval($foid)!=0 ) - { - $sql = new Sql( <<<SQL - -SELECT parentid,id,filename - FROM {t_object} - WHERE {t_object}.id={parentid} - -SQL - ); - $sql->setInt('parentid' ,$foid ); - - $row = $db->getRow( $sql ); - - if ( in_array($row['id'],$idCache)) - Http::serverError('fatal: parent-rekursion in object-id: '.$this->objectid.', double-parent-id: '.$row['id']); - else - $idCache[] = $row['id']; - - $this->addParentfolder( $row['id'],$row['filename'] ); - $foid = $row['parentid']; - } - - - $this->checkParentFolders($with_root,$with_self); - - return $this->parentfolders; - } - - function parentObjectNames( $with_root = false, $with_self = false ) - { - $db = Session::getDatabase(); - - $foid = $this->id; - $idCache = array(); - - while( intval($foid)!=0 ) - { - $sql = new Sql( <<<SQL - -SELECT {t_object}.parentid,{t_object}.id,{t_object}.filename,{t_name}.name FROM {t_object} - LEFT JOIN {t_name} - ON {t_object}.id = {t_name}.objectid - AND {t_name}.languageid = {languageid} - WHERE {t_object}.id={parentid} - -SQL - ); - $sql->setInt('languageid',$this->languageid); - $sql->setInt('parentid' ,$foid ); - - $row = $db->getRow( $sql ); - - if ( in_array($row['id'],$idCache)) - Http::serverError('fatal: parent-rekursion in object-id: '.$this->objectid.', double-parent-id: '.$row['id']); - else - $idCache[] = $row['id']; - - $this->addParentfolder( $row['id'],$row['name'],$row['filename'] ); - $foid = $row['parentid']; - } - - $this->checkParentFolders($with_root,$with_self); - - return $this->parentfolders; - } - - - // Ermitteln aller Unterordner - // - function subfolder() - { - $db = db_connection(); - - $sql = new Sql('SELECT id FROM {t_object} '. - ' WHERE parentid={objectid} AND is_folder=1'. - ' ORDER BY orderid ASC' ); - $sql->setInt( 'objectid' ,$this->objectid ); - - $this->subfolders = $db->getCol( $sql ); - - return $this->subfolders; - } - - - - function getSubfolderFilenames() - { - $db = db_connection(); - - $sql = new Sql('SELECT id,filename FROM {t_object} '. - ' WHERE parentid={objectid} AND is_folder=1'. - ' ORDER BY orderid ASC' ); - $sql->setInt( 'objectid' ,$this->objectid ); - - return $db->getAssoc( $sql ); - } - - - // Ermitteln aller Unterordner (rekursives Absteigen) - // - function getAllSubFolderIds() - { - global $SESS; - - $ids = array(); - - foreach( $this->getSubFolderIds() as $id ) - { -// echo "durchlaufe $id"; - $ids[] = $id; - - $f = new Folder( $id ); - if ( !empty($this->projectid) ) - $f->projectid = $this->projectid; - - foreach( $f->getAllSubFolderIds() as $xid ) - { - $ids[] = $xid; - } - } - -// print_r( $ids ); - return $ids; - } - - - /** - * Loeschen dieses Ordners. - * Der Ordner wird nur geloescht, wenn er keine Unterelemente mehr enth?lt. - * Zum Loeschen inklusive Unterelemente dient die Methode deleteAll() - */ - function delete() - { - $db = db_connection(); - - // Nur loeschen, wenn es keine Unterelemente gibt - if ( count( $this->getObjectIds() ) == 0 ) - { - $sql = new Sql( 'UPDATE {t_element} '. - ' SET folderobjectid=NULL '. - ' WHERE folderobjectid={objectid}' ); - $sql->setInt('objectid',$this->objectid); - $db->query( $sql ); - - $sql = new Sql( 'DELETE FROM {t_folder} '. - ' WHERE objectid={objectid}' ); - $sql->setInt('objectid',$this->objectid); - $db->query( $sql ); - - $this->objectDelete(); - } - } - - - /** - * Rekursives loeschen aller Inhalte - * - * Loeschen aller Inhalte dieses Ordners - * inclusive aller Unterelemente - */ - function deleteAll() - { - $db = db_connection(); - - // L?schen aller Unterordner - foreach( $this->subfolder() as $folderid ) - { - $folder = new Folder( $folderid ); - { - $folder->deleteAll(); - } - } - - // L?schen aller Seiten,Verknuepfungen und Dateien in - // diesem Ordner - foreach( $this->getObjectIds() as $oid ) - { - $object = new Object( $oid ); - { - $object->load(); - - if ( $object->isPage ) - { - $page = new Page( $oid ); - $page->load(); - $page->delete(); - } - - if ( $object->isLink ) - { - $link = new Link( $oid ); - $link->load(); - $link->delete(); - } - - if ( $object->isFile ) - { - $file = new File( $oid ); - $file->load(); - $file->delete(); - } - } - } - - // Zum Abschluss den aktuellen Ordner loeschen - $this->delete(); - } - - - function getSubFolderIds() - { - return $this->subfolder(); - } -} - - -?>- \ No newline at end of file diff --git a/objectClasses/Group.class.php b/objectClasses/Group.class.php @@ -1,354 +0,0 @@ -<?php -// OpenRat Content Management System -// Copyright (C) 2002-2010 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. - - - -/** - * Darstellen einer Benutzergruppe. Eine Gruppe enthaelt beliebig viele Benutzer - * - * @version $Revision$ - * @author $Author$ - * @package openrat.objects - */ -class Group -{ - var $groupid = 0; - var $error = ''; - - var $name = ''; - var $fullname = ''; - var $ldap_dn; - var $tel; - var $mail; - var $desc; - var $style; - var $isAdmin; - - - // Konstruktor - function Group( $groupid='' ) - { - if ( is_numeric($groupid) ) - $this->groupid = $groupid; - } - - - // Lesen aller Gruppen aus der Datenbank - function getAll() - { - global $conf; - $db = db_connection(); - - $sql = new Sql( 'SELECT id,name FROM {t_group}' ); - - return $db->getAssoc( $sql ); - } - - - // Lesen Benutzer aus der Datenbank - function load() - { - $db = db_connection(); - - $sql = new Sql( 'SELECT * FROM {t_group}'. - ' WHERE id={groupid}' ); - $sql->setInt( 'groupid',$this->groupid ); - - $row = $db->getRow( $sql ); - if ( count($row) > 0 ) - $this->name = $row['name' ]; - else - $this->name = ''; - } - - - // Speichern Benutzer in der Datenbank - function save() - { - if ( empty($this->name) ) - $this->name = lang('GLOBAL_GROUP').' '.$this->groupid; - - $db = db_connection(); - - // Gruppe speichern - $sql = new Sql( 'UPDATE {t_group} '. - 'SET name = {name} '. - 'WHERE id={groupid}' ); - $sql->setString( 'name' ,$this->name ); - $sql->setInt ('groupid',$this->groupid ); - - // Datenbankabfrage ausfuehren - $db->query( $sql ); - } - - - /** - * Rueckgabe aller Eigenschaften - * @return Array - */ - function getProperties() - { - return Array( 'name' =>$this->name, - 'groupid'=>$this->groupid ); - } - - - // Gruppe hinzufuegen - function add( $name = '' ) - { - $db = db_connection(); - - if ( $name != '' ) - $this->name = $name; - - $sql = new Sql('SELECT MAX(id) FROM {t_group}'); - $this->groupid = intval($db->getOne($sql))+1; - - // Gruppe hinzuf?gen - $sql = new Sql( 'INSERT INTO {t_group} '. - '(id,name) VALUES( {groupid},{name} )'); - $sql->setInt ('groupid',$this->groupid ); - $sql->setString('name' ,$this->name ); - - // Datenbankbefehl ausfuehren - $db->query( $sql ); - } - - - // Gruppe entfernen - function delete() - { - $db = db_connection(); - - // Berechtigungen zu dieser Gruppe loeschen - $sql = new Sql( 'DELETE FROM {t_acl} '. - 'WHERE groupid={groupid}' ); - $sql->setInt ('groupid',$this->groupid ); - $db->query( $sql ); - - - // Alle Gruppenzugehoerigkeiten zu dieser Gruppe loeschen - $sql = new Sql( 'DELETE FROM {t_usergroup} '. - 'WHERE groupid={groupid}' ); - $sql->setInt ('groupid',$this->groupid ); - $db->query($sql); - - // Gruppe loeschen - $sql = new Sql( 'DELETE FROM {t_group} '. - 'WHERE id={groupid}' ); - $sql->setInt ('groupid',$this->groupid ); - $db->query($sql); - } - - - // Benutzer ermitteln, die Mitglied dieser Gruppe sind - function getUsers() - { - $db = db_connection(); - - $sql = new Sql( 'SELECT {t_user}.id,{t_user}.name FROM {t_user} '. - 'LEFT JOIN {t_usergroup} ON {t_usergroup}.userid={t_user}.id '. - 'WHERE {t_usergroup}.groupid={groupid}' ); - $sql->setInt('groupid',$this->groupid ); - - return $db->getAssoc( $sql ); - } - - - // Benutzer ermitteln, die *nicht* Mitglied dieser Gruppe sind - function getOtherUsers() - { - $db = db_connection(); - - $sql = new Sql( 'SELECT {t_user}.id,{t_user}.name FROM {t_user}'. - ' LEFT JOIN {t_usergroup} ON {t_usergroup}.userid={t_user}.id AND {t_usergroup}.groupid={groupid}'. - ' WHERE {t_usergroup}.groupid IS NULL' ); - $sql->setInt('groupid' ,$this->groupid ); - - return $db->getAssoc( $sql ); - } - - - // Benutzer einer Gruppe hinzufuegen - function addUser( $userid ) - { - $db = db_connection(); - - $sql = new Sql('SELECT MAX(id) FROM {t_usergroup}'); - $usergroupid = intval($db->getOne($sql))+1; - - $sql = new Sql( 'INSERT INTO {t_usergroup} '. - ' (id,userid,groupid) '. - ' VALUES( {usergroupid},{userid},{groupid} )' ); - $sql->setInt('usergroupid',$usergroupid ); - $sql->setInt('userid' ,$userid ); - $sql->setInt('groupid' ,$this->groupid ); - - $db->query( $sql ); - - } - - - // Benutzer aus Gruppe entfernen - function delUser( $userid ) - { - $db = db_connection(); - - $sql = new Sql( 'DELETE FROM {t_usergroup} '. - ' WHERE userid={userid} AND groupid={groupid}' ); - $sql->setInt ('userid' ,$userid ); - $sql->setInt ('groupid' ,$this->groupid ); - - $db->query( $sql ); - } - - - // Alle Berechtigungen ermitteln - function getRights() - { - global $SESS,$conf_php; - $db = db_connection(); - $var = array(); - - // Alle Projekte lesen - $sql = new Sql( 'SELECT id,name FROM {t_project}' ); - $projects = $db->getAssoc( $sql ); - - foreach( $projects as $projectid=>$projectname ) - { - $var[$projectid] = array(); - $var[$projectid]['name'] = $projectname; - $var[$projectid]['folders'] = array(); - $var[$projectid]['rights'] = array(); - - $sql = new Sql( 'SELECT {t_acl}.* FROM {t_acl}'. - ' LEFT JOIN {t_folder} ON {t_acl}.folderid = {t_folder}.id'. - ' WHERE {t_folder}.projectid={projectid}'. - ' AND {t_acl}.groupid={groupid}' ); - $sql->setInt('projectid',$projectid ); - $sql->setInt('groupid' ,$this->groupid ); - - $acls = $db->getAll( $sql ); - - foreach( $acls as $acl ) - { - $aclid = $acl['id']; - $folder = new Folder( $acl['folderid'] ); - $folder->load(); - $var[$projectid]['rights'][$aclid] = $acl; - $var[$projectid]['rights'][$aclid]['foldername'] = implode(' &raquo; ',$folder->parentfolder( false,true )); - $var[$projectid]['rights'][$aclid]['delete_url'] = 'user.'.$conf_php.'?useraction=delright&aclid='.$aclid; - } - - $sql = new Sql( 'SELECT id FROM {t_folder}'. - ' WHERE projectid={projectid}' ); - $sql->setInt('projectid',$projectid); - $folders = $db->getCol( $sql ); - - $var[$projectid]['folders'] = array(); - - foreach( $folders as $folderid ) - { - $folder = new Folder( $folderid ); - $folder->load(); - $var[$projectid]['folders'][$folderid] = implode(' &raquo; ',$folder->parentfolder( false,true )); - } - - asort( $var[$projectid]['folders'] ); - } - - return $var; - } - - - // Berechtigung der Gruppe hinzufuegen - function addRight( $data ) - { - global $REQ,$SESS; - $db = db_connection(); - - $sql = new SQL('INSERT INTO {t_acl} '. - '(userid,groupid,folderid,`read`,`write`,`create`,`delete`,publish) '. - 'VALUES({userid},{groupid},{folderid},{read},{write},{create},{delete},{publish})'); - - $sql->setNull('userid'); - $sql->setInt ('groupid',$this->groupid); - $sql->setInt ('projectid',$SESS['projectid']); - $sql->setInt ('folderid',$data['folderid']); - - $sql->setInt ('read' ,$data['read' ]); - $sql->setInt ('write' ,$data['write' ]); - $sql->setInt ('create' ,$data['create' ]); - $sql->setInt ('delete' ,$data['delete' ]); - $sql->setInt ('publish',$data['publish']); - - // Datenbankabfrage ausf?hren - $db->query( $sql ); - } - - - - /** - * Ermitteln aller Berechtigungen dieser Gruppe.<br> - * Diese Daten werden auf der Gruppenseite in der Administration angezeigt. - * - * @return unknown - */ - function getAllAcls() - { - $db = db_connection(); - $sql = new Sql( 'SELECT {t_acl}.*,{t_object}.projectid,{t_language}.name AS languagename FROM {t_acl}'. - ' LEFT JOIN {t_object} '. - ' ON {t_object}.id={t_acl}.objectid '. - ' LEFT JOIN {t_language} '. - ' ON {t_language}.id={t_acl}.languageid '. - ' WHERE ( {t_acl}.groupid={groupid} OR ({t_acl}.userid IS NULL AND {t_acl}.groupid IS NULL) )'. - ' ORDER BY {t_object}.projectid,{t_acl}.languageid' ); - $sql->setInt ( 'groupid' ,$this->groupid ); - - $aclList = array(); - - foreach( $db->getAll( $sql ) as $row ) - { - $acl = new Acl(); - $acl->setDatabaseRow( $row ); - $acl->projectid = $row['projectid' ]; - if ( intval($acl->languageid) == 0 ) - $acl->languagename = lang('GLOBAL_ALL_LANGUAGES'); - else - $acl->languagename = $row['languagename']; - $aclList[] = $acl; - } - - return $aclList; - } - - - - // Berechtigung entfernen - function delRight( $aclid ) - { - $sql = new SQL('DELETE FROM {t_acl} WHERE id={aclid}'); - $sql->setInt( 'aclid',$aclid ); - - // Datenbankabfrage ausf?hren - $db->query( $sql ); - } -} - -?>- \ No newline at end of file diff --git a/objectClasses/Language.class.php b/objectClasses/Language.class.php @@ -1,286 +0,0 @@ -<?php -// OpenRat Content Management System -// Copyright (C) 2002-2010 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. - - -/** - * Darstellen einer Sprache. Jeder Seiteninhalt wird einer Sprache zugeordnet. - * - * @version $Revision$ - * @author $Author$ - * @package openrat.objects - */ -class Language -{ - var $languageid = 0; - var $error = ''; - var $projectid; - - var $name = ''; - var $isoCode = ''; - var $isDefault = false; - - - // Konstruktor - function Language( $languageid='' ) - { - global $SESS; - - if ( is_numeric($languageid) ) - $this->languageid = $languageid; - -// $this->projectid = $SESS['projectid']; - } - - - - /** - * Stellt fest, ob die angegebene Id existiert. - */ - function available( $id ) - { - $db = db_connection(); - - $sql = new Sql('SELECT 1 FROM {t_language} '. - ' WHERE id={id}'); - $sql->setInt('id' ,$id ); - - return intval($db->getOne($sql)) == 1; - } - - - - // Lesen aller Sprachen aus der Datenbank - function getAll() - { - global $SESS; - $db = db_connection(); - - $sql = new Sql( "SELECT id,name FROM {t_language} ". - " WHERE projectid = {projectid} ". - " ORDER BY name" ); - - if ( !empty($this->projectid) ) - $sql->setInt('projectid',$this->projectid ); - else - { - $project = Session::getProject(); - $sql->setInt('projectid',$project->projectid); - } - - return $db->getAssoc( $sql ); - } - - - /** - * Ermittelt die Anzahl aller Sprachen zum aktuellen Projekt. - */ - function count() - { - global $SESS; - $db = db_connection(); - - $sql = new Sql( <<<SQL - SELECT count(*) FROM {t_language} - WHERE projectid = {projectid} -SQL -); - - if ( !empty($this->projectid) ) - $sql->setInt('projectid',$this->projectid ); - else - { - $project = Session::getProject(); - $sql->setInt('projectid',$project->projectid); - } - - return $db->getOne( $sql ); - } - - - // Lesen aus der Datenbank - function load() - { - $db = Session::getDatabase(); - - $sql = new Sql( 'SELECT * FROM {t_language}'. - ' WHERE id={languageid}' ); - $sql->setInt( 'languageid',$this->languageid ); - - $row = $db->getRow( $sql ); - - if ( count($row) > 0 ) - { - $this->name = $row['name' ]; - $this->isoCode = $row['isocode' ]; - $this->projectid = intval( $row['projectid'] ); - - $this->isDefault = ( $row['is_default'] == '1' ); - } - } - - - // Speichern der Sprache in der Datenbank - function save() - { - $db = db_connection(); - - // Gruppe speichern - $sql = new Sql( 'UPDATE {t_language} '. - 'SET name = {name}, '. - ' isocode = {isocode} '. - 'WHERE id={languageid}' ); - $sql->setString( 'name' ,$this->name ); - $sql->setString( 'isocode' ,$this->isoCode ); - - $sql->setInt( 'languageid',$this->languageid ); - - // Datenbankabfrage ausfuehren - $db->query( $sql ); - } - - - /** - * Ermitteln aller Eigenschaften dieser Sprache - * @return Array - */ - function getProperties() - { - return Array( 'name' =>$this->name, - 'isocode'=>$this->isoCode ); - } - - - /** - * Neue Sprache hinzuf?gen - */ - function add( $isocode='' ) - { - global $SESS; - global $iso; - $db = db_connection(); - - if ( $isocode != '' ) - { - // Kleiner Trick, damit "no" (Norwegen) in der .ini-Datei stehen kann - $isocode = str_replace('_','',$isocode); - - $this->isocode = $isocode; - $codes = GlobalFunctions::getIsoCodes(); - $this->name = $codes[ $isocode ]; - } - - $sql = new Sql('SELECT MAX(id) FROM {t_language}'); - $this->languageid = intval($db->getOne($sql))+1; - - // Sprache hinzuf?gen - $sql = new Sql( 'INSERT INTO {t_language} '. - '(id,projectid,name,isocode,is_default) VALUES( {languageid},{projectid},{name},{isocode},0 )'); - $sql->setInt ('languageid',$this->languageid ); - $sql->setInt ('projectid' ,$this->projectid ); - $sql->setString('name' ,$this->name ); - $sql->setString('isocode' ,$this->isoCode ); - - // Datenbankbefehl ausfuehren - $db->query( $sql ); - } - - - // Diese Sprache als 'default' markieren. - function setDefault() - { - global $SESS; - $db = db_connection(); - - // Zuerst alle auf nicht-Standard setzen - $sql = new Sql( 'UPDATE {t_language} '. - ' SET is_default = 0 '. - ' WHERE projectid={projectid}' ); - $sql->setInt('projectid',$this->projectid ); - $db->query( $sql ); - - // Jetzt die gew?nschte Sprachvariante auf Standard setzen - $sql = new Sql( 'UPDATE {t_language} '. - ' SET is_default = 1 '. - ' WHERE id={languageid}' ); - $sql->setInt('languageid',$this->languageid ); - $db->query( $sql ); - } - - - function getDefaultId() - { - global $SESS; - $db = db_connection(); - - $sql = new Sql( 'SELECT id FROM {t_language} '. - ' WHERE projectid={projectid}'. - ' ORDER BY is_default DESC' ); - - if ( isset($this->projectid) ) - $sql->setInt('projectid',$this->projectid ); - else - { - $project = Session::getProject(); - $sql->setInt('projectid',$project->projectid); - } - - return $db->getOne( $sql ); - } - - - // Sprache entfernen - function delete() - { - $db = db_connection(); - - // Sprache l?schen -// $sql = new Sql( 'SELECT COUNT(*) FROM {t_language} WHERE projectid={projectid}' ); -// $sql->setInt( 'projectid',$this->projectid ); -// $count = $db->getOne( $sql ); -// -// // Nur l?schen, wenn es mindestens 2 Sprachen gibt -// if ( $count >= 2 ) -// { - // Inhalte mit dieser Sprache l?schen - $sql = new Sql( 'DELETE FROM {t_value} WHERE languageid={languageid}' );