1<?php
2/* Copyright (C) 2004      Rodolphe Quiedeville <rodolphe@quiedeville.org>
3 * Copyright (C) 2005-2020 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
20/**
21 *   \file       htdocs/admin/clicktodial.php
22 *   \ingroup    clicktodial
23 *   \brief      Page to setup module clicktodial
24 */
25
26require '../main.inc.php';
27require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php';
28
29// Load translation files required by the page
30$langs->load("admin");
31
32if (!$user->admin) accessforbidden();
33
34$action = GETPOST('action', 'aZ09');
35
36if (!in_array('clicktodial', $conf->modules)) {
37	accessforbidden($langs->trans("WarningModuleNotActive", $langs->transnoentitiesnoconv("Module58Name")));
38}
39
40
41/*
42 *	Actions
43 */
44
45if ($action == 'setvalue' && $user->admin)
46{
47	$result1 = dolibarr_set_const($db, "CLICKTODIAL_USE_TEL_LINK_ON_PHONE_NUMBERS", GETPOST("CLICKTODIAL_USE_TEL_LINK_ON_PHONE_NUMBERS"), 'chaine', 0, '', $conf->entity);
48	$result2 = dolibarr_set_const($db, "CLICKTODIAL_URL", GETPOST("CLICKTODIAL_URL"), 'chaine', 0, '', $conf->entity);
49
50	if ($result1 >= 0 && $result2 >= 0)
51	{
52		setEventMessages($langs->trans("SetupSaved"), null, 'mesgs');
53	} else {
54		setEventMessages($langs->trans("Error"), null, 'errors');
55	}
56}
57
58
59/*
60 * View
61 */
62
63$form = new Form($db);
64
65$user->fetch_clicktodial();
66
67$wikihelp = 'EN:Module_ClickToDial_En|FR:Module_ClickToDial|ES:Módulo_ClickTodial_Es';
68llxHeader('', $langs->trans("ClickToDialSetup"), $wikihelp);
69
70$linkback = '<a href="'.DOL_URL_ROOT.'/admin/modules.php?restore_lastsearch_values=1">'.$langs->trans("BackToModuleList").'</a>';
71print load_fiche_titre($langs->trans("ClickToDialSetup"), $linkback, 'title_setup');
72
73print '<span class="opacitymedium">'.$langs->trans("ClickToDialDesc")."</span><br>\n";
74
75print '<br>';
76print '<form method="post" action="clicktodial.php">';
77print '<input type="hidden" name="token" value="'.newToken().'">';
78print '<input type="hidden" name="action" value="setvalue">';
79
80print '<div class="div-table-responsive-no-min">';
81print '<table class="noborder centpercent">';
82print '<tr class="liste_titre">';
83print '<td>'.$langs->trans("Name").'</td>';
84print '<td>'.$langs->trans("Value").'</td>';
85print "</tr>\n";
86
87
88print '<tr class="oddeven"><td>';
89print $langs->trans("ClickToDialUseTelLink").'</td><td>';
90print $form->selectyesno("CLICKTODIAL_USE_TEL_LINK_ON_PHONE_NUMBERS", $conf->global->CLICKTODIAL_USE_TEL_LINK_ON_PHONE_NUMBERS, 1).'<br>';
91print '<br>';
92print $langs->trans("ClickToDialUseTelLinkDesc");
93print '</td></tr>';
94
95
96print '<tr class="oddeven"><td>';
97print $langs->trans("DefaultLink").'</td><td>';
98print '<input class="quatrevingtpercent" type="text" id="CLICKTODIAL_URL" name="CLICKTODIAL_URL"'.($conf->global->CLICKTODIAL_USE_TEL_LINK_ON_PHONE_NUMBERS ? ' disabled="disabled"' : '').' value="'.$conf->global->CLICKTODIAL_URL.'"><br>';
99print ajax_autoselect('CLICKTODIAL_URL');
100print '<br>';
101print $langs->trans("ClickToDialUrlDesc").'<br>';
102print $langs->trans("Example").':<br>http://myphoneserver/mypage?login=__LOGIN__&password=__PASS__&caller=__PHONEFROM__&called=__PHONETO__';
103
104//if (! empty($user->clicktodial_url))
105//{
106	print '<br>';
107	print info_admin($langs->trans("ValueOverwrittenByUserSetup"));
108//}
109
110print '</td></tr>';
111
112print '</table>';
113print '</div>';
114
115print '<div class="center"><br><input type="submit" class="button" value="'.$langs->trans("Modify").'"></div>';
116
117print '</form><br><br>';
118
119
120if (!empty($conf->global->CLICKTODIAL_URL))
121{
122	$user->fetch_clicktodial();
123
124	$phonefortest = $mysoc->phone;
125	if (GETPOST('phonefortest')) $phonefortest = GETPOST('phonefortest');
126
127	print '<form action="'.$_SERVER["PHP_SELF"].'">';
128	print '<input type="hidden" name="token" value="'.newToken().'">';
129	print $langs->trans("LinkToTestClickToDial", $user->login).' : ';
130	print '<input class="flat" type="text" name="phonefortest" value="'.dol_escape_htmltag($phonefortest).'">';
131	print '<input type="submit" class="button" value="'.dol_escape_htmltag($langs->trans("RefreshPhoneLink")).'">';
132	print '</form>';
133
134	$setupcomplete = 1;
135	if (preg_match('/__LOGIN__/', $conf->global->CLICKTODIAL_URL) && empty($user->clicktodial_login)) $setupcomplete = 0;
136	if (preg_match('/__PASSWORD__/', $conf->global->CLICKTODIAL_URL) && empty($user->clicktodial_password)) $setupcomplete = 0;
137	if (preg_match('/__PHONEFROM__/', $conf->global->CLICKTODIAL_URL) && empty($user->clicktodial_poste)) $setupcomplete = 0;
138
139	if ($setupcomplete)
140	{
141		print $langs->trans("LinkToTest", $user->login).': '.dol_print_phone($phonefortest, '', 0, 0, 'AC_TEL');
142	} else {
143		$langs->load("errors");
144		print '<div class="warning">'.$langs->trans("WarningClickToDialUserSetupNotComplete").'</div>';
145	}
146}
147
148// End of page
149llxFooter();
150$db->close();
151