/
qa-sig-admin.php
174 lines (144 loc) · 4.51 KB
/
qa-sig-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
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
<?php
class qa_signatures_admin {
function option_default($option) {
switch($option) {
case 'signatures_length':
return 1000;
case 'signatures_header':
return '<div class="signature">';
case 'signatures_footer':
return '</div>';
case 'signatures_format':
return 0;
case 'signature_allow':
return QA_PERMIT_USER;
case 'signature_edit_allow':
return QA_PERMIT_ADMIN;
default:
return null;
}
}
function allow_template($template)
{
return ($template!='admin');
}
function admin_form(&$qa_content)
{
// Process form input
$ok = null;
if (qa_clicked('signatures_save')) {
if(qa_post_text('signatures_length') > 1000) {
$error = 'Max possible signature length is 1000 characters';
}
else {
if(!qa_opt('signatures_enable') && qa_post_text('signatures_enable')) {
qa_db_query_sub(
'CREATE TABLE IF NOT EXISTS ^usersignatures ('.
'userid INT(11) NOT NULL,'.
'signature VARCHAR (1000) DEFAULT \'\','.
'format VARCHAR (20) DEFAULT \'\','.
'id INT(11) NOT NULL AUTO_INCREMENT,'.
'UNIQUE (userid),'.
'PRIMARY KEY (id)'.
') ENGINE=MyISAM DEFAULT CHARSET=utf8'
);
}
qa_opt('signatures_enable',(bool)qa_post_text('signatures_enable'));
qa_opt('signatures_q_enable',(bool)qa_post_text('signatures_q_enable'));
qa_opt('signatures_a_enable',(bool)qa_post_text('signatures_a_enable'));
qa_opt('signatures_c_enable',(bool)qa_post_text('signatures_c_enable'));
qa_opt('signatures_profile_enable',(bool)qa_post_text('signatures_profile_enable'));
qa_opt('signatures_length',(int)qa_post_text('signatures_length'));
qa_opt('signatures_format',(int)qa_post_text('signatures_format'));
qa_opt('signatures_html',(bool)qa_post_text('signatures_html'));
qa_opt('signatures_header',qa_post_text('signatures_header'));
qa_opt('signatures_footer',qa_post_text('signatures_footer'));
$ok = 'Settings Saved.';
}
}
// Create the form for display
$formats = qa_list_modules('editor');
foreach ($formats as $key => $format)
if(!strlen($format))
$formats[$key] = qa_lang_html('admin/basic_editor');
$fields = array();
$fields[] = array(
'label' => 'Enable signatures',
'tags' => 'NAME="signatures_enable"',
'value' => qa_opt('signatures_enable'),
'type' => 'checkbox',
);
$fields[] = array(
'label' => 'in questions',
'tags' => 'NAME="signatures_q_enable"',
'value' => qa_opt('signatures_q_enable'),
'type' => 'checkbox',
);
$fields[] = array(
'label' => 'in answers',
'tags' => 'NAME="signatures_a_enable"',
'value' => qa_opt('signatures_a_enable'),
'type' => 'checkbox',
);
$fields[] = array(
'label' => 'in comments',
'tags' => 'NAME="signatures_c_enable"',
'value' => qa_opt('signatures_c_enable'),
'type' => 'checkbox',
);
$fields[] = array(
'type' => 'blank',
);
$fields[] = array(
'label' => 'Show signatures in public profiles',
'tags' => 'NAME="signatures_profile_enable"',
'value' => qa_opt('signatures_profile_enable'),
'type' => 'checkbox',
);
$fields[] = array(
'label' => 'Signature length (chars)',
'type' => 'number',
'value' => (int)qa_opt('signatures_length'),
'tags' => 'NAME="signatures_length"',
'note' => 'max possible is 1000 characters',
);
$fields[] = array(
'label' => 'Signature format',
'tags' => 'NAME="signatures_format"',
'type' => 'select',
'options' => $formats,
'value' => @$formats[qa_opt('signatures_format')],
);
$fields[] = array(
'label' => 'Allow HTML',
'tags' => 'NAME="signatures_html"',
'value' => qa_opt('signatures_html'),
'type' => 'checkbox',
);
$fields[] = array(
'type' => 'blank',
);
$fields[] = array(
'label' => 'Signature header',
'type' => 'text',
'value' => qa_html(qa_opt('signatures_header')),
'tags' => 'NAME="signatures_header"',
);
$fields[] = array(
'label' => 'Signature footer',
'type' => 'text',
'value' => qa_html(qa_opt('signatures_footer')),
'tags' => 'NAME="signatures_footer"',
);
return array(
'ok' => ($ok && !isset($error)) ? $ok : null,
'fields' => $fields,
'buttons' => array(
array(
'label' => 'Save',
'tags' => 'NAME="signatures_save"',
)
),
);
}
}