X-Git-Url: http://git.polytechnique.org/?a=blobdiff_plain;f=classes%2Fplwizard.php;h=7a2366aad2f70e09502a093d7af8718131b68634;hb=c16ab9ce3537fad8a05ecba1cdb25268440aec29;hp=b5affd1936cecc487df3be5bcda1f7b32258ec07;hpb=93553cea371ce061dce9dfc34825b7b98a6ded34;p=platal.git diff --git a/classes/plwizard.php b/classes/plwizard.php index b5affd1..7a2366a 100644 --- a/classes/plwizard.php +++ b/classes/plwizard.php @@ -1,6 +1,6 @@ name = 'wiz_' . $name; $this->layout = $layout; @@ -81,6 +89,8 @@ class PlWizard $this->pages = array(); $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; @@ -99,6 +109,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; @@ -136,10 +156,10 @@ class PlWizard return new $page($this); } - public function apply(PlatalPage &$smarty, $baseurl, $pgid = null) + 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]; + if ($this->stateless && (isset($this->lookup[$pgid]) || isset($this->pages[$pgid]))) { + $curpage = is_numeric($pgid) ? $pgid : $this->lookup[$pgid]; } else if ($this->stateless && is_null($pgid)) { $curpage = 0; } else { @@ -149,9 +169,12 @@ 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(); + $success = false; + $next = $page->process($success); $last = $curpage; switch ($next) { case PlWizard::FIRST_PAGE: @@ -190,22 +213,37 @@ class PlWizard // Prepare the page $_SESSION[$this->name . '_page'] = $curpage; if ($curpage != $oldpage) { - pl_redirect($baseurl . '/' . $this->inv_lookup[$curpage]); + if (isset($success) && $success) { + pl_redirect($baseurl . '/' . $this->inv_lookup[$curpage] . '/null/' . $success); + } else { + pl_redirect($baseurl . '/' . $this->inv_lookup[$curpage]); + } } else if (!isset($page)) { $page = $this->getPage($curpage); } - $smarty->changeTpl($this->layout); + if ($mode == 'ajax') { + pl_content_headers("text/html"); + $smarty->changeTpl($this->layout, NO_SKIN); + $smarty->assign('wiz_run_ajax', true); + } else { + $smarty->changeTpl($this->layout); + } $smarty->assign('pages', $this->titles); $smarty->assign('current', $curpage); $smarty->assign('lookup', $this->inv_lookup); $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); - $page->prepare($smarty); + $smarty->assign('pl_no_errors', true); + $page->prepare($smarty, isset($this->inv_lookup[$curpage]) ? $this->inv_lookup[$curpage] : $curpage); + if (isset($success) && $success) { + $smarty->trigSuccess($page->success()); + } } } -// vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8: +// vim:set et sw=4 sts=4 sws=4 foldmethod=marker fenc=utf-8: ?>