projects
/
platal.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Allows addition of outsite JS scripts.
[platal.git]
/
classes
/
plwizard.php
diff --git
a/classes/plwizard.php
b/classes/plwizard.php
index
3667268
..
656b957
100644
(file)
--- a/
classes/plwizard.php
+++ b/
classes/plwizard.php
@@
-1,6
+1,6
@@
<?php
/***************************************************************************
<?php
/***************************************************************************
- * Copyright (C) 2003-20
08
Polytechnique.org *
+ * Copyright (C) 2003-20
11
Polytechnique.org *
* http://opensource.polytechnique.org/ *
* *
* This program is free software; you can redistribute it and/or modify *
* http://opensource.polytechnique.org/ *
* *
* This program is free software; you can redistribute it and/or modify *
@@
-29,7
+29,7
@@
interface PlWizardPage
/** Build a new instance of the class
* associated with the given wizard master.
*/
/** Build a new instance of the class
* associated with the given wizard master.
*/
- public function __construct(PlWizard
&
$wiz);
+ public function __construct(PlWizard $wiz);
/** Return the name of the templace describing the page.
*/
/** Return the name of the templace describing the page.
*/
@@
-37,7
+37,7
@@
interface PlWizardPage
/** Prepare the page by assigning to it any useful value.
*/
/** Prepare the page by assigning to it any useful value.
*/
- public function prepare(Pl
atalPage &
$page, $id);
+ public function prepare(Pl
Page
$page, $id);
/** Process information resulting of the application of the page.
* This function must return a clue indicating the next page to show.
/** Process information resulting of the application of the page.
* This function must return a clue indicating the next page to show.
@@
-45,7
+45,11
@@
interface PlWizardPage
* id (PlWizard::FIRST_PAGE, PlWizard::NEXT_PAGE, PlWizard::CURRENT_PAGE
* PlWizard::PREVIOUS_PAGE, PlWizard::LAST_PAGE).
*/
* id (PlWizard::FIRST_PAGE, PlWizard::NEXT_PAGE, PlWizard::CURRENT_PAGE
* PlWizard::PREVIOUS_PAGE, PlWizard::LAST_PAGE).
*/
- public function process();
+ public function process(&$success);
+
+ /** Displays the success message.
+ */
+ public function success();
}
/** A PlWizard is a set of pages through which the user can navigate,
}
/** A PlWizard is a set of pages through which the user can navigate,
@@
-64,17
+68,20
@@
class PlWizard
const PREVIOUS_PAGE = 'bt_previous';
const LAST_PAGE = 'bt_last';
const PREVIOUS_PAGE = 'bt_previous';
const LAST_PAGE = 'bt_last';
+ private $userdata = array();
+
protected $name;
protected $layout;
protected $stateless;
protected $ajax;
protected $name;
protected $layout;
protected $stateless;
protected $ajax;
+ protected $ajax_animated;
protected $pages;
protected $titles;
protected $lookup;
protected $inv_lookup;
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;
{
$this->name = 'wiz_' . $name;
$this->layout = $layout;
@@
-83,6
+90,7
@@
class PlWizard
$this->lookup = array();
$this->titles = array();
$this->ajax = $ajax;
$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;
if (!isset($_SESSION[$this->name])) {
$_SESSION[$this->name] = array();
$_SESSION[$this->name . '_page'] = null;
@@
-101,6
+109,16
@@
class PlWizard
$this->titles[] = $title;
}
$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;
public function set($varname, $value)
{
$_SESSION[$this->name][$varname] = $value;
@@
-138,10
+156,10
@@
class PlWizard
return new $page($this);
}
return new $page($this);
}
- public function apply(Pl
atalPage &
$smarty, $baseurl, $pgid = null, $mode = 'normal')
+ public function apply(Pl
Page
$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 {
} else if ($this->stateless && is_null($pgid)) {
$curpage = 0;
} else {
@@
-151,9
+169,12
@@
class PlWizard
// Process the previous page
if (Post::has('valid_page')) {
// 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');
$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:
$last = $curpage;
switch ($next) {
case PlWizard::FIRST_PAGE:
@@
-192,13
+213,18
@@
class PlWizard
// Prepare the page
$_SESSION[$this->name . '_page'] = $curpage;
if ($curpage != $oldpage) {
// 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);
}
if ($mode == 'ajax') {
} 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);
+ pl_content_headers("text/html");
+ $smarty->changeTpl($this->layout, NO_SKIN);
+ $smarty->assign('wiz_run_ajax', true);
} else {
$smarty->changeTpl($this->layout);
}
} else {
$smarty->changeTpl($this->layout);
}
@@
-208,10
+234,14
@@
class PlWizard
$smarty->assign('stateless', $this->stateless);
$smarty->assign('wiz_baseurl', $baseurl);
$smarty->assign('wiz_ajax', $this->ajax);
$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('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);
$page->prepare($smarty, isset($this->inv_lookup[$curpage]) ? $this->inv_lookup[$curpage] : $curpage);
+ if (isset($success) && $success) {
+ $smarty->trigSuccess($page->success());
+ }
}
}
}
}