myobject_card.php 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604
  1. <?php
  2. /* Copyright (C) 2017 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 <https://www.gnu.org/licenses/>.
  17. */
  18. /**
  19. * \file htdocs/modulebuilder/template/myobject_card.php
  20. * \ingroup mymodule
  21. * \brief Page to create/edit/view myobject
  22. */
  23. //if (! defined('NOREQUIREDB')) define('NOREQUIREDB','1'); // Do not create database handler $db
  24. //if (! defined('NOREQUIREUSER')) define('NOREQUIREUSER','1'); // Do not load object $user
  25. //if (! defined('NOREQUIRESOC')) define('NOREQUIRESOC','1'); // Do not load object $mysoc
  26. //if (! defined('NOREQUIRETRAN')) define('NOREQUIRETRAN','1'); // Do not load object $langs
  27. //if (! defined('NOSCANGETFORINJECTION')) define('NOSCANGETFORINJECTION','1'); // Do not check injection attack on GET parameters
  28. //if (! defined('NOSCANPOSTFORINJECTION')) define('NOSCANPOSTFORINJECTION','1'); // Do not check injection attack on POST parameters
  29. //if (! defined('NOCSRFCHECK')) define('NOCSRFCHECK','1'); // Do not check CSRF attack (test on referer + on token if option MAIN_SECURITY_CSRF_WITH_TOKEN is on).
  30. //if (! defined('NOTOKENRENEWAL')) define('NOTOKENRENEWAL','1'); // Do not roll the Anti CSRF token (used if MAIN_SECURITY_CSRF_WITH_TOKEN is on)
  31. //if (! defined('NOSTYLECHECK')) define('NOSTYLECHECK','1'); // Do not check style html tag into posted data
  32. //if (! defined('NOREQUIREMENU')) define('NOREQUIREMENU','1'); // If there is no need to load and show top and left menu
  33. //if (! defined('NOREQUIREHTML')) define('NOREQUIREHTML','1'); // If we don't need to load the html.form.class.php
  34. //if (! defined('NOREQUIREAJAX')) define('NOREQUIREAJAX','1'); // Do not load ajax.lib.php library
  35. //if (! defined("NOLOGIN")) define("NOLOGIN",'1'); // If this page is public (can be called outside logged session). This include the NOIPCHECK too.
  36. //if (! defined('NOIPCHECK')) define('NOIPCHECK','1'); // Do not check IP defined into conf $dolibarr_main_restrict_ip
  37. //if (! defined("MAIN_LANG_DEFAULT")) define('MAIN_LANG_DEFAULT','auto'); // Force lang to a particular value
  38. //if (! defined("MAIN_AUTHENTICATION_MODE")) define('MAIN_AUTHENTICATION_MODE','aloginmodule'); // Force authentication handler
  39. //if (! defined("NOREDIRECTBYMAINTOLOGIN")) define('NOREDIRECTBYMAINTOLOGIN',1); // The main.inc.php does not make a redirect if not logged, instead show simple error message
  40. //if (! defined("FORCECSP")) define('FORCECSP','none'); // Disable all Content Security Policies
  41. // Load Dolibarr environment
  42. $res = 0;
  43. // Try main.inc.php into web root known defined into CONTEXT_DOCUMENT_ROOT (not always defined)
  44. if (!$res && !empty($_SERVER["CONTEXT_DOCUMENT_ROOT"])) $res = @include $_SERVER["CONTEXT_DOCUMENT_ROOT"]."/main.inc.php";
  45. // Try main.inc.php into web root detected using web root calculated from SCRIPT_FILENAME
  46. $tmp = empty($_SERVER['SCRIPT_FILENAME']) ? '' : $_SERVER['SCRIPT_FILENAME']; $tmp2 = realpath(__FILE__); $i = strlen($tmp) - 1; $j = strlen($tmp2) - 1;
  47. while ($i > 0 && $j > 0 && isset($tmp[$i]) && isset($tmp2[$j]) && $tmp[$i] == $tmp2[$j]) { $i--; $j--; }
  48. if (!$res && $i > 0 && file_exists(substr($tmp, 0, ($i + 1))."/main.inc.php")) $res = @include substr($tmp, 0, ($i + 1))."/main.inc.php";
  49. if (!$res && $i > 0 && file_exists(dirname(substr($tmp, 0, ($i + 1)))."/main.inc.php")) $res = @include dirname(substr($tmp, 0, ($i + 1)))."/main.inc.php";
  50. // Try main.inc.php using relative path
  51. if (!$res && file_exists("../main.inc.php")) $res = @include "../main.inc.php";
  52. if (!$res && file_exists("../../main.inc.php")) $res = @include "../../main.inc.php";
  53. if (!$res && file_exists("../../../main.inc.php")) $res = @include "../../../main.inc.php";
  54. if (!$res) die("Include of main fails");
  55. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formcompany.class.php';
  56. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
  57. dol_include_once('/mymodule/class/myobject.class.php');
  58. dol_include_once('/mymodule/lib/mymodule_myobject.lib.php');
  59. // Load translation files required by the page
  60. $langs->loadLangs(array("mymodule@mymodule", "other"));
  61. // Get parameters
  62. $id = GETPOST('id', 'int');
  63. $ref = GETPOST('ref', 'alpha');
  64. $action = GETPOST('action', 'aZ09');
  65. $confirm = GETPOST('confirm', 'alpha');
  66. $cancel = GETPOST('cancel', 'aZ09');
  67. $contextpage = GETPOST('contextpage', 'aZ') ?GETPOST('contextpage', 'aZ') : 'myobjectcard'; // To manage different context of search
  68. $backtopage = GETPOST('backtopage', 'alpha');
  69. $backtopageforcancel = GETPOST('backtopageforcancel', 'alpha');
  70. //$lineid = GETPOST('lineid', 'int');
  71. // Initialize technical objects
  72. $object = new MyObject($db);
  73. $extrafields = new ExtraFields($db);
  74. $diroutputmassaction = $conf->mymodule->dir_output.'/temp/massgeneration/'.$user->id;
  75. $hookmanager->initHooks(array('myobjectcard', 'globalcard')); // Note that conf->hooks_modules contains array
  76. // Fetch optionals attributes and labels
  77. $extrafields->fetch_name_optionals_label($object->table_element);
  78. $search_array_options = $extrafields->getOptionalsFromPost($object->table_element, '', 'search_');
  79. // Initialize array of search criterias
  80. $search_all = trim(GETPOST("search_all", 'alpha'));
  81. $search = array();
  82. foreach ($object->fields as $key => $val)
  83. {
  84. if (GETPOST('search_'.$key, 'alpha')) $search[$key] = GETPOST('search_'.$key, 'alpha');
  85. }
  86. if (empty($action) && empty($id) && empty($ref)) $action = 'view';
  87. // Load object
  88. include DOL_DOCUMENT_ROOT.'/core/actions_fetchobject.inc.php'; // Must be include, not include_once.
  89. $permissiontoread = $user->rights->mymodule->myobject->read;
  90. $permissiontoadd = $user->rights->mymodule->myobject->write; // Used by the include of actions_addupdatedelete.inc.php and actions_lineupdown.inc.php
  91. $permissiontodelete = $user->rights->mymodule->myobject->delete || ($permissiontoadd && isset($object->status) && $object->status == $object::STATUS_DRAFT);
  92. $permissionnote = $user->rights->mymodule->myobject->write; // Used by the include of actions_setnotes.inc.php
  93. $permissiondellink = $user->rights->mymodule->myobject->write; // Used by the include of actions_dellink.inc.php
  94. $upload_dir = $conf->mymodule->multidir_output[isset($object->entity) ? $object->entity : 1];
  95. // Security check - Protection if external user
  96. //if ($user->socid > 0) accessforbidden();
  97. //if ($user->socid > 0) $socid = $user->socid;
  98. //$isdraft = (($object->statut == $object::STATUS_DRAFT) ? 1 : 0);
  99. //$result = restrictedArea($user, 'mymodule', $object->id, '', '', 'fk_soc', 'rowid', $isdraft);
  100. //if (!$permissiontoread) accessforbidden();
  101. /*
  102. * Actions
  103. */
  104. $parameters = array();
  105. $reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
  106. if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
  107. if (empty($reshook))
  108. {
  109. $error = 0;
  110. $backurlforlist = dol_buildpath('/mymodule/myobject_list.php', 1);
  111. if (empty($backtopage) || ($cancel && empty($id))) {
  112. if (empty($backtopage) || ($cancel && strpos($backtopage, '__ID__'))) {
  113. if (empty($id) && (($action != 'add' && $action != 'create') || $cancel)) $backtopage = $backurlforlist;
  114. else $backtopage = dol_buildpath('/mymodule/myobject_card.php', 1).'?id='.($id > 0 ? $id : '__ID__');
  115. }
  116. }
  117. $triggermodname = 'MYMODULE_MYOBJECT_MODIFY'; // Name of trigger action code to execute when we modify record
  118. // Actions cancel, add, update, update_extras, confirm_validate, confirm_delete, confirm_deleteline, confirm_clone, confirm_close, confirm_setdraft, confirm_reopen
  119. include DOL_DOCUMENT_ROOT.'/core/actions_addupdatedelete.inc.php';
  120. // Actions when linking object each other
  121. include DOL_DOCUMENT_ROOT.'/core/actions_dellink.inc.php';
  122. // Actions when printing a doc from card
  123. include DOL_DOCUMENT_ROOT.'/core/actions_printing.inc.php';
  124. // Action to move up and down lines of object
  125. //include DOL_DOCUMENT_ROOT.'/core/actions_lineupdown.inc.php';
  126. // Action to build doc
  127. include DOL_DOCUMENT_ROOT.'/core/actions_builddoc.inc.php';
  128. if ($action == 'set_thirdparty' && $permissiontoadd)
  129. {
  130. $object->setValueFrom('fk_soc', GETPOST('fk_soc', 'int'), '', '', 'date', '', $user, 'MYOBJECT_MODIFY');
  131. }
  132. if ($action == 'classin' && $permissiontoadd)
  133. {
  134. $object->setProject(GETPOST('projectid', 'int'));
  135. }
  136. // Actions to send emails
  137. $triggersendname = 'MYOBJECT_SENTBYMAIL';
  138. $autocopy = 'MAIN_MAIL_AUTOCOPY_MYOBJECT_TO';
  139. $trackid = 'myobject'.$object->id;
  140. include DOL_DOCUMENT_ROOT.'/core/actions_sendmails.inc.php';
  141. }
  142. /*
  143. * View
  144. *
  145. * Put here all code to build page
  146. */
  147. $form = new Form($db);
  148. $formfile = new FormFile($db);
  149. $title = $langs->trans("MyObject");
  150. $help_url = '';
  151. llxHeader('', $title, $help_url);
  152. // Example : Adding jquery code
  153. print '<script type="text/javascript" language="javascript">
  154. jQuery(document).ready(function() {
  155. function init_myfunc()
  156. {
  157. jQuery("#myid").removeAttr(\'disabled\');
  158. jQuery("#myid").attr(\'disabled\',\'disabled\');
  159. }
  160. init_myfunc();
  161. jQuery("#mybutton").click(function() {
  162. init_myfunc();
  163. });
  164. });
  165. </script>';
  166. // Part to create
  167. if ($action == 'create')
  168. {
  169. print load_fiche_titre($langs->trans("NewObject", $langs->transnoentitiesnoconv("MyObject")));
  170. print '<form method="POST" action="'.$_SERVER["PHP_SELF"].'">';
  171. print '<input type="hidden" name="token" value="'.newToken().'">';
  172. print '<input type="hidden" name="action" value="add">';
  173. if ($backtopage) print '<input type="hidden" name="backtopage" value="'.$backtopage.'">';
  174. if ($backtopageforcancel) print '<input type="hidden" name="backtopageforcancel" value="'.$backtopageforcancel.'">';
  175. dol_fiche_head(array(), '');
  176. print '<table class="border centpercent tableforfieldcreate">'."\n";
  177. // Common attributes
  178. include DOL_DOCUMENT_ROOT.'/core/tpl/commonfields_add.tpl.php';
  179. // Other attributes
  180. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_add.tpl.php';
  181. print '</table>'."\n";
  182. dol_fiche_end();
  183. print '<div class="center">';
  184. print '<input type="submit" class="button" name="add" value="'.dol_escape_htmltag($langs->trans("Create")).'">';
  185. print '&nbsp; ';
  186. print '<input type="'.($backtopage ? "submit" : "button").'" class="button" name="cancel" value="'.dol_escape_htmltag($langs->trans("Cancel")).'"'.($backtopage ? '' : ' onclick="javascript:history.go(-1)"').'>'; // Cancel for create does not post form if we don't know the backtopage
  187. print '</div>';
  188. print '</form>';
  189. //dol_set_focus('input[name="ref"]');
  190. }
  191. // Part to edit record
  192. if (($id || $ref) && $action == 'edit')
  193. {
  194. print load_fiche_titre($langs->trans("MyObject"));
  195. print '<form method="POST" action="'.$_SERVER["PHP_SELF"].'">';
  196. print '<input type="hidden" name="token" value="'.newToken().'">';
  197. print '<input type="hidden" name="action" value="update">';
  198. print '<input type="hidden" name="id" value="'.$object->id.'">';
  199. if ($backtopage) print '<input type="hidden" name="backtopage" value="'.$backtopage.'">';
  200. if ($backtopageforcancel) print '<input type="hidden" name="backtopageforcancel" value="'.$backtopageforcancel.'">';
  201. dol_fiche_head();
  202. print '<table class="border centpercent tableforfieldedit">'."\n";
  203. // Common attributes
  204. include DOL_DOCUMENT_ROOT.'/core/tpl/commonfields_edit.tpl.php';
  205. // Other attributes
  206. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_edit.tpl.php';
  207. print '</table>';
  208. dol_fiche_end();
  209. print '<div class="center"><input type="submit" class="button" name="save" value="'.$langs->trans("Save").'">';
  210. print ' &nbsp; <input type="submit" class="button" name="cancel" value="'.$langs->trans("Cancel").'">';
  211. print '</div>';
  212. print '</form>';
  213. }
  214. // Part to show record
  215. if ($object->id > 0 && (empty($action) || ($action != 'edit' && $action != 'create')))
  216. {
  217. $res = $object->fetch_optionals();
  218. $head = myobjectPrepareHead($object);
  219. dol_fiche_head($head, 'card', $langs->trans("MyObject"), -1, $object->picto);
  220. $formconfirm = '';
  221. // Confirmation to delete
  222. if ($action == 'delete')
  223. {
  224. $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('DeleteMyObject'), $langs->trans('ConfirmDeleteObject'), 'confirm_delete', '', 0, 1);
  225. }
  226. // Confirmation to delete line
  227. if ($action == 'deleteline')
  228. {
  229. $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id.'&lineid='.$lineid, $langs->trans('DeleteLine'), $langs->trans('ConfirmDeleteLine'), 'confirm_deleteline', '', 0, 1);
  230. }
  231. // Clone confirmation
  232. if ($action == 'clone') {
  233. // Create an array for form
  234. $formquestion = array();
  235. $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('ToClone'), $langs->trans('ConfirmCloneAsk', $object->ref), 'confirm_clone', $formquestion, 'yes', 1);
  236. }
  237. // Confirmation of action xxxx
  238. if ($action == 'xxx')
  239. {
  240. $formquestion = array();
  241. /*
  242. $forcecombo=0;
  243. if ($conf->browser->name == 'ie') $forcecombo = 1; // There is a bug in IE10 that make combo inside popup crazy
  244. $formquestion = array(
  245. // 'text' => $langs->trans("ConfirmClone"),
  246. // array('type' => 'checkbox', 'name' => 'clone_content', 'label' => $langs->trans("CloneMainAttributes"), 'value' => 1),
  247. // array('type' => 'checkbox', 'name' => 'update_prices', 'label' => $langs->trans("PuttingPricesUpToDate"), 'value' => 1),
  248. // array('type' => 'other', 'name' => 'idwarehouse', 'label' => $langs->trans("SelectWarehouseForStockDecrease"), 'value' => $formproduct->selectWarehouses(GETPOST('idwarehouse')?GETPOST('idwarehouse'):'ifone', 'idwarehouse', '', 1, 0, 0, '', 0, $forcecombo))
  249. );
  250. */
  251. $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('XXX'), $text, 'confirm_xxx', $formquestion, 0, 1, 220);
  252. }
  253. // Call Hook formConfirm
  254. $parameters = array('formConfirm' => $formconfirm, 'lineid' => $lineid);
  255. $reshook = $hookmanager->executeHooks('formConfirm', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
  256. if (empty($reshook)) $formconfirm .= $hookmanager->resPrint;
  257. elseif ($reshook > 0) $formconfirm = $hookmanager->resPrint;
  258. // Print form confirm
  259. print $formconfirm;
  260. // Object card
  261. // ------------------------------------------------------------
  262. $linkback = '<a href="'.dol_buildpath('/mymodule/myobject_list.php', 1).'?restore_lastsearch_values=1'.(!empty($socid) ? '&socid='.$socid : '').'">'.$langs->trans("BackToList").'</a>';
  263. $morehtmlref = '<div class="refidno">';
  264. /*
  265. // Ref bis
  266. $morehtmlref.=$form->editfieldkey("RefBis", 'ref_client', $object->ref_client, $object, $user->rights->mymodule->myobject->creer, 'string', '', 0, 1);
  267. $morehtmlref.=$form->editfieldval("RefBis", 'ref_client', $object->ref_client, $object, $user->rights->mymodule->myobject->creer, 'string', '', null, null, '', 1);
  268. // Thirdparty
  269. $morehtmlref.='<br>'.$langs->trans('ThirdParty') . ' : ' . (is_object($object->thirdparty) ? $object->thirdparty->getNomUrl(1) : '');
  270. // Project
  271. if (! empty($conf->projet->enabled))
  272. {
  273. $langs->load("projects");
  274. $morehtmlref.='<br>'.$langs->trans('Project') . ' ';
  275. if ($permissiontoadd)
  276. {
  277. if ($action != 'classify')
  278. $morehtmlref.='<a class="editfielda" href="' . $_SERVER['PHP_SELF'] . '?action=classify&amp;id=' . $object->id . '">' . img_edit($langs->transnoentitiesnoconv('SetProject')) . '</a> : ';
  279. if ($action == 'classify') {
  280. //$morehtmlref.=$form->form_project($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->socid, $object->fk_project, 'projectid', 0, 0, 1, 1);
  281. $morehtmlref.='<form method="post" action="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'">';
  282. $morehtmlref.='<input type="hidden" name="action" value="classin">';
  283. $morehtmlref.='<input type="hidden" name="token" value="'.newToken().'">';
  284. $morehtmlref.=$formproject->select_projects($object->socid, $object->fk_project, 'projectid', 0, 0, 1, 0, 1, 0, 0, '', 1);
  285. $morehtmlref.='<input type="submit" class="button valignmiddle" value="'.$langs->trans("Modify").'">';
  286. $morehtmlref.='</form>';
  287. } else {
  288. $morehtmlref.=$form->form_project($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->socid, $object->fk_project, 'none', 0, 0, 0, 1);
  289. }
  290. } else {
  291. if (! empty($object->fk_project)) {
  292. $proj = new Project($db);
  293. $proj->fetch($object->fk_project);
  294. $morehtmlref.=$proj->getNomUrl();
  295. } else {
  296. $morehtmlref.='';
  297. }
  298. }
  299. }
  300. */
  301. $morehtmlref .= '</div>';
  302. dol_banner_tab($object, 'ref', $linkback, 1, 'ref', 'ref', $morehtmlref);
  303. print '<div class="fichecenter">';
  304. print '<div class="fichehalfleft">';
  305. print '<div class="underbanner clearboth"></div>';
  306. print '<table class="border centpercent">'."\n";
  307. // Common attributes
  308. //$keyforbreak='fieldkeytoswitchonsecondcolumn'; // We change column just after this field
  309. //unset($object->fields['fk_project']); // Hide field already shown in banner
  310. //unset($object->fields['fk_soc']); // Hide field already shown in banner
  311. include DOL_DOCUMENT_ROOT.'/core/tpl/commonfields_view.tpl.php';
  312. // Other attributes. Fields from hook formObjectOptions and Extrafields.
  313. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_view.tpl.php';
  314. print '</table>';
  315. print '</div>';
  316. print '</div>';
  317. print '<div class="clearboth"></div>';
  318. dol_fiche_end();
  319. /*
  320. * Lines
  321. */
  322. if (!empty($object->table_element_line))
  323. {
  324. // Show object lines
  325. $result = $object->getLinesArray();
  326. print ' <form name="addproduct" id="addproduct" action="'.$_SERVER["PHP_SELF"].'?id='.$object->id.(($action != 'editline') ? '#addline' : '#line_'.GETPOST('lineid', 'int')).'" method="POST">
  327. <input type="hidden" name="token" value="' . newToken().'">
  328. <input type="hidden" name="action" value="' . (($action != 'editline') ? 'addline' : 'updateline').'">
  329. <input type="hidden" name="mode" value="">
  330. <input type="hidden" name="id" value="' . $object->id.'">
  331. ';
  332. if (!empty($conf->use_javascript_ajax) && $object->status == 0) {
  333. include DOL_DOCUMENT_ROOT.'/core/tpl/ajaxrow.tpl.php';
  334. }
  335. print '<div class="div-table-responsive-no-min">';
  336. if (!empty($object->lines) || ($object->status == $object::STATUS_DRAFT && $permissiontoadd && $action != 'selectlines' && $action != 'editline'))
  337. {
  338. print '<table id="tablelines" class="noborder noshadow" width="100%">';
  339. }
  340. if (!empty($object->lines))
  341. {
  342. $object->printObjectLines($action, $mysoc, null, GETPOST('lineid', 'int'), 1);
  343. }
  344. // Form to add new line
  345. if ($object->status == 0 && $permissiontoadd && $action != 'selectlines')
  346. {
  347. if ($action != 'editline')
  348. {
  349. // Add products/services form
  350. $object->formAddObjectLine(1, $mysoc, $soc);
  351. $parameters = array();
  352. $reshook = $hookmanager->executeHooks('formAddObjectLine', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
  353. }
  354. }
  355. if (!empty($object->lines) || ($object->status == $object::STATUS_DRAFT && $permissiontoadd && $action != 'selectlines' && $action != 'editline'))
  356. {
  357. print '</table>';
  358. }
  359. print '</div>';
  360. print "</form>\n";
  361. }
  362. // Buttons for actions
  363. if ($action != 'presend' && $action != 'editline') {
  364. print '<div class="tabsAction">'."\n";
  365. $parameters = array();
  366. $reshook = $hookmanager->executeHooks('addMoreActionsButtons', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
  367. if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
  368. if (empty($reshook))
  369. {
  370. // Send
  371. if (empty($user->socid)) {
  372. print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&action=presend&mode=init#formmailbeforetitle">'.$langs->trans('SendMail').'</a>'."\n";
  373. }
  374. // Back to draft
  375. if ($object->status == $object::STATUS_VALIDATED)
  376. {
  377. if ($permissiontoadd)
  378. {
  379. print '<a class="butAction" href="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'&action=confirm_setdraft&confirm=yes">'.$langs->trans("SetToDraft").'</a>';
  380. }
  381. }
  382. // Modify
  383. if ($permissiontoadd)
  384. {
  385. print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&action=edit">'.$langs->trans("Modify").'</a>'."\n";
  386. }
  387. else
  388. {
  389. print '<a class="butActionRefused classfortooltip" href="#" title="'.dol_escape_htmltag($langs->trans("NotEnoughPermissions")).'">'.$langs->trans('Modify').'</a>'."\n";
  390. }
  391. // Validate
  392. if ($object->status == $object::STATUS_DRAFT)
  393. {
  394. if ($permissiontoadd)
  395. {
  396. if (empty($object->table_element_line) || (is_array($object->lines) && count($object->lines) > 0))
  397. {
  398. print '<a class="butAction" href="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'&action=confirm_validate&confirm=yes">'.$langs->trans("Validate").'</a>';
  399. }
  400. else
  401. {
  402. $langs->load("errors");
  403. print '<a class="butActionRefused" href="" title="'.$langs->trans("ErrorAddAtLeastOneLineFirst").'">'.$langs->trans("Validate").'</a>';
  404. }
  405. }
  406. }
  407. // Clone
  408. if ($permissiontoadd)
  409. {
  410. print '<a class="butAction" href="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'&socid='.$object->socid.'&action=clone&object=myobject">'.$langs->trans("ToClone").'</a>'."\n";
  411. }
  412. /*
  413. if ($permissiontoadd)
  414. {
  415. if ($object->status == $object::STATUS_ENABLED)
  416. {
  417. print '<a class="butActionDelete" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&action=disable">'.$langs->trans("Disable").'</a>'."\n";
  418. }
  419. else
  420. {
  421. print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&action=enable">'.$langs->trans("Enable").'</a>'."\n";
  422. }
  423. }
  424. if ($permissiontoadd)
  425. {
  426. if ($object->status == $object::STATUS_VALIDATED)
  427. {
  428. print '<a class="butActionDelete" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&action=close">'.$langs->trans("Cancel").'</a>'."\n";
  429. }
  430. else
  431. {
  432. print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&action=reopen">'.$langs->trans("Re-Open").'</a>'."\n";
  433. }
  434. }
  435. */
  436. // Delete (need delete permission, or if draft, just need create/modify permission)
  437. if ($permissiontodelete)
  438. {
  439. print '<a class="butActionDelete" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&amp;action=delete">'.$langs->trans('Delete').'</a>'."\n";
  440. }
  441. else
  442. {
  443. print '<a class="butActionRefused classfortooltip" href="#" title="'.dol_escape_htmltag($langs->trans("NotEnoughPermissions")).'">'.$langs->trans('Delete').'</a>'."\n";
  444. }
  445. }
  446. print '</div>'."\n";
  447. }
  448. // Select mail models is same action as presend
  449. if (GETPOST('modelselected')) {
  450. $action = 'presend';
  451. }
  452. if ($action != 'presend')
  453. {
  454. print '<div class="fichecenter"><div class="fichehalfleft">';
  455. print '<a name="builddoc"></a>'; // ancre
  456. // Documents
  457. /*$objref = dol_sanitizeFileName($object->ref);
  458. $relativepath = $objref . '/' . $objref . '.pdf';
  459. $filedir = $conf->mymodule->dir_output . '/' . $objref;
  460. $urlsource = $_SERVER["PHP_SELF"] . "?id=" . $object->id;
  461. $genallowed = $user->rights->mymodule->myobject->read; // If you can read, you can build the PDF to read content
  462. $delallowed = $user->rights->mymodule->myobject->create; // If you can create/edit, you can remove a file on card
  463. print $formfile->showdocuments('mymodule', $objref, $filedir, $urlsource, $genallowed, $delallowed, $object->modelpdf, 1, 0, 0, 28, 0, '', '', '', $langs->defaultlang);
  464. */
  465. // Show links to link elements
  466. $linktoelem = $form->showLinkToObjectBlock($object, null, array('myobject'));
  467. $somethingshown = $form->showLinkedObjectBlock($object, $linktoelem);
  468. print '</div><div class="fichehalfright"><div class="ficheaddleft">';
  469. $MAXEVENT = 10;
  470. $morehtmlright = '<a href="'.dol_buildpath('/mymodule/myobject_agenda.php', 1).'?id='.$object->id.'">';
  471. $morehtmlright .= $langs->trans("SeeAll");
  472. $morehtmlright .= '</a>';
  473. // List of actions on element
  474. include_once DOL_DOCUMENT_ROOT.'/core/class/html.formactions.class.php';
  475. $formactions = new FormActions($db);
  476. $somethingshown = $formactions->showactions($object, $object->element, (is_object($object->thirdparty) ? $object->thirdparty->id : 0), 1, '', $MAXEVENT, '', $morehtmlright);
  477. print '</div></div></div>';
  478. }
  479. //Select mail models is same action as presend
  480. if (GETPOST('modelselected')) $action = 'presend';
  481. // Presend form
  482. $modelmail = 'myobject';
  483. $defaulttopic = 'InformationMessage';
  484. $diroutput = $conf->mymodule->dir_output;
  485. $trackid = 'myobject'.$object->id;
  486. include DOL_DOCUMENT_ROOT.'/core/tpl/card_presend.tpl.php';
  487. }
  488. // End of page
  489. llxFooter();
  490. $db->close();