1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
|
<?php
$module = array("admin" => "structure_admin");
function content_types($name, $module) {
global $types;
if ($module[type]) $types[$name] = $name;
}
function category_form($edit = array()) {
global $types;
$threshold_post = array(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 20, 25, 30, 35, 40, 45, 50, 60, 70, 80, 90, 100);
$threshold_dump = array(-1, -2, -3, -4, -5, -6, -7, -8, -9, -10, -11, -12, -13, -14, -15, -20, -25, -30);
$threshold_expire = array(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 20, 25, 30, 35, 40, 45, 50, 60, 70, 80, 90, 100);
module_iterate("content_types");
$output .= "<FORM ACTION=\"admin.php?mod=structure&type=category\" METHOD=\"post\">\n";
$output .= "<B>Name:</B><BR>\n";
$output .= "<INPUT NAME=\"edit[name]\" SIZE=\"55\" VALUE=\"". check_textfield($edit[name]) ."\"><BR>\n";
$output .= "<SMALL><I>A unique name for this category like 'announcement', 'article', 'column', 'review', etc.</I></SMALL><P>\n";
$output .= "<B>Content type:</B><BR>\n";
foreach ($types as $key=>$value) $options1 .= "<OPTION VALUE=\"$key\"". ($edit[type] == $value ? " SELECTED" : "") .">". check_select($value) ."</OPTION>";
$output .= "<SELECT NAME=\"edit[type]\">$options1</SELECT><BR>\n";
$output .= "<SMALL><I>The content type to bind or associate this category with.</I></SMALL><P>\n";
$output .= "<B>Comment:</B><BR>\n";
foreach (node_comment_status() as $key=>$value) $options2 .= "<OPTION VALUE=\"$key\"". ($edit[comment] == $key ? " SELECTED" : "") .">". check_select($value) ."</OPTION>";
$output .= "<SELECT NAME=\"edit[comment]\">$options2</SELECT><BR>\n";
$output .= "<SMALL><I>By default, allow or dissallow users to post comments in this category.</I></SMALL><P>\n";
$output .= "<B>Promote:</B><BR>\n";
foreach (node_promote_status() as $key=>$value) $options3 .= "<OPTION VALUE=\"$key\"". ($edit[promote] == $key ? " SELECTED" : "") .">". check_select($value) ."</OPTION>";
$output .= "<SELECT NAME=\"edit[promote]\">$options3</SELECT><BR>\n";
$output .= "<SMALL><I>By default, promote new submissions in this category to the front page.</I></SMALL><P>\n";
$output .= "<B>Submission:</B><BR>\n";
foreach (node_submission_status() as $key=>$value) $options4 .= "<OPTION VALUE=\"$key\"". ($edit[submission] == $key ? " SELECTED" : "") .">". check_select($value) ."</OPTION>";
$output .= "<SELECT NAME=\"edit[submission]\">$options4</SELECT><BR>\n";
foreach ($threshold_post as $value) $options5 .= "<OPTION VALUE=\"$value\"". ($edit[post] == $value ? " SELECTED" : "") .">". format_plural($value, "point", "points") ."</OPTION>";
$output .= "<SELECT NAME=\"edit[post]\">$options5</SELECT>\n";
foreach ($threshold_dump as $value) $options6 .= "<OPTION VALUE=\"$value\"". ($edit[dump] == $value ? " SELECTED" : "") .">". format_plural($value, "point", "points") ."</OPTION>";
$output .= "<SELECT NAME=\"edit[dump]\">$options6</SELECT>\n";
foreach ($threshold_expire as $value) $options7 .= "<OPTION VALUE=\"$value\"". ($edit[expire] == $value ? " SELECTED" : "") .">". format_plural($value, "vote", "votes") ."</OPTION>";
$output .= "<SELECT NAME=\"edit[expire]\">$options7</SELECT><BR>\n";
$output .= "<SMALL><I>What to do with new submissions in this category?<BR>Specify the post, dump and expiration threshold for moderation purpose.</I></SMALL><P>\n";
if ($edit[cid]) {
$output .= "<INPUT TYPE=\"hidden\" NAME=\"edit[cid]\" VALUE=\"$edit[cid]\">\n";
$output .= "<INPUT TYPE=\"submit\" NAME=\"op\" VALUE=\"Save category\">\n";
$output .= "<INPUT TYPE=\"submit\" NAME=\"op\" VALUE=\"Delete category\">\n";
}
else {
$output .= "<INPUT TYPE=\"submit\" NAME=\"op\" VALUE=\"Save category\">\n";
}
$output .= "</FORM>\n";
return $output;
}
function category_overview() {
$result = db_query("SELECT * FROM category ORDER BY name");
$output .= "<TABLE BORDER=\"1\" CELLPADDING=\"2\" CELLSPACING=\"2\">\n";
$output .= " <TR><TH>name</TH><TH>type</TH><TH>comment</TH><TH>promote</TH><TH>submissions</TH><TH>operations</TH></TR>\n";
while ($category = db_fetch_object($result)) {
$output .= " <TR><TD>". check_output($category->name) ."</TD><TD>". check_output($category->type) ."</TD><TD>". node_comment_status($category->comment) ."</TD><TD>". node_promote_status($category->promote) ."</TD><TD>". node_submission_status($category->submission) ."". ($category->submission ? "<BR><SMALL>post: $category->post, dump: $category->dump, expire: $category->expire</SMALL>" : "") ."</TD><TD><A HREF=\"admin.php?mod=structure&type=category&op=edit&id=$category->cid\">edit category</A></TD></TR>\n";
}
$output .= "</TABLE>\n";
return $output;
}
// ---- topic ----
function topic_form($edit = array()) {
$output .= "<FORM ACTION=\"admin.php?mod=structure&type=topic\" METHOD=\"post\">\n";
$output .= "<B>Name:</B><BR>\n";
$output .= "<INPUT NAME=\"edit[name]\" SIZE=\"55\" VALUE=\"". check_textfield($edit[name]) ."\"><BR>\n";
$output .= "<SMALL><I>A unique name for this topic like 'science', 'internet', 'culture', etc.</I></SMALL><P>\n";
$output .= "<B>Parent:</B><BR>\n";
foreach (topic_tree() as $key=>$value) $options .= "<OPTION VALUE=\"$key\"". ($edit[pid] == $key ? " SELECTED" : "") .">". check_select($value) ."</OPTION>";
$output .= "<SELECT NAME=\"edit[pid]\"><OPTION VALUE=\"0\"> </OPTION>$options</SELECT><BR>\n";
$output .= "<SMALL><I>The parent topic this topic belongs in.</I></SMALL><P>\n";
if ($edit[tid]) {
$output .= "<INPUT TYPE=\"hidden\" NAME=\"edit[tid]\" VALUE=\"$edit[tid]\">\n";
$output .= "<INPUT TYPE=\"submit\" NAME=\"op\" VALUE=\"Save topic\">\n";
$output .= "<INPUT TYPE=\"submit\" NAME=\"op\" VALUE=\"Delete topic\">\n";
}
else {
$output .= "<INPUT TYPE=\"submit\" NAME=\"op\" VALUE=\"Save topic\">\n";
}
return $output;
}
function topic_overview() {
$tree = topic_tree();
$output .= "<TABLE BORDER=\"1\" CELLPADDING=\"2\" CELLSPACING=\"2\">\n";
$output .= " <TR><TH>name</TH><TH>operations</TH></TR>\n";
foreach ($tree as $id=>$name) {
$output .= " <TR><TD>". check_output($name) ."</TD><TD><A HREF=\"admin.php?mod=structure&type=topic&op=edit&id=$id\">edit topic</A></TD></TR>\n";
}
$output .= "</TABLE>\n";
return $output;
}
// ----- structure -----
function structure_overview() {
$output .= "<H3>Categories</H3>\n";
$output .= category_overview();
$output .= "<H3>Topics</H3>\n";
$output .= topic_overview();
return $output;
}
function structure_admin() {
global $id, $op, $type, $edit;
print "<SMALL><A HREF=\"admin.php?mod=structure&type=category&op=add\">add new category</A> | <A HREF=\"admin.php?mod=structure&type=topic&op=add\">add new topic</A> | <A HREF=\"admin.php?mod=structure\">overview</A></SMALL><HR>\n";
switch ($type) {
case "category":
switch ($op) {
case "add":
print category_form();
break;
case "edit":
print category_form(category_get_array("cid", $id));
break;
case "view":
print category_view($id);
break;
case "Delete category":
print status(category_del($edit[cid]));
print structure_overview();
break;
case "Save category":
print status(category_save($edit));
print structure_overview();
break;
default:
print structure_overview();
}
break;
case "topic":
switch ($op) {
case "add":
print topic_form();
break;
case "edit":
print topic_form(topic_get_array("tid", $id));
break;
case "view":
print topic_view($id);
break;
case "Delete topic":
print status(topic_del($edit[tid]));
print structure_overview();
break;
case "Save topic":
print status(topic_save($edit));
print structure_overview();
break;
default:
print structure_overview();
}
break;
default:
print structure_overview();
}
}
?>
|