31 if (!defined(
'NOREQUIRESOC')) {
32 define(
'NOREQUIRESOC',
'1');
34 if (!defined(
'NOREQUIRETRAN')) {
35 define(
'NOREQUIRETRAN',
'1');
37 if (!defined(
'NOCSRFCHECK')) {
38 define(
'NOCSRFCHECK',
'1');
40 if (!defined(
'NOTOKENRENEWAL')) {
41 define(
'NOTOKENRENEWAL',
'1');
43 if (!defined(
'NOREQUIREMENU')) {
44 define(
'NOREQUIREMENU',
'1');
46 if (!defined(
'NOREQUIREHTML')) {
47 define(
'NOREQUIREHTML',
'1');
49 if (!defined(
'NOREQUIREAJAX')) {
50 define(
'NOREQUIREAJAX',
'1');
63 print
'<title>Asterisk redirection from Dolibarr...</title>'.
"\n";
75 print
"\n".
'</html>'.
"\n";
79 require_once
'../main.inc.php';
80 require_once DOL_DOCUMENT_ROOT.
'/core/lib/functions.lib.php';
81 require_once DOL_DOCUMENT_ROOT.
'/core/lib/functions2.lib.php';
85 if (empty($conf->clicktodial->enabled)) {
92 if (!isset($conf->global->ASTERISK_HOST)) {
93 $conf->global->ASTERISK_HOST =
"127.0.0.1";
95 if (!isset($conf->global->ASTERISK_TYPE)) {
96 $conf->global->ASTERISK_TYPE =
"SIP/";
98 if (!isset($conf->global->ASTERISK_INDICATIF)) {
99 $conf->global->ASTERISK_INDICATIF =
"0";
101 if (!isset($conf->global->ASTERISK_PORT)) {
102 $conf->global->ASTERISK_PORT = 5038;
104 if ($conf->global->ASTERISK_INDICATIF ==
'NONE') {
105 $conf->global->ASTERISK_INDICATIF =
'';
107 if (!isset($conf->global->ASTERISK_CONTEXT)) {
108 $conf->global->ASTERISK_CONTEXT =
"from-internal";
110 if (!isset($conf->global->ASTERISK_WAIT_TIME)) {
111 $conf->global->ASTERISK_WAIT_TIME =
"30";
113 if (!isset($conf->global->ASTERISK_PRIORITY)) {
114 $conf->global->ASTERISK_PRIORITY =
"1";
116 if (!isset($conf->global->ASTERISK_MAX_RETRY)) {
117 $conf->global->ASTERISK_MAX_RETRY =
"2";
121 $login =
GETPOST(
'login',
'alphanohtml');
122 $password =
GETPOST(
'password',
'none');
123 $caller =
GETPOST(
'caller',
'alphanohtml');
124 $called =
GETPOST(
'called',
'alphanohtml');
127 $strHost = $conf->global->ASTERISK_HOST;
130 $channel = $conf->global->ASTERISK_TYPE;
132 $prefix = $conf->global->ASTERISK_INDICATIF;
134 $port = $conf->global->ASTERISK_PORT;
136 $strContext = $conf->global->ASTERISK_CONTEXT;
138 $strWaitTime = $conf->global->ASTERISK_WAIT_TIME;
140 $strPriority = $conf->global->ASTERISK_PRIORITY;
142 $strMaxRetry = $conf->global->ASTERISK_MAX_RETRY;
151 $sql =
"SELECT s.nom as name FROM ".MAIN_DB_PREFIX.
"societe as s";
152 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"socpeople as sp ON sp.fk_soc = s.rowid";
153 $sql .=
" WHERE s.entity IN (".getEntity(
'societe').
")";
154 $sql .=
" AND (s.phone='".$db->escape($called).
"'";
155 $sql .=
" OR sp.phone='".$db->escape($called).
"'";
156 $sql .=
" OR sp.phone_perso='".$db->escape($called).
"'";
157 $sql .=
" OR sp.phone_mobile='".$db->escape($called).
"')";
158 $sql .= $db->plimit(1);
160 dol_syslog(
'click to dial search information with phone '.$called, LOG_DEBUG);
161 $resql = $db->query($sql);
163 $obj = $db->fetch_object(
$resql);
167 $found =
'Not found';
175 $number = strtolower($called);
176 $pos = strpos($number,
"local");
177 if (!empty($number)) {
178 if ($pos ===
false) {
181 $strCallerId =
"Dolibarr caller $found <".strtolower($number).
">";
182 $oSocket = @fsockopen($strHost, $port, $errno, $errstr, 10);
185 $txt =
"Failed to execute fsockopen($strHost, $port, \$errno, \$errstr, 10)<br>\n";
188 $txt = $errstr.
" (".$errno.
")<br>\n";
191 print
'</body>'.
"\n";
193 $txt =
"Call Asterisk dialer for caller: ".$caller.
", called: ".$called.
" clicktodiallogin: ".$login;
195 print
'<body onload="javascript:history.go(-1);">'.
"\n";
196 print
'<!-- '.$txt.
' -->';
197 fputs($oSocket,
"Action: login\r\n");
198 fputs($oSocket,
"Events: off\r\n");
199 fputs($oSocket,
"Username: $login\r\n");
200 fputs($oSocket,
"Secret: $password\r\n\r\n");
201 fputs($oSocket,
"Action: originate\r\n");
202 fputs($oSocket,
"Channel: ".$channel.$caller.
"\r\n");
203 fputs($oSocket,
"WaitTime: $strWaitTime\r\n");
204 fputs($oSocket,
"CallerId: $strCallerId\r\n");
205 fputs($oSocket,
"Exten: ".$prefix.$number.
"\r\n");
206 fputs($oSocket,
"Context: $strContext\r\n");
207 fputs($oSocket,
"Priority: $strPriority\r\n\r\n");
208 fputs($oSocket,
"Action: Logoff\r\n\r\n");
211 print
'</body>'.
"\n";
215 print
'Bad parameters in URL. Must be '.dol_escape_htmltag($_SERVER[
'PHP_SELF']).
'?caller=99999&called=99999&login=xxxxx&password=xxxxx';