blob: 947e3216192eca5ee5c84e7a60409f4b10026abd (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
|
<?php
function init_configurations_wizard() {
global $S, $request, $conf;
if (!isset($S['user'])) {
return 'login';
}
if (isset($request['configuration']) && strlen($request['configuration']) == 6 && ctype_alnum($request['configuration'])) {
$S['wizard']['configuration']=new sql_configuration($request['configuration']);
$configuration=&$S['wizard']['configuration'];
if ($configuration->owner != $S['user']->id) {
return '404';
}
if (isset($request['wizard_submit'])) {
$steps=array_keys($request['wizard_submit']);
$step=$steps[0];
wizard_load_step($step);
debug('wizard', "processing $configuration->module step $step");
$result=$S['wizard']['step']->process();
if ($result === $step) {
debug('wizard', "$configuration->module step $step not finished - staying put");
} elseif ($result === null) {
debug('wizard', "$configuration->module step $step returned <i>null</i> - config finished");
$configuration->status=0;
unset($S['wizard']['step']);
$configuration->write();
} else {
$configuration->status=$result;
$configuration->write();
wizard_load_step($result);
}
} elseif (isset($request['step']) && ctype_alnum($request['step'])) {
wizard_load_step($request['step']);
} elseif ($configuration->status > 0) {
wizard_load_step($configuration->status);
}
} elseif (isset($request['init'])) {
$S['wizard']['configuration']=new sql_configuration();
$configuration=&$S['wizard']['configuration'];
$configuration->name=$request['name'];
$mod=isset($request['mod']) && isset($conf['modules'][$request['mod']])?$conf['modules'][$request['mod']]:$conf['modules'][0];
$configuration->module=$mod;
$configuration->init();
debug('wizard', "Module: $mod");
wizard_load_step(1);
}
if (isset($S['wizard']['step'])) {
return array('title' => "Step {$S['wizard']['step']->step}: {$S['wizard']['step']->title}");
} else {
return array('title' => 'Create');
}
}
function body_configurations_wizard() {
global $S, $conf;
if (isset($S['wizard']['configuration'])) {
$configuration=&$S['wizard']['configuration'];
if (isset($S['wizard']['step']))
$S['wizard']['step']->output();
else
echo print_success('Config finished!', '<form action="'.url('configurations').'" method="post"><input type="hidden" name="configuration" value="'.$configuration->id.'" />Name (optional): <input name="name" value="'.($configuration->name?htmlentities($configuration->name):'').'" /> <input type="submit" name="build" value="Build" /></form>');
} else {
echo '<form action="'.url('create').'" method="post"><h3>Request an image built</h3>Name of your configuration (optional): <input name="name" /><br/>';
if (count($conf['modules']) > 1) {
echo 'Module: <select name="mod">';
$i=0;
foreach ($conf['modules'] as $mod) {
$mod=new module($mod);
echo '<option value="'.$i++.'">'.htmlentities($mod->name).'</option>';
}
echo '</select><br/>';
}
echo '<input type="submit" name="init" value="Start" /></form>';
}
}
function &wizard_load_step($step) {
global $S;
if (!isset($S['wizard']['steps'][$step])) {
$S['wizard']['steps'][$step]=new wizard_step($S['wizard']['configuration'], $step);
}
$S['wizard']['step']=&$S['wizard']['steps'][$step];
return $S['wizard']['steps'];
}
?>
|