Пример #1
0
 public static function dotName($name)
 {
     if (preg_match("/Hans(.*)Mühlen/", $name)) {
         return "hans.muhlen";
     }
     return functions::strip_accents(mb_strtolower(str_replace("ð", "d", str_replace(" ", ".", str_replace(" ", ".", str_replace("‑", ".", str_replace(".", "", $name)))))));
 }
Пример #2
0
 public static function getAlumniArrayData()
 {
     $userarray = array();
     // --------------------
     // DETERMINE SOURCE OF PEOPLE DATA
     // --> $GLOBALS["peopleClass"]
     // --------------------
     self::loadClass("ea");
     // ---------------------------------------------------------------------------
     // SELECT APPROPRIATE SQL QUERY
     // If $searchVariant='user', only the record for user $u is selected.
     // --> $sql
     // ---------------------------------------------------------------------------
     $sql = $GLOBALS["peopleClass"]->getSqlForEmployment();
     // --------------------
     // OBTAIN DATA FROM DATABASE
     // --> $userarray
     // --------------------
     $countryCodeArray = functions::countryCodeArray();
     $result = $GLOBALS["peopleClass"]->query($sql);
     if ($GLOBALS["peopleClass"]->num_rows($result) > 0) {
         while ($rec = $GLOBALS["peopleClass"]->next_record_assoc($result)) {
             if (!empty($rec["lm_option"])) {
                 $options = @unserialize(stripslashes($rec["lm_option"]));
                 if ($options) {
                     $rec = @array_merge($rec, $options);
                 }
             }
             if (!empty($rec["av_id"])) {
                 $udata = array();
                 // -----------------------------------
                 $udata["nw_firstname"] = isset($rec["av_firstname"]) ? $rec["av_firstname"] : "";
                 $udata["nw_lastname"] = isset($rec["av_lastname"]) ? $rec["av_lastname"] : "";
                 $udata["nw_fullname"] = str_replace(" ", " ", str_replace("-", "‑", $udata["nw_firstname"])) . " " . str_replace(" ", " ", str_replace("-", "‑", $udata["nw_lastname"]));
                 $udata["nw_fullname_reverse"] = str_replace(" ", " ", preg_replace("/" . (!empty($rec["av_von"]) ? $rec["av_von"] . "\\s*" : "") . "/i", "", str_replace("-", "‑", $udata["nw_lastname"]))) . ", " . str_replace(" ", " ", str_replace("-", "‑", $udata["nw_firstname"])) . (!empty($rec["av_von"]) ? " " . $rec["av_von"] : "");
                 $udata["nw_fullname_reverse_sortable"] = strtolower(functions::strip_accents($udata["nw_fullname_reverse"]));
                 $udata["nw_user"] = functions::dotName($udata["nw_fullname"]);
                 if (self::getSpecialDotname($udata["nw_user"])) {
                     $udata["nw_user"] = self::getSpecialDotname($udata["nw_user"]);
                 }
                 $udata["nw_current_institute"] = $rec["av_institute"];
                 $udata["nw_current_email"] = functions::obscurify_email($rec["av_email"]);
                 $udata["nw_deceased"] = !empty($rec["av_ddate"]) ? 1 : 0;
                 // -----------------------------------
                 // COLLECT DATA FROM OTHER SOURCES, IF NEEDED
                 // -----------------------------------
                 include PATH_DATA . "/adhoc_people_data.php";
                 // -----------------------------------
                 // SPECIAL EMPLOYMENT-RELATED FIELDS
                 // -----------------------------------
                 $em = array();
                 $em["nw_employment_status"] = $rec["um_status"];
                 $em["nw_employment_title"] = $rec["lm_value"];
                 $em["nw_employment_fromdate"] = $rec["lm_key"];
                 $em["nw_employment_todate"] = $rec["lm_status"];
                 if ($rec["lm_status"] <= date("Y-m-d")) {
                     $em["nw_employment_date"] = functions::readableDateInterval($rec["lm_key"], $rec["lm_status"]);
                     $em["nw_employment_current"] = 0;
                 } else {
                     $em["nw_employment_date"] = functions::readableDate($rec["lm_key"]) . " &#8212;&nbsp;";
                     $em["nw_employment_current"] = 1;
                 }
                 $em["nw_employment_inst"] = isset($options["e_inst"]) ? $options["e_inst"] : "";
                 if (isset($options["e_org"])) {
                     switch ($options["e_org"]) {
                         case MYPEAR_ORGID_NORDITA:
                             $em["nw_employment_inst"] = "Nordita";
                             $em["nw_employment_country"] = $em["nw_employment_fromdate"] >= date("2007-01-01") || in_array($rec["user"], array("yb", "brandenb", "jifalt", "uw", "divecchi")) ? "SE" : "DK";
                             break;
                         case MYPEAR_ORGID_FYSIKUM:
                             $em["nw_employment_inst"] = "Stockholm University";
                             $em["nw_employment_country"] = "SE";
                             break;
                         case MYPEAR_ORGID_ALBANOVA:
                             $em["nw_employment_inst"] = "AlbaNova";
                             $em["nw_employment_country"] = "SE";
                             break;
                         case MYPEAR_ORGID_KTH:
                             $em["nw_employment_inst"] = "KTH Royal Institute of Technology";
                             $em["nw_employment_country"] = "SE";
                             break;
                         case MYPEAR_ORGID_OKC:
                             $em["nw_employment_inst"] = "Oskar Klein Center";
                             $em["nw_employment_country"] = "SE";
                             break;
                     }
                 }
                 if (empty($em["nw_employment_country"])) {
                     $em["nw_employment_country"] = isset($options["e_cc"]) ? $options["e_cc"] : "";
                 }
                 if (isset($options["e_cc"]) && ($k = array_search($options["e_cc"], $countryCodeArray))) {
                     $em["nw_employment_country"] = $k;
                 }
                 $em["nw_employment_isnordic"] = functions::fromCountryCodeTo("continentcode", $em["nw_employment_country"], 1, 0, 0) == "NO" ? 1 : 0;
                 if (!empty($em["nw_employment_title"])) {
                     $em["nw_employment_type"] = self::getEmploymentTypeFromTitle($em["nw_employment_title"]);
                 } elseif (!empty($options["e_rate"])) {
                     $em["nw_employment_type"] = $options["e_rate"];
                 } elseif (!empty($udata["nw_employeeType"])) {
                     $em["nw_employment_type"] = $udata["nw_employeeType"];
                 } else {
                     $em["nw_employment_type"] = "";
                 }
                 //TODO: often inconclusive
                 $em["nw_employment_gid"] = isset($options["e_gid"]) ? $options["e_gid"] : "";
                 if (stripos($em["nw_employment_inst"], "nordita") !== FALSE && stripos($em["nw_employment_title"], "board") === FALSE) {
                     $em["nw_employment_isnorditaemployment"] = 1;
                 } else {
                     $em["nw_employment_isnorditaemployment"] = 0;
                 }
                 // -----------------------------------
                 $key = $udata["nw_fullname_reverse_sortable"];
                 if (empty($udata["nw_fullname_reverse_sortable"])) {
                     $key = $udata["av_id"];
                 }
                 if (!isset($userarray[$key])) {
                     $userarray[$key] = $udata;
                 }
                 $userarray[$key]["employment"][$em["nw_employment_fromdate"] . "-" . $rec["lm_id"]] = $em;
                 // -----------------------------------
                 if ($em["nw_employment_isnorditaemployment"]) {
                     $userarray[$key]["nw_isnorditaalumn"] = 1;
                     if ($em["nw_employment_current"]) {
                         $userarray[$key]["nw_current_isnorditastaff"] = 1;
                     }
                 }
                 if (0 && IS_TESTSERVER) {
                     echo "<hr>" . $udata["nw_fullname"];
                     echo "<br>Current: " . $udata["nw_current_institute"];
                     foreach ($userarray[$key]["employment"] as $e) {
                         if ($e["nw_employment_current"]) {
                             echo "<br>* " . $e["nw_employment_title"] . ", " . $e["nw_employment_inst"];
                         }
                     }
                     echo "<br>TYPE = " . $e["nw_employment_type"];
                     echo "<br>GUESS: " . self::getEmploymentTypeFromTitle($em["nw_employment_title"]);
                     debug::rr($rec);
                     debug::rr($options);
                     debug::rr($em);
                     debug::rr($udata);
                 }
             }
             // end if
         }
     }
     // end while $rec
     ksort($userarray);
     foreach ($userarray as $key => $udata) {
         $ct = $cc = array();
         $ci = explode(",", $userarray[$key]["nw_current_institute"]);
         $userarray[$key]["nw_current_isnordic"] = 0;
         $userarray[$key]["nw_isnorditaalumn"] = 0;
         if (!isset($udata["nw_current_isnorditastaff"])) {
             $userarray[$key]["nw_current_isnorditastaff"] = 0;
         }
         foreach ($udata["employment"] as $item) {
             if ($item["nw_employment_current"] && stripos($item["nw_employment_title"], "board") === FALSE) {
                 foreach (explode(",", $item["nw_employment_inst"]) as $ins) {
                     if (!empty($ins) && array_search(trim($ins), $ci) === false) {
                         $ci[] = $ins;
                     }
                 }
                 $ct[] = $item["nw_employment_title"];
                 $cc[] = $item["nw_employment_country"];
                 if ($item["nw_employment_isnordic"]) {
                     $userarray[$key]["nw_current_isnordic"] = 1;
                 }
             }
             if ($item["nw_employment_isnorditaemployment"]) {
                 $userarray[$key]["nw_isnorditaalumn"] = 1;
             }
         }
         $userarray[$key]["nw_current_title"] = implode(", ", array_unique($ct));
         $userarray[$key]["nw_current_institute"] = implode(", ", array_unique($ci));
         $userarray[$key]["nw_current_country"] = implode(", ", array_unique($cc));
         $e = $udata["employment"];
         ksort($e);
         $userarray[$key]["nw_nordita_employment"] = $e;
         unset($userarray[$key]["employment"]);
         if ($udata["nw_deceased"]) {
             $userarray[$key]["nw_current_institute"] = "";
             $userarray[$key]["nw_current_email"] = "";
             $userarray[$key]["nw_current_isnordic"] = "";
             $userarray[$key]["nw_current_isnorditastaff"] = "";
             $userarray[$key]["nw_current_title"] = "";
             $userarray[$key]["nw_current_country"] = "";
         }
     }
     // end foreach
     // --------------------
     if (0 && IS_TESTSERVER) {
         debug::rr($userarray);
     }
     return $userarray;
 }
