public static function setUpBeforeClass()
 {
     parent::setUpBeforeClass();
     SecurityTestHelper::createSuperAdmin();
     $user = UserTestHelper::createBasicUser('steve');
     $user->primaryEmail->emailAddress = '*****@*****.**';
     $user->setRight('ContactsModule', ContactsModule::RIGHT_ACCESS_CONTACTS);
     assert($user->save());
     // Not Coding Standard
     $contact1 = ContactTestHelper::createContactByNameForOwner('peter', $user);
     $contact1->primaryEmail->emailAddress = '*****@*****.**';
     $contact1->secondaryEmail->emailAddress = '*****@*****.**';
     assert($contact1->save());
     // Not Coding Standard
     $contactsOrLeads = ContactSearch::getContactsByAnyEmailAddress('*****@*****.**', null, null);
     $contact2 = ContactTestHelper::createContactByNameForOwner('jim', $user);
     $contact2->primaryEmail->emailAddress = '*****@*****.**';
     assert($contact2->save());
     // Not Coding Standard
     $nonExistingUserEmail = '*****@*****.**';
     self::$user = $user;
     self::$contact1 = $contact1;
     self::$contact2 = $contact2;
     self::$nonExistingUserEmail = $nonExistingUserEmail;
     Yii::app()->imap->imapUsername = '******';
 }
 /**
  * Gets matched models
  * @param $value
  * @param null|int $pageSize
  * @return array
  */
 protected function getMatchedModels($value, $pageSize)
 {
     $matchedModels = array();
     $penultimateModelClassName = $this->penultimateModelClassName;
     if ($penultimateModelClassName == 'Account') {
         $matchedModels = AccountSearch::getAccountsByAnyEmailAddress($value, $pageSize);
     } elseif ($penultimateModelClassName == 'Contact') {
         $matchedModels = ContactSearch::getContactsByAnyEmailAddress($value, $pageSize);
     }
     return $matchedModels;
 }
 /**
  * @return array - Jui AutoComplete ready array
  *  containing id, value, and label elements.
  * @param string $partialName
  * @param int $pageSize
  * @param null|string $stateMetadataAdapterClassName
  * @return array
  */
 public static function getByPartialName($partialName, $pageSize, $stateMetadataAdapterClassName = null)
 {
     assert('is_string($partialName)');
     assert('is_int($pageSize)');
     assert('$stateMetadataAdapterClassName == null || is_string($stateMetadataAdapterClassName)');
     $autoCompleteResults = array();
     $contacts = ContactSearch::getContactsByPartialFullName($partialName, $pageSize, $stateMetadataAdapterClassName);
     foreach ($contacts as $contact) {
         $autoCompleteResults[] = array('id' => $contact->id, 'value' => strval($contact), 'label' => strval($contact));
     }
     return $autoCompleteResults;
 }
 /**
  * Gets matched models
  * @param $value
  * @param null|int $pageSize
  * @return array
  */
 protected function getMatchedModels($value, $pageSize)
 {
     $matchedModels = ContactSearch::getContactsByFullName($value, $pageSize);
     return $matchedModels;
 }
