update 2008/10/16
@@ -1,1099 +1,1108 @@ | ||
1 | -<?php | |
2 | - | |
3 | -/** | |
4 | - * class ListManager | |
5 | - */ | |
6 | - | |
7 | -class ListManager{ | |
8 | - | |
9 | - var $db; | |
10 | - var $list_id; | |
11 | - var $type; | |
12 | - var $template; | |
13 | - var $list_th; | |
14 | - var $thumb_dir; | |
15 | - var $thumb_size; | |
16 | - var $thumb_active_size; | |
17 | - var $sort_target; | |
18 | - var $sort_method; | |
19 | - var $page; | |
20 | - var $limit; | |
21 | - var $refine; | |
22 | - var $refine_flg; | |
23 | - var $tsearch_flg; | |
24 | - var $kws_flg; | |
25 | - var $uid; | |
26 | - var $item; | |
27 | - var $error; | |
28 | - | |
29 | - /** | |
30 | - * Class Constructor | |
31 | - */ | |
32 | - function ListManager(){ | |
33 | - $this->db =& Database::getInstance(); | |
34 | - } | |
35 | - | |
36 | - function setUser($time){ | |
37 | - $this->uid = $time; | |
38 | - } | |
39 | - | |
40 | - function setListId($list_id){ | |
41 | - | |
42 | - # get template | |
43 | - $sql = "SELECT * FROM ".$this->db->prefix('newdb_list')." WHERE list_id='".$list_id."'"; | |
44 | - $rs = $this->db->query($sql); | |
45 | - | |
46 | - if($this->db->getRowsNum($rs) == 0){ | |
47 | - $this->error = 'This List ID does not exist. (listmanager.php line '.__LINE__.')'; | |
48 | - $this->list_id = -1; | |
49 | - return false; | |
50 | - | |
51 | - }else{ | |
52 | - $row = $this->db->fetchArray($rs); | |
53 | - $this->list_id = $list_id; | |
54 | - $this->type = $row['type']; | |
55 | - $this->template = $row['template']; | |
56 | - $this->thumb_dir = $row['thumb_dir']; | |
57 | - $this->thumb_size = explode(';', $row['thumb_size']); | |
58 | - $this->page = 1; | |
59 | - $this->item = 0; | |
60 | - $this->limit = 20; | |
61 | - $this->refine = array(); | |
62 | - $this->refine_flg = 0; | |
63 | - $this->kws_flg = 0; | |
64 | - $this->tsearch_flg = 0; | |
65 | - $this->list_th = $this->setListTH($row['list_th']); | |
66 | - | |
67 | - if($this->type == 2){ | |
68 | - $this->__setSize(); | |
69 | - } | |
70 | - } | |
71 | - return true; | |
72 | - } | |
73 | - | |
74 | - function setListTH($th){ | |
75 | - | |
76 | - $sql = "SELECT * FROM ".$this->db->prefix('newdb_component_master'); | |
77 | - $rs = $this->db->query($sql); | |
78 | - while($row = $this->db->fetchArray($rs)){ | |
79 | - $template = '{'.$row['name'].'}'; | |
80 | - if(strstr($th, $template)){ | |
81 | - $th = str_replace($template, $row['tag'], $th); | |
82 | - } | |
83 | - } | |
84 | - return $th; | |
85 | - } | |
86 | - | |
87 | - | |
88 | - ########################### | |
89 | - ## thumbnail things | |
90 | - ########################### | |
91 | - | |
92 | - /** | |
93 | - * __setSize | |
94 | - * | |
95 | - * setting thumbnail with default size-set | |
96 | - * @access private | |
97 | - */ | |
98 | - function __setSize(){ | |
99 | - | |
100 | - $size = array(); | |
101 | - $size = explode(',', $this->thumb_size[0]); | |
102 | - | |
103 | - $this->thumb_active_size[0] = $size[0]; | |
104 | - $this->thumb_active_size[1] = $size[1]; | |
105 | - $this->thumb_active_size[2] = $size[2]; | |
106 | - $this->thumb_active_size[3] = $size[3]; | |
107 | - | |
108 | - return true; | |
109 | - } | |
110 | - | |
111 | - | |
112 | - /** | |
113 | - * changeSize | |
114 | - * | |
115 | - * change thumbnail size | |
116 | - * @access public | |
117 | - * @param $name (target thumbnail size name) | |
118 | - */ | |
119 | - function changeSize($name){ | |
120 | - | |
121 | - $myts =& MyTextSanitizer::getInstance(); | |
122 | - $name = $myts->stripSlashesGPC($name); | |
123 | - | |
124 | - $size = array(); | |
125 | - for($i=0; $i<count($this->thumb_size); $i++){ | |
126 | - $size[] = explode(',', $this->thumb_size[$i]); | |
127 | - } | |
128 | - | |
129 | - for($i=0; $i<count($this->thumb_size); $i++){ | |
130 | - if($size[$i][0] == $name){ | |
131 | - $this->thumb_active_size[0] = $size[$i][0]; | |
132 | - $this->thumb_active_size[1] = $size[$i][1]; | |
133 | - $this->thumb_active_size[2] = $size[$i][2]; | |
134 | - $this->thumb_active_size[3] = $size[$i][3]; | |
135 | - } | |
136 | - } | |
137 | - | |
138 | - return true; | |
139 | - } | |
140 | - | |
141 | - | |
142 | - /** | |
143 | - * __getThumbLink | |
144 | - * | |
145 | - * making thumbnail size selection box | |
146 | - * @access private | |
147 | - * @return $thumb_link (thumbnail size selection box) | |
148 | - */ | |
149 | - function __getThumbLink(){ | |
150 | - | |
151 | - $thumb_link = " <select name='size'>"; | |
152 | - for($i=0; $i<count($this->thumb_size); $i++){ | |
153 | - | |
154 | - $ts = explode(',', $this->thumb_size[$i]); | |
155 | - $thumb_link.= "<option value=".$ts[0]; | |
156 | - if($ts[0] == $this->thumb_active_size[0]){ | |
157 | - $thumb_link.= " selected"; | |
158 | - } | |
159 | - $thumb_link.= ">".$ts[0]."</option> \n"; | |
160 | - } | |
161 | - | |
162 | - $thumb_link.= "</select>"; | |
163 | - return $thumb_link; | |
164 | - } | |
165 | - | |
166 | - | |
167 | - ########################### | |
168 | - ## paging things | |
169 | - ########################### | |
170 | - | |
171 | - /** | |
172 | - * setPage | |
173 | - * | |
174 | - * setting page number and limit | |
175 | - * @access public | |
176 | - * @param $p (page number) | |
177 | - * @param $l (showing limit) | |
178 | - */ | |
179 | - function setPage($item, $l){ | |
180 | - | |
181 | - if($l < 0 || !$l) $l = 20; | |
182 | - $this->limit = intval($l); | |
183 | - | |
184 | - if($item <= 0 || !$item){ | |
185 | - $p = 1; | |
186 | - $this->item = 0; | |
187 | - }else{ | |
188 | - $p = $item / $this->limit + 1; | |
189 | - $this->item = $item; | |
190 | - } | |
191 | - $this->page = intval($p); | |
192 | - } | |
193 | - | |
194 | - | |
195 | - /** | |
196 | - * getPagelink | |
197 | - * | |
198 | - * making page selection link | |
199 | - * @access public | |
200 | - * @return $pagelink | |
201 | - */ | |
202 | - function getPagelink(){ | |
203 | - | |
204 | - $n = count($this->getLabels(1)); | |
205 | - $pagenum = ceil($n / $this->limit); | |
206 | - $pagenow = $this->page.'/'.$pagenum; | |
207 | - $f = ($pagenow-1) * $this->limit + 1; | |
208 | - $t = $pagenow * $this->limit; | |
209 | - if($t > $n) $t = $n; | |
210 | - $pagelink = _ND_CLASS_ALL.$n._ND_CLASS_HIT." ( ".$f." - ".$t._ND_CLASS_HIT_NOW." ) "; | |
211 | - | |
212 | - $href = "id=".$this->list_id; | |
213 | - $href.= "&n=".$this->limit; | |
214 | - $href.= "&sort=".$this->sort_target; | |
215 | - $href.= "&sort_method=".$this->sort_method; | |
216 | - if($this->refine_flg){ | |
217 | - $href.= "&refine=usedb"; | |
218 | - $href.= "&user=".$this->uid; | |
219 | - } | |
220 | - if($this->tsearch_flg){ | |
221 | - $href.= "&tsearch=usedb"; | |
222 | - $href.= "&user=".$this->uid; | |
223 | - } | |
224 | - if($this->type == 2) $href.= "&size=".$this->thumb_active_size[0]; | |
225 | - | |
226 | - require XOOPS_ROOT_PATH.'/class/pagenav.php'; | |
227 | - $xp = new XoopsPageNav($n, $this->limit, $f, 'item', $href); | |
228 | - $pagelink.= $xp->renderNav(); | |
229 | - | |
230 | - return $pagelink; | |
231 | - } | |
232 | - | |
233 | - | |
234 | - ########################### | |
235 | - ## sort things | |
236 | - ########################### | |
237 | - | |
238 | - /** | |
239 | - * setSort | |
240 | - * | |
241 | - * setting sort target id and method | |
242 | - * @access public | |
243 | - * @param $sort_target (sort item's ID) | |
244 | - * @param $sort_method (asc or desc) | |
245 | - */ | |
246 | - function setSort($sort_target, $sort_method){ | |
247 | - $this->sort_target = intval($sort_target); | |
248 | - if($sort_method != 'desc' && $sort_method != 'asc'){ | |
249 | - $this->sort_method = 'desc'; | |
250 | - }else{ | |
251 | - $this->sort_method = $sort_method; | |
252 | - } | |
253 | - } | |
254 | - | |
255 | - | |
256 | - /** | |
257 | - * getSortbox | |
258 | - * | |
259 | - * making sort box for list and thumbnail page | |
260 | - * @access public | |
261 | - * @return $sortbox (sort box) | |
262 | - */ | |
263 | - function getSortbox(){ | |
264 | - | |
265 | - $sortbox = "<form method='GET' action='list.php' style='margin:0'>\n"; | |
266 | - $sortbox.= "<select name='sort'>\n"; | |
267 | - | |
268 | - # sort target | |
269 | - $sql = "SELECT * FROM ".$this->db->prefix('newdb_component_master'); | |
270 | - $sql.= " WHERE onoff='0' ORDER BY sort"; | |
271 | - $rs = $this->db->query($sql); | |
272 | - while($row = $this->db->fetchArray($rs)){ | |
273 | - $sortbox.= "<option value='".$row['comp_id']."' "; | |
274 | - if($row['comp_id'] == $this->sort_target){ | |
275 | - $sortbox.= "selected"; | |
276 | - } | |
277 | - $sortbox.= ">".$row['tag']."</option>\n"; | |
278 | - } | |
279 | - $sortbox.= "</select>\n"; | |
280 | - | |
281 | - # up/down | |
282 | - $sortbox.= "<select name='sort_method'>\n"; | |
283 | - $sortbox.= "<option value='asc' "; | |
284 | - if($this->sort_method == 'asc'){ | |
285 | - $sortbox.= "selected"; | |
286 | - } | |
287 | - $sortbox.= ">"._ND_UP."</option>\n"; | |
288 | - | |
289 | - $sortbox.= "<option value='desc' "; | |
290 | - if($this->sort_method == 'desc'){ | |
291 | - $sortbox.= "selected"; | |
292 | - } | |
293 | - $sortbox.= ">"._ND_DOWN."</option>\n"; | |
294 | - $sortbox.= "</select>\n"; | |
295 | - | |
296 | - # show limit | |
297 | - $n = array(20,40,60,80,100); | |
298 | - $sortbox.="<select name='n'>"; | |
299 | - for($i=0; $i<count($n); $i++){ | |
300 | - $sortbox.="<option vaule='".$n[$i]."'"; | |
301 | - if($this->limit == $n[$i]) $sortbox.= "selected"; | |
302 | - $sortbox.=">".$n[$i]."</option>"; | |
303 | - } | |
304 | - $sortbox.="</select>"; | |
305 | - | |
306 | - # thumb size | |
307 | - if($this->type == 2){ | |
308 | - $sortbox.= $this->__getThumbLink(); | |
309 | - } | |
310 | - | |
311 | - $sortbox.= "<input type='hidden' name='id' value='".$this->list_id."'>\n"; | |
312 | - $sortbox.= "<input type='hidden' name='item' value='0'>\n"; | |
313 | - if($this->refine_flg){ | |
314 | - $sortbox.= "<input type='hidden' name='refine' value='usedb'>\n"; | |
315 | - $sortbox.= "<input type='hidden' name='user' value='".$this->uid."'>\n"; | |
316 | - } | |
317 | - if($this->kws_flg){ | |
318 | - $sortbox.= "<input type='hidden' name='kws' value='paging'>\n"; | |
319 | - } | |
320 | - if($this->tsearch_flg){ | |
321 | - $sortbox.= "<input type='hidden' name='tsearch' value='usedb'>\n"; | |
322 | - $sortbox.= "<input type='hidden' name='user' value='".$this->uid."'>\n"; | |
323 | - } | |
324 | - $sortbox.= " <input type='submit' value='Sort' style='border:1px solid; background:white'>\n"; | |
325 | - $sortbox.= "</form>\n"; | |
326 | - | |
327 | - return $sortbox; | |
328 | - } | |
329 | - | |
330 | - | |
331 | - ########################### | |
332 | - ## text search things | |
333 | - ########################### | |
334 | - | |
335 | - function getTextbox($width='60%'){ | |
336 | - | |
337 | - $val = ""; | |
338 | - $sql = "SELECT * FROM ".$this->db->prefix('newdb_component_master'); | |
339 | - $sql.= " WHERE type='4' ORDER BY sort"; | |
340 | - $rs = $this->db->query($sql); | |
341 | - if($this->db->getRowsNum($rs)){ | |
342 | - $val.= "<form action='' method='GET'>"; | |
343 | - $val.= "<select name='comp_id'>"; | |
344 | - while($row = $this->db->fetchArray($rs)){ | |
345 | - $val.= "<option value='".$row['comp_id']."'>".$row['tag']."</option>"; | |
346 | - } | |
347 | - $val.= "</select> "; | |
348 | - | |
349 | - $val.= "<input type='text' style='width:".$width."' name='text'"; | |
350 | - if($this->tsearch_flg){ | |
351 | - $sql = "SELECT * FROM ".$this->db->prefix('newdb_list_textsearch'); | |
352 | - $sql.= " WHERE user='".$this->uid."'"; | |
353 | - $rs = $this->db->query($sql); | |
354 | - $row = $this->db->fetchArray($rs); | |
355 | - $v = $row['text']; | |
356 | - $val.= " value='".$v."'> "; | |
357 | - }else{ | |
358 | - $v = " "._ND_LIST_TSEARCH; | |
359 | - $val.= " value='".$v."' onclick=\"javascript:if(this.value == '".$v."') this.value=''\"> "; | |
360 | - } | |
361 | - $val.= "<input type='submit' name='tsearch' value='Go' style='background:white;border:1px solid'>"; | |
362 | - | |
363 | - if($this->type == 2){ | |
364 | - $val.="<input type='hidden' name='size' value='".$this->thumb_active_size[0]."'>\n"; | |
365 | - } | |
366 | - $val.= "<input type='hidden' name='item' value='0'>\n"; | |
367 | - $val.= "<input type='hidden' name='sort' value='".$this->sort_target."'>\n"; | |
368 | - $val.= "<input type='hidden' name='sort_method' value='".$this->sort_method."'>\n"; | |
369 | - $val.= "<input type='hidden' name='n' value='".$this->limit."'>\n"; | |
370 | - $val.= "<input type='hidden' name='id' value='".$this->list_id."'>\n"; | |
371 | - $val.= "<input type='hidden' name='user' value='".$this->uid."'>\n"; | |
372 | - $val.= "</form>"; | |
373 | - } | |
374 | - return $val; | |
375 | - } | |
376 | - | |
377 | - # Search Data Name on condition that $system=1 | |
378 | - function setTextbox($comp_id, $target, $system=0){ | |
379 | - | |
380 | - $label = ""; | |
381 | - $t = ""; $t2 = array(); | |
382 | - $target = str_replace(' ', ' ', $target); | |
383 | - $t2 = explode(' ', $target); | |
384 | - for($i=0; $i<count($t2); $i++){ | |
385 | - if($t != '') $t.= " OR "; | |
386 | - $t.= "value like '%".$t2[$i]."%'"; | |
387 | - } | |
388 | - | |
389 | - if($system){ | |
390 | - $t = str_replace('value like', 'label like', $t); | |
391 | - $sql = "SELECT * FROM ".$this->db->prefix('newdb_master'); | |
392 | - $sql.= " WHERE ".$t; | |
393 | - }else{ | |
394 | - $sql = "SELECT * FROM ".$this->db->prefix('newdb_component'); | |
395 | - $sql.= " WHERE comp_id='".$comp_id."' AND ".$t; | |
396 | - } | |
397 | - | |
398 | - $rs = $this->db->query($sql); | |
399 | - while($row = $this->db->fetchArray($rs)){ | |
400 | - if($label != "") $label.= ","; | |
401 | - $label.= $row['label_id']; | |
402 | - } | |
403 | - | |
404 | - $sql = "SELECT * FROM ".$this->db->prefix('newdb_list_textsearch'); | |
405 | - $sql.= " WHERE user='".$this->uid."'"; | |
406 | - $rs = $this->db->query($sql); | |
407 | - if($this->db->getRowsNum($rs)){ | |
408 | - $sql = "DELETE FROM ".$this->db->prefix('newdb_list_textsearch'); | |
409 | - $sql.= " WHERE user='".$this->uid."'"; | |
410 | - $rs = $this->db->queryF($sql); | |
411 | - } | |
412 | - | |
413 | - $sql = "INSERT INTO ".$this->db->prefix('newdb_list_textsearch'); | |
414 | - $sql.= " VALUES('','".$this->uid."','".addslashes($target)."','".$label."')"; | |
415 | - $rs = $this->db->queryF($sql); | |
416 | - $this->setTextFromDB(); | |
417 | - } | |
418 | - | |
419 | - function setTextFromDB(){ | |
420 | - | |
421 | - $this->tsearch_flg = 1; | |
422 | - $sql = "SELECT * FROM ".$this->db->prefix('newdb_list_textsearch'); | |
423 | - $sql.= " WHERE user='".$this->uid."' ORDER BY ref_id DESC"; | |
424 | - $rs = $this->db->query($sql); | |
425 | - $row = $this->db->fetchArray($rs); | |
426 | - $this->refine = explode(',', $row['labels']); | |
427 | - } | |
428 | - | |
429 | - ########################### | |
430 | - ## refine things | |
431 | - ########################### | |
432 | - | |
433 | - /** | |
434 | - * getRefinebox | |
435 | - * | |
436 | - * making refine box | |
437 | - * @access public | |
438 | - * @return $value (refine box) | |
439 | - */ | |
440 | - function getRefinebox(){ | |
441 | - $retv=''; | |
442 | - | |
443 | - # ID number for custom field (custom radio, custom check...) | |
444 | - $custom_id = array('CR'=>0, 'CC'=>0, 'CT'=>0, 'CS'=>0); | |
445 | - | |
446 | - $sql = "SELECT * FROM ".$this->db->prefix('newdb_component_master'); | |
447 | - $rs = $this->db->query($sql." WHERE onoff_refine='0' ORDER BY sort"); | |
448 | - while($row = $this->db->fetchArray($rs)){ | |
449 | - if($row['name']=='Views' || $row['name']=='ID' || $row['name']=='Data Name') continue; | |
450 | - | |
451 | - switch($row['type']){ | |
452 | - # System | |
453 | - case '1': | |
454 | - if($row['name']=='Author'){ | |
455 | - $retv.= "<table class='list_table' style='width:80%;'><tr>\n"; | |
456 | - $retv.= "<td style='width:80px'>".$row['tag']."</td><td>\n"; | |
457 | - $retv.= "<select name='author[]' size='5' MULTIPLE>\n"; | |
458 | - | |
459 | - $rs2 = $this->db->query("SELECT uid,uname FROM ".$this->db->prefix('users')); | |
460 | - while($row2 = $this->db->fetchArray($rs2)){ | |
461 | - $retv.="<option value='".$row2['uid']."'>".$row2['uname']."</option>\n"; | |
462 | - } | |
463 | - $retv.= "</select>"; | |
464 | - $retv.= "</td></tr></table>\n"; | |
465 | - | |
466 | - }elseif($row['name']=='Creation Date'){ | |
467 | - $retv.= "<table class='list_table' style='width:80%;'><tr>\n"; | |
468 | - $retv.= "<td style='width:80px'>".$row['tag']."</td><td>\n"; | |
469 | - $sql2 = "SELECT reg_date FROM ".$this->db->prefix('newdb_master')." ORDER BY reg_date"; | |
470 | - $rs2 = $this->db->query($sql2); | |
471 | - $year = array(); | |
472 | - while($row2 = $this->db->fetchArray($rs2)){ | |
473 | - $d = date('Y', $row2['reg_date']); | |
474 | - if(!in_array($d, $year)) $year[] = $d; | |
475 | - } | |
476 | - | |
477 | - for($i=1; $i<3; $i++){ | |
478 | - ($i==1) ? $retv.="From " : $retv.=" To "; | |
479 | - $retv.="<select name='year".$i."'>\n"; | |
480 | - for($j=0; $j<count($year); $j++){ | |
481 | - if($i==2 && $j==count($year)-1){ | |
482 | - $retv.="<option value='".$year[$j]."' selected>".$year[$j]."</option>\n"; | |
483 | - }else{ | |
484 | - $retv.="<option value='".$year[$j]."'>".$year[$j]."</option>\n"; | |
485 | - } | |
486 | - } | |
487 | - $retv.="</select>\n<select name='month".$i."'>\n"; | |
488 | - for($j=1; $j<13; $j++){ | |
489 | - if($i==2 && $j==12){ | |
490 | - $retv.="<option value='".$j."' selected>".$j."</option>\n"; | |
491 | - }else{ | |
492 | - $retv.="<option value='".$j."'>".$j."</option>\n"; | |
493 | - } | |
494 | - } | |
495 | - $retv.="</select>\n<select name='day".$i."'>\n"; | |
496 | - for($j=1; $j<32; $j++){ | |
497 | - if($i==2 && $j==31){ | |
498 | - $retv.="<option value='".$j."' selected>".$j."</option>\n"; | |
499 | - }else{ | |
500 | - $retv.="<option value='".$j."'>".$j."</option>\n"; | |
501 | - } | |
502 | - } | |
503 | - $retv.="</select>\n"; | |
504 | - } | |
505 | - $retv.= "</td>"; | |
506 | - $retv .= "</tr></table>\n"; | |
507 | - } | |
508 | - break; | |
509 | - | |
510 | - # Radio | |
511 | - case '2': | |
512 | - $retv.= "<table class='list_table' style='width:80%;'>\n"; | |
513 | - $retv.= "<tr><td style='width:80px'>".htmlspecialchars($row['tag'])."</td><td>"; | |
514 | - $svalue = explode(',', $row['select_value']); | |
515 | - for($j=0; $j<count($svalue); $j++){ | |
516 | - $retv.= "<input type='checkbox' name='CR".$custom_id['CR']."[]' value='".$svalue[$j]."'>"; | |
517 | - $svalue[$j] = str_replace('{', '<img src="images/admin/', $svalue[$j]); | |
518 | - $svalue[$j] = str_replace('}', '">', $svalue[$j]); | |
519 | - $retv.= $svalue[$j]." \n"; | |
520 | - } | |
521 | - $retv.= "<input type='hidden' name='CR".$custom_id['CR']."_id' value='".$row['comp_id']."'>"; | |
522 | - $retv.= "</td></tr></table>"; | |
523 | - $custom_id['CR']++; | |
524 | - break; | |
525 | - | |
526 | - # Checkbox | |
527 | - case '3': | |
528 | - $retv.= "<table class='list_table' style='width:80%;'>\n"; | |
529 | - $retv.= "<tr><td style='width:80px'>".htmlspecialchars($row['tag'])."</td><td>"; | |
530 | - $svalue = explode(',', $row['select_value']); | |
531 | - for($j=0; $j<count($svalue); $j++){ | |
532 | - $retv.= "<input type='checkbox' name='CC".$custom_id['CC']."[]' value='".$svalue[$j]."'>"; | |
533 | - $svalue[$j] = str_replace('{', '<img src="images/admin/', $svalue[$j]); | |
534 | - $svalue[$j] = str_replace('}', '">', $svalue[$j]); | |
535 | - $retv.= $svalue[$j]." \n"; | |
536 | - } | |
537 | - $retv.= "<input type='hidden' name='CC".$custom_id['CC']."_id' value='".$row['comp_id']."'>"; | |
538 | - $retv.= "</td></tr></table>"; | |
539 | - $custom_id['CC']++; | |
540 | - break; | |
541 | - | |
542 | - # Select | |
543 | - case '5': | |
544 | - $retv.= "<table class='list_table' style='width:80%;'>\n"; | |
545 | - $retv.= "<tr><td style='width:80px'>".htmlspecialchars($row['tag'])."</td><td>"; | |
546 | - $svalue = explode(',', $row['select_value']); | |
547 | - for($j=0; $j<count($svalue); $j++){ | |
548 | - $retv.= "<input type='checkbox' name='CS".$custom_id['CS']."[]' value='".$svalue[$j]."'>".$svalue[$j]." \n"; | |
549 | - } | |
550 | - $retv.= "<input type='hidden' name='CS".$custom_id['CS']."_id' value='".$row['comp_id']."'>"; | |
551 | - $retv.= "</td></tr></table>"; | |
552 | - $custom_id['CS']++; | |
553 | - break; | |
554 | - | |
555 | - default: | |
556 | - } | |
557 | - } | |
558 | - | |
559 | - $retv.="<br>"; | |
560 | - if($this->type == 2){ | |
561 | - $retv.="<input type='hidden' name='size' value='".$this->thumb_active_size[0]."'>\n"; | |
562 | - } | |
563 | - $retv.= "<input type='hidden' name='sort' value='".$this->sort_target."'>\n"; | |
564 | - $retv.= "<input type='hidden' name='sort_method' value='".$this->sort_method."'>\n"; | |
565 | - $retv.= "<input type='hidden' name='id' value='".$this->list_id."'>\n"; | |
566 | - $retv.= "<input type='hidden' name='n' value='".$this->limit."'>\n"; | |
567 | - $retv.= "<input type='hidden' name='item' value='0'>\n"; | |
568 | - $retv.= "<input type='hidden' name='refine' value='y'>\n"; | |
569 | - $retv.= "<input type='hidden' name='user' value='".$this->uid."'>\n"; | |
570 | - if($this->refine_flg){ | |
571 | - $retv.= "<input type='submit' name='more' value='"._ND_CLASS_REFINE2."' style='border:1px solid black; background:white'> "; | |
572 | - } | |
573 | - $retv.= "<input type='submit' name='do' value='"._ND_CLASS_REFINE."' style='border:1px solid black; background:white'> "; | |
574 | - $retv.= "<input type='submit' name='all' value='"._ND_CLASS_SHOWALL."' style='border:1px solid black; background:white'> "; | |
575 | - return $retv; | |
576 | - } | |
577 | - | |
578 | - | |
579 | - /** | |
580 | - * setRefine | |
581 | - * | |
582 | - * setting refine option | |
583 | - * @access public | |
584 | - */ | |
585 | - function setRefine($author, $from, $to, $component, $mode, $refineby){ | |
586 | - $this->refine_flg = 1; | |
587 | - | |
588 | - # aurhor | |
589 | - $authors = ''; | |
590 | - if(!empty($author)){ | |
591 | - $author = explode(',', $author); | |
592 | - for($i=0; $i<count($author); $i++){ | |
593 | - if($authors) $authors.=' OR '; | |
594 | - $authors.= "author='".$author[$i]."'"; | |
595 | - } | |
596 | - if($authors != '') $authors = "(".$authors.") AND "; | |
597 | - } | |
598 | - | |
599 | - # date | |
600 | - if(empty($from)) $from = strtotime('1990/1/1'); | |
601 | - if(empty($to)) $to = strtotime('2030/1/1'); | |
602 | - $date = "(reg_date >= '".$from."' AND reg_date <= '".$to."')"; | |
603 | - | |
604 | - $tmp1 = array(); | |
605 | - $sql = "SELECT label_id FROM ".$this->db->prefix('newdb_master'); | |
606 | - $sql.= " WHERE ".$authors." ".$date; | |
607 | - $rs = $this->db->query($sql); | |
608 | - while($row = $this->db->fetchArray($rs)){ | |
609 | - $tmp1[] = $row['label_id']; | |
610 | - } | |
611 | - | |
612 | - $tmp2 = array(); | |
613 | - for($i=0; $i<count($component); $i++){ | |
614 | - $sql = "SELECT label_id FROM ".$this->db->prefix('newdb_component'); | |
615 | - $sql.= " WHERE comp_id='".$component[$i][0]."' AND value='".$component[$i][1]."'"; | |
616 | - $rs = $this->db->query($sql); | |
617 | - while($row = $this->db->fetchArray($rs)){ | |
618 | - if(!in_array($row['label_id'], $tmp2)) $tmp2[] = $row['label_id']; | |
619 | - } | |
620 | - } | |
621 | - | |
622 | - # check | |
623 | - # modified again by H.Ikeno, 2006/05/11 | |
624 | - # change again by N.takuto 2006/08/28 | |
625 | - # | |
626 | - # 0 empty | |
627 | - # 1 refine by author, date only | |
628 | - # 2 refine by custom component only | |
629 | - # 3 refine by both | |
630 | - #echo $refineby; | |
631 | - switch ($refineby){ | |
632 | - case 0: | |
633 | - $this->refine = array(); | |
634 | - break; | |
635 | - | |
636 | - case 1: | |
637 | - $this->refine = $tmp1; | |
638 | - break; | |
639 | - | |
640 | - case 2: | |
641 | - $this->refine = $tmp2; | |
642 | - break; | |
643 | - | |
644 | - case 3: | |
645 | - $this->refine = array(); | |
646 | - if(count($tmp2)){ | |
647 | - for($i=0; $i<count($tmp1); $i++){ | |
648 | - if(in_array($tmp1[$i], $tmp2)) $this->refine[] = $tmp1[$i]; | |
649 | - } | |
650 | - } else { | |
651 | - $this->refine = $tmp1; | |
652 | - } | |
653 | - break; | |
654 | - } | |
655 | - | |
656 | - # more (refine) | |
657 | - if($mode == 1){ | |
658 | - $sql = "SELECT * FROM ".$this->db->prefix('newdb_list_refine'); | |
659 | - $sql.= " WHERE user='".$this->uid."'"; | |
660 | - $rs = $this->db->query($sql); | |
661 | - $row = $this->db->fetchArray($rs); | |
662 | - $before = explode(',', $row['labels']); | |
663 | - | |
664 | - $new = array(); | |
665 | - for($i=0; $i<count($this->refine); $i++){ | |
666 | - if(in_array($this->refine[$i], $before)) $new[] = $this->refine[$i]; | |
667 | - } | |
668 | - | |
669 | - $this->refine = array(); | |
670 | - $this->refine = $new; | |
671 | - } | |
672 | - | |
673 | - $tmp = ''; | |
674 | - for($i=0; $i<count($this->refine); $i++){ | |
675 | - if($tmp != '') $tmp.=','; | |
676 | - $tmp .= $this->refine[$i]; | |
677 | - } | |
678 | - | |
679 | - if($mode == 1 || $mode == 0){ | |
680 | - $sql = "DELETE FROM ".$this->db->prefix('newdb_list_refine')." WHERE user='".$this->uid."'"; | |
681 | - $rs = $this->db->queryF($sql); | |
682 | - | |
683 | - $sql = "INSERT INTO ".$this->db->prefix('newdb_list_refine'); | |
684 | - $sql.= " VALUES('','".$this->uid."','".$tmp."')"; | |
685 | - $rs = $this->db->queryF($sql); | |
686 | - } | |
687 | - return $tmp; | |
688 | - } | |
689 | - | |
690 | - # for refine + keyword search | |
691 | - function setRefineFromDB(){ | |
692 | - | |
693 | - $this->refine_flg = 1; | |
694 | - $sql = "SELECT * FROM ".$this->db->prefix('newdb_list_refine')." WHERE user='".$this->uid."'"; | |
695 | - $rs = $this->db->query($sql); | |
696 | - $row = $this->db->fetchArray($rs); | |
697 | - $this->refine = explode(',', $row['labels']); | |
698 | - } | |
699 | - | |
700 | - # for refine + keyword search | |
701 | - function getRefineFromDB(){ | |
702 | - | |
703 | - $sql = "SELECT * FROM ".$this->db->prefix('newdb_list_refine')." WHERE user='".$this->uid."'"; | |
704 | - $rs = $this->db->query($sql); | |
705 | - $row = $this->db->fetchArray($rs); | |
706 | - | |
707 | - $labels = explode(',', $row['labels']); | |
708 | - $ret = array(); | |
709 | - for($i=0; $i<count($labels); $i++){ | |
710 | - if($labels[$i] != '') $ret[] = $labels[$i]; | |
711 | - } | |
712 | - return $ret; | |
713 | - } | |
714 | - | |
715 | - | |
716 | - ########################### | |
717 | - ## kws things | |
718 | - ########################### | |
719 | - | |
720 | - function setKwsFlg(){ | |
721 | - $this->kws_flg = 1; | |
722 | - } | |
723 | - | |
724 | - function setKLabels($kw, $andor, $notkws){ | |
725 | - if($andor != 'and' && $andor != 'or') $andor = 'and'; | |
726 | - | |
727 | - # not keywords | |
728 | - $notkws = explode(',', substr($notkws, 0, -1)); | |
729 | - $notnum = array(); | |
730 | - $notkw = ''; | |
731 | - for($i=0; $i<count($notkws); $i++){ | |
732 | - if(!isset($notnum[$notkws[$i]])) $notnum[$notkws[$i]] = 0; | |
733 | - $notnum[$notkws[$i]]++; | |
734 | - } | |
735 | - foreach($notnum as $k => $v){ | |
736 | - if(($v % 2)){ | |
737 | - if(!empty($notkw)) $notkw.=','; | |
738 | - $notkw.= $k; | |
739 | - } | |
740 | - } | |
741 | - | |
742 | - # save keyword | |
743 | - if($kw){ | |
744 | - $sql = "INSERT INTO ".$this->db->prefix('newdb_list_refine_option'); | |
745 | - $sql.= " VALUES('', '".$this->uid."', '".$andor.":".$kw."')"; | |
746 | - $rs = $this->db->queryF($sql); | |
747 | - } | |
748 | - if($notkw){ | |
749 | - $sql = "INSERT INTO ".$this->db->prefix('newdb_list_refine_option'); | |
750 | - $sql.= " VALUES('', '".$this->uid."', 'not:".$notkw."')"; | |
751 | - $rs = $this->db->queryF($sql); | |
752 | - } | |
753 | - | |
754 | - # kw search | |
755 | - $kw = explode(',', $kw); | |
756 | - $notkw = explode(',', $notkw); | |
757 | - | |
758 | - $kws = ''; $labels = array(); | |
759 | - for($i=0; $i<count($kw); $i++){ | |
760 | - if(empty($kw[$i])) continue; | |
761 | - if(!empty($kws)) $kws.= ' '.$andor.' '; | |
762 | - $kws.= "keyword like '%[".$kw[$i]."]%'"; | |
763 | - } | |
764 | - | |
765 | - $notkws = ''; | |
766 | - for($i=0; $i<count($notkw); $i++){ | |
767 | - if(empty($notkw[$i])) continue; | |
768 | - if(!empty($notkws)) $notkws.= ' AND '; | |
769 | - $notkws.= "keyword not like '%[".$notkw[$i]."]%'"; | |
770 | - } | |
771 | - | |
772 | - if($kws && $notkws){ | |
773 | - $kws = "(".$kws.") AND (".$notkws.")"; | |
774 | - }elseif(!$kws && $notkws){ | |
775 | - $kws = $notkws; | |
776 | - } | |
777 | - if($kws) $kws = " WHERE ".$kws; | |
778 | - | |
779 | - $sql = "SELECT * FROM ".$this->db->prefix('newdb_master').$kws; | |
780 | - $rs = $this->db->query($sql); | |
781 | - $num = $this->db->getRowsNum($rs); | |
782 | - if($num > 0){ | |
783 | - while($row = $this->db->fetchArray($rs)){ | |
784 | - $labels[] = $row['label_id']; | |
785 | - } | |
786 | - } | |
787 | - #echo $sql; | |
788 | - | |
789 | - # check refine list | |
790 | - $refines = $this->getRefineFromDB(); | |
791 | - $label_list = ''; | |
792 | - if(count($refines) > 0){ | |
793 | - for($i=0; $i<count($labels); $i++){ | |
794 | - if(in_array($labels[$i], $refines)){ | |
795 | - if(!empty($label_list)) $label_list.=','; | |
796 | - $label_list.= $labels[$i]; | |
797 | - } | |
798 | - } | |
799 | - }else{ | |
800 | - for($i=0; $i<count($labels); $i++){ | |
801 | - if(!empty($label_list)) $label_list.=','; | |
802 | - $label_list.= $labels[$i]; | |
803 | - } | |
804 | - } | |
805 | - | |
806 | - $sql = "DELETE FROM ".$this->db->prefix('newdb_list_refine'); | |
807 | - $sql.= " WHERE user='".$this->uid."'"; | |
808 | - $rs = $this->db->queryF($sql); | |
809 | - | |
810 | - $sql = "INSERT INTO ".$this->db->prefix('newdb_list_refine'); | |
811 | - $sql.= " VALUES('', '".$this->uid."', '".$label_list."')"; | |
812 | - $rs = $this->db->queryF($sql); | |
813 | - $this->setRefineFromDB(); | |
814 | - } | |
815 | - | |
816 | - | |
817 | - ########################### | |
818 | - ## general things | |
819 | - ########################### | |
820 | - | |
821 | - function __getAllLabels(){ | |
822 | - | |
823 | - $label_list = array(); | |
824 | - $sql = "SELECT name,type FROM ".$this->db->prefix('newdb_component_master'); | |
825 | - $sql.= " WHERE comp_id='".$this->sort_target."'"; | |
826 | - $rs = $this->db->query($sql); | |
827 | - | |
828 | - if($this->db->getRowsNum($rs) > 0){ | |
829 | - $row = $this->db->fetchArray($rs); | |
830 | - | |
831 | - # sort by system component | |
832 | - if($row['type'] == 1){ | |
833 | - | |
834 | - $sql = "SELECT label_id FROM ".$this->db->prefix('newdb_master')." ORDER BY "; | |
835 | - if($row['name'] == 'ID'){ | |
836 | - $sql.= "label_id"; | |
837 | - }elseif($row['name'] == 'Data Name'){ | |
838 | - $sql.= "label"; | |
839 | - }elseif($row['name'] == 'Author'){ | |
840 | - $sql.= "author"; | |
841 | - }elseif($row['name'] == 'Creation Date'){ | |
842 | - $sql.= "reg_date"; | |
843 | - }elseif($row['name'] == 'Views'){ | |
844 | - $sql.= "views"; | |
845 | - } | |
846 | - $sql.= " ".$this->sort_method; | |
847 | - $rs = $this->db->query($sql); | |
848 | - while($row = $this->db->fetchArray($rs)){ | |
849 | - $label_list[] = $row['label_id']; | |
850 | - } | |
851 | - | |
852 | - # sort by radio, check, text component | |
853 | - }else{ | |
854 | - | |
855 | - $sql = "SELECT label_id FROM ".$this->db->prefix('newdb_component'); | |
856 | - $sql.= " WHERE comp_id='".$this->sort_target."' ORDER BY value ".$this->sort_method.""; | |
857 | - $rs = $this->db->query($sql); | |
858 | - while($row = $this->db->fetchArray($rs)){ | |
859 | - if(!in_array($row['label_id'], $label_list)) $label_list[] = $row['label_id']; | |
860 | - } | |
861 | - | |
862 | - $sql = "SELECT label_id FROM ".$this->db->prefix('newdb_master')." ORDER BY label_id desc"; | |
863 | - $rs = $this->db->query($sql); | |
864 | - while($row = $this->db->fetchArray($rs)){ | |
865 | - if(!in_array($row['label_id'], $label_list)) $label_list[] = $row['label_id']; | |
866 | - } | |
867 | - } | |
868 | - }else{ | |
869 | - $this->error = 'No item found. (listmanager.php line '.__LINE__.')'; | |
870 | - } | |
871 | - | |
872 | - return $label_list; | |
873 | - } | |
874 | - | |
875 | - /** | |
876 | - * getLabels | |
877 | - * | |
878 | - * making label list for show | |
879 | - * @access public | |
880 | - * @return $return_list (label array) | |
881 | - */ | |
882 | - function getLabels($mode=0){ | |
883 | - | |
884 | - $label_list = $this->__getAllLabels(); | |
885 | - | |
886 | - # refine or text search | |
887 | - if($this->refine_flg || $this->tsearch_flg){ | |
888 | - $label_list2 = array(); | |
889 | - for($i=0; $i<count($label_list); $i++){ | |
890 | - if(in_array($label_list[$i], $this->refine)) | |
891 | - $label_list2[] = $label_list[$i]; | |
892 | - } | |
893 | - $label_list = array(); | |
894 | - for($i=0; $i<count($label_list2); $i++) | |
895 | - $label_list[] = $label_list2[$i]; | |
896 | - } | |
897 | - | |
898 | - # paging | |
899 | - $return_list = array(); | |
900 | - $start = ($this->page - 1) * $this->limit; | |
901 | - for($i=$start; $i<$start+$this->limit; $i++){ | |
902 | - if(count($label_list) <= $i) break; | |
903 | - $return_list[] = $label_list[$i]; | |
904 | - } | |
905 | - | |
906 | - # return refine labels for paging | |
907 | - if($mode){ | |
908 | - $return_list = $label_list; | |
909 | - } | |
910 | - | |
911 | - return $return_list; | |
912 | - } | |
913 | - | |
914 | - /** | |
915 | - * getValues | |
916 | - * | |
917 | - * replace template like {ID} into value | |
918 | - * @access public | |
919 | - * @param $label_id (label id) | |
920 | - * @param $label (label name) | |
921 | - * @param $author (author) | |
922 | - * @param $date (creation date) | |
923 | - * @return $template | |
924 | - */ | |
925 | - function getValues($label_id, $label, $author, $date, $views, $dname_flg=0){ | |
926 | - | |
927 | - # uname | |
928 | - $sql = "SELECT uname FROM ".$this->db->prefix('users')." WHERE uid='".$author."'"; | |
929 | - $rs = $this->db->query($sql); | |
930 | - $row = $this->db->fetchArray($rs); | |
931 | - $uname = $row['uname']; | |
932 | - if($dname_flg){ | |
933 | - $label = "<a href='detail.php?id=".$label_id."'>".$label."</a>"; | |
934 | - $label_id4show = $label_id; | |
935 | - }else{ | |
936 | - $label_id4show = "<a href='detail.php?id=".$label_id."'>".$label_id."</a>"; | |
937 | - } | |
938 | - $template = $this->template; | |
939 | - | |
940 | - if(strstr($template, '{ID}')){ | |
941 | - $template = str_replace('{ID}', $label_id4show, $template); | |
942 | - } | |
943 | - if(strstr($template, '{Data Name}')){ | |
944 | - $template = str_replace('{Data Name}', $label, $template); | |
945 | - } | |
946 | - if(strstr($template, '{Author}')){ | |
947 | - $template = str_replace('{Author}', $uname, $template); | |
948 | - } | |
949 | - if(strstr($template, '{Creation Date}')){ | |
950 | - $template = str_replace('{Creation Date}', date('Y-m-d', $date), $template); | |
951 | - } | |
952 | - if(strstr($template, '{Views}')){ | |
953 | - $template = str_replace('{Views}', $views, $template); | |
954 | - } | |
955 | - | |
956 | - # get component value | |
957 | - $sql = "SELECT * FROM ".$this->db->prefix('newdb_component_master'); | |
958 | - $rs = $this->db->query($sql); | |
959 | - while($row = $this->db->fetchArray($rs)){ | |
960 | - | |
961 | - if(strstr($template,'{'.$row['name'].'}')){ | |
962 | - $sql = "SELECT * FROM ".$this->db->prefix('newdb_component'); | |
963 | - $sql.= " WHERE label_id='".$label_id."' AND comp_id='".$row['comp_id']."'"; | |
964 | - $rs2 = $this->db->query($sql); | |
965 | - $value = ''; | |
966 | - while($row2 = $this->db->fetchArray($rs2)){ | |
967 | - if($value) $value.= ', '; | |
968 | - | |
969 | - if($row['type']=='2' || $row['type']=='3'){ | |
970 | - $row2['value'] = str_replace('{', '<img src="images/admin/', $row2['value']); | |
971 | - $row2['value'] = str_replace('}', '">', $row2['value']); | |
972 | - | |
973 | - }elseif($row['type']=='4'){ | |
974 | - if($row['textmax']=='0'){ | |
975 | - $row2['value'] = str_replace("\r\n", "\r", $row2['value']); | |
976 | - $row2['value'] = str_replace("\r", "\n", $row2['value']); | |
977 | - $row2['value'] = str_replace("\n", "<br>", $row2['value']); | |
978 | - } | |
979 | - } | |
980 | - $value.= $row2['value']; | |
981 | - } | |
982 | - $template = str_replace('{'.$row['name'].'}', $value, $template); | |
983 | - } | |
984 | - } | |
985 | - | |
986 | - # clipboard | |
987 | - if(strstr($template, '{Ref ')){ | |
988 | - $st = 0; $end = 0; | |
989 | - for(;;){ | |
990 | - $st = strpos($template, '{Ref ', $end); | |
991 | - if($st > $end){ | |
992 | - $end = strpos($template, '}', $st); | |
993 | - $ref = substr($template, $st, ($end - $st + 1)); | |
994 | - $suffix = str_replace('{Ref ', '', $ref); | |
995 | - $suffix = str_replace('}', '', $suffix); | |
996 | - | |
997 | - $path=''; | |
998 | - $sql = "SELECT * FROM ".$this->db->prefix('newdb_master')." WHERE label_id='".$label_id."'"; | |
999 | - $rs = $this->db->query($sql); | |
1000 | - $row = $this->db->fetchArray($rs); | |
1001 | - $label = $row['label']; | |
1002 | - | |
1003 | - $sql = "SELECT * FROM ".$this->db->prefix('newdb_item'); | |
1004 | - $sql.= " WHERE label_id='".$label_id."' AND name like '%.".$suffix."' AND type='file'"; | |
1005 | - $rs = $this->db->query($sql); | |
1006 | - if($this->db->getRowsNum($rs)){ | |
1007 | - while($row = $this->db->fetchArray($rs)){ | |
1008 | - if(!empty($row['path'])){ | |
1009 | - $p = $row['path']."/"; | |
1010 | - }else{ | |
1011 | - $p = ''; | |
1012 | - } | |
1013 | - $tmp = "extract/".$label_id."/data/".$p.$row['name']; | |
1014 | - $path.= "<a style='cursor: pointer;' onClick=\"javascript:setClipboard('".$tmp."')\">".$row['name']."</a><br>"; | |
1015 | - } | |
1016 | - }else{ | |
1017 | - $path = ''; | |
1018 | - } | |
1019 | - $template = str_replace($ref, $path, $template); | |
1020 | - }else{ | |
1021 | - break; | |
1022 | - } | |
1023 | - } | |
1024 | - } | |
1025 | - | |
1026 | - # directories | |
1027 | - $sql = "SELECT * FROM ".$this->db->prefix('newdb_item'); | |
1028 | - $sql.= " WHERE type='dir' AND path='' AND label_id='".$label_id."' ORDER BY name"; | |
1029 | - | |
1030 | - if(strstr($template, '{Dirs}')){ | |
1031 | - $rs = $this->db->query($sql); | |
1032 | - $dirs = ''; | |
1033 | - while($row = $this->db->fetchArray($rs)){ | |
1034 | - if(!empty($dirs)) $dirs.=', '; | |
1035 | - $dirs.= substr($row['name'], 0, 3); | |
1036 | - } | |
1037 | - $template = str_replace('{Dirs}', $dirs, $template); | |
1038 | - } | |
1039 | - | |
1040 | - | |
1041 | - if(strstr($template, '{Dirs ')){ | |
1042 | - $st = 0; $end = 0; | |
1043 | - $st = strpos($template, '{Dirs ', $end); | |
1044 | - if($st > $end){ | |
1045 | - $end = strpos($template, '}', $st); | |
1046 | - $ref = substr($template, $st, ($end - $st + 1)); | |
1047 | - $num = str_replace('{Dirs ', '', $ref); | |
1048 | - $num = str_replace('}', '', $num); | |
1049 | - $num = intval($num); | |
1050 | - | |
1051 | - $rs = $this->db->query($sql); | |
1052 | - $dirs = ''; | |
1053 | - while($row = $this->db->fetchArray($rs)){ | |
1054 | - if(!empty($dirs)) $dirs.=', '; | |
1055 | - $dirs.= substr($row['name'], 0, $num); | |
1056 | - } | |
1057 | - $template = str_replace('{Dirs '.$num.'}', $dirs, $template); | |
1058 | - } | |
1059 | - } | |
1060 | - | |
1061 | - return $template; | |
1062 | - } | |
1063 | - | |
1064 | - function getListlink(){ | |
1065 | - | |
1066 | - $ret_value = ''; | |
1067 | - $sql = "SELECT * FROM ".$this->db->prefix('newdb_list')." WHERE onoff='0' ORDER BY sort"; | |
1068 | - $rs = $this->db->query($sql); | |
1069 | - while($row = $this->db->fetchArray($rs)){ | |
1070 | - $list_id = $row['list_id']; | |
1071 | - $name = $row['name']; | |
1072 | - | |
1073 | - $href = "id=".$list_id; | |
1074 | - $href.= "&n=".$this->limit; | |
1075 | - $href.= "&sort=".$this->sort_target; | |
1076 | - $href.= "&sort_method=".$this->sort_method; | |
1077 | - if($this->refine_flg){ | |
1078 | - $href.= "&refine=usedb"; | |
1079 | - $href.= "&user=".$this->uid; | |
1080 | - } | |
1081 | - if($this->type == 2) $href.= "&size=".$this->thumb_active_size[0]; | |
1082 | - $href.= "&item=".$this->item; | |
1083 | - | |
1084 | - if(!empty($ret_value)) $ret_value.= ' | '; | |
1085 | - if($list_id == $this->list_id){ | |
1086 | - $ret_value.= $name; | |
1087 | - }else{ | |
1088 | - $ret_value.= "<a href='list.php?".$href."'>".$name."</a>"; | |
1089 | - } | |
1090 | - } | |
1091 | - return $ret_value; | |
1092 | - } | |
1093 | - | |
1094 | - function error(){ | |
1095 | - return $this->error; | |
1096 | - } | |
1097 | - | |
1098 | -} | |
1099 | -?> | |
1 | +<?php | |
2 | + | |
3 | +/** | |
4 | + * class ListManager | |
5 | + */ | |
6 | + | |
7 | +class ListManager{ | |
8 | + | |
9 | + var $db; | |
10 | + var $list_id; | |
11 | + var $type; | |
12 | + var $template; | |
13 | + var $list_th; | |
14 | + var $thumb_dir; | |
15 | + var $thumb_size; | |
16 | + var $thumb_active_size; | |
17 | + var $sort_target; | |
18 | + var $sort_method; | |
19 | + var $page; | |
20 | + var $limit; | |
21 | + var $refine; | |
22 | + var $refine_flg; | |
23 | + var $tsearch_flg; | |
24 | + var $kws_flg; | |
25 | + var $uid; | |
26 | + var $item; | |
27 | + var $error; | |
28 | + | |
29 | + /** | |
30 | + * Class Constructor | |
31 | + */ | |
32 | + function ListManager(){ | |
33 | + $this->db =& Database::getInstance(); | |
34 | + } | |
35 | + | |
36 | + function setUser($time){ | |
37 | + $this->uid = $time; | |
38 | + } | |
39 | + | |
40 | + function setListId($list_id){ | |
41 | + | |
42 | + # get template | |
43 | + $sql = "SELECT * FROM ".$this->db->prefix('newdb_list')." WHERE list_id='".$list_id."'"; | |
44 | + $rs = $this->db->query($sql); | |
45 | + | |
46 | + if($this->db->getRowsNum($rs) == 0){ | |
47 | + $this->error = 'This List ID does not exist. (listmanager.php line '.__LINE__.')'; | |
48 | + $this->list_id = -1; | |
49 | + return false; | |
50 | + | |
51 | + }else{ | |
52 | + $row = $this->db->fetchArray($rs); | |
53 | + $this->list_id = $list_id; | |
54 | + $this->type = $row['type']; | |
55 | + $this->template = $row['template']; | |
56 | + $this->thumb_dir = $row['thumb_dir']; | |
57 | + $this->thumb_size = explode(';', $row['thumb_size']); | |
58 | + $this->page = 1; | |
59 | + $this->item = 0; | |
60 | + $this->limit = 20; | |
61 | + $this->refine = array(); | |
62 | + $this->refine_flg = 0; | |
63 | + $this->kws_flg = 0; | |
64 | + $this->tsearch_flg = 0; | |
65 | + $this->list_th = $this->setListTH($row['list_th']); | |
66 | + | |
67 | + if($this->type == 2){ | |
68 | + $this->__setSize(); | |
69 | + } | |
70 | + } | |
71 | + return true; | |
72 | + } | |
73 | + | |
74 | + function setListTH($th){ | |
75 | + | |
76 | + $sql = "SELECT * FROM ".$this->db->prefix('newdb_component_master'); | |
77 | + $rs = $this->db->query($sql); | |
78 | + while($row = $this->db->fetchArray($rs)){ | |
79 | + $template = '{'.$row['name'].'}'; | |
80 | + if(strstr($th, $template)){ | |
81 | + $th = str_replace($template, $row['tag'], $th); | |
82 | + } | |
83 | + } | |
84 | + return $th; | |
85 | + } | |
86 | + | |
87 | + | |
88 | + ########################### | |
89 | + ## thumbnail things | |
90 | + ########################### | |
91 | + | |
92 | + /** | |
93 | + * __setSize | |
94 | + * | |
95 | + * setting thumbnail with default size-set | |
96 | + * @access private | |
97 | + */ | |
98 | + function __setSize(){ | |
99 | + | |
100 | + $size = array(); | |
101 | + $size = explode(',', $this->thumb_size[0]); | |
102 | + | |
103 | + $this->thumb_active_size[0] = $size[0]; | |
104 | + $this->thumb_active_size[1] = $size[1]; | |
105 | + $this->thumb_active_size[2] = $size[2]; | |
106 | + $this->thumb_active_size[3] = $size[3]; | |
107 | + | |
108 | + return true; | |
109 | + } | |
110 | + | |
111 | + | |
112 | + /** | |
113 | + * changeSize | |
114 | + * | |
115 | + * change thumbnail size | |
116 | + * @access public | |
117 | + * @param $name (target thumbnail size name) | |
118 | + */ | |
119 | + function changeSize($name){ | |
120 | + | |
121 | + $myts =& MyTextSanitizer::getInstance(); | |
122 | + $name = $myts->stripSlashesGPC($name); | |
123 | + | |
124 | + $size = array(); | |
125 | + for($i=0; $i<count($this->thumb_size); $i++){ | |
126 | + $size[] = explode(',', $this->thumb_size[$i]); | |
127 | + } | |
128 | + | |
129 | + for($i=0; $i<count($this->thumb_size); $i++){ | |
130 | + if($size[$i][0] == $name){ | |
131 | + $this->thumb_active_size[0] = $size[$i][0]; | |
132 | + $this->thumb_active_size[1] = $size[$i][1]; | |
133 | + $this->thumb_active_size[2] = $size[$i][2]; | |
134 | + $this->thumb_active_size[3] = $size[$i][3]; | |
135 | + } | |
136 | + } | |
137 | + | |
138 | + return true; | |
139 | + } | |
140 | + | |
141 | + | |
142 | + /** | |
143 | + * __getThumbLink | |
144 | + * | |
145 | + * making thumbnail size selection box | |
146 | + * @access private | |
147 | + * @return $thumb_link (thumbnail size selection box) | |
148 | + */ | |
149 | + function __getThumbLink(){ | |
150 | + | |
151 | + $thumb_link = " <select name='size'>"; | |
152 | + for($i=0; $i<count($this->thumb_size); $i++){ | |
153 | + | |
154 | + $ts = explode(',', $this->thumb_size[$i]); | |
155 | + $thumb_link.= "<option value=".$ts[0]; | |
156 | + if($ts[0] == $this->thumb_active_size[0]){ | |
157 | + $thumb_link.= " selected"; | |
158 | + } | |
159 | + $thumb_link.= ">".$ts[0]."</option> \n"; | |
160 | + } | |
161 | + | |
162 | + $thumb_link.= "</select>"; | |
163 | + return $thumb_link; | |
164 | + } | |
165 | + | |
166 | + | |
167 | + ########################### | |
168 | + ## paging things | |
169 | + ########################### | |
170 | + | |
171 | + /** | |
172 | + * setPage | |
173 | + * | |
174 | + * setting page number and limit | |
175 | + * @access public | |
176 | + * @param $p (page number) | |
177 | + * @param $l (showing limit) | |
178 | + */ | |
179 | + function setPage($item, $l){ | |
180 | + | |
181 | + if($l < 0 || !$l) $l = 20; | |
182 | + $this->limit = intval($l); | |
183 | + | |
184 | + if($item <= 0 || !$item){ | |
185 | + $p = 1; | |
186 | + $this->item = 0; | |
187 | + }else{ | |
188 | + $p = $item / $this->limit + 1; | |
189 | + $this->item = $item; | |
190 | + } | |
191 | + $this->page = intval($p); | |
192 | + } | |
193 | + | |
194 | + | |
195 | + /** | |
196 | + * getPagelink | |
197 | + * | |
198 | + * making page selection link | |
199 | + * @access public | |
200 | + * @return $pagelink | |
201 | + */ | |
202 | + function getPagelink(){ | |
203 | + | |
204 | + $n = count($this->getLabels(1)); | |
205 | + $pagenum = ceil($n / $this->limit); | |
206 | + $pagenow = $this->page.'/'.$pagenum; | |
207 | + $f = ($pagenow-1) * $this->limit + 1; | |
208 | + $t = $pagenow * $this->limit; | |
209 | + if($t > $n) $t = $n; | |
210 | + $pagelink = _ND_CLASS_ALL.$n._ND_CLASS_HIT." ( ".$f." - ".$t._ND_CLASS_HIT_NOW." ) "; | |
211 | + | |
212 | + $href = "id=".$this->list_id; | |
213 | + $href.= "&n=".$this->limit; | |
214 | + $href.= "&sort=".$this->sort_target; | |
215 | + $href.= "&sort_method=".$this->sort_method; | |
216 | + if($this->refine_flg){ | |
217 | + $href.= "&refine=usedb"; | |
218 | + $href.= "&user=".$this->uid; | |
219 | + } | |
220 | + if($this->tsearch_flg){ | |
221 | + $href.= "&tsearch=usedb"; | |
222 | + $href.= "&user=".$this->uid; | |
223 | + } | |
224 | + if($this->type == 2) $href.= "&size=".$this->thumb_active_size[0]; | |
225 | + | |
226 | + require XOOPS_ROOT_PATH.'/class/pagenav.php'; | |
227 | + $xp = new XoopsPageNav($n, $this->limit, $f, 'item', $href); | |
228 | + $pagelink.= $xp->renderNav(); | |
229 | + | |
230 | + return $pagelink; | |
231 | + } | |
232 | + | |
233 | + | |
234 | + ########################### | |
235 | + ## sort things | |
236 | + ########################### | |
237 | + | |
238 | + /** | |
239 | + * setSort | |
240 | + * | |
241 | + * setting sort target id and method | |
242 | + * @access public | |
243 | + * @param $sort_target (sort item's ID) | |
244 | + * @param $sort_method (asc or desc) | |
245 | + */ | |
246 | + function setSort($sort_target, $sort_method){ | |
247 | + $this->sort_target = intval($sort_target); | |
248 | + if($sort_method != 'desc' && $sort_method != 'asc'){ | |
249 | + $this->sort_method = 'desc'; | |
250 | + }else{ | |
251 | + $this->sort_method = $sort_method; | |
252 | + } | |
253 | + } | |
254 | + | |
255 | + | |
256 | + /** | |
257 | + * getSortbox | |
258 | + * | |
259 | + * making sort box for list and thumbnail page | |
260 | + * @access public | |
261 | + * @return $sortbox (sort box) | |
262 | + */ | |
263 | + function getSortbox(){ | |
264 | + | |
265 | + $sortbox = "<form method='GET' action='list.php' style='margin:0'>\n"; | |
266 | + $sortbox.= "<select name='sort'>\n"; | |
267 | + | |
268 | + # sort target | |
269 | + $sql = "SELECT * FROM ".$this->db->prefix('newdb_component_master'); | |
270 | + $sql.= " WHERE onoff='0' ORDER BY sort"; | |
271 | + $rs = $this->db->query($sql); | |
272 | + while($row = $this->db->fetchArray($rs)){ | |
273 | + $sortbox.= "<option value='".$row['comp_id']."' "; | |
274 | + if($row['comp_id'] == $this->sort_target){ | |
275 | + $sortbox.= "selected"; | |
276 | + } | |
277 | + $sortbox.= ">".$row['tag']."</option>\n"; | |
278 | + } | |
279 | + $sortbox.= "</select>\n"; | |
280 | + | |
281 | + # up/down | |
282 | + $sortbox.= "<select name='sort_method'>\n"; | |
283 | + $sortbox.= "<option value='asc' "; | |
284 | + if($this->sort_method == 'asc'){ | |
285 | + $sortbox.= "selected"; | |
286 | + } | |
287 | + $sortbox.= ">"._ND_UP."</option>\n"; | |
288 | + | |
289 | + $sortbox.= "<option value='desc' "; | |
290 | + if($this->sort_method == 'desc'){ | |
291 | + $sortbox.= "selected"; | |
292 | + } | |
293 | + $sortbox.= ">"._ND_DOWN."</option>\n"; | |
294 | + $sortbox.= "</select>\n"; | |
295 | + | |
296 | + # show limit | |
297 | + $n = array(20,40,60,80,100); | |
298 | + $sortbox.="<select name='n'>"; | |
299 | + for($i=0; $i<count($n); $i++){ | |
300 | + $sortbox.="<option vaule='".$n[$i]."'"; | |
301 | + if($this->limit == $n[$i]) $sortbox.= "selected"; | |
302 | + $sortbox.=">".$n[$i]."</option>"; | |
303 | + } | |
304 | + $sortbox.="</select>"; | |
305 | + | |
306 | + # thumb size | |
307 | + if($this->type == 2){ | |
308 | + $sortbox.= $this->__getThumbLink(); | |
309 | + } | |
310 | + | |
311 | + $sortbox.= "<input type='hidden' name='id' value='".$this->list_id."'>\n"; | |
312 | + $sortbox.= "<input type='hidden' name='item' value='0'>\n"; | |
313 | + if($this->refine_flg){ | |
314 | + $sortbox.= "<input type='hidden' name='refine' value='usedb'>\n"; | |
315 | + $sortbox.= "<input type='hidden' name='user' value='".$this->uid."'>\n"; | |
316 | + } | |
317 | + if($this->kws_flg){ | |
318 | + $sortbox.= "<input type='hidden' name='kws' value='paging'>\n"; | |
319 | + } | |
320 | + if($this->tsearch_flg){ | |
321 | + $sortbox.= "<input type='hidden' name='tsearch' value='usedb'>\n"; | |
322 | + $sortbox.= "<input type='hidden' name='user' value='".$this->uid."'>\n"; | |
323 | + } | |
324 | + $sortbox.= " <input type='submit' value='Sort' style='border:1px solid; background:white'>\n"; | |
325 | + $sortbox.= "</form>\n"; | |
326 | + | |
327 | + return $sortbox; | |
328 | + } | |
329 | + | |
330 | + | |
331 | + ########################### | |
332 | + ## text search things | |
333 | + ########################### | |
334 | + | |
335 | + function getTextbox($width='60%'){ | |
336 | + | |
337 | + $val = ""; | |
338 | + $sql = "SELECT * FROM ".$this->db->prefix('newdb_component_master'); | |
339 | + $sql.= " WHERE type='4' ORDER BY sort"; | |
340 | + $rs = $this->db->query($sql); | |
341 | + if($this->db->getRowsNum($rs)){ | |
342 | + $val.= "<form action='' method='GET'>"; | |
343 | + $val.= "<select name='comp_id'>"; | |
344 | + while($row = $this->db->fetchArray($rs)){ | |
345 | + $val.= "<option value='".$row['comp_id']."'>".$row['tag']."</option>"; | |
346 | + } | |
347 | + $val.= "</select> "; | |
348 | + | |
349 | + $val.= "<input type='text' style='width:".$width."' name='text'"; | |
350 | + if($this->tsearch_flg){ | |
351 | + $sql = "SELECT * FROM ".$this->db->prefix('newdb_list_textsearch'); | |
352 | + $sql.= " WHERE user='".$this->uid."'"; | |
353 | + $rs = $this->db->query($sql); | |
354 | + $row = $this->db->fetchArray($rs); | |
355 | + $v = $row['text']; | |
356 | + $val.= " value='".$v."'> "; | |
357 | + }else{ | |
358 | + $v = " "._ND_LIST_TSEARCH; | |
359 | + $val.= " value='".$v."' onclick=\"javascript:if(this.value == '".$v."') this.value=''\"> "; | |
360 | + } | |
361 | + $val.= "<input type='submit' name='tsearch' value='Go' style='background:white;border:1px solid'>"; | |
362 | + | |
363 | + if($this->type == 2){ | |
364 | + $val.="<input type='hidden' name='size' value='".$this->thumb_active_size[0]."'>\n"; | |
365 | + } | |
366 | + $val.= "<input type='hidden' name='item' value='0'>\n"; | |
367 | + $val.= "<input type='hidden' name='sort' value='".$this->sort_target."'>\n"; | |
368 | + $val.= "<input type='hidden' name='sort_method' value='".$this->sort_method."'>\n"; | |
369 | + $val.= "<input type='hidden' name='n' value='".$this->limit."'>\n"; | |
370 | + $val.= "<input type='hidden' name='id' value='".$this->list_id."'>\n"; | |
371 | + $val.= "<input type='hidden' name='user' value='".$this->uid."'>\n"; | |
372 | + $val.= "</form>"; | |
373 | + } | |
374 | + return $val; | |
375 | + } | |
376 | + | |
377 | + # Search Data Name on condition that $system=1 | |
378 | + function setTextbox($comp_id, $target, $system=0){ | |
379 | + | |
380 | + $label = ""; | |
381 | + $t = ""; $t2 = array(); | |
382 | + $target = str_replace(' ', ' ', $target); | |
383 | + $t2 = explode(' ', $target); | |
384 | + for($i=0; $i<count($t2); $i++){ | |
385 | + if($t != '') $t.= " OR "; | |
386 | + $t.= "value like '%".$t2[$i]."%'"; | |
387 | + } | |
388 | + | |
389 | + if($system){ | |
390 | + $t = str_replace('value like', 'label like', $t); | |
391 | + $sql = "SELECT * FROM ".$this->db->prefix('newdb_master'); | |
392 | + $sql.= " WHERE ".$t; | |
393 | + }else{ | |
394 | + $sql = "SELECT * FROM ".$this->db->prefix('newdb_component'); | |
395 | + $sql.= " WHERE comp_id='".$comp_id."' AND ".$t; | |
396 | + } | |
397 | + | |
398 | + $rs = $this->db->query($sql); | |
399 | + while($row = $this->db->fetchArray($rs)){ | |
400 | + if($label != "") $label.= ","; | |
401 | + $label.= $row['label_id']; | |
402 | + } | |
403 | + | |
404 | + $sql = "SELECT * FROM ".$this->db->prefix('newdb_list_textsearch'); | |
405 | + $sql.= " WHERE user='".$this->uid."'"; | |
406 | + $rs = $this->db->query($sql); | |
407 | + if($this->db->getRowsNum($rs)){ | |
408 | + $sql = "DELETE FROM ".$this->db->prefix('newdb_list_textsearch'); | |
409 | + $sql.= " WHERE user='".$this->uid."'"; | |
410 | + $rs = $this->db->queryF($sql); | |
411 | + } | |
412 | + | |
413 | + $sql = "INSERT INTO ".$this->db->prefix('newdb_list_textsearch'); | |
414 | + $sql.= " VALUES('','".$this->uid."','".addslashes($target)."','".$label."')"; | |
415 | + $rs = $this->db->queryF($sql); | |
416 | + $this->setTextFromDB(); | |
417 | + } | |
418 | + | |
419 | + function setTextFromDB(){ | |
420 | + | |
421 | + $this->tsearch_flg = 1; | |
422 | + $sql = "SELECT * FROM ".$this->db->prefix('newdb_list_textsearch'); | |
423 | + $sql.= " WHERE user='".$this->uid."' ORDER BY ref_id DESC"; | |
424 | + $rs = $this->db->query($sql); | |
425 | + $row = $this->db->fetchArray($rs); | |
426 | + $this->refine = explode(',', $row['labels']); | |
427 | + } | |
428 | + | |
429 | + ########################### | |
430 | + ## refine things | |
431 | + ########################### | |
432 | + | |
433 | + /** | |
434 | + * getRefinebox | |
435 | + * | |
436 | + * making refine box | |
437 | + * @access public | |
438 | + * @return $value (refine box) | |
439 | + */ | |
440 | + function getRefinebox(){ | |
441 | + $retv=''; | |
442 | + | |
443 | + # ID number for custom field (custom radio, custom check...) | |
444 | + $custom_id = array('CR'=>0, 'CC'=>0, 'CT'=>0, 'CS'=>0); | |
445 | + | |
446 | + $sql = "SELECT * FROM ".$this->db->prefix('newdb_component_master'); | |
447 | + $rs = $this->db->query($sql." WHERE onoff_refine='0' ORDER BY sort"); | |
448 | + while($row = $this->db->fetchArray($rs)){ | |
449 | + if($row['name']=='Views' || $row['name']=='ID' || $row['name']=='Data Name') continue; | |
450 | + | |
451 | + switch($row['type']){ | |
452 | + # System | |
453 | + case '1': | |
454 | + if($row['name']=='Author'){ | |
455 | + $retv.= "<table class='list_table' style='width:80%;'><tr>\n"; | |
456 | + $retv.= "<td style='width:80px'>".$row['tag']."</td><td>\n"; | |
457 | + $retv.= "<select name='author[]' size='5' MULTIPLE>\n"; | |
458 | + | |
459 | + $rs2 = $this->db->query("SELECT uid,uname FROM ".$this->db->prefix('users')); | |
460 | + while($row2 = $this->db->fetchArray($rs2)){ | |
461 | + $retv.="<option value='".$row2['uid']."'>".$row2['uname']."</option>\n"; | |
462 | + } | |
463 | + $retv.= "</select>"; | |
464 | + $retv.= "</td></tr></table>\n"; | |
465 | + | |
466 | + }elseif($row['name']=='Creation Date'){ | |
467 | + $retv.= "<table class='list_table' style='width:80%;'><tr>\n"; | |
468 | + $retv.= "<td style='width:80px'>".$row['tag']."</td><td>\n"; | |
469 | + $sql2 = "SELECT reg_date FROM ".$this->db->prefix('newdb_master')." ORDER BY reg_date"; | |
470 | + $rs2 = $this->db->query($sql2); | |
471 | + $year = array(); | |
472 | + while($row2 = $this->db->fetchArray($rs2)){ | |
473 | + $d = date('Y', $row2['reg_date']); | |
474 | + if(!in_array($d, $year)) $year[] = $d; | |
475 | + } | |
476 | + | |
477 | + for($i=1; $i<3; $i++){ | |
478 | + ($i==1) ? $retv.="From " : $retv.=" To "; | |
479 | + $retv.="<select name='year".$i."'>\n"; | |
480 | + for($j=0; $j<count($year); $j++){ | |
481 | + if($i==2 && $j==count($year)-1){ | |
482 | + $retv.="<option value='".$year[$j]."' selected>".$year[$j]."</option>\n"; | |
483 | + }else{ | |
484 | + $retv.="<option value='".$year[$j]."'>".$year[$j]."</option>\n"; | |
485 | + } | |
486 | + } | |
487 | + $retv.="</select>\n<select name='month".$i."'>\n"; | |
488 | + for($j=1; $j<13; $j++){ | |
489 | + if($i==2 && $j==12){ | |
490 | + $retv.="<option value='".$j."' selected>".$j."</option>\n"; | |
491 | + }else{ | |
492 | + $retv.="<option value='".$j."'>".$j."</option>\n"; | |
493 | + } | |
494 | + } | |
495 | + $retv.="</select>\n<select name='day".$i."'>\n"; | |
496 | + for($j=1; $j<32; $j++){ | |
497 | + if($i==2 && $j==31){ | |
498 | + $retv.="<option value='".$j."' selected>".$j."</option>\n"; | |
499 | + }else{ | |
500 | + $retv.="<option value='".$j."'>".$j."</option>\n"; | |
501 | + } | |
502 | + } | |
503 | + $retv.="</select>\n"; | |
504 | + } | |
505 | + $retv.= "</td>"; | |
506 | + $retv .= "</tr></table>\n"; | |
507 | + } | |
508 | + break; | |
509 | + | |
510 | + # Radio | |
511 | + case '2': | |
512 | + $retv.= "<table class='list_table' style='width:80%;'>\n"; | |
513 | + $retv.= "<tr><td style='width:80px'>".htmlspecialchars($row['tag'])."</td><td>"; | |
514 | + $svalue = explode(',', $row['select_value']); | |
515 | + for($j=0; $j<count($svalue); $j++){ | |
516 | + $retv.= "<input type='checkbox' name='CR".$custom_id['CR']."[]' value='".$svalue[$j]."'>"; | |
517 | + $svalue[$j] = str_replace('{', '<img src="images/admin/', $svalue[$j]); | |
518 | + $svalue[$j] = str_replace('}', '">', $svalue[$j]); | |
519 | + $retv.= $svalue[$j]." \n"; | |
520 | + } | |
521 | + $retv.= "<input type='hidden' name='CR".$custom_id['CR']."_id' value='".$row['comp_id']."'>"; | |
522 | + $retv.= "</td></tr></table>"; | |
523 | + $custom_id['CR']++; | |
524 | + break; | |
525 | + | |
526 | + # Checkbox | |
527 | + case '3': | |
528 | + $retv.= "<table class='list_table' style='width:80%;'>\n"; | |
529 | + $retv.= "<tr><td style='width:80px'>".htmlspecialchars($row['tag'])."</td><td>"; | |
530 | + $svalue = explode(',', $row['select_value']); | |
531 | + for($j=0; $j<count($svalue); $j++){ | |
532 | + $retv.= "<input type='checkbox' name='CC".$custom_id['CC']."[]' value='".$svalue[$j]."'>"; | |
533 | + $svalue[$j] = str_replace('{', '<img src="images/admin/', $svalue[$j]); | |
534 | + $svalue[$j] = str_replace('}', '">', $svalue[$j]); | |
535 | + $retv.= $svalue[$j]." \n"; | |
536 | + } | |
537 | + $retv.= "<input type='hidden' name='CC".$custom_id['CC']."_id' value='".$row['comp_id']."'>"; | |
538 | + $retv.= "</td></tr></table>"; | |
539 | + $custom_id['CC']++; | |
540 | + break; | |
541 | + | |
542 | + # Select | |
543 | + case '5': | |
544 | + $retv.= "<table class='list_table' style='width:80%;'>\n"; | |
545 | + $retv.= "<tr><td style='width:80px'>".htmlspecialchars($row['tag'])."</td><td>"; | |
546 | + $svalue = explode(',', $row['select_value']); | |
547 | + for($j=0; $j<count($svalue); $j++){ | |
548 | + $retv.= "<input type='checkbox' name='CS".$custom_id['CS']."[]' value='".$svalue[$j]."'>".$svalue[$j]." \n"; | |
549 | + } | |
550 | + $retv.= "<input type='hidden' name='CS".$custom_id['CS']."_id' value='".$row['comp_id']."'>"; | |
551 | + $retv.= "</td></tr></table>"; | |
552 | + $custom_id['CS']++; | |
553 | + break; | |
554 | + | |
555 | + default: | |
556 | + } | |
557 | + } | |
558 | + | |
559 | + $retv.="<br>"; | |
560 | + if($this->type == 2){ | |
561 | + $retv.="<input type='hidden' name='size' value='".$this->thumb_active_size[0]."'>\n"; | |
562 | + } | |
563 | + $retv.= "<input type='hidden' name='sort' value='".$this->sort_target."'>\n"; | |
564 | + $retv.= "<input type='hidden' name='sort_method' value='".$this->sort_method."'>\n"; | |
565 | + $retv.= "<input type='hidden' name='id' value='".$this->list_id."'>\n"; | |
566 | + $retv.= "<input type='hidden' name='n' value='".$this->limit."'>\n"; | |
567 | + $retv.= "<input type='hidden' name='item' value='0'>\n"; | |
568 | + $retv.= "<input type='hidden' name='refine' value='y'>\n"; | |
569 | + $retv.= "<input type='hidden' name='user' value='".$this->uid."'>\n"; | |
570 | + if($this->refine_flg){ | |
571 | + $retv.= "<input type='submit' name='more' value='"._ND_CLASS_REFINE2."' style='border:1px solid black; background:white'> "; | |
572 | + } | |
573 | + $retv.= "<input type='submit' name='do' value='"._ND_CLASS_REFINE."' style='border:1px solid black; background:white'> "; | |
574 | + $retv.= "<input type='submit' name='all' value='"._ND_CLASS_SHOWALL."' style='border:1px solid black; background:white'> "; | |
575 | + return $retv; | |
576 | + } | |
577 | + | |
578 | + | |
579 | + /** | |
580 | + * setRefine | |
581 | + * | |
582 | + * setting refine option | |
583 | + * @access public | |
584 | + */ | |
585 | + function setRefine($author, $from, $to, $component, $mode, $refineby){ | |
586 | + $this->refine_flg = 1; | |
587 | + | |
588 | + # aurhor | |
589 | + $authors = ''; | |
590 | + if(!empty($author)){ | |
591 | + $author = explode(',', $author); | |
592 | + for($i=0; $i<count($author); $i++){ | |
593 | + if($authors) $authors.=' OR '; | |
594 | + $authors.= "author='".$author[$i]."'"; | |
595 | + } | |
596 | + if($authors != '') $authors = "(".$authors.") AND "; | |
597 | + } | |
598 | + | |
599 | + # date | |
600 | + if(empty($from)) $from = strtotime('1990/1/1'); | |
601 | + if(empty($to)) $to = strtotime('2030/1/1'); | |
602 | + $date = "(reg_date >= '".$from."' AND reg_date <= '".$to."')"; | |
603 | + | |
604 | + $tmp1 = array(); | |
605 | + $sql = "SELECT label_id FROM ".$this->db->prefix('newdb_master'); | |
606 | + $sql.= " WHERE ".$authors." ".$date; | |
607 | + $rs = $this->db->query($sql); | |
608 | + while($row = $this->db->fetchArray($rs)){ | |
609 | + $tmp1[] = $row['label_id']; | |
610 | + } | |
611 | + | |
612 | + $tmp2 = array(); | |
613 | + for($i=0; $i<count($component); $i++){ | |
614 | + $sql = "SELECT label_id FROM ".$this->db->prefix('newdb_component'); | |
615 | + $sql.= " WHERE comp_id='".$component[$i][0]."' AND value='".$component[$i][1]."'"; | |
616 | + $rs = $this->db->query($sql); | |
617 | + while($row = $this->db->fetchArray($rs)){ | |
618 | + if(!in_array($row['label_id'], $tmp2)) $tmp2[] = $row['label_id']; | |
619 | + } | |
620 | + } | |
621 | + | |
622 | + # check | |
623 | + # modified again by H.Ikeno, 2006/05/11 | |
624 | + # change again by N.takuto 2006/08/28 | |
625 | + # | |
626 | + # 0 empty | |
627 | + # 1 refine by author, date only | |
628 | + # 2 refine by custom component only | |
629 | + # 3 refine by both | |
630 | + #echo $refineby; | |
631 | + switch ($refineby){ | |
632 | + case 0: | |
633 | + $this->refine = array(); | |
634 | + break; | |
635 | + | |
636 | + case 1: | |
637 | + $this->refine = $tmp1; | |
638 | + break; | |
639 | + | |
640 | + case 2: | |
641 | + $this->refine = $tmp2; | |
642 | + break; | |
643 | + | |
644 | + case 3: | |
645 | + $this->refine = array(); | |
646 | + if(count($tmp2)){ | |
647 | + for($i=0; $i<count($tmp1); $i++){ | |
648 | + if(in_array($tmp1[$i], $tmp2)) $this->refine[] = $tmp1[$i]; | |
649 | + } | |
650 | + } else { | |
651 | + $this->refine = $tmp1; | |
652 | + } | |
653 | + break; | |
654 | + } | |
655 | + | |
656 | + # more (refine) | |
657 | + if($mode == 1){ | |
658 | + $sql = "SELECT * FROM ".$this->db->prefix('newdb_list_refine'); | |
659 | + $sql.= " WHERE user='".$this->uid."'"; | |
660 | + $rs = $this->db->query($sql); | |
661 | + $row = $this->db->fetchArray($rs); | |
662 | + $before = explode(',', $row['labels']); | |
663 | + | |
664 | + $new = array(); | |
665 | + for($i=0; $i<count($this->refine); $i++){ | |
666 | + if(in_array($this->refine[$i], $before)) $new[] = $this->refine[$i]; | |
667 | + } | |
668 | + | |
669 | + $this->refine = array(); | |
670 | + $this->refine = $new; | |
671 | + } | |
672 | + | |
673 | + $tmp = ''; | |
674 | + for($i=0; $i<count($this->refine); $i++){ | |
675 | + if($tmp != '') $tmp.=','; | |
676 | + $tmp .= $this->refine[$i]; | |
677 | + } | |
678 | + | |
679 | + if($mode == 1 || $mode == 0){ | |
680 | + $sql = "DELETE FROM ".$this->db->prefix('newdb_list_refine')." WHERE user='".$this->uid."'"; | |
681 | + $rs = $this->db->queryF($sql); | |
682 | + | |
683 | + $sql = "INSERT INTO ".$this->db->prefix('newdb_list_refine'); | |
684 | + $sql.= " VALUES('','".$this->uid."','".$tmp."')"; | |
685 | + $rs = $this->db->queryF($sql); | |
686 | + } | |
687 | + return $tmp; | |
688 | + } | |
689 | + | |
690 | + # for refine + keyword search | |
691 | + function setRefineFromDB(){ | |
692 | + | |
693 | + $this->refine_flg = 1; | |
694 | + $sql = "SELECT * FROM ".$this->db->prefix('newdb_list_refine')." WHERE user='".$this->uid."'"; | |
695 | + $rs = $this->db->query($sql); | |
696 | + $row = $this->db->fetchArray($rs); | |
697 | + $this->refine = explode(',', $row['labels']); | |
698 | + } | |
699 | + | |
700 | + # for refine + keyword search | |
701 | + function getRefineFromDB(){ | |
702 | + | |
703 | + $sql = "SELECT * FROM ".$this->db->prefix('newdb_list_refine')." WHERE user='".$this->uid."'"; | |
704 | + $rs = $this->db->query($sql); | |
705 | + $row = $this->db->fetchArray($rs); | |
706 | + | |
707 | + $labels = explode(',', $row['labels']); | |
708 | + $ret = array(); | |
709 | + for($i=0; $i<count($labels); $i++){ | |
710 | + if($labels[$i] != '') $ret[] = $labels[$i]; | |
711 | + } | |
712 | + return $ret; | |
713 | + } | |
714 | + | |
715 | + | |
716 | + ########################### | |
717 | + ## kws things | |
718 | + ########################### | |
719 | + | |
720 | + function setKwsFlg(){ | |
721 | + $this->kws_flg = 1; | |
722 | + } | |
723 | + | |
724 | + function setKLabels($kw, $andor, $notkws){ | |
725 | + if($andor != 'and' && $andor != 'or') $andor = 'and'; | |
726 | + | |
727 | + # not keywords | |
728 | + $notkws = explode(',', substr($notkws, 0, -1)); | |
729 | + $notnum = array(); | |
730 | + $notkw = ''; | |
731 | + for($i=0; $i<count($notkws); $i++){ | |
732 | + if(!isset($notnum[$notkws[$i]])) $notnum[$notkws[$i]] = 0; | |
733 | + $notnum[$notkws[$i]]++; | |
734 | + } | |
735 | + foreach($notnum as $k => $v){ | |
736 | + if(($v % 2)){ | |
737 | + if(!empty($notkw)) $notkw.=','; | |
738 | + $notkw.= $k; | |
739 | + } | |
740 | + } | |
741 | + | |
742 | + # save keyword | |
743 | + if($kw){ | |
744 | + $sql = "INSERT INTO ".$this->db->prefix('newdb_list_refine_option'); | |
745 | + $sql.= " VALUES('', '".$this->uid."', '".$andor.":".$kw."')"; | |
746 | + $rs = $this->db->queryF($sql); | |
747 | + } | |
748 | + if($notkw){ | |
749 | + $sql = "INSERT INTO ".$this->db->prefix('newdb_list_refine_option'); | |
750 | + $sql.= " VALUES('', '".$this->uid."', 'not:".$notkw."')"; | |
751 | + $rs = $this->db->queryF($sql); | |
752 | + } | |
753 | + | |
754 | + # kw search | |
755 | + $kw = explode(',', $kw); | |
756 | + $notkw = explode(',', $notkw); | |
757 | + | |
758 | + $kws = ''; $labels = array(); | |
759 | + for($i=0; $i<count($kw); $i++){ | |
760 | + if(empty($kw[$i])) continue; | |
761 | + if(!empty($kws)) $kws.= ' '.$andor.' '; | |
762 | + $kws.= "keyword like '%[".$kw[$i]."]%'"; | |
763 | + } | |
764 | + | |
765 | + $notkws = ''; | |
766 | + for($i=0; $i<count($notkw); $i++){ | |
767 | + if(empty($notkw[$i])) continue; | |
768 | + if(!empty($notkws)) $notkws.= ' AND '; | |
769 | + $notkws.= "keyword not like '%[".$notkw[$i]."]%'"; | |
770 | + } | |
771 | + | |
772 | + if($kws && $notkws){ | |
773 | + $kws = "(".$kws.") AND (".$notkws.")"; | |
774 | + }elseif(!$kws && $notkws){ | |
775 | + $kws = $notkws; | |
776 | + } | |
777 | + if($kws) $kws = " WHERE ".$kws; | |
778 | + | |
779 | + $sql = "SELECT * FROM ".$this->db->prefix('newdb_master').$kws; | |
780 | + $rs = $this->db->query($sql); | |
781 | + $num = $this->db->getRowsNum($rs); | |
782 | + if($num > 0){ | |
783 | + while($row = $this->db->fetchArray($rs)){ | |
784 | + $labels[] = $row['label_id']; | |
785 | + } | |
786 | + } | |
787 | + #echo $sql; | |
788 | + | |
789 | + # check refine list | |
790 | + $refines = $this->getRefineFromDB(); | |
791 | + $label_list = ''; | |
792 | + if(count($refines) > 0){ | |
793 | + for($i=0; $i<count($labels); $i++){ | |
794 | + if(in_array($labels[$i], $refines)){ | |
795 | + if(!empty($label_list)) $label_list.=','; | |
796 | + $label_list.= $labels[$i]; | |
797 | + } | |
798 | + } | |
799 | + }else{ | |
800 | + for($i=0; $i<count($labels); $i++){ | |
801 | + if(!empty($label_list)) $label_list.=','; | |
802 | + $label_list.= $labels[$i]; | |
803 | + } | |
804 | + } | |
805 | + | |
806 | + $sql = "DELETE FROM ".$this->db->prefix('newdb_list_refine'); | |
807 | + $sql.= " WHERE user='".$this->uid."'"; | |
808 | + $rs = $this->db->queryF($sql); | |
809 | + | |
810 | + $sql = "INSERT INTO ".$this->db->prefix('newdb_list_refine'); | |
811 | + $sql.= " VALUES('', '".$this->uid."', '".$label_list."')"; | |
812 | + $rs = $this->db->queryF($sql); | |
813 | + $this->setRefineFromDB(); | |
814 | + } | |
815 | + | |
816 | + | |
817 | + ########################### | |
818 | + ## general things | |
819 | + ########################### | |
820 | + | |
821 | + function __getAllLabels(){ | |
822 | + | |
823 | + $label_list = array(); | |
824 | + $sql = "SELECT name,type FROM ".$this->db->prefix('newdb_component_master'); | |
825 | + $sql.= " WHERE comp_id='".$this->sort_target."'"; | |
826 | + $rs = $this->db->query($sql); | |
827 | + | |
828 | + if($this->db->getRowsNum($rs) > 0){ | |
829 | + $row = $this->db->fetchArray($rs); | |
830 | + | |
831 | + # sort by system component | |
832 | + if($row['type'] == 1){ | |
833 | + | |
834 | + $sql = "SELECT label_id FROM ".$this->db->prefix('newdb_master')." ORDER BY "; | |
835 | + if($row['name'] == 'ID'){ | |
836 | + $sql.= "label_id"; | |
837 | + }elseif($row['name'] == 'Data Name'){ | |
838 | + $sql.= "label"; | |
839 | + }elseif($row['name'] == 'Author'){ | |
840 | + $sql.= "author"; | |
841 | + }elseif($row['name'] == 'Creation Date'){ | |
842 | + $sql.= "reg_date"; | |
843 | + }elseif($row['name'] == 'Views'){ | |
844 | + $sql.= "views"; | |
845 | + } | |
846 | + $sql.= " ".$this->sort_method; | |
847 | + $rs = $this->db->query($sql); | |
848 | + while($row = $this->db->fetchArray($rs)){ | |
849 | + $label_list[] = $row['label_id']; | |
850 | + } | |
851 | + | |
852 | + # sort by radio, check, text component | |
853 | + }else{ | |
854 | + | |
855 | + $sql = "SELECT label_id FROM ".$this->db->prefix('newdb_component'); | |
856 | + $sql.= " WHERE comp_id='".$this->sort_target."' ORDER BY value ".$this->sort_method.""; | |
857 | + $rs = $this->db->query($sql); | |
858 | + while($row = $this->db->fetchArray($rs)){ | |
859 | + if(!in_array($row['label_id'], $label_list)) $label_list[] = $row['label_id']; | |
860 | + } | |
861 | + | |
862 | + $sql = "SELECT label_id FROM ".$this->db->prefix('newdb_master')." ORDER BY label_id desc"; | |
863 | + $rs = $this->db->query($sql); | |
864 | + while($row = $this->db->fetchArray($rs)){ | |
865 | + if(!in_array($row['label_id'], $label_list)) $label_list[] = $row['label_id']; | |
866 | + } | |
867 | + } | |
868 | + }else{ | |
869 | + $this->error = 'No item found. (listmanager.php line '.__LINE__.')'; | |
870 | + } | |
871 | + | |
872 | + return $label_list; | |
873 | + } | |
874 | + | |
875 | + /** | |
876 | + * getLabels | |
877 | + * | |
878 | + * making label list for show | |
879 | + * @access public | |
880 | + * @return $return_list (label array) | |
881 | + */ | |
882 | + function getLabels($mode=0){ | |
883 | + | |
884 | + $label_list = $this->__getAllLabels(); | |
885 | + | |
886 | + # refine or text search | |
887 | + if($this->refine_flg || $this->tsearch_flg){ | |
888 | + $label_list2 = array(); | |
889 | + for($i=0; $i<count($label_list); $i++){ | |
890 | + if(in_array($label_list[$i], $this->refine)) | |
891 | + $label_list2[] = $label_list[$i]; | |
892 | + } | |
893 | + $label_list = array(); | |
894 | + for($i=0; $i<count($label_list2); $i++) | |
895 | + $label_list[] = $label_list2[$i]; | |
896 | + } | |
897 | + | |
898 | + # paging | |
899 | + $return_list = array(); | |
900 | + $start = ($this->page - 1) * $this->limit; | |
901 | + for($i=$start; $i<$start+$this->limit; $i++){ | |
902 | + if(count($label_list) <= $i) break; | |
903 | + $return_list[] = $label_list[$i]; | |
904 | + } | |
905 | + | |
906 | + # return refine labels for paging | |
907 | + if($mode){ | |
908 | + $return_list = $label_list; | |
909 | + } | |
910 | + | |
911 | + return $return_list; | |
912 | + } | |
913 | + | |
914 | + /** | |
915 | + * getValues | |
916 | + * | |
917 | + * replace template like {ID} into value | |
918 | + * @access public | |
919 | + * @param $label_id (label id) | |
920 | + * @param $label (label name) | |
921 | + * @param $author (author) | |
922 | + * @param $date (creation date) | |
923 | + * @return $template | |
924 | + */ | |
925 | + function getValues($label_id, $label, $author, $date, $views, $dname_flg=0){ | |
926 | + | |
927 | + # uname | |
928 | + $sql = "SELECT uname FROM ".$this->db->prefix('users')." WHERE uid='".$author."'"; | |
929 | + $rs = $this->db->query($sql); | |
930 | + $row = $this->db->fetchArray($rs); | |
931 | + $uname = $row['uname']; | |
932 | + if($dname_flg){ | |
933 | + $label = "<a href='detail.php?id=".$label_id."'>".$label."</a>"; | |
934 | + $label_id4show = $label_id; | |
935 | + }else{ | |
936 | + $label_id4show = "<a href='detail.php?id=".$label_id."'>".$label_id."</a>"; | |
937 | + } | |
938 | + $template = $this->template; | |
939 | + | |
940 | + if(strstr($template, '{ID}')){ | |
941 | + $replace_label = "<a href='detail.php?id=".$label_id."'>".$label_id4show."</a>"; | |
942 | + $template = str_replace('{ID}', $replace_label, $template); | |
943 | + } | |
944 | + if(strstr($template, '{Data Name}')){ | |
945 | + $replace_label = "<a href='detail.php?id=".$label_id."'>".$label."</a>"; | |
946 | + $template = str_replace('{Data Name}', $replace_label, $template); | |
947 | + } | |
948 | + if(strstr($template, '{Author}')){ | |
949 | + $replace_uname = "<a href='detail.php?id=".$label_id."'>".$uname."</a>"; | |
950 | + $template = str_replace('{Author}', $replace_uname, $template); | |
951 | + } | |
952 | + if(strstr($template, '{Creation Date}')){ | |
953 | + $replace_date = "<a href='detail.php?id=".$label_id."'>".date('Y-m-d', $date)."</a>"; | |
954 | + $template = str_replace('{Creation Date}', $replace_date, $template); | |
955 | + } | |
956 | + if(strstr($template, '{Views}')){ | |
957 | + $replace_views = "<a href='detail.php?id=".$label_id."'>".$views."</a>"; | |
958 | + $template = str_replace('{Views}', $replace_views, $template); | |
959 | + } | |
960 | + | |
961 | + # get component value | |
962 | + $sql = "SELECT * FROM ".$this->db->prefix('newdb_component_master'); | |
963 | + $rs = $this->db->query($sql); | |
964 | + while($row = $this->db->fetchArray($rs)){ | |
965 | + | |
966 | + if(strstr($template,'{'.$row['name'].'}')){ | |
967 | + $sql = "SELECT * FROM ".$this->db->prefix('newdb_component'); | |
968 | + $sql.= " WHERE label_id='".$label_id."' AND comp_id='".$row['comp_id']."'"; | |
969 | + $rs2 = $this->db->query($sql); | |
970 | + $value = ''; | |
971 | + while($row2 = $this->db->fetchArray($rs2)){ | |
972 | + if($value) $value.= ', '; | |
973 | + | |
974 | + if($row['type']=='2' || $row['type']=='3'){ | |
975 | + $row2['value'] = str_replace('{', '<img src="images/admin/', $row2['value']); | |
976 | + $row2['value'] = str_replace('}', '">', $row2['value']); | |
977 | + | |
978 | + }elseif($row['type']=='4'){ | |
979 | + if($row['textmax']=='0'){ | |
980 | + $row2['value'] = str_replace("\r\n", "\r", $row2['value']); | |
981 | + $row2['value'] = str_replace("\r", "\n", $row2['value']); | |
982 | + $row2['value'] = str_replace("\n", "<br>", $row2['value']); | |
983 | + } | |
984 | + } | |
985 | + $value.= $row2['value']; | |
986 | + } | |
987 | + $replace_value = "<a href='detail.php?id=".$label_id."'>".$value."</a>"; | |
988 | + $template = str_replace('{'.$row['name'].'}', $replace_value, $template); | |
989 | + } | |
990 | + } | |
991 | + | |
992 | + # clipboard | |
993 | + if(strstr($template, '{Ref ')){ | |
994 | + $st = 0; $end = 0; | |
995 | + for(;;){ | |
996 | + $st = strpos($template, '{Ref ', $end); | |
997 | + if($st > $end){ | |
998 | + $end = strpos($template, '}', $st); | |
999 | + $ref = substr($template, $st, ($end - $st + 1)); | |
1000 | + $suffix = str_replace('{Ref ', '', $ref); | |
1001 | + $suffix = str_replace('}', '', $suffix); | |
1002 | + | |
1003 | + $path=''; | |
1004 | + $sql = "SELECT * FROM ".$this->db->prefix('newdb_master')." WHERE label_id='".$label_id."'"; | |
1005 | + $rs = $this->db->query($sql); | |
1006 | + $row = $this->db->fetchArray($rs); | |
1007 | + $label = $row['label']; | |
1008 | + | |
1009 | + $sql = "SELECT * FROM ".$this->db->prefix('newdb_item'); | |
1010 | + $sql.= " WHERE label_id='".$label_id."' AND name like '%.".$suffix."' AND type='file'"; | |
1011 | + $rs = $this->db->query($sql); | |
1012 | + if($this->db->getRowsNum($rs)){ | |
1013 | + while($row = $this->db->fetchArray($rs)){ | |
1014 | + if(!empty($row['path'])){ | |
1015 | + $p = $row['path']."/"; | |
1016 | + }else{ | |
1017 | + $p = ''; | |
1018 | + } | |
1019 | + $tmp = "extract/".$label_id."/data/".$p.$row['name']; | |
1020 | + $path.= "<a style='cursor: pointer;' onClick=\"javascript:setClipboard('".$tmp."')\">".$row['name']."</a><br>"; | |
1021 | + } | |
1022 | + }else{ | |
1023 | + $path = ''; | |
1024 | + } | |
1025 | + $replace_path = "<a href='detail.php?id=".$label_id."'>".$path."</a>"; | |
1026 | + $template = str_replace($ref, $replace_path, $template); | |
1027 | + }else{ | |
1028 | + break; | |
1029 | + } | |
1030 | + } | |
1031 | + } | |
1032 | + | |
1033 | + # directories | |
1034 | + $sql = "SELECT * FROM ".$this->db->prefix('newdb_item'); | |
1035 | + $sql.= " WHERE type='dir' AND path='' AND label_id='".$label_id."' ORDER BY name"; | |
1036 | + | |
1037 | + if(strstr($template, '{Dirs}')){ | |
1038 | + $rs = $this->db->query($sql); | |
1039 | + $dirs = ''; | |
1040 | + while($row = $this->db->fetchArray($rs)){ | |
1041 | + if(!empty($dirs)) $dirs.=', '; | |
1042 | + $dirs.= substr($row['name'], 0, 3); | |
1043 | + } | |
1044 | + $replace_dirs = "<a href='detail.php?id=".$label_id."'>".$dirs."</a>"; | |
1045 | + $template = str_replace('{Dirs}', $replace_dirs, $template); | |
1046 | + } | |
1047 | + | |
1048 | + | |
1049 | + if(strstr($template, '{Dirs ')){ | |
1050 | + $st = 0; $end = 0; | |
1051 | + $st = strpos($template, '{Dirs ', $end); | |
1052 | + if($st > $end){ | |
1053 | + $end = strpos($template, '}', $st); | |
1054 | + $ref = substr($template, $st, ($end - $st + 1)); | |
1055 | + $num = str_replace('{Dirs ', '', $ref); | |
1056 | + $num = str_replace('}', '', $num); | |
1057 | + $num = intval($num); | |
1058 | + | |
1059 | + $rs = $this->db->query($sql); | |
1060 | + $dirs = ''; | |
1061 | + while($row = $this->db->fetchArray($rs)){ | |
1062 | + if(!empty($dirs)) $dirs.=', '; | |
1063 | + $dirs.= substr($row['name'], 0, $num); | |
1064 | + } | |
1065 | + $replace_dirs = "<a href='detail.php?id=".$label_id."'>".$dirs."</a>"; | |
1066 | + $template = str_replace('{Dirs '.$num.'}', $replace_dirs, $template); | |
1067 | + } | |
1068 | + } | |
1069 | + | |
1070 | + return $template; | |
1071 | + } | |
1072 | + | |
1073 | + function getListlink(){ | |
1074 | + | |
1075 | + $ret_value = ''; | |
1076 | + $sql = "SELECT * FROM ".$this->db->prefix('newdb_list')." WHERE onoff='0' ORDER BY sort"; | |
1077 | + $rs = $this->db->query($sql); | |
1078 | + while($row = $this->db->fetchArray($rs)){ | |
1079 | + $list_id = $row['list_id']; | |
1080 | + $name = $row['name']; | |
1081 | + | |
1082 | + $href = "id=".$list_id; | |
1083 | + $href.= "&n=".$this->limit; | |
1084 | + $href.= "&sort=".$this->sort_target; | |
1085 | + $href.= "&sort_method=".$this->sort_method; | |
1086 | + if($this->refine_flg){ | |
1087 | + $href.= "&refine=usedb"; | |
1088 | + $href.= "&user=".$this->uid; | |
1089 | + } | |
1090 | + if($this->type == 2) $href.= "&size=".$this->thumb_active_size[0]; | |
1091 | + $href.= "&item=".$this->item; | |
1092 | + | |
1093 | + if(!empty($ret_value)) $ret_value.= ' | '; | |
1094 | + if($list_id == $this->list_id){ | |
1095 | + $ret_value.= $name; | |
1096 | + }else{ | |
1097 | + $ret_value.= "<a href='list.php?".$href."'>".$name."</a>"; | |
1098 | + } | |
1099 | + } | |
1100 | + return $ret_value; | |
1101 | + } | |
1102 | + | |
1103 | + function error(){ | |
1104 | + return $this->error; | |
1105 | + } | |
1106 | + | |
1107 | +} | |
1108 | +?> |