dolibarr  16.0.5
partnership.php
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 
25 // Load Dolibarr environment
26 require '../main.inc.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.'/core/lib/member.lib.php';
30 require_once DOL_DOCUMENT_ROOT.'/adherents/class/adherent.class.php';
31 require_once DOL_DOCUMENT_ROOT.'/adherents/class/adherent_type.class.php';
32 require_once DOL_DOCUMENT_ROOT.'/partnership/class/partnership.class.php';
33 require_once DOL_DOCUMENT_ROOT.'/partnership/lib/partnership.lib.php';
34 
35 // Load translation files required by the page
36 $langs->loadLangs(array("companies","members","partnership", "other"));
37 
38 // Get parameters
39 $id = GETPOST('rowid', 'int') ? GETPOST('rowid', 'int') : GETPOST('id', 'int');
40 $ref = GETPOST('ref', 'alpha');
41 $action = GETPOST('action', 'aZ09');
42 $confirm = GETPOST('confirm', 'alpha');
43 $cancel = GETPOST('cancel', 'aZ09');
44 $contextpage = GETPOST('contextpage', 'aZ') ? GETPOST('contextpage', 'aZ') : 'partnershipcard'; // To manage different context of search
45 $backtopage = GETPOST('backtopage', 'alpha');
46 $backtopageforcancel = GETPOST('backtopageforcancel', 'alpha');
47 //$lineid = GETPOST('lineid', 'int');
48 
49 $object = new Adherent($db);
50 if ($id > 0) {
51  $object->fetch($id);
52 }
53 
54 // Initialize technical objects
55 $object = new Partnership($db);
56 $extrafields = new ExtraFields($db);
57 $adht = new AdherentType($db);
58 $diroutputmassaction = $conf->partnership->dir_output.'/temp/massgeneration/'.$user->id;
59 $hookmanager->initHooks(array('partnershipthirdparty', 'globalcard')); // Note that conf->hooks_modules contains array
60 
61 // Fetch optionals attributes and labels
62 $extrafields->fetch_name_optionals_label($object->table_element);
63 
64 $search_array_options = $extrafields->getOptionalsFromPost($object->table_element, '', 'search_');
65 
66 // Initialize array of search criterias
67 $search_all = GETPOST("search_all", 'alpha');
68 $search = array();
69 
70 foreach ($object->fields as $key => $val) {
71  if (GETPOST('search_'.$key, 'alpha')) {
72  $search[$key] = GETPOST('search_'.$key, 'alpha');
73  }
74 }
75 
76 // Load object
77 include DOL_DOCUMENT_ROOT.'/core/actions_fetchobject.inc.php'; // Must be include, not include_once.
78 
79 $permissiontoread = $user->rights->partnership->read;
80 $permissiontoadd = $user->rights->partnership->write; // Used by the include of actions_addupdatedelete.inc.php and actions_lineupdown.inc.php
81 $permissiontodelete = $user->rights->partnership->delete || ($permissiontoadd && isset($object->status) && $object->status == $object::STATUS_DRAFT);
82 $permissionnote = $user->rights->partnership->write; // Used by the include of actions_setnotes.inc.php
83 $permissiondellink = $user->rights->partnership->write; // Used by the include of actions_dellink.inc.php
84 $usercanclose = $user->rights->partnership->write; // Used by the include of actions_addupdatedelete.inc.php and actions_lineupdown.inc.php
85 $upload_dir = $conf->partnership->multidir_output[isset($object->entity) ? $object->entity : 1];
86 
87 
88 if (getDolGlobalString('PARTNERSHIP_IS_MANAGED_FOR') != 'member') {
89  accessforbidden('Partnership module is not activated for members');
90 }
91 if (empty($conf->partnership->enabled)) {
93 }
94 if (empty($permissiontoread)) {
96 }
97 if ($action == 'edit' && empty($permissiontoadd)) {
99 }
100 if (($action == 'update' || $action == 'edit') && $object->status != $object::STATUS_DRAFT) {
101  accessforbidden();
102 }
103 
104 
105 // Security check
106 $result = restrictedArea($user, 'adherent', $id, '', '', 'socid', 'rowid', 0);
107 
108 
109 /*
110  * Actions
111  */
112 
113 $parameters = array();
114 $reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
115 if ($reshook < 0) {
116  setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
117 }
118 
119 $date_start = dol_mktime(0, 0, 0, GETPOST('date_partnership_startmonth', 'int'), GETPOST('date_partnership_startday', 'int'), GETPOST('date_partnership_startyear', 'int'));
120 $date_end = dol_mktime(0, 0, 0, GETPOST('date_partnership_endmonth', 'int'), GETPOST('date_partnership_endday', 'int'), GETPOST('date_partnership_endyear', 'int'));
121 
122 if (empty($reshook)) {
123  $error = 0;
124 
125  $backtopage = dol_buildpath('/partnership/partnership.php', 1).'?rowid='.($id > 0 ? $id : '__ID__');
126 
127  // Actions when linking object each other
128  include DOL_DOCUMENT_ROOT.'/core/actions_dellink.inc.php';
129 }
130 
131 $object->fields['fk_member']['visible'] = 0;
132 if ($object->id > 0 && $object->status == $object::STATUS_REFUSED && empty($action)) $object->fields['reason_decline_or_cancel']['visible'] = 1;
133 $object->fields['note_public']['visible'] = 1;
134 
135 
136 /*
137  * View
138  */
139 
140 $form = new Form($db);
141 $formfile = new FormFile($db);
142 
143 $title = $langs->trans("Partnership");
144 llxHeader('', $title);
145 
146 $form = new Form($db);
147 
148 if ($id > 0) {
149  $langs->load("members");
150 
151  $object = new Adherent($db);
152  $result = $object->fetch($id);
153 
154  if (!empty($conf->notification->enabled)) {
155  $langs->load("mails");
156  }
157 
158  $adht->fetch($object->typeid);
159 
160  $head = member_prepare_head($object);
161 
162  print dol_get_fiche_head($head, 'partnership', $langs->trans("ThirdParty"), -1, 'user');
163 
164  $linkback = '<a href="'.DOL_URL_ROOT.'/adherents/list.php?restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>';
165 
166  dol_banner_tab($object, 'rowid', $linkback);
167 
168  print '<div class="fichecenter">';
169 
170  print '<div class="underbanner clearboth"></div>';
171  print '<table class="border centpercent tableforfield">';
172 
173  // Login
174  if (empty($conf->global->ADHERENT_LOGIN_NOT_REQUIRED)) {
175  print '<tr><td class="titlefield">'.$langs->trans("Login").' / '.$langs->trans("Id").'</td><td class="valeur">'.$object->login.'&nbsp;</td></tr>';
176  }
177 
178  // Type
179  print '<tr><td class="titlefield">'.$langs->trans("Type").'</td><td class="valeur">'.$adht->getNomUrl(1)."</td></tr>\n";
180 
181  // Morphy
182  print '<tr><td>'.$langs->trans("MemberNature").'</td><td class="valeur" >'.$object->getmorphylib().'</td>';
183  print '</tr>';
184 
185  // Company
186  print '<tr><td>'.$langs->trans("Company").'</td><td class="valeur">'.$object->company.'</td></tr>';
187 
188  // Civility
189  print '<tr><td>'.$langs->trans("UserTitle").'</td><td class="valeur">'.$object->getCivilityLabel().'&nbsp;</td>';
190  print '</tr>';
191 
192  print '</table>';
193 
194  print '</div>';
195 
196  print dol_get_fiche_end();
197 } else {
198  dol_print_error('', 'Parameter rowid not defined');
199 }
200 
201 
202 // Part to show record
203 if ($object->id > 0 && (empty($action) || ($action != 'edit' && $action != 'create'))) {
204  // Buttons for actions
205 
206  if ($action != 'presend') {
207  print '<div class="tabsAction">'."\n";
208  $parameters = array();
209  $reshook = $hookmanager->executeHooks('addMoreActionsButtons', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
210  if ($reshook < 0) {
211  setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
212  }
213 
214  if (empty($reshook)) {
215  // Show
216  if ($permissiontoadd) {
217  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);
218  }
219  }
220  print '</div>'."\n";
221  }
222 
223 
224  //$morehtmlright = 'partnership/partnership_card.php?action=create&backtopage=%2Fdolibarr%2Fhtdocs%2Fpartnership%2Fpartnership_list.php';
225  $morehtmlright = '';
226 
227  print load_fiche_titre($langs->trans("PartnershipDedicatedToThisMember", $langs->transnoentitiesnoconv("Partnership")), $morehtmlright, '');
228 
229  $memberid = $object->id;
230 
231 
232  // TODO Replace this card with the list of all partnerships.
233 
234  $object = new Partnership($db);
235  $partnershipid = $object->fetch(0, "", $memberid);
236 
237  if ($partnershipid > 0) {
238  print '<div class="fichecenter">';
239  print '<div class="fichehalfleft">';
240  print '<div class="underbanner clearboth"></div>';
241  print '<table class="border centpercent tableforfield">'."\n";
242 
243  // Common attributes
244  //$keyforbreak='fieldkeytoswitchonsecondcolumn'; // We change column just before this field
245  //unset($object->fields['fk_project']); // Hide field already shown in banner
246  //unset($object->fields['fk_member']); // Hide field already shown in banner
247  include DOL_DOCUMENT_ROOT.'/core/tpl/commonfields_view.tpl.php';
248 
249  // End of subscription date
250  $fadherent = new Adherent($db);
251  $fadherent->fetch($object->fk_member);
252  print '<tr><td>'.$langs->trans("SubscriptionEndDate").'</td><td class="valeur">';
253  if ($fadherent->datefin) {
254  print dol_print_date($fadherent->datefin, 'day');
255  if ($fadherent->hasDelay()) {
256  print " ".img_warning($langs->trans("Late"));
257  }
258  } else {
259  if (!$adht->subscription) {
260  print $langs->trans("SubscriptionNotRecorded");
261  if ($fadherent->statut > 0) {
262  print " ".img_warning($langs->trans("Late")); // Display a delay picto only if it is not a draft and is not canceled
263  }
264  } else {
265  print $langs->trans("SubscriptionNotReceived");
266  if ($fadherent->statut > 0) {
267  print " ".img_warning($langs->trans("Late")); // Display a delay picto only if it is not a draft and is not canceled
268  }
269  }
270  }
271  print '</td></tr>';
272 
273  print '</table>';
274  print '</div>';
275  }
276 }
277 
278 // End of page
279 llxFooter();
280 $db->close();
AdherentType
Class to manage members type.
Definition: adherent_type.class.php:35
restrictedArea
restrictedArea($user, $features, $objectid=0, $tableandshare='', $feature2='', $dbt_keyfield='fk_soc', $dbt_select='rowid', $isdraft=0, $mode=0)
Check permissions of a user to show a page and an object.
Definition: security.lib.php:234
llxFooter
llxFooter()
Empty footer.
Definition: wrapper.php:73
load_fiche_titre
load_fiche_titre($titre, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
Definition: functions.lib.php:5204
GETPOST
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
Definition: functions.lib.php:484
dol_print_error
dol_print_error($db='', $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
Definition: functions.lib.php:4844
Partnership
Class for Partnership.
Definition: partnership.class.php:34
dol_buildpath
dol_buildpath($path, $type=0, $returnemptyifnotfound=0)
Return path of url or filesystem.
Definition: functions.lib.php:1062
$form
if($cancel &&! $id) if($action=='add' &&! $cancel) if($action=='delete') if($id) $form
Actions.
Definition: card.php:142
member_prepare_head
member_prepare_head(Adherent $object)
Return array head with list of tabs to view object informations.
Definition: member.lib.php:33
dolGetButtonAction
dolGetButtonAction($label, $html='', $actionType='default', $url='', $id='', $userRight=1, $params=array())
Function dolGetButtonAction.
Definition: functions.lib.php:10450
dol_banner_tab
dol_banner_tab($object, $paramid, $morehtml='', $shownav=1, $fieldid='rowid', $fieldref='ref', $morehtmlref='', $moreparam='', $nodbprefix=0, $morehtmlleft='', $morehtmlstatus='', $onlybanner=0, $morehtmlright='')
Show tab footer of a card.
Definition: functions.lib.php:2046
dol_print_date
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs='', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
Definition: functions.lib.php:2514
FormFile
Class to offer components to list and upload files.
Definition: html.formfile.class.php:36
Adherent
Class to manage members of a foundation.
Definition: adherent.class.php:46
dol_get_fiche_head
dol_get_fiche_head($links=array(), $active='', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limittoshow=0, $moretabssuffix='')
Show tabs of a record.
Definition: functions.lib.php:1822
getDolGlobalString
if(!function_exists('utf8_encode')) if(!function_exists('utf8_decode')) getDolGlobalString($key, $default='')
Return dolibarr global constant string value.
Definition: functions.lib.php:80
dol_get_fiche_end
dol_get_fiche_end($notab=0)
Return tab footer of a card.
Definition: functions.lib.php:2018
ExtraFields
Class to manage standard extra fields.
Definition: extrafields.class.php:39
Form
Class to manage generation of HTML components Only common components must be here.
Definition: html.form.class.php:52
setEventMessages
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='')
Set event messages in dol_events session object.
Definition: functions.lib.php:8137
accessforbidden
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program Calling this function terminate execution ...
Definition: security.lib.php:933
dol_mktime
dol_mktime($hour, $minute, $second, $month, $day, $year, $gm='auto', $check=1)
Return a timestamp date built from detailed informations (by default a local PHP server timestamp) Re...
Definition: functions.lib.php:2757
llxHeader
if(!defined('NOREQUIRESOC')) if(!defined('NOREQUIRETRAN')) if(!defined('NOCSRFCHECK')) if(!defined('NOTOKENRENEWAL')) if(!defined('NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined('NOREQUIREAJAX')) llxHeader()
Empty header.
Definition: wrapper.php:59