Projekt

Obecné

Profil

Stáhnout (23 KB) Statistiky
| Větev: | Tag: | Revize:
1
<?php
2

    
3
	/**
4
	 * Manage functions in a database
5
	 *
6
	 * $Id: functions.php,v 1.52 2005/10/18 03:45:16 chriskl Exp $
7
	 */
8

    
9
	// Include application functions
10
	include_once('./libraries/lib.inc.php');
11
	
12
	$action = (isset($_REQUEST['action'])) ? $_REQUEST['action'] : '';
13
	if (!isset($msg)) $msg = '';
14
	$PHP_SELF = $_SERVER['PHP_SELF'];
15
	
16
	/** 
17
	 * Function to save after editing a function
18
	 */
19
	function doSaveEdit() {
20
		global $data, $lang;
21
		
22
		$fnlang = strtolower($_POST['original_lang']);
23
		
24
		if ($fnlang == 'c') {
25
			$def = array($_POST['formObjectFile'], $_POST['formLinkSymbol']);
26
		} else if ($fnlang == 'internal'){
27
			$def = $_POST['formLinkSymbol'];
28
		} else {
29
			$def = $_POST['formDefinition'];
30
		}
31
		
32
		$status = $data->setFunction($_POST['function_oid'], $_POST['original_function'], $_POST['formFunction'], 
33
										$_POST['original_arguments'], 
34
										$_POST['original_returns'], $def,
35
										$_POST['original_lang'], $_POST['formProperties'], 
36
										isset($_POST['original_setof']), $_POST['formComment']);
37
		if ($status == 0)
38
			doProperties($lang['strfunctionupdated']);
39
		else
40
			doEdit($lang['strfunctionupdatedbad']);
41
	}
42
	
43
	/**
44
	 * Function to allow editing of a Function
45
	 */
