Example #1
0
function tlxAccountSearchAndSet()
{
    global $DB, $json, $C;
    VerifyPrivileges(P_ACCOUNT_MODIFY, TRUE);
    $user_columns = $DB->GetColumns('tlx_account_fields');
    $search_type = $_REQUEST['search'] == 'NULL' ? ST_EMPTY : ST_CONTAINS;
    $u = new UpdateBuilder('tlx_accounts');
    if (in_array($_REQUEST['field'], $user_columns) || in_array($_REQUEST['set_field'], $user_columns)) {
        $u->AddJoin('tlx_accounts', 'tlx_account_fields', '', 'username');
    }
    if ($_REQUEST['replace'] == 'NULL') {
        $_REQUEST['replace'] = null;
    }
    if ($_REQUEST['field'] == 'return_percent') {
        $_REQUEST['search'] = $_REQUEST['search'] / 100;
    }
    if ($_REQUEST['set_field'] == 'return_percent') {
        $_REQUEST['replace'] = $_REQUEST['replace'] / 100;
    }
    $u->AddSet($_REQUEST['set_field'], $_REQUEST['replace']);
    $u->AddWhere($_REQUEST['field'], $search_type, $_REQUEST['search']);
    $replacements = $DB->Update($u->Generate(), $u->binds);
    echo $json->encode(array('status' => JSON_SUCCESS, 'message' => "{$replacements} changes have been made"));
}
Example #2
0
function txGallerySearchAndSet()
{
    global $DB, $json, $C;
    VerifyPrivileges(P_GALLERY_MODIFY, TRUE);
    $user_columns = $DB->GetColumns('tx_gallery_fields');
    $preview_columns = $DB->GetColumns('tx_gallery_previews');
    $search_type = $_REQUEST['search'] == 'NULL' ? ST_EMPTY : ST_CONTAINS;
    $u = new UpdateBuilder('tx_galleries');
    if (in_array($_REQUEST['field'], $user_columns) || in_array($_REQUEST['set_field'], $user_columns)) {
        $u->AddJoin('tx_galleries', 'tx_gallery_fields', '', 'gallery_id');
    }
    if (in_array($_REQUEST['field'], $preview_columns) || in_array($_REQUEST['set_field'], $preview_columns)) {
        $u->AddJoin('tx_galleries', 'tx_gallery_previews', '', 'gallery_id');
    }
    if ($_REQUEST['replace'] == 'NULL') {
        $_REQUEST['replace'] = null;
    }
    if ($_REQUEST['set_field'] == 'sponsor_id' && $_REQUEST['replace'] != null) {
        $sponsor_name = $_REQUEST['replace'];
        $_REQUEST['replace'] = $DB->Count('SELECT `sponsor_id` FROM `tx_sponsors` WHERE `name`=?', array($_REQUEST['replace']));
        if (!$_REQUEST['replace']) {
            echo $json->encode(array('status' => JSON_SUCCESS, 'message' => "Sponsor '" . htmlspecialchars($sponsor_name) . "' does not exist"));
            return;
        }
    }
    if ($_REQUEST['field'] == 'sponsor_id' && $_REQUEST['search'] != 'NULL') {
        $sponsor_name = $_REQUEST['search'];
        $_REQUEST['search'] = $DB->Count('SELECT `sponsor_id` FROM `tx_sponsors` WHERE `name`=?', array($_REQUEST['search']));
        if (!$_REQUEST['search']) {
            echo $json->encode(array('status' => JSON_SUCCESS, 'message' => "Sponsor '" . htmlspecialchars($sponsor_name) . "' does not exist"));
            return;
        }
        $search_type = ST_MATCHES;
    }
    $u->AddSet($_REQUEST['set_field'], $_REQUEST['replace']);
    $u->AddWhere($_REQUEST['field'], $search_type, $_REQUEST['search']);
    $replacements = $DB->Update($u->Generate(), $u->binds);
    echo $json->encode(array('status' => JSON_SUCCESS, 'message' => "{$replacements} changes have been made"));
}