更新到 5.2 正式版后第一次 SVN 提交。
[email protected] git-svn-id: https://svn.code.sf.net/p/hawebs/svn@627 a2543c7e-f6e9-4f8a-8bff-1ffc34733512
This commit is contained in:
@@ -0,0 +1,221 @@
|
||||
<?php
|
||||
/*********************************************************************************
|
||||
** The contents of this file are subject to the vtiger CRM Public License Version 1.0
|
||||
* ("License"); You may not use this file except in compliance with the License
|
||||
* The Original Code is: vtiger CRM Open Source
|
||||
* The Initial Developer of the Original Code is vtiger.
|
||||
* Portions created by vtiger are Copyright (C) vtiger.
|
||||
* All Rights Reserved.
|
||||
********************************************************************************/
|
||||
/**
|
||||
* this function returns the asterisk server information
|
||||
* @param $adb - the peardatabase type object
|
||||
* @return array $data - contains the asterisk server and port information in the format array(server, port)
|
||||
*/
|
||||
function getAsteriskInfo($adb){
|
||||
global $log;
|
||||
$sql = "select * from vtiger_asterisk";
|
||||
$server = "";
|
||||
$port = ""; //hard-coded for now
|
||||
|
||||
$result = $adb->pquery($sql, array());
|
||||
if($adb->num_rows($result)>0){
|
||||
$data = array();
|
||||
$data['server'] = $adb->query_result($result,0,"server");
|
||||
$data['port'] = $adb->query_result($result,0,"port");
|
||||
$data['username'] = $adb->query_result($result,0,"username");
|
||||
$data['password'] = $adb->query_result($result,0,"password");
|
||||
$data['version'] = $adb->query_result($result,0,"version");
|
||||
return $data;
|
||||
}else{
|
||||
$log->debug("Asterisk server settings not specified.\n".
|
||||
"Change the configuration from vtiger-> Settings-> Softphone Settings\n");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* this function will authorize the first user from the database that it finds
|
||||
* this is required as some user must be authenticated into the asterisk server to
|
||||
* receive the events that are being generated by asterisk
|
||||
*
|
||||
* @param string $username - the asterisk username
|
||||
* @param string $password - the asterisk password
|
||||
* @param object $asterisk - asterisk type object
|
||||
*/
|
||||
function authorizeUser($username, $password, $asterisk){
|
||||
echo "Trying to login to asterisk\n";
|
||||
|
||||
if(!empty($username) && !empty($password)){
|
||||
$asterisk->setUserInfo($username, $password);
|
||||
if( !$asterisk->authenticateUser() ) {
|
||||
echo "Cannot login to asterisk using\n
|
||||
User: $username\n
|
||||
Password: $password\n
|
||||
Please check your configuration details.\n";
|
||||
exit(0);
|
||||
}else{
|
||||
echo "Logged in successfully to asterisk server\n\n";
|
||||
return true;
|
||||
}
|
||||
}else{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* this function logs in a user so that he can make calls
|
||||
* @param string $username - the asterisk username
|
||||
* @param string $password - the asterisk password
|
||||
* @param object $asterisk - asterisk type object
|
||||
*/
|
||||
function loginUser($username, $password, $asterisk){
|
||||
if(!empty($username) && !empty($password)){
|
||||
$asterisk->setUserInfo($username, $password);
|
||||
if( !$asterisk->authenticateUser() ) {
|
||||
echo "Cannot login to asterisk using\n
|
||||
User: $username\n
|
||||
Password: $password\n
|
||||
Please check your configuration details.\n";
|
||||
exit(0);
|
||||
}else{
|
||||
return true;
|
||||
}
|
||||
}else{
|
||||
echo "Missing username and/or password";
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* this function returns the channel for the current call
|
||||
* @param object $asterisk - the asterisk object
|
||||
* @return :: on success - string $value - the channel for the current call
|
||||
* on failure - false
|
||||
*/
|
||||
function getChannel($asterisk){
|
||||
$res = array();
|
||||
while(true){
|
||||
$res = $asterisk->getAsteriskResponse(false);
|
||||
if(empty($res)){
|
||||
continue;
|
||||
}
|
||||
foreach($res as $action => $value) {
|
||||
if($action == 'Channel'){
|
||||
return $value;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* this function accepts a asterisk extension and returnsthe userid for which it is associated to
|
||||
* in case of multiple users having the extension, it returns the first find
|
||||
* @param string $extension - the asterisk extension for the user
|
||||
* @param object $adb - the peardatabase object
|
||||
* @return integer $userid - the user id with the extension
|
||||
*/
|
||||
function getUserFromExtension($extension, $adb){
|
||||
$userid = false;
|
||||
$sql = "select userid from vtiger_asteriskextensions where asterisk_extension=?";
|
||||
$result = $adb->pquery($sql, array($extension));
|
||||
if($adb->num_rows($result) > 0){
|
||||
$userid = $adb->query_result($result, 0, "userid");
|
||||
}
|
||||
return $userid;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* this function adds the call information to the actvity history
|
||||
* @param string $callerName - the caller name
|
||||
* @param string $callerNumber - the callers' number
|
||||
* @param string $callerType - the caller type (SIP/PSTN...)
|
||||
* @param object $adb - the peardatabase object
|
||||
* @param object $current_user - the current user
|
||||
* @return string $status - on success - string success
|
||||
* on failure - string failure
|
||||
*/
|
||||
function asterisk_addToActivityHistory($callerName, $callerNumber, $callerType, $adb, $userid, $relcrmid, $callerInfo=false){
|
||||
global $log, $current_user;
|
||||
|
||||
// Reset date format for a while
|
||||
$old_userdate_format = $current_user->date_format;
|
||||
$current_user->date_format = 'yyyy-mm-dd';
|
||||
|
||||
require_once 'modules/Calendar/Activity.php';
|
||||
$focus = new Activity();
|
||||
$focus->column_fields['subject'] = "Incoming call from $callerName ($callerNumber)";
|
||||
$focus->column_fields['activitytype'] = "Call";
|
||||
$focus->column_fields['date_start'] = date('Y-m-d');
|
||||
$focus->column_fields['due_date'] = date('Y-m-d');
|
||||
$focus->column_fields['time_start'] = date('H:i');
|
||||
$focus->column_fields['time_end'] = date('H:i');
|
||||
$focus->column_fields['eventstatus'] = "Held";
|
||||
$focus->column_fields['assigned_user_id'] = $userid;
|
||||
$focus->save('Calendar');
|
||||
$focus->setActivityReminder('off');
|
||||
|
||||
// Restore dateformat
|
||||
$current_user->date_format = $old_userdate_format;
|
||||
|
||||
if(empty($relcrmid)) {
|
||||
if(empty($callerInfo)) {
|
||||
$callerInfo = getCallerInfo($callerNumber);
|
||||
}
|
||||
} else {
|
||||
$callerInfo = array();
|
||||
$callerInfo['module'] = getSalesEntityType($relcrmid);
|
||||
$callerInfo['id'] = $relcrmid;
|
||||
}
|
||||
|
||||
if($callerInfo != false){
|
||||
$tablename = array('Contacts'=>'vtiger_cntactivityrel', 'Accounts'=>'vtiger_seactivityrel', 'Leads'=>'vtiger_seactivityrel');
|
||||
$sql = "insert into ".$tablename[$callerInfo['module']]." values (?,?)";
|
||||
$params = array($callerInfo['id'], $focus->id);
|
||||
$adb->pquery($sql, $params);
|
||||
}
|
||||
|
||||
return $focus->id;
|
||||
}
|
||||
|
||||
/* Function to add an outgoing call to the History
|
||||
* Params Object $current_user - the current user
|
||||
* string $extension - the users extension number
|
||||
* int $record - the activity will be attached to this record
|
||||
* object $adb - the peardatabase object
|
||||
*/
|
||||
function addOutgoingcallHistory($current_user,$extension, $record ,$adb){
|
||||
global $log;
|
||||
require_once 'modules/Calendar/Activity.php';
|
||||
$focus = new Activity();
|
||||
$focus->column_fields['subject'] = "Outgoing call from $current_user->user_name ($extension)";
|
||||
$focus->column_fields['activitytype'] = "Call";
|
||||
$focus->column_fields['date_start'] = date('Y-m-d');
|
||||
$focus->column_fields['due_date'] = date('Y-m-d');
|
||||
$focus->column_fields['time_start'] = date('H:i');
|
||||
$focus->column_fields['time_end'] = date('H:i');
|
||||
$focus->column_fields['eventstatus'] = "Held";
|
||||
$focus->column_fields['assigned_user_id'] = $current_user->id;
|
||||
$focus->save('Calendar');
|
||||
$focus->setActivityReminder('off');
|
||||
$setype = $adb->pquery("SELECT setype FROM vtiger_crmentity WHERE crmid = ?",array($record));
|
||||
$rows = $adb->num_rows($setype);
|
||||
|
||||
if($rows > 0){
|
||||
$module = $adb->query_result($setype,0,'setype');
|
||||
$tablename = array('Contacts'=>'vtiger_cntactivityrel', 'Accounts'=>'vtiger_seactivityrel', 'Leads'=>'vtiger_seactivityrel');
|
||||
$sql = "insert into ".$tablename[$module]." values (?,?)";
|
||||
$params = array($record, $focus->id);
|
||||
$adb->pquery($sql, $params);
|
||||
$status = "success";
|
||||
}else{
|
||||
$status = "failure";
|
||||
}
|
||||
|
||||
return $status;
|
||||
}
|
||||
?>
|
||||
@@ -0,0 +1,11 @@
|
||||
<?php
|
||||
/*********************************************************************************
|
||||
** The contents of this file are subject to the vtiger CRM Public License Version 1.0
|
||||
* ("License"); You may not use this file except in compliance with the License
|
||||
* The Original Code is: vtiger CRM Open Source
|
||||
* The Initial Developer of the Original Code is vtiger.
|
||||
* Portions created by vtiger are Copyright (C) vtiger.
|
||||
* All Rights Reserved.
|
||||
********************************************************************************/
|
||||
|
||||
?>
|
||||
@@ -0,0 +1,13 @@
|
||||
<?php
|
||||
/*********************************************************************************
|
||||
** The contents of this file are subject to the vtiger CRM Public License Version 1.0
|
||||
* ("License"); You may not use this file except in compliance with the License
|
||||
* The Original Code is: vtiger CRM Open Source
|
||||
* The Initial Developer of the Original Code is vtiger.
|
||||
* Portions created by vtiger are Copyright (C) vtiger.
|
||||
* All Rights Reserved.
|
||||
********************************************************************************/
|
||||
|
||||
include('modules/CustomView/index.php');
|
||||
|
||||
?>
|
||||
@@ -0,0 +1,26 @@
|
||||
<?php
|
||||
/*+********************************************************************************
|
||||
* The contents of this file are subject to the vtiger CRM Public License Version 1.0
|
||||
* ("License"); You may not use this file except in compliance with the License
|
||||
* The Original Code is: vtiger CRM Open Source
|
||||
* The Initial Developer of the Original Code is vtiger.
|
||||
* Portions created by vtiger are Copyright (C) vtiger.
|
||||
* All Rights Reserved.
|
||||
********************************************************************************/
|
||||
|
||||
global $currentModule;
|
||||
$focus = CRMEntity::getInstance($currentModule);
|
||||
|
||||
$record = vtlib_purify($_REQUEST['record']);
|
||||
$module = vtlib_purify($_REQUEST['module']);
|
||||
$return_module = vtlib_purify($_REQUEST['return_module']);
|
||||
$return_action = vtlib_purify($_REQUEST['return_action']);
|
||||
$return_id = vtlib_purify($_REQUEST['return_id']);
|
||||
|
||||
DeleteEntity($currentModule, $return_module, $focus, $record, $return_id);
|
||||
|
||||
$parenttab = getParentTab();
|
||||
|
||||
header("Location: index.php?module=$return_module&action=$return_action&record=$return_id&parenttab=$parenttab&relmodule=$module");
|
||||
|
||||
?>
|
||||
@@ -0,0 +1,11 @@
|
||||
<?php
|
||||
/*********************************************************************************
|
||||
** The contents of this file are subject to the vtiger CRM Public License Version 1.0
|
||||
* ("License"); You may not use this file except in compliance with the License
|
||||
* The Original Code is: vtiger CRM Open Source
|
||||
* The Initial Developer of the Original Code is vtiger.
|
||||
* Portions created by vtiger are Copyright (C) vtiger.
|
||||
* All Rights Reserved.
|
||||
********************************************************************************/
|
||||
|
||||
?>
|
||||
@@ -0,0 +1,11 @@
|
||||
<?php
|
||||
/*********************************************************************************
|
||||
** The contents of this file are subject to the vtiger CRM Public License Version 1.0
|
||||
* ("License"); You may not use this file except in compliance with the License
|
||||
* The Original Code is: vtiger CRM Open Source
|
||||
* The Initial Developer of the Original Code is vtiger.
|
||||
* Portions created by vtiger are Copyright (C) vtiger.
|
||||
* All Rights Reserved.
|
||||
********************************************************************************/
|
||||
|
||||
?>
|
||||
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
/*********************************************************************************
|
||||
|
||||
** The contents of this file are subject to the vtiger CRM Public License Version 1.0
|
||||
* ("License"); You may not use this file except in compliance with the License
|
||||
* The Original Code is: vtiger CRM Open Source
|
||||
* The Initial Developer of the Original Code is vtiger.
|
||||
* Portions created by vtiger are Copyright (C) vtiger.
|
||||
* All Rights Reserved.
|
||||
********************************************************************************/
|
||||
|
||||
global $app_strings, $mod_strings, $current_language, $currentModule, $theme;
|
||||
|
||||
require_once('Smarty_setup.php');
|
||||
require_once("modules/$currentModule/$currentModule.php");
|
||||
|
||||
$focus = new $currentModule();
|
||||
$smarty = new vtigerCRM_Smarty();
|
||||
|
||||
$category = getParentTab($currentModule);
|
||||
|
||||
$smarty->assign('APP', $app_strings);
|
||||
$smarty->assign('MOD', $mod_strings);
|
||||
$smarty->assign('MODULE', $currentModule);
|
||||
|
||||
$smarty->assign('SINGLE_MOD', "CallHistory");
|
||||
$smarty->assign('CATEGORY', $category);
|
||||
$smarty->assign("THEME", $theme);
|
||||
$smarty->assign('IMAGE_PATH', "themes/$theme/images/");
|
||||
|
||||
$smarty->assign('CHECK', array());
|
||||
|
||||
$smarty->display(vtlib_getModuleTemplate('PBXManager', 'EditView.tpl'));
|
||||
|
||||
?>
|
||||
@@ -0,0 +1,13 @@
|
||||
<?php
|
||||
/*********************************************************************************
|
||||
** The contents of this file are subject to the vtiger CRM Public License Version 1.0
|
||||
* ("License"); You may not use this file except in compliance with the License
|
||||
* The Original Code is: vtiger CRM Open Source
|
||||
* The Initial Developer of the Original Code is vtiger.
|
||||
* Portions created by vtiger are Copyright (C) vtiger.
|
||||
* All Rights Reserved.
|
||||
********************************************************************************/
|
||||
|
||||
require_once('include/utils/ExportRecords.php');
|
||||
|
||||
?>
|
||||
@@ -0,0 +1,13 @@
|
||||
<?php
|
||||
/*********************************************************************************
|
||||
** The contents of this file are subject to the vtiger CRM Public License Version 1.0
|
||||
* ("License"); You may not use this file except in compliance with the License
|
||||
* The Original Code is: vtiger CRM Open Source
|
||||
* The Initial Developer of the Original Code is vtiger.
|
||||
* Portions created by vtiger are Copyright (C) vtiger.
|
||||
* All Rights Reserved.
|
||||
********************************************************************************/
|
||||
|
||||
require_once('modules/Import/index.php');
|
||||
|
||||
?>
|
||||
@@ -0,0 +1,180 @@
|
||||
<?php
|
||||
/*+********************************************************************************
|
||||
* The contents of this file are subject to the vtiger CRM Public License Version 1.0
|
||||
* ("License"); You may not use this file except in compliance with the License
|
||||
* The Original Code is: vtiger CRM Open Source
|
||||
* The Initial Developer of the Original Code is vtiger.
|
||||
* Portions created by vtiger are Copyright (C) vtiger.
|
||||
* All Rights Reserved.
|
||||
********************************************************************************/
|
||||
|
||||
global $app_strings, $mod_strings, $current_language, $currentModule, $theme;
|
||||
global $list_max_entries_per_page;
|
||||
|
||||
require_once('Smarty_setup.php');
|
||||
require_once('include/ListView/ListView.php');
|
||||
require_once('modules/CustomView/CustomView.php');
|
||||
require_once('include/DatabaseUtil.php');
|
||||
require_once("modules/$currentModule/$currentModule.php");
|
||||
|
||||
$category = getParentTab();
|
||||
$url_string = '';
|
||||
|
||||
$tool_buttons = array("index"=>"yes",);
|
||||
$tool_buttons["moduleSettings"] = isModuleSettingPermitted($currentModule);
|
||||
$list_buttons = Array();
|
||||
if(isPermitted($currentModule,'Delete','') == 'yes') $list_buttons['del'] = $app_strings[LBL_MASS_DELETE];
|
||||
|
||||
$focus = new $currentModule();
|
||||
$sorder = $focus->getSortOrder();
|
||||
$order_by = $focus->getOrderBy();
|
||||
|
||||
$_SESSION[$currentModule."_Order_By"] = $order_by;
|
||||
$_SESSION[$currentModule."_Sort_Order"]=$sorder;
|
||||
|
||||
$smarty = new vtigerCRM_Smarty();
|
||||
|
||||
// Identify this module as custom module.
|
||||
$smarty->assign('CUSTOM_MODULE', true);
|
||||
|
||||
$smarty->assign('MOD', $mod_strings);
|
||||
$smarty->assign('APP', $app_strings);
|
||||
$smarty->assign("THEME", $theme);
|
||||
$smarty->assign('MODULE', $currentModule);
|
||||
$smarty->assign('SINGLE_MOD', "CallHistory");
|
||||
$smarty->assign('CATEGORY', $category);
|
||||
$smarty->assign('BUTTONS', $list_buttons);
|
||||
$smarty->assign('CHECK', $tool_buttons);
|
||||
$smarty->assign('IMAGE_PATH', "themes/$theme/images/");
|
||||
|
||||
$smarty->assign('CHANGE_OWNER', getUserslist());
|
||||
$smarty->assign('CHANGE_GROUP_OWNER', getGroupslist());
|
||||
|
||||
// Custom View
|
||||
$customView = new CustomView($currentModule);
|
||||
$viewid = $customView->getViewId($currentModule);
|
||||
$customview_html = $customView->getCustomViewCombo($viewid);
|
||||
$viewinfo = $customView->getCustomViewByCvid($viewid);
|
||||
|
||||
// Feature available from 5.1
|
||||
if(method_exists($customView, 'isPermittedChangeStatus')) {
|
||||
// Approving or Denying status-public by the admin in CustomView
|
||||
$statusdetails = $customView->isPermittedChangeStatus($viewinfo['status']);
|
||||
|
||||
// To check if a user is able to edit/delete a CustomView
|
||||
$edit_permit = $customView->isPermittedCustomView($viewid,'EditView',$currentModule);
|
||||
$delete_permit = $customView->isPermittedCustomView($viewid,'Delete',$currentModule);
|
||||
|
||||
$smarty->assign("CUSTOMVIEW_PERMISSION",$statusdetails);
|
||||
$smarty->assign("CV_EDIT_PERMIT",$edit_permit);
|
||||
$smarty->assign("CV_DELETE_PERMIT",$delete_permit);
|
||||
}
|
||||
// END
|
||||
|
||||
$smarty->assign("VIEWID", $viewid);
|
||||
|
||||
if($viewinfo['viewname'] == 'All') $smarty->assign('ALL', 'All');
|
||||
|
||||
global $current_user;
|
||||
$queryGenerator = new QueryGenerator($currentModule, $current_user);
|
||||
if ($viewid != "0") {
|
||||
$queryGenerator->initForCustomViewById($viewid);
|
||||
} else {
|
||||
$queryGenerator->initForDefaultCustomView();
|
||||
}
|
||||
|
||||
// Enabling Module Search
|
||||
$url_string = '';
|
||||
if($_REQUEST['query'] == 'true') {
|
||||
$queryGenerator->addUserSearchConditions($_REQUEST);
|
||||
$ustring = getSearchURL($_REQUEST);
|
||||
$url_string .= "&query=true$ustring";
|
||||
$smarty->assign('SEARCH_URL', $url_string);
|
||||
}
|
||||
|
||||
$list_query = $queryGenerator->getQuery();
|
||||
// Sorting
|
||||
if(!empty($order_by)) {
|
||||
if($order_by == 'smownerid') $list_query .= ' ORDER BY user_name '.$sorder;
|
||||
else {
|
||||
$tablename = getTableNameForField($currentModule, $order_by);
|
||||
$tablename = ($tablename != '')? ($tablename . '.') : '';
|
||||
$list_query .= ' ORDER BY ' . $tablename . $order_by . ' ' . $sorder;
|
||||
}
|
||||
}
|
||||
|
||||
if(PerformancePrefs::getBoolean('LISTVIEW_COMPUTE_PAGE_COUNT', false) === true){
|
||||
$count_result = $adb->query( mkCountQuery( $list_query));
|
||||
$noofrows = $adb->query_result($count_result,0,"count");
|
||||
}else{
|
||||
$noofrows = null;
|
||||
}
|
||||
|
||||
$queryMode = (isset($_REQUEST['query']) && $_REQUEST['query'] == 'true');
|
||||
$start = ListViewSession::getRequestCurrentPage($currentModule, $list_query, $viewid, $queryMode);
|
||||
|
||||
$navigation_array = VT_getSimpleNavigationValues($start,$list_max_entries_per_page,$noofrows);
|
||||
|
||||
$limit_start_rec = ($start-1) * $list_max_entries_per_page;
|
||||
|
||||
if( $adb->dbType == "pgsql")
|
||||
$list_result = $adb->pquery($list_query. " OFFSET $limit_start_rec LIMIT $list_max_entries_per_page", array());
|
||||
else
|
||||
$list_result = $adb->pquery($list_query. " LIMIT $limit_start_rec, $list_max_entries_per_page", array());
|
||||
|
||||
$recordListRangeMsg = getRecordRangeMessage($list_result, $limit_start_rec,$noofrows);
|
||||
$smarty->assign('recordListRange',$recordListRangeMsg);
|
||||
|
||||
$smarty->assign("CUSTOMVIEW_OPTION",$customview_html);
|
||||
|
||||
// Navigation
|
||||
$start = $_SESSION['lvs'][$currentModule]['start'];
|
||||
$navigationOutput = getTableHeaderSimpleNavigation($navigation_array, $url_string, $currentModule, 'index', $viewid);
|
||||
$smarty->assign("NAVIGATION", $navigationOutput);
|
||||
|
||||
$controller = new ListViewController($adb, $current_user, $queryGenerator);
|
||||
$listview_header = $controller->getListViewHeader($focus,$currentModule,$url_string,$sorder,
|
||||
$order_by);
|
||||
$listview_entries = $controller->getListViewEntries($focus,$currentModule,$list_result,
|
||||
$navigation_array);
|
||||
$listview_header_search = $controller->getBasicSearchFieldInfoList();
|
||||
|
||||
// Convert field value to DetailView Link
|
||||
if(isset($focus->detailview_links) && count($focus->detailview_links)) {
|
||||
foreach($listview_entries as $listview_recid=>$listview_row) {
|
||||
foreach($listview_row as $listview_key=>$listview_val) {
|
||||
$listview_key_header = $listview_header[$listview_key];
|
||||
preg_match('/(<[^>]+>)([^<]+)(<[^>]+>)/', $listview_key_header, $matches);
|
||||
$linktext = array_search(trim($matches[2], ' \t\r\n'), $mod_strings);
|
||||
if(in_array($linktext, $focus->detailview_links)) {
|
||||
$listview_row[$listview_key] =
|
||||
"<a href='index.php?action=DetailView&module=$currentModule&record=$listview_recid&parenttab=$category'>".$listview_val."</a>";
|
||||
}
|
||||
}
|
||||
$listview_entries[$listview_recid] = $listview_row;
|
||||
}
|
||||
}
|
||||
$smarty->assign('LISTHEADER', $listview_header);
|
||||
$smarty->assign('LISTENTITY', $listview_entries);
|
||||
$smarty->assign('SEARCHLISTHEADER',$listview_header_search);
|
||||
|
||||
// Module Search
|
||||
$alphabetical = AlphabeticalSearch($currentModule,'index',$focus->def_basicsearch_col,'true','basic','','','','',$viewid);
|
||||
$fieldnames = $controller->getAdvancedSearchOptionString();
|
||||
$criteria = getcriteria_options();
|
||||
$smarty->assign("ALPHABETICAL", $alphabetical);
|
||||
$smarty->assign("FIELDNAMES", $fieldnames);
|
||||
$smarty->assign("CRITERIA", $criteria);
|
||||
|
||||
// Gather the custom link information to display
|
||||
include_once('vtlib/Vtiger/Link.php');
|
||||
$customlink_params = Array('MODULE'=>$currentModule, 'ACTION'=>vtlib_purify($_REQUEST['action']), 'CATEGORY'=> $category);
|
||||
$smarty->assign('CUSTOM_LINKS', Vtiger_Link::getAllByType(getTabid($currentModule), Array('LISTVIEWBASIC','LISTVIEW'), $customlink_params));
|
||||
// END
|
||||
|
||||
if(isset($_REQUEST['ajax']) && $_REQUEST['ajax'] != '')
|
||||
$smarty->display("ListViewEntries.tpl");
|
||||
else
|
||||
$smarty->display('ListView.tpl');
|
||||
|
||||
?>
|
||||
@@ -0,0 +1,11 @@
|
||||
<?php
|
||||
/*+*******************************************************************************
|
||||
* The contents of this file are subject to the vtiger CRM Public License Version 1.0
|
||||
* ("License"); You may not use this file except in compliance with the License
|
||||
* The Original Code is: vtiger CRM Open Source
|
||||
* The Initial Developer of the Original Code is vtiger.
|
||||
* Portions created by vtiger are Copyright (C) vtiger.
|
||||
* All Rights Reserved.
|
||||
*********************************************************************************/
|
||||
require_once 'include/ListView/ListViewPagging.php';
|
||||
?>
|
||||
@@ -0,0 +1,9 @@
|
||||
/*********************************************************************************
|
||||
** The contents of this file are subject to the vtiger CRM Public License Version 1.0
|
||||
* ("License"); You may not use this file except in compliance with the License
|
||||
* The Original Code is: vtiger CRM Open Source
|
||||
* The Initial Developer of the Original Code is vtiger.
|
||||
* Portions created by vtiger are Copyright (C) vtiger.
|
||||
* All Rights Reserved.
|
||||
********************************************************************************/
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,11 @@
|
||||
<?php
|
||||
/*********************************************************************************
|
||||
** The contents of this file are subject to the vtiger CRM Public License Version 1.0
|
||||
* ("License"); You may not use this file except in compliance with the License
|
||||
* The Original Code is: vtiger CRM Open Source
|
||||
* The Initial Developer of the Original Code is vtiger.
|
||||
* Portions created by vtiger are Copyright (C) vtiger.
|
||||
* All Rights Reserved.
|
||||
********************************************************************************/
|
||||
require_once('include/Ajax/CommonAjax.php');
|
||||
?>
|
||||
@@ -0,0 +1,43 @@
|
||||
<?php
|
||||
/*+********************************************************************************
|
||||
* The contents of this file are subject to the vtiger CRM Public License Version 1.0
|
||||
* ("License"); You may not use this file except in compliance with the License
|
||||
* The Original Code is: vtiger CRM Open Source
|
||||
* The Initial Developer of the Original Code is vtiger.
|
||||
* Portions created by vtiger are Copyright (C) vtiger.
|
||||
* All Rights Reserved.
|
||||
********************************************************************************/
|
||||
|
||||
global $current_user, $currentModule;
|
||||
require_once("modules/$currentModule/$currentModule.php");
|
||||
|
||||
$focus = new $currentModule();
|
||||
|
||||
if($mode) $focus->mode = $mode;
|
||||
if($record)$focus->id = $record;
|
||||
|
||||
setObjectValuesFromRequest($focus);
|
||||
|
||||
$mode = $_REQUEST['mode'];
|
||||
$record=$_REQUEST['record'];
|
||||
|
||||
if($_REQUEST['assigntype'] == 'U') {
|
||||
$focus->column_fields['assigned_user_id'] = $_REQUEST['assigned_user_id'];
|
||||
} elseif($_REQUEST['assigntype'] == 'T') {
|
||||
$focus->column_fields['assigned_user_id'] = $_REQUEST['assigned_group_id'];
|
||||
}
|
||||
$focus->save($currentModule);
|
||||
$return_id = $focus->id;
|
||||
|
||||
$parenttab = getParentTab();
|
||||
if($_REQUEST['return_module'] != '') $return_module = vtlib_purify($_REQUEST['return_module']);
|
||||
else $return_module = $currentModule;
|
||||
|
||||
if($_REQUEST['return_action'] != '') $return_action = vtlib_purify($_REQUEST['return_action']);
|
||||
else $return_action = "DetailView";
|
||||
|
||||
if($_REQUEST['return_id'] != '') $return_id = vtlib_purify($_REQUEST['return_id']);
|
||||
|
||||
header("Location: index.php?action=$return_action&module=$return_module&record=$return_id&parenttab=$parenttab&start=".vtlib_purify($_REQUEST['pagenumber']));
|
||||
|
||||
?>
|
||||
@@ -0,0 +1,46 @@
|
||||
<?php
|
||||
/*********************************************************************************
|
||||
** The contents of this file are subject to the vtiger CRM Public License Version 1.0
|
||||
* ("License"); You may not use this file except in compliance with the License
|
||||
* The Original Code is: vtiger CRM Open Source
|
||||
* The Initial Developer of the Original Code is vtiger.
|
||||
* Portions created by vtiger are Copyright (C) vtiger.
|
||||
* All Rights Reserved.
|
||||
*
|
||||
********************************************************************************/
|
||||
require_once ('include/utils/utils.php');
|
||||
require_once ('Smarty_setup.php');
|
||||
global $app_strings;
|
||||
global $mod_strings;
|
||||
global $adb;
|
||||
global $currentModule;
|
||||
global $theme;
|
||||
$theme_path = "themes/" . $theme . "/";
|
||||
$image_path = $theme_path . "images/";
|
||||
global $current_language;
|
||||
|
||||
$smarty = new vtigerCRM_Smarty;
|
||||
|
||||
$smarty->assign("MOD", return_module_language($current_language, 'Settings'));
|
||||
$smarty->assign("CMOD", $mod_strings);
|
||||
$smarty->assign("THEME", $theme);
|
||||
$smarty->assign("APP", $app_strings);
|
||||
$smarty->assign("IMAGE_PATH", $image_path);
|
||||
|
||||
$result = $adb->pquery("select * from vtiger_asterisk", array ());
|
||||
if($adb->num_rows($result) > 0){
|
||||
$asterisk_server_ip = $adb->query_result($result, 0, 'server');
|
||||
$asterisk_port = $adb->query_result($result, 0, 'port');
|
||||
$asterisk_username = $adb->query_result($result, 0, 'username');
|
||||
$asterisk_password = $adb->query_result($result, 0, 'password');
|
||||
$asterisk_version = $adb->query_result($result, 0, 'version');
|
||||
}
|
||||
|
||||
$smarty->assign("ASTERISK_SERVER_IP", $asterisk_server_ip);
|
||||
$smarty->assign("ASTERISK_PORT", $asterisk_port);
|
||||
$smarty->assign("ASTERISK_USERNAME", $asterisk_username);
|
||||
$smarty->assign("ASTERISK_PASSWORD", $asterisk_password);
|
||||
$smarty->assign("ASTERISK_VERSION", $asterisk_version);
|
||||
|
||||
$smarty->display(vtlib_getModuleTemplate('PBXManager', 'Settings.tpl'));
|
||||
?>
|
||||
@@ -0,0 +1,61 @@
|
||||
<?php
|
||||
/*+**********************************************************************************
|
||||
* The contents of this file are subject to the vtiger CRM Public License Version 1.0
|
||||
* ("License"); You may not use this file except in compliance with the License
|
||||
* The Original Code is: vtiger CRM Open Source
|
||||
* The Initial Developer of the Original Code is vtiger.
|
||||
* Portions created by vtiger are Copyright (C) vtiger.
|
||||
* All Rights Reserved.
|
||||
************************************************************************************/
|
||||
|
||||
/**
|
||||
* this function starts the call, it writes the caller and called information to database where it is picked up from
|
||||
*/
|
||||
echo startCall();
|
||||
|
||||
|
||||
|
||||
function startCall(){
|
||||
global $current_user, $adb,$log;
|
||||
require_once 'include/utils/utils.php';
|
||||
require_once 'modules/PBXManager/utils/AsteriskClass.php';
|
||||
require_once('modules/PBXManager/AsteriskUtils.php');
|
||||
|
||||
$id = $current_user->id;
|
||||
$number = $_REQUEST['number'];
|
||||
$record = $_REQUEST['recordid'];
|
||||
$result = $adb->query("select * from vtiger_asteriskextensions where userid=".$current_user->id);
|
||||
$extension = $adb->query_result($result, 0, "asterisk_extension");
|
||||
$data = getAsteriskInfo($adb);
|
||||
$server = $data['server'];
|
||||
$port = $data['port'];
|
||||
$username = $data['username'];
|
||||
$password = $data['password'];
|
||||
$version = $data['version'];
|
||||
$errno = $errstr = NULL;
|
||||
$sock = fsockopen($server, $port, $errno, $errstr, 1);
|
||||
stream_set_blocking($sock, false);
|
||||
if( $sock === false ) {
|
||||
echo "Socket cannot be created due to error: $errno: $errstr\n";
|
||||
$log->debug("Socket cannot be created due to error: $errno: $errstr\n");
|
||||
exit(0);
|
||||
}
|
||||
$asterisk = new Asterisk($sock, $server, $port);
|
||||
|
||||
loginUser($username, $password, $asterisk);
|
||||
|
||||
$asterisk->transfer($extension,$number);
|
||||
|
||||
$callerModule = getSalesEntityType($record);
|
||||
$entityNames = getEntityName($callerModule, array($record));
|
||||
$callerName = $entityNames[$record];
|
||||
$callerInfo = array('id'=>$record, 'module'=>$callerModule, 'name'=>$callerName);
|
||||
|
||||
//adds to pbx manager
|
||||
addToCallHistory($extension, $extension, $number, "outgoing", $adb, $callerInfo);
|
||||
|
||||
// add to the records activity history
|
||||
addOutgoingcallHistory($current_user ,$extension,$record ,$adb);
|
||||
|
||||
}
|
||||
?>
|
||||
@@ -0,0 +1,11 @@
|
||||
<?php
|
||||
/*********************************************************************************
|
||||
** The contents of this file are subject to the vtiger CRM Public License Version 1.0
|
||||
* ("License"); You may not use this file except in compliance with the License
|
||||
* The Original Code is: vtiger CRM Open Source
|
||||
* The Initial Developer of the Original Code is vtiger.
|
||||
* Portions created by vtiger are Copyright (C) vtiger.
|
||||
* All Rights Reserved.
|
||||
********************************************************************************/
|
||||
require_once('include/Ajax/TagCloud.php');
|
||||
?>
|
||||
@@ -0,0 +1,127 @@
|
||||
<?php
|
||||
/*+**********************************************************************************
|
||||
* The contents of this file are subject to the vtiger CRM Public License Version 1.0
|
||||
* ("License"); You may not use this file except in compliance with the License
|
||||
* The Original Code is: vtiger CRM Open Source
|
||||
* The Initial Developer of the Original Code is vtiger.
|
||||
* Portions created by vtiger are Copyright (C) vtiger.
|
||||
* All Rights Reserved.
|
||||
************************************************************************************/
|
||||
|
||||
echo TraceIncomingCall();
|
||||
|
||||
/**
|
||||
* This function traces an incoming call and adds it to the databse for vtiger to pickup,
|
||||
* it also adds an entry to the activity history of the related Contact/Lead/Account
|
||||
* only these three modules are supported for now
|
||||
*/
|
||||
function TraceIncomingCall(){
|
||||
|
||||
require_once('modules/PBXManager/AsteriskUtils.php');
|
||||
global $adb, $current_user;
|
||||
global $theme,$app_strings,$log;
|
||||
|
||||
$theme_path="themes/".$theme."/";
|
||||
$image_path=$theme_path."images/";
|
||||
|
||||
$asterisk_extension = false;
|
||||
if(isset($current_user->column_fields)) {
|
||||
$asterisk_extension = $current_user->column_fields['asterisk_extension'];
|
||||
} else {
|
||||
$sql = "select asterisk_extension from vtiger_asteriskextensions where userid = ?";
|
||||
$result = $adb->pquery($sql, array($current_user->id));
|
||||
$asterisk_extension = $adb->query_result($result, 0, "asterisk_extension");
|
||||
}
|
||||
|
||||
$query = "select * from vtiger_asteriskincomingcalls where to_number = ?";
|
||||
$result = $adb->pquery($query, array($asterisk_extension));
|
||||
|
||||
if($adb->num_rows($result)>0){
|
||||
$flag = $adb->query_result($result,0,"flag");
|
||||
$oldTime = $adb->query_result($result,0,"timer");
|
||||
$callerNumber = $adb->query_result($result,0,"from_number");
|
||||
$callerName = $adb->query_result($result,0,"from_name");
|
||||
$callerType = $adb->query_result($result,0,"callertype");
|
||||
$refuid = $adb->query_result($result, 0, "refuid");
|
||||
|
||||
if(!empty($callerNumber)){
|
||||
$tracedCallerInfo = getTraceIncomingCallerInfo($callerNumber);
|
||||
}
|
||||
|
||||
$callerLinks = $tracedCallerInfo['callerLinks'];
|
||||
$firstCallerInfo = false;
|
||||
if(!empty($tracedCallerInfo['callerInfos'])) {
|
||||
$firstCallerInfo = $tracedCallerInfo['callerInfos'];
|
||||
}
|
||||
|
||||
$newTime = time();
|
||||
if(($newTime-$oldTime)>=3 && $flag == 1){
|
||||
$adb->pquery("delete from vtiger_asteriskincomingcalls where to_number = ?", array($asterisk_extension));
|
||||
}else{
|
||||
if($flag==0){
|
||||
$flag=1;
|
||||
|
||||
// Trying to get the Related CRM ID for the Event (if already desired by popup click)
|
||||
$relcrmid = false;
|
||||
if(!empty($refuid)) {
|
||||
$refuidres = $adb->pquery('SELECT relcrmid FROM vtiger_asteriskincomingevents WHERE uid=?',array($refuid));
|
||||
if($adb->num_rows($refuidres)) $relcrmid = $adb->query_result($refuidres, 0, 'relcrmid');
|
||||
}
|
||||
$adb->pquery("update vtiger_asteriskincomingcalls set flag = ? where to_number = ?", array($flag, $asterisk_extension));
|
||||
$activityid = asterisk_addToActivityHistory($callerName, $callerNumber, $callerType, $adb, $current_user->id, $relcrmid, $firstCallerInfo);
|
||||
|
||||
}
|
||||
//prepare the div for incoming calls
|
||||
$status = " <table border='0' cellpadding='5' cellspacing='0'>
|
||||
<tr>
|
||||
<td style='padding:10px;' colspan='2'><b>".$app_strings['LBL_INCOMING_CALL']."</b></td>
|
||||
</tr>
|
||||
</table>
|
||||
<table border='0' cellpadding='0' cellspacing='0' class='hdrNameBg'>
|
||||
<tr><td style='padding:10px;' colspan='2'><b>".$app_strings['LBL_CALLER_INFORMATION']."</b>
|
||||
<br><b>".$app_strings['LBL_CALLER_NUMBER']."</b> $callerNumber
|
||||
<br><b>".$app_strings['LBL_CALLER_NAME']."</b> $callerName
|
||||
</td></tr>
|
||||
<tr><td style='padding:10px;' colspan='2'><b>".$app_strings['LBL_INFORMATION_VTIGER']."</b>
|
||||
<br> $callerLinks
|
||||
</td></tr>
|
||||
</table>";
|
||||
}
|
||||
}else{
|
||||
$status = "failure";
|
||||
}
|
||||
return $status;
|
||||
}
|
||||
|
||||
//functions for asterisk integration start
|
||||
/**
|
||||
* this function returns the caller name based on the phone number that is passed to it
|
||||
* @param $from - the number which is calling
|
||||
* returns caller information in name(type) format :: for e.g. Mary Smith (Contact)
|
||||
* if no information is present in database, it returns :: Unknown Caller (Unknown)
|
||||
*/
|
||||
function getTraceIncomingCallerInfo($from) {
|
||||
global $adb;
|
||||
// Grab all possible caller informations (lookup for number as well stripped number)
|
||||
$callerInfos = getCallerInfo($from);
|
||||
$callerLinks = '';
|
||||
|
||||
if($callerInfos !== false){
|
||||
$callerName = decode_html($callerInfos['name']);
|
||||
$module = $callerInfos['module'];
|
||||
$callerModule = " [$module]";
|
||||
$callerID = $callerInfos['id'];
|
||||
$callerLinks = $callerLinks."<a href='index.php?module=$module&action=DetailView&record=$callerID'>$callerName</a>$callerModule<br>";
|
||||
}else{
|
||||
$callerLinks = $callerLinks."<br>
|
||||
<a target='_blank' href='index.php?module=Leads&action=EditView&extra_action=addToCallHistory&phone=$from'>".getTranslatedString('LBL_CREATE_LEAD')."</a><br>
|
||||
<a target='_blank' href='index.php?module=Contacts&action=EditView&extra_action=addToCallHistory&phone=$from'>".getTranslatedString('LBL_CREATE_CONTACT')."</a><br>
|
||||
<a target='_blank' href='index.php?module=Accounts&action=EditView&extra_action=addToCallHistory&phone=$from'>".getTranslatedString('LBL_CREATE_ACCOUNT')."</a>";
|
||||
}
|
||||
return array(
|
||||
'callerInfos' => $callerInfos,
|
||||
'callerLinks' => $callerLinks
|
||||
);
|
||||
}
|
||||
|
||||
?>
|
||||
@@ -0,0 +1,11 @@
|
||||
<?php
|
||||
/*+*******************************************************************************
|
||||
* The contents of this file are subject to the vtiger CRM Public License Version 1.0
|
||||
* ("License"); You may not use this file except in compliance with the License
|
||||
* The Original Code is: vtiger CRM Open Source
|
||||
* The Initial Developer of the Original Code is vtiger.
|
||||
* Portions created by vtiger are Copyright (C) vtiger.
|
||||
* All Rights Reserved.
|
||||
*********************************************************************************/
|
||||
require_once 'modules/Home/UnifiedSearch.php';
|
||||
?>
|
||||
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
/*********************************************************************************
|
||||
** The contents of this file are subject to the vtiger CRM Public License Version 1.0
|
||||
* ("License"); You may not use this file except in compliance with the License
|
||||
* The Original Code is: vtiger CRM Open Source
|
||||
* The Initial Developer of the Original Code is vtiger.
|
||||
* Portions created by vtiger are Copyright (C) vtiger.
|
||||
* All Rights Reserved.
|
||||
*
|
||||
********************************************************************************/
|
||||
savePBXDetails();
|
||||
|
||||
function savePBXDetails(){
|
||||
global $adb;
|
||||
$semodule = $_REQUEST['semodule'];
|
||||
|
||||
if($semodule == 'asterisk'){
|
||||
$server = $_REQUEST['qserver'];
|
||||
$port = $_REQUEST['qport'];
|
||||
$username = $_REQUEST['qusername'];
|
||||
$password = $_REQUEST['qpassword'];
|
||||
$version = $_REQUEST['version'];
|
||||
|
||||
$sql = "delete from vtiger_asterisk";
|
||||
$adb->query($sql); //delete older records (if any)
|
||||
|
||||
$sql = "insert into vtiger_asterisk (server, port, username, password, version) values (?,?,?,?,?)";
|
||||
$params = array($server,$port, $username, $password, $version);
|
||||
$adb->pquery($sql, $params);
|
||||
}
|
||||
}
|
||||
?>
|
||||
@@ -0,0 +1,14 @@
|
||||
<?php
|
||||
/*********************************************************************************
|
||||
** The contents of this file are subject to the vtiger CRM Public License Version 1.0
|
||||
* ("License"); You may not use this file except in compliance with the License
|
||||
* The Original Code is: vtiger CRM Open Source
|
||||
* The Initial Developer of the Original Code is vtiger.
|
||||
* Portions created by vtiger are Copyright (C) vtiger.
|
||||
* All Rights Reserved.
|
||||
********************************************************************************/
|
||||
|
||||
global $currentModule;
|
||||
include_once("modules/$currentModule/ListView.php");
|
||||
|
||||
?>
|
||||
@@ -0,0 +1,20 @@
|
||||
<?php
|
||||
/*********************************************************************************
|
||||
** The contents of this file are subject to the vtiger CRM Public License Version 1.0
|
||||
* ("License"); You may not use this file except in compliance with the License
|
||||
* The Original Code is: vtiger CRM Open Source
|
||||
* The Initial Developer of the Original Code is vtiger.
|
||||
* Portions created by vtiger are Copyright (C) vtiger.
|
||||
* All Rights Reserved.
|
||||
********************************************************************************/
|
||||
|
||||
$mod_strings = Array(
|
||||
'Asterisk' => 'Asterisk',
|
||||
'LBL_ASTERISK_INFORMATION' => 'ASTERISK Information',
|
||||
|
||||
'Call From'=>'Call From',
|
||||
'Call To'=>'Call To',
|
||||
'Time Of Call'=>'Time Of Call',
|
||||
);
|
||||
|
||||
?>
|
||||
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright (C) 2006-2010 YUCHENG HU
|
||||
*
|
||||
* ---------------------------------------------
|
||||
* HA WEBSYSTEMS
|
||||
* http://www.hawebs.net
|
||||
* https://www.hawebs.org/forums/computer/
|
||||
*
|
||||
* CONTACT
|
||||
* [email protected] / [email protected]
|
||||
*
|
||||
* ---------------------------------------------
|
||||
* [A] GNU GENERAL PUBLIC LICENSE GNU/LGPL
|
||||
* [B] Apache License, Version 2.0
|
||||
*
|
||||
* ---------------------------------------------
|
||||
* NOTE
|
||||
* 1. 所有的语言配置文件请采用 UTF-8 编码
|
||||
*
|
||||
* ---------------------------------------------
|
||||
*/
|
||||
|
||||
$mod_strings = Array(
|
||||
'Asterisk' => 'Asterisk',
|
||||
'LBL_ASTERISK_INFORMATION' => 'ASTERISK 信息',
|
||||
|
||||
'Call From'=>'来电',
|
||||
'Call To'=>'去电',
|
||||
'Time Of Call'=>'通话时间',
|
||||
);
|
||||
|
||||
?>
|
||||
@@ -0,0 +1,15 @@
|
||||
<?xml version='1.0'?>
|
||||
<schema>
|
||||
<tables>
|
||||
<table>
|
||||
<name>vtiger_pbxmanager</name>
|
||||
<sql><![CDATA[CREATE TABLE `vtiger_pbxmanager` (
|
||||
`pbxmanagerid` int(11) default NULL,
|
||||
`callfrom` varchar(255) default NULL,
|
||||
`callto` varchar(255) default NULL,
|
||||
`timeofcall` varchar(255) default NULL,
|
||||
`status` varchar(255) default NULL
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8]]></sql>
|
||||
</table>
|
||||
</tables>
|
||||
</schema>
|
||||
@@ -0,0 +1,176 @@
|
||||
<?php
|
||||
/*********************************************************************************
|
||||
** The contents of this file are subject to the vtiger CRM Public License Version 1.0
|
||||
* ("License"); You may not use this file except in compliance with the License
|
||||
* The Original Code is: vtiger CRM Open Source
|
||||
* The Initial Developer of the Original Code is vtiger.
|
||||
* Portions created by vtiger are Copyright (C) vtiger.
|
||||
* All Rights Reserved.
|
||||
********************************************************************************/
|
||||
require_once('include/database/PearDatabase.php');
|
||||
require_once('include/logging.php');
|
||||
|
||||
class Asterisk {
|
||||
var $address;
|
||||
var $port;
|
||||
var $userName;
|
||||
var $password;
|
||||
var $sock;
|
||||
var $db;
|
||||
var $log;
|
||||
var $queue;
|
||||
|
||||
/**
|
||||
* this is the constructor of the class, it initializes the parameters of the class
|
||||
* @param resource $sock - a socket type
|
||||
* @param string $server - the asterisk server address
|
||||
* @param integer $port - the port number where to connect to the asterisk server
|
||||
*/
|
||||
function Asterisk ( $sock, $server, $port){
|
||||
$this->sock = $sock;
|
||||
$this->address = $server;
|
||||
$this->port = $port;
|
||||
$this->db = PearDatabase::getInstance();
|
||||
$this->log = LoggerManager::getLogger('asterisk');
|
||||
$this->queue = array();
|
||||
}
|
||||
|
||||
/**
|
||||
* this function sets the username and password for the asterisk object
|
||||
* @param string $userName - asterisk username
|
||||
* @param string $password - password for the user
|
||||
*/
|
||||
function setUserInfo($userName, $password){
|
||||
$this->userName = $userName;
|
||||
$this->password = $password;
|
||||
}
|
||||
|
||||
/**
|
||||
* this function authenticates the user
|
||||
* @return - true on success else false
|
||||
*/
|
||||
function authenticateUser(){
|
||||
$request = "Action: Login\r\n".
|
||||
"Username: ".$this->userName."\r\n".
|
||||
"Secret: ".$this->password.
|
||||
"\r\n\r\n";
|
||||
if( !fwrite($this->sock, $request) ) {
|
||||
echo "in function authenticateUser() Socket error.Cannot send.(function: fwrite)";
|
||||
$this->log->debug("in function authenticateUser() Socket error.Cannot send.(function: fwrite)");
|
||||
exit(0);
|
||||
}
|
||||
sleep(1); //wait for the response to come
|
||||
$response = fread($this->sock, 4096); //read the response
|
||||
|
||||
if(strstr($response,"Response") && (strstr($response,"Error") || strstr($response,"failed"))) {
|
||||
print_r($response);
|
||||
$this->log->debug($response);
|
||||
return false;
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* create a call between from and to
|
||||
* @param string $from - the from number
|
||||
* @param sring $to - the to number
|
||||
* this function prepares the parameter $context and calls the createCall() function
|
||||
*/
|
||||
function transfer($from,$to){
|
||||
$this->log->debug("in function transfer($from, $to)");
|
||||
if(empty($from) || empty($to)) {
|
||||
echo "Not sufficient parameters to create the call";
|
||||
$this->log->debug("Not sufficient parameters to create the call");
|
||||
return false;
|
||||
}
|
||||
|
||||
//the caller would always be a SIP phone in our case
|
||||
if(!strstr($from,"SIP")){
|
||||
$from = "SIP/$from";
|
||||
}
|
||||
if(strpos($to, ":")!==FALSE){
|
||||
$arr = explode(":", $to);
|
||||
if(is_array($arr)){
|
||||
$typeCalled = $arr[0];
|
||||
$to = trim($arr[1]);
|
||||
}
|
||||
}
|
||||
|
||||
switch($typeCalled){
|
||||
case "SIP":
|
||||
$context = "default";
|
||||
break;
|
||||
case "PSTN":
|
||||
$context = "from-inside";//"outbound-dialing";
|
||||
break;
|
||||
default:
|
||||
$context = "default";
|
||||
}
|
||||
$this->createCall($from, $to, $context);
|
||||
}
|
||||
|
||||
/**
|
||||
* creates a call between $from and $to
|
||||
* @param string $from -the number from which to call
|
||||
* @param string $to - the number to which to call
|
||||
* @param string $context - the context of the call (e.g. local-extensions for local calls)
|
||||
*/
|
||||
function createCall($from, $to, $context){
|
||||
$arr = explode("/", $from);
|
||||
$request = "Action: Originate\r\n".
|
||||
"Channel: $from\r\n".
|
||||
"Exten: ".preg_replace('~[^0-9]~', "", $to)."\r\n".
|
||||
"Context: $context\r\n".
|
||||
"Priority: 1\r\n".
|
||||
"Callerid: $arr[1]\r\n".
|
||||
"Async: yes\r\n\r\n";
|
||||
if( !fwrite($this->sock, $request) ) {
|
||||
echo "in function createcall() Socket error.Cannot send.(function: fwrite)";
|
||||
$this->log->debug("in function authenticateUser() Socket error.Cannot send.(function: fwrite)");
|
||||
exit(0);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* this is the destructor for the class :: it closes the opened socket
|
||||
*/
|
||||
function __destruct(){
|
||||
fclose($this->sock);
|
||||
}
|
||||
|
||||
/**
|
||||
* this function reads the socket for asterisk events and
|
||||
* creates a queue with the response arrays
|
||||
*
|
||||
* @param boolean $echoFlag - if set no echos are performed (added since some ajax requests might use the function)
|
||||
* @return the event array present in the queue
|
||||
* if no array is present it returns a null
|
||||
*/
|
||||
function getAsteriskResponse($echoFlag = true){
|
||||
if(sizeof($this->queue)==0){
|
||||
$this->strData.=fread($this->sock, 4096);
|
||||
|
||||
if($echoFlag){
|
||||
echo $this->strData;
|
||||
}
|
||||
|
||||
$this->log->debug($this->strData);
|
||||
$arr = explode("\r\n\r\n", $this->strData);
|
||||
|
||||
for($i=0;$i<sizeof($arr)-1;$i++){
|
||||
$resp = $arr[$i];
|
||||
$lines = explode("\r\n", $resp);
|
||||
$obj = array();
|
||||
foreach($lines as $line){
|
||||
list($key, $value) = explode(":", $line);
|
||||
$obj[$key] = trim($value);
|
||||
}
|
||||
$this->queue[] = $obj;
|
||||
}
|
||||
$this->strData = $arr[$i];
|
||||
}
|
||||
return array_shift($this->queue);
|
||||
}
|
||||
}
|
||||
?>
|
||||
Reference in New Issue
Block a user