Пример #1
0
/**
 * Return first line of text. Cut will depends if content is HTML or not.
 *
 * @param 	string	$text		Input text
 * @return	string				Output text
 * @see dol_nboflines_bis
 */
function dolGetFirstLineOfText($text)
{
    if (dol_textishtml($text)) {
        $firstline = preg_replace('/<br[^>]*>.*$/s', '', $text);
        // The s pattern modifier means the . can match newline characters
    } else {
        $firstline = preg_replace('/[\\n\\r].*/', '', $text);
    }
    return $firstline . (strlen($firstline) != strlen($text) ? '...' : '');
}
Пример #2
0
 /**
  * Make substitution
  *
  * @param	$object				Adherent Object
  * @return  string      		Value of input text string with substitutions done
  */
 function makeSubstitution($object)
 {
     global $conf, $langs;
     $text = $this->body;
     $birthday = dol_print_date($object->naiss, 'day');
     $msgishtml = 0;
     if (dol_textishtml($text, 1)) {
         $msgishtml = 1;
     }
     $infos = '';
     // Specific for Photo
     $photoName = $object->photo;
     $photoType = $object->_attachments->{$photoName}->content_type;
     $photoBase64 = $object->getFileBase64($object->photo);
     $photo = '<img src="data:' . $PhotoType . ';base64,' . $photoBase64 . '"/>';
     // Substitutions
     $substitutionarray = array('__DOL_MAIN_URL_ROOT__' => DOL_MAIN_URL_ROOT, '__ID__' => $msgishtml ? dol_htmlentitiesbr($object->login) : $object->login, '__CIVILITE__' => $object->getCivilityLabel($msgishtml ? 0 : 1), '__FIRSTNAME__' => $msgishtml ? dol_htmlentitiesbr($object->Firstname) : $object->Firstname, '__LASTNAME__' => $msgishtml ? dol_htmlentitiesbr($object->Lastname) : $object->Lastname, '__FULLNAME__' => $msgishtml ? dol_htmlentitiesbr($object->getFullName($langs)) : $object->getFullName($langs), '__COMPANY__' => $msgishtml ? dol_htmlentitiesbr($object->societe) : $object->societe, '__ADDRESS__' => $msgishtml ? dol_htmlentitiesbr($object->address) : $object->address, '__ZIP__' => $msgishtml ? dol_htmlentitiesbr($object->zip) : $object->zip, '__TOWN__' => $msgishtml ? dol_htmlentitiesbr($object->town) : $object->town, '__COUNTRY__' => $msgishtml ? dol_htmlentitiesbr($object->country) : $object->country, '__EMAIL__' => $msgishtml ? dol_htmlentitiesbr($object->email) : $object->email, '__NAISS__' => $msgishtml ? dol_htmlentitiesbr($birthday) : $birthday, '__PHOTO__' => $photo, '__LOGIN__' => $msgishtml ? dol_htmlentitiesbr($object->login) : $object->login, '__PASSWORD__' => $msgishtml ? dol_htmlentitiesbr($object->pass) : $object->pass, '__STATUS__' => $object->getLibStatus(), '__INFOS__' => $msgishtml ? dol_htmlentitiesbr($infos) : $infos, '__PRENOM__' => $msgishtml ? dol_htmlentitiesbr($object->Firstname) : $object->Firstname, '__NOM__' => $msgishtml ? dol_htmlentitiesbr($object->Lastname) : $object->Lastname, '__SOCIETE__' => $msgishtml ? dol_htmlentitiesbr($object->societe) : $object->societe, '__ADRESSE__' => $msgishtml ? dol_htmlentitiesbr($object->address) : $object->address, '__CP__' => $msgishtml ? dol_htmlentitiesbr($object->zip) : $object->zip, '__VILLE__' => $msgishtml ? dol_htmlentitiesbr($object->town) : $object->town, '__PAYS__' => $msgishtml ? dol_htmlentitiesbr($object->country) : $object->country);
     complete_substitutions_array($substitutionarray, $langs);
     $this->body = make_substitutions($text, $substitutionarray);
     return 1;
 }
