17 include_once (
"FDL/Class.Doc.php");
 
   18 include_once (
"FDL/sendmail.php");
 
   22     $docid = GetHttpVars(
"id");
 
   23     $cr = GetHttpVars(
"cr"); 
 
   30     $err = $famMail->control(
'create');
 
   33     $tmailto = $tmailcc = $tmailbcc = array();
 
   34     $mailfrom = GetHttpVars(
"_mail_from");
 
   40         $tmailto[$format] = array();
 
   41         $tmailcc[$format] = array();
 
   42         $tmailbcc[$format] = array();
 
   46     $mt = GetHttpVars(
"to"); 
 
   48         $rtype = GetHttpVars(
"_mail_copymode", 
"");
 
   49         $raddr = GetHttpVars(
"_mail_recip", 
"");
 
   50         $idraddr = GetHttpVars(
"_mail_recipid", 
"");
 
   51         $tformat = GetHttpVars(
"_mail_sendformat", 
"");
 
   52         if ((is_array($raddr)) && (count($raddr) > 0)) {
 
   53             foreach ($raddr as $k => $v) {
 
   56                     if ($tformat[$k] == 
"") $tformat[$k] = 
"plain";
 
   59                             $tmailcc[$tformat[$k]][$v] = $v;
 
   63                             $tmailbcc[$tformat[$k]][$v] = $v;
 
   67                             $tmailto[$tformat[$k]][$v] = $v;
 
   68                             if ($idraddr[$k] > 0) $tuid[] = $idraddr[$k];
 
   76         $tmailto[
"plain"][0] = $mt;
 
   77         $oldcc = GetHttpVars(
"cc");
 
   78         if ($oldcc) $tmailcc[
"plain"][0] = $oldcc;
 
   79         $oldbcc = GetHttpVars(
"bcc");
 
   80         if ($oldbcc) $tmailbcc[
"plain"][0] = $oldbcc;
 
   81         if ($mailfrom == 
"") $mailfrom = GetHttpVars(
"from");
 
   90         $mailto = implode(
",", $tmailto[$format]);
 
   91         $mailcc = implode(
",", $tmailcc[$format]);
 
   92         $mailbcc = implode(
",", $tmailbcc[$format]);
 
   94         setHttpVar(
"_mail_to", $mailto);
 
   95         setHttpVar(
"_mail_cc", $mailcc);
 
   96         setHttpVar(
"_mail_bcc", $mailbcc);
 
   97         setHttpVar(
"_mail_from", $mailfrom);
 
   98         if ($format == 
"link") setHttpVar(
"_mail_format", 
"htmlnotif");
 
   99         if (($mailto != 
"") || ($mailcc != 
"") || ($mailbcc != 
"")) {
 
  106         if (
$err != 
"") $action->
exitError(sprintf(_(
"the document %s has not be sended :\n %s") , 
$doc->title, 
$err));
 
  107         elseif (!$sendedmail) $action->
addWarningMsg(sprintf(_(
"the document %s has not been sended : no recipient") , 
$doc->title));
 
  110     foreach ($tuid as $uid) {
 
  113             $wuid = 
getv($tu, 
"us_whatid");
 
  114             $doc->addUTag($wuid, 
"TOVIEW");
 
  118     redirect($action, GetHttpVars(
"redirect_app", 
"FDL") , GetHttpVars(
"redirect_act", 
"FDL_CARD&latest=Y&refreshfld=Y&id=" . 
$doc->id) , $action->GetParam(
"CORE_STANDURL"));
 
  127     $err = 
sendCard($action, GetHttpVars(
"id") , GetHttpVars(
"_mail_to", 
'') , GetHttpVars(
"_mail_cc", 
"") , GetHttpVars(
"_mail_subject") , GetHttpVars(
"zone") , GetHttpVars(
"ulink", 
"N") == 
"Y", GetHttpVars(
"_mail_cm", 
"") , GetHttpVars(
"_mail_from", 
"") , GetHttpVars(
"_mail_bcc", 
"") , GetHttpVars(
"_mail_format", 
"html") , $sendcopy, $addfiles, $userinfo, GetHttpVars(
"_mail_savecopy", 
"no") == 
"yes");
 
  131     $state = GetHttpVars(
"state");
 
  135         $docid = GetHttpVars(
"id");
 
  146                 $err = $wdoc->ChangeState($state, _(
"email sended") , 
true);
 
  150             $action->AddLogMsg(sprintf(_(
"the document %s is not related to a workflow") , 
$doc->title));
 
  160 $addfiles = array() , $userinfo = null, $savecopy = 
false)
 
  162     if (is_null($userinfo)) {
 
  168     $viewonly = (GetHttpVars(
"viewonly", 
"N") == 
"Y");
 
  169     if ((!$viewonly) && (
$to == 
"") && (
$cc == 
"") && (
$bcc == 
"")) 
return _(
"mail dest is empty");
 
  187     if (GetHttpVars(
"_mail_format") == 
"") setHttpVar(
"_mail_format", $format);
 
  192     $ftitle = str_replace(array(
 
  197     ) , 
"_", $doc->title);
 
  198     $ftitle = str_replace(
"'", 
"", $ftitle);
 
  199     $ftitle = str_replace(
"\"", 
"", $ftitle);
 
  200     $ftitle = str_replace(
"&", 
"", $ftitle);
 
  202     $to = str_replace(
"\"", 
"'", 
$to);
 
  203     $cc = str_replace(
"\"", 
"'", 
$cc);
 
  204     $bcc = str_replace(
"\"", 
"'", 
$bcc);
 
  213     if ($sendercopy && $action->getParam(
"FDL_BCC") == 
"yes") {
 
  216             if (
$bcc != 
"") 
$bcc = 
"$bcc,$umail";
 
  217             else $bcc = 
"$umail";
 
  223         if (
$from == 
"") 
$from = $action->user->login . 
'@' . php_uname(
'n');
 
  229     $layout = 
"maildoc.xml"; 
 
  230     if ($format == 
"htmlnotif") {
 
  231         $layout = 
"mailnotification.xml";
 
  232         $zonebodycard = 
"FDL:MAILNOTIFICATION:S";
 
  235     if ($zonebodycard == 
"") $zonebodycard = $doc->defaultmview;
 
  236     if ($zonebodycard == 
"") $zonebodycard = $doc->defaultview;
 
  238     if (preg_match(
"/[A-Z]+:[^:]+:S/", $zonebodycard, $reg)) $szone = 
true; 
 
  239     if (preg_match(
"/[A-Z]+:[^:]+:T/", $zonebodycard, $reg)) setHttpVar(
"dochead", 
"N"); 
 
  240     if (preg_match(
"/[A-Z]+:[^:]+:B/", $zonebodycard, $reg)) $binary = 
true;
 
  244         $binfile = $doc->viewDoc($zonebodycard);
 
  245         if (!is_file($binfile)) 
$err = $binfile;
 
  249             $engine = $doc->getZoneTransform($zonebodycard);
 
  251                 include_once (
"FDL/Lib.Vault.php");
 
  263                     $tplfile = $doc->getZoneFile($zonebodycard);
 
  268             $message->addAttachment(
new \Dcp\Mail\Attachment($binfile, sprintf(
"%s.%s", $doc->title, 
$ext) , $mime));
 
  270             $zonebodycard = 
"FDL:EMPTY";
 
  275         setHttpVar(
"target", 
"mail");
 
  276         if (preg_match(
"/html/", $format, $reg)) {
 
  278             if ($action->GetParam(
"CORE_URLINDEX") != 
"") {
 
  279                 $turl = parse_url($action->GetParam(
"CORE_URLINDEX"));
 
  280                 $url = $turl[
"scheme"] . 
'://' . $turl[
"host"];
 
  281                 if (isset($turl[
"port"])) $url.= 
':' . $turl[
"port"];
 
  282                 if (isset($turl[
"path"])) $url.= $turl[
"path"] . 
"/";
 
  284                 $absurl = $action->GetParam(
"CORE_URLINDEX");
 
  286                 $absurl = $action->GetParam(
"CORE_ABSURL");
 
  287                 $baseurl = $action->GetParam(
"CORE_ABSURL");
 
  292                 $doc->viewDoc($zonebodycard, 
"mail", $ulink, 
false, 
true);
 
  294                 $doc->lay->Set(
"absurl", $absurl);
 
  295                 $doc->lay->Set(
"baseurl", $baseurl);
 
  296                 $sgen = $doc->lay->gen();
 
  299                     $sgen = preg_replace(
"'<body([^>]*)>'i", 
"<body \\1><P>$comment<P><HR>", $sgen);
 
  305                 $docmail->Set(
"TITLE", $doc->title);
 
  306                 $docmail->Set(
"ID", $doc->id);
 
  307                 $docmail->Set(
"zone", $zonebodycard);
 
  308                 $docmail->Set(
"absurl", $absurl);
 
  309                 $docmail->Set(
"baseurl", $baseurl);
 
  311                     $docmail->setBlockData(
"COMMENT", array(
 
  316                     $docmail->set(
"comment", nl2br(
$comment));
 
  319                 $sgen = $docmail->gen();
 
  326             $sgen1 = preg_replace_callback(
'/src="(FDL\/geticon[^"]+)"/i', 
function ($matches)
 
  332             $sgen1 = preg_replace_callback(array(
 
  335             ) , 
function ($matches)
 
  341             $pfout = uniqid(
getTmpDir() . 
"/" . $doc->id);
 
  342             $fout = fopen($pfout, 
"w");
 
  344             fwrite($fout, $sgen1);
 
  349         if (preg_match(
"/pdf/", $format, $reg)) {
 
  353                 $sgen = $doc->viewDoc($zonebodycard, 
"mail", 
false);
 
  358                 $docmail2->Set(
"zone", $zonebodycard);
 
  359                 $docmail2->Set(
"TITLE", $doc->title);
 
  361                 $sgen = $docmail2->gen();
 
  363             $sgen2 = preg_replace_callback(
'/src="([^"]+)"/i', 
function ($matches)
 
  369             $ppdf = uniqid(
getTmpDir() . 
"/" . $doc->id) . 
".pdf.html";
 
  370             $fout = fopen($ppdf, 
"w");
 
  371             $sgen2 = preg_replace(
'/\xE2\x82\xAC/', 
'€', $sgen2);
 
  372             fwrite($fout, $sgen2);
 
  377         if (preg_match(
"/html/", $format, $reg)) {
 
  378             $body = file_get_contents($pfout);
 
  379             $mailBody = new \Dcp\Mail\Body($body, 
'text/html');
 
  381         } 
else if ($format == 
"pdf") {
 
  382             $mailBody = new \Dcp\Mail\Body(
$comment, 
'text/plain');
 
  386         if ($format != 
"pdf") {
 
  389             if (preg_match_all(
"/(href|src)=\"cid:([^\"]*)\"/i", $sgen, $match)) {
 
  391                 $afiles = $doc->GetFileAttributes();
 
  392                 $taids = array_keys($afiles);
 
  393                 if (count($afiles) > 0) {
 
  394                     foreach ($tcids as $vaf) {
 
  395                         $tf = explode(
"+", $vaf);
 
  396                         if (count($tf) == 1) {
 
  403                         if (in_array($aid, $taids)) {
 
  404                             if ($afiles[$aid]->repeat) $va = $doc->getMultipleRawValues($aid, 
"", $index);
 
  405                             else $va = $doc->getRawValue($aid);
 
  408                                 $ticon = explode(
"|", $va);
 
  409                                 $mime = empty($ticon[0]) ? 
false : $ticon[0];
 
  410                                 $vid = empty($ticon[1]) ? 
false : $ticon[1];
 
  416                                     if ($vf->Retrieve($vid, 
$info) == 
"") {
 
  419                                         if (($mixed) && ($afiles[$aid]->type != 
"image")) $cidindex = 
$info->name;
 
  420                                         $message->addBodyRelatedAttachment(
new \Dcp\Mail\RelatedAttachment(
$info->path, 
$info->name, (
$info->mime_s ? 
$info->mime_s : $mime) , $cidindex));
 
  430             if (preg_match(
"/html/", $format, $reg)) {
 
  434                         $ticon = explode(
"|", $va);
 
  435                         $mime = empty($ticon[0]) ? 
false : $ticon[0];
 
  436                         $vid = empty($ticon[1]) ? 
false : $ticon[1];
 
  442                             if ($vf->Retrieve($vid, 
$info) == 
"") {
 
  443                                 $mailAttach = new \Dcp\Mail\RelatedAttachment(
$info->path, 
$info->name, (
$info->mime_s ? 
$info->mime_s : $mime) , 
'icon');
 
  444                                 $message->addBodyRelatedAttachment($mailAttach);
 
  447                             $icon = $doc->getIcon();
 
  448                             if (file_exists($pubdir . 
"/$icon")) {
 
  449                                 $mailAttach = new \Dcp\Mail\RelatedAttachment(sprintf(
"%s/%s", $pubdir, $icon) , 
'icon', sprintf(
"image/%s", 
fileextension($icon)) , 
'icon');
 
  450                                 $message->addBodyRelatedAttachment($mailAttach);
 
  458             foreach ($ifiles as $v) {
 
  459                 if (file_exists($pubdir . 
"/$v")) {
 
  460                     $mailAttach = new \Dcp\Mail\RelatedAttachment(sprintf(
"%s/%s", $pubdir, $v) , basename($v) , sprintf(
"image/%s", 
fileextension($v)) , $v);
 
  461                     $message->addBodyRelatedAttachment($mailAttach);
 
  465             foreach ($tfiles as $k => $v) {
 
  466                 if (file_exists($v)) {
 
  467                     $mailAttach = new \Dcp\Mail\RelatedAttachment($v, $k, trim(shell_exec(sprintf(
"file --mime -b %s", escapeshellarg($v)))) , $k);
 
  468                     $message->addBodyRelatedAttachment($mailAttach);
 
  472             if (count($addfiles) > 0) {
 
  473                 foreach ($addfiles as $vf) {
 
  474                     if (count($vf) == 3) {
 
  479                         $fgen = $doc->viewDoc($fview, 
"mail");
 
  480                         $fpname = 
getTmpDir() . 
"/" . str_replace(array(
 
  485                         ) , 
"_", uniqid($doc->id) . $fname);
 
  486                         if ($fp = fopen($fpname, 
'w')) {
 
  490                         $fpst = stat($fpname);
 
  491                         if (is_array($fpst) && $fpst[
"size"] > 0) {
 
  492                             $message->addAttachment(
new \Dcp\Mail\Attachment($fpname, $fname, $fmime));
 
  498         if (preg_match(
"/pdf/", $format, $reg)) {
 
  500             $fps = uniqid(
getTmpDir() . 
"/" . $doc->id) . 
"ps";
 
  501             $fpdf = uniqid(
getTmpDir() . 
"/" . $doc->id) . 
"pdf";
 
  508             $html = file_get_contents($ppdf);
 
  509             if ($html !== 
false) {
 
  510                 $tmp = tempnam(dirname($ppdf) , basename($ppdf) . 
".cleanup");
 
  511                 if ($tmp !== 
false) {
 
  512                     $html = preg_replace(
'#<style[^>]*>.*?</style\s*>#s', 
'', $html);
 
  513                     if (file_put_contents($tmp, $html) !== 
false) {
 
  514                         if (rename($tmp, $ppdf) === 
false) {
 
  522             $cmdpdf = sprintf(
"recode u8..l9 %s && html2ps -U -i 0.5 -b %s/ %s > %s && ps2pdf %s %s", escapeshellarg($ppdf) , 
 
  523             escapeshellarg($pubdir) , escapeshellarg($ppdf) , escapeshellarg($fps) , 
 
  524             escapeshellarg($fps) , escapeshellarg($fpdf) 
 
  528                 $message->addAttachment(
new \Dcp\Mail\Attachment($fpdf, sprintf(
"%s.pdf", $doc->title) , 
'application/pdf'));
 
  530                 $action->addlogmsg(sprintf(_(
"PDF conversion failed for %s") , $doc->title));
 
  546             if (
$cc != 
"") $lsend = sprintf(
"%s and %s", 
$to, 
$cc);
 
  548             $doc->addHistoryEntry(sprintf(_(
"sended to %s") , $lsend));
 
  549             $action->addlogmsg(sprintf(_(
"sending %s to %s") , $doc->title, $lsend));
 
  550             if (\Dcp\Family\Mailtemplate::NOTIFY_SENDMAIL_ALWAYS === $notifySendMail) {
 
  551                 $action->addWarningMsg(sprintf(_(
"sending %s to %s") , $doc->title, $lsend));
 
  554             $action->log->warning(
$err);
 
  555             $action->addlogmsg(sprintf(_(
"%s cannot be sent") , $doc->title));
 
  556             if (\Dcp\Family\Mailtemplate::NOTIFY_SENDMAIL_ALWAYS === $notifySendMail || \Dcp\Family\Mailtemplate::NOTIFY_SENDMAIL_ERRORS_ONLY === $notifySendMail) {
 
  557                 $action->addWarningMsg(sprintf(_(
"%s cannot be sent") , $doc->title));
 
  558                 $action->addWarningMsg(
$err);
 
  562         if (isset($ftxt) && is_file($ftxt)) unlink($ftxt);
 
  563         if (isset($fpdf) && is_file($fpdf)) unlink($fpdf);
 
  564         if (isset($fps) && is_file($fps)) unlink($fps);
 
  565         if (isset($pfout) && is_file($pfout)) unlink($pfout);
 
  566         if (isset($ppdf) && is_file($ppdf)) unlink($ppdf);
 
  567         if (isset($binfile) && is_file($binfile)) unlink($binfile);
 
  569         $tmpfile = array_merge($tmpfile, $tfiles);
 
  570         foreach ($tmpfile as $v) {
 
  571             if (file_exists($v) && (substr($v, 0, 9) == 
getTmpDir() . 
"/")) unlink($v);
 
  588     if (substr($src, 0, 3) == 
"cid") 
return "src=\"$src\"";
 
  589     if (substr($src, 0, 4) == 
"http") {
 
  597             if (strlen($url) <= 0) {
 
  600             if (strcmp(substr($src, 0, strlen($url)) , $url) == 0) {
 
  602                 $chopped_src = substr($src, strlen($url));
 
  606         if ($chopped_src == 
'') {
 
  607             return sprintf(
'src="%s"', $src);
 
  612     if (preg_match(
"/(.*)(app=FDL.*action=EXPORTFILE.*)$/", $src, $reg)) {
 
  613         return imgvaultfile(str_replace(
'&', 
'&', $reg[2]));
 
  614     } elseif (preg_match(
'!^file/(?P<docid>\d+)/(?P<vid>\d+)/(?P<attrid>[^/]+)/(?P<index>[^/]+)/(?P<fname>[^?]+)!', $src, $reg)) {
 
  618     if (!in_array(strtolower(
fileextension($src)) , $vext)) 
return "";
 
  620     $ifiles[$src] = $src;
 
  621     return "src=\"cid:$src\"";
 
  628         $src = 
"img" . count($tfiles);
 
  629         $tfiles[$src] = $newfile;
 
  630         return "src=\"cid:$src\" ";
 
  636     include_once (
'FDL/exportfile.php');
 
  638     if (preg_match(
"/(.*)(app=FDL.*action=EXPORTFILE.*)docid=([^&]*).*&attrid=([^&]*).*&index=([^&]*)/", $src, $reg)) {
 
  639         $fileDoc = new_doc(
"", $reg[3]);
 
  644             if (!copy($filePath, $newfile)) {
 
  650     if (preg_match(
"|^FDL/geticon\\.php\\?vaultid=(?P<vid>\\d+)|", $src, $reg)) {
 
  653         if (!copy(
$info->path, $newfile)) {
 
  658     if (preg_match(
'!^file/(?P<docid>\d+)/(?P<vid>\d+)/(?P<attrid>[^/]+)/(?P<index>[^/]+)/(?P<fname>[^?]+)!', $src, $reg)) {
 
  660         $fileDoc = new_doc(
"", $reg[
'docid']);
 
  665             if (!copy($filePath, $newfile)) {
 
  682     if ($src == 
"cid:icon") {
 
  685         if (substr($src, 0, 4) == 
"cid:") {
 
  686             $va = $doc->getRawValue(substr($src, 4));
 
  687         } elseif (preg_match(
"/(.*)(app=FDL.*action=EXPORTFILE.*)$/", $src, $reg)) {
 
  688             $va = 
copyvault(str_replace(
'&', 
'&', $reg[2]));
 
  696         $ticon = explode(
"|", $va);
 
  697         $vid = empty($ticon[1]) ? 
false : $ticon[1];
 
  704             if ($vf->Retrieve($vid, 
$info) == 
"") {
 
  708             if (file_exists($va)) {
 
  710             } elseif (file_exists($pubdir . 
"/$va")) {
 
  711                 $f = $pubdir . 
"/$va";
 
  712             } elseif (file_exists($pubdir . 
"/Images/$va")) {
 
  713                 $f = $pubdir . 
"/Images/$va";
 
  714             } elseif ((substr($va, 0, 12) == 
getTmpDir() . 
'/img') && file_exists($va)) {
 
  719     if ($f) 
return "src=\"$f\"";
 
Layout is a template generator. 
convertFile($infile, $engine, $outfile, &$info)
vault_properties($idfile, $teng_name="")
getTDoc($dbaccess, $id, $sqlfilters=array(), $result=array())
newFreeVaultFile($dbaccess)
getMailAddr($userid, $full=false)
sendCard(Action &$action, $docid, $to, $cc, $subject, $zonebodycard="", $ulink=false, $comment="", $from="", $bcc="", $format="html", $sendercopy=true, $addfiles=array(), $userinfo=null, $savecopy=false)
static getParameterValue($application, $parameterName)
getSysMimeFile($f, $fn="")
fileextension($filename, $ext="nop")
exitError($texterr, $exit=true, $code="")
getFileExtension($filename)
getLayoutFile($app, $layfile)
mailcard(Action &$action)
getParam($name, $def="")
must be in core or global type 
const NOTIFY_SENDMAIL_ALWAYS
new_Doc($dbaccess, $id= '', $latest=false)
const NOTIFY_SENDMAIL_NEVER
getExportFileDocumentPath(\Doc $doc, $attrid, $index=-1)
sendmailcard(Action &$action)
if($file) if($subject==""&&$file) if($subject=="") $err