ldap.php 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  1. <?php
  2. /* Copyright (C) 2006-2010 Laurent Destailleur <eldy@users.sourceforge.net>
  3. * Copyright (C) 2006-2012 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/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. $action=GETPOST('action','aZ09');
  32. // Security check
  33. $id = GETPOST('id', 'int');
  34. if ($user->societe_id) $socid=$user->societe_id;
  35. $result = restrictedArea($user, 'contact', $id, 'socpeople&societe');
  36. $object = new Contact($db);
  37. if ($id > 0)
  38. {
  39. $object->fetch($id, $user);
  40. }
  41. /*
  42. * Actions
  43. */
  44. if ($action == 'dolibarr2ldap')
  45. {
  46. $db->begin();
  47. $ldap=new Ldap();
  48. $result=$ldap->connect_bind();
  49. $info=$object->_load_ldap_info();
  50. $dn=$object->_load_ldap_dn($info);
  51. $olddn=$dn; // We can say that old dn = dn as we force synchro
  52. $result=$ldap->update($dn,$info,$user,$olddn);
  53. if ($result >= 0)
  54. {
  55. setEventMessages($langs->trans("ContactSynchronized"), null, 'mesgs');
  56. $db->commit();
  57. }
  58. else
  59. {
  60. setEventMessages($ldap->error, $ldap->errors, 'errors');
  61. $db->rollback();
  62. }
  63. }
  64. /*
  65. * View
  66. */
  67. $title = (! empty($conf->global->SOCIETE_ADDRESSES_MANAGEMENT) ? $langs->trans("Contacts") : $langs->trans("ContactsAddresses"));
  68. llxHeader('',$title,'EN:Module_Third_Parties|FR:Module_Tiers|ES:M&oacute;dulo_Empresas');
  69. $form = new Form($db);
  70. $head = contact_prepare_head($object);
  71. dol_fiche_head($head, 'ldap', $title, -1, 'contact');
  72. dol_banner_tab($object, 'id', $linkback, 1, 'rowid', 'ref', '');
  73. print '<div class="fichecenter">';
  74. print '<div class="underbanner clearboth"></div>';
  75. print '<table class="border centpercent">';
  76. // Company
  77. if ($object->socid > 0)
  78. {
  79. $thirdparty = new Societe($db);
  80. $thirdparty->fetch($object->socid);
  81. print '<tr><td class="titlefield">'.$langs->trans("ThirdParty").'</td><td colspan="3">'.$thirdparty->getNomUrl(1).'</td></tr>';
  82. }
  83. else
  84. {
  85. print '<tr><td class="titlefield">'.$langs->trans("ThirdParty").'</td><td colspan="3">';
  86. print $langs->trans("ContactNotLinkedToCompany");
  87. print '</td></tr>';
  88. }
  89. // Civility
  90. print '<tr><td class="titlefield">'.$langs->trans("UserTitle").'</td><td colspan="3">';
  91. print $object->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. dol_fiche_end();
  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='.$object->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 load_fiche_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=$object->_load_ldap_info();
  127. $dn=$object->_load_ldap_dn($info,1);
  128. $search = "(".$object->_load_ldap_dn($info,2).")";
  129. $records = $ldap->getAttribute($dn,$search);
  130. //var_dump($records);
  131. // Affichage arbre
  132. if ((! is_numeric($records) || $records != 0) && (! 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. llxFooter();
  156. $db->close();