blob: 33b99494fffbe58b5315acf23617ed1792b58ea9 (
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
|
<?php
function init_configurations_wizard(&$S) {
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'];
$configuration->visibility='public';
$mod=isset($_REQUEST['mod']) && isset($S['conf']['modules'][$_REQUEST['mod']])?$S['conf']['modules'][$_REQUEST['mod']]:$S['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(&$S) {
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($S['conf']['modules']) > 1) {
echo 'Module: <select name="mod">';
$i=0;
foreach ($S['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'];
}
?>
|