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