Ejemplo n.º 1
0
// |                                actions                                |
// +-----------------------------------------------------------------------+
$action = isset($_GET['action']) ? $_GET['action'] : '';
switch ($action) {
    case 'lock_gallery':
        conf_update_param('gallery_locked', 'true');
        redirect(get_root_url() . 'admin.php?page=maintenance');
        break;
    case 'unlock_gallery':
        conf_update_param('gallery_locked', 'false');
        $_SESSION['page_infos'] = array(l10n('Gallery unlocked'));
        redirect(get_root_url() . 'admin.php?page=maintenance');
        break;
    case 'categories':
        images_integrity();
        update_uppercats();
        update_category('all');
        update_global_rank();
        invalidate_user_cache(true);
        break;
    case 'images':
        images_integrity();
        update_path();
        include_once PHPWG_ROOT_PATH . 'include/functions_rate.inc.php';
        update_rating_score();
        invalidate_user_cache();
        break;
    case 'delete_orphan_tags':
        delete_orphan_tags();
        break;
    case 'user_cache':
Ejemplo n.º 2
0
/**
 * Change the parent category of the given categories. The categories are
 * supposed virtual.
 *
 * @param int[] $category_ids
 * @param int $new_parent (-1 for root)
 */
function move_categories($category_ids, $new_parent = -1)
{
    global $page;
    if (count($category_ids) == 0) {
        return;
    }
    $new_parent = $new_parent < 1 ? 'NULL' : $new_parent;
    $categories = array();
    $query = '
SELECT id, id_uppercat, status, uppercats
  FROM ' . CATEGORIES_TABLE . '
  WHERE id IN (' . implode(',', $category_ids) . ')
;';
    $result = pwg_query($query);
    while ($row = pwg_db_fetch_assoc($result)) {
        $categories[$row['id']] = array('parent' => empty($row['id_uppercat']) ? 'NULL' : $row['id_uppercat'], 'status' => $row['status'], 'uppercats' => $row['uppercats']);
    }
    // is the movement possible? The movement is impossible if you try to move
    // a category in a sub-category or itself
    if ('NULL' != $new_parent) {
        $query = '
SELECT uppercats
  FROM ' . CATEGORIES_TABLE . '
  WHERE id = ' . $new_parent . '
;';
        list($new_parent_uppercats) = pwg_db_fetch_row(pwg_query($query));
        foreach ($categories as $category) {
            // technically, you can't move a category with uppercats 12,125,13,14
            // into a new parent category with uppercats 12,125,13,14,24
            if (preg_match('/^' . $category['uppercats'] . '(,|$)/', $new_parent_uppercats)) {
                $page['errors'][] = l10n('You cannot move an album in its own sub album');
                return;
            }
        }
    }
    $tables = array(USER_ACCESS_TABLE => 'user_id', GROUP_ACCESS_TABLE => 'group_id');
    $query = '
UPDATE ' . CATEGORIES_TABLE . '
  SET id_uppercat = ' . $new_parent . '
  WHERE id IN (' . implode(',', $category_ids) . ')
;';
    pwg_query($query);
    update_uppercats();
    update_global_rank();
    // status and related permissions management
    if ('NULL' == $new_parent) {
        $parent_status = 'public';
    } else {
        $query = '
SELECT status
  FROM ' . CATEGORIES_TABLE . '
  WHERE id = ' . $new_parent . '
;';
        list($parent_status) = pwg_db_fetch_row(pwg_query($query));
    }
    if ('private' == $parent_status) {
        set_cat_status(array_keys($categories), 'private');
    }
    $page['infos'][] = l10n_dec('%d album moved', '%d albums moved', count($categories));
}