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