type_ldap.php 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  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. require '../main.inc.php';
  24. require_once DOL_DOCUMENT_ROOT.'/core/lib/member.lib.php';
  25. require_once DOL_DOCUMENT_ROOT.'/adherents/class/adherent.class.php';
  26. require_once DOL_DOCUMENT_ROOT.'/adherents/class/adherent_type.class.php';
  27. require_once DOL_DOCUMENT_ROOT.'/core/class/ldap.class.php';
  28. require_once DOL_DOCUMENT_ROOT.'/core/lib/ldap.lib.php';
  29. // Load translation files required by the page
  30. $langs->loadLangs(array("admin", "members", "ldap"));
  31. $id = GETPOST('rowid', 'int');
  32. $action = GETPOST('action', 'aZ09');
  33. // Security check
  34. $result = restrictedArea($user, 'adherent', $id, 'adherent_type');
  35. $object = new AdherentType($db);
  36. $object->fetch($id);
  37. // Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context
  38. $hookmanager->initHooks(array('membertypeldapcard', 'globalcard'));
  39. /*
  40. * Actions
  41. */
  42. $parameters = array();
  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 == 'dolibarr2ldap') {
  49. $ldap = new Ldap();
  50. $result = $ldap->connect_bind();
  51. if ($result > 0) {
  52. $object->listMembersForMemberType('', 1);
  53. $info = $object->_load_ldap_info();
  54. $dn = $object->_load_ldap_dn($info);
  55. $olddn = $dn; // We can say that old dn = dn as we force synchro
  56. $result = $ldap->update($dn, $info, $user, $olddn);
  57. }
  58. if ($result >= 0) {
  59. setEventMessages($langs->trans("MemberTypeSynchronized"), null, 'mesgs');
  60. } else {
  61. setEventMessages($ldap->error, $ldap->errors, 'errors');
  62. }
  63. }
  64. }
  65. /*
  66. * View
  67. */
  68. llxHeader();
  69. $form = new Form($db);
  70. $head = member_type_prepare_head($object);
  71. print dol_get_fiche_head($head, 'ldap', $langs->trans("MemberType"), -1, 'group');
  72. $linkback = '<a href="'.DOL_URL_ROOT.'/adherents/type.php?restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>';
  73. dol_banner_tab($object, 'rowid', $linkback);
  74. print '<div class="fichecenter">';
  75. print '<div class="underbanner clearboth"></div>';
  76. print '<table class="border centpercent">';
  77. // LDAP DN
  78. print '<tr><td>LDAP '.$langs->trans("LDAPMemberTypeDn").'</td><td class="valeur">'.$conf->global->LDAP_MEMBER_TYPE_DN."</td></tr>\n";
  79. // LDAP Cle
  80. print '<tr><td>LDAP '.$langs->trans("LDAPNamingAttribute").'</td><td class="valeur">'.$conf->global->LDAP_KEY_MEMBERS_TYPES."</td></tr>\n";
  81. // LDAP Server
  82. print '<tr><td>LDAP '.$langs->trans("Type").'</td><td class="valeur">'.$conf->global->LDAP_SERVER_TYPE."</td></tr>\n";
  83. print '<tr><td>LDAP '.$langs->trans("Version").'</td><td class="valeur">'.$conf->global->LDAP_SERVER_PROTOCOLVERSION."</td></tr>\n";
  84. print '<tr><td>LDAP '.$langs->trans("LDAPPrimaryServer").'</td><td class="valeur">'.$conf->global->LDAP_SERVER_HOST."</td></tr>\n";
  85. print '<tr><td>LDAP '.$langs->trans("LDAPSecondaryServer").'</td><td class="valeur">'.$conf->global->LDAP_SERVER_HOST_SLAVE."</td></tr>\n";
  86. print '<tr><td>LDAP '.$langs->trans("LDAPServerPort").'</td><td class="valeur">'.$conf->global->LDAP_SERVER_PORT."</td></tr>\n";
  87. print '</table>';
  88. print '</div>';
  89. print dol_get_fiche_end();
  90. /*
  91. * Action bar
  92. */
  93. print '<div class="tabsAction">';
  94. if (getDolGlobalInt('LDAP_MEMBER_TYPE_ACTIVE') === Ldap::SYNCHRO_DOLIBARR_TO_LDAP) {
  95. print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?rowid='.$object->id.'&action=dolibarr2ldap">'.$langs->trans("ForceSynchronize").'</a>';
  96. }
  97. print "</div>\n";
  98. if (getDolGlobalInt('LDAP_MEMBER_TYPE_ACTIVE') === Ldap::SYNCHRO_DOLIBARR_TO_LDAP) {
  99. print "<br>\n";
  100. }
  101. // Display LDAP attributes
  102. print load_fiche_titre($langs->trans("LDAPInformationsForThisMemberType"));
  103. print '<table width="100%" class="noborder">';
  104. print '<tr class="liste_titre">';
  105. print '<td>'.$langs->trans("LDAPAttributes").'</td>';
  106. print '<td>'.$langs->trans("Value").'</td>';
  107. print '</tr>';
  108. // LDAP reading
  109. $ldap = new Ldap();
  110. $result = $ldap->connect_bind();
  111. if ($result > 0) {
  112. $info = $object->_load_ldap_info();
  113. $dn = $object->_load_ldap_dn($info, 1);
  114. $search = "(".$object->_load_ldap_dn($info, 2).")";
  115. $records = $ldap->getAttribute($dn, $search);
  116. //print_r($records);
  117. // Show tree
  118. if (((!is_numeric($records)) || $records != 0) && (!isset($records['count']) || $records['count'] > 0)) {
  119. if (!is_array($records)) {
  120. print '<tr class="oddeven"><td colspan="2"><span class="error">'.$langs->trans("ErrorFailedToReadLDAP").'</span></td></tr>';
  121. } else {
  122. $result = show_ldap_content($records, 0, $records['count'], true);
  123. }
  124. } else {
  125. print '<tr class="oddeven"><td colspan="2">'.$langs->trans("LDAPRecordNotFound").' (dn='.dol_escape_htmltag($dn).' - search='.dol_escape_htmltag($search).')</td></tr>';
  126. }
  127. $ldap->unbind();
  128. } else {
  129. setEventMessages($ldap->error, $ldap->errors, 'errors');
  130. }
  131. print '</table>';
  132. // End of page
  133. llxFooter();
  134. $db->close();