Пример #1
0
 /**
  * Create test user
  *
  */
 public function setUp()
 {
     $this->markTestIncomplete('Skipping for now while investigating');
     //setup test portal user
     $this->_setupTestUser();
     $this->_soapClient = new nusoapclient($GLOBALS['sugar_config']['site_url'] . '/soap.php', false, false, false, false, false, 600, 600);
     $this->_login();
     //setup test account
     $account = new Account();
     $account->name = 'test account for bug 39855';
     $account->assigned_user_id = 'SugarUser';
     $account->save();
     $this->_acc = $account;
     //setup test cases
     $case1 = new aCase();
     $case1->name = 'test case for bug 39855 ASDF';
     $case1->account_id = $this->_acc->id;
     $case1->status = 'New';
     $case1->save();
     $this->_case1 = $case1;
     $case2 = new aCase();
     //$account->id = 'a_'.$unid;
     $case2->name = 'test case for bug 39855 QWER';
     $case2->account_id = $this->_acc->id;
     $case2->status = 'Rejected';
     $case2->save();
     $this->_case2 = $case2;
 }
Пример #2
0
 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);
 }
Пример #3
0
 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();
 }
Пример #4
0
 public function testGetRelatedBean()
 {
     $team_id = 1;
     $case = new aCase();
     $case->name = 'testBug47949';
     $case->team_id = $team_id;
     $case->team_set_id = 1;
     $case->save();
     $beans = $case->get_linked_beans('teams', 'Team');
     // teams is based on Link (not Link2), should still work
     $this->assertEquals(1, count($beans), 'should have one and only one team');
     $this->assertEquals($team_id, $beans[0]->id, 'incorrect team id, should be ' . $team_id);
     // cleanup
     $GLOBALS['db']->query("delete from cases where id= '{$case->id}'");
 }
Пример #5
0
 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();
     }
 }
Пример #6
0
 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();
 }
