forked from J2paper/iModule
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathModuleDatabase.class.php
More file actions
99 lines (83 loc) · 3.6 KB
/
ModuleDatabase.class.php
File metadata and controls
99 lines (83 loc) · 3.6 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
<?php
class ModuleDatabase extends Module {
public $mDB;
public $table;
public $userfile;
public $thumbnail;
function __construct() {
parent::__construct('database');
$this->mDB = &DB::instance();
$this->table['table'] = $_ENV['code'].'_database_table';
$this->table['file'] = $_ENV['code'].'_database_file_table';
$this->userfile = '/database';
$this->thumbnail = '/database/thumbnail';
}
function GetTable($idx=0,$table='') {
if ($idx == 0) {
$data = $this->mDB->DBfetch($this->table['table'],'*',"where `name`='$table'");
} else {
$data = $this->mDB->DBfetch($this->table['table'],'*',"where `idx`=$idx");
}
$field = unserialize($data['field']);
$data['field'] = array();
for ($i=0, $loop=sizeof($field);$i<$loop;$i++) {
$data['field'][$field[$i]['name']] = $field[$i];
}
return $data;
}
function DBfetch($table,$selector,$find='',$order='',$limit='') {
$table = $this->GetTable(0,$table);
$data = $this->mDB->DBfetch($table['name'],$selector,$find,$order,$limit,$table['database']);
if (is_array($data) == true) {
foreach ($data as $field=>$value) {
if ($table['field'][$field]['type'] == 'FILE') {
if ($value && $value != '0') {
$file = $this->mDB->DBfetch($this->table['file'],array('idx','filename','filepath','filesize','filetype','hit'),"where `idx`=$value");
$file['filepath'] = $_ENV['userfilePath'].$this->userfile.$file['filepath'];
$file['filedir'] = $file['filetype'] == 'IMG' ? $this->moduleDir.'/exec/ShowImage.do.php?idx='.$file['idx'].'&tno='.$table['idx'] : $_ENV['userfileDir'].$this->userfile.$file['filepath'];
$file['download'] = $this->moduleDir.'/exec/FileDownload.do.php?idx='.$file['idx'].'&tno='.$table['idx'];
$data[$field] = $file;
} else {
$data[$field] = array('idx'=>0,'filename'=>'','filepath'=>'','filedir'=>'','filesize'=>0,'filetype'=>'ETC','hit'=>0,'download'=>'');
}
} else {
if ($table['field'][$field]['type'] == 'HTML') {
$value = '<div class="smartOutput">'.str_replace('{$moduleDir}',$this->moduleDir,$value).'</div>';
}
$data[$field] = $value;
}
}
}
return $data;
}
function DBfetchs($table,$selector,$find='',$order='',$limit='') {
$table = $this->GetTable(0,$table);
$data = $this->mDB->DBfetchs($table['name'],$selector,$find,$order,$limit,$table['database']);
for ($i=0, $loop=sizeof($data);$i<$loop;$i++) {
foreach ($data[$i] as $field=>$value) {
if ($table['field'][$field]['type'] == 'FILE') {
if ($value && $value != '0') {
$file = $this->mDB->DBfetch($this->table['file'],array('idx','filename','filepath','filesize','filetype','hit'),"where `idx`=$value");
$file['filepath'] = $_ENV['userfilePath'].$this->userfile.$file['filepath'];
$file['filedir'] = $file['filetype'] == 'IMG' ? $this->moduleDir.'/exec/ShowImage.do.php?idx='.$file['idx'].'&tno='.$table['idx'] : $_ENV['userfileDir'].$this->userfile.$file['filepath'];
$file['download'] = $this->moduleDir.'/exec/FileDownload.do.php?idx='.$file['idx'].'&tno='.$table['idx'];
$data[$i][$field] = $file;
} else {
$data[$i][$field] = array('idx'=>0,'filename'=>'','filepath'=>'','filedir'=>'','filesize'=>0,'filetype'=>'ETC','hit'=>0,'download'=>'');
}
} else {
if ($table['field'][$field]['type'] == 'HTML') {
$value = '<div class="smartOutput">'.str_replace('{$moduleDir}',$this->moduleDir,$value).'</div>';
}
$data[$i][$field] = $value;
}
}
}
return $data;
}
function DBcount($table,$find='') {
$table = $this->GetTable(0,$table);
return $this->mDB->DBcount($table['name'],$find,$table['database']);
}
}
?>