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";
44require_once DOL_DOCUMENT_ROOT.
'/core/lib/functionscli.lib.php';
45require_once DOL_DOCUMENT_ROOT.
"/core/lib/date.lib.php";
46require_once DOL_DOCUMENT_ROOT.
"/core/class/ldap.class.php";
47require_once DOL_DOCUMENT_ROOT.
"/adherents/class/adherent.class.php";
48require_once DOL_DOCUMENT_ROOT.
"/adherents/class/subscription.class.php";
57$langs->loadLangs(array(
"main",
"errors"));
60$version = constant(
'DOL_VERSION');
65$hookmanager->initHooks(array(
'cli'));
73print
"***** ".$script_file.
" (".$version.
") pid=".
dol_getmypid().
" *****\n";
74dol_syslog($script_file.
" launched with arg ".join(
',', $argv));
77$required_fields = array(
78 $conf->global->LDAP_KEY_MEMBERS,
79 $conf->global->LDAP_FIELD_FULLNAME,
80 $conf->global->LDAP_FIELD_LOGIN,
81 $conf->global->LDAP_FIELD_LOGIN_SAMBA,
82 $conf->global->LDAP_FIELD_PASSWORD,
83 $conf->global->LDAP_FIELD_PASSWORD_CRYPTED,
84 $conf->global->LDAP_FIELD_NAME,
85 $conf->global->LDAP_FIELD_FIRSTNAME,
86 $conf->global->LDAP_FIELD_MAIL,
87 $conf->global->LDAP_FIELD_PHONE,
88 $conf->global->LDAP_FIELD_PHONE_PERSO,
89 $conf->global->LDAP_FIELD_MOBILE,
90 $conf->global->LDAP_FIELD_FAX,
91 $conf->global->LDAP_FIELD_ADDRESS,
92 $conf->global->LDAP_FIELD_ZIP,
93 $conf->global->LDAP_FIELD_TOWN,
94 $conf->global->LDAP_FIELD_COUNTRY,
95 $conf->global->LDAP_FIELD_DESCRIPTION,
96 $conf->global->LDAP_FIELD_BIRTHDATE,
97 $conf->global->LDAP_FIELD_MEMBER_STATUS,
98 $conf->global->LDAP_FIELD_MEMBER_END_LASTSUBSCRIPTION,
100 $conf->global->LDAP_FIELD_MEMBER_FIRSTSUBSCRIPTION_DATE,
101 $conf->global->LDAP_FIELD_MEMBER_FIRSTSUBSCRIPTION_AMOUNT,
102 $conf->global->LDAP_FIELD_MEMBER_LASTSUBSCRIPTION_DATE,
103 $conf->global->LDAP_FIELD_MEMBER_LASTSUBSCRIPTION_AMOUNT
107$required_fields = array_unique(array_values(array_filter($required_fields,
"dolValidElement")));
109if (!isset($argv[2]) || !is_numeric($argv[2])) {
110 print
"Usage: $script_file (nocommitiferror|commitiferror) id_member_type [--server=ldapserverhost] [-y]\n";
114$typeid = (int) $argv[2];
115foreach ($argv as $key => $val) {
116 if ($val ==
'commitiferror') {
119 if (preg_match(
'/--server=([^\s]+)$/', $val, $reg)) {
120 $conf->global->LDAP_SERVER_HOST = $reg[1];
122 if (preg_match(
'/-y$/', $val, $reg)) {
127print
"Mails sending disabled (useless in batch mode)\n";
128$conf->global->MAIN_DISABLE_ALL_MAILS = 1;
130print
"----- Synchronize all records from LDAP database:\n";
141print
"----- To Dolibarr database:\n";
142print
"type=".$conf->db->type.
"\n";
143print
"host=".$conf->db->host.
"\n";
144print
"port=".$conf->db->port.
"\n";
145print
"login=".$conf->db->user.
"\n";
146print
"database=".$conf->db->name.
"\n";
147print
"----- Options:\n";
148print
"commitiferror=".$forcecommit.
"\n";
149print
"Mapped LDAP fields=".join(
',', $required_fields).
"\n";
154 print $langs->trans(
"Error").
': '.$langs->trans(
"LDAP setup for members not defined inside Dolibarr").
"\n";
158 print $langs->trans(
"Error").
': Parameter id_member_type is not a valid ref of an existing member type'.
"\n";
162if (!empty($dolibarr_main_db_readonly)) {
163 print
"Error: instance in read-onyl mode\n";
168 print
"Hit Enter to continue or CTRL+C to stop...\n";
169 $input = trim(fgets(STDIN));
173$hashlib2rowid = array();
175$sql =
"SELECT rowid, code, label, active";
176$sql .=
" FROM ".MAIN_DB_PREFIX.
"c_country";
177$sql .=
" WHERE active = 1";
178$sql .=
" ORDER BY code ASC";
179$resql = $db->query($sql);
181 $num = $db->num_rows($resql);
185 $obj = $db->fetch_object($resql);
188 $hashlib2rowid[strtolower($obj->label)] = $obj->rowid;
189 $countries[$obj->rowid] = array(
'rowid' => $obj->rowid,
'label' => $obj->label,
'code' => $obj->code);
200$result = $ldap->connectBind();
202 $justthese = array();
206 $conf->global->LDAP_MEMBER_ACTIVE = 0;
209 if (is_array($ldaprecords)) {
213 foreach ($ldaprecords as $key => $ldapuser) {
227 $member->country_id = $countries[$hashlib2rowid[strtolower($member->country)]][
'rowid'];
228 $member->country_code = $countries[$hashlib2rowid[strtolower($member->country)]][
'code'];
236 $member->morphy =
'phy';
241 $member->statut = -1;
252 $member->typeid = $typeid;
255 print $langs->transnoentities(
"MemberCreate").
' # '.$key.
': login='.$member->login.
', fullname='.$member->getFullName($langs);
256 print
', datec='.$member->datec;
257 $member_id = $member->create($user);
258 if ($member_id > 0) {
259 print
' --> Created member id='.$member_id.
' login='.$member->login;
262 print
' --> '.$member->error;
283 if ($datefirst && $datelast && $datelast <= $datefirst) {
286 if (!$pricefirst && $pricelast) {
287 $pricefirst = $pricelast;
296 $crowid = $member->subscription($datefirst, $pricefirst, 0);
303 $crowid = $member->subscription($datelast, $pricelast, 0);
307 if (!$error || $forcecommit) {
309 print $langs->transnoentities(
"NoErrorCommitIsDone").
"\n";
311 print $langs->transnoentities(
"ErrorButCommitIsDone").
"\n";
315 print $langs->transnoentities(
"ErrorSomeErrorWereFoundRollbackIsDone", $error).
"\n";
339 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=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.
global $conf
The following vars must be defined: $type2label $form $conf, $lang, The following vars may also be de...
dolValidElement($element)
Function to say if a value is empty or not.