/** * Searching / Filtering * * Construct the WHERE clause for server-side processing SQL query. * * NOTE this does not match the built-in DataTables filtering which does it * word by word on any field. It's possible to do here performance on large * databases would be very poor * * @param array $request Data sent to server by DataTables * @param array $columns Column information array * @param array $bindings Array of values for PDO bindings, used in the * sql_exec() function * @return string SQL where clause */ static function filter($request, $columns) { $globalSearch = array(); $columnSearch = array(); $dtColumns = self::pluck($columns, 'dt'); if (isset($request['search']) && $request['search']['value'] != '') { $str = $request['search']['value']; for ($i = 0, $ien = count($request['columns']); $i < $ien; $i++) { $requestColumn = $request['columns'][$i]; $columnIdx = array_search($requestColumn['data'], $dtColumns); $column = $columns[$columnIdx]; if ($requestColumn['searchable'] == 'true') { $pos1 = strpos($column['db'], 'date'); $pos2 = strpos($column['db'], 'fecha'); if ($pos1 === false && $pos2 === false) { $globalSearch[] = " translate(upper(" . $column['db'] . "),'áéíóúÁÉÍÓÚäëïöüÄËÏÖÜ','aeiouAEIOUaeiouAEIOU') LIKE " . "'%" . pg_escape_string(clean_upper2($str)) . "%'"; } else { $globalSearch[] = " to_char(" . $column['db'] . ", 'dd/mm/YYYY') LIKE " . "'%" . $str . "%'"; } } } } // Individual column filtering for ($i = 0, $ien = count($request['columns']); $i < $ien; $i++) { $requestColumn = $request['columns'][$i]; $columnIdx = array_search($requestColumn['data'], $dtColumns); $column = $columns[$columnIdx]; $str = $requestColumn['search']['value']; if ($requestColumn['searchable'] == 'true' && $str != '') { $columnSearch[] = " translate(upper(" . $column['db'] . "),'áéíóúÁÉÍÓÚäëïöüÄËÏÖÜ','aeiouAEIOUaeiouAEIOU') LIKE " . "'%" . pg_escape_string(clean_upper2($str)) . "%'"; } } // Combine the filters into a single string $where = ''; if (count($globalSearch)) { $where = '(' . implode(' OR ', $globalSearch) . ')'; } if (count($columnSearch)) { $where = $where === '' ? implode(' AND ', $columnSearch) : $where . ' AND ' . implode(' AND ', $columnSearch); } if ($where !== '') { $where = ' and ' . $where . ' '; } return $where; }
function clientGetUsuarios2() { try { if ($this->config->item('local_opd_id') == $_POST['opd_id']) { $resultado = $this->modelo->buscar_usuarios(clean_upper2($_POST['termino'])); $resultado2 = array(); foreach ($resultado as $value) { // if ($value['usr_id'] != $this->session->userdata('usr_id')) $resultado2[] = $value; } echo "OK!!" . json_encode($resultado2); } else { $datos_opd = $this->modelo->get_opd($_POST['opd_id']); $datos_opd = $datos_opd[0]; $urlWS = $datos_opd['opd_url']; // Utilizar el uri $client = new SoapClient(null, array('location' => $urlWS, 'uri' => 'urn:webservices')); $resultado = $client->buscarUsuarios($_POST['termino'], 4); foreach ($resultado as $value) { if ($this->modelo->usuario_remoto_existe($_POST['opd_id'], $value['usr_id']) != null) { $value['opd_id'] = $_POST['opd_id']; $this->modelo->actualizar_usuario_remoto($value); } else { $value['opd_id'] = $_POST['opd_id']; $this->modelo->insert_usuario_remoto($value); } } echo "OK!!" . json_encode($resultado); } } catch (Exception $e) { echo "ERROR!!" . $e->getMessage(); //echo $urlWS; } }