Пример #3
0
				else
				{
					print '&nbsp;';
				}
				print "</td></tr>\n";
			}

            // Custom code
            print '<tr><td>'.$langs->trans("CustomCode").'</td><td colspan="2">'.$product->customcode.'</td>';

            // Origin country code
            print '<tr><td>'.$langs->trans("CountryOrigin").'</td><td colspan="2">'.getCountry($product->country_id,0,$db).'</td>';


			// Note
			print '<tr><td valign="top">'.$langs->trans("Note").'</td><td colspan="2">'.(dol_textishtml($product->note)?$product->note:dol_nl2br($product->note,1,true)).'</td></tr>';

			print "</table>\n";
		}
		else
		{
			$canvas->assign_values('view');
			$canvas->display_canvas();
		}

		dol_fiche_end();
	}

}
else if ($action != 'create')
{
Пример #4
0
/**
 *  Concat 2 descriptions (second one after first one with a new line separator if required)
 *  text1 html + text2 html => text1 + '<br>' + text2
 *  text1 html + text2 txt  => text1 + '<br>' + dol_nl2br(text2)
 *  text1 txt  + text2 html => dol_nl2br(text1) + '<br>' + text2
 *  text1 txt  + text2 txt  => text1 + '\n' + text2
 *
 *  @param	string	$text1		Text 1
 *  @param	string	$text2		Text 2
 *  @param  bool	$forxml     false=Use <br>, true=Use <br />
 *  @return	string				Text 1 + new line + Text2
 *  @see    dol_textishtml
 */
function dol_concatdesc($text1, $text2, $forxml = false)
{
    $ret = '';
    $ret .= !dol_textishtml($text1) && dol_textishtml($text2) ? dol_nl2br($text1, 0, $forxml) : $text1;
    $ret .= !empty($text1) && !empty($text2) ? dol_textishtml($text1) || dol_textishtml($text2) ? $forxml ? "<br \\>\n" : "<br>\n" : "\n" : "";
    $ret .= dol_textishtml($text1) && !dol_textishtml($text2) ? dol_nl2br($text2, 0, $forxml) : $text2;
    return $ret;
}
Пример #5
0
 $email_from = '';
 if (!empty($_POST["fromname"])) {
     $email_from = $_POST["fromname"] . ' ';
 }
 if (!empty($_POST["frommail"])) {
     $email_from .= '<' . $_POST["frommail"] . '>';
 }
 $errors_to = $_POST["errorstomail"];
 $sendto = $_POST["sendto"];
 $sendtocc = $_POST["sendtocc"];
 $sendtoccc = $_POST["sendtoccc"];
 $subject = $_POST['subject'];
 $body = $_POST['message'];
 $deliveryreceipt = $_POST["deliveryreceipt"];
 //Check if we have to decode HTML
 if (!empty($conf->global->FCKEDITOR_ENABLE_MAILING) && dol_textishtml(dol_html_entity_decode($body, ENT_COMPAT | ENT_HTML401))) {
     $body = dol_html_entity_decode($body, ENT_COMPAT | ENT_HTML401);
 }
 // Create form object
 include_once DOL_DOCUMENT_ROOT . '/core/class/html.formmail.class.php';
 $formmail = new FormMail($db);
 $attachedfiles = $formmail->get_attached_files();
 $filepath = $attachedfiles['paths'];
 $filename = $attachedfiles['names'];
 $mimetype = $attachedfiles['mimes'];
 if (empty($_POST["frommail"])) {
     setEventMessage($langs->trans("ErrorFieldRequired", $langs->transnoentities("MailFrom")), 'errors');
     $action = 'test';
     $error++;
 }
 if (empty($sendto)) {
Пример #6
0
/**
 *  Return line description translated in outputlangs and encoded into htmlentities and with <br>
 *
 *  @param  Object		$object              Object
 *  @param  int			$i                   Current line number (0 = first line, 1 = second line, ...)
 *  @param  Translate	$outputlangs         Object langs for output
 *  @param  int			$hideref             Hide reference
 *  @param  int			$hidedesc            Hide description
 *  @param  int			$issupplierline      Is it a line for a supplier object ?
 *  @return string       				     String with line
 */
function pdf_getlinedesc($object, $i, $outputlangs, $hideref = 0, $hidedesc = 0, $issupplierline = 0)
{
    global $db, $conf, $langs;
    $idprod = !empty($object->lines[$i]->fk_product) ? $object->lines[$i]->fk_product : false;
    $label = !empty($object->lines[$i]->label) ? $object->lines[$i]->label : (!empty($object->lines[$i]->product_label) ? $object->lines[$i]->product_label : '');
    $desc = !empty($object->lines[$i]->desc) ? $object->lines[$i]->desc : (!empty($object->lines[$i]->description) ? $object->lines[$i]->description : '');
    $ref_supplier = !empty($object->lines[$i]->ref_supplier) ? $object->lines[$i]->ref_supplier : (!empty($object->lines[$i]->ref_fourn) ? $object->lines[$i]->ref_fourn : '');
    // TODO Not yet saved for supplier invoices, only supplier orders
    $note = !empty($object->lines[$i]->note) ? $object->lines[$i]->note : '';
    $dbatch = !empty($object->lines[$i]->detail_batch) ? $object->lines[$i]->detail_batch : false;
    if ($issupplierline) {
        $prodser = new ProductFournisseur($db);
    } else {
        $prodser = new Product($db);
    }
    if ($idprod) {
        $prodser->fetch($idprod);
        // If a predefined product and multilang and on other lang, we renamed label with label translated
        if (!empty($conf->global->MAIN_MULTILANGS) && $outputlangs->defaultlang != $langs->defaultlang) {
            $translatealsoifmodified = !empty($conf->global->MAIN_MULTILANG_TRANSLATE_EVEN_IF_MODIFIED);
            // By default if value was modified manually, we keep it (no translation because we don't have it)
            // TODO Instead of making a compare to see if param was modified, check that content contains reference translation. If yes, add the added part to the new translation
            // ($textwasmodified is replaced with $textwasmodifiedorcompleted and we add completion).
            // Set label
            // If we want another language, and if label is same than default language (we did force it to a specific value), we can use translation.
            //var_dump($outputlangs->defaultlang.' - '.$langs->defaultlang.' - '.$label.' - '.$prodser->label);exit;
            $textwasmodified = $label == $prodser->label;
            if (!empty($prodser->multilangs[$outputlangs->defaultlang]["label"]) && ($textwasmodified || $translatealsoifmodified)) {
                $label = $prodser->multilangs[$outputlangs->defaultlang]["label"];
            }
            // Set desc
            // Manage HTML entities description test because $prodser->description is store with htmlentities but $desc no
            $textwasmodified = false;
            if (!empty($desc) && dol_textishtml($desc) && !empty($prodser->description) && dol_textishtml($prodser->description)) {
                $textwasmodified = strpos(dol_html_entity_decode($desc, ENT_QUOTES | ENT_HTML401), dol_html_entity_decode($prodser->description, ENT_QUOTES | ENT_HTML401)) !== false;
            } else {
                $textwasmodified = $desc == $prodser->description;
            }
            if (!empty($prodser->multilangs[$outputlangs->defaultlang]["description"]) && ($textwasmodified || $translatealsoifmodified)) {
                $desc = $prodser->multilangs[$outputlangs->defaultlang]["description"];
            }
            // Set note
            $textwasmodified = $note == $prodser->note;
            if (!empty($prodser->multilangs[$outputlangs->defaultlang]["note"]) && ($textwasmodified || $translatealsoifmodified)) {
                $note = $prodser->multilangs[$outputlangs->defaultlang]["note"];
            }
        }
    }
    // Description short of product line
    $libelleproduitservice = $label;
    // Description long of product line
    if (!empty($desc) && $desc != $label) {
        if ($libelleproduitservice && empty($hidedesc)) {
            $libelleproduitservice .= '__N__';
        }
        if ($desc == '(CREDIT_NOTE)' && $object->lines[$i]->fk_remise_except) {
            $discount = new DiscountAbsolute($db);
            $discount->fetch($object->lines[$i]->fk_remise_except);
            $libelleproduitservice = $outputlangs->transnoentitiesnoconv("DiscountFromCreditNote", $discount->ref_facture_source);
        } elseif ($desc == '(DEPOSIT)' && $object->lines[$i]->fk_remise_except) {
            $discount = new DiscountAbsolute($db);
            $discount->fetch($object->lines[$i]->fk_remise_except);
            $libelleproduitservice = $outputlangs->transnoentitiesnoconv("DiscountFromDeposit", $discount->ref_facture_source);
            // Add date of deposit
            if (!empty($conf->global->INVOICE_ADD_DEPOSIT_DATE)) {
                echo ' (' . dol_print_date($discount->datec, 'day', '', $outputlangs) . ')';
            }
        } else {
            if ($idprod) {
                if (empty($hidedesc)) {
                    $libelleproduitservice .= $desc;
                }
            } else {
                $libelleproduitservice .= $desc;
            }
        }
    }
    // If line linked to a product
    if ($idprod) {
        // We add ref
        if ($prodser->ref) {
            $prefix_prodserv = "";
            $ref_prodserv = "";
            if (!empty($conf->global->PRODUCT_ADD_TYPE_IN_DOCUMENTS)) {
                if ($prodser->isService()) {
                    $prefix_prodserv = $outputlangs->transnoentitiesnoconv("Service") . " ";
                } else {
                    $prefix_prodserv = $outputlangs->transnoentitiesnoconv("Product") . " ";
                }
            }
            if (empty($hideref)) {
                if ($issupplierline) {
                    $ref_prodserv = $prodser->ref . ($ref_supplier ? ' (' . $outputlangs->transnoentitiesnoconv("SupplierRef") . ' ' . $ref_supplier . ')' : '');
                } else {
                    $ref_prodserv = $prodser->ref;
                }
                // Show local ref only
                if (!empty($libelleproduitservice)) {
                    $ref_prodserv .= " - ";
                }
            }
            $libelleproduitservice = $prefix_prodserv . $ref_prodserv . $libelleproduitservice;
        }
    }
    // Add an additional description for the category products
    if (!empty($conf->global->CATEGORY_ADD_DESC_INTO_DOC) && $idprod && !empty($conf->categorie->enabled)) {
        include_once DOL_DOCUMENT_ROOT . '/categories/class/categorie.class.php';
        $categstatic = new Categorie($db);
        // recovering the list of all the categories linked to product
        $tblcateg = $categstatic->containing($idprod, Categorie::TYPE_PRODUCT);
        foreach ($tblcateg as $cate) {
            // Adding the descriptions if they are filled
            $desccateg = $cate->add_description;
            if ($desccateg) {
                $libelleproduitservice .= '__N__' . $desccateg;
            }
        }
    }
    if (!empty($object->lines[$i]->date_start) || !empty($object->lines[$i]->date_end)) {
        $format = 'day';
        // Show duration if exists
        if ($object->lines[$i]->date_start && $object->lines[$i]->date_end) {
            $period = '(' . $outputlangs->transnoentitiesnoconv('DateFromTo', dol_print_date($object->lines[$i]->date_start, $format, false, $outputlangs), dol_print_date($object->lines[$i]->date_end, $format, false, $outputlangs)) . ')';
        }
        if ($object->lines[$i]->date_start && !$object->lines[$i]->date_end) {
            $period = '(' . $outputlangs->transnoentitiesnoconv('DateFrom', dol_print_date($object->lines[$i]->date_start, $format, false, $outputlangs)) . ')';
        }
        if (!$object->lines[$i]->date_start && $object->lines[$i]->date_end) {
            $period = '(' . $outputlangs->transnoentitiesnoconv('DateUntil', dol_print_date($object->lines[$i]->date_end, $format, false, $outputlangs)) . ')';
        }
        //print '>'.$outputlangs->charset_output.','.$period;
        $libelleproduitservice .= "__N__" . $period;
        //print $libelleproduitservice;
    }
    if ($dbatch) {
        $format = 'day';
        foreach ($dbatch as $detail) {
            $dte = array();
            if ($detail->eatby) {
                $dte[] = $outputlangs->transnoentitiesnoconv('printEatby', dol_print_date($detail->eatby, $format, false, $outputlangs));
            }
            if ($detail->sellby) {
                $dte[] = $outputlangs->transnoentitiesnoconv('printSellby', dol_print_date($detail->sellby, $format, false, $outputlangs));
            }
            if ($detail->batch) {
                $dte[] = $outputlangs->transnoentitiesnoconv('printBatch', $detail->batch);
            }
            $dte[] = $outputlangs->transnoentitiesnoconv('printQty', $detail->dluo_qty);
            $libelleproduitservice .= "__N__  " . implode($dte, "-");
        }
    }
    // Now we convert \n into br
    if (dol_textishtml($libelleproduitservice)) {
        $libelleproduitservice = preg_replace('/__N__/', '<br>', $libelleproduitservice);
    } else {
        $libelleproduitservice = preg_replace('/__N__/', "\n", $libelleproduitservice);
    }
    $libelleproduitservice = dol_htmlentitiesbr($libelleproduitservice, 1);
    return $libelleproduitservice;
}
 /**
  *	Get the form to input an email
  *  this->withfile: 0=No attaches files, 1=Show attached files, 2=Can add new attached files
  *
  *	@param	string	$addfileaction		Name of action when posting file attachments
  *	@param	string	$removefileaction	Name of action when removing file attachments
  *	@return string						Form to show
  */
 function get_form($addfileaction = 'addfile', $removefileaction = 'removefile')
 {
     global $conf, $langs, $user, $hookmanager, $form;
     if (!is_object($form)) {
         $form = new Form($this->db);
     }
     $langs->load("other");
     $langs->load("mails");
     $hookmanager->initHooks(array('formmail'));
     $parameters = array('addfileaction' => $addfileaction, 'removefileaction' => $removefileaction);
     $reshook = $hookmanager->executeHooks('getFormMail', $parameters, $this);
     if (!empty($reshook)) {
         return $hookmanager->resPrint;
     } else {
         $out = '';
         // Define list of attached files
         $listofpaths = array();
         $listofnames = array();
         $listofmimes = array();
         if (!empty($_SESSION["listofpaths"])) {
             $listofpaths = explode(';', $_SESSION["listofpaths"]);
         }
         if (!empty($_SESSION["listofnames"])) {
             $listofnames = explode(';', $_SESSION["listofnames"]);
         }
         if (!empty($_SESSION["listofmimes"])) {
             $listofmimes = explode(';', $_SESSION["listofmimes"]);
         }
         $out .= "\n<!-- Debut form mail -->\n";
         if ($this->withform == 1) {
             $out .= '<form method="POST" name="mailform" enctype="multipart/form-data" action="' . $this->param["returnurl"] . '">' . "\n";
             $out .= '<input type="hidden" name="token" value="' . $_SESSION['newtoken'] . '" />';
         }
         foreach ($this->param as $key => $value) {
             $out .= '<input type="hidden" id="' . $key . '" name="' . $key . '" value="' . $value . '" />' . "\n";
         }
         $out .= '<table class="border" width="100%">' . "\n";
         // Substitution array
         if (!empty($this->withsubstit)) {
             $out .= '<tr><td colspan="2">';
             $help = "";
             foreach ($this->substit as $key => $val) {
                 $help .= $key . ' -> ' . $langs->trans($val) . '<br>';
             }
             $out .= $form->textwithpicto($langs->trans("EMailTestSubstitutionReplacedByGenericValues"), $help);
             $out .= "</td></tr>\n";
         }
         // From
         if (!empty($this->withfrom)) {
             if (!empty($this->withfromreadonly)) {
                 $out .= '<input type="hidden" id="fromname" name="fromname" value="' . $this->fromname . '" />';
                 $out .= '<input type="hidden" id="frommail" name="frommail" value="' . $this->frommail . '" />';
                 $out .= '<tr><td width="180">' . $langs->trans("MailFrom") . '</td><td>';
                 if ($this->fromtype == 'user' && $this->fromid > 0) {
                     $langs->load("users");
                     $fuser = new User($this->db);
                     $fuser->fetch($this->fromid);
                     $out .= $fuser->getNomUrl(1);
                 } else {
                     $out .= $this->fromname;
                 }
                 if ($this->frommail) {
                     $out .= " &lt;" . $this->frommail . "&gt;";
                 } else {
                     if ($this->fromtype) {
                         $langs->load("errors");
                         $out .= '<font class="warning"> &lt;' . $langs->trans("ErrorNoMailDefinedForThisUser") . '&gt; </font>';
                     }
                 }
                 $out .= "</td></tr>\n";
                 $out .= "</td></tr>\n";
             } else {
                 $out .= "<tr><td>" . $langs->trans("MailFrom") . "</td><td>";
                 $out .= $langs->trans("Name") . ':<input type="text" id="fromname" name="fromname" size="32" value="' . $this->fromname . '" />';
                 $out .= '&nbsp; &nbsp; ';
                 $out .= $langs->trans("EMail") . ':&lt;<input type="text" id="frommail" name="frommail" size="32" value="' . $this->frommail . '" />&gt;';
                 $out .= "</td></tr>\n";
             }
         }
         // Replyto
         if (!empty($this->withreplyto)) {
             if ($this->withreplytoreadonly) {
                 $out .= '<input type="hidden" id="replyname" name="replyname" value="' . $this->replytoname . '" />';
                 $out .= '<input type="hidden" id="replymail" name="replymail" value="' . $this->replytomail . '" />';
                 $out .= "<tr><td>" . $langs->trans("MailReply") . "</td><td>" . $this->replytoname . ($this->replytomail ? " &lt;" . $this->replytomail . "&gt;" : "");
                 $out .= "</td></tr>\n";
             }
         }
         // Errorsto
         if (!empty($this->witherrorsto)) {
             //if (! $this->errorstomail) $this->errorstomail=$this->frommail;
             $errorstomail = !empty($conf->global->MAIN_MAIL_ERRORS_TO) ? $conf->global->MAIN_MAIL_ERRORS_TO : $this->errorstomail;
             if ($this->witherrorstoreadonly) {
                 $out .= '<input type="hidden" id="errorstomail" name="errorstomail" value="' . $errorstomail . '" />';
                 $out .= '<tr><td>' . $langs->trans("MailErrorsTo") . '</td><td>';
                 $out .= $errorstomail;
                 $out .= "</td></tr>\n";
             } else {
                 $out .= '<tr><td>' . $langs->trans("MailErrorsTo") . '</td><td>';
                 $out .= '<input size="30" id="errorstomail" name="errorstomail" value="' . $errorstomail . '" />';
                 $out .= "</td></tr>\n";
             }
         }
         // To
         if (!empty($this->withto) || is_array($this->withto)) {
             $out .= '<tr><td width="180">';
             if ($this->withtofree) {
                 $out .= $form->textwithpicto($langs->trans("MailTo"), $langs->trans("YouCanUseCommaSeparatorForSeveralRecipients"));
             } else {
                 $out .= $langs->trans("MailTo");
             }
             $out .= '</td><td>';
             if ($this->withtoreadonly) {
                 if (!empty($this->toname) && !empty($this->tomail)) {
                     $out .= '<input type="hidden" id="toname" name="toname" value="' . $this->toname . '" />';
                     $out .= '<input type="hidden" id="tomail" name="tomail" value="' . $this->tomail . '" />';
                     if ($this->totype == 'thirdparty') {
                         $soc = new Societe($this->db);
                         $soc->fetch($this->toid);
                         $out .= $soc->getNomUrl(1);
                     } else {
                         if ($this->totype == 'contact') {
                             $contact = new Contact($this->db);
                             $contact->fetch($this->toid);
                             $out .= $contact->getNomUrl(1);
                         } else {
                             $out .= $this->toname;
                         }
                     }
                     $out .= ' &lt;' . $this->tomail . '&gt;';
                     if ($this->withtofree) {
                         $out .= '<br>' . $langs->trans("or") . ' <input size="' . (is_array($this->withto) ? "30" : "60") . '" id="sendto" name="sendto" value="' . (!is_array($this->withto) && !is_numeric($this->withto) ? isset($_REQUEST["sendto"]) ? $_REQUEST["sendto"] : $this->withto : "") . '" />';
                     }
                 } else {
                     $out .= !is_array($this->withto) && !is_numeric($this->withto) ? $this->withto : "";
                 }
             } else {
                 if (!empty($this->withtofree)) {
                     $out .= '<input size="' . (is_array($this->withto) ? "30" : "60") . '" id="sendto" name="sendto" value="' . (!is_array($this->withto) && !is_numeric($this->withto) ? isset($_REQUEST["sendto"]) ? $_REQUEST["sendto"] : $this->withto : "") . '" />';
                 }
                 if (!empty($this->withto) && is_array($this->withto)) {
                     if (!empty($this->withtofree)) {
                         $out .= " " . $langs->trans("or") . " ";
                     }
                     $out .= $form->selectarray("receiver", $this->withto, GETPOST("receiver"), 1);
                 }
                 if (isset($this->withtosocid) && $this->withtosocid > 0) {
                     $liste = array();
                     $soc = new Societe($this->db);
                     $soc->fetch($this->withtosocid);
                     foreach ($soc->thirdparty_and_contact_email_array(1) as $key => $value) {
                         $liste[$key] = $value;
                     }
                     if ($this->withtofree) {
                         $out .= " " . $langs->trans("or") . " ";
                     }
                     $out .= $form->selectarray("receiver", $liste, GETPOST("receiver"), 1);
                 }
             }
             $out .= "</td></tr>\n";
         }
         // CC
         if (!empty($this->withtocc) || is_array($this->withtocc)) {
             $out .= '<tr><td width="180">';
             $out .= $form->textwithpicto($langs->trans("MailCC"), $langs->trans("YouCanUseCommaSeparatorForSeveralRecipients"));
             $out .= '</td><td>';
             if ($this->withtoccreadonly) {
                 $out .= !is_array($this->withtocc) && !is_numeric($this->withtocc) ? $this->withtocc : "";
             } else {
                 $out .= '<input size="' . (is_array($this->withtocc) ? "30" : "60") . '" 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"] : "")) . '" />';
                 if (!empty($this->withtocc) && is_array($this->withtocc)) {
                     $out .= " " . $langs->trans("or") . " ";
                     $out .= $form->selectarray("receivercc", $this->withtocc, GETPOST("receivercc"), 1);
                 }
             }
             $out .= "</td></tr>\n";
         }
         // CCC
         if (!empty($this->withtoccc) || is_array($this->withtoccc)) {
             $out .= '<tr><td width="180">';
             $out .= $form->textwithpicto($langs->trans("MailCCC"), $langs->trans("YouCanUseCommaSeparatorForSeveralRecipients"));
             $out .= '</td><td>';
             if (!empty($this->withtocccreadonly)) {
                 $out .= !is_array($this->withtoccc) && !is_numeric($this->withtoccc) ? $this->withtoccc : "";
             } else {
                 $out .= '<input size="' . (is_array($this->withtoccc) ? "30" : "60") . '" 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"] : "")) . '" />';
                 if (!empty($this->withtoccc) && is_array($this->withtoccc)) {
                     $out .= " " . $langs->trans("or") . " ";
                     $out .= $form->selectarray("receiverccc", $this->withtoccc, GETPOST("receiverccc"), 1);
                 }
             }
             //if (! empty($conf->global->MAIN_MAIL_AUTOCOPY_TO)) print ' '.info_admin("+ ".$conf->global->MAIN_MAIL_AUTOCOPY_TO,1);
             $out .= "</td></tr>\n";
         }
         // Ask delivery receipt
         if (!empty($this->withdeliveryreceipt)) {
             $out .= '<tr><td width="180">' . $langs->trans("DeliveryReceipt") . '</td><td>';
             if (!empty($this->withdeliveryreceiptreadonly)) {
                 $out .= yn($this->withdeliveryreceipt);
             } else {
                 $out .= $form->selectyesno('deliveryreceipt', isset($_POST["deliveryreceipt"]) ? $_POST["deliveryreceipt"] : 0, 1);
             }
             $out .= "</td></tr>\n";
         }
         // Topic
         if (!empty($this->withtopic)) {
             $this->withtopic = make_substitutions($this->withtopic, $this->substit);
             $out .= '<tr>';
             $out .= '<td width="180">' . $langs->trans("MailTopic") . '</td>';
             $out .= '<td>';
             if ($this->withtopicreadonly) {
                 $out .= $this->withtopic;
                 $out .= '<input type="hidden" size="60" id="subject" name="subject" value="' . $this->withtopic . '" />';
             } else {
                 $out .= '<input type="text" size="60" id="subject" name="subject" value="' . (isset($_POST["subject"]) ? $_POST["subject"] : (is_numeric($this->withtopic) ? '' : $this->withtopic)) . '" />';
             }
             $out .= "</td></tr>\n";
         }
         // Attached files
         if (!empty($this->withfile)) {
             $out .= '<tr>';
             $out .= '<td width="180">' . $langs->trans("MailFile") . '</td>';
             $out .= '<td>';
             if (is_numeric($this->withfile)) {
                 // TODO Trick to have param removedfile containing nb of image to delete. But this does not works without javascript
                 $out .= '<input type="hidden" class="removedfilehidden" name="removedfile" value="">' . "\n";
                 $out .= '<script type="text/javascript" language="javascript">';
                 $out .= 'jQuery(document).ready(function () {';
                 $out .= '    jQuery(".removedfile").click(function() {';
                 $out .= '        jQuery(".removedfilehidden").val(jQuery(this).val());';
                 $out .= '    });';
                 $out .= '})';
                 $out .= '</script>' . "\n";
                 if (count($listofpaths)) {
                     foreach ($listofpaths as $key => $val) {
                         $out .= '<div id="attachfile_' . $key . '">';
                         $out .= img_mime($listofnames[$key]) . ' ' . $listofnames[$key];
                         if (!$this->withfilereadonly) {
                             $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 . '" />';
                             //$out.= ' <a href="'.$_SERVER["PHP_SELF"].'?removedfile='.($key+1).' id="removedfile_'.$key.'">'.img_delete($langs->trans("Delete").'</a>';
                         }
                         $out .= '<br></div>';
                     }
                 } else {
                     $out .= $langs->trans("NoAttachedFiles") . '<br>';
                 }
                 if ($this->withfile == 2) {
                     $out .= '<input type="file" class="flat" id="addedfile" name="addedfile" value="' . $langs->trans("Upload") . '" />';
                     $out .= ' ';
                     $out .= '<input type="submit" class="button" id="' . $addfileaction . '" name="' . $addfileaction . '" value="' . $langs->trans("MailingAddFile") . '" />';
                 }
             } else {
                 $out .= $this->withfile;
             }
             $out .= "</td></tr>\n";
         }
         // Message
         if (!empty($this->withbody)) {
             $defaultmessage = "";
             // TODO    A partir du type, proposer liste de messages dans table llx_c_email_template
             if ($this->param["models"] == 'facture_send') {
                 $defaultmessage = $langs->transnoentities("PredefinedMailContentSendInvoice");
             } elseif ($this->param["models"] == 'facture_relance') {
                 $defaultmessage = $langs->transnoentities("PredefinedMailContentSendInvoiceReminder");
             } elseif ($this->param["models"] == 'propal_send') {
                 $defaultmessage = $langs->transnoentities("PredefinedMailContentSendProposal");
             } elseif ($this->param["models"] == 'order_send') {
                 $defaultmessage = $langs->transnoentities("PredefinedMailContentSendOrder");
             } elseif ($this->param["models"] == 'order_supplier_send') {
                 $defaultmessage = $langs->transnoentities("PredefinedMailContentSendSupplierOrder");
             } elseif ($this->param["models"] == 'invoice_supplier_send') {
                 $defaultmessage = $langs->transnoentities("PredefinedMailContentSendSupplierInvoice");
             } elseif ($this->param["models"] == 'shipping_send') {
                 $defaultmessage = $langs->transnoentities("PredefinedMailContentSendShipping");
             } elseif ($this->param["models"] == 'fichinter_send') {
                 $defaultmessage = $langs->transnoentities("PredefinedMailContentSendFichInter");
             } elseif ($this->param["models"] == 'thirdparty') {
                 $defaultmessage = $langs->transnoentities("PredefinedMailContentThirdparty");
             } elseif (!is_numeric($this->withbody)) {
                 $defaultmessage = $this->withbody;
             }
             // Complete substitution array
             if (!empty($conf->paypal->enabled) && !empty($conf->global->PAYPAL_ADD_PAYMENT_URL)) {
                 require_once DOL_DOCUMENT_ROOT . '/paypal/lib/paypal.lib.php';
                 $langs->load('paypal');
                 if ($this->param["models"] == 'order_send') {
                     $url = getPaypalPaymentUrl(0, 'order', $this->substit['__ORDERREF__']);
                     $this->substit['__PERSONALIZED__'] = str_replace('\\n', "\n", $langs->transnoentitiesnoconv("PredefinedMailContentLink", $url));
                 }
                 if ($this->param["models"] == 'facture_send') {
                     $url = getPaypalPaymentUrl(0, 'invoice', $this->substit['__FACREF__']);
                     $this->substit['__PERSONALIZED__'] = str_replace('\\n', "\n", $langs->transnoentitiesnoconv("PredefinedMailContentLink", $url));
                 }
             }
             $defaultmessage = str_replace('\\n', "\n", $defaultmessage);
             // Deal with format differences between message and signature (text / HTML)
             if (dol_textishtml($defaultmessage) && !dol_textishtml($this->substit['__SIGNATURE__'])) {
                 $this->substit['__SIGNATURE__'] = dol_nl2br($this->substit['__SIGNATURE__']);
             } else {
                 if (!dol_textishtml($defaultmessage) && dol_textishtml($this->substit['__SIGNATURE__'])) {
                     $defaultmessage = dol_nl2br($defaultmessage);
                 }
             }
             if (isset($_POST["message"])) {
                 $defaultmessage = $_POST["message"];
             } else {
                 $defaultmessage = make_substitutions($defaultmessage, $this->substit);
                 // Clean first \n and br (to avoid empty line when CONTACTCIVNAME is empty)
                 $defaultmessage = preg_replace("/^(<br>)+/", "", $defaultmessage);
                 $defaultmessage = preg_replace("/^\n+/", "", $defaultmessage);
             }
             $out .= '<tr>';
             $out .= '<td width="180" valign="top">' . $langs->trans("MailText") . '</td>';
             $out .= '<td>';
             if ($this->withbodyreadonly) {
                 $out .= nl2br($defaultmessage);
                 $out .= '<input type="hidden" id="message" name="message" value="' . $defaultmessage . '" />';
             } else {
                 if (!isset($this->ckeditortoolbar)) {
                     $this->ckeditortoolbar = 'dolibarr_notes';
                 }
                 // Editor wysiwyg
                 require_once DOL_DOCUMENT_ROOT . '/core/class/doleditor.class.php';
                 if ($this->withfckeditor == -1) {
                     if (!empty($conf->global->FCKEDITOR_ENABLE_MAIL)) {
                         $this->withfckeditor = 1;
                     } else {
                         $this->withfckeditor = 0;
                     }
                 }
                 $doleditor = new DolEditor('message', $defaultmessage, '', 280, $this->ckeditortoolbar, 'In', true, true, $this->withfckeditor, 8, 72);
                 $out .= $doleditor->Create(1);
             }
             $out .= "</td></tr>\n";
         }
         if ($this->withform == 1 || $this->withform == -1) {
             $out .= '<tr><td align="center" colspan="2"><center>';
             $out .= '<input class="button" type="submit" id="sendmail" name="sendmail" value="' . $langs->trans("SendMail") . '"';
             // Add a javascript test to avoid to forget to submit file before sending email
             if ($this->withfile == 2 && $conf->use_javascript_ajax) {
                 $out .= ' onClick="if (document.mailform.addedfile.value != \'\') { alert(\'' . dol_escape_js($langs->trans("FileWasNotUploaded")) . '\'); return false; } else { return true; }"';
             }
             $out .= ' />';
             if ($this->withcancel) {
                 $out .= ' &nbsp; &nbsp; ';
                 $out .= '<input class="button" type="submit" id="cancel" name="cancel" value="' . $langs->trans("Cancel") . '" />';
             }
             $out .= '</center></td></tr>' . "\n";
         }
         $out .= '</table>' . "\n";
         if ($this->withform == 1) {
             $out .= '</form>' . "\n";
         }
         $out .= "<!-- Fin form mail -->\n";
         return $out;
     }
 }
Пример #8
0
                $sendto = $conf->global->PAYPAL_PAYONLINE_SENDEMAIL;
                $from = $conf->global->MAILING_EMAIL_FROM;
                // Define $urlwithroot
                $urlwithouturlroot = preg_replace('/' . preg_quote(DOL_URL_ROOT, '/') . '$/i', '', trim($dolibarr_main_url_root));
                $urlwithroot = $urlwithouturlroot . DOL_URL_ROOT;
                // This is to use external domain name found into config file
                //$urlwithroot=DOL_MAIN_URL_ROOT;					// This is to use same domain name than current
                $urlback = $_SERVER["REQUEST_URI"];
                $topic = '[' . $conf->global->MAIN_APPLICATION_TITLE . '] ' . $langs->transnoentitiesnoconv("ValidationOfPaypalPaymentFailed");
                $content = "";
                $content .= $langs->transnoentitiesnoconv("PaypalConfirmPaymentPageWasCalledButFailed") . "\n";
                $content .= "\n";
                $content .= $langs->transnoentitiesnoconv("TechnicalInformation") . ":\n";
                $content .= $langs->transnoentitiesnoconv("ReturnURLAfterPayment") . ': ' . $urlback . "\n";
                $content .= "tag=" . $fulltag . "\ntoken=" . $token . " paymentType=" . $paymentType . " currencycodeType=" . $currencyCodeType . " payerId=" . $payerID . " ipaddress=" . $ipaddress . " FinalPaymentAmt=" . $FinalPaymentAmt;
                $ishtml = dol_textishtml($content);
                // May contain urls
                require_once DOL_DOCUMENT_ROOT . '/core/class/CMailFile.class.php';
                $mailfile = new CMailFile($topic, $sendto, $from, $content, array(), array(), array(), '', '', 0, $ishtml);
                $result = $mailfile->sendfile();
                if ($result) {
                    dol_syslog("EMail sent to " . $sendto, LOG_DEBUG, 0, '_paypal');
                } else {
                    dol_syslog("Failed to send EMail to " . $sendto, LOG_ERR, 0, '_paypal');
                }
            }
        }
    } else {
        dol_print_error('', 'Session expired');
    }
} else {
/**
 * 	Send email
 *
 * 	@param	string	$mode			Mode (test | confirm)
 *  @param	string	$oldemail		Target email
 * 	@param	string	$message		Message to send
 * 	@param	string	$total			Total amount of unpayed invoices
 *  @param	string	$userlang		Code lang to use for email output.
 *  @param	string	$oldtarget		Target name
 * 	@return	int						<0 if KO, >0 if OK
 */
function envoi_mail($mode, $oldemail, $message, $total, $userlang, $oldtarget)
{
    global $conf, $langs;
    if (getenv('DOL_FORCE_EMAIL_TO')) {
        $oldemail = getenv('DOL_FORCE_EMAIL_TO');
    }
    $newlangs = new Translate('', $conf);
    $newlangs->setDefaultLang(empty($userlang) ? empty($conf->global->MAIN_LANG_DEFAULT) ? 'auto' : $conf->global->MAIN_LANG_DEFAULT : $userlang);
    $newlangs->load("main");
    $newlangs->load("bills");
    $subject = empty($conf->global->SCRIPT_EMAIL_UNPAID_INVOICES_CUSTOMERS_SUBJECT) ? $newlangs->trans("ListOfYourUnpaidInvoices") : $conf->global->SCRIPT_EMAIL_UNPAID_INVOICES_CUSTOMERS_SUBJECT;
    $sendto = $oldemail;
    $from = $conf->global->MAIN_MAIL_EMAIL_FROM;
    $errorsto = $conf->global->MAIN_MAIL_ERRORS_TO;
    $msgishtml = -1;
    print "- Send email to '" . $oldtarget . "' (" . $oldemail . "), total: " . $total . "\n";
    dol_syslog("email_unpaid_invoices_to_customers.php: send mail to " . $oldemail);
    $usehtml = 0;
    if (dol_textishtml($conf->global->SCRIPT_EMAIL_UNPAID_INVOICES_CUSTOMERS_FOOTER)) {
        $usehtml += 1;
    }
    if (dol_textishtml($conf->global->SCRIPT_EMAIL_UNPAID_INVOICES_CUSTOMERS_HEADER)) {
        $usehtml += 1;
    }
    $allmessage = '';
    if (!empty($conf->global->SCRIPT_EMAIL_UNPAID_INVOICES_CUSTOMERS_HEADER)) {
        $allmessage .= $conf->global->SCRIPT_EMAIL_UNPAID_INVOICES_CUSTOMERS_HEADER;
    } else {
        $allmessage .= "Dear customer" . ($usehtml ? "<br>\n" : "\n") . ($usehtml ? "<br>\n" : "\n");
        $allmessage .= "Please, find a summary of the bills with pending payments from you." . ($usehtml ? "<br>\n" : "\n") . ($usehtml ? "<br>\n" : "\n");
        $allmessage .= "Note: This list contains only unpaid invoices." . ($usehtml ? "<br>\n" : "\n");
    }
    $allmessage .= $message . ($usehtml ? "<br>\n" : "\n");
    $allmessage .= $langs->trans("Total") . " = " . price($total, 0, $userlang, 0, 0, -1, $conf->currency) . ($usehtml ? "<br>\n" : "\n");
    if (!empty($conf->global->SCRIPT_EMAIL_UNPAID_INVOICES_CUSTOMERS_FOOTER)) {
        $allmessage .= $conf->global->SCRIPT_EMAIL_UNPAID_INVOICES_CUSTOMERS_FOOTER;
        if (dol_textishtml($conf->global->SCRIPT_EMAIL_UNPAID_INVOICES_CUSTOMERS_FOOTER)) {
            $usehtml += 1;
        }
    }
    $mail = new CMailFile($subject, $sendto, $from, $allmessage, array(), array(), array(), '', '', 0, $msgishtml);
    $mail->errors_to = $errorsto;
    // Send or not email
    if ($mode == 'confirm') {
        $result = $mail->sendfile();
        if (!$result) {
            print "Error sending email " . $mail->error . "\n";
            dol_syslog("Error sending email " . $mail->error . "\n");
        }
    } else {
        print "No email sent (test mode)\n";
        dol_syslog("No email sent (test mode)");
        $mail->dump_mail();
        $result = 1;
    }
    unset($newlangs);
    if ($result) {
        return 1;
    } else {
        return -1;
    }
}
if (!empty($conf->global->MAIN_AUTO_TIMESTAMP_IN_PUBLIC_NOTES)) {
    $stringtoadd = dol_print_date(dol_now(), 'dayhour') . ' ' . $user->getFullName($langs) . ' --';
    if (GETPOST('action') == 'edit' . $note_public) {
        $value_public = dol_concatdesc($value_public, ($value_public ? "\n" : "") . "-- " . $stringtoadd);
        if (dol_textishtml($value_public)) {
            $value_public .= "<br>\n";
        } else {
            $value_public .= "\n";
        }
    }
}
if (!empty($conf->global->MAIN_AUTO_TIMESTAMP_IN_PRIVATE_NOTES)) {
    $stringtoadd = dol_print_date(dol_now(), 'dayhour') . ' ' . $user->getFullName($langs) . ' --';
    if (GETPOST('action') == 'edit' . $note_private) {
        $value_private = dol_concatdesc($value_private, ($value_private ? "\n" : "") . "-- " . $stringtoadd);
        if (dol_textishtml($value_private)) {
            $value_private .= "<br>\n";
        } else {
            $value_private .= "\n";
        }
    }
}
// Special cases
if ($module == 'propal') {
    $permission = $user->rights->propale->creer;
} elseif ($module == 'fichinter') {
    $permission = $user->rights->ficheinter->creer;
} elseif ($module == 'project') {
    $permission = $user->rights->projet->creer;
} elseif ($module == 'project_task') {
    $permission = $user->rights->projet->creer;
Пример #11
0
/**
 *  Return line description translated in outputlangs and encoded into htmlentities and with <br>
 *
 *  @param  Object		$object              Object
 *  @param  int			$i                   Current line number (0 = first line, 1 = second line, ...)
 *  @param  Translate	$outputlangs         Object langs for output
 *  @param  int			$hideref             Hide reference
 *  @param  int			$hidedesc            Hide description
 *  @param  int			$issupplierline      Is it a line for a supplier object ?
 *  @return string       				     String with line
 */
function pdf_getlinedesc($object, $i, $outputlangs, $hideref = 0, $hidedesc = 0, $issupplierline = 0)
{
    global $db, $conf, $langs;
    $idprod = !empty($object->lines[$i]->fk_product) ? $object->lines[$i]->fk_product : false;
    $label = !empty($object->lines[$i]->label) ? $object->lines[$i]->label : (!empty($object->lines[$i]->libelle) ? $object->lines[$i]->libelle : '');
    $desc = !empty($object->lines[$i]->desc) ? $object->lines[$i]->desc : (!empty($object->lines[$i]->description) ? $object->lines[$i]->description : '');
    $ref_supplier = !empty($object->lines[$i]->ref_supplier) ? $object->lines[$i]->ref_supplier : (!empty($object->lines[$i]->ref_fourn) ? $object->lines[$i]->ref_fourn : '');
    // TODO Not yet saved for supplier invoices, only supplier orders
    $note = !empty($object->lines[$i]->note) ? $object->lines[$i]->note : '';
    if ($issupplierline) {
        $prodser = new ProductFournisseur($db);
    } else {
        $prodser = new Product($db);
    }
    if ($idprod) {
        $prodser->fetch($idprod);
        // If a predefined product and multilang and on other lang, we renamed label with label translated
        if ($conf->global->MAIN_MULTILANGS && $outputlangs->defaultlang != $langs->defaultlang) {
            if (!empty($prodser->multilangs[$outputlangs->defaultlang]["libelle"]) && $label == $prodser->label) {
                $label = $prodser->multilangs[$outputlangs->defaultlang]["libelle"];
            }
            if (!empty($prodser->multilangs[$outputlangs->defaultlang]["description"]) && $desc == $prodser->description) {
                $desc = $prodser->multilangs[$outputlangs->defaultlang]["description"];
            }
            if (!empty($prodser->multilangs[$outputlangs->defaultlang]["note"]) && $note == $prodser->note) {
                $note = $prodser->multilangs[$outputlangs->defaultlang]["note"];
            }
        }
    }
    // Description short of product line
    $libelleproduitservice = $label;
    // Description long of product line
    if ($desc && $desc != $label) {
        if ($libelleproduitservice && empty($hidedesc)) {
            $libelleproduitservice .= '__N__';
        }
        if ($desc == '(CREDIT_NOTE)' && $object->lines[$i]->fk_remise_except) {
            $discount = new DiscountAbsolute($db);
            $discount->fetch($object->lines[$i]->fk_remise_except);
            $libelleproduitservice = $outputlangs->transnoentitiesnoconv("DiscountFromCreditNote", $discount->ref_facture_source);
        } elseif ($desc == '(DEPOSIT)' && $object->lines[$i]->fk_remise_except) {
            $discount = new DiscountAbsolute($db);
            $discount->fetch($object->lines[$i]->fk_remise_except);
            $libelleproduitservice = $outputlangs->transnoentitiesnoconv("DiscountFromDeposit", $discount->ref_facture_source);
            // Add date of deposit
            if (!empty($conf->global->INVOICE_ADD_DEPOSIT_DATE)) {
                echo ' (' . dol_print_date($discount->datec, 'day', '', $outputlangs) . ')';
            }
        } else {
            if ($idprod) {
                if (empty($hidedesc)) {
                    $libelleproduitservice .= $desc;
                }
            } else {
                $libelleproduitservice .= $desc;
            }
        }
    }
    // If line linked to a product
    if ($idprod) {
        // On ajoute la ref
        if ($prodser->ref) {
            $prefix_prodserv = "";
            $ref_prodserv = "";
            if (!empty($conf->global->PRODUCT_ADD_TYPE_IN_DOCUMENTS)) {
                if ($prodser->isservice()) {
                    $prefix_prodserv = $outputlangs->transnoentitiesnoconv("Service") . " ";
                } else {
                    $prefix_prodserv = $outputlangs->transnoentitiesnoconv("Product") . " ";
                }
            }
            if (empty($hideref)) {
                if ($issupplierline) {
                    $ref_prodserv = $prodser->ref . ' (' . $outputlangs->transnoentitiesnoconv("SupplierRef") . ' ' . $ref_supplier . ')';
                } else {
                    $ref_prodserv = $prodser->ref;
                }
                // Show local ref only
                $ref_prodserv .= " - ";
            }
            $libelleproduitservice = $prefix_prodserv . $ref_prodserv . $libelleproduitservice;
        }
    }
    if (!empty($object->lines[$i]->date_start) || !empty($object->lines[$i]->date_end)) {
        $format = 'day';
        // Show duration if exists
        if ($object->lines[$i]->date_start && $object->lines[$i]->date_end) {
            $period = '(' . $outputlangs->transnoentitiesnoconv('DateFromTo', dol_print_date($object->lines[$i]->date_start, $format, false, $outputlangs), dol_print_date($object->lines[$i]->date_end, $format, false, $outputlangs)) . ')';
        }
        if ($object->lines[$i]->date_start && !$object->lines[$i]->date_end) {
            $period = '(' . $outputlangs->transnoentitiesnoconv('DateFrom', dol_print_date($object->lines[$i]->date_start, $format, false, $outputlangs)) . ')';
        }
        if (!$object->lines[$i]->date_start && $object->lines[$i]->date_end) {
            $period = '(' . $outputlangs->transnoentitiesnoconv('DateUntil', dol_print_date($object->lines[$i]->date_end, $format, false, $outputlangs)) . ')';
        }
        //print '>'.$outputlangs->charset_output.','.$period;
        $libelleproduitservice .= "__N__" . $period;
        //print $libelleproduitservice;
    }
    // Now we convert \n into br
    if (dol_textishtml($libelleproduitservice)) {
        $libelleproduitservice = preg_replace('/__N__/', '<br>', $libelleproduitservice);
    } else {
        $libelleproduitservice = preg_replace('/__N__/', "\n", $libelleproduitservice);
    }
    $libelleproduitservice = dol_htmlentitiesbr($libelleproduitservice, 1);
    return $libelleproduitservice;
}
Пример #12
0
    /**
     * testDolTextIsHtml
     *
     * @return void
     */
    public function testDolTextIsHtml()
    {
        // True
        $input='<html>xxx</html>';
        $after=dol_textishtml($input);
        $this->assertTrue($after);
        $input='<body>xxx</body>';
        $after=dol_textishtml($input);
        $this->assertTrue($after);
        $input='xxx <b>yyy</b> zzz';
        $after=dol_textishtml($input);
        $this->assertTrue($after);
        $input='xxx<br>';
        $after=dol_textishtml($input);
        $this->assertTrue($after);
        $input='text with <div>some div</div>';
        $after=dol_textishtml($input);
        $this->assertTrue($after);
        $input='text with HTML &nbsp; entities';
        $after=dol_textishtml($input);
        $this->assertTrue($after);

        // False
        $input='xxx < br>';
        $after=dol_textishtml($input);
        $this->assertFalse($after);
    }
    /**
     *	Get the form to input an email
     *  this->withfile: 0=No attaches files, 1=Show attached files, 2=Can add new attached files
     *  this->param:	Contains more parameteres like email templates info
     *
     *	@param	string	$addfileaction		Name of action when posting file attachments
     *	@param	string	$removefileaction	Name of action when removing file attachments
     *	@return string						Form to show
     */
    function get_form($addfileaction = 'addfile', $removefileaction = 'removefile')
    {
        global $conf, $langs, $user, $hookmanager, $form;
        if (!is_object($form)) {
            $form = new Form($this->db);
        }
        $langs->load("other");
        $langs->load("mails");
        $hookmanager->initHooks(array('formmail'));
        $parameters = array('addfileaction' => $addfileaction, 'removefileaction' => $removefileaction);
        $reshook = $hookmanager->executeHooks('getFormMail', $parameters, $this);
        if (!empty($reshook)) {
            return $hookmanager->resPrint;
        } else {
            $out = '';
            // Define list of attached files
            $listofpaths = array();
            $listofnames = array();
            $listofmimes = array();
            if (!empty($_SESSION["listofpaths"])) {
                $listofpaths = explode(';', $_SESSION["listofpaths"]);
            }
            if (!empty($_SESSION["listofnames"])) {
                $listofnames = explode(';', $_SESSION["listofnames"]);
            }
            if (!empty($_SESSION["listofmimes"])) {
                $listofmimes = explode(';', $_SESSION["listofmimes"]);
            }
            // Define output language
            $outputlangs = $langs;
            $newlang = '';
            if ($conf->global->MAIN_MULTILANGS && empty($newlang)) {
                $newlang = $this->param['langsmodels'];
            }
            if (!empty($newlang)) {
                $outputlangs = new Translate("", $conf);
                $outputlangs->setDefaultLang($newlang);
                $outputlangs->load('other');
            }
            // Get message template
            $model_id = 0;
            if (array_key_exists('models_id', $this->param)) {
                $model_id = $this->param["models_id"];
            }
            $arraydefaultmessage = $this->getEMailTemplate($this->db, $this->param["models"], $user, $outputlangs, $model_id);
            //var_dump($arraydefaultmessage);
            $out .= "\n<!-- Begin form mail -->\n";
            if ($this->withform == 1) {
                $out .= '<form method="POST" name="mailform" id="mailform" enctype="multipart/form-data" action="' . $this->param["returnurl"] . '#formmail">' . "\n";
                $out .= '<input style="display:none" type="submit" id="sendmail" name="sendmail">';
                $out .= '<input type="hidden" name="token" value="' . $_SESSION['newtoken'] . '" />';
                $out .= '<input type="hidden" name="trackid" value="' . $this->trackid . '" />';
                $out .= '<a id="formmail" name="formmail"></a>';
            }
            foreach ($this->param as $key => $value) {
                $out .= '<input type="hidden" id="' . $key . '" name="' . $key . '" value="' . $value . '" />' . "\n";
            }
            $result = $this->fetchAllEMailTemplate($this->param["models"], $user, $outputlangs);
            if ($result < 0) {
                setEventMessage($this->error, 'errors');
            }
            $modelmail_array = array();
            foreach ($this->lines_model as $line) {
                $modelmail_array[$line->id] = $line->label;
            }
            // Zone to select its email template
            if (count($modelmail_array) > 0) {
                $out .= '<div style="padding: 3px 0 3px 0">' . "\n";
                $out .= $langs->trans('SelectMailModel') . ': ' . $this->selectarray('modelmailselected', $modelmail_array, 0, 1);
                if ($user->admin) {
                    $out .= info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"), 1);
                }
                $out .= ' &nbsp; ';
                $out .= '<input class="button" type="submit" value="' . $langs->trans('Valid') . '" name="modelselected" id="modelselected">';
                $out .= ' &nbsp; ';
                $out .= '</div>';
            }
            $out .= '<table class="border" width="100%">' . "\n";
            // Substitution array
            if (!empty($this->withsubstit)) {
                $out .= '<tr><td colspan="2">';
                $help = "";
                foreach ($this->substit as $key => $val) {
                    $help .= $key . ' -> ' . $langs->trans($val) . '<br>';
                }
                $out .= $form->textwithpicto($langs->trans("EMailTestSubstitutionReplacedByGenericValues"), $help);
                $out .= "</td></tr>\n";
            }
            // From
            if (!empty($this->withfrom)) {
                if (!empty($this->withfromreadonly)) {
                    $out .= '<input type="hidden" id="fromname" name="fromname" value="' . $this->fromname . '" />';
                    $out .= '<input type="hidden" id="frommail" name="frommail" value="' . $this->frommail . '" />';
                    $out .= '<tr><td width="180">' . $langs->trans("MailFrom") . '</td><td>';
                    if ($this->fromtype == 'user' && $this->fromid > 0) {
                        $langs->load("users");
                        $fuser = new User($this->db);
                        $fuser->fetch($this->fromid);
                        $out .= $fuser->getNomUrl(1);
                    } else {
                        $out .= $this->fromname;
                    }
                    if ($this->frommail) {
                        $out .= " &lt;" . $this->frommail . "&gt;";
                    } else {
                        if ($this->fromtype) {
                            $langs->load("errors");
                            $out .= '<font class="warning"> &lt;' . $langs->trans("ErrorNoMailDefinedForThisUser") . '&gt; </font>';
                        }
                    }
                    $out .= "</td></tr>\n";
                    $out .= "</td></tr>\n";
                } else {
                    $out .= "<tr><td>" . $langs->trans("MailFrom") . "</td><td>";
                    $out .= $langs->trans("Name") . ':<input type="text" id="fromname" name="fromname" size="32" value="' . $this->fromname . '" />';
                    $out .= '&nbsp; &nbsp; ';
                    $out .= $langs->trans("EMail") . ':&lt;<input type="text" id="frommail" name="frommail" size="32" value="' . $this->frommail . '" />&gt;';
                    $out .= "</td></tr>\n";
                }
            }
            // Replyto
            if (!empty($this->withreplyto)) {
                if ($this->withreplytoreadonly) {
                    $out .= '<input type="hidden" id="replyname" name="replyname" value="' . $this->replytoname . '" />';
                    $out .= '<input type="hidden" id="replymail" name="replymail" value="' . $this->replytomail . '" />';
                    $out .= "<tr><td>" . $langs->trans("MailReply") . "</td><td>" . $this->replytoname . ($this->replytomail ? " &lt;" . $this->replytomail . "&gt;" : "");
                    $out .= "</td></tr>\n";
                }
            }
            // Errorsto
            if (!empty($this->witherrorsto)) {
                //if (! $this->errorstomail) $this->errorstomail=$this->frommail;
                $errorstomail = !empty($conf->global->MAIN_MAIL_ERRORS_TO) ? $conf->global->MAIN_MAIL_ERRORS_TO : $this->errorstomail;
                if ($this->witherrorstoreadonly) {
                    $out .= '<input type="hidden" id="errorstomail" name="errorstomail" value="' . $errorstomail . '" />';
                    $out .= '<tr><td>' . $langs->trans("MailErrorsTo") . '</td><td>';
                    $out .= $errorstomail;
                    $out .= "</td></tr>\n";
                } else {
                    $out .= '<tr><td>' . $langs->trans("MailErrorsTo") . '</td><td>';
                    $out .= '<input size="30" id="errorstomail" name="errorstomail" value="' . $errorstomail . '" />';
                    $out .= "</td></tr>\n";
                }
            }
            // To
            if (!empty($this->withto) || is_array($this->withto)) {
                $out .= '<tr><td width="180">';
                if ($this->withtofree) {
                    $out .= $form->textwithpicto($langs->trans("MailTo"), $langs->trans("YouCanUseCommaSeparatorForSeveralRecipients"));
                } else {
                    $out .= $langs->trans("MailTo");
                }
                $out .= '</td><td>';
                if ($this->withtoreadonly) {
                    if (!empty($this->toname) && !empty($this->tomail)) {
                        $out .= '<input type="hidden" id="toname" name="toname" value="' . $this->toname . '" />';
                        $out .= '<input type="hidden" id="tomail" name="tomail" value="' . $this->tomail . '" />';
                        if ($this->totype == 'thirdparty') {
                            $soc = new Societe($this->db);
                            $soc->fetch($this->toid);
                            $out .= $soc->getNomUrl(1);
                        } else {
                            if ($this->totype == 'contact') {
                                $contact = new Contact($this->db);
                                $contact->fetch($this->toid);
                                $out .= $contact->getNomUrl(1);
                            } else {
                                $out .= $this->toname;
                            }
                        }
                        $out .= ' &lt;' . $this->tomail . '&gt;';
                        if ($this->withtofree) {
                            $out .= '<br>' . $langs->trans("or") . ' <input size="' . (is_array($this->withto) ? "30" : "60") . '" id="sendto" name="sendto" value="' . (!is_array($this->withto) && !is_numeric($this->withto) ? isset($_REQUEST["sendto"]) ? $_REQUEST["sendto"] : $this->withto : "") . '" />';
                        }
                    } else {
                        $out .= !is_array($this->withto) && !is_numeric($this->withto) ? $this->withto : "";
                    }
                } else {
                    if (!empty($this->withtofree)) {
                        $out .= '<input size="' . (is_array($this->withto) ? "30" : "60") . '" id="sendto" name="sendto" value="' . (!is_array($this->withto) && !is_numeric($this->withto) ? isset($_REQUEST["sendto"]) ? $_REQUEST["sendto"] : $this->withto : "") . '" />';
                    }
                    if (!empty($this->withto) && is_array($this->withto)) {
                        if (!empty($this->withtofree)) {
                            $out .= " " . $langs->trans("or") . " ";
                        }
                        $out .= $form->selectarray("receiver", $this->withto, GETPOST("receiver"), 1);
                    }
                    if (isset($this->withtosocid) && $this->withtosocid > 0) {
                        $liste = array();
                        $soc = new Societe($this->db);
                        $soc->fetch($this->withtosocid);
                        foreach ($soc->thirdparty_and_contact_email_array(1) as $key => $value) {
                            $liste[$key] = $value;
                        }
                        if ($this->withtofree) {
                            $out .= " " . $langs->trans("or") . " ";
                        }
                        $out .= $form->selectarray("receiver", $liste, GETPOST("receiver"), 1);
                    }
                }
                $out .= "</td></tr>\n";
            }
            // CC
            if (!empty($this->withtocc) || is_array($this->withtocc)) {
                $out .= '<tr><td width="180">';
                $out .= $form->textwithpicto($langs->trans("MailCC"), $langs->trans("YouCanUseCommaSeparatorForSeveralRecipients"));
                $out .= '</td><td>';
                if ($this->withtoccreadonly) {
                    $out .= !is_array($this->withtocc) && !is_numeric($this->withtocc) ? $this->withtocc : "";
                } else {
                    $out .= '<input size="' . (is_array($this->withtocc) ? "30" : "60") . '" 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"] : "")) . '" />';
                    if (!empty($this->withtocc) && is_array($this->withtocc)) {
                        $out .= " " . $langs->trans("or") . " ";
                        $out .= $form->selectarray("receivercc", $this->withtocc, GETPOST("receivercc"), 1);
                    }
                }
                $out .= "</td></tr>\n";
            }
            // CCC
            if (!empty($this->withtoccc) || is_array($this->withtoccc)) {
                $out .= '<tr><td width="180">';
                $out .= $form->textwithpicto($langs->trans("MailCCC"), $langs->trans("YouCanUseCommaSeparatorForSeveralRecipients"));
                $out .= '</td><td>';
                if (!empty($this->withtocccreadonly)) {
                    $out .= !is_array($this->withtoccc) && !is_numeric($this->withtoccc) ? $this->withtoccc : "";
                } else {
                    $out .= '<input size="' . (is_array($this->withtoccc) ? "30" : "60") . '" 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"] : "")) . '" />';
                    if (!empty($this->withtoccc) && is_array($this->withtoccc)) {
                        $out .= " " . $langs->trans("or") . " ";
                        $out .= $form->selectarray("receiverccc", $this->withtoccc, GETPOST("receiverccc"), 1);
                    }
                }
                $showinfobcc = '';
                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;
                }
                if (!empty($conf->global->MAIN_MAIL_AUTOCOPY_ASKPRICESUPPLIER_TO) && !empty($this->param['models']) && $this->param['models'] == 'askpricesupplier_send') {
                    $showinfobcc = $conf->global->MAIN_MAIL_AUTOCOPY_ASKPRICESUPPLIER_TO;
                }
                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;
                }
                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;
                }
                if ($showinfobcc) {
                    $out .= ' + ' . $showinfobcc;
                }
                $out .= "</td></tr>\n";
            }
            // Ask delivery receipt
            if (!empty($this->withdeliveryreceipt)) {
                $out .= '<tr><td width="180">' . $langs->trans("DeliveryReceipt") . '</td><td>';
                if (!empty($this->withdeliveryreceiptreadonly)) {
                    $out .= yn($this->withdeliveryreceipt);
                } else {
                    $defaultvaluefordeliveryreceipt = 0;
                    if (!empty($conf->global->MAIL_FORCE_DELIVERY_RECEIPT_PROPAL) && !empty($this->param['models']) && $this->param['models'] == 'propal_send') {
                        $defaultvaluefordeliveryreceipt = 1;
                    }
                    if (!empty($conf->global->MAIL_FORCE_DELIVERY_RECEIPT_ASKPRICESUPPLIER) && !empty($this->param['models']) && $this->param['models'] == 'askpricesupplier_send') {
                        $defaultvaluefordeliveryreceipt = 1;
                    }
                    if (!empty($conf->global->MAIL_FORCE_DELIVERY_RECEIPT_ORDER) && !empty($this->param['models']) && $this->param['models'] == 'order_send') {
                        $defaultvaluefordeliveryreceipt = 1;
                    }
                    if (!empty($conf->global->MAIL_FORCE_DELIVERY_RECEIPT_INVOICE) && !empty($this->param['models']) && $this->param['models'] == 'facture_send') {
                        $defaultvaluefordeliveryreceipt = 1;
                    }
                    $out .= $form->selectyesno('deliveryreceipt', isset($_POST["deliveryreceipt"]) ? $_POST["deliveryreceipt"] : $defaultvaluefordeliveryreceipt, 1);
                }
                $out .= "</td></tr>\n";
            }
            // Topic
            if (!empty($this->withtopic)) {
                $defaulttopic = "";
                if (count($arraydefaultmessage) > 0 && $arraydefaultmessage['topic']) {
                    $defaulttopic = $arraydefaultmessage['topic'];
                } elseif (!is_numeric($this->withtopic)) {
                    $defaulttopic = $this->withtopic;
                }
                $defaulttopic = make_substitutions($defaulttopic, $this->substit);
                $out .= '<tr>';
                $out .= '<td width="180">' . $langs->trans("MailTopic") . '</td>';
                $out .= '<td>';
                if ($this->withtopicreadonly) {
                    $out .= $defaulttopic;
                    $out .= '<input type="hidden" size="60" id="subject" name="subject" value="' . $defaulttopic . '" />';
                } else {
                    $out .= '<input type="text" size="60" id="subject" name="subject" value="' . (isset($_POST["subject"]) && !$_POST['modelselected'] ? $_POST["subject"] : ($defaulttopic ? $defaulttopic : '')) . '" />';
                }
                $out .= "</td></tr>\n";
            }
            // Attached files
            if (!empty($this->withfile)) {
                $out .= '<tr>';
                $out .= '<td width="180">' . $langs->trans("MailFile") . '</td>';
                $out .= '<td>';
                if (is_numeric($this->withfile)) {
                    // TODO Trick to have param removedfile containing nb of image to delete. But this does not works without javascript
                    $out .= '<input type="hidden" class="removedfilehidden" name="removedfile" value="">' . "\n";
                    $out .= '<script type="text/javascript" language="javascript">';
                    $out .= 'jQuery(document).ready(function () {';
                    $out .= '    jQuery(".removedfile").click(function() {';
                    $out .= '        jQuery(".removedfilehidden").val(jQuery(this).val());';
                    $out .= '    });';
                    $out .= '})';
                    $out .= '</script>' . "\n";
                    if (count($listofpaths)) {
                        foreach ($listofpaths as $key => $val) {
                            $out .= '<div id="attachfile_' . $key . '">';
                            $out .= img_mime($listofnames[$key]) . ' ' . $listofnames[$key];
                            if (!$this->withfilereadonly) {
                                $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 . '" />';
                                //$out.= ' <a href="'.$_SERVER["PHP_SELF"].'?removedfile='.($key+1).' id="removedfile_'.$key.'">'.img_delete($langs->trans("Delete").'</a>';
                            }
                            $out .= '<br></div>';
                        }
                    } else {
                        $out .= $langs->trans("NoAttachedFiles") . '<br>';
                    }
                    if ($this->withfile == 2) {
                        $out .= '<input type="file" class="flat" id="addedfile" name="addedfile" value="' . $langs->trans("Upload") . '" />';
                        $out .= ' ';
                        $out .= '<input type="submit" class="button" id="' . $addfileaction . '" name="' . $addfileaction . '" value="' . $langs->trans("MailingAddFile") . '" />';
                    }
                } else {
                    $out .= $this->withfile;
                }
                $out .= "</td></tr>\n";
            }
            // Message
            if (!empty($this->withbody)) {
                $defaultmessage = "";
                if (count($arraydefaultmessage) > 0 && $arraydefaultmessage['content']) {
                    $defaultmessage = $arraydefaultmessage['content'];
                } elseif (!is_numeric($this->withbody)) {
                    $defaultmessage = $this->withbody;
                }
                // Complete substitution array
                if (!empty($conf->paypal->enabled) && !empty($conf->global->PAYPAL_ADD_PAYMENT_URL)) {
                    require_once DOL_DOCUMENT_ROOT . '/paypal/lib/paypal.lib.php';
                    $langs->load('paypal');
                    if ($this->param["models"] == 'order_send') {
                        $url = getPaypalPaymentUrl(0, 'order', $this->substit['__ORDERREF__']);
                        $this->substit['__PERSONALIZED__'] = str_replace('\\n', "\n", $langs->transnoentitiesnoconv("PredefinedMailContentLink", $url));
                    }
                    if ($this->param["models"] == 'facture_send') {
                        $url = getPaypalPaymentUrl(0, 'invoice', $this->substit['__FACREF__']);
                        $this->substit['__PERSONALIZED__'] = str_replace('\\n', "\n", $langs->transnoentitiesnoconv("PredefinedMailContentLink", $url));
                    }
                }
                $defaultmessage = str_replace('\\n', "\n", $defaultmessage);
                // Deal with format differences between message and signature (text / HTML)
                if (dol_textishtml($defaultmessage) && !dol_textishtml($this->substit['__SIGNATURE__'])) {
                    $this->substit['__SIGNATURE__'] = dol_nl2br($this->substit['__SIGNATURE__']);
                } else {
                    if (!dol_textishtml($defaultmessage) && dol_textishtml($this->substit['__SIGNATURE__'])) {
                        $defaultmessage = dol_nl2br($defaultmessage);
                    }
                }
                if (isset($_POST["message"]) && !$_POST['modelselected']) {
                    $defaultmessage = $_POST["message"];
                } else {
                    $defaultmessage = make_substitutions($defaultmessage, $this->substit);
                    // Clean first \n and br (to avoid empty line when CONTACTCIVNAME is empty)
                    $defaultmessage = preg_replace("/^(<br>)+/", "", $defaultmessage);
                    $defaultmessage = preg_replace("/^\n+/", "", $defaultmessage);
                }
                $out .= '<tr>';
                $out .= '<td width="180" valign="top">' . $langs->trans("MailText") . '</td>';
                $out .= '<td>';
                if ($this->withbodyreadonly) {
                    $out .= nl2br($defaultmessage);
                    $out .= '<input type="hidden" id="message" name="message" value="' . $defaultmessage . '" />';
                } else {
                    if (!isset($this->ckeditortoolbar)) {
                        $this->ckeditortoolbar = 'dolibarr_notes';
                    }
                    // Editor wysiwyg
                    require_once DOL_DOCUMENT_ROOT . '/core/class/doleditor.class.php';
                    if ($this->withfckeditor == -1) {
                        if (!empty($conf->global->FCKEDITOR_ENABLE_MAIL)) {
                            $this->withfckeditor = 1;
                        } else {
                            $this->withfckeditor = 0;
                        }
                    }
                    $doleditor = new DolEditor('message', $defaultmessage, '', 280, $this->ckeditortoolbar, 'In', true, true, $this->withfckeditor, 8, 72);
                    $out .= $doleditor->Create(1);
                }
                $out .= "</td></tr>\n";
            }
            if ($this->withform == 1 || $this->withform == -1) {
                $out .= '<tr><td align="center" colspan="2"><div class="center">';
                $out .= '<input class="button" type="submit" id="sendmail" name="sendmail" value="' . $langs->trans("SendMail") . '"';
                // Add a javascript test to avoid to forget to submit file before sending email
                if ($this->withfile == 2 && $conf->use_javascript_ajax) {
                    $out .= ' onClick="if (document.mailform.addedfile.value != \'\') { alert(\'' . dol_escape_js($langs->trans("FileWasNotUploaded")) . '\'); return false; } else { return true; }"';
                }
                $out .= ' />';
                if ($this->withcancel) {
                    $out .= ' &nbsp; &nbsp; ';
                    $out .= '<input class="button" type="submit" id="cancel" name="cancel" value="' . $langs->trans("Cancel") . '" />';
                }
                $out .= '</div></td></tr>' . "\n";
            }
            $out .= '</table>' . "\n";
            if ($this->withform == 1) {
                $out .= '</form>' . "\n";
            }
            // Disable enter key if option MAIN_MAILFORM_DISABLE_ENTERKEY is set
            if (!empty($conf->global->MAIN_MAILFORM_DISABLE_ENTERKEY)) {
                $out .= '<script type="text/javascript" language="javascript">';
                $out .= 'jQuery(document).ready(function () {';
                $out .= '	$(document).on("keypress", \'#mailform\', function (e) {		/* Note this is calle at every key pressed ! */
	    						var code = e.keyCode || e.which;
	    						if (code == 13) {
	        						e.preventDefault();
	        						return false;
	    						}
							});';
                $out .= '		})';
                $out .= '</script>';
            }
            $out .= "<!-- End form mail -->\n";
            return $out;
        }
    }
