add network graph
[contractdashboard.git] / admin / importSON.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
<?php
include_once ("../lib/common.inc.php");
function fetchSON($SONID)
{
    global $conn;
    echo $SONID;
 
# Create a search parser object
    $search = new DOMDocument();
    $doc = new DOMDocument();
 
# Parse the HTML from Google.
# The @ before the method call suppresses any warnings that
# loadHTML might throw because of invalid HTML in the page.
    @$search->loadHTML(file_get_contents("https://www.tenders.gov.au/?event=public.advancedsearch.CNSONRedirect&type=sonSearchEvent&SONID=$SONID"));
 
# Iterate over all the <a> tags
    foreach ($search->getElementsByTagName('a') as $link) {
        # Show the <a href>
        if (strpos($link->getAttribute('href'), 'UUID')) {
            echo $link->getAttribute('href');
            @$doc->loadHTML(file_get_contents("https://www.tenders.gov.au".$link->getAttribute('href')));
        }
    }
 
    //TODO update title from $x("//p[@class='lead']/text()")
 
 
    $sql='insert into standingoffer_suppliers("SONID",name,abn,state,postcode) values(?,?,?,?,?)';
    $q=$conn->prepare($sql);
 
    foreach($doc->getElementsByTagName('tr') as $row) {
        $supplier = Array("SONID"=>$SONID);
        $i = 0;
        foreach ($row->childNodes as $column){
            //echo $i;
            if ($i==0) $supplier['name'] = $column->textContent;
            if ($i==2) $supplier['abn'] = trim(str_replace(' ','',$column->textContent));
            if ($i==4) $supplier['state'] = $column->textContent;
            if ($i==6) $supplier['postcode'] = $column->textContent;
            //echo $column->textContent;
        $i++;
    }
    //print_r($supplier);
        $q->execute(array_values($supplier));
    }
}
if ($_REQUEST['SONID']) {
    fetchSON($_REQUEST['SONID']);
}