]> matita.cs.unibo.it Git - helm.git/blobdiff - helm/software/matita/scripts/public_html/common.php
added raw query form
[helm.git] / helm / software / matita / scripts / public_html / common.php
index 5b9f51e5dc68cc488bb66d2b4ee79528a2ebf3bc..48121b5498ad748ff80ffff815bdd6fef0bfb483 100644 (file)
@@ -1,8 +1,59 @@
 <?php
 
+$i = 0;
+  
+function array_to_combo($a) {
+  foreach($a as $k => $v){
+    echo "<option value=\"{$v}\">{$v}</option>";
+  }
+}
+
+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 "<tr>";
+  if ( $i == 0) {
+      foreach( $q as $name => $txt) {
+          echo "<th>$name</th>";
+      }
+  }
+  echo "</tr>\n";
+  if ( $i%2 == 0)
+     echo "<tr class=\"even\">";      
+  else
+     echo "<tr class=\"odd\">";
+  foreach( $q as $name => $txt) {
+     echo "<td>" . prettify($txt,$name) . "</td>";
+  }
+  echo "</tr>\n";      
+  $i++;
+}
+
+
 function query($q,$f) {
   $db = mysql_pconnect("localhost","helm");
   mysql_select_db("matita");
+  if (!preg_match("/^(select|describe)[^\n;]*;?$/i",$q)) {
+    echo "Query not allowed!";
+    return;
+  }
   $rc = mysql_query($q,$db);
   if(!$rc) {
     die("Query failed: " . mysql_error());
@@ -25,15 +76,4 @@ function time_2_cents($t) {
   return ((int) $t_cents) + ((int) $t_secs) * 100 + ((int)$t_minutes) * 6000 ;
 }
 
-function array_to_combo($l,$a) {
-  echo "<select name=\"$l\">";
-  echo "<option value=\"--\">--</option>";
-  foreach ($a as $k => $v) {
-    foreach( array_keys($v) as $k1 => $i) {
-      echo "<option value=\"{$v[$i]}\">{$v[$i]}</option>";
-    }
-  }
-  echo "</select>";
-}
-
 ?>