/** * eventAddFeed * This event is triggered when the note is added in the * contact.php page. * Its the last event and assume that the ContactNoteEditSave has * a primary key from the database table. * This event action prepare all the data so no additional query is needed * in the display table. * @param EventControler */ function eventAddFeed(EventControler $evtcl) { $this->note = $_SESSION['ContactNoteEditSave']->note; $this->iduser = $evtcl->iduser_for_feed; $this->idcontact = $_SESSION['ContactNoteEditSave']->idcontact; $this->idcontact_note = $_SESSION['ContactNoteEditSave']->idcontact_note; $user = new User(); $user->getId($this->iduser); $do_contact = new Contact(); $do_contact->getId($this->idcontact); if ($evtcl->added_by_cont == 'Yes') { $this->added_by = $do_contact->getContactFullName(); } else { $this->added_by = $user->getFullName(); } $this->contact_full_name = $do_contact->getContactFullName(); $this->contact_image_url = $do_contact->getContactPicture(); if (strlen($this->note) > 200) { $this->note = substr($this->note, 0, 200); $this->more = True; } else { $this->more = false; } $user_relation = new ContactSharing(); $user_array = $user_relation->getCoWorkerByContact($this->idcontact); @array_push($user_array, $this->iduser); if (!is_array($user_array) || $user_array === false) { $user_array = array($evtcl->iduser_for_feed); } //print_r($user_array);exit; $this->addFeed($user_array); }
/** * addTweet * Prepare all the data for the RSS feed * look for Co-Workers associated with the contact * and add the users as a feed recipient. * @note this is used in a cronjob so no session variables will works. * @param ContactNote object * @param website url * @param note_content (without the link to source) */ function addTweet($do_contact_note, $website, $note_content) { $do_contact = new Contact(); $this->idcontact = $do_contact_note->idcontact; $do_contact->getId($this->idcontact); $this->iduser = $do_contact->iduser; if (strlen($note_content) > 200) { $this->feed_content = substr($note_content, 0, 200); } else { $this->feed_content = $note_content; } $picture = $do_contact->getContactPicture(); $this->full_contact_name = $do_contact->getContactFullName($this->idcontact); //$this->task_event_type = "rss_feed_cron"; $this->cont_image_url = $picture; $this->website_url = $website; $user_relation = new ContactSharing(); $users = $user_relation->getCoWorkerByContact($this->idcontact); $users[] = $do_contact->iduser; $this->addFeed($users); }
/** * Function adds workfeed when a contact unsubscibe emails * @param object $obj, object containing the contact and user id * @param string $responder , name of the responder */ function addUnsubscribeEmailWorkfeed($obj, $responder = "") { if ($responder == "") { $this->note = _('has unsubscribed from emails'); } else { $this->note = _('has unsubscribed from the auto-responder series ') . $responder; } $this->iduser = $obj->iduser; $this->idcontact = $obj->idcontact; $user = new User(); $user->getId($this->iduser); $do_contact = new Contact(); $do_contact->getId($this->idcontact); //$this->added_by = $do_contact->getContactFullName(); $this->contact_full_name = $do_contact->getContactFullName(); $this->contact_image_url = $do_contact->getContactPicture(); $user_relation = new ContactSharing(); $user_array = $user_relation->getCoWorkerByContact($this->idcontact); @array_push($user_array, $this->iduser); $this->addFeed($user_array); }
/** * eventAddFeed * This event is triggered when the note is added in the * contact.php page. * Its the last event and assume that the ContactNoteEditSave has * a primary key from the database table. * This event action prepare all the data so no additional query is needed * in the display table. * @param EventControler */ function eventAddFeed(EventControler $evtcl) { $this->note = $_SESSION['ContactNoteEditSave']->note; $this->iduser = $_SESSION['ContactNoteEditSave']->iduser; $this->idcontact = $_SESSION['ContactNoteEditSave']->idcontact; $this->idcontact_note = $_SESSION['ContactNoteEditSave']->idcontact_note; $user = new User(); $user->getId($this->iduser); $this->user_full_name = $user->getFullName(); $do_contact = new Contact(); $do_contact->getId($this->idcontact); $this->contact_full_name = $do_contact->getContactFullName(); $this->contact_image_url = $do_contact->getContactPicture(); if (strlen($this->note) > 200) { $this->note = substr($this->note, 0, 200); $this->more = True; } else { $this->more = false; } $user_relation = new ContactSharing(); $this->addFeed($user_relation->getCoWorkerByContact($this->idcontact)); }
// echo '<div class="solidline"></div>'; ?> <!-- </div> </div> <div class="contentfull">--> <?php $set_share = false; if (isset($_POST['ck'])) { $contact_ids = $_POST['ck']; $set_share = true; // Request comes from Contact page } $_SESSION['do_coworker']->getAllCoWorker(); //Get all the Co-Workers if (!is_object($_SESSION['do_contact_sharing'])) { $do_contact_sharing = new ContactSharing(); $do_contact_sharing->sessionPersistent("do_contact_sharing", "index.php", 36000); } if ($_SESSION['do_coworker']->getNumrows()) { if (!is_object($_SESSION['do_Contacts'])) { $do_Contacts = new Contact(); $do_Contacts->setRegistry("all_contacts"); $do_Contacts->sessionPersistent("do_Contacts", "index.php", 36000); } if (!$set_share) { // If not having POST vales // $user_coworker = new User(); while ($_SESSION['do_coworker']->next()) { // $user_coworker->getId($_SESSION['do_coworker']->idcoworker); // Get the contacts shared for this Co-Worker $shared_contacts = $_SESSION['do_contact_sharing']->getSharedContacts($_SESSION['do_coworker']->idcoworker);
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(); }
/** * The below function is to merge the contacts and related information * Need some better algorithm for that so as to avoid the repeated code * FIXME * @param $cont_array -- Array with idcontact */ function MergeContactsAutomated($cont_array) { if (is_array($cont_array)) { $this->mergeContactTags($cont_array); $this->mergeContactRelated($cont_array); $id_to_keep = $cont_array[0]; //take the first record from the contact array to keep $do_deleting_contact = new Contact(); $do_check_duplicate = new Contact(); $do_cont_sharing = new ContactSharing(); $facebook_id_updated = false; $facebook_image_updated = false; $twitter_id_updated = false; foreach ($cont_array as $contact_id_del) { if ($contact_id_del != $id_to_keep) { // facebook Related keep the image if facebook image is available from the merged $q = new sqlQuery($this->getDbCon()); $q_master = new sqlQuery($this->getDbCon()); $q_rel = new sqlQuery($this->getDbCon()); if (!$facebook_image_updated) { $q_master->query("select picture from contact where idcontact = " . $id_to_keep); $q_master->fetch(); $picture = $q_master->getData("picture"); if (!preg_match("/facebook.com/", $picture, $matches)) { $q_rel->query("select picture from contact where idcontact = " . $contact_id_del); $q_rel->fetch(); $r_picture = $q_rel->getData("picture"); if (preg_match("/facebook.com/", $r_picture, $matches)) { $q->query("update contact set picture = '" . $r_picture . "' where idcontact = " . $id_to_keep); $facebook_image_updated = true; } } else { $facebook_image_updated = true; } } // Facebook Related keep track of facebook id of contact $q = new sqlQuery($this->getDbCon()); $q_master = new sqlQuery($this->getDbCon()); $q_rel = new sqlQuery($this->getDbCon()); if (!$facebook_id_updated) { $q_master->query("select fb_userid from contact where idcontact = " . $id_to_keep); $q_master->fetch(); $fb_uid = $q_master->getData("fb_userid"); if ($fb_uid == 0 || empty($fb_uid) || $fb_uid == '') { $q_rel->query("select fb_userid from contact where idcontact = " . $contact_id_del); $q_rel->fetch(); $fb_userid = $q_rel->getData("fb_userid"); if ($fb_userid != 0 && !empty($fb_userid) && $fb_userid != '') { $q->query("update contact set fb_userid = " . $fb_userid . " where idcontact = " . $id_to_keep); $facebook_id_updated = true; } } else { $facebook_id_updated = true; } } // Twitter Related :: keep track of twitter id of the contact $q = new sqlQuery($this->getDbCon()); $q_master = new sqlQuery($this->getDbCon()); $q_rel = new sqlQuery($this->getDbCon()); if (!$twitter_id_updated) { $q_master->query("select tw_user_id from contact where idcontact = " . $id_to_keep); $q_master->fetch(); $tw_uid = $q_master->getData('tw_user_id'); if (empty($tw_uid) || $tw_uid == '') { $q_rel->query("select tw_user_id from contact where idcontact = " . $contact_id_del); $q_rel->fetch(); $tw_user_id = $q_rel->getData('tw_user_id'); if (!empty($tw_user_id) && $tw_user_id != '') { $q->query("update contact set tw_user_id = " . $tw_user_id . " where idcontact = " . $id_to_keep); $twitter_id_updated = true; } } else { $twitter_id_updated = true; } } //update the ContactPhone with $id_to_keep $q = new sqlQuery($this->getDbCon()); $q_master = new sqlQuery($this->getDbCon()); $q_rel = new sqlQuery($this->getDbCon()); $q_master->query("select * from contact_phone where idcontact = " . $id_to_keep); if ($q_master->getNumRows() > 0) { $update_ids_array = array(); $q_rel->query("select * from contact_phone where idcontact = " . $contact_id_del); if ($q_rel->getNumRows()) { while ($q_rel->fetch()) { $found = true; while ($q_master->fetch()) { if ($q_rel->getData("phone_number") == $q_master->getData("phone_number") && $q_rel->getData("phone_type") == $q_master->getData("phone_type")) { $found = true; break; } else { $found = false; } } if (!$found) { $q->query("update contact_phone set idcontact = " . $id_to_keep . " where idcontact_phone = " . $q_rel->getData("idcontact_phone")); } } } } else { $q->query("update contact_phone set idcontact = " . $id_to_keep . " where idcontact = " . $contact_id_del); } //Update the ContactEmail with $id_to_keep $q = new sqlQuery($this->getDbCon()); $q_master = new sqlQuery($this->getDbCon()); $q_rel = new sqlQuery($this->getDbCon()); $q_master->query("select * from contact_email where idcontact = " . $id_to_keep); if ($q_master->getNumRows() > 0) { $update_ids_array = array(); $q_rel->query("select * from contact_email where idcontact = " . $contact_id_del); if ($q_rel->getNumRows()) { $count = 0; while ($q_rel->fetch()) { $found = true; while ($q_master->fetch()) { $count++; if ($q_rel->getData("email_address") == $q_master->getData("email_address") && $q_rel->getData("email_type") == $q_master->getData("email_type")) { $found = true; break; } else { $found = false; } } if (!$found) { $q->query("update contact_email set idcontact = " . $id_to_keep . " where idcontact_email = " . $q_rel->getData("idcontact_email")); } } } } else { $q->query("update contact_email set idcontact = " . $id_to_keep . " where idcontact = " . $contact_id_del); } //Update the ContactInstantMessage with $id_to_keep $q = new sqlQuery($this->getDbCon()); $q_master = new sqlQuery($this->getDbCon()); $q_rel = new sqlQuery($this->getDbCon()); $q_master->query("select * from contact_instant_message where idcontact = " . $id_to_keep); if ($q_master->getNumRows() > 0) { $update_ids_array = array(); $q_rel->query("select * from contact_instant_message where idcontact = " . $contact_id_del); if ($q_rel->getNumRows()) { while ($q_rel->fetch()) { $found = true; while ($q_master->fetch()) { if ($q_rel->getData("im_options") == $q_master->getData("im_options") && $q_rel->getData("im_type") == $q_master->getData("im_type") && $q_rel->getData("im_username") == $q_master->getData("im_username")) { $found = true; break; } else { $found = false; } } if (!$found) { $q->query("update contact_instant_message set idcontact = " . $id_to_keep . " where idcontact_instant_message = " . $q_rel->getData("idcontact_instant_message")); } } } } else { $q->query("update contact_instant_message set idcontact = " . $id_to_keep . " where idcontact = " . $contact_id_del); } //Update the ContactWebsite with $id_to_keep $q = new sqlQuery($this->getDbCon()); $q_master = new sqlQuery($this->getDbCon()); $q_rel = new sqlQuery($this->getDbCon()); $q_master->query("select * from contact_website where idcontact = " . $id_to_keep); if ($q_master->getNumRows() > 0) { $update_ids_array = array(); $q_rel->query("select * from contact_website where idcontact = " . $contact_id_del); if ($q_rel->getNumRows()) { while ($q_rel->fetch()) { $found = true; while ($q_master->fetch()) { if ($q_rel->getData("website") == $q_master->getData("website") && $q_rel->getData("website_type") == $q_master->getData("website_type")) { $found = true; break; } else { $found = false; } } if (!$found) { $q->query("update contact_website set idcontact = " . $id_to_keep . " where idcontact_website = " . $q_rel->getData("idcontact_website")); } } } } else { $q->query("update contact_website set idcontact = " . $id_to_keep . " where idcontact = " . $contact_id_del); } //Update the ContactAddress with $id_to_keep $q = new sqlQuery($this->getDbCon()); $q_master = new sqlQuery($this->getDbCon()); $q_rel = new sqlQuery($this->getDbCon()); $q_master->query("select * from contact_address where idcontact = " . $id_to_keep); if ($q_master->getNumRows() > 0) { $update_ids_array = array(); $q_rel->query("select * from contact_address where idcontact = " . $contact_id_del); if ($q_rel->getNumRows()) { while ($q_rel->fetch()) { $found = true; while ($q_master->fetch()) { if ($q_rel->getData("address") == $q_master->getData("address") && $q_rel->getData("address_type") == $q_master->getData("address_type") && $q_rel->getData("city") == $q_master->getData("city") && $q_rel->getData("country") == $q_master->getData("country") && $q_rel->getData("state") == $q_master->getData("state") && $q_rel->getData("street") == $q_master->getData("street") && $q_rel->getData("zipcode") == $q_master->getData("zipcode")) { $found = true; break; } else { $found = false; } } if (!$found) { $q->query("update contact_address set idcontact = " . $id_to_keep . " where idcontact_address = " . $q_rel->getData("idcontact_address")); } } } } else { $q->query("update contact_address set idcontact = " . $id_to_keep . " where idcontact = " . $contact_id_del); } //Update the ContactRssFeed with $id_to_keep $q = new sqlQuery($this->getDbCon()); $q_master = new sqlQuery($this->getDbCon()); $q_rel = new sqlQuery($this->getDbCon()); $q_master->query("select * from contact_rss_feed where idcontact = " . $id_to_keep); if ($q_master->getNumRows() > 0) { $update_ids_array = array(); $q_rel->query("select * from contact_rss_feed where idcontact = " . $contact_id_del); if ($q_rel->getNumRows()) { while ($q_rel->fetch()) { $found = true; while ($q_master->fetch()) { if ($q_rel->getData("feed_type") == $q_master->getData("feed_type") && $q_rel->getData("rss_feed_url") == $q_master->getData("rss_feed_url") && $q_rel->getData("username") == $q_master->getData("username")) { $found = true; break; } else { $found = false; } } if (!$found) { $q->query("update contact_rss_feed set idcontact = " . $id_to_keep . " where idcontact_rss_feed = " . $q_rel->getData("idcontact_rss_feed")); } } } } else { $q->query("update contact_rss_feed set idcontact = " . $id_to_keep . " where idcontact = " . $contact_id_del); } $q = new sqlQuery($this->getDbCon()); //Update the ContactNotes with $id_to_keep $q->query("update contact_note set idcontact = " . $id_to_keep . " where idcontact = " . $contact_id_del); //Update the Contacttasks with $id_to_keep $q->query("update task set idcontact = " . $id_to_keep . " where idcontact = " . $contact_id_del); //update the invoice with #id_to_keep and idcompany $idcompany = $this->getIdCompanyForContact($id_to_keep); $inv_addr = $this->ajaxGetInvoiceAddress($id_to_keep); $q->query("update invoice set idcontact = " . $id_to_keep . ",idcompany = {$idcompany},invoice_address='{$inv_addr}' where idcontact = " . $contact_id_del); //Update the google_contact_info with $id_to_keep //$q->query("update google_contact_info set idcontact = ".$id_to_keep. " where idcontact = ".$contact_id_del); // Update the shared contact $do_cont_sharing->resetContactSharingOnMerging($id_to_keep, $contact_id_del); // delete contact $do_deleting_contact->getId($contact_id_del); $do_deleting_contact->delete(); } } // For each ends here $do_deleting_contact->free(); //exit; //$rlog = new UpdateRecordLog(); //$rlog->setLastUpdate("contact", $id_to_keep); //$this->setActivity(); return $id_to_keep; } else { return false; } }
/** * Function to delete tags for a contact which is shared * @param object $Obj , holding the tag data */ function deleteTagShared($Obj) { $do_contact_sharing = new ContactSharing(); $do_contact_view = new ContactView(); $shared_co_workers = $do_contact_sharing->selectAllUsersFromContactSharing($Obj->idreference); //print_r($shared_co_workers);exit; if ($shared_co_workers !== false) { $q = new sqlQuery($this->getDbCon()); foreach ($shared_co_workers as $user) { if ($Obj->iduser != $user) { $idtag = $this->isTagExistsForReferer($Obj->tag_name, $Obj->idreference, $user, $Obj->reference_type); //echo $Obj->tag_name.'----'.$Obj->idcontact.'----'.$Obj->reference_type.'---'.$user;exit; if ($idtag !== false) { $q->query("delete from " . $this->table . " where idtag = " . $idtag . " limit 1 "); $do_contact_view->setUser($user); $do_contact_view->deleteTag($Obj->tag_name, $Obj->idreference); } } } } }