Пример #14
0
print '<tr><td>';
$adresseadmin = $object->mail_admin;
print $langs->trans("Title") . '</td><td colspan="2">';
if ($action == 'edit') {
    print '<input type="text" name="nouveautitre" style="width: 95%" value="' . dol_escape_htmltag(dol_htmlentities($object->titre)) . '">';
} else {
    print dol_htmlentities($object->titre);
}
print '</td></tr>';
// Description
print '<tr><td class="tdtop">' . $langs->trans("Description") . '</td><td colspan="2">';
if ($action == 'edit') {
    $doleditor = new DolEditor('nouveauxcommentaires', dol_htmlentities($object->commentaires), '', 120, 'dolibarr_notes', 'In', 1, 1, 1, ROWS_7, 120);
    $doleditor->Create(0, '');
} else {
    print dol_textishtml($object->commentaires) ? $object->commentaires : dol_nl2br($object->commentaires, 1, true);
}
print '</td></tr>';
// EMail
//If linked user, then emails are going to be sent to users' email
if (!$object->fk_user_creat) {
    print '<tr><td>' . $langs->trans("EMail") . '</td><td colspan="2">';
    if ($action == 'edit') {
        print '<input type="text" name="nouvelleadresse" size="40" value="' . $object->mail_admin . '">';
    } else {
        print dol_print_email($object->mail_admin, 0, 0, 1);
    }
    print '</td></tr>';
}
// Receive an email with each vote
print '<tr><td>' . $langs->trans('ToReceiveEMailForEachVote') . '</td><td colspan="2">';
Пример #15
0
         $newlang = '';
         if (empty($newlang) && GETPOST('lang_id')) {
             $newlang = GETPOST('lang_id');
         }
         if (empty($newlang)) {
             $newlang = $object->client->default_lang;
         }
         if (!empty($newlang)) {
             $outputlangs = new Translate("", $conf);
             $outputlangs->setDefaultLang($newlang);
         }
         $desc = !empty($prod->multilangs[$outputlangs->defaultlang]["description"]) ? $prod->multilangs[$outputlangs->defaultlang]["description"] : $prod->description;
     } else {
         $desc = $prod->description;
     }
     $desc .= $desc && GETPOST('np_desc') ? dol_textishtml($desc) || dol_textishtml(GETPOST('np_desc')) ? "<br />\n" : "\n" : "";
     $desc .= GETPOST('np_desc');
     $type = $prod->type;
 } else {
     $pu_ht = GETPOST('np_price');
     $tva_tx = str_replace('*', '', GETPOST('np_tva_tx'));
     $tva_npr = preg_match('/\\*/', GETPOST('np_tva_tx')) ? 1 : 0;
     $desc = GETPOST('dp_desc');
     $type = GETPOST('type');
 }
 // Local Taxes
 $localtax1_tx = get_localtax($tva_tx, 1, $object->client);
 $localtax2_tx = get_localtax($tva_tx, 2, $object->client);
 $desc = dol_htmlcleanlastbr($desc);
 // ajout prix achat
 $fk_fournprice = GETPOST('np_fournprice');
