File: item_add.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 (653 lines) | stat: -rw-r--r-- 24,339 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
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
<?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.
*/

// This must be first - includes config.php
require_once("./include/begin.inc.php");

include_once("./include/language.php");
include_once("./include/theme.php");

include_once("./functions/database.php");
include_once("./functions/auth.php");
include_once("./functions/logging.php");
include_once("./functions/item_type.php");
include_once("./functions/parseutils.php");
include_once("./functions/widgets.php");
include_once("./functions/utils.php");
include_once("./functions/item.php");
include_once("./functions/user.php");
include_once("./functions/status_type.php");
include_once("./functions/site_plugin.php");

function display_site_plugin_blocks($HTTP_VARS, $item_r=NULL)
{
	global $CONFIG_VARS;
	global $LANG_VARS;

	$div_interface = $CONFIG_VARS['item_input.item_add_site_div_interface'];

	// At least one input field provided for user input.
	$input_field_provided=FALSE;

	$results = fetch_site_plugin_rs($HTTP_VARS['s_item_type']);
	if($results)
	{
	    echo get_popup_javascript();

		// Yes we have one.
		$input_field_provided=TRUE;

	    if($div_interface!==FALSE)
	    {
		    echo('<script language="JavaScript1.3">
			var panes = new Array();
			function setupPanes(containerId, defaultTabId)
			{
				var maxHeight = 0; var maxWidth = 0;
				var container = document.getElementById(containerId);
				var paneList = container.getElementsByTagName("div");
				for (var i=0; i < paneList.length; i++ )
				{
					var pane = paneList[i];

					if (pane.nodeType != 1) continue;
					if (pane.offsetHeight > maxHeight) maxHeight = pane.offsetHeight;
					if (pane.offsetWidth  > maxWidth ) maxWidth  = pane.offsetWidth;

					panes[pane.id] = pane;

					pane.style.display = "none";
				}
				container.style.height = maxHeight + "px";
				container.style.width  = maxWidth + "px";

			    showPane(containerId, defaultTabId);
			}

			function showPane(containerId, paneId)
			{
				var container = document.getElementById(containerId);
				var paneList = container.getElementsByTagName("div");
				for (var i=0; i < paneList.length; i++ )
				{
				    var pane = paneList[i];
					pane.style.display = "none"
				}

				for (var i=0; i < paneList.length; i++ )
				{
					var pane = paneList[i];
					if (pane.id == paneId)
					    pane.style.display = "block";
				}

				return true;
			}
			</script>');

	        $linkblock = '<table border=0 cellspacing=5 cellpadding=0><form>';
	        $defaultsite = NULL;
		}

        $siteblock = '';
		$count = 0;

		while($site_plugin_r = mysql_fetch_array($results, MYSQL_ASSOC))
		{
			if(is_exists_site_plugin($site_plugin_r['site_type']))
			{
				// Do not get s_item_type records if s_item_type already defined.  We would not be inside
				// unless this site_type was compatible with the specified s_item_type...
				if(strlen($HTTP_VARS['s_item_type'])==0)
				{
					$sitresults = fetch_site_item_type_rs($site_plugin_r['site_type']);
				}

				if(strlen($HTTP_VARS['s_item_type'])>0 || $sitresults)
				{
				    $hrefblock = "<a href=\"javascript:popup('external.php?url=".urlencode($site_plugin_r['external_url'])."&title=".urlencode($site_plugin_r['title'])."', 800, 600);\">";
					if(strlen($site_plugin_r['image'])>0)
					{
						$hrefblock .= "<img src=\"./site/images/".$site_plugin_r['image']."\" title=\"".strip_tags($site_plugin_r['description'])."\" alt=\"".strip_tags($site_plugin_r['description'])."\" border=0>";
					}
					$hrefblock .= "</a>";

				    if($div_interface!==FALSE)
	    			{
				    	if($count == 0)
							$linkblock .= "\n<tr>";

                        $linkblock .= "<td>".
                        			"\n<table cellspacing=0 cellpadding=0><tr><td><input type=radio name=\"site_plugin\" onClick=\"return showPane('site-container', '".$site_plugin_r['site_type']."');\" ".($defaultsite==NULL?" CHECKED":"")."></td>".
                                    "<td>".$hrefblock."</td></tr></table>".
									"</td>";

						if($defaultsite==NULL)
			    			$defaultsite = $site_plugin_r['site_type'];

                        $count++;
						if($count == 4)
						{
							$linkblock .= "\n</tr>";
							$count = 0;
						}

						$siteblock .= "\n<div id=\"".$site_plugin_r['site_type']."\" style=\"position:relative\">";
					}
					else
					{
					    if($count == 0)
							$siteblock .= "\n<tr>";

                        $count++;
                        $siteblock .= "<td>";
					}

					$siteblock .= "<table border=0><tr><td>";
					if($div_interface!==FALSE)
	    			{
						$siteblock .= "<h3>".$site_plugin_r['title']."</h3>";
					}
					else
					{
					    $siteblock .= $hrefblock ."</td><td>";
					}
					$siteblock .= "<font class=\"colortext\">".$site_plugin_r['description']."</font></td></tr>";
					$siteblock .= "<form action=\"item_input.php\" method=\"GET\">";

					$siteblock .= "\n<input type=hidden name=\"op\" value=\"site-search\">";
					$siteblock .= "\n<input type=hidden name=\"site_type\" value=\"".$site_plugin_r['site_type']."\">";

					// Let the item_input script validate the owner_id, just pass it through for now.
					if(strlen($HTTP_VARS['owner_id'])>0)
					{
						$siteblock .= "\n<input type=hidden name=\"owner_id\" value=\"".$HTTP_VARS['owner_id']."\">";
					}

					$siteblock .= "\n<input type=hidden name=\"s_status_type\" value=\"".$HTTP_VARS['s_status_type']."\">";
					$siteblock .= "\n<input type=hidden name=\"listing_link\" value=\"".$HTTP_VARS['listing_link']."\">";
					$siteblock .= "\n<input type=hidden name=\"item_id\" value=\"".$HTTP_VARS['item_id']."\">";
					$siteblock .= "\n<input type=hidden name=\"instance_no\" value=\"".$HTTP_VARS['instance_no']."\">";
					$siteblock .= "\n<input type=hidden name=\"parent_id\" value=\"".$HTTP_VARS['parent_id']."\">";
					$siteblock .= "\n<input type=hidden name=\"parent_instance_no\" value=\"".$HTTP_VARS['parent_instance_no']."\">";
					$siteblock .= "</td></tr></table>";

					$siteblock .= "<table border=0>";

					$inrow=FALSE;
					$sifresults = fetch_site_plugin_input_field_rs($site_plugin_r['site_type']);
					if($sifresults)
					{
						while($input_field_r = mysql_fetch_array($sifresults, MYSQL_ASSOC))
						{
							// Only if we are are refreshing an item.
							if(is_not_empty_array($item_r))
							{
								$value = expand_item_title_mask($item_r, $input_field_r['refresh_mask']);
							}
							else if($input_field_r['field_type'] != 'hidden')
							{
								// a kludge to support feature request #816240 - failure when adding an item should return previous search
								$mask_elements = parse_field_mask($input_field_r['refresh_mask']);
								$value = ifempty(expand_field_mask($HTTP_VARS, $input_field_r['refresh_mask'], $mask_elements),
												$input_field_r['default_value']);
							}
							else
							{
								$value = $input_field_r['default_value'];
							}

							// The format of the field is defined here.  Currently only 'hidden'
							// is supported, otherwise the default text field will be displayed.
							switch($input_field_r['field_type'])
							{
								case 'hidden':
									$siteblock .= "\n<input type=hidden name=\"".$input_field_r['field']."\" value=\"".htmlspecialchars($value)."\">\n";
									break;

								default:

									$field = "<input type=text name=\"".$input_field_r['field']."\" value=\"".htmlspecialchars($value)."\">";

									// If no prompt defined, don't try to display it!
									if(strlen($input_field_r['prompt'])>0)
									{
										if($inrow)
										{
											$siteblock .= "\n</td></tr>";
											$inrow = FALSE;
										}

										$siteblock .= "\n<tr><td align=right class=\"prompt\">".$input_field_r['prompt'].":&nbsp;</td>";

										$siteblock .= "\n<td class=\"data\" nowrap>";
										$siteblock .= $field;

										$inrow = TRUE;
									}
									else
									{
										if(!$inrow)
										{
											$siteblock .= "\n<tr><td class=\"data\">";
											$newrow = TRUE;
										}
										$siteblock .= $field;
									}
							}
						}//while

						if($inrow)
						{
							$siteblock .= "</td></tr>";
						}
						mysql_free_result($sifresults);
					}//if($sifresults)

					if(is_exists_item_type($HTTP_VARS['s_item_type']))
					{
						$siteblock .= "\n<input type=hidden name=\"s_item_type\" value=\"".$HTTP_VARS['s_item_type']."\">";
					}
					else
					{
					    $siteblock .= "\n<tr><td align=right class=\"prompt\">".$LANG_VARS['item_type'].":&nbsp;</td>";
						$siteblock .= "<td class=\"data\">".single_select("s_item_type", $sitresults, "%value% - %display%", NULL, NULL)."</td></tr>";
					}
					$siteblock .= "<tr><td><input type=submit value=\"".replace_lang_var('site', $site_plugin_r['title'], $LANG_VARS['site_search'])."\">";
					$siteblock .= "\n</td></tr>";

					$siteblock .= "</form></table>";

					if($div_interface!==FALSE)
	    			{
						$siteblock .= "\n</div>\n";
     				}
     				else
	    			{
	    			    $siteblock .= "</td>";
						if($count == 2)
						{
							$siteblock .= "\n</tr>";
							$count = 0;
						}
				    }
				}//if(strlen($HTTP_VARS['s_item_type'])>0 || $sitresults)
			}//if(is_exists_site_plugin($site_plugin_r['site_type']))
		}//while($site_plugin_r = mysql_fetch_array($results, MYSQL_ASSOC))
		mysql_free_result($results);

        if($div_interface!==FALSE)
		{
		    $linkblock .= "</form></table>";
        	echo("\n<div style=\"position:relative\">");
	    	echo $linkblock;
    		echo("\n</div>");

    		echo("\n<div id=\"site-container\" style=\"position:relative\">");
    		echo $siteblock;
        	echo("\n</div>");

	    	echo("
    			<script>
				function initSetupPanes()
				{
					setupPanes(\"site-container\", \"$defaultsite\");
				    return true;
				}
				window.document.onLoad = initSetupPanes();
				</script>");
		}
		else
		{
		    echo "<table border=0>".$siteblock."</table>";
		}
	}//if($results)

	if($item_r == NULL)
	{
		$input_field_provided = TRUE;

		if($div_interface!==FALSE)
		{
			echo("\n<div style=\"position:relative\">");
		}

		echo "<br><table border=0>";
		echo "<form action=\"item_input.php\" method=\"GET\">";

		echo "\n<tr><td colspan=2>";
        if(file_exists("./site/images/manual.gif"))
			$imgsrc .= "\n<img src=\"./site/images/manual.gif\" title=\"".$LANG_VARS['manual_entry']."\" alt=\"".$LANG_VARS['manual_entry']."\" valign=absmiddle align=absmiddle border=0>";
		else
			$imgsrc .= _theme_image('icon.gif', NULL, NULL, 'absmiddle');

        echo "<h3>$imgsrc ".$LANG_VARS['manual_entry']."</h3></td></tr>";

		echo "\n<input type=hidden name=op value=\"new\">";

		// Let the item_input script validate the owner_id, just pass it through for now.
		if(strlen($HTTP_VARS['owner_id'])>0)
		{
			echo "\n<input type=hidden name=\"owner_id\" value=\"".$HTTP_VARS['owner_id']."\">";
		}
		echo "\n<input type=hidden name=\"s_status_type\" value=\"".$HTTP_VARS['s_status_type']."\">";
		echo "\n<input type=hidden name=\"listing_link\" value=\"".$HTTP_VARS['listing_link']."\">";
		echo "\n<input type=hidden name=\"parent_id\" value=\"".$HTTP_VARS['parent_id']."\">";
		echo "\n<input type=hidden name=\"parent_instance_no\" value=\"".$HTTP_VARS['parent_instance_no']."\">";

		if(is_exists_item_type($HTTP_VARS['s_item_type']))
		{
			echo "\n<input type=hidden name=\"s_item_type\" value=\"".$HTTP_VARS['s_item_type']."\">";
		}
		else
		{
		    echo("\n<tr><td align=right class=\"prompt\">".$LANG_VARS['item_type'].":&nbsp;</td>");
			$results = fetch_item_type_rs(TRUE);
			if($results)
			{
				echo("<td class=\"data\">".single_select("s_item_type", $results, "%value% - %display%", NULL, NULL)."</td>");
			}
		}
		echo "<tr><td><input type=submit value=\"".$LANG_VARS['add_new_item']."\"></td></tr>";
		echo "\n</form></table>";

		if($div_interface!==FALSE)
		{
			echo("\n</div>");
		}
	}

	if($input_field_provided)
		return TRUE;
	else
		return FALSE;
}

if($CONFIG_VARS['site.enable']!==FALSE)
{
	session_start();
	if (is_opendb_valid_session())
	{
		if(is_user_allowed_to_own($HTTP_SESSION_VARS['user_id'], $HTTP_SESSION_VARS['user_type']))
		{
			if(is_numeric($HTTP_VARS['parent_id']) && is_numeric($HTTP_VARS['parent_instance_no']))
			{
				$parent_item_r = fetch_item_instance_r($HTTP_VARS['parent_id'], $HTTP_VARS['parent_instance_no']);
			}
			
			// At least the item_id specified, now we check if item or item_instance.
			if(is_numeric($HTTP_VARS['item_id']))
			{
				if(is_not_empty_array($parent_item_r))
					$item_r = fetch_child_item_r($HTTP_VARS['item_id']);
				else if(is_numeric($HTTP_VARS['instance_no']))
					$item_r = fetch_item_instance_r($HTTP_VARS['item_id'], $HTTP_VARS['instance_no']);
			}
			
			// New item.
			if(!is_array($parent_item_r) && !is_array($item_r))
			{
				if(!is_numeric($HTTP_VARS['item_id']))
				{
					// if we changed owner_id's then must reset s_status_type to NULL
					if($HTTP_VARS['confirmed'] === 'false')
					{
                        $HTTP_VARS['s_status_type'] = NULL;
					}

                    if(strlen($HTTP_VARS['s_status_type'])==0)
					{
                        // if more than one row, then will display a LOV below.
                   		$status_type_results = fetch_newitem_status_type_rs($HTTP_VARS['owner_id']);
                       	if($status_type_results)
						{
							if(mysql_num_rows($status_type_results)==1)
							{
								$status_type_r = array_merge(mysql_fetch_array($status_type_results, MYSQL_ASSOC));
								mysql_free_result($status_type_results);
								$status_type_results = NULL;

                           	    $HTTP_VARS['s_status_type'] = $status_type_r['value'];
							}
						}
					}

					if($HTTP_VARS['confirmed'] === 'false' || strlen($HTTP_VARS['s_status_type'])==0 || strlen($HTTP_VARS['owner_id'])==0)
					{
						$page_title = $LANG_VARS['add_item'];
						echo _theme_header($page_title);

						if(is_exists_item_type($HTTP_VARS['s_item_type']))
							echo("<h2>".$page_title." ".get_item_image($HTTP_VARS['s_item_type'])."</h2>");
						else
							echo("<h2>".$page_title."</h2>");
							
						echo("\n<table border=0 frameborder=0 cellspacing=1>".
							"<form action=\"$PHP_SELF\" method=\"POST\">".
							get_url_fields($HTTP_VARS, array('confirmed'=>'true')));

                        $HTTP_VARS['owner_id'] = ifempty($HTTP_VARS['owner_id'], $HTTP_SESSION_VARS['user_id']);
						echo(
							format_field(
								$LANG_VARS['owner'],
								NULL, // prompt_mask
								"\n<select name=\"owner_id\" onChange=\"this.form['confirmed'].value='false'; this.form.submit();\">".
								custom_select(
									'owner_id',
									fetch_user_rs(get_owner_user_types_r()),
									'%fullname% (%user_id%)',
									'NA',
									$HTTP_VARS['owner_id'],
									'user_id').
								"\n</select>"));

						// if s_status_type is empty, we should just reexecuted the fetch in case the
						// owner_id is different or something. Its a minor overhead to rexecute
						// fetch_newitem_status_type_rs, but its simpler this way.
						if(strlen($HTTP_VARS['s_status_type'])==0 && strlen($HTTP_VARS['owner_id'])>0)
						{
                        	$status_type_results = fetch_newitem_status_type_rs($HTTP_VARS['owner_id']);
						}

						if($status_type_results)
						{
							// Only include Status type restriction, if more than once status type.
							if(mysql_num_rows($status_type_results)>1)
							{
								echo format_field(
									$LANG_VARS['s_status_type'],
									NULL,
									radio_grid('s_status_type',
										$status_type_results,
										'%img%', // mask
										'3', // columns
										'', // border
										NULL)); // value
							}
						}

						echo("<tr><td colspan=2 align=left><br><input type=\"submit\" value=\"".$LANG_VARS['add_item']."\"></td></tr>");
						echo("</form></table>");
					}//if($show_owner_field || $show_status_type_field)
					else
					{
						$status_type_r = fetch_status_type_r($HTTP_VARS['s_status_type']);
						if(is_array($status_type_r))
						{
							if($HTTP_VARS['owner_id'] != $HTTP_SESSION_VARS['user_id'])
								$page_title = replace_lang_vars(array('s_status_type_desc'=>$status_type_r['description'], 'user_id'=>$HTTP_VARS['owner_id'], 'fullname'=>fetch_user_name($HTTP_VARS['owner_id'])), $LANG_VARS['add_s_status_type_item_for_name']);
							else
								$page_title = replace_lang_var('s_status_type_desc', $status_type_r['description'], $LANG_VARS['add_s_status_type_item']);
						}
						else 
						{
							if($HTTP_VARS['owner_id'] != $HTTP_SESSION_VARS['user_id'])
								$page_title = replace_lang_vars(array('user_id'=>$HTTP_VARS['owner_id'], 'fullname'=>fetch_user_name($HTTP_VARS['owner_id'])), $LANG_VARS['add_item_for_name']);
							else
								$page_title = $LANG_VARS['add_item'];
						}
						echo _theme_header($page_title);

						if(is_exists_item_type($HTTP_VARS['s_item_type']))
							echo("<h2>".$page_title." ".get_item_image($HTTP_VARS['s_item_type'])."</h2>");
						else
							echo("<h2>".$page_title."</h2>");
						
						if( is_user_allowed_to_own($HTTP_VARS['owner_id']) && (
								$HTTP_VARS['owner_id'] == $HTTP_SESSION_VARS['user_id'] || 
								is_user_admin($HTTP_SESSION_VARS['user_id'], $HTTP_SESSION_VARS['user_type'])) )
						{	
							// If status_type for this item is closed, we must generate an error, as this is illegal.	
							if(!is_array($status_type_r) || $status_type_r['closed_ind'] != 'Y')
							{	
								if(!is_array($status_type_r) || $status_type_r['insert_ind'] == 'Y')
								{
									if(!is_array($status_type_r) || strlen($status_type_r['min_create_user_type'])==0 || in_array($status_type_r['min_create_user_type'], get_min_user_type_r($HTTP_SESSION_VARS['user_type'])))
									{
										// Do display choices dialog if refreshing an item!
										echo("<div class=\"colortext\">");
										echo($LANG_VARS['item_add_intro']."<br><br>");
										$plugin_display = display_site_plugin_blocks($HTTP_VARS, $item_r);
										echo("</div>");
										
										if(!$plugin_display)
											echo("<div class=\"error\">".$LANG_VARS['operation_not_available']."</div>");
									}
									else //if(in_array($status_type_r['min_create_user_type'], get_min_user_type_r($HTTP_SESSION_VARS['user_type'])))
									{
										echo("<div class=\"error\">".
											replace_lang_vars(array('usertype'=>get_usertype_description($HTTP_SESSION_VARS['user_type']),'s_status_type_desc'=>$status_type_r['description']),$LANG_VARS['s_status_type_create_access_disabled_for_usertype']).
											"</div>");
									}
								}
								else//if($status_type_r['insert_ind'] == 'Y')
								{
									echo("<div class=\"error\">".
											replace_lang_var('s_status_type_desc', $status_type_r['description'], $LANG_VARS['operation_not_avail_s_status_type']).
											"</div>");
								}
							}
							else // if($status_type_r['closed_ind'] != 'Y')
							{
								echo("<div class=\"error\">".
									replace_lang_var('s_status_type_desc', $status_type_r['description'], $LANG_VARS['s_status_type_not_supported']).
									"</div>");
							}
						}
						else
						{
							echo("<div class=\"error\">".
									$LANG_VARS['operation_not_available'].
									"</div>");
						}
					}
				}
				else //if(!is_numeric($HTTP_VARS['item_id']))
				{
					echo _theme_header($lang_var['item_not_found']);
					echo("<div class=\"error\">".$lang_var['item_not_found']."</div>");
				}
			}
			else if(is_not_empty_array($parent_item_r)) // Child item edit/add
			{
				$page_title = replace_lang_vars(array('display_title'=>expand_item_title_mask($parent_item_r, $CONFIG_VARS['item_display.title_display_mask'])), $LANG_VARS['edit_title']);
				echo _theme_header($page_title);
				echo("\n<h2>".$page_title." ".get_item_image($parent_item_r['s_item_type'])."</h2>");
			
				if(is_not_empty_array($item_r)) // Child item refresh
				{
					echo("\n<h3>".replace_lang_var("title", $item_r['title'], $LANG_VARS['refresh_linked_title'])." ".get_item_image($item_r['s_item_type'], NULL, TRUE)."</h3>\n");
				}
				else // Add new child item.
				{
					// Enforce the $s_item_type in this case.
					if($CONFIG_VARS['item_input.link_same_type_only']===TRUE)
					{
						$HTTP_VARS['s_item_type'] = $parent_item_r['s_item_type'];
						echo ("<h3>".$LANG_VARS['add_linked_item']." ".get_item_image($parent_item_r['s_item_type'])."</h3>\n");
					}
					else
					{
						echo ("<h3>".$LANG_VARS['add_linked_item']."</h3>\n");
					}
				}
				
				echo("<div class=\"colortext\">");
				$plugin_display = display_site_plugin_blocks($HTTP_VARS, $item_r);
				echo("</div>");
				if(!$plugin_display)
					echo("<div class=\"error\">".$LANG_VARS['operation_not_available']."</div>");
			}
			else if(is_not_empty_array($item_r)) // Parent item refresh
			{
				$HTTP_VARS['s_item_type'] = $item_r['s_item_type'];
			
				$page_title = replace_lang_vars(array('display_title'=>expand_item_title_mask($item_r, $CONFIG_VARS['item_display.title_display_mask'])), $LANG_VARS['refresh_title']);
				echo _theme_header($page_title);
				echo("<h2>".$page_title." ".get_item_image($item_r['s_item_type'])."</h2>\n");
				
				echo("<div class=\"colortext\">");
				$plugin_display = display_site_plugin_blocks($HTTP_VARS, $item_r);
				echo("</div>");
				if(!$plugin_display)
					echo("<div class=\"error\">".$LANG_VARS['operation_not_available']."</div>");
			}
	
			// Now the links...
			if($HTTP_VARS['item_link'] === 'y' && is_exists_item_instance($HTTP_VARS['item_id'],$HTTP_VARS['instance_no']))
			{
				$footer_links_r[] = array(url=>"item_display.php?item_id=".$HTTP_VARS['item_id']."&instance_no=".$HTTP_VARS['instance_no']."&listing_link=".$HTTP_VARS['listing_link'],text=>$LANG_VARS['back_to_item']);
			}
	
			if(is_array($parent_item_r))
			{
				$footer_links_r[] = array(url=>"item_display.php?item_id=".$HTTP_VARS['parent_id']."&instance_no=".$HTTP_VARS['parent_instance_no']."&listing_link=".$HTTP_VARS['listing_link'],text=>$LANG_VARS['back_to_parent']);
			}
			
			// Include a Back to Listing link.
			if($HTTP_VARS['listing_link'] === 'y' && is_array($HTTP_SESSION_VARS['listing_url_vars']))
			{
				$footer_links_r[] = array(url=>"listings.php?".get_url_string($HTTP_SESSION_VARS['listing_url_vars']),text=>$LANG_VARS['back_to_listing']);
			}
		}//no guests or borrowers allowed!
		else
		{				 
			echo _theme_header($LANG_VARS['not_authorized_to_page']);
			echo _theme_error($LANG_VARS['not_authorized_to_page']);
		}
		
		echo format_footer_links($footer_links_r);
		echo _theme_footer();
	}
	else
	{
		// invalid login, so login instead.
		include("./login.php");
	}
}//if($CONFIG_VARS['site.enable']!==FALSE)
else
{
	echo _theme_header($LANG_VARS['site_is_disabled'], FALSE);
	echo _theme_error($LANG_VARS['site_is_disabled']);
	echo _theme_footer();
}

// Cleanup after begin.inc.php
require_once("./include/end.inc.php");
?>