[219864] Top translators and scoreboard
diff --git a/classes/export/dbmaintenance_15min.php b/classes/export/dbmaintenance_15min.php
new file mode 100644
index 0000000..d700118
--- /dev/null
+++ b/classes/export/dbmaintenance_15min.php
@@ -0,0 +1,39 @@
+<?php
+
+/*******************************************************************************
+ * Copyright (c) 2008 Eclipse Foundation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ *    Eclipse Foundation - Initial API and implementation
+*******************************************************************************/
+
+	/*
+	 * This is a cronjob-driven database maintenance script
+	 * It is run every 15 minutes
+	 */
+
+	define('BABEL_BASE_DIR', "../../");
+	require(BABEL_BASE_DIR . "classes/system/dbconnection.class.php");
+	
+	if (!($ini = @parse_ini_file(BABEL_BASE_DIR . 'classes/base.conf'))) {
+		errorLog("Failed to find/read database conf file - aborting.");
+		exitTo("error.php?errNo=101300","error: 101300 - database conf can not be found");
+	}
+	  
+	$context = $ini['context'];
+	if($context == "") {
+		$context = "staging";
+	}
+	$dbc = new DBConnection();
+	$dbh = $dbc->connect();
+
+
+	# refresh the scoreboard
+	require_once(BABEL_BASE_DIR . "classes/system/scoreboard.class.php");
+	$sb = new Scoreboard();
+	$sb->refresh();
+?>
\ No newline at end of file
diff --git a/classes/system/scoreboard.class.php b/classes/system/scoreboard.class.php
index 51ca0dc..4fd3371 100644
--- a/classes/system/scoreboard.class.php
+++ b/classes/system/scoreboard.class.php
@@ -13,27 +13,33 @@
 
 class Scoreboard {
 
-	public refresh() {
-		global $App, $dbh;
+	public function refresh() {
+		global $dbh;
 		$sql = "SELECT MAX(translation_id) as t, quantity FROM translations, scoreboard WHERE itemid = 'LASGEN' GROUP BY quantity HAVING t > quantity";
+	
+		$t = 0;
 		
 		$result = mysql_query($sql, $dbh);
 		if($result && mysql_num_rows($result) > 0) {
+			$myrow = mysql_fetch_assoc($result);
 			
+			$t = $myrow['t'];
+
 			# "lock" the scoreboard so that 2 clients don't update it simultaneously
 			mysql_query("UPDATE scoreboard SET quantity = 9999999999 WHERE itemid = 'LASGEN'", $dbh);
 
 			# rebuilding the scoreboard takes time ... dump stuff to tmp
-			$sql = "CREATE TEMPORARY TABLE _tmp_scoreboard LIKE scoreboard";
+			mysql_query("CREATE TEMPORARY TABLE _tmp_scoreboard LIKE scoreboard", $dbh);
 			$sql = "INSERT INTO _tmp_scoreboard SELECT NULL, 'LANGPR', CONCAT(b.name,IF(ISNULL(b.locale),'',CONCAT(' ', b.locale))), count(*) as StringCount from translations as a inner join languages as b on b.language_id = a.language_id where a.value <> '' and a.is_active = 1 group by a.language_id order by StringCount desc";
 			mysql_query($sql, $dbh);
 			$sql = "INSERT INTO _tmp_scoreboard SELECT NULL, 'TOPTR', CONCAT(first_name, IF(ISNULL(last_name),'',CONCAT(' ', last_name))), count(translations.string_id) as cnt from translations inner join users on users.userid = translations.userid where is_active=1 group by first_name, last_name order by cnt desc limit 20";
 			mysql_query($sql, $dbh);
-			$sql = "INSERT INTO _tmp_scoreboard SELECT NULL, 'LASGEN', 'Scoreboard Last Generated', MAX(translation_id) FROM translations";
 
+			$sql = "INSERT INTO _tmp_scoreboard SELECT NULL, 'LASGEN', 'Scoreboard Last Generated', MAX(translation_id) FROM translations";
 			mysql_query($sql, $dbh);
+			
 			mysql_query("LOCK TABLES scoreboard WRITE", $dbh);
-			mysql_query("TRUNCATE TABLE scoreboard", $dbh);
+			mysql_query("DELETE FROM scoreboard", $dbh);
 			mysql_query("INSERT INTO scoreboard SELECT * FROM _tmp_scoreboard", $dbh);
 			mysql_query("UNLOCK TABLES", $dbh);
 			mysql_query("DROP TABLE _tmp_scoreboard", $dbh);
diff --git a/html/callback/setStringTranslation.php b/html/callback/setStringTranslation.php
index 7f7e2f4..1394fb3 100644
--- a/html/callback/setStringTranslation.php
+++ b/html/callback/setStringTranslation.php
@@ -14,9 +14,6 @@
 
 require_once("cb_global.php");
 
-//print_r($_REQUEST);
-
-// print_r($_POST);
 
 $string_id = $App->getHTTPParameter("string_id", "POST");
 $translation = $App->getHTTPParameter("translation", "POST");
@@ -184,14 +181,6 @@
 				  	created_on = NOW()";
 		mysql_query($sql, $dbh);
 	}
-	
-	# refresh the scoreboard
-	# 25 of every 100 hits (25%) will clean up
-	if(rand(0, 100) < 25) {
-		require_once(BABEL_BASE_DIR . "classes/system/scoreboard.class.php");
-		$sb = new Scoreboard();
-		$sb->refresh();
-	}
 }
 
 ?>
\ No newline at end of file