function do_dbwrite($sql, $verb, $expected_rows = 1, $link = NULL) { if ($link == NULL) { $link = get_dblink(); } if ($link == NULL) { return false; } write_debug("SQL {$verb}: [{$sql}]"); $rc = mysql_query($sql, $link); if ($rc == false) { $err = mysql_error(); $upperverb = strtoupper($verb); write_error("Problem in {$upperverb} statement: {$err}"); return false; } // if $retval = mysql_affected_rows($link); if ($expected_rows >= 0 and $retval != $expected_rows) { $err = mysql_error(); write_error("Database {$verb} error: {$err}"); } // if return $retval; }
function write_json($query, $reversed, $line) { if ($query == 'line') { write_ok($line); } elseif ($query == 'bus') { $bus = $line[0]; $bus_info = get_bus_info($bus, $reversed); $bus_pos = cache_bus_pos($bus, $reversed); $result = array('bus_info' => $bus_info['info'], 'bus_station' => $bus_info['station'], 'bus_pos' => $bus_pos); write_ok($result); } else { write_error($GLOBALS['ERR_PARAMS_QUERY']); } }
function get_joke($type, $joke_id, $cat_id, $limit) { if ($joke_id) { $sql = "select `id`, `cat`, `cat_id`, `title`, `content` from `joke` where `id` = {$joke_id}"; } elseif ($cat_id == -1) { $sql = "select `id`, `cat`, `cat_id`, `title`, `content` from `joke` order by rand() limit {$limit}"; } else { $sql = "select `id`, `cat`, `cat_id`, `title`, `content` from `joke` where `cat_id` = {$cat_id} order by rand() limit {$limit}"; } $jokes = query_sql($sql); if ($type == 'text') { $result = ""; foreach ($jokes as $joke) { $result .= $joke['title'] . "\n" . $joke['content'] . "\n\n"; } write_ok_text($result); } elseif ($type == 'json') { write_ok($jokes); } else { write_error($GLOBALS['ERR_PARAMS_TYPE']); } }
write_error("Can't open file for write."); } //logic to read and save chunk posted with multipart if ($isMultiPart) { $filearr = pos($_FILES); if (!($input = file_get_contents($filearr['tmp_name']))) { write_error("Can't read from file."); } else { if (!fwrite($file, $input)) { write_error("Can't write to file."); } } } else { $input = file_get_contents("php://input"); if (!fwrite($file, $input)) { write_error("Can't write to file."); } } fclose($file); //Upload complete if size of saved temp file >= size of source file. if (filesize($filePath) >= $fileSize) { if (file_exists($dirPath . "/" . $filename)) { //delete file if exist unlink($dirPath . "/" . $filename); //or rename old or new file } //move file rename($filePath, $dirPath . "/" . $filename); //here You can do some other actions when upload complete echo "<response>File uploaded correctly</response>"; }
die; } else { //Success $response['success'] = 1; $response['message'] = "Changement de l'email effectué"; $response['value'] = $email; echo json_encode($response); } } } else { if (isset($_POST['old_password']) && $_POST['old_password'] != null && isset($_POST['new_password']) && $_POST['new_password'] != null) { $old_password = md5($_POST['old_password']); $new_password = md5($_POST['new_password']); $query = mysql_query("UPDATE mrbs_users SET password = '******' WHERE id = '{$id}' AND password = '******'"); if (!$query) { write_error(mysql_error()); die; } else { $response['success'] = 1; $response['message'] = "Enregistrement password effectué"; $response['value'] = ""; echo json_encode($response); } } else { $response['success'] = 0; $response['message'] = "Une erreur est survenue"; echo json_encode($response); } } } } else {
function op_revaluetok() { if (!welcome_here()) { return; } if (!get_input_string('tokname', 'token name', $tokname)) { return; } if (!get_input_int('newval', 'new token value', $newval)) { return; } if (!get_input_string('extname', 'extension name', $extname)) { return; } if (!get_input_int('extid', 'extension id', $extid)) { return; } // see if it's already in the database... $sqlnewval = db_escape_string($newval); $sql = 'select tok.*, ext.extname from alextreg_tokens as tok' . ' left outer join alextreg_extensions as ext' . ' on tok.extid=ext.id' . " where (tokenval={$newval})"; $query = do_dbquery($sql); if ($query == false) { return; } // error output is handled in database.php ... if (db_num_rows($query) > 0) { write_error('Please note the new token value is in use, which may be okay. Below is what a search turned up.'); render_token_list(false, $query); } // if db_free_result($query); $hex = ''; if (sscanf($newval, "0x%X", &$dummy) != 1) { $hex = sprintf(" (0x%X hex)", $newval); } // !!! FIXME: faster way to do this? // Just a small sanity check. $cookie = $_REQUEST['iamsure']; if (!empty($cookie) and $cookie == $_SERVER['REMOTE_ADDR']) { $sqltokname = db_escape_string($tokname); $sqlauthor = db_escape_string($_SERVER['REMOTE_USER']); // ok, nuke it. $sql = "update alextreg_tokens set tokenval={$newval}," . " lastedit=NOW(), lasteditauthor='{$sqlauthor}'" . " where tokenname='{$sqltokname}'"; if (do_dbupdate($sql) == 1) { update_papertrail("Token '{$tokname}' revalued to '{$newval}'{$hex}", $sql, $extid); do_showext($extname); } // if } else { $form = get_form_tag(); $htmlnewval = htmlentities($newval, ENT_QUOTES); $htmlextname = htmlentities($extname, ENT_QUOTES); $htmltokname = htmlentities($tokname, ENT_QUOTES); echo "About to change the value of a token named '{$htmltokname}' to {$newval}{$hex}.<br>\n"; echo "...if you're sure, click 'Confirm'...<br>\n"; echo "{$form}\n"; echo "<input type='hidden' name='iamsure' value='{$_SERVER['REMOTE_ADDR']}'>\n"; echo "<input type='hidden' name='extid' value='{$extid}'>\n"; echo "<input type='hidden' name='newval' value='{$htmlnewval}'>\n"; echo "<input type='hidden' name='tokname' value='{$htmltokname}'>\n"; echo "<input type='hidden' name='extname' value='{$htmlextname}'>\n"; echo "<input type='hidden' name='operation' value='op_revaluetok'>\n"; echo "<input type='submit' name='form_submit' value='Confirm'>\n"; echo "</form>\n"; } // else }
function get_param_key($key) { if (isset($_GET[$key]) && $_GET[$key] != '') { $param = $_GET[$key]; } else { write_error($GLOBALS['ERR_PARAMS_OTHER']); } return $param; }
// Builds jQuery bundle if (!isset($argv)) { die('register_argc_argv is not enabled'); } if (count($argv) < 3) { usage(); } // get dependency name $sourceRoot = $argv[1]; $dependency = $argv[2]; $outputPath = $argv[3]; // build bundle if (($dependencyJs = file_get_contents($filePath = $sourceRoot . '/src/js/dep/' . $dependency . '/fileUploader.' . $dependency . '.js')) === false) { read_error($filePath); } if (($coreJs = file_get_contents($filePath = $sourceRoot . '/src/js/fileUploader.core.js')) === false) { read_error($filePath); } if (($apiJs = file_get_contents($filePath = $sourceRoot . '/src/js/api/fileUploader.Uploader.js')) === false) { read_error($filePath); } if (($dependencyApiJs = file_get_contents($filePath = $sourceRoot . '/src/js/api/' . $dependency . '/fileUploader.' . $dependency . '.js')) === false) { read_error($filePath); } // build output code $output = '// File-Uploader ' . $dependency . ' API, build ' . date('Y/m/d H:i:s') . '. Get your own File Uploader at http://github.com/Evolver/File-Uploader' . "\n\n" . '// ' . 'src/js/dep/' . $dependency . '/fileUploader.' . $dependency . '.js' . "\n\n" . $dependencyJs . "\n\n" . '// ' . 'src/js/fileUploader.core.js' . "\n\n" . $coreJs . "\n\n" . '// ' . 'src/js/api/fileUploader.Uploader.js' . "\n\n" . $apiJs . "\n\n" . '// ' . 'src/js/api/' . $dependency . '/fileUploader.' . $dependency . '.js' . "\n\n" . $dependencyApiJs; // output bundled file if (!file_put_contents($outputPath, $output)) { write_error($outputPath); } echo 'Written to "' . $outputPath . '". If you wish to compress output file to a smaller size, use http://javascriptcompressor.com/ online tool to compress and obfuscate JavaScript code' . "\n";
<?php require_once dirname(dirname(dirname(__DIR__))) . '/autoload.php'; function write_error($msg) { $stderr = fopen('php://stderr', 'w'); fwrite($stderr, $msg); } $options = getopt("h:p:l:"); $exit_status = 0; if (!array_key_exists('h', $options)) { write_error("You must provide a host parameter (-h).\n"); $exit_status = 64; } if (!array_key_exists('p', $options)) { write_error("You must provide a port parameter (-p).\n"); $exit_status = 64; } if ($exit_status == 0) { $settings = array('host' => $options['h'], 'port' => $options['p']); if (array_key_exists('l', $options)) { $settings['listen_port'] = $options['l']; } $mysql_concentrator = new MySQLConcentrator\Server($settings); $mysql_concentrator->run(); } exit($exit_status);
function get_input_number($reqname, $reqtype, &$reqval, $defval = false) { if (!get_input_sanitized($reqname, $reqtype, $reqval, $defval)) { return false; } if (sscanf($reqval, "0x%X", &$hex) == 1) { // it's a 0xHEX value. $reqval = $hex; } if (!is_numeric($reqval)) { write_error("{$reqtype} isn't a number"); return false; } // if return true; }
die("Не удалось открыть файл для записи ошибки\r\n"); } fwrite($fp, date("Y-m-d H:i:s") . "\t{$text}\r\n"); fclose($fp); } function write_log($text) { $fp = fopen(__DIR__ . '/log/log.txt', 'a'); if (!$fp) { die("Не удалось открыть файл для записи лога\r\n"); } fwrite($fp, date("Y-m-d H:i:s") . "\t{$text}\r\n"); fclose($fp); } if (!extension_loaded('mysqli')) { write_error('Не установлено расширение MYSQL'); die; } function setLastdate($date = null) { // return; $date = !is_null($date) ? $date : date("Y-m-d H:i:s"); $fp = fopen(__DIR__ . '/lastdate.txt', 'w'); fwrite($fp, $date); fclose($fp); } function getLastdate() { $fname = __DIR__ . '/lastdate.txt'; if (file_exists($fname)) { return file_get_contents($fname);
// print_r($nopermisos); // print_r($ambpermisos); // $resultat = array_merge($nopermisos, $ambpermisos); if ($tot != 1) { echo "<br />El fitxer creat inclou només els cursos actius (apte per a ser publicat a la pàgina inicial)"; $fitxer = "/dades/wikiform/data/pages/z_gestio/aux/index_cursos.txt"; } else { echo "<br />El fitxer inclou tots els cursos, inclosos els inactius (destinat a la gestió)"; $fitxer = "/dades/wikiform/data/pages/z_gestio/aux/index_cursos_gestio.txt"; } $cami2 = "/dades/wikiform/data/media/"; $fitxer2 = $cami2 . "permisoswiki.csv"; //$fitxer2 = "/dades/wikiform/data/pages/z_gestio/aux/permisoswiki.csv"; $fitxer3 = "/dades/wikiform/data/pages/z_gestio/aux/permisoswiki.txt"; write_error('errors.log', "\n" . $alerta, 'a'); write_error('errors.log', "\n\n" . "Data de creació de l'índex de cursos: " . date("d/m/Y G:i:s"), 'a'); if (file_put_contents("/dades/wikiform/data/pages/z_gestio/aux/temp.txt", $resultat) === false) { if ($tot != 1) { echo "No s'ha pogur crear el fitxer temporal"; } } else { unlink($fitxer); rename("/dades/wikiform/data/pages/z_gestio/aux/temp.txt", $fitxer); echo "<br />Fitxer '{$fitxer}' creat amb èxit <br /><br />"; echo "<br />Cursos sense títol: <br />"; include 'errors.log'; } if (file_put_contents($cami2 . "temp2.txt", $fullcalcul) === false) { echo "No s'ha pogur crear el fitxer temporal"; } else { unlink($fitxer2);
function database_connection($query) { mysql_connect('localhost', 'root', '') or die(write_error("No connection possible.")); mysql_select_db('todo'); return mysql_query($query); }
function llegeixtitols($fitxer) { if (!file_exists($fitxer)) { return; } $codi = explode('/', $fitxer); $codi_curs = trim($codi[count($codi) - 2]); $existeix = false; // Llegeix l'arxiu index.txt on ha d'haver el títol del curs $linies = file($fitxer); $titols = array(); foreach ($linies as $linia) { // echo $linia; // Mirem el títol del curs $inici = strpos($linia, "<html><!--"); // primer $fi = strrpos($linia, "-->"); if ($fi > 0) { //Hi ha títol // Mirar si el codi del curs coincideix amb el directori $titols[] = substr($linia, $inici + 10, $fi - 10); $aux = explode("-", substr($linia, $inici + 10, $fi - 10)); if (strtoupper($codi_curs) == strtoupper(trim($aux[0]))) { $existeix = true; } else { $no_concorda = true; } } // Mirem títols de cada mòdul if (strpos($linia, "modul") > 0 || strpos($linia, "mòdul") > 0) { $inici = strpos($linia, "|"); $fi = strrpos($linia, "]]") - 1; if ($inici > 0) { $titols[] = substr($linia, $inici + 1, $fi - $inici); } } // Mirem data versió if (strpos($linia, "Descàrrega del curs") > 0 and substr($linia, 0, 6) != '<html>') { preg_match('/\\((.+)\\)/', $linia, $coincidencies); $titols['dataversio'] = $coincidencies[0]; } elseif (preg_match("/\\s([0-9]{4})\\s/", $linia, $coincidencies2) and strpos($linia, "2003") == 0) { $titols['dataversio'] .= " / " . rtrim($linia); } if (substr($linia, 0, 6) == "{{tag>") { $tags = rtrim(substr($linia, 6)); $titols['tags'] = substr($tags, 0, -2); } } if (!$existeix) { if ($no_concorda) { $fitxer = "DISCORDANÇA: " . $fitxer; } else { $fitxer = "SENSE TÍTOL: " . $fitxer; } write_error('errors.log', "\n" . $fitxer, 'a'); } return $titols; }
if (isset($pfrom) and $pfrom > 0) { $where_str .= " and (IF(s.status, s.specials_new_products_price, p.products_price) * if(gz.geo_zone_id is null, 1, 1 + (tr.tax_rate / 100) ) >= " . (double) $pfrom . ")"; } if (isset($pto) and $pto > 0) { $where_str .= " and (IF(s.status, s.specials_new_products_price, p.products_price) * if(gz.geo_zone_id is null, 1, 1 + (tr.tax_rate / 100) ) <= " . (double) $pto . ")"; } if (!empty($pfrom) || !empty($pto)) { $where_str .= " group by p.products_id, tr.tax_priority"; } // Ende des Codeblocks aus advanced_search_result.php $listing_sql = $select_str . $from_str . $where_str; // Zaehler fuer die Anzahl der Produkte, die zurueckgegeben wird $c_size = MAX_ITEMS; if (!empty($new_size)) { if ($new_size <= 0) { write_error(1303, $requestArray); } if ($new_size < MAX_ITEMS) { $c_size = $new_size; } } // TODO: Tabelarische u.a. Versandkosten werden (noch) nicht beruecksichtigt. // Siehe auch elmar_products.php! $free_shipping = defined('MODULE_ORDER_TOTAL_SHIPPING_FREE_SHIPPING') && MODULE_ORDER_TOTAL_SHIPPING_FREE_SHIPPING == 'true'; $shipping_flat_status = defined('MODULE_SHIPPING_FLAT_STATUS') && MODULE_SHIPPING_FLAT_STATUS == 'True'; if ($shipping_flat_status) { // Standard: Flat-Preis ist netto. Bei Brutto Shops muss MwSt addiert werden, sonst nicht. // [Ein Beitrag von Kai Schulz] $shipping_flat_cost = tep_add_tax(MODULE_SHIPPING_FLAT_COST, tep_get_tax_rate(MODULE_SHIPPING_FLAT_TAX_CLASS, STORE_COUNTRY, MODULE_SHIPPING_FLAT_ZONE)); } $partner_id = false;
include_once 'base.php'; //Доступ к локальной базе данных $mysqli = new mysqli($base['host'], $base['user'], $base['password'], $base['base']); $mysqli->query("SET NAMES UTF8"); if (mysqli_connect_errno()) { write_error("Соединение с базой данных потерпело неудачу"); die; } // Отправляем запрос к базе данных $result = $mysqli->query($query); echo $mysqli->error; if (mysqli_affected_rows($mysqli) > 0) { //Создаем файл для записи выгруженных данных $fp = fopen($path . $file_name . '.sql', 'w'); if (!$fp) { write_error("Не удалось создать файл выгрузки"); die; } $toFile = ''; $i2 = 0; /* Выборка результатов запроса */ while ($row = mysqli_fetch_assoc($result)) { /* Убираем лишние пробелы */ $row = array_map(function ($array) { return trim($array); }, $row); // $row = array_merge($row, $config['clinic'],['created' => time()]); $q2 = ''; foreach ($row as $value) { // die($value); $q2 .= "'" . addslashes($value) . "',";
function do_showext($extname) { $sqlextname = db_escape_string($extname); $sql = "select * from alextreg_extensions" . " where extname='{$sqlextname}'"; if (!is_authorized_vendor()) { $sql .= " and (public=1)"; } $query = do_dbquery($sql); if ($query == false) { return; } else { if (db_num_rows($query) == 0) { write_error('No such extension.'); } else { // just in case there's more than one for some reason... while (($row = db_fetch_array($query)) != false) { show_one_extension($row); } } } // else db_free_result($query); }