import re
file_path = 'index.php'
with open(file_path, 'r') as f:
content = f.read()
# 1. Replace
with
# We want to be careful. The user specifically mentioned "Items edit form" and "Add new items form".
# And "Apply the style to all forms in app".
# "row g-3" is the standard Bootstrap form layout class. Replacing it with "form-grid-3" (which I defined)
# should be safe for forms.
# However, "row g-3" might be used for non-form layouts (e.g. stats cards).
# I should look for inputs inside.
# But checking content inside is hard with regex.
# Let's count how many "row g-3" there are.
matches = len(re.findall(r'class=["\']row g-3["\']', content))
print(f"Found {matches} instances of 'row g-3'.")
# Strategy:
# Replace 'class="row g-3"' with 'class="form-grid-3"' IF it's inside a form or modal context.
# Or just replace all? "row g-3" implies a grid with gap 3 (1rem).
# My "form-grid-3" is a grid with gap 1rem and 3 columns.
# If "row g-3" was used for 2 columns (col-6) or 4 columns (col-3), forcing 3 columns might break layout.
# BUT the user said "Apply the style to all forms".
# Most "row g-3" in this app seem to be forms (based on previous grep).
# Non-form grids usually use "row" without "g-3" or with different gap?
# Let's assume "row g-3" is the form standard here.
# I'll define a function to replace specific occurrences if I can identify them.
# The "Edit Item" modal is around line 4964.
# The "Add Item" modal is around line 10141.
# Regex to find
and replace it, but maybe verify context?
# I'll just do a global replace for now, but I will backup first.
# Wait, "row g-3" in a dashboard stats widget (e.g. 4 cards) would become 3 columns.
# That might be annoying.
# I should inspect if there are stats widgets using "row g-3".
# Let's look for "col-md-3" or "col-xl-3" inside "row g-3".
# If I see "col-xl-3", it's likely a 4-column layout (12/3 = 4).
# My "form-grid-3" forces 3 columns.
# So replacing it would break 4-column layouts.
# "Edit Item" uses "col-md-3", "col-md-4", "col-md-6".
# If I change the container to grid-3, the children become grid items.
# I added CSS to make children width 100%.
# To be safer, I will only replace "row g-3" if it contains "form-control" or "form-select" or "form-label" inside it (heuristic).
# This is tricky with regex.
# Alternative: Find the specific blocks for Items and change them.
# Then find other *forms*.
# Let's use a simpler approach.
# I will search for the specific lines for Edit Item and Add Item and change them.
# Then I will search for other obvious forms.
new_content = content
# 1. Edit Item Modal (around line 4975)
# Context:
...
# I'll use regex to match the structure.
# Pattern for Edit/Add Item Modals (and potentially others)
# Matches
inside a form or modal body?
# Actually, the user wants "items edit form" specifically.
# I'll replace specifically in the Item Modals first.
# "Edit Item" has id="editItemModal..."
# "Add Item" has id="addItemModal"
# But "Edit Item" is inside a PHP loop? No, the modal ID has PHP echo.
# L4965:
# I'll verify the lines again.
# L4975 is likely correct.
# I'll proceed with a more manual replacement for the Items forms to ensure they are fixed.
# Then I'll check "Edit Profile" (L8558) and "Company Profile" (L8594).
def replace_block(text, start_marker, end_marker, old_class, new_class):
# Find start marker
pattern = re.compile(re.escape(start_marker) + r'.*?' + re.escape(old_class), re.DOTALL)
# This is hard because of multiple occurrences.
pass
# Direct replacement on known lines (approximate) is safer if I can locate them uniquely.
# Or replace all "row g-3" that are inside