46
	function doEdit($msg = '') {
47
		global $data, $misc;
48
		global $PHP_SELF, $lang;
49
		
50
		$misc->printTrail('function');
51
		$misc->printTitle($lang['stralter'],'pg.function.alter');
52
		$misc->printMsg($msg);
53

    
54
		$fndata = $data->getFunction($_REQUEST['function_oid']);
55

    
56
		if ($fndata->recordCount() > 0) {
57
			$fndata->f['proretset'] = $data->phpBool($fndata->f['proretset']);
58

    
59
			// Initialise variables
60
			if (!isset($_POST['formDefinition'])) $_POST['formDefinition'] = $fndata->f['prosrc'];
61
			if (!isset($_POST['formProperties'])) $_POST['formProperties'] = $data->getFunctionProperties($fndata->f);
62
			if (!isset($_POST['formFunction'])) $_POST['formFunction'] = $fndata->f['proname'];
63
			if (!isset($_POST['formComment'])) $_POST['formComment'] = $fndata->f['procomment'];
64
			if (!isset($_POST['formObjectFile'])) $_POST['formObjectFile'] = $fndata->f['probin'];
65
			if (!isset($_POST['formLinkSymbol'])) $_POST['formLinkSymbol'] = $fndata->f['prosrc'];
66

    
67
			// Deal with named parameters
68
			if ($data->hasNamedParams()) {
69
				$args_arr = explode(', ', $fndata->f['proarguments']);
70
				$names_arr = $data->phpArray($fndata->f['proargnames']);
71
				$args = '';
72
				$i = 0;
73
				for ($i = 0; $i < sizeof($args_arr); $i++) {
74
					if ($i != 0) $args .= ', ';
75
					if (isset($names_arr[$i]) && $names_arr[$i] != '') {
76
						$data->fieldClean($names_arr[$i]);					
77
						$args .= '"' . $names_arr[$i] . '" ';
78
					}
79
					$args .= $args_arr[$i];
80
				}
81
			}
82
			else {
83
				$args = $fndata->f['proarguments'];
84
			}
85

    
86
			$func_full = $fndata->f['proname'] . "(". $fndata->f['proarguments'] .")";
87
			echo "<form action=\"$PHP_SELF\" method=\"post\">\n";
88
			echo "<table width=\"90%\">\n";
89
			echo "<tr>\n";
90
			echo "<th class=\"data required\">{$lang['strfunction']}</th>\n";
91
			echo "<th class=\"data\">{$lang['strarguments']}</th>\n";
92
			echo "<th class=\"data required\">{$lang['strreturns']}</th>\n";
93
			echo "<th class=\"data required\">{$lang['strproglanguage']}</th>\n";
94
			echo "</tr>\n";
95
				
96

    
97
			echo "<tr>\n";
98
			echo "<td class=\"data1\">";
99
			echo "<input type=\"hidden\" name=\"original_function\" value=\"", htmlspecialchars($fndata->f['proname']),"\" />\n"; 
100
			echo "<input name=\"formFunction\" style=\"width: 100%\" maxlength=\"{$data->_maxNameLen}\" value=\"", htmlspecialchars($_POST['formFunction']), "\" />";
101
			echo "</td>\n";
102

    
103
			echo "<td class=\"data1\">", $misc->printVal($args), "\n";
104
			echo "<input type=\"hidden\" name=\"original_arguments\" value=\"",htmlspecialchars($args),"\" />\n"; 
105
			echo "</td>\n";
106

    
107
			echo "<td class=\"data1\">";
108
			if ($fndata->f['proretset']) echo "setof ";
109
			echo $misc->printVal($fndata->f['proresult']), "\n";
110
			echo "<input type=\"hidden\" name=\"original_returns\" value=\"", htmlspecialchars($fndata->f['proresult']), "\" />\n"; 
111
			if ($fndata->f['proretset'])
112
				echo "<input type=\"hidden\" name=\"original_setof\" value=\"yes\" />\n"; 
113
			echo "</td>\n";
114

    
115
			echo "<td class=\"data1\">", $misc->printVal($fndata->f['prolanguage']), "\n";
116
			echo "<input type=\"hidden\" name=\"original_lang\" value=\"", htmlspecialchars($fndata->f['prolanguage']), "\" />\n"; 
117
			echo "</td>\n";
118
			
119
			$fnlang = strtolower($fndata->f['prolanguage']);
120
			if ($fnlang == 'c') {
121
				echo "<tr><th class=\"data required\" colspan=\"2\">{$lang['strobjectfile']}</th>\n";
122
				echo "<th class=\"data\" colspan=\"2\">{$lang['strlinksymbol']}</th></tr>\n";
123
				echo "<tr><td class=\"data1\" colspan=\"2\"><input type=\"text\" name=\"formObjectFile\" style=\"width:100%\" value=\"",
124
					htmlspecialchars($_POST['formObjectFile']), "\" /></td>\n";
125
				echo "<td class=\"data1\" colspan=\"2\"><input type=\"text\" name=\"formLinkSymbol\" style=\"width:100%\" value=\"",
126
					htmlspecialchars($_POST['formLinkSymbol']), "\" /></td></tr>\n";
127
			} else if ($fnlang == 'internal') {
128
				echo "<tr><th class=\"data\" colspan=\"4\">{$lang['strlinksymbol']}</th></tr>\n";
129
				echo "<tr><td class=\"data1\" colspan=\"4\"><input type=\"text\" name=\"formLinkSymbol\" style=\"width:100%\" value=\"",
130
					htmlspecialchars($_POST['formLinkSymbol']), "\" /></td></tr>\n";
131
			} else {
132
				echo "<tr><th class=\"data required\" colspan=\"4\">{$lang['strdefinition']}</th></tr>\n";
133
				echo "<tr><td class=\"data1\" colspan=\"4\"><textarea style=\"width:100%;\" rows=\"20\" cols=\"50\" name=\"formDefinition\" wrap=\"virtual\">", 
134
					htmlspecialchars($_POST['formDefinition']), "</textarea></td></tr>\n";
135
			}
136
			
137
			// Display function comment
138
			echo "<tr><th class=\"data\" colspan=\"4\">{$lang['strcomment']}</th></tr>\n";
139
			echo "<tr><td class=\"data1\" colspan=\"4\"><textarea style=\"width:100%;\" name=\"formComment\" rows=\"3\" cols=\"50\" wrap=\"virtual\">", 
140
					htmlspecialchars($_POST['formComment']), "</textarea></td></tr>\n";
141
			// Display function properies
142
			if (is_array($data->funcprops) && sizeof($data->funcprops) > 0) {
143
				echo "<tr><th class=\"data\" colspan=\"4\">{$lang['strproperties']}</th></tr>\n";
144
				echo "<tr><td class=\"data1\" colspan=\"4\">\n";
145
				$i = 0;
146
				foreach ($data->funcprops as $k => $v) {
147
					echo "<select name=\"formProperties[{$i}]\">\n";
148
					foreach ($v as $p) {
149
						echo "<option value=\"", htmlspecialchars($p), "\"", 
150
							($p == $_POST['formProperties'][$i]) ? ' selected="selected"' : '', 
151
							">", $misc->printVal($p), "</option>\n";
152
					}
153
					echo "</select><br />\n";
154
					$i++;
155
				}
156
				echo "</td></tr>\n";
157
			}		
158
			echo "</table>\n";
159
			echo "<p><input type=\"hidden\" name=\"action\" value=\"save_edit\" />\n";
160
			echo "<input type=\"hidden\" name=\"function\" value=\"", htmlspecialchars($_REQUEST['function']), "\" />\n";
161
			echo "<input type=\"hidden\" name=\"function_oid\" value=\"", htmlspecialchars($_REQUEST['function_oid']), "\" />\n";
162
			echo $misc->form;
163
			echo "<input type=\"submit\" value=\"{$lang['stralter']}\" />\n";
164
			echo "<input type=\"submit\" name=\"cancel\" value=\"{$lang['strcancel']}\" /></p>\n";
165
			echo "</form>\n";
166
		}
167
		else echo "<p>{$lang['strnodata']}</p>\n";
168
	}
169

    
170
	/**
171
	 * Show read only properties of a function
172
	 */
173
	function doProperties($msg = '') {
174
		global $data, $misc;
175
		global $PHP_SELF, $lang;
176
		
177
		$misc->printTrail('function');
178
		$misc->printTitle($lang['strproperties'],'pg.function');
179
		$misc->printMsg($msg);
180
		
181
		$funcdata = $data->getFunction($_REQUEST['function_oid']);
182
		
183
		if ($funcdata->recordCount() > 0) {
184
			// Deal with named parameters
185
			if ($data->hasNamedParams()) {
186
				$args_arr = explode(', ', $funcdata->f['proarguments']);
187
				$names_arr = $data->phpArray($funcdata->f['proargnames']);
188
				$args = '';
189
				$i = 0;
190
				for ($i = 0; $i < sizeof($args_arr); $i++) {
191
					if ($i != 0) $args .= ', ';
192
					if (isset($names_arr[$i]) && $names_arr[$i] != '') {
193
						$data->fieldClean($names_arr[$i]);					
194
						$args .= '"' . $names_arr[$i] . '" ';
195
					}
196
					$args .= $args_arr[$i];
197
				}
198
			}
199
			else {
200
				$args = $funcdata->f['proarguments'];
201
			}
202

    
203
			// Show comment if any
204
			if ($funcdata->f['procomment'] !== null)
205
				echo "<p class=\"comment\">", $misc->printVal($funcdata->f['procomment']), "</p>\n";
206

    
207
			$funcdata->f['proretset'] = $data->phpBool($funcdata->f['proretset']);
208
			$func_full = $funcdata->f['proname'] . "(". $funcdata->f['proarguments'] .")";
209
			echo "<table width=\"90%\">\n";
210
			echo "<tr><th class=\"data\">{$lang['strfunction']}</th>\n";
211
			echo "<th class=\"data\">{$lang['strarguments']}</th>\n";
212
			echo "<th class=\"data\">{$lang['strreturns']}</th>\n";
213
			echo "<th class=\"data\">{$lang['strproglanguage']}</th></tr>\n";
214
			echo "<tr><td class=\"data1\">", $misc->printVal($funcdata->f['proname']), "</td>\n";
215
			echo "<td class=\"data1\">", $misc->printVal($args), "</td>\n";
216
			echo "<td class=\"data1\">";
217
			if ($funcdata->f['proretset']) echo "setof ";			
218
			echo $misc->printVal($funcdata->f['proresult']), "</td>\n";
219
			echo "<td class=\"data1\">", $misc->printVal($funcdata->f['prolanguage']), "</td></tr>\n";
220
			
221
			$fnlang = strtolower($funcdata->f['prolanguage']);
222
			if ($fnlang == 'c') {
223
				echo "<tr><th class=\"data\" colspan=\"2\">{$lang['strobjectfile']}</th>\n";
224
				echo "<th class=\"data\" colspan=\"2\">{$lang['strlinksymbol']}</th></tr>\n";
225
				echo "<tr><td class=\"data1\" colspan=\"2\">", $misc->printVal($funcdata->f['probin']), "</td>\n";
226
				echo "<td class=\"data1\" colspan=\"2\">", $misc->printVal($funcdata->f['prosrc']), "</td></tr>\n";
227
			} else if ($fnlang == 'internal') {
228
				echo "<tr><th class=\"data\" colspan=\"4\">{$lang['strlinksymbol']}</th></tr>\n";
229
				echo "<tr><td class=\"data1\" colspan=\"4\">", $misc->printVal($funcdata->f['prosrc']), "</td></tr>\n";
230
			} else {
231
				include_once('./libraries/highlight.php');		
232
				echo "<tr><th class=\"data\" colspan=\"4\">{$lang['strdefinition']}</th></tr>\n";
233
				// Check to see if we have syntax highlighting for this language
234
				if (isset($data->langmap[$funcdata->f['prolanguage']])) {
235
					$temp = syntax_highlight(htmlspecialchars($funcdata->f['prosrc']), $data->langmap[$funcdata->f['prolanguage']]);
236
					$tag = 'prenoescape';
237
				}
238
				else {
239
					$temp = $funcdata->f['prosrc'];
240
					$tag = 'pre';
241
				}
242
				echo "<tr><td class=\"data1\" colspan=\"4\">", $misc->printVal($temp, $tag, array('lineno' => true, 'class' => 'data1')), "</td></tr>\n";
243
			}
244
			
245
			// Show flags
246
			if (is_array($data->funcprops) && sizeof($data->funcprops) > 0) {
247
				// Fetch an array of the function properties
248
				$funcprops = $data->getFunctionProperties($funcdata->f);
249
				echo "<tr><th class=\"data\" colspan=\"4\">{$lang['strproperties']}</th></tr>\n";
250
				echo "<tr><td class=\"data1\" colspan=\"4\">\n";
251
				foreach ($funcprops as $v) {
252
					echo $misc->printVal($v), "<br />\n";
253
				}
254
				echo "</td></tr>\n";
255
			}		
256
			echo "</table>\n";
257
		}
258
		else echo "<p>{$lang['strnodata']}</p>\n";
259
		
260
		echo "<p><a class=\"navlink\" href=\"$PHP_SELF?{$misc->href}\">{$lang['strshowallfunctions']}</a> |\n";
261
		echo "<a class=\"navlink\" href=\"$PHP_SELF?action=edit&amp;{$misc->href}&amp;function=", 
262
			urlencode($_REQUEST['function']), "&amp;function_oid=", urlencode($_REQUEST['function_oid']), "\">{$lang['stralter']}</a> |\n";
263
		echo "<a class=\"navlink\" href=\"$PHP_SELF?action=confirm_drop&amp;{$misc->href}&amp;function=",
264
			urlencode($func_full), "&amp;function_oid=", $_REQUEST['function_oid'], "\">{$lang['strdrop']}</a>\n";
265
	}
266
	
267
	/**
268
	 * Show confirmation of drop and perform actual drop
269
	 */
270
	function doDrop($confirm) {
271
		global $data, $misc;
272
		global $PHP_SELF, $lang;
273

    
274
		if ($confirm) {
275
			$misc->printTrail('schema');
276
			$misc->printTitle($lang['strdrop'],'pg.function.drop');
277
			
278
			echo "<p>", sprintf($lang['strconfdropfunction'], $misc->printVal($_REQUEST['function'])), "</p>\n";	
279
			
280
			echo "<form action=\"$PHP_SELF\" method=\"post\">\n";
281
			echo "<input type=\"hidden\" name=\"action\" value=\"drop\" />\n";
282
			echo "<input type=\"hidden\" name=\"function\" value=\"", htmlspecialchars($_REQUEST['function']), "\" />\n";
283
			echo "<input type=\"hidden\" name=\"function_oid\" value=\"", htmlspecialchars($_REQUEST['function_oid']), "\" />\n";
284
			echo $misc->form;
285
			// Show cascade drop option if supportd
286
			if ($data->hasDropBehavior()) {
287
				echo "<p><input type=\"checkbox\" name=\"cascade\" /> {$lang['strcascade']}</p>\n";
288
			}
289
			echo "<input type=\"submit\" name=\"drop\" value=\"{$lang['strdrop']}\" />\n";
290
			echo "<input type=\"submit\" name=\"cancel\" value=\"{$lang['strcancel']}\" />\n";
291
			echo "</form>\n";
292
		}
293
		else {
294
			$status = $data->dropFunction($_POST['function_oid'], isset($_POST['cascade']));
295
			if ($status == 0)
296
				doDefault($lang['strfunctiondropped']);
297
			else
298
				doDefault($lang['strfunctiondroppedbad']);
299
		}
300
		
301
	}
302
	
303
	/**
304
	 * Displays a screen where they can enter a new function
305
	 */
306
	function doCreate($msg = '') {
307
		global $data, $misc;
308
		global $PHP_SELF, $lang;
309
		
310
		$misc->printTrail('schema');
311
		
312
		if (!isset($_POST['formFunction'])) $_POST['formFunction'] = '';
313
		if (!isset($_POST['formArguments'])) $_POST['formArguments'] = '';
314
		if (!isset($_POST['formReturns'])) $_POST['formReturns'] = '';
315
		if (!isset($_POST['formLanguage'])) $_POST['formLanguage'] = isset($_REQUEST['language']) ? $_REQUEST['language'] : 'sql';
316
		if (!isset($_POST['formDefinition'])) $_POST['formDefinition'] = '';
317
		if (!isset($_POST['formObjectFile'])) $_POST['formObjectFile'] = '';
318
		if (!isset($_POST['formLinkSymbol'])) $_POST['formLinkSymbol'] = '';
319
		if (!isset($_POST['formProperties'])) $_POST['formProperties'] = $data->defaultprops;
320
		if (!isset($_POST['formSetOf'])) $_POST['formSetOf'] = '';
321
		if (!isset($_POST['formArray'])) $_POST['formArray'] = '';
322

    
323
		$types = $data->getTypes(true, true, true);
324
		$langs = $data->getLanguages(true);
325
		$fnlang = strtolower($_POST['formLanguage']);
326

    
327
		switch ($fnlang) {
328
			case 'c':
329
				$misc->printTitle($lang['strcreatecfunction'],'pg.function.create.c');
330
				break;
331
			case 'internal':
332
				$misc->printTitle($lang['strcreateinternalfunction'],'pg.function.create.internal');
333
				break;
334
			default:
335
				$misc->printTitle($lang['strcreateplfunction'],'pg.function.create.pl');
336
				break;
337
		}
338
		$misc->printMsg($msg);
339

    
340
		echo "<form action=\"$PHP_SELF\" method=post>\n";
341
		echo "<table>\n";
342
		echo "<tr><th class=\"data required\">{$lang['strname']}</th>\n";
343
		echo "<th class=\"data\">{$lang['strarguments']}</th>\n";
344
		echo "<th class=\"data required\">{$lang['strreturns']}</th>\n";
345
		echo "<th class=\"data required\">{$lang['strproglanguage']}</th></tr>\n";
346

    
347
		echo "<tr><td class=\"data1\"><input name=\"formFunction\" size=\"16\" maxlength=\"{$data->_maxNameLen}\" value=\"",
348
			htmlspecialchars($_POST['formFunction']), "\" /></td>\n";
349

    
350
		echo "<td class=\"data1\"><input name=\"formArguments\" style=\"width:100%;\" size=\"16\" value=\"",
351
			htmlspecialchars($_POST['formArguments']), "\" /></td>\n";
352

    
353
		echo "<td class=\"data1\">\n";
354
		// Output setof option
355
		echo "<select name=\"formSetOf\">\n";
356
		echo '<option value=""', ($_POST['formSetOf'] == '') ? ' selected="selected"' : '', "></option>\n";
357
		echo '<option value="SETOF"', ($_POST['formSetOf'] == 'SETOF') ? ' selected="selected"' : '', ">SETOF</option>\n";
358
		echo "</select>\n";
359

    
360
		// Output return type list		
361
		echo "<select name=\"formReturns\">\n";
362
		while (!$types->EOF) {
363
			echo "<option value=\"", htmlspecialchars($types->f['typname']), "\"", 
364
				($types->f['typname'] == $_POST['formReturns']) ? ' selected="selected"' : '', ">",
365
				$misc->printVal($types->f['typname']), "</option>\n";
366
			$types->moveNext();
367
		}
368
		echo "</select>\n";
369
		
370
		// Output array type selector
371
		echo "<select name=\"formArray\">\n";
372
		echo "<option value=\"\"", ($_POST['formArray'] == '') ? ' selected="selected"' : '', "></option>\n";
373
		echo "<option value=\"[]\"", ($_POST['formArray'] == '[]') ? ' selected="selected"' : '', ">[ ]</option>\n";
374
		echo "</select></td>\n";
375

    
376
		// Output language
377
		echo "<td class=\"data1\">";
378
		if ($fnlang == 'c' || $fnlang == 'internal') echo $_POST['formLanguage'], "<input type=\"hidden\" name=\"formLanguage\" value=\"{$_POST['formLanguage']}\" />";
379
		else {
380
			echo "<select name=\"formLanguage\">\n";
381
			while (!$langs->EOF) {
382
				if (strtolower($langs->f['lanname']) != 'c' && strtolower($langs->f['lanname']) != 'internal')
383
					echo "<option value=\"", htmlspecialchars($langs->f['lanname']), "\"",
384
						($langs->f['lanname'] == $_POST['formLanguage']) ? ' selected="selected"' : '', ">",
385
						$misc->printVal($langs->f['lanname']), "</option>\n";
386
				$langs->moveNext();
387
			}
388
			echo "</select>\n";
389
		}
390
		echo "</td></tr>\n";
391
		
392
		if ($fnlang == 'c') {
393
			echo "<tr><th class=\"data required\" colspan=\"2\">{$lang['strobjectfile']}</th>\n";
394
			echo "<th class=\"data\" colspan=\"2\">{$lang['strlinksymbol']}</th></tr>\n";
395
			echo "<tr><td class=\"data1\" colspan=\"2\"><input type=\"text\" name=\"formObjectFile\" style=\"width:100%\" value=\"",
396
				htmlspecialchars($_POST['formObjectFile']), "\" /></td>\n";
397
			echo "<td class=\"data1\" colspan=\"2\"><input type=\"text\" name=\"formLinkSymbol\" style=\"width:100%\" value=\"",
398
				htmlspecialchars($_POST['formLinkSymbol']), "\" /></td></tr>\n";
399
		} else if ($fnlang == 'internal') {
400
			echo "<tr><th class=\"data\" colspan=\"4\">{$lang['strlinksymbol']}</th></tr>\n";
401
			echo "<td class=\"data1\" colspan=\"4\"><input type=\"text\" name=\"formLinkSymbol\" style=\"width:100%\" value=\"",
402
				htmlspecialchars($_POST['formLinkSymbol']), "\" /></td></tr>\n";
403
		} else {
404
			echo "<tr><th class=\"data required\" colspan=\"4\">{$lang['strdefinition']}</th></tr>\n";
405
			echo "<tr><td class=\"data1\" colspan=\"4\"><textarea style=\"width:100%;\" rows=\"20\" cols=\"50\" name=\"formDefinition\" wrap=\"virtual\">", 
406
				htmlspecialchars($_POST['formDefinition']), "</textarea></td></tr>\n";
407
		}
408
		
409
		// Display function properies
410
		if (is_array($data->funcprops) && sizeof($data->funcprops) > 0) {
411
			echo "<tr><th class=\"data\" colspan=\"4\">{$lang['strproperties']}</th></tr>\n";
412
			echo "<tr><td class=\"data1\" colspan=\"4\">\n";
413
			$i = 0;
414
			foreach ($data->funcprops as $k => $v) {
415
				echo "<select name=\"formProperties[{$i}]\">\n";
416
				foreach ($v as $p) {
417
					echo "<option value=\"", htmlspecialchars($p), "\"", 
418
						($p == $_POST['formProperties'][$i]) ? ' selected="selected"' : '', 
419
						">", $misc->printVal($p), "</option>\n";
420
				}
421
				echo "</select><br />\n";
422
				$i++;
423
			}
424
			echo "</td></tr>\n";
425
		}		
426
		echo "</table>\n";
427
		echo "<p><input type=\"hidden\" name=\"action\" value=\"save_create\" />\n";
428
		echo $misc->form;
429
		echo "<input type=\"submit\" value=\"{$lang['strcreate']}\" />\n";
430
		echo "<input type=\"submit\" name=\"cancel\" value=\"{$lang['strcancel']}\" /></p>\n";
431
		echo "</form>\n";
432
	}
433
	
434
	/**
435
	 * Actually creates the new function in the database
436
	 */
437
	function doSaveCreate() {
438
		global $data, $lang;
439
		
440
		$fnlang = strtolower($_POST['formLanguage']);
441
		
442
		if ($fnlang == 'c') {
443
			$def = array($_POST['formObjectFile'], $_POST['formLinkSymbol']);
444
		} else if ($fnlang == 'internal'){
445
			$def = $_POST['formLinkSymbol'];
446
		} else {
447
			$def = $_POST['formDefinition'];
448
		}
449

    
450
		// Check that they've given a name and a definition
451
		if ($_POST['formFunction'] == '') doCreate($lang['strfunctionneedsname']);
452
		elseif ($fnlang != 'internal' && !$def) doCreate($lang['strfunctionneedsdef']);
453
		else {
454
			// Append array symbol to type if chosen
455
			$status = $data->createFunction($_POST['formFunction'], $_POST['formArguments'] , 
456
					$_POST['formReturns'] . $_POST['formArray'] , $def , $_POST['formLanguage'], 
457
					$_POST['formProperties'], $_POST['formSetOf'] == 'SETOF', false);
458
			if ($status == 0)
459
				doDefault($lang['strfunctioncreated']);
460
			else
461
				doCreate($lang['strfunctioncreatedbad']);
462
		}
463
	}	
