summaryrefslogtreecommitdiff
blob: de35c657dd7892e40a9301e478f49025889b23f7 (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
83
84
<?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']);
		wizard::set_configuration($S['wizard']['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;
				$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();
		wizard::set_configuration($S['wizard']['configuration']);		
		$configuration=&$S['wizard']['configuration'];
		$configuration->name=$request['name'];
		$mods=explode(' ', $conf['modules']);
		$mod=isset($request['mod']) && isset($mods[$request['mod']])?$mods[$request['mod']]:$mods[0];
		$configuration->module=$mod;
		$configuration->init();
		debug('wizard', "Module: $mod");
		wizard_load_step(1);
	}
	if (isset($S['wizard']['step'])) {
		return array('title' => $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 ($configuration->status == 0) {
			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 {
			$S['wizard']['step']->output();
		}
	} else {
		echo '<form action="'.url('create').'" method="post"><h3>Request an image built</h3>Name of your configuration (optional): <input name="name" /><br/>';
		$mods=explode(' ', $conf['modules']);
		if (count($mods) > 1) {
			echo 'Module: <select name="mod">';
			$i=0;
			foreach ($mods as $mod)
				echo '<option value="'.$i++."\">$mod</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']->module, $step);
	}
	$S['wizard']['step']=&$S['wizard']['steps'][$step];
	return $S['wizard']['steps'];
}
?>