Пример #1
1
 /**
  * get recipients of reminding email for specific activity
  * @param string $id
  * @param string $module
  * @return array
  */
 protected function getRecipients($id, $module = "Meetings")
 {
     global $db;
     switch ($module) {
         case "Meetings":
             $field_part = "meeting";
             break;
         case "Calls":
             $field_part = "call";
             break;
         default:
             return array();
     }
     $emails = array();
     // fetch users
     $query = "SELECT user_id FROM {$field_part}s_users WHERE {$field_part}_id = '{$id}' AND accept_status != 'decline' AND deleted = 0\n        ";
     $re = $db->query($query);
     while ($row = $db->fetchByAssoc($re)) {
         $user = new User();
         $user->retrieve($row['user_id']);
         if (!empty($user->email1)) {
             $arr = array('type' => 'Users', 'name' => $user->full_name, 'email' => $user->email1);
             $emails[] = $arr;
         }
     }
     // fetch contacts
     $query = "SELECT contact_id FROM {$field_part}s_contacts WHERE {$field_part}_id = '{$id}' AND accept_status != 'decline' AND deleted = 0";
     $re = $db->query($query);
     while ($row = $db->fetchByAssoc($re)) {
         $contact = new Contact();
         $contact->retrieve($row['contact_id']);
         if (!empty($contact->email1)) {
             $arr = array('type' => 'Contacts', 'name' => $contact->full_name, 'email' => $contact->email1);
             $emails[] = $arr;
         }
     }
     // fetch leads
     $query = "SELECT lead_id FROM {$field_part}s_leads WHERE {$field_part}_id = '{$id}' AND accept_status != 'decline' AND deleted = 0";
     $re = $db->query($query);
     while ($row = $db->fetchByAssoc($re)) {
         $lead = new Lead();
         $lead->retrieve($row['lead_id']);
         if (!empty($lead->email1)) {
             $arr = array('type' => 'Leads', 'name' => $lead->full_name, 'email' => $lead->email1);
             $emails[] = $arr;
         }
     }
     return $emails;
 }
Пример #2
1
	function get_notification_recipients() {
		if($this->special_notification) {
			return parent::get_notification_recipients();
		}

//		$GLOBALS['log']->debug('Call.php->get_notification_recipients():'.print_r($this,true));
		$list = array();
        if(!is_array($this->contacts_arr)) {
			$this->contacts_arr =	array();
		}

		if(!is_array($this->users_arr)) {
			$this->users_arr =	array();
		}

        if(!is_array($this->leads_arr)) {
			$this->leads_arr =	array();
		}

		foreach($this->users_arr as $user_id) {
			$notify_user = new User();
			$notify_user->retrieve($user_id);
			$notify_user->new_assigned_user_name = $notify_user->full_name;
			$GLOBALS['log']->info("Notifications: recipient is $notify_user->new_assigned_user_name");
			$list[$notify_user->id] = $notify_user;
		}

		foreach($this->contacts_arr as $contact_id) {
			$notify_user = new Contact();
			$notify_user->retrieve($contact_id);
			$notify_user->new_assigned_user_name = $notify_user->full_name;
			$GLOBALS['log']->info("Notifications: recipient is $notify_user->new_assigned_user_name");
			$list[$notify_user->id] = $notify_user;
		}

        foreach($this->leads_arr as $lead_id) {
			$notify_user = new Lead();
			$notify_user->retrieve($lead_id);
			$notify_user->new_assigned_user_name = $notify_user->full_name;
			$GLOBALS['log']->info("Notifications: recipient is $notify_user->new_assigned_user_name");
			$list[$notify_user->id] = $notify_user;
		}
		global $sugar_config;
		if(isset($sugar_config['disable_notify_current_user']) && $sugar_config['disable_notify_current_user']) {
			global $current_user;
			if(isset($list[$current_user->id]))
				unset($list[$current_user->id]);
		}
//		$GLOBALS['log']->debug('Call.php->get_notification_recipients():'.print_r($list,true));
		return $list;
	}
Пример #3
0
 function update_tilkee_tilk(&$bean, $event, $arguments = null)
 {
     if ($event != 'before_save') {
         return;
     }
     global $beanFiles;
     $tilk_name = '[TILK] ';
     // Email initialisation
     if ($bean->contacts_id != '') {
         require_once $beanFiles['Contact'];
         $the_contact = new Contact();
         $the_contact->retrieve($bean->contacts_id);
         $bean->contact_email = $the_contact->emailAddress->getPrimaryAddress($the_contact);
         $bean->name = $tilk_name . $the_contact->name;
     }
     if ($bean->leads_id != '') {
         require_once $beanFiles['Lead'];
         $the_lead = new Lead();
         $the_lead->retrieve($bean->leads_id);
         $bean->contact_email = $the_lead->emailAddress->getPrimaryAddress($the_lead);
         $bean->name = $tilk_name . $the_lead->name;
     }
     // delete URL if tilk is archived
     if ($bean->archived == 'true') {
         $bean->tilk_url = '';
     }
 }
