Example #1
0
function GalleryExportSql($args)
{
    global $DB, $C;
    $galleries_file = SafeFilename("{$GLOBALS['BASE_DIR']}/data/{$args['galleries-file']}", FALSE);
    $thumbs_file = empty($args['thumbs-file']) ? null : SafeFilename("{$GLOBALS['BASE_DIR']}/data/{$args['thumbs-file']}", FALSE);
    $tables = array('tx_categories', 'tx_annotations', 'tx_icons', 'tx_sponsors', 'tx_partners', 'tx_partner_fields', 'tx_partner_icons', 'tx_gallery_field_defs', 'tx_partner_field_defs');
    $galleries_fd = fopen($galleries_file, 'w');
    flock($galleries_fd, LOCK_EX);
    if (!empty($args['thumbs-file'])) {
        $thumbs_fd = fopen($thumbs_file, 'w');
        flock($thumbs_fd, LOCK_EX);
    }
    foreach ($tables as $table) {
        $row = $DB->Row('SHOW CREATE TABLE #', array($table));
        $create = str_replace(array("\r", "\n"), '', $row['Create Table']);
        fwrite($galleries_fd, "DROP TABLE IF EXISTS `{$table}`;\n");
        fwrite($galleries_fd, "{$create};\n");
        fwrite($galleries_fd, "DELETE FROM `{$table}`;\n");
        fwrite($galleries_fd, "LOCK TABLES `{$table}` WRITE;\n");
        fwrite($galleries_fd, "ALTER TABLE `{$table}` DISABLE KEYS;\n");
        $result = mysql_unbuffered_query("SELECT * FROM {$table}", $DB->handle);
        while ($row = mysql_fetch_row($result)) {
            $row = array_map('mysql_real_escape_string', $row);
            fwrite($galleries_fd, "INSERT INTO `{$table}` VALUES ('" . join("','", $row) . "');\n");
        }
        $DB->Free($result);
        fwrite($galleries_fd, "UNLOCK TABLES;\n");
        fwrite($galleries_fd, "ALTER TABLE `{$table}` ENABLE KEYS;\n");
    }
    // Get CREATE clause for tx_gallery_fields
    $row = $DB->Row('SHOW CREATE TABLE #', array('tx_gallery_fields'));
    $create = str_replace(array("\r", "\n"), '', $row['Create Table']);
    fwrite($galleries_fd, "DROP TABLE IF EXISTS `tx_gallery_fields`;\n");
    fwrite($galleries_fd, "{$create};\n");
    $gallery_tables = array('tx_gallery_previews', 'tx_gallery_fields', 'tx_gallery_icons');
    $_REQUEST = $args;
    $result = GetWhichGalleries();
    while ($gallery = mysql_fetch_row($result)) {
        $gallery = array_map('mysql_real_escape_string', $gallery);
        fwrite($galleries_fd, "INSERT INTO `tx_galleries` VALUES ('" . join("','", $gallery) . "');\n");
        foreach ($gallery_tables as $table) {
            $sub_result = $DB->Query("SELECT * FROM `{$table}` WHERE `gallery_id`=?", array($gallery[0]));
            while ($row = mysql_fetch_row($sub_result)) {
                if ($table == 'tx_gallery_previews' && !empty($args['thumbs-file']) && strpos($row[2], $C['preview_url']) === 0) {
                    $thumb_data = file_get_contents("{$C['preview_dir']}/{$row[0]}.jpg");
                    fwrite($thumbs_fd, "{$row[0]}.jpg|" . base64_encode($thumb_data) . "\n");
                }
                $row = array_map('mysql_real_escape_string', $row);
                fwrite($galleries_fd, "INSERT INTO `{$table}` VALUES ('" . join("','", $row) . "');\n");
            }
            $DB->Free($sub_result);
        }
    }
    $DB->Free($result);
    if (!empty($args['thumbs-file'])) {
        flock($thumbs_fd, LOCK_UN);
        fclose($thumbs_fd);
    }
    flock($galleries_fd, LOCK_UN);
    fclose($galleries_fd);
}
Example #2
0
function txGalleryEnable()
{
    global $DB, $json, $C;
    VerifyPrivileges(P_GALLERY_MODIFY, TRUE);
    $result = GetWhichGalleries();
    $amount = 0;
    while ($gallery = $DB->NextRow($result)) {
        if ($gallery['status'] == 'disabled') {
            $DB->Update('UPDATE `tx_galleries` SET `status`=?,`previous_status`=? WHERE `gallery_id`=?', array($gallery['previous_status'], null, $gallery['gallery_id']));
            $amount++;
        }
    }
    $DB->Free($result);
    echo $json->encode(array('status' => JSON_SUCCESS, 'message' => "{$amount} galler" . ($amount == 1 ? 'y has' : 'ies have') . " been enabled"));
}
Example #3
0
function txSubmitterMail()
{
    global $DB, $C, $t;
    VerifyAdministrator(P_GALLERY);
    if (isset($_REQUEST['to'])) {
        $result = $DB->Query('SELECT * FROM `tx_galleries` WHERE `gallery_id`=?', array($_REQUEST['to']));
    } else {
        $result = GetWhichGalleries();
    }
    $message = PrepareMessage();
    $t = new Template();
    $t->assign_by_ref('config', $C);
    while ($gallery = $DB->NextRow($result)) {
        $t->assign_by_ref('gallery', $gallery);
        SendMail($gallery['email'], $message, $t, FALSE);
    }
    $DB->Free($result);
    $message = 'The selected gallery submitters have been e-mailed';
    include_once 'includes/message.php';
}