$DESCRIPTIONS[$row['country_id']]['funders'][$row['funder_id']] = array();
            $DESCRIPTIONS[$row['country_id']]['funders'][$row['funder_id']]['name'] = $row['funder_name'];
            $DESCRIPTIONS[$row['country_id']]['funders'][$row['funder_id']]['programs'] = array();
        }
        $row['title'] = preg_replace("/\"/", "", $row['title']);
        $row['title'] = preg_replace("/\\'/", "''", $row['title']);
        $DESCRIPTIONS[$row['country_id']]['funders'][$row['funder_id']]['programs'][] = $row['title'];
    }
    foreach ($DESCRIPTIONS as $country_k => $country_v) {
        $country_id = $country_k;
        $funder_count = $country_v['funder_count'];
        $country_name = $country_v['country_name'];
        $program_string = '';
        foreach ($country_v['funders'] as $cf_k => $cf_v) {
            $funder_id = $cf_k;
            $funder_name = $cf_v['name'];
            foreach ($cf_v['programs'] as $cfp_k => $cfp_v) {
                if (strlen($program_string) > 0) {
                    $program_string .= "<br />";
                }
                $program_string .= $cfp_v;
            }
            $cartoUpdateSQL = sprintf("insert into donor_programs (country_id, country_name, description, funder_count, funder_id, funder_name) " . "values (%d, '%s', '%s', %d, %d, '%s')", $country_id, $country_name, $program_string, $funder_count, $funder_id, $funder_name);
            $s = cartoSQL($cartoUpdateSQL);
            echo $s;
        }
    }
}
?>
</body>
</html>
}
.funder_detail_block b {
  color: #444;
}
</style>
<body>
<?php 
require_once "config.php";
require_once "cartodb.php";
$fundersNames = array("funder_aus" => 'Austria', "funder_bel" => 'Belgium', "funder_den" => 'Denmark', "funder_eu" => 'EU', "funder_fao" => 'FAO', "funder_fra" => 'France', "funder_ger" => 'Germany', "funder_net" => 'Netherlands', "funder_swe" => 'Sweden', "funder_swi" => 'Switzerland', "funder_uk" => 'United Kingdom', "funder_us" => 'United States', "funder_wb" => 'World Bank');
// This only takes a cartodb_id and returns stuff about it that we can use.
//
$is_print = sprintf("%d", $_REQUEST['print']);
$cartodb_id = sprintf("%d", $_REQUEST['cartodb_id']);
$sqlRequest = sprintf("select * from land_governance where cartodb_id = %d", $cartodb_id);
$s = cartoSQL($sqlRequest);
$obj = json_decode($s);
$country_id = $obj->rows[0]->country_id;
$funders = sprintf("%s", $_REQUEST['funders']);
// Grab all of the program data from the database for this country_id and the selected funders, then return it.
//
$sqlRequest = sprintf("select f.name as funder_name, c.country_name, p.* " . "from program p, country c, funder f, program_country pc, program_funder pf " . "where " . "  p.program_id = pc.program_id and " . "  p.program_id = pf.program_id and " . "  pf.funder_id = f.funder_id and " . "  pc.country_id = c.country_id and " . "  pc.country_id = %d ", $country_id);
if ($country_id == -1) {
    $sqlRequest = "select f.name as funder_name, p.* " . "from program p, funder f, program_funder pf " . "where " . "  p.program_id = pf.program_id and " . "  pf.funder_id = f.funder_id and " . "  p.scope_id = 3 ";
}
if (isset($_REQUEST['funders']) && strlen($_REQUEST['funders']) > 0) {
    $funderString = $_REQUEST['funders'];
    $funderArray = preg_split("/,/", $funderString);
    $funderInString = '';
    $first = 1;
    foreach ($funderArray as $f) {