MIOLO20
Carregando...
Procurando...
Nenhuma entrada encontrada
mlookup.class
Ir para a documentação deste ficheiro.
1<?php
2class MLookup
3{
5 var $dbconf;
6 var $sql;
7 var $labels;
9 var $module;
10 var $item;
14 var $event;
15 var $filterValue = '';
17 var $form;
18 var $pageLength = 20;
20 var $title;
21 var $grid;
24 var $gridClass = 'LookupGrid';
25 var $lookupType = 'grid';
26 protected $filterColumns = 0;
27
28 function __construct($baseModule = 'admin')
29 {
30 global $MIOLO;
31
32 $this->baseModule = $baseModule;
33 $this->formName = $_GET['name'];
34 $this->module = $_GET['lmodule'];
35 $this->item = $_GET['item'];
36 $this->function = $_GET['function'];
37 $this->event = $_GET['event'];
38 $this->lheight = $_GET['lheight'];
39 $this->lwidth = $_GET['lwidth'];
40 $this->related = $_GET['related'];
41 $this->filterValue = $_GET['filter'];
42 $url = $MIOLO->GetActionURL($this->baseModule,
43 'lookup', urlencode($this->item), array('name' => urlencode($this->formName), 'lmodule' => urlencode($this->module), 'function' => urlencode($this->function), 'event' => urlencode($this->event)), NULL, false);
44 $this->href = $url;
45 $this->listingTitle = _M('Search Result');
46 }
47
48 public function setListingTitle($title)
49 {
50 $this->listingTitle = $title;
51 }
52
53 function GetFilterValue($name = '')
54 {
55 global $page;
56
57 $value = ($name != '') ? $page->Request($name) : $this->filterValue;
58 $value = str_replace("'", '', $value);
59 $value = str_replace("\"", '', $value);
60 $value = str_replace("#", '', $value);
61 return $value;
62 }
63
64 function setLookupType( $type='grid' )
65 {
66 $this->lookupType = $type;
67 }
68
69 function generate( )
70 {
71 if ( $this->lookupType == 'form' )
72 {
73 return $this->form;
74 }
75 return $this->grid;
76 }
77
79 {
80 $this->setLookupType( 'form' );
81 $this->form = new mForm( $title, '', 'javascript:MIOLO_Close( )' );
82
83 $idx = MIOLO::_Request('idx');
84 $related = explode(',', MIOLO::_Request('related'));
85 if ( is_array($idx) )
86 {
87 $info = array( );
88 foreach($related as $r)
89 {
90 if ( $idx[$r] )
91 {
92 $info[] = "document.forms[0]['$campoAqui'].value";
93 }
94 else
95 {
96 $info[] = 'null';
97 }
98 }
99 $info = implode(',', $info);
100 $related = implode(',', $related);
101 }
102 else
103 {
104 $info = "''";
105 }
106
107 if ( $related )
108 {
109 $this->form->page->onLoad("eval('MIOLO_getWindow( true ).' + '$this->formName').related = '$related';");
110 }
111 $this->form->addButton( new FormButton( 'submit', _M('Send'), "MIOLO_Deliver( '$this->formName', 0, $info);"));
112 }
113
114 function addField( $field )
115 {
116 $this->form->addField( $field );
117 }
118
119 function setFields( $fields )
120 {
121 $this->form->setFields( $fields );
122 }
123
124 public function setFilterColumns($countColumns)
125 {
126 $this->filterColumns = $countColumns;
127 }
128
129 function GetHRef()
130 {
131 return $this->href;
132 }
133
135 {
136 global $MIOLO;
137 $db = $MIOLO->GetDatabase($dbconf);
138 return $db->GetQuery($sql);
139 }
140
141 function AddFilterField($field)
142 {
143 $this->filterFields[] = &$field;
144 }
145
146 function SetGridClass($class, $module, $classFile)
147 {
148 global $MIOLO;
149
150 $MIOLO->Uses($classFile, $module);
151 $this->gridClass = $class;
152 }
153
154 function getGrid($query, $columns, $href, $pageLength, $indexColumn)
155 {
156 return new $this->gridClass($query, $columns, $href, $pageLength, $indexColumn, $this->filterColumns);
157 }
158
159 function setLookupGrid($dbconf, $sql, $columns, $title = 'Search', $pageLength = 15, $indexColumn = 0)
160 {
161 // if $sql is an array, we create a MGrid and put the data
162 if ( ! is_object($sql) )
163 {
164 $this->grid = new MGrid($sql, $columns, $this->href, $pageLength, $indexColumn, '', true, true, false, false, false);
165 }
166 else
167 {
168 try
169 {
170 $query = $this->getQuery($dbconf, $sql);
171 }
172 catch ( EDatabaseException $e )
173 {
174 $query = NULL;
175 }
176
177 $this->grid = $this->getGrid($query, $columns, $this->href, $pageLength, $indexColumn);
178 }
179
180 $this->grid->setFilter(true);
181 $this->grid->setLinkType('hyperlink');
182 $this->grid->setTitle($title);
183
184 for ($i = 0; $i < count($this->filterFields); $i++)
185 {
186 $this->grid->addFilterControl($i, $this->filterFields[$i]);
187 }
188
189 if ( ! is_object($sql) )
190 {
191 for ($i = 0; $i < count($columns); $i++)
192 {
193 if ($i)
194 {
195 $args .= ',';
196 }
197
198 $args .= "&quot;#$i#&quot;";
199 }
200 }
201 else
202 {
203 for ($i = 0; $i < count($query->result[0]); $i++)
204 {
205 if ($i)
206 {
207 $args .= ',';
208 }
209
210 $args .= "&quot;#$i#&quot;";
211 }
212 }
213
214 $actionIcon = "javascript:MIOLO_Deliver('$this->formName', {$indexColumn}, $args)";
215
216 if (strpos(MIOLO::getInstance()->getTheme()->id, "sbootstrap") !== false)
217 {
218 MIOLO::getInstance()->getPage()->addAJAXJsCode("
219 // Modal title, não tenho esse título antes
220 window.parent.document.getElementById('lookupTitle_".$_GET['field']."').innerHTML = '".$this->grid->title."';
221
222 // ESC para fechar
223 window.onkeydown = function(e) {
224 var e = e || window.event;
225 if (e.keyCode === 27) {
226 window.parent.closeLookupModals();
227 }
228 }
229
230 // Stop no loading
231 let stateCheck = setInterval(() => {
232 if (document.readyState === 'complete') {
233 clearInterval(stateCheck);
234 document.getElementsByTagName('BODY')[0].style = 'min-height: 0;';
235 window.parent.stopShowLoading();
236 }
237 }, 100);
238
239 ");
240
241 $actionIcon .= ";window.parent.closeLookupModals();";
242 }
243
244 $this->grid->addActionIcon('ID', 'select', $actionIcon);
245 }
246
247 function SetMActiveLookupGrid($dbconf, $sql, $columns, $title = 'Search', $pageLength = 15, $indexColumn = 0)
248 {
249 $query = $this->GetQuery($dbconf, $sql);
250 $this->grid = $this->GetGrid($query, $columns, $this->href, $pageLength, $indexColumn);
251 $this->grid->SetLinkType('hyperlink');
252 $this->grid->SetFullWidth($this->lwidth);
253 $this->grid->SetFullHeight($this->lheight);
254 for ($i = 0; $i < count($query->result[0]); $i++)
255 {
256 if ($i)
257 {
258 $args .= ',';
259 }
260
261 $args .= "&quot;#$i#&quot;";
262 }
263 $this->grid->AddActionIcon('ID', 'select', "javascript:MIOLO_ActiveDeliver('$this->formName', {$indexColumn}, '{$this->event}','{$this->related}', $args)");
264 }
265
266 function SetGrid($dbconf, $sql, $columns, $title = 'Search', $pageLength = 15, $indexColumn = 0)
267 {
268 $method = "Set" . $this->gridClass;
269 $this->$method($dbconf, $sql, $columns, $title, $pageLength, $indexColumn);
270 }
271}
272?>
static getInstance()
Definição miolo.class:134
setLookupGrid($dbconf, $sql, $columns, $title='Search', $pageLength=15, $indexColumn=0)
Definição mlookup.class:159
GetFilterValue($name='')
Definição mlookup.class:53
$filterValue
Definição mlookup.class:15
setLookupForm( $title)
Definição mlookup.class:78
SetGrid($dbconf, $sql, $columns, $title='Search', $pageLength=15, $indexColumn=0)
Definição mlookup.class:266
SetMActiveLookupGrid($dbconf, $sql, $columns, $title='Search', $pageLength=15, $indexColumn=0)
Definição mlookup.class:247
setLookupType( $type='grid')
Definição mlookup.class:64
SetGridClass($class, $module, $classFile)
Definição mlookup.class:146
addField( $field)
Definição mlookup.class:114
__construct($baseModule='admin')
Definição mlookup.class:28
$filterColumns
Definição mlookup.class:26
AddFilterField($field)
Definição mlookup.class:141
setListingTitle($title)
Definição mlookup.class:48
setFields( $fields)
Definição mlookup.class:119
& GetQuery($dbconf, $sql)
Definição mlookup.class:134
$listingTitle
Definição mlookup.class:4
generate()
Definição mlookup.class:69
setFilterColumns($countColumns)
Definição mlookup.class:124
getGrid($query, $columns, $href, $pageLength, $indexColumn)
Definição mlookup.class:154
$filterFields
Definição mlookup.class:16
$url
Definição base.php:2