| Conditions | 201 |
| Paths | 0 |
| Total Lines | 735 |
| Code Lines | 396 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | <?php |
||
| 249 | function get_form($addfileaction='addfile',$removefileaction='removefile') |
||
| 250 | { |
||
| 251 | global $conf, $langs, $user, $hookmanager, $form; |
||
| 252 | |||
| 253 | if (! is_object($form)) $form=new Form($this->db); |
||
| 254 | |||
| 255 | $langs->load("other"); |
||
| 256 | $langs->load("mails"); |
||
| 257 | |||
| 258 | |||
| 259 | // Clear temp files. Must be done at beginning, before call of triggers |
||
| 260 | if (GETPOST('mode','alpha') == 'init' || (GETPOST('modelmailselected','alpha') && GETPOST('modelmailselected','alpha') != '-1')) |
||
| 261 | { |
||
| 262 | $this->clear_attached_files(); |
||
| 263 | } |
||
| 264 | |||
| 265 | // Call hook getFormMail |
||
| 266 | $hookmanager->initHooks(array('formmail')); |
||
| 267 | |||
| 268 | $parameters=array( |
||
| 269 | 'addfileaction' => $addfileaction, |
||
| 270 | 'removefileaction'=> $removefileaction, |
||
| 271 | 'trackid'=> $this->trackid |
||
| 272 | ); |
||
| 273 | $reshook=$hookmanager->executeHooks('getFormMail', $parameters, $this); |
||
| 274 | |||
| 275 | if (!empty($reshook)) |
||
| 276 | { |
||
| 277 | return $hookmanager->resPrint; |
||
| 278 | } |
||
| 279 | else |
||
| 280 | { |
||
| 281 | $out=''; |
||
| 282 | |||
| 283 | $disablebademails=1; |
||
| 284 | |||
| 285 | // Define output language |
||
| 286 | $outputlangs = $langs; |
||
| 287 | $newlang = ''; |
||
| 288 | if ($conf->global->MAIN_MULTILANGS && empty($newlang)) $newlang = $this->param['langsmodels']; |
||
| 289 | if (! empty($newlang)) |
||
| 290 | { |
||
| 291 | $outputlangs = new Translate("", $conf); |
||
| 292 | $outputlangs->setDefaultLang($newlang); |
||
| 293 | $outputlangs->load('other'); |
||
| 294 | } |
||
| 295 | |||
| 296 | // Get message template for $this->param["models"] into c_email_templates |
||
| 297 | $arraydefaultmessage=array(); |
||
| 298 | if ($this->param['models'] != 'none') |
||
| 299 | { |
||
| 300 | $model_id=0; |
||
| 301 | if (array_key_exists('models_id',$this->param)) |
||
| 302 | { |
||
| 303 | $model_id=$this->param["models_id"]; |
||
| 304 | } |
||
| 305 | $arraydefaultmessage=$this->getEMailTemplate($this->db, $this->param["models"], $user, $outputlangs, ($model_id ? $model_id : -1)); // we set -1 if model_id empty |
||
| 306 | } |
||
| 307 | //var_dump($this->param["models"]); |
||
| 308 | //var_dump($model_id); |
||
| 309 | //var_dump($arraydefaultmessage); |
||
| 310 | |||
| 311 | |||
| 312 | // Define list of attached files |
||
| 313 | $listofpaths=array(); |
||
| 314 | $listofnames=array(); |
||
| 315 | $listofmimes=array(); |
||
| 316 | $keytoavoidconflict = empty($this->trackid)?'':'-'.$this->trackid; // this->trackid must be defined |
||
| 317 | |||
| 318 | if (GETPOST('mode','alpha') == 'init' || (GETPOST('modelmailselected','alpha') && GETPOST('modelmailselected','alpha') != '-1')) |
||
| 319 | { |
||
| 320 | if (! empty($arraydefaultmessage['joinfiles']) && is_array($this->param['fileinit'])) |
||
| 321 | { |
||
| 322 | foreach($this->param['fileinit'] as $file) |
||
| 323 | { |
||
| 324 | $this->add_attached_files($file, basename($file), dol_mimetype($file)); |
||
| 325 | } |
||
| 326 | } |
||
| 327 | } |
||
| 328 | |||
| 329 | if (! empty($_SESSION["listofpaths".$keytoavoidconflict])) $listofpaths=explode(';',$_SESSION["listofpaths".$keytoavoidconflict]); |
||
| 330 | if (! empty($_SESSION["listofnames".$keytoavoidconflict])) $listofnames=explode(';',$_SESSION["listofnames".$keytoavoidconflict]); |
||
| 331 | if (! empty($_SESSION["listofmimes".$keytoavoidconflict])) $listofmimes=explode(';',$_SESSION["listofmimes".$keytoavoidconflict]); |
||
| 332 | |||
| 333 | |||
| 334 | $out.= "\n".'<!-- Begin form mail type='.$this->param["models"].' --><div id="mailformdiv"></div>'."\n"; |
||
| 335 | if ($this->withform == 1) |
||
| 336 | { |
||
| 337 | $out.= '<form method="POST" name="mailform" id="mailform" enctype="multipart/form-data" action="'.$this->param["returnurl"].'#formmail">'."\n"; |
||
| 338 | |||
| 339 | $out.= '<a id="formmail" name="formmail"></a>'; |
||
| 340 | $out.= '<input style="display:none" type="submit" id="sendmail" name="sendmail">'; |
||
| 341 | $out.= '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'" />'; |
||
| 342 | $out.= '<input type="hidden" name="trackid" value="'.$this->trackid.'" />'; |
||
| 343 | } |
||
| 344 | if (! empty($this->withfrom)) |
||
| 345 | { |
||
| 346 | if (! empty($this->withfromreadonly)) |
||
| 347 | { |
||
| 348 | $out.= '<input type="hidden" id="fromname" name="fromname" value="'.$this->fromname.'" />'; |
||
| 349 | $out.= '<input type="hidden" id="frommail" name="frommail" value="'.$this->frommail.'" />'; |
||
| 350 | } |
||
| 351 | } |
||
| 352 | foreach ($this->param as $key=>$value) |
||
| 353 | { |
||
| 354 | $out.= '<input type="hidden" id="'.$key.'" name="'.$key.'" value="'.$value.'" />'."\n"; |
||
| 355 | } |
||
| 356 | |||
| 357 | $modelmail_array=array(); |
||
| 358 | if ($this->param['models'] != 'none') |
||
| 359 | { |
||
| 360 | $result = $this->fetchAllEMailTemplate($this->param["models"], $user, $outputlangs); |
||
| 361 | if ($result < 0) |
||
| 362 | { |
||
| 363 | setEventMessages($this->error, $this->errors, 'errors'); |
||
| 364 | } |
||
| 365 | foreach($this->lines_model as $line) |
||
| 366 | { |
||
| 367 | $langs->trans("members"); |
||
| 368 | if (preg_match('/\((.*)\)/', $line->label, $reg)) |
||
| 369 | { |
||
| 370 | $modelmail_array[$line->id]=$langs->trans($reg[1]); // langs->trans when label is __(xxx)__ |
||
| 371 | } |
||
| 372 | else |
||
| 373 | { |
||
| 374 | $modelmail_array[$line->id]=$line->label; |
||
| 375 | } |
||
| 376 | if ($line->lang) $modelmail_array[$line->id].=' ('.$line->lang.')'; |
||
| 377 | if ($line->private) $modelmail_array[$line->id].=' - '.$langs->trans("Private"); |
||
| 378 | //if ($line->fk_user != $user->id) $modelmail_array[$line->id].=' - '.$langs->trans("By").' '; |
||
| 379 | } |
||
| 380 | } |
||
| 381 | |||
| 382 | // Zone to select email template |
||
| 383 | if (count($modelmail_array)>0) |
||
| 384 | { |
||
| 385 | // If list of template is filled |
||
| 386 | $out.= '<div class="center" style="padding: 0px 0 12px 0">'."\n"; |
||
| 387 | $out.= '<span class="opacitymedium">'.$langs->trans('SelectMailModel').':</span> '.$this->selectarray('modelmailselected', $modelmail_array, 0, 1, 0, 0, '', 0, 0, 0, '', 'minwidth100'); |
||
| 388 | if ($user->admin) $out.= info_admin($langs->trans("YouCanChangeValuesForThisListFrom", $langs->transnoentitiesnoconv('Setup').' - '.$langs->transnoentitiesnoconv('EMails')),1); |
||
| 389 | $out.= ' '; |
||
| 390 | $out.= '<input class="button" type="submit" value="'.$langs->trans('Apply').'" name="modelselected" id="modelselected">'; |
||
| 391 | $out.= ' '; |
||
| 392 | $out.= '</div>'; |
||
| 393 | } |
||
| 394 | elseif (! empty($this->param['models']) && in_array($this->param['models'], array( |
||
| 395 | 'propal_send','order_send','facture_send', |
||
| 396 | 'shipping_send','fichinter_send','supplier_proposal_send','order_supplier_send', |
||
| 397 | 'invoice_supplier_send','thirdparty','contract','user','all' |
||
| 398 | ))) |
||
| 399 | { |
||
| 400 | // If list of template is empty |
||
| 401 | $out.= '<div class="center" style="padding: 0px 0 12px 0">'."\n"; |
||
| 402 | $out.= $langs->trans('SelectMailModel').': <select name="modelmailselected" disabled="disabled"><option value="none">'.$langs->trans("NoTemplateDefined").'</option></select>'; // Do not put 'disabled' on 'option' tag, it is already on 'select' and it makes chrome crazy. |
||
| 403 | if ($user->admin) $out.= info_admin($langs->trans("YouCanChangeValuesForThisListFrom", $langs->transnoentitiesnoconv('Setup').' - '.$langs->transnoentitiesnoconv('EMails')),1); |
||
| 404 | $out.= ' '; |
||
| 405 | $out.= '<input class="button" type="submit" value="'.$langs->trans('Apply').'" name="modelselected" disabled="disabled" id="modelselected">'; |
||
| 406 | $out.= ' '; |
||
| 407 | $out.= '</div>'; |
||
| 408 | } |
||
| 409 | |||
| 410 | |||
| 411 | |||
| 412 | $out.= '<table class="tableforemailform boxtablenotop" width="100%">'."\n"; |
||
| 413 | |||
| 414 | // Substitution array |
||
| 415 | if (! empty($this->withsubstit)) // Unset or set ->withsubstit=0 to disable this. |
||
| 416 | { |
||
| 417 | $out.= '<tr><td colspan="2" align="right">'; |
||
| 418 | //$out.='<div class="floatright">'; |
||
| 419 | $help=""; |
||
| 420 | foreach($this->substit as $key => $val) |
||
| 421 | { |
||
| 422 | $help.=$key.' -> '.$langs->trans(dol_string_nohtmltag($val)).'<br>'; |
||
| 423 | } |
||
| 424 | if (is_numeric($this->withsubstit)) $out.= $form->textwithpicto($langs->trans("EMailTestSubstitutionReplacedByGenericValues"), $help, 1, 'help', '', 0, 2, 'substittooltip'); // Old usage |
||
| 425 | else $out.= $form->textwithpicto($langs->trans('AvailableVariables'), $help, 1, 'help', '', 0, 2, 'substittooltip'); // New usage |
||
| 426 | $out.= "</td></tr>\n"; |
||
| 427 | //$out.='</div>'; |
||
| 428 | } |
||
| 429 | |||
| 430 | /*var_dump(! empty($this->withfromreadonly)); |
||
| 431 | var_dump($this->withfrom); |
||
| 432 | var_dump($this->fromtype); |
||
| 433 | var_dump($this->fromname);*/ |
||
| 434 | |||
| 435 | // From |
||
| 436 | if (! empty($this->withfrom)) |
||
| 437 | { |
||
| 438 | if (! empty($this->withfromreadonly)) |
||
| 439 | { |
||
| 440 | $out.= '<tr><td class="fieldrequired minwidth200">'.$langs->trans("MailFrom").'</td><td>'; |
||
| 441 | |||
| 442 | // $this->fromtype is the default value to use to select sender |
||
| 443 | if (! ($this->fromtype === 'user' && $this->fromid > 0) |
||
| 444 | && ! ($this->fromtype === 'company') |
||
| 445 | && ! ($this->fromtype === 'robot') |
||
| 446 | && ! preg_match('/user_aliases/', $this->fromtype) |
||
| 447 | && ! preg_match('/global_aliases/', $this->fromtype) |
||
| 448 | && ! preg_match('/senderprofile/', $this->fromtype) |
||
| 449 | ) |
||
| 450 | { |
||
| 451 | // Use this->fromname and this->frommail or error if not defined |
||
| 452 | $out.= $this->fromname; |
||
| 453 | if ($this->frommail) |
||
| 454 | { |
||
| 455 | $out.= ' <'.$this->frommail.'>'; |
||
| 456 | } |
||
| 457 | else |
||
| 458 | { |
||
| 459 | if ($this->fromtype) |
||
| 460 | { |
||
| 461 | $langs->load('errors'); |
||
| 462 | $out.= '<span class="warning"> <'.$langs->trans('ErrorNoMailDefinedForThisUser').'> </span>'; |
||
| 463 | } |
||
| 464 | } |
||
| 465 | } else { |
||
| 466 | $liste = array(); |
||
| 467 | |||
| 468 | // Add user email |
||
| 469 | if (empty($user->email)) |
||
| 470 | { |
||
| 471 | $langs->load('errors'); |
||
| 472 | $liste['user'] = $user->getFullName($langs) . ' <'.$langs->trans('ErrorNoMailDefinedForThisUser').'>'; |
||
| 473 | } |
||
| 474 | else |
||
| 475 | { |
||
| 476 | $liste['user'] = $user->getFullName($langs) .' <'.$user->email.'>'; |
||
| 477 | } |
||
| 478 | |||
| 479 | // Add also company main email |
||
| 480 | $liste['company'] = $conf->global->MAIN_INFO_SOCIETE_NOM .' <'.$conf->global->MAIN_INFO_SOCIETE_MAIL.'>'; |
||
| 481 | |||
| 482 | // Add also email aliases if there is some |
||
| 483 | $listaliases=array('user_aliases'=>$user->email_aliases, 'global_aliases'=>$conf->global->MAIN_INFO_SOCIETE_MAIL_ALIASES); |
||
| 484 | |||
| 485 | // Also add robot email |
||
| 486 | if (! empty($this->fromalsorobot)) |
||
| 487 | { |
||
| 488 | if (! empty($conf->global->MAIN_MAIL_EMAIL_FROM) && $conf->global->MAIN_MAIL_EMAIL_FROM != $conf->global->MAIN_INFO_SOCIETE_MAIL) |
||
| 489 | { |
||
| 490 | $liste['robot'] = $conf->global->MAIN_MAIL_EMAIL_FROM; |
||
| 491 | if ($this->frommail) |
||
| 492 | { |
||
| 493 | $liste['robot'] .= ' <'.$conf->global->MAIN_MAIL_EMAIL_FROM.'>'; |
||
| 494 | } |
||
| 495 | } |
||
| 496 | } |
||
| 497 | |||
| 498 | // Add also email aliases from the c_email_senderprofile table |
||
| 499 | $sql='SELECT rowid, label, email FROM '.MAIN_DB_PREFIX.'c_email_senderprofile WHERE active = 1 ORDER BY position'; |
||
| 500 | $resql = $this->db->query($sql); |
||
| 501 | if ($resql) |
||
| 502 | { |
||
| 503 | $num = $this->db->num_rows($resql); |
||
| 504 | $i=0; |
||
| 505 | while($i < $num) |
||
| 506 | { |
||
| 507 | $obj = $this->db->fetch_object($resql); |
||
| 508 | if ($obj) |
||
| 509 | { |
||
| 510 | $listaliases['senderprofile_'.$obj->rowid] = $obj->label.' <'.$obj->email.'>'; |
||
| 511 | } |
||
| 512 | $i++; |
||
| 513 | } |
||
| 514 | } |
||
| 515 | else dol_print_error($this->db); |
||
| 516 | |||
| 517 | foreach($listaliases as $typealias => $listalias) |
||
| 518 | { |
||
| 519 | $posalias=0; |
||
| 520 | $listaliasarray=explode(',', $listalias); |
||
| 521 | foreach ($listaliasarray as $listaliasval) |
||
| 522 | { |
||
| 523 | $posalias++; |
||
| 524 | $listaliasval=trim($listaliasval); |
||
| 525 | if ($listaliasval) |
||
| 526 | { |
||
| 527 | $listaliasval=preg_replace('/</', '<', $listaliasval); |
||
| 528 | $listaliasval=preg_replace('/>/', '>', $listaliasval); |
||
| 529 | if (! preg_match('/</', $listaliasval)) $listaliasval='<'.$listaliasval.'>'; |
||
| 530 | $liste[$typealias.'_'.$posalias]=$listaliasval; |
||
| 531 | } |
||
| 532 | } |
||
| 533 | } |
||
| 534 | |||
| 535 | // Set the default "From" |
||
| 536 | $defaultfrom=''; |
||
| 537 | $reshook=$hookmanager->executeHooks('getDefaultFromEmail', $parameters, $this); |
||
| 538 | if (empty($reshook)) |
||
| 539 | { |
||
| 540 | $defaultfrom = $this->fromtype; |
||
| 541 | } |
||
| 542 | if (! empty($hookmanager->resArray['defaultfrom'])) $defaultfrom=$hookmanager->resArray['defaultfrom']; |
||
| 543 | |||
| 544 | // Using combo here make the '<email>' no more visible on list. |
||
| 545 | //$out.= ' '.$form->selectarray('fromtype', $liste, $this->fromtype, 0, 0, 0, '', 0, 0, 0, '', 'fromforsendingprofile maxwidth200onsmartphone', 1, '', $disablebademails); |
||
| 546 | $out.= ' '.$form->selectarray('fromtype', $liste, $defaultfrom, 0, 0, 0, '', 0, 0, 0, '', 'fromforsendingprofile maxwidth200onsmartphone', 0, '', $disablebademails); |
||
| 547 | } |
||
| 548 | |||
| 549 | $out.= "</td></tr>\n"; |
||
| 550 | } |
||
| 551 | else |
||
| 552 | { |
||
| 553 | $out.= '<tr><td class="fieldrequired width200">'.$langs->trans("MailFrom")."</td><td>"; |
||
| 554 | $out.= $langs->trans("Name").':<input type="text" id="fromname" name="fromname" class="maxwidth200onsmartphone" value="'.$this->fromname.'" />'; |
||
| 555 | $out.= ' '; |
||
| 556 | $out.= $langs->trans("EMail").':<<input type="text" id="frommail" name="frommail" class="maxwidth200onsmartphone" value="'.$this->frommail.'" />>'; |
||
| 557 | $out.= "</td></tr>\n"; |
||
| 558 | } |
||
| 559 | } |
||
| 560 | |||
| 561 | // To |
||
| 562 | if (! empty($this->withto) || is_array($this->withto)) |
||
| 563 | { |
||
| 564 | $out.= '<tr><td class="fieldrequired">'; |
||
| 565 | if ($this->withtofree) $out.= $form->textwithpicto($langs->trans("MailTo"),$langs->trans("YouCanUseCommaSeparatorForSeveralRecipients")); |
||
| 566 | else $out.= $langs->trans("MailTo"); |
||
| 567 | $out.= '</td><td>'; |
||
| 568 | if ($this->withtoreadonly) |
||
| 569 | { |
||
| 570 | if (! empty($this->toname) && ! empty($this->tomail)) |
||
| 571 | { |
||
| 572 | $out.= '<input type="hidden" id="toname" name="toname" value="'.$this->toname.'" />'; |
||
| 573 | $out.= '<input type="hidden" id="tomail" name="tomail" value="'.$this->tomail.'" />'; |
||
| 574 | if ($this->totype == 'thirdparty') |
||
| 575 | { |
||
| 576 | $soc=new Societe($this->db); |
||
| 577 | $soc->fetch($this->toid); |
||
| 578 | $out.= $soc->getNomUrl(1); |
||
| 579 | } |
||
| 580 | else if ($this->totype == 'contact') |
||
| 581 | { |
||
| 582 | $contact=new Contact($this->db); |
||
| 583 | $contact->fetch($this->toid); |
||
| 584 | $out.= $contact->getNomUrl(1); |
||
| 585 | } |
||
| 586 | else |
||
| 587 | { |
||
| 588 | $out.= $this->toname; |
||
| 589 | } |
||
| 590 | $out.= ' <'.$this->tomail.'>'; |
||
| 591 | if ($this->withtofree) |
||
| 592 | { |
||
| 593 | $out.= '<br>'.$langs->trans("and").' <input class="minwidth200" id="sendto" name="sendto" value="'.(! is_array($this->withto) && ! is_numeric($this->withto)? (isset($_REQUEST["sendto"])?$_REQUEST["sendto"]:$this->withto) :"").'" />'; |
||
| 594 | } |
||
| 595 | } |
||
| 596 | else |
||
| 597 | { |
||
| 598 | // Note withto may be a text like 'AllRecipientSelected' |
||
| 599 | $out.= (! is_array($this->withto) && ! is_numeric($this->withto))?$this->withto:""; |
||
| 600 | } |
||
| 601 | } |
||
| 602 | else |
||
| 603 | { |
||
| 604 | if (! empty($this->withtofree)) |
||
| 605 | { |
||
| 606 | $out.= '<input class="minwidth200" id="sendto" name="sendto" value="'.(! is_array($this->withto) && ! is_numeric($this->withto)? (isset($_REQUEST["sendto"])?$_REQUEST["sendto"]:$this->withto) :"").'" />'; |
||
| 607 | } |
||
| 608 | if (! empty($this->withto) && is_array($this->withto)) |
||
| 609 | { |
||
| 610 | if (! empty($this->withtofree)) $out.= " ".$langs->trans("and")."/".$langs->trans("or")." "; |
||
| 611 | // multiselect array convert html entities into options tags, even if we dont want this, so we encode them a second time |
||
| 612 | $tmparray = $this->withto; |
||
| 613 | foreach($tmparray as $key => $val) |
||
| 614 | { |
||
| 615 | $tmparray[$key]=dol_htmlentities($tmparray[$key], null, 'UTF-8', true); |
||
| 616 | } |
||
| 617 | $withtoselected=GETPOST("receiver",'none'); // Array of selected value |
||
| 618 | if (empty($withtoselected) && count($tmparray) == 1 && GETPOST('action','aZ09') == 'presend') |
||
| 619 | { |
||
| 620 | $withtoselected = array_keys($tmparray); |
||
| 621 | } |
||
| 622 | $out.= $form->multiselectarray("receiver", $tmparray, $withtoselected, null, null, 'inline-block minwidth500', null, ""); |
||
| 623 | } |
||
| 624 | } |
||
| 625 | $out.= "</td></tr>\n"; |
||
| 626 | } |
||
| 627 | |||
| 628 | // withoptiononeemailperrecipient |
||
| 629 | if (! empty($this->withoptiononeemailperrecipient)) |
||
| 630 | { |
||
| 631 | $out.= '<tr><td class="minwidth200">'; |
||
| 632 | $out.= $langs->trans("GroupEmails"); |
||
| 633 | $out.= '</td><td>'; |
||
| 634 | $out.=' <input type="checkbox" name="oneemailperrecipient"'.($this->withoptiononeemailperrecipient > 0?' checked="checked"':'').'> '; |
||
| 635 | $out.= $langs->trans("OneEmailPerRecipient"); |
||
| 636 | $out.='<span class="hideonsmartphone">'; |
||
| 637 | $out.=' - '; |
||
| 638 | $out.= $langs->trans("WarningIfYouCheckOneRecipientPerEmail"); |
||
| 639 | $out.='</span>'; |
||
| 640 | $out.= '</td></tr>'; |
||
| 641 | } |
||
| 642 | |||
| 643 | // CC |
||
| 644 | if (! empty($this->withtocc) || is_array($this->withtocc)) |
||
| 645 | { |
||
| 646 | $out.= '<tr><td>'; |
||
| 647 | $out.= $form->textwithpicto($langs->trans("MailCC"),$langs->trans("YouCanUseCommaSeparatorForSeveralRecipients")); |
||
| 648 | $out.= '</td><td>'; |
||
| 649 | if ($this->withtoccreadonly) |
||
| 650 | { |
||
| 651 | $out.= (! is_array($this->withtocc) && ! is_numeric($this->withtocc))?$this->withtocc:""; |
||
| 652 | } |
||
| 653 | else |
||
| 654 | { |
||
| 655 | $out.= '<input class="minwidth200" id="sendtocc" name="sendtocc" value="'.((! is_array($this->withtocc) && ! is_numeric($this->withtocc))? (isset($_POST["sendtocc"])?$_POST["sendtocc"]:$this->withtocc) : (isset($_POST["sendtocc"])?$_POST["sendtocc"]:"") ).'" />'; |
||
| 656 | if (! empty($this->withtocc) && is_array($this->withtocc)) |
||
| 657 | { |
||
| 658 | $out.= " ".$langs->trans("and")."/".$langs->trans("or")." "; |
||
| 659 | // multiselect array convert html entities into options tags, even if we dont want this, so we encode them a second time |
||
| 660 | $tmparray = $this->withtocc; |
||
| 661 | foreach($tmparray as $key => $val) |
||
| 662 | { |
||
| 663 | $tmparray[$key]=dol_htmlentities($tmparray[$key], null, 'UTF-8', true); |
||
| 664 | } |
||
| 665 | $withtoccselected=GETPOST("receivercc"); // Array of selected value |
||
| 666 | $out.= $form->multiselectarray("receivercc", $tmparray, $withtoccselected, null, null, 'inline-block minwidth500',null, ""); |
||
| 667 | } |
||
| 668 | } |
||
| 669 | $out.= "</td></tr>\n"; |
||
| 670 | } |
||
| 671 | |||
| 672 | // CCC |
||
| 673 | if (! empty($this->withtoccc) || is_array($this->withtoccc)) |
||
| 674 | { |
||
| 675 | $out.= '<tr><td>'; |
||
| 676 | $out.= $form->textwithpicto($langs->trans("MailCCC"),$langs->trans("YouCanUseCommaSeparatorForSeveralRecipients")); |
||
| 677 | $out.= '</td><td>'; |
||
| 678 | if (! empty($this->withtocccreadonly)) |
||
| 679 | { |
||
| 680 | $out.= (! is_array($this->withtoccc) && ! is_numeric($this->withtoccc))?$this->withtoccc:""; |
||
| 681 | } |
||
| 682 | else |
||
| 683 | { |
||
| 684 | $out.= '<input class="minwidth200" id="sendtoccc" name="sendtoccc" value="'.((! is_array($this->withtoccc) && ! is_numeric($this->withtoccc))? (isset($_POST["sendtoccc"])?$_POST["sendtoccc"]:$this->withtoccc) : (isset($_POST["sendtoccc"])?$_POST["sendtoccc"]:"") ).'" />'; |
||
| 685 | if (! empty($this->withtoccc) && is_array($this->withtoccc)) |
||
| 686 | { |
||
| 687 | $out.= " ".$langs->trans("and")."/".$langs->trans("or")." "; |
||
| 688 | // multiselect array convert html entities into options tags, even if we dont want this, so we encode them a second time |
||
| 689 | $tmparray = $this->withtoccc; |
||
| 690 | foreach($tmparray as $key => $val) |
||
| 691 | { |
||
| 692 | $tmparray[$key]=dol_htmlentities($tmparray[$key], null, 'UTF-8', true); |
||
| 693 | } |
||
| 694 | $withtocccselected=GETPOST("receiverccc"); // Array of selected value |
||
| 695 | $out.= $form->multiselectarray("receiverccc", $tmparray, $withtocccselected, null, null, null,null, "90%"); |
||
| 696 | } |
||
| 697 | } |
||
| 698 | |||
| 699 | $showinfobcc=''; |
||
| 700 | if (! empty($conf->global->MAIN_MAIL_AUTOCOPY_PROPOSAL_TO) && ! empty($this->param['models']) && $this->param['models'] == 'propal_send') $showinfobcc=$conf->global->MAIN_MAIL_AUTOCOPY_PROPOSAL_TO; |
||
| 701 | if (! empty($conf->global->MAIN_MAIL_AUTOCOPY_SUPPLIER_PROPOSAL_TO) && ! empty($this->param['models']) && $this->param['models'] == 'supplier_proposal_send') $showinfobcc=$conf->global->MAIN_MAIL_AUTOCOPY_SUPPLIER_PROPOSAL_TO; |
||
| 702 | if (! empty($conf->global->MAIN_MAIL_AUTOCOPY_ORDER_TO) && ! empty($this->param['models']) && $this->param['models'] == 'order_send') $showinfobcc=$conf->global->MAIN_MAIL_AUTOCOPY_ORDER_TO; |
||
| 703 | if (! empty($conf->global->MAIN_MAIL_AUTOCOPY_INVOICE_TO) && ! empty($this->param['models']) && $this->param['models'] == 'facture_send') $showinfobcc=$conf->global->MAIN_MAIL_AUTOCOPY_INVOICE_TO; |
||
| 704 | if ($showinfobcc) $out.=' + '.$showinfobcc; |
||
| 705 | $out.= "</td></tr>\n"; |
||
| 706 | } |
||
| 707 | |||
| 708 | // Replyto |
||
| 709 | if (! empty($this->withreplyto)) |
||
| 710 | { |
||
| 711 | if ($this->withreplytoreadonly) |
||
| 712 | { |
||
| 713 | $out.= '<input type="hidden" id="replyname" name="replyname" value="'.$this->replytoname.'" />'; |
||
| 714 | $out.= '<input type="hidden" id="replymail" name="replymail" value="'.$this->replytomail.'" />'; |
||
| 715 | $out.= "<tr><td>".$langs->trans("MailReply")."</td><td>".$this->replytoname.($this->replytomail?(" <".$this->replytomail.">"):""); |
||
| 716 | $out.= "</td></tr>\n"; |
||
| 717 | } |
||
| 718 | } |
||
| 719 | |||
| 720 | // Errorsto |
||
| 721 | if (! empty($this->witherrorsto)) |
||
| 722 | { |
||
| 723 | //if (! $this->errorstomail) $this->errorstomail=$this->frommail; |
||
| 724 | $errorstomail = (! empty($conf->global->MAIN_MAIL_ERRORS_TO) ? $conf->global->MAIN_MAIL_ERRORS_TO : $this->errorstomail); |
||
| 725 | if ($this->witherrorstoreadonly) |
||
| 726 | { |
||
| 727 | $out.= '<input type="hidden" id="errorstomail" name="errorstomail" value="'.$errorstomail.'" />'; |
||
| 728 | $out.= '<tr><td>'.$langs->trans("MailErrorsTo").'</td><td>'; |
||
| 729 | $out.= $errorstomail; |
||
| 730 | $out.= "</td></tr>\n"; |
||
| 731 | } |
||
| 732 | else |
||
| 733 | { |
||
| 734 | $out.= '<tr><td>'.$langs->trans("MailErrorsTo").'</td><td>'; |
||
| 735 | $out.= '<input size="30" id="errorstomail" name="errorstomail" value="'.$errorstomail.'" />'; |
||
| 736 | $out.= "</td></tr>\n"; |
||
| 737 | } |
||
| 738 | } |
||
| 739 | |||
| 740 | // Ask delivery receipt |
||
| 741 | if (! empty($this->withdeliveryreceipt)) |
||
| 742 | { |
||
| 743 | $out.= '<tr><td>'.$langs->trans("DeliveryReceipt").'</td><td>'; |
||
| 744 | |||
| 745 | if (! empty($this->withdeliveryreceiptreadonly)) |
||
| 746 | { |
||
| 747 | $out.= yn($this->withdeliveryreceipt); |
||
| 748 | } |
||
| 749 | else |
||
| 750 | { |
||
| 751 | $defaultvaluefordeliveryreceipt=0; |
||
| 752 | if (! empty($conf->global->MAIL_FORCE_DELIVERY_RECEIPT_PROPAL) && ! empty($this->param['models']) && $this->param['models'] == 'propal_send') $defaultvaluefordeliveryreceipt=1; |
||
| 753 | if (! empty($conf->global->MAIL_FORCE_DELIVERY_RECEIPT_SUPPLIER_PROPOSAL) && ! empty($this->param['models']) && $this->param['models'] == 'supplier_proposal_send') $defaultvaluefordeliveryreceipt=1; |
||
| 754 | if (! empty($conf->global->MAIL_FORCE_DELIVERY_RECEIPT_ORDER) && ! empty($this->param['models']) && $this->param['models'] == 'order_send') $defaultvaluefordeliveryreceipt=1; |
||
| 755 | if (! empty($conf->global->MAIL_FORCE_DELIVERY_RECEIPT_INVOICE) && ! empty($this->param['models']) && $this->param['models'] == 'facture_send') $defaultvaluefordeliveryreceipt=1; |
||
| 756 | $out.= $form->selectyesno('deliveryreceipt', (isset($_POST["deliveryreceipt"])?$_POST["deliveryreceipt"]:$defaultvaluefordeliveryreceipt), 1); |
||
| 757 | } |
||
| 758 | |||
| 759 | $out.= "</td></tr>\n"; |
||
| 760 | } |
||
| 761 | |||
| 762 | // Topic |
||
| 763 | if (! empty($this->withtopic)) |
||
| 764 | { |
||
| 765 | $defaulttopic=GETPOST('subject','none'); |
||
| 766 | if (! GETPOST('modelselected','alpha') || GETPOST('modelmailselected') != '-1') |
||
| 767 | { |
||
| 768 | if (is_array($arraydefaultmessage) && count($arraydefaultmessage) > 0 && $arraydefaultmessage['topic']) $defaulttopic=$arraydefaultmessage['topic']; |
||
| 769 | elseif (! is_numeric($this->withtopic)) $defaulttopic=$this->withtopic; |
||
| 770 | } |
||
| 771 | |||
| 772 | $defaulttopic=make_substitutions($defaulttopic,$this->substit); |
||
| 773 | |||
| 774 | $out.= '<tr>'; |
||
| 775 | $out.= '<td class="fieldrequired">'.$langs->trans("MailTopic").'</td>'; |
||
| 776 | $out.= '<td>'; |
||
| 777 | if ($this->withtopicreadonly) |
||
| 778 | { |
||
| 779 | $out.= $defaulttopic; |
||
| 780 | $out.= '<input type="hidden" class="quatrevingtpercent" id="subject" name="subject" value="'.$defaulttopic.'" />'; |
||
| 781 | } |
||
| 782 | else |
||
| 783 | { |
||
| 784 | $out.= '<input type="text" class="quatrevingtpercent" id="subject" name="subject" value="'. ((isset($_POST["subject"]) && ! $_POST['modelselected'])?$_POST["subject"]:($defaulttopic?$defaulttopic:'')) .'" />'; |
||
| 785 | } |
||
| 786 | $out.= "</td></tr>\n"; |
||
| 787 | } |
||
| 788 | |||
| 789 | // Attached files |
||
| 790 | if (! empty($this->withfile)) |
||
| 791 | { |
||
| 792 | $out.= '<tr>'; |
||
| 793 | $out.= '<td>'.$langs->trans("MailFile").'</td>'; |
||
| 794 | |||
| 795 | $out.= '<td>'; |
||
| 796 | if (! empty($this->withmaindocfile)) |
||
| 797 | { |
||
| 798 | if ($this->withmaindocfile == 1) |
||
| 799 | { |
||
| 800 | $out.='<input type="checkbox" name="addmaindocfile" value="1" />'; |
||
| 801 | } |
||
| 802 | if ($this->withmaindocfile == -1) |
||
| 803 | { |
||
| 804 | $out.='<input type="checkbox" name="addmaindocfile" checked="checked" />'; |
||
| 805 | } |
||
| 806 | $out.=' '.$langs->trans("JoinMainDoc").'.<br>'; |
||
| 807 | } |
||
| 808 | |||
| 809 | if (is_numeric($this->withfile)) |
||
| 810 | { |
||
| 811 | // TODO Trick to have param removedfile containing nb of file to delete. But this does not works without javascript |
||
| 812 | $out.= '<input type="hidden" class="removedfilehidden" name="removedfile" value="">'."\n"; |
||
| 813 | $out.= '<script type="text/javascript" language="javascript">'; |
||
| 814 | $out.= 'jQuery(document).ready(function () {'; |
||
| 815 | $out.= ' jQuery(".removedfile").click(function() {'; |
||
| 816 | $out.= ' jQuery(".removedfilehidden").val(jQuery(this).val());'; |
||
| 817 | $out.= ' });'; |
||
| 818 | $out.= '})'; |
||
| 819 | $out.= '</script>'."\n"; |
||
| 820 | if (count($listofpaths)) |
||
| 821 | { |
||
| 822 | foreach($listofpaths as $key => $val) |
||
| 823 | { |
||
| 824 | $out.= '<div id="attachfile_'.$key.'">'; |
||
| 825 | $out.= img_mime($listofnames[$key]).' '.$listofnames[$key]; |
||
| 826 | if (! $this->withfilereadonly) |
||
| 827 | { |
||
| 828 | $out.= ' <input type="image" style="border: 0px;" src="'.DOL_URL_ROOT.'/theme/'.$conf->theme.'/img/delete.png" value="'.($key+1).'" class="removedfile" id="removedfile_'.$key.'" name="removedfile_'.$key.'" />'; |
||
| 829 | //$out.= ' <a href="'.$_SERVER["PHP_SELF"].'?removedfile='.($key+1).' id="removedfile_'.$key.'">'.img_delete($langs->trans("Delete").'</a>'; |
||
| 830 | } |
||
| 831 | $out.= '<br></div>'; |
||
| 832 | } |
||
| 833 | } |
||
| 834 | else if (empty($this->withmaindocfile)) // Do not show message if we asked to show the checkbox |
||
| 835 | { |
||
| 836 | $out.= $langs->trans("NoAttachedFiles").'<br>'; |
||
| 837 | } |
||
| 838 | if ($this->withfile == 2) // Can add other files |
||
| 839 | { |
||
| 840 | if (!empty($conf->global->FROM_MAIL_USE_INPUT_FILE_MULTIPLE)) $out.= '<input type="file" class="flat" id="addedfile" name="addedfile[]" value="'.$langs->trans("Upload").'" multiple />'; |
||
| 841 | else $out.= '<input type="file" class="flat" id="addedfile" name="addedfile" value="'.$langs->trans("Upload").'" />'; |
||
| 842 | $out.= ' '; |
||
| 843 | $out.= '<input class="button" type="submit" id="'.$addfileaction.'" name="'.$addfileaction.'" value="'.$langs->trans("MailingAddFile").'" />'; |
||
| 844 | } |
||
| 845 | } |
||
| 846 | else |
||
| 847 | { |
||
| 848 | $out.=$this->withfile; |
||
| 849 | } |
||
| 850 | |||
| 851 | $out.= "</td></tr>\n"; |
||
| 852 | } |
||
| 853 | |||
| 854 | // Message |
||
| 855 | if (! empty($this->withbody)) |
||
| 856 | { |
||
| 857 | $defaultmessage=GETPOST('message','none'); |
||
| 858 | if (! GETPOST('modelselected','alpha') || GETPOST('modelmailselected') != '-1') |
||
| 859 | { |
||
| 860 | if (count($arraydefaultmessage) > 0 && $arraydefaultmessage['content']) $defaultmessage=$arraydefaultmessage['content']; |
||
| 861 | elseif (! is_numeric($this->withbody)) $defaultmessage=$this->withbody; |
||
| 862 | } |
||
| 863 | |||
| 864 | // Complete substitution array |
||
| 865 | $paymenturl=''; |
||
| 866 | if (empty($this->substit['__REF__'])) |
||
| 867 | { |
||
| 868 | $paymenturl=''; |
||
| 869 | } |
||
| 870 | else |
||
| 871 | { |
||
| 872 | // Set the online payment url link into __ONLINE_PAYMENT_URL__ key |
||
| 873 | require_once DOL_DOCUMENT_ROOT.'/core/lib/payments.lib.php'; |
||
| 874 | $langs->load('paypal'); |
||
| 875 | $typeforonlinepayment='free'; |
||
| 876 | if ($this->param["models"]=='order_send') $typeforonlinepayment='order'; // TODO use detection on something else than template |
||
| 877 | if ($this->param["models"]=='facture_send') $typeforonlinepayment='invoice'; // TODO use detection on something else than template |
||
| 878 | if ($this->param["models"]=='member_send') $typeforonlinepayment='member'; // TODO use detection on something else than template |
||
| 879 | $url=getOnlinePaymentUrl(0, $typeforonlinepayment, $this->substit['__REF__']); |
||
| 880 | $paymenturl=$url; |
||
| 881 | } |
||
| 882 | |||
| 883 | $this->substit['__ONLINE_PAYMENT_URL__']=$paymenturl; |
||
| 884 | |||
| 885 | //Add lines substitution key from each line |
||
| 886 | $lines = ''; |
||
| 887 | $defaultlines = $arraydefaultmessage['content_lines']; |
||
| 888 | if (isset($defaultlines)) |
||
| 889 | { |
||
| 890 | foreach ($this->substit_lines as $substit_line) |
||
| 891 | { |
||
| 892 | $lines .= make_substitutions($defaultlines,$substit_line)."\n"; |
||
| 893 | } |
||
| 894 | } |
||
| 895 | $this->substit['__LINES__']=$lines; |
||
| 896 | |||
| 897 | $defaultmessage=str_replace('\n',"\n",$defaultmessage); |
||
| 898 | |||
| 899 | // Deal with format differences between message and signature (text / HTML) |
||
| 900 | if(dol_textishtml($defaultmessage) && !dol_textishtml($this->substit['__USER_SIGNATURE__'])) { |
||
| 901 | $this->substit['__USER_SIGNATURE__'] = dol_nl2br($this->substit['__USER_SIGNATURE__']); |
||
| 902 | } else if(!dol_textishtml($defaultmessage) && dol_textishtml($this->substit['__USER_SIGNATURE__'])) { |
||
| 903 | $defaultmessage = dol_nl2br($defaultmessage); |
||
| 904 | } |
||
| 905 | |||
| 906 | if (isset($_POST["message"]) && ! $_POST['modelselected']) $defaultmessage=$_POST["message"]; |
||
| 907 | else |
||
| 908 | { |
||
| 909 | $defaultmessage=make_substitutions($defaultmessage,$this->substit); |
||
| 910 | // Clean first \n and br (to avoid empty line when CONTACTCIVNAME is empty) |
||
| 911 | $defaultmessage=preg_replace("/^(<br>)+/","",$defaultmessage); |
||
| 912 | $defaultmessage=preg_replace("/^\n+/","",$defaultmessage); |
||
| 913 | } |
||
| 914 | |||
| 915 | $out.= '<tr>'; |
||
| 916 | $out.= '<td valign="top">'.$langs->trans("MailText").'</td>'; |
||
| 917 | $out.= '<td>'; |
||
| 918 | if ($this->withbodyreadonly) |
||
| 919 | { |
||
| 920 | $out.= nl2br($defaultmessage); |
||
| 921 | $out.= '<input type="hidden" id="message" name="message" value="'.$defaultmessage.'" />'; |
||
| 922 | } |
||
| 923 | else |
||
| 924 | { |
||
| 925 | if (! isset($this->ckeditortoolbar)) $this->ckeditortoolbar = 'dolibarr_notes'; |
||
| 926 | |||
| 927 | // Editor wysiwyg |
||
| 928 | require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php'; |
||
| 929 | if ($this->withfckeditor == -1) |
||
| 930 | { |
||
| 931 | if (! empty($conf->global->FCKEDITOR_ENABLE_MAIL)) $this->withfckeditor=1; |
||
| 932 | else $this->withfckeditor=0; |
||
| 933 | } |
||
| 934 | |||
| 935 | $doleditor=new DolEditor('message',$defaultmessage,'',280,$this->ckeditortoolbar,'In',true,true,$this->withfckeditor,8,'95%'); |
||
| 936 | $out.= $doleditor->Create(1); |
||
| 937 | } |
||
| 938 | $out.= "</td></tr>\n"; |
||
| 939 | } |
||
| 940 | |||
| 941 | $out.= '</table>'."\n"; |
||
| 942 | |||
| 943 | if ($this->withform == 1 || $this->withform == -1) |
||
| 944 | { |
||
| 945 | $out.= '<br><div class="center">'; |
||
| 946 | $out.= '<input class="button" type="submit" id="sendmail" name="sendmail" value="'.$langs->trans("SendMail").'"'; |
||
| 947 | // Add a javascript test to avoid to forget to submit file before sending email |
||
| 948 | if ($this->withfile == 2 && $conf->use_javascript_ajax) |
||
| 949 | { |
||
| 950 | $out.= ' onClick="if (document.mailform.addedfile.value != \'\') { alert(\''.dol_escape_js($langs->trans("FileWasNotUploaded")).'\'); return false; } else { return true; }"'; |
||
| 951 | } |
||
| 952 | $out.= ' />'; |
||
| 953 | if ($this->withcancel) |
||
| 954 | { |
||
| 955 | $out.= ' '; |
||
| 956 | $out.= '<input class="button" type="submit" id="cancel" name="cancel" value="'.$langs->trans("Cancel").'" />'; |
||
| 957 | } |
||
| 958 | $out.= '</div>'."\n"; |
||
| 959 | } |
||
| 960 | |||
| 961 | if ($this->withform == 1) $out.= '</form>'."\n"; |
||
| 962 | |||
| 963 | // Disable enter key if option MAIN_MAILFORM_DISABLE_ENTERKEY is set |
||
| 964 | if (! empty($conf->global->MAIN_MAILFORM_DISABLE_ENTERKEY)) |
||
| 965 | { |
||
| 966 | $out.= '<script type="text/javascript" language="javascript">'; |
||
| 967 | $out.= 'jQuery(document).ready(function () {'; |
||
| 968 | $out.= ' $(document).on("keypress", \'#mailform\', function (e) { /* Note this is called at every key pressed ! */ |
||
| 969 | var code = e.keyCode || e.which; |
||
| 970 | if (code == 13) { |
||
| 971 | e.preventDefault(); |
||
| 972 | return false; |
||
| 973 | } |
||
| 974 | });'; |
||
| 975 | $out.=' })'; |
||
| 976 | $out.= '</script>'; |
||
| 977 | } |
||
| 978 | |||
| 979 | $out.= "<!-- End form mail -->\n"; |
||
| 980 | |||
| 981 | return $out; |
||
| 982 | } |
||
| 983 | } |
||
| 984 | |||
| 1314 |