31 if (!defined(
'NOREQUIRESOC')) {
32 define(
'NOREQUIRESOC',
'1');
34 if (!defined(
'NOREQUIRETRAN')) {
35 define(
'NOREQUIRETRAN',
'1');
37 if (!defined(
'NOTOKENRENEWAL')) {
38 define(
'NOTOKENRENEWAL',
'1');
40 if (!defined(
'NOREQUIREMENU')) {
41 define(
'NOREQUIREMENU',
'1');
43 if (!defined(
'NOREQUIREHTML')) {
44 define(
'NOREQUIREHTML',
'1');
46 if (!defined(
'NOREQUIREAJAX')) {
47 define(
'NOREQUIREAJAX',
'1');
60 print
'<title>Asterisk redirection from Dolibarr...</title>'.
"\n";
72 print
"\n".
'</html>'.
"\n";
75 require_once
'../main.inc.php';
76 require_once DOL_DOCUMENT_ROOT.
'/core/lib/functions.lib.php';
77 require_once DOL_DOCUMENT_ROOT.
'/core/lib/functions2.lib.php';
81 if (empty($conf->clicktodial->enabled)) {
88 if (!isset($conf->global->ASTERISK_HOST)) {
89 $conf->global->ASTERISK_HOST =
"127.0.0.1";
91 if (!isset($conf->global->ASTERISK_TYPE)) {
92 $conf->global->ASTERISK_TYPE =
"SIP/";
94 if (!isset($conf->global->ASTERISK_INDICATIF)) {
95 $conf->global->ASTERISK_INDICATIF =
"0";
97 if (!isset($conf->global->ASTERISK_PORT)) {
98 $conf->global->ASTERISK_PORT = 5038;
100 if ($conf->global->ASTERISK_INDICATIF ==
'NONE') {
101 $conf->global->ASTERISK_INDICATIF =
'';
103 if (!isset($conf->global->ASTERISK_CONTEXT)) {
104 $conf->global->ASTERISK_CONTEXT =
"from-internal";
106 if (!isset($conf->global->ASTERISK_WAIT_TIME)) {
107 $conf->global->ASTERISK_WAIT_TIME =
"30";
109 if (!isset($conf->global->ASTERISK_PRIORITY)) {
110 $conf->global->ASTERISK_PRIORITY =
"1";
112 if (!isset($conf->global->ASTERISK_MAX_RETRY)) {
113 $conf->global->ASTERISK_MAX_RETRY =
"2";
117 $login =
GETPOST(
'login',
'alphanohtml');
118 $password =
GETPOST(
'password',
'none');
119 $caller =
GETPOST(
'caller',
'alphanohtml');
120 $called =
GETPOST(
'called',
'alphanohtml');
123 $strHost = $conf->global->ASTERISK_HOST;
127 $channel = $conf->global->ASTERISK_TYPE;
130 $prefix = $conf->global->ASTERISK_INDICATIF;
133 $port = $conf->global->ASTERISK_PORT;
136 $strContext = $conf->global->ASTERISK_CONTEXT;
139 $strWaitTime = $conf->global->ASTERISK_WAIT_TIME;
142 $strPriority = $conf->global->ASTERISK_PRIORITY;
145 $strMaxRetry = $conf->global->ASTERISK_MAX_RETRY;
154 $sql =
"SELECT s.nom as name FROM ".MAIN_DB_PREFIX.
"societe as s";
155 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"socpeople as sp ON sp.fk_soc = s.rowid";
156 $sql .=
" WHERE s.entity IN (".getEntity(
'societe').
")";
157 $sql .=
" AND (s.phone='".$db->escape($called).
"'";
158 $sql .=
" OR sp.phone='".$db->escape($called).
"'";
159 $sql .=
" OR sp.phone_perso='".$db->escape($called).
"'";
160 $sql .=
" OR sp.phone_mobile='".$db->escape($called).
"')";
161 $sql .= $db->plimit(1);
163 dol_syslog(
'click to dial search information with phone '.$called, LOG_DEBUG);
164 $resql = $db->query(
$sql);
166 $obj = $db->fetch_object($resql);
170 $found =
'Not found';
178 $number = strtolower($called);
179 $pos = strpos($number,
"local");
180 if (!empty($number)) {
181 if ($pos ===
false) {
184 $strCallerId =
"Dolibarr caller $found <".strtolower($number).
">";
185 $oSocket = @fsockopen($strHost, $port, $errno, $errstr, 10);
188 $txt =
"Failed to execute fsockopen($strHost, $port, \$errno, \$errstr, 10)<br>\n";
191 $txt = $errstr.
" (".$errno.
")<br>\n";
194 print
'</body>'.
"\n";
196 $txt =
"Call Asterisk dialer for caller: ".$caller.
", called: ".$called.
" clicktodiallogin: ".$login;
198 print
'<body onload="history.go(-1);">'.
"\n";
199 print
'<!-- '.$txt.
' -->';
200 fputs($oSocket,
"Action: login\r\n");
201 fputs($oSocket,
"Events: off\r\n");
202 fputs($oSocket,
"Username: $login\r\n");
203 fputs($oSocket,
"Secret: $password\r\n\r\n");
204 fputs($oSocket,
"Action: originate\r\n");
205 fputs($oSocket,
"Channel: ".$channel.$caller.
"\r\n");
206 fputs($oSocket,
"WaitTime: $strWaitTime\r\n");
207 fputs($oSocket,
"CallerId: $strCallerId\r\n");
208 fputs($oSocket,
"Exten: ".$prefix.$number.
"\r\n");
209 fputs($oSocket,
"Context: $strContext\r\n");
210 fputs($oSocket,
"Priority: $strPriority\r\n\r\n");
211 fputs($oSocket,
"Action: Logoff\r\n\r\n");
214 print
'</body>'.
"\n";
218 print
'Bad parameters in URL. Must be '.dol_escape_htmltag($_SERVER[
'PHP_SELF']).
'?caller=99999&called=99999&login=xxxxx&password=xxxxx';