27if (!defined(
'NOSESSION')) {
28 define(
'NOSESSION',
'1');
31$sapi_type = php_sapi_name();
32$script_file = basename(__FILE__);
36if (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";
41require_once $path.
"../../htdocs/master.inc.php";
42require_once DOL_DOCUMENT_ROOT.
"/core/lib/date.lib.php";
43require_once DOL_DOCUMENT_ROOT.
"/core/class/ldap.class.php";
44require_once DOL_DOCUMENT_ROOT.
"/adherents/class/adherent.class.php";
45require_once DOL_DOCUMENT_ROOT.
"/adherents/class/subscription.class.php";
47$langs->loadLangs(array(
"main",
"errors"));
50$version = constant(
'DOL_VERSION');
60print
"***** ".$script_file.
" (".$version.
") pid=".
dol_getmypid().
" *****\n";
61dol_syslog($script_file.
" launched with arg ".join(
',', $argv));
64$required_fields = array(
65 $conf->global->LDAP_KEY_MEMBERS,
66 $conf->global->LDAP_FIELD_FULLNAME,
67 $conf->global->LDAP_FIELD_LOGIN,
68 $conf->global->LDAP_FIELD_LOGIN_SAMBA,
69 $conf->global->LDAP_FIELD_PASSWORD,
70 $conf->global->LDAP_FIELD_PASSWORD_CRYPTED,
71 $conf->global->LDAP_FIELD_NAME,
72 $conf->global->LDAP_FIELD_FIRSTNAME,
73 $conf->global->LDAP_FIELD_MAIL,
74 $conf->global->LDAP_FIELD_PHONE,
75 $conf->global->LDAP_FIELD_PHONE_PERSO,
76 $conf->global->LDAP_FIELD_MOBILE,
77 $conf->global->LDAP_FIELD_FAX,
78 $conf->global->LDAP_FIELD_ADDRESS,
79 $conf->global->LDAP_FIELD_ZIP,
80 $conf->global->LDAP_FIELD_TOWN,
81 $conf->global->LDAP_FIELD_COUNTRY,
82 $conf->global->LDAP_FIELD_DESCRIPTION,
83 $conf->global->LDAP_FIELD_BIRTHDATE,
84 $conf->global->LDAP_FIELD_MEMBER_STATUS,
85 $conf->global->LDAP_FIELD_MEMBER_END_LASTSUBSCRIPTION,
87 $conf->global->LDAP_FIELD_MEMBER_FIRSTSUBSCRIPTION_DATE,
88 $conf->global->LDAP_FIELD_MEMBER_FIRSTSUBSCRIPTION_AMOUNT,
89 $conf->global->LDAP_FIELD_MEMBER_LASTSUBSCRIPTION_DATE,
90 $conf->global->LDAP_FIELD_MEMBER_LASTSUBSCRIPTION_AMOUNT
94$required_fields = array_unique(array_values(array_filter($required_fields,
"dolValidElement")));
96if (!isset($argv[2]) || !is_numeric($argv[2])) {
97 print
"Usage: $script_file (nocommitiferror|commitiferror) id_member_type [--server=ldapserverhost] [-y]\n";
101$typeid = (int) $argv[2];
102foreach ($argv as $key => $val) {
103 if ($val ==
'commitiferror') {
106 if (preg_match(
'/--server=([^\s]+)$/', $val, $reg)) {
107 $conf->global->LDAP_SERVER_HOST = $reg[1];
109 if (preg_match(
'/-y$/', $val, $reg)) {
114print
"Mails sending disabled (useless in batch mode)\n";
115$conf->global->MAIN_DISABLE_ALL_MAILS = 1;
117print
"----- Synchronize all records from LDAP database:\n";
128print
"----- To Dolibarr database:\n";
129print
"type=".$conf->db->type.
"\n";
130print
"host=".$conf->db->host.
"\n";
131print
"port=".$conf->db->port.
"\n";
132print
"login=".$conf->db->user.
"\n";
133print
"database=".$conf->db->name.
"\n";
134print
"----- Options:\n";
135print
"commitiferror=".$forcecommit.
"\n";
136print
"Mapped LDAP fields=".join(
',', $required_fields).
"\n";
141 print $langs->trans(
"Error").
': '.$langs->trans(
"LDAP setup for members not defined inside Dolibarr").
"\n";
145 print $langs->trans(
"Error").
': Parameter id_member_type is not a valid ref of an existing member type'.
"\n";
149if (!empty($dolibarr_main_db_readonly)) {
150 print
"Error: instance in read-onyl mode\n";
155 print
"Hit Enter to continue or CTRL+C to stop...\n";
156 $input = trim(fgets(STDIN));
160$hashlib2rowid = array();
162$sql =
"SELECT rowid, code, label, active";
163$sql .=
" FROM ".MAIN_DB_PREFIX.
"c_country";
164$sql .=
" WHERE active = 1";
165$sql .=
" ORDER BY code ASC";
166$resql = $db->query($sql);
168 $num = $db->num_rows($resql);
172 $obj = $db->fetch_object($resql);
175 $hashlib2rowid[strtolower($obj->label)] = $obj->rowid;
176 $countries[$obj->rowid] = array(
'rowid' => $obj->rowid,
'label' => $obj->label,
'code' => $obj->code);
187$result = $ldap->connect_bind();
189 $justthese = array();
193 $conf->global->LDAP_MEMBER_ACTIVE = 0;
196 if (is_array($ldaprecords)) {
200 foreach ($ldaprecords as $key => $ldapuser) {
214 $member->country_id = $countries[$hashlib2rowid[strtolower($member->country)]][
'rowid'];
215 $member->country_code = $countries[$hashlib2rowid[strtolower($member->country)]][
'code'];
223 $member->morphy =
'phy';
228 $member->statut = -1;
239 $member->typeid = $typeid;
242 print $langs->transnoentities(
"MemberCreate").
' # '.$key.
': login='.$member->login.
', fullname='.$member->getFullName($langs);
243 print
', datec='.$member->datec;
244 $member_id = $member->create($user);
245 if ($member_id > 0) {
246 print
' --> Created member id='.$member_id.
' login='.$member->login;
249 print
' --> '.$member->error;
270 if ($datefirst && $datelast && $datelast <= $datefirst) {
273 if (!$pricefirst && $pricelast) {
274 $pricefirst = $pricelast;
283 $crowid = $member->subscription($datefirst, $pricefirst, 0);
290 $crowid = $member->subscription($datelast, $pricelast, 0);
294 if (!$error || $forcecommit) {
296 print $langs->transnoentities(
"NoErrorCommitIsDone").
"\n";
298 print $langs->transnoentities(
"ErrorButCommitIsDone").
"\n";
302 print $langs->transnoentities(
"ErrorSomeErrorWereFoundRollbackIsDone", $error).
"\n";
326 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...
dol_getmypid()
Return getmypid() or random PID when function is disabled Some web hosts disable this php function fo...
price2num($amount, $rounding='', $option=0)
Function that return a number with universal decimal format (decimal separator is '.
dol_print_error($db='', $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
getDolGlobalString($key, $default='')
Return dolibarr global constant string value.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
dolValidElement($element)
Function to say if a value is empty or not.