29if (!defined(
'NOSESSION')) {
30 define(
'NOSESSION',
'1');
33$sapi_type = php_sapi_name();
34$script_file = basename(__FILE__);
38if (substr($sapi_type, 0, 3) ==
'cgi') {
39 echo
"Error: You are using PHP for CGI. To execute ".$script_file.
" from command line, you must use PHP for CLI mode.\n";
43require_once $path.
"../../htdocs/master.inc.php";
53require_once DOL_DOCUMENT_ROOT.
'/core/lib/functionscli.lib.php';
54require_once DOL_DOCUMENT_ROOT.
"/core/lib/date.lib.php";
55require_once DOL_DOCUMENT_ROOT.
"/core/class/ldap.class.php";
56require_once DOL_DOCUMENT_ROOT.
"/adherents/class/adherent.class.php";
57require_once DOL_DOCUMENT_ROOT.
"/adherents/class/subscription.class.php";
66$langs->loadLangs(array(
"main",
"errors"));
69$version = constant(
'DOL_VERSION');
74$hookmanager->initHooks(array(
'cli'));
82print
"***** ".$script_file.
" (".$version.
") pid=".dol_getmypid().
" *****\n";
83dol_syslog($script_file.
" launched with arg ".implode(
',', $argv));
86$required_fields = array(
116$required_fields = array_unique(array_values(array_filter($required_fields,
"dolValidLdapElement")));
118if (!isset($argv[2]) || !is_numeric($argv[2])) {
119 print
"Usage: $script_file (nocommitiferror|commitiferror) id_member_type [--server=ldapserverhost] [-y]\n";
123$typeid = (int) $argv[2];
124foreach ($argv as $key => $val) {
125 if ($val ==
'commitiferror') {
129 if (preg_match(
'/--server=([^\s]+)$/', $val, $reg)) {
130 $conf->global->LDAP_SERVER_HOST = $reg[1];
132 if (preg_match(
'/-y$/', $val, $reg)) {
137print
"Mails sending disabled (useless in batch mode)\n";
138$conf->global->MAIN_DISABLE_ALL_MAILS = 1;
140print
"----- Synchronize all records from LDAP database:\n";
151print
"----- To Dolibarr database:\n";
152print
"type=".$conf->db->type.
"\n";
153print
"host=".$conf->db->host.
"\n";
154print
"port=".$conf->db->port.
"\n";
155print
"login=".$conf->db->user.
"\n";
156print
"database=".$conf->db->name.
"\n";
157print
"----- Options:\n";
158print
"commitiferror=".$forcecommit.
"\n";
159print
"Mapped LDAP fields=".implode(
',', $required_fields).
"\n";
164 print $langs->trans(
"Error").
': '.$langs->trans(
"LDAP setup for members not defined inside Dolibarr").
"\n";
168 print $langs->trans(
"Error").
': Parameter id_member_type is not a valid ref of an existing member type'.
"\n";
172if (!empty($dolibarr_main_db_readonly)) {
173 print
"Error: instance in read-onyl mode\n";
178 print
"Hit Enter to continue or CTRL+C to stop...\n";
179 $input = trim(fgets(STDIN));
183$hashlib2rowid = array();
185$sql =
"SELECT rowid, code, label, active";
186$sql .=
" FROM ".MAIN_DB_PREFIX.
"c_country";
187$sql .=
" WHERE active = 1";
188$sql .=
" ORDER BY code ASC";
189$resql =
$db->query($sql);
191 $num =
$db->num_rows($resql);
195 $obj =
$db->fetch_object($resql);
198 $hashlib2rowid[strtolower($obj->label)] = $obj->rowid;
199 $countries[$obj->rowid] = array(
'rowid' => $obj->rowid,
'label' => $obj->label,
'code' => $obj->code);
210$result = $ldap->connectBind();
212 $justthese = array();
216 $conf->global->LDAP_MEMBER_ACTIVE = 0;
219 if (is_array($ldaprecords)) {
223 foreach ($ldaprecords as $key => $ldapuser) {
237 $member->country_id = $countries[$hashlib2rowid[strtolower($member->country)]][
'rowid'];
238 $member->country_code = $countries[$hashlib2rowid[strtolower($member->country)]][
'code'];
246 $member->morphy =
'phy';
251 $member->statut = -1;
262 $member->typeid = $typeid;
265 print $langs->transnoentities(
"MemberCreate").
' # '.$key.
': login='.$member->login.
', fullname='.$member->getFullName($langs);
266 print
', datec='.$member->datec;
267 $member_id = $member->create($user);
268 if ($member_id > 0) {
269 print
' --> Created member id='.$member_id.
' login='.$member->login;
272 print
' --> '.$member->error;
293 if ($datefirst && $datelast && $datelast <= $datefirst) {
296 if (!$pricefirst && $pricelast) {
297 $pricefirst = $pricelast;
306 $crowid = $member->subscription($datefirst, $pricefirst, 0);
313 $crowid = $member->subscription($datelast, $pricelast, 0);
317 if (!$error || $forcecommit) {
319 print $langs->transnoentities(
"NoErrorCommitIsDone").
"\n";
321 print $langs->transnoentities(
"ErrorButCommitIsDone").
"\n";
325 print $langs->transnoentities(
"ErrorSomeErrorWereFoundRollbackIsDone", (
string) $error).
"\n";
349 return (trim($element) !=
'');
Class to manage members of a foundation.
Class to manage LDAP features.
dol_time_plus_duree($time, $duration_value, $duration_unit, $ruleforendofmonth=0)
Add a delay to a date.
dol_stringtotime($string, $gm=1)
Convert a string date into a GM Timestamps date Warning: YYYY-MM-DDTHH:MM:SS+02:00 (RFC3339) is not s...
price2num($amount, $rounding='', $option=0)
Function that return a number with universal decimal format (decimal separator is '.
dol_print_error($db=null, $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
dolValidLdapElement($element)
Function to say if a value is empty or not.