partnership.php 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280
  1. <?php
  2. /* Copyright (C) 2017 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.formfile.class.php';
  26. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formprojet.class.php';
  27. require_once DOL_DOCUMENT_ROOT.'/core/lib/member.lib.php';
  28. require_once DOL_DOCUMENT_ROOT.'/adherents/class/adherent.class.php';
  29. require_once DOL_DOCUMENT_ROOT.'/adherents/class/adherent_type.class.php';
  30. require_once DOL_DOCUMENT_ROOT.'/partnership/class/partnership.class.php';
  31. require_once DOL_DOCUMENT_ROOT.'/partnership/lib/partnership.lib.php';
  32. // Load translation files required by the page
  33. $langs->loadLangs(array("companies","members","partnership", "other"));
  34. // Get parameters
  35. $id = GETPOST('rowid', 'int') ? GETPOST('rowid', 'int') : GETPOST('id', 'int');
  36. $ref = GETPOST('ref', 'alpha');
  37. $action = GETPOST('action', 'aZ09');
  38. $confirm = GETPOST('confirm', 'alpha');
  39. $cancel = GETPOST('cancel', 'aZ09');
  40. $contextpage = GETPOST('contextpage', 'aZ') ? GETPOST('contextpage', 'aZ') : 'partnershipcard'; // To manage different context of search
  41. $backtopage = GETPOST('backtopage', 'alpha');
  42. $backtopageforcancel = GETPOST('backtopageforcancel', 'alpha');
  43. //$lineid = GETPOST('lineid', 'int');
  44. $object = new Adherent($db);
  45. if ($id > 0) {
  46. $object->fetch($id);
  47. }
  48. // Initialize technical objects
  49. $object = new Partnership($db);
  50. $extrafields = new ExtraFields($db);
  51. $adht = new AdherentType($db);
  52. $diroutputmassaction = $conf->partnership->dir_output.'/temp/massgeneration/'.$user->id;
  53. $hookmanager->initHooks(array('partnershipthirdparty', 'globalcard')); // Note that conf->hooks_modules contains array
  54. // Fetch optionals attributes and labels
  55. $extrafields->fetch_name_optionals_label($object->table_element);
  56. $search_array_options = $extrafields->getOptionalsFromPost($object->table_element, '', 'search_');
  57. // Initialize array of search criterias
  58. $search_all = GETPOST("search_all", 'alpha');
  59. $search = array();
  60. foreach ($object->fields as $key => $val) {
  61. if (GETPOST('search_'.$key, 'alpha')) {
  62. $search[$key] = GETPOST('search_'.$key, 'alpha');
  63. }
  64. }
  65. // Load object
  66. include DOL_DOCUMENT_ROOT.'/core/actions_fetchobject.inc.php'; // Must be include, not include_once.
  67. $permissiontoread = $user->hasRight('partnership', 'read');
  68. $permissiontoadd = $user->hasRight('partnership', 'write'); // Used by the include of actions_addupdatedelete.inc.php and actions_lineupdown.inc.php
  69. $permissiontodelete = $user->hasRight('partnership', 'delete') || ($permissiontoadd && isset($object->status) && $object->status == $object::STATUS_DRAFT);
  70. $permissionnote = $user->hasRight('partnership', 'write'); // Used by the include of actions_setnotes.inc.php
  71. $permissiondellink = $user->hasRight('partnership', 'write'); // Used by the include of actions_dellink.inc.php
  72. $usercanclose = $user->hasRight('partnership', 'write'); // Used by the include of actions_addupdatedelete.inc.php and actions_lineupdown.inc.php
  73. $upload_dir = $conf->partnership->multidir_output[isset($object->entity) ? $object->entity : 1];
  74. if (getDolGlobalString('PARTNERSHIP_IS_MANAGED_FOR') != 'member') {
  75. accessforbidden('Partnership module is not activated for members');
  76. }
  77. if (!isModEnabled('partnership')) {
  78. accessforbidden();
  79. }
  80. if (empty($permissiontoread)) {
  81. accessforbidden();
  82. }
  83. if ($action == 'edit' && empty($permissiontoadd)) {
  84. accessforbidden();
  85. }
  86. if (($action == 'update' || $action == 'edit') && $object->status != $object::STATUS_DRAFT) {
  87. accessforbidden();
  88. }
  89. // Security check
  90. $result = restrictedArea($user, 'adherent', $id, '', '', 'socid', 'rowid', 0);
  91. /*
  92. * Actions
  93. */
  94. $parameters = array();
  95. $reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
  96. if ($reshook < 0) {
  97. setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
  98. }
  99. $date_start = dol_mktime(0, 0, 0, GETPOST('date_partnership_startmonth', 'int'), GETPOST('date_partnership_startday', 'int'), GETPOST('date_partnership_startyear', 'int'));
  100. $date_end = dol_mktime(0, 0, 0, GETPOST('date_partnership_endmonth', 'int'), GETPOST('date_partnership_endday', 'int'), GETPOST('date_partnership_endyear', 'int'));
  101. if (empty($reshook)) {
  102. $error = 0;
  103. $backtopage = dol_buildpath('/partnership/partnership.php', 1).'?rowid='.($id > 0 ? $id : '__ID__');
  104. // Actions when linking object each other
  105. include DOL_DOCUMENT_ROOT.'/core/actions_dellink.inc.php';
  106. }
  107. $object->fields['fk_member']['visible'] = 0;
  108. if ($object->id > 0 && $object->status == $object::STATUS_REFUSED && empty($action)) $object->fields['reason_decline_or_cancel']['visible'] = 1;
  109. $object->fields['note_public']['visible'] = 1;
  110. /*
  111. * View
  112. */
  113. $form = new Form($db);
  114. $formfile = new FormFile($db);
  115. $title = $langs->trans("Partnership");
  116. llxHeader('', $title);
  117. $form = new Form($db);
  118. if ($id > 0) {
  119. $langs->load("members");
  120. $object = new Adherent($db);
  121. $result = $object->fetch($id);
  122. if (isModEnabled('notification')) {
  123. $langs->load("mails");
  124. }
  125. $adht->fetch($object->typeid);
  126. $head = member_prepare_head($object);
  127. print dol_get_fiche_head($head, 'partnership', $langs->trans("ThirdParty"), -1, 'user');
  128. $linkback = '<a href="'.DOL_URL_ROOT.'/adherents/list.php?restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>';
  129. dol_banner_tab($object, 'rowid', $linkback);
  130. print '<div class="fichecenter">';
  131. print '<div class="underbanner clearboth"></div>';
  132. print '<table class="border centpercent tableforfield">';
  133. // Login
  134. if (empty($conf->global->ADHERENT_LOGIN_NOT_REQUIRED)) {
  135. print '<tr><td class="titlefield">'.$langs->trans("Login").' / '.$langs->trans("Id").'</td><td class="valeur">'.$object->login.'&nbsp;</td></tr>';
  136. }
  137. // Type
  138. print '<tr><td class="titlefield">'.$langs->trans("Type").'</td><td class="valeur">'.$adht->getNomUrl(1)."</td></tr>\n";
  139. // Morphy
  140. print '<tr><td>'.$langs->trans("MemberNature").'</td><td class="valeur" >'.$object->getmorphylib().'</td>';
  141. print '</tr>';
  142. // Company
  143. print '<tr><td>'.$langs->trans("Company").'</td><td class="valeur">'.$object->company.'</td></tr>';
  144. // Civility
  145. print '<tr><td>'.$langs->trans("UserTitle").'</td><td class="valeur">'.$object->getCivilityLabel().'&nbsp;</td>';
  146. print '</tr>';
  147. print '</table>';
  148. print '</div>';
  149. print dol_get_fiche_end();
  150. } else {
  151. dol_print_error('', 'Parameter rowid not defined');
  152. }
  153. // Part to show record
  154. if ($object->id > 0 && (empty($action) || ($action != 'edit' && $action != 'create'))) {
  155. // Buttons for actions
  156. if ($action != 'presend') {
  157. print '<div class="tabsAction">'."\n";
  158. $parameters = array();
  159. $reshook = $hookmanager->executeHooks('addMoreActionsButtons', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
  160. if ($reshook < 0) {
  161. setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
  162. }
  163. if (empty($reshook)) {
  164. // Show
  165. if ($permissiontoadd) {
  166. print dolGetButtonAction($langs->trans('AddPartnership'), '', 'default', DOL_URL_ROOT.'/partnership/partnership_card.php?action=create&fk_member='.$object->id.'&backtopage='.urlencode(DOL_URL_ROOT.'/adherents/partnership.php?id='.$object->id), '', $permissiontoadd);
  167. }
  168. }
  169. print '</div>'."\n";
  170. }
  171. //$morehtmlright = 'partnership/partnership_card.php?action=create&backtopage=%2Fdolibarr%2Fhtdocs%2Fpartnership%2Fpartnership_list.php';
  172. $morehtmlright = '';
  173. print load_fiche_titre($langs->trans("PartnershipDedicatedToThisMember", $langs->transnoentitiesnoconv("Partnership")), $morehtmlright, '');
  174. $memberid = $object->id;
  175. // TODO Replace this card with the list of all partnerships.
  176. $object = new Partnership($db);
  177. $partnershipid = $object->fetch(0, "", $memberid);
  178. if ($partnershipid > 0) {
  179. print '<div class="fichecenter">';
  180. print '<div class="fichehalfleft">';
  181. print '<div class="underbanner clearboth"></div>';
  182. print '<table class="border centpercent tableforfield">'."\n";
  183. // Common attributes
  184. //$keyforbreak='fieldkeytoswitchonsecondcolumn'; // We change column just before this field
  185. //unset($object->fields['fk_project']); // Hide field already shown in banner
  186. //unset($object->fields['fk_member']); // Hide field already shown in banner
  187. include DOL_DOCUMENT_ROOT.'/core/tpl/commonfields_view.tpl.php';
  188. // End of subscription date
  189. $fadherent = new Adherent($db);
  190. $fadherent->fetch($object->fk_member);
  191. print '<tr><td>'.$langs->trans("SubscriptionEndDate").'</td><td class="valeur">';
  192. if ($fadherent->datefin) {
  193. print dol_print_date($fadherent->datefin, 'day');
  194. if ($fadherent->hasDelay()) {
  195. print " ".img_warning($langs->trans("Late"));
  196. }
  197. } else {
  198. if (!$adht->subscription) {
  199. print $langs->trans("SubscriptionNotRecorded");
  200. if ($fadherent->statut > 0) {
  201. print " ".img_warning($langs->trans("Late")); // Display a delay picto only if it is not a draft and is not canceled
  202. }
  203. } else {
  204. print $langs->trans("SubscriptionNotReceived");
  205. if ($fadherent->statut > 0) {
  206. print " ".img_warning($langs->trans("Late")); // Display a delay picto only if it is not a draft and is not canceled
  207. }
  208. }
  209. }
  210. print '</td></tr>';
  211. print '</table>';
  212. print '</div>';
  213. }
  214. }
  215. // End of page
  216. llxFooter();
  217. $db->close();