diff --git a/htdocs/comm/card.php b/htdocs/comm/card.php index 8271a351986..b1cdf0c7da4 100644 --- a/htdocs/comm/card.php +++ b/htdocs/comm/card.php @@ -276,7 +276,7 @@ if (empty($reshook)) { $result = $object->setSalesRep(GETPOST('commercial', 'array')); } - if ($action == 'update_extras') { + if ($action == 'update_extras' && $user->hasRight('societe', 'creer')) { $object->fetch($id); $object->oldcopy = dol_clone($object, 2); diff --git a/htdocs/comm/propal/card.php b/htdocs/comm/propal/card.php index 45668a9111d..091ce9db948 100644 --- a/htdocs/comm/propal/card.php +++ b/htdocs/comm/propal/card.php @@ -1693,7 +1693,7 @@ if (empty($reshook)) { } elseif ($action == 'setwarehouse' && $usercancreate) { // warehouse $result = $object->setWarehouse(GETPOSTINT('warehouse_id')); - } elseif ($action == 'update_extras') { + } elseif ($action == 'update_extras' && $usercancreate) { $object->oldcopy = dol_clone($object, 2); $attribute_name = GETPOST('attribute', 'restricthtml'); diff --git a/htdocs/commande/card.php b/htdocs/commande/card.php index e66237e0bff..c7aa9292337 100644 --- a/htdocs/commande/card.php +++ b/htdocs/commande/card.php @@ -631,7 +631,7 @@ if (empty($reshook)) { $object->generateDocument($object->model_pdf, $outputlangs, $hidedetails, $hidedesc, $hideref); } } - } elseif ($action == 'set_incoterms' && isModEnabled('incoterm')) { + } elseif ($action == 'set_incoterms' && isModEnabled('incoterm') && $usercancreate) { // Set incoterm $result = $object->setIncoterms(GETPOSTINT('incoterm_id'), GETPOSTFLOAT('location_incoterms')); if ($result < 0) { @@ -1511,7 +1511,7 @@ if (empty($reshook)) { } } - if ($action == 'update_extras') { + if ($action == 'update_extras' && $usercancreate) { $object->oldcopy = dol_clone($object, 2); $attribute_name = GETPOST('attribute', 'restricthtml'); diff --git a/htdocs/compta/facture/card-rec.php b/htdocs/compta/facture/card-rec.php index ad171e23a6a..871a060a19e 100644 --- a/htdocs/compta/facture/card-rec.php +++ b/htdocs/compta/facture/card-rec.php @@ -118,11 +118,14 @@ $usercanread = $user->hasRight('facture', 'lire'); $usercancreate = $user->hasRight('facture', 'creer'); $usercanissuepayment = $user->hasRight('facture', 'paiement'); $usercandelete = $user->hasRight('facture', 'supprimer'); + +// Advanced permissions $usercanvalidate = ((!getDolGlobalString('MAIN_USE_ADVANCED_PERMS') && $usercancreate) || (getDolGlobalString('MAIN_USE_ADVANCED_PERMS') && $user->hasRight('facture', 'invoice_advance', 'validate'))); $usercansend = (!getDolGlobalString('MAIN_USE_ADVANCED_PERMS') || $user->rights->facture->invoice_advance->send); $usercanreopen = (!getDolGlobalString('MAIN_USE_ADVANCED_PERMS') || $user->rights->facture->invoice_advance->reopen); $usercanunvalidate = ((!getDolGlobalString('MAIN_USE_ADVANCED_PERMS') && !empty($usercancreate)) || (getDolGlobalString('MAIN_USE_ADVANCED_PERMS') && $user->hasRight('facture', 'invoice_advance', 'unvalidate'))); +// Other permissions $usercanproductignorepricemin = ((getDolGlobalString('MAIN_USE_ADVANCED_PERMS') && !$user->hasRight('produit', 'ignore_price_min_advance')) || !getDolGlobalString('MAIN_USE_ADVANCED_PERMS')); $usercancreatemargin = $user->hasRight("margins", "creer"); $usercanreadallmargin = $user->hasRight("margins", "liretous"); @@ -312,19 +315,19 @@ if (empty($reshook)) { // Update field - if ($action == 'setconditions' && $user->hasRight('facture', 'creer')) { + if ($action == 'setconditions' && $usercancreate) { // Set condition $object->context['actionmsg'] = $langs->trans("FieldXModified", $langs->transnoentitiesnoconv("PaymentTerm")); $result = $object->setPaymentTerms(GETPOSTINT('cond_reglement_id')); - } elseif ($action == 'setmode' && $user->hasRight('facture', 'creer')) { + } elseif ($action == 'setmode' && $usercancreate) { // Set mode $object->context['actionmsg'] = $langs->trans("FieldXModified", $langs->transnoentitiesnoconv("PaymentMode")); $result = $object->setPaymentMethods(GETPOSTINT('mode_reglement_id')); - } elseif ($action == 'classin' && $user->hasRight('facture', 'creer')) { + } elseif ($action == 'classin' && $usercancreate) { // Set project $object->context['actionmsg'] = $langs->trans("FieldXModified", $langs->transnoentitiesnoconv("Project")); $object->setProject(GETPOSTINT('projectid')); - } elseif ($action == 'setref' && $user->hasRight('facture', 'creer')) { + } elseif ($action == 'setref' && $usercancreate) { // Set bank account $object->context['actionmsg'] = $langs->trans("FieldXModifiedFromYToZ", $langs->transnoentitiesnoconv("Title"), $object->title, $ref); $result = $object->setValueFrom('titre', $ref, '', null, 'text', '', $user, 'BILLREC_MODIFY'); @@ -340,33 +343,33 @@ if (empty($reshook)) { setEventMessages($object->error, $object->errors, 'errors'); } } - } elseif ($action == 'setbankaccount' && $user->hasRight('facture', 'creer')) { + } elseif ($action == 'setbankaccount' && $usercancreate) { // Set bank account $object->context['actionmsg'] = $langs->trans("FieldXModified", $langs->transnoentitiesnoconv("Bank")); $result = $object->setBankAccount(GETPOSTINT('fk_account')); - } elseif ($action == 'setfrequency' && $user->hasRight('facture', 'creer')) { + } elseif ($action == 'setfrequency' && $usercancreate) { // Set frequency and unit frequency $object->context['actionmsg'] = $langs->trans("FieldXModified", $langs->transnoentitiesnoconv("Frequency")); $object->setFrequencyAndUnit(GETPOSTINT('frequency'), GETPOST('unit_frequency')); - } elseif ($action == 'setdate_when' && $user->hasRight('facture', 'creer')) { + } elseif ($action == 'setdate_when' && $usercancreate) { // Set next date of execution $date = dol_mktime(GETPOST('date_whenhour'), GETPOST('date_whenmin'), 0, GETPOST('date_whenmonth'), GETPOST('date_whenday'), GETPOST('date_whenyear')); if (!empty($date)) { $object->setNextDate($date); } - } elseif ($action == 'setnb_gen_max' && $user->hasRight('facture', 'creer')) { + } elseif ($action == 'setnb_gen_max' && $usercancreate) { // Set max period $object->setMaxPeriod(GETPOSTINT('nb_gen_max')); - } elseif ($action == 'setauto_validate' && $user->hasRight('facture', 'creer')) { + } elseif ($action == 'setauto_validate' && $usercancreate) { // Set auto validate $object->setAutoValidate(GETPOSTINT('auto_validate')); - } elseif ($action == 'setgenerate_pdf' && $user->hasRight('facture', 'creer')) { + } elseif ($action == 'setgenerate_pdf' && $usercancreate) { // Set generate pdf $object->setGeneratepdf(GETPOSTINT('generate_pdf')); - } elseif ($action == 'setmodelpdf' && $user->hasRight('facture', 'creer')) { + } elseif ($action == 'setmodelpdf' && $usercancreate) { // Set model pdf $object->setModelpdf(GETPOST('modelpdf', 'alpha')); - } elseif ($action == 'disable' && $user->hasRight('facture', 'creer')) { + } elseif ($action == 'disable' && $usercancreate) { // Set status disabled $db->begin(); @@ -383,7 +386,7 @@ if (empty($reshook)) { $db->rollback(); setEventMessages($object->error, $object->errors, 'errors'); } - } elseif ($action == 'enable' && $user->hasRight('facture', 'creer')) { + } elseif ($action == 'enable' && $usercancreate) { // Set status enabled $db->begin(); @@ -409,7 +412,7 @@ if (empty($reshook)) { } // Delete line - if ($action == 'confirm_deleteline' && $confirm == 'yes' && $user->hasRight('facture', 'creer')) { + if ($action == 'confirm_deleteline' && $confirm == 'yes' && $usercancreate) { $object->fetch($id); $object->fetch_thirdparty(); @@ -434,7 +437,7 @@ if (empty($reshook)) { $db->rollback(); setEventMessages($line->error, $line->errors, 'errors'); } - } elseif ($action == 'update_extras') { + } elseif ($action == 'update_extras' && $usercancreate) { $object->oldcopy = dol_clone($object, 2); // Fill array 'array_options' with data from update form diff --git a/htdocs/compta/facture/card.php b/htdocs/compta/facture/card.php index 8d82368b230..1e2c7811758 100644 --- a/htdocs/compta/facture/card.php +++ b/htdocs/compta/facture/card.php @@ -87,7 +87,8 @@ $socid = GETPOSTINT('socid'); $action = GETPOST('action', 'aZ09'); $confirm = GETPOST('confirm', 'alpha'); $cancel = GETPOST('cancel', 'alpha'); -$backtopage = GETPOST('backtopage', 'alpha'); +$backtopage = GETPOST('backtopage', 'alpha'); // if not set, a default page will be used +$backtopageforcancel = GETPOST('backtopageforcancel', 'alpha'); // if not set, $backtopage will be used $lineid = GETPOSTINT('lineid'); $userid = GETPOSTINT('userid'); $search_ref = GETPOST('sf_ref', 'alpha') ? GETPOST('sf_ref', 'alpha') : GETPOST('search_ref', 'alpha'); @@ -152,8 +153,9 @@ if (getDolGlobalString('INVOICE_DISALLOW_REOPEN')) { $usercanreopen = false; } $usercanunvalidate = ((!getDolGlobalString('MAIN_USE_ADVANCED_PERMS') && !empty($usercancreate)) || (getDolGlobalString('MAIN_USE_ADVANCED_PERMS') && $user->hasRight('facture', 'invoice_advance', 'unvalidate'))); - $usermustrespectpricemin = ((getDolGlobalString('MAIN_USE_ADVANCED_PERMS') && !$user->hasRight('produit', 'ignore_price_min_advance')) || !getDolGlobalString('MAIN_USE_ADVANCED_PERMS')); + +// Other permissions $usercancreatemargin = $user->hasRight('margins', 'creer'); $usercanreadallmargin = $user->hasRight('margins', 'liretous'); $usercancreatewithdrarequest = $user->hasRight('prelevement', 'bons', 'creer'); @@ -423,7 +425,7 @@ if (empty($reshook)) { if ($result < 0) { dol_print_error($db, $object->error); } - } elseif ($action == 'setretainedwarrantyconditions' && $user->hasRight('facture', 'creer')) { + } elseif ($action == 'setretainedwarrantyconditions' && $usercancreate) { $object->fetch($id); $object->retained_warranty_fk_cond_reglement = 0; // To clean property $result = $object->setRetainedWarrantyPaymentTerms(GETPOSTINT('retained_warranty_fk_cond_reglement')); @@ -443,13 +445,13 @@ if (empty($reshook)) { if ($result < 0) { dol_print_error($db, $object->error); } - } elseif ($action == 'setretainedwarranty' && $user->hasRight('facture', 'creer')) { + } elseif ($action == 'setretainedwarranty' && $usercancreate) { $object->fetch($id); $result = $object->setRetainedWarranty(GETPOSTFLOAT('retained_warranty')); if ($result < 0) { dol_print_error($db, $object->error); } - } elseif ($action == 'setretainedwarrantydatelimit' && $user->hasRight('facture', 'creer')) { + } elseif ($action == 'setretainedwarrantydatelimit' && $usercancreate) { $object->fetch($id); $result = $object->setRetainedWarrantyDateLimit(GETPOSTFLOAT('retained_warranty_date_limit')); if ($result < 0) { @@ -580,7 +582,7 @@ if (empty($reshook)) { } } } - } elseif ($action == 'set_incoterms' && isModEnabled('incoterm')) { // Set incoterm + } elseif ($action == 'set_incoterms' && isModEnabled('incoterm') && $usercancreate) { // Set incoterm $result = $object->setIncoterms(GETPOSTINT('incoterm_id'), GETPOSTINT('location_incoterms')); } elseif ($action == 'setbankaccount' && $usercancreate) { // bank account $result = $object->setBankAccount(GETPOSTINT('fk_account')); @@ -830,7 +832,7 @@ if (empty($reshook)) { } else { setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Reason")), null, 'errors'); } - } elseif ($action == 'confirm_canceled' && $confirm == 'yes') { + } elseif ($action == 'confirm_canceled' && $confirm == 'yes' && $usercancreate) { // Classify "abandoned" $object->fetch($id); $close_code = GETPOST("close_code", 'restricthtml'); @@ -2986,9 +2988,7 @@ if (empty($reshook)) { setEventMessages($langs->trans('ErrorFindNextSituationInvoice'), array(), 'errors'); } } - } elseif ($action == 'import_lines_from_object' - && $usercancreate - && $object->status == Facture::STATUS_DRAFT + } elseif ($action == 'import_lines_from_object' && $usercancreate && $object->status == Facture::STATUS_DRAFT && ($object->type == Facture::TYPE_STANDARD || $object->type == Facture::TYPE_REPLACEMENT || $object->type == Facture::TYPE_DEPOSIT || $object->type == Facture::TYPE_PROFORMA || $object->type == Facture::TYPE_SITUATION)) { // add lines from objectlinked $fromElement = GETPOST('fromelement'); @@ -3082,7 +3082,7 @@ if (empty($reshook)) { include DOL_DOCUMENT_ROOT.'/core/actions_builddoc.inc.php'; - if ($action == 'update_extras') { + if ($action == 'update_extras' && $usercancreate) { $object->oldcopy = dol_clone($object, 2); $attribute_name = GETPOST('attribute', 'restricthtml'); @@ -3106,8 +3106,8 @@ if (empty($reshook)) { } } - if (getDolGlobalString('MAIN_DISABLE_CONTACTS_TAB') && $usercancreate) { - if ($action == 'addcontact') { + if (getDolGlobalString('MAIN_DISABLE_CONTACTS_TAB')) { + if ($action == 'addcontact' && $usercancreate) { $result = $object->fetch($id); if ($result > 0 && $id > 0) { @@ -3127,14 +3127,14 @@ if (empty($reshook)) { setEventMessages($object->error, $object->errors, 'errors'); } } - } elseif ($action == 'swapstatut') { + } elseif ($action == 'swapstatut' && $usercancreate) { // toggle the status of a contact if ($object->fetch($id)) { $result = $object->swapContactStatus(GETPOSTINT('ligne')); } else { dol_print_error($db); } - } elseif ($action == 'deletecontact') { + } elseif ($action == 'deletecontact' && $usercancreate) { // Delete a contact $object->fetch($id); $result = $object->delete_contact($lineid); diff --git a/htdocs/delivery/card.php b/htdocs/delivery/card.php index 9f989484963..b3eb32f5011 100644 --- a/htdocs/delivery/card.php +++ b/htdocs/delivery/card.php @@ -60,16 +60,10 @@ $action = GETPOST('action', 'aZ09'); $confirm = GETPOST('confirm', 'alpha'); $backtopage = GETPOST('backtopage', 'alpha'); -// Security check -$id = GETPOSTINT('id'); -if ($user->socid) { - $socid = $user->socid; -} // Initialize a technical object to manage hooks of page. Note that conf->hooks_modules contains an array of hook context $hookmanager->initHooks(array('deliverycard', 'globalcard')); -$result = restrictedArea($user, 'expedition', $id, 'delivery', 'delivery'); $object = new Delivery($db); $extrafields = new ExtraFields($db); @@ -85,6 +79,20 @@ include DOL_DOCUMENT_ROOT.'/core/actions_fetchobject.inc.php'; // Must be 'inclu $error = 0; +// Security check +$id = GETPOSTINT('id'); +if ($user->socid) { + $socid = $user->socid; +} +$result = restrictedArea($user, 'expedition', $id, 'delivery', 'delivery'); + +$permissiontoread = $user->hasRight('expedition', 'delivery', 'read'); +$permissiontoadd = $user->hasRight('expedition', 'delivery', 'creer'); // Used by the include of actions_addupdatedelete.inc.php and actions_lineupdown.inc.php +$permissiontodelete = $user->hasRight('expedition', 'delivery', 'supprimer') || ($permissiontoadd && isset($object->status) && $object->status == $object::STATUS_DRAFT); +$permissiontovalidate = ((!getDolGlobalString('MAIN_USE_ADVANCED_PERMS') && $user->hasRight('expedition', 'delivery', 'creer')) || (getDolGlobalString('MAIN_USE_ADVANCED_PERMS') && $user->hasRight('expedition', 'delivery_advance', 'validate'))); +$permissionnote = $user->hasRight('expedition', 'delivery', 'creer'); // Used by the include of actions_setnotes.inc.php +$permissiondellink = $user->hasRight('expedition', 'delivery', 'creer'); // Used by the include of actions_dellink.inc.php + /* * Actions @@ -96,7 +104,7 @@ $reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action $permissiondellink = $user->hasRight('expedition', 'delivery', 'supprimer'); // Used by the include of actions_dellink.inc.php include DOL_DOCUMENT_ROOT.'/core/actions_dellink.inc.php'; // Must be 'include', not 'include_once' -if ($action == 'add') { +if ($action == 'add' && $permissiontoadd) { $db->begin(); $object->date_delivery = dol_now(); @@ -135,10 +143,7 @@ if ($action == 'add') { $action = 'create'; } -} elseif ($action == 'confirm_valid' && $confirm == 'yes' && - ((!getDolGlobalString('MAIN_USE_ADVANCED_PERMS') && $user->hasRight('expedition', 'delivery', 'creer')) - || (getDolGlobalString('MAIN_USE_ADVANCED_PERMS') && $user->hasRight('expedition', 'delivery_advance', 'validate'))) -) { +} elseif ($action == 'confirm_valid' && $confirm == 'yes' && $permissiontovalidate) { $result = $object->valid($user); // Define output language @@ -165,7 +170,7 @@ if ($action == 'add') { } } -if ($action == 'confirm_delete' && $confirm == 'yes' && $user->hasRight('expedition', 'delivery', 'supprimer')) { +if ($action == 'confirm_delete' && $confirm == 'yes' && $permissiontodelete) { $db->begin(); $result = $object->delete($user); @@ -182,7 +187,7 @@ if ($action == 'confirm_delete' && $confirm == 'yes' && $user->hasRight('expedit } } -if ($action == 'setdate_delivery' && $user->hasRight('expedition', 'delivery', 'creer')) { +if ($action == 'setdate_delivery' && $permissiontoadd) { $datedelivery = dol_mktime(GETPOSTINT('liv_hour'), GETPOSTINT('liv_min'), 0, GETPOSTINT('liv_month'), GETPOSTINT('liv_day'), GETPOSTINT('liv_year')); $result = $object->setDeliveryDate($user, $datedelivery); if ($result < 0) { @@ -194,7 +199,7 @@ if ($action == 'setdate_delivery' && $user->hasRight('expedition', 'delivery', ' } // Update extrafields -if ($action == 'update_extras') { +if ($action == 'update_extras' && $permissiontoadd) { $object->oldcopy = dol_clone($object, 2); // Fill array 'array_options' with data from update form @@ -218,7 +223,7 @@ if ($action == 'update_extras') { } // Extrafields line -if ($action == 'update_extras_line') { +if ($action == 'update_extras_line' && $permissiontoadd) { $array_options = array(); $num = count($object->lines); @@ -245,7 +250,6 @@ if ($action == 'update_extras_line') { // Actions to build doc $upload_dir = $conf->expedition->dir_output.'/receipt'; -$permissiontoadd = $user->hasRight('expedition', 'creer'); include DOL_DOCUMENT_ROOT.'/core/actions_builddoc.inc.php'; include DOL_DOCUMENT_ROOT.'/core/actions_printing.inc.php'; diff --git a/htdocs/delivery/class/delivery.class.php b/htdocs/delivery/class/delivery.class.php index e2ce2b4bfc1..79e91f53e4e 100644 --- a/htdocs/delivery/class/delivery.class.php +++ b/htdocs/delivery/class/delivery.class.php @@ -119,6 +119,11 @@ class Delivery extends CommonObject public $user_author_id; + const STATUS_DRAFT = 0; + const STATUS_VALIDATED = 1; + const STATUS_CANCELED = -1; + + /** * Constructor * diff --git a/htdocs/don/card.php b/htdocs/don/card.php index 449b3ace269..73b743c9a2e 100644 --- a/htdocs/don/card.php +++ b/htdocs/don/card.php @@ -326,7 +326,7 @@ if (empty($reshook)) { $object->setProject($projectid); } - if ($action == 'update_extras') { + if ($action == 'update_extras' && $user->hasRight('don', 'creer')) { $object->fetch($id); $object->oldcopy = dol_clone($object, 2); diff --git a/htdocs/expedition/card.php b/htdocs/expedition/card.php index a2deb541cc0..d0b5c98e64b 100644 --- a/htdocs/expedition/card.php +++ b/htdocs/expedition/card.php @@ -202,7 +202,7 @@ if (empty($reshook)) { } } - if ($action == 'update_extras') { + if ($action == 'update_extras' && $user->hasRight('expedition', 'creer')) { $object->oldcopy = dol_clone($object, 2); $attribute_name = GETPOST('attribute', 'restricthtml'); diff --git a/htdocs/expedition/shipment.php b/htdocs/expedition/shipment.php index e06113fcb7c..5ea03261b7f 100644 --- a/htdocs/expedition/shipment.php +++ b/htdocs/expedition/shipment.php @@ -82,6 +82,11 @@ if ($user->socid) { $result = restrictedArea($user, 'expedition', 0, ''); // We use 0 for id, because there is no particular shipment on this tab, only id of order is known +$permissiontoread = $user->hasRight('expedition', 'lire'); +$permissiontoadd = $user->hasRight('expedition', 'creer'); // Used by the include of actions_addupdatedelete.inc.php and actions_lineupdown.inc.php +$permissiontodelete = $user->hasRight('expedition', 'supprimer') || ($permissiontoadd && isset($object->status) && $object->status == $object::STATUS_DRAFT); +$permissionnote = $user->hasRight('expedition', 'creer'); // Used by the include of actions_setnotes.inc.php +$permissiondellink = $user->hasRight('expedition', 'creer'); // Used by the include of actions_dellink.inc.php /* @@ -96,15 +101,15 @@ if ($reshook < 0) { if (empty($reshook)) { // Categorisation dans projet - if ($action == 'classin') { + if ($action == 'classin' && $permissiontoadd) { $object->fetch($id); $object->setProject(GETPOSTINT('projectid')); } - if ($action == 'confirm_cloture' && GETPOST('confirm', 'alpha') == 'yes') { + if ($action == 'confirm_cloture' && GETPOST('confirm', 'alpha') == 'yes' && $permissiontoadd) { $object->fetch($id); $result = $object->cloture($user); - } elseif ($action == 'setref_client' && $user->hasRight('commande', 'creer')) { + } elseif ($action == 'setref_client' && $permissiontoadd) { // Positionne ref commande client $result = $object->set_ref_client($user, GETPOST('ref_client')); if ($result < 0) { @@ -112,7 +117,7 @@ if (empty($reshook)) { } } - if ($action == 'setdatedelivery' && $user->hasRight('commande', 'creer')) { + if ($action == 'setdatedelivery' && $permissiontoadd) { $datedelivery = dol_mktime(GETPOSTINT('liv_hour'), GETPOSTINT('liv_min'), 0, GETPOSTINT('liv_month'), GETPOSTINT('liv_day'), GETPOSTINT('liv_year')); $object->fetch($id); @@ -121,17 +126,7 @@ if (empty($reshook)) { setEventMessages($object->error, $object->errors, 'errors'); } } - /* - if ($action == 'setdeliveryaddress' && $user->hasRight('commande', 'creer')) - { - $object = new Commande($db); - $object->fetch($id); - $object->setDeliveryAddress(GETPOST('delivery_address_id','int')); - if ($result < 0) - setEventMessages($object->error, $object->errors, 'errors'); - } - */ - if ($action == 'setmode' && $user->hasRight('commande', 'creer')) { + if ($action == 'setmode' && $permissiontoadd) { $object->fetch($id); $result = $object->setPaymentMethods(GETPOSTINT('mode_reglement_id')); if ($result < 0) { @@ -139,7 +134,7 @@ if (empty($reshook)) { } } - if ($action == 'setavailability' && $user->hasRight('commande', 'creer')) { + if ($action == 'setavailability' && $permissiontoadd) { $object->fetch($id); $result = $object->availability(GETPOST('availability_id')); if ($result < 0) { @@ -147,7 +142,7 @@ if (empty($reshook)) { } } - if ($action == 'setdemandreason' && $user->hasRight('commande', 'creer')) { + if ($action == 'setdemandreason' && $permissiontoadd) { $object->fetch($id); $result = $object->demand_reason(GETPOST('demand_reason_id')); if ($result < 0) { @@ -155,7 +150,7 @@ if (empty($reshook)) { } } - if ($action == 'setconditions' && $user->hasRight('commande', 'creer')) { + if ($action == 'setconditions' && $permissiontoadd) { $object->fetch($id); $result = $object->setPaymentTerms(GETPOSTINT('cond_reglement_id')); if ($result < 0) { @@ -170,7 +165,7 @@ if (empty($reshook)) { } // shipping method - if ($action == 'setshippingmethod' && $user->hasRight('commande', 'creer')) { + if ($action == 'setshippingmethod' && $permissiontoadd) { $object->fetch($id); $result = $object->setShippingMethod(GETPOSTINT('shipping_method_id')); if ($result < 0) { @@ -179,7 +174,7 @@ if (empty($reshook)) { } // warehouse - if ($action == 'setwarehouse' && $user->hasRight('commande', 'creer')) { + if ($action == 'setwarehouse' && $permissiontoadd) { $object->fetch($id); $result = $object->setWarehouse(GETPOSTINT('warehouse_id')); if ($result < 0) { @@ -187,7 +182,7 @@ if (empty($reshook)) { } } - if ($action == 'update_extras') { + if ($action == 'update_extras' && $permissiontoadd) { $object->oldcopy = dol_clone($object, 2); // Fill array 'array_options' with data from update form @@ -210,7 +205,7 @@ if (empty($reshook)) { } } - if ($action == 'set_thirdparty' && $user->hasRight('commande', 'creer')) { + if ($action == 'set_thirdparty' && $permissiontoadd) { $object->fetch($id); $object->setValueFrom('fk_soc', $socid, '', '', 'date', '', $user, 'ORDER_MODIFY'); @@ -283,8 +278,8 @@ if ($id > 0 || !empty($ref)) { $morehtmlref = '
'; // Ref customer - $morehtmlref .= $form->editfieldkey("RefCustomer", 'ref_customer', $object->ref_client, $object, $user->hasRight('commande', 'creer'), 'string', '', 0, 1); - $morehtmlref .= $form->editfieldval("RefCustomer", 'ref_customer', $object->ref_client, $object, $user->hasRight('commande', 'creer'), 'string', '', null, null, '', 1); + $morehtmlref .= $form->editfieldkey("RefCustomer", 'ref_customer', $object->ref_client, $object, $permissiontoadd, 'string', '', 0, 1); + $morehtmlref .= $form->editfieldval("RefCustomer", 'ref_customer', $object->ref_client, $object, $permissiontoadd, 'string', '', null, null, '', 1); // Thirdparty $morehtmlref .= '
'.$soc->getNomUrl(1); // Project @@ -423,7 +418,7 @@ if ($id > 0 || !empty($ref)) { print ''; - if ($action != 'editwarehouse' && $user->hasRight('commande', 'creer')) { + if ($action != 'editwarehouse' && $permissiontoadd) { print ''; } print '
'; print $langs->trans('Warehouse'); print 'id.'">'.img_edit($langs->trans('SetWarehouse'), 1).'
'; @@ -513,7 +508,7 @@ if ($id > 0 || !empty($ref)) { print ''; } -if ($object->element == 'stock') { +if ($object->element == 'stockmouvement') { print ''; print ''; print ''; - print 'element == 'stock' ? '' : ' class="fieldrequired"').'>'.$langs->trans("batch_number").''; } -if ($object->element == 'stock') { +if ($object->element == 'stockmouvement') { print ''; print ''; // Serial / Eat-by date if (isModEnabled('productbatch') && (($object->element == 'product' && $object->hasbatch()) -|| ($object->element == 'stock')) +|| ($object->element == 'stockmouvement')) ) { print ''; - print 'element == 'stock' ? '' : ' class="fieldrequired"').'>'.$langs->trans("batch_number").'
'; print $langs->trans('IncotermLabel'); print ''; - if ($user->hasRight('commande', 'creer')) { + if ($permissiontoadd) { print ''.img_edit().''; } else { print ' '; diff --git a/htdocs/expensereport/card.php b/htdocs/expensereport/card.php index ed74fc6d189..ac16d2a69a1 100644 --- a/htdocs/expensereport/card.php +++ b/htdocs/expensereport/card.php @@ -352,7 +352,7 @@ if (empty($reshook)) { } } - if ($action == 'update_extras') { + if ($action == 'update_extras' && $user->hasRight('expensereport', 'creer')) { $object->oldcopy = dol_clone($object, 2); // Fill array 'array_options' with data from update form diff --git a/htdocs/fichinter/card.php b/htdocs/fichinter/card.php index 00598b8f9ca..8dd6cd6fe21 100644 --- a/htdocs/fichinter/card.php +++ b/htdocs/fichinter/card.php @@ -749,7 +749,7 @@ if (empty($reshook)) { $permissiontoadd = $user->hasRight('ficheinter', 'creer'); include DOL_DOCUMENT_ROOT.'/core/actions_builddoc.inc.php'; - if ($action == 'update_extras') { + if ($action == 'update_extras' && $user->hasRight('ficheinter', 'creer')) { $object->oldcopy = dol_clone($object, 2); $attribute_name = GETPOST('attribute', 'restricthtml'); diff --git a/htdocs/fourn/facture/card-rec.php b/htdocs/fourn/facture/card-rec.php index f135c963f10..7fefb8a3c44 100644 --- a/htdocs/fourn/facture/card-rec.php +++ b/htdocs/fourn/facture/card-rec.php @@ -404,7 +404,7 @@ if (empty($reshook)) { $db->rollback(); setEventMessages($line->error, $line->errors, 'errors'); } - } elseif ($action == 'update_extras') { + } elseif ($action == 'update_extras' && $usercancreate) { $object->oldcopy = dol_clone($object, 2); // Fill array 'array_options' with data from update form diff --git a/htdocs/fourn/facture/card.php b/htdocs/fourn/facture/card.php index 424f7f8405a..5424efd5754 100644 --- a/htdocs/fourn/facture/card.php +++ b/htdocs/fourn/facture/card.php @@ -1981,7 +1981,7 @@ if (empty($reshook)) { exit; } } - if ($action == 'update_extras') { + if ($action == 'update_extras' && $usercancreate) { $object->oldcopy = dol_clone($object, 2); // Fill array 'array_options' with data from add form diff --git a/htdocs/holiday/card.php b/htdocs/holiday/card.php index f73a1df8f99..8a2297f5f93 100644 --- a/htdocs/holiday/card.php +++ b/htdocs/holiday/card.php @@ -155,149 +155,140 @@ if (empty($reshook)) { } // Add leave request - if ($action == 'add') { - // If no right to create a request - if (!$cancreate) { + if ($action == 'add' && $cancreate) { + $object = new Holiday($db); + + $db->begin(); + + $date_debut = dol_mktime(0, 0, 0, GETPOST('date_debut_month'), GETPOST('date_debut_day'), GETPOST('date_debut_year')); + $date_fin = dol_mktime(0, 0, 0, GETPOST('date_fin_month'), GETPOST('date_fin_day'), GETPOST('date_fin_year')); + $date_debut_gmt = dol_mktime(0, 0, 0, GETPOST('date_debut_month'), GETPOST('date_debut_day'), GETPOST('date_debut_year'), 1); + $date_fin_gmt = dol_mktime(0, 0, 0, GETPOST('date_fin_month'), GETPOST('date_fin_day'), GETPOST('date_fin_year'), 1); + $starthalfday = GETPOST('starthalfday'); + $endhalfday = GETPOST('endhalfday'); + $type = GETPOST('type'); + $halfday = 0; + if ($starthalfday == 'afternoon' && $endhalfday == 'morning') { + $halfday = 2; + } elseif ($starthalfday == 'afternoon') { + $halfday = -1; + } elseif ($endhalfday == 'morning') { + $halfday = 1; + } + + $approverid = GETPOSTINT('valideur'); + $description = trim(GETPOST('description', 'restricthtml')); + + // Check that leave is for a user inside the hierarchy or advanced permission for all is set + if (!$cancreateall) { + if (!getDolGlobalString('MAIN_USE_ADVANCED_PERMS')) { + if (!$user->hasRight('holiday', 'write')) { + $error++; + setEventMessages($langs->trans("NotEnoughPermissions"), null, 'errors'); + } elseif (!in_array($fuserid, $childids)) { + $error++; + setEventMessages($langs->trans("UserNotInHierachy"), null, 'errors'); + $action = 'create'; + } + } else { + if (!$user->hasRight('holiday', 'write') && !$user->hasRight('holiday', 'writeall_advance')) { + $error++; + setEventMessages($langs->trans("NotEnoughPermissions"), null, 'errors'); + } elseif (!$user->hasRight('holiday', 'writeall_advance') && !in_array($fuserid, $childids)) { + $error++; + setEventMessages($langs->trans("UserNotInHierachy"), null, 'errors'); + $action = 'create'; + } + } + } + + // If no type + if ($type <= 0) { + setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Type")), null, 'errors'); $error++; - setEventMessages($langs->trans('CantCreateCP'), null, 'errors'); $action = 'create'; } + // If no start date + if (empty($date_debut)) { + setEventMessages($langs->trans("NoDateDebut"), null, 'errors'); + $error++; + $action = 'create'; + } + // If no end date + if (empty($date_fin)) { + setEventMessages($langs->trans("NoDateFin"), null, 'errors'); + $error++; + $action = 'create'; + } + // If start date after end date + if ($date_debut > $date_fin) { + setEventMessages($langs->trans("ErrorEndDateCP"), null, 'errors'); + $error++; + $action = 'create'; + } + + // Check if there is already holiday for this period + $verifCP = $object->verifDateHolidayCP($fuserid, $date_debut, $date_fin, $halfday); + if (!$verifCP) { + setEventMessages($langs->trans("alreadyCPexist"), null, 'errors'); + $error++; + $action = 'create'; + } + + // If there is no Business Days within request + $nbopenedday = num_open_day($date_debut_gmt, $date_fin_gmt, 0, 1, $halfday); + if ($nbopenedday < 0.5) { + setEventMessages($langs->trans("ErrorDureeCP"), null, 'errors'); // No working day + $error++; + $action = 'create'; + } + + // If no validator designated + if ($approverid < 1) { + setEventMessages($langs->transnoentitiesnoconv('InvalidValidatorCP'), null, 'errors'); + $error++; + } + + $approverslist = $object->fetch_users_approver_holiday(); + if (!in_array($approverid, $approverslist)) { + setEventMessages($langs->transnoentitiesnoconv('InvalidValidator'), null, 'errors'); + $error++; + } + + // Fill array 'array_options' with data from add form + $ret = $extrafields->setOptionalsFromPost(null, $object); + if ($ret < 0) { + $error++; + } + + $result = 0; + if (!$error) { - $object = new Holiday($db); + $object->fk_user = $fuserid; + $object->description = $description; + $object->fk_validator = $approverid; + $object->fk_type = $type; + $object->date_debut = $date_debut; + $object->date_fin = $date_fin; + $object->halfday = $halfday; + $object->entity = $conf->entity; - $db->begin(); - - $date_debut = dol_mktime(0, 0, 0, GETPOST('date_debut_month'), GETPOST('date_debut_day'), GETPOST('date_debut_year')); - $date_fin = dol_mktime(0, 0, 0, GETPOST('date_fin_month'), GETPOST('date_fin_day'), GETPOST('date_fin_year')); - $date_debut_gmt = dol_mktime(0, 0, 0, GETPOST('date_debut_month'), GETPOST('date_debut_day'), GETPOST('date_debut_year'), 1); - $date_fin_gmt = dol_mktime(0, 0, 0, GETPOST('date_fin_month'), GETPOST('date_fin_day'), GETPOST('date_fin_year'), 1); - $starthalfday = GETPOST('starthalfday'); - $endhalfday = GETPOST('endhalfday'); - $type = GETPOST('type'); - $halfday = 0; - if ($starthalfday == 'afternoon' && $endhalfday == 'morning') { - $halfday = 2; - } elseif ($starthalfday == 'afternoon') { - $halfday = -1; - } elseif ($endhalfday == 'morning') { - $halfday = 1; - } - - $approverid = GETPOSTINT('valideur'); - $description = trim(GETPOST('description', 'restricthtml')); - - // Check that leave is for a user inside the hierarchy or advanced permission for all is set - if (!$cancreateall) { - if (!getDolGlobalString('MAIN_USE_ADVANCED_PERMS')) { - if (!$user->hasRight('holiday', 'write')) { - $error++; - setEventMessages($langs->trans("NotEnoughPermissions"), null, 'errors'); - } elseif (!in_array($fuserid, $childids)) { - $error++; - setEventMessages($langs->trans("UserNotInHierachy"), null, 'errors'); - $action = 'create'; - } - } else { - if (!$user->hasRight('holiday', 'write') && !$user->hasRight('holiday', 'writeall_advance')) { - $error++; - setEventMessages($langs->trans("NotEnoughPermissions"), null, 'errors'); - } elseif (!$user->hasRight('holiday', 'writeall_advance') && !in_array($fuserid, $childids)) { - $error++; - setEventMessages($langs->trans("UserNotInHierachy"), null, 'errors'); - $action = 'create'; - } - } - } - - // If no type - if ($type <= 0) { - setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Type")), null, 'errors'); - $error++; - $action = 'create'; - } - - // If no start date - if (empty($date_debut)) { - setEventMessages($langs->trans("NoDateDebut"), null, 'errors'); - $error++; - $action = 'create'; - } - // If no end date - if (empty($date_fin)) { - setEventMessages($langs->trans("NoDateFin"), null, 'errors'); - $error++; - $action = 'create'; - } - // If start date after end date - if ($date_debut > $date_fin) { - setEventMessages($langs->trans("ErrorEndDateCP"), null, 'errors'); - $error++; - $action = 'create'; - } - - // Check if there is already holiday for this period - $verifCP = $object->verifDateHolidayCP($fuserid, $date_debut, $date_fin, $halfday); - if (!$verifCP) { - setEventMessages($langs->trans("alreadyCPexist"), null, 'errors'); - $error++; - $action = 'create'; - } - - // If there is no Business Days within request - $nbopenedday = num_open_day($date_debut_gmt, $date_fin_gmt, 0, 1, $halfday); - if ($nbopenedday < 0.5) { - setEventMessages($langs->trans("ErrorDureeCP"), null, 'errors'); // No working day - $error++; - $action = 'create'; - } - - // If no validator designated - if ($approverid < 1) { - setEventMessages($langs->transnoentitiesnoconv('InvalidValidatorCP'), null, 'errors'); + $result = $object->create($user); + if ($result <= 0) { + setEventMessages($object->error, $object->errors, 'errors'); $error++; } + } - $approverslist = $object->fetch_users_approver_holiday(); - if (!in_array($approverid, $approverslist)) { - setEventMessages($langs->transnoentitiesnoconv('InvalidValidator'), null, 'errors'); - $error++; - } + // If no SQL error we redirect to the request card + if (!$error) { + $db->commit(); - // Fill array 'array_options' with data from add form - $ret = $extrafields->setOptionalsFromPost(null, $object); - if ($ret < 0) { - $error++; - } - - $result = 0; - - if (!$error) { - $object->fk_user = $fuserid; - $object->description = $description; - $object->fk_validator = $approverid; - $object->fk_type = $type; - $object->date_debut = $date_debut; - $object->date_fin = $date_fin; - $object->halfday = $halfday; - $object->entity = $conf->entity; - - $result = $object->create($user); - if ($result <= 0) { - setEventMessages($object->error, $object->errors, 'errors'); - $error++; - } - } - - // If no SQL error we redirect to the request card - if (!$error) { - $db->commit(); - - header('Location: '.$_SERVER["PHP_SELF"].'?id='.$object->id); - exit; - } else { - $db->rollback(); - } + header('Location: '.$_SERVER["PHP_SELF"].'?id='.$object->id); + exit; + } else { + $db->rollback(); } } @@ -324,7 +315,7 @@ if (empty($reshook)) { $action = ''; } - if ($action == 'update' && !GETPOSTISSET('savevalidator')) { + if ($action == 'update' && !GETPOSTISSET('savevalidator')) { // Test on permission done later $date_debut = dol_mktime(0, 0, 0, GETPOST('date_debut_month'), GETPOST('date_debut_day'), GETPOST('date_debut_year')); $date_fin = dol_mktime(0, 0, 0, GETPOST('date_fin_month'), GETPOST('date_fin_day'), GETPOST('date_fin_year')); $date_debut_gmt = dol_mktime(0, 0, 0, GETPOST('date_debut_month'), GETPOST('date_debut_day'), GETPOST('date_debut_year'), 1); @@ -459,7 +450,7 @@ if (empty($reshook)) { } // Action validate (+ send email for approval to the expected approver) - if ($action == 'confirm_send') { + if ($action == 'confirm_send') { // Test on permission done later $object->fetch($id); // If draft and owner of leave diff --git a/htdocs/product/card.php b/htdocs/product/card.php index 458bda8d606..0bee0ac2500 100644 --- a/htdocs/product/card.php +++ b/htdocs/product/card.php @@ -431,14 +431,14 @@ if (empty($reshook)) { include DOL_DOCUMENT_ROOT.'/core/actions_printing.inc.php'; // Barcode type - if ($action == 'setfk_barcode_type' && $createbarcode) { + if ($action == 'setfk_barcode_type' && $usercancreate) { $result = $object->setValueFrom('fk_barcode_type', GETPOST('fk_barcode_type'), '', null, 'text', '', $user, 'PRODUCT_MODIFY'); header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id); exit; } // Barcode value - if ($action == 'setbarcode' && $createbarcode) { + if ($action == 'setbarcode' && $usercancreate) { $result = $object->check_barcode(GETPOST('barcode'), GETPOST('barcode_type_code')); if ($result >= 0) { @@ -463,7 +463,7 @@ if (empty($reshook)) { } // Quick edit for extrafields - if ($action == 'update_extras') { + if ($action == 'update_extras' && $usercancreate) { $object->oldcopy = dol_clone($object, 2); // Fill array 'array_options' with data from update form @@ -1055,9 +1055,12 @@ if (empty($reshook)) { } - // Add product into object - if ($object->id > 0 && $action == 'addin') { + // Add product into object (when PRODUCT_ADD_FORM_ADD_TO is set) + if ($object->id > 0 && $action == 'addin') { // Test on permission is done just after $thirpdartyid = 0; + $permissiontoaddline = false; + + // Get object and test permission if (GETPOST('propalid') > 0) { $propal = new Propal($db); $result = $propal->fetch(GETPOST('propalid')); @@ -1066,6 +1069,7 @@ if (empty($reshook)) { exit; } $thirpdartyid = $propal->socid; + $permissiontoaddline = $user->hasRight('propal', 'creer'); } elseif (GETPOST('commandeid') > 0) { $commande = new Commande($db); $result = $commande->fetch(GETPOST('commandeid')); @@ -1074,6 +1078,7 @@ if (empty($reshook)) { exit; } $thirpdartyid = $commande->socid; + $permissiontoaddline = $user->hasRight('commande', 'creer'); } elseif (GETPOST('factureid') > 0) { $facture = new Facture($db); $result = $facture->fetch(GETPOST('factureid')); @@ -1082,6 +1087,7 @@ if (empty($reshook)) { exit; } $thirpdartyid = $facture->socid; + $permissiontoaddline = $user->hasRight('facture', 'creer'); } if ($thirpdartyid > 0) { @@ -1142,7 +1148,7 @@ if (empty($reshook)) { } } - if (GETPOST('propalid') > 0) { + if (GETPOST('propalid') > 0 && $permissiontoaddline) { // Define cost price for margin calculation $buyprice = 0; if (($result = $propal->defineBuyPrice($pu_ht, price2num(GETPOST('remise_percent'), '', 2), $object->id)) < 0) { @@ -1182,7 +1188,7 @@ if (empty($reshook)) { } setEventMessages($langs->trans("ErrorUnknown").": $result", null, 'errors'); - } elseif (GETPOST('commandeid') > 0) { + } elseif (GETPOST('commandeid') > 0 && $permissiontoaddline) { // Define cost price for margin calculation $buyprice = 0; if (($result = $commande->defineBuyPrice($pu_ht, price2num(GETPOST('remise_percent'), '', 2), $object->id)) < 0) { @@ -1222,7 +1228,9 @@ if (empty($reshook)) { header("Location: ".DOL_URL_ROOT."/commande/card.php?id=".urlencode((string) ($commande->id))); exit; } - } elseif (GETPOST('factureid') > 0) { + + setEventMessages($langs->trans("ErrorUnknown").": $result", null, 'errors'); + } elseif (GETPOST('factureid') > 0 && $permissiontoaddline) { // Define cost price for margin calculation $buyprice = 0; if (($result = $facture->defineBuyPrice($pu_ht, price2num(GETPOST('remise_percent'), '', 2), $object->id)) < 0) { @@ -1267,6 +1275,8 @@ if (empty($reshook)) { header("Location: ".DOL_URL_ROOT."/compta/facture/card.php?facid=".$facture->id); exit; } + + setEventMessages($langs->trans("ErrorUnknown").": $result", null, 'errors'); } } else { $action = ""; @@ -3085,7 +3095,7 @@ if (getDolGlobalString('PRODUCT_ADD_FORM_ADD_TO') && $object->id && ($action == } } - //If any text is going to be printed, then we show the table + // If any text is going to be printed, then we show the table if (!empty($html)) { print '
'; print ''; diff --git a/htdocs/product/stock/card.php b/htdocs/product/stock/card.php index c69ed74ff58..34843626dc5 100644 --- a/htdocs/product/stock/card.php +++ b/htdocs/product/stock/card.php @@ -94,9 +94,9 @@ if ($id > 0 || !empty($ref)) { } } -$usercanread = (($user->hasRight('stock', 'lire'))); -$usercancreate = (($user->hasRight('stock', 'creer'))); -$usercandelete = (($user->hasRight('stock', 'supprimer'))); +$usercanread = $user->hasRight('stock', 'lire'); +$usercancreate = $user->hasRight('stock', 'creer'); +$usercandelete = $user->hasRight('stock', 'supprimer'); /* @@ -198,8 +198,8 @@ if (empty($reshook)) { } } - // Modification entrepot - if ($action == 'update' && !$cancel) { + // Update warehouse + if ($action == 'update' && !$cancel && $user->hasRight('stock', 'creer')) { if ($object->fetch($id)) { $object->label = GETPOST("libelle"); $object->fk_parent = GETPOST("fk_parent"); @@ -239,7 +239,7 @@ if (empty($reshook)) { $action = 'edit'; setEventMessages($object->error, $object->errors, 'errors'); } - } elseif ($action == 'update_extras') { + } elseif ($action == 'update_extras' && $user->hasRight('stock', 'creer')) { $object->oldcopy = dol_clone($object, 2); // Fill array 'array_options' with data from update form diff --git a/htdocs/product/stock/movement_list.php b/htdocs/product/stock/movement_list.php index 496b60f47de..312ff774367 100644 --- a/htdocs/product/stock/movement_list.php +++ b/htdocs/product/stock/movement_list.php @@ -980,11 +980,11 @@ if ((empty($action) || $action == 'list') && $id > 0) { // modified by hook if (empty($reshook)) { if ($user->hasRight('stock', 'mouvement', 'creer')) { - print ''.$langs->trans("CorrectStock").''; + print ''.$langs->trans("TransferStock").''; } if ($user->hasRight('stock', 'mouvement', 'creer')) { - print ''.$langs->trans("TransferStock").''; + print ''.$langs->trans("CorrectStock").''; } } diff --git a/htdocs/product/stock/productlot_card.php b/htdocs/product/stock/productlot_card.php index a904c7df52b..d1a05e65773 100644 --- a/htdocs/product/stock/productlot_card.php +++ b/htdocs/product/stock/productlot_card.php @@ -108,20 +108,17 @@ if ($id || $ref) { // Initialize a technical object to manage hooks of modules. Note that conf->hooks_modules contains array array $hookmanager->initHooks(array('productlotcard', 'globalcard')); - -$permissionnote = $user->hasRight('stock', 'creer'); // Used by the include of actions_setnotes.inc.php -$permissiondellink = $user->hasRight('stock', 'creer'); // Used by the include of actions_dellink.inc.php -$permissiontoadd = $user->hasRight('stock', 'creer'); // Used by the include of actions_addupdatedelete.inc.php and actions_lineupdown.inc.php +$upload_dir = $conf->productbatch->multidir_output[$conf->entity]; $usercanread = $user->hasRight('produit', 'lire'); $usercancreate = $user->hasRight('produit', 'creer'); $usercandelete = $user->hasRight('produit', 'supprimer'); -$upload_dir = $conf->productbatch->multidir_output[$conf->entity]; - $permissiontoread = $usercanread; $permissiontoadd = $usercancreate; $permissiontodelete = $usercandelete; +$permissionnote = $user->hasRight('produit', 'creer'); // Used by the include of actions_setnotes.inc.php +$permissiondellink = $user->hasRight('produit', 'creer'); // Used by the include of actions_setnotes.inc.php // Security check if (!isModEnabled('productbatch')) { @@ -153,7 +150,7 @@ if (empty($reshook)) { $backurlforlist = dol_buildpath('/product/stock/productlot_list.php', 1); - if ($action == 'seteatby' && $user->hasRight('stock', 'creer') && ! GETPOST('cancel', 'alpha')) { + if ($action == 'seteatby' && $permissiontoadd && ! GETPOST('cancel', 'alpha')) { $newvalue = dol_mktime(12, 0, 0, GETPOSTINT('eatbymonth'), GETPOSTINT('eatbyday'), GETPOSTINT('eatbyyear')); // check parameters @@ -178,7 +175,7 @@ if (empty($reshook)) { } } - if ($action == 'setsellby' && $user->hasRight('stock', 'creer') && ! GETPOST('cancel', 'alpha')) { + if ($action == 'setsellby' && $permissiontoadd && ! GETPOST('cancel', 'alpha')) { $newvalue = dol_mktime(12, 0, 0, GETPOSTINT('sellbymonth'), GETPOSTINT('sellbyday'), GETPOSTINT('sellbyyear')); // check parameters @@ -203,7 +200,7 @@ if (empty($reshook)) { } } - if ($action == 'seteol_date' && $user->hasRight('stock', 'creer') && ! GETPOST('cancel', 'alpha')) { + if ($action == 'seteol_date' && $permissiontoadd && ! GETPOST('cancel', 'alpha')) { $newvalue = dol_mktime(12, 0, 0, GETPOSTINT('eol_datemonth'), GETPOSTINT('eol_dateday'), GETPOSTINT('eol_dateyear')); $result = $object->setValueFrom('eol_date', $newvalue, '', null, 'date', '', $user, 'PRODUCTLOT_MODIFY'); if ($result < 0) { @@ -214,7 +211,7 @@ if (empty($reshook)) { } } - if ($action == 'setmanufacturing_date' && $user->hasRight('stock', 'creer') && ! GETPOST('cancel', 'alpha')) { + if ($action == 'setmanufacturing_date' && $permissiontoadd && ! GETPOST('cancel', 'alpha')) { $newvalue = dol_mktime(12, 0, 0, GETPOSTINT('manufacturing_datemonth'), GETPOSTINT('manufacturing_dateday'), GETPOSTINT('manufacturing_dateyear')); $result = $object->setValueFrom('manufacturing_date', $newvalue, '', null, 'date', '', $user, 'PRODUCTLOT_MODIFY'); if ($result < 0) { @@ -225,7 +222,7 @@ if (empty($reshook)) { } } - if ($action == 'setscrapping_date' && $user->hasRight('stock', 'creer') && ! GETPOST('cancel', 'alpha')) { + if ($action == 'setscrapping_date' && $permissiontoadd && ! GETPOST('cancel', 'alpha')) { $newvalue = dol_mktime(12, 0, 0, GETPOSTINT('scrapping_datemonth'), GETPOSTINT('scrapping_dateday'), GETPOSTINT('scrapping_dateyear')); $result = $object->setValueFrom('scrapping_date', $newvalue, '', null, 'date', '', $user, 'PRODUCTLOT_MODIFY'); if ($result < 0) { @@ -236,7 +233,7 @@ if (empty($reshook)) { } } - /* if ($action == 'setcommissionning_date' && $user->hasRight('stock', 'creer') && ! GETPOST('cancel', 'alpha')) { + /* if ($action == 'setcommissionning_date' && $permissiontoadd && ! GETPOST('cancel', 'alpha')) { $newvalue = dol_mktime(12, 0, 0, GETPOST('commissionning_datemonth', 'int'), GETPOST('commissionning_dateday', 'int'), GETPOST('commissionning_dateyear', 'int')); $result = $object->setValueFrom('commissionning_date', $newvalue, '', null, 'date', '', $user, 'PRODUCTLOT_MODIFY'); if ($result < 0) { @@ -247,7 +244,7 @@ if (empty($reshook)) { } } */ - if ($action == 'setqc_frequency' && $user->hasRight('stock', 'creer') && ! GETPOST('cancel', 'alpha')) { + if ($action == 'setqc_frequency' && $permissiontoadd && ! GETPOST('cancel', 'alpha')) { $result = $object->setValueFrom('qc_frequency', GETPOST('qc_frequency'), '', null, 'int', '', $user, 'PRODUCT_MODIFY'); if ($result < 0) { // Prévoir un test de format de durée setEventMessages($object->error, null, 'errors'); @@ -262,7 +259,7 @@ if (empty($reshook)) { // Actions cancel, add, update, update_extras, confirm_validate, confirm_delete, confirm_deleteline, confirm_clone, confirm_close, confirm_setdraft, confirm_reopen include DOL_DOCUMENT_ROOT.'/core/actions_addupdatedelete.inc.php'; /* - if ($action == 'update_extras') { + if ($action == 'update_extras' && $permissiontoadd) { $object->oldcopy = dol_clone($object, 2); // Fill array 'array_options' with data from update form @@ -284,7 +281,7 @@ if (empty($reshook)) { } // Action to add record - if ($action == 'add') { + if ($action == 'add' && $permissiontoadd) { if (GETPOST('cancel', 'alpha')) { $urltogo = $backtopage ? $backtopage : dol_buildpath('/stock/list.php', 1); header("Location: ".$urltogo); @@ -325,10 +322,12 @@ if (empty($reshook)) { } // Cancel - if ($action == 'update' && GETPOST('cancel', 'alpha')) $action = 'view'; + if ($action == 'update' && GETPOST('cancel', 'alpha') && $permissiontoadd) { + $action = 'view'; + } // Action to update record - if ($action == 'update' && !GETPOST('cancel', 'alpha')) { + if ($action == 'update' && !GETPOST('cancel', 'alpha') && $permissiontoadd) { $error = 0; $object->entity = GETPOST('entity', 'int'); @@ -359,7 +358,7 @@ if (empty($reshook)) { } // Action to delete - if ($action == 'confirm_delete') { + if ($action == 'confirm_delete' && $permissiontodelete) { $result = $object->delete($user); if ($result > 0) { // Delete OK diff --git a/htdocs/product/stock/tpl/stockcorrection.tpl.php b/htdocs/product/stock/tpl/stockcorrection.tpl.php index 708c527ee6a..03db7871053 100644 --- a/htdocs/product/stock/tpl/stockcorrection.tpl.php +++ b/htdocs/product/stock/tpl/stockcorrection.tpl.php @@ -153,7 +153,7 @@ if ($object->element == 'product') { print img_picto('', 'stock', 'class="pictofixedwidth"').$formproduct->selectWarehouses($ident, 'id_entrepot', 'warehouseopen,warehouseinternal', 1, 0, 0, '', 0, 0, null, 'minwidth100 maxwidth300 widthcentpercentminusx'); print '
'.$langs->trans("Product").''; print img_picto('', 'product'); @@ -162,7 +162,7 @@ if ($object->element == 'stock') { } print ''.$langs->trans("NumberOfUnit").''; -if ($object->element == 'product' || $object->element == 'stock') { +if ($object->element == 'product' || $object->element == 'stockmouvement') { print '
'; + print 'element == 'stockmouvement' ? '' : ' class="fieldrequired"').'>'.$langs->trans("batch_number").''; if ($pdluoid > 0) { // If form was opened for a specific pdluoid, field is disabled print ''; diff --git a/htdocs/product/stock/tpl/stocktransfer.tpl.php b/htdocs/product/stock/tpl/stocktransfer.tpl.php index 13f54ce6b56..c7bac77a67b 100644 --- a/htdocs/product/stock/tpl/stocktransfer.tpl.php +++ b/htdocs/product/stock/tpl/stocktransfer.tpl.php @@ -78,7 +78,7 @@ if ($object->element == 'product') { print $formproduct->selectWarehouses($selected, 'id_entrepot', $warehousestatus, 1, 0, 0, '', 0, 0, array(), 'minwidth75 maxwidth300 widthcentpercentminusx'); print ''.$langs->trans("Product").''; print img_picto('', 'product'); @@ -95,10 +95,10 @@ print '
'; + print 'element == 'stockmouvement' ? '' : ' class="fieldrequired"').'>'.$langs->trans("batch_number").''; if ($pdluoid > 0) { // If form was opened for a specific pdluoid, field is disabled print ''; diff --git a/htdocs/product/traduction.php b/htdocs/product/traduction.php index 0eb8369a4ef..24f3896379d 100644 --- a/htdocs/product/traduction.php +++ b/htdocs/product/traduction.php @@ -67,6 +67,10 @@ if ($object->id > 0) { restrictedArea($user, 'produit|service', $fieldvalue, 'product&product', '', '', $fieldtype); } +// Permissions +$usercancreate = (($object->type == Product::TYPE_PRODUCT && $user->hasRight('produit', 'creer')) || ($object->type == Product::TYPE_SERVICE && $user->hasRight('service', 'creer'))); + + /* * Actions */ @@ -82,7 +86,7 @@ if (empty($reshook)) { $action = ''; } - if ($action == 'delete' && GETPOST('langtodelete', 'alpha')) { + if ($action == 'delete' && GETPOST('langtodelete', 'alpha') && $usercancreate) { $object = new Product($db); $object->fetch($id); $object->delMultiLangs(GETPOST('langtodelete', 'alpha'), $user); @@ -91,7 +95,7 @@ if (empty($reshook)) { } // Add translation - if ($action == 'vadd' && $cancel != $langs->trans("Cancel") && ($user->hasRight('produit', 'creer') || $user->hasRight('service', 'creer'))) { + if ($action == 'vadd' && $cancel != $langs->trans("Cancel") && $usercancreate) { $object = new Product($db); $object->fetch($id); $current_lang = $langs->getDefaultLang(); @@ -126,7 +130,7 @@ if (empty($reshook)) { } // Edit translation - if ($action == 'vedit' && $cancel != $langs->trans("Cancel") && ($user->hasRight('produit', 'creer') || $user->hasRight('service', 'creer'))) { + if ($action == 'vedit' && $cancel != $langs->trans("Cancel") && $usercancreate) { $object = new Product($db); $object->fetch($id); $current_lang = $langs->getDefaultLang(); @@ -155,7 +159,7 @@ if (empty($reshook)) { } // Delete translation - if ($action == 'vdelete' && $cancel != $langs->trans("Cancel") && ($user->hasRight('produit', 'creer') || $user->hasRight('service', 'creer'))) { + if ($action == 'vdelete' && $cancel != $langs->trans("Cancel") && $usercancreate) { $object = new Product($db); $object->fetch($id); $langtodelete = GETPOST('langdel', 'alpha'); diff --git a/htdocs/societe/card.php b/htdocs/societe/card.php index 708db62f682..80abbf6b83f 100644 --- a/htdocs/societe/card.php +++ b/htdocs/societe/card.php @@ -235,20 +235,20 @@ if (empty($reshook)) { $_POST["supplier_code"] = "Acompleter"; } - if ($action == 'set_localtax1') { + if ($action == 'set_localtax1' && $user->hasRight('societe', 'creer')) { //get selected from combobox $value = GETPOST('lt1'); $object->fetch($socid); $res = $object->setValueFrom('localtax1_value', $value, '', null, 'text', '', $user, 'COMPANY_MODIFY'); } - if ($action == 'set_localtax2') { + if ($action == 'set_localtax2' && $user->hasRight('societe', 'creer')) { //get selected from combobox $value = GETPOST('lt2'); $object->fetch($socid); $res = $object->setValueFrom('localtax2_value', $value, '', null, 'text', '', $user, 'COMPANY_MODIFY'); } - if ($action == 'update_extras') { + if ($action == 'update_extras' && $user->hasRight('societe', 'creer')) { $object->fetch($socid); $object->oldcopy = dol_clone($object, 2); @@ -275,8 +275,7 @@ if (empty($reshook)) { } // Add new or update third party - if ((!GETPOST('getcustomercode') && !GETPOST('getsuppliercode')) - && ($action == 'add' || $action == 'update') && $user->hasRight('societe', 'creer')) { + if ((!GETPOST('getcustomercode') && !GETPOST('getsuppliercode')) && ($action == 'add' || $action == 'update') && $user->hasRight('societe', 'creer')) { require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php'; if (!GETPOST('name')) { diff --git a/htdocs/supplier_proposal/card.php b/htdocs/supplier_proposal/card.php index 660e18de992..6b6c9498115 100644 --- a/htdocs/supplier_proposal/card.php +++ b/htdocs/supplier_proposal/card.php @@ -1132,7 +1132,7 @@ if (empty($reshook)) { } elseif ($action == 'setmulticurrencyrate' && $usercancreate) { // Multicurrency rate $result = $object->setMulticurrencyRate(price2num(GETPOST('multicurrency_tx')), GETPOSTINT('calculation_mode')); - } elseif ($action == 'update_extras') { + } elseif ($action == 'update_extras' && $usercancreate) { $object->oldcopy = dol_clone($object, 2); $attribute_name = GETPOST('attribute', 'restricthtml');