massactions_pre.tpl.php 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  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. // Following var must be set:
  21. // $arrayofselected = array of id selected
  22. // $object
  23. // $objecttmp=new Propal($db);
  24. // $topicmail="SendSupplierProposalRef";
  25. // $modelmail="supplier_proposal_send";
  26. // $trackid='ord'.$object->id;
  27. if ($massaction == 'predeletedraft') {
  28. print $form->formconfirm($_SERVER["PHP_SELF"], $langs->trans("ConfirmMassDraftDeletion"), $langs->trans("ConfirmMassDeletionQuestion", count($toselect)), "delete", null, '', 0, 200, 500, 1);
  29. }
  30. if ($massaction == 'predelete') {
  31. print $form->formconfirm($_SERVER["PHP_SELF"], $langs->trans("ConfirmMassDeletion"), $langs->trans("ConfirmMassDeletionQuestion", count($toselect)), "delete", null, '', 0, 200, 500, 1);
  32. }
  33. if ($massaction == 'preaffecttag') {
  34. require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php';
  35. $categ = new Categorie($db);
  36. $categ_types=array();
  37. $categ_type_array=$categ->getMapList();
  38. foreach ($categ_type_array as $categdef) {
  39. if (isset($object) && $categdef['obj_table']==$object->table_element) {
  40. if (!array_key_exists($categdef['code'], $categ_types)) {
  41. $categ_types[$categdef['code']] = array('code'=>$categdef['code'],'label'=>$langs->trans($categdef['obj_class']));
  42. }
  43. }
  44. if (isset($objecttmp) && $categdef['obj_table']==$objecttmp->table_element) {
  45. if (!array_key_exists($categdef['code'], $categ_types)) {
  46. $categ_types[$categdef['code']] = array('code'=>$categdef['code'],'label'=>$langs->trans($categdef['obj_class']));
  47. }
  48. }
  49. }
  50. $formquestion = array();
  51. if (!empty($categ_types)) {
  52. foreach ($categ_types as $categ_type) {
  53. $cate_arbo = $form->select_all_categories($categ_type['code'], null, 'parent', null, null, 1);
  54. $formquestion[]=array('type' => 'other',
  55. 'name' => 'affecttag_'.$categ_type['code'],
  56. 'label' => $langs->trans("Tag").' '.$categ_type['label'],
  57. 'value' => $form->multiselectarray('contcats_'.$categ_type['code'], $cate_arbo, GETPOST('contcats_'.$categ_type['code'], 'array'), null, null, null, null, '60%'));
  58. }
  59. $formquestion[]=array('type' => 'other',
  60. 'name' => 'affecttag_type',
  61. 'label' => '',
  62. 'value' => '<input type="hidden" name="affecttag_type" id="affecttag_type" value="'.implode(",", array_keys($categ_types)).'"/>');
  63. print $form->formconfirm($_SERVER["PHP_SELF"], $langs->trans("ConfirmAffectTag"), $langs->trans("ConfirmAffectTagQuestion", count($toselect)), "affecttag", $formquestion, 1, 0, 200, 500, 1);
  64. } else {
  65. setEventMessage('CategTypeNotFound');
  66. }
  67. }
  68. if ($massaction == 'presend') {
  69. $langs->load("mails");
  70. $listofselectedid = array();
  71. $listofselectedthirdparties = array();
  72. $listofselectedref = array();
  73. if (!GETPOST('cancel', 'alpha')) {
  74. foreach ($arrayofselected as $toselectid) {
  75. $result = $objecttmp->fetch($toselectid);
  76. if ($result > 0) {
  77. $listofselectedid[$toselectid] = $toselectid;
  78. $thirdpartyid = ($objecttmp->fk_soc ? $objecttmp->fk_soc : $objecttmp->socid);
  79. if ($objecttmp->element == 'societe') {
  80. $thirdpartyid = $objecttmp->id;
  81. }
  82. if ($objecttmp->element == 'expensereport') {
  83. $thirdpartyid = $objecttmp->fk_user_author;
  84. }
  85. $listofselectedthirdparties[$thirdpartyid] = $thirdpartyid;
  86. $listofselectedref[$thirdpartyid][$toselectid] = $objecttmp->ref;
  87. }
  88. }
  89. }
  90. print '<input type="hidden" name="massaction" value="confirm_presend">';
  91. print dol_get_fiche_head(null, '', '');
  92. // Create mail form
  93. include_once DOL_DOCUMENT_ROOT.'/core/class/html.formmail.class.php';
  94. $formmail = new FormMail($db);
  95. $formmail->withform = -1;
  96. $formmail->fromtype = (GETPOST('fromtype') ? GETPOST('fromtype') : (!empty($conf->global->MAIN_MAIL_DEFAULT_FROMTYPE) ? $conf->global->MAIN_MAIL_DEFAULT_FROMTYPE : 'user'));
  97. if ($formmail->fromtype === 'user') {
  98. $formmail->fromid = $user->id;
  99. }
  100. $formmail->trackid = $trackid;
  101. $formmail->withfrom = 1;
  102. $liste = $langs->trans("AllRecipientSelected", count($arrayofselected));
  103. if (count($listofselectedthirdparties) == 1) { // Only 1 different recipient selected, we can suggest contacts
  104. $liste = array();
  105. $thirdpartyid = array_shift($listofselectedthirdparties);
  106. if ($objecttmp->element == 'expensereport') {
  107. $fuser = new User($db);
  108. $fuser->fetch($thirdpartyid);
  109. $liste['thirdparty'] = $fuser->getFullName($langs)." &lt;".$fuser->email."&gt;";
  110. } elseif ($objecttmp->element == 'partnership' && $conf->global->PARTNERSHIP_IS_MANAGED_FOR == 'member') {
  111. $fadherent = new Adherent($db);
  112. $fadherent->fetch($objecttmp->fk_member);
  113. $liste['member'] = $fadherent->getFullName($langs)." &lt;".$fadherent->email."&gt;";
  114. } else {
  115. $soc = new Societe($db);
  116. $soc->fetch($thirdpartyid);
  117. foreach ($soc->thirdparty_and_contact_email_array(1) as $key => $value) {
  118. $liste[$key] = $value;
  119. }
  120. }
  121. $formmail->withtoreadonly = 0;
  122. } else {
  123. $formmail->withtoreadonly = 1;
  124. }
  125. $formmail->withoptiononeemailperrecipient = ((count($listofselectedref) == 1 && count(reset($listofselectedref)) == 1) || empty($liste)) ? 0 : ((GETPOST('oneemailperrecipient') == 'on') ? 1 : -1);
  126. $formmail->withto = empty($liste) ? (GETPOST('sendto', 'alpha') ?GETPOST('sendto', 'alpha') : array()) : $liste;
  127. $formmail->withtofree = empty($liste) ? 1 : 0;
  128. $formmail->withtocc = 1;
  129. $formmail->withtoccc = $conf->global->MAIN_EMAIL_USECCC;
  130. $formmail->withtopic = $langs->transnoentities($topicmail, '__REF__', '__REF_CLIENT__');
  131. $formmail->withfile = 1;
  132. // $formmail->withfile = 2; Not yet supported in mass action
  133. $formmail->withmaindocfile = 1; // Add a checkbox "Attach also main document"
  134. if ($objecttmp->element != 'societe') {
  135. $formmail->withfile = '<span class="hideonsmartphone">'.$langs->trans("OnlyPDFattachmentSupported").'</span>';
  136. $formmail->withmaindocfile = - 1; // Add a checkbox "Attach also main document" but not checked by default
  137. }
  138. $formmail->withbody = 1;
  139. $formmail->withdeliveryreceipt = 1;
  140. $formmail->withcancel = 1;
  141. // Make substitution in email content
  142. $substitutionarray = getCommonSubstitutionArray($langs, 0, null, $object);
  143. $substitutionarray['__EMAIL__'] = $sendto;
  144. $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"/>' : '';
  145. $substitutionarray['__PERSONALIZED__'] = ''; // deprecated
  146. $substitutionarray['__CONTACTCIVNAME__'] = '';
  147. $parameters = array(
  148. 'mode' => 'formemail'
  149. );
  150. complete_substitutions_array($substitutionarray, $langs, $object, $parameters);
  151. // Tableau des substitutions
  152. $formmail->substit = $substitutionarray;
  153. // Tableau des parametres complementaires du post
  154. $formmail->param['action'] = $action;
  155. $formmail->param['models'] = $modelmail;
  156. $formmail->param['models_id'] = GETPOST('modelmailselected', 'int');
  157. $formmail->param['id'] = join(',', $arrayofselected);
  158. // $formmail->param['returnurl']=$_SERVER["PHP_SELF"].'?id='.$object->id;
  159. if (!empty($conf->global->MAILING_LIMIT_SENDBYWEB) && count($listofselectedthirdparties) > $conf->global->MAILING_LIMIT_SENDBYWEB) {
  160. $langs->load("errors");
  161. print img_warning().' '.$langs->trans('WarningNumberOfRecipientIsRestrictedInMassAction', $conf->global->MAILING_LIMIT_SENDBYWEB);
  162. print ' - <a href="javascript: window.history.go(-1)">'.$langs->trans("GoBack").'</a>';
  163. $arrayofmassactions = array();
  164. } else {
  165. print $formmail->get_form();
  166. }
  167. print dol_get_fiche_end();
  168. }
  169. if ($massaction == 'preenable') {
  170. print $form->formconfirm($_SERVER["PHP_SELF"], $langs->trans("ConfirmMassEnabling"), $langs->trans("ConfirmMassEnablingQuestion", count($toselect)), "enable", null, '', 0, 200, 500, 1);
  171. }
  172. if ($massaction == 'predisable') {
  173. print $form->formconfirm($_SERVER["PHP_SELF"], $langs->trans("ConfirmMassDisabling"), $langs->trans("ConfirmMassDisablingQuestion", count($toselect)), "disable", null, '', 0, 200, 500, 1);
  174. }
  175. if ($massaction == 'preapproveleave') {
  176. print $form->formconfirm($_SERVER["PHP_SELF"], $langs->trans("ConfirmMassLeaveApproval"), $langs->trans("ConfirmMassLeaveApprovalQuestion", count($toselect)), "approveleave", null, '', 0, 200, 500, 1);
  177. }
  178. // Allow Pre-Mass-Action hook (eg for confirmation dialog)
  179. $parameters = array(
  180. 'toselect' => $toselect,
  181. 'uploaddir' => isset($uploaddir) ? $uploaddir : null
  182. );
  183. $reshook = $hookmanager->executeHooks('doPreMassActions', $parameters, $object, $action);
  184. if ($reshook < 0) {
  185. setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
  186. } else {
  187. print $hookmanager->resPrint;
  188. }