X-Git-Url: http://matita.cs.unibo.it/gitweb/?p=helm.git;a=blobdiff_plain;f=matita%2Fscripts%2Fpublic_html%2Fcommon.php;fp=matita%2Fscripts%2Fpublic_html%2Fcommon.php;h=d56c9d40bf5b5d4b1eab1df4afb59737547c4048;hp=0000000000000000000000000000000000000000;hb=f61af501fb4608cc4fb062a0864c774e677f0d76;hpb=58ae1809c352e71e7b5530dc41e2bfc834e1aef1 diff --git a/matita/scripts/public_html/common.php b/matita/scripts/public_html/common.php new file mode 100644 index 000000000..d56c9d40b --- /dev/null +++ b/matita/scripts/public_html/common.php @@ -0,0 +1,80 @@ + $v){ + echo ""; + } +} + +function prettify($s,$name) { + if (preg_match("/^[0-9]{12}$/",$s)) { + $year = substr($s,0,4); + $month = substr($s,4,2); + $day = substr($s,6,2); + $hour = substr($s,8,2); + $minute = substr($s,10,2); + return $day . "/" . $month . "/" . $year . " " . $hour . ":" . $minute; + } else if (preg_match("/time/",$name)){ + $min = floor($s / 6000); + $sec = floor(($s - $min * 6000) / 100); + $cents = $s % 100; + return $min . "m" . $sec . "." . $cents . "s"; + } else + return rtrim($s); +} + + +function printer($q){ + global $i; + echo ""; + if ( $i == 0) { + foreach( $q as $name => $txt) { + echo "$name"; + } + } + echo "\n"; + if ( $i%2 == 0) + echo ""; + else + echo ""; + foreach( $q as $name => $txt) { + echo "" . prettify($txt,$name) . ""; + } + echo "\n"; + $i++; +} + + +function query($q,$f) { + $db = mysql_pconnect("localhost","helm"); + mysql_select_db("matita"); + $q = ltrim(rtrim(preg_replace("/\n/"," ",$q))); + if (!preg_match("/^(select|describe)[^\n;]*;?$/i",$q)) { + die("Query not allowed!
" . $q . "
"); + return; + } + $rc = mysql_query($q,$db); + if(!$rc) { + die("Query failed: " . mysql_error()); + } + while( $row = mysql_fetch_array($rc, MYSQL_ASSOC)){ + $f($row); + } + mysql_free_result($rc); + mysql_close($db); +} + +function time_2_cents($t) { + $matches = array(); + $rex = "/^(\d+)m(\d\d?)\.(\d{2})s$/"; + $m = preg_match($rex,$t,$matches); + if ( $m == 0 ) exit(1); + $t_minutes = $matches[1]; + $t_secs = $matches[2]; + $t_cents = $matches[3]; + return ((int) $t_cents) + ((int) $t_secs) * 100 + ((int)$t_minutes) * 6000 ; +} + +?>