Пример #4
0
 /**
  * Create a lead and convert it to an existing Account and Contact
  */
 public function testConvertLinkingExistingContact()
 {
     // Create records
     $lead = SugarTestLeadUtilities::createLead();
     $account = SugarTestAccountUtilities::createAccount();
     $contact = SugarTestContactUtilities::createContact();
     // ConvertLead to an existing Contact and Account
     $_REQUEST = array('module' => 'Leads', 'record' => $lead->id, 'isDuplicate' => 'false', 'action' => 'ConvertLead', 'convert_create_Contacts' => 'false', 'report_to_name' => $contact->name, 'reports_to_id' => $contact->id, 'convert_create_Accounts' => 'false', 'account_name' => $account->name, 'account_id' => $account->id, 'handle' => 'save');
     // Call display to trigger conversion
     $vc = new ViewConvertLead();
     $vc->display();
     // Refresh Lead
     $leadId = $lead->id;
     $lead = new Lead();
     $lead->retrieve($leadId);
     // Refresh Contact
     $contactId = $contact->id;
     $contact = new Contact();
     $contact->retrieve($contactId);
     // Check if contact it's linked properly
     $this->assertEquals($contact->id, $lead->contact_id, 'Contact not linked with Lead successfully.');
     // Check if account is linked with lead properly
     $this->assertEquals($account->id, $lead->account_id, 'Account not linked with Lead successfully.');
     // Check if account is linked with contact properly
     $this->assertEquals($account->id, $contact->account_id, 'Account not linked with Contact successfully.');
     // Check Lead Status, should be converted
     $this->assertEquals('Converted', $lead->status, "Lead status should be 'Converted'.");
 }
Пример #5
0
 function display()
 {
     if (isset($this->bean->lead_id) && !empty($this->bean->lead_id)) {
         //get lead name
         $lead = new Lead();
         $lead->retrieve($this->bean->lead_id);
         $this->ss->assign('lead', $lead);
     }
     parent::display();
 }
Пример #6
0
 function display()
 {
     global $mod_strings, $app_strings, $app_list_strings, $sugar_config, $beanFiles;
     $this->ss->assign("MOD", $mod_strings);
     $this->ss->assign("APP_LIST", $app_list_strings);
     // Init default name
     $this->bean->name = '[TILK] ';
     // IF THE TILK IS CREATED FROM AN CONTACT
     if (isset($_REQUEST['CreateFromContact']) && $_REQUEST['CreateFromContact'] == 'true') {
         // CREATE DEFAULT TILK LINK WITH CONTACT
         require_once $beanFiles['Contact'];
         $link_contact = new Contact();
         $link_contact->retrieve($_REQUEST['return_id']);
         $this->bean->contacts_id = $link_contact->id;
         $this->bean->contacts_name = $link_contact->name;
         $this->bean->contact_email = $link_contact->emailAddress->getPrimaryAddress($link_contact);
         $this->bean->name = '[TILK] ' . $link_contact->name;
         //$this->bean->id     = $this->bean->save();
         $_REQUEST['record'] = $this->bean->id;
         // TILKEE API - CREATE PROJECT AND SYNCH IT
     }
     // IF THE TILK IS CREATED FROM AN LEAD
     if (isset($_REQUEST['CreateFromLead']) && $_REQUEST['CreateFromLead'] == 'true') {
         // CREATE DEFAULT TILK LINK WITH LEAD
         require_once $beanFiles['Lead'];
         $link_lead = new Lead();
         $link_lead->retrieve($_REQUEST['return_id']);
         $this->bean->leads_name = $link_lead->name;
         $this->bean->leads_id = $link_lead->id;
         $this->bean->contact_email = $link_lead->emailAddress->getPrimaryAddress($link_lead);
         $this->bean->name = '[TILK] ' . $link_lead->name;
         //$this->bean->id     = $this->bean->save();
         $_REQUEST['record'] = $this->bean->id;
         // TILKEE API - CREATE PROJECT AND SYNCH IT
     }
     // IF THE TILK IS CREATED FROM AN PROJECT
     if (isset($_REQUEST['CreateFromProject']) && $_REQUEST['CreateFromProject'] == 'true') {
         // CREATE DEFAULT TILK LINK WITH PROJECT
         require_once $beanFiles['TILKEE_PROJECTS'];
         $link_tilkee_project = new TILKEE_PROJECTS();
         $link_tilkee_project->retrieve($_REQUEST['return_id']);
         $this->bean->tilkee_projects_name = $link_tilkee_project->name;
         $this->bean->tilkee_projects_id = $link_tilkee_project->id;
         //$this->bean->id     = $this->bean->save();
         $_REQUEST['record'] = $this->bean->id;
         // TILKEE API - CREATE PROJECT AND SYNCH IT
     }
     parent::display();
 }
Пример #7
0
 /**
  * @group bug40629
  */
 public function testImportedVcardAccountLink()
 {
     $filename = dirname(__FILE__) . "/SimpleVCard.vcf";
     $vcard = new vCard();
     $contact_id = $vcard->importVCard($filename, 'Contacts');
     $contact_record = new Contact();
     $contact_record->retrieve($contact_id);
     $this->assertFalse(empty($contact_record->account_id), "Contact should have an account record associated");
     $GLOBALS['db']->query("delete from contacts where id = '{$contact_id}'");
     $vcard = new vCard();
     $lead_id = $vcard->importVCard($filename, 'Leads');
     $lead_record = new Lead();
     $lead_record->retrieve($lead_id);
     $this->assertTrue(empty($lead_record->account_id), "Lead should not have an account record associated");
     $GLOBALS['db']->query("delete from leads where id = '{$lead_id}'");
 }
