ldap.php 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  1. <?php
  2. /* Copyright (C) 2006-2010 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 <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. // Load translation files required by the page
  29. $langs->loadLangs(array('companies', '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. $linkback = '<a href="'.DOL_URL_ROOT.'/contact/list.php?restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>';
  73. dol_banner_tab($object, 'id', $linkback, 1, 'rowid', 'ref', '');
  74. print '<div class="fichecenter">';
  75. print '<div class="underbanner clearboth"></div>';
  76. print '<table class="border centpercent">';
  77. // Company
  78. if ($object->socid > 0)
  79. {
  80. $thirdparty = new Societe($db);
  81. $thirdparty->fetch($object->socid);
  82. print '<tr><td class="titlefield">'.$langs->trans("ThirdParty").'</td><td colspan="3">'.$thirdparty->getNomUrl(1).'</td></tr>';
  83. }
  84. else
  85. {
  86. print '<tr><td class="titlefield">'.$langs->trans("ThirdParty").'</td><td colspan="3">';
  87. print $langs->trans("ContactNotLinkedToCompany");
  88. print '</td></tr>';
  89. }
  90. // Civility
  91. print '<tr><td class="titlefield">'.$langs->trans("UserTitle").'</td><td colspan="3">';
  92. print $object->getCivilityLabel();
  93. print '</td></tr>';
  94. // LDAP DN
  95. print '<tr><td>LDAP '.$langs->trans("LDAPContactDn").'</td><td class="valeur" colspan="3">'.$conf->global->LDAP_CONTACT_DN."</td></tr>\n";
  96. // LDAP Cle
  97. print '<tr><td>LDAP '.$langs->trans("LDAPNamingAttribute").'</td><td class="valeur" colspan="3">'.$conf->global->LDAP_KEY_CONTACTS."</td></tr>\n";
  98. // LDAP Server
  99. print '<tr><td>LDAP '.$langs->trans("LDAPPrimaryServer").'</td><td class="valeur" colspan="3">'.$conf->global->LDAP_SERVER_HOST."</td></tr>\n";
  100. print '<tr><td>LDAP '.$langs->trans("LDAPSecondaryServer").'</td><td class="valeur" colspan="3">'.$conf->global->LDAP_SERVER_HOST_SLAVE."</td></tr>\n";
  101. print '<tr><td>LDAP '.$langs->trans("LDAPServerPort").'</td><td class="valeur" colspan="3">'.$conf->global->LDAP_SERVER_PORT."</td></tr>\n";
  102. print '</table>';
  103. print '</div>';
  104. dol_fiche_end();
  105. /*
  106. * Barre d'actions
  107. */
  108. print '<div class="tabsAction">';
  109. if (! empty($conf->global->LDAP_CONTACT_ACTIVE) && $conf->global->LDAP_CONTACT_ACTIVE != 'ldap2dolibarr')
  110. {
  111. print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&amp;action=dolibarr2ldap">'.$langs->trans("ForceSynchronize").'</a>';
  112. }
  113. print "</div>\n";
  114. if (! empty($conf->global->LDAP_CONTACT_ACTIVE) && $conf->global->LDAP_CONTACT_ACTIVE != 'ldap2dolibarr') print "<br>\n";
  115. // Affichage attributs LDAP
  116. print load_fiche_titre($langs->trans("LDAPInformationsForThisContact"));
  117. print '<table width="100%" class="noborder">';
  118. print '<tr class="liste_titre">';
  119. print '<td>'.$langs->trans("LDAPAttributes").'</td>';
  120. print '<td>'.$langs->trans("Value").'</td>';
  121. print '</tr>';
  122. // Lecture LDAP
  123. $ldap=new Ldap();
  124. $result=$ldap->connect_bind();
  125. if ($result > 0)
  126. {
  127. $info=$object->_load_ldap_info();
  128. $dn=$object->_load_ldap_dn($info,1);
  129. $search = "(".$object->_load_ldap_dn($info,2).")";
  130. $records = $ldap->getAttribute($dn,$search);
  131. //var_dump($records);
  132. // Affichage arbre
  133. if ((! is_numeric($records) || $records != 0) && (! isset($records['count']) || $records['count'] > 0))
  134. {
  135. if (! is_array($records))
  136. {
  137. print '<tr '.$bc[false].'><td colspan="2"><font class="error">'.$langs->trans("ErrorFailedToReadLDAP").'</font></td></tr>';
  138. }
  139. else
  140. {
  141. $result=show_ldap_content($records,0,$records['count'],true);
  142. }
  143. }
  144. else
  145. {
  146. print '<tr '.$bc[false].'><td colspan="2">'.$langs->trans("LDAPRecordNotFound").' (dn='.$dn.' - search='.$search.')</td></tr>';
  147. }
  148. $ldap->unbind();
  149. $ldap->close();
  150. }
  151. else
  152. {
  153. setEventMessages($ldap->error, $ldap->errors, 'errors');
  154. }
  155. print '</table>';
  156. llxFooter();
  157. $db->close();