-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathfunction.php
More file actions
223 lines (187 loc) · 6.06 KB
/
function.php
File metadata and controls
223 lines (187 loc) · 6.06 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
<?php
use XoopsModules\Tadtools\Utility;
/********************* 自訂函數 *********************/
/**
* @param string $name
* @return mixed
*/
//取得顏色陣列
function get_color($name = '')
{
global $xoopsConfig;
require_once __DIR__ . "/language/{$xoopsConfig['language']}/modinfo.php";
$default = ('fixed_status' === $name) ? constant('_MI_TADREPAIR_FIXED_STATUS_VAL') : constant('_MI_TADREPAIR_REPAIR_STATUS_VAL');
$def_arr = mk_arr(explode(';', $default));
// die(var_export($def_arr));
foreach ($def_arr as $color => $item) {
$def_color_arr[$item] = $color;
}
// die(var_export($def_color_arr));
$arr = mc2arr($name, '', false, 'return');
// die(var_export($arr));
foreach ($arr as $color => $item) {
$color_arr[$item] = (is_numeric($color) or $color == $item) ? $def_color_arr[$item] : $color;
}
return $color_arr;
}
function SendEmail($uid = '', $title = '', $content = '')
{
global $xoopsDB, $xoopsModuleConfig;
if (empty($uid)) {
return;
}
$msg = '';
if ($xoopsModuleConfig['can_send_mail']) {
$sql = 'SELECT `email` FROM `' . $xoopsDB->prefix('users') . '` WHERE `uid`=?';
$result = Utility::query($sql, 'i', [$uid]) or Utility::web_error($sql, __FILE__, __LINE__);
list($email) = $xoopsDB->fetchRow($result);
$xoopsMailer = getMailer();
$xoopsMailer->multimailer->ContentType = 'text/html';
$xoopsMailer->addHeaders('MIME-Version: 1.0');
$headers = '';
$sendMail = $xoopsMailer->sendMail($email, $title, $content, $headers);
$getErrors = $xoopsMailer->getErrors(true);
$msg .= $sendMail ? sprintf(_MD_TADREPAIR_MAIL_OK, $title, $email) : sprintf(_MD_TADREPAIR_MAIL_FAIL, $title, $email) . $getErrors;
return $msg;
}
}
//取得tad_repair_unit
function get_tad_repair_unit_list()
{
global $xoopsDB;
$sql = 'SELECT `unit_sn`, `unit_title` FROM `' . $xoopsDB->prefix('tad_repair_unit') . '` ORDER BY `unit_sn`';
$result = Utility::query($sql) or Utility::web_error($sql, __FILE__, __LINE__);
while (list($unit_sn, $unit_title) = $xoopsDB->fetchRow($result)) {
$list[$unit_sn] = $unit_title;
}
return $list;
}
//取得各單位的管理員陣列
function unit_admin_arr()
{
global $xoopsDB;
$sql = 'SELECT * FROM `' . $xoopsDB->prefix('tad_repair_unit') . '`';
$result = Utility::query($sql) or Utility::web_error($sql, __FILE__, __LINE__);
$unit_admin_arr = [];
while (false !== ($data = $xoopsDB->fetchArray($result))) {
foreach ($data as $k => $v) {
$$k = $v;
}
$unit_admin_uid = explode(',', $unit_admin);
foreach ($unit_admin_uid as $uid) {
$unit_admin_arr[$unit_sn][] = (int) $uid;
}
}
return $unit_admin_arr;
}
//以流水號取得某筆tad_repair資料
function get_tad_repair($repair_sn = '')
{
global $xoopsDB;
if (empty($repair_sn)) {
return;
}
$sql = 'SELECT * FROM `' . $xoopsDB->prefix('tad_repair') . '` WHERE `repair_sn` = ?';
$result = Utility::query($sql, 'i', [$repair_sn]) or Utility::web_error($sql, __FILE__, __LINE__);
$data = $xoopsDB->fetchArray($result);
return $data;
}
//把模組設定項目轉為選項
function mc2arr($name = '', $def = '', $v_as_k = true, $type = 'option', $other = '', $nl = true)
{
global $xoopsModuleConfig;
if (is_array($xoopsModuleConfig[$name])) {
$arr = $xoopsModuleConfig[$name];
} else {
$arr = explode(';', $xoopsModuleConfig[$name]);
}
$new_arr = mk_arr($arr, $v_as_k);
if ('checkbox' === $type) {
$opt = arr2chk($name, $new_arr, $def, $v_as_k, $other);
} elseif ('radio' === $type) {
$opt = arr2radio($name, $new_arr, $def, $v_as_k, $other);
} elseif ('return' === $type) {
return $new_arr;
} else {
$opt = arr2opt($new_arr, $def, $v_as_k, $other, $nl);
}
return $opt;
}
function mk_arr($arr = [], $v_as_k = false)
{
if (is_array($arr)) {
foreach ($arr as $item) {
if (empty($item)) {
continue;
}
if (preg_match('/=/', $item)) {
list($k, $v) = explode('=', $item);
if ($v_as_k) {
$k = $v;
} elseif ('' == $v) {
$v = $k;
}
$new_arr[$k] = $v;
} else {
$new_arr[$item] = $item;
}
}
} else {
$new_arr = [];
}
return $new_arr;
}
//把陣列轉為選項
function arr2opt($arr, $def = '', $v_as_k = false, $other = '')
{
if (is_array($def)) {
$def_arr = $def;
} else {
$def_arr = [$def];
}
$main = '';
foreach ($arr as $k => $v) {
if ($v_as_k) {
$k = $v;
}
$selected = (in_array($k, $def_arr)) ? 'selected' : '';
$main .= "<option value='$k' $selected $other>$v</option>";
}
return $main;
}
//把陣列轉為選項
function arr2chk($name, $arr, $def = '', $v_as_k = false, $other = '')
{
if (is_array($def)) {
$def_arr = $def;
} else {
$def_arr = [$def];
}
$i = 1;
foreach ($arr as $k => $v) {
if ($v_as_k) {
$k = $v;
}
$checked = (in_array($k, $def_arr)) ? 'checked' : '';
$main .= "<span style='white-space:nowrap;'><input type='checkbox' name='{$name}[]' value='$k' id='{$name}_{$i}' $checked $other>
<label for='{$name}_{$i}'>$v</label></span> ";
$i++;
}
return $main;
}
//把陣列轉為單選項
function arr2radio($name, $arr, $def = '', $v_as_k = false, $other = '')
{
$i = 1;
foreach ($arr as $k => $v) {
if ($v_as_k) {
$k = $v;
}
$checked = ($def == $k) ? 'checked' : '';
$main .= "<span style='white-space:nowrap;'><input type='radio' name='{$name}' value='$k' id='{$name}_{$i}' $checked $other>
<label for='{$name}_{$i}'>$v</label></span> ";
$i++;
}
return $main;
}
/********************* 預設函數 *********************/