Exemplo n.º 1
0
function sailing_series_submit()
{
    global $ssc_database;
    // Get id number
    $id = (int) $_POST['id'];
    // Bitflags
    $flags = 0;
    if (isset($_POST['class']) && (int) $_POST['class'] == 1) {
        $flags |= SSC_SAILING_CLASS;
    }
    if (isset($_POST['club']) && (int) $_POST['club'] == 1) {
        $flags |= SSC_SAILING_CLUB;
    }
    if (isset($_POST['div']) && (int) $_POST['div'] == 1) {
        $flags |= SSC_SAILING_PREFIX;
    }
    if ($id == 0) {
        // Inserting fresh
        $result = $ssc_database->query("INSERT INTO #__handler (path, handler) VALUES ('%s', %d)", $_POST['url'], module_id('sailing'));
        if (!$result) {
            ssc_add_message(SSC_MSG_CRIT, 'Error inserting into db');
            return false;
        }
        $id = $ssc_database->last_id();
        $result = $ssc_database->query("INSERT INTO #__sailing_series (id, name, description, updated, flags, heats) VALUES (%d, '%s', '%s', 0, %d, '')", $id, $_POST['name'], $_POST['desc'], $flags);
        if (!$result) {
            ssc_add_message(SSC_MSG_CRIT, 'Error inserting into db');
            return false;
        }
    } else {
        // Update existing
        $ssc_database->query("UPDATE #__handler SET path = '%s' WHERE id = %d LIMIT 1", $_POST['url'], $id);
        $ssc_database->query("UPDATE #__sailing_series SET name = '%s', description = '%s', flags = %d WHERE id = %d LIMIT 1", $_POST['name'], $_POST['desc'], $flags, $id);
    }
    if (isset($_FILES['update']['name'])) {
        switch ($_FILES['update']['error']) {
            case UPLOAD_ERR_OK:
                if (!_ssc_sailing_parse_csv($id)) {
                    ssc_add_message(SSC_MSG_CRIT, t('Unable to update race results'));
                } else {
                    ssc_add_message(SSC_MSG_INFO, t('Regatta details and heats updated successfully'));
                }
                unlink($_FILES['update']['tmp_name']);
                break;
            case UPLOAD_ERR_NO_FILE:
                // No file, but other details should be saved
                ssc_add_message(SSC_MSG_INFO, t("Regatta details updated successfully"));
                break;
            default:
                ssc_add_message(SSC_MSG_ERROR, t('Unknown file upload error: !num', array('!num' => $_FILES['update']['error'])));
                break;
        }
    }
    if ((int) $_POST['id'] == 0) {
        ssc_redirect('/admin/sailing/edit/' . $id);
    }
}
Exemplo n.º 2
0
/**
 * Page submission
 */
function blog_form_submit()
{
    global $ssc_database;
    $id = intval($_POST['id']);
    if ($id == 0) {
        // Insert
        $result = $ssc_database->query("INSERT INTO #__handler (path, handler) VALUES ('%s', %d)", $_POST['url'], module_id('blog'));
        if (!$result) {
            ssc_add_message(SSC_MSG_CRIT, 'Error inserting into DB');
            return;
        }
        $id = $ssc_database->last_id();
        $result = $ssc_database->query("INSERT INTO #__blog (id, name, comments, page) VALUES (%d, '%s', %d, %d)", $id, $_POST['title'], empty($_POST['comment']) ? 0 : 1, $_POST['page']);
        if (!$result) {
            ssc_add_message(SSC_MSG_CRIT, 'Error inserting into DB');
            return;
        }
        ssc_add_message(SSC_MSG_INFO, t('Page settings saved'));
        ssc_redirect('/admin/blog/edit/' . $id);
    } else {
        // Update
        $ssc_database->query("UPDATE #__blog b, #__handler h SET b.name = '%s', b.comments = %d, h.path = '%s', b.page = %d WHERE b.id = h.id AND b.id = %d", $_POST['title'], empty($_POST['comment']) ? 0 : 1, $_POST['url'], $_POST['page'], $id);
        echo $ssc_database->error();
    }
    ssc_add_message(SSC_MSG_INFO, t('Page settings saved'));
}
Exemplo n.º 3
0
/**
 * Gallery edit submission
 */
