partnership_card.php 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681
  1. <?php
  2. /* Copyright (C) 2017-2021 Laurent Destailleur <eldy@users.sourceforge.net>
  3. * Copyright (C) 2021 NextGestion <contact@nextgestion.com>
  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 partnership_card.php
  20. * \ingroup partnership
  21. * \brief Page to create/edit/view partnership
  22. */
  23. // Load Dolibarr environment
  24. require '../main.inc.php';
  25. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formcompany.class.php';
  26. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
  27. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formprojet.class.php';
  28. require_once DOL_DOCUMENT_ROOT.'/partnership/class/partnership.class.php';
  29. require_once DOL_DOCUMENT_ROOT.'/partnership/lib/partnership.lib.php';
  30. // Load translation files required by the page
  31. $langs->loadLangs(array("partnership", "other"));
  32. // Get parameters
  33. $id = GETPOST('id', 'int');
  34. $ref = GETPOST('ref', 'alpha');
  35. $action = GETPOST('action', 'aZ09');
  36. $confirm = GETPOST('confirm', 'alpha');
  37. $cancel = GETPOST('cancel', 'aZ09');
  38. $contextpage = GETPOST('contextpage', 'aZ') ? GETPOST('contextpage', 'aZ') : str_replace('_', '', basename(dirname(__FILE__)).basename(__FILE__, '.php')); // To manage different context of search
  39. $backtopage = GETPOST('backtopage', 'alpha');
  40. $backtopageforcancel = GETPOST('backtopageforcancel', 'alpha');
  41. $lineid = GETPOST('lineid', 'int');
  42. $dol_openinpopup = GETPOST('dol_openinpopup', 'aZ09');
  43. // Initialize technical objects
  44. $object = new Partnership($db);
  45. $extrafields = new ExtraFields($db);
  46. $diroutputmassaction = $conf->partnership->dir_output.'/temp/massgeneration/'.$user->id;
  47. $hookmanager->initHooks(array('partnershipcard', 'globalcard')); // Note that conf->hooks_modules contains array
  48. // Fetch optionals attributes and labels
  49. $extrafields->fetch_name_optionals_label($object->table_element);
  50. $search_array_options = $extrafields->getOptionalsFromPost($object->table_element, '', 'search_');
  51. // Initialize array of search criterias
  52. $search_all = GETPOST("search_all", 'alpha');
  53. $search = array();
  54. foreach ($object->fields as $key => $val) {
  55. if (GETPOST('search_'.$key, 'alpha')) {
  56. $search[$key] = GETPOST('search_'.$key, 'alpha');
  57. }
  58. }
  59. if (empty($action) && empty($id) && empty($ref)) {
  60. $action = 'view';
  61. }
  62. // Load object
  63. include DOL_DOCUMENT_ROOT.'/core/actions_fetchobject.inc.php'; // Must be include, not include_once.
  64. $permissiontoread = $user->hasRight('partnership', 'read');
  65. $permissiontoadd = $user->hasRight('partnership', 'write'); // Used by the include of actions_addupdatedelete.inc.php and actions_lineupdown.inc.php
  66. $permissiontodelete = $user->hasRight('partnership', 'delete') || ($permissiontoadd && isset($object->status) && $object->status == $object::STATUS_DRAFT);
  67. $permissionnote = $user->hasRight('partnership', 'write'); // Used by the include of actions_setnotes.inc.php
  68. $permissiondellink = $user->hasRight('partnership', 'write'); // Used by the include of actions_dellink.inc.php
  69. $upload_dir = $conf->partnership->multidir_output[isset($object->entity) ? $object->entity : 1];
  70. $managedfor = getDolGlobalString('PARTNERSHIP_IS_MANAGED_FOR', 'thirdparty');
  71. // Security check (enable the most restrictive one)
  72. //if ($user->socid > 0) accessforbidden();
  73. //if ($user->socid > 0) $socid = $user->socid;
  74. //$isdraft = (isset($object->status) && ($object->status == $object::STATUS_DRAFT) ? 1 : 0);
  75. //restrictedArea($user, $object->module, $object->id, $object->table_element, $object->element, 'fk_soc', 'rowid', $isdraft);
  76. if (!isModEnabled('partnership')) {
  77. accessforbidden();
  78. }
  79. if (!$permissiontoread) {
  80. accessforbidden();
  81. }
  82. if ($object->id > 0 && !($object->fk_member > 0) && $managedfor == 'member') accessforbidden();
  83. if ($object->id > 0 && !($object->fk_soc > 0) && $managedfor == 'thirdparty') accessforbidden();
  84. /*
  85. * Actions
  86. */
  87. $parameters = array();
  88. $reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
  89. if ($reshook < 0) {
  90. setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
  91. }
  92. if (empty($reshook)) {
  93. $error = 0;
  94. $backurlforlist = dol_buildpath('/partnership/partnership_list.php', 1);
  95. if (empty($backtopage) || ($cancel && empty($id))) {
  96. if (empty($backtopage) || ($cancel && strpos($backtopage, '__ID__'))) {
  97. if (empty($id) && (($action != 'add' && $action != 'create') || $cancel)) {
  98. $backtopage = $backurlforlist;
  99. } else {
  100. $backtopage = dol_buildpath('/partnership/partnership_card.php', 1).'?id='.($id > 0 ? $id : '__ID__');
  101. }
  102. }
  103. }
  104. $fk_partner = ($managedfor == 'member') ? GETPOST('fk_member', 'int') : GETPOST('fk_soc', 'int');
  105. $obj_partner = ($managedfor == 'member') ? $object->fk_member : $object->fk_soc;
  106. $triggermodname = 'PARTNERSHIP_MODIFY'; // Name of trigger action code to execute when we modify record
  107. // Actions cancel, add, update, update_extras, confirm_validate, confirm_delete, confirm_deleteline, confirm_clone, confirm_close, confirm_setdraft, confirm_reopen
  108. include DOL_DOCUMENT_ROOT.'/core/actions_addupdatedelete.inc.php';
  109. // Action accept object
  110. if ($action == 'confirm_validate' && $confirm == 'yes' && $permissiontoadd) {
  111. $result = $object->validate($user);
  112. if ($result >= 0) {
  113. // Define output language
  114. if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) {
  115. if (method_exists($object, 'generateDocument')) {
  116. $outputlangs = $langs;
  117. $newlang = '';
  118. if (getDolGlobalInt('MAIN_MULTILANGS') && empty($newlang) && GETPOST('lang_id', 'aZ09')) {
  119. $newlang = GETPOST('lang_id', 'aZ09');
  120. }
  121. if (getDolGlobalInt('MAIN_MULTILANGS') && empty($newlang)) {
  122. $newlang = $object->thirdparty->default_lang;
  123. }
  124. if (!empty($newlang)) {
  125. $outputlangs = new Translate("", $conf);
  126. $outputlangs->setDefaultLang($newlang);
  127. }
  128. $ret = $object->fetch($id); // Reload to get new records
  129. $model = $object->model_pdf;
  130. $retgen = $object->generateDocument($model, $outputlangs, 0, 0, 0);
  131. if ($retgen < 0) {
  132. setEventMessages($object->error, $object->errors, 'warnings');
  133. }
  134. }
  135. }
  136. } else {
  137. setEventMessages($object->error, $object->errors, 'errors');
  138. }
  139. } elseif ($action == 'confirm_accept' && $confirm == 'yes' && $permissiontoadd) {
  140. $result = $object->approve($user);
  141. if ($result >= 0) {
  142. // Define output language
  143. if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) {
  144. if (method_exists($object, 'generateDocument')) {
  145. $outputlangs = $langs;
  146. $newlang = '';
  147. if (getDolGlobalInt('MAIN_MULTILANGS') && empty($newlang) && GETPOST('lang_id', 'aZ09')) {
  148. $newlang = GETPOST('lang_id', 'aZ09');
  149. }
  150. if (getDolGlobalInt('MAIN_MULTILANGS') && empty($newlang)) {
  151. $newlang = $object->thirdparty->default_lang;
  152. }
  153. if (!empty($newlang)) {
  154. $outputlangs = new Translate("", $conf);
  155. $outputlangs->setDefaultLang($newlang);
  156. }
  157. $ret = $object->fetch($id); // Reload to get new records
  158. $model = $object->model_pdf;
  159. $retgen = $object->generateDocument($model, $outputlangs, 0, 0, 0);
  160. if ($retgen < 0) {
  161. setEventMessages($object->error, $object->errors, 'warnings');
  162. }
  163. }
  164. }
  165. } else {
  166. setEventMessages($object->error, $object->errors, 'errors');
  167. }
  168. } elseif ($action == 'confirm_refuse' && $permissiontoadd && !GETPOST('cancel', 'alpha')) {
  169. // Close proposal
  170. if (!(GETPOST('reason_decline_or_cancel', 'alpha'))) {
  171. setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Refuse")), null, 'errors');
  172. $action = 'refuse';
  173. } else {
  174. // prevent browser refresh from closing proposal several times
  175. if ($object->statut != $object::STATUS_REFUSED) {
  176. $db->begin();
  177. $result = $object->refused($user, GETPOST('reason_decline_or_cancel', 'restricthtml'));
  178. if ($result < 0) {
  179. setEventMessages($object->error, $object->errors, 'errors');
  180. $error++;
  181. } else {
  182. $object->reason_decline_or_cancel = GETPOST('reason_decline_or_cancel', 'restricthtml');
  183. }
  184. if (!$error) {
  185. $db->commit();
  186. } else {
  187. $db->rollback();
  188. }
  189. }
  190. }
  191. }
  192. // Actions when linking object each other
  193. include DOL_DOCUMENT_ROOT.'/core/actions_dellink.inc.php';
  194. // Actions when printing a doc from card
  195. include DOL_DOCUMENT_ROOT.'/core/actions_printing.inc.php';
  196. // Action to move up and down lines of object
  197. //include DOL_DOCUMENT_ROOT.'/core/actions_lineupdown.inc.php';
  198. // Action to build doc
  199. include DOL_DOCUMENT_ROOT.'/core/actions_builddoc.inc.php';
  200. if ($action == 'set_thirdparty' && $permissiontoadd) {
  201. $object->setValueFrom('fk_soc', GETPOST('fk_soc', 'int'), '', '', 'date', '', $user, $triggermodname);
  202. }
  203. if ($action == 'classin' && $permissiontoadd) {
  204. $object->setProject(GETPOST('projectid', 'int'));
  205. }
  206. // Actions to send emails
  207. $triggersendname = 'PARTNERSHIP_SENTBYMAIL';
  208. $autocopy = 'MAIN_MAIL_AUTOCOPY_PARTNERSHIP_TO';
  209. $trackid = 'pship'.$object->id;
  210. include DOL_DOCUMENT_ROOT.'/core/actions_sendmails.inc.php';
  211. if (!empty($id) && !empty(GETPOST('confirm'))) {
  212. header("Location: ".$_SERVER['PHP_SELF']."?id=".$id);
  213. exit;
  214. }
  215. }
  216. if ($object->id > 0 && $object->status == $object::STATUS_REFUSED) $object->fields['reason_decline_or_cancel']['visible'] = 3;
  217. /*
  218. * View
  219. */
  220. $form = new Form($db);
  221. $formfile = new FormFile($db);
  222. $formproject = new FormProjets($db);
  223. $title = $langs->trans("Partnership");
  224. $help_url = '';
  225. llxHeader('', $title, $help_url);
  226. // Part to create
  227. if ($action == 'create') {
  228. if (empty($permissiontoadd)) {
  229. accessforbidden('NotEnoughPermissions', 0, 1);
  230. }
  231. print load_fiche_titre($langs->trans("NewPartnership"), '', 'object_'.$object->picto);
  232. print '<form method="POST" action="'.$_SERVER["PHP_SELF"].'">';
  233. print '<input type="hidden" name="token" value="'.newToken().'">';
  234. print '<input type="hidden" name="action" value="add">';
  235. if ($backtopage) {
  236. print '<input type="hidden" name="backtopage" value="'.$backtopage.'">';
  237. }
  238. if ($backtopageforcancel) {
  239. print '<input type="hidden" name="backtopageforcancel" value="'.$backtopageforcancel.'">';
  240. }
  241. print dol_get_fiche_head(array(), '');
  242. print '<table class="border centpercent tableforfieldcreate">'."\n";
  243. // Common attributes
  244. include DOL_DOCUMENT_ROOT.'/core/tpl/commonfields_add.tpl.php';
  245. // Other attributes
  246. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_add.tpl.php';
  247. print '</table>'."\n";
  248. print dol_get_fiche_end();
  249. print $form->buttonsSaveCancel("Create");
  250. print '</form>';
  251. //dol_set_focus('input[name="ref"]');
  252. }
  253. // Part to edit record
  254. if (($id || $ref) && $action == 'edit') {
  255. print load_fiche_titre($langs->trans("Partnership"), '', 'object_'.$object->picto);
  256. print '<form method="POST" action="'.$_SERVER["PHP_SELF"].'">';
  257. print '<input type="hidden" name="token" value="'.newToken().'">';
  258. print '<input type="hidden" name="action" value="update">';
  259. print '<input type="hidden" name="id" value="'.$object->id.'">';
  260. if ($backtopage) {
  261. print '<input type="hidden" name="backtopage" value="'.$backtopage.'">';
  262. }
  263. if ($backtopageforcancel) {
  264. print '<input type="hidden" name="backtopageforcancel" value="'.$backtopageforcancel.'">';
  265. }
  266. print dol_get_fiche_head();
  267. print '<table class="border centpercent tableforfieldedit">'."\n";
  268. // Common attributes
  269. include DOL_DOCUMENT_ROOT.'/core/tpl/commonfields_edit.tpl.php';
  270. // Other attributes
  271. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_edit.tpl.php';
  272. print '</table>';
  273. print dol_get_fiche_end();
  274. print $form->buttonsSaveCancel();
  275. print '</form>';
  276. }
  277. // Part to show record
  278. if ($object->id > 0 && (empty($action) || ($action != 'edit' && $action != 'create'))) {
  279. $head = partnershipPrepareHead($object);
  280. print dol_get_fiche_head($head, 'card', $langs->trans("Partnership"), -1, $object->picto);
  281. $formconfirm = '';
  282. // Confirmation to delete
  283. if ($action == 'delete') {
  284. $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('DeletePartnership'), $langs->trans('ConfirmDeleteObject'), 'confirm_delete', '', 0, 1);
  285. }
  286. // Confirmation to delete line
  287. if ($action == 'deleteline') {
  288. $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id.'&lineid='.$lineid, $langs->trans('DeleteLine'), $langs->trans('ConfirmDeleteLine'), 'confirm_deleteline', '', 0, 1);
  289. }
  290. // Clone confirmation
  291. if ($action == 'clone') {
  292. // Create an array for form
  293. $formquestion = array();
  294. $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('ToClone'), $langs->trans('ConfirmCloneAsk', $object->ref), 'confirm_clone', $formquestion, 'yes', 1);
  295. }
  296. // Close confirmation
  297. if ($action == 'close') {
  298. // Create an array for form
  299. $formquestion = array();
  300. $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('ToClose'), $langs->trans('ConfirmClosePartnershipAsk', $object->ref), 'confirm_close', $formquestion, 'yes', 1);
  301. }
  302. // Reopon confirmation
  303. if ($action == 'reopen') {
  304. // Create an array for form
  305. $formquestion = array();
  306. $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('ToReopon'), $langs->trans('ConfirmReoponAsk', $object->ref), 'confirm_reopen', $formquestion, 'yes', 1);
  307. }
  308. // Refuse confirmation
  309. if ($action == 'refuse') {
  310. //Form to close proposal (signed or not)
  311. $formquestion = array(
  312. array('type' => 'text', 'name' => 'reason_decline_or_cancel', 'label' => $langs->trans("Note"), 'morecss' => 'reason_decline_or_cancel minwidth400', 'value' => '') // Field to complete private note (not replace)
  313. );
  314. // if (isModEnabled('notification')) {
  315. // require_once DOL_DOCUMENT_ROOT.'/core/class/notify.class.php';
  316. // $notify = new Notify($db);
  317. // $formquestion = array_merge($formquestion, array(
  318. // array('type' => 'onecolumn', 'value' => $notify->confirmMessage('PARTNERSHIP_CLOSE_DENY', $object->socid, $object)),
  319. // ));
  320. // }
  321. $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('ToRefuse'), '', 'confirm_refuse', $formquestion, '', 1, 250);
  322. }
  323. // Call Hook formConfirm
  324. $parameters = array('formConfirm' => $formconfirm, 'lineid' => $lineid);
  325. $reshook = $hookmanager->executeHooks('formConfirm', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
  326. if (empty($reshook)) {
  327. $formconfirm .= $hookmanager->resPrint;
  328. } elseif ($reshook > 0) {
  329. $formconfirm = $hookmanager->resPrint;
  330. }
  331. // Print form confirm
  332. print $formconfirm;
  333. // Object card
  334. // ------------------------------------------------------------
  335. $linkback = '<a href="'.dol_buildpath('/partnership/partnership_list.php', 1).'?restore_lastsearch_values=1'.(!empty($socid) ? '&socid='.$socid : '').'">'.$langs->trans("BackToList").'</a>';
  336. $morehtmlref = '<div class="refidno">';
  337. /*
  338. // Ref customer
  339. $morehtmlref .= $form->editfieldkey("RefCustomer", 'ref_client', $object->ref_client, $object, 0, 'string', '', 0, 1);
  340. $morehtmlref .= $form->editfieldval("RefCustomer", 'ref_client', $object->ref_client, $object, 0, 'string', '', null, null, '', 1);
  341. // Thirdparty
  342. $morehtmlref .= '<br>'.$object->thirdparty->getNomUrl(1, 'customer');
  343. if (empty($conf->global->MAIN_DISABLE_OTHER_LINK) && $object->thirdparty->id > 0) {
  344. $morehtmlref .= ' (<a href="'.DOL_URL_ROOT.'/commande/list.php?socid='.$object->thirdparty->id.'&search_societe='.urlencode($object->thirdparty->name).'">'.$langs->trans("OtherOrders").'</a>)';
  345. }
  346. // Project
  347. if (isModEnabled('project')) {
  348. $langs->load("projects");
  349. $morehtmlref .= '<br>';
  350. if ($permissiontoadd) {
  351. $morehtmlref .= img_picto($langs->trans("Project"), 'project', 'class="pictofixedwidth"');
  352. if ($action != 'classify') {
  353. $morehtmlref .= '<a class="editfielda" href="'.$_SERVER['PHP_SELF'].'?action=classify&token='.newToken().'&id='.$object->id.'">'.img_edit($langs->transnoentitiesnoconv('SetProject')).'</a> ';
  354. }
  355. $morehtmlref .= $form->form_project($_SERVER['PHP_SELF'].'?id='.$object->id, $object->socid, $object->fk_project, ($action == 'classify' ? 'projectid' : 'none'), 0, 0, 0, 1, '', 'maxwidth300');
  356. } else {
  357. if (!empty($object->fk_project)) {
  358. $proj = new Project($db);
  359. $proj->fetch($object->fk_project);
  360. $morehtmlref .= $proj->getNomUrl(1);
  361. if ($proj->title) {
  362. $morehtmlref .= '<span class="opacitymedium"> - '.dol_escape_htmltag($proj->title).'</span>';
  363. }
  364. }
  365. }
  366. }
  367. */
  368. $morehtmlref .= '</div>';
  369. if (!isset($npfilter)) {
  370. $npfilter = "";
  371. }
  372. if ($managedfor == 'member') $npfilter .= " AND te.fk_member > 0 "; else $npfilter .= " AND te.fk_soc > 0 ";
  373. $object->next_prev_filter = $npfilter;
  374. dol_banner_tab($object, 'ref', $linkback, 1, 'ref', 'ref', $morehtmlref);
  375. print '<div class="fichecenter">';
  376. print '<div class="fichehalfleft">';
  377. print '<div class="underbanner clearboth"></div>';
  378. print '<table class="border centpercent tableforfield">'."\n";
  379. // Common attributes
  380. //$keyforbreak='fieldkeytoswitchonsecondcolumn'; // We change column just before this field
  381. //unset($object->fields['fk_project']); // Hide field already shown in banner
  382. //unset($object->fields['fk_soc']); // Hide field already shown in banner
  383. include DOL_DOCUMENT_ROOT.'/core/tpl/commonfields_view.tpl.php';
  384. // End of subscription date
  385. if ($managedfor == 'member') {
  386. $fadherent = new Adherent($db);
  387. $fadherent->fetch($object->fk_member);
  388. print '<tr><td>'.$langs->trans("SubscriptionEndDate").'</td><td class="valeur">';
  389. if ($fadherent->datefin) {
  390. print dol_print_date($fadherent->datefin, 'day');
  391. if ($fadherent->hasDelay()) {
  392. print " ".img_warning($langs->trans("Late"));
  393. }
  394. } else {
  395. if (!$adht->subscription) {
  396. print $langs->trans("SubscriptionNotRecorded");
  397. if ($fadherent->statut > 0) {
  398. print " ".img_warning($langs->trans("Late")); // Display a delay picto only if it is not a draft and is not canceled
  399. }
  400. } else {
  401. print $langs->trans("SubscriptionNotReceived");
  402. if ($fadherent->statut > 0) {
  403. print " ".img_warning($langs->trans("Late")); // Display a delay picto only if it is not a draft and is not canceled
  404. }
  405. }
  406. }
  407. print '</td></tr>';
  408. }
  409. // Other attributes. Fields from hook formObjectOptions and Extrafields.
  410. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_view.tpl.php';
  411. print '</table>';
  412. print '</div>';
  413. print '</div>';
  414. print '<div class="clearboth"></div>';
  415. print dol_get_fiche_end();
  416. /*
  417. * Lines
  418. */
  419. if (!empty($object->table_element_line)) {
  420. // Show object lines
  421. $result = $object->getLinesArray();
  422. print ' <form name="addproduct" id="addproduct" action="'.$_SERVER["PHP_SELF"].'?id='.$object->id.(($action != 'editline') ? '' : '#line_'.GETPOST('lineid', 'int')).'" method="POST">
  423. <input type="hidden" name="token" value="' . newToken().'">
  424. <input type="hidden" name="action" value="' . (($action != 'editline') ? 'addline' : 'updateline').'">
  425. <input type="hidden" name="mode" value="">
  426. <input type="hidden" name="page_y" value="">
  427. <input type="hidden" name="id" value="' . $object->id.'">
  428. ';
  429. if (!empty($conf->use_javascript_ajax) && $object->status == 0) {
  430. include DOL_DOCUMENT_ROOT.'/core/tpl/ajaxrow.tpl.php';
  431. }
  432. print '<div class="div-table-responsive-no-min">';
  433. if (!empty($object->lines) || ($object->status == $object::STATUS_DRAFT && $permissiontoadd && $action != 'selectlines' && $action != 'editline')) {
  434. print '<table id="tablelines" class="noborder noshadow" width="100%">';
  435. }
  436. if (!empty($object->lines)) {
  437. $object->printObjectLines($action, $mysoc, null, GETPOST('lineid', 'int'), 1);
  438. }
  439. // Form to add new line
  440. if ($object->status == 0 && $permissiontoadd && $action != 'selectlines') {
  441. if ($action != 'editline') {
  442. // Add products/services form
  443. $parameters = array();
  444. $reshook = $hookmanager->executeHooks('formAddObjectLine', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
  445. if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
  446. if (empty($reshook))
  447. $object->formAddObjectLine(1, $mysoc, $soc);
  448. }
  449. }
  450. if (!empty($object->lines) || ($object->status == $object::STATUS_DRAFT && $permissiontoadd && $action != 'selectlines' && $action != 'editline')) {
  451. print '</table>';
  452. }
  453. print '</div>';
  454. print "</form>\n";
  455. }
  456. // Buttons for actions
  457. if ($action != 'presend' && $action != 'editline') {
  458. print '<div class="tabsAction">'."\n";
  459. $parameters = array();
  460. $reshook = $hookmanager->executeHooks('addMoreActionsButtons', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
  461. if ($reshook < 0) {
  462. setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
  463. }
  464. if (empty($reshook)) {
  465. // Send
  466. if (empty($user->socid)) {
  467. print dolGetButtonAction('', $langs->trans('SendMail'), 'default', $_SERVER["PHP_SELF"].'?id='.$object->id.'&action=presend&token='.newToken().'&mode=init#formmailbeforetitle');
  468. }
  469. print dolGetButtonAction('', $langs->trans('Modify'), 'default', $_SERVER["PHP_SELF"].'?id='.$object->id.'&action=edit&token='.newToken(), '', $permissiontoadd);
  470. // Back to draft
  471. if ($object->status != $object::STATUS_DRAFT) {
  472. print dolGetButtonAction('', $langs->trans('SetToDraft'), 'default', $_SERVER["PHP_SELF"].'?id='.$object->id.'&action=confirm_setdraft&confirm=yes&token='.newToken(), '', $permissiontoadd);
  473. }
  474. // Validate
  475. if ($object->status == $object::STATUS_DRAFT) {
  476. if (empty($object->table_element_line) || (is_array($object->lines) && count($object->lines) > 0)) {
  477. print dolGetButtonAction('', $langs->trans('Validate'), 'default', $_SERVER['PHP_SELF'].'?id='.$object->id.'&action=confirm_validate&confirm=yes&token='.newToken(), '', $permissiontoadd);
  478. } else {
  479. $langs->load("errors");
  480. print dolGetButtonAction($langs->trans("ErrorAddAtLeastOneLineFirst"), $langs->trans("Validate"), 'default', '#', '', 0);
  481. }
  482. }
  483. // Approve
  484. if ($object->status == $object::STATUS_VALIDATED) {
  485. if (empty($object->table_element_line) || (is_array($object->lines) && count($object->lines) > 0)) {
  486. print dolGetButtonAction($langs->trans('Approve'), '', 'default', $_SERVER['PHP_SELF'].'?id='.$object->id.'&action=confirm_accept&confirm=yes&token='.newToken(), '', $permissiontoadd);
  487. } else {
  488. $langs->load("errors");
  489. print dolGetButtonAction($langs->trans("ErrorAddAtLeastOneLineFirst"), $langs->trans("Approved"), 'default', '#', '', 0);
  490. }
  491. }
  492. // Cancel
  493. if ($permissiontoadd) {
  494. if ($object->status == $object::STATUS_APPROVED) {
  495. print dolGetButtonAction($langs->trans('Resiliate'), '', 'default', $_SERVER["PHP_SELF"].'?id='.$object->id.'&action=close&token='.newToken(), '', $permissiontoadd);
  496. } elseif ($object->status > $object::STATUS_APPROVED) {
  497. // print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&action=reopen&token='.newToken().'">'.$langs->trans("Re-Open").'</a>'."\n";
  498. print dolGetButtonAction($langs->trans('Re-Open'), '', 'default', $_SERVER["PHP_SELF"].'?id='.$object->id.'&action=confirm_reopen&confirm=yes&token='.newToken(), '', $permissiontoadd);
  499. }
  500. }
  501. // Refuse
  502. if ($permissiontoadd) {
  503. if ($object->status != $object::STATUS_DRAFT && $object->status != $object::STATUS_APPROVED && $object->status != $object::STATUS_CANCELED && $object->status != $object::STATUS_REFUSED) {
  504. print dolGetButtonAction($langs->trans('Refuse'), '', 'default', $_SERVER['PHP_SELF'].'?id='.$object->id.'&action=refuse&token='.newToken(), '', $permissiontoadd);
  505. }
  506. }
  507. // Delete (need delete permission, or if draft, just need create/modify permission)
  508. print dolGetButtonAction($langs->trans('Delete'), '', 'delete', $_SERVER['PHP_SELF'].'?id='.$object->id.'&action=delete&token='.newToken(), '', $permissiontodelete || ($object->status == $object::STATUS_DRAFT && $permissiontoadd));
  509. }
  510. print '</div>'."\n";
  511. }
  512. // Select mail models is same action as presend
  513. if (GETPOST('modelselected')) {
  514. $action = 'presend';
  515. }
  516. if ($action != 'presend') {
  517. print '<div class="fichecenter"><div class="fichehalfleft">';
  518. print '<a name="builddoc"></a>'; // ancre
  519. $includedocgeneration = 0;
  520. // Documents
  521. if ($includedocgeneration) {
  522. $objref = dol_sanitizeFileName($object->ref);
  523. $relativepath = $objref.'/'.$objref.'.pdf';
  524. $filedir = $conf->partnership->dir_output.'/'.$object->element.'/'.$objref;
  525. $urlsource = $_SERVER["PHP_SELF"]."?id=".$object->id;
  526. $genallowed = $permissiontoread; // If you can read, you can build the PDF to read content
  527. $delallowed = $permissiontoadd; // If you can create/edit, you can remove a file on card
  528. print $formfile->showdocuments('partnership:Partnership', $object->element.'/'.$objref, $filedir, $urlsource, $genallowed, $delallowed, $object->model_pdf, 1, 0, 0, 28, 0, '', '', '', $langs->defaultlang);
  529. }
  530. // Show links to link elements
  531. $linktoelem = $form->showLinkToObjectBlock($object, null, array('partnership'));
  532. $somethingshown = $form->showLinkedObjectBlock($object, $linktoelem);
  533. print '</div><div class="fichehalfright">';
  534. $MAXEVENT = 10;
  535. $morehtmlcenter = dolGetButtonTitle($langs->trans('SeeAll'), '', 'fa fa-bars imgforviewmode', DOL_URL_ROOT.'/partnership/partnership_agenda.php?id='.$object->id);
  536. // List of actions on element
  537. include_once DOL_DOCUMENT_ROOT.'/core/class/html.formactions.class.php';
  538. $formactions = new FormActions($db);
  539. $somethingshown = $formactions->showactions($object, $object->element.'@'.$object->module, (is_object($object->thirdparty) ? $object->thirdparty->id : 0), 1, '', $MAXEVENT, '', $morehtmlcenter);
  540. print '</div></div>';
  541. }
  542. //Select mail models is same action as presend
  543. if (GETPOST('modelselected')) {
  544. $action = 'presend';
  545. }
  546. // Presend form
  547. $modelmail = 'partnership_send';
  548. $defaulttopic = 'InformationMessage';
  549. $diroutput = $conf->partnership->dir_output;
  550. $trackid = 'pship'.$object->id;
  551. include DOL_DOCUMENT_ROOT.'/core/tpl/card_presend.tpl.php';
  552. }
  553. // End of page
  554. llxFooter();
  555. $db->close();