dolibarr  16.0.5
clicktodial.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (C) 2004 Rodolphe Quiedeville <rodolphe@quiedeville.org>
3  * Copyright (C) 2005-2021 Laurent Destailleur <eldy@users.sourceforge.org>
4  * Copyright (C) 2011-2013 Juanjo Menent <jmenent@2byte.es>
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program. If not, see <https://www.gnu.org/licenses/>.
18  */
19 
26 require '../main.inc.php';
27 require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php';
28 
29 // Load translation files required by the page
30 $langs->load("admin");
31 
32 if (!$user->admin) {
34 }
35 
36 $action = GETPOST('action', 'aZ09');
37 
38 if (!in_array('clicktodial', $conf->modules)) {
39  accessforbidden($langs->trans("WarningModuleNotActive", $langs->transnoentitiesnoconv("Module58Name")));
40 }
41 
42 
43 /*
44  * Actions
45  */
46 
47 if ($action == 'setvalue' && $user->admin) {
48  $result1 = dolibarr_set_const($db, "CLICKTODIAL_USE_TEL_LINK_ON_PHONE_NUMBERS", GETPOST("CLICKTODIAL_USE_TEL_LINK_ON_PHONE_NUMBERS"), 'chaine', 0, '', $conf->entity);
49  $result2 = dolibarr_set_const($db, "CLICKTODIAL_URL", GETPOST("CLICKTODIAL_URL"), 'chaine', 0, '', $conf->entity);
50  $result3 = dolibarr_set_const($db, "CLICKTODIAL_KEY_FOR_CIDLOOKUP", GETPOST("CLICKTODIAL_KEY_FOR_CIDLOOKUP"), 'chaine', 0, '', $conf->entity);
51 
52  if ($result1 >= 0 && $result2 >= 0 && $result3 >= 0) {
53  setEventMessages($langs->trans("SetupSaved"), null, 'mesgs');
54  } else {
55  setEventMessages($langs->trans("Error"), null, 'errors');
56  }
57 }
58 
59 
60 /*
61  * View
62  */
63 
64 $form = new Form($db);
65 
66 $user->fetch_clicktodial();
67 
68 $wikihelp = 'EN:Module_ClickToDial_En|FR:Module_ClickToDial|ES:Módulo_ClickTodial_Es';
69 llxHeader('', $langs->trans("ClickToDialSetup"), $wikihelp);
70 
71 $linkback = '<a href="'.DOL_URL_ROOT.'/admin/modules.php?restore_lastsearch_values=1">'.$langs->trans("BackToModuleList").'</a>';
72 print load_fiche_titre($langs->trans("ClickToDialSetup"), $linkback, 'title_setup');
73 
74 print '<span class="opacitymedium">'.$langs->trans("ClickToDialDesc")."</span><br>\n";
75 
76 print '<br>';
77 print '<form method="post" action="clicktodial.php">';
78 print '<input type="hidden" name="token" value="'.newToken().'">';
79 print '<input type="hidden" name="action" value="setvalue">';
80 
81 print '<div class="div-table-responsive-no-min">';
82 print '<table class="noborder centpercent">';
83 print '<tr class="liste_titre">';
84 print '<td class="minwidth200">'.$langs->trans("Name").'</td>';
85 print '<td>'.$langs->trans("Value").'</td>';
86 print "</tr>\n";
87 
88 
89 print '<tr class="oddeven"><td>';
90 print $langs->trans("ClickToDialUseTelLink").'</td><td>';
91 print $form->selectyesno("CLICKTODIAL_USE_TEL_LINK_ON_PHONE_NUMBERS", $conf->global->CLICKTODIAL_USE_TEL_LINK_ON_PHONE_NUMBERS, 1).'<br>';
92 print '<br>';
93 print '<span class="opacitymedium small">'.$langs->trans("ClickToDialUseTelLinkDesc").'</span>';
94 print '</td></tr>';
95 
96 
97 print '<tr class="oddeven"><td>';
98 print $langs->trans("DefaultLink").'</td><td>';
99 print '<input class="quatrevingtpercent" type="text" id="CLICKTODIAL_URL" name="CLICKTODIAL_URL"'.(getDolGlobalString('CLICKTODIAL_USE_TEL_LINK_ON_PHONE_NUMBERS') ? ' disabled="disabled"' : '').' value="'.getDolGlobalString('CLICKTODIAL_URL').'"><br>';
100 print ajax_autoselect('CLICKTODIAL_URL');
101 print '<br>';
102 print $langs->trans("ClickToDialUrlDesc").'<br>';
103 print '<br>';
104 print '<span class="opacitymedium">';
105 print $langs->trans("Examples").':<br>';
106 print '* https://myphoneserver/phoneurl?login=__LOGIN__&password=__PASS__&caller=__PHONEFROM__&called=__PHONETO__<br>';
107 print '* sip:__PHONETO__@my.sip.server';
108 print '</span>';
109 
110 //if (! empty($user->clicktodial_url))
111 //{
112  print '<br>';
113  print info_admin($langs->trans("ValueOverwrittenByUserSetup"));
114 //}
115 
116 print '</td></tr>';
117 
118 print '<tr class="oddeven">';
119 print '<td>'.$langs->trans("SecurityKey").'</td>';
120 print '<td>';
121 
122 global $dolibarr_main_url_root;
123 
124 // Define $urlwithroot
125 $urlwithouturlroot = preg_replace('/'.preg_quote(DOL_URL_ROOT, '/').'$/i', '', trim($dolibarr_main_url_root));
126 $urlwithroot = $urlwithouturlroot.DOL_URL_ROOT; // This is to use external domain name found into config file
127 //$urlwithroot=DOL_MAIN_URL_ROOT; // This is to use same domain name than current
128 
129 // Url for CIDLookup
130 //print '<div class="div-table-responsive-no-min">';
131 //print $langs->trans("URLToLaunchCronJobs").':<br>';
132 $url = $urlwithroot.'/public/clicktodial/cidlookup.php?securitykey='.getDolGlobalString('CLICKTODIAL_KEY_FOR_CIDLOOKUP', 'ValueToDefine').'&phone=...';
133 //print img_picto('', 'globe').' <a href="'.$url.'" target="_blank" rel="noopener noreferrer">'.$url."</a><br>\n";
134 //print '</div>';
135 //print '<br>';
136 
137 
138 print '<span class="opacitymedium">'.$langs->trans("CIDLookupURL").'</span>';
139 print '<br>'.$url;
140 print '<br>';
141 print '<br>';
142 print '<input type="text" class="flat minwidth300" id="CLICKTODIAL_KEY_FOR_CIDLOOKUP" name="CLICKTODIAL_KEY_FOR_CIDLOOKUP" value="'.(GETPOST('CLICKTODIAL_KEY_FOR_CIDLOOKUP') ? GETPOST('CLICKTODIAL_KEY_FOR_CIDLOOKUP') : (!empty($conf->global->CLICKTODIAL_KEY_FOR_CIDLOOKUP) ? $conf->global->CLICKTODIAL_KEY_FOR_CIDLOOKUP : '')).'">';
143 if (!empty($conf->use_javascript_ajax)) {
144  print '&nbsp;'.img_picto($langs->trans('Generate'), 'refresh', 'id="generate_token" class="linkobject"');
145 }
146 print '</td>';
147 print '</tr>';
148 
149 print '</table>';
150 print '</div>';
151 
152 print $form->buttonsSaveCancel("Modify", '');
153 
154 print '</form><br><br>';
155 
156 
157 if (!empty($conf->global->CLICKTODIAL_URL)) {
158  $user->fetch_clicktodial();
159 
160  $phonefortest = $mysoc->phone;
161  if (GETPOST('phonefortest')) {
162  $phonefortest = GETPOST('phonefortest');
163  }
164 
165  print '<form action="'.$_SERVER["PHP_SELF"].'">';
166  print '<input type="hidden" name="token" value="'.newToken().'">';
167  print $langs->trans("LinkToTestClickToDial", $user->login).' : ';
168  print '<input class="flat" type="text" name="phonefortest" value="'.dol_escape_htmltag($phonefortest).'">';
169  print '<input type="submit" class="button small" value="'.dol_escape_htmltag($langs->trans("RefreshPhoneLink")).'">';
170  print '</form>';
171 
172  $setupcomplete = 1;
173  if (preg_match('/__LOGIN__/', $conf->global->CLICKTODIAL_URL) && empty($user->clicktodial_login)) {
174  $setupcomplete = 0;
175  }
176  if (preg_match('/__PASSWORD__/', $conf->global->CLICKTODIAL_URL) && empty($user->clicktodial_password)) {
177  $setupcomplete = 0;
178  }
179  if (preg_match('/__PHONEFROM__/', $conf->global->CLICKTODIAL_URL) && empty($user->clicktodial_poste)) {
180  $setupcomplete = 0;
181  }
182 
183  if ($setupcomplete) {
184  print $langs->trans("LinkToTest", $user->login).': &nbsp; '.dol_print_phone($phonefortest, '', 0, 0, 'AC_TEL', '', 'mobile');
185  } else {
186  $langs->load("errors");
187  print '<div class="warning">'.$langs->trans("WarningClickToDialUserSetupNotComplete").'</div>';
188  }
189 }
190 
191 if (!empty($conf->use_javascript_ajax)) {
192  print "\n".'<script type="text/javascript">';
193  print '$(document).ready(function () {
194  $("#generate_token").click(function() {
195  console.log("Click done");
196  $.get( "'.DOL_URL_ROOT.'/core/ajax/security.php", {
197  action: \'getrandompassword\',
198  generic: true
199  },
200  function(token) {
201  $("#CLICKTODIAL_KEY_FOR_CIDLOOKUP").val(token);
202  });
203  });
204  });';
205  print '</script>';
206 }
207 
208 // End of page
209 llxFooter();
210 $db->close();
llxFooter
llxFooter()
Empty footer.
Definition: wrapper.php:73
load_fiche_titre
load_fiche_titre($titre, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
Definition: functions.lib.php:5204
GETPOST
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
Definition: functions.lib.php:484
$form
if($cancel &&! $id) if($action=='add' &&! $cancel) if($action=='delete') if($id) $form
Actions.
Definition: card.php:142
$wikihelp
if($actionsave) if(!isset($conf->global->MAIN_AGENDA_EXPORT_PAST_DELAY)) $wikihelp
View.
Definition: agenda_xcal.php:72
getDolGlobalString
if(!function_exists('utf8_encode')) if(!function_exists('utf8_decode')) getDolGlobalString($key, $default='')
Return dolibarr global constant string value.
Definition: functions.lib.php:80
info_admin
info_admin($text, $infoonimgalt=0, $nodiv=0, $admin='1', $morecss='hideonsmartphone', $textfordropdown='')
Show information for admin users or standard users.
Definition: functions.lib.php:4800
dolibarr_set_const
dolibarr_set_const($db, $name, $value, $type='chaine', $visible=0, $note='', $entity=1)
Insert a parameter (key,value) into database (delete old key then insert it again).
Definition: admin.lib.php:627
Form
Class to manage generation of HTML components Only common components must be here.
Definition: html.form.class.php:52
dol_print_phone
dol_print_phone($phone, $countrycode='', $cid=0, $socid=0, $addlink='', $separ="&nbsp;", $withpicto='', $titlealt='', $adddivfloat=0)
Format phone numbers according to country.
Definition: functions.lib.php:3185
setEventMessages
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='')
Set event messages in dol_events session object.
Definition: functions.lib.php:8137
accessforbidden
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 ...
Definition: security.lib.php:933
ajax_autoselect
ajax_autoselect($htmlname, $addlink='', $textonlink='Link')
Make content of an input box selected when we click into input field.
Definition: functions.lib.php:9681
llxHeader
if(!defined('NOREQUIRESOC')) if(!defined('NOREQUIRETRAN')) if(!defined('NOCSRFCHECK')) if(!defined('NOTOKENRENEWAL')) if(!defined('NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined('NOREQUIREAJAX')) llxHeader()
Empty header.
Definition: wrapper.php:59