72 print
"\n".
'</html>'.
"\n";
75require_once
'../main.inc.php';
76require_once DOL_DOCUMENT_ROOT.
'/core/lib/functions.lib.php';
77require_once DOL_DOCUMENT_ROOT.
'/core/lib/functions2.lib.php';
81if (empty($conf->clicktodial->enabled)) {
88if (!isset($conf->global->ASTERISK_HOST)) {
89 $conf->global->ASTERISK_HOST =
"127.0.0.1";
91if (!isset($conf->global->ASTERISK_TYPE)) {
92 $conf->global->ASTERISK_TYPE =
"SIP/";
94if (!isset($conf->global->ASTERISK_INDICATIF)) {
95 $conf->global->ASTERISK_INDICATIF =
"0";
97if (!isset($conf->global->ASTERISK_PORT)) {
98 $conf->global->ASTERISK_PORT = 5038;
100if ($conf->global->ASTERISK_INDICATIF ==
'NONE') {
101 $conf->global->ASTERISK_INDICATIF =
'';
103if (!isset($conf->global->ASTERISK_CONTEXT)) {
104 $conf->global->ASTERISK_CONTEXT =
"from-internal";
106if (!isset($conf->global->ASTERISK_WAIT_TIME)) {
107 $conf->global->ASTERISK_WAIT_TIME =
"30";
109if (!isset($conf->global->ASTERISK_PRIORITY)) {
110 $conf->global->ASTERISK_PRIORITY =
"1";
112if (!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;
126$channel = $conf->global->ASTERISK_TYPE;
128$prefix = $conf->global->ASTERISK_INDICATIF;
130$port = $conf->global->ASTERISK_PORT;
132$strContext = $conf->global->ASTERISK_CONTEXT;
134$strWaitTime = $conf->global->ASTERISK_WAIT_TIME;
136$strPriority = $conf->global->ASTERISK_PRIORITY;
138$strMaxRetry = $conf->global->ASTERISK_MAX_RETRY;
147$sql =
"SELECT s.nom as name FROM ".MAIN_DB_PREFIX.
"societe as s";
148$sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"socpeople as sp ON sp.fk_soc = s.rowid";
149$sql .=
" WHERE s.entity IN (".getEntity(
'societe').
")";
150$sql .=
" AND (s.phone='".$db->escape($called).
"'";
151$sql .=
" OR sp.phone='".$db->escape($called).
"'";
152$sql .=
" OR sp.phone_perso='".$db->escape($called).
"'";
153$sql .=
" OR sp.phone_mobile='".$db->escape($called).
"')";
154$sql .= $db->plimit(1);
156dol_syslog(
'click to dial search information with phone '.$called, LOG_DEBUG);
157$resql = $db->query($sql);
159 $obj = $db->fetch_object($resql);
163 $found =
'Not found';
171$number = strtolower($called);
172$pos = strpos($number,
"local");
173if (!empty($number)) {
174 if ($pos ===
false) {
177 $strCallerId =
"Dolibarr caller $found <".strtolower($number).
">";
178 $oSocket = @fsockopen($strHost, $port, $errno, $errstr, 10);
181 $txt =
"Failed to execute fsockopen($strHost, $port, \$errno, \$errstr, 10)<br>\n";
184 $txt = $errstr.
" (".$errno.
")<br>\n";
187 print
'</body>'.
"\n";
189 $txt =
"Call Asterisk dialer for caller: ".$caller.
", called: ".$called.
" clicktodiallogin: ".$login;
191 print
'<body onload="history.go(-1);">'.
"\n";
192 print
'<!-- '.$txt.
' -->';
193 fputs($oSocket,
"Action: login\r\n");
194 fputs($oSocket,
"Events: off\r\n");
195 fputs($oSocket,
"Username: $login\r\n");
196 fputs($oSocket,
"Secret: $password\r\n\r\n");
197 fputs($oSocket,
"Action: originate\r\n");
198 fputs($oSocket,
"Channel: ".$channel.$caller.
"\r\n");
199 fputs($oSocket,
"WaitTime: $strWaitTime\r\n");
200 fputs($oSocket,
"CallerId: $strCallerId\r\n");
201 fputs($oSocket,
"Exten: ".$prefix.$number.
"\r\n");
202 fputs($oSocket,
"Context: $strContext\r\n");
203 fputs($oSocket,
"Priority: $strPriority\r\n\r\n");
204 fputs($oSocket,
"Action: Logoff\r\n\r\n");
207 print
'</body>'.
"\n";
dol_print_error($db='', $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.