Exemplo n.º 1
0
 public static function OutputStatisticsNationality($stattype = "applicants", $distinguishNordic = TRUE, $distinguishBaltic = TRUE, $countPolandAsBaltic = FALSE, $showOnlyNordic = FALSE, $showSummary = FALSE)
 {
     //    if ($stattype=="visitors") return statistics::statisticsVisitors($stattype,$showOnlyNordic,$showSummary);
     if (!in_array($stattype, array("applicants", "events", "visitors", "allguests"))) {
         return "<p class='box error padding background bold'>Found no data to process</p>\r\n";
     }
     // ------------------------
     if (!class_exists("fromdb_jam", FALSE) || !isset($dbJam) || !is_object($dbJam)) {
         require_once PATH_CLASSES . "/fromdb/jam.php";
         $dbJam = new fromdb_jam();
     }
     if (!class_exists("fromdb_vm", FALSE) || !isset($dbVm) || !is_object($dbVm)) {
         require_once PATH_CLASSES . "/fromdb/vm.php";
         $dbVm = new fromdb_vm();
     }
     //TESTING JAM: if (in_array($stattype,array("applicants"))) $dbJam->getJamPositions();
     // ------------------------
     $stdout = "";
     $personData = array();
     $outdata = array();
     // ------------------------------------------------------------------------
     // AUXILIARY VARIABLES
     // ------------------------------------------------------------------------
     // ------------------------
     // -- Construct auxiliary arrays
     //      $aux["conts"]    = array (integer=>continentCode)
     //      $aux["extConts"] = array (continentCode=>label)
     // ------------------------
     if ($distinguishNordic) {
         $aux["conts"][] = "NO";
     }
     if ($distinguishBaltic) {
         $aux["conts"][] = "BA";
     }
     $aux["conts"] = array_merge($aux["conts"], array("EU", "NA", "AS", "AF", "SA", "OC", ""));
     foreach ($aux["conts"] as $cc) {
         $aux["extConts"][$cc] = functions::fromContinentCode($cc, $distinguishNordic, $distinguishBaltic, $countPolandAsBaltic);
     }
     // ------------------------------------------------------------------------
     // GPC WITH DEFAULT VALUES
     // ------------------------------------------------------------------------
     functions::gpc_declare_input("beenthere", false, true);
     functions::gpc_declare_input("all", false, true);
     functions::gpc_declare_input("reset", false, true);
     functions::gpc_declare_input("eventindex", self::getDefaultEvents($stattype), false);
     // if (in_array($stattype,array("allguests"))) {
     functions::gpc_declare_input("yearfrom", VM_START_YEAR, false);
     functions::gpc_declare_input("yearto", date("Y"), false);
     functions::gpc_declare_input("mindays", 1, false);
     // ------------------------------------------------------------------------
     // OBTAIN BASIC DATA
     //   --> visitorDataRecord $personData
     // ------------------------------------------------------------------------
     // -- When 'applicants' requested
     if (in_array($stattype, array("applicants"))) {
         $personData = $dbJam->getApplicantData($stattype, $distinguishNordic, $distinguishBaltic, $countPolandAsBaltic);
         $outdata["applicant"]["applicants"] = $personData;
     }
     // -- When 'events' requested
     if (in_array($stattype, array("events"))) {
         $personData = $dbVm->getVisitorData($stattype, $distinguishNordic, $distinguishBaltic, $countPolandAsBaltic, $showOnlyNordic, isset($GLOBALS["eventindex"]) ? array_keys($GLOBALS["eventindex"]) : array());
         $outdata["applicant"]["events"] = $personData;
     }
     // -- When 'visitors' requested
     if (in_array($stattype, array("visitors"))) {
         $personData = $dbVm->getVisitorData($stattype, true, true, false, $showOnlyNordic, array());
         $outdata["applicant"]["visitors"] = $personData;
     }
     // -- When 'allguests' requested
     if (in_array($stattype, array("allguests"))) {
         $participant = $dbVm->getVisitorData("events", $distinguishNordic, $distinguishBaltic, $countPolandAsBaltic, $showOnlyNordic, isset($GLOBALS["eventindex"]) ? array_keys($GLOBALS["eventindex"]) : array());
         $visitor = $dbVm->getVisitorData("visitors", $distinguishNordic, $distinguishBaltic, $countPolandAsBaltic, $showOnlyNordic, array());
         //      $outdata["applicant"][$stattype] = ...;
         $outdata = array_merge($outdata, $dbVm->participantStatistics("events", $distinguishNordic, $distinguishBaltic, $countPolandAsBaltic, $showOnlyNordic, isset($GLOBALS["eventindex"]) ? array_keys($GLOBALS["eventindex"]) : array()));
         // => $outdata["applicant"]["events"]
         //      foreach (self::$emptyEvents as $idx) if (isset(self::$eventTitles[$idx])) unset(self::$eventTitles[$idx]);
         //echo"<hr>";debug::rr(array_keys($outdata["applicant"]));
         //echo"<hr>";debug::rr(array_keys($outdata));
         $outdata1 = $dbVm->participantStatistics("visitors", $distinguishNordic, $distinguishBaltic, $countPolandAsBaltic, $showOnlyNordic, array());
         $outdata["applicant"]["allguests"] = $outdata["applicant"]["visitors"] = $outdata1["applicant"]["visitors"];
         //echo"<hr>";debug::rr(array_keys($outdata["applicant"]));
         $personData = $outdata["applicant"]["allguests"];
     }
     // -- Return if no data found
     if (empty($personData)) {
         return "          <p class='box error padding background bold'>Found no data to process</p>\r\n";
     }
     // ------------------------
     // --> self::$eventTitles
     // ------------------------
     if (in_array($stattype, array("applicants"))) {
         self::$eventTitles = $dbJam->getCampaigns();
     }
     if (in_array($stattype, array("events", "allguests"))) {
         self::$eventTitles = array("0" => "All " . (isset($_REQUEST["beenthere"]) ? "Selected " : "") . "Events") + $dbVm->getAllEventsTitles(mktime(0, 0, 0, 1, 1, 2009), time());
         foreach (self::$emptyEvents as $idx) {
             if (isset(self::$eventTitles[$idx])) {
                 unset(self::$eventTitles[$idx]);
             }
         }
     }
     //echo"<hr>";debug::rr(array_keys($outdata));
     //debug::rr(self::$eventTitles);
     // ------------------------
     // -- Construct auxiliary arrays
     //      $aux["columns"]
     //      $aux["extColumns"]
     // ------------------------
     switch ($stattype) {
         case "applicants":
             $showCols = array("cit", "res", "phd");
             break;
         case "events":
         case "allguests":
             $showCols = array("res");
             break;
         case "visitors":
             $showCols = array();
             break;
     }
     $aux["columns"] = array();
     foreach ($showCols as $col) {
         switch ($col) {
             case "cit":
                 $aux["columns"][$col] = "Citizens";
                 break;
             case "res":
                 $aux["columns"][$col] = "Residents";
                 break;
             case "ms":
                 $aux["columns"][$col] = "MS Degree";
                 break;
             case "phd":
                 $aux["columns"][$col] = "PhD Degree";
                 break;
         }
     }
     $aux["extColumns"] = $aux["columns"];
     if (in_array($stattype, array("applicants"))) {
         $aux["extColumns"]["any"] = "Any connection";
     }
     // ------------------------------------------------------------------------
     // CALCULATE STATISTICS (extracted from $personData)
     //   --> array $tables
     //   --> array $charts
     // ------------------------------------------------------------------------
     $tables = $charts = array();
     $maxbin = 100;
     if (in_array($stattype, array("visitors"))) {
         $tables["visitorsAlphabetical"] = self::calculateVisitors($personData, $GLOBALS["yearfrom"], $GLOBALS["yearto"], $GLOBALS["mindays"]);
         $tables["visitorsSummary"] = $showSummary ? self::calculateNordicVisitors(self::calculateVisitorsYear($personData), $GLOBALS["yearfrom"], $GLOBALS["yearto"], $GLOBALS["mindays"]) : array();
         $charts = self::calculateVisitorsCharts($tables["visitorsAlphabetical"], $maxbin);
     }
     if (in_array($stattype, array("applicants", "events"))) {
         $tables["nationlists"] = self::calculateNationLists($personData, $aux);
         $charts = self::calculateNationPies($tables["nationlists"], $aux);
     }
     if (in_array($stattype, array("allguests"))) {
         $tables["visitorsSummary"] = self::calculateNordicVisitors(self::calculateVisitorsYear($outdata["applicant"]["visitors"]), $GLOBALS["yearfrom"], $GLOBALS["yearto"], $GLOBALS["mindays"]);
         $tables["nationlists"] = self::calculateNationLists($personData, $aux);
     }
     // ------------------------------------------------------------------------
     // OUTPUT DATA
     // ------------------------------------------------------------------------
     // -- Output intro texts
     $stdout .= self::outputBlurb($stattype, $showSummary, $showOnlyNordic);
     // -- Output form
     if (in_array($stattype, array("applicants", "events", "allguests"))) {
         $stdout .= self::outputForm($stattype, in_array($stattype, array("applicants")) ? false : true);
     } elseif (in_array($stattype, array("visitors"))) {
         $stdout .= self::outputFormVisitors();
     }
     if ($GLOBALS["reset"]) {
         return $stdout;
     }
     // -- Output tables and charts
     if (in_array($stattype, array("visitors"))) {
         $totvisitors = isset($tables["visitorsSummary"][0]["tot"]) ? $tables["visitorsSummary"][0]["tot"] : 0;
         $stdout .= ($showSummary ? self::outputVisitorsSummary($tables["visitorsSummary"], $showOnlyNordic) : "") . self::outputChart("dataDays", $charts["dataDays"], $maxbin) . ($GLOBALS["mindays"] == 1 ? self::outputVisitorsAlphabeticalColumns($tables["visitorsAlphabetical"], $showOnlyNordic) : self::outputVisitorsAlphabeticalList($tables["visitorsAlphabetical"], $showOnlyNordic, $totvisitors, $GLOBALS["mindays"]));
     }
     if (in_array($stattype, array("applicants", "events", "allguests"))) {
         $stdout .= self::outputNationLists($stattype, $tables["nationlists"], $charts, $aux, $countPolandAsBaltic, $showOnlyNordic);
     }
     if (in_array($stattype, array("allguests"))) {
         $stdout .= self::outputVisitorsSummary($tables["visitorsSummary"], $showOnlyNordic);
     }
     return $stdout;
 }