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