@@ -94,12 +94,12 @@ discard block |
||
| 94 | 94 | /** |
| 95 | 95 | * @var string Error code (or message) |
| 96 | 96 | */ |
| 97 | - public $error=''; |
|
| 97 | + public $error = ''; |
|
| 98 | 98 | |
| 99 | 99 | var $errno; |
| 100 | 100 | |
| 101 | 101 | |
| 102 | - public static $type2label=array( |
|
| 102 | + public static $type2label = array( |
|
| 103 | 103 | 'varchar'=>'String', |
| 104 | 104 | 'text'=>'TextLong', |
| 105 | 105 | 'html'=>'HtmlText', |
@@ -171,29 +171,29 @@ discard block |
||
| 171 | 171 | * @param string $enabled Condition to have the field enabled or not |
| 172 | 172 | * @return int <=0 if KO, >0 if OK |
| 173 | 173 | */ |
| 174 | - function addExtraField($attrname, $label, $type, $pos, $size, $elementtype, $unique=0, $required=0, $default_value='', $param='', $alwayseditable=0, $perms='', $list='-1', $help='', $computed='', $entity='', $langfile='', $enabled='1') |
|
| 174 | + function addExtraField($attrname, $label, $type, $pos, $size, $elementtype, $unique = 0, $required = 0, $default_value = '', $param = '', $alwayseditable = 0, $perms = '', $list = '-1', $help = '', $computed = '', $entity = '', $langfile = '', $enabled = '1') |
|
| 175 | 175 | { |
| 176 | 176 | if (empty($attrname)) return -1; |
| 177 | 177 | if (empty($label)) return -1; |
| 178 | 178 | |
| 179 | - if ($elementtype == 'thirdparty') $elementtype='societe'; |
|
| 180 | - if ($elementtype == 'contact') $elementtype='socpeople'; |
|
| 179 | + if ($elementtype == 'thirdparty') $elementtype = 'societe'; |
|
| 180 | + if ($elementtype == 'contact') $elementtype = 'socpeople'; |
|
| 181 | 181 | |
| 182 | 182 | // Create field into database except for separator type which is not stored in database |
| 183 | 183 | if ($type != 'separate') |
| 184 | 184 | { |
| 185 | - $result=$this->create($attrname, $type, $size, $elementtype, $unique, $required, $default_value, $param, $perms, $list, $computed, $help); |
|
| 185 | + $result = $this->create($attrname, $type, $size, $elementtype, $unique, $required, $default_value, $param, $perms, $list, $computed, $help); |
|
| 186 | 186 | } |
| 187 | - $err1=$this->errno; |
|
| 187 | + $err1 = $this->errno; |
|
| 188 | 188 | if ($result > 0 || $err1 == 'DB_ERROR_COLUMN_ALREADY_EXISTS' || $type == 'separate') |
| 189 | 189 | { |
| 190 | 190 | // Add declaration of field into table |
| 191 | - $result2=$this->create_label($attrname, $label, $type, $pos, $size, $elementtype, $unique, $required, $param, $alwayseditable, $perms, $list, $help, $default_value, $computed, $entity, $langfile, $enabled); |
|
| 192 | - $err2=$this->errno; |
|
| 191 | + $result2 = $this->create_label($attrname, $label, $type, $pos, $size, $elementtype, $unique, $required, $param, $alwayseditable, $perms, $list, $help, $default_value, $computed, $entity, $langfile, $enabled); |
|
| 192 | + $err2 = $this->errno; |
|
| 193 | 193 | if ($result2 > 0 || ($err1 == 'DB_ERROR_COLUMN_ALREADY_EXISTS' && $err2 == 'DB_ERROR_RECORD_ALREADY_EXISTS')) |
| 194 | 194 | { |
| 195 | - $this->error=''; |
|
| 196 | - $this->errno=0; |
|
| 195 | + $this->error = ''; |
|
| 196 | + $this->errno = 0; |
|
| 197 | 197 | return 1; |
| 198 | 198 | } |
| 199 | 199 | else return -2; |
@@ -221,69 +221,69 @@ discard block |
||
| 221 | 221 | * @param string $computed Computed value |
| 222 | 222 | * @return int <=0 if KO, >0 if OK |
| 223 | 223 | */ |
| 224 | - private function create($attrname, $type='varchar', $length=255, $elementtype='member', $unique=0, $required=0, $default_value='',$param='', $perms='', $list='0', $computed='') |
|
| 224 | + private function create($attrname, $type = 'varchar', $length = 255, $elementtype = 'member', $unique = 0, $required = 0, $default_value = '', $param = '', $perms = '', $list = '0', $computed = '') |
|
| 225 | 225 | { |
| 226 | - if ($elementtype == 'thirdparty') $elementtype='societe'; |
|
| 227 | - if ($elementtype == 'contact') $elementtype='socpeople'; |
|
| 228 | - |
|
| 229 | - $table=$elementtype.'_extrafields'; |
|
| 230 | - if ($elementtype == 'categorie') $table='categories_extrafields'; |
|
| 231 | - |
|
| 232 | - if (! empty($attrname) && preg_match("/^\w[a-zA-Z0-9_]*$/",$attrname) && ! is_numeric($attrname)) |
|
| 233 | - { |
|
| 234 | - if ($type=='boolean') { |
|
| 235 | - $typedb='int'; |
|
| 236 | - $lengthdb='1'; |
|
| 237 | - } elseif($type=='price') { |
|
| 238 | - $typedb='double'; |
|
| 239 | - $lengthdb='24,8'; |
|
| 240 | - } elseif($type=='phone') { |
|
| 241 | - $typedb='varchar'; |
|
| 242 | - $lengthdb='20'; |
|
| 243 | - } elseif($type=='mail') { |
|
| 244 | - $typedb='varchar'; |
|
| 245 | - $lengthdb='128'; |
|
| 246 | - } elseif($type=='url') { |
|
| 247 | - $typedb='varchar'; |
|
| 248 | - $lengthdb='255'; |
|
| 249 | - } elseif (($type=='select') || ($type=='sellist') || ($type=='radio') ||($type=='checkbox') ||($type=='chkbxlst')){ |
|
| 250 | - $typedb='varchar'; |
|
| 251 | - $lengthdb='255'; |
|
| 252 | - } elseif ($type=='link') { |
|
| 253 | - $typedb='int'; |
|
| 254 | - $lengthdb='11'; |
|
| 255 | - } elseif ($type=='html') { |
|
| 256 | - $typedb='text'; |
|
| 257 | - $lengthdb=$length; |
|
| 258 | - } elseif($type=='password') { |
|
| 259 | - $typedb='varchar'; |
|
| 260 | - $lengthdb='128'; |
|
| 226 | + if ($elementtype == 'thirdparty') $elementtype = 'societe'; |
|
| 227 | + if ($elementtype == 'contact') $elementtype = 'socpeople'; |
|
| 228 | + |
|
| 229 | + $table = $elementtype.'_extrafields'; |
|
| 230 | + if ($elementtype == 'categorie') $table = 'categories_extrafields'; |
|
| 231 | + |
|
| 232 | + if (!empty($attrname) && preg_match("/^\w[a-zA-Z0-9_]*$/", $attrname) && !is_numeric($attrname)) |
|
| 233 | + { |
|
| 234 | + if ($type == 'boolean') { |
|
| 235 | + $typedb = 'int'; |
|
| 236 | + $lengthdb = '1'; |
|
| 237 | + } elseif ($type == 'price') { |
|
| 238 | + $typedb = 'double'; |
|
| 239 | + $lengthdb = '24,8'; |
|
| 240 | + } elseif ($type == 'phone') { |
|
| 241 | + $typedb = 'varchar'; |
|
| 242 | + $lengthdb = '20'; |
|
| 243 | + } elseif ($type == 'mail') { |
|
| 244 | + $typedb = 'varchar'; |
|
| 245 | + $lengthdb = '128'; |
|
| 246 | + } elseif ($type == 'url') { |
|
| 247 | + $typedb = 'varchar'; |
|
| 248 | + $lengthdb = '255'; |
|
| 249 | + } elseif (($type == 'select') || ($type == 'sellist') || ($type == 'radio') || ($type == 'checkbox') || ($type == 'chkbxlst')) { |
|
| 250 | + $typedb = 'varchar'; |
|
| 251 | + $lengthdb = '255'; |
|
| 252 | + } elseif ($type == 'link') { |
|
| 253 | + $typedb = 'int'; |
|
| 254 | + $lengthdb = '11'; |
|
| 255 | + } elseif ($type == 'html') { |
|
| 256 | + $typedb = 'text'; |
|
| 257 | + $lengthdb = $length; |
|
| 258 | + } elseif ($type == 'password') { |
|
| 259 | + $typedb = 'varchar'; |
|
| 260 | + $lengthdb = '128'; |
|
| 261 | 261 | } else { |
| 262 | - $typedb=$type; |
|
| 263 | - $lengthdb=$length; |
|
| 264 | - if ($type == 'varchar' && empty($lengthdb)) $lengthdb='255'; |
|
| 262 | + $typedb = $type; |
|
| 263 | + $lengthdb = $length; |
|
| 264 | + if ($type == 'varchar' && empty($lengthdb)) $lengthdb = '255'; |
|
| 265 | 265 | } |
| 266 | 266 | $field_desc = array( |
| 267 | 267 | 'type'=>$typedb, |
| 268 | 268 | 'value'=>$lengthdb, |
| 269 | - 'null'=>($required?'NOT NULL':'NULL'), |
|
| 269 | + 'null'=>($required ? 'NOT NULL' : 'NULL'), |
|
| 270 | 270 | 'default' => $default_value |
| 271 | 271 | ); |
| 272 | 272 | |
| 273 | - $result=$this->db->DDLAddField(MAIN_DB_PREFIX.$table, $attrname, $field_desc); |
|
| 273 | + $result = $this->db->DDLAddField(MAIN_DB_PREFIX.$table, $attrname, $field_desc); |
|
| 274 | 274 | if ($result > 0) |
| 275 | 275 | { |
| 276 | 276 | if ($unique) |
| 277 | 277 | { |
| 278 | - $sql="ALTER TABLE ".MAIN_DB_PREFIX.$table." ADD UNIQUE INDEX uk_".$table."_".$attrname." (".$attrname.")"; |
|
| 279 | - $resql=$this->db->query($sql,1,'dml'); |
|
| 278 | + $sql = "ALTER TABLE ".MAIN_DB_PREFIX.$table." ADD UNIQUE INDEX uk_".$table."_".$attrname." (".$attrname.")"; |
|
| 279 | + $resql = $this->db->query($sql, 1, 'dml'); |
|
| 280 | 280 | } |
| 281 | 281 | return 1; |
| 282 | 282 | } |
| 283 | 283 | else |
| 284 | 284 | { |
| 285 | - $this->error=$this->db->lasterror(); |
|
| 286 | - $this->errno=$this->db->lasterrno(); |
|
| 285 | + $this->error = $this->db->lasterror(); |
|
| 286 | + $this->errno = $this->db->lasterrno(); |
|
| 287 | 287 | return -1; |
| 288 | 288 | } |
| 289 | 289 | } |
@@ -317,22 +317,22 @@ discard block |
||
| 317 | 317 | * @param string $enabled Condition to have the field enabled or not |
| 318 | 318 | * @return int <=0 if KO, >0 if OK |
| 319 | 319 | */ |
| 320 | - private function create_label($attrname, $label='', $type='', $pos=0, $size=0, $elementtype='member', $unique=0, $required=0, $param='', $alwayseditable=0, $perms='', $list='-1', $help='', $default='', $computed='',$entity='', $langfile='', $enabled='1') |
|
| 320 | + private function create_label($attrname, $label = '', $type = '', $pos = 0, $size = 0, $elementtype = 'member', $unique = 0, $required = 0, $param = '', $alwayseditable = 0, $perms = '', $list = '-1', $help = '', $default = '', $computed = '', $entity = '', $langfile = '', $enabled = '1') |
|
| 321 | 321 | { |
| 322 | 322 | // phpcs:enable |
| 323 | - global $conf,$user; |
|
| 323 | + global $conf, $user; |
|
| 324 | 324 | |
| 325 | - if ($elementtype == 'thirdparty') $elementtype='societe'; |
|
| 326 | - if ($elementtype == 'contact') $elementtype='socpeople'; |
|
| 325 | + if ($elementtype == 'thirdparty') $elementtype = 'societe'; |
|
| 326 | + if ($elementtype == 'contact') $elementtype = 'socpeople'; |
|
| 327 | 327 | |
| 328 | 328 | // Clean parameters |
| 329 | - if (empty($pos)) $pos=0; |
|
| 330 | - if (empty($list)) $list='0'; |
|
| 331 | - if (empty($required)) $required=0; |
|
| 332 | - if (empty($unique)) $unique=0; |
|
| 333 | - if (empty($alwayseditable)) $alwayseditable=0; |
|
| 329 | + if (empty($pos)) $pos = 0; |
|
| 330 | + if (empty($list)) $list = '0'; |
|
| 331 | + if (empty($required)) $required = 0; |
|
| 332 | + if (empty($unique)) $unique = 0; |
|
| 333 | + if (empty($alwayseditable)) $alwayseditable = 0; |
|
| 334 | 334 | |
| 335 | - if (! empty($attrname) && preg_match("/^\w[a-zA-Z0-9-_]*$/",$attrname) && ! is_numeric($attrname)) |
|
| 335 | + if (!empty($attrname) && preg_match("/^\w[a-zA-Z0-9-_]*$/", $attrname) && !is_numeric($attrname)) |
|
| 336 | 336 | { |
| 337 | 337 | if (is_array($param) && count($param) > 0) |
| 338 | 338 | { |
@@ -344,54 +344,54 @@ discard block |
||
| 344 | 344 | } |
| 345 | 345 | else |
| 346 | 346 | { |
| 347 | - $params=''; |
|
| 347 | + $params = ''; |
|
| 348 | 348 | } |
| 349 | 349 | |
| 350 | 350 | $sql = "INSERT INTO ".MAIN_DB_PREFIX."extrafields("; |
| 351 | - $sql.= " name,"; |
|
| 352 | - $sql.= " label,"; |
|
| 353 | - $sql.= " type,"; |
|
| 354 | - $sql.= " pos,"; |
|
| 355 | - $sql.= " size,"; |
|
| 356 | - $sql.= " entity,"; |
|
| 357 | - $sql.= " elementtype,"; |
|
| 358 | - $sql.= " fieldunique,"; |
|
| 359 | - $sql.= " fieldrequired,"; |
|
| 360 | - $sql.= " param,"; |
|
| 361 | - $sql.= " alwayseditable,"; |
|
| 362 | - $sql.= " perms,"; |
|
| 363 | - $sql.= " langs,"; |
|
| 364 | - $sql.= " list,"; |
|
| 365 | - $sql.= " fielddefault,"; |
|
| 366 | - $sql.= " fieldcomputed,"; |
|
| 367 | - $sql.= " fk_user_author,"; |
|
| 368 | - $sql.= " fk_user_modif,"; |
|
| 369 | - $sql.= " datec,"; |
|
| 370 | - $sql.= " enabled,"; |
|
| 371 | - $sql.= " help"; |
|
| 372 | - $sql.= " )"; |
|
| 373 | - $sql.= " VALUES('".$attrname."',"; |
|
| 374 | - $sql.= " '".$this->db->escape($label)."',"; |
|
| 375 | - $sql.= " '".$this->db->escape($type)."',"; |
|
| 376 | - $sql.= " ".$pos.","; |
|
| 377 | - $sql.= " '".$this->db->escape($size)."',"; |
|
| 378 | - $sql.= " ".($entity===''?$conf->entity:$entity).","; |
|
| 379 | - $sql.= " '".$this->db->escape($elementtype)."',"; |
|
| 380 | - $sql.= " ".$unique.","; |
|
| 381 | - $sql.= " ".$required.","; |
|
| 382 | - $sql.= " '".$this->db->escape($params)."',"; |
|
| 383 | - $sql.= " ".$alwayseditable.","; |
|
| 384 | - $sql.= " ".($perms?"'".$this->db->escape($perms)."'":"null").","; |
|
| 385 | - $sql.= " ".($langfile?"'".$this->db->escape($langfile)."'":"null").","; |
|
| 386 | - $sql.= " '".$this->db->escape($list)."',"; |
|
| 387 | - $sql.= " ".($default?"'".$this->db->escape($default)."'":"null").","; |
|
| 388 | - $sql.= " ".($computed?"'".$this->db->escape($computed)."'":"null").","; |
|
| 389 | - $sql .= " " . (is_object($user) ? $user->id : 0). ","; |
|
| 390 | - $sql .= " " . (is_object($user) ? $user->id : 0). ","; |
|
| 391 | - $sql .= "'" . $this->db->idate(dol_now()) . "',"; |
|
| 392 | - $sql.= " ".($enabled?"'".$this->db->escape($enabled)."'":"1").","; |
|
| 393 | - $sql.= " ".($help?"'".$this->db->escape($help)."'":"null"); |
|
| 394 | - $sql.=')'; |
|
| 351 | + $sql .= " name,"; |
|
| 352 | + $sql .= " label,"; |
|
| 353 | + $sql .= " type,"; |
|
| 354 | + $sql .= " pos,"; |
|
| 355 | + $sql .= " size,"; |
|
| 356 | + $sql .= " entity,"; |
|
| 357 | + $sql .= " elementtype,"; |
|
| 358 | + $sql .= " fieldunique,"; |
|
| 359 | + $sql .= " fieldrequired,"; |
|
| 360 | + $sql .= " param,"; |
|
| 361 | + $sql .= " alwayseditable,"; |
|
| 362 | + $sql .= " perms,"; |
|
| 363 | + $sql .= " langs,"; |
|
| 364 | + $sql .= " list,"; |
|
| 365 | + $sql .= " fielddefault,"; |
|
| 366 | + $sql .= " fieldcomputed,"; |
|
| 367 | + $sql .= " fk_user_author,"; |
|
| 368 | + $sql .= " fk_user_modif,"; |
|
| 369 | + $sql .= " datec,"; |
|
| 370 | + $sql .= " enabled,"; |
|
| 371 | + $sql .= " help"; |
|
| 372 | + $sql .= " )"; |
|
| 373 | + $sql .= " VALUES('".$attrname."',"; |
|
| 374 | + $sql .= " '".$this->db->escape($label)."',"; |
|
| 375 | + $sql .= " '".$this->db->escape($type)."',"; |
|
| 376 | + $sql .= " ".$pos.","; |
|
| 377 | + $sql .= " '".$this->db->escape($size)."',"; |
|
| 378 | + $sql .= " ".($entity === '' ? $conf->entity : $entity).","; |
|
| 379 | + $sql .= " '".$this->db->escape($elementtype)."',"; |
|
| 380 | + $sql .= " ".$unique.","; |
|
| 381 | + $sql .= " ".$required.","; |
|
| 382 | + $sql .= " '".$this->db->escape($params)."',"; |
|
| 383 | + $sql .= " ".$alwayseditable.","; |
|
| 384 | + $sql .= " ".($perms ? "'".$this->db->escape($perms)."'" : "null").","; |
|
| 385 | + $sql .= " ".($langfile ? "'".$this->db->escape($langfile)."'" : "null").","; |
|
| 386 | + $sql .= " '".$this->db->escape($list)."',"; |
|
| 387 | + $sql .= " ".($default ? "'".$this->db->escape($default)."'" : "null").","; |
|
| 388 | + $sql .= " ".($computed ? "'".$this->db->escape($computed)."'" : "null").","; |
|
| 389 | + $sql .= " ".(is_object($user) ? $user->id : 0).","; |
|
| 390 | + $sql .= " ".(is_object($user) ? $user->id : 0).","; |
|
| 391 | + $sql .= "'".$this->db->idate(dol_now())."',"; |
|
| 392 | + $sql .= " ".($enabled ? "'".$this->db->escape($enabled)."'" : "1").","; |
|
| 393 | + $sql .= " ".($help ? "'".$this->db->escape($help)."'" : "null"); |
|
| 394 | + $sql .= ')'; |
|
| 395 | 395 | |
| 396 | 396 | dol_syslog(get_class($this)."::create_label", LOG_DEBUG); |
| 397 | 397 | if ($this->db->query($sql)) |
@@ -400,8 +400,8 @@ discard block |
||
| 400 | 400 | } |
| 401 | 401 | else |
| 402 | 402 | { |
| 403 | - $this->error=$this->db->lasterror(); |
|
| 404 | - $this->errno=$this->db->lasterrno(); |
|
| 403 | + $this->error = $this->db->lasterror(); |
|
| 404 | + $this->errno = $this->db->lasterrno(); |
|
| 405 | 405 | return -1; |
| 406 | 406 | } |
| 407 | 407 | } |
@@ -414,31 +414,31 @@ discard block |
||
| 414 | 414 | * @param string $elementtype Element type ('member', 'product', 'thirdparty', 'contact', ...) |
| 415 | 415 | * @return int < 0 if KO, 0 if nothing is done, 1 if OK |
| 416 | 416 | */ |
| 417 | - function delete($attrname, $elementtype='member') |
|
| 417 | + function delete($attrname, $elementtype = 'member') |
|
| 418 | 418 | { |
| 419 | - if ($elementtype == 'thirdparty') $elementtype='societe'; |
|
| 420 | - if ($elementtype == 'contact') $elementtype='socpeople'; |
|
| 419 | + if ($elementtype == 'thirdparty') $elementtype = 'societe'; |
|
| 420 | + if ($elementtype == 'contact') $elementtype = 'socpeople'; |
|
| 421 | 421 | |
| 422 | - $table=$elementtype.'_extrafields'; |
|
| 423 | - if ($elementtype == 'categorie') $table='categories_extrafields'; |
|
| 422 | + $table = $elementtype.'_extrafields'; |
|
| 423 | + if ($elementtype == 'categorie') $table = 'categories_extrafields'; |
|
| 424 | 424 | |
| 425 | - $error=0; |
|
| 425 | + $error = 0; |
|
| 426 | 426 | |
| 427 | - if (! empty($attrname) && preg_match("/^\w[a-zA-Z0-9-_]*$/",$attrname)) |
|
| 427 | + if (!empty($attrname) && preg_match("/^\w[a-zA-Z0-9-_]*$/", $attrname)) |
|
| 428 | 428 | { |
| 429 | - $result=$this->delete_label($attrname,$elementtype); |
|
| 429 | + $result = $this->delete_label($attrname, $elementtype); |
|
| 430 | 430 | if ($result < 0) |
| 431 | 431 | { |
| 432 | - $this->error=$this->db->lasterror(); |
|
| 432 | + $this->error = $this->db->lasterror(); |
|
| 433 | 433 | $error++; |
| 434 | 434 | } |
| 435 | 435 | |
| 436 | - if (! $error) |
|
| 436 | + if (!$error) |
|
| 437 | 437 | { |
| 438 | 438 | $sql = "SELECT COUNT(rowid) as nb"; |
| 439 | - $sql.= " FROM ".MAIN_DB_PREFIX."extrafields"; |
|
| 440 | - $sql.= " WHERE elementtype = '".$elementtype."'"; |
|
| 441 | - $sql.= " AND name = '".$attrname."'"; |
|
| 439 | + $sql .= " FROM ".MAIN_DB_PREFIX."extrafields"; |
|
| 440 | + $sql .= " WHERE elementtype = '".$elementtype."'"; |
|
| 441 | + $sql .= " AND name = '".$attrname."'"; |
|
| 442 | 442 | //$sql.= " AND entity IN (0,".$conf->entity.")"; Do not test on entity here. We want to see if there is still on field remaning in other entities before deleting field in table |
| 443 | 443 | $resql = $this->db->query($sql); |
| 444 | 444 | if ($resql) |
@@ -446,10 +446,10 @@ discard block |
||
| 446 | 446 | $obj = $this->db->fetch_object($resql); |
| 447 | 447 | if ($obj->nb <= 0) |
| 448 | 448 | { |
| 449 | - $result=$this->db->DDLDropField(MAIN_DB_PREFIX.$table,$attrname); // This also drop the unique key |
|
| 449 | + $result = $this->db->DDLDropField(MAIN_DB_PREFIX.$table, $attrname); // This also drop the unique key |
|
| 450 | 450 | if ($result < 0) |
| 451 | 451 | { |
| 452 | - $this->error=$this->db->lasterror(); |
|
| 452 | + $this->error = $this->db->lasterror(); |
|
| 453 | 453 | $error++; |
| 454 | 454 | } |
| 455 | 455 | } |
@@ -472,23 +472,23 @@ discard block |
||
| 472 | 472 | * @param string $elementtype Element type ('member', 'product', 'thirdparty', ...) |
| 473 | 473 | * @return int < 0 if KO, 0 if nothing is done, 1 if OK |
| 474 | 474 | */ |
| 475 | - private function delete_label($attrname, $elementtype='member') |
|
| 475 | + private function delete_label($attrname, $elementtype = 'member') |
|
| 476 | 476 | { |
| 477 | 477 | // phpcs:enable |
| 478 | 478 | global $conf; |
| 479 | 479 | |
| 480 | - if ($elementtype == 'thirdparty') $elementtype='societe'; |
|
| 481 | - if ($elementtype == 'contact') $elementtype='socpeople'; |
|
| 480 | + if ($elementtype == 'thirdparty') $elementtype = 'societe'; |
|
| 481 | + if ($elementtype == 'contact') $elementtype = 'socpeople'; |
|
| 482 | 482 | |
| 483 | - if (isset($attrname) && $attrname != '' && preg_match("/^\w[a-zA-Z0-9-_]*$/",$attrname)) |
|
| 483 | + if (isset($attrname) && $attrname != '' && preg_match("/^\w[a-zA-Z0-9-_]*$/", $attrname)) |
|
| 484 | 484 | { |
| 485 | 485 | $sql = "DELETE FROM ".MAIN_DB_PREFIX."extrafields"; |
| 486 | - $sql.= " WHERE name = '".$attrname."'"; |
|
| 487 | - $sql.= " AND entity IN (0,".$conf->entity.')'; |
|
| 488 | - $sql.= " AND elementtype = '".$elementtype."'"; |
|
| 486 | + $sql .= " WHERE name = '".$attrname."'"; |
|
| 487 | + $sql .= " AND entity IN (0,".$conf->entity.')'; |
|
| 488 | + $sql .= " AND elementtype = '".$elementtype."'"; |
|
| 489 | 489 | |
| 490 | 490 | dol_syslog(get_class($this)."::delete_label", LOG_DEBUG); |
| 491 | - $resql=$this->db->query($sql); |
|
| 491 | + $resql = $this->db->query($sql); |
|
| 492 | 492 | if ($resql) |
| 493 | 493 | { |
| 494 | 494 | return 1; |
@@ -529,82 +529,82 @@ discard block |
||
| 529 | 529 | * @param int $totalizable Is extrafield totalizable on list |
| 530 | 530 | * @return int >0 if OK, <=0 if KO |
| 531 | 531 | */ |
| 532 | - function update($attrname, $label, $type, $length, $elementtype, $unique=0, $required=0, $pos=0, $param='', $alwayseditable=0, $perms='', $list='', $help='', $default='', $computed='', $entity='', $langfile='', $enabled='1', $totalizable=0) |
|
| 532 | + function update($attrname, $label, $type, $length, $elementtype, $unique = 0, $required = 0, $pos = 0, $param = '', $alwayseditable = 0, $perms = '', $list = '', $help = '', $default = '', $computed = '', $entity = '', $langfile = '', $enabled = '1', $totalizable = 0) |
|
| 533 | 533 | { |
| 534 | - if ($elementtype == 'thirdparty') $elementtype='societe'; |
|
| 535 | - if ($elementtype == 'contact') $elementtype='socpeople'; |
|
| 536 | - |
|
| 537 | - $table=$elementtype.'_extrafields'; |
|
| 538 | - if ($elementtype == 'categorie') $table='categories_extrafields'; |
|
| 539 | - |
|
| 540 | - if (isset($attrname) && $attrname != '' && preg_match("/^\w[a-zA-Z0-9-_]*$/",$attrname)) |
|
| 541 | - { |
|
| 542 | - if ($type=='boolean') { |
|
| 543 | - $typedb='int'; |
|
| 544 | - $lengthdb='1'; |
|
| 545 | - } elseif($type=='price') { |
|
| 546 | - $typedb='double'; |
|
| 547 | - $lengthdb='24,8'; |
|
| 548 | - } elseif($type=='phone') { |
|
| 549 | - $typedb='varchar'; |
|
| 550 | - $lengthdb='20'; |
|
| 551 | - } elseif($type=='mail') { |
|
| 552 | - $typedb='varchar'; |
|
| 553 | - $lengthdb='128'; |
|
| 554 | - } elseif($type=='url') { |
|
| 555 | - $typedb='varchar'; |
|
| 556 | - $lengthdb='255'; |
|
| 557 | - } elseif (($type=='select') || ($type=='sellist') || ($type=='radio') || ($type=='checkbox') || ($type=='chkbxlst')) { |
|
| 558 | - $typedb='varchar'; |
|
| 559 | - $lengthdb='255'; |
|
| 534 | + if ($elementtype == 'thirdparty') $elementtype = 'societe'; |
|
| 535 | + if ($elementtype == 'contact') $elementtype = 'socpeople'; |
|
| 536 | + |
|
| 537 | + $table = $elementtype.'_extrafields'; |
|
| 538 | + if ($elementtype == 'categorie') $table = 'categories_extrafields'; |
|
| 539 | + |
|
| 540 | + if (isset($attrname) && $attrname != '' && preg_match("/^\w[a-zA-Z0-9-_]*$/", $attrname)) |
|
| 541 | + { |
|
| 542 | + if ($type == 'boolean') { |
|
| 543 | + $typedb = 'int'; |
|
| 544 | + $lengthdb = '1'; |
|
| 545 | + } elseif ($type == 'price') { |
|
| 546 | + $typedb = 'double'; |
|
| 547 | + $lengthdb = '24,8'; |
|
| 548 | + } elseif ($type == 'phone') { |
|
| 549 | + $typedb = 'varchar'; |
|
| 550 | + $lengthdb = '20'; |
|
| 551 | + } elseif ($type == 'mail') { |
|
| 552 | + $typedb = 'varchar'; |
|
| 553 | + $lengthdb = '128'; |
|
| 554 | + } elseif ($type == 'url') { |
|
| 555 | + $typedb = 'varchar'; |
|
| 556 | + $lengthdb = '255'; |
|
| 557 | + } elseif (($type == 'select') || ($type == 'sellist') || ($type == 'radio') || ($type == 'checkbox') || ($type == 'chkbxlst')) { |
|
| 558 | + $typedb = 'varchar'; |
|
| 559 | + $lengthdb = '255'; |
|
| 560 | 560 | } elseif ($type == 'html') { |
| 561 | - $typedb='text'; |
|
| 562 | - } elseif ($type=='link') { |
|
| 563 | - $typedb='int'; |
|
| 564 | - $lengthdb='11'; |
|
| 565 | - } elseif($type=='password') { |
|
| 566 | - $typedb='varchar'; |
|
| 567 | - $lengthdb='50'; |
|
| 561 | + $typedb = 'text'; |
|
| 562 | + } elseif ($type == 'link') { |
|
| 563 | + $typedb = 'int'; |
|
| 564 | + $lengthdb = '11'; |
|
| 565 | + } elseif ($type == 'password') { |
|
| 566 | + $typedb = 'varchar'; |
|
| 567 | + $lengthdb = '50'; |
|
| 568 | 568 | } else { |
| 569 | - $typedb=$type; |
|
| 570 | - $lengthdb=$length; |
|
| 569 | + $typedb = $type; |
|
| 570 | + $lengthdb = $length; |
|
| 571 | 571 | } |
| 572 | - $field_desc = array('type'=>$typedb, 'value'=>$lengthdb, 'null'=>($required?'NOT NULL':'NULL'), 'default'=>$default); |
|
| 572 | + $field_desc = array('type'=>$typedb, 'value'=>$lengthdb, 'null'=>($required ? 'NOT NULL' : 'NULL'), 'default'=>$default); |
|
| 573 | 573 | |
| 574 | 574 | if ($type != 'separate') // No table update when separate type |
| 575 | 575 | { |
| 576 | - $result=$this->db->DDLUpdateField(MAIN_DB_PREFIX.$table, $attrname, $field_desc); |
|
| 576 | + $result = $this->db->DDLUpdateField(MAIN_DB_PREFIX.$table, $attrname, $field_desc); |
|
| 577 | 577 | } |
| 578 | 578 | if ($result > 0 || $type == 'separate') |
| 579 | 579 | { |
| 580 | 580 | if ($label) |
| 581 | 581 | { |
| 582 | - $result=$this->update_label($attrname,$label,$type,$length,$elementtype,$unique,$required,$pos,$param,$alwayseditable,$perms,$list,$help,$default,$computed,$entity,$langfile,$enabled, $totalizable); |
|
| 582 | + $result = $this->update_label($attrname, $label, $type, $length, $elementtype, $unique, $required, $pos, $param, $alwayseditable, $perms, $list, $help, $default, $computed, $entity, $langfile, $enabled, $totalizable); |
|
| 583 | 583 | } |
| 584 | 584 | if ($result > 0) |
| 585 | 585 | { |
| 586 | - $sql=''; |
|
| 586 | + $sql = ''; |
|
| 587 | 587 | if ($unique) |
| 588 | 588 | { |
| 589 | - $sql="ALTER TABLE ".MAIN_DB_PREFIX.$table." ADD UNIQUE INDEX uk_".$table."_".$attrname." (".$attrname.")"; |
|
| 589 | + $sql = "ALTER TABLE ".MAIN_DB_PREFIX.$table." ADD UNIQUE INDEX uk_".$table."_".$attrname." (".$attrname.")"; |
|
| 590 | 590 | } |
| 591 | 591 | else |
| 592 | 592 | { |
| 593 | - $sql="ALTER TABLE ".MAIN_DB_PREFIX.$table." DROP INDEX uk_".$table."_".$attrname; |
|
| 593 | + $sql = "ALTER TABLE ".MAIN_DB_PREFIX.$table." DROP INDEX uk_".$table."_".$attrname; |
|
| 594 | 594 | } |
| 595 | 595 | dol_syslog(get_class($this).'::update', LOG_DEBUG); |
| 596 | - $resql=$this->db->query($sql,1,'dml'); |
|
| 596 | + $resql = $this->db->query($sql, 1, 'dml'); |
|
| 597 | 597 | return 1; |
| 598 | 598 | } |
| 599 | 599 | else |
| 600 | 600 | { |
| 601 | - $this->error=$this->db->lasterror(); |
|
| 601 | + $this->error = $this->db->lasterror(); |
|
| 602 | 602 | return -1; |
| 603 | 603 | } |
| 604 | 604 | } |
| 605 | 605 | else |
| 606 | 606 | { |
| 607 | - $this->error=$this->db->lasterror(); |
|
| 607 | + $this->error = $this->db->lasterror(); |
|
| 608 | 608 | return -1; |
| 609 | 609 | } |
| 610 | 610 | } |
@@ -639,26 +639,26 @@ discard block |
||
| 639 | 639 | * @param int $totalizable Is extrafield totalizable on list |
| 640 | 640 | * @return int <=0 if KO, >0 if OK |
| 641 | 641 | */ |
| 642 | - private function update_label($attrname,$label,$type,$size,$elementtype,$unique=0,$required=0,$pos=0,$param='',$alwayseditable=0,$perms='',$list='0',$help='',$default='',$computed='',$entity='',$langfile='',$enabled='1', $totalizable=0) |
|
| 642 | + private function update_label($attrname, $label, $type, $size, $elementtype, $unique = 0, $required = 0, $pos = 0, $param = '', $alwayseditable = 0, $perms = '', $list = '0', $help = '', $default = '', $computed = '', $entity = '', $langfile = '', $enabled = '1', $totalizable = 0) |
|
| 643 | 643 | { |
| 644 | 644 | // phpcs:enable |
| 645 | 645 | global $conf, $user; |
| 646 | 646 | dol_syslog(get_class($this)."::update_label ".$attrname.", ".$label.", ".$type.", ".$size.", ".$elementtype.", ".$unique.", ".$required.", ".$pos.", ".$alwayseditable.", ".$perms.", ".$list.", ".$default.", ".$computed.", ".$entity.", ".$langfile.", ".$enabled.", ".$totalizable); |
| 647 | 647 | |
| 648 | 648 | // Clean parameters |
| 649 | - if ($elementtype == 'thirdparty') $elementtype='societe'; |
|
| 650 | - if ($elementtype == 'contact') $elementtype='socpeople'; |
|
| 649 | + if ($elementtype == 'thirdparty') $elementtype = 'societe'; |
|
| 650 | + if ($elementtype == 'contact') $elementtype = 'socpeople'; |
|
| 651 | 651 | |
| 652 | - if (empty($pos)) $pos=0; |
|
| 653 | - if (empty($list)) $list='0'; |
|
| 652 | + if (empty($pos)) $pos = 0; |
|
| 653 | + if (empty($list)) $list = '0'; |
|
| 654 | 654 | if (empty($totalizable)) { |
| 655 | 655 | $totalizable = 0; |
| 656 | 656 | } |
| 657 | - if (empty($required)) $required=0; |
|
| 658 | - if (empty($unique)) $unique=0; |
|
| 659 | - if (empty($alwayseditable)) $alwayseditable=0; |
|
| 657 | + if (empty($required)) $required = 0; |
|
| 658 | + if (empty($unique)) $unique = 0; |
|
| 659 | + if (empty($alwayseditable)) $alwayseditable = 0; |
|
| 660 | 660 | |
| 661 | - if (isset($attrname) && $attrname != '' && preg_match("/^\w[a-zA-Z0-9-_]*$/",$attrname)) |
|
| 661 | + if (isset($attrname) && $attrname != '' && preg_match("/^\w[a-zA-Z0-9-_]*$/", $attrname)) |
|
| 662 | 662 | { |
| 663 | 663 | $this->db->begin(); |
| 664 | 664 | |
@@ -672,76 +672,76 @@ discard block |
||
| 672 | 672 | } |
| 673 | 673 | else |
| 674 | 674 | { |
| 675 | - $params=''; |
|
| 675 | + $params = ''; |
|
| 676 | 676 | } |
| 677 | 677 | |
| 678 | 678 | if ($entity === '' || $entity != '0') |
| 679 | 679 | { |
| 680 | 680 | // We dont want on all entities, we delete all and current |
| 681 | 681 | $sql_del = "DELETE FROM ".MAIN_DB_PREFIX."extrafields"; |
| 682 | - $sql_del.= " WHERE name = '".$attrname."'"; |
|
| 683 | - $sql_del.= " AND entity IN (0, ".($entity===''?$conf->entity:$entity).")"; |
|
| 684 | - $sql_del.= " AND elementtype = '".$elementtype."'"; |
|
| 682 | + $sql_del .= " WHERE name = '".$attrname."'"; |
|
| 683 | + $sql_del .= " AND entity IN (0, ".($entity === '' ? $conf->entity : $entity).")"; |
|
| 684 | + $sql_del .= " AND elementtype = '".$elementtype."'"; |
|
| 685 | 685 | } |
| 686 | 686 | else |
| 687 | 687 | { |
| 688 | 688 | // We want on all entities ($entities = '0'), we delete on all only (we keep setup specific to each entity) |
| 689 | 689 | $sql_del = "DELETE FROM ".MAIN_DB_PREFIX."extrafields"; |
| 690 | - $sql_del.= " WHERE name = '".$attrname."'"; |
|
| 691 | - $sql_del.= " AND entity = 0"; |
|
| 692 | - $sql_del.= " AND elementtype = '".$elementtype."'"; |
|
| 690 | + $sql_del .= " WHERE name = '".$attrname."'"; |
|
| 691 | + $sql_del .= " AND entity = 0"; |
|
| 692 | + $sql_del .= " AND elementtype = '".$elementtype."'"; |
|
| 693 | 693 | } |
| 694 | - $resql1=$this->db->query($sql_del); |
|
| 694 | + $resql1 = $this->db->query($sql_del); |
|
| 695 | 695 | |
| 696 | 696 | $sql = "INSERT INTO ".MAIN_DB_PREFIX."extrafields("; |
| 697 | - $sql.= " name,"; // This is code |
|
| 698 | - $sql.= " entity,"; |
|
| 699 | - $sql.= " label,"; |
|
| 700 | - $sql.= " type,"; |
|
| 701 | - $sql.= " size,"; |
|
| 702 | - $sql.= " elementtype,"; |
|
| 703 | - $sql.= " fieldunique,"; |
|
| 704 | - $sql.= " fieldrequired,"; |
|
| 705 | - $sql.= " perms,"; |
|
| 706 | - $sql.= " langs,"; |
|
| 707 | - $sql.= " pos,"; |
|
| 708 | - $sql.= " alwayseditable,"; |
|
| 709 | - $sql.= " param,"; |
|
| 710 | - $sql.= " list,"; |
|
| 711 | - $sql.= " totalizable,"; |
|
| 712 | - $sql.= " fielddefault,"; |
|
| 713 | - $sql.= " fieldcomputed,"; |
|
| 714 | - $sql.= " fk_user_author,"; |
|
| 715 | - $sql.= " fk_user_modif,"; |
|
| 716 | - $sql.= " datec,"; |
|
| 717 | - $sql.= " enabled,"; |
|
| 718 | - $sql.= " help"; |
|
| 719 | - $sql.= ") VALUES ("; |
|
| 720 | - $sql.= "'".$attrname."',"; |
|
| 721 | - $sql.= " ".($entity===''?$conf->entity:$entity).","; |
|
| 722 | - $sql.= " '".$this->db->escape($label)."',"; |
|
| 723 | - $sql.= " '".$this->db->escape($type)."',"; |
|
| 724 | - $sql.= " '".$this->db->escape($size)."',"; |
|
| 725 | - $sql.= " '".$this->db->escape($elementtype)."',"; |
|
| 726 | - $sql.= " ".$unique.","; |
|
| 727 | - $sql.= " ".$required.","; |
|
| 728 | - $sql.= " ".($perms?"'".$this->db->escape($perms)."'":"null").","; |
|
| 729 | - $sql.= " ".($langfile?"'".$this->db->escape($langfile)."'":"null").","; |
|
| 730 | - $sql.= " ".$pos.","; |
|
| 731 | - $sql.= " '".$this->db->escape($alwayseditable)."',"; |
|
| 732 | - $sql.= " '".$this->db->escape($params)."',"; |
|
| 733 | - $sql.= " '".$this->db->escape($list)."', "; |
|
| 734 | - $sql.= " ".$totalizable.","; |
|
| 735 | - $sql.= " ".(($default!='')?"'".$this->db->escape($default)."'":"null").","; |
|
| 736 | - $sql.= " ".($computed?"'".$this->db->escape($computed)."'":"null").","; |
|
| 737 | - $sql .= " " . $user->id . ","; |
|
| 738 | - $sql .= " " . $user->id . ","; |
|
| 739 | - $sql .= "'" . $this->db->idate(dol_now()) . "',"; |
|
| 740 | - $sql .= "'" . $this->db->escape($enabled). "',"; |
|
| 741 | - $sql.= " ".($help?"'".$this->db->escape($help)."'":"null"); |
|
| 742 | - $sql.= ")"; |
|
| 743 | - |
|
| 744 | - $resql2=$this->db->query($sql); |
|
| 697 | + $sql .= " name,"; // This is code |
|
| 698 | + $sql .= " entity,"; |
|
| 699 | + $sql .= " label,"; |
|
| 700 | + $sql .= " type,"; |
|
| 701 | + $sql .= " size,"; |
|
| 702 | + $sql .= " elementtype,"; |
|
| 703 | + $sql .= " fieldunique,"; |
|
| 704 | + $sql .= " fieldrequired,"; |
|
| 705 | + $sql .= " perms,"; |
|
| 706 | + $sql .= " langs,"; |
|
| 707 | + $sql .= " pos,"; |
|
| 708 | + $sql .= " alwayseditable,"; |
|
| 709 | + $sql .= " param,"; |
|
| 710 | + $sql .= " list,"; |
|
| 711 | + $sql .= " totalizable,"; |
|
| 712 | + $sql .= " fielddefault,"; |
|
| 713 | + $sql .= " fieldcomputed,"; |
|
| 714 | + $sql .= " fk_user_author,"; |
|
| 715 | + $sql .= " fk_user_modif,"; |
|
| 716 | + $sql .= " datec,"; |
|
| 717 | + $sql .= " enabled,"; |
|
| 718 | + $sql .= " help"; |
|
| 719 | + $sql .= ") VALUES ("; |
|
| 720 | + $sql .= "'".$attrname."',"; |
|
| 721 | + $sql .= " ".($entity === '' ? $conf->entity : $entity).","; |
|
| 722 | + $sql .= " '".$this->db->escape($label)."',"; |
|
| 723 | + $sql .= " '".$this->db->escape($type)."',"; |
|
| 724 | + $sql .= " '".$this->db->escape($size)."',"; |
|
| 725 | + $sql .= " '".$this->db->escape($elementtype)."',"; |
|
| 726 | + $sql .= " ".$unique.","; |
|
| 727 | + $sql .= " ".$required.","; |
|
| 728 | + $sql .= " ".($perms ? "'".$this->db->escape($perms)."'" : "null").","; |
|
| 729 | + $sql .= " ".($langfile ? "'".$this->db->escape($langfile)."'" : "null").","; |
|
| 730 | + $sql .= " ".$pos.","; |
|
| 731 | + $sql .= " '".$this->db->escape($alwayseditable)."',"; |
|
| 732 | + $sql .= " '".$this->db->escape($params)."',"; |
|
| 733 | + $sql .= " '".$this->db->escape($list)."', "; |
|
| 734 | + $sql .= " ".$totalizable.","; |
|
| 735 | + $sql .= " ".(($default != '') ? "'".$this->db->escape($default)."'" : "null").","; |
|
| 736 | + $sql .= " ".($computed ? "'".$this->db->escape($computed)."'" : "null").","; |
|
| 737 | + $sql .= " ".$user->id.","; |
|
| 738 | + $sql .= " ".$user->id.","; |
|
| 739 | + $sql .= "'".$this->db->idate(dol_now())."',"; |
|
| 740 | + $sql .= "'".$this->db->escape($enabled)."',"; |
|
| 741 | + $sql .= " ".($help ? "'".$this->db->escape($help)."'" : "null"); |
|
| 742 | + $sql .= ")"; |
|
| 743 | + |
|
| 744 | + $resql2 = $this->db->query($sql); |
|
| 745 | 745 | |
| 746 | 746 | if ($resql1 && $resql2) |
| 747 | 747 | { |
@@ -770,34 +770,34 @@ discard block |
||
| 770 | 770 | * @param boolean $forceload Force load of extra fields whatever is option MAIN_EXTRAFIELDS_DISABLED. Deprecated. Should not be required. |
| 771 | 771 | * @return array Array of attributes keys+label for all extra fields. |
| 772 | 772 | */ |
| 773 | - function fetch_name_optionals_label($elementtype,$forceload=false) |
|
| 773 | + function fetch_name_optionals_label($elementtype, $forceload = false) |
|
| 774 | 774 | { |
| 775 | 775 | // phpcs:enable |
| 776 | 776 | global $conf; |
| 777 | 777 | |
| 778 | 778 | if (empty($elementtype)) return array(); |
| 779 | 779 | |
| 780 | - if ($elementtype == 'thirdparty') $elementtype='societe'; |
|
| 781 | - if ($elementtype == 'contact') $elementtype='socpeople'; |
|
| 782 | - if ($elementtype == 'order_supplier') $elementtype='commande_fournisseur'; |
|
| 780 | + if ($elementtype == 'thirdparty') $elementtype = 'societe'; |
|
| 781 | + if ($elementtype == 'contact') $elementtype = 'socpeople'; |
|
| 782 | + if ($elementtype == 'order_supplier') $elementtype = 'commande_fournisseur'; |
|
| 783 | 783 | |
| 784 | - $array_name_label=array(); |
|
| 784 | + $array_name_label = array(); |
|
| 785 | 785 | |
| 786 | 786 | // To avoid conflicts with external modules. TODO Remove this. |
| 787 | 787 | if (!$forceload && !empty($conf->global->MAIN_EXTRAFIELDS_DISABLED)) return $array_name_label; |
| 788 | 788 | |
| 789 | 789 | // Set array of label of entity |
| 790 | 790 | // TODO Remove completely loading of label. This should be done by presentation. |
| 791 | - $labelmulticompany=array(); |
|
| 791 | + $labelmulticompany = array(); |
|
| 792 | 792 | if (!empty($conf->multicompany->enabled)) |
| 793 | 793 | { |
| 794 | - $sql_entity_name='SELECT rowid, label FROM '.MAIN_DB_PREFIX.'entity WHERE rowid in (0,'.$conf->entity.')'; |
|
| 795 | - $resql_entity_name=$this->db->query($sql_entity_name); |
|
| 794 | + $sql_entity_name = 'SELECT rowid, label FROM '.MAIN_DB_PREFIX.'entity WHERE rowid in (0,'.$conf->entity.')'; |
|
| 795 | + $resql_entity_name = $this->db->query($sql_entity_name); |
|
| 796 | 796 | if ($resql_entity_name) |
| 797 | 797 | { |
| 798 | 798 | while ($obj = $this->db->fetch_object($resql_entity_name)) |
| 799 | 799 | { |
| 800 | - $labelmulticompany[$obj->rowid]=$obj->label; |
|
| 800 | + $labelmulticompany[$obj->rowid] = $obj->label; |
|
| 801 | 801 | } |
| 802 | 802 | } |
| 803 | 803 | } |
@@ -806,12 +806,12 @@ discard block |
||
| 806 | 806 | dol_syslog("fetch_name_optionals_label elementtype=".$elementtype); |
| 807 | 807 | |
| 808 | 808 | $sql = "SELECT rowid,name,label,type,size,elementtype,fieldunique,fieldrequired,param,pos,alwayseditable,perms,langs,list,totalizable,fielddefault,fieldcomputed,entity,enabled,help"; |
| 809 | - $sql.= " FROM ".MAIN_DB_PREFIX."extrafields"; |
|
| 810 | - $sql.= " WHERE entity IN (0,".$conf->entity.")"; |
|
| 811 | - if ($elementtype) $sql.= " AND elementtype = '".$elementtype."'"; // Filed with object->table_element |
|
| 812 | - $sql.= " ORDER BY pos"; |
|
| 809 | + $sql .= " FROM ".MAIN_DB_PREFIX."extrafields"; |
|
| 810 | + $sql .= " WHERE entity IN (0,".$conf->entity.")"; |
|
| 811 | + if ($elementtype) $sql .= " AND elementtype = '".$elementtype."'"; // Filed with object->table_element |
|
| 812 | + $sql .= " ORDER BY pos"; |
|
| 813 | 813 | |
| 814 | - $resql=$this->db->query($sql); |
|
| 814 | + $resql = $this->db->query($sql); |
|
| 815 | 815 | if ($resql) |
| 816 | 816 | { |
| 817 | 817 | if ($this->db->num_rows($resql)) |
@@ -821,57 +821,57 @@ discard block |
||
| 821 | 821 | // We can add this attribute to object. TODO Remove this and return $this->attributes[$elementtype]['label'] |
| 822 | 822 | if ($tab->type != 'separate') |
| 823 | 823 | { |
| 824 | - $array_name_label[$tab->name]=$tab->label; |
|
| 824 | + $array_name_label[$tab->name] = $tab->label; |
|
| 825 | 825 | } |
| 826 | 826 | |
| 827 | 827 | // Old usage |
| 828 | - $this->attribute_type[$tab->name]=$tab->type; |
|
| 829 | - $this->attribute_label[$tab->name]=$tab->label; |
|
| 830 | - $this->attribute_size[$tab->name]=$tab->size; |
|
| 831 | - $this->attribute_elementtype[$tab->name]=$tab->elementtype; |
|
| 832 | - $this->attribute_default[$tab->name]=$tab->fielddefault; |
|
| 833 | - $this->attribute_computed[$tab->name]=$tab->fieldcomputed; |
|
| 834 | - $this->attribute_unique[$tab->name]=$tab->fieldunique; |
|
| 835 | - $this->attribute_required[$tab->name]=$tab->fieldrequired; |
|
| 836 | - $this->attribute_param[$tab->name]=($tab->param ? unserialize($tab->param) : ''); |
|
| 837 | - $this->attribute_pos[$tab->name]=$tab->pos; |
|
| 838 | - $this->attribute_alwayseditable[$tab->name]=$tab->alwayseditable; |
|
| 839 | - $this->attribute_perms[$tab->name]=(strlen($tab->perms) == 0 ? 1 : $tab->perms); |
|
| 840 | - $this->attribute_langfile[$tab->name]=$tab->langs; |
|
| 841 | - $this->attribute_list[$tab->name]=$tab->list; |
|
| 842 | - $this->attribute_totalizable[$tab->name]=$tab->totalizable; |
|
| 843 | - $this->attribute_entityid[$tab->name]=$tab->entity; |
|
| 844 | - $this->attribute_entitylabel[$tab->name]=(empty($labelmulticompany[$tab->entity])?'Entity'.$tab->entity:$labelmulticompany[$tab->entity]); |
|
| 828 | + $this->attribute_type[$tab->name] = $tab->type; |
|
| 829 | + $this->attribute_label[$tab->name] = $tab->label; |
|
| 830 | + $this->attribute_size[$tab->name] = $tab->size; |
|
| 831 | + $this->attribute_elementtype[$tab->name] = $tab->elementtype; |
|
| 832 | + $this->attribute_default[$tab->name] = $tab->fielddefault; |
|
| 833 | + $this->attribute_computed[$tab->name] = $tab->fieldcomputed; |
|
| 834 | + $this->attribute_unique[$tab->name] = $tab->fieldunique; |
|
| 835 | + $this->attribute_required[$tab->name] = $tab->fieldrequired; |
|
| 836 | + $this->attribute_param[$tab->name] = ($tab->param ? unserialize($tab->param) : ''); |
|
| 837 | + $this->attribute_pos[$tab->name] = $tab->pos; |
|
| 838 | + $this->attribute_alwayseditable[$tab->name] = $tab->alwayseditable; |
|
| 839 | + $this->attribute_perms[$tab->name] = (strlen($tab->perms) == 0 ? 1 : $tab->perms); |
|
| 840 | + $this->attribute_langfile[$tab->name] = $tab->langs; |
|
| 841 | + $this->attribute_list[$tab->name] = $tab->list; |
|
| 842 | + $this->attribute_totalizable[$tab->name] = $tab->totalizable; |
|
| 843 | + $this->attribute_entityid[$tab->name] = $tab->entity; |
|
| 844 | + $this->attribute_entitylabel[$tab->name] = (empty($labelmulticompany[$tab->entity]) ? 'Entity'.$tab->entity : $labelmulticompany[$tab->entity]); |
|
| 845 | 845 | |
| 846 | 846 | // New usage |
| 847 | - $this->attributes[$tab->elementtype]['type'][$tab->name]=$tab->type; |
|
| 848 | - $this->attributes[$tab->elementtype]['label'][$tab->name]=$tab->label; |
|
| 849 | - $this->attributes[$tab->elementtype]['size'][$tab->name]=$tab->size; |
|
| 850 | - $this->attributes[$tab->elementtype]['elementtype'][$tab->name]=$tab->elementtype; |
|
| 851 | - $this->attributes[$tab->elementtype]['default'][$tab->name]=$tab->fielddefault; |
|
| 852 | - $this->attributes[$tab->elementtype]['computed'][$tab->name]=$tab->fieldcomputed; |
|
| 853 | - $this->attributes[$tab->elementtype]['unique'][$tab->name]=$tab->fieldunique; |
|
| 854 | - $this->attributes[$tab->elementtype]['required'][$tab->name]=$tab->fieldrequired; |
|
| 855 | - $this->attributes[$tab->elementtype]['param'][$tab->name]=($tab->param ? unserialize($tab->param) : ''); |
|
| 856 | - $this->attributes[$tab->elementtype]['pos'][$tab->name]=$tab->pos; |
|
| 857 | - $this->attributes[$tab->elementtype]['alwayseditable'][$tab->name]=$tab->alwayseditable; |
|
| 858 | - $this->attributes[$tab->elementtype]['perms'][$tab->name]=(strlen($tab->perms) == 0 ? 1 : $tab->perms); |
|
| 859 | - $this->attributes[$tab->elementtype]['langfile'][$tab->name]=$tab->langs; |
|
| 860 | - $this->attributes[$tab->elementtype]['list'][$tab->name]=$tab->list; |
|
| 861 | - $this->attributes[$tab->elementtype]['totalizable'][$tab->name]=$tab->totalizable; |
|
| 862 | - $this->attributes[$tab->elementtype]['entityid'][$tab->name]=$tab->entity; |
|
| 863 | - $this->attributes[$tab->elementtype]['entitylabel'][$tab->name]=(empty($labelmulticompany[$tab->entity])?'Entity'.$tab->entity:$labelmulticompany[$tab->entity]); |
|
| 864 | - $this->attributes[$tab->elementtype]['enabled'][$tab->name]=$tab->enabled; |
|
| 865 | - $this->attributes[$tab->elementtype]['help'][$tab->name]=$tab->help; |
|
| 866 | - |
|
| 867 | - $this->attributes[$tab->elementtype]['loaded']=1; |
|
| 847 | + $this->attributes[$tab->elementtype]['type'][$tab->name] = $tab->type; |
|
| 848 | + $this->attributes[$tab->elementtype]['label'][$tab->name] = $tab->label; |
|
| 849 | + $this->attributes[$tab->elementtype]['size'][$tab->name] = $tab->size; |
|
| 850 | + $this->attributes[$tab->elementtype]['elementtype'][$tab->name] = $tab->elementtype; |
|
| 851 | + $this->attributes[$tab->elementtype]['default'][$tab->name] = $tab->fielddefault; |
|
| 852 | + $this->attributes[$tab->elementtype]['computed'][$tab->name] = $tab->fieldcomputed; |
|
| 853 | + $this->attributes[$tab->elementtype]['unique'][$tab->name] = $tab->fieldunique; |
|
| 854 | + $this->attributes[$tab->elementtype]['required'][$tab->name] = $tab->fieldrequired; |
|
| 855 | + $this->attributes[$tab->elementtype]['param'][$tab->name] = ($tab->param ? unserialize($tab->param) : ''); |
|
| 856 | + $this->attributes[$tab->elementtype]['pos'][$tab->name] = $tab->pos; |
|
| 857 | + $this->attributes[$tab->elementtype]['alwayseditable'][$tab->name] = $tab->alwayseditable; |
|
| 858 | + $this->attributes[$tab->elementtype]['perms'][$tab->name] = (strlen($tab->perms) == 0 ? 1 : $tab->perms); |
|
| 859 | + $this->attributes[$tab->elementtype]['langfile'][$tab->name] = $tab->langs; |
|
| 860 | + $this->attributes[$tab->elementtype]['list'][$tab->name] = $tab->list; |
|
| 861 | + $this->attributes[$tab->elementtype]['totalizable'][$tab->name] = $tab->totalizable; |
|
| 862 | + $this->attributes[$tab->elementtype]['entityid'][$tab->name] = $tab->entity; |
|
| 863 | + $this->attributes[$tab->elementtype]['entitylabel'][$tab->name] = (empty($labelmulticompany[$tab->entity]) ? 'Entity'.$tab->entity : $labelmulticompany[$tab->entity]); |
|
| 864 | + $this->attributes[$tab->elementtype]['enabled'][$tab->name] = $tab->enabled; |
|
| 865 | + $this->attributes[$tab->elementtype]['help'][$tab->name] = $tab->help; |
|
| 866 | + |
|
| 867 | + $this->attributes[$tab->elementtype]['loaded'] = 1; |
|
| 868 | 868 | } |
| 869 | 869 | } |
| 870 | - if ($elementtype) $this->attributes[$elementtype]['loaded']=1; // If nothing found, we also save tag 'loaded' |
|
| 870 | + if ($elementtype) $this->attributes[$elementtype]['loaded'] = 1; // If nothing found, we also save tag 'loaded' |
|
| 871 | 871 | } |
| 872 | 872 | else |
| 873 | 873 | { |
| 874 | - $this->error=$this->db->lasterror(); |
|
| 874 | + $this->error = $this->db->lasterror(); |
|
| 875 | 875 | dol_syslog(get_class($this)."::fetch_name_optionals_label ".$this->error, LOG_ERR); |
| 876 | 876 | } |
| 877 | 877 | |
@@ -893,57 +893,57 @@ discard block |
||
| 893 | 893 | * @param string $extrafieldsobjectkey If defined (for example $object->table_element), use the new method to get extrafields data |
| 894 | 894 | * @return string |
| 895 | 895 | */ |
| 896 | - function showInputField($key, $value, $moreparam='', $keysuffix='', $keyprefix='', $morecss='', $objectid=0, $extrafieldsobjectkey='') |
|
| 896 | + function showInputField($key, $value, $moreparam = '', $keysuffix = '', $keyprefix = '', $morecss = '', $objectid = 0, $extrafieldsobjectkey = '') |
|
| 897 | 897 | { |
| 898 | - global $conf,$langs,$form; |
|
| 898 | + global $conf, $langs, $form; |
|
| 899 | 899 | |
| 900 | - if (! is_object($form)) |
|
| 900 | + if (!is_object($form)) |
|
| 901 | 901 | { |
| 902 | 902 | require_once DOL_DOCUMENT_ROOT.'/core/class/html.form.class.php'; |
| 903 | - $form=new Form($this->db); |
|
| 903 | + $form = new Form($this->db); |
|
| 904 | 904 | } |
| 905 | 905 | |
| 906 | - $out=''; |
|
| 906 | + $out = ''; |
|
| 907 | 907 | |
| 908 | - $keyprefix = $keyprefix.'options_'; // Because we work on extrafields |
|
| 908 | + $keyprefix = $keyprefix.'options_'; // Because we work on extrafields |
|
| 909 | 909 | |
| 910 | - if (! empty($extrafieldsobjectkey)) |
|
| 910 | + if (!empty($extrafieldsobjectkey)) |
|
| 911 | 911 | { |
| 912 | - $label=$this->attributes[$extrafieldsobjectkey]['label'][$key]; |
|
| 913 | - $type=$this->attributes[$extrafieldsobjectkey]['type'][$key]; |
|
| 914 | - $size=$this->attributes[$extrafieldsobjectkey]['size'][$key]; |
|
| 915 | - $default=$this->attributes[$extrafieldsobjectkey]['default'][$key]; |
|
| 916 | - $computed=$this->attributes[$extrafieldsobjectkey]['computed'][$key]; |
|
| 917 | - $unique=$this->attributes[$extrafieldsobjectkey]['unique'][$key]; |
|
| 918 | - $required=$this->attributes[$extrafieldsobjectkey]['required'][$key]; |
|
| 919 | - $param=$this->attributes[$extrafieldsobjectkey]['param'][$key]; |
|
| 920 | - $perms=dol_eval($this->attributes[$extrafieldsobjectkey]['perms'][$key], 1); |
|
| 921 | - $langfile=$this->attributes[$extrafieldsobjectkey]['langfile'][$key]; |
|
| 922 | - $list=dol_eval($this->attributes[$extrafieldsobjectkey]['list'][$key], 1); |
|
| 923 | - $totalizable=$this->attributes[$extrafieldsobjectkey]['totalizable'][$key]; |
|
| 924 | - $help=$this->attributes[$extrafieldsobjectkey]['help'][$key]; |
|
| 925 | - $hidden=(empty($list) ? 1 : 0); // If empty, we are sure it is hidden, otherwise we show. If it depends on mode (view/create/edit form or list, this must be filtered by caller) |
|
| 912 | + $label = $this->attributes[$extrafieldsobjectkey]['label'][$key]; |
|
| 913 | + $type = $this->attributes[$extrafieldsobjectkey]['type'][$key]; |
|
| 914 | + $size = $this->attributes[$extrafieldsobjectkey]['size'][$key]; |
|
| 915 | + $default = $this->attributes[$extrafieldsobjectkey]['default'][$key]; |
|
| 916 | + $computed = $this->attributes[$extrafieldsobjectkey]['computed'][$key]; |
|
| 917 | + $unique = $this->attributes[$extrafieldsobjectkey]['unique'][$key]; |
|
| 918 | + $required = $this->attributes[$extrafieldsobjectkey]['required'][$key]; |
|
| 919 | + $param = $this->attributes[$extrafieldsobjectkey]['param'][$key]; |
|
| 920 | + $perms = dol_eval($this->attributes[$extrafieldsobjectkey]['perms'][$key], 1); |
|
| 921 | + $langfile = $this->attributes[$extrafieldsobjectkey]['langfile'][$key]; |
|
| 922 | + $list = dol_eval($this->attributes[$extrafieldsobjectkey]['list'][$key], 1); |
|
| 923 | + $totalizable = $this->attributes[$extrafieldsobjectkey]['totalizable'][$key]; |
|
| 924 | + $help = $this->attributes[$extrafieldsobjectkey]['help'][$key]; |
|
| 925 | + $hidden = (empty($list) ? 1 : 0); // If empty, we are sure it is hidden, otherwise we show. If it depends on mode (view/create/edit form or list, this must be filtered by caller) |
|
| 926 | 926 | } |
| 927 | 927 | else // Old usage |
| 928 | 928 | { |
| 929 | - $label=$this->attribute_label[$key]; |
|
| 930 | - $type =$this->attribute_type[$key]; |
|
| 931 | - $size =$this->attribute_size[$key]; |
|
| 932 | - $elementtype=$this->attribute_elementtype[$key]; // Seems not used |
|
| 933 | - $default=$this->attribute_default[$key]; |
|
| 934 | - $computed=$this->attribute_computed[$key]; |
|
| 935 | - $unique=$this->attribute_unique[$key]; |
|
| 936 | - $required=$this->attribute_required[$key]; |
|
| 937 | - $param=$this->attribute_param[$key]; |
|
| 938 | - $langfile=$this->attribute_langfile[$key]; |
|
| 939 | - $list=$this->attribute_list[$key]; |
|
| 940 | - $totalizable=$this->attribute_totalizable[$key]; |
|
| 941 | - $hidden=(empty($list) ? 1 : 0); // If empty, we are sure it is hidden, otherwise we show. If it depends on mode (view/create/edit form or list, this must be filtered by caller) |
|
| 929 | + $label = $this->attribute_label[$key]; |
|
| 930 | + $type = $this->attribute_type[$key]; |
|
| 931 | + $size = $this->attribute_size[$key]; |
|
| 932 | + $elementtype = $this->attribute_elementtype[$key]; // Seems not used |
|
| 933 | + $default = $this->attribute_default[$key]; |
|
| 934 | + $computed = $this->attribute_computed[$key]; |
|
| 935 | + $unique = $this->attribute_unique[$key]; |
|
| 936 | + $required = $this->attribute_required[$key]; |
|
| 937 | + $param = $this->attribute_param[$key]; |
|
| 938 | + $langfile = $this->attribute_langfile[$key]; |
|
| 939 | + $list = $this->attribute_list[$key]; |
|
| 940 | + $totalizable = $this->attribute_totalizable[$key]; |
|
| 941 | + $hidden = (empty($list) ? 1 : 0); // If empty, we are sure it is hidden, otherwise we show. If it depends on mode (view/create/edit form or list, this must be filtered by caller) |
|
| 942 | 942 | } |
| 943 | 943 | |
| 944 | 944 | if ($computed) |
| 945 | 945 | { |
| 946 | - if (! preg_match('/^search_/', $keyprefix)) return '<span class="opacitymedium">'.$langs->trans("AutomaticallyCalculated").'</span>'; |
|
| 946 | + if (!preg_match('/^search_/', $keyprefix)) return '<span class="opacitymedium">'.$langs->trans("AutomaticallyCalculated").'</span>'; |
|
| 947 | 947 | else return ''; |
| 948 | 948 | } |
| 949 | 949 | |
@@ -957,21 +957,21 @@ discard block |
||
| 957 | 957 | { |
| 958 | 958 | $morecss = 'minwidth200imp'; |
| 959 | 959 | } |
| 960 | - elseif (in_array($type,array('int','integer','double','price'))) |
|
| 960 | + elseif (in_array($type, array('int', 'integer', 'double', 'price'))) |
|
| 961 | 961 | { |
| 962 | 962 | $morecss = 'maxwidth75'; |
| 963 | 963 | } |
| 964 | 964 | elseif ($type == 'password') |
| 965 | 965 | { |
| 966 | - $morecss='maxwidth100'; |
|
| 966 | + $morecss = 'maxwidth100'; |
|
| 967 | 967 | } |
| 968 | 968 | elseif ($type == 'url') |
| 969 | 969 | { |
| 970 | - $morecss='minwidth400'; |
|
| 970 | + $morecss = 'minwidth400'; |
|
| 971 | 971 | } |
| 972 | 972 | elseif ($type == 'boolean') |
| 973 | 973 | { |
| 974 | - $morecss=''; |
|
| 974 | + $morecss = ''; |
|
| 975 | 975 | } |
| 976 | 976 | else |
| 977 | 977 | { |
@@ -990,12 +990,12 @@ discard block |
||
| 990 | 990 | } |
| 991 | 991 | } |
| 992 | 992 | |
| 993 | - if (in_array($type,array('date','datetime'))) |
|
| 993 | + if (in_array($type, array('date', 'datetime'))) |
|
| 994 | 994 | { |
| 995 | - $tmp=explode(',',$size); |
|
| 996 | - $newsize=$tmp[0]; |
|
| 995 | + $tmp = explode(',', $size); |
|
| 996 | + $newsize = $tmp[0]; |
|
| 997 | 997 | |
| 998 | - $showtime = in_array($type,array('datetime')) ? 1 : 0; |
|
| 998 | + $showtime = in_array($type, array('datetime')) ? 1 : 0; |
|
| 999 | 999 | |
| 1000 | 1000 | // Do not show current date when field not required (see selectDate() method) |
| 1001 | 1001 | if (!$required && $value == '') $value = '-1'; |
@@ -1003,244 +1003,244 @@ discard block |
||
| 1003 | 1003 | // TODO Must also support $moreparam |
| 1004 | 1004 | $out = $form->selectDate($value, $keyprefix.$key.$keysuffix, $showtime, $showtime, $required, '', 1, (($keyprefix != 'search_' && $keyprefix != 'search_options_') ? 1 : 0), 0, 1); |
| 1005 | 1005 | } |
| 1006 | - elseif (in_array($type,array('int','integer'))) |
|
| 1006 | + elseif (in_array($type, array('int', 'integer'))) |
|
| 1007 | 1007 | { |
| 1008 | - $tmp=explode(',',$size); |
|
| 1009 | - $newsize=$tmp[0]; |
|
| 1010 | - $out='<input type="text" class="flat '.$morecss.' maxwidthonsmartphone" name="'.$keyprefix.$key.$keysuffix.'" id="'.$keyprefix.$key.$keysuffix.'" maxlength="'.$newsize.'" value="'.dol_escape_htmltag($value).'"'.($moreparam?$moreparam:'').'>'; |
|
| 1008 | + $tmp = explode(',', $size); |
|
| 1009 | + $newsize = $tmp[0]; |
|
| 1010 | + $out = '<input type="text" class="flat '.$morecss.' maxwidthonsmartphone" name="'.$keyprefix.$key.$keysuffix.'" id="'.$keyprefix.$key.$keysuffix.'" maxlength="'.$newsize.'" value="'.dol_escape_htmltag($value).'"'.($moreparam ? $moreparam : '').'>'; |
|
| 1011 | 1011 | } |
| 1012 | 1012 | elseif (preg_match('/varchar/', $type)) |
| 1013 | 1013 | { |
| 1014 | - $out='<input type="text" class="flat '.$morecss.' maxwidthonsmartphone" name="'.$keyprefix.$key.$keysuffix.'" id="'.$keyprefix.$key.$keysuffix.'" maxlength="'.$size.'" value="'.dol_escape_htmltag($value).'"'.($moreparam?$moreparam:'').'>'; |
|
| 1014 | + $out = '<input type="text" class="flat '.$morecss.' maxwidthonsmartphone" name="'.$keyprefix.$key.$keysuffix.'" id="'.$keyprefix.$key.$keysuffix.'" maxlength="'.$size.'" value="'.dol_escape_htmltag($value).'"'.($moreparam ? $moreparam : '').'>'; |
|
| 1015 | 1015 | } |
| 1016 | 1016 | elseif (in_array($type, array('mail', 'phone', 'url'))) |
| 1017 | 1017 | { |
| 1018 | - $out='<input type="text" class="flat '.$morecss.' maxwidthonsmartphone" name="'.$keyprefix.$key.$keysuffix.'" id="'.$keyprefix.$key.$keysuffix.'" value="'.dol_escape_htmltag($value).'" '.($moreparam?$moreparam:'').'>'; |
|
| 1018 | + $out = '<input type="text" class="flat '.$morecss.' maxwidthonsmartphone" name="'.$keyprefix.$key.$keysuffix.'" id="'.$keyprefix.$key.$keysuffix.'" value="'.dol_escape_htmltag($value).'" '.($moreparam ? $moreparam : '').'>'; |
|
| 1019 | 1019 | } |
| 1020 | 1020 | elseif ($type == 'text') |
| 1021 | 1021 | { |
| 1022 | - if (! preg_match('/search_/', $keyprefix)) // If keyprefix is search_ or search_options_, we must just use a simple text field |
|
| 1022 | + if (!preg_match('/search_/', $keyprefix)) // If keyprefix is search_ or search_options_, we must just use a simple text field |
|
| 1023 | 1023 | { |
| 1024 | 1024 | require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php'; |
| 1025 | - $doleditor=new DolEditor($keyprefix.$key.$keysuffix,$value,'',200,'dolibarr_notes','In',false,false,false,ROWS_5,'90%'); |
|
| 1026 | - $out=$doleditor->Create(1); |
|
| 1025 | + $doleditor = new DolEditor($keyprefix.$key.$keysuffix, $value, '', 200, 'dolibarr_notes', 'In', false, false, false, ROWS_5, '90%'); |
|
| 1026 | + $out = $doleditor->Create(1); |
|
| 1027 | 1027 | } |
| 1028 | 1028 | else |
| 1029 | 1029 | { |
| 1030 | - $out='<input type="text" class="flat '.$morecss.' maxwidthonsmartphone" name="'.$keyprefix.$key.$keysuffix.'" id="'.$keyprefix.$key.$keysuffix.'" value="'.dol_escape_htmltag($value).'" '.($moreparam?$moreparam:'').'>'; |
|
| 1030 | + $out = '<input type="text" class="flat '.$morecss.' maxwidthonsmartphone" name="'.$keyprefix.$key.$keysuffix.'" id="'.$keyprefix.$key.$keysuffix.'" value="'.dol_escape_htmltag($value).'" '.($moreparam ? $moreparam : '').'>'; |
|
| 1031 | 1031 | } |
| 1032 | 1032 | } |
| 1033 | 1033 | elseif ($type == 'html') |
| 1034 | 1034 | { |
| 1035 | - if (! preg_match('/search_/', $keyprefix)) // If keyprefix is search_ or search_options_, we must just use a simple text field |
|
| 1035 | + if (!preg_match('/search_/', $keyprefix)) // If keyprefix is search_ or search_options_, we must just use a simple text field |
|
| 1036 | 1036 | { |
| 1037 | 1037 | require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php'; |
| 1038 | - $doleditor=new DolEditor($keyprefix.$key.$keysuffix,$value,'',200,'dolibarr_notes','In',false,false,! empty($conf->fckeditor->enabled) && $conf->global->FCKEDITOR_ENABLE_SOCIETE,ROWS_5,'90%'); |
|
| 1039 | - $out=$doleditor->Create(1); |
|
| 1038 | + $doleditor = new DolEditor($keyprefix.$key.$keysuffix, $value, '', 200, 'dolibarr_notes', 'In', false, false, !empty($conf->fckeditor->enabled) && $conf->global->FCKEDITOR_ENABLE_SOCIETE, ROWS_5, '90%'); |
|
| 1039 | + $out = $doleditor->Create(1); |
|
| 1040 | 1040 | } |
| 1041 | 1041 | else |
| 1042 | 1042 | { |
| 1043 | - $out='<input type="text" class="flat '.$morecss.' maxwidthonsmartphone" name="'.$keyprefix.$key.$keysuffix.'" id="'.$keyprefix.$key.$keysuffix.'" value="'.dol_escape_htmltag($value).'" '.($moreparam?$moreparam:'').'>'; |
|
| 1043 | + $out = '<input type="text" class="flat '.$morecss.' maxwidthonsmartphone" name="'.$keyprefix.$key.$keysuffix.'" id="'.$keyprefix.$key.$keysuffix.'" value="'.dol_escape_htmltag($value).'" '.($moreparam ? $moreparam : '').'>'; |
|
| 1044 | 1044 | } |
| 1045 | 1045 | } |
| 1046 | 1046 | elseif ($type == 'boolean') |
| 1047 | 1047 | { |
| 1048 | - $checked=''; |
|
| 1048 | + $checked = ''; |
|
| 1049 | 1049 | if (!empty($value)) { |
| 1050 | - $checked=' checked value="1" '; |
|
| 1050 | + $checked = ' checked value="1" '; |
|
| 1051 | 1051 | } else { |
| 1052 | - $checked=' value="1" '; |
|
| 1052 | + $checked = ' value="1" '; |
|
| 1053 | 1053 | } |
| 1054 | - $out='<input type="checkbox" class="flat '.$morecss.' maxwidthonsmartphone" name="'.$keyprefix.$key.$keysuffix.'" id="'.$keyprefix.$key.$keysuffix.'" '.$checked.' '.($moreparam?$moreparam:'').'>'; |
|
| 1054 | + $out = '<input type="checkbox" class="flat '.$morecss.' maxwidthonsmartphone" name="'.$keyprefix.$key.$keysuffix.'" id="'.$keyprefix.$key.$keysuffix.'" '.$checked.' '.($moreparam ? $moreparam : '').'>'; |
|
| 1055 | 1055 | } |
| 1056 | 1056 | elseif ($type == 'price') |
| 1057 | 1057 | { |
| 1058 | 1058 | if (!empty($value)) { // $value in memory is a php numeric, we format it into user number format. |
| 1059 | - $value=price($value); |
|
| 1059 | + $value = price($value); |
|
| 1060 | 1060 | } |
| 1061 | - $out='<input type="text" class="flat '.$morecss.' maxwidthonsmartphone" name="'.$keyprefix.$key.$keysuffix.'" id="'.$keyprefix.$key.$keysuffix.'" value="'.$value.'" '.($moreparam?$moreparam:'').'> '.$langs->getCurrencySymbol($conf->currency); |
|
| 1061 | + $out = '<input type="text" class="flat '.$morecss.' maxwidthonsmartphone" name="'.$keyprefix.$key.$keysuffix.'" id="'.$keyprefix.$key.$keysuffix.'" value="'.$value.'" '.($moreparam ? $moreparam : '').'> '.$langs->getCurrencySymbol($conf->currency); |
|
| 1062 | 1062 | } |
| 1063 | 1063 | elseif ($type == 'double') |
| 1064 | 1064 | { |
| 1065 | 1065 | if (!empty($value)) { // $value in memory is a php numeric, we format it into user number format. |
| 1066 | - $value=price($value); |
|
| 1066 | + $value = price($value); |
|
| 1067 | 1067 | } |
| 1068 | - $out='<input type="text" class="flat '.$morecss.' maxwidthonsmartphone" name="'.$keyprefix.$key.$keysuffix.'" id="'.$keyprefix.$key.$keysuffix.'" value="'.$value.'" '.($moreparam?$moreparam:'').'> '; |
|
| 1068 | + $out = '<input type="text" class="flat '.$morecss.' maxwidthonsmartphone" name="'.$keyprefix.$key.$keysuffix.'" id="'.$keyprefix.$key.$keysuffix.'" value="'.$value.'" '.($moreparam ? $moreparam : '').'> '; |
|
| 1069 | 1069 | } |
| 1070 | 1070 | elseif ($type == 'select') |
| 1071 | 1071 | { |
| 1072 | 1072 | $out = ''; |
| 1073 | - if (! empty($conf->use_javascript_ajax) && ! empty($conf->global->MAIN_EXTRAFIELDS_USE_SELECT2)) |
|
| 1073 | + if (!empty($conf->use_javascript_ajax) && !empty($conf->global->MAIN_EXTRAFIELDS_USE_SELECT2)) |
|
| 1074 | 1074 | { |
| 1075 | - include_once DOL_DOCUMENT_ROOT . '/core/lib/ajax.lib.php'; |
|
| 1076 | - $out.= ajax_combobox($keyprefix.$key.$keysuffix, array(), 0); |
|
| 1075 | + include_once DOL_DOCUMENT_ROOT.'/core/lib/ajax.lib.php'; |
|
| 1076 | + $out .= ajax_combobox($keyprefix.$key.$keysuffix, array(), 0); |
|
| 1077 | 1077 | } |
| 1078 | 1078 | |
| 1079 | - $out.='<select class="flat '.$morecss.' maxwidthonsmartphone" name="'.$keyprefix.$key.$keysuffix.'" id="'.$keyprefix.$key.$keysuffix.'" '.($moreparam?$moreparam:'').'>'; |
|
| 1080 | - $out.='<option value="0"> </option>'; |
|
| 1079 | + $out .= '<select class="flat '.$morecss.' maxwidthonsmartphone" name="'.$keyprefix.$key.$keysuffix.'" id="'.$keyprefix.$key.$keysuffix.'" '.($moreparam ? $moreparam : '').'>'; |
|
| 1080 | + $out .= '<option value="0"> </option>'; |
|
| 1081 | 1081 | foreach ($param['options'] as $key => $val) |
| 1082 | 1082 | { |
| 1083 | 1083 | if ((string) $key == '') continue; |
| 1084 | 1084 | list($val, $parent) = explode('|', $val); |
| 1085 | - $out.='<option value="'.$key.'"'; |
|
| 1086 | - $out.= (((string) $value == (string) $key)?' selected':''); |
|
| 1087 | - $out.= (!empty($parent)?' parent="'.$parent.'"':''); |
|
| 1088 | - $out.='>'; |
|
| 1089 | - if ($langfile && $val) $out.=$langs->trans($val); |
|
| 1090 | - else $out.=$val; |
|
| 1091 | - $out.='</option>'; |
|
| 1085 | + $out .= '<option value="'.$key.'"'; |
|
| 1086 | + $out .= (((string) $value == (string) $key) ? ' selected' : ''); |
|
| 1087 | + $out .= (!empty($parent) ? ' parent="'.$parent.'"' : ''); |
|
| 1088 | + $out .= '>'; |
|
| 1089 | + if ($langfile && $val) $out .= $langs->trans($val); |
|
| 1090 | + else $out .= $val; |
|
| 1091 | + $out .= '</option>'; |
|
| 1092 | 1092 | } |
| 1093 | - $out.='</select>'; |
|
| 1093 | + $out .= '</select>'; |
|
| 1094 | 1094 | } |
| 1095 | 1095 | elseif ($type == 'sellist') |
| 1096 | 1096 | { |
| 1097 | 1097 | $out = ''; |
| 1098 | - if (! empty($conf->use_javascript_ajax) && ! empty($conf->global->MAIN_EXTRAFIELDS_USE_SELECT2)) |
|
| 1098 | + if (!empty($conf->use_javascript_ajax) && !empty($conf->global->MAIN_EXTRAFIELDS_USE_SELECT2)) |
|
| 1099 | 1099 | { |
| 1100 | - include_once DOL_DOCUMENT_ROOT . '/core/lib/ajax.lib.php'; |
|
| 1101 | - $out.= ajax_combobox($keyprefix.$key.$keysuffix, array(), 0); |
|
| 1100 | + include_once DOL_DOCUMENT_ROOT.'/core/lib/ajax.lib.php'; |
|
| 1101 | + $out .= ajax_combobox($keyprefix.$key.$keysuffix, array(), 0); |
|
| 1102 | 1102 | } |
| 1103 | 1103 | |
| 1104 | - $out.='<select class="flat '.$morecss.' maxwidthonsmartphone" name="'.$keyprefix.$key.$keysuffix.'" id="'.$keyprefix.$key.$keysuffix.'" '.($moreparam?$moreparam:'').'>'; |
|
| 1104 | + $out .= '<select class="flat '.$morecss.' maxwidthonsmartphone" name="'.$keyprefix.$key.$keysuffix.'" id="'.$keyprefix.$key.$keysuffix.'" '.($moreparam ? $moreparam : '').'>'; |
|
| 1105 | 1105 | if (is_array($param['options'])) |
| 1106 | 1106 | { |
| 1107 | - $param_list=array_keys($param['options']); |
|
| 1107 | + $param_list = array_keys($param['options']); |
|
| 1108 | 1108 | $InfoFieldList = explode(":", $param_list[0]); |
| 1109 | - $parentName=''; |
|
| 1110 | - $parentField=''; |
|
| 1109 | + $parentName = ''; |
|
| 1110 | + $parentField = ''; |
|
| 1111 | 1111 | // 0 : tableName |
| 1112 | 1112 | // 1 : label field name |
| 1113 | 1113 | // 2 : key fields name (if differ of rowid) |
| 1114 | 1114 | // 3 : key field parent (for dependent lists) |
| 1115 | 1115 | // 4 : where clause filter on column or table extrafield, syntax field='value' or extra.field=value |
| 1116 | - $keyList=(empty($InfoFieldList[2])?'rowid':$InfoFieldList[2].' as rowid'); |
|
| 1116 | + $keyList = (empty($InfoFieldList[2]) ? 'rowid' : $InfoFieldList[2].' as rowid'); |
|
| 1117 | 1117 | |
| 1118 | 1118 | |
| 1119 | - if (count($InfoFieldList) > 4 && ! empty($InfoFieldList[4])) |
|
| 1119 | + if (count($InfoFieldList) > 4 && !empty($InfoFieldList[4])) |
|
| 1120 | 1120 | { |
| 1121 | 1121 | if (strpos($InfoFieldList[4], 'extra.') !== false) |
| 1122 | 1122 | { |
| 1123 | - $keyList='main.'.$InfoFieldList[2].' as rowid'; |
|
| 1123 | + $keyList = 'main.'.$InfoFieldList[2].' as rowid'; |
|
| 1124 | 1124 | } else { |
| 1125 | - $keyList=$InfoFieldList[2].' as rowid'; |
|
| 1125 | + $keyList = $InfoFieldList[2].' as rowid'; |
|
| 1126 | 1126 | } |
| 1127 | 1127 | } |
| 1128 | - if (count($InfoFieldList) > 3 && ! empty($InfoFieldList[3])) |
|
| 1128 | + if (count($InfoFieldList) > 3 && !empty($InfoFieldList[3])) |
|
| 1129 | 1129 | { |
| 1130 | 1130 | list($parentName, $parentField) = explode('|', $InfoFieldList[3]); |
| 1131 | - $keyList.= ', '.$parentField; |
|
| 1131 | + $keyList .= ', '.$parentField; |
|
| 1132 | 1132 | } |
| 1133 | 1133 | |
| 1134 | - $fields_label = explode('|',$InfoFieldList[1]); |
|
| 1134 | + $fields_label = explode('|', $InfoFieldList[1]); |
|
| 1135 | 1135 | if (is_array($fields_label)) |
| 1136 | 1136 | { |
| 1137 | - $keyList .=', '; |
|
| 1137 | + $keyList .= ', '; |
|
| 1138 | 1138 | $keyList .= implode(', ', $fields_label); |
| 1139 | 1139 | } |
| 1140 | 1140 | |
| 1141 | - $sqlwhere=''; |
|
| 1141 | + $sqlwhere = ''; |
|
| 1142 | 1142 | $sql = 'SELECT '.$keyList; |
| 1143 | - $sql.= ' FROM '.MAIN_DB_PREFIX .$InfoFieldList[0]; |
|
| 1143 | + $sql .= ' FROM '.MAIN_DB_PREFIX.$InfoFieldList[0]; |
|
| 1144 | 1144 | if (!empty($InfoFieldList[4])) |
| 1145 | 1145 | { |
| 1146 | 1146 | // can use curent entity filter |
| 1147 | - if (strpos($InfoFieldList[4], '$ENTITY$')!==false) { |
|
| 1148 | - $InfoFieldList[4]=str_replace('$ENTITY$',$conf->entity,$InfoFieldList[4]); |
|
| 1147 | + if (strpos($InfoFieldList[4], '$ENTITY$') !== false) { |
|
| 1148 | + $InfoFieldList[4] = str_replace('$ENTITY$', $conf->entity, $InfoFieldList[4]); |
|
| 1149 | 1149 | } |
| 1150 | 1150 | // can use SELECT request |
| 1151 | - if (strpos($InfoFieldList[4], '$SEL$')!==false) { |
|
| 1152 | - $InfoFieldList[4]=str_replace('$SEL$','SELECT',$InfoFieldList[4]); |
|
| 1151 | + if (strpos($InfoFieldList[4], '$SEL$') !== false) { |
|
| 1152 | + $InfoFieldList[4] = str_replace('$SEL$', 'SELECT', $InfoFieldList[4]); |
|
| 1153 | 1153 | } |
| 1154 | 1154 | |
| 1155 | 1155 | // current object id can be use into filter |
| 1156 | - if (strpos($InfoFieldList[4], '$ID$')!==false && !empty($objectid)) { |
|
| 1157 | - $InfoFieldList[4]=str_replace('$ID$',$objectid,$InfoFieldList[4]); |
|
| 1156 | + if (strpos($InfoFieldList[4], '$ID$') !== false && !empty($objectid)) { |
|
| 1157 | + $InfoFieldList[4] = str_replace('$ID$', $objectid, $InfoFieldList[4]); |
|
| 1158 | 1158 | } else { |
| 1159 | - $InfoFieldList[4]=str_replace('$ID$','0',$InfoFieldList[4]); |
|
| 1159 | + $InfoFieldList[4] = str_replace('$ID$', '0', $InfoFieldList[4]); |
|
| 1160 | 1160 | } |
| 1161 | 1161 | //We have to join on extrafield table |
| 1162 | - if (strpos($InfoFieldList[4], 'extra')!==false) |
|
| 1162 | + if (strpos($InfoFieldList[4], 'extra') !== false) |
|
| 1163 | 1163 | { |
| 1164 | - $sql.= ' as main, '.MAIN_DB_PREFIX .$InfoFieldList[0].'_extrafields as extra'; |
|
| 1165 | - $sqlwhere.= ' WHERE extra.fk_object=main.'.$InfoFieldList[2]. ' AND '.$InfoFieldList[4]; |
|
| 1164 | + $sql .= ' as main, '.MAIN_DB_PREFIX.$InfoFieldList[0].'_extrafields as extra'; |
|
| 1165 | + $sqlwhere .= ' WHERE extra.fk_object=main.'.$InfoFieldList[2].' AND '.$InfoFieldList[4]; |
|
| 1166 | 1166 | } |
| 1167 | 1167 | else |
| 1168 | 1168 | { |
| 1169 | - $sqlwhere.= ' WHERE '.$InfoFieldList[4]; |
|
| 1169 | + $sqlwhere .= ' WHERE '.$InfoFieldList[4]; |
|
| 1170 | 1170 | } |
| 1171 | 1171 | } |
| 1172 | 1172 | else |
| 1173 | 1173 | { |
| 1174 | - $sqlwhere.= ' WHERE 1=1'; |
|
| 1174 | + $sqlwhere .= ' WHERE 1=1'; |
|
| 1175 | 1175 | } |
| 1176 | 1176 | // Some tables may have field, some other not. For the moment we disable it. |
| 1177 | - if (in_array($InfoFieldList[0],array('tablewithentity'))) |
|
| 1177 | + if (in_array($InfoFieldList[0], array('tablewithentity'))) |
|
| 1178 | 1178 | { |
| 1179 | - $sqlwhere.= ' AND entity = '.$conf->entity; |
|
| 1179 | + $sqlwhere .= ' AND entity = '.$conf->entity; |
|
| 1180 | 1180 | } |
| 1181 | - $sql.=$sqlwhere; |
|
| 1181 | + $sql .= $sqlwhere; |
|
| 1182 | 1182 | //print $sql; |
| 1183 | 1183 | |
| 1184 | - $sql .= ' ORDER BY ' . implode(', ', $fields_label); |
|
| 1184 | + $sql .= ' ORDER BY '.implode(', ', $fields_label); |
|
| 1185 | 1185 | |
| 1186 | 1186 | dol_syslog(get_class($this).'::showInputField type=sellist', LOG_DEBUG); |
| 1187 | 1187 | $resql = $this->db->query($sql); |
| 1188 | 1188 | if ($resql) |
| 1189 | 1189 | { |
| 1190 | - $out.='<option value="0"> </option>'; |
|
| 1190 | + $out .= '<option value="0"> </option>'; |
|
| 1191 | 1191 | $num = $this->db->num_rows($resql); |
| 1192 | 1192 | $i = 0; |
| 1193 | 1193 | while ($i < $num) |
| 1194 | 1194 | { |
| 1195 | - $labeltoshow=''; |
|
| 1195 | + $labeltoshow = ''; |
|
| 1196 | 1196 | $obj = $this->db->fetch_object($resql); |
| 1197 | 1197 | |
| 1198 | 1198 | // Several field into label (eq table:code|libelle:rowid) |
| 1199 | 1199 | $notrans = false; |
| 1200 | - $fields_label = explode('|',$InfoFieldList[1]); |
|
| 1200 | + $fields_label = explode('|', $InfoFieldList[1]); |
|
| 1201 | 1201 | if (is_array($fields_label)) |
| 1202 | 1202 | { |
| 1203 | 1203 | $notrans = true; |
| 1204 | 1204 | foreach ($fields_label as $field_toshow) |
| 1205 | 1205 | { |
| 1206 | - $labeltoshow.= $obj->$field_toshow.' '; |
|
| 1206 | + $labeltoshow .= $obj->$field_toshow.' '; |
|
| 1207 | 1207 | } |
| 1208 | 1208 | } |
| 1209 | 1209 | else |
| 1210 | 1210 | { |
| 1211 | - $labeltoshow=$obj->{$InfoFieldList[1]}; |
|
| 1211 | + $labeltoshow = $obj->{$InfoFieldList[1]}; |
|
| 1212 | 1212 | } |
| 1213 | - $labeltoshow=dol_trunc($labeltoshow,45); |
|
| 1213 | + $labeltoshow = dol_trunc($labeltoshow, 45); |
|
| 1214 | 1214 | |
| 1215 | 1215 | if ($value == $obj->rowid) |
| 1216 | 1216 | { |
| 1217 | 1217 | foreach ($fields_label as $field_toshow) |
| 1218 | 1218 | { |
| 1219 | - $translabel=$langs->trans($obj->$field_toshow); |
|
| 1220 | - if ($translabel!=$obj->$field_toshow) { |
|
| 1221 | - $labeltoshow=dol_trunc($translabel,18).' '; |
|
| 1222 | - }else { |
|
| 1223 | - $labeltoshow=dol_trunc($obj->$field_toshow,18).' '; |
|
| 1219 | + $translabel = $langs->trans($obj->$field_toshow); |
|
| 1220 | + if ($translabel != $obj->$field_toshow) { |
|
| 1221 | + $labeltoshow = dol_trunc($translabel, 18).' '; |
|
| 1222 | + } else { |
|
| 1223 | + $labeltoshow = dol_trunc($obj->$field_toshow, 18).' '; |
|
| 1224 | 1224 | } |
| 1225 | 1225 | } |
| 1226 | - $out.='<option value="'.$obj->rowid.'" selected>'.$labeltoshow.'</option>'; |
|
| 1226 | + $out .= '<option value="'.$obj->rowid.'" selected>'.$labeltoshow.'</option>'; |
|
| 1227 | 1227 | } |
| 1228 | 1228 | else |
| 1229 | 1229 | { |
| 1230 | - if (! $notrans) |
|
| 1230 | + if (!$notrans) |
|
| 1231 | 1231 | { |
| 1232 | - $translabel=$langs->trans($obj->{$InfoFieldList[1]}); |
|
| 1233 | - if ($translabel!=$obj->{$InfoFieldList[1]}) { |
|
| 1234 | - $labeltoshow=dol_trunc($translabel,18); |
|
| 1232 | + $translabel = $langs->trans($obj->{$InfoFieldList[1]}); |
|
| 1233 | + if ($translabel != $obj->{$InfoFieldList[1]}) { |
|
| 1234 | + $labeltoshow = dol_trunc($translabel, 18); |
|
| 1235 | 1235 | } |
| 1236 | 1236 | else { |
| 1237 | - $labeltoshow=dol_trunc($obj->{$InfoFieldList[1]},18); |
|
| 1237 | + $labeltoshow = dol_trunc($obj->{$InfoFieldList[1]},18); |
|
| 1238 | 1238 | } |
| 1239 | 1239 | } |
| 1240 | - if (empty($labeltoshow)) $labeltoshow='(not defined)'; |
|
| 1241 | - if ($value==$obj->rowid) |
|
| 1240 | + if (empty($labeltoshow)) $labeltoshow = '(not defined)'; |
|
| 1241 | + if ($value == $obj->rowid) |
|
| 1242 | 1242 | { |
| 1243 | - $out.='<option value="'.$obj->rowid.'" selected>'.$labeltoshow.'</option>'; |
|
| 1243 | + $out .= '<option value="'.$obj->rowid.'" selected>'.$labeltoshow.'</option>'; |
|
| 1244 | 1244 | } |
| 1245 | 1245 | |
| 1246 | 1246 | if (!empty($InfoFieldList[3]) && $parentField) |
@@ -1248,10 +1248,10 @@ discard block |
||
| 1248 | 1248 | $parent = $parentName.':'.$obj->{$parentField}; |
| 1249 | 1249 | } |
| 1250 | 1250 | |
| 1251 | - $out.='<option value="'.$obj->rowid.'"'; |
|
| 1252 | - $out.= ($value==$obj->rowid?' selected':''); |
|
| 1253 | - $out.= (!empty($parent)?' parent="'.$parent.'"':''); |
|
| 1254 | - $out.='>'.$labeltoshow.'</option>'; |
|
| 1251 | + $out .= '<option value="'.$obj->rowid.'"'; |
|
| 1252 | + $out .= ($value == $obj->rowid ? ' selected' : ''); |
|
| 1253 | + $out .= (!empty($parent) ? ' parent="'.$parent.'"' : ''); |
|
| 1254 | + $out .= '>'.$labeltoshow.'</option>'; |
|
| 1255 | 1255 | } |
| 1256 | 1256 | |
| 1257 | 1257 | $i++; |
@@ -1262,23 +1262,23 @@ discard block |
||
| 1262 | 1262 | print 'Error in request '.$sql.' '.$this->db->lasterror().'. Check setup of extra parameters.<br>'; |
| 1263 | 1263 | } |
| 1264 | 1264 | } |
| 1265 | - $out.='</select>'; |
|
| 1265 | + $out .= '</select>'; |
|
| 1266 | 1266 | } |
| 1267 | 1267 | elseif ($type == 'checkbox') |
| 1268 | 1268 | { |
| 1269 | - $value_arr=explode(',',$value); |
|
| 1270 | - $out=$form->multiselectarray($keyprefix.$key.$keysuffix, (empty($param['options'])?null:$param['options']), $value_arr, '', 0, '', 0, '100%'); |
|
| 1269 | + $value_arr = explode(',', $value); |
|
| 1270 | + $out = $form->multiselectarray($keyprefix.$key.$keysuffix, (empty($param['options']) ?null:$param['options']), $value_arr, '', 0, '', 0, '100%'); |
|
| 1271 | 1271 | } |
| 1272 | 1272 | elseif ($type == 'radio') |
| 1273 | 1273 | { |
| 1274 | - $out=''; |
|
| 1274 | + $out = ''; |
|
| 1275 | 1275 | foreach ($param['options'] as $keyopt => $val) |
| 1276 | 1276 | { |
| 1277 | - $out.='<input class="flat '.$morecss.'" type="radio" name="'.$keyprefix.$key.$keysuffix.'" id="'.$keyprefix.$key.$keysuffix.'" '.($moreparam?$moreparam:''); |
|
| 1278 | - $out.=' value="'.$keyopt.'"'; |
|
| 1279 | - $out.=' id="'.$keyprefix.$key.$keysuffix.'_'.$keyopt.'"'; |
|
| 1280 | - $out.= ($value==$keyopt?'checked':''); |
|
| 1281 | - $out.='/><label for="'.$keyprefix.$key.$keysuffix.'_'.$keyopt.'">'.$val.'</label><br>'; |
|
| 1277 | + $out .= '<input class="flat '.$morecss.'" type="radio" name="'.$keyprefix.$key.$keysuffix.'" id="'.$keyprefix.$key.$keysuffix.'" '.($moreparam ? $moreparam : ''); |
|
| 1278 | + $out .= ' value="'.$keyopt.'"'; |
|
| 1279 | + $out .= ' id="'.$keyprefix.$key.$keysuffix.'_'.$keyopt.'"'; |
|
| 1280 | + $out .= ($value == $keyopt ? 'checked' : ''); |
|
| 1281 | + $out .= '/><label for="'.$keyprefix.$key.$keysuffix.'_'.$keyopt.'">'.$val.'</label><br>'; |
|
| 1282 | 1282 | } |
| 1283 | 1283 | } |
| 1284 | 1284 | elseif ($type == 'chkbxlst') |
@@ -1293,24 +1293,24 @@ discard block |
||
| 1293 | 1293 | if (is_array($param['options'])) { |
| 1294 | 1294 | $param_list = array_keys($param['options']); |
| 1295 | 1295 | $InfoFieldList = explode(":", $param_list[0]); |
| 1296 | - $parentName=''; |
|
| 1297 | - $parentField=''; |
|
| 1296 | + $parentName = ''; |
|
| 1297 | + $parentField = ''; |
|
| 1298 | 1298 | // 0 : tableName |
| 1299 | 1299 | // 1 : label field name |
| 1300 | 1300 | // 2 : key fields name (if differ of rowid) |
| 1301 | 1301 | // 3 : key field parent (for dependent lists) |
| 1302 | 1302 | // 4 : where clause filter on column or table extrafield, syntax field='value' or extra.field=value |
| 1303 | - $keyList = (empty($InfoFieldList[2]) ? 'rowid' : $InfoFieldList[2] . ' as rowid'); |
|
| 1303 | + $keyList = (empty($InfoFieldList[2]) ? 'rowid' : $InfoFieldList[2].' as rowid'); |
|
| 1304 | 1304 | |
| 1305 | - if (count($InfoFieldList) > 3 && ! empty($InfoFieldList[3])) { |
|
| 1306 | - list ( $parentName, $parentField ) = explode('|', $InfoFieldList[3]); |
|
| 1307 | - $keyList .= ', ' . $parentField; |
|
| 1305 | + if (count($InfoFieldList) > 3 && !empty($InfoFieldList[3])) { |
|
| 1306 | + list ($parentName, $parentField) = explode('|', $InfoFieldList[3]); |
|
| 1307 | + $keyList .= ', '.$parentField; |
|
| 1308 | 1308 | } |
| 1309 | - if (count($InfoFieldList) > 4 && ! empty($InfoFieldList[4])) { |
|
| 1309 | + if (count($InfoFieldList) > 4 && !empty($InfoFieldList[4])) { |
|
| 1310 | 1310 | if (strpos($InfoFieldList[4], 'extra.') !== false) { |
| 1311 | - $keyList = 'main.' . $InfoFieldList[2] . ' as rowid'; |
|
| 1311 | + $keyList = 'main.'.$InfoFieldList[2].' as rowid'; |
|
| 1312 | 1312 | } else { |
| 1313 | - $keyList = $InfoFieldList[2] . ' as rowid'; |
|
| 1313 | + $keyList = $InfoFieldList[2].' as rowid'; |
|
| 1314 | 1314 | } |
| 1315 | 1315 | } |
| 1316 | 1316 | |
@@ -1321,59 +1321,59 @@ discard block |
||
| 1321 | 1321 | } |
| 1322 | 1322 | |
| 1323 | 1323 | $sqlwhere = ''; |
| 1324 | - $sql = 'SELECT ' . $keyList; |
|
| 1325 | - $sql .= ' FROM ' . MAIN_DB_PREFIX . $InfoFieldList[0]; |
|
| 1326 | - if (! empty($InfoFieldList[4])) { |
|
| 1324 | + $sql = 'SELECT '.$keyList; |
|
| 1325 | + $sql .= ' FROM '.MAIN_DB_PREFIX.$InfoFieldList[0]; |
|
| 1326 | + if (!empty($InfoFieldList[4])) { |
|
| 1327 | 1327 | |
| 1328 | 1328 | // can use SELECT request |
| 1329 | - if (strpos($InfoFieldList[4], '$SEL$')!==false) { |
|
| 1330 | - $InfoFieldList[4]=str_replace('$SEL$','SELECT',$InfoFieldList[4]); |
|
| 1329 | + if (strpos($InfoFieldList[4], '$SEL$') !== false) { |
|
| 1330 | + $InfoFieldList[4] = str_replace('$SEL$', 'SELECT', $InfoFieldList[4]); |
|
| 1331 | 1331 | } |
| 1332 | 1332 | |
| 1333 | 1333 | // current object id can be use into filter |
| 1334 | - if (strpos($InfoFieldList[4], '$ID$')!==false && !empty($objectid)) { |
|
| 1335 | - $InfoFieldList[4]=str_replace('$ID$',$objectid,$InfoFieldList[4]); |
|
| 1336 | - } else if (preg_match("#^.*list.php$#",$_SERVER["DOCUMENT_URI"])) { |
|
| 1334 | + if (strpos($InfoFieldList[4], '$ID$') !== false && !empty($objectid)) { |
|
| 1335 | + $InfoFieldList[4] = str_replace('$ID$', $objectid, $InfoFieldList[4]); |
|
| 1336 | + } else if (preg_match("#^.*list.php$#", $_SERVER["DOCUMENT_URI"])) { |
|
| 1337 | 1337 | // Pattern for word=$ID$ |
| 1338 | 1338 | $word = '\b[a-zA-Z0-9-\.-_]+\b=\$ID\$'; |
| 1339 | 1339 | |
| 1340 | 1340 | // Removing space arount =, ( and ) |
| 1341 | - $InfoFieldList[4]=preg_replace('# *(=|\(|\)) *#','$1', $InfoFieldList[4]); |
|
| 1341 | + $InfoFieldList[4] = preg_replace('# *(=|\(|\)) *#', '$1', $InfoFieldList[4]); |
|
| 1342 | 1342 | |
| 1343 | 1343 | $nbPreg = 1; |
| 1344 | 1344 | // While we have parenthesis |
| 1345 | - while ($nbPreg!=0) { |
|
| 1345 | + while ($nbPreg != 0) { |
|
| 1346 | 1346 | // Init des compteurs |
| 1347 | 1347 | $nbPregRepl = $nbPregSel = 0; |
| 1348 | 1348 | // On retire toutes les parenthèses sans = avant |
| 1349 | - $InfoFieldList[4]=preg_replace( '#([^=])(\([^)^(]*(' . $word . ')[^)^(]*\))#','$1 $3 ',$InfoFieldList[4],-1,$nbPregRepl); |
|
| 1349 | + $InfoFieldList[4] = preg_replace('#([^=])(\([^)^(]*('.$word.')[^)^(]*\))#', '$1 $3 ', $InfoFieldList[4], -1, $nbPregRepl); |
|
| 1350 | 1350 | // On retire les espaces autour des = et parenthèses |
| 1351 | - $InfoFieldList[4]=preg_replace('# *(=|\(|\)) *#','$1', $InfoFieldList[4]); |
|
| 1351 | + $InfoFieldList[4] = preg_replace('# *(=|\(|\)) *#', '$1', $InfoFieldList[4]); |
|
| 1352 | 1352 | // On retire toutes les parenthèses avec = avant |
| 1353 | - $InfoFieldList[4]=preg_replace( '#\b[a-zA-Z0-9-\.-_]+\b=\([^)^(]*(' . $word . ')[^)^(]*\)#','$1 ',$InfoFieldList[4], -1, $nbPregSel); |
|
| 1353 | + $InfoFieldList[4] = preg_replace('#\b[a-zA-Z0-9-\.-_]+\b=\([^)^(]*('.$word.')[^)^(]*\)#', '$1 ', $InfoFieldList[4], -1, $nbPregSel); |
|
| 1354 | 1354 | // On retire les espaces autour des = et parenthèses |
| 1355 | - $InfoFieldList[4]=preg_replace('# *(=|\(|\)) *#','$1', $InfoFieldList[4]); |
|
| 1355 | + $InfoFieldList[4] = preg_replace('# *(=|\(|\)) *#', '$1', $InfoFieldList[4]); |
|
| 1356 | 1356 | |
| 1357 | 1357 | // Calcul du compteur général pour la boucle |
| 1358 | 1358 | $nbPreg = $nbPregRepl + $nbPregSel; |
| 1359 | 1359 | } |
| 1360 | 1360 | |
| 1361 | 1361 | // Si l'on a un AND ou un OR, avant ou après |
| 1362 | - preg_match('#(AND|OR|) *('.$word.') *(AND|OR|)#',$InfoFieldList[4],$matchCondition); |
|
| 1363 | - while(!empty($matchCondition[0])) { |
|
| 1362 | + preg_match('#(AND|OR|) *('.$word.') *(AND|OR|)#', $InfoFieldList[4], $matchCondition); |
|
| 1363 | + while (!empty($matchCondition[0])) { |
|
| 1364 | 1364 | // If the two sides differ but are not empty |
| 1365 | - if (! empty($matchCondition[1]) && ! empty($matchCondition[3]) && $matchCondition[1] != $matchCondition[3] ) { |
|
| 1365 | + if (!empty($matchCondition[1]) && !empty($matchCondition[3]) && $matchCondition[1] != $matchCondition[3]) { |
|
| 1366 | 1366 | // Nobody sain would do that without parentheses |
| 1367 | - $InfoFieldList[4]=str_replace('$ID$','0',$InfoFieldList[4]); |
|
| 1367 | + $InfoFieldList[4] = str_replace('$ID$', '0', $InfoFieldList[4]); |
|
| 1368 | 1368 | } |
| 1369 | 1369 | else { |
| 1370 | - if (! empty($matchCondition[1])) { |
|
| 1371 | - $boolCond =(( $matchCondition[1] == "AND" )?' AND 1 ':' OR 0 '); |
|
| 1372 | - $InfoFieldList[4]=str_replace($matchCondition[0],$boolCond.$matchCondition[3],$InfoFieldList[4]); |
|
| 1370 | + if (!empty($matchCondition[1])) { |
|
| 1371 | + $boolCond = (($matchCondition[1] == "AND") ? ' AND 1 ' : ' OR 0 '); |
|
| 1372 | + $InfoFieldList[4] = str_replace($matchCondition[0], $boolCond.$matchCondition[3], $InfoFieldList[4]); |
|
| 1373 | 1373 | } |
| 1374 | - else if (! empty($matchCondition[3])) { |
|
| 1375 | - $boolCond =(( $matchCondition[3] == "AND" )?' 1 AND ':' 0 OR'); |
|
| 1376 | - $InfoFieldList[4]=str_replace($matchCondition[0],$boolCond,$InfoFieldList[4]); |
|
| 1374 | + else if (!empty($matchCondition[3])) { |
|
| 1375 | + $boolCond = (($matchCondition[3] == "AND") ? ' 1 AND ' : ' 0 OR'); |
|
| 1376 | + $InfoFieldList[4] = str_replace($matchCondition[0], $boolCond, $InfoFieldList[4]); |
|
| 1377 | 1377 | } |
| 1378 | 1378 | else { |
| 1379 | 1379 | $InfoFieldList[4] = 1; |
@@ -1381,41 +1381,41 @@ discard block |
||
| 1381 | 1381 | } |
| 1382 | 1382 | |
| 1383 | 1383 | // Si l'on a un AND ou un OR, avant ou après |
| 1384 | - preg_match('#(AND|OR|) *('.$word.') *(AND|OR|)#',$InfoFieldList[4],$matchCondition); |
|
| 1384 | + preg_match('#(AND|OR|) *('.$word.') *(AND|OR|)#', $InfoFieldList[4], $matchCondition); |
|
| 1385 | 1385 | } |
| 1386 | 1386 | } |
| 1387 | 1387 | else { |
| 1388 | - $InfoFieldList[4]=str_replace('$ID$','0',$InfoFieldList[4]); |
|
| 1388 | + $InfoFieldList[4] = str_replace('$ID$', '0', $InfoFieldList[4]); |
|
| 1389 | 1389 | } |
| 1390 | 1390 | |
| 1391 | 1391 | // We have to join on extrafield table |
| 1392 | 1392 | if (strpos($InfoFieldList[4], 'extra') !== false) { |
| 1393 | - $sql .= ' as main, ' . MAIN_DB_PREFIX . $InfoFieldList[0] . '_extrafields as extra'; |
|
| 1394 | - $sqlwhere .= ' WHERE extra.fk_object=main.' . $InfoFieldList[2] . ' AND ' . $InfoFieldList[4]; |
|
| 1393 | + $sql .= ' as main, '.MAIN_DB_PREFIX.$InfoFieldList[0].'_extrafields as extra'; |
|
| 1394 | + $sqlwhere .= ' WHERE extra.fk_object=main.'.$InfoFieldList[2].' AND '.$InfoFieldList[4]; |
|
| 1395 | 1395 | } else { |
| 1396 | - $sqlwhere .= ' WHERE ' . $InfoFieldList[4]; |
|
| 1396 | + $sqlwhere .= ' WHERE '.$InfoFieldList[4]; |
|
| 1397 | 1397 | } |
| 1398 | 1398 | } else { |
| 1399 | 1399 | $sqlwhere .= ' WHERE 1=1'; |
| 1400 | 1400 | } |
| 1401 | 1401 | // Some tables may have field, some other not. For the moment we disable it. |
| 1402 | - if (in_array($InfoFieldList[0], array ('tablewithentity'))) |
|
| 1402 | + if (in_array($InfoFieldList[0], array('tablewithentity'))) |
|
| 1403 | 1403 | { |
| 1404 | - $sqlwhere .= ' AND entity = ' . $conf->entity; |
|
| 1404 | + $sqlwhere .= ' AND entity = '.$conf->entity; |
|
| 1405 | 1405 | } |
| 1406 | 1406 | // $sql.=preg_replace('/^ AND /','',$sqlwhere); |
| 1407 | 1407 | // print $sql; |
| 1408 | 1408 | |
| 1409 | 1409 | $sql .= $sqlwhere; |
| 1410 | - dol_syslog(get_class($this) . '::showInputField type=chkbxlst',LOG_DEBUG); |
|
| 1410 | + dol_syslog(get_class($this).'::showInputField type=chkbxlst', LOG_DEBUG); |
|
| 1411 | 1411 | $resql = $this->db->query($sql); |
| 1412 | 1412 | if ($resql) { |
| 1413 | 1413 | $num = $this->db->num_rows($resql); |
| 1414 | 1414 | $i = 0; |
| 1415 | 1415 | |
| 1416 | - $data=array(); |
|
| 1416 | + $data = array(); |
|
| 1417 | 1417 | |
| 1418 | - while ( $i < $num ) { |
|
| 1418 | + while ($i < $num) { |
|
| 1419 | 1419 | $labeltoshow = ''; |
| 1420 | 1420 | $obj = $this->db->fetch_object($resql); |
| 1421 | 1421 | |
@@ -1424,8 +1424,8 @@ discard block |
||
| 1424 | 1424 | $fields_label = explode('|', $InfoFieldList[1]); |
| 1425 | 1425 | if (is_array($fields_label)) { |
| 1426 | 1426 | $notrans = true; |
| 1427 | - foreach ( $fields_label as $field_toshow ) { |
|
| 1428 | - $labeltoshow .= $obj->$field_toshow . ' '; |
|
| 1427 | + foreach ($fields_label as $field_toshow) { |
|
| 1428 | + $labeltoshow .= $obj->$field_toshow.' '; |
|
| 1429 | 1429 | } |
| 1430 | 1430 | } else { |
| 1431 | 1431 | $labeltoshow = $obj->{$InfoFieldList[1]}; |
@@ -1433,18 +1433,18 @@ discard block |
||
| 1433 | 1433 | $labeltoshow = dol_trunc($labeltoshow, 45); |
| 1434 | 1434 | |
| 1435 | 1435 | if (is_array($value_arr) && in_array($obj->rowid, $value_arr)) { |
| 1436 | - foreach ( $fields_label as $field_toshow ) { |
|
| 1436 | + foreach ($fields_label as $field_toshow) { |
|
| 1437 | 1437 | $translabel = $langs->trans($obj->$field_toshow); |
| 1438 | 1438 | if ($translabel != $obj->$field_toshow) { |
| 1439 | - $labeltoshow = dol_trunc($translabel, 18) . ' '; |
|
| 1439 | + $labeltoshow = dol_trunc($translabel, 18).' '; |
|
| 1440 | 1440 | } else { |
| 1441 | - $labeltoshow = dol_trunc($obj->$field_toshow, 18) . ' '; |
|
| 1441 | + $labeltoshow = dol_trunc($obj->$field_toshow, 18).' '; |
|
| 1442 | 1442 | } |
| 1443 | 1443 | } |
| 1444 | 1444 | |
| 1445 | - $data[$obj->rowid]=$labeltoshow; |
|
| 1445 | + $data[$obj->rowid] = $labeltoshow; |
|
| 1446 | 1446 | } else { |
| 1447 | - if (! $notrans) { |
|
| 1447 | + if (!$notrans) { |
|
| 1448 | 1448 | $translabel = $langs->trans($obj->{$InfoFieldList[1]}); |
| 1449 | 1449 | if ($translabel != $obj->{$InfoFieldList[1]}) { |
| 1450 | 1450 | $labeltoshow = dol_trunc($translabel, 18); |
@@ -1456,40 +1456,40 @@ discard block |
||
| 1456 | 1456 | $labeltoshow = '(not defined)'; |
| 1457 | 1457 | |
| 1458 | 1458 | if (is_array($value_arr) && in_array($obj->rowid, $value_arr)) { |
| 1459 | - $data[$obj->rowid]=$labeltoshow; |
|
| 1459 | + $data[$obj->rowid] = $labeltoshow; |
|
| 1460 | 1460 | } |
| 1461 | 1461 | |
| 1462 | - if (! empty($InfoFieldList[3]) && $parentField) { |
|
| 1463 | - $parent = $parentName . ':' . $obj->{$parentField}; |
|
| 1462 | + if (!empty($InfoFieldList[3]) && $parentField) { |
|
| 1463 | + $parent = $parentName.':'.$obj->{$parentField}; |
|
| 1464 | 1464 | } |
| 1465 | 1465 | |
| 1466 | - $data[$obj->rowid]=$labeltoshow; |
|
| 1466 | + $data[$obj->rowid] = $labeltoshow; |
|
| 1467 | 1467 | } |
| 1468 | 1468 | |
| 1469 | - $i ++; |
|
| 1469 | + $i++; |
|
| 1470 | 1470 | } |
| 1471 | 1471 | $this->db->free($resql); |
| 1472 | 1472 | |
| 1473 | - $out=$form->multiselectarray($keyprefix.$key.$keysuffix, $data, $value_arr, '', 0, '', 0, '100%'); |
|
| 1473 | + $out = $form->multiselectarray($keyprefix.$key.$keysuffix, $data, $value_arr, '', 0, '', 0, '100%'); |
|
| 1474 | 1474 | } else { |
| 1475 | - print 'Error in request ' . $sql . ' ' . $this->db->lasterror() . '. Check setup of extra parameters.<br>'; |
|
| 1475 | + print 'Error in request '.$sql.' '.$this->db->lasterror().'. Check setup of extra parameters.<br>'; |
|
| 1476 | 1476 | } |
| 1477 | 1477 | } |
| 1478 | 1478 | } |
| 1479 | 1479 | elseif ($type == 'link') |
| 1480 | 1480 | { |
| 1481 | - $param_list=array_keys($param['options']); // $param_list='ObjectName:classPath' |
|
| 1482 | - $showempty=(($required && $default != '')?0:1); |
|
| 1483 | - $out=$form->selectForForms($param_list[0], $keyprefix.$key.$keysuffix, $value, $showempty); |
|
| 1481 | + $param_list = array_keys($param['options']); // $param_list='ObjectName:classPath' |
|
| 1482 | + $showempty = (($required && $default != '') ? 0 : 1); |
|
| 1483 | + $out = $form->selectForForms($param_list[0], $keyprefix.$key.$keysuffix, $value, $showempty); |
|
| 1484 | 1484 | } |
| 1485 | 1485 | elseif ($type == 'password') |
| 1486 | 1486 | { |
| 1487 | 1487 | // If prefix is 'search_', field is used as a filter, we use a common text field. |
| 1488 | - $out='<input style="display:none" type="text" name="fakeusernameremembered">'; // Hidden field to reduce impact of evil Google Chrome autopopulate bug. |
|
| 1489 | - $out.='<input autocomplete="new-password" type="'.($keyprefix=='search_'?'text':'password').'" class="flat '.$morecss.'" name="'.$keyprefix.$key.$keysuffix.'" id="'.$keyprefix.$key.$keysuffix.'" value="'.$value.'" '.($moreparam?$moreparam:'').'>'; |
|
| 1488 | + $out = '<input style="display:none" type="text" name="fakeusernameremembered">'; // Hidden field to reduce impact of evil Google Chrome autopopulate bug. |
|
| 1489 | + $out .= '<input autocomplete="new-password" type="'.($keyprefix == 'search_' ? 'text' : 'password').'" class="flat '.$morecss.'" name="'.$keyprefix.$key.$keysuffix.'" id="'.$keyprefix.$key.$keysuffix.'" value="'.$value.'" '.($moreparam ? $moreparam : '').'>'; |
|
| 1490 | 1490 | } |
| 1491 | 1491 | if (!empty($hidden)) { |
| 1492 | - $out='<input type="hidden" value="'.$value.'" name="'.$keyprefix.$key.$keysuffix.'" id="'.$keyprefix.$key.$keysuffix.'"/>'; |
|
| 1492 | + $out = '<input type="hidden" value="'.$value.'" name="'.$keyprefix.$key.$keysuffix.'" id="'.$keyprefix.$key.$keysuffix.'"/>'; |
|
| 1493 | 1493 | } |
| 1494 | 1494 | /* Add comments |
| 1495 | 1495 | if ($type == 'date') $out.=' (YYYY-MM-DD)'; |
@@ -1508,44 +1508,44 @@ discard block |
||
| 1508 | 1508 | * @param string $extrafieldsobjectkey If defined (for example $object->table_element), use the new method to get extrafields data |
| 1509 | 1509 | * @return string Formated value |
| 1510 | 1510 | */ |
| 1511 | - function showOutputField($key, $value, $moreparam='', $extrafieldsobjectkey='') |
|
| 1511 | + function showOutputField($key, $value, $moreparam = '', $extrafieldsobjectkey = '') |
|
| 1512 | 1512 | { |
| 1513 | - global $conf,$langs; |
|
| 1514 | - |
|
| 1515 | - if (! empty($extrafieldsobjectkey)) |
|
| 1516 | - { |
|
| 1517 | - $label=$this->attributes[$extrafieldsobjectkey]['label'][$key]; |
|
| 1518 | - $type=$this->attributes[$extrafieldsobjectkey]['type'][$key]; |
|
| 1519 | - $size=$this->attributes[$extrafieldsobjectkey]['size'][$key]; |
|
| 1520 | - $default=$this->attributes[$extrafieldsobjectkey]['default'][$key]; |
|
| 1521 | - $computed=$this->attributes[$extrafieldsobjectkey]['computed'][$key]; |
|
| 1522 | - $unique=$this->attributes[$extrafieldsobjectkey]['unique'][$key]; |
|
| 1523 | - $required=$this->attributes[$extrafieldsobjectkey]['required'][$key]; |
|
| 1524 | - $param=$this->attributes[$extrafieldsobjectkey]['param'][$key]; |
|
| 1525 | - $perms=dol_eval($this->attributes[$extrafieldsobjectkey]['perms'][$key], 1); |
|
| 1526 | - $langfile=$this->attributes[$extrafieldsobjectkey]['langfile'][$key]; |
|
| 1527 | - $list=dol_eval($this->attributes[$extrafieldsobjectkey]['list'][$key], 1); |
|
| 1528 | - $help=$this->attributes[$extrafieldsobjectkey]['help'][$key]; |
|
| 1529 | - $hidden=(empty($list) ? 1 : 0); // If $list empty, we are sure it is hidden, otherwise we show. If it depends on mode (view/create/edit form or list, this must be filtered by caller) |
|
| 1513 | + global $conf, $langs; |
|
| 1514 | + |
|
| 1515 | + if (!empty($extrafieldsobjectkey)) |
|
| 1516 | + { |
|
| 1517 | + $label = $this->attributes[$extrafieldsobjectkey]['label'][$key]; |
|
| 1518 | + $type = $this->attributes[$extrafieldsobjectkey]['type'][$key]; |
|
| 1519 | + $size = $this->attributes[$extrafieldsobjectkey]['size'][$key]; |
|
| 1520 | + $default = $this->attributes[$extrafieldsobjectkey]['default'][$key]; |
|
| 1521 | + $computed = $this->attributes[$extrafieldsobjectkey]['computed'][$key]; |
|
| 1522 | + $unique = $this->attributes[$extrafieldsobjectkey]['unique'][$key]; |
|
| 1523 | + $required = $this->attributes[$extrafieldsobjectkey]['required'][$key]; |
|
| 1524 | + $param = $this->attributes[$extrafieldsobjectkey]['param'][$key]; |
|
| 1525 | + $perms = dol_eval($this->attributes[$extrafieldsobjectkey]['perms'][$key], 1); |
|
| 1526 | + $langfile = $this->attributes[$extrafieldsobjectkey]['langfile'][$key]; |
|
| 1527 | + $list = dol_eval($this->attributes[$extrafieldsobjectkey]['list'][$key], 1); |
|
| 1528 | + $help = $this->attributes[$extrafieldsobjectkey]['help'][$key]; |
|
| 1529 | + $hidden = (empty($list) ? 1 : 0); // If $list empty, we are sure it is hidden, otherwise we show. If it depends on mode (view/create/edit form or list, this must be filtered by caller) |
|
| 1530 | 1530 | } |
| 1531 | 1531 | else // Old usage |
| 1532 | 1532 | { |
| 1533 | - $label=$this->attribute_label[$key]; |
|
| 1534 | - $type=$this->attribute_type[$key]; |
|
| 1535 | - $size=$this->attribute_size[$key]; |
|
| 1536 | - $default=$this->attribute_default[$key]; |
|
| 1537 | - $computed=$this->attribute_computed[$key]; |
|
| 1538 | - $unique=$this->attribute_unique[$key]; |
|
| 1539 | - $required=$this->attribute_required[$key]; |
|
| 1540 | - $param=$this->attribute_param[$key]; |
|
| 1541 | - $perms=dol_eval($this->attribute_perms[$key], 1); |
|
| 1542 | - $langfile=$this->attribute_langfile[$key]; |
|
| 1543 | - $list=dol_eval($this->attribute_list[$key], 1); |
|
| 1544 | - $help=''; // Not supported with old syntax |
|
| 1545 | - $hidden=(empty($list) ? 1 : 0); // If $list empty, we are sure it is hidden, otherwise we show. If it depends on mode (view/create/edit form or list, this must be filtered by caller) |
|
| 1533 | + $label = $this->attribute_label[$key]; |
|
| 1534 | + $type = $this->attribute_type[$key]; |
|
| 1535 | + $size = $this->attribute_size[$key]; |
|
| 1536 | + $default = $this->attribute_default[$key]; |
|
| 1537 | + $computed = $this->attribute_computed[$key]; |
|
| 1538 | + $unique = $this->attribute_unique[$key]; |
|
| 1539 | + $required = $this->attribute_required[$key]; |
|
| 1540 | + $param = $this->attribute_param[$key]; |
|
| 1541 | + $perms = dol_eval($this->attribute_perms[$key], 1); |
|
| 1542 | + $langfile = $this->attribute_langfile[$key]; |
|
| 1543 | + $list = dol_eval($this->attribute_list[$key], 1); |
|
| 1544 | + $help = ''; // Not supported with old syntax |
|
| 1545 | + $hidden = (empty($list) ? 1 : 0); // If $list empty, we are sure it is hidden, otherwise we show. If it depends on mode (view/create/edit form or list, this must be filtered by caller) |
|
| 1546 | 1546 | } |
| 1547 | 1547 | |
| 1548 | - if ($hidden) return ''; // This is a protection. If field is hidden, we should just not call this method. |
|
| 1548 | + if ($hidden) return ''; // This is a protection. If field is hidden, we should just not call this method. |
|
| 1549 | 1549 | |
| 1550 | 1550 | // If field is a computed field, value must become result of compute |
| 1551 | 1551 | if ($computed) |
@@ -1555,88 +1555,88 @@ discard block |
||
| 1555 | 1555 | $value = dol_eval($computed, 1, 0); |
| 1556 | 1556 | } |
| 1557 | 1557 | |
| 1558 | - $showsize=0; |
|
| 1558 | + $showsize = 0; |
|
| 1559 | 1559 | if ($type == 'date') |
| 1560 | 1560 | { |
| 1561 | - $showsize=10; |
|
| 1562 | - $value=dol_print_date($value, 'day'); |
|
| 1561 | + $showsize = 10; |
|
| 1562 | + $value = dol_print_date($value, 'day'); |
|
| 1563 | 1563 | } |
| 1564 | 1564 | elseif ($type == 'datetime') |
| 1565 | 1565 | { |
| 1566 | - $showsize=19; |
|
| 1567 | - $value=dol_print_date($value, 'dayhour'); |
|
| 1566 | + $showsize = 19; |
|
| 1567 | + $value = dol_print_date($value, 'dayhour'); |
|
| 1568 | 1568 | } |
| 1569 | 1569 | elseif ($type == 'int') |
| 1570 | 1570 | { |
| 1571 | - $showsize=10; |
|
| 1571 | + $showsize = 10; |
|
| 1572 | 1572 | } |
| 1573 | 1573 | elseif ($type == 'double') |
| 1574 | 1574 | { |
| 1575 | 1575 | if (!empty($value)) { |
| 1576 | - $value=price($value); |
|
| 1576 | + $value = price($value); |
|
| 1577 | 1577 | } |
| 1578 | 1578 | } |
| 1579 | 1579 | elseif ($type == 'boolean') |
| 1580 | 1580 | { |
| 1581 | - $checked=''; |
|
| 1581 | + $checked = ''; |
|
| 1582 | 1582 | if (!empty($value)) { |
| 1583 | - $checked=' checked '; |
|
| 1583 | + $checked = ' checked '; |
|
| 1584 | 1584 | } |
| 1585 | - $value='<input type="checkbox" '.$checked.' '.($moreparam?$moreparam:'').' readonly disabled>'; |
|
| 1585 | + $value = '<input type="checkbox" '.$checked.' '.($moreparam ? $moreparam : '').' readonly disabled>'; |
|
| 1586 | 1586 | } |
| 1587 | 1587 | elseif ($type == 'mail') |
| 1588 | 1588 | { |
| 1589 | - $value=dol_print_email($value, 0, 0, 0, 64, 1, 1); |
|
| 1589 | + $value = dol_print_email($value, 0, 0, 0, 64, 1, 1); |
|
| 1590 | 1590 | } |
| 1591 | 1591 | elseif ($type == 'url') |
| 1592 | 1592 | { |
| 1593 | - $value=dol_print_url($value,'_blank',32,1); |
|
| 1593 | + $value = dol_print_url($value, '_blank', 32, 1); |
|
| 1594 | 1594 | } |
| 1595 | 1595 | elseif ($type == 'phone') |
| 1596 | 1596 | { |
| 1597 | - $value=dol_print_phone($value, '', 0, 0, '', ' ', 1); |
|
| 1597 | + $value = dol_print_phone($value, '', 0, 0, '', ' ', 1); |
|
| 1598 | 1598 | } |
| 1599 | 1599 | elseif ($type == 'price') |
| 1600 | 1600 | { |
| 1601 | - $value=price($value, 0, $langs, 0, 0, -1, $conf->currency); |
|
| 1601 | + $value = price($value, 0, $langs, 0, 0, -1, $conf->currency); |
|
| 1602 | 1602 | } |
| 1603 | 1603 | elseif ($type == 'select') |
| 1604 | 1604 | { |
| 1605 | - if ($langfile && $param['options'][$value]) $value=$langs->trans($param['options'][$value]); |
|
| 1606 | - else $value=$param['options'][$value]; |
|
| 1605 | + if ($langfile && $param['options'][$value]) $value = $langs->trans($param['options'][$value]); |
|
| 1606 | + else $value = $param['options'][$value]; |
|
| 1607 | 1607 | } |
| 1608 | 1608 | elseif ($type == 'sellist') |
| 1609 | 1609 | { |
| 1610 | - $param_list=array_keys($param['options']); |
|
| 1610 | + $param_list = array_keys($param['options']); |
|
| 1611 | 1611 | $InfoFieldList = explode(":", $param_list[0]); |
| 1612 | 1612 | |
| 1613 | - $selectkey="rowid"; |
|
| 1614 | - $keyList='rowid'; |
|
| 1613 | + $selectkey = "rowid"; |
|
| 1614 | + $keyList = 'rowid'; |
|
| 1615 | 1615 | |
| 1616 | - if (count($InfoFieldList)>=3) |
|
| 1616 | + if (count($InfoFieldList) >= 3) |
|
| 1617 | 1617 | { |
| 1618 | 1618 | $selectkey = $InfoFieldList[2]; |
| 1619 | - $keyList=$InfoFieldList[2].' as rowid'; |
|
| 1619 | + $keyList = $InfoFieldList[2].' as rowid'; |
|
| 1620 | 1620 | } |
| 1621 | 1621 | |
| 1622 | - $fields_label = explode('|',$InfoFieldList[1]); |
|
| 1623 | - if(is_array($fields_label)) { |
|
| 1624 | - $keyList .=', '; |
|
| 1622 | + $fields_label = explode('|', $InfoFieldList[1]); |
|
| 1623 | + if (is_array($fields_label)) { |
|
| 1624 | + $keyList .= ', '; |
|
| 1625 | 1625 | $keyList .= implode(', ', $fields_label); |
| 1626 | 1626 | } |
| 1627 | 1627 | |
| 1628 | 1628 | $sql = 'SELECT '.$keyList; |
| 1629 | - $sql.= ' FROM '.MAIN_DB_PREFIX .$InfoFieldList[0]; |
|
| 1630 | - if (strpos($InfoFieldList[4], 'extra')!==false) |
|
| 1629 | + $sql .= ' FROM '.MAIN_DB_PREFIX.$InfoFieldList[0]; |
|
| 1630 | + if (strpos($InfoFieldList[4], 'extra') !== false) |
|
| 1631 | 1631 | { |
| 1632 | - $sql.= ' as main'; |
|
| 1632 | + $sql .= ' as main'; |
|
| 1633 | 1633 | } |
| 1634 | - if ($selectkey=='rowid' && empty($value)) { |
|
| 1635 | - $sql.= " WHERE ".$selectkey."=0"; |
|
| 1636 | - } elseif ($selectkey=='rowid') { |
|
| 1637 | - $sql.= " WHERE ".$selectkey."=".$this->db->escape($value); |
|
| 1638 | - }else { |
|
| 1639 | - $sql.= " WHERE ".$selectkey."='".$this->db->escape($value)."'"; |
|
| 1634 | + if ($selectkey == 'rowid' && empty($value)) { |
|
| 1635 | + $sql .= " WHERE ".$selectkey."=0"; |
|
| 1636 | + } elseif ($selectkey == 'rowid') { |
|
| 1637 | + $sql .= " WHERE ".$selectkey."=".$this->db->escape($value); |
|
| 1638 | + } else { |
|
| 1639 | + $sql .= " WHERE ".$selectkey."='".$this->db->escape($value)."'"; |
|
| 1640 | 1640 | } |
| 1641 | 1641 | |
| 1642 | 1642 | //$sql.= ' AND entity = '.$conf->entity; |
@@ -1645,38 +1645,38 @@ discard block |
||
| 1645 | 1645 | $resql = $this->db->query($sql); |
| 1646 | 1646 | if ($resql) |
| 1647 | 1647 | { |
| 1648 | - $value=''; // value was used, so now we reste it to use it to build final output |
|
| 1648 | + $value = ''; // value was used, so now we reste it to use it to build final output |
|
| 1649 | 1649 | |
| 1650 | 1650 | $obj = $this->db->fetch_object($resql); |
| 1651 | 1651 | |
| 1652 | 1652 | // Several field into label (eq table:code|libelle:rowid) |
| 1653 | - $fields_label = explode('|',$InfoFieldList[1]); |
|
| 1653 | + $fields_label = explode('|', $InfoFieldList[1]); |
|
| 1654 | 1654 | |
| 1655 | - if(is_array($fields_label) && count($fields_label)>1) |
|
| 1655 | + if (is_array($fields_label) && count($fields_label) > 1) |
|
| 1656 | 1656 | { |
| 1657 | 1657 | foreach ($fields_label as $field_toshow) |
| 1658 | 1658 | { |
| 1659 | - $translabel=''; |
|
| 1659 | + $translabel = ''; |
|
| 1660 | 1660 | if (!empty($obj->$field_toshow)) { |
| 1661 | - $translabel=$langs->trans($obj->$field_toshow); |
|
| 1661 | + $translabel = $langs->trans($obj->$field_toshow); |
|
| 1662 | 1662 | } |
| 1663 | - if ($translabel!=$field_toshow) { |
|
| 1664 | - $value.=dol_trunc($translabel,18).' '; |
|
| 1665 | - }else { |
|
| 1666 | - $value.=$obj->$field_toshow.' '; |
|
| 1663 | + if ($translabel != $field_toshow) { |
|
| 1664 | + $value .= dol_trunc($translabel, 18).' '; |
|
| 1665 | + } else { |
|
| 1666 | + $value .= $obj->$field_toshow.' '; |
|
| 1667 | 1667 | } |
| 1668 | 1668 | } |
| 1669 | 1669 | } |
| 1670 | 1670 | else |
| 1671 | 1671 | { |
| 1672 | - $translabel=''; |
|
| 1672 | + $translabel = ''; |
|
| 1673 | 1673 | if (!empty($obj->{$InfoFieldList[1]})) { |
| 1674 | - $translabel=$langs->trans($obj->{$InfoFieldList[1]}); |
|
| 1674 | + $translabel = $langs->trans($obj->{$InfoFieldList[1]}); |
|
| 1675 | 1675 | } |
| 1676 | - if ($translabel!=$obj->{$InfoFieldList[1]}) { |
|
| 1677 | - $value=dol_trunc($translabel,18); |
|
| 1678 | - }else { |
|
| 1679 | - $value=$obj->{$InfoFieldList[1]}; |
|
| 1676 | + if ($translabel != $obj->{$InfoFieldList[1]}) { |
|
| 1677 | + $value = dol_trunc($translabel, 18); |
|
| 1678 | + } else { |
|
| 1679 | + $value = $obj->{$InfoFieldList[1]}; |
|
| 1680 | 1680 | } |
| 1681 | 1681 | } |
| 1682 | 1682 | } |
@@ -1684,20 +1684,20 @@ discard block |
||
| 1684 | 1684 | } |
| 1685 | 1685 | elseif ($type == 'radio') |
| 1686 | 1686 | { |
| 1687 | - $value=$param['options'][$value]; |
|
| 1687 | + $value = $param['options'][$value]; |
|
| 1688 | 1688 | } |
| 1689 | 1689 | elseif ($type == 'checkbox') |
| 1690 | 1690 | { |
| 1691 | - $value_arr=explode(',',$value); |
|
| 1692 | - $value=''; |
|
| 1693 | - $toprint=array(); |
|
| 1691 | + $value_arr = explode(',', $value); |
|
| 1692 | + $value = ''; |
|
| 1693 | + $toprint = array(); |
|
| 1694 | 1694 | if (is_array($value_arr)) |
| 1695 | 1695 | { |
| 1696 | 1696 | foreach ($value_arr as $keyval=>$valueval) { |
| 1697 | - $toprint[]='<li class="select2-search-choice-dolibarr noborderoncategories" style="background: #aaa">'.$param['options'][$valueval].'</li>'; |
|
| 1697 | + $toprint[] = '<li class="select2-search-choice-dolibarr noborderoncategories" style="background: #aaa">'.$param['options'][$valueval].'</li>'; |
|
| 1698 | 1698 | } |
| 1699 | 1699 | } |
| 1700 | - $value='<div class="select2-container-multi-dolibarr" style="width: 90%;"><ul class="select2-choices-dolibarr">'.implode(' ', $toprint).'</ul></div>'; |
|
| 1700 | + $value = '<div class="select2-container-multi-dolibarr" style="width: 90%;"><ul class="select2-choices-dolibarr">'.implode(' ', $toprint).'</ul></div>'; |
|
| 1701 | 1701 | } |
| 1702 | 1702 | elseif ($type == 'chkbxlst') |
| 1703 | 1703 | { |
@@ -1711,7 +1711,7 @@ discard block |
||
| 1711 | 1711 | |
| 1712 | 1712 | if (count($InfoFieldList) >= 3) { |
| 1713 | 1713 | $selectkey = $InfoFieldList[2]; |
| 1714 | - $keyList = $InfoFieldList[2] . ' as rowid'; |
|
| 1714 | + $keyList = $InfoFieldList[2].' as rowid'; |
|
| 1715 | 1715 | } |
| 1716 | 1716 | |
| 1717 | 1717 | $fields_label = explode('|', $InfoFieldList[1]); |
@@ -1720,74 +1720,74 @@ discard block |
||
| 1720 | 1720 | $keyList .= implode(', ', $fields_label); |
| 1721 | 1721 | } |
| 1722 | 1722 | |
| 1723 | - $sql = 'SELECT ' . $keyList; |
|
| 1724 | - $sql .= ' FROM ' . MAIN_DB_PREFIX . $InfoFieldList[0]; |
|
| 1723 | + $sql = 'SELECT '.$keyList; |
|
| 1724 | + $sql .= ' FROM '.MAIN_DB_PREFIX.$InfoFieldList[0]; |
|
| 1725 | 1725 | if (strpos($InfoFieldList[4], 'extra') !== false) { |
| 1726 | 1726 | $sql .= ' as main'; |
| 1727 | 1727 | } |
| 1728 | 1728 | // $sql.= " WHERE ".$selectkey."='".$this->db->escape($value)."'"; |
| 1729 | 1729 | // $sql.= ' AND entity = '.$conf->entity; |
| 1730 | 1730 | |
| 1731 | - dol_syslog(get_class($this) . ':showOutputField:$type=chkbxlst',LOG_DEBUG); |
|
| 1731 | + dol_syslog(get_class($this).':showOutputField:$type=chkbxlst', LOG_DEBUG); |
|
| 1732 | 1732 | $resql = $this->db->query($sql); |
| 1733 | 1733 | if ($resql) { |
| 1734 | 1734 | $value = ''; // value was used, so now we reste it to use it to build final output |
| 1735 | - $toprint=array(); |
|
| 1736 | - while ( $obj = $this->db->fetch_object($resql) ) { |
|
| 1735 | + $toprint = array(); |
|
| 1736 | + while ($obj = $this->db->fetch_object($resql)) { |
|
| 1737 | 1737 | |
| 1738 | 1738 | // Several field into label (eq table:code|libelle:rowid) |
| 1739 | 1739 | $fields_label = explode('|', $InfoFieldList[1]); |
| 1740 | 1740 | if (is_array($value_arr) && in_array($obj->rowid, $value_arr)) { |
| 1741 | 1741 | if (is_array($fields_label) && count($fields_label) > 1) { |
| 1742 | - foreach ( $fields_label as $field_toshow ) { |
|
| 1742 | + foreach ($fields_label as $field_toshow) { |
|
| 1743 | 1743 | $translabel = ''; |
| 1744 | - if (! empty($obj->$field_toshow)) { |
|
| 1744 | + if (!empty($obj->$field_toshow)) { |
|
| 1745 | 1745 | $translabel = $langs->trans($obj->$field_toshow); |
| 1746 | 1746 | } |
| 1747 | 1747 | if ($translabel != $field_toshow) { |
| 1748 | - $toprint[]='<li class="select2-search-choice-dolibarr noborderoncategories" style="background: #aaa">'.dol_trunc($translabel, 18).'</li>'; |
|
| 1748 | + $toprint[] = '<li class="select2-search-choice-dolibarr noborderoncategories" style="background: #aaa">'.dol_trunc($translabel, 18).'</li>'; |
|
| 1749 | 1749 | } else { |
| 1750 | - $toprint[]='<li class="select2-search-choice-dolibarr noborderoncategories" style="background: #aaa">'.$obj->$field_toshow.'</li>'; |
|
| 1750 | + $toprint[] = '<li class="select2-search-choice-dolibarr noborderoncategories" style="background: #aaa">'.$obj->$field_toshow.'</li>'; |
|
| 1751 | 1751 | } |
| 1752 | 1752 | } |
| 1753 | 1753 | } else { |
| 1754 | 1754 | $translabel = ''; |
| 1755 | - if (! empty($obj->{$InfoFieldList[1]})) { |
|
| 1755 | + if (!empty($obj->{$InfoFieldList[1]})) { |
|
| 1756 | 1756 | $translabel = $langs->trans($obj->{$InfoFieldList[1]}); |
| 1757 | 1757 | } |
| 1758 | 1758 | if ($translabel != $obj->{$InfoFieldList[1]}) { |
| 1759 | - $toprint[]='<li class="select2-search-choice-dolibarr noborderoncategories" style="background: #aaa">'.dol_trunc($translabel, 18).'</li>'; |
|
| 1759 | + $toprint[] = '<li class="select2-search-choice-dolibarr noborderoncategories" style="background: #aaa">'.dol_trunc($translabel, 18).'</li>'; |
|
| 1760 | 1760 | } else { |
| 1761 | - $toprint[]='<li class="select2-search-choice-dolibarr noborderoncategories" style="background: #aaa">'.$obj->{$InfoFieldList[1]}.'</li>'; |
|
| 1761 | + $toprint[] = '<li class="select2-search-choice-dolibarr noborderoncategories" style="background: #aaa">'.$obj->{$InfoFieldList[1]}.'</li>'; |
|
| 1762 | 1762 | } |
| 1763 | 1763 | } |
| 1764 | 1764 | } |
| 1765 | 1765 | } |
| 1766 | - $value='<div class="select2-container-multi-dolibarr" style="width: 90%;"><ul class="select2-choices-dolibarr">'.implode(' ', $toprint).'</ul></div>'; |
|
| 1766 | + $value = '<div class="select2-container-multi-dolibarr" style="width: 90%;"><ul class="select2-choices-dolibarr">'.implode(' ', $toprint).'</ul></div>'; |
|
| 1767 | 1767 | } else { |
| 1768 | - dol_syslog(get_class($this) . '::showOutputField error ' . $this->db->lasterror(), LOG_WARNING); |
|
| 1768 | + dol_syslog(get_class($this).'::showOutputField error '.$this->db->lasterror(), LOG_WARNING); |
|
| 1769 | 1769 | } |
| 1770 | 1770 | } |
| 1771 | 1771 | elseif ($type == 'link') |
| 1772 | 1772 | { |
| 1773 | - $out=''; |
|
| 1773 | + $out = ''; |
|
| 1774 | 1774 | |
| 1775 | 1775 | // Only if something to display (perf) |
| 1776 | 1776 | if ($value) // If we have -1 here, pb is into sert, not into ouptu |
| 1777 | 1777 | { |
| 1778 | - $param_list=array_keys($param['options']); // $param_list='ObjectName:classPath' |
|
| 1778 | + $param_list = array_keys($param['options']); // $param_list='ObjectName:classPath' |
|
| 1779 | 1779 | |
| 1780 | 1780 | $InfoFieldList = explode(":", $param_list[0]); |
| 1781 | - $classname=$InfoFieldList[0]; |
|
| 1782 | - $classpath=$InfoFieldList[1]; |
|
| 1783 | - if (! empty($classpath)) |
|
| 1781 | + $classname = $InfoFieldList[0]; |
|
| 1782 | + $classpath = $InfoFieldList[1]; |
|
| 1783 | + if (!empty($classpath)) |
|
| 1784 | 1784 | { |
| 1785 | 1785 | dol_include_once($InfoFieldList[1]); |
| 1786 | 1786 | if ($classname && class_exists($classname)) |
| 1787 | 1787 | { |
| 1788 | 1788 | $object = new $classname($this->db); |
| 1789 | 1789 | $object->fetch($value); |
| 1790 | - $value=$object->getNomUrl(3); |
|
| 1790 | + $value = $object->getNomUrl(3); |
|
| 1791 | 1791 | } |
| 1792 | 1792 | } |
| 1793 | 1793 | else |
@@ -1799,24 +1799,24 @@ discard block |
||
| 1799 | 1799 | } |
| 1800 | 1800 | elseif ($type == 'text') |
| 1801 | 1801 | { |
| 1802 | - $value=dol_htmlentitiesbr($value); |
|
| 1802 | + $value = dol_htmlentitiesbr($value); |
|
| 1803 | 1803 | } |
| 1804 | 1804 | elseif ($type == 'html') |
| 1805 | 1805 | { |
| 1806 | - $value=dol_htmlentitiesbr($value); |
|
| 1806 | + $value = dol_htmlentitiesbr($value); |
|
| 1807 | 1807 | } |
| 1808 | 1808 | elseif ($type == 'password') |
| 1809 | 1809 | { |
| 1810 | - $value=dol_trunc(preg_replace('/./i','*',$value), 8, 'right', 'UTF-8', 1); |
|
| 1810 | + $value = dol_trunc(preg_replace('/./i', '*', $value), 8, 'right', 'UTF-8', 1); |
|
| 1811 | 1811 | } |
| 1812 | 1812 | else |
| 1813 | 1813 | { |
| 1814 | - $showsize=round($size); |
|
| 1815 | - if ($showsize > 48) $showsize=48; |
|
| 1814 | + $showsize = round($size); |
|
| 1815 | + if ($showsize > 48) $showsize = 48; |
|
| 1816 | 1816 | } |
| 1817 | 1817 | |
| 1818 | 1818 | //print $type.'-'.$size; |
| 1819 | - $out=$value; |
|
| 1819 | + $out = $value; |
|
| 1820 | 1820 | |
| 1821 | 1821 | return $out; |
| 1822 | 1822 | } |
@@ -1828,46 +1828,46 @@ discard block |
||
| 1828 | 1828 | * @param string $extrafieldsobjectkey If defined, use the new method to get extrafields data |
| 1829 | 1829 | * @return string Formated value |
| 1830 | 1830 | */ |
| 1831 | - function getAlignFlag($key, $extrafieldsobjectkey='') |
|
| 1831 | + function getAlignFlag($key, $extrafieldsobjectkey = '') |
|
| 1832 | 1832 | { |
| 1833 | - global $conf,$langs; |
|
| 1833 | + global $conf, $langs; |
|
| 1834 | 1834 | |
| 1835 | - if (! empty($extrafieldsobjectkey)) $type=$this->attributes[$extrafieldsobjectkey]['type'][$key]; |
|
| 1836 | - else $type=$this->attribute_type[$key]; |
|
| 1835 | + if (!empty($extrafieldsobjectkey)) $type = $this->attributes[$extrafieldsobjectkey]['type'][$key]; |
|
| 1836 | + else $type = $this->attribute_type[$key]; |
|
| 1837 | 1837 | |
| 1838 | - $align=''; |
|
| 1838 | + $align = ''; |
|
| 1839 | 1839 | |
| 1840 | 1840 | if ($type == 'date') |
| 1841 | 1841 | { |
| 1842 | - $align="center"; |
|
| 1842 | + $align = "center"; |
|
| 1843 | 1843 | } |
| 1844 | 1844 | elseif ($type == 'datetime') |
| 1845 | 1845 | { |
| 1846 | - $align="center"; |
|
| 1846 | + $align = "center"; |
|
| 1847 | 1847 | } |
| 1848 | 1848 | elseif ($type == 'int') |
| 1849 | 1849 | { |
| 1850 | - $align="right"; |
|
| 1850 | + $align = "right"; |
|
| 1851 | 1851 | } |
| 1852 | 1852 | elseif ($type == 'double') |
| 1853 | 1853 | { |
| 1854 | - $align="right"; |
|
| 1854 | + $align = "right"; |
|
| 1855 | 1855 | } |
| 1856 | 1856 | elseif ($type == 'boolean') |
| 1857 | 1857 | { |
| 1858 | - $align="center"; |
|
| 1858 | + $align = "center"; |
|
| 1859 | 1859 | } |
| 1860 | 1860 | elseif ($type == 'radio') |
| 1861 | 1861 | { |
| 1862 | - $align="center"; |
|
| 1862 | + $align = "center"; |
|
| 1863 | 1863 | } |
| 1864 | 1864 | elseif ($type == 'checkbox') |
| 1865 | 1865 | { |
| 1866 | - $align="center"; |
|
| 1866 | + $align = "center"; |
|
| 1867 | 1867 | } |
| 1868 | 1868 | elseif ($type == 'price') |
| 1869 | 1869 | { |
| 1870 | - $align="right"; |
|
| 1870 | + $align = "right"; |
|
| 1871 | 1871 | } |
| 1872 | 1872 | |
| 1873 | 1873 | return $align; |
@@ -1885,8 +1885,8 @@ discard block |
||
| 1885 | 1885 | global $langs; |
| 1886 | 1886 | |
| 1887 | 1887 | $out = '<tr class="trextrafieldseparator trextrafieldseparator'.$key.'"><td colspan="2"><strong>'; |
| 1888 | - $out.= $langs->trans($this->attributes[$object->table_element]['label'][$key]); |
|
| 1889 | - $out.= '</strong></td></tr>'; |
|
| 1888 | + $out .= $langs->trans($this->attributes[$object->table_element]['label'][$key]); |
|
| 1889 | + $out .= '</strong></td></tr>'; |
|
| 1890 | 1890 | return $out; |
| 1891 | 1891 | } |
| 1892 | 1892 | |
@@ -1898,20 +1898,20 @@ discard block |
||
| 1898 | 1898 | * @param string $onlykey Only following key is filled. When we make update of only one extrafield ($action = 'update_extras'), calling page must must set this to avoid to have other extrafields being reset. |
| 1899 | 1899 | * @return int 1 if array_options set, 0 if no value, -1 if error (field required missing for example) |
| 1900 | 1900 | */ |
| 1901 | - function setOptionalsFromPost($extralabels, &$object, $onlykey='') |
|
| 1901 | + function setOptionalsFromPost($extralabels, &$object, $onlykey = '') |
|
| 1902 | 1902 | { |
| 1903 | 1903 | global $_POST, $langs; |
| 1904 | - $nofillrequired='';// For error when required field left blank |
|
| 1904 | + $nofillrequired = ''; // For error when required field left blank |
|
| 1905 | 1905 | $error_field_required = array(); |
| 1906 | 1906 | |
| 1907 | - if (is_array($this->attributes[$object->table_element]['label'])) $extralabels=$this->attributes[$object->table_element]['label']; |
|
| 1907 | + if (is_array($this->attributes[$object->table_element]['label'])) $extralabels = $this->attributes[$object->table_element]['label']; |
|
| 1908 | 1908 | |
| 1909 | 1909 | if (is_array($extralabels)) |
| 1910 | 1910 | { |
| 1911 | 1911 | // Get extra fields |
| 1912 | 1912 | foreach ($extralabels as $key => $value) |
| 1913 | 1913 | { |
| 1914 | - if (! empty($onlykey) && $key != $onlykey) continue; |
|
| 1914 | + if (!empty($onlykey) && $key != $onlykey) continue; |
|
| 1915 | 1915 | |
| 1916 | 1916 | $key_type = $this->attributes[$object->table_element]['type'][$key]; |
| 1917 | 1917 | if ($key_type == 'separate') continue; |
@@ -1932,7 +1932,7 @@ discard block |
||
| 1932 | 1932 | if ($this->attributes[$object->table_element]['required'][$key]) // Value is required |
| 1933 | 1933 | { |
| 1934 | 1934 | // Check if empty without using GETPOST, value can be alpha, int, array, etc... |
| 1935 | - if ((! is_array($_POST["options_".$key]) && empty($_POST["options_".$key]) && $_POST["options_".$key] != '0') |
|
| 1935 | + if ((!is_array($_POST["options_".$key]) && empty($_POST["options_".$key]) && $_POST["options_".$key] != '0') |
|
| 1936 | 1936 | || (is_array($_POST["options_".$key]) && empty($_POST["options_".$key]))) |
| 1937 | 1937 | { |
| 1938 | 1938 | //print 'ccc'.$value.'-'.$this->attributes[$object->table_element]['required'][$key]; |
@@ -1941,43 +1941,43 @@ discard block |
||
| 1941 | 1941 | } |
| 1942 | 1942 | } |
| 1943 | 1943 | |
| 1944 | - if (in_array($key_type,array('date'))) |
|
| 1944 | + if (in_array($key_type, array('date'))) |
|
| 1945 | 1945 | { |
| 1946 | 1946 | // Clean parameters |
| 1947 | 1947 | // TODO GMT date in memory must be GMT so we should add gm=true in parameters |
| 1948 | - $value_key=dol_mktime(0, 0, 0, $_POST["options_".$key."month"], $_POST["options_".$key."day"], $_POST["options_".$key."year"]); |
|
| 1948 | + $value_key = dol_mktime(0, 0, 0, $_POST["options_".$key."month"], $_POST["options_".$key."day"], $_POST["options_".$key."year"]); |
|
| 1949 | 1949 | } |
| 1950 | - elseif (in_array($key_type,array('datetime'))) |
|
| 1950 | + elseif (in_array($key_type, array('datetime'))) |
|
| 1951 | 1951 | { |
| 1952 | 1952 | // Clean parameters |
| 1953 | 1953 | // TODO GMT date in memory must be GMT so we should add gm=true in parameters |
| 1954 | - $value_key=dol_mktime($_POST["options_".$key."hour"], $_POST["options_".$key."min"], 0, $_POST["options_".$key."month"], $_POST["options_".$key."day"], $_POST["options_".$key."year"]); |
|
| 1954 | + $value_key = dol_mktime($_POST["options_".$key."hour"], $_POST["options_".$key."min"], 0, $_POST["options_".$key."month"], $_POST["options_".$key."day"], $_POST["options_".$key."year"]); |
|
| 1955 | 1955 | } |
| 1956 | - else if (in_array($key_type,array('checkbox','chkbxlst'))) |
|
| 1956 | + else if (in_array($key_type, array('checkbox', 'chkbxlst'))) |
|
| 1957 | 1957 | { |
| 1958 | - $value_arr=GETPOST("options_".$key, 'array'); // check if an array |
|
| 1958 | + $value_arr = GETPOST("options_".$key, 'array'); // check if an array |
|
| 1959 | 1959 | if (!empty($value_arr)) { |
| 1960 | - $value_key=implode($value_arr,','); |
|
| 1961 | - }else { |
|
| 1962 | - $value_key=''; |
|
| 1960 | + $value_key = implode($value_arr, ','); |
|
| 1961 | + } else { |
|
| 1962 | + $value_key = ''; |
|
| 1963 | 1963 | } |
| 1964 | 1964 | } |
| 1965 | - else if (in_array($key_type,array('price','double'))) |
|
| 1965 | + else if (in_array($key_type, array('price', 'double'))) |
|
| 1966 | 1966 | { |
| 1967 | - $value_arr=GETPOST("options_".$key, 'alpha'); |
|
| 1968 | - $value_key=price2num($value_arr); |
|
| 1967 | + $value_arr = GETPOST("options_".$key, 'alpha'); |
|
| 1968 | + $value_key = price2num($value_arr); |
|
| 1969 | 1969 | } |
| 1970 | 1970 | else |
| 1971 | 1971 | { |
| 1972 | - $value_key=GETPOST("options_".$key); |
|
| 1972 | + $value_key = GETPOST("options_".$key); |
|
| 1973 | 1973 | } |
| 1974 | 1974 | |
| 1975 | - $object->array_options["options_".$key]=$value_key; |
|
| 1975 | + $object->array_options["options_".$key] = $value_key; |
|
| 1976 | 1976 | } |
| 1977 | 1977 | |
| 1978 | 1978 | if ($nofillrequired) { |
| 1979 | 1979 | $langs->load('errors'); |
| 1980 | - setEventMessages($langs->trans('ErrorFieldsRequired').' : '.implode(', ',$error_field_required), null, 'errors'); |
|
| 1980 | + setEventMessages($langs->trans('ErrorFieldsRequired').' : '.implode(', ', $error_field_required), null, 'errors'); |
|
| 1981 | 1981 | return -1; |
| 1982 | 1982 | } |
| 1983 | 1983 | else { |
@@ -1997,7 +1997,7 @@ discard block |
||
| 1997 | 1997 | * @param string $keysuffix Suffix string to add into name and id of field (can be used to avoid duplicate names) |
| 1998 | 1998 | * @return array|int array_options set or 0 if no value |
| 1999 | 1999 | */ |
| 2000 | - function getOptionalsFromPost($extrafieldsobjectkey, $keyprefix='', $keysuffix='') |
|
| 2000 | + function getOptionalsFromPost($extrafieldsobjectkey, $keyprefix = '', $keysuffix = '') |
|
| 2001 | 2001 | { |
| 2002 | 2002 | global $_POST; |
| 2003 | 2003 | |
@@ -2023,29 +2023,29 @@ discard block |
||
| 2023 | 2023 | $key_type = $this->attributes[$extrafieldsobjectkey]['type'][$key]; |
| 2024 | 2024 | } |
| 2025 | 2025 | |
| 2026 | - if (in_array($key_type,array('date','datetime'))) |
|
| 2026 | + if (in_array($key_type, array('date', 'datetime'))) |
|
| 2027 | 2027 | { |
| 2028 | 2028 | // Clean parameters |
| 2029 | - $value_key=dol_mktime($_POST[$keysuffix."options_".$key.$keyprefix."hour"], $_POST[$keysuffix."options_".$key.$keyprefix."min"], 0, $_POST[$keysuffix."options_".$key.$keyprefix."month"], $_POST[$keysuffix."options_".$key.$keyprefix."day"], $_POST[$keysuffix."options_".$key.$keyprefix."year"]); |
|
| 2029 | + $value_key = dol_mktime($_POST[$keysuffix."options_".$key.$keyprefix."hour"], $_POST[$keysuffix."options_".$key.$keyprefix."min"], 0, $_POST[$keysuffix."options_".$key.$keyprefix."month"], $_POST[$keysuffix."options_".$key.$keyprefix."day"], $_POST[$keysuffix."options_".$key.$keyprefix."year"]); |
|
| 2030 | 2030 | } |
| 2031 | - else if (in_array($key_type,array('checkbox', 'chkbxlst'))) |
|
| 2031 | + else if (in_array($key_type, array('checkbox', 'chkbxlst'))) |
|
| 2032 | 2032 | { |
| 2033 | - $value_arr=GETPOST($keysuffix."options_".$key.$keyprefix); |
|
| 2033 | + $value_arr = GETPOST($keysuffix."options_".$key.$keyprefix); |
|
| 2034 | 2034 | // Make sure we get an array even if there's only one checkbox |
| 2035 | - $value_arr=(array) $value_arr; |
|
| 2036 | - $value_key=implode(',', $value_arr); |
|
| 2035 | + $value_arr = (array) $value_arr; |
|
| 2036 | + $value_key = implode(',', $value_arr); |
|
| 2037 | 2037 | } |
| 2038 | - else if (in_array($key_type,array('price','double'))) |
|
| 2038 | + else if (in_array($key_type, array('price', 'double'))) |
|
| 2039 | 2039 | { |
| 2040 | - $value_arr=GETPOST($keysuffix."options_".$key.$keyprefix); |
|
| 2041 | - $value_key=price2num($value_arr); |
|
| 2040 | + $value_arr = GETPOST($keysuffix."options_".$key.$keyprefix); |
|
| 2041 | + $value_key = price2num($value_arr); |
|
| 2042 | 2042 | } |
| 2043 | 2043 | else |
| 2044 | 2044 | { |
| 2045 | - $value_key=GETPOST($keysuffix."options_".$key.$keyprefix); |
|
| 2045 | + $value_key = GETPOST($keysuffix."options_".$key.$keyprefix); |
|
| 2046 | 2046 | } |
| 2047 | 2047 | |
| 2048 | - $array_options[$keysuffix."options_".$key]=$value_key; // No keyprefix here. keyprefix is used only for read. |
|
| 2048 | + $array_options[$keysuffix."options_".$key] = $value_key; // No keyprefix here. keyprefix is used only for read. |
|
| 2049 | 2049 | } |
| 2050 | 2050 | |
| 2051 | 2051 | return $array_options; |
@@ -37,12 +37,12 @@ discard block |
||
| 37 | 37 | /** |
| 38 | 38 | * @var string ID to identify managed object |
| 39 | 39 | */ |
| 40 | - public $element='events'; |
|
| 40 | + public $element = 'events'; |
|
| 41 | 41 | |
| 42 | 42 | /** |
| 43 | 43 | * @var string Name of table without prefix where object is stored |
| 44 | 44 | */ |
| 45 | - public $table_element='events'; |
|
| 45 | + public $table_element = 'events'; |
|
| 46 | 46 | |
| 47 | 47 | /** |
| 48 | 48 | * @var int ID |
@@ -57,7 +57,7 @@ discard block |
||
| 57 | 57 | /** |
| 58 | 58 | * @var string Error code (or message) |
| 59 | 59 | */ |
| 60 | - public $error=''; |
|
| 60 | + public $error = ''; |
|
| 61 | 61 | |
| 62 | 62 | public $tms; |
| 63 | 63 | public $type; |
@@ -75,20 +75,20 @@ discard block |
||
| 75 | 75 | public $description; |
| 76 | 76 | |
| 77 | 77 | // List of all Audit/Security events supported by triggers |
| 78 | - public $eventstolog=array( |
|
| 79 | - array('id'=>'USER_LOGIN', 'test'=>1), |
|
| 80 | - array('id'=>'USER_LOGIN_FAILED', 'test'=>1), |
|
| 81 | - array('id'=>'USER_LOGOUT', 'test'=>1), |
|
| 82 | - array('id'=>'USER_CREATE', 'test'=>1), |
|
| 83 | - array('id'=>'USER_MODIFY', 'test'=>1), |
|
| 84 | - array('id'=>'USER_NEW_PASSWORD', 'test'=>1), |
|
| 85 | - array('id'=>'USER_ENABLEDISABLE', 'test'=>1), |
|
| 86 | - array('id'=>'USER_DELETE', 'test'=>1), |
|
| 78 | + public $eventstolog = array( |
|
| 79 | + array('id'=>'USER_LOGIN', 'test'=>1), |
|
| 80 | + array('id'=>'USER_LOGIN_FAILED', 'test'=>1), |
|
| 81 | + array('id'=>'USER_LOGOUT', 'test'=>1), |
|
| 82 | + array('id'=>'USER_CREATE', 'test'=>1), |
|
| 83 | + array('id'=>'USER_MODIFY', 'test'=>1), |
|
| 84 | + array('id'=>'USER_NEW_PASSWORD', 'test'=>1), |
|
| 85 | + array('id'=>'USER_ENABLEDISABLE', 'test'=>1), |
|
| 86 | + array('id'=>'USER_DELETE', 'test'=>1), |
|
| 87 | 87 | /* array('id'=>'USER_SETINGROUP', 'test'=>1), deprecated. Replace with USER_MODIFY |
| 88 | 88 | array('id'=>'USER_REMOVEFROMGROUP', 'test'=>1), deprecated. Replace with USER_MODIFY */ |
| 89 | - array('id'=>'GROUP_CREATE', 'test'=>1), |
|
| 90 | - array('id'=>'GROUP_MODIFY', 'test'=>1), |
|
| 91 | - array('id'=>'GROUP_DELETE', 'test'=>1), |
|
| 89 | + array('id'=>'GROUP_CREATE', 'test'=>1), |
|
| 90 | + array('id'=>'GROUP_MODIFY', 'test'=>1), |
|
| 91 | + array('id'=>'GROUP_DELETE', 'test'=>1), |
|
| 92 | 92 | /* array('id'=>'ACTION_CREATE', 'test'=>$conf->societe->enabled), |
| 93 | 93 | array('id'=>'COMPANY_CREATE', 'test'=>$conf->societe->enabled), |
| 94 | 94 | array('id'=>'CONTRACT_VALIDATE', 'test'=>$conf->contrat->enabled), |
@@ -136,33 +136,33 @@ discard block |
||
| 136 | 136 | global $conf, $langs; |
| 137 | 137 | |
| 138 | 138 | // Clean parameters |
| 139 | - $this->description=trim($this->description); |
|
| 140 | - if (empty($this->user_agent) && !empty($_SERVER['HTTP_USER_AGENT'])) $this->user_agent=$_SERVER['HTTP_USER_AGENT']; |
|
| 139 | + $this->description = trim($this->description); |
|
| 140 | + if (empty($this->user_agent) && !empty($_SERVER['HTTP_USER_AGENT'])) $this->user_agent = $_SERVER['HTTP_USER_AGENT']; |
|
| 141 | 141 | |
| 142 | 142 | // Check parameters |
| 143 | - if (empty($this->description)) { $this->error='ErrorBadValueForParameterCreateEventDesc'; return -1; } |
|
| 143 | + if (empty($this->description)) { $this->error = 'ErrorBadValueForParameterCreateEventDesc'; return -1; } |
|
| 144 | 144 | |
| 145 | 145 | // Insert request |
| 146 | 146 | $sql = "INSERT INTO ".MAIN_DB_PREFIX."events("; |
| 147 | - $sql.= "type,"; |
|
| 148 | - $sql.= "entity,"; |
|
| 149 | - $sql.= "ip,"; |
|
| 150 | - $sql.= "user_agent,"; |
|
| 151 | - $sql.= "dateevent,"; |
|
| 152 | - $sql.= "fk_user,"; |
|
| 153 | - $sql.= "description"; |
|
| 154 | - $sql.= ") VALUES ("; |
|
| 155 | - $sql.= " '".$this->db->escape($this->type)."',"; |
|
| 156 | - $sql.= " ".$conf->entity.","; |
|
| 157 | - $sql.= " '".$this->db->escape(getUserRemoteIP())."',"; |
|
| 158 | - $sql.= " ".($this->user_agent ? "'".$this->db->escape(dol_trunc($this->user_agent,250))."'" : 'NULL').","; |
|
| 159 | - $sql.= " '".$this->db->idate($this->dateevent)."',"; |
|
| 160 | - $sql.= " ".($user->id?"'".$this->db->escape($user->id)."'":'NULL').","; |
|
| 161 | - $sql.= " '".$this->db->escape(dol_trunc($this->description,250))."'"; |
|
| 162 | - $sql.= ")"; |
|
| 147 | + $sql .= "type,"; |
|
| 148 | + $sql .= "entity,"; |
|
| 149 | + $sql .= "ip,"; |
|
| 150 | + $sql .= "user_agent,"; |
|
| 151 | + $sql .= "dateevent,"; |
|
| 152 | + $sql .= "fk_user,"; |
|
| 153 | + $sql .= "description"; |
|
| 154 | + $sql .= ") VALUES ("; |
|
| 155 | + $sql .= " '".$this->db->escape($this->type)."',"; |
|
| 156 | + $sql .= " ".$conf->entity.","; |
|
| 157 | + $sql .= " '".$this->db->escape(getUserRemoteIP())."',"; |
|
| 158 | + $sql .= " ".($this->user_agent ? "'".$this->db->escape(dol_trunc($this->user_agent, 250))."'" : 'NULL').","; |
|
| 159 | + $sql .= " '".$this->db->idate($this->dateevent)."',"; |
|
| 160 | + $sql .= " ".($user->id ? "'".$this->db->escape($user->id)."'" : 'NULL').","; |
|
| 161 | + $sql .= " '".$this->db->escape(dol_trunc($this->description, 250))."'"; |
|
| 162 | + $sql .= ")"; |
|
| 163 | 163 | |
| 164 | 164 | dol_syslog(get_class($this)."::create", LOG_DEBUG); |
| 165 | - $resql=$this->db->query($sql); |
|
| 165 | + $resql = $this->db->query($sql); |
|
| 166 | 166 | if ($resql) |
| 167 | 167 | { |
| 168 | 168 | $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX."events"); |
@@ -170,7 +170,7 @@ discard block |
||
| 170 | 170 | } |
| 171 | 171 | else |
| 172 | 172 | { |
| 173 | - $this->error="Error ".$this->db->lasterror(); |
|
| 173 | + $this->error = "Error ".$this->db->lasterror(); |
|
| 174 | 174 | return -1; |
| 175 | 175 | } |
| 176 | 176 | } |
@@ -183,30 +183,30 @@ discard block |
||
| 183 | 183 | * @param int $notrigger 0=no, 1=yes (no update trigger) |
| 184 | 184 | * @return int <0 if KO, >0 if OK |
| 185 | 185 | */ |
| 186 | - function update($user=null, $notrigger=0) |
|
| 186 | + function update($user = null, $notrigger = 0) |
|
| 187 | 187 | { |
| 188 | 188 | global $conf, $langs; |
| 189 | 189 | |
| 190 | 190 | // Clean parameters |
| 191 | - $this->id=trim($this->id); |
|
| 192 | - $this->type=trim($this->type); |
|
| 193 | - $this->description=trim($this->description); |
|
| 191 | + $this->id = trim($this->id); |
|
| 192 | + $this->type = trim($this->type); |
|
| 193 | + $this->description = trim($this->description); |
|
| 194 | 194 | |
| 195 | 195 | // Check parameters |
| 196 | 196 | // Put here code to add control on parameters values |
| 197 | 197 | |
| 198 | 198 | // Update request |
| 199 | 199 | $sql = "UPDATE ".MAIN_DB_PREFIX."events SET"; |
| 200 | - $sql.= " type='".$this->db->escape($this->type)."',"; |
|
| 201 | - $sql.= " dateevent='".$this->db->idate($this->dateevent)."',"; |
|
| 202 | - $sql.= " description='".$this->db->escape($this->description)."'"; |
|
| 203 | - $sql.= " WHERE rowid=".$this->id; |
|
| 200 | + $sql .= " type='".$this->db->escape($this->type)."',"; |
|
| 201 | + $sql .= " dateevent='".$this->db->idate($this->dateevent)."',"; |
|
| 202 | + $sql .= " description='".$this->db->escape($this->description)."'"; |
|
| 203 | + $sql .= " WHERE rowid=".$this->id; |
|
| 204 | 204 | |
| 205 | 205 | dol_syslog(get_class($this)."::update", LOG_DEBUG); |
| 206 | 206 | $resql = $this->db->query($sql); |
| 207 | - if (! $resql) |
|
| 207 | + if (!$resql) |
|
| 208 | 208 | { |
| 209 | - $this->error="Error ".$this->db->lasterror(); |
|
| 209 | + $this->error = "Error ".$this->db->lasterror(); |
|
| 210 | 210 | return -1; |
| 211 | 211 | } |
| 212 | 212 | return 1; |
@@ -220,31 +220,31 @@ discard block |
||
| 220 | 220 | * @param User $user User that load |
| 221 | 221 | * @return int <0 if KO, >0 if OK |
| 222 | 222 | */ |
| 223 | - function fetch($id, $user=null) |
|
| 223 | + function fetch($id, $user = null) |
|
| 224 | 224 | { |
| 225 | 225 | global $langs; |
| 226 | 226 | |
| 227 | 227 | $sql = "SELECT"; |
| 228 | - $sql.= " t.rowid,"; |
|
| 229 | - $sql.= " t.tms,"; |
|
| 230 | - $sql.= " t.type,"; |
|
| 231 | - $sql.= " t.entity,"; |
|
| 232 | - $sql.= " t.dateevent,"; |
|
| 233 | - $sql.= " t.description,"; |
|
| 234 | - $sql.= " t.ip,"; |
|
| 235 | - $sql.= " t.user_agent"; |
|
| 236 | - $sql.= " FROM ".MAIN_DB_PREFIX."events as t"; |
|
| 237 | - $sql.= " WHERE t.rowid = ".$id; |
|
| 228 | + $sql .= " t.rowid,"; |
|
| 229 | + $sql .= " t.tms,"; |
|
| 230 | + $sql .= " t.type,"; |
|
| 231 | + $sql .= " t.entity,"; |
|
| 232 | + $sql .= " t.dateevent,"; |
|
| 233 | + $sql .= " t.description,"; |
|
| 234 | + $sql .= " t.ip,"; |
|
| 235 | + $sql .= " t.user_agent"; |
|
| 236 | + $sql .= " FROM ".MAIN_DB_PREFIX."events as t"; |
|
| 237 | + $sql .= " WHERE t.rowid = ".$id; |
|
| 238 | 238 | |
| 239 | 239 | dol_syslog(get_class($this)."::fetch", LOG_DEBUG); |
| 240 | - $resql=$this->db->query($sql); |
|
| 240 | + $resql = $this->db->query($sql); |
|
| 241 | 241 | if ($resql) |
| 242 | 242 | { |
| 243 | 243 | if ($this->db->num_rows($resql)) |
| 244 | 244 | { |
| 245 | 245 | $obj = $this->db->fetch_object($resql); |
| 246 | 246 | |
| 247 | - $this->id = $obj->rowid; |
|
| 247 | + $this->id = $obj->rowid; |
|
| 248 | 248 | $this->tms = $this->db->jdate($obj->tms); |
| 249 | 249 | $this->type = $obj->type; |
| 250 | 250 | $this->entity = $obj->entity; |
@@ -259,7 +259,7 @@ discard block |
||
| 259 | 259 | } |
| 260 | 260 | else |
| 261 | 261 | { |
| 262 | - $this->error="Error ".$this->db->lasterror(); |
|
| 262 | + $this->error = "Error ".$this->db->lasterror(); |
|
| 263 | 263 | return -1; |
| 264 | 264 | } |
| 265 | 265 | } |
@@ -276,13 +276,13 @@ discard block |
||
| 276 | 276 | global $conf, $langs; |
| 277 | 277 | |
| 278 | 278 | $sql = "DELETE FROM ".MAIN_DB_PREFIX."events"; |
| 279 | - $sql.= " WHERE rowid=".$this->id; |
|
| 279 | + $sql .= " WHERE rowid=".$this->id; |
|
| 280 | 280 | |
| 281 | 281 | dol_syslog(get_class($this)."::delete", LOG_DEBUG); |
| 282 | 282 | $resql = $this->db->query($sql); |
| 283 | - if (! $resql) |
|
| 283 | + if (!$resql) |
|
| 284 | 284 | { |
| 285 | - $this->error="Error ".$this->db->lasterror(); |
|
| 285 | + $this->error = "Error ".$this->db->lasterror(); |
|
| 286 | 286 | return -1; |
| 287 | 287 | } |
| 288 | 288 | |
@@ -299,11 +299,11 @@ discard block |
||
| 299 | 299 | */ |
| 300 | 300 | function initAsSpecimen() |
| 301 | 301 | { |
| 302 | - $this->id=0; |
|
| 302 | + $this->id = 0; |
|
| 303 | 303 | |
| 304 | - $this->tms=time(); |
|
| 305 | - $this->type=''; |
|
| 306 | - $this->dateevent=time(); |
|
| 307 | - $this->description='This is a specimen event'; |
|
| 304 | + $this->tms = time(); |
|
| 305 | + $this->type = ''; |
|
| 306 | + $this->dateevent = time(); |
|
| 307 | + $this->description = 'This is a specimen event'; |
|
| 308 | 308 | } |
| 309 | 309 | } |
@@ -99,18 +99,18 @@ discard block |
||
| 99 | 99 | // Put here code to add control on parameters values |
| 100 | 100 | |
| 101 | 101 | // Insert request |
| 102 | - $sql = 'INSERT INTO ' . MAIN_DB_PREFIX . $this->table_element . '('; |
|
| 102 | + $sql = 'INSERT INTO '.MAIN_DB_PREFIX.$this->table_element.'('; |
|
| 103 | 103 | |
| 104 | - $sql.= 'code,'; |
|
| 105 | - $sql.= 'label'; |
|
| 106 | - $sql.= 'active'; |
|
| 104 | + $sql .= 'code,'; |
|
| 105 | + $sql .= 'label'; |
|
| 106 | + $sql .= 'active'; |
|
| 107 | 107 | |
| 108 | 108 | |
| 109 | 109 | $sql .= ') VALUES ('; |
| 110 | 110 | |
| 111 | - $sql .= ' '.(! isset($this->code)?'NULL':"'".$this->db->escape($this->code)."'").','; |
|
| 112 | - $sql .= ' '.(! isset($this->label)?'NULL':"'".$this->db->escape($this->label)."'").','; |
|
| 113 | - $sql .= ' '.(! isset($this->active)?'NULL':$this->active); |
|
| 111 | + $sql .= ' '.(!isset($this->code) ? 'NULL' : "'".$this->db->escape($this->code)."'").','; |
|
| 112 | + $sql .= ' '.(!isset($this->label) ? 'NULL' : "'".$this->db->escape($this->label)."'").','; |
|
| 113 | + $sql .= ' '.(!isset($this->active) ? 'NULL' : $this->active); |
|
| 114 | 114 | |
| 115 | 115 | |
| 116 | 116 | $sql .= ')'; |
@@ -119,13 +119,13 @@ discard block |
||
| 119 | 119 | |
| 120 | 120 | $resql = $this->db->query($sql); |
| 121 | 121 | if (!$resql) { |
| 122 | - $error ++; |
|
| 123 | - $this->errors[] = 'Error ' . $this->db->lasterror(); |
|
| 124 | - dol_syslog(__METHOD__ . ' ' . implode(',', $this->errors), LOG_ERR); |
|
| 122 | + $error++; |
|
| 123 | + $this->errors[] = 'Error '.$this->db->lasterror(); |
|
| 124 | + dol_syslog(__METHOD__.' '.implode(',', $this->errors), LOG_ERR); |
|
| 125 | 125 | } |
| 126 | 126 | |
| 127 | 127 | if (!$error) { |
| 128 | - $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX . $this->table_element); |
|
| 128 | + $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX.$this->table_element); |
|
| 129 | 129 | |
| 130 | 130 | // Uncomment this and change MYOBJECT to your own tag if you |
| 131 | 131 | // want this action to call a trigger. |
@@ -142,7 +142,7 @@ discard block |
||
| 142 | 142 | if ($error) { |
| 143 | 143 | $this->db->rollback(); |
| 144 | 144 | |
| 145 | - return - 1 * $error; |
|
| 145 | + return -1 * $error; |
|
| 146 | 146 | } else { |
| 147 | 147 | $this->db->commit(); |
| 148 | 148 | |
@@ -159,7 +159,7 @@ discard block |
||
| 159 | 159 | * |
| 160 | 160 | * @return int <0 if KO, 0 if not found, >0 if OK |
| 161 | 161 | */ |
| 162 | - public function fetch($id,$code='',$label='') |
|
| 162 | + public function fetch($id, $code = '', $label = '') |
|
| 163 | 163 | { |
| 164 | 164 | dol_syslog(__METHOD__, LOG_DEBUG); |
| 165 | 165 | |
@@ -171,10 +171,10 @@ discard block |
||
| 171 | 171 | $sql .= " t.active"; |
| 172 | 172 | |
| 173 | 173 | |
| 174 | - $sql .= ' FROM ' . MAIN_DB_PREFIX . $this->table_element . ' as t'; |
|
| 175 | - if ($id) $sql.= " WHERE t.id = ".$id; |
|
| 176 | - elseif ($code) $sql.= " WHERE t.code = '".$this->db->escape($code)."'"; |
|
| 177 | - elseif ($label) $sql.= " WHERE t.label = '".$this->db->escape($label)."'"; |
|
| 174 | + $sql .= ' FROM '.MAIN_DB_PREFIX.$this->table_element.' as t'; |
|
| 175 | + if ($id) $sql .= " WHERE t.id = ".$id; |
|
| 176 | + elseif ($code) $sql .= " WHERE t.code = '".$this->db->escape($code)."'"; |
|
| 177 | + elseif ($label) $sql .= " WHERE t.label = '".$this->db->escape($label)."'"; |
|
| 178 | 178 | |
| 179 | 179 | |
| 180 | 180 | $resql = $this->db->query($sql); |
@@ -204,10 +204,10 @@ discard block |
||
| 204 | 204 | return 0; |
| 205 | 205 | } |
| 206 | 206 | } else { |
| 207 | - $this->errors[] = 'Error ' . $this->db->lasterror(); |
|
| 208 | - dol_syslog(__METHOD__ . ' ' . implode(',', $this->errors), LOG_ERR); |
|
| 207 | + $this->errors[] = 'Error '.$this->db->lasterror(); |
|
| 208 | + dol_syslog(__METHOD__.' '.implode(',', $this->errors), LOG_ERR); |
|
| 209 | 209 | |
| 210 | - return - 1; |
|
| 210 | + return -1; |
|
| 211 | 211 | } |
| 212 | 212 | } |
| 213 | 213 | |
@@ -223,7 +223,7 @@ discard block |
||
| 223 | 223 | * |
| 224 | 224 | * @return int <0 if KO, >0 if OK |
| 225 | 225 | */ |
| 226 | - public function fetchAll($sortorder='', $sortfield='', $limit=0, $offset=0, array $filter = array(), $filtermode='AND') |
|
| 226 | + public function fetchAll($sortorder = '', $sortfield = '', $limit = 0, $offset = 0, array $filter = array(), $filtermode = 'AND') |
|
| 227 | 227 | { |
| 228 | 228 | dol_syslog(__METHOD__, LOG_DEBUG); |
| 229 | 229 | |
@@ -235,24 +235,24 @@ discard block |
||
| 235 | 235 | $sql .= " t.active"; |
| 236 | 236 | |
| 237 | 237 | |
| 238 | - $sql .= ' FROM ' . MAIN_DB_PREFIX . $this->table_element. ' as t'; |
|
| 238 | + $sql .= ' FROM '.MAIN_DB_PREFIX.$this->table_element.' as t'; |
|
| 239 | 239 | |
| 240 | 240 | // Manage filter |
| 241 | 241 | $sqlwhere = array(); |
| 242 | 242 | if (count($filter) > 0) { |
| 243 | 243 | foreach ($filter as $key => $value) { |
| 244 | - $sqlwhere [] = $key . ' LIKE \'%' . $this->db->escape($value) . '%\''; |
|
| 244 | + $sqlwhere [] = $key.' LIKE \'%'.$this->db->escape($value).'%\''; |
|
| 245 | 245 | } |
| 246 | 246 | } |
| 247 | 247 | |
| 248 | 248 | if (count($sqlwhere) > 0) { |
| 249 | - $sql .= ' WHERE ' . implode(' '.$filtermode.' ', $sqlwhere); |
|
| 249 | + $sql .= ' WHERE '.implode(' '.$filtermode.' ', $sqlwhere); |
|
| 250 | 250 | } |
| 251 | 251 | if (!empty($sortfield)) { |
| 252 | - $sql .= $this->db->order($sortfield,$sortorder); |
|
| 252 | + $sql .= $this->db->order($sortfield, $sortorder); |
|
| 253 | 253 | } |
| 254 | 254 | if (!empty($limit)) { |
| 255 | - $sql .= ' ' . $this->db->plimit($limit, $offset); |
|
| 255 | + $sql .= ' '.$this->db->plimit($limit, $offset); |
|
| 256 | 256 | } |
| 257 | 257 | |
| 258 | 258 | $resql = $this->db->query($sql); |
@@ -272,10 +272,10 @@ discard block |
||
| 272 | 272 | |
| 273 | 273 | return $num; |
| 274 | 274 | } else { |
| 275 | - $this->errors[] = 'Error ' . $this->db->lasterror(); |
|
| 276 | - dol_syslog(__METHOD__ . ' ' . implode(',', $this->errors), LOG_ERR); |
|
| 275 | + $this->errors[] = 'Error '.$this->db->lasterror(); |
|
| 276 | + dol_syslog(__METHOD__.' '.implode(',', $this->errors), LOG_ERR); |
|
| 277 | 277 | |
| 278 | - return - 1; |
|
| 278 | + return -1; |
|
| 279 | 279 | } |
| 280 | 280 | } |
| 281 | 281 | |
@@ -309,22 +309,22 @@ discard block |
||
| 309 | 309 | // Put here code to add a control on parameters values |
| 310 | 310 | |
| 311 | 311 | // Update request |
| 312 | - $sql = 'UPDATE ' . MAIN_DB_PREFIX . $this->table_element . ' SET'; |
|
| 312 | + $sql = 'UPDATE '.MAIN_DB_PREFIX.$this->table_element.' SET'; |
|
| 313 | 313 | |
| 314 | - $sql .= ' code = '.(isset($this->code)?"'".$this->db->escape($this->code)."'":"null").','; |
|
| 315 | - $sql .= ' label = '.(isset($this->label)?"'".$this->db->escape($this->label)."'":"null").','; |
|
| 316 | - $sql .= ' active = '.(isset($this->active)?$this->active:"null"); |
|
| 314 | + $sql .= ' code = '.(isset($this->code) ? "'".$this->db->escape($this->code)."'" : "null").','; |
|
| 315 | + $sql .= ' label = '.(isset($this->label) ? "'".$this->db->escape($this->label)."'" : "null").','; |
|
| 316 | + $sql .= ' active = '.(isset($this->active) ? $this->active : "null"); |
|
| 317 | 317 | |
| 318 | 318 | |
| 319 | - $sql .= ' WHERE rowid=' . $this->id; |
|
| 319 | + $sql .= ' WHERE rowid='.$this->id; |
|
| 320 | 320 | |
| 321 | 321 | $this->db->begin(); |
| 322 | 322 | |
| 323 | 323 | $resql = $this->db->query($sql); |
| 324 | 324 | if (!$resql) { |
| 325 | - $error ++; |
|
| 326 | - $this->errors[] = 'Error ' . $this->db->lasterror(); |
|
| 327 | - dol_syslog(__METHOD__ . ' ' . implode(',', $this->errors), LOG_ERR); |
|
| 325 | + $error++; |
|
| 326 | + $this->errors[] = 'Error '.$this->db->lasterror(); |
|
| 327 | + dol_syslog(__METHOD__.' '.implode(',', $this->errors), LOG_ERR); |
|
| 328 | 328 | } |
| 329 | 329 | |
| 330 | 330 | // Uncomment this and change MYOBJECT to your own tag if you |
@@ -341,7 +341,7 @@ discard block |
||
| 341 | 341 | if ($error) { |
| 342 | 342 | $this->db->rollback(); |
| 343 | 343 | |
| 344 | - return - 1 * $error; |
|
| 344 | + return -1 * $error; |
|
| 345 | 345 | } else { |
| 346 | 346 | $this->db->commit(); |
| 347 | 347 | |
@@ -378,14 +378,14 @@ discard block |
||
| 378 | 378 | // If you need to delete child tables to, you can insert them here |
| 379 | 379 | |
| 380 | 380 | if (!$error) { |
| 381 | - $sql = 'DELETE FROM ' . MAIN_DB_PREFIX . $this->table_element; |
|
| 382 | - $sql .= ' WHERE rowid=' . $this->id; |
|
| 381 | + $sql = 'DELETE FROM '.MAIN_DB_PREFIX.$this->table_element; |
|
| 382 | + $sql .= ' WHERE rowid='.$this->id; |
|
| 383 | 383 | |
| 384 | 384 | $resql = $this->db->query($sql); |
| 385 | 385 | if (!$resql) { |
| 386 | - $error ++; |
|
| 387 | - $this->errors[] = 'Error ' . $this->db->lasterror(); |
|
| 388 | - dol_syslog(__METHOD__ . ' ' . implode(',', $this->errors), LOG_ERR); |
|
| 386 | + $error++; |
|
| 387 | + $this->errors[] = 'Error '.$this->db->lasterror(); |
|
| 388 | + dol_syslog(__METHOD__.' '.implode(',', $this->errors), LOG_ERR); |
|
| 389 | 389 | } |
| 390 | 390 | } |
| 391 | 391 | |
@@ -393,7 +393,7 @@ discard block |
||
| 393 | 393 | if ($error) { |
| 394 | 394 | $this->db->rollback(); |
| 395 | 395 | |
| 396 | - return - 1 * $error; |
|
| 396 | + return -1 * $error; |
|
| 397 | 397 | } else { |
| 398 | 398 | $this->db->commit(); |
| 399 | 399 | |
@@ -431,9 +431,9 @@ discard block |
||
| 431 | 431 | |
| 432 | 432 | // Other options |
| 433 | 433 | if ($result < 0) { |
| 434 | - $error ++; |
|
| 434 | + $error++; |
|
| 435 | 435 | $this->errors = $object->errors; |
| 436 | - dol_syslog(__METHOD__ . ' ' . implode(',', $this->errors), LOG_ERR); |
|
| 436 | + dol_syslog(__METHOD__.' '.implode(',', $this->errors), LOG_ERR); |
|
| 437 | 437 | } |
| 438 | 438 | |
| 439 | 439 | // End |
@@ -444,7 +444,7 @@ discard block |
||
| 444 | 444 | } else { |
| 445 | 445 | $this->db->rollback(); |
| 446 | 446 | |
| 447 | - return - 1; |
|
| 447 | + return -1; |
|
| 448 | 448 | } |
| 449 | 449 | } |
| 450 | 450 | |
@@ -22,7 +22,7 @@ discard block |
||
| 22 | 22 | * \ingroup core |
| 23 | 23 | * \brief Fichier de la classe permettant la generation du formulaire html d'envoi de mail unitaire |
| 24 | 24 | */ |
| 25 | -require_once DOL_DOCUMENT_ROOT .'/core/class/html.form.class.php'; |
|
| 25 | +require_once DOL_DOCUMENT_ROOT.'/core/class/html.form.class.php'; |
|
| 26 | 26 | |
| 27 | 27 | |
| 28 | 28 | /** |
@@ -45,7 +45,7 @@ discard block |
||
| 45 | 45 | public $toname; |
| 46 | 46 | public $tomail; |
| 47 | 47 | |
| 48 | - public $withsubstit; // Show substitution array |
|
| 48 | + public $withsubstit; // Show substitution array |
|
| 49 | 49 | public $withfrom; |
| 50 | 50 | public $withto; |
| 51 | 51 | public $withtopic; |
@@ -57,18 +57,18 @@ discard block |
||
| 57 | 57 | public $withtopicreadonly; |
| 58 | 58 | public $withcancel; |
| 59 | 59 | |
| 60 | - public $substit=array(); |
|
| 61 | - public $param=array(); |
|
| 60 | + public $substit = array(); |
|
| 61 | + public $param = array(); |
|
| 62 | 62 | |
| 63 | 63 | /** |
| 64 | 64 | * @var string Error code (or message) |
| 65 | 65 | */ |
| 66 | - public $error=''; |
|
| 66 | + public $error = ''; |
|
| 67 | 67 | |
| 68 | 68 | /** |
| 69 | 69 | * @var string[] Array of error strings |
| 70 | 70 | */ |
| 71 | - public $errors=array(); |
|
| 71 | + public $errors = array(); |
|
| 72 | 72 | |
| 73 | 73 | |
| 74 | 74 | /** |
@@ -80,16 +80,16 @@ discard block |
||
| 80 | 80 | { |
| 81 | 81 | $this->db = $db; |
| 82 | 82 | |
| 83 | - $this->withfrom=1; |
|
| 84 | - $this->withto=1; |
|
| 85 | - $this->withtopic=1; |
|
| 86 | - $this->withbody=1; |
|
| 83 | + $this->withfrom = 1; |
|
| 84 | + $this->withto = 1; |
|
| 85 | + $this->withtopic = 1; |
|
| 86 | + $this->withbody = 1; |
|
| 87 | 87 | |
| 88 | - $this->withfromreadonly=1; |
|
| 89 | - $this->withreplytoreadonly=1; |
|
| 90 | - $this->withtoreadonly=0; |
|
| 91 | - $this->withtopicreadonly=0; |
|
| 92 | - $this->withbodyreadonly=0; |
|
| 88 | + $this->withfromreadonly = 1; |
|
| 89 | + $this->withreplytoreadonly = 1; |
|
| 90 | + $this->withtoreadonly = 0; |
|
| 91 | + $this->withtopicreadonly = 0; |
|
| 92 | + $this->withbodyreadonly = 0; |
|
| 93 | 93 | } |
| 94 | 94 | |
| 95 | 95 | // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps |
@@ -100,17 +100,17 @@ discard block |
||
| 100 | 100 | * @param int $showform Show form tags and submit button (recommanded is to use with value 0) |
| 101 | 101 | * @return void |
| 102 | 102 | */ |
| 103 | - function show_form($morecss='titlefield', $showform=1) |
|
| 103 | + function show_form($morecss = 'titlefield', $showform = 1) |
|
| 104 | 104 | { |
| 105 | 105 | // phpcs:enable |
| 106 | 106 | global $conf, $langs, $user, $form; |
| 107 | 107 | |
| 108 | - if (! is_object($form)) $form=new Form($this->db); |
|
| 108 | + if (!is_object($form)) $form = new Form($this->db); |
|
| 109 | 109 | |
| 110 | 110 | // Load translation files required by the page |
| 111 | 111 | $langs->loadLangs(array('other', 'mails', 'sms')); |
| 112 | 112 | |
| 113 | - $soc=new Societe($this->db); |
|
| 113 | + $soc = new Societe($this->db); |
|
| 114 | 114 | if (!empty($this->withtosocid) && $this->withtosocid > 0) |
| 115 | 115 | { |
| 116 | 116 | $soc->fetch($this->withtosocid); |
@@ -141,15 +141,15 @@ discard block |
||
| 141 | 141 | print "<table class=\"border centpercent\">\n"; |
| 142 | 142 | |
| 143 | 143 | // Substitution array |
| 144 | - if (! empty($this->withsubstit)) // Unset or set ->withsubstit=0 to disable this. |
|
| 144 | + if (!empty($this->withsubstit)) // Unset or set ->withsubstit=0 to disable this. |
|
| 145 | 145 | { |
| 146 | 146 | print "<tr><td colspan=\"2\">"; |
| 147 | - $help=""; |
|
| 148 | - foreach($this->substit as $key => $val) |
|
| 147 | + $help = ""; |
|
| 148 | + foreach ($this->substit as $key => $val) |
|
| 149 | 149 | { |
| 150 | - $help.=$key.' -> '.$langs->trans($val).'<br>'; |
|
| 150 | + $help .= $key.' -> '.$langs->trans($val).'<br>'; |
|
| 151 | 151 | } |
| 152 | - print $form->textwithpicto($langs->trans("SmsTestSubstitutionReplacedByGenericValues"),$help); |
|
| 152 | + print $form->textwithpicto($langs->trans("SmsTestSubstitutionReplacedByGenericValues"), $help); |
|
| 153 | 153 | print "</td></tr>\n"; |
| 154 | 154 | } |
| 155 | 155 | |
@@ -164,7 +164,7 @@ discard block |
||
| 164 | 164 | if ($this->fromtype == 'user') |
| 165 | 165 | { |
| 166 | 166 | $langs->load("users"); |
| 167 | - $fuser=new User($this->db); |
|
| 167 | + $fuser = new User($this->db); |
|
| 168 | 168 | $fuser->fetch($this->fromid); |
| 169 | 169 | print $fuser->getNomUrl(1); |
| 170 | 170 | print ' '; |
@@ -203,19 +203,19 @@ discard block |
||
| 203 | 203 | $resultsender = $sms->SmsSenderList(); |
| 204 | 204 | } |
| 205 | 205 | } |
| 206 | - catch(Exception $e) |
|
| 206 | + catch (Exception $e) |
|
| 207 | 207 | { |
| 208 | - dol_print_error('','Error to get list of senders: '.$e->getMessage()); |
|
| 208 | + dol_print_error('', 'Error to get list of senders: '.$e->getMessage()); |
|
| 209 | 209 | } |
| 210 | 210 | } |
| 211 | 211 | else if (!empty($conf->global->MAIN_SMS_SENDMODE)) // $conf->global->MAIN_SMS_SENDMODE looks like a value 'class@module' |
| 212 | 212 | { |
| 213 | - $tmp=explode('@',$conf->global->MAIN_SMS_SENDMODE); |
|
| 214 | - $classfile=$tmp[0]; $module=(empty($tmp[1])?$tmp[0]:$tmp[1]); |
|
| 213 | + $tmp = explode('@', $conf->global->MAIN_SMS_SENDMODE); |
|
| 214 | + $classfile = $tmp[0]; $module = (empty($tmp[1]) ? $tmp[0] : $tmp[1]); |
|
| 215 | 215 | dol_include_once('/'.$module.'/class/'.$classfile.'.class.php'); |
| 216 | 216 | try |
| 217 | 217 | { |
| 218 | - $classname=ucfirst($classfile); |
|
| 218 | + $classname = ucfirst($classfile); |
|
| 219 | 219 | if (class_exists($classname)) |
| 220 | 220 | { |
| 221 | 221 | $sms = new $classname($this->db); |
@@ -224,26 +224,26 @@ discard block |
||
| 224 | 224 | else |
| 225 | 225 | { |
| 226 | 226 | $sms = new stdClass(); |
| 227 | - $sms->error='The SMS manager "'.$classfile.'" defined into SMS setup MAIN_SMS_SENDMODE is not found'; |
|
| 227 | + $sms->error = 'The SMS manager "'.$classfile.'" defined into SMS setup MAIN_SMS_SENDMODE is not found'; |
|
| 228 | 228 | } |
| 229 | 229 | } |
| 230 | - catch(Exception $e) |
|
| 230 | + catch (Exception $e) |
|
| 231 | 231 | { |
| 232 | - dol_print_error('','Error to get list of senders: '.$e->getMessage()); |
|
| 232 | + dol_print_error('', 'Error to get list of senders: '.$e->getMessage()); |
|
| 233 | 233 | exit; |
| 234 | 234 | } |
| 235 | 235 | } |
| 236 | 236 | else |
| 237 | 237 | { |
| 238 | 238 | dol_syslog("Warning: The SMS sending method has not been defined into MAIN_SMS_SENDMODE", LOG_WARNING); |
| 239 | - $resultsender=array(); |
|
| 240 | - $resultsender[0]->number=$this->fromsms; |
|
| 239 | + $resultsender = array(); |
|
| 240 | + $resultsender[0]->number = $this->fromsms; |
|
| 241 | 241 | } |
| 242 | 242 | |
| 243 | 243 | if (is_array($resultsender) && count($resultsender) > 0) |
| 244 | 244 | { |
| 245 | 245 | print '<select name="fromsms" id="fromsms" class="flat">'; |
| 246 | - foreach($resultsender as $obj) |
|
| 246 | + foreach ($resultsender as $obj) |
|
| 247 | 247 | { |
| 248 | 248 | print '<option value="'.$obj->number.'">'.$obj->number.'</option>'; |
| 249 | 249 | } |
@@ -252,7 +252,7 @@ discard block |
||
| 252 | 252 | else |
| 253 | 253 | { |
| 254 | 254 | print '<span class="error">'.$langs->trans("SmsNoPossibleSenderFound"); |
| 255 | - if (is_object($sms) && ! empty($sms->error)) print ' '.$sms->error; |
|
| 255 | + if (is_object($sms) && !empty($sms->error)) print ' '.$sms->error; |
|
| 256 | 256 | print '</span>'; |
| 257 | 257 | } |
| 258 | 258 | print '</td>'; |
@@ -265,22 +265,22 @@ discard block |
||
| 265 | 265 | { |
| 266 | 266 | print '<tr><td>'; |
| 267 | 267 | //$moretext=$langs->trans("YouCanUseCommaSeparatorForSeveralRecipients"); |
| 268 | - $moretext=''; |
|
| 269 | - print $form->textwithpicto($langs->trans("SmsTo"),$moretext); |
|
| 268 | + $moretext = ''; |
|
| 269 | + print $form->textwithpicto($langs->trans("SmsTo"), $moretext); |
|
| 270 | 270 | print '</td><td>'; |
| 271 | 271 | if ($this->withtoreadonly) |
| 272 | 272 | { |
| 273 | - print (! is_array($this->withto) && ! is_numeric($this->withto))?$this->withto:""; |
|
| 273 | + print (!is_array($this->withto) && !is_numeric($this->withto)) ? $this->withto : ""; |
|
| 274 | 274 | } |
| 275 | 275 | else |
| 276 | 276 | { |
| 277 | - print "<input size=\"16\" id=\"sendto\" name=\"sendto\" value=\"".dol_escape_htmltag(! is_array($this->withto) && $this->withto != '1'? (isset($_REQUEST["sendto"])?GETPOST("sendto"):$this->withto):"+")."\">"; |
|
| 278 | - if (! empty($this->withtosocid) && $this->withtosocid > 0) |
|
| 277 | + print "<input size=\"16\" id=\"sendto\" name=\"sendto\" value=\"".dol_escape_htmltag(!is_array($this->withto) && $this->withto != '1' ? (isset($_REQUEST["sendto"]) ?GETPOST("sendto") : $this->withto) : "+")."\">"; |
|
| 278 | + if (!empty($this->withtosocid) && $this->withtosocid > 0) |
|
| 279 | 279 | { |
| 280 | - $liste=array(); |
|
| 280 | + $liste = array(); |
|
| 281 | 281 | foreach ($soc->thirdparty_and_contact_phone_array() as $key => $value) |
| 282 | 282 | { |
| 283 | - $liste[$key]=$value; |
|
| 283 | + $liste[$key] = $value; |
|
| 284 | 284 | } |
| 285 | 285 | print " ".$langs->trans("or")." "; |
| 286 | 286 | //var_dump($_REQUEST);exit; |
@@ -294,14 +294,14 @@ discard block |
||
| 294 | 294 | // Message |
| 295 | 295 | if ($this->withbody) |
| 296 | 296 | { |
| 297 | - $defaultmessage=''; |
|
| 298 | - if ($this->param["models"]=='body') |
|
| 297 | + $defaultmessage = ''; |
|
| 298 | + if ($this->param["models"] == 'body') |
|
| 299 | 299 | { |
| 300 | - $defaultmessage=$this->withbody; |
|
| 300 | + $defaultmessage = $this->withbody; |
|
| 301 | 301 | } |
| 302 | - $defaultmessage=make_substitutions($defaultmessage,$this->substit); |
|
| 303 | - if (isset($_POST["message"])) $defaultmessage=$_POST["message"]; |
|
| 304 | - $defaultmessage=str_replace('\n',"\n",$defaultmessage); |
|
| 302 | + $defaultmessage = make_substitutions($defaultmessage, $this->substit); |
|
| 303 | + if (isset($_POST["message"])) $defaultmessage = $_POST["message"]; |
|
| 304 | + $defaultmessage = str_replace('\n', "\n", $defaultmessage); |
|
| 305 | 305 | |
| 306 | 306 | print "<tr>"; |
| 307 | 307 | print '<td class="tdtop">'.$langs->trans("SmsText")."</td>"; |
@@ -314,7 +314,7 @@ discard block |
||
| 314 | 314 | else |
| 315 | 315 | { |
| 316 | 316 | print '<textarea class="quatrevingtpercent" name="message" id="message" rows="'.ROWS_4.'" onkeyup="limitChars(this, 160, \'charlimitinfospan\')">'.$defaultmessage.'</textarea>'; |
| 317 | - print '<div id="charlimitinfo">'.$langs->trans("SmsInfoCharRemain").': <span id="charlimitinfospan">'.(160-dol_strlen($defaultmessage)).'</span></div></td>'; |
|
| 317 | + print '<div id="charlimitinfo">'.$langs->trans("SmsInfoCharRemain").': <span id="charlimitinfospan">'.(160 - dol_strlen($defaultmessage)).'</span></div></td>'; |
|
| 318 | 318 | } |
| 319 | 319 | print "</td></tr>\n"; |
| 320 | 320 | } |
@@ -34,9 +34,9 @@ discard block |
||
| 34 | 34 | /** |
| 35 | 35 | * @var string Error code (or message) |
| 36 | 36 | */ |
| 37 | - public $error=''; |
|
| 37 | + public $error = ''; |
|
| 38 | 38 | |
| 39 | - private $_format=''; |
|
| 39 | + private $_format = ''; |
|
| 40 | 40 | private $_urlRSS; |
| 41 | 41 | private $_language; |
| 42 | 42 | private $_generator; |
@@ -46,8 +46,8 @@ discard block |
||
| 46 | 46 | private $_link; |
| 47 | 47 | private $_title; |
| 48 | 48 | private $_description; |
| 49 | - private $_lastfetchdate; // Last successful fetch |
|
| 50 | - private $_rssarray=array(); |
|
| 49 | + private $_lastfetchdate; // Last successful fetch |
|
| 50 | + private $_rssarray = array(); |
|
| 51 | 51 | |
| 52 | 52 | // For parsing with xmlparser |
| 53 | 53 | var $stack = array(); // parser stack |
@@ -184,40 +184,40 @@ discard block |
||
| 184 | 184 | * @param string $cachedir Directory where to save cache file |
| 185 | 185 | * @return int <0 if KO, >0 if OK |
| 186 | 186 | */ |
| 187 | - public function parser($urlRSS, $maxNb=0, $cachedelay=60, $cachedir='') |
|
| 187 | + public function parser($urlRSS, $maxNb = 0, $cachedelay = 60, $cachedir = '') |
|
| 188 | 188 | { |
| 189 | 189 | global $conf; |
| 190 | 190 | |
| 191 | 191 | include_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php'; |
| 192 | 192 | |
| 193 | - $rss=''; |
|
| 194 | - $str=''; // This will contain content of feed |
|
| 193 | + $rss = ''; |
|
| 194 | + $str = ''; // This will contain content of feed |
|
| 195 | 195 | |
| 196 | 196 | // Check parameters |
| 197 | - if (! dol_is_url($urlRSS)) |
|
| 197 | + if (!dol_is_url($urlRSS)) |
|
| 198 | 198 | { |
| 199 | - $this->error="ErrorBadUrl"; |
|
| 199 | + $this->error = "ErrorBadUrl"; |
|
| 200 | 200 | return -1; |
| 201 | 201 | } |
| 202 | 202 | |
| 203 | 203 | $this->_urlRSS = $urlRSS; |
| 204 | - $newpathofdestfile=$cachedir.'/'.dol_hash($this->_urlRSS,3); // Force md5 hash (does not contains special chars) |
|
| 205 | - $newmask='0644'; |
|
| 204 | + $newpathofdestfile = $cachedir.'/'.dol_hash($this->_urlRSS, 3); // Force md5 hash (does not contains special chars) |
|
| 205 | + $newmask = '0644'; |
|
| 206 | 206 | |
| 207 | 207 | //dol_syslog("RssPArser::parser parse url=".$urlRSS." => cache file=".$newpathofdestfile); |
| 208 | 208 | $nowgmt = dol_now(); |
| 209 | 209 | |
| 210 | 210 | // Search into cache |
| 211 | - $foundintocache=0; |
|
| 211 | + $foundintocache = 0; |
|
| 212 | 212 | if ($cachedelay > 0 && $cachedir) |
| 213 | 213 | { |
| 214 | - $filedate=dol_filemtime($newpathofdestfile); |
|
| 214 | + $filedate = dol_filemtime($newpathofdestfile); |
|
| 215 | 215 | if ($filedate >= ($nowgmt - $cachedelay)) |
| 216 | 216 | { |
| 217 | 217 | //dol_syslog("RssParser::parser cache file ".$newpathofdestfile." is not older than now - cachedelay (".$nowgmt." - ".$cachedelay.") so we use it."); |
| 218 | - $foundintocache=1; |
|
| 218 | + $foundintocache = 1; |
|
| 219 | 219 | |
| 220 | - $this->_lastfetchdate=$filedate; |
|
| 220 | + $this->_lastfetchdate = $filedate; |
|
| 221 | 221 | } |
| 222 | 222 | else |
| 223 | 223 | { |
@@ -233,13 +233,13 @@ discard block |
||
| 233 | 233 | else |
| 234 | 234 | { |
| 235 | 235 | try { |
| 236 | - ini_set("user_agent","Dolibarr ERP-CRM RSS reader"); |
|
| 236 | + ini_set("user_agent", "Dolibarr ERP-CRM RSS reader"); |
|
| 237 | 237 | ini_set("max_execution_time", $conf->global->MAIN_USE_RESPONSE_TIMEOUT); |
| 238 | 238 | ini_set("default_socket_timeout", $conf->global->MAIN_USE_RESPONSE_TIMEOUT); |
| 239 | 239 | |
| 240 | 240 | $opts = array('http'=>array('method'=>"GET")); |
| 241 | - if (! empty($conf->global->MAIN_USE_CONNECT_TIMEOUT)) $opts['http']['timeout']=$conf->global->MAIN_USE_CONNECT_TIMEOUT; |
|
| 242 | - if (! empty($conf->global->MAIN_PROXY_USE)) $opts['http']['proxy']='tcp://'.$conf->global->MAIN_PROXY_HOST.':'.$conf->global->MAIN_PROXY_PORT; |
|
| 241 | + if (!empty($conf->global->MAIN_USE_CONNECT_TIMEOUT)) $opts['http']['timeout'] = $conf->global->MAIN_USE_CONNECT_TIMEOUT; |
|
| 242 | + if (!empty($conf->global->MAIN_PROXY_USE)) $opts['http']['proxy'] = 'tcp://'.$conf->global->MAIN_PROXY_HOST.':'.$conf->global->MAIN_PROXY_PORT; |
|
| 243 | 243 | //var_dump($opts);exit; |
| 244 | 244 | $context = stream_context_create($opts); |
| 245 | 245 | |
@@ -253,7 +253,7 @@ discard block |
||
| 253 | 253 | if ($str !== false) |
| 254 | 254 | { |
| 255 | 255 | // Convert $str into xml |
| 256 | - if (! empty($conf->global->EXTERNALRSS_USE_SIMPLEXML)) |
|
| 256 | + if (!empty($conf->global->EXTERNALRSS_USE_SIMPLEXML)) |
|
| 257 | 257 | { |
| 258 | 258 | //print 'xx'.LIBXML_NOCDATA; |
| 259 | 259 | libxml_use_internal_errors(false); |
@@ -261,9 +261,9 @@ discard block |
||
| 261 | 261 | } |
| 262 | 262 | else |
| 263 | 263 | { |
| 264 | - $xmlparser=xml_parser_create(''); |
|
| 264 | + $xmlparser = xml_parser_create(''); |
|
| 265 | 265 | if (!is_resource($xmlparser)) { |
| 266 | - $this->error="ErrorFailedToCreateParser"; return -1; |
|
| 266 | + $this->error = "ErrorFailedToCreateParser"; return -1; |
|
| 267 | 267 | } |
| 268 | 268 | |
| 269 | 269 | xml_set_object($xmlparser, $this); |
@@ -271,7 +271,7 @@ discard block |
||
| 271 | 271 | xml_set_character_data_handler($xmlparser, 'feed_cdata'); |
| 272 | 272 | $status = xml_parse($xmlparser, $str); |
| 273 | 273 | xml_parser_free($xmlparser); |
| 274 | - $rss=$this; |
|
| 274 | + $rss = $this; |
|
| 275 | 275 | //var_dump($rss->_format);exit; |
| 276 | 276 | } |
| 277 | 277 | } |
@@ -283,16 +283,16 @@ discard block |
||
| 283 | 283 | if (empty($foundintocache) && $cachedir) |
| 284 | 284 | { |
| 285 | 285 | dol_syslog(get_class($this)."::parser cache file ".$newpathofdestfile." is saved onto disk."); |
| 286 | - if (! dol_is_dir($cachedir)) dol_mkdir($cachedir); |
|
| 286 | + if (!dol_is_dir($cachedir)) dol_mkdir($cachedir); |
|
| 287 | 287 | $fp = fopen($newpathofdestfile, 'w'); |
| 288 | 288 | if ($fp) |
| 289 | 289 | { |
| 290 | 290 | fwrite($fp, $str); |
| 291 | 291 | fclose($fp); |
| 292 | - if (! empty($conf->global->MAIN_UMASK)) $newmask=$conf->global->MAIN_UMASK; |
|
| 292 | + if (!empty($conf->global->MAIN_UMASK)) $newmask = $conf->global->MAIN_UMASK; |
|
| 293 | 293 | @chmod($newpathofdestfile, octdec($newmask)); |
| 294 | 294 | |
| 295 | - $this->_lastfetchdate=$nowgmt; |
|
| 295 | + $this->_lastfetchdate = $nowgmt; |
|
| 296 | 296 | } |
| 297 | 297 | else |
| 298 | 298 | { |
@@ -300,21 +300,21 @@ discard block |
||
| 300 | 300 | } |
| 301 | 301 | } |
| 302 | 302 | |
| 303 | - unset($str); // Free memory |
|
| 303 | + unset($str); // Free memory |
|
| 304 | 304 | |
| 305 | 305 | if (empty($rss->_format)) // If format not detected automatically |
| 306 | 306 | { |
| 307 | - $rss->_format='rss'; |
|
| 308 | - if (empty($rss->channel)) $rss->_format='atom'; |
|
| 307 | + $rss->_format = 'rss'; |
|
| 308 | + if (empty($rss->channel)) $rss->_format = 'atom'; |
|
| 309 | 309 | } |
| 310 | 310 | |
| 311 | - $items=array(); |
|
| 311 | + $items = array(); |
|
| 312 | 312 | |
| 313 | 313 | // Save description entries |
| 314 | 314 | if ($rss->_format == 'rss') |
| 315 | 315 | { |
| 316 | 316 | //var_dump($rss); |
| 317 | - if (! empty($conf->global->EXTERNALRSS_USE_SIMPLEXML)) |
|
| 317 | + if (!empty($conf->global->EXTERNALRSS_USE_SIMPLEXML)) |
|
| 318 | 318 | { |
| 319 | 319 | if (!empty($rss->channel->language)) $this->_language = (string) $rss->channel->language; |
| 320 | 320 | if (!empty($rss->channel->generator)) $this->_generator = (string) $rss->channel->generator; |
@@ -338,14 +338,14 @@ discard block |
||
| 338 | 338 | if (!empty($rss->channel['description'])) $this->_description = (string) $rss->channel['description']; |
| 339 | 339 | } |
| 340 | 340 | |
| 341 | - if (! empty($conf->global->EXTERNALRSS_USE_SIMPLEXML)) $items=$rss->channel->item; // With simplexml |
|
| 342 | - else $items=$rss->items; // With xmlparse |
|
| 341 | + if (!empty($conf->global->EXTERNALRSS_USE_SIMPLEXML)) $items = $rss->channel->item; // With simplexml |
|
| 342 | + else $items = $rss->items; // With xmlparse |
|
| 343 | 343 | //var_dump($items);exit; |
| 344 | 344 | } |
| 345 | 345 | else if ($rss->_format == 'atom') |
| 346 | 346 | { |
| 347 | 347 | //var_dump($rss); |
| 348 | - if (! empty($conf->global->EXTERNALRSS_USE_SIMPLEXML)) |
|
| 348 | + if (!empty($conf->global->EXTERNALRSS_USE_SIMPLEXML)) |
|
| 349 | 349 | { |
| 350 | 350 | if (!empty($rss->generator)) $this->_generator = (string) $rss->generator; |
| 351 | 351 | if (!empty($rss->lastbuilddate)) $this->_lastbuilddate = (string) $rss->modified; |
@@ -364,10 +364,10 @@ discard block |
||
| 364 | 364 | if (!empty($rss->channel['title'])) $this->_title = (string) $rss->channel['title']; |
| 365 | 365 | //if (!empty($rss->channel['rss_description'])) $this->_description = (string) $rss->channel['rss_description']; |
| 366 | 366 | } |
| 367 | - if (! empty($conf->global->EXTERNALRSS_USE_SIMPLEXML)) { |
|
| 368 | - $tmprss=xml2php($rss); $items=$tmprss['entry']; |
|
| 367 | + if (!empty($conf->global->EXTERNALRSS_USE_SIMPLEXML)) { |
|
| 368 | + $tmprss = xml2php($rss); $items = $tmprss['entry']; |
|
| 369 | 369 | } // With simplexml |
| 370 | - else $items=$rss->items; // With xmlparse |
|
| 370 | + else $items = $rss->items; // With xmlparse |
|
| 371 | 371 | //var_dump($items);exit; |
| 372 | 372 | } |
| 373 | 373 | |
@@ -376,12 +376,12 @@ discard block |
||
| 376 | 376 | // Loop on each record |
| 377 | 377 | if (is_array($items)) |
| 378 | 378 | { |
| 379 | - foreach($items as $item) |
|
| 379 | + foreach ($items as $item) |
|
| 380 | 380 | { |
| 381 | 381 | //var_dump($item);exit; |
| 382 | 382 | if ($rss->_format == 'rss') |
| 383 | 383 | { |
| 384 | - if (! empty($conf->global->EXTERNALRSS_USE_SIMPLEXML)) |
|
| 384 | + if (!empty($conf->global->EXTERNALRSS_USE_SIMPLEXML)) |
|
| 385 | 385 | { |
| 386 | 386 | $itemLink = (string) $item->link; |
| 387 | 387 | $itemTitle = (string) $item->title; |
@@ -401,7 +401,7 @@ discard block |
||
| 401 | 401 | } |
| 402 | 402 | |
| 403 | 403 | // Loop on each category |
| 404 | - $itemCategory=array(); |
|
| 404 | + $itemCategory = array(); |
|
| 405 | 405 | if (is_array($item->category)) |
| 406 | 406 | { |
| 407 | 407 | foreach ($item->category as $cat) |
@@ -412,14 +412,14 @@ discard block |
||
| 412 | 412 | } |
| 413 | 413 | else if ($rss->_format == 'atom') |
| 414 | 414 | { |
| 415 | - if (! empty($conf->global->EXTERNALRSS_USE_SIMPLEXML)) |
|
| 415 | + if (!empty($conf->global->EXTERNALRSS_USE_SIMPLEXML)) |
|
| 416 | 416 | { |
| 417 | 417 | $itemLink = (isset($item['link']['href']) ? (string) $item['link']['href'] : ''); |
| 418 | 418 | $itemTitle = (string) $item['title']; |
| 419 | 419 | $itemDescription = (string) $item['summary']; |
| 420 | 420 | $itemPubDate = (string) $item['created']; |
| 421 | 421 | $itemId = (string) $item['id']; |
| 422 | - $itemAuthor = (string) ($item['author']?$item['author']:$item['author_name']); |
|
| 422 | + $itemAuthor = (string) ($item['author'] ? $item['author'] : $item['author_name']); |
|
| 423 | 423 | } |
| 424 | 424 | else |
| 425 | 425 | { |
@@ -428,7 +428,7 @@ discard block |
||
| 428 | 428 | $itemDescription = (string) $item['summary']; |
| 429 | 429 | $itemPubDate = (string) $item['created']; |
| 430 | 430 | $itemId = (string) $item['id']; |
| 431 | - $itemAuthor = (string) ($item['author']?$item['author']:$item['author_name']); |
|
| 431 | + $itemAuthor = (string) ($item['author'] ? $item['author'] : $item['author_name']); |
|
| 432 | 432 | } |
| 433 | 433 | } |
| 434 | 434 | else print 'ErrorBadFeedFormat'; |
@@ -446,7 +446,7 @@ discard block |
||
| 446 | 446 | |
| 447 | 447 | $i++; |
| 448 | 448 | |
| 449 | - if ($i > $maxNb) break; // We get all records we want |
|
| 449 | + if ($i > $maxNb) break; // We get all records we want |
|
| 450 | 450 | } |
| 451 | 451 | } |
| 452 | 452 | |
@@ -454,7 +454,7 @@ discard block |
||
| 454 | 454 | } |
| 455 | 455 | else |
| 456 | 456 | { |
| 457 | - $this->error='ErrorFailedToLoadRSSFile'; |
|
| 457 | + $this->error = 'ErrorFailedToLoadRSSFile'; |
|
| 458 | 458 | return -1; |
| 459 | 459 | } |
| 460 | 460 | } |
@@ -482,7 +482,7 @@ discard block |
||
| 482 | 482 | { |
| 483 | 483 | list($ns, $el) = explode(':', $element, 2); |
| 484 | 484 | } |
| 485 | - if ( $ns and $ns != 'rdf' ) |
|
| 485 | + if ($ns and $ns != 'rdf') |
|
| 486 | 486 | { |
| 487 | 487 | $this->current_namespace = $ns; |
| 488 | 488 | } |
@@ -490,15 +490,15 @@ discard block |
||
| 490 | 490 | // if feed type isn't set, then this is first element of feed identify feed from root element |
| 491 | 491 | if (empty($this->_format)) |
| 492 | 492 | { |
| 493 | - if ( $el == 'rdf' ) { |
|
| 493 | + if ($el == 'rdf') { |
|
| 494 | 494 | $this->_format = 'rss'; |
| 495 | 495 | $this->feed_version = '1.0'; |
| 496 | 496 | } |
| 497 | - elseif ( $el == 'rss' ) { |
|
| 497 | + elseif ($el == 'rss') { |
|
| 498 | 498 | $this->_format = 'rss'; |
| 499 | 499 | $this->feed_version = $attrs['version']; |
| 500 | 500 | } |
| 501 | - elseif ( $el == 'feed' ) { |
|
| 501 | + elseif ($el == 'feed') { |
|
| 502 | 502 | $this->_format = 'atom'; |
| 503 | 503 | $this->feed_version = $attrs['version']; |
| 504 | 504 | $this->inchannel = true; |
@@ -506,14 +506,14 @@ discard block |
||
| 506 | 506 | return; |
| 507 | 507 | } |
| 508 | 508 | |
| 509 | - if ( $el == 'channel' ) |
|
| 509 | + if ($el == 'channel') |
|
| 510 | 510 | { |
| 511 | 511 | $this->inchannel = true; |
| 512 | 512 | } |
| 513 | - elseif ($el == 'item' or $el == 'entry' ) |
|
| 513 | + elseif ($el == 'item' or $el == 'entry') |
|
| 514 | 514 | { |
| 515 | 515 | $this->initem = true; |
| 516 | - if ( isset($attrs['rdf:about']) ) { |
|
| 516 | + if (isset($attrs['rdf:about'])) { |
|
| 517 | 517 | $this->current_item['about'] = $attrs['rdf:about']; |
| 518 | 518 | } |
| 519 | 519 | } |
@@ -537,10 +537,10 @@ discard block |
||
| 537 | 537 | } |
| 538 | 538 | |
| 539 | 539 | // handle atom content constructs |
| 540 | - elseif ( $this->_format == 'atom' and in_array($el, $this->_CONTENT_CONSTRUCTS) ) |
|
| 540 | + elseif ($this->_format == 'atom' and in_array($el, $this->_CONTENT_CONSTRUCTS)) |
|
| 541 | 541 | { |
| 542 | 542 | // avoid clashing w/ RSS mod_content |
| 543 | - if ($el == 'content' ) { |
|
| 543 | + if ($el == 'content') { |
|
| 544 | 544 | $el = 'atom_content'; |
| 545 | 545 | } |
| 546 | 546 | |
@@ -548,7 +548,7 @@ discard block |
||
| 548 | 548 | } |
| 549 | 549 | |
| 550 | 550 | // if inside an Atom content construct (e.g. content or summary) field treat tags as text |
| 551 | - elseif ($this->_format == 'atom' and $this->incontent ) |
|
| 551 | + elseif ($this->_format == 'atom' and $this->incontent) |
|
| 552 | 552 | { |
| 553 | 553 | // if tags are inlined, then flatten |
| 554 | 554 | $attrs_str = join(' ', array_map('map_attrs', array_keys($attrs), array_values($attrs))); |
@@ -562,14 +562,14 @@ discard block |
||
| 562 | 562 | // Magpie treats link elements of type rel='alternate' |
| 563 | 563 | // as being equivalent to RSS's simple link element. |
| 564 | 564 | // |
| 565 | - elseif ($this->_format == 'atom' and $el == 'link' ) |
|
| 565 | + elseif ($this->_format == 'atom' and $el == 'link') |
|
| 566 | 566 | { |
| 567 | - if ( isset($attrs['rel']) && $attrs['rel'] == 'alternate' ) |
|
| 567 | + if (isset($attrs['rel']) && $attrs['rel'] == 'alternate') |
|
| 568 | 568 | { |
| 569 | 569 | $link_el = 'link'; |
| 570 | 570 | } |
| 571 | 571 | else { |
| 572 | - $link_el = 'link_' . $attrs['rel']; |
|
| 572 | + $link_el = 'link_'.$attrs['rel']; |
|
| 573 | 573 | } |
| 574 | 574 | |
| 575 | 575 | $this->append($link_el, $attrs['href']); |
@@ -622,26 +622,26 @@ discard block |
||
| 622 | 622 | $this->current_item = array(); |
| 623 | 623 | $this->initem = false; |
| 624 | 624 | } |
| 625 | - elseif ($this->_format == 'rss' and $this->current_namespace == '' and $el == 'textinput' ) |
|
| 625 | + elseif ($this->_format == 'rss' and $this->current_namespace == '' and $el == 'textinput') |
|
| 626 | 626 | { |
| 627 | 627 | $this->intextinput = false; |
| 628 | 628 | } |
| 629 | - elseif ($this->_format == 'rss' and $this->current_namespace == '' and $el == 'image' ) |
|
| 629 | + elseif ($this->_format == 'rss' and $this->current_namespace == '' and $el == 'image') |
|
| 630 | 630 | { |
| 631 | 631 | $this->inimage = false; |
| 632 | 632 | } |
| 633 | - elseif ($this->_format == 'atom' and in_array($el, $this->_CONTENT_CONSTRUCTS) ) |
|
| 633 | + elseif ($this->_format == 'atom' and in_array($el, $this->_CONTENT_CONSTRUCTS)) |
|
| 634 | 634 | { |
| 635 | 635 | $this->incontent = false; |
| 636 | 636 | } |
| 637 | - elseif ($el == 'channel' or $el == 'feed' ) |
|
| 637 | + elseif ($el == 'channel' or $el == 'feed') |
|
| 638 | 638 | { |
| 639 | 639 | $this->inchannel = false; |
| 640 | 640 | } |
| 641 | - elseif ($this->_format == 'atom' and $this->incontent ) { |
|
| 641 | + elseif ($this->_format == 'atom' and $this->incontent) { |
|
| 642 | 642 | // balance tags properly |
| 643 | 643 | // note: i don't think this is actually neccessary |
| 644 | - if ( $this->stack[0] == $el ) |
|
| 644 | + if ($this->stack[0] == $el) |
|
| 645 | 645 | { |
| 646 | 646 | $this->append_content("</$el>"); |
| 647 | 647 | } |
@@ -666,10 +666,10 @@ discard block |
||
| 666 | 666 | * @param string $str2 Str2 |
| 667 | 667 | * @return string String cancatenated |
| 668 | 668 | */ |
| 669 | - function concat(&$str1, $str2="") |
|
| 669 | + function concat(&$str1, $str2 = "") |
|
| 670 | 670 | { |
| 671 | - if (!isset($str1) ) { |
|
| 672 | - $str1=""; |
|
| 671 | + if (!isset($str1)) { |
|
| 672 | + $str1 = ""; |
|
| 673 | 673 | } |
| 674 | 674 | $str1 .= $str2; |
| 675 | 675 | } |
@@ -684,11 +684,11 @@ discard block |
||
| 684 | 684 | function append_content($text) |
| 685 | 685 | { |
| 686 | 686 | // phpcs:enable |
| 687 | - if ( $this->initem ) { |
|
| 688 | - $this->concat($this->current_item[ $this->incontent ], $text); |
|
| 687 | + if ($this->initem) { |
|
| 688 | + $this->concat($this->current_item[$this->incontent], $text); |
|
| 689 | 689 | } |
| 690 | - elseif ( $this->inchannel ) { |
|
| 691 | - $this->concat($this->channel[ $this->incontent ], $text); |
|
| 690 | + elseif ($this->inchannel) { |
|
| 691 | + $this->concat($this->channel[$this->incontent], $text); |
|
| 692 | 692 | } |
| 693 | 693 | } |
| 694 | 694 | |
@@ -704,33 +704,33 @@ discard block |
||
| 704 | 704 | if (!$el) { |
| 705 | 705 | return; |
| 706 | 706 | } |
| 707 | - if ( $this->current_namespace ) |
|
| 707 | + if ($this->current_namespace) |
|
| 708 | 708 | { |
| 709 | - if ( $this->initem ) { |
|
| 710 | - $this->concat($this->current_item[ $this->current_namespace ][ $el ], $text); |
|
| 709 | + if ($this->initem) { |
|
| 710 | + $this->concat($this->current_item[$this->current_namespace][$el], $text); |
|
| 711 | 711 | } |
| 712 | 712 | elseif ($this->inchannel) { |
| 713 | - $this->concat($this->channel[ $this->current_namespace][ $el ], $text); |
|
| 713 | + $this->concat($this->channel[$this->current_namespace][$el], $text); |
|
| 714 | 714 | } |
| 715 | 715 | elseif ($this->intextinput) { |
| 716 | - $this->concat($this->textinput[ $this->current_namespace][ $el ], $text); |
|
| 716 | + $this->concat($this->textinput[$this->current_namespace][$el], $text); |
|
| 717 | 717 | } |
| 718 | 718 | elseif ($this->inimage) { |
| 719 | - $this->concat($this->image[ $this->current_namespace ][ $el ], $text); |
|
| 719 | + $this->concat($this->image[$this->current_namespace][$el], $text); |
|
| 720 | 720 | } |
| 721 | 721 | } |
| 722 | 722 | else { |
| 723 | - if ( $this->initem ) { |
|
| 724 | - $this->concat($this->current_item[ $el ], $text); |
|
| 723 | + if ($this->initem) { |
|
| 724 | + $this->concat($this->current_item[$el], $text); |
|
| 725 | 725 | } |
| 726 | 726 | elseif ($this->intextinput) { |
| 727 | - $this->concat($this->textinput[ $el ], $text); |
|
| 727 | + $this->concat($this->textinput[$el], $text); |
|
| 728 | 728 | } |
| 729 | 729 | elseif ($this->inimage) { |
| 730 | - $this->concat($this->image[ $el ], $text); |
|
| 730 | + $this->concat($this->image[$el], $text); |
|
| 731 | 731 | } |
| 732 | 732 | elseif ($this->inchannel) { |
| 733 | - $this->concat($this->channel[ $el ], $text); |
|
| 733 | + $this->concat($this->channel[$el], $text); |
|
| 734 | 734 | } |
| 735 | 735 | } |
| 736 | 736 | } |
@@ -748,18 +748,18 @@ discard block |
||
| 748 | 748 | $fils = 0; |
| 749 | 749 | $tab = false; |
| 750 | 750 | $array = array(); |
| 751 | - foreach($xml->children() as $key => $value) |
|
| 751 | + foreach ($xml->children() as $key => $value) |
|
| 752 | 752 | { |
| 753 | 753 | $child = xml2php($value); |
| 754 | 754 | |
| 755 | 755 | //To deal with the attributes |
| 756 | - foreach($value->attributes() as $ak=>$av) |
|
| 756 | + foreach ($value->attributes() as $ak=>$av) |
|
| 757 | 757 | { |
| 758 | 758 | $child[$ak] = (string) $av; |
| 759 | 759 | } |
| 760 | 760 | |
| 761 | 761 | //Let see if the new child is not in the array |
| 762 | - if ($tab === false && in_array($key,array_keys($array))) |
|
| 762 | + if ($tab === false && in_array($key, array_keys($array))) |
|
| 763 | 763 | { |
| 764 | 764 | //If this element is already in the array we will create an indexed array |
| 765 | 765 | $tmp = $array[$key]; |
@@ -768,7 +768,7 @@ discard block |
||
| 768 | 768 | $array[$key][] = $child; |
| 769 | 769 | $tab = true; |
| 770 | 770 | } |
| 771 | - elseif($tab === true) |
|
| 771 | + elseif ($tab === true) |
|
| 772 | 772 | { |
| 773 | 773 | //Add an element in an existing array |
| 774 | 774 | $array[$key][] = $child; |
@@ -783,7 +783,7 @@ discard block |
||
| 783 | 783 | } |
| 784 | 784 | |
| 785 | 785 | |
| 786 | - if ($fils==0) |
|
| 786 | + if ($fils == 0) |
|
| 787 | 787 | { |
| 788 | 788 | return (string) $xml; |
| 789 | 789 | } |
@@ -20,7 +20,7 @@ discard block |
||
| 20 | 20 | * \ingroup core |
| 21 | 21 | * \brief File of class of generic business class |
| 22 | 22 | */ |
| 23 | -require_once DOL_DOCUMENT_ROOT .'/core/class/commonobject.class.php'; |
|
| 23 | +require_once DOL_DOCUMENT_ROOT.'/core/class/commonobject.class.php'; |
|
| 24 | 24 | |
| 25 | 25 | |
| 26 | 26 | /** |
@@ -36,6 +36,6 @@ discard block |
||
| 36 | 36 | */ |
| 37 | 37 | function __construct($db) |
| 38 | 38 | { |
| 39 | - $this->db=$db; |
|
| 39 | + $this->db = $db; |
|
| 40 | 40 | } |
| 41 | 41 | } |
@@ -65,9 +65,9 @@ discard block |
||
| 65 | 65 | * @param string $prefix Prefix to title (image or picto) |
| 66 | 66 | * @return void |
| 67 | 67 | */ |
| 68 | - function add($url, $titre, $level=0, $enabled=1, $target='',$mainmenu='',$leftmenu='',$position=0, $id='', $idsel='', $classname='', $prefix='') |
|
| 68 | + function add($url, $titre, $level = 0, $enabled = 1, $target = '', $mainmenu = '', $leftmenu = '', $position = 0, $id = '', $idsel = '', $classname = '', $prefix = '') |
|
| 69 | 69 | { |
| 70 | - $this->liste[]=array('url'=>$url,'titre'=>$titre,'level'=>$level,'enabled'=>$enabled,'target'=>$target,'mainmenu'=>$mainmenu,'leftmenu'=>$leftmenu, 'position'=>$position, 'id'=>$id, 'idsel'=>$idsel, 'classname'=>$classname, 'prefix'=>$prefix); |
|
| 70 | + $this->liste[] = array('url'=>$url, 'titre'=>$titre, 'level'=>$level, 'enabled'=>$enabled, 'target'=>$target, 'mainmenu'=>$mainmenu, 'leftmenu'=>$leftmenu, 'position'=>$position, 'id'=>$id, 'idsel'=>$idsel, 'classname'=>$classname, 'prefix'=>$prefix); |
|
| 71 | 71 | } |
| 72 | 72 | |
| 73 | 73 | /** |
@@ -88,12 +88,12 @@ discard block |
||
| 88 | 88 | * @param string $prefix Prefix to title (image or picto) |
| 89 | 89 | * @return void |
| 90 | 90 | */ |
| 91 | - function insert($idafter, $url, $titre, $level=0, $enabled=1, $target='',$mainmenu='',$leftmenu='',$position=0, $id='', $idsel='', $classname='', $prefix='') |
|
| 91 | + function insert($idafter, $url, $titre, $level = 0, $enabled = 1, $target = '', $mainmenu = '', $leftmenu = '', $position = 0, $id = '', $idsel = '', $classname = '', $prefix = '') |
|
| 92 | 92 | { |
| 93 | - $array_start = array_slice($this->liste,0,($idafter+1)); |
|
| 94 | - $array_new = array(0=>array('url'=>$url,'titre'=>$titre,'level'=>$level,'enabled'=>$enabled,'target'=>$target,'mainmenu'=>$mainmenu,'leftmenu'=>$leftmenu,'position'=>$position, 'id'=>$id, 'idsel'=>$idsel, 'classname'=>$classname, 'prefix'=>$prefix)); |
|
| 95 | - $array_end = array_slice($this->liste,($idafter+1)); |
|
| 96 | - $this->liste=array_merge($array_start,$array_new,$array_end); |
|
| 93 | + $array_start = array_slice($this->liste, 0, ($idafter + 1)); |
|
| 94 | + $array_new = array(0=>array('url'=>$url, 'titre'=>$titre, 'level'=>$level, 'enabled'=>$enabled, 'target'=>$target, 'mainmenu'=>$mainmenu, 'leftmenu'=>$leftmenu, 'position'=>$position, 'id'=>$id, 'idsel'=>$idsel, 'classname'=>$classname, 'prefix'=>$prefix)); |
|
| 95 | + $array_end = array_slice($this->liste, ($idafter + 1)); |
|
| 96 | + $this->liste = array_merge($array_start, $array_new, $array_end); |
|
| 97 | 97 | } |
| 98 | 98 | |
| 99 | 99 | // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps |
@@ -117,10 +117,10 @@ discard block |
||
| 117 | 117 | */ |
| 118 | 118 | function getNbOfVisibleMenuEntries() |
| 119 | 119 | { |
| 120 | - $nb=0; |
|
| 121 | - foreach($this->liste as $val) |
|
| 120 | + $nb = 0; |
|
| 121 | + foreach ($this->liste as $val) |
|
| 122 | 122 | { |
| 123 | - if (! empty($val['enabled'])) $nb++; |
|
| 123 | + if (!empty($val['enabled'])) $nb++; |
|
| 124 | 124 | } |
| 125 | 125 | return $nb; |
| 126 | 126 | } |
@@ -40,13 +40,13 @@ discard block |
||
| 40 | 40 | public $sendmode; |
| 41 | 41 | public $sendsetup; |
| 42 | 42 | |
| 43 | - var $subject; // Topic: Subject of email |
|
| 44 | - var $addr_from; // From: Label and EMail of sender (must include '<>'). For example '<[email protected]>' or 'John Doe <[email protected]>' or '<[email protected]>'). Note that with gmail smtps, value here is forced by google to account (but not the reply-to). |
|
| 43 | + var $subject; // Topic: Subject of email |
|
| 44 | + var $addr_from; // From: Label and EMail of sender (must include '<>'). For example '<[email protected]>' or 'John Doe <[email protected]>' or '<[email protected]>'). Note that with gmail smtps, value here is forced by google to account (but not the reply-to). |
|
| 45 | 45 | // Sender: Who send the email ("Sender" has sent emails on behalf of "From"). |
| 46 | 46 | // Use it when the "From" is an email of a domain that is a SPF protected domain, and sending smtp server is not this domain. In such case, add Sender field with an email of the protected domain. |
| 47 | 47 | // Return-Path: Email where to send bounds. |
| 48 | - var $reply_to; // Reply-To: Email where to send replies from mailer software (mailer use From if reply-to not defined, Gmail use gmail account if reply-to not defined) |
|
| 49 | - var $errors_to; // Errors-To: Email where to send errors. |
|
| 48 | + var $reply_to; // Reply-To: Email where to send replies from mailer software (mailer use From if reply-to not defined, Gmail use gmail account if reply-to not defined) |
|
| 49 | + var $errors_to; // Errors-To: Email where to send errors. |
|
| 50 | 50 | var $addr_to; |
| 51 | 51 | var $addr_cc; |
| 52 | 52 | var $addr_bcc; |
@@ -63,10 +63,10 @@ discard block |
||
| 63 | 63 | /** |
| 64 | 64 | * @var string Error code (or message) |
| 65 | 65 | */ |
| 66 | - public $error=''; |
|
| 66 | + public $error = ''; |
|
| 67 | 67 | |
| 68 | - var $smtps; // Contains SMTPs object (if this method is used) |
|
| 69 | - var $phpmailer; // Contains PHPMailer object (if this method is used) |
|
| 68 | + var $smtps; // Contains SMTPs object (if this method is used) |
|
| 69 | + var $phpmailer; // Contains PHPMailer object (if this method is used) |
|
| 70 | 70 | |
| 71 | 71 | /** |
| 72 | 72 | * @var string CSS |
@@ -83,9 +83,9 @@ discard block |
||
| 83 | 83 | // Image |
| 84 | 84 | var $html; |
| 85 | 85 | var $image_boundary; |
| 86 | - var $atleastoneimage=0; // at least one image file with file=xxx.ext into content (TODO Debug this. How can this case be tested. Remove if not used). |
|
| 87 | - var $html_images=array(); |
|
| 88 | - var $images_encoded=array(); |
|
| 86 | + var $atleastoneimage = 0; // at least one image file with file=xxx.ext into content (TODO Debug this. How can this case be tested. Remove if not used). |
|
| 87 | + var $html_images = array(); |
|
| 88 | + var $images_encoded = array(); |
|
| 89 | 89 | var $image_types = array( |
| 90 | 90 | 'gif' => 'image/gif', |
| 91 | 91 | 'jpg' => 'image/jpeg', |
@@ -119,13 +119,13 @@ discard block |
||
| 119 | 119 | * @param string $sendcontext 'standard', 'emailing', ... (used to define with sending mode and parameters to use) |
| 120 | 120 | * @param string $replyto Reply-to email (will be set to same value than From by default if not provided) |
| 121 | 121 | */ |
| 122 | - function __construct($subject, $to, $from, $msg, $filename_list=array(), $mimetype_list=array(), $mimefilename_list=array(), $addr_cc="", $addr_bcc="", $deliveryreceipt=0, $msgishtml=0, $errors_to='', $css='', $trackid='', $moreinheader='', $sendcontext='standard', $replyto='') |
|
| 122 | + function __construct($subject, $to, $from, $msg, $filename_list = array(), $mimetype_list = array(), $mimefilename_list = array(), $addr_cc = "", $addr_bcc = "", $deliveryreceipt = 0, $msgishtml = 0, $errors_to = '', $css = '', $trackid = '', $moreinheader = '', $sendcontext = 'standard', $replyto = '') |
|
| 123 | 123 | { |
| 124 | 124 | global $conf, $dolibarr_main_data_root; |
| 125 | 125 | |
| 126 | 126 | $this->sendcontext = $sendcontext; |
| 127 | 127 | |
| 128 | - if (empty($replyto)) $replyto=$from; |
|
| 128 | + if (empty($replyto)) $replyto = $from; |
|
| 129 | 129 | |
| 130 | 130 | // Define this->sendmode |
| 131 | 131 | $this->sendmode = ''; |
@@ -133,28 +133,28 @@ discard block |
||
| 133 | 133 | { |
| 134 | 134 | $this->sendmode = $conf->global->MAIN_MAIL_SENDMODE_EMAILING; |
| 135 | 135 | } |
| 136 | - if (empty($this->sendmode)) $this->sendmode=$conf->global->MAIN_MAIL_SENDMODE; |
|
| 137 | - if (empty($this->sendmode)) $this->sendmode='mail'; |
|
| 136 | + if (empty($this->sendmode)) $this->sendmode = $conf->global->MAIN_MAIL_SENDMODE; |
|
| 137 | + if (empty($this->sendmode)) $this->sendmode = 'mail'; |
|
| 138 | 138 | |
| 139 | 139 | // We define end of line (RFC 821). |
| 140 | - $this->eol="\r\n"; |
|
| 140 | + $this->eol = "\r\n"; |
|
| 141 | 141 | // We define end of line for header fields (RFC 822bis section 2.3 says header must contains \r\n). |
| 142 | - $this->eol2="\r\n"; |
|
| 143 | - if (! empty($conf->global->MAIN_FIX_FOR_BUGGED_MTA)) |
|
| 142 | + $this->eol2 = "\r\n"; |
|
| 143 | + if (!empty($conf->global->MAIN_FIX_FOR_BUGGED_MTA)) |
|
| 144 | 144 | { |
| 145 | - $this->eol="\n"; |
|
| 146 | - $this->eol2="\n"; |
|
| 147 | - $moreinheader = str_replace("\r\n","\n",$moreinheader); |
|
| 145 | + $this->eol = "\n"; |
|
| 146 | + $this->eol2 = "\n"; |
|
| 147 | + $moreinheader = str_replace("\r\n", "\n", $moreinheader); |
|
| 148 | 148 | } |
| 149 | 149 | |
| 150 | 150 | // On defini mixed_boundary |
| 151 | - $this->mixed_boundary = "multipart_x." . time() . ".x_boundary"; |
|
| 151 | + $this->mixed_boundary = "multipart_x.".time().".x_boundary"; |
|
| 152 | 152 | |
| 153 | 153 | // On defini related_boundary |
| 154 | - $this->related_boundary = 'mul_'.dol_hash(uniqid("dolibarr2"), 3); // Force md5 hash (does not contains special chars) |
|
| 154 | + $this->related_boundary = 'mul_'.dol_hash(uniqid("dolibarr2"), 3); // Force md5 hash (does not contains special chars) |
|
| 155 | 155 | |
| 156 | 156 | // On defini alternative_boundary |
| 157 | - $this->alternative_boundary = 'mul_'.dol_hash(uniqid("dolibarr3"), 3); // Force md5 hash (does not contains special chars) |
|
| 157 | + $this->alternative_boundary = 'mul_'.dol_hash(uniqid("dolibarr3"), 3); // Force md5 hash (does not contains special chars) |
|
| 158 | 158 | |
| 159 | 159 | dol_syslog("CMailFile::CMailfile: sendmode=".$this->sendmode." charset=".$conf->file->character_set_client." from=$from, to=$to, addr_cc=$addr_cc, addr_bcc=$addr_bcc, errors_to=$errors_to, trackid=$trackid sendcontext=$sendcontext", LOG_DEBUG); |
| 160 | 160 | dol_syslog("CMailFile::CMailfile: subject=".$subject.", deliveryreceipt=".$deliveryreceipt.", msgishtml=".$msgishtml, LOG_DEBUG); |
@@ -162,13 +162,13 @@ discard block |
||
| 162 | 162 | if (empty($subject)) |
| 163 | 163 | { |
| 164 | 164 | dol_syslog("CMailFile::CMailfile: Try to send an email with empty subject"); |
| 165 | - $this->error='ErrorSubjectIsRequired'; |
|
| 165 | + $this->error = 'ErrorSubjectIsRequired'; |
|
| 166 | 166 | return; |
| 167 | 167 | } |
| 168 | 168 | if (empty($msg)) |
| 169 | 169 | { |
| 170 | 170 | dol_syslog("CMailFile::CMailfile: Try to send an email with empty body"); |
| 171 | - $msg='.'; // Avoid empty message (with empty message conten show a multipart structure) |
|
| 171 | + $msg = '.'; // Avoid empty message (with empty message conten show a multipart structure) |
|
| 172 | 172 | } |
| 173 | 173 | |
| 174 | 174 | // Detect if message is HTML (use fast method) |
@@ -185,21 +185,21 @@ discard block |
||
| 185 | 185 | global $dolibarr_main_url_root; |
| 186 | 186 | |
| 187 | 187 | // Define $urlwithroot |
| 188 | - $urlwithouturlroot=preg_replace('/'.preg_quote(DOL_URL_ROOT,'/').'$/i','',trim($dolibarr_main_url_root)); |
|
| 189 | - $urlwithroot=$urlwithouturlroot.DOL_URL_ROOT; // This is to use external domain name found into config file |
|
| 188 | + $urlwithouturlroot = preg_replace('/'.preg_quote(DOL_URL_ROOT, '/').'$/i', '', trim($dolibarr_main_url_root)); |
|
| 189 | + $urlwithroot = $urlwithouturlroot.DOL_URL_ROOT; // This is to use external domain name found into config file |
|
| 190 | 190 | //$urlwithroot=DOL_MAIN_URL_ROOT; // This is to use same domain name than current |
| 191 | 191 | |
| 192 | 192 | // Replace relative /viewimage to absolute path |
| 193 | - $msg = preg_replace('/src="'.preg_quote(DOL_URL_ROOT,'/').'\/viewimage\.php/ims', 'src="'.$urlwithroot.'/viewimage.php', $msg, -1, $nbrep); |
|
| 193 | + $msg = preg_replace('/src="'.preg_quote(DOL_URL_ROOT, '/').'\/viewimage\.php/ims', 'src="'.$urlwithroot.'/viewimage.php', $msg, -1, $nbrep); |
|
| 194 | 194 | |
| 195 | - if (! empty($conf->global->MAIN_MAIL_FORCE_CONTENT_TYPE_TO_HTML)) $this->msgishtml=1; // To force to send everything with content type html. |
|
| 195 | + if (!empty($conf->global->MAIN_MAIL_FORCE_CONTENT_TYPE_TO_HTML)) $this->msgishtml = 1; // To force to send everything with content type html. |
|
| 196 | 196 | |
| 197 | 197 | // Detect images |
| 198 | 198 | if ($this->msgishtml) |
| 199 | 199 | { |
| 200 | 200 | $this->html = $msg; |
| 201 | 201 | |
| 202 | - if (! empty($conf->global->MAIN_MAIL_ADD_INLINE_IMAGES_IF_IN_MEDIAS)) |
|
| 202 | + if (!empty($conf->global->MAIN_MAIL_ADD_INLINE_IMAGES_IF_IN_MEDIAS)) |
|
| 203 | 203 | { |
| 204 | 204 | $findimg = $this->findHtmlImages($dolibarr_main_data_root.'/medias'); |
| 205 | 205 | } |
@@ -211,7 +211,7 @@ discard block |
||
| 211 | 211 | { |
| 212 | 212 | if ($this->html_images[$i]) |
| 213 | 213 | { |
| 214 | - $this->atleastoneimage=1; |
|
| 214 | + $this->atleastoneimage = 1; |
|
| 215 | 215 | dol_syslog("CMailFile::CMailfile: html_images[$i]['name']=".$this->html_images[$i]['name'], LOG_DEBUG); |
| 216 | 216 | } |
| 217 | 217 | } |
@@ -225,14 +225,14 @@ discard block |
||
| 225 | 225 | { |
| 226 | 226 | if ($filename_list[$i]) |
| 227 | 227 | { |
| 228 | - $this->atleastonefile=1; |
|
| 228 | + $this->atleastonefile = 1; |
|
| 229 | 229 | dol_syslog("CMailFile::CMailfile: filename_list[$i]=".$filename_list[$i].", mimetype_list[$i]=".$mimetype_list[$i]." mimefilename_list[$i]=".$mimefilename_list[$i], LOG_DEBUG); |
| 230 | 230 | } |
| 231 | 231 | } |
| 232 | 232 | } |
| 233 | 233 | |
| 234 | 234 | // Add autocopy to (Note: Adding bcc for specific modules are also done from pages) |
| 235 | - if (! empty($conf->global->MAIN_MAIL_AUTOCOPY_TO)) $addr_bcc.=($addr_bcc?', ':'').$conf->global->MAIN_MAIL_AUTOCOPY_TO; |
|
| 235 | + if (!empty($conf->global->MAIN_MAIL_AUTOCOPY_TO)) $addr_bcc .= ($addr_bcc ? ', ' : '').$conf->global->MAIN_MAIL_AUTOCOPY_TO; |
|
| 236 | 236 | |
| 237 | 237 | // Action according to choosed sending method |
| 238 | 238 | if ($this->sendmode == 'mail') |
@@ -257,17 +257,17 @@ discard block |
||
| 257 | 257 | $this->trackid = $trackid; |
| 258 | 258 | |
| 259 | 259 | $smtp_headers = $this->write_smtpheaders(); |
| 260 | - if (! empty($moreinheader)) $smtp_headers.=$moreinheader; // $moreinheader contains the \r\n |
|
| 260 | + if (!empty($moreinheader)) $smtp_headers .= $moreinheader; // $moreinheader contains the \r\n |
|
| 261 | 261 | |
| 262 | 262 | // Define mime_headers |
| 263 | 263 | $mime_headers = $this->write_mimeheaders($filename_list, $mimefilename_list); |
| 264 | 264 | |
| 265 | - if (! empty($this->html)) |
|
| 265 | + if (!empty($this->html)) |
|
| 266 | 266 | { |
| 267 | 267 | if (!empty($css)) |
| 268 | 268 | { |
| 269 | 269 | $this->css = $css; |
| 270 | - $this->buildCSS(); // Build a css style (mode = all) into this->styleCSS and this->bodyCSS |
|
| 270 | + $this->buildCSS(); // Build a css style (mode = all) into this->styleCSS and this->bodyCSS |
|
| 271 | 271 | } |
| 272 | 272 | |
| 273 | 273 | $msg = $this->html; |
@@ -279,20 +279,20 @@ discard block |
||
| 279 | 279 | // Add attachments to text_encoded |
| 280 | 280 | if ($this->atleastonefile) |
| 281 | 281 | { |
| 282 | - $files_encoded = $this->write_files($filename_list,$mimetype_list,$mimefilename_list); |
|
| 282 | + $files_encoded = $this->write_files($filename_list, $mimetype_list, $mimefilename_list); |
|
| 283 | 283 | } |
| 284 | 284 | |
| 285 | 285 | // We now define $this->headers and $this->message |
| 286 | - $this->headers = $smtp_headers . $mime_headers; |
|
| 286 | + $this->headers = $smtp_headers.$mime_headers; |
|
| 287 | 287 | // On nettoie le header pour qu'il ne se termine pas par un retour chariot. |
| 288 | 288 | // Ceci evite aussi les lignes vides en fin qui peuvent etre interpretees |
| 289 | 289 | // comme des injections mail par les serveurs de messagerie. |
| 290 | - $this->headers = preg_replace("/([\r\n]+)$/i","",$this->headers); |
|
| 290 | + $this->headers = preg_replace("/([\r\n]+)$/i", "", $this->headers); |
|
| 291 | 291 | |
| 292 | 292 | //$this->message = $this->eol.'This is a message with multiple parts in MIME format.'.$this->eol; |
| 293 | 293 | $this->message = 'This is a message with multiple parts in MIME format.'.$this->eol; |
| 294 | - $this->message.= $text_body . $files_encoded; |
|
| 295 | - $this->message.= "--" . $this->mixed_boundary . "--" . $this->eol; |
|
| 294 | + $this->message .= $text_body.$files_encoded; |
|
| 295 | + $this->message .= "--".$this->mixed_boundary."--".$this->eol; |
|
| 296 | 296 | } |
| 297 | 297 | else if ($this->sendmode == 'smtps') |
| 298 | 298 | { |
@@ -304,14 +304,14 @@ discard block |
||
| 304 | 304 | $smtps->setCharSet($conf->file->character_set_client); |
| 305 | 305 | |
| 306 | 306 | $smtps->setSubject($this->encodetorfc2822($subject)); |
| 307 | - $smtps->setTO($this->getValidAddress($to,0,1)); |
|
| 308 | - $smtps->setFrom($this->getValidAddress($from,0,1)); |
|
| 307 | + $smtps->setTO($this->getValidAddress($to, 0, 1)); |
|
| 308 | + $smtps->setFrom($this->getValidAddress($from, 0, 1)); |
|
| 309 | 309 | $smtps->setTrackId($trackid); |
| 310 | - $smtps->setReplyTo($this->getValidAddress($replyto,0,1)); |
|
| 310 | + $smtps->setReplyTo($this->getValidAddress($replyto, 0, 1)); |
|
| 311 | 311 | |
| 312 | - if (! empty($moreinheader)) $smtps->setMoreInHeader($moreinheader); |
|
| 312 | + if (!empty($moreinheader)) $smtps->setMoreInHeader($moreinheader); |
|
| 313 | 313 | |
| 314 | - if (! empty($this->html)) |
|
| 314 | + if (!empty($this->html)) |
|
| 315 | 315 | { |
| 316 | 316 | if (!empty($css)) |
| 317 | 317 | { |
@@ -322,14 +322,14 @@ discard block |
||
| 322 | 322 | $msg = $this->checkIfHTML($msg); |
| 323 | 323 | } |
| 324 | 324 | |
| 325 | - if ($this->msgishtml) $smtps->setBodyContent($msg,'html'); |
|
| 326 | - else $smtps->setBodyContent($msg,'plain'); |
|
| 325 | + if ($this->msgishtml) $smtps->setBodyContent($msg, 'html'); |
|
| 326 | + else $smtps->setBodyContent($msg, 'plain'); |
|
| 327 | 327 | |
| 328 | 328 | if ($this->atleastoneimage) |
| 329 | 329 | { |
| 330 | 330 | foreach ($this->images_encoded as $img) |
| 331 | 331 | { |
| 332 | - $smtps->setImageInline($img['image_encoded'],$img['name'],$img['content_type'],$img['cid']); |
|
| 332 | + $smtps->setImageInline($img['image_encoded'], $img['name'], $img['content_type'], $img['cid']); |
|
| 333 | 333 | } |
| 334 | 334 | } |
| 335 | 335 | |
@@ -337,8 +337,8 @@ discard block |
||
| 337 | 337 | { |
| 338 | 338 | foreach ($filename_list as $i => $val) |
| 339 | 339 | { |
| 340 | - $content=file_get_contents($filename_list[$i]); |
|
| 341 | - $smtps->setAttachment($content,$mimefilename_list[$i],$mimetype_list[$i]); |
|
| 340 | + $content = file_get_contents($filename_list[$i]); |
|
| 341 | + $smtps->setAttachment($content, $mimefilename_list[$i], $mimetype_list[$i]); |
|
| 342 | 342 | } |
| 343 | 343 | } |
| 344 | 344 | |
@@ -347,7 +347,7 @@ discard block |
||
| 347 | 347 | $smtps->setErrorsTo($errors_to); |
| 348 | 348 | $smtps->setDeliveryReceipt($deliveryreceipt); |
| 349 | 349 | |
| 350 | - $this->smtps=$smtps; |
|
| 350 | + $this->smtps = $smtps; |
|
| 351 | 351 | } |
| 352 | 352 | else if ($this->sendmode == 'swiftmailer') |
| 353 | 353 | { |
@@ -383,8 +383,8 @@ discard block |
||
| 383 | 383 | //$this->message = new Swift_SignedMessage(); |
| 384 | 384 | // Adding a trackid header to a message |
| 385 | 385 | $headers = $this->message->getHeaders(); |
| 386 | - $headers->addTextHeader('X-Dolibarr-TRACKID', $trackid . '@' . $host); |
|
| 387 | - $headerID = time() . '.swiftmailer-dolibarr-' . $trackid . '@' . $host; |
|
| 386 | + $headers->addTextHeader('X-Dolibarr-TRACKID', $trackid.'@'.$host); |
|
| 387 | + $headerID = time().'.swiftmailer-dolibarr-'.$trackid.'@'.$host; |
|
| 388 | 388 | $msgid = $headers->get('Message-ID'); |
| 389 | 389 | $msgid->setId($headerID); |
| 390 | 390 | $headers->addIdHeader('References', $headerID); |
@@ -394,12 +394,12 @@ discard block |
||
| 394 | 394 | try { |
| 395 | 395 | $result = $this->message->setSubject($subject); |
| 396 | 396 | } catch (Exception $e) { |
| 397 | - $this->errors[] = $e->getMessage(); |
|
| 397 | + $this->errors[] = $e->getMessage(); |
|
| 398 | 398 | } |
| 399 | 399 | |
| 400 | 400 | // Set the From address with an associative array |
| 401 | 401 | //$this->message->setFrom(array('[email protected]' => 'John Doe')); |
| 402 | - if (! empty($from)) { |
|
| 402 | + if (!empty($from)) { |
|
| 403 | 403 | try { |
| 404 | 404 | $result = $this->message->setFrom($this->getArrayAddress($from)); |
| 405 | 405 | } catch (Exception $e) { |
@@ -408,7 +408,7 @@ discard block |
||
| 408 | 408 | } |
| 409 | 409 | |
| 410 | 410 | // Set the To addresses with an associative array |
| 411 | - if (! empty($to)) { |
|
| 411 | + if (!empty($to)) { |
|
| 412 | 412 | try { |
| 413 | 413 | $result = $this->message->setTo($this->getArrayAddress($to)); |
| 414 | 414 | } catch (Exception $e) { |
@@ -416,7 +416,7 @@ discard block |
||
| 416 | 416 | } |
| 417 | 417 | } |
| 418 | 418 | |
| 419 | - if (! empty($replyto)) { |
|
| 419 | + if (!empty($replyto)) { |
|
| 420 | 420 | try { |
| 421 | 421 | $result = $this->message->SetReplyTo($this->getArrayAddress($replyto)); |
| 422 | 422 | } catch (Exception $e) { |
@@ -427,10 +427,10 @@ discard block |
||
| 427 | 427 | try { |
| 428 | 428 | $result = $this->message->setCharSet($conf->file->character_set_client); |
| 429 | 429 | } catch (Exception $e) { |
| 430 | - $this->errors[] = $e->getMessage(); |
|
| 430 | + $this->errors[] = $e->getMessage(); |
|
| 431 | 431 | } |
| 432 | 432 | |
| 433 | - if (! empty($this->html)) |
|
| 433 | + if (!empty($this->html)) |
|
| 434 | 434 | { |
| 435 | 435 | if (!empty($css)) |
| 436 | 436 | { |
@@ -455,11 +455,11 @@ discard block |
||
| 455 | 455 | } |
| 456 | 456 | |
| 457 | 457 | if ($this->msgishtml) { |
| 458 | - $this->message->setBody($msg,'text/html'); |
|
| 458 | + $this->message->setBody($msg, 'text/html'); |
|
| 459 | 459 | // And optionally an alternative body |
| 460 | 460 | $this->message->addPart(html_entity_decode(strip_tags($msg)), 'text/plain'); |
| 461 | 461 | } else { |
| 462 | - $this->message->setBody($msg,'text/plain'); |
|
| 462 | + $this->message->setBody($msg, 'text/plain'); |
|
| 463 | 463 | // And optionally an alternative body |
| 464 | 464 | $this->message->addPart($msg, 'text/html'); |
| 465 | 465 | } |
@@ -469,13 +469,13 @@ discard block |
||
| 469 | 469 | foreach ($filename_list as $i => $val) |
| 470 | 470 | { |
| 471 | 471 | //$this->message->attach(Swift_Attachment::fromPath($filename_list[$i],$mimetype_list[$i])); |
| 472 | - $attachment = Swift_Attachment::fromPath($filename_list[$i],$mimetype_list[$i]); |
|
| 472 | + $attachment = Swift_Attachment::fromPath($filename_list[$i], $mimetype_list[$i]); |
|
| 473 | 473 | $this->message->attach($attachment); |
| 474 | 474 | } |
| 475 | 475 | } |
| 476 | 476 | |
| 477 | - if (! empty($addr_cc)) $this->message->setCc($this->getArrayAddress($addr_cc)); |
|
| 478 | - if (! empty($addr_bcc)) $this->message->setBcc($this->getArrayAddress($addr_bcc)); |
|
| 477 | + if (!empty($addr_cc)) $this->message->setCc($this->getArrayAddress($addr_cc)); |
|
| 478 | + if (!empty($addr_bcc)) $this->message->setBcc($this->getArrayAddress($addr_bcc)); |
|
| 479 | 479 | //if (! empty($errors_to)) $this->message->setErrorsTo($this->getArrayAddress($errors_to); |
| 480 | 480 | if (isset($deliveryreceipt) && $deliveryreceipt == 1) $this->message->setReadReceiptTo($this->getArrayAddress($from)); |
| 481 | 481 | } |
@@ -495,25 +495,25 @@ discard block |
||
| 495 | 495 | */ |
| 496 | 496 | function sendfile() |
| 497 | 497 | { |
| 498 | - global $conf,$db,$langs; |
|
| 498 | + global $conf, $db, $langs; |
|
| 499 | 499 | |
| 500 | - $errorlevel=error_reporting(); |
|
| 500 | + $errorlevel = error_reporting(); |
|
| 501 | 501 | //error_reporting($errorlevel ^ E_WARNING); // Desactive warnings |
| 502 | 502 | |
| 503 | - $res=false; |
|
| 503 | + $res = false; |
|
| 504 | 504 | |
| 505 | 505 | if (empty($conf->global->MAIN_DISABLE_ALL_MAILS) || !empty($conf->global->MAIN_MAIL_FORCE_SENDTO)) |
| 506 | 506 | { |
| 507 | - require_once DOL_DOCUMENT_ROOT . '/core/class/hookmanager.class.php'; |
|
| 507 | + require_once DOL_DOCUMENT_ROOT.'/core/class/hookmanager.class.php'; |
|
| 508 | 508 | $hookmanager = new HookManager($db); |
| 509 | 509 | $hookmanager->initHooks(array('mail')); |
| 510 | 510 | |
| 511 | - $parameters=array(); $action=''; |
|
| 511 | + $parameters = array(); $action = ''; |
|
| 512 | 512 | $reshook = $hookmanager->executeHooks('sendMail', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks |
| 513 | 513 | if ($reshook < 0) |
| 514 | 514 | { |
| 515 | - $this->error = "Error in hook maildao sendMail " . $reshook; |
|
| 516 | - dol_syslog("CMailFile::sendfile: mail end error=" . $this->error, LOG_ERR); |
|
| 515 | + $this->error = "Error in hook maildao sendMail ".$reshook; |
|
| 516 | + dol_syslog("CMailFile::sendfile: mail end error=".$this->error, LOG_ERR); |
|
| 517 | 517 | |
| 518 | 518 | return $reshook; |
| 519 | 519 | } |
@@ -523,52 +523,52 @@ discard block |
||
| 523 | 523 | } |
| 524 | 524 | |
| 525 | 525 | // Check number of recipient is lower or equal than MAIL_MAX_NB_OF_RECIPIENTS_IN_SAME_EMAIL |
| 526 | - if (empty($conf->global->MAIL_MAX_NB_OF_RECIPIENTS_TO_IN_SAME_EMAIL)) $conf->global->MAIL_MAX_NB_OF_RECIPIENTS_TO_IN_SAME_EMAIL=10; |
|
| 526 | + if (empty($conf->global->MAIL_MAX_NB_OF_RECIPIENTS_TO_IN_SAME_EMAIL)) $conf->global->MAIL_MAX_NB_OF_RECIPIENTS_TO_IN_SAME_EMAIL = 10; |
|
| 527 | 527 | $tmparray1 = explode(',', $this->addr_to); |
| 528 | 528 | if (count($tmparray1) > $conf->global->MAIL_MAX_NB_OF_RECIPIENTS_TO_IN_SAME_EMAIL) |
| 529 | 529 | { |
| 530 | 530 | $this->error = 'Too much recipients in to:'; |
| 531 | - dol_syslog("CMailFile::sendfile: mail end error=" . $this->error, LOG_WARNING); |
|
| 531 | + dol_syslog("CMailFile::sendfile: mail end error=".$this->error, LOG_WARNING); |
|
| 532 | 532 | return false; |
| 533 | 533 | } |
| 534 | - if (empty($conf->global->MAIL_MAX_NB_OF_RECIPIENTS_CC_IN_SAME_EMAIL)) $conf->global->MAIL_MAX_NB_OF_RECIPIENTS_CC_IN_SAME_EMAIL=10; |
|
| 534 | + if (empty($conf->global->MAIL_MAX_NB_OF_RECIPIENTS_CC_IN_SAME_EMAIL)) $conf->global->MAIL_MAX_NB_OF_RECIPIENTS_CC_IN_SAME_EMAIL = 10; |
|
| 535 | 535 | $tmparray2 = explode(',', $this->addr_cc); |
| 536 | 536 | if (count($tmparray2) > $conf->global->MAIL_MAX_NB_OF_RECIPIENTS_CC_IN_SAME_EMAIL) |
| 537 | 537 | { |
| 538 | 538 | $this->error = 'Too much recipients in cc:'; |
| 539 | - dol_syslog("CMailFile::sendfile: mail end error=" . $this->error, LOG_WARNING); |
|
| 539 | + dol_syslog("CMailFile::sendfile: mail end error=".$this->error, LOG_WARNING); |
|
| 540 | 540 | return false; |
| 541 | 541 | } |
| 542 | - if (empty($conf->global->MAIL_MAX_NB_OF_RECIPIENTS_BCC_IN_SAME_EMAIL)) $conf->global->MAIL_MAX_NB_OF_RECIPIENTS_BCC_IN_SAME_EMAIL=10; |
|
| 542 | + if (empty($conf->global->MAIL_MAX_NB_OF_RECIPIENTS_BCC_IN_SAME_EMAIL)) $conf->global->MAIL_MAX_NB_OF_RECIPIENTS_BCC_IN_SAME_EMAIL = 10; |
|
| 543 | 543 | $tmparray3 = explode(',', $this->addr_bcc); |
| 544 | 544 | if (count($tmparray3) > $conf->global->MAIL_MAX_NB_OF_RECIPIENTS_BCC_IN_SAME_EMAIL) |
| 545 | 545 | { |
| 546 | 546 | $this->error = 'Too much recipients in bcc:'; |
| 547 | - dol_syslog("CMailFile::sendfile: mail end error=" . $this->error, LOG_WARNING); |
|
| 547 | + dol_syslog("CMailFile::sendfile: mail end error=".$this->error, LOG_WARNING); |
|
| 548 | 548 | return false; |
| 549 | 549 | } |
| 550 | - if (empty($conf->global->MAIL_MAX_NB_OF_RECIPIENTS_IN_SAME_EMAIL)) $conf->global->MAIL_MAX_NB_OF_RECIPIENTS_IN_SAME_EMAIL=10; |
|
| 551 | - if ((count($tmparray1)+count($tmparray2)+count($tmparray3)) > $conf->global->MAIL_MAX_NB_OF_RECIPIENTS_IN_SAME_EMAIL) |
|
| 550 | + if (empty($conf->global->MAIL_MAX_NB_OF_RECIPIENTS_IN_SAME_EMAIL)) $conf->global->MAIL_MAX_NB_OF_RECIPIENTS_IN_SAME_EMAIL = 10; |
|
| 551 | + if ((count($tmparray1) + count($tmparray2) + count($tmparray3)) > $conf->global->MAIL_MAX_NB_OF_RECIPIENTS_IN_SAME_EMAIL) |
|
| 552 | 552 | { |
| 553 | 553 | $this->error = 'Too much recipients in to:, cc:, bcc:'; |
| 554 | - dol_syslog("CMailFile::sendfile: mail end error=" . $this->error, LOG_WARNING); |
|
| 554 | + dol_syslog("CMailFile::sendfile: mail end error=".$this->error, LOG_WARNING); |
|
| 555 | 555 | return false; |
| 556 | 556 | } |
| 557 | 557 | |
| 558 | - $keyforsmtpserver='MAIN_MAIL_SMTP_SERVER'; |
|
| 559 | - $keyforsmtpport ='MAIN_MAIL_SMTP_PORT'; |
|
| 560 | - $keyforsmtpid ='MAIN_MAIL_SMTPS_ID'; |
|
| 561 | - $keyforsmtppw ='MAIN_MAIL_SMTPS_PW'; |
|
| 562 | - $keyfortls ='MAIN_MAIL_EMAIL_TLS'; |
|
| 563 | - $keyforstarttls ='MAIN_MAIL_EMAIL_STARTTLS'; |
|
| 558 | + $keyforsmtpserver = 'MAIN_MAIL_SMTP_SERVER'; |
|
| 559 | + $keyforsmtpport = 'MAIN_MAIL_SMTP_PORT'; |
|
| 560 | + $keyforsmtpid = 'MAIN_MAIL_SMTPS_ID'; |
|
| 561 | + $keyforsmtppw = 'MAIN_MAIL_SMTPS_PW'; |
|
| 562 | + $keyfortls = 'MAIN_MAIL_EMAIL_TLS'; |
|
| 563 | + $keyforstarttls = 'MAIN_MAIL_EMAIL_STARTTLS'; |
|
| 564 | 564 | if ($this->sendcontext == 'emailing' && !empty($conf->global->MAIN_MAIL_SENDMODE_EMAILING) && $conf->global->MAIN_MAIL_SENDMODE_EMAILING != 'default') |
| 565 | 565 | { |
| 566 | - $keyforsmtpserver='MAIN_MAIL_SMTP_SERVER_EMAILING'; |
|
| 567 | - $keyforsmtpport ='MAIN_MAIL_SMTP_PORT_EMAILING'; |
|
| 568 | - $keyforsmtpid ='MAIN_MAIL_SMTPS_ID_EMAILING'; |
|
| 569 | - $keyforsmtppw ='MAIN_MAIL_SMTPS_PW_EMAILING'; |
|
| 570 | - $keyfortls ='MAIN_MAIL_EMAIL_TLS_EMAILING'; |
|
| 571 | - $keyforstarttls ='MAIN_MAIL_EMAIL_STARTTLS_EMAILING'; |
|
| 566 | + $keyforsmtpserver = 'MAIN_MAIL_SMTP_SERVER_EMAILING'; |
|
| 567 | + $keyforsmtpport = 'MAIN_MAIL_SMTP_PORT_EMAILING'; |
|
| 568 | + $keyforsmtpid = 'MAIN_MAIL_SMTPS_ID_EMAILING'; |
|
| 569 | + $keyforsmtppw = 'MAIN_MAIL_SMTPS_PW_EMAILING'; |
|
| 570 | + $keyfortls = 'MAIN_MAIL_EMAIL_TLS_EMAILING'; |
|
| 571 | + $keyforstarttls = 'MAIN_MAIL_EMAIL_STARTTLS_EMAILING'; |
|
| 572 | 572 | } |
| 573 | 573 | |
| 574 | 574 | if (!empty($conf->global->MAIN_MAIL_FORCE_SENDTO)) |
@@ -591,68 +591,68 @@ discard block |
||
| 591 | 591 | if (isset($_SERVER["WINDIR"])) |
| 592 | 592 | { |
| 593 | 593 | if (empty($this->addr_from)) $this->addr_from = '[email protected]'; |
| 594 | - @ini_set('sendmail_from',$this->getValidAddress($this->addr_from,2)); |
|
| 594 | + @ini_set('sendmail_from', $this->getValidAddress($this->addr_from, 2)); |
|
| 595 | 595 | } |
| 596 | 596 | |
| 597 | 597 | // Force parameters |
| 598 | - if (! empty($conf->global->$keyforsmtpserver)) ini_set('SMTP',$conf->global->$keyforsmtpserver); |
|
| 599 | - if (! empty($conf->global->$keyforsmtpport)) ini_set('smtp_port',$conf->global->$keyforsmtpport); |
|
| 598 | + if (!empty($conf->global->$keyforsmtpserver)) ini_set('SMTP', $conf->global->$keyforsmtpserver); |
|
| 599 | + if (!empty($conf->global->$keyforsmtpport)) ini_set('smtp_port', $conf->global->$keyforsmtpport); |
|
| 600 | 600 | |
| 601 | - $res=true; |
|
| 602 | - if ($res && ! $this->subject) |
|
| 601 | + $res = true; |
|
| 602 | + if ($res && !$this->subject) |
|
| 603 | 603 | { |
| 604 | - $this->error="Failed to send mail with php mail to HOST=".ini_get('SMTP').", PORT=".ini_get('smtp_port')."<br>Subject is empty"; |
|
| 604 | + $this->error = "Failed to send mail with php mail to HOST=".ini_get('SMTP').", PORT=".ini_get('smtp_port')."<br>Subject is empty"; |
|
| 605 | 605 | dol_syslog("CMailFile::sendfile: mail end error=".$this->error, LOG_ERR); |
| 606 | - $res=false; |
|
| 606 | + $res = false; |
|
| 607 | 607 | } |
| 608 | - $dest=$this->getValidAddress($this->addr_to,2); |
|
| 609 | - if ($res && ! $dest) |
|
| 608 | + $dest = $this->getValidAddress($this->addr_to, 2); |
|
| 609 | + if ($res && !$dest) |
|
| 610 | 610 | { |
| 611 | - $this->error="Failed to send mail with php mail to HOST=".ini_get('SMTP').", PORT=".ini_get('smtp_port')."<br>Recipient address '$dest' invalid"; |
|
| 611 | + $this->error = "Failed to send mail with php mail to HOST=".ini_get('SMTP').", PORT=".ini_get('smtp_port')."<br>Recipient address '$dest' invalid"; |
|
| 612 | 612 | dol_syslog("CMailFile::sendfile: mail end error=".$this->error, LOG_ERR); |
| 613 | - $res=false; |
|
| 613 | + $res = false; |
|
| 614 | 614 | } |
| 615 | 615 | |
| 616 | 616 | if ($res) |
| 617 | 617 | { |
| 618 | - $additionnalparam = ''; // By default |
|
| 619 | - if (! empty($conf->global->MAIN_MAIL_ALLOW_SENDMAIL_F)) |
|
| 618 | + $additionnalparam = ''; // By default |
|
| 619 | + if (!empty($conf->global->MAIN_MAIL_ALLOW_SENDMAIL_F)) |
|
| 620 | 620 | { |
| 621 | 621 | // le "Return-Path" (retour des messages bounced) dans les header ne fonctionne pas avec tous les MTA |
| 622 | 622 | // Le forcage de la valeur grace à l'option -f de sendmail est donc possible si la constante MAIN_MAIL_ALLOW_SENDMAIL_F est definie. |
| 623 | 623 | // Having this variable defined may create problems with some sendmail (option -f refused) |
| 624 | 624 | // Having this variable not defined may create problems with some other sendmail (option -f required) |
| 625 | - $additionnalparam .= ($additionnalparam?' ':'').(! empty($conf->global->MAIN_MAIL_ERRORS_TO) ? '-f' . $this->getValidAddress($conf->global->MAIN_MAIL_ERRORS_TO,2) : ($this->addr_from != '' ? '-f' . $this->getValidAddress($this->addr_from,2) : '') ); |
|
| 625 | + $additionnalparam .= ($additionnalparam ? ' ' : '').(!empty($conf->global->MAIN_MAIL_ERRORS_TO) ? '-f'.$this->getValidAddress($conf->global->MAIN_MAIL_ERRORS_TO, 2) : ($this->addr_from != '' ? '-f'.$this->getValidAddress($this->addr_from, 2) : '')); |
|
| 626 | 626 | } |
| 627 | - if (! empty($conf->global->MAIN_MAIL_SENDMAIL_FORCE_BA)) // To force usage of -ba option. This option tells sendmail to read From: or Sender: to setup sender |
|
| 627 | + if (!empty($conf->global->MAIN_MAIL_SENDMAIL_FORCE_BA)) // To force usage of -ba option. This option tells sendmail to read From: or Sender: to setup sender |
|
| 628 | 628 | { |
| 629 | - $additionnalparam .= ($additionnalparam?' ':'').'-ba'; |
|
| 629 | + $additionnalparam .= ($additionnalparam ? ' ' : '').'-ba'; |
|
| 630 | 630 | } |
| 631 | 631 | |
| 632 | - if (! empty($conf->global->MAIN_MAIL_SENDMAIL_FORCE_ADDPARAM)) $additionnalparam .= ($additionnalparam?' ':'').'-U '.$additionnalparam; // Use -U to add additionnal params |
|
| 632 | + if (!empty($conf->global->MAIN_MAIL_SENDMAIL_FORCE_ADDPARAM)) $additionnalparam .= ($additionnalparam ? ' ' : '').'-U '.$additionnalparam; // Use -U to add additionnal params |
|
| 633 | 633 | |
| 634 | 634 | dol_syslog("CMailFile::sendfile: mail start HOST=".ini_get('SMTP').", PORT=".ini_get('smtp_port').", additionnal_parameters=".$additionnalparam, LOG_DEBUG); |
| 635 | 635 | |
| 636 | - $this->message=stripslashes($this->message); |
|
| 636 | + $this->message = stripslashes($this->message); |
|
| 637 | 637 | |
| 638 | - if (! empty($conf->global->MAIN_MAIL_DEBUG)) $this->dump_mail(); |
|
| 638 | + if (!empty($conf->global->MAIN_MAIL_DEBUG)) $this->dump_mail(); |
|
| 639 | 639 | |
| 640 | - if (! empty($additionnalparam)) $res = mail($dest, $this->encodetorfc2822($this->subject), $this->message, $this->headers, $additionnalparam); |
|
| 640 | + if (!empty($additionnalparam)) $res = mail($dest, $this->encodetorfc2822($this->subject), $this->message, $this->headers, $additionnalparam); |
|
| 641 | 641 | else $res = mail($dest, $this->encodetorfc2822($this->subject), $this->message, $this->headers); |
| 642 | 642 | |
| 643 | - if (! $res) |
|
| 643 | + if (!$res) |
|
| 644 | 644 | { |
| 645 | 645 | $langs->load("errors"); |
| 646 | - $this->error="Failed to send mail with php mail"; |
|
| 647 | - $linuxlike=1; |
|
| 648 | - if (preg_match('/^win/i',PHP_OS)) $linuxlike=0; |
|
| 649 | - if (preg_match('/^mac/i',PHP_OS)) $linuxlike=0; |
|
| 650 | - if (! $linuxlike) |
|
| 646 | + $this->error = "Failed to send mail with php mail"; |
|
| 647 | + $linuxlike = 1; |
|
| 648 | + if (preg_match('/^win/i', PHP_OS)) $linuxlike = 0; |
|
| 649 | + if (preg_match('/^mac/i', PHP_OS)) $linuxlike = 0; |
|
| 650 | + if (!$linuxlike) |
|
| 651 | 651 | { |
| 652 | - $this->error.=" to HOST=".ini_get('SMTP').", PORT=".ini_get('smtp_port'); // This values are value used only for non linuxlike systems |
|
| 652 | + $this->error .= " to HOST=".ini_get('SMTP').", PORT=".ini_get('smtp_port'); // This values are value used only for non linuxlike systems |
|
| 653 | 653 | } |
| 654 | - $this->error.=".<br>"; |
|
| 655 | - $this->error.=$langs->trans("ErrorPhpMailDelivery"); |
|
| 654 | + $this->error .= ".<br>"; |
|
| 655 | + $this->error .= $langs->trans("ErrorPhpMailDelivery"); |
|
| 656 | 656 | dol_syslog("CMailFile::sendfile: mail end error=".$this->error, LOG_ERR); |
| 657 | 657 | } |
| 658 | 658 | else |
@@ -667,86 +667,86 @@ discard block |
||
| 667 | 667 | } |
| 668 | 668 | |
| 669 | 669 | // Restore parameters |
| 670 | - if (! empty($conf->global->$keyforsmtpserver)) ini_restore('SMTP'); |
|
| 671 | - if (! empty($conf->global->$keyforsmtpport)) ini_restore('smtp_port'); |
|
| 670 | + if (!empty($conf->global->$keyforsmtpserver)) ini_restore('SMTP'); |
|
| 671 | + if (!empty($conf->global->$keyforsmtpport)) ini_restore('smtp_port'); |
|
| 672 | 672 | } |
| 673 | 673 | else if ($this->sendmode == 'smtps') |
| 674 | 674 | { |
| 675 | - if (! is_object($this->smtps)) |
|
| 675 | + if (!is_object($this->smtps)) |
|
| 676 | 676 | { |
| 677 | - $this->error="Failed to send mail with smtps lib to HOST=".$server.", PORT=".$conf->global->$keyforsmtpport."<br>Constructor of object CMailFile was not initialized without errors."; |
|
| 677 | + $this->error = "Failed to send mail with smtps lib to HOST=".$server.", PORT=".$conf->global->$keyforsmtpport."<br>Constructor of object CMailFile was not initialized without errors."; |
|
| 678 | 678 | dol_syslog("CMailFile::sendfile: mail end error=".$this->error, LOG_ERR); |
| 679 | 679 | return false; |
| 680 | 680 | } |
| 681 | 681 | |
| 682 | 682 | // Use SMTPS library |
| 683 | 683 | // ------------------------------------------ |
| 684 | - $this->smtps->setTransportType(0); // Only this method is coded in SMTPs library |
|
| 684 | + $this->smtps->setTransportType(0); // Only this method is coded in SMTPs library |
|
| 685 | 685 | |
| 686 | 686 | // Clean parameters |
| 687 | - if (empty($conf->global->$keyforsmtpserver)) $conf->global->$keyforsmtpserver=ini_get('SMTP'); |
|
| 688 | - if (empty($conf->global->$keyforsmtpport)) $conf->global->$keyforsmtpport=ini_get('smtp_port'); |
|
| 687 | + if (empty($conf->global->$keyforsmtpserver)) $conf->global->$keyforsmtpserver = ini_get('SMTP'); |
|
| 688 | + if (empty($conf->global->$keyforsmtpport)) $conf->global->$keyforsmtpport = ini_get('smtp_port'); |
|
| 689 | 689 | |
| 690 | 690 | // If we use SSL/TLS |
| 691 | - $server=$conf->global->$keyforsmtpserver; |
|
| 692 | - $secure=''; |
|
| 693 | - if (! empty($conf->global->$keyfortls) && function_exists('openssl_open')) $secure='ssl'; |
|
| 694 | - if (! empty($conf->global->$keyforstarttls) && function_exists('openssl_open')) $secure='tls'; |
|
| 695 | - $server=($secure?$secure.'://':'').$server; |
|
| 691 | + $server = $conf->global->$keyforsmtpserver; |
|
| 692 | + $secure = ''; |
|
| 693 | + if (!empty($conf->global->$keyfortls) && function_exists('openssl_open')) $secure = 'ssl'; |
|
| 694 | + if (!empty($conf->global->$keyforstarttls) && function_exists('openssl_open')) $secure = 'tls'; |
|
| 695 | + $server = ($secure ? $secure.'://' : '').$server; |
|
| 696 | 696 | |
| 697 | - $port=$conf->global->$keyforsmtpport; |
|
| 697 | + $port = $conf->global->$keyforsmtpport; |
|
| 698 | 698 | |
| 699 | 699 | $this->smtps->setHost($server); |
| 700 | 700 | $this->smtps->setPort($port); // 25, 465...; |
| 701 | 701 | |
| 702 | - $loginid=''; $loginpass=''; |
|
| 703 | - if (! empty($conf->global->$keyforsmtpid)) |
|
| 702 | + $loginid = ''; $loginpass = ''; |
|
| 703 | + if (!empty($conf->global->$keyforsmtpid)) |
|
| 704 | 704 | { |
| 705 | 705 | $loginid = $conf->global->$keyforsmtpid; |
| 706 | 706 | $this->smtps->setID($loginid); |
| 707 | 707 | } |
| 708 | - if (! empty($conf->global->$keyforsmtppw)) |
|
| 708 | + if (!empty($conf->global->$keyforsmtppw)) |
|
| 709 | 709 | { |
| 710 | 710 | $loginpass = $conf->global->$keyforsmtppw; |
| 711 | 711 | $this->smtps->setPW($loginpass); |
| 712 | 712 | } |
| 713 | 713 | |
| 714 | - $res=true; |
|
| 715 | - $from=$this->smtps->getFrom('org'); |
|
| 716 | - if ($res && ! $from) |
|
| 714 | + $res = true; |
|
| 715 | + $from = $this->smtps->getFrom('org'); |
|
| 716 | + if ($res && !$from) |
|
| 717 | 717 | { |
| 718 | - $this->error="Failed to send mail with smtps lib to HOST=".$server.", PORT=".$conf->global->$keyforsmtpport."<br>Sender address '$from' invalid"; |
|
| 718 | + $this->error = "Failed to send mail with smtps lib to HOST=".$server.", PORT=".$conf->global->$keyforsmtpport."<br>Sender address '$from' invalid"; |
|
| 719 | 719 | dol_syslog("CMailFile::sendfile: mail end error=".$this->error, LOG_ERR); |
| 720 | - $res=false; |
|
| 720 | + $res = false; |
|
| 721 | 721 | } |
| 722 | - $dest=$this->smtps->getTo(); |
|
| 723 | - if ($res && ! $dest) |
|
| 722 | + $dest = $this->smtps->getTo(); |
|
| 723 | + if ($res && !$dest) |
|
| 724 | 724 | { |
| 725 | - $this->error="Failed to send mail with smtps lib to HOST=".$server.", PORT=".$conf->global->$keyforsmtpport."<br>Recipient address '$dest' invalid"; |
|
| 725 | + $this->error = "Failed to send mail with smtps lib to HOST=".$server.", PORT=".$conf->global->$keyforsmtpport."<br>Recipient address '$dest' invalid"; |
|
| 726 | 726 | dol_syslog("CMailFile::sendfile: mail end error=".$this->error, LOG_ERR); |
| 727 | - $res=false; |
|
| 727 | + $res = false; |
|
| 728 | 728 | } |
| 729 | 729 | |
| 730 | 730 | if ($res) |
| 731 | 731 | { |
| 732 | - if (! empty($conf->global->MAIN_MAIL_DEBUG)) $this->smtps->setDebug(true); |
|
| 732 | + if (!empty($conf->global->MAIN_MAIL_DEBUG)) $this->smtps->setDebug(true); |
|
| 733 | 733 | |
| 734 | - $result=$this->smtps->sendMsg(); |
|
| 734 | + $result = $this->smtps->sendMsg(); |
|
| 735 | 735 | //print $result; |
| 736 | 736 | |
| 737 | - if (! empty($conf->global->MAIN_MAIL_DEBUG)) $this->dump_mail(); |
|
| 737 | + if (!empty($conf->global->MAIN_MAIL_DEBUG)) $this->dump_mail(); |
|
| 738 | 738 | |
| 739 | - $result=$this->smtps->getErrors(); |
|
| 739 | + $result = $this->smtps->getErrors(); |
|
| 740 | 740 | if (empty($this->error) && empty($result)) |
| 741 | 741 | { |
| 742 | 742 | dol_syslog("CMailFile::sendfile: mail end success", LOG_DEBUG); |
| 743 | - $res=true; |
|
| 743 | + $res = true; |
|
| 744 | 744 | } |
| 745 | 745 | else |
| 746 | 746 | { |
| 747 | - if (empty($this->error)) $this->error=$result; |
|
| 747 | + if (empty($this->error)) $this->error = $result; |
|
| 748 | 748 | dol_syslog("CMailFile::sendfile: mail end error=".$this->error, LOG_ERR); |
| 749 | - $res=false; |
|
| 749 | + $res = false; |
|
| 750 | 750 | } |
| 751 | 751 | } |
| 752 | 752 | } |
@@ -757,19 +757,19 @@ discard block |
||
| 757 | 757 | require_once DOL_DOCUMENT_ROOT.'/includes/swiftmailer/lib/swift_required.php'; |
| 758 | 758 | |
| 759 | 759 | // Clean parameters |
| 760 | - if (empty($conf->global->$keyforsmtpserver)) $conf->global->$keyforsmtpserver=ini_get('SMTP'); |
|
| 761 | - if (empty($conf->global->$keyforsmtpport)) $conf->global->$keyforsmtpport=ini_get('smtp_port'); |
|
| 760 | + if (empty($conf->global->$keyforsmtpserver)) $conf->global->$keyforsmtpserver = ini_get('SMTP'); |
|
| 761 | + if (empty($conf->global->$keyforsmtpport)) $conf->global->$keyforsmtpport = ini_get('smtp_port'); |
|
| 762 | 762 | |
| 763 | 763 | // If we use SSL/TLS |
| 764 | 764 | $server = $conf->global->$keyforsmtpserver; |
| 765 | 765 | $secure = ''; |
| 766 | - if (! empty($conf->global->$keyfortls) && function_exists('openssl_open')) $secure='ssl'; |
|
| 767 | - if (! empty($conf->global->$keyforstarttls) && function_exists('openssl_open')) $secure='tls'; |
|
| 766 | + if (!empty($conf->global->$keyfortls) && function_exists('openssl_open')) $secure = 'ssl'; |
|
| 767 | + if (!empty($conf->global->$keyforstarttls) && function_exists('openssl_open')) $secure = 'tls'; |
|
| 768 | 768 | |
| 769 | 769 | $this->transport = new Swift_SmtpTransport($server, $conf->global->$keyforsmtpport, $secure); |
| 770 | 770 | |
| 771 | - if (! empty($conf->global->$keyforsmtpid)) $this->transport->setUsername($conf->global->$keyforsmtpid); |
|
| 772 | - if (! empty($conf->global->$keyforsmtppw)) $this->transport->setPassword($conf->global->$keyforsmtppw); |
|
| 771 | + if (!empty($conf->global->$keyforsmtpid)) $this->transport->setUsername($conf->global->$keyforsmtpid); |
|
| 772 | + if (!empty($conf->global->$keyforsmtppw)) $this->transport->setPassword($conf->global->$keyforsmtppw); |
|
| 773 | 773 | //$smtps->_msgReplyTo = '[email protected]'; |
| 774 | 774 | |
| 775 | 775 | // Create the Mailer using your created Transport |
@@ -784,7 +784,7 @@ discard block |
||
| 784 | 784 | $this->message->attachSigner($signer->ignoreHeader('Return-Path')); |
| 785 | 785 | } |
| 786 | 786 | |
| 787 | - if (! empty($conf->global->MAIN_MAIL_DEBUG)) { |
|
| 787 | + if (!empty($conf->global->MAIN_MAIL_DEBUG)) { |
|
| 788 | 788 | // To use the ArrayLogger |
| 789 | 789 | $this->logger = new Swift_Plugins_Loggers_ArrayLogger(); |
| 790 | 790 | // Or to use the Echo Logger |
@@ -795,14 +795,14 @@ discard block |
||
| 795 | 795 | try { |
| 796 | 796 | $result = $this->mailer->send($this->message); |
| 797 | 797 | } catch (Exception $e) { |
| 798 | - $this->error = $e->getMessage(); |
|
| 798 | + $this->error = $e->getMessage(); |
|
| 799 | 799 | } |
| 800 | - if (! empty($conf->global->MAIN_MAIL_DEBUG)) $this->dump_mail(); |
|
| 800 | + if (!empty($conf->global->MAIN_MAIL_DEBUG)) $this->dump_mail(); |
|
| 801 | 801 | |
| 802 | 802 | $res = true; |
| 803 | - if (! empty($this->error) || ! $result) { |
|
| 803 | + if (!empty($this->error) || !$result) { |
|
| 804 | 804 | dol_syslog("CMailFile::sendfile: mail end error=".$this->error, LOG_ERR); |
| 805 | - $res=false; |
|
| 805 | + $res = false; |
|
| 806 | 806 | } |
| 807 | 807 | else |
| 808 | 808 | { |
@@ -817,23 +817,23 @@ discard block |
||
| 817 | 817 | return 'Bad value for sendmode'; |
| 818 | 818 | } |
| 819 | 819 | |
| 820 | - $parameters=array(); $action=''; |
|
| 820 | + $parameters = array(); $action = ''; |
|
| 821 | 821 | $reshook = $hookmanager->executeHooks('sendMailAfter', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks |
| 822 | 822 | if ($reshook < 0) |
| 823 | 823 | { |
| 824 | - $this->error = "Error in hook maildao sendMailAfter " . $reshook; |
|
| 825 | - dol_syslog("CMailFile::sendfile: mail end error=" . $this->error, LOG_ERR); |
|
| 824 | + $this->error = "Error in hook maildao sendMailAfter ".$reshook; |
|
| 825 | + dol_syslog("CMailFile::sendfile: mail end error=".$this->error, LOG_ERR); |
|
| 826 | 826 | |
| 827 | 827 | return $reshook; |
| 828 | 828 | } |
| 829 | 829 | } |
| 830 | 830 | else |
| 831 | 831 | { |
| 832 | - $this->error='No mail sent. Feature is disabled by option MAIN_DISABLE_ALL_MAILS'; |
|
| 832 | + $this->error = 'No mail sent. Feature is disabled by option MAIN_DISABLE_ALL_MAILS'; |
|
| 833 | 833 | dol_syslog("CMailFile::sendfile: ".$this->error, LOG_WARNING); |
| 834 | 834 | } |
| 835 | 835 | |
| 836 | - error_reporting($errorlevel); // Reactive niveau erreur origine |
|
| 836 | + error_reporting($errorlevel); // Reactive niveau erreur origine |
|
| 837 | 837 | |
| 838 | 838 | return $res; |
| 839 | 839 | } |
@@ -860,17 +860,17 @@ discard block |
||
| 860 | 860 | function _encode_file($sourcefile) |
| 861 | 861 | { |
| 862 | 862 | // phpcs:enable |
| 863 | - $newsourcefile=dol_osencode($sourcefile); |
|
| 863 | + $newsourcefile = dol_osencode($sourcefile); |
|
| 864 | 864 | |
| 865 | 865 | if (is_readable($newsourcefile)) |
| 866 | 866 | { |
| 867 | - $contents = file_get_contents($newsourcefile); // Need PHP 4.3 |
|
| 868 | - $encoded = chunk_split(base64_encode($contents), 76, $this->eol); // 76 max is defined into http://tools.ietf.org/html/rfc2047 |
|
| 867 | + $contents = file_get_contents($newsourcefile); // Need PHP 4.3 |
|
| 868 | + $encoded = chunk_split(base64_encode($contents), 76, $this->eol); // 76 max is defined into http://tools.ietf.org/html/rfc2047 |
|
| 869 | 869 | return $encoded; |
| 870 | 870 | } |
| 871 | 871 | else |
| 872 | 872 | { |
| 873 | - $this->error="Error: Can't read file '".$sourcefile."' into _encode_file"; |
|
| 873 | + $this->error = "Error: Can't read file '".$sourcefile."' into _encode_file"; |
|
| 874 | 874 | dol_syslog("CMailFile::encode_file: ".$this->error, LOG_ERR); |
| 875 | 875 | return -1; |
| 876 | 876 | } |
@@ -888,30 +888,30 @@ discard block |
||
| 888 | 888 | function dump_mail() |
| 889 | 889 | { |
| 890 | 890 | // phpcs:enable |
| 891 | - global $conf,$dolibarr_main_data_root; |
|
| 891 | + global $conf, $dolibarr_main_data_root; |
|
| 892 | 892 | |
| 893 | 893 | if (@is_writeable($dolibarr_main_data_root)) // Avoid fatal error on fopen with open_basedir |
| 894 | 894 | { |
| 895 | - $outputfile=$dolibarr_main_data_root."/dolibarr_mail.log"; |
|
| 896 | - $fp = fopen($outputfile,"w"); |
|
| 895 | + $outputfile = $dolibarr_main_data_root."/dolibarr_mail.log"; |
|
| 896 | + $fp = fopen($outputfile, "w"); |
|
| 897 | 897 | |
| 898 | 898 | if ($this->sendmode == 'mail') |
| 899 | 899 | { |
| 900 | 900 | fputs($fp, $this->headers); |
| 901 | - fputs($fp, $this->eol); // This eol is added by the mail function, so we add it in log |
|
| 901 | + fputs($fp, $this->eol); // This eol is added by the mail function, so we add it in log |
|
| 902 | 902 | fputs($fp, $this->message); |
| 903 | 903 | } |
| 904 | 904 | elseif ($this->sendmode == 'smtps') |
| 905 | 905 | { |
| 906 | - fputs($fp, $this->smtps->log); // this->smtps->log is filled only if MAIN_MAIL_DEBUG was set to on |
|
| 906 | + fputs($fp, $this->smtps->log); // this->smtps->log is filled only if MAIN_MAIL_DEBUG was set to on |
|
| 907 | 907 | } |
| 908 | 908 | elseif ($this->sendmode == 'swiftmailer') |
| 909 | 909 | { |
| 910 | - fputs($fp, $this->logger->dump()); // this->logger is filled only if MAIN_MAIL_DEBUG was set to on |
|
| 910 | + fputs($fp, $this->logger->dump()); // this->logger is filled only if MAIN_MAIL_DEBUG was set to on |
|
| 911 | 911 | } |
| 912 | 912 | |
| 913 | 913 | fclose($fp); |
| 914 | - if (! empty($conf->global->MAIN_UMASK)) |
|
| 914 | + if (!empty($conf->global->MAIN_UMASK)) |
|
| 915 | 915 | @chmod($outputfile, octdec($conf->global->MAIN_UMASK)); |
| 916 | 916 | } |
| 917 | 917 | } |
@@ -925,15 +925,15 @@ discard block |
||
| 925 | 925 | */ |
| 926 | 926 | function checkIfHTML($msg) |
| 927 | 927 | { |
| 928 | - if (!preg_match('/^[\s\t]*<html/i',$msg)) |
|
| 928 | + if (!preg_match('/^[\s\t]*<html/i', $msg)) |
|
| 929 | 929 | { |
| 930 | 930 | $out = "<html><head><title></title>"; |
| 931 | - if (!empty($this->styleCSS)) $out.= $this->styleCSS; |
|
| 932 | - $out.= "</head><body"; |
|
| 933 | - if (!empty($this->bodyCSS)) $out.= $this->bodyCSS; |
|
| 934 | - $out.= ">"; |
|
| 935 | - $out.= $msg; |
|
| 936 | - $out.= "</body></html>"; |
|
| 931 | + if (!empty($this->styleCSS)) $out .= $this->styleCSS; |
|
| 932 | + $out .= "</head><body"; |
|
| 933 | + if (!empty($this->bodyCSS)) $out .= $this->bodyCSS; |
|
| 934 | + $out .= ">"; |
|
| 935 | + $out .= $msg; |
|
| 936 | + $out .= "</body></html>"; |
|
| 937 | 937 | } |
| 938 | 938 | else |
| 939 | 939 | { |
@@ -950,24 +950,24 @@ discard block |
||
| 950 | 950 | */ |
| 951 | 951 | function buildCSS() |
| 952 | 952 | { |
| 953 | - if (! empty($this->css)) |
|
| 953 | + if (!empty($this->css)) |
|
| 954 | 954 | { |
| 955 | 955 | // Style CSS |
| 956 | 956 | $this->styleCSS = '<style type="text/css">'; |
| 957 | - $this->styleCSS.= 'body {'; |
|
| 957 | + $this->styleCSS .= 'body {'; |
|
| 958 | 958 | |
| 959 | 959 | if ($this->css['bgcolor']) |
| 960 | 960 | { |
| 961 | - $this->styleCSS.= ' background-color: '.$this->css['bgcolor'].';'; |
|
| 962 | - $this->bodyCSS.= ' bgcolor="'.$this->css['bgcolor'].'"'; |
|
| 961 | + $this->styleCSS .= ' background-color: '.$this->css['bgcolor'].';'; |
|
| 962 | + $this->bodyCSS .= ' bgcolor="'.$this->css['bgcolor'].'"'; |
|
| 963 | 963 | } |
| 964 | 964 | if ($this->css['bgimage']) |
| 965 | 965 | { |
| 966 | 966 | // TODO recuperer cid |
| 967 | - $this->styleCSS.= ' background-image: url("cid:'.$this->css['bgimage_cid'].'");'; |
|
| 967 | + $this->styleCSS .= ' background-image: url("cid:'.$this->css['bgimage_cid'].'");'; |
|
| 968 | 968 | } |
| 969 | - $this->styleCSS.= '}'; |
|
| 970 | - $this->styleCSS.= '</style>'; |
|
| 969 | + $this->styleCSS .= '}'; |
|
| 970 | + $this->styleCSS .= '</style>'; |
|
| 971 | 971 | } |
| 972 | 972 | } |
| 973 | 973 | |
@@ -988,48 +988,48 @@ discard block |
||
| 988 | 988 | |
| 989 | 989 | // Sender |
| 990 | 990 | //$out.= "Sender: ".getValidAddress($this->addr_from,2)).$this->eol2; |
| 991 | - $out.= "From: ".$this->getValidAddress($this->addr_from,3,1).$this->eol2; |
|
| 992 | - if (! empty($conf->global->MAIN_MAIL_SENDMAIL_FORCE_BA)) |
|
| 991 | + $out .= "From: ".$this->getValidAddress($this->addr_from, 3, 1).$this->eol2; |
|
| 992 | + if (!empty($conf->global->MAIN_MAIL_SENDMAIL_FORCE_BA)) |
|
| 993 | 993 | { |
| 994 | - $out.= "To: ".$this->getValidAddress($this->addr_to,0,1).$this->eol2; |
|
| 994 | + $out .= "To: ".$this->getValidAddress($this->addr_to, 0, 1).$this->eol2; |
|
| 995 | 995 | } |
| 996 | 996 | // Return-Path is important because it is used by SPF. Some MTA does not read Return-Path from header but from command line. See option MAIN_MAIL_ALLOW_SENDMAIL_F for that. |
| 997 | - $out.= "Return-Path: ".$this->getValidAddress($this->addr_from,0,1).$this->eol2; |
|
| 998 | - if (isset($this->reply_to) && $this->reply_to) $out.= "Reply-To: ".$this->getValidAddress($this->reply_to,2).$this->eol2; |
|
| 999 | - if (isset($this->errors_to) && $this->errors_to) $out.= "Errors-To: ".$this->getValidAddress($this->errors_to,2).$this->eol2; |
|
| 997 | + $out .= "Return-Path: ".$this->getValidAddress($this->addr_from, 0, 1).$this->eol2; |
|
| 998 | + if (isset($this->reply_to) && $this->reply_to) $out .= "Reply-To: ".$this->getValidAddress($this->reply_to, 2).$this->eol2; |
|
| 999 | + if (isset($this->errors_to) && $this->errors_to) $out .= "Errors-To: ".$this->getValidAddress($this->errors_to, 2).$this->eol2; |
|
| 1000 | 1000 | |
| 1001 | 1001 | // Receiver |
| 1002 | - if (isset($this->addr_cc) && $this->addr_cc) $out.= "Cc: ".$this->getValidAddress($this->addr_cc,2).$this->eol2; |
|
| 1003 | - if (isset($this->addr_bcc) && $this->addr_bcc) $out.= "Bcc: ".$this->getValidAddress($this->addr_bcc,2).$this->eol2; // TODO Question: bcc must not be into header, only into SMTP command "RCPT TO". Does php mail support this ? |
|
| 1002 | + if (isset($this->addr_cc) && $this->addr_cc) $out .= "Cc: ".$this->getValidAddress($this->addr_cc, 2).$this->eol2; |
|
| 1003 | + if (isset($this->addr_bcc) && $this->addr_bcc) $out .= "Bcc: ".$this->getValidAddress($this->addr_bcc, 2).$this->eol2; // TODO Question: bcc must not be into header, only into SMTP command "RCPT TO". Does php mail support this ? |
|
| 1004 | 1004 | |
| 1005 | 1005 | // Delivery receipt |
| 1006 | - if (isset($this->deliveryreceipt) && $this->deliveryreceipt == 1) $out.= "Disposition-Notification-To: ".$this->getValidAddress($this->addr_from,2).$this->eol2; |
|
| 1006 | + if (isset($this->deliveryreceipt) && $this->deliveryreceipt == 1) $out .= "Disposition-Notification-To: ".$this->getValidAddress($this->addr_from, 2).$this->eol2; |
|
| 1007 | 1007 | |
| 1008 | 1008 | //$out.= "X-Priority: 3".$this->eol2; |
| 1009 | 1009 | |
| 1010 | - $out.= 'Date: ' . date("r") . $this->eol2; |
|
| 1010 | + $out .= 'Date: '.date("r").$this->eol2; |
|
| 1011 | 1011 | |
| 1012 | 1012 | $trackid = $this->trackid; |
| 1013 | 1013 | if ($trackid) |
| 1014 | 1014 | { |
| 1015 | 1015 | // References is kept in response and Message-ID is returned into In-Reply-To: |
| 1016 | - $out.= 'Message-ID: <' . time() . '.phpmail-dolibarr-'. $trackid . '@' . $host . ">" . $this->eol2; // Uppercase seems replaced by phpmail |
|
| 1017 | - $out.= 'References: <' . time() . '.phpmail-dolibarr-'. $trackid . '@' . $host . ">" . $this->eol2; |
|
| 1018 | - $out.= 'X-Dolibarr-TRACKID: ' . $trackid . '@' . $host. $this->eol2; |
|
| 1016 | + $out .= 'Message-ID: <'.time().'.phpmail-dolibarr-'.$trackid.'@'.$host.">".$this->eol2; // Uppercase seems replaced by phpmail |
|
| 1017 | + $out .= 'References: <'.time().'.phpmail-dolibarr-'.$trackid.'@'.$host.">".$this->eol2; |
|
| 1018 | + $out .= 'X-Dolibarr-TRACKID: '.$trackid.'@'.$host.$this->eol2; |
|
| 1019 | 1019 | } |
| 1020 | 1020 | else |
| 1021 | 1021 | { |
| 1022 | - $out.= 'Message-ID: <' . time() . '.phpmail@' . $host . ">" . $this->eol2; |
|
| 1022 | + $out .= 'Message-ID: <'.time().'.phpmail@'.$host.">".$this->eol2; |
|
| 1023 | 1023 | } |
| 1024 | 1024 | |
| 1025 | - if (! empty($_SERVER['REMOTE_ADDR'])) $out.= "X-RemoteAddr: " . $_SERVER['REMOTE_ADDR']. $this->eol2; |
|
| 1026 | - $out.= "X-Mailer: Dolibarr version " . DOL_VERSION ." (using php mail)".$this->eol2; |
|
| 1027 | - $out.= "Mime-Version: 1.0".$this->eol2; |
|
| 1025 | + if (!empty($_SERVER['REMOTE_ADDR'])) $out .= "X-RemoteAddr: ".$_SERVER['REMOTE_ADDR'].$this->eol2; |
|
| 1026 | + $out .= "X-Mailer: Dolibarr version ".DOL_VERSION." (using php mail)".$this->eol2; |
|
| 1027 | + $out .= "Mime-Version: 1.0".$this->eol2; |
|
| 1028 | 1028 | |
| 1029 | 1029 | //$out.= "From: ".$this->getValidAddress($this->addr_from,3,1).$this->eol; |
| 1030 | 1030 | |
| 1031 | - $out.= "Content-Type: multipart/mixed;".$this->eol2." boundary=\"".$this->mixed_boundary."\"".$this->eol2; |
|
| 1032 | - $out.= "Content-Transfer-Encoding: 8bit".$this->eol2; // TODO Seems to be ignored. Header is 7bit once received. |
|
| 1031 | + $out .= "Content-Type: multipart/mixed;".$this->eol2." boundary=\"".$this->mixed_boundary."\"".$this->eol2; |
|
| 1032 | + $out .= "Content-Transfer-Encoding: 8bit".$this->eol2; // TODO Seems to be ignored. Header is 7bit once received. |
|
| 1033 | 1033 | |
| 1034 | 1034 | dol_syslog("CMailFile::write_smtpheaders smtp_header=\n".$out); |
| 1035 | 1035 | return $out; |
@@ -1047,18 +1047,18 @@ discard block |
||
| 1047 | 1047 | function write_mimeheaders($filename_list, $mimefilename_list) |
| 1048 | 1048 | { |
| 1049 | 1049 | // phpcs:enable |
| 1050 | - $mimedone=0; |
|
| 1050 | + $mimedone = 0; |
|
| 1051 | 1051 | $out = ""; |
| 1052 | 1052 | |
| 1053 | 1053 | if (is_array($filename_list)) |
| 1054 | 1054 | { |
| 1055 | - $filename_list_size=count($filename_list); |
|
| 1056 | - for($i=0;$i < $filename_list_size;$i++) |
|
| 1055 | + $filename_list_size = count($filename_list); |
|
| 1056 | + for ($i = 0; $i < $filename_list_size; $i++) |
|
| 1057 | 1057 | { |
| 1058 | 1058 | if ($filename_list[$i]) |
| 1059 | 1059 | { |
| 1060 | 1060 | if ($mimefilename_list[$i]) $filename_list[$i] = $mimefilename_list[$i]; |
| 1061 | - $out.= "X-attachments: $filename_list[$i]".$this->eol2; |
|
| 1061 | + $out .= "X-attachments: $filename_list[$i]".$this->eol2; |
|
| 1062 | 1062 | } |
| 1063 | 1063 | } |
| 1064 | 1064 | } |
@@ -1079,31 +1079,31 @@ discard block |
||
| 1079 | 1079 | // phpcs:enable |
| 1080 | 1080 | global $conf; |
| 1081 | 1081 | |
| 1082 | - $out=''; |
|
| 1082 | + $out = ''; |
|
| 1083 | 1083 | |
| 1084 | - $out.= "--" . $this->mixed_boundary . $this->eol; |
|
| 1084 | + $out .= "--".$this->mixed_boundary.$this->eol; |
|
| 1085 | 1085 | |
| 1086 | 1086 | if ($this->atleastoneimage) |
| 1087 | 1087 | { |
| 1088 | - $out.= "Content-Type: multipart/alternative;".$this->eol." boundary=\"".$this->alternative_boundary."\"".$this->eol; |
|
| 1089 | - $out.= $this->eol; |
|
| 1090 | - $out.= "--" . $this->alternative_boundary . $this->eol; |
|
| 1088 | + $out .= "Content-Type: multipart/alternative;".$this->eol." boundary=\"".$this->alternative_boundary."\"".$this->eol; |
|
| 1089 | + $out .= $this->eol; |
|
| 1090 | + $out .= "--".$this->alternative_boundary.$this->eol; |
|
| 1091 | 1091 | } |
| 1092 | 1092 | |
| 1093 | 1093 | // Make RFC821 Compliant, replace bare linefeeds |
| 1094 | - $strContent = preg_replace("/(?<!\r)\n/si", "\r\n", $msgtext); // PCRE modifier /s means new lines are common chars |
|
| 1095 | - if (! empty($conf->global->MAIN_FIX_FOR_BUGGED_MTA)) |
|
| 1094 | + $strContent = preg_replace("/(?<!\r)\n/si", "\r\n", $msgtext); // PCRE modifier /s means new lines are common chars |
|
| 1095 | + if (!empty($conf->global->MAIN_FIX_FOR_BUGGED_MTA)) |
|
| 1096 | 1096 | { |
| 1097 | - $strContent = preg_replace("/\r\n/si", "\n", $strContent); // PCRE modifier /s means new lines are common chars |
|
| 1097 | + $strContent = preg_replace("/\r\n/si", "\n", $strContent); // PCRE modifier /s means new lines are common chars |
|
| 1098 | 1098 | } |
| 1099 | 1099 | |
| 1100 | 1100 | $strContentAltText = ''; |
| 1101 | 1101 | if ($this->msgishtml) |
| 1102 | 1102 | { |
| 1103 | 1103 | // Similar code to forge a text from html is also in CMailFile.class.php |
| 1104 | - $strContentAltText = preg_replace("/<br\s*[^>]*>/"," ", $strContent); |
|
| 1104 | + $strContentAltText = preg_replace("/<br\s*[^>]*>/", " ", $strContent); |
|
| 1105 | 1105 | $strContentAltText = html_entity_decode(strip_tags($strContentAltText)); |
| 1106 | - $strContentAltText = rtrim(wordwrap($strContentAltText, 75, empty($conf->global->MAIN_FIX_FOR_BUGGED_MTA)?"\r\n":"\n")); |
|
| 1106 | + $strContentAltText = rtrim(wordwrap($strContentAltText, 75, empty($conf->global->MAIN_FIX_FOR_BUGGED_MTA) ? "\r\n" : "\n")); |
|
| 1107 | 1107 | |
| 1108 | 1108 | // Check if html header already in message, if not complete the message |
| 1109 | 1109 | $strContent = $this->checkIfHTML($strContent); |
@@ -1112,57 +1112,57 @@ discard block |
||
| 1112 | 1112 | // Make RFC2045 Compliant, split lines |
| 1113 | 1113 | //$strContent = rtrim(chunk_split($strContent)); // Function chunck_split seems ko if not used on a base64 content |
| 1114 | 1114 | // TODO Encode main content into base64 and use the chunk_split, or quoted-printable |
| 1115 | - $strContent = rtrim(wordwrap($strContent, 75, empty($conf->global->MAIN_FIX_FOR_BUGGED_MTA)?"\r\n":"\n")); // TODO Using this method creates unexpected line break on text/plain content. |
|
| 1115 | + $strContent = rtrim(wordwrap($strContent, 75, empty($conf->global->MAIN_FIX_FOR_BUGGED_MTA) ? "\r\n" : "\n")); // TODO Using this method creates unexpected line break on text/plain content. |
|
| 1116 | 1116 | |
| 1117 | 1117 | if ($this->msgishtml) |
| 1118 | 1118 | { |
| 1119 | 1119 | if ($this->atleastoneimage) |
| 1120 | 1120 | { |
| 1121 | - $out.= "Content-Type: text/plain; charset=".$conf->file->character_set_client.$this->eol; |
|
| 1121 | + $out .= "Content-Type: text/plain; charset=".$conf->file->character_set_client.$this->eol; |
|
| 1122 | 1122 | //$out.= "Content-Transfer-Encoding: 7bit".$this->eol; |
| 1123 | - $out.= $this->eol.($strContentAltText?$strContentAltText:strip_tags($strContent)).$this->eol; // Add plain text message |
|
| 1124 | - $out.= "--" . $this->alternative_boundary . $this->eol; |
|
| 1125 | - $out.= "Content-Type: multipart/related;".$this->eol." boundary=\"".$this->related_boundary."\"".$this->eol; |
|
| 1126 | - $out.= $this->eol; |
|
| 1127 | - $out.= "--" . $this->related_boundary . $this->eol; |
|
| 1123 | + $out .= $this->eol.($strContentAltText ? $strContentAltText : strip_tags($strContent)).$this->eol; // Add plain text message |
|
| 1124 | + $out .= "--".$this->alternative_boundary.$this->eol; |
|
| 1125 | + $out .= "Content-Type: multipart/related;".$this->eol." boundary=\"".$this->related_boundary."\"".$this->eol; |
|
| 1126 | + $out .= $this->eol; |
|
| 1127 | + $out .= "--".$this->related_boundary.$this->eol; |
|
| 1128 | 1128 | } |
| 1129 | 1129 | |
| 1130 | - if (! $this->atleastoneimage && $strContentAltText && ! empty($conf->global->MAIN_MAIL_USE_MULTI_PART)) // Add plain text message part before html part |
|
| 1130 | + if (!$this->atleastoneimage && $strContentAltText && !empty($conf->global->MAIN_MAIL_USE_MULTI_PART)) // Add plain text message part before html part |
|
| 1131 | 1131 | { |
| 1132 | - $out.= "Content-Type: multipart/alternative;".$this->eol." boundary=\"".$this->alternative_boundary."\"".$this->eol; |
|
| 1133 | - $out.= $this->eol; |
|
| 1134 | - $out.= "--" . $this->alternative_boundary . $this->eol; |
|
| 1135 | - $out.= "Content-Type: text/plain; charset=".$conf->file->character_set_client.$this->eol; |
|
| 1132 | + $out .= "Content-Type: multipart/alternative;".$this->eol." boundary=\"".$this->alternative_boundary."\"".$this->eol; |
|
| 1133 | + $out .= $this->eol; |
|
| 1134 | + $out .= "--".$this->alternative_boundary.$this->eol; |
|
| 1135 | + $out .= "Content-Type: text/plain; charset=".$conf->file->character_set_client.$this->eol; |
|
| 1136 | 1136 | //$out.= "Content-Transfer-Encoding: 7bit".$this->eol; |
| 1137 | - $out.= $this->eol.$strContentAltText.$this->eol; |
|
| 1138 | - $out.= "--" . $this->alternative_boundary . $this->eol; |
|
| 1137 | + $out .= $this->eol.$strContentAltText.$this->eol; |
|
| 1138 | + $out .= "--".$this->alternative_boundary.$this->eol; |
|
| 1139 | 1139 | } |
| 1140 | 1140 | |
| 1141 | - $out.= "Content-Type: text/html; charset=".$conf->file->character_set_client.$this->eol; |
|
| 1141 | + $out .= "Content-Type: text/html; charset=".$conf->file->character_set_client.$this->eol; |
|
| 1142 | 1142 | //$out.= "Content-Transfer-Encoding: 7bit".$this->eol; // TODO Use base64 |
| 1143 | - $out.= $this->eol.$strContent.$this->eol; |
|
| 1143 | + $out .= $this->eol.$strContent.$this->eol; |
|
| 1144 | 1144 | |
| 1145 | - if (! $this->atleastoneimage && $strContentAltText && ! empty($conf->global->MAIN_MAIL_USE_MULTI_PART)) // Add plain text message part after html part |
|
| 1145 | + if (!$this->atleastoneimage && $strContentAltText && !empty($conf->global->MAIN_MAIL_USE_MULTI_PART)) // Add plain text message part after html part |
|
| 1146 | 1146 | { |
| 1147 | - $out.= "--" . $this->alternative_boundary . "--". $this->eol; |
|
| 1147 | + $out .= "--".$this->alternative_boundary."--".$this->eol; |
|
| 1148 | 1148 | } |
| 1149 | 1149 | } |
| 1150 | 1150 | else |
| 1151 | 1151 | { |
| 1152 | - $out.= "Content-Type: text/plain; charset=".$conf->file->character_set_client.$this->eol; |
|
| 1152 | + $out .= "Content-Type: text/plain; charset=".$conf->file->character_set_client.$this->eol; |
|
| 1153 | 1153 | //$out.= "Content-Transfer-Encoding: 7bit".$this->eol; |
| 1154 | - $out.= $this->eol.$strContent.$this->eol; |
|
| 1154 | + $out .= $this->eol.$strContent.$this->eol; |
|
| 1155 | 1155 | } |
| 1156 | 1156 | |
| 1157 | - $out.= $this->eol; |
|
| 1157 | + $out .= $this->eol; |
|
| 1158 | 1158 | |
| 1159 | 1159 | // Encode images |
| 1160 | 1160 | if ($this->atleastoneimage) |
| 1161 | 1161 | { |
| 1162 | 1162 | $out .= $this->write_images($this->images_encoded); |
| 1163 | 1163 | // always end related and end alternative after inline images |
| 1164 | - $out .= "--" . $this->related_boundary . "--" . $this->eol; |
|
| 1165 | - $out .= $this->eol . "--" . $this->alternative_boundary . "--" . $this->eol; |
|
| 1164 | + $out .= "--".$this->related_boundary."--".$this->eol; |
|
| 1165 | + $out .= $this->eol."--".$this->alternative_boundary."--".$this->eol; |
|
| 1166 | 1166 | $out .= $this->eol; |
| 1167 | 1167 | } |
| 1168 | 1168 | |
@@ -1178,13 +1178,13 @@ discard block |
||
| 1178 | 1178 | * @param array $mimefilename_list Tableau |
| 1179 | 1179 | * @return string Chaine fichiers encodes |
| 1180 | 1180 | */ |
| 1181 | - function write_files($filename_list,$mimetype_list,$mimefilename_list) |
|
| 1181 | + function write_files($filename_list, $mimetype_list, $mimefilename_list) |
|
| 1182 | 1182 | { |
| 1183 | 1183 | // phpcs:enable |
| 1184 | 1184 | $out = ''; |
| 1185 | 1185 | |
| 1186 | - $filename_list_size=count($filename_list); |
|
| 1187 | - for($i=0;$i < $filename_list_size;$i++) |
|
| 1186 | + $filename_list_size = count($filename_list); |
|
| 1187 | + for ($i = 0; $i < $filename_list_size; $i++) |
|
| 1188 | 1188 | { |
| 1189 | 1189 | if ($filename_list[$i]) |
| 1190 | 1190 | { |
@@ -1193,18 +1193,18 @@ discard block |
||
| 1193 | 1193 | if ($encoded >= 0) |
| 1194 | 1194 | { |
| 1195 | 1195 | if ($mimefilename_list[$i]) $filename_list[$i] = $mimefilename_list[$i]; |
| 1196 | - if (! $mimetype_list[$i]) { |
|
| 1196 | + if (!$mimetype_list[$i]) { |
|
| 1197 | 1197 | $mimetype_list[$i] = "application/octet-stream"; |
| 1198 | 1198 | } |
| 1199 | 1199 | |
| 1200 | - $out.= "--" . $this->mixed_boundary . $this->eol; |
|
| 1201 | - $out.= "Content-Disposition: attachment; filename=\"".$filename_list[$i]."\"".$this->eol; |
|
| 1202 | - $out.= "Content-Type: " . $mimetype_list[$i] . "; name=\"".$filename_list[$i]."\"".$this->eol; |
|
| 1203 | - $out.= "Content-Transfer-Encoding: base64".$this->eol; |
|
| 1204 | - $out.= "Content-Description: ".$filename_list[$i].$this->eol; |
|
| 1205 | - $out.= $this->eol; |
|
| 1206 | - $out.= $encoded; |
|
| 1207 | - $out.= $this->eol; |
|
| 1200 | + $out .= "--".$this->mixed_boundary.$this->eol; |
|
| 1201 | + $out .= "Content-Disposition: attachment; filename=\"".$filename_list[$i]."\"".$this->eol; |
|
| 1202 | + $out .= "Content-Type: ".$mimetype_list[$i]."; name=\"".$filename_list[$i]."\"".$this->eol; |
|
| 1203 | + $out .= "Content-Transfer-Encoding: base64".$this->eol; |
|
| 1204 | + $out .= "Content-Description: ".$filename_list[$i].$this->eol; |
|
| 1205 | + $out .= $this->eol; |
|
| 1206 | + $out .= $encoded; |
|
| 1207 | + $out .= $this->eol; |
|
| 1208 | 1208 | //$out.= $this->eol; |
| 1209 | 1209 | } |
| 1210 | 1210 | else |
@@ -1236,14 +1236,14 @@ discard block |
||
| 1236 | 1236 | { |
| 1237 | 1237 | dol_syslog("CMailFile::write_images: ".$img["name"]); |
| 1238 | 1238 | |
| 1239 | - $out.= "--" . $this->related_boundary . $this->eol; // always related for an inline image |
|
| 1240 | - $out.= "Content-Type: " . $img["content_type"] . "; name=\"".$img["name"]."\"".$this->eol; |
|
| 1241 | - $out.= "Content-Transfer-Encoding: base64".$this->eol; |
|
| 1242 | - $out.= "Content-Disposition: inline; filename=\"".$img["name"]."\"".$this->eol; |
|
| 1243 | - $out.= "Content-ID: <".$img["cid"].">".$this->eol; |
|
| 1244 | - $out.= $this->eol; |
|
| 1245 | - $out.= $img["image_encoded"]; |
|
| 1246 | - $out.= $this->eol; |
|
| 1239 | + $out .= "--".$this->related_boundary.$this->eol; // always related for an inline image |
|
| 1240 | + $out .= "Content-Type: ".$img["content_type"]."; name=\"".$img["name"]."\"".$this->eol; |
|
| 1241 | + $out .= "Content-Transfer-Encoding: base64".$this->eol; |
|
| 1242 | + $out .= "Content-Disposition: inline; filename=\"".$img["name"]."\"".$this->eol; |
|
| 1243 | + $out .= "Content-ID: <".$img["cid"].">".$this->eol; |
|
| 1244 | + $out .= $this->eol; |
|
| 1245 | + $out .= $img["image_encoded"]; |
|
| 1246 | + $out .= $this->eol; |
|
| 1247 | 1247 | } |
| 1248 | 1248 | } |
| 1249 | 1249 | |
@@ -1259,44 +1259,44 @@ discard block |
||
| 1259 | 1259 | * @param int $port Example: 25, 465 |
| 1260 | 1260 | * @return int Socket id if ok, 0 if KO |
| 1261 | 1261 | */ |
| 1262 | - function check_server_port($host,$port) |
|
| 1262 | + function check_server_port($host, $port) |
|
| 1263 | 1263 | { |
| 1264 | 1264 | // phpcs:enable |
| 1265 | 1265 | global $conf; |
| 1266 | 1266 | |
| 1267 | - $_retVal=0; |
|
| 1268 | - $timeout=5; // Timeout in seconds |
|
| 1267 | + $_retVal = 0; |
|
| 1268 | + $timeout = 5; // Timeout in seconds |
|
| 1269 | 1269 | |
| 1270 | 1270 | if (function_exists('fsockopen')) |
| 1271 | 1271 | { |
| 1272 | - $keyforsmtpserver='MAIN_MAIL_SMTP_SERVER'; |
|
| 1273 | - $keyforsmtpport ='MAIN_MAIL_SMTP_PORT'; |
|
| 1274 | - $keyforsmtpid ='MAIN_MAIL_SMTPS_ID'; |
|
| 1275 | - $keyforsmtppw ='MAIN_MAIL_SMTPS_PW'; |
|
| 1276 | - $keyfortls ='MAIN_MAIL_EMAIL_TLS'; |
|
| 1277 | - $keyforstarttls ='MAIN_MAIL_EMAIL_STARTTLS'; |
|
| 1272 | + $keyforsmtpserver = 'MAIN_MAIL_SMTP_SERVER'; |
|
| 1273 | + $keyforsmtpport = 'MAIN_MAIL_SMTP_PORT'; |
|
| 1274 | + $keyforsmtpid = 'MAIN_MAIL_SMTPS_ID'; |
|
| 1275 | + $keyforsmtppw = 'MAIN_MAIL_SMTPS_PW'; |
|
| 1276 | + $keyfortls = 'MAIN_MAIL_EMAIL_TLS'; |
|
| 1277 | + $keyforstarttls = 'MAIN_MAIL_EMAIL_STARTTLS'; |
|
| 1278 | 1278 | if ($this->sendcontext == 'emailing' && !empty($conf->global->MAIN_MAIL_SENDMODE_EMAILING) && $conf->global->MAIN_MAIL_SENDMODE_EMAILING != 'default') |
| 1279 | 1279 | { |
| 1280 | - $keyforsmtpserver='MAIN_MAIL_SMTP_SERVER_EMAILING'; |
|
| 1281 | - $keyforsmtpport ='MAIN_MAIL_SMTP_PORT_EMAILING'; |
|
| 1282 | - $keyforsmtpid ='MAIN_MAIL_SMTPS_ID_EMAILING'; |
|
| 1283 | - $keyforsmtppw ='MAIN_MAIL_SMTPS_PW_EMAILING'; |
|
| 1284 | - $keyfortls ='MAIN_MAIL_EMAIL_TLS_EMAILING'; |
|
| 1285 | - $keyforstarttls ='MAIN_MAIL_EMAIL_STARTTLS_EMAILING'; |
|
| 1280 | + $keyforsmtpserver = 'MAIN_MAIL_SMTP_SERVER_EMAILING'; |
|
| 1281 | + $keyforsmtpport = 'MAIN_MAIL_SMTP_PORT_EMAILING'; |
|
| 1282 | + $keyforsmtpid = 'MAIN_MAIL_SMTPS_ID_EMAILING'; |
|
| 1283 | + $keyforsmtppw = 'MAIN_MAIL_SMTPS_PW_EMAILING'; |
|
| 1284 | + $keyfortls = 'MAIN_MAIL_EMAIL_TLS_EMAILING'; |
|
| 1285 | + $keyforstarttls = 'MAIN_MAIL_EMAIL_STARTTLS_EMAILING'; |
|
| 1286 | 1286 | } |
| 1287 | 1287 | |
| 1288 | 1288 | // If we use SSL/TLS |
| 1289 | - if (! empty($conf->global->$keyfortls) && function_exists('openssl_open')) $host='ssl://'.$host; |
|
| 1289 | + if (!empty($conf->global->$keyfortls) && function_exists('openssl_open')) $host = 'ssl://'.$host; |
|
| 1290 | 1290 | // tls smtp start with no encryption |
| 1291 | 1291 | //if (! empty($conf->global->MAIN_MAIL_EMAIL_STARTTLS) && function_exists('openssl_open')) $host='tls://'.$host; |
| 1292 | 1292 | |
| 1293 | 1293 | dol_syslog("Try socket connection to host=".$host." port=".$port); |
| 1294 | 1294 | //See if we can connect to the SMTP server |
| 1295 | 1295 | if ($socket = @fsockopen( |
| 1296 | - $host, // Host to test, IP or domain. Add ssl:// for SSL/TLS. |
|
| 1297 | - $port, // which Port number to use |
|
| 1298 | - $errno, // actual system level error |
|
| 1299 | - $errstr, // and any text that goes with the error |
|
| 1296 | + $host, // Host to test, IP or domain. Add ssl:// for SSL/TLS. |
|
| 1297 | + $port, // which Port number to use |
|
| 1298 | + $errno, // actual system level error |
|
| 1299 | + $errstr, // and any text that goes with the error |
|
| 1300 | 1300 | $timeout |
| 1301 | 1301 | )) // timeout for reading/writing data over the socket |
| 1302 | 1302 | { |
@@ -1306,11 +1306,11 @@ discard block |
||
| 1306 | 1306 | dol_syslog("Now we wait for answer 220"); |
| 1307 | 1307 | |
| 1308 | 1308 | // Check response from Server |
| 1309 | - if ( $_retVal = $this->server_parse($socket, "220") ) $_retVal = $socket; |
|
| 1309 | + if ($_retVal = $this->server_parse($socket, "220")) $_retVal = $socket; |
|
| 1310 | 1310 | } |
| 1311 | 1311 | else |
| 1312 | 1312 | { |
| 1313 | - $this->error = utf8_check('Error '.$errno.' - '.$errstr)?'Error '.$errno.' - '.$errstr:utf8_encode('Error '.$errno.' - '.$errstr); |
|
| 1313 | + $this->error = utf8_check('Error '.$errno.' - '.$errstr) ? 'Error '.$errno.' - '.$errstr : utf8_encode('Error '.$errno.' - '.$errstr); |
|
| 1314 | 1314 | } |
| 1315 | 1315 | } |
| 1316 | 1316 | return $_retVal; |
@@ -1328,21 +1328,21 @@ discard block |
||
| 1328 | 1328 | function server_parse($socket, $response) |
| 1329 | 1329 | { |
| 1330 | 1330 | // phpcs:enable |
| 1331 | - $_retVal = true; // Indicates if Object was created or not |
|
| 1331 | + $_retVal = true; // Indicates if Object was created or not |
|
| 1332 | 1332 | $server_response = ''; |
| 1333 | 1333 | |
| 1334 | - while (substr($server_response,3,1) != ' ') |
|
| 1334 | + while (substr($server_response, 3, 1) != ' ') |
|
| 1335 | 1335 | { |
| 1336 | - if (! ($server_response = fgets($socket, 256)) ) |
|
| 1336 | + if (!($server_response = fgets($socket, 256))) |
|
| 1337 | 1337 | { |
| 1338 | - $this->error="Couldn't get mail server response codes"; |
|
| 1338 | + $this->error = "Couldn't get mail server response codes"; |
|
| 1339 | 1339 | return false; |
| 1340 | 1340 | } |
| 1341 | 1341 | } |
| 1342 | 1342 | |
| 1343 | - if( !( substr($server_response, 0, 3) == $response ) ) |
|
| 1343 | + if (!(substr($server_response, 0, 3) == $response)) |
|
| 1344 | 1344 | { |
| 1345 | - $this->error="Ran into problems sending Mail.\r\nResponse: $server_response"; |
|
| 1345 | + $this->error = "Ran into problems sending Mail.\r\nResponse: $server_response"; |
|
| 1346 | 1346 | $_retVal = false; |
| 1347 | 1347 | } |
| 1348 | 1348 | |
@@ -1361,22 +1361,22 @@ discard block |
||
| 1361 | 1361 | $extensions = array_keys($this->image_types); |
| 1362 | 1362 | |
| 1363 | 1363 | $matches = array(); |
| 1364 | - preg_match_all('/(?:"|\')([^"\']+\.('.implode('|', $extensions).'))(?:"|\')/Ui', $this->html, $matches); // If "xxx.ext" or 'xxx.ext' found |
|
| 1364 | + preg_match_all('/(?:"|\')([^"\']+\.('.implode('|', $extensions).'))(?:"|\')/Ui', $this->html, $matches); // If "xxx.ext" or 'xxx.ext' found |
|
| 1365 | 1365 | |
| 1366 | - if (! empty($matches)) |
|
| 1366 | + if (!empty($matches)) |
|
| 1367 | 1367 | { |
| 1368 | - $i=0; |
|
| 1368 | + $i = 0; |
|
| 1369 | 1369 | foreach ($matches[1] as $full) |
| 1370 | 1370 | { |
| 1371 | 1371 | |
| 1372 | - if (preg_match('/file=([A-Za-z0-9_\-\/]+[\.]?[A-Za-z0-9]+)?$/i',$full,$regs)) // If xxx is 'file=aaa' |
|
| 1372 | + if (preg_match('/file=([A-Za-z0-9_\-\/]+[\.]?[A-Za-z0-9]+)?$/i', $full, $regs)) // If xxx is 'file=aaa' |
|
| 1373 | 1373 | { |
| 1374 | 1374 | $img = $regs[1]; |
| 1375 | 1375 | |
| 1376 | 1376 | if (file_exists($images_dir.'/'.$img)) |
| 1377 | 1377 | { |
| 1378 | 1378 | // Image path in src |
| 1379 | - $src = preg_quote($full,'/'); |
|
| 1379 | + $src = preg_quote($full, '/'); |
|
| 1380 | 1380 | |
| 1381 | 1381 | // Image full path |
| 1382 | 1382 | $this->html_images[$i]["fullpath"] = $images_dir.'/'.$img; |
@@ -1387,12 +1387,12 @@ discard block |
||
| 1387 | 1387 | // Content type |
| 1388 | 1388 | if (preg_match('/^.+\.(\w{3,4})$/', $img, $reg)) |
| 1389 | 1389 | { |
| 1390 | - $ext=strtolower($reg[1]); |
|
| 1390 | + $ext = strtolower($reg[1]); |
|
| 1391 | 1391 | $this->html_images[$i]["content_type"] = $this->image_types[$ext]; |
| 1392 | 1392 | } |
| 1393 | 1393 | |
| 1394 | 1394 | // cid |
| 1395 | - $this->html_images[$i]["cid"] = dol_hash(uniqid(time()), 3); // Force md5 hash (does not contains special chars) |
|
| 1395 | + $this->html_images[$i]["cid"] = dol_hash(uniqid(time()), 3); // Force md5 hash (does not contains special chars) |
|
| 1396 | 1396 | $this->html = preg_replace("/src=\"$src\"|src='$src'/i", "src=\"cid:".$this->html_images[$i]["cid"]."\"", $this->html); |
| 1397 | 1397 | } |
| 1398 | 1398 | $i++; |
@@ -1403,20 +1403,20 @@ discard block |
||
| 1403 | 1403 | { |
| 1404 | 1404 | $inline = array(); |
| 1405 | 1405 | |
| 1406 | - $i=0; |
|
| 1406 | + $i = 0; |
|
| 1407 | 1407 | |
| 1408 | 1408 | foreach ($this->html_images as $img) |
| 1409 | 1409 | { |
| 1410 | 1410 | $fullpath = $images_dir.'/'.$img["name"]; |
| 1411 | 1411 | |
| 1412 | 1412 | // If duplicate images are embedded, they may show up as attachments, so remove them. |
| 1413 | - if (!in_array($fullpath,$inline)) |
|
| 1413 | + if (!in_array($fullpath, $inline)) |
|
| 1414 | 1414 | { |
| 1415 | 1415 | // Read image file |
| 1416 | 1416 | if ($image = file_get_contents($fullpath)) |
| 1417 | 1417 | { |
| 1418 | 1418 | // On garde que le nom de l'image |
| 1419 | - preg_match('/([A-Za-z0-9_-]+[\.]?[A-Za-z0-9]+)?$/i',$img["name"],$regs); |
|
| 1419 | + preg_match('/([A-Za-z0-9_-]+[\.]?[A-Za-z0-9]+)?$/i', $img["name"], $regs); |
|
| 1420 | 1420 | $imgName = $regs[1]; |
| 1421 | 1421 | |
| 1422 | 1422 | $this->images_encoded[$i]['name'] = $imgName; |
@@ -1457,19 +1457,19 @@ discard block |
||
| 1457 | 1457 | * If format 3: '<[email protected]>' or '"John Doe" <[email protected]>' or '"=?UTF-8?B?Sm9obiBEb2U=?=" <[email protected]>' |
| 1458 | 1458 | * If format 4: 'John Doe' or '[email protected]' if no label exists |
| 1459 | 1459 | */ |
| 1460 | - static function getValidAddress($address,$format,$encode=0,$maxnumberofemail=0) |
|
| 1460 | + static function getValidAddress($address, $format, $encode = 0, $maxnumberofemail = 0) |
|
| 1461 | 1461 | { |
| 1462 | 1462 | global $conf; |
| 1463 | 1463 | |
| 1464 | - $ret=''; |
|
| 1464 | + $ret = ''; |
|
| 1465 | 1465 | |
| 1466 | - $arrayaddress=explode(',',$address); |
|
| 1466 | + $arrayaddress = explode(',', $address); |
|
| 1467 | 1467 | |
| 1468 | 1468 | // Boucle sur chaque composant de l'adresse |
| 1469 | - $i=0; |
|
| 1470 | - foreach($arrayaddress as $val) |
|
| 1469 | + $i = 0; |
|
| 1470 | + foreach ($arrayaddress as $val) |
|
| 1471 | 1471 | { |
| 1472 | - if (preg_match('/^(.*)<(.*)>$/i',trim($val),$regs)) |
|
| 1472 | + if (preg_match('/^(.*)<(.*)>$/i', trim($val), $regs)) |
|
| 1473 | 1473 | { |
| 1474 | 1474 | $name = trim($regs[1]); |
| 1475 | 1475 | $email = trim($regs[2]); |
@@ -1484,32 +1484,32 @@ discard block |
||
| 1484 | 1484 | { |
| 1485 | 1485 | $i++; |
| 1486 | 1486 | |
| 1487 | - $newemail=''; |
|
| 1487 | + $newemail = ''; |
|
| 1488 | 1488 | if ($format == 4) |
| 1489 | 1489 | { |
| 1490 | - $newemail = $name?$name:$email; |
|
| 1490 | + $newemail = $name ? $name : $email; |
|
| 1491 | 1491 | } |
| 1492 | 1492 | if ($format == 2) |
| 1493 | 1493 | { |
| 1494 | - $newemail=$email; |
|
| 1494 | + $newemail = $email; |
|
| 1495 | 1495 | } |
| 1496 | 1496 | if ($format == 1 || $format == 3) |
| 1497 | 1497 | { |
| 1498 | - $newemail='<'.$email.'>'; |
|
| 1498 | + $newemail = '<'.$email.'>'; |
|
| 1499 | 1499 | } |
| 1500 | 1500 | if ($format == 0 || $format == 3) |
| 1501 | 1501 | { |
| 1502 | - if (! empty($conf->global->MAIN_MAIL_NO_FULL_EMAIL)) $newemail='<'.$email.'>'; |
|
| 1503 | - elseif (! $name) $newemail='<'.$email.'>'; |
|
| 1504 | - else $newemail=($format==3?'"':'').($encode?self::encodetorfc2822($name):$name).($format==3?'"':'').' <'.$email.'>'; |
|
| 1502 | + if (!empty($conf->global->MAIN_MAIL_NO_FULL_EMAIL)) $newemail = '<'.$email.'>'; |
|
| 1503 | + elseif (!$name) $newemail = '<'.$email.'>'; |
|
| 1504 | + else $newemail = ($format == 3 ? '"' : '').($encode ?self::encodetorfc2822($name) : $name).($format == 3 ? '"' : '').' <'.$email.'>'; |
|
| 1505 | 1505 | } |
| 1506 | 1506 | |
| 1507 | - $ret=($ret ? $ret.',' : '').$newemail; |
|
| 1507 | + $ret = ($ret ? $ret.',' : '').$newemail; |
|
| 1508 | 1508 | |
| 1509 | 1509 | // Stop if we have too much records |
| 1510 | 1510 | if ($maxnumberofemail && $i >= $maxnumberofemail) |
| 1511 | 1511 | { |
| 1512 | - if (count($arrayaddress) > $maxnumberofemail) $ret.='...'; |
|
| 1512 | + if (count($arrayaddress) > $maxnumberofemail) $ret .= '...'; |
|
| 1513 | 1513 | break; |
| 1514 | 1514 | } |
| 1515 | 1515 | } |
@@ -1528,14 +1528,14 @@ discard block |
||
| 1528 | 1528 | { |
| 1529 | 1529 | global $conf; |
| 1530 | 1530 | |
| 1531 | - $ret=array(); |
|
| 1531 | + $ret = array(); |
|
| 1532 | 1532 | |
| 1533 | - $arrayaddress=explode(',',$address); |
|
| 1533 | + $arrayaddress = explode(',', $address); |
|
| 1534 | 1534 | |
| 1535 | 1535 | // Boucle sur chaque composant de l'adresse |
| 1536 | - foreach($arrayaddress as $val) |
|
| 1536 | + foreach ($arrayaddress as $val) |
|
| 1537 | 1537 | { |
| 1538 | - if (preg_match('/^(.*)<(.*)>$/i',trim($val),$regs)) |
|
| 1538 | + if (preg_match('/^(.*)<(.*)>$/i', trim($val), $regs)) |
|
| 1539 | 1539 | { |
| 1540 | 1540 | $name = trim($regs[1]); |
| 1541 | 1541 | $email = trim($regs[2]); |
@@ -1546,7 +1546,7 @@ discard block |
||
| 1546 | 1546 | $email = trim($val); |
| 1547 | 1547 | } |
| 1548 | 1548 | |
| 1549 | - $ret[$email]=empty($conf->global->MAIN_MAIL_NO_FULL_EMAIL)?$name:null; |
|
| 1549 | + $ret[$email] = empty($conf->global->MAIN_MAIL_NO_FULL_EMAIL) ? $name : null; |
|
| 1550 | 1550 | } |
| 1551 | 1551 | |
| 1552 | 1552 | return $ret; |
@@ -37,7 +37,7 @@ discard block |
||
| 37 | 37 | /** |
| 38 | 38 | * @var string Error code (or message) |
| 39 | 39 | */ |
| 40 | - public $error=''; |
|
| 40 | + public $error = ''; |
|
| 41 | 41 | |
| 42 | 42 | |
| 43 | 43 | /** |
@@ -60,7 +60,7 @@ discard block |
||
| 60 | 60 | * @param int $idForm Id du formulaire |
| 61 | 61 | * @return string HTML select string |
| 62 | 62 | */ |
| 63 | - function setBarcodeEncoder($selected,$barcodelist,$code_id,$idForm='formbarcode') |
|
| 63 | + function setBarcodeEncoder($selected, $barcodelist, $code_id, $idForm = 'formbarcode') |
|
| 64 | 64 | { |
| 65 | 65 | global $conf, $langs; |
| 66 | 66 | |
@@ -81,8 +81,8 @@ discard block |
||
| 81 | 81 | } |
| 82 | 82 | |
| 83 | 83 | // We check if barcode is already selected by default |
| 84 | - if (((! empty($conf->product->enabled) || ! empty($conf->service->enabled)) && $conf->global->PRODUIT_DEFAULT_BARCODE_TYPE == $code_id) || |
|
| 85 | - (! empty($conf->societe->enabled) && $conf->global->GENBARCODE_BARCODETYPE_THIRDPARTY == $code_id)) |
|
| 84 | + if (((!empty($conf->product->enabled) || !empty($conf->service->enabled)) && $conf->global->PRODUIT_DEFAULT_BARCODE_TYPE == $code_id) || |
|
| 85 | + (!empty($conf->societe->enabled) && $conf->global->GENBARCODE_BARCODETYPE_THIRDPARTY == $code_id)) |
|
| 86 | 86 | { |
| 87 | 87 | $disable = 'disabled'; |
| 88 | 88 | } |
@@ -90,24 +90,24 @@ discard block |
||
| 90 | 90 | if (!empty($conf->use_javascript_ajax)) |
| 91 | 91 | { |
| 92 | 92 | $select_encoder = '<form action="'.DOL_URL_ROOT.'/admin/barcode.php" method="POST" id="form'.$idForm.'">'; |
| 93 | - $select_encoder.= '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">'; |
|
| 94 | - $select_encoder.= '<input type="hidden" name="action" value="update">'; |
|
| 95 | - $select_encoder.= '<input type="hidden" name="code_id" value="'.$code_id.'">'; |
|
| 93 | + $select_encoder .= '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">'; |
|
| 94 | + $select_encoder .= '<input type="hidden" name="action" value="update">'; |
|
| 95 | + $select_encoder .= '<input type="hidden" name="code_id" value="'.$code_id.'">'; |
|
| 96 | 96 | } |
| 97 | 97 | |
| 98 | - $selectname=(!empty($conf->use_javascript_ajax)?'coder':'coder'.$code_id); |
|
| 99 | - $select_encoder.= '<select id="select'.$idForm.'" class="flat" name="'.$selectname.'">'; |
|
| 100 | - $select_encoder.= '<option value="0"'.($selected==0?' selected':'').' '.$disable.'>'.$langs->trans('Disable').'</option>'; |
|
| 101 | - $select_encoder.= '<option value="-1" disabled>--------------------</option>'; |
|
| 102 | - foreach($barcodelist as $key => $value) |
|
| 98 | + $selectname = (!empty($conf->use_javascript_ajax) ? 'coder' : 'coder'.$code_id); |
|
| 99 | + $select_encoder .= '<select id="select'.$idForm.'" class="flat" name="'.$selectname.'">'; |
|
| 100 | + $select_encoder .= '<option value="0"'.($selected == 0 ? ' selected' : '').' '.$disable.'>'.$langs->trans('Disable').'</option>'; |
|
| 101 | + $select_encoder .= '<option value="-1" disabled>--------------------</option>'; |
|
| 102 | + foreach ($barcodelist as $key => $value) |
|
| 103 | 103 | { |
| 104 | - $select_encoder.= '<option value="'.$key.'"'.($selected==$key?' selected':'').'>'.$value.'</option>'; |
|
| 104 | + $select_encoder .= '<option value="'.$key.'"'.($selected == $key ? ' selected' : '').'>'.$value.'</option>'; |
|
| 105 | 105 | } |
| 106 | - $select_encoder.= '</select>'; |
|
| 106 | + $select_encoder .= '</select>'; |
|
| 107 | 107 | |
| 108 | 108 | if (!empty($conf->use_javascript_ajax)) |
| 109 | 109 | { |
| 110 | - $select_encoder.= '</form>'; |
|
| 110 | + $select_encoder .= '</form>'; |
|
| 111 | 111 | } |
| 112 | 112 | |
| 113 | 113 | return $select_encoder; |
@@ -123,7 +123,7 @@ discard block |
||
| 123 | 123 | * @return void |
| 124 | 124 | * @deprecated |
| 125 | 125 | */ |
| 126 | - function select_barcode_type($selected='', $htmlname='barcodetype_id', $useempty=0) |
|
| 126 | + function select_barcode_type($selected = '', $htmlname = 'barcodetype_id', $useempty = 0) |
|
| 127 | 127 | { |
| 128 | 128 | // phpcs:enable |
| 129 | 129 | print $this->selectBarcodeType($selected, $htmlname, $useempty); |
@@ -137,17 +137,17 @@ discard block |
||
| 137 | 137 | * @param int $useempty Display empty value in select |
| 138 | 138 | * @return string |
| 139 | 139 | */ |
| 140 | - function selectBarcodeType($selected='', $htmlname='barcodetype_id', $useempty=0) |
|
| 140 | + function selectBarcodeType($selected = '', $htmlname = 'barcodetype_id', $useempty = 0) |
|
| 141 | 141 | { |
| 142 | 142 | global $langs, $conf; |
| 143 | 143 | |
| 144 | 144 | $out = ''; |
| 145 | 145 | |
| 146 | 146 | $sql = "SELECT rowid, code, libelle"; |
| 147 | - $sql.= " FROM ".MAIN_DB_PREFIX."c_barcode_type"; |
|
| 148 | - $sql.= " WHERE coder <> '0'"; |
|
| 149 | - $sql.= " AND entity = ".$conf->entity; |
|
| 150 | - $sql.= " ORDER BY code"; |
|
| 147 | + $sql .= " FROM ".MAIN_DB_PREFIX."c_barcode_type"; |
|
| 148 | + $sql .= " WHERE coder <> '0'"; |
|
| 149 | + $sql .= " AND entity = ".$conf->entity; |
|
| 150 | + $sql .= " ORDER BY code"; |
|
| 151 | 151 | |
| 152 | 152 | $result = $this->db->query($sql); |
| 153 | 153 | if ($result) { |
@@ -155,20 +155,20 @@ discard block |
||
| 155 | 155 | $i = 0; |
| 156 | 156 | |
| 157 | 157 | if ($useempty && $num > 0) { |
| 158 | - $out .= '<select class="flat minwidth75imp" name="' . $htmlname . '" id="select_' . $htmlname . '">'; |
|
| 158 | + $out .= '<select class="flat minwidth75imp" name="'.$htmlname.'" id="select_'.$htmlname.'">'; |
|
| 159 | 159 | $out .= '<option value="0"> </option>'; |
| 160 | 160 | } else { |
| 161 | 161 | $langs->load("errors"); |
| 162 | - $out .= '<select disabled class="flat minwidth75imp" name="' . $htmlname . '" id="select_' . $htmlname . '">'; |
|
| 163 | - $out .= '<option value="0" selected>' . $langs->trans('ErrorNoActivatedBarcode') . '</option>'; |
|
| 162 | + $out .= '<select disabled class="flat minwidth75imp" name="'.$htmlname.'" id="select_'.$htmlname.'">'; |
|
| 163 | + $out .= '<option value="0" selected>'.$langs->trans('ErrorNoActivatedBarcode').'</option>'; |
|
| 164 | 164 | } |
| 165 | 165 | |
| 166 | 166 | while ($i < $num) { |
| 167 | 167 | $obj = $this->db->fetch_object($result); |
| 168 | 168 | if ($selected == $obj->rowid) { |
| 169 | - $out .= '<option value="' . $obj->rowid . '" selected>'; |
|
| 169 | + $out .= '<option value="'.$obj->rowid.'" selected>'; |
|
| 170 | 170 | } else { |
| 171 | - $out .= '<option value="' . $obj->rowid . '">'; |
|
| 171 | + $out .= '<option value="'.$obj->rowid.'">'; |
|
| 172 | 172 | } |
| 173 | 173 | $out .= $obj->libelle; |
| 174 | 174 | $out .= '</option>'; |
@@ -193,7 +193,7 @@ discard block |
||
| 193 | 193 | * @return void |
| 194 | 194 | * @deprecated |
| 195 | 195 | */ |
| 196 | - function form_barcode_type($page, $selected='', $htmlname='barcodetype_id') |
|
| 196 | + function form_barcode_type($page, $selected = '', $htmlname = 'barcodetype_id') |
|
| 197 | 197 | { |
| 198 | 198 | // phpcs:enable |
| 199 | 199 | print $this->formBarcodeType($page, $selected, $htmlname); |
@@ -207,19 +207,19 @@ discard block |
||
| 207 | 207 | * @param string $htmlname Nom du formulaire select |
| 208 | 208 | * @return string |
| 209 | 209 | */ |
| 210 | - function formBarcodeType($page, $selected='', $htmlname='barcodetype_id') |
|
| 210 | + function formBarcodeType($page, $selected = '', $htmlname = 'barcodetype_id') |
|
| 211 | 211 | { |
| 212 | 212 | global $langs, $conf; |
| 213 | 213 | $out = ''; |
| 214 | 214 | if ($htmlname != "none") { |
| 215 | - $out .= '<form method="post" action="' . $page . '">'; |
|
| 216 | - $out .= '<input type="hidden" name="token" value="' . $_SESSION['newtoken'] . '">'; |
|
| 215 | + $out .= '<form method="post" action="'.$page.'">'; |
|
| 216 | + $out .= '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">'; |
|
| 217 | 217 | $out .= '<input type="hidden" name="action" value="set'.$htmlname.'">'; |
| 218 | 218 | $out .= '<table class="nobordernopadding" cellpadding="0" cellspacing="0">'; |
| 219 | 219 | $out .= '<tr><td>'; |
| 220 | 220 | $out .= $this->selectBarcodeType($selected, $htmlname, 1); |
| 221 | 221 | $out .= '</td>'; |
| 222 | - $out .= '<td align="left"><input type="submit" class="button" value="' . $langs->trans("Modify") . '">'; |
|
| 222 | + $out .= '<td align="left"><input type="submit" class="button" value="'.$langs->trans("Modify").'">'; |
|
| 223 | 223 | $out .= '</td></tr></table></form>'; |
| 224 | 224 | } |
| 225 | 225 | return $out; |