Make common include for DB/template
Make common include for DB/template

file:b/.gitignore (new)
  /nbproject/private/
[submodule "sag"] [submodule "sag"]
path = sag path = sag
url = git://github.com/sbisbee/sag.git url = https://github.com/sbisbee/sag.git
  [submodule "couchdb/couchdb-lucene"]
  path = couchdb/couchdb-lucene
  url = https://github.com/rnewson/couchdb-lucene.git
   
file:b/common.inc.php (new)
  <?php
 
  /*
  * To change this template, choose Tools | Templates
  * and open the template in the editor.
  */
 
  function createAgencyDesignDoc() {
  global $sag;
  //See if the design doc exists, creating it if it doesn't
  try {
  //it does exist, so finish early
  if ($sag->head('_design/app')->headers->_HTTP->status != "404")
  return true;
  } catch (Exception $e) {
  //database issue
  return false;
  }
  $ddoc = new StdClass();
  $ddoc->_id = '_design/app';
  $ddoc->views = new StdClass();
  // by abn, by name
  $ddoc->views->byABN = new StdClass();
  $ddoc->views->byABN->map = "function(doc) { emit(doc.abn, doc); };";
  $ddoc->views->byName = new StdClass();
  $ddoc->views->byName->map = "function(doc) { emit(doc.name, doc); };";
  $ddoc->views->getActive = new StdClass();
  $ddoc->views->getActive->map = 'function(doc) { if (doc.status == "active") { emit(doc._id, doc); } };';
  $ddoc->views->getSuspended = new StdClass();
  $ddoc->views->getSuspended->map = 'function(doc) { if (doc.status == "suspended") { emit(doc._id, doc); } };';
  $ddoc->views->getScrapeRequired = new StdClass();
  $ddoc->views->getScrapeRequired->map = "function(doc) { emit(doc.abn, doc); };";
  try {
  $sag->put('_design/app', $ddoc);
  } catch (Exception $e) {
  /*
  * A 409 status code means there was a conflict, so another client
  * already created the design doc for us. This is fine.
  */
  if ($e->getCode() != 409)
  return false;
  }
  return true;
  }
  error_reporting(0);
  require_once('sag/src/SagException.php');
  require_once('sag/src/SagCouchException.php');
  require_once('sag/src/SagConfigurationCheck.php');
  require_once('sag/src/httpAdapters/SagHTTPAdapter.php');
  require_once('sag/src/httpAdapters/SagNativeHTTPAdapter.php');
  require_once('sag/src/httpAdapters/SagCURLHTTPAdapter.php');
  require_once 'sag/src/Sag.php';
  error_reporting(E_ALL ^ E_STRICT ^ E_NOTICE);
  $sag = new Sag();
 
  // createAgencyDesignDoc();
 
  function include_header() {
  ?>
  <!DOCTYPE html>
 
  <!-- paulirish.com/2008/conditional-stylesheets-vs-css-hacks-answer-neither/ -->
  <!--[if lt IE 7]> <html class="no-js lt-ie9 lt-ie8 lt-ie7" lang="en"> <![endif]-->
  <!--[if IE 7]> <html class="no-js lt-ie9 lt-ie8" lang="en"> <![endif]-->
  <!--[if IE 8]> <html class="no-js lt-ie9" lang="en"> <![endif]-->
  <!--[if gt IE 8]><!--> <html lang="en"> <!--<![endif]-->
  <head>
  <meta charset="utf-8" />
 
  <!-- Set the viewport width to device width for mobile -->
  <meta name="viewport" content="width=device-width" />
 
  <title>Welcome to Foundation</title>
 
  <!-- Included CSS Files -->
  <link rel="stylesheet" href="stylesheets/foundation.css">
  <link rel="stylesheet" href="stylesheets/app.css">
 
  <!--[if lt IE 9]>
  <link rel="stylesheet" href="stylesheets/ie.css">
  <![endif]-->
 
 
  <!-- IE Fix for HTML5 Tags -->
  <!--[if lt IE 9]>
  <script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script>
  <![endif]-->
 
  </head>
  <body>
 
  <!-- navBar -->
  <div id="navBar" class="container">
  <div class="row">
  <div class="four columns">
  <h1><a href="/">Disclosr</a></h1>
  </div>
  <div class="eight columns hide-on-phones">
  <strong class="right">
  <a href="../grid.php">Features</a>
  <a href="../case-soapbox.php">Case Studies</a>
  <a href="index.php">Documentation</a>
  <a href="http://github.com/navb/foundation">Github</a>
  <a href="../files/foundation-download-2.1.4.zip" class="small blue nice button src-download">Download</a>
 
  </strong>
  </div>
  </div>
  </div>
  <!-- /navBar -->
 
  <!-- container -->
  <div class="container">
  <?php }
 
  function include_footer() { ?>
  </div>
  <!-- container -->
 
 
 
 
  <!-- Included JS Files -->
  <script src="javascripts/foundation.js"></script>
  <script src="javascripts/app.js"></script>
 
  </body>
  </html>
 
  <?php } ?>
 
 
 
  <?php
 
  include_once("./lib/common.inc.php");
  setlocale(LC_CTYPE, 'C');
  // source: http://stackoverflow.com/questions/81934/easy-way-to-export-a-sql-table-without-access-to-the-server-or-phpmyadmin#81951
 
  $unspsc = Array();
  $unspscresult = $conn->prepare('select * from "UNSPSCcategories" where "UNSPSC"::text like \'%00000\';');
  $unspscresult->execute();
  foreach ($unspscresult->fetchAll() as $row) {
  $unspsc[$row['UNSPSC']] = $row['Title'];
  }
 
  $query = $conn->prepare('
  SELECT "CNID",contractnotice."agencyName",agency_nametoabn.abn as "agencyABN",
  EXTRACT(EPOCH FROM "publishDate") as "publishDate",
  EXTRACT(EPOCH FROM "contractStart") as "contractStart",
  EXTRACT(EPOCH FROM "contractEnd") as "contractEnd",
  value,description,category,
  "supplierName",(case when "supplierABN" != 0 THEN "supplierABN"::text ELSE "supplierName" END) as supplierID,
  (\'https://www.tenders.gov.au/?event=public.advancedsearch.keyword&keyword=CN\'::text || "CNID"::text) as sourceURL
  FROM contractnotice join agency_nametoabn on contractnotice."agencyName"=agency_nametoabn."agencyName"
  where "childCN" is null'
  , array(PDO::ATTR_CURSOR => PDO::FETCH_ORI_NEXT));
  $query->execute();
  $errors = $conn->errorInfo();
  if ($errors[2] != "") {
  die("Export terminated, db error" . print_r($errors, true));
  }
 
  $num_fields = $query->columnCount();
  $headers = Array();
  for ($i = 0; $i < $num_fields; $i++) { // for each column in query, make a CSV header
  $meta = $query->getColumnMeta($i);
  $headers[] = $meta['name'];
  }
  $fp = fopen('php://output', 'w');
  if ($fp && $query) {
  header('Content-Type: text/csv');
  header('Content-Disposition: attachment; filename="export.' . date("c") . '.csv"');
  header('Pragma: no-cache');
  header('Expires: 0');
  fputcsv($fp, $headers);
  while ($row = $query->fetch(PDO::FETCH_NUM, PDO::FETCH_ORI_NEXT)) {
  foreach ($row as $key => &$colvalue) {
 
  $colvalue = preg_replace('/[^[:print:]]/', '', utf8_encode($colvalue));
  if ($headers[$key] == "publishDate" || $headers[$key] == "contractStart"
  || $headers[$key] == "contractEnd") {
  $colvalue = date("Y-m-d", $colvalue);
  }
  /* if ($headers[$key] == "CNID") {
  $colvalue = str_replace("A","", $colvalue);
  }*/
  if ($headers[$key] == "cat1" || $headers[$key] == "cat2"
  || $headers[$key] == "cat3") {
  $colvalue = $unspsc[$colvalue];
  }
  }
  fputcsv($fp, array_values($row));
  }
  die;
  }
  ?>
 
file:b/foundation.html (new)
  <!DOCTYPE html>
 
  <!-- paulirish.com/2008/conditional-stylesheets-vs-css-hacks-answer-neither/ -->
  <!--[if lt IE 7]> <html class="no-js lt-ie9 lt-ie8 lt-ie7" lang="en"> <![endif]-->
  <!--[if IE 7]> <html class="no-js lt-ie9 lt-ie8" lang="en"> <![endif]-->
  <!--[if IE 8]> <html class="no-js lt-ie9" lang="en"> <![endif]-->
  <!--[if gt IE 8]><!--> <html lang="en"> <!--<![endif]-->
  <head>
  <meta charset="utf-8" />
 
  <!-- Set the viewport width to device width for mobile -->
  <meta name="viewport" content="width=device-width" />
 
  <title>Welcome to Foundation</title>
 
  <!-- Included CSS Files -->
  <link rel="stylesheet" href="stylesheets/foundation.css">
  <link rel="stylesheet" href="stylesheets/app.css">
 
  <!--[if lt IE 9]>
  <link rel="stylesheet" href="stylesheets/ie.css">
  <![endif]-->
 
 
  <!-- IE Fix for HTML5 Tags -->
  <!--[if lt IE 9]>
  <script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script>
  <![endif]-->
 
  </head>
  <body>
 
  <!-- container -->
  <div class="container">
 
  <div class="row">
  <div class="twelve columns">
  <h2>Welcome to Foundation</h2>
  <p>This is version 2.1.4 released on December 19, 2011</p>
  <hr />
  </div>
  </div>
 
  <div class="row">
  <div class="eight columns">
  <h3>The Grid</h3>
 
  <!-- Grid Example -->
  <div class="row">
  <div class="twelve columns">
  <div class="panel">
  <p>This is a twelve column section in a row. Each of these includes a div.panel element so you can see where the columns are - it's not required at all for the grid.</p>
  </div>
  </div>
  </div>
  <div class="row">
  <div class="six columns">
  <div class="panel">
  <p>Six columns</p>
  </div>
  </div>
  <div class="six columns">
  <div class="panel">
  <p>Six columns</p>
  </div>
  </div>
  </div>
  <div class="row">
  <div class="four columns">
  <div class="panel">
  <p>Four columns</p>
  </div>
  </div>
  <div class="four columns">
  <div class="panel">
  <p>Four columns</p>
  </div>
  </div>
  <div class="four columns">
  <div class="panel">
  <p>Four columns</p>
  </div>
  </div>
  </div>
 
  <h3>Tabs</h3>
  <dl class="tabs">
  <dd><a href="#simple1" class="active">Simple Tab 1</a></dd>
  <dd><a href="#simple2">Simple Tab 2</a></dd>
  <dd><a href="#simple3">Simple Tab 3</a></dd>
  </dl>
 
  <ul class="tabs-content">
  <li class="active" id="simple1Tab">This is simple tab 1's content. Pretty neat, huh?</li>
  <li id="simple2Tab">This is simple tab 2's content. Now you see it!</li>
  <li id="simple3Tab">This is simple tab 3's content. It's, you know...okay.</li>
  </ul>
 
  <h3>Buttons</h3>
 
  <p><a href="#" class="small blue button">Small Blue Button</a></p>
  <p><a href="#" class="blue button">Medium Blue Button</a></p>
  <p><a href="#" class="large blue button">Large Blue Button</a></p>
 
  <p><a href="#" class="nice radius small blue button">Nice Blue Button</a></p>
  <p><a href="#" class="nice radius blue button">Nice Blue Button</a></p>
  <p><a href="#" class="nice radius large blue button">Nice Blue Button</a></p>
 
  </div>
 
  <div class="four columns">
  <h4>Getting Started</h4>
  <p>We're stoked you want to try Foundation! To get going, this file (index.html) includes some basic styles you can modify, play around with, or totally destroy to get going.</p>
 
  <h4>Other Resources</h4>
  <p>Once you've exhausted the fun in this document, you should check out:</p>
  <ul class="disc">
  <li><a href="http://foundation.zurb.com/docs">Foundation Documentation</a><br />Everything you need to know about using the framework.</li>
  <li><a href="http://github.com/zurb/foundation">Foundation on Github</a><br />Latest code, issue reports, feature requests and more.</li>
  <li><a href="http://twitter.com/foundationzurb">@foundationzurb</a><br />Ping us on Twitter if you have questions. If you build something with this we'd love to see it (and send you a totally boss sticker).</li>
  </ul>
  </div>
  </div>
 
  </div>
  <!-- container -->
 
 
 
 
  <!-- Included JS Files -->
  <script src="javascripts/foundation.js"></script>
  <script src="javascripts/app.js"></script>
 
  </body>
  </html>
 
<
<?php <?php
function createAgencyDesignDoc()  
{ include_once('common.inc.php');
global $sag; include_header();
//See if the design doc exists, creating it if it doesn't  
try {  
//it does exist, so finish early  
if ($sag->head('_design/app')->headers->_HTTP->status != "404") return true;  
}  
catch(Exception $e) {  
//database issue