-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlookupsuggest.php
150 lines (115 loc) · 4.34 KB
/
lookupsuggest.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
<?php
@ini_set("display_errors","1");
@ini_set("display_startup_errors","1");
require_once("include/dbcommon.php");
require_once( getabspath( "classes/controls/Control.php" ) );
require_once( getabspath( "classes/controls/LookupField.php" ) );
header("Expires: Thu, 01 Jan 1970 00:00:01 GMT");
$shortTable = postvalue("table");
$table = GetTableByShort( $shortTable );
if( !$table )
exit(0);
$pageType = postvalue("pageType");
$pageName = postvalue("page");
$field = postvalue('searchField');
if( !Security::userHasFieldPermissions( $table, $field, $pageType, $pageName, true ) )
return;
$pSet = new ProjectSettings( $table, $pageType, $pageName );
// if suggest for dashboard search
if( $pSet->getEntityType() == titDASHBOARD )
{
$dashboard = $table;
$dashFields = $pSet->getDashboardSearchFields();
$table = $dashFields[ $field ][0]["table"];
$field = $dashFields[$field][0]["field"];
$pSet = new ProjectSettings($table, $pageType, $pageName, $dashboard );
}
$cipherer = new RunnerCipherer($table);
$masterTable = postvalue('masterTable');
if ( $masterTable != "" && isset($_SESSION[ $masterTable . "_masterRecordData" ]) )
{
$contextParams["masterData"] = $_SESSION[ $masterTable . "_masterRecordData" ];
}
$contextParams["data"] = my_json_decode( postvalue('data') );
RunnerContext::push( new RunnerContextItem( $pageType, $contextParams));
$isExistParent = postvalue('isExistParent');
$searchByLinkField = postvalue('searchByLinkField');
$parentCtrlsData = my_json_decode( postvalue('parentCtrlsData') );
$value = postvalue('searchFor');
$values = postvalue('multiselection') ? splitLookupValues($value) : array($value);
$lookupField = "";
if( $pSet->getEditFormat($field) == EDIT_FORMAT_LOOKUP_WIZARD )
{
$LookupType = $pSet->getLookupType($field);
if( $LookupType == LT_LOOKUPTABLE || $LookupType == LT_QUERY )
{
$lookupField = $field;
}
}
if( !$lookupField )
{
$respObj = array('success' => false, 'data' => array());
echo printJSON($respObj);
exit();
}
$lookupTable = $pSet->getLookupTable($lookupField);
$lookupPSet = null;
if( $pSet->getLookupType($field) == LT_QUERY )
$lookupPSet = new ProjectSettings( $lookupTable );
$linkFieldName = $pSet->getLinkField($lookupField);
$displayFieldName = $pSet->getDisplayField( $field );
$linkAndDisplaySame = $displayFieldName == $linkFieldName;
// create DsCommand
$dcDisplay = LookupField::makeLookupDataCommand( $field, $pSet, $parentCtrlsData, $value, true, $searchByLinkField, true, $searchByLinkField );
$dc = $dcDisplay["dc"];
$displayFieldAlias = $dcDisplay["displayField"];
$operation = $ajaxSearchStartsWith ? dsopSTART : dsopCONTAIN;
if( !$searchByLinkField ) {
$displayFieldCondition = $pSet->getCustomDisplay( $field )
? DataCondition::SQLIs( $displayFieldName, $operation, $value )
: DataCondition::FieldIs( $displayFieldName, $operation, $value );
// add display field filter
$dc->filter = DataCondition::_And( array(
$dc->filter,
$displayFieldCondition
) );
}
$dc->reccount = 200;
$dataSource = getLookupDataSource( $lookupField, $pSet );
$qResult = $dataSource->getList( $dc );
if( !$qResult ) {
showError( $dataSource->lastError() );
}
$multiselect = $pSet->multiSelect( $lookupField );
$linkField = $pSet->getLinkField( $field );
$response = array();
while( $data = $qResult->fetchAssoc() )
{
if( $LookupType == LT_QUERY && $pSet->isLookupUnique($lookupField) )
{
if( !isset($uniqueArray) )
$uniqueArray = array();
if( in_array($data[ $displayFieldAlias ], $uniqueArray) )
continue;
$uniqueArray[] = $data[ $displayFieldAlias ];
}
$data[ $linkField ] = $cipherer->DecryptField($lookupField, $data[ $linkField ]);
if( $LookupType == LT_QUERY )
$data[ $displayFieldAlias ] = $cipherer->DecryptField($displayFieldName, $data[ $displayFieldAlias ]);
$displayedValue = $data[ $displayFieldAlias ];
if ( in_array( $pSet->getViewFormat( $lookupField ), array(FORMAT_DATE_SHORT, FORMAT_DATE_LONG, FORMAT_DATE_TIME) ) )
{
$ctrlData = array();
//if( $multiselect )
$ctrlData[ $lookupField ] = $data[ $linkField ];
/*else
$ctrlData[ $lookupField ] = $displayedValue;*/
$displayedValue = $viewContainer->getControl( $lookupField )->getTextValue( $ctrlData );
}
$response[] = $data[ $linkField ];
$response[] = $displayedValue;
}
$respObj = array('success' => true, 'data' => array_slice($response, 0, 40));
echo printJSON($respObj);
exit();
?>