-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathajax.php
More file actions
233 lines (201 loc) · 7.87 KB
/
Copy pathajax.php
File metadata and controls
233 lines (201 loc) · 7.87 KB
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
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
<?php
use Xmf\Request;
use XoopsModules\Tadtools\TadDataCenter;
use XoopsModules\Tadtools\TadUpFiles;
use XoopsModules\Tadtools\Utility;
use XoopsModules\Tad_blocks\Tools;
/*-----------引入檔案區--------------*/
require_once __DIR__ . '/header.php';
if (!$tad_blocks_adm) {
redirect_header('index.php', 3, _MD_TAD_BLOCKS_NO_PERMISSION);
}
header('HTTP/1.1 200 OK');
$xoopsLogger->activated = false;
/*-----------執行動作判斷區----------*/
$op = Request::getString('op');
$bid = !empty($_REQUEST['pk']) ? Request::getInt('pk') : Request::getInt('bid');
$module_id = Request::getString('module_id');
$col = Request::getString('col');
$val = Request::getString('val');
$weight = Request::getInt('weight');
$side = Request::getInt('side');
$title = !empty($_REQUEST['value']) ? Request::getString('value') : Request::getString('title');
$tag = Request::getString('tag');
$link_url = Request::getString('link_url');
$col_name = Request::getString('col_name');
$col_sn = Request::getInt('col_sn');
$data_sort = Request::getInt('data_sort');
switch ($op) {
case "del_data":
del_data($col_name, $col_sn, $data_sort);
exit;
case "update_newblock":
Tools::update_newblock($bid, $side, $weight);
exit;
case "change_block_module_link":
Tools::change_block_module_link($bid, $module_id);
exit;
case "change_newblock":
Tools::change_newblock($bid, $col, $val);
header("location: {$_SERVER['HTTP_REFERER']}");
exit;
case "visible":
Tools::change_newblock($bid, 'visible', 1);
exit;
case "invisible":
Tools::change_newblock($bid, 'visible', 0);
exit;
case "update_title":
update_title($bid, $title, $tag, $link_url);
exit;
case "setting_form":
$form = setting_form($bid);
die($form);
case "echo":
die("<img src='$val'>");
case "save_sort":
save_sort();
exit;
}
/*-----------秀出結果區--------------*/
/*-----------功能函數區--------------*/
function setting_form($bid)
{
global $xoopsDB, $tags;
$show_file = ['pic', 'img', 'icon'];
$show_link = ['link'];
$show_help = ['pic', 'img'];
$sql = 'SELECT * FROM `' . $xoopsDB->prefix('newblocks') . '` WHERE `bid` = ?';
$result = Utility::query($sql, 'i', [$bid]) or die($sql);
$block = $xoopsDB->fetchArray($result);
$save = _TAD_SAVE;
$title = $block['title'];
$display_link = $display_file = $display_help = 'style="display:none;"';
$jquery = Utility::get_jquery(false, 'return');
foreach ($tags as $tag) {
$start = strpos($block['title'], "[$tag]");
$selected_tag = "selected_{$tag}";
if ($start !== false) {
$title = substr($block['title'], 0, $start);
$old_tag = "[$tag]";
$$selected_tag = 'selected';
$display_file = in_array($tag, $show_file) ? '' : $display_file;
$display_link = in_array($tag, $show_link) ? '' : $display_link;
$display_help = in_array($tag, $show_help) ? '' : $display_help;
} else {
$$selected_tag = '';
}
}
$url = XOOPS_URL;
$choose = _MD_TAD_BLOCKS_CHOOSE;
$hide = _MD_TAD_BLOCKS_TITLE_HIDE;
$pic = _MD_TAD_BLOCKS_TITLE_PIC;
$img = _MD_TAD_BLOCKS_TITLE_IMG;
$icon = _MD_TAD_BLOCKS_TITLE_ICON;
$link = _MD_TAD_BLOCKS_TITLE_LINK;
$upload = _MD_TAD_BLOCKS_UPLOAD_PIC;
$help = _MD_TAD_BLOCKS_LOGO_HELP;
$form = <<<"EOD"
$jquery
<link rel="stylesheet" type="text/css" media="all" title="Style sheet" href="$url/modules/tad_blocks/css/module.css">
<h4>{$block['title']}</h4>
<form action="ajax.php" method="post" enctype="multipart/form-data">
<input type="text" name="value" value="$title">
<select name="tag" id="tag">
<option value="" $selected>$choose</option>
<option value="hide" $selected_hide>[hide]$hide</option>
<option value="pic" $selected_pic>[pic]$pic</option>
<option value="img" $selected_img>[img]$img</option>
<option value="icon" $selected_icon>[icon]$icon</option>
<option value="link" $selected_link>[link]$link</option>
</select>
<input type="text" name="link_url" id="link" placeholder="http://" $display_link>
<input type="file" name="tag2" id="file" placeholder="$upload" $display_file>
<input type="hidden" name="bid" value="$bid">
<button type="submit" name="op" value="update_title">$save</button>
<div id="help" $display_help>$help</div>
</form>
<script>
$(document).ready(function(){
$('#tag').on('change', function(){
var tag=$('#tag').val();
if(tag=='hide' || tag==''){
$('#link').hide();
$('#file').hide();
$('#help').hide();
}else if(tag=='icon'){
$('#link').hide();
$('#file').show();
$('#help').hide();
}else if(tag=='pic' || tag=='img'){
$('#link').hide();
$('#file').show();
$('#help').show();
}else if(tag=='link'){
$('#link').show();
$('#file').hide();
$('#help').hide();
}
});
});
</script>
EOD;
return $form;
}
function update_title($bid, $title = '', $need_tag = '', $link_url = '')
{
$file_up = ['pic', 'img', 'icon'];
$have_link = ['link'];
$new_tag_url = '';
// 圖片類的
if (in_array($need_tag, $file_up)) {
// 自行上傳的
if ($_FILES['tag2']['name']) {
$TadUpFiles = new TadUpFiles("tad_blocks");
$TadUpFiles->set_col($need_tag, $bid);
$files_sn = $TadUpFiles->upload_one_file($_FILES['tag2']['name'], $_FILES['tag2']['tmp_name'], $_FILES['tag2']['type'], $_FILES['tag2']['size'], null, null, null, null, true);
$new_tag_url = $TadUpFiles->get_pic_file('images', 'url', $files_sn);
} else {
// 沒上傳,自動產生的
$TadDataCenter = new TadDataCenter('tad_blocks');
$TadDataCenter->set_col('block_logo', 0);
$logo_setting = $TadDataCenter->getData();
if ($logo_setting) {
foreach ($logo_setting as $key => $value) {
$$key = $value[0];
}
}
$new_tag_url = Utility::mkTitlePic('/uploads/bid', $bid, $title, $size, $border_size, $color, $border_color, $font_file_sn, $shadow_color, $shadow_x, $shadow_y, $shadow_size);
}
} elseif (in_array($need_tag, $have_link)) {
// 連結類
$new_tag_url = $link_url;
}
$new_title = $need_tag ? "{$title}[$need_tag]{$new_tag_url}" : $title;
Tools::change_newblock($bid, 'title', $new_title);
die($title);
}
function save_sort()
{
global $xoopsDB;
$bid = (int) $_POST['bid'];
foreach ($_POST['col'] as $col) {
$sql = 'UPDATE `' . $xoopsDB->prefix('tad_blocks_data_center') . '` SET `data_sort`= `data_sort` + 10000 WHERE `col_name`=? AND `col_sn`=? AND `data_name`=?';
Utility::query($sql, 'sis', ['bid', $bid, $col]) or die(_TAD_SORT_FAIL . ' (' . date('Y-m-d H:i:s') . ')' . $sql);
}
$sort = 1;
foreach ($_POST['form'] as $item) {
$old_sort = (int) str_replace('data', '', $item) + 10000;
foreach ($_POST['col'] as $col) {
$sql = 'UPDATE `' . $xoopsDB->prefix('tad_blocks_data_center') . '` SET `data_sort`=? WHERE `col_name`=? AND `col_sn`=? AND `data_name`=? AND `data_sort`=?';
Utility::query($sql, 'sisii', [$sort, 'bid', $bid, $col, $old_sort]) or die(_TAD_SORT_FAIL . ' (' . date('Y-m-d H:i:s') . ')' . $sql);
}
$sort++;
}
die(_TAD_SORTED . "(" . date("Y-m-d H:i:s") . ")");
}
function del_data($col_name, $col_sn, $data_sort)
{
$TadDataCenter = new TadDataCenter('tad_blocks');
$TadDataCenter->delData('', $data_sort, $col_name, $col_sn);
}