dolibarr  16.0.5
clicktodial.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (C) 2005 Rodolphe Quiedeville <rodolphe@quiedeville.org>
3  * Copyright (C) 2005-2012 Laurent Destailleur <eldy@users.sourceforge.net>
4  * Copyright (C) 2012 Regis Houssin <regis.houssin@inodbox.com>
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 
25 require '../main.inc.php';
26 require_once DOL_DOCUMENT_ROOT.'/core/lib/usergroups.lib.php';
27 
28 // Load translation files required by page
29 $langs->loadLangs(array('users', 'admin'));
30 
31 $action = (string) GETPOST('action', 'aZ09');
32 $id = (int) GETPOST('id', 'int');
33 
34 // Security check
35 $socid = 0;
36 if ($user->socid > 0) {
37  $socid = $user->socid;
38 }
39 $feature2 = (($socid && $user->rights->user->self->creer) ? '' : 'user');
40 
41 $result = restrictedArea($user, 'user', $id, 'user&user', $feature2);
42 
43 // Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context
44 $hookmanager->initHooks(array('usercard', 'globalcard'));
45 
46 
47 /*
48  * Actions
49  */
50 
51 $parameters = array('id'=>$socid);
52 $reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
53 if ($reshook < 0) {
54  setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
55 }
56 
57 if (empty($reshook)) {
58  if ($action == 'update' && !GETPOST('cancel', 'alpha')) {
59  $edituser = new User($db);
60  $edituser->fetch($id);
61 
62  $edituser->clicktodial_url = (string) GETPOST("url", "alpha");
63  $edituser->clicktodial_login = (string) GETPOST("login", "alpha");
64  $edituser->clicktodial_password = (string) GETPOST("password", "alpha");
65  $edituser->clicktodial_poste = (string) GETPOST("poste", "alpha");
66 
67  $result = $edituser->update_clicktodial();
68  if ($result < 0) {
69  setEventMessages($edituser->error, $edituser->errors, 'errors');
70  }
71  }
72 }
73 
74 
75 /*
76  * View
77  */
78 
79 $form = new Form($db);
80 
81 llxHeader("", "ClickToDial");
82 
83 
84 if ($id > 0) {
85  $object = new User($db);
86  $object->fetch($id, '', '', 1);
87  $object->getrights();
88  $object->fetch_clicktodial();
89 
90 
91  $head = user_prepare_head($object);
92 
93  $title = $langs->trans("User");
94 
95 
96  print '<form action="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'" method="post">';
97  print '<input type="hidden" name="token" value="'.newToken().'">';
98  print '<input type="hidden" name="action" value="update">';
99 
100  print dol_get_fiche_head($head, 'clicktodial', $title, -1, 'user');
101 
102  $linkback = '';
103 
104  if ($user->rights->user->user->lire || $user->admin) {
105  $linkback = '<a href="'.DOL_URL_ROOT.'/user/list.php?restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>';
106  }
107 
108  $morehtmlref = '<a href="'.DOL_URL_ROOT.'/user/vcard.php?id='.$object->id.'" class="refid">';
109  $morehtmlref .= img_picto($langs->trans("Download").' '.$langs->trans("VCard"), 'vcard.png', 'class="valignmiddle marginleftonly paddingrightonly"');
110  $morehtmlref .= '</a>';
111 
112  dol_banner_tab($object, 'id', $linkback, $user->rights->user->user->lire || $user->admin, 'rowid', 'ref', $morehtmlref);
113 
114  print '<div class="fichecenter">';
115  print '<div class="underbanner clearboth"></div>';
116 
117  // Edit mode
118  if ($action == 'edit') {
119  print '<table class="border centpercent">';
120 
121  if ($user->admin) {
122  print '<tr><td class="titlefield fieldrequired">ClickToDial URL</td>';
123  print '<td class="valeur">';
124  print '<input name="url" value="'.(!empty($object->clicktodial_url) ? $object->clicktodial_url : '').'" size="92">';
125  if (empty($conf->global->CLICKTODIAL_URL) && empty($object->clicktodial_url)) {
126  $langs->load("errors");
127  print '<span class="error">'.$langs->trans("ErrorModuleSetupNotComplete", $langs->transnoentitiesnoconv("ClickToDial")).'</span>';
128  } else {
129  print ' &nbsp; &nbsp; '.$form->textwithpicto($langs->trans("KeepEmptyToUseDefault").': '.$conf->global->CLICKTODIAL_URL, $langs->trans("ClickToDialUrlDesc"));
130  }
131  print '</td>';
132  print '</tr>';
133  }
134 
135  print '<tr><td class="titlefield fieldrequired">ClickToDial '.$langs->trans("IdPhoneCaller").'</td>';
136  print '<td class="valeur">';
137  print '<input name="poste" value="'.(!empty($object->clicktodial_poste) ? $object->clicktodial_poste : '').'"></td>';
138  print "</tr>\n";
139 
140  print '<tr><td>ClickToDial '.$langs->trans("Login").'</td>';
141  print '<td class="valeur">';
142  print '<input name="login" value="'.(!empty($object->clicktodial_login) ? $object->clicktodial_login : '').'"></td>';
143  print '</tr>';
144 
145  print '<tr><td>ClickToDial '.$langs->trans("Password").'</td>';
146  print '<td class="valeur">';
147  print '<input type="password" name="password" value="'.dol_escape_htmltag(empty($object->clicktodial_password) ? '' : $object->clicktodial_password).'"></td>';
148  print "</tr>\n";
149 
150  print '</table>';
151  } else // View mode
152  {
153  print '<table class="border centpercent tableforfield">';
154 
155  if (!empty($user->admin)) {
156  print '<tr><td class="titlefield">ClickToDial URL</td>';
157  print '<td class="valeur">';
158  if (!empty($conf->global->CLICKTODIAL_URL)) {
159  $url = $conf->global->CLICKTODIAL_URL;
160  }
161  if (!empty($object->clicktodial_url)) {
162  $url = $object->clicktodial_url;
163  }
164  if (empty($url)) {
165  $langs->load("errors");
166  print '<span class="error">'.$langs->trans("ErrorModuleSetupNotComplete", $langs->transnoentitiesnoconv("ClickToDial")).'</span>';
167  } else {
168  print $form->textwithpicto((empty($object->clicktodial_url) ? '<span class="opacitymedium">'.$langs->trans("DefaultLink").':</span> ' : '').$url, $langs->trans("ClickToDialUrlDesc"));
169  }
170  print '</td>';
171  print '</tr>';
172  }
173 
174  print '<tr><td class="titlefield">ClickToDial '.$langs->trans("IdPhoneCaller").'</td>';
175  print '<td class="valeur">'.(!empty($object->clicktodial_poste) ? $object->clicktodial_poste : '').'</td>';
176  print "</tr>";
177 
178  print '<tr><td>ClickToDial '.$langs->trans("Login").'</td>';
179  print '<td class="valeur">'.(!empty($object->clicktodial_login) ? $object->clicktodial_login : '').'</td>';
180  print '</tr>';
181 
182  print '<tr><td>ClickToDial '.$langs->trans("Password").'</td>';
183  print '<td class="valeur">'.preg_replace('/./', '*', (!empty($object->clicktodial_password) ? $object->clicktodial_password : '')).'</a></td>';
184  print "</tr>\n";
185 
186  print "</table>\n";
187  }
188 
189  print dol_get_fiche_end();
190 
191  if ($action == 'edit') {
192  print '<br>';
193  print '<div class="center"><input class="button button-save" type="submit" value="'.$langs->trans("Save").'">';
194  print '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
195  print '<input class="button button-cancel" type="submit" name="cancel" value="'.$langs->trans("Cancel").'">';
196  print '</div>';
197  }
198 
199  print '</div>';
200  print '</form>';
201 
202  /*
203  * Action bar
204  */
205  print '<div class="tabsAction">';
206 
207  if (!empty($user->admin) && $action <> 'edit') {
208  print '<a class="butAction" href="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'&action=edit&token='.newToken().'">'.$langs->trans("Modify").'</a>';
209  }
210 
211  print "</div>\n";
212 }
213 
214 // End of page
215 llxFooter();
216 $db->close();
restrictedArea
restrictedArea($user, $features, $objectid=0, $tableandshare='', $feature2='', $dbt_keyfield='fk_soc', $dbt_select='rowid', $isdraft=0, $mode=0)
Check permissions of a user to show a page and an object.
Definition: security.lib.php:234
llxFooter
llxFooter()
Empty footer.
Definition: wrapper.php:73
user_prepare_head
user_prepare_head(User $object)
Prepare array with list of tabs.
Definition: usergroups.lib.php:35
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
dol_banner_tab
dol_banner_tab($object, $paramid, $morehtml='', $shownav=1, $fieldid='rowid', $fieldref='ref', $morehtmlref='', $moreparam='', $nodbprefix=0, $morehtmlleft='', $morehtmlstatus='', $onlybanner=0, $morehtmlright='')
Show tab footer of a card.
Definition: functions.lib.php:2046
img_picto
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
Definition: functions.lib.php:3880
dol_get_fiche_head
dol_get_fiche_head($links=array(), $active='', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limittoshow=0, $moretabssuffix='')
Show tabs of a record.
Definition: functions.lib.php:1822
newToken
newToken()
Return the value of token currently saved into session with name 'newtoken'.
Definition: functions.lib.php:10878
dol_get_fiche_end
dol_get_fiche_end($notab=0)
Return tab footer of a card.
Definition: functions.lib.php:2018
User
Class to manage Dolibarr users.
Definition: user.class.php:44
Form
Class to manage generation of HTML components Only common components must be here.
Definition: html.form.class.php:52
setEventMessages
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='')
Set event messages in dol_events session object.
Definition: functions.lib.php:8137
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