/**
  * 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;
 }
Exemple #2
0
        $error++;
    }
    if (empty($smsfrom) || !str_replace('+', '', $smsfrom)) {
        $message = '<div class="error">' . $langs->trans("ErrorFieldRequired", $langs->transnoentities("SmsFrom")) . '</div>';
        $action = 'test';
        $error++;
    }
    if (empty($sendto) || !str_replace('+', '', $sendto)) {
        $message = '<div class="error">' . $langs->trans("ErrorFieldRequired", $langs->transnoentities("SmsTo")) . '</div>';
        $action = 'test';
        $error++;
    }
    if (!$error) {
        // Make substitutions into message
        complete_substitutions_array($substitutionarrayfortest, $langs);
        $body = make_substitutions($body, $substitutionarrayfortest);
        require_once DOL_DOCUMENT_ROOT . "/core/class/CSMSFile.class.php";
        $smsfile = new CSMSFile($sendto, $smsfrom, $body, $deliveryreceipt, $deferred, $priority, $class);
        // This define OvhSms->login, pass, session and account
        $result = $smsfile->sendfile();
        // This send SMS
        if ($result) {
            $message = '<div class="ok">' . $langs->trans("SmsSuccessfulySent", $smsfrom, $sendto) . '</div>';
        } else {
            $message = '<div class="error">' . $langs->trans("ResultKo") . '<br>' . $smsfile->error . ' ' . $result . '</div>';
        }
        $action = '';
    }
}
/*
 * View
    /**
     *	Show the form to input an sms
     */
    function show_form($width = '180px')
    {
        global $conf, $langs, $user;
        $langs->load("other");
        $langs->load("mails");
        $langs->load("sms");
        $form = new Form($this->db);
        $soc = new Societe($this->db);
        if (!empty($this->withtosocid) && $this->withtosocid > 0) {
            $soc->fetch($this->withtosocid);
        }
        print "\n<!-- Debut form SMS -->\n";
        print '
<script language="javascript">
function limitChars(textarea, limit, infodiv)
{
    var text = textarea.value;
    var textlength = text.length;
    var info = document.getElementById(infodiv);

    info.innerHTML = \'' . $langs->trans("SmsInfoCharRemain") . ': \' + (limit - textlength);
    return true;
}
</script>';
        print "<form method=\"POST\" name=\"smsform\" enctype=\"multipart/form-data\" action=\"" . $this->param["returnurl"] . "\">\n";
        print '<input type="hidden" name="token" value="' . $_SESSION['newtoken'] . '">';
        foreach ($this->param as $key => $value) {
            print "<input type=\"hidden\" name=\"{$key}\" value=\"{$value}\">\n";
        }
        print "<table class=\"border\" width=\"100%\">\n";
        // Substitution array
        if ($this->withsubstit) {
            print "<tr><td colspan=\"2\">";
            $help = "";
            foreach ($this->substit as $key => $val) {
                $help .= $key . ' -> ' . $langs->trans($val) . '<br>';
            }
            print $form->textwithpicto($langs->trans("SmsTestSubstitutionReplacedByGenericValues"), $help);
            print "</td></tr>\n";
        }
        // From
        if ($this->withfrom) {
            if ($this->withfromreadonly) {
                print '<input type="hidden" name="fromsms" value="' . $this->fromsms . '">';
                print "<tr><td width=\"" . $width . "\">" . $langs->trans("SmsFrom") . "</td><td>";
                if ($this->fromtype == 'user') {
                    $langs->load("users");
                    $fuser = new User($this->db);
                    $fuser->fetch($this->fromid);
                    print $fuser->getNomUrl(1);
                    print ' &nbsp; ';
                }
                if ($this->fromsms) {
                    print $this->fromsms;
                } else {
                    if ($this->fromtype) {
                        $langs->load("errors");
                        print '<font class="warning"> &lt;' . $langs->trans("ErrorNoPhoneDefinedForThisUser") . '&gt; </font>';
                    }
                }
                print "</td></tr>\n";
                print "</td></tr>\n";
            } else {
                print "<tr><td width=\"" . $width . "\">" . $langs->trans("SmsFrom") . "</td><td>";
                //print '<input type="text" name="fromname" size="30" value="'.$this->fromsms.'">';
                if ($conf->global->MAIN_SMS_SENDMODE == 'ovh') {
                    dol_include_once('/ovh/class/ovhsms.class.php');
                    try {
                        $sms = new OvhSms($this->db);
                        if (empty($conf->global->OVHSMS_ACCOUNT)) {
                            $resultsender = 'ErrorOVHSMS_ACCOUNT not defined';
                        } else {
                            $resultsender = $sms->SmsSenderList($conf->global->OVHSMS_ACCOUNT);
                        }
                    } catch (Exception $e) {
                        dol_print_error('', 'Error to get list of senders: ' . $e->getMessage());
                    }
                } else {
                    dol_syslog("Warning: The SMS sending method has not been defined into MAIN_SMS_SENDMODE", LOG_WARNING);
                    $resultsender[0]->number = $this->fromsms;
                }
                if (is_array($resultsender) && count($resultsender) > 0) {
                    print '<select name="fromsms" id="valid" class="flat">';
                    foreach ($resultsender as $obj) {
                        print '<option value="' . $obj->number . '">' . $obj->number . '</option>';
                    }
                    print '</select>';
                } else {
                    print '<span class="error">' . $langs->trans("SmsNoPossibleRecipientFound") . '</span>';
                }
                print '</td>';
                print "</tr>\n";
            }
        }
        // To
        if ($this->withto || is_array($this->withto)) {
            print '<tr><td width="180">';
            //$moretext=$langs->trans("YouCanUseCommaSeparatorForSeveralRecipients");
            $moretext = '';
            print $form->textwithpicto($langs->trans("SmsTo"), $moretext);
            print '</td><td>';
            if ($this->withtoreadonly) {
                print !is_array($this->withto) && !is_numeric($this->withto) ? $this->withto : "";
            } else {
                print "<input size=\"16\" id=\"sendto\" name=\"sendto\" value=\"" . (!is_array($this->withto) && $this->withto != '1' ? isset($_REQUEST["sendto"]) ? $_REQUEST["sendto"] : $this->withto : "+") . "\">";
                if (!empty($this->withtosocid) && $this->withtosocid > 0) {
                    $liste = array();
                    foreach ($soc->thirdparty_and_contact_phone_array() as $key => $value) {
                        $liste[$key] = $value;
                    }
                    print " " . $langs->trans("or") . " ";
                    //var_dump($_REQUEST);exit;
                    print $form->selectarray("receiver", $liste, GETPOST("receiver"), 1);
                }
                print ' ' . $langs->trans("SmsInfoNumero");
            }
            print "</td></tr>\n";
        }
        // Message
        if ($this->withbody) {
            $defaultmessage = '';
            if ($this->param["models"] == 'body') {
                $defaultmessage = $this->withbody;
            }
            $defaultmessage = make_substitutions($defaultmessage, $this->substit, $langs);
            if (isset($_POST["message"])) {
                $defaultmessage = $_POST["message"];
            }
            $defaultmessage = str_replace('\\n', "\n", $defaultmessage);
            print "<tr>";
            print "<td width=\"180\" valign=\"top\">" . $langs->trans("SmsText") . "</td>";
            print "<td>";
            if ($this->withbodyreadonly) {
                print nl2br($defaultmessage);
                print '<input type="hidden" name="message" value="' . $defaultmessage . '">';
            } else {
                print '<textarea cols="40" name="message" id="message" rows="4" onkeyup="limitChars(this, 160, \'charlimitinfo\')">' . $defaultmessage . '</textarea>';
                print '<div id="charlimitinfo">' . $langs->trans("SmsInfoCharRemain") . ': <span id="charlimitinfospan">' . (160 - dol_strlen($defaultmessage)) . '</span></div></td>';
            }
            print "</td></tr>\n";
        }
        print '
           <tr>
            <td>' . $langs->trans("DelayBeforeSending") . ':</td>
            <td> <input name="deferred" id="deferred" size="4" value="0"></td></tr>

           <tr><td>' . $langs->trans("Priority") . ' :</td><td>
           <select name="priority" id="valid" class="flat">
           <option value="0">0</option>
           <option value="1">1</option>
           <option value="2">2</option>
           <option value="3" selected="selected">3</option>
           </select></td></tr>

           <tr><td>' . $langs->trans("Type") . ' :</td><td>
           <select name="class" id="valid" class="flat">
           <option value="0">Flash</option>
           <option value="1" selected="selected">Standard</option>
           <option value="2">SIM</option>
           <option value="3">ToolKit</option>
           </select></td></tr>';
        print '<tr><td align="center" colspan="2"><center>';
        print "<input class=\"button\" type=\"submit\" name=\"sendmail\" value=\"" . $langs->trans("SendSms") . "\"";
        print ">";
        if ($this->withcancel) {
            print " &nbsp; &nbsp; ";
            print "<input class=\"button\" type=\"submit\" name=\"cancel\" value=\"" . $langs->trans("Cancel") . "\">";
        }
        print "</center></td></tr>\n";
        print "</table>\n";
        print "</form>\n";
        print "<!-- Fin form SMS -->\n";
    }
 $upload_dir = $conf->mailing->dir_output . "/" . get_exdir($object->id, 2, 0, 1);
 $object->sendto = $_POST["sendto"];
 if (!$object->sendto) {
     $mesg = '<div class="error">' . $langs->trans("ErrorFieldRequired", $langs->trans("MailTo")) . '</div>';
     $error++;
 }
 if (!$error) {
     // Le message est-il en html
     $msgishtml = -1;
     // Inconnu par defaut
     if (preg_match('/[\\s\\t]*<html>/i', $object->body)) {
         $msgishtml = 1;
     }
     // Pratique les substitutions sur le sujet et message
     $tmpsujet = make_substitutions($object->sujet, $object->substitutionarrayfortest);
     $tmpbody = make_substitutions($object->body, $object->substitutionarrayfortest);
     $arr_file = array();
     $arr_mime = array();
     $arr_name = array();
     $arr_css = array();
     // Ajout CSS
     if (!empty($object->bgcolor)) {
         $arr_css['bgcolor'] = (preg_match('/^#/', $object->bgcolor) ? '' : '#') . $object->bgcolor;
     }
     if (!empty($object->bgimage)) {
         $arr_css['bgimage'] = $object->bgimage;
     }
     // Attached files
     $listofpaths = dol_dir_list($upload_dir, 'all', 0, '', '', 'name', SORT_ASC, 0);
     if (count($listofpaths)) {
         foreach ($listofpaths as $key => $val) {
function _sendByMail(&$db, &$conf, &$user, &$langs, &$facture, &$societe, $label)
{
    $filename_list = array();
    $mimetype_list = array();
    $mimefilename_list = array();
    $ref = dol_sanitizeFileName($facture->ref);
    $fileparams = dol_most_recent_file($conf->facture->dir_output . '/' . $ref, preg_quote($ref, '/') . '([^\\-])+');
    $file = $fileparams['fullname'];
    // Build document if it not exists
    if (!$file || !is_readable($file)) {
        $result = $facture->generateDocument($facture->modelpdf, $langs, 0, 0, 0);
        if ($result <= 0) {
            $error = 1;
            return $error;
        }
    }
    $label = !empty($conf->global->SENDINVOICETOADHERENT_SUBJECT) ? $conf->global->SENDINVOICETOADHERENT_SUBJECT : $label;
    $substitutionarray = array('__NAME__' => $societe->name, '__REF__' => $facture->ref);
    $message = $conf->global->SENDINVOICETOADHERENT_MESSAGE;
    $message = make_substitutions($message, $substitutionarray);
    $fileparams = dol_most_recent_file($conf->facture->dir_output . '/' . $ref, preg_quote($ref, '/') . '([^\\-])+');
    $file = $fileparams['fullname'];
    $filename = basename($file);
    $mimefile = dol_mimetype($file);
    $filename_list[] = $file;
    $mimetype_list[] = $mimefile;
    $mimefilename_list[] = $filename;
    $CMail = new CMailFile($label, $societe->email, $conf->global->MAIN_MAIL_EMAIL_FROM, $message, $filename_list, $mimetype_list, $mimefilename_list, '', '', '', '', $errors_to = $conf->global->MAIN_MAIL_ERRORS_TO);
    // Send mail
    return $CMail->sendfile();
}
         }
         //echo "[".$html."]";
         // post-processing cleanup
         $html = preg_replace('!<p>[\\s\\h\\v]*</p>!u', '', $html);
         if ($links == 'remove') {
             $html = preg_replace('!</?a[^>]*>!', '', $html);
         }
         //echo "[". $html ."]";
         // get text sample for language detection
         $text_sample = strip_tags(substr($html, 0, 500));
         if (!$valid_key) {
             $html = make_substitutions($options->message_to_prepend) . $html;
             $html .= make_substitutions($options->message_to_append);
         } else {
             $html = make_substitutions($options->message_to_prepend_with_key) . $html;
             $html .= make_substitutions($options->message_to_append_with_key);
         }
     }
 }
 /*
 if ($format == 'atom') {
 	$newitem->addElement('content', $html);
 	$newitem->setDate((int)$item->get_date('U'));
 	if ($author = $item->get_author()) {
 		$newitem->addElement('author', array('name'=>$author->get_name()));
 	}
 } else { 
 */
 if ($valid_key && isset($_GET['pubsub'])) {
     // used only on fivefilters.org at the moment
     $newitem->addElement('guid', 'http://fivefilters.org/content-only/redirect.php?url=' . urlencode($item->get_permalink()), array('isPermaLink' => 'false'));
Exemple #7
0
         $textfooter = make_substitutions($conf->global->ADHERENT_CARD_FOOTER_TEXT, $substitutionarray);
         $textright = make_substitutions($conf->global->ADHERENT_CARD_TEXT_RIGHT, $substitutionarray);
         if (is_numeric($foruserid) || $foruserlogin) {
             for ($j = 0; $j < 100; $j++) {
                 $arrayofmembers[] = array('textleft' => $textleft, 'textheader' => $textheader, 'textfooter' => $textfooter, 'textright' => $textright, 'id' => $objp->rowid, 'photo' => $objp->photo);
             }
         } else {
             $arrayofmembers[] = array('textleft' => $textleft, 'textheader' => $textheader, 'textfooter' => $textfooter, 'textright' => $textright, 'id' => $objp->rowid, 'photo' => $objp->photo);
         }
     }
     // For labels
     if ($mode == 'label') {
         if (empty($conf->global->ADHERENT_ETIQUETTE_TEXT)) {
             $conf->global->ADHERENT_ETIQUETTE_TEXT = "%FULLNAME%\n%ADDRESS%\n%ZIP% %TOWN%\n%COUNTRY%";
         }
         $textleft = make_substitutions($conf->global->ADHERENT_ETIQUETTE_TEXT, $substitutionarray);
         $textheader = '';
         $textfooter = '';
         $textright = '';
         $arrayofmembers[] = array('textleft' => $textleft, 'textheader' => $textheader, 'textfooter' => $textfooter, 'textright' => $textright, 'id' => $objp->rowid, 'photo' => $objp->photo);
     }
     $i++;
 }
 // Build and output PDF
 if (empty($mode) || $mode == 'card' || $mode == 'cardlogin') {
     if (!count($arrayofmembers)) {
         $mesg = $langs->trans("ErrorRecordNotFound");
     }
     if (empty($model) || $model == '-1') {
         $mesg = $langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("DescADHERENT_CARD_TYPE"));
     }
         //convert to TCPDF compatible encoding types
         $is2d = $module->is2d;
     }
 }
 if (!$error) {
     // List of values to scan for a replacement
     $substitutionarray = array('%LOGIN%' => $user->login, '%COMPANY%' => $mysoc->name, '%ADDRESS%' => $mysoc->address, '%ZIP%' => $mysoc->zip, '%TOWN%' => $mysoc->town, '%COUNTRY%' => $mysoc->country, '%COUNTRY_CODE%' => $mysoc->country_code, '%EMAIL%' => $mysoc->email, '%YEAR%' => $year, '%MONTH%' => $month, '%DAY%' => $day, '%DOL_MAIN_URL_ROOT%' => DOL_MAIN_URL_ROOT, '%SERVER%' => "http://" . $_SERVER["SERVER_NAME"] . "/");
     complete_substitutions_array($substitutionarray, $langs);
     // For labels
     if ($mode == 'label') {
         $txtforsticker = "%PHOTO%";
         // Photo will be barcode image, %BARCODE% posible when using TCPDF generator
         $textleft = make_substitutions(empty($conf->global->BARCODE_LABEL_LEFT_TEXT) ? $txtforsticker : $conf->global->BARCODE_LABEL_LEFT_TEXT, $substitutionarray);
         $textheader = make_substitutions(empty($conf->global->BARCODE_LABEL_HEADER_TEXT) ? '' : $conf->global->BARCODE_LABEL_HEADER_TEXT, $substitutionarray);
         $textfooter = make_substitutions(empty($conf->global->BARCODE_LABEL_FOOTER_TEXT) ? '' : $conf->global->BARCODE_LABEL_FOOTER_TEXT, $substitutionarray);
         $textright = make_substitutions(empty($conf->global->BARCODE_LABEL_RIGHT_TEXT) ? '' : $conf->global->BARCODE_LABEL_RIGHT_TEXT, $substitutionarray);
         $forceimgscalewidth = empty($conf->global->BARCODE_FORCEIMGSCALEWIDTH) ? 1 : $conf->global->BARCODE_FORCEIMGSCALEWIDTH;
         $forceimgscaleheight = empty($conf->global->BARCODE_FORCEIMGSCALEHEIGHT) ? 1 : $conf->global->BARCODE_FORCEIMGSCALEHEIGHT;
         for ($i = 0; $i < $numberofsticker; $i++) {
             $arrayofrecords[] = array('textleft' => $textleft, 'textheader' => $textheader, 'textfooter' => $textfooter, 'textright' => $textright, 'code' => $code, 'encoding' => $encoding, 'is2d' => $is2d, 'photo' => $barcodeimage);
         }
     }
     $i++;
     $mesg = '';
     // Build and output PDF
     if ($mode == 'label') {
         if (!count($arrayofrecords)) {
             $mesg = $langs->trans("ErrorRecordNotFound");
         }
         if (empty($modellabel) || $modellabel == '-1') {
             $mesg = $langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("DescADHERENT_ETIQUETTE_TYPE"));
Exemple #9
0
/**
 *  Show footer of page for PDF generation
 *
 *	@param	PDF			&$pdf     		The PDF factory
 *  @param  Translate	$outputlangs	Object lang for output
 * 	@param	string		$paramfreetext	Constant name of free text
 * 	@param	Societe		$fromcompany	Object company
 * 	@param	int			$marge_basse	Margin bottom
 * 	@param	int			$marge_gauche	Margin left
 * 	@param	int			$page_hauteur	Page height
 * 	@param	Object		$object			Object shown in PDF
 * 	@param	int			$showdetails	Show company details
 * 	@return	void
 */
function pdf_pagefoot(&$pdf, $outputlangs, $paramfreetext, $fromcompany, $marge_basse, $marge_gauche, $page_hauteur, $object, $showdetails = 0)
{
    global $conf, $user;
    $outputlangs->load("dict");
    $line = '';
    // Line of free text
    if (!empty($conf->global->{$paramfreetext})) {
        // Make substitution
        $substitutionarray = array('__FROM_NAME__' => $fromcompany->nom, '__FROM_EMAIL__' => $fromcompany->email, '__TOTAL_TTC__' => $object->total_ttc, '__TOTAL_HT__' => $object->total_ht, '__TOTAL_VAT__' => $object->total_vat);
        complete_substitutions_array($substitutionarray, $outputlangs, $object);
        $newfreetext = make_substitutions($conf->global->{$paramfreetext}, $substitutionarray);
        $line .= $outputlangs->convToOutputCharset($newfreetext);
    }
    // First line of company infos
    if ($showdetails) {
        $line1 = "";
        // Company name
        if ($fromcompany->name) {
            $line1 .= ($line1 ? " - " : "") . $outputlangs->transnoentities("RegisteredOffice") . ": " . $fromcompany->name;
        }
        // Address
        if ($fromcompany->address) {
            $line1 .= ($line1 ? " - " : "") . $fromcompany->address;
        }
        // Zip code
        if ($fromcompany->zip) {
            $line1 .= ($line1 ? " - " : "") . $fromcompany->zip;
        }
        // Town
        if ($fromcompany->town) {
            $line1 .= ($line1 ? " " : "") . $fromcompany->town;
        }
        // Phone
        if ($fromcompany->phone) {
            $line1 .= ($line1 ? " - " : "") . $outputlangs->transnoentities("Phone") . ": " . $fromcompany->phone;
        }
        // Fax
        if ($fromcompany->fax) {
            $line1 .= ($line1 ? " - " : "") . $outputlangs->transnoentities("Fax") . ": " . $fromcompany->fax;
        }
        $line2 = "";
        // URL
        if ($fromcompany->url) {
            $line2 .= ($line2 ? " - " : "") . $fromcompany->url;
        }
        // Email
        if ($fromcompany->email) {
            $line2 .= ($line2 ? " - " : "") . $fromcompany->email;
        }
    }
    // Line 3 of company infos
    $line3 = "";
    // Juridical status
    if ($fromcompany->forme_juridique_code) {
        $line3 .= ($line3 ? " - " : "") . $outputlangs->convToOutputCharset(getFormeJuridiqueLabel($fromcompany->forme_juridique_code));
    }
    // Capital
    if ($fromcompany->capital) {
        $line3 .= ($line3 ? " - " : "") . $outputlangs->transnoentities("CapitalOf", $fromcompany->capital) . " " . $outputlangs->transnoentities("Currency" . $conf->currency);
    }
    // Prof Id 1
    if ($fromcompany->idprof1 && ($fromcompany->country_code != 'FR' || !$fromcompany->idprof2)) {
        $field = $outputlangs->transcountrynoentities("ProfId1", $fromcompany->country_code);
        if (preg_match('/\\((.*)\\)/i', $field, $reg)) {
            $field = $reg[1];
        }
        $line3 .= ($line3 ? " - " : "") . $field . ": " . $outputlangs->convToOutputCharset($fromcompany->idprof1);
    }
    // Prof Id 2
    if ($fromcompany->idprof2) {
        $field = $outputlangs->transcountrynoentities("ProfId2", $fromcompany->country_code);
        if (preg_match('/\\((.*)\\)/i', $field, $reg)) {
            $field = $reg[1];
        }
        $line3 .= ($line3 ? " - " : "") . $field . ": " . $outputlangs->convToOutputCharset($fromcompany->idprof2);
    }
    // Line 4 of company infos
    $line4 = "";
    // Prof Id 3
    if ($fromcompany->idprof3) {
        $field = $outputlangs->transcountrynoentities("ProfId3", $fromcompany->country_code);
        if (preg_match('/\\((.*)\\)/i', $field, $reg)) {
            $field = $reg[1];
        }
        $line4 .= ($line4 ? " - " : "") . $field . ": " . $outputlangs->convToOutputCharset($fromcompany->idprof3);
    }
    // Prof Id 4
    if ($fromcompany->idprof4) {
        $field = $outputlangs->transcountrynoentities("ProfId4", $fromcompany->country_code);
        if (preg_match('/\\((.*)\\)/i', $field, $reg)) {
            $field = $reg[1];
        }
        $line4 .= ($line4 ? " - " : "") . $field . ": " . $outputlangs->convToOutputCharset($fromcompany->idprof4);
    }
    // IntraCommunautary VAT
    if ($fromcompany->tva_intra != '') {
        $line4 .= ($line4 ? " - " : "") . $outputlangs->transnoentities("VATIntraShort") . ": " . $outputlangs->convToOutputCharset($fromcompany->tva_intra);
    }
    $pdf->SetFont('', '', 7);
    $pdf->SetDrawColor(224, 224, 224);
    // On positionne le debut du bas de page selon nbre de lignes de ce bas de page
    $nbofline = dol_nboflines_bis($line, 0, $outputlangs->charset_output);
    //print 'nbofline='.$nbofline; exit;
    //print 'e'.$line.'t'.dol_nboflines($line);exit;
    $posy = $marge_basse + $nbofline * 3 + (!empty($line1) ? 3 : 0) + (!empty($line2) ? 3 : 0) + (!empty($line3) ? 3 : 0) + (!empty($line4) ? 3 : 0);
    if ($line) {
        $pdf->SetXY($marge_gauche, -$posy);
        $width = 20000;
        $align = 'L';
        // By default, ask a manual break: We use a large value 20000, to not have automatic wrap. This make user understand, he need to add CR on its text.
        if ($conf->global->MAIN_USE_AUTOWRAP_ON_FREETEXT) {
            $width = 200;
            $align = 'C';
        }
        $pdf->MultiCell($width, 3, $line, 0, $align, 0);
        $posy -= $nbofline * 3;
        // 6 of ligne + 3 of MultiCell
    }
    $pdf->SetY(-$posy);
    $pdf->line($marge_gauche, $page_hauteur - $posy, 200, $page_hauteur - $posy);
    $posy--;
    if (!empty($line1)) {
        $pdf->SetFont('', 'B', 7);
        $pdf->SetXY($marge_gauche, -$posy);
        $pdf->MultiCell(200, 2, $line1, 0, 'C', 0);
        $posy -= 3;
        $pdf->SetFont('', '', 7);
    }
    if (!empty($line2)) {
        $pdf->SetFont('', 'B', 7);
        $pdf->SetXY($marge_gauche, -$posy);
        $pdf->MultiCell(200, 2, $line2, 0, 'C', 0);
        $posy -= 3;
        $pdf->SetFont('', '', 7);
    }
    if (!empty($line3)) {
        $pdf->SetXY($marge_gauche, -$posy);
        $pdf->MultiCell(200, 2, $line3, 0, 'C', 0);
    }
    if (!empty($line4)) {
        $posy -= 3;
        $pdf->SetXY($marge_gauche, -$posy);
        $pdf->MultiCell(200, 2, $line4, 0, 'C', 0);
    }
    // Show page nb only on iso languages (so default Helvetica font)
    if (pdf_getPDFFont($outputlangs) == 'Helvetica') {
        $pdf->SetXY(-20, -$posy);
        $pdf->MultiCell(11, 2, $pdf->PageNo() . '/' . $pdf->getAliasNbPages(), 0, 'R', 0);
        //print 'xxx'.$pdf->getAliasNbPages().'-'.$pdf->getAliasNumPage();exit;
    }
}
Exemple #10
0
	$mil->sendto = $_POST["sendto"];
	if (! $mil->sendto)
	{
		$message='<div class="error">'.$langs->trans("ErrorFieldRequired",$langs->trans("MailTo")).'</div>';
		$error++;
	}

	if (! $error)
	{
		// Le message est-il en html
		$msgishtml=-1;	// Inconnu par defaut
		if (preg_match('/[\s\t]*<html>/i',$message)) $msgishtml=1;

		// Pratique les substitutions sur le sujet et message
		$mil->sujet=make_substitutions($mil->sujet,$substitutionarrayfortest,$langs);
		$mil->body=make_substitutions($mil->body,$substitutionarrayfortest,$langs);

		$arr_file = array();
		$arr_mime = array();
		$arr_name = array();
		$arr_css  = array();

        // Ajout CSS
        if (!empty($mil->bgcolor)) $arr_css['bgcolor'] = (preg_match('/^#/',$mil->bgcolor)?'':'#').$mil->bgcolor;
        if (!empty($mil->bgimage)) $arr_css['bgimage'] = $mil->bgimage;

        // Attached files
		$listofpaths=dol_dir_list($upload_dir,'all',0,'','','name',SORT_ASC,0);
		if (sizeof($listofpaths))
		{
			foreach($listofpaths as $key => $val)
    /**
     *	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;
        }
    }
 /**
  *
  * @param unknown $object
  */
 static function sendOrderByMail(&$object)
 {
     global $conf, $langs, $user, $db;
     if (empty($object->thirdparty)) {
         $object->fetch_thirdparty();
     }
     $sendto = $object->thirdparty->email;
     $sendtocc = '';
     $from = empty($user->email) ? $conf->global->MAIN_MAIL_EMAIL_FROM : $user->email;
     $id = $object->id;
     $_POST['receiver'] = '-1';
     $_POST['frommail'] = $_POST['replytomail'] = $from;
     $_POST['fromname'] = $_POST['replytoname'] = $user->getFullName($langs);
     dol_include_once('/core/class/html.formmail.class.php');
     $formmail = new Formmail($db);
     $outputlangs = clone $langs;
     $id_template = (int) $conf->global->GRAPEFRUIT_SEND_BILL_BY_MAIL_ON_VALIDATE_MODEL;
     $formmail->fetchAllEMailTemplate('facture_send', $user, $outputlangs);
     foreach ($formmail->lines_model as &$model) {
         if ($model->id == $id_template) {
             break;
         }
     }
     if (empty($model)) {
         setEventMessage($langs->trans('ModelRequire'), 'errors');
     }
     // Make substitution
     $substit['__REF__'] = $object->ref;
     $substit['__SIGNATURE__'] = $user->signature;
     $substit['__REFCLIENT__'] = $object->ref_client;
     $substit['__THIRDPARTY_NAME__'] = $object->thirdparty->name;
     $substit['__PROJECT_REF__'] = is_object($object->projet) ? $object->projet->ref : '';
     $substit['__PROJECT_NAME__'] = is_object($object->projet) ? $object->projet->title : '';
     $substit['__PERSONALIZED__'] = '';
     $substit['__CONTACTCIVNAME__'] = '';
     // Find the good contact adress
     $custcontact = '';
     $contactarr = array();
     $contactarr = $object->liste_contact(-1, 'external');
     if (is_array($contactarr) && count($contactarr) > 0) {
         foreach ($contactarr as $contact) {
             dol_syslog(get_class($this) . '::' . __METHOD__ . ' lib=' . $contact['libelle']);
             dol_syslog(get_class($this) . '::' . __METHOD__ . ' trans=' . $langs->trans('TypeContact_commande_external_BILLING'));
             if ($contact['libelle'] == $langs->trans('TypeContact_commande_external_BILLING')) {
                 require_once DOL_DOCUMENT_ROOT . '/contact/class/contact.class.php';
                 $contactstatic = new Contact($db);
                 $contactstatic->fetch($contact['id']);
                 $custcontact = $contactstatic->getFullName($langs, 1);
                 dol_syslog(get_class($this) . '::' . __METHOD__ . ' email=' . $contactstatic->email);
             }
         }
         if (!empty($custcontact)) {
             $substit['__CONTACTCIVNAME__'] = $custcontact;
         }
         if (!empty($contactstatic->email)) {
             $sendto = $contactstatic->email;
         }
     }
     $topic = make_substitutions($model->topic, $substit);
     $message = make_substitutions($model->content, $substit);
     $_POST['message'] = $message;
     $_POST['subject'] = $topic;
     require_once DOL_DOCUMENT_ROOT . '/core/lib/files.lib.php';
     // Add attached files
     $fileparams = dol_most_recent_file($conf->commande->dir_output . '/' . $object->ref, preg_quote($object->ref, '/') . '[^\\-]+');
     if (is_array($fileparams) && array_key_exists('fullname', $fileparams) && !empty($fileparams['fullname'])) {
         $_SESSION["listofpaths"] = $fileparams['fullname'];
         $_SESSION["listofnames"] = basename($fileparams['fullname']);
         $_SESSION["listofmimes"] = dol_mimetype($fileparams['fullname']);
     } else {
         // generate invoice
         $result = $object->generateDocument($object->modelpdf, $outputlangs, 0, 0, 0);
         if ($result <= 0) {
             $this->error = $object->error;
         }
         $fileparams = dol_most_recent_file($conf->commande->dir_output . '/' . $object->ref, preg_quote($object->ref, '/') . '[^\\-]+');
         if (is_array($fileparams) && array_key_exists('fullname', $fileparams) && !empty($fileparams['fullname'])) {
             $_SESSION["listofpaths"] = $fileparams['fullname'];
             $_SESSION["listofnames"] = basename($fileparams['fullname']);
             $_SESSION["listofmimes"] = dol_mimetype($fileparams['fullname']);
         }
     }
     $action = 'send';
     $actiontypecode = 'AC_FAC';
     $trigger_name = 'BILL_SENTBYMAIL';
     $paramname = 'id';
     $mode = 'emailfrominvoice';
     if (!empty($sendto)) {
         require_once __DIR__ . '/../tpl/actions_sendmails.inc.php';
     }
 }
 /**
  *	Function to build a document on disk using the generic odt module.
  *
  *	@param	Facture		$object					Object source to build document
  *	@param	Translate	$outputlangs			Lang output object
  * 	@param	string		$srctemplatepath	    Full path of source filename for generator using a template file
  *	@return	int         						1 if OK, <=0 if KO
  */
 function write_file($object, $outputlangs, $srctemplatepath)
 {
     global $user, $langs, $conf, $mysoc;
     if (empty($srctemplatepath)) {
         dol_syslog("doc_generic_odt::write_file parameter srctemplatepath empty", LOG_WARNING);
         return -1;
     }
     if (!is_object($outputlangs)) {
         $outputlangs = $langs;
     }
     $sav_charset_output = $outputlangs->charset_output;
     $outputlangs->charset_output = 'UTF-8';
     $outputlangs->load("main");
     $outputlangs->load("dict");
     $outputlangs->load("companies");
     $outputlangs->load("bills");
     if ($conf->facture->dir_output) {
         // If $object is id instead of object
         if (!is_object($object)) {
             $id = $object;
             $object = new Facture($this->db);
             $result = $object->fetch($id);
             if ($result < 0) {
                 dol_print_error($this->db, $object->error);
                 return -1;
             }
         }
         $dir = $conf->facture->dir_output;
         $objectref = dol_sanitizeFileName($object->ref);
         if (!preg_match('/specimen/i', $objectref)) {
             $dir .= "/" . $objectref;
         }
         $file = $dir . "/" . $objectref . ".odt";
         if (!file_exists($dir)) {
             if (dol_mkdir($dir) < 0) {
                 $this->error = $langs->transnoentities("ErrorCanNotCreateDir", $dir);
                 return -1;
             }
         }
         if (file_exists($dir)) {
             //print "srctemplatepath=".$srctemplatepath;exit;	// Src filename
             $newfile = basename($srctemplatepath);
             $newfiletmp = preg_replace('/\\.odt/i', '', $newfile);
             $newfiletmp = preg_replace('/template_/i', '', $newfiletmp);
             $newfiletmp = preg_replace('/modele_/i', '', $newfiletmp);
             $newfiletmp = $objectref . '_' . $newfiletmp;
             //$file=$dir.'/'.$newfiletmp.'.'.dol_print_date(dol_now(),'%Y%m%d%H%M%S').'.odt';
             $file = $dir . '/' . $newfiletmp . '.odt';
             //print "newdir=".$dir;
             //print "newfile=".$newfile;
             //print "file=".$file;
             //print "conf->societe->dir_temp=".$conf->societe->dir_temp;
             dol_mkdir($conf->facture->dir_temp);
             // If BILLING contact defined on invoice, we use it
             $usecontact = false;
             $arrayidcontact = $object->getIdContact('external', 'BILLING');
             if (count($arrayidcontact) > 0) {
                 $usecontact = true;
                 $result = $object->fetch_contact($arrayidcontact[0]);
             }
             // Recipient name
             if (!empty($usecontact)) {
                 // On peut utiliser le nom de la societe du contact
                 if ($conf->global->MAIN_USE_COMPANY_NAME_OF_CONTACT) {
                     $socobject = $object->contact;
                 } else {
                     $socobject = $object->client;
                 }
             } else {
                 $socobject = $object->client;
             }
             // Make substitution
             $substitutionarray = array('__FROM_NAME__' => $this->emetteur->nom, '__FROM_EMAIL__' => $this->emetteur->email, '__TOTAL_TTC__' => $object->total_ttc, '__TOTAL_HT__' => $object->total_ht, '__TOTAL_VAT__' => $object->total_vat);
             complete_substitutions_array($substitutionarray, $langs, $object);
             // Line of free text
             $newfreetext = '';
             $paramfreetext = 'FACTURE_FREE_TEXT';
             if (!empty($conf->global->{$paramfreetext})) {
                 $newfreetext = make_substitutions($conf->global->{$paramfreetext}, $substitutionarray);
             }
             // Open and load template
             require_once ODTPHP_PATH . 'odf.php';
             $odfHandler = new odf($srctemplatepath, array('PATH_TO_TMP' => $conf->facture->dir_temp, 'ZIP_PROXY' => 'PclZipProxy', 'DELIMITER_LEFT' => '{', 'DELIMITER_RIGHT' => '}'));
             // After construction $odfHandler->contentXml contains content and
             // [!-- BEGIN row.lines --]*[!-- END row.lines --] has been replaced by
             // [!-- BEGIN lines --]*[!-- END lines --]
             //print html_entity_decode($odfHandler->__toString());
             //print exit;
             // Make substitutions into odt of freetext
             try {
                 $odfHandler->setVars('free_text', $newfreetext, true, 'UTF-8');
             } catch (OdfException $e) {
             }
             // Make substitutions into odt of user info
             $tmparray = $this->get_substitutionarray_user($user, $outputlangs);
             //var_dump($tmparray); exit;
             foreach ($tmparray as $key => $value) {
                 try {
                     if (preg_match('/logo$/', $key)) {
                         //var_dump($value);exit;
                         if (file_exists($value)) {
                             $odfHandler->setImage($key, $value);
                         } else {
                             $odfHandler->setVars($key, 'ErrorFileNotFound', true, 'UTF-8');
                         }
                     } else {
                         $odfHandler->setVars($key, $value, true, 'UTF-8');
                     }
                 } catch (OdfException $e) {
                 }
             }
             // Make substitutions into odt of mysoc
             $tmparray = $this->get_substitutionarray_mysoc($mysoc, $outputlangs);
             //var_dump($tmparray); exit;
             foreach ($tmparray as $key => $value) {
                 try {
                     if (preg_match('/logo$/', $key)) {
                         //var_dump($value);exit;
                         if (file_exists($value)) {
                             $odfHandler->setImage($key, $value);
                         } else {
                             $odfHandler->setVars($key, 'ErrorFileNotFound', true, 'UTF-8');
                         }
                     } else {
                         $odfHandler->setVars($key, $value, true, 'UTF-8');
                     }
                 } catch (OdfException $e) {
                 }
             }
             // Make substitutions into odt of thirdparty
             $tmparray = $this->get_substitutionarray_thirdparty($socobject, $outputlangs);
             foreach ($tmparray as $key => $value) {
                 try {
                     if (preg_match('/logo$/', $key)) {
                         if (file_exists($value)) {
                             $odfHandler->setImage($key, $value);
                         } else {
                             $odfHandler->setVars($key, 'ErrorFileNotFound', true, 'UTF-8');
                         }
                     } else {
                         $odfHandler->setVars($key, $value, true, 'UTF-8');
                     }
                 } catch (OdfException $e) {
                 }
             }
             // Replace tags of object + external modules
             $tmparray = $this->get_substitutionarray_object($object, $outputlangs);
             complete_substitutions_array($tmparray, $outputlangs, $object);
             foreach ($tmparray as $key => $value) {
                 try {
                     if (preg_match('/logo$/', $key)) {
                         if (file_exists($value)) {
                             $odfHandler->setImage($key, $value);
                         } else {
                             $odfHandler->setVars($key, 'ErrorFileNotFound', true, 'UTF-8');
                         }
                     } else {
                         $odfHandler->setVars($key, $value, true, 'UTF-8');
                     }
                 } catch (OdfException $e) {
                 }
             }
             // Replace tags of lines
             try {
                 $listlines = $odfHandler->setSegment('lines');
                 foreach ($object->lines as $line) {
                     $tmparray = $this->get_substitutionarray_lines($line, $outputlangs);
                     foreach ($tmparray as $key => $val) {
                         try {
                             $listlines->setVars($key, $val, true, 'UTF-8');
                         } catch (OdfException $e) {
                         } catch (SegmentException $e) {
                         }
                     }
                     $listlines->merge();
                 }
                 $odfHandler->mergeSegment($listlines);
             } catch (OdfException $e) {
                 $this->error = $e->getMessage();
                 dol_syslog($this->error, LOG_WARNING);
                 return -1;
             }
             // Write new file
             //$result=$odfHandler->exportAsAttachedFile('toto');
             $odfHandler->saveToDisk($file);
             if (!empty($conf->global->MAIN_UMASK)) {
                 @chmod($file, octdec($conf->global->MAIN_UMASK));
             }
             $odfHandler = null;
             // Destroy object
             return 1;
             // Success
         } else {
             $this->error = $langs->transnoentities("ErrorCanNotCreateDir", $dir);
             return -1;
         }
     }
     return -1;
 }
Exemple #14
0
/**
 *  Complete or removed entries into a head array (used to build tabs) with value added by external modules.
 *  Such values are declared into $conf->modules_parts['tab'].
 *
 *  @param	Conf			$conf           Object conf
 *  @param  Translate		$langs          Object langs
 *  @param  object|null		$object         Object object
 *  @param  array			$head          	Object head
 *  @param  int				$h				New position to fill
 *  @param  string			$type           Value for object where objectvalue can be
 *                              			'thirdparty'       to add a tab in third party view
 *		                        	      	'intervention'     to add a tab in intervention view
 *     		                    	     	'supplier_order'   to add a tab in supplier order view
 *          		            	        'supplier_invoice' to add a tab in supplier invoice view
 *                  		    	        'invoice'          to add a tab in customer invoice view
 *                          			    'order'            to add a tab in customer order view
 *                      			        'product'          to add a tab in product view
 *                              			'propal'           to add a tab in propal view
 *                              			'user'             to add a tab in user view
 *                              			'group'            to add a tab in group view
 * 		        	               	     	'member'           to add a tab in fundation member view
 *      		                        	'categories_x'	   to add a tab in category view ('x': type of category (0=product, 1=supplier, 2=customer, 3=member)
 *      									'ecm'			   to add a tab for another ecm view
 *  @param  string		$mode  	        	'add' to complete head, 'remove' to remove entries
 *	@return	void
 */
function complete_head_from_modules($conf, $langs, $object, &$head, &$h, $type, $mode = 'add')
{
    if (isset($conf->modules_parts['tabs'][$type]) && is_array($conf->modules_parts['tabs'][$type])) {
        foreach ($conf->modules_parts['tabs'][$type] as $value) {
            $values = explode(':', $value);
            if ($mode == 'add' && !preg_match('/^\\-/', $values[1])) {
                if (count($values) == 6) {
                    if ($values[0] != $type) {
                        continue;
                    }
                    if (verifCond($values[4])) {
                        if ($values[3]) {
                            $langs->load($values[3]);
                        }
                        if (preg_match('/SUBSTITUTION_([^_]+)/i', $values[2], $reg)) {
                            $substitutionarray = array();
                            complete_substitutions_array($substitutionarray, $langs, $object);
                            $label = make_substitutions($reg[1], $substitutionarray);
                        } else {
                            $label = $langs->trans($values[2]);
                        }
                        $head[$h][0] = dol_buildpath(preg_replace('/__ID__/i', is_object($object) && !empty($object->id) ? $object->id : '', $values[5]), 1);
                        $head[$h][1] = $label;
                        $head[$h][2] = str_replace('+', '', $values[1]);
                        $h++;
                    }
                } else {
                    if (count($values) == 5) {
                        if ($values[0] != $type) {
                            continue;
                        }
                        if ($values[3]) {
                            $langs->load($values[3]);
                        }
                        if (preg_match('/SUBSTITUTION_([^_]+)/i', $values[2], $reg)) {
                            $substitutionarray = array();
                            complete_substitutions_array($substitutionarray, $langs, $object);
                            $label = make_substitutions($reg[1], $substitutionarray);
                        } else {
                            $label = $langs->trans($values[2]);
                        }
                        $head[$h][0] = dol_buildpath(preg_replace('/__ID__/i', is_object($object) && !empty($object->id) ? $object->id : '', $values[4]), 1);
                        $head[$h][1] = $label;
                        $head[$h][2] = str_replace('+', '', $values[1]);
                        $h++;
                    }
                }
            } else {
                if ($mode == 'remove' && preg_match('/^\\-/', $values[1])) {
                    if ($values[0] != $type) {
                        continue;
                    }
                    $tabname = str_replace('-', '', $values[1]);
                    foreach ($head as $key => $val) {
                        $condition = !empty($values[3]) ? verifCond($values[3]) : 1;
                        if ($head[$key][2] == $tabname && $condition) {
                            unset($head[$key]);
                            break;
                        }
                    }
                }
            }
        }
    }
}
Exemple #15
0
             $error++;
             setEventMessage('Failed to generate image file of barcode for code=' . $code . ' encoding=' . $encoding . ' file=' . basename($barcodeimage), 'errors');
         }
     } else {
         $error++;
         setEventMessage("Error, encoding " . $encoding . " is not supported by encoder " . $generator . '. You must choose another barcode type or install a barcode generation engine that support ' . $encoding, 'errors');
     }
 }
 if (!$error) {
     // List of values to scan for a replacement
     $substitutionarray = array('%LOGIN%' => $user->login, '%COMPANY%' => $mysoc->name, '%ADDRESS%' => $mysoc->address, '%ZIP%' => $mysoc->zip, '%TOWN%' => $mysoc->town, '%COUNTRY%' => $mysoc->country, '%COUNTRY_CODE%' => $mysoc->country_code, '%EMAIL%' => $mysoc->email, '%YEAR%' => $year, '%MONTH%' => $month, '%DAY%' => $day, '%DOL_MAIN_URL_ROOT%' => DOL_MAIN_URL_ROOT, '%SERVER%' => "http://" . $_SERVER["SERVER_NAME"] . "/");
     complete_substitutions_array($substitutionarray, $langs);
     // For labels
     if ($mode == 'label') {
         $txtforsticker = "%PHOTO%";
         $textleft = make_substitutions($txtforsticker, $substitutionarray);
         $textheader = '';
         $textfooter = '';
         $textright = '';
         $forceimgscalewidth = empty($conf->global->BARCODE_FORCEIMGSCALEWIDTH) ? 1 : $conf->global->BARCODE_FORCEIMGSCALEWIDTH;
         $forceimgscaleheight = empty($conf->global->BARCODE_FORCEIMGSCALEHEIGHT) ? 1 : $conf->global->BARCODE_FORCEIMGSCALEHEIGHT;
         for ($i = 0; $i < $numberofsticker; $i++) {
             $arrayofmembers[] = array('textleft' => $textleft, 'textheader' => $textheader, 'textfooter' => $textfooter, 'textright' => $textright, 'photo' => $barcodeimage);
         }
     }
     $i++;
     $mesg = '';
     // Build and output PDF
     if ($mode == 'label') {
         if (!count($arrayofmembers)) {
             $mesg = $langs->trans("ErrorRecordNotFound");
Exemple #16
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);
 }
Exemple #17
0
/**
 *  Show footer of page for PDF generation
 *
 *	@param	PDF			$pdf     		The PDF factory
 *  @param  Translate	$outputlangs	Object lang for output
 * 	@param	string		$paramfreetext	Constant name of free text
 * 	@param	Societe		$fromcompany	Object company
 * 	@param	int			$marge_basse	Margin bottom we use for the autobreak
 * 	@param	int			$marge_gauche	Margin left (no more used)
 * 	@param	int			$page_hauteur	Page height (no more used)
 * 	@param	Object		$object			Object shown in PDF
 * 	@param	int			$showdetails	Show company details into footer. This param seems to not be used by standard version. (1=Show address, 2=Show managers, 3=Both)
 *  @param	int			$hidefreetext	1=Hide free text, 0=Show free text
 * 	@return	int							Return height of bottom margin including footer text
 */
function pdf_pagefoot(&$pdf, $outputlangs, $paramfreetext, $fromcompany, $marge_basse, $marge_gauche, $page_hauteur, $object, $showdetails = 0, $hidefreetext = 0)
{
    global $conf, $user;
    $outputlangs->load("dict");
    $line = '';
    $dims = $pdf->getPageDimensions();
    // Line of free text
    if (empty($hidefreetext) && !empty($conf->global->{$paramfreetext})) {
        // Make substitution
        $substitutionarray = array('__FROM_NAME__' => $fromcompany->name, '__FROM_EMAIL__' => $fromcompany->email, '__TOTAL_TTC__' => $object->total_ttc, '__TOTAL_HT__' => $object->total_ht, '__TOTAL_VAT__' => $object->total_vat);
        complete_substitutions_array($substitutionarray, $outputlangs, $object);
        $newfreetext = make_substitutions($conf->global->{$paramfreetext}, $substitutionarray);
        $line .= $outputlangs->convToOutputCharset($newfreetext);
    }
    // First line of company infos
    $line1 = "";
    $line2 = "";
    $line3 = "";
    $line4 = "";
    if ($showdetails) {
        // Company name
        if ($fromcompany->name) {
            $line1 .= ($line1 ? " - " : "") . $outputlangs->transnoentities("RegisteredOffice") . ": " . $fromcompany->name;
        }
        // Address
        if ($fromcompany->address) {
            $line1 .= ($line1 ? " - " : "") . $fromcompany->address;
        }
        // Zip code
        if ($fromcompany->zip) {
            $line1 .= ($line1 ? " - " : "") . $fromcompany->zip;
        }
        // Town
        if ($fromcompany->town) {
            $line1 .= ($line1 ? " " : "") . $fromcompany->town;
        }
        // Phone
        if ($fromcompany->phone) {
            $line1 .= ($line1 ? " - " : "") . $outputlangs->transnoentities("Phone") . ": " . $fromcompany->phone;
        }
        // Fax
        if ($fromcompany->fax) {
            $line1 .= ($line1 ? " - " : "") . $outputlangs->transnoentities("Fax") . ": " . $fromcompany->fax;
        }
        // URL
        if ($fromcompany->url) {
            $line2 .= ($line2 ? " - " : "") . $fromcompany->url;
        }
        // Email
        if ($fromcompany->email) {
            $line2 .= ($line2 ? " - " : "") . $fromcompany->email;
        }
    }
    if ($showdetails || $fromcompany->country_code == 'DE') {
        // Managers
        if ($fromcompany->managers) {
            $line2 .= ($line2 ? " - " : "") . $fromcompany->managers;
        }
    }
    // Line 3 of company infos
    // Juridical status
    if ($fromcompany->forme_juridique_code) {
        $line3 .= ($line3 ? " - " : "") . $outputlangs->convToOutputCharset(getFormeJuridiqueLabel($fromcompany->forme_juridique_code));
    }
    // Capital
    if ($fromcompany->capital) {
        $tmpamounttoshow = price2num($fromcompany->capital);
        // This field is a free string
        if (is_numeric($tmpamounttoshow) && $tmpamounttoshow > 0) {
            $line3 .= ($line3 ? " - " : "") . $outputlangs->transnoentities("CapitalOf", price($tmpamounttoshow, 0, $outputlangs, 0, 0, 0, $conf->currency));
        } else {
            $line3 .= ($line3 ? " - " : "") . $outputlangs->transnoentities("CapitalOf", $tmpamounttoshow, $outputlangs);
        }
    }
    // Prof Id 1
    if ($fromcompany->idprof1 && ($fromcompany->country_code != 'FR' || !$fromcompany->idprof2)) {
        $field = $outputlangs->transcountrynoentities("ProfId1", $fromcompany->country_code);
        if (preg_match('/\\((.*)\\)/i', $field, $reg)) {
            $field = $reg[1];
        }
        $line3 .= ($line3 ? " - " : "") . $field . ": " . $outputlangs->convToOutputCharset($fromcompany->idprof1);
    }
    // Prof Id 2
    if ($fromcompany->idprof2) {
        $field = $outputlangs->transcountrynoentities("ProfId2", $fromcompany->country_code);
        if (preg_match('/\\((.*)\\)/i', $field, $reg)) {
            $field = $reg[1];
        }
        $line3 .= ($line3 ? " - " : "") . $field . ": " . $outputlangs->convToOutputCharset($fromcompany->idprof2);
    }
    // Line 4 of company infos
    // Prof Id 3
    if ($fromcompany->idprof3) {
        $field = $outputlangs->transcountrynoentities("ProfId3", $fromcompany->country_code);
        if (preg_match('/\\((.*)\\)/i', $field, $reg)) {
            $field = $reg[1];
        }
        $line4 .= ($line4 ? " - " : "") . $field . ": " . $outputlangs->convToOutputCharset($fromcompany->idprof3);
    }
    // Prof Id 4
    if ($fromcompany->idprof4) {
        $field = $outputlangs->transcountrynoentities("ProfId4", $fromcompany->country_code);
        if (preg_match('/\\((.*)\\)/i', $field, $reg)) {
            $field = $reg[1];
        }
        $line4 .= ($line4 ? " - " : "") . $field . ": " . $outputlangs->convToOutputCharset($fromcompany->idprof4);
    }
    // IntraCommunautary VAT
    if ($fromcompany->tva_intra != '') {
        $line4 .= ($line4 ? " - " : "") . $outputlangs->transnoentities("VATIntraShort") . ": " . $outputlangs->convToOutputCharset($fromcompany->tva_intra);
    }
    $pdf->SetFont('', '', 7);
    $pdf->SetDrawColor(224, 224, 224);
    // The start of the bottom of this page footer is positioned according to # of lines
    $freetextheight = 0;
    if ($line) {
        //$line="eee<br>\nfd<strong>sf</strong>sdf<br>\nghfghg<br>";
        if (empty($conf->global->PDF_ALLOW_HTML_FOR_FREE_TEXT)) {
            $width = 20000;
            $align = 'L';
            // By default, ask a manual break: We use a large value 20000, to not have automatic wrap. This make user understand, he need to add CR on its text.
            if (!empty($conf->global->MAIN_USE_AUTOWRAP_ON_FREETEXT)) {
                $width = 200;
                $align = 'C';
            }
            $freetextheight = $pdf->getStringHeight($width, $line);
        } else {
            $freetextheight = pdfGetHeightForHtmlContent($pdf, dol_htmlentitiesbr($line, 1, 'UTF-8', 0));
            // New method (works for HTML content)
            //print '<br>'.$freetextheight;exit;
        }
    }
    $marginwithfooter = $marge_basse + $freetextheight + (!empty($line1) ? 3 : 0) + (!empty($line2) ? 3 : 0) + (!empty($line3) ? 3 : 0) + (!empty($line4) ? 3 : 0);
    $posy = $marginwithfooter + 0;
    if ($line) {
        $pdf->SetXY($dims['lm'], -$posy);
        if (empty($conf->global->PDF_ALLOW_HTML_FOR_FREE_TEXT)) {
            $pdf->MultiCell(0, 3, $line, 0, $align, 0);
        } else {
            $pdf->writeHTMLCell($pdf->page_largeur - $pdf->margin_left - $pdf->margin_right, $freetextheight, $dims['lm'], $dims['hk'] - $marginwithfooter, dol_htmlentitiesbr($line, 1, 'UTF-8', 0));
        }
        $posy -= $freetextheight;
    }
    $pdf->SetY(-$posy);
    $pdf->line($dims['lm'], $dims['hk'] - $posy, $dims['wk'] - $dims['rm'], $dims['hk'] - $posy);
    $posy--;
    if (!empty($line1)) {
        $pdf->SetFont('', 'B', 7);
        $pdf->SetXY($dims['lm'], -$posy);
        $pdf->MultiCell($dims['wk'] - $dims['rm'], 2, $line1, 0, 'C', 0);
        $posy -= 3;
        $pdf->SetFont('', '', 7);
    }
    if (!empty($line2)) {
        $pdf->SetFont('', 'B', 7);
        $pdf->SetXY($dims['lm'], -$posy);
        $pdf->MultiCell($dims['wk'] - $dims['rm'], 2, $line2, 0, 'C', 0);
        $posy -= 3;
        $pdf->SetFont('', '', 7);
    }
    if (!empty($line3)) {
        $pdf->SetXY($dims['lm'], -$posy);
        $pdf->MultiCell($dims['wk'] - $dims['rm'], 2, $line3, 0, 'C', 0);
    }
    if (!empty($line4)) {
        $posy -= 3;
        $pdf->SetXY($dims['lm'], -$posy);
        $pdf->MultiCell($dims['wk'] - $dims['rm'], 2, $line4, 0, 'C', 0);
    }
    // Show page nb only on iso languages (so default Helvetica font)
    if (strtolower(pdf_getPDFFont($outputlangs)) == 'helvetica') {
        $pdf->SetXY(-20, -$posy);
        //print 'xxx'.$pdf->PageNo().'-'.$pdf->getAliasNbPages().'-'.$pdf->getAliasNumPage();exit;
        if (empty($conf->global->MAIN_USE_FPDF)) {
            $pdf->MultiCell(13, 2, $pdf->PageNo() . '/' . $pdf->getAliasNbPages(), 0, 'R', 0);
        } else {
            $pdf->MultiCell(13, 2, $pdf->PageNo() . '/{nb}', 0, 'R', 0);
        }
    }
    return $marginwithfooter;
}
Exemple #18
0
 $other4 = $other[3];
 $other5 = $other[4];
 // Array of possible substitutions (See also fie mailing-send.php that should manage same substitutions)
 $signature = !empty($user->signature) ? $user->signature : '';
 $substitutionarray = array('__ID__' => $obj->source_id, '__EMAIL__' => $obj->email, '__LASTNAME__' => $obj2->lastname, '__FIRSTNAME__' => $obj2->firstname, '__MAILTOEMAIL__' => '<a href="mailto:' . $obj2->email . '">' . $obj2->email . '</a>', '__OTHER1__' => $other1, '__OTHER2__' => $other2, '__OTHER3__' => $other3, '__OTHER4__' => $other4, '__OTHER5__' => $other5, '__SIGNATURE__' => $signature, '__CHECK_READ__' => '<img src="' . DOL_MAIN_URL_ROOT . '/public/emailing/mailing-read.php?tag=' . $obj2->tag . '&securitykey=' . urlencode($conf->global->MAILING_EMAIL_UNSUBSCRIBE_KEY) . '" width="1" height="1" style="width:1px;height:1px" border="0"/>', '__UNSUBSCRIBE__' => '<a href="' . DOL_MAIN_URL_ROOT . '/public/emailing/mailing-unsubscribe.php?tag=' . $obj2->tag . '&unsuscrib=1&securitykey=' . urlencode($conf->global->MAILING_EMAIL_UNSUBSCRIBE_KEY) . '" target="_blank">' . $langs->trans("MailUnsubcribe") . '</a>');
 if (!empty($conf->paypal->enabled) && !empty($conf->global->PAYPAL_SECURITY_TOKEN)) {
     $substitutionarray['__SECUREKEYPAYPAL__'] = dol_hash($conf->global->PAYPAL_SECURITY_TOKEN, 2);
     if (empty($conf->global->PAYPAL_SECURITY_TOKEN_UNIQUE)) {
         $substitutionarray['__SECUREKEYPAYPAL_MEMBER__'] = dol_hash($conf->global->PAYPAL_SECURITY_TOKEN, 2);
     } else {
         $substitutionarray['__SECUREKEYPAYPAL_MEMBER__'] = dol_hash($conf->global->PAYPAL_SECURITY_TOKEN . 'membersubscription' . $obj->source_id, 2);
     }
 }
 complete_substitutions_array($substitutionarray, $langs);
 $newsubject = make_substitutions($subject, $substitutionarray);
 $newmessage = make_substitutions($message, $substitutionarray);
 $substitutionisok = true;
 // Fabrication du mail
 $mail = new CMailFile($newsubject, $sendto, $from, $newmessage, array(), array(), array(), '', '', 0, $msgishtml, $errorsto);
 if ($mail->error) {
     $res = 0;
 }
 if (!$substitutionisok) {
     $mail->error = 'Some substitution failed';
     $res = 0;
 }
 // Send Email
 if ($res) {
     $res = $mail->sendfile();
 }
 if ($res) {
 /**
  *	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;
     }
 }
Exemple #20
0
/**
 * 	Format phone numbers according to country
 * 	@param 		phone 		Phone number to format
 * 	@param 		country 	Country to use for formatting
 * 	@param 		cid 		Id of contact if known
 * 	@param 		socid 		Id of third party if known
 * 	@param 		addlink		0=no link to create action
 * 	@param 		separ 		separation between numbers for a better visibility example : xx.xx.xx.xx.xx
 * 	@return 	string 		Formated phone number
 */
function dol_print_phone($phone, $country = "FR", $cid = 0, $socid = 0, $addlink = 0, $separ = "&nbsp;")
{
    global $conf, $user, $langs;
    // Clean phone parameter
    $phone = preg_replace("/[\\s.-]/", "", trim($phone));
    if (empty($phone)) {
        return '';
    }
    $newphone = $phone;
    if (strtoupper($country) == "FR") {
        // France
        if (dol_strlen($phone) == 10) {
            $newphone = substr($newphone, 0, 2) . $separ . substr($newphone, 2, 2) . $separ . substr($newphone, 4, 2) . $separ . substr($newphone, 6, 2) . $separ . substr($newphone, 8, 2);
        } elseif (dol_strlen($newphone) == 7) {
            $newphone = substr($newphone, 0, 3) . $separ . substr($newphone, 3, 2) . $separ . substr($newphone, 5, 2);
        } elseif (dol_strlen($newphone) == 9) {
            $newphone = substr($newphone, 0, 2) . $separ . substr($newphone, 2, 3) . $separ . substr($newphone, 5, 2) . $separ . substr($newphone, 7, 2);
        } elseif (dol_strlen($newphone) == 11) {
            $newphone = substr($newphone, 0, 3) . $separ . substr($newphone, 3, 2) . $separ . substr($newphone, 5, 2) . $separ . substr($newphone, 7, 2) . $separ . substr($newphone, 9, 2);
        } elseif (dol_strlen($newphone) == 12) {
            $newphone = substr($newphone, 0, 4) . $separ . substr($newphone, 4, 2) . $separ . substr($newphone, 6, 2) . $separ . substr($newphone, 8, 2) . $separ . substr($newphone, 10, 2);
        }
    }
    if (!empty($addlink)) {
        if ($conf->clicktodial->enabled) {
            if (empty($user->clicktodial_loaded)) {
                $user->fetch_clicktodial();
            }
            if (empty($conf->global->CLICKTODIAL_URL)) {
                $urlmask = 'ErrorClickToDialModuleNotConfigured';
            } else {
                $urlmask = $conf->global->CLICKTODIAL_URL;
            }
            // This line is for backward compatibility
            $url = sprintf($urlmask, urlencode($phone), urlencode($user->clicktodial_poste), urlencode($user->clicktodial_login), urlencode($user->clicktodial_password));
            // Thoose lines are for substitution
            $substitarray = array('__PHONEFROM__' => urlencode($user->clicktodial_poste), '__PHONETO__' => urlencode($phone), '__LOGIN__' => urlencode($user->clicktodial_login), '__PASS__' => urlencode($user->clicktodial_password));
            $url = make_substitutions($url, $substitarray);
            $newphonesav = $newphone;
            $newphone = '<a href="' . $url . '"';
            if (!empty($conf->global->CLICKTODIAL_FORCENEWTARGET)) {
                $newphone .= ' target="_blank"';
            }
            $newphone .= '>' . $newphonesav . '</a>';
        }
        //if (($cid || $socid) && $conf->agenda->enabled && $user->rights->agenda->myactions->create)
        if ($conf->agenda->enabled && $user->rights->agenda->myactions->create) {
            $type = 'AC_TEL';
            $link = '';
            if ($addlink == 'AC_FAX') {
                $type = 'AC_FAX';
            }
            if (!empty($conf->global->AGENDA_ADDACTIONFORPHONE)) {
                $link = '<a href="' . DOL_URL_ROOT . '/comm/action/fiche.php?action=create&amp;backtopage=1&amp;actioncode=' . $type . ($cid ? '&amp;contactid=' . $cid : '') . ($socid ? '&amp;socid=' . $socid : '') . '">' . img_object($langs->trans("AddAction"), "calendar") . '</a>';
            }
            $newphone = '<table class="nobordernopadding"><tr><td>' . $newphone . ' </td><td>&nbsp;' . $link . '</td></tr></table>';
        }
    }
    return $newphone;
}
 /**
  *	Function to build a document on disk using the generic odt module.
  *
  *	@param		Propale		$object				Object source to build document
  *	@param		Translate	$outputlangs		Lang output object
  * 	@param		string		$srctemplatepath	Full path of source filename for generator using a template file
  *  @param		int			$hidedetails		Do not show line details
  *  @param		int			$hidedesc			Do not show desc
  *  @param		int			$hideref			Do not show ref
  *	@return		int         					1 if OK, <=0 if KO
  */
 function write_file($object, $outputlangs, $srctemplatepath, $hidedetails = 0, $hidedesc = 0, $hideref = 0)
 {
     global $user, $langs, $conf, $mysoc, $hookmanager;
     if (empty($srctemplatepath)) {
         dol_syslog("doc_generic_odt::write_file parameter srctemplatepath empty", LOG_WARNING);
         return -1;
     }
     // Add odtgeneration hook
     if (!is_object($hookmanager)) {
         include_once DOL_DOCUMENT_ROOT . '/core/class/hookmanager.class.php';
         $hookmanager = new HookManager($this->db);
     }
     $hookmanager->initHooks(array('odtgeneration'));
     global $action;
     if (!is_object($outputlangs)) {
         $outputlangs = $langs;
     }
     $sav_charset_output = $outputlangs->charset_output;
     $outputlangs->charset_output = 'UTF-8';
     $outputlangs->load("main");
     $outputlangs->load("dict");
     $outputlangs->load("companies");
     $outputlangs->load("bills");
     if ($conf->supplier_proposal->dir_output) {
         // If $object is id instead of object
         if (!is_object($object)) {
             $id = $object;
             $object = new SupplierProposal($this->db);
             $result = $object->fetch($id);
             if ($result < 0) {
                 dol_print_error($this->db, $object->error);
                 return -1;
             }
         }
         $dir = $conf->supplier_proposal->dir_output;
         $objectref = dol_sanitizeFileName($object->ref);
         if (!preg_match('/specimen/i', $objectref)) {
             $dir .= "/" . $objectref;
         }
         $file = $dir . "/" . $objectref . ".odt";
         if (!file_exists($dir)) {
             if (dol_mkdir($dir) < 0) {
                 $this->error = $langs->transnoentities("ErrorCanNotCreateDir", $dir);
                 return -1;
             }
         }
         if (file_exists($dir)) {
             //print "srctemplatepath=".$srctemplatepath;	// Src filename
             $newfile = basename($srctemplatepath);
             $newfiletmp = preg_replace('/\\.od(t|s)/i', '', $newfile);
             $newfiletmp = preg_replace('/template_/i', '', $newfiletmp);
             $newfiletmp = preg_replace('/modele_/i', '', $newfiletmp);
             $newfiletmp = $objectref . '_' . $newfiletmp;
             // Get extension (ods or odt)
             $newfileformat = substr($newfile, strrpos($newfile, '.') + 1);
             if (!empty($conf->global->MAIN_DOC_USE_TIMING)) {
                 $filename = $newfiletmp . '.' . dol_print_date(dol_now(), '%Y%m%d%H%M%S') . '.' . $newfileformat;
             } else {
                 $filename = $newfiletmp . '.' . $newfileformat;
             }
             $file = $dir . '/' . $filename;
             //print "newdir=".$dir;
             //print "newfile=".$newfile;
             //print "file=".$file;
             //print "conf->propal->dir_temp=".$conf->propal->dir_temp;
             dol_mkdir($conf->supplier_proposal->dir_temp);
             // If BILLING contact defined on invoice, we use it
             $usecontact = false;
             $arrayidcontact = $object->getIdContact('external', 'BILLING');
             if (count($arrayidcontact) > 0) {
                 $usecontact = true;
                 $result = $object->fetch_contact($arrayidcontact[0]);
             }
             // Recipient name
             if (!empty($usecontact)) {
                 // On peut utiliser le nom de la societe du contact
                 if (!empty($conf->global->MAIN_USE_COMPANY_NAME_OF_CONTACT)) {
                     $socobject = $object->contact;
                 } else {
                     $socobject = $object->client;
                 }
             } else {
                 $socobject = $object->client;
             }
             // Make substitution
             $substitutionarray = array('__FROM_NAME__' => $this->emetteur->name, '__FROM_EMAIL__' => $this->emetteur->email, '__TOTAL_TTC__' => $object->total_ttc, '__TOTAL_HT__' => $object->total_ht, '__TOTAL_VAT__' => $object->total_vat);
             complete_substitutions_array($substitutionarray, $langs, $object);
             // Call the ODTSubstitution hook
             $parameters = array('file' => $file, 'object' => $object, 'outputlangs' => $outputlangs, 'substitutionarray' => &$substitutionarray);
             $reshook = $hookmanager->executeHooks('ODTSubstitution', $parameters, $this, $action);
             // Note that $action and $object may have been modified by some hooks
             // Line of free text
             $newfreetext = '';
             $paramfreetext = 'SUPPLIER_PROPOSAL_FREE_TEXT';
             if (!empty($conf->global->{$paramfreetext})) {
                 $newfreetext = make_substitutions($conf->global->{$paramfreetext}, $substitutionarray);
             }
             // Open and load template
             require_once ODTPHP_PATH . 'odf.php';
             try {
                 $odfHandler = new odf($srctemplatepath, array('PATH_TO_TMP' => $conf->supplier_proposal->dir_temp, 'ZIP_PROXY' => 'PclZipProxy', 'DELIMITER_LEFT' => '{', 'DELIMITER_RIGHT' => '}'));
             } catch (Exception $e) {
                 $this->error = $e->getMessage();
                 return -1;
             }
             // After construction $odfHandler->contentXml contains content and
             // [!-- BEGIN row.lines --]*[!-- END row.lines --] has been replaced by
             // [!-- BEGIN lines --]*[!-- END lines --]
             //print html_entity_decode($odfHandler->__toString());
             //print exit;
             // Make substitutions into odt of freetext
             try {
                 $odfHandler->setVars('free_text', $newfreetext, true, 'UTF-8');
             } catch (OdfException $e) {
             }
             // Make substitutions into odt
             $array_user = $this->get_substitutionarray_user($user, $outputlangs);
             $array_soc = $this->get_substitutionarray_mysoc($mysoc, $outputlangs);
             $array_thirdparty = $this->get_substitutionarray_thirdparty($socobject, $outputlangs);
             $array_objet = $this->get_substitutionarray_object($object, $outputlangs);
             $array_other = $this->get_substitutionarray_other($outputlangs);
             $tmparray = array_merge($array_user, $array_soc, $array_thirdparty, $array_objet, $array_other);
             complete_substitutions_array($tmparray, $outputlangs, $object);
             // Call the ODTSubstitution hook
             $parameters = array('odfHandler' => &$odfHandler, 'file' => $file, 'object' => $object, 'outputlangs' => $outputlangs, 'substitutionarray' => &$tmparray);
             $reshook = $hookmanager->executeHooks('ODTSubstitution', $parameters, $this, $action);
             // Note that $action and $object may have been modified by some hooks
             foreach ($tmparray as $key => $value) {
                 try {
                     if (preg_match('/logo$/', $key)) {
                         if (file_exists($value)) {
                             $odfHandler->setImage($key, $value);
                         } else {
                             $odfHandler->setVars($key, 'ErrorFileNotFound', true, 'UTF-8');
                         }
                     } else {
                         $odfHandler->setVars($key, $value, true, 'UTF-8');
                     }
                 } catch (OdfException $e) {
                 }
             }
             // Replace tags of lines
             try {
                 $listlines = $odfHandler->setSegment('lines');
                 foreach ($object->lines as $line) {
                     $tmparray = $this->get_substitutionarray_lines($line, $outputlangs);
                     complete_substitutions_array($tmparray, $outputlangs, $object, $line, "completesubstitutionarray_lines");
                     // Call the ODTSubstitutionLine hook
                     $parameters = array('odfHandler' => &$odfHandler, 'file' => $file, 'object' => $object, 'outputlangs' => $outputlangs, 'substitutionarray' => &$tmparray, 'line' => $line);
                     $reshook = $hookmanager->executeHooks('ODTSubstitutionLine', $parameters, $this, $action);
                     // Note that $action and $object may have been modified by some hooks
                     foreach ($tmparray as $key => $val) {
                         try {
                             $listlines->setVars($key, $val, true, 'UTF-8');
                         } catch (OdfException $e) {
                         } catch (SegmentException $e) {
                         }
                     }
                     $listlines->merge();
                 }
                 $odfHandler->mergeSegment($listlines);
             } catch (OdfException $e) {
                 $this->error = $e->getMessage();
                 dol_syslog($this->error, LOG_WARNING);
                 return -1;
             }
             // Replace labels translated
             $tmparray = $outputlangs->get_translations_for_substitutions();
             foreach ($tmparray as $key => $value) {
                 try {
                     $odfHandler->setVars($key, $value, true, 'UTF-8');
                 } catch (OdfException $e) {
                 }
             }
             // Call the beforeODTSave hook
             $parameters = array('odfHandler' => &$odfHandler, 'file' => $file, 'object' => $object, 'outputlangs' => $outputlangs, 'substitutionarray' => &$tmparray);
             $reshook = $hookmanager->executeHooks('beforeODTSave', $parameters, $this, $action);
             // Note that $action and $object may have been modified by some hooks
             // Write new file
             if (!empty($conf->global->MAIN_ODT_AS_PDF)) {
                 try {
                     $odfHandler->exportAsAttachedPDF($file);
                 } catch (Exception $e) {
                     $this->error = $e->getMessage();
                     return -1;
                 }
             } else {
                 try {
                     $odfHandler->saveToDisk($file);
                 } catch (Exception $e) {
                     $this->error = $e->getMessage();
                     return -1;
                 }
             }
             $parameters = array('odfHandler' => &$odfHandler, 'file' => $file, 'object' => $object, 'outputlangs' => $outputlangs, 'substitutionarray' => &$tmparray);
             $reshook = $hookmanager->executeHooks('afterODTCreation', $parameters, $this, $action);
             // Note that $action and $object may have been modified by some hooks
             if (!empty($conf->global->MAIN_UMASK)) {
                 @chmod($file, octdec($conf->global->MAIN_UMASK));
             }
             $odfHandler = null;
             // Destroy object
             return 1;
             // Success
         } else {
             $this->error = $langs->transnoentities("ErrorCanNotCreateDir", $dir);
             return -1;
         }
     }
     return -1;
 }
 /**
  * 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);
 }
             } else {
                 $html = $content_block->ownerDocument->saveXML($content_block);
                 // essentially outerHTML
             }
             // post-processing cleanup
             $html = preg_replace('!<p>[\\s\\h\\v]*</p>!u', '', $html);
             if ($links == 'remove') {
                 $html = preg_replace('!</?a[^>]*>!', '', $html);
             }
             // get text sample for language detection
             $text_sample = strip_tags(substr($html, 0, 500));
             if ($options->message_to_prepend) {
                 $html = make_substitutions($options->message_to_prepend) . $html;
             }
             if ($options->message_to_append) {
                 $html .= make_substitutions($options->message_to_append);
             }
             // filter XSS
             if ($xss_filter) {
                 debug('Filtering HTML to remove XSS');
                 $html = htmLawed::hl($html, array('safe' => 1, 'deny_attribute' => 'style', 'comment' => 1, 'cdata' => 1));
             }
             set_cached($permalink, $html);
         }
     }
 }
 $newitem->addElement('guid', $item->get_permalink(), array('isPermaLink' => 'true'));
 // add content
 if ($options->summary === true) {
     // get summary
     $summary = '';
Exemple #24
0
 /**
  * Make substitution
  *
  * @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->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->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, '%CIVILITE%' => $this->getCivilityLabel($msgishtml ? 0 : 1), '%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, '%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, '%INFOS%' => $msgishtml ? dol_htmlentitiesbr($infos) : $infos, '%PRENOM%' => $msgishtml ? dol_htmlentitiesbr($this->Firstname) : $this->Firstname, '%NOM%' => $msgishtml ? dol_htmlentitiesbr($this->Lastname) : $this->Lastname, '%SOCIETE%' => $msgishtml ? dol_htmlentitiesbr($this->societe) : $this->societe, '%ADRESSE%' => $msgishtml ? dol_htmlentitiesbr($this->address) : $this->address, '%CP%' => $msgishtml ? dol_htmlentitiesbr($this->zip) : $this->zip, '%VILLE%' => $msgishtml ? dol_htmlentitiesbr($this->town) : $this->town, '%PAYS%' => $msgishtml ? dol_htmlentitiesbr($this->country) : $this->country);
     complete_substitutions_array($substitutionarray, $langs);
     return make_substitutions($text, $substitutionarray);
 }