File: loadtabfiles.php

package info (click to toggle)
gforge 4.5.14-22etch13
  • links: PTS
  • area: main
  • in suites: etch
  • size: 13,004 kB
  • ctags: 11,918
  • sloc: php: 36,047; sql: 29,050; sh: 10,538; perl: 6,496; xml: 3,810; makefile: 341; python: 263; ansic: 256
file content (184 lines) | stat: -rw-r--r-- 6,482 bytes parent folder | download | duplicates (2)
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
<?php
/**
 * //TODO DESCRIPTION
 *
 * @version   $Id: loadtabfiles.php 3386 2004-09-29 15:10:41Z cbayle $
 *
 * This file is part of GForge.
 *
 * GForge 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.
 *
 * GForge 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 GForge; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */


require_once('pre.php');
require_once('common/include/account.php');
require_once('www/admin/admin_utils.php');
require_once('www/include/BaseLanguage.class');

session_require(array('group'=>'1','admin_flags'=>'A'));

if ($purgeall) {
	db_query("DROP TABLE tmp_lang;");
}

if ($loadall) {
	db_query("DROP TABLE tmp_lang;");
	db_query("CREATE TABLE tmp_lang (tmpid integer, language_id text, seq integer , pagename text, category text, tstring  text);");
	//db_commit();
	$rep= $sys_urlroot . 'include/languages/';
	//chdir($rep);
	$dir = opendir("$rep");
	while($file = readdir($dir)) {
		if(ereg("(.*)\.tab$",$file,$regs)){
			$tmpid=0;
			$language_id=$regs[1];
			$ary = file($rep . $file,1);
			for ($i=0; $i<sizeof($ary); $i++) {
				$seq=$i*10;
				if (substr($ary[$i], 0, 1) == '#') {
					$query="INSERT INTO tmp_lang values(". $seq . ",'" . $language_id . "'," . $seq . ",'#','#" . $seq . "','" . $ary[$i] . "')";
					$tmpid++;
					db_query($query);
					continue;
				}
				$line = explode("\t", $ary[$i], 3);
				//$query="INSERT INTO tmp_lang values(". $seq . ",'" . $language_id . "'," . $seq . ",'" . $line[0] . "','" . $line[1] . "','" . $line[2] ."')";
				$query="INSERT INTO tmp_lang values(". $seq . ",'" . $language_id . "'," . $seq . ",'" . $line[0] . "','" . $line[1] . "','" . addslashes(quotemeta(htmlspecialchars($line[2]))) ."')";
				//$query="INSERT INTO tmp_lang values(". $seq . ",'" . $language_id . "'," . $seq . ",'" . $line[0] . "','" . $line[1] . "','" . base64_encode($line[2]) ."')";
				$tmpid++;
				$res=db_query($query);
				if (!$res){
					echo '<br />'.$query.'<br />'. db_error();
				}
			}
		}
	}
	rewinddir($dir);
	while($file = readdir($dir)) {
		if(ereg("(.*)\.tab$",$file,$regs)){
			$language_id=$regs[1];
			$query="INSERT INTO tmp_lang SELECT -1,'".$language_id."',seq+5,pagename,category,tstring FROM tmp_lang WHERE language_id='Base' AND pagename!='#' AND pagename||category NOT IN (select pagename||category FROM tmp_lang WHERE language_id='" . $language_id . "' ) ORDER BY seq";
			$res=db_query($query);
			if (!$res){
				echo '<br />'.$query.'<br />'. db_error();
			}
		}
	}
	closedir($dir);
	//db_commit();
}

site_admin_header(array('title'=>"Site Admin"));
?>

<form name="mload" method="post" action="<?php echo $PHP_SELF; ?>">

<input type="submit" name="loadall" value="<?php echo "(Re)Load all language files"; ?>" />
<input type="submit" name="purgeall" value="<?php echo "Purge loaded data"; ?>" />

</form>

<p />

