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