function delete_album($del_id)
{
    global $config;
    $sql = "SELECT c.name AS collection_name, a.name AS album_name, a.id AS album_id, c.path AS collection_path, a.path AS album_path\r\n\t\tFROM " . TABLE_PREFIX . "albums a, " . TABLE_PREFIX . "collections c\r\n\t\tWHERE c.id = a.parent_id AND a.id = '{$del_id}'";
    $result = run_query($sql);
    $album = mysql_fetch_assoc($result);
    if (!$album) {
        return array('errors' => plog_tr('No such album'));
    }
    // first delete all pictures registered with this album
    $sql = 'SELECT * FROM ' . TABLE_PREFIX . 'pictures WHERE parent_album = ' . $album['album_id'];
    $result = run_query($sql);
    while ($row = mysql_fetch_assoc($result)) {
        delete_picture($row['id']);
    }
    // XXX: un-register album
    $query = "DELETE FROM " . TABLE_PREFIX . "albums WHERE `id`= '" . $album['album_id'] . "'";
    run_query($query);
    // finally try to delete the directory itself. It will succeed, if there are no files left inside it ..
    // if there are then .. how did they get there? Probably not through plogger and in this case do we
    // really want to delete those?
    $source_album_name = $album["album_path"];
    $source_collection_name = $album["collection_path"];
    $album_directory = realpath($config['basedir'] . 'images/' . $source_collection_name . "/" . $source_album_name);
    $relative_path = substr($album_directory, 0, strlen($config['basedir']));
    $album_path = explode('/', substr($album_directory, strlen($config['basedir'])));
    // it needs to have 3 parts - images, collection name and album name, if it doesn't, then there is something
    // wrong with either collectio or album name and it's probably not safe to try to delete the directory
    if ($relative_path == $config['basedir'] && sizeof($album_path) == 3) {
        @chmod($album_directory, 0777);
        $delete_result = rmdir($album_directory);
        if (!$delete_result) {
            return array('errors' => plog_tr('Album directory still contains files after all pictures have been deleted.'));
        }
    } else {
        return array('errors' => plog_tr('Album has invalid path, not deleting directory'));
    }
    return array();
}
Exemple #2
0
function delete_album($aid)
{
    global $CONFIG, $lang_errors, $lang_delete_php;
    $query = "SELECT title, category FROM {$CONFIG['TABLE_ALBUMS']} WHERE aid ='{$aid}'";
    $result = cpg_db_query($query);
    if (!mysql_num_rows($result)) {
        cpg_die(CRITICAL_ERROR, $lang_errors['non_exist_ap'], __FILE__, __LINE__);
    }
    $album_data = mysql_fetch_array($result);
    if (!GALLERY_ADMIN_MODE) {
        if ($album_data['category'] != FIRST_USER_CAT + USER_ID) {
            cpg_die(ERROR, $lang_errors['perm_denied'], __FILE__, __LINE__);
        }
    }
    $query = "SELECT pid FROM {$CONFIG['TABLE_PICTURES']} WHERE aid='{$aid}'";
    $result = cpg_db_query($query);
    // Delete all files
    while ($pic = mysql_fetch_array($result)) {
        delete_picture($pic['pid']);
    }
    // Delete album
    $query = "DELETE from {$CONFIG['TABLE_ALBUMS']} WHERE aid='{$aid}'";
    $result = cpg_db_query($query);
    if (mysql_affected_rows() > 0) {
        echo "<tr><td colspan=\"6\" class=\"tableb\">" . sprintf($lang_delete_php['alb_del_success'], $album_data['title']) . "</td></tr>\n";
    }
}
$level = isset($_REQUEST['level']) && $_REQUEST['level'] != '' ? $_REQUEST['level'] : 'collections';
$output = "\n\t" . '<h1>' . plog_tr('Manage Content') . '</h1>' . "\n";
global $config;
// Here we will determine if we need to perform any form actions.
if (isset($_REQUEST['action'])) {
    switch ($_REQUEST['action']) {
        case 'move-delete':
            // We're either moving or deleting
            $num_items = 0;
            $action_result = array();
            if (isset($_REQUEST['delete_checked'])) {
                // Perform the delete function on the selected items
                if (isset($_REQUEST['selected'])) {
                    foreach ($_REQUEST['selected'] as $del_id) {
                        if ($level == 'pictures') {
                            $rv = delete_picture($del_id);
                        }
                        if ($level == 'collections') {
                            $rv = delete_collection($del_id);
                        }
                        if ($level == 'albums') {
                            $rv = delete_album($del_id);
                        }
                        if (isset($rv['errors'])) {
                            $output .= "\n\t" . '<p class="errors">' . $rv['errors'] . '</p>' . "\n";
                        } else {
                            $num_items++;
                        }
                    }
                    if ($num_items > 0) {
                        $text = $num_items == 1 ? plog_tr('entry') : plog_tr('entries');
Exemple #4
0
function delete_album($aid)
{
    global $xoopsDB;
    global $del_message, $del_pic, $pic_del;
    $query = "SELECT title, category FROM " . $xoopsDB->prefix("xcgal_albums") . " WHERE aid ='{$aid}'";
    $result = $xoopsDB->query($query);
    if (!$xoopsDB->getRowsNum($result)) {
        redirect_header('index.php', 2, _MD_NON_EXIST_AP);
    }
    $album_data = $xoopsDB->fetchArray($result);
    if (!GALLERY_ADMIN_MODE) {
        if ($album_data['category'] != FIRST_USER_CAT + USER_ID) {
            redirect_header('index.php', 2, _MD_PERM_DENIED);
        }
    }
    $query = "SELECT pid FROM " . $xoopsDB->prefix("xcgal_pictures") . " WHERE aid='{$aid}'";
    $result = $xoopsDB->query($query);
    // Delete all files
    $pic_del = '';
    while ($pic = $xoopsDB->fetchArray($result)) {
        delete_picture($pic['pid']);
        $pic_del .= $del_pic;
        $del_pic = '';
    }
    // Delete album
    $query = "DELETE from " . $xoopsDB->prefix("xcgal_albums") . " WHERE aid='{$aid}'";
    $result = $xoopsDB->queryf($query);
    if ($xoopsDB->getAffectedRows() > 0) {
        $del_message = sprintf(_MD_DEL_ALB_DEL_SUC, $album_data['title']);
    } else {
        $del_message = '';
    }
}
function delete_album($aid)
{
    global $CONFIG, $lang_errors, $lang_delete_php, $LINEBREAK;
    $return = '';
    $query = "SELECT title, category, owner FROM {$CONFIG['TABLE_ALBUMS']} WHERE aid ='{$aid}'";
    $result = cpg_db_query($query);
    if (!$result->numRows()) {
        cpg_die(CRITICAL_ERROR, $lang_errors['non_exist_ap'], __FILE__, __LINE__);
    }
    $album_data = $result->fetchAssoc(true);
    if (!GALLERY_ADMIN_MODE) {
        if ($album_data['category'] != FIRST_USER_CAT + USER_ID && $album_data['owner'] != USER_ID) {
            cpg_die(ERROR, $lang_errors['perm_denied'], __FILE__, __LINE__);
        }
    }
    $query = "SELECT pid FROM {$CONFIG['TABLE_PICTURES']} WHERE aid='{$aid}'";
    $result = cpg_db_query($query);
    // Delete all files
    $loopCounter = 0;
    while ($pic = $result->fetchAssoc()) {
        if ($loopCounter / 2 == floor($loopCounter / 2)) {
            $tablecellstyle = 'tableb';
        } else {
            $tablecellstyle = 'tableb tableb_alternate';
        }
        ob_start();
        delete_picture($pic['pid'], $tablecellstyle);
        $return .= ob_get_contents();
        $loopCounter++;
        ob_end_clean();
    }
    $result->free();
    // Delete album
    $query = "DELETE FROM {$CONFIG['TABLE_ALBUMS']} WHERE aid='{$aid}'";
    cpg_db_query($query);
    if (cpg_db_affected_rows() > 0) {
        $return .= "<tr><td colspan=\"6\" class=\"tableb\">" . sprintf($lang_delete_php['alb_del_success'], $album_data['title']) . '</td></tr>' . $LINEBREAK;
    }
    return $return;
}
Exemple #6
0
function delete_album($aid)
{
    global $db, $CONFIG;
    $result = $db->sql_query("SELECT title, category FROM {$CONFIG['TABLE_ALBUMS']} WHERE aid ='{$aid}'", false, __FILE__, __LINE__);
    if (!$db->sql_numrows($result)) {
        cpg_die(_CRITICAL_ERROR, NON_EXIST_AP, __FILE__, __LINE__);
    }
    $album_data = $db->sql_fetchrow($result);
    if (!GALLERY_ADMIN_MODE) {
        if ($album_data['category'] != FIRST_USER_CAT + USER_ID) {
            cpg_die(_ERROR, PERM_DENIED, __FILE__, __LINE__);
        }
    }
    $result = $db->sql_query("SELECT pid FROM {$CONFIG['TABLE_PICTURES']} WHERE aid='{$aid}'", false, __FILE__, __LINE__);
    // Delete all files
    while ($pic = $db->sql_fetchrow($result)) {
        delete_picture($pic['pid']);
    }
    speedup_pictures();
    // Delete album
    $result = $db->sql_query("DELETE from {$CONFIG['TABLE_ALBUMS']} WHERE aid='{$aid}'", false, __FILE__, __LINE__);
    if ($db->sql_affectedrows() > 0) {
        echo "<tr><td colspan=\"6\" class=\"tableb\">" . sprintf(ALB_DEL_SUCCESS, $album_data['title']) . "</td></tr>\n";
    }
}
function delete_album($album_id)
{
    global $smcFunc;
    $album_id = (int) $album_id;
    $request = $smcFunc['db_query']('', '
		SELECT id_album 
		FROM {db_prefix}Maximum_albums 
		WHERE parent_id = {int:id_parent}', array('id_parent' => $album_id));
    while ($album = $smcFunc['db_fetch_assoc']($request)) {
        $request2 = $smcFunc['db_query']('', '
			SELECT id_picture 
			FROM {db_prefix}Maximum_pictures 
			WHERE id_album = {int:id_album}', array('id_album' => $album['id_album']));
        while ($picture = $smcFunc['db_fetch_assoc']($request2)) {
            delete_picture($picture['id_picture']);
        }
        $smcFunc['db_query']('', '
			DELETE FROM {db_prefix}Maximum_albums 
			WHERE id_album = {int:id_album}', array('id_album' => $album['id_album']));
        delete_album($album['id_album']);
    }
    $request = $smcFunc['db_query']('', '
		SELECT id_picture 
		FROM {db_prefix}Maximum_pictures 
		WHERE id_album = {int:id_album}', array('id_album' => $album_id));
    while ($picture = $smcFunc['db_fetch_assoc']($request)) {
        delete_picture($picture['id_picture']);
    }
    $smcFunc['db_query']('', '
		DELETE FROM {db_prefix}Maximum_albums 
		WHERE id_album = {int:id_album}', array('id_album' => $album_id));
}
function delete_album($del_id)
{
    global $config;
    $sql = "SELECT c.name AS collection_name, a.name AS album_name, a.id AS album_id, c.path AS collection_path, a.path AS album_path\n\t\tFROM " . PLOGGER_TABLE_PREFIX . "albums a, " . PLOGGER_TABLE_PREFIX . "collections c\n\t\tWHERE c.id = a.parent_id AND a.id = '{$del_id}'";
    $result = run_query($sql);
    $album = $result->fetch();
    if (!$album) {
        return array('errors' => plog_tr('No such album'));
    }
    // First delete all pictures registered with this album
    $sql = 'SELECT * FROM ' . PLOGGER_TABLE_PREFIX . 'pictures WHERE parent_album = ' . $album['album_id'];
    $result = run_query($sql);
    while ($row = $result->fetch()) {
        delete_picture($row['id']);
    }
    // XXX: un-register album
    $query = "DELETE FROM " . PLOGGER_TABLE_PREFIX . "albums WHERE \"id\"= '" . $album['album_id'] . "'";
    run_query($query);
    // Finally try to delete the directory itself. It will succeed, if there are no files left inside it ..
    // If there are then .. how did they get there? Probably not through Plogger and in this case do we
    // really want to delete those?
    $source_album_name = SmartStripSlashes($album['album_path']);
    $source_collection_name = SmartStripSlashes($album['collection_path']);
    // Delete any thumbnails for the album
    $album_thumb_directory = $config['basedir'] . 'plog-content/thumbs/' . $source_collection_name . '/' . $source_album_name;
    if (file_exists($album_thumb_directory)) {
        kill_dir($album_thumb_directory);
    }
    // Check to see if the album_directory is a real directory and then try to delete it
    $album_directory = $config['basedir'] . 'plog-content/images/' . $source_collection_name . '/' . $source_album_name;
    if (is_dir($album_directory)) {
        if (!kill_dir($album_directory)) {
            return array('errors' => plog_tr('Album directory still contains files after all pictures have been deleted.'));
        }
    } else {
        return array('errors' => plog_tr('Album has invalid path, not deleting directory.'));
    }
    return array();
}