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: public function __construct($searchOptions) {
89: parent::__construct();
90:
91: $this->_elementPerPage = $searchOptions['elementPerPage'];
92: $this->_orderBy = $searchOptions['orderBy'];
93: $this->_sortOrder = $searchOptions['sortOrder'];
94: $this->_moduleType = $searchOptions['moduleType'];
95: $this->_filter = $searchOptions['filter'];
96: $this->_searchIn = $searchOptions['searchIn'];
97: $this->_selectedPage = $searchOptions['selectedPage'];
98: }
99:
100: 101: 102: 103: 104:
105: private function _echo($arg) {
106: echo '<pre>' . print_r($arg) . '</pre>';
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: public function searchForAllModules() {
126: global $cfg, $client;
127:
128: $idClient = $client;
129:
130:
131:
132: $sql = sprintf("SELECT * FROM %s WHERE idclient = %s", $cfg['tab']['mod'], $idClient);
133:
134:
135: $db = cRegistry::getDb();
136: $db->query($sql);
137: $moduleIds = array();
138:
139:
140: while (($modul = $db->nextRecord()) !== false) {
141: $this->initWithDatabaseRow($db);
142: if (strlen(stripslashes($this->_filter)) === 0
143: || strpos($this->readInput(), stripslashes($this->_filter)) !== false
144: || strpos($this->readOutput(), stripslashes($this->_filter)) !== false) {
145: $moduleIds[] = $db->f('idmod');
146: }
147: }
148:
149:
150: $idFilter = "";
151: foreach ($moduleIds as $moduleId) {
152: $idFilter .= " OR idmod=" . (int) $moduleId;
153: }
154: $sql = sprintf("SELECT * FROM %s WHERE idclient = %s AND (
155: type LIKE '%s'
156: AND type LIKE '%s'
157: OR description LIKE '%s'
158: OR name LIKE '%s'" . $idFilter . ")
159: ORDER BY %s %s", $cfg['tab']['mod'], $idClient, $this->_moduleType, '%' . $this->_filter . '%', '%' . $this->_filter . '%', '%' . $this->_filter . '%', $this->_orderBy, $this->_sortOrder);
160:
161: $db = cRegistry::getDb();
162: $db->query($sql);
163: $result = array();
164:
165: while (($modul = $db->nextRecord()) !== false) {
166: $this->initWithDatabaseRow($db);
167: $result[$db->f('idmod')] = array(
168: 'name' => $db->f('name'),
169: 'description' => $db->f('description'),
170: 'error' => $db->f('error'),
171: 'input' => $this->readInput(),
172: 'output' => $this->readOutput()
173: );
174: }
175:
176: return $result;
177: }
178:
179: 180: 181: 182: 183: 184:
185: public function getModules() {
186: $modules = array();
187:
188: switch ($this->_searchIn) {
189: case 'all':
190: $modules = $this->searchForAllModules();
191: break;
192: case 'name':
193: $modules = $this->findeModulWithName();
194: break;
195: case 'description':
196: $modules = $this->findModuleWithDescription();
197: break;
198: case 'type':
199: $modules = $this->findModuleWithType();
200: break;
201: case 'input':
202: $modules = $this->findModulWithInput();
203: break;
204: case 'output':
205: $modules = $this->findModulWithOutput();
206: break;
207: }
208:
209: $this->_result = $modules;
210: if ($this->_elementPerPage > 0) {
211: if (count($this->_result) < (($this->_page - 1) * $this->_elementPerPage)) {
212: $this->_page = 1;
213: }
214:
215: if ($this->_elementPerPage * ($this->_page) >= count($this->_result) + $this->_elementPerPage && $this->_page != 1) {
216: $this->_page--;
217: }
218: return array_slice($modules, $this->_elementPerPage * ($this->_selectedPage - 1), $this->_elementPerPage, true);
219: } else {
220: return $modules;
221: }
222: }
223:
224: 225: 226: 227: 228:
229: public function findeModulWithName() {
230: global $cfg, $client;
231: $idClient = $client;
232:
233: $sql = sprintf("SELECT * FROM %s WHERE idclient = %s AND (type LIKE '%s' AND name 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 findModulWithInput() {
259: global $cfg, $client;
260:
261: $idClient = $client;
262: $sql = sprintf("SELECT * FROM %s WHERE idclient = %s AND type LIKE '%s'
263: ORDER BY %s %s ", $cfg['tab']['mod'], $idClient, $this->_moduleType, $this->_orderBy, $this->_sortOrder);
264:
265: $db = cRegistry::getDb();
266: $db->query($sql);
267: $result = array();
268: while (($module = $db->nextRecord()) !== false) {
269: $this->initWithDatabaseRow($db);
270: if (strlen(stripslashes($this->_filter)) === 0
271: || strpos($this->readInput(), stripslashes($this->_filter)) !== false) {
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: }
281:
282: return $result;
283: }
284:
285: 286: 287: 288: 289:
290: public function findModulWithOutput() {
291: global $cfg, $client;
292:
293: $result = array();
294:
295: $idClient = $client;
296: $sql = sprintf("SELECT * FROM %s WHERE idclient = %s AND type LIKE '%s'
297: ORDER BY %s %s ", $cfg['tab']['mod'], $idClient, $this->_moduleType, $this->_orderBy, $this->_sortOrder);
298:
299: $db = cRegistry::getDb();
300: $db->query($sql);
301: $result = array();
302: while (($module = $db->nextRecord()) !== false) {
303: $this->initWithDatabaseRow($db);
304: if (strlen(stripslashes($this->_filter)) === 0
305: || strpos($this->readOutput(), stripslashes($this->_filter)) !== false) {
306: $result[$db->f('idmod')] = array(
307: 'name' => $db->f('name'),
308: 'description' => $db->f('description'),
309: 'error' => $db->f('error'),
310: 'input' => $this->readInput(),
311: 'output' => $this->readOutput()
312: );
313: }
314: }
315:
316: return $result;
317: }
318:
319: 320: 321: 322: 323:
324: public function findModuleWithType() {
325: global $cfg, $client;
326: $idClient = $client;
327:
328: $sql = sprintf("SELECT * FROM %s WHERE idclient = %s AND (
329: type LIKE '%s'
330: AND type LIKE '%s')
331: ORDER BY %s %s ", $cfg['tab']['mod'], $idClient, $this->_moduleType, '%' . $this->_filter . '%', $this->_orderBy, $this->_sortOrder);
332:
333: $db = cRegistry::getDb();
334: $db->query($sql);
335: $result = array();
336:
337: while (($module = $db->nextRecord()) !== false) {
338: $this->initWithDatabaseRow($db);
339: $result[$db->f('idmod')] = array(
340: 'name' => $db->f('name'),
341: 'description' => $db->f('description'),
342: 'error' => $db->f('error'),
343: 'input' => $this->readInput(),
344: 'output' => $this->readOutput()
345: );
346: }
347: return $result;
348: }
349:
350: 351: 352: 353: 354:
355: public function findModuleWithDescription() {
356: global $cfg, $client;
357: $idClient = $client;
358:
359: $sql = sprintf("SELECT * FROM %s WHERE idclient = %s AND (
360: type LIKE '%s'
361: AND description LIKE '%s')
362: ORDER BY %s %s ", $cfg['tab']['mod'], $idClient, $this->_moduleType, '%' . $this->_filter . '%', $this->_orderBy, $this->_sortOrder);
363:
364: $db = cRegistry::getDb();
365: $db->query($sql);
366: $result = array();
367:
368: while (($module = $db->nextRecord()) !== false) {
369: $this->initWithDatabaseRow($db);
370: $result[$db->f('idmod')] = array(
371: 'name' => $db->f('name'),
372: 'description' => $db->f('description'),
373: 'error' => $db->f('error'),
374: 'input' => $this->readInput(),
375: 'output' => $this->readOutput()
376: );
377: }
378:
379: return $result;
380: }
381:
382: }
383: