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 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 | <?php include_once("../include/common.inc.php"); function shortName($name) { $name = trim($name); if (strstr($name,"Minister ") || strstr($name,"Treasurer") || strstr($name,"Parliamentary Secretary")) { $badWords = Array ("Assisting the Prime Minister on","Assisting on"," the "," of "," for "," on "," and "," to ",","," ","'","`"); return str_replace($badWords,"",$name); } else { $out = Array(); preg_match_all('/[A-Z]/', $name, $out); return implode("", $out[0]); } } setlocale(LC_CTYPE, 'C'); $headers = Array("#id", "name", "request_email", "short_name", "notes", "publication_scheme", "home_page", "tag_string"); $db = $server->get_db('disclosr-agencies'); $tag = Array(); try { $rows = $db->get_view("app", "byDeptStateName", null, true)->rows; //print_r($rows); foreach ($rows as $row) { $tag[$row->id] = phrase_to_tag(dept_to_portfolio($row->key)); } } catch (SetteeRestClientException $e) { setteErrorHandler($e); die(); } $foiEmail = Array(); try { $rows = $db->get_view("app", "foiEmails", null, true)->rows; //print_r($rows); foreach ($rows as $row) { $foiEmail[$row->key] = $row->value; } } catch (SetteeRestClientException $e) { setteErrorHandler($e); die(); } $fp = fopen('php://output', 'w'); if ($fp && $db) { header('Content-Type: text/csv; charset=utf-8'); header('Content-Disposition: attachment; filename="export.' . date("c") . '.csv"'); header('Pragma: no-cache'); header('Expires: 0'); fputcsv($fp, $headers); try { $agencies = $db->get_view("app", "byCanonicalName", null, true)->rows; //print_r($rows); foreach ($agencies as $agency) { // print_r($agency); if (isset($agency->value->foiEmail) && $agency->value->foiEmail != "null" && !isset($agency->value->status)) { $row = Array(); $row["#id"] = $agency->id; $row["name"] = trim($agency->value->name); if (isset($agency->value->foiEmail)) { $row["request_email"] = $agency->value->foiEmail; } else { if ($agency->value->orgType == "FMA-DepartmentOfState") { $row["request_email"] = "foi@" . GetDomain($agency->value->website); } else { $row["request_email"] = $foiEmail[$agency->value->parentOrg]; } } if (isset($agency->value->shortName)) { $row["short_name"] = $agency->value->shortName; } else { $row["short_name"] = shortName($agency->value->name); } $row["notes"] = ""; $row["publication_scheme"] = (isset($agency->value->infoPublicationSchemeURL) ? $agency->value->infoPublicationSchemeURL : ""); $row["home_page"] = (isset($agency->value->website) ? $agency->value->website : ""); if ($agency->value->orgType == "FMA-DepartmentOfState") { $row["tag_string"] = $tag[$agency->value->_id] . " " . $agency->value->orgType; } else { $row["tag_string"] = $tag[$agency->value->parentOrg] . " " . $agency->value->orgType; } fputcsv($fp, array_values($row)); if (isset($agency->value->foiBodies)) { foreach ($agency->value->foiBodies as $foiBody) { $row['name'] = iconv("UTF-8", "ASCII//TRANSLIT",$foiBody); $row["short_name"] = shortName($foiBody); fputcsv($fp, array_values($row)); } } } } } catch (SetteeRestClientException $e) { setteErrorHandler($e); } die; } ?> |