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 (type LIKE '%s' AND name LIKE '%s')
203: ORDER BY %s %s ", $cfg['tab']['mod'], $idClient, $this->_moduleType, '%' . $this->_filter . '%', $this->_orderBy, $this->_sortOrder);
204:
205: $db = cRegistry::getDb();
206: $db->query($sql);
207: $result = array();
208:
209: while (($module = $db->nextRecord()) !== false) {
210: $this->initWithDatabaseRow($db);
211: $result[$db->f('idmod')] = array(
212: 'name' => $db->f('name'),
213: 'description' => $db->f('description'),
214: 'error' => $db->f('error'),
215: 'input' => $this->readInput(),
216: 'output' => $this->readOutput()
217: );
218: }
219: return $result;
220: }
221:
222: 223: 224: 225: 226:
227: public function findModulWithInput() {
228: global $cfg, $client;
229: $idClient = $client;
230:
231: $sql = sprintf("SELECT * FROM %s WHERE idclient = %s AND (
232: type LIKE '%s' AND input LIKE '%s')
233: ORDER BY %s %s ", $cfg['tab']['mod'], $idClient, $this->_moduleType, '%' . $this->_filter . '%', $this->_orderBy, $this->_sortOrder);
234:
235: $db = cRegistry::getDb();
236: $db->query($sql);
237: $result = array();
238:
239: while (($module = $db->nextRecord()) !== false) {
240: $this->initWithDatabaseRow($db);
241: $result[$db->f('idmod')] = array(
242: 'name' => $db->f('name'),
243: 'description' => $db->f('description'),
244: 'error' => $db->f('error'),
245: 'input' => $this->readInput(),
246: 'output' => $this->readOutput()
247: );
248: }
249: return $result;
250: }
251:
252: 253: 254: 255: 256:
257: public function findModulWithOutput() {
258: global $cfg, $client;
259: $idClient = $client;
260:
261: $sql = sprintf("SELECT * FROM %s WHERE idclient = %s AND (type LIKE '%s' AND output LIKE '%s' )
262: ORDER BY %s %s ", $cfg['tab']['mod'], $idClient, $this->_moduleType, '%' . $this->_filter . '%', $this->_orderBy, $this->_sortOrder);
263:
264: $db = cRegistry::getDb();
265: $db->query($sql);
266: $result = array();
267:
268: while (($module = $db->nextRecord()) !== false) {
269: $this->initWithDatabaseRow($db);
270: $result[$db->f('idmod')] = array(
271: 'name' => $db->f('name'),
272: 'description' => $db->f('description'),
273: 'error' => $db->f('error'),
274: 'input' => $this->readInput(),
275: 'output' => $this->readOutput()
276: );
277: }
278: return $result;
279: }
280:
281: 282: 283: 284: 285:
286: public function findModuleWithType() {
287: global $cfg, $client;
288: $idClient = $client;
289:
290: $sql = sprintf("SELECT * FROM %s WHERE idclient = %s AND (
291: type LIKE '%s'
292: AND type LIKE '%s')
293: ORDER BY %s %s ", $cfg['tab']['mod'], $idClient, $this->_moduleType, '%' . $this->_filter . '%', $this->_orderBy, $this->_sortOrder);
294:
295: $db = cRegistry::getDb();
296: $db->query($sql);
297: $result = array();
298:
299: while (($module = $db->nextRecord()) !== false) {
300: $this->initWithDatabaseRow($db);
301: $result[$db->f('idmod')] = array(
302: 'name' => $db->f('name'),
303: 'description' => $db->f('description'),
304: 'error' => $db->f('error'),
305: 'input' => $this->readInput(),
306: 'output' => $this->readOutput()
307: );
308: }
309:
310: return $result;
311: }
312:
313: 314: 315: 316: 317:
318: public function findModuleWithDescription() {
319: global $cfg, $client;
320: $idClient = $client;
321:
322: $sql = sprintf("SELECT * FROM %s WHERE idclient = %s AND (
323: type LIKE '%s'
324: AND description 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: