1: <?php
2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15:
16:
17: defined('CON_FRAMEWORK') || die('Illegal call: Missing framework initialization - request aborted.');
18:
19: 20: 21: 22: 23: 24:
25: class cModuleSearch extends cModuleHandler {
26:
27: 28: 29: 30: 31:
32: protected $_elementPerPage = '';
33:
34: 35: 36: 37: 38:
39: protected $_orderBy = '';
40:
41: 42: 43: 44: 45:
46: protected $_sortOrder = '';
47:
48: 49: 50: 51: 52:
53: protected $_moduleType = '';
54:
55: 56: 57: 58: 59:
60: protected $_filter = '';
61:
62: 63: 64: 65: 66:
67: protected $_searchIn = '';
68:
69: 70: 71: 72: 73:
74: protected $_selectedPage = 1;
75:
76: 77: 78: 79: 80:
81: protected $_result = array();
82:
83: 84: 85: 86: 87:
88: private function _echo($arg) {
89: echo '<pre>' . print_r($arg) . '</pre>';
90: }
91:
92: public function __construct($searchOptions) {
93: $this->_elementPerPage = $searchOptions['elementPerPage'];
94: $this->_orderBy = $searchOptions['orderBy'];
95: $this->_sortOrder = $searchOptions['sortOrder'];
96: $this->_moduleType = $searchOptions['moduleType'];
97: $this->_filter = $searchOptions['filter'];
98: $this->_searchIn = $searchOptions['searchIn'];
99: $this->_selectedPage = $searchOptions['selectedPage'];
100: }
101:
102: 103: 104: 105: 106:
107: public function getModulCount() {
108: return count($this->_result);
109: }
110:
111: 112: 113: 114: 115: 116:
117: public function searchForAllModules() {
118: global $cfg, $client;
119: $idClient = $client;
120:
121: $sql = sprintf("SELECT *, (0) FROM %s WHERE idclient = %s AND (
122: type LIKE '%s'
123: AND type LIKE '%s'
124: OR description LIKE '%s'
125: OR name LIKE '%s'
126: OR input LIKE '%s'
127: OR output LIKE '%s')
128: ORDER BY %s %s", $cfg['tab']['mod'], $idClient, $this->_moduleType, '%' . $this->_filter . '%', '%' . $this->_filter . '%', '%' . $this->_filter . '%', '%' . $this->_filter . '%', '%' . $this->_filter . '%', $this->_orderBy, $this->_sortOrder);
129:
130: $db = cRegistry::getDb();
131: $db->query($sql);
132: $result = array();
133:
134: while (($modul = $db->nextRecord()) !== false) {
135: $this->initWithDatabaseRow($db);
136: $result[$db->f('idmod')] = array(
137: 'name' => $db->f('name'),
138: 'description' => $db->f('description'),
139: 'error' => $db->f('error'),
140: 'input' => $this->readInput(),
141: 'output' => $this->readOutput()
142: );
143: }
144:
145: return $result;
146: }
147:
148: 149: 150: 151: 152: 153:
154: public function getModules() {
155: $modules = array();
156:
157: switch ($this->_searchIn) {
158: case 'all':
159: $modules = $this->searchForAllModules();
160: break;
161: case 'name':
162: $modules = $this->findeModulWithName();
163: break;
164: case 'description':
165: $modules = $this->findModuleWithDescription();
166: break;
167: case 'type':
168: $modules = $this->findModuleWithType();
169: break;
170: case 'input':
171: $modules = $this->findModulWithInput();
172: break;
173: case 'output':
174: $modules = $this->findModulWithOutput();
175: break;
176: }
177:
178: $this->_result = $modules;
179: if ($this->_elementPerPage > 0) {
180: if (count($this->_result) < (($this->_page - 1) * $this->_elementPerPage)) {
181: $this->_page = 1;
182: }
183:
184: if ($this->_elementPerPage * ($this->_page) >= count($this->_result) + $this->_elementPerPage && $this->_page != 1) {
185: $this->_page--;
186: }
187: return array_slice($modules, $this->_elementPerPage * ($this->_selectedPage - 1), $this->_elementPerPage, true);
188: } else {
189: return $modules;
190: }
191: }
192:
193: 194: 195: 196: 197:
198: public function findeModulWithName() {
199: global $cfg, $client;
200: $idClient = $client;
201:
202: $sql = sprintf("SELECT * FROM %s WHERE idclient = %s AND (
203: type LIKE '%s' AND name LIKE '%s' )
204: ORDER BY %s %s ", $cfg['tab']['mod'], $idClient, $this->_moduleType, '%' . $this->_filter . '%', $this->_orderBy, $this->_sortOrder);
205:
206: $db = cRegistry::getDb();
207: $db->query($sql);
208: $result = array();
209:
210: while (($module = $db->nextRecord()) !== false) {
211: $this->initWithDatabaseRow($db);
212: $result[$db->f('idmod')] = array(
213: 'name' => $db->f('name'),
214: 'description' => $db->f('description'),
215: 'error' => $db->f('error'),
216: 'input' => $this->readInput(),
217: 'output' => $this->readOutput()
218: );
219: }
220: return $result;
221: }
222:
223: 224: 225: 226: 227:
228: public function findModulWithInput() {
229: global $cfg, $client;
230: $idClient = $client;
231:
232: $sql = sprintf("SELECT * FROM %s WHERE idclient = %s AND (
233: type LIKE '%s' AND input LIKE '%s')
234: ORDER BY %s %s ", $cfg['tab']['mod'], $idClient, $this->_moduleType, '%' . $this->_filter . '%', $this->_orderBy, $this->_sortOrder);
235:
236: $db = cRegistry::getDb();
237: $db->query($sql);
238: $result = array();
239:
240: while (($module = $db->nextRecord()) !== false) {
241: $this->initWithDatabaseRow($db);
242: $result[$db->f('idmod')] = array(
243: 'name' => $db->f('name'),
244: 'description' => $db->f('description'),
245: 'error' => $db->f('error'),
246: 'input' => $this->readInput(),
247: 'output' => $this->readOutput()
248: );
249: }
250: return $result;
251: }
252:
253: 254: 255: 256: 257:
258: public function findModulWithOutput() {
259: global $cfg, $client;
260: $idClient = $client;
261:
262: $sql = sprintf("SELECT * FROM %s WHERE idclient = %s AND (
263: type LIKE '%s' AND output LIKE '%s' )
264: ORDER BY %s %s ", $cfg['tab']['mod'], $idClient, $this->_moduleType, '%' . $this->_filter . '%', $this->_orderBy, $this->_sortOrder);
265:
266: $db = cRegistry::getDb();
267: $db->query($sql);
268: $result = array();
269:
270: while (($module = $db->nextRecord()) !== false) {
271: $this->initWithDatabaseRow($db);
272: $result[$db->f('idmod')] = array(
273: 'name' => $db->f('name'),
274: 'description' => $db->f('description'),
275: 'error' => $db->f('error'),
276: 'input' => $this->readInput(),
277: 'output' => $this->readOutput()
278: );
279: }
280: return $result;
281: }
282:
283: 284: 285: 286: 287:
288: public function findModuleWithType() {
289: global $cfg, $client;
290: $idClient = $client;
291:
292: $sql = sprintf("SELECT * FROM %s WHERE idclient = %s AND (
293: type LIKE '%s'
294: AND type LIKE '%s')
295: ORDER BY %s %s ", $cfg['tab']['mod'], $idClient, $this->_moduleType, '%' . $this->_filter . '%', $this->_orderBy, $this->_sortOrder);
296:
297: $db = cRegistry::getDb();
298: $db->query($sql);
299: $result = array();
300:
301: while (($module = $db->nextRecord()) !== false) {
302: $this->initWithDatabaseRow($db);
303: $result[$db->f('idmod')] = array(
304: 'name' => $db->f('name'),
305: 'description' => $db->f('description'),
306: 'error' => $db->f('error'),
307: 'input' => $this->readInput(),
308: 'output' => $this->readOutput()
309: );
310: }
311:
312: return $result;
313: }
314:
315: 316: 317: 318: 319:
320: public function findModuleWithDescription() {
321: global $cfg, $client;
322: $idClient = $client;
323:
324: $sql = sprintf("SELECT * FROM %s WHERE idclient = %s AND (
325: type LIKE '%s'
326: AND description LIKE '%s')
327: ORDER BY %s %s ", $cfg['tab']['mod'], $idClient, $this->_moduleType, '%' . $this->_filter . '%', $this->_orderBy, $this->_sortOrder);
328:
329: $db = cRegistry::getDb();
330: $db->query($sql);
331: $result = array();
332:
333: while (($module = $db->nextRecord()) !== false) {
334: $this->initWithDatabaseRow($db);
335: $result[$db->f('idmod')] = array(
336: 'name' => $db->f('name'),
337: 'description' => $db->f('description'),
338: 'error' => $db->f('error'),
339: 'input' => $this->readInput(),
340: 'output' => $this->readOutput()
341: );
342: }
343: return $result;
344: }
345:
346: }
347: