File: index.php

package info (click to toggle)
opendb 0.81p18-2
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 4,716 kB
  • ctags: 6,787
  • sloc: php: 50,213; sql: 3,098; sh: 272; makefile: 54; xml: 48
file content (355 lines) | stat: -rw-r--r-- 19,293 bytes parent folder | download
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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
<?php
/* 	OpenDb - Open Media Lending Database
	Copyright (C) 2001,2002 by Jason Pell

	This program is free software; you can redistribute it and/or
	modify it under the terms of the GNU General Public License
	as published by the Free Software Foundation; either version 2
	of the License, or (at your option) any later version.

	This program is distributed in the hope that it will be useful,
	but WITHOUT ANY WARRANTY; without even the implied warranty of
	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
	GNU General Public License for more details.

	You should have received a copy of the GNU General Public License
	along with this program; if not, write to the Free Software
	Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
*/

include_once("./functions/user.php");
include_once("./functions/status_type.php");

function display_edit_form($status_type_r, $HTTP_VARS=NULL)
{
	global $_COLUMN_DESC;
	
	if(is_array($status_type_r))
		echo get_input_field("s_status_type", NULL, $_COLUMN_DESC['s_status_type'], "readonly", "Y", $status_type_r['s_status_type'], TRUE, "%prompt%<a class=\"smlink\" href=\"javascript:popup('admin.php?type=s_status_type&op=help&inc_header=N&column=s_status_type','500', '350')\">(?)</a>");
	else
		echo get_input_field("s_status_type", NULL, $_COLUMN_DESC['s_status_type'], "text(1,1)", "Y", $HTTP_VARS['s_status_type'], TRUE, "%prompt%<a class=\"smlink\" href=\"javascript:popup('admin.php?type=s_status_type&op=help&inc_header=N&column=s_status_type','500', '350')\">(?)</a>");

	echo get_input_field("description", NULL, $_COLUMN_DESC['description'], "text(30,60)", "Y", ifempty($status_type_r['description'],$HTTP_VARS['description']), TRUE, "%prompt%<a class=\"smlink\" href=\"javascript:popup('admin.php?type=s_status_type&op=help&inc_header=N&column=description','500', '350')\">(?)</a>");

	$field = get_input_field("img", NULL, $_COLUMN_DESC['img'], "url(15,*,\"gif,jpg,png\",N)", "N", ifempty($status_type_r['img'],$HTTP_VARS['img']), FALSE);
	$image_src = _theme_image_src(ifempty($status_type_r['img'],$HTTP_VARS['img']));
	if($image_src!==FALSE && strlen($image_src)>0)
		$field .= " <img align=absmiddle valign=absmiddle src=\"$image_src\">";
	echo format_field($_COLUMN_DESC['img'], NULL, $field, TRUE, "%prompt%<a class=\"smlink\" href=\"javascript:popup('admin.php?type=s_status_type&op=help&inc_header=N&column=img','500', '350')\">(?)</a>");
	
	echo get_input_field("insert_ind", NULL, $_COLUMN_DESC['insert_ind'], "value_radio_grid('Y,N',*)", "N", ifempty($status_type_r['insert_ind'],$HTTP_VARS['insert_ind']), TRUE, "%prompt%<a class=\"smlink\" href=\"javascript:popup('admin.php?type=s_status_type&op=help&inc_header=N&column=insert_ind','500', '350')\">(?)</a>");
	echo get_input_field("update_ind", NULL, $_COLUMN_DESC['update_ind'], "value_radio_grid('Y,N',*)", "N", ifempty($status_type_r['update_ind'],$HTTP_VARS['update_ind']), TRUE, "%prompt%<a class=\"smlink\" href=\"javascript:popup('admin.php?type=s_status_type&op=help&inc_header=N&column=update_ind','500', '350')\">(?)</a>");
	echo get_input_field("delete_ind", NULL, $_COLUMN_DESC['delete_ind'], "value_radio_grid('Y,N',*)", "N", ifempty($status_type_r['delete_ind'],$HTTP_VARS['delete_ind']), TRUE, "%prompt%<a class=\"smlink\" href=\"javascript:popup('admin.php?type=s_status_type&op=help&inc_header=N&column=delete_ind','500', '350')\">(?)</a>");
	echo get_input_field("change_owner_ind", NULL, $_COLUMN_DESC['change_owner_ind'], "value_radio_grid('Y,N',*)", "N", ifempty($status_type_r['change_owner_ind'], ifempty($HTTP_VARS['change_owner_ind'],"N")), TRUE, "%prompt%<a class=\"smlink\" href=\"javascript:popup('admin.php?type=s_status_type&op=help&inc_header=N&column=change_owner_ind','500', '350')\">(?)</a>");
	
	$user_type_rs = array_merge(array(array('value'=>'', 'display'=>'')), get_user_types_rs(get_user_types_r()));
	echo format_field($_COLUMN_DESC['min_display_user_type'], NULL, custom_select("min_display_user_type", $user_type_rs, '%value% - %display%', 1, ifempty($status_type_r['min_display_user_type'],$HTTP_VARS['min_display_user_type'])), TRUE, "%prompt%<a class=\"smlink\" href=\"javascript:popup('admin.php?type=s_status_type&op=help&inc_header=N&column=min_display_user_type','500', '350')\">(?)</a>");
	echo format_field($_COLUMN_DESC['min_create_user_type'], NULL, custom_select("min_create_user_type", $user_type_rs, '%value% - %display%', 1, ifempty($status_type_r['min_create_user_type'],$HTTP_VARS['min_create_user_type'])), TRUE, "%prompt%<a class=\"smlink\" href=\"javascript:popup('admin.php?type=s_status_type&op=help&inc_header=N&column=min_create_user_type','500', '350')\">(?)</a>");
	
	echo get_input_field("new_owner_instance_ind", NULL, $_COLUMN_DESC['new_owner_instance_ind'], "value_radio_grid('Y,N',*)", "N", ifempty($status_type_r['new_owner_instance_ind'],$HTTP_VARS['new_owner_instance_ind']), TRUE, "%prompt%<a class=\"smlink\" href=\"javascript:popup('admin.php?type=s_status_type&op=help&inc_header=N&column=new_owner_instance_ind','500', '350')\">(?)</a>");
	echo get_input_field("new_not_owner_instance_ind", NULL, $_COLUMN_DESC['new_not_owner_instance_ind'], "value_radio_grid('Y,N',*)", "N", ifempty($status_type_r['new_not_owner_instance_ind'],$HTTP_VARS['new_not_owner_instance_ind']), TRUE, "%prompt%<a class=\"smlink\" href=\"javascript:popup('admin.php?type=s_status_type&op=help&inc_header=N&column=new_not_owner_instance_ind','500', '350')\">(?)</a>");
	echo get_input_field("borrow_ind", NULL, $_COLUMN_DESC['borrow_ind'], "value_radio_grid('Y,N,B,X',*)", "N", ifempty($status_type_r['borrow_ind'],$HTTP_VARS['borrow_ind']), TRUE, "%prompt%<a class=\"smlink\" href=\"javascript:popup('admin.php?type=s_status_type&op=help&inc_header=N&column=borrow_ind','500', '350')\">(?)</a>");
	echo get_input_field("status_comment_ind", NULL, $_COLUMN_DESC['status_comment_ind'], "value_radio_grid('Y,H,N',*)", "N", ifempty($status_type_r['status_comment_ind'],$HTTP_VARS['status_comment_ind']), TRUE, "%prompt%<a class=\"smlink\" href=\"javascript:popup('admin.php?type=s_status_type&op=help&inc_header=N&column=status_comment_ind','500', '350')\">(?)</a>");
	echo get_input_field("default_ind", NULL, $_COLUMN_DESC['default_ind'], "checkbox(Y,N)", "N", ifempty($status_type_r['default_ind'],$HTTP_VARS['default_ind']), TRUE, "%prompt%<a class=\"smlink\" href=\"javascript:popup('admin.php?type=s_status_type&op=help&inc_header=N&column=default_ind','500', '350')\">(?)</a>");
	
	if(is_array($status_type_r))
		echo get_input_field("closed_ind", NULL, $_COLUMN_DESC['closed_ind'], "checkbox(Y,N)", "N", ifempty($status_type_r['closed_ind'],$HTTP_VARS['closed_ind']), TRUE, "%prompt%<a class=\"smlink\" href=\"javascript:popup('admin.php?type=s_status_type&op=help&inc_header=N&column=closed_ind','500', '350')\">(?)</a>");
}

function display_s_status_type_chooser($script_name, $type, $s_status_type)
{
	echo("\n<p><form action=\"$script_name\" method=\"get\">");
	echo("\n<input type=\"hidden\" name=\"op\" value=\"edit\">");
	echo("\n<input type=\"hidden\" name=\"type\" value=\"".$type."\">");

	$lookup_results = fetch_status_type_rs();
	echo custom_select("s_status_type", $lookup_results, "%s_status_type% - %description%", 1, $s_status_type, "s_status_type", NULL).
				"&nbsp;<input type=button value=\"Edit\" onclick=\"this.form['op'].value='edit'; this.form.submit();\">&nbsp;".
				"<input type=button value=\"New\" onclick=\"this.form['op'].value='new'; this.form.submit();\">";
	echo("</form></p>");
}

// temporary
function get_s_status_type_doc($columnname)
{
	global $_COLUMN_HELP;
	global $_COLUMN_DESC;

	if(isset($_COLUMN_HELP[$columnname]))
	{
		echo("<h3>".$_COLUMN_DESC[$columnname]."</h3>");
		echo("<p class=\"colortext\">Column: ".$columnname."</p>");
		echo(format_help_block($_COLUMN_HELP[$columnname]));
	}
	else
	{
		echo("<p class=\"colortext\">No Help available</p>");
	}
}

// #################################################################################
// Main Process
// #################################################################################
if(is_opendb_valid_session())
{
	if(is_user_admin($HTTP_SESSION_VARS['user_id'], $HTTP_SESSION_VARS['user_type']))
	{
		// Get rid of select box value.
		if($HTTP_VARS['op'] == 'new')
		{
			unset($HTTP_VARS['s_status_type']);
		}
			
		if($HTTP_VARS['op'] == 'help')
		{
			echo _theme_header("Status Type Help", FALSE);
			echo("\n<h2>Status Type Help</h2>");

			echo("<pre>".
				get_s_status_type_doc($HTTP_VARS['column']).
				"</pre>");
		}
		else if($HTTP_VARS['op'] == 'delete')
		{
			if(is_valid_s_status_type($HTTP_VARS['s_status_type']))
			{
				$status_type_r = fetch_status_type_r($HTTP_VARS['s_status_type']);
				
				if( $status_type_r['closed_ind'] != 'Y' && $status_type_r['default_ind'] == 'Y' &&
						fetch_default_status_type_cnt() <= 1)
				{
					display_s_status_type_chooser($PHP_SELF, $HTTP_VARS['type'], $HTTP_VARS['s_status_type']);
					
					echo("\n<h3>Delete Status type</h3>");
					echo format_error_block(array('error'=>'Status type not deleted','detail'=>'Status type is default and there are no other default records'));
				}
				else if(is_exists_items_with_status_type($HTTP_VARS['s_status_type']))// Validate that no items are attached for this status type.
				{
					// Display the chooser at the top whatever happens.
					display_s_status_type_chooser($PHP_SELF, $HTTP_VARS['type'], $HTTP_VARS['s_status_type']);

					echo("\n<h3>Delete Status type</h3>");
					echo format_error_block(array('error'=>'Status type not deleted','detail'=>'Status type cannot be deleted while '.$status_type_r['description'].' item instance(s) exist.'));
				}
				else
				{
					if($HTTP_VARS['confirmed'] == 'true')
					{
						if(delete_s_status_type($HTTP_VARS['s_status_type']))
						{
							display_s_status_type_chooser($PHP_SELF, $HTTP_VARS['type'], $HTTP_VARS['s_status_type']);
							
							echo("\n<h3>Delete Status type</h3>");
							echo("\n<div class=\"success\">Status type deleted</div>");
						}
						else
						{
							display_s_status_type_chooser($PHP_SELF, $HTTP_VARS['type'], $HTTP_VARS['s_status_type']);
							echo("\n<h3>Delete Status type</h3>");
							echo format_error_block(array('error'=>'Status type not deleted','detail'=>mysql_error()));
						}
					}
					else if($HTTP_VARS['confirmed'] != 'false')
					{
						display_s_status_type_chooser($PHP_SELF, $HTTP_VARS['type'], $HTTP_VARS['s_status_type']);
						echo("\n<h3>Delete Status type</h3>");
						echo(get_op_confirm_form($PHP_SELF, 
								"Are you sure you want to delete status type '".$HTTP_VARS['s_status_type']." - ".$status_type_r['description']."'?", 
								array('type'=>$HTTP_VARS['type'], 'op'=>'delete', 's_status_type'=>$HTTP_VARS['s_status_type'])));
					}
					else // confirmation required.
					{
						display_s_status_type_chooser($PHP_SELF, $HTTP_VARS['type'], $HTTP_VARS['s_status_type']);
						echo("\n<h3>Delete Status type</h3>");
						echo "\n<div class=\"success\">Status Type not deleted</div>";
					}
				}
			}
			else
			{
				echo format_error_block('Invalid status type specified');
			}
		}
		else if($HTTP_VARS['op'] == 'update')
		{
			display_s_status_type_chooser($PHP_SELF, $HTTP_VARS['type'], $HTTP_VARS['s_status_type']);
			echo("\n<h3>Update Status type</h3>");

			if(is_valid_s_status_type($HTTP_VARS['s_status_type']))
			{
				$status_type_r = fetch_status_type_r($HTTP_VARS['s_status_type']);
				
				// If default_ind is currently 'Y', and being set to 'N', or closed_ind being set 'Y' from 'N'
				if( (($HTTP_VARS['default_ind'] != 'Y' && $status_type_r['default_ind'] == 'Y') ||
					($HTTP_VARS['closed_ind'] == 'Y' && $status_type_r['closed_ind'] != 'Y' && $status_type_r['default_ind'] == 'Y')) &&
						fetch_default_status_type_cnt() <= 1)
				{
					echo format_error_block(
								array('error'=>'Status type not updated',
										'detail'=>'Status type is default, and there are no other default records'));
				}
				else if(user_type_cmp($status_type_r['min_create_user_type'], $HTTP_VARS['min_create_user_type']) > 0 && 
						is_exists_items_for_user_type_and_status_type($status_type_r['s_status_type'], $status_type_r['min_create_user_type']))
				{
					echo format_error_block(
								array('error'=>'Status type not updated',
									'detail'=>'Item instance(s) exist for user(s) whose type, is not compatible with the new \''.$_COLUMN_DESC['min_create_user_type'].'\' (min_create_user_type) value.'));
				}
				else if($HTTP_VARS['borrow_ind'] != $status_type_r['borrow_ind'] && $HTTP_VARS['borrow_ind'] != 'Y' && $HTTP_VARS['borrow_ind'] != 'N' && is_exists_borrowed_items_for_status_type($HTTP_VARS['s_status_type'], TRUE))
				{
					echo format_error_block(
								array('error'=>'Status type not updated',
									'detail'=>'Cannot update borrow_ind to \''.$HTTP_VARS['borrow_ind'].'\', as '.$status_type_r['description'].' item instance(s) exist, which are currently checked out.'));
				}
				else if($HTTP_VARS['borrow_ind'] != $status_type_r['borrow_ind'] && $HTTP_VARS['borrow_ind'] != 'Y' && $HTTP_VARS['borrow_ind'] != 'N' && $HTTP_VARS['borrow_ind'] != 'B' && is_exists_borrowed_items_for_status_type($HTTP_VARS['s_status_type']))
				{
					echo format_error_block(
								array('error'=>'Status type not updated',
									'detail'=>'Cannot update borrow_ind to \''.$HTTP_VARS['borrow_ind'].'\', as '.$status_type_r['description'].' item instance(s) exist, which have borrowed item(s) attached.'));
				}
				else
				{
					if(update_s_status_type($HTTP_VARS['s_status_type'], $HTTP_VARS['description'], $HTTP_VARS['img'], 
								$HTTP_VARS['insert_ind'], $HTTP_VARS['update_ind'], $HTTP_VARS['delete_ind'], $HTTP_VARS['change_owner_ind'],
								$HTTP_VARS['min_display_user_type'], $HTTP_VARS['min_create_user_type'],
								$HTTP_VARS['new_owner_instance_ind'], $HTTP_VARS['new_not_owner_instance_ind'],
								$HTTP_VARS['borrow_ind'], $HTTP_VARS['status_comment_ind'], $HTTP_VARS['default_ind'],
								$HTTP_VARS['closed_ind']))
					{
						echo "<div class=\"success\">Status type updated</a>";
					}
					else
					{
						echo format_error_block(array('error'=>'Status type not updated','detail'=>mysql_error()));
					}
				}
			}
			else
			{
				echo format_error_block('Invalid status type specified');
			}
		}
		else if($HTTP_VARS['op'] == 'insert')
		{
			$HTTP_VARS['s_status_type'] = strtoupper(substr($HTTP_VARS['s_status_type'],0,1));
			
			if(strlen($HTTP_VARS['s_status_type'])>0 && !is_valid_s_status_type($HTTP_VARS['s_status_type']))
			{
				if(insert_s_status_type($HTTP_VARS['s_status_type'], $HTTP_VARS['description'], $HTTP_VARS['img'], 
								$HTTP_VARS['insert_ind'], $HTTP_VARS['update_ind'], $HTTP_VARS['delete_ind'], $HTTP_VARS['change_owner_ind'],
								$HTTP_VARS['min_display_user_type'], $HTTP_VARS['min_create_user_type'],
								$HTTP_VARS['new_owner_instance_ind'], $HTTP_VARS['new_not_owner_instance_ind'],
								$HTTP_VARS['borrow_ind'], $HTTP_VARS['status_comment_ind'], $HTTP_VARS['default_ind']))
				{
					display_s_status_type_chooser($PHP_SELF, $HTTP_VARS['type'], $HTTP_VARS['s_status_type']);
					echo("\n<h3>Insert Status type</h3>");
					echo "<div class=\"success\">Status type inserted.</a>";
				}
				else
				{
					display_s_status_type_chooser($PHP_SELF, $HTTP_VARS['type'], $HTTP_VARS['s_status_type']);
					echo format_error_block(array('error'=>'Status type ('.$HTTP_VARS['s_status_type'].') not inserted','detail'=>mysql_error()));
				}
			}
			else
			{
				if(strlen($HTTP_VARS['s_status_type'])>0)
				{
					// We are reloading the New form, so pass message down to be displayed there.
					$error_message = format_error_block('Status type exists');
					$HTTP_VARS['op'] = 'new';
				}
				else
				{
					echo format_error_block('Invalid status type specified');
				}
			}
		}
		
		// Allows reset of $HTTP_VARS['op'] to 'new' by insert process
		if(strlen($HTTP_VARS['op'])==0 || $HTTP_VARS['op'] == 'new' || $HTTP_VARS['op'] == 'edit')
		{
			// Include validation javascript here.
			echo get_validation_javascript();

			display_s_status_type_chooser($PHP_SELF, $HTTP_VARS['type'], $HTTP_VARS['s_status_type']);
				
			if($HTTP_VARS['op'] == 'new')
			{
				echo("\n<br><h3>New Status type</h3>");
				if(strlen($error_message)>0)
					echo($error_message);

				echo("\n<table cellspacing=2 border=0>");
				echo("\n<form name=\"s_status_type\" action=\"$PHP_SELF\" method=\"post\">");
	
				echo("\n<input type=\"hidden\" name=\"op\" value=\"insert\">");
				echo("\n<input type=\"hidden\" name=\"type\" value=\"".$HTTP_VARS['type']."\">");
				
				display_edit_form(NULL, $HTTP_VARS);
				
				if($CONFIG_VARS['widgets.show_prompt_compulsory_ind']!==FALSE)
				{
					echo("\n<tr><td align=left nowrap>".
					format_help_block(array(array('img'=>'compulsory.gif', 'text'=>$LANG_VARS['compulsory_field']))).
					"</td><td>&nbsp;</td></tr>");
				}
				
				echo("\n<tr><td colspan=\"2\" align=center>");
				if($CONFIG_VARS['widgets.enable_javascript_validation']!==FALSE)
					echo("\n<input type=button value=\"Insert\" onclick=\"if(!checkForm(this.form)){return false;}else{this.form.submit();}\">");
				else
					echo("\n<input type=button value=\"Insert\" onclick=\"this.form.submit();\">");
				echo("\n</td></tr>");

				echo("\n</form>");
				echo("\n</table>");
			}
			else if($HTTP_VARS['op'] == 'edit' && is_valid_s_status_type($HTTP_VARS['s_status_type']))
			{
				echo("\n<br><h3>Edit Status type</h3>");

				$status_type_r = fetch_status_type_r($HTTP_VARS['s_status_type']);
				if($status_type_r!==FALSE)
				{
					echo("\n<table cellspacing=2 border=0>");
					echo("\n<form name=\"s_status_type\" action=\"$PHP_SELF\" method=\"post\">");
	
					echo("\n<input type=\"hidden\" name=\"op\" value=\"update\">");
					echo("\n<input type=\"hidden\" name=\"type\" value=\"".$HTTP_VARS['type']."\">");

					display_edit_form($status_type_r);
					
					if($CONFIG_VARS['widgets.show_prompt_compulsory_ind']!==FALSE)
					{
						echo("\n<tr><td align=left nowrap>".
							format_help_block(array(array('img'=>'compulsory.gif', 'text'=>$LANG_VARS['compulsory_field']))).
							"</td><td>&nbsp;</td></tr>");
					}
					
					echo("\n<tr><td colspan=\"2\" align=center>");
					
					if($CONFIG_VARS['widgets.enable_javascript_validation']!==FALSE)
					{
						echo("\n<input type=button value=\"Update\" onclick=\"if(!checkForm(this.form)){return false;}else{this.form.submit();}\">");
						echo("\n&nbsp;<input type=button value=\"Delete\" onclick=\"if(!checkForm(this.form)){return false;}else{this.form['op'].value='delete'; this.form.submit();}\">");
					}
					else
					{
						echo("\n<input type=button value=\"Update\" onclick=\"this.form.submit();\">");
						echo("\n&nbsp;<input type=button value=\"Delete\" onclick=\"this.form['op'].value='delete'; this.form.submit();\">");
					}
					echo("\n</td></tr>");

					echo("\n</form>");
					echo("\n</table>");
				}
				else
				{
					echo format_error_block('Status type ('.$HTTP_VARS['s_status_type'].') not found');
				}
			}
		}
	}//if(is_user_admin($HTTP_SESSION_VARS['user_id'], $HTTP_SESSION_VARS['user_type']))
}//if(is_opendb_valid_session())
?>