openrat-cms

# OpenRat Content Management System
git clone http://git.code.weiherhei.de/openrat-cms.git
Log | Files | Refs

ProjectAction.class.php (8316B)


      1 <?php
      2 
      3 namespace cms\action;
      4 
      5 use cms\model\Project;
      6 use cms\model\Folder;
      7 
      8 // OpenRat Content Management System
      9 // Copyright (C) 2002-2012 Jan Dankert, cms@jandankert.de
     10 //
     11 // This program is free software; you can redistribute it and/or
     12 // modify it under the terms of the GNU General Public License
     13 // as published by the Free Software Foundation; either version 2
     14 // of the License, or (at your option) any later version.
     15 //
     16 // This program is distributed in the hope that it will be useful,
     17 // but WITHOUT ANY WARRANTY; without even the implied warranty of
     18 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     19 // GNU General Public License for more details.
     20 //
     21 // You should have received a copy of the GNU General Public License
     22 // along with this program; if not, write to the Free Software
     23 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
     24 
     25 
     26 /**
     27  * Action-Klasse zum Bearbeiten eines Projektes
     28  * @author $Author$
     29  * @version $Revision$
     30  * @package openrat.actions
     31  */
     32 class ProjectAction extends BaseAction
     33 {
     34 	public $security = Action::SECURITY_ADMIN;
     35 
     36     /**
     37      * @var Project
     38      */
     39 	private $project;
     40 	var $defaultSubAction = 'listing';
     41 
     42 
     43 	function __construct()
     44 	{
     45         parent::__construct();
     46     }
     47 
     48 
     49     public function init()
     50     {
     51 		$this->project = new Project( $this->getRequestId() );
     52 		$this->project->load();
     53 	}
     54 
     55 
     56 	function propPost()
     57 	{
     58 		if	( $this->getRequestVar('name') != '')
     59 		{
     60 			$this->project->name                 = $this->getRequestVar('name'               ,OR_FILTER_ALPHANUM);
     61 			$this->project->url                  = $this->getRequestVar('url'                ,OR_FILTER_ALPHANUM);
     62 			$this->project->target_dir           = $this->getRequestVar('target_dir'         ,OR_FILTER_RAW     );
     63 			$this->project->ftp_url              = $this->getRequestVar('ftp_url'            ,OR_FILTER_RAW     );
     64 			$this->project->ftp_passive          = $this->getRequestVar('ftp_passive'        ,OR_FILTER_RAW     );
     65 			$this->project->cmd_after_publish    = $this->getRequestVar('cmd_after_publish'  ,OR_FILTER_RAW     );
     66 			$this->project->content_negotiation  = $this->getRequestVar('content_negotiation',OR_FILTER_NUMBER  );
     67 			$this->project->cut_index            = $this->getRequestVar('cut_index'          ,OR_FILTER_NUMBER  );
     68 			$this->project->publishFileExtension = $this->getRequestVar('publishFileExtension',OR_FILTER_NUMBER  );
     69 			$this->project->publishPageExtension = $this->getRequestVar('publishPageExtension',OR_FILTER_NUMBER  );
     70 			$this->project->linkAbsolute         = $this->getRequestVar('linksAbsolute'       ,OR_FILTER_NUMBER  ) == '1';
     71 
     72 			$this->addNotice('project',$this->project->name,'SAVED','ok');
     73 			$this->project->save(); // speichern
     74 			
     75 			$root = new Folder( $this->project->getRootObjectId() );
     76 			$root->setTimestamp();
     77 		}
     78 		else
     79 		{
     80 			$this->addValidationError('name');
     81 			$this->callSubAction('edit');
     82 		}
     83 	}
     84 
     85 
     86 
     87 
     88 	public function editView() {
     89 
     90 
     91         $list[] = array(
     92             'name'=>'content',
     93             'type'=>'folder',
     94             'id'  => $this->project->getRootObjectId()
     95         );
     96         $list[] = array(
     97             'name'=>'templates',
     98             'type'=>'templatelist',
     99             'id'  => $this->project->projectid
    100         );
    101         $list[] = array(
    102             'name'=>'languages',
    103             'type'=>'languagelist',
    104             'id'  => $this->project->projectid
    105         );
    106         $list[] = array(
    107             'name'=>'models',
    108             'type'=>'modellist',
    109             'id'  => $this->project->projectid
    110         );
    111 
    112         $this->setTemplateVar('content',$list);
    113     }
    114 
    115 	/**
    116 	 * Liste aller Projekte anzeigen.
    117 	 *
    118 	 */
    119 	function listingView()
    120 	{
    121 		global $conf_php;
    122 
    123 		// Projekte ermitteln
    124 		$list = array();
    125 
    126 		foreach(Project::getAllProjects() as $id=> $name )
    127 		{
    128 			$list[$id]             = array();
    129 			$list[$id]['url'     ] = Html::url('project','edit',$id);
    130 			$list[$id]['use_url' ] = Html::url('tree'   ,'load',0  ,array('projectid'=>$id,'target'=>'tree'));
    131 			$list[$id]['name'    ] = $name;
    132 		}
    133 		$this->setTemplateVar('el',$list);
    134 	}
    135 
    136 
    137 	/**
    138 	 * Auswaehlen und starten eines Projektes.
    139 	 */
    140 	function select()
    141 	{
    142 		$user     = Session::getUser();
    143 		$projects = $user->projects;
    144 
    145 		// Administrator sieht Administrationsbereich
    146 		if   ( $user->isAdmin )
    147 			$projects = array_merge( array("-1"=>lang('ADMINISTRATION')),$projects );
    148 
    149 		// Projekte ermitteln
    150 		$list = array();
    151 
    152 		foreach( $projects as $id=>$name )
    153 		{
    154 			$list[$id]         = array();
    155 			$list[$id]['url' ] = Html::url('index','project',$id);
    156 			$list[$id]['name'] = $name;
    157 		}
    158 		$this->setTemplateVar('el',$list);
    159 	}
    160 
    161 
    162 	/**
    163 	 * Anzeige der Eigenschaften des Projektes.
    164 	 */
    165 	function propView()
    166 	{
    167 		$extraProperties = array(
    168 		    'rootobjectid'  => $this->project->getRootObjectId(),
    169             'linksAbsolute' => $this->project->linkAbsolute?'1':'0'
    170         );
    171 		
    172 		$this->setTemplateVars( $this->project->getProperties() + $extraProperties );
    173 
    174 	}
    175 	
    176 	
    177 	function removeView()
    178 	{
    179 		$this->setTemplateVar( 'name',$this->project->name );
    180 	}
    181 	
    182 	
    183 	function removePost()
    184 	{
    185 		if   ( !$this->hasRequestVar('delete') )
    186 		{
    187 			$this->addValidationError('delete');
    188 			return;
    189 		}
    190 		
    191 		// Gesamtes Projekt loeschen
    192 		$this->project->delete();
    193 
    194 		$this->setTemplateVar('tree_refresh',true);
    195 		$this->addNotice('project',$this->project->name,'DELETED'); 
    196 	}
    197 	
    198 	
    199 
    200 	/**
    201 	 * Anzeige View fuer Wartung.
    202 	 */
    203 	function maintenanceView()
    204 	{
    205 	}
    206 
    207 
    208 
    209 	/**
    210 	 * Wartung durchfuehren.
    211 	 */
    212 	function maintenancePost()
    213 	{
    214 		switch( $this->getRequestVar('type') )
    215 		{
    216 			case 'check_files':
    217 				// Konsistenzprüfungen
    218 				$this->project->checkLostFiles();
    219 				$status = empty($this->project->log) ? OR_NOTICE_OK : OR_NOTICE_ERROR;
    220 					
    221 				$this->addNotice('project',$this->project->name,'DONE',$status,array(),$this->project->log);
    222 				break;
    223 				
    224 			case 'check_limit':
    225 				// Alte Versionen löschen.
    226 				$this->project->checkLimit();
    227 				$this->addNotice('project',$this->project->name,'DONE');
    228 				break;
    229 				
    230 			default:
    231 				$this->addValidationError('type');
    232 				return;
    233 		}
    234 	}
    235 
    236 	
    237 
    238 	/**
    239 	 * Synchronisation mit dem Dateisystem. 
    240 	 */
    241 	public function syncPost()
    242 	{
    243 		
    244 	}
    245 
    246 
    247 	/**
    248 	 * Synchronisation mit dem Dateisystem. 
    249 	 */
    250 	public function syncView()
    251 	{
    252 		global $conf;
    253 		$syncConf = $conf['sync'];
    254 		
    255 		if	( ! $syncConf['enabled'] )
    256 			return;
    257 		
    258 		$syncDir = slashify($syncConf['directory']).$this->project->name;
    259 		
    260 		
    261 	}
    262 
    263 
    264 	/**
    265 	 * Import aus dem Dateisystem. 
    266 	 */
    267 	public function importView()
    268 	{
    269 		
    270 	}
    271 
    272 
    273 	/**
    274 	 * Import aus dem Dateisystem. 
    275 	 */
    276 	public function importPost()
    277 	{
    278 		
    279 	}
    280 
    281 
    282 	/**
    283 	 * Export in Dateisystem.
    284 	 */
    285 	public function exportView()
    286 	{
    287 		
    288 	}
    289 
    290 
    291 	/**
    292 	 * Export in Dateisystem.
    293 	 */
    294 	public function exportPost()
    295 	{
    296 		
    297 	}
    298 
    299 
    300 	/**
    301 	 * Projekt exportieren.
    302 	 */
    303 	public function copyView()
    304 	{
    305 		
    306 	}
    307 	
    308 	
    309 	/**
    310 	 * Projekt exportieren.
    311 	 */
    312 	public function copyPost()
    313 	{
    314 		$db = db_connection();
    315 		$this->setTemplateVar( 'dbid',$db->id );
    316 
    317 		global $conf;
    318 		$dbids = array();
    319 		
    320 		foreach( $conf['database'] as $dbname=>$dbconf )
    321 		{
    322 			if	( is_array($dbconf) && $dbconf['enabled'])
    323 				$dbids[$dbname] = $dbconf['description'];
    324 		}
    325 		$this->setTemplateVar( 'dbids',$dbids );
    326 		
    327 		
    328 		if	( $this->hasRequestVar('ok') )
    329 		{
    330 			$this->project->export( $this->getRequestVar('dbid') );
    331 			
    332 			$this->addNotice('project',$this->project->name,'DONE');
    333 			$this->setTemplateVar('done',true);
    334 		}
    335 	}
    336 	
    337 	
    338 	
    339 	/**
    340 	 * Ausgabe PHPINFO.
    341 	 *
    342 	 */
    343 	function phpinfo()
    344 	{
    345 		global $conf;
    346 		if	( !@$conf['security']['show_system_info'] )
    347 			Http::sendStatus(403,'Forbidden','Display of system information is disabled by configuration');
    348 			
    349 		phpinfo();
    350 	}
    351 
    352 	
    353 	
    354 	
    355 	function infoView()
    356 	{
    357 		$this->setTemplateVar( 'info', $this->project->info() );
    358 	}
    359 	
    360 	
    361 	
    362 	
    363 	/**
    364 	 * @param String $name Menüpunkt
    365 	 * @return boolean true, falls Menüpunkt zugelassen
    366 	 */
    367 	function checkMenu( $name )
    368 	{
    369 		global $conf;
    370 		
    371 		switch( $name )
    372 		{
    373 			case 'remove':
    374 				return     !readonly();
    375 			case 'maintenance':
    376 				return     !readonly();
    377 				
    378 			default:
    379 				return true;
    380 		}	
    381 	}
    382 	
    383 	
    384 	/**
    385 	 * Ermittelt die letzten Änderungen, die im aktuellen Projekt gemacht worden sind.
    386 	 */
    387 	public function historyView()
    388 	{
    389 		$result = $this->project->getLastChanges();
    390 	
    391 		$this->setTemplateVar('timeline', $result);
    392 	}
    393 	
    394 	
    395 }