464

    
465
	/**
466
	 * Show default list of functions in the database
467
	 */
468
	function doDefault($msg = '') {
469
		global $data, $conf, $misc, $func;
470
		global $PHP_SELF, $lang;
471
		
472
		$misc->printTrail('schema');
473
		$misc->printTabs('schema','functions');
474
		$misc->printMsg($msg);
475
		
476
		$funcs = $data->getFunctions();
477
		
478
		$columns = array(
479
			'function' => array(
480
				'title' => $lang['strfunction'],
481
				'field' => 'proproto',
482
				'type'  => 'verbatim',
483
			),
484
			'returns' => array(
485
				'title' => $lang['strreturns'],
486
				'field' => 'proreturns',
487
				'type'  => 'verbatim',
488
			),
489
			'owner' => array(
490
				'title' => $lang['strowner'],
491
				'field' => 'proowner',
492
			),
493
			'proglanguage' => array(
494
				'title' => $lang['strproglanguage'],
495
				'field' => 'prolanguage',
496
			),
497
			'actions' => array(
498
				'title' => $lang['stractions'],
499
			),
500
			'comment' => array(
501
				'title' => $lang['strcomment'],
502
				'field' => 'procomment',
503
			),
504
		);
505
		
506
		$actions = array(
507
			'properties' => array(
508
				'title' => $lang['strproperties'],
509
				'url'   => "redirect.php?subject=function&amp;action=properties&amp;{$misc->href}&amp;",
510
				'vars'  => array('function' => 'proproto', 'function_oid' => 'prooid'),
511
			),
512
			'alter' => array(
513
				'title' => $lang['stralter'],
514
				'url'   => "{$PHP_SELF}?action=edit&amp;{$misc->href}&amp;",
515
				'vars'  => array('function' => 'proproto', 'function_oid' => 'prooid'),
516
			),
517
			'drop' => array(
518
				'title' => $lang['strdrop'],
519
				'url'   => "{$PHP_SELF}?action=confirm_drop&amp;{$misc->href}&amp;",
520
				'vars'  => array('function' => 'proproto', 'function_oid' => 'prooid'),
521
			),
522
			'privileges' => array(
523
				'title' => $lang['strprivileges'],
524
				'url'   => "privileges.php?{$misc->href}&amp;subject=function&amp;",
525
				'vars'  => array('function' => 'proproto', 'function_oid' => 'prooid'),
526
			),
527
		);
528

    
529
		if ( !$data->hasFuncPrivs() ) {
530
			unset($actions['privileges']);
531
		}
532
		
533
		$misc->printTable($funcs, $columns, $actions, $lang['strnofunctions']);
534

    
535
		echo "<p><a class=\"navlink\" href=\"{$PHP_SELF}?action=create&amp;{$misc->href}\">{$lang['strcreateplfunction']}</a> | ";
536
		echo "<a class=\"navlink\" href=\"{$PHP_SELF}?action=create&amp;language=internal&amp;{$misc->href}\">{$lang['strcreateinternalfunction']}</a> | ";
537
		echo "<a class=\"navlink\" href=\"{$PHP_SELF}?action=create&amp;language=C&amp;{$misc->href}\">{$lang['strcreatecfunction']}</a></p>\n";
538
	}
