public function testParentsAreRelatedDuringImport() { $file = 'upload://test50438.csv'; $ret = file_put_contents($file, $this->fileArr); $this->assertGreaterThan(0, $ret, 'Failed to write to ' . $file . ' for content ' . var_export($this->fileArr, true)); $importSource = new ImportFile($file, ',', '"'); $bean = loadBean('Calls'); $_REQUEST['columncount'] = 5; $_REQUEST['colnum_0'] = 'id'; $_REQUEST['colnum_1'] = 'subject'; $_REQUEST['colnum_2'] = 'status'; $_REQUEST['colnum_3'] = 'parent_type'; $_REQUEST['colnum_4'] = 'parent_id'; $_REQUEST['import_module'] = 'Contacts'; $_REQUEST['importlocale_charset'] = 'UTF-8'; $_REQUEST['importlocale_timezone'] = 'GMT'; $_REQUEST['importlocale_default_currency_significant_digits'] = '2'; $_REQUEST['importlocale_currency'] = '-99'; $_REQUEST['importlocale_dec_sep'] = '.'; $_REQUEST['importlocale_currency'] = '-99'; $_REQUEST['importlocale_default_locale_name_format'] = 's f l'; $_REQUEST['importlocale_num_grp_sep'] = ','; $_REQUEST['importlocale_dateformat'] = 'm/d/y'; $_REQUEST['importlocale_timeformat'] = 'h:i:s'; $importer = new Importer($importSource, $bean); $importer->import(); //fetch the bean using the passed in id and get related contacts require_once 'modules/Calls/Call.php'; $call = new Call(); $call->retrieve($this->call_id); $call->load_relationship('contacts'); $related_contacts = $call->contacts->get(); //test that the contact id is in the array of related contacts. $this->assertContains($this->contact->id, $related_contacts, ' Contact was not related during simulated import despite being set in related parent id'); unset($call); /* if (is_file($file)) { unlink($file); } */ }
function setBeanID($call_record, $bean_module, $bean_id) { //wrapped the entire action to require a call_record - if this is not being passed then there is no point for this action - PJH if (is_string($call_record) && is_string($bean_id)) { // Very basic sanitization $bean_id = preg_replace('/[^a-z0-9\\-\\. ]/i', '', $bean_id); $bean_module = preg_replace('/[^a-z0-9\\-\\. ]/i', '', $bean_module); $call_record = preg_replace('/[^a-z0-9\\-\\. ]/i', '', $call_record); // Workaround See Discussion here: https://github.com/blak3r/yaai/pull/20 $parent_module = null; $parent_id = null; $parent_name = null; $parent_link = null; $bean_link = build_link($bean_module, $bean_id); $bean_module = strtolower($bean_module); if ($bean_module == 'contacts') { $c = new Contact(); $c->retrieve($bean_id); $bean_name = $c->name; $bean_description = $c->description; $parent_id = $c->account_id; $parent_module = "accounts"; $parent_name = $c->account_name; //$GLOBALS["log"]->fatal(print_r($c,true)); } else { if ($bean_module == "accounts") { $a = new Account(); $a->retrieve($bean_id); $bean_name = $a->name; $bean_description = $a->description; } else { $GLOBALS['log']->fatal("Unsupported Module: {$bean_module}!"); } } $query = "update asterisk_log set bean_id='{$bean_id}', bean_module='{$bean_module}', bean_name='{$bean_name}', bean_link='{$bean_link}', bean_description='{$bean_description}', " . " parent_id='{$parent_id}', parent_module='{$parent_module}', parent_name='{$parent_name}', parent_link='{$parent_link}' " . " where call_record_id='{$call_record}'"; // $GLOBALS['log']->fatal($query); $GLOBALS['current_user']->db->query($query, false); if ($GLOBALS['current_user']->db->checkError()) { trigger_error("Update setContactId-Query failed: {$query}"); } $focus = new Call(); $focus->retrieve($call_record); $focus->load_relationship('contacts'); $focus->load_relationship('accounts'); // TODO here, find if there is a way to remove all relationships dynamically so we don't need to specify 'contacts', 'accounts' explicitly // Remove any contacts already associated with call (if there are any) foreach ($focus->contacts->getBeans() as $contact) { $focus->contacts->delete($call_record, $contact->id); } foreach ($focus->accounts->getBeans() as $account) { $focus->accounts->delete($call_record, $account->id); } switch ($bean_module) { case 'contacts': $focus->contacts->add($bean_id); // Add the new one! $contactBean = new Contact(); $contactBean->retrieve($bean_id); $focus->parent_id = $contactBean->account_id; $focus->parent_type = "Accounts"; break; case 'accounts': $focus->accounts->add($bean_id); break; } $focus->save(); } }
$cUser->retrieve($_SESSION['authenticated_user_id']); // query log // Very basic santization $contactId = preg_replace('/[^a-z0-9\\-\\. ]/i', '', $_REQUEST['contact_id']); // mysql_real_escape_string($_REQUEST['ui_state']); $callRecord = preg_replace('/[^a-z0-9\\-\\. ]/i', '', $_REQUEST['call_record']); // mysql_real_escape_string($_REQUEST['call_record']); $query = "update asterisk_log set contact_id=\"{$contactId}\" where call_record_id=\"{$callRecord}\""; $resultSet = $cUser->db->query($query, false); if ($cUser->db->checkError()) { trigger_error("Update setContactId-Query failed: {$query}"); } // Adds the new relationship! (This must be done here in case the call has already been hungup as that's when asteriskLogger sets relations) $focus = new Call(); $focus->retrieve($callRecord); $focus->load_relationship('contacts'); // Remove any contacts already associated with call (if there are any) foreach ($focus->contacts->getBeans() as $contact) { $focus->contacts->delete($callRecord, $contact->id); } $focus->contacts->add($contactId); // Add the new one! $contactBean = new Contact(); $contactBean->retrieve($contactId); $focus->parent_id = $contactBean->account_id; $focus->parent_type = "Accounts"; $focus->save(); } else { if ($_REQUEST['action'] == "call") { // TODO: For some reason this code isn't working... I think it's getting the extension. // For the time being, callCreate is still being used.
function callComplete() { global $timedate, $current_user; $current_user = new User(); $current_user->retrieve('1'); // $log = true; // // if($log) { // $fp = fopen('callcomplete.txt', 'a+'); // $callResponse = print_r($_REQUEST,true); // fwrite($fp, $callResponse); // fclose($fp); // } $twilio_connector = new ext_rest_twilio(); $sid = $twilio_connector->getProperty('twilio_account_id'); $token = $twilio_connector->getProperty('twilio_auth_token'); $client = new Services_Twilio($sid, $token); $call = new Call(); //_ppl('request begin'); //_ppl($_REQUEST); //_ppl('request end'); $record_id = ''; $module_name = ''; $record_id = isset($_REQUEST['record_id']) ? $_REQUEST['record_id'] : ''; $module_name = isset($_REQUEST['module_name']) ? $_REQUEST['module_name'] : ''; $call_sid = $_REQUEST['DialCallSid']; $call->direction = "Outbound"; if (strpos(strtolower($_REQUEST['From']), 'client:') === false) { //Call in or using call conection if (strpos(strtolower($_REQUEST['Direction']), 'inbound') !== false) { //this is inbound call $call_sid = $_REQUEST['CallSid']; $call->direction = "Inbound"; } } $call_record = $client->account->calls->get($call_sid); // if(is_array($call_record->recordings)){ // _ppl('array'); // }else{ // _ppl('not array'); // } //_ppl($call_record); // foreach($call_record->recordings as $record_obj){ // $call->description= "Recording URL: ". $record_obj->RecordingUrl; // //break; // _ppl('recording url:' . $record_obj->RecordingUrl); // _ppl('recording url2:' . $record_obj->recordingurl); // } //$RecordingUrl _ppl('from: ' . $call_record->from); _ppl('to: ' . $call_record->to); _ppl('Direction: ' . $call_record->direction); if ($call->direction == 'Inbound') { $call->name = "Call from {$call_record->from}"; /* * currently, we only support looking up the phone number in E.164 number formatting, see following URL for detail * http://www.twilio.com/help/faq/phone-numbers/how-do-i-format-phone-numbers-to-work-internationally */ $matched_obj = lookup_inbound_obj($call_record->from); $module_name = isset($matched_obj['module_name']) ? $matched_obj['module_name'] : ''; $record_id = isset($matched_obj['record_id']) ? $matched_obj['record_id'] : ''; } else { if (strpos(strtolower($_REQUEST['From']), 'client:') === false) { $call->name = "Call to {$call_record->to} (using connection)"; } else { $call->name = "Call to {$call_record->to}"; } } $start_time = new DateTime(isset($call_record->starttime) ? $call_record->starttime : ''); $end_time = new DateTime(isset($call_record->endtime) ? $call_record->endtime : ''); $timezone = new DateTimeZone("UTC"); $start_time->setTimezone($timezone); $end_time->setTimezone($timezone); $call->date_start = $start_time->format($timedate->get_db_date_time_format()); $call->date_end = $end_time->format($timedate->get_db_date_time_format()); _ppl('duration: ' . $call_record->duration); $duration_hours = floor($call_record->duration / 3600); $duration_minutes = $call_record->duration / 60 % 60; $call->duration_hours = $duration_hours; if ($duration_minutes > 0 && $duration_minutes <= 15) { $call->duration_minutes = 15; } elseif ($duration_minutes > 15 && $duration_minutes <= 30) { $call->duration_minutes = 30; } elseif ($duration_minutes > 30 && $duration_minutes <= 45) { $call->duration_minutes = 45; } else { $call->duration_minutes = 0; } $call->status = "Held"; $call->team_id = '1'; $call->assigned_user_id = '1'; $call->parent_type = 'Contacts'; $call->parent_id = $record_id; if ($module_name == 'Contacts') { $call->contact_id = $record_id; $contact_bean = new Contact(); $contact_bean->retrieve($record_id); $call->parent_type = 'Accounts'; $call->parent_id = $contact_bean->account_id; } if ($module_name == 'Accounts') { $call->parent_id = $record_id; $call->parent_type = 'Accounts'; } $call->save(); if ($module_name == 'Contacts') { $call->load_relationship("contacts"); $call->contacts->add($record_id); } else { if ($module_name == 'Leads') { $call->load_relationship("leads"); $call->leads->add($record_id); } else { if ($module_name == 'Users') { $call->load_relationship("users"); $call->users->add($record_id); } } } header('Content-type: text/xml'); ?> <Response> <Hangup/> </Response> <?php }