FolderAction.class.php

gehe zur Dokumentation dieser Datei
00001 <?php
00002 // ---------------------------------------------------------------------------
00003 // $Id$
00004 // ---------------------------------------------------------------------------
00005 // OpenRat Content Management System
00006 // Copyright (C) 2002-2004 Jan Dankert, cms@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.52  2009-03-22 21:54:35  dankert
00024 // Korrektur: Rechteabfrage für Verschieben/Löschen.
00025 //
00026 // Revision 1.51  2009-03-22 21:49:08  dankert
00027 // Subaction "showprop" entfernt, da in "prop" mit aufgegangen.
00028 //
00029 // Revision 1.50  2009-03-17 01:43:19  dankert
00030 // Auch Bilder (wieder) im gleichen Frame anzeigen.
00031 //
00032 // Revision 1.49  2009-03-02 23:07:11  dankert
00033 // Bugfix: Sortieren nach Typ
00034 //
00035 // Revision 1.48  2009-02-07 02:41:37  dankert
00036 // CSS-Klasse für Ordner-Inhalte ermitteln.
00037 //
00038 // Revision 1.47  2008-09-11 19:04:39  dankert
00039 // Korrektur Rueckmeldung.
00040 //
00041 // Revision 1.46  2007-12-23 16:05:00  dankert
00042 // Anzeigen der Ordner-Eigenschaften verbessert.
00043 //
00044 // Revision 1.45  2007-11-22 21:21:45  dankert
00045 // Dateien auch per HTTP-Link anlegen.
00046 //
00047 // Revision 1.44  2007-11-15 21:41:59  dankert
00048 // Warnmeldung, wenn es keine Seitenvorlagen gibt.
00049 //
00050 // Revision 1.43  2007-11-08 20:37:59  dankert
00051 // Warnmeldung, wenn beim L?schen nicht best?tigt wird.
00052 //
00053 // Revision 1.42  2007-11-05 20:47:39  dankert
00054 // Aufruf von "addValidationError(...)" bei Eingabefehlern.
00055 //
00056 // Revision 1.41  2007-10-05 23:32:40  dankert
00057 // Nach dem Ver?ffentlichen auf Fehler abfragen.
00058 //
00059 // Revision 1.40  2007-10-02 21:13:44  dankert
00060 // Men?punkt "Neu" mit direktem Hinzuf?gen von Objekten.
00061 //
00062 // Revision 1.39  2007-10-01 21:43:42  dankert
00063 // Ermitteln der maximalen Dateigroesse bei Uploads.
00064 //
00065 // Revision 1.38  2007-07-02 20:14:07  dankert
00066 // Ordnerinhalte rekursiv l?schen (also samt Unterordnern)
00067 //
00068 // Revision 1.37  2007-07-02 19:02:08  dankert
00069 // Korrektur: Anzeige der letzten ?nderung.
00070 //
00071 // Revision 1.36  2006/06/01 19:11:46  dankert
00072 // Abfragen von Rechten.
00073 //
00074 // Revision 1.35  2006/06/01 18:15:30  dankert
00075 // Implementiert: "kopieren, verschieben, l?schen"
00076 //
00077 // Revision 1.34  2006/02/05 11:30:12  dankert
00078 // Hinzuf?gen: Methode "select()"
00079 //
00080 // Revision 1.33  2006/01/29 17:18:58  dankert
00081 // Steuerung der Aktionsklasse ?ber .ini-Datei, dazu umbenennen einzelner Methoden
00082 //
00083 // Revision 1.32  2006/01/23 23:08:52  dankert
00084 // Kl. ?nderungen beim Anlegen von Objekten
00085 //
00086 // Revision 1.31  2006/01/11 22:50:00  dankert
00087 // Neue Methode order()
00088 //
00089 // Revision 1.30  2005/11/07 22:31:38  dankert
00090 // Wenn Dateiname=Objekt-Id, dann Dateinamen auf leer setzen.
00091 //
00092 // Revision 1.29  2005/01/28 23:05:39  dankert
00093 // Bei Aenderungen des Verzeichnis-Inhaltes den Timestamp des Verzeichnisses aktualisieren
00094 //
00095 // Revision 1.28  2005/01/27 22:21:30  dankert
00096 // Nach Generierung Systembefehl mit exec() ausf?hren
00097 //
00098 // Revision 1.27  2005/01/14 21:40:57  dankert
00099 // Aufruf von lastModified() fuer Conditional-GET
00100 //
00101 // Revision 1.26  2004/12/30 23:11:03  dankert
00102 // Wenn Root-Folder, dann keine Eigenschaften
00103 //
00104 // Revision 1.25  2004/12/30 21:44:23  dankert
00105 // Nach Speichern der Eigenschaften wieder Eigenschaften aufrufen
00106 //
00107 // Revision 1.24  2004/12/29 20:43:30  dankert
00108 // Kontextsensitives Anzeigen der Veroeffentlichungs-Checkboxen
00109 //
00110 // Revision 1.23  2004/12/28 22:58:23  dankert
00111 // Neuer Schalter fuer "Liveserver aufraeumen"
00112 //
00113 // Revision 1.22  2004/12/27 23:26:39  dankert
00114 // Seite vor dem Loeschen laden
00115 //
00116 // Revision 1.21  2004/12/27 23:24:50  dankert
00117 // Korrektur Html::url(...)
00118 //
00119 // Revision 1.20  2004/12/26 20:54:29  dankert
00120 // Sortierfunktion korrigiert
00121 //
00122 // Revision 1.19  2004/12/20 22:31:22  dankert
00123 // Uebertragen des Benutzers geaendert
00124 //
00125 // Revision 1.18  2004/12/19 20:40:51  dankert
00126 // Korrektur URLs
00127 //
00128 // Revision 1.17  2004/12/19 14:53:54  dankert
00129 // pub2() -> pubnow()
00130 //
00131 // Revision 1.16  2004/12/15 23:23:11  dankert
00132 // Anpassung an Session-Funktionen
00133 //
00134 // Revision 1.15  2004/11/29 23:24:36  dankert
00135 // Korrektur Veroeffentlichung
00136 //
00137 // Revision 1.14  2004/11/29 21:09:51  dankert
00138 // neue Methode pub2()
00139 //
00140 // Revision 1.13  2004/11/28 22:59:48  dankert
00141 // Ausgabe von "notices"
00142 //
00143 // Revision 1.12  2004/11/28 21:27:07  dankert
00144 // Ausgabe von "notices"
00145 //
00146 // Revision 1.11  2004/11/28 16:53:51  dankert
00147 // Korrektur create()
00148 //
00149 // Revision 1.10  2004/11/27 13:06:26  dankert
00150 // Ausgabe von Meldungen
00151 //
00152 // Revision 1.9  2004/11/10 22:36:16  dankert
00153 // Dateioperationen, Verschieben/Kopieren/Verknuepfen von mehreren Objekten in einem Arbeitsschritt
00154 //
00155 // Revision 1.8  2004/10/14 22:57:44  dankert
00156 // Neue Verknuepfungen mit dem Linknamen als Url vorbelegen
00157 //
00158 // Revision 1.7  2004/10/13 21:18:50  dankert
00159 // Neue Links zum Verschieben nach ganz oben/unten
00160 //
00161 // Revision 1.6  2004/05/07 21:30:59  dankert
00162 // Korrektur up_url
00163 //
00164 // Revision 1.5  2004/05/07 21:29:16  dankert
00165 // Url ?ber Html::url erzeugen
00166 //
00167 // Revision 1.4  2004/05/02 14:49:37  dankert
00168 // Einf?gen package-name (@package)
00169 //
00170 // Revision 1.3  2004/04/28 20:01:52  dankert
00171 // Ordner l?schen erm?glichen
00172 //
00173 // Revision 1.2  2004/04/24 16:57:13  dankert
00174 // Korrektur: pub()
00175 //
00176 // Revision 1.1  2004/04/24 15:14:52  dankert
00177 // Initiale Version
00178 //
00179 // ---------------------------------------------------------------------------
00180 
00181 
00189 class FolderAction extends ObjectAction
00190 {
00191      var $defaultSubAction = 'show';
00192      var $folder;
00193 
00194      function FolderAction()
00195      {
00196           if   ( $this->getRequestId() != 0  )
00197           {
00198                $this->folder = new Folder( $this->getRequestId() );
00199                $this->folder->load();
00200                Session::setObject( $this->folder );
00201           }
00202           else
00203           {
00204                $this->folder = Session::getObject();
00205           }
00206           
00207           // Datum letzte Aenderung an Browser uebertragen
00208           $this->lastModified( $this->folder->lastchangeDate );
00209      }
00210 
00211 
00212 
00217      function createnew()
00218      {
00219           global $conf;
00220           $type = $this->getRequestVar('type'       );
00221           
00222           switch( $type )
00223           {
00224                case 'folder':
00225                     $name = $this->getRequestVar('folder_name');
00226 
00227                     if   ( !empty($name) )
00228                     {
00229                          $f = new Folder();
00230                          $f->name     = $name;
00231                          $f->parentid = $this->folder->objectid; 
00232                          $f->add();
00233                          $this->folder->setTimestamp();
00234                          $this->addNotice('folder',$f->name,'ADDED','ok');
00235                     }
00236                     else
00237                     {
00238                          $this->addValidationError('folder_name');
00239                          $this->callSubAction('create');
00240                     }
00241                     break;
00242 
00243                case 'file':
00244                     $upload = new Upload();
00245 
00246                     if   ( !$upload->isValid() )
00247                     {
00248                          $this->addValidationError('file','COMMON_VALIDATION_ERROR',array(),$upload->error);
00249                          $this->callSubAction('createfile');
00250                          return;
00251                     }
00252                     // Pr�fen der maximal erlaubten Dateigr��e.
00253                     elseif    ( $upload->size > $this->maxFileSize() )
00254                     {
00255                          // Maximale Dateigr��e ist �berschritten
00256                          $this->addValidationError('file','MAX_FILE_SIZE_EXCEEDED');
00257                          $this->callSubAction('createfile');
00258                          return;
00259                     }
00260                     elseif( $upload->size > 0 )
00261                     {
00262                          $file   = new File();
00263                          $file->desc      = '';
00264                          $file->filename  = $upload->filename;
00265                          $file->name      = $upload->filename;
00266                          $file->extension = $upload->extension;       
00267                          $file->size      = $upload->size;
00268                          $file->parentid  = $this->folder->objectid;
00269                
00270                          $file->value     = $upload->value;
00271                
00272                          $file->add(); // Datei hinzufuegen
00273                          $this->folder->setTimestamp();
00274                          $this->addNotice('file',$file->name,'ADDED','ok');
00275                     }
00276                     
00277                     break;
00278 
00279                case 'page':
00280 
00281                     $name = $this->getRequestVar('page_name');
00282                     if   ( !empty($name) )
00283                     {
00284                          $page = new Page();
00285                          $page->name       = $name;
00286                          $page->templateid = $this->getRequestVar('page_templateid');
00287                          $page->parentid   = $this->folder->objectid;
00288                          $page->add();
00289                          $this->folder->setTimestamp();
00290           
00291                          $this->addNotice('page',$page->name,'ADDED','ok');
00292                     }
00293                     else
00294                     {
00295                          $this->addValidationError('page_name');
00296                          $this->callSubAction('create');
00297                     }
00298                     break;
00299                     
00300                case 'link':
00301 
00302                     $name = $this->getRequestVar('link_name');
00303                     if   ( !empty($name) )
00304                     {
00305                          $link = new Link();
00306                          $link->name           = $name;
00307                          $link->parentid       = $this->folder->objectid;
00308           
00309                          $link->isLinkToObject = false;
00310                          $link->url            = $name;
00311           
00312                          $link->add();
00313                          $this->folder->setTimestamp();
00314 
00315                          $this->addNotice('link',$link->name,'ADDED','ok');
00316                     }
00317                     else
00318                     {
00319                          $this->addValidationError('link_name');
00320                          $this->callSubAction('create');
00321                     }
00322                     
00323                     break;
00324                     
00325                default:
00326                     $this->addValidationError('type');
00327                     $this->callSubAction('create');
00328                     
00329           }
00330                               
00331      }    
00332 
00333      
00334      
00335      function createnewfolder()
00336      {
00337           $type        = $this->getRequestVar('type'       );
00338           $name        = $this->getRequestVar('name'       );
00339           $filename    = $this->getRequestVar('filename'   );
00340           $description = $this->getRequestVar('description');
00341           
00342           if   ( !empty($name) )
00343           {
00344                $f = new Folder();
00345                $f->name     = $name;
00346                $f->filename = $name;
00347                $f->desc     = $description;
00348                $f->parentid = $this->folder->objectid; 
00349 
00350                $f->add();
00351                $this->addNotice('folder',$f->name,'ADDED','ok');
00352           }
00353           else
00354           {
00355                $this->addValidationError('name');
00356                $this->callSubAction('createfolder');
00357           }
00358           
00359           $this->folder->setTimestamp();
00360      }    
00361 
00362 
00363 
00364      function createnewfile()
00365      {
00366           $type        = $this->getRequestVar('type'       );
00367           $name        = $this->getRequestVar('name'       );
00368           $filename    = $this->getRequestVar('filename'   );
00369           $description = $this->getRequestVar('description');
00370           
00371           $file   = new File();
00372           
00373           if   ( $this->hasRequestVar('url') )
00374           {
00375                $url = $this->getRequestVar('url');
00376                $http = new Http();
00377                $http->setUrl( $url );
00378           
00379                $ok = $http->request();
00380                
00381                if   ( !$ok )
00382                {
00383                     $this->addValidationError('url','COMMON_VALIDATION_ERROR',array(),$http->error);
00384                     $this->callSubAction('createfile');
00385                     return;
00386                }
00387                
00388                $file->desc      = $description;
00389                $file->filename  = basename($url);
00390                $file->name      = !empty($name)?$name:basename($url);
00391                $file->size      = strlen($http->body);
00392                $file->value     = $http->body;
00393                $file->parentid  = $this->folder->objectid;
00394           }
00395           else
00396           {
00397                $upload = new Upload();
00398                
00399                if   ( !$upload->isValid() )
00400                {
00401                     $this->addValidationError('file','COMMON_VALIDATION_ERROR',array(),$upload->error);
00402                     $this->callSubAction('createfile');
00403                     return;
00404                }
00405      
00406                $file->desc      = $description;
00407                $file->filename  = $upload->filename;
00408                $file->name      = !empty($name)?$name:$upload->filename;
00409                $file->extension = $upload->extension;       
00410                $file->size      = $upload->size;
00411                $file->parentid  = $this->folder->objectid;
00412      
00413                $file->value     = $upload->value;
00414           }
00415 
00416           $file->add(); // Datei hinzufuegen
00417           $this->addNotice('file',$file->name,'ADDED','ok');
00418 
00419           $this->folder->setTimestamp();
00420 
00421           $this->setTemplateVar('tree_refresh',true);
00422      }    
00423 
00424 
00425 
00426      function createnewlink()
00427      {
00428           $type        = $this->getRequestVar('type'       );
00429           $name        = $this->getRequestVar('name'       );
00430           $filename    = $this->getRequestVar('filename'   );
00431           $description = $this->getRequestVar('description');
00432           
00433           if   ( !empty($name) )
00434           {
00435                $link = new Link();
00436                $link->name           = $name;
00437                $link->desc           = $description;
00438                $link->parentid       = $this->folder->objectid;
00439 
00440                $link->isLinkToObject = false;
00441                $link->url            = $this->getRequestVar('name');
00442 
00443                $this->addNotice('link',$link->name,'ADDED','ok');
00444 
00445                $link->add();
00446           }
00447           else
00448           {
00449                $this->addValidationError('name');
00450                $this->callSubAction('createlink');
00451                return;
00452           }
00453           
00454           $this->folder->setTimestamp();
00455      }    
00456 
00457 
00458 
00459      function createnewpage()
00460      {
00461           $type        = $this->getRequestVar('type'       );
00462           $name        = $this->getRequestVar('name'       );
00463           $filename    = $this->getRequestVar('filename'   );
00464           $description = $this->getRequestVar('description');
00465           
00466           if   ( $this->getRequestVar('name') != '' )
00467           {
00468                $page = new Page();
00469                $page->name       = $name;
00470                $page->desc       = $description;
00471                $page->filename   = $filename;
00472                $page->templateid = $this->getRequestVar('templateid');
00473                $page->parentid   = $this->folder->objectid;
00474 
00475                $this->addNotice('page',$page->name,'ADDED','ok');
00476                $page->add();
00477           }
00478           else
00479           {
00480                $this->addValidationError('name');
00481                $this->callSubAction('createpage');
00482                return;
00483           }
00484           
00485           $this->folder->setTimestamp();
00486      }    
00487 
00488 
00489 
00494      function saveprop()
00495      {
00496           // Ordnereigenschaften speichern
00497           if   ( $this->getRequestVar('name') != '' )
00498                $this->folder->name     = $this->getRequestVar('name'    );
00499           elseif ($this->getRequestVar('filename') != '' )
00500                $this->folder->name     = $this->getRequestVar('filename');
00501           else
00502           {
00503                $this->addValidationError('name');
00504                $this->addValidationError('filename');
00505                $this->callSubAction('prop');
00506                return;
00507           }
00508           
00509           $this->folder->filename = $this->getRequestVar('filename'   );
00510           $this->folder->desc     = $this->getRequestVar('description');
00511           $this->folder->save();
00512           $this->addNotice($this->folder->getType(),$this->folder->name,'PROP_SAVED','ok');
00513      }
00514 
00515 
00520      function delete()
00521      {
00522           if   ( $this->getRequestVar('delete') != '' )
00523           {
00524                // Ordner l?schen
00525                $this->folder->delete();
00526                $this->addNotice($this->folder->getType(),$this->folder->name,lang('DELETED'),'ok');
00527           }
00528      }
00529 
00530 
00531      // Reihenfolge von Objekten aendern
00532      function changesequence()
00533      {
00534           $ids = $this->folder->getObjectIds();
00535           $seq = 0;
00536           foreach( $ids as $id )
00537           {
00538                $seq++; // Sequenz um 1 erhoehen
00539                
00540                // Die beiden Ordner vertauschen
00541                if   ( $id == $this->getRequestVar('objectid1') )
00542                     $id = $this->getRequestVar('objectid2');
00543                elseif ( $id == $this->getRequestVar('objectid2') )
00544                     $id = $this->getRequestVar('objectid1');
00545                     
00546                $o = new Object( $id );
00547                $o->setOrderId( $seq );
00548      
00549                unset( $o ); // Selfmade Garbage Collection :-)
00550           }
00551           
00552           $this->addNotice($this->folder->getType(),$this->folder->name,'SEQUENCE_CHANGED','ok');
00553           $this->folder->setTimestamp();
00554 
00555           // Ordner anzeigen
00556           $this->callSubAction('order');
00557           
00558      }
00559 
00560 
00567      function edit()
00568      {
00569           $type = $this->getRequestVar('type'); // Typ der Aktion, z.B "copy" oder "move"
00570           
00571           switch( $type )
00572           {
00573                case 'move':
00574                case 'copy':
00575                case 'link':
00576                     // Liste von m�glichen Zielordnern anzeigen
00577      
00578                     $otherfolder = array();
00579                     foreach( $this->folder->getAllFolders() as $id )
00580                     {
00581                          $f = new Folder( $id );
00582                          
00583                          // Beim Verkn�pfen muss im Zielordner die Berechtigung zum Erstellen
00584                          // von Verkn�pfungen vorhanden sein.
00585                          //
00586                          // Beim Verschieben und Kopieren muss im Zielordner die Berechtigung
00587                          // zum Erstellen von Ordner, Dateien oder Seiten vorhanden sein.
00588                          if   ( ( $type=='link' && $f->hasRight( ACL_CREATE_LINK ) ) || 
00589                                 ( ( $type=='move' || $type == 'copy' ) && 
00590                                   ( $f->hasRight(ACL_CREATE_FOLDER) || $f->hasRight(ACL_CREATE_FILE) || $f->hasRight(ACL_CREATE_PAGE) ) ) )
00591                               // Zielordner hinzuf�gen
00592                               $otherfolder[$id] = FILE_SEP.implode( FILE_SEP,$f->parentObjectNames(false,true) );
00593                     }
00594                     
00595                     // Zielordner-Liste alphabetisch sortieren
00596                     asort( $otherfolder );
00597                               
00598                     $this->setTemplateVar('folder',$otherfolder);
00599                     
00600                     break;
00601                     
00602                case 'archive':
00603                     $this->setTemplateVar('ask_filename','');
00604                     break;
00605 
00606                case 'delete':
00607                     $this->setTemplateVar('ask_commit','');
00608                     break;
00609                     
00610                default:
00611                     exit("trouble");
00612                     
00613           } // switch
00614           
00615           $ids        = $this->folder->getObjectIds();
00616           $objectList = array();
00617 
00618           foreach( $ids as $id )
00619           {
00620                // Nur, wenn Objekt ausgewaehlt wurde
00621                if   ( !$this->hasRequestVar('obj'.$id) )
00622                     continue;
00623 
00624                $o = new Object( $id );
00625                $o->load();
00626                
00627                // F�r die gew�nschte Aktion m�ssen pro Objekt die entsprechenden Rechte
00628                // vorhanden sein.
00629                if   ( $type == 'copy'   && $o->hasRight( ACL_READ   ) ||
00630                       $type == 'move'   && $o->hasRight( ACL_DELETE ) ||
00631                       $type == 'link'   && $o->hasRight( ACL_READ   ) ||
00632                       $type == 'delete' && $o->hasRight( ACL_DELETE )    )
00633                     $objectList[ $id ] = $o->getProperties();
00634           }
00635           
00636           $this->setTemplateVar('type'  ,$type       );
00637           $this->setTemplateVar('objectlist',$objectList );
00638           
00639           // Komma-separierte Liste von ausgew�hlten Objekt-Ids erzeugen 
00640           $this->setTemplateVar('ids',join(array_keys($objectList),',') );
00641      }
00642 
00643 
00644 
00648      function multiple()
00649      {
00650           $type           = $this->getRequestVar('type');
00651           $ids            = explode(',',$this->getRequestVar('ids'));
00652           $targetObjectId = $this->getRequestVar('targetobjectid');
00653 
00654           foreach( $ids as $id )
00655           {
00656                $o = new Object( $id );
00657                $o->load();
00658 
00659                switch( $type )
00660                {
00661                     case 'move':
00662                          if   ( $o->isFolder )
00663                          {
00664                               $f = new Folder( $id );
00665                               $allsubfolders = $f->getAllSubFolderIds();
00666                               
00667                               // Wenn
00668                               // - Das Zielverzeichnis sich nicht in einem Unterverzeichnis des zu verschiebenen Ordners liegt
00669                               // und
00670                               // - Das Zielverzeichnis nicht der zu verschiebene Ordner ist
00671                               // dann verschieben
00672                               if   ( !in_array($targetObjectId,$allsubfolders) && $id != $targetObjectId )
00673                               {
00674                                    $this->addNotice($o->getType(),$o->name,'MOVED','ok');
00675                                    //$o->setParentId( $targetObjectId );
00676                               }
00677                               else
00678                               {
00679                                    $this->addNotice($o->getType(),$o->name,'ERROR','error');
00680                               }
00681                          }
00682                          else
00683                          {
00684                               $o->setParentId( $targetObjectId );
00685                               $this->addNotice($o->getType(),$o->name,'MOVED','ok');
00686                          }
00687                          break;
00688      
00689                     case 'copy':
00690                          switch( $o->getType() )
00691                          {
00692                               case 'folder':
00693                                    // Ordner zur Zeit nicht kopieren
00694                                    // Funktion waere zu verwirrend
00695                                    $this->addNotice($o->getType(),$o->name,'CANNOT_COPY_FOLDER','error');
00696                                    break;
00697                               
00698                               case 'file':
00699                                    $f = new File( $id );
00700                                    $f->load();
00701                                    $f->filename = '';
00702                                    $f->name     = lang('GLOBAL_COPY_OF').' '.$f->name;
00703                                    $f->parentid = $targetObjectId;
00704                                    $f->add();
00705                                    $f->copyValueFromFile( $id );
00706                                    $this->addNotice($o->getType(),$o->name,'COPIED','ok');
00707                                    break;
00708                               
00709                               case 'page':
00710                                    $p = new Page( $id );
00711                                    $p->load();
00712                                    $p->filename = '';
00713                                    $p->name     = lang('GLOBAL_COPY_OF').' '.$p->name;
00714                                    $p->parentid = $targetObjectId;
00715                                    $p->add();
00716                                    $p->copyValuesFromPage( $id );
00717                                    $this->addNotice($o->getType(),$o->name,'COPIED','ok');
00718                                    break;
00719                               
00720                               case 'link':
00721                                    $l = new Link( $id );
00722                                    $l->load();
00723                                    $l->filename = '';
00724                                    $l->name     = lang('GLOBAL_COPY_OF').' '.$l->name;
00725                                    $l->parentid = $targetObjectId;
00726                                    $l->add();
00727                                    $this->addNotice($o->getType(),$o->name,'COPIED','ok');
00728                                    break;
00729                               
00730                               default:
00731                                    die('fatal: what type to delete?');
00732                          }
00733                          $notices[] = lang('COPIED');
00734                          break;
00735      
00736                     case 'link':
00737 
00738                          if   ( $o->isFile  ||
00739                                 $o->isPage  )  // Nur Seiten oder Dateien sind verknuepfbar
00740                          {
00741                               $link = new Link();
00742                               $link->parentid       = $targetObjectId;
00743                     
00744                               $link->linkedObjectId = $id;
00745                               $link->isLinkToObject = true;
00746                               $link->name           = lang('GLOBAL_LINK_TO').' '.$o->name;
00747                               $link->add();
00748                               $this->addNotice($o->getType(),$o->name,'LINKED','ok');
00749                          }
00750                          else
00751                          {
00752                               $this->addNotice($o->getType(),$o->name,'ERROR','error');
00753                          }
00754                          break;
00755      
00756                     case 'delete':
00757 
00758                          if   ( $this->hasRequestVar('commit') ) 
00759                          {
00760                               switch( $o->getType() )
00761                               {
00762                                    case 'folder':
00763                                         $f = new Folder( $id );
00764                                         $f->deleteAll();
00765                                         break;
00766                                    
00767                                    case 'file':
00768                                         $f = new File( $id );
00769                                         $f->delete();
00770                                         break;
00771                                    
00772                                    case 'page':
00773                                         $p = new Page( $id );
00774                                         $p->load();
00775                                         $p->delete();
00776                                         break;
00777                                    
00778                                    case 'link':
00779                                         $l = new Link( $id );
00780                                         $l->delete();
00781                                         break;
00782                                    
00783                                    default:
00784                                         Http::serverError('Internal Error while deleting: What type to delete?');
00785                               }
00786                               $this->addNotice($o->getType(),$o->name,'DELETED',OR_NOTICE_OK);
00787                          }
00788                          else
00789                          {
00790                               $this->addNotice($o->getType(),$o->name,'NOTHING_DONE',OR_NOTICE_WARN);
00791                          }
00792                          
00793                          break;
00794 
00795                     default:
00796                          $this->addNotice($o->getType(),$o->name,'ERROR','error');
00797                }
00798 
00799           }
00800 
00801           $this->folder->setTimestamp();
00802           
00803           // Ordner anzeigen
00804           $this->callSubAction('show');
00805      }
00806 
00807 
00808      // Reihenfolge von Objekten aendern
00809      function reorder()
00810      {
00811           $type = $this->getRequestVar('type');
00812           
00813           switch( $type )
00814           {
00815                case 'type':
00816                     $ids = $this->folder->getObjectIdsByType();
00817                     break;
00818 
00819                case 'name':
00820                     $ids = $this->folder->getObjectIdsByName();
00821                     break;
00822 
00823                case 'lastchange':
00824                     $ids = $this->folder->getObjectIdsByLastChange();
00825                     break;
00826 
00827                case 'flip':
00828                     $ids = $this->folder->getObjectIds();
00829                     $ids = array_reverse( $ids ); // Reihenfolge drehen
00830                     
00831                     break;
00832 
00833                default:
00834                     Http::sendStatus(400,'Bad request','Unknown reordertype: '.$type );
00835           }
00836 
00837           // Und jetzt die neu ermittelte Reihenfolge speichern
00838           $seq = 0;
00839           foreach( $ids as $id )
00840           {
00841                $seq++; // Sequenz um 1 erhoehen
00842                
00843                $o = new Object( $id );
00844                $o->setOrderId( $seq );
00845      
00846                unset( $o );
00847           }
00848           $this->addNotice($this->folder->getType(),$this->folder->name,'SEQUENCE_CHANGED','ok');
00849 
00850           $this->folder->setTimestamp();
00851           
00852           // Ordner anzeigen
00853           $this->callSubAction('order');
00854      }
00855 
00856 
00857      function settop()
00858      {
00859           $o = new Object( $this->getRequestVar('objectid1') );
00860           $o->setOrderId( 1 );
00861 
00862           $ids = $this->folder->getObjectIds();
00863           $seq = 1;
00864 
00865           foreach( $ids as $id )
00866           {
00867                if   ( $id != $this->getRequestVar('objectid1') )
00868                {
00869                     $seq++; // Sequenz um 1 erhoehen
00870 
00871                     $o = new Object( $id );
00872                     $o->setOrderId( $seq );
00873      
00874                     unset( $o ); // Selfmade Garbage Collection :-)
00875                }
00876           }
00877 
00878           $this->addNotice($this->folder->getType(),$this->folder->name,'SEQUENCE_CHANGED','ok');
00879           $this->folder->setTimestamp();
00880           
00881           // Ordner anzeigen
00882           $this->callSubAction('order');
00883      }
00884 
00885 
00886      function setbottom()
00887      {
00888           $ids = $this->folder->getObjectIds();
00889           $seq = 0;
00890 
00891           foreach( $ids as $id )
00892           {
00893                if   ( $id != $this->getRequestVar('objectid1') )
00894                {
00895                     $seq++; // Sequenz um 1 erhoehen
00896 
00897                     $o = new Object( $id );
00898                     $o->setOrderId( $seq );
00899      
00900                     unset( $o ); // Selfmade Garbage Collection :-)
00901                }
00902           }
00903 
00904           $seq++; // Sequenz um 1 erhoehen
00905           $o = new Object( $this->getRequestVar('objectid1') );
00906           $o->setOrderId( $seq );
00907 
00908           $this->addNotice($this->folder->getType(),$this->folder->name,'SEQUENCE_CHANGED','ok');
00909           $this->folder->setTimestamp();
00910           
00911           // Ordner anzeigen
00912           $this->callSubAction('order');
00913           
00914      }
00915 
00916 
00917      function create()
00918      {
00919           // Maximale Dateigroesse.
00920           $maxSizeBytes = $this->maxFileSize();
00921           $this->setTemplateVar('max_size' ,($maxSizeBytes/1024).' KB' );
00922           $this->setTemplateVar('maxlength',$maxSizeBytes );
00923           
00924           $all_templates = Template::getAll();
00925           $this->setTemplateVar('templates' ,$all_templates );
00926           
00927           if   ( count($all_templates) == 0 )
00928                $this->addNotice('folder',$this->folder->name,'NO_TEMPLATES_AVAILABLE',OR_NOTICE_WARN);
00929           
00930           $this->setTemplateVar('objectid'  ,$this->folder->objectid );
00931      }
00932 
00933 
00934 
00935      function createfolder()
00936      {
00937           $this->setTemplateVar('objectid'  ,$this->folder->objectid );
00938      }
00939 
00940 
00941 
00948      function maxFileSize()
00949      {
00950           global $conf;
00951           
00952           // When querying memory size values:
00953           // Many ini memory size values, such as upload_max_filesize,
00954           // are stored in the php.ini file in shorthand notation.
00955           // ini_get() will return the exact string stored in the php.ini file
00956           // and NOT its integer equivalent.
00957           $sizes = array(10*1024*1024*1024); // Init with 10GB enough? :)
00958           
00959           foreach( array('upload_max_filesize','post_max_size','memory_limit') as $var )
00960           {
00961                $v = $this->stringToBytes(ini_get($var));
00962                
00963                if   ($v > 0 )
00964                     $sizes[] = $v;
00965           }
00966           
00967           $confMaxSize = intval($conf['content']['file']['max_file_size'])*1024; 
00968           if   ( $confMaxSize > 0 )
00969                $sizes[] = $confMaxSize;
00970           
00971           return min($sizes);
00972      }
00973 
00974      
00979      function createfile()
00980      {
00981           // Maximale Dateigroesse.
00982           $maxSizeBytes = $this->maxFileSize();
00983           $this->setTemplateVar('max_size' ,($maxSizeBytes/1024).' KB' );
00984           $this->setTemplateVar('maxlength',$maxSizeBytes );
00985           
00986           $this->setTemplateVar('objectid',$this->folder->objectid );
00987      }
00988 
00989      
00999      function stringToBytes($val)
01000      {
01001           $val  = trim($val);
01002           $last = strtolower($val{strlen($val)-1});
01003           // Achtung: Der Trick ist das "Fallthrough", kein "break" vorhanden!
01004           switch($last)
01005           {
01006                // The 'G' modifier is available since PHP 5.1.0
01007                case 'g':
01008                     $val *= 1024;
01009                case 'm':
01010                     $val *= 1024;
01011                case 'k':
01012                     $val *= 1024;
01013           }
01014           
01015           return intval($val);
01016      }
01017  
01018      
01019 
01020      function createlink()
01021      {
01022           $this->setTemplateVar('objectid'  ,$this->folder->objectid );
01023      }
01024 
01025 
01026      function createpage()
01027      {
01028           $all_templates = Template::getAll();
01029           $this->setTemplateVar('templates' ,$all_templates          );
01030           $this->setTemplateVar('objectid'  ,$this->folder->objectid );
01031 
01032           if   ( count($all_templates) == 0 )
01033                $this->addNotice('folder',$this->folder->name,'NO_TEMPLATES_AVAILABLE',OR_NOTICE_WARN);
01034      }
01035 
01036 
01041      function show()
01042      {
01043           global $conf_php;
01044 
01045           if   ( ! $this->folder->isRoot )
01046                $this->setTemplateVar('up_url',Html::url('main','folder',$this->folder->parentid));
01047 
01048           $this->setTemplateVar('writable',$this->folder->hasRight(ACL_WRITE) );
01049           
01050           $list = array();
01051 
01052           // Schleife ueber alle Objekte in diesem Ordner
01053           foreach( $this->folder->getObjects() as $o )
01054           {
01055                $id = $o->objectid;
01056 
01057                if   ( $o->hasRight(ACL_READ) )
01058                {
01059                     $list[$id]['name']     = Text::maxLaenge( 30,$o->name     );
01060                     $list[$id]['filename'] = Text::maxLaenge( 20,$o->filename );
01061                     $list[$id]['desc']     = Text::maxLaenge( 30,$o->desc     );
01062                     if   ( $list[$id]['desc'] == '' )
01063                          $list[$id]['desc'] = lang('GLOBAL_NO_DESCRIPTION_AVAILABLE');
01064                     $list[$id]['desc'] = $list[$id]['desc'].' - '.lang('GLOBAL_IMAGE').' '.$id; 
01065 
01066                     $list[$id]['type'] = $o->getType();
01067                     
01068                     $list[$id]['icon' ] = $o->getType();
01069                     $list[$id]['class'] = $o->getType();
01070                     $list[$id]['url' ] = Html::url('main',$o->getType(),$id);
01071                     
01072                     if   ( $o->getType() == 'file' )
01073                     {
01074                          $file = new File( $id );
01075                          $file->load();
01076                          $list[$id]['desc'] .= ' - '.intval($file->size/1000).'kB';
01077 
01078                          if   ( $file->isImage() )
01079                          {
01080                               $list[$id]['icon' ] = 'image';
01081                               $list[$id]['class'] = 'image';
01082                               //$list[$id]['url' ] = Html::url('file','show',$id) nur sinnvoll bei Lightbox-Anzeige
01083                          }
01084 //                       if   ( substr($file->mimeType(),0,5) == 'text/' )
01085 //                            $list[$id]['icon'] = 'text';
01086                     }
01087 
01088                     $list[$id]['date'] = $o->lastchangeDate;
01089                     $list[$id]['user'] = $o->lastchangeUser;
01090                }
01091           }
01092 
01093           $this->setTemplateVar('object'      ,$list            );
01094      }
01095 
01096 
01097      function select()
01098      {
01099           global $conf_php;
01100 
01101           $this->setTemplateVar('writable',$this->folder->hasRight(ACL_WRITE) );
01102           
01103           $list = array();
01104 
01105           // Schleife ueber alle Objekte in diesem Ordner
01106           foreach( $this->folder->getObjects() as $o )
01107           {
01108                $id = $o->objectid;
01109 
01110                if   ( $o->hasRight(ACL_READ) )
01111                {
01112                     $list[$id]['id']     = 'obj'.$id;
01113                     $list[$id]['name']     = Text::maxLaenge( 30,$o->name     );
01114                     $list[$id]['filename'] = Text::maxLaenge( 20,$o->filename );
01115                     $list[$id]['desc']     = Text::maxLaenge( 30,$o->desc     );
01116                     if   ( $list[$id]['desc'] == '' )
01117                          $list[$id]['desc'] = lang('GLOBAL_NO_DESCRIPTION_AVAILABLE');
01118                     $list[$id]['desc'] = 'ID '.$id.' - '.$list[$id]['desc']; 
01119 
01120                     $list[$id]['type'] = $o->getType();
01121                     
01122                     $list[$id]['icon'] = $o->getType();
01123 
01124                     if   ( $o->getType() == 'file' )
01125                     {
01126                          $file = new File( $id );
01127                          $file->load();
01128                          $list[$id]['desc'] .= ' - '.intval($file->size/1000).'kB';
01129 
01130                          if   ( substr($file->mimeType(),0,6) == 'image/' )
01131                               $list[$id]['icon'] = 'image';
01132 //                       if   ( substr($file->mimeType(),0,5) == 'text/' )
01133 //                            $list[$id]['icon'] = 'text';
01134                     }
01135 
01136                     $list[$id]['url' ] = Html::url('main',$o->getType(),$id);
01137                     $list[$id]['date'] = date( lang('DATE_FORMAT'),$o->lastchangeDate );
01138                     $list[$id]['user'] = $o->lastchangeUser;
01139                }
01140           }
01141 
01142           if   ( $this->folder->hasRight(ACL_WRITE) )
01143           {
01144                // Alle anderen Ordner ermitteln
01145                $otherfolder = array();
01146                foreach( $this->folder->getAllFolders() as $id )
01147                {
01148                     $f = new Folder( $id );
01149                     if   ( $f->hasRight( ACL_WRITE ) )
01150                          $otherfolder[$id] = FILE_SEP.implode( FILE_SEP,$f->parentObjectNames(false,true) );
01151                }
01152                asort( $otherfolder );
01153      
01154                $this->setTemplateVar('folder',$otherfolder);
01155      
01156                // URLs zum Umsortieren der Eintraege
01157                $this->setTemplateVar('order_url'      ,Html::url('folder','order',$this->folder->id) );
01158           }    
01159 
01160           $actionList = array();
01161           $actionList[] = array('type'=>'copy');
01162           $actionList[] = array('type'=>'link');
01163 
01164           if   ( $this->folder->hasRight(ACL_WRITE) )
01165           {
01166                $actionList[] = array('type'=>'move');
01167                $actionList[] = array('type'=>'delete');
01168           }
01169           
01170           $this->setTemplateVar('actionlist',$actionList );
01171 
01172           $this->setTemplateVar('object'      ,$list            );
01173           $this->setTemplateVar('act_objectid',$this->folder->id);
01174      }
01175 
01176 
01177 
01178 
01179 
01180 
01181      function order()
01182      {
01183           global $conf_php;
01184 
01185           $list = array();
01186           $last_objectid = 0;
01187 
01188           // Schleife ueber alle Objekte in diesem Ordner
01189           foreach( $this->folder->getObjects() as $o )
01190           {
01191                $id = $o->objectid;
01192 
01193                if   ( $o->hasRight(ACL_READ) )
01194                {
01195                     $list[$id]['name']     = Text::maxLaenge( 30,$o->name     );
01196                     $list[$id]['filename'] = Text::maxLaenge( 20,$o->filename );
01197                     $list[$id]['desc']     = Text::maxLaenge( 30,$o->desc     );
01198                     if   ( $list[$id]['desc'] == '' )
01199                          $list[$id]['desc'] = lang('GLOBAL_NO_DESCRIPTION_AVAILABLE');
01200                     $list[$id]['desc'] = 'ID '.$id.' - '.$list[$id]['desc']; 
01201 
01202                     $list[$id]['type'] = $o->getType();
01203                     
01204                     $list[$id]['icon'] = $o->getType();
01205 
01206                     if   ( $o->getType() == 'file' )
01207                     {
01208                          $file = new File( $id );
01209                          $file->load();
01210                          $list[$id]['desc'] .= ' - '.intval($file->size/1000).'kB';
01211 
01212                          if   ( $file->isImage() )
01213                               $list[$id]['icon'] = 'image';
01214                     }
01215 
01216                     $list[$id]['url' ] = Html::url('main',$o->getType(),$id);
01217                     $list[$id]['date'] = $o->lastchangeDate;
01218                     $list[$id]['user'] = $o->lastchangeUser;
01219 
01220                     if   ( $last_objectid != 0 && $o->hasRight(ACL_WRITE) )
01221                     {
01222                          $list[$id           ]['upurl'    ] = Html::url('folder','changesequence',0,array(
01223                                                                               'objectid1'=>$id,
01224                                                                               'objectid2'=>$last_objectid));
01225                          $list[$last_objectid]['downurl'  ] = $list[$id]['upurl'];
01226                          $list[$last_objectid]['bottomurl'] = Html::url('folder','setbottom',0,array(
01227                                                                               'objectid1'=>$last_objectid));
01228                          $list[$id           ]['topurl'   ] = Html::url('folder','settop',0,array(
01229                                                                               'objectid1'=>$id));
01230                     }
01231 
01232                     $last_objectid = $id;
01233                }
01234           }
01235 
01236           $this->setTemplateVar('flip_url'             ,Html::url('folder','reorder',0,array('type'=>'flip'      )) );
01237           $this->setTemplateVar('orderbyname_url'      ,Html::url('folder','reorder',0,array('type'=>'name'      )) );
01238           $this->setTemplateVar('orderbytype_url'      ,Html::url('folder','reorder',0,array('type'=>'type'      )) );
01239           $this->setTemplateVar('orderbylastchange_url',Html::url('folder','reorder',0,array('type'=>'lastchange')) );
01240           $this->setTemplateVar('object'      ,$list            );
01241           $this->setTemplateVar('act_objectid',$this->folder->id);
01242      }
01243 
01244 
01245      
01246      function prop()
01247      {
01248           $this->setTemplateVars( $this->folder->getProperties() );
01249           $this->setTemplateVar( 'full_filename',$this->folder->full_filename() );
01250      }
01251 
01252 
01253      function remove()
01254      {
01255           $this->setTemplateVars( $this->folder->getProperties() );
01256      }
01257 
01258 
01259      function pub()
01260      {
01261           // Schalter nur anzeigen, wenn sinnvoll
01262           $this->setTemplateVar('files'  ,count($this->folder->getFiles()) > 0 );
01263           $this->setTemplateVar('pages'  ,count($this->folder->getPages()) > 0 );
01264           $this->setTemplateVar('subdirs',count($this->folder->getSubFolderIds()) > 0 );
01265           $this->setTemplateVar('clean'  ,$this->folder->isRoot );
01266           
01267 //        $this->addNotice('folder',$this->folder->name,'MUCH_TIME',OR_NOTICE_WARN);
01268      }
01269 
01270 
01271      function pubnow()
01272      {
01273           if   ( !$this->folder->hasRight( ACL_PUBLISH ) )
01274                die('no rights for publish');
01275 
01276           $subdirs = ( $this->hasRequestVar('subdirs') );
01277           $pages   = ( $this->hasRequestVar('pages'  ) );
01278           $files   = ( $this->hasRequestVar('files'  ) );
01279 
01280           $publish = new Publish();
01281           
01282           $this->folder->publish = &$publish;
01283           $this->folder->publish( $pages,$files,$subdirs );
01284           $this->folder->publish->close();
01285 
01286           $list = array();
01287           foreach( $publish->publishedObjects as $o )
01288                $list[] = $o['full_filename'];
01289           
01290           if   ( !$publish->ok )
01291                $this->addNotice('folder',$this->folder->name,'PUBLISHED_ERROR',OR_NOTICE_ERROR,array(),$publish->log);
01292           else
01293                $this->addNotice('folder',$this->folder->name,'PUBLISHED',OR_NOTICE_OK,array(),$list);
01294                     
01295           // Wenn gewuenscht, das Zielverzeichnis aufraeumen
01296           if   ( $this->hasRequestVar('clean')      )
01297                $publish->clean();
01298 
01299           $this->callSubaction( 'pub' );
01300      }
01301      
01302      
01303      
01304      function checkMenu( $name )
01305      {
01306           switch( $name)
01307           {
01308                case 'createfolder':
01309                     return $this->folder->hasRight(ACL_CREATE_FOLDER) && count($this->folder->parentObjectIds(true,true)) < MAX_FOLDER_DEPTH;
01310 
01311                case 'createfile':
01312                     return $this->folder->hasRight(ACL_CREATE_FILE);
01313 
01314                case 'createlink':
01315                     return $this->folder->hasRight(ACL_CREATE_LINK);
01316 
01317                case 'createpage':
01318                     return $this->folder->hasRight(ACL_CREATE_PAGE);
01319 
01320                case 'remove':
01321                     return count($this->folder->getObjectIds()) == 0;
01322 
01323                default:
01324                     return true;
01325           }
01326      }
01327 }

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