Пример #16
0
    print '<tr '.$bc[$var].'><td valign="top">'.$langs->trans("Note").'</td>';
    print '<td valign="top">';
    if ($action == 'edit' && $user->rights->societe->creer)
    {
        print '<input type="hidden" name="action" value="add" />';
        print '<input type="hidden" name="socid" value="'.$object->id.'" />';

        // Editeur wysiwyg
        require_once(DOL_DOCUMENT_ROOT."/core/class/doleditor.class.php");
        $doleditor=new DolEditor('note',$object->note,'',360,'dolibarr_notes','In',true,false,$conf->global->FCKEDITOR_ENABLE_SOCIETE,20,70);
        $doleditor->Create();
    }
    else
    {
        print dol_textishtml($object->note)?$object->note:dol_nl2br($object->note,1,true);
    }
    print "</td></tr>";
    $var=!$var;

    print "</table>";

    if ($action == 'edit')
    {
        print '<center><br>';
        print '<input type="submit" class="button" name="save" value="'.$langs->trans("Save").'">';
        print ' &nbsp; ';
        print '<input type="submit" class="button" name="cancel" value="'.$langs->trans("Cancel").'">';
        print '</center>';
    }
Пример #17
0
 /**
  * Make substitution of tags into text with value of current object.
  *
  * @param	string	$text       Text to make substitution to
  * @return  string      		Value of input text string with substitutions done
  */
 function makeSubstitution($text)
 {
     global $conf, $langs;
     $birthday = dol_print_date($this->birth, 'day');
     $msgishtml = 0;
     if (dol_textishtml($text, 1)) {
         $msgishtml = 1;
     }
     $infos = '';
     if ($this->civility_id) {
         $infos .= $langs->transnoentities("UserTitle") . ": " . $this->getCivilityLabel() . "\n";
     }
     $infos .= $langs->transnoentities("id") . ": " . $this->id . "\n";
     $infos .= $langs->transnoentities("Lastname") . ": " . $this->lastname . "\n";
     $infos .= $langs->transnoentities("Firstname") . ": " . $this->firstname . "\n";
     $infos .= $langs->transnoentities("Company") . ": " . $this->societe . "\n";
     $infos .= $langs->transnoentities("Address") . ": " . $this->address . "\n";
     $infos .= $langs->transnoentities("Zip") . ": " . $this->zip . "\n";
     $infos .= $langs->transnoentities("Town") . ": " . $this->town . "\n";
     $infos .= $langs->transnoentities("Country") . ": " . $this->country . "\n";
     $infos .= $langs->transnoentities("EMail") . ": " . $this->email . "\n";
     if (empty($conf->global->ADHERENT_LOGIN_NOT_REQUIRED)) {
         $infos .= $langs->transnoentities("Login") . ": " . $this->login . "\n";
         $infos .= $langs->transnoentities("Password") . ": " . $this->pass . "\n";
     }
     $infos .= $langs->transnoentities("Birthday") . ": " . $birthday . "\n";
     $infos .= $langs->transnoentities("Photo") . ": " . $this->photo . "\n";
     $infos .= $langs->transnoentities("Public") . ": " . yn($this->public);
     // Substitutions
     $substitutionarray = array('%DOL_MAIN_URL_ROOT%' => DOL_MAIN_URL_ROOT, '%ID%' => $msgishtml ? dol_htmlentitiesbr($this->id) : $this->id, '%CIVILITY%' => $this->getCivilityLabel(), '%FIRSTNAME%' => $msgishtml ? dol_htmlentitiesbr($this->firstname) : $this->firstname, '%LASTNAME%' => $msgishtml ? dol_htmlentitiesbr($this->lastname) : $this->lastname, '%FULLNAME%' => $msgishtml ? dol_htmlentitiesbr($this->getFullName($langs)) : $this->getFullName($langs), '%COMPANY%' => $msgishtml ? dol_htmlentitiesbr($this->societe) : $this->societe, '%ADDRESS%' => $msgishtml ? dol_htmlentitiesbr($this->address) : $this->address, '%ZIP%' => $msgishtml ? dol_htmlentitiesbr($this->zip) : $this->zip, '%TOWN%' => $msgishtml ? dol_htmlentitiesbr($this->town) : $this->town, '%COUNTRY%' => $msgishtml ? dol_htmlentitiesbr($this->country) : $this->country, '%EMAIL%' => $msgishtml ? dol_htmlentitiesbr($this->email) : $this->email, '%BIRTH%' => $msgishtml ? dol_htmlentitiesbr($birthday) : $birthday, '%PHOTO%' => $msgishtml ? dol_htmlentitiesbr($this->photo) : $this->photo, '%LOGIN%' => $msgishtml ? dol_htmlentitiesbr($this->login) : $this->login, '%PASSWORD%' => $msgishtml ? dol_htmlentitiesbr($this->pass) : $this->pass, '%INFOS%' => $msgishtml ? dol_htmlentitiesbr($infos) : $infos, '%SOCIETE%' => $msgishtml ? dol_htmlentitiesbr($this->societe) : $this->societe, '%PRENOM%' => $msgishtml ? dol_htmlentitiesbr($this->firstname) : $this->firstname, '%NOM%' => $msgishtml ? dol_htmlentitiesbr($this->lastname) : $this->lastname, '%CP%' => $msgishtml ? dol_htmlentitiesbr($this->zip) : $this->zip, '%VILLE%' => $msgishtml ? dol_htmlentitiesbr($this->town) : $this->town, '%PAYS%' => $msgishtml ? dol_htmlentitiesbr($this->country) : $this->country);
     // Add extrafields as substitution key %EXTRA_XXX%
     foreach ($this->array_options as $key => $val) {
         $keyshort = preg_replace('/^(options|extra)_/', '', $key);
         $substitutionarray['%EXTRA_' . $keyshort . '%'] = $val;
     }
     complete_substitutions_array($substitutionarray, $langs);
     return make_substitutions($text, $substitutionarray);
 }
