Fixed template copy function
authorMarcel Werk <burntime@woltlab.com>
Thu, 25 Apr 2013 23:46:51 +0000 (01:46 +0200)
committerMarcel Werk <burntime@woltlab.com>
Thu, 25 Apr 2013 23:49:50 +0000 (01:49 +0200)
wcfsetup/install/files/acp/templates/templateAdd.tpl
wcfsetup/install/files/lib/acp/form/TemplateAddForm.class.php

index a3f5bb819870b13c52a4f73e3e2522047e9f616b..edcbf6df2c5455e8a1a599951d51d3beb3af13ae 100644 (file)
@@ -79,6 +79,7 @@
                
                <div class="formSubmit">
                        <input type="submit" value="{lang}wcf.global.button.submit{/lang}" accesskey="s" />
+                       {if $copy}<input type="hidden" name="copy" value="{@$copy}" />{/if}
                </div>
        </form>
 {else}
index 7ad09cde43b25ba1d32faeb2dd9a45f2119ab4bb..f1b3dbdcca4b7f39c3635b4e47fbcf1149e27b93 100644 (file)
@@ -6,6 +6,7 @@ use wcf\data\template\group\TemplateGroupList;
 use wcf\data\template\Template;
 use wcf\data\template\TemplateAction;
 use wcf\form\AbstractForm;
+use wcf\system\exception\IllegalLinkException;
 use wcf\system\exception\UserInputException;
 use wcf\system\WCF;
 use wcf\util\StringUtil;
@@ -61,6 +62,35 @@ class TemplateAddForm extends AbstractForm {
         */
        public $packageID = PACKAGE_ID;
        
+       /**
+        * id of copied template
+        * @var integer
+        */
+       public $copy = 0;
+       
+       /**
+        * copied template object
+        * @var wcf\data\template\Template
+        */
+       public $copiedTemplate = null;
+       
+       /**
+        * @see wcf\page\IPage::readParameters()
+        */
+       public function readParameters() {
+               parent::readParameters();
+       
+               if (!empty($_REQUEST['copy'])) {
+                       $this->copy = intval($_REQUEST['copy']);
+                       $this->copiedTemplate = new Template($this->copy);
+                       if (!$this->copiedTemplate->templateID) {
+                               throw new IllegalLinkException();
+                       }
+                       
+                       $this->packageID = $this->copiedTemplate->packageID;
+               }
+       }
+       
        /**
         * @see wcf\form\IForm::readFormParameters()
         */
@@ -171,13 +201,9 @@ class TemplateAddForm extends AbstractForm {
                $templateGroupList->readObjects();
                $this->availableTemplateGroups = $templateGroupList->getObjects();
                
-               if (!count($_POST)) {
-                       if (!empty($_REQUEST['copy'])) {
-                               $templateID = intval($_REQUEST['copy']);
-                               $template = new Template($templateID);
-                               $this->tplName = $template->templateName;
-                               $this->templateSource = $template->getSource();
-                       }
+               if (!count($_POST) && $this->copiedTemplate !== null) {
+                       $this->tplName = $this->copiedTemplate->templateName;
+                       $this->templateSource = $this->copiedTemplate->getSource();
                }
        }
        
@@ -192,7 +218,8 @@ class TemplateAddForm extends AbstractForm {
                        'tplName' => $this->tplName,
                        'templateGroupID' => $this->templateGroupID,
                        'templateSource' => $this->templateSource,
-                       'availableTemplateGroups' => $this->availableTemplateGroups
+                       'availableTemplateGroups' => $this->availableTemplateGroups,
+                       'copy' => $this->copy
                ));
        }
 }