Пример #8
0
 /**
  * Saves a new Contact as well as any related items passed in.
  *
  * @return null
  */
 protected function handleSave()
 {
     require_once "include/formbase.php";
     $lead = false;
     if (!empty($_REQUEST['record'])) {
         $lead = new Lead();
         $lead->retrieve($_REQUEST['record']);
     }
     global $beanList;
     $this->loadDefs();
     $beans = array();
     $selectedBeans = array();
     $selects = array();
     //Make sure the contact object is availible for relationships.
     $beans['Contacts'] = new Contact();
     $beans['Contacts']->id = create_guid();
     $beans['Contacts']->new_with_id = true;
     // Bug 39287 - Check for Duplicates on selected modules before save
     if (!empty($_REQUEST['selectedContact'])) {
         $beans['Contacts']->retrieve($_REQUEST['selectedContact']);
         if (!empty($beans['Contacts']->id)) {
             $beans['Contacts']->new_with_id = false;
             unset($_REQUEST["convert_create_Contacts"]);
             unset($_POST["convert_create_Contacts"]);
         }
     } elseif (!empty($_REQUEST["convert_create_Contacts"]) && $_REQUEST["convert_create_Contacts"] != "false" && !isset($_POST['ContinueContact'])) {
         require_once 'modules/Contacts/ContactFormBase.php';
         $contactForm = new ContactFormBase();
         $duplicateContacts = $contactForm->checkForDuplicates('Contacts');
         if (isset($duplicateContacts)) {
             echo $contactForm->buildTableForm($duplicateContacts, 'Contacts');
             return;
         }
     }
     if (!empty($_REQUEST['selectedAccount'])) {
         $_REQUEST['account_id'] = $_REQUEST['selectedAccount'];
         unset($_REQUEST["convert_create_Accounts"]);
         unset($_POST["convert_create_Accounts"]);
     } elseif (!empty($_REQUEST["convert_create_Accounts"]) && $_REQUEST["convert_create_Accounts"] != "false" && empty($_POST['ContinueAccount'])) {
         require_once 'modules/Accounts/AccountFormBase.php';
         $accountForm = new AccountFormBase();
         $duplicateAccounts = $accountForm->checkForDuplicates('Accounts');
         if (isset($duplicateAccounts)) {
             echo $accountForm->buildTableForm($duplicateAccounts);
             return;
         }
     }
     foreach ($this->defs as $module => $vdef) {
         //Create a new record if "create" was selected
         if (!empty($_REQUEST["convert_create_{$module}"]) && $_REQUEST["convert_create_{$module}"] != "false") {
             //Save the new record
             $bean = $beanList[$module];
             if (empty($beans[$module])) {
                 $beans[$module] = new $bean();
             }
             $this->populateNewBean($module, $beans[$module], $beans['Contacts'], $lead);
         } else {
             if (!empty($vdef['ConvertLead']['select'])) {
                 //Save the new record
                 $select = $vdef['ConvertLead']['select'];
                 $fieldDef = $beans['Contacts']->field_defs[$select];
                 if (!empty($fieldDef['id_name']) && !empty($_REQUEST[$fieldDef['id_name']])) {
                     $beans['Contacts']->{$fieldDef}['id_name'] = $_REQUEST[$fieldDef['id_name']];
                     $selects[$module] = $_REQUEST[$fieldDef['id_name']];
                     if (!empty($_REQUEST[$select])) {
                         $beans['Contacts']->{$select} = $_REQUEST[$select];
                     }
                     // Bug 39268 - Add the existing beans to a list of beans we'll potentially add the lead's activities to
                     $bean = loadBean($module);
                     $bean->retrieve($_REQUEST[$fieldDef['id_name']]);
                     $selectedBeans[$module] = $bean;
                 }
             }
         }
     }
     $this->handleActivities($lead, $beans);
     // Bug 39268 - Add the lead's activities to the selected beans
     $this->handleActivities($lead, $selectedBeans);
     //link selected account to lead if it exists
     if (!empty($selectedBeans['Accounts'])) {
         $lead->account_id = $selectedBeans['Accounts']->id;
     }
     //Handle non-contacts relationships
     foreach ($beans as $bean) {
         if (!empty($lead)) {
             if (empty($bean->assigned_user_id)) {
                 $bean->assigned_user_id = $lead->assigned_user_id;
             }
             $leadsRel = $this->findRelationship($bean, $lead);
             if (!empty($leadsRel)) {
                 $bean->load_relationship($leadsRel);
                 $relObject = $bean->{$leadsRel}->getRelationshipObject();
                 if ($relObject->relationship_type == "one-to-many" && $bean->{$leadsRel}->_get_bean_position()) {
                     $id_field = $relObject->rhs_key;
                     $lead->{$id_field} = $bean->id;
                 } else {
                     $bean->{$leadsRel}->add($lead->id);
                 }
             }
         }
         //Special case code for opportunities->Accounts
         if ($bean->object_name == "Opportunity" && empty($bean->account_id)) {
             if (isset($beans['Accounts'])) {
                 $bean->account_id = $beans['Accounts']->id;
                 $bean->account_name = $beans['Accounts']->name;
             } else {
                 if (!empty($selects['Accounts'])) {
                     $bean->account_id = $selects['Accounts'];
                 }
             }
         }
         $this->copyAddressFields($bean, $beans['Contacts']);
         $bean->save();
     }
     if (!empty($lead)) {
         //Mark the original Lead converted
         $lead->status = "Converted";
         $lead->converted = '1';
         $lead->in_workflow = true;
         $lead->save();
     }
     $this->displaySaveResults($beans);
 }
