40 if (empty($objectclass) || empty($uploaddir)) {
41 dol_print_error(
null,
'include of actions_massactions.inc.php is done but var $objectclass or $uploaddir was not defined');
46 if (!empty($permtoread) && empty($permissiontoread)) {
47 $permissiontoread = $permtoread;
49 if (!empty($permtocreate) && empty($permissiontoadd)) {
50 $permissiontoadd = $permtocreate;
52 if (!empty($permtodelete) && empty($permissiontodelete)) {
53 $permissiontodelete = $permtodelete;
58 $maxformassaction = (empty($conf->global->MAIN_LIMIT_FOR_MASS_ACTIONS) ? 1000 : $conf->global->MAIN_LIMIT_FOR_MASS_ACTIONS);
59 if (!empty($massaction) && is_array($toselect) && count($toselect) < 1) {
63 if (!$error && is_array($toselect) && count($toselect) > $maxformassaction) {
64 setEventMessages($langs->trans(
'TooManyRecordForMassAction', $maxformassaction),
null,
'errors');
68 if (!$error && $massaction ==
'confirm_presend_attendees' && !
GETPOST(
'sendmail')) {
69 $massaction =
'presend_attendees';
71 if (!$error && $massaction ==
'confirm_presend_attendees') {
75 $langs->load(
"mails");
76 include_once DOL_DOCUMENT_ROOT .
'/core/lib/files.lib.php';
78 $listofobjectid = array();
80 $listofobjectref = array();
81 $oneemailperrecipient = (
GETPOST(
'oneemailperrecipient',
'int') ? 1 : 0);
84 require_once DOL_DOCUMENT_ROOT .
'/eventorganization/class/conferenceorboothattendee.class.php';
86 $listofselectedid = array();
87 $listofselectedref = array();
88 $objecttmp =
new $objectclass($db);
90 foreach ($toselect as $toselectid) {
91 $result = $objecttmp->fetch($toselectid);
93 $attendees = $attendee->fetchAll();
94 if (is_array($attendees) && count($attendees) > 0) {
95 foreach ($attendees as $attmail) {
96 if (!empty($attmail->email)) {
97 $attmail->fetch_thirdparty();
98 $listofselectedid[$attmail->email] = $attmail;
99 $listofselectedref[$attmail->email] = $objecttmp;
108 if (
GETPOST(
'fromtype',
'alpha') ===
'user' && empty($user->email)) {
111 $massaction =
'presend_attendees';
114 $receiver =
GETPOST(
'receiver',
'alphawithlgt');
115 if (!is_array($receiver)) {
116 if (empty($receiver) || $receiver ==
'-1') {
119 $receiver = array($receiver);
122 if (!trim($_POST[
'sendto']) && count($receiver) == 0 && count($listofselectedid) == 0) {
124 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Recipient")),
null,
'warnings');
125 $massaction =
'presend_attendees';
128 if (!
GETPOST(
'subject',
'restricthtml')) {
130 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"MailTopic")),
null,
'warnings');
131 $massaction =
'presend_attendees';
135 $objecttmp->fetch_thirdparty();
136 foreach ($listofselectedid as $email => $attendees) {
143 $sendto = $attendees->thirdparty->name .
'<' . trim($attendees->email) .
'>';
146 $receivercc =
GETPOST(
'receivercc',
'alphawithlgt');
147 if (!is_array($receivercc)) {
148 if ($receivercc ==
'-1') {
149 $receivercc = array();
151 $receivercc = array($receivercc);
155 if (trim($_POST[
'sendtocc'])) {
156 $tmparray[] = trim(
GETPOST(
'sendtocc',
'alphawithlgt'));
158 $sendtocc = implode(
',', $tmparray);
161 $langs->load(
"commercial");
164 $fromtype =
GETPOST(
'fromtype');
165 if ($fromtype ===
'user') {
166 $from = $user->getFullName($langs) .
' <' . $user->email .
'>';
167 } elseif ($fromtype ===
'company') {
168 $from = $conf->global->MAIN_INFO_SOCIETE_NOM .
' <' . $conf->global->MAIN_INFO_SOCIETE_MAIL .
'>';
169 } elseif (preg_match(
'/user_aliases_(\d+)/', $fromtype, $reg)) {
170 $tmp = explode(
',', $user->email_aliases);
171 $from = trim($tmp[($reg[1] - 1)]);
172 } elseif (preg_match(
'/global_aliases_(\d+)/', $fromtype, $reg)) {
173 $tmp = explode(
',', $conf->global->MAIN_INFO_SOCIETE_MAIL_ALIASES);
174 $from = trim($tmp[($reg[1] - 1)]);
175 } elseif (preg_match(
'/senderprofile_(\d+)_(\d+)/', $fromtype, $reg)) {
176 $sql =
"SELECT rowid, label, email FROM " . MAIN_DB_PREFIX .
"c_email_senderprofile WHERE rowid = " . (int) $reg[1];
177 $resql = $db->query($sql);
178 $obj = $db->fetch_object(
$resql);
187 $subject =
GETPOST(
'subject',
'restricthtml');
188 $message =
GETPOST(
'message',
'restricthtml');
190 $sendtobcc =
GETPOST(
'sendtoccc',
'alphawithlgt');
196 if (!empty($conf->global->MAIN_AGENDA_XCAL_EXPORTKEY)) {
197 $urlwithouturlroot = preg_replace(
'/' . preg_quote(DOL_URL_ROOT,
'/') .
'$/i',
'', trim($dolibarr_main_url_root));
198 $urlwithroot = $urlwithouturlroot . DOL_URL_ROOT;
199 $url_link = $urlwithroot .
'/public/agenda/agendaexport.php?format=ical' . ($conf->entity > 1 ?
"&entity=" . $conf->entity :
"");
200 $url_link .=
'&exportkey=' . ($conf->global->MAIN_AGENDA_XCAL_EXPORTKEY ? urlencode($conf->global->MAIN_AGENDA_XCAL_EXPORTKEY) :
'...');
201 $url_link .=
"&project=" . $listofselectedref[$email]->fk_project .
'&module=' . urlencode(
'@eventorganization') .
'&status=' . ConferenceOrBooth::STATUS_CONFIRMED;
202 $html_link =
'<a href="' . $url_link .
'">' . $langs->trans(
'DownloadICSLink') .
'</a>';
204 $substitutionarray[
'__EVENTORGANIZATION_ICS_LINK__'] = $html_link;
205 $substitutionarray[
'__EVENTORGANIZATION_URL_LINK__'] = $url_link;
206 $substitutionarray[
'__CHECK_READ__'] =
'<img src="' . DOL_MAIN_URL_ROOT .
'/public/emailing/mailing-read.php?tag=' . urlencode($attendees->thirdparty->tag) .
'&securitykey=' . urlencode($conf->global->MAILING_EMAIL_UNSUBSCRIBE_KEY) .
'" width="1" height="1" style="width:1px;height:1px" border="0"/>';
208 $parameters = array(
'mode' =>
'formemail');
210 if (!empty($listofobjectref)) {
211 $parameters[
'listofobjectref'] = $listofobjectref;
220 if (empty($sendcontext)) {
221 $sendcontext =
'standard';
225 require_once DOL_DOCUMENT_ROOT .
'/core/class/CMailFile.class.php';
226 $mailfile =
new CMailFile($subjectreplaced, $sendto, $from, $messagereplaced, array(), array(), array(), $sendtocc, $sendtobcc, $deliveryreceipt, -1,
'',
'',
"attendees_".$attendees->id,
'', $sendcontext);
227 if ($mailfile->error) {
228 $resaction .=
'<div class="error">' . $mailfile->error .
'</div>';
230 $result = $mailfile->sendfile();
232 $resaction .= $langs->trans(
'MailSuccessfulySent', $mailfile->getValidAddress($from, 2), $mailfile->getValidAddress($sendto, 2)) .
'<br>';
235 dol_syslog(
"Try to insert email event into agenda for objid=" . $attendees->id .
" => objectobj=" . get_class($attendees));
237 $actionmsg = $langs->transnoentities(
'MailSentBy') .
' ' . $from .
' ' . $langs->transnoentities(
'To') .
' ' . $sendto;
240 $actionmsg =
dol_concatdesc($actionmsg, $langs->transnoentities(
'Bcc') .
": " . $sendtocc);
242 $actionmsg =
dol_concatdesc($actionmsg, $langs->transnoentities(
'MailTopic') .
": " . $subjectreplaced);
243 $actionmsg =
dol_concatdesc($actionmsg, $langs->transnoentities(
'TextUsedInTheMessageBody') .
":");
248 $objectobj2 = $listofselectedref[$email];
250 $objectobj2->actionmsg = $actionmsg;
251 $objectobj2->actionmsg2 = $actionmsg2;
252 $objectobj2->fk_element = $objectobj2->id;
253 $objectobj2->elementtype = $objectobj2->element;
255 $triggername =
'CONFERENCEORBOOTHATTENDEE_SENTBYMAIL';
256 if (!empty($triggername)) {
258 $result = $objectobj2->call_trigger($triggername, $user);
266 dol_syslog(
"Error in trigger " . $triggername .
' ' . $db->lasterror(), LOG_ERR);
272 $langs->load(
"other");
273 if ($mailfile->error) {
274 $resaction .= $langs->trans(
'ErrorFailedToSendMail', $from, $sendto);
275 $resaction .=
'<br><div class="error">' . $mailfile->error .
'</div>';
276 } elseif (!empty($conf->global->MAIN_DISABLE_ALL_MAILS)) {
277 $resaction .=
'<div class="warning">No mail sent. Feature is disabled by option MAIN_DISABLE_ALL_MAILS</div>';
279 $resaction .= $langs->trans(
'ErrorFailedToSendMail', $from, $sendto) .
'<br><div class="error">(unhandled error)</div>';
285 $resaction .= ($resaction ?
'<br>' : $resaction);
286 $resaction .=
'<strong>' . $langs->trans(
"ResultOfMailSending") .
':</strong><br>' .
"\n";
287 $resaction .= $langs->trans(
"NbSelected") .
': ' . count($toselect) .
"\n<br>";
288 $resaction .= $langs->trans(
"NbIgnored") .
': ' . ($nbignored ? $nbignored : 0) .
"\n<br>";
289 $resaction .= $langs->trans(
"NbSent") .
': ' . ($nbsent ? $nbsent : 0) .
"\n<br>";
294 setEventMessages($langs->trans(
"EMailSentForNElements", $nbsent .
'/' . count($toselect)),
null,
'mesgs');
307 $parameters[
'toselect'] = $toselect;
308 $parameters[
'uploaddir'] = $uploaddir;
309 $parameters[
'massaction'] = $massaction;
310 $parameters[
'diroutputmassaction'] = isset($diroutputmassaction) ? $diroutputmassaction :
null;
312 $reshook = $hookmanager->executeHooks(
'doMassActions', $parameters, $object, $action);