1<?php
2/* Copyright (C)    2013      Cédric Salvador     <csalvador@gpcsolutions.fr>
3 * Copyright (C)    2013-2014 Laurent Destailleur <eldy@users.sourceforge.net>
4 * Copyright (C)	2015	  Marcos García		  <marcosgdf@gmail.com>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 3 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <https://www.gnu.org/licenses/>.
18 * or see https://www.gnu.org/
19 */
20
21// Following var must be set:
22// $arrayofselected = array of id selected
23// $object
24// $objecttmp=new Propal($db);
25// $topicmail="SendSupplierProposalRef";
26// $modelmail="supplier_proposal_send";
27// $trackid='ord'.$object->id;
28
29if ($massaction == 'presend_attendees') {
30	$langs->load("mails");
31	require_once DOL_DOCUMENT_ROOT.'/eventorganization/class/conferenceorboothattendee.class.php';
32	$attendee = new ConferenceOrBoothAttendee($db);
33	$listofselectedid = array();
34	$listofselectedref = array();
35
36	if (!GETPOST('cancel', 'alpha')) {
37		foreach ($arrayofselected as $toselectid) {
38			$result = $objecttmp->fetch($toselectid);
39			if ($result > 0) {
40				$attendees = $attendee->fetchAll('', '', 0, 0, array('t.fk_actioncomm'=>$objecttmp->id));
41				if (is_array($attendees) && count($attendees)>0) {
42					foreach ($attendees as $attmail) {
43						if (!empty($attmail->email)) {
44							$listofselectedid[$attmail->email] = $attmail->id;
45							$listofselectedref[$attmail->id][$toselectid] = $objecttmp->ref;
46						}
47					}
48				}
49			}
50		}
51	}
52
53	print '<input type="hidden" name="massaction" value="confirm_presend_attendees">';
54	print '<input type="hidden" name="projectid" value="'.GETPOST('projectid', 'int').'">';
55
56	include_once DOL_DOCUMENT_ROOT.'/core/class/html.formmail.class.php';
57	$formmail = new FormMail($db);
58
59	print dol_get_fiche_head(null, '', '');
60
61	// Cree l'objet formulaire mail
62	include_once DOL_DOCUMENT_ROOT.'/core/class/html.formmail.class.php';
63	$formmail = new FormMail($db);
64	$formmail->withform = -1;
65	$formmail->fromtype = (GETPOST('fromtype') ? GETPOST('fromtype') : (!empty($conf->global->MAIN_MAIL_DEFAULT_FROMTYPE) ? $conf->global->MAIN_MAIL_DEFAULT_FROMTYPE : 'user'));
66
67	if ($formmail->fromtype === 'user') {
68		$formmail->fromid = $user->id;
69	}
70	$formmail->trackid = $trackid;
71	if (!empty($conf->global->MAIN_EMAIL_ADD_TRACK_ID) && ($conf->global->MAIN_EMAIL_ADD_TRACK_ID & 2)) { // If bit 2 is set
72		include DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
73		$formmail->frommail = dolAddEmailTrackId($formmail->frommail, $trackid);
74	}
75	$formmail->withfrom = 1;
76	$liste = $langs->trans("AllRecipientSelected", count($listofselectedid));
77	$formmail->withtoreadonly = 1;
78
79	$formmail->withoptiononeemailperrecipient = ((count($listofselectedref) == 1 && count(reset($listofselectedref)) == 1) || empty($liste)) ? 0 : ((GETPOST('oneemailperrecipient') == 'on') ? 1 : -1);
80
81	$formmail->withto = empty($liste) ? (GETPOST('sendto', 'alpha') ?GETPOST('sendto', 'alpha') : array()) : $liste;
82	$formmail->withtofree = empty($liste) ? 1 : 0;
83	$formmail->withtocc = 1;
84	$formmail->withtoccc = $conf->global->MAIN_EMAIL_USECCC;
85	$formmail->withtopic = $langs->transnoentities($topicmail, '__REF__', '__REF_CLIENT__');
86	$formmail->withfile = 0;
87	// $formmail->withfile = 2; Not yet supported in mass action
88	$formmail->withmaindocfile = 0; // Add a checkbox "Attach also main document"
89	$formmail->withbody = 1;
90	$formmail->withdeliveryreceipt = 1;
91	$formmail->withcancel = 1;
92
93	// Make substitution in email content
94	$substitutionarray = getCommonSubstitutionArray($langs, 0, null, $object);
95
96	$substitutionarray['__EMAIL__'] = $sendto;
97	$substitutionarray['__CHECK_READ__'] = (is_object($object) && is_object($object->thirdparty)) ? '<img src="'.DOL_MAIN_URL_ROOT.'/public/emailing/mailing-read.php?tag='.urlencode($object->thirdparty->tag).'&securitykey='.urlencode($conf->global->MAILING_EMAIL_UNSUBSCRIBE_KEY).'" width="1" height="1" style="width:1px;height:1px" border="0"/>' : '';
98	$substitutionarray['__PERSONALIZED__'] = ''; // deprecated
99	$substitutionarray['__CONTACTCIVNAME__'] = '';
100
101	$parameters = array(
102		'mode' => 'formemail'
103	);
104	complete_substitutions_array($substitutionarray, $langs, $object, $parameters);
105
106	// Tableau des substitutions
107	$formmail->substit = $substitutionarray;
108
109	// Tableau des parametres complementaires du post
110	$formmail->param['action'] = $action;
111	$formmail->param['models'] = $modelmail;
112	$formmail->param['models_id'] = empty(GETPOST('modelmailselected', 'int'))?$conf->global->EVENTORGANIZATION_TEMPLATE_EMAIL_BULK_ATTENDES:GETPOST('modelmailselected', 'int');
113	$formmail->param['id'] = join(',', $arrayofselected);
114	// $formmail->param['returnurl']=$_SERVER["PHP_SELF"].'?id='.$object->id;
115	if (!empty($conf->global->MAILING_LIMIT_SENDBYWEB) && count($listofselectedid) > $conf->global->MAILING_LIMIT_SENDBYWEB) {
116		$langs->load("errors");
117		print img_warning().' '.$langs->trans('WarningNumberOfRecipientIsRestrictedInMassAction', $conf->global->MAILING_LIMIT_SENDBYWEB);
118		print ' - <a href="javascript: window.history.go(-1)">'.$langs->trans("GoBack").'</a>';
119		$arrayofmassactions = array();
120	} else {
121		print $formmail->get_form();
122	}
123
124	print dol_get_fiche_end();
125}
126// Allow Pre-Mass-Action hook (eg for confirmation dialog)
127$parameters = array(
128	'toselect' => $toselect,
129	'uploaddir' => isset($uploaddir) ? $uploaddir : null
130);
131