function validate_record($fields)
{
    $db = new Database();
    if (!$db->get_row_by_key('affiliates', 'id', $fields['affiliate'])) {
        echo json_encode('That affiliate does not exist.');
        return FALSE;
    }
    if ($db->get_row_by_key('orders', 'id', $fields['id']) && (!isset($fields['key']) || $fields['id'] != $fields['key'])) {
        echo json_encode('That order number is already in use.');
        return FALSE;
    }
    return TRUE;
}
function validate_record($fields)
{
    $db = new Database();
    if (!$db->get_row_by_key('affiliates', 'id', $fields['affiliate'])) {
        echo json_encode('That affiliate does not exist.');
        return FALSE;
    }
    return TRUE;
}
 private function send_update($affiliate, $subject, $content)
 {
     global $notification_email_address;
     if ($notification_email_address != '') {
         $this->send($notification_email_address, $subject, $content);
     }
     $db = new Database();
     $record = $db->get_row_by_key('affiliates', 'id', $affiliate);
     if ($record['email_update']) {
         $this->send($record['email'], $subject, $content);
     }
 }
<?php

/*
Copyright (c) 2008 Metathinking Ltd.
This file is part of Affiliates For All.
Affiliates For All is free software: you can redistribute it and/or
modify it under the terms of the GNU General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
Affiliates For All is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with Affiliates For All.  If not, see
<http://www.gnu.org/licenses/>.
*/
$logon_not_required = TRUE;
require_once '../lib/bootstrap.php';
Template::check_ajax_key();
$db = new Database();
$result = $row = $db->insert('affiliates', array('local_username' => $_GET['user'], 'local_password' => $_GET['password']));
if ($result) {
    echo json_encode('overview.php');
    $row = $db->get_row_by_key('affiliates', 'local_username', $_GET['user']);
    $_SESSION['affiliate_id'] = $row['id'];
    $_SESSION['wizard_incomplete'] = TRUE;
    $_SESSION['administrator'] = FALSE;
} else {
    echo json_encode(false);
}
<?php

/*
Copyright (c) 2008 Metathinking Ltd.
This file is part of Affiliates For All.
Affiliates For All is free software: you can redistribute it and/or
modify it under the terms of the GNU General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
Affiliates For All is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with Affiliates For All.  If not, see
<http://www.gnu.org/licenses/>.
*/
$admin_required = TRUE;
require_once '../lib/bootstrap.php';
Template::check_ajax_key();
$db = new Database();
$row = $db->get_row_by_key('banners', 'id', $_GET['id']);
if ($row['name'] != $_GET['name']) {
    $row = $db->get_row_by_key('banners', 'name', $_GET['name']);
    if ($row != null) {
        echo json_encode('duplicate');
        exit;
    }
}
$db->update_by_key('banners', 'id', $_GET['id'], array('name' => $_GET['name'], 'link_target' => $_GET['linktarget'], 'enabled' => $_GET['enabled']));
echo json_encode(true);
You should have received a copy of the GNU General Public License
along with Affiliates For All.  If not, see
<http://www.gnu.org/licenses/>.
*/
$admin_required = TRUE;
require_once '../lib/bootstrap.php';
$db = new Database();
$template = new Template('admin-banners');
$banners = __('Banners');
$template->set('title', "{$affiliate_programme_name}: {$banners}");
$template->set('start', 'normal');
if (isset($_FILES['file'])) {
    $template->set('new_file', $_FILES['file']['name']);
    $template->set('new_name', $_POST['new_name']);
    $template->set('new_linktarget', $_POST['new_linktarget']);
    $row = $db->get_row_by_key('banners', 'name', $_POST['new_name']);
    if ($row != null) {
        $template->set('start', 'duplicate');
    } else {
        $image = file_get_contents($_FILES['file']['tmp_name']);
        $db->insert('banners', array('name' => $_POST['new_name'], 'link_target' => $_POST['new_linktarget'], 'enabled' => 1, 'banner' => $image, 'mime_type' => $_FILES['file']['type']));
        $template->set('start', 'success');
    }
} else {
    $template->set('new_file', '');
    $template->set('new_name', '');
    $template->set('new_linktarget', '');
}
$rows = $db->get_pdo()->query('select id, name, link_target, enabled from banners order by id');
$rows = $rows->fetchAll();
$template->set('banners', $rows);
function order_cancelled($secret, $order_no)
{
    if ($error = check_secret($secret)) {
        return $error;
    }
    $db = new Database();
    $order = $db->get_row_by_key('orders', 'id', $order_no);
    if ($order['status'] == 'new') {
        $db->update_by_key('orders', 'id', $order_no, array('status' => 'cancelled'));
    } else {
        if ($order['status'] == 'shipped') {
            $db->update_by_key('orders', 'id', $order_no, array('status' => 'refunded'));
            $new_order = array('id' => $order['id'] . '-r', 'affiliate' => $order['affiliate'], 'affiliate_data' => $order['affiliate_data'], 'status' => 'refund', 'customer_email' => $order['customer_email'], 'customer_name' => $order['customer_name'], 'total' => -$order['total'], 'commission' => -$order['commission']);
            $db->insert('orders', $new_order);
        }
    }
}
/*
Copyright (c) 2008 Metathinking Ltd.
This file is part of Affiliates For All.
Affiliates For All is free software: you can redistribute it and/or
modify it under the terms of the GNU General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
Affiliates For All is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with Affiliates For All.  If not, see
<http://www.gnu.org/licenses/>.
*/
$logon_not_required = TRUE;
require_once '../lib/bootstrap.php';
Template::check_ajax_key();
$user = $_GET['user'];
if ($user == '') {
    echo json_encode(array(false, '<div class="no">Please enter a username.</div>'));
} else {
    $db = new Database();
    $row = $db->get_row_by_key('affiliates', 'local_username', $user);
    if ($row == null) {
        echo json_encode(array(true, '<div class="yes">‘' . $user . '’ is available.</div>'));
    } else {
        echo json_encode(array(false, '<div class="no">‘' . $user . '’ is not available.</div>'));
    }
}