type_ldap.php 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  1. <?php
  2. /* Copyright (C) 2006-2012 Laurent Destailleur <eldy@users.sourceforge.net>
  3. * Copyright (C) 2006-2017 Regis Houssin <regis.houssin@inodbox.com>
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation; either version 3 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  17. */
  18. /**
  19. * \file htdocs/adherents/type_ldap.php
  20. * \ingroup ldap
  21. * \brief Page fiche LDAP members types
  22. */
  23. // Load Dolibarr environment
  24. require '../main.inc.php';
  25. require_once DOL_DOCUMENT_ROOT.'/core/lib/member.lib.php';
  26. require_once DOL_DOCUMENT_ROOT.'/adherents/class/adherent.class.php';
  27. require_once DOL_DOCUMENT_ROOT.'/adherents/class/adherent_type.class.php';
  28. require_once DOL_DOCUMENT_ROOT.'/core/class/ldap.class.php';
  29. require_once DOL_DOCUMENT_ROOT.'/core/lib/ldap.lib.php';
  30. // Load translation files required by the page
  31. $langs->loadLangs(array("admin", "members", "ldap"));
  32. $id = GETPOST('rowid', 'int');
  33. $action = GETPOST('action', 'aZ09');
  34. // Security check
  35. $result = restrictedArea($user, 'adherent', $id, 'adherent_type');
  36. $object = new AdherentType($db);
  37. $object->fetch($id);
  38. // Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context
  39. $hookmanager->initHooks(array('membertypeldapcard', 'globalcard'));
  40. /*
  41. * Actions
  42. */
  43. $parameters = array();
  44. $reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
  45. if ($reshook < 0) {
  46. setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
  47. }
  48. if (empty($reshook)) {
  49. if ($action == 'dolibarr2ldap') {
  50. $ldap = new Ldap();
  51. $result = $ldap->connect_bind();
  52. if ($result > 0) {
  53. $object->listMembersForMemberType('', 1);
  54. $info = $object->_load_ldap_info();
  55. $dn = $object->_load_ldap_dn($info);
  56. $olddn = $dn; // We can say that old dn = dn as we force synchro
  57. $result = $ldap->update($dn, $info, $user, $olddn);
  58. }
  59. if ($result >= 0) {
  60. setEventMessages($langs->trans("MemberTypeSynchronized"), null, 'mesgs');
  61. } else {
  62. setEventMessages($ldap->error, $ldap->errors, 'errors');
  63. }
  64. }
  65. }
  66. /*
  67. * View
  68. */
  69. llxHeader();
  70. $form = new Form($db);
  71. $head = member_type_prepare_head($object);
  72. print dol_get_fiche_head($head, 'ldap', $langs->trans("MemberType"), -1, 'group');
  73. $linkback = '<a href="'.DOL_URL_ROOT.'/adherents/type.php?restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>';
  74. dol_banner_tab($object, 'rowid', $linkback);
  75. print '<div class="fichecenter">';
  76. print '<div class="underbanner clearboth"></div>';
  77. print '<table class="border centpercent">';
  78. // LDAP DN
  79. print '<tr><td>LDAP '.$langs->trans("LDAPMemberTypeDn").'</td><td class="valeur">'.$conf->global->LDAP_MEMBER_TYPE_DN."</td></tr>\n";
  80. // LDAP Cle
  81. print '<tr><td>LDAP '.$langs->trans("LDAPNamingAttribute").'</td><td class="valeur">'.$conf->global->LDAP_KEY_MEMBERS_TYPES."</td></tr>\n";
  82. // LDAP Server
  83. print '<tr><td>LDAP '.$langs->trans("Type").'</td><td class="valeur">'.$conf->global->LDAP_SERVER_TYPE."</td></tr>\n";
  84. print '<tr><td>LDAP '.$langs->trans("Version").'</td><td class="valeur">'.$conf->global->LDAP_SERVER_PROTOCOLVERSION."</td></tr>\n";
  85. print '<tr><td>LDAP '.$langs->trans("LDAPPrimaryServer").'</td><td class="valeur">'.$conf->global->LDAP_SERVER_HOST."</td></tr>\n";
  86. print '<tr><td>LDAP '.$langs->trans("LDAPSecondaryServer").'</td><td class="valeur">'.$conf->global->LDAP_SERVER_HOST_SLAVE."</td></tr>\n";
  87. print '<tr><td>LDAP '.$langs->trans("LDAPServerPort").'</td><td class="valeur">'.$conf->global->LDAP_SERVER_PORT."</td></tr>\n";
  88. print '</table>';
  89. print '</div>';
  90. print dol_get_fiche_end();
  91. /*
  92. * Action bar
  93. */
  94. print '<div class="tabsAction">';
  95. if (getDolGlobalInt('LDAP_MEMBER_TYPE_ACTIVE') === Ldap::SYNCHRO_DOLIBARR_TO_LDAP) {
  96. print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?rowid='.$object->id.'&action=dolibarr2ldap">'.$langs->trans("ForceSynchronize").'</a>';
  97. }
  98. print "</div>\n";
  99. if (getDolGlobalInt('LDAP_MEMBER_TYPE_ACTIVE') === Ldap::SYNCHRO_DOLIBARR_TO_LDAP) {
  100. print "<br>\n";
  101. }
  102. // Display LDAP attributes
  103. print load_fiche_titre($langs->trans("LDAPInformationsForThisMemberType"));
  104. print '<table width="100%" class="noborder">';
  105. print '<tr class="liste_titre">';
  106. print '<td>'.$langs->trans("LDAPAttributes").'</td>';
  107. print '<td>'.$langs->trans("Value").'</td>';
  108. print '</tr>';
  109. // LDAP reading
  110. $ldap = new Ldap();
  111. $result = $ldap->connect_bind();
  112. if ($result > 0) {
  113. $info = $object->_load_ldap_info();
  114. $dn = $object->_load_ldap_dn($info, 1);
  115. $search = "(".$object->_load_ldap_dn($info, 2).")";
  116. $records = $ldap->getAttribute($dn, $search);
  117. //print_r($records);
  118. // Show tree
  119. if (((!is_numeric($records)) || $records != 0) && (!isset($records['count']) || $records['count'] > 0)) {
  120. if (!is_array($records)) {
  121. print '<tr class="oddeven"><td colspan="2"><span class="error">'.$langs->trans("ErrorFailedToReadLDAP").'</span></td></tr>';
  122. } else {
  123. $result = show_ldap_content($records, 0, $records['count'], true);
  124. }
  125. } else {
  126. print '<tr class="oddeven"><td colspan="2">'.$langs->trans("LDAPRecordNotFound").' (dn='.dol_escape_htmltag($dn).' - search='.dol_escape_htmltag($search).')</td></tr>';
  127. }
  128. $ldap->unbind();
  129. } else {
  130. setEventMessages($ldap->error, $ldap->errors, 'errors');
  131. }
  132. print '</table>';
  133. // End of page
  134. llxFooter();
  135. $db->close();