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  * 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 
26 // Load Dolibarr environment
27 require '../main.inc.php';
28 require_once DOL_DOCUMENT_ROOT.'/core/class/html.formcompany.class.php';
29 require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
30 require_once DOL_DOCUMENT_ROOT.'/core/class/html.formprojet.class.php';
31 require_once DOL_DOCUMENT_ROOT.'/societe/class/societe.class.php';
32 require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
33 require_once DOL_DOCUMENT_ROOT.'/partnership/class/partnership.class.php';
34 require_once DOL_DOCUMENT_ROOT.'/partnership/lib/partnership.lib.php';
35 
36 // Load translation files required by the page
37 $langs->loadLangs(array("companies", "partnership", "other"));
38 
39 // Get parameters
40 $id = GETPOST('id', 'int');
41 $ref = GETPOST('ref', 'alpha');
42 $action = GETPOST('action', 'aZ09');
43 $confirm = GETPOST('confirm', 'alpha');
44 $cancel = GETPOST('cancel', 'aZ09');
45 $contextpage = GETPOST('contextpage', 'aZ') ? GETPOST('contextpage', 'aZ') : 'partnershipcard'; // To manage different context of search
46 $backtopage = GETPOST('backtopage', 'alpha');
47 $backtopageforcancel = GETPOST('backtopageforcancel', 'alpha');
48 //$lineid = GETPOST('lineid', 'int');
49 
50 // Security check
51 $socid = GETPOST('socid', 'int');
52 if (!empty($user->socid)) {
53  $socid = $user->socid;
54 }
55 
56 if (empty($id) && $socid && (getDolGlobalString('PARTNERSHIP_IS_MANAGED_FOR', 'thirdparty') == 'thirdparty')) {
57  $id = $socid;
58 }
59 
60 $object = new Societe($db);
61 if ($id > 0) {
62  $object->fetch($id);
63 }
64 
65 // Initialize technical objects
66 $object = new Partnership($db);
67 $extrafields = new ExtraFields($db);
68 $diroutputmassaction = $conf->partnership->dir_output.'/temp/massgeneration/'.$user->id;
69 $hookmanager->initHooks(array('thirdpartypartnership', 'globalcard')); // Note that conf->hooks_modules contains array
70 
71 // Fetch optionals attributes and labels
72 $extrafields->fetch_name_optionals_label($object->table_element);
73 
74 $search_array_options = $extrafields->getOptionalsFromPost($object->table_element, '', 'search_');
75 
76 // Initialize array of search criterias
77 $search_all = GETPOST("search_all", 'alpha');
78 $search = array();
79 
80 foreach ($object->fields as $key => $val) {
81  if (GETPOST('search_'.$key, 'alpha')) {
82  $search[$key] = GETPOST('search_'.$key, 'alpha');
83  }
84 }
85 
86 // Load object
87 include DOL_DOCUMENT_ROOT.'/core/actions_fetchobject.inc.php'; // Must be include, not include_once.
88 
89 $permissiontoread = $user->rights->partnership->read;
90 $permissiontoadd = $user->rights->partnership->write; // Used by the include of actions_addupdatedelete.inc.php and actions_lineupdown.inc.php
91 $permissiontodelete = $user->rights->partnership->delete || ($permissiontoadd && isset($object->status) && $object->status == $object::STATUS_DRAFT);
92 $permissionnote = $user->rights->partnership->write; // Used by the include of actions_setnotes.inc.php
93 $permissiondellink = $user->rights->partnership->write; // Used by the include of actions_dellink.inc.php
94 $usercanclose = $user->rights->partnership->write; // Used by the include of actions_addupdatedelete.inc.php and actions_lineupdown.inc.php
95 $upload_dir = $conf->partnership->multidir_output[isset($object->entity) ? $object->entity : 1];
96 
97 
98 if (getDolGlobalString('PARTNERSHIP_IS_MANAGED_FOR', 'thirdparty') != 'thirdparty') {
99  accessforbidden('Partnership is not activated for thirdparties');
100 }
101 if (empty($conf->partnership->enabled)) {
102  accessforbidden();
103 }
104 if (empty($permissiontoread)) {
105  accessforbidden();
106 }
107 if ($action == 'edit' && empty($permissiontoadd)) {
108  accessforbidden();
109 }
110 
111 if (($action == 'update' || $action == 'edit') && $object->status != $object::STATUS_DRAFT && !empty($user->socid)) {
112  accessforbidden();
113 }
114 
115 
116 // Security check
117 $result = restrictedArea($user, 'societe', $id, '&societe', '', 'fk_soc', 'rowid', 0);
118 
119 
120 /*
121  * Actions
122  */
123 
124 $parameters = array();
125 $reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
126 if ($reshook < 0) {
127  setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
128 }
129 
130 $date_start = dol_mktime(0, 0, 0, GETPOST('date_partnership_startmonth', 'int'), GETPOST('date_partnership_startday', 'int'), GETPOST('date_partnership_startyear', 'int'));
131 $date_end = dol_mktime(0, 0, 0, GETPOST('date_partnership_endmonth', 'int'), GETPOST('date_partnership_endday', 'int'), GETPOST('date_partnership_endyear', 'int'));
132 
133 if (empty($reshook)) {
134  $error = 0;
135 
136  $backtopage = DOL_URL_ROOT.'/partnership/partnership.php?id='.($id > 0 ? $id : '__ID__');
137 
138  // Actions when linking object each other
139  include DOL_DOCUMENT_ROOT.'/core/actions_dellink.inc.php';
140 }
141 
142 $object->fields['fk_soc']['visible'] = 0;
143 if ($object->id > 0 && $object->status == $object::STATUS_REFUSED && empty($action)) {
144  $object->fields['reason_decline_or_cancel']['visible'] = 1;
145 }
146 $object->fields['note_public']['visible'] = 1;
147 
148 
149 /*
150  * View
151  */
152 
153 $form = new Form($db);
154 $formfile = new FormFile($db);
155 
156 $title = $langs->trans("Partnership");
157 llxHeader('', $title);
158 
159 $form = new Form($db);
160 
161 if ($id > 0) {
162  $langs->load("companies");
163 
164  $object = new Societe($db);
165  $result = $object->fetch($id);
166 
167  if (!empty($conf->notification->enabled)) {
168  $langs->load("mails");
169  }
170  $head = societe_prepare_head($object);
171 
172  print dol_get_fiche_head($head, 'partnership', $langs->trans("ThirdParty"), -1, 'company');
173 
174  $linkback = '<a href="'.DOL_URL_ROOT.'/societe/list.php?restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>';
175 
176  dol_banner_tab($object, 'socid', $linkback, ($user->socid ? 0 : 1), 'rowid', 'nom');
177 
178  print '<div class="fichecenter">';
179 
180  print '<div class="underbanner clearboth"></div>';
181  print '<table class="border centpercent tableforfield">';
182 
183  if (!empty($conf->global->SOCIETE_USEPREFIX)) { // Old not used prefix field
184  print '<tr><td>'.$langs->trans('Prefix').'</td><td colspan="3">'.$object->prefix_comm.'</td></tr>';
185  }
186 
187  if ($object->client) {
188  print '<tr><td class="titlefield">';
189  print $langs->trans('CustomerCode').'</td><td colspan="3">';
190  print showValueWithClipboardCPButton(dol_escape_htmltag($object->code_client));
191  $tmpcheck = $object->check_codeclient();
192  if ($tmpcheck != 0 && $tmpcheck != -5) {
193  print ' <span class="error">('.$langs->trans("WrongCustomerCode").')</span>';
194  }
195  print '</td></tr>';
196  }
197 
198  if ($object->fournisseur) {
199  print '<tr><td class="titlefield">';
200  print $langs->trans('SupplierCode').'</td><td colspan="3">';
201  print showValueWithClipboardCPButton(dol_escape_htmltag($object->code_fournisseur));
202  $tmpcheck = $object->check_codefournisseur();
203  if ($tmpcheck != 0 && $tmpcheck != -5) {
204  print ' <span class="error">('.$langs->trans("WrongSupplierCode").')</span>';
205  }
206  print '</td>';
207  print '</tr>';
208  }
209 
210  print '</table>';
211 
212  print '</div>';
213 
214  print dol_get_fiche_end();
215 } else {
216  dol_print_error('', 'Parameter id not defined');
217 }
218 
219 // Part to show record
220 if ($object->id > 0 && (empty($action) || ($action != 'edit' && $action != 'create'))) {
221  // Buttons for actions
222 
223  if ($action != 'presend') {
224  print '<div class="tabsAction">'."\n";
225  $parameters = array();
226  $reshook = $hookmanager->executeHooks('addMoreActionsButtons', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
227  if ($reshook < 0) {
228  setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
229  }
230 
231  if (empty($reshook)) {
232  // Show
233  if ($permissiontoadd) {
234  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);
235  }
236  }
237  print '</div>'."\n";
238  }
239 
240 
241  //$morehtmlright = 'partnership/partnership_card.php?action=create&backtopage=%2Fdolibarr%2Fhtdocs%2Fpartnership%2Fpartnership_list.php';
242  $morehtmlright = '';
243 
244  print load_fiche_titre($langs->trans("PartnershipDedicatedToThisThirdParty", $langs->transnoentitiesnoconv("Partnership")), $morehtmlright, '');
245 
246  $socid = $object->id;
247 
248 
249  // TODO Replace this card with a table of list of all partnerships.
250 
251  $object = new Partnership($db);
252  $partnershipid = $object->fetch(0, '', 0, $socid);
253 
254  if ($partnershipid > 0) {
255  print '<div class="fichecenter">';
256  print '<div class="fichehalfleft">';
257  print '<div class="underbanner clearboth"></div>';
258  print '<table class="border centpercent tableforfield">'."\n";
259 
260  // Common attributes
261  unset($object->fields['fk_soc']); // Hide field already shown in banner
262  include DOL_DOCUMENT_ROOT.'/core/tpl/commonfields_view.tpl.php';
263  $forcefieldid = 'socid';
264  $forceobjectid = $object->fk_soc;
265  include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_view.tpl.php';
266 
267  print '</table>';
268  print '</div>';
269  }
270 }
271 
272 // End of page
273 llxFooter();
274 $db->close();
Societe
Class to manage third parties objects (customers, suppliers, prospects...)
Definition: societe.class.php:48
dol_escape_htmltag
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $noescapetags='', $escapeonlyhtmltags=0)
Returns text escaped for inclusion in HTML alt or title tags, or into values of HTML input fields.
Definition: functions.lib.php:1468
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
$form
if($cancel &&! $id) if($action=='add' &&! $cancel) if($action=='delete') if($id) $form
Actions.
Definition: card.php:142
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
FormFile
Class to offer components to list and upload files.
Definition: html.formfile.class.php:36
showValueWithClipboardCPButton
showValueWithClipboardCPButton($valuetocopy, $showonlyonhover=1, $texttoshow='')
Create a button to copy $valuetocopy in the clipboard (for copy and paste feature).
Definition: functions.lib.php:11087
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
societe_prepare_head
societe_prepare_head(Societe $object)
Return array of tabs to used on pages for third parties cards.
Definition: company.lib.php:42
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