Пример #9
0
 /**
  * Change the parent id and parent type of an activity
  * @param $activity Activity to be modified
  * @param $bean New parent bean of the activity
  */
 protected function moveActivity($activity, $bean)
 {
     global $beanList;
     $lead = null;
     if (!empty($_REQUEST['record'])) {
         $lead = new Lead();
         $lead->retrieve($_REQUEST['record']);
     }
     // delete the old relationship to the old parent (lead)
     if ($rel = $this->findRelationship($activity, $lead)) {
         $activity->load_relationship($rel);
         if ($activity->parent_id && $activity->id) {
             $activity->{$rel}->delete($activity->id, $activity->parent_id);
         }
     }
     // add the new relationship to the new parent (contact, account, etc)
     if ($rel = $this->findRelationship($activity, $bean)) {
         $activity->load_relationship($rel);
         $relObj = $activity->{$rel}->getRelationshipObject();
         if ($relObj->relationship_type == 'one-to-one' || $relObj->relationship_type == 'one-to-many') {
             $key = $relObj->rhs_key;
             $activity->{$key} = $bean->id;
         }
         $activity->{$rel}->add($bean);
     }
     // set the new parent id and type
     $activity->parent_id = $bean->id;
     $activity->parent_type = $bean->module_dir;
     $activity->save();
 }
Пример #10
0
 function converted_lead($leadid, $contactid, $accountid, $opportunityid)
 {
     $query = "UPDATE leads set converted='1', contact_id={$contactid}, account_id={$accountid}, opportunity_id={$opportunityid} where  id={$leadid} and deleted=0";
     $this->db->query($query, true, "Error converting lead: ");
     //we must move the status out here in order to be able to capture workflow conditions
     $leadid = str_replace("'", "", $leadid);
     $lead = new Lead();
     $lead->retrieve($leadid);
     $lead->status = 'Converted';
     $lead->save();
 }
