/** * Deletes a site and call delete_categories for each primary category of the site * * @param int $id */ function delete_site($id) { // destruction of the categories of the site $query = ' SELECT id FROM ' . CATEGORIES_TABLE . ' WHERE site_id = ' . $id . ' ;'; $category_ids = query2array($query, null, 'id'); delete_categories($category_ids); // destruction of the site $query = ' DELETE FROM ' . SITES_TABLE . ' WHERE id = ' . $id . ' ;'; pwg_query($query); }
$categories = array(); $base_url = get_root_url() . 'admin.php?page=cat_list'; $navigation = '<a href="' . $base_url . '">'; $navigation .= l10n('Home'); $navigation .= '</a>'; // +-----------------------------------------------------------------------+ // | tabs | // +-----------------------------------------------------------------------+ $page['tab'] = 'list'; include PHPWG_ROOT_PATH . 'admin/include/albums_tab.inc.php'; // +-----------------------------------------------------------------------+ // | virtual categories management | // +-----------------------------------------------------------------------+ // request to delete a virtual category if (isset($_GET['delete']) and is_numeric($_GET['delete'])) { delete_categories(array($_GET['delete'])); $_SESSION['page_infos'] = array(l10n('Virtual album deleted')); update_global_rank(); invalidate_user_cache(); $redirect_url = get_root_url() . 'admin.php?page=cat_list'; if (isset($_GET['parent_id'])) { $redirect_url .= '&parent_id=' . $_GET['parent_id']; } redirect($redirect_url); } elseif (isset($_POST['submitAdd'])) { $output_create = create_virtual_category($_POST['virtual_name'], @$_GET['parent_id']); invalidate_user_cache(); if (isset($output_create['error'])) { $page['errors'][] = $output_create['error']; } else { $page['infos'][] = $output_create['info'];
/** * API method * Deletes a category * @param mixed[] $params * @option string|int[] category_id * @option string photo_deletion_mode * @option string pwg_token */ function ws_categories_delete($params, &$service) { if (get_pwg_token() != $params['pwg_token']) { return new PwgError(403, 'Invalid security token'); } $modes = array('no_delete', 'delete_orphans', 'force_delete'); if (!in_array($params['photo_deletion_mode'], $modes)) { return new PwgError(500, '[ws_categories_delete]' . ' invalid parameter photo_deletion_mode "' . $params['photo_deletion_mode'] . '"' . ', possible values are {' . implode(', ', $modes) . '}.'); } if (!is_array($params['category_id'])) { $params['category_id'] = preg_split('/[\\s,;\\|]/', $params['category_id'], -1, PREG_SPLIT_NO_EMPTY); } $params['category_id'] = array_map('intval', $params['category_id']); $category_ids = array(); foreach ($params['category_id'] as $category_id) { if ($category_id > 0) { $category_ids[] = $category_id; } } if (count($category_ids) == 0) { return; } $query = ' SELECT id FROM ' . CATEGORIES_TABLE . ' WHERE id IN (' . implode(',', $category_ids) . ') ;'; $category_ids = array_from_query($query, 'id'); if (count($category_ids) == 0) { return; } include_once PHPWG_ROOT_PATH . 'admin/include/functions.php'; delete_categories($category_ids, $params['photo_deletion_mode']); update_global_rank(); }
} // to delete categories $to_delete = array(); $to_delete_derivative_dirs = array(); foreach (array_diff(array_keys($db_fulldirs), $fs_fulldirs) as $fulldir) { $to_delete[] = $db_fulldirs[$fulldir]; unset($db_fulldirs[$fulldir]); $infos[] = array('path' => $fulldir, 'info' => l10n('deleted')); if (substr_compare($fulldir, '../', 0, 3) == 0) { $fulldir = substr($fulldir, 3); } $to_delete_derivative_dirs[] = PHPWG_ROOT_PATH . PWG_DERIVATIVE_DIR . $fulldir; } if (count($to_delete) > 0) { if (!$simulate) { delete_categories($to_delete); foreach ($to_delete_derivative_dirs as $to_delete_dir) { if (is_dir($to_delete_dir)) { clear_derivative_cache_rec($to_delete_dir, '#.+#'); } } } $counts['del_categories'] = count($to_delete); } $template->append('footer_elements', '<!-- scanning dirs : ' . get_elapsed_time($start, get_moment()) . ' -->'); } // +-----------------------------------------------------------------------+ // | files / elements | // +-----------------------------------------------------------------------+ if (isset($_POST['submit']) and $_POST['sync'] == 'files' and !$general_failure) { $start_files = get_moment();
if ($category_id == NULL || $category_id == FALSE || $code == NULL || $name == NULL || $price == NULL || $price == FALSE) { $error = "Invalid product data. Check all fields and try again."; include '../errors/error.php'; } else { add_product($category_id, $code, $name, $price); header("Location: .?category_id={$category_id}"); } } else { if ($action == 'list_categories') { list_categories(); } else { if ($action == 'add_categories') { add_categories(); } else { if ($action == 'delete_categories') { delete_categories(); } else { if ($action == 'edit_products') { edit_products(); } } } } } } } } function list_categories() { $categories = get_categories(); include 'category_list.php';
<?php // ワンタイムトークン if (!token('check')) { error('不正なアクセスです。'); } // トランザクションを開始 db_transaction(); // 分類を削除 $resource = delete_categories(array('where' => array('categories.id = :id', array('id' => $_POST['id']))), array('associate' => 'true')); if (!$resource) { error('データを削除できません。'); } // トランザクションを終了 db_commit(); // リダイレクト redirect('/admin/category?ok=delete');
function osm_get_items($page) { // Limit search by category, by tag, by smartalbum $LIMIT_SEARCH = ""; $INNER_JOIN = ""; if (isset($page['section'])) { if ($page['section'] === 'categories' and isset($page['category']) and isset($page['category']['id'])) { $LIMIT_SEARCH = "FIND_IN_SET(" . $page['category']['id'] . ", c.uppercats) AND "; $INNER_JOIN = "INNER JOIN " . CATEGORIES_TABLE . " AS c ON ic.category_id = c.id"; } if ($page['section'] === 'tags' and isset($page['tags']) and isset($page['tags'][0]['id'])) { $items = get_image_ids_for_tags(array($page['tags'][0]['id'])); if (!empty($items)) { $LIMIT_SEARCH = "ic.image_id IN (" . implode(',', $items) . ") AND "; } } if ($page['section'] === 'tags' and isset($page['category']) and isset($page['category']['id'])) { $LIMIT_SEARCH = "FIND_IN_SET(" . $page['category']['id'] . ", c.uppercats) AND "; $INNER_JOIN = "INNER JOIN " . CATEGORIES_TABLE . " AS c ON ic.category_id = c.id"; } } $forbidden = get_sql_condition_FandF(array('forbidden_categories' => 'ic.category_id', 'visible_categories' => 'ic.category_id', 'visible_images' => 'i.id'), "\n AND"); /* We have lat and lng coordonate for virtual album */ if (isset($_GET['min_lat']) and isset($_GET['max_lat']) and isset($_GET['min_lng']) and isset($_GET['max_lng'])) { $LIMIT_SEARCH = ""; $INNER_JOIN = ""; /* Delete all previous album */ $query = "SELECT `id` FROM " . CATEGORIES_TABLE . " WHERE `name` = 'Locations' AND `comment` LIKE '%OSM plugin%';"; $ids = array_from_query($query, 'id'); /* Unlink items for the previous album */ delete_categories($ids, $photo_deletion_mode = 'no_delete'); /* Create an album */ $options = array('comment' => 'Generated by OSM plugin'); $osm_album = create_virtual_category('Locations', NULL, $options); /* Create a sub album */ $options = array('comment' => "OSM virtual album\nlat:" . $_GET['min_lat'] . " " . $_GET['max_lat'] . "\nlng:" . $_GET['min_lng'] . " " . $_GET['max_lng']); $osm_sub_album = create_virtual_category("OSM" . $_GET['min_lat'] . "", $osm_album['id'], $options); /* Get all items inside the lat and lng */ $query = "SELECT `id`, `latitude`, `longitude` \n FROM " . IMAGES_TABLE . " AS i\n INNER JOIN " . IMAGE_CATEGORY_TABLE . " AS ic ON id = ic.image_id\n WHERE " . $LIMIT_SEARCH . " `latitude` IS NOT NULL AND `longitude` IS NOT NULL \n AND `latitude` > " . $_GET['min_lat'] . " AND `latitude` < " . $_GET['max_lat'] . "\n AND `longitude` > " . $_GET['min_lng'] . " AND `longitude` < " . $_GET['max_lng'] . "\n " . $forbidden . ";"; $items = hash_from_query($query, 'id'); /* Add items to the new sub album */ foreach ($items as $item) { $query = "INSERT INTO " . IMAGE_CATEGORY_TABLE . " ( `image_id` ,`category_id` ,`rank` ) VALUES ( '" . $item['id'] . "', '" . $osm_sub_album['id'] . "', NULL );"; pwg_query($query); } /* Redirect to the new album */ header('Location: ' . get_absolute_root_url() . 'index.php?/category/' . $osm_sub_album['id']); exit; } // Fetch data with latitude and longitude //$query="SELECT `latitude`, `longitude`, `name`, `path` FROM ".IMAGES_TABLE." WHERE `latitude` IS NOT NULL AND `longitude` IS NOT NULL;"; // SUBSTRING_INDEX(TRIM(LEADING '.' FROM `path`), '.', 1) full path without filename extension // SUBSTRING_INDEX(TRIM(LEADING '.' FROM `path`), '.', -1) full path with only filename extension if (isset($page['image_id'])) { $LIMIT_SEARCH .= 'i.id = ' . $page['image_id'] . ' AND '; } $query = "SELECT i.latitude, i.longitude,\n IFNULL(i.name, '') AS `name`,\n IF(i.representative_ext IS NULL,\n CONCAT(SUBSTRING_INDEX(TRIM(LEADING '.' FROM i.path), '.', 1 ), '-sq.', SUBSTRING_INDEX(TRIM(LEADING '.' FROM i.path), '.', -1 )),\n TRIM(LEADING '.' FROM\n REPLACE(i.path, TRIM(TRAILING '.' FROM SUBSTRING_INDEX(i.path, '/', -1 )),\n CONCAT('pwg_representative/',\n CONCAT(\n TRIM(TRAILING '.' FROM SUBSTRING_INDEX( SUBSTRING_INDEX(i.path, '/', -1 ) , '.', 1 )),\n CONCAT('-sq.', i.representative_ext)\n )\n )\n )\n )\n ) AS `pathurl`,\n TRIM(TRAILING '/' FROM CONCAT( i.id, '/category/', IFNULL(i.storage_category_id, '') ) ) AS `imgurl`,\n IFNULL(i.comment, '') AS `comment`,\n IFNULL(i.author, '') AS `author`,\n i.width\n FROM " . IMAGES_TABLE . " AS i\n INNER JOIN (" . IMAGE_CATEGORY_TABLE . " AS ic " . $INNER_JOIN . ") ON i.id = ic.image_id\n WHERE " . $LIMIT_SEARCH . " i.latitude IS NOT NULL AND i.longitude IS NOT NULL " . $forbidden . " GROUP BY i.id;"; //echo $query; $php_data = array_from_query($query); //print_r($php_data); $js_data = array(); foreach ($php_data as $array) { // MySQL did all the job //print_r($array); $js_data[] = array((double) $array['latitude'], (double) $array['longitude'], $array['name'], get_absolute_root_url() . "i.php?" . $array['pathurl'], get_absolute_root_url() . "picture.php?/" . $array['imgurl'], $array['comment'], $array['author'], (int) $array['width']); } /* START Debug generate dummy data $js_data = array(); $str = 'abcdef'; $minLat = -90.00; $maxLat = 90.00; $minLon = -180.00; $maxLon = 180.00; for ($i = 1; $i <= 5000; $i++) { $js_data[] = array( (double)$minLat + (double)((float)rand()/(float)getrandmax() * (($maxLat - $minLat) + 1)), (double)$minLon + (double)((float)rand()/(float)getrandmax() * (($maxLon - $minLon) + 1)), str_shuffle($str), "http://placehold.it/120x120", "http://placehold.it/200x200", "Comment", "Author", (int)120 ); } END Debug generate dummy data */ return $js_data; }