clicktodial.php 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220
  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. /**
  20. * \file htdocs/user/clicktodial.php
  21. * \brief Page for Click to dial datas
  22. */
  23. // Load Dolibarr environment
  24. require '../main.inc.php';
  25. require_once DOL_DOCUMENT_ROOT.'/core/lib/usergroups.lib.php';
  26. // Load translation files required by page
  27. $langs->loadLangs(array('users', 'admin'));
  28. $action = (string) GETPOST('action', 'aZ09');
  29. $id = (int) GETPOST('id', 'int');
  30. // Security check
  31. $socid = 0;
  32. if ($user->socid > 0) {
  33. $socid = $user->socid;
  34. }
  35. $feature2 = (($socid && $user->hasRight('user', 'self', 'creer')) ? '' : 'user');
  36. $result = restrictedArea($user, 'user', $id, 'user&user', $feature2);
  37. // Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context
  38. $hookmanager->initHooks(array('usercard', 'globalcard'));
  39. /*
  40. * Actions
  41. */
  42. $parameters = array('id'=>$socid);
  43. $reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
  44. if ($reshook < 0) {
  45. setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
  46. }
  47. if (empty($reshook)) {
  48. if ($action == 'update' && !GETPOST('cancel', 'alpha')) {
  49. $edituser = new User($db);
  50. $edituser->fetch($id);
  51. $edituser->clicktodial_url = (string) GETPOST("url", "alpha");
  52. $edituser->clicktodial_login = (string) GETPOST("login", "alpha");
  53. $edituser->clicktodial_password = (string) GETPOST("password", "alpha");
  54. $edituser->clicktodial_poste = (string) GETPOST("poste", "alpha");
  55. $result = $edituser->update_clicktodial();
  56. if ($result < 0) {
  57. setEventMessages($edituser->error, $edituser->errors, 'errors');
  58. }
  59. }
  60. }
  61. /*
  62. * View
  63. */
  64. $form = new Form($db);
  65. if ($id > 0) {
  66. $object = new User($db);
  67. $object->fetch($id, '', '', 1);
  68. $object->getrights();
  69. $object->fetch_clicktodial();
  70. $person_name = !empty($object->firstname) ? $object->lastname.", ".$object->firstname : $object->lastname;
  71. $title = $person_name." - ".$langs->trans('ClickToDial');
  72. $help_url = '';
  73. llxHeader('', $title, $help_url);
  74. $head = user_prepare_head($object);
  75. $title = $langs->trans("User");
  76. print '<form action="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'" method="post">';
  77. print '<input type="hidden" name="token" value="'.newToken().'">';
  78. print '<input type="hidden" name="action" value="update">';
  79. print dol_get_fiche_head($head, 'clicktodial', $title, -1, 'user');
  80. $linkback = '';
  81. if ($user->hasRight('user', 'user', 'lire') || $user->admin) {
  82. $linkback = '<a href="'.DOL_URL_ROOT.'/user/list.php?restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>';
  83. }
  84. $morehtmlref = '<a href="'.DOL_URL_ROOT.'/user/vcard.php?id='.$object->id.'&output=file&file='.urlencode(dol_sanitizeFileName($object->getFullName($langs).'.vcf')).'" class="refid" rel="noopener">';
  85. $morehtmlref .= img_picto($langs->trans("Download").' '.$langs->trans("VCard"), 'vcard.png', 'class="valignmiddle marginleftonly paddingrightonly"');
  86. $morehtmlref .= '</a>';
  87. $urltovirtualcard = '/user/virtualcard.php?id='.((int) $object->id);
  88. $morehtmlref .= dolButtonToOpenUrlInDialogPopup('publicvirtualcard', $langs->trans("PublicVirtualCardUrl").' - '.$object->getFullName($langs), img_picto($langs->trans("PublicVirtualCardUrl"), 'card', 'class="valignmiddle marginleftonly paddingrightonly"'), $urltovirtualcard, '', 'nohover');
  89. dol_banner_tab($object, 'id', $linkback, $user->hasRight('user', 'user', 'lire') || $user->admin, 'rowid', 'ref', $morehtmlref);
  90. print '<div class="fichecenter">';
  91. print '<div class="underbanner clearboth"></div>';
  92. // Edit mode
  93. if ($action == 'edit') {
  94. print '<table class="border centpercent">';
  95. if ($user->admin) {
  96. print '<tr><td class="titlefield fieldrequired">ClickToDial URL</td>';
  97. print '<td class="valeur">';
  98. print '<input name="url" value="'.(!empty($object->clicktodial_url) ? $object->clicktodial_url : '').'" size="92">';
  99. if (!getDolGlobalString('CLICKTODIAL_URL') && empty($object->clicktodial_url)) {
  100. $langs->load("errors");
  101. print '<span class="error">'.$langs->trans("ErrorModuleSetupNotComplete", $langs->transnoentitiesnoconv("ClickToDial")).'</span>';
  102. } else {
  103. print '<br>'.$form->textwithpicto('<span class="opacitymedium">'.$langs->trans("KeepEmptyToUseDefault").'</span>:<br>' . getDolGlobalString('CLICKTODIAL_URL'), $langs->trans("ClickToDialUrlDesc"));
  104. }
  105. print '</td>';
  106. print '</tr>';
  107. }
  108. print '<tr><td class="titlefield fieldrequired">ClickToDial '.$langs->trans("IdPhoneCaller").'</td>';
  109. print '<td class="valeur">';
  110. print '<input name="poste" value="'.(!empty($object->clicktodial_poste) ? $object->clicktodial_poste : '').'"></td>';
  111. print "</tr>\n";
  112. print '<tr><td>ClickToDial '.$langs->trans("Login").'</td>';
  113. print '<td class="valeur">';
  114. print '<input name="login" value="'.(!empty($object->clicktodial_login) ? $object->clicktodial_login : '').'"></td>';
  115. print '</tr>';
  116. print '<tr><td>ClickToDial '.$langs->trans("Password").'</td>';
  117. print '<td class="valeur">';
  118. print '<input type="password" name="password" value="'.dol_escape_htmltag(empty($object->clicktodial_password) ? '' : $object->clicktodial_password).'"></td>';
  119. print "</tr>\n";
  120. print '</table>';
  121. } else // View mode
  122. {
  123. print '<table class="border centpercent tableforfield">';
  124. if (!empty($user->admin)) {
  125. print '<tr><td class="">ClickToDial URL</td>';
  126. print '<td class="valeur">';
  127. if (getDolGlobalString('CLICKTODIAL_URL')) {
  128. $url = $conf->global->CLICKTODIAL_URL;
  129. }
  130. if (!empty($object->clicktodial_url)) {
  131. $url = $object->clicktodial_url;
  132. }
  133. if (empty($url)) {
  134. $langs->load("errors");
  135. print '<span class="error">'.$langs->trans("ErrorModuleSetupNotComplete", $langs->transnoentitiesnoconv("ClickToDial")).'</span>';
  136. } else {
  137. print $form->textwithpicto((empty($object->clicktodial_url) ? '<span class="opacitymedium">'.$langs->trans("DefaultLink").':</span> ' : '').$url, $langs->trans("ClickToDialUrlDesc"));
  138. }
  139. print '</td>';
  140. print '</tr>';
  141. }
  142. print '<tr><td class="">ClickToDial '.$langs->trans("IdPhoneCaller").'</td>';
  143. print '<td class="valeur">'.(!empty($object->clicktodial_poste) ? $object->clicktodial_poste : '').'</td>';
  144. print "</tr>";
  145. print '<tr><td>ClickToDial '.$langs->trans("Login").'</td>';
  146. print '<td class="valeur">'.(!empty($object->clicktodial_login) ? $object->clicktodial_login : '').'</td>';
  147. print '</tr>';
  148. print '<tr><td>ClickToDial '.$langs->trans("Password").'</td>';
  149. print '<td class="valeur">'.preg_replace('/./', '*', (!empty($object->clicktodial_password) ? $object->clicktodial_password : '')).'</a></td>';
  150. print "</tr>\n";
  151. print "</table>\n";
  152. }
  153. print dol_get_fiche_end();
  154. if ($action == 'edit') {
  155. print '<br>';
  156. print '<div class="center"><input class="button button-save" type="submit" value="'.$langs->trans("Save").'">';
  157. print '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
  158. print '<input class="button button-cancel" type="submit" name="cancel" value="'.$langs->trans("Cancel").'">';
  159. print '</div>';
  160. }
  161. print '</div>';
  162. print '</form>';
  163. /*
  164. * Action bar
  165. */
  166. print '<div class="tabsAction">';
  167. if (!empty($user->admin) && $action <> 'edit') {
  168. print '<a class="butAction" href="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'&action=edit&token='.newToken().'">'.$langs->trans("Modify").'</a>';
  169. }
  170. print "</div>\n";
  171. }
  172. // End of page
  173. llxFooter();
  174. $db->close();