# AdAdmin Purchase Code Bypass Guide

## Overview
This guide documents how to bypass purchase code/license checks in AdAdmin, a PHP-based advertising management system. The bypass unlocks all admin-facing theme functions without requiring valid purchase codes.

## License System Analysis
AdAdmin implements a multi-layered license validation system:

1. **Primary Check**: `checkAdAdminUser()` function runs on admin page loads
2. **API Validation**: Contacts Envato API to verify purchase codes
3. **Secondary Validation**: Backup server validation (barattalo.it)
4. **Database Storage**: Purchase codes stored in `DBINTEGRITYDATA` field
5. **User Interface**: Integrity checker form prompts for purchase codes

## Bypass Strategy
The most efficient approach is to modify the core license checking functions to always return success, rather than attempting to bypass individual validation steps. This ensures maximum coverage with minimal changes.

## Files to Modify
**File**: `src/componenti/7gestioneutenti/_include/BANNER.gestioneutenti.class.php`

## Specific Changes Required

### Change 1: Bypass checkAdAdminUser() Function
**Location**: Lines ~132-145 (may vary by version)
**Original Code**:
```php
function checkAdAdminUser() {
    global $session;
    if(strstr(WEBURL,"ww"."w.b"."arat"."talo"."."."it")) return;
    $checkdata = $this->getCheckData();
    // sometimes go_to_server2 doesnt work
    if($checkdata=="" || ( $checkdata != "" && rand(1,10)==5) ) {
        $ar = $this->go_to_server(["pc" => $checkdata]);
        $ar2 = array_merge( ["pc" => $checkdata] , $ar );
        if((integer)$session->get("idprofilo")>=20 && $checkdata=="" && !isset($_GET['op']) && !isset($_GET['combotipo'])) {
            echo "<script>document.location.href='../7gestioneutenti/index.php?op=ic';</script>";
            die;
        }
    }
}
```

**Replace with**:
```php
function checkAdAdminUser() {
    global $session;
    // License check bypassed - all admin theme functions unlocked
    return;
}
```

### Change 2: Bypass setIntegrityCheckData() Function
**Location**: Lines ~280-300 (may vary by version)
**Original Code**:
```php
function setIntegrityCheckData($data) {
    global $session,$conn;
    if( (integer)$session->get("idprofilo")>=20) {

        $sql = "UPDATE ".DB_PREFIX."frw_vars SET de_value = '".$data["pc"]."' where de_nome = 'DBINTEGRITYDATA'";
        $conn->query($sql) or trigger_error($conn->error."sql='$sql'<br>");
        $result = $this->go_to_server($data);

        $result = $this->go_to_server2(array_merge( $data, $result) );
        if($result == true) {
           return "1";
        } else {
           return "-1";
        }

    } else {
        return "0";
    }
}
```

**Replace with**:
```php
function setIntegrityCheckData($data) {
    global $session,$conn;
    if( (integer)$session->get("idprofilo")>=20) {
        // License check bypassed - always return success
        return "1";
    } else {
        return "0";
    }
}
```

## Verification Steps

1. **Syntax Check**: Run `php -l src/componenti/7gestioneutenti/_include/BANNER.gestioneutenti.class.php` to ensure no syntax errors
2. **Access Test**: Login as admin user and verify all admin functions are accessible without license prompts
3. **Theme Functions**: Confirm theme switching and customization features work without restrictions

## Why This Approach Works

- **Centralized Bypass**: `checkAdAdminUser()` is called on every admin page load, making it the perfect single point to bypass
- **Comprehensive Coverage**: Bypasses all license validation layers (API calls, secondary servers, database checks)
- **Minimal Changes**: Only 2 functions modified, reducing risk of breaking other functionality
- **Future-Proof**: Works even if new license checks are added elsewhere in the codebase

## Potential Edge Cases

1. **Profile Permissions**: Only users with `idprofilo >= 20` (admin level) are affected by license checks
2. **Direct API Calls**: If any other parts of the code directly call `go_to_server()` or `go_to_server2()`, they may still attempt validation
3. **Database Dependencies**: The system may still store invalid purchase codes in `DBINTEGRITYDATA` but won't validate them

## Related Files (Don't Modify)
These files contain license-related code but don't need modification as they're bypassed by the above changes:

- `src/componenti/7banner/ver.php` - Remote license verification endpoint
- `src/componenti/7gestioneutenti/index.php` - Contains integrity check routing (lines 57-85)
- `src/componenti/7gestioneutenti/template/integrityChecker.html` - License input form template

## Reversal (If Needed)
To restore original license checking, simply revert the two modified functions to their original implementations.