Esempio n. 1
0
function txPartnerEdit()
{
    global $C, $DB, $L, $t, $domain;
    $partner = ValidPartnerLogin();
    if ($partner !== FALSE) {
        $v = new Validator();
        $v->Register($_REQUEST['email'], V_EMAIL, $L['INVALID_EMAIL']);
        // Check that new e-mail address does not conflict with another account
        if ($partner['email'] != $_REQUEST['email'] && $DB->Count('SELECT COUNT(*) FROM `tx_partners` WHERE `email`=?', array($_REQUEST['email']))) {
            $v->SetError($L['EXISTING_EMAIL']);
        }
        // Check if new passwords match
        if (!IsEmptyString($_REQUEST['password'])) {
            $v->Register($_REQUEST['password'], V_EQUALS, $L['NO_PASSWORD_MATCH'], $_REQUEST['confirm_password']);
            $v->Register($_REQUEST['password'], V_LENGTH, sprintf($L['PASSWORD_LENGTH'], 3, 32), '3,32');
            $partner['password'] = sha1($_REQUEST['password']);
        }
        // Validation of user defined fields
        $fields =& GetUserPartnerFields();
        foreach ($fields as $field) {
            if ($field['on_edit']) {
                // Set values for unchecked checkboxes
                if ($field['type'] == FT_CHECKBOX && !isset($_REQUEST[$field['name']])) {
                    $_REQUEST[$field['name']] = null;
                }
                if ($field['required_edit']) {
                    $v->Register($_REQUEST[$field['name']], V_EMPTY, sprintf($L['REQUIRED_FIELD'], $field['label']));
                }
                if (!IsEmptyString($_REQUEST[$field['name']]) && $field['validation']) {
                    $v->Register($_REQUEST[$field['name']], $field['validation'], $field['validation_message'], $field['validation_extras']);
                }
            }
        }
        if (!$v->Validate()) {
            return $v->ValidationError('txShPartnerEdit', TRUE);
        }
        // Update the predefined fields
        $DB->Update('UPDATE `tx_partners` SET ' . '`email`=?, ' . '`name`=?, ' . '`password`=? ' . 'WHERE `username`=?', array($_REQUEST['email'], $_REQUEST['name'], $partner['password'], $partner['username']));
        // Update user defined fields
        $_REQUEST['username'] = $partner['username'];
        UserDefinedUpdate('tx_partner_fields', 'tx_partner_field_defs', 'username', $_REQUEST['username'], $_REQUEST);
        $t->assign('updated', TRUE);
        txShPartnerEdit();
    }
}
Esempio n. 2
0
function txPartnerEdit()
{
    global $DB, $C;
    VerifyPrivileges(P_PARTNER_MODIFY);
    $partner = $DB->Row('SELECT * FROM `tx_partners` WHERE `username`=?', array($_REQUEST['username']));
    $start_or_end_empty = $_REQUEST['date_start'] && !$_REQUEST['date_end'] || !$_REQUEST['date_start'] && $_REQUEST['date_end'];
    $v = new Validator();
    $v->Register($_REQUEST['email'], V_EMAIL, 'The e-mail address is not properly formatted');
    $v->Register($_REQUEST['email'], V_EMAIL, 'The e-mail address is not properly formatted');
    $v->Register($_REQUEST['weight'], V_NUMERIC, 'The Weight field must be filled in and numeric');
    $v->Register($_REQUEST['per_day'], V_NUMERIC, 'The Galleries Per Day field must be filled in and numeric');
    $v->Register($_REQUEST['date_start'], V_DATETIME, 'The Start Date field is not properly formatted');
    $v->Register($_REQUEST['date_end'], V_DATETIME, 'The End Date field is not properly formatted');
    $v->Register($start_or_end_empty, V_FALSE, 'Start Date must be provided if End Date is provided, and vice versa');
    if ($_REQUEST['password']) {
        $v->Register($_REQUEST['password'], V_LENGTH, 'The password must contain at least 4 characters', array('min' => 4, 'max' => 999));
    }
    if (!$v->Validate()) {
        return $v->ValidationError('txShPartnerEdit');
    }
    if ($_REQUEST['password']) {
        // Password has changed, so invalidate any current session that may be active
        $DB->Update('UPDATE `tx_partners` SET `session`=NULL,`session_start`=NULL WHERE `username`=?', array($_REQUEST['username']));
        $_REQUEST['password'] = sha1($_REQUEST['password']);
    } else {
        $_REQUEST['password'] = $partner['password'];
    }
    if (!in_array('__ALL__', $_REQUEST['categories'])) {
        $_REQUEST['categories'] = serialize($_REQUEST['categories']);
    } else {
        $_REQUEST['categories'] = null;
    }
    if (!in_array('__ALL__', $_REQUEST['domains'])) {
        $_REQUEST['domains'] = serialize($_REQUEST['domains']);
    } else {
        $_REQUEST['domains'] = null;
    }
    NullIfEmpty($_REQUEST['date_start']);
    NullIfEmpty($_REQUEST['date_end']);
    // Update account information
    $DB->Update('UPDATE `tx_partners` SET ' . '`password`=?, ' . '`name`=?, ' . '`email`=?, ' . '`date_start`=?, ' . '`date_end`=?, ' . '`per_day`=?, ' . '`weight`=?, ' . '`categories`=?, ' . '`categories_as_exclude`=?, ' . '`domains`=?, ' . '`domains_as_exclude`=?, ' . '`status`=?, ' . '`allow_redirect`=?, ' . '`allow_norecip`=?, ' . '`allow_autoapprove`=?, ' . '`allow_noconfirm`=?, ' . '`allow_blacklist`=? ' . 'WHERE `username`=?', array($_REQUEST['password'], $_REQUEST['name'], $_REQUEST['email'], $_REQUEST['date_start'], $_REQUEST['date_end'], $_REQUEST['per_day'], $_REQUEST['weight'], $_REQUEST['categories'], intval($_REQUEST['categories_as_exclude']), $_REQUEST['domains'], intval($_REQUEST['domains_as_exclude']), $_REQUEST['status'], $_REQUEST['allow_redirect'], $_REQUEST['allow_norecip'], $_REQUEST['allow_autoapprove'], $_REQUEST['allow_noconfirm'], $_REQUEST['allow_blacklist'], $_REQUEST['username']));
    // Update user defined fields
    UserDefinedUpdate('tx_partner_fields', 'tx_partner_field_defs', 'username', $_REQUEST['username'], $_REQUEST);
    // Update icons
    $DB->Update('DELETE FROM `tx_partner_icons` WHERE `username`=?', array($_REQUEST['username']));
    if (is_array($_REQUEST['icons'])) {
        foreach ($_REQUEST['icons'] as $icon_id) {
            $DB->Update('INSERT INTO `tx_partner_icons` VALUES (?,?)', array($_REQUEST['username'], $icon_id));
        }
    }
    // Reactivate galleries if this account is being reactivated
    if ($_REQUEST['status'] == 'active' && $partner['status'] == 'disabled') {
        $DB->Update('UPDATE `tx_galleries` SET `status`=`previous_status`,`previous_status`=NULL WHERE `status`=? AND `partner`=?', array('disabled', $_REQUEST['username']));
    } else {
        if ($_REQUEST['status'] == 'suspended') {
            $DB->Update('UPDATE `tx_galleries` SET `previous_status`=`status`,`status`=? WHERE `status`!=? AND `partner`=?', array('disabled', 'disabled', $_REQUEST['username']));
        }
    }
    $GLOBALS['message'] = 'Partner account successfully updated';
    $GLOBALS['added'] = true;
    txShPartnerEdit();
}