PageRenderTime 46ms CodeModel.GetById 21ms RepoModel.GetById 0ms app.codeStats 0ms

/htdocs/core/lib/ldap.lib.php

https://github.com/asterix14/dolibarr
PHP | 160 lines | 104 code | 19 blank | 37 comment | 35 complexity | 6b344c8c59f855d1f7ab3291d7358a73 MD5 | raw file
Possible License(s): LGPL-2.0
  1. <?php
  2. /* Copyright (C) 2006 Laurent Destailleur <eldy@users.sourceforge.net>
  3. *
  4. * This program is free software; you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License as published by
  6. * the Free Software Foundation; either version 2 of the License, or
  7. * (at your option) any later version.
  8. *
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  16. * or see http://www.gnu.org/
  17. */
  18. /**
  19. * \file htdocs/core/lib/ldap.lib.php
  20. * \brief Ensemble de fonctions de base pour le module LDAP
  21. * \ingroup ldap
  22. */
  23. function ldap_prepare_head()
  24. {
  25. global $langs, $conf, $user;
  26. $langs->load("ldap");
  27. // Onglets
  28. $head=array();
  29. $h = 0;
  30. $head[$h][0] = DOL_URL_ROOT."/admin/ldap.php";
  31. $head[$h][1] = $langs->trans("LDAPGlobalParameters");
  32. $head[$h][2] = 'ldap';
  33. $h++;
  34. if ($conf->global->LDAP_SYNCHRO_ACTIVE)
  35. {
  36. $head[$h][0] = DOL_URL_ROOT."/admin/ldap_users.php";
  37. $head[$h][1] = $langs->trans("LDAPUsersSynchro");
  38. $head[$h][2] = 'users';
  39. $h++;
  40. }
  41. if ($conf->global->LDAP_SYNCHRO_ACTIVE)
  42. {
  43. $head[$h][0] = DOL_URL_ROOT."/admin/ldap_groups.php";
  44. $head[$h][1] = $langs->trans("LDAPGroupsSynchro");
  45. $head[$h][2] = 'groups';
  46. $h++;
  47. }
  48. if ($conf->societe->enabled && $conf->global->LDAP_CONTACT_ACTIVE)
  49. {
  50. $head[$h][0] = DOL_URL_ROOT."/admin/ldap_contacts.php";
  51. $head[$h][1] = $langs->trans("LDAPContactsSynchro");
  52. $head[$h][2] = 'contacts';
  53. $h++;
  54. }
  55. if ($conf->adherent->enabled && $conf->global->LDAP_MEMBER_ACTIVE)
  56. {
  57. $head[$h][0] = DOL_URL_ROOT."/admin/ldap_members.php";
  58. $head[$h][1] = $langs->trans("LDAPMembersSynchro");
  59. $head[$h][2] = 'members';
  60. $h++;
  61. }
  62. return $head;
  63. }
  64. /**
  65. * \brief Show button test LDAP synchro
  66. */
  67. function show_ldap_test_button($butlabel,$testlabel,$key,$dn,$objectclass)
  68. {
  69. global $langs, $conf, $user;
  70. //print 'key='.$key.' dn='.$dn.' objectclass='.$objectclass;
  71. print '<br>';
  72. if (! function_exists("ldap_connect"))
  73. {
  74. print '<a class="butActionRefused" href="#" title="'.$langs->trans('LDAPFunctionsNotAvailableOnPHP').'">'.$butlabel.'</a>';
  75. }
  76. else if (empty($conf->global->LDAP_SERVER_HOST))
  77. {
  78. print '<a class="butActionRefused" href="#" title="'.$langs->trans('LDAPSetupNotComplete').'">'.$butlabel.'</a>';
  79. }
  80. else if (empty($key) || empty($dn) || empty($objectclass))
  81. {
  82. $langs->load("errors");
  83. print '<a class="butActionRefused" href="#" title="'.$langs->trans('ErrorLDAPSetupNotComplete').'">'.$butlabel.'</a>';
  84. }
  85. else
  86. {
  87. print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?action='.$testlabel.'">'.$butlabel.'</a>';
  88. }
  89. print '<br><br>';
  90. }
  91. /**
  92. * Show a LDAP array into an HTML output array.
  93. *
  94. * @param $result Array to show. This array is already encoded into charset_output
  95. * @param $level
  96. * @param $count
  97. * @param $var
  98. * @param $hide
  99. * @param $subcount
  100. * @return intr
  101. */
  102. function show_ldap_content($result,$level,$count,$var,$hide=0,$subcount=0)
  103. {
  104. global $bc, $conf;
  105. $count--;
  106. if ($count == 0) return -1; // To stop loop
  107. if (! is_array($result)) return -1;
  108. foreach($result as $key => $val)
  109. {
  110. if ("$key" == "objectclass") continue;
  111. if ("$key" == "count") continue;
  112. if ("$key" == "dn") continue;
  113. if ("$val" == "objectclass") continue;
  114. $lastkey[$level]=$key;
  115. if (is_array($val))
  116. {
  117. $hide=0;
  118. if (! is_numeric($key))
  119. {
  120. $var=!$var;
  121. print '<tr '.$bc[$var].' valign="top">';
  122. print '<td>';
  123. print $key;
  124. print '</td><td>';
  125. if (strtolower($key) == 'userpassword') $hide=1;
  126. }
  127. show_ldap_content($val,$level+1,$count,$var,$hide,$val["count"]);
  128. }
  129. else if ($subcount)
  130. {
  131. $subcount--;
  132. $newstring=dol_htmlentitiesbr($val);
  133. if ($hide) print preg_replace('/./i','*',$newstring);
  134. else print $newstring;
  135. print '<br>';
  136. }
  137. if ("$val" != $lastkey[$level] && !$subcount) print '</td></tr>';
  138. }
  139. return 1;
  140. }
  141. ?>