Beispiel #5
0
 /**
  * Get Contact or Account or User, based on email address
  * @param string $emailAddress
  * @param boolean $userCanAccessContacts
  * @param boolean $userCanAccessLeads
  * @param boolean $userCanAccessAccounts
  * @return Contact || Account || User || NULL
  */
 public static function resolvePersonOrAccountByEmailAddress($emailAddress, $userCanAccessContacts = false, $userCanAccessLeads = false, $userCanAccessAccounts = false)
 {
     assert('is_string($emailAddress)');
     assert('is_bool($userCanAccessContacts)');
     assert('is_bool($userCanAccessLeads)');
     assert('is_bool($userCanAccessAccounts)');
     $personOrAccount = null;
     $contactsOrLeads = array();
     if ($userCanAccessContacts || $userCanAccessLeads) {
         $stateMetadataAdapterClassName = LeadsStateMetadataAdapter::resolveStateMetadataAdapterClassNameByAccess($userCanAccessContacts, $userCanAccessLeads);
         $contactsOrLeads = ContactSearch::getContactsByAnyEmailAddress($emailAddress, null, $stateMetadataAdapterClassName);
     }
     if (!empty($contactsOrLeads)) {
         $personOrAccount = $contactsOrLeads[0];
     } else {
         $accounts = array();
         // Check if email belongs to account
         if ($userCanAccessAccounts) {
             $accounts = AccountSearch::getAccountsByAnyEmailAddress($emailAddress);
         }
         if (count($accounts)) {
             $personOrAccount = $accounts[0];
         } else {
             $users = UserSearch::getUsersByEmailAddress($emailAddress);
             if (count($users)) {
                 $personOrAccount = $users[0];
             }
         }
     }
     return $personOrAccount;
 }
 /**
  * Given a partial name or e-mail address, search for all Users, Leads or Contacts
  * JSON encode the resulting array of contacts.
  */
 public function actionAutoCompleteForMultiSelectAutoComplete($term, $autoCompleteOptions = null)
 {
     $pageSize = Yii::app()->pagination->resolveActiveForCurrentUserByType('autoCompleteListPageSize', get_class($this->getModule()));
     $usersByFullName = UserSearch::getUsersByPartialFullName($term, $pageSize, $autoCompleteOptions);
     $usersByEmailAddress = UserSearch::getUsersByEmailAddress($term, 'contains', true, $autoCompleteOptions, $pageSize);
     $contacts = ContactSearch::getContactsByPartialFullNameOrAnyEmailAddress($term, $pageSize, null, 'contains', $autoCompleteOptions);
     $autoCompleteResults = array();
     foreach ($usersByEmailAddress as $user) {
         if (isset($user->primaryEmail->emailAddress)) {
             $autoCompleteResults[] = array('id' => strval($user->primaryEmail), 'name' => strval($user) . ' (' . $user->primaryEmail . ')');
         }
     }
     foreach ($usersByFullName as $user) {
         if (isset($user->primaryEmail->emailAddress)) {
             $autoCompleteResults[] = array('id' => strval($user->primaryEmail), 'name' => strval($user) . ' (' . $user->primaryEmail . ')');
         }
     }
     foreach ($contacts as $contact) {
         if (isset($contact->primaryEmail->emailAddress)) {
             $autoCompleteResults[] = array('id' => strval($contact->primaryEmail), 'name' => strval($contact) . ' (' . $contact->primaryEmail . ')');
         }
     }
     $emailValidator = new CEmailValidator();
     if (count($autoCompleteResults) == 0 && $emailValidator->validateValue($term)) {
         $autoCompleteResults[] = array('id' => $term, 'name' => $term);
     }
     echo CJSON::encode($autoCompleteResults);
 }
 public function testUsingStateAdapters()
 {
     $super = User::getByUsername('super');
     Yii::app()->user->userModel = $super;
     $contactStates = ContactState::getAll();
     $this->assertTrue(count($contactStates) > 1);
     $firstContactState = $contactStates[0];
     $lastContactState = $contactStates[count($contactStates) - 1];
     $contact = new Contact();
     $contact->title->value = 'Mr.';
     $contact->firstName = 'Sallyy';
     $contact->lastName = 'Sallyyson';
     $contact->owner = $super;
     $contact->state = $firstContactState;
     $contact->primaryEmail = new Email();
     $contact->primaryEmail->emailAddress = '*****@*****.**';
     $contact->secondaryEmail = new Email();
     $contact->secondaryEmail->emailAddress = '*****@*****.**';
     $this->assertTrue($contact->save());
     $data = ContactSearch::getContactsByPartialFullNameOrAnyEmailAddress('sally', 5);
     $this->assertEquals(2, count($data));
     $data = ContactSearch::getContactsByPartialFullName('sally', 5);
     $this->assertEquals(2, count($data));
     //Use contact state adapter
     $data = ContactSearch::getContactsByPartialFullNameOrAnyEmailAddress('sally', 5, 'ContactsStateMetadataAdapter');
     $this->assertEquals(1, count($data));
     $this->assertEquals($lastContactState, $data[0]->state);
     $data = ContactSearch::getContactsByPartialFullName('sally', 5, 'ContactsStateMetadataAdapter');
     $this->assertEquals(1, count($data));
     $this->assertEquals($lastContactState, $data[0]->state);
     //Use lead state adapter
     $data = ContactSearch::getContactsByPartialFullNameOrAnyEmailAddress('sally', 5, 'LeadsStateMetadataAdapter');
     $this->assertEquals(1, count($data));
     $this->assertEquals($firstContactState, $data[0]->state);
     $data = ContactSearch::getContactsByPartialFullName('sally', 5, 'LeadsStateMetadataAdapter');
     $this->assertEquals(1, count($data));
     $this->assertEquals($firstContactState, $data[0]->state);
 }
 /**
  * Given a partial name or e-mail address, search for all contacts or users regardless of contact state unless
  * the current user has security restrictions on some states. If the adapter resolver returns false, then the
  * user does not have access to the Leads or Contacts module.
  * JSON encode the resulting array of contacts.
  */
 public function actionAutoCompleteAllContactsOrUsersForMultiSelectAutoComplete($term, $autoCompleteOptions = null)
 {
     $pageSize = Yii::app()->pagination->resolveActiveForCurrentUserByType('autoCompleteListPageSize', get_class($this->getModule()));
     $adapterName = ContactsUtil::resolveContactStateAdapterByModulesUserHasAccessTo('LeadsModule', 'ContactsModule', Yii::app()->user->userModel);
     if ($adapterName === false) {
         $messageView = new AccessFailureView();
         $view = new AccessFailurePageView($messageView);
         echo $view->render();
         Yii::app()->end(0, false);
     }
     $contacts = ContactSearch::getContactsByPartialFullNameOrAnyEmailAddress($term, $pageSize, $adapterName, null, $autoCompleteOptions);
     $autoCompleteResults = array();
     foreach ($contacts as $contact) {
         $autoCompleteResults[] = array('id' => Meeting::CONTACT_ATTENDEE_PREFIX . $contact->id, 'name' => MultipleContactsForMeetingElement::renderHtmlContentLabelFromContactAndKeyword($contact, $term));
     }
     $users = UserSearch::getUsersByPartialFullNameOrAnyEmailAddress($term, $pageSize, null, null, $autoCompleteOptions);
     foreach ($users as $user) {
         $autoCompleteResults[] = array('id' => Meeting::USER_ATTENDEE_PREFIX . $user->id, 'name' => MultipleContactsForMeetingElement::renderHtmlContentLabelFromUserAndKeyword($user, $term));
     }
     echo CJSON::encode($autoCompleteResults);
 }
 public function make_column($name, $errors)
 {
     global $Me;
     $p = strpos($name, ":");
     $cids = ContactSearch::make_pc(substr($name, $p + 1), $Me)->ids;
     if (count($cids) == 0) {
         self::make_column_error($errors, "No PC member matches “" . htmlspecialchars(substr($name, $p + 1)) . "”.", 2);
     } else {
         if (count($cids) == 1) {
             $pcm = pcMembers();
             return parent::register(new PreferencePaperColumn($name, $this->editable, $pcm[$cids[0]]));
         } else {
             self::make_column_error($errors, "“" . htmlspecialchars(substr($name, $p + 1)) . "” matches more than one PC member.", 2);
         }
     }
     return null;
 }
 public function testGetContactsByAnyPhone()
 {
     $super = User::getByUsername('super');
     Yii::app()->user->userModel = $super;
     $contactStates = ContactState::getAll();
     $this->assertTrue(count($contactStates) > 1);
     $firstContactState = $contactStates[0];
     $contact = new Contact();
     $contact->title->value = 'Mr.';
     $contact->firstName = 'test contact';
     $contact->lastName = 'for search by any phone';
     $contact->owner = $super;
     $contact->state = $firstContactState;
     $contact->primaryEmail = new Email();
     $contact->primaryEmail->emailAddress = '*****@*****.**';
     $contact->mobilePhone = '123-456-789';
     $contact->officePhone = '987-654-321';
     $this->assertTrue($contact->save());
     $data = ContactSearch::getContactsByAnyPhone('123-456-789');
     $this->assertEquals(1, count($data));
     $data = ContactSearch::getContactsByAnyPhone('987-654-321');
     $this->assertEquals(1, count($data));
     $data = ContactSearch::getContactsByAnyPhone('987-987-987');
     $this->assertEquals(0, count($data));
 }
