partnership_card.php 26 KB

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