Пример #7
0
/*********************************************************************************
 * Description:  TODO: To be written.
 * 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'];
    /**
     * returns the HTML for InboundEmail system settings
     * @return string HTML
     */
    function getSystemSettingsForm()
    {
        global $sugar_config;
        global $mod_strings;
        global $app_strings;
        global $app_list_strings;
        ////	Case Macro
        if (!class_exists('aCase')) {
        }
        $c = new aCase();
        $macro = $c->getEmailSubjectMacro();
        ////	Save Raw Source
        $saveRawYes = 'CHECKED';
        $saveRawNo = 'CHECKED';
        if (isset($sugar_config['email_inbound_save_raw']) && $sugar_config['email_inbound_save_raw'] == true) {
            $saveRawNo = '';
        } else {
            $saveRawYes = '';
        }
        ////	max auto-response
        $maxAuto = isset($sugar_config['email_num_autoreplies_24_hours']) && !empty($sugar_config['email_num_autoreplies_24_hours']) ? $sugar_config['email_num_autoreplies_24_hours'] : 10;
        $ret = <<<eoq
\t\t\t<form action="index.php" method="post" name="Macro" id="form">
\t\t\t\t\t\t<input type="hidden" name="module" value="InboundEmail">
\t\t\t\t\t\t<input type="hidden" name="action" value="ListView">
\t\t\t\t\t\t<input type="hidden" name="save" value="true">

\t\t\t<table width="100%" cellpadding="0" cellspacing="0" border="0">
\t\t\t\t<tr>
\t\t\t\t\t<td>
\t\t\t\t\t\t<input \ttitle="{$app_strings['LBL_SAVE_BUTTON_TITLE']}"
\t\t\t\t\t\t\t\taccessKey="{$app_strings['LBL_SAVE_BUTTON_KEY']}"
\t\t\t\t\t\t\t\tclass="button"
\t\t\t\t\t\t\t\tonclick="this.form.return_module.value='InboundEmail'; this.form.return_action.value='ListView';"
\t\t\t\t\t\t\t\ttype="submit" name="Edit" value="  {$app_strings['LBL_SAVE_BUTTON_LABEL']}  ">
\t\t\t\t\t</td>
\t\t\t\t</tr>
\t\t\t</table>

\t\t\t<table width="100%" border="0" cellspacing="0" cellpadding="0" class="detail view">
\t\t\t\t<tr>
\t\t\t\t\t<td valign="top" width='10%' NOWRAP scope="row">
\t\t\t\t\t\t<slot>
\t\t\t\t\t\t\t<b>{$mod_strings['LBL_CASE_MACRO']}:</b>
\t\t\t\t\t\t</slot>
\t\t\t\t\t</td>
\t\t\t\t\t<td valign="top" width='20%'>
\t\t\t\t\t\t<slot>
\t\t\t\t\t\t\t<input name="inbound_email_case_macro" type="text" value="{$macro}">
\t\t\t\t\t\t</slot>
\t\t\t\t\t</td>
\t\t\t\t\t<td valign="top" width='70%'>
\t\t\t\t\t\t<slot>
\t\t\t\t\t\t\t{$mod_strings['LBL_CASE_MACRO_DESC']}
\t\t\t\t\t\t\t<br />
\t\t\t\t\t\t\t<i>{$mod_strings['LBL_CASE_MACRO_DESC2']}</i>
\t\t\t\t\t\t</slot>
\t\t\t\t\t</td>
\t\t\t\t</tr>
\t\t\t\t<tr>
\t\t\t\t\t<td valign="top" width='10%' NOWRAP scope="row">
\t\t\t\t\t\t<slot>
\t\t\t\t\t\t\t<b>{$mod_strings['LBL_SAVE_RAW']}:</b>
\t\t\t\t\t\t</slot>
\t\t\t\t\t</td>
\t\t\t\t\t<td valign="top" width='20%'>
\t\t\t\t\t\t<slot>
\t\t\t\t\t\t\t<input type='radio' name='email_inbound_save_raw' value="1"{$saveRawYes}> {$app_list_strings['checkbox_dom']['1']}&nbsp;
\t\t\t\t\t\t\t<input type='radio' name='email_inbound_save_raw' value="2"{$saveRawNo}> {$app_list_strings['checkbox_dom']['2']}
\t\t\t\t\t\t</slot>
\t\t\t\t\t</td>
\t\t\t\t\t<td valign="top" width='70%'>
\t\t\t\t\t\t<slot>
\t\t\t\t\t\t\t{$mod_strings['LBL_SAVE_RAW_DESC_1']}
\t\t\t\t\t\t\t<br />
\t\t\t\t\t\t\t<i>{$mod_strings['LBL_SAVE_RAW_DESC_2']}</i>
\t\t\t\t\t\t</slot>
\t\t\t\t\t</td>
\t\t\t\t</tr>
\t\t\t\t<tr>
\t\t\t\t\t<td valign="top" width='10%' NOWRAP scope="row">
\t\t\t\t\t\t<slot>
\t\t\t\t\t\t\t<b>{$mod_strings['LBL_MAX_AUTO_REPLIES']}:</b>
\t\t\t\t\t\t</slot>
\t\t\t\t\t</td>
\t\t\t\t\t<td valign="top" width='20%'>
\t\t\t\t\t\t<slot>
\t\t\t\t\t\t\t<input type='text' class='input' name='email_num_autoreplies_24_hours' value="{$maxAuto}">
\t\t\t\t\t\t</slot>
\t\t\t\t\t</td>
\t\t\t\t\t<td valign="top" width='70%'>
\t\t\t\t\t\t<slot>
\t\t\t\t\t\t\t{$mod_strings['LBL_MAX_AUTO_REPLIES_DESC']}
\t\t\t\t\t\t\t<br />
\t\t\t\t\t\t\t<!-- i>{$mod_strings['LBL_SAVE_RAW_DESC_2']}</i-->
\t\t\t\t\t\t</slot>
\t\t\t\t\t</td>
\t\t\t\t</tr>
\t\t\t</table>
\t\t\t</form>
eoq;
        return $ret;
    }
Пример #9
0
 public function testgetAccount()
 {
     $aCase = new aCase();
     $result = $aCase->getAccount(1);
     $this->assertTrue(is_array($result));
     $this->assertEquals(array('account_name' => '', 'account_id' => ''), $result);
 }
