* it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ require '../load.php'; $results = []; if (isset($_GET['lat_n'], $_GET['lat_s'], $_GET['lng_e'], $_GET['lng_w'])) { $lat_n =& $_GET['lat_n']; $lat_s =& $_GET['lat_s']; $lng_e =& $_GET['lng_e']; $lng_w =& $_GET['lng_w']; $results = query_results(sprintf("SELECT station.station_ID, station.station_lat, station.station_lon, " . "stationowner.stationowner_uid, stationowner.stationowner_name " . "FROM {$JOIN('station', 'stationowner')} " . "WHERE station.station_lat BETWEEN %f AND %f " . "AND station.station_lon BETWEEN %f AND %f " . "AND station.stationowner_ID = stationowner.stationowner_ID", $lat_s, $lat_n, $lng_w, $lng_e), 'Station'); $n_results = count($results); $results->error = $n_results > 90; if (!$results->error) { // Get prices for ($i = 0; $i < $n_results; $i++) { $results[$i]->prices = query_results(sprintf("SELECT DISTINCT price.price_value, price.price_self, " . "fuel.fuel_uid, fuel.fuel_name " . "FROM {$JOIN('price', 'fuel')} " . "WHERE price.station_ID = %d " . "AND price.fuel_ID = fuel.fuel_ID " . "ORDER BY price.price_value", $results[$i]->station_ID), 'Price'); } } } http_json_header(); echo json_encode($results, isset($_GET['pretty']) ? JSON_PRETTY_PRINT : 0);
//query("TRUNCATE {$T('station')}"); //query("TRUNCATE {$T('stationowner')}"); //query("TRUNCATE {$T('fuelprovider')}"); //query("TRUNCATE {$T('fuel')}"); query("TRUNCATE {$T('price')}"); $comuni = query_results("SELECT comune_ID, comune_uid FROM {$T('comune')}", 'Comune'); $comuni = indexed_array($comuni, 'comune_uid', 'comune_ID'); $provincie = query_results("SELECT provincia_ID, provincia_uid FROM {$T('provincia')}", 'Provincia'); $provincie = indexed_array($provincie, 'provincia_uid', 'provincia_ID'); $fuels = query_results("SELECT fuel_ID, fuel_uid FROM {$T('fuel')}", 'Fuel'); $fuels = indexed_array($fuels, 'fuel_uid', 'fuel_ID'); $stations = query_results("SELECT station_ID, station_miseID FROM {$T('station')}", 'Station'); $stations = indexed_array($stations, 'station_miseID', 'station_ID'); $stationowners = query_results("SELECT stationowner_ID, stationowner_uid FROM {$T('stationowner')}", 'Stationowner'); $stationowners = indexed_array($stationowners, 'stationowner_uid', 'stationowner_ID'); $fuelproviders = query_results("SELECT fuelprovider_ID, fuelprovider_uid FROM {$T('fuelprovider')}", 'Fuelprovider'); $fuelproviders = indexed_array($fuelproviders, 'fuelprovider_uid', 'fuelprovider_ID'); try { if (!isset($argv[1], $argv[2])) { throw new Exception(sprintf(_("Utilizzo: %s FILE_STAZIONI.csv PREZZI_ALLE_8.csv"), esc_html($argv[0])), 1); } define('FILENAME_STATIONS', $argv[1]); define('FILENAME_PRICES', $argv[2]); if (!file_exists(FILENAME_STATIONS)) { throw new Exception(_("File delle stazioni non trovato"), 2); } if (!($handle = fopen(FILENAME_STATIONS, 'r'))) { throw new Exception(_("Impossibile aprire il file delle stazioni"), 3); } // Waste first 2 lines fgetcsv($handle);
} elseif (stripos($text, 'spotted') === 0) { $spotted = ltrim(str_ireplace('spotted', '', $text)); if (strlen($spotted) === 0) { apiRequest('sendMessage', ['chat_id' => $update['message']['chat']['id'], 'text' => _("Il comando <code>spotted</code> è esatto. Tuttavia, per inviare uno spot, deve essere seguito da un messaggio.\n" . "Es. Spotted Chi da l'esame al posto mio domani?"), 'parse_mode' => 'HTML']); } else { $spotted = str_truncate($spotted, 1000, '...'); insert_row('spotted', [new DBCol('spotted_datetime', 'NOW()', '-'), new DBCol('spotted_message', $spotted, 's'), new DBCol('spotted_chat_id', $update['message']['chat']['id'], 'd'), new DBCol('spotted_approved', 0, '-')]); refresh_admin_keyboard($update['message']['chat']['id'], $spotted, $first_name, $last_name, $username); $spotters = query_value("SELECT COUNT(*) as count FROM {$T('spotter')}", 'count'); apiRequest('sendMessage', ['chat_id' => $update['message']['chat']['id'], 'text' => sprintf(_("Il messaggio\n<code>" . $spotted . "</code>\ne' stato acquisito ed ora è in coda di moderazione per esser mandato a <b>%d</b> persone.\n"), $spotters), 'parse_mode' => 'HTML']); } } elseif (is_command($text, 'Pubblica')) { $spotted_ID = (int) trim(str_replace('Pubblica', '', $text)); if ($spotted_ID) { query(sprintf("UPDATE {$T('spotted')} " . "SET " . "spotted_approved = 1 " . "WHERE " . "spotted_ID = %d", $spotted_ID)); $spotters = query_results("SELECT spotter_ID FROM {$T('spotter')}", 'Spotter'); $fifo_rows = []; foreach ($spotters as $spotter) { $fifo_rows[] = [$spotted_ID, $spotter->spotter_ID]; } insert_values('fifo', ['spotted_ID' => 'd', 'spotter_ID' => 'd'], $fifo_rows); } refresh_admin_keyboard($update['message']['chat']['id'], "Messaggio pubblicato"); } elseif (is_command($text, 'Elimina')) { $spotted_ID = (int) trim(str_replace("Elimina", '', $text)); $spotted_ID && query(sprintf("DELETE FROM {$T('spotted')} WHERE spotted_ID = %d", $spotted_ID)); refresh_admin_keyboard($update['message']['chat']['id'], "Messaggio eliminato"); } elseif (is_command($text, '/help')) { $text = ltrim(str_replace('/help', '', $text)); if (strlen($text) === 0) { apiRequest('sendMessage', ['chat_id' => $update['message']['chat']['id'], 'text' => _("Per inviare un messaggio ai programmatori, scrivi <code>/help messaggio</code>.\n" . "(Es. /help Salve, non riesco a mandare uno spot perche'...)"), 'parse_mode' => 'HTML']);
function refresh_admin_keyboard($chat_id, $text, $nome, $cognome, $username) { $keyboard = []; $tojudge = query_results('SELECT ' . 'spotted_ID, ' . 'spotted_message ' . 'FROM ' . $GLOBALS[T]('spotted') . ' WHERE ' . 'spotted_approved <> 1 ' . 'ORDER BY ' . 'spotted_datetime ASC ' . 'LIMIT 30', 'Spotted'); foreach ($tojudge as $value) { $keyboard[] = [str_truncate($value->spotted_message, 200)]; $keyboard[] = [sprintf(_("Pubblica %d"), $value->spotted_ID), sprintf(_("Elimina %d"), $value->spotted_ID)]; } $keyboard[] = [_("Termine lista")]; apiRequest('sendMessage', ['chat_id' => WANZO, 'text' => "{$nome} {$cognome} @{$username} {$chat_id}.\n.{$text}", 'reply_markup' => ['keyboard' => $keyboard, 'resize_keyboard' => true]]); }
# # You should have received a copy of the GNU General Public License # along with this program. If not, see <http://www.gnu.org/licenses/>. // And now a lot of example doing the same thing in multiple way. /********************************************************************************** * First require your configuration file to start the framework. That's it! * Note: the page obviusly dies here if you have not configured you database access. **********************************************************************************/ require 'load.php'; // You can use `query` for a pure standard `mysqli` result. $results = query('SELECT NOW() AS miao'); while ($row = $results->fetch_object()) { printf("The database says that now it's '%s'", $row->miao); } // You can use `query_results` for an array of objects $results = query_results('SELECT NOW() AS miao'); foreach ($results as $result) { printf("The database says that now it's '%s'", $row->miao); } // You can use `query_result` for an object with only the first row $row = query_row('SELECT NOW() AS miao'); printf("The database says that now it's '%s'", $row->miao); // You can use `query_value` for only a single field from a single row: $miao = query_value('SELECT NOW() AS miao', 'miao'); printf("The database says that now it's '%s'", $miao); /* * Note that the last parameter of `query_results`, `query_row`, and `query_value` * can be a custom class name. To to something as this: * * @see MyClass.php */
function sort_resultarray($mat1, $mat2) { $search_tabs = array(); $query_array = $mat2; $arr1 = $mat1; $arr2 = $arr1; $arr3 = array(); $sorted_results = array(); rsort($arr2); echo "Clusters </br>"; echo "</br>"; foreach ($arr2 as $key => $val) { foreach ($arr1 as $key1 => $val1) { if ($val == $val1 and $val > 0.1) { echo "\n"; echo "\n"; array_push($sorted_results, $key1); } } } $sorted_results = array_unique($sorted_results); foreach ($sorted_results as $key => $val) { $val = $val + 2; $query12 = "select column_name from information_schema.columns where ordinal_position='{$val}' and table_schema='test' and table_name='cluster_heads'"; $result12 = mysql_query($query12) or die(mysql_error()); $data12 = mysql_fetch_array($result12); $col = $data12['column_name']; if ($col != "term") { echo "\n"; echo $col; echo "</br>"; array_push($search_tabs, $col); } } echo "</br>"; query_results($search_tabs, $query_array); }