Beispiel #11
0
 public function testGetContactsByAnyEmailAddress()
 {
     $super = User::getByUsername('super');
     Yii::app()->user->userModel = $super;
     $contactStates = ContactState::getAll();
     $this->assertTrue(count($contactStates) > 1);
     $firstContactState = $contactStates[0];
     $contact = new Contact();
     $contact->title->value = 'Mr.';
     $contact->firstName = 'test';
     $contact->lastName = 'contact';
     $contact->owner = $super;
     $contact->state = $firstContactState;
     $contact->primaryEmail = new Email();
     $contact->primaryEmail->emailAddress = '*****@*****.**';
     $contact->secondaryEmail = new Email();
     $contact->secondaryEmail->emailAddress = '*****@*****.**';
     $this->assertTrue($contact->save());
     $data = ContactSearch::getContactsByAnyEmailAddress('*****@*****.**');
     $this->assertEquals(1, count($data));
 }
 private function lookup_users(&$req, $assigner)
 {
     // move all usable identification data to email, firstName, lastName
     if (isset($req["name"])) {
         self::apply_user_parts($req, Text::split_name($req["name"]));
     }
     if (isset($req["user"]) && strpos($req["user"], " ") === false) {
         if (!get($req, "email")) {
             $req["email"] = $req["user"];
         }
     } else {
         if (isset($req["user"])) {
             self::apply_user_parts($req, Text::split_name($req["user"], true));
         }
     }
     // extract email, first, last
     $first = get($req, "firstName");
     $last = get($req, "lastName");
     $email = trim((string) get($req, "email"));
     $lemail = strtolower($email);
     $special = null;
     if ($lemail) {
         $special = $lemail;
     } else {
         if (!$first && $last && strpos(trim($last), " ") === false) {
             $special = trim(strtolower($last));
         }
     }
     $xspecial = $special;
     if ($special === "all") {
         $special = "any";
     }
     // check missing contact
     if (!$first && !$last && !$lemail) {
         if ($assigner->allow_special_contact("missing", $req, $this->astate)) {
             return array(null);
         } else {
             return $this->error("User missing.");
         }
     }
     // check special: "none", "any", "pc", "me", PC tag, "external"
     if ($special === "none" || $special === "any") {
         if (!$assigner->allow_special_contact($special, $req, $this->astate)) {
             return $this->error("User “{$xspecial}” not allowed here.");
         }
         return array((object) array("roles" => 0, "contactId" => null, "email" => $special, "sorter" => ""));
     }
     if ($special && !$first && (!$lemail || !$last)) {
         $ret = ContactSearch::make_special($special, $this->contact->contactId);
         if ($ret->ids !== false) {
             return $ret->contacts();
         }
     }
     if (($special === "ext" || $special === "external") && $assigner->contact_set($req, $this->astate) === "reviewers") {
         $ret = array();
         foreach ($this->reviewer_set() as $u) {
             if (!$u->is_pc_member()) {
                 $ret[] = $u;
             }
         }
         return $ret;
     }
     // check for precise email match on existing contact (common case)
     if ($lemail && ($contact = $this->cmap->lookup_lemail($lemail))) {
         return array($contact);
     }
     // check PC list
     $cset = $assigner->contact_set($req, $this->astate);
     if ($cset === "pc") {
         $cset = pcMembers();
     } else {
         if ($cset === "reviewers") {
             $cset = $this->reviewer_set();
         }
     }
     if ($cset) {
         $text = "";
         if ($first && $last) {
             $text = "{$last}, {$first}";
         } else {
             if ($first || $last) {
                 $text = "{$last}{$first}";
             }
         }
         if ($email) {
             $text .= " <{$email}>";
         }
         $ret = ContactSearch::make_cset($text, $this->contact->cid, $cset);
         if (count($ret->ids) == 1) {
             return $ret->contacts();
         } else {
             if (count($ret->ids) == 0) {
                 $this->error("No user matches “" . self::req_user_html($req) . "”.");
             } else {
                 $this->error("“" . self::req_user_html($req) . "” matches more than one user, use a full email address to disambiguate.");
             }
         }
         return false;
     }
     // create contact
     if (!$email) {
         return $this->error("Missing email address");
     }
     $contact = $this->cmap->make_email($email);
     if ($contact->contactId < 0) {
         if (!validate_email($email)) {
             return $this->error("Email address “" . htmlspecialchars($email) . "” is invalid.");
         }
         if (!isset($contact->firstName) && get($req, "firstName")) {
             $contact->firstName = $req["firstName"];
         }
         if (!isset($contact->lastName) && get($req, "lastName")) {
             $contact->lastName = $req["lastName"];
         }
     }
     return array($contact);
 }
 private function _expand_tag($tagword, $allow_star)
 {
     // see also TagAssigner
     $ret = array("");
     $twiddle = strpos($tagword, "~");
     if ($this->privChair && $twiddle > 0 && !ctype_digit(substr($tagword, 0, $twiddle))) {
         $c = substr($tagword, 0, $twiddle);
         $ret = ContactSearch::make_pc($c, $this->cid)->ids;
         if (count($ret) == 0) {
             $this->warn("“" . htmlspecialchars($c) . "” doesn’t match a PC email.");
         }
         $tagword = substr($tagword, $twiddle);
     } else {
         if ($twiddle === 0 && ($tagword === "" || $tagword[1] !== "~")) {
             $ret[0] = $this->cid;
         }
     }
     $tagger = new Tagger($this->contact);
     if (!$tagger->check("#" . $tagword, Tagger::ALLOWRESERVED | Tagger::NOVALUE | ($allow_star ? Tagger::ALLOWSTAR : 0))) {
         $this->warn($tagger->error_html);
         $ret = array();
     }
     foreach ($ret as &$x) {
         $x .= $tagword;
     }
     return $ret;
 }