function gallery_form_submit()
{
    global $ssc_database, $ssc_site_path;
    if ($_POST['gid'] == 0) {
        // Insert new
        $result = $ssc_database->query("INSERT INTO #__handler (status, handler, path) \n\t\t\t\tVALUES (0, %d, '%s')", module_id('gallery'), $_POST['url']);
        if (!$result) {
            ssc_add_message(SSC_MSG_CRIT, 'Error inserting into DB');
            return;
        }
        $id = $ssc_database->last_id();
        $result = $ssc_database->query("INSERT INTO #__gallery (id, title, description, visible) \n\t\t\t\tVALUES (%d, '%s', '%s', %d)", $id, $_POST['name'], $_POST['desc'], $_POST['vis']);
        if (!$result) {
            $ssc_database->query("DELETE FROM #__handler WHERE id = %d LIMIT 1", $id);
            ssc_add_message(SSC_MSG_CRIT, 'Error inserting into DB');
            return;
        }
        mkdir($ssc_site_path . '/images/gallery/' . $id);
        ssc_add_message(SSC_MSG_INFO, t('Gallery saved'));
        ssc_redirect('/admin/gallery/edit/' . $id);
    } else {
        $result = $ssc_database->query("UPDATE #__gallery g, #__handler h SET title = '%s', description = '%s', \n\t\t\t\tvisible = %d, path = '%s' WHERE g.id = %d AND g.id = h.id ", $_POST['name'], $_POST['desc'], $_POST['vis'], $_POST['url'], $_POST['gid']);
        if (!$result) {
            ssc_add_message(SSC_MSG_CRIT, 'Gallery details were not saved');
        } else {
            ssc_add_message(SSC_MSG_INFO, 'Gallery details updated');
        }
    }
    if (isset($_FILES['single'])) {
        // Uploading single file
        $ext = pathinfo($_FILES['single']['name']);
        $ext = "." . $ext['extension'];
        $file = $ssc_site_path . '/tmp/' . time() . "{$ext}";
        if (!move_uploaded_file($_FILES['single']['tmp_name'], $file)) {
            return;
        }
        $image = new sscImage($file);
        // Possibly messy, but insert before resizing
        $result = $ssc_database->query("INSERT INTO #__gallery_content (gallery_id, caption, mid) VALUES (%d, '', 0)", $_POST['gid']);
        if (!$result) {
            ssc_add_message(SSC_MSG_CRIT, 'Unable to insert new image');
            return;
        }
        $id = $ssc_database->last_id();
        $path = $ssc_site_path . '/images/gallery/' . $_POST['gid'] . '/';
        if (!$image->resize($path . $id . $ext, 1024, -1)) {
            $ssc_database->query("DELETE FROM #__gallery_content WHERE id = %d LIMIT 1", $id);
            unlink($file);
            ssc_add_message(SSC_MSG_CRIT, 'Unable to insert new image');
            return;
        }
        if (!$image->resize($path . $id . "_m{$ext}", 350, -1)) {
            $ssc_database->query("DELETE FROM #__gallery_content WHERE id = %d LIMIT 1", $id);
            unlink($file);
            unlink($path . $id . $ext);
            ssc_add_message(SSC_MSG_CRIT, 'Unable to insert new image');
            return;
        }
        if (!$image->resize($path . $id . "_t{$ext}", 150, -1)) {
            $ssc_database->query("DELETE FROM #__gallery_content WHERE id = %d LIMIT 1", $id);
            unlink($file);
            unlink($path . $id . $ext);
            unlink($path . $id . "_m.{$ext}");
            ssc_add_message(SSC_MSG_CRIT, 'Unable to insert new image');
            return;
        }
        ssc_add_message(SSC_MSG_INFO, t('Image uploaded'));
        unlink($file);
    }
}
Exemplo n.º 4
0
/**
 * Page submission
 */
function static_form_submit()
{
    global $ssc_database;
    $id = intval($_POST['id']);
    if ($id == 0) {
        // Insert
        $result = $ssc_database->query("INSERT INTO #__handler (path, handler) VALUES ('%s', %d)", $_POST['url'], module_id('static'));
        if (!$result) {
            ssc_add_message(SSC_MSG_CRIT, 'Error inserting into DB');
            return;
        }
        $id = $ssc_database->last_id();
        $result = $ssc_database->query("INSERT INTO #__static (id, title, created, modified, body) VALUES (%d, '%s', %d, %d, '%s')", $id, $_POST['title'], time(), time(), $_POST['body']);
        if (!$result) {
            ssc_add_message(SSC_MSG_CRIT, 'Error inserting into DB');
            return;
        }
        ssc_add_message(SSC_MSG_INFO, t('Page saved'));
        ssc_redirect('/admin/static/edit/' . $id);
    } else {
        // Update
        $ssc_database->query("UPDATE #__static s, #__handler h SET s.title = '%s', s.body = '%s', h.path = '%s', s.modified = %d WHERE s.id = h.id AND s.id = %d", $_POST['title'], $_POST['body'], $_POST['url'], time(), $id);
    }
    ssc_add_message(SSC_MSG_INFO, t('Page saved'));
}