]> matita.cs.unibo.it Git - helm.git/blob - helm/software/matita/scripts/public_html/common.php
5b9f51e5dc68cc488bb66d2b4ee79528a2ebf3bc
[helm.git] / helm / software / matita / scripts / public_html / common.php
1 <?php
2
3 function query($q,$f) {
4   $db = mysql_pconnect("localhost","helm");
5   mysql_select_db("matita");
6   $rc = mysql_query($q,$db);
7   if(!$rc) {
8     die("Query failed: " . mysql_error());
9   }
10   while( $row = mysql_fetch_array($rc, MYSQL_ASSOC)){
11     $f($row);
12   }
13   mysql_free_result($rc);
14   mysql_close($db);
15 }
16
17 function time_2_cents($t) {
18   $matches = array();
19   $rex = "/^(\d+)m(\d\d?)\.(\d{2})s$/";
20   $m = preg_match($rex,$t,$matches);
21   if ( $m == 0 ) exit(1);
22   $t_minutes = $matches[1];
23   $t_secs = $matches[2];
24   $t_cents = $matches[3];
25   return ((int) $t_cents) + ((int) $t_secs) * 100 + ((int)$t_minutes) * 6000 ;
26 }
27
28 function array_to_combo($l,$a) {
29   echo "<select name=\"$l\">";
30   echo "<option value=\"--\">--</option>";
31   foreach ($a as $k => $v) {
32     foreach( array_keys($v) as $k1 => $i) {
33       echo "<option value=\"{$v[$i]}\">{$v[$i]}</option>";
34     }
35   }
36   echo "</select>";
37 }
38
39 ?>