function setTagIndexes()
{
    global $Conf, $Me, $Error;
    $filename = null;
    if (isset($_REQUEST["upload"]) && fileUploaded($_FILES["file"])) {
        if (($text = file_get_contents($_FILES["file"]["tmp_name"])) === false) {
            Conf::msg_error("Internal error: cannot read file.");
            return;
        }
        $filename = @$_FILES["file"]["name"];
    } else {
        if (!($text = defval($_REQUEST, "data"))) {
            Conf::msg_error("Choose a file first.");
            return;
        }
    }
    $RealMe = $Me;
    $tagger = new Tagger();
    if ($tag = defval($_REQUEST, "tag")) {
        $tag = $tagger->check($tag, Tagger::NOVALUE);
    }
    $curIndex = 0;
    $lineno = 1;
    $settings = $titles = $linenos = $errors = array();
    foreach (explode("\n", rtrim(cleannl($text))) as $l) {
        if (substr($l, 0, 4) == "Tag:" || substr($l, 0, 6) == "# Tag:") {
            if (!$tag) {
                $tag = $tagger->check(trim(substr($l, $l[0] == "#" ? 6 : 4)), Tagger::NOVALUE);
            }
            ++$lineno;
            continue;
        } else {
            if ($l == "" || $l[0] == "#") {
                ++$lineno;
                continue;
            }
        }
        if (preg_match('/\\A\\s*?([Xx=]|>*|\\([-\\d]+\\))\\s+(\\d+)\\s*(.*?)\\s*\\z/', $l, $m)) {
            if (isset($settings[$m[2]])) {
                $errors[$lineno] = "Paper #{$m['2']} already given on line " . $linenos[$m[2]];
            }
            if ($m[1] == "X" || $m[1] == "x") {
                $settings[$m[2]] = null;
            } else {
                if ($m[1] == "" || $m[1] == ">") {
                    $settings[$m[2]] = $curIndex = $curIndex + 1;
                } else {
                    if ($m[1][0] == "(") {
                        $settings[$m[2]] = $curIndex = substr($m[1], 1, -1);
                    } else {
                        if ($m[1] == "=") {
                            $settings[$m[2]] = $curIndex;
                        } else {
                            $settings[$m[2]] = $curIndex = $curIndex + strlen($m[1]);
                        }
                    }
                }
            }
            $titles[$m[2]] = $m[3];
            $linenos[$m[2]] = $lineno;
        } else {
            if ($RealMe->privChair && preg_match('/\\A\\s*<\\s*([^<>]*?(|<[^<>]*>))\\s*>\\s*\\z/', $l, $m)) {
                if (count($settings) && $Me) {
                    saveTagIndexes($tag, $filename, $settings, $titles, $linenos, $errors);
                }
                $ret = ContactSearch::make_pc($m[1], $RealMe);
                $Me = null;
                if (count($ret->ids) == 1) {
                    $Me = $ret->contact(0);
                } else {
                    if (count($ret->ids) == 0) {
                        $errors[$lineno] = htmlspecialchars($m[1]) . " matches no PC member";
                    } else {
                        $errors[$lineno] = htmlspecialchars($m[1]) . " matches more than one PC member, give a full email address to disambiguate";
                    }
                }
            } else {
                if (trim($l) !== "") {
                    $errors[$lineno] = "Syntax error";
                }
            }
        }
        ++$lineno;
    }
    if (count($settings) && $Me) {
        saveTagIndexes($tag, $filename, $settings, $titles, $linenos, $errors);
    }
    $Me = $RealMe;
    if (count($errors)) {
        ksort($errors);
        if ($filename) {
            foreach ($errors as $lineno => &$error) {
                $error = '<span class="lineno">' . htmlspecialchars($filename) . ':' . $lineno . ':</span> ' . $error;
            }
        }
        $Error["tags"] = '<div class="parseerr"><p>' . join("</p>\n<p>", $errors) . '</p></div>';
    }
    if (isset($Error["tags"])) {
        Conf::msg_error($Error["tags"]);
    } else {
        if (isset($_REQUEST["setvote"])) {
            $Conf->confirmMsg("Votes saved.");
        } else {
            $Conf->confirmMsg("Ranking saved.  To view it, <a href='" . hoturl("search", "q=order:" . urlencode($tag)) . "'>search for &ldquo;order:{$tag}&rdquo;</a>.");
        }
    }
}