Пример #10
0
 private function sendClosureEmail(aCase $bean)
 {
     if (!isAOPEnabled()) {
         return;
     }
     $GLOBALS['log']->warn("CaseUpdatesHook: sendClosureEmail called");
     require_once "include/SugarPHPMailer.php";
     $mailer = new SugarPHPMailer();
     $admin = new Administration();
     $admin->retrieveSettings();
     $mailer->prepForOutbound();
     $mailer->setMailerForSystem();
     $email_template = new EmailTemplate();
     $aop_config = $this->getAOPConfig();
     $email_template = $email_template->retrieve($aop_config['case_closure_email_template_id']);
     if (!$email_template) {
         $GLOBALS['log']->warn("CaseUpdatesHook: sendClosureEmail template is empty");
         return false;
     }
     $contact = $bean->get_linked_beans("contacts", "Contact");
     if ($contact) {
         $contact = $contact[0];
     } else {
         return false;
     }
     $emailSettings = getPortalEmailSettings();
     $text = $this->populateTemplate($email_template, $bean, $contact);
     $mailer->Subject = $text['subject'];
     $mailer->Body = $text['body'];
     $mailer->IsHTML(true);
     $mailer->AltBody = $text['body_alt'];
     $mailer->From = $emailSettings['from_address'];
     $mailer->FromName = $emailSettings['from_name'];
     $email = $contact->emailAddress->getPrimaryAddress($contact);
     $mailer->AddAddress($email);
     if (!$mailer->Send()) {
         $GLOBALS['log']->info("CaseUpdatesHook: Could not send email:  " . $mailer->ErrorInfo);
         return false;
     } else {
         $this->logEmail($email, $mailer, $bean->id);
         return true;
     }
 }
Пример #11
0
 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 syncticket($session, $data)
 {
     $GLOBALS['log']->error("syncticket");
     if (!self::$helperObject->checkSessionAndModuleAccess($session, 'invalid_session', 'Cases', 'write', 'no_access', new SoapError())) {
         echo "No access";
         return;
     }
     $admin = new Administration();
     $admin->retrieveSettings('system');
     $ticket = new SimpleXMLElement(str_replace('!AMP!', '&', $data));
     $GLOBALS['log']->error("find or create case");
     $case = new aCase();
     $nice_id = (int) $ticket->{'nice-id'};
     if ($case = $case->retrieve_by_string_fields(array('zendesk_ticket_id_c' => $nice_id))) {
         $GLOBALS['log']->error("found case " . $case->id);
     } else {
         $GLOBALS['log']->error("creating new case");
         $case = new aCase();
     }
     $case->zendesk_ticket_id_c = $nice_id;
     $case->name = $ticket->subject;
     if ($admin->settings['system_zendesk_status_map']) {
         $mapped_to = $admin->settings['system_zendesk_status_map'];
         $mapped_field = 'system_zendesk_status_map_' . $ticket->{'status-id'};
         $case->{$mapped_to} = $admin->settings[$mapped_field];
     }
     if ($admin->settings['system_zendesk_priority_map']) {
         $mapped_to = $admin->settings['system_zendesk_priority_map'];
         $mapped_field = 'system_zendesk_priority_map_' . $ticket->{'priority-id'};
         $case->{$mapped_to} = $admin->settings[$mapped_field];
     }
     if ($admin->settings['system_zendesk_type_map']) {
         $mapped_to = $admin->settings['system_zendesk_type_map'];
         $mapped_field = 'system_zendesk_type_map_' . $ticket->{'ticket-type-id'};
         $case->{$mapped_to} = $admin->settings[$mapped_field];
     }
     $requester = $ticket->requester;
     if ($requester->organization) {
         $account = new Account();
         if ($account = $account->retrieve_by_string_fields(array('name' => $requester->organization->name))) {
             $GLOBALS['log']->error("found account " . $account->id);
         } else {
             $account = new Account();
             $account->name = $requester->organization->name;
             $account->save();
             $GLOBALS['log']->error("created account " . $account->id);
         }
         $case->account_id = $account->id;
     }
     $GLOBALS['log']->error("save case with zendesk_ticket_id_c " . $case->zendesk_ticket_id_c);
     $case->save();
     $GLOBALS['log']->error("associate contacts");
     if ($case->load_relationship('contacts')) {
         $ea = new EmailAddress();
         $ids = $ea->getRelatedId($requester->email, 'contacts');
         if (!empty($ids)) {
             $case->contacts->add($ids);
         } else {
             $contact = new Contact();
             $contact->email1 = $requester->email;
             $names = split(' ', $requester->name);
             $contact->last_name = $names[count($names) - 1];
             $contact->first_name = join(' ', array_slice($names, 0, -1));
             $contact->save();
             $case->contacts->add(array($contact->id));
         }
     }
     $GLOBALS['log']->error("syncticket done");
     echo "OK " . $case->id;
 }
