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