Core  3.2
PHP API documentation
 All Data Structures Namespaces Files Functions Variables Pages
mailcard.php
Go to the documentation of this file.
1 <?php
2 /*
3  * @author Anakeen
4  * @package FDL
5 */
6 /**
7  * Functions to send document by email
8  *
9  * @author Anakeen
10  * @version $Id: mailcard.php,v 1.83 2008/12/16 15:52:35 eric Exp $
11  * @package FDL
12  * @subpackage
13  */
14 /**
15  */
16 
17 include_once ("FDL/Class.Doc.php");
18 include_once ("FDL/sendmail.php");
19 // -----------------------------------
20 function mailcard(Action & $action)
21 {
22  $docid = GetHttpVars("id");
23  $cr = GetHttpVars("cr"); // want a status
24  $dbaccess = $action->dbaccess;
26  // control sending
27  $err = $doc->control('send');
28  if ($err != "") $action->exitError($err);
29  $famMail = new_doc($dbaccess, 'MAIL');
30  $err = $famMail->control('create');
31  if ($err != "") $action->exitError($err);
32 
33  $tmailto = $tmailcc = $tmailbcc = array();
34  $mailfrom = GetHttpVars("_mail_from");
35 
36  foreach (array(
37  "plain",
38  "link"
39  ) as $format) {
40  $tmailto[$format] = array();
41  $tmailcc[$format] = array();
42  $tmailbcc[$format] = array();
43  }
44 
45  $tuid = array(); // list of user id to notify
46  $mt = GetHttpVars("to"); // simple arguments (can be use with wsh
47  if ($mt == "") {
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) {
54  $v = trim($v);
55  if ($v != "") {
56  if ($tformat[$k] == "") $tformat[$k] = "plain";
57  switch ($rtype[$k]) {
58  case "cc":
59  $tmailcc[$tformat[$k]][$v] = $v;
60  break;
61 
62  case "bcc":
63  $tmailbcc[$tformat[$k]][$v] = $v;
64  break;
65 
66  default:
67  $tmailto[$tformat[$k]][$v] = $v;
68  if ($idraddr[$k] > 0) $tuid[] = $idraddr[$k];
69  break;
70  }
71  }
72  }
73  }
74  } else {
75  // other notation
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");
82  }
83 
84  $sendedmail = false;
85  foreach (array(
86  "plain",
87  "link"
88  ) as $format) {
89 
90  $mailto = implode(",", $tmailto[$format]);
91  $mailcc = implode(",", $tmailcc[$format]);
92  $mailbcc = implode(",", $tmailbcc[$format]);
93  // correct trim --->
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 != "")) {
100  $err = sendmailcard($action);
101  $sendedmail = true;
102  }
103  }
104 
105  if ($cr == "Y") {
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));
108  }
109 
110  foreach ($tuid as $uid) {
111  if ($uid > 0) {
112  $tu = getTDoc($dbaccess, $uid);
113  $wuid = getv($tu, "us_whatid");
114  $doc->addUTag($wuid, "TOVIEW");
115  }
116  }
117 
118  redirect($action, GetHttpVars("redirect_app", "FDL") , GetHttpVars("redirect_act", "FDL_CARD&latest=Y&refreshfld=Y&id=" . $doc->id) , $action->GetParam("CORE_STANDURL"));
119 }
120 // -----------------------------------
122 {
123 
124  $sendcopy = true;
125  $addfiles = array();
126  $userinfo = null;
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");
128 
129  if ($err != "") return $err;
130  // also change state sometime with confirmmail action
131  $state = GetHttpVars("state");
132 
133  if ($state != "") {
134 
135  $docid = GetHttpVars("id");
136 
137  $dbaccess = $action->dbaccess;
139  if ($doc->wid > 0) {
140  if ($state != "-") {
141  /*
142  * @var WDoc $wdoc
143  */
144  $wdoc = new_Doc($dbaccess, $doc->wid);
145  $wdoc->Set($doc);
146  $err = $wdoc->ChangeState($state, _("email sended") , true);
147  if ($err != "") $action->addWarningMsg($err);
148  }
149  } else {
150  $action->AddLogMsg(sprintf(_("the document %s is not related to a workflow") , $doc->title));
151  }
152  }
153  return '';
154 }
155 
156 function sendCard(Action & $action, $docid, $to, $cc, $subject, $zonebodycard = "", // define mail layout
157 $ulink = false, // don't see hyperlink
158 $comment = "", $from = "", $bcc = "", $format = "html", // define view action
159 $sendercopy = true, // true : a copy is send to the sender according to the Freedom user parameter
160 $addfiles = array() , $userinfo = null, $savecopy = false)
161 {
162  if (is_null($userinfo)) {
163  $notifySendMail = \ApplicationParameterManager::getParameterValue('CORE', 'CORE_NOTIFY_SENDMAIL');
164  } else {
166  }
167  // -----------------------------------
168  $viewonly = (GetHttpVars("viewonly", "N") == "Y");
169  if ((!$viewonly) && ($to == "") && ($cc == "") && ($bcc == "")) return _("mail dest is empty");
170  // -----------------------------------
171  global $ifiles;
172  global $tfiles;
173  global $tmpfile;
174  global $vf;
175  global $doc;
176  global $pubdir;
177  global $action;
178 
179  $ifiles = array();
180  $tfiles = array();
181  $tmpfile = array();
182  $mixed = true; // to see file as attachement
183  $err = '';
184  $pfout = $ppdf = '';
185  // set title
186  setHttpVar("id", $docid); // for view zone
187  if (GetHttpVars("_mail_format") == "") setHttpVar("_mail_format", $format);
188 
189  $dbaccess = $action->dbaccess;
190  $doc = new_Doc($dbaccess, $docid);
191 
192  $ftitle = str_replace(array(
193  " ",
194  "/",
195  ")",
196  "("
197  ) , "_", $doc->title);
198  $ftitle = str_replace("'", "", $ftitle);
199  $ftitle = str_replace("\"", "", $ftitle);
200  $ftitle = str_replace("&", "", $ftitle);
201 
202  $to = str_replace("\"", "'", $to);
203  $cc = str_replace("\"", "'", $cc);
204  $bcc = str_replace("\"", "'", $bcc);
205 
207  $pubdir = DEFAULT_PUBDIR;
208  $szone = false;
209  $sgen = $sgen1 = '';
210 
211  $message = new \Dcp\Mail\Message();
212 
213  if ($sendercopy && $action->getParam("FDL_BCC") == "yes") {
214  $umail = getMailAddr($action->user->id);
215  if ($umail != "") {
216  if ($bcc != "") $bcc = "$bcc,$umail";
217  else $bcc = "$umail";
218  }
219  }
220  if ($from == "") {
221  $from = getMailAddr($action->user->id, true);
222  if ($from == "") $from = getParam('SMTP_FROM');
223  if ($from == "") $from = $action->user->login . '@' . php_uname('n');
224  }
225 
226  if ($subject == "") $subject = $ftitle;
227  $subject = str_replace("\"", "'", $subject);
228 
229  $layout = "maildoc.xml"; // the default
230  if ($format == "htmlnotif") {
231  $layout = "mailnotification.xml";
232  $zonebodycard = "FDL:MAILNOTIFICATION:S";
233  }
234 
235  if ($zonebodycard == "") $zonebodycard = $doc->defaultmview;
236  if ($zonebodycard == "") $zonebodycard = $doc->defaultview;
237  $binary = false;
238  if (preg_match("/[A-Z]+:[^:]+:S/", $zonebodycard, $reg)) $szone = true; // the zonebodycard is a standalone zone ?
239  if (preg_match("/[A-Z]+:[^:]+:T/", $zonebodycard, $reg)) setHttpVar("dochead", "N"); // the zonebodycard without head ?
240  if (preg_match("/[A-Z]+:[^:]+:B/", $zonebodycard, $reg)) $binary = true;
241 
242  if ($binary) {
243 
244  $binfile = $doc->viewDoc($zonebodycard);
245  if (!is_file($binfile)) $err = $binfile;
246 
247  if ($err == "") {
248  $mime = $ext = '';
249  $engine = $doc->getZoneTransform($zonebodycard);
250  if ($engine) {
251  include_once ("FDL/Lib.Vault.php");
252  $outfile = uniqid(getTmpDir() . "/conv") . ".$engine";
253  $err = convertFile($binfile, $engine, $outfile, $info);
254  if ($err == "") {
255  $mime = getSysMimeFile($outfile, basename($outfile));
256  $ext = getExtension($mime);
257  $binfile = $outfile;
258  }
259  } else {
260  $mime = getSysMimeFile($binfile, basename($binfile));
261  $ext = getExtension($mime);
262  if (!$ext) {
263  $tplfile = $doc->getZoneFile($zonebodycard);
264  $ext = getFileExtension($tplfile);
265  }
266  }
267 
268  $message->addAttachment(new \Dcp\Mail\Attachment($binfile, sprintf("%s.%s", $doc->title, $ext) , $mime));
269 
270  $zonebodycard = "FDL:EMPTY";
271  }
272  }
273 
274  if ($err == "") {
275  setHttpVar("target", "mail");
276  if (preg_match("/html/", $format, $reg)) {
277 
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"] . "/";
283  $baseurl = $url;
284  $absurl = $action->GetParam("CORE_URLINDEX");
285  } else {
286  $absurl = $action->GetParam("CORE_ABSURL");
287  $baseurl = $action->GetParam("CORE_ABSURL");
288  }
289 
290  if ($szone) {
291 
292  $doc->viewDoc($zonebodycard, "mail", $ulink, false, true);
293 
294  $doc->lay->Set("absurl", $absurl);
295  $doc->lay->Set("baseurl", $baseurl);
296  $sgen = $doc->lay->gen();
297  if ($comment != "") {
298  $comment = nl2br($comment);
299  $sgen = preg_replace("'<body([^>]*)>'i", "<body \\1><P>$comment<P><HR>", $sgen);
300  }
301  } else {
302  // contruct HTML mail
303  $docmail = new Layout(getLayoutFile("FDL", $layout) , $action);
304 
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);
310  if ($comment != "") {
311  $docmail->setBlockData("COMMENT", array(
312  array(
313  "boo"
314  )
315  ));
316  $docmail->set("comment", nl2br($comment));
317  }
318 
319  $sgen = $docmail->gen();
320  }
321  if ($viewonly) {
322  echo $sgen;
323  exit;
324  }
325 
326  $sgen1 = preg_replace_callback('/src="(FDL\/geticon[^"]+)"/i', function ($matches)
327  {
328  return imgvaultfile($matches[1]);
329  }
330  , $sgen);
331 
332  $sgen1 = preg_replace_callback(array(
333  '/SRC="([^"]+)"/',
334  '/src="([^"]+)"/'
335  ) , function ($matches)
336  {
337  return srcfile($matches[1]);
338  }
339  , $sgen1);
340 
341  $pfout = uniqid(getTmpDir() . "/" . $doc->id);
342  $fout = fopen($pfout, "w");
343 
344  fwrite($fout, $sgen1);
345 
346  fclose($fout);
347  }
348 
349  if (preg_match("/pdf/", $format, $reg)) {
350  // ---------------------------
351  // contruct PDF mail
352  if ($szone) {
353  $sgen = $doc->viewDoc($zonebodycard, "mail", false);
354  } else {
355 
356  $docmail2 = new Layout(getLayoutFile("FDL", $layout) , $action);
357 
358  $docmail2->Set("zone", $zonebodycard);
359  $docmail2->Set("TITLE", $doc->title);
360 
361  $sgen = $docmail2->gen();
362  }
363  $sgen2 = preg_replace_callback('/src="([^"]+)"/i', function ($matches)
364  {
365  return realfile($matches[1]);
366  }
367  , $sgen);
368 
369  $ppdf = uniqid(getTmpDir() . "/" . $doc->id) . ".pdf.html";
370  $fout = fopen($ppdf, "w");
371  $sgen2 = preg_replace('/\xE2\x82\xAC/', '&euro;', $sgen2);
372  fwrite($fout, $sgen2);
373  fclose($fout);
374  }
375  // ---------------------------
376  // construct message's body
377  if (preg_match("/html/", $format, $reg)) {
378  $body = file_get_contents($pfout);
379  $mailBody = new \Dcp\Mail\Body($body, 'text/html');
380  $message->setBody($mailBody);
381  } else if ($format == "pdf") {
382  $mailBody = new \Dcp\Mail\Body($comment, 'text/plain');
383  $message->setBody($mailBody);
384  }
385 
386  if ($format != "pdf") {
387  // ---------------------------
388  // insert attached files
389  if (preg_match_all("/(href|src)=\"cid:([^\"]*)\"/i", $sgen, $match)) {
390  $tcids = $match[2]; // list of file references inserted in mail
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) {
397  $aid = $tf[0];
398  $index = - 1;
399  } else {
400  $aid = $tf[0];
401  $index = $tf[1];
402  }
403  if (in_array($aid, $taids)) {
404  if ($afiles[$aid]->repeat) $va = $doc->getMultipleRawValues($aid, "", $index);
405  else $va = $doc->getRawValue($aid);
406 
407  if ($va != "") {
408  $ticon = explode("|", $va);
409  $mime = empty($ticon[0]) ? false : $ticon[0];
410  $vid = empty($ticon[1]) ? false : $ticon[1];
411 
412  if ($vid != "") {
413  /*
414  * @var VaultFileInfo $info
415  */
416  if ($vf->Retrieve($vid, $info) == "") {
417 
418  $cidindex = $vaf;
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));
421  }
422  }
423  }
424  }
425  }
426  }
427  }
428  // ---------------------------
429  // add icon image
430  if (preg_match("/html/", $format, $reg)) {
431  if (!$szone) {
432  $va = $doc->icon;
433  if ($va != "") {
434  $ticon = explode("|", $va);
435  $mime = empty($ticon[0]) ? false : $ticon[0];
436  $vid = empty($ticon[1]) ? false : $ticon[1];
437 
438  if ($vid != "") {
439  /*
440  * @var VaultFileInfo $info
441  */
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);
445  }
446  } else {
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);
451  }
452  }
453  }
454  }
455  }
456  // ---------------------------
457  // add inserted image
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);
462  }
463  }
464 
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);
469  }
470  }
471  // Other files,
472  if (count($addfiles) > 0) {
473  foreach ($addfiles as $vf) {
474  if (count($vf) == 3) {
475  $fview = $vf[0];
476  $fname = $vf[1];
477  $fmime = $vf[2];
478 
479  $fgen = $doc->viewDoc($fview, "mail");
480  $fpname = getTmpDir() . "/" . str_replace(array(
481  " ",
482  "/",
483  "(",
484  ")"
485  ) , "_", uniqid($doc->id) . $fname);
486  if ($fp = fopen($fpname, 'w')) {
487  fwrite($fp, $fgen);
488  fclose($fp);
489  }
490  $fpst = stat($fpname);
491  if (is_array($fpst) && $fpst["size"] > 0) {
492  $message->addAttachment(new \Dcp\Mail\Attachment($fpname, $fname, $fmime));
493  }
494  }
495  }
496  }
497  }
498  if (preg_match("/pdf/", $format, $reg)) {
499  // try PDF
500  $fps = uniqid(getTmpDir() . "/" . $doc->id) . "ps";
501  $fpdf = uniqid(getTmpDir() . "/" . $doc->id) . "pdf";
502  /*
503  * Remove CSS rules as they are not interpreted by html2ps
504  * (and can cause html2ps to choke on some strings and
505  * print out raw CSS instructions in the resulting output
506  * file).
507  */
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) {
515  unlink($tmp);
516  }
517  } else {
518  unlink($tmp);
519  }
520  }
521  }
522  $cmdpdf = sprintf("recode u8..l9 %s && html2ps -U -i 0.5 -b %s/ %s > %s && ps2pdf %s %s", escapeshellarg($ppdf) , // recode
523  escapeshellarg($pubdir) , escapeshellarg($ppdf) , escapeshellarg($fps) , // html2ps
524  escapeshellarg($fps) , escapeshellarg($fpdf) // ps2pdf
525  );
526  system(($cmdpdf) , $status);
527  if ($status == 0) {
528  $message->addAttachment(new \Dcp\Mail\Attachment($fpdf, sprintf("%s.pdf", $doc->title) , 'application/pdf'));
529  } else {
530  $action->addlogmsg(sprintf(_("PDF conversion failed for %s") , $doc->title));
531  }
532  }
533  /*
534  $err = sendmail($to, $from, $cc, $bcc, $subject, $multi_mix);
535  */
536  $message->setFrom($from);
537  $message->addTo($to);
538  $message->addCc($cc);
539  $message->addBcc($bcc);
540  $message->setSubject($subject);
541  $err = $message->send();
542  if ($err == "") {
543  if ($savecopy) {
544  createSentMessage($to, $from, $cc, $bcc, $subject, $message, $doc);
545  }
546  if ($cc != "") $lsend = sprintf("%s and %s", $to, $cc);
547  else $lsend = $to;
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));
552  }
553  } else {
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);
559  }
560  }
561  // suppress temporaries files
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);
568 
569  $tmpfile = array_merge($tmpfile, $tfiles);
570  foreach ($tmpfile as $v) {
571  if (file_exists($v) && (substr($v, 0, 9) == getTmpDir() . "/")) unlink($v);
572  }
573  }
574 
575  return $err;
576 }
577 
578 function srcfile($src)
579 {
580  global $ifiles;
581  $vext = array(
582  "gif",
583  "png",
584  "jpg",
585  "jpeg",
586  "bmp"
587  );
588  if (substr($src, 0, 3) == "cid") return "src=\"$src\"";
589  if (substr($src, 0, 4) == "http") {
590  $chopped_src = '';
591  // Detect HTTP URLs pointing to myself
592  foreach (array(
593  'CORE_URLINDEX',
594  'CORE_PUBURL'
595  ) as $url) {
596  $url = getParam($url);
597  if (strlen($url) <= 0) {
598  continue;
599  }
600  if (strcmp(substr($src, 0, strlen($url)) , $url) == 0) {
601  // Chop the URL base part, and leave only the args/vars
602  $chopped_src = substr($src, strlen($url));
603  break;
604  }
605  }
606  if ($chopped_src == '') {
607  return sprintf('src="%s"', $src);
608  }
609  $src = $chopped_src;
610  }
611 
612  if (preg_match("/(.*)(app=FDL.*action=EXPORTFILE.*)$/", $src, $reg)) {
613  return imgvaultfile(str_replace('&amp;', '&', $reg[2]));
614  } elseif (preg_match('!^file/(?P<docid>\d+)/(?P<vid>\d+)/(?P<attrid>[^/]+)/(?P<index>[^/]+)/(?P<fname>[^?]+)!', $src, $reg)) {
615  return imgvaultfile($src);
616  }
617 
618  if (!in_array(strtolower(fileextension($src)) , $vext)) return "";
619 
620  $ifiles[$src] = $src;
621  return "src=\"cid:$src\"";
622 }
623 function imgvaultfile($src)
624 {
625  global $tfiles;
626  $newfile = copyvault($src);
627  if ($newfile) {
628  $src = "img" . count($tfiles);
629  $tfiles[$src] = $newfile;
630  return "src=\"cid:$src\" ";
631  }
632  return "";
633 }
634 function copyvault($src)
635 {
636  include_once ('FDL/exportfile.php');
637 
638  if (preg_match("/(.*)(app=FDL.*action=EXPORTFILE.*)docid=([^&]*).*&attrid=([^&]*).*&index=([^&]*)/", $src, $reg)) {
639  $fileDoc = new_doc("", $reg[3]);
640  $filePath = getExportFileDocumentPath($fileDoc, $reg[4], $reg[5]);
641 
642  if ($filePath) {
643  $newfile = uniqid(getTmpDir() . "/img");
644  if (!copy($filePath, $newfile)) {
645  return "";
646  }
647  return $newfile;
648  }
649  }
650  if (preg_match("|^FDL/geticon\\.php\\?vaultid=(?P<vid>\\d+)|", $src, $reg)) {
651  $info = vault_properties($reg['vid']);
652  $newfile = uniqid(getTmpDir() . "/img");
653  if (!copy($info->path, $newfile)) {
654  return "";
655  }
656  return $newfile;
657  }
658  if (preg_match('!^file/(?P<docid>\d+)/(?P<vid>\d+)/(?P<attrid>[^/]+)/(?P<index>[^/]+)/(?P<fname>[^?]+)!', $src, $reg)) {
659 
660  $fileDoc = new_doc("", $reg['docid']);
661  $filePath = getExportFileDocumentPath($fileDoc, $reg['attrid'], $reg['index']);
662 
663  if ($filePath) {
664  $newfile = uniqid(getTmpDir() . "/img");
665  if (!copy($filePath, $newfile)) {
666  return "";
667  }
668  return $newfile;
669  }
670  }
671 
672  return "";
673 }
674 
675 function realfile($src)
676 {
677  global $vf;
678  global $doc;
679  global $pubdir;
680  global $tmpfile;
681  $f = false;
682  if ($src == "cid:icon") {
683  $va = $doc->icon;
684  } else {
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('&amp;', '&', $reg[2]));
689  $tmpfile[] = $va;
690  } else {
691  $va = $src;
692  }
693  }
694 
695  if ($va != "") {
696  $ticon = explode("|", $va);
697  $vid = empty($ticon[1]) ? false : $ticon[1];
698 
699  if ($vid != "") {
700  $info = null;
701  /*
702  * @var VaultFileInfo $info
703  */
704  if ($vf->Retrieve($vid, $info) == "") {
705  $f = $info->path;
706  }
707  } else {
708  if (file_exists($va)) {
709  $f = $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)) {
715  $f = $va;
716  }
717  }
718  }
719  if ($f) return "src=\"$f\"";
720  return "";
721 }
Layout is a template generator.
convertFile($infile, $engine, $outfile, &$info)
Definition: Lib.Vault.php:219
$status
Definition: index.php:30
addWarningMsg($msg)
$tmpfile
$comment
Definition: fdl_execute.php:35
vault_properties($idfile, $teng_name="")
Definition: Lib.Vault.php:114
if($_POST["login"]=="")
Definition: chgpasswd.php:19
getTDoc($dbaccess, $id, $sqlfilters=array(), $result=array())
global $action
newFreeVaultFile($dbaccess)
Definition: Lib.Util.php:17
getMailAddr($userid, $full=false)
Definition: Lib.Common.php:133
global $pubdir
Definition: vault_init.php:18
srcfile($src)
Definition: mailcard.php:578
$message
sendCard(Action &$action, $docid, $to, $cc, $subject, $zonebodycard="", $ulink=false, $comment="", $from="", $bcc="", $format="html", $sendercopy=true, $addfiles=array(), $userinfo=null, $savecopy=false)
Definition: mailcard.php:156
static getParameterValue($application, $parameterName)
getv(&$t, $k, $d="")
getSysMimeFile($f, $fn="")
imgvaultfile($src)
Definition: mailcard.php:623
fileextension($filename, $ext="nop")
$to
copyvault($src)
Definition: mailcard.php:634
const DEFAULT_PUBDIR
Definition: Lib.Prefix.php:28
$subject
exitError($texterr, $exit=true, $code="")
$docid
Definition: cleanFamily.php:13
getFileExtension($filename)
getLayoutFile($app, $layfile)
Definition: Lib.Common.php:258
$outfile
mailcard(Action &$action)
Definition: mailcard.php:20
getParam($name, $def="")
must be in core or global type
Definition: Lib.Common.php:193
$bcc
getTmpDir($def= '/tmp')
Definition: Lib.Common.php:150
switch($command) exit
Definition: checkVault.php:46
new_Doc($dbaccess, $id= '', $latest=false)
realfile($src)
Definition: mailcard.php:675
$cc
$from
$vf
Definition: geticon.php:28
$dbaccess
Definition: checkVault.php:17
getExportFileDocumentPath(\Doc $doc, $attrid, $index=-1)
Definition: exportfile.php:225
$info
Definition: geticon.php:30
sendmailcard(Action &$action)
Definition: mailcard.php:121
getExtension($smime)
if($file) if($subject==""&&$file) if($subject=="") $err
← centre documentaire © anakeen