/** * Convert a comma separated string of names, into an array with email addresses * @param string $people * @param string $entity the related entity that can assist in the look up * @param integer $entityID the id of the related entity * @return array an array of people, indexed by their email address */ public function get_people($options = array(), $entity = "", $entityID = "") { $person_table =& get_cached_table("person"); $people = $options; if ($entity && $entityID) { $e = new $entity(); $e->set_id($entityID); $e->select(); in_array("default", $people) and $default_recipients = $e->get_all_parties(); in_array("internal", $people) and $internal_recipients = $e->get_all_parties(); } // remove default and internal from the array $clean_people = array_diff($people, array("default", "internal")); if (is_object($e)) { $projectID = $e->get_project_id(); $p = new project(); $p->set_id($projectID); $p->select(); $client = $p->get_foreign_object("client"); $clientID = $client->get_id(); } foreach ((array) $default_recipients as $email => $info) { if ($info["selected"]) { $rtn[$email] = $this->reduce_person_info($info); } } foreach ((array) $internal_recipients as $email => $info) { if ($info["selected"] && !$info["external"]) { $rtn[$email] = $this->reduce_person_info($info); } } foreach ((array) $clean_people as $person) { $bad_person = true; $person = trim($person); // personID if (is_numeric($person)) { if ($person_table[$person]["personActive"]) { $rtn[$person_table[$person]["emailAddress"]] = $person_table[$person]; $bad_person = false; continue; } // email addresses } else { if (in_str("@", $person)) { foreach ($person_table as $pid => $data) { if (same_email_address($person, $data["emailAddress"]) && $data["personActive"]) { $rtn[$data["emailAddress"]] = $data; $bad_person = false; continue 2; } } if ($ccID = clientContact::find_by_email($person)) { $cc = new clientContact(); $cc->set_id($ccID); $cc->select(); $rtn[$cc->get_value("clientContactEmail")] = $cc->row(); $bad_person = false; continue; } // If we get here, then return the email address entered list($e, $n) = parse_email_address($person); $rtn[$e] = array("emailAddress" => $e, "name" => $n); $bad_person = false; continue; // usernames, partial and full names } else { foreach ($person_table as $pid => $data) { // If matches username if (strtolower($person) == strtolower($data["username"]) && $data["personActive"]) { $rtn[$data["emailAddress"]] = $data; $bad_person = false; continue 2; } } foreach ($person_table as $pid => $data) { // If matches name if (strtolower($person) == strtolower($data["firstName"] . " " . $data["surname"]) && $data["personActive"]) { $rtn[$data["emailAddress"]] = $data; $bad_person = false; continue 2; } } foreach ($person_table as $pid => $data) { // If matches a section of name, eg: a search for "Ale" will match the full name "Alex Lance" if (strtolower($person) == strtolower(substr(strtolower($data["firstName"] . " " . $data["surname"]), 0, strlen($person))) && $data["personActive"]) { $rtn[$data["emailAddress"]] = $data; $bad_person = false; continue 2; } } if ($ccID = clientContact::find_by_nick($person, $clientID)) { $cc = new clientContact(); $cc->set_id($ccID); $cc->select(); $rtn[$cc->get_value("clientContactEmail")] = $cc->row(); $bad_person = false; continue; } if ($ccID = clientContact::find_by_name($person, $projectID)) { $cc = new clientContact(); $cc->set_id($ccID); $cc->select(); $rtn[$cc->get_value("clientContactEmail")] = $cc->row(); $bad_person = false; continue; } if ($ccID = clientContact::find_by_partial_name($person, $projectID)) { $cc = new clientContact(); $cc->set_id($ccID); $cc->select(); $rtn[$cc->get_value("clientContactEmail")] = $cc->row(); $bad_person = false; continue; } } } if ($bad_person) { die("Unable to find person: " . $person); } } foreach ((array) $rtn as $id => $p) { $rtn[$id] = $this->reduce_person_info($p); } return (array) $rtn; }