} if (!empty($_POST['deletepostsok'])) { // TRANSACTION PART if (!$xoopsGTicket->check(true, 'd3forum')) { redirect_header(XOOPS_URL . '/', 3, $xoopsGTicket->getErrors()); } // guest's delete (check password) if (empty($uid)) { if (empty($_POST['guest_pass']) || md5($_POST['guest_pass'] . 'd3forum') != $post_row['guest_pass_md5']) { redirect_header(XOOPS_URL . "/modules/{$mydirname}/index.php?post_id={$post_id}", 2, _MD_D3FORUM_ERR_GUESTPASSMISMATCH); exit; } } require_once dirname(dirname(__FILE__)) . '/include/transact_functions.php'; d3forum_delete_post_recursive($mydirname, $post_id); d3forum_sync_topic($mydirname, $topic_id); if ($topic_row['topic_first_post_id'] == $post_id) { redirect_header(XOOPS_URL . "/modules/{$mydirname}/index.php?forum_id={$forum_id}", 2, _MD_D3FORUM_MSG_POSTSDELETED); exit; } else { redirect_header(XOOPS_URL . "/modules/{$mydirname}/index.php?topic_id={$topic_id}", 2, _MD_D3FORUM_MSG_POSTSDELETED); exit; } } else { // FORM PART // references to confirm the post will be deleted $reference_message4html = $myts->displayTarea($post_row['post_text'], $post_row['html'], $post_row['smiley'], $post_row['xcode'], $xoopsModuleConfig['allow_textimg'], $post_row['br'], 0, $post_row['number_entity'], $post_row['special_entity']); $reference_time = intval($post_row['post_time']); if (!empty($post_row['guest_name'])) { $reference_name4html = htmlspecialchars($post_row['guest_name'], ENT_QUOTES); } else {
if ($hide_uid) { $set4sql .= ",uid=0,uid_hidden='{$uid}'"; } else { $set4sql .= ",uid='{$uid}',uid_hidden=0"; } // create topic and get a new topic_id if (!$db->query("INSERT INTO " . $db->prefix($mydirname . "_topics") . " SET forum_id={$forum_id},topic_invisible={$topic_invisible},topic_external_link_id='" . addslashes(@$external_link_id) . "'")) { die("DB ERROR IN INSERT topic"); } $topic_id = $db->getInsertId(); // create post in the topic if (!$db->query("INSERT INTO " . $db->prefix($mydirname . "_posts") . " SET {$set4sql},topic_id={$topic_id},post_time=UNIX_TIMESTAMP(),poster_ip='" . addslashes(@$_SERVER['REMOTE_ADDR']) . "'")) { die("DB ERROR IN INSERT post"); } $post_id = $db->getInsertId(); d3forum_sync_topic($mydirname, $topic_id, true, true); } } // increment post if (is_object(@$xoopsUser) && $mode != 'edit') { $xoopsUser->incrementPost(); } // set u2t_marked if ($uid && @$xoopsModuleConfig['allow_mark']) { $u2t_marked = empty($_POST['u2t_marked']) ? 0 : 1; $db->query("UPDATE " . $db->prefix($mydirname . "_users2topics") . " SET u2t_marked={$u2t_marked},u2t_time=UNIX_TIMESTAMP() WHERE uid={$uid} AND topic_id={$topic_id}"); if (!$db->getAffectedRows()) { $db->query("INSERT INTO " . $db->prefix($mydirname . "_users2topics") . " SET uid={$uid},topic_id={$topic_id},u2t_marked={$u2t_marked},u2t_time=UNIX_TIMESTAMP()"); } } // Define tags for notification message
set_time_limit(0); $synctopics_start = intval(@$_POST['synctopics_start']); $synctopics_num = empty($_POST['synctopics_num']) ? 100 : intval($_POST['synctopics_num']); // sync topics $trs = $db->query("SELECT topic_id FROM " . $db->prefix($mydirname . "_topics") . " WHERE topic_id>={$synctopics_start} AND topic_id<" . ($synctopics_start + $synctopics_num)); $topic_counter = 0; while (list($topic_id) = $db->fetchRow($trs)) { $topic_counter++; $topic_id = intval($topic_id); // sync posts from post_votes $prs = $db->query("SELECT post_id FROM " . $db->prefix($mydirname . "_posts") . " WHERE topic_id={$topic_id}"); while (list($post_id) = $db->fetchRow($prs)) { d3forum_sync_post_votes($mydirname, $post_id, false); } d3forum_sync_topic_votes($mydirname, $topic_id, false); d3forum_sync_topic($mydirname, $topic_id, false); } $_SESSION[$mydirname . '_synctopics_start'] = $synctopics_start + $synctopics_num; $_SESSION[$mydirname . '_synctopics_num'] = $synctopics_num; redirect_header(XOOPS_URL . "/modules/{$mydirname}/admin/index.php?page=advanced_admin", 3, sprintf(_MD_A_D3FORUM_FMT_SYNCTOPICSDONE, $topic_counter)); exit; } if (!empty($_POST['do_syncforums'])) { set_time_limit(0); // sync all forums $result = $db->query("SELECT forum_id FROM " . $db->prefix($mydirname . "_forums")); while (list($forum_id) = $db->fetchRow($result)) { d3forum_sync_forum($mydirname, $forum_id, false); } redirect_header(XOOPS_URL . "/modules/{$mydirname}/admin/index.php?page=advanced_admin", 3, _MD_A_D3FORUM_MSG_SYNCTABLESDONE); exit;
function d3forum_export_topic_to_d3forum($mydirname, $export_mid, $export_forum_id, $forum_id, $topic_id, $is_move = false) { $db =& Database::getInstance(); $module_handler =& xoops_gethandler('module'); $to_module =& $module_handler->get($export_mid); $export_mydirname = $to_module->getVar('dirname'); // topics table $table_name = 'topics'; $from_table = $db->prefix($mydirname . '_' . $table_name); $to_table = $db->prefix($export_mydirname . '_' . $table_name); $columns = array_diff($GLOBALS['d3forum_tables'][$table_name], array('topic_id', 'forum_id')); $columns4sql = implode(',', $columns); $sql = "INSERT INTO `{$to_table}` ({$columns4sql},`forum_id`) SELECT {$columns4sql},{$export_forum_id} FROM `{$from_table}` WHERE topic_id={$topic_id}"; $ers = $db->query($sql); $export_topic_id = $db->getInsertId(); if ($is_move) { $db->query("DELETE FROM `{$from_table}` WHERE topic_id={$topic_id}"); } // users2topics table $table_name = 'users2topics'; $from_table = $db->prefix($mydirname . '_' . $table_name); $to_table = $db->prefix($export_mydirname . '_' . $table_name); $columns = array_diff($GLOBALS['d3forum_tables'][$table_name], array('topic_id')); $columns4sql = implode(',', $columns); $sql = "INSERT INTO `{$to_table}` ({$columns4sql},`topic_id`) SELECT {$columns4sql},{$export_topic_id} FROM `{$from_table}` WHERE topic_id={$topic_id}"; $ers = $db->query($sql); if ($is_move) { $db->query("DELETE FROM `{$from_table}` WHERE topic_id={$topic_id}"); } // posts table $table_name = 'posts'; $from_table = $db->prefix($mydirname . '_' . $table_name); $to_table = $db->prefix($export_mydirname . '_' . $table_name); $columns = array_diff($GLOBALS['d3forum_tables'][$table_name], array('post_id', 'topic_id')); $columns4sql = implode(',', $columns); $prs = $db->query("SELECT post_id FROM `{$from_table}` WHERE topic_id={$topic_id} ORDER BY post_id"); $post_conversions = array(); while (list($post_id) = $db->fetchRow($prs)) { $sql = "INSERT INTO `{$to_table}` ({$columns4sql},`topic_id`) SELECT {$columns4sql},{$export_topic_id} FROM `{$from_table}` WHERE post_id={$post_id}"; $ers = $db->query($sql); $post_conversions[$post_id] = $db->getInsertId(); if ($is_move) { $db->query("DELETE FROM `{$from_table}` WHERE post_id={$post_id}"); } } // update pid of posts table foreach ($post_conversions as $post_id => $export_post_id) { $sql = "UPDATE `{$to_table}` SET pid={$export_post_id} WHERE pid={$post_id} AND topic_id={$export_topic_id}"; $ers = $db->query($sql); } // post_votes table $table_name = 'post_votes'; $from_table = $db->prefix($mydirname . '_' . $table_name); $to_table = $db->prefix($export_mydirname . '_' . $table_name); $columns = array_diff($GLOBALS['d3forum_tables'][$table_name], array('post_id')); $columns4sql = implode(',', $columns); foreach ($post_conversions as $post_id => $export_post_id) { $sql = "INSERT INTO `{$to_table}` ({$columns4sql},`post_id`) SELECT {$columns4sql},{$export_post_id} FROM `{$from_table}` WHERE post_id={$post_id}"; $ers = $db->query($sql); if ($is_move) { $db->query("DELETE FROM `{$from_table}` WHERE post_id={$post_id}"); } } // sync topic, forum, category d3forum_sync_topic($export_mydirname, $export_topic_id); if ($is_move) { d3forum_sync_forum($mydirname, $forum_id); } }