private static function outputNationLists($stattype = "applicants", $nationlists = array(), $charts = array(), $aux = array(), $countPolandAsBaltic = FALSE, $showOnlyNordic = FALSE) { /* data = array( [0] => conts [1] => extconts //[2] => type //[3] => show //[4] => event //[5] => applicant //[6] => person [7] => columns [8] => extcolumns [9] => nationlists //[10] => pie ) */ $stdout = ""; $label = self::getEventLabel($stattype); switch ($stattype) { case "applicants": $caveattext = "per Application (not per individual applicant)"; $summarytext1 = "applications"; $summarytext2 = "applicants"; break; case "events": $caveattext = "per Event (not per individual)"; $summarytext1 = "participants"; $summarytext2 = ""; break; case "allguests": $caveattext = "per Event (not per individual)"; $summarytext1 = "visits"; $summarytext2 = ""; break; } // end switch // ------------------------ // Auxiliary parameters // -- $no_of_decimals // ------------------------ $no_of_decimals = 0; // ------------------------ // Output local styles // ------------------------ if (count($aux["columns"]) > 3) { $stdout .= " <style type='text/css'>.nationalities table { width: 100%; }</style>\r\n" . "\r\n"; } // ------------------------ // Output: table start code // ------------------------ $table_start = " <table>\r\n" . " <tr>\r\n" . " <th> </th>\r\n"; foreach ($aux["extColumns"] as $coltitle) { $table_start .= " <th>" . $coltitle . "</th>\r\n"; } $table_start .= " </tr>\r\n"; // ------------------------ // Output: loop over events // ------------------------ foreach ($nationlists as $idx => $event) { if ((!isset($GLOBALS["beenthere"]) && ($idx == 0 || $stattype != "visitors") || isset($GLOBALS["eventindex"][$idx]) && ($idx != 0 || count($GLOBALS["eventindex"]) > 2) && ($idx != 0 || count($GLOBALS["eventindex"]) > 2)) && !empty($event["summary"]["total"])) { $stdout .= " <div class='nationalities" . ($showOnlyNordic && !$idx ? " summary" : "") . ($showOnlyNordic && $idx ? " nordic" : "") . "'>\r\n" . "\r\n" . ($stattype != "visitors" ? " <h2>" . $event["title"] . "</h2>\r\n" : "") . "\r\n"; // ------------------------ // Summary // ------------------------ if (!$showOnlyNordic || !$idx) { $stdout .= " <h4>" . ($stattype != "visitors" ? "Statistics " . ($idx == 0 ? $caveattext : " for this " . ucfirst($label)) : "Total Visitor Statistics") . "</h4>\r\n"; } $stdout .= " <dl>\r\n" . " <dd>Any Nordic Connection: " . "<strong>" . $event["summary"]["nordic"] . "</strong> " . "(" . $event["summary"]["nordicpr"] . "%)" . "</dd>\r\n" . " <dd>No Nordic Connection: " . "<strong>" . $event["summary"]["nonordic"] . "</strong> " . "(" . (100 - $event["summary"]["nordicpr"]) . "%)" . "</dd>\r\n" . " <dd>Total number of " . $summarytext1 . ": " . "<strong>" . $event["summary"]["total"] . "</strong></dd>\r\n" . ($idx == 0 ? " <dd>[Number of unique " . $summarytext2 . ": " . "<strong>" . $event["summary"]["unique"] . "</strong>]</dd>\r\n" : "") . " </dl>\r\n" . "\r\n"; // ------------------------ // By campaign // ------------------------ //debug::rr($nationlists[0]); //debug::rr($nationlists[7]); if ($stattype == "applicants" && $idx == 0) { // summary of all selected $stdout .= " <h4>Nordic Applicants, by Campaign:</h4>\r\n" . " <table>\r\n" . " <tr>\r\n" . " <th> </th>\r\n" . " <th>Total Number of Applications</th>\r\n" . " <th>Nordic <br>Citizens</th>\r\n" . " <th>Nordic <br>Residents</th>\r\n" . " <th>Nordic PhD Degree</th>\r\n" . " </tr>\r\n"; foreach ($nationlists as $nidx => $nevent) { if ($nidx != 0) { $brieftitle = strlen($nevent["title"]) > 45 ? substr($nevent["title"], 0, 38) . "... [" . $nevent["year"] . "]" : $nevent["title"]; $stdout .= " <tr>\r\n" . " <td class='red bold'>" . $brieftitle . "</td>\r\n" . " <td><strong>" . $nationlists[$nidx]["summary"]["total"] . "</strong></td>\r\n" . " <td><strong>" . $nationlists[$nidx]["continent"]["NO"]["cit"] . "</strong> (" . round(100 * $nationlists[$nidx]["continent"]["NO"]["cit"] / $nationlists[$nidx]["summary"]["total"]) . "%)</td>\r\n" . " <td><strong>" . $nationlists[$nidx]["continent"]["NO"]["res"] . "</strong> (" . round(100 * $nationlists[$nidx]["continent"]["NO"]["res"] / $nationlists[$nidx]["summary"]["total"]) . "%)</td>\r\n" . " <td><strong>" . $nationlists[$nidx]["continent"]["NO"]["phd"] . "</strong> (" . round(100 * $nationlists[$nidx]["continent"]["NO"]["phd"] / $nationlists[$nidx]["summary"]["total"]) . "%)</td>\r\n" . " </tr>\r\n"; } } $stdout .= " <tr>\r\n" . " <td><em>Total, selected campaigns</em></td>\r\n" . " <td class='total'><strong>" . $nationlists[0]["summary"]["total"] . "</strong></td>\r\n" . " <td class='total'><strong>" . $nationlists[0]["continent"]["NO"]["cit"] . "</strong> (" . round(100 * $nationlists[0]["continent"]["NO"]["cit"] / $nationlists[0]["summary"]["total"]) . "%)</td>\r\n" . " <td class='total'><strong>" . $nationlists[0]["continent"]["NO"]["res"] . "</strong> (" . round(100 * $nationlists[0]["continent"]["NO"]["res"] / $nationlists[0]["summary"]["total"]) . "%)</td>\r\n" . " <td class='total'><strong>" . $nationlists[0]["continent"]["NO"]["phd"] . "</strong> (" . round(100 * $nationlists[0]["continent"]["NO"]["phd"] / $nationlists[0]["summary"]["total"]) . "%)</td>\r\n" . " </tr>\r\n"; $stdout .= " </table>\r\n" . "\r\n"; } // end if // ------------------------ // By continent // ------------------------ if (!$showOnlyNordic) { $noinfo = $event["continent"][""]; $stdout .= ($stattype != "applicants" || $idx ? " <h4>By Region and Continent:</h4>\r\n" : " <h4>All applicants, by Region and Continent:</h4>\r\n") . $table_start; foreach ($aux["extConts"] as $cc => $item) { if (!empty($cc)) { $regular = "/(\\(except Nordic [^)]*\\))/iU"; $item = preg_replace($regular, "<span style='font-weight:normal;font-style:italic;color:#333;font-size:smaller;'>\\1</span>", $item); $stdout .= " <tr>\r\n" . " <th" . ($cc == "NO" ? " class='nordic'" : ($cc == "BA" ? " class='baltic'" : "")) . ">" . $item . "</th>\r\n"; foreach ($aux["extColumns"] as $col => $dummy) { if ($cc != "" || $col != "any") { $stdout .= !isset($event["continent"][$cc][$col]) ? " <td" . ($col == "any" ? " class='any'" : "") . "><strong>0</strong> (0%)</td>\r\n" : " <td" . ($col == "any" ? " class='any'" : "") . "><strong>" . ($event["continent"][$cc][$col] + 0) . "</strong> (" . number_format(100 * ($event["continent"][$cc][$col] + 0) / $event["summary"]["total"], $no_of_decimals) . "%)</td>\r\n"; } } $stdout .= " </tr>\r\n"; // Subtotal for Europe, listed just after "rest of Europe" line if ($cc == "EU") { $stdout .= " <tr>\r\n" . " <td class='europe'><em>Total Europe</em></th>\r\n"; foreach ($aux["extColumns"] as $col => $dummy) { $stdout .= !isset($event["continent"]["eur"][$col]) ? " <td" . ($col == "any" ? " class='any'" : "") . "><strong>0</strong> (0%)</td>" : " <td class='europe" . ($col == "any" ? " any" : "") . "'><strong>" . ($event["continent"]["eur"][$col] + 0) . "</strong> (" . number_format(100 * ($event["continent"]["eur"][$col] + 0) / $event["summary"]["total"], $no_of_decimals) . "%)</td>\r\n"; } $stdout .= " </tr>\r\n"; } // end subtotal europe } } // end foreach continent $stdout .= " <tr>\r\n" . " <td class='total'><em>Total</em></td>\r\n"; foreach ($aux["extColumns"] as $col => $dummy) { if ($col != "any") { $stdout .= !isset($event["continent"]["tot"][$col]) ? " <td class='total'><strong>0</strong> (0%)</td>\r\n" : " <td class='total'><strong>" . $event["continent"]["tot"][$col] . "</strong> (" . number_format(100 * ($event["continent"]["tot"][$col] + 0) / $event["summary"]["total"], $no_of_decimals) . "%)</td>\r\n"; } else { $stdout .= " <td class='total'> </td>\r\n"; } } $stdout .= " </tr>\r\n" . " <tr>\r\n" . " <td class='none'><em>No country information submitted</em></td>\r\n"; foreach ($aux["extColumns"] as $col => $dummy) { if ($col != "any") { $stdout .= !isset($noinfo[$col]) ? " <td class='none'><strong>0</strong> (0%)</td>\r\n" : " <td class='none'><strong>" . $noinfo[$col] . "</strong> (" . number_format(100 * ($noinfo[$col] + 0) / $event["summary"]["total"], $no_of_decimals) . "%)</td>\r\n"; } else { $stdout .= " <td class='none'> </td>\r\n"; } } $stdout .= " </tr>\r\n" . " </table>\r\n" . "\r\n"; } // end if // ------------------------ // By Continent - Piechart // ------------------------ if (!empty($charts) && !$showOnlyNordic) { if (true && $idx == 0 && $stattype == "applicants") { $stdout .= " <div>\r\n"; foreach ($charts[$idx] as $col => $chartData) { $stdout .= self::outputPiechart($idx . $col, $chartData, $aux["extColumns"][$col] . " - By Region and Continent", "370", "250", self::$palette["nbr"]); } $stdout .= " </div>\r\n"; } if (true && $idx == 0 && $stattype == "events") { $stdout .= " <div>\r\n"; foreach ($charts[$idx] as $col => $chartData) { $stdout .= self::outputPiechart($idx . $col, $chartData, $aux["extColumns"][$col] . " - By Country", "350", "250", self::$palette["nbr"]); } $stdout .= " </div>\r\n"; } } // end if // ------------------------ // By Country // ------------------------ $noinfo = isset($event["country"][""]) ? $event["country"][""] : array(); if (!$showOnlyNordic) { if ($stattype != "applicants" || $idx) { $stdout .= " <h4>By Country:</h4>\r\n"; } else { $stdout .= " <h4>All applicants, by Country:</h4>\r\n"; } } elseif (!$idx) { $stdout .= " <h4>Nordic applicants, by Country:</h4>\r\n"; } $stdout .= $table_start; foreach ($event["country"] as $cc => $dummy) { if (!empty($cc) && $cc != "tot" && (!$showOnlyNordic || functions::isInRegion("nordic", array($cc), FALSE))) { $stdout .= " <tr>\r\n" . " <th" . (!$showOnlyNordic && functions::isInRegion("nordic", array($cc), $countPolandAsBaltic) ? " class='nordic'" : (!$showOnlyNordic && functions::isInRegion("baltic", array($cc), $countPolandAsBaltic) ? " class='baltic'" : "")) . ">" . functions::fromCountryCodeTo("country", $cc, in_array("NO", $aux["conts"]) ? true : false, in_array("BA", $aux["conts"]) ? true : false) . "</th>\r\n"; foreach ($aux["extColumns"] as $col => $dummy) { if ($cc != "" || $col != "any") { $stdout .= !isset($event["country"][$cc][$col]) ? " <td><strong>0</strong> (0%)</td>\r\n" : " <td" . ($col == "any" ? " class='any'" : "") . "><strong>" . ($event["country"][$cc][$col] + 0) . "</strong> (" . number_format(100 * ($event["country"][$cc][$col] + 0) / $event["summary"]["total"], $no_of_decimals) . "%)</td>\r\n"; } } $stdout .= " </tr>\r\n"; if ($stattype == "events" && $cc == "SE") { $stdout .= " <tr>\r\n" . " <td style='text-indent:1em;white-space:nowrap;font-style:italic'>Stockholm</td>\r\n" . " <td style='text-indent:1em;white-space:nowrap;font-style:italic'>" . $event["country"]["local"][$col] . " (" . number_format(100 * ($event["country"]["local"][$col] + 0) / $event["summary"]["total"], $no_of_decimals) . "%)</td>\r\n" . " </tr>\r\n" . " <tr>\r\n" . " <td style='text-indent:1em;white-space:nowrap;font-style:italic'>non-locals</td>\r\n" . " <td style='text-indent:1em;white-space:nowrap;font-style:italic'>" . ($event["country"]["SE"][$col] - $event["country"]["local"][$col]) . " (" . number_format(100 * ($event["country"]["SE"][$col] - $event["country"]["local"][$col]) / $event["summary"]["total"], $no_of_decimals) . "%)</td>\r\n" . " </tr>\r\n"; } } } // end foreach country $stdout .= " <tr>\r\n" . " <td><em>Total Nordic countries</em></td>\r\n"; foreach ($aux["extColumns"] as $col => $dummy) { if ($col != "any") { if (!isset($event["country"]["tot"][$col])) { $stdout .= " <td class='total'><strong>0</strong> (0%)</td>\r\n"; } elseif (!$showOnlyNordic) { $stdout .= " <td class='total'><strong>" . $event["country"]["tot"][$col] . "</strong> (" . number_format(100 * ($event["country"]["tot"][$col] + 0) / $event["summary"]["total"], $no_of_decimals) . "%)</td>\r\n"; } else { $stdout .= " <td class='total'><strong>" . $event["continent"]["NO"][$col] . "</strong> (" . number_format(100 * ($event["continent"]["NO"][$col] + 0) / $event["summary"]["total"], $no_of_decimals) . "%)</td>\r\n"; } } else { $stdout .= " <td class='total'> </td>\r\n"; } } $stdout .= " </tr>\r\n" . " <tr>\r\n" . " <td class='none'><em>No country information submitted</em></td>\r\n"; foreach ($aux["extColumns"] as $col => $dummy) { if ($col != "any") { $stdout .= !isset($noinfo[$col]) ? " <td class='none'><strong>0</strong> (0%)</td>\r\n" : " <td class='none'><strong>" . $noinfo[$col] . "</strong> (" . number_format(100 * ($noinfo[$col] + 0) / $event["summary"]["total"], $no_of_decimals) . "%)</td>\r\n"; } else { $stdout .= " <td class='none'> </td>\r\n"; } } $stdout .= " </tr>\r\n" . " </table>\r\n" . "\r\n"; // ------------------------ $stdout .= " </div>\r\n" . "\r\n"; } } // end foreach ($show as $idx => $event) return $stdout; }
public function getVisitorData($stattype = "events", $distinguishNordic = FALSE, $distinguishBaltic = FALSE, $countPolandAsBaltic = FALSE, $onlyShowNordic = FALSE, $confids = array()) { $from_timestamp = "UNIX_TIMESTAMP('2007-01-01 00:00:00')"; $to_timestamp = "UNIX_TIMESTAMP()"; //$from_timestamp = "UNIX_TIMESTAMP('2009-01-01 00:00:00')"; //$to_timestamp = "UNIX_TIMESTAMP('2010-12-31 00:00:00')"; if (isset($confids[0])) { unset($confids[0]); } $where = $tmp = array(); if (in_array($stattype, array("visitors"))) { $where[] = "((" . $from_timestamp . "<V.v_start) AND (V.v_start<" . $to_timestamp . "))"; } if (!empty($confids)) { foreach ($confids as $id) { $tmp[] = "E.e_code='" . $id . "'"; } $where[] = implode(" OR ", $tmp); } $where[] = "V.v_status <> 'STATUS_NO'"; $sql = "\nSELECT\n A.av_firstname,\n A.av_lastname,\n A.av_residentship,\n A.av_city,\n A.av_institute,\n E.e_code,\n E.e_name,\n V.v_start,\n V.v_end,\n" . "\n V.v_type\nFROM\n abs_visits AS V\n LEFT JOIN zzz_avatars AS A ON A.av_id=V.v_avid\n LEFT JOIN abs_events AS E ON E.e_code=SUBSTRING(V.v_code,1,LENGTH(E.e_code)) " . (!empty($where) ? " WHERE (" . implode(") AND (", $where) . ") " : "") . " ORDER BY\n A.av_lastname,A.av_firstname,V.v_start"; // v_type: _COLL, _RENT, _PROG $res = $this->query($sql, IS_TESTSERVER); // includes a call to connect if (!$res || $this->num_rows($res) == 0) { return array(); } // ------------------------ // Convert search result to array of data type visitorDataRecord // $applicant[][lastname,firstname,citizenship,residentship,ms,phd, // cit_continent,res_continent,ms_continent,phd_continent, // nordic,baltic,event] // ------------------------ $applicant = array(); while ($cell = $this->next_record_assoc($res)) { switch ($stattype) { case "allguests": case "events": $select = !empty($cell["e_code"]) ? true : false; break; case "visitors": $select = $cell["v_type"] == "_COLL" ? true : false; break; case "brief": $select = !empty($cell["e_code"]) && $cell["v_type"] == "_COLL" ? true : false; break; default: return array(); } // end switch if ($select) { if (strlen($cell["av_residentship"]) > 2) { $cell["av_residentship"] = functions::fromCountryToCodeAdHoc($cell["av_residentship"]); } else { if ($cell["av_residentship"] == "SX") { $cell["av_residentship"] = "RS"; } } $applicant[] = array("lastname" => mb_convert_case($cell["av_lastname"], MB_CASE_TITLE, "UTF-8"), "firstname" => mb_convert_case($cell["av_firstname"], MB_CASE_TITLE, "UTF-8"), "institute" => $cell["av_institute"], "cit" => "", "res" => $cell["av_residentship"], "ms" => "", "phd" => "", "cit_continent" => "", "res_continent" => functions::fromCountryCodeTo("continentcode", $cell["av_residentship"], $distinguishNordic, $distinguishBaltic, $countPolandAsBaltic), "ms_continent" => "", "phd_continent" => "", "nordic" => functions::isInRegion("nordic", array($cell["av_residentship"]), $countPolandAsBaltic), "baltic" => functions::isInRegion("baltic", array($cell["av_residentship"]), $countPolandAsBaltic), "local" => strpos($cell["av_city"], "Stockholm") !== false ? 1 : 0, "id" => $cell["e_code"], "visit_start" => $cell["v_start"], "visit_end" => $cell["v_end"]); } // end if } // end while return $applicant; }
function getApplicantData($stattype = "applicants", $distinguishNordic = TRUE, $distinguishBaltic = TRUE, $countPolandAsBaltic = FALSE) { $applicant = array(); // ------------------------ // Read CSV file to array $this->applicantDataSource[line] // ------------------------ if (!$this->setApplicantDataSource()) { return array(); } //TODO: nicer error handling // ------------------------ // Convert raw data to array // $applicant[][lastname,firstname,citizenship,residentship,ms,phd, // cit_continent,res_continent,ms_continent,phd_continent, // nordic,baltic,campaign_id] // ------------------------ $idx = 0; foreach ($this->applicantDataSource as $line) { if (preg_match("/^.*--- (.*)/", trim($line), $res)) { $idx++; } elseif (!isset($GLOBALS["beenthere"]) || !$GLOBALS["beenthere"] || isset($GLOBALS["reset"]) || isset($GLOBALS["eventindex"][$idx])) { $arr = preg_split("/\\s?,\\s?/", str_Replace("??", "", $line)); if (count($arr) > 1) { $applicant[] = array("lastname" => mb_convert_case($arr[4], MB_CASE_TITLE, "UTF-8"), "firstname" => mb_convert_case($arr[5], MB_CASE_TITLE, "UTF-8"), "cit" => $arr[0], "res" => $arr[1], "ms" => $arr[2], "phd" => $arr[3], "cit_continent" => functions::fromCountryCodeTo("continentcode", $arr[0], $distinguishNordic, $distinguishBaltic, $countPolandAsBaltic), "res_continent" => functions::fromCountryCodeTo("continentcode", $arr[1], $distinguishNordic, $distinguishBaltic, $countPolandAsBaltic), "ms_continent" => functions::fromCountryCodeTo("continentcode", $arr[2], $distinguishNordic, $distinguishBaltic, $countPolandAsBaltic), "phd_continent" => functions::fromCountryCodeTo("continentcode", $arr[3], $distinguishNordic, $distinguishBaltic, $countPolandAsBaltic), "nordic" => functions::isInRegion("nordic", array($arr[0], $arr[1], $arr[2], $arr[3]), $countPolandAsBaltic), "baltic" => functions::isInRegion("baltic", array($arr[0], $arr[1], $arr[2], $arr[3]), $countPolandAsBaltic), "id" => $idx, "timestamp" => 0, "timestamp" => 0); } } } return $applicant; }