diff --git a/htdocs/compta/sociales/card.php b/htdocs/compta/sociales/card.php index dd7cd655392..debeab8a681 100644 --- a/htdocs/compta/sociales/card.php +++ b/htdocs/compta/sociales/card.php @@ -497,9 +497,7 @@ if ($id > 0) { $formconfirm = $hookmanager->resPrint; } - /* - * View card - */ + print dol_get_fiche_head($head, 'card', $langs->trans("SocialContribution"), -1, 'bill', 0, '', '', 0, '', 1); // Print form confirm diff --git a/htdocs/contact/list.php b/htdocs/contact/list.php index e35a62608b0..867c6b26d51 100644 --- a/htdocs/contact/list.php +++ b/htdocs/contact/list.php @@ -409,7 +409,7 @@ if (empty($reshook)) { $uploaddir = $conf->societe->dir_output; include DOL_DOCUMENT_ROOT.'/core/actions_massactions.inc.php'; - if ($action == 'setstcomm') { + if ($action == 'setstcomm' && $permissiontoadd) { $object = new Contact($db); $result = $object->fetch(GETPOST('stcommcontactid')); $object->stcomm_id = dol_getIdFromCode($db, GETPOST('stcomm', 'alpha'), 'c_stcommcontact'); diff --git a/htdocs/core/ajax/check_notifications.php b/htdocs/core/ajax/check_notifications.php index e636b499745..43e71fa6dd0 100644 --- a/htdocs/core/ajax/check_notifications.php +++ b/htdocs/core/ajax/check_notifications.php @@ -53,7 +53,7 @@ $listofreminderids = GETPOST('listofreminderids', 'aZ09'); * Actions */ -if ($action == 'stopreminder') { +if ($action == 'stopreminder') { // Test on permission not required here. Endpoint can be called dol_syslog("Clear notification for listofreminderids=".$listofreminderids); $listofreminderid = GETPOST('listofreminderids', 'intcomma'); diff --git a/htdocs/core/ajax/constantonoff.php b/htdocs/core/ajax/constantonoff.php index eff5c260b26..c4d57726ea5 100644 --- a/htdocs/core/ajax/constantonoff.php +++ b/htdocs/core/ajax/constantonoff.php @@ -59,23 +59,28 @@ if (empty($user->admin)) { /* - * View + * Actions */ -top_httphead(); - -//print ''."\n"; - // Registering the new value of constant if (!empty($action) && !empty($name)) { - if ($action == 'set') { + if ($action == 'set') { // Test on permission not required here. Already done into test on user->admin in header. dolibarr_set_const($db, $name, $value, 'chaine', 0, '', $entity); - } elseif ($action == 'del') { + } elseif ($action == 'del') { // Test on permission not required here. Already done into test on user->admin in header. dolibarr_del_const($db, $name, $entity); if ($entity == 1) { // Sometimes the param was saved in both entity 0 and 1. When we work on master entity, we should clean also if entity is 0 dolibarr_del_const($db, $name, 0); } } } else { - http_response_code(403); + httponly_accessforbidden('Param action and name is required', 403); } + + +/* + * View + */ + +top_httphead(); + +//print ''."\n"; diff --git a/htdocs/ecm/index_medias.php b/htdocs/ecm/index_medias.php index bf5ca78cd16..b6726fe9e99 100644 --- a/htdocs/ecm/index_medias.php +++ b/htdocs/ecm/index_medias.php @@ -98,7 +98,11 @@ $hookmanager->initHooks(array('ecmmediascard', 'globalcard')); $result = restrictedArea($user, 'ecm', 0); +$permissiontoread = ($user->hasRight('ecm', 'read') || $user->hasRight('mailing', 'lire') || $user->hasRight('website', 'read')); $permissiontouploadfile = ($user->hasRight('ecm', 'setup') || $user->hasRight('mailing', 'creer') || $user->hasRight('website', 'write')); +$permissiontoadd = $permissiontouploadfile; // Used by the include of actions_addupdatedelete.inc.php and actions_linkedfiles + + $diroutput = $conf->medias->multidir_output[$conf->entity]; $relativepath = $section_dir; @@ -106,7 +110,7 @@ $upload_dir = preg_replace('/\/$/', '', $diroutput).'/'.preg_replace('/^\//', '' $websitekey = ''; -$permissiontoadd = $permissiontouploadfile; // Used by the include of actions_addupdatedelete.inc.php and actions_linkedfiles + /* * Actions @@ -124,7 +128,7 @@ include DOL_DOCUMENT_ROOT.'/core/actions_linkedfiles.inc.php'; // This manage 's $backtopage = $savbacktopage; -if ($action == 'renamefile') { // Must be after include DOL_DOCUMENT_ROOT.'/core/actions_linkedfiles.inc.php'; If action were renamefile, we set it to 'file_manager' +if ($action == 'renamefile') { // Test on permission not required here. Must be after include DOL_DOCUMENT_ROOT.'/core/actions_linkedfiles.inc.php'; If action were renamefile, we set it to 'file_manager' $action = 'file_manager'; } @@ -148,7 +152,7 @@ if ($action == 'add' && $permissiontouploadfile) { } // Remove directory -if ($action == 'confirm_deletesection' && GETPOST('confirm', 'alpha') == 'yes') { +if ($action == 'confirm_deletesection' && GETPOST('confirm', 'alpha') == 'yes' && $permissiontoadd) { $result = $ecmdir->delete($user); setEventMessages($langs->trans("ECMSectionWasRemoved", $ecmdir->label), null, 'mesgs'); @@ -158,7 +162,7 @@ if ($action == 'confirm_deletesection' && GETPOST('confirm', 'alpha') == 'yes') // Refresh directory view // This refresh list of dirs, not list of files (for performance reason). List of files is refresh only if dir was not synchronized. // To refresh content of dir with cache, just open the dir in edit mode. -if ($action == 'refreshmanual') { +if ($action == 'refreshmanual' && $permissiontoread) { $ecmdirtmp = new EcmDirectory($db); // This part of code is same than into file ecm/ajax/ecmdatabase.php TODO Remove duplicate diff --git a/htdocs/expedition/ajax/searchfrombarcode.php b/htdocs/expedition/ajax/searchfrombarcode.php index f1f354a0438..543ec0c34a5 100644 --- a/htdocs/expedition/ajax/searchfrombarcode.php +++ b/htdocs/expedition/ajax/searchfrombarcode.php @@ -65,13 +65,21 @@ if (!$result) { httponly_accessforbidden('Not allowed by restrictArea (module='.$object->module.' table_element='.$object->table_element.')'); } + +/* + * Action + */ + +// None + + /* * View */ top_httphead('application/json'); -if ($action == "existbarcode" && !empty($barcode)) { +if ($action == "existbarcode" && !empty($barcode) && $user->hasRight('stock', 'lire')) { if (!empty($mode) && $mode == "lotserial") { $sql = "SELECT ps.fk_entrepot, ps.fk_product, p.barcode, ps.reel, pb.batch"; $sql .= " FROM ".MAIN_DB_PREFIX."product_batch as pb"; diff --git a/htdocs/expedition/card.php b/htdocs/expedition/card.php index 1b3072f8402..d0b8b07db05 100644 --- a/htdocs/expedition/card.php +++ b/htdocs/expedition/card.php @@ -528,7 +528,7 @@ if (empty($reshook)) { setEventMessages($object->error, $object->errors, 'errors'); } // TODO add alternative status - //} elseif ($action == 'reopen' && (!empty($user->rights->expedition->creer) || !empty($user->rights->expedition->shipping_advance->validate))) + //} elseif ($action == 'reopen' && ($user->hasRight('expedition', 'creer') || $user->hasRight('expedition', 'shipping_advance', 'validate'))) //{ // $result = $object->setStatut(0); // if ($result < 0) @@ -544,15 +544,7 @@ if (empty($reshook)) { if ($result < 0) { setEventMessages($object->error, $object->errors, 'errors'); } - } elseif (($action == 'settracking_number' - || $action == 'settracking_url' - || $action == 'settrueWeight' - || $action == 'settrueWidth' - || $action == 'settrueHeight' - || $action == 'settrueDepth' - || $action == 'setshipping_method_id') - && $user->hasRight('expedition', 'creer') - ) { + } elseif (in_array($action, array('settracking_number', 'settracking_url', 'settrueWeight', 'settrueWidth', 'settrueHeight', 'settrueDepth', 'setshipping_method_id')) && $user->hasRight('expedition', 'creer')) { // Action update $error = 0; @@ -589,7 +581,7 @@ if (empty($reshook)) { } $action = ""; - } elseif ($action == 'classifybilled') { + } elseif ($action == 'classifybilled' && $permissiontoadd) { $object->fetch($id); $result = $object->setBilled(); if ($result >= 0) { @@ -597,7 +589,7 @@ if (empty($reshook)) { exit(); } setEventMessages($object->error, $object->errors, 'errors'); - } elseif ($action == 'classifyclosed') { + } elseif ($action == 'classifyclosed' && $permissiontoadd) { $object->fetch($id); $result = $object->setClosed(); if ($result >= 0) { @@ -605,7 +597,7 @@ if (empty($reshook)) { exit(); } setEventMessages($object->error, $object->errors, 'errors'); - } elseif ($action == 'deleteline' && !empty($line_id)) { + } elseif ($action == 'deleteline' && !empty($line_id) && $permissiontoadd) { // delete a line $object->fetch($id); $lines = $object->lines; @@ -640,7 +632,7 @@ if (empty($reshook)) { } else { setEventMessages($line->error, $line->errors, 'errors'); } - } elseif ($action == 'updateline' && $user->hasRight('expedition', 'creer') && GETPOST('save')) { + } elseif ($action == 'updateline' && $permissiontoadd && GETPOST('save')) { // Update a line // Clean parameters $qty = 0; @@ -876,7 +868,7 @@ if (empty($reshook)) { header('Location: '.$_SERVER['PHP_SELF'].'?id='.$object->id); // To redisplay the form being edited exit(); } - } elseif ($action == 'updateline' && $user->hasRight('expedition', 'creer') && GETPOST('cancel', 'alpha') == $langs->trans("Cancel")) { + } elseif ($action == 'updateline' && $permissiontoadd && GETPOST('cancel', 'alpha') == $langs->trans("Cancel")) { header('Location: '.$_SERVER['PHP_SELF'].'?id='.$object->id); // To redisplay the form being edited exit(); } diff --git a/htdocs/exports/export.php b/htdocs/exports/export.php index 6229bdff4ad..4291ae72ba8 100644 --- a/htdocs/exports/export.php +++ b/htdocs/exports/export.php @@ -243,10 +243,10 @@ if ($action == 'unselectfield' && $user->hasRight('export', 'creer')) { if (($action == 'downfield' || $action == 'upfield') && $user->hasRight('export', 'creer')) { $pos = $array_selected[GETPOST("field")]; - if ($action == 'downfield') { + if ($action == 'downfield') { // Test on permission already done $newpos = $pos + 1; } - if ($action == 'upfield') { + if ($action == 'upfield') { // Test on permission already done $newpos = $pos - 1; } // Recherche code avec qui switcher diff --git a/htdocs/fourn/commande/card.php b/htdocs/fourn/commande/card.php index 8df3a82fe01..4759e1ed30f 100644 --- a/htdocs/fourn/commande/card.php +++ b/htdocs/fourn/commande/card.php @@ -1063,7 +1063,7 @@ if (empty($reshook)) { } // Force mandatory order method - if ($action == 'commande') { // Not a real action so no permission test + if ($action == 'commande') { // Test on permission not required here $methodecommande = GETPOSTINT('methodecommande'); if ($cancel) { @@ -1546,8 +1546,8 @@ if (empty($reshook)) { } } - if (getDolGlobalString('MAIN_DISABLE_CONTACTS_TAB') && $permissiontoadd) { - if ($action == 'addcontact') { + if (getDolGlobalString('MAIN_DISABLE_CONTACTS_TAB')) { + if ($action == 'addcontact' && $permissiontoadd) { if ($object->id > 0) { $contactid = (GETPOST('userid') ? GETPOST('userid') : GETPOST('contactid')); $typeid = (GETPOST('typecontact') ? GETPOST('typecontact') : GETPOST('type')); @@ -1565,10 +1565,10 @@ if (empty($reshook)) { setEventMessages($object->error, $object->errors, 'errors'); } } - } elseif ($action == 'swapstatut' && $object->id > 0) { + } elseif ($action == 'swapstatut' && $object->id > 0 && $permissiontoadd) { // bascule du statut d'un contact $result = $object->swapContactStatus(GETPOSTINT('ligne')); - } elseif ($action == 'deletecontact' && $object->id > 0) { + } elseif ($action == 'deletecontact' && $object->id > 0 && $permissiontoadd) { // Efface un contact $result = $object->delete_contact(GETPOSTINT("lineid")); diff --git a/htdocs/fourn/facture/card-rec.php b/htdocs/fourn/facture/card-rec.php index 7fefb8a3c44..aa7e5ede40e 100644 --- a/htdocs/fourn/facture/card-rec.php +++ b/htdocs/fourn/facture/card-rec.php @@ -872,7 +872,7 @@ if (empty($reshook)) { } /* - * View + * View */ $help_url = ''; @@ -889,9 +889,8 @@ $invoicerectmp = new FactureFournisseurRec($db); $now = dol_now(); $nowlasthour = dol_get_last_hour($now); -/* - * Create mode - */ +// Create mode + if ($action == 'create') { print load_fiche_titre($langs->trans("CreateRepeatableInvoice"), '', 'bill'); diff --git a/htdocs/fourn/facture/card.php b/htdocs/fourn/facture/card.php index b77d4e47e15..10a5536a845 100644 --- a/htdocs/fourn/facture/card.php +++ b/htdocs/fourn/facture/card.php @@ -2050,7 +2050,7 @@ if (empty($reshook)) { /* - * View + * View */ $form = new Form($db); diff --git a/htdocs/fourn/paiement/card.php b/htdocs/fourn/paiement/card.php index e5a990b7756..ae60d77c152 100644 --- a/htdocs/fourn/paiement/card.php +++ b/htdocs/fourn/paiement/card.php @@ -68,12 +68,16 @@ if ($socid && $socid != $object->thirdparty->id) { accessforbidden(); } +$permissiontoadd = ($user->hasRight("fournisseur", "facture", "creer") || $user->hasRight("supplier_invoice", "write")); +$permissiontovalidate = ((!getDolGlobalString('MAIN_USE_ADVANCED_PERMS') && ($user->hasRight("fournisseur", "facture", "creer") || $user->hasRight("supplier_invoice", "write"))) || (getDolGlobalString('MAIN_USE_ADVANCED_PERMS') && $user->hasRight("fournisseur", "supplier_invoice_advance", "validate"))); +$permissiontodelete = ($user->hasRight("fournisseur", "facture", "supprimer") || $user->hasRight("supplier_invoice", "delete")); + /* * Actions */ -if ($action == 'setnote' && ($user->hasRight("fournisseur", "facture", "creer") || $user->hasRight("supplier_invoice", "creer"))) { +if ($action == 'setnote' && $permissiontoadd) { $db->begin(); $object->fetch($id); @@ -87,7 +91,7 @@ if ($action == 'setnote' && ($user->hasRight("fournisseur", "facture", "creer") } } -if ($action == 'confirm_delete' && $confirm == 'yes' && $user->hasRight("fournisseur", "facture", "supprimer")) { +if ($action == 'confirm_delete' && $confirm == 'yes' && $permissiontodelete) { $db->begin(); $object->fetch($id); @@ -102,10 +106,7 @@ if ($action == 'confirm_delete' && $confirm == 'yes' && $user->hasRight("fournis } } -if ($action == 'confirm_validate' && $confirm == 'yes' && - ((!getDolGlobalString('MAIN_USE_ADVANCED_PERMS') && ($user->hasRight("fournisseur", "facture", "creer") || $user->hasRight("supplier_invoice", "creer"))) - || (getDolGlobalString('MAIN_USE_ADVANCED_PERMS') && $user->hasRight("fournisseur", "supplier_invoice_advance", "validate"))) -) { +if ($action == 'confirm_validate' && $confirm == 'yes' && $permissiontovalidate) { $db->begin(); $object->fetch($id); @@ -119,7 +120,7 @@ if ($action == 'confirm_validate' && $confirm == 'yes' && } } -if ($action == 'setnum_paiement' && GETPOST('num_paiement')) { +if ($action == 'setnum_paiement' && GETPOST('num_paiement') && $permissiontoadd) { $object->fetch($id); $res = $object->update_num(GETPOST('num_paiement')); if ($res === 0) { @@ -129,7 +130,7 @@ if ($action == 'setnum_paiement' && GETPOST('num_paiement')) { } } -if ($action == 'setdatep' && GETPOST('datepday')) { +if ($action == 'setdatep' && GETPOST('datepday') && $permissiontoadd) { $object->fetch($id); $datepaye = dol_mktime(GETPOSTINT('datephour'), GETPOSTINT('datepmin'), GETPOSTINT('datepsec'), GETPOSTINT('datepmonth'), GETPOSTINT('datepday'), GETPOSTINT('datepyear')); $res = $object->update_date($datepaye); @@ -142,8 +143,6 @@ if ($action == 'setdatep' && GETPOST('datepday')) { // Build document $upload_dir = $conf->fournisseur->payment->dir_output; -// TODO: get the appropriate permission -$permissiontoadd = true; include DOL_DOCUMENT_ROOT.'/core/actions_builddoc.inc.php'; // Actions to send emails diff --git a/htdocs/holiday/card.php b/htdocs/holiday/card.php index 8a2297f5f93..4abddc738c7 100644 --- a/htdocs/holiday/card.php +++ b/htdocs/holiday/card.php @@ -95,14 +95,14 @@ if (($id > 0) || $ref) { // Initialize a technical object to manage hooks of page. Note that conf->hooks_modules contains an array of hook context $hookmanager->initHooks(array('holidaycard', 'globalcard')); -$cancreate = 0; -$cancreateall = 0; +$permissiontoadd = 0; +$permissiontoaddall = 0; if ($user->hasRight('holiday', 'write') && in_array($fuserid, $childids)) { - $cancreate = 1; + $permissiontoadd = 1; } if ($user->hasRight('holiday', 'writeall')) { - $cancreate = 1; - $cancreateall = 1; + $permissiontoadd = 1; + $permissiontoaddall = 1; } $candelete = 0; @@ -155,7 +155,7 @@ if (empty($reshook)) { } // Add leave request - if ($action == 'add' && $cancreate) { + if ($action == 'add' && $permissiontoadd) { $object = new Holiday($db); $db->begin(); @@ -180,7 +180,7 @@ if (empty($reshook)) { $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 (!$permissiontoaddall) { if (!getDolGlobalString('MAIN_USE_ADVANCED_PERMS')) { if (!$user->hasRight('holiday', 'write')) { $error++; @@ -332,8 +332,8 @@ if (empty($reshook)) { } // If no right to modify a request - if (!$cancreateall) { - if ($cancreate) { + if (!$permissiontoaddall) { + if ($permissiontoadd) { if (!in_array($fuserid, $childids)) { setEventMessages($langs->trans("UserNotInHierachy"), null, 'errors'); header('Location: '.$_SERVER["PHP_SELF"].'?action=create'); @@ -351,7 +351,7 @@ if (empty($reshook)) { // If under validation if ($object->status == Holiday::STATUS_DRAFT) { // If this is the requester or has read/write rights - if ($cancreate) { + if ($permissiontoadd) { $approverid = GETPOSTINT('valideur'); // TODO Check this approver user id has the permission for approval @@ -454,7 +454,7 @@ if (empty($reshook)) { $object->fetch($id); // If draft and owner of leave - if ($object->status == Holiday::STATUS_DRAFT && $cancreate) { + if ($object->status == Holiday::STATUS_DRAFT && $permissiontoadd) { $object->oldcopy = dol_clone($object, 2); $object->status = Holiday::STATUS_VALIDATED; @@ -595,7 +595,7 @@ if (empty($reshook)) { $object->fetch($id); // If status is waiting approval and approver is also user - if ($object->status == Holiday::STATUS_VALIDATED && ($user->id == $object->fk_validator || $cancreateall) && $user->hasRight('holiday', 'approve')) { + if ($object->status == Holiday::STATUS_VALIDATED && ($user->id == $object->fk_validator || $permissiontoaddall) && $user->hasRight('holiday', 'approve')) { $object->oldcopy = dol_clone($object, 2); $object->date_approval = dol_now(); @@ -702,7 +702,7 @@ if (empty($reshook)) { $object->fetch($id); // If status pending validation and validator = user - if ($object->status == Holiday::STATUS_VALIDATED && ($user->id == $object->fk_validator || $cancreateall) && $user->hasRight('holiday', 'approve')) { + if ($object->status == Holiday::STATUS_VALIDATED && ($user->id == $object->fk_validator || $permissiontoaddall) && $user->hasRight('holiday', 'approve')) { $object->date_refuse = dol_now(); $object->fk_user_refuse = $user->id; $object->statut = Holiday::STATUS_REFUSED; @@ -823,7 +823,7 @@ if (empty($reshook)) { // If status pending validation and validator = validator or user, or rights to do for others if (($object->status == Holiday::STATUS_VALIDATED || $object->status == Holiday::STATUS_APPROVED) && - (!empty($user->admin) || $user->id == $object->fk_validator || $cancreate || $cancreateall)) { + (!empty($user->admin) || $user->id == $object->fk_validator || $permissiontoadd || $permissiontoaddall)) { $db->begin(); $oldstatus = $object->status; @@ -1047,7 +1047,7 @@ if ((empty($id) && empty($ref)) || $action == 'create' || $action == 'add') { print '