Added interface to input some settings
Jeremy D

Jeremy D commited on 2011-10-18 13:02:29
Showing 1 changed files, with 85 additions and 4 deletions.

... ...
@@ -20,6 +20,7 @@
20 20
 * @TODO The developers list of things todo.	
21 21
 * Add js to support ajax
22 22
 * Add ajax support
23
+* Test
23 24
 */
24 25
 
25 26
 class tbg_coverter
... ...
@@ -78,9 +79,16 @@ class tbg_coverter
78 79
 
79 80
 		// We can't process anymore until this exists.
80 81
 		if (empty($this->db_user))
81
-		{
82
-		}
82
+			$this->converterSetup();
83 83
 		else
84
+			$this->doConversion();
85
+	}
86
+
87
+	/**
88
+	* Actually does the conversion process
89
+	*
90
+	*/
91
+	private function doConversion()
84 92
 	{
85 93
 		$this->setDatabasePrefix();
86 94
 		$this->getDatabaseConnection();
... ...
@@ -95,6 +103,29 @@ class tbg_coverter
95 103
 		$function = 'doStep' . $this->step;
96 104
 		$function();
97 105
 	}
106
+
107
+	/**
108
+	* Ask the user for some settings, validate and then start conversion.
109
+	*
110
+	*/
111
+	private function converterSetup()
112
+	{
113
+		global $theme;
114
+
115
+		if (isset($_POST['save']))
116
+		{
117
+			$errors = $this->setSettings();
118
+
119
+			if ($errors === null)
120
+			{
121
+				// From here on, its all automatic.
122
+				$this->updateStep('doStep1');
123
+				$this->doConversion();
124
+			}
125
+		}
126
+
127
+		// Prompt for some settings.
128
+		$theme->showSettings($this->converterSettings());
98 129
 	}
99 130
 
100 131
 	/**
... ...
@@ -104,9 +135,9 @@ class tbg_coverter
104 135
 	private function converterSettings()
105 136
 	{
106 137
 		return array(
107
-			'tbg_loc' => array('type' => 'text', 'required' => true, 'default' => dirname(__FILE__), 'validate' => 'return file_exists($data);'),
138
+			'tbg_loc' => array('name' => 'The Bug Genie location', 'type' => 'text', 'required' => true, 'default' => dirname(__FILE__), 'validate' => 'return file_exists($data);'),
108 139
 			// @TODO: Make this validate the password.
109
-			'tbg_db_pass' => array('type' => 'password', 'required' => true, 'validate' => true,),
140
+			'tbg_db_pass' => array('name' => 'The Bug Genie database password', 'type' => 'password', 'required' => true, 'validate' => true,),
110 141
 		);
111 142
 	}
112 143
 
... ...
@@ -137,6 +168,8 @@ class tbg_coverter
137 168
 	{
138 169
 		$settings = $this->converterSettings();
139 170
 		$new_settings = array();
171
+		$errors = array();
172
+
140 173
 		foreach ($settings as $key => $details)
141 174
 		{
142 175
 			// We are saving then
... ...
@@ -149,8 +182,13 @@ class tbg_coverter
149 182
 			}
150 183
 		}
151 184
 
185
+		if (!empty($errors))
186
+			return $errors;
187
+
152 188
 		// Save these.
153 189
 		$_SESSION['tbg_converter'] = serialize($new_settings);
190
+
191
+		return null;
154 192
 	}
155 193
 
156 194
 	/**
... ...
@@ -815,4 +853,47 @@ class tbg_converter_wrapper
815 853
 </body></html>';
816 854
 
817 855
 	}
856
+
857
+	/*
858
+	* Show some settings.
859
+	*
860
+	*/
861
+	public function showSettings($settings)
862
+	{
863
+		echo '
864
+				<form action="', $_SERVER['PHP_SELF'], '" method="post" id="showSettings">
865
+					<dl>';
866
+
867
+		foreach ($settings as $key => $data)
868
+		{
869
+			echo '
870
+						<dt id="', $key, '_name">', $data['name'], '</dt>
871
+						<dd id="', $key, '_field">';
872
+
873
+			if ($data['type'] == 'textarea')
874
+				echo '<textarea name="', $key, '"></textarea>';
875
+			elseif ($data['type'] == 'select')
876
+			{
877
+				echo '<select name="', $key, '">';
878
+				
879
+				foreach ($data['options'] as $opt => $value)
880
+					echo '
881
+							<option name="', $opt, '">', $value, '</option>';
882
+
883
+				echo '
884
+						</select>';
885
+			}
886
+			else
887
+				echo '<input type="', $data['type'] == 'password' ? 'password' : 'text', '" name="', $key, '" />';
888
+
889
+			echo '</dd>';
890
+		}
891
+
892
+		echo '
893
+						<dt><input type="submit" value="Start conversion" /></dt>
894
+					</dl>
895
+				</form>';
896
+	}
897
+
898
+
818 899
 }
819 900
\ No newline at end of file
820 901