00001 <?php
00002
00011 abstract class TKSnapEditor extends TKContainer {
00012 protected $res;
00013 protected $path;
00014 protected $version;
00015 protected $redirectTo;
00016 protected $actionVars;
00017
00018 const REDIR_ADMINTOOL = 1;
00019
00028 public function __construct($version, $redirectTo = self::REDIR_ADMINTOOL, $showPreview = true) {
00029 parent::__construct();
00030
00031 $this->version = $version;
00032 $this->path = $version->getCanonicalPath();
00033 $this->res = $version->getResource();
00034
00035 if($showPreview)
00036 $this->addText('<h3>Editor</h3>');
00037
00038 $continue = true;
00039 if(isset($_REQUEST['snap2ed_save']))
00040 $continue = $this->preSave();
00041 else if(isset($_REQUEST['snap2ed_saveAndExit']))
00042 $continue = $this->preSaveAndExit();
00043 else if(isset($_REQUEST['snap2ed_exit']))
00044 $continue = $this->preExit();
00045
00046 $error = false;
00047 if($continue) {
00048 if(isset($_REQUEST['snap2ed_save']) || isset($_REQUEST['snap2ed_saveAndExit'])) {
00049 $newCM = $this->processSave($this->version->getContentModule());
00050 if($newCM !== false) {
00051 if(!$this->version->update($newCM)) {
00052 $html = "<p><b>Error</b>: " . $this->version->getLastError() . "</p>";
00053 $this->addText($html);
00054 $error = true;
00055 }
00056 }
00057 else
00058 $error = true;
00059 }
00060 if(isset($_REQUEST['snap2ed_saveAndExit']) || isset($_REQUEST['snap2ed_exit'])) {
00061 if(!$error) {
00062 if(isset($_REQUEST['snap2ed_saveAndExit']))
00063 $this->postSaveAndExit($newCM, $error);
00064 else if(isset($_REQUEST['snap2ed_exit']))
00065 $this->postExit();
00066
00067 if($redirectTo === self::REDIR_ADMINTOOL)
00068 SWATFunctions::redirect("/snap2/view" . $path);
00069 else
00070 SWATFunctions::redirect($redirectTo);
00071 }
00072 }
00073
00074 if(isset($_REQUEST['snap2ed_save']))
00075 $this->postSave($newCM, $error);
00076 }
00077 else
00078 $this->addText('<b>Action Cancelled</b>');
00079
00080 $this->showEditor($version->getContentModule(), $error);
00081 if($showPreview) {
00082 $preview = $version->getContentModule()->getPreview();
00083 $this->add($preview);
00084 }
00085 }
00086
00088 protected function renderContainer($class, $style, $events, $id) {
00089 $html = "<div$id$class[0]$style[0]$events>\n";
00090 foreach($this->getChildrenBySlot('main') as $idx => $c) {
00091 if(is_object($c)) {
00092 $tmp = $c->render();
00093 }
00094 else {
00095 $tmp = $c;
00096 }
00097
00098 $html .= $tmp;
00099 }
00100 $html .= "</div>\n";
00101 return $html;
00102 }
00103
00117 protected abstract function showEditor($cm, $failed);
00118
00129 protected abstract function processSave($oldCM);
00130
00131
00139 protected function preSave() {
00140 return true;
00141 }
00142
00150 protected function preSaveAndExit() {
00151 return true;
00152 }
00153
00161 protected function preExit() {
00162 return true;
00163 }
00164
00174 protected function postSave($newCM, $error) {
00175 }
00176
00186 protected function postSaveAndExit($newCM, $error) {
00187 }
00188
00196 protected function postExit() {
00197 }
00198 }
00199
00200 ?>