Пример #13
0
 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.");
             }
         }
     }
 }
Пример #14
0
 function handleCreateCase($email, $userId)
 {
     global $current_user, $mod_strings, $current_language;
     $mod_strings = return_module_language($current_language, "Emails");
     $GLOBALS['log']->debug('In handleCreateCase in AOPInboundEmail');
     $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();
         $notes = $email->get_linked_beans('notes', 'Notes');
         $noteIds = array();
         foreach ($notes as $note) {
             $noteIds[] = $note->id;
         }
         if ($email->description_html) {
             $c->description = $this->processImageLinks(SugarCleaner::cleanHtml($email->description_html), $noteIds);
         } else {
             $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
         $contactIds = $this->getRelatedId($contactAddr, 'contacts');
         if (!empty($contactIds)) {
             $c->contact_created_by_id = $contactIds[0];
         }
         $c->save(true);
         $caseId = $c->id;
         $c = new aCase();
         $c->retrieve($caseId);
         if ($c->load_relationship('emails')) {
             $c->emails->add($email->id);
         }
         // if
         if (!empty($contactIds) && $c->load_relationship('contacts')) {
             if (!$accountIds && count($contactIds) == 1) {
                 $contact = BeanFactory::getBean('Contacts', $contactIds[0]);
                 if ($contact->load_relationship('accounts')) {
                     $acct = $contact->accounts->get();
                     if ($c->load_relationship('accounts') && !empty($acct[0])) {
                         $c->accounts->add($acct[0]);
                     }
                 }
             }
             $c->contacts->add($contactIds);
         }
         // if
         foreach ($notes as $note) {
             //Link notes to case also
             $newNote = BeanFactory::newBean('Notes');
             $newNote->name = $note->name;
             $newNote->file_mime_type = $note->file_mime_type;
             $newNote->filename = $note->filename;
             $newNote->parent_type = 'Cases';
             $newNote->parent_id = $c->id;
             $newNote->save();
             $srcFile = "upload://{$note->id}";
             $destFile = "upload://{$newNote->id}";
             copy($srcFile, $destFile);
         }
         $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 {
         echo "First if not matching\n";
         if (!empty($email->reply_to_email)) {
             $contactAddr = $email->reply_to_email;
         } else {
             $contactAddr = $email->from_addr;
         }
         $this->handleAutoresponse($email, $contactAddr);
     }
     echo "End of handle create case\n";
 }
 }
 $account->billing_address_postalcode = mt_rand(10000, 99999);
 $account->billing_address_country = 'USA';
 $account->shipping_address_street = $account->billing_address_street;
 $account->shipping_address_city = $account->billing_address_city;
 $account->shipping_address_state = $account->billing_address_state;
 $account->shipping_address_postalcode = $account->billing_address_postalcode;
 $account->shipping_address_country = $account->billing_address_country;
 $key = array_rand($app_list_strings['industry_dom']);
 $account->industry = $app_list_strings['industry_dom'][$key];
 $account->account_type = "Customer";
 $account->save();
 $account_ids[] = $account->id;
 $accounts[] = $account;
 // Create a case for the account
 $case = new aCase();
 $case->account_id = $account->id;
 $case->priority = $casePriority[mt_rand(0, 2)];
 $case->status = $caseStatus[mt_rand(0, 4)];
 $case->name = $case_seed_names[mt_rand(0, 4)];
 $case->assigned_user_id = $account->assigned_user_id;
 $case->assigned_user_name = $account->assigned_user_name;
 $case->save();
 $note = new Note();
 $note->parent_type = 'Accounts';
 $note->parent_id = $account->id;
 $seed_data_index = mt_rand(0, 3);
 $note->name = $note_seed_names_and_Descriptions[$seed_data_index][0];
 $note->description = $note_seed_names_and_Descriptions[$seed_data_index][1];
 $note->assigned_user_id = $account->assigned_user_id;
 $note->assigned_user_name = $account->assigned_user_name;
