/** * get_faq_list */ function get_faq_list($faq_id, $bean) { $list = array(); $childTags = get_child_ids($faq_id, $bean); if (count($childTags) == 0) { return $list; } $queryIds = ''; foreach (array_keys($childTags) as $node) { $queryIds .= ",'" . $node . "'"; } $queryIds = substr($queryIds, 1); //remove leading ',' $query = "select distinct(k.id)as id, k.created_by as created_by from kbdocuments k\n INNER join kbdocuments_kbtags kt on kt.kbdocument_id = k.id "; $query .= " AND k.is_external_article = 1"; $query .= "\tAND kt.kbtag_id in ({$queryIds})"; $result = $bean->db->query($query); while ($row = $bean->db->fetchByAssoc($result)) { $id = $row['id']; $record = BeanFactory::getBean('KBDocuments', $id, array("disable_row_level_security" => true)); if (empty($record)) { continue; } $query = "SELECT first_name, last_name FROM users WHERE id = '" . $row['created_by'] . "'"; $results = $bean->db->query($query); $row2 = $bean->db->fetchByAssoc($results); if (!empty($row2)) { $record->created_by = $row2['first_name'] . ' ' . $row2['last_name']; } // This gets really expensive... do it outside loop in one shot query $list[$id] = $record; } //while // With the list of KBDocuments on hand, now add the hierarachy information $query = "select kb.id as id, kb.kbdocument_id as doc_id, kb.kbtag_id as tag_id, t.parent_tag_id as parent_id, t.tag_name as tag_name\n from kbdocuments_kbtags kb INNER JOIN kbtags t on kb.kbtag_id = t.id AND kb.kbtag_id in ({$queryIds})"; $result = $bean->db->query($query); while ($row = $bean->db->fetchByAssoc($result)) { $rec = $list[$row['doc_id']]; $rec->tags[] = $row; } return $list; }
function get_child_ids($mod, $id) { $ids = ''; $list = $mod->where("pid={$id}")->select(); if ($list) { foreach ($list as $key => $val) { $ids .= $val['id'] . ','; $ids .= get_child_ids($mod, $val['id']); } } else { return ''; } return trim($ids, ','); }
protected function _before_delete() { $id = intval($_REQUEST['id']); $ids = get_child_ids($this->_mod, $id); $this->_mod->where("id in({$ids})")->delete(); }
/** * deletes a posting and all its replies * * @param int $id : the id of the posting */ function delete_posting_recursive($id) { global $db_settings, $connid; $id = intval($id); $result = mysql_query("SELECT pid, tid FROM " . $db_settings['forum_table'] . " WHERE id = " . $id, $connid) or raise_error('database_error', mysql_error()); $field = mysql_fetch_array($result); $tid = $field['tid']; mysql_free_result($result); if ($field["pid"] == 0) { // it's a thread starting posting - delete whole thread: // clear cache: $ids_result = mysql_query("SELECT id FROM " . $db_settings['forum_table'] . " WHERE tid = " . intval($id), $connid); while ($ids_data = mysql_fetch_array($ids_result)) { @mysql_query("DELETE FROM " . $db_settings['entry_cache_table'] . " WHERE cache_id=" . intval($ids_data['id']), $connid); } mysql_free_result($ids_result); // end clear cache @mysql_query("DELETE FROM " . $db_settings['forum_table'] . " WHERE tid = " . intval($id), $connid); } else { // it's a posting within the thread - delete posting and child postings: $child_ids = get_child_ids($id); @mysql_query("DELETE FROM " . $db_settings['forum_table'] . " WHERE id = " . intval($id), $connid); @mysql_query("DELETE FROM " . $db_settings['entry_cache_table'] . " WHERE cache_id=" . intval($id), $connid); if (isset($child_ids) && is_array($child_ids)) { foreach ($child_ids as $child_id) { @mysql_query("DELETE FROM " . $db_settings['forum_table'] . " WHERE id = " . intval($child_id), $connid); @mysql_query("DELETE FROM " . $db_settings['entry_cache_table'] . " WHERE cache_id=" . intval($child_id), $connid); } } // set last reply time: $result = @mysql_query("SELECT time FROM " . $db_settings['forum_table'] . " WHERE tid = " . intval($tid) . " ORDER BY time DESC LIMIT 1", $connid) or raise_error('database_error', mysql_error()); $field = mysql_fetch_array($result); mysql_free_result($result); @mysql_query("UPDATE " . $db_settings['forum_table'] . " SET time=time, last_reply='" . $field['time'] . "' WHERE tid=" . intval($tid), $connid); } }
$field = mysql_fetch_array($last_reply_result); mysql_free_result($last_reply_result); @mysql_query("UPDATE " . $db_settings['forum_table'] . " SET category=" . $field['category'] . ", time=time, edited=edited, last_reply=last_reply WHERE tid=" . intval($data['tid']), $connid); if (isset($back) && $back == 'thread') { header('Location: index.php?mode=thread&id=' . intval($_POST['move_posting'])); } else { header('Location: index.php?id=' . intval($_POST['move_posting'])); } exit; } else { $smarty->assign('errors', $errors); $action = 'move_posting'; } } else { // make self-contained thread: $child_ids = get_child_ids($_POST['move_posting']); @mysql_query("UPDATE " . $db_settings['forum_table'] . " SET pid=0, tid=" . intval($_POST['move_posting']) . ", time=time, last_reply=last_reply, edited=edited WHERE id=" . intval($_POST['move_posting']), $connid); if (is_array($child_ids)) { foreach ($child_ids as $id) { @mysql_query("UPDATE " . $db_settings['forum_table'] . " SET tid=" . intval($_POST['move_posting']) . ", time=time, last_reply=last_reply, edited=edited WHERE id=" . intval($id), $connid); } } // set last reply of original thread: $last_reply_result = @mysql_query("SELECT time FROM " . $db_settings['forum_table'] . " WHERE tid = " . intval($o_data['tid']) . " ORDER BY time DESC LIMIT 1", $connid); $field = mysql_fetch_array($last_reply_result); mysql_free_result($last_reply_result); @mysql_query("UPDATE " . $db_settings['forum_table'] . " SET time=time, edited=edited, last_reply='" . $field['time'] . "' WHERE tid=" . intval($o_data['tid']), $connid); // set last reply of new thread: $last_reply_result = @mysql_query("SELECT time FROM " . $db_settings['forum_table'] . " WHERE tid = " . intval($_POST['move_posting']) . " ORDER BY time DESC LIMIT 1", $connid); $field = mysql_fetch_array($last_reply_result); mysql_free_result($last_reply_result);