Пример #18
0
 /**
  *	Get object from database
  *
  *	@param	int		$rowid      Id of emailing
  *	@return	int					<0 if KO, >0 if OK
  */
 function fetch($rowid)
 {
     global $conf;
     $sql = "SELECT m.rowid, m.titre, m.sujet, m.body, m.bgcolor, m.bgimage";
     $sql .= ", m.email_from, m.email_replyto, m.email_errorsto";
     $sql .= ", m.statut, m.nbemail";
     $sql .= ", m.fk_user_creat, m.fk_user_valid";
     $sql .= ", m.date_creat";
     $sql .= ", m.date_valid";
     $sql .= ", m.date_envoi";
     $sql .= ", m.extraparams";
     $sql .= " FROM " . MAIN_DB_PREFIX . "mailing as m";
     $sql .= " WHERE m.rowid = " . $rowid;
     dol_syslog(get_class($this) . "::fetch", LOG_DEBUG);
     $result = $this->db->query($sql);
     if ($result) {
         if ($this->db->num_rows($result)) {
             $obj = $this->db->fetch_object($result);
             $this->id = $obj->rowid;
             $this->ref = $obj->rowid;
             $this->statut = $obj->statut;
             $this->nbemail = $obj->nbemail;
             $this->titre = $obj->titre;
             $this->sujet = $obj->sujet;
             if (!empty($conf->global->FCKEDITOR_ENABLE_MAILING) && dol_textishtml(dol_html_entity_decode($obj->body, ENT_COMPAT | ENT_HTML401))) {
                 $this->body = dol_html_entity_decode($obj->body, ENT_COMPAT | ENT_HTML401);
             } else {
                 $this->body = $obj->body;
             }
             $this->bgcolor = $obj->bgcolor;
             $this->bgimage = $obj->bgimage;
             $this->email_from = $obj->email_from;
             $this->email_replyto = $obj->email_replyto;
             $this->email_errorsto = $obj->email_errorsto;
             $this->user_creat = $obj->fk_user_creat;
             $this->user_valid = $obj->fk_user_valid;
             $this->date_creat = $this->db->jdate($obj->date_creat);
             $this->date_valid = $this->db->jdate($obj->date_valid);
             $this->date_envoi = $this->db->jdate($obj->date_envoi);
             $this->extraparams = (array) json_decode($obj->extraparams, true);
             return 1;
         } else {
             dol_syslog(get_class($this) . "::fetch Erreur -1");
             return -1;
         }
     } else {
         dol_syslog(get_class($this) . "::fetch Erreur -2");
         return -2;
     }
 }
