<?php include 'template/header.php'; include 'template/menu.php'; ?> <?php if (!empty($_GET['category'])) { $category_info = category_info($_GET['category']); if (!empty($category_info)) { /*************************category update***********************/ if (!empty($_POST['submit'])) { $update_category = update_category($_GET['category'], $_POST['category_name'], $_POST['category_code_slug']); if ($update_category == 1) { $message = "Category has been updated."; } else { $errormessage = "Something wrong. Please Try Again!!"; } } /*************************end category update***********************/ $all_category = all_category(); //show all category } else { header("Location:category.php"); } } else { header("Location:category.php"); } ?>
function action_update_category($db) { $id = filter_input(INPUT_POST, 'id', FILTER_SANITIZE_NUMBER_INT); $category = filter_input(INPUT_POST, 'category', FILTER_SANITIZE_STRING); return json_encode(update_category($db, $id, $category)); }
} if (count($to_delete_elements) > 0) { if (!$simulate) { delete_elements($to_delete_elements); } $counts['del_elements'] = count($to_delete_elements); } $template->append('footer_elements', '<!-- scanning files : ' . get_elapsed_time($start_files, get_moment()) . ' -->'); } // +-----------------------------------------------------------------------+ // | synchronize files | // +-----------------------------------------------------------------------+ if (isset($_POST['submit']) and ($_POST['sync'] == 'dirs' or $_POST['sync'] == 'files') and !$general_failure) { if (!$simulate) { $start = get_moment(); update_category('all'); $template->append('footer_elements', '<!-- update_category(all) : ' . get_elapsed_time($start, get_moment()) . ' -->'); $start = get_moment(); update_global_rank(); $template->append('footer_elements', '<!-- ordering categories : ' . get_elapsed_time($start, get_moment()) . ' -->'); } if ($_POST['sync'] == 'files') { $start = get_moment(); $opts['category_id'] = ''; $opts['recursive'] = true; if (isset($_POST['cat'])) { $opts['category_id'] = $_POST['cat']; if (!isset($_POST['subcats-included']) or $_POST['subcats-included'] != 1) { $opts['recursive'] = false; } }
<?php include_once 'config.php'; include_once 'func.php'; $connection = connect_db(); if (isset($_POST['id']) || isset($_POST['name'])) { echo "success"; update_category($connection, $_POST['id'], $_POST['name']); } $result = get_category($connection); ?> <!DOCTYPE HTML> <html> <head> <title>Update Category</title> </head> <body> <div> <form action="" method="post"> <div> <select name="id"> <?php while ($row = mysqli_fetch_assoc($result)) { ?> <option value="<?php echo $row['id']; ?> "><?php echo $row['name']; ?>
$page_title = 'Categories'; // process post actions // insert category if (isset($_POST['add_category']) && $_POST['add_category'] == 'add') { $insert_status = insert_category(); if (is_int($insert_status)) { $reload = $_SERVER["PHP_SELF"] . '?page_name=categories&category_id=' . $insert_status; header('Location: ' . $reload); } else { $insert_error = $insert_status; } } // edit category if (isset($_POST['edit_category']) && $_POST['edit_category'] == 'edit') { $category_id = (int) $_GET['category_id']; $update_status = update_category($category_id); if ($update_status === true) { header('Location: ' . $url); } else { $error = $update_status; } } // delete category if (isset($_POST['confirm_delete_category']) && $_POST['confirm_delete_category'] == 'Yes') { $category_id = (int) $_GET['category_id']; $delete_status = delete_category($category_id); if ($delete_status === true) { $reload = $_SERVER["PHP_SELF"] . '?page_name=categories'; header('Location: ' . $reload); } else { $error = $delete_status;
cache_delete($moduleid . '.part'); } foreach ($setting as $k => $v) { if (strpos($k, 'seo_') === false) { continue; } seo_check($v) or msg('SEO信息包含非法字符'); } update_setting($moduleid, $setting); cache_module($moduleid); if ($setting['php_list_urlid'] != $MOD['php_list_urlid'] || $setting['htm_list_urlid'] != $MOD['htm_list_urlid'] || $setting['htm_list_prefix'] != $MOD['htm_list_prefix'] || $setting['list_html'] != $MOD['list_html']) { $_MOD = $MOD; $MOD = $setting; $result = $db->query("SELECT * FROM {$DT_PRE}category WHERE moduleid={$moduleid}"); while ($r = $db->fetch_array($result)) { update_category($r); } cache_category($moduleid); $MOD = $_MOD; } if ($setting['php_item_urlid'] != $MOD['php_item_urlid'] || $setting['htm_item_urlid'] != $MOD['htm_item_urlid'] || $setting['htm_item_prefix'] != $MOD['htm_item_prefix'] || $setting['show_html'] != $MOD['show_html']) { msg('设置保存成功,开始更新地址', '?moduleid=' . $moduleid . '&file=html&action=show&update=1&num=1000'); } dmsg('更新成功', '?moduleid=' . $moduleid . '&file=' . $file . '&tab=' . $tab); } else { $r = $db->get_one("SELECT MAX(itemid) AS maxid FROM {$table}"); $maxid = $r['maxid']; extract(dhtmlspecialchars($MOD)); if ($kw) { $all = 1; ob_start();
/** * Associate a list of images to a list of categories. * The function will not duplicate links and will preserve ranks. * * @param int[] $images * @param int[] $categories */ function associate_images_to_categories($images, $categories) { if (count($images) == 0 or count($categories) == 0) { return false; } // get existing associations $query = ' SELECT image_id, category_id FROM ' . IMAGE_CATEGORY_TABLE . ' WHERE image_id IN (' . implode(',', $images) . ') AND category_id IN (' . implode(',', $categories) . ') ;'; $result = pwg_query($query); $existing = array(); while ($row = pwg_db_fetch_assoc($result)) { $existing[$row['category_id']][] = $row['image_id']; } // get max rank of each categories $query = ' SELECT category_id, MAX(rank) AS max_rank FROM ' . IMAGE_CATEGORY_TABLE . ' WHERE rank IS NOT NULL AND category_id IN (' . implode(',', $categories) . ') GROUP BY category_id ;'; $current_rank_of = query2array($query, 'category_id', 'max_rank'); // associate only not already associated images $inserts = array(); foreach ($categories as $category_id) { if (!isset($current_rank_of[$category_id])) { $current_rank_of[$category_id] = 0; } if (!isset($existing[$category_id])) { $existing[$category_id] = array(); } foreach ($images as $image_id) { if (!in_array($image_id, $existing[$category_id])) { $rank = ++$current_rank_of[$category_id]; $inserts[] = array('image_id' => $image_id, 'category_id' => $category_id, 'rank' => $rank); } } } if (count($inserts)) { mass_inserts(IMAGE_CATEGORY_TABLE, array_keys($inserts[0]), $inserts); update_category($categories); } }
if ($catid) { $catids = $catid; } $catids or msg(); $do->delete($catids); $NUM > 200 ? $do->cache() : $do->repair(); dmsg('删除成功', $forward); break; case 'update': if (!$category || !is_array($category)) { msg(); } $do->update($category); foreach ($category as $catid => $v) { $CATEGORY[$catid] = $db->get_one("SELECT * FROM {$table} WHERE catid={$catid}"); update_category($CATEGORY[$catid]); } $NUM > 200 ? $do->cache() : $do->repair(); dmsg('更新成功', $forward); break; case 'letters': $update = false; foreach ($CATEGORY as $k => $v) { if (strlen($v['letter']) != 1) { $letter = $do->get_letter($v['catname'], false); if ($letter) { $update = true; $letter = substr($letter, 0, 1); $db->query("UPDATE {$table} SET letter='{$letter}' WHERE catid='{$v['catid']}'"); } }
} else { update_category($category['id'], 'aot', 0); } if ($_POST['expanded'][$category['id']] == "on") { update_category($category['id'], 'expanded', 1); } else { update_category($category['id'], 'expanded', 0); } } // Update order foreach ($_POST['order'] as $id => $order) { update_category($id, 'order', $order); } // Update name foreach ($_POST['name'] as $id => $name) { update_category($id, 'name', $name); } $success = lang('success_edited_cat'); } if (isset($_POST['add'])) { // Convert checkboxes if ($_POST['aop'] == "on") { $_POST['aop'] = 1; } else { $_POST['aop'] = 0; } if ($_POST['aot'] == "on") { $_POST['aot'] = 1; } else { $_POST['aot'] = 0; }
<meta charset="utf-8"> <?php session_start(); require_once "book_f.php"; ?> <?php if (check_admin_user()) { if (isset($_POST['updatecat'])) { if (update_category($_POST['catid'], $_POST['catname'])) { echo "Loại sách đã được cập nhật ok<br>"; } else { echo "Có lỗi. Loại sách không được cập nhật. Error<br>"; } } else { echo "Bạn không click updatecat<br>"; } do_html_url("index.php?dk=admin", "Trở lại trang quản trị"); } else { echo "Bạn không là admin. Không xem trang này được"; } ?>
function ufdbtables($nopid = false) { $unix = new unix(); $sock = new sockets(); $users = new usersMenus(); if (!$users->CORP_LICENSE) { updatev2_checkversions(); updatev2_progress(10, "{license_error}"); return; } if (!$nopid) { $pidfile = "/etc/artica-postfix/pids/" . basename(__FILE__) . "." . __FUNCTION__ . ".pid"; $nohup = $unix->find_program("nohup"); $pid = @file_get_contents($pidfile); if ($unix->process_exists($pid, __FILE__)) { $timepid = $unix->PROCCESS_TIME_MIN($pid); updatev2_progress(110, "Error, {$timepid} already running [" . __LINE__ . "]"); if (!$GLOBALS["NOLOGS"]) { // ufdbguard_admin_events("UFDB::Warning: Task already executed PID: $pid since {$timepid}Mn",__FUNCTION__,__FILE__,__LINE__,"ufbd-artica"); return; } } @file_put_contents($pidfile, getmypid()); } $EnableArticaMetaClient = intval(@file_get_contents("/etc/artica-postfix/settings/Daemons/EnableArticaMetaClient")); $EnableArticaMetaServer = intval(@file_get_contents("/etc/artica-postfix/settings/Daemons/EnableArticaMetaServer")); if ($EnableArticaMetaServer == 1) { $EnableArticaMetaClient = 0; } if ($EnableArticaMetaClient == 1) { updatev2_progress(10, "Using Meta console [" . __LINE__ . "]"); return ufdbtables_artica_meta(); } $GLOBALS["EVENTS"] = array(); $CACHE_FILE = "/etc/artica-postfix/settings/Daemons/CurrentArticaDbCloud"; $InterfaceFile = "/etc/artica-postfix/settings/Daemons/ArticaDbCloud"; updatev2_checkversion(); $UseRemoteUfdbguardService = $sock->GET_INFO('UseRemoteUfdbguardService'); if (!is_numeric($UseRemoteUfdbguardService)) { $UseRemoteUfdbguardService = 0; } if ($UseRemoteUfdbguardService == 1) { updatev2_progress(10, "UseRemoteUfdbguardService = TRUE - aborting [" . __LINE__ . "]"); return; } if ($GLOBALS["MIRROR"] == null) { updatev2_progress(10, "MIRROR is null #1 [" . __LINE__ . "]"); unset($GLOBALS["updatev2_checkversion"]); updatev2_checkversion(); } if ($GLOBALS["MIRROR"] == null) { updatev2_progress(10, "MIRROR is null #2 [" . __LINE__ . "]"); webupdate_admin_mysql(0, "Unable to find a suitable mirror", null, __FILE__, __LINE__); return; } $tmpdir = $unix->TEMP_DIR(); $URIBASE = $GLOBALS["MIRROR"]; $WORKDIR = $GLOBALS["WORKDIR_LOCAL"]; if (is_link($WORKDIR)) { $WORKDIR = readlink($WORKDIR); } $CategoriesDatabasesByCron = intval($sock->GET_INFO("CategoriesDatabaseByCron")); if (!$GLOBALS["FORCE"]) { if ($CategoriesDatabasesByCron == 1) { if (!$GLOBALS["BYCRON"]) { updatev2_progress(110, "{done} CategoriesDatabasesByCron [" . __LINE__ . "]"); return; } } } $MAIN_ARRAY = unserialize(base64_decode(@file_get_contents($InterfaceFile))); $LOCAL_ARRAY = unserialize(@file_get_contents($CACHE_FILE)); $countDecategories = count($MAIN_ARRAY); updatev2_progress(10, "{$countDecategories} {categories}"); $c = 0; $FAILED = 0; $updated = 0; $GLOBALS["DOWNLOADED_SIZE"] = 0; @mkdir("/var/lib/ufdbartica", 0755, true); $CountOfPackages = count($MAIN_ARRAY); while (list($tablename, $MAIN) = each($MAIN_ARRAY)) { $c++; $increment_text = " [{$c}/{$CountOfPackages}]"; $DOWNLOADED_SIZE = FormatBytes($GLOBALS["DOWNLOADED_SIZE"] / 1024); $ROWS = $MAIN["ROWS"]; $ROWS_TEXT = FormatNumber($ROWS); $TIME = $MAIN["TIME"]; $MD5SRC = $MAIN["MD5SRC"]; $MD5GZ = $MAIN["MD5GZ"]; $CurrentFile = "/var/lib/ufdbartica/{$tablename}/domains.ufdb"; $CURRENT_MD5 = md5_file($CurrentFile); $prc = $c / $countDecategories; $prc = round($prc * 100); if ($prc > 10) { if ($prc < 95) { updatev2_progress($prc, "{checking} {$tablename} ({$ROWS_TEXT} {items}){$increment_text}"); } } if ($CURRENT_MD5 == $MD5SRC) { updatev2_progress($prc, "{skipping} {$tablename} ({$ROWS_TEXT} {items}){$increment_text}"); $LOCAL_ARRAY[$tablename]["ROWS"] = $ROWS; $LOCAL_ARRAY[$tablename]["TIME"] = $TIME; $LOCAL_ARRAY[$tablename]["SUCCESS"] = true; $LOCAL_ARRAY[$tablename]["MD5SRC"] = $CURRENT_MD5; $LOCAL_ARRAY[$tablename]["SIZE"] = @filesize($CurrentFile); @file_put_contents($CACHE_FILE, serialize($LOCAL_ARRAY)); continue; } updatev2_progress($prc, "{updating} {$tablename} ({$DOWNLOADED_SIZE}) ({$ROWS_TEXT} {items}){$increment_text}"); if (!update_category("{$URIBASE}/{$tablename}.gz", $tablename, $MD5GZ, $MD5SRC, $prc, $increment_text)) { updatev2_progress($prc, "{update_failed} {$tablename}"); $LOCAL_ARRAY[$tablename]["SUCCESS"] = false; $FAILED++; if ($FAILED > 5) { updatev2_progress(110, "{too_many_errors} {aborting}"); return; } continue; } $DOWNLOADED_SIZE = FormatBytes($GLOBALS["DOWNLOADED_SIZE"] / 1024); updatev2_progress($prc, "{success} {$tablename} ({$DOWNLOADED_SIZE})"); $LOCAL_ARRAY[$tablename]["ROWS"] = $ROWS; $LOCAL_ARRAY[$tablename]["TIME"] = $TIME; $LOCAL_ARRAY[$tablename]["UPDATED"] = time(); $LOCAL_ARRAY[$tablename]["SUCCESS"] = true; $LOCAL_ARRAY[$tablename]["MD5SRC"] = md5_file($CurrentFile); $LOCAL_ARRAY[$tablename]["SIZE"] = @filesize($CurrentFile); @file_put_contents($CACHE_FILE, serialize($LOCAL_ARRAY)); $updated++; } if ($updated > 0) { artica_update_event(2, "Success update {$updated} Licensed Webfiltering databases", null, __FILE__, __LINE__); squid_admin_mysql(2, "Success update {$updated} Licensed Webfiltering databases", null, __FILE__, __LINE__); squid_admin_mysql(2, "Reloading Web filtering services", null, __FILE__, __LINE__); shell_exec("/etc/init.d/ufdb reload"); shell_exec("/etc/init.d/ufdbcat reload"); } updatev2_progress(96, "{verify}"); reset($MAIN_ARRAY); while (list($tablename, $MAIN) = each($MAIN_ARRAY)) { $ROWS = $MAIN["ROWS"]; $ROWS_TEXT = FormatNumber($ROWS); $TIME = $MAIN["TIME"]; $MD5SRC = $MAIN["MD5SRC"]; $MD5GZ = $MAIN["MD5GZ"]; $CurrentFile = "/var/lib/ufdbartica/{$tablename}/domains.ufdb"; echo "{$tablename}\n"; $unix->events("Verify: {$tablename} [{$MD5SRC}]", "/var/log/artica-ufdb.log", false, __FUNCTION__, __LINE__, __FILE__); if (!is_file($CurrentFile)) { $unix->events("Verifiy: {$tablename} {$CurrentFile} no such file", "/var/log/artica-ufdb.log", false, __FUNCTION__, __LINE__, __FILE__); echo "{$CurrentFile} no such file\n"; $LOCAL_ARRAY[$tablename]["SUCCESS"] = false; updatev2_progress(96, "{$tablename} {failed}"); continue; } $md5db = md5_file($CurrentFile); if ($md5db != $MD5SRC) { $unix->events("Verifiy: {$tablename} {$CurrentFile} MD5 differ {$md5db}<>{$MD5SRC}", "/var/log/artica-ufdb.log", false, __FUNCTION__, __LINE__, __FILE__); echo "{$CurrentFile} MD5 differ\n"; $LOCAL_ARRAY[$tablename]["SUCCESS"] = false; updatev2_progress(96, "{$tablename} {failed}"); continue; } $unix->events("Verifiy: {$tablename} success...", "/var/log/artica-ufdb.log", false, __FUNCTION__, __LINE__, __FILE__); $LOCAL_ARRAY[$tablename]["SUCCESS"] = true; $LOCAL_ARRAY[$tablename]["MD5SRC"] = $md5db; $LOCAL_ARRAY[$tablename]["SIZE"] = @filesize($CurrentFile); $LOCAL_ARRAY[$tablename]["ROWS"] = $ROWS; $LOCAL_ARRAY[$tablename]["TIME"] = $TIME; $LOCAL_ARRAY[$tablename]["UPDATED"] = time(); } @file_put_contents($CACHE_FILE, serialize($LOCAL_ARRAY)); updatev2_progress(99, "{done}"); }
$query = ' ALTER TABLE ' . PREFIX_TABLE . $table . ' ADD ' . ($index['unique'] ? 'UNIQUE' : 'INDEX') . ' ' . $index_name . ' (' . implode(',', $index['columns']) . ') ;'; pwg_query($query); } } } // // insert params in new configuration table // $params = array(array('param' => 'prefix_thumbnail', 'value' => $save['prefix_thumbnail'], 'comment' => 'thumbnails filename prefix'), array('param' => 'mail_webmaster', 'value' => $save['mail_webmaster'], 'comment' => 'webmaster mail'), array('param' => 'default_language', 'value' => 'en_UK.iso-8859-1', 'comment' => 'Default gallery language'), array('param' => 'default_template', 'value' => 'default', 'comment' => 'Default gallery style'), array('param' => 'default_maxwidth', 'value' => '', 'comment' => 'maximum width authorized for displaying images'), array('param' => 'default_maxheight', 'value' => '', 'comment' => 'maximum height authorized for the displaying images'), array('param' => 'nb_comment_page', 'value' => '10', 'comment' => 'number of comments to display on each page'), array('param' => 'upload_maxfilesize', 'value' => '150', 'comment' => 'maximum filesize for the uploaded pictures'), array('param' => 'upload_maxwidth', 'value' => '800', 'comment' => 'maximum width authorized for the uploaded images'), array('param' => 'upload_maxheight', 'value' => '600', 'comment' => 'maximum height authorized for the uploaded images'), array('param' => 'upload_maxwidth_thumbnail', 'value' => '150', 'comment' => 'maximum width authorized for the uploaded thumbnails'), array('param' => 'upload_maxheight_thumbnail', 'value' => '100', 'comment' => 'maximum height authorized for the uploaded thumbnails'), array('param' => 'log', 'value' => 'false', 'comment' => 'keep an history of visits on your website'), array('param' => 'comments_validation', 'value' => 'false', 'comment' => 'administrators validate users comments before becoming visible'), array('param' => 'comments_forall', 'value' => 'false', 'comment' => 'even guest not registered can post comments'), array('param' => 'mail_notification', 'value' => 'false', 'comment' => 'automated mail notification for adminsitrators'), array('param' => 'nb_image_line', 'value' => '5', 'comment' => 'Number of images displayed per row'), array('param' => 'nb_line_page', 'value' => '3', 'comment' => 'Number of rows displayed per page'), array('param' => 'recent_period', 'value' => '7', 'comment' => 'Period within which pictures are displayed as new (in days)'), array('param' => 'auto_expand', 'value' => 'false', 'comment' => 'Auto expand of the category tree'), array('param' => 'show_nb_comments', 'value' => 'false', 'comment' => 'Show the number of comments under the thumbnails'), array('param' => 'use_iptc', 'value' => 'false', 'comment' => 'Use IPTC data during database synchronization with files metadata'), array('param' => 'use_exif', 'value' => 'false', 'comment' => 'Use EXIF data during database synchronization with files metadata'), array('param' => 'show_iptc', 'value' => 'false', 'comment' => 'Show IPTC metadata on picture.php if asked by user'), array('param' => 'show_exif', 'value' => 'true', 'comment' => 'Show EXIF metadata on picture.php if asked by user'), array('param' => 'authorize_remembering', 'value' => 'true', 'comment' => 'Authorize users to be remembered, see $conf{remember_me_length}'), array('param' => 'gallery_locked', 'value' => 'false', 'comment' => 'Lock your gallery temporary for non admin users')); mass_inserts(CONFIG_TABLE, array_keys($params[0]), $params); // refresh calculated datas update_global_rank(); update_category(); // update calculated field "images.path" $cat_ids = array(); $query = ' SELECT DISTINCT(storage_category_id) AS unique_storage_category_id FROM ' . IMAGES_TABLE . ' ;'; $result = pwg_query($query); while ($row = pwg_db_fetch_assoc($result)) { array_push($cat_ids, $row['unique_storage_category_id']); } $fulldirs = get_fulldirs($cat_ids); foreach ($cat_ids as $cat_id) { $query = ' UPDATE ' . IMAGES_TABLE . ' SET path = CONCAT(\'' . $fulldirs[$cat_id] . '\',\'/\',file)
if (empty($category['ranking'])) { $error_ranking = 'Ranking must be filled out'; $formValidation = false; } else { if (!is_numeric($category['ranking'])) { $error_ranking = 'Ranking must be valid number'; $formValidation = false; } } if ($formValidation) { if (empty($category['categoryID'])) { session_start(); $category['createdBy'] = $_SESSION['userId']; add_category($category); } else { update_category($category); } $success_notification = 'Successfully saved'; } } catch (Exception $e) { $error_notification = $e->getMessage(); } } else { if (isset($_GET['categoryID'])) { $categoryID = $_GET['categoryID']; } if (!empty($categoryID)) { $category = get_category($categoryID); } } ?>
<?php // include function files for this application require_once 'book_sc_fns.php'; session_start(); do_html_header('Updating category'); if (check_admin_user()) { if (filled_out($HTTP_POST_VARS)) { if (update_category($HTTP_POST_VARS['catid'], $HTTP_POST_VARS['catname'])) { echo 'Category was updated.<br />'; } else { echo 'Category could not be updated.<br />'; } } else { echo 'You have not filled out the form. Please try again.'; } do_html_url('admin.php', 'Back to administration menu'); } else { echo 'You are not authorised to view this page.'; } do_html_footer();
$_SESSION["token"] = $sessionToken; } elseif (($action == 2) && ($sessionToken == $formToken)) { delete_category($categoryname); echo "Category $categoryname deleted<br>"; $sessionToken = $sessionToken + 1; $_SESSION["token"] = $sessionToken; } elseif (($action == 3) && ($sessionToken == $formToken)) { $totalAppClass = trim ($totalAppClass, ","); if (is_array($functions)) { $functions = implode (" ", $functions); } update_category($categoryname, $totalAppClass, $categorydescription, $categorytype,$functions); echo "Category $categoryname updated <br>"; $sessionToken = $sessionToken + 1; $_SESSION["token"] = $sessionToken; } ?> <fieldset> <legend>Available Categories</legend> <p> To Change or Delete a category, select it</p> <? # Setting a session token
include 'category_list.php'; break; case 'delete_category': $category_id = filter_input(INPUT_POST, 'category_id', FILTER_VALIDATE_INT); delete_category($category_id); header("Location: ."); break; case 'add_category': $name = filter_input(INPUT_POST, 'name'); // Validate inputs if (empty($name)) { display_error('You must include a name for the category. Please try again.'); } else { $category_id = add_category($name); } header("Location: ."); break; case 'update_category': $category_id = filter_input(INPUT_POST, 'category_id', FILTER_VALIDATE_INT); $name = filter_input(INPUT_POST, 'name'); // Validate inputs if (empty($name)) { display_error('You must include a name for the category. Please try again.'); } else { update_category($category_id, $name); } header("Location: ."); break; }
/** * Sets associations of an image * @param int $image_id * @param string $categories_string - "cat_id[,rank];cat_id[,rank]" * @param bool $replace_mode - removes old associations */ function ws_add_image_category_relations($image_id, $categories_string, $replace_mode = false) { // let's add links between the image and the categories // // $params['categories'] should look like 123,12;456,auto;789 which means: // // 1. associate with category 123 on rank 12 // 2. associate with category 456 on automatic rank // 3. associate with category 789 on automatic rank $cat_ids = array(); $rank_on_category = array(); $search_current_ranks = false; $tokens = explode(';', $categories_string); foreach ($tokens as $token) { @(list($cat_id, $rank) = explode(',', $token)); if (!preg_match('/^\\d+$/', $cat_id)) { continue; } $cat_ids[] = $cat_id; if (!isset($rank)) { $rank = 'auto'; } $rank_on_category[$cat_id] = $rank; if ($rank == 'auto') { $search_current_ranks = true; } } $cat_ids = array_unique($cat_ids); if (count($cat_ids) == 0) { return new PwgError(500, '[ws_add_image_category_relations] there is no category defined in "' . $categories_string . '"'); } $query = ' SELECT id FROM ' . CATEGORIES_TABLE . ' WHERE id IN (' . implode(',', $cat_ids) . ') ;'; $db_cat_ids = query2array($query, null, 'id'); $unknown_cat_ids = array_diff($cat_ids, $db_cat_ids); if (count($unknown_cat_ids) != 0) { return new PwgError(500, '[ws_add_image_category_relations] the following categories are unknown: ' . implode(', ', $unknown_cat_ids)); } $to_update_cat_ids = array(); // in case of replace mode, we first check the existing associations $query = ' SELECT category_id FROM ' . IMAGE_CATEGORY_TABLE . ' WHERE image_id = ' . $image_id . ' ;'; $existing_cat_ids = query2array($query, null, 'category_id'); if ($replace_mode) { $to_remove_cat_ids = array_diff($existing_cat_ids, $cat_ids); if (count($to_remove_cat_ids) > 0) { $query = ' DELETE FROM ' . IMAGE_CATEGORY_TABLE . ' WHERE image_id = ' . $image_id . ' AND category_id IN (' . implode(', ', $to_remove_cat_ids) . ') ;'; pwg_query($query); update_category($to_remove_cat_ids); } } $new_cat_ids = array_diff($cat_ids, $existing_cat_ids); if (count($new_cat_ids) == 0) { return true; } if ($search_current_ranks) { $query = ' SELECT category_id, MAX(rank) AS max_rank FROM ' . IMAGE_CATEGORY_TABLE . ' WHERE rank IS NOT NULL AND category_id IN (' . implode(',', $new_cat_ids) . ') GROUP BY category_id ;'; $current_rank_of = query2array($query, 'category_id', 'max_rank'); foreach ($new_cat_ids as $cat_id) { if (!isset($current_rank_of[$cat_id])) { $current_rank_of[$cat_id] = 0; } if ('auto' == $rank_on_category[$cat_id]) { $rank_on_category[$cat_id] = $current_rank_of[$cat_id] + 1; } } } $inserts = array(); foreach ($new_cat_ids as $cat_id) { $inserts[] = array('image_id' => $image_id, 'category_id' => $cat_id, 'rank' => $rank_on_category[$cat_id]); } mass_inserts(IMAGE_CATEGORY_TABLE, array_keys($inserts[0]), $inserts); include_once PHPWG_ROOT_PATH . 'admin/include/functions.php'; update_category($new_cat_ids); }