1<?php
2/********************************
3OSBib:
4A collection of PHP classes to create and manage bibliographic formatting for OS bibliography software
5using the OSBib standard.
6
7Released through http://bibliophile.sourceforge.net under the GPL licence.
8Do whatever you like with this -- some credit to the author(s) would be appreciated.
9
10If you make improvements, please consider contacting the administrators at bibliophile.sourceforge.net
11so that your improvements can be added to the release package.
12
13Adapted from WIKINDX: http://wikindx.sourceforge.net
14
15Mark Grimshaw 2005
16http://bibliophile.sourceforge.net
17********************************/
18/**
19*	HTML FORM elements
20*
21*	@author Mark Grimshaw
22*
23*	$Header: /cvsroot/bibliophile/OSBib/create/FORM.php,v 1.1 2005/06/20 22:26:51 sirfragalot Exp $
24*/
25class FORM
26{
27// constructor
28	function FORM()
29	{
30	}
31// print form header with hidden action field
32	function formHeader($action)
33	{
34		global $PHP_SELF;
35		$pString = <<< END
36<form method="post" action="$PHP_SELF">
37<input type="hidden" name="action" value="$action" />
38END;
39		return $pString . "\n";
40	}
41// end a form
42	function formEnd()
43	{
44		return "</form>\n";
45	}
46// print form header with hidden action field for multi-part upload forms
47	function formMultiHeader($action)
48	{
49		global $PHP_SELF;
50		$pString = <<< END
51<form enctype="multipart/form-data" method="post" action="$PHP_SELF">
52<input type="hidden" name="action" value="$action" />
53END;
54		return $pString . "\n";
55	}
56// print form footer with submit field
57	function formSubmit($value = FALSE)
58	{
59		include_once("MESSAGES.php");
60		$messages = new MESSAGES();
61		if(!$value)
62			$value = $messages->text("submit", "Submit");
63		else
64			$value = $messages->text("submit", $value);
65		$pString = <<< END
66<input type="submit" value=" $value " />
67END;
68		return $pString . "\n";
69	}
70// print form reset button
71	function formReset()
72	{
73		include_once("MESSAGES.php");
74		$messages = new MESSAGES();
75		$value = $messages->text("submit", "reset");
76		$pString = <<< END
77<input type="reset" value=" $value " />
78END;
79		return $pString . "\n";
80	}
81// print hidden form input
82	function hidden($name, $value)
83	{
84		$pString = <<< END
85<input type="hidden" name="$name" value="$value" />
86END;
87		return $pString . "\n";
88	}
89// print radio button
90	function radioButton($label, $name, $value = FALSE, $checked = FALSE)
91	{
92		$checked ? $checked = "checked=\"checked\"" : "";
93		$pString = '';
94		if($label)
95			$pString = "$label:<br />";
96		$pString .= <<< END
97<input type="radio" name="$name" value="$value" $checked />
98END;
99		return $pString . "\n";
100	}
101// print checkbox
102	function checkbox($label, $name, $checked = FALSE)
103	{
104		$checked ? $checked = "checked=\"checked\"" : "";
105		$pString = '';
106		if($label)
107			$pString = "$label:<br />";
108		$pString .= <<< END
109<input type="checkbox" name="$name" $checked />
110END;
111		return $pString . "\n";
112	}
113// create select boxes for HTML forms
114// requires $name, $array and optional $size.
115// First OPTION is always SELECTED
116// optional $override allows the programmer to override the user set preferences for character limiting in select boxes
117	function selectFBox($label, $name, $array, $size = 3, $override = FALSE)
118	{
119		include_once("FORMMISC.php");
120		$formMisc = new FORMMISC();
121		$pString = '';
122		if($label)
123			$pString = "$label:<br />";
124		$pString .= "<select name=\"$name\" id=\"$name\" size=\"$size\">\n";
125		$value = array_shift($array);
126		$string = $formMisc->reduceLongText($value, $override);
127		$pString .= "<option value=\"$value\" selected=\"selected\">" . $string . "</option>\n";
128		foreach($array as $value)
129		{
130			$string = $formMisc->reduceLongText($value, $override);
131			$pString .= "<option value=\"$value\">$string</option>\n";
132		}
133		$pString .= "</select>\n";
134		return $pString;
135	}
136// create select boxes for HTML forms
137// requires $name, $array, selected value and optional $size.
138// 'selected value' is set SELECTED
139// optional $override allows the programmer to override the user set preferences for character limiting in select boxes
140	function selectedBox($label, $name, $array, $select, $size = 3, $override = FALSE)
141	{
142		include_once("FORMMISC.php");
143		$formMisc = new FORMMISC();
144		$pString = '';
145		if($label)
146			$pString = "$label:<br />";
147		$pString .= "<select name=\"$name\" id=\"$name\" size=\"$size\">\n";
148		foreach($array as $value)
149		{
150			if($value == $select)
151			{
152				$string = $formMisc->reduceLongText($value, $override);
153				$pString .= "<option value=\"$value\" selected=\"selected\">$string</option>\n";
154			}
155			else
156			{
157				$value = $formMisc->reduceLongText($value, $override);
158				$pString .= "<option>$value</option>\n";
159			}
160		}
161		$pString .= "</select>\n";
162		return $pString;
163	}
164// create select boxes form HTML forms
165// requires $name, $array and optional $size.
166// First entry is default selection.
167// OPTION VALUE is set so expects assoc. array where key holds this value
168// optional $override allows the programmer to override the user set preferences for character limiting in select boxes
169	function selectFBoxValue($label, $name, $array, $size = 3, $override = FALSE)
170	{
171		include_once("FORMMISC.php");
172		$formMisc = new FORMMISC();
173		$pString = '';
174		if($label)
175			$pString = "$label:<br />\n";
176		$pString .= "<select name=\"$name\" id=\"$name\" size=\"$size\">\n";
177		$pString .= "<option value=\"" . key($array) . "\" selected=\"selected\">" .
178			$formMisc->reduceLongText(current($array), $override) . "</option>\n";
179		$doneFirst = FALSE;
180		foreach($array as $key => $value)
181		{
182			$value = $formMisc->reduceLongText($value, $override);
183			if(!$doneFirst)
184			{
185				$doneFirst = TRUE;
186				continue;
187			}
188			$pString .= "<option value=\"$key\">$value</option>\n";
189		}
190		$pString .= "</select>\n";
191		return $pString;
192	}
193// create select boxes form HTML forms
194// requires $name, $array and optional $size.
195// $select is default selection.
196// OPTION VALUE is set so expects assoc. array where key holds this value
197// optional $override allows the programmer to override the user set preferences for character limiting in select boxes
198	function selectedBoxValue($label, $name, $array, $select, $size = 3, $override = FALSE)
199	{
200		include_once("FORMMISC.php");
201		$formMisc = new FORMMISC();
202		$pString = '';
203		if($label)
204			$pString = "$label:<br />\n";
205		$pString .= "<select name=\"$name\" id=\"$name\" size=\"$size\">\n";
206		foreach($array as $key => $value)
207		{
208			$value = $formMisc->reduceLongText($value, $override);
209			($key == $select) ?
210				$pString .= "<option value=\"$key\" selected=\"selected\">$value</option>\n" :
211				$pString .= "<option value=\"$key\">$value</option>\n";
212		}
213		$pString .= "</select>\n";
214		return $pString;
215	}
216// create select boxes form HTML forms
217// requires $name, $array and optional $size.
218// First entry is default selection.
219// OPTION VALUE is set so expects assoc. array where key holds this value.
220// MULTIPLE values may be selected
221// optional $override allows the programmer to override the user set preferences for character limiting in select boxes
222	function selectFBoxValueMultiple($label, $name, $array, $size = 3, $override = FALSE)
223	{
224		include_once("FORMMISC.php");
225		$formMisc = new FORMMISC();
226		$pString = '';
227		if($label)
228			$pString = "$label:<br />\n";
229		$name .= '[]';
230		$pString .= "<select name=\"$name\" id=\"$name\" size=\"$size\" multiple=\"multiple\">\n";
231		$pString .= "<option value=\"" . key($array) . "\" selected=\"selected\">" .
232			$formMisc->reduceLongText(current($array), $override) . "</option>\n";
233		$doneFirst = FALSE;
234		foreach($array as $key => $value)
235		{
236			$value = $formMisc->reduceLongText($value, $override);
237			if(!$doneFirst)
238			{
239				$doneFirst = TRUE;
240				continue;
241			}
242			$pString .= "<option value=\"$key\">$value</option>\n";
243		}
244		$pString .= "</select>\n";
245		return $pString;
246	}
247// create select boxes form HTML forms
248// requires $name, $array, selected values (array of) and optional $size.
249// OPTION VALUE is set so expects assoc. array where key holds this value.
250// MULTIPLE values may be selected
251// optional $override allows the programmer to override the user set preferences for character limiting in select boxes
252	function selectedBoxValueMultiple($label, $name, $array, $values, $size = 3, $override = FALSE)
253	{
254		include_once("FORMMISC.php");
255		$formMisc = new FORMMISC();
256		include_once("MESSAGES.php");
257		$messages = new MESSAGES();
258		$pString = '';
259		if($label)
260			$pString = "$label:<br />\n";
261		$name .= '[]';
262		$pString .= "<select name=\"$name\" id=\"$name\" size=\"$size\" multiple=\"multiple\">\n";
263		foreach($array as $key => $value)
264		{
265			if($value == $messages->text("misc", "ignore"))
266			{
267				$pString .= "<option value=\"$key\">$value</option>\n";
268				continue;
269			}
270			$value = $formMisc->reduceLongText($value, $override);
271			if(array_search($key, $values) !== FALSE)
272				$pString .= "<option value=\"" . $key .
273					"\" selected=\"selected\">" . $value . "</option>\n";
274			else
275				$pString .= "<option value=\"$key\">$value</option>\n";
276		}
277/* This is slow, slow, so slow! MG - 1/April/2005  Above is quicker (much, much quicker!)
278		foreach($array as $key => $value)
279		{
280			$match = FALSE;
281			$value = $formMisc->reduceLongText($value, $override);
282			foreach($values AS $select)
283			{
284				if($value == $messages->text("misc", "ignore"))
285					break;
286				if($key == $select)
287				{
288					$pString .= "<option value=\"" . $key .
289						"\" selected=\"selected\">" . $value . "</option>\n";
290					$match = TRUE;
291					break;
292				}
293			}
294			if(!$match)
295				$pString .= "<option value=\"$key\">$value</option>\n";
296		}
297*/
298		$pString .= "</select>\n";
299		return $pString;
300	}
301// password input type
302	function passwordInput($label, $name, $value = FALSE, $size = 20, $maxLength = 255)
303	{
304		$pString = '';
305		if($label)
306			$pString = "$label:<br />";
307		$pString .= <<< END
308<input type="password" name="$name" value="$value" size="$size" maxlength="$maxLength" />
309END;
310		return $pString . "\n";
311	}
312// text input type
313	function textInput($label, $name, $value = FALSE, $size = 20, $maxLength = 255)
314	{
315		$pString = '';
316		if($label)
317			$pString = "$label:<br />";
318		$pString .= <<< END
319<input type="text" name="$name" value="$value" size="$size" maxlength="$maxLength" />
320END;
321		return $pString . "\n";
322	}
323// textarea input type
324	function textareaInput($label, $name, $value = FALSE, $cols = 30, $rows = 5)
325	{
326		$pString = '';
327		if($label)
328			$pString = "$label:<br />";
329		$pString .= <<< END
330<textarea name="$name" id="$name" cols="$cols" rows="$rows">$value</textarea>
331END;
332		return $pString . "\n";
333	}
334// upload box
335	function fileUpload($label, $name, $size = 20)
336	{
337		$pString = '';
338		if($label)
339			$pString = "$label:<br />";
340		$pString .= <<< END
341<input type="file" name="$name" size="$size" />
342END;
343		return $pString . "\n";
344	}
345}
346?>
347