Пример #19
0
                {
                    $pu_ttc = price2num($pu_ht * (1 + ($tva_tx/100)), 'MU');
                }
            }

            $desc = $prod->description;
            $desc.= ($prod->description && $_POST['np_desc']) ? ((dol_textishtml($prod->description) || dol_textishtml($_POST['np_desc']))?"<br>\n":"\n") : "";
            $desc.= $_POST['np_desc'];
            if (! empty($prod->customcode) || ! empty($prod->country_code))
            {
                $tmptxt='(';
                if (! empty($prod->customcode)) $tmptxt.=$langs->transnoentitiesnoconv("CustomCode").': '.$prod->customcode;
                if (! empty($prod->customcode) && ! empty($prod->country_code)) $tmptxt.=' - ';
                if (! empty($prod->country_code)) $tmptxt.=$langs->transnoentitiesnoconv("CountryOrigin").': '.getCountry($prod->country_code,0,$db,$langs,0);
                $tmptxt.=')';
                $desc.= (dol_textishtml($desc)?"<br>\n":"\n").$tmptxt;
            }
            $type = $prod->type;
        }
        else
        {
            $pu_ht=$_POST['np_price'];
            $tva_tx=str_replace('*','',$_POST['np_tva_tx']);
            $tva_npr=preg_match('/\*/',$_POST['np_tva_tx'])?1:0;
            $desc=$_POST['dp_desc'];
            $type=$_POST["type"];
        }

        $localtax1_tx=get_localtax($tva_tx,1,$object->client);
        $localtax2_tx=get_localtax($tva_tx,2,$object->client);
Пример #20
0
 /**
  * Make substitution
  * @param       text        Text to make substitution to
  * @return      string      Value of input text string with substitutions done
  */
 function makeSubstitution($text)
 {
     global $langs;
     $birthday = dol_print_date($this->naiss, 'day');
     $msgishtml = 0;
     if (dol_textishtml($text, 1)) {
         $msgishtml = 1;
     }
     $infos = '';
     if ($this->civilite_id) {
         $infos .= $langs->transnoentities("UserTitle") . ": " . $this->getCivilityLabel(1) . "\n";
     }
     $infos .= $langs->transnoentities("id") . ": " . $this->id . "\n";
     $infos .= $langs->transnoentities("Lastname") . ": " . $this->nom . "\n";
     $infos .= $langs->transnoentities("Firstname") . ": " . $this->prenom . "\n";
     $infos .= $langs->transnoentities("Company") . ": " . $this->societe . "\n";
     $infos .= $langs->transnoentities("Address") . ": " . $this->adresse . "\n";
     $infos .= $langs->transnoentities("Zip") . ": " . $this->cp . "\n";
     $infos .= $langs->transnoentities("Town") . ": " . $this->ville . "\n";
     $infos .= $langs->transnoentities("Country") . ": " . $this->pays . "\n";
     $infos .= $langs->transnoentities("EMail") . ": " . $this->email . "\n";
     $infos .= $langs->transnoentities("Login") . ": " . $this->login . "\n";
     $infos .= $langs->transnoentities("Password") . ": " . $this->pass . "\n";
     $infos .= $langs->transnoentities("Birthday") . ": " . $birthday . "\n";
     $infos .= $langs->transnoentities("Photo") . ": " . $this->photo . "\n";
     $infos .= $langs->transnoentities("Public") . ": " . yn($this->public);
     // Substitutions
     $substitutionarray = array('%DOL_MAIN_URL_ROOT%' => DOL_MAIN_URL_ROOT, '%ID%' => $msgishtml ? dol_htmlentitiesbr($this->id) : $this->id, '%INFOS%' => $msgishtml ? dol_htmlentitiesbr($infos) : $infos, '%CIVILITE%' => $this->getCivilityLabel($msgishtml ? 0 : 1), '%PRENOM%' => $msgishtml ? dol_htmlentitiesbr($this->prenom) : $this->prenom, '%NOM%' => $msgishtml ? dol_htmlentitiesbr($this->nom) : $this->nom, '%SOCIETE%' => $msgishtml ? dol_htmlentitiesbr($this->societe) : $this->societe, '%ADRESSE%' => $msgishtml ? dol_htmlentitiesbr($this->adresse) : $this->adresse, '%CP%' => $msgishtml ? dol_htmlentitiesbr($this->cp) : $this->cp, '%VILLE%' => $msgishtml ? dol_htmlentitiesbr($this->ville) : $this->ville, '%PAYS%' => $msgishtml ? dol_htmlentitiesbr($this->pays) : $this->pays, '%EMAIL%' => $msgishtml ? dol_htmlentitiesbr($this->email) : $this->email, '%NAISS%' => $msgishtml ? dol_htmlentitiesbr($birthday) : $birthday, '%PHOTO%' => $msgishtml ? dol_htmlentitiesbr($this->photo) : $this->photo, '%LOGIN%' => $msgishtml ? dol_htmlentitiesbr($this->login) : $this->login, '%PASSWORD%' => $msgishtml ? dol_htmlentitiesbr($this->pass) : $this->pass);
     complete_substitutions_array($substitutionarray, $langs);
     return make_substitutions($text, $substitutionarray);
 }
