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