$label["employer_manager_deleted_posts"] = str_replace('%COUNT%', $i, $label["employer_manager_deleted_posts"]); $JBMarkup->ok_msg($label["employer_manager_deleted_posts"]); } else { $JBMarkup->error_msg($label["employer_manager_not_selected_del"]); } } if ($_REQUEST['expire'] != '') { if (sizeof($_REQUEST['posts']) > 0) { $i = 0; foreach ($_REQUEST['posts'] as $post_id) { $post_id = (int) $post_id; $post_data = JB_load_post_data($post_id); if ($post_data['user_id'] == $_SESSION['JB_ID']) { // is it owned by the person who logged in? $i++; JB_expire_post($post_id); JB_update_post_category_count($post_data); } } JB_finalize_post_updates(); $label['employer_manager_expired_posts'] = str_replace('%COUNT%', $i, $label['employer_manager_expired_posts']); $JBMarkup->ok_msg($label["employer_manager_expired_posts"]); } else { $JBMarkup->error_msg($label["employer_manager_not_selected_exp"]); } } if (isset($_REQUEST['undo_expire'])) { $post_id = (int) $_REQUEST['post_id']; $post_data = JB_load_post_data($post_id); if ($post_data['user_id'] == $_SESSION['JB_ID']) { // is it owned by the person who logged in?
function JB_expire_posts($post_type) { if ($post_type == 'PREMIUM') { if (defined('JB_P_POSTS_DISPLAY_DAYS')) { $display_days = JB_P_POSTS_DISPLAY_DAYS; $type_sql = " AND post_mode = 'premium' "; } else { $display_days = JB_POSTS_DISPLAY_DAYS; $type_sql = " AND post_mode != 'premium' "; } } else { $display_days = JB_POSTS_DISPLAY_DAYS; $type_sql = " AND post_mode != 'premium' "; } // select all field_id where type is Category form the post table // then put these field_ids in to a string, eg 13, 22, 24 $sql = "SELECT field_id FROM form_fields WHERE field_type='CATEGORY' AND form_id='1' "; $cat_result = JB_mysql_query($sql) or die(mysql_error()); $cats = array(); if (mysql_num_rows($cat_result)) { while ($cat_row = mysql_fetch_array($cat_result, MYSQL_ASSOC)) { $cats[] = "`" . $cat_row['field_id'] . "`"; } $cats = ', ' . implode(',', $cats); } else { // there are no categories to select $cats = ''; } // Now select the $cats along with the post_id form the posts table which // are older than $display_days (expired) $now = gmdate("Y-m-d H:i:s"); $sql = "SELECT post_id {$cats} FROM posts_table WHERE DATE_SUB('{$now}',INTERVAL " . jb_escape_sql($display_days) . " DAY) >= `post_date` AND expired='N' {$type_sql} "; $exp_result = JB_mysql_query($sql) or $DB_ERROR = mysql_error(); $affected_cats = array(); while ($post_row = mysql_fetch_array($exp_result, MYSQL_ASSOC)) { // go through each column, if the column is a post_id then expire // else it is a category foreach ($post_row as $col_name => $col_val) { if ($col_name == 'post_id') { //echo "update post_id:".$col_val."<br>"; // set to expired JB_expire_post($col_val); } else { $affected_cats[$col_val] = $col_name; // remember the affected category } } } foreach ($affected_cats as $key => $val) { //JB_update_post_category_counters($leaf_cat_id, $field_id, $search_set=''); JB_update_post_category_counters($key, $val); //echo "updating counters...$key, $val<br>"; } JB_finalize_post_updates(); }