<?

// Perform a query
  function query($s) {
    // eval $s for variables
    global $cat,$exp,$text,$title,$response,$expire, $graphicurl,$adid;
    global $delid,$approve,$state,$now,$qq;
    eval("\$s=\"$s\";");
    $db=odbc_connect("classad","","", SQL_CUR_USE_ODBC) or die("Connect");
    return odbc_exec($db,$s);
  }

// Read next row 
 function fetch_array($r) {
   if (!odbc_fetch_row($r)) return false;
   $n=odbc_num_fields($r);
   $tmpary=array();
   for ($i=1;$i<=$n;$i++) {
     $tmpary[odbc_field_name($r,$i)]=odbc_result($r,$i);
   }
   return $tmpary;
  }

// Get last insert ID
function insert_id() {
  $dbii=query("select @@IDENTITY");
  odbc_fetch_row($dbii);
  return odbc_result($dbii,1);
  }

// Display a date (formatted)
function show_date($datein) {
  return $datein;
  }

// Get expire date
function get_todaystring($daysoffset) {
   return strftime("%d/%m/%Y %H:%M",time()+86400*$daysoffset);
   }

// This database can't fetch a specific page
$can_use_limit=0;
// Date format for inserts
$db_datefmt="%m/%d/%Y %H:%M";


// The SQL queries
$sql_insert="insert into ads (catid,title,adtext,response,exp,graphicurl,active) values (\$cat,'\$title','\$text','\$response','\$expire','\$graphicurl',false)";
$sql_update="update ads SET title='\$title', response='\$response', exp='\$expire', graphicurl='\$graphicurl', adtext='\$text' where adid=\$adid";
$sql_query1="select * from ads where adid=\$adid";
$sql_showquery="select * from ads where catid=\$cat and exp>=now() and active=true order by posted desc";
$sql_delete="delete from ads where adid=\$delid";
$sql_approve="update ads set exp='\$expire', active=true where adid=\$approve";
$sql_appquery="select * from ads where exp>=now() and active=\$state order by posted desc";
$sql_search="select * from ads where (title like '\$qq' or adtext like '\$qq') and active=true and exp>=now() order by posted desc";
$sql_last="select top 1 * from ads where exp>=now() and active=true order by posted desc";
$sql_nav="select * from category order by catid"; 
?>