Пример #21
0
                // Other attributes
                $parameters = array('colspan' => ' colspan="' . (2 + ($showphoto || $showbarcode ? 1 : 0)) . '"');
                $reshook = $hookmanager->executeHooks('formObjectOptions', $parameters, $object, $action);
                // Note that $action and $object may have been modified by hook
                if (empty($reshook) && !empty($extrafields->attribute_label)) {
                    print $object->showOptionals($extrafields);
                }
                // Categories
                if ($conf->categorie->enabled) {
                    print '<tr><td valign="middle">' . $langs->trans("Categories") . '</td><td colspan="3">';
                    print $form->showCategories($object->id, 'product', 1);
                    print "</td></tr>";
                }
                // Note
                print '<!-- show Note --> ' . "\n";
                print '<tr><td class="tdtop">' . $langs->trans("Note") . '</td><td colspan="' . (2 + ($showphoto || $showbarcode ? 1 : 0)) . '">' . (dol_textishtml($object->note) ? $object->note : dol_nl2br($object->note, 1, true)) . '</td></tr>' . "\n";
                print '<!-- End show Note --> ' . "\n";
                print "</table>\n";
                print '</div>';
                print '</div></div>';
                print '<div style="clear:both"></div>';
                dol_fiche_end();
            }
        } else {
            if ($action != 'create') {
                exit;
            }
        }
    }
}
// Load object modCodeProduct
/**
 * 	Send email
 *
 * 	@param	string	$mode			Mode (test | confirm)
 *  @param	string	$oldemail		Target email
 * 	@param	string	$message		Message to send
 * 	@param	string	$total			Total amount of unpayed invoices
 *  @param	string	$userlang		Code lang to use for email output.
 *  @param	string	$oldtarget		Target name
 *  @param  int		$duration_value	duration value
 * 	@return	int						<0 if KO, >0 if OK
 */
function envoi_mail($mode, $oldemail, $message, $total, $userlang, $oldtarget, $duration_value)
{
    global $conf, $langs;
    if (getenv('DOL_FORCE_EMAIL_TO')) {
        $oldemail = getenv('DOL_FORCE_EMAIL_TO');
    }
    $newlangs = new Translate('', $conf);
    $newlangs->setDefaultLang(empty($userlang) ? empty($conf->global->MAIN_LANG_DEFAULT) ? 'auto' : $conf->global->MAIN_LANG_DEFAULT : $userlang);
    $newlangs->load("main");
    $newlangs->load("contracts");
    if ($duration_value) {
        if ($duration_value > 0) {
            $title = $newlangs->transnoentities("ListOfServicesToExpireWithDuration", $duration_value);
        } else {
            $title = $newlangs->transnoentities("ListOfServicesToExpireWithDurationNeg", $duration_value);
        }
    } else {
        $title = $newlangs->transnoentities("ListOfServicesToExpire");
    }
    $subject = empty($conf->global->SCRIPT_EMAIL_EXPIRE_SERVICES_CUSTOMERS_SUBJECT) ? $title : $conf->global->SCRIPT_EMAIL_EXPIRE_SERVICES_CUSTOMERS_SUBJECT;
    $sendto = $oldemail;
    $from = $conf->global->MAIN_MAIL_EMAIL_FROM;
    $errorsto = $conf->global->MAIN_MAIL_ERRORS_TO;
    $msgishtml = -1;
    print "- Send email to '" . $oldtarget . "' (" . $oldemail . "), total: " . $total . "\n";
    dol_syslog("email_expire_services_to_customers.php: send mail to " . $oldemail);
    $usehtml = 0;
    if (dol_textishtml($conf->global->SCRIPT_EMAIL_EXPIRE_SERVICES_CUSTOMERS_FOOTER)) {
        $usehtml += 1;
    }
    if (dol_textishtml($conf->global->SCRIPT_EMAIL_EXPIRE_SERVICES_CUSTOMERS_HEADER)) {
        $usehtml += 1;
    }
    $allmessage = '';
    if (!empty($conf->global->SCRIPT_EMAIL_EXPIRE_SERVICES_CUSTOMERS_HEADER)) {
        $allmessage .= $conf->global->SCRIPT_EMAIL_EXPIRE_SERVICES_CUSTOMERS_HEADER;
    } else {
        $allmessage .= "Dear customer" . ($usehtml ? "<br>\n" : "\n") . ($usehtml ? "<br>\n" : "\n");
        $allmessage .= "Please, find a summary of the services contracted by you that are about to expire." . ($usehtml ? "<br>\n" : "\n") . ($usehtml ? "<br>\n" : "\n");
    }
    $allmessage .= $message . ($usehtml ? "<br>\n" : "\n");
    //$allmessage.= $langs->trans("Total")." = ".price($total,0,$userlang,0,0,-1,$conf->currency).($usehtml?"<br>\n":"\n");
    if (!empty($conf->global->SCRIPT_EMAIL_EXPIRE_SERVICES_CUSTOMERS_FOOTER)) {
        $allmessage .= $conf->global->SCRIPT_EMAIL_EXPIRE_SERVICES_CUSTOMERS_FOOTER;
        if (dol_textishtml($conf->global->SCRIPT_EMAIL_EXPIRE_SERVICES_CUSTOMERS_FOOTER)) {
            $usehtml += 1;
        }
    }
    $mail = new CMailFile($subject, $sendto, $from, $allmessage, array(), array(), array(), '', '', 0, $msgishtml);
    $mail->errors_to = $errorsto;
    // Send or not email
    if ($mode == 'confirm') {
        $result = $mail->sendfile();
        if (!$result) {
            print "Error sending email " . $mail->error . "\n";
            dol_syslog("Error sending email " . $mail->error . "\n");
        }
    } else {
        print "No email sent (test mode)\n";
        dol_syslog("No email sent (test mode)");
        $mail->dump_mail();
        $result = 1;
    }
    unset($newlangs);
    if ($result) {
        return 1;
    } else {
        return -1;
    }
}
Пример #23
0
         $pu_ht = $prod->price;
         $pu_ttc = $prod->price_ttc;
         $price_min = $prod->price_min;
         $price_base_type = $prod->price_base_type;
     }
     // On reevalue prix selon taux tva car taux tva transaction peut etre different
     // de ceux du produit par defaut (par exemple si pays different entre vendeur et acheteur).
     if ($tva_tx != $prod->tva_tx) {
         if ($price_base_type != 'HT') {
             $pu_ht = price2num($pu_ttc / (1 + $tva_tx / 100), 'MU');
         } else {
             $pu_ttc = price2num($pu_ht * (1 + $tva_tx / 100), 'MU');
         }
     }
     $desc = $prod->description;
     $desc .= $prod->description && $_POST['np_desc'] ? dol_textishtml($prod->description) || dol_textishtml($_POST['np_desc']) ? "<br />\n" : "\n" : "";
     $desc .= $_POST['np_desc'];
     $type = $prod->type;
 } else {
     $pu_ht = $_POST['np_price'];
     $tva_tx = str_replace('*', '', $_POST['np_tva_tx']);
     $tva_npr = preg_match('/\\*/', $_POST['np_tva_tx']) ? 1 : 0;
     $desc = $_POST['dp_desc'];
     $type = $_POST["type"];
 }
 // Local Taxes
 $localtax1_tx = get_localtax($tva_tx, 1, $object->client);
 $localtax2_tx = get_localtax($tva_tx, 2, $object->client);
 $desc = dol_htmlcleanlastbr($desc);
 $info_bits = 0;
 if ($tva_npr) {
Пример #24
0
    print '<tr><td valign="top">'.$langs->trans("Note").'</td>';
    print '<td valign="top">';
    if ($action == 'edit' && $user->rights->societe->creer)
    {
        print "<input type=\"hidden\" name=\"action\" value=\"add\">";
        print "<input type=\"hidden\" name=\"socid\" value=\"".$societe->id."\">";

        // Editeur wysiwyg
        require_once(DOL_DOCUMENT_ROOT."/lib/doleditor.class.php");
        $doleditor=new DolEditor('note',$societe->note,'',360,'dolibarr_notes','In',true,false,$conf->fckeditor->enabled && $conf->global->FCKEDITOR_ENABLE_SOCIETE,20,70);
        $doleditor->Create();
    }
    else
    {
        print dol_textishtml($societe->note)?$societe->note:dol_nl2br($societe->note,1,true);
    }
    print "</td></tr>";

    if ($action == 'edit')
    {
        print '<tr><td colspan="2" align="center">';
        print '<input type="submit" class="button" name="save" value="'.$langs->trans("Save").'">';
        print ' &nbsp; ';
        print '<input type="submit" class="button" name="cancel" value="'.$langs->trans("Cancel").'">';
        print '</td></tr>';
    }

    print "</table>";

    print '</form>';
/**
 * 	Send email
 *
 * 	@param	string	$mode					Mode (test | confirm)
 *  @param	string	$oldemail				Old email
 * 	@param	string	$message				Message to send
 * 	@param	string	$total					Total amount of unpayed invoices
 *  @param	string	$userlang				Code lang to use for email output.
 *  @param	string	$oldsalerepresentative	Old sale representative
 * 	@return	int								<0 if KO, >0 if OK
 */
function envoi_mail($mode, $oldemail, $message, $total, $userlang, $oldsalerepresentative)
{
    global $conf, $langs;
    if (getenv('DOL_FORCE_EMAIL_TO')) {
        $oldemail = getenv('DOL_FORCE_EMAIL_TO');
    }
    $newlangs = new Translate('', $conf);
    $newlangs->setDefaultLang(empty($userlang) ? empty($conf->global->MAIN_LANG_DEFAULT) ? 'auto' : $conf->global->MAIN_LANG_DEFAULT : $userlang);
    $newlangs->load("main");
    $newlangs->load("bills");
    $subject = empty($conf->global->SCRIPT_EMAIL_UNPAID_INVOICES_SALESREPRESENTATIVES_SUBJECT) ? $newlangs->trans("ListOfYourUnpaidInvoices") : $conf->global->SCRIPT_EMAIL_UNPAID_INVOICES_SALESREPRESENTATIVES_SUBJECT;
    $sendto = $oldemail;
    $from = $conf->global->MAIN_MAIL_EMAIL_FROM;
    $errorsto = $conf->global->MAIN_MAIL_ERRORS_TO;
    $msgishtml = -1;
    print "- Send email for " . $oldsalerepresentative . " (" . $oldemail . "), total: " . $total . "\n";
    dol_syslog("email_unpaid_invoices_to_representatives.php: send mail to " . $oldemail);
    $usehtml = 0;
    if (dol_textishtml($conf->global->SCRIPT_EMAIL_UNPAID_INVOICES_SALESREPRESENTATIVES_FOOTER)) {
        $usehtml += 1;
    }
    if (dol_textishtml($conf->global->SCRIPT_EMAIL_UNPAID_INVOICES_SALESREPRESENTATIVES_HEADER)) {
        $usehtml += 1;
    }
    $allmessage = '';
    if (!empty($conf->global->SCRIPT_EMAIL_UNPAID_INVOICES_SALESREPRESENTATIVES_HEADER)) {
        $allmessage .= $conf->global->SCRIPT_EMAIL_UNPAID_INVOICES_SALESREPRESENTATIVES_HEADER;
    } else {
        $allmessage .= $newlangs->transnoentities("ListOfYourUnpaidInvoices") . ($usehtml ? "<br>\n" : "\n") . ($usehtml ? "<br>\n" : "\n");
        $allmessage .= $newlangs->transnoentities("NoteListOfYourUnpaidInvoices") . ($usehtml ? "<br>\n" : "\n");
    }
    $allmessage .= $message . ($usehtml ? "<br>\n" : "\n");
    $allmessage .= $langs->trans("Total") . " = " . price($total, 0, $newlangs, 0, 0, -1, $conf->currency) . ($usehtml ? "<br>\n" : "\n");
    if (!empty($conf->global->SCRIPT_EMAIL_UNPAID_INVOICES_SALESREPRESENTATIVES_FOOTER)) {
        $allmessage .= $conf->global->SCRIPT_EMAIL_UNPAID_INVOICES_SALESREPRESENTATIVES_FOOTER;
        if (dol_textishtml($conf->global->SCRIPT_EMAIL_UNPAID_INVOICES_SALESREPRESENTATIVES_FOOTER)) {
            $usehtml += 1;
        }
    }
    $mail = new CMailFile($subject, $sendto, $from, $allmessage, array(), array(), array(), '', '', 0, $msgishtml);
    $mail->errors_to = $errorsto;
    // Send or not email
    if ($mode == 'confirm') {
        $result = $mail->sendfile();
        if (!$result) {
            print "Error sending email " . $mail->error . "\n";
            dol_syslog("Error sending email " . $mail->error . "\n");
        }
    } else {
        print "No email sent (test mode)\n";
        dol_syslog("No email sent (test mode)");
        $mail->dump_mail();
        $result = 1;
    }
    if ($result) {
        return 1;
    } else {
        return -1;
    }
}
Пример #26
0
 /**
  * Function to convert a HTML string into an ODT string
  *
  * @param	string	$value	String to convert
  */
 public function htmlToUTFAndPreOdf($value)
 {
     // We decode into utf8, entities
     $value = dol_html_entity_decode($value, ENT_QUOTES);
     // We convert html tags
     $ishtml = dol_textishtml($value);
     if ($ishtml) {
         // If string is "MYPODUCT - Desc <strong>bold</strong> with &eacute; accent<br />\n<br />\nUn texto en espa&ntilde;ol ?"
         // Result after clean must be "MYPODUCT - Desc bold with é accent\n\nUn texto en espa&ntilde;ol ?"
         // We want to ignore \n and we want all <br> to be \n
         $value = preg_replace('/(\\r\\n|\\r|\\n)/i', '', $value);
         $value = preg_replace('/<br>/i', "\n", $value);
         $value = preg_replace('/<br\\s+[^<>\\/]*>/i', "\n", $value);
         $value = preg_replace('/<br\\s+[^<>\\/]*\\/>/i', "\n", $value);
         //$value=preg_replace('/<strong>/','__lt__text:p text:style-name=__quot__bold__quot____gt__',$value);
         //$value=preg_replace('/<\/strong>/','__lt__/text:p__gt__',$value);
         $value = dol_string_nohtmltag($value, 0);
     }
     return $value;
 }
 /**
  *	CMailFile
  *
  *	@param 	string	$subject             Topic/Subject of mail
  *	@param 	string	$to                  Recipients emails (RFC 2822: "Nom firstname <email>[, ...]" ou "email[, ...]" ou "<email>[, ...]")
  *	@param 	string	$from                Sender email      (RFC 2822: "Nom firstname <email>[, ...]" ou "email[, ...]" ou "<email>[, ...]")
  *	@param 	string	$msg                 Message
  *	@param 	array	$filename_list       List of files to attach (full path of filename on file system)
  *	@param 	array	$mimetype_list       List of MIME type of attached files
  *	@param 	array	$mimefilename_list   List of attached file name in message
  *	@param 	string	$addr_cc             Email cc
  *	@param 	string	$addr_bcc            Email bcc (Note: This is autocompleted with MAIN_MAIL_AUTOCOPY_TO if defined)
  *	@param 	int		$deliveryreceipt     Ask a delivery receipt
  *	@param 	int		$msgishtml           1=String IS already html, 0=String IS NOT html, -1=Unknown make autodetection (with fast mode, not reliable)
  *	@param 	string	$errors_to      	 Email errors
  *	@param	string	$css                 Css option
  */
 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 = '')
 {
     global $conf;
     // We define end of line (RFC 821).
     $this->eol = "\r\n";
     // We define end of line for header fields (RFC 822bis section 2.3 says header must contains \r\n).
     $this->eol2 = "\r\n";
     if (!empty($conf->global->MAIN_FIX_FOR_BUGGED_MTA)) {
         $this->eol = "\n";
         $this->eol2 = "\n";
     }
     // On defini mixed_boundary
     $this->mixed_boundary = "multipart_x." . time() . ".x_boundary";
     // On defini related_boundary
     $this->related_boundary = 'mul_' . dol_hash(uniqid("dolibarr2"));
     // On defini alternative_boundary
     $this->alternative_boundary = 'mul_' . dol_hash(uniqid("dolibarr3"));
     // If ending method not defined
     if (empty($conf->global->MAIN_MAIL_SENDMODE)) {
         $conf->global->MAIN_MAIL_SENDMODE = 'mail';
     }
     dol_syslog("CMailFile::CMailfile: MAIN_MAIL_SENDMODE=" . $conf->global->MAIN_MAIL_SENDMODE . " charset=" . $conf->file->character_set_client . " from={$from}, to={$to}, addr_cc={$addr_cc}, addr_bcc={$addr_bcc}, errors_to={$errors_to}", LOG_DEBUG);
     dol_syslog("CMailFile::CMailfile: subject={$subject}, deliveryreceipt={$deliveryreceipt}, msgishtml={$msgishtml}", LOG_DEBUG);
     // Detect if message is HTML (use fast method)
     if ($msgishtml == -1) {
         $this->msgishtml = 0;
         if (dol_textishtml($msg)) {
             $this->msgishtml = 1;
         }
     } else {
         $this->msgishtml = $msgishtml;
     }
     // Detect images
     if ($this->msgishtml) {
         $this->html = $msg;
         $findimg = $this->findHtmlImages($conf->fckeditor->dir_output);
         // Define if there is at least one file
         if ($findimg) {
             foreach ($this->html_images as $i => $val) {
                 if ($this->html_images[$i]) {
                     $this->atleastoneimage = 1;
                     dol_syslog("CMailFile::CMailfile: html_images[{$i}]['name']=" . $this->html_images[$i]['name'], LOG_DEBUG);
                 }
             }
         }
     }
     // Define if there is at least one file
     foreach ($filename_list as $i => $val) {
         if ($filename_list[$i]) {
             $this->atleastonefile = 1;
             dol_syslog("CMailFile::CMailfile: filename_list[{$i}]=" . $filename_list[$i] . ", mimetype_list[{$i}]=" . $mimetype_list[$i] . " mimefilename_list[{$i}]=" . $mimefilename_list[$i], LOG_DEBUG);
         }
     }
     // Add autocopy to
     if (!empty($conf->global->MAIN_MAIL_AUTOCOPY_TO)) {
         $addr_bcc .= ($addr_bcc ? ', ' : '') . $conf->global->MAIN_MAIL_AUTOCOPY_TO;
     }
     // Action according to choosed sending method
     if ($conf->global->MAIN_MAIL_SENDMODE == 'mail') {
         // Use mail php function (default PHP method)
         // ------------------------------------------
         $smtp_headers = "";
         $mime_headers = "";
         $text_body = "";
         $files_encoded = "";
         // Define smtp_headers
         $this->subject = $subject;
         $this->addr_from = $from;
         $this->errors_to = $errors_to;
         $this->addr_to = $to;
         $this->addr_cc = $addr_cc;
         $this->addr_bcc = $addr_bcc;
         $this->deliveryreceipt = $deliveryreceipt;
         $smtp_headers = $this->write_smtpheaders();
         // Define mime_headers
         $mime_headers = $this->write_mimeheaders($filename_list, $mimefilename_list);
         if (!empty($this->html)) {
             if (!empty($css)) {
                 $this->css = $css;
                 $this->buildCSS();
                 // Build a css style (mode = all) into this->styleCSS and this->bodyCSS
             }
             $msg = $this->html;
         }
         // Define body in text_body
         $text_body = $this->write_body($msg);
         // Encode images
         $images_encoded = '';
         if ($this->atleastoneimage) {
             $images_encoded .= $this->write_images($this->images_encoded);
             // always end related and end alternative after inline images
             $images_encoded .= "--" . $this->related_boundary . "--" . $this->eol;
             $images_encoded .= $this->eol . "--" . $this->alternative_boundary . "--" . $this->eol;
             $images_encoded .= $this->eol;
         }
         // Add attachments to text_encoded
         if ($this->atleastonefile) {
             $files_encoded = $this->write_files($filename_list, $mimetype_list, $mimefilename_list);
         }
         // We now define $this->headers and $this->message
         $this->headers = $smtp_headers . $mime_headers;
         // On nettoie le header pour qu'il ne se termine pas par un retour chariot.
         // Ceci evite aussi les lignes vides en fin qui peuvent etre interpretees
         // comme des injections mail par les serveurs de messagerie.
         $this->headers = preg_replace("/([\r\n]+)\$/i", "", $this->headers);
         $this->message = 'This is a message with multiple parts in MIME format.' . $this->eol;
         $this->message .= $text_body . $images_encoded . $files_encoded;
         $this->message .= "--" . $this->mixed_boundary . "--" . $this->eol;
     } else {
         if ($conf->global->MAIN_MAIL_SENDMODE == 'smtps') {
             // Use SMTPS library
             // ------------------------------------------
             require_once DOL_DOCUMENT_ROOT . '/core/class/smtps.class.php';
             $smtps = new SMTPs();
             $smtps->setCharSet($conf->file->character_set_client);
             $smtps->setSubject($this->encodetorfc2822($subject));
             $smtps->setTO($this->getValidAddress($to, 0, 1));
             $smtps->setFrom($this->getValidAddress($from, 0, 1));
             if (!empty($this->html)) {
                 if (!empty($css)) {
                     $this->css = $css;
                     $this->buildCSS();
                 }
                 $msg = $this->html;
                 $msg = $this->checkIfHTML($msg);
             }
             if ($this->msgishtml) {
                 $smtps->setBodyContent($msg, 'html');
             } else {
                 $smtps->setBodyContent($msg, 'plain');
             }
             if ($this->atleastoneimage) {
                 foreach ($this->images_encoded as $img) {
                     $smtps->setImageInline($img['image_encoded'], $img['name'], $img['content_type'], $img['cid']);
                 }
             }
             if ($this->atleastonefile) {
                 foreach ($filename_list as $i => $val) {
                     $content = file_get_contents($filename_list[$i]);
                     $smtps->setAttachment($content, $mimefilename_list[$i], $mimetype_list[$i]);
                 }
             }
             $smtps->setCC($addr_cc);
             $smtps->setBCC($addr_bcc);
             $smtps->setErrorsTo($errors_to);
             $smtps->setDeliveryReceipt($deliveryreceipt);
             $this->smtps = $smtps;
         } else {
             if ($conf->global->MAIN_MAIL_SENDMODE == 'phpmailer') {
                 // Use PHPMailer library
                 // ------------------------------------------
                 require_once DOL_DOCUMENT_ROOT . '/includes/phpmailer/class.phpmailer.php';
                 $this->phpmailer = new PHPMailer();
                 $this->phpmailer->CharSet = $conf->file->character_set_client;
                 $this->phpmailer->Subject($this->encodetorfc2822($subject));
                 $this->phpmailer->setTO($this->getValidAddress($to, 0, 1));
                 $this->phpmailer->SetFrom($this->getValidAddress($from, 0, 1));
                 if (!empty($this->html)) {
                     if (!empty($css)) {
                         $this->css = $css;
                         $this->buildCSS();
                     }
                     $msg = $this->html;
                     $msg = $this->checkIfHTML($msg);
                 }
                 if ($this->msgishtml) {
                     $smtps->setBodyContent($msg, 'html');
                 } else {
                     $smtps->setBodyContent($msg, 'plain');
                 }
                 if ($this->atleastoneimage) {
                     foreach ($this->images_encoded as $img) {
                         $smtps->setImageInline($img['image_encoded'], $img['name'], $img['content_type'], $img['cid']);
                     }
                 }
                 if ($this->atleastonefile) {
                     foreach ($filename_list as $i => $val) {
                         $content = file_get_contents($filename_list[$i]);
                         $smtps->setAttachment($content, $mimefilename_list[$i], $mimetype_list[$i]);
                     }
                 }
                 $smtps->setCC($addr_cc);
                 $smtps->setBCC($addr_bcc);
                 $smtps->setErrorsTo($errors_to);
                 $smtps->setDeliveryReceipt($deliveryreceipt);
                 $this->smtps = $smtps;
             } else {
                 // Send mail method not correctly defined
                 // --------------------------------------
                 return 'Bad value for MAIN_MAIL_SENDMODE constant';
             }
         }
     }
 }
