Roles (module_vendor, functions/vendor.php): our own vendors - * the ones with no client: suppliers, distributors, the colo - to see (Read), change (Modify) and * delete (Full), so a role can keep technicians out of their numbers, accounts and contacts. A * client's vendors stay with the Clients permission. * * Until now anyone could see ours and Financial changed them, so each role is given that here: * Read, or its Financial level when that is higher. Nothing changes until an admin lowers it. * Admins have every permission. * * Re-runnable: the permission, and each role's level for it, is added only where it isn't there. */ defined('FROM_DB_UPDATER') || die("Direct file access is not allowed"); if (!mysqli_num_rows(mysqli_query($mysqli, "SELECT 1 FROM modules WHERE module_name = 'module_vendor'"))) { mysqli_query($mysqli, "INSERT INTO modules SET module_name = 'module_vendor', module_description = 'Our own vendors - suppliers, distributors, the colo - with their numbers, accounts and contacts'"); } $itflow_vendor_module = intval(mysqli_fetch_row(mysqli_query($mysqli, "SELECT module_id FROM modules WHERE module_name = 'module_vendor' LIMIT 1"))[0]); $itflow_financial_module = intval((mysqli_fetch_row(mysqli_query($mysqli, "SELECT module_id FROM modules WHERE module_name = 'module_financial' LIMIT 1")) ?: [0])[0]); $itflow_roles = mysqli_query($mysqli, "SELECT role_id, (SELECT MAX(user_role_permission_level) FROM user_role_permissions WHERE user_role_id = role_id AND module_id = $itflow_financial_module) AS financial, (SELECT COUNT(*) FROM user_role_permissions WHERE user_role_id = role_id AND module_id = $itflow_vendor_module) AS has_vendor FROM user_roles"); while ($itflow_roles && ($itflow_role = mysqli_fetch_assoc($itflow_roles))) { if (intval($itflow_role['has_vendor']) === 0) { mysqli_query($mysqli, "INSERT INTO user_role_permissions SET user_role_id = " . intval($itflow_role['role_id']) . ", module_id = $itflow_vendor_module, user_role_permission_level = " . max(1, min(3, intval($itflow_role['financial'])))); } }