Triggers must be displaid when page is loaded via ajax.
[platal.git] / classes / plwizard.php
index 3667268..43a8762 100644 (file)
@@ -37,7 +37,7 @@ interface PlWizardPage
 
     /** Prepare the page by assigning to it any useful value.
      */
-    public function prepare(PlatalPage &$page, $id);
+    public function prepare(PlPage &$page, $id);
 
     /** Process information resulting of the application of the page.
      * This function must return a clue indicating the next page to show.
@@ -64,17 +64,20 @@ class PlWizard
     const PREVIOUS_PAGE = 'bt_previous';
     const LAST_PAGE     = 'bt_last';
 
+    private $userdata = array();
+
     protected $name;
     protected $layout;
     protected $stateless;
     protected $ajax;
+    protected $ajax_animated;
 
     protected $pages;
     protected $titles;
     protected $lookup;
     protected $inv_lookup;
 
-    public function __construct($name, $layout, $stateless = false, $ajax = true)
+    public function __construct($name, $layout, $stateless = false, $ajax = true, $ajax_animated = true)
     {
         $this->name      = 'wiz_' . $name;
         $this->layout    = $layout;
@@ -83,6 +86,7 @@ class PlWizard
         $this->lookup = array();
         $this->titles = array();
         $this->ajax   = $ajax;
+        $this->ajax_animated = $ajax_animated;
         if (!isset($_SESSION[$this->name])) {
             $_SESSION[$this->name] = array();
             $_SESSION[$this->name . '_page']  = null;
@@ -101,6 +105,16 @@ class PlWizard
         $this->titles[]     = $title;
     }
 
+    public function addUserData($name, $value)
+    {
+        $this->userdata[$name] = $value;
+    }
+
+    public function getUserData($name, $default = null)
+    {
+        return $this->userdata[$name];
+    }
+
     public function set($varname, $value)
     {
         $_SESSION[$this->name][$varname] = $value;
@@ -138,7 +152,7 @@ class PlWizard
         return new $page($this);
     }
 
-    public function apply(PlatalPage &$smarty, $baseurl, $pgid = null, $mode = 'normal')
+    public function apply(PlPage &$smarty, $baseurl, $pgid = null, $mode = 'normal')
     {
         if ($this->stateless && (isset($this->lookup[$pgid]) || isset($this->pages[$pgid]))) { 
             $curpage = is_numeric($pgid) ? $pgid : $this->lookup[$pgid]; 
@@ -151,6 +165,8 @@ class PlWizard
 
         // Process the previous page
         if (Post::has('valid_page')) {
+            S::assert_xsrf_token();
+
             $page = $this->getPage(Post::i('valid_page'));
             $curpage = Post::i('valid_page');
             $next = $page->process();
@@ -198,7 +214,8 @@ class PlWizard
         }
         if ($mode == 'ajax') {
             header('Content-Type: text/html; charset=utf-8');
-            $smarty->changeTpl($page->template(), NO_SKIN);
+            $smarty->changeTpl($this->layout, NO_SKIN);
+            $smarty->assign('wiz_run_ajax', true);
         } else {
             $smarty->changeTpl($this->layout);
         }
@@ -208,9 +225,10 @@ class PlWizard
         $smarty->assign('stateless', $this->stateless);
         $smarty->assign('wiz_baseurl', $baseurl);
         $smarty->assign('wiz_ajax', $this->ajax);
+        $smarty->assign('wiz_animated', $this->ajax_animated);
         $smarty->assign('tab_width', (int)(99 / count($this->pages)));
         $smarty->assign('wiz_page', $page->template());
-        $smarty->assign('xorg_no_errors', true);
+        $smarty->assign('pl_no_errors', true);
         $page->prepare($smarty, isset($this->inv_lookup[$curpage]) ? $this->inv_lookup[$curpage] : $curpage);
     }
 }