Пример #3
0
 public static function getAllValidUsers($ownerUid = 0)
 {
     $users = $uids = array();
     // -- In the unexpected event that the user with UID=$ownerUid cannot be found in the usual ways
     $dummyOwnerRecord = array("name" => "dummy", "uid" => $ownerUid, "gecos" => "uid=" . $ownerUid);
     // -- Fetch special users from local DB
     foreach (auth::getSpecialUsers(TRUE) as $row) {
         $users[strtolower(functions::strip_accents($row["gecos"]))] = array("name" => $row["name"], "uid" => $row["uid"], "gecos" => $row["gecos"]);
         $uids[$row["uid"]] = 1;
     }
     // -- Fetch active users from EA
     foreach (people::getPeopleArray("all") as $row) {
         $name = "";
         $row["nw_fullname"] = functions::utf8encode($row["nw_fullname"]);
         // Use SU usernames before trying KTH usernames
         if (!empty($row["nw_acc_su"])) {
             $name = $row["nw_acc_su"];
         } elseif (!empty($row["nw_acc_kth"])) {
             $name = $row["nw_acc_kth"];
         }
         // Get UID from local passwd file
         $u = posix_getpwnam($name);
         if (!empty($u["uid"]) && !preg_match("/20[0-9][0-9]/i", $name)) {
             // Not sure what the YYYY test is for
             $users[strtolower(functions::strip_accents($row["nw_fullname"]))] = array("name" => $name, "uid" => $u["uid"], "gecos" => $row["nw_fullname"]);
             $uids[$u["uid"]] = 1;
         }
     }
     if (!empty($ownerUid) && !in_array($ownerUid, array_keys($uids))) {
         $users["~~owner"] = $dummyOwnerRecord;
     }
     ksort($users);
     return $users;
 }
