function track_email($user_name, $password, $contact_ids, $date_sent, $email_subject, $email_body) { if (authentication($user_name, $password)) { global $current_user; global $adb; global $log; require_once 'modules/Users/Users.php'; require_once 'modules/Emails/Emails.php'; $current_user = new Users(); $user_id = $current_user->retrieve_user_id($user_name); $query = "select email1 from vtiger_users where id =?"; $result = $adb->pquery($query, array($user_id)); $user_emailid = $adb->query_result($result, 0, "email1"); $current_user = $current_user->retrieveCurrentUserInfoFromFile($user_id); $email = new Emails(); //$log->debug($msgdtls['contactid']); $emailbody = str_replace("'", "''", $email_body); $emailsubject = str_replace("'", "''", $email_subject); $datesent = substr($date_sent, 1, 10); $mydate = date('Y-m-d', $datesent); $mydate = getDBInsertDateValue($mydate); $email->column_fields[subject] = $emailsubject; $email->column_fields[assigned_user_id] = $user_id; $email->column_fields[date_start] = $mydate; $email->column_fields[description] = $emailbody; $email->column_fields[activitytype] = 'Emails'; $email->plugin_save = true; $email->save("Emails"); $query = "select fieldid from vtiger_field where fieldname = 'email' and tabid = 4 and vtiger_field.presence in (0,2)"; $result = $adb->pquery($query, array()); $field_id = $adb->query_result($result, 0, "fieldid"); $email->set_emails_contact_invitee_relationship($email->id, $contact_ids); $email->set_emails_se_invitee_relationship($email->id, $contact_ids); $email->set_emails_user_invitee_relationship($email->id, $user_id); $sql = "select email from vtiger_contactdetails inner join vtiger_crmentity on vtiger_crmentity.crmid = vtiger_contactdetails.contactid where vtiger_crmentity.deleted =0 and vtiger_contactdetails.contactid=?"; $result = $adb->pquery($sql, array($contact_ids)); $camodulerow = $adb->fetch_array($result); if (isset($camodulerow)) { $emailid = $camodulerow["email"]; //added to save < as $lt; and > as > in the database so as to retrive the emailID $user_emailid = str_replace('<', '<', $user_emailid); $user_emailid = str_replace('>', '>', $user_emailid); $query = 'insert into vtiger_emaildetails values (?,?,?,?,?,?,?,?)'; $params = array($email->id, $emailid, $user_emailid, "", "", "", $user_id . '@-1|' . $contact_ids . '@' . $field_id . '|', "THUNDERBIRD"); $adb->pquery($query, $params); } return $email->id; } }
function AddMessageToContact($username, $session, $contactid, $msgdtls) { if (!validateSession($username, $session)) { return null; } global $current_user; global $adb; require_once 'modules/Users/Users.php'; require_once 'modules/Emails/Emails.php'; $current_user = new Users(); $user_id = $current_user->retrieve_user_id($username); $query = "select email1 from vtiger_users where id = ?"; $result = $adb->pquery($query, array($user_id)); $user_emailid = $adb->query_result($result, 0, "email1"); $current_user = $current_user->retrieveCurrentUserInfoFromFile($user_id); foreach ($msgdtls as $msgdtl) { if (isset($msgdtl)) { $email = new Emails(); //$log->debug($msgdtls['contactid']); $email_body = str_replace("'", "''", $msgdtl['body']); $email_body = str_replace('<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">', " ", $email_body); $email_subject = str_replace("'", "''", $msgdtl['subject']); $date_sent = getDisplayDate($msgdtl['datesent']); $email->column_fields[subject] = $email_subject; $email->column_fields[assigned_user_id] = $user_id; $email->column_fields[date_start] = $date_sent; $email->column_fields[description] = $email_body; $email->column_fields[activitytype] = 'Emails'; $email->column_fields[email_flag] = 'SENT'; $email->plugin_save = true; $email->save("Emails"); $query = "select fieldid from vtiger_field where fieldname = 'email' and tabid = 4 and vtiger_field.presence in (0,2)"; $result = $adb->pquery($query, array()); $field_id = $adb->query_result($result, 0, "fieldid"); $email->set_emails_contact_invitee_relationship($email->id, $contactid); $email->set_emails_se_invitee_relationship($email->id, $contactid); $email->set_emails_user_invitee_relationship($email->id, $user_id); return $email->id; } else { return ""; } } }