$this->response['val']['tpl-last-edit-tst'] = $tpl_data['tpl_last_edit_tm']; $this->response['html']['tpl-name-old-save'] = $tpl_data['tpl_name']; $this->response['html']['tpl-last-edit-time'] = bb_date($tpl_data['tpl_last_edit_tm'], 'd-M-y H:i'); $this->response['html']['tpl-last-edit-by'] = get_username(intval($tpl_data['tpl_last_edit_by'])); $this->response['tpl_rules_href'] = POST_URL . $tpl_data['tpl_rules_post_id'] . '#' . $tpl_data['tpl_rules_post_id']; break; // включение / отключение шаблона в форуме // включение / отключение шаблона в форуме case 'assign': if (!($tpl_id = (int) $this->request['tpl_id'])) { $this->ajax_die('Выбранный шаблон не найден, создайте новый (empty tpl_id)'); } if (!($forum_id = (int) $this->request['forum_id'])) { $this->ajax_die('empty forum_id'); } if (!forum_exists($forum_id)) { $this->ajax_die("нет такого форума [id: {$forum_id}]"); } // отключение if ($tpl_id == -1) { $new_tpl_id = 0; $this->response['msg'] = 'Шаблоны в этом форуме отключены'; } else { if (!($tpl_name = DB()->fetch_row("SELECT tpl_name FROM " . BB_TOPIC_TPL . " WHERE tpl_id = {$tpl_id} LIMIT 1", 'tpl_name'))) { $this->ajax_die("Шаблон [id: {$tpl_id}] не найден в БД"); } $new_tpl_id = $tpl_id; $this->response['msg'] = "Включен шаблон {$tpl_name}"; } DB()->query("UPDATE " . BB_FORUMS . " SET forum_tpl_id = {$new_tpl_id} WHERE forum_id = {$forum_id} LIMIT 1"); break;
function topic_move($topic_id, $to_forum_id, $from_forum_id = null, $leave_shadow = false, $insert_bot_msg = false) { global $log_action; $to_forum_id = (int) $to_forum_id; // Verify input params if (!($topic_csv = get_id_csv($topic_id))) { return false; } if (!forum_exists($to_forum_id)) { return false; } if ($from_forum_id && (!forum_exists($from_forum_id) || $to_forum_id == $from_forum_id)) { return false; } // Get topics info $where_sql = ($forum_csv = get_id_csv($from_forum_id)) ? "AND forum_id IN({$forum_csv})" : ''; $sql = "SELECT * FROM " . BB_TOPICS . " WHERE topic_id IN({$topic_csv}) AND topic_status != " . TOPIC_MOVED . " {$where_sql}"; $topics = array(); $sync_forums = array($to_forum_id => true); foreach (DB()->fetch_rowset($sql) as $row) { if ($row['forum_id'] != $to_forum_id) { $topics[$row['topic_id']] = $row; $sync_forums[$row['forum_id']] = true; } } if (!$topics or !($topic_csv = get_id_csv(array_keys($topics)))) { return false; } // Insert topic in the old forum that indicates that the topic has moved if ($leave_shadow) { $shadows = array(); foreach ($topics as $topic_id => $row) { $shadows[] = array('forum_id' => $row['forum_id'], 'topic_title' => $row['topic_title'], 'topic_poster' => $row['topic_poster'], 'topic_time' => TIMENOW, 'topic_status' => TOPIC_MOVED, 'topic_type' => POST_NORMAL, 'topic_vote' => $row['topic_vote'], 'topic_views' => $row['topic_views'], 'topic_replies' => $row['topic_replies'], 'topic_first_post_id' => $row['topic_first_post_id'], 'topic_last_post_id' => $row['topic_last_post_id'], 'topic_moved_id' => $topic_id, 'topic_last_post_time' => $row['topic_last_post_time']); } if ($sql_args = DB()->build_array('MULTI_INSERT', $shadows)) { DB()->query("INSERT INTO " . BB_TOPICS . $sql_args); } } DB()->query("UPDATE " . BB_TOPICS . " SET forum_id = {$to_forum_id} WHERE topic_id IN({$topic_csv})"); DB()->query("UPDATE " . BB_POSTS . " SET forum_id = {$to_forum_id} WHERE topic_id IN({$topic_csv})"); DB()->query("UPDATE " . BB_BT_TORRENTS . " SET forum_id = {$to_forum_id} WHERE topic_id IN({$topic_csv})"); // Bot if ($insert_bot_msg) { foreach ($topics as $topic_id => $row) { insert_post('after_move', $topic_id, $to_forum_id, $row['forum_id']); } sync('topic', array_keys($topics)); } // Sync sync('forum', array_keys($sync_forums)); // Log action foreach ($topics as $topic_id => $row) { $log_action->mod('mod_topic_move', array('forum_id' => $row['forum_id'], 'forum_id_new' => $to_forum_id, 'topic_id' => $topic_id, 'topic_title' => $row['topic_title'])); } return true; }