type_ldap.php 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  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', 'alpha');
  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) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
  45. if (empty($reshook))
  46. {
  47. if ($action == 'dolibarr2ldap')
  48. {
  49. $ldap = new Ldap();
  50. $result = $ldap->connect_bind();
  51. if ($result > 0)
  52. {
  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. }
  62. else {
  63. setEventMessages($ldap->error, $ldap->errors, 'errors');
  64. }
  65. }
  66. }
  67. /*
  68. * View
  69. */
  70. llxHeader();
  71. $form = new Form($db);
  72. $head = member_type_prepare_head($object);
  73. dol_fiche_head($head, 'ldap', $langs->trans("MemberType"), -1, 'group');
  74. $linkback = '<a href="'.DOL_URL_ROOT.'/adherents/type.php?restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>';
  75. dol_banner_tab($object, 'rowid', $linkback);
  76. print '<div class="fichecenter">';
  77. print '<div class="underbanner clearboth"></div>';
  78. print '<table class="border" width="100%">';
  79. // LDAP DN
  80. print '<tr><td>LDAP '.$langs->trans("LDAPMemberTypeDn").'</td><td class="valeur">'.$conf->global->LDAP_MEMBER_TYPE_DN."</td></tr>\n";
  81. // LDAP Cle
  82. print '<tr><td>LDAP '.$langs->trans("LDAPNamingAttribute").'</td><td class="valeur">'.$conf->global->LDAP_KEY_MEMBERS_TYPES."</td></tr>\n";
  83. // LDAP Server
  84. print '<tr><td>LDAP '.$langs->trans("Type").'</td><td class="valeur">'.$conf->global->LDAP_SERVER_TYPE."</td></tr>\n";
  85. print '<tr><td>LDAP '.$langs->trans("Version").'</td><td class="valeur">'.$conf->global->LDAP_SERVER_PROTOCOLVERSION."</td></tr>\n";
  86. print '<tr><td>LDAP '.$langs->trans("LDAPPrimaryServer").'</td><td class="valeur">'.$conf->global->LDAP_SERVER_HOST."</td></tr>\n";
  87. print '<tr><td>LDAP '.$langs->trans("LDAPSecondaryServer").'</td><td class="valeur">'.$conf->global->LDAP_SERVER_HOST_SLAVE."</td></tr>\n";
  88. print '<tr><td>LDAP '.$langs->trans("LDAPServerPort").'</td><td class="valeur">'.$conf->global->LDAP_SERVER_PORT."</td></tr>\n";
  89. print '</table>';
  90. print '</div>';
  91. dol_fiche_end();
  92. /*
  93. * Barre d'actions
  94. */
  95. print '<div class="tabsAction">';
  96. if ($conf->global->LDAP_MEMBER_TYPE_ACTIVE == 1)
  97. {
  98. print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?rowid='.$object->id.'&action=dolibarr2ldap">'.$langs->trans("ForceSynchronize").'</a>';
  99. }
  100. print "</div>\n";
  101. if ($conf->global->LDAP_MEMBER_TYPE_ACTIVE == 1) print "<br>\n";
  102. // Affichage attributs LDAP
  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. // Lecture LDAP
  110. $ldap=new Ldap();
  111. $result=$ldap->connect_bind();
  112. if ($result > 0)
  113. {
  114. $info=$object->_load_ldap_info();
  115. $dn=$object->_load_ldap_dn($info, 1);
  116. $search = "(".$object->_load_ldap_dn($info, 2).")";
  117. $records = $ldap->getAttribute($dn, $search);
  118. //print_r($records);
  119. // Show tree
  120. if (((! is_numeric($records)) || $records != 0) && (! isset($records['count']) || $records['count'] > 0))
  121. {
  122. if (! is_array($records))
  123. {
  124. print '<tr class="oddeven"><td colspan="2"><font class="error">'.$langs->trans("ErrorFailedToReadLDAP").'</font></td></tr>';
  125. }
  126. else
  127. {
  128. $result=show_ldap_content($records, 0, $records['count'], true);
  129. }
  130. }
  131. else
  132. {
  133. print '<tr class="oddeven"><td colspan="2">'.$langs->trans("LDAPRecordNotFound").' (dn='.$dn.' - search='.$search.')</td></tr>';
  134. }
  135. $ldap->unbind();
  136. $ldap->close();
  137. }
  138. else
  139. {
  140. setEventMessages($ldap->error, $ldap->errors, 'errors');
  141. }
  142. print '</table>';
  143. // End of page
  144. llxFooter();
  145. $db->close();