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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
|
<?php
function init_configurations_wizard() {
global $S, $request, $conf;
if (!isset($S['user'])) {
return 'login';
}
// Make it so you can just pop over to config configuration=x and it will go to the right step
if (isset($request['configuration']) && preg_match('/^[a-zA-Z0-9]{6}$/', $request['configuration'])) {
$r=$S['pdo']->query('SELECT * FROM `configurations` WHERE `owner`='.$S['user']->id.' AND `id`="'.$request['configuration'].'"');
if ($r->rowCount()) {
$S['wizard.configuration']=new sql_configuration($r->fetch(PDO::FETCH_ASSOC));
$configuration=&$S['wizard.configuration'];
$opts=$configuration->get_configopts();
$S['wizard.module']=$opts['frontend_module'];
$module=&$S['wizard.module'];
if (!preg_match('#^config/step([0-9]+)$#', $configuration->status, $match)) {
debug('wizard', 'configuration not in config stage (status '.$configuration->status.') - PANIC!');
throw_exception('We haven\'t implemented this yet.');
}
$S['wizard.step']=$match[1];
$step=&$S['wizard.step'];
debug('wizard', 'Build '.$configuration->id." is at step $step");
if (isset($request['wizard_submit'])) {
debug('wizard', "Processing step $step");
if (!is_file(FRONTEND."/modules/$module/step$step.php")) {
throw_exception("$modules step $step doesn't exist!");
}
require_once(FRONTEND."/modules/$module/step$step.php");
$proc=$module.'_process_step'.$step;
if (function_exists($proc)) {
if ($proc() === true) {
debug('wizard', "Step $step returned <i>true</i> - config finished!");
$configuration->status='config/done';
$configuration->write();
$S['wizard.done']=true;
return array('title' => 'Config Finished');
}
} else {
debug('wizard', "No processing function for $wizard step $step");
}
$configuration->status='config/step'.++$step;
$configuration->write();
debug('wizard', "Continuing to step $step");
} else {
debug('wizard', "Not ready for processing... staying at step $step");
}
} else {
throw_exception('Build not found');
}
} elseif (isset($request['init'])) {
$r=$S['pdo']->query('SELECT * FROM `configurations` WHERE `owner`='.$S['user']->id.' AND `status`="config/step1"');
if ($r->rowCount()) {
$S['wizard.configuration']=new sql_configuration($r->fetch(PDO::FETCH_ASSOC));
} else {
$S['wizard.configuration']=new sql_configuration();
$S['wizard.configuration']->init();
}
$configuration=&$S['wizard.configuration'];
$S['wizard.configuration']->name=$request['name'];
$S['wizard.configuration']->write();
$femods=explode(' ', $conf['frontend_modules']);
$bemods=explode(' ', $conf['backend_modules']);
$femod=isset($request['femod']) && isset($femods[$request['femod']])?$femods[$request['femod']]:$femods[0];
$bemod=isset($request['bemod']) && isset($bemods[$request['bemod']])?$bemods[$request['bemod']]:$bemods[0];
$beopt=new sql_configopt($configuration->id, 'backend_module', $bemod);
$feopt=new sql_configopt($configuration->id, 'frontend_module', $femod);
debug('wizard', "Backend: $bemod; Frontend: $femod");
$beopt->write();
$feopt->write();
$S['wizard.module']=$femod;
$module=&$S['wizard.module'];
$S['wizard.step']=1;
}
if (isset($S['wizard.configuration'], $S['wizard.step'])) {
$step=&$S['wizard.step'];
if (is_file(FRONTEND."/modules/$module/step$step.php")) {
require_once(FRONTEND."/modules/$module/step$step.php");
$S['title']='Create - Step '.$step;
$proc=$module.'_init_step'.$step;
if (function_exists($proc)) {
return $proc();
} else {
debug('wizard', 'No init function for step '.$step);
return;
}
} else {
throw_exception("$module step $step doesn't exist");
}
}
return array('title' => 'Create');
}
function body_configurations_wizard() {
global $S, $conf;
if (isset($S['wizard.configuration'])) {
if (isset($S['wizard.done'])) {
echo print_success('Config finished!', '<form action="'.url('configurations').'" method="post"><input type="hidden" name="configuration" value="'.$S['wizard.configuration']->id.'" />Name (optional): <input name="name" value="'.($S['wizard.configuration']->name?htmlentities($S['wizard.configuration']->name):'').'" /> <input type="submit" name="build" value="Build" /></form>');
} else {
$configuration=&$S['wizard.configuration'];
$module=&$S['wizard.module'];
$step=&$S['wizard.step'];
echo '<h3>'.$S['title'].'</h3>';
echo '<form action="'.url('config/'.$configuration->id).'" method="post">';
require_once(FRONTEND."/modules/$module/step$step.php");
$proc=$module.'_body_step'.$step;
if (!function_exists($proc)) {
throw_exception("Body function doesn't exist for $module step $step");
}
$proc();
echo '<input type="submit" name="wizard_submit" value="Continue" /></form>';
}
} else {
echo '<form action="'.url('create').'" method="post"><h3>Request an image built</h3>Name of your configuration (optional): <input name="name" /><br/>';
$femods=explode(' ', $conf['frontend_modules']);
$bemods=explode(' ', $conf['backend_modules']);
if (count($femods) > 1) {
echo 'Frontend module: <select name="femod">';
$i=0;
foreach ($femods as $mod)
echo '<option value="'.$i++."\">$mod</option>";
echo '</select><br/>';
}
if (count($bemods) > 1) {
echo 'Backend module: <select name="bemod">';
$i=0;
foreach ($bemods as $mod)
echo '<option value="'.$i++."\">$mod</option>";
echo '</select><br/>';
}
echo '<input type="submit" name="init" value="Start" /></form>';
}
}
?>
|