41 $action->parent->AddJsRef(htmlspecialchars(
"?app=FDL&action=FCKDOCATTR&famid=" . urlencode($mailfamily) , ENT_QUOTES));
51 private function checkAttributeExistsInRelation(
$values, array
$doc)
53 $tattrid = explode(
":",
$values);
54 if (count($tattrid) == 1) {
55 if (!array_key_exists($tattrid[0], $doc))
return sprintf(_(
"Send mail error : Attribute %s not found.") , $tattrid[0]);
58 $lattrid = array_pop($tattrid);
59 foreach ($tattrid as $v) {
60 if (!array_key_exists($v, $doc))
return sprintf(_(
"Send mail error : Relation to attribute %s not found. Incorrect relation key: %s") , $lattrid, $v);
65 return sprintf(_(
"Send mail error : Relation to attribute %s not found. Relation key %s does'nt link to a document") , $lattrid, $v);
67 $doc =
getTDoc($this->dbaccess, array_pop($docids));
68 if (!$doc)
return sprintf(_(
"Send mail error : Relation to attribute %s not found. Relation key %s does'nt link to a document") , $lattrid, $v);
70 if (!array_key_exists($lattrid, $doc))
return sprintf(_(
"Send mail error : Attribute %s not found.") , $lattrid);
81 public function getMailMessage(\
Doc & $doc,
$keys = array())
100 "tmail_copymode" =>
"from",
101 "tmail_desttype" => $this->
getRawValue(
"tmail_fromtype") ,
102 "tmail_recip" =>
$from
110 $wdoc = new_doc($this->dbaccess, $doc->wid);
113 foreach ($tdest as $k => $v) {
114 $toccbcc = $v[
"tmail_copymode"];
115 $type = $v[
"tmail_desttype"];
119 $mail = $v[
"tmail_recip"];
123 $aid = strtok($v[
"tmail_recip"],
" ");
124 $err = $this->checkAttributeExistsInRelation($aid,
getLatestTDoc($this->dbaccess, $doc->initid));
126 $action->log->error(
$err);
128 throw new \Dcp\Exception(
$err);
135 $aid = strtok($v[
"tmail_recip"],
" ");
138 $action->log->error(
$err);
140 throw new \Dcp\Exception(
$err);
142 $mail =
$wdoc->getRValue($aid);
147 $aid = strtok($v[
"tmail_recip"],
" ");
149 $action->log->error(sprintf(_(
"Send mail error : Parameter %s doesn't exists") , $aid));
150 $doc->
addHistoryEntry(sprintf(_(
"Send mail error : Parameter %s doesn't exists") , $aid));
151 throw new \Dcp\Exception(sprintf(_(
"Send mail error : Parameter %s doesn't exists") , $aid));
158 $aid = strtok($v[
"tmail_recip"],
" ");
159 if (!
$wdoc->getAttribute($aid)) {
160 $action->log->error(sprintf(_(
"Send mail error : Parameter %s doesn't exists") , $aid));
161 $wdoc->addHistoryEntry(sprintf(_(
"Send mail error : Parameter %s doesn't exists") , $aid));
162 throw new \Dcp\Exception(sprintf(_(
"Send mail error : Parameter %s doesn't exists") , $aid));
164 $mail =
$wdoc->getFamilyParameterValue($aid);
179 $aid = strtok($v[
"tmail_recip"],
" ");
180 if (!$udoc->getAttribute($aid) && !array_key_exists(strtolower($aid) , $udoc->getParamAttributes())) {
181 $action->log->error(sprintf(_(
"Send mail error : Attribute %s not found") , $aid));
182 $doc->
addHistoryEntry(sprintf(_(
"Send mail error : Attribute %s not found") , $aid));
183 throw new \Dcp\Exception(sprintf(_(
"Send mail error : Attribute %s not found") , $aid));
186 $vdocid = $udoc->getFamilyParameterValue($aid);
188 $vdocid = $udoc->getRawValue($aid);
191 $vdocid = str_replace(
'<BR>',
"\n", $vdocid);
192 if (strpos($vdocid,
"\n")) {
195 $it = new \DocumentList();
196 $it->addDocumentIdentifiers($tvdoc);
200 foreach ($it as $aDoc) {
202 if (method_exists($aDoc,
"getMail")) {
203 $umail = $aDoc->getMail();
206 $umail = $aDoc->getRawValue(
'us_mail',
'');
209 $umail = $aDoc->getRawValue(
'grp_mail',
'');
215 $mail = implode(
",", $tmail);
217 if (strpos($aid,
':')) {
218 $mail = $udoc->getRValue($aid);
225 if (method_exists($aDoc,
"getMail")) {
226 $mail = $aDoc->getMail();
229 $mail = $aDoc->getRawValue(
'us_mail',
'');
232 $mail = $aDoc->getRawValue(
'grp_mail',
'');
240 $aid = strtok($v[
"tmail_recip"],
" ");
242 $action->log->error(sprintf(_(
"Send mail error : Parameter %s doesn't exists") , $aid));
243 $doc->
addHistoryEntry(sprintf(_(
"Send mail error : Parameter %s doesn't exists") , $aid));
244 throw new \Dcp\Exception( sprintf(_(
"Send mail error : Parameter %s doesn't exists") , $aid));
250 $recipDocId = $v[
'tmail_recip'];
251 if (preg_match(
'/^(?P<id>\d+)/', $v[
'tmail_recip'], $m)) {
255 $recipDocId = $m[
'id'];
260 $recipientDoc =
new_Doc($this->dbaccess, $recipDocId,
true);
261 if (!is_object($recipientDoc) || !$recipientDoc->isAlive()) {
262 $err = sprintf(_(
"Send mail error: recipient document '%s' does not exists.") , $recipDocId);
263 $action->log->error(
$err);
265 throw new \Dcp\Exception(
$err);
267 if (!is_a($recipientDoc,
'IMailRecipient')) {
268 $err = sprintf(_(
"Send mail error: recipient document '%s' does not implements IMailRecipient interface.") , $recipDocId);
269 $action->log->error(
$err);
271 throw new \Dcp\Exception(
$err);
273 $mail = $recipientDoc->getMail();
276 if ($mail)
$dest[$toccbcc][] = str_replace(array(
293 ) , html_entity_decode(
$subject, ENT_COMPAT,
"UTF-8"));
294 $pfout = $this->generateMailInstance($doc, $this->
getRawValue(
"tmail_body") , $this->
getAttribute(
"tmail_body"));
296 $dest[
'to'] = array_filter(
$dest[
'to'],
function ($v)
298 return !preg_match(
'/^\s*$/', $v);
300 $dest[
'cc'] = array_filter($dest[
'cc'],
function ($v)
302 return !preg_match(
'/^\s*$/', $v);
304 $dest[
'bcc'] = array_filter($dest[
'bcc'],
function ($v)
306 return !preg_match(
'/^\s*$/', $v);
308 $dest[
'from'] = array_filter($dest[
'from'],
function ($v)
310 return !preg_match(
'/^\s*$/', $v);
313 $this->addSubstitutes($dest);
315 $to = implode(
',', $dest[
'to']);
316 $cc = implode(
',', $dest[
'cc']);
317 $bcc = implode(
',', $dest[
'bcc']);
318 $from = implode(
',', $dest[
'from']);
330 $action->log->info(sprintf(_(
"Send mail info : can't send mail %s: no sendee found") ,
$subject));
332 if ($this->stopIfNoRecip) {
336 if ($this->sendercopy &&
getParam(
"FDL_BCC") ==
"yes") {
338 if ($umail !=
"") $bcc.= (trim($bcc) ==
"" ?
"" :
",") . $umail;
341 $body = new \Dcp\Mail\Body($pfout,
'text/html');
345 foreach ($this->ifiles as $k => $v) {
346 if (file_exists($v)) {
347 $message->addBodyRelatedAttachment(
new \Dcp\Mail\RelatedAttachment($v, $k, sprintf(
"image/%s",
fileextension($v)) , $k));
352 foreach ($ta as $k => $v) {
353 $err = $this->checkAttributeExistsInRelation(strtok($v,
" ") ,
getLatestTDoc($this->dbaccess, $doc->initid));
355 $action->log->error(
$err);
357 throw new \Dcp\Exception(
$err);
362 foreach ($tvf as
$vf) {
365 if ($fileinfo[
"path"]) {
366 $message->addAttachment(
new \Dcp\Mail\Attachment($fileinfo[
'path'], $fileinfo[
'name'], $fileinfo[
'mime_s']));
393 include_once (
"FDL/sendmail.php");
394 include_once (
"FDL/Lib.Vault.php");
401 $this->stopIfNoRecip=
true;
406 $this->stopIfNoRecip=
false;
408 $this->stopIfNoRecip=
false;
409 return $e->getMessage();
418 $savecopy = $this->
getRawValue(
"tmail_savecopy") ==
"yes";
419 if ((
$err ==
"") && $savecopy) {
424 $recip.= sprintf(_(
"sendmailto %s") ,
$to);
427 $recip.=
' ' . sprintf(_(
"sendmailcc %s") ,
$cc);
430 $recip.=
' ' . sprintf(_(
"sendmailbcc %s") , $bcc);
433 if (self::NOTIFY_SENDMAIL_AUTO === $this->notifySendMail) {
444 $action->log->info(sprintf(_(
"Mail %s sent to %s") ,
$subject, $recip));
450 $action->log->error(sprintf(_(
"cannot send mail %s to %s : %s") ,
$subject, $recip,
$err));
465 $allowedValues = [self::NOTIFY_SENDMAIL_ALWAYS, self::NOTIFY_SENDMAIL_ERRORS_ONLY, self::NOTIFY_SENDMAIL_NEVER, self::NOTIFY_SENDMAIL_AUTO];
481 private function generateMailInstance(\
Doc & $doc, $tpl, $oattr =
false)
484 $tpl = str_replace(
"[",
"[", $tpl);
485 $doc->lay = new \Layout(
"", $action, $tpl);
487 $ulink = ($this->
getRawValue(
"tmail_ulink") ==
"yes");
490 foreach ($this->keys as $k => $v) $doc->lay->set($k, $v);
491 $body = $doc->lay->gen();
492 $body = preg_replace_callback(array(
493 "/SRC=\"([^\"]+)\"/",
495 ) ,
function ($matches)
497 return $this->srcfile($matches[1]);
501 if ($oattr !==
false && $oattr->type ==
'htmltext') {
502 $body = $doc->
getHtmlValue($oattr, $body,
"mail", $ulink);
510 private function addSubstitutes(array & $dests)
512 $sql =
"SELECT incumbent.login as inlogin, incumbent.mail as inmail, substitut.firstname || ' ' || substitut.lastname as suname , substitut.mail as sumail from users as incumbent, users as substitut where substitut.id=incumbent.substitute and incumbent.substitute is not null and incumbent.mail is not null and substitut.mail is not null;";
519 if (!isset($dests[$td])) {
522 foreach ($dests[$td] as & $aDest) {
523 foreach ($substituteMails as $aSumail) {
524 $suName = str_replace(
'"',
'', sprintf(_(
"%s (as substitute)") , $aSumail[
"suname"]));
525 $aDest = str_replace(sprintf(
'<%s>', $aSumail[
"inmail"]) , sprintf(
'<%s>, "%s" <%s>', $aSumail[
"inmail"], $suName, $aSumail[
"sumail"]) , $aDest);
527 $aDest = preg_replace(sprintf(
'/(^|,|\s)(%s)/', preg_quote($aSumail[
"inmail"],
"/")) , sprintf(
'\1\2, "%s" <%s>', $suName, $aSumail[
"sumail"]) , $aDest);
534 private function getUniqId()
537 if (!$unid) $unid = date(
'Ymdhis');
540 private function srcfile($src)
550 if (substr($src, 0, 3) ==
"cid")
return "src=\"$src\"";
551 if (substr($src, 0, 4) ==
"http") {
559 if (strlen($url) <= 0) {
562 if (strcmp(substr($src, 0, strlen($url)) , $url) == 0) {
564 $chopped_src = substr($src, strlen($url));
568 if ($chopped_src ==
'') {
569 return sprintf(
'src="%s"', $src);
575 if (preg_match(
"/.*app=FDL.*action=EXPORTFILE.*vid=([0-9]*)/", $src, $reg)) {
579 } elseif (preg_match(
'!file/(?P<docid>\d+)/(?P<vid>\d+)/(?P<attrid>[^/]+)/(?P<index>[^/]+)/(?P<fname>[^?]+)!', $src, $reg)) {
589 $this->ifiles[$cid] = $src;
590 return "src=\"cid:$cid\"";
vault_properties(NormalAttribute $attr)
getTDoc($dbaccess, $id, $sqlfilters=array(), $result=array())
& getAttribute($idAttr, &$oa=null, $useMask=true)
getMailAddr($userid, $full=false)
static rawValueToArray($v)
static getParameterValue($application, $parameterName)
fileextension($filename, $ext="nop")
getArrayRawValues($idAttr, $index=-1)
viewdefaultcard($target="_self", $ulink=true, $abstract=false, $viewhidden=false)
setNotification($notifySendMail)
getRValue($RidAttr, $def="", $latest=true, $html=false)
getFamilyParameterValue($idp, $def="")
getLatestTDoc($dbaccess, $initid, $sqlfilters=array(), $fromid=false)
getMultipleRawValues($idAttr, $def="", $index=-1)
const NOTIFY_SENDMAIL_ERRORS_ONLY
getHttpVars($name, $def="", $scope="all")
getParam($param, $defv="")
sendDocument(\Doc &$doc, $keys=array())
getHtmlValue($oattr, $value, $target="_self", $htmllink=true, $index=-1, $entities=true, $abstract=false)
getFileInfo($filesvalue, $key="", $returnType="array")
const NOTIFY_SENDMAIL_ALWAYS
const NOTIFY_SENDMAIL_AUTO
new_Doc($dbaccess, $id= '', $latest=false)
const NOTIFY_SENDMAIL_NEVER
getLatestDocIds($dbaccess, $ids)
simpleQuery($dbaccess, $query, &$result=array(), $singlecolumn=false, $singleresult=false, $useStrict=null)
if($file) if($subject==""&&$file) if($subject=="") $err
addHistoryEntry($comment= '', $level=DocHisto::INFO, $code= '', $uid= '')
getRawValue($idAttr, $def="")