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