myobject_card.php 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604
  1. <?php
  2. /* Copyright (C) 2007-2015 Laurent Destailleur <eldy@users.sourceforge.net>
  3. * Copyright (C) ---Put here your own copyright and developer email---
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation; either version 3 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18. /**
  19. * \file htdocs/modulebuilder/template/myobject_card.php
  20. * \ingroup mymodule othermodule1 othermodule2
  21. * \brief This file is an example of a php page
  22. * Put here some comments
  23. */
  24. //if (! defined('NOREQUIREUSER')) define('NOREQUIREUSER','1');
  25. //if (! defined('NOREQUIREDB')) define('NOREQUIREDB','1');
  26. //if (! defined('NOREQUIRESOC')) define('NOREQUIRESOC','1');
  27. //if (! defined('NOREQUIRETRAN')) define('NOREQUIRETRAN','1');
  28. //if (! defined('NOCSRFCHECK')) define('NOCSRFCHECK','1'); // Do not check anti CSRF attack test
  29. //if (! defined('NOSTYLECHECK')) define('NOSTYLECHECK','1'); // Do not check style html tag into posted data
  30. //if (! defined('NOTOKENRENEWAL')) define('NOTOKENRENEWAL','1'); // Do not check anti POST attack test
  31. //if (! defined('NOREQUIREMENU')) define('NOREQUIREMENU','1'); // If there is no need to load and show top and left menu
  32. //if (! defined('NOREQUIREHTML')) define('NOREQUIREHTML','1'); // If we don't need to load the html.form.class.php
  33. //if (! defined('NOREQUIREAJAX')) define('NOREQUIREAJAX','1');
  34. //if (! defined("NOLOGIN")) define("NOLOGIN",'1'); // If this page is public (can be called outside logged session)
  35. // Change this following line to use the correct relative path (../, ../../, etc)
  36. $res=0;
  37. if (! $res && file_exists("../main.inc.php")) $res=@include '../main.inc.php'; // to work if your module directory is into dolibarr root htdocs directory
  38. if (! $res && file_exists("../../main.inc.php")) $res=@include '../../main.inc.php'; // to work if your module directory is into a subdir of root htdocs directory
  39. if (! $res && file_exists("../../../dolibarr/htdocs/main.inc.php")) $res=@include '../../../dolibarr/htdocs/main.inc.php'; // Used on dev env only
  40. if (! $res && file_exists("../../../../dolibarr/htdocs/main.inc.php")) $res=@include '../../../../dolibarr/htdocs/main.inc.php'; // Used on dev env only
  41. if (! $res) die("Include of main fails");
  42. // Change this following line to use the correct relative path from htdocs
  43. include_once(DOL_DOCUMENT_ROOT.'/core/class/html.formcompany.class.php');
  44. dol_include_once('/mymodule/class/myobject_class.class.php');
  45. // Load traductions files requiredby by page
  46. $langs->load("mymodule");
  47. $langs->load("other");
  48. // Get parameters
  49. $id = GETPOST('id','int');
  50. $action = GETPOST('action','alpha');
  51. $cancel = GETPOST('cancel');
  52. $backtopage = GETPOST('backtopage');
  53. $myparam = GETPOST('myparam','alpha');
  54. $search_field1=GETPOST("search_field1");
  55. $search_field2=GETPOST("search_field2");
  56. if (empty($action) && empty($id) && empty($ref)) $action='view';
  57. // Protection if external user
  58. if ($user->societe_id > 0)
  59. {
  60. //accessforbidden();
  61. }
  62. //$result = restrictedArea($user, 'mymodule', $id);
  63. $object = new MyObject_Class($db);
  64. $extrafields = new ExtraFields($db);
  65. // fetch optionals attributes and labels
  66. $extralabels = $extrafields->fetch_name_optionals_label($object->table_element);
  67. // Load object
  68. include DOL_DOCUMENT_ROOT.'/core/actions_fetchobject.inc.php'; // Must be include, not include_once // Must be include, not include_once. Include fetch and fetch_thirdparty but not fetch_optionals
  69. // Initialize technical object to manage hooks of modules. Note that conf->hooks_modules contains array array
  70. $hookmanager->initHooks(array('mymodule'));
  71. /*
  72. * ACTIONS
  73. *
  74. * Put here all code to do according to value of "action" parameter
  75. */
  76. $parameters=array();
  77. $reshook=$hookmanager->executeHooks('doActions',$parameters,$object,$action); // Note that $action and $object may have been modified by some hooks
  78. if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
  79. if (empty($reshook))
  80. {
  81. if ($cancel)
  82. {
  83. if ($action != 'addlink')
  84. {
  85. $urltogo=$backtopage?$backtopage:dol_buildpath('/mymodule/list.php',1);
  86. header("Location: ".$urltogo);
  87. exit;
  88. }
  89. if ($id > 0 || ! empty($ref)) $ret = $object->fetch($id,$ref);
  90. $action='';
  91. }
  92. // Action to add record
  93. if ($action == 'add' && ! empty($user->rights->mymodule->create))
  94. {
  95. if ($cancel)
  96. {
  97. $urltogo=$backtopage?$backtopage:dol_buildpath('/mymodule/list.php',1);
  98. header("Location: ".$urltogo);
  99. exit;
  100. }
  101. $error=0;
  102. /* object_prop_getpost_prop */
  103. $object->prop1=GETPOST("field1");
  104. $object->prop2=GETPOST("field2");
  105. if (empty($object->ref))
  106. {
  107. $error++;
  108. setEventMessages($langs->trans("ErrorFieldRequired",$langs->transnoentitiesnoconv("Ref")), null, 'errors');
  109. }
  110. if (! $error)
  111. {
  112. $result=$object->create($user);
  113. if ($result > 0)
  114. {
  115. // Creation OK
  116. $urltogo=$backtopage?$backtopage:dol_buildpath('/mymodule/list.php',1);
  117. header("Location: ".$urltogo);
  118. exit;
  119. }
  120. {
  121. // Creation KO
  122. if (! empty($object->errors)) setEventMessages(null, $object->errors, 'errors');
  123. else setEventMessages($object->error, null, 'errors');
  124. $action='create';
  125. }
  126. }
  127. else
  128. {
  129. $action='create';
  130. }
  131. }
  132. // Action to update record
  133. if ($action == 'update' && ! empty($user->rights->mymodule->create))
  134. {
  135. $error=0;
  136. $object->prop1=GETPOST("field1");
  137. $object->prop2=GETPOST("field2");
  138. if (empty($object->ref))
  139. {
  140. $error++;
  141. setEventMessages($langs->transnoentitiesnoconv("ErrorFieldRequired",$langs->transnoentitiesnoconv("Ref")), null, 'errors');
  142. }
  143. if (! $error)
  144. {
  145. $result=$object->update($user);
  146. if ($result > 0)
  147. {
  148. $action='view';
  149. }
  150. else
  151. {
  152. // Creation KO
  153. if (! empty($object->errors)) setEventMessages(null, $object->errors, 'errors');
  154. else setEventMessages($object->error, null, 'errors');
  155. $action='edit';
  156. }
  157. }
  158. else
  159. {
  160. $action='edit';
  161. }
  162. }
  163. // Action to delete
  164. if ($action == 'confirm_delete' && ! empty($user->rights->mymodule->delete))
  165. {
  166. $result=$object->delete($user);
  167. if ($result > 0)
  168. {
  169. // Delete OK
  170. setEventMessages("RecordDeleted", null, 'mesgs');
  171. header("Location: ".dol_buildpath('/mymodule/list.php',1));
  172. exit;
  173. }
  174. else
  175. {
  176. if (! empty($object->errors)) setEventMessages(null, $object->errors, 'errors');
  177. else setEventMessages($object->error, null, 'errors');
  178. }
  179. }
  180. }
  181. /*
  182. * VIEW
  183. *
  184. * Put here all code to build page
  185. */
  186. $form=new Form($db);
  187. llxHeader('','MyPageName','');
  188. // Put here content of your page
  189. // Example : Adding jquery code
  190. print '<script type="text/javascript" language="javascript">
  191. jQuery(document).ready(function() {
  192. function init_myfunc()
  193. {
  194. jQuery("#myid").removeAttr(\'disabled\');
  195. jQuery("#myid").attr(\'disabled\',\'disabled\');
  196. }
  197. init_myfunc();
  198. jQuery("#mybutton").click(function() {
  199. init_myfunc();
  200. });
  201. });
  202. </script>';
  203. // Part to create
  204. if ($action == 'create')
  205. {
  206. print load_fiche_titre($langs->trans("NewMyModule"));
  207. print '<form method="POST" action="'.$_SERVER["PHP_SELF"].'">';
  208. print '<input type="hidden" name="action" value="add">';
  209. print '<input type="hidden" name="backtopage" value="'.$backtopage.'">';
  210. dol_fiche_head();
  211. print '<table class="border centpercent">'."\n";
  212. // print '<tr><td class="fieldrequired">'.$langs->trans("Label").'</td><td><input class="flat" type="text" size="36" name="label" value="'.$label.'"></td></tr>';
  213. // LIST_OF_TD_LABEL_FIELDS_CREATE
  214. print '</table>'."\n";
  215. dol_fiche_end();
  216. print '<div class="center"><input type="submit" class="button" name="add" value="'.$langs->trans("Create").'"> &nbsp; <input type="submit" class="button" name="cancel" value="'.$langs->trans("Cancel").'"></div>';
  217. print '</form>';
  218. }
  219. // Part to edit record
  220. if (($id || $ref) && $action == 'edit')
  221. {
  222. print load_fiche_titre($langs->trans("MyModule"));
  223. print '<form method="POST" action="'.$_SERVER["PHP_SELF"].'">';
  224. print '<input type="hidden" name="action" value="update">';
  225. print '<input type="hidden" name="backtopage" value="'.$backtopage.'">';
  226. print '<input type="hidden" name="id" value="'.$object->id.'">';
  227. dol_fiche_head();
  228. print '<table class="border centpercent">'."\n";
  229. // print '<tr><td class="fieldrequired">'.$langs->trans("Label").'</td><td><input class="flat" type="text" size="36" name="label" value="'.$label.'"></td></tr>';
  230. // LIST_OF_TD_LABEL_FIELDS_EDIT
  231. print '</table>';
  232. dol_fiche_end();
  233. print '<div class="center"><input type="submit" class="button" name="save" value="'.$langs->trans("Save").'">';
  234. print ' &nbsp; <input type="submit" class="button" name="cancel" value="'.$langs->trans("Cancel").'">';
  235. print '</div>';
  236. print '</form>';
  237. }
  238. // Part to show record
  239. if ($object->id > 0 && (empty($action) || ($action != 'edit' && $action != 'create')))
  240. {
  241. $res = $object->fetch_optionals($object->id, $extralabels);
  242. $head = mymodule_prepare_head($object);
  243. dol_fiche_head($head, 'order', $langs->trans("CustomerOrder"), -1, 'order');
  244. $formconfirm = '';
  245. // Confirmation to delete
  246. if ($action == 'delete') {
  247. $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"] . '?id=' . $object->id, $langs->trans('DeleteOrder'), $langs->trans('ConfirmDeleteOrder'), 'confirm_delete', '', 0, 1);
  248. }
  249. // Confirmation of action xxxx
  250. if ($action == 'xxx')
  251. {
  252. $formquestion=array();
  253. /*
  254. $formquestion = array(
  255. // 'text' => $langs->trans("ConfirmClone"),
  256. // array('type' => 'checkbox', 'name' => 'clone_content', 'label' => $langs->trans("CloneMainAttributes"), 'value' => 1),
  257. // array('type' => 'checkbox', 'name' => 'update_prices', 'label' => $langs->trans("PuttingPricesUpToDate"), 'value' => 1),
  258. // array('type' => 'other', 'name' => 'idwarehouse', 'label' => $langs->trans("SelectWarehouseForStockDecrease"), 'value' => $formproduct->selectWarehouses(GETPOST('idwarehouse')?GETPOST('idwarehouse'):'ifone', 'idwarehouse', '', 1)));
  259. }*/
  260. $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"] . '?id=' . $object->id, $langs->trans('XXX'), $text, 'confirm_xxx', $formquestion, 0, 1, 220);
  261. }
  262. if (! $formconfirm) {
  263. $parameters = array('lineid' => $lineid);
  264. $reshook = $hookmanager->executeHooks('formConfirm', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
  265. if (empty($reshook)) $formconfirm.=$hookmanager->resPrint;
  266. elseif ($reshook > 0) $formconfirm=$hookmanager->resPrint;
  267. }
  268. // Print form confirm
  269. print $formconfirm;
  270. // Object card
  271. // ------------------------------------------------------------
  272. $linkback = '<a href="' . DOL_URL_ROOT . '/mymodule/list.php' . (! empty($socid) ? '?socid=' . $socid : '') . '">' . $langs->trans("BackToList") . '</a>';
  273. $morehtmlref='<div class="refidno">';
  274. /*
  275. // Ref bis
  276. $morehtmlref.=$form->editfieldkey("RefBis", 'ref_client', $object->ref_client, $object, $user->rights->mymodule->creer, 'string', '', 0, 1);
  277. $morehtmlref.=$form->editfieldval("RefBis", 'ref_client', $object->ref_client, $object, $user->rights->mymodule->creer, 'string', '', null, null, '', 1);
  278. // Thirdparty
  279. $morehtmlref.='<br>'.$langs->trans('ThirdParty') . ' : ' . $soc->getNomUrl(1);
  280. // Project
  281. if (! empty($conf->projet->enabled))
  282. {
  283. $langs->load("projects");
  284. $morehtmlref.='<br>'.$langs->trans('Project') . ' ';
  285. if ($user->rights->mymodule->creer)
  286. {
  287. if ($action != 'classify')
  288. {
  289. $morehtmlref.='<a href="' . $_SERVER['PHP_SELF'] . '?action=classify&amp;id=' . $object->id . '">' . img_edit($langs->transnoentitiesnoconv('SetProject')) . '</a> : ';
  290. if ($action == 'classify') {
  291. //$morehtmlref.=$form->form_project($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->socid, $object->fk_project, 'projectid', 0, 0, 1, 1);
  292. $morehtmlref.='<form method="post" action="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'">';
  293. $morehtmlref.='<input type="hidden" name="action" value="classin">';
  294. $morehtmlref.='<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
  295. $morehtmlref.=$formproject->select_projects($object->socid, $object->fk_project, 'projectid', $maxlength, 0, 1, 0, 1, 0, 0, '', 1);
  296. $morehtmlref.='<input type="submit" class="button valignmiddle" value="'.$langs->trans("Modify").'">';
  297. $morehtmlref.='</form>';
  298. } else {
  299. $morehtmlref.=$form->form_project($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->socid, $object->fk_project, 'none', 0, 0, 0, 1);
  300. }
  301. }
  302. } else {
  303. if (! empty($object->fk_project)) {
  304. $proj = new Project($db);
  305. $proj->fetch($object->fk_project);
  306. $morehtmlref.='<a href="'.DOL_URL_ROOT.'/projet/card.php?id=' . $object->fk_project . '" title="' . $langs->trans('ShowProject') . '">';
  307. $morehtmlref.=$proj->ref;
  308. $morehtmlref.='</a>';
  309. } else {
  310. $morehtmlref.='';
  311. }
  312. }
  313. }
  314. */
  315. $morehtmlref.='</div>';
  316. dol_banner_tab($object, 'ref', $linkback, 1, 'ref', 'ref', $morehtmlref);
  317. print '<div class="fichecenter">';
  318. print '<div class="fichehalfleft">';
  319. print '<div class="underbanner clearboth"></div>';
  320. print '<table class="border centpercent">'."\n";
  321. // print '<tr><td class="fieldrequired">'.$langs->trans("Label").'</td><td>'.$object->label.'</td></tr>';
  322. // LIST_OF_TD_LABEL_FIELDS_VIEW
  323. // Other attributes
  324. $cols = 2;
  325. include DOL_DOCUMENT_ROOT . '/core/tpl/extrafields_view.tpl.php';
  326. print '</table>';
  327. print '</div>';
  328. print '<div class="fichehalfright">';
  329. print '<div class="ficheaddleft">';
  330. print '<div class="underbanner clearboth"></div>';
  331. print '<table class="border centpercent">';
  332. print '</table>';
  333. print '</div>';
  334. print '</div>';
  335. print '</div>';
  336. print '<div class="clearboth"></div><br>';
  337. dol_fiche_end();
  338. // Buttons for actions
  339. if ($action != 'presend' && $action != 'editline') {
  340. print '<div class="tabsAction">'."\n";
  341. $parameters=array();
  342. $reshook=$hookmanager->executeHooks('addMoreActionsButtons',$parameters,$object,$action); // Note that $action and $object may have been modified by hook
  343. if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
  344. if (empty($reshook))
  345. {
  346. if ($user->rights->mymodule->write)
  347. {
  348. print '<div class="inline-block divButAction"><a class="butAction" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&amp;action=edit">'.$langs->trans("Modify").'</a></div>'."\n";
  349. }
  350. if ($user->rights->mymodule->delete)
  351. {
  352. print '<div class="inline-block divButAction"><a class="butActionDelete" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&amp;action=delete">'.$langs->trans('Delete').'</a></div>'."\n";
  353. }
  354. }
  355. print '</div>'."\n";
  356. }
  357. // Select mail models is same action as presend
  358. if (GETPOST('modelselected')) {
  359. $action = 'presend';
  360. }
  361. if ($action != 'presend')
  362. {
  363. print '<div class="fichecenter"><div class="fichehalfleft">';
  364. print '<a name="builddoc"></a>'; // ancre
  365. // Documents
  366. $comref = dol_sanitizeFileName($object->ref);
  367. $relativepath = $comref . '/' . $comref . '.pdf';
  368. $filedir = $conf->mymodule->dir_output . '/' . $comref;
  369. $urlsource = $_SERVER["PHP_SELF"] . "?id=" . $object->id;
  370. $genallowed = $user->rights->mymodule->creer;
  371. $delallowed = $user->rights->mymodule->supprimer;
  372. print $formfile->showdocuments('mymodule', $comref, $filedir, $urlsource, $genallowed, $delallowed, $object->modelpdf, 1, 0, 0, 28, 0, '', '', '', $soc->default_lang);
  373. // Show links to link elements
  374. $linktoelem = $form->showLinkToObjectBlock($object, null, array('order'));
  375. $somethingshown = $form->showLinkedObjectBlock($object, $linktoelem);
  376. print '</div><div class="fichehalfright"><div class="ficheaddleft">';
  377. // List of actions on element
  378. include_once DOL_DOCUMENT_ROOT . '/core/class/html.formactions.class.php';
  379. $formactions = new FormActions($db);
  380. $somethingshown = $formactions->showactions($object, 'order', $socid);
  381. print '</div></div></div>';
  382. }
  383. /*
  384. * Action presend
  385. */
  386. /*
  387. if ($action == 'presend')
  388. {
  389. $object->fetch_projet();
  390. $ref = dol_sanitizeFileName($object->ref);
  391. include_once DOL_DOCUMENT_ROOT . '/core/lib/files.lib.php';
  392. $fileparams = dol_most_recent_file($conf->commande->dir_output . '/' . $ref, preg_quote($ref, '/').'[^\-]+');
  393. $file = $fileparams['fullname'];
  394. // Define output language
  395. $outputlangs = $langs;
  396. $newlang = '';
  397. if ($conf->global->MAIN_MULTILANGS && empty($newlang) && ! empty($_REQUEST['lang_id']))
  398. $newlang = $_REQUEST['lang_id'];
  399. if ($conf->global->MAIN_MULTILANGS && empty($newlang))
  400. $newlang = $object->thirdparty->default_lang;
  401. if (!empty($newlang))
  402. {
  403. $outputlangs = new Translate('', $conf);
  404. $outputlangs->setDefaultLang($newlang);
  405. $outputlangs->load('commercial');
  406. }
  407. // Build document if it not exists
  408. if (! $file || ! is_readable($file)) {
  409. $result = $object->generateDocument(GETPOST('model') ? GETPOST('model') : $object->modelpdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
  410. if ($result <= 0) {
  411. dol_print_error($db, $object->error, $object->errors);
  412. exit();
  413. }
  414. $fileparams = dol_most_recent_file($conf->commande->dir_output . '/' . $ref, preg_quote($ref, '/').'[^\-]+');
  415. $file = $fileparams['fullname'];
  416. }
  417. print '<div id="formmailbeforetitle" name="formmailbeforetitle"></div>';
  418. print '<div class="clearboth"></div>';
  419. print '<br>';
  420. print load_fiche_titre($langs->trans('SendOrderByMail'));
  421. dol_fiche_head('');
  422. // Cree l'objet formulaire mail
  423. include_once DOL_DOCUMENT_ROOT . '/core/class/html.formmail.class.php';
  424. $formmail = new FormMail($db);
  425. $formmail->param['langsmodels']=(empty($newlang)?$langs->defaultlang:$newlang);
  426. $formmail->fromtype = (GETPOST('fromtype')?GETPOST('fromtype'):(!empty($conf->global->MAIN_MAIL_DEFAULT_FROMTYPE)?$conf->global->MAIN_MAIL_DEFAULT_FROMTYPE:'user'));
  427. if($formmail->fromtype === 'user'){
  428. $formmail->fromid = $user->id;
  429. }
  430. $formmail->trackid='ord'.$object->id;
  431. if (! empty($conf->global->MAIN_EMAIL_ADD_TRACK_ID) && ($conf->global->MAIN_EMAIL_ADD_TRACK_ID & 2)) // If bit 2 is set
  432. {
  433. include DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
  434. $formmail->frommail=dolAddEmailTrackId($formmail->frommail, 'ord'.$object->id);
  435. }
  436. $formmail->withfrom = 1;
  437. $liste = array();
  438. foreach ($object->thirdparty->thirdparty_and_contact_email_array(1) as $key => $value)
  439. $liste [$key] = $value;
  440. $formmail->withto = GETPOST('sendto') ? GETPOST('sendto') : $liste;
  441. $formmail->withtocc = $liste;
  442. $formmail->withtoccc = $conf->global->MAIN_EMAIL_USECCC;
  443. if (empty($object->ref_client)) {
  444. $formmail->withtopic = $outputlangs->trans('SendOrderRef', '__ORDERREF__');
  445. } else if (! empty($object->ref_client)) {
  446. $formmail->withtopic = $outputlangs->trans('SendOrderRef', '__ORDERREF__ (__REFCLIENT__)');
  447. }
  448. $formmail->withfile = 2;
  449. $formmail->withbody = 1;
  450. $formmail->withdeliveryreceipt = 1;
  451. $formmail->withcancel = 1;
  452. // Tableau des substitutions
  453. $formmail->setSubstitFromObject($object);
  454. $formmail->substit ['__ORDERREF__'] = $object->ref;
  455. $custcontact = '';
  456. $contactarr = array();
  457. $contactarr = $object->liste_contact(- 1, 'external');
  458. if (is_array($contactarr) && count($contactarr) > 0)
  459. {
  460. foreach ($contactarr as $contact)
  461. {
  462. if ($contact['libelle'] == $langs->trans('TypeContact_commande_external_CUSTOMER')) { // TODO Use code and not label
  463. $contactstatic = new Contact($db);
  464. $contactstatic->fetch($contact ['id']);
  465. $custcontact = $contactstatic->getFullName($langs, 1);
  466. }
  467. }
  468. if (! empty($custcontact)) {
  469. $formmail->substit['__CONTACTCIVNAME__'] = $custcontact;
  470. }
  471. }
  472. // Tableau des parametres complementaires
  473. $formmail->param['action'] = 'send';
  474. $formmail->param['models'] = 'order_send';
  475. $formmail->param['models_id']=GETPOST('modelmailselected','int');
  476. $formmail->param['orderid'] = $object->id;
  477. $formmail->param['returnurl'] = $_SERVER["PHP_SELF"] . '?id=' . $object->id;
  478. // Init list of files
  479. if (GETPOST("mode") == 'init') {
  480. $formmail->clear_attached_files();
  481. $formmail->add_attached_files($file, basename($file), dol_mimetype($file));
  482. }
  483. // Show form
  484. print $formmail->get_form();
  485. dol_fiche_end();
  486. }*/
  487. }
  488. // End of page
  489. llxFooter();
  490. $db->close();