massactions_pre.tpl.php 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376
  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. // $action
  22. // $arrayofselected = array of id selected
  23. // $objecttmp = new MyObject($db);
  24. // $topicmail="SendSupplierProposalRef";
  25. // $modelmail="supplier_proposal_send";
  26. // $trackid='ord'.$objecttmp->id;
  27. //
  28. // Following var can be set
  29. // $object = Object fetched;
  30. // $sendto
  31. // $withmaindocfilemail
  32. if ($massaction == 'predeletedraft') {
  33. print $form->formconfirm($_SERVER["PHP_SELF"], $langs->trans("ConfirmMassDraftDeletion"), $langs->trans("ConfirmMassDeletionQuestion", count($toselect)), "delete", null, '', 0, 200, 500, 1);
  34. }
  35. if ($massaction == 'predelete') {
  36. print $form->formconfirm($_SERVER["PHP_SELF"], $langs->trans("ConfirmMassDeletion"), $langs->trans("ConfirmMassDeletionQuestion", count($toselect)), "delete", null, '', 0, 200, 500, 1);
  37. }
  38. if ($massaction == 'preaffecttag' && isModEnabled('category')) {
  39. require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php';
  40. $categ = new Categorie($db);
  41. $categ_types = array();
  42. $categ_type_array = $categ->getMapList();
  43. foreach ($categ_type_array as $categdef) {
  44. // Test on $object (should be useless, we already check on $objecttmp just after)
  45. if (isset($object) && $categdef['obj_table'] == $object->table_element) {
  46. if (!array_key_exists($categdef['code'], $categ_types)) {
  47. $categ_types[$categdef['code']] = array('code'=>$categdef['code'], 'label'=>$langs->trans($categdef['obj_class']));
  48. }
  49. }
  50. if (isset($objecttmp) && $categdef['obj_table'] == $objecttmp->table_element) {
  51. if (!array_key_exists($categdef['code'], $categ_types)) {
  52. $categ_types[$categdef['code']] = array('code'=>$categdef['code'], 'label'=>$langs->trans($categdef['obj_class']));
  53. }
  54. }
  55. }
  56. $formquestion = array();
  57. if (!empty($categ_types)) {
  58. foreach ($categ_types as $categ_type) {
  59. $categ_arbo_tmp = $form->select_all_categories($categ_type['code'], null, 'parent', null, null, 2);
  60. $formquestion[] = array(
  61. 'type' => 'other',
  62. 'name' => 'affecttag_'.$categ_type['code'],
  63. 'label' => '',
  64. 'value' => $form->multiselectarray('contcats_'.$categ_type['code'], $categ_arbo_tmp, GETPOST('contcats_'.$categ_type['code'], 'array'), null, null, '', 0, '60%', '', '', $langs->trans("SelectTheTagsToAssign"))
  65. );
  66. }
  67. $formquestion[] = array(
  68. 'type' => 'other',
  69. 'name' => 'affecttag_type',
  70. 'label' => '',
  71. 'value' => '<input type="hidden" name="affecttag_type" id="affecttag_type" value="'.implode(",", array_keys($categ_types)).'"/>'
  72. );
  73. print $form->formconfirm($_SERVER["PHP_SELF"], $langs->trans("ConfirmAffectTag"), $langs->trans("ConfirmAffectTagQuestion", count($toselect)), "affecttag", $formquestion, 1, 0, 200, 500, 1);
  74. } else {
  75. setEventMessage('CategTypeNotFound');
  76. }
  77. }
  78. if ($massaction == 'preupdateprice' && isModEnabled('category')) {
  79. $formquestion = array();
  80. $valuefield = '<div style="display: flex; align-items: center; justify-content: flex-end; padding-right: 150px">';
  81. $valuefield .= '<input type="number" name="pricerate" id="pricerate" min="-100" value="0" style="width: 100px; text-align: right; margin-right: 10px" />%';
  82. $valuefield .= '</div>';
  83. $formquestion[] = array(
  84. 'type' => 'other',
  85. 'name' => 'pricerate',
  86. 'label' => $langs->trans("Rate"),
  87. 'value' => $valuefield
  88. );
  89. print $form->formconfirm($_SERVER["PHP_SELF"], $langs->trans("ConfirmUpdatePrice"), $langs->trans("ConfirmUpdatePriceQuestion", count($toselect)), "updateprice", $formquestion, 1, 0, 200, 500, 1);
  90. }
  91. if ($massaction == 'presetsupervisor') {
  92. $formquestion = array();
  93. $valuefield = '<div style="display: flex; align-items: center; justify-content: flex-end; padding-right: 150px">';
  94. $valuefield .= img_picto('', 'user').' ';
  95. $valuefield .= $form->select_dolusers('', 'supervisortoset', 1, $arrayofselected, 0, '', 0, $object->entity, 0, 0, '', 0, '', 'widthcentpercentminusx maxwidth300');
  96. $valuefield .= '</div>';
  97. $formquestion[] = array(
  98. 'type' => 'other',
  99. 'name' => 'supervisortoset',
  100. 'label' => $langs->trans("Supervisor"),
  101. 'value' => $valuefield
  102. );
  103. print $form->formconfirm($_SERVER["PHP_SELF"], $langs->trans("ConfirmSetSupervisor"), $langs->trans("ConfirmSetSupervisorQuestion", count($toselect)), "setsupervisor", $formquestion, 1, 0, 200, 500, 1);
  104. }
  105. if ($massaction == 'preaffectuser') {
  106. $formquestion = array();
  107. $valuefielduser = '<div style="display: flex; align-items: center; justify-content: flex-end; padding-right: 165px; padding-bottom: 6px; gap: 5px">';
  108. $valuefielduser .= img_picto('', 'user').' ';
  109. $valuefielduser .= $form->select_dolusers('', 'usertoaffect', 1, $arrayofselected, 0, '', 0, $object->entity, 0, 0, '', 0, '', 'widthcentpercentminusx maxwidth300');
  110. $valuefielduser .= '</div>';
  111. $valuefieldprojrole = '<div style="display: flex; align-items: center; justify-content: flex-end; padding-right: 150px; padding-bottom: 6px">';
  112. $valuefieldprojrole .= $formcompany->selectTypeContact($object, '', 'projectrole', 'internal', 'position', 0, 'widthcentpercentminusx maxwidth300', 0);
  113. $valuefieldprojrole .= '</div>';
  114. $valuefieldtasksrole = '<div style="display: flex; align-items: center; justify-content: flex-end; padding-right: 150px">';
  115. $valuefieldtasksrole .= $formcompany->selectTypeContact($taskstatic, '', 'tasksrole', 'internal', 'position', 0, 'widthcentpercentminusx maxwidth300', 0);
  116. $valuefieldtasksrole .= '</div>';
  117. $formquestion[] = array(
  118. 'type' => 'other',
  119. 'name' => 'usertoaffect',
  120. 'label' => $langs->trans("User"),
  121. 'value' => $valuefielduser
  122. );
  123. $formquestion[] = array(
  124. 'type' => 'other',
  125. 'name' => 'projectrole',
  126. 'label' => $langs->trans("ProjectRole"),
  127. 'value' => $valuefieldprojrole
  128. );
  129. $formquestion[] = array(
  130. 'type' => 'other',
  131. 'name' => 'tasksrole',
  132. 'label' => $langs->trans("TasksRole"),
  133. 'value' => $valuefieldtasksrole
  134. );
  135. print $form->formconfirm($_SERVER["PHP_SELF"], $langs->trans("ConfirmAffectUser"), $langs->trans("ConfirmAffectUserQuestion", count($toselect)), "affectuser", $formquestion, 1, 0, 200, 500, 1);
  136. }
  137. if ($massaction == 'presend') {
  138. $langs->load("mails");
  139. $listofselectedid = array();
  140. $listofselectedrecipientobjid = array();
  141. $listofselectedref = array();
  142. if (!GETPOST('cancel', 'alpha')) {
  143. foreach ($arrayofselected as $toselectid) {
  144. $result = $objecttmp->fetch($toselectid);
  145. if ($result > 0) {
  146. $listofselectedid[$toselectid] = $toselectid;
  147. $thirdpartyid = ($objecttmp->fk_soc ? $objecttmp->fk_soc : $objecttmp->socid); // For proposal, order, invoice, conferenceorbooth, ...
  148. if (in_array($objecttmp->element, array('societe', 'conferenceorboothattendee'))) {
  149. $thirdpartyid = $objecttmp->id;
  150. }
  151. if ($objecttmp->element == 'expensereport') {
  152. $thirdpartyid = $objecttmp->fk_user_author;
  153. }
  154. if (empty($thirdpartyid)) {
  155. $thirdpartyid = 0;
  156. }
  157. if ($thirdpartyid) {
  158. $listofselectedrecipientobjid[$thirdpartyid] = $thirdpartyid;
  159. }
  160. $listofselectedref[$thirdpartyid][$toselectid] = $objecttmp->ref;
  161. }
  162. }
  163. }
  164. print '<input type="hidden" name="massaction" value="confirm_presend">';
  165. print dol_get_fiche_head(null, '', '');
  166. // Create mail form
  167. include_once DOL_DOCUMENT_ROOT.'/core/class/html.formmail.class.php';
  168. $formmail = new FormMail($db);
  169. $formmail->withform = -1;
  170. $formmail->fromtype = (GETPOST('fromtype') ? GETPOST('fromtype') : (!empty($conf->global->MAIN_MAIL_DEFAULT_FROMTYPE) ? $conf->global->MAIN_MAIL_DEFAULT_FROMTYPE : 'user'));
  171. if ($formmail->fromtype === 'user') {
  172. $formmail->fromid = $user->id;
  173. }
  174. $formmail->trackid = $trackid;
  175. $formmail->withfrom = 1;
  176. $liste = $langs->trans("AllRecipientSelected", count($arrayofselected));
  177. if (count($listofselectedrecipientobjid) == 1) { // Only 1 different recipient selected, we can suggest contacts
  178. $liste = array();
  179. $thirdpartyid = array_shift($listofselectedrecipientobjid);
  180. if ($objecttmp->element == 'expensereport') {
  181. $fuser = new User($db);
  182. $fuser->fetch($thirdpartyid);
  183. $liste['thirdparty'] = $fuser->getFullName($langs)." &lt;".$fuser->email."&gt;";
  184. } elseif ($objecttmp->element == 'partnership' && getDolGlobalString('PARTNERSHIP_IS_MANAGED_FOR') == 'member') {
  185. $fadherent = new Adherent($db);
  186. $fadherent->fetch($objecttmp->fk_member);
  187. $liste['member'] = $fadherent->getFullName($langs)." &lt;".$fadherent->email."&gt;";
  188. } else {
  189. $soc = new Societe($db);
  190. $soc->fetch($thirdpartyid);
  191. foreach ($soc->thirdparty_and_contact_email_array(1) as $key => $value) {
  192. $liste[$key] = $value;
  193. }
  194. }
  195. $formmail->withtoreadonly = 0;
  196. } else {
  197. $formmail->withtoreadonly = 1;
  198. }
  199. $formmail->withoptiononeemailperrecipient = ((count($listofselectedref) == 1 && count(reset($listofselectedref)) == 1) || empty($liste)) ? 0 : (GETPOST('oneemailperrecipient', 'int') ? 1 : -1);
  200. if (in_array($objecttmp->element, array('conferenceorboothattendee'))) {
  201. $formmail->withoptiononeemailperrecipient = 0;
  202. }
  203. $formmail->withto = empty($liste) ? (GETPOST('sendto', 'alpha') ?GETPOST('sendto', 'alpha') : array()) : $liste;
  204. $formmail->withtofree = empty($liste) ? 1 : 0;
  205. $formmail->withtocc = 1;
  206. $formmail->withtoccc = $conf->global->MAIN_EMAIL_USECCC;
  207. if (!empty($topicmail)) {
  208. $formmail->withtopic = $langs->transnoentities($topicmail, '__REF__', '__REF_CLIENT__');
  209. } else {
  210. $formmail->withtopic = 1;
  211. }
  212. $formmail->withfile = 1; // $formmail->withfile = 2 to allow to upload files is not yet supported in mass action
  213. // Add a checkbox "Attach also main document"
  214. if (isset($withmaindocfilemail)) {
  215. $formmail->withmaindocfile = $withmaindocfilemail;
  216. } else { // Do an automatic definition of $formmail->withmaindocfile
  217. $formmail->withmaindocfile = 1;
  218. if ($objecttmp->element != 'societe') {
  219. $formmail->withfile = '<span class="hideonsmartphone opacitymedium">'.$langs->trans("OnlyPDFattachmentSupported").'</span>';
  220. $formmail->withmaindocfile = -1; // Add a checkbox "Attach also main document" but not checked by default
  221. }
  222. }
  223. $formmail->withbody = 1;
  224. $formmail->withdeliveryreceipt = 1;
  225. $formmail->withcancel = 1;
  226. // Make substitution in email content
  227. $substitutionarray = getCommonSubstitutionArray($langs, 0, null, $object);
  228. $substitutionarray['__EMAIL__'] = $sendto;
  229. $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"/>' : '';
  230. $substitutionarray['__PERSONALIZED__'] = ''; // deprecated
  231. $substitutionarray['__CONTACTCIVNAME__'] = '';
  232. $parameters = array(
  233. 'mode' => 'formemail'
  234. );
  235. complete_substitutions_array($substitutionarray, $langs, $object, $parameters);
  236. // Array of substitutions
  237. $formmail->substit = $substitutionarray;
  238. // Tableau des parametres complementaires du post
  239. $formmail->param['action'] = $action;
  240. $formmail->param['models'] = $modelmail; // the filter to know which kind of template emails to show. 'none' means no template suggested.
  241. $formmail->param['models_id'] = GETPOST('modelmailselected', 'int') ? GETPOST('modelmailselected', 'int') : '-1';
  242. $formmail->param['id'] = join(',', $arrayofselected);
  243. // $formmail->param['returnurl']=$_SERVER["PHP_SELF"].'?id='.$object->id;
  244. if (!empty($conf->global->MAILING_LIMIT_SENDBYWEB) && count($listofselectedrecipientobjid) > $conf->global->MAILING_LIMIT_SENDBYWEB) {
  245. $langs->load("errors");
  246. print img_warning().' '.$langs->trans('WarningNumberOfRecipientIsRestrictedInMassAction', $conf->global->MAILING_LIMIT_SENDBYWEB);
  247. print ' - <a href="javascript: window.history.go(-1)">'.$langs->trans("GoBack").'</a>';
  248. $arrayofmassactions = array();
  249. } else {
  250. print $formmail->get_form();
  251. }
  252. print dol_get_fiche_end();
  253. }
  254. if ($massaction == 'edit_extrafields') {
  255. require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php';
  256. $elementtype = $objecttmp->element;
  257. /** @var CommonObject $objecttmp */
  258. $extrafields = new ExtraFields($db);
  259. $keysuffix = '';
  260. $extrafields->fetch_name_optionals_label($elementtype);
  261. $extrafields_list = $extrafields->attributes[$elementtype]['label'];
  262. $formquestion = array();
  263. if (!empty($extrafields_list)) {
  264. $myParamExtra = $object->showOptionals($extrafields, 'create');
  265. $formquestion[] = array(
  266. 'type' => 'other',
  267. 'value' => $form->selectarray('extrafield-key-to-update', $extrafields_list, GETPOST('extrafield-key-to-update'), 1)
  268. );
  269. $outputShowOutputFields = '<div class="extrafields-inputs">';
  270. foreach ($extrafields_list as $extraKey => $extraLabel) {
  271. $outputShowOutputFields.= '<div class="mass-action-extrafield" data-extrafield="'.$extraKey.'" style="display:none;" >';
  272. $outputShowOutputFields.= '<br><span>'. $langs->trans('NewValue').'</span>';
  273. $outputShowOutputFields.= $extrafields->showInputField($extraKey, '', '', $keysuffix, '', 0, $objecttmp->id, $objecttmp->table_element);
  274. $outputShowOutputFields.= '</div>';
  275. }
  276. $outputShowOutputFields.= '<script>
  277. jQuery(function($) {
  278. $("#extrafield-key-to-update").on(\'change\',function(){
  279. let selectedExtrtafield = $(this).val();
  280. if($(".extrafields-inputs .product_extras_"+selectedExtrtafield) != undefined){
  281. $(".mass-action-extrafield").hide();
  282. $(".mass-action-extrafield[data-extrafield=" + selectedExtrtafield + "]").show();
  283. }
  284. });
  285. });
  286. </script>';
  287. $outputShowOutputFields.= '</div>';
  288. $formquestion[] = array(
  289. 'type' => 'other',
  290. 'value' => $outputShowOutputFields
  291. );
  292. print $form->formconfirm($_SERVER["PHP_SELF"], $langs->trans("ConfirmEditExtrafield"), $langs->trans("ConfirmEditExtrafieldQuestion", count($toselect)), "confirm_edit_value_extrafields", $formquestion, 1, 0, 200, 500, 1);
  293. } else {
  294. setEventMessage($langs->trans("noExtrafields"));
  295. }
  296. }
  297. if ($massaction == 'preenable') {
  298. print $form->formconfirm($_SERVER["PHP_SELF"], $langs->trans("ConfirmMassEnabling"), $langs->trans("ConfirmMassEnablingQuestion", count($toselect)), "enable", null, 'yes', 0, 200, 500, 1);
  299. }
  300. if ($massaction == 'predisable') {
  301. print $form->formconfirm($_SERVER["PHP_SELF"], $langs->trans("ConfirmMassDisabling"), $langs->trans("ConfirmMassDisablingQuestion", count($toselect)), "disable", null, '', 0, 200, 500, 1);
  302. }
  303. if ($massaction == 'presetcommercial') {
  304. $formquestion = array();
  305. $userlist = $form->select_dolusers('', '', 0, null, 0, '', '', 0, 0, 0, 'AND u.statut = 1', 0, '', '', 0, 1);
  306. $formquestion[] = array('type' => 'other',
  307. 'name' => 'affectedcommercial',
  308. 'label' => $form->editfieldkey('AllocateCommercial', 'commercial_id', '', $object, 0),
  309. 'value' => $form->multiselectarray('commercial', $userlist, null, 0, 0, 'quatrevingtpercent widthcentpercentminusx', 0, 0, '', '', '', 1));
  310. print $form->formconfirm($_SERVER["PHP_SELF"], $langs->trans("ConfirmAllocateCommercial"), $langs->trans("ConfirmAllocateCommercialQuestion", count($toselect)), "affectcommercial", $formquestion, 1, 0, 200, 500, 1);
  311. }
  312. if ($massaction == 'preapproveleave') {
  313. print $form->formconfirm($_SERVER["PHP_SELF"], $langs->trans("ConfirmMassLeaveApproval"), $langs->trans("ConfirmMassLeaveApprovalQuestion", count($toselect)), "approveleave", null, 'yes', 0, 200, 500, 1);
  314. }
  315. // Allow Pre-Mass-Action hook (eg for confirmation dialog)
  316. $parameters = array(
  317. 'toselect' => isset($toselect) ? $toselect : array(),
  318. 'uploaddir' => isset($uploaddir) ? $uploaddir : null,
  319. 'massaction' => $massaction
  320. );
  321. $reshook = $hookmanager->executeHooks('doPreMassActions', $parameters, $object, $action);
  322. if ($reshook < 0) {
  323. setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
  324. } else {
  325. print $hookmanager->resPrint;
  326. }