Пример #4
0
 public static function OutputEventSlidesfromtalks()
 {
     $stdout = $code = "";
     $eventShortname = $shortname = $oneEventContributions = $contributions = $roomsArray = array();
     // ------------------------------------------------------------------------
     // Output drop-down list
     // ------------------------------------------------------------------------
     $stdout .= event::outputEventDropdown(array(), "timetable");
     // ------------------------------------------------------------------------
     if (!isset($_REQUEST["confid"]) || empty($_REQUEST["confid"])) {
         return $stdout;
     }
     // ------------------------------------------------------------------------
     // GPC
     // ------------------------------------------------------------------------
     // Must be after call to event::outputEventDropdown() where $GLOBALS["confid"] is set.
     if (!isset($GLOBALS["confid"])) {
         functions::gpc_declare_input("confid", array(), false);
     }
     if (!empty($GLOBALS["confid"])) {
         $confidArray = is_array($GLOBALS["confid"]) ? $GLOBALS["confid"] : array($GLOBALS["confid"]);
     }
     // ------------------------------------------------------------------------
     // Obtain data
     // ------------------------------------------------------------------------
     foreach ($confidArray as $confid) {
         $eventShortname[$confid] = $GLOBALS["documentClass"]->getPathFromAgendaId($confid);
         $oneEventContributions[$confid] = functions::callMethod('fromdb_nwevents', 'fromdb/nwevents', 'getEventContributions', $confid);
     }
     // end foreach
     $shortname = current($eventShortname);
     // Merge all talks to one array
     foreach ($oneEventContributions as $confid => $records) {
         foreach ($records as $datetime => $event) {
             $title = $speaker = $affiliation = $sortname = "";
             if (isset($event["title_plain"])) {
                 $title = $event["title_plain"];
             }
             if (isset($event["speakers"])) {
                 $s = current($event["speakers"]);
                 if (isset($s["nw_fullname"])) {
                     $speaker = $s["nw_fullname"];
                 }
                 if (isset($s["av_institute"])) {
                     $affiliation = $s["av_institute"];
                 }
             }
             $n = explode(" ", $speaker);
             if (is_array($n)) {
                 $sortname = strtolower(functions::strip_accents(array_pop($n)));
             }
             if (!empty($title) && !empty($speaker)) {
                 $contributions[$sortname] = array("title" => $title, "speaker" => $speaker);
             }
         }
     }
     ksort($contributions);
     // ------------------------------------------------------------------------
     // Output data
     // ------------------------------------------------------------------------
     $code .= "<h2 class='title'>SLIDES FROM TALKS</h2>\r\n" . "\r\n" . (empty($contributions) ? "<h4>Slides from talks will be published here later</h4>\r\n\r\n" : "") . "<ul>\r\n" . "\r\n";
     foreach ($contributions as $sortname => $data) {
         if (count(explode(" ", $data["speaker"])) > 2) {
             $code .= "<!-- *** check name sort order and file name *** -->\r\n";
         }
         $code .= "<!--li style='margin-bottom: 1em;'>\r\n" . "<p><strong>" . $data["speaker"] . "</strong>\r\n" . "<br>\"" . $data["title"] . "\"\r\n" . "<br><a href='http://www.nordita.org/docs/agenda/slides-" . $shortname . "-" . $sortname . ".pdf' style='font-weight: bold;'>Slides</a> (PDF)</p>\r\n" . "</li-->\r\n" . "\r\n";
     }
     // end foreach
     $code .= "</ul>\r\n" . "\r\n";
     // ----------------------------
     return $stdout . "<pre>" . htmlspecialchars($code) . "</pre>";
 }
