dolibarr  9.0.0
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 <http://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 
44 function llxHeader()
45 {
46  print '<html>'."\n";
47  print '<head>'."\n";
48  print '<title>Asterisk redirection from Dolibarr...</title>'."\n";
49  print '</head>'."\n";
50 }
56 function llxFooter()
57 {
58  print "\n".'</html>'."\n";
59 }
60 
61 require_once '../main.inc.php';
62 require_once DOL_DOCUMENT_ROOT.'/core/lib/functions.lib.php';
63 require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
64 
65 
66 // Security check
67 if (empty($conf->clicktodial->enabled))
68 {
70  exit;
71 }
72 
73 
74 // Define Asterisk setup
75 if (! isset($conf->global->ASTERISK_HOST)) $conf->global->ASTERISK_HOST="127.0.0.1";
76 if (! isset($conf->global->ASTERISK_TYPE)) $conf->global->ASTERISK_TYPE="SIP/";
77 if (! isset($conf->global->ASTERISK_INDICATIF)) $conf->global->ASTERISK_INDICATIF="0";
78 if (! isset($conf->global->ASTERISK_PORT)) $conf->global->ASTERISK_PORT=5038;
79 if ($conf->global->ASTERISK_INDICATIF=='NONE') $conf->global->ASTERISK_INDICATIF='';
80 if (! isset($conf->global->ASTERISK_CONTEXT)) $conf->global->ASTERISK_CONTEXT="from-internal";
81 if (! isset($conf->global->ASTERISK_WAIT_TIME)) $conf->global->ASTERISK_WAIT_TIME="30";
82 if (! isset($conf->global->ASTERISK_PRIORITY)) $conf->global->ASTERISK_PRIORITY="1";
83 if (! isset($conf->global->ASTERISK_MAX_RETRY)) $conf->global->ASTERISK_MAX_RETRY="2";
84 
85 
86 $login = GETPOST('login');
87 $password = GETPOST('password');
88 $caller = GETPOST('caller');
89 $called = GETPOST('called');
90 
91 // IP address of Asterisk server
92 $strHost = $conf->global->ASTERISK_HOST;
93 // SpĂ©cifiez le type d'extension par laquelle vous poste est connecte.
94 // ex: SIP/, IAX2/, ZAP/, etc
95 $channel = $conf->global->ASTERISK_TYPE;
96 // Indicatif de la ligne sortante
97 $prefix = $conf->global->ASTERISK_INDICATIF;
98 // Port
99 $port = $conf->global->ASTERISK_PORT;
100 // Context ( generalement from-internal )
101 $strContext = $conf->global->ASTERISK_CONTEXT;
102 // Delai d'attente avant de raccrocher
103 $strWaitTime = $conf->global->ASTERISK_WAIT_TIME;
104 // Priority
105 $strPriority = $conf->global->ASTERISK_PRIORITY;
106 // Nomber of try
107 $strMaxRetry = $conf->global->ASTERISK_MAX_RETRY;
108 
109 
110 /*
111  * View
112  */
113 
114 llxHeader();
115 
116 $sql = "SELECT s.nom as name FROM ".MAIN_DB_PREFIX."societe as s";
117 $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."socpeople as sp ON sp.fk_soc = s.rowid";
118 $sql.= " WHERE s.entity IN (".getEntity('societe').")";
119 $sql.= " AND (s.phone='".$db->escape($called)."'";
120 $sql.= " OR sp.phone='".$db->escape($called)."'";
121 $sql.= " OR sp.phone_perso='".$db->escape($called)."'";
122 $sql.= " OR sp.phone_mobile='".$db->escape($called)."')";
123 $sql.= $db->plimit(1);
124 
125 dol_syslog('click to dial search information with phone '.$called, LOG_DEBUG);
126 $resql = $db->query($sql);
127 if ($resql)
128 {
129  $obj = $db->fetch_object($resql);
130  if ($obj)
131  {
132  $found = $obj->name;
133  } else {
134  $found = $notfound;
135  }
136  $db->free($resql);
137 }
138 else
139 {
140  dol_print_error($db,'Error');
141  $found = 'Error';
142 }
143 
144 $number=strtolower($called);
145 $pos=strpos($number,"local");
146 if (! empty($number))
147 {
148  if ($pos===false)
149  {
150  $errno=0;
151  $errstr=0;
152  $strCallerId = "Dolibarr call $found <".strtolower($number).">";
153  $oSocket = @fsockopen($strHost, $port, $errno, $errstr, 10);
154  if (!$oSocket)
155  {
156  print '<body>'."\n";
157  $txt="Failed to execute fsockopen($strHost, $port, \$errno, \$errstr, 10)<br>\n";
158  print $txt;
159  dol_syslog($txt,LOG_ERR);
160  $txt=$errstr." (".$errno.")<br>\n";
161  print $txt;
162  dol_syslog($txt,LOG_ERR);
163  print '</body>'."\n";
164  }
165  else
166  {
167  $txt="Call Asterisk dialer for caller: ".$caller.", called: ".$called." clicktodiallogin: ".$login;
168  dol_syslog($txt);
169  print '<body onload="javascript:history.go(-1);">'."\n";
170  print '<!-- '.$txt.' -->';
171  fputs($oSocket, "Action: login\r\n");
172  fputs($oSocket, "Events: off\r\n");
173  fputs($oSocket, "Username: $login\r\n");
174  fputs($oSocket, "Secret: $password\r\n\r\n");
175  fputs($oSocket, "Action: originate\r\n");
176  fputs($oSocket, "Channel: ".$channel.$caller."\r\n");
177  fputs($oSocket, "WaitTime: $strWaitTime\r\n");
178  fputs($oSocket, "CallerId: $strCallerId\r\n");
179  fputs($oSocket, "Exten: ".$prefix.$number."\r\n");
180  fputs($oSocket, "Context: $strContext\r\n");
181  fputs($oSocket, "Priority: $strPriority\r\n\r\n");
182  fputs($oSocket, "Action: Logoff\r\n\r\n");
183  sleep(2);
184  fclose($oSocket);
185  print '</body>'."\n";
186  }
187  }
188 }
189 else {
190  print 'Bad parameters in URL. Must be '.$_SERVER['PHP_SELF'].'?caller=99999&called=99999&login=xxxxx&password=xxxxx';
191 }
192 
193 // End of page
194 llxFooter();
195 $db->close();
llxFooter()
Empty footer.
Definition: wrapper.php:56
GETPOST($paramname, $check='none', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
print
Draft customers invoices.
Definition: index.php:91
if(! empty($conf->facture->enabled) && $user->rights->facture->lire) if(! empty($conf->fournisseur->enabled) && $user->rights->fournisseur->facture->lire) if(! empty($conf->don->enabled) && $user->rights->societe->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) && $user->rights->fournisseur->facture->lire) $resql
Social contributions to pay.
Definition: index.php:1053
dol_print_error($db='', $error='', $errors=null)
Affiche message erreur system avec toutes les informations pour faciliter le diagnostic et la remonte...
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0)
Show a message to say access is forbidden and stop program Calling this function terminate execution ...
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='')
Write log message into outputs.
llxHeader()
Empty header.
Definition: wrapper.php:44