Пример #11
0
    $current_entity = $current_user;
} else {
    if (!empty($_REQUEST['contact_id'])) {
        $current_entity = new Contact();
        $current_entity->disable_row_level_security = true;
        $result = $current_entity->retrieve($_REQUEST['contact_id']);
        if ($result == null) {
            session_destroy();
            sugar_cleanup();
            die("The contact id doesn't exist");
        }
    } else {
        if (!empty($_REQUEST['lead_id'])) {
            $current_entity = new Lead();
            $current_entity->disable_row_level_security = true;
            $result = $current_entity->retrieve($_REQUEST['lead_id']);
            if ($result == null) {
                session_destroy();
                sugar_cleanup();
                die("The lead id doesn't exist");
            }
        }
    }
}
$bean = $beanList[clean_string($_REQUEST['module'])];
require_once $beanFiles[$bean];
$focus = new $bean();
$focus->disable_row_level_security = true;
$result = $focus->retrieve($_REQUEST['record']);
if ($result == null) {
    session_destroy();
Пример #12
0
$xtpl->assign("ALT_ADDRESS_COUNTRY", $focus->alt_address_country);
$xtpl->assign("DESCRIPTION", nl2br(url2html($focus->description)));
$xtpl->assign("DATE_MODIFIED", $focus->date_modified);
$xtpl->assign("DATE_ENTERED", $focus->date_entered);
$xtpl->assign("ACCOUNT_NAME", $focus->account_name);
$detailView->processListNavigation($xtpl, "PROSPECT", $offset);
// adding custom fields:
require_once 'modules/DynamicFields/templates/Files/DetailView.php';
$xtpl->parse("main.open_source");
$preform = "<table width='100%' border='1' cellspacing='0' cellpadding='0'><tr><td><table width='100%'><tr><td>";
$displayPreform = false;
//$tags = $focus->listviewACLHelper();
if (isset($focus->lead_id) && !empty($focus->lead_id)) {
    //get lead name
    $lead = new Lead();
    $lead->retrieve($focus->lead_id);
    //$tag = $tags['LEAD'];
    $displayPreform = true;
    $preform .= $mod_strings["LBL_CONVERTED_LEAD"] . "&nbsp;<a href='index.php?module=Leads&action=DetailView&record=" . $focus->lead_id . "'>" . $lead->name . "</a>";
}
$preform .= "</td></tr></table></td></tr></table>";
if ($displayPreform) {
    $xtpl->assign("PREVIEW", $preform);
}
$xtpl->parse("main");
$xtpl->out("main");
require_once 'include/SubPanel/SubPanelTiles.php';
$subpanel = new SubPanelTiles($focus, 'Prospects');
echo $subpanel->display();
require_once 'modules/SavedSearch/SavedSearch.php';
$savedSearch = new SavedSearch();
Пример #13
0
    }
    if (isset($call)) {
        $call->track_view($current_user->id, 'Calls');
        array_push($ROWVALUES, "<LI>" . $mod_strings['LBL_CREATED_CALL'] . " - <a href='index.php?action=DetailView&module=Calls&record=" . $call->id . "'>" . $call->name . "</a>");
    }
    if (isset($meeting)) {
        $meeting->track_view($current_user->id, 'Meetings');
        array_push($ROWVALUES, "<LI>" . $mod_strings['LBL_CREATED_MEETING'] . " - <a href='index.php?action=DetailView&module=Meetings&record=" . $meeting->id . "'>" . $meeting->name . "</a>");
    }
    array_push($ROWVALUES, "&nbsp;");
    array_push($ROWVALUES, "<a href='index.php?module=Leads&action=ListView'>{$mod_strings['LBL_BACKTOLEADS']}</a>");
    $sugar_smarty->assign('ROWVALUES', $ROWVALUES);
    echo $sugar_smarty->fetch('modules/Leads/ConvertLead.tpl');
} else {
    $lead = new Lead();
    $lead->retrieve($_REQUEST['record']);
    $sugar_smarty->assign('RECORD', $_REQUEST['record']);
    $sugar_smarty->assign('TABLECLASS', 'edit view');
    //CONTACT
    $sugar_smarty->assign('FORMHEADER', $mod_strings['LNK_NEW_CONTACT']);
    $sugar_smarty->assign('OPPNEEDSACCOUNT', $mod_strings['NTC_OPPORTUNITY_REQUIRES_ACCOUNT']);
    if ($sugar_config['require_accounts']) {
        $sugar_smarty->assign('CHECKOPPORTUNITY', "&& checkOpportunity()");
    } else {
        $sugar_smarty->assign('CHECKOPPORTUNITY', "");
    }
    require_once 'modules/Contacts/ContactFormBase.php';
    $contactForm = new ContactFormBase();
    $sugar_smarty->assign('FORMBODY', $contactForm->getWideFormBody('Contacts', 'Contacts', 'ConvertLead', $lead, false));
    //$sugar_smarty->assign('FORMFOOTER',get_form_footer());
    $sugar_smarty->assign('CLASS', 'dataLabel');
Пример #14
0
 public function testSaveAndConverted_lead()
 {
     $lead = new Lead();
     $lead->first_name = "firstn";
     $lead->last_name = "lastnn";
     $lead->lead_source = "test";
     $result = $lead->save();
     //test for record ID to verify that record is saved
     $this->assertTrue(isset($lead->id));
     $this->assertEquals(36, strlen($lead->id));
     $this->assertEquals("New", $lead->status);
     //test converted_lead method after saving
     /*$lead->converted_lead("'" . $lead->id . "'" , "'1'", "'1'", "'1'");
     
         	//retrieve back to test if attributes are updated in db
         	$lead = $lead->retrieve($lead->id);
         	$this->assertEquals("Converted", $lead->status);
         	$this->assertEquals("1", $lead->converted);
         	$this->assertEquals("1", $lead->contact_id);
         	$this->assertEquals("1", $lead->account_id);
         	$this->assertEquals("1", $lead->opportunity_id);
     		*/
     $this->markTestSkipped("converted_lead: Error in query, id's not properly escaped ");
     //mark the record as deleted and verify that this record cannot be retrieved anymore.
     $lead->mark_deleted($lead->id);
     $result = $lead->retrieve($lead->id);
     $this->assertEquals(null, $result);
 }
Пример #15
0
 public function testConversionAndDoNothing()
 {
     global $sugar_config;
     // init
     $lead = SugarTestLeadUtilities::createLead();
     $account = SugarTestAccountUtilities::createAccount();
     $meeting = SugarTestMeetingUtilities::createMeeting();
     SugarTestMeetingUtilities::addMeetingParent($meeting->id, $lead->id);
     $relation_id = SugarTestMeetingUtilities::addMeetingLeadRelation($meeting->id, $lead->id);
     $_REQUEST['record'] = $lead->id;
     // set the request/post parameters before converting the lead
     $_REQUEST['module'] = 'Leads';
     $_REQUEST['action'] = 'ConvertLead';
     $_REQUEST['record'] = $lead->id;
     $_REQUEST['handle'] = 'save';
     $_REQUEST['selectedAccount'] = $account->id;
     $sugar_config['lead_conv_activity_opt'] = 'none';
     // call display to trigger conversion
     $vc = new ViewConvertLead();
     $vc->display();
     // refresh meeting
     $meeting_id = $meeting->id;
     $meeting = new Meeting();
     $meeting->retrieve($meeting_id);
     // refresh lead
     $lead_id = $lead->id;
     $lead = new Lead();
     $lead->retrieve($lead_id);
     // retrieve the new contact id from the conversion
     $contact_id = $lead->contact_id;
     // 1. Lead's contact_id should not be null
     $this->assertNotNull($contact_id, 'Lead has null contact id after conversion.');
     // 2. Lead status should be 'Converted'
     $this->assertEquals('Converted', $lead->status, "Lead atatus should be 'Converted'.");
     // 3. parent_type of the original meeting should be Leads
     $this->assertEquals('Leads', $meeting->parent_type, 'Meeting parent should be Leads');
     // 4. parent_id of the original meeting should be contact id
     $this->assertEquals($lead_id, $meeting->parent_id, 'Meeting parent id should be lead id.');
     // 5. record should NOT be deleted from meetings_leads table
     $sql = "select id from meetings_leads where meeting_id='{$meeting->id}' and lead_id='{$lead->id}' and deleted=0";
     $result = $GLOBALS['db']->query($sql);
     $row = $GLOBALS['db']->fetchByAssoc($result);
     $this->assertFalse(empty($row), "Meeting-Lead relationship is removed.");
     // 6. record should NOT be added to meetings_contacts table
     $sql = "select meeting_id from meetings_contacts where contact_id='{$contact_id}' and deleted=0";
     $result = $GLOBALS['db']->query($sql);
     $row = $GLOBALS['db']->fetchByAssoc($result);
     $this->assertFalse($row, "Meeting-Contact relationship should not be added.");
     // clean up
     unset($_REQUEST['record']);
     $GLOBALS['db']->query("delete from meetings where parent_id='{$lead->id}' and parent_type= 'Leads'");
     $GLOBALS['db']->query("delete from meetings where parent_id='{$contact_id}' and parent_type= 'Contacts'");
     $GLOBALS['db']->query("delete from contacts where id='{$contact_id}'");
     $GLOBALS['db']->query("delete from meetings_leads where meeting_id='{$meeting->id}' and lead_id= '{$lead_id}'");
     $GLOBALS['db']->query("delete from meetings_contacts where contact_id= '{$contact_id}'");
     SugarTestMeetingUtilities::deleteMeetingLeadRelation($relation_id);
     SugarTestMeetingUtilities::removeMeetingContacts();
     SugarTestMeetingUtilities::removeAllCreatedMeetings();
     SugarTestAccountUtilities::removeAllCreatedAccounts();
     SugarTestLeadUtilities::removeAllCreatedLeads();
 }
Пример #16
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/Leads/Lead.php';
global $mod_strings;
$focus = new Lead();
if (!isset($_REQUEST['record'])) {
    sugar_die($mod_strings['ERR_DELETE_RECORD']);
}
$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']);
 function getInvitationHash(&$focus, $event)
 {
     global $sugar_config;
     global $system_config;
     global $timedate;
     $date_start_in_db_fmt = $timedate->swap_formats($focus->date_start, $timedate->get_date_time_format(true, $current_user), $timedate->get_db_date_time_format());
     $date_start_array = split(" ", trim($date_start_in_db_fmt));
     $date_time_start = DateTimeUtil::get_time_start($date_start_array[0], $date_start_array[1]);
     $date_start_timestamp = mktime($date_time_start->hour, $date_time_start->min, $date_time_start->sec, $date_time_start->month, $date_time_start->day);
     $startDateString = date("d.m.Y", $date_start_timestamp);
     //dd.mm.yyyy
     $startTimeString = date("H:i", $date_start_timestamp);
     $date_end_timestamp = $date_start_timestamp + ($focus->duration_hours * 3600 + $focus->duration_minutes * 60);
     $endDateString = date("d.m.Y", $date_end_timestamp);
     //dd.mm.yyyy
     $endTimeString = date("H:i", $date_end_timestamp);
     /*
     
     echo '<pre>'; 
     
     echo $startDateString;
     echo "\n";
     
     echo $startTimeString;
     echo "\n";
     
     
     echo $date_start_in_db_fmt;
     echo "\n";
     
     echo "endDateString ". $endDateString;
     echo "\n";
     echo "endTimeString ". $endTimeString;
     echo "\n";
     exit();
     
     echo '</pre>';
     */
     if ($focus->online_meeting_url_c == "" && $focus->is_openmeetings_c == true && $_REQUEST['send_invites'] == "1") {
         $_REQUEST['send_invites'] = '0';
         $openmeetings_gateway = new openmeetings_gateway();
         if ($openmeetings_gateway->openmeetings_loginuser()) {
             $admin = new Administration();
             $admin->retrieveSettings();
             //$notify_user = $focus->get_notification_recipients();
             foreach ($focus->users_arr as $user_id) {
                 $notify_user = new User();
                 $notify_user->retrieve($user_id);
                 $notify_user->new_assigned_user_name = $notify_user->full_name;
                 $GLOBALS['log']->info("Notifications: recipient is {$notify_user->new_assigned_user_name}");
                 $invitation_hash = $openmeetings_gateway->getInvitationHash($notify_user->name, $focus->openmeetings_roomid_c, false, "123", 2, $startDateString, $startTimeString, $endDateString, $endTimeString);
                 $notify_user->online_meeting_url_temp = "http://" . $system_config->settings[info_openmeetings_url] . ":" . $system_config->settings[info_openmeetings_http_port] . "/openmeetings/?" . "invitationHash=" . $invitation_hash;
                 //$admin = new Administration();
                 //$admin->retrieveSettings();
                 $focus->send_assignment_notifications($notify_user, $admin);
             }
             foreach ($focus->contacts_arr as $contact_id) {
                 $notify_user = new Contact();
                 $notify_user->retrieve($contact_id);
                 $notify_user->new_assigned_user_name = $notify_user->name;
                 $GLOBALS['log']->info("Notifications: recipient is {$notify_user->new_assigned_user_name}");
                 $invitation_hash = $openmeetings_gateway->getInvitationHash($notify_user->name, $focus->openmeetings_roomid_c, false, "123", 2, $startDateString, $startTimeString, $endDateString, $endTimeString);
                 $notify_user->online_meeting_url_temp = "http://" . $system_config->settings[info_openmeetings_url] . ":" . $system_config->settings[info_openmeetings_http_port] . "/openmeetings/?" . "invitationHash=" . $invitation_hash;
                 //$admin = new Administration();
                 //$admin->retrieveSettings();
                 $focus->send_assignment_notifications($notify_user, $admin);
             }
             foreach ($focus->leads_arr as $lead_id) {
                 $notify_user = new Lead();
                 $notify_user->retrieve($lead_id);
                 $notify_user->new_assigned_user_name = $notify_user->full_name;
                 $GLOBALS['log']->info("Notifications: recipient is {$notify_user->new_assigned_user_name}");
                 $invitation_hash = $openmeetings_gateway->getInvitationHash($notify_user->name, $focus->openmeetings_roomid_c, false, "123", 2, $startDateString, $startTimeString, $endDateString, $endTimeString);
                 $notify_user->online_meeting_url_temp = "http://" . $system_config->settings[info_openmeetings_url] . ":" . $system_config->settings[info_openmeetings_http_port] . "/openmeetings/?" . "invitationHash=" . $invitation_hash;
                 //$admin = new Administration();
                 //$admin->retrieveSettings();
                 $focus->send_assignment_notifications($notify_user, $admin);
             }
         } else {
             echo "Could not login User to OpenMeetings, check your OpenMeetings Module Configuration";
             //exit();
         }
     }
 }
Пример #18
0
 protected function get_notification_recipients()
 {
     if ($this->special_notification) {
         return parent::get_notification_recipients();
     }
     $list = [];
     if (!is_array($this->contacts_arr)) {
         $this->contacts_arr = [];
     }
     if (!is_array($this->users_arr)) {
         $this->users_arr = [];
     }
     if (!is_array($this->leads_arr)) {
         $this->leads_arr = [];
     }
     foreach ($this->users_arr as $user_id) {
         $notify_user = new User();
         $notify_user->retrieve($user_id);
         $notify_user->new_assigned_user_name = $notify_user->full_name;
         Log::info("Notifications: recipient is {$notify_user->new_assigned_user_name}");
         $list[$notify_user->id] = $notify_user;
     }
     foreach ($this->contacts_arr as $contact_id) {
         $notify_user = new Contact();
         $notify_user->retrieve($contact_id);
         $notify_user->new_assigned_user_name = $notify_user->full_name;
         Log::info("Notifications: recipient is {$notify_user->new_assigned_user_name}");
         $list[$notify_user->id] = $notify_user;
     }
     foreach ($this->leads_arr as $lead_id) {
         $notify_user = new Lead();
         $notify_user->retrieve($lead_id);
         $notify_user->new_assigned_user_name = $notify_user->full_name;
         Log::info("Notifications: recipient is {$notify_user->new_assigned_user_name}");
         $list[$notify_user->id] = $notify_user;
     }
     global $sugar_config;
     if (isset($sugar_config['disable_notify_current_user']) && $sugar_config['disable_notify_current_user']) {
         global $current_user;
         if (isset($list[$current_user->id])) {
             unset($list[$current_user->id]);
         }
     }
     return $list;
 }
Пример #19
0
 /**
  * handles linking contacts, accounts, etc. to an email
  *
  * @param object Email bean to be linked against
  * @return string contactAddr is the email address of the sender
  */
 function handleLinking(&$email)
 {
     // link email to an User if emails match TO addr
     if ($userIds = $this->getRelatedId($email->to_addrs, 'users')) {
         $GLOBALS['log']->debug('I-E linking email to User');
         // link the user to the email
         $email->load_relationship('users');
         $email->users->add($userIds);
     }
     // link email to a Contact, Lead, or Account if the emails match
     // give precedence to REPLY-TO above FROM
     if (!empty($email->reply_to_email)) {
         $contactAddr = $email->reply_to_email;
     } else {
         $contactAddr = $email->from_addr;
     }
     // Samir Gandhi : 12/06/07
     // This changes has been done because the linking was done only with the from address and
     // not with to address
     $relationShipAddress = $contactAddr;
     if (empty($relationShipAddress)) {
         $relationShipAddress .= $email->to_addrs;
     } else {
         $relationShipAddress = $relationShipAddress . "," . $email->to_addrs;
     }
     if ($leadIds = $this->getRelatedId($relationShipAddress, 'leads')) {
         $GLOBALS['log']->debug('I-E linking email to Lead');
         $email->load_relationship('leads');
         $email->leads->add($leadIds);
         foreach ($leadIds as $leadId) {
             $lead = new Lead();
             $lead->retrieve($leadId);
             $lead->load_relationship('emails');
             $lead->emails->add($email->id);
         }
     }
     if ($contactIds = $this->getRelatedId($relationShipAddress, 'contacts')) {
         $GLOBALS['log']->debug('I-E linking email to Contact');
         // link the contact to the email
         $email->load_relationship('contacts');
         $email->contacts->add($contactIds);
     }
     if ($accountIds = $this->getRelatedId($relationShipAddress, 'accounts')) {
         $GLOBALS['log']->debug('I-E linking email to Account');
         // link the account to the email
         $email->load_relationship('accounts');
         $email->accounts->add($accountIds);
         /* cn: bug 9171 another cause of dying I-E - bad linking
         			foreach($accountIds as $accountId) {
         				$GLOBALS['log']->debug('I-E reverse-linking Accounts to Emails');
         				$acct = new Account();
         				$acct->retrieve($accountId);
         				$acct->load_relationship('emails');
         				$acct->account_emails->add($email->id);
         			}
         			*/
     }
     return $contactAddr;
 }
 /**
  * handles linking contacts, accounts, etc. to an email
  *
  * @param object Email bean to be linked against
  * @return string contactAddr is the email address of the sender
  */
 function handleLinking(&$email)
 {
     // link email to an User if emails match TO addr
     if ($userIds = $this->getRelatedId($email->to_addrs, 'users')) {
         $GLOBALS['log']->debug('I-E linking email to User');
         // link the user to the email
         $email->load_relationship('users');
         $email->users->add($userIds);
     }
     // link email to a Contact, Lead, or Account if the emails match
     // give precedence to REPLY-TO above FROM
     if (!empty($email->reply_to_email)) {
         $contactAddr = $email->reply_to_email;
     } else {
         $contactAddr = $email->from_addr;
     }
     if ($leadIds = $this->getRelatedId($contactAddr, 'leads')) {
         $GLOBALS['log']->debug('I-E linking email to Lead');
         $email->load_relationship('leads');
         $email->leads->add($leadIds);
         if (!class_exists('Lead')) {
             require_once 'modules/Leads/Lead.php';
         }
         foreach ($leadIds as $leadId) {
             $lead = new Lead();
             $lead->retrieve($leadId);
             $lead->load_relationship('emails');
             $lead->emails->add($email->id);
         }
     }
     if ($contactIds = $this->getRelatedId($contactAddr, 'contacts')) {
         $GLOBALS['log']->debug('I-E linking email to Contact');
         // link the contact to the email
         $email->load_relationship('contacts');
         $email->contacts->add($contactIds);
     }
     if ($accountIds = $this->getRelatedId($contactAddr, 'accounts')) {
         $GLOBALS['log']->debug('I-E linking email to Account');
         // link the account to the email
         $email->load_relationship('accounts');
         $email->accounts->add($accountIds);
         if (!class_exists('Account')) {
             require_once 'modules/Accounts/Account.php';
         }
         /* cn: bug 9171 another cause of dying I-E - bad linking
         			foreach($accountIds as $accountId) {
         				$GLOBALS['log']->debug('I-E reverse-linking Accounts to Emails');
         				$acct = new Account();
         				$acct->retrieve($accountId);
         				$acct->load_relationship('emails');
         				$acct->account_emails->add($email->id);
         			}
         			*/
     }
     return $contactAddr;
 }
Пример #21
-1
 function get_notification_recipients()
 {
     if ($this->special_notification) {
         return parent::get_notification_recipients();
     }
     $list = array();
     if (!is_array($this->contacts_arr)) {
         $this->contacts_arr = array();
     }
     if (!is_array($this->users_arr)) {
         $this->users_arr = array();
     }
     if (!is_array($this->leads_arr)) {
         $this->leads_arr = array();
     }
     foreach ($this->users_arr as $user_id) {
         $notify_user = new User();
         $notify_user->retrieve($user_id);
         $notify_user->new_assigned_user_name = $notify_user->full_name;
         $GLOBALS['log']->info("Notifications: recipient is {$notify_user->new_assigned_user_name}");
         $list[$notify_user->id] = $notify_user;
     }
     foreach ($this->contacts_arr as $contact_id) {
         $notify_user = new Contact();
         $notify_user->retrieve($contact_id);
         $notify_user->new_assigned_user_name = $notify_user->full_name;
         $GLOBALS['log']->info("Notifications: recipient is {$notify_user->new_assigned_user_name}");
         $list[$notify_user->id] = $notify_user;
     }
     foreach ($this->leads_arr as $lead_id) {
         $notify_user = new Lead();
         $notify_user->retrieve($lead_id);
         $notify_user->new_assigned_user_name = $notify_user->full_name;
         $GLOBALS['log']->info("Notifications: recipient is {$notify_user->new_assigned_user_name}");
         $list[$notify_user->id] = $notify_user;
     }
     return $list;
 }