File: index.php

package info (click to toggle)
opendb 0.62p9-3
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 3,544 kB
  • ctags: 3,560
  • sloc: php: 26,575; sql: 1,982; sh: 250; makefile: 54
file content (212 lines) | stat: -rw-r--r-- 6,443 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
<?php
/* 	OpenDb - Open Lending Database Project
	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.
*/

//
// Note: Does not support DIFF for $lang_var['site']['?????'] = array(....) 
//
include_once("./functions/widgets.php");
include_once("./functions/http.php");

function get_lang_vars_from_file($filename)
{
	include($filename);
	
	if(is_not_empty_array($LANG_VARS))
		return $LANG_VARS;
	else if(is_not_empty_array($lang_var))
		return $lang_var;
	else
		return NULL;
}

function display_changes($prefix, $diff_array)
{
	if(is_array($diff_array))
	{
		reset($diff_array);
		while(list($key,$value) = each($diff_array))
		{
			if(is_array($value))
				display_changes($prefix."['$key']", $value);
			else
			{
				echo($prefix."['$key']");
				echo(" = '".htmlspecialchars($value)."';\n");
			}
		}
	}
}
	
session_start();
if(is_opendb_valid_session())
{ 
	if(is_file_upload_enabled())
	{
		if (is_user_admin($HTTP_SESSION_VARS['user_id'], $HTTP_SESSION_VARS['user_type']))
		{
			if($HTTP_VARS['op'] == 'diff')
			{
				echo("<div class=\"footer\">[<a href=\"$PHP_SELF?type=$ADMIN_TYPE\">New Diff</a>]</div>");
			
				if(is_uploaded_file($HTTP_POST_FILES['old_file']['tmp_name']))
				{
					$old_lang_vars = get_lang_vars_from_file($HTTP_POST_FILES['old_file']['tmp_name']);
					if(is_uploaded_file($HTTP_POST_FILES['new_file']['tmp_name']))
						$new_lang_vars = get_lang_vars_from_file($HTTP_POST_FILES['new_file']['tmp_name']);
					else
						$new_lang_vars = get_lang_vars_from_file("lang/".$_OPENDB_LANGUAGE.".inc.php");
					
					if(is_array($old_lang_vars) && is_array($new_lang_vars))
					{
						$diffs['added'] = NULL;
						$diffs['updated'] = NULL;
						$diffs['deleted'] = NULL;
			
						// TODO: Support complete nesting diff checking
						while(list($key,$var) = each($old_lang_vars))
						{
							if(isset($new_lang_vars[$key])) // found
							{
								// nested array.
								if(is_array($var))
								{
									if(is_array($new_lang_vars[$key]))
									{
										// Compare the indexes.
										while(list($key2,$value) = each($old_lang_vars[$key]))
										{
											if(isset($new_lang_vars[$key][$key2]))
											{
												// We are not checking nested arrays from this point!!!
												// Generally the $lang_var['site'], is the only 
												// structure that goes to this depth anyway.
												if(!is_array($value))
												{
													if($value != $new_lang_vars[$key][$key2])
														$diffs['updated'][$key][$key2] = $new_lang_vars[$key][$key2];	
												}
												//else ignore as too much nesting.
											}
											else
											{
												$diffs['deleted'][$key][$key2] = $old_lang_vars[$key][$key2];
											}
										}
								
										while(list($key2,$value) = each($new_lang_vars[$key]))
										{
											if(!isset($old_lang_vars[$key][$key2]))
											{
												$diffs['added'][$key][$key2] = $new_lang_vars[$key][$key2];
											}
										}
									}
									else // No longer in new file, so it is deleted.
										$diffs['deleted'][$key] = $var;
								}
								else //normal variable.
								{
									if($var != $new_lang_vars[$key])
										$diffs['updated'][$key] = $new_lang_vars[$key];	
								}
							}
							else
							{
								$diffs['deleted'][$key] = $var;
							}
						}
			
						while(list($key,$var) = each($new_lang_vars))
						{
							if(!isset($old_lang_vars[$key]))
							{
								$diffs['added'][$key] = $new_lang_vars[$key];
							}
						}
			
						if(is_array($diffs['added']))
						{
							ksort($diffs['added']);
				
							echo("<h3>New variables</h3>");
							echo("<pre>");
							display_changes("\$LANG_VARS", $diffs['added']);
							echo("</pre>");
						}
			
						if(is_array($diffs['updated']))
						{
							ksort($diffs['updated']);
				
							echo("<h3>Updated variables</h3>");
							echo("<pre>");
							display_changes("\$LANG_VARS", $diffs['updated']);
							echo("</pre>");
						}
			
						if(is_array($diffs['deleted']))
						{
							ksort($diffs['deleted']);
				
							echo("<h3>Deleted variables</h3>");
							echo("<pre>");
							display_changes("\$LANG_VARS", $diffs['deleted']);
							echo("</pre>");
						}
					}
					else if(is_array($old_lang_vars))
						echo("<div class=\"error\">New language file not specified</div>");
					else if(is_array($new_lang_vars))
						echo("<div class=\"error\">Old language file not specified</div>");
					else
						echo("<div class=\"error\">Old and New language files not specified</div>");
				}
				else
				{
					echo("<div class=\"error\">Old and/or New language files not specified</div>");
				}
			}
			else
			{
				echo("\n<table border=0 frameborder=0 cellspacing=1>");
				echo("\n<form name=\"main\" action=\"$PHP_SELF\" method=\"post\" enctype=\"multipart/form-data\">");
				echo("\n<input type=\"hidden\" name=\"type\" value=\"$ADMIN_TYPE\">");
				echo("\n<input type=\"hidden\" name=\"op\" value=\"diff\">");
				echo(get_input_field("old_file", NULL, 'Old File', "upload(25,*,\"php\")"));
				echo(get_input_field("new_file", NULL, 'New File*', "upload(25,*,\"php\")"));
	
				echo("\n<tr><td colspan=2><input type=submit>");
				echo("\n</td></tr>");
				echo("\n</form>");
				echo("\n</table>");
				
				echo("<p><div class=\"footer\">* If you do not specify a 'New File', the ".$CONFIG_VARS['site.title']." ".$CONFIG_VARS['site.version']." <i>lang/".$_OPENDB_LANGUAGE.".inc.php</i> language file will be used.</div></p>");
			}
		}
		else
		{
			echo _theme_error($LANG_VARS['not_authorized_to_page']);
		}	
	}
	else// File upload not supported on server
	{
		echo _theme_error($LANG_VARS['file_upload_not_available']);
	}
}//if(is_opendb_valid_session())
?>