<?php
$result1=db_query("select language_id, count(language_id) AS count from tmp_lang where pagename!='#' and tmpid!='-1' group by language_id");
$result2=db_query("select language_id, count(language_id) AS count from tmp_lang where pagename!='#' group by language_id");
if (db_numrows($result1)>0) {
?>
	<h3 style="color:red">Tables loaded:</h3>
<?php
	echo '
	<table border="0" bgcolor=white width="100%">
		<tr bgcolor=blue>
			<td><b><font color="white">Language</b></font></td>
			<td colspan=2><b><font color="white">Translated</b></font></td>
			<td colspan=2><b><font color="white">Extra</b></font></td>
			<td><b><font color="white">Double</b></font></td>
			<td><b><font color="white">Translation</b></font></td>
			<td><b><font color="white">To Translate</b></font></td>
			<td><b><font color="white">Not in Base</b></font></td>
			<td><b><font color="white">Tab file</b></font></td>
		</tr>';
		
	$maxtrans=0;
	for ($i=0; $i<db_numrows($result1) ; $i++) {
		$howmany1=db_result($result1, $i, 'count');
		//if ($howmany>$maxtrans) $maxtrans=$howmany;
		$lang=db_result($result1, $i, 'language_id');
		if ($lang=='Base') $maxtrans=$howmany1;
	}
	for ($i=0; $i<db_numrows($result1) ; $i++) {
		$howmany1=db_result($result1,$i,'count');
		$howmany2=db_result($result2,$i,'count')-$maxtrans;
		$rate1=$howmany1 * 100 / $maxtrans;
		$rate2=$howmany2 * 100 / $maxtrans;
		$language_id=db_result($result1,$i,'language_id');
		echo "\n<tr bgcolor=lightblue><td>$language_id</td>";
		printf("<td>%d</td><td>%3.2f",$howmany1,$rate1);
		echo "%</td>";
		if ($rate2!=0) {
			printf("<td>%d</td><td>%3.2f",$howmany2,$rate2);
			echo "%</td>";
		} else {
			printf("<td colspan=2></td>");
		}
?>
<td>
	<a href="editdouble.php?function=show&lang=<?php echo "$language_id"; ?>">[edit]</a>
</td>
<td>
	<a href="seetranstabfiles.php?function=show&lang=<?php echo "$language_id"; ?>">[see]</a>
	<a href="edittranstabfiles.php?function=show&lang=<?php echo "$language_id"; ?>">[edit]</a>
</td>
<td>
	<a href="seenotranstabfiles.php?function=show&lang=<?php echo "$language_id"; ?>">[see]</a>
	<a href="editnotranstabfiles.php?function=show&lang=<?php echo "$language_id"; ?>">[edit]</a>
</td>
<td>
	<a href="seenotinbasetabfiles.php?function=show&lang=<?php echo "$language_id"; ?>">
	<? if ($rate2!=0) echo "[see]";?></a>
	<a href="editnotinbasetabfiles.php?function=show&lang=<?php echo "$language_id"; ?>">
	<? if ($rate2!=0) echo "[edit]";?></a>
</td>
<td>
	<a href="seetabfiles.php?function=show&lang=<?php echo "$language_id"; ?>">[see]</a>
	<a href="edittabfiles.php?function=show&lang=<?php echo "$language_id"; ?>">[edit]</a>
	<a href="gettabfiles.php?function=show&lang=<?php echo "$language_id"; ?>">[get]</a>
</td>
<?php
		echo "</tr>";
	}
	echo "\n</table>";
} else {
?>
	<h3 style="color:red">Available Tables:</h3>
		<table border="0">
<?php
	$rep= $sys_urlroot . 'include/languages/';
	//chdir($rep);
	$dir = opendir("$rep");
	while($file = readdir($dir)) {
		if(ereg("(.*)\.tab$",$file,$regs)){
			$language_id=$regs[1];
			echo "\n<tr><td>$language_id</td>";
			echo "<tr>";
		}
	}
	echo "\n</table>";
}

site_admin_footer(array());

?>