function get_data_from_mongo($dt, $industry, $fname) { // connect $m = new MongoClient(); // select a database $db = $m->labour1; // select a collection (analogous to a relational database's table) $collection = $db->ee; // echo "writing data"; // prepare header $fw = fopen($fname . ".csv", "w"); $array1 = create_list_of_measures($dt); array_push($array1, "industry"); array_unshift($array1, "date"); fputcsv($fw, $array1); // export data // find everything in the collection $cursor = $collection->find(); // iterate through the results foreach ($cursor as $document) { $this_line = array(); $c = 0; $this_line[] = $document["idate"]; foreach ($dt as $dt_key => $dt_val) { if (null != $document[$dt_key]) { $c++; } $this_line[] = $document[$dt_key]; } $this_line[] = $industry[$document["industry"]]; if (0 != $c) { fputcsv($fw, $this_line); } //echo $document["title"] . "\n"; } fclose($fw); return $fname . ".csv"; }
file_put_contents("/tmp/bls-callback.log", date(DATE_ATOM) . " hit " . print_r($_REQUEST, true) . " \n", FILE_APPEND); if (FALSE !== strpos($_GET["type"], "deleteSchema")) { die("OK"); } if (FALSE !== strpos($_GET["type"], "updateschema")) { // do it $key = (int) $_GET["obj_key"]; include_once 'askhost.php'; $dt = get_datatype1(); $industry = get_datatype2(); $fname = tempnam("/tmp", "bls1"); $csvname = get_data_from_mongo($dt, $industry, $fname); zip_compress_csv($fname . "zip", $csvname); @unlink($fname); $secret = sha1($capsidea_client_secret . $capsidea_permanent_access_token); $array1 = create_list_of_measures($dt); $measures = ""; foreach ($array1 as $val) { $measures = $measures . "{Name: \"{$val}\", TypeName:\"double\" },"; } $schemajson = "&fields=" . urlencode('[{Name: "date", TypeName:"timestamp"},' . $measures . '{Name: "industry", TypeName:"string"}]'); $host_reply = askhost($server_url . "&schemakey=" . $key . $schemajson, array('file_contents' => '@' . $fname . ".zip"), "", "", "", 800000, array("appid: {$capsidea_appid}", "sig: {$secret}"), true); // defined in askhost.php //echo "done\n"; $httpcode = $host_reply["httpcode"]; // $jsonres=json_decode($host_reply["data"], true); // $key=(int)$jsonres["Key"]; // if (0==$key) $key=$cdata["k"]; $error_log = "response:<pre>" . $host_reply["data"] . "</pre>" . "<br>connection debug:<pre>" . $host_reply["d"] . "</pre>"; if (200 == $httpcode) { unlink($fname . ".zip");