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

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

https://bitbucket.org/speedealing/speedealing
PHP | 172 lines | 104 code | 19 blank | 49 comment | 35 complexity | f2c062492d25c6e9fd51c51bc0314de7 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. *
  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 3 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. /**
  24. * Initialize the array of tabs for customer invoice
  25. *
  26. * @return array Array of head tabs
  27. */
  28. function ldap_prepare_head()
  29. {
  30. global $langs, $conf, $user;
  31. $langs->load("ldap");
  32. // Onglets
  33. $head=array();
  34. $h = 0;
  35. $head[$h][0] = DOL_URL_ROOT."/admin/ldap.php";
  36. $head[$h][1] = $langs->trans("LDAPGlobalParameters");
  37. $head[$h][2] = 'ldap';
  38. $h++;
  39. if (! empty($conf->global->LDAP_SYNCHRO_ACTIVE))
  40. {
  41. $head[$h][0] = DOL_URL_ROOT."/admin/ldap_users.php";
  42. $head[$h][1] = $langs->trans("LDAPUsersSynchro");
  43. $head[$h][2] = 'users';
  44. $h++;
  45. }
  46. if (! empty($conf->global->LDAP_SYNCHRO_ACTIVE))
  47. {
  48. $head[$h][0] = DOL_URL_ROOT."/admin/ldap_groups.php";
  49. $head[$h][1] = $langs->trans("LDAPGroupsSynchro");
  50. $head[$h][2] = 'groups';
  51. $h++;
  52. }
  53. if (! empty($conf->societe->enabled) && ! empty($conf->global->LDAP_CONTACT_ACTIVE))
  54. {
  55. $head[$h][0] = DOL_URL_ROOT."/admin/ldap_contacts.php";
  56. $head[$h][1] = $langs->trans("LDAPContactsSynchro");
  57. $head[$h][2] = 'contacts';
  58. $h++;
  59. }
  60. if (! empty($conf->adherent->enabled) && ! empty($conf->global->LDAP_MEMBER_ACTIVE))
  61. {
  62. $head[$h][0] = DOL_URL_ROOT."/admin/ldap_members.php";
  63. $head[$h][1] = $langs->trans("LDAPMembersSynchro");
  64. $head[$h][2] = 'members';
  65. $h++;
  66. }
  67. return $head;
  68. }
  69. /**
  70. * Show button test LDAP synchro
  71. *
  72. * @param string $butlabel Label
  73. * @param string $testlabel Label
  74. * @param string $key Key
  75. * @param string $dn Dn
  76. * @param string $objectclass Class
  77. * @return void
  78. */
  79. function show_ldap_test_button($butlabel,$testlabel,$key,$dn,$objectclass)
  80. {
  81. global $langs, $conf, $user;
  82. //print 'key='.$key.' dn='.$dn.' objectclass='.$objectclass;
  83. print '<br>';
  84. if (! function_exists("ldap_connect"))
  85. {
  86. print '<a class="butActionRefused" href="#" title="'.$langs->trans('LDAPFunctionsNotAvailableOnPHP').'">'.$butlabel.'</a>';
  87. }
  88. else if (empty($conf->global->LDAP_SERVER_HOST))
  89. {
  90. print '<a class="butActionRefused" href="#" title="'.$langs->trans('LDAPSetupNotComplete').'">'.$butlabel.'</a>';
  91. }
  92. else if (empty($key) || empty($dn) || empty($objectclass))
  93. {
  94. $langs->load("errors");
  95. print '<a class="butActionRefused" href="#" title="'.$langs->trans('ErrorLDAPSetupNotComplete').'">'.$butlabel.'</a>';
  96. }
  97. else
  98. {
  99. print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?action='.$testlabel.'">'.$butlabel.'</a>';
  100. }
  101. print '<br><br>';
  102. }
  103. /**
  104. * Show a LDAP array into an HTML output array.
  105. *
  106. * @param string $result Array to show. This array is already encoded into charset_output
  107. * @param int $level Level
  108. * @param int $count Count
  109. * @param string $var Var
  110. * @param int $hide Hide
  111. * @param int $subcount Subcount
  112. * @return int
  113. */
  114. function show_ldap_content($result,$level,$count,$var,$hide=0,$subcount=0)
  115. {
  116. global $bc, $conf;
  117. $count--;
  118. if ($count == 0) return -1; // To stop loop
  119. if (! is_array($result)) return -1;
  120. foreach($result as $key => $val)
  121. {
  122. if ("$key" == "objectclass") continue;
  123. if ("$key" == "count") continue;
  124. if ("$key" == "dn") continue;
  125. if ("$val" == "objectclass") continue;
  126. $lastkey[$level]=$key;
  127. if (is_array($val))
  128. {
  129. $hide=0;
  130. if (! is_numeric($key))
  131. {
  132. $var=!$var;
  133. print '<tr '.$bc[$var].' valign="top">';
  134. print '<td>';
  135. print $key;
  136. print '</td><td>';
  137. if (strtolower($key) == 'userpassword') $hide=1;
  138. }
  139. show_ldap_content($val,$level+1,$count,$var,$hide,$val["count"]);
  140. }
  141. else if ($subcount)
  142. {
  143. $subcount--;
  144. $newstring=dol_htmlentitiesbr($val);
  145. if ($hide) print preg_replace('/./i','*',$newstring);
  146. else print $newstring;
  147. print '<br>';
  148. }
  149. if ("$val" != $lastkey[$level] && !$subcount) print '</td></tr>';
  150. }
  151. return 1;
  152. }
  153. ?>