Пример #16
0
 /**
  * For mailboxes of type "Support" parse for '[CASE:%1]'
  *
  * @param string $emailName The subject line of the email
  * @param aCase  $aCase     A Case object
  *
  * @return string|boolean   Case ID or FALSE if not found
  */
 function getCaseIdFromCaseNumber($emailName, $aCase)
 {
     //$emailSubjectMacro
     $exMacro = explode('%1', $aCase->getEmailSubjectMacro());
     $open = $exMacro[0];
     $close = $exMacro[1];
     if ($sub = stristr($emailName, $open)) {
         // eliminate everything up to the beginning of the macro and return the rest
         // $sub is [CASE:XX] xxxxxxxxxxxxxxxxxxxxxx
         $sub2 = str_replace($open, '', $sub);
         // $sub2 is XX] xxxxxxxxxxxxxx
         $sub3 = substr($sub2, 0, strpos($sub2, $close));
         // case number is supposed to be numeric
         if (ctype_digit($sub3)) {
             // filter out deleted records in order to create a new case
             // if email is related to deleted one (bug #49840)
             $query = 'SELECT id FROM cases WHERE case_number = ' . $this->db->quoted($sub3) . ' and deleted = 0';
             $r = $this->db->query($query, true);
             $a = $this->db->fetchByAssoc($r);
             if (!empty($a['id'])) {
                 return $a['id'];
             }
         }
     }
     return false;
 }
Пример #17
0
 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;
 }
Пример #18
0
 /**
  * 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;
 }
Пример #19
0
 *
 * All copies of the Covered Code must include on each user interface screen:
 *    (i) the "Powered by SugarCRM" logo and
 *    (ii) the SugarCRM copyright notice
 * in the same form as they appear in the distribution.  See full license for
 * requirements.
 *
 * The Original Code is: SugarCRM Open Source
 * The Initial Developer of the Original Code is SugarCRM, Inc.
 * Portions created by SugarCRM are Copyright (C) 2004-2006 SugarCRM, Inc.;
 * All Rights Reserved.
 * Contributor(s): ______________________________________.
 ********************************************************************************/
/*********************************************************************************
 * Description:  TODO: To be written.
 * Portions created by SugarCRM are Copyright (C) SugarCRM, Inc.
 * All Rights Reserved.
 * Contributor(s): ______________________________________..
 ********************************************************************************/
require_once 'modules/Cases/Case.php';
$focus = new aCase();
if (!isset($_REQUEST['record'])) {
    sugar_die("A record number must be specified to delete the case.");
}
$focus->retrieve($_REQUEST['record']);
if (!$focus->ACLAccess('Delete')) {
    ACLController::displayNoAccess(true);
    sugar_cleanup(true);
}
$focus->mark_deleted($_REQUEST['record']);
header("Location: index.php?module=" . $_REQUEST['return_module'] . "&action=" . $_REQUEST['return_action'] . "&record=" . $_REQUEST['return_id']);
Пример #20
0
function create_case($user_name, $password, $name)
{
    if (!validate_user($user_name, $password)) {
        return 0;
    }
    //todo make the activity body not be html encoded
    $seed_user = new User();
    $user_id = $seed_user->retrieve_user_id($user_name);
    $case = new aCase();
    if (!$case->ACLAccess('Save')) {
        return -1;
    }
    $case->assigned_user_id = $user_id;
    $case->assigned_user_name = $user_name;
    $case->name = $name;
    return $case->save();
}
Пример #21
0
				</script>';
    $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;
