-
Notifications
You must be signed in to change notification settings - Fork 0
/
DocumentEdit.class.php
157 lines (156 loc) · 5.23 KB
/
DocumentEdit.class.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
<?php
/*
Module: print form by array from databases;
Author: Theadore Lee;
Create @ 2014.12.20;
*/
class documentedit{
//整理include
private function RecoIncloud($displayArray){
foreach ($displayArray as $key => $value) {
if($displayArray[$key]['type'] == 'text' || $displayArray[$key]['type'] == 'file' || $displayArray[$key]['type'] == 'hidden' || $displayArray[$key]['type'] == 'password'){
$include_value[$key] = 'input';
}
else{
$include_value[$key] = $displayArray[$key]['type'];
}
}
return $include_value;
}
//整理主数组
private function RecoMainArray($displayArray){
$db = new db_pdo();
foreach ($displayArray as $key => $value) {
$MainArray[$key]['title'] = $displayArray[$key]['title'];
$MainArray[$key]['type'] = $displayArray[$key]['type'];
if( $displayArray[$key]['type'] == 'select' || $displayArray[$key]['type'] == 'radio' || $displayArray[$key]['type'] == 'checkbox'){
$MainArray[$key]['value'] = explode(",", $displayArray[$key]['value']);
$MainArray[$key]['output'] = explode(",", $displayArray[$key]['output']);
}
elseif ($displayArray[$key]['type'] == 'checkfield') {
$dbinfoVal = explode(",", $displayArray[$key]['value'] );
$dbinfoOut = explode(",", $displayArray[$key]['output'] );
$sqlVal = "select ".$dbinfoVal[1]." from ".$dbinfoVal[0];
$sqlOut = "select ".$dbinfoOut[1]." from ".$dbinfoOut[0];
$reVal = $db->query($sqlVal);
foreach ($reVal as $valkey => $valvalue) {
$val[$valkey] = $valvalue[$dbinfoVal[1]];
}
$reOut = $db->query($sqlOut);
foreach ($reOut as $outkey => $outvalue) {
$out[$outkey] = $outvalue[$dbinfoOut[1]];
}
$MainArray[$key]['value'] = $val;
$MainArray[$key]['output'] = $out;
}
else{
$MainArray[$key]['value'] = $displayArray[$key]['value'];
$MainArray[$key]['output'] = $displayArray[$key]['output'];
}
$MainArray[$key]['class'] = $displayArray[$key]['class'];
$MainArray[$key]['input_name'] = $displayArray[$key]['id'];
}
return $MainArray;
}
//整理数据库名
private function RecoDBName($displayArray){
foreach ($displayArray as $key => $value) {
$DBname = $displayArray[$key]['table_id'];
}
return $DBname;
}
//整理字段名
private function RecoColumnsName($displayArray){
foreach ($displayArray as $key => $value) {
$ColumnsName[$key] = $displayArray[$key]['field_name'];
}
return $ColumnsName;
}
//整理编辑值
private function RecoEditValue($DBName,$edit_value,$ColumnsName,$include_value){
if($edit_value!= ""){
$edit = $this->GainArray($DBName,$edit_value,'1');
foreach ($ColumnsName as $key => $value) {
foreach ($edit[0] as $Edkey => $Edvalue) {
if ($Edkey == $value) {
$editArray[$key] = $Edvalue;
}
}
}
foreach ($include_value as $key => $value) {
if ($value == 'checkbox' || $value == 'checkfield') {
$editArray[$key] = explode(",", $editArray[$key]);
}
}
}
else{
foreach ($ColumnsName as $key => $value) {
$editArray[$key] = "";
}
}
return $editArray;
}
//生成数组
private function JointArray($displayArray,$edit_value){
/*-----------------------为打印表单生成数组-----------------------*/
//调用DBname方法
$DBName = $this->RecoDBName($displayArray);
//调用include方法
$include_value = $this->RecoIncloud($displayArray);
//调用MainArray方法
$MainArray = $this->RecoMainArray($displayArray);
//调用RecoColumnsName方法
$ColumnsName = $this->RecoColumnsName($displayArray);
//传入值,调用RecoEditValue方法
$editArray = $this->RecoEditValue($DBName,$edit_value,$ColumnsName,$include_value);
$FormArray['include'] = $include_value;
$FormArray['main'] = $MainArray;
$FormArray['edit'] = $editArray;
/*-----------------------为session传值生成数组-----------------------*/
foreach ($MainArray as $key => $value) {
foreach ($value as $Vkey => $Vvalue) {
$input_name[$key] = $value['input_name'];
}
}
if ($edit_value != "") {
$re_Array['edit'] = $edit_value;
}
else{
$re_Array['edit'] = "";
}
$re_Array['DBName'] = $DBName;
$re_Array['input'] = $input_name;
$re_Array['Columns'] = $ColumnsName;
$re_Array['include'] = $include_value;
//开启session
session_start();
$_SESSION['Docum_ReArray'] = $re_Array;
return $FormArray;
}
//从数据库中获取数组
private function GainArray($table_id,$limits,$jud){
$db = new db_pdo();
if ($jud == '0') {
$sql = "select * from form_model where table_id = :table_id and edit_limits >= :limits_start and edit_limits <= :limits_end";
$limit = explode(",", $limits);
$a = array("table_id" => $table_id,"limits_start" => $limit[0],"limits_end" => $limit[1]);
}
elseif ($jud == '1') {
$sql = "select * from ".$table_id." where id = :limits";
$a = array("limits" => $limits);
}
$re = $db->query($sql,$a);
return $re;
}
//接收table_id,limits,edit_value生成表单打印数组
public function DisplayForm($table_id,$limits,$edit_value){
$displayArray = $this->GainArray($table_id,$limits,'0');
$FinalArray = $this->JointArray($displayArray,$edit_value);
return $FinalArray;
}
public function trash($tableName,$id,$status){
$db = new db_pdo();
$db->query("UPDATE ".$tableName." SET status = ".$status." WHERE id = ?", $id);
}
}
?>