50 if (!$res && !empty($_SERVER[
"CONTEXT_DOCUMENT_ROOT"])) {
51 $res = @include $_SERVER[
"CONTEXT_DOCUMENT_ROOT"].
"/main.inc.php";
54 $tmp = empty($_SERVER[
'SCRIPT_FILENAME']) ?
'' : $_SERVER[
'SCRIPT_FILENAME']; $tmp2 = realpath(__FILE__); $i = strlen($tmp) - 1; $j = strlen($tmp2) - 1;
55 while ($i > 0 && $j > 0 && isset($tmp[$i]) && isset($tmp2[$j]) && $tmp[$i] == $tmp2[$j]) {
58 if (!$res && $i > 0 && file_exists(substr($tmp, 0, ($i + 1)).
"/main.inc.php")) {
59 $res = @include substr($tmp, 0, ($i + 1)).
"/main.inc.php";
61 if (!$res && $i > 0 && file_exists(dirname(substr($tmp, 0, ($i + 1))).
"/main.inc.php")) {
62 $res = @include dirname(substr($tmp, 0, ($i + 1))).
"/main.inc.php";
65 if (!$res && file_exists(
"../main.inc.php")) {
66 $res = @include
"../main.inc.php";
68 if (!$res && file_exists(
"../../main.inc.php")) {
69 $res = @include
"../../main.inc.php";
71 if (!$res && file_exists(
"../../../main.inc.php")) {
72 $res = @include
"../../../main.inc.php";
75 die(
"Include of main fails");
78 require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formcompany.class.php';
79 require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formfile.class.php';
80 require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formprojet.class.php';
85 $langs->loadLangs(array(
"mymodule@mymodule",
"other"));
90 $lineid =
GETPOST(
'lineid',
'int');
92 $action =
GETPOST(
'action',
'aZ09');
93 $confirm =
GETPOST(
'confirm',
'alpha');
94 $cancel =
GETPOST(
'cancel',
'aZ09');
95 $contextpage =
GETPOST(
'contextpage',
'aZ') ?
GETPOST(
'contextpage',
'aZ') : str_replace(
'_',
'', basename(dirname(__FILE__)).basename(__FILE__,
'.php'));
96 $backtopage =
GETPOST(
'backtopage',
'alpha');
97 $backtopageforcancel =
GETPOST(
'backtopageforcancel',
'alpha');
98 $dol_openinpopup =
GETPOST(
'dol_openinpopup',
'aZ09');
103 $diroutputmassaction = $conf->mymodule->dir_output.
'/temp/massgeneration/'.$user->id;
104 $hookmanager->initHooks(array(
'myobjectcard',
'globalcard'));
107 $extrafields->fetch_name_optionals_label($object->table_element);
109 $search_array_options = $extrafields->getOptionalsFromPost($object->table_element,
'',
'search_');
112 $search_all =
GETPOST(
"search_all",
'alpha');
114 foreach ($object->fields as $key => $val) {
115 if (
GETPOST(
'search_'.$key,
'alpha')) {
116 $search[$key] =
GETPOST(
'search_'.$key,
'alpha');
120 if (empty($action) && empty($id) && empty($ref)) {
125 include DOL_DOCUMENT_ROOT.
'/core/actions_fetchobject.inc.php';
129 $enablepermissioncheck = 0;
130 if ($enablepermissioncheck) {
131 $permissiontoread = $user->rights->mymodule->myobject->read;
132 $permissiontoadd = $user->rights->mymodule->myobject->write;
133 $permissiontodelete = $user->rights->mymodule->myobject->delete || ($permissiontoadd && isset($object->status) && $object->status == $object::STATUS_DRAFT);
134 $permissionnote = $user->rights->mymodule->myobject->write;
135 $permissiondellink = $user->rights->mymodule->myobject->write;
137 $permissiontoread = 1;
138 $permissiontoadd = 1;
139 $permissiontodelete = 1;
141 $permissiondellink = 1;
144 $upload_dir = $conf->mymodule->multidir_output[isset($object->entity) ? $object->entity : 1].
'/myobject';
159 $parameters = array();
160 $reshook = $hookmanager->executeHooks(
'doActions', $parameters, $object, $action);
165 if (empty($reshook)) {
168 $backurlforlist =
dol_buildpath(
'/mymodule/myobject_list.php', 1);
170 if (empty($backtopage) || ($cancel && empty($id))) {
171 if (empty($backtopage) || ($cancel && strpos($backtopage,
'__ID__'))) {
172 if (empty($id) && (($action !=
'add' && $action !=
'create') || $cancel)) {
173 $backtopage = $backurlforlist;
175 $backtopage =
dol_buildpath(
'/mymodule/myobject_card.php', 1).
'?id='.((!empty($id) && $id > 0) ? $id :
'__ID__');
180 $triggermodname =
'MYMODULE_MYOBJECT_MODIFY';
183 include DOL_DOCUMENT_ROOT.
'/core/actions_addupdatedelete.inc.php';
186 include DOL_DOCUMENT_ROOT.
'/core/actions_dellink.inc.php';
189 include DOL_DOCUMENT_ROOT.
'/core/actions_printing.inc.php';
195 include DOL_DOCUMENT_ROOT.
'/core/actions_builddoc.inc.php';
197 if ($action ==
'set_thirdparty' && $permissiontoadd) {
198 $object->setValueFrom(
'fk_soc',
GETPOST(
'fk_soc',
'int'),
'',
'',
'date',
'', $user, $triggermodname);
200 if ($action ==
'classin' && $permissiontoadd) {
201 $object->setProject(
GETPOST(
'projectid',
'int'));
205 $triggersendname =
'MYMODULE_MYOBJECT_SENTBYMAIL';
206 $autocopy =
'MAIN_MAIL_AUTOCOPY_MYOBJECT_TO';
207 $trackid =
'myobject'.$object->id;
208 include DOL_DOCUMENT_ROOT.
'/core/actions_sendmails.inc.php';
224 $title = $langs->trans(
"MyObject");
245 if ($action ==
'create') {
246 if (empty($permissiontoadd)) {
251 print
load_fiche_titre($langs->trans(
"NewObject", $langs->transnoentitiesnoconv(
"MyObject")),
'',
'object_'.$object->picto);
253 print
'<form method="POST" action="'.$_SERVER[
"PHP_SELF"].
'">';
254 print
'<input type="hidden" name="token" value="'.newToken().
'">';
255 print
'<input type="hidden" name="action" value="add">';
257 print
'<input type="hidden" name="backtopage" value="'.$backtopage.
'">';
259 if ($backtopageforcancel) {
260 print
'<input type="hidden" name="backtopageforcancel" value="'.$backtopageforcancel.
'">';
268 print
'<table class="border centpercent tableforfieldcreate">'.
"\n";
271 include DOL_DOCUMENT_ROOT.
'/core/tpl/commonfields_add.tpl.php';
274 include DOL_DOCUMENT_ROOT.
'/core/tpl/extrafields_add.tpl.php';
276 print
'</table>'.
"\n";
280 print
$form->buttonsSaveCancel(
"Create");
288 if (($id || $ref) && $action ==
'edit') {
289 print
load_fiche_titre($langs->trans(
"MyObject"),
'',
'object_'.$object->picto);
291 print
'<form method="POST" action="'.$_SERVER[
"PHP_SELF"].
'">';
292 print
'<input type="hidden" name="token" value="'.newToken().
'">';
293 print
'<input type="hidden" name="action" value="update">';
294 print
'<input type="hidden" name="id" value="'.$object->id.
'">';
296 print
'<input type="hidden" name="backtopage" value="'.$backtopage.
'">';
298 if ($backtopageforcancel) {
299 print
'<input type="hidden" name="backtopageforcancel" value="'.$backtopageforcancel.
'">';
304 print
'<table class="border centpercent tableforfieldedit">'.
"\n";
307 include DOL_DOCUMENT_ROOT.
'/core/tpl/commonfields_edit.tpl.php';
310 include DOL_DOCUMENT_ROOT.
'/core/tpl/extrafields_edit.tpl.php';
316 print
$form->buttonsSaveCancel();
322 if ($object->id > 0 && (empty($action) || ($action !=
'edit' && $action !=
'create'))) {
323 $res = $object->fetch_optionals();
326 print
dol_get_fiche_head($head,
'card', $langs->trans(
"MyObject"), -1, $object->picto);
331 if ($action ==
'delete') {
332 $formconfirm =
$form->formconfirm($_SERVER[
"PHP_SELF"].
'?id='.$object->id, $langs->trans(
'DeleteMyObject'), $langs->trans(
'ConfirmDeleteObject'),
'confirm_delete',
'', 0, 1);
335 if ($action ==
'deleteline') {
336 $formconfirm =
$form->formconfirm($_SERVER[
"PHP_SELF"].
'?id='.$object->id.
'&lineid='.$lineid, $langs->trans(
'DeleteLine'), $langs->trans(
'ConfirmDeleteLine'),
'confirm_deleteline',
'', 0, 1);
340 if ($action ==
'clone') {
342 $formquestion = array();
343 $formconfirm =
$form->formconfirm($_SERVER[
"PHP_SELF"].
'?id='.$object->id, $langs->trans(
'ToClone'), $langs->trans(
'ConfirmCloneAsk', $object->ref),
'confirm_clone', $formquestion,
'yes', 1);
347 if ($action ==
'xxx') {
348 $text = $langs->trans(
'ConfirmActionMyObject', $object->ref);
357 $formquestion = array();
368 $formconfirm =
$form->formconfirm($_SERVER[
"PHP_SELF"].
'?id='.$object->id, $langs->trans(
'XXX'), $text,
'confirm_xxx', $formquestion, 0, 1, 220);
372 $parameters = array(
'formConfirm' =>
$formconfirm,
'lineid' => $lineid);
373 $reshook = $hookmanager->executeHooks(
'formConfirm', $parameters, $object, $action);
374 if (empty($reshook)) {
376 } elseif ($reshook > 0) {
386 $linkback =
'<a href="'.dol_buildpath(
'/mymodule/myobject_list.php', 1).
'?restore_lastsearch_values=1'.(!empty($socid) ?
'&socid='.$socid :
'').
'">'.$langs->trans(
"BackToList").
'</a>';
388 $morehtmlref =
'<div class="refidno">';
423 $morehtmlref .=
'</div>';
426 dol_banner_tab($object,
'ref', $linkback, 1,
'ref',
'ref', $morehtmlref);
429 print
'<div class="fichecenter">';
430 print
'<div class="fichehalfleft">';
431 print
'<div class="underbanner clearboth"></div>';
432 print
'<table class="border centpercent tableforfield">'.
"\n";
438 include DOL_DOCUMENT_ROOT.
'/core/tpl/commonfields_view.tpl.php';
441 include DOL_DOCUMENT_ROOT.
'/core/tpl/extrafields_view.tpl.php';
447 print
'<div class="clearboth"></div>';
456 if (!empty($object->table_element_line)) {
458 $result = $object->getLinesArray();
460 print
' <form name="addproduct" id="addproduct" action="'.$_SERVER[
"PHP_SELF"].
'?id='.$object->id.(($action !=
'editline') ?
'' :
'#line_'.
GETPOST(
'lineid',
'int')).
'" method="POST">
461 <input type="hidden" name="token" value="' .
newToken().
'">
462 <input type="hidden" name="action" value="' . (($action !=
'editline') ?
'addline' :
'updateline').
'">
463 <input type="hidden" name="mode" value="">
464 <input type="hidden" name="page_y" value="">
465 <input type="hidden" name="id" value="' . $object->id.
'">
468 if (!empty($conf->use_javascript_ajax) && $object->status == 0) {
469 include DOL_DOCUMENT_ROOT.
'/core/tpl/ajaxrow.tpl.php';
472 print
'<div class="div-table-responsive-no-min">';
473 if (!empty($object->lines) || ($object->status == $object::STATUS_DRAFT && $permissiontoadd && $action !=
'selectlines' && $action !=
'editline')) {
474 print
'<table id="tablelines" class="noborder noshadow" width="100%">';
477 if (!empty($object->lines)) {
478 $object->printObjectLines($action, $mysoc,
null,
GETPOST(
'lineid',
'int'), 1);
482 if ($object->status == 0 && $permissiontoadd && $action !=
'selectlines') {
483 if ($action !=
'editline') {
486 $parameters = array();
487 $reshook = $hookmanager->executeHooks(
'formAddObjectLine', $parameters, $object, $action);
488 if ($reshook < 0)
setEventMessages($hookmanager->error, $hookmanager->errors,
'errors');
490 $object->formAddObjectLine(1, $mysoc, $soc);
494 if (!empty($object->lines) || ($object->status == $object::STATUS_DRAFT && $permissiontoadd && $action !=
'selectlines' && $action !=
'editline')) {
505 if ($action !=
'presend' && $action !=
'editline') {
506 print
'<div class="tabsAction">'.
"\n";
507 $parameters = array();
508 $reshook = $hookmanager->executeHooks(
'addMoreActionsButtons', $parameters, $object, $action);
513 if (empty($reshook)) {
515 if (empty($user->socid)) {
516 print
dolGetButtonAction($langs->trans(
'SendMail'),
'',
'default', $_SERVER[
"PHP_SELF"].
'?id='.$object->id.
'&action=presend&mode=init&token='.
newToken().
'#formmailbeforetitle');
520 if ($object->status == $object::STATUS_VALIDATED) {
521 print
dolGetButtonAction($langs->trans(
'SetToDraft'),
'',
'default', $_SERVER[
"PHP_SELF"].
'?id='.$object->id.
'&action=confirm_setdraft&confirm=yes&token='.
newToken(),
'', $permissiontoadd);
524 print
dolGetButtonAction($langs->trans(
'Modify'),
'',
'default', $_SERVER[
"PHP_SELF"].
'?id='.$object->id.
'&action=edit&token='.
newToken(),
'', $permissiontoadd);
527 if ($object->status == $object::STATUS_DRAFT) {
528 if (empty($object->table_element_line) || (is_array($object->lines) && count($object->lines) > 0)) {
529 print
dolGetButtonAction($langs->trans(
'Validate'),
'',
'default', $_SERVER[
'PHP_SELF'].
'?id='.$object->id.
'&action=confirm_validate&confirm=yes&token='.
newToken(),
'', $permissiontoadd);
531 $langs->load(
"errors");
532 print
dolGetButtonAction($langs->trans(
"ErrorAddAtLeastOneLineFirst"), $langs->trans(
"Validate"),
'default',
'#',
'', 0);
537 print
dolGetButtonAction($langs->trans(
'ToClone'),
'',
'default', $_SERVER[
'PHP_SELF'].
'?id='.$object->id.(!empty($object->socid)?
'&socid='.$object->socid:
'').
'&action=clone&token='.
newToken(),
'', $permissiontoadd);
557 print
dolGetButtonAction($langs->trans(
'Delete'),
'',
'delete', $_SERVER[
'PHP_SELF'].
'?id='.$object->id.
'&action=delete&token='.
newToken(),
'', $permissiontodelete || ($object->status == $object::STATUS_DRAFT && $permissiontoadd));
564 if (
GETPOST(
'modelselected')) {
568 if ($action !=
'presend') {
569 print
'<div class="fichecenter"><div class="fichehalfleft">';
570 print
'<a name="builddoc"></a>';
572 $includedocgeneration = 0;
575 if ($includedocgeneration) {
577 $relativepath = $objref.
'/'.$objref.
'.pdf';
578 $filedir = $conf->mymodule->dir_output.
'/'.$object->element.
'/'.$objref;
579 $urlsource = $_SERVER[
"PHP_SELF"].
"?id=".$object->id;
580 $genallowed = $permissiontoread;
581 $delallowed = $permissiontoadd;
582 print $formfile->showdocuments(
'mymodule:MyObject', $object->element.
'/'.$objref, $filedir, $urlsource, $genallowed, $delallowed, $object->model_pdf, 1, 0, 0, 28, 0,
'',
'',
'', $langs->defaultlang);
586 $linktoelem =
$form->showLinkToObjectBlock($object,
null, array(
'myobject'));
587 $somethingshown =
$form->showLinkedObjectBlock($object, $linktoelem);
590 print
'</div><div class="fichehalfright">';
594 $morehtmlcenter =
dolGetButtonTitle($langs->trans(
'SeeAll'),
'',
'fa fa-bars imgforviewmode',
dol_buildpath(
'/mymodule/myobject_agenda.php', 1).
'?id='.$object->id);
597 include_once DOL_DOCUMENT_ROOT.
'/core/class/html.formactions.class.php';
599 $somethingshown =
$formactions->showactions($object, $object->element.
'@'.$object->module, (is_object($object->thirdparty) ? $object->thirdparty->id : 0), 1,
'', $MAXEVENT,
'', $morehtmlcenter);
601 print
'</div></div>';
605 if (
GETPOST(
'modelselected')) {
610 $modelmail =
'myobject';
611 $defaulttopic =
'InformationMessage';
612 $diroutput = $conf->mymodule->dir_output;
613 $trackid =
'myobject'.$object->id;
615 include DOL_DOCUMENT_ROOT.
'/core/tpl/card_presend.tpl.php';