Object.class.php

gehe zur Dokumentation dieser Datei
00001 <?php
00002 // ---------------------------------------------------------------------------
00003 // $Id$
00004 // ---------------------------------------------------------------------------
00005 // DaCMS Content Management System
00006 // Copyright (C) 2002 Jan Dankert, jandankert@jandankert.de
00007 //
00008 // This program is free software; you can redistribute it and/or
00009 // modify it under the terms of the GNU General Public License
00010 // as published by the Free Software Foundation; either version 2
00011 // of the License, or (at your option) any later version.
00012 //
00013 // This program is distributed in the hope that it will be useful,
00014 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00015 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00016 // GNU General Public License for more details.
00017 //
00018 // You should have received a copy of the GNU General Public License
00019 // along with this program; if not, write to the Free Software
00020 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
00021 // ---------------------------------------------------------------------------
00022 // $Log$
00023 // Revision 1.32  2009-03-19 04:36:12  dankert
00024 // Beim Anlegen eines Objektes sofort Standard-Rechte vergeben.
00025 //
00026 // Revision 1.31  2009-03-17 01:39:43  dankert
00027 // Funktionsfähigkeit bei enable_cache=false
00028 //
00029 // Revision 1.30  2009-03-17 01:27:28  dankert
00030 // Überarbeitung der temporären Dateinamen.
00031 //
00032 // Revision 1.29  2009-03-02 21:20:02  dankert
00033 // Korrektur in "getTempDir()"
00034 //
00035 // Revision 1.28  2007-12-11 00:22:31  dankert
00036 // Cache von Dateien und Seiten zur Performancesteigerung beim Ver?ffentlichen.
00037 //
00038 // Revision 1.27  2007-12-01 17:49:37  dankert
00039 // Methode "available()" ergibt sofort "false", wenn Objekt-Id ung?ltig (Performance)
00040 //
00041 // Revision 1.26  2007-06-08 23:05:44  dankert
00042 // Als tempor?res Verzeichnis das "upload_tmp_dir" aus der PHP-Konfiguration verwenden.
00043 //
00044 // Revision 1.25  2007-06-04 22:17:51  dankert
00045 // Suchergebnisse absteigend nach ?nderungsdatum sortieren.
00046 //
00047 // Revision 1.24  2007-04-22 00:16:44  dankert
00048 // Fehlermeldung vermeiden, wenn eine Objekt-Id nicht in der Datenbank vorhanden ist.
00049 //
00050 // Revision 1.23  2007-04-08 15:25:35  dankert
00051 // Eigenschaft "type" erg?nzt.
00052 //
00053 // Revision 1.22  2007-04-06 01:38:52  dankert
00054 // Namen nicht speichern, wenn leer.
00055 //
00056 // Revision 1.21  2007/02/14 22:10:57  dankert
00057 // TODO f?r tmpfile-Erzeugung
00058 //
00059 // Revision 1.20  2006/01/29 17:26:55  dankert
00060 // Neben "desc" auch "description" f?llen.
00061 //
00062 // Revision 1.19  2005/11/07 22:36:40  dankert
00063 // Flexibere Ermittlung des Dateinamen anhand neuer Konfigurationseigenschaften.
00064 //
00065 // Revision 1.18  2004/12/27 23:19:47  dankert
00066 // ungueltige Zeichen im Dateinamen mit Punkt ersetzen
00067 //
00068 // Revision 1.17  2004/12/20 23:04:15  dankert
00069 // Korrektur Timestamp setzen
00070 //
00071 // Revision 1.16  2004/12/20 22:42:03  dankert
00072 // Kl. Korrekturen
00073 //
00074 // Revision 1.15  2004/12/20 22:03:45  dankert
00075 // Lesen des Benutzers und speichern als Objekt
00076 //
00077 // Revision 1.14  2004/12/20 20:01:20  dankert
00078 // Benutzen von switch() in filename()
00079 //
00080 // Revision 1.13  2004/12/19 15:23:56  dankert
00081 // Anpassung Session-Funktionen
00082 //
00083 // Revision 1.12  2004/12/15 23:18:09  dankert
00084 // Anpassung an Session-Funktionen
00085 //
00086 // Revision 1.11  2004/11/29 23:54:36  dankert
00087 // Korrektur Vorversion
00088 //
00089 // Revision 1.10  2004/11/29 23:34:39  dankert
00090 // neue Methode setTimestamp()
00091 //
00092 // Revision 1.9  2004/11/29 23:24:36  dankert
00093 // Korrektur Veroeffentlichung
00094 //
00095 // Revision 1.8  2004/11/29 00:02:41  dankert
00096 // Bei L?schen von Objekten alle Referenzen in Tabelle or_link entfernen
00097 //
00098 // Revision 1.7  2004/11/28 22:32:52  dankert
00099 // in getProperties() auch den Typ zurueckgeben
00100 //
00101 // Revision 1.6  2004/11/28 16:56:04  dankert
00102 // in hasRight() auch Abfrage des Parent-Ordners
00103 //
00104 // Revision 1.5  2004/11/24 22:06:24  dankert
00105 // Neu: setDatabaseRow() zur Performancesteigerung
00106 //
00107 // Revision 1.4  2004/11/15 21:34:44  dankert
00108 // Aenderung methode hasRight()
00109 //
00110 // Revision 1.3  2004/11/10 22:46:52  dankert
00111 // Neue Methoden checkFilename(), objectLoadRaw()
00112 //
00113 // Revision 1.2  2004/05/02 14:41:31  dankert
00114 // Einf?gen package-name (@package)
00115 //
00116 // Revision 1.1  2004/04/24 15:15:12  dankert
00117 // Initiale Version
00118 //
00119 // Revision 1.2  2004/03/20 14:15:07  dankert
00120 // Kommentare
00121 //
00122 // Revision 1.1  2004/03/20 01:47:33  dankert
00123 // *** empty log message ***
00124 //
00125 // ---------------------------------------------------------------------------
00126 
00135 class Object
00136 {
00141      var $id;
00142 
00146      var $objectid;
00147 
00153      var $parentid;
00154 
00159      var $filename = '';
00160 
00165      var $name = '';
00166 
00171      var $description = 'none';
00172      var $desc = '';
00173 
00177      var $createDate;
00178 
00182      var $lastchangeDate;
00183 
00187      var $createUser;
00188 
00192      var $lastchangeUser;
00193 
00198      var $isFolder = false;
00199 
00204      var $isFile = false;
00205 
00210      var $isPage = false;
00211 
00216      var $isLink = false;
00217 
00224      var $type = null;
00225      
00229      var $isRoot = false;
00230 
00235      var $languageid;
00236      
00242      var $modelid;
00243      
00249      var $projectid;
00250 
00255      var $tmpfile;
00256 
00257      var $aclMask = null;
00258 
00266      function Object($objectid = '')
00267      {
00268           global $SESS;
00269 
00270           if   ( is_numeric($objectid) )
00271           {
00272                $this->objectid = $objectid;
00273                $this->id       = $objectid;
00274           }
00275 
00276 
00277           $language = Session::getProjectLanguage();
00278           $this->languageid = $language->languageid;
00279 
00280           $model = Session::getProjectModel();
00281           $this->modelid = $model->modelid;
00282 
00283           $project = Session::getProject();
00284           $this->projectid = $project->projectid;
00285      }
00286 
00287 
00292      function getAllObjectIds()
00293      {
00294           global $SESS;
00295           $db = db_connection();
00296 
00297           if   ( ! isset($this->projectid) )
00298           {
00299                $project = Session::getProject();
00300                $projectid = $project->projectid;
00301           }
00302           else
00303           {
00304                $projectid = $this->projectid;
00305           }
00306 
00307           $sql = new Sql('SELECT id from {t_object} '.
00308                          '  WHERE projectid={projectid}');
00309           $sql->setInt('projectid', $projectid);
00310 
00311           return $db->getCol($sql->query);
00312      }
00313 
00314 
00315      // Kompletten Dateinamen des Objektes erzeugen
00316      function full_filename()
00317      {
00318           $path = $this->path();
00319 
00320           if ($path != '')
00321                $path.= '/';
00322 
00323           $path.= $this->filename();
00324 
00325           return $path;
00326      }
00327 
00331      function checkRight( $type )
00332      {
00333           return true;
00334      }
00335 
00336 
00340      function hasRight( $type )
00341      {
00342 //        $user = Session::getUser();
00343 //        return $user->hasRight( $this->objectid,$type ) || (isset($this->parentid)&&$user->hasRight($this->parentid,$type)&&$user->hasRight($this->parentid,ACL_TRANSMIT));
00344           
00345           if   ( is_null($this->aclMask) )
00346           {
00347                $this->aclMask = 0;
00348                
00349                $project  = Session::getProject();
00350                $language = Session::getProjectLanguage();
00351                $user     = Session::getUser();
00352                
00353                if   ( $user->isAdmin && !$conf['security']['readonly'] )
00354                     $this->aclMask = ACL_READ +
00355                                      ACL_WRITE +
00356                                      ACL_PROP +
00357                                      ACL_DELETE +
00358                                      ACL_RELEASE +
00359                                      ACL_PUBLISH +
00360                                      ACL_CREATE_FOLDER +
00361                                      ACL_CREATE_FILE +
00362                                      ACL_CREATE_LINK +
00363                                      ACL_CREATE_PAGE +
00364                                      ACL_GRANT +
00365                                      ACL_TRANSMIT;
00366 
00367                if   ( $user->isAdmin && $type & ACL_READ )
00368                     return true;
00369      
00370                $sql = new Sql( <<<SQL
00371 SELECT {t_acl}.* FROM {t_acl}
00372                       LEFT JOIN {t_object}
00373                              ON {t_object}.id={t_acl}.objectid
00374                       WHERE objectid={objectid}
00375                         AND ( languageid={languageid} OR languageid IS NULL )
00376                         AND ( {t_acl}.userid={userid} OR {group_clause}
00377                                                                  OR ({t_acl}.userid IS NULL AND {t_acl}.groupid IS NULL) )
00378 SQL
00379 );
00380 
00381                $sql->setInt  ( 'languageid'  ,$language->languageid   );
00382                $sql->setInt  ( 'objectid'    ,$this->objectid         );
00383                $sql->setInt  ( 'userid'      ,$user->userid           );
00384                $sql->setParam( 'group_clause',$user->getGroupClause() );
00385      
00386                $db = db_connection();
00387                foreach( $db->getAll( $sql->query ) as $row )
00388                {
00389                     $acl = new Acl();
00390                     $acl->setDatabaseRow( $row );
00391                     #Html::debug($acl,"ACL");
00392                     
00393                     $this->aclMask |= $acl->getMask();
00394                }
00395           }
00396           
00397 //        Html::debug($type,"Anfrage");
00398 //        Html::debug($this->aclMask,"Maske fuer Objekt ".$this->objectid);
00399 //        Html::debug($this->aclMask & $type,"Ergebnis");
00400           return $this->aclMask & $type;
00401      }
00402 
00403 
00409      function getType()
00410      {
00411           if ($this->isFolder)
00412                return OR_TYPE_FOLDER;
00413           if ($this->isFile)
00414                return OR_TYPE_FILE;
00415           if ($this->isPage)
00416                return OR_TYPE_PAGE;
00417           if ($this->isLink)
00418                return OR_TYPE_LINK;
00419 
00420           return 'unknown';
00421      }
00422 
00423 
00424      function getProperties()
00425      {
00426           return Array( 'id'               =>$this->objectid,
00427                         'objectid'         =>$this->objectid,
00428                         'parentid'         =>$this->parentid,
00429                         'filename'         =>$this->filename,
00430                         'name'             =>$this->name,
00431                         'desc'             =>$this->desc,
00432                         'description'      =>$this->desc,
00433                         'create_date'      =>$this->createDate,
00434                         'create_user'      =>$this->createUser,
00435                         'lastchange_date'  =>$this->lastchangeDate,
00436                         'lastchange_user'  =>$this->lastchangeUser,
00437                         'isFolder'         =>$this->isFolder,
00438                         'isFile'           =>$this->isFile,
00439                         'isLink'           =>$this->isLink,
00440                         'isPage'           =>$this->isPage,
00441                         'isRoot'           =>$this->isRoot,
00442                         'languageid'       =>$this->languageid,
00443                         'modelid'          =>$this->modelid,
00444                         'projectid'        =>$this->projectid,
00445                         'type'             =>$this->getType()  );
00446      }
00447 
00448 
00453      function path()
00454      {
00455           $folder = new Folder($this->parentid);
00456 
00457           return implode('/', $folder->parentObjectFileNames(false, true));
00458      }
00459 
00460 
00461 
00465      function goodFilename( $filename )
00466      {
00467           // Dateiname muss gueltig sein,
00468           // ungueltige Zeichen werden entfernt
00469           $gueltig = 'abcdefghijklmnopqrstuvwxyz0123456789.-_';
00470           $tmp = strtr($filename, $gueltig, str_repeat('#', strlen($gueltig)));
00471           return( str_replace('-','',strtr($this->filename, $tmp, str_repeat('-', strlen($tmp)))) );
00472      }
00473 
00474 
00475 
00480      function filename()
00481      {
00482 
00483           global $conf;
00484 
00485           if   ( $conf['filename']['edit'] && $this->filename != '' && $this->filename != $this->objectid )
00486           {
00487                $this->filename = $this->goodFilename(trim(strtolower($this->name)));
00488                return $this->filename;
00489           }
00490 
00491           if   ( $this->type == OR_TYPE_FOLDER )
00492           {
00493                $this->filename = $this->objectid;
00494           }
00495           elseif    ( $this->orderid == 1              &&
00496                  !empty($conf['filename']['default']) &&
00497                  !$conf['filename']['edit']              )
00498           {
00499                $this->filename = $conf['filename']['default'];
00500           }
00501           else
00502           {
00503                switch( $conf['filename']['style'] )
00504                {
00505                     case 'longid':
00506                          // Eine etwas laengere ID als Dateinamen benutzen
00507                          $this->filename = base_convert(str_pad($this->objectid,6,'a'),11,10);
00508                          break;
00509 
00510                     case 'id':
00511                          // Einfach die Objekt-Id als Dateinamen verwenden.
00512                          $this->filename = $this->objectid;
00513                          break;
00514 
00515                     case 'short':
00516                          // So kurz wie moeglich: Erhoehen der Basis vom 10 auf 36.
00517                          // Beispiele:
00518                          // 1  -> 1
00519                          // 10 -> a
00520                          $this->filename = base_convert($this->objectid,10,36);
00521                          break;
00522 
00523 //                       case 'md5':
00524 //                            $this->filename = md5(md5($this->objectid));
00525 //                            break;
00526                     case  'ss':
00527                          // Imitieren von "StoryServer" URLs. Wers braucht.
00528                          $this->filename = '0,'.
00529                                            base_convert(str_pad($this->parentid,3,'a'),11,10).
00530                                            ','.
00531                                            base_convert(str_pad($this->objectid,7,'a'),11,10).
00532                                            ',00';
00533                          break;
00534 //                       case  'title':
00535 //                            $this->filename = $this->goodFilename(trim(strtolower($this->name)));
00536 //                            break;
00537 
00538                     default:
00539                          die('Unknown filename style: '.$conf['filename']['style'] );
00540                }
00541           }
00542 
00543           return $this->filename;
00544      }
00545 
00546 
00547 
00551      function available( $objectid )
00552      {
00553           $db = db_connection();
00554 
00555           // Vielleicht k�nnen wir uns den DB-Zugriff auch ganz sparen.
00556           if   ( !is_numeric($objectid) || $objectid <= 0 )
00557                return false; // Objekt-Id ung�ltig.
00558                
00559           $sql = new Sql('SELECT 1 FROM {t_object} '.
00560                          ' WHERE id={objectid}');
00561           $sql->setInt('objectid'  , $objectid  );
00562 
00563           return intval($db->getOne($sql->query)) == 1;
00564      }
00565      
00566      
00573      function objectLoad()
00574      {
00575           global $SESS;
00576           $db = db_connection();
00577 
00578           $sql = new Sql('SELECT {t_object}.*,' .
00579                          '       {t_name}.name,{t_name}.descr,'.
00580                          '       lastchangeuser.name     as lastchange_username,     '.
00581                          '       lastchangeuser.fullname as lastchange_userfullname, '.
00582                          '       lastchangeuser.mail     as lastchange_usermail,     '.
00583                          '       createuser.name         as create_username,     '.
00584                          '       createuser.fullname     as create_userfullname, '.
00585                          '       createuser.mail         as create_usermail,     '.
00586                          '       {t_name}.name,{t_name}.descr'.
00587                          ' FROM {t_object}'.
00588                          ' LEFT JOIN {t_name} '.
00589                          '        ON {t_object}.id={t_name}.objectid AND {t_name}.languageid={languageid} '.
00590                          ' LEFT JOIN {t_user} as lastchangeuser '.
00591                          '        ON {t_object}.lastchange_userid=lastchangeuser.id '.
00592                          ' LEFT JOIN {t_user} as createuser '.
00593                          '        ON {t_object}.create_userid=createuser.id '.
00594                          ' WHERE {t_object}.id={objectid}');
00595           $sql->setInt('objectid'  , $this->objectid  );
00596           $sql->setInt('languageid', $this->languageid);
00597 
00598           $row = $db->getRow($sql->query);
00599           
00600           if   ( count($row)==0 )
00601                die('cannot load object '.$this->objectid );
00602 
00603           $this->setDatabaseRow( $row );
00604 
00605           if (count($row) == 0)
00606                die('fatal: Object::objectLoad(): objectid not found: '.$this->objectid.', SQL='.$sql->query );
00607 
00608      }
00609 
00610 
00616      function objectLoadRaw()
00617      {
00618           global $SESS;
00619           $db = db_connection();
00620 
00621           $sql = new Sql('SELECT * FROM {t_object}'.
00622                        ' WHERE {t_object}.id={objectid}');
00623           $sql->setInt('objectid'  , $this->objectid  );
00624           $row = $db->getRow($sql->query);
00625 
00626           if (count($row) == 0)
00627                die('fatal: Object::objectLoadRaw(): objectid not found: '.$this->objectid.', SQL='.$sql->query);
00628 
00629           $this->parentid  = $row['parentid' ];
00630           $this->filename  = $row['filename' ];
00631           $this->projectid = $row['projectid'];
00632           
00633           if   ( intval($this->parentid) == 0 )
00634                $this->isRoot = true;
00635           else
00636                $this->isRoot = false;
00637 
00638           $this->name = 'n/a';
00639 
00640           $this->create_date       = $row['create_date'];
00641           $this->create_userid     = $row['create_userid'];
00642           $this->lastchange_date   = $row['lastchange_date'];
00643           $this->lastchange_userid = $row['lastchange_userid'];
00644 
00645 
00646           $this->isFolder = ( $row['is_folder'] == '1' );
00647           $this->isFile   = ( $row['is_file'  ] == '1' );
00648           $this->isPage   = ( $row['is_page'  ] == '1' );
00649           $this->isLink   = ( $row['is_link'  ] == '1' );
00650      }
00651 
00652 
00658      function setDatabaseRow( $row )
00659      {
00660           if   ( count($row)==0 )
00661                die('setDatabaseRow() got empty array, oid='.$this->objectid);
00662 
00663           $this->parentid  = $row['parentid' ];
00664           $this->projectid = $row['projectid'];
00665           $this->filename  = $row['filename' ];
00666           $this->orderid   = $row['orderid'  ];
00667           
00668           if   ( intval($this->parentid) == 0 )
00669                $this->isRoot = true;
00670           else $this->isRoot = false;
00671 
00672           $this->createDate     = $row['create_date'    ];
00673           $this->lastchangeDate = $row['lastchange_date'];
00674 
00675           $this->createUser = new User();
00676           $this->createUser->userid       = $row['create_userid'          ];
00677           if   ( !empty($row['create_username']) )
00678           {
00679                $this->createUser->name         = $row['create_username'        ];
00680                $this->createUser->fullname     = $row['create_userfullname'    ];
00681                $this->createUser->mail         = $row['create_usermail'        ];
00682           }
00683 
00684           $this->lastchangeUser = new User();
00685           $this->lastchangeUser->userid   = $row['lastchange_userid'      ];
00686           
00687           if   ( !empty($row['lastchange_username']) )
00688           {
00689                $this->lastchangeUser->name     = $row['lastchange_username'    ];
00690                $this->lastchangeUser->fullname = $row['lastchange_userfullname'];
00691                $this->lastchangeUser->mail     = $row['lastchange_usermail'    ];
00692           }
00693 
00694           $this->isFolder = ( $row['is_folder'] == '1' );
00695           $this->isFile   = ( $row['is_file'  ] == '1' );
00696           $this->isPage   = ( $row['is_page'  ] == '1' );
00697           $this->isLink   = ( $row['is_link'  ] == '1' );
00698 
00699           if   ( $this->isRoot )
00700           {
00701                $project = Session::getProject();
00702                $this->name        = $project->name;
00703                $this->desc        = '';
00704                $this->description = '';
00705           }
00706           else
00707           {
00708                $this->name        = $row['name' ];
00709                $this->desc        = $row['descr'];
00710                $this->description = $row['descr'];
00711           }
00712 
00713           $this->checkName();
00714      }
00715 
00716 
00717 
00722      function load()
00723      {
00724           $this->objectLoad();
00725      }
00726 
00733      function objectLoadName()
00734      {
00735           die();
00736           global $SESS;
00737           $db = db_connection();
00738 
00739           $sql = new Sql('SELECT *'.' FROM {t_name}'.' WHERE objectid={objectid}'.'   AND languageid={languageid}');
00740           $sql->setInt('objectid'  , $this->objectid  );
00741           $sql->setInt('languageid', $this->languageid);
00742           $res = $db->query($sql->query);
00743 
00744           if ($res->numRows() == 0)
00745           {
00746                // Wenn Name in dieser Sprache nicht vorhanden, dann irgendeinen Namen lesen
00747                $sql->setQuery('SELECT *'.' FROM {t_name}'.' WHERE objectid={objectid}'.'   AND name != {blank}');
00748                $sql->setString('blank', '');
00749                $res = $db->query($sql->query);
00750           }
00751           $row = $res->fetchRow();
00752 
00753           $this->name = $row['name'];
00754           $this->desc = $row['description'];
00755 
00756           // Falls leer, id<objectnr> als Dateinamen verwenden
00757           if ($this->name == '')
00758                $this->name = $this->filename;
00759      }
00760 
00764      function objectSave( $withName = true )
00765      {
00766           global $SESS;
00767           $db = db_connection();
00768 
00769           $this->checkFilename();
00770 
00771           $sql = new Sql('UPDATE {t_object} SET '.
00772                          '  parentid={parentid},'.
00773                          '  lastchange_date   = {time}  ,'.
00774                          '  lastchange_userid = {userid},'.
00775                          '  filename  = {filename}'.
00776                          ' WHERE id={objectid}');
00777 
00778           if   ( $this->isRoot )
00779                $sql->setNull('parentid');
00780           else $sql->setInt ('parentid',$this->parentid );
00781 
00782           $sql->setInt   ('objectid', $this->objectid);
00783           $sql->setString('filename', $this->filename);
00784 
00785           $user = Session::getUser();
00786           $this->lastchangeUser = $user;
00787           $this->lastchangeDate = time();
00788 
00789           $sql->setInt   ('userid'  ,$this->lastchangeUser->userid  );
00790           $sql->setInt   ('time'    ,$this->lastchangeDate          );
00791 
00792           $db->query($sql->query);
00793 
00794           // Nur wenn nicht Wurzelordner
00795           if   ( !$this->isRoot && $withName )
00796           {
00797                if   ( $this->name == '' )
00798                     $this->name = $this->filename;
00799 
00800                $this->objectSaveName();
00801           }
00802      }
00803 
00804 
00805 
00809      function setTimestamp()
00810      {
00811           $db = db_connection();
00812 
00813           $sql = new Sql('UPDATE {t_object} SET '.
00814                          '  lastchange_date   = {time}  ,'.
00815                          '  lastchange_userid = {userid} '.
00816                          ' WHERE id={objectid}');
00817 
00818           $user = Session::getUser();
00819           $this->lastchangeUser = $user;
00820           $this->lastchangeDate = time();
00821 
00822           $sql->setInt   ('userid'  ,$this->lastchangeUser->userid  );
00823           $sql->setInt   ('objectid',$this->objectid                );
00824           $sql->setInt   ('time'    ,$this->lastchangeDate          );
00825 
00826           $db->query( $sql->query );
00827           
00828      }
00829 
00830 
00831 
00838      function ObjectSaveName()
00839      {
00840           global $SESS;
00841           $db = db_connection();
00842 
00843           $sql = new Sql('SELECT COUNT(*) FROM {t_name} '.' WHERE objectid  ={objectid}'.'   AND languageid={languageid}');
00844           $sql->setInt( 'objectid'  , $this->objectid   );
00845           $sql->setInt( 'languageid', $this->languageid );
00846           $count = $db->getOne($sql->query);
00847 
00848           if ($count > 0)
00849           {
00850                $sql->setQuery('UPDATE {t_name} SET '.
00851                               '  name  = {name},'.
00852                               '  descr = {desc} '.
00853                               ' WHERE objectid  ={objectid}'.
00854                               '   AND languageid={languageid}');
00855                $sql->setString('name', $this->name);
00856                $sql->setString('desc', $this->desc);
00857                $db->query($sql->query);
00858           }
00859           else
00860           {
00861                $sql = new Sql('SELECT MAX(id) FROM {t_name}');
00862                $nameid = intval($db->getOne($sql->query))+1;
00863 
00864                $sql->setQuery('INSERT INTO {t_name}'.'  (id,objectid,languageid,name,descr)'.' VALUES( {nameid},{objectid},{languageid},{name},{desc} )');
00865                $sql->setInt   ('objectid'  , $this->objectid    );
00866                $sql->setInt   ('languageid', $this->languageid  );
00867                $sql->setInt   ('nameid', $nameid    );
00868                $sql->setString('name'  , $this->name);
00869                $sql->setString('desc'  , $this->desc);
00870                $db->query($sql->query);
00871           }
00872      }
00873 
00879      function objectDelete()
00880      {
00881           $db = db_connection();
00882 
00883           $sql = new Sql( 'UPDATE {t_element} '.
00884                           '  SET default_objectid=NULL '.
00885                           '  WHERE default_objectid={objectid}' );
00886           $sql->setInt('objectid',$this->objectid);
00887           $db->query( $sql->query );
00888 
00889           $sql = new Sql( 'UPDATE {t_value} '.
00890                           '  SET linkobjectid=NULL '.
00891                           '  WHERE linkobjectid={objectid}' );
00892           $sql->setInt('objectid',$this->objectid);
00893           $db->query( $sql->query );
00894 
00895           $sql = new Sql( 'UPDATE {t_link} '.
00896                           '  SET link_objectid=NULL '.
00897                           '  WHERE link_objectid={objectid}' );
00898           $sql->setInt('objectid',$this->objectid);
00899           $db->query( $sql->query );
00900 
00901 
00902           // Objekt-Namen l?schen
00903           $sql = new Sql('DELETE FROM {t_name} WHERE objectid={objectid}');
00904           $sql->setInt('objectid', $this->objectid);
00905           $db->query($sql->query);
00906 
00907           // Objekt l?schen
00908           $sql = new Sql('DELETE FROM {t_object} WHERE id={objectid}');
00909           $sql->setInt('objectid', $this->objectid);
00910           $db->query($sql->query);
00911 
00912           $this->deleteAllACLs();
00913      }
00914 
00915 
00919      function objectAdd()
00920      {
00921           global $SESS;
00922           $db = db_connection();
00923 
00924           // Neue Objekt-Id bestimmen
00925           $sql = new Sql('SELECT MAX(id) FROM {t_object}');
00926           $this->objectid = intval($db->getOne($sql->query))+1;
00927 
00928           $this->checkFilename();
00929           $sql = new Sql('INSERT INTO {t_object}'.
00930                          ' (id,parentid,projectid,filename,orderid,create_date,create_userid,lastchange_date,lastchange_userid,is_folder,is_file,is_page,is_link)'.
00931                          ' VALUES( {objectid},{parentid},{projectid},{filename},{orderid},{time},{userid},{time},{userid},{is_folder},{is_file},{is_page},{is_link} )');
00932 
00933           if   ( $this->isRoot )
00934                $sql->setNull('parentid');
00935           else $sql->setInt ('parentid',$this->parentid );
00936 
00937           $sql->setInt   ('objectid' , $this->objectid );
00938           $sql->setString('filename' , $this->filename );
00939           $sql->setString('projectid', $this->projectid);
00940           $sql->setInt   ('orderid'  , 99999           );
00941           $sql->setInt   ('time'     , time()          );
00942           $user = Session::getUser();
00943           $sql->setInt   ('userid'   , $user->userid   );
00944 
00945           $sql->setBoolean('is_folder',$this->isFolder);
00946           $sql->setBoolean('is_file',  $this->isFile);
00947           $sql->setBoolean('is_page',  $this->isPage);
00948           $sql->setBoolean('is_link',  $this->isLink);
00949 
00950           $db->query($sql->query);
00951 
00952           if   ( !empty($this->name) )
00953                $this->objectSaveName();
00954                
00955           $acl = new Acl();
00956           $acl->userid = $user->userid;
00957           $acl->objectid = $this->objectid;
00958           
00959           // Standard-Rechte fuer dieses neue Objekt setzen.
00960           // Der Benutzer hat Lese- und Schreibrechte auf das Objekt.
00961           $acl->read   = true;
00962           $acl->write  = true;
00963           $acl->prop   = true;
00964           $acl->delete = true;
00965           $acl->grant = true;
00966           if   ( $this->isFolder )
00967           {
00968                $acl->create_file   = true;
00969                $acl->create_page   = true;
00970                $acl->create_folder = true;
00971                $acl->create_link   = true;
00972           }
00973           $acl->add();
00974 
00975           // Aus dem Eltern-Ordner vererbbare Berechtigungen übernehmen.
00976           $folder = new Folder( $this->parentid );
00977           foreach( $folder->getAclIds() as $aclid )
00978           {
00979                $acl = new Acl( $aclid );
00980                $acl->load();
00981                
00982                if   ( $acl->transmit ) // ACL is vererbbar, also kopieren.
00983                {
00984                     $acl->objectid = $this->objectid;
00985                     $acl->add(); // ... und hinzufuegen.
00986                }
00987           }
00988      }
00989 
00990 
00994      function checkFilename()
00995      {
00996           if   ( empty($this->filename) )
00997                $this->filename = $this->objectid;
00998 
00999 //        $this->filename = trim(strtolower($this->filename));
01000 
01001 //        $this->filename = $this->goodFilename( $this->filename);
01002 
01003           if   ( $this->isRoot )
01004                return;
01005 
01006           if   ( !$this->filenameIsUnique( $this->filename ) )
01007           {
01008 //             $this->filename = $this->objectid;
01009 //
01010 //             if   ( !$this->filenameIsUnique( $this->filename ) )
01011                     $this->filename = $this->filename.'.'.md5(microtime());
01012           }
01013      }
01014 
01015 
01016      function filenameIsUnique( $filename )
01017      {
01018           $db = db_connection();
01019 
01020           $sql = new Sql('SELECT COUNT(*) FROM {t_object}'.' WHERE parentid={parentid} AND filename={filename} AND NOT id = {objectid}');
01021 
01022           $sql->setString('parentid', $this->parentid);
01023           $sql->setString('objectid', $this->objectid);
01024 
01025           $sql->setString('filename', $filename      );
01026 
01027           return( intval($db->getOne($sql->query)) == 0 );
01028      }
01029 
01030 
01034      function checkName()
01035      {
01036           if   ( empty($this->name) )
01037                $this->name = $this->filename;
01038 
01039           if   ( empty($this->name) )
01040                $this->name = $this->objectid;
01041      }
01042 
01043 
01044      function getAclIds()
01045      {
01046           $db = db_connection();
01047           
01048           $sql = new Sql( 'SELECT id FROM {t_acl} '.
01049                           '  WHERE objectid={objectid}'.
01050                           '    AND ( languageid IS NULL OR '.
01051                           '          languageid = {languageid} )'.
01052                           '  ORDER BY userid,groupid ASC' );
01053           $sql->setInt('languageid',$this->languageid);
01054           $sql->setInt('objectid'  ,$this->objectid);
01055 
01056           return $db->getCol( $sql->query );
01057      }
01058 
01059 
01060      function getAllAclIds()
01061      {
01062           $db = db_connection();
01063           
01064           $sql = new Sql( 'SELECT id FROM {t_acl} '.
01065                           '  WHERE objectid={objectid}'.
01066                           '  ORDER BY userid,groupid ASC' );
01067           $sql->setInt('objectid'  ,$this->objectid);
01068 
01069           return $db->getCol( $sql->query );
01070      }
01071 
01072 
01073      function getInheritedAclIds()
01074      {
01075           $acls = array();
01076           
01077           if   ( $this->getType() == 'unknown' )
01078                $this->load();
01079 
01080           // Root-Ordner erhaelt keine Vererbungen
01081           if   ( $this->isRoot )
01082                return $acls;
01083           
01084           $db = db_connection();
01085           $folder = new Folder( $this->parentid );
01086           
01087           foreach( $folder->parentObjectIds(true,true) as $oid )
01088           {
01089                $sql = new Sql( 'SELECT id FROM {t_acl} '.
01090                                '  WHERE objectid={objectid}'.
01091                                '    AND is_transmit = 1'.
01092                                '    AND ( languageid IS NULL OR '.
01093                                '          languageid = {languageid} )'.
01094                                '  ORDER BY userid,groupid ASC' );
01095                $sql->setInt('objectid'  ,$oid);
01096                $sql->setInt('languageid',$this->languageid);
01097                $acls = array_merge( $acls,$db->getCol( $sql->query ) );
01098           }
01099 
01100           return $acls;
01101      }
01102 
01103 
01104      function getAllInheritedAclIds()
01105      {
01106           $acls = array();
01107           
01108           if   ( $this->getType() == 'unknown' )
01109                $this->load();
01110 
01111           // Root-Ordner erhaelt keine Vererbungen
01112           if   ( $this->isRoot )
01113                return $acls;
01114           
01115           $db = db_connection();
01116           $folder = new Folder( $this->parentid );
01117           
01118           foreach( $folder->parentObjectIds(true,true) as $oid )
01119           {
01120                $sql = new Sql( 'SELECT id FROM {t_acl} '.
01121                                '  WHERE objectid={objectid}'.
01122                                '    AND is_transmit = 1'.
01123                                '  ORDER BY userid,groupid ASC' );
01124                $sql->setInt('objectid'  ,$oid);
01125                $acls = array_merge( $acls,$db->getCol( $sql->query ) );
01126           }
01127 
01128           return $acls;
01129      }
01130 
01131 
01135      function getRelatedAclTypes()
01136      {
01137           if   ( $this->isFolder )
01138                return( array('read','write','delete','prop','release','publish','create_folder','create_file','create_page','create_link','grant','transmit') );
01139           if   ( $this->isFile )
01140                return( array('read','write','delete','prop','release','publish','grant') );
01141           if   ( $this->isPage )
01142                return( array('read','write','delete','prop','release','publish','grant') );
01143           if   ( $this->isLink )
01144                return( array('read','write','delete','prop','grant') );
01145      }
01146 
01147 
01151      function getAssocRelatedAclTypes()
01152      {
01153           $rights = array('read','write','delete','prop','release','publish','create_folder','create_file','create_page','create_link','grant','transmit');
01154           $types  = array();
01155           foreach( $rights as $r )
01156                $types[$r] = false;
01157 
01158           foreach( $this->getRelatedAclTypes() as $t )
01159                $types[$t] = true;
01160 
01161           return $types;
01162      }
01163 
01168      function deleteAllACLs()
01169      {
01170           foreach( $this->getAllAclIds() as $aclid )
01171           {
01172                $acl = new Acl( $aclid );
01173                $acl->delete();
01174           }
01175      }
01176 
01177 
01181      function tmpfileYYYYYY()
01182      {
01183           if   ( isset($this->tmpfile) && $this->tmpfile != '' )
01184                return $this->tmpfile; // Tempor�rer Dateiname bereits vorhanden.
01185 
01186           global $conf;
01187           
01188           // 1. Versuch: Temp-Dir aus Konfiguration.
01189           $tmpdir = @$conf['cache']['tmp_dir'];
01190           if   ( $this->tmpfile === FALSE )
01191                $this->tmpfile = @tempnam( $tmpdir,'openrat_tmp' );
01192 
01193           // 2. Versuch: Temp-Dir aus "upload_tmp_dir".
01194           if   ( $this->tmpfile === FALSE )
01195           {
01196                Html::debug($this->tmpfile,"nochmal");
01197                $tmpdir = ini_get('upload_tmp_dir');
01198                $this->tmpfile = @tempnam( $tmpdir,'openrat_tmp' );
01199           }
01200           
01201           elseif    ( $this->tmpfile === FALSE )
01202           {
01203           Html::debug($this->tmpfile,"nochmal");
01204                $this->tmpfile = @tempnam( '','openrat_tmp' );
01205           }
01206                
01207           Html::debug($this->tmpfile,"tmpfile in objekt");
01208           Logger::debug( 'creating temporary file: '.$this->tmpfile );
01209 
01210           return $this->tmpfile;
01211      }
01212 
01213 
01217      function getTempDir()
01218      {
01219           global $conf;
01220           $tmpdir = @$conf['cache']['tmp_dir'];
01221           $tmpfile = @tempnam( $tmpdir,'openrat_tmp' );
01222 
01223           // 2. Versuch: Temp-Dir aus "upload_tmp_dir".
01224           if   ( $tmpfile === FALSE )
01225           {
01226                $tmpdir = ini_get('upload_tmp_dir');
01227                $tmpfile = @tempnam( $tmpdir,'openrat_tmp' );
01228           }
01229           
01230           elseif    ( $tmpfile === FALSE )
01231           {
01232                $tmpfile = @tempnam( '','openrat_tmp' );
01233           }
01234           
01235           $tmpdir = dirname($tmpfile);
01236           @unlink($tmpfile);
01237                
01238           return $tmpdir;
01239      }
01240 
01241      
01242      
01248      function getTempFileName( $attr = array() )
01249      {
01250           global $conf;
01251           
01252 //        if   ( $conf['cache']['enable_cache'] )
01253 //        {
01254                $filename = Object::getTempDir().'/openrat';
01255                foreach( $attr as $a=>$w )
01256                     $filename .= '_'.$a.$w;
01257                     
01258                $filename .= '.tmp';
01259                return $filename;
01260 //        }
01261 //        else
01262 //        {
01263 //             $tmpdir = @$conf['cache']['tmp_dir'];
01264 //             $tmpfile = tempnam( $tmpdir,'openrat_tmp' );
01265 //             
01266 //             return $tmpfile;
01267 //        }
01268      }
01269 
01270 
01271 
01276      function getTempFile()
01277      {
01278           return tmpfile();
01279      }
01280 
01281 
01282 
01289      function setOrderId( $orderid )
01290      {
01291           $db = db_connection();
01292 
01293           $sql = new Sql('UPDATE {t_object} '.'  SET orderid={orderid}'.'  WHERE id={objectid}');
01294           $sql->setInt('objectid', $this->objectid);
01295           $sql->setInt('orderid', $orderid);
01296 
01297           $db->query($sql->query);
01298      }
01299 
01300 
01307      function setParentId( $parentid )
01308      {
01309           $db = db_connection();
01310 
01311           $sql = new Sql('UPDATE {t_object} '.'  SET parentid={parentid}'.'  WHERE id={objectid}');
01312           $sql->setInt('objectid', $this->objectid);
01313           $sql->setInt('parentid', $parentid);
01314 
01315           $db->query($sql->query);
01316      }
01317 
01318 
01319      function getDependentObjectIds()
01320      {
01321           $db = db_connection();
01322 
01323           $sql = new Sql( 'SELECT {t_page}.objectid FROM {t_value}'.
01324                           '  LEFT JOIN {t_page} '.
01325                           '    ON {t_value}.pageid = {t_page}.id '.
01326                           '  WHERE linkobjectid={objectid}' );
01327           $sql->setInt( 'objectid',$this->objectid );
01328 
01329           return $db->getCol( $sql->query );
01330      }
01331 
01332 
01338      function getObjectIdsByFileName( $text )
01339      {
01340           $db = db_connection();
01341           
01342           $sql = new Sql( 'SELECT id FROM {t_object} '.
01343                           ' WHERE filename LIKE {filename}'.
01344                           '   AND projectid={projectid}'.
01345                           '  ORDER BY lastchange_date DESC' );
01346           $sql->setInt   ( 'projectid',$this->projectid );
01347           $sql->setString( 'filename','%'.$text.'%' );
01348           
01349           return $db->getCol( $sql->query );
01350      }
01351 
01352 
01358      function getObjectIdsByName( $text )
01359      {
01360           $db = db_connection();
01361           
01362           $sql = new Sql( 'SELECT {t_object}.id FROM {t_object} '.
01363                           ' LEFT JOIN {t_name} '.
01364                           '   ON {t_object}.id={t_name}.objectid'.
01365                           ' WHERE {t_name}.name LIKE {name}'.
01366                           '   AND {t_name}.languageid={languageid}'.
01367                           '   AND {t_object}.projectid={projectid}'.
01368                           '  ORDER BY lastchange_date DESC' );
01369           $sql->setInt   ( 'projectid' ,$this->projectid );
01370           $sql->setInt   ( 'languageid',$this->languageid );
01371           $sql->setString( 'name'      ,'%'.$text.'%' );
01372           
01373           return $db->getCol( $sql->query );
01374      }
01375 
01376 
01382      function getObjectIdsByDescription( $text )
01383      {
01384           $db = db_connection();
01385           
01386           $sql = new Sql( 'SELECT {t_object}.id FROM {t_object} '.
01387                           ' LEFT JOIN {t_name} '.
01388                           '   ON {t_object}.id={t_name}.objectid'.
01389                           ' WHERE {t_name}.descr LIKE {desc}'.
01390                           '   AND {t_name}.languageid={languageid}'.
01391                           '   AND {t_object}.projectid={projectid}'.
01392                           '  ORDER BY lastchange_date DESC' );
01393           $sql->setInt   ( 'projectid' ,$this->projectid );
01394           $sql->setInt   ( 'languageid',$this->languageid );
01395           $sql->setString( 'desc'      ,'%'.$text.'%' );
01396           
01397           return $db->getCol( $sql->query );
01398      }
01399 
01400 
01406      function getObjectIdsByCreateUserId( $userid )
01407      {
01408           $db = db_connection();
01409           
01410           $sql = new Sql( 'SELECT id FROM {t_object} '.
01411                           ' WHERE create_userid={userid}'.
01412                           '   AND projectid={projectid}'.
01413                           '  ORDER BY lastchange_date DESC' );
01414           $sql->setInt   ( 'projectid',$this->projectid );
01415           $sql->setInt   ( 'userid'   ,$userid          );
01416           
01417           return $db->getCol( $sql->query );
01418      }
01419 
01420 
01426      function getObjectIdsByLastChangeUserId( $userid )
01427      {
01428           $db = db_connection();
01429           
01430           $sql = new Sql( 'SELECT id FROM {t_object} '.
01431                           ' WHERE lastchange_userid={userid}'.
01432                           '   AND projectid={projectid}'.
01433                           '  ORDER BY lastchange_date DESC' );
01434           $sql->setInt   ( 'projectid',$this->projectid );
01435           $sql->setInt   ( 'userid'   ,$userid          );
01436           
01437           return $db->getCol( $sql->query );
01438      }
01439 
01440 
01446      function isObjectId( $id )
01447      {
01448           $db = db_connection();
01449           
01450           $sql = new Sql( 'SELECT id FROM {t_object} '.
01451                           ' WHERE id={objectid}'.
01452                           '   AND projectid={projectid}' );
01453           $sql->setInt   ( 'projectid' ,$this->projectid );
01454           $sql->setInt   ( 'objectid'  ,$id              );
01455 
01456           return ($db->getOne($sql->query) == intval($id) );
01457      }
01458 
01459 
01460 
01461 }
01462 
01463 ?>

Erzeugt am Thu May 14 00:55:48 2009 für OpenRat von  doxygen 1.5.8