Add interface PlIteraface and the corresponding abstract class
[platal.git] / classes / plpage.php
index 875981e..63ece95 100644 (file)
@@ -134,6 +134,12 @@ abstract class PlPage extends Smarty
             $this->_page_typ = SKINNED;
         }
 
+        if ($this->_page_type == SIMPLE) {
+            $this->assign('simple', true);
+        } else {
+            $this->assign('simple', false);
+        }
+
         switch ($this->_page_type) {
           case NO_SKIN:
             if (!($globals->debug & DEBUG_SMARTY)) {
@@ -143,8 +149,6 @@ abstract class PlPage extends Smarty
             exit;
 
           case SIMPLE:
-            $this->assign('simple', true);
-
           case SKINNED:
             $this->register_modifier('escape_html', 'escape_html');
             $this->default_modifiers = Array('@escape_html');
@@ -242,6 +246,34 @@ abstract class PlPage extends Smarty
     }
 
     // }}}
+    // {{{ function trigRedirect
+
+    // Acts as trig(), but replaces the template with a simple one displaying
+    // the error messages and a "continue" link.
+    private function trigRedirect($msg, $continue, $type = 'errors')
+    {
+        $this->trig($msg, $type);
+        $this->coreTpl('msgredirect.tpl');
+        $this->assign('continue', $continue);
+        $this->run();
+    }
+
+    public function trigErrorRedirect($msg, $continue)
+    {
+        $this->trigRedirect($msg, $continue, 'errors');
+    }
+
+    public function trigWarningRedirect($msg, $continue)
+    {
+        $this->trigRedirect($msg, $continue, 'warnings');
+    }
+
+    public function trigSuccessRedirect($msg, $continue)
+    {
+        $this->trigRedirect($msg, $continue, 'success');
+    }
+
+    // }}}
     // {{{ function kill()
 
     public function kill($msg, $type = 'errors')
@@ -338,6 +370,10 @@ abstract class PlPage extends Smarty
     protected function jsonDisplay()
     {
         pl_content_headers("text/javascript");
+        if (!empty($GLOBALS['pl_errors'])) {
+            $this->jsonAssign('pl_errors', join("\n", $GLOBALS['pl_errors']));
+            $GLOBALS['pl_errors'] = array();
+        }
         array_walk_recursive($this->_jsonVars, "escape_xorgDB");
         $jsonbegin = Env::v('jsonBegin');
         $jsonend = Env::v('jsonEnd');