dolibarr  13.0.2
wrapper.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (C) 2009-2010 Laurent Destailleur <eldy@users.sourceforge.net>
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation; either version 3 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program. If not, see <https://www.gnu.org/licenses/>.
16  */
17 
31 if (!defined('NOREQUIRESOC')) define('NOREQUIRESOC', '1');
32 if (!defined('NOREQUIRETRAN')) define('NOREQUIRETRAN', '1');
33 if (!defined('NOCSRFCHECK')) define('NOCSRFCHECK', '1');
34 if (!defined('NOTOKENRENEWAL')) define('NOTOKENRENEWAL', '1');
35 if (!defined('NOREQUIREMENU')) define('NOREQUIREMENU', '1');
36 if (!defined('NOREQUIREHTML')) define('NOREQUIREHTML', '1');
37 if (!defined('NOREQUIREAJAX')) define('NOREQUIREAJAX', '1');
38 
45 function llxHeader()
46 {
47  print '<html>'."\n";
48  print '<head>'."\n";
49  print '<title>Asterisk redirection from Dolibarr...</title>'."\n";
50  print '</head>'."\n";
51 }
52 
59 function llxFooter()
60 {
61  print "\n".'</html>'."\n";
62 }
63 
64 require_once '../main.inc.php';
65 require_once DOL_DOCUMENT_ROOT.'/core/lib/functions.lib.php';
66 require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
67 
68 
69 // Security check
70 if (empty($conf->clicktodial->enabled))
71 {
73  exit;
74 }
75 
76 
77 // Define Asterisk setup
78 if (!isset($conf->global->ASTERISK_HOST)) $conf->global->ASTERISK_HOST = "127.0.0.1";
79 if (!isset($conf->global->ASTERISK_TYPE)) $conf->global->ASTERISK_TYPE = "SIP/";
80 if (!isset($conf->global->ASTERISK_INDICATIF)) $conf->global->ASTERISK_INDICATIF = "0";
81 if (!isset($conf->global->ASTERISK_PORT)) $conf->global->ASTERISK_PORT = 5038;
82 if ($conf->global->ASTERISK_INDICATIF == 'NONE') $conf->global->ASTERISK_INDICATIF = '';
83 if (!isset($conf->global->ASTERISK_CONTEXT)) $conf->global->ASTERISK_CONTEXT = "from-internal";
84 if (!isset($conf->global->ASTERISK_WAIT_TIME)) $conf->global->ASTERISK_WAIT_TIME = "30";
85 if (!isset($conf->global->ASTERISK_PRIORITY)) $conf->global->ASTERISK_PRIORITY = "1";
86 if (!isset($conf->global->ASTERISK_MAX_RETRY)) $conf->global->ASTERISK_MAX_RETRY = "2";
87 
88 
89 $login = GETPOST('login');
90 $password = GETPOST('password');
91 $caller = GETPOST('caller');
92 $called = GETPOST('called');
93 
94 // IP address of Asterisk server
95 $strHost = $conf->global->ASTERISK_HOST;
96 // SpĂ©cifiez le type d'extension par laquelle vous poste est connecte.
97 // ex: SIP/, IAX2/, ZAP/, etc
98 $channel = $conf->global->ASTERISK_TYPE;
99 // Indicatif de la ligne sortante
100 $prefix = $conf->global->ASTERISK_INDICATIF;
101 // Port
102 $port = $conf->global->ASTERISK_PORT;
103 // Context ( generalement from-internal )
104 $strContext = $conf->global->ASTERISK_CONTEXT;
105 // Delai d'attente avant de raccrocher
106 $strWaitTime = $conf->global->ASTERISK_WAIT_TIME;
107 // Priority
108 $strPriority = $conf->global->ASTERISK_PRIORITY;
109 // Nomber of try
110 $strMaxRetry = $conf->global->ASTERISK_MAX_RETRY;
111 
112 
113 /*
114  * View
115  */
116 
117 llxHeader();
118 
119 $sql = "SELECT s.nom as name FROM ".MAIN_DB_PREFIX."societe as s";
120 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."socpeople as sp ON sp.fk_soc = s.rowid";
121 $sql .= " WHERE s.entity IN (".getEntity('societe').")";
122 $sql .= " AND (s.phone='".$db->escape($called)."'";
123 $sql .= " OR sp.phone='".$db->escape($called)."'";
124 $sql .= " OR sp.phone_perso='".$db->escape($called)."'";
125 $sql .= " OR sp.phone_mobile='".$db->escape($called)."')";
126 $sql .= $db->plimit(1);
127 
128 dol_syslog('click to dial search information with phone '.$called, LOG_DEBUG);
129 $resql = $db->query($sql);
130 if ($resql)
131 {
132  $obj = $db->fetch_object($resql);
133  if ($obj)
134  {
135  $found = $obj->name;
136  } else {
137  $found = $notfound;
138  }
139  $db->free($resql);
140 } else {
141  dol_print_error($db, 'Error');
142  $found = 'Error';
143 }
144 
145 $number = strtolower($called);
146 $pos = strpos($number, "local");
147 if (!empty($number))
148 {
149  if ($pos === false)
150  {
151  $errno = 0;
152  $errstr = 0;
153  $strCallerId = "Dolibarr call $found <".strtolower($number).">";
154  $oSocket = @fsockopen($strHost, $port, $errno, $errstr, 10);
155  if (!$oSocket)
156  {
157  print '<body>'."\n";
158  $txt = "Failed to execute fsockopen($strHost, $port, \$errno, \$errstr, 10)<br>\n";
159  print $txt;
160  dol_syslog($txt, LOG_ERR);
161  $txt = $errstr." (".$errno.")<br>\n";
162  print $txt;
163  dol_syslog($txt, LOG_ERR);
164  print '</body>'."\n";
165  } else {
166  $txt = "Call Asterisk dialer for caller: ".$caller.", called: ".$called." clicktodiallogin: ".$login;
167  dol_syslog($txt);
168  print '<body onload="javascript:history.go(-1);">'."\n";
169  print '<!-- '.$txt.' -->';
170  fputs($oSocket, "Action: login\r\n");
171  fputs($oSocket, "Events: off\r\n");
172  fputs($oSocket, "Username: $login\r\n");
173  fputs($oSocket, "Secret: $password\r\n\r\n");
174  fputs($oSocket, "Action: originate\r\n");
175  fputs($oSocket, "Channel: ".$channel.$caller."\r\n");
176  fputs($oSocket, "WaitTime: $strWaitTime\r\n");
177  fputs($oSocket, "CallerId: $strCallerId\r\n");
178  fputs($oSocket, "Exten: ".$prefix.$number."\r\n");
179  fputs($oSocket, "Context: $strContext\r\n");
180  fputs($oSocket, "Priority: $strPriority\r\n\r\n");
181  fputs($oSocket, "Action: Logoff\r\n\r\n");
182  sleep(2);
183  fclose($oSocket);
184  print '</body>'."\n";
185  }
186  }
187 } else {
188  print 'Bad parameters in URL. Must be '.$_SERVER['PHP_SELF'].'?caller=99999&called=99999&login=xxxxx&password=xxxxx';
189 }
190 
191 // End of page
192 llxFooter();
193 $db->close();
GETPOST($paramname, $check= 'alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
llxHeader()
Empty header.
Definition: wrapper.php:45
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 Calling this function terminate execution ...
print
Draft customers invoices.
Definition: index.php:89
if(!empty($conf->facture->enabled)&&$user->rights->facture->lire) if((!empty($conf->fournisseur->enabled)&&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)||!empty($conf->supplier_invoice->enabled))&&$user->rights->fournisseur->facture->lire) if(!empty($conf->don->enabled)&&$user->rights->don->lire) if(!empty($conf->tax->enabled)&&$user->rights->tax->charges->lire) if(!empty($conf->facture->enabled)&&!empty($conf->commande->enabled)&&$user->rights->commande->lire &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) if(!empty($conf->facture->enabled)&&$user->rights->facture->lire) if((!empty($conf->fournisseur->enabled)&&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)||!empty($conf->supplier_invoice->enabled))&&$user->rights->fournisseur->facture->lire) $resql
Social contributions to pay.
Definition: index.php:1232
dol_print_error($db= '', $error= '', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
llxFooter()
Empty footer.
Definition: wrapper.php:59