company_socialnetworks.php 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. <?php
  2. /* Copyright (C) 2001-2007 Rodolphe Quiedeville <rodolphe@quiedeville.org>
  3. * Copyright (C) 2004-2019 Laurent Destailleur <eldy@users.sourceforge.net>
  4. * Copyright (C) 2005-2017 Regis Houssin <regis.houssin@inodbox.com>
  5. * Copyright (C) 2010-2014 Juanjo Menent <jmenent@2byte.es>
  6. * Copyright (C) 2011-2017 Philippe Grand <philippe.grand@atoo-net.com>
  7. * Copyright (C) 2015 Alexandre Spangaro <aspangaro@open-dsi.fr>
  8. * Copyright (C) 2017 Rui Strecht <rui.strecht@aliartalentos.com>
  9. * Copyright (C) 2020 Frédéric France <frederic.france@netlogic.fr>
  10. *
  11. * This program is free software; you can redistribute it and/or modify
  12. * it under the terms of the GNU General Public License as published by
  13. * the Free Software Foundation; either version 3 of the License, or
  14. * (at your option) any later version.
  15. *
  16. * This program is distributed in the hope that it will be useful,
  17. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  19. * GNU General Public License for more details.
  20. *
  21. * You should have received a copy of the GNU General Public License
  22. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  23. */
  24. /**
  25. * \file htdocs/admin/company_socialnetworks.php
  26. * \ingroup company
  27. * \brief Setup page to configure company social networks
  28. */
  29. // Load Dolibarr environment
  30. require '../main.inc.php';
  31. require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php';
  32. $action = GETPOST('action', 'aZ09');
  33. $contextpage = GETPOST('contextpage', 'aZ') ?GETPOST('contextpage', 'aZ') : 'admincompany'; // To manage different context of search
  34. // Load translation files required by the page
  35. $langs->loadLangs(array('admin', 'companies'));
  36. if (!$user->admin) {
  37. accessforbidden();
  38. }
  39. $listofnetworks = getArrayOfSocialNetworks();
  40. // Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context
  41. $hookmanager->initHooks(array('adminsocialnetworkscompany', 'globaladmin'));
  42. /*
  43. * Actions
  44. */
  45. $parameters = array();
  46. $reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
  47. if ($reshook < 0) {
  48. setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
  49. }
  50. if (($action == 'update' && !GETPOST("cancel", 'alpha'))) {
  51. foreach ($listofnetworks as $key => $value) {
  52. if (!empty($value['active'])) {
  53. $networkconstname = 'MAIN_INFO_SOCIETE_'.strtoupper($key).'_URL';
  54. $networkconstid = 'MAIN_INFO_SOCIETE_'.strtoupper($key);
  55. if (GETPOSTISSET($key.'url') && GETPOST($key.'url', 'alpha') != '') {
  56. dolibarr_set_const($db, $networkconstname, GETPOST($key.'url', 'alpha'), 'chaine', 0, '', $conf->entity);
  57. dolibarr_set_const($db, $networkconstid, GETPOST($key, 'alpha'), 'chaine', 0, '', $conf->entity);
  58. } elseif (GETPOSTISSET($key) && GETPOST($key, 'alpha') != '') {
  59. if (!empty($listofnetworks[$key]['url'])) {
  60. $url = str_replace('{socialid}', GETPOST($key, 'alpha'), $listofnetworks[$key]['url']);
  61. dolibarr_set_const($db, $networkconstname, $url, 'chaine', 0, '', $conf->entity);
  62. }
  63. dolibarr_set_const($db, $networkconstid, GETPOST($key, 'alpha'), 'chaine', 0, '', $conf->entity);
  64. } else {
  65. dolibarr_del_const($db, $networkconstname, $conf->entity);
  66. dolibarr_del_const($db, $networkconstid, $conf->entity);
  67. }
  68. }
  69. }
  70. setEventMessages($langs->trans("SetupSaved"), null, 'mesgs');
  71. }
  72. /*
  73. * View
  74. */
  75. $form = new Form($db);
  76. $wikihelp = 'EN:First_setup|FR:Premiers_paramétrages|ES:Primeras_configuraciones';
  77. llxHeader('', $langs->trans("Setup"), $wikihelp);
  78. print load_fiche_titre($langs->trans("CompanyFoundation"), '', 'title_setup');
  79. $head = company_admin_prepare_head();
  80. print dol_get_fiche_head($head, 'socialnetworks', '', -1, '');
  81. print '<span class="opacitymedium">'.$langs->trans("CompanyFundationDesc", $langs->transnoentities("Save"))."</span><br>\n";
  82. print '<span class="opacitymedium">'.$langs->trans("MoreNetworksAvailableWithModule")."</span><br>\n";
  83. print "<br>\n";
  84. /**
  85. * Edit parameters
  86. */
  87. print '<form method="POST" action="'.$_SERVER["PHP_SELF"].'">';
  88. print '<input type="hidden" name="token" value="'.newToken().'">';
  89. print '<input type="hidden" name="action" value="update">';
  90. print '<div class="div-table-responsive-no-min">';
  91. print '<table class="noborder centpercent editmode">';
  92. print '<tr class="liste_titre">';
  93. print '<td class="titlefieldcreate">'.$langs->trans("SocialNetworksInformation").'</td>';
  94. print '<td>'.$langs->trans("SocialNetworkId").'</td>';
  95. print '<td>'.$form->textwithpicto($langs->trans("Url"), $langs->trans("KeepEmptyToUseDefault")).'</td>';
  96. print '<td></td>';
  97. print "</tr>\n";
  98. $listofnetworks = dol_sort_array($listofnetworks, 'label');
  99. //var_dump($listofnetworks);
  100. foreach ($listofnetworks as $key => $value) {
  101. if (!empty($value['active'])) {
  102. print '<tr class="oddeven">';
  103. print '<td><label for="'.$key.'url">'.$langs->trans(ucfirst($key)).'</label></td>';
  104. $networkconstname = 'MAIN_INFO_SOCIETE_'.strtoupper($key).'_URL';
  105. $networkconstid = 'MAIN_INFO_SOCIETE_'.strtoupper($key);
  106. print '<td class="nowraponall"><span class="fa paddingright '.($value['icon'] ? $value['icon'] : 'fa-link').'"></span>';
  107. print '<input name="'.$key.'" id="'.$key.'" class="minwidth300" value="'.(!empty($conf->global->$networkconstid) ? dol_escape_htmltag($conf->global->$networkconstid) : '').'">';
  108. print '</td><td>';
  109. print '<input name="'.$key.'url" id="'.$key.'url" class="minwidth300" value="'.(!empty($conf->global->$networkconstname) ? dol_escape_htmltag($conf->global->$networkconstname) : '').'">';
  110. print '</td>';
  111. print '<td class="nowraponall">'.dol_print_socialnetworks((!empty($conf->global->$networkconstid) ? dol_escape_htmltag($conf->global->$networkconstid) : ''), 0, 0, $key, $listofnetworks).'</td>';
  112. print '</tr>'."\n";
  113. }
  114. }
  115. print "</table>";
  116. print '</div>';
  117. print $form->buttonsSaveCancel("Save", '');
  118. print '</form>';
  119. // End of page
  120. llxFooter();
  121. $db->close();