Пример #5
0
 function adaptRawUserArray($userarray = array(), $status = "active")
 {
     if (empty($userarray)) {
         return array();
     }
     // ------------------------------------------
     // MASSAGE DATA IN ARRAY $userarray
     // ------------------------------------------
     //if (IS_TESTSERVER) debug::rr($userarray);
     foreach ($userarray as $usr => $udata) {
         // -----------------------------------
         // -- Not every user has a value for these fields:
         // -----------------------------------
         foreach (array("e_gid", "e_inst", "e_off", "e_org", "e_rate", "e_type") as $key) {
             if (!isset($udata[$key])) {
                 $udata[$key] = "";
             }
         }
         // -----------------------------------
         // -- Rename field nw_firstname
         // -- Rename field nw_lastname
         // -----------------------------------
         // nw_firstname in maildb: "name"
         // nw_lastname in maildb: "namefam"
         $udata["nw_firstname"] = isset($udata["av_firstname"]) ? $udata["av_firstname"] : "";
         $udata["nw_lastname"] = isset($udata["av_lastname"]) ? $udata["av_lastname"] : "";
         // -----------------------------------
         // -- Create field nw_namevon = von
         // -- Create field nw_vonnamefam = von lastname
         // -- Create field nw_fullname = firstname von lastname
         // -- Create field nw_fullname_break = firstname<br>von lastname
         // -- Create field nw_fullname_reverse = lastname, firstname von
         // -- Create field nw_dotname = firstname.von.lastname
         // -----------------------------------
         // nw_namevon in maildb: "von"
         $udata["nw_namevon"] = $udata["av_von"];
         $udata["nw_vonnamefam"] = trim($udata["av_von"] . " " . $udata["nw_lastname"]);
         $udata["nw_fullname"] = str_replace(" ", "&nbsp;", str_replace("-", "&#8209;", $udata["nw_firstname"])) . "&nbsp;" . (!empty($udata["av_von"]) ? $udata["av_von"] . "&nbsp;" : "") . str_replace(" ", "&nbsp;", str_replace("-", "&#8209;", $udata["nw_lastname"]));
         $udata["nw_fullname_break"] = str_replace(" ", "&nbsp;", str_replace("-", "&#8209;", $udata["nw_firstname"])) . "<br>" . (!empty($udata["av_von"]) ? $udata["av_von"] . " " : "") . str_replace(" ", "&nbsp;", str_replace("-", "&#8209;", $udata["nw_lastname"]));
         $udata["nw_fullname_reverse"] = str_replace(" ", "&nbsp;", preg_replace("/" . (!empty($udata["nw_namevon"]) ? $udata["nw_namevon"] . "\\s*" : "") . "/i", "", str_replace("-", "&#8209;", $udata["nw_lastname"]))) . ",&nbsp;" . str_replace(" ", "&nbsp;", str_replace("-", "&#8209;", $udata["nw_firstname"])) . (!empty($udata["nw_namevon"]) ? "&nbsp;" . $udata["nw_namevon"] : "");
         $udata["nw_fullname_reverse_sortable"] = strtolower(functions::strip_accents($udata["nw_fullname_reverse"]));
         $udata["nw_dotname"] = functions::dotName($udata["nw_fullname"]);
         if (functions::callMethod('people', 'lib/people', 'getSpecialDotname', $udata["nw_dotname"])) {
             $udata["nw_dotname"] = functions::callMethod('people', 'lib/people', 'getSpecialDotname', $udata["nw_dotname"]);
         }
         // -----------------------------------
         // -- Rename field nw_user
         // -----------------------------------
         // In maildb: "user"
         // NB. Can't use field 'av_identity' since it is a comma-separated list of
         //     various usernames of unknown origin
         $udata["nw_user"] = $udata["nw_dotname"];
         // -----------------------------------
         // -- Rename field nw_id_ea
         // -- Rename field nw_id_maildb
         // -----------------------------------
         // ID in maildb: "m_id"
         // ID in ea:     "av_id"
         $udata["nw_id_ea"] = isset($udata["av_id"]) ? $udata["av_id"] : "";
         $udata["nw_id_maildb"] = isset($udata["m_id"]) ? $udata["m_id"] : "";
         // -----------------------------------
         // -- Rename field nw_localinstitute
         // -----------------------------------
         // In maildb: "institution"
         //TODO: 'av_institute' not reliable!
         $udata["nw_localinstitute"] = isset($udata["av_institute"]) ? strtolower($udata["av_institute"]) : "";
         $ins = explode(",", $udata["nw_localinstitute"]);
         $insAll = array();
         foreach ($ins as $item) {
             switch ($item) {
                 case "nordita":
                     $insAll[] = "NOR";
                     break;
                 case "fysikum":
                     $insAll[] = "FKM";
                     break;
                 case "albanova":
                     $insAll[] = "ALB";
                     break;
                 case "vetenskapens hus":
                 case "vetenskapenshus":
                     $insAll[] = "VH";
                     break;
             }
         }
         $udata["nw_localinstitute"] = join(",", $insAll);
         // -----------------------------------
         // -- Rename field nw_institute
         // -----------------------------------
         // In maildb: ~"institution"
         $udata["nw_institute"] = isset($udata["av_institute"]) ? ucfirst($udata["av_institute"]) : "";
         // -----------------------------------
         // -- Rename field nw_ssn
         // -----------------------------------
         // In maildb: "pers_number"
         $udata["nw_ssn"] = isset($udata["av_ssn"]) ? $udata["av_ssn"] : "";
         // -----------------------------------
         // -- Rename field nw_birthdate
         // -- Create field nw_birthday
         // -----------------------------------
         // NB: 'av_birthdate' is a timestamp, 'nw_birthdate' is a date YYYY-MM-DD
         if (!empty($udata["av_birthdate"]) && abs($udata["av_birthdate"]) > date("Y")) {
             // must be a timestamp, not a year
             $udata["nw_birthdate"] = date("Y-m-d", $udata["av_birthdate"]);
         } elseif (!empty($udata["nw_ssn"]) && preg_match("/^(\\d\\d)(\\d\\d)(\\d\\d)/", $udata["nw_ssn"], $pn) && $pn[1] != "00") {
             $udata["nw_birthdate"] = ($pn[1] > date("y") + 10 ? "19" : "20") . $pn[1] . "-" . $pn[2] . "-" . $pn[3];
         } else {
             $udata["nw_birthdate"] = "";
         }
         // In maildb: N/A
         $udata["nw_birthday"] = !empty($udata["nw_birthdate"]) && ($t = strtotime($udata["nw_birthdate"])) ? date("m-d", $t) : "";
         // -----------------------------------
         // -- Rename field nw_office
         // -----------------------------------
         // In maildb: "office"
         $udata["nw_office"] = isset($udata["e_off"]) ? $udata["e_off"] : "";
         // -----------------------------------
         // -- Create field nw_leaveofabsence, nw_notyetarrived
         //    (call after nw_office)
         // -----------------------------------
         if (!isset($udata["nw_leaveofabsence"])) {
             $udata["nw_leaveofabsence"] = "";
             if (strpos(mb_strtolower($udata["nw_office"]), "leave of absence") !== false || strpos(mb_strtolower($udata["nw_office"]), "on leave") !== false) {
                 $udata["nw_leaveofabsence"] = "On leave of absence";
             } elseif (strpos($udata["nw_office"], "from") !== false || strpos($udata["nw_office"], "Arrives") !== false || strpos($udata["nw_office"], "arrives") !== false) {
                 $udata["nw_leaveofabsence"] = $udata["nw_notyetarrived"] = $udata["nw_office"];
             }
         }
         if (!empty($udata["nw_leaveofabsence"])) {
             $udata["nw_office"] = "";
         }
         // -----------------------------------
         // -- Create field nw_acc_kth
         // -- Create field nw_acc_su
         // -- Create field nw_acc_nbi
         // -- Create field nw_acc_maildb
         // -----------------------------------
         $udata["nw_acc_kth"] = isset($udata["acc_kth"]) ? $udata["acc_kth"] : "";
         // In maildb: "acc_kth"
         $udata["nw_acc_su"] = isset($udata["acc_su"]) ? $udata["acc_su"] : "";
         // In maildb: "acc_su"
         $udata["nw_acc_nbi"] = !empty($udata["maildrop"]) && preg_match("/([^@]*)\\@(.*).dk/", $udata["maildrop"], $res) ? $res[1] : "";
         //	  $udata["nw_acc_nbi"] = (isset($udata["acc_nbi"])) ? $udata["acc_nbi"] : "";
         //      $udata["nw_acc_nbi"] = (!empty($udata["av_email"]) // Use "av_email" and "av_email2", not "nw_email"
         //                              && preg_match("/^(.+)@nbi.dk$/i",$udata["av_email"],$nbi))
         //		? $nbi[1]
         //		: "";
         // In maildb: "cmt" and "maildrop"
         $udata["nw_acc_maildb"] = isset($udata["user"]) ? $udata["user"] : "";
         //	  $udata["nw_acc_maildb"] = (isset($udata["av_identity"])) ? $udata["av_identity"] : "";
         // In maildb: "user"
         // -----------------------------------
         // -- Rename field nw_phone
         // -- Create field nw_extension
         // -- Create field nw_phone_linked
         //    (call after nw_notyetarrived)
         // -----------------------------------
         $udata["nw_phone"] = isset($udata["av_phone"]) ? $udata["av_phone"] : "";
         // In maildb: "phone"
         $udata["nw_extension"] = "";
         if ($udata["nw_phone"] == "0000") {
             $udata["nw_phone"] = "";
         } else {
             $udata["nw_phone"] = preg_replace("/ (..) (..)/", " \\1\\2", $udata["nw_phone"]);
             $udata["nw_phone"] = trim(str_replace("&nbsp;", " ", $udata["nw_phone"]));
             if (strlen($udata["nw_phone"]) == 4) {
                 $udata["nw_extension"] = $udata["nw_phone"];
                 $udata["nw_phone"] = "+46&nbsp;8&nbsp;5537&nbsp;<strong>" . $udata["nw_phone"] . "</strong>";
             } elseif (preg_match("/46[\\D]*8[\\D]*5537[\\D]*(\\d\\d\\d\\d)/", $udata["nw_phone"], $res)) {
                 $udata["nw_extension"] = $res[1];
                 $udata["nw_phone"] = "+46&nbsp;8&nbsp;5537&nbsp;<strong>" . $res[1] . "</strong>";
             } elseif (preg_match("/46[\\D]*8[\\D]*16[\\D]*(\\d\\d\\d\\d)/", $udata["nw_phone"], $res)) {
                 $udata["nw_extension"] = $res[1];
                 $udata["nw_phone"] = "+46&nbsp;8&nbsp;16&nbsp;<strong>" . $res[1] . "</strong>";
             } elseif (preg_match("/46[\\D]*8[\\D]*674[\\D]*(\\d\\d\\d\\d)/", $udata["nw_phone"], $res)) {
                 $udata["nw_extension"] = $res[1];
                 $udata["nw_phone"] = "+46&nbsp;8&nbsp;674&nbsp;<strong>" . $res[1] . "</strong>";
             }
             $udata["nw_phone"] = str_replace(" ", "&nbsp;", $udata["nw_phone"]);
         }
         $phonestring = substr($udata["nw_phone"], 0, 1) == "+" ? str_replace("&nbsp;", "", str_replace(" ", "", str_replace("-", "", strip_tags($udata["nw_phone"])))) : "";
         $udata["nw_phone_linked"] = !empty($phonestring) ? "<a href='tel:" . $phonestring . "'>" . $udata["nw_phone"] . "</a>" : $udata["nw_phone"];
         if (!empty($udata["nw_notyetarrived"])) {
             $udata["nw_phone"] = "";
             $udata["nw_extension"] = "";
             $udata["nw_phone_linked"] = "";
         }
         // -----------------------------------
         // -- Create field nw_city
         //    (after nw_phone)
         // -----------------------------------
         $udata["nw_city"] = strpos($udata["nw_phone"], "+45") !== false ? "Copenhagen" : "Stockholm";
         // Also in ea: "av_residentship"
         // -----------------------------------
         // -- Create field nw_fax
         //    (after nw_phone)
         // -----------------------------------
         $udata["nw_fax"] = strpos($udata["nw_phone"], "+45") !== false ? FAX_COPENHAGEN_EXT : FAX_STOCKHOLM_EXT;
         // -----------------------------------
         // -- Create field nw_building
         //    (call after 'nw_city' and 'nw_leaveofabsence')
         // -----------------------------------
         if ($udata["nw_city"] == "Copenhagen") {
             $udata["nw_building"] = "dk";
             // "NBI (Copenhagen)"
         } elseif (preg_match("/^13/i", $udata["nw_office"], $res)) {
             $udata["nw_building"] = "13";
             // "Nordita East Building"
         } elseif (preg_match("/^12/i", $udata["nw_office"], $res)) {
             $udata["nw_building"] = "12";
             // "Nordita West Building"
         } elseif (preg_match("/^11/i", $udata["nw_office"], $res)) {
             $udata["nw_building"] = "11";
             // "Nordita South Building"
         } elseif (preg_match("/^A5/i", $udata["nw_office"], $res)) {
             $udata["nw_building"] = "an";
             // "AlbaNova Main Building"
         } else {
             $udata["nw_building"] = "";
         }
         // -----------------------------------
         // -- Create field nw_email
         // -- Create field nw_email_plain
         //    (call after nw_notyetarrived)
         // -----------------------------------
         // These fields exist but are not set for all users:
         // In ea: "av_email"
         // In maildb: "m_email" or "maildrop", see also "forward"
         // First check if people::$specialmail contains special instructions
         $smail = functions::callMethod('people', 'lib/people', 'getSpecialMail', $udata["nw_user"]);
         $udata["nw_email_plain"] = "";
         if ($smail !== false) {
             $udata["nw_email_plain"] = $smail;
         } elseif (empty($udata["nw_notyetarrived"])) {
             $udata["nw_email_plain"] = $udata["nw_user"] . "@" . MAIL_DOMAIN;
         }
         $udata["nw_email"] = functions::obscurify_email($udata["nw_email_plain"]);
         // -----------------------------------
         // -- Rename field nw_gid
         // -- Create field nw_group
         // -- Create field nw_groupShort
         // -----------------------------------
         // in ea: "e_gid"
         // In maildb: "groupid"
         $udata["nw_group"] = $udata["nw_groupShort"] = $udata["nw_gid"] = "";
         if (!empty($udata["e_gid"])) {
             $gridtmp = explode(",", $udata["e_gid"]);
             unset($grid);
             unset($gid);
             foreach ($gridtmp as $k => $v) {
                 $v = trim($v);
                 if ($v == "grund") {
                     $v = "adm";
                 }
                 if ($v == "admin") {
                     $v = "adm";
                 }
                 $gid[] = $v;
                 if (isset($this->researchGroups[$v])) {
                     $grid[] = $this->researchGroups[$v];
                 }
             }
             $udata["nw_group"] = isset($grid) && is_array($grid) ? implode("; ", $grid) : "";
             $udata["nw_groupShort"] = str_replace("Statistical ", "Stat.&nbsp;", str_replace("Condensed ", "Cond.&nbsp;", $udata["nw_group"]));
             $udata["nw_gid"] = is_array($gid) ? implode(",", $gid) : "";
             $udata["nw_gid"] = preg_replace("/^,/", "", preg_replace("/,\$/", "", str_replace(",,", ",", str_replace("kof", "", str_replace("BIO", "CM", str_replace("MA", "SA", str_replace("NP", "SA", str_replace("HP", "SA", $udata["nw_gid"]))))))));
         }
         // -----------------------------------
         // -- Rename field nw_employmentStart
         // -- Rename field nw_employmentEnd
         // -- Create field nw_employmentPeriod
         // -----------------------------------
         $udata["nw_employmentStart"] = isset($udata["lm_key"]) ? $udata["lm_key"] : "";
         $udata["nw_employmentEnd"] = isset($udata["lm_status"]) ? $udata["lm_status"] : "";
         // In maildb: "norPeriodOfStay"
         if ($udata["nw_employmentEnd"] > date("Y-m-d", mktime(0, 0, 0, 1, 1, date("Y") + 15))) {
             $udata["nw_employmentEnd"] = "";
         }
         $udata["nw_employmentPeriod"] = functions::readableDateInterval($udata["nw_employmentStart"], $udata["nw_employmentEnd"], 1);
         // -----------------------------------
         // -- Create field nw_status
         // -----------------------------------
         // In maildb: "status"
         //TODO:
         $udata["nw_status"] = date("Y-m-d") <= $udata["nw_employmentEnd"] || empty($udata["nw_employmentEnd"]) ? "Active" : "Passive";
         // -----------------------------------
         // -- Rename field nw_employeeTitle
         // -----------------------------------
         $udata["nw_employeeTitle"] = mb_strtolower($udata["lm_value"]);
         // In maildb: "employeeTitle"
         // Also in ea: "av_salutation"
         // 'lm_data' can be of the form "professor / professor emeritus", concatenating all
         // positions held by the user at Nordita over time.
         if (preg_match("#/\\S*([^/]*\\S*em[ei]rit[aus]*)\\S*/?#i", $udata["nw_employeeTitle"], $res)) {
             $udata["nw_employeeTitle"] = trim($res[1]);
         }
         $udata["nw_employeeTitle"] = preg_replace("#deputy director / professor#", "professor, deputy director", $udata["nw_employeeTitle"]);
         $udata["nw_employeeTitle"] = preg_replace("#visiting professor,professor#", "visiting professor", $udata["nw_employeeTitle"]);
         $udata["nw_employeeTitle"] = preg_replace("#phd student,associate phd student#", "associate phd student", $udata["nw_employeeTitle"]);
         if (strpos($udata["nw_employeeTitle"], "/") !== false) {
             $tmp = explode("/", $udata["nw_employeeTitle"]);
             $udata["nw_employeeTitle"] = trim(array_pop($tmp));
         }
         // Cleanup of some exact string matches
         if ($udata["nw_employeeTitle"] == "fellow") {
             $udata["nw_employeeTitle"] = "nordita&nbsp;fellow";
         } elseif (in_array($udata["nw_employeeTitle"], array("vice director", "deputy director"))) {
             $udata["nw_employeeTitle"] = "professor, deputy director";
         } elseif ($udata["nw_employeeTitle"] == "director") {
             $udata["nw_employeeTitle"] = "professor, director";
         }
         $etArray = explode(",", $udata["nw_employeeTitle"]);
         foreach ($etArray as $key => $title) {
             $title = trim($title);
             $etArray[$key] = ucfirst(str_ireplace("emiritus", "emeritus", str_ireplace("nordita", "Nordita", str_ireplace(" ", "&nbsp;", str_ireplace("postdoctoral fellow", "postdoc", str_ireplace("postdoctoral researcher", "postdoc", str_ireplace("prof.", "professor", str_ireplace("phd", "PhD", str_ireplace("Visiting professor, Professor", "Visiting professor", str_ireplace("Hr officer", "HR officer", str_ireplace("Professor / ", "", str_ireplace("Ass.professor / ", "", $title))))))))))));
         }
         $udata["nw_employeeTitle"] = join(", ", $etArray);
         // -----------------------------------
         // -- Create field nw_employeeTitleShort
         // -----------------------------------
         $udata["nw_employeeTitleShort"] = str_ireplace("Assistant", "Asst.", str_ireplace("Professor&nbsp;emeritus", "Prof.&nbsp;emer.", str_ireplace("Director&nbsp;emeritus", "Director.&nbsp;emer.", preg_replace("/ssociate[d]?/", "ssoc.", str_replace("orresponding", "orresp.", str_replace("ostdoctoral", "ostdoct.", str_replace("eputy", "ep.", str_replace("coordinator", "coord.", $udata["nw_employeeTitle"]))))))));
         // -----------------------------------
         // -- Rename field nw_employeeType
         //    ["faculty"|"fellows"|"visitors"|"postgrads"|"admin"]
         //    After setting of "nw_employeeTitle"
         // -----------------------------------
         $udata["nw_employeeType"] = functions::callMethod('people', 'lib/people', 'getEmploymentTypeFromTitle', $udata["nw_employeeTitle"]);
         if (empty($udata["nw_employeeType"])) {
             $udata["nw_employeeType"] = isset($udata["e_rate"]) ? $udata["e_rate"] : "";
             // In maildb: "employeeType"
             // In ea: "lm_value"
             if ($udata["um_status"] == "v") {
                 $udata["nw_employeeType"] = "visitors";
             }
         }
         // -----------------------------------
         // -- Create field nw_employeeTitleGrp
         // -----------------------------------
         if (!class_exists("people", FALSE)) {
             require_once PATH_CLASSES . "/lib/people.php";
         }
         $udata["nw_employeeTitleGrp"] = isset(people::$fieldnames[$udata["nw_employeeType"]]) ? people::$fieldnames[$udata["nw_employeeType"]] : "";
         /*
               $grpArray = array();
               foreach ($etArray as $key => $title) {
         
                 switch (str_replace("&nbsp;"," ",mb_strtolower($title))) {
                   case "professor":
                   case "professor emeritus":
                   case "visiting professor":
                   case "corresponding professor":
                   case "associate professor":
                     $grpArray["Professors"] = 1;
                     if (empty($udata["nw_employeeType"])) $udata["nw_employeeType"] = "faculty";
                     break;
                   case "assistant professor":
                   case "visiting assistant professor":
                   case "corresponding assistant professor":
                   case "associate assistant professor":
                   case "senior lecturer":
                   case "visiting senior lecturer":
                   case "corresponding senior lecturer":
                   case "associate senior lecturer":
                     $grpArray["Assistant Professors"] = 1;
                     if (empty($udata["nw_employeeType"])) $udata["nw_employeeType"] = "faculty";
                     break;
                   case "fellow":
                   case "nordita fellow":
                   case "postdoc":
                   case "postdoctoral fellow":
                   case "visiting fellow":
                   case "visiting postdoc":
                   case "visiting postdoctoral fellow":
                   case "corresponding fellow":
                   case "corresponding postdoc":
                   case "associate fellow":
                   case "associate postdoc":
                     $grpArray["Postdocs"] = 1;
                     if (empty($udata["nw_employeeType"])) $udata["nw_employeeType"] = "fellows";
                     break;
                   case "phd student":
                   case "phd fellow":
                   case "visiting phd fellow":
                   case "visiting phd student":
                   case "corresponding phd student":
                   case "corresponding phd fellow":
                   case "associate phd student":
                   case "associate phd fellow":
                     $grpArray["PhD Students"] = 1;
                     if (empty($udata["nw_employeeType"])) $udata["nw_employeeType"] = "postgrads";
                     break;
                   case "masters student":
                   case "visiting masters student":
                   case "corresponding masters student":
                   case "associate masters student":
                     $grpArray["Masters Students"] = 1;
                     if (empty($udata["nw_employeeType"])) $udata["nw_employeeType"] = "postgrads";
                     break;
                   case "web and computing":
                   case "economic officer":
                   case "scientific program coordinator":
                   case "student assistant":
                   case "administrator":
                   case "director":
                   case "deputy director":
                   case "hr officer":
                   case "head of computing":
                   case "head of administration":
                   case "director emeritus":
                     $grpArray["Administration"] = 1;
                     if (empty($udata["nw_employeeType"])) $udata["nw_employeeType"] = "admin";
                     break;
                   default:
                     $grpArray[ucfirst($udata["nw_employeeTitle"])] = 1;
                     break;
                 } // end switch
               } // end foreach
               $udata["nw_employeeTitleGrp"] = join(", ",array_keys($grpArray));
         */
         // -----------------------------------
         // -- Create field nw_image_small
         // -- Create field nw_image_medium
         // -- Create field nw_image_large
         // -----------------------------------
         // In ea: "av_photo"
         // In maildb: "m_photo"
         $udata["nw_image_small"] = PATH_PEOPLE . "/48x48/" . "blank-48.png";
         $pic_sans_ext = PATH_PEOPLE . "/48x48/" . $udata["nw_user"] . "-48";
         foreach (array('.png', '.jpg', '.jpeg') as $ext) {
             if (file_exists(INCLEVEL . $pic_sans_ext . $ext)) {
                 $udata["nw_image_small"] = $pic_sans_ext . $ext;
                 break;
             }
         }
         $udata["nw_image_medium"] = PATH_PEOPLE . "/85x113/" . "blank-3x4.png";
         $pic_sans_ext = PATH_PEOPLE . "/85x113/" . $udata["nw_user"] . "-3x4";
         foreach (array('.png', '.jpg', '.jpeg') as $ext) {
             if (file_exists(INCLEVEL . $pic_sans_ext . $ext)) {
                 $udata["nw_image_medium"] = $pic_sans_ext . $ext;
                 break;
             }
         }
         $udata["nw_image_large"] = PATH_PEOPLE . "/188x250/" . "blank.png";
         $pic_sans_ext = PATH_PEOPLE . "/188x250/" . $udata["nw_user"];
         foreach (array('.png', '.jpg', '.jpeg') as $ext) {
             if (file_exists(INCLEVEL . $pic_sans_ext . $ext)) {
                 $udata["nw_image_large"] = $pic_sans_ext . $ext;
                 break;
             }
         }
         // -----------------------------------
         // -- Create field nw_homepage
         // -- Create field nw_homepage_unlinked
         // -----------------------------------
         // Also in ea: "av_http"
         $udata["nw_homepage_unlinked"] = "";
         $udata["nw_homepage"] = "";
         //TODO: fetch people::hasValidHomepage() from cache
         $slask = array($udata["nw_acc_kth"], $udata["nw_acc_su"], $udata["nw_acc_nbi"], $udata["nw_acc_maildb"], $udata["nw_user"]);
         if ($sweb = functions::callMethod('people', 'lib/people', 'getSpecialHomepage', $udata["nw_user"])) {
             $udata["nw_homepage_unlinked"] = $sweb;
             $udata["nw_homepage"] = "<a href='http://" . $sweb . "'" . ">" . $sweb . "</a>";
         } elseif (functions::callMethod('people', 'lib/people', 'hasValidHomepage', $udata["nw_user"])) {
             $udata["nw_homepage_unlinked"] = "www.nordita.org/~" . $udata["nw_user"];
             $udata["nw_homepage"] = "<a href='http://" . $udata["nw_homepage_unlinked"] . "/'" . ">" . $udata["nw_homepage_unlinked"] . "</a>";
         }
         // -----------------------------------
         // -- Rename field nw_home_address
         // -- Rename field nw_home_zip
         // -- Rename field nw_home_city
         // -- Create field nw_home_phone
         // -- Create field nw_phone_mobile
         // -----------------------------------
         $udata["nw_home_address"] = isset($udata["av_address"]) ? $udata["av_address"] : "";
         // In maildb: "address"
         $udata["nw_home_zip"] = isset($udata["av_zip"]) ? $udata["av_zip"] : "";
         // In maildb: "postnummer"
         $udata["nw_home_city"] = isset($udata["av_city"]) ? $udata["av_city"] : "";
         // In maildb: "ortnamn"
         //TODO:
         $udata["nw_home_phone"] = "";
         // (isset($udata[""])) ? $udata[""] : "";
         // In maildb: "phone_home"
         //TODO:
         $udata["nw_phone_mobile"] = "";
         // (isset($udata[""])) ? $udata[""] : "";
         // In maildb: "phone_mobile"
         // -----------------------------------
         // -- Rename field nw_cv
         // -----------------------------------
         $udata["nw_cv"] = isset($udata["cv"]) ? $udata["cv"] : "";
         if ($udata["nw_cv"]["text"] == "") {
             if (!class_exists("fromdb_cv", FALSE)) {
                 require_once PATH_CLASSES . "/fromdb/cv.php";
             }
             $dbCvs = new fromdb_cv();
             $cvitems = $dbCvs->getCvs();
             // array("text","brief")
             $udata["nw_cv"] = isset($cvitems[$udata["nw_user"]]) ? $cvitems[$udata["nw_user"]] : array("text" => "", "brief" => "");
             $udata["nw_cv"]["text"] = str_replace("<p></p>", "", $udata["nw_cv"]["text"]);
             $udata["nw_cv"]["plain"] = isset($udata["nw_cv"]["text"]) ? strip_tags($udata["nw_cv"]["text"]) : "";
         }
         // -----------------------------------
         // ERASE OBSOLETE FIELDS IN DB OUTPUT
         // -----------------------------------
         foreach (array("acc_kth", "acc_su", "acc_nbi", "acc_maildb", "av_address", "av_birthcountry", "av_birthdate", "av_birthplace", "av_citizenship", "av_city", "av_ddate", "av_email", "av_email2", "av_firstname", "av_http", "av_id", "av_id2", "av_identity", "av_institute", "av_lastlogin", "av_lastname", "av_ms_country", "av_ms_institute", "av_ms_year", "av_phd_adviser_avid", "av_phd_country", "av_phd_institute", "av_phd_year", "av_phone", "av_photo", "av_position", "av_pwd", "av_pwd2", "av_residentship", "av_salutation", "av_sex", "av_ssn", "av_timestamp", "av_zip", "av_timestamp", "av_von", "e_cc", "e_gid", "e_inst", "e_off", "e_org", "e_rate", "e_type", "lm_value", "lm_key", "lm_status", "lm_option", "um_status", "altname", "altacct", "maildrop", "user", "cv") as $field) {
             if (isset($udata[$field])) {
                 unset($udata[$field]);
             }
         }
         // -----------------------------------
         // COLLECT DATA FROM OTHER SOURCES, IF NEEDED
         // -----------------------------------
         include PATH_DATA . "/adhoc_people_data.php";
         // -----------------------------------
         // SAVE BACK CHANGES INTO ARRAY $userarray
         // NB. An empty $status papameter should be interpreted as "any status"
         // -------------------------------------------------------------------------
         if (empty($status) || strtolower($udata["nw_status"]) == $status || $status == "alumni") {
             $userarray[$usr] = $udata;
         }
     }
     // end foreach
     // ------------------------------------------
     return $userarray;
 }