Export employee stats
Export employee stats


Former-commit-id: cffd8ae4e74fc751c71cdaf62195ce99303268a2

--- /dev/null
+++ b/admin/exportEmployees.csv.php
@@ -1,1 +1,60 @@
+<?php
 
+include_once("../include/common.inc.php");
+
+
+setlocale(LC_CTYPE, 'C');
+
+$headers = Array("name");
+
+$db = $server->get_db('disclosr-agencies');
+try {
+    $rows = $db->get_view("app", "all", null, true)->rows;
+
+    $dataValues = Array();
+    foreach ($rows as $row) {
+        if (isset($row->value->statistics->employees)) {
+
+            $headers = array_unique(array_merge($headers, array_keys(object_to_array($row->value->statistics->employees))));
+        }
+    }
+} catch (SetteeRestClientException $e) {
+    setteErrorHandler($e);
+}
+
+$fp = fopen('php://output', 'w');
+if ($fp && $db) {
+    header('Content-Type: text/csv; charset=utf-8');
+    header('Content-Disposition: attachment; filename="export.employeestats.' . date("c") . '.csv"');
+    header('Pragma: no-cache');
+    header('Expires: 0');
+    fputcsv($fp, $headers);
+    try {
+        $agencies = $db->get_view("app", "all", null, true)->rows;
+        //print_r($agencies);
+        foreach ($agencies as $agency) {
+
+            if (isset($agency->value->statistics->employees)) {
+                $row = Array();
+                $agencyEmployeesArray = object_to_array($agency->value->statistics->employees);
+                foreach ($headers as $fieldName) {
+                    if ($fieldName == "name") {
+                        $row[] = $agency->value->name;
+                    } else if (isset($agencyEmployeesArray[$fieldName])) {
+                        $row[] = $agencyEmployeesArray[$fieldName]["value"];
+                    } else {
+                        $row[] = 0;
+                    }
+                }
+
+                fputcsv($fp, array_values($row));
+            }
+        }
+    } catch (SetteeRestClientException $e) {
+        setteErrorHandler($e);
+    }
+
+    die;
+}
+?>
+