32if (!defined(
'NOREQUIRESOC')) {
33 define(
'NOREQUIRESOC',
'1');
35if (!defined(
'NOREQUIRETRAN')) {
36 define(
'NOREQUIRETRAN',
'1');
38if (!defined(
'NOTOKENRENEWAL')) {
39 define(
'NOTOKENRENEWAL',
'1');
41if (!defined(
'NOREQUIREMENU')) {
42 define(
'NOREQUIREMENU',
'1');
44if (!defined(
'NOREQUIREHTML')) {
45 define(
'NOREQUIREHTML',
'1');
47if (!defined(
'NOREQUIREAJAX')) {
48 define(
'NOREQUIREAJAX',
'1');
73function llxHeader($head =
'', $title =
'', $help_url =
'', $target =
'', $disablejs = 0, $disablehead = 0, $arrayofjs =
'', $arrayofcss =
'', $morequerystring =
'', $morecssonbody =
'', $replacemainareaby =
'', $disablenofollow = 0, $disablenoindex = 0)
77 print
'<title>Asterisk redirection from Dolibarr...</title>'.
"\n";
91function llxFooter($comment =
'', $zone =
'private', $disabledoutputofmessages = 0)
93 print
"\n".
'</html>'.
"\n";
96require_once
'../main.inc.php';
97require_once DOL_DOCUMENT_ROOT.
'/core/lib/functions.lib.php';
98require_once DOL_DOCUMENT_ROOT.
'/core/lib/functions2.lib.php';
109if (!isModEnabled(
'clicktodial')) {
116 $conf->global->ASTERISK_HOST =
"127.0.0.1";
119 $conf->global->ASTERISK_TYPE =
"SIP/";
122 $conf->global->ASTERISK_INDICATIF =
"0";
125 $conf->global->ASTERISK_PORT = 5038;
128 $conf->global->ASTERISK_INDICATIF =
'';
131 $conf->global->ASTERISK_CONTEXT =
"from-internal";
134 $conf->global->ASTERISK_WAIT_TIME =
"30";
137 $conf->global->ASTERISK_PRIORITY =
"1";
140 $conf->global->ASTERISK_MAX_RETRY =
"2";
144$login =
GETPOST(
'login',
'alphanohtml');
145$password =
GETPOST(
'password',
'password');
146$caller =
GETPOST(
'caller',
'alphanohtml');
147$called =
GETPOST(
'called',
'alphanohtml');
150$login = preg_replace(
'/[\n\r]/',
'', $login);
151$password = preg_replace(
'/[\n\r]/',
'', $password);
152$caller = preg_replace(
'/[\n\r]/',
'', $caller);
153$called = preg_replace(
'/[\n\r]/',
'', $called);
185llxHeader(
'',
'',
'',
'', 0, 0,
'',
'',
'',
'mod-asterisk page-wrapper');
187$sql =
"SELECT s.nom as name FROM ".MAIN_DB_PREFIX.
"societe as s";
188$sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"socpeople as sp ON sp.fk_soc = s.rowid";
189$sql .=
" WHERE s.entity IN (".getEntity(
'societe').
")";
190$sql .=
" AND (s.phone='".$db->escape($called).
"'";
191$sql .=
" OR sp.phone='".$db->escape($called).
"'";
192$sql .=
" OR sp.phone_perso='".$db->escape($called).
"'";
193$sql .=
" OR sp.phone_mobile='".$db->escape($called).
"')";
194$sql .= $db->plimit(1);
196dol_syslog(
'click to dial search information with phone '.$called, LOG_DEBUG);
197$resql = $db->query($sql);
199 $obj = $db->fetch_object($resql);
203 $found =
'Not found';
211$number = strtolower($called);
212$pos = strpos($number,
"local");
213if (!empty($number)) {
214 if ($pos ===
false) {
217 $strCallerId =
"Dolibarr caller $found <".strtolower($number).
">";
218 $oSocket = @fsockopen($strHost, (
int) $port, $errno, $errstr, 10);
221 $txt =
"Failed to execute fsockopen($strHost, $port, \$errno, \$errstr, 10)<br>\n";
224 $txt = $errstr.
" (".$errno.
")<br>\n";
227 print
'</body>'.
"\n";
229 $txt =
"Call Asterisk dialer for caller: ".$caller.
", called: ".$called.
" clicktodiallogin: ".$login;
231 print
'<body onload="history.go(-1);">'.
"\n";
232 print
'<!-- '.$txt.
' -->';
233 fwrite($oSocket,
"Action: login\r\n");
234 fwrite($oSocket,
"Events: off\r\n");
235 fwrite($oSocket,
"Username: $login\r\n");
236 fwrite($oSocket,
"Secret: $password\r\n\r\n");
237 fwrite($oSocket,
"Action: originate\r\n");
238 fwrite($oSocket,
"Channel: ".$channel.$caller.
"\r\n");
239 fwrite($oSocket,
"WaitTime: $strWaitTime\r\n");
240 fwrite($oSocket,
"CallerId: $strCallerId\r\n");
241 fwrite($oSocket,
"Exten: ".$prefix.$number.
"\r\n");
242 fwrite($oSocket,
"Context: $strContext\r\n");
243 fwrite($oSocket,
"Priority: $strPriority\r\n\r\n");
244 fwrite($oSocket,
"Action: Logoff\r\n\r\n");
247 print
'</body>'.
"\n";
251 print
'Bad parameters in URL. Must be '.dol_escape_htmltag($_SERVER[
'PHP_SELF']).
'?caller=99999&called=99999&login=xxxxx&password=xxxxx';
llxFooter($comment='', $zone='private', $disabledoutputofmessages=0)
Empty footer.
if(!defined('NOREQUIRESOC')) if(!defined( 'NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined( 'NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined( 'NOREQUIREAJAX')) llxHeader($head='', $title='', $help_url='', $target='', $disablejs=0, $disablehead=0, $arrayofjs='', $arrayofcss='', $morequerystring='', $morecssonbody='', $replacemainareaby='', $disablenofollow=0, $disablenoindex=0)
Empty header.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
dol_print_error($db=null, $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
global $conf
The following vars must be defined: $type2label $form $conf, $lang, The following vars may also be de...
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.