]> andersk Git - sql-web.git/blobdiff - lib/joe/joe.lib.php
git-svn-id: svn://presbrey.mit.edu/php/php@100 a142d4bd-2cfb-0310-9673-cb33a7e74f58
[sql-web.git] / lib / joe / joe.lib.php
index 26723218b3064bf77c1b6051e6c84ba15c04b21e..dffb0df346513b609b716774770accef27126833 100644 (file)
@@ -2,29 +2,24 @@
 /*
     (c) 2005 Joe Presbrey
     joepresbrey@gmail.com
-
-    ATTN:  This library was compiled and completed in its entirety independent of
-    any and all corporate projects and/or work environment.
-
-    You may NOT use this library elsewhere!
-
 */
 
-function isFormPost() {
+function isPost() {
   if($_SERVER['REQUEST_METHOD'] == 'POST') {
     return true;
   } else {
     return false;
   }
 }
+function isFormPost() { return isPost(); }
 
 function isSess($id) {
   return isset($_SESSION[$id]);
 }
 
-function sess($id,$val=NULL) {
+function sess($id,$val=null) {
   if (is_null($val)) {
-    return (isSess($id)?$_SESSION[$id]:NULL);
+    return (isSess($id)?$_SESSION[$id]:null);
   } elseif (empty($val)) {
     unset($_SESSION[$id]);
   } else {
@@ -45,28 +40,30 @@ function stopSess() {
   @session_destroy();
 
   foreach($sid as $id) {
-    @unlink(SESSIONS_PATH.'/sess_'.$id);
+    @unlink(session_save_path().'/sess_'.$id);
   }
 }
 
 function sessTime($query=null) {
+  global $timingc;
   global $timings;
 
   if(!isset($timings)) {
     $timings = array();
   }
 
-  if (!isSess('TIMING')) {
-    sess('TIMING', '1');    
+  if (!isset($timingc) || empty($timingc)) {
+       $timingc = 1;
   } elseif (!is_null($query)) {
-    $current = sess('TIMING');
-    $current++;
-    sess('TIMING', $current);
+    $current = $timingc;
+       $timingc = ++$current;
   }
-  $key = sess('TIMING');
+  $key = $timingc;
 
   if (is_null($query)) {
     $timings[$key]['time'] = microtime(true)-$timings[$key]['time'];
+       if (mysql_error())
+               $timings[$key]['error'] = mysql_error();
     return true;
   } else {
     $timings[$key] = array();
@@ -77,7 +74,6 @@ function sessTime($query=null) {
 }
 
 function fetchRows($rs, $key = null) {
-    /* ask me how to use this if its not obvious ~ Joe */
     if (!$rs) return array();
     $kn = is_null($key);
     $n = mysql_num_rows($rs);
@@ -104,17 +100,24 @@ function fetchRows($rs, $key = null) {
     }
 }
 
-function printErrors($errArray) {
-    if (isset($errArray) && count($errArray)) {
-        echo '<ul style="color:red;">';
-        foreach($errArray as $err) {
-            echo '<li style="color:red;"><p>',$err,'</p></li>';
+function printErrors($err) { printList('err', $err); }
+function printMsgs($err) { printList('msg', $err); }
+
+function printList($class,$err) {
+    if (is_array($err) && count($err)) {
+        echo '<div class="',$class,'">',(count($err)>1?'<ul>':'');
+        foreach($err as $e) {
+                       if (count($err)>1) {
+                               echo '<li><p>',$e,'</p></li>';
+                       } else {
+                               echo '<p>',$e,'</p>';
+                       }
         }
-        echo '</ul>';
+        echo (count($err)>1?'</ul>':''),'</div>';
     }
 }
 
-function buildSQLSet($fields, $values=NULL) {
+function buildSQLSet($fields, $values=null) {
     $ex = array('NOW()','NULL');
     $sql = 'SET';
     $c = 0;
@@ -136,7 +139,7 @@ function buildSQLSet($fields, $values=NULL) {
     return $sql;
 }
 
-function buildSQLInsert($array, $table=NULL) {
+function buildSQLInsert($array, $table=null) {
     $ex = array('NOW()','NULL');
     $sql = '(';
     $c = 0;
@@ -169,10 +172,8 @@ function build_str($query_array) {
     return join('&', $query_string);
 }
 
-function newQS($key, $val) {
-    parse_str($_SERVER['QUERY_STRING'], $arr);
-    $arr[$key] = $val;
-    return '?'.build_str($arr);
+function newQS($key, $val=null) {
+    return newQSA(array($key=>$val));
 }
 
 function newQSA($array=array()) {
This page took 0.042914 seconds and 4 git commands to generate.