Repository navigation
Expand file tree
/
Copy pathFE_CRUD.php
More file actions
376 lines (356 loc) · 15.8 KB
/
Copy pathFE_CRUD.php
File metadata and controls
376 lines (356 loc) · 15.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
<?php
includeOnce('MysqlUtilities.class.php');
includeOnce('Validate.class.php');
class gitFeCrudOps extends Validate {
/* validate method for provided objects */
public function validateDBCompatibility($Column='',$object){
$ERROR = false;
if($object->getKeyValue($Column) == NULL and $object->getKeyValue($Column,"_IS_NULLABLE") == "NO"){
$ERROR = true;
}else if($object->getKeyValue($Column,"_DATA_TYPE") == "varchar" && $object->getKeyValue($Column,"_DATA_TYPE") == "char" && $object->getKeyValue($Column,"_DATA_TYPE") == "text"){
if($object->getKeyValue($Column,"_CHARACTER_MAXIMUM_LENGTH") > strlen($object->getKeyValue($Column))){
$ERROR = true;
}
if($object->getKeyValue($Column,"_CHARACTER_MINIMUM_LENGTH") !=null && $object->getKeyValue($Column,"_CHARACTER_MINIMUM_LENGTH") >0){
if($object->getKeyValue($Column,"_CHARACTER_MINIMUM_LENGTH") < strlen($object->getKeyValue($Column))){
$ERROR = true;
}
}
}else if($object->getKeyValue($Column,"_DATA_TYPE") == "int" && $object->getKeyValue($Column,"_DATA_TYPE") == "bigint"){
if (!(ereg("^([0-9])+$", $object->getKeyValue($Column)))){
$ERROR = true;
}
if($object->getKeyValue($Column,"_NUMERIC_PRECISION") > strlen($object->getKeyValue($Column))){
$ERROR = true;
}
if($object->getKeyValue($Column,"_CHARACTER_MINIMUM_LENGTH") !=null && $object->getKeyValue($Column,"_CHARACTER_MINIMUM_LENGTH") >0){
if($object->getKeyValue($Column,"_CHARACTER_MINIMUM_LENGTH") < strlen($object->getKeyValue($Column))){
$ERROR = true;
}
}
}
return $ERROR;
}
/* search method for provided objects */
public function searchOperation($SelectColumns = '*' , $SearchTerm='',$object,$pagingData=true,$data4json = false){
global $user_details;
$Config = new get_config();
$SearchInView =false;
if($SelectColumns == '' || $SelectColumns == '*'){
$SelectColumns = $object->ColumnArray;}
$sql_statement = 'SELECT '.$SelectColumns.' FROM '.$object->TableName.'_view';
$MySQLObject = new MysqlUtilities($object->DatabaseName,$object->HtmlDebug,$object->Debug);
$sql_result = $MySQLObject->Query($sql_statement);// or die(mysql_error());//$MySQLObject->ShowError($sql_statement);
if($line = @mysql_fetch_array($sql_result)){
$object->TableName = $object->TableName."_view";
$SearchInView =true;
}
$sql_statement = 'SELECT '.$SelectColumns.' FROM '.$object->TableName.' ';
$sql_statementPG = 'SELECT count('.$object->MAINCOLUMN.') as CNT FROM '.$object->TableName.' ';
$sql_statementSearch = 'SELECT '.$SelectColumns.' FROM '.$object->TableName.' ';
$sql_statement = '';
$ColumnList = explode(',', $object->SearchArray);
if($SearchTerm!=''){
$sql_statement .=' WHERE ';
$addOR = false;
for($i=0;$i< sizeof($ColumnList);++$i){
if(parent::isNum($SearchTerm)){
if($this->getKeyValue($ColumnList[$i],"_DATA_TYPE",$object) == "bigint" || $this->getKeyValue($ColumnList[$i],"_DATA_TYPE",$object) == "int" || $this->getKeyValue($ColumnList[$i],"_DATA_TYPE",$object) == "float"){
if($addOR){$sql_statement .=" || ";}
$sql_statement .=" ".$ColumnList[$i] ." = $SearchTerm ";
$addOR = true;
}elseif($this->getKeyValue($ColumnList[$i],"_DATA_TYPE",$object) == "varchar" || $this->getKeyValue($ColumnList[$i],"_DATA_TYPE",$object) == "char" || $this->getKeyValue($ColumnList[$i],"_DATA_TYPE",$object) == "text"){
if($addOR){$sql_statement .=" || ";}
$sql_statement .=" ".$ColumnList[$i] ." like \"%$SearchTerm%\"";
$addOR = true;
}else if($this->getKeyValue($ColumnList[$i],"_DATA_TYPE",$object) == "timestamp" || $this->getKeyValue($ColumnList[$i],"_DATA_TYPE",$object) == "date"){
}else if($this->getKeyValue($ColumnList[$i],"_DATA_TYPE",$object) == "datetime" || $this->getKeyValue($ColumnList[$i],"_DATA_TYPE",$object) == "date"){
}
}else{
if($SearchInView){
if($this->getKeyValue($ColumnList[$i],"_DATA_TYPE",$object) == "bigint" ){
if($addOR){$sql_statement .=" || ";}
$sql_statement .=" ".$ColumnList[$i] ." like \"%$SearchTerm%\"";
$addOR = true;
}
}
if($this->getKeyValue($ColumnList[$i],"_DATA_TYPE",$object) == "varchar" || $this->getKeyValue($ColumnList[$i],"_DATA_TYPE",$object) == "char" || $this->getKeyValue($ColumnList[$i],"_DATA_TYPE",$object) == "text"){
if($addOR){$sql_statement .=" || ";}
$sql_statement .=" ".$ColumnList[$i] ." like \"%$SearchTerm%\"";
$addOR = true;
}else if($this->getKeyValue($ColumnList[$i],"_DATA_TYPE",$object) == "timestamp" || $this->getKeyValue($ColumnList[$i],"_DATA_TYPE",$object) == "date"){
}else if($this->getKeyValue($ColumnList[$i],"_DATA_TYPE",$object) == "datetime" || $this->getKeyValue($ColumnList[$i],"_DATA_TYPE",$object) == "date"){
}//else
}
}
}
$StartFrom = 0;
$MySQLObject = new MysqlUtilities($object->DatabaseName,$object->HtmlDebug,$object->Debug);
$sql_statementPG .= $sql_statement;
$sql_result = mysql_query($sql_statementPG) or $MySQLObject->ShowError($sql_statementPG);
$totalRows = mysql_fetch_array($sql_result);
$totalRows = $totalRows['CNT'];
$totalPages= $totalRows/$Config->max_Page_Size;
if(($totalRows%$Config->max_Page_Size) > 0){
$totalPages++;
}
$StartFrom = 0;
if(getValueGPC('pageNumber') != "")
$StartFrom = ((getValueGPC('pageNumber')*$Config->max_Page_Size)-$Config->max_Page_Size);
else{
$_GET['pageNumber'] = 1;
}
if(isset($_REQUEST['SQLORDERBY'])){
$sql_statement .= " order by ".$_REQUEST['SQLORDERBY']." ";
if(isset($_REQUEST['SQLORDERBYTYPE'])){
$sql_statement .= $_REQUEST["SQLORDERBYTYPE"]." ";
}else{/*Do Nothing*/}
}else{
$sql_statement .= " order by $ColumnList[0] desc ";
}
if(getValueGPC('print_report')=="true"){
}else{
$sql_statement .= " limit $StartFrom, $Config->max_Page_Size ";
}
//echo $sql_statement;
//$sql_result = $MySQLObject->Query($sql_statement) or $MySQLObject->ShowError($sql_statement);
$MySQLObject = new MysqlUtilities($object->DatabaseName,$object->HtmlDebug,$object->Debug);
$sql_statementSearch.=$sql_statement;
$sql_result = $MySQLObject->Query($sql_statementSearch) or $MySQLObject->ShowError($sql_statementSearch);
$totalRows = $MySQLObject->last_found_count;//mysql_num_rows($sql_result);
//$totalPages= $totalRows/$Config->max_Page_Size;
//if(($totalRows%$Config->max_Page_Size) > 0){
// $totalPages++;
//}
//echo $totalPages;
if($totalPages >= 2){
if(!$data4json){
if(getValueGPC('print_report')=="true" || getValueGPC('print_page')=="true"){
if(getValueGPC('print_report_screen')==''){
echo $printCode="<script>window.print();</script>";
}
$pagingCode="";
}else{
if(getValueGPC('Search')!=""){
echo $pagingCode = $this->pagingCode($totalPages,"Search=$SearchTerm");
}else{
echo $pagingCode = $this->pagingCode($totalPages,"");
}
}
}
}
//}
$i = 1;
$Array = array();
$ArrayJson = array();
$SelfProperties=$this->getObjectAttributes($object);
while($line = mysql_fetch_array($sql_result)) { //$MySQLObject->Row())
$ReceivedProperties = $line;
// print_r($ReceivedProperties);
$j=0;
foreach($SelfProperties as $key => $value) { //Each variable is compared to variables of the object passed
foreach($ReceivedProperties as $newkey => $newvalue){
if(strtoupper($key) == strtoupper($newkey)) { //if a match is found, this object's vars are populated;
$Array[0][$j] = $key;
$ArrayJson[0][$key]=$key;
$Array[$i][$j] = trim($newvalue);
$ArrayJson[$i][$key]=trim($newvalue);
//echo $key." - ".$newvalue."<br>";
++$j;
//break;
}
}
}
$i++;
}
if($i < 1){
echo "No Result Found";
$Array['FE_TYPE'] = 'MESSAGE';
$Array['Result'] = "No Result Data Available";
if($isApiCall){
}else{
echo $Array[1]['Result'];
}
}
if($data4json){
$Array = array();
$_a = sizeof($Array);
$Array[$_a]['FE_PAGE_COUNT'] = floor($totalPages);
$Array[$_a]['FE_CURRENT_PAGE'] = getValueGPC('pageNumber');
$_a = $Array;
$Array = array();
$Array['FE_TYPE'] = 'TABLE-DATA';
$Array['DATA'] = $ArrayJson;
$Array['CONFIG'] = $_a;
}
return $Array;
}
/* Input method for provided objects */
public function insertIntoTable($table='',$object){
$mainIdColumn = "$"."thisOutput = $"."object->get".$object->MAINCOLUMN."();";
eval($mainIdColumn);
if($thisOutput == ""){
$MySQLObject = new MysqlUtilities($object->DatabaseName,$object->HtmlDebug,$object->Debug);
$SelfProperties=get_object_vars($object);
$SelfProperties = array_merge($this->getObjectAttributes($object),$SelfProperties);
$MySQLObject->AddtoDB($object->TableName,$SelfProperties);
if($thisOutput == ""){
eval ("$"."object->set".$object->MAINCOLUMN."('".$MySQLObject->GetLastInsertID()."');");
}
$MySQLObject->Close();
}
return true;
}
/* update method for provided objects */
public function updateTableFromPostedData($object){
//print_r($_POST);
//var_dump($object);
//eval("$"."object->set".$object->MAINCOLUMN."(".$_POST[$object->MAINCOLUMN].");");
//echo $mainIdColumn."---".$thisOutput."#";
$mainIdColumn = "$"."thisOutput = $"."object->get".$object->MAINCOLUMN."();";
eval($mainIdColumn);
$Array = array();
if($thisOutput != ""){
//echo "updateTableFromPostedData";
$MySQLObject = new MysqlUtilities($object->DatabaseName,$object->HtmlDebug,$object->Debug);
$SelfProperties=$this->getObjectAttributes($object);
//print_r($SelfProperties);
//print_r($_POST);
$profileColumns=$MySQLObject->GetColumns($object->TableName);
//print_r($profileColumns);
foreach($SelfProperties as $key => $value) { //Each variable is compared to variables of the object passed
//echo $key.'-'.$value."-----\n";
if(isset($value) && in_array(strtoupper($key),$profileColumns)){
$Array[strtoupper($key)]=$value;
}
}
//print_r($Array);die();
$where_clause = $object->MAINCOLUMN ." = ".$thisOutput;
$MySQLObject->UpdateDB($object->TableName,$Array,$where_clause);
}
}
/* populate From ID method for provided objects */
public function populateFromID($SelectColumns='*' , $Condition='',$object){
$ExecuteQuery=true;
/*if ($SelectColumns == '*' && !$AllVariablesSet)
{
$this->setAllVariablesSet(true);
$ExecuteQuery=true;
}
elseif($SelectColumns == '*' && $AllVariablesSet)
$ExecuteQuery=false;/**/
$mainIdColumn = "$"."thisOutput = $"."object->get".$object->MAINCOLUMN."();";
eval($mainIdColumn);
if($ExecuteQuery){
$sql_statement = 'SELECT '.$SelectColumns.' FROM '.$object->TableName.' WHERE ID='.$thisOutput;
if($Condition!='')
$sql_statement .= ' and '.$Condition;
$MySQLObject = new MysqlUtilities('',$object->HtmlDebug,$object->Debug);
//echo $sql_statement;
$sql_result = $MySQLObject->Query($sql_statement) or $MySQLObject->ShowError($sql_statement);
if($sql_row = $MySQLObject->Row()){
$object->setAllProperties($sql_row);
return true;
}
else
return false;
}
setIsModifyTrue();
}
/* delete method for provided objects */
public function deleteDetails($object){
//var_dump($object);
$mainIdColumn = "$"."thisOutput = $"."object->get".$object->MAINCOLUMN."();";
eval($mainIdColumn);
//echo $thisOutput;
if( $thisOutput != "" ){
$sql = "DELETE FROM $object->TableName where ". $object->MAINCOLUMN ." =".$thisOutput;
$MySQLObject = new MysqlUtilities($this->DatabaseName,$object->HtmlDebug,$object->Debug);
$MySQLObject->Query($sql) or $MySQLObject->ShowError($sql);
$MySQLObject->Close();
}
}
private function getObjectVariableValue($string="",$object){
$mainIdColumn = "$"."thisOutput = $"."object->get".$string."();";
eval($mainIdColumn);
return $thisOutput;
}
public function getKeyValue($Column,$String='',$object){
$KEY = $Column.$String;
$mainIdColumn = "$"."thisOutput = $"."object->getKeyValue($"."Column,$"."String);";
eval($mainIdColumn);
return $thisOutput;
}
public function getObjectAttributes($object){
//echo $object->ColumnArray;
$elements = explode(',',$object->ColumnArray);
$selfArray;
foreach($elements as $key => $value){
$thisColumn = "$"."thisOutput = $"."object->get".$value."();";
try{
if(method_exists($object,"get".$value)){
eval($thisColumn);
$selfArray[$value] = $thisOutput;
}
}catch(Exception $e){}
}
//print_r($selfArray);
return $selfArray;
}
public function defaultOperation($object,$_Array){
global $PageName;
if(isset($_Array['Message'])){
echo $_Array['Message']."<br>";
}
if(is_array(@$_Array['OperationString'])){
foreach($_Array['OperationString'] as $key => $value){
eval($value);
}
}
if(isset($_Array['DefaultOperationString']) && $_Array['DefaultOperationString'] == "SearchListEdit"){
echo generateTableEditLink($object->searchOperation($object->SearchArray,getValueGPC('Search')),0,'Edit',0,$PageName);
}else if(isset($_Array['DefaultOperationString']) && $_Array['DefaultOperationString'] == "SearchList"){
echo generateTable($object->searchOperation($object->SearchArray,getValueGPC('Search')),0,'Edit',0,$PageName);
}else if(isset($_Array['DefaultOperationString'])){
eval($_Array['DefaultOperationString']);
}else{
echo generateTableEditLink($object->searchOperation($object->SearchArray,getValueGPC('Search')),0,'Edit',0,$PageName);
}
}
public function pagingCode($totalPages,$PARAMS){
global $PageName;
$SQLORDERBY = "";
if(isset($_GET['SQLORDERBY'])){
$SQLORDERBY = "&SQLORDERBY=".$_REQUEST['SQLORDERBY'];
if($_GET['SQLORDERBYTYPE'] == "desc"){
$SQLORDERBY .= "&SQLORDERBYTYPE=".$_REQUEST['SQLORDERBYTYPE'];
}else{
if(isset($_REQUEST['SQLORDERBYTYPE'])){
$SQLORDERBY .= "&SQLORDERBYTYPE=".$_REQUEST['SQLORDERBYTYPE'];
}else{
$SQLORDERBY .= "&SQLORDERBYTYPE=asc";
}
}
}else{
}
$TillPageNumber = ((getValueGPC('pageNumber')+5)> $totalPages) ? $totalPages :(getValueGPC('pageNumber')+5);
$FromPageNumber = ((getValueGPC('pageNumber')-5)> 0) ? (getValueGPC('pageNumber')-5) :1;
$pagingCode ="";
if(getValueGPC('pageNumber')>1)
$pagingCode.=" <a href=$PageName?checksum=".getValueGPC('checksum')."&$PARAMS$SQLORDERBY&pageNumber=".(getValueGPC('pageNumber')-1)." onclick=\"javascript:showData('$PageName','".getValueGPC('checksum')."&$PARAMS$SQLORDERBY&pageNumber=".(getValueGPC('pageNumber')-1)."');return false;\"><PREV</a> | ";
for($i=$FromPageNumber;$i<=$TillPageNumber;++$i){
$pagingCode.="<a href=$PageName?checksum=".getValueGPC('checksum')."&$PARAMS$SQLORDERBY&pageNumber=$i onclick=\"javascript:showData('$PageName','".getValueGPC('checksum')."&$PARAMS$SQLORDERBY&pageNumber=$i');return false;
\">";
if( getValueGPC('pageNumber') == $i ) {
$pagingCode.="<b><u>$i</b></u>";
}else{ $pagingCode.="$i"; }
$pagingCode.="</a> | ";
}
if((getValueGPC('pageNumber')+1)<=$totalPages)
$pagingCode.="<a href=$PageName?checksum=".getValueGPC('checksum')."&$PARAMS$SQLORDERBY&pageNumber=".(getValueGPC('pageNumber')+1)." onclick=\"javascript:showData('$PageName','".getValueGPC('checksum')."&$PARAMS$SQLORDERBY&pageNumber=".(getValueGPC('pageNumber')+1)."');return false;\">NEXT></a> ";
//$pagingCode .= "| <a href=\"$PageName?checksum=".getValueGPC('checksum')."&print_report=true&$PARAMS$SQLORDERBY\" target=\"_ReportPrint\">Print Report</a> ";
$pagingCode .= " | <a href=\"$PageName?checksum=".getValueGPC('checksum')."&print_page=true&$PARAMS$SQLORDERBY&pageNumber=".(getValueGPC('pageNumber'))."\" target=\"_ReportPrint\">Print Page</a>";
return $pagingCode;
}
}
?>