@@ -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 | |
@@ -33,9 +33,9 @@ discard block |
||
| 33 | 33 | |
| 34 | 34 | if (empty($user->id)) |
| 35 | 35 | { |
| 36 | - print "Load permissions for admin user nb 1\n"; |
|
| 37 | - $user->fetch(1); |
|
| 38 | - $user->getrights(); |
|
| 36 | + print "Load permissions for admin user nb 1\n"; |
|
| 37 | + $user->fetch(1); |
|
| 38 | + $user->getrights(); |
|
| 39 | 39 | } |
| 40 | 40 | $conf->global->MAIN_DISABLE_ALL_MAILS=1; |
| 41 | 41 | |
@@ -49,74 +49,74 @@ discard block |
||
| 49 | 49 | */ |
| 50 | 50 | class MouvementStockTest extends PHPUnit_Framework_TestCase |
| 51 | 51 | { |
| 52 | - protected $savconf; |
|
| 53 | - protected $savuser; |
|
| 54 | - protected $savlangs; |
|
| 55 | - protected $savdb; |
|
| 56 | - |
|
| 57 | - /** |
|
| 58 | - * Constructor |
|
| 59 | - * We save global variables into local variables |
|
| 60 | - * |
|
| 61 | - * @return ContratTest |
|
| 62 | - */ |
|
| 63 | - function __construct() |
|
| 64 | - { |
|
| 65 | - parent::__construct(); |
|
| 66 | - |
|
| 67 | - //$this->sharedFixture |
|
| 68 | - global $conf,$user,$langs,$db; |
|
| 69 | - $this->savconf=$conf; |
|
| 70 | - $this->savuser=$user; |
|
| 71 | - $this->savlangs=$langs; |
|
| 72 | - $this->savdb=$db; |
|
| 73 | - |
|
| 74 | - print __METHOD__." db->type=".$db->type." user->id=".$user->id; |
|
| 75 | - //print " - db ".$db->db; |
|
| 76 | - print "\n"; |
|
| 77 | - } |
|
| 78 | - |
|
| 79 | - // Static methods |
|
| 80 | - public static function setUpBeforeClass() |
|
| 52 | + protected $savconf; |
|
| 53 | + protected $savuser; |
|
| 54 | + protected $savlangs; |
|
| 55 | + protected $savdb; |
|
| 56 | + |
|
| 57 | + /** |
|
| 58 | + * Constructor |
|
| 59 | + * We save global variables into local variables |
|
| 60 | + * |
|
| 61 | + * @return ContratTest |
|
| 62 | + */ |
|
| 63 | + function __construct() |
|
| 64 | + { |
|
| 65 | + parent::__construct(); |
|
| 66 | + |
|
| 67 | + //$this->sharedFixture |
|
| 68 | + global $conf,$user,$langs,$db; |
|
| 69 | + $this->savconf=$conf; |
|
| 70 | + $this->savuser=$user; |
|
| 71 | + $this->savlangs=$langs; |
|
| 72 | + $this->savdb=$db; |
|
| 73 | + |
|
| 74 | + print __METHOD__." db->type=".$db->type." user->id=".$user->id; |
|
| 75 | + //print " - db ".$db->db; |
|
| 76 | + print "\n"; |
|
| 77 | + } |
|
| 78 | + |
|
| 79 | + // Static methods |
|
| 80 | + public static function setUpBeforeClass() |
|
| 81 | 81 | { |
| 82 | - global $conf,$user,$langs,$db; |
|
| 83 | - $db->begin(); // This is to have all actions inside a transaction even if test launched without suite. |
|
| 82 | + global $conf,$user,$langs,$db; |
|
| 83 | + $db->begin(); // This is to have all actions inside a transaction even if test launched without suite. |
|
| 84 | 84 | |
| 85 | - print __METHOD__."\n"; |
|
| 85 | + print __METHOD__."\n"; |
|
| 86 | 86 | } |
| 87 | 87 | |
| 88 | 88 | // tear down after class |
| 89 | 89 | public static function tearDownAfterClass() |
| 90 | 90 | { |
| 91 | - global $conf,$user,$langs,$db; |
|
| 92 | - $db->rollback(); |
|
| 91 | + global $conf,$user,$langs,$db; |
|
| 92 | + $db->rollback(); |
|
| 93 | 93 | |
| 94 | - print __METHOD__."\n"; |
|
| 94 | + print __METHOD__."\n"; |
|
| 95 | 95 | } |
| 96 | 96 | |
| 97 | - /** |
|
| 98 | - * Init phpunit tests |
|
| 99 | - * |
|
| 100 | - * @return void |
|
| 101 | - */ |
|
| 97 | + /** |
|
| 98 | + * Init phpunit tests |
|
| 99 | + * |
|
| 100 | + * @return void |
|
| 101 | + */ |
|
| 102 | 102 | protected function setUp() |
| 103 | 103 | { |
| 104 | - global $conf,$user,$langs,$db; |
|
| 105 | - $conf=$this->savconf; |
|
| 106 | - $user=$this->savuser; |
|
| 107 | - $langs=$this->savlangs; |
|
| 108 | - $db=$this->savdb; |
|
| 104 | + global $conf,$user,$langs,$db; |
|
| 105 | + $conf=$this->savconf; |
|
| 106 | + $user=$this->savuser; |
|
| 107 | + $langs=$this->savlangs; |
|
| 108 | + $db=$this->savdb; |
|
| 109 | 109 | |
| 110 | - print __METHOD__."\n"; |
|
| 110 | + print __METHOD__."\n"; |
|
| 111 | 111 | } |
| 112 | - /** |
|
| 113 | - * End phpunit tests |
|
| 114 | - * |
|
| 115 | - * @return void |
|
| 116 | - */ |
|
| 112 | + /** |
|
| 113 | + * End phpunit tests |
|
| 114 | + * |
|
| 115 | + * @return void |
|
| 116 | + */ |
|
| 117 | 117 | protected function tearDown() |
| 118 | 118 | { |
| 119 | - print __METHOD__."\n"; |
|
| 119 | + print __METHOD__."\n"; |
|
| 120 | 120 | } |
| 121 | 121 | |
| 122 | 122 | /** |
@@ -126,97 +126,97 @@ discard block |
||
| 126 | 126 | */ |
| 127 | 127 | public function testMouvementCreate() |
| 128 | 128 | { |
| 129 | - global $conf,$user,$langs,$db; |
|
| 130 | - $conf=$this->savconf; |
|
| 131 | - $user=$this->savuser; |
|
| 132 | - $langs=$this->savlangs; |
|
| 133 | - $db=$this->savdb; |
|
| 134 | - |
|
| 135 | - // We create a product for tests |
|
| 136 | - $product1=new Product($db); |
|
| 137 | - $product1->initAsSpecimen(); |
|
| 138 | - $product1->ref.=' 1'; |
|
| 139 | - $product1->label.=' 1'; |
|
| 140 | - $product1id=$product1->create($user); |
|
| 141 | - |
|
| 142 | - $product2=new Product($db); |
|
| 143 | - $product2->initAsSpecimen(); |
|
| 144 | - $product2->ref.=' 2'; |
|
| 145 | - $product2->label.=' 2'; |
|
| 146 | - $product2id=$product2->create($user); |
|
| 147 | - |
|
| 148 | - // We create a product for tests |
|
| 149 | - $warehouse1=new Entrepot($db); |
|
| 150 | - $warehouse1->initAsSpecimen(); |
|
| 151 | - $warehouse1->libelle.=' 1'; |
|
| 152 | - $warehouse1->description.=' 1'; |
|
| 153 | - $warehouse1id=$warehouse1->create($user); |
|
| 154 | - |
|
| 155 | - $warehouse2=new Entrepot($db); |
|
| 156 | - $warehouse2->initAsSpecimen(); |
|
| 157 | - $warehouse2->libelle.=' 2'; |
|
| 158 | - $warehouse2->description.=' 2'; |
|
| 159 | - $warehouse2id=$warehouse2->create($user); |
|
| 160 | - |
|
| 161 | - $localobject=new MouvementStock($this->savdb); |
|
| 162 | - |
|
| 163 | - // Do a list of movement into warehouse 1 |
|
| 164 | - |
|
| 165 | - // Create an input movement (type = 3) of price 9.9 -> shoul dupdate PMP to 9.9 |
|
| 166 | - $result=$localobject->_create($user, $product1id, $warehouse1id, 10, 3, 9.9, 'Movement for unit test 1', 'Inventory Code Test'); |
|
| 167 | - print __METHOD__." result=".$result."\n"; |
|
| 168 | - $this->assertLessThan($result, 0); |
|
| 169 | - |
|
| 170 | - // Create an input movement (type = 3) of price 9.7 -> shoul dupdate PMP to 9.9/9.7 = 9.8 |
|
| 171 | - $result=$localobject->_create($user, $product1id, $warehouse1id, 10, 3, 9.7, 'Movement for unit test 2', 'Inventory Code Test'); |
|
| 172 | - print __METHOD__." result=".$result."\n"; |
|
| 173 | - $this->assertLessThan($result, 0); |
|
| 174 | - |
|
| 175 | - // Create an output movement (type = 2) of price 9.7 -> shoul dupdate PMP to 9.9/9.7 = 9.8 |
|
| 176 | - $result=$localobject->_create($user, $product1id, $warehouse1id, -5, 2, 999, 'Movement for unit test 3', 'Inventory Code Test'); |
|
| 177 | - print __METHOD__." result=".$result."\n"; |
|
| 178 | - $this->assertLessThan($result, 0); |
|
| 179 | - |
|
| 180 | - // Create an output movement (type = 1) of price 9.7 -> shoul dupdate PMP to 9.9/9.7 = 9.8 |
|
| 181 | - $result=$localobject->_create($user, $product1id, $warehouse1id, 1, 0, 0, 'Input from transfer', 'Transfert X'); |
|
| 182 | - print __METHOD__." result=".$result."\n"; |
|
| 183 | - $this->assertLessThan($result, 0); |
|
| 184 | - |
|
| 185 | - // Create an output movement (type = 1) of price 9.7 -> shoul dupdate PMP to 9.9/9.7 = 9.8 |
|
| 186 | - $result=$localobject->_create($user, $product1id, $warehouse1id, -2, 1, 0, 'Output from transfer', 'Transfert Y'); |
|
| 187 | - print __METHOD__." result=".$result."\n"; |
|
| 188 | - $this->assertLessThan($result, 0); |
|
| 189 | - |
|
| 190 | - |
|
| 191 | - // Do same but into warehouse 2 |
|
| 192 | - |
|
| 193 | - // Create an input movement (type = 3) of price 9.9 -> shoul dupdate PMP to 9.9 |
|
| 194 | - $result=$localobject->_create($user, $product1id, $warehouse2id, 10, 3, 9.9, 'Movement for unit test 1 wh 2', 'Inventory Code Test 2'); |
|
| 195 | - print __METHOD__." result=".$result."\n"; |
|
| 196 | - $this->assertLessThan($result, 0); |
|
| 197 | - |
|
| 198 | - // Create an input movement (type = 3) of price 9.7 -> shoul dupdate PMP to 9.9/9.7 = 9.8 |
|
| 199 | - $result=$localobject->_create($user, $product1id, $warehouse2id, 10, 3, 9.7, 'Movement for unit test 2 wh 2', 'Inventory Code Test 2'); |
|
| 200 | - print __METHOD__." result=".$result."\n"; |
|
| 201 | - $this->assertLessThan($result, 0); |
|
| 202 | - |
|
| 203 | - // Create an output movement (type = 2) of price 9.7 -> shoul dupdate PMP to 9.9/9.7 = 9.8 |
|
| 204 | - $result=$localobject->_create($user, $product1id, $warehouse2id, -5, 2, 999, 'Movement for unit test 3 wh 2', 'Inventory Code Test 2'); |
|
| 205 | - print __METHOD__." result=".$result."\n"; |
|
| 206 | - $this->assertLessThan($result, 0); |
|
| 207 | - |
|
| 208 | - // Create an output movement (type = 1) of price 9.7 -> shoul dupdate PMP to 9.9/9.7 = 9.8 |
|
| 209 | - $result=$localobject->_create($user, $product1id, $warehouse2id, 1, 0, 0, 'Input from transfer wh 2', 'Transfert X 2'); |
|
| 210 | - print __METHOD__." result=".$result."\n"; |
|
| 211 | - $this->assertLessThan($result, 0); |
|
| 212 | - |
|
| 213 | - // Create an output movement (type = 1) of price 9.7 -> shoul dupdate PMP to 9.9/9.7 = 9.8 |
|
| 214 | - $result=$localobject->_create($user, $product1id, $warehouse2id, -2, 1, 0, 'Output from transfer wh 2', 'Transfert Y 2'); |
|
| 215 | - print __METHOD__." result=".$result."\n"; |
|
| 216 | - $this->assertLessThan($result, 0); |
|
| 217 | - |
|
| 218 | - |
|
| 219 | - return $localobject; |
|
| 129 | + global $conf,$user,$langs,$db; |
|
| 130 | + $conf=$this->savconf; |
|
| 131 | + $user=$this->savuser; |
|
| 132 | + $langs=$this->savlangs; |
|
| 133 | + $db=$this->savdb; |
|
| 134 | + |
|
| 135 | + // We create a product for tests |
|
| 136 | + $product1=new Product($db); |
|
| 137 | + $product1->initAsSpecimen(); |
|
| 138 | + $product1->ref.=' 1'; |
|
| 139 | + $product1->label.=' 1'; |
|
| 140 | + $product1id=$product1->create($user); |
|
| 141 | + |
|
| 142 | + $product2=new Product($db); |
|
| 143 | + $product2->initAsSpecimen(); |
|
| 144 | + $product2->ref.=' 2'; |
|
| 145 | + $product2->label.=' 2'; |
|
| 146 | + $product2id=$product2->create($user); |
|
| 147 | + |
|
| 148 | + // We create a product for tests |
|
| 149 | + $warehouse1=new Entrepot($db); |
|
| 150 | + $warehouse1->initAsSpecimen(); |
|
| 151 | + $warehouse1->libelle.=' 1'; |
|
| 152 | + $warehouse1->description.=' 1'; |
|
| 153 | + $warehouse1id=$warehouse1->create($user); |
|
| 154 | + |
|
| 155 | + $warehouse2=new Entrepot($db); |
|
| 156 | + $warehouse2->initAsSpecimen(); |
|
| 157 | + $warehouse2->libelle.=' 2'; |
|
| 158 | + $warehouse2->description.=' 2'; |
|
| 159 | + $warehouse2id=$warehouse2->create($user); |
|
| 160 | + |
|
| 161 | + $localobject=new MouvementStock($this->savdb); |
|
| 162 | + |
|
| 163 | + // Do a list of movement into warehouse 1 |
|
| 164 | + |
|
| 165 | + // Create an input movement (type = 3) of price 9.9 -> shoul dupdate PMP to 9.9 |
|
| 166 | + $result=$localobject->_create($user, $product1id, $warehouse1id, 10, 3, 9.9, 'Movement for unit test 1', 'Inventory Code Test'); |
|
| 167 | + print __METHOD__." result=".$result."\n"; |
|
| 168 | + $this->assertLessThan($result, 0); |
|
| 169 | + |
|
| 170 | + // Create an input movement (type = 3) of price 9.7 -> shoul dupdate PMP to 9.9/9.7 = 9.8 |
|
| 171 | + $result=$localobject->_create($user, $product1id, $warehouse1id, 10, 3, 9.7, 'Movement for unit test 2', 'Inventory Code Test'); |
|
| 172 | + print __METHOD__." result=".$result."\n"; |
|
| 173 | + $this->assertLessThan($result, 0); |
|
| 174 | + |
|
| 175 | + // Create an output movement (type = 2) of price 9.7 -> shoul dupdate PMP to 9.9/9.7 = 9.8 |
|
| 176 | + $result=$localobject->_create($user, $product1id, $warehouse1id, -5, 2, 999, 'Movement for unit test 3', 'Inventory Code Test'); |
|
| 177 | + print __METHOD__." result=".$result."\n"; |
|
| 178 | + $this->assertLessThan($result, 0); |
|
| 179 | + |
|
| 180 | + // Create an output movement (type = 1) of price 9.7 -> shoul dupdate PMP to 9.9/9.7 = 9.8 |
|
| 181 | + $result=$localobject->_create($user, $product1id, $warehouse1id, 1, 0, 0, 'Input from transfer', 'Transfert X'); |
|
| 182 | + print __METHOD__." result=".$result."\n"; |
|
| 183 | + $this->assertLessThan($result, 0); |
|
| 184 | + |
|
| 185 | + // Create an output movement (type = 1) of price 9.7 -> shoul dupdate PMP to 9.9/9.7 = 9.8 |
|
| 186 | + $result=$localobject->_create($user, $product1id, $warehouse1id, -2, 1, 0, 'Output from transfer', 'Transfert Y'); |
|
| 187 | + print __METHOD__." result=".$result."\n"; |
|
| 188 | + $this->assertLessThan($result, 0); |
|
| 189 | + |
|
| 190 | + |
|
| 191 | + // Do same but into warehouse 2 |
|
| 192 | + |
|
| 193 | + // Create an input movement (type = 3) of price 9.9 -> shoul dupdate PMP to 9.9 |
|
| 194 | + $result=$localobject->_create($user, $product1id, $warehouse2id, 10, 3, 9.9, 'Movement for unit test 1 wh 2', 'Inventory Code Test 2'); |
|
| 195 | + print __METHOD__." result=".$result."\n"; |
|
| 196 | + $this->assertLessThan($result, 0); |
|
| 197 | + |
|
| 198 | + // Create an input movement (type = 3) of price 9.7 -> shoul dupdate PMP to 9.9/9.7 = 9.8 |
|
| 199 | + $result=$localobject->_create($user, $product1id, $warehouse2id, 10, 3, 9.7, 'Movement for unit test 2 wh 2', 'Inventory Code Test 2'); |
|
| 200 | + print __METHOD__." result=".$result."\n"; |
|
| 201 | + $this->assertLessThan($result, 0); |
|
| 202 | + |
|
| 203 | + // Create an output movement (type = 2) of price 9.7 -> shoul dupdate PMP to 9.9/9.7 = 9.8 |
|
| 204 | + $result=$localobject->_create($user, $product1id, $warehouse2id, -5, 2, 999, 'Movement for unit test 3 wh 2', 'Inventory Code Test 2'); |
|
| 205 | + print __METHOD__." result=".$result."\n"; |
|
| 206 | + $this->assertLessThan($result, 0); |
|
| 207 | + |
|
| 208 | + // Create an output movement (type = 1) of price 9.7 -> shoul dupdate PMP to 9.9/9.7 = 9.8 |
|
| 209 | + $result=$localobject->_create($user, $product1id, $warehouse2id, 1, 0, 0, 'Input from transfer wh 2', 'Transfert X 2'); |
|
| 210 | + print __METHOD__." result=".$result."\n"; |
|
| 211 | + $this->assertLessThan($result, 0); |
|
| 212 | + |
|
| 213 | + // Create an output movement (type = 1) of price 9.7 -> shoul dupdate PMP to 9.9/9.7 = 9.8 |
|
| 214 | + $result=$localobject->_create($user, $product1id, $warehouse2id, -2, 1, 0, 'Output from transfer wh 2', 'Transfert Y 2'); |
|
| 215 | + print __METHOD__." result=".$result."\n"; |
|
| 216 | + $this->assertLessThan($result, 0); |
|
| 217 | + |
|
| 218 | + |
|
| 219 | + return $localobject; |
|
| 220 | 220 | } |
| 221 | 221 | |
| 222 | 222 | /** |
@@ -230,26 +230,26 @@ discard block |
||
| 230 | 230 | */ |
| 231 | 231 | public function testMouvementCheck($localobject) |
| 232 | 232 | { |
| 233 | - global $conf,$user,$langs,$db; |
|
| 234 | - $conf=$this->savconf; |
|
| 235 | - $user=$this->savuser; |
|
| 236 | - $langs=$this->savlangs; |
|
| 237 | - $db=$this->savdb; |
|
| 233 | + global $conf,$user,$langs,$db; |
|
| 234 | + $conf=$this->savconf; |
|
| 235 | + $user=$this->savuser; |
|
| 236 | + $langs=$this->savlangs; |
|
| 237 | + $db=$this->savdb; |
|
| 238 | 238 | |
| 239 | - $productid = $localobject->product_id; |
|
| 240 | - $warehouseid = $localobject->entrepot_id; |
|
| 239 | + $productid = $localobject->product_id; |
|
| 240 | + $warehouseid = $localobject->entrepot_id; |
|
| 241 | 241 | |
| 242 | - print __METHOD__." productid=".$productid."\n"; |
|
| 242 | + print __METHOD__." productid=".$productid."\n"; |
|
| 243 | 243 | |
| 244 | - $producttotest = new Product($db); |
|
| 245 | - $producttotest->fetch($productid); |
|
| 244 | + $producttotest = new Product($db); |
|
| 245 | + $producttotest->fetch($productid); |
|
| 246 | 246 | |
| 247 | - print __METHOD__." producttotest->stock_reel=".$producttotest->stock_reel."\n"; |
|
| 248 | - $this->assertEquals($producttotest->stock_reel, 28); // 28 is result of stock movement defined into testMouvementCreate |
|
| 247 | + print __METHOD__." producttotest->stock_reel=".$producttotest->stock_reel."\n"; |
|
| 248 | + $this->assertEquals($producttotest->stock_reel, 28); // 28 is result of stock movement defined into testMouvementCreate |
|
| 249 | 249 | |
| 250 | - print __METHOD__." producttotest->pmp=".$producttotest->pmp."\n"; |
|
| 251 | - $this->assertEquals($producttotest->pmp, 9.8); |
|
| 250 | + print __METHOD__." producttotest->pmp=".$producttotest->pmp."\n"; |
|
| 251 | + $this->assertEquals($producttotest->pmp, 9.8); |
|
| 252 | 252 | |
| 253 | - return $localobject; |
|
| 253 | + return $localobject; |
|
| 254 | 254 | } |
| 255 | 255 | } |
@@ -23,7 +23,7 @@ discard block |
||
| 23 | 23 | * \remarks To run this script as CLI: phpunit filename.php |
| 24 | 24 | */ |
| 25 | 25 | |
| 26 | -global $conf,$user,$langs,$db; |
|
| 26 | +global $conf, $user, $langs, $db; |
|
| 27 | 27 | //define('TEST_DB_FORCE_TYPE','mysql'); // This is to force using mysql driver |
| 28 | 28 | //require_once 'PHPUnit/Autoload.php'; |
| 29 | 29 | require_once dirname(__FILE__).'/../../htdocs/master.inc.php'; |
@@ -37,7 +37,7 @@ discard block |
||
| 37 | 37 | $user->fetch(1); |
| 38 | 38 | $user->getrights(); |
| 39 | 39 | } |
| 40 | -$conf->global->MAIN_DISABLE_ALL_MAILS=1; |
|
| 40 | +$conf->global->MAIN_DISABLE_ALL_MAILS = 1; |
|
| 41 | 41 | |
| 42 | 42 | |
| 43 | 43 | /** |
@@ -65,11 +65,11 @@ discard block |
||
| 65 | 65 | parent::__construct(); |
| 66 | 66 | |
| 67 | 67 | //$this->sharedFixture |
| 68 | - global $conf,$user,$langs,$db; |
|
| 69 | - $this->savconf=$conf; |
|
| 70 | - $this->savuser=$user; |
|
| 71 | - $this->savlangs=$langs; |
|
| 72 | - $this->savdb=$db; |
|
| 68 | + global $conf, $user, $langs, $db; |
|
| 69 | + $this->savconf = $conf; |
|
| 70 | + $this->savuser = $user; |
|
| 71 | + $this->savlangs = $langs; |
|
| 72 | + $this->savdb = $db; |
|
| 73 | 73 | |
| 74 | 74 | print __METHOD__." db->type=".$db->type." user->id=".$user->id; |
| 75 | 75 | //print " - db ".$db->db; |
@@ -79,8 +79,8 @@ discard block |
||
| 79 | 79 | // Static methods |
| 80 | 80 | public static function setUpBeforeClass() |
| 81 | 81 | { |
| 82 | - global $conf,$user,$langs,$db; |
|
| 83 | - $db->begin(); // This is to have all actions inside a transaction even if test launched without suite. |
|
| 82 | + global $conf, $user, $langs, $db; |
|
| 83 | + $db->begin(); // This is to have all actions inside a transaction even if test launched without suite. |
|
| 84 | 84 | |
| 85 | 85 | print __METHOD__."\n"; |
| 86 | 86 | } |
@@ -88,7 +88,7 @@ discard block |
||
| 88 | 88 | // tear down after class |
| 89 | 89 | public static function tearDownAfterClass() |
| 90 | 90 | { |
| 91 | - global $conf,$user,$langs,$db; |
|
| 91 | + global $conf, $user, $langs, $db; |
|
| 92 | 92 | $db->rollback(); |
| 93 | 93 | |
| 94 | 94 | print __METHOD__."\n"; |
@@ -101,11 +101,11 @@ discard block |
||
| 101 | 101 | */ |
| 102 | 102 | protected function setUp() |
| 103 | 103 | { |
| 104 | - global $conf,$user,$langs,$db; |
|
| 105 | - $conf=$this->savconf; |
|
| 106 | - $user=$this->savuser; |
|
| 107 | - $langs=$this->savlangs; |
|
| 108 | - $db=$this->savdb; |
|
| 104 | + global $conf, $user, $langs, $db; |
|
| 105 | + $conf = $this->savconf; |
|
| 106 | + $user = $this->savuser; |
|
| 107 | + $langs = $this->savlangs; |
|
| 108 | + $db = $this->savdb; |
|
| 109 | 109 | |
| 110 | 110 | print __METHOD__."\n"; |
| 111 | 111 | } |
@@ -126,64 +126,64 @@ discard block |
||
| 126 | 126 | */ |
| 127 | 127 | public function testMouvementCreate() |
| 128 | 128 | { |
| 129 | - global $conf,$user,$langs,$db; |
|
| 130 | - $conf=$this->savconf; |
|
| 131 | - $user=$this->savuser; |
|
| 132 | - $langs=$this->savlangs; |
|
| 133 | - $db=$this->savdb; |
|
| 129 | + global $conf, $user, $langs, $db; |
|
| 130 | + $conf = $this->savconf; |
|
| 131 | + $user = $this->savuser; |
|
| 132 | + $langs = $this->savlangs; |
|
| 133 | + $db = $this->savdb; |
|
| 134 | 134 | |
| 135 | 135 | // We create a product for tests |
| 136 | - $product1=new Product($db); |
|
| 136 | + $product1 = new Product($db); |
|
| 137 | 137 | $product1->initAsSpecimen(); |
| 138 | - $product1->ref.=' 1'; |
|
| 139 | - $product1->label.=' 1'; |
|
| 140 | - $product1id=$product1->create($user); |
|
| 138 | + $product1->ref .= ' 1'; |
|
| 139 | + $product1->label .= ' 1'; |
|
| 140 | + $product1id = $product1->create($user); |
|
| 141 | 141 | |
| 142 | - $product2=new Product($db); |
|
| 142 | + $product2 = new Product($db); |
|
| 143 | 143 | $product2->initAsSpecimen(); |
| 144 | - $product2->ref.=' 2'; |
|
| 145 | - $product2->label.=' 2'; |
|
| 146 | - $product2id=$product2->create($user); |
|
| 144 | + $product2->ref .= ' 2'; |
|
| 145 | + $product2->label .= ' 2'; |
|
| 146 | + $product2id = $product2->create($user); |
|
| 147 | 147 | |
| 148 | 148 | // We create a product for tests |
| 149 | - $warehouse1=new Entrepot($db); |
|
| 149 | + $warehouse1 = new Entrepot($db); |
|
| 150 | 150 | $warehouse1->initAsSpecimen(); |
| 151 | - $warehouse1->libelle.=' 1'; |
|
| 152 | - $warehouse1->description.=' 1'; |
|
| 153 | - $warehouse1id=$warehouse1->create($user); |
|
| 151 | + $warehouse1->libelle .= ' 1'; |
|
| 152 | + $warehouse1->description .= ' 1'; |
|
| 153 | + $warehouse1id = $warehouse1->create($user); |
|
| 154 | 154 | |
| 155 | - $warehouse2=new Entrepot($db); |
|
| 155 | + $warehouse2 = new Entrepot($db); |
|
| 156 | 156 | $warehouse2->initAsSpecimen(); |
| 157 | - $warehouse2->libelle.=' 2'; |
|
| 158 | - $warehouse2->description.=' 2'; |
|
| 159 | - $warehouse2id=$warehouse2->create($user); |
|
| 157 | + $warehouse2->libelle .= ' 2'; |
|
| 158 | + $warehouse2->description .= ' 2'; |
|
| 159 | + $warehouse2id = $warehouse2->create($user); |
|
| 160 | 160 | |
| 161 | - $localobject=new MouvementStock($this->savdb); |
|
| 161 | + $localobject = new MouvementStock($this->savdb); |
|
| 162 | 162 | |
| 163 | 163 | // Do a list of movement into warehouse 1 |
| 164 | 164 | |
| 165 | 165 | // Create an input movement (type = 3) of price 9.9 -> shoul dupdate PMP to 9.9 |
| 166 | - $result=$localobject->_create($user, $product1id, $warehouse1id, 10, 3, 9.9, 'Movement for unit test 1', 'Inventory Code Test'); |
|
| 166 | + $result = $localobject->_create($user, $product1id, $warehouse1id, 10, 3, 9.9, 'Movement for unit test 1', 'Inventory Code Test'); |
|
| 167 | 167 | print __METHOD__." result=".$result."\n"; |
| 168 | 168 | $this->assertLessThan($result, 0); |
| 169 | 169 | |
| 170 | 170 | // Create an input movement (type = 3) of price 9.7 -> shoul dupdate PMP to 9.9/9.7 = 9.8 |
| 171 | - $result=$localobject->_create($user, $product1id, $warehouse1id, 10, 3, 9.7, 'Movement for unit test 2', 'Inventory Code Test'); |
|
| 171 | + $result = $localobject->_create($user, $product1id, $warehouse1id, 10, 3, 9.7, 'Movement for unit test 2', 'Inventory Code Test'); |
|
| 172 | 172 | print __METHOD__." result=".$result."\n"; |
| 173 | 173 | $this->assertLessThan($result, 0); |
| 174 | 174 | |
| 175 | 175 | // Create an output movement (type = 2) of price 9.7 -> shoul dupdate PMP to 9.9/9.7 = 9.8 |
| 176 | - $result=$localobject->_create($user, $product1id, $warehouse1id, -5, 2, 999, 'Movement for unit test 3', 'Inventory Code Test'); |
|
| 176 | + $result = $localobject->_create($user, $product1id, $warehouse1id, -5, 2, 999, 'Movement for unit test 3', 'Inventory Code Test'); |
|
| 177 | 177 | print __METHOD__." result=".$result."\n"; |
| 178 | 178 | $this->assertLessThan($result, 0); |
| 179 | 179 | |
| 180 | 180 | // Create an output movement (type = 1) of price 9.7 -> shoul dupdate PMP to 9.9/9.7 = 9.8 |
| 181 | - $result=$localobject->_create($user, $product1id, $warehouse1id, 1, 0, 0, 'Input from transfer', 'Transfert X'); |
|
| 181 | + $result = $localobject->_create($user, $product1id, $warehouse1id, 1, 0, 0, 'Input from transfer', 'Transfert X'); |
|
| 182 | 182 | print __METHOD__." result=".$result."\n"; |
| 183 | 183 | $this->assertLessThan($result, 0); |
| 184 | 184 | |
| 185 | 185 | // Create an output movement (type = 1) of price 9.7 -> shoul dupdate PMP to 9.9/9.7 = 9.8 |
| 186 | - $result=$localobject->_create($user, $product1id, $warehouse1id, -2, 1, 0, 'Output from transfer', 'Transfert Y'); |
|
| 186 | + $result = $localobject->_create($user, $product1id, $warehouse1id, -2, 1, 0, 'Output from transfer', 'Transfert Y'); |
|
| 187 | 187 | print __METHOD__." result=".$result."\n"; |
| 188 | 188 | $this->assertLessThan($result, 0); |
| 189 | 189 | |
@@ -191,27 +191,27 @@ discard block |
||
| 191 | 191 | // Do same but into warehouse 2 |
| 192 | 192 | |
| 193 | 193 | // Create an input movement (type = 3) of price 9.9 -> shoul dupdate PMP to 9.9 |
| 194 | - $result=$localobject->_create($user, $product1id, $warehouse2id, 10, 3, 9.9, 'Movement for unit test 1 wh 2', 'Inventory Code Test 2'); |
|
| 194 | + $result = $localobject->_create($user, $product1id, $warehouse2id, 10, 3, 9.9, 'Movement for unit test 1 wh 2', 'Inventory Code Test 2'); |
|
| 195 | 195 | print __METHOD__." result=".$result."\n"; |
| 196 | 196 | $this->assertLessThan($result, 0); |
| 197 | 197 | |
| 198 | 198 | // Create an input movement (type = 3) of price 9.7 -> shoul dupdate PMP to 9.9/9.7 = 9.8 |
| 199 | - $result=$localobject->_create($user, $product1id, $warehouse2id, 10, 3, 9.7, 'Movement for unit test 2 wh 2', 'Inventory Code Test 2'); |
|
| 199 | + $result = $localobject->_create($user, $product1id, $warehouse2id, 10, 3, 9.7, 'Movement for unit test 2 wh 2', 'Inventory Code Test 2'); |
|
| 200 | 200 | print __METHOD__." result=".$result."\n"; |
| 201 | 201 | $this->assertLessThan($result, 0); |
| 202 | 202 | |
| 203 | 203 | // Create an output movement (type = 2) of price 9.7 -> shoul dupdate PMP to 9.9/9.7 = 9.8 |
| 204 | - $result=$localobject->_create($user, $product1id, $warehouse2id, -5, 2, 999, 'Movement for unit test 3 wh 2', 'Inventory Code Test 2'); |
|
| 204 | + $result = $localobject->_create($user, $product1id, $warehouse2id, -5, 2, 999, 'Movement for unit test 3 wh 2', 'Inventory Code Test 2'); |
|
| 205 | 205 | print __METHOD__." result=".$result."\n"; |
| 206 | 206 | $this->assertLessThan($result, 0); |
| 207 | 207 | |
| 208 | 208 | // Create an output movement (type = 1) of price 9.7 -> shoul dupdate PMP to 9.9/9.7 = 9.8 |
| 209 | - $result=$localobject->_create($user, $product1id, $warehouse2id, 1, 0, 0, 'Input from transfer wh 2', 'Transfert X 2'); |
|
| 209 | + $result = $localobject->_create($user, $product1id, $warehouse2id, 1, 0, 0, 'Input from transfer wh 2', 'Transfert X 2'); |
|
| 210 | 210 | print __METHOD__." result=".$result."\n"; |
| 211 | 211 | $this->assertLessThan($result, 0); |
| 212 | 212 | |
| 213 | 213 | // Create an output movement (type = 1) of price 9.7 -> shoul dupdate PMP to 9.9/9.7 = 9.8 |
| 214 | - $result=$localobject->_create($user, $product1id, $warehouse2id, -2, 1, 0, 'Output from transfer wh 2', 'Transfert Y 2'); |
|
| 214 | + $result = $localobject->_create($user, $product1id, $warehouse2id, -2, 1, 0, 'Output from transfer wh 2', 'Transfert Y 2'); |
|
| 215 | 215 | print __METHOD__." result=".$result."\n"; |
| 216 | 216 | $this->assertLessThan($result, 0); |
| 217 | 217 | |
@@ -230,11 +230,11 @@ discard block |
||
| 230 | 230 | */ |
| 231 | 231 | public function testMouvementCheck($localobject) |
| 232 | 232 | { |
| 233 | - global $conf,$user,$langs,$db; |
|
| 234 | - $conf=$this->savconf; |
|
| 235 | - $user=$this->savuser; |
|
| 236 | - $langs=$this->savlangs; |
|
| 237 | - $db=$this->savdb; |
|
| 233 | + global $conf, $user, $langs, $db; |
|
| 234 | + $conf = $this->savconf; |
|
| 235 | + $user = $this->savuser; |
|
| 236 | + $langs = $this->savlangs; |
|
| 237 | + $db = $this->savdb; |
|
| 238 | 238 | |
| 239 | 239 | $productid = $localobject->product_id; |
| 240 | 240 | $warehouseid = $localobject->entrepot_id; |
@@ -245,7 +245,7 @@ discard block |
||
| 245 | 245 | $producttotest->fetch($productid); |
| 246 | 246 | |
| 247 | 247 | print __METHOD__." producttotest->stock_reel=".$producttotest->stock_reel."\n"; |
| 248 | - $this->assertEquals($producttotest->stock_reel, 28); // 28 is result of stock movement defined into testMouvementCreate |
|
| 248 | + $this->assertEquals($producttotest->stock_reel, 28); // 28 is result of stock movement defined into testMouvementCreate |
|
| 249 | 249 | |
| 250 | 250 | print __METHOD__." producttotest->pmp=".$producttotest->pmp."\n"; |
| 251 | 251 | $this->assertEquals($producttotest->pmp, 9.8); |
@@ -59,9 +59,9 @@ discard block |
||
| 59 | 59 | */ |
| 60 | 60 | function __construct() |
| 61 | 61 | { |
| 62 | - parent::__construct(); |
|
| 62 | + parent::__construct(); |
|
| 63 | 63 | |
| 64 | - //$this->sharedFixture |
|
| 64 | + //$this->sharedFixture |
|
| 65 | 65 | global $conf,$user,$langs,$db; |
| 66 | 66 | $this->savconf=$conf; |
| 67 | 67 | $this->savuser=$user; |
@@ -205,18 +205,18 @@ discard block |
||
| 205 | 205 | */ |
| 206 | 206 | public function testActionCommUpdate($localobject) |
| 207 | 207 | { |
| 208 | - global $conf,$user,$langs,$db; |
|
| 209 | - $conf=$this->savconf; |
|
| 210 | - $user=$this->savuser; |
|
| 211 | - $langs=$this->savlangs; |
|
| 212 | - $db=$this->savdb; |
|
| 213 | - |
|
| 214 | - $localobject->label='New label'; |
|
| 215 | - $result=$localobject->update($user); |
|
| 216 | - |
|
| 217 | - $this->assertLessThan($result, 0); |
|
| 218 | - print __METHOD__." id=".$id." result=".$result."\n"; |
|
| 219 | - return $localobject->id; |
|
| 208 | + global $conf,$user,$langs,$db; |
|
| 209 | + $conf=$this->savconf; |
|
| 210 | + $user=$this->savuser; |
|
| 211 | + $langs=$this->savlangs; |
|
| 212 | + $db=$this->savdb; |
|
| 213 | + |
|
| 214 | + $localobject->label='New label'; |
|
| 215 | + $result=$localobject->update($user); |
|
| 216 | + |
|
| 217 | + $this->assertLessThan($result, 0); |
|
| 218 | + print __METHOD__." id=".$id." result=".$result."\n"; |
|
| 219 | + return $localobject->id; |
|
| 220 | 220 | } |
| 221 | 221 | |
| 222 | 222 | /** |
@@ -23,7 +23,7 @@ discard block |
||
| 23 | 23 | * \remarks To run this script as CLI: phpunit filename.php |
| 24 | 24 | */ |
| 25 | 25 | |
| 26 | -global $conf,$user,$langs,$db; |
|
| 26 | +global $conf, $user, $langs, $db; |
|
| 27 | 27 | //define('TEST_DB_FORCE_TYPE','mysql'); // This is to force using mysql driver |
| 28 | 28 | //require_once 'PHPUnit/Autoload.php'; |
| 29 | 29 | require_once dirname(__FILE__).'/../../htdocs/master.inc.php'; |
@@ -34,7 +34,7 @@ discard block |
||
| 34 | 34 | $user->fetch(1); |
| 35 | 35 | $user->getrights(); |
| 36 | 36 | } |
| 37 | -$conf->global->MAIN_DISABLE_ALL_MAILS=1; |
|
| 37 | +$conf->global->MAIN_DISABLE_ALL_MAILS = 1; |
|
| 38 | 38 | |
| 39 | 39 | |
| 40 | 40 | /** |
@@ -62,11 +62,11 @@ discard block |
||
| 62 | 62 | parent::__construct(); |
| 63 | 63 | |
| 64 | 64 | //$this->sharedFixture |
| 65 | - global $conf,$user,$langs,$db; |
|
| 66 | - $this->savconf=$conf; |
|
| 67 | - $this->savuser=$user; |
|
| 68 | - $this->savlangs=$langs; |
|
| 69 | - $this->savdb=$db; |
|
| 65 | + global $conf, $user, $langs, $db; |
|
| 66 | + $this->savconf = $conf; |
|
| 67 | + $this->savuser = $user; |
|
| 68 | + $this->savlangs = $langs; |
|
| 69 | + $this->savdb = $db; |
|
| 70 | 70 | |
| 71 | 71 | print __METHOD__." db->type=".$db->type." user->id=".$user->id; |
| 72 | 72 | //print " - db ".$db->db; |
@@ -76,7 +76,7 @@ discard block |
||
| 76 | 76 | // Static methods |
| 77 | 77 | public static function setUpBeforeClass() |
| 78 | 78 | { |
| 79 | - global $conf,$user,$langs,$db; |
|
| 79 | + global $conf, $user, $langs, $db; |
|
| 80 | 80 | $db->begin(); // This is to have all actions inside a transaction even if test launched without suite. |
| 81 | 81 | |
| 82 | 82 | if (empty($conf->agenda->enabled)) { print __METHOD__." module agenda must be enabled.\n"; die(); } |
@@ -87,7 +87,7 @@ discard block |
||
| 87 | 87 | // tear down after class |
| 88 | 88 | public static function tearDownAfterClass() |
| 89 | 89 | { |
| 90 | - global $conf,$user,$langs,$db; |
|
| 90 | + global $conf, $user, $langs, $db; |
|
| 91 | 91 | $db->rollback(); |
| 92 | 92 | |
| 93 | 93 | print __METHOD__."\n"; |
@@ -100,11 +100,11 @@ discard block |
||
| 100 | 100 | */ |
| 101 | 101 | protected function setUp() |
| 102 | 102 | { |
| 103 | - global $conf,$user,$langs,$db; |
|
| 104 | - $conf=$this->savconf; |
|
| 105 | - $user=$this->savuser; |
|
| 106 | - $langs=$this->savlangs; |
|
| 107 | - $db=$this->savdb; |
|
| 103 | + global $conf, $user, $langs, $db; |
|
| 104 | + $conf = $this->savconf; |
|
| 105 | + $user = $this->savuser; |
|
| 106 | + $langs = $this->savlangs; |
|
| 107 | + $db = $this->savdb; |
|
| 108 | 108 | |
| 109 | 109 | print __METHOD__."\n"; |
| 110 | 110 | //print $db->getVersion()."\n"; |
@@ -127,28 +127,28 @@ discard block |
||
| 127 | 127 | */ |
| 128 | 128 | public function testActionCommCreate() |
| 129 | 129 | { |
| 130 | - global $conf,$user,$langs,$db; |
|
| 131 | - $conf=$this->savconf; |
|
| 132 | - $user=$this->savuser; |
|
| 133 | - $langs=$this->savlangs; |
|
| 134 | - $db=$this->savdb; |
|
| 130 | + global $conf, $user, $langs, $db; |
|
| 131 | + $conf = $this->savconf; |
|
| 132 | + $user = $this->savuser; |
|
| 133 | + $langs = $this->savlangs; |
|
| 134 | + $db = $this->savdb; |
|
| 135 | 135 | |
| 136 | 136 | $now = dol_now(); |
| 137 | 137 | |
| 138 | - $localobject=new ActionComm($this->savdb); |
|
| 138 | + $localobject = new ActionComm($this->savdb); |
|
| 139 | 139 | |
| 140 | - $localobject->type_code = 'AC_OTH_AUTO'; // Type of event ('AC_OTH', 'AC_OTH_AUTO', 'AC_XXX'...) |
|
| 140 | + $localobject->type_code = 'AC_OTH_AUTO'; // Type of event ('AC_OTH', 'AC_OTH_AUTO', 'AC_XXX'...) |
|
| 141 | 141 | $localobject->code = 'AC_PHPUNITTEST'; |
| 142 | 142 | $localobject->label = 'This is a description'; |
| 143 | 143 | $localobject->note = 'This is note'; |
| 144 | 144 | $localobject->fk_project = 0; |
| 145 | 145 | $localobject->datep = $now; |
| 146 | 146 | $localobject->datef = $now; |
| 147 | - $localobject->percentage = -1; // Not applicable |
|
| 147 | + $localobject->percentage = -1; // Not applicable |
|
| 148 | 148 | $localobject->socid = 0; |
| 149 | 149 | $localobject->contactid = 0; |
| 150 | - $localobject->authorid = $user->id; // User saving action |
|
| 151 | - $localobject->userownerid = $user->id; // Owner of action |
|
| 150 | + $localobject->authorid = $user->id; // User saving action |
|
| 151 | + $localobject->userownerid = $user->id; // Owner of action |
|
| 152 | 152 | // Fields when action is en email (content should be added into note) |
| 153 | 153 | /*$localobject->email_msgid = $object->email_msgid; |
| 154 | 154 | $localobject->email_from = $object->email_from; |
@@ -180,14 +180,14 @@ discard block |
||
| 180 | 180 | */ |
| 181 | 181 | public function testActionCommFetch($id) |
| 182 | 182 | { |
| 183 | - global $conf,$user,$langs,$db; |
|
| 184 | - $conf=$this->savconf; |
|
| 185 | - $user=$this->savuser; |
|
| 186 | - $langs=$this->savlangs; |
|
| 187 | - $db=$this->savdb; |
|
| 183 | + global $conf, $user, $langs, $db; |
|
| 184 | + $conf = $this->savconf; |
|
| 185 | + $user = $this->savuser; |
|
| 186 | + $langs = $this->savlangs; |
|
| 187 | + $db = $this->savdb; |
|
| 188 | 188 | |
| 189 | - $localobject=new ActionComm($this->savdb); |
|
| 190 | - $result=$localobject->fetch($id); |
|
| 189 | + $localobject = new ActionComm($this->savdb); |
|
| 190 | + $result = $localobject->fetch($id); |
|
| 191 | 191 | |
| 192 | 192 | $this->assertLessThan($result, 0); |
| 193 | 193 | print __METHOD__." id=".$id." result=".$result."\n"; |
@@ -205,14 +205,14 @@ discard block |
||
| 205 | 205 | */ |
| 206 | 206 | public function testActionCommUpdate($localobject) |
| 207 | 207 | { |
| 208 | - global $conf,$user,$langs,$db; |
|
| 209 | - $conf=$this->savconf; |
|
| 210 | - $user=$this->savuser; |
|
| 211 | - $langs=$this->savlangs; |
|
| 212 | - $db=$this->savdb; |
|
| 208 | + global $conf, $user, $langs, $db; |
|
| 209 | + $conf = $this->savconf; |
|
| 210 | + $user = $this->savuser; |
|
| 211 | + $langs = $this->savlangs; |
|
| 212 | + $db = $this->savdb; |
|
| 213 | 213 | |
| 214 | - $localobject->label='New label'; |
|
| 215 | - $result=$localobject->update($user); |
|
| 214 | + $localobject->label = 'New label'; |
|
| 215 | + $result = $localobject->update($user); |
|
| 216 | 216 | |
| 217 | 217 | $this->assertLessThan($result, 0); |
| 218 | 218 | print __METHOD__." id=".$id." result=".$result."\n"; |
@@ -230,15 +230,15 @@ discard block |
||
| 230 | 230 | */ |
| 231 | 231 | public function testActionCommDelete($id) |
| 232 | 232 | { |
| 233 | - global $conf,$user,$langs,$db; |
|
| 234 | - $conf=$this->savconf; |
|
| 235 | - $user=$this->savuser; |
|
| 236 | - $langs=$this->savlangs; |
|
| 237 | - $db=$this->savdb; |
|
| 238 | - |
|
| 239 | - $localobject=new ActionComm($this->savdb); |
|
| 240 | - $result=$localobject->fetch($id); |
|
| 241 | - $result=$localobject->delete($user); |
|
| 233 | + global $conf, $user, $langs, $db; |
|
| 234 | + $conf = $this->savconf; |
|
| 235 | + $user = $this->savuser; |
|
| 236 | + $langs = $this->savlangs; |
|
| 237 | + $db = $this->savdb; |
|
| 238 | + |
|
| 239 | + $localobject = new ActionComm($this->savdb); |
|
| 240 | + $result = $localobject->fetch($id); |
|
| 241 | + $result = $localobject->delete($user); |
|
| 242 | 242 | |
| 243 | 243 | print __METHOD__." id=".$id." result=".$result."\n"; |
| 244 | 244 | $this->assertLessThan($result, 0); |