1645 lines
68 KiB
PHP
Executable File
1645 lines
68 KiB
PHP
Executable File
<?php
|
|
if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');
|
|
/*****************************************************************************
|
|
* The contents of this file are subject to the RECIPROCAL PUBLIC LICENSE
|
|
* Version 1.1 ("License"); You may not use this file except in compliance
|
|
* with the License. You may obtain a copy of the License at
|
|
* http://opensource.org/licenses/rpl.php. Software distributed under the
|
|
* License is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND,
|
|
* either express or implied.
|
|
*
|
|
* You may:
|
|
* a) Use and distribute this code exactly as you received without payment or
|
|
* a royalty or other fee.
|
|
* b) Create extensions for this code, provided that you make the extensions
|
|
* publicly available and document your modifications clearly.
|
|
* c) Charge for a fee for warranty or support or for accepting liability
|
|
* obligations for your customers.
|
|
*
|
|
* You may NOT:
|
|
* a) Charge for the use of the original code or extensions, including in
|
|
* electronic distribution models, such as ASP (Application Service
|
|
* Provider).
|
|
* b) Charge for the original source code or your extensions other than a
|
|
* nominal fee to cover distribution costs where such distribution
|
|
* involves PHYSICAL media.
|
|
* c) Modify or delete any pre-existing copyright notices, change notices,
|
|
* or License text in the Licensed Software
|
|
* d) Assert any patent claims against the Licensor or Contributors, or
|
|
* which would in any way restrict the ability of any third party to use the
|
|
* Licensed Software.
|
|
*
|
|
* You must:
|
|
* a) Document any modifications you make to this code including the nature of
|
|
* the change, the authors of the change, and the date of the change.
|
|
* b) Make the source code for any extensions you deploy available via an
|
|
* Electronic Distribution Mechanism such as FTP or HTTP download.
|
|
* c) Notify the licensor of the availability of source code to your extensions
|
|
* and include instructions on how to acquire the source code and updates.
|
|
* d) Grant Licensor a world-wide, non-exclusive, royalty-free license to use,
|
|
* reproduce, perform, modify, sublicense, and distribute your extensions.
|
|
*
|
|
* The Original Code is: CommuniCore
|
|
* Olavo Farias
|
|
* 2006-04-7 olavo.farias@gmail.com
|
|
*
|
|
* The Initial Developer of the Original Code is CommuniCore.
|
|
* Portions created by CommuniCore are Copyright (C) 2005 CommuniCore Ltda
|
|
* All Rights Reserved.
|
|
********************************************************************************/
|
|
require_once('data/SugarBean.php');
|
|
require_once('include/utils.php');
|
|
// SHOULD INCLUDE SELECTIVELY
|
|
class EcmCall extends SugarBean {
|
|
|
|
var $field_name_map = array();
|
|
|
|
// STANDARD FIELDS
|
|
var $id;
|
|
var $deleted;
|
|
var $note;
|
|
|
|
// TABLE COLUMNS
|
|
var $calldate;
|
|
var $src;
|
|
var $dst;
|
|
var $dcontext;
|
|
var $channel;
|
|
var $dstchannel;
|
|
var $lastapp;
|
|
var $lastdata;
|
|
var $duration;
|
|
var $billsec;
|
|
var $disposition;
|
|
var $amaflags;
|
|
var $accountcode;
|
|
var $userfield;
|
|
|
|
// RELATED FIELDS
|
|
|
|
// SUBPANELS RELATED
|
|
|
|
// MODULE OBJECT DETAILS
|
|
var $module_dir = 'EcmCalls';
|
|
var $table_name = "cdr";
|
|
var $object_name = "EcmCall";
|
|
|
|
// RELATED TABLE NAMES
|
|
|
|
|
|
// USED TO RETRIEVE RELATED FIELDS FROM FORM POSTS.
|
|
var $additional_column_fields = Array(
|
|
);
|
|
|
|
|
|
|
|
// RELATIONSHIP FIELDS
|
|
var $relationship_fields = Array(
|
|
);
|
|
|
|
|
|
function EcmCall() {
|
|
parent::SugarBean();
|
|
$this->setupCustomFields('EcmCalls');
|
|
foreach($this->field_defs as $field) {
|
|
$this->field_name_map[$field['name']] = $field;
|
|
}
|
|
}
|
|
|
|
|
|
var $new_schema = true;
|
|
|
|
function get_summary_text(){
|
|
return "$this->name";
|
|
}
|
|
|
|
|
|
function create_list_query($order_by, $where, $show_deleted = 0) {
|
|
$custom_join = $this->custom_fields->getJOIN();
|
|
$query = "SELECT
|
|
$this->table_name.*";
|
|
if($custom_join) {
|
|
$query .= $custom_join['select'];
|
|
}
|
|
$query .= " FROM $this->table_name ";
|
|
|
|
if($custom_join) {
|
|
$query .= $custom_join['join'];
|
|
}
|
|
$query .= "";
|
|
$where_auto = " $this->table_name.deleted=0
|
|
";
|
|
if($where != "")
|
|
$query .= " where $where AND ".$where_auto;
|
|
else
|
|
$query .= " where ".$where_auto;
|
|
if($order_by != "")
|
|
$query .= " ORDER BY $order_by";
|
|
else
|
|
$query .= " ORDER BY $this->table_name.calldate";
|
|
|
|
return $query;
|
|
}
|
|
|
|
function create_export_query($order_by, $where) {
|
|
$custom_join = $this->custom_fields->getJOIN();
|
|
$query = "SELECT
|
|
$this->table_name.*";
|
|
if($custom_join) {
|
|
$query .= $custom_join['select'];
|
|
}
|
|
$query .= " FROM $this->table_name ";
|
|
|
|
if($custom_join) {
|
|
$query .= $custom_join['join'];
|
|
}
|
|
$query .= "";
|
|
$where_auto = " $this->table_name.deleted=0
|
|
";
|
|
if($where != "")
|
|
$query .= " where $where AND ".$where_auto;
|
|
else
|
|
$query .= " where ".$where_auto;
|
|
if($order_by != "")
|
|
$query .= " ORDER BY $order_by";
|
|
else
|
|
$query .= " ORDER BY $this->table_name.calldate";
|
|
|
|
return $query;
|
|
}
|
|
|
|
function fill_in_additional_list_fields() {
|
|
$this->fill_in_additional_detail_fields();
|
|
}
|
|
|
|
function fill_in_additional_detail_fields() {
|
|
// FILL IN THE ASSIGNED_USER_NAME
|
|
$this->assigned_user_name = get_assigned_user_name($this->assigned_user_id);
|
|
$this->created_by_name = get_assigned_user_name($this->created_by);
|
|
$this->modified_by_name = get_assigned_user_name($this->modified_user_id);
|
|
|
|
}
|
|
|
|
function get_list_view_data(){
|
|
return;
|
|
|
|
//convert date
|
|
global $timedate, $timezones;
|
|
require_once('modules/EcmCalls/TimeDateC.php');
|
|
$tdc = new TimeDateC();
|
|
$this->calldate = $timedate->to_db($this->calldate);
|
|
$this->calldate = $tdc->handle_offset($this->calldate, $tdc->get_db_date_time_format(), false);
|
|
$this->calldate = $timedate->to_display_date_time($this->calldate);
|
|
|
|
if(empty($this->note) || empty($this->dcontext)) {
|
|
$query = "SELECT `note`, `dcontext`, `dstchannel`, `channel`, `disposition`, `src`, `dst` FROM `cdr` WHERE `id`='$this->id' AND `deleted`='0' LIMIT 1";
|
|
$result = $this->db->query($query);
|
|
if($result) {
|
|
$row = $this->db->fetchByAssoc($result);
|
|
if($row) {
|
|
$this->note = $row['note'];
|
|
$this->dcontext = $row['dcontext'];
|
|
$this->dstchannel = $row['dstchannel'];
|
|
$this->channel = $row['channel'];
|
|
$this->dst = $row['dst'];
|
|
$this->src = $row['src'];
|
|
$this->disposition = $row['disposition'];
|
|
}
|
|
}
|
|
}
|
|
|
|
$this->src = $this->get_number($this->src);
|
|
$this->dst = $this->get_number($this->dst);
|
|
|
|
$type = $this->get_call_type();
|
|
|
|
$this->src = $this->name_src_number(); //$this->name_number($this->src);
|
|
$this->dst = $this->name_dst_number(); //$this->name_number($this->dst);
|
|
|
|
if($_REQUEST['testmore7']==5) {
|
|
$this->src .= 'test';
|
|
$this->dst .= 'test';
|
|
}
|
|
|
|
global $current_language;
|
|
$app_list_strings = return_app_list_strings_language($current_language);
|
|
$mod_strings = return_module_language($current_language, 'EcmCalls');
|
|
$the_array = parent::get_list_view_data();
|
|
|
|
// THE NEW LISTVIEW CODE ONLY FETCHES COLUMNS THAT WE'RE DISPLAYING AND NOT ALL
|
|
// THE COLUMNS SO WE NEED THESE CHECKS.
|
|
|
|
$the_array['DURATION'] = $this->format_time($this->duration);
|
|
$the_array['BILLSEC'] = $this->format_time($this->billsec);
|
|
$r=mysql_fetch_array(mysql_query("select bean_id,bean_module from ecmcalls_beans where ecmcall_id='".$this->id."' and (bean_module='Accounts' or bean_module='Contacts')"));
|
|
$bean_id=$r['bean_id'];
|
|
if($r['bean_module']=="Contacts"){
|
|
$r=mysql_fetch_array(mysql_query("select account_id,contact_id from accounts_contacts where contact_id='".$r['bean_id']."' and deleted='0'"));
|
|
$r=mysql_fetch_array(mysql_query("select id,name from accounts where id='".$r['account_id']."' and deleted='0'"));
|
|
$bean_type="Contacts";
|
|
|
|
}
|
|
if($r['bean_module']=="Accounts"){
|
|
$r=mysql_fetch_array(mysql_query("select account_id from accounts_contacts where account_id='".$r['bean_id']."' and deleted='0'"));
|
|
$r=mysql_fetch_array(mysql_query("select id,name from accounts where id='".$r['account_id']."' and deleted='0'"));
|
|
$bean_type="Accounts";
|
|
}
|
|
$the_array['ACCOUNT'] = '<a target="_blank" href="index.php?module=Accounts&action=DetailView&record='.$r['id'].'">'.$r['name'].'</a>';
|
|
// $the_array['SRC'] = $this->format_phone_number($this->src);
|
|
// $the_array['DST'] = $this->format_phone_number($this->dst);
|
|
|
|
|
|
$type_img = '<img src="modules/EcmCalls/images/'.$type.'_'.strtolower(str_replace(' ','_',$this->disposition)).'.gif" title="'.$app_list_strings['calls_type_dom'][$type].'">';
|
|
$the_array['TYPE_IMG'] = $type_img;
|
|
$the_array['DISPOSITION'] = $app_list_strings['calls_disposition_dom'][$this->disposition];
|
|
|
|
$guid = create_guid();
|
|
$rcall=mysql_fetch_array(mysql_query("select description from calls where deleted='0' and parent_type='".$bean_type."' and parent_id='".$bean_id."' order by date_entered desc limit 1"));
|
|
$hint_ = '<div class="tabForm" id="hint_div_'.$guid.'" style="border:0px solid black;position:absolute;left:-210px;display:none;text-align:center;">';
|
|
$hint_ .= '<div align="center" style="width:300px;text-align:left">'.$rcall['description'].'
|
|
<!--<textarea '.(!ACLController::checkAccess('EcmCalls', "edit", true)?'readonly="readonly" ':'').'style="width:300px;height:180px;" maxlength="1000">'.$this->note.'</textarea>
|
|
<div align="right">
|
|
'.(ACLController::checkAccess('EcmCalls', "edit", true)?('<a href="javascript:saveNote(\''.$guid.'\',\''.$this->id.'\');">'.$mod_strings['LBL_SAVE_TITLE'].'</a> '):'').'<a href="javascript:cancelNote(\''.$guid.'\');">'.$mod_strings['LBL_CANCEL_TITLE'].'</a>
|
|
</div>-->
|
|
</div>
|
|
';
|
|
$hint_ .= '</div>';
|
|
|
|
|
|
if(!ACLController::checkAccess('EcmCalls', "edit", true) && (!isset($this->note) || $this->note == ''))
|
|
$hint = '<span id="'.$guid.'">'.$hint_.'</span><img src="modules/EcmCalls/images/hint_grey.gif">';
|
|
else
|
|
$hint = '<span id="'.$guid.'">'.$hint_.'</span><img src="modules/EcmCalls/images/hint_'.((isset($this->note) && $this->note != '')?'black':'grey').'.gif" onClick="lock_unlock_Position(\''.$guid.'\',this);" onMouseOver="showCallHint(event,\''.$guid.'\',\''.$this->id.'\',this,\''.$mod_strings['LBL_NOTE_TITLE'].'\');" onMouseOut="hideCallHint(event,\''.$guid.'\',\''.$this->id.'\',this);">';
|
|
|
|
$the_array['HINT'] = $hint;
|
|
|
|
return $the_array;
|
|
}
|
|
|
|
function tr($vname,$module) {
|
|
$tmp = translate($vname,$module);
|
|
if(substr($tmp,-1) != ':') $tmp .= ':';
|
|
return $tmp;
|
|
}
|
|
|
|
function find_bean($number,$module) {
|
|
|
|
$query = "SELECT `ecb`.`bean_id` as `id`, `ecb`.`bean_module` as `module` FROM `ecmcalls_beans` as `ecb` WHERE `ecb`.`ecmcall_id` = '$this->id' AND `ecb`.`bean_module` = '$module' AND LPAD('$number',50,'0') = LPAD(`ecb`.`src`,50,'0') LIMIT 1";
|
|
|
|
$result = $this->db->query($query);
|
|
if($result) {
|
|
$row = $this->db->fetchByAssoc($result);
|
|
if($row) {
|
|
if(isset($row['id']) && $row['id'] != '') return $row;
|
|
}
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
function name_src_number() {
|
|
|
|
$focus = false;
|
|
|
|
if(strpos($this->channel, "SIP/".$this->dcontext."-") !== FALSE) $this->src = $this->dcontext;
|
|
|
|
if(!($focus = $this->find_bean($this->src,'Contacts')))
|
|
if(!($focus = $this->find_bean($this->src,'Accounts')))
|
|
$focus = $this->find_bean($this->src,'Users');
|
|
|
|
$central = $this->name_central_number($this->src);
|
|
if($central) return $central;
|
|
|
|
if($focus) {
|
|
return $this->createHint($this->src, $focus['id'], $focus['module']);
|
|
}
|
|
/*
|
|
return '<span onMouseOver="EcmCalls_showAssignImage(this,\''.$this->src.'\',\''.$this->id.'\');" onMouseOut="EcmCalls_hideAssignImage(this,\''.$this->src.'\');" onClick="CALL(\''.$this->src.'\');" style="cursor:pointer;">'.$this->src.'</span>'; //$this->format_phone_number($this->src);
|
|
*/
|
|
// return '<span style="cursor:pointer;">'.$this->src.'</span>'; //$this->format_phone_number($this->src);
|
|
$chi = create_guid();
|
|
return "<span onClick=\"show_hide_Position('unknown_number');\" onMouseMove='showCallHint(event,\"unknown_number\",undefined,undefined,undefined, \"".$this->src."\", \"".$this->id."\", undefined, undefined, \"$chi\");' onMouseOut='hideCallHint(event,\"unknown_number\");' style=\"cursor:pointer;\">".$this->src."</span>"."<span style=\"display:none;\" id='EcmCallsCallHintIcon_".$chi."'>".$this->FTSC($this->src,true)."</span>";
|
|
}
|
|
|
|
function name_dst_number() {
|
|
|
|
$focus = false;
|
|
|
|
if(!($focus = $this->find_bean($this->dst,'Contacts')))
|
|
if(!($focus = $this->find_bean($this->dst,'Accounts')))
|
|
$focus = $this->find_bean($this->dst,'Users');
|
|
|
|
$central = $this->name_central_number($this->dst);
|
|
if($central) return $central;
|
|
|
|
if($focus) {
|
|
return $this->createHint($this->dst, $focus['id'], $focus['module']);
|
|
}
|
|
|
|
/*
|
|
return '<span onMouseOver="EcmCalls_showAssignImage(this,\''.$this->dst.'\',\''.$this->id.'\');" onMouseOut="EcmCalls_hideAssignImage(this,\''.$this->dst.'\');" onClick="CALL(\''.$this->dst.'\');" style="cursor:pointer;">'.$this->dst.'</span>'; //$this->format_phone_number($this->dst);
|
|
*/
|
|
|
|
// return '<span style="cursor:pointer;">'.$this->dst.'</span>'; //$this->format_phone_number($this->dst);
|
|
|
|
$chi = create_guid();
|
|
return "<span onClick=\"show_hide_Position('unknown_number');\" onMouseMove='showCallHint(event,\"unknown_number\",undefined,undefined,undefined, \"".$this->dst."\", \"".$this->id."\", undefined, undefined,\"".$chi."\");' onMouseOut='hideCallHint(event,\"unknown_number\");' style=\"cursor:pointer;\">".$this->dst."</span>"."<span style=\"display:none;\" id='EcmCallsCallHintIcon_".$chi."'>".$this->FTSC($this->dst,true)."</span>";
|
|
}
|
|
|
|
function createHintPositions($arr) {
|
|
$str = '';
|
|
foreach($arr as $key => $value) {
|
|
$str .= '<tr><td class="EcmCallsAdditionalDetailsTableTD1" noWrap>'.$value[0].'</td><td class="EcmCallsAdditionalDetailsTableTD2" noWrap>'.$value[1].'</td></tr>';
|
|
}
|
|
return $str;
|
|
}
|
|
|
|
function createBeanPhonesHintPositions($bean) {
|
|
$arr[] = array();
|
|
foreach($bean->field_defs as $name => $value) {
|
|
if($value['type'] == "phone" || strpos($name,"phone_") === 0)
|
|
$arr[] = array(
|
|
$this->tr($bean->field_defs[$name]['vname'], $bean->module_dir),
|
|
$this->FTSC($bean->$name)
|
|
);
|
|
}
|
|
return $arr;
|
|
}
|
|
|
|
function createHint($number, $id, $module) {
|
|
global $hilite_bg;
|
|
|
|
if(!isset($_SESSION['ecmcalls_phones'][$module][$id]['div'])) {
|
|
|
|
global $beanList, $beanFiles;
|
|
$bean = $beanList[$module];
|
|
$file = $beanFiles[$bean];
|
|
if(file_exists($file)) {
|
|
require_once($file);
|
|
$focus = new $beanList[$module]();
|
|
$focus->retrieve($id);
|
|
}
|
|
|
|
if($module == "Contacts") {
|
|
|
|
$_SESSION['ecmcalls_phones'][$module][$id]['name'] = $focus->full_name;
|
|
|
|
$arr = array();
|
|
$arr[] = array($this->tr($focus->field_defs['account_name']['vname'],"Contacts"), $focus->account_name);
|
|
|
|
$arr = array_merge($arr, $this->createBeanPhonesHintPositions($focus));
|
|
|
|
$tmp_str = '';
|
|
if(!empty($focus->primary_address_street)) $tmp_str .= $focus->primary_address_street;
|
|
if(!empty($focus->primary_address_city)) $tmp_str .= '<br>'.$focus->primary_address_city.' '.$focus->primary_address_postalcode;
|
|
if(!empty($focus->primary_address_state)) $tmp_str .= '<br>'.$focus->primary_address_state;
|
|
if(!empty($focus->primary_address_country)) $tmp_str .= '<br>'.$focus->primary_address_country;
|
|
$arr[] = array($this->tr('LBL_ADDRESS','EcmCalls'), $tmp_str);
|
|
|
|
$str = '<table>'.$this->createHintPositions($arr).'</table>';
|
|
|
|
}
|
|
|
|
if($module == "Users") {
|
|
|
|
$_SESSION['ecmcalls_phones'][$module][$id]['name'] = $focus->full_name;
|
|
|
|
$arr = array();
|
|
|
|
$arr = array_merge($arr, $this->createBeanPhonesHintPositions($focus));
|
|
|
|
$tmp_str = '';
|
|
if(!empty($focus->address_street)) $tmp_str .= $focus->address_street;
|
|
if(!empty($focus->address_city)) $tmp_str .= '<br>'.$focus->address_city.' '.$focus->address_postalcode;
|
|
if(!empty($focus->address_state)) $tmp_str .= '<br>'.$focus->address_state;
|
|
if(!empty($focus->address_country)) $tmp_str .= '<br>'.$focus->address_country;
|
|
$arr[] = array($this->tr('LBL_ADDRESS','EcmCalls'), $tmp_str);
|
|
|
|
$str = '<table>'.$this->createHintPositions($arr).'</table>';
|
|
|
|
}
|
|
|
|
if($module == "Accounts") {
|
|
|
|
$_SESSION['ecmcalls_phones'][$module][$id]['name'] = $focus->name;
|
|
|
|
$arr = array();
|
|
|
|
$arr = array_merge($arr, $this->createBeanPhonesHintPositions($focus));
|
|
|
|
$tmp_str = '';
|
|
if(!empty($focus->billing_address_street)) $tmp_str .= $focus->billing_address_street;
|
|
if(!empty($focus->billing_address_city)) $tmp_str .= '<br>'.$focus->billing_address_city.' '.$focus->billing_address_postalcode;
|
|
if(!empty($focus->billing_address_state)) $tmp_str .= '<br>'.$focus->billing_address_state;
|
|
if(!empty($focus->billing_address_country)) $tmp_str .= '<br>'.$focus->billing_address_country;
|
|
$arr[] = array($this->tr('LBL_ADDRESS','EcmCalls'), $tmp_str);
|
|
|
|
$str = '<table>'.$this->createHintPositions($arr).'</table>';
|
|
|
|
}
|
|
|
|
$guid = create_guid();
|
|
$_SESSION['ecmcalls_phones'][$module][$id]['div'] = $guid;
|
|
$tmp = "<div class=\"EcmCallsAdditionalDetailsDiv\" style='display:none' id='hint_div_$guid' onMouseOut='hideCallHint(event,\"".$_SESSION['ecmcalls_phones'][$module][$id]['div']."\");'>";
|
|
$tmp .= $str;
|
|
$tmp .= "</div>";
|
|
|
|
}
|
|
|
|
$chi = create_guid();
|
|
$tmp .= "<span onClick=\"show_hide_Position('".$_SESSION['ecmcalls_phones'][$module][$id]['div']."');\"><a href=\"javascript:\" onMouseMove='showCallHint(event,\"".$_SESSION['ecmcalls_phones'][$module][$id]['div']."\",undefined,undefined,\"".$_SESSION['ecmcalls_phones'][$module][$id]['name']."\", \"".$number."\", \"".$this->id."\", \"$module\", \"$id\",\"".$chi."\");' onMouseOut='hideCallHint(event,\"".$_SESSION['ecmcalls_phones'][$module][$id]['div']."\");'>".$_SESSION['ecmcalls_phones'][$module][$id]['name']." (".$number.")"."</a></span>"."<span style=\"display:none;\" id='EcmCallsCallHintIcon_".$chi."'>".$this->FTSC($number,true)."</span>";
|
|
return $tmp;
|
|
|
|
}
|
|
|
|
function FTSC($number, $additional_details = false) {
|
|
require_once("include/ECM/EcmFormatPhoneNumber/EcmFormatPhoneNumber.php");
|
|
if(!$additional_details)
|
|
return EcmFormatPhoneNumber($number, "EcmCall", "EcmCalls", $this->id);
|
|
else
|
|
return EcmFormatPhoneNumber($number, "EcmCall", "EcmCalls", $this->id, 'additional_details', false);
|
|
}
|
|
|
|
function name_number($number) {
|
|
global $hilite_bg;
|
|
foreach($_SESSION['ecmcalls_phones'] as $module => $ids)
|
|
foreach($ids as $id => $info)
|
|
foreach($info['numbers'] as $key => $nr)
|
|
if(strrpos($number,$nr[0]) !== false && ($len = (strlen($number)-strlen($nr[0]))) >= 0 && $len <=3) {
|
|
|
|
if(!isset($_SESSION['ecmcalls_phones'][$module][$id]['div'])) {
|
|
|
|
$focus_array = array();
|
|
|
|
if($module == "Contacts")
|
|
$fa = array('phone_home', 'phone_mobile', 'phone_work', 'phone_other', 'phone_fax', 'primary_address_street', 'primary_address_city', 'primary_address_state', 'primary_address_postalcode', 'primary_address_country');
|
|
if($module == "Users")
|
|
$fa = array('phone_home', 'phone_mobile', 'phone_work', 'phone_other', 'phone_fax', 'address_street', 'address_city', 'address_state', 'address_postalcode', 'address_country');
|
|
if($module == "Accounts")
|
|
$fa = array('phone_office', 'phone_fax', 'phone_alternate', 'billing_address_street', 'billing_address_city', 'billing_address_state', 'billing_address_postalcode', 'billing_address_country');
|
|
|
|
$query = "SELECT `".implode('`, `',$fa)."` FROM `".strtolower($module)."` WHERE `id`='".$id."' AND `deleted`=0 LIMIT 1";
|
|
$result = $GLOBALS['db']->query($query);
|
|
if($result) {
|
|
$row = $GLOBALS['db']->fetchByAssoc($result);
|
|
if($row) {
|
|
$focus_array = $row;
|
|
}
|
|
}
|
|
|
|
if($module == "Contacts") {
|
|
$query = "SELECT `acc`.name FROM `accounts` as `acc`, `accounts_contacts` as `a_c` WHERE `a_c`.account_id = `acc`.id AND `a_c`.contact_id = '$id' AND `a_c`.deleted = '0' AND `acc`.deleted = '0' LIMIT 1";
|
|
$result = $GLOBALS['db']->query($query);
|
|
if($result) {
|
|
$row = $GLOBALS['db']->fetchByAssoc($result);
|
|
if($row) {
|
|
$focus_array['account_name'] = $row['name'];
|
|
}
|
|
}
|
|
|
|
require_once('modules/Contacts/Contact.php');
|
|
|
|
$focus = new Contact();
|
|
$str = '<table>';
|
|
$fn = 'account_name';
|
|
$str .= '<tr><td style="font-weight:900;" noWrap>'.$this->tr($focus->field_defs[$fn]['vname'],$module).'</td><td style="width:100px;" noWrap>'.$focus_array[$fn].'</td></tr>';
|
|
$fn = 'phone_work';
|
|
$str .= '<tr><td style="font-weight:900;" noWrap>'.$this->tr($focus->field_defs[$fn]['vname'],$module).'</td><td noWrap>'.$this->FTSC($focus_array[$fn]).'</td></tr>';
|
|
$fn = 'phone_home';
|
|
$str .= '<tr><td style="font-weight:900;" noWrap>'.$this->tr($focus->field_defs[$fn]['vname'],$module).'</td><td noWrap>'.$this->FTSC($focus_array[$fn]).'</td></tr>';
|
|
$fn = 'phone_mobile';
|
|
$str .= '<tr><td style="font-weight:900;" noWrap>'.$this->tr($focus->field_defs[$fn]['vname'],$module).'</td><td noWrap>'.$this->FTSC($focus_array[$fn]).'</td></tr>';
|
|
$fn = 'phone_fax';
|
|
$str .= '<tr><td style="font-weight:900;" noWrap>'.$this->tr($focus->field_defs[$fn]['vname'],$module).'</td><td noWrap>'.$focus_array[$fn].'</td></tr>';
|
|
$fn = 'phone_other';
|
|
$str .= '<tr><td style="font-weight:900;" noWrap>'.$this->tr($focus->field_defs[$fn]['vname'],$module).'</td><td noWrap>'.$this->FTSC($focus_array[$fn]).'</td></tr>';
|
|
$str .= '<tr><td style="font-weight:900;" valign="top" noWrap>'.$this->tr('LBL_ADDRESS','EcmCalls').'</td><td noWrap>';
|
|
if(!empty($focus_array['primary_address_street'])) $str .= $focus_array['primary_address_street'];
|
|
if(!empty($focus_array['primary_address_city'])) $str .= '<br>'.$focus_array['primary_address_city'].' '.$focus_array['primary_address_postalcode'];
|
|
if(!empty($focus_array['primary_address_state'])) $str .= '<br>'.$focus_array['primary_address_state'];
|
|
if(!empty($focus_array['primary_address_country'])) $str .= '<br>'.$focus_array['primary_address_country'];
|
|
$str .= '</td></tr></table>';
|
|
}
|
|
|
|
|
|
if($module == "Users") {
|
|
|
|
require_once('modules/Users/User.php');
|
|
$focus = new User();
|
|
$str = '<table>';
|
|
|
|
$fn = 'phone_work';
|
|
$str .= '<tr><td style="font-weight:900;" noWrap>'.$this->tr($focus->field_defs[$fn]['vname'],$module).'</td><td style="width:100px;" noWrap>'.$this->FTSC($focus_array[$fn]).'</td></tr>';
|
|
$fn = 'phone_home';
|
|
$str .= '<tr><td style="font-weight:900;" noWrap>'.$this->tr($focus->field_defs[$fn]['vname'],$module).'</td><td noWrap>'.$this->FTSC($focus_array[$fn]).'</td></tr>';
|
|
$fn = 'phone_mobile';
|
|
$str .= '<tr><td style="font-weight:900;" noWrap>'.$this->tr($focus->field_defs[$fn]['vname'],$module).'</td><td noWrap>'.$this->FTSC($focus_array[$fn]).'</td></tr>';
|
|
$fn = 'phone_fax';
|
|
$str .= '<tr><td style="font-weight:900;" noWrap>'.$this->tr($focus->field_defs[$fn]['vname'],$module).'</td><td noWrap>'.$focus_array[$fn].'</td></tr>';
|
|
$fn = 'phone_other';
|
|
$str .= '<tr><td style="font-weight:900;" noWrap>'.$this->tr($focus->field_defs[$fn]['vname'],$module).'</td><td noWrap>'.$this->FTSC($focus_array[$fn]).'</td></tr>';
|
|
$str .= '<tr><td style="font-weight:900;" valign="top" noWrap>'.$this->tr('LBL_ADDRESS','EcmCalls').'</td><td noWrap>';
|
|
if(!empty($focus_array['address_street'])) $str .= $focus_array['address_street'];
|
|
if(!empty($focus_array['address_city'])) $str .= '<br>'.$focus_array['address_city'].' '.$focus_array['address_postalcode'];
|
|
if(!empty($focus_array['address_state'])) $str .= '<br>'.$focus_array['address_state'];
|
|
if(!empty($focus_array['address_country'])) $str .= '<br>'.$focus_array['address_country'];
|
|
$str .= '</td></tr></table>';
|
|
}
|
|
|
|
if($module == "Accounts") {
|
|
|
|
require_once('modules/Accounts/Account.php');
|
|
$focus = new Account();
|
|
$str = '<table>';
|
|
|
|
$fn = 'phone_office';
|
|
$str .= '<tr><td style="font-weight:900;" noWrap>'.$this->tr($focus->field_defs[$fn]['vname'],$module).'</td><td style="width:100px;" noWrap>'.$this->FTSC($focus_array[$fn]).'</td></tr>';
|
|
$fn = 'phone_alternate';
|
|
$str .= '<tr><td style="font-weight:900;" noWrap>'.$this->tr($focus->field_defs[$fn]['vname'],$module).'</td><td noWrap>'.$this->FTSC($focus_array[$fn]).'</td></tr>';
|
|
$fn = 'phone_fax';
|
|
$str .= '<tr><td style="font-weight:900;" noWrap>'.$this->tr($focus->field_defs[$fn]['vname'],$module).'</td><td noWrap>'.$focus_array[$fn].'</td></tr>';
|
|
$str .= '<tr><td style="font-weight:900;" valign="top" noWrap>'.$this->tr('LBL_ADDRESS','EcmCalls').'</td><td noWrap>';
|
|
if(!empty($focus_array['billing_address_street'])) $str .= $focus_array['billing_address_street'];
|
|
if(!empty($focus_array['billing_address_city'])) $str .= '<br>'.$focus_array['billing_address_city'].' '.$focus_array['billing_address_postalcode'];
|
|
if(!empty($focus_array['billing_address_state'])) $str .= '<br>'.$focus_array['billing_address_state'];
|
|
if(!empty($focus_array['billing_address_country'])) $str .= '<br>'.$focus_array['billing_address_country'];
|
|
$str .= '</td></tr></table>';
|
|
}
|
|
|
|
$guid = create_guid();
|
|
$_SESSION['ecmcalls_phones'][$module][$id]['div'] = $guid;
|
|
$tmp = "<div style='border:1px solid black;position:absolute;left:-600px;text-align:center;background-color:$hilite_bg;' id='hint_div_$guid' onMouseOut='hideCallHint(event,\"".$_SESSION['ecmcalls_phones'][$module][$id]['div']."\");'>";
|
|
$tmp .= $str;
|
|
$tmp .= "</div>";
|
|
}
|
|
$tmp .= "<a href='javascript:;' onMouseMove='showCallHint(event,\"".$_SESSION['ecmcalls_phones'][$module][$id]['div']."\");' onMouseOut='hideCallHint(event,\"".$_SESSION['ecmcalls_phones'][$module][$id]['div']."\");' style=\"cursor:pointer;\">".$info['name']."</a>";
|
|
return $tmp;
|
|
|
|
}
|
|
|
|
return $number;//$this->format_phone_number($number);
|
|
}
|
|
|
|
|
|
function name_central_number($number) {
|
|
if(array_key_exists($number,$_SESSION['EcmCalls']['central_phones'])) {
|
|
global $mod_strings;
|
|
$c_name = (($_SESSION['EcmCalls']['central_phones'][$number] != NULL && $_SESSION['EcmCalls']['central_phones'][$number] != '')?$_SESSION['EcmCalls']['central_phones'][$number]:$mod_strings['LBL_CENTRAL_PHONE']);
|
|
/*
|
|
$c_tmp = "<span onMouseOver=\"EcmCalls_showAssignImage(this,'$number','$this->id');\" onMouseOut=\"EcmCalls_hideAssignImage(this,'$number');\"><a href=\"javascript:CALL('$number');\" >$c_name ($number)</a></span>";
|
|
*/
|
|
$chi = create_guid();
|
|
$c_tmp = "<span onClick=\"show_hide_Position('unknown_number');\" onMouseMove='showCallHint(event,\"unknown_number\",undefined,undefined,\"$c_name\", \"$number\", \"".$this->id."\", undefined, undefined,\"".$chi."\");' onMouseOut='hideCallHint(event,\"unknown_number\");' style=\"cursor:pointer;\">$c_name ($number)</span>"."<span style=\"display:none;\" id='EcmCallsCallHintIcon_".$chi."'>".$this->FTSC($number,true)."</span>";
|
|
return $c_tmp;
|
|
}
|
|
return NULL;
|
|
}
|
|
|
|
function format_phone_number($number,$format = '+{countrycode}{areacode}{phonenumber}') {
|
|
if($this->get_number_type($number) == 'outside') {
|
|
if(strlen($number) == 13) {
|
|
$format = str_replace('{countrycode}',substr($number,2,2),$format);
|
|
$format = str_replace('{areacode}',substr($number,-9,2),$format);
|
|
$format = str_replace('{phonenumber}',substr($number,-7),$format);
|
|
$number = $format;
|
|
}
|
|
}
|
|
return $number;
|
|
}
|
|
|
|
function format_time($duration) {
|
|
return sprintf("%02d:%02d:%02d",$duration/3600,($duration%3600)/60,$duration%60);
|
|
}
|
|
|
|
function get_call_type() {
|
|
$src = $this->get_number_type($this->src);
|
|
$dst = $this->get_number_type($this->dst);
|
|
if($src == 'inside' && $dst == 'inside') return 'inside'; else
|
|
if($src == 'inside' && $dst == 'outside') return 'out'; else
|
|
if($src == 'outside' && $dst == 'inside') return 'in'; else
|
|
return 'in';
|
|
}
|
|
|
|
function get_number($number) {
|
|
if($number == "anonymous") return $number;
|
|
$areacode = $_SESSION['ecmcalls_config']['central_areacode'];
|
|
if(array_key_exists($number,$_SESSION['EcmCalls']['central_phones'])) {
|
|
$nr = $this->parse_number($this->dcontext);
|
|
if($nr != 0 && $nr != '') return $nr; else return $number;
|
|
}
|
|
else
|
|
return $number;
|
|
}
|
|
|
|
function get_number_type($number) {
|
|
$number = $this->parse_number($number);
|
|
if($number != $this->src)
|
|
if((array_key_exists($number,$_SESSION['EcmCalls']['central_phones']) || strlen($number) < 4) && $number != '') return 'inside'; else return 'outside';
|
|
else {
|
|
if((array_key_exists($number,$_SESSION['EcmCalls']['central_phones']) || strlen($number) < 4 || strpos($this->channel, "SIP/".$this->dcontext."-") !== FALSE) && $number != '') return 'inside'; else return 'outside';
|
|
}
|
|
}
|
|
|
|
|
|
function parse_number($number,$no_string = false) {
|
|
return $this->str2int($number,true,$no_string);
|
|
}
|
|
|
|
static function str2int($string, $to_string = false, $no_string = false, $concat = true) {
|
|
$length = strlen($string);
|
|
for ($i = 0, $int = '', $concat_flag = true; $i < $length; $i++) {
|
|
if (is_numeric($string[$i]) && $concat_flag) {
|
|
$int .= $string[$i];
|
|
} elseif(!$concat && $concat_flag && strlen($int) > 0) {
|
|
$concat_flag = false;
|
|
if($no_string) return -1;
|
|
} else if($no_string) return -1;
|
|
}
|
|
if(!$to_string)
|
|
return (int) $int;
|
|
else
|
|
return $int;
|
|
}
|
|
/**
|
|
BUILDS A GENERIC SEARCH BASED ON THE QUERY STRING USING OR.
|
|
DO NOT INCLUDE ANY $THIS-> BECAUSE THIS IS CALLED ON WITHOUT HAVING THE CLASS INSTANTIATED.
|
|
*/
|
|
function build_generic_where_clause ($the_query_string) {
|
|
$where_clauses = Array();
|
|
$the_query_string = PearDatabase::quote(from_html($the_query_string));
|
|
array_push($where_clauses, "$this->table_name.name like '$the_query_string%'");
|
|
$the_where = "";
|
|
foreach($where_clauses as $clause){
|
|
if($the_where != "") $the_where .= " or ";
|
|
$the_where .= $clause;
|
|
}
|
|
return $the_where;
|
|
}
|
|
|
|
function set_notification_body($xtpl, $simplemodule) {
|
|
global $mod_strings, $app_list_strings;
|
|
// $xtpl->assign("NAME", $simplemodule->name);
|
|
// $xtpl->assign("ECMCALLS_DESCRIPTION", $this->description);
|
|
return $xtpl;
|
|
}
|
|
|
|
function bean_implements($interface) {
|
|
switch($interface){
|
|
case 'ACL':return true;
|
|
}
|
|
return false;
|
|
}
|
|
|
|
function save($check_notify = FALSE) {
|
|
return parent::save($check_notify);
|
|
}
|
|
|
|
static function loadCentralPhonesToSession() {
|
|
$query = "SELECT `phone`, `note` FROM `ecmcallsphones` WHERE `bean_module` = 'EcmCalls'";
|
|
$result = $GLOBALS['db']->query($query);
|
|
$arr = array();
|
|
if($result)
|
|
while($r = $GLOBALS['db']->fetchByAssoc($result)) $arr[$r['phone']] = $r['note'];
|
|
$_SESSION['EcmCalls']['central_phones'] = $arr;
|
|
|
|
}
|
|
|
|
function mark_deleted($id)
|
|
{
|
|
|
|
if(isset($_SESSION['show_deleted']))
|
|
{
|
|
$this->mark_undeleted($id);
|
|
}
|
|
else
|
|
{
|
|
// call the custom business logic
|
|
$custom_logic_arguments['id'] = $id;
|
|
$this->call_custom_logic("before_delete", $custom_logic_arguments);
|
|
|
|
$query = "UPDATE $this->table_name set deleted=1 where id='$id'";
|
|
$this->db->query($query, true,"Error marking record deleted: ");
|
|
$this->mark_relationships_deleted($id);
|
|
|
|
// Take the item off the recently viewed lists
|
|
$tracker = new Tracker();
|
|
$tracker->makeInvisibleForAll($id);
|
|
|
|
// call the custom business logic
|
|
$this->call_custom_logic("after_delete", $custom_logic_arguments);
|
|
}
|
|
}
|
|
|
|
function mark_undeleted($id)
|
|
{
|
|
// call the custom business logic
|
|
$custom_logic_arguments['id'] = $id;
|
|
$this->call_custom_logic("before_restore", $custom_logic_arguments);
|
|
|
|
$query = "UPDATE $this->table_name set deleted=0 where id='$id'";
|
|
$this->db->query($query, true,"Error marking record undeleted: ");
|
|
|
|
// call the custom business logic
|
|
$this->call_custom_logic("after_restore", $custom_logic_arguments);
|
|
}
|
|
|
|
static function loadCallsSettings() {
|
|
require_once('modules/EcmCalls/config.php');
|
|
$_SESSION['ecmcalls_config'] = $ecmcalls_config;
|
|
|
|
|
|
$phones = array();
|
|
|
|
$query = "SELECT `id`, `first_name`, `last_name`, `phone_home`, `phone_mobile`, `phone_work`, `phone_other`, `phone_fax` FROM `contacts` WHERE `deleted`='0'";
|
|
$result = $GLOBALS['db']->query($query);
|
|
if($result) {
|
|
while($row = $GLOBALS['db']->fetchByAssoc($result)) {
|
|
$id = $row['id'];
|
|
if(($nr = EcmCall::returnNumber($row['phone_home'])) != -1) $phones['Contacts'][$id]['numbers'][] = array($nr, $row['phone_home'], 'phone_home');
|
|
if(($nr = EcmCall::returnNumber($row['phone_mobile'])) != -1) $phones['Contacts'][$id]['numbers'][] = array($nr, $row['phone_mobile'], 'phone_mobile');
|
|
if(($nr = EcmCall::returnNumber($row['phone_work'])) != -1) $phones['Contacts'][$id]['numbers'][] = array($nr, $row['phone_work'], 'phone_work');
|
|
if(($nr = EcmCall::returnNumber($row['phone_other'])) != -1) $phones['Contacts'][$id]['numbers'][] = array($nr, $row['phone_other'], 'phone_other');
|
|
if(($nr = EcmCall::returnNumber($row['phone_fax'])) != -1) $phones['Contacts'][$id]['numbers'][] = array($nr, $row['phone_fax'], 'phone_fax');
|
|
if(isset($phones['Contacts'][$id])) $phones['Contacts'][$id]['name'] = ((isset($row['first_name']) && $row['first_name'] != '') ? ($row['first_name'].' ') : '').$row['last_name'];
|
|
}
|
|
}
|
|
|
|
$query = "SELECT `id`, `name`, `phone_office`, `phone_alternate`, `phone_fax` FROM `accounts` WHERE `deleted`='0'";
|
|
$result = $GLOBALS['db']->query($query);
|
|
if($result) {
|
|
while($row = $GLOBALS['db']->fetchByAssoc($result)) {
|
|
$id = $row['id'];
|
|
if(($nr = EcmCall::returnNumber($row['phone_office'])) != -1) $phones['Accounts'][$id]['numbers'][] = array($nr, $row['phone_office'], 'phone_office');
|
|
if(($nr = EcmCall::returnNumber($row['phone_alternate'])) != -1) $phones['Accounts'][$id]['numbers'][] = array($nr, $row['phone_alternate'], 'phone_alternate');
|
|
if(($nr = EcmCall::returnNumber($row['phone_fax'])) != -1) $phones['Accounts'][$id]['numbers'][] = array($nr, $row['phone_fax'], 'phone_fax');
|
|
if(isset($phones['Accounts'][$id])) $phones['Accounts'][$id]['name'] = $row['name'];
|
|
}
|
|
}
|
|
|
|
//loading names and numbers of Users
|
|
$query = "SELECT `id`, `first_name`, `last_name`, `phone_home`, `phone_mobile`, `phone_work`, `phone_other`, `phone_fax` FROM `users` WHERE `deleted`='0'";
|
|
$result = $GLOBALS['db']->query($query);
|
|
if($result) {
|
|
while($row = $GLOBALS['db']->fetchByAssoc($result)) {
|
|
$id = $row['id'];
|
|
if(($nr = EcmCall::returnNumber($row['phone_home'])) != -1) $phones['Users'][$id]['numbers'][] = array($nr, $row['phone_home'], 'phone_home');
|
|
if(($nr = EcmCall::returnNumber($row['phone_mobile'])) != -1) $phones['Users'][$id]['numbers'][] = array($nr, $row['phone_mobile'], 'phone_mobile');
|
|
if(($nr = EcmCall::returnNumber($row['phone_work'])) != -1) $phones['Users'][$id]['numbers'][] = array($nr, $row['phone_work'], 'phone_work');
|
|
if(($nr = EcmCall::returnNumber($row['phone_other'])) != -1) $phones['Users'][$id]['numbers'][] = array($nr, $row['phone_other'], 'phone_other');
|
|
if(($nr = EcmCall::returnNumber($row['phone_fax'])) != -1) $phones['Users'][$id]['numbers'][] = array($nr, $row['phone_fax'], 'phone_fax');
|
|
if(isset($phones['Users'][$id])) $phones['Users'][$id]['name'] = ((isset($row['first_name']) && $row['first_name'] != '') ? ($row['first_name'].' ') : '').$row['last_name'];
|
|
}
|
|
}
|
|
|
|
//var_dump($phones);
|
|
$_SESSION['ecmcalls_phones'] = $phones;
|
|
}
|
|
|
|
static function returnNumber($number) {
|
|
require_once('modules/EcmCalls/EcmCall.php');
|
|
$nr = EcmCall::str2int($number,true);
|
|
if($nr == '') return -1; else return $nr;
|
|
}
|
|
|
|
static function CentralUrl($number) {
|
|
$number = EcmCall::returnNumber($number);
|
|
if($number == -1)
|
|
return null;
|
|
|
|
global $current_user;
|
|
$authentication = '';
|
|
if(isset($current_user->cp_user_name) && $current_user->cp_user_name != '' && isset($current_user->cp_user_password) && $current_user->cp_user_password != '') $authentication = $current_user->cp_user_name.':'.$current_user->cp_user_password.'@';
|
|
return "$current_user->cp_protocol://$authentication$current_user->cp_phone_ip:$current_user->cp_phone_port/command.htm?number=".$number;
|
|
}
|
|
|
|
function processCall($call) {
|
|
if(is_array($call)) {
|
|
foreach($call as $key => $value) $this->$key = $value;
|
|
global $timedate;
|
|
$this->calldate = $timedate->to_display_date_time($this->calldate);
|
|
return $this->get_list_view_data();
|
|
} else return null;
|
|
}
|
|
|
|
static function autoAssigning() {
|
|
EcmCall::loadCallsSettings();
|
|
foreach($_SESSION['ecmcalls_phones'] as $module => $ids)
|
|
foreach($ids as $id => $info)
|
|
foreach($info['numbers'] as $key => $nr) {
|
|
EcmCall::addEcmCallPhone($nr[0],$module,$id,$nr[2]);
|
|
}
|
|
return true;
|
|
}
|
|
|
|
static function deleteIfSomeoneHaveThisPhone($number,$bean_id) {
|
|
$GLOBALS['db'] = new MysqlManager();
|
|
$GLOBALS['db']->connect();
|
|
$query = "SELECT `bean_module`, `bean_id`, `note` FROM `ecmcallsphones` WHERE `phone`='$number'";
|
|
$results = $GLOBALS['db']->query($query);
|
|
if(is_resource($results)) {
|
|
while($row = $GLOBALS['db']->fetchByAssoc($results)) {
|
|
if($row['bean_id'] != $bean_id) {
|
|
$qu = "UPDATE `".strtolower($row['bean_module'])."` SET `".$row['note']."`='' WHERE `id`='".$row['bean_id']."'";
|
|
$GLOBALS['db']->query($qu);
|
|
}
|
|
}
|
|
$qu = "DELETE FROM `ecmcallsphones` WHERE `phone`='$number' AND `bean_id`<>'$bean_id'";
|
|
$GLOBALS['db']->query($qu);
|
|
}
|
|
}
|
|
|
|
|
|
static function addEcmCallPhone($number,$bean_module,$bean_id,$note,$bean = null) {
|
|
|
|
$phone = EcmCall::returnNumber($number);
|
|
|
|
$is_from_list = false;
|
|
if(isset($bean) && isset($bean->EcmCallInfo) && is_array($bean->EcmCallInfo) && $bean->EcmCallInfo['parent_phone'] == $note) {
|
|
$is_from_list = true;
|
|
$eci = $bean->EcmCallInfo;
|
|
if(isset($eci['ecmcall_record']) && $eci['ecmcall_record'] != '') {
|
|
$ec = new EcmCall();
|
|
$ec->retrieve($eci['ecmcall_record']);
|
|
if(isset($ec->id) && $ec->id != '') {
|
|
global $timedate;
|
|
|
|
$ec_calldate_cdr = $timedate->to_db($ec->calldate);
|
|
|
|
//convert date
|
|
global $timedate, $timezones;
|
|
require_once('modules/EcmCalls/TimeDateC.php');
|
|
$tdc = new TimeDateC();
|
|
$ec->calldate = $timedate->to_db($ec->calldate);
|
|
$ec->calldate = $tdc->handle_offset($ec->calldate, $tdc->get_db_date_time_format(), false);
|
|
//$this->calldate = $timedate->to_display_date_time($this->calldate);
|
|
|
|
$ec_calldate_ecb = $ec->calldate;
|
|
$qq = "SELECT `date_modified` FROM `ecmcalls_beans` WHERE `ecmcall_id`='$ec->id' LIMIT 1";
|
|
$re = $GLOBALS['db']->query($qq);
|
|
if($re) {
|
|
$rr = $GLOBALS['db']->fetchByAssoc($re);
|
|
if(isset($rr['date_modified']) && $rr['date_modified'] != '') {
|
|
$ecm_calldate_ecb = $rr['date_modified'];
|
|
}
|
|
}
|
|
|
|
|
|
if(isset($eci['update_records']) && $eci['update_records'] != '') {
|
|
$ur = $eci['update_records'];
|
|
if ($ur == "all") $wd = '';
|
|
elseif ($ur == "only_oldest") $wd = '<';
|
|
elseif ($ur == "only_newest") $wd = '>';
|
|
elseif ($ur == "only_this") $wd = '=';
|
|
elseif ($ur == "only_this_and_oldest") $wd = '<';
|
|
elseif ($ur == "only_this_and_newest") $wd = '>';
|
|
|
|
if($wd != '') {
|
|
$where_date_ecb = " AND `date_modified` $wd '$ec_calldate_ecb' ";
|
|
$where_date_cdr = " AND `cdr`.`calldate` $wd '$ec_calldate_cdr' ";
|
|
}
|
|
else {
|
|
$where_date_ecb = "";
|
|
$where_date_cdr = "";
|
|
}
|
|
if($ur == "only_this") {
|
|
$where_date_ecb = " AND `ecmcall_id`='".$bean->EcmCallInfo['ecmcall_record']."' ";
|
|
$where_date_cdr = " AND `id`='".$bean->EcmCallInfo['ecmcall_record']."' ";
|
|
}
|
|
$query = "DELETE FROM `ecmcalls_beans` WHERE `bean_id`='".$bean->EcmCallInfo['old_parent_id']."' $where_date_ecb AND `src`='".$bean->EcmCallInfo['old_parent_phone']."'";
|
|
$GLOBALS['db']->query($query);
|
|
|
|
if($phone != '') {
|
|
$query = "INSERT INTO `ecmcalls_beans` (`id`, `ecmcall_id`, `bean_id`, `bean_module`, `src`, `date_modified`, `deleted`) SELECT UUID() as `id`, `cdr`.`id` as `ecmcall_id`, '$bean_id' as `bean_id`, '$bean_module' as `bean_module`, '$phone' as `src`, `cdr`.`calldate` as `date_modified`, '0' as `deleted` FROM `cdr` WHERE ((LPAD(`cdr`.`dst`,50,'0') = LPAD('$phone',50,'0')) OR ((LPAD(`cdr`.`src`,50,'0') = LPAD('$phone',50,'0')) OR (LPAD(`cdr`.`dcontext`,50,'0') = LPAD('$phone',50,'0')))) $where_date_cdr;";
|
|
$GLOBALS['db']->query($query);
|
|
|
|
if($ur == "only_this_and_newes" || $ur == "only_this_and_oldest") {
|
|
$where_date_ecb = " AND `ecmcall_id`='".$bean->EcmCallInfo['ecmcall_record']."' ";
|
|
$where_date_cdr = " AND `id`='".$bean->EcmCallInfo['ecmcall_record']."' ";
|
|
$query = "INSERT INTO `ecmcalls_beans` (`id`, `ecmcall_id`, `bean_id`, `bean_module`, `src`, `date_modified`, `deleted`) SELECT UUID() as `id`, `cdr`.`id` as `ecmcall_id`, '$bean_id' as `bean_id`, '$bean_module' as `bean_module`, '$phone' as `src`, `cdr`.`calldate` as `date_modified`, '0' as `deleted` FROM `cdr` WHERE ((LPAD(`cdr`.`dst`,50,'0') = LPAD('$phone',50,'0')) OR ((LPAD(`cdr`.`src`,50,'0') = LPAD('$phone',50,'0')) OR (LPAD(`cdr`.`dcontext`,50,'0') = LPAD('$phone',50,'0')))) $where_date_cdr;";
|
|
$GLOBALS['db']->query($query);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
//EcmCall::deleteIfSomeoneHaveThisPhone($phone,$bean_id);
|
|
|
|
if($phone != -1) {
|
|
|
|
$query = "SELECT COUNT(*) as `count` FROM `ecmcallsphones` WHERE LPAD(`phone`,50,'0') = LPAD('$phone',50,'0') AND `bean_id` = '$bean_id' AND `note` = '$note'";
|
|
$count1 = $GLOBALS['db']->fetchByAssoc($GLOBALS['db']->query($query));
|
|
$count1 = intval($count1['count']);
|
|
|
|
if($count1 == 1 && $is_from_list == false) {
|
|
|
|
return true;
|
|
|
|
} else {
|
|
|
|
$query = "SELECT COUNT(*) as `count` FROM `ecmcallsphones` WHERE LPAD(`phone`,50,'0') = LPAD('$phone',50,'0') AND `bean_id` != '$bean_id'";
|
|
$count2 = $GLOBALS['db']->fetchByAssoc($GLOBALS['db']->query($query));
|
|
$count2 = intval($count2['count']);
|
|
|
|
if( !($count1 == 0 && $count2 > 0) || $is_from_list == true) {
|
|
$query = "DELETE FROM `ecmcallsphones` WHERE LPAD(`phone`,50,'0') = LPAD('$phone',50,'0')";
|
|
$result = $GLOBALS['db']->query($query);
|
|
}
|
|
|
|
if(($count2 == 0 && $count1 == 0) || $is_from_list == true) {
|
|
$query = "INSERT INTO `ecmcallsphones` ( `id` , `bean_module` , `bean_id` , `phone` , `note` ) VALUES ( '".create_guid()."' , '$bean_module' , '$bean_id' , '$phone' , '$note' )";
|
|
$result = $GLOBALS['db']->query($query);
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
else { // $phone == -1
|
|
$query = "DELETE FROM `ecmcallsphones` WHERE `bean_id`='$bean_id' AND `bean_module`='$bean_module' AND `note`='$note'";
|
|
$result = $GLOBALS['db']->query($query);
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
static function deleteEcmCallPhones($bean_module,$bean_id) {
|
|
$query = "DELETE FROM `ecmcallsphones` WHERE `bean_id`='$bean_id' AND `bean_module`='$bean_module'";
|
|
$result = $GLOBALS['db']->query($query);
|
|
}
|
|
|
|
function create_new_list_query($order_by, $where,$filter=array(),$params=array(), $show_deleted = 0,$join_type='', $return_array = false,$parentbean, $singleSelect = false) {
|
|
|
|
if(ACLController::checkAccess('EcmCalls', "list", false) == false) {
|
|
$_REQUEST["current_user_only_basic"] = "1";
|
|
$_REQUEST["current_user_only_advanced"] = "1";
|
|
$_REQUEST["current_user_only"] = "1";
|
|
$_POST["current_user_only_basic"] = "1";
|
|
$_POST["current_user_only_advanced"] = "1";
|
|
$_POST["current_user_only"] = "1";
|
|
}
|
|
|
|
if(!isset($_REQUEST['user_id']) || $_REQUEST['user_id'] == '') {
|
|
global $current_user;
|
|
$_REQUEST['user_id'] = $current_user->id;
|
|
}
|
|
|
|
global $current_language;
|
|
if(!is_file($GLOBALS['sugar_config']['cache_dir'] . 'jsLanguage/EcmCalls/' . $GLOBALS['current_language'] . '.js')) {
|
|
require_once('include/language/jsLanguage.php');
|
|
jsLanguage::createModuleStringsCache("EcmCalls", $GLOBALS['current_language']);
|
|
}
|
|
echo '<script type="text/javascript" src="cache/jsLanguage/EcmCalls/'.$current_language.'.js"></script>';
|
|
echo '<img id="EcmCalls_image_assign" src="modules/EcmCalls/images/assign_call.gif" style="display:none;" />';
|
|
echo '<img id="EcmCalls_image_search" src="modules/EcmCalls/images/search_call.gif" style="display:none;" />';
|
|
echo '<script type="text/javascript" src="include/JSON.js"></script>';
|
|
echo '<script type="text/javascript" src="modules/EcmCalls/Hint.js"></script>';
|
|
echo '<script language="javascript" src="modules/EcmCalls/DoCall.js"></script>';
|
|
echo '<script language="javascript" src="modules/EcmCalls/ListView.js"></script>';
|
|
echo '<link rel="stylesheet" type="text/css" href="modules/EcmCalls/Hint.css" />';
|
|
require_once('modules/EcmCalls/EcmCall.php');
|
|
EcmCall::loadCentralPhonesToSession();
|
|
echo "<div style='display:none;' id='hint_div_unknown_number'></div>";
|
|
|
|
$_SESSION['ecmcalls_phones'] = null;
|
|
|
|
require_once('modules/EcmCalls/anMenu/anMenu.php');
|
|
$anMenu = new anMenu();
|
|
$anMenu->display();
|
|
|
|
global $beanFiles, $beanList;
|
|
$selectedFields = array();
|
|
$secondarySelectedFields = array();
|
|
$ret_array = array();
|
|
$distinct = '';
|
|
|
|
if($this->bean_implements('ACL') && ACLController::requireOwner($this->module_dir, 'list') )
|
|
{
|
|
global $current_user;
|
|
$owner_where = $this->getOwnerWhere($current_user->id);
|
|
if(empty($where))
|
|
{
|
|
$where = $owner_where;
|
|
}
|
|
else
|
|
{
|
|
$where .= ' AND '. $owner_where;
|
|
}
|
|
}
|
|
//EcmTeam *********************************************
|
|
else {
|
|
if(class_exists('EcmTeam') && EcmTeam::isUseEcmTeamEnabled()) $where = EcmTeam::addTeamWhere($this, $where);
|
|
}
|
|
//*****************************************************
|
|
$ret_array['from'] = " FROM $this->table_name ";
|
|
|
|
|
|
if($_REQUEST['searchFormTab'] == "basic_search") {
|
|
$where = '';
|
|
$ecb = false;
|
|
if(isset($_REQUEST['current_user_only_basic']) && $_REQUEST['current_user_only_basic'] != "0") {
|
|
$ecb_l = true;
|
|
if($where != '') $where .= ' AND ';
|
|
$where = " (l.bean_id = '".$_REQUEST['user_id']."') AND (l.ecmcall_id = cdr.id) ";
|
|
}
|
|
|
|
if(isset($_REQUEST['calldate_basic']) && $_REQUEST['calldate_basic'] != '') {
|
|
|
|
echo '<input type="hidden" id="calldate_ecmcalls_tmp" value="'.$_REQUEST['calldate_basic'].'" />';
|
|
|
|
$cd = $_REQUEST['calldate_basic'];
|
|
$_REQUEST['call_date_from'] = '';
|
|
$_REQUEST['call_date_to'] = '';
|
|
|
|
require_once('modules/EcmCalls/TimeDateC.php');
|
|
|
|
$tdc = new TimeDateC();
|
|
$td = $tdc->queryFilter($cd);
|
|
|
|
global $timedate;
|
|
$_REQUEST['call_date_from_basic'] = $timedate->to_display_date_time($td['begin']);
|
|
$_REQUEST['call_date_to_basic'] = $timedate->to_display_date_time($td['end']);
|
|
|
|
}
|
|
|
|
|
|
if(isset($_REQUEST['call_date_from_basic']) && strlen($_REQUEST['call_date_from_basic']) > 6) {
|
|
//convert date
|
|
global $timedate, $timezones;
|
|
require_once('modules/EcmCalls/TimeDateC.php');
|
|
$tdc = new TimeDateC();
|
|
$calldate = $timedate->to_db($_REQUEST['call_date_from_basic']);
|
|
$calldate = $tdc->handle_offset($calldate, $tdc->get_db_date_time_format(), true);
|
|
if($where != '') $where .= ' AND ';
|
|
$where .= " (cdr.calldate > '$calldate') ";
|
|
}
|
|
|
|
if(isset($_REQUEST['call_date_to_basic']) && strlen($_REQUEST['call_date_to_basic']) > 6) {
|
|
//convert date
|
|
global $timedate, $timezones;
|
|
require_once('modules/EcmCalls/TimeDateC.php');
|
|
$tdc = new TimeDateC();
|
|
$calldate = $_REQUEST['call_date_to_basic'];
|
|
$calldate = preg_replace('/00([\.:])00/', '23${1}59${1}59', $calldate);
|
|
$calldate = $timedate->to_db($calldate);
|
|
$calldate = $tdc->handle_offset($calldate, $tdc->get_db_date_time_format(), true);
|
|
if($where != '') $where .= ' AND ';
|
|
$where .= " (cdr.calldate < '$calldate') ";
|
|
}
|
|
|
|
|
|
|
|
if((isset($_REQUEST['parent_from_basic']) && $_REQUEST['parent_from_basic'] != '')) {
|
|
$from = $_REQUEST['parent_from_basic'];
|
|
$params['distinct'] = true;
|
|
$ecb_l = true;
|
|
if($where != '') $where .= ' AND ';
|
|
$where .= " ( ";
|
|
if(isset($from) && $from != '') $where .= " l.bean_module = '".$_REQUEST['parent_from_basic']."' AND (LPAD(l.src,50,'0')=LPAD(cdr.src,50,'0') OR LPAD(l.src,50,'0')=LPAD(cdr.dcontext,50,'0')) ";
|
|
$where .= " ) ";
|
|
|
|
}
|
|
|
|
if((isset($_REQUEST['parent_to_basic']) && $_REQUEST['parent_to_basic'] != '')) {
|
|
$to = $_REQUEST['parent_to_basic'];
|
|
$params['distinct'] = true;
|
|
$ecb_r = true;
|
|
if($where != '') $where .= ' AND ';
|
|
$where .= " ( ";
|
|
if(isset($to) && $to != '') $where .= " r.bean_module = '".$_REQUEST['parent_to_basic']."' AND LPAD(r.src,50,'0')=LPAD(cdr.dst,50,'0') ";
|
|
$where .= " ) ";
|
|
|
|
}
|
|
|
|
if((isset($_REQUEST['dst_basic']) && $_REQUEST['dst_basic'] != '')) {
|
|
$to = $_REQUEST['dst_basic'];
|
|
if($where != '') $where .= ' AND ';
|
|
$where .= " ( ";
|
|
if(isset($to) && $to != '') $where .= " cdr.dst LIKE '".$to."%' || cdr.dst = '".$to."'";
|
|
$where .= " ) ";
|
|
}
|
|
if((isset($_REQUEST['src_basic']) && $_REQUEST['src_basic'] != '')) {
|
|
$to = $_REQUEST['src_basic'];
|
|
if($where != '') $where .= ' AND ';
|
|
$where .= " ( ";
|
|
if(isset($to) && $to != '') $where .= " cdr.src LIKE '".$to."%' || cdr.src = '".$to."'";
|
|
$where .= " ) ";
|
|
}
|
|
|
|
} else
|
|
|
|
if($_REQUEST['searchFormTab'] == "advanced_search") {
|
|
$where = '';
|
|
$ecb = false;
|
|
if(isset($_REQUEST['current_user_only_advanced']) && $_REQUEST['current_user_only_advanced'] != "0") {
|
|
$ecb_l = true;
|
|
if($where != '') $where .= ' AND ';
|
|
$where = " (l.bean_id = '".$_REQUEST['user_id']."') AND (l.ecmcall_id = cdr.id) ";
|
|
}
|
|
|
|
if(isset($_REQUEST['calldate_advanced']) && $_REQUEST['calldate_advanced'] != '') {
|
|
|
|
echo '<input type="hidden" id="calldate_ecmcalls_tmp" value="'.$_REQUEST['calldate_advanced'].'" />';
|
|
|
|
$cd = $_REQUEST['calldate_advanced'];
|
|
$_REQUEST['call_date_from'] = '';
|
|
$_REQUEST['call_date_to'] = '';
|
|
|
|
require_once('modules/EcmCalls/TimeDateC.php');
|
|
|
|
$tdc = new TimeDateC();
|
|
$td = $tdc->queryFilter($cd);
|
|
|
|
global $timedate;
|
|
$_REQUEST['call_date_from_advanced'] = $timedate->to_display_date_time($td['begin']);
|
|
$_REQUEST['call_date_to_advanced'] = $timedate->to_display_date_time($td['end']);
|
|
|
|
}
|
|
if(isset($_REQUEST['disposition_advanced'])){
|
|
if($where != '') $where .= ' AND ';
|
|
$where.="cdr.disposition like '".$_REQUEST['disposition_advanced']."'";
|
|
}
|
|
if(isset($_REQUEST['duration_advanced']) && isset($_REQUEST['duration_type_advanced'])){
|
|
if($where != '') $where .= ' AND ';
|
|
if($_REQUEST['duration_type_advanced']=="more")
|
|
$where.="cdr.duration>".$_REQUEST['duration_advanced'];
|
|
else
|
|
$where.="cdr.duration<=".$_REQUEST['duration_advanced'];
|
|
}
|
|
|
|
if(isset($_REQUEST['call_date_from_advanced']) && strlen($_REQUEST['call_date_from_advanced']) > 6) {
|
|
|
|
echo '<input type="hidden" id="call_date_from_ecmcalls_tmp" value="'.$_REQUEST['call_date_from_advanced'].'" />';
|
|
|
|
//convert date
|
|
global $timedate, $timezones;
|
|
require_once('modules/EcmCalls/TimeDateC.php');
|
|
$tdc = new TimeDateC();
|
|
$calldate = $timedate->to_db($_REQUEST['call_date_from_advanced']);
|
|
$calldate = $tdc->handle_offset($calldate, $tdc->get_db_date_time_format(), true);
|
|
if($where != '') $where .= ' AND ';
|
|
$where .= " (cdr.calldate > '$calldate') ";
|
|
}
|
|
|
|
if(isset($_REQUEST['call_date_to_advanced']) && strlen($_REQUEST['call_date_to_advanced']) > 6) {
|
|
|
|
echo '<input type="hidden" id="call_date_to_ecmcalls_tmp" value="'.$_REQUEST['call_date_to_advanced'].'" />';
|
|
|
|
//convert date
|
|
global $timedate, $timezones;
|
|
require_once('modules/EcmCalls/TimeDateC.php');
|
|
$tdc = new TimeDateC();
|
|
$calldate = $_REQUEST['call_date_to_advanced'];
|
|
$calldate = preg_replace('/00([\.:])00/', '23${1}59${1}59', $calldate);
|
|
$calldate = $timedate->to_db($calldate);
|
|
$calldate = $tdc->handle_offset($calldate, $tdc->get_db_date_time_format(), true);
|
|
if($where != '') $where .= ' AND ';
|
|
$where .= " (cdr.calldate < '$calldate') ";
|
|
}
|
|
|
|
if((isset($_REQUEST['parent_from_advanced']) && $_REQUEST['parent_from_advanced'] != '')) {
|
|
$from = $_REQUEST['parent_from_advanced'];
|
|
$params['distinct'] = true;
|
|
$ecb_l = true;
|
|
if($where != '') $where .= ' AND ';
|
|
if(isset($_REQUEST['parent_from_id_advanced']) && $_REQUEST['parent_from_id_advanced'] != '') $pfida = " AND l.bean_id IN('".implode("', '", $_REQUEST['parent_from_id_advanced'])."') "; else $pfida = '';
|
|
$where .= " ( ";
|
|
if(isset($from) && $from != '') $where .= " l.bean_module = '".$_REQUEST['parent_from_advanced']."' $pfida ";
|
|
|
|
if(!isset($_REQUEST['in_out_advanced']) || $_REQUEST['in_out_advanced'] != 'on')
|
|
$where .= "AND (LPAD(l.src,50,'0')=LPAD(cdr.src,50,'0') OR LPAD(l.src,50,'0')=LPAD(cdr.dcontext,50,'0')) ";
|
|
$where .= " ) ";
|
|
|
|
|
|
}
|
|
|
|
if((isset($_REQUEST['parent_to_advanced']) && $_REQUEST['parent_to_advanced'] != '')) {
|
|
$to = $_REQUEST['parent_to_advanced'];
|
|
$params['distinct'] = true;
|
|
$ecb_r = true;
|
|
if($where != '') $where .= ' AND ';
|
|
if(isset($_REQUEST['parent_to_id_advanced']) && $_REQUEST['parent_to_id_advanced'] != '') $ptida = " AND r.bean_id IN('".implode("', '", $_REQUEST['parent_to_id_advanced'])."') "; else $ptida = '';
|
|
|
|
$where .= " ( ";
|
|
if(isset($to) && $to != '') $where .= " r.bean_module = '".$_REQUEST['parent_to_advanced']."' $ptida AND LPAD(r.src,50,'0')=LPAD(cdr.dst,50,'0') ";
|
|
$where .= " ) ";
|
|
|
|
}
|
|
|
|
if((isset($_REQUEST['dst_advanced']) && $_REQUEST['dst_advanced'] != '')) {
|
|
$to = $_REQUEST['dst_advanced'];
|
|
if($where != '') $where .= ' AND ';
|
|
$where .= " ( ";
|
|
if(isset($to) && $to != '') $where .= " cdr.dst LIKE '".$to."%' || cdr.dst = '".$to."'";
|
|
$where .= " ) ";
|
|
}
|
|
if((isset($_REQUEST['src_advanced']) && $_REQUEST['src_advanced'] != '')) {
|
|
$to = $_REQUEST['src_advanced'];
|
|
if($where != '') $where .= ' AND ';
|
|
$where .= " ( ";
|
|
if(isset($to) && $to != '') $where .= " cdr.src LIKE '".$to."%' || cdr.src = '".$to."'";
|
|
$where .= " ) ";
|
|
}
|
|
|
|
}
|
|
|
|
if($ecb_l) $ret_array['from'] .= ", ecmcalls_beans as l ";
|
|
if($ecb_r) $ret_array['from'] .= ", ecmcalls_beans as r ";
|
|
if($ecb_l && $ecb_r) $where .= " AND l.ecmcall_id = r.ecmcall_id ";
|
|
else if($ecb_l && !$ecb_r) $where .= " AND l.ecmcall_id = cdr.id ";
|
|
else if(!$ecb_l && $ecb_r) $where .= " AND r.ecmcall_id = cdr.id ";
|
|
|
|
|
|
//if(!empty($params['distinct']))
|
|
//{
|
|
$distinct = ' DISTINCT ';
|
|
//}
|
|
if(empty($filter))
|
|
{
|
|
$ret_array['select'] = " SELECT $distinct $this->table_name.* ";
|
|
}
|
|
else
|
|
{
|
|
$ret_array['select'] = " SELECT $distinct $this->table_name.id ";
|
|
}
|
|
//EcmTeam *********************************************
|
|
if(class_exists('EcmTeam') && EcmTeam::isUseEcmTeamEnabled()) $ret_array['select'] = EcmTeam::addTeamSelect($this, $ret_array['select']);
|
|
//*****************************************************
|
|
|
|
$ret_array['from_min'] = $ret_array['from'];
|
|
$ret_array['secondary_from'] = $ret_array['from'] ;
|
|
$ret_array['where'] = '';
|
|
$ret_array['order_by'] = '';
|
|
//secondary selects are selects that need to be run after the primarty query to retrieve additional info on main
|
|
if($singleSelect)
|
|
{
|
|
$ret_array['secondary_select']=& $ret_array['select'];
|
|
$ret_array['secondary_from'] = & $ret_array['from'];
|
|
}
|
|
else
|
|
{
|
|
$ret_array['secondary_select'] = '';
|
|
}
|
|
$custom_join = false;
|
|
if((!isset($params['include_custom_fields']) || $params['include_custom_fields']) && isset($this->custom_fields))
|
|
{
|
|
$custom_join = $this->custom_fields->getJOIN();
|
|
if($custom_join)
|
|
{
|
|
$ret_array['select'] .= ' ' .$custom_join['select'];
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if($custom_join)
|
|
{
|
|
$ret_array['from'] .= ' ' . $custom_join['join'];
|
|
}
|
|
$jtcount = 0;
|
|
//LOOP AROUND FOR FIXIN VARDEF ISSUES
|
|
require('include/VarDefHandler/listvardefoverride.php');
|
|
$joined_tables = array();
|
|
if(isset($params['joined_tables']))
|
|
{
|
|
foreach($params['joined_tables'] as $table)
|
|
{
|
|
$joined_tables[$table] = 1;
|
|
}
|
|
}
|
|
if(!empty($filter))
|
|
{
|
|
$filterKeys = array_keys($filter);
|
|
if(is_numeric($filterKeys[0]))
|
|
{
|
|
$fields = array();
|
|
foreach($filter as $field)
|
|
{
|
|
$field = strtolower($field);
|
|
if(isset($this->field_defs[$field]))
|
|
{
|
|
$fields[$field]= $this->field_defs[$field];
|
|
}
|
|
else
|
|
{
|
|
$fields[$field] = array('force_exists'=>true);
|
|
}
|
|
}
|
|
}else{
|
|
$fields = $filter;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
$fields = $this->field_defs;
|
|
}
|
|
|
|
foreach($fields as $field=>$value)
|
|
{
|
|
//alias is used to alias field names
|
|
$alias='';
|
|
if (isset($value['alias']))
|
|
{
|
|
$alias =' as ' . $value['alias'] . ' ';
|
|
}
|
|
|
|
if(empty($this->field_defs[$field]) || !empty($value['force_blank']) )
|
|
{
|
|
if(!empty($filter) && isset($filter[$field]['force_exists']) && $filter[$field]['force_exists'])
|
|
{
|
|
//spaces are a fix for length issue problem with unions. The union only returns the maximum number of characters from the first select statemtn.
|
|
$ret_array['select'] .= ", ' ' $field ";
|
|
}
|
|
continue;
|
|
}
|
|
else
|
|
{
|
|
$data = $this->field_defs[$field];
|
|
}
|
|
|
|
//ignore fields that are a part of the collection and a field has been removed as a result of
|
|
//layout customization.. this happens in subpanel customizations, use case, from the contacts subpanel
|
|
//in opportunities module remove the contact_role/opportunity_role field.
|
|
$process_field=true;
|
|
if (isset($data['relationship_fields']) and !empty($data['relationship_fields']))
|
|
{
|
|
foreach ($data['relationship_fields'] as $field_name)
|
|
{
|
|
if (!isset($fields[$field_name]))
|
|
{
|
|
$process_field=false;
|
|
}
|
|
}
|
|
}
|
|
if (!$process_field)
|
|
{
|
|
continue;
|
|
}
|
|
|
|
if( (!isset($data['source']) || $data['source'] == 'db') && (!empty($alias) || !empty($filter) ))
|
|
{
|
|
$ret_array['select'] .= ", $this->table_name.$field $alias";
|
|
$selectedFields["$this->table_name.$field"] = true;
|
|
}
|
|
|
|
|
|
if($data['type'] != 'relate' && isset($data['db_concat_fields']))
|
|
{
|
|
$ret_array['select'] .= ", " . db_concat($this->table_name, $data['db_concat_fields']) . " as $field";
|
|
$selectedFields[db_concat($this->table_name, $data['db_concat_fields'])] = true;
|
|
}
|
|
if($data['type'] == 'relate' && isset($data['link']))
|
|
{
|
|
|
|
$this->load_relationship($data['link']);
|
|
if(!empty($this->$data['link']))
|
|
{
|
|
|
|
$params = array();
|
|
if(empty($join_type))
|
|
{
|
|
$params['join_type'] = ' LEFT JOIN ';
|
|
}
|
|
else
|
|
{
|
|
$params['join_type'] = $join_type;
|
|
}
|
|
if(isset($data['join_name']))
|
|
{
|
|
$params['join_table_alias'] = $data['join_name'];
|
|
}
|
|
else
|
|
{
|
|
$params['join_table_alias'] = 'jt' . $jtcount;
|
|
|
|
}
|
|
if(isset($data['join_link_name']))
|
|
{
|
|
$params['join_table_link_alias'] = $data['join_link_name'];
|
|
}
|
|
else
|
|
{
|
|
$params['join_table_link_alias'] = 'jtl' . $jtcount;
|
|
}
|
|
|
|
|
|
$join = $this->$data['link']->getJoin($params, true);
|
|
$rel_module = $this->$data['link']->getRelatedModuleName();
|
|
$table_joined = !empty($joined_tables[$params['join_table_alias']]) || (!empty($joined_tables[$params['join_table_link_alias']]) && isset($data['link_type']) && $data['link_type'] == 'relationship_info');
|
|
|
|
if($join['type'] == 'many-to-many')
|
|
{
|
|
if(empty($ret_array['secondary_select']))
|
|
{
|
|
$ret_array['secondary_select'] = " SELECT $this->table_name.id ref_id ";
|
|
|
|
if(!empty($beanFiles[$beanList[$rel_module]]))
|
|
{
|
|
require_once($beanFiles[$beanList[$rel_module]]);
|
|
$rel_mod = new $beanList[$rel_module]();
|
|
if(isset($rel_mod->field_defs['assigned_user_id']))
|
|
{
|
|
$ret_array['secondary_select'].= " , ". $params['join_table_alias'] . ".assigned_user_id {$field}_owner, '$rel_module' {$field}_mod";
|
|
|
|
}
|
|
else
|
|
{
|
|
if(isset($rel_mod->field_defs['created_by']))
|
|
{
|
|
$ret_array['secondary_select'].= " , ". $params['join_table_alias'] . ".created_by {$field}_owner , '$rel_module' {$field}_mod";
|
|
|
|
}
|
|
}
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
if(isset($data['db_concat_fields']))
|
|
{
|
|
$ret_array['secondary_select'] .= ' , ' . db_concat($params['join_table_alias'], $data['db_concat_fields']) . ' ' . $field;
|
|
}
|
|
else
|
|
{
|
|
if(!isset($data['relationship_fields']))
|
|
{
|
|
$ret_array['secondary_select'] .= ' , ' . $params['join_table_alias'] . '.' . $data['rname'] . ' ' . $field;
|
|
}
|
|
}
|
|
if(!$singleSelect)
|
|
{
|
|
$ret_array['select'] .= ", ' ' $field ";
|
|
$ret_array['select'] .= ", ' ' " . $join['rel_key'] . ' ';
|
|
}
|
|
$ret_array['secondary_select'] .= ', ' . $params['join_table_link_alias'].'.'. $join['rel_key'] .' ' . $join['rel_key'];
|
|
if(isset($data['relationship_fields']))
|
|
{
|
|
foreach($data['relationship_fields'] as $r_name=>$alias_name)
|
|
{
|
|
if(!empty( $secondarySelectedFields[$alias_name]))continue;
|
|
$ret_array['secondary_select'] .= ', ' . $params['join_table_link_alias'].'.'. $r_name .' ' . $alias_name;
|
|
$secondarySelectedFields[$alias_name] = true;
|
|
}
|
|
}
|
|
if(!$table_joined)
|
|
{
|
|
$ret_array['secondary_from'] .= ' ' . $join['join']. ' AND ' . $params['join_table_alias'].'.deleted=0';
|
|
if (isset($data['link_type']) && $data['link_type'] == 'relationship_info')
|
|
{
|
|
$ret_array['secondary_where'] = $params['join_table_link_alias'] . '.' . $join['rel_key']. "='" .$parentbean->id . "'";
|
|
}
|
|
}
|
|
}
|
|
else
|
|
{
|
|
if(isset($data['db_concat_fields']))
|
|
{
|
|
$ret_array['select'] .= ' , ' . db_concat($params['join_table_alias'], $data['db_concat_fields']) . ' ' . $field;
|
|
}
|
|
else
|
|
{
|
|
$ret_array['select'] .= ' , ' . $params['join_table_alias'] . '.' . $data['rname'] . ' ' . $field;
|
|
}
|
|
if(!$table_joined)
|
|
{
|
|
$ret_array['from'] .= ' ' . $join['join']. ' AND ' . $params['join_table_alias'].'.deleted=0';
|
|
if(!empty($beanList[$rel_module]) && !empty($beanFiles[$beanList[$rel_module]]))
|
|
{
|
|
require_once($beanFiles[$beanList[$rel_module]]);
|
|
$rel_mod = new $beanList[$rel_module]();
|
|
if(isset($value['target_record_key']) && !empty($filter))
|
|
{
|
|
$selectedFields[$this->table_name.'.'.$value['target_record_key']] = true;
|
|
$ret_array['select'] .= " , $this->table_name.{$value['target_record_key']} ";
|
|
}
|
|
if(isset($rel_mod->field_defs['assigned_user_id']))
|
|
{
|
|
$ret_array['select'] .= ' , ' .$params['join_table_alias'] . '.assigned_user_id ' . $field . '_owner';
|
|
}
|
|
else
|
|
{
|
|
$ret_array['select'] .= ' , ' .$params['join_table_alias'] . '.created_by ' . $field . '_owner';
|
|
}
|
|
$ret_array['select'] .= " , '".$rel_module ."' " . $field . '_mod';
|
|
|
|
}
|
|
}
|
|
}
|
|
//Replace references to this table in the where clause with the new alias
|
|
$join_table_name = $this->$data['link']->getRelatedTableName();
|
|
$where = str_replace("$join_table_name.", "{$params['join_table_alias']}.", $where);
|
|
|
|
if(!$table_joined)
|
|
{
|
|
$joined_tables[$params['join_table_alias']]=1;
|
|
$joined_tables[$params['join_table_link_alias']]=1;
|
|
}
|
|
|
|
$jtcount++;
|
|
}
|
|
}
|
|
}
|
|
if(!empty($filter))
|
|
{
|
|
if(isset($this->field_defs['assigned_user_id']) && empty($selectedFields[$this->table_name.'.assigned_user_id']))
|
|
{
|
|
$ret_array['select'] .= ", $this->table_name.assigned_user_id ";
|
|
}
|
|
else if(isset($this->field_defs['created_by']) && empty($selectedFields[$this->table_name.'.created_by']))
|
|
{
|
|
$ret_array['select'] .= ", $this->table_name.created_by ";
|
|
}
|
|
if(isset($this->field_defs['system_id']) && empty($selectedFields[$this->table_name.'.system_id']))
|
|
{
|
|
$ret_array['select'] .= ", $this->table_name.system_id ";
|
|
}
|
|
}
|
|
$where_auto = '1=1';
|
|
if($show_deleted == 0)
|
|
{
|
|
$where_auto = "$this->table_name.deleted=0";
|
|
}else if($show_deleted == 1)
|
|
{
|
|
$where_auto = "$this->table_name.deleted=1";
|
|
}
|
|
|
|
if($where != "")
|
|
$ret_array['where'] = " where ($where) AND $where_auto";
|
|
else
|
|
$ret_array['where'] = " where $where_auto";
|
|
if(!empty($order_by))
|
|
{
|
|
//make call to process the order by clause
|
|
$ret_array['order_by'] = " ORDER BY ". $this->process_order_by($order_by, null);
|
|
}
|
|
if($singleSelect)
|
|
{
|
|
unset($ret_array['secondary_where']);
|
|
unset($ret_array['secondary_from']);
|
|
unset($ret_array['secondary_select']);
|
|
}
|
|
|
|
//var_dump($_REQUEST); echo '<br><br>';
|
|
//var_dump($ret_array);
|
|
/*
|
|
if($_REQUEST['out']=="1") {
|
|
var_dump($ret_array);
|
|
}
|
|
*/
|
|
|
|
if($return_array)
|
|
{
|
|
//print_r($ret_array);
|
|
return $ret_array;
|
|
}
|
|
|
|
$arr = $ret_array['select'] . $ret_array['from'] . $ret_array['where']. $ret_array['order_by'];
|
|
//echo $arr;
|
|
return $arr;
|
|
}
|
|
|
|
static function getParentFromDropDown(){
|
|
static $parent_from = null;
|
|
if(!$parent_from){
|
|
global $app_list_strings;
|
|
$parent_from['Contacts'] = $app_list_strings['moduleList']['Contacts'];
|
|
$parent_from['Accounts'] = $app_list_strings['moduleList']['Accounts'];
|
|
$parent_from['Users'] = $app_list_strings['moduleList']['Users'];
|
|
}
|
|
return $parent_from;
|
|
}
|
|
|
|
static function getPhoneList($array = false) {
|
|
$query = "SELECT `phone`, `note` FROM `ecmcallsphones` WHERE bean_module = 'EcmCalls' ORDER BY `index` ASC";
|
|
$r = $GLOBALS['db']->query($query);
|
|
$return_array = array();
|
|
if($r) {
|
|
while($w = $GLOBALS['db']->fetchByAssoc($r)) {
|
|
$return_array [] = $w;
|
|
}
|
|
$json = getJSONobj();
|
|
return $array ? $return_array : str_replace('"','\"',$json->encode($return_array));
|
|
}
|
|
return $array ? false : '[]';
|
|
}
|
|
|
|
static function savePhoneList($array) {
|
|
$query = "DELETE FROM `ecmcallsphones` WHERE `bean_module` = 'EcmCalls'";
|
|
$r = $GLOBALS['db']->query($query);
|
|
$i = 0;
|
|
foreach($array as $key => $value) {
|
|
$query = "INSERT INTO `ecmcallsphones` (`id`,`bean_module`,`bean_id`,`phone`, `note`, `index`) VALUES ('".create_guid()."', 'EcmCalls', '', '".$value['phone']."', '".$value['note']."', '".$i++."')";
|
|
$r = $GLOBALS['db']->query($query);
|
|
}
|
|
}
|
|
|
|
}
|
|
?>
|