539
	
540
	/**
541
	 * Generate XML for the browser tree.
542
	 */
543
	function doTree() {
544
		global $misc, $data;
545
		
546
		$funcs = $data->getFunctions();
547
		
548
		$proto = concat(field('proname'),' (',field('proarguments'),')');
549
		
550
		$reqvars = $misc->getRequestVars('function');
551
		
552
		$attrs = array(
553
			'text'    => $proto,
554
			'icon'    => 'functions',
555
			'toolTip' => field('procomment'),
556
			'action'  => url('redirect.php',
557
							$reqvars,
558
							array(
559
								'action' => 'properties',
560
								'function' => $proto,
561
								'function_oid' => field('prooid')
562
							)
563
						)
564
		);
565
		
566
		$misc->printTreeXML($funcs, $attrs);
567
		exit;
568
	}
569
	
570
	if ($action == 'tree') doTree();
571
	
572
	$misc->printHeader($lang['strfunctions']);
573
	$misc->printBody();
574

    
575
	switch ($action) {
576
		case 'save_create':
577
			if (isset($_POST['cancel'])) doDefault();
578
			else doSaveCreate();
579
			break;
580
		case 'create':
581
			doCreate();
582
			break;
583
		case 'drop':
584
			if (isset($_POST['drop'])) doDrop(false);
585
			else doDefault();
586
			break;
587
		case 'confirm_drop':
588
			doDrop(true);
589
			break;			
590
		case 'save_edit':
591
			if (isset($_POST['cancel'])) doDefault();
592
			else doSaveEdit();
593
			break;
594
		case 'edit':
595
			doEdit();
596
			break;
597
		case 'properties':
598
			doProperties();
599
			break;
600
		default:
601
			doDefault();
602
			break;
603
	}	
604

    
605
	$misc->printFooter();
606
	
607
?>
(21-21/53)