PageRenderTime 49ms CodeModel.GetById 10ms RepoModel.GetById 0ms app.codeStats 0ms

/htdocs/contact/ldap.php

https://github.com/asterix14/dolibarr
PHP | 212 lines | 115 code | 55 blank | 42 comment | 19 complexity | 3a79718a506ee80d85afa22332af6c02 MD5 | raw file
Possible License(s): LGPL-2.0
  1. <?php
  2. /* Copyright (C) 2006-2010 Laurent Destailleur <eldy@users.sourceforge.net>
  3. * Copyright (C) 2006 Regis Houssin <regis@dolibarr.fr>
  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 2 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/contact/ldap.php
  20. * \ingroup ldap
  21. * \brief Page fiche LDAP contact
  22. */
  23. require("../main.inc.php");
  24. require_once(DOL_DOCUMENT_ROOT."/contact/class/contact.class.php");
  25. require_once(DOL_DOCUMENT_ROOT."/core/lib/contact.lib.php");
  26. require_once(DOL_DOCUMENT_ROOT."/core/class/ldap.class.php");
  27. require_once(DOL_DOCUMENT_ROOT."/core/lib/ldap.lib.php");
  28. $langs->load("companies");
  29. $langs->load("ldap");
  30. $langs->load("admin");
  31. // Security check
  32. $contactid = isset($_GET["id"])?$_GET["id"]:'';
  33. if ($user->societe_id) $socid=$user->societe_id;
  34. $result = restrictedArea($user, 'contact', $contactid, 'socpeople');
  35. $contact = new Contact($db);
  36. $contact->fetch($_GET["id"], $user);
  37. /*
  38. * Actions
  39. */
  40. if ($_GET["action"] == 'dolibarr2ldap')
  41. {
  42. $message="";
  43. $db->begin();
  44. $ldap=new Ldap();
  45. $result=$ldap->connect_bind();
  46. $info=$contact->_load_ldap_info();
  47. $dn=$contact->_load_ldap_dn($info);
  48. $olddn=$dn; // We can say that old dn = dn as we force synchro
  49. $result=$ldap->update($dn,$info,$user,$olddn);
  50. if ($result >= 0)
  51. {
  52. $message.='<div class="ok">'.$langs->trans("ContactSynchronized").'</div>';
  53. $db->commit();
  54. }
  55. else
  56. {
  57. $message.='<div class="error">'.$ldap->error.'</div>';
  58. $db->rollback();
  59. }
  60. }
  61. /*
  62. * View
  63. */
  64. llxHeader('',$langs->trans("ContactsAddresses"),'EN:Module_Third_Parties|FR:Module_Tiers|ES:M&oacute;dulo_Empresas');
  65. $form = new Form($db);
  66. $head = contact_prepare_head($contact);
  67. dol_fiche_head($head, 'ldap', $langs->trans("ContactsAddresses"), 0, 'contact');
  68. print '<table class="border" width="100%">';
  69. // Ref
  70. print '<tr><td width="20%">'.$langs->trans("Ref").'</td><td colspan="3">';
  71. print $form->showrefnav($contact,'id');
  72. print '</td></tr>';
  73. // Name
  74. print '<tr><td>'.$langs->trans("Lastname").' / '.$langs->trans("Label").'</td><td>'.$contact->name.'</td>';
  75. print '<td>'.$langs->trans("Firstname").'</td><td width="25%">'.$contact->firstname.'</td></tr>';
  76. // Company
  77. if ($contact->socid > 0)
  78. {
  79. $objsoc = new Societe($db);
  80. $objsoc->fetch($contact->socid);
  81. print '<tr><td width="20%">'.$langs->trans("Company").'</td><td colspan="3">'.$objsoc->getNomUrl(1).'</td></tr>';
  82. }
  83. else
  84. {
  85. print '<tr><td width="20%">'.$langs->trans("Company").'</td><td colspan="3">';
  86. print $langs->trans("ContactNotLinkedToCompany");
  87. print '</td></tr>';
  88. }
  89. // Civility
  90. print '<tr><td>'.$langs->trans("UserTitle").'</td><td colspan="3">';
  91. print $contact->getCivilityLabel();
  92. print '</td></tr>';
  93. // LDAP DN
  94. print '<tr><td>LDAP '.$langs->trans("LDAPContactDn").'</td><td class="valeur" colspan="3">'.$conf->global->LDAP_CONTACT_DN."</td></tr>\n";
  95. // LDAP Cle
  96. print '<tr><td>LDAP '.$langs->trans("LDAPNamingAttribute").'</td><td class="valeur" colspan="3">'.$conf->global->LDAP_KEY_CONTACTS."</td></tr>\n";
  97. // LDAP Server
  98. print '<tr><td>LDAP '.$langs->trans("LDAPPrimaryServer").'</td><td class="valeur" colspan="3">'.$conf->global->LDAP_SERVER_HOST."</td></tr>\n";
  99. print '<tr><td>LDAP '.$langs->trans("LDAPSecondaryServer").'</td><td class="valeur" colspan="3">'.$conf->global->LDAP_SERVER_HOST_SLAVE."</td></tr>\n";
  100. print '<tr><td>LDAP '.$langs->trans("LDAPServerPort").'</td><td class="valeur" colspan="3">'.$conf->global->LDAP_SERVER_PORT."</td></tr>\n";
  101. print '</table>';
  102. print '</div>';
  103. if ($message) { print $message; }
  104. /*
  105. * Barre d'actions
  106. */
  107. print '<div class="tabsAction">';
  108. if (! empty($conf->global->LDAP_CONTACT_ACTIVE) && $conf->global->LDAP_CONTACT_ACTIVE != 'ldap2dolibarr')
  109. {
  110. print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?id='.$contact->id.'&amp;action=dolibarr2ldap">'.$langs->trans("ForceSynchronize").'</a>';
  111. }
  112. print "</div>\n";
  113. if (! empty($conf->global->LDAP_CONTACT_ACTIVE) && $conf->global->LDAP_CONTACT_ACTIVE != 'ldap2dolibarr') print "<br>\n";
  114. // Affichage attributs LDAP
  115. print_titre($langs->trans("LDAPInformationsForThisContact"));
  116. print '<table width="100%" class="noborder">';
  117. print '<tr class="liste_titre">';
  118. print '<td>'.$langs->trans("LDAPAttributes").'</td>';
  119. print '<td>'.$langs->trans("Value").'</td>';
  120. print '</tr>';
  121. // Lecture LDAP
  122. $ldap=new Ldap();
  123. $result=$ldap->connect_bind();
  124. if ($result > 0)
  125. {
  126. $info=$contact->_load_ldap_info();
  127. $dn=$contact->_load_ldap_dn($info,1);
  128. $search = "(".$contact->_load_ldap_dn($info,2).")";
  129. $records=$ldap->getAttribute($dn,$search);
  130. //var_dump($records);
  131. // Affichage arbre
  132. if (count($records) && $records != false && (! isset($records['count']) || $records['count'] > 0))
  133. {
  134. if (! is_array($records))
  135. {
  136. print '<tr '.$bc[false].'><td colspan="2"><font class="error">'.$langs->trans("ErrorFailedToReadLDAP").'</font></td></tr>';
  137. }
  138. else
  139. {
  140. $result=show_ldap_content($records,0,$records['count'],true);
  141. }
  142. }
  143. else
  144. {
  145. print '<tr '.$bc[false].'><td colspan="2">'.$langs->trans("LDAPRecordNotFound").' (dn='.$dn.' - search='.$search.')</td></tr>';
  146. }
  147. $ldap->unbind();
  148. $ldap->close();
  149. }
  150. else
  151. {
  152. dol_print_error('',$ldap->error);
  153. }
  154. print '</table>';
  155. $db->close();
  156. llxFooter();
  157. ?>