-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathqa-feature-admin.php
100 lines (86 loc) · 2.71 KB
/
qa-feature-admin.php
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
<?php
class qa_feature_admin {
function option_default($option) {
switch($option) {
case 'qa_featured_questions_level':
return QA_USER_LEVEL_MODERATOR;
case 'qa_featured_css':
return '.qa-q-read { background-color: palegreen;}';
default:
return null;
}
}
function init_queries($tableslc) {
require_once QA_INCLUDE_DIR."db/selects.php";
$queries = array();
if(qa_opt('qa_featured_enable_user_reads'))
{
$tablename=qa_db_add_table_prefix('userreads');
$usertablename=qa_db_add_table_prefix('users');
if(!in_array($tablename, $tableslc)) {
$queries[] = "create table if not exists $tablename
(
`userid` int(10) unsigned NOT NULL,
`postid` int(10) unsigned NOT NULL,
PRIMARY KEY (`userid`,`postid`),
KEY `entitytype` (`postid`),
FOREIGN KEY (`userid`) REFERENCES `$usertablename` (`userid`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8";
}
}
return $queries;
}
function allow_template($template)
{
return ($template!='admin');
}
function admin_form(&$qa_content)
{
// Process form input
$ok = null;
if (qa_clicked('qa_featured_questions_save')) {
qa_opt('qa_featured_questions_level',qa_post_text('qa_featured_questions_level'));
qa_opt('qa_featured_enable_user_reads',(bool)qa_post_text('qa_featured_enable_user_reads'));
qa_opt('qa_featured_css',qa_post_text('qa_featured_css'));
$ok = qa_lang('admin/options_saved');
}
$showoptions = array(
QA_USER_LEVEL_EXPERT => "Experts",
QA_USER_LEVEL_EDITOR => "Editors",
QA_USER_LEVEL_MODERATOR => "Moderators",
QA_USER_LEVEL_ADMIN => "Admins",
QA_USER_LEVEL_SUPER => "Super Admins",
);
// Create the form for display
$fields = array();
$fields[] = array(
'label' => 'Min. User Level Required for Featuring',
'tags' => 'name="qa_featured_questions_level"',
'value' => @$showoptions[qa_opt('qa_featured_questions_level')],
'type' => 'select',
'options' => $showoptions,
);
$fields[] = array(
'label' => 'Enable Read Lists for Users',
'tags' => 'name="qa_featured_enable_user_reads"',
'value' => qa_opt('qa_featured_enable_user_reads'),
'type' => 'checkbox',
);
$fields[] = array(
'label' => 'CSS for marking Read Questions in Question Lists',
'tags' => 'name="qa_featured_css"',
'value' => qa_opt('qa_featured_css'),
'type' => 'textarea',
);
return array(
'ok' => ($ok && !isset($error)) ? $ok : null,
'fields' => $fields,
'buttons' => array(
array(
'label' => qa_lang_html('main/save_button'),
'tags' => 'NAME="qa_featured_questions_save"',
),
),
);
}
}