Пример #22
0
    /**
     * returns the HTML for InboundEmail system settings
     * @return string HTML
     */
    function getSystemSettingsForm()
    {
        global $sugar_config;
        global $mod_strings;
        global $app_strings;
        global $app_list_strings;
        ////	Case Macro
        $c = new aCase();
        $macro = $c->getEmailSubjectMacro();
        $ret = <<<eoq
\t\t\t<form action="index.php" method="post" name="Macro" id="form">
\t\t\t\t\t\t<input type="hidden" name="module" value="InboundEmail">
\t\t\t\t\t\t<input type="hidden" name="action" value="ListView">
\t\t\t\t\t\t<input type="hidden" name="save" value="true">

\t\t\t<table width="100%" cellpadding="0" cellspacing="0" border="0">
\t\t\t\t<tr>
\t\t\t\t\t<td>
\t\t\t\t\t\t<input \ttitle="{$app_strings['LBL_SAVE_BUTTON_TITLE']}"
\t\t\t\t\t\t\t\taccessKey="{$app_strings['LBL_SAVE_BUTTON_KEY']}"
\t\t\t\t\t\t\t\tclass="button"
\t\t\t\t\t\t\t\tonclick="this.form.return_module.value='InboundEmail'; this.form.return_action.value='ListView';"
\t\t\t\t\t\t\t\ttype="submit" name="Edit" value="  {$app_strings['LBL_SAVE_BUTTON_LABEL']}  ">
\t\t\t\t\t</td>
\t\t\t\t</tr>
\t\t\t</table>

\t\t\t<table width="100%" border="0" cellspacing="0" cellpadding="0" class="detail view">
\t\t\t\t<tr>
\t\t\t\t\t<td valign="top" width='10%' NOWRAP scope="row">
\t\t\t\t\t\t<slot>
\t\t\t\t\t\t\t<b>{$mod_strings['LBL_CASE_MACRO']}:</b>
\t\t\t\t\t\t</slot>
\t\t\t\t\t</td>
\t\t\t\t\t<td valign="top" width='20%'>
\t\t\t\t\t\t<slot>
\t\t\t\t\t\t\t<input name="inbound_email_case_macro" type="text" value="{$macro}">
\t\t\t\t\t\t</slot>
\t\t\t\t\t</td>
\t\t\t\t\t<td valign="top" width='70%'>
\t\t\t\t\t\t<slot>
\t\t\t\t\t\t\t{$mod_strings['LBL_CASE_MACRO_DESC']}
\t\t\t\t\t\t\t<br />
\t\t\t\t\t\t\t<i>{$mod_strings['LBL_CASE_MACRO_DESC2']}</i>
\t\t\t\t\t\t</slot>
\t\t\t\t\t</td>
\t\t\t\t</tr>
\t\t\t</table>
\t\t\t</form>
eoq;
        return $ret;
    }
    /**
     * returns the HTML for the Case macro setting
     * @return string form
     */
    function getCaseMacroForm()
    {
        global $mod_strings;
        global $app_strings;
        if (!class_exists('aCase')) {
            require_once 'modules/Cases/Case.php';
        }
        $c = new aCase();
        $macro = $c->getEmailSubjectMacro();
        $ret = <<<eoq
\t\t\t<form action="index.php" method="post" name="Macro" id="form">
\t\t\t\t\t\t<input type="hidden" name="module" value="InboundEmail">
\t\t\t\t\t\t<input type="hidden" name="action" value="ListView">
\t\t\t\t\t\t<input type="hidden" name="save" value="true">

\t\t\t<table width="100%" cellpadding="0" cellspacing="0" border="0">
\t\t\t\t<tr>
\t\t\t\t\t<td style="padding-bottom: 2px;">
\t\t\t\t\t\t<input \ttitle="{$app_strings['LBL_SAVE_BUTTON_TITLE']}"
\t\t\t\t\t\t\t\taccessKey="{$app_strings['LBL_SAVE_BUTTON_KEY']}"
\t\t\t\t\t\t\t\tclass="button"
\t\t\t\t\t\t\t\tonclick="this.form.return_module.value='InboundEmail'; this.form.return_action.value='ListView';"
\t\t\t\t\t\t\t\ttype="submit" name="Edit" value="  {$app_strings['LBL_SAVE_BUTTON_LABEL']}  ">
\t\t\t\t\t</td>
\t\t\t\t</tr>
\t\t\t</table>

\t\t\t<table width="100%" border="0" cellspacing="0" cellpadding="0" class="tabDetailView">
\t\t\t\t<tr>
\t\t\t\t\t<td valign="top" class="tabDetailViewDL" width='10%' NOWRAP>
\t\t\t\t\t\t<slot>
\t\t\t\t\t\t\t<b>{$mod_strings['LBL_CASE_MACRO']}:</b>
\t\t\t\t\t\t</slot>
\t\t\t\t\t</td>
\t\t\t\t\t<td valign="top" class="tabDetailViewDF" width='20%'>
\t\t\t\t\t\t<slot>
\t\t\t\t\t\t\t<input name="inbound_email_case_macro" type="text" value="{$macro}">
\t\t\t\t\t\t</slot>
\t\t\t\t\t</td>
\t\t\t\t\t<td valign="top" class="tabDetailViewDF" width='70%'>
\t\t\t\t\t\t<slot>
\t\t\t\t\t\t\t{$mod_strings['LBL_CASE_MACRO_DESC']}
\t\t\t\t\t\t\t<br />
\t\t\t\t\t\t\t<i>{$mod_strings['LBL_CASE_MACRO_DESC2']}</i>
\t\t\t\t\t\t</slot>
\t\t\t\t\t</td>
\t\t\t\t</tr>
\t\t\t</table>
\t\t\t</form>
eoq;
        return $ret;
    }