| Conditions | 159 |
| Paths | 4 |
| Total Lines | 645 |
| Code Lines | 395 |
| 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 |
||
| 356 | public function get_form($addfileaction = 'addfile', $removefileaction = 'removefile') |
||
| 357 | { |
||
| 358 | // phpcs:enable |
||
| 359 | global $conf, $langs, $user, $hookmanager, $form; |
||
| 360 | |||
| 361 | // Required to show preview wof mail attachments |
||
| 362 | require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php'; |
||
| 363 | $formfile = new Formfile($this->db); |
||
| 364 | |||
| 365 | if (!is_object($form)) { |
||
| 366 | $form = new Form($this->db); |
||
| 367 | } |
||
| 368 | |||
| 369 | // Load translation files required by the page |
||
| 370 | $langs->loadLangs(array('other', 'mails', 'members')); |
||
| 371 | |||
| 372 | // Clear temp files. Must be done before call of triggers, at beginning (mode = init), or when we select a new template |
||
| 373 | if (GETPOST('mode', 'alpha') == 'init' || (GETPOST('modelselected') && GETPOST('modelmailselected', 'alpha') && GETPOST('modelmailselected', 'alpha') != '-1')) { |
||
| 374 | $this->clear_attached_files(); |
||
| 375 | } |
||
| 376 | |||
| 377 | // Call hook getFormMail |
||
| 378 | $hookmanager->initHooks(array('formmail')); |
||
| 379 | |||
| 380 | $parameters = array( |
||
| 381 | 'addfileaction' => $addfileaction, |
||
| 382 | 'removefileaction'=> $removefileaction, |
||
| 383 | 'trackid'=> $this->trackid |
||
| 384 | ); |
||
| 385 | $reshook = $hookmanager->executeHooks('getFormMail', $parameters, $this); |
||
| 386 | |||
| 387 | if (!empty($reshook)) { |
||
| 388 | return $hookmanager->resPrint; |
||
| 389 | } else { |
||
| 390 | $out = ''; |
||
| 391 | |||
| 392 | $disablebademails = 1; |
||
| 393 | |||
| 394 | // Define output language |
||
| 395 | $outputlangs = $langs; |
||
| 396 | $newlang = ''; |
||
| 397 | if ($conf->global->MAIN_MULTILANGS && empty($newlang)) { |
||
| 398 | $newlang = $this->param['langsmodels']; |
||
| 399 | } |
||
| 400 | if (!empty($newlang)) { |
||
| 401 | $outputlangs = new Translate("", $conf); |
||
| 402 | $outputlangs->setDefaultLang($newlang); |
||
| 403 | $outputlangs->load('other'); |
||
| 404 | } |
||
| 405 | |||
| 406 | // Get message template for $this->param["models"] into c_email_templates |
||
| 407 | $arraydefaultmessage = -1; |
||
| 408 | if ($this->param['models'] != 'none') { |
||
| 409 | $model_id = 0; |
||
| 410 | if (array_key_exists('models_id', $this->param)) { |
||
| 411 | $model_id = $this->param["models_id"]; |
||
| 412 | } |
||
| 413 | |||
| 414 | $arraydefaultmessage = $this->getEMailTemplate($this->db, $this->param["models"], $user, $outputlangs, $model_id); // If $model_id is empty, preselect the first one |
||
| 415 | } |
||
| 416 | |||
| 417 | // Define list of attached files |
||
| 418 | $listofpaths = array(); |
||
| 419 | $listofnames = array(); |
||
| 420 | $listofmimes = array(); |
||
| 421 | $keytoavoidconflict = empty($this->trackid) ? '' : '-'.$this->trackid; // this->trackid must be defined |
||
| 422 | |||
| 423 | if (GETPOST('mode', 'alpha') == 'init' || (GETPOST('modelselected') && GETPOST('modelmailselected', 'alpha') && GETPOST('modelmailselected', 'alpha') != '-1')) { |
||
| 424 | if (!empty($arraydefaultmessage->joinfiles) && is_array($this->param['fileinit'])) { |
||
| 425 | foreach ($this->param['fileinit'] as $file) { |
||
| 426 | $this->add_attached_files($file, basename($file), dol_mimetype($file)); |
||
| 427 | } |
||
| 428 | } |
||
| 429 | } |
||
| 430 | |||
| 431 | if (!empty($_SESSION["listofpaths".$keytoavoidconflict])) { |
||
| 432 | $listofpaths = explode(';', $_SESSION["listofpaths".$keytoavoidconflict]); |
||
| 433 | } |
||
| 434 | if (!empty($_SESSION["listofnames".$keytoavoidconflict])) { |
||
| 435 | $listofnames = explode(';', $_SESSION["listofnames".$keytoavoidconflict]); |
||
| 436 | } |
||
| 437 | if (!empty($_SESSION["listofmimes".$keytoavoidconflict])) { |
||
| 438 | $listofmimes = explode(';', $_SESSION["listofmimes".$keytoavoidconflict]); |
||
| 439 | } |
||
| 440 | |||
| 441 | |||
| 442 | $out .= "\n".'<!-- Begin form mail type='.$this->param["models"].' --><div id="mailformdiv"></div>'."\n"; |
||
| 443 | if ($this->withform == 1) { |
||
| 444 | $out .= '<form method="POST" name="mailform" id="mailform" enctype="multipart/form-data" action="'.$this->param["returnurl"].'#formmail">'."\n"; |
||
| 445 | |||
| 446 | $out .= '<a id="formmail" name="formmail"></a>'; |
||
| 447 | $out .= '<input style="display:none" type="submit" id="sendmailhidden" name="sendmail">'; |
||
| 448 | $out .= '<input type="hidden" name="token" value="'.newToken().'" />'; |
||
| 449 | $out .= '<input type="hidden" name="trackid" value="'.$this->trackid.'" />'; |
||
| 450 | } |
||
| 451 | if (!empty($this->withfrom)) { |
||
| 452 | if (!empty($this->withfromreadonly)) { |
||
| 453 | $out .= '<input type="hidden" id="fromname" name="fromname" value="'.$this->fromname.'" />'; |
||
| 454 | $out .= '<input type="hidden" id="frommail" name="frommail" value="'.$this->frommail.'" />'; |
||
| 455 | } |
||
| 456 | } |
||
| 457 | foreach ($this->param as $key => $value) { |
||
| 458 | if (is_array($value)) { |
||
| 459 | $out .= "<!-- param key=".$key." is array, we do not output input filed for it -->\n"; |
||
| 460 | } else { |
||
| 461 | $out .= '<input type="hidden" id="'.$key.'" name="'.$key.'" value="'.$value.'" />'."\n"; |
||
| 462 | } |
||
| 463 | } |
||
| 464 | |||
| 465 | $modelmail_array = array(); |
||
| 466 | if ($this->param['models'] != 'none') { |
||
| 467 | $result = $this->fetchAllEMailTemplate($this->param["models"], $user, $outputlangs); |
||
| 468 | if ($result < 0) { |
||
| 469 | setEventMessages($this->error, $this->errors, 'errors'); |
||
| 470 | } |
||
| 471 | |||
| 472 | foreach ($this->lines_model as $line) { |
||
| 473 | $reg = array(); |
||
| 474 | if (preg_match('/\((.*)\)/', $line->label, $reg)) { |
||
| 475 | $labeltouse = $langs->trans($reg[1]); // langs->trans when label is __(xxx)__ |
||
| 476 | } else { |
||
| 477 | $labeltouse = $line->label; |
||
| 478 | } |
||
| 479 | |||
| 480 | // We escape the $labeltouse to store it into $modelmail_array. |
||
| 481 | $modelmail_array[$line->id] = dol_escape_htmltag($labeltouse); |
||
| 482 | if ($line->lang) { |
||
| 483 | $modelmail_array[$line->id] .= ' '.picto_from_langcode($line->lang); |
||
| 484 | } |
||
| 485 | if ($line->private) { |
||
| 486 | $modelmail_array[$line->id] .= ' - <span class="opacitymedium">'.dol_escape_htmltag($langs->trans("Private")).'</span>'; |
||
| 487 | } |
||
| 488 | } |
||
| 489 | } |
||
| 490 | |||
| 491 | // Zone to select email template |
||
| 492 | if (count($modelmail_array) > 0) { |
||
| 493 | $model_mail_selected_id = GETPOSTISSET('modelmailselected') ? GETPOST('modelmailselected', 'int') : ($arraydefaultmessage->id > 0 ? $arraydefaultmessage->id : 0); |
||
| 494 | |||
| 495 | // If list of template is filled |
||
| 496 | $out .= '<div class="center" style="padding: 0px 0 12px 0">'."\n"; |
||
| 497 | |||
| 498 | $out .= '<span class="opacitymedium">'.$langs->trans('SelectMailModel').':</span> '; |
||
| 499 | |||
| 500 | $out .= $this->selectarray('modelmailselected', $modelmail_array, $model_mail_selected_id, 1, 0, 0, '', 0, 0, 0, '', 'minwidth100', 1, '', 0, 1); |
||
| 501 | if ($user->admin) { |
||
| 502 | $out .= info_admin($langs->trans("YouCanChangeValuesForThisListFrom", $langs->transnoentitiesnoconv('Setup').' - '.$langs->transnoentitiesnoconv('EMails')), 1); |
||
| 503 | } |
||
| 504 | |||
| 505 | $out .= ' '; |
||
| 506 | $out .= '<input type="submit" class="button reposition" value="'.$langs->trans('Apply').'" name="modelselected" id="modelselected">'; |
||
| 507 | $out .= ' '; |
||
| 508 | $out .= '</div>'; |
||
| 509 | } elseif (!empty($this->param['models']) && in_array($this->param['models'], array( |
||
| 510 | 'propal_send', 'order_send', 'facture_send', |
||
| 511 | 'shipping_send', 'fichinter_send', 'supplier_proposal_send', 'order_supplier_send', |
||
| 512 | 'invoice_supplier_send', 'thirdparty', 'contract', 'user', 'recruitmentcandidature_send', 'all' |
||
| 513 | ))) { |
||
| 514 | // If list of template is empty |
||
| 515 | $out .= '<div class="center" style="padding: 0px 0 12px 0">'."\n"; |
||
| 516 | $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. |
||
| 517 | if ($user->admin) { |
||
| 518 | $out .= info_admin($langs->trans("YouCanChangeValuesForThisListFrom", $langs->transnoentitiesnoconv('Setup').' - '.$langs->transnoentitiesnoconv('EMails')), 1); |
||
| 519 | } |
||
| 520 | $out .= ' '; |
||
| 521 | $out .= '<input type="submit" class="button" value="'.$langs->trans('Apply').'" name="modelselected" disabled="disabled" id="modelselected">'; |
||
| 522 | $out .= ' '; |
||
| 523 | $out .= '</div>'; |
||
| 524 | } else { |
||
| 525 | $out .= '<!-- No template available for $this->param["models"] = '.$this->param['models'].' -->'; |
||
| 526 | } |
||
| 527 | |||
| 528 | |||
| 529 | $out .= '<table class="tableforemailform boxtablenotop centpercent">'."\n"; |
||
| 530 | |||
| 531 | // Substitution array/string |
||
| 532 | $helpforsubstitution = ''; |
||
| 533 | if (is_array($this->substit) && count($this->substit)) { |
||
| 534 | $helpforsubstitution .= $langs->trans('AvailableVariables').' :<br>'."\n"; |
||
| 535 | } |
||
| 536 | foreach ($this->substit as $key => $val) { |
||
| 537 | $helpforsubstitution .= $key.' -> '.$langs->trans(dol_string_nohtmltag(dolGetFirstLineOfText($val))).'<br>'; |
||
| 538 | } |
||
| 539 | if (!empty($this->withsubstit)) { // Unset or set ->withsubstit=0 to disable this. |
||
| 540 | $out .= '<tr><td colspan="2" class="right">'; |
||
| 541 | //$out.='<div class="floatright">'; |
||
| 542 | if (is_numeric($this->withsubstit)) { |
||
| 543 | $out .= $form->textwithpicto($langs->trans("EMailTestSubstitutionReplacedByGenericValues"), $helpforsubstitution, 1, 'help', '', 0, 2, 'substittooltip'); // Old usage |
||
| 544 | } else { |
||
| 545 | $out .= $form->textwithpicto($langs->trans('AvailableVariables'), $helpforsubstitution, 1, 'help', '', 0, 2, 'substittooltip'); // New usage |
||
| 546 | } |
||
| 547 | $out .= "</td></tr>\n"; |
||
| 548 | //$out.='</div>'; |
||
| 549 | } |
||
| 550 | |||
| 551 | // From |
||
| 552 | if (!empty($this->withfrom)) { |
||
| 553 | if (!empty($this->withfromreadonly)) { |
||
| 554 | $out .= '<tr><td class="fieldrequired minwidth200">'.$langs->trans("MailFrom").'</td><td>'; |
||
| 555 | |||
| 556 | // $this->fromtype is the default value to use to select sender |
||
| 557 | if (!($this->fromtype === 'user' && $this->fromid > 0) |
||
| 558 | && !($this->fromtype === 'company') |
||
| 559 | && !($this->fromtype === 'robot') |
||
| 560 | && !preg_match('/user_aliases/', $this->fromtype) |
||
| 561 | && !preg_match('/global_aliases/', $this->fromtype) |
||
| 562 | && !preg_match('/senderprofile/', $this->fromtype) |
||
| 563 | ) { |
||
| 564 | // Use this->fromname and this->frommail or error if not defined |
||
| 565 | $out .= $this->fromname; |
||
| 566 | if ($this->frommail) { |
||
| 567 | $out .= ' <'.$this->frommail.'>'; |
||
| 568 | } else { |
||
| 569 | if ($this->fromtype) { |
||
| 570 | $langs->load('errors'); |
||
| 571 | $out .= '<span class="warning"> <'.$langs->trans('ErrorNoMailDefinedForThisUser').'> </span>'; |
||
| 572 | } |
||
| 573 | } |
||
| 574 | } else { |
||
| 575 | $liste = array(); |
||
| 576 | |||
| 577 | // Add user email |
||
| 578 | if (empty($user->email)) { |
||
| 579 | $langs->load('errors'); |
||
| 580 | $liste['user'] = $user->getFullName($langs).' <'.$langs->trans('ErrorNoMailDefinedForThisUser').'>'; |
||
| 581 | } else { |
||
| 582 | $liste['user'] = $user->getFullName($langs).' <'.$user->email.'>'; |
||
| 583 | } |
||
| 584 | |||
| 585 | // Add also company main email |
||
| 586 | $liste['company'] = $conf->global->MAIN_INFO_SOCIETE_NOM.' <'.$conf->global->MAIN_INFO_SOCIETE_MAIL.'>'; |
||
| 587 | |||
| 588 | // Add also email aliases if there is some |
||
| 589 | $listaliases = array( |
||
| 590 | 'user_aliases' => (empty($user->email_aliases) ? '' : $user->email_aliases), |
||
| 591 | 'global_aliases' => getDolGlobalString('MAIN_INFO_SOCIETE_MAIL_ALIASES'), |
||
| 592 | ); |
||
| 593 | |||
| 594 | // Also add robot email |
||
| 595 | if (!empty($this->fromalsorobot)) { |
||
| 596 | if (!empty($conf->global->MAIN_MAIL_EMAIL_FROM) && $conf->global->MAIN_MAIL_EMAIL_FROM != $conf->global->MAIN_INFO_SOCIETE_MAIL) { |
||
| 597 | $liste['robot'] = $conf->global->MAIN_MAIL_EMAIL_FROM; |
||
| 598 | if ($this->frommail) { |
||
| 599 | $liste['robot'] .= ' <'.$conf->global->MAIN_MAIL_EMAIL_FROM.'>'; |
||
| 600 | } |
||
| 601 | } |
||
| 602 | } |
||
| 603 | |||
| 604 | // Add also email aliases from the c_email_senderprofile table |
||
| 605 | $sql = "SELECT rowid, label, email FROM ".$this->db->prefix()."c_email_senderprofile"; |
||
| 606 | $sql .= " WHERE active = 1 AND (private = 0 OR private = ".((int) $user->id).")"; |
||
| 607 | $sql .= " ORDER BY position"; |
||
| 608 | $resql = $this->db->query($sql); |
||
| 609 | if ($resql) { |
||
| 610 | $num = $this->db->num_rows($resql); |
||
| 611 | $i = 0; |
||
| 612 | while ($i < $num) { |
||
| 613 | $obj = $this->db->fetch_object($resql); |
||
| 614 | if ($obj) { |
||
| 615 | $listaliases['senderprofile_'.$obj->rowid] = $obj->label.' <'.$obj->email.'>'; |
||
| 616 | } |
||
| 617 | $i++; |
||
| 618 | } |
||
| 619 | } else { |
||
| 620 | dol_print_error($this->db); |
||
| 621 | } |
||
| 622 | |||
| 623 | foreach ($listaliases as $typealias => $listalias) { |
||
| 624 | $posalias = 0; |
||
| 625 | $listaliasarray = explode(',', $listalias); |
||
| 626 | foreach ($listaliasarray as $listaliasval) { |
||
| 627 | $posalias++; |
||
| 628 | $listaliasval = trim($listaliasval); |
||
| 629 | if ($listaliasval) { |
||
| 630 | $listaliasval = preg_replace('/</', '<', $listaliasval); |
||
| 631 | $listaliasval = preg_replace('/>/', '>', $listaliasval); |
||
| 632 | if (!preg_match('/</', $listaliasval)) { |
||
| 633 | $listaliasval = '<'.$listaliasval.'>'; |
||
| 634 | } |
||
| 635 | $liste[$typealias.'_'.$posalias] = $listaliasval; |
||
| 636 | } |
||
| 637 | } |
||
| 638 | } |
||
| 639 | |||
| 640 | // Set the default "From" |
||
| 641 | $defaultfrom = ''; |
||
| 642 | $reshook = $hookmanager->executeHooks('getDefaultFromEmail', $parameters, $this); |
||
| 643 | if (empty($reshook)) { |
||
| 644 | $defaultfrom = $this->fromtype; |
||
| 645 | } |
||
| 646 | if (!empty($hookmanager->resArray['defaultfrom'])) { |
||
| 647 | $defaultfrom = $hookmanager->resArray['defaultfrom']; |
||
| 648 | } |
||
| 649 | |||
| 650 | // Using combo here make the '<email>' no more visible on list. |
||
| 651 | //$out.= ' '.$form->selectarray('fromtype', $liste, $this->fromtype, 0, 0, 0, '', 0, 0, 0, '', 'fromforsendingprofile maxwidth200onsmartphone', 1, '', $disablebademails); |
||
| 652 | $out .= ' '.$form->selectarray('fromtype', $liste, $defaultfrom, 0, 0, 0, '', 0, 0, 0, '', 'fromforsendingprofile maxwidth200onsmartphone', 0, '', $disablebademails); |
||
| 653 | } |
||
| 654 | |||
| 655 | $out .= "</td></tr>\n"; |
||
| 656 | } else { |
||
| 657 | $out .= '<tr><td class="fieldrequired width200">'.$langs->trans("MailFrom")."</td><td>"; |
||
| 658 | $out .= $langs->trans("Name").':<input type="text" id="fromname" name="fromname" class="maxwidth200onsmartphone" value="'.$this->fromname.'" />'; |
||
| 659 | $out .= ' '; |
||
| 660 | $out .= $langs->trans("EMail").':<<input type="text" id="frommail" name="frommail" class="maxwidth200onsmartphone" value="'.$this->frommail.'" />>'; |
||
| 661 | $out .= "</td></tr>\n"; |
||
| 662 | } |
||
| 663 | } |
||
| 664 | |||
| 665 | // To |
||
| 666 | if (!empty($this->withto) || is_array($this->withto)) { |
||
| 667 | $out .= $this->getHtmlForTo(); |
||
| 668 | } |
||
| 669 | |||
| 670 | // To User |
||
| 671 | if (!empty($this->withtouser) && is_array($this->withtouser) && !empty($conf->global->MAIN_MAIL_ENABLED_USER_DEST_SELECT)) { |
||
| 672 | $out .= '<tr><td>'; |
||
| 673 | $out .= $langs->trans("MailToUsers"); |
||
| 674 | $out .= '</td><td>'; |
||
| 675 | |||
| 676 | // multiselect array convert html entities into options tags, even if we dont want this, so we encode them a second time |
||
| 677 | $tmparray = $this->withtouser; |
||
| 678 | foreach ($tmparray as $key => $val) { |
||
| 679 | $tmparray[$key] = dol_htmlentities($tmparray[$key], null, 'UTF-8', true); |
||
| 680 | } |
||
| 681 | $withtoselected = GETPOST("receiveruser", 'array'); // Array of selected value |
||
| 682 | if (empty($withtoselected) && count($tmparray) == 1 && GETPOST('action', 'aZ09') == 'presend') { |
||
| 683 | $withtoselected = array_keys($tmparray); |
||
| 684 | } |
||
| 685 | $out .= $form->multiselectarray("receiveruser", $tmparray, $withtoselected, null, null, 'inline-block minwidth500', null, ""); |
||
| 686 | $out .= "</td></tr>\n"; |
||
| 687 | } |
||
| 688 | |||
| 689 | // With option one email per recipient |
||
| 690 | if (!empty($this->withoptiononeemailperrecipient)) { |
||
| 691 | if (abs($this->withoptiononeemailperrecipient) == 1) { |
||
| 692 | $out .= '<tr><td class="minwidth200">'; |
||
| 693 | $out .= $langs->trans("GroupEmails"); |
||
| 694 | $out .= '</td><td>'; |
||
| 695 | $out .= ' <input type="checkbox" id="oneemailperrecipient" value="1" name="oneemailperrecipient"'.($this->withoptiononeemailperrecipient > 0 ? ' checked="checked"' : '').'> '; |
||
| 696 | $out .= '<label for="oneemailperrecipient">'.$langs->trans("OneEmailPerRecipient").'</label>'; |
||
| 697 | $out .= '<span class="hideonsmartphone opacitymedium">'; |
||
| 698 | $out .= ' - '; |
||
| 699 | $out .= $langs->trans("WarningIfYouCheckOneRecipientPerEmail"); |
||
| 700 | $out .= '</span>'; |
||
| 701 | $out .= '</td></tr>'; |
||
| 702 | } else { |
||
| 703 | $out .= '<tr><td><input type="hidden" name="oneemailperrecipient" value="1"></td><td></td></tr>'; |
||
| 704 | } |
||
| 705 | } |
||
| 706 | |||
| 707 | // CC |
||
| 708 | if (!empty($this->withtocc) || is_array($this->withtocc)) { |
||
| 709 | $out .= $this->getHtmlForCc(); |
||
| 710 | } |
||
| 711 | |||
| 712 | // To User cc |
||
| 713 | if (!empty($this->withtoccuser) && is_array($this->withtoccuser) && !empty($conf->global->MAIN_MAIL_ENABLED_USER_DEST_SELECT)) { |
||
| 714 | $out .= '<tr><td>'; |
||
| 715 | $out .= $langs->trans("MailToCCUsers"); |
||
| 716 | $out .= '</td><td>'; |
||
| 717 | |||
| 718 | // multiselect array convert html entities into options tags, even if we dont want this, so we encode them a second time |
||
| 719 | $tmparray = $this->withtoccuser; |
||
| 720 | foreach ($tmparray as $key => $val) { |
||
| 721 | $tmparray[$key] = dol_htmlentities($tmparray[$key], null, 'UTF-8', true); |
||
| 722 | } |
||
| 723 | $withtoselected = GETPOST("receiverccuser", 'array'); // Array of selected value |
||
| 724 | if (empty($withtoselected) && count($tmparray) == 1 && GETPOST('action', 'aZ09') == 'presend') { |
||
| 725 | $withtoselected = array_keys($tmparray); |
||
| 726 | } |
||
| 727 | $out .= $form->multiselectarray("receiverccuser", $tmparray, $withtoselected, null, null, 'inline-block minwidth500', null, ""); |
||
| 728 | $out .= "</td></tr>\n"; |
||
| 729 | } |
||
| 730 | |||
| 731 | // CCC |
||
| 732 | if (!empty($this->withtoccc) || is_array($this->withtoccc)) { |
||
| 733 | $out .= $this->getHtmlForWithCcc(); |
||
| 734 | } |
||
| 735 | |||
| 736 | // Replyto |
||
| 737 | if (!empty($this->withreplyto)) { |
||
|
|
|||
| 738 | if ($this->withreplytoreadonly) { |
||
| 739 | $out .= '<input type="hidden" id="replyname" name="replyname" value="'.$this->replytoname.'" />'; |
||
| 740 | $out .= '<input type="hidden" id="replymail" name="replymail" value="'.$this->replytomail.'" />'; |
||
| 741 | $out .= "<tr><td>".$langs->trans("MailReply")."</td><td>".$this->replytoname.($this->replytomail ? (" <".$this->replytomail.">") : ""); |
||
| 742 | $out .= "</td></tr>\n"; |
||
| 743 | } |
||
| 744 | } |
||
| 745 | |||
| 746 | // Errorsto |
||
| 747 | if (!empty($this->witherrorsto)) { |
||
| 748 | $out .= $this->getHtmlForWithErrorsTo(); |
||
| 749 | } |
||
| 750 | |||
| 751 | // Ask delivery receipt |
||
| 752 | if (!empty($this->withdeliveryreceipt)) { |
||
| 753 | $out .= $this->getHtmlForDeliveryReceipt(); |
||
| 754 | } |
||
| 755 | |||
| 756 | // Topic |
||
| 757 | if (!empty($this->withtopic)) { |
||
| 758 | $out .= $this->getHtmlForTopic($arraydefaultmessage, $helpforsubstitution); |
||
| 759 | } |
||
| 760 | |||
| 761 | // Attached files |
||
| 762 | if (!empty($this->withfile)) { |
||
| 763 | $out .= '<tr>'; |
||
| 764 | $out .= '<td>'.$langs->trans("MailFile").'</td>'; |
||
| 765 | |||
| 766 | $out .= '<td>'; |
||
| 767 | |||
| 768 | if ($this->withmaindocfile) { |
||
| 769 | // withmaindocfile is set to 1 or -1 to show the checkbox (-1 = checked or 1 = not checked) |
||
| 770 | if (GETPOSTISSET('sendmail')) { |
||
| 771 | $this->withmaindocfile = (GETPOST('addmaindocfile', 'alpha') ? -1 : 1); |
||
| 772 | } elseif (is_object($arraydefaultmessage) && $arraydefaultmessage->id > 0) { |
||
| 773 | // If a template was selected, we use setup of template to define if join file checkbox is selected or not. |
||
| 774 | $this->withmaindocfile = ($arraydefaultmessage->joinfiles ? -1 : 1); |
||
| 775 | } |
||
| 776 | } |
||
| 777 | |||
| 778 | if (!empty($this->withmaindocfile)) { |
||
| 779 | if ($this->withmaindocfile == 1) { |
||
| 780 | $out .= '<input type="checkbox" id="addmaindocfile" name="addmaindocfile" value="1" />'; |
||
| 781 | } elseif ($this->withmaindocfile == -1) { |
||
| 782 | $out .= '<input type="checkbox" id="addmaindocfile" name="addmaindocfile" value="1" checked="checked" />'; |
||
| 783 | } |
||
| 784 | $out .= ' <label for="addmaindocfile">'.$langs->trans("JoinMainDoc").'.</label><br>'; |
||
| 785 | } |
||
| 786 | |||
| 787 | if (is_numeric($this->withfile)) { |
||
| 788 | // TODO Trick to have param removedfile containing nb of file to delete. But this does not works without javascript |
||
| 789 | $out .= '<input type="hidden" class="removedfilehidden" name="removedfile" value="">'."\n"; |
||
| 790 | $out .= '<script type="text/javascript">'; |
||
| 791 | $out .= 'jQuery(document).ready(function () {'; |
||
| 792 | $out .= ' jQuery(".removedfile").click(function() {'; |
||
| 793 | $out .= ' jQuery(".removedfilehidden").val(jQuery(this).val());'; |
||
| 794 | $out .= ' });'; |
||
| 795 | $out .= '})'; |
||
| 796 | $out .= '</script>'."\n"; |
||
| 797 | if (count($listofpaths)) { |
||
| 798 | foreach ($listofpaths as $key => $val) { |
||
| 799 | $relativepathtofile = substr($val, (strlen(DOL_DATA_ROOT) - strlen($val))); |
||
| 800 | |||
| 801 | if ($conf->entity > 1) { |
||
| 802 | $relativepathtofile = str_replace($conf->entity.'/', '', $relativepathtofile); |
||
| 803 | } |
||
| 804 | // Try to extract data from full path |
||
| 805 | $formfile_params = array(); |
||
| 806 | preg_match('#^(/)(\w+)(/)(.+)$#', $relativepathtofile, $formfile_params); |
||
| 807 | |||
| 808 | $out .= '<div id="attachfile_'.$key.'">'; |
||
| 809 | // Preview of attachment |
||
| 810 | $out .= img_mime($listofnames[$key]).' '.$listofnames[$key]; |
||
| 811 | |||
| 812 | $out .= $formfile->showPreview(array(), $formfile_params[2], $formfile_params[4]); |
||
| 813 | if (!$this->withfilereadonly) { |
||
| 814 | $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.'" />'; |
||
| 815 | //$out.= ' <a href="'.$_SERVER["PHP_SELF"].'?removedfile='.($key+1).' id="removedfile_'.$key.'">'.img_delete($langs->trans("Delete").'</a>'; |
||
| 816 | } |
||
| 817 | $out .= '<br></div>'; |
||
| 818 | } |
||
| 819 | } elseif (empty($this->withmaindocfile)) { |
||
| 820 | $out .= '<span class="opacitymedium">'.$langs->trans("NoAttachedFiles").'</span><br>'; |
||
| 821 | } |
||
| 822 | if ($this->withfile == 2) { |
||
| 823 | // Can add other files |
||
| 824 | if (!empty($conf->global->FROM_MAIL_USE_INPUT_FILE_MULTIPLE)) { |
||
| 825 | $out .= '<input type="file" class="flat" id="addedfile" name="addedfile[]" value="'.$langs->trans("Upload").'" multiple />'; |
||
| 826 | } else { |
||
| 827 | $out .= '<input type="file" class="flat" id="addedfile" name="addedfile" value="'.$langs->trans("Upload").'" />'; |
||
| 828 | } |
||
| 829 | $out .= ' '; |
||
| 830 | $out .= '<input type="submit" class="button" id="'.$addfileaction.'" name="'.$addfileaction.'" value="'.$langs->trans("MailingAddFile").'" />'; |
||
| 831 | } |
||
| 832 | } else { |
||
| 833 | $out .= $this->withfile; |
||
| 834 | } |
||
| 835 | |||
| 836 | $out .= "</td></tr>\n"; |
||
| 837 | } |
||
| 838 | |||
| 839 | // Message |
||
| 840 | if (!empty($this->withbody)) { |
||
| 841 | $defaultmessage = GETPOST('message', 'restricthtml'); |
||
| 842 | if (!GETPOST('modelselected', 'alpha') || GETPOST('modelmailselected') != '-1') { |
||
| 843 | if ($arraydefaultmessage && $arraydefaultmessage->content) { |
||
| 844 | $defaultmessage = $arraydefaultmessage->content; |
||
| 845 | } elseif (!is_numeric($this->withbody)) { |
||
| 846 | $defaultmessage = $this->withbody; |
||
| 847 | } |
||
| 848 | } |
||
| 849 | |||
| 850 | // Complete substitution array with the url to make online payment |
||
| 851 | $paymenturl = ''; |
||
| 852 | $validpaymentmethod = array(); |
||
| 853 | if (empty($this->substit['__REF__'])) { |
||
| 854 | $paymenturl = ''; |
||
| 855 | } else { |
||
| 856 | // Set the online payment url link into __ONLINE_PAYMENT_URL__ key |
||
| 857 | require_once DOL_DOCUMENT_ROOT.'/core/lib/payments.lib.php'; |
||
| 858 | $langs->loadLangs(array('paypal', 'other')); |
||
| 859 | $typeforonlinepayment = 'free'; |
||
| 860 | if ($this->param["models"] == 'order' || $this->param["models"] == 'order_send') { |
||
| 861 | $typeforonlinepayment = 'order'; // TODO use detection on something else than template |
||
| 862 | } |
||
| 863 | if ($this->param["models"] == 'invoice' || $this->param["models"] == 'facture_send') { |
||
| 864 | $typeforonlinepayment = 'invoice'; // TODO use detection on something else than template |
||
| 865 | } |
||
| 866 | if ($this->param["models"] == 'member') { |
||
| 867 | $typeforonlinepayment = 'member'; // TODO use detection on something else than template |
||
| 868 | } |
||
| 869 | $url = getOnlinePaymentUrl(0, $typeforonlinepayment, $this->substit['__REF__']); |
||
| 870 | $paymenturl = $url; |
||
| 871 | |||
| 872 | $validpaymentmethod = getValidOnlinePaymentMethods(''); |
||
| 873 | } |
||
| 874 | |||
| 875 | if (count($validpaymentmethod) > 0 && $paymenturl) { |
||
| 876 | $langs->load('other'); |
||
| 877 | $this->substit['__ONLINE_PAYMENT_TEXT_AND_URL__'] = str_replace('\n', "\n", $langs->transnoentities("PredefinedMailContentLink", $paymenturl)); |
||
| 878 | $this->substit['__ONLINE_PAYMENT_URL__'] = $paymenturl; |
||
| 879 | } else { |
||
| 880 | $this->substit['__ONLINE_PAYMENT_TEXT_AND_URL__'] = ''; |
||
| 881 | $this->substit['__ONLINE_PAYMENT_URL__'] = ''; |
||
| 882 | } |
||
| 883 | |||
| 884 | $this->substit['__ONLINE_INTERVIEW_SCHEDULER_TEXT_AND_URL__'] = ''; |
||
| 885 | |||
| 886 | // Add lines substitution key from each line |
||
| 887 | $lines = ''; |
||
| 888 | $defaultlines = $arraydefaultmessage->content_lines; |
||
| 889 | if (isset($defaultlines)) { |
||
| 890 | foreach ($this->substit_lines as $substit_line) { |
||
| 891 | $lines .= make_substitutions($defaultlines, $substit_line)."\n"; |
||
| 892 | } |
||
| 893 | } |
||
| 894 | $this->substit['__LINES__'] = $lines; |
||
| 895 | |||
| 896 | $defaultmessage = str_replace('\n', "\n", $defaultmessage); |
||
| 897 | |||
| 898 | // Deal with format differences between message and some substitution variables (text / HTML) |
||
| 899 | $atleastonecomponentishtml = 0; |
||
| 900 | if (strpos($defaultmessage, '__USER_SIGNATURE__') !== false && dol_textishtml($this->substit['__USER_SIGNATURE__'])) { |
||
| 901 | $atleastonecomponentishtml++; |
||
| 902 | } |
||
| 903 | if (strpos($defaultmessage, '__ONLINE_PAYMENT_TEXT_AND_URL__') !== false && dol_textishtml($this->substit['__ONLINE_PAYMENT_TEXT_AND_URL__'])) { |
||
| 904 | $atleastonecomponentishtml++; |
||
| 905 | } |
||
| 906 | if (strpos($defaultmessage, '__ONLINE_INTERVIEW_SCHEDULER_TEXT_AND_URL__') !== false && dol_textishtml($this->substit['__ONLINE_INTERVIEW_SCHEDULER_TEXT_AND_URL__'])) { |
||
| 907 | $atleastonecomponentishtml++; |
||
| 908 | } |
||
| 909 | if (dol_textishtml($defaultmessage)) { |
||
| 910 | $atleastonecomponentishtml++; |
||
| 911 | } |
||
| 912 | if ($atleastonecomponentishtml) { |
||
| 913 | if (!dol_textishtml($this->substit['__USER_SIGNATURE__'])) { |
||
| 914 | $this->substit['__USER_SIGNATURE__'] = dol_nl2br($this->substit['__USER_SIGNATURE__']); |
||
| 915 | } |
||
| 916 | if (!dol_textishtml($this->substit['__ONLINE_PAYMENT_TEXT_AND_URL__'])) { |
||
| 917 | $this->substit['__ONLINE_PAYMENT_TEXT_AND_URL__'] = dol_nl2br($this->substit['__ONLINE_PAYMENT_TEXT_AND_URL__']); |
||
| 918 | } |
||
| 919 | if (!dol_textishtml($defaultmessage)) { |
||
| 920 | $defaultmessage = dol_nl2br($defaultmessage); |
||
| 921 | } |
||
| 922 | } |
||
| 923 | |||
| 924 | if (GETPOSTISSET("message") && !GETPOST('modelselected')) { |
||
| 925 | $defaultmessage = GETPOST("message", "restricthtml"); |
||
| 926 | } else { |
||
| 927 | $defaultmessage = make_substitutions($defaultmessage, $this->substit); |
||
| 928 | // Clean first \n and br (to avoid empty line when CONTACTCIVNAME is empty) |
||
| 929 | $defaultmessage = preg_replace("/^(<br>)+/", "", $defaultmessage); |
||
| 930 | $defaultmessage = preg_replace("/^\n+/", "", $defaultmessage); |
||
| 931 | } |
||
| 932 | |||
| 933 | $out .= '<tr>'; |
||
| 934 | $out .= '<td class="tdtop">'; |
||
| 935 | $out .= $form->textwithpicto($langs->trans('MailText'), $helpforsubstitution, 1, 'help', '', 0, 2, 'substittooltipfrombody'); |
||
| 936 | $out .= '</td>'; |
||
| 937 | $out .= '<td>'; |
||
| 938 | if ($this->withbodyreadonly) { |
||
| 939 | $out .= nl2br($defaultmessage); |
||
| 940 | $out .= '<input type="hidden" id="message" name="message" value="'.$defaultmessage.'" />'; |
||
| 941 | } else { |
||
| 942 | if (!isset($this->ckeditortoolbar)) { |
||
| 943 | $this->ckeditortoolbar = 'dolibarr_notes'; |
||
| 944 | } |
||
| 945 | |||
| 946 | // Editor wysiwyg |
||
| 947 | require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php'; |
||
| 948 | if ($this->withfckeditor == -1) { |
||
| 949 | if (!empty($conf->global->FCKEDITOR_ENABLE_MAIL)) { |
||
| 950 | $this->withfckeditor = 1; |
||
| 951 | } else { |
||
| 952 | $this->withfckeditor = 0; |
||
| 953 | } |
||
| 954 | } |
||
| 955 | |||
| 956 | $doleditor = new DolEditor('message', $defaultmessage, '', 280, $this->ckeditortoolbar, 'In', true, true, $this->withfckeditor, 8, '95%'); |
||
| 957 | $out .= $doleditor->Create(1); |
||
| 958 | } |
||
| 959 | $out .= "</td></tr>\n"; |
||
| 960 | } |
||
| 961 | |||
| 962 | $out .= '</table>'."\n"; |
||
| 963 | |||
| 964 | if ($this->withform == 1 || $this->withform == -1) { |
||
| 965 | $out .= '<div class="center">'; |
||
| 966 | $out .= '<input type="submit" class="button button-add" id="sendmail" name="sendmail" value="'.$langs->trans("SendMail").'"'; |
||
| 967 | // Add a javascript test to avoid to forget to submit file before sending email |
||
| 968 | if ($this->withfile == 2 && $conf->use_javascript_ajax) { |
||
| 969 | $out .= ' onClick="if (document.mailform.addedfile.value != \'\') { alert(\''.dol_escape_js($langs->trans("FileWasNotUploaded")).'\'); return false; } else { return true; }"'; |
||
| 970 | } |
||
| 971 | $out .= ' />'; |
||
| 972 | if ($this->withcancel) { |
||
| 973 | $out .= '<input class="button button-cancel" type="submit" id="cancel" name="cancel" value="'.$langs->trans("Cancel").'" />'; |
||
| 974 | } |
||
| 975 | $out .= '</div>'."\n"; |
||
| 976 | } |
||
| 977 | |||
| 978 | if ($this->withform == 1) { |
||
| 979 | $out .= '</form>'."\n"; |
||
| 980 | } |
||
| 981 | |||
| 982 | // Disable enter key if option MAIN_MAILFORM_DISABLE_ENTERKEY is set |
||
| 983 | if (!empty($conf->global->MAIN_MAILFORM_DISABLE_ENTERKEY)) { |
||
| 984 | $out .= '<script type="text/javascript">'; |
||
| 985 | $out .= 'jQuery(document).ready(function () {'; |
||
| 986 | $out .= ' $(document).on("keypress", \'#mailform\', function (e) { /* Note this is called at every key pressed ! */ |
||
| 987 | var code = e.keyCode || e.which; |
||
| 988 | if (code == 13) { |
||
| 989 | console.log("Enter was intercepted and blocked"); |
||
| 990 | e.preventDefault(); |
||
| 991 | return false; |
||
| 992 | } |
||
| 993 | });'; |
||
| 994 | $out .= ' })'; |
||
| 995 | $out .= '</script>'; |
||
| 996 | } |
||
| 997 | |||
| 998 | $out .= "<!-- End form mail -->\n"; |
||
| 999 | |||
| 1000 | return $out; |
||
| 1001 | } |
||
| 1694 |