PageelementAction.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 
00023 
00030 class PageelementAction extends Action
00031 {
00032      var $defaultSubAction = 'edit';
00033 
00034 
00039      var $page;
00040 
00045      var $element;
00046 
00047 
00053      var $value;
00054 
00055 
00056 
00060      function PageelementAction()
00061      {
00062           $this->value = new Value();
00063 
00064           $this->page = Session::getObject();
00065 
00066           if   ( $this->getRequestId() != 0  )
00067           {
00068                $this->page = new Page( $this->getRequestId() );
00069                $this->page->load();
00070                Session::setObject( $this->page );
00071           }
00072           else
00073           {
00074                $this->page = Session::getObject();
00075           }
00076 
00077           if   ( $this->hasRequestVar('elementid') )
00078           {
00079                $this->element = new Element( $this->getRequestVar('elementid') );
00080                Session::setElement( $this->element );
00081           }
00082           else
00083           {
00084                $this->element = Session::getElement();
00085           }
00086      }
00087 
00088 
00089 
00093      function prop()
00094      {
00095           $language = Session::getProjectLanguage();
00096           $this->value->languageid = $language->languageid;
00097           $this->value->objectid   = $this->page->objectid;
00098           $this->value->pageid     = $this->page->pageid;
00099           $this->value->page       = $this->page;
00100           $this->value->simple = false;
00101           $this->value->element = &$this->element;
00102           $this->value->element->load();
00103           $this->value->publish = false;
00104           $this->value->load();
00105 
00106           $this->setTemplateVar('name'        ,$this->value->element->name     );
00107           $this->setTemplateVar('description' ,$this->value->element->desc     );
00108           $this->setTemplateVar('elementid'   ,$this->value->element->elementid);
00109           $this->setTemplateVar('element_type',$this->value->element->type     );
00110 
00111           if   ( $this->value->element->type == 'longtext' && $this->value->element->wiki )
00112           {
00113                $this->setTemplateVar('text',$this->value->text);
00114           }
00115           
00116           $user = new User( $this->value->lastchangeUserId );
00117           $user->load();
00118           $this->setTemplateVar('lastchange_user',$user);
00119           $this->setTemplateVar('lastchange_date',$this->value->lastchangeTimeStamp);
00120 
00121           $t = new Template( $this->page->templateid );
00122           $t->load();
00123           $this->setTemplateVar('template_name',$t->name );
00124           $this->setTemplateVar('template_url' ,Html::url('template','prop',$t->templateid) );
00125 
00126           $this->setTemplateVar('element_name' ,$this->value->element->name );
00127           $this->setTemplateVar('element_url'  ,Html::url('element','name',$this->value->element->elementid) );
00128 
00129      }
00130 
00131 
00132 
00138      function edit()
00139      {
00140           $language = Session::getProjectLanguage();
00141           $this->value->languageid = $language->languageid;
00142           $this->value->objectid   = $this->page->objectid;
00143           $this->value->pageid     = $this->page->pageid;
00144           $this->value->element = &$this->element;
00145           $this->value->element->load();
00146           $this->value->publish = false;
00147 
00148           if   ( intval($this->value->valueid)!=0 )
00149                $this->value->loadWithId();
00150           else
00151                $this->value->load();
00152 
00153           $this->setTemplateVar('name'     ,$this->value->element->name     );
00154           $this->setTemplateVar('desc'     ,$this->value->element->desc     );
00155           $this->setTemplateVar('elementid',$this->value->element->elementid);
00156           $this->setTemplateVar('type'     ,$this->value->element->type     );
00157           $this->setTemplateVar('value_time',time() );
00158           
00159 
00160           $this->value->page             = new Page( $this->page->objectid );
00161           $this->value->page->languageid = $this->value->languageid;
00162           $this->value->page->load();
00163 
00164           $this->setTemplateVar( 'objectid',$this->value->page->objectid );
00165 
00166           if   ( $this->value->page->hasRight(ACL_RELEASE) )
00167           $this->setTemplateVar( 'release',true  );
00168           if   ( $this->value->page->hasRight(ACL_PUBLISH) )
00169           $this->setTemplateVar( 'publish',false );
00170 
00171           $funktionName = 'edit'.$this->value->element->type;
00172 
00173           if   ( ! method_exists($this,$funktionName) )
00174           Http::serverError('Method does not exist: PageElementAction#'.$funktionName );
00175                
00176           $this->$funktionName(); // Aufruf der Funktion "edit<Elementtyp>()".
00177      }
00178 
00179 
00180 
00185      function editdate()
00186      {
00187           global $conf;
00188           $date =  $this->value->date;
00189 
00190           // Wenn Datum nicht vorhanden, dann aktuelles Datum verwenden
00191           if   ( $date == 0 )
00192           $date = intval(time()/60)*60;
00193 
00194           $this->setTemplateVar('ansidate',date( 'Y-m-d H:i:s',$date ) );
00195           $this->setTemplateVar('date'    ,$date);
00196 
00197           if   ( $this->getSessionVar('pageaction') != '' )
00198           $this->setTemplateVar('old_pageaction',$this->getSessionVar('pageaction'));
00199           else $this->setTemplateVar('old_pageaction','show'                            );
00200 
00201 
00202           $date = $this->value->date;
00203 
00204           // Wenn Datum nicht vorhanden, dann aktuelles Datum verwenden
00205           if   ( $this->hasRequestVar('year') )
00206           {
00207                $date = mktime( $this->getRequestVar('hour'),
00208                $this->getRequestVar('minute'),
00209                $this->getRequestVar('second'),
00210                $this->getRequestVar('month'),
00211                $this->getRequestVar('day'),
00212                $this->getRequestVar('year')    );
00213           }
00214           $year   = date('Y',$date);
00215           $month  = date('n',$date);
00216           $day    = date('j',$date);
00217           $hour   = date('G',$date);
00218           $minute = date('i',$date);
00219           $second = date('s',$date);
00220           $this->setTemplateVar('year'  ,$year   );
00221           $this->setTemplateVar('month' ,$month  );
00222           $this->setTemplateVar('day'   ,$day    );
00223           $this->setTemplateVar('hour'  ,$hour   );
00224           $this->setTemplateVar('minute',$minute );
00225           $this->setTemplateVar('second',$second );
00226 
00227           $this->setTemplateVar('monthname',lang('DATE_MONTH'.date('n',$date)) );
00228           $this->setTemplateVar('yearname' ,date('Y',$date) );
00229 
00230 
00231           // Zwischenberechnungen
00232           $heuteTag         = intval(date('j'));
00233           $monatLetzterTag  = intval(date('t',$date));
00234           $monatErsterDatum = $date-(($day-1)*86400);
00235           $wocheNr          = date( 'W',$monatErsterDatum );
00236           $wochentagErster  = date( 'w',$monatErsterDatum );
00237 
00238 
00239           $weekdayOffset = intval($conf['editor']['calendar']['weekday_offset']);
00240 
00241           // Alle Wochentage
00242           $weekdays = array();
00243           for  ( $i=0; $i<=6; $i++ )
00244           {
00245                $wday = ($i+$weekdayOffset)%7;
00246                $weekdays[$wday] = lang('DATE_WEEKDAY'.$wday);
00247           }
00248                
00249           $this->setTemplateVar('weekdays',$weekdays);
00250 
00251 
00252           $monat = array();
00253           $d = 0;
00254           $begin = false;
00255           do
00256           {
00257                $woche = array(); // Neue Woche
00258                     
00259                for  ( $i=0; $i<=6; $i++ ) // Alle Wochentage der Woche
00260                {
00261                     $wday = ($i+$weekdayOffset)%7;
00262                     $tag = array(); // Neuer Tag
00263 
00264                     if   (!$begin && $wday == $wochentagErster)
00265                     $begin = true;
00266 
00267                     if   ( $begin && $d < $monatLetzterTag )
00268                     {
00269                          $d++;
00270                          $tag['nr']    = $d;
00271                          $tag['today'] = ($year==date('Y') && $month==date('n') && $d==$heuteTag);
00272                          if   ($d != $day)
00273                          $tag['url'] = Html::url( 'pageelement','edit','',
00274                          array('elementid'=>$this->element->elementid,'mode'=>'edit',
00275                                                              'year'  =>$year  ,
00276                                                              'month' =>$month ,
00277                                                              'day'   =>$d     ,
00278                                                              'hour'  =>$hour  ,
00279                                                              'minute'=>$minute,
00280                                                              'second'=>$second  ) );
00281                          else
00282                          $tag['url'] = '';
00283                     }
00284                     else
00285                     {
00286                          $tag['nr'    ]='';
00287                          $tag['today' ]=false;
00288                          $tag['url'   ]='';
00289                     }
00290                     $woche[] = $tag;
00291 
00292                }
00293                $monat[$wocheNr] = $woche;
00294                $wocheNr++;
00295           }
00296           while( $d < $monatLetzterTag-1 );
00297           //        Html::debug($monat);
00298           $this->setTemplateVar('weeklist',$monat);
00299 
00300           $this->setTemplateVar('actdate' ,date( lang('DATE_FORMAT'),$date ) );
00301           $this->setTemplateVar('todayurl',Html::url( 'pageelement','edit','',
00302           array('elementid'=>$this->element->elementid,'mode'=>'edit',
00303                                                              'year'  =>date('Y'),
00304                                                              'month' =>date('n'),
00305                                                              'day'   =>date('j'),
00306                                                              'hour'  =>date('G'),
00307                                                              'minute'=>date('i'),
00308                                                              'second'=>date('s') ) ) );
00309           $this->setTemplateVar('lastyearurl',Html::url( 'pageelement','edit','',
00310           array('elementid'=>$this->element->elementid,'mode'=>'edit',
00311                                                              'year'  =>$year-1,
00312                                                              'month' =>$month ,
00313                                                              'day'   =>$day   ,
00314                                                              'hour'  =>$hour  ,
00315                                                              'minute'=>$minute,
00316                                                              'second'=>$second  ) ) );
00317           $this->setTemplateVar('nextyearurl',Html::url( 'pageelement','edit','',
00318           array('elementid'=>$this->element->elementid,'mode'=>'edit',
00319                                                              'year'  =>$year+1 ,
00320                                                              'month' =>$month ,
00321                                                              'day'   =>$day   ,
00322                                                              'hour'  =>$hour  ,
00323                                                              'minute'=>$minute,
00324                                                              'second'=>$second  ) ) );
00325           $this->setTemplateVar('lastmonthurl',Html::url( 'pageelement','edit','',
00326           array('elementid'=>$this->element->elementid,'mode'=>'edit',
00327                                                              'year'  =>$year  ,
00328                                                              'month' =>$month-1,
00329                                                              'day'   =>$day   ,
00330                                                              'hour'  =>$hour  ,
00331                                                              'minute'=>$minute,
00332                                                              'second'=>$second  ) ) );
00333           $this->setTemplateVar('nextmonthurl',Html::url( 'pageelement','edit','',
00334           array('elementid'=>$this->element->elementid,'mode'=>'edit',
00335                                                              'year'  =>$year  ,
00336                                                              'month' =>$month+1,
00337                                                              'day'   =>$day   ,
00338                                                              'hour'  =>$hour  ,
00339                                                              'minute'=>$minute,
00340                                                              'second'=>$second  ) ) );
00341            
00342           //        $this->setTemplateVar('date'    ,$date);
00343 
00344 
00345 
00346           if   ( $this->getSessionVar('pageaction') != '' )
00347           $this->setTemplateVar('old_pageaction',$this->getSessionVar('pageaction'));
00348           else $this->setTemplateVar('old_pageaction','show'                            );
00349 
00350 
00351           $all_years   = array();
00352           $all_months  = array();
00353           $all_days    = array();
00354           $all_hours   = array();
00355           $all_minutes = array();
00356           for( $i=$year-100; $i<=$year+100;$i++ ) $all_years  [$i] = $i;
00357           for( $i=1;    $i<=12;  $i++ ) $all_months [$i] = lang('DATE_MONTH'.$i);
00358           for( $i=1;    $i<=31;  $i++ ) $all_days   [$i] = str_pad($i,2,'0',STR_PAD_LEFT);
00359           for( $i=0;    $i<=23;  $i++ ) $all_hours  [$i] = str_pad($i,2,'0',STR_PAD_LEFT);
00360           for( $i=0;    $i<=59;  $i++ ) $all_minutes[$i] = str_pad($i,2,'0',STR_PAD_LEFT);
00361 
00362           $this->setTemplateVar('all_years'  ,$all_years  );
00363           $this->setTemplateVar('all_months' ,$all_months );
00364           $this->setTemplateVar('all_days'   ,$all_days   );
00365           $this->setTemplateVar('all_hours'  ,$all_hours  );
00366           $this->setTemplateVar('all_minutes',$all_minutes);
00367           $this->setTemplateVar('all_seconds',$all_minutes);
00368      }
00369 
00370 
00371 
00376      function editlink()
00377      {
00378 
00379           // Ermitteln, welche Objekttypen verlinkt werden d�rfen.
00380           if   ( empty($this->value->element->subtype) )
00381           $types = array('page','file','link'); // Fallback: Alle erlauben :)
00382           else
00383           $types = explode(',',$this->value->element->subtype );
00384 
00385           $objects = array();
00386 
00387           foreach( Folder::getAllObjectIds($types) as $id )
00388           {
00389                $o = new Object( $id );
00390                $o->load();
00391                     
00392                //             if   ( in_array( $o->getType(),$types ))
00393                //             {
00394                $f = new Folder( $o->parentid );
00395                //                       $f->load();
00396 
00397                $objects[ $id ]  = lang( 'GLOBAL_'.$o->getType() ).': ';
00398                $objects[ $id ] .=  implode( FILE_SEP,$f->parentObjectNames(false,true) );
00399                $objects[ $id ] .= FILE_SEP.$o->name;
00400                //             }
00401                }
00402 
00403                asort( $objects ); // Sortieren
00404 
00405                $this->setTemplateVar('objects'         ,$objects);
00406                $this->setTemplateVar('linkobjectid',$this->value->linkToObjectId);
00407 
00408                if   ( $this->getSessionVar('pageaction') != '' )
00409                $this->setTemplateVar('old_pageaction',$this->getSessionVar('pageaction'));
00410                else $this->setTemplateVar('old_pageaction','show'                            );
00411 
00412                $this->forward('pageelement_edit_'.$this->value->element->type);
00413           }
00414 
00415 
00416 
00417           function link()
00418           {
00419                $language = Session::getProjectLanguage();
00420                $this->value->languageid = $language->languageid;
00421                $this->value->objectid   = $this->page->objectid;
00422                $this->value->pageid     = $this->page->pageid;
00423                $this->value->element = &$this->element;
00424                $this->value->element->load();
00425                $this->value->publish = false;
00426                $this->value->load();
00427 
00428                // Ermitteln, welche Objekttypen verlinkt werden d�rfen.
00429                if   ( empty($this->value->element->subtype) )
00430                $types = array('page','file','link'); // Fallback: Alle erlauben :)
00431                else
00432                $types = explode(',',$this->value->element->subtype );
00433 
00434                $objects = array();
00435 
00436                $t = new Template( $this->page->templateid );
00437 
00438                foreach( $t->getDependentObjectIds() as $id )
00439                {
00440                     $o = new Object( $id );
00441                     $o->load();
00442                          
00443                     //             if   ( in_array( $o->getType(),$types ))
00444                     //             {
00445                     $f = new Folder( $o->parentid );
00446                     //                       $f->load();
00447 
00448                     $objects[ $id ]  = lang( 'GLOBAL_'.$o->getType() ).': ';
00449                     $objects[ $id ] .=  implode( FILE_SEP,$f->parentObjectNames(false,true) );
00450                     $objects[ $id ] .= FILE_SEP.$o->name;
00451                     //             }
00452                }
00453 
00454                asort( $objects ); // Sortieren
00455 
00456                $this->setTemplateVar('objects'         ,$objects);
00457                $this->setTemplateVar('linkobjectid',$this->value->linkToObjectId);
00458 
00459                if   ( $this->getSessionVar('pageaction') != '' )
00460                $this->setTemplateVar('old_pageaction',$this->getSessionVar('pageaction'));
00461                else $this->setTemplateVar('old_pageaction','show'                            );
00462 
00463                $this->value->page             = new Page( $this->page->objectid );
00464                $this->value->page->languageid = $this->value->languageid;
00465                $this->value->page->load();
00466 
00467                $this->setTemplateVar( 'release',$this->value->page->hasRight(ACL_RELEASE) );
00468                $this->setTemplateVar( 'publish',$this->value->page->hasRight(ACL_PUBLISH) );
00469 
00470                $this->setTemplateVar( 'objectid',$this->value->page->objectid );
00471 
00472                $this->forward('pageelement_edit_'.$this->value->element->type);
00473           }
00474 
00475 
00476 
00481           function editselect()
00482           {
00483                $this->setTemplateVar( 'items',$this->value->element->getSelectItems() );
00484                $this->setTemplateVar( 'text' ,$this->value->text                      );
00485 
00486 
00487                if   ( $this->getSessionVar('pageaction') != '' )
00488                $this->setTemplateVar('old_pageaction',$this->getSessionVar('pageaction'));
00489                else $this->setTemplateVar('old_pageaction','show'                            );
00490 
00491                $this->forward('pageelement_edit_'.$this->value->element->type);
00492           }
00493 
00494 
00495 
00500           function editlist()
00501           {
00502                $this->editinsert();
00503           }
00504           
00505           
00506           
00511           function editinsert()
00512           {
00513                // Auswahl ueber alle Elementtypen
00514                $objects = array();
00515                foreach( Folder::getAllFolders() as $id )
00516                {
00517                     $f = new Folder( $id );
00518                     $f->load();
00519                          
00520                     $objects[ $id ]  = lang( 'GLOBAL_'.$f->getType() ).': ';
00521                     $objects[ $id ] .=  implode( ' &raquo; ',$f->parentObjectNames(false,true) );
00522                }
00523 
00524                asort( $objects ); // Sortieren
00525 
00526                $this->setTemplateVar('objects'         ,$objects);
00527                $this->setTemplateVar('linkobjectid',$this->value->linkToObjectId);
00528 
00529 
00530                if   ( $this->getSessionVar('pageaction') != '' )
00531                $this->setTemplateVar('old_pageaction',$this->getSessionVar('pageaction'));
00532                else $this->setTemplateVar('old_pageaction','show'                            );
00533           }
00534 
00535 
00536 
00541           function editnumber()
00542           {
00543                $this->setTemplateVar('number',$this->value->number / pow(10,$this->value->element->decimals) );
00544 
00545                if   ( $this->getSessionVar('pageaction') != '' )
00546                $this->setTemplateVar('old_pageaction',$this->getSessionVar('pageaction'));
00547                else $this->setTemplateVar('old_pageaction','show'                            );
00548 
00549                $this->forward('pageelement_edit_'.$this->value->element->type);
00550           }
00551 
00552 
00558           function editlongtext()
00559           {
00560                if   ($this->value->element->wiki)
00561                     $this->setTemplateVar( 'editor','wiki' );
00562                elseif    ($this->value->element->html)
00563                     $this->setTemplateVar( 'editor','html' );
00564                else
00565                     $this->setTemplateVar( 'editor','text' );
00566 
00567                if ( !isset($this->templateVars['text']))
00568                     // Möglicherweise ist die Ausgabevariable bereits gesetzt, wenn man bereits
00569                     // einen Text eingegeben hat (Vorschaufunktion).
00570                     $this->setTemplateVar( 'text',$this->convertOIDs( $this->value->text ) );
00571 
00572                if   (! $this->isEditMode() )
00573                {
00574                     $this->value->generate(); // Inhalt erzeugen.
00575                     $this->setTemplateVar('text',$this->convertOIDs( $this->value->value ));
00576                }
00577 
00578                if   ( $this->getSessionVar('pageaction') != '' )
00579                $this->setTemplateVar('old_pageaction',$this->getSessionVar('pageaction'));
00580                else $this->setTemplateVar('old_pageaction','show'                            );
00581 
00582 
00583                if   ( $this->element->wiki )
00584                {
00585                     // Ermitteln aller verlinkbaren Objekte (fuer Editor)
00586                     $objects = array();
00587 
00588                     foreach( Folder::getAllObjectIds() as $id )
00589                     {
00590                          $o = new Object( $id );
00591                          $o->load();
00592 
00593                          if   ( $o->getType() != 'folder' )
00594                          {
00595                               $f = new Folder( $o->parentid );
00596                               $objects[ $id ]  = lang( 'GLOBAL_'.$o->getType() ).': ';
00597                               $objects[ $id ] .=  implode( FILE_SEP,$f->parentObjectNames(false,true) );
00598                               $objects[ $id ] .= FILE_SEP.$o->name;
00599                          }
00600                     }
00601                     asort( $objects ); // Sortieren
00602 
00603                          
00604                     $transformer = new Transformer();
00605                     $transformer->text = $this->value->text;
00606                     $transformer->parseDocument();
00607                     $this->setTemplateVar( 'document',$transformer->doc );
00608                     
00609                     if ( !isset($this->templateVars['text']))
00610                          // Möglicherweise ist die Ausgabevariable bereits gesetzt, wenn man bereits
00611                          // einen Text eingegeben hat (Vorschaufunktion).
00612                          $this->setTemplateVar( 'text',$this->value->text          );
00613                     $this->setTemplateVar( 'objects',$objects );
00614                     $this->setTemplateVar( 'images' ,$objects );
00615                }
00616 
00617           }
00618 
00619 
00620 
00626           function edittext()
00627           {
00628                $this->setTemplateVar( 'text',$this->value->text );
00629 
00630                if   ( $this->getSessionVar('pageaction') != '' )
00631                $this->setTemplateVar('old_pageaction',$this->getSessionVar('pageaction'));
00632                else $this->setTemplateVar('old_pageaction','show'                            );
00633           }
00634 
00635 
00636 
00640           function usevalue()
00641           {
00642                $this->value->valueid = $this->getRequestVar('valueid');
00643           }
00644 
00645 
00646 
00650           function release()
00651           {
00652                $this->value->valueid = intval($this->getRequestVar('valueid'));
00653                $this->value->loadWithId();
00654 
00655                if   ( $this->value->pageid != $this->page->pageid )
00656                die( 'cannot release, bad page' );
00657 
00658                // Pruefen, ob Berechtigung zum Freigeben besteht
00659                if   ( !$this->page->hasRight(ACL_RELEASE) )
00660                die( 'cannot release, no right' );
00661 
00662                // Inhalt freigeben
00663                $this->value->release();
00664           }
00665 
00666 
00670           function archive()
00671           {
00672                $this->page->public = true;
00673                $this->page->simple = true;
00674                $this->page->load();
00675                $this->value->page = &$this->page;
00676 
00677                $this->value->simple = true;
00678                $language = Session::getProjectLanguage();
00679                $this->value->languageid = $language->languageid;
00680                $this->value->objectid   = $this->page->objectid;
00681                $this->value->pageid     = Page::getPageIdFromObjectId( $this->page->objectid );
00682                $this->value->element    = &$this->element;
00683                $this->value->element->load();
00684 
00685                $list         = array();
00686                //        $version_list = array();
00687                $lfd_nr       = 0;
00688 
00689                foreach( $this->value->getVersionList() as $value )
00690                {
00691                     $lfd_nr++;
00692                     $value->element = &$this->element;
00693                     $value->page    = &$this->page;
00694                     $value->simple  = true;
00695                     $value->generate();
00696                          
00697 
00698                     //             $date = date( lang('DATE_FORMAT'),$value->lastchangeTimeStamp);
00699                          
00700                     //             if   ( in_array(    $this->element->type,array('text','longtext') ) )
00701                     //                  $version_list[ $value->valueid ] = '('.$lfd_nr.') '.$date;
00702 
00703                     $zeile = array(  'value'     => Text::maxLaenge( 50,$value->value),
00704                                 'date'      => $value->lastchangeTimeStamp,     
00705                                 'lfd_nr'    => $lfd_nr,     
00706                                 'id'        => $value->valueid,  
00707                                 'user'      => $value->lastchangeUserName );
00708 
00709                     // Nicht aktive Inhalte k�nnen direkt bearbeitet werden und sind
00710                     // nach dem Speichern dann wieder aktiv (nat�rlich als n�chster/neuer Inhalt) 
00711                     if   ( ! $value->active )
00712                     $zeile['useUrl'] = Html::url('pageelement','usevalue',$this->page->objectid,array('valueid'  =>$value->valueid,'mode'=>'edit'));
00713 
00714                     // Freigeben des Inhaltes.
00715                     // Nur das aktive Inhaltselement kann freigegeben werden. Nat�rlich auch nur,
00716                     // wenn es nicht schon freigegeben ist.
00717                     if   ( ! $value->publish && $value->active )
00718                     $zeile['releaseUrl'] = Html::url('pageelement','release',$this->page->objectid,array('valueid'  =>$value->valueid ));
00719 
00720                     $zeile['public'] = $value->publish;
00721                     $zeile['active'] = $value->active;
00722 
00723                     $list[$lfd_nr] = $zeile;
00724 
00725                }
00726 
00727                if   ( in_array( $this->value->element->type, array('longtext') ) && $lfd_nr >= 2 )
00728                {
00729                     $this->setTemplateVar('compareid',$list[$lfd_nr-1]['id']);
00730                     $this->setTemplateVar('withid'   ,$list[$lfd_nr  ]['id']);
00731                }
00732 
00733                $this->setTemplateVar('name'     ,$value->element->name);
00734                $this->setTemplateVar('el'       ,$list                );
00735           }
00736 
00737 
00741           function diff()
00742           {
00743                $value1id = $this->getRequestVar('compareid');
00744                $value2id = $this->getRequestVar('withid'   );
00745 
00746                // Wenn Value1-Id groesser als Value2-Id, dann Variablen tauschen
00747                if   ( $value1id == $value2id )
00748                {
00749                     $this->addValidationError('compareid'   );
00750                     $this->addValidationError('withid'   ,'');
00751                     $this->callSubAction('archive');
00752                     return;
00753                }
00754 
00755                // Wenn Value1-Id groesser als Value2-Id, dann Variablen tauschen
00756                if   ( $value1id > $value2id )
00757                list($value1id,$value2id) = array( $value2id,$value1id );
00758 
00759 
00760                $value1 = new Value( $value1id );
00761                $value2 = new Value( $value2id );
00762                $value1->valueid = $value1id;
00763                $value2->valueid = $value2id;
00764 
00765                $value1->loadWithId();
00766                $value2->loadWithId();
00767 
00768                $this->setTemplateVar('date_left' ,$value1->lastchangeTimeStamp);
00769                $this->setTemplateVar('date_right',$value2->lastchangeTimeStamp);
00770 
00771                $text1 = explode("\n",$value1->text);
00772                $text2 = explode("\n",$value2->text);
00773 
00774                // Unterschiede feststellen.
00775                $res_diff = Text::diff($text1,$text2);
00776 
00777                list( $text1,$text2 ) = $res_diff;
00778 
00779                $diff = array();
00780                $i = 0;
00781                while( isset($text1[$i]) || isset($text2[$i]) )
00782                {
00783                     $line = array();
00784 
00785                     if   ( isset($text1[$i]['text']) )
00786                     $line['left'] = $text1[$i];
00787 
00788                     if   ( isset($text2[$i]['text']) )
00789                     $line['right'] = $text2[$i];
00790 
00791                     $i++;
00792                     $diff[] = $line;
00793                }
00794                $this->setTemplateVar('diff',$diff );
00795           }
00796 
00797 
00798 
00802           function save()
00803           {
00804                $this->element->load();
00805                $type = $this->element->type;
00806 
00807                if   ( empty($type))
00808                die('Error: No element type available.');
00809                     
00810                $funktionName = 'save'.$type;
00811 
00812                $this->$funktionName(); // Aufruf Methode "save<ElementTyp>()"
00813           }
00814 
00815 
00816 
00822           function savetext()
00823           {
00824                $value = new Value();
00825                $language = Session::getProjectLanguage();
00826                $value->languageid = $language->languageid;
00827                $value->objectid   = $this->page->objectid;
00828                $value->pageid     = Page::getPageIdFromObjectId( $this->page->objectid );
00829 
00830                if   ( $this->hasRequestVar('elementid') )
00831                $value->element = new Element( $this->getRequestVar('elementid') );
00832                else
00833                $value->element = Session::getElement();
00834 
00835                $value->element->load();
00836                $value->publish = false;
00837                $value->load();
00838 
00839                if   ( $this->hasRequestVar('linkobjectid') )
00840                $value->linkToObjectId = $this->getRequestVar('linkobjectid');
00841                else
00842                $value->text           = $this->getRequestVar('text');
00843 
00844                $this->afterSave($value);
00845           }
00846 
00847 
00848 
00858           function afterSave( $value )
00859           {
00860                $value->page = new Page( $value->objectid );
00861                $value->page->load();
00862 
00863 
00864                // Inhalt sofort freigegeben, wenn
00865                // - Recht vorhanden
00866                // - Freigabe gewuenscht
00867                if   ( $value->page->hasRight( ACL_RELEASE ) && $this->hasRequestVar('release') )
00868                     $value->publish = true;
00869                else
00870                     $value->publish = false;
00871 
00872                // Up-To-Date-Check
00873                $lastChangeTime = $value->getLastChangeTime();
00874                if   ( $lastChangeTime > $this->getRequestVar('value_time') )
00875                {
00876                     $this->addNotice('pageelement',$value->element->name,'CONCURRENT_VALUE_CHANGE',OR_NOTICE_WARN,array('last_change_time'=>date(lang('DATE_FORMAT'),$lastChangeTime)));
00877                }
00878 
00879                // Inhalt speichern
00880 
00881                // Wenn Inhalt in allen Sprachen gleich ist, dann wird der Inhalt
00882                // fuer jede Sprache einzeln gespeichert.
00883                if   ( $value->element->allLanguages )
00884                {
00885                     $project = Session::getProject();
00886                     foreach( $project->getLanguageIds() as $languageid )
00887                     {
00888                          $value->languageid = $languageid;
00889                          $value->save();
00890                     }
00891                }
00892                else
00893                {
00894                     // sonst nur 1x speichern (fuer die aktuelle Sprache)
00895                     $value->save();
00896                }
00897 
00898                $this->addNotice('pageelement',$value->element->name,'SAVED',OR_NOTICE_OK);
00899                $this->page->setTimestamp(); // "Letzte Aenderung" setzen
00900 
00901                // Falls ausgewaehlt die Seite sofort veroeffentlichen
00902                if   ( $value->page->hasRight( ACL_PUBLISH ) && $this->hasRequestVar('publish') )
00903                {
00904                     $this->page->publish();
00905                     $this->addNotice('pageelement',$value->element->name,'PUBLISHED',OR_NOTICE_OK);
00906                }
00907           }
00908 
00909 
00915           function savelongtext()
00916           {
00917                global $conf;
00918                $value = new Value();
00919                $language = Session::getProjectLanguage();
00920                $value->languageid = $language->languageid;
00921                $value->objectid   = $this->page->objectid;
00922                $value->pageid     = Page::getPageIdFromObjectId( $this->page->objectid );
00923 
00924                if   ( $this->hasRequestVar('elementid') )
00925                $value->element = new Element( $this->getRequestVar('elementid') );
00926                else
00927                $value->element = Session::getElement();
00928 
00929                $value->element->load();
00930                $value->publish = false;
00931                $value->load();
00932 
00933 
00934                if   ( $this->hasRequestVar('linkobjectid') )
00935                     $value->linkToObjectId = $this->getRequestVar('linkobjectid');
00936                else
00937                     $value->text           = $this->convertOIDs( $this->getRequestVar('text') );
00938 
00939                // Vorschau anzeigen
00940                if   ( $this->hasRequestVar('preview'  ) ||
00941                       $this->hasRequestVar('addmarkup')    )
00942                {
00943                     $inputText = $this->getRequestVar('text');
00944                     
00945                     if   ( $this->hasRequestVar('preview') )
00946                     {
00947                          $value->page             = $this->page;
00948                          $value->simple           = false;
00949                          $value->page->languageid = $value->languageid;
00950                          $value->page->load();
00951                          $value->generate();
00952                          $this->setTemplateVar('preview',$value->value );
00953                     }
00954 
00955                     if   ( $this->hasRequestVar('addmarkup') )
00956                     {
00957                          $conf_tags = $conf['editor']['text-markup'];
00958 
00959                          if   ( $this->hasRequestVar('addtext') ) // Nur, wenn ein Text eingegeben wurde
00960                          {
00961                               $addText = $this->getRequestVar('addtext');
00962 
00963                               if   ( $this->hasRequestVar('strong') )
00964                                    $inputText .= $conf_tags['strong-begin'].$addText.$conf_tags['strong-end'];
00965 
00966                               if   ( $this->hasRequestVar('emphatic') )
00967                                    $inputText .= $conf_tags['emphatic-begin'].$addText.$conf_tags['emphatic-end'];
00968 
00969                               if   ( $this->hasRequestVar('link') )
00970                                    $inputText .= '"'.$addText.'"'.$conf_tags['linkto'].'"'.$this->getRequestVar('objectid').'"';
00971                          }
00972 
00973                          if   ( $this->hasRequestVar('table') )
00974                               $inputText .= "\n".
00975                                             $conf_tags['table-cell-sep'].' '.$addText.' '.$conf_tags['table-cell-sep'].' '.$addText.' '.$conf_tags['table-cell-sep']."\n".
00976                                             $conf_tags['table-cell-sep'].' '.$addText.' '.$conf_tags['table-cell-sep'].' '.$addText.' '.$conf_tags['table-cell-sep']."\n".
00977                                             $conf_tags['table-cell-sep'].' '.$addText.' '.$conf_tags['table-cell-sep'].' '.$addText.' '.$conf_tags['table-cell-sep']."\n";
00978 
00979                          if   ( $this->hasRequestVar('list') )
00980                               $inputText .= "\n".
00981                                             $conf_tags['list-unnumbered'].' '.$addText."\n".
00982                                             $conf_tags['list-unnumbered'].' '.$addText."\n".
00983                                             $conf_tags['list-unnumbered'].' '.$addText."\n";
00984 
00985                          if   ( $this->hasRequestVar('numlist') )
00986                               $inputText .= "\n".
00987                                             $conf_tags['list-numbered'].' '.$addText."\n".
00988                                             $conf_tags['list-numbered'].' '.$addText."\n".
00989                                             $conf_tags['list-numbered'].' '.$addText."\n";
00990 
00991                          if   ( $this->hasRequestVar('image') )
00992                               $inputText .= $conf_tags['image-begin'].$this->getRequestVar('objectid').$conf_tags['image-end'];
00993                     }
00994 
00995                     // Ermitteln aller verlinkbaren Objekte (fuer Editor)
00996                     $objects = array();
00997 
00998                     foreach( Folder::getAllObjectIds() as $id )
00999                     {
01000                          $o = new Object( $id );
01001                          $o->load();
01002 
01003                          if   ( $o->getType() != 'folder' )
01004                          {
01005                               $f = new Folder( $o->parentid );
01006                               $objects[ $id ]  = lang( 'GLOBAL_'.$o->getType() ).': ';
01007                               $objects[ $id ] .=  implode( FILE_SEP,$f->parentObjectNames(false,true) );
01008                               $objects[ $id ] .= FILE_SEP.$o->name;
01009                          }
01010                     }
01011                     asort($objects);
01012                     $this->setTemplateVar( 'objects' ,$objects );
01013 
01014                     $this->setTemplateVar( 'release' ,$this->page->hasRight(ACL_RELEASE) );
01015                     $this->setTemplateVar( 'publish' ,$this->page->hasRight(ACL_PUBLISH) );
01016                     $this->setTemplateVar( 'html'    ,$value->element->html );
01017                     $this->setTemplateVar( 'wiki'    ,$value->element->wiki );
01018                     $this->setTemplateVar( 'text'    ,$inputText );
01019                     $this->setTemplateVar( 'name'    ,$value->element->name );
01020                     $this->setTemplateVar( 'desc'    ,$value->element->desc );
01021                     $this->setTemplateVar( 'objectid',$this->page->objectid );
01022 
01023                     $this->setTemplateVar( 'mode'    ,'edit' );
01024                }
01025                else
01026                {
01027                     $this->afterSave($value);
01028                }
01029 
01030           }
01031 
01032 
01038           function savedate()
01039           {
01040                $value = new Value();
01041                $language = Session::getProjectLanguage();
01042                $value->languageid = $language->languageid;
01043                $value->objectid   = $this->page->objectid;
01044                $value->pageid     = Page::getPageIdFromObjectId( $this->page->objectid );
01045 
01046                if   ( $this->hasRequestVar('elementid') )
01047                $value->element = new Element( $this->getRequestVar('elementid') );
01048                else
01049                $value->element = Session::getElement();
01050 
01051                $value->element->load();
01052                $value->publish = false;
01053                $value->load();
01054 
01055                if   ( $this->hasRequestVar('linkobjectid') )
01056                $value->linkToObjectId = $this->getRequestVar('linkobjectid');
01057                elseif   ( $this->getRequestVar('ansidate') != $this->getRequestVar('ansidate_orig') )
01058                // Wenn ein ANSI-Datum eingegeben wurde, dann dieses verwenden
01059                $value->date = strtotime($this->getRequestVar('ansidate') );
01060                else
01061                // Sonst die Zeitwerte einzeln zu einem Datum zusammensetzen
01062                $value->date = mktime( $this->getRequestVar('hour'  ),
01063                $this->getRequestVar('minute'),
01064                $this->getRequestVar('second'),
01065                $this->getRequestVar('month' ),
01066                $this->getRequestVar('day'   ),
01067                $this->getRequestVar('year'  ) );
01068 
01069                $this->afterSave($value);
01070           }
01071 
01072 
01073 
01079           function saveselect()
01080           {
01081                $value = new Value();
01082                $language = Session::getProjectLanguage();
01083                $value->languageid = $language->languageid;
01084                $value->objectid   = $this->page->objectid;
01085                $value->pageid     = Page::getPageIdFromObjectId( $this->page->objectid );
01086 
01087                if   ( $this->hasRequestVar('elementid') )
01088                $value->element = new Element( $this->getRequestVar('elementid') );
01089                else
01090                $value->element = Session::getElement();
01091 
01092                $value->element->load();
01093                $value->publish = false;
01094                $value->load();
01095 
01096                $value->text           = $this->getRequestVar('text');
01097 
01098                $this->afterSave($value);
01099           }
01100 
01101 
01102 
01108           function savelink()
01109           {
01110                $value = new Value();
01111                $language = Session::getProjectLanguage();
01112                $value->languageid = $language->languageid;
01113                $value->objectid   = $this->page->objectid;
01114                $value->pageid     = Page::getPageIdFromObjectId( $this->page->objectid );
01115 
01116                if   ( $this->hasRequestVar('elementid') )
01117                $value->element = new Element( $this->getRequestVar('elementid') );
01118                else
01119                $value->element = Session::getElement();
01120 
01121                $value->element->load();
01122                $value->publish = false;
01123                $value->load();
01124 
01125                if   ( $this->hasRequestVar('linkurl') )
01126                $value->linkToObjectId = $this->parseOID($this->getRequestVar('linkurl'));
01127                else
01128                $value->linkToObjectId = intval($this->getRequestVar('linkobjectid'));
01129 
01130                $this->afterSave($value);
01131           }
01132 
01133 
01134 
01140           function savelist()
01141           {
01142                $this->saveinsert();
01143           }
01144           
01145 
01146           
01152           function saveinsert()
01153           {
01154                $value = new Value();
01155                $language = Session::getProjectLanguage();
01156                $value->languageid = $language->languageid;
01157                $value->objectid   = $this->page->objectid;
01158                $value->pageid     = Page::getPageIdFromObjectId( $this->page->objectid );
01159 
01160                if   ( $this->hasRequestVar('elementid') )
01161                $value->element = new Element( $this->getRequestVar('elementid') );
01162                else
01163                $value->element = Session::getElement();
01164 
01165                $value->element->load();
01166                $value->publish = false;
01167                $value->load();
01168 
01169                $value->linkToObjectId = intval($this->getRequestVar('linkobjectid'));
01170 
01171                $this->afterSave($value);
01172           }
01173 
01174 
01175 
01181           function savenumber()
01182           {
01183                $value = new Value();
01184                $language = Session::getProjectLanguage();
01185                $value->languageid = $language->languageid;
01186                $value->objectid   = $this->page->objectid;
01187                $value->pageid     = Page::getPageIdFromObjectId( $this->page->objectid );
01188 
01189                if   ( $this->hasRequestVar('elementid') )
01190                $value->element = new Element( $this->getRequestVar('elementid') );
01191                else
01192                $value->element = Session::getElement();
01193 
01194                $value->element->load();
01195                $value->publish = false;
01196                $value->load();
01197 
01198                if   ( $this->hasRequestVar('linkobjectid') )
01199                $value->linkToObjectId = $this->getRequestVar('linkobjectid');
01200                else
01201                $value->number         = $this->getRequestVar('number') * pow(10,$value->element->decimals);
01202 
01203                $this->afterSave($value);
01204           }
01205 
01206 
01207           function exportlongtext()
01208           {
01209                $types = array();
01210 
01211                foreach( array('odf','plaintext') as $type )
01212                {
01213                     $types[$type] = lang('FILETYPE_'.$type);
01214                }
01215 
01216                $this->setTemplateVar('types',$types);
01217           }
01218 
01219 
01220           function importlongtext()
01221           {
01222                $types = array();
01223 
01224                foreach( array('odf','plaintext') as $type )
01225                {
01226                     $types[$type] = lang('FILETYPE_'.$type);
01227                }
01228                $this->setTemplateVar('types',$types);
01229           }
01230 
01231 
01232           function doexportlongtext()
01233           {
01234                $type = $this->getRequestVar('type');
01235                switch($type)
01236                {
01237                     case 'odf':
01238                               
01239                          // Angabe Content-Type
01240                          //                  header('Content-Type: '.$this->file->mimeType());
01241                          //                  header('X-File-Id: '.$this->file->fileid);
01242 
01243                          //                  header('Content-Disposition: inline; filename='.$this->id.'.odt');
01244                          header('Content-Transfer-Encoding: binary');
01245                          //                  header('Content-Description: '.$this->file->name);
01246 
01247                          echo $this->createOdfDocument();
01248 
01249                          exit;
01250 
01251                     default:
01252                }
01253 
01254                exit;
01255           }
01256 
01257 
01264           function createOdfDocument()
01265           {
01266                // TODO: ODF ist nicht ganz ohne.
01267                $transformer = new Transformer();
01268                $transformer->text = $this->value->text;
01269                $transformer->type = 'odf';
01270                $transformer->transform();
01271                return $transformer->text;
01272           }
01273 
01274 
01275 
01282           function checkMenu( $name )
01283           {
01284                $type = $this->value->element->type;
01285 
01286                switch( $name )
01287                {
01288                     case 'edit':
01289                     case 'prop':
01290                          return true;
01291 
01292                     case 'archive':
01293                          // Archiv ist nur verf�gbar, wenn es mind. 1 Version des Inhaltes gibt.
01294                          
01295                          if   ( $this->subActionName!='diff' && is_object($this->value) )
01296                               return $this->value->getCountVersions() > 0;
01297                          else
01298                               return true;
01299 
01300                     case 'link':
01301                          // Verkn�pfung zu anderen Seiten ist nur m�glich f�r
01302                          // Datum, Text, Textabsatz, Ganzzahl.
01303                          return in_array($type,array('date','text','longtext','number'));
01304 
01305                     default:
01306                          return false;
01307                }
01308           }
01309 
01310 
01311           function convertOIDs( $text )
01312           {
01313                $treffer = array();
01314                preg_match_all('/\"([^\"]*)__OID__([0-9]+)__([^\"]*)\"/', $text, $treffer,PREG_SET_ORDER);
01315                //        preg_match_all('(.*)__OID__([0-9]+)__', $text, $treffer);
01316                foreach( $treffer as $t )
01317                {
01318                     $oid = $t[2];
01319                     $url = $this->page->path_to_object($oid);
01320                     $text = str_replace($t[0],'"'.$url.'"',$text);
01321                }
01322 
01323                return $text;
01324           }
01325 
01326 
01327           function parseOID( $text )
01328           {
01329                $treffer = array();
01330                preg_match_all('/(.*)__OID__([0-9]+)__(.*)/', $text, $treffer,PREG_SET_ORDER);
01331 
01332                return $treffer[0][2];
01333           }
01334 }
01335 
01336 ?>

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