<?php

/*
# --------------------------------------------------------------------------
# Password stregth overriding by admins will also cover domain passwords
# --------------------------------------------------------------------------
*/
$query = "SELECT value FROM setting WHERE name = 'Allow Admins Override Enforce Password Strength In Customer Profile Section'";
$result = $this->db->query($query);
if ($row = $result->fetch()) {
    $query = "INSERT INTO setting VALUES (NULL, 'Allow Admins Override Enforce Password Strength', ?, NULL , 'Select YES to have the password strength rules not apply to admin users when editing a customer profile or package.', 12, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0)";
    $result = $this->db->query($query, $row['value']);
}

/*
# --------------------------------------------------------------------------
# Remove hard-coding of access groups in snapins permissions.
# Here I try to conserve the current permissions, only for groups that have
# the default names.
# --------------------------------------------------------------------------
*/

$names = array(
    'Customer'          => 'Customers',
    'Support Staff'     => 'Support Staff members',
    'Billing'           => 'Billing Staff members',
    'Support Manager'   => 'Support Managers',
);

foreach ($names as $groupName => $permissionName) {
    $query = "SELECT name FROM groups WHERE name = ?";
    $result = $this->db->query($query, $groupName);
    if ($result->getNumRows() > 0) {
        $query2 = "SELECT id, name FROM setting WHERE name LIKE '%Viewable by ".$permissionName."'";
        $result2 = $this->db->query($query2);
        while ($row = $result2->fetch()) {
            $newName = substr($row['name'], 0, strlen($row['name']) - strlen($permissionName));
            $newName .= $groupName;
            $query3 = "UPDATE setting SET name = ? WHERE id = ?";
            $this->db->query($query3, $newName, $row['id']);
        }
    }
}

?>
