summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'frontend/pages/wizard.php')
-rw-r--r--frontend/pages/wizard.php83
1 files changed, 65 insertions, 18 deletions
diff --git a/frontend/pages/wizard.php b/frontend/pages/wizard.php
index dee3c57..e9af804 100644
--- a/frontend/pages/wizard.php
+++ b/frontend/pages/wizard.php
@@ -1,32 +1,79 @@
<?php
function init_wizard() {
global $S, $request;
- // TODO we shouldn't have to set the step this way, it should be stored in SQL
- if (isset($S['user'])) {
- if (isset($request['finished'])) {
- return 'wizard/end';
- } elseif (isset($request['step']) && is_array($request['step']) && count($request['step']) == 1) {
- $keys=array_keys($request['step']);
- if (is_numeric($keys[0]) && is_file(FRONTEND.'/pages/wizard/step'.$keys[0].'.php')) {
- return 'wizard/step'.$keys[0];
+ if (!isset($S['user'])) {
+ return 'login';
+ }
+ if (isset($request['step']) && is_array($request['step']) && count($request['step']) == 1) {
+ $keys=array_keys($request['step']);
+ if (is_numeric($keys[0]) && is_file(FRONTEND.'/pages/wizard/step'.$keys[0].'.php')) {
+ $step=$keys[0];
+ $r=$S['pdo']->query('SELECT * FROM `builds` WHERE `owner`='.$S['user']->id.' AND `status`="config/step'.$step.'"');
+ if ($r->rowCount() == 0) {
+ debug('wizard', 'Build not found!');
+ // Build
+ unset($request['step']);
+ return 'wizard';
+ }
+ $S['build']=new sql_build($r->fetch(PDO::FETCH_ASSOC));
+ require_once(FRONTEND.'/pages/wizard/step'.$step.'.php');
+ $proc='process_wizard_step'.$step;
+ if (function_exists($proc)) {
+ $proc();
} else {
- debug('Not numeric, or file not existant for '.$keys[0]);
+ debug('wizard', 'No processing function for step '.$step);
}
+ $step++;
+ if (is_file(FRONTEND.'/pages/wizard/step'.$step.'.php')) {
+ $S['build']->status='config/step'.$step;
+ $S['build']->write();
+ $S['title']='Create - Step '.$step;
+ return 'wizard/step'.$step;
+ } else {
+ $S['build']->status='build/ready';
+ $S['build']->ctime=time();
+ $S['build']->write();
+ return array('title' => 'Create - Finished');
+ }
+ } else {
+ debug('wizard', 'step[0] not numeric, or step '.htmlentities($step).' not existant');
}
- return array('title' => 'Create');
} else {
- return 'login';
+ $r=$S['pdo']->query('SELECT * FROM `builds` WHERE `owner`='.$S['user']->id.' AND `status` LIKE "config/step0"');
+ if ($r->rowCount()) {
+ $S['build']=new sql_build($r->fetch(PDO::FETCH_ASSOC));
+ } else {
+ $S['build']=new sql_build();
+ $S['build']->init();
+ }
}
+ return array('title' => 'Create');
}
function body_wizard() {
global $S;
- echo '<form action="'.url('create').'" method="post"><h3>Request an image built</h3>Name of your build (optional): <input name="name" /><br/>Profile: <select name="pkgdir">';
- $r=$S['pdo']->query('SELECT * FROM `profiles` WHERE `flags` NOT LIKE "%d%"'); // d for disabled
- while ($profile=$r->fetch(PDO::FETCH_ASSOC)) {
- $profile=new sql_profile($profile);
- $display=$profile->name?$profile->name:($profile->pkgdir?$profile->pkgdir:'/');
- echo '<option value="'.htmlentities($profile->pkgdir).'">'.htmlentities($display).'</option>';
+ if ($S['build']->status == 'config/step0') {
+ echo '<form action="'.url('create').'" method="post"><h3>Request an image built</h3>Name of your build (optional): <input name="name" /><br/>Profile: <select name="pkgdir">';
+ $r=$S['pdo']->query('SELECT * FROM `profiles` WHERE `flags` NOT LIKE "%d%"'); // d for disabled
+ while ($profile=$r->fetch(PDO::FETCH_ASSOC)) {
+ $profile=new sql_profile($profile);
+ $display=$profile->name?$profile->name:($profile->pkgdir?$profile->pkgdir:'/');
+ echo '<option value="'.htmlentities($profile->pkgdir).'">'.htmlentities($display).'</option>';
+ }
+ echo '</select><br/><input type="submit" name="step[0]" value="Start" /></form>';
+ } else {
+ echo '<h3>Config finished!</h3><p>Check your build\'s status <a href="'.url('logs/build'.$S['build']->id).'">here</a></p>';
}
- echo '</select><br/><input type="submit" name="step[1]" value="Start" /></form>';
+}
+function process_wizard_step0() {
+ global $S, $request;
+ $S['build']->name=$request['name'];
+ $profile=new sql_profile($request['pkgdir']);
+ $profileopt=new sql_buildopt($S['build']->id, 'profile', $profile->pkgdir); // TODO pkgdir -> id
+ $profileopt->write();
+ $S['build']->write();
+}
+// One day this is going to be necessary
+function body_wizard_step0() {
+ body_wizard();
}
?>