function eventGetContacts(EventControler $evtcl) { $plugType = 'email'; $provider_box = $evtcl->provider_box; $email_box = $evtcl->email_box; $password_box = $evtcl->password_box; $msg = ""; $contacts = ""; $ok = false; if (empty($email_box)) { $msg = "Email missing !"; } if (empty($password_box)) { $msg = "Password missing !"; } if (empty($provider_box)) { $msg = "Provider missing !"; } if ($msg == "") { $inviter = new OpenInviter(); $inviter->startPlugin($provider_box); $internal = $inviter->getInternalError(); if ($internal) { $msg = $internal; } elseif (!$inviter->login($email_box, $password_box)) { $internal = $inviter->getInternalError(); $msg = $internal ? $internal : "Login failed. Please check the email and password you have provided and try again later !"; } elseif (false === ($contacts = $inviter->getMyContacts())) { $msg = "Unable to get contacts !"; } else { $msg = "Contacts imported successfully."; $ok = true; //$_POST['oi_session_id']=$inviter->plugin->getSessionID(); } } if ($ok) { /*print_r($contacts); exit();*/ foreach ($contacts as $email => $name) { $do_contact = new Contact(); $do_contact->firstname = $name; $do_contact->iduser = $_SESSION['do_User']->iduser; $do_contact->add(); $lastInsertedContId = $do_contact->getPrimaryKeyValue(); $do_contact->addEmail($email, 'Home'); $do_contact->free(); //contact view $do_cv = new ContactView(); $do_cv->idcontact = $lastInsertedContId; $do_cv->firstname = $name; $do_cv->email_address = $email; $do_cv->add(); $do_cv->free(); } } $_SESSION['in_page_message'] = $msg; }
function eventAddContactToTeamCW(Contact $contact) { $do_teams = new Teams(); //gets user's teams which are marked as auto-shared $do_teams->getUserTeamsAutoShared(); if ($do_teams->getNumRows()) { while ($do_teams->next()) { //gets Co-Workers of the team $do_teams_cw = new Teams(); $do_teams_cw->getCoWorkersOfTheTeam($do_teams->idteam); if ($do_teams_cw->getNumRows()) { while ($do_teams_cw->next()) { $this->addNew(); $this->idcontact = $contact->idcontact; $this->idteam = $do_teams->idteam; $this->idcoworker = $do_teams_cw->idco_worker; $this->add(); $this->free(); //building contact view table $do_cv = new ContactView(); $do_cv->table = "userid" . $do_teams_cw->idco_worker . "_contact"; $do_cv->getId($contact->idcontact); if (!$do_cv->hasData()) { $do_cv->addNew(); $do_cv->idcontact = $contact->idcontact; $do_cv->firstname = $contact->firstname; $do_cv->lastname = $contact->lastname; $do_cv->company = $contact->company; $do_cv->idcompany = $contact->idcompany; $do_cv->position = $contact->position; $do_cv->picture = $contact->picture; $do_cv->last_activity = date('Y-m-d h:i:s'); $do_cv->last_update = date('Y-m-d h:i:s'); $do_cv->first_created = date('Y-m-d h:i:s'); $do_cv->add(); $do_cv->free(); } //Conact sharing with Co-Worker $do_cs_check = new ContactSharing(); $contact_shared = $do_cs_check->checkCoWorkerContactRel($contact->idcontact, $do_teams_cw->idco_worker); if (!$contact_shared) { $do_cs = new ContactSharing(); $do_cs->addNew(); $do_cs->iduser = $_SESSION['do_User']->iduser; $do_cs->idcontact = $contact->idcontact; $do_cs->idcoworker = $do_teams_cw->idco_worker; $do_cs->add(); $do_cs->free(); } $do_cs_check->free(); } } else { $this->addNew(); $this->idcontact = $_SESSION['ContactEditSave']->idcontact; $this->idteam = $do_teams->idteam; $this->add(); $this->free(); } $do_teams_cw->free(); } } $do_teams->free(); }