X-Git-Url: http://git.polytechnique.org/?a=blobdiff_plain;ds=inline;f=classes%2Fplwizard.php;h=48117d539ea39511b7ea9a8a4ad34b2494c9a30f;hb=d7610c358d074c78e1e8dc25fe0cf0e5e7e1c55e;hp=7b6721d7f52f23aa53276e68685c596fb7fbbb29;hpb=45c358a97c9e7a0ba3c4c77b5e6d922d7482bfaa;p=platal.git diff --git a/classes/plwizard.php b/classes/plwizard.php index 7b6721d..48117d5 100644 --- a/classes/plwizard.php +++ b/classes/plwizard.php @@ -1,6 +1,6 @@ name = 'wiz_' . $name; $this->layout = $layout; @@ -80,20 +82,23 @@ class PlWizard $this->pages = array(); $this->lookup = array(); $this->titles = array(); + $this->ajax = $ajax; if (!isset($_SESSION[$this->name])) { $_SESSION[$this->name] = array(); + $_SESSION[$this->name . '_page'] = null; + $_SESSION[$this->name . '_stack'] = array(); } - $_SESSION[$this->name . '_page'] = null; - $_SESSION[$this->name . '_stack'] = array(); } - public function addPage($class, $title,$id = null) + public function addPage($class, $title, $id = null) { - if ($id != null) { - $this->lookup[$id] = count($this->pages); + if ($id == null) { + $id = count($this->pages); } - $this->pages[] = $class; - $this->titles[] = $title; + $this->lookup[$id] = count($this->pages); + $this->inv_lookup[] = $id; + $this->pages[] = $class; + $this->titles[] = $title; } public function set($varname, $value) @@ -133,13 +138,21 @@ class PlWizard return new $page($this); } - public function apply(PlatalPage &$smarty, $baseurl, $pgid = null) + public function apply(PlPage &$smarty, $baseurl, $pgid = null, $mode = 'normal') { - $curpage =& $_SESSION[$this->name . '_page']; + 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 { + $curpage = $_SESSION[$this->name . '_page']; + } + $oldpage = $curpage; // Process the previous page - if (!is_null($curpage)) { - $page = $this->getPage($curpage); + if (Post::has('valid_page')) { + $page = $this->getPage(Post::i('valid_page')); + $curpage = Post::i('valid_page'); $next = $page->process(); $last = $curpage; switch ($next) { @@ -165,30 +178,40 @@ class PlWizard break; case PlWizard::CURRENT_PAGE: break; // don't change the page default: - $curpage = is_numeric($next) ? $next : $this->lookup[$curpage]; + $curpage = is_numeric($next) ? $next : $this->lookup[$next]; break; } if (!$this->stateless) { array_push($_SESSION[$this->name . '_stack'], $last); } } - if ($this->stateless && (in_array($pgid, $this->lookup) || isset($this->pages[$pgid]))) { - $curpage = $pgid; - } if (is_null($curpage)) { $curpage = 0; } // Prepare the page - $page = $this->getPage($curpage); - $smarty->changeTpl($this->layout); + $_SESSION[$this->name . '_page'] = $curpage; + if ($curpage != $oldpage) { + pl_redirect($baseurl . '/' . $this->inv_lookup[$curpage]); + } else if (!isset($page)) { + $page = $this->getPage($curpage); + } + if ($mode == 'ajax') { + header('Content-Type: text/html; charset=utf-8'); + $smarty->changeTpl($page->template(), NO_SKIN); + } 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('tab_width', (int)(99 / count($this->pages))); $smarty->assign('wiz_page', $page->template()); - $page->prepare($smarty); + $smarty->assign('xorg_no_errors', true); + $page->prepare($smarty, isset($this->inv_lookup[$curpage]) ? $this->inv_lookup[$curpage] : $curpage); } }