From d7fefa2a6b4722e4ecd6f9cde2d8e8832d750d86 Mon Sep 17 00:00:00 2001 From: Dries Buytaert Date: Sat, 14 Apr 2001 19:27:44 +0000 Subject: - preliminary section code - does _not_ work yet --- includes/structure.inc | 72 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 72 insertions(+) create mode 100644 includes/structure.inc (limited to 'includes/structure.inc') diff --git a/includes/structure.inc b/includes/structure.inc new file mode 100644 index 000000000..ff697c4d3 --- /dev/null +++ b/includes/structure.inc @@ -0,0 +1,72 @@ +$value) db_query("UPDATE category SET $key = '". check_input($value) ."' WHERE cid = '$edit[cid]'"); +} + +function category_del($id) { + db_query("DELETE FROM category WHERE cid = '$id'"); +} + +// ----- topic ----- +function _topic_get($field, $value) { + return db_query("SELECT * FROM topic WHERE $field = '$value'"); +} + +// returns the topic object where $field = $value: +function topic_get_object($field, $value) { + return db_fetch_object(_topic_get($field, $value)); +} + +// returns the topic array where $field = $value: +function topic_get_array($field, $value) { + return db_fetch_array(_topic_get($field, $value)); +} + +// save a topic: +function topic_save($edit) { + if (!$edit[tid]) $edit[tid] = db_insert_id(db_query("INSERT INTO topic (name) VALUES ('". check_input($edit[name])."')")); + foreach ($edit as $key=>$value) db_query("UPDATE topic SET $key = '". check_input($value) ."' WHERE tid = '$edit[tid]'"); +} + +// returns a sorted tree-representation of all topics: +function topic_tree($parent = 0, $name = "", $tree = array()) { + $result = db_query("SELECT * FROM topic WHERE pid = '$parent' ORDER BY name"); + while ($topic = db_fetch_object($result)) { + $tree[$topic->tid] = ($name ? "$name - $topic->name" : $topic->name); + $tree = topic_tree($topic->tid, $tree[$topic->tid], $tree); + } + return $tree; +} + +// renders a form to select one or more topics: +function topic_form_select($type, $topics = array(), $size = 1) { + foreach (topic_tree() as $tid=>$name) { + $options .= "\n"; + } + return "". t("Topic") .":

\n"; +} + +function topic_del($id) { + db_query("DELETE FROM topic WHERE tid = '$id'"); +} + +?> \ No newline at end of file -- cgit v1.2.3