public function testGetCaseIdFromCaseNumber() { $this->case->save(); $id = $this->case->id; $this->case->disable_row_level_security = true; $this->case->retrieve($id); $number = $this->case->case_number; $ie = new InboundEmail(); $subject = '[CASE:' . $number . ']'; $actual_id = $ie->getCaseIdFromCaseNumber($subject, $this->case); $this->assertEquals($id, $actual_id); }
function display() { $this->ev->process(); echo "<!-- \n"; var_dump($_REQUEST); echo "-->"; if (empty($this->ev->focus->id) && $_REQUEST['return_module'] == 'Cases') { $parent = new aCase(); $parent->retrieve($_REQUEST['return_id']); if (isset($parent->facility_c) && $this->ev->fieldDefs['facility_c']['value'] == "") { $this->ev->fieldDefs['facility_c']['value'] = $parent->facility_c; } if (isset($parent->wellname_c) && $this->ev->fieldDefs['wellname_c']['value'] == "") { $this->ev->fieldDefs['wellname_c']['value'] = $parent->wellname_c; } if (isset($parent->afe_c) && $this->ev->fieldDefs['afe_c']['value'] == "") { $this->ev->fieldDefs['afe_c']['value'] = $parent->afe_c; } if (isset($parent->po_c) && $this->ev->fieldDefs['po_c']['value'] == "") { $this->ev->fieldDefs['po_c']['value'] = $parent->po_c; } if (isset($parent->parish_c) && $this->ev->fieldDefs['parish_c']['value'] == "") { $this->ev->fieldDefs['parish_c']['value'] = $parent->parish_c; } if (isset($parent->areablock_c) && $this->ev->fieldDefs['areablock_c']['value'] == "") { $this->ev->fieldDefs['areablock_c']['value'] = $parent->areablock_c; } if (isset($parent->specialbilling_c) && $this->ev->fieldDefs['specialbilling_c']['value'] == "") { $this->ev->fieldDefs['specialbilling_c']['value'] = $parent->specialbilling_c; } if (isset($parent->lat_c) && $this->ev->fieldDefs['lat_c']['value'] == "") { $this->ev->fieldDefs['lat_c']['value'] = $parent->lat_c; } if (isset($parent->longitude_c) && $this->ev->fieldDefs['longitude_c']['value'] == "") { $this->ev->fieldDefs['longitude_c']['value'] = $parent->longitude_c; } if (isset($parent->drivingdirections_c) && $this->ev->fieldDefs['drivingdirections_c']['value'] == "") { $this->ev->fieldDefs['drivingdirections_c']['value'] = $parent->drivingdirections_c; } if (isset($parent->customer_c) && $this->ev->fieldDefs['customer_c']['value'] == "") { $this->ev->fieldDefs['customer_c']['value'] = $parent->customer_c; } if (isset($parent->contactname_c) && $this->ev->fieldDefs['contactname_c']['value'] == "") { $this->ev->fieldDefs['contactname_c']['value'] = $parent->contactname_c; } if (isset($parent->contactphone_c) && $this->ev->fieldDefs['contactphone_c']['value'] == "") { $this->ev->fieldDefs['contactphone_c']['value'] = $parent->contactphone_c; } } echo $this->ev->display(); }
public function saveUpdate($bean, $event, $arguments) { if (!$bean->id) { //New case so do nothing. return; } if ($_REQUEST['module'] == 'Import') { return; } $oldbean = new aCase(); $oldbean->retrieve($bean->id); $events = $this->compareBeans($oldbean, $bean); foreach ($events as $event) { $event->save(); } }
function display() { $this->ev->process(); echo "<!-- \n"; var_dump($_REQUEST); var_dump($this->ev->fieldDefs); echo "-->"; if (empty($this->ev->focus->id) && $_REQUEST['return_module'] == 'Cases') { $parent = new aCase(); $parent->retrieve($_REQUEST['return_id']); if (isset($parent->jobnumber_c) && $this->ev->fieldDefs['jobnumber_c']['value'] == "") { $this->ev->fieldDefs['jobnumber_c']['value'] = $parent->jobnumber_c; } if (isset($parent->account_id) && $this->ev->fieldDefs['account_id_c']['value'] == "") { $this->ev->fieldDefs['account_id_c']['value'] = $parent->account_id; $this->ev->fieldDefs['account_c']['value'] = $parent->account_name; } } echo $this->ev->display(); }
function handleCreateCase($email, $userId) { global $current_user, $mod_strings, $current_language; $mod_strings = return_module_language($current_language, "Emails"); $GLOBALS['log']->debug('In handleCreateCase'); $c = new aCase(); $this->getCaseIdFromCaseNumber($email->name, $c); if (!$this->handleCaseAssignment($email) && $this->isMailBoxTypeCreateCase()) { // create a case $GLOBALS['log']->debug('retrieveing email'); $email->retrieve($email->id); $c = new aCase(); $c->description = $email->description; $c->assigned_user_id = $userId; $c->name = $email->name; $c->status = 'New'; $c->priority = 'P1'; if (!empty($email->reply_to_email)) { $contactAddr = $email->reply_to_email; } else { $contactAddr = $email->from_addr; } $GLOBALS['log']->debug('finding related accounts with address ' . $contactAddr); if ($accountIds = $this->getRelatedId($contactAddr, 'accounts')) { if (sizeof($accountIds) == 1) { $c->account_id = $accountIds[0]; $acct = new Account(); $acct->retrieve($c->account_id); $c->account_name = $acct->name; } // if } // if $c->save(true); $caseId = $c->id; $c = new aCase(); $c->retrieve($caseId); if ($c->load_relationship('emails')) { $c->emails->add($email->id); } // if if ($contactIds = $this->getRelatedId($contactAddr, 'contacts')) { if (!empty($contactIds) && $c->load_relationship('contacts')) { $c->contacts->add($contactIds); } // if } // if $c->email_id = $email->id; $email->parent_type = "Cases"; $email->parent_id = $caseId; // assign the email to the case owner $email->assigned_user_id = $c->assigned_user_id; $email->name = str_replace('%1', $c->case_number, $c->getEmailSubjectMacro()) . " " . $email->name; $email->save(); $GLOBALS['log']->debug('InboundEmail created one case with number: ' . $c->case_number); $createCaseTemplateId = $this->get_stored_options('create_case_email_template', ""); if (!empty($this->stored_options)) { $storedOptions = unserialize(base64_decode($this->stored_options)); } if (!empty($createCaseTemplateId)) { $fromName = ""; $fromAddress = ""; if (!empty($this->stored_options)) { $fromAddress = $storedOptions['from_addr']; $fromName = from_html($storedOptions['from_name']); $replyToName = !empty($storedOptions['reply_to_name']) ? from_html($storedOptions['reply_to_name']) : $fromName; $replyToAddr = !empty($storedOptions['reply_to_addr']) ? $storedOptions['reply_to_addr'] : $fromAddress; } // if $defaults = $current_user->getPreferredEmail(); $fromAddress = !empty($fromAddress) ? $fromAddress : $defaults['email']; $fromName = !empty($fromName) ? $fromName : $defaults['name']; $to[0]['email'] = $contactAddr; // handle to name: address, prefer reply-to if (!empty($email->reply_to_name)) { $to[0]['display'] = $email->reply_to_name; } elseif (!empty($email->from_name)) { $to[0]['display'] = $email->from_name; } $et = new EmailTemplate(); $et->retrieve($createCaseTemplateId); if (empty($et->subject)) { $et->subject = ''; } if (empty($et->body)) { $et->body = ''; } if (empty($et->body_html)) { $et->body_html = ''; } $et->subject = "Re:" . " " . str_replace('%1', $c->case_number, $c->getEmailSubjectMacro() . " " . $c->name); $html = trim($email->description_html); $plain = trim($email->description); $email->email2init(); $email->from_addr = $email->from_addr_name; $email->to_addrs = $email->to_addrs_names; $email->cc_addrs = $email->cc_addrs_names; $email->bcc_addrs = $email->bcc_addrs_names; $email->from_name = $email->from_addr; $email = $email->et->handleReplyType($email, "reply"); $ret = $email->et->displayComposeEmail($email); $ret['description'] = empty($email->description_html) ? str_replace("\n", "\n<BR/>", $email->description) : $email->description_html; $reply = new Email(); $reply->type = 'out'; $reply->to_addrs = $to[0]['email']; $reply->to_addrs_arr = $to; $reply->cc_addrs_arr = array(); $reply->bcc_addrs_arr = array(); $reply->from_name = $fromName; $reply->from_addr = $fromAddress; $reply->reply_to_name = $replyToName; $reply->reply_to_addr = $replyToAddr; $reply->name = $et->subject; $reply->description = $et->body . "<div><hr /></div>" . $email->description; if (!$et->text_only) { $reply->description_html = $et->body_html . "<div><hr /></div>" . $email->description; } $GLOBALS['log']->debug('saving and sending auto-reply email'); //$reply->save(); // don't save the actual email. $reply->send(); } // if } else { if (!empty($email->reply_to_email)) { $contactAddr = $email->reply_to_email; } else { $contactAddr = $email->from_addr; } $this->handleAutoresponse($email, $contactAddr); } }
/** * Formats email body on reply/forward * @param object email Email object in focus * @param string type * @return object email */ function handleReplyType($email, $type) { global $mod_strings; $GLOBALS['log']->debug("****At Handle Reply Type: {$type}"); switch ($type) { case "reply": case "replyAll": $header = $email->getReplyHeader(); if (!preg_match('/^(re:)+/i', $email->name)) { $email->name = "{$mod_strings['LBL_RE']} {$email->name}"; } if ($type == "reply") { $email->cc_addrs = ""; if (!empty($email->reply_to_addr)) { $email->from_addr = $email->reply_to_addr; } // if } else { if (!empty($email->reply_to_addr)) { $email->to_addrs = $email->to_addrs . "," . $email->reply_to_addr; } // if } // else break; case "forward": $header = $email->getForwardHeader(); if (!preg_match('/^(fw:)+/i', $email->name)) { $email->name = "{$mod_strings['LBL_FW']} {$email->name}"; } $email->cc_addrs = ""; break; case "replyCase": $GLOBALS['log']->debug("EMAILUI: At reply case"); $header = $email->getReplyHeader(); $myCase = new aCase(); $myCase->retrieve($email->parent_id); $myCaseMacro = $myCase->getEmailSubjectMacro(); $email->parent_name = $myCase->name; $GLOBALS['log']->debug("****Case # : {$myCase->case_number} macro: {$myCaseMacro}"); if (!strpos($email->name, str_replace('%1', $myCase->case_number, $myCaseMacro))) { $GLOBALS['log']->debug("Replacing"); $email->name = str_replace('%1', $myCase->case_number, $myCaseMacro) . ' ' . $email->name; } $email->name = "{$mod_strings['LBL_RE']} {$email->name}"; break; } $html = trim($email->description_html); $plain = trim($email->description); $desc = !empty($html) ? $html : $plain; $email->description = $header . $email->quoteHtmlEmailForNewEmailUI($desc); return $email; }
* Portions created by SugarCRM are Copyright (C) SugarCRM, Inc. * All Rights Reserved. * Contributor(s): ______________________________________.. ********************************************************************************/ require_once 'XTemplate/xtpl.php'; require_once 'data/Tracker.php'; require_once 'modules/Cases/Case.php'; require_once 'modules/Cases/Forms.php'; global $app_strings; global $app_list_strings; global $mod_strings; global $current_user; global $sugar_version, $sugar_config; $focus = new aCase(); if (isset($_REQUEST['record'])) { $focus->retrieve($_REQUEST['record']); } if (isset($_REQUEST['isDuplicate']) && $_REQUEST['isDuplicate'] == 'true') { $focus->id = ""; } //needed when creating a new case with a default account value passed in if (isset($_REQUEST['account_name']) && is_null($focus->account_name)) { $focus->account_name = $_REQUEST['account_name']; } if (isset($_REQUEST['account_id']) && is_null($focus->account_id)) { $focus->account_id = $_REQUEST['account_id']; } if (isset($_REQUEST['contact_id']) && is_null($focus->contact_id)) { $focus->contact_id = $_REQUEST['contact_id']; } if (!empty($_REQUEST['status'])) {
$useGroup .= $mod_strings['LBL_USE_MAILBOX_INFO']; $xtpl->assign('FROM_ADDR_GROUP', $useGroup); } //// END INBOUND EMAIL HANDLING /////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////// //// SUBJECT FIELD MANIPULATION $name = ''; if (!empty($_REQUEST['parent_id']) && !empty($_REQUEST['parent_type'])) { $focus->parent_id = $_REQUEST['parent_id']; $focus->parent_type = $_REQUEST['parent_type']; } if (!empty($focus->parent_id) && !empty($focus->parent_type)) { if ($focus->parent_type == 'Cases') { $myCase = new aCase(); $myCase->retrieve($focus->parent_id); $myCaseMacro = $myCase->getEmailSubjectMacro(); if (isset($ieMail->name) && !empty($ieMail->name)) { // if replying directly to an InboundEmail $oldEmailSubj = $ieMail->name; } elseif (isset($_REQUEST['parent_name']) && !empty($_REQUEST['parent_name'])) { $oldEmailSubj = $_REQUEST['parent_name']; } else { $oldEmailSubj = $focus->name; // replying to an email using old subject } if (!preg_match('/^re:/i', $oldEmailSubj)) { $oldEmailSubj = 'RE: ' . $oldEmailSubj; } $focus->name = $oldEmailSubj; if (strpos($focus->name, str_replace('%1', $myCase->case_number, $myCaseMacro))) {
function set_notification_body($xtpl, $task) { global $app_list_strings; global $timedate; $task->custom_fields->retrieve(); $notifyUser = $task->current_notify_user; $prefDate = $notifyUser->getUserDateTimePreferences(); $xtpl->assign("TASK_SUBJECT", $task->name); //MFH #13507 $xtpl->assign("TASK_PRIORITY", isset($task->priority) ? $app_list_strings['task_priority_dom'][$task->priority] : ""); if (!empty($task->date_due)) { $duedate = $timedate->fromDb($task->date_due); $xtpl->assign("TASK_DUEDATE", $timedate->asUser($duedate, $notifyUser) . " " . TimeDate::userTimezoneSuffix($duedate, $notifyUser)); } else { $xtpl->assign("TASK_DUEDATE", ''); } $xtpl->assign("TASK_STATUS", isset($task->status) ? $app_list_strings['task_status_dom'][$task->status] : ""); $xtpl->assign("TASK_DESCRIPTION", $task->description); //Custom Additions $lcase = new aCase(); $lproject = new Project(); $lcase->retrieve($task->parent_id); $linkedprojects = $lcase->get_linked_beans('project', 'Project'); foreach ($linkedprojects as $curproj) { $lproject = $curproj; } $lproject->custom_fields->retrieve(); $xtpl->assign("TASK_PROJECT_NAME", isset($lproject->name) ? $lproject->name : ""); $xtpl->assign("TASK_PROJECT_FACILITY", isset($lproject->facility_c) ? $lproject->facility_c : ""); $xtpl->assign("TASK_JOBNUMBER", isset($task->jobnumber_c) ? $task->jobnumber_c : ""); $xtpl->assign("TASK_CASENUMBER", isset($lcase->case_number) ? $lcase->case_number : ""); $xtpl->assign("TASK_DEPARTMENT", isset($task->department_c) ? $app_list_strings['department_list'][$task->department_c] : ""); $xtpl->assign("TASK_TYPE", isset($task->type_c) ? $app_list_strings['Task_Type_list'][$task->type_c] : ""); $xtpl->assign("TASK_CONTACTNAME", isset($task->contactname_c) ? $task->contactname_c : ""); $xtpl->assign("TASK_CONTACTNUMBER", isset($task->contactnumber_c) ? $task->contactnumber_c : ""); $xtpl->assign("TASK_PARTSSPARESNEEDED", isset($task->partssparesneeded_c) ? $task->partssparesneeded_c : ""); $xtpl->assign("TASK_DOCKHELIPORTLOCATION", isset($task->dockheliportlocation_c) ? $task->dockheliportlocation_c : ""); $xtpl->assign("TASK_VESSELNAME", isset($task->vesselname_c) ? $task->vesselname_c : ""); $xtpl->assign("TASK_ACCOUNT", isset($task->account_c) ? $task->account_c : ""); $xtpl->assign("TASK_WORKLOG", isset($task->worklog_c) ? $task->worklog_c : ""); return $xtpl; }
public function testSetAutoIncrementStart() { $case = new aCase(); $case->name = "foo"; $case->save(); $case->retrieve($case->id); $lastAuto = $case->case_number; $case->deleted = true; $case->save(); $newAuto = $lastAuto + 5; $this->_helper->setAutoIncrementStart("cases", "case_number", $newAuto); $case2 = new aCase(); $case2->name = "foo2"; $case2->save(); $case2->retrieve($case2->id); $case_number = $case2->case_number; $GLOBALS['db']->query("DELETE FROM cases WHERE id= '{$case->id}'"); $GLOBALS['db']->query("DELETE FROM cases WHERE id= '{$case2->id}'"); $this->assertEquals($newAuto, $case_number); }
function postUpdate($bean, $event, $arguments) { if ($bean->parent_type == "Cases" && $bean->parent_id) { $case = new aCase(); $case->retrieve($bean->parent_id); if ($bean->module_dir == "Notes") { if (!$bean->fetched_row) { $this->_sendActivity($case, "The note \"" . $bean->name . "\" has been created."); } else { $this->_sendActivity($case, "The note \"" . $bean->name . "\" has been updated."); } } if ($bean->module_dir == "Tasks") { if (!$bean->fetched_row) { $this->_sendActivity($case, "The task \"" . $bean->name . "\" has been created."); } else { if ($bean->fetched_row["status"] != $bean->status || $bean->fetched_row["priority"] != $bean->priority) { if ($bean->fetched_row["status"] != $bean->status) { $this->_sendActivity($case, "The status of the task \"" . $bean->name . "\" has been changed from " . $bean->fetched_row["status"] . " to " . $bean->status . "."); } if ($bean->fetched_row["priority"] != $bean->priority) { $this->_sendActivity($case, "The priority of the task \"" . $bean->name . "\" has been changed from " . $bean->fetched_row["priority"] . " to " . $bean->priority . "."); } } else { $this->_sendActivity($case, "The task \"" . $bean->name . "\" has been updated."); } } } if ($bean->module_dir == "Calls") { if (!$bean->fetched_row) { $this->_sendActivity($case, "The call \"" . $bean->name . "\" has been created."); } else { $this->_sendActivity($case, "The call \"" . $bean->name . "\" has been updated."); } } if ($bean->module_dir == "Emails") { if (!$bean->fetched_row) { $this->_sendActivity($case, "The email \"" . $bean->name . "\" has been created."); } else { $this->_sendActivity($case, "The email \"" . $bean->name . "\" has been updated."); } } if ($bean->module_dir == "Meetings") { if (!$bean->fetched_row) { $this->_sendActivity($case, "The meeting \"" . $bean->name . "\" has been scheduled to start on " . $bean->date_start . "."); } else { if ($bean->date_start != $bean->fetched_row["date_start"]) { $this->_sendActivity($case, "The meeting \"" . $bean->name . "\" has been re-scheduled to start on " . $bean->date_start . "."); } else { $this->_sendActivity($case, "The meeting \"" . $bean->name . "\" has been updated."); } } } if ($bean->module_dir == "Bugs") { $this->_sendActivity($case, "The bug \"" . $bean->name . "\" has been updated."); } } else { if ($bean->module_dir == "Cases") { if (!$bean->fetched_row) { //The case is new, there is no space listening yet. return; } $sent = false; if ($bean->name != $bean->fetched_row["name"]) { $sent = true; $this->_sendActivity($bean, "The case has been renamed to \"" . $bean->name . "\"."); } if ($bean->priority != $bean->fetched_row["priority"]) { $sent = true; $this->_sendActivity($bean, "The priority if the case has been changed from \"" . $bean->fetched_row["priority"] . "\" to \"" . $bean->priority . "\"."); } if ($bean->fetched_row["status"] != $bean->status) { $sent = true; $this->_sendActivity($bean, "The status of the case has been changed from " . $bean->fetched_row["status"] . " to " . $bean->status . "."); } if (!$sent) { $this->_sendActivity($bean, "The case has been updated."); } } } }
public function testsave() { $aCase = new aCase(); $aCase->name = 'test'; $aCase->priority = 'P1'; $aCase->save(); //test for record ID to verify that record is saved $this->assertTrue(isset($aCase->id)); $this->assertEquals(36, strlen($aCase->id)); //mark the record as deleted and verify that this record cannot be retrieved anymore. $aCase->mark_deleted($aCase->id); $result = $aCase->retrieve($aCase->id); $this->assertEquals(null, $result); }