@@ -31,7 +31,7 @@ discard block |
||
31 | 31 | // Test if batch mode |
32 | 32 | if (substr($sapi_type, 0, 3) == 'cgi') { |
33 | 33 | echo "Error: You are using PHP for CGI. To execute ".$script_file." from command line, you must use PHP for CLI mode.\n"; |
34 | - exit(-1); |
|
34 | + exit(-1); |
|
35 | 35 | } |
36 | 36 | |
37 | 37 | require_once $path."../../htdocs/master.inc.php"; |
@@ -58,41 +58,41 @@ discard block |
||
58 | 58 | |
59 | 59 | // List of fields to get from LDAP |
60 | 60 | $required_fields = array( |
61 | - $conf->global->LDAP_KEY_USERS, |
|
62 | - $conf->global->LDAP_FIELD_FULLNAME, |
|
63 | - $conf->global->LDAP_FIELD_NAME, |
|
64 | - $conf->global->LDAP_FIELD_FIRSTNAME, |
|
65 | - $conf->global->LDAP_FIELD_LOGIN, |
|
66 | - $conf->global->LDAP_FIELD_LOGIN_SAMBA, |
|
67 | - $conf->global->LDAP_FIELD_PASSWORD, |
|
68 | - $conf->global->LDAP_FIELD_PASSWORD_CRYPTED, |
|
69 | - $conf->global->LDAP_FIELD_PHONE, |
|
70 | - $conf->global->LDAP_FIELD_FAX, |
|
71 | - $conf->global->LDAP_FIELD_MOBILE, |
|
72 | - //$conf->global->LDAP_FIELD_ADDRESS, |
|
73 | - //$conf->global->LDAP_FIELD_ZIP, |
|
74 | - //$conf->global->LDAP_FIELD_TOWN, |
|
75 | - //$conf->global->LDAP_FIELD_COUNTRY, |
|
76 | - $conf->global->LDAP_FIELD_MAIL, |
|
77 | - $conf->global->LDAP_FIELD_TITLE, |
|
78 | - $conf->global->LDAP_FIELD_DESCRIPTION, |
|
79 | - $conf->global->LDAP_FIELD_SID |
|
61 | + $conf->global->LDAP_KEY_USERS, |
|
62 | + $conf->global->LDAP_FIELD_FULLNAME, |
|
63 | + $conf->global->LDAP_FIELD_NAME, |
|
64 | + $conf->global->LDAP_FIELD_FIRSTNAME, |
|
65 | + $conf->global->LDAP_FIELD_LOGIN, |
|
66 | + $conf->global->LDAP_FIELD_LOGIN_SAMBA, |
|
67 | + $conf->global->LDAP_FIELD_PASSWORD, |
|
68 | + $conf->global->LDAP_FIELD_PASSWORD_CRYPTED, |
|
69 | + $conf->global->LDAP_FIELD_PHONE, |
|
70 | + $conf->global->LDAP_FIELD_FAX, |
|
71 | + $conf->global->LDAP_FIELD_MOBILE, |
|
72 | + //$conf->global->LDAP_FIELD_ADDRESS, |
|
73 | + //$conf->global->LDAP_FIELD_ZIP, |
|
74 | + //$conf->global->LDAP_FIELD_TOWN, |
|
75 | + //$conf->global->LDAP_FIELD_COUNTRY, |
|
76 | + $conf->global->LDAP_FIELD_MAIL, |
|
77 | + $conf->global->LDAP_FIELD_TITLE, |
|
78 | + $conf->global->LDAP_FIELD_DESCRIPTION, |
|
79 | + $conf->global->LDAP_FIELD_SID |
|
80 | 80 | ); |
81 | 81 | |
82 | 82 | // Remove from required_fields all entries not configured in LDAP (empty) and duplicated |
83 | 83 | $required_fields=array_unique(array_values(array_filter($required_fields, "dolValidElement"))); |
84 | 84 | |
85 | 85 | if (! isset($argv[1])) { |
86 | - print "Usage: $script_file (nocommitiferror|commitiferror) [--server=ldapserverhost] [--excludeuser=user1,user2...] [-y]\n"; |
|
86 | + print "Usage: $script_file (nocommitiferror|commitiferror) [--server=ldapserverhost] [--excludeuser=user1,user2...] [-y]\n"; |
|
87 | 87 | exit(-1); |
88 | 88 | } |
89 | 89 | |
90 | 90 | foreach($argv as $key => $val) |
91 | 91 | { |
92 | - if ($val == 'commitiferror') $forcecommit=1; |
|
93 | - if (preg_match('/--server=([^\s]+)$/',$val,$reg)) $conf->global->LDAP_SERVER_HOST=$reg[1]; |
|
94 | - if (preg_match('/--excludeuser=([^\s]+)$/',$val,$reg)) $excludeuser=explode(',',$reg[1]); |
|
95 | - if (preg_match('/-y$/',$val,$reg)) $confirmed=1; |
|
92 | + if ($val == 'commitiferror') $forcecommit=1; |
|
93 | + if (preg_match('/--server=([^\s]+)$/',$val,$reg)) $conf->global->LDAP_SERVER_HOST=$reg[1]; |
|
94 | + if (preg_match('/--excludeuser=([^\s]+)$/',$val,$reg)) $excludeuser=explode(',',$reg[1]); |
|
95 | + if (preg_match('/-y$/',$val,$reg)) $confirmed=1; |
|
96 | 96 | } |
97 | 97 | |
98 | 98 | print "Mails sending disabled (useless in batch mode)\n"; |
@@ -120,14 +120,14 @@ discard block |
||
120 | 120 | |
121 | 121 | if (! $confirmed) |
122 | 122 | { |
123 | - print "Hit Enter to continue or CTRL+C to stop...\n"; |
|
124 | - $input = trim(fgets(STDIN)); |
|
123 | + print "Hit Enter to continue or CTRL+C to stop...\n"; |
|
124 | + $input = trim(fgets(STDIN)); |
|
125 | 125 | } |
126 | 126 | |
127 | 127 | if (empty($conf->global->LDAP_USER_DN)) |
128 | 128 | { |
129 | - print $langs->trans("Error").': '.$langs->trans("LDAP setup for users not defined inside Dolibarr"); |
|
130 | - exit(-1); |
|
129 | + print $langs->trans("Error").': '.$langs->trans("LDAP setup for users not defined inside Dolibarr"); |
|
130 | + exit(-1); |
|
131 | 131 | } |
132 | 132 | |
133 | 133 | |
@@ -141,27 +141,27 @@ discard block |
||
141 | 141 | $resql=$db->query($sql); |
142 | 142 | if ($resql) |
143 | 143 | { |
144 | - $num = $db->num_rows($resql); |
|
145 | - $i = 0; |
|
146 | - if ($num) |
|
147 | - { |
|
148 | - while ($i < $num) |
|
149 | - { |
|
150 | - $obj = $db->fetch_object($resql); |
|
151 | - if ($obj) |
|
152 | - { |
|
153 | - //print 'Load cache for country '.strtolower($obj->label).' rowid='.$obj->rowid."\n"; |
|
154 | - $hashlib2rowid[strtolower($obj->label)]=$obj->rowid; |
|
155 | - $countries[$obj->rowid]=array('rowid' => $obj->rowid, 'label' => $obj->label, 'code' => $obj->code); |
|
156 | - } |
|
157 | - $i++; |
|
158 | - } |
|
159 | - } |
|
144 | + $num = $db->num_rows($resql); |
|
145 | + $i = 0; |
|
146 | + if ($num) |
|
147 | + { |
|
148 | + while ($i < $num) |
|
149 | + { |
|
150 | + $obj = $db->fetch_object($resql); |
|
151 | + if ($obj) |
|
152 | + { |
|
153 | + //print 'Load cache for country '.strtolower($obj->label).' rowid='.$obj->rowid."\n"; |
|
154 | + $hashlib2rowid[strtolower($obj->label)]=$obj->rowid; |
|
155 | + $countries[$obj->rowid]=array('rowid' => $obj->rowid, 'label' => $obj->label, 'code' => $obj->code); |
|
156 | + } |
|
157 | + $i++; |
|
158 | + } |
|
159 | + } |
|
160 | 160 | } |
161 | 161 | else |
162 | 162 | { |
163 | - dol_print_error($db); |
|
164 | - exit(-1); |
|
163 | + dol_print_error($db); |
|
164 | + exit(-1); |
|
165 | 165 | } |
166 | 166 | |
167 | 167 | |
@@ -170,44 +170,44 @@ discard block |
||
170 | 170 | $result = $ldap->connect_bind(); |
171 | 171 | if ($result >= 0) |
172 | 172 | { |
173 | - $justthese=array(); |
|
174 | - |
|
175 | - |
|
176 | - // We disable synchro Dolibarr-LDAP |
|
177 | - $conf->global->LDAP_SYNCHRO_ACTIVE=0; |
|
178 | - |
|
179 | - $ldaprecords = $ldap->getRecords('*',$conf->global->LDAP_USER_DN, $conf->global->LDAP_KEY_USERS, $required_fields, 'user'); // Fiter on 'user' filter param |
|
180 | - if (is_array($ldaprecords)) |
|
181 | - { |
|
182 | - $db->begin(); |
|
183 | - |
|
184 | - // Warning $ldapuser has a key in lowercase |
|
185 | - foreach ($ldaprecords as $key => $ldapuser) |
|
186 | - { |
|
187 | - // If login into exclude list, we discard record |
|
188 | - if (in_array($ldapuser[$conf->global->LDAP_FIELD_LOGIN],$excludeuser)) |
|
189 | - { |
|
190 | - print $langs->transnoentities("UserDiscarded").' # '.$key.': login='.$ldapuser[$conf->global->LDAP_FIELD_LOGIN].' --> Discarded'."\n"; |
|
191 | - continue; |
|
192 | - } |
|
193 | - |
|
194 | - $fuser = new User($db); |
|
195 | - |
|
196 | - if($conf->global->LDAP_KEY_USERS == $conf->global->LDAP_FIELD_SID) { |
|
197 | - $fuser->fetch('','',$ldapuser[$conf->global->LDAP_KEY_USERS]); // Chargement du user concerné par le SID |
|
198 | - } else if($conf->global->LDAP_KEY_USERS == $conf->global->LDAP_FIELD_LOGIN) { |
|
199 | - $fuser->fetch('',$ldapuser[$conf->global->LDAP_KEY_USERS]); // Chargement du user concerné par le login |
|
200 | - } |
|
201 | - |
|
202 | - // Propriete membre |
|
203 | - $fuser->firstname=$ldapuser[$conf->global->LDAP_FIELD_FIRSTNAME]; |
|
204 | - $fuser->lastname=$ldapuser[$conf->global->LDAP_FIELD_NAME]; |
|
205 | - $fuser->login=$ldapuser[$conf->global->LDAP_FIELD_LOGIN]; |
|
206 | - $fuser->pass=$ldapuser[$conf->global->LDAP_FIELD_PASSWORD]; |
|
207 | - $fuser->pass_indatabase_crypted=$ldapuser[$conf->global->LDAP_FIELD_PASSWORD_CRYPTED]; |
|
208 | - |
|
209 | - //$user->societe; |
|
210 | - /* |
|
173 | + $justthese=array(); |
|
174 | + |
|
175 | + |
|
176 | + // We disable synchro Dolibarr-LDAP |
|
177 | + $conf->global->LDAP_SYNCHRO_ACTIVE=0; |
|
178 | + |
|
179 | + $ldaprecords = $ldap->getRecords('*',$conf->global->LDAP_USER_DN, $conf->global->LDAP_KEY_USERS, $required_fields, 'user'); // Fiter on 'user' filter param |
|
180 | + if (is_array($ldaprecords)) |
|
181 | + { |
|
182 | + $db->begin(); |
|
183 | + |
|
184 | + // Warning $ldapuser has a key in lowercase |
|
185 | + foreach ($ldaprecords as $key => $ldapuser) |
|
186 | + { |
|
187 | + // If login into exclude list, we discard record |
|
188 | + if (in_array($ldapuser[$conf->global->LDAP_FIELD_LOGIN],$excludeuser)) |
|
189 | + { |
|
190 | + print $langs->transnoentities("UserDiscarded").' # '.$key.': login='.$ldapuser[$conf->global->LDAP_FIELD_LOGIN].' --> Discarded'."\n"; |
|
191 | + continue; |
|
192 | + } |
|
193 | + |
|
194 | + $fuser = new User($db); |
|
195 | + |
|
196 | + if($conf->global->LDAP_KEY_USERS == $conf->global->LDAP_FIELD_SID) { |
|
197 | + $fuser->fetch('','',$ldapuser[$conf->global->LDAP_KEY_USERS]); // Chargement du user concerné par le SID |
|
198 | + } else if($conf->global->LDAP_KEY_USERS == $conf->global->LDAP_FIELD_LOGIN) { |
|
199 | + $fuser->fetch('',$ldapuser[$conf->global->LDAP_KEY_USERS]); // Chargement du user concerné par le login |
|
200 | + } |
|
201 | + |
|
202 | + // Propriete membre |
|
203 | + $fuser->firstname=$ldapuser[$conf->global->LDAP_FIELD_FIRSTNAME]; |
|
204 | + $fuser->lastname=$ldapuser[$conf->global->LDAP_FIELD_NAME]; |
|
205 | + $fuser->login=$ldapuser[$conf->global->LDAP_FIELD_LOGIN]; |
|
206 | + $fuser->pass=$ldapuser[$conf->global->LDAP_FIELD_PASSWORD]; |
|
207 | + $fuser->pass_indatabase_crypted=$ldapuser[$conf->global->LDAP_FIELD_PASSWORD_CRYPTED]; |
|
208 | + |
|
209 | + //$user->societe; |
|
210 | + /* |
|
211 | 211 | $fuser->address=$ldapuser[$conf->global->LDAP_FIELD_ADDRESS]; |
212 | 212 | $fuser->zip=$ldapuser[$conf->global->LDAP_FIELD_ZIP]; |
213 | 213 | $fuser->town=$ldapuser[$conf->global->LDAP_FIELD_TOWN]; |
@@ -216,93 +216,93 @@ discard block |
||
216 | 216 | $fuser->country_code=$countries[$hashlib2rowid[strtolower($fuser->country)]]['code']; |
217 | 217 | */ |
218 | 218 | |
219 | - $fuser->office_phone=$ldapuser[$conf->global->LDAP_FIELD_PHONE]; |
|
220 | - $fuser->user_mobile=$ldapuser[$conf->global->LDAP_FIELD_MOBILE]; |
|
221 | - $fuser->office_fax=$ldapuser[$conf->global->LDAP_FIELD_FAX]; |
|
222 | - $fuser->email=$ldapuser[$conf->global->LDAP_FIELD_MAIL]; |
|
223 | - $fuser->ldap_sid=$ldapuser[$conf->global->LDAP_FIELD_SID]; |
|
224 | - |
|
225 | - $fuser->job=$ldapuser[$conf->global->LDAP_FIELD_TITLE]; |
|
226 | - $fuser->note=$ldapuser[$conf->global->LDAP_FIELD_DESCRIPTION]; |
|
227 | - $fuser->admin=0; |
|
228 | - $fuser->societe_id=0; |
|
229 | - $fuser->contact_id=0; |
|
230 | - $fuser->fk_member=0; |
|
231 | - |
|
232 | - $fuser->statut=1; |
|
233 | - // TODO : revoir la gestion du status |
|
234 | - /*if (isset($ldapuser[$conf->global->LDAP_FIELD_MEMBER_STATUS])) |
|
219 | + $fuser->office_phone=$ldapuser[$conf->global->LDAP_FIELD_PHONE]; |
|
220 | + $fuser->user_mobile=$ldapuser[$conf->global->LDAP_FIELD_MOBILE]; |
|
221 | + $fuser->office_fax=$ldapuser[$conf->global->LDAP_FIELD_FAX]; |
|
222 | + $fuser->email=$ldapuser[$conf->global->LDAP_FIELD_MAIL]; |
|
223 | + $fuser->ldap_sid=$ldapuser[$conf->global->LDAP_FIELD_SID]; |
|
224 | + |
|
225 | + $fuser->job=$ldapuser[$conf->global->LDAP_FIELD_TITLE]; |
|
226 | + $fuser->note=$ldapuser[$conf->global->LDAP_FIELD_DESCRIPTION]; |
|
227 | + $fuser->admin=0; |
|
228 | + $fuser->societe_id=0; |
|
229 | + $fuser->contact_id=0; |
|
230 | + $fuser->fk_member=0; |
|
231 | + |
|
232 | + $fuser->statut=1; |
|
233 | + // TODO : revoir la gestion du status |
|
234 | + /*if (isset($ldapuser[$conf->global->LDAP_FIELD_MEMBER_STATUS])) |
|
235 | 235 | { |
236 | 236 | $fuser->datec=dol_stringtotime($ldapuser[$conf->global->LDAP_FIELD_MEMBER_FIRSTSUBSCRIPTION_DATE]); |
237 | 237 | $fuser->datevalid=dol_stringtotime($ldapuser[$conf->global->LDAP_FIELD_MEMBER_FIRSTSUBSCRIPTION_DATE]); |
238 | 238 | $fuser->statut=$ldapuser[$conf->global->LDAP_FIELD_MEMBER_STATUS]; |
239 | 239 | }*/ |
240 | - //if ($fuser->statut > 1) $fuser->statut=1; |
|
241 | - |
|
242 | - //print_r($ldapuser); |
|
243 | - |
|
244 | - if($fuser->id > 0) { // User update |
|
245 | - print $langs->transnoentities("UserUpdate").' # '.$key.': login='.$fuser->login.', fullname='.$fuser->getFullName($langs); |
|
246 | - $res=$fuser->update($user); |
|
247 | - |
|
248 | - if ($res < 0) |
|
249 | - { |
|
250 | - $error++; |
|
251 | - print ' --> '.$res.' '.$fuser->error; |
|
252 | - } |
|
253 | - else |
|
254 | - { |
|
255 | - print ' --> Updated user id='.$fuser->id.' login='.$fuser->login; |
|
256 | - } |
|
257 | - } else { // User creation |
|
258 | - print $langs->transnoentities("UserCreate").' # '.$key.': login='.$fuser->login.', fullname='.$fuser->getFullName($langs); |
|
259 | - $res=$fuser->create($user); |
|
260 | - |
|
261 | - if ($res > 0) |
|
262 | - { |
|
263 | - print ' --> Created user id='.$fuser->id.' login='.$fuser->login; |
|
264 | - } |
|
265 | - else |
|
266 | - { |
|
267 | - $error++; |
|
268 | - print ' --> '.$res.' '.$fuser->error; |
|
269 | - } |
|
270 | - } |
|
271 | - print "\n"; |
|
272 | - //print_r($fuser); |
|
273 | - |
|
274 | - // Gestion des groupes |
|
275 | - // TODO : revoir la gestion des groupes (ou script de sync groupes) |
|
276 | - /*if(!$error) { |
|
240 | + //if ($fuser->statut > 1) $fuser->statut=1; |
|
241 | + |
|
242 | + //print_r($ldapuser); |
|
243 | + |
|
244 | + if($fuser->id > 0) { // User update |
|
245 | + print $langs->transnoentities("UserUpdate").' # '.$key.': login='.$fuser->login.', fullname='.$fuser->getFullName($langs); |
|
246 | + $res=$fuser->update($user); |
|
247 | + |
|
248 | + if ($res < 0) |
|
249 | + { |
|
250 | + $error++; |
|
251 | + print ' --> '.$res.' '.$fuser->error; |
|
252 | + } |
|
253 | + else |
|
254 | + { |
|
255 | + print ' --> Updated user id='.$fuser->id.' login='.$fuser->login; |
|
256 | + } |
|
257 | + } else { // User creation |
|
258 | + print $langs->transnoentities("UserCreate").' # '.$key.': login='.$fuser->login.', fullname='.$fuser->getFullName($langs); |
|
259 | + $res=$fuser->create($user); |
|
260 | + |
|
261 | + if ($res > 0) |
|
262 | + { |
|
263 | + print ' --> Created user id='.$fuser->id.' login='.$fuser->login; |
|
264 | + } |
|
265 | + else |
|
266 | + { |
|
267 | + $error++; |
|
268 | + print ' --> '.$res.' '.$fuser->error; |
|
269 | + } |
|
270 | + } |
|
271 | + print "\n"; |
|
272 | + //print_r($fuser); |
|
273 | + |
|
274 | + // Gestion des groupes |
|
275 | + // TODO : revoir la gestion des groupes (ou script de sync groupes) |
|
276 | + /*if(!$error) { |
|
277 | 277 | foreach ($ldapuser[$conf->global->LDAP_FIELD_USERGROUPS] as $groupdn) { |
278 | 278 | $groupdn; |
279 | 279 | } |
280 | 280 | }*/ |
281 | - } |
|
282 | - |
|
283 | - if (! $error || $forcecommit) |
|
284 | - { |
|
285 | - if (! $error) print $langs->transnoentities("NoErrorCommitIsDone")."\n"; |
|
286 | - else print $langs->transnoentities("ErrorButCommitIsDone")."\n"; |
|
287 | - $db->commit(); |
|
288 | - } |
|
289 | - else |
|
290 | - { |
|
291 | - print $langs->transnoentities("ErrorSomeErrorWereFoundRollbackIsDone",$error)."\n"; |
|
292 | - $db->rollback(); |
|
293 | - } |
|
294 | - print "\n"; |
|
295 | - } |
|
296 | - else |
|
297 | - { |
|
298 | - dol_print_error('',$ldap->error); |
|
299 | - $error++; |
|
300 | - } |
|
281 | + } |
|
282 | + |
|
283 | + if (! $error || $forcecommit) |
|
284 | + { |
|
285 | + if (! $error) print $langs->transnoentities("NoErrorCommitIsDone")."\n"; |
|
286 | + else print $langs->transnoentities("ErrorButCommitIsDone")."\n"; |
|
287 | + $db->commit(); |
|
288 | + } |
|
289 | + else |
|
290 | + { |
|
291 | + print $langs->transnoentities("ErrorSomeErrorWereFoundRollbackIsDone",$error)."\n"; |
|
292 | + $db->rollback(); |
|
293 | + } |
|
294 | + print "\n"; |
|
295 | + } |
|
296 | + else |
|
297 | + { |
|
298 | + dol_print_error('',$ldap->error); |
|
299 | + $error++; |
|
300 | + } |
|
301 | 301 | } |
302 | 302 | else |
303 | 303 | { |
304 | - dol_print_error('',$ldap->error); |
|
305 | - $error++; |
|
304 | + dol_print_error('',$ldap->error); |
|
305 | + $error++; |
|
306 | 306 | } |
307 | 307 | |
308 | 308 | |
@@ -317,6 +317,6 @@ discard block |
||
317 | 317 | */ |
318 | 318 | function dolValidElement($element) |
319 | 319 | { |
320 | - return (trim($element) != ''); |
|
320 | + return (trim($element) != ''); |
|
321 | 321 | } |
322 | 322 |
@@ -26,7 +26,7 @@ discard block |
||
26 | 26 | |
27 | 27 | $sapi_type = php_sapi_name(); |
28 | 28 | $script_file = basename(__FILE__); |
29 | -$path=dirname(__FILE__).'/'; |
|
29 | +$path = dirname(__FILE__).'/'; |
|
30 | 30 | |
31 | 31 | // Test if batch mode |
32 | 32 | if (substr($sapi_type, 0, 3) == 'cgi') { |
@@ -42,11 +42,11 @@ discard block |
||
42 | 42 | $langs->loadLangs(array("main", "errors")); |
43 | 43 | |
44 | 44 | // Global variables |
45 | -$version=DOL_VERSION; |
|
46 | -$error=0; |
|
47 | -$forcecommit=0; |
|
48 | -$excludeuser=array(); |
|
49 | -$confirmed=0; |
|
45 | +$version = DOL_VERSION; |
|
46 | +$error = 0; |
|
47 | +$forcecommit = 0; |
|
48 | +$excludeuser = array(); |
|
49 | +$confirmed = 0; |
|
50 | 50 | |
51 | 51 | /* |
52 | 52 | * Main |
@@ -54,7 +54,7 @@ discard block |
||
54 | 54 | |
55 | 55 | @set_time_limit(0); |
56 | 56 | print "***** ".$script_file." (".$version.") pid=".dol_getmypid()." *****\n"; |
57 | -dol_syslog($script_file." launched with arg ".join(',',$argv)); |
|
57 | +dol_syslog($script_file." launched with arg ".join(',', $argv)); |
|
58 | 58 | |
59 | 59 | // List of fields to get from LDAP |
60 | 60 | $required_fields = array( |
@@ -80,31 +80,31 @@ discard block |
||
80 | 80 | ); |
81 | 81 | |
82 | 82 | // Remove from required_fields all entries not configured in LDAP (empty) and duplicated |
83 | -$required_fields=array_unique(array_values(array_filter($required_fields, "dolValidElement"))); |
|
83 | +$required_fields = array_unique(array_values(array_filter($required_fields, "dolValidElement"))); |
|
84 | 84 | |
85 | -if (! isset($argv[1])) { |
|
85 | +if (!isset($argv[1])) { |
|
86 | 86 | print "Usage: $script_file (nocommitiferror|commitiferror) [--server=ldapserverhost] [--excludeuser=user1,user2...] [-y]\n"; |
87 | 87 | exit(-1); |
88 | 88 | } |
89 | 89 | |
90 | -foreach($argv as $key => $val) |
|
90 | +foreach ($argv as $key => $val) |
|
91 | 91 | { |
92 | - if ($val == 'commitiferror') $forcecommit=1; |
|
93 | - if (preg_match('/--server=([^\s]+)$/',$val,$reg)) $conf->global->LDAP_SERVER_HOST=$reg[1]; |
|
94 | - if (preg_match('/--excludeuser=([^\s]+)$/',$val,$reg)) $excludeuser=explode(',',$reg[1]); |
|
95 | - if (preg_match('/-y$/',$val,$reg)) $confirmed=1; |
|
92 | + if ($val == 'commitiferror') $forcecommit = 1; |
|
93 | + if (preg_match('/--server=([^\s]+)$/', $val, $reg)) $conf->global->LDAP_SERVER_HOST = $reg[1]; |
|
94 | + if (preg_match('/--excludeuser=([^\s]+)$/', $val, $reg)) $excludeuser = explode(',', $reg[1]); |
|
95 | + if (preg_match('/-y$/', $val, $reg)) $confirmed = 1; |
|
96 | 96 | } |
97 | 97 | |
98 | 98 | print "Mails sending disabled (useless in batch mode)\n"; |
99 | -$conf->global->MAIN_DISABLE_ALL_MAILS=1; // On bloque les mails |
|
99 | +$conf->global->MAIN_DISABLE_ALL_MAILS = 1; // On bloque les mails |
|
100 | 100 | print "\n"; |
101 | 101 | print "----- Synchronize all records from LDAP database:\n"; |
102 | 102 | print "host=".$conf->global->LDAP_SERVER_HOST."\n"; |
103 | 103 | print "port=".$conf->global->LDAP_SERVER_PORT."\n"; |
104 | 104 | print "login=".$conf->global->LDAP_ADMIN_DN."\n"; |
105 | -print "pass=".preg_replace('/./i','*',$conf->global->LDAP_ADMIN_PASS)."\n"; |
|
105 | +print "pass=".preg_replace('/./i', '*', $conf->global->LDAP_ADMIN_PASS)."\n"; |
|
106 | 106 | print "DN to extract=".$conf->global->LDAP_USER_DN."\n"; |
107 | -if (! empty($conf->global->LDAP_FILTER_CONNECTION)) print 'Filter=('.$conf->global->LDAP_FILTER_CONNECTION.')'."\n"; // Note: filter is defined into function getRecords |
|
107 | +if (!empty($conf->global->LDAP_FILTER_CONNECTION)) print 'Filter=('.$conf->global->LDAP_FILTER_CONNECTION.')'."\n"; // Note: filter is defined into function getRecords |
|
108 | 108 | else print 'Filter=('.$conf->global->LDAP_KEY_USERS.'=*)'."\n"; |
109 | 109 | print "----- To Dolibarr database:\n"; |
110 | 110 | print "type=".$conf->db->type."\n"; |
@@ -114,11 +114,11 @@ discard block |
||
114 | 114 | print "database=".$conf->db->name."\n"; |
115 | 115 | print "----- Options:\n"; |
116 | 116 | print "commitiferror=".$forcecommit."\n"; |
117 | -print "excludeuser=".join(',',$excludeuser)."\n"; |
|
118 | -print "Mapped LDAP fields=".join(',',$required_fields)."\n"; |
|
117 | +print "excludeuser=".join(',', $excludeuser)."\n"; |
|
118 | +print "Mapped LDAP fields=".join(',', $required_fields)."\n"; |
|
119 | 119 | print "\n"; |
120 | 120 | |
121 | -if (! $confirmed) |
|
121 | +if (!$confirmed) |
|
122 | 122 | { |
123 | 123 | print "Hit Enter to continue or CTRL+C to stop...\n"; |
124 | 124 | $input = trim(fgets(STDIN)); |
@@ -132,13 +132,13 @@ discard block |
||
132 | 132 | |
133 | 133 | |
134 | 134 | // Load table of correspondence of countries |
135 | -$hashlib2rowid=array(); |
|
136 | -$countries=array(); |
|
135 | +$hashlib2rowid = array(); |
|
136 | +$countries = array(); |
|
137 | 137 | $sql = "SELECT rowid, code, label, active"; |
138 | -$sql.= " FROM ".MAIN_DB_PREFIX."c_country"; |
|
139 | -$sql.= " WHERE active = 1"; |
|
140 | -$sql.= " ORDER BY code ASC"; |
|
141 | -$resql=$db->query($sql); |
|
138 | +$sql .= " FROM ".MAIN_DB_PREFIX."c_country"; |
|
139 | +$sql .= " WHERE active = 1"; |
|
140 | +$sql .= " ORDER BY code ASC"; |
|
141 | +$resql = $db->query($sql); |
|
142 | 142 | if ($resql) |
143 | 143 | { |
144 | 144 | $num = $db->num_rows($resql); |
@@ -151,8 +151,8 @@ discard block |
||
151 | 151 | if ($obj) |
152 | 152 | { |
153 | 153 | //print 'Load cache for country '.strtolower($obj->label).' rowid='.$obj->rowid."\n"; |
154 | - $hashlib2rowid[strtolower($obj->label)]=$obj->rowid; |
|
155 | - $countries[$obj->rowid]=array('rowid' => $obj->rowid, 'label' => $obj->label, 'code' => $obj->code); |
|
154 | + $hashlib2rowid[strtolower($obj->label)] = $obj->rowid; |
|
155 | + $countries[$obj->rowid] = array('rowid' => $obj->rowid, 'label' => $obj->label, 'code' => $obj->code); |
|
156 | 156 | } |
157 | 157 | $i++; |
158 | 158 | } |
@@ -170,13 +170,13 @@ discard block |
||
170 | 170 | $result = $ldap->connect_bind(); |
171 | 171 | if ($result >= 0) |
172 | 172 | { |
173 | - $justthese=array(); |
|
173 | + $justthese = array(); |
|
174 | 174 | |
175 | 175 | |
176 | 176 | // We disable synchro Dolibarr-LDAP |
177 | - $conf->global->LDAP_SYNCHRO_ACTIVE=0; |
|
177 | + $conf->global->LDAP_SYNCHRO_ACTIVE = 0; |
|
178 | 178 | |
179 | - $ldaprecords = $ldap->getRecords('*',$conf->global->LDAP_USER_DN, $conf->global->LDAP_KEY_USERS, $required_fields, 'user'); // Fiter on 'user' filter param |
|
179 | + $ldaprecords = $ldap->getRecords('*', $conf->global->LDAP_USER_DN, $conf->global->LDAP_KEY_USERS, $required_fields, 'user'); // Fiter on 'user' filter param |
|
180 | 180 | if (is_array($ldaprecords)) |
181 | 181 | { |
182 | 182 | $db->begin(); |
@@ -185,7 +185,7 @@ discard block |
||
185 | 185 | foreach ($ldaprecords as $key => $ldapuser) |
186 | 186 | { |
187 | 187 | // If login into exclude list, we discard record |
188 | - if (in_array($ldapuser[$conf->global->LDAP_FIELD_LOGIN],$excludeuser)) |
|
188 | + if (in_array($ldapuser[$conf->global->LDAP_FIELD_LOGIN], $excludeuser)) |
|
189 | 189 | { |
190 | 190 | print $langs->transnoentities("UserDiscarded").' # '.$key.': login='.$ldapuser[$conf->global->LDAP_FIELD_LOGIN].' --> Discarded'."\n"; |
191 | 191 | continue; |
@@ -193,18 +193,18 @@ discard block |
||
193 | 193 | |
194 | 194 | $fuser = new User($db); |
195 | 195 | |
196 | - if($conf->global->LDAP_KEY_USERS == $conf->global->LDAP_FIELD_SID) { |
|
197 | - $fuser->fetch('','',$ldapuser[$conf->global->LDAP_KEY_USERS]); // Chargement du user concerné par le SID |
|
198 | - } else if($conf->global->LDAP_KEY_USERS == $conf->global->LDAP_FIELD_LOGIN) { |
|
199 | - $fuser->fetch('',$ldapuser[$conf->global->LDAP_KEY_USERS]); // Chargement du user concerné par le login |
|
196 | + if ($conf->global->LDAP_KEY_USERS == $conf->global->LDAP_FIELD_SID) { |
|
197 | + $fuser->fetch('', '', $ldapuser[$conf->global->LDAP_KEY_USERS]); // Chargement du user concerné par le SID |
|
198 | + } else if ($conf->global->LDAP_KEY_USERS == $conf->global->LDAP_FIELD_LOGIN) { |
|
199 | + $fuser->fetch('', $ldapuser[$conf->global->LDAP_KEY_USERS]); // Chargement du user concerné par le login |
|
200 | 200 | } |
201 | 201 | |
202 | 202 | // Propriete membre |
203 | - $fuser->firstname=$ldapuser[$conf->global->LDAP_FIELD_FIRSTNAME]; |
|
204 | - $fuser->lastname=$ldapuser[$conf->global->LDAP_FIELD_NAME]; |
|
205 | - $fuser->login=$ldapuser[$conf->global->LDAP_FIELD_LOGIN]; |
|
206 | - $fuser->pass=$ldapuser[$conf->global->LDAP_FIELD_PASSWORD]; |
|
207 | - $fuser->pass_indatabase_crypted=$ldapuser[$conf->global->LDAP_FIELD_PASSWORD_CRYPTED]; |
|
203 | + $fuser->firstname = $ldapuser[$conf->global->LDAP_FIELD_FIRSTNAME]; |
|
204 | + $fuser->lastname = $ldapuser[$conf->global->LDAP_FIELD_NAME]; |
|
205 | + $fuser->login = $ldapuser[$conf->global->LDAP_FIELD_LOGIN]; |
|
206 | + $fuser->pass = $ldapuser[$conf->global->LDAP_FIELD_PASSWORD]; |
|
207 | + $fuser->pass_indatabase_crypted = $ldapuser[$conf->global->LDAP_FIELD_PASSWORD_CRYPTED]; |
|
208 | 208 | |
209 | 209 | //$user->societe; |
210 | 210 | /* |
@@ -216,20 +216,20 @@ discard block |
||
216 | 216 | $fuser->country_code=$countries[$hashlib2rowid[strtolower($fuser->country)]]['code']; |
217 | 217 | */ |
218 | 218 | |
219 | - $fuser->office_phone=$ldapuser[$conf->global->LDAP_FIELD_PHONE]; |
|
220 | - $fuser->user_mobile=$ldapuser[$conf->global->LDAP_FIELD_MOBILE]; |
|
221 | - $fuser->office_fax=$ldapuser[$conf->global->LDAP_FIELD_FAX]; |
|
222 | - $fuser->email=$ldapuser[$conf->global->LDAP_FIELD_MAIL]; |
|
223 | - $fuser->ldap_sid=$ldapuser[$conf->global->LDAP_FIELD_SID]; |
|
219 | + $fuser->office_phone = $ldapuser[$conf->global->LDAP_FIELD_PHONE]; |
|
220 | + $fuser->user_mobile = $ldapuser[$conf->global->LDAP_FIELD_MOBILE]; |
|
221 | + $fuser->office_fax = $ldapuser[$conf->global->LDAP_FIELD_FAX]; |
|
222 | + $fuser->email = $ldapuser[$conf->global->LDAP_FIELD_MAIL]; |
|
223 | + $fuser->ldap_sid = $ldapuser[$conf->global->LDAP_FIELD_SID]; |
|
224 | 224 | |
225 | - $fuser->job=$ldapuser[$conf->global->LDAP_FIELD_TITLE]; |
|
226 | - $fuser->note=$ldapuser[$conf->global->LDAP_FIELD_DESCRIPTION]; |
|
227 | - $fuser->admin=0; |
|
228 | - $fuser->societe_id=0; |
|
229 | - $fuser->contact_id=0; |
|
230 | - $fuser->fk_member=0; |
|
225 | + $fuser->job = $ldapuser[$conf->global->LDAP_FIELD_TITLE]; |
|
226 | + $fuser->note = $ldapuser[$conf->global->LDAP_FIELD_DESCRIPTION]; |
|
227 | + $fuser->admin = 0; |
|
228 | + $fuser->societe_id = 0; |
|
229 | + $fuser->contact_id = 0; |
|
230 | + $fuser->fk_member = 0; |
|
231 | 231 | |
232 | - $fuser->statut=1; |
|
232 | + $fuser->statut = 1; |
|
233 | 233 | // TODO : revoir la gestion du status |
234 | 234 | /*if (isset($ldapuser[$conf->global->LDAP_FIELD_MEMBER_STATUS])) |
235 | 235 | { |
@@ -241,9 +241,9 @@ discard block |
||
241 | 241 | |
242 | 242 | //print_r($ldapuser); |
243 | 243 | |
244 | - if($fuser->id > 0) { // User update |
|
244 | + if ($fuser->id > 0) { // User update |
|
245 | 245 | print $langs->transnoentities("UserUpdate").' # '.$key.': login='.$fuser->login.', fullname='.$fuser->getFullName($langs); |
246 | - $res=$fuser->update($user); |
|
246 | + $res = $fuser->update($user); |
|
247 | 247 | |
248 | 248 | if ($res < 0) |
249 | 249 | { |
@@ -256,7 +256,7 @@ discard block |
||
256 | 256 | } |
257 | 257 | } else { // User creation |
258 | 258 | print $langs->transnoentities("UserCreate").' # '.$key.': login='.$fuser->login.', fullname='.$fuser->getFullName($langs); |
259 | - $res=$fuser->create($user); |
|
259 | + $res = $fuser->create($user); |
|
260 | 260 | |
261 | 261 | if ($res > 0) |
262 | 262 | { |
@@ -280,28 +280,28 @@ discard block |
||
280 | 280 | }*/ |
281 | 281 | } |
282 | 282 | |
283 | - if (! $error || $forcecommit) |
|
283 | + if (!$error || $forcecommit) |
|
284 | 284 | { |
285 | - if (! $error) print $langs->transnoentities("NoErrorCommitIsDone")."\n"; |
|
285 | + if (!$error) print $langs->transnoentities("NoErrorCommitIsDone")."\n"; |
|
286 | 286 | else print $langs->transnoentities("ErrorButCommitIsDone")."\n"; |
287 | 287 | $db->commit(); |
288 | 288 | } |
289 | 289 | else |
290 | 290 | { |
291 | - print $langs->transnoentities("ErrorSomeErrorWereFoundRollbackIsDone",$error)."\n"; |
|
291 | + print $langs->transnoentities("ErrorSomeErrorWereFoundRollbackIsDone", $error)."\n"; |
|
292 | 292 | $db->rollback(); |
293 | 293 | } |
294 | 294 | print "\n"; |
295 | 295 | } |
296 | 296 | else |
297 | 297 | { |
298 | - dol_print_error('',$ldap->error); |
|
298 | + dol_print_error('', $ldap->error); |
|
299 | 299 | $error++; |
300 | 300 | } |
301 | 301 | } |
302 | 302 | else |
303 | 303 | { |
304 | - dol_print_error('',$ldap->error); |
|
304 | + dol_print_error('', $ldap->error); |
|
305 | 305 | $error++; |
306 | 306 | } |
307 | 307 |
@@ -89,11 +89,19 @@ discard block |
||
89 | 89 | |
90 | 90 | foreach($argv as $key => $val) |
91 | 91 | { |
92 | - if ($val == 'commitiferror') $forcecommit=1; |
|
93 | - if (preg_match('/--server=([^\s]+)$/',$val,$reg)) $conf->global->LDAP_SERVER_HOST=$reg[1]; |
|
94 | - if (preg_match('/--excludeuser=([^\s]+)$/',$val,$reg)) $excludeuser=explode(',',$reg[1]); |
|
95 | - if (preg_match('/-y$/',$val,$reg)) $confirmed=1; |
|
96 | -} |
|
92 | + if ($val == 'commitiferror') { |
|
93 | + $forcecommit=1; |
|
94 | + } |
|
95 | + if (preg_match('/--server=([^\s]+)$/',$val,$reg)) { |
|
96 | + $conf->global->LDAP_SERVER_HOST=$reg[1]; |
|
97 | + } |
|
98 | + if (preg_match('/--excludeuser=([^\s]+)$/',$val,$reg)) { |
|
99 | + $excludeuser=explode(',',$reg[1]); |
|
100 | + } |
|
101 | + if (preg_match('/-y$/',$val,$reg)) { |
|
102 | + $confirmed=1; |
|
103 | + } |
|
104 | + } |
|
97 | 105 | |
98 | 106 | print "Mails sending disabled (useless in batch mode)\n"; |
99 | 107 | $conf->global->MAIN_DISABLE_ALL_MAILS=1; // On bloque les mails |
@@ -104,8 +112,13 @@ discard block |
||
104 | 112 | print "login=".$conf->global->LDAP_ADMIN_DN."\n"; |
105 | 113 | print "pass=".preg_replace('/./i','*',$conf->global->LDAP_ADMIN_PASS)."\n"; |
106 | 114 | print "DN to extract=".$conf->global->LDAP_USER_DN."\n"; |
107 | -if (! empty($conf->global->LDAP_FILTER_CONNECTION)) print 'Filter=('.$conf->global->LDAP_FILTER_CONNECTION.')'."\n"; // Note: filter is defined into function getRecords |
|
108 | -else print 'Filter=('.$conf->global->LDAP_KEY_USERS.'=*)'."\n"; |
|
115 | +if (! empty($conf->global->LDAP_FILTER_CONNECTION)) { |
|
116 | + print 'Filter=('.$conf->global->LDAP_FILTER_CONNECTION.')'."\n"; |
|
117 | +} |
|
118 | +// Note: filter is defined into function getRecords |
|
119 | +else { |
|
120 | + print 'Filter=('.$conf->global->LDAP_KEY_USERS.'=*)'."\n"; |
|
121 | +} |
|
109 | 122 | print "----- To Dolibarr database:\n"; |
110 | 123 | print "type=".$conf->db->type."\n"; |
111 | 124 | print "host=".$conf->db->host."\n"; |
@@ -157,8 +170,7 @@ discard block |
||
157 | 170 | $i++; |
158 | 171 | } |
159 | 172 | } |
160 | -} |
|
161 | -else |
|
173 | +} else |
|
162 | 174 | { |
163 | 175 | dol_print_error($db); |
164 | 176 | exit(-1); |
@@ -249,8 +261,7 @@ discard block |
||
249 | 261 | { |
250 | 262 | $error++; |
251 | 263 | print ' --> '.$res.' '.$fuser->error; |
252 | - } |
|
253 | - else |
|
264 | + } else |
|
254 | 265 | { |
255 | 266 | print ' --> Updated user id='.$fuser->id.' login='.$fuser->login; |
256 | 267 | } |
@@ -261,8 +272,7 @@ discard block |
||
261 | 272 | if ($res > 0) |
262 | 273 | { |
263 | 274 | print ' --> Created user id='.$fuser->id.' login='.$fuser->login; |
264 | - } |
|
265 | - else |
|
275 | + } else |
|
266 | 276 | { |
267 | 277 | $error++; |
268 | 278 | print ' --> '.$res.' '.$fuser->error; |
@@ -282,24 +292,24 @@ discard block |
||
282 | 292 | |
283 | 293 | if (! $error || $forcecommit) |
284 | 294 | { |
285 | - if (! $error) print $langs->transnoentities("NoErrorCommitIsDone")."\n"; |
|
286 | - else print $langs->transnoentities("ErrorButCommitIsDone")."\n"; |
|
295 | + if (! $error) { |
|
296 | + print $langs->transnoentities("NoErrorCommitIsDone")."\n"; |
|
297 | + } else { |
|
298 | + print $langs->transnoentities("ErrorButCommitIsDone")."\n"; |
|
299 | + } |
|
287 | 300 | $db->commit(); |
288 | - } |
|
289 | - else |
|
301 | + } else |
|
290 | 302 | { |
291 | 303 | print $langs->transnoentities("ErrorSomeErrorWereFoundRollbackIsDone",$error)."\n"; |
292 | 304 | $db->rollback(); |
293 | 305 | } |
294 | 306 | print "\n"; |
295 | - } |
|
296 | - else |
|
307 | + } else |
|
297 | 308 | { |
298 | 309 | dol_print_error('',$ldap->error); |
299 | 310 | $error++; |
300 | 311 | } |
301 | -} |
|
302 | -else |
|
312 | +} else |
|
303 | 313 | { |
304 | 314 | dol_print_error('',$ldap->error); |
305 | 315 | $error++; |
@@ -31,12 +31,12 @@ discard block |
||
31 | 31 | // Test if batch mode |
32 | 32 | if (substr($sapi_type, 0, 3) == 'cgi') { |
33 | 33 | echo "Error: You are using PHP for CGI. To execute ".$script_file." from command line, you must use PHP for CLI mode.\n"; |
34 | - exit(-1); |
|
34 | + exit(-1); |
|
35 | 35 | } |
36 | 36 | |
37 | 37 | if (! isset($argv[1]) || ! $argv[1]) { |
38 | 38 | print "Usage: ".$script_file." now\n"; |
39 | - exit(-1); |
|
39 | + exit(-1); |
|
40 | 40 | } |
41 | 41 | $now=$argv[1]; |
42 | 42 | |
@@ -71,54 +71,54 @@ discard block |
||
71 | 71 | $resql = $db->query($sql); |
72 | 72 | if ($resql) |
73 | 73 | { |
74 | - $num = $db->num_rows($resql); |
|
75 | - $i = 0; |
|
74 | + $num = $db->num_rows($resql); |
|
75 | + $i = 0; |
|
76 | 76 | |
77 | - $ldap=new Ldap(); |
|
78 | - $ldap->connect_bind(); |
|
77 | + $ldap=new Ldap(); |
|
78 | + $ldap->connect_bind(); |
|
79 | 79 | |
80 | - while ($i < $num) |
|
81 | - { |
|
82 | - $ldap->error=""; |
|
80 | + while ($i < $num) |
|
81 | + { |
|
82 | + $ldap->error=""; |
|
83 | 83 | |
84 | - $obj = $db->fetch_object($resql); |
|
84 | + $obj = $db->fetch_object($resql); |
|
85 | 85 | |
86 | - $fgroup = new UserGroup($db); |
|
87 | - $fgroup->id = $obj->rowid; |
|
88 | - $fgroup->fetch($fgroup->id); |
|
86 | + $fgroup = new UserGroup($db); |
|
87 | + $fgroup->id = $obj->rowid; |
|
88 | + $fgroup->fetch($fgroup->id); |
|
89 | 89 | |
90 | - print $langs->trans("UpdateGroup")." rowid=".$fgroup->id." ".$fgroup->name; |
|
90 | + print $langs->trans("UpdateGroup")." rowid=".$fgroup->id." ".$fgroup->name; |
|
91 | 91 | |
92 | - $oldobject=$fgroup; |
|
92 | + $oldobject=$fgroup; |
|
93 | 93 | |
94 | - $oldinfo=$oldobject->_load_ldap_info(); |
|
95 | - $olddn=$oldobject->_load_ldap_dn($oldinfo); |
|
94 | + $oldinfo=$oldobject->_load_ldap_info(); |
|
95 | + $olddn=$oldobject->_load_ldap_dn($oldinfo); |
|
96 | 96 | |
97 | - $info=$fgroup->_load_ldap_info(); |
|
98 | - $dn=$fgroup->_load_ldap_dn($info); |
|
97 | + $info=$fgroup->_load_ldap_info(); |
|
98 | + $dn=$fgroup->_load_ldap_dn($info); |
|
99 | 99 | |
100 | - $result=$ldap->add($dn,$info,$user); // Wil fail if already exists |
|
101 | - $result=$ldap->update($dn,$info,$user,$olddn); |
|
102 | - if ($result > 0) |
|
103 | - { |
|
104 | - print " - ".$langs->trans("OK"); |
|
105 | - } |
|
106 | - else |
|
107 | - { |
|
108 | - $error++; |
|
109 | - print " - ".$langs->trans("KO").' - '.$ldap->error; |
|
110 | - } |
|
111 | - print "\n"; |
|
100 | + $result=$ldap->add($dn,$info,$user); // Wil fail if already exists |
|
101 | + $result=$ldap->update($dn,$info,$user,$olddn); |
|
102 | + if ($result > 0) |
|
103 | + { |
|
104 | + print " - ".$langs->trans("OK"); |
|
105 | + } |
|
106 | + else |
|
107 | + { |
|
108 | + $error++; |
|
109 | + print " - ".$langs->trans("KO").' - '.$ldap->error; |
|
110 | + } |
|
111 | + print "\n"; |
|
112 | 112 | |
113 | - $i++; |
|
114 | - } |
|
113 | + $i++; |
|
114 | + } |
|
115 | 115 | |
116 | - $ldap->unbind(); |
|
117 | - $ldap->close(); |
|
116 | + $ldap->unbind(); |
|
117 | + $ldap->close(); |
|
118 | 118 | } |
119 | 119 | else |
120 | 120 | { |
121 | - dol_print_error($db); |
|
121 | + dol_print_error($db); |
|
122 | 122 | } |
123 | 123 | |
124 | 124 | exit($error); |
@@ -26,7 +26,7 @@ discard block |
||
26 | 26 | |
27 | 27 | $sapi_type = php_sapi_name(); |
28 | 28 | $script_file = basename(__FILE__); |
29 | -$path=dirname(__FILE__).'/'; |
|
29 | +$path = dirname(__FILE__).'/'; |
|
30 | 30 | |
31 | 31 | // Test if batch mode |
32 | 32 | if (substr($sapi_type, 0, 3) == 'cgi') { |
@@ -34,19 +34,19 @@ discard block |
||
34 | 34 | exit(-1); |
35 | 35 | } |
36 | 36 | |
37 | -if (! isset($argv[1]) || ! $argv[1]) { |
|
37 | +if (!isset($argv[1]) || !$argv[1]) { |
|
38 | 38 | print "Usage: ".$script_file." now\n"; |
39 | 39 | exit(-1); |
40 | 40 | } |
41 | -$now=$argv[1]; |
|
41 | +$now = $argv[1]; |
|
42 | 42 | |
43 | 43 | require_once $path."../../htdocs/master.inc.php"; |
44 | 44 | require_once DOL_DOCUMENT_ROOT."/core/class/ldap.class.php"; |
45 | 45 | require_once DOL_DOCUMENT_ROOT."/user/class/usergroup.class.php"; |
46 | 46 | |
47 | 47 | // Global variables |
48 | -$version=DOL_VERSION; |
|
49 | -$error=0; |
|
48 | +$version = DOL_VERSION; |
|
49 | +$error = 0; |
|
50 | 50 | |
51 | 51 | |
52 | 52 | /* |
@@ -55,7 +55,7 @@ discard block |
||
55 | 55 | |
56 | 56 | @set_time_limit(0); |
57 | 57 | print "***** ".$script_file." (".$version.") pid=".dol_getmypid()." *****\n"; |
58 | -dol_syslog($script_file." launched with arg ".join(',',$argv)); |
|
58 | +dol_syslog($script_file." launched with arg ".join(',', $argv)); |
|
59 | 59 | |
60 | 60 | /* |
61 | 61 | if (! $conf->global->LDAP_SYNCHRO_ACTIVE) |
@@ -74,12 +74,12 @@ discard block |
||
74 | 74 | $num = $db->num_rows($resql); |
75 | 75 | $i = 0; |
76 | 76 | |
77 | - $ldap=new Ldap(); |
|
77 | + $ldap = new Ldap(); |
|
78 | 78 | $ldap->connect_bind(); |
79 | 79 | |
80 | 80 | while ($i < $num) |
81 | 81 | { |
82 | - $ldap->error=""; |
|
82 | + $ldap->error = ""; |
|
83 | 83 | |
84 | 84 | $obj = $db->fetch_object($resql); |
85 | 85 | |
@@ -89,16 +89,16 @@ discard block |
||
89 | 89 | |
90 | 90 | print $langs->trans("UpdateGroup")." rowid=".$fgroup->id." ".$fgroup->name; |
91 | 91 | |
92 | - $oldobject=$fgroup; |
|
92 | + $oldobject = $fgroup; |
|
93 | 93 | |
94 | - $oldinfo=$oldobject->_load_ldap_info(); |
|
95 | - $olddn=$oldobject->_load_ldap_dn($oldinfo); |
|
94 | + $oldinfo = $oldobject->_load_ldap_info(); |
|
95 | + $olddn = $oldobject->_load_ldap_dn($oldinfo); |
|
96 | 96 | |
97 | - $info=$fgroup->_load_ldap_info(); |
|
98 | - $dn=$fgroup->_load_ldap_dn($info); |
|
97 | + $info = $fgroup->_load_ldap_info(); |
|
98 | + $dn = $fgroup->_load_ldap_dn($info); |
|
99 | 99 | |
100 | - $result=$ldap->add($dn,$info,$user); // Wil fail if already exists |
|
101 | - $result=$ldap->update($dn,$info,$user,$olddn); |
|
100 | + $result = $ldap->add($dn, $info, $user); // Wil fail if already exists |
|
101 | + $result = $ldap->update($dn, $info, $user, $olddn); |
|
102 | 102 | if ($result > 0) |
103 | 103 | { |
104 | 104 | print " - ".$langs->trans("OK"); |
@@ -102,8 +102,7 @@ discard block |
||
102 | 102 | if ($result > 0) |
103 | 103 | { |
104 | 104 | print " - ".$langs->trans("OK"); |
105 | - } |
|
106 | - else |
|
105 | + } else |
|
107 | 106 | { |
108 | 107 | $error++; |
109 | 108 | print " - ".$langs->trans("KO").' - '.$ldap->error; |
@@ -115,8 +114,7 @@ discard block |
||
115 | 114 | |
116 | 115 | $ldap->unbind(); |
117 | 116 | $ldap->close(); |
118 | -} |
|
119 | -else |
|
117 | +} else |
|
120 | 118 | { |
121 | 119 | dol_print_error($db); |
122 | 120 | } |
@@ -32,7 +32,7 @@ discard block |
||
32 | 32 | // Test if batch mode |
33 | 33 | if (substr($sapi_type, 0, 3) == 'cgi') { |
34 | 34 | echo "Error: You are using PHP for CGI. To execute ".$script_file." from command line, you must use PHP for CLI mode.\n"; |
35 | - exit(-1); |
|
35 | + exit(-1); |
|
36 | 36 | } |
37 | 37 | |
38 | 38 | require_once $path."../../htdocs/master.inc.php"; |
@@ -60,10 +60,10 @@ discard block |
||
60 | 60 | |
61 | 61 | // List of fields to get from LDAP |
62 | 62 | $required_fields = array( |
63 | - $conf->global->LDAP_KEY_GROUPS, |
|
64 | - $conf->global->LDAP_GROUP_FIELD_FULLNAME, |
|
65 | - $conf->global->LDAP_GROUP_FIELD_DESCRIPTION, |
|
66 | - $conf->global->LDAP_GROUP_FIELD_GROUPMEMBERS |
|
63 | + $conf->global->LDAP_KEY_GROUPS, |
|
64 | + $conf->global->LDAP_GROUP_FIELD_FULLNAME, |
|
65 | + $conf->global->LDAP_GROUP_FIELD_DESCRIPTION, |
|
66 | + $conf->global->LDAP_GROUP_FIELD_GROUPMEMBERS |
|
67 | 67 | ); |
68 | 68 | |
69 | 69 | // Remove from required_fields all entries not configured in LDAP (empty) and duplicated |
@@ -71,17 +71,17 @@ discard block |
||
71 | 71 | |
72 | 72 | |
73 | 73 | if (! isset($argv[1])) { |
74 | - //print "Usage: $script_file (nocommitiferror|commitiferror) [id_group]\n"; |
|
75 | - print "Usage: $script_file (nocommitiferror|commitiferror) [--server=ldapserverhost] [--excludeuser=user1,user2...] [-y]\n"; |
|
76 | - exit(-1); |
|
74 | + //print "Usage: $script_file (nocommitiferror|commitiferror) [id_group]\n"; |
|
75 | + print "Usage: $script_file (nocommitiferror|commitiferror) [--server=ldapserverhost] [--excludeuser=user1,user2...] [-y]\n"; |
|
76 | + exit(-1); |
|
77 | 77 | } |
78 | 78 | |
79 | 79 | foreach($argv as $key => $val) |
80 | 80 | { |
81 | - if ($val == 'commitiferror') $forcecommit=1; |
|
82 | - if (preg_match('/--server=([^\s]+)$/',$val,$reg)) $conf->global->LDAP_SERVER_HOST=$reg[1]; |
|
83 | - if (preg_match('/--excludeuser=([^\s]+)$/',$val,$reg)) $excludeuser=explode(',',$reg[1]); |
|
84 | - if (preg_match('/-y$/',$val,$reg)) $confirmed=1; |
|
81 | + if ($val == 'commitiferror') $forcecommit=1; |
|
82 | + if (preg_match('/--server=([^\s]+)$/',$val,$reg)) $conf->global->LDAP_SERVER_HOST=$reg[1]; |
|
83 | + if (preg_match('/--excludeuser=([^\s]+)$/',$val,$reg)) $excludeuser=explode(',',$reg[1]); |
|
84 | + if (preg_match('/-y$/',$val,$reg)) $confirmed=1; |
|
85 | 85 | } |
86 | 86 | |
87 | 87 | print "Mails sending disabled (useless in batch mode)\n"; |
@@ -107,14 +107,14 @@ discard block |
||
107 | 107 | |
108 | 108 | if (! $confirmed) |
109 | 109 | { |
110 | - print "Hit Enter to continue or CTRL+C to stop...\n"; |
|
111 | - $input = trim(fgets(STDIN)); |
|
110 | + print "Hit Enter to continue or CTRL+C to stop...\n"; |
|
111 | + $input = trim(fgets(STDIN)); |
|
112 | 112 | } |
113 | 113 | |
114 | 114 | if (empty($conf->global->LDAP_GROUP_DN)) |
115 | 115 | { |
116 | - print $langs->trans("Error").': '.$langs->trans("LDAP setup for groups not defined inside Dolibarr"); |
|
117 | - exit(-1); |
|
116 | + print $langs->trans("Error").': '.$langs->trans("LDAP setup for groups not defined inside Dolibarr"); |
|
117 | + exit(-1); |
|
118 | 118 | } |
119 | 119 | |
120 | 120 | |
@@ -122,131 +122,131 @@ discard block |
||
122 | 122 | $result = $ldap->connect_bind(); |
123 | 123 | if ($result >= 0) |
124 | 124 | { |
125 | - $justthese=array(); |
|
126 | - |
|
127 | - |
|
128 | - // We disable synchro Dolibarr-LDAP |
|
129 | - $conf->global->LDAP_SYNCHRO_ACTIVE=0; |
|
130 | - |
|
131 | - $ldaprecords = $ldap->getRecords('*',$conf->global->LDAP_GROUP_DN, $conf->global->LDAP_KEY_GROUPS, $required_fields, 0, array($conf->global->LDAP_GROUP_FIELD_GROUPMEMBERS)); |
|
132 | - if (is_array($ldaprecords)) |
|
133 | - { |
|
134 | - $db->begin(); |
|
135 | - |
|
136 | - // Warning $ldapuser has a key in lowercase |
|
137 | - foreach ($ldaprecords as $key => $ldapgroup) |
|
138 | - { |
|
139 | - $group = new UserGroup($db); |
|
140 | - $group->fetch('', $ldapgroup[$conf->global->LDAP_KEY_GROUPS]); |
|
141 | - $group->name = $ldapgroup[$conf->global->LDAP_GROUP_FIELD_FULLNAME]; |
|
142 | - $group->nom = $group->name; // For backward compatibility |
|
143 | - $group->note = $ldapgroup[$conf->global->LDAP_GROUP_FIELD_DESCRIPTION]; |
|
144 | - $group->entity = $conf->entity; |
|
145 | - |
|
146 | - //print_r($ldapgroup); |
|
147 | - |
|
148 | - if($group->id > 0) { // Group update |
|
149 | - print $langs->transnoentities("GroupUpdate").' # '.$key.': name='.$group->name; |
|
150 | - $res=$group->update(); |
|
151 | - |
|
152 | - if ($res > 0) |
|
153 | - { |
|
154 | - print ' --> Updated group id='.$group->id.' name='.$group->name; |
|
155 | - } |
|
156 | - else |
|
157 | - { |
|
158 | - $error++; |
|
159 | - print ' --> '.$res.' '.$group->error; |
|
160 | - } |
|
161 | - print "\n"; |
|
162 | - } else { // Group creation |
|
163 | - print $langs->transnoentities("GroupCreate").' # '.$key.': name='.$group->name; |
|
164 | - $res=$group->create(); |
|
165 | - |
|
166 | - if ($res > 0) |
|
167 | - { |
|
168 | - print ' --> Created group id='.$group->id.' name='.$group->name; |
|
169 | - } |
|
170 | - else |
|
171 | - { |
|
172 | - $error++; |
|
173 | - print ' --> '.$res.' '.$group->error; |
|
174 | - } |
|
175 | - print "\n"; |
|
176 | - } |
|
177 | - |
|
178 | - //print_r($group); |
|
179 | - |
|
180 | - // Gestion des utilisateurs associés au groupe |
|
181 | - // 1 - Association des utilisateurs du groupe LDAP au groupe Dolibarr |
|
182 | - $userList = array(); |
|
183 | - $userIdList = array(); |
|
184 | - foreach($ldapgroup[$conf->global->LDAP_GROUP_FIELD_GROUPMEMBERS] as $key => $userdn) { |
|
185 | - if($key === 'count') continue; |
|
186 | - if(empty($userList[$userdn])) { // Récupération de l'utilisateur |
|
187 | - // Schéma rfc2307: les membres sont listés dans l'attribut memberUid sous form de login uniquement |
|
188 | - if ($conf->global->LDAP_GROUP_FIELD_GROUPMEMBERS === 'memberUid'){ |
|
189 | - $userKey = array($userdn); |
|
190 | - } else { // Pour les autres schémas, les membres sont listés sous forme de DN complets |
|
191 | - $userFilter = explode(',', $userdn); |
|
192 | - $userKey = $ldap->getAttributeValues('('.$userFilter[0].')', $conf->global->LDAP_KEY_USERS); |
|
193 | - } |
|
194 | - if(!is_array($userKey)) continue; |
|
195 | - |
|
196 | - $fuser = new User($db); |
|
197 | - |
|
198 | - if($conf->global->LDAP_KEY_USERS == $conf->global->LDAP_FIELD_SID) { |
|
199 | - $fuser->fetch('','',$userKey[0]); // Chargement du user concerné par le SID |
|
200 | - } else if($conf->global->LDAP_KEY_USERS == $conf->global->LDAP_FIELD_LOGIN) { |
|
201 | - $fuser->fetch('',$userKey[0]); // Chargement du user concerné par le login |
|
202 | - } |
|
203 | - |
|
204 | - $userList[$userdn] = $fuser; |
|
205 | - } else { |
|
206 | - $fuser = &$userList[$userdn]; |
|
207 | - } |
|
208 | - |
|
209 | - $userIdList[$userdn] = $fuser->id; |
|
210 | - |
|
211 | - // Ajout de l'utilisateur dans le groupe |
|
212 | - if(!in_array($fuser->id, array_keys($group->members))) { |
|
213 | - $fuser->SetInGroup($group->id, $group->entity); |
|
214 | - echo $fuser->login.' added'."\n"; |
|
215 | - } |
|
216 | - } |
|
217 | - |
|
218 | - // 2 - Suppression des utilisateurs du groupe Dolibarr qui ne sont plus dans le groupe LDAP |
|
219 | - foreach ($group->members as $guser) { |
|
220 | - if(!in_array($guser->id, $userIdList)) { |
|
221 | - $guser->RemoveFromGroup($group->id, $group->entity); |
|
222 | - echo $guser->login.' removed'."\n"; |
|
223 | - } |
|
224 | - } |
|
225 | - } |
|
226 | - |
|
227 | - if (! $error || $forcecommit) |
|
228 | - { |
|
229 | - if (! $error) print $langs->transnoentities("NoErrorCommitIsDone")."\n"; |
|
230 | - else print $langs->transnoentities("ErrorButCommitIsDone")."\n"; |
|
231 | - $db->commit(); |
|
232 | - } |
|
233 | - else |
|
234 | - { |
|
235 | - print $langs->transnoentities("ErrorSomeErrorWereFoundRollbackIsDone",$error)."\n"; |
|
236 | - $db->rollback(); |
|
237 | - } |
|
238 | - print "\n"; |
|
239 | - } |
|
240 | - else |
|
241 | - { |
|
242 | - dol_print_error('',$ldap->error); |
|
243 | - $error++; |
|
244 | - } |
|
125 | + $justthese=array(); |
|
126 | + |
|
127 | + |
|
128 | + // We disable synchro Dolibarr-LDAP |
|
129 | + $conf->global->LDAP_SYNCHRO_ACTIVE=0; |
|
130 | + |
|
131 | + $ldaprecords = $ldap->getRecords('*',$conf->global->LDAP_GROUP_DN, $conf->global->LDAP_KEY_GROUPS, $required_fields, 0, array($conf->global->LDAP_GROUP_FIELD_GROUPMEMBERS)); |
|
132 | + if (is_array($ldaprecords)) |
|
133 | + { |
|
134 | + $db->begin(); |
|
135 | + |
|
136 | + // Warning $ldapuser has a key in lowercase |
|
137 | + foreach ($ldaprecords as $key => $ldapgroup) |
|
138 | + { |
|
139 | + $group = new UserGroup($db); |
|
140 | + $group->fetch('', $ldapgroup[$conf->global->LDAP_KEY_GROUPS]); |
|
141 | + $group->name = $ldapgroup[$conf->global->LDAP_GROUP_FIELD_FULLNAME]; |
|
142 | + $group->nom = $group->name; // For backward compatibility |
|
143 | + $group->note = $ldapgroup[$conf->global->LDAP_GROUP_FIELD_DESCRIPTION]; |
|
144 | + $group->entity = $conf->entity; |
|
145 | + |
|
146 | + //print_r($ldapgroup); |
|
147 | + |
|
148 | + if($group->id > 0) { // Group update |
|
149 | + print $langs->transnoentities("GroupUpdate").' # '.$key.': name='.$group->name; |
|
150 | + $res=$group->update(); |
|
151 | + |
|
152 | + if ($res > 0) |
|
153 | + { |
|
154 | + print ' --> Updated group id='.$group->id.' name='.$group->name; |
|
155 | + } |
|
156 | + else |
|
157 | + { |
|
158 | + $error++; |
|
159 | + print ' --> '.$res.' '.$group->error; |
|
160 | + } |
|
161 | + print "\n"; |
|
162 | + } else { // Group creation |
|
163 | + print $langs->transnoentities("GroupCreate").' # '.$key.': name='.$group->name; |
|
164 | + $res=$group->create(); |
|
165 | + |
|
166 | + if ($res > 0) |
|
167 | + { |
|
168 | + print ' --> Created group id='.$group->id.' name='.$group->name; |
|
169 | + } |
|
170 | + else |
|
171 | + { |
|
172 | + $error++; |
|
173 | + print ' --> '.$res.' '.$group->error; |
|
174 | + } |
|
175 | + print "\n"; |
|
176 | + } |
|
177 | + |
|
178 | + //print_r($group); |
|
179 | + |
|
180 | + // Gestion des utilisateurs associés au groupe |
|
181 | + // 1 - Association des utilisateurs du groupe LDAP au groupe Dolibarr |
|
182 | + $userList = array(); |
|
183 | + $userIdList = array(); |
|
184 | + foreach($ldapgroup[$conf->global->LDAP_GROUP_FIELD_GROUPMEMBERS] as $key => $userdn) { |
|
185 | + if($key === 'count') continue; |
|
186 | + if(empty($userList[$userdn])) { // Récupération de l'utilisateur |
|
187 | + // Schéma rfc2307: les membres sont listés dans l'attribut memberUid sous form de login uniquement |
|
188 | + if ($conf->global->LDAP_GROUP_FIELD_GROUPMEMBERS === 'memberUid'){ |
|
189 | + $userKey = array($userdn); |
|
190 | + } else { // Pour les autres schémas, les membres sont listés sous forme de DN complets |
|
191 | + $userFilter = explode(',', $userdn); |
|
192 | + $userKey = $ldap->getAttributeValues('('.$userFilter[0].')', $conf->global->LDAP_KEY_USERS); |
|
193 | + } |
|
194 | + if(!is_array($userKey)) continue; |
|
195 | + |
|
196 | + $fuser = new User($db); |
|
197 | + |
|
198 | + if($conf->global->LDAP_KEY_USERS == $conf->global->LDAP_FIELD_SID) { |
|
199 | + $fuser->fetch('','',$userKey[0]); // Chargement du user concerné par le SID |
|
200 | + } else if($conf->global->LDAP_KEY_USERS == $conf->global->LDAP_FIELD_LOGIN) { |
|
201 | + $fuser->fetch('',$userKey[0]); // Chargement du user concerné par le login |
|
202 | + } |
|
203 | + |
|
204 | + $userList[$userdn] = $fuser; |
|
205 | + } else { |
|
206 | + $fuser = &$userList[$userdn]; |
|
207 | + } |
|
208 | + |
|
209 | + $userIdList[$userdn] = $fuser->id; |
|
210 | + |
|
211 | + // Ajout de l'utilisateur dans le groupe |
|
212 | + if(!in_array($fuser->id, array_keys($group->members))) { |
|
213 | + $fuser->SetInGroup($group->id, $group->entity); |
|
214 | + echo $fuser->login.' added'."\n"; |
|
215 | + } |
|
216 | + } |
|
217 | + |
|
218 | + // 2 - Suppression des utilisateurs du groupe Dolibarr qui ne sont plus dans le groupe LDAP |
|
219 | + foreach ($group->members as $guser) { |
|
220 | + if(!in_array($guser->id, $userIdList)) { |
|
221 | + $guser->RemoveFromGroup($group->id, $group->entity); |
|
222 | + echo $guser->login.' removed'."\n"; |
|
223 | + } |
|
224 | + } |
|
225 | + } |
|
226 | + |
|
227 | + if (! $error || $forcecommit) |
|
228 | + { |
|
229 | + if (! $error) print $langs->transnoentities("NoErrorCommitIsDone")."\n"; |
|
230 | + else print $langs->transnoentities("ErrorButCommitIsDone")."\n"; |
|
231 | + $db->commit(); |
|
232 | + } |
|
233 | + else |
|
234 | + { |
|
235 | + print $langs->transnoentities("ErrorSomeErrorWereFoundRollbackIsDone",$error)."\n"; |
|
236 | + $db->rollback(); |
|
237 | + } |
|
238 | + print "\n"; |
|
239 | + } |
|
240 | + else |
|
241 | + { |
|
242 | + dol_print_error('',$ldap->error); |
|
243 | + $error++; |
|
244 | + } |
|
245 | 245 | } |
246 | 246 | else |
247 | 247 | { |
248 | - dol_print_error('',$ldap->error); |
|
249 | - $error++; |
|
248 | + dol_print_error('',$ldap->error); |
|
249 | + $error++; |
|
250 | 250 | } |
251 | 251 | |
252 | 252 | |
@@ -261,6 +261,6 @@ discard block |
||
261 | 261 | */ |
262 | 262 | function dolValidElement($element) |
263 | 263 | { |
264 | - return (trim($element) != ''); |
|
264 | + return (trim($element) != ''); |
|
265 | 265 | } |
266 | 266 |
@@ -27,7 +27,7 @@ discard block |
||
27 | 27 | |
28 | 28 | $sapi_type = php_sapi_name(); |
29 | 29 | $script_file = basename(__FILE__); |
30 | -$path=dirname(__FILE__).'/'; |
|
30 | +$path = dirname(__FILE__).'/'; |
|
31 | 31 | |
32 | 32 | // Test if batch mode |
33 | 33 | if (substr($sapi_type, 0, 3) == 'cgi') { |
@@ -44,10 +44,10 @@ discard block |
||
44 | 44 | $langs->loadLangs(array("main", "errors")); |
45 | 45 | |
46 | 46 | // Global variables |
47 | -$version=DOL_VERSION; |
|
48 | -$error=0; |
|
49 | -$forcecommit=0; |
|
50 | -$confirmed=0; |
|
47 | +$version = DOL_VERSION; |
|
48 | +$error = 0; |
|
49 | +$forcecommit = 0; |
|
50 | +$confirmed = 0; |
|
51 | 51 | |
52 | 52 | |
53 | 53 | /* |
@@ -56,7 +56,7 @@ discard block |
||
56 | 56 | |
57 | 57 | @set_time_limit(0); |
58 | 58 | print "***** ".$script_file." (".$version.") pid=".dol_getmypid()." *****\n"; |
59 | -dol_syslog($script_file." launched with arg ".join(',',$argv)); |
|
59 | +dol_syslog($script_file." launched with arg ".join(',', $argv)); |
|
60 | 60 | |
61 | 61 | // List of fields to get from LDAP |
62 | 62 | $required_fields = array( |
@@ -67,31 +67,31 @@ discard block |
||
67 | 67 | ); |
68 | 68 | |
69 | 69 | // Remove from required_fields all entries not configured in LDAP (empty) and duplicated |
70 | -$required_fields=array_unique(array_values(array_filter($required_fields, "dolValidElement"))); |
|
70 | +$required_fields = array_unique(array_values(array_filter($required_fields, "dolValidElement"))); |
|
71 | 71 | |
72 | 72 | |
73 | -if (! isset($argv[1])) { |
|
73 | +if (!isset($argv[1])) { |
|
74 | 74 | //print "Usage: $script_file (nocommitiferror|commitiferror) [id_group]\n"; |
75 | 75 | print "Usage: $script_file (nocommitiferror|commitiferror) [--server=ldapserverhost] [--excludeuser=user1,user2...] [-y]\n"; |
76 | 76 | exit(-1); |
77 | 77 | } |
78 | 78 | |
79 | -foreach($argv as $key => $val) |
|
79 | +foreach ($argv as $key => $val) |
|
80 | 80 | { |
81 | - if ($val == 'commitiferror') $forcecommit=1; |
|
82 | - if (preg_match('/--server=([^\s]+)$/',$val,$reg)) $conf->global->LDAP_SERVER_HOST=$reg[1]; |
|
83 | - if (preg_match('/--excludeuser=([^\s]+)$/',$val,$reg)) $excludeuser=explode(',',$reg[1]); |
|
84 | - if (preg_match('/-y$/',$val,$reg)) $confirmed=1; |
|
81 | + if ($val == 'commitiferror') $forcecommit = 1; |
|
82 | + if (preg_match('/--server=([^\s]+)$/', $val, $reg)) $conf->global->LDAP_SERVER_HOST = $reg[1]; |
|
83 | + if (preg_match('/--excludeuser=([^\s]+)$/', $val, $reg)) $excludeuser = explode(',', $reg[1]); |
|
84 | + if (preg_match('/-y$/', $val, $reg)) $confirmed = 1; |
|
85 | 85 | } |
86 | 86 | |
87 | 87 | print "Mails sending disabled (useless in batch mode)\n"; |
88 | -$conf->global->MAIN_DISABLE_ALL_MAILS=1; // On bloque les mails |
|
88 | +$conf->global->MAIN_DISABLE_ALL_MAILS = 1; // On bloque les mails |
|
89 | 89 | print "\n"; |
90 | 90 | print "----- Synchronize all records from LDAP database:\n"; |
91 | 91 | print "host=".$conf->global->LDAP_SERVER_HOST."\n"; |
92 | 92 | print "port=".$conf->global->LDAP_SERVER_PORT."\n"; |
93 | 93 | print "login=".$conf->global->LDAP_ADMIN_DN."\n"; |
94 | -print "pass=".preg_replace('/./i','*',$conf->global->LDAP_ADMIN_PASS)."\n"; |
|
94 | +print "pass=".preg_replace('/./i', '*', $conf->global->LDAP_ADMIN_PASS)."\n"; |
|
95 | 95 | print "DN to extract=".$conf->global->LDAP_GROUP_DN."\n"; |
96 | 96 | print 'Filter=('.$conf->global->LDAP_KEY_GROUPS.'=*)'."\n"; |
97 | 97 | print "----- To Dolibarr database:\n"; |
@@ -102,10 +102,10 @@ discard block |
||
102 | 102 | print "database=".$conf->db->name."\n"; |
103 | 103 | print "----- Options:\n"; |
104 | 104 | print "commitiferror=".$forcecommit."\n"; |
105 | -print "Mapped LDAP fields=".join(',',$required_fields)."\n"; |
|
105 | +print "Mapped LDAP fields=".join(',', $required_fields)."\n"; |
|
106 | 106 | print "\n"; |
107 | 107 | |
108 | -if (! $confirmed) |
|
108 | +if (!$confirmed) |
|
109 | 109 | { |
110 | 110 | print "Hit Enter to continue or CTRL+C to stop...\n"; |
111 | 111 | $input = trim(fgets(STDIN)); |
@@ -122,13 +122,13 @@ discard block |
||
122 | 122 | $result = $ldap->connect_bind(); |
123 | 123 | if ($result >= 0) |
124 | 124 | { |
125 | - $justthese=array(); |
|
125 | + $justthese = array(); |
|
126 | 126 | |
127 | 127 | |
128 | 128 | // We disable synchro Dolibarr-LDAP |
129 | - $conf->global->LDAP_SYNCHRO_ACTIVE=0; |
|
129 | + $conf->global->LDAP_SYNCHRO_ACTIVE = 0; |
|
130 | 130 | |
131 | - $ldaprecords = $ldap->getRecords('*',$conf->global->LDAP_GROUP_DN, $conf->global->LDAP_KEY_GROUPS, $required_fields, 0, array($conf->global->LDAP_GROUP_FIELD_GROUPMEMBERS)); |
|
131 | + $ldaprecords = $ldap->getRecords('*', $conf->global->LDAP_GROUP_DN, $conf->global->LDAP_KEY_GROUPS, $required_fields, 0, array($conf->global->LDAP_GROUP_FIELD_GROUPMEMBERS)); |
|
132 | 132 | if (is_array($ldaprecords)) |
133 | 133 | { |
134 | 134 | $db->begin(); |
@@ -139,15 +139,15 @@ discard block |
||
139 | 139 | $group = new UserGroup($db); |
140 | 140 | $group->fetch('', $ldapgroup[$conf->global->LDAP_KEY_GROUPS]); |
141 | 141 | $group->name = $ldapgroup[$conf->global->LDAP_GROUP_FIELD_FULLNAME]; |
142 | - $group->nom = $group->name; // For backward compatibility |
|
142 | + $group->nom = $group->name; // For backward compatibility |
|
143 | 143 | $group->note = $ldapgroup[$conf->global->LDAP_GROUP_FIELD_DESCRIPTION]; |
144 | 144 | $group->entity = $conf->entity; |
145 | 145 | |
146 | 146 | //print_r($ldapgroup); |
147 | 147 | |
148 | - if($group->id > 0) { // Group update |
|
148 | + if ($group->id > 0) { // Group update |
|
149 | 149 | print $langs->transnoentities("GroupUpdate").' # '.$key.': name='.$group->name; |
150 | - $res=$group->update(); |
|
150 | + $res = $group->update(); |
|
151 | 151 | |
152 | 152 | if ($res > 0) |
153 | 153 | { |
@@ -161,7 +161,7 @@ discard block |
||
161 | 161 | print "\n"; |
162 | 162 | } else { // Group creation |
163 | 163 | print $langs->transnoentities("GroupCreate").' # '.$key.': name='.$group->name; |
164 | - $res=$group->create(); |
|
164 | + $res = $group->create(); |
|
165 | 165 | |
166 | 166 | if ($res > 0) |
167 | 167 | { |
@@ -181,24 +181,24 @@ discard block |
||
181 | 181 | // 1 - Association des utilisateurs du groupe LDAP au groupe Dolibarr |
182 | 182 | $userList = array(); |
183 | 183 | $userIdList = array(); |
184 | - foreach($ldapgroup[$conf->global->LDAP_GROUP_FIELD_GROUPMEMBERS] as $key => $userdn) { |
|
185 | - if($key === 'count') continue; |
|
186 | - if(empty($userList[$userdn])) { // Récupération de l'utilisateur |
|
184 | + foreach ($ldapgroup[$conf->global->LDAP_GROUP_FIELD_GROUPMEMBERS] as $key => $userdn) { |
|
185 | + if ($key === 'count') continue; |
|
186 | + if (empty($userList[$userdn])) { // Récupération de l'utilisateur |
|
187 | 187 | // Schéma rfc2307: les membres sont listés dans l'attribut memberUid sous form de login uniquement |
188 | - if ($conf->global->LDAP_GROUP_FIELD_GROUPMEMBERS === 'memberUid'){ |
|
188 | + if ($conf->global->LDAP_GROUP_FIELD_GROUPMEMBERS === 'memberUid') { |
|
189 | 189 | $userKey = array($userdn); |
190 | 190 | } else { // Pour les autres schémas, les membres sont listés sous forme de DN complets |
191 | 191 | $userFilter = explode(',', $userdn); |
192 | 192 | $userKey = $ldap->getAttributeValues('('.$userFilter[0].')', $conf->global->LDAP_KEY_USERS); |
193 | 193 | } |
194 | - if(!is_array($userKey)) continue; |
|
194 | + if (!is_array($userKey)) continue; |
|
195 | 195 | |
196 | 196 | $fuser = new User($db); |
197 | 197 | |
198 | - if($conf->global->LDAP_KEY_USERS == $conf->global->LDAP_FIELD_SID) { |
|
199 | - $fuser->fetch('','',$userKey[0]); // Chargement du user concerné par le SID |
|
200 | - } else if($conf->global->LDAP_KEY_USERS == $conf->global->LDAP_FIELD_LOGIN) { |
|
201 | - $fuser->fetch('',$userKey[0]); // Chargement du user concerné par le login |
|
198 | + if ($conf->global->LDAP_KEY_USERS == $conf->global->LDAP_FIELD_SID) { |
|
199 | + $fuser->fetch('', '', $userKey[0]); // Chargement du user concerné par le SID |
|
200 | + } else if ($conf->global->LDAP_KEY_USERS == $conf->global->LDAP_FIELD_LOGIN) { |
|
201 | + $fuser->fetch('', $userKey[0]); // Chargement du user concerné par le login |
|
202 | 202 | } |
203 | 203 | |
204 | 204 | $userList[$userdn] = $fuser; |
@@ -209,7 +209,7 @@ discard block |
||
209 | 209 | $userIdList[$userdn] = $fuser->id; |
210 | 210 | |
211 | 211 | // Ajout de l'utilisateur dans le groupe |
212 | - if(!in_array($fuser->id, array_keys($group->members))) { |
|
212 | + if (!in_array($fuser->id, array_keys($group->members))) { |
|
213 | 213 | $fuser->SetInGroup($group->id, $group->entity); |
214 | 214 | echo $fuser->login.' added'."\n"; |
215 | 215 | } |
@@ -217,35 +217,35 @@ discard block |
||
217 | 217 | |
218 | 218 | // 2 - Suppression des utilisateurs du groupe Dolibarr qui ne sont plus dans le groupe LDAP |
219 | 219 | foreach ($group->members as $guser) { |
220 | - if(!in_array($guser->id, $userIdList)) { |
|
220 | + if (!in_array($guser->id, $userIdList)) { |
|
221 | 221 | $guser->RemoveFromGroup($group->id, $group->entity); |
222 | 222 | echo $guser->login.' removed'."\n"; |
223 | 223 | } |
224 | 224 | } |
225 | 225 | } |
226 | 226 | |
227 | - if (! $error || $forcecommit) |
|
227 | + if (!$error || $forcecommit) |
|
228 | 228 | { |
229 | - if (! $error) print $langs->transnoentities("NoErrorCommitIsDone")."\n"; |
|
229 | + if (!$error) print $langs->transnoentities("NoErrorCommitIsDone")."\n"; |
|
230 | 230 | else print $langs->transnoentities("ErrorButCommitIsDone")."\n"; |
231 | 231 | $db->commit(); |
232 | 232 | } |
233 | 233 | else |
234 | 234 | { |
235 | - print $langs->transnoentities("ErrorSomeErrorWereFoundRollbackIsDone",$error)."\n"; |
|
235 | + print $langs->transnoentities("ErrorSomeErrorWereFoundRollbackIsDone", $error)."\n"; |
|
236 | 236 | $db->rollback(); |
237 | 237 | } |
238 | 238 | print "\n"; |
239 | 239 | } |
240 | 240 | else |
241 | 241 | { |
242 | - dol_print_error('',$ldap->error); |
|
242 | + dol_print_error('', $ldap->error); |
|
243 | 243 | $error++; |
244 | 244 | } |
245 | 245 | } |
246 | 246 | else |
247 | 247 | { |
248 | - dol_print_error('',$ldap->error); |
|
248 | + dol_print_error('', $ldap->error); |
|
249 | 249 | $error++; |
250 | 250 | } |
251 | 251 |
@@ -78,11 +78,19 @@ discard block |
||
78 | 78 | |
79 | 79 | foreach($argv as $key => $val) |
80 | 80 | { |
81 | - if ($val == 'commitiferror') $forcecommit=1; |
|
82 | - if (preg_match('/--server=([^\s]+)$/',$val,$reg)) $conf->global->LDAP_SERVER_HOST=$reg[1]; |
|
83 | - if (preg_match('/--excludeuser=([^\s]+)$/',$val,$reg)) $excludeuser=explode(',',$reg[1]); |
|
84 | - if (preg_match('/-y$/',$val,$reg)) $confirmed=1; |
|
85 | -} |
|
81 | + if ($val == 'commitiferror') { |
|
82 | + $forcecommit=1; |
|
83 | + } |
|
84 | + if (preg_match('/--server=([^\s]+)$/',$val,$reg)) { |
|
85 | + $conf->global->LDAP_SERVER_HOST=$reg[1]; |
|
86 | + } |
|
87 | + if (preg_match('/--excludeuser=([^\s]+)$/',$val,$reg)) { |
|
88 | + $excludeuser=explode(',',$reg[1]); |
|
89 | + } |
|
90 | + if (preg_match('/-y$/',$val,$reg)) { |
|
91 | + $confirmed=1; |
|
92 | + } |
|
93 | + } |
|
86 | 94 | |
87 | 95 | print "Mails sending disabled (useless in batch mode)\n"; |
88 | 96 | $conf->global->MAIN_DISABLE_ALL_MAILS=1; // On bloque les mails |
@@ -152,8 +160,7 @@ discard block |
||
152 | 160 | if ($res > 0) |
153 | 161 | { |
154 | 162 | print ' --> Updated group id='.$group->id.' name='.$group->name; |
155 | - } |
|
156 | - else |
|
163 | + } else |
|
157 | 164 | { |
158 | 165 | $error++; |
159 | 166 | print ' --> '.$res.' '.$group->error; |
@@ -166,8 +173,7 @@ discard block |
||
166 | 173 | if ($res > 0) |
167 | 174 | { |
168 | 175 | print ' --> Created group id='.$group->id.' name='.$group->name; |
169 | - } |
|
170 | - else |
|
176 | + } else |
|
171 | 177 | { |
172 | 178 | $error++; |
173 | 179 | print ' --> '.$res.' '.$group->error; |
@@ -182,7 +188,9 @@ discard block |
||
182 | 188 | $userList = array(); |
183 | 189 | $userIdList = array(); |
184 | 190 | foreach($ldapgroup[$conf->global->LDAP_GROUP_FIELD_GROUPMEMBERS] as $key => $userdn) { |
185 | - if($key === 'count') continue; |
|
191 | + if($key === 'count') { |
|
192 | + continue; |
|
193 | + } |
|
186 | 194 | if(empty($userList[$userdn])) { // Récupération de l'utilisateur |
187 | 195 | // Schéma rfc2307: les membres sont listés dans l'attribut memberUid sous form de login uniquement |
188 | 196 | if ($conf->global->LDAP_GROUP_FIELD_GROUPMEMBERS === 'memberUid'){ |
@@ -191,7 +199,9 @@ discard block |
||
191 | 199 | $userFilter = explode(',', $userdn); |
192 | 200 | $userKey = $ldap->getAttributeValues('('.$userFilter[0].')', $conf->global->LDAP_KEY_USERS); |
193 | 201 | } |
194 | - if(!is_array($userKey)) continue; |
|
202 | + if(!is_array($userKey)) { |
|
203 | + continue; |
|
204 | + } |
|
195 | 205 | |
196 | 206 | $fuser = new User($db); |
197 | 207 | |
@@ -226,24 +236,24 @@ discard block |
||
226 | 236 | |
227 | 237 | if (! $error || $forcecommit) |
228 | 238 | { |
229 | - if (! $error) print $langs->transnoentities("NoErrorCommitIsDone")."\n"; |
|
230 | - else print $langs->transnoentities("ErrorButCommitIsDone")."\n"; |
|
239 | + if (! $error) { |
|
240 | + print $langs->transnoentities("NoErrorCommitIsDone")."\n"; |
|
241 | + } else { |
|
242 | + print $langs->transnoentities("ErrorButCommitIsDone")."\n"; |
|
243 | + } |
|
231 | 244 | $db->commit(); |
232 | - } |
|
233 | - else |
|
245 | + } else |
|
234 | 246 | { |
235 | 247 | print $langs->transnoentities("ErrorSomeErrorWereFoundRollbackIsDone",$error)."\n"; |
236 | 248 | $db->rollback(); |
237 | 249 | } |
238 | 250 | print "\n"; |
239 | - } |
|
240 | - else |
|
251 | + } else |
|
241 | 252 | { |
242 | 253 | dol_print_error('',$ldap->error); |
243 | 254 | $error++; |
244 | 255 | } |
245 | -} |
|
246 | -else |
|
256 | +} else |
|
247 | 257 | { |
248 | 258 | dol_print_error('',$ldap->error); |
249 | 259 | $error++; |
@@ -31,7 +31,7 @@ discard block |
||
31 | 31 | // Test if batch mode |
32 | 32 | if (substr($sapi_type, 0, 3) == 'cgi') { |
33 | 33 | echo "Error: You are using PHP for CGI. To execute ".$script_file." from command line, you must use PHP for CLI mode.\n"; |
34 | - exit(-1); |
|
34 | + exit(-1); |
|
35 | 35 | } |
36 | 36 | |
37 | 37 | require_once $path."../../htdocs/master.inc.php"; |
@@ -59,32 +59,32 @@ discard block |
||
59 | 59 | |
60 | 60 | // List of fields to get from LDAP |
61 | 61 | $required_fields = array( |
62 | - $conf->global->LDAP_KEY_MEMBERS, |
|
63 | - $conf->global->LDAP_FIELD_FULLNAME, |
|
64 | - $conf->global->LDAP_FIELD_LOGIN, |
|
65 | - $conf->global->LDAP_FIELD_LOGIN_SAMBA, |
|
66 | - $conf->global->LDAP_FIELD_PASSWORD, |
|
67 | - $conf->global->LDAP_FIELD_PASSWORD_CRYPTED, |
|
68 | - $conf->global->LDAP_FIELD_NAME, |
|
69 | - $conf->global->LDAP_FIELD_FIRSTNAME, |
|
70 | - $conf->global->LDAP_FIELD_MAIL, |
|
71 | - $conf->global->LDAP_FIELD_PHONE, |
|
72 | - $conf->global->LDAP_FIELD_PHONE_PERSO, |
|
73 | - $conf->global->LDAP_FIELD_MOBILE, |
|
74 | - $conf->global->LDAP_FIELD_FAX, |
|
75 | - $conf->global->LDAP_FIELD_ADDRESS, |
|
76 | - $conf->global->LDAP_FIELD_ZIP, |
|
77 | - $conf->global->LDAP_FIELD_TOWN, |
|
78 | - $conf->global->LDAP_FIELD_COUNTRY, |
|
79 | - $conf->global->LDAP_FIELD_DESCRIPTION, |
|
80 | - $conf->global->LDAP_FIELD_BIRTHDATE, |
|
81 | - $conf->global->LDAP_FIELD_MEMBER_STATUS, |
|
82 | - $conf->global->LDAP_FIELD_MEMBER_END_LASTSUBSCRIPTION, |
|
83 | - // Subscriptions |
|
84 | - $conf->global->LDAP_FIELD_MEMBER_FIRSTSUBSCRIPTION_DATE, |
|
85 | - $conf->global->LDAP_FIELD_MEMBER_FIRSTSUBSCRIPTION_AMOUNT, |
|
86 | - $conf->global->LDAP_FIELD_MEMBER_LASTSUBSCRIPTION_DATE, |
|
87 | - $conf->global->LDAP_FIELD_MEMBER_LASTSUBSCRIPTION_AMOUNT |
|
62 | + $conf->global->LDAP_KEY_MEMBERS, |
|
63 | + $conf->global->LDAP_FIELD_FULLNAME, |
|
64 | + $conf->global->LDAP_FIELD_LOGIN, |
|
65 | + $conf->global->LDAP_FIELD_LOGIN_SAMBA, |
|
66 | + $conf->global->LDAP_FIELD_PASSWORD, |
|
67 | + $conf->global->LDAP_FIELD_PASSWORD_CRYPTED, |
|
68 | + $conf->global->LDAP_FIELD_NAME, |
|
69 | + $conf->global->LDAP_FIELD_FIRSTNAME, |
|
70 | + $conf->global->LDAP_FIELD_MAIL, |
|
71 | + $conf->global->LDAP_FIELD_PHONE, |
|
72 | + $conf->global->LDAP_FIELD_PHONE_PERSO, |
|
73 | + $conf->global->LDAP_FIELD_MOBILE, |
|
74 | + $conf->global->LDAP_FIELD_FAX, |
|
75 | + $conf->global->LDAP_FIELD_ADDRESS, |
|
76 | + $conf->global->LDAP_FIELD_ZIP, |
|
77 | + $conf->global->LDAP_FIELD_TOWN, |
|
78 | + $conf->global->LDAP_FIELD_COUNTRY, |
|
79 | + $conf->global->LDAP_FIELD_DESCRIPTION, |
|
80 | + $conf->global->LDAP_FIELD_BIRTHDATE, |
|
81 | + $conf->global->LDAP_FIELD_MEMBER_STATUS, |
|
82 | + $conf->global->LDAP_FIELD_MEMBER_END_LASTSUBSCRIPTION, |
|
83 | + // Subscriptions |
|
84 | + $conf->global->LDAP_FIELD_MEMBER_FIRSTSUBSCRIPTION_DATE, |
|
85 | + $conf->global->LDAP_FIELD_MEMBER_FIRSTSUBSCRIPTION_AMOUNT, |
|
86 | + $conf->global->LDAP_FIELD_MEMBER_LASTSUBSCRIPTION_DATE, |
|
87 | + $conf->global->LDAP_FIELD_MEMBER_LASTSUBSCRIPTION_AMOUNT |
|
88 | 88 | ); |
89 | 89 | |
90 | 90 | // Remove from required_fields all entries not configured in LDAP (empty) and duplicated |
@@ -93,15 +93,15 @@ discard block |
||
93 | 93 | |
94 | 94 | if (! isset($argv[2]) || ! is_numeric($argv[2])) { |
95 | 95 | print "Usage: $script_file (nocommitiferror|commitiferror) id_member_type [--server=ldapserverhost] [-y]\n"; |
96 | - exit(-1); |
|
96 | + exit(-1); |
|
97 | 97 | } |
98 | 98 | |
99 | 99 | $typeid=$argv[2]; |
100 | 100 | foreach($argv as $key => $val) |
101 | 101 | { |
102 | - if ($val == 'commitiferror') $forcecommit=1; |
|
103 | - if (preg_match('/--server=([^\s]+)$/',$val,$reg)) $conf->global->LDAP_SERVER_HOST=$reg[1]; |
|
104 | - if (preg_match('/-y$/',$val,$reg)) $confirmed=1; |
|
102 | + if ($val == 'commitiferror') $forcecommit=1; |
|
103 | + if (preg_match('/--server=([^\s]+)$/',$val,$reg)) $conf->global->LDAP_SERVER_HOST=$reg[1]; |
|
104 | + if (preg_match('/-y$/',$val,$reg)) $confirmed=1; |
|
105 | 105 | } |
106 | 106 | |
107 | 107 | print "Mails sending disabled (useless in batch mode)\n"; |
@@ -129,20 +129,20 @@ discard block |
||
129 | 129 | // Check parameters |
130 | 130 | if (empty($conf->global->LDAP_MEMBER_DN)) |
131 | 131 | { |
132 | - print $langs->trans("Error").': '.$langs->trans("LDAP setup for members not defined inside Dolibarr")."\n"; |
|
133 | - exit(-1); |
|
132 | + print $langs->trans("Error").': '.$langs->trans("LDAP setup for members not defined inside Dolibarr")."\n"; |
|
133 | + exit(-1); |
|
134 | 134 | } |
135 | 135 | if ($typeid <= 0) |
136 | 136 | { |
137 | - print $langs->trans("Error").': Parameter id_member_type is not a valid ref of an existing member type'."\n"; |
|
138 | - exit(-2); |
|
137 | + print $langs->trans("Error").': Parameter id_member_type is not a valid ref of an existing member type'."\n"; |
|
138 | + exit(-2); |
|
139 | 139 | } |
140 | 140 | |
141 | 141 | |
142 | 142 | if (! $confirmed) |
143 | 143 | { |
144 | - print "Hit Enter to continue or CTRL+C to stop...\n"; |
|
145 | - $input = trim(fgets(STDIN)); |
|
144 | + print "Hit Enter to continue or CTRL+C to stop...\n"; |
|
145 | + $input = trim(fgets(STDIN)); |
|
146 | 146 | } |
147 | 147 | |
148 | 148 | // Load table of correspondence of countries |
@@ -155,27 +155,27 @@ discard block |
||
155 | 155 | $resql=$db->query($sql); |
156 | 156 | if ($resql) |
157 | 157 | { |
158 | - $num = $db->num_rows($resql); |
|
159 | - $i = 0; |
|
160 | - if ($num) |
|
161 | - { |
|
162 | - while ($i < $num) |
|
163 | - { |
|
164 | - $obj = $db->fetch_object($resql); |
|
165 | - if ($obj) |
|
166 | - { |
|
167 | - //print 'Load cache for country '.strtolower($obj->label).' rowid='.$obj->rowid."\n"; |
|
168 | - $hashlib2rowid[strtolower($obj->label)]=$obj->rowid; |
|
169 | - $countries[$obj->rowid]=array('rowid' => $obj->rowid, 'label' => $obj->label, 'code' => $obj->code); |
|
170 | - } |
|
171 | - $i++; |
|
172 | - } |
|
173 | - } |
|
158 | + $num = $db->num_rows($resql); |
|
159 | + $i = 0; |
|
160 | + if ($num) |
|
161 | + { |
|
162 | + while ($i < $num) |
|
163 | + { |
|
164 | + $obj = $db->fetch_object($resql); |
|
165 | + if ($obj) |
|
166 | + { |
|
167 | + //print 'Load cache for country '.strtolower($obj->label).' rowid='.$obj->rowid."\n"; |
|
168 | + $hashlib2rowid[strtolower($obj->label)]=$obj->rowid; |
|
169 | + $countries[$obj->rowid]=array('rowid' => $obj->rowid, 'label' => $obj->label, 'code' => $obj->code); |
|
170 | + } |
|
171 | + $i++; |
|
172 | + } |
|
173 | + } |
|
174 | 174 | } |
175 | 175 | else |
176 | 176 | { |
177 | - dol_print_error($db); |
|
178 | - exit(-1); |
|
177 | + dol_print_error($db); |
|
178 | + exit(-1); |
|
179 | 179 | } |
180 | 180 | |
181 | 181 | |
@@ -184,146 +184,146 @@ discard block |
||
184 | 184 | $result = $ldap->connect_bind(); |
185 | 185 | if ($result >= 0) |
186 | 186 | { |
187 | - $justthese=array(); |
|
188 | - |
|
189 | - |
|
190 | - // We disable synchro Dolibarr-LDAP |
|
191 | - $conf->global->LDAP_MEMBER_ACTIVE=0; |
|
192 | - |
|
193 | - $ldaprecords = $ldap->getRecords('*',$conf->global->LDAP_MEMBER_DN, $conf->global->LDAP_KEY_MEMBERS, $required_fields, 'member'); // Fiter on 'member' filter param |
|
194 | - if (is_array($ldaprecords)) |
|
195 | - { |
|
196 | - $db->begin(); |
|
197 | - |
|
198 | - // Warning $ldapuser has a key in lowercase |
|
199 | - foreach ($ldaprecords as $key => $ldapuser) |
|
200 | - { |
|
201 | - $member = new Adherent($db); |
|
202 | - |
|
203 | - // Propriete membre |
|
204 | - $member->firstname=$ldapuser[$conf->global->LDAP_FIELD_FIRSTNAME]; |
|
205 | - $member->lastname=$ldapuser[$conf->global->LDAP_FIELD_NAME]; |
|
206 | - $member->login=$ldapuser[$conf->global->LDAP_FIELD_LOGIN]; |
|
207 | - $member->pass=$ldapuser[$conf->global->LDAP_FIELD_PASSWORD]; |
|
208 | - |
|
209 | - //$member->societe; |
|
210 | - $member->address=$ldapuser[$conf->global->LDAP_FIELD_ADDRESS]; |
|
211 | - $member->zip=$ldapuser[$conf->global->LDAP_FIELD_ZIP]; |
|
212 | - $member->town=$ldapuser[$conf->global->LDAP_FIELD_TOWN]; |
|
213 | - $member->country=$ldapuser[$conf->global->LDAP_FIELD_COUNTRY]; |
|
214 | - $member->country_id=$countries[$hashlib2rowid[strtolower($member->country)]]['rowid']; |
|
215 | - $member->country_code=$countries[$hashlib2rowid[strtolower($member->country)]]['code']; |
|
216 | - |
|
217 | - $member->phone=$ldapuser[$conf->global->LDAP_FIELD_PHONE]; |
|
218 | - $member->phone_perso=$ldapuser[$conf->global->LDAP_FIELD_PHONE_PERSO]; |
|
219 | - $member->phone_mobile=$ldapuser[$conf->global->LDAP_FIELD_MOBILE]; |
|
220 | - $member->email=$ldapuser[$conf->global->LDAP_FIELD_MAIL]; |
|
221 | - |
|
222 | - $member->note=$ldapuser[$conf->global->LDAP_FIELD_DESCRIPTION]; |
|
223 | - $member->morphy='phy'; |
|
224 | - $member->photo=''; |
|
225 | - $member->public=1; |
|
226 | - $member->birth=dol_stringtotime($ldapuser[$conf->global->LDAP_FIELD_BIRTHDATE]); |
|
227 | - |
|
228 | - $member->statut=-1; |
|
229 | - if (isset($ldapuser[$conf->global->LDAP_FIELD_MEMBER_STATUS])) |
|
230 | - { |
|
231 | - $member->datec=dol_stringtotime($ldapuser[$conf->global->LDAP_FIELD_MEMBER_FIRSTSUBSCRIPTION_DATE]); |
|
232 | - $member->datevalid=dol_stringtotime($ldapuser[$conf->global->LDAP_FIELD_MEMBER_FIRSTSUBSCRIPTION_DATE]); |
|
233 | - $member->statut=$ldapuser[$conf->global->LDAP_FIELD_MEMBER_STATUS]; |
|
234 | - } |
|
235 | - //if ($member->statut > 1) $member->statut=1; |
|
236 | - |
|
237 | - //print_r($ldapuser); |
|
238 | - |
|
239 | - // Propriete type membre |
|
240 | - $member->typeid=$typeid; |
|
241 | - |
|
242 | - // Creation membre |
|
243 | - print $langs->transnoentities("MemberCreate").' # '.$key.': login='.$member->login.', fullname='.$member->getFullName($langs); |
|
244 | - print ', datec='.$member->datec; |
|
245 | - $member_id=$member->create($user); |
|
246 | - if ($member_id > 0) |
|
247 | - { |
|
248 | - print ' --> Created member id='.$member_id.' login='.$member->login; |
|
249 | - } |
|
250 | - else |
|
251 | - { |
|
252 | - $error++; |
|
253 | - print ' --> '.$member->error; |
|
254 | - } |
|
255 | - print "\n"; |
|
256 | - |
|
257 | - //print_r($member); |
|
258 | - |
|
259 | - $datefirst=''; |
|
260 | - if ($conf->global->LDAP_FIELD_MEMBER_FIRSTSUBSCRIPTION_DATE) |
|
261 | - { |
|
262 | - $datefirst=dol_stringtotime($ldapuser[$conf->global->LDAP_FIELD_MEMBER_FIRSTSUBSCRIPTION_DATE]); |
|
263 | - $pricefirst=price2num($ldapuser[$conf->global->LDAP_FIELD_MEMBER_FIRSTSUBSCRIPTION_AMOUNT]); |
|
264 | - } |
|
265 | - |
|
266 | - $datelast=''; |
|
267 | - if ($conf->global->LDAP_FIELD_MEMBER_LASTSUBSCRIPTION_DATE) |
|
268 | - { |
|
269 | - $datelast=dol_stringtotime($ldapuser[$conf->global->LDAP_FIELD_MEMBER_LASTSUBSCRIPTION_DATE]); |
|
270 | - $pricelast=price2num($ldapuser[$conf->global->LDAP_FIELD_MEMBER_LASTSUBSCRIPTION_AMOUNT]); |
|
271 | - } |
|
272 | - elseif ($conf->global->LDAP_FIELD_MEMBER_END_LASTSUBSCRIPTION) |
|
273 | - { |
|
274 | - $datelast=dol_time_plus_duree(dol_stringtotime($ldapuser[$conf->global->LDAP_FIELD_MEMBER_END_LASTSUBSCRIPTION]),-1,'y')+60*60*24; |
|
275 | - $pricelast=price2num($ldapuser[$conf->global->LDAP_FIELD_MEMBER_LASTSUBSCRIPTION_AMOUNT]); |
|
276 | - |
|
277 | - // Cas special ou date derniere <= date premiere |
|
278 | - if ($datefirst && $datelast && $datelast <= $datefirst) |
|
279 | - { |
|
280 | - // On ne va inserer que la premiere |
|
281 | - $datelast=0; |
|
282 | - if (! $pricefirst && $pricelast) $pricefirst = $pricelast; |
|
283 | - } |
|
284 | - } |
|
285 | - |
|
286 | - |
|
287 | - // Insert first subscription |
|
288 | - if ($datefirst) |
|
289 | - { |
|
290 | - // Cree premiere cotisation et met a jour datefin dans adherent |
|
291 | - //print "xx".$datefirst."\n"; |
|
292 | - $crowid=$member->subscription($datefirst, $pricefirst, 0); |
|
293 | - } |
|
294 | - |
|
295 | - // Insert last subscription |
|
296 | - if ($datelast) |
|
297 | - { |
|
298 | - // Cree derniere cotisation et met a jour datefin dans adherent |
|
299 | - //print "yy".dol_print_date($datelast)."\n"; |
|
300 | - $crowid=$member->subscription($datelast, $pricelast, 0); |
|
301 | - } |
|
302 | - } |
|
303 | - |
|
304 | - if (! $error || $forcecommit) |
|
305 | - { |
|
306 | - if (! $error) print $langs->transnoentities("NoErrorCommitIsDone")."\n"; |
|
307 | - else print $langs->transnoentities("ErrorButCommitIsDone")."\n"; |
|
308 | - $db->commit(); |
|
309 | - } |
|
310 | - else |
|
311 | - { |
|
312 | - print $langs->transnoentities("ErrorSomeErrorWereFoundRollbackIsDone",$error)."\n"; |
|
313 | - $db->rollback(); |
|
314 | - } |
|
315 | - print "\n"; |
|
316 | - } |
|
317 | - else |
|
318 | - { |
|
319 | - dol_print_error('',$ldap->error); |
|
320 | - $error++; |
|
321 | - } |
|
187 | + $justthese=array(); |
|
188 | + |
|
189 | + |
|
190 | + // We disable synchro Dolibarr-LDAP |
|
191 | + $conf->global->LDAP_MEMBER_ACTIVE=0; |
|
192 | + |
|
193 | + $ldaprecords = $ldap->getRecords('*',$conf->global->LDAP_MEMBER_DN, $conf->global->LDAP_KEY_MEMBERS, $required_fields, 'member'); // Fiter on 'member' filter param |
|
194 | + if (is_array($ldaprecords)) |
|
195 | + { |
|
196 | + $db->begin(); |
|
197 | + |
|
198 | + // Warning $ldapuser has a key in lowercase |
|
199 | + foreach ($ldaprecords as $key => $ldapuser) |
|
200 | + { |
|
201 | + $member = new Adherent($db); |
|
202 | + |
|
203 | + // Propriete membre |
|
204 | + $member->firstname=$ldapuser[$conf->global->LDAP_FIELD_FIRSTNAME]; |
|
205 | + $member->lastname=$ldapuser[$conf->global->LDAP_FIELD_NAME]; |
|
206 | + $member->login=$ldapuser[$conf->global->LDAP_FIELD_LOGIN]; |
|
207 | + $member->pass=$ldapuser[$conf->global->LDAP_FIELD_PASSWORD]; |
|
208 | + |
|
209 | + //$member->societe; |
|
210 | + $member->address=$ldapuser[$conf->global->LDAP_FIELD_ADDRESS]; |
|
211 | + $member->zip=$ldapuser[$conf->global->LDAP_FIELD_ZIP]; |
|
212 | + $member->town=$ldapuser[$conf->global->LDAP_FIELD_TOWN]; |
|
213 | + $member->country=$ldapuser[$conf->global->LDAP_FIELD_COUNTRY]; |
|
214 | + $member->country_id=$countries[$hashlib2rowid[strtolower($member->country)]]['rowid']; |
|
215 | + $member->country_code=$countries[$hashlib2rowid[strtolower($member->country)]]['code']; |
|
216 | + |
|
217 | + $member->phone=$ldapuser[$conf->global->LDAP_FIELD_PHONE]; |
|
218 | + $member->phone_perso=$ldapuser[$conf->global->LDAP_FIELD_PHONE_PERSO]; |
|
219 | + $member->phone_mobile=$ldapuser[$conf->global->LDAP_FIELD_MOBILE]; |
|
220 | + $member->email=$ldapuser[$conf->global->LDAP_FIELD_MAIL]; |
|
221 | + |
|
222 | + $member->note=$ldapuser[$conf->global->LDAP_FIELD_DESCRIPTION]; |
|
223 | + $member->morphy='phy'; |
|
224 | + $member->photo=''; |
|
225 | + $member->public=1; |
|
226 | + $member->birth=dol_stringtotime($ldapuser[$conf->global->LDAP_FIELD_BIRTHDATE]); |
|
227 | + |
|
228 | + $member->statut=-1; |
|
229 | + if (isset($ldapuser[$conf->global->LDAP_FIELD_MEMBER_STATUS])) |
|
230 | + { |
|
231 | + $member->datec=dol_stringtotime($ldapuser[$conf->global->LDAP_FIELD_MEMBER_FIRSTSUBSCRIPTION_DATE]); |
|
232 | + $member->datevalid=dol_stringtotime($ldapuser[$conf->global->LDAP_FIELD_MEMBER_FIRSTSUBSCRIPTION_DATE]); |
|
233 | + $member->statut=$ldapuser[$conf->global->LDAP_FIELD_MEMBER_STATUS]; |
|
234 | + } |
|
235 | + //if ($member->statut > 1) $member->statut=1; |
|
236 | + |
|
237 | + //print_r($ldapuser); |
|
238 | + |
|
239 | + // Propriete type membre |
|
240 | + $member->typeid=$typeid; |
|
241 | + |
|
242 | + // Creation membre |
|
243 | + print $langs->transnoentities("MemberCreate").' # '.$key.': login='.$member->login.', fullname='.$member->getFullName($langs); |
|
244 | + print ', datec='.$member->datec; |
|
245 | + $member_id=$member->create($user); |
|
246 | + if ($member_id > 0) |
|
247 | + { |
|
248 | + print ' --> Created member id='.$member_id.' login='.$member->login; |
|
249 | + } |
|
250 | + else |
|
251 | + { |
|
252 | + $error++; |
|
253 | + print ' --> '.$member->error; |
|
254 | + } |
|
255 | + print "\n"; |
|
256 | + |
|
257 | + //print_r($member); |
|
258 | + |
|
259 | + $datefirst=''; |
|
260 | + if ($conf->global->LDAP_FIELD_MEMBER_FIRSTSUBSCRIPTION_DATE) |
|
261 | + { |
|
262 | + $datefirst=dol_stringtotime($ldapuser[$conf->global->LDAP_FIELD_MEMBER_FIRSTSUBSCRIPTION_DATE]); |
|
263 | + $pricefirst=price2num($ldapuser[$conf->global->LDAP_FIELD_MEMBER_FIRSTSUBSCRIPTION_AMOUNT]); |
|
264 | + } |
|
265 | + |
|
266 | + $datelast=''; |
|
267 | + if ($conf->global->LDAP_FIELD_MEMBER_LASTSUBSCRIPTION_DATE) |
|
268 | + { |
|
269 | + $datelast=dol_stringtotime($ldapuser[$conf->global->LDAP_FIELD_MEMBER_LASTSUBSCRIPTION_DATE]); |
|
270 | + $pricelast=price2num($ldapuser[$conf->global->LDAP_FIELD_MEMBER_LASTSUBSCRIPTION_AMOUNT]); |
|
271 | + } |
|
272 | + elseif ($conf->global->LDAP_FIELD_MEMBER_END_LASTSUBSCRIPTION) |
|
273 | + { |
|
274 | + $datelast=dol_time_plus_duree(dol_stringtotime($ldapuser[$conf->global->LDAP_FIELD_MEMBER_END_LASTSUBSCRIPTION]),-1,'y')+60*60*24; |
|
275 | + $pricelast=price2num($ldapuser[$conf->global->LDAP_FIELD_MEMBER_LASTSUBSCRIPTION_AMOUNT]); |
|
276 | + |
|
277 | + // Cas special ou date derniere <= date premiere |
|
278 | + if ($datefirst && $datelast && $datelast <= $datefirst) |
|
279 | + { |
|
280 | + // On ne va inserer que la premiere |
|
281 | + $datelast=0; |
|
282 | + if (! $pricefirst && $pricelast) $pricefirst = $pricelast; |
|
283 | + } |
|
284 | + } |
|
285 | + |
|
286 | + |
|
287 | + // Insert first subscription |
|
288 | + if ($datefirst) |
|
289 | + { |
|
290 | + // Cree premiere cotisation et met a jour datefin dans adherent |
|
291 | + //print "xx".$datefirst."\n"; |
|
292 | + $crowid=$member->subscription($datefirst, $pricefirst, 0); |
|
293 | + } |
|
294 | + |
|
295 | + // Insert last subscription |
|
296 | + if ($datelast) |
|
297 | + { |
|
298 | + // Cree derniere cotisation et met a jour datefin dans adherent |
|
299 | + //print "yy".dol_print_date($datelast)."\n"; |
|
300 | + $crowid=$member->subscription($datelast, $pricelast, 0); |
|
301 | + } |
|
302 | + } |
|
303 | + |
|
304 | + if (! $error || $forcecommit) |
|
305 | + { |
|
306 | + if (! $error) print $langs->transnoentities("NoErrorCommitIsDone")."\n"; |
|
307 | + else print $langs->transnoentities("ErrorButCommitIsDone")."\n"; |
|
308 | + $db->commit(); |
|
309 | + } |
|
310 | + else |
|
311 | + { |
|
312 | + print $langs->transnoentities("ErrorSomeErrorWereFoundRollbackIsDone",$error)."\n"; |
|
313 | + $db->rollback(); |
|
314 | + } |
|
315 | + print "\n"; |
|
316 | + } |
|
317 | + else |
|
318 | + { |
|
319 | + dol_print_error('',$ldap->error); |
|
320 | + $error++; |
|
321 | + } |
|
322 | 322 | } |
323 | 323 | else |
324 | 324 | { |
325 | - dol_print_error('',$ldap->error); |
|
326 | - $error++; |
|
325 | + dol_print_error('',$ldap->error); |
|
326 | + $error++; |
|
327 | 327 | } |
328 | 328 | |
329 | 329 | |
@@ -338,6 +338,6 @@ discard block |
||
338 | 338 | */ |
339 | 339 | function dolValidElement($element) |
340 | 340 | { |
341 | - return (trim($element) != ''); |
|
341 | + return (trim($element) != ''); |
|
342 | 342 | } |
343 | 343 |
@@ -26,7 +26,7 @@ discard block |
||
26 | 26 | |
27 | 27 | $sapi_type = php_sapi_name(); |
28 | 28 | $script_file = basename(__FILE__); |
29 | -$path=dirname(__FILE__).'/'; |
|
29 | +$path = dirname(__FILE__).'/'; |
|
30 | 30 | |
31 | 31 | // Test if batch mode |
32 | 32 | if (substr($sapi_type, 0, 3) == 'cgi') { |
@@ -43,10 +43,10 @@ discard block |
||
43 | 43 | $langs->loadLangs(array("main", "errors")); |
44 | 44 | |
45 | 45 | // Global variables |
46 | -$version=DOL_VERSION; |
|
47 | -$error=0; |
|
48 | -$forcecommit=0; |
|
49 | -$confirmed=0; |
|
46 | +$version = DOL_VERSION; |
|
47 | +$error = 0; |
|
48 | +$forcecommit = 0; |
|
49 | +$confirmed = 0; |
|
50 | 50 | |
51 | 51 | |
52 | 52 | /* |
@@ -55,7 +55,7 @@ discard block |
||
55 | 55 | |
56 | 56 | @set_time_limit(0); |
57 | 57 | print "***** ".$script_file." (".$version.") pid=".dol_getmypid()." *****\n"; |
58 | -dol_syslog($script_file." launched with arg ".join(',',$argv)); |
|
58 | +dol_syslog($script_file." launched with arg ".join(',', $argv)); |
|
59 | 59 | |
60 | 60 | // List of fields to get from LDAP |
61 | 61 | $required_fields = array( |
@@ -88,32 +88,32 @@ discard block |
||
88 | 88 | ); |
89 | 89 | |
90 | 90 | // Remove from required_fields all entries not configured in LDAP (empty) and duplicated |
91 | -$required_fields=array_unique(array_values(array_filter($required_fields, "dolValidElement"))); |
|
91 | +$required_fields = array_unique(array_values(array_filter($required_fields, "dolValidElement"))); |
|
92 | 92 | |
93 | 93 | |
94 | -if (! isset($argv[2]) || ! is_numeric($argv[2])) { |
|
94 | +if (!isset($argv[2]) || !is_numeric($argv[2])) { |
|
95 | 95 | print "Usage: $script_file (nocommitiferror|commitiferror) id_member_type [--server=ldapserverhost] [-y]\n"; |
96 | 96 | exit(-1); |
97 | 97 | } |
98 | 98 | |
99 | -$typeid=$argv[2]; |
|
100 | -foreach($argv as $key => $val) |
|
99 | +$typeid = $argv[2]; |
|
100 | +foreach ($argv as $key => $val) |
|
101 | 101 | { |
102 | - if ($val == 'commitiferror') $forcecommit=1; |
|
103 | - if (preg_match('/--server=([^\s]+)$/',$val,$reg)) $conf->global->LDAP_SERVER_HOST=$reg[1]; |
|
104 | - if (preg_match('/-y$/',$val,$reg)) $confirmed=1; |
|
102 | + if ($val == 'commitiferror') $forcecommit = 1; |
|
103 | + if (preg_match('/--server=([^\s]+)$/', $val, $reg)) $conf->global->LDAP_SERVER_HOST = $reg[1]; |
|
104 | + if (preg_match('/-y$/', $val, $reg)) $confirmed = 1; |
|
105 | 105 | } |
106 | 106 | |
107 | 107 | print "Mails sending disabled (useless in batch mode)\n"; |
108 | -$conf->global->MAIN_DISABLE_ALL_MAILS=1; // On bloque les mails |
|
108 | +$conf->global->MAIN_DISABLE_ALL_MAILS = 1; // On bloque les mails |
|
109 | 109 | print "\n"; |
110 | 110 | print "----- Synchronize all records from LDAP database:\n"; |
111 | 111 | print "host=".$conf->global->LDAP_SERVER_HOST."\n"; |
112 | 112 | print "port=".$conf->global->LDAP_SERVER_PORT."\n"; |
113 | 113 | print "login=".$conf->global->LDAP_ADMIN_DN."\n"; |
114 | -print "pass=".preg_replace('/./i','*',$conf->global->LDAP_ADMIN_PASS)."\n"; |
|
114 | +print "pass=".preg_replace('/./i', '*', $conf->global->LDAP_ADMIN_PASS)."\n"; |
|
115 | 115 | print "DN to extract=".$conf->global->LDAP_MEMBER_DN."\n"; |
116 | -if (! empty($conf->global->LDAP_MEMBER_FILTER)) print 'Filter=('.$conf->global->LDAP_MEMBER_FILTER.')'."\n"; // Note: filter is defined into function getRecords |
|
116 | +if (!empty($conf->global->LDAP_MEMBER_FILTER)) print 'Filter=('.$conf->global->LDAP_MEMBER_FILTER.')'."\n"; // Note: filter is defined into function getRecords |
|
117 | 117 | else print 'Filter=('.$conf->global->LDAP_KEY_MEMBERS.'=*)'."\n"; |
118 | 118 | print "----- To Dolibarr database:\n"; |
119 | 119 | print "type=".$conf->db->type."\n"; |
@@ -123,7 +123,7 @@ discard block |
||
123 | 123 | print "database=".$conf->db->name."\n"; |
124 | 124 | print "----- Options:\n"; |
125 | 125 | print "commitiferror=".$forcecommit."\n"; |
126 | -print "Mapped LDAP fields=".join(',',$required_fields)."\n"; |
|
126 | +print "Mapped LDAP fields=".join(',', $required_fields)."\n"; |
|
127 | 127 | print "\n"; |
128 | 128 | |
129 | 129 | // Check parameters |
@@ -139,20 +139,20 @@ discard block |
||
139 | 139 | } |
140 | 140 | |
141 | 141 | |
142 | -if (! $confirmed) |
|
142 | +if (!$confirmed) |
|
143 | 143 | { |
144 | 144 | print "Hit Enter to continue or CTRL+C to stop...\n"; |
145 | 145 | $input = trim(fgets(STDIN)); |
146 | 146 | } |
147 | 147 | |
148 | 148 | // Load table of correspondence of countries |
149 | -$hashlib2rowid=array(); |
|
150 | -$countries=array(); |
|
149 | +$hashlib2rowid = array(); |
|
150 | +$countries = array(); |
|
151 | 151 | $sql = "SELECT rowid, code, label, active"; |
152 | -$sql.= " FROM ".MAIN_DB_PREFIX."c_country"; |
|
153 | -$sql.= " WHERE active = 1"; |
|
154 | -$sql.= " ORDER BY code ASC"; |
|
155 | -$resql=$db->query($sql); |
|
152 | +$sql .= " FROM ".MAIN_DB_PREFIX."c_country"; |
|
153 | +$sql .= " WHERE active = 1"; |
|
154 | +$sql .= " ORDER BY code ASC"; |
|
155 | +$resql = $db->query($sql); |
|
156 | 156 | if ($resql) |
157 | 157 | { |
158 | 158 | $num = $db->num_rows($resql); |
@@ -165,8 +165,8 @@ discard block |
||
165 | 165 | if ($obj) |
166 | 166 | { |
167 | 167 | //print 'Load cache for country '.strtolower($obj->label).' rowid='.$obj->rowid."\n"; |
168 | - $hashlib2rowid[strtolower($obj->label)]=$obj->rowid; |
|
169 | - $countries[$obj->rowid]=array('rowid' => $obj->rowid, 'label' => $obj->label, 'code' => $obj->code); |
|
168 | + $hashlib2rowid[strtolower($obj->label)] = $obj->rowid; |
|
169 | + $countries[$obj->rowid] = array('rowid' => $obj->rowid, 'label' => $obj->label, 'code' => $obj->code); |
|
170 | 170 | } |
171 | 171 | $i++; |
172 | 172 | } |
@@ -184,13 +184,13 @@ discard block |
||
184 | 184 | $result = $ldap->connect_bind(); |
185 | 185 | if ($result >= 0) |
186 | 186 | { |
187 | - $justthese=array(); |
|
187 | + $justthese = array(); |
|
188 | 188 | |
189 | 189 | |
190 | 190 | // We disable synchro Dolibarr-LDAP |
191 | - $conf->global->LDAP_MEMBER_ACTIVE=0; |
|
191 | + $conf->global->LDAP_MEMBER_ACTIVE = 0; |
|
192 | 192 | |
193 | - $ldaprecords = $ldap->getRecords('*',$conf->global->LDAP_MEMBER_DN, $conf->global->LDAP_KEY_MEMBERS, $required_fields, 'member'); // Fiter on 'member' filter param |
|
193 | + $ldaprecords = $ldap->getRecords('*', $conf->global->LDAP_MEMBER_DN, $conf->global->LDAP_KEY_MEMBERS, $required_fields, 'member'); // Fiter on 'member' filter param |
|
194 | 194 | if (is_array($ldaprecords)) |
195 | 195 | { |
196 | 196 | $db->begin(); |
@@ -201,48 +201,48 @@ discard block |
||
201 | 201 | $member = new Adherent($db); |
202 | 202 | |
203 | 203 | // Propriete membre |
204 | - $member->firstname=$ldapuser[$conf->global->LDAP_FIELD_FIRSTNAME]; |
|
205 | - $member->lastname=$ldapuser[$conf->global->LDAP_FIELD_NAME]; |
|
206 | - $member->login=$ldapuser[$conf->global->LDAP_FIELD_LOGIN]; |
|
207 | - $member->pass=$ldapuser[$conf->global->LDAP_FIELD_PASSWORD]; |
|
204 | + $member->firstname = $ldapuser[$conf->global->LDAP_FIELD_FIRSTNAME]; |
|
205 | + $member->lastname = $ldapuser[$conf->global->LDAP_FIELD_NAME]; |
|
206 | + $member->login = $ldapuser[$conf->global->LDAP_FIELD_LOGIN]; |
|
207 | + $member->pass = $ldapuser[$conf->global->LDAP_FIELD_PASSWORD]; |
|
208 | 208 | |
209 | 209 | //$member->societe; |
210 | - $member->address=$ldapuser[$conf->global->LDAP_FIELD_ADDRESS]; |
|
211 | - $member->zip=$ldapuser[$conf->global->LDAP_FIELD_ZIP]; |
|
212 | - $member->town=$ldapuser[$conf->global->LDAP_FIELD_TOWN]; |
|
213 | - $member->country=$ldapuser[$conf->global->LDAP_FIELD_COUNTRY]; |
|
214 | - $member->country_id=$countries[$hashlib2rowid[strtolower($member->country)]]['rowid']; |
|
215 | - $member->country_code=$countries[$hashlib2rowid[strtolower($member->country)]]['code']; |
|
216 | - |
|
217 | - $member->phone=$ldapuser[$conf->global->LDAP_FIELD_PHONE]; |
|
218 | - $member->phone_perso=$ldapuser[$conf->global->LDAP_FIELD_PHONE_PERSO]; |
|
219 | - $member->phone_mobile=$ldapuser[$conf->global->LDAP_FIELD_MOBILE]; |
|
220 | - $member->email=$ldapuser[$conf->global->LDAP_FIELD_MAIL]; |
|
221 | - |
|
222 | - $member->note=$ldapuser[$conf->global->LDAP_FIELD_DESCRIPTION]; |
|
223 | - $member->morphy='phy'; |
|
224 | - $member->photo=''; |
|
225 | - $member->public=1; |
|
226 | - $member->birth=dol_stringtotime($ldapuser[$conf->global->LDAP_FIELD_BIRTHDATE]); |
|
227 | - |
|
228 | - $member->statut=-1; |
|
210 | + $member->address = $ldapuser[$conf->global->LDAP_FIELD_ADDRESS]; |
|
211 | + $member->zip = $ldapuser[$conf->global->LDAP_FIELD_ZIP]; |
|
212 | + $member->town = $ldapuser[$conf->global->LDAP_FIELD_TOWN]; |
|
213 | + $member->country = $ldapuser[$conf->global->LDAP_FIELD_COUNTRY]; |
|
214 | + $member->country_id = $countries[$hashlib2rowid[strtolower($member->country)]]['rowid']; |
|
215 | + $member->country_code = $countries[$hashlib2rowid[strtolower($member->country)]]['code']; |
|
216 | + |
|
217 | + $member->phone = $ldapuser[$conf->global->LDAP_FIELD_PHONE]; |
|
218 | + $member->phone_perso = $ldapuser[$conf->global->LDAP_FIELD_PHONE_PERSO]; |
|
219 | + $member->phone_mobile = $ldapuser[$conf->global->LDAP_FIELD_MOBILE]; |
|
220 | + $member->email = $ldapuser[$conf->global->LDAP_FIELD_MAIL]; |
|
221 | + |
|
222 | + $member->note = $ldapuser[$conf->global->LDAP_FIELD_DESCRIPTION]; |
|
223 | + $member->morphy = 'phy'; |
|
224 | + $member->photo = ''; |
|
225 | + $member->public = 1; |
|
226 | + $member->birth = dol_stringtotime($ldapuser[$conf->global->LDAP_FIELD_BIRTHDATE]); |
|
227 | + |
|
228 | + $member->statut = -1; |
|
229 | 229 | if (isset($ldapuser[$conf->global->LDAP_FIELD_MEMBER_STATUS])) |
230 | 230 | { |
231 | - $member->datec=dol_stringtotime($ldapuser[$conf->global->LDAP_FIELD_MEMBER_FIRSTSUBSCRIPTION_DATE]); |
|
232 | - $member->datevalid=dol_stringtotime($ldapuser[$conf->global->LDAP_FIELD_MEMBER_FIRSTSUBSCRIPTION_DATE]); |
|
233 | - $member->statut=$ldapuser[$conf->global->LDAP_FIELD_MEMBER_STATUS]; |
|
231 | + $member->datec = dol_stringtotime($ldapuser[$conf->global->LDAP_FIELD_MEMBER_FIRSTSUBSCRIPTION_DATE]); |
|
232 | + $member->datevalid = dol_stringtotime($ldapuser[$conf->global->LDAP_FIELD_MEMBER_FIRSTSUBSCRIPTION_DATE]); |
|
233 | + $member->statut = $ldapuser[$conf->global->LDAP_FIELD_MEMBER_STATUS]; |
|
234 | 234 | } |
235 | 235 | //if ($member->statut > 1) $member->statut=1; |
236 | 236 | |
237 | 237 | //print_r($ldapuser); |
238 | 238 | |
239 | 239 | // Propriete type membre |
240 | - $member->typeid=$typeid; |
|
240 | + $member->typeid = $typeid; |
|
241 | 241 | |
242 | 242 | // Creation membre |
243 | 243 | print $langs->transnoentities("MemberCreate").' # '.$key.': login='.$member->login.', fullname='.$member->getFullName($langs); |
244 | 244 | print ', datec='.$member->datec; |
245 | - $member_id=$member->create($user); |
|
245 | + $member_id = $member->create($user); |
|
246 | 246 | if ($member_id > 0) |
247 | 247 | { |
248 | 248 | print ' --> Created member id='.$member_id.' login='.$member->login; |
@@ -256,30 +256,30 @@ discard block |
||
256 | 256 | |
257 | 257 | //print_r($member); |
258 | 258 | |
259 | - $datefirst=''; |
|
259 | + $datefirst = ''; |
|
260 | 260 | if ($conf->global->LDAP_FIELD_MEMBER_FIRSTSUBSCRIPTION_DATE) |
261 | 261 | { |
262 | - $datefirst=dol_stringtotime($ldapuser[$conf->global->LDAP_FIELD_MEMBER_FIRSTSUBSCRIPTION_DATE]); |
|
263 | - $pricefirst=price2num($ldapuser[$conf->global->LDAP_FIELD_MEMBER_FIRSTSUBSCRIPTION_AMOUNT]); |
|
262 | + $datefirst = dol_stringtotime($ldapuser[$conf->global->LDAP_FIELD_MEMBER_FIRSTSUBSCRIPTION_DATE]); |
|
263 | + $pricefirst = price2num($ldapuser[$conf->global->LDAP_FIELD_MEMBER_FIRSTSUBSCRIPTION_AMOUNT]); |
|
264 | 264 | } |
265 | 265 | |
266 | - $datelast=''; |
|
266 | + $datelast = ''; |
|
267 | 267 | if ($conf->global->LDAP_FIELD_MEMBER_LASTSUBSCRIPTION_DATE) |
268 | 268 | { |
269 | - $datelast=dol_stringtotime($ldapuser[$conf->global->LDAP_FIELD_MEMBER_LASTSUBSCRIPTION_DATE]); |
|
270 | - $pricelast=price2num($ldapuser[$conf->global->LDAP_FIELD_MEMBER_LASTSUBSCRIPTION_AMOUNT]); |
|
269 | + $datelast = dol_stringtotime($ldapuser[$conf->global->LDAP_FIELD_MEMBER_LASTSUBSCRIPTION_DATE]); |
|
270 | + $pricelast = price2num($ldapuser[$conf->global->LDAP_FIELD_MEMBER_LASTSUBSCRIPTION_AMOUNT]); |
|
271 | 271 | } |
272 | 272 | elseif ($conf->global->LDAP_FIELD_MEMBER_END_LASTSUBSCRIPTION) |
273 | 273 | { |
274 | - $datelast=dol_time_plus_duree(dol_stringtotime($ldapuser[$conf->global->LDAP_FIELD_MEMBER_END_LASTSUBSCRIPTION]),-1,'y')+60*60*24; |
|
275 | - $pricelast=price2num($ldapuser[$conf->global->LDAP_FIELD_MEMBER_LASTSUBSCRIPTION_AMOUNT]); |
|
274 | + $datelast = dol_time_plus_duree(dol_stringtotime($ldapuser[$conf->global->LDAP_FIELD_MEMBER_END_LASTSUBSCRIPTION]), -1, 'y') + 60 * 60 * 24; |
|
275 | + $pricelast = price2num($ldapuser[$conf->global->LDAP_FIELD_MEMBER_LASTSUBSCRIPTION_AMOUNT]); |
|
276 | 276 | |
277 | 277 | // Cas special ou date derniere <= date premiere |
278 | 278 | if ($datefirst && $datelast && $datelast <= $datefirst) |
279 | 279 | { |
280 | 280 | // On ne va inserer que la premiere |
281 | - $datelast=0; |
|
282 | - if (! $pricefirst && $pricelast) $pricefirst = $pricelast; |
|
281 | + $datelast = 0; |
|
282 | + if (!$pricefirst && $pricelast) $pricefirst = $pricelast; |
|
283 | 283 | } |
284 | 284 | } |
285 | 285 | |
@@ -289,7 +289,7 @@ discard block |
||
289 | 289 | { |
290 | 290 | // Cree premiere cotisation et met a jour datefin dans adherent |
291 | 291 | //print "xx".$datefirst."\n"; |
292 | - $crowid=$member->subscription($datefirst, $pricefirst, 0); |
|
292 | + $crowid = $member->subscription($datefirst, $pricefirst, 0); |
|
293 | 293 | } |
294 | 294 | |
295 | 295 | // Insert last subscription |
@@ -297,32 +297,32 @@ discard block |
||
297 | 297 | { |
298 | 298 | // Cree derniere cotisation et met a jour datefin dans adherent |
299 | 299 | //print "yy".dol_print_date($datelast)."\n"; |
300 | - $crowid=$member->subscription($datelast, $pricelast, 0); |
|
300 | + $crowid = $member->subscription($datelast, $pricelast, 0); |
|
301 | 301 | } |
302 | 302 | } |
303 | 303 | |
304 | - if (! $error || $forcecommit) |
|
304 | + if (!$error || $forcecommit) |
|
305 | 305 | { |
306 | - if (! $error) print $langs->transnoentities("NoErrorCommitIsDone")."\n"; |
|
306 | + if (!$error) print $langs->transnoentities("NoErrorCommitIsDone")."\n"; |
|
307 | 307 | else print $langs->transnoentities("ErrorButCommitIsDone")."\n"; |
308 | 308 | $db->commit(); |
309 | 309 | } |
310 | 310 | else |
311 | 311 | { |
312 | - print $langs->transnoentities("ErrorSomeErrorWereFoundRollbackIsDone",$error)."\n"; |
|
312 | + print $langs->transnoentities("ErrorSomeErrorWereFoundRollbackIsDone", $error)."\n"; |
|
313 | 313 | $db->rollback(); |
314 | 314 | } |
315 | 315 | print "\n"; |
316 | 316 | } |
317 | 317 | else |
318 | 318 | { |
319 | - dol_print_error('',$ldap->error); |
|
319 | + dol_print_error('', $ldap->error); |
|
320 | 320 | $error++; |
321 | 321 | } |
322 | 322 | } |
323 | 323 | else |
324 | 324 | { |
325 | - dol_print_error('',$ldap->error); |
|
325 | + dol_print_error('', $ldap->error); |
|
326 | 326 | $error++; |
327 | 327 | } |
328 | 328 |
@@ -99,10 +99,16 @@ discard block |
||
99 | 99 | $typeid=$argv[2]; |
100 | 100 | foreach($argv as $key => $val) |
101 | 101 | { |
102 | - if ($val == 'commitiferror') $forcecommit=1; |
|
103 | - if (preg_match('/--server=([^\s]+)$/',$val,$reg)) $conf->global->LDAP_SERVER_HOST=$reg[1]; |
|
104 | - if (preg_match('/-y$/',$val,$reg)) $confirmed=1; |
|
105 | -} |
|
102 | + if ($val == 'commitiferror') { |
|
103 | + $forcecommit=1; |
|
104 | + } |
|
105 | + if (preg_match('/--server=([^\s]+)$/',$val,$reg)) { |
|
106 | + $conf->global->LDAP_SERVER_HOST=$reg[1]; |
|
107 | + } |
|
108 | + if (preg_match('/-y$/',$val,$reg)) { |
|
109 | + $confirmed=1; |
|
110 | + } |
|
111 | + } |
|
106 | 112 | |
107 | 113 | print "Mails sending disabled (useless in batch mode)\n"; |
108 | 114 | $conf->global->MAIN_DISABLE_ALL_MAILS=1; // On bloque les mails |
@@ -113,8 +119,13 @@ discard block |
||
113 | 119 | print "login=".$conf->global->LDAP_ADMIN_DN."\n"; |
114 | 120 | print "pass=".preg_replace('/./i','*',$conf->global->LDAP_ADMIN_PASS)."\n"; |
115 | 121 | print "DN to extract=".$conf->global->LDAP_MEMBER_DN."\n"; |
116 | -if (! empty($conf->global->LDAP_MEMBER_FILTER)) print 'Filter=('.$conf->global->LDAP_MEMBER_FILTER.')'."\n"; // Note: filter is defined into function getRecords |
|
117 | -else print 'Filter=('.$conf->global->LDAP_KEY_MEMBERS.'=*)'."\n"; |
|
122 | +if (! empty($conf->global->LDAP_MEMBER_FILTER)) { |
|
123 | + print 'Filter=('.$conf->global->LDAP_MEMBER_FILTER.')'."\n"; |
|
124 | +} |
|
125 | +// Note: filter is defined into function getRecords |
|
126 | +else { |
|
127 | + print 'Filter=('.$conf->global->LDAP_KEY_MEMBERS.'=*)'."\n"; |
|
128 | +} |
|
118 | 129 | print "----- To Dolibarr database:\n"; |
119 | 130 | print "type=".$conf->db->type."\n"; |
120 | 131 | print "host=".$conf->db->host."\n"; |
@@ -171,8 +182,7 @@ discard block |
||
171 | 182 | $i++; |
172 | 183 | } |
173 | 184 | } |
174 | -} |
|
175 | -else |
|
185 | +} else |
|
176 | 186 | { |
177 | 187 | dol_print_error($db); |
178 | 188 | exit(-1); |
@@ -246,8 +256,7 @@ discard block |
||
246 | 256 | if ($member_id > 0) |
247 | 257 | { |
248 | 258 | print ' --> Created member id='.$member_id.' login='.$member->login; |
249 | - } |
|
250 | - else |
|
259 | + } else |
|
251 | 260 | { |
252 | 261 | $error++; |
253 | 262 | print ' --> '.$member->error; |
@@ -268,8 +277,7 @@ discard block |
||
268 | 277 | { |
269 | 278 | $datelast=dol_stringtotime($ldapuser[$conf->global->LDAP_FIELD_MEMBER_LASTSUBSCRIPTION_DATE]); |
270 | 279 | $pricelast=price2num($ldapuser[$conf->global->LDAP_FIELD_MEMBER_LASTSUBSCRIPTION_AMOUNT]); |
271 | - } |
|
272 | - elseif ($conf->global->LDAP_FIELD_MEMBER_END_LASTSUBSCRIPTION) |
|
280 | + } elseif ($conf->global->LDAP_FIELD_MEMBER_END_LASTSUBSCRIPTION) |
|
273 | 281 | { |
274 | 282 | $datelast=dol_time_plus_duree(dol_stringtotime($ldapuser[$conf->global->LDAP_FIELD_MEMBER_END_LASTSUBSCRIPTION]),-1,'y')+60*60*24; |
275 | 283 | $pricelast=price2num($ldapuser[$conf->global->LDAP_FIELD_MEMBER_LASTSUBSCRIPTION_AMOUNT]); |
@@ -279,7 +287,9 @@ discard block |
||
279 | 287 | { |
280 | 288 | // On ne va inserer que la premiere |
281 | 289 | $datelast=0; |
282 | - if (! $pricefirst && $pricelast) $pricefirst = $pricelast; |
|
290 | + if (! $pricefirst && $pricelast) { |
|
291 | + $pricefirst = $pricelast; |
|
292 | + } |
|
283 | 293 | } |
284 | 294 | } |
285 | 295 | |
@@ -303,24 +313,24 @@ discard block |
||
303 | 313 | |
304 | 314 | if (! $error || $forcecommit) |
305 | 315 | { |
306 | - if (! $error) print $langs->transnoentities("NoErrorCommitIsDone")."\n"; |
|
307 | - else print $langs->transnoentities("ErrorButCommitIsDone")."\n"; |
|
316 | + if (! $error) { |
|
317 | + print $langs->transnoentities("NoErrorCommitIsDone")."\n"; |
|
318 | + } else { |
|
319 | + print $langs->transnoentities("ErrorButCommitIsDone")."\n"; |
|
320 | + } |
|
308 | 321 | $db->commit(); |
309 | - } |
|
310 | - else |
|
322 | + } else |
|
311 | 323 | { |
312 | 324 | print $langs->transnoentities("ErrorSomeErrorWereFoundRollbackIsDone",$error)."\n"; |
313 | 325 | $db->rollback(); |
314 | 326 | } |
315 | 327 | print "\n"; |
316 | - } |
|
317 | - else |
|
328 | + } else |
|
318 | 329 | { |
319 | 330 | dol_print_error('',$ldap->error); |
320 | 331 | $error++; |
321 | 332 | } |
322 | -} |
|
323 | -else |
|
333 | +} else |
|
324 | 334 | { |
325 | 335 | dol_print_error('',$ldap->error); |
326 | 336 | $error++; |
@@ -31,7 +31,7 @@ discard block |
||
31 | 31 | // Test if batch mode |
32 | 32 | if (substr($sapi_type, 0, 3) == 'cgi') { |
33 | 33 | echo "Error: You are using PHP for CGI. To execute ".$script_file." from command line, you must use PHP for CLI mode.\n"; |
34 | - exit(-1); |
|
34 | + exit(-1); |
|
35 | 35 | } |
36 | 36 | |
37 | 37 | require_once $path."../../htdocs/master.inc.php"; |
@@ -56,12 +56,12 @@ discard block |
||
56 | 56 | |
57 | 57 | if (! isset($argv[1]) || ! $argv[1]) { |
58 | 58 | print "Usage: $script_file now [-y]\n"; |
59 | - exit(-1); |
|
59 | + exit(-1); |
|
60 | 60 | } |
61 | 61 | |
62 | 62 | foreach($argv as $key => $val) |
63 | 63 | { |
64 | - if (preg_match('/-y$/',$val,$reg)) $confirmed=1; |
|
64 | + if (preg_match('/-y$/',$val,$reg)) $confirmed=1; |
|
65 | 65 | } |
66 | 66 | |
67 | 67 | $now=$argv[1]; |
@@ -87,12 +87,12 @@ discard block |
||
87 | 87 | |
88 | 88 | if (! $confirmed) |
89 | 89 | { |
90 | - print "Press a key to confirm...\n"; |
|
91 | - $input = trim(fgets(STDIN)); |
|
92 | - print "Warning, this operation may result in data loss if it failed.\n"; |
|
93 | - print "Be sure to have a backup of your LDAP database (With OpenLDAP: slapcat > save.ldif).\n"; |
|
94 | - print "Hit Enter to continue or CTRL+C to stop...\n"; |
|
95 | - $input = trim(fgets(STDIN)); |
|
90 | + print "Press a key to confirm...\n"; |
|
91 | + $input = trim(fgets(STDIN)); |
|
92 | + print "Warning, this operation may result in data loss if it failed.\n"; |
|
93 | + print "Be sure to have a backup of your LDAP database (With OpenLDAP: slapcat > save.ldif).\n"; |
|
94 | + print "Hit Enter to continue or CTRL+C to stop...\n"; |
|
95 | + $input = trim(fgets(STDIN)); |
|
96 | 96 | } |
97 | 97 | |
98 | 98 | /* |
@@ -109,64 +109,64 @@ discard block |
||
109 | 109 | $resql = $db->query($sql); |
110 | 110 | if ($resql) |
111 | 111 | { |
112 | - $num = $db->num_rows($resql); |
|
113 | - $i = 0; |
|
114 | - |
|
115 | - $ldap=new Ldap(); |
|
116 | - $ldap->connect_bind(); |
|
117 | - |
|
118 | - while ($i < $num) |
|
119 | - { |
|
120 | - $ldap->error=""; |
|
121 | - |
|
122 | - $obj = $db->fetch_object($resql); |
|
123 | - |
|
124 | - $member = new Adherent($db); |
|
125 | - $result=$member->fetch($obj->rowid); |
|
126 | - if ($result < 0) |
|
127 | - { |
|
128 | - dol_print_error($db,$member->error); |
|
129 | - exit(-1); |
|
130 | - } |
|
131 | - $result=$member->fetch_subscriptions(); |
|
132 | - if ($result < 0) |
|
133 | - { |
|
134 | - dol_print_error($db,$member->error); |
|
135 | - exit(-1); |
|
136 | - } |
|
137 | - |
|
138 | - print $langs->transnoentities("UpdateMember")." rowid=".$member->id." ".$member->getFullName($langs); |
|
139 | - |
|
140 | - $oldobject=$member; |
|
141 | - |
|
142 | - $oldinfo=$oldobject->_load_ldap_info(); |
|
143 | - $olddn=$oldobject->_load_ldap_dn($oldinfo); |
|
144 | - |
|
145 | - $info=$member->_load_ldap_info(); |
|
146 | - $dn=$member->_load_ldap_dn($info); |
|
147 | - |
|
148 | - $result=$ldap->add($dn,$info,$user); // Wil fail if already exists |
|
149 | - $result=$ldap->update($dn,$info,$user,$olddn); |
|
150 | - if ($result > 0) |
|
151 | - { |
|
152 | - print " - ".$langs->transnoentities("OK"); |
|
153 | - } |
|
154 | - else |
|
155 | - { |
|
156 | - $error++; |
|
157 | - print " - ".$langs->transnoentities("KO").' - '.$ldap->error; |
|
158 | - } |
|
159 | - print "\n"; |
|
160 | - |
|
161 | - $i++; |
|
162 | - } |
|
163 | - |
|
164 | - $ldap->unbind(); |
|
165 | - $ldap->close(); |
|
112 | + $num = $db->num_rows($resql); |
|
113 | + $i = 0; |
|
114 | + |
|
115 | + $ldap=new Ldap(); |
|
116 | + $ldap->connect_bind(); |
|
117 | + |
|
118 | + while ($i < $num) |
|
119 | + { |
|
120 | + $ldap->error=""; |
|
121 | + |
|
122 | + $obj = $db->fetch_object($resql); |
|
123 | + |
|
124 | + $member = new Adherent($db); |
|
125 | + $result=$member->fetch($obj->rowid); |
|
126 | + if ($result < 0) |
|
127 | + { |
|
128 | + dol_print_error($db,$member->error); |
|
129 | + exit(-1); |
|
130 | + } |
|
131 | + $result=$member->fetch_subscriptions(); |
|
132 | + if ($result < 0) |
|
133 | + { |
|
134 | + dol_print_error($db,$member->error); |
|
135 | + exit(-1); |
|
136 | + } |
|
137 | + |
|
138 | + print $langs->transnoentities("UpdateMember")." rowid=".$member->id." ".$member->getFullName($langs); |
|
139 | + |
|
140 | + $oldobject=$member; |
|
141 | + |
|
142 | + $oldinfo=$oldobject->_load_ldap_info(); |
|
143 | + $olddn=$oldobject->_load_ldap_dn($oldinfo); |
|
144 | + |
|
145 | + $info=$member->_load_ldap_info(); |
|
146 | + $dn=$member->_load_ldap_dn($info); |
|
147 | + |
|
148 | + $result=$ldap->add($dn,$info,$user); // Wil fail if already exists |
|
149 | + $result=$ldap->update($dn,$info,$user,$olddn); |
|
150 | + if ($result > 0) |
|
151 | + { |
|
152 | + print " - ".$langs->transnoentities("OK"); |
|
153 | + } |
|
154 | + else |
|
155 | + { |
|
156 | + $error++; |
|
157 | + print " - ".$langs->transnoentities("KO").' - '.$ldap->error; |
|
158 | + } |
|
159 | + print "\n"; |
|
160 | + |
|
161 | + $i++; |
|
162 | + } |
|
163 | + |
|
164 | + $ldap->unbind(); |
|
165 | + $ldap->close(); |
|
166 | 166 | } |
167 | 167 | else |
168 | 168 | { |
169 | - dol_print_error($db); |
|
169 | + dol_print_error($db); |
|
170 | 170 | } |
171 | 171 | |
172 | 172 | exit($error); |
@@ -26,7 +26,7 @@ discard block |
||
26 | 26 | |
27 | 27 | $sapi_type = php_sapi_name(); |
28 | 28 | $script_file = basename(__FILE__); |
29 | -$path=dirname(__FILE__).'/'; |
|
29 | +$path = dirname(__FILE__).'/'; |
|
30 | 30 | |
31 | 31 | // Test if batch mode |
32 | 32 | if (substr($sapi_type, 0, 3) == 'cgi') { |
@@ -41,9 +41,9 @@ discard block |
||
41 | 41 | $langs->load("main"); |
42 | 42 | |
43 | 43 | // Global variables |
44 | -$version=DOL_VERSION; |
|
45 | -$error=0; |
|
46 | -$confirmed=0; |
|
44 | +$version = DOL_VERSION; |
|
45 | +$error = 0; |
|
46 | +$confirmed = 0; |
|
47 | 47 | |
48 | 48 | |
49 | 49 | /* |
@@ -52,22 +52,22 @@ discard block |
||
52 | 52 | |
53 | 53 | @set_time_limit(0); |
54 | 54 | print "***** ".$script_file." (".$version.") pid=".dol_getmypid()." *****\n"; |
55 | -dol_syslog($script_file." launched with arg ".join(',',$argv)); |
|
55 | +dol_syslog($script_file." launched with arg ".join(',', $argv)); |
|
56 | 56 | |
57 | -if (! isset($argv[1]) || ! $argv[1]) { |
|
57 | +if (!isset($argv[1]) || !$argv[1]) { |
|
58 | 58 | print "Usage: $script_file now [-y]\n"; |
59 | 59 | exit(-1); |
60 | 60 | } |
61 | 61 | |
62 | -foreach($argv as $key => $val) |
|
62 | +foreach ($argv as $key => $val) |
|
63 | 63 | { |
64 | - if (preg_match('/-y$/',$val,$reg)) $confirmed=1; |
|
64 | + if (preg_match('/-y$/', $val, $reg)) $confirmed = 1; |
|
65 | 65 | } |
66 | 66 | |
67 | -$now=$argv[1]; |
|
67 | +$now = $argv[1]; |
|
68 | 68 | |
69 | 69 | print "Mails sending disabled (useless in batch mode)\n"; |
70 | -$conf->global->MAIN_DISABLE_ALL_MAILS=1; // On bloque les mails |
|
70 | +$conf->global->MAIN_DISABLE_ALL_MAILS = 1; // On bloque les mails |
|
71 | 71 | print "\n"; |
72 | 72 | print "----- Synchronize all records from Dolibarr database:\n"; |
73 | 73 | print "type=".$conf->db->type."\n"; |
@@ -81,11 +81,11 @@ discard block |
||
81 | 81 | print "host=".$conf->global->LDAP_SERVER_HOST."\n"; |
82 | 82 | print "port=".$conf->global->LDAP_SERVER_PORT."\n"; |
83 | 83 | print "login=".$conf->global->LDAP_ADMIN_DN."\n"; |
84 | -print "pass=".preg_replace('/./i','*',$conf->global->LDAP_ADMIN_PASS)."\n"; |
|
84 | +print "pass=".preg_replace('/./i', '*', $conf->global->LDAP_ADMIN_PASS)."\n"; |
|
85 | 85 | print "DN target=".$conf->global->LDAP_MEMBER_DN."\n"; |
86 | 86 | print "\n"; |
87 | 87 | |
88 | -if (! $confirmed) |
|
88 | +if (!$confirmed) |
|
89 | 89 | { |
90 | 90 | print "Press a key to confirm...\n"; |
91 | 91 | $input = trim(fgets(STDIN)); |
@@ -112,41 +112,41 @@ discard block |
||
112 | 112 | $num = $db->num_rows($resql); |
113 | 113 | $i = 0; |
114 | 114 | |
115 | - $ldap=new Ldap(); |
|
115 | + $ldap = new Ldap(); |
|
116 | 116 | $ldap->connect_bind(); |
117 | 117 | |
118 | 118 | while ($i < $num) |
119 | 119 | { |
120 | - $ldap->error=""; |
|
120 | + $ldap->error = ""; |
|
121 | 121 | |
122 | 122 | $obj = $db->fetch_object($resql); |
123 | 123 | |
124 | 124 | $member = new Adherent($db); |
125 | - $result=$member->fetch($obj->rowid); |
|
125 | + $result = $member->fetch($obj->rowid); |
|
126 | 126 | if ($result < 0) |
127 | 127 | { |
128 | - dol_print_error($db,$member->error); |
|
128 | + dol_print_error($db, $member->error); |
|
129 | 129 | exit(-1); |
130 | 130 | } |
131 | - $result=$member->fetch_subscriptions(); |
|
131 | + $result = $member->fetch_subscriptions(); |
|
132 | 132 | if ($result < 0) |
133 | 133 | { |
134 | - dol_print_error($db,$member->error); |
|
134 | + dol_print_error($db, $member->error); |
|
135 | 135 | exit(-1); |
136 | 136 | } |
137 | 137 | |
138 | 138 | print $langs->transnoentities("UpdateMember")." rowid=".$member->id." ".$member->getFullName($langs); |
139 | 139 | |
140 | - $oldobject=$member; |
|
140 | + $oldobject = $member; |
|
141 | 141 | |
142 | - $oldinfo=$oldobject->_load_ldap_info(); |
|
143 | - $olddn=$oldobject->_load_ldap_dn($oldinfo); |
|
142 | + $oldinfo = $oldobject->_load_ldap_info(); |
|
143 | + $olddn = $oldobject->_load_ldap_dn($oldinfo); |
|
144 | 144 | |
145 | - $info=$member->_load_ldap_info(); |
|
146 | - $dn=$member->_load_ldap_dn($info); |
|
145 | + $info = $member->_load_ldap_info(); |
|
146 | + $dn = $member->_load_ldap_dn($info); |
|
147 | 147 | |
148 | - $result=$ldap->add($dn,$info,$user); // Wil fail if already exists |
|
149 | - $result=$ldap->update($dn,$info,$user,$olddn); |
|
148 | + $result = $ldap->add($dn, $info, $user); // Wil fail if already exists |
|
149 | + $result = $ldap->update($dn, $info, $user, $olddn); |
|
150 | 150 | if ($result > 0) |
151 | 151 | { |
152 | 152 | print " - ".$langs->transnoentities("OK"); |
@@ -61,8 +61,10 @@ discard block |
||
61 | 61 | |
62 | 62 | foreach($argv as $key => $val) |
63 | 63 | { |
64 | - if (preg_match('/-y$/',$val,$reg)) $confirmed=1; |
|
65 | -} |
|
64 | + if (preg_match('/-y$/',$val,$reg)) { |
|
65 | + $confirmed=1; |
|
66 | + } |
|
67 | + } |
|
66 | 68 | |
67 | 69 | $now=$argv[1]; |
68 | 70 | |
@@ -150,8 +152,7 @@ discard block |
||
150 | 152 | if ($result > 0) |
151 | 153 | { |
152 | 154 | print " - ".$langs->transnoentities("OK"); |
153 | - } |
|
154 | - else |
|
155 | + } else |
|
155 | 156 | { |
156 | 157 | $error++; |
157 | 158 | print " - ".$langs->transnoentities("KO").' - '.$ldap->error; |
@@ -163,8 +164,7 @@ discard block |
||
163 | 164 | |
164 | 165 | $ldap->unbind(); |
165 | 166 | $ldap->close(); |
166 | -} |
|
167 | -else |
|
167 | +} else |
|
168 | 168 | { |
169 | 169 | dol_print_error($db); |
170 | 170 | } |
@@ -32,12 +32,12 @@ discard block |
||
32 | 32 | // Test if batch mode |
33 | 33 | if (substr($sapi_type, 0, 3) == 'cgi') { |
34 | 34 | echo "Error: You are using PHP for CGI. To execute ".$script_file." from command line, you must use PHP for CLI mode.\n"; |
35 | - exit(-1); |
|
35 | + exit(-1); |
|
36 | 36 | } |
37 | 37 | |
38 | 38 | if (! isset($argv[1]) || ! $argv[1]) { |
39 | 39 | print "Usage: ".$script_file." now\n"; |
40 | - exit(-1); |
|
40 | + exit(-1); |
|
41 | 41 | } |
42 | 42 | $now=$argv[1]; |
43 | 43 | |
@@ -72,60 +72,60 @@ discard block |
||
72 | 72 | $resql = $db->query($sql); |
73 | 73 | if ($resql) |
74 | 74 | { |
75 | - $num = $db->num_rows($resql); |
|
76 | - $i = 0; |
|
77 | - |
|
78 | - $ldap=new Ldap(); |
|
79 | - $result=$ldap->connect_bind(); |
|
80 | - |
|
81 | - if ($result > 0) |
|
82 | - { |
|
83 | - while ($i < $num) |
|
84 | - { |
|
85 | - $ldap->error=""; |
|
86 | - |
|
87 | - $obj = $db->fetch_object($resql); |
|
88 | - |
|
89 | - $membertype = new AdherentType($db); |
|
90 | - $membertype->id = $obj->rowid; |
|
91 | - $membertype->fetch($membertype->id); |
|
92 | - |
|
93 | - print $langs->trans("UpdateMemberType")." rowid=".$membertype->id." ".$membertype-label; |
|
94 | - |
|
95 | - $oldobject=$membertype; |
|
96 | - |
|
97 | - $oldinfo=$membertype->_load_ldap_info(); |
|
98 | - $olddn=$membertype->_load_ldap_dn($oldinfo); |
|
99 | - |
|
100 | - $info=$membertype->_load_ldap_info(); |
|
101 | - $dn=$membertype->_load_ldap_dn($info); |
|
102 | - |
|
103 | - $result=$ldap->add($dn,$info,$user); // Wil fail if already exists |
|
104 | - $result=$ldap->update($dn,$info,$user,$olddn); |
|
105 | - if ($result > 0) |
|
106 | - { |
|
107 | - print " - ".$langs->trans("OK"); |
|
108 | - } |
|
109 | - else |
|
110 | - { |
|
111 | - $error++; |
|
112 | - print " - ".$langs->trans("KO").' - '.$ldap->error; |
|
113 | - } |
|
114 | - print "\n"; |
|
115 | - |
|
116 | - $i++; |
|
117 | - } |
|
118 | - |
|
119 | - $ldap->unbind(); |
|
120 | - $ldap->close(); |
|
121 | - } |
|
122 | - else { |
|
123 | - print $ldap->error; |
|
124 | - } |
|
75 | + $num = $db->num_rows($resql); |
|
76 | + $i = 0; |
|
77 | + |
|
78 | + $ldap=new Ldap(); |
|
79 | + $result=$ldap->connect_bind(); |
|
80 | + |
|
81 | + if ($result > 0) |
|
82 | + { |
|
83 | + while ($i < $num) |
|
84 | + { |
|
85 | + $ldap->error=""; |
|
86 | + |
|
87 | + $obj = $db->fetch_object($resql); |
|
88 | + |
|
89 | + $membertype = new AdherentType($db); |
|
90 | + $membertype->id = $obj->rowid; |
|
91 | + $membertype->fetch($membertype->id); |
|
92 | + |
|
93 | + print $langs->trans("UpdateMemberType")." rowid=".$membertype->id." ".$membertype-label; |
|
94 | + |
|
95 | + $oldobject=$membertype; |
|
96 | + |
|
97 | + $oldinfo=$membertype->_load_ldap_info(); |
|
98 | + $olddn=$membertype->_load_ldap_dn($oldinfo); |
|
99 | + |
|
100 | + $info=$membertype->_load_ldap_info(); |
|
101 | + $dn=$membertype->_load_ldap_dn($info); |
|
102 | + |
|
103 | + $result=$ldap->add($dn,$info,$user); // Wil fail if already exists |
|
104 | + $result=$ldap->update($dn,$info,$user,$olddn); |
|
105 | + if ($result > 0) |
|
106 | + { |
|
107 | + print " - ".$langs->trans("OK"); |
|
108 | + } |
|
109 | + else |
|
110 | + { |
|
111 | + $error++; |
|
112 | + print " - ".$langs->trans("KO").' - '.$ldap->error; |
|
113 | + } |
|
114 | + print "\n"; |
|
115 | + |
|
116 | + $i++; |
|
117 | + } |
|
118 | + |
|
119 | + $ldap->unbind(); |
|
120 | + $ldap->close(); |
|
121 | + } |
|
122 | + else { |
|
123 | + print $ldap->error; |
|
124 | + } |
|
125 | 125 | } |
126 | 126 | else |
127 | 127 | { |
128 | - dol_print_error($db); |
|
128 | + dol_print_error($db); |
|
129 | 129 | } |
130 | 130 | |
131 | 131 | exit($error); |
@@ -27,7 +27,7 @@ discard block |
||
27 | 27 | |
28 | 28 | $sapi_type = php_sapi_name(); |
29 | 29 | $script_file = basename(__FILE__); |
30 | -$path=dirname(__FILE__).'/'; |
|
30 | +$path = dirname(__FILE__).'/'; |
|
31 | 31 | |
32 | 32 | // Test if batch mode |
33 | 33 | if (substr($sapi_type, 0, 3) == 'cgi') { |
@@ -35,19 +35,19 @@ discard block |
||
35 | 35 | exit(-1); |
36 | 36 | } |
37 | 37 | |
38 | -if (! isset($argv[1]) || ! $argv[1]) { |
|
38 | +if (!isset($argv[1]) || !$argv[1]) { |
|
39 | 39 | print "Usage: ".$script_file." now\n"; |
40 | 40 | exit(-1); |
41 | 41 | } |
42 | -$now=$argv[1]; |
|
42 | +$now = $argv[1]; |
|
43 | 43 | |
44 | 44 | require_once $path."../../htdocs/master.inc.php"; |
45 | 45 | require_once DOL_DOCUMENT_ROOT."/core/class/ldap.class.php"; |
46 | 46 | require_once DOL_DOCUMENT_ROOT."/adherents/class/adherent_type.class.php"; |
47 | 47 | |
48 | 48 | // Global variables |
49 | -$version=DOL_VERSION; |
|
50 | -$error=0; |
|
49 | +$version = DOL_VERSION; |
|
50 | +$error = 0; |
|
51 | 51 | |
52 | 52 | |
53 | 53 | /* |
@@ -56,7 +56,7 @@ discard block |
||
56 | 56 | |
57 | 57 | @set_time_limit(0); |
58 | 58 | print "***** ".$script_file." (".$version.") pid=".dol_getmypid()." *****\n"; |
59 | -dol_syslog($script_file." launched with arg ".join(',',$argv)); |
|
59 | +dol_syslog($script_file." launched with arg ".join(',', $argv)); |
|
60 | 60 | |
61 | 61 | /* |
62 | 62 | if (! $conf->global->LDAP_SYNCHRO_ACTIVE) |
@@ -75,14 +75,14 @@ discard block |
||
75 | 75 | $num = $db->num_rows($resql); |
76 | 76 | $i = 0; |
77 | 77 | |
78 | - $ldap=new Ldap(); |
|
79 | - $result=$ldap->connect_bind(); |
|
78 | + $ldap = new Ldap(); |
|
79 | + $result = $ldap->connect_bind(); |
|
80 | 80 | |
81 | 81 | if ($result > 0) |
82 | 82 | { |
83 | 83 | while ($i < $num) |
84 | 84 | { |
85 | - $ldap->error=""; |
|
85 | + $ldap->error = ""; |
|
86 | 86 | |
87 | 87 | $obj = $db->fetch_object($resql); |
88 | 88 | |
@@ -90,18 +90,18 @@ discard block |
||
90 | 90 | $membertype->id = $obj->rowid; |
91 | 91 | $membertype->fetch($membertype->id); |
92 | 92 | |
93 | - print $langs->trans("UpdateMemberType")." rowid=".$membertype->id." ".$membertype-label; |
|
93 | + print $langs->trans("UpdateMemberType")." rowid=".$membertype->id." ".$membertype - label; |
|
94 | 94 | |
95 | - $oldobject=$membertype; |
|
95 | + $oldobject = $membertype; |
|
96 | 96 | |
97 | - $oldinfo=$membertype->_load_ldap_info(); |
|
98 | - $olddn=$membertype->_load_ldap_dn($oldinfo); |
|
97 | + $oldinfo = $membertype->_load_ldap_info(); |
|
98 | + $olddn = $membertype->_load_ldap_dn($oldinfo); |
|
99 | 99 | |
100 | - $info=$membertype->_load_ldap_info(); |
|
101 | - $dn=$membertype->_load_ldap_dn($info); |
|
100 | + $info = $membertype->_load_ldap_info(); |
|
101 | + $dn = $membertype->_load_ldap_dn($info); |
|
102 | 102 | |
103 | - $result=$ldap->add($dn,$info,$user); // Wil fail if already exists |
|
104 | - $result=$ldap->update($dn,$info,$user,$olddn); |
|
103 | + $result = $ldap->add($dn, $info, $user); // Wil fail if already exists |
|
104 | + $result = $ldap->update($dn, $info, $user, $olddn); |
|
105 | 105 | if ($result > 0) |
106 | 106 | { |
107 | 107 | print " - ".$langs->trans("OK"); |
@@ -105,8 +105,7 @@ discard block |
||
105 | 105 | if ($result > 0) |
106 | 106 | { |
107 | 107 | print " - ".$langs->trans("OK"); |
108 | - } |
|
109 | - else |
|
108 | + } else |
|
110 | 109 | { |
111 | 110 | $error++; |
112 | 111 | print " - ".$langs->trans("KO").' - '.$ldap->error; |
@@ -118,12 +117,10 @@ discard block |
||
118 | 117 | |
119 | 118 | $ldap->unbind(); |
120 | 119 | $ldap->close(); |
121 | - } |
|
122 | - else { |
|
120 | + } else { |
|
123 | 121 | print $ldap->error; |
124 | 122 | } |
125 | -} |
|
126 | -else |
|
123 | +} else |
|
127 | 124 | { |
128 | 125 | dol_print_error($db); |
129 | 126 | } |
@@ -33,7 +33,7 @@ discard block |
||
33 | 33 | // Test if batch mode |
34 | 34 | if (substr($sapi_type, 0, 3) == 'cgi') { |
35 | 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); |
|
36 | + exit(-1); |
|
37 | 37 | } |
38 | 38 | |
39 | 39 | require_once $path."../../htdocs/master.inc.php"; |
@@ -60,10 +60,10 @@ discard block |
||
60 | 60 | |
61 | 61 | // List of fields to get from LDAP |
62 | 62 | $required_fields = array( |
63 | - $conf->global->LDAP_KEY_MEMBERS_TYPES, |
|
64 | - $conf->global->LDAP_MEMBER_TYPE_FIELD_FULLNAME, |
|
65 | - $conf->global->LDAP_MEMBER_TYPE_FIELD_DESCRIPTION, |
|
66 | - $conf->global->LDAP_MEMBER_TYPE_FIELD_GROUPMEMBERS |
|
63 | + $conf->global->LDAP_KEY_MEMBERS_TYPES, |
|
64 | + $conf->global->LDAP_MEMBER_TYPE_FIELD_FULLNAME, |
|
65 | + $conf->global->LDAP_MEMBER_TYPE_FIELD_DESCRIPTION, |
|
66 | + $conf->global->LDAP_MEMBER_TYPE_FIELD_GROUPMEMBERS |
|
67 | 67 | ); |
68 | 68 | |
69 | 69 | // Remove from required_fields all entries not configured in LDAP (empty) and duplicated |
@@ -71,17 +71,17 @@ discard block |
||
71 | 71 | |
72 | 72 | |
73 | 73 | if (! isset($argv[1])) { |
74 | - //print "Usage: $script_file (nocommitiferror|commitiferror) [id_group]\n"; |
|
75 | - print "Usage: $script_file (nocommitiferror|commitiferror) [--server=ldapserverhost] [--excludeuser=user1,user2...] [-y]\n"; |
|
76 | - exit(-1); |
|
74 | + //print "Usage: $script_file (nocommitiferror|commitiferror) [id_group]\n"; |
|
75 | + print "Usage: $script_file (nocommitiferror|commitiferror) [--server=ldapserverhost] [--excludeuser=user1,user2...] [-y]\n"; |
|
76 | + exit(-1); |
|
77 | 77 | } |
78 | 78 | |
79 | 79 | foreach($argv as $key => $val) |
80 | 80 | { |
81 | - if ($val == 'commitiferror') $forcecommit=1; |
|
82 | - if (preg_match('/--server=([^\s]+)$/',$val,$reg)) $conf->global->LDAP_SERVER_HOST=$reg[1]; |
|
83 | - if (preg_match('/--excludeuser=([^\s]+)$/',$val,$reg)) $excludeuser=explode(',',$reg[1]); |
|
84 | - if (preg_match('/-y$/',$val,$reg)) $confirmed=1; |
|
81 | + if ($val == 'commitiferror') $forcecommit=1; |
|
82 | + if (preg_match('/--server=([^\s]+)$/',$val,$reg)) $conf->global->LDAP_SERVER_HOST=$reg[1]; |
|
83 | + if (preg_match('/--excludeuser=([^\s]+)$/',$val,$reg)) $excludeuser=explode(',',$reg[1]); |
|
84 | + if (preg_match('/-y$/',$val,$reg)) $confirmed=1; |
|
85 | 85 | } |
86 | 86 | |
87 | 87 | print "Mails sending disabled (useless in batch mode)\n"; |
@@ -107,14 +107,14 @@ discard block |
||
107 | 107 | |
108 | 108 | if (! $confirmed) |
109 | 109 | { |
110 | - print "Hit Enter to continue or CTRL+C to stop...\n"; |
|
111 | - $input = trim(fgets(STDIN)); |
|
110 | + print "Hit Enter to continue or CTRL+C to stop...\n"; |
|
111 | + $input = trim(fgets(STDIN)); |
|
112 | 112 | } |
113 | 113 | |
114 | 114 | if (empty($conf->global->LDAP_MEMBER_TYPE_DN)) |
115 | 115 | { |
116 | - print $langs->trans("Error").': '.$langs->trans("LDAP setup for members types not defined inside Dolibarr"); |
|
117 | - exit(-1); |
|
116 | + print $langs->trans("Error").': '.$langs->trans("LDAP setup for members types not defined inside Dolibarr"); |
|
117 | + exit(-1); |
|
118 | 118 | } |
119 | 119 | |
120 | 120 | |
@@ -122,84 +122,84 @@ discard block |
||
122 | 122 | $result = $ldap->connect_bind(); |
123 | 123 | if ($result >= 0) |
124 | 124 | { |
125 | - $justthese=array(); |
|
126 | - |
|
127 | - |
|
128 | - // We disable synchro Dolibarr-LDAP |
|
129 | - $conf->global->LDAP_MEMBER_TYPE_ACTIVE=0; |
|
130 | - |
|
131 | - $ldaprecords = $ldap->getRecords('*',$conf->global->LDAP_MEMBER_TYPE_DN, $conf->global->LDAP_KEY_MEMBERS_TYPES, $required_fields, 0, array($conf->global->LDAP_MEMBER_TYPE_FIELD_GROUPMEMBERS)); |
|
132 | - if (is_array($ldaprecords)) |
|
133 | - { |
|
134 | - $db->begin(); |
|
135 | - |
|
136 | - // Warning $ldapuser has a key in lowercase |
|
137 | - foreach ($ldaprecords as $key => $ldapgroup) |
|
138 | - { |
|
139 | - $membertype = new AdherentType($db); |
|
140 | - $membertype->fetch('', $ldapgroup[$conf->global->LDAP_KEY_MEMBERS_TYPES]); |
|
141 | - $membertype->label = $ldapgroup[$conf->global->LDAP_MEMBER_TYPE_FIELD_FULLNAME]; |
|
142 | - $membertype->description = $ldapgroup[$conf->global->LDAP_MEMBER_TYPE_FIELD_DESCRIPTION]; |
|
143 | - $membertype->entity = $conf->entity; |
|
144 | - |
|
145 | - //print_r($ldapgroup); |
|
146 | - |
|
147 | - if ($membertype->id > 0) { // Member type update |
|
148 | - print $langs->transnoentities("MemberTypeUpdate").' # '.$key.': name='.$membertype->label; |
|
149 | - $res=$membertype->update($user); |
|
150 | - |
|
151 | - if ($res > 0) |
|
152 | - { |
|
153 | - print ' --> Updated member type id='.$membertype->id.' name='.$membertype->label; |
|
154 | - } |
|
155 | - else |
|
156 | - { |
|
157 | - $error++; |
|
158 | - print ' --> '.$res.' '.$membertype->error; |
|
159 | - } |
|
160 | - print "\n"; |
|
161 | - } else { // Member type creation |
|
162 | - print $langs->transnoentities("MemberTypeCreate").' # '.$key.': name='.$membertype->label; |
|
163 | - $res=$membertype->create($user); |
|
164 | - |
|
165 | - if ($res > 0) |
|
166 | - { |
|
167 | - print ' --> Created member type id='.$membertype->id.' name='.$membertype->label; |
|
168 | - } |
|
169 | - else |
|
170 | - { |
|
171 | - $error++; |
|
172 | - print ' --> '.$res.' '.$membertype->error; |
|
173 | - } |
|
174 | - print "\n"; |
|
175 | - } |
|
176 | - |
|
177 | - //print_r($membertype); |
|
178 | - } |
|
179 | - |
|
180 | - if (! $error || $forcecommit) |
|
181 | - { |
|
182 | - if (! $error) print $langs->transnoentities("NoErrorCommitIsDone")."\n"; |
|
183 | - else print $langs->transnoentities("ErrorButCommitIsDone")."\n"; |
|
184 | - $db->commit(); |
|
185 | - } |
|
186 | - else |
|
187 | - { |
|
188 | - print $langs->transnoentities("ErrorSomeErrorWereFoundRollbackIsDone",$error)."\n"; |
|
189 | - $db->rollback(); |
|
190 | - } |
|
191 | - print "\n"; |
|
192 | - } |
|
193 | - else |
|
194 | - { |
|
195 | - dol_print_error('',$ldap->error); |
|
196 | - $error++; |
|
197 | - } |
|
125 | + $justthese=array(); |
|
126 | + |
|
127 | + |
|
128 | + // We disable synchro Dolibarr-LDAP |
|
129 | + $conf->global->LDAP_MEMBER_TYPE_ACTIVE=0; |
|
130 | + |
|
131 | + $ldaprecords = $ldap->getRecords('*',$conf->global->LDAP_MEMBER_TYPE_DN, $conf->global->LDAP_KEY_MEMBERS_TYPES, $required_fields, 0, array($conf->global->LDAP_MEMBER_TYPE_FIELD_GROUPMEMBERS)); |
|
132 | + if (is_array($ldaprecords)) |
|
133 | + { |
|
134 | + $db->begin(); |
|
135 | + |
|
136 | + // Warning $ldapuser has a key in lowercase |
|
137 | + foreach ($ldaprecords as $key => $ldapgroup) |
|
138 | + { |
|
139 | + $membertype = new AdherentType($db); |
|
140 | + $membertype->fetch('', $ldapgroup[$conf->global->LDAP_KEY_MEMBERS_TYPES]); |
|
141 | + $membertype->label = $ldapgroup[$conf->global->LDAP_MEMBER_TYPE_FIELD_FULLNAME]; |
|
142 | + $membertype->description = $ldapgroup[$conf->global->LDAP_MEMBER_TYPE_FIELD_DESCRIPTION]; |
|
143 | + $membertype->entity = $conf->entity; |
|
144 | + |
|
145 | + //print_r($ldapgroup); |
|
146 | + |
|
147 | + if ($membertype->id > 0) { // Member type update |
|
148 | + print $langs->transnoentities("MemberTypeUpdate").' # '.$key.': name='.$membertype->label; |
|
149 | + $res=$membertype->update($user); |
|
150 | + |
|
151 | + if ($res > 0) |
|
152 | + { |
|
153 | + print ' --> Updated member type id='.$membertype->id.' name='.$membertype->label; |
|
154 | + } |
|
155 | + else |
|
156 | + { |
|
157 | + $error++; |
|
158 | + print ' --> '.$res.' '.$membertype->error; |
|
159 | + } |
|
160 | + print "\n"; |
|
161 | + } else { // Member type creation |
|
162 | + print $langs->transnoentities("MemberTypeCreate").' # '.$key.': name='.$membertype->label; |
|
163 | + $res=$membertype->create($user); |
|
164 | + |
|
165 | + if ($res > 0) |
|
166 | + { |
|
167 | + print ' --> Created member type id='.$membertype->id.' name='.$membertype->label; |
|
168 | + } |
|
169 | + else |
|
170 | + { |
|
171 | + $error++; |
|
172 | + print ' --> '.$res.' '.$membertype->error; |
|
173 | + } |
|
174 | + print "\n"; |
|
175 | + } |
|
176 | + |
|
177 | + //print_r($membertype); |
|
178 | + } |
|
179 | + |
|
180 | + if (! $error || $forcecommit) |
|
181 | + { |
|
182 | + if (! $error) print $langs->transnoentities("NoErrorCommitIsDone")."\n"; |
|
183 | + else print $langs->transnoentities("ErrorButCommitIsDone")."\n"; |
|
184 | + $db->commit(); |
|
185 | + } |
|
186 | + else |
|
187 | + { |
|
188 | + print $langs->transnoentities("ErrorSomeErrorWereFoundRollbackIsDone",$error)."\n"; |
|
189 | + $db->rollback(); |
|
190 | + } |
|
191 | + print "\n"; |
|
192 | + } |
|
193 | + else |
|
194 | + { |
|
195 | + dol_print_error('',$ldap->error); |
|
196 | + $error++; |
|
197 | + } |
|
198 | 198 | } |
199 | 199 | else |
200 | 200 | { |
201 | - dol_print_error('',$ldap->error); |
|
202 | - $error++; |
|
201 | + dol_print_error('',$ldap->error); |
|
202 | + $error++; |
|
203 | 203 | } |
204 | 204 | |
205 | 205 | |
@@ -214,6 +214,6 @@ discard block |
||
214 | 214 | */ |
215 | 215 | function dolValidElementType($element) |
216 | 216 | { |
217 | - return (trim($element) != ''); |
|
217 | + return (trim($element) != ''); |
|
218 | 218 | } |
219 | 219 |
@@ -28,7 +28,7 @@ discard block |
||
28 | 28 | |
29 | 29 | $sapi_type = php_sapi_name(); |
30 | 30 | $script_file = basename(__FILE__); |
31 | -$path=dirname(__FILE__).'/'; |
|
31 | +$path = dirname(__FILE__).'/'; |
|
32 | 32 | |
33 | 33 | // Test if batch mode |
34 | 34 | if (substr($sapi_type, 0, 3) == 'cgi') { |
@@ -44,10 +44,10 @@ discard block |
||
44 | 44 | $langs->loadLangs(array("main", "errors")); |
45 | 45 | |
46 | 46 | // Global variables |
47 | -$version=DOL_VERSION; |
|
48 | -$error=0; |
|
49 | -$forcecommit=0; |
|
50 | -$confirmed=0; |
|
47 | +$version = DOL_VERSION; |
|
48 | +$error = 0; |
|
49 | +$forcecommit = 0; |
|
50 | +$confirmed = 0; |
|
51 | 51 | |
52 | 52 | |
53 | 53 | /* |
@@ -56,7 +56,7 @@ discard block |
||
56 | 56 | |
57 | 57 | @set_time_limit(0); |
58 | 58 | print "***** ".$script_file." (".$version.") pid=".dol_getmypid()." *****\n"; |
59 | -dol_syslog($script_file." launched with arg ".join(',',$argv)); |
|
59 | +dol_syslog($script_file." launched with arg ".join(',', $argv)); |
|
60 | 60 | |
61 | 61 | // List of fields to get from LDAP |
62 | 62 | $required_fields = array( |
@@ -67,31 +67,31 @@ discard block |
||
67 | 67 | ); |
68 | 68 | |
69 | 69 | // Remove from required_fields all entries not configured in LDAP (empty) and duplicated |
70 | -$required_fields=array_unique(array_values(array_filter($required_fields, "dolValidElementType"))); |
|
70 | +$required_fields = array_unique(array_values(array_filter($required_fields, "dolValidElementType"))); |
|
71 | 71 | |
72 | 72 | |
73 | -if (! isset($argv[1])) { |
|
73 | +if (!isset($argv[1])) { |
|
74 | 74 | //print "Usage: $script_file (nocommitiferror|commitiferror) [id_group]\n"; |
75 | 75 | print "Usage: $script_file (nocommitiferror|commitiferror) [--server=ldapserverhost] [--excludeuser=user1,user2...] [-y]\n"; |
76 | 76 | exit(-1); |
77 | 77 | } |
78 | 78 | |
79 | -foreach($argv as $key => $val) |
|
79 | +foreach ($argv as $key => $val) |
|
80 | 80 | { |
81 | - if ($val == 'commitiferror') $forcecommit=1; |
|
82 | - if (preg_match('/--server=([^\s]+)$/',$val,$reg)) $conf->global->LDAP_SERVER_HOST=$reg[1]; |
|
83 | - if (preg_match('/--excludeuser=([^\s]+)$/',$val,$reg)) $excludeuser=explode(',',$reg[1]); |
|
84 | - if (preg_match('/-y$/',$val,$reg)) $confirmed=1; |
|
81 | + if ($val == 'commitiferror') $forcecommit = 1; |
|
82 | + if (preg_match('/--server=([^\s]+)$/', $val, $reg)) $conf->global->LDAP_SERVER_HOST = $reg[1]; |
|
83 | + if (preg_match('/--excludeuser=([^\s]+)$/', $val, $reg)) $excludeuser = explode(',', $reg[1]); |
|
84 | + if (preg_match('/-y$/', $val, $reg)) $confirmed = 1; |
|
85 | 85 | } |
86 | 86 | |
87 | 87 | print "Mails sending disabled (useless in batch mode)\n"; |
88 | -$conf->global->MAIN_DISABLE_ALL_MAILS=1; // On bloque les mails |
|
88 | +$conf->global->MAIN_DISABLE_ALL_MAILS = 1; // On bloque les mails |
|
89 | 89 | print "\n"; |
90 | 90 | print "----- Synchronize all records from LDAP database:\n"; |
91 | 91 | print "host=".$conf->global->LDAP_SERVER_HOST."\n"; |
92 | 92 | print "port=".$conf->global->LDAP_SERVER_PORT."\n"; |
93 | 93 | print "login=".$conf->global->LDAP_ADMIN_DN."\n"; |
94 | -print "pass=".preg_replace('/./i','*',$conf->global->LDAP_ADMIN_PASS)."\n"; |
|
94 | +print "pass=".preg_replace('/./i', '*', $conf->global->LDAP_ADMIN_PASS)."\n"; |
|
95 | 95 | print "DN to extract=".$conf->global->LDAP_MEMBER_TYPE_DN."\n"; |
96 | 96 | print 'Filter=('.$conf->global->LDAP_KEY_MEMBERS_TYPES.'=*)'."\n"; |
97 | 97 | print "----- To Dolibarr database:\n"; |
@@ -102,10 +102,10 @@ discard block |
||
102 | 102 | print "database=".$conf->db->name."\n"; |
103 | 103 | print "----- Options:\n"; |
104 | 104 | print "commitiferror=".$forcecommit."\n"; |
105 | -print "Mapped LDAP fields=".join(',',$required_fields)."\n"; |
|
105 | +print "Mapped LDAP fields=".join(',', $required_fields)."\n"; |
|
106 | 106 | print "\n"; |
107 | 107 | |
108 | -if (! $confirmed) |
|
108 | +if (!$confirmed) |
|
109 | 109 | { |
110 | 110 | print "Hit Enter to continue or CTRL+C to stop...\n"; |
111 | 111 | $input = trim(fgets(STDIN)); |
@@ -122,13 +122,13 @@ discard block |
||
122 | 122 | $result = $ldap->connect_bind(); |
123 | 123 | if ($result >= 0) |
124 | 124 | { |
125 | - $justthese=array(); |
|
125 | + $justthese = array(); |
|
126 | 126 | |
127 | 127 | |
128 | 128 | // We disable synchro Dolibarr-LDAP |
129 | - $conf->global->LDAP_MEMBER_TYPE_ACTIVE=0; |
|
129 | + $conf->global->LDAP_MEMBER_TYPE_ACTIVE = 0; |
|
130 | 130 | |
131 | - $ldaprecords = $ldap->getRecords('*',$conf->global->LDAP_MEMBER_TYPE_DN, $conf->global->LDAP_KEY_MEMBERS_TYPES, $required_fields, 0, array($conf->global->LDAP_MEMBER_TYPE_FIELD_GROUPMEMBERS)); |
|
131 | + $ldaprecords = $ldap->getRecords('*', $conf->global->LDAP_MEMBER_TYPE_DN, $conf->global->LDAP_KEY_MEMBERS_TYPES, $required_fields, 0, array($conf->global->LDAP_MEMBER_TYPE_FIELD_GROUPMEMBERS)); |
|
132 | 132 | if (is_array($ldaprecords)) |
133 | 133 | { |
134 | 134 | $db->begin(); |
@@ -146,7 +146,7 @@ discard block |
||
146 | 146 | |
147 | 147 | if ($membertype->id > 0) { // Member type update |
148 | 148 | print $langs->transnoentities("MemberTypeUpdate").' # '.$key.': name='.$membertype->label; |
149 | - $res=$membertype->update($user); |
|
149 | + $res = $membertype->update($user); |
|
150 | 150 | |
151 | 151 | if ($res > 0) |
152 | 152 | { |
@@ -160,7 +160,7 @@ discard block |
||
160 | 160 | print "\n"; |
161 | 161 | } else { // Member type creation |
162 | 162 | print $langs->transnoentities("MemberTypeCreate").' # '.$key.': name='.$membertype->label; |
163 | - $res=$membertype->create($user); |
|
163 | + $res = $membertype->create($user); |
|
164 | 164 | |
165 | 165 | if ($res > 0) |
166 | 166 | { |
@@ -177,28 +177,28 @@ discard block |
||
177 | 177 | //print_r($membertype); |
178 | 178 | } |
179 | 179 | |
180 | - if (! $error || $forcecommit) |
|
180 | + if (!$error || $forcecommit) |
|
181 | 181 | { |
182 | - if (! $error) print $langs->transnoentities("NoErrorCommitIsDone")."\n"; |
|
182 | + if (!$error) print $langs->transnoentities("NoErrorCommitIsDone")."\n"; |
|
183 | 183 | else print $langs->transnoentities("ErrorButCommitIsDone")."\n"; |
184 | 184 | $db->commit(); |
185 | 185 | } |
186 | 186 | else |
187 | 187 | { |
188 | - print $langs->transnoentities("ErrorSomeErrorWereFoundRollbackIsDone",$error)."\n"; |
|
188 | + print $langs->transnoentities("ErrorSomeErrorWereFoundRollbackIsDone", $error)."\n"; |
|
189 | 189 | $db->rollback(); |
190 | 190 | } |
191 | 191 | print "\n"; |
192 | 192 | } |
193 | 193 | else |
194 | 194 | { |
195 | - dol_print_error('',$ldap->error); |
|
195 | + dol_print_error('', $ldap->error); |
|
196 | 196 | $error++; |
197 | 197 | } |
198 | 198 | } |
199 | 199 | else |
200 | 200 | { |
201 | - dol_print_error('',$ldap->error); |
|
201 | + dol_print_error('', $ldap->error); |
|
202 | 202 | $error++; |
203 | 203 | } |
204 | 204 |
@@ -78,11 +78,19 @@ discard block |
||
78 | 78 | |
79 | 79 | foreach($argv as $key => $val) |
80 | 80 | { |
81 | - if ($val == 'commitiferror') $forcecommit=1; |
|
82 | - if (preg_match('/--server=([^\s]+)$/',$val,$reg)) $conf->global->LDAP_SERVER_HOST=$reg[1]; |
|
83 | - if (preg_match('/--excludeuser=([^\s]+)$/',$val,$reg)) $excludeuser=explode(',',$reg[1]); |
|
84 | - if (preg_match('/-y$/',$val,$reg)) $confirmed=1; |
|
85 | -} |
|
81 | + if ($val == 'commitiferror') { |
|
82 | + $forcecommit=1; |
|
83 | + } |
|
84 | + if (preg_match('/--server=([^\s]+)$/',$val,$reg)) { |
|
85 | + $conf->global->LDAP_SERVER_HOST=$reg[1]; |
|
86 | + } |
|
87 | + if (preg_match('/--excludeuser=([^\s]+)$/',$val,$reg)) { |
|
88 | + $excludeuser=explode(',',$reg[1]); |
|
89 | + } |
|
90 | + if (preg_match('/-y$/',$val,$reg)) { |
|
91 | + $confirmed=1; |
|
92 | + } |
|
93 | + } |
|
86 | 94 | |
87 | 95 | print "Mails sending disabled (useless in batch mode)\n"; |
88 | 96 | $conf->global->MAIN_DISABLE_ALL_MAILS=1; // On bloque les mails |
@@ -151,8 +159,7 @@ discard block |
||
151 | 159 | if ($res > 0) |
152 | 160 | { |
153 | 161 | print ' --> Updated member type id='.$membertype->id.' name='.$membertype->label; |
154 | - } |
|
155 | - else |
|
162 | + } else |
|
156 | 163 | { |
157 | 164 | $error++; |
158 | 165 | print ' --> '.$res.' '.$membertype->error; |
@@ -165,8 +172,7 @@ discard block |
||
165 | 172 | if ($res > 0) |
166 | 173 | { |
167 | 174 | print ' --> Created member type id='.$membertype->id.' name='.$membertype->label; |
168 | - } |
|
169 | - else |
|
175 | + } else |
|
170 | 176 | { |
171 | 177 | $error++; |
172 | 178 | print ' --> '.$res.' '.$membertype->error; |
@@ -179,24 +185,24 @@ discard block |
||
179 | 185 | |
180 | 186 | if (! $error || $forcecommit) |
181 | 187 | { |
182 | - if (! $error) print $langs->transnoentities("NoErrorCommitIsDone")."\n"; |
|
183 | - else print $langs->transnoentities("ErrorButCommitIsDone")."\n"; |
|
188 | + if (! $error) { |
|
189 | + print $langs->transnoentities("NoErrorCommitIsDone")."\n"; |
|
190 | + } else { |
|
191 | + print $langs->transnoentities("ErrorButCommitIsDone")."\n"; |
|
192 | + } |
|
184 | 193 | $db->commit(); |
185 | - } |
|
186 | - else |
|
194 | + } else |
|
187 | 195 | { |
188 | 196 | print $langs->transnoentities("ErrorSomeErrorWereFoundRollbackIsDone",$error)."\n"; |
189 | 197 | $db->rollback(); |
190 | 198 | } |
191 | 199 | print "\n"; |
192 | - } |
|
193 | - else |
|
200 | + } else |
|
194 | 201 | { |
195 | 202 | dol_print_error('',$ldap->error); |
196 | 203 | $error++; |
197 | 204 | } |
198 | -} |
|
199 | -else |
|
205 | +} else |
|
200 | 206 | { |
201 | 207 | dol_print_error('',$ldap->error); |
202 | 208 | $error++; |
@@ -30,7 +30,7 @@ discard block |
||
30 | 30 | // Test if batch mode |
31 | 31 | if (substr($sapi_type, 0, 3) == 'cgi') { |
32 | 32 | echo "Error: You are using PHP for CGI. To execute ".$script_file." from command line, you must use PHP for CLI mode.\n"; |
33 | - exit(-1); |
|
33 | + exit(-1); |
|
34 | 34 | } |
35 | 35 | |
36 | 36 | @set_time_limit(0); // No timeout for this script |
@@ -58,7 +58,7 @@ discard block |
||
58 | 58 | |
59 | 59 | if (! isset($argv[1]) || $argv[1] != 'product') { |
60 | 60 | print "Usage: $script_file product\n"; |
61 | - exit(-1); |
|
61 | + exit(-1); |
|
62 | 62 | } |
63 | 63 | |
64 | 64 | print '--- start'."\n"; |
@@ -66,24 +66,24 @@ discard block |
||
66 | 66 | // Case to migrate products path |
67 | 67 | if ($argv[1] == 'product') |
68 | 68 | { |
69 | - $product = new Product($db); |
|
70 | - |
|
71 | - $sql = "SELECT rowid as pid from ".MAIN_DB_PREFIX."product"; // Get list of all products |
|
72 | - $resql = $db->query($sql); |
|
73 | - if ($resql) |
|
74 | - { |
|
75 | - while ($obj = $db->fetch_object($resql)) |
|
76 | - { |
|
77 | - $product->fetch($obj->pid); |
|
78 | - print " migrating product id=".$product->id." ref=".$product->ref."\n"; |
|
79 | - migrate_product_photospath($product); |
|
80 | - } |
|
81 | - } |
|
82 | - else |
|
83 | - { |
|
84 | - print "\n sql error ".$sql; |
|
85 | - exit; |
|
86 | - } |
|
69 | + $product = new Product($db); |
|
70 | + |
|
71 | + $sql = "SELECT rowid as pid from ".MAIN_DB_PREFIX."product"; // Get list of all products |
|
72 | + $resql = $db->query($sql); |
|
73 | + if ($resql) |
|
74 | + { |
|
75 | + while ($obj = $db->fetch_object($resql)) |
|
76 | + { |
|
77 | + $product->fetch($obj->pid); |
|
78 | + print " migrating product id=".$product->id." ref=".$product->ref."\n"; |
|
79 | + migrate_product_photospath($product); |
|
80 | + } |
|
81 | + } |
|
82 | + else |
|
83 | + { |
|
84 | + print "\n sql error ".$sql; |
|
85 | + exit; |
|
86 | + } |
|
87 | 87 | } |
88 | 88 | |
89 | 89 | |
@@ -101,47 +101,47 @@ discard block |
||
101 | 101 | */ |
102 | 102 | function migrate_product_photospath($product) |
103 | 103 | { |
104 | - global $conf; |
|
104 | + global $conf; |
|
105 | 105 | |
106 | - $dir = $conf->product->multidir_output[$product->entity]; |
|
107 | - $conf->global->PRODUCT_USE_OLD_PATH_FOR_PHOTO = 1; |
|
108 | - $origin = $dir .'/'. get_exdir($product->id,2,0,0,$product,'product') . $product->id ."/photos"; |
|
109 | - $destin = $dir.'/'.dol_sanitizeFileName($product->ref); |
|
106 | + $dir = $conf->product->multidir_output[$product->entity]; |
|
107 | + $conf->global->PRODUCT_USE_OLD_PATH_FOR_PHOTO = 1; |
|
108 | + $origin = $dir .'/'. get_exdir($product->id,2,0,0,$product,'product') . $product->id ."/photos"; |
|
109 | + $destin = $dir.'/'.dol_sanitizeFileName($product->ref); |
|
110 | 110 | |
111 | - $error = 0; |
|
111 | + $error = 0; |
|
112 | 112 | |
113 | - $origin_osencoded=dol_osencode($origin); |
|
114 | - $destin_osencoded=dol_osencode($destin); |
|
115 | - dol_mkdir($destin); |
|
113 | + $origin_osencoded=dol_osencode($origin); |
|
114 | + $destin_osencoded=dol_osencode($destin); |
|
115 | + dol_mkdir($destin); |
|
116 | 116 | |
117 | - if (dol_is_dir($origin)) |
|
118 | - { |
|
119 | - $handle=opendir($origin_osencoded); |
|
117 | + if (dol_is_dir($origin)) |
|
118 | + { |
|
119 | + $handle=opendir($origin_osencoded); |
|
120 | 120 | if (is_resource($handle)) |
121 | 121 | { |
122 | - while (($file = readdir($handle)) !== false) |
|
123 | - { |
|
124 | - if ($file != '.' && $file != '..' && is_dir($origin_osencoded.'/'.$file)) |
|
125 | - { |
|
126 | - $thumbs = opendir($origin_osencoded.'/'.$file); |
|
127 | - if (is_resource($thumbs)) |
|
128 | - { |
|
129 | - dol_mkdir($destin.'/'.$file); |
|
130 | - while (($thumb = readdir($thumbs)) !== false) |
|
131 | - { |
|
132 | - dol_move($origin.'/'.$file.'/'.$thumb, $destin.'/'.$file.'/'.$thumb); |
|
133 | - } |
|
122 | + while (($file = readdir($handle)) !== false) |
|
123 | + { |
|
124 | + if ($file != '.' && $file != '..' && is_dir($origin_osencoded.'/'.$file)) |
|
125 | + { |
|
126 | + $thumbs = opendir($origin_osencoded.'/'.$file); |
|
127 | + if (is_resource($thumbs)) |
|
128 | + { |
|
129 | + dol_mkdir($destin.'/'.$file); |
|
130 | + while (($thumb = readdir($thumbs)) !== false) |
|
131 | + { |
|
132 | + dol_move($origin.'/'.$file.'/'.$thumb, $destin.'/'.$file.'/'.$thumb); |
|
133 | + } |
|
134 | 134 | // dol_delete_dir($origin.'/'.$file); |
135 | - } |
|
136 | - } |
|
137 | - else |
|
138 | - { |
|
139 | - if (dol_is_file($origin.'/'.$file) ) |
|
140 | - { |
|
141 | - dol_move($origin.'/'.$file, $destin.'/'.$file); |
|
142 | - } |
|
143 | - } |
|
144 | - } |
|
135 | + } |
|
136 | + } |
|
137 | + else |
|
138 | + { |
|
139 | + if (dol_is_file($origin.'/'.$file) ) |
|
140 | + { |
|
141 | + dol_move($origin.'/'.$file, $destin.'/'.$file); |
|
142 | + } |
|
143 | + } |
|
144 | + } |
|
145 | 145 | } |
146 | - } |
|
146 | + } |
|
147 | 147 | } |
@@ -25,7 +25,7 @@ discard block |
||
25 | 25 | |
26 | 26 | $sapi_type = php_sapi_name(); |
27 | 27 | $script_file = basename(__FILE__); |
28 | -$path=dirname(__FILE__).'/'; |
|
28 | +$path = dirname(__FILE__).'/'; |
|
29 | 29 | |
30 | 30 | // Test if batch mode |
31 | 31 | if (substr($sapi_type, 0, 3) == 'cgi') { |
@@ -33,8 +33,8 @@ discard block |
||
33 | 33 | exit(-1); |
34 | 34 | } |
35 | 35 | |
36 | -@set_time_limit(0); // No timeout for this script |
|
37 | -define('EVEN_IF_ONLY_LOGIN_ALLOWED',1); // Set this define to 0 if you want to lock your script when dolibarr setup is "locked to admin user only". |
|
36 | +@set_time_limit(0); // No timeout for this script |
|
37 | +define('EVEN_IF_ONLY_LOGIN_ALLOWED', 1); // Set this define to 0 if you want to lock your script when dolibarr setup is "locked to admin user only". |
|
38 | 38 | |
39 | 39 | // Include and load Dolibarr environment variables |
40 | 40 | require_once $path."../../htdocs/master.inc.php"; |
@@ -44,19 +44,19 @@ discard block |
||
44 | 44 | // $user is created but empty. |
45 | 45 | |
46 | 46 | //$langs->setDefaultLang('en_US'); // To change default language of $langs |
47 | -$langs->load("main"); // To load language file for default language |
|
47 | +$langs->load("main"); // To load language file for default language |
|
48 | 48 | |
49 | 49 | |
50 | 50 | // Global variables |
51 | -$version=DOL_VERSION; |
|
52 | -$error=0; |
|
53 | -$forcecommit=0; |
|
51 | +$version = DOL_VERSION; |
|
52 | +$error = 0; |
|
53 | +$forcecommit = 0; |
|
54 | 54 | |
55 | 55 | |
56 | 56 | print "***** ".$script_file." (".$version.") pid=".dol_getmypid()." *****\n"; |
57 | -dol_syslog($script_file." launched with arg ".join(',',$argv)); |
|
57 | +dol_syslog($script_file." launched with arg ".join(',', $argv)); |
|
58 | 58 | |
59 | -if (! isset($argv[1]) || $argv[1] != 'product') { |
|
59 | +if (!isset($argv[1]) || $argv[1] != 'product') { |
|
60 | 60 | print "Usage: $script_file product\n"; |
61 | 61 | exit(-1); |
62 | 62 | } |
@@ -68,7 +68,7 @@ discard block |
||
68 | 68 | { |
69 | 69 | $product = new Product($db); |
70 | 70 | |
71 | - $sql = "SELECT rowid as pid from ".MAIN_DB_PREFIX."product"; // Get list of all products |
|
71 | + $sql = "SELECT rowid as pid from ".MAIN_DB_PREFIX."product"; // Get list of all products |
|
72 | 72 | $resql = $db->query($sql); |
73 | 73 | if ($resql) |
74 | 74 | { |
@@ -87,7 +87,7 @@ discard block |
||
87 | 87 | } |
88 | 88 | |
89 | 89 | |
90 | -$db->close(); // Close $db database opened handler |
|
90 | +$db->close(); // Close $db database opened handler |
|
91 | 91 | |
92 | 92 | exit($error); |
93 | 93 | |
@@ -105,18 +105,18 @@ discard block |
||
105 | 105 | |
106 | 106 | $dir = $conf->product->multidir_output[$product->entity]; |
107 | 107 | $conf->global->PRODUCT_USE_OLD_PATH_FOR_PHOTO = 1; |
108 | - $origin = $dir .'/'. get_exdir($product->id,2,0,0,$product,'product') . $product->id ."/photos"; |
|
108 | + $origin = $dir.'/'.get_exdir($product->id, 2, 0, 0, $product, 'product').$product->id."/photos"; |
|
109 | 109 | $destin = $dir.'/'.dol_sanitizeFileName($product->ref); |
110 | 110 | |
111 | 111 | $error = 0; |
112 | 112 | |
113 | - $origin_osencoded=dol_osencode($origin); |
|
114 | - $destin_osencoded=dol_osencode($destin); |
|
113 | + $origin_osencoded = dol_osencode($origin); |
|
114 | + $destin_osencoded = dol_osencode($destin); |
|
115 | 115 | dol_mkdir($destin); |
116 | 116 | |
117 | 117 | if (dol_is_dir($origin)) |
118 | 118 | { |
119 | - $handle=opendir($origin_osencoded); |
|
119 | + $handle = opendir($origin_osencoded); |
|
120 | 120 | if (is_resource($handle)) |
121 | 121 | { |
122 | 122 | while (($file = readdir($handle)) !== false) |
@@ -136,7 +136,7 @@ discard block |
||
136 | 136 | } |
137 | 137 | else |
138 | 138 | { |
139 | - if (dol_is_file($origin.'/'.$file) ) |
|
139 | + if (dol_is_file($origin.'/'.$file)) |
|
140 | 140 | { |
141 | 141 | dol_move($origin.'/'.$file, $destin.'/'.$file); |
142 | 142 | } |
@@ -78,8 +78,7 @@ discard block |
||
78 | 78 | print " migrating product id=".$product->id." ref=".$product->ref."\n"; |
79 | 79 | migrate_product_photospath($product); |
80 | 80 | } |
81 | - } |
|
82 | - else |
|
81 | + } else |
|
83 | 82 | { |
84 | 83 | print "\n sql error ".$sql; |
85 | 84 | exit; |
@@ -133,8 +132,7 @@ discard block |
||
133 | 132 | } |
134 | 133 | // dol_delete_dir($origin.'/'.$file); |
135 | 134 | } |
136 | - } |
|
137 | - else |
|
135 | + } else |
|
138 | 136 | { |
139 | 137 | if (dol_is_file($origin.'/'.$file) ) |
140 | 138 | { |
@@ -30,7 +30,7 @@ discard block |
||
30 | 30 | // Test if batch mode |
31 | 31 | if (substr($sapi_type, 0, 3) == 'cgi') { |
32 | 32 | echo "Error: You are using PHP for CGI. To execute ".$script_file." from command line, you must use PHP for CLI mode.\n"; |
33 | - exit(-1); |
|
33 | + exit(-1); |
|
34 | 34 | } |
35 | 35 | |
36 | 36 | @set_time_limit(0); // No timeout for this script |
@@ -69,13 +69,13 @@ discard block |
||
69 | 69 | $subdir=$argv[1]; |
70 | 70 | if (empty($dir) || empty($subdir)) |
71 | 71 | { |
72 | - dol_print_error('', 'dir not defined'); |
|
73 | - exit(1); |
|
72 | + dol_print_error('', 'dir not defined'); |
|
73 | + exit(1); |
|
74 | 74 | } |
75 | 75 | if (! dol_is_dir($dir.'/'.$subdir)) |
76 | 76 | { |
77 | - print 'Directory '.$dir.'/'.$subdir.' not found.'."\n"; |
|
78 | - exit(2); |
|
77 | + print 'Directory '.$dir.'/'.$subdir.' not found.'."\n"; |
|
78 | + exit(2); |
|
79 | 79 | } |
80 | 80 | |
81 | 81 | $filearray=dol_dir_list($dir.'/'.$subdir,"directories",0,'','temp$'); |
@@ -84,22 +84,22 @@ discard block |
||
84 | 84 | |
85 | 85 | foreach($filearray as $keyf => $valf) |
86 | 86 | { |
87 | - $ref=basename($valf['name']); |
|
88 | - $filearrayimg=dol_dir_list($valf['fullname'],"files",0,'(\.gif|\.png|\.jpg|\.jpeg|\.bmp)$','(\.meta|_preview.*\.png)$'); |
|
89 | - foreach($filearrayimg as $keyi => $vali) |
|
90 | - { |
|
91 | - print 'Process image for ref '.$ref.' : '.$vali['name']."\n"; |
|
92 | - |
|
93 | - // Create small thumbs for image |
|
94 | - // Used on logon for example |
|
95 | - $imgThumbSmall = vignette($vali['fullname'], $maxwidthsmall, $maxheightsmall, '_small', 50, "thumbs"); |
|
96 | - if (preg_match('/Error/', $imgThumbSmall)) print $imgThumbSmall."\n"; |
|
97 | - |
|
98 | - // Create mini thumbs for image (Ratio is near 16/9) |
|
99 | - // Used on menu or for setup page for example |
|
100 | - $imgThumbMini = vignette($vali['fullname'], $maxwidthmini, $maxheightmini, '_mini', 50, "thumbs"); |
|
101 | - if (preg_match('/Error/', $imgThumbMini)) print $imgThumbMini."\n"; |
|
102 | - } |
|
87 | + $ref=basename($valf['name']); |
|
88 | + $filearrayimg=dol_dir_list($valf['fullname'],"files",0,'(\.gif|\.png|\.jpg|\.jpeg|\.bmp)$','(\.meta|_preview.*\.png)$'); |
|
89 | + foreach($filearrayimg as $keyi => $vali) |
|
90 | + { |
|
91 | + print 'Process image for ref '.$ref.' : '.$vali['name']."\n"; |
|
92 | + |
|
93 | + // Create small thumbs for image |
|
94 | + // Used on logon for example |
|
95 | + $imgThumbSmall = vignette($vali['fullname'], $maxwidthsmall, $maxheightsmall, '_small', 50, "thumbs"); |
|
96 | + if (preg_match('/Error/', $imgThumbSmall)) print $imgThumbSmall."\n"; |
|
97 | + |
|
98 | + // Create mini thumbs for image (Ratio is near 16/9) |
|
99 | + // Used on menu or for setup page for example |
|
100 | + $imgThumbMini = vignette($vali['fullname'], $maxwidthmini, $maxheightmini, '_mini', 50, "thumbs"); |
|
101 | + if (preg_match('/Error/', $imgThumbMini)) print $imgThumbMini."\n"; |
|
102 | + } |
|
103 | 103 | } |
104 | 104 | |
105 | 105 | $db->close(); // Close $db database opened handler |
@@ -25,7 +25,7 @@ discard block |
||
25 | 25 | |
26 | 26 | $sapi_type = php_sapi_name(); |
27 | 27 | $script_file = basename(__FILE__); |
28 | -$path=dirname(__FILE__).'/'; |
|
28 | +$path = dirname(__FILE__).'/'; |
|
29 | 29 | |
30 | 30 | // Test if batch mode |
31 | 31 | if (substr($sapi_type, 0, 3) == 'cgi') { |
@@ -33,8 +33,8 @@ discard block |
||
33 | 33 | exit(-1); |
34 | 34 | } |
35 | 35 | |
36 | -@set_time_limit(0); // No timeout for this script |
|
37 | -define('EVEN_IF_ONLY_LOGIN_ALLOWED',1); // Set this define to 0 if you want to lock your script when dolibarr setup is "locked to admin user only". |
|
36 | +@set_time_limit(0); // No timeout for this script |
|
37 | +define('EVEN_IF_ONLY_LOGIN_ALLOWED', 1); // Set this define to 0 if you want to lock your script when dolibarr setup is "locked to admin user only". |
|
38 | 38 | |
39 | 39 | // Include and load Dolibarr environment variables |
40 | 40 | require_once $path."../../htdocs/master.inc.php"; |
@@ -45,17 +45,17 @@ discard block |
||
45 | 45 | // $user is created but empty. |
46 | 46 | |
47 | 47 | //$langs->setDefaultLang('en_US'); // To change default language of $langs |
48 | -$langs->load("main"); // To load language file for default language |
|
48 | +$langs->load("main"); // To load language file for default language |
|
49 | 49 | |
50 | 50 | |
51 | 51 | // Global variables |
52 | -$version=DOL_VERSION; |
|
53 | -$error=0; |
|
54 | -$forcecommit=0; |
|
52 | +$version = DOL_VERSION; |
|
53 | +$error = 0; |
|
54 | +$forcecommit = 0; |
|
55 | 55 | |
56 | 56 | |
57 | 57 | print "***** ".$script_file." (".$version.") pid=".dol_getmypid()." *****\n"; |
58 | -dol_syslog($script_file." launched with arg ".join(',',$argv)); |
|
58 | +dol_syslog($script_file." launched with arg ".join(',', $argv)); |
|
59 | 59 | |
60 | 60 | if (empty($argv[1])) { |
61 | 61 | print "Usage: $script_file subdirtoscan\n"; |
@@ -66,27 +66,27 @@ discard block |
||
66 | 66 | print '--- start'."\n"; |
67 | 67 | |
68 | 68 | $dir = DOL_DATA_ROOT; |
69 | -$subdir=$argv[1]; |
|
69 | +$subdir = $argv[1]; |
|
70 | 70 | if (empty($dir) || empty($subdir)) |
71 | 71 | { |
72 | 72 | dol_print_error('', 'dir not defined'); |
73 | 73 | exit(1); |
74 | 74 | } |
75 | -if (! dol_is_dir($dir.'/'.$subdir)) |
|
75 | +if (!dol_is_dir($dir.'/'.$subdir)) |
|
76 | 76 | { |
77 | 77 | print 'Directory '.$dir.'/'.$subdir.' not found.'."\n"; |
78 | 78 | exit(2); |
79 | 79 | } |
80 | 80 | |
81 | -$filearray=dol_dir_list($dir.'/'.$subdir,"directories",0,'','temp$'); |
|
81 | +$filearray = dol_dir_list($dir.'/'.$subdir, "directories", 0, '', 'temp$'); |
|
82 | 82 | |
83 | 83 | global $maxwidthsmall, $maxheightsmall, $maxwidthmini, $maxheightmini; |
84 | 84 | |
85 | -foreach($filearray as $keyf => $valf) |
|
85 | +foreach ($filearray as $keyf => $valf) |
|
86 | 86 | { |
87 | - $ref=basename($valf['name']); |
|
88 | - $filearrayimg=dol_dir_list($valf['fullname'],"files",0,'(\.gif|\.png|\.jpg|\.jpeg|\.bmp)$','(\.meta|_preview.*\.png)$'); |
|
89 | - foreach($filearrayimg as $keyi => $vali) |
|
87 | + $ref = basename($valf['name']); |
|
88 | + $filearrayimg = dol_dir_list($valf['fullname'], "files", 0, '(\.gif|\.png|\.jpg|\.jpeg|\.bmp)$', '(\.meta|_preview.*\.png)$'); |
|
89 | + foreach ($filearrayimg as $keyi => $vali) |
|
90 | 90 | { |
91 | 91 | print 'Process image for ref '.$ref.' : '.$vali['name']."\n"; |
92 | 92 | |
@@ -102,6 +102,6 @@ discard block |
||
102 | 102 | } |
103 | 103 | } |
104 | 104 | |
105 | -$db->close(); // Close $db database opened handler |
|
105 | +$db->close(); // Close $db database opened handler |
|
106 | 106 | |
107 | 107 | exit($error); |
@@ -93,12 +93,16 @@ |
||
93 | 93 | // Create small thumbs for image |
94 | 94 | // Used on logon for example |
95 | 95 | $imgThumbSmall = vignette($vali['fullname'], $maxwidthsmall, $maxheightsmall, '_small', 50, "thumbs"); |
96 | - if (preg_match('/Error/', $imgThumbSmall)) print $imgThumbSmall."\n"; |
|
96 | + if (preg_match('/Error/', $imgThumbSmall)) { |
|
97 | + print $imgThumbSmall."\n"; |
|
98 | + } |
|
97 | 99 | |
98 | 100 | // Create mini thumbs for image (Ratio is near 16/9) |
99 | 101 | // Used on menu or for setup page for example |
100 | 102 | $imgThumbMini = vignette($vali['fullname'], $maxwidthmini, $maxheightmini, '_mini', 50, "thumbs"); |
101 | - if (preg_match('/Error/', $imgThumbMini)) print $imgThumbMini."\n"; |
|
103 | + if (preg_match('/Error/', $imgThumbMini)) { |
|
104 | + print $imgThumbMini."\n"; |
|
105 | + } |
|
102 | 106 | } |
103 | 107 | } |
104 | 108 |