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 (100 lines) | stat: -rw-r--r-- 3,554 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
<?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.
*/
function check_if_installed()
{
	global $CONFIG_VARS;

	return check_table($CONFIG_VARS['session_handler.session_table'],
						FALSE,
						'session_handler');
}

if($CONFIG_VARS['patch.enable']===TRUE)
{
	if($HTTP_VARS['op'] == "menu")
	{
		if($CONFIG_VARS['session_handler.enable'] === TRUE)
		{
			// We only want to run the check_table query once!
			$table_installed = check_if_installed();
	
			echo("<div align=\"center\">");
			echo("<form action=\"$PHP_SELF\" method=\"get\" target=\"main\">");
			print_button("add", "Add ".strtoupper($CONFIG_VARS['session_handler.session_table'])." Table", $table_installed);
			echo("&nbsp;");
			print_button("remove", "Remove ".strtoupper($CONFIG_VARS['session_handler.session_table'])." Table", !$table_installed);
			echo("<br>");
			echo("<input type=\"hidden\" name=\"op\" value=\"result\">");
			echo("<input type=\"hidden\" name=\"from\" value=\"".$HTTP_VARS['from']."\">");
			echo("</form>");
			echo("</div>");
		}
		else
		{
			echo("<div class=\"error\">The <b>\$CONFIG_VARS['session_handler.enable']</b> variable must be TRUE.</div>");
		}			
	}
	else
	{
		if($CONFIG_VARS['session_handler.enable'] === TRUE)
		{
			// We only want to run the check_table query once!
			$table_installed = check_if_installed();
			
			if(isset($HTTP_VARS['add']))
			{
				if(!$table_installed)
				{
					$sql_command =
						"CREATE TABLE ".$CONFIG_VARS['session_handler.session_table'].
						"\n(".
						"\n\tSID char(32) NOT NULL,".
						"\n\texpiration INT NOT NULL,".
			  			"\n\tvalue TEXT NOT NULL,".
						"\n\tPRIMARY KEY(SID)".
						"\n)";

					echo("<div class=\"code\"><pre>$sql_command;</pre></div>\n");
					if(run_opendb_query($sql_command, FALSE, 'session_handler'))
						echo("<div class=\"upgrade_success\">SQL query evaluated successfully.</div>\n");
					else
						echo("<div class=\"upgrade_failure\">SQL query evaluation failed. (".mysql_error().")</div>\n");
				}
				else
					echo("<div class=\"upgrade_warning\">Table ".$CONFIG_VARS['session_handler.session_table']." exists.</div>\n");
			}
			else if(isset($HTTP_VARS['remove']))
			{
				if($table_installed)
				{
					$sql_command = "DROP TABLE ".$CONFIG_VARS['session_handler.session_table'];
				
					echo("<div class=\"code\"><pre>$sql_command;</pre></div>\n");
					if(run_opendb_query($sql_command, FALSE, 'session_handler'))
						echo("<div class=\"upgrade_success\">SQL query evaluated successfully.</div>\n");
					else
						echo("<div class=\"upgrade_failure\">SQL query evaluation failed. (".mysql_error().")</div>\n");
				}
				else
					echo("<div class=\"upgrade_warning\">Table ".$CONFIG_VARS['session_handler.session_table']." not found.</div>\n");
			}
		}//if($CONFIG_VARS['session_handler.enable'] === TRUE)		
	}
}
?>