openrat-cms

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

commit 72af030cb11a630b88230e7608e59cc3acabc363
parent 3eb6745f14b0db03d026145762aee3d01bf65ca6
Author: Jan Dankert <develop@jandankert.de>
Date:   Fri, 22 Nov 2019 23:47:33 +0100

New: Change the file type.

Diffstat:
modules/cms-core/action/FileAction.class.php | 17++++++++++++++++-
modules/cms-core/model/File.class.php | 24++++++++++++++++++++++++
modules/cms-ui/themes/default/html/views/file/advanced.php | 2++
modules/cms-ui/themes/default/html/views/file/advanced.tpl.src.xml | 1+
4 files changed, 43 insertions(+), 1 deletion(-)

diff --git a/modules/cms-core/action/FileAction.class.php b/modules/cms-core/action/FileAction.class.php @@ -11,6 +11,7 @@ use cms\publish\PublishPublic; use Http; use \Html; use Upload; +use ValidationException; // OpenRat Content Management System // Copyright (C) 2002-2012 Jan Dankert, cms@jandankert.de @@ -105,7 +106,7 @@ class FileAction extends ObjectAction else { // No file received. - throw new \ValidationException('value'); + throw new ValidationException('value'); } $this->file->setTimestamp(); @@ -121,6 +122,14 @@ class FileAction extends ObjectAction function advancedPost() { $this->file->extension = $this->getRequestVar('extension' ,OR_FILTER_FILENAME); + + $typeid = $this->getRequestVar('type',OR_FILTER_NUMBER ); + + if ( ! in_array($typeid,[BaseObject::TYPEID_FILE,BaseObject::TYPEID_IMAGE,BaseObject::TYPEID_TEXT])) + throw new ValidationException('type'); + + $this->file->typeid = $typeid; + $this->file->updateType(); $this->file->save(); $this->addNotice($this->file->getType(),$this->file->filename,'PROP_SAVED','ok'); @@ -233,6 +242,12 @@ class FileAction extends ObjectAction { // Eigenschaften der Datei uebertragen $this->setTemplateVar( 'extension',$this->file->extension ); + $this->setTemplateVar( 'type' ,$this->file->type ); + $this->setTemplateVar( 'types' ,[ + BaseObject::TYPEID_FILE => lang('file' ), + BaseObject::TYPEID_IMAGE => lang('image'), + BaseObject::TYPEID_TEXT => lang('text' ) + ] ); } diff --git a/modules/cms-core/model/File.class.php b/modules/cms-core/model/File.class.php @@ -499,6 +499,30 @@ EOF + + /** + * Change type. + * + * This is only allowed for files, because it is only allowed to switch between the following types: file,image,text. + */ + public function updateType() + { + + $stmt = db()->sql(<<<SQL +UPDATE {{object}} SET + typeid = {typeid} +WHERE id={objectid} +SQL + ); + + $stmt->setInt('typeid' , $this->typeid ); + $stmt->setInt('objectid', $this->objectid); + $stmt->query(); + } + + + + /** * Ermittelt die wirksame Datei-Endung. Diese kann sich * in der Extra-Dateiendung, aber auch direkt im Dateiname diff --git a/modules/cms-ui/themes/default/html/views/file/advanced.php b/modules/cms-ui/themes/default/html/views/file/advanced.php @@ -1,4 +1,6 @@ <?php if (!defined('OR_TITLE')) die('Forbidden'); ?> <form name="" target="_self" data-target="view" action="./" data-method="advanced" data-action="file" data-id="<?php echo OR_ID ?>" method="POST" enctype="application/x-www-form-urlencoded" class="or-form file" data-async="false" data-autosave="false"><input type="hidden" name="<?php echo REQ_PARAM_TOKEN ?>" value="<?php echo token() ?>" /><input type="hidden" name="<?php echo REQ_PARAM_ACTION ?>" value="file" /><input type="hidden" name="<?php echo REQ_PARAM_SUBACTION ?>" value="advanced" /><input type="hidden" name="<?php echo REQ_PARAM_ID ?>" value="<?php echo OR_ID ?>" /> <label class="or-form-row"><span class="or-form-label"><?php echo lang('file_extension') ?></span><span class="or-form-input"><div class="inputholder"><input id="<?php echo REQUEST_ID ?>_extension" name="<?php if ('') echo ''.'_' ?>extension<?php if (false) echo '_disabled' ?>" type="text" maxlength="256" class="extension" value="<?php echo Text::encodeHtml(@$extension) ?>" /><?php if (false) { ?><input type="hidden" name="extension" value="<?php $extension ?>"/><?php } ?></div></span></label> + <label class="or-form-row"><span class="or-form-label">?type?</span><span class="or-form-input"><div class="inputholder"><select id="<?php echo REQUEST_ID ?>_type" name="type" title="" class=""<?php if (count($types)<=1) echo ' disabled="disabled"'; ?> size="1"><?php include_once( 'modules/template-engine/components/html/selectbox/component-select-box.php') ?><?php component_select_option_list($types,$type,0,0) ?><?php if (count($types)==0) { ?><input type="hidden" name="type" value="" /><?php } ?><?php if (count($types)==1) { ?><input type="hidden" name="type" value="<?php echo array_keys($types)[0] ?>" /><?php } ?> + </select></div></span></label> <div class="or-form-actionbar"><input type="button" class="or-form-btn or-form-btn--secondary or-form-btn--cancel" value="<?php echo lang("CANCEL") ?>" /><input type="submit" class="or-form-btn or-form-btn--primary" value="<?php echo lang('BUTTON_OK') ?>" /></div></form> \ No newline at end of file diff --git a/modules/cms-ui/themes/default/html/views/file/advanced.tpl.src.xml b/modules/cms-ui/themes/default/html/views/file/advanced.tpl.src.xml @@ -2,5 +2,6 @@ xsi:schemaLocation="http://www.openrat.de/template ../../../../../../template-engine/components/template.xsd"> <form> <input label="file_extension" name="extension" size="10" class="extension"></input> + <selectbox label="type" name="type" size="1" list="types"></selectbox> </form> </output> \ No newline at end of file