PageRenderTime 41ms CodeModel.GetById 15ms RepoModel.GetById 0ms app.codeStats 0ms

/htdocs/adherent/ldap.php

https://bitbucket.org/speedealing/speedealing
PHP | 244 lines | 140 code | 59 blank | 45 comment | 21 complexity | 4868e4b3337131a66f7c9eedcd821c37 MD5 | raw file
Possible License(s): LGPL-3.0, LGPL-2.1, GPL-3.0, MIT
  1. <?php
  2. /* Copyright (C) 2006 Laurent Destailleur <eldy@users.sourceforge.net>
  3. * Copyright (C) 2006 Regis Houssin <regis.houssin@capnetworks.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 <http://www.gnu.org/licenses/>.
  17. */
  18. /**
  19. * \file htdocs/adherents/ldap.php
  20. * \ingroup ldap member
  21. * \brief Page fiche LDAP adherent
  22. */
  23. require '../main.inc.php';
  24. require_once DOL_DOCUMENT_ROOT.'/core/lib/member.lib.php';
  25. require_once DOL_DOCUMENT_ROOT.'/core/lib/ldap.lib.php';
  26. require_once DOL_DOCUMENT_ROOT.'/core/class/ldap.class.php';
  27. require_once DOL_DOCUMENT_ROOT.'/adherents/class/adherent.class.php';
  28. require_once DOL_DOCUMENT_ROOT.'/adherents/class/adherent_type.class.php';
  29. $langs->load("companies");
  30. $langs->load("members");
  31. $langs->load("ldap");
  32. $langs->load("admin");
  33. $rowid = GETPOST('id','int');
  34. $action = GETPOST('action');
  35. // Protection
  36. $socid=0;
  37. if ($user->societe_id > 0)
  38. {
  39. $socid = $user->societe_id;
  40. }
  41. $adh = new Adherent($db);
  42. $adh->id = $rowid;
  43. $result=$adh->fetch($rowid);
  44. if (! $result)
  45. {
  46. dol_print_error($db,"Failed to get adherent: ".$adh->error);
  47. exit;
  48. }
  49. /*
  50. * Actions
  51. */
  52. if ($action == 'dolibarr2ldap')
  53. {
  54. $message="";
  55. $db->begin();
  56. $ldap=new Ldap();
  57. $result=$ldap->connect_bind();
  58. $info=$adh->_load_ldap_info();
  59. $dn=$adh->_load_ldap_dn($info);
  60. $olddn=$dn; // We can say that old dn = dn as we force synchro
  61. $result=$ldap->update($dn,$info,$user,$olddn);
  62. if ($result >= 0)
  63. {
  64. $message.='<div class="ok">'.$langs->trans("MemberSynchronized").'</div>';
  65. $db->commit();
  66. }
  67. else
  68. {
  69. $message.='<div class="error">'.$ldap->error.'</div>';
  70. $db->rollback();
  71. }
  72. }
  73. /*
  74. * View
  75. */
  76. llxHeader('',$langs->trans("Member"),'EN:Module_Foundations|FR:Module_Adh&eacute;rents|ES:M&oacute;dulo_Miembros');
  77. $form = new Form($db);
  78. $head = member_prepare_head($adh);
  79. dol_fiche_head($head, 'ldap', $langs->trans("Member"), 0, 'user');
  80. print '<table class="border" width="100%">';
  81. // Ref
  82. print '<tr><td width="20%">'.$langs->trans("Ref").'</td>';
  83. print '<td class="valeur">';
  84. print $form->showrefnav($adh,'id');
  85. print '</td></tr>';
  86. // Nom
  87. print '<tr><td>'.$langs->trans("Lastname").'</td><td class="valeur">'.$adh->lastname.'&nbsp;</td>';
  88. print '</tr>';
  89. // Prenom
  90. print '<tr><td width="15%">'.$langs->trans("Firstname").'</td><td class="valeur">'.$adh->firstname.'&nbsp;</td>';
  91. print '</tr>';
  92. // Login
  93. print '<tr><td>'.$langs->trans("Login").'</td><td class="valeur">'.$adh->login.'&nbsp;</td></tr>';
  94. // Password not crypted
  95. if (! empty($conf->global->LDAP_MEMBER_FIELD_PASSWORD))
  96. {
  97. print '<tr><td>'.$langs->trans("LDAPFieldPasswordNotCrypted").'</td>';
  98. print '<td class="valeur">'.$adh->pass.'</td>';
  99. print "</tr>\n";
  100. }
  101. // Password crypted
  102. if (! empty($conf->global->LDAP_MEMBER_FIELD_PASSWORD_CRYPTED))
  103. {
  104. print '<tr><td>'.$langs->trans("LDAPFieldPasswordCrypted").'</td>';
  105. print '<td class="valeur">'.$adh->pass_crypted.'</td>';
  106. print "</tr>\n";
  107. }
  108. // Type
  109. print '<tr><td>'.$langs->trans("Type").'</td><td class="valeur">'.$adh->type."</td></tr>\n";
  110. $langs->load("admin");
  111. // LDAP DN
  112. print '<tr><td>LDAP '.$langs->trans("LDAPMemberDn").'</td><td class="valeur">'.$conf->global->LDAP_MEMBER_DN."</td></tr>\n";
  113. // LDAP Cle
  114. print '<tr><td>LDAP '.$langs->trans("LDAPNamingAttribute").'</td><td class="valeur">'.$conf->global->LDAP_KEY_MEMBERS."</td></tr>\n";
  115. // LDAP Server
  116. print '<tr><td>LDAP '.$langs->trans("Type").'</td><td class="valeur">'.$conf->global->LDAP_SERVER_TYPE."</td></tr>\n";
  117. print '<tr><td>LDAP '.$langs->trans("Version").'</td><td class="valeur">'.$conf->global->LDAP_SERVER_PROTOCOLVERSION."</td></tr>\n";
  118. print '<tr><td>LDAP '.$langs->trans("LDAPPrimaryServer").'</td><td class="valeur">'.$conf->global->LDAP_SERVER_HOST."</td></tr>\n";
  119. print '<tr><td>LDAP '.$langs->trans("LDAPSecondaryServer").'</td><td class="valeur">'.$conf->global->LDAP_SERVER_HOST_SLAVE."</td></tr>\n";
  120. print '<tr><td>LDAP '.$langs->trans("LDAPServerPort").'</td><td class="valeur">'.$conf->global->LDAP_SERVER_PORT."</td></tr>\n";
  121. print '</table>';
  122. print '</div>';
  123. dol_htmloutput_mesg($message);
  124. /*
  125. * Barre d'actions
  126. */
  127. print '<div class="tabsAction">';
  128. if (! empty($conf->global->LDAP_MEMBER_ACTIVE) && $conf->global->LDAP_MEMBER_ACTIVE != 'ldap2dolibarr')
  129. {
  130. print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?id='.$adh->id.'&amp;action=dolibarr2ldap">'.$langs->trans("ForceSynchronize").'</a>';
  131. }
  132. print "</div>\n";
  133. if (! empty($conf->global->LDAP_MEMBER_ACTIVE) && $conf->global->LDAP_MEMBER_ACTIVE != 'ldap2dolibarr') print "<br>\n";
  134. // Affichage attributs LDAP
  135. print_titre($langs->trans("LDAPInformationsForThisMember"));
  136. print '<table width="100%" class="noborder">';
  137. print '<tr class="liste_titre">';
  138. print '<td>'.$langs->trans("LDAPAttributes").'</td>';
  139. print '<td>'.$langs->trans("Value").'</td>';
  140. print '</tr>';
  141. // Lecture LDAP
  142. $ldap=new Ldap();
  143. $result=$ldap->connect_bind();
  144. if ($result > 0)
  145. {
  146. $info=$adh->_load_ldap_info();
  147. $dn=$adh->_load_ldap_dn($info,1);
  148. $search = "(".$adh->_load_ldap_dn($info,2).")";
  149. if (empty($dn))
  150. {
  151. $langs->load("errors");
  152. print '<tr '.$bc[false].'><td colspan="2"><font class="error">'.$langs->trans("ErrorModuleSetupNotComplete").'</font></td></tr>';
  153. }
  154. else
  155. {
  156. $records=$ldap->getAttribute($dn,$search);
  157. //print_r($records);
  158. // Affichage arbre
  159. if (count($records) && $records != false && (! isset($records['count']) || $records['count'] > 0))
  160. {
  161. if (! is_array($records))
  162. {
  163. print '<tr '.$bc[false].'><td colspan="2"><font class="error">'.$langs->trans("ErrorFailedToReadLDAP").'</font></td></tr>';
  164. }
  165. else
  166. {
  167. $result=show_ldap_content($records,0,$records['count'],true);
  168. }
  169. }
  170. else
  171. {
  172. print '<tr '.$bc[false].'><td colspan="2">'.$langs->trans("LDAPRecordNotFound").' (dn='.$dn.' - search='.$search.')</td></tr>';
  173. }
  174. }
  175. $ldap->unbind();
  176. $ldap->close();
  177. }
  178. else
  179. {
  180. dol_print_error('',$ldap->error);
  181. }
  182. print '</table>';
  183. llxFooter();
  184. $db->close();
  185. ?>