Пример #28
0
/**
 *	This function is called to encode a string into a HTML string but differs from htmlentities because
 * 	all entities but &,<,> are converted. This permits to encode special chars to entities with no double
 *  encoding for already encoded HTML strings.
 * 	This function also remove last CR/BR.
 *  For PDF usage, you can show text by 2 ways:
 *              - writeHTMLCell -> param must be encoded into HTML.
 *              - MultiCell -> param must not be encoded into HTML.
 *              Because writeHTMLCell convert also \n into <br>, if function
 *              is used to build PDF, nl2brmode must be 1.
 *	@param		stringtoencode		String to encode
 *	@param		nl2brmode			0=Adding br before \n, 1=Replacing \n by br (for use with FPDF writeHTMLCell function for example)
 *  @param      pagecodefrom        Pagecode stringtoencode is encoded
 */
function dol_htmlentitiesbr($stringtoencode, $nl2brmode = 0, $pagecodefrom = 'UTF-8')
{
    if (dol_textishtml($stringtoencode)) {
        $newstring = $stringtoencode;
        //$newstring=preg_replace('/([^<li\s*>]+)(\r\n|\r|\n)+/i',($forxml?'$1<br />':'$1<br>'),$stringtoencode); // Don't replace if in list
        //$newstring=preg_replace('/<li\s*>(\r\n|\r|\n)+/','__li__',$newstring); // Don't replace if \n is just after a li
        //$newstring=preg_replace('/(\r\n|\r|\n)+/i',($forxml?'<br />':'<br>'),$newstring); // If already HTML, CR should be <br> so we don't change \n
        $newstring = preg_replace('/<br(\\s[\\sa-zA-Z_="]*)?\\/?>/i', '<br>', $newstring);
        // Replace "<br type="_moz" />" by "<br>". It's same and avoid pb with FPDF.
        $newstring = preg_replace('/<br>$/i', '', $newstring);
        // Remove last <br>
        $newstring = strtr($newstring, array('&' => '__and__', '<' => '__lt__', '>' => '__gt__', '"' => '__dquot__'));
        $newstring = dol_htmlentities($newstring, ENT_COMPAT, $pagecodefrom);
        // Make entity encoding
        $newstring = strtr($newstring, array('__and__' => '&', '__lt__' => '<', '__gt__' => '>', '__dquot__' => '"'));
        //$newstring=strtr($newstring,array('__li__'=>"<li>\n")); // Restore <li>\n
    } else {
        $newstring = dol_nl2br(dol_htmlentities($stringtoencode, ENT_COMPAT, $pagecodefrom), $nl2brmode);
    }
    // Other substitutions that htmlentities does not do
    //$newstring=str_replace(chr(128),'&euro;',$newstring);	// 128 = 0x80. Not in html entity table.
    return $newstring;
}
Пример #29
0
	// Note
    print '<tr><td valign="top">'.$langs->trans("Note").'</td>';
	print '<td valign="top" colspan="3">';
	if ($action == 'edit' && $user->rights->user->user->creer)
	{
		print "<input type=\"hidden\" name=\"action\" value=\"update\">";
		print "<input type=\"hidden\" name=\"id\" value=\"".$fuser->id."\">";
	    // Editeur wysiwyg
		require_once(DOL_DOCUMENT_ROOT."/lib/doleditor.class.php");
		$doleditor=new DolEditor('note',$fuser->note,'',280,'dolibarr_notes','In',true,false,$conf->fckeditor->enabled && $conf->global->FCKEDITOR_ENABLE_USER,10,80);
		$doleditor->Create();
	}
	else
	{
		print dol_textishtml($fuser->note)?$fuser->note:dol_nl2br($fuser->note,1,true);
	}
	print "</td></tr>";

	if ($action == 'edit')
	{
		print '<tr><td colspan="4" align="center">';
		print '<input type="submit" class="button" name="update" value="'.$langs->trans("Save").'">';
		print '&nbsp; &nbsp;';
		print '<input type="submit" class="button" name="cancel" value="'.$langs->trans("Cancel").'">';
		print '</td></tr>';
	}

    print "</table>";
	print "</form>\n";
Пример #30
0
         $newlang = '';
         if (empty($newlang) && GETPOST('lang_id')) {
             $newlang = GETPOST('lang_id');
         }
         if (empty($newlang)) {
             $newlang = $object->client->default_lang;
         }
         if (!empty($newlang)) {
             $outputlangs = new Translate("", $conf);
             $outputlangs->setDefaultLang($newlang);
         }
         $desc = !empty($prod->multilangs[$outputlangs->defaultlang]["description"]) ? $prod->multilangs[$outputlangs->defaultlang]["description"] : $prod->description;
     } else {
         $desc = $prod->description;
     }
     $desc .= $desc && $_POST['np_desc'] ? dol_textishtml($desc) || dol_textishtml($_POST['np_desc']) ? "<br />\n" : "\n" : "";
     $desc .= $_POST['np_desc'];
     $type = $prod->type;
 } else {
     $pu_ht = $_POST['np_price'];
     $tva_tx = str_replace('*', '', $_POST['np_tva_tx']);
     $tva_npr = preg_match('/\\*/', $_POST['np_tva_tx']) ? 1 : 0;
     $desc = $_POST['dp_desc'];
     $type = $_POST["type"];
     $localtax1_tx = get_localtax($tva_tx, 1, $object->client);
     $localtax2_tx = get_localtax($tva_tx, 2, $object->client);
 }
 // ajout prix achat
 $fk_fournprice = $_POST['np_fournprice'];
 if (!empty($_POST['np_buying_price'])) {
     $pa_ht = $_POST['np_buying_price'];