dolibarr  16.0.5
sync_groups_dolibarr2ldap.php
Go to the documentation of this file.
1 #!/usr/bin/env php
2 <?php
27 if (!defined('NOSESSION')) {
28  define('NOSESSION', '1');
29 }
30 
31 $sapi_type = php_sapi_name();
32 $script_file = basename(__FILE__);
33 $path = __DIR__.'/';
34 
35 // Test if batch mode
36 if (substr($sapi_type, 0, 3) == 'cgi') {
37  echo "Error: You are using PHP for CGI. To execute ".$script_file." from command line, you must use PHP for CLI mode.\n";
38  exit(-1);
39 }
40 
41 if (!isset($argv[1]) || !$argv[1]) {
42  print "Usage: ".$script_file." now\n";
43  exit(-1);
44 }
45 $now = $argv[1];
46 
47 require_once $path."../../htdocs/master.inc.php";
48 require_once DOL_DOCUMENT_ROOT."/core/class/ldap.class.php";
49 require_once DOL_DOCUMENT_ROOT."/user/class/usergroup.class.php";
50 
51 // Global variables
52 $version = DOL_VERSION;
53 $error = 0;
54 
55 /*
56  * Main
57  */
58 
59 @set_time_limit(0);
60 print "***** ".$script_file." (".$version.") pid=".dol_getmypid()." *****\n";
61 dol_syslog($script_file." launched with arg ".join(',', $argv));
62 
63 /*
64  * if (! $conf->global->LDAP_SYNCHRO_ACTIVE)
65  * {
66  * print $langs->trans("LDAPSynchronizationNotSetupInDolibarr");
67  * exit(-1);
68  * }
69  */
70 
71 $sql = "SELECT rowid";
72 $sql .= " FROM ".MAIN_DB_PREFIX."usergroup";
73 
74 $resql = $db->query($sql);
75 if ($resql) {
76  $num = $db->num_rows($resql);
77  $i = 0;
78 
79  $ldap = new Ldap();
80  $ldap->connect_bind();
81 
82  while ($i < $num) {
83  $ldap->error = "";
84 
85  $obj = $db->fetch_object($resql);
86 
87  $fgroup = new UserGroup($db);
88  $fgroup->id = $obj->rowid;
89  $fgroup->fetch($fgroup->id);
90 
91  print $langs->trans("UpdateGroup")." rowid=".$fgroup->id." ".$fgroup->name;
92 
93  $oldobject = $fgroup;
94 
95  $oldinfo = $oldobject->_load_ldap_info();
96  $olddn = $oldobject->_load_ldap_dn($oldinfo);
97 
98  $info = $fgroup->_load_ldap_info();
99  $dn = $fgroup->_load_ldap_dn($info);
100 
101  $result = $ldap->add($dn, $info, $user); // Wil fail if already exists
102  $result = $ldap->update($dn, $info, $user, $olddn);
103  if ($result > 0) {
104  print " - ".$langs->trans("OK");
105  } else {
106  $error++;
107  print " - ".$langs->trans("KO").' - '.$ldap->error;
108  }
109  print "\n";
110 
111  $i++;
112  }
113 
114  $ldap->unbind();
115 } else {
116  dol_print_error($db);
117 }
118 
119 exit($error);
Ldap
Class to manage LDAP features.
Definition: ldap.class.php:34
dol_print_error
dol_print_error($db='', $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
Definition: functions.lib.php:4844
dol_getmypid
dol_getmypid()
Return getmypid() or random PID when function is disabled Some web hosts disable this php function fo...
Definition: functions.lib.php:9393
UserGroup
Class to manage user groups.
Definition: usergroup.class.php:39
dol_syslog
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
Definition: functions.lib.php:1603
$resql
if(isModEnabled('facture') &&!empty($user->rights->facture->lire)) if((isModEnabled('fournisseur') &&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD) && $user->rights->fournisseur->facture->lire)||(isModEnabled('supplier_invoice') && $user->rights->supplier_invoice->lire)) if(isModEnabled('don') &&!empty($user->rights->don->lire)) if(isModEnabled('tax') &&!empty($user->rights->tax->charges->lire)) if(isModEnabled('facture') &&isModEnabled('commande') && $user->rights->commande->lire &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) $resql
Social contributions to pay.
Definition: index.php:742