From 22ec79d03ce781d7eff42e5337969ff4845fb595 Mon Sep 17 00:00:00 2001 From: NextGestion Date: Fri, 16 Apr 2021 12:10:26 +0100 Subject: [PATCH] Code optimisation --- htdocs/langs/en_US/main.lang | 1 + htdocs/langs/en_US/partnership.lang | 3 + htdocs/partnership/partnership_card.php | 22 ++++++- htdocs/societe/partnership.php | 79 ++++--------------------- 4 files changed, 35 insertions(+), 70 deletions(-) diff --git a/htdocs/langs/en_US/main.lang b/htdocs/langs/en_US/main.lang index dc2a83f2015..51d4d99bd8c 100644 --- a/htdocs/langs/en_US/main.lang +++ b/htdocs/langs/en_US/main.lang @@ -1070,6 +1070,7 @@ ValidFrom=Valid from ValidUntil=Valid until NoRecordedUsers=No users ToClose=To close +ToRefuse=To refuse ToProcess=To process ToApprove=To approve GlobalOpenedElemView=Global view diff --git a/htdocs/langs/en_US/partnership.lang b/htdocs/langs/en_US/partnership.lang index 3ac04a5bae0..3e176afdf8f 100644 --- a/htdocs/langs/en_US/partnership.lang +++ b/htdocs/langs/en_US/partnership.lang @@ -42,6 +42,9 @@ DatePartnershipStart=Start date DatePartnershipEnd=End date ReasonDecline=Decline reason ReasonDeclineOrCancel=Decline reason +PartnershipAlreadyExist=Partnership already exist +ShowPartnership=Show partnership +ConfirmClosePartnershipAsk=Are you sure you want to cancel this partnership? # # Template Mail diff --git a/htdocs/partnership/partnership_card.php b/htdocs/partnership/partnership_card.php index 2e6e43ac47e..f46b608d603 100644 --- a/htdocs/partnership/partnership_card.php +++ b/htdocs/partnership/partnership_card.php @@ -161,6 +161,17 @@ if (empty($reshook)) { } } + $fk_soc = GETPOST('fk_soc', 'int'); + if ($action == 'add' || ($action == 'update' && $object->fk_soc != $fk_soc)) { + $fpartnership = new Partnership($db); + + $partnershipid = $fpartnership->fetch(0, "", $fk_soc); + if($partnershipid > 0){ + setEventMessages($langs->trans('PartnershipAlreadyExist').' : '.$fpartnership->getNomUrl(0,'',1), '', 'errors'); + $action = ($action == 'add') ? 'create' : 'edit'; + } + } + $triggermodname = 'PARTNERSHIP_MODIFY'; // Name of trigger action code to execute when we modify record // Actions cancel, add, update, update_extras, confirm_validate, confirm_delete, confirm_deleteline, confirm_clone, confirm_close, confirm_setdraft, confirm_reopen @@ -250,6 +261,11 @@ if (empty($reshook)) { $autocopy = 'MAIN_MAIL_AUTOCOPY_PARTNERSHIP_TO'; $trackid = 'partnership'.$object->id; include DOL_DOCUMENT_ROOT.'/core/actions_sendmails.inc.php'; + + if(!empty($id) && !empty(GETPOST('confirm'))){ + header("Location: ".$_SERVER['PHP_SELF']."?id=".$id); + exit; + } } if ($object->id > 0 && $object->status == $object::STATUS_REFUSED) $object->fields['reason_decline_or_cancel']['visible'] = 3; @@ -391,7 +407,7 @@ if ($object->id > 0 && (empty($action) || ($action != 'edit' && $action != 'crea if ($action == 'close') { // Create an array for form $formquestion = array(); - $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('ToClose'), $langs->trans('ConfirmCloseAsk', $object->ref), 'confirm_close', $formquestion, 'yes', 1); + $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('ToClose'), $langs->trans('ConfirmClosePartnershipAsk', $object->ref), 'confirm_close', $formquestion, 'yes', 1); } // Reopon confirmation if ($action == 'reopen') { @@ -415,7 +431,7 @@ if ($object->id > 0 && (empty($action) || ($action != 'edit' && $action != 'crea // )); // } - $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('ReasonDecline'), $text, 'confirm_refuse', $formquestion, '', 1, 250); + $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('ToRefuse'), $text, 'confirm_refuse', $formquestion, '', 1, 250); } // Confirmation of action xxxx @@ -626,7 +642,7 @@ if ($object->id > 0 && (empty($action) || ($action != 'edit' && $action != 'crea // Cancel if ($permissiontoadd) { if ($object->status == $object::STATUS_ACCEPTED) { - print dolGetButtonAction($langs->trans('Cancel'), '', 'default', $_SERVER["PHP_SELF"].'?id='.$object->id.'&action=confirm_close&confirm=yes&token='.newToken(), '', $permissiontoadd); + print dolGetButtonAction($langs->trans('Cancel'), '', 'default', $_SERVER["PHP_SELF"].'?id='.$object->id.'&action=close&token='.newToken(), '', $permissiontoadd); } elseif ($object->status > $object::STATUS_ACCEPTED) { // print ''.$langs->trans("Re-Open").''."\n"; print dolGetButtonAction($langs->trans('Re-Open'), '', 'default', $_SERVER["PHP_SELF"].'?id='.$object->id.'&action=confirm_reopen&confirm=yes&token='.newToken(), '', $permissiontoadd); diff --git a/htdocs/societe/partnership.php b/htdocs/societe/partnership.php index 90071846531..0cb18930030 100644 --- a/htdocs/societe/partnership.php +++ b/htdocs/societe/partnership.php @@ -186,6 +186,7 @@ if (empty($reshook)) { $object->fk_soc = $socid; $object->date_partnership_start = (!GETPOST('date_partnership_start')) ? '' : $date_start; $object->date_partnership_end = (!GETPOST('date_partnership_end')) ? '' : $date_end; + $object->note_public = GETPOST('note_public', 'restricthtml'); $object->date_creation = $now; $object->fk_user_creat = $user->id; $object->entity = $conf->entity; @@ -229,6 +230,7 @@ if (empty($reshook)) { $object->date_partnership_start = (!GETPOST('date_partnership_start')) ? '' : $date_start; $object->date_partnership_end = (!GETPOST('date_partnership_end')) ? '' : $date_end; + $object->note_public = GETPOST('note_public', 'restricthtml'); $object->fk_user_creat = $user->id; $object->fk_user_modif = $user->id; @@ -266,15 +268,11 @@ if (empty($reshook)) { // Actions when linking object each other include DOL_DOCUMENT_ROOT.'/core/actions_dellink.inc.php'; - - // // Actions to send emails - // $triggersendname = 'PARTNERSHIP_SENTBYMAIL'; - // $autocopy = 'MAIN_MAIL_AUTOCOPY_PARTNERSHIP_TO'; - // $trackid = 'partnership'.$object->id; - // include DOL_DOCUMENT_ROOT.'/core/actions_sendmails.inc.php'; } - +$object->fields['fk_soc']['visible'] = 0; +if ($object->id > 0 && $object->status == $object::STATUS_REFUSED && empty($action)) $object->fields['reason_decline_or_cancel']['visible'] = 1; +$object->fields['note_public']['visible'] = 1; /* * View @@ -354,8 +352,6 @@ if ($socid) { dol_print_error('', 'Parameter socid not defined'); } -$object->fields['fk_soc']['visible'] = 0; - // Part to create if ($action == 'create') { print load_fiche_titre($langs->trans("NewObject", $langs->transnoentitiesnoconv("Partnership")), '', ''); @@ -455,7 +451,7 @@ if ($object->id > 0 && (empty($action) || ($action != 'edit' && $action != 'crea if ($action == 'close') { // Create an array for form $formquestion = array(); - $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('ToClose'), $langs->trans('ConfirmCloseAsk', $object->ref), 'confirm_close', $formquestion, 'yes', 1); + $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('ToClose'), $langs->trans('ConfirmClosePartnershipAsk', $object->ref), 'confirm_close', $formquestion, 'yes', 1); } // Reopon confirmation if ($action == 'reopen') { @@ -535,72 +531,21 @@ if ($object->id > 0 && (empty($action) || ($action != 'edit' && $action != 'crea print dolGetButtonAction($langs->trans('Modify'), '', 'default', $_SERVER["PHP_SELF"].'?socid='.$socid.'&action=edit', '', $permissiontoadd); } + // Show + if ($permissiontoadd) { + print dolGetButtonAction($langs->trans('ShowPartnership'), '', 'default', dol_buildpath('/partnership/partnership_card.php', 1).'?id='.$object->id, '', $permissiontoadd); + } + // Cancel if ($permissiontoadd) { if ($object->status == $object::STATUS_ACCEPTED) { print dolGetButtonAction($langs->trans('Cancel'), '', 'default', $_SERVER["PHP_SELF"].'?id='.$object->id.'&action=close&token='.newToken(), '', $permissiontoadd); } } + } print ''."\n"; } - - - // Select mail models is same action as presend - if (GETPOST('modelselected')) { - $action = 'presend'; - } - - // if ($action != 'presend') { - // print '
'; - // print ''; // ancre - - // $includedocgeneration = 0; - - // // Documents - // if ($includedocgeneration) { - // $objref = dol_sanitizeFileName($object->ref); - // $relativepath = $objref.'/'.$objref.'.pdf'; - // $filedir = $conf->partnership->dir_output.'/'.$object->element.'/'.$objref; - // $urlsource = $_SERVER["PHP_SELF"]."?id=".$object->id; - // $genallowed = $user->rights->partnership->read; // If you can read, you can build the PDF to read content - // $delallowed = $user->rights->partnership->write; // If you can create/edit, you can remove a file on card - // print $formfile->showdocuments('partnership:Partnership', $object->element.'/'.$objref, $filedir, $urlsource, $genallowed, $delallowed, $object->model_pdf, 1, 0, 0, 28, 0, '', '', '', $langs->defaultlang); - // } - - // // Show links to link elements - // $linktoelem = $form->showLinkToObjectBlock($object, null, array('partnership')); - // $somethingshown = $form->showLinkedObjectBlock($object, $linktoelem); - - - // print '
'; - - // $MAXEVENT = 10; - - // $morehtmlright = ''; - // $morehtmlright .= $langs->trans("SeeAll"); - // $morehtmlright .= ''; - - // // List of actions on element - // include_once DOL_DOCUMENT_ROOT.'/core/class/html.formactions.class.php'; - // $formactions = new FormActions($db); - // $somethingshown = $formactions->showactions($object, $object->element.'@'.$object->module, (is_object($object->thirdparty) ? $object->thirdparty->id : 0), 1, '', $MAXEVENT, '', $morehtmlright); - - // print '
'; - // } - - //Select mail models is same action as presend - if (GETPOST('modelselected')) { - $action = 'presend'; - } - - // Presend form - $modelmail = 'partnership'; - $defaulttopic = 'InformationMessage'; - $diroutput = $conf->partnership->dir_output; - $trackid = 'partnership'.$object->id; - - include DOL_DOCUMENT_ROOT.'/core/tpl/card_presend.tpl.php'; } // End of page