PageRenderTime 39ms CodeModel.GetById 13ms RepoModel.GetById 0ms app.codeStats 0ms

/htdocs/societe/partnership.php

https://github.com/Dolibarr/dolibarr
PHP | 274 lines | 168 code | 60 blank | 46 comment | 57 complexity | 2313a02b47425d5c2c128886e1f4aaa7 MD5 | raw file
  1. <?php
  2. /* Copyright (C) 2017 Laurent Destailleur <eldy@users.sourceforge.net>
  3. * Copyright (C) 2021 NextGestion <contact@nextgestion.com>
  4. * Copyright (C) 2022 Charlene Benke <charlent@patas-monkey.com>
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; either version 3 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  18. */
  19. /**
  20. * \file partnership_card.php
  21. * \ingroup partnership
  22. * \brief Page to create/edit/view partnership
  23. */
  24. // Load Dolibarr environment
  25. require '../main.inc.php';
  26. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formcompany.class.php';
  27. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
  28. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formprojet.class.php';
  29. require_once DOL_DOCUMENT_ROOT.'/societe/class/societe.class.php';
  30. require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
  31. require_once DOL_DOCUMENT_ROOT.'/partnership/class/partnership.class.php';
  32. require_once DOL_DOCUMENT_ROOT.'/partnership/lib/partnership.lib.php';
  33. // Load translation files required by the page
  34. $langs->loadLangs(array("companies", "partnership", "other"));
  35. // Get parameters
  36. $id = GETPOST('id', 'int');
  37. $ref = GETPOST('ref', 'alpha');
  38. $action = GETPOST('action', 'aZ09');
  39. $confirm = GETPOST('confirm', 'alpha');
  40. $cancel = GETPOST('cancel', 'aZ09');
  41. $contextpage = GETPOST('contextpage', 'aZ') ? GETPOST('contextpage', 'aZ') : 'partnershipcard'; // To manage different context of search
  42. $backtopage = GETPOST('backtopage', 'alpha');
  43. $backtopageforcancel = GETPOST('backtopageforcancel', 'alpha');
  44. //$lineid = GETPOST('lineid', 'int');
  45. // Security check
  46. $socid = GETPOST('socid', 'int');
  47. if (!empty($user->socid)) {
  48. $socid = $user->socid;
  49. }
  50. if (empty($id) && $socid && (getDolGlobalString('PARTNERSHIP_IS_MANAGED_FOR', 'thirdparty') == 'thirdparty')) {
  51. $id = $socid;
  52. }
  53. $object = new Societe($db);
  54. if ($id > 0) {
  55. $object->fetch($id);
  56. }
  57. // Initialize technical objects
  58. $object = new Partnership($db);
  59. $extrafields = new ExtraFields($db);
  60. $diroutputmassaction = $conf->partnership->dir_output.'/temp/massgeneration/'.$user->id;
  61. $hookmanager->initHooks(array('thirdpartypartnership', 'globalcard')); // Note that conf->hooks_modules contains array
  62. // Fetch optionals attributes and labels
  63. $extrafields->fetch_name_optionals_label($object->table_element);
  64. $search_array_options = $extrafields->getOptionalsFromPost($object->table_element, '', 'search_');
  65. // Initialize array of search criterias
  66. $search_all = GETPOST("search_all", 'alpha');
  67. $search = array();
  68. foreach ($object->fields as $key => $val) {
  69. if (GETPOST('search_'.$key, 'alpha')) {
  70. $search[$key] = GETPOST('search_'.$key, 'alpha');
  71. }
  72. }
  73. // Load object
  74. include DOL_DOCUMENT_ROOT.'/core/actions_fetchobject.inc.php'; // Must be include, not include_once.
  75. $permissiontoread = $user->rights->partnership->read;
  76. $permissiontoadd = $user->rights->partnership->write; // Used by the include of actions_addupdatedelete.inc.php and actions_lineupdown.inc.php
  77. $permissiontodelete = $user->rights->partnership->delete || ($permissiontoadd && isset($object->status) && $object->status == $object::STATUS_DRAFT);
  78. $permissionnote = $user->rights->partnership->write; // Used by the include of actions_setnotes.inc.php
  79. $permissiondellink = $user->rights->partnership->write; // Used by the include of actions_dellink.inc.php
  80. $usercanclose = $user->rights->partnership->write; // Used by the include of actions_addupdatedelete.inc.php and actions_lineupdown.inc.php
  81. $upload_dir = $conf->partnership->multidir_output[isset($object->entity) ? $object->entity : 1];
  82. if (getDolGlobalString('PARTNERSHIP_IS_MANAGED_FOR', 'thirdparty') != 'thirdparty') {
  83. accessforbidden('Partnership is not activated for thirdparties');
  84. }
  85. if (empty($conf->partnership->enabled)) {
  86. accessforbidden();
  87. }
  88. if (empty($permissiontoread)) {
  89. accessforbidden();
  90. }
  91. if ($action == 'edit' && empty($permissiontoadd)) {
  92. accessforbidden();
  93. }
  94. if (($action == 'update' || $action == 'edit') && $object->status != $object::STATUS_DRAFT && !empty($user->socid)) {
  95. accessforbidden();
  96. }
  97. // Security check
  98. $result = restrictedArea($user, 'societe', $id, '&societe', '', 'fk_soc', 'rowid', 0);
  99. /*
  100. * Actions
  101. */
  102. $parameters = array();
  103. $reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
  104. if ($reshook < 0) {
  105. setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
  106. }
  107. $date_start = dol_mktime(0, 0, 0, GETPOST('date_partnership_startmonth', 'int'), GETPOST('date_partnership_startday', 'int'), GETPOST('date_partnership_startyear', 'int'));
  108. $date_end = dol_mktime(0, 0, 0, GETPOST('date_partnership_endmonth', 'int'), GETPOST('date_partnership_endday', 'int'), GETPOST('date_partnership_endyear', 'int'));
  109. if (empty($reshook)) {
  110. $error = 0;
  111. $backtopage = DOL_URL_ROOT.'/partnership/partnership.php?id='.($id > 0 ? $id : '__ID__');
  112. // Actions when linking object each other
  113. include DOL_DOCUMENT_ROOT.'/core/actions_dellink.inc.php';
  114. }
  115. $object->fields['fk_soc']['visible'] = 0;
  116. if ($object->id > 0 && $object->status == $object::STATUS_REFUSED && empty($action)) {
  117. $object->fields['reason_decline_or_cancel']['visible'] = 1;
  118. }
  119. $object->fields['note_public']['visible'] = 1;
  120. /*
  121. * View
  122. */
  123. $form = new Form($db);
  124. $formfile = new FormFile($db);
  125. $title = $langs->trans("Partnership");
  126. llxHeader('', $title);
  127. $form = new Form($db);
  128. if ($id > 0) {
  129. $langs->load("companies");
  130. $object = new Societe($db);
  131. $result = $object->fetch($id);
  132. if (!empty($conf->notification->enabled)) {
  133. $langs->load("mails");
  134. }
  135. $head = societe_prepare_head($object);
  136. print dol_get_fiche_head($head, 'partnership', $langs->trans("ThirdParty"), -1, 'company');
  137. $linkback = '<a href="'.DOL_URL_ROOT.'/societe/list.php?restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>';
  138. dol_banner_tab($object, 'socid', $linkback, ($user->socid ? 0 : 1), 'rowid', 'nom');
  139. print '<div class="fichecenter">';
  140. print '<div class="underbanner clearboth"></div>';
  141. print '<table class="border centpercent tableforfield">';
  142. if (!empty($conf->global->SOCIETE_USEPREFIX)) { // Old not used prefix field
  143. print '<tr><td>'.$langs->trans('Prefix').'</td><td colspan="3">'.$object->prefix_comm.'</td></tr>';
  144. }
  145. if ($object->client) {
  146. print '<tr><td class="titlefield">';
  147. print $langs->trans('CustomerCode').'</td><td colspan="3">';
  148. print showValueWithClipboardCPButton(dol_escape_htmltag($object->code_client));
  149. $tmpcheck = $object->check_codeclient();
  150. if ($tmpcheck != 0 && $tmpcheck != -5) {
  151. print ' <span class="error">('.$langs->trans("WrongCustomerCode").')</span>';
  152. }
  153. print '</td></tr>';
  154. }
  155. if ($object->fournisseur) {
  156. print '<tr><td class="titlefield">';
  157. print $langs->trans('SupplierCode').'</td><td colspan="3">';
  158. print showValueWithClipboardCPButton(dol_escape_htmltag($object->code_fournisseur));
  159. $tmpcheck = $object->check_codefournisseur();
  160. if ($tmpcheck != 0 && $tmpcheck != -5) {
  161. print ' <span class="error">('.$langs->trans("WrongSupplierCode").')</span>';
  162. }
  163. print '</td>';
  164. print '</tr>';
  165. }
  166. print '</table>';
  167. print '</div>';
  168. print dol_get_fiche_end();
  169. } else {
  170. dol_print_error('', 'Parameter id not defined');
  171. }
  172. // Part to show record
  173. if ($object->id > 0 && (empty($action) || ($action != 'edit' && $action != 'create'))) {
  174. // Buttons for actions
  175. if ($action != 'presend') {
  176. print '<div class="tabsAction">'."\n";
  177. $parameters = array();
  178. $reshook = $hookmanager->executeHooks('addMoreActionsButtons', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
  179. if ($reshook < 0) {
  180. setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
  181. }
  182. if (empty($reshook)) {
  183. // Show
  184. if ($permissiontoadd) {
  185. print dolGetButtonAction($langs->trans('AddPartnership'), '', 'default', DOL_URL_ROOT.'/partnership/partnership_card.php?action=create&fk_soc='.$object->id.'&backtopage='.urlencode(DOL_URL_ROOT.'/societe/partnership.php?id='.$object->id), '', $permissiontoadd);
  186. }
  187. }
  188. print '</div>'."\n";
  189. }
  190. //$morehtmlright = 'partnership/partnership_card.php?action=create&backtopage=%2Fdolibarr%2Fhtdocs%2Fpartnership%2Fpartnership_list.php';
  191. $morehtmlright = '';
  192. print load_fiche_titre($langs->trans("PartnershipDedicatedToThisThirdParty", $langs->transnoentitiesnoconv("Partnership")), $morehtmlright, '');
  193. $socid = $object->id;
  194. // TODO Replace this card with a table of list of all partnerships.
  195. $object = new Partnership($db);
  196. $partnershipid = $object->fetch(0, '', 0, $socid);
  197. if ($partnershipid > 0) {
  198. print '<div class="fichecenter">';
  199. print '<div class="fichehalfleft">';
  200. print '<div class="underbanner clearboth"></div>';
  201. print '<table class="border centpercent tableforfield">'."\n";
  202. // Common attributes
  203. unset($object->fields['fk_soc']); // Hide field already shown in banner
  204. include DOL_DOCUMENT_ROOT.'/core/tpl/commonfields_view.tpl.php';
  205. $forcefieldid = 'socid';
  206. $forceobjectid = $object->fk_soc;
  207. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_view.tpl.php';
  208. print '</table>';
  209. print '</div>';
  210. }
  211. }
  212. // End of page
  213. llxFooter();
  214. $db->close();