function catalogo($tid, $i) { $database = new DB(); $query = "SELECT categoria_id,categoria FROM categoria\n\t\twhere 1 "; $results = $database->get_results($query); foreach ($results as $row) { echo "<tr ><td colspan=3>" . $row['categoria'] . " </td></tr>"; $query = "SELECT descuento from temporada where temporada_Id={$tid}"; list($descuento) = $database->get_row($query); $query = "SELECT subcategoria_id,subcategoria FROM subcategoria where categoria_id=" . $row['categoria_id']; $subs = $database->get_results($query); foreach ($subs as $sub) { $query = "SELECT count(producto_id) as productos FROM producto\n\t\t\t\t\twhere producto.temporada_id={$tid} AND subcategoria_id=" . $sub['subcategoria_id']; if ($i) { $query .= " AND producto.descuento={$descuento}"; } else { $query .= " AND producto.descuento<>{$descuento}"; } list($productos) = $database->get_row($query); if ($productos) { echo "<tr><td></td><td align=right>\n\t\t\t\t\t\t<a href=/index.php?data=catalogo&subcat=" . $sub['subcategoria_id'] . "&tid={$tid}>" . $sub['subcategoria'] . "</a>\n </td>\n\t\t\t\t\t\t<td>{$productos}</td></tr>"; } } } }
/** * Get the userWhereIs info */ function get_user_localization($user_localization_id = null, $online_time = USER_ONLINE_TIME) { if (!$user_localization_id) { $user_localization_id = $this->get_user_localization_id(); } return DB::get_row("SELECT " . DB_PREFIX . "user.*, " . DB_PREFIX . "user_localization.*\r\n\t\t\t\t\t\t\tFROM " . DB_PREFIX . "user_localization\r\n\t\t\t\t\t\t\tLEFT JOIN " . DB_PREFIX . "user ON " . DB_PREFIX . "user_localization.user_id = " . DB_PREFIX . "user.user_id\r\n\t\t\t\t\t\t\tWHERE ( " . TIME . " - time ) < {$online_time}\r\n\t\t\t\t\t\t\tAND user_localization_id = {$user_localization_id}"); }
/** * static function get * Returns a single comment, by ID * * <code> * $post = Post::get( 10 ); * </code> * * @param int $id An ID * @return array A single Comment object */ static function get($id = 0) { if (!$id) { return false; } return DB::get_row('SELECT * FROM {comments} WHERE id = ?', array($id), 'Comment'); }
/** * static function get * Returns a single traffum, by ID * * @param int An ID * @return array A single Traffum object **/ static function get($ID = 0) { if (!$ID) { return false; } return DB::get_row('SELECT * FROM {link_traffic} WHERE id = ?', array($ID), 'Traffum'); }
public function test_update_block() { $params = array( 'title' => $this->title, 'type' => $this->type ); $block = new Block($params); $block->insert(); $block_id = $block->id; $updated_title = 'Updated Block Title'; $updated_type = 'Updated Block Type'; $block->title = $updated_title; $block->type = $updated_type; $block->update(); $updated_block = DB::get_row('SELECT * FROM {blocks} WHERE id=:id', array('id' => $block_id), 'Block'); $this->assert_equal( $updated_block->title, $updated_title, 'Block title should be updated' ); $this->assert_equal( $updated_block->type, $updated_type, 'Block type should be updated' ); // Try updating data as well $block->data_test = 'foo'; $block->update(); $updated_block = DB::get_row('SELECT * FROM {blocks} WHERE id=:id', array('id' => $block_id), 'Block'); $this->assert_equal( $updated_block->data_test, $block->data_test, 'Block data should be updated' ); $block->delete(); }
/** * Return contents of silo directories. This is what the publish page uses. * */ public function silo_dir($path) { $section = strtok($path, '/'); $results = array(); $user = User::identify(); // If the root is being requested, return all scratchpads for this user if ($section == '') { $scratchpads = DB::get_results('SELECT id, name, slug FROM {scratchpads} WHERE user_id = ?', array($user->id)); foreach ($scratchpads as $scratchpad) { $results[] = new MediaAsset(self::SILO_NAME . '/' . $scratchpad->slug, true, array('title' => ucfirst($scratchpad->name))); } } else { $scratchpad = DB::get_row('SELECT id, slug, template FROM {scratchpads} WHERE slug = ? AND user_id = ?', array($section, $user->id)); // Get a template, either this scratchpad's or the default. $template = ''; if (!isset($scratchpad->template)) { $template = DB::get_value('SELECT template FROM {scratchpads} WHERE slug = ? AND user_id = ?', array('default', $user->id)); } else { $template = $scratchpad->template; } $entries = DB::get_results('SELECT * FROM {scratchpad_entries} WHERE scratchpad_id = ?', array($scratchpad->id)); foreach ($entries as $entry) { $this->entry = $entry; // Insert relevant parts in the template $output = preg_replace_callback('%\\{\\$(.+?)\\}%', array(&$this, 'replace_parts'), $template); $results[] = new MediaAsset(self::SILO_NAME . '/' . $scratchpad->slug . '/' . $entry->slug, false, array('filetype' => 'scratchpad', 'title' => $entry->title, 'url' => $entry->url, 'content' => $entry->content, 'output' => $output)); } } return $results; }
function subcategorias($categoria_id) { $database = new DB(); $query = "SELECT categoria FROM categoria where categoria_id={$categoria_id} "; list($categoria) = $database->get_row($query); echo "<div class=\"box-header\">\n\t\t\t\t\t\t<h2><i class=\"halflings-icon align-justify\"></i><span class=\"break\"></span>Subcategorias de: " . strtoupper($categoria) . " </h2>\n\t\t\t\t\t\t<div class=\"box-icon\">\n\t\t\t\t\t\t\t<a href=\"#\" class=\"btn-setting\"><i class=\"halflings-icon wrench\"></i></a>\n\t\t\t\t\t\t\t<a href=\"#\" class=\"btn-minimize\"><i class=\"halflings-icon chevron-up\"></i></a>\n\t\t\t\t\t\t\t<a href=\"#\" class=\"btn-close\"><i class=\"halflings-icon remove\"></i></a>\n\t\t\t\t\t\t</div>\n\t\t\t\t\t</div>\n\t\t\t\t\t<div class=\"box-content\">"; echo "\t\t\t<form class=\"form-horizontal\" action=\"/functions/crud_proveedores.php\">\n\t\t\t\t\t\t\t<fieldset>\n\n\t\t\t\t\t\t\t\t\n\t\t\t\t\t\t\t\t<div class=\"control-group \">\n\t\t\t\t\t\t\t\t\n\t\t\t\t\t\t\t\t<label class=\"control-label\" for=\"subcategoria\">SubCategoria</label>\n\t\t\t\t\t\t\t\t<div class=\"controls\">\n\t\t\t\t\t\t\t\t <input class=\"input-large\" id=\"subcategoria\" name=\"subcategoria\" type=\"text\" value=\"" . strtoupper($rfc) . "\"> \n\t\t\t\t\t\t\t\t<button type=\"submit\" class=\"btn btn-primary\">Agregar SubCategoria</button>\n\t\t\t\t\t\t\t\t</div>\n\t\t\t\t\t\t\t </div>\n\t\t\t\t\t\t\t\n\n\t\t\t\t\t\t\t</fieldset>\n\t\t\t\t\t\t</form>"; echo "<table class=\"table table-striped table-bordered \">\n\t\t\t\t\t\t\t <thead>\n\t\t\t\t\t\t\t\t <tr>\n\t\t\t\t\t\t\t\t\t <th>Subcategoria</th>\n\t\t\t\t\t\t\t\t\t <th>Productos</th>\n\t\t\t\t\t\t\t\t\t <th>Acciones</th>\n\t\t\t\t\t\t\t\t </tr>\n\t\t\t\t\t\t\t </thead> \n\t\t\t\t\t\t\t <tbody>"; $query = "SELECT subcategoria_id,subcategoria FROM subcategoria where categoria_id=" . $categoria_id; $subs = $database->get_results($query); foreach ($subs as $sub) { $query = "SELECT count(producto_id) as productos FROM producto \n\t\t\t\t\twhere subcategoria_id=" . $sub['subcategoria_id']; list($productos) = $database->get_row($query); echo "<tr><td align=right> \n\t\t\t\t\t\t<a href=/index.php?data=catalogo&subcat=" . $sub['subcategoria_id'] . ">" . $sub['subcategoria'] . "</a> </td>\n\t\t\t\t\t\t<td>{$productos}</td></tr>"; } echo "\t\t\t\t </tbody>\n\t\t\t\t\t\t </table> \n\t\t\t\t\t</div>\n\t\t\t\t"; }
/** * Get a Cron Job by name or id from the Database. * * @param mixed $name The name or id of the cron job to retreive. * @return \Habari\CronJob The cron job retreived from the DB */ static function get_cronjob($name) { if (is_int($name)) { $cron = DB::get_row('SELECT * FROM {crontab} WHERE cron_id = ?', array($name), '\\Habari\\CronJob'); } else { $cron = DB::get_row('SELECT * FROM {crontab} WHERE name = ?', array($name), '\\Habari\\CronJob'); } return $cron; }
function catalogo($proveedor_id) { $database = new DB(); $query = "SELECT categoria_id,categoria FROM categoria \n\t\twhere 1 "; $results = $database->get_results($query); foreach ($results as $row) { echo "<tr >\n\t\t\t<td><font >" . $row['categoria'] . " </td>\n\t\t\t<td><font > </td>\n\t\t\t<td><font > </td>\n\t\t\t<td><font > </td>\n\t\t\t<td><font > </td>\n\t\t\t</tr>"; $query = "SELECT subcategoria_id,subcategoria FROM subcategoria where categoria_id=" . $row['categoria_id']; $subs = $database->get_results($query); foreach ($subs as $sub) { $query = "SELECT MIN(precio_compra) as precio_min,MAX(precio_compra) as precio_max FROM producto \n\t\t\t\t\t\twhere subcategoria_id=" . $sub['subcategoria_id'] . " AND proveedor_id={$proveedor_id}"; list($precio_min, $precio_max) = $database->get_row($query); $query = "SELECT count(producto_id) as productos FROM producto \n\t\t\t\t\twhere subcategoria_id=" . $sub['subcategoria_id'] . " AND proveedor_id={$proveedor_id}"; list($productos) = $database->get_row($query); echo "<tr><td></td><td align=right> \n\t\t\t\t\t\t<a href=/index.php?data=proveedores&op=detalles&pid={$proveedor_id}&subcat=" . $sub['subcategoria_id'] . ">" . $sub['subcategoria'] . "</a> </td>\n\t\t\t\t\t\t<td>{$productos}</td><td style='text-align:right'>" . dinero($precio_min) . "</td><td style='text-align:right'>" . dinero($precio_max) . "</td></tr>"; } } }
public static function getGroupInfo($groupid) { $groupid = DB::escape($groupid); $query = 'SELECT * FROM ' . TABLE_PREFIX . 'groups WHERE '; if (is_numeric($groupid)) { $query .= 'id=' . $groupid; } else { $query .= 'name=\'' . $groupid . '\''; } return DB::get_row($query); }
/** * Get the specific award of a pilot, mainly to see if they have it * * @param int $pilotid Pilot ID * @param int $awardid Award ID * @return array Row of the award * */ public static function GetPilotAward($pilotid, $awardid) { $pilotid = intval($pilotid); $awardid = intval($awardid); $sql = 'SELECT g.id, g.pilotid, a.* FROM ' . TABLE_PREFIX . 'awardsgranted g INNER JOIN ' . TABLE_PREFIX . 'awards a ON a.awardid=g.awardid WHERE g.`pilotid`=' . $pilotid . ' AND g.`awardid`=' . $awardid; return DB::get_row($sql); }
public static function check_hoursdiff($name, $age_hours) { $name = strtoupper($name); $sql = 'SELECT `lastupdate` FROM ' . TABLE_PREFIX . "updates\n\t\t\t\tWHERE DATE_SUB(CURDATE(), INTERVAL {$age_hours} HOUR) <= lastupdate\n\t\t\t\t\tAND name='{$name}'"; $row = DB::get_row($sql); if (!$row) { return false; } return true; }
private function content_query($format, $params) { //basic content query for id if (isset($params['id'])) { $field = array($params['id']); //initial test query for single row content $db_content = DB::get_row("SELECT contenttext FROM content WHERE contentid=?", $field); $db_content = $db_content['contenttext']; } self::$default_content = $db_content; }
/** * Save the fuel price in our local cache so the api * server won't get hammered * * @param object $xmlObj The object with the fuel data * @return mixed This is the return value description * */ protected static function save_cached_price($xmlObj) { $query = "SELECT * \n\t\t\t\t\tFROM `" . TABLE_PREFIX . "fuelprices`\n\t\t\t\t\tWHERE `icao`='{$xmlObj->icao}'"; $res = DB::get_row($query); if ($res) { $query = "UPDATE `" . TABLE_PREFIX . "fuelprices`\n\t\t\t\t\t\tSET `icao`='{$xmlObj->icao}', \n\t\t\t\t\t\t\t`lowlead`='{$xmlObj->lowlead}', \n\t\t\t\t\t\t\t`jeta`='{$xmlObj->jeta}', \n\t\t\t\t\t\t\tdateupdated=NOW()\n\t\t\t\t\t\tWHERE `id`={$res->id}"; } else { $query = "INSERT INTO `" . TABLE_PREFIX . "fuelprices`\n\t\t\t\t\t\t\t(`icao`, \n\t\t\t\t\t\t\t `lowlead`, \n\t\t\t\t\t\t\t `jeta`,\n\t\t\t\t\t\t\t `dateupdated`)\n\t\t\t\t\t\tVALUES ('{$xmlObj->icao}', \n\t\t\t\t\t\t\t\t'{$xmlObj->lowlead}', \n\t\t\t\t\t\t\t\t'{$xmlObj->jeta}', \n\t\t\t\t\t\t\t\tNOW())"; } DB::query($query); }
/** * Read session data from the database to return into the $_SESSION global. * Verifies against a number of parameters for security purposes. * * @param string $session_id The id generated by PHP for the session. * @return string The retrieved session. */ static function read($session_id) { // for offline testing $remote_address = isset($_SERVER['REMOTE_ADDR']) ? $_SERVER['REMOTE_ADDR'] : '127.0.0.1'; // not always set, even by real browsers $user_agent = isset($_SERVER['HTTP_USER_AGENT']) ? $_SERVER['HTTP_USER_AGENT'] : ''; $session = DB::get_row('SELECT * FROM {sessions} WHERE token = ?', array($session_id)); // Verify session exists if (!$session) { self::$initial_data = false; return false; } $dodelete = false; if (!defined('SESSION_SKIP_SUBNET') || SESSION_SKIP_SUBNET != true) { // Verify on the same subnet $subnet = self::get_subnet($remote_address); if ($session->subnet != $subnet) { $dodelete = true; } } // Verify expiry if (HabariDateTime::date_create(time())->int > $session->expires) { Session::error(_t('Your session expired.'), 'expired_session'); $dodelete = true; } // Verify User Agent if ($user_agent != $session->ua) { $dodelete = true; } // Let plugins ultimately decide $dodelete = Plugins::filter('session_read', $dodelete, $session, $session_id); if ($dodelete) { $sql = 'DELETE FROM {sessions} WHERE token = ?'; $args = array($session_id); $sql = Plugins::filter('sessions_clean', $sql, 'read', $args); DB::query($sql, $args); return false; } // Do garbage collection, since PHP is bad at it $probability = ini_get('session.gc_probability'); // Allow plugins to control the probability of a gc event, return >=100 to always collect garbage $probability = Plugins::filter('gc_probability', is_numeric($probability) && $probability > 0 ? $probability : 1); if (rand(1, 100) <= $probability) { self::gc(ini_get('session.gc_maxlifetime')); } // Throttle session writes, so as to not hammer the DB self::$initial_data = ini_get('session.gc_maxlifetime') - $session->expires + HabariDateTime::date_create(time())->int < 120 ? $session->data : FALSE; return $session->data; }
function movimientos($cliente_id, $saldo) { $database = new DB(); $fecha_hoy = date("Y-m-d H:i:s"); $fecha = fechaminusmonth($fecha_hoy, 3); $query = "SELECT sum(cantidad) FROM cliente,movimiento,admin,tipomov \n\t\twhere movimiento.cliente_id={$cliente_id} AND movimiento.tipomov_id=tipomov.tipomov_id AND movimiento.cliente_id=cliente.cliente_id \n\t\tAND movimiento.admin_id=admin.admin_id AND fecha >= '{$fecha}' AND tipomov.tmov=1 ORDER BY movimiento.fecha ASC limit 100"; list($total_abonos) = $database->get_row($query); $query = "SELECT sum(cantidad) FROM cliente,movimiento,admin,tipomov \n\t\twhere movimiento.cliente_id={$cliente_id} AND movimiento.tipomov_id=tipomov.tipomov_id AND movimiento.cliente_id=cliente.cliente_id \n\t\tAND movimiento.admin_id=admin.admin_id AND fecha >= '{$fecha}' AND tipomov.tmov=0 ORDER BY movimiento.fecha ASC limit 100"; list($total_cargos) = $database->get_row($query); $query = "SELECT factura_id,fecha, cantidad, tipomov.tipomov,tmov, admin.nombre,total_ultimo FROM cliente,movimiento,admin,tipomov \n\t\twhere movimiento.cliente_id={$cliente_id} AND movimiento.tipomov_id=tipomov.tipomov_id AND movimiento.cliente_id=cliente.cliente_id \n\t\tAND movimiento.admin_id=admin.admin_id AND fecha >= '{$fecha}' ORDER BY movimiento.fecha ASC limit 100"; $saldo = $saldo + $total_cargos - $total_abonos; $results = $database->get_results($query); $i = 0; foreach ($results as $row) { if ($row['tmov'] == 0 || $row['tmov'] == 1) { $i += 1; if ($row['tmov'] == 0) { $saldo -= $row['cantidad']; } if ($row['tmov'] == 1) { $saldo += $row['cantidad']; } echo "<tr >\n\t\t\t<td align=right><font > {$i} </td>\n\t\t\t<td><a class=\"hidden-print\" href=\"/index.php?data=clientes&op=factura&fid=" . $row['factura_id'] . "\">" . $row['fecha'] . "<a>\n\t\t\t\t<a class=\"visible-print\" >" . fechamysqltomx($row['fecha'], 1) . "<a>\n\t\t\t </td>"; if ($row['tmov'] == 0) { echo "<td align=center>---</td>\n\t\t\t\t<td align=right> <font >" . $row['cantidad'] . " </td>"; } if ($row['tmov'] == 1) { echo "\n\t\t\t\t<td align=right> <font >" . $row['cantidad'] . " </td>\n\t\t\t\t<td align=center>---</td>"; } $row['admin_id'] = isset($row['admin_id']) ? $row['admin_id'] : ''; echo "<td><font ><b>" . dinero($saldo) . "</td>\n\t\t\t<td><font >" . $row['tipomov'] . "</td>"; "<td hidden> <font >" . $row['admin_id'] . "</td>"; echo "</tr>"; } } }
/** * action: post_update_after * * @access public * @param object $post * @return void */ public function action_post_update_after($post) { if ($post->content_type == Post::type('revision')) { return; } $rev_count = DB::get_row('SELECT COUNT(*) AS count FROM {posts} LEFT JOIN {postinfo} ON {posts}.id = {postinfo}.post_id WHERE {postinfo}.name = \'revision_post_id\' AND {postinfo}.value = :post_id', array('post_id' => $post->id)); $revision = $rev_count->count + 1; $rev_post = clone $post; $rev_post->id = null; $rev_post->slug = 'revision-' . $revision . ':' . $rev_post->slug; $rev_post->content_type = Post::type('revision'); $rev_post->info->revision = $revision; $rev_post->info->revision_post_id = $post->id; DB::insert(DB::table('posts'), array_diff_key($rev_post->to_array(), $rev_post->list_excluded_fields())); $rev_post->info->commit(DB::last_insert_id()); }
/** * StatsTest::testPaxCount() * * @return void */ public function testPaxCount() { $total = DB::get_row('SELECT SUM(`load`) AS `total` FROM phpvms_pireps WHERE `flighttype`=\'P\' AND `accepted`=' . PIREP_ACCEPTED); $this->assertEquals($total->total, StatsData::TotalPaxCarried(), 'StatsData::TotalPaxCarried(NO CODE)'); $airlines = OperationsData::getAllAirlines(true); foreach ($airlines as $airline) { $pilotCount = StatsData::TotalPaxCarried($airline->code); $total = DB::get_row('SELECT SUM(`load`) AS `total` FROM phpvms_pireps WHERE accepted =' . PIREP_ACCEPTED . ' AND flighttype = \'P\' AND code = \'' . $airline->code . '\''); $this->assertEquals($total->total, $pilotCount, 'StatsData::TotalPaxCarried(' . $airline->code . ')'); } }
public static function get_articles($cate_id, $page, $page_size = 10, $order = 'id~desc') { $ret = []; $where = ''; if ($cate_id != 0) { $where = "where category_id={$cate_id}"; } $db = new DB([]); $db->connect(); $sql = "select count(*) as cnt from msf_article {$where}"; $result = $db->get_row($sql); $total = $result['cnt']; $total_page = 0; $total_page = ceil($total / $page_size); $start = ($page - 1) * $page_size; $limit = $page_size; //$page * $page_size - 1; $order_tag = explode('~', $order); $sql = "select * from msf_article {$where} order by `{$order_tag[0]}` {$order_tag[1]} limit {$start}, {$limit}"; $articles = $db->get_results($sql); $sql = "select id, name, alias from msf_category"; $cates = $db->get_results($sql); $cate = []; foreach ($cates as $idx => $data) { $cate[$data['id']] = [$data['name'], $data['alias']]; } $sql = "select id, name from msf_user"; $users = $db->get_results($sql); $user = []; foreach ($users as $idx => $data) { $user[$data['id']] = $data['name']; } foreach ($articles as $key => $article) { if (array_key_exists($article['category_id'], $cate)) { $articles[$key]['category_name'] = $cate[$article['category_id']][0]; $articles[$key]['category_alias'] = $cate[$article['category_id']][1]; } } foreach ($articles as $key => $value) { if (array_key_exists($value['create_user'], $user)) { $articles[$key]['create_user'] = $user[$value['create_user']]; } } $ret = ['page_info' => ['total_page' => $total_page, 'cur_page' => $page, 'page_size' => $page_size], 'articles' => $articles]; return $ret; }
public static function pilot_pay($pilotid) { $ft = "SELECT flighttime FROM phpvms_pireps WHERE pilotid = '{$pilotid}' ORDER BY submitdate DESC"; $flttme = DB::get_row($ft); $hr = intval($flttme->flighttime); $mn = ($flttme->flighttime - $hr) * 100; $min = $hr * 60 + $mn; $fr = "SELECT pilotpay FROM phpvms_pireps WHERE pilotid = '{$pilotid}' ORDER BY submitdate DESC"; $payrate = DB::get_row($fr); $pay = $payrate->pilotpay / 60; $pp = "SELECT totalpay FROM phpvms_pilots WHERE pilotid = '{$pilotid}'"; $ppay = DB::get_row($pp); $pipay = $payrate->totalpay; $ftupdt = $min * $pay; $ttalpay = $ftupdt + $pipay; $totalpay = ROUND($ttalpay, 2); $updt = "UPDATE phpvms_pilots SET totalpay = '{$totalpay}' + totalpay WHERE pilotid = '{$pilotid}'"; DB::query($updt); }
function autocupon($factura_id) { $database = new DB(); $query = "SELECT cantidad,sku,cupontipo_id,fecha_fin,compra_minima from cupones where factura_id='{$factura_id}'"; list($cantidad, $cupon_sku, $cupontipo_id, $fecha_fin, $compra_minima) = $database->get_row($query); if ($cantidad) { echo "<table width=310 style='border:2px dotted black'>"; echo "<tr><td align=center>CUPON</td></tr>"; echo "<tr><td align=center>BUENO POR</td></tr>"; echo "<tr><td align=center><font size=+3><b>\$ " . dinero($cantidad) . " MX<b></font></td></tr>"; echo "<tr><td align=center>Compra Minima: \$ " . dinero($compra_minima) . " MX</td></tr>"; echo "<tr><td align=center><font size=-1>Valido hasta: " . fechamysqltomx($fecha_fin, "letra") . "</center></font></td></tr>"; echo "<tr><td align=center> <img width=310 src=\"barcode.php?text=" . $cupon_sku . "\" alt=\"barcode\" /></td></tr>"; echo "<tr><td align=center><font size=-1>Promocion no reembolsable en efectivo, ni combinable con otras promociones\n o cupones. <br>No aplica con productos en LIQUIDACION</font></td></tr>"; echo "</table>"; return $cupon_sku; } else { return ""; } }
/** * Add a bid */ public static function addBid($pilotid, $routeid) { $pilotid = DB::escape($pilotid); $routeid = DB::escape($routeid); if (DB::get_row('SELECT bidid FROM ' . TABLE_PREFIX . 'bids WHERE pilotid=' . $pilotid . ' AND routeid=' . $routeid)) { return false; } $pilotid = DB::escape($pilotid); $routeid = DB::escape($routeid); $sql = 'INSERT INTO ' . TABLE_PREFIX . 'bids (pilotid, routeid, dateadded) VALUES (' . $pilotid . ', ' . $routeid . ', NOW())'; DB::query($sql); self::setBidOnSchedule($routeid, DB::$insert_id); if (DB::errno() != 0) { return false; } return true; }
public static function ProcessLogin($useridoremail, $password) { # Allow them to login in any manner: # Email: blah@blah.com # Pilot ID: VMA0001, VMA 001, etc # Just ID: 001 if (is_numeric($useridoremail)) { $useridoremail = $useridoremail - intval(Config::Get('PILOTID_OFFSET')); $sql = 'SELECT * FROM ' . TABLE_PREFIX . 'pilots WHERE pilotid=' . $useridoremail; } else { if (preg_match('/^.*\\@.*$/i', $useridoremail) > 0) { $emailaddress = DB::escape($useridoremail); $sql = 'SELECT * FROM ' . TABLE_PREFIX . 'pilots WHERE email=\'' . $useridoremail . '\''; } elseif (preg_match('/^([A-Za-z]*)(.*)(\\d*)/', $useridoremail, $matches) > 0) { $id = trim($matches[2]); $id = $id - intval(Config::Get('PILOTID_OFFSET')); $sql = 'SELECT * FROM ' . TABLE_PREFIX . 'pilots WHERE pilotid=' . $id; } else { return false; } } $password = DB::escape($password); $userinfo = DB::get_row($sql); if (!$userinfo) { return false; } if ($userinfo->retired == 1) { return false; } //ok now check it $hash = md5($password . $userinfo->salt); if ($hash == $userinfo->password) { return true; } else { return false; } }
function generar_cupones($cuid, $cuantos, $admin_id, $fecha_ini, $fecha_fin) { $array = isset($array) ? $array : ""; $database = new DB(); echo $query = "SELECT cupon_id,cantidad,cupontipo_id,compra_minima FROM cupon WHERE cupon_id='{$cuid}' limit 1"; list($cupon_id, $cantidad, $cupontipo_id, $compra_minima) = $database->get_row($query); $query = "SELECT sku FROM cupones ORDER BY sku DESC limit 1"; list($sku) = $database->get_row($query); $query = "SELECT bulk FROM cupones GROUP BY bulk ORDER BY bulk DESC limit 1"; list($bulk) = $database->get_row($query); $bulk = $bulk + 1; if ($sku == 0) { $sku = "10102000320000"; } $i = isset($i) ? $i : 30000; $k = isset($k) ?: 0; $residuo = $cuantos % 5; $cuantos = floor($cuantos / 5); while ($m < $cuantos) { do { $sku = $sku + $i; $values .= "('{$cupon_id}','{$sku}','{$fecha_ini}','{$fecha_fin}','{$cantidad}','{$cupontipo_id}','{$compra_minima}','0','{$admin_id}','{$bulk}'),"; $k++; } while ($k < 5); $k = 0; $m++; //echo $values."<br>"; $longitud = strlen($values); $values[$longitud - 1] = ' '; $query = "insert into cupones (cupon_id,sku,fecha_ini,fecha_fin,cantidad,cupontipo_id,compra_minima,activo,admin_id,bulk) values {$values}"; $database->query($query); $values = ""; } if ($residuo) { do { $sku = $sku + $i; $values .= "('{$cupon_id}','{$sku}','{$fecha_ini}','{$fecha_fin}','{$cantidad}','{$cupontipo_id}','{$compra_minima}','0','{$admin_id}','{$bulk}'),"; $k++; } while ($k < $residuo); //echo $values; $longitud = strlen($values); $values[$longitud - 1] = ' '; $query = "insert into cupones (cupon_id,sku,fecha_ini,fecha_fin,cantidad,cupontipo_id,compra_minima,activo,admin_id,bulk) values {$values}"; $database->query($query); } return 0; }
/** * Returns a Tag object based on a supplied ID * * @param tag_id The ID of the tag to retrieve * @return A Tag object */ public static function get_by_id($tag) { /* * A LEFT JOIN is needed here to accomodate tags not yet * related to a post, like the default "habari" tag... */ return DB::get_row('SELECT t.id AS id, t.tag_text AS tag, t.tag_slug AS slug, COUNT(tp.tag_id) AS count FROM {tags} t LEFT JOIN {tag2post} tp ON t.id=tp.tag_id WHERE id = ? GROUP BY id, tag, slug', array($tag)); }
/** * Get list product by condition tolerances and weight of extra field * * @author MinhNV * Date 2010/08/18 */ private function getListProductByCondOfExtraField() { $cat_product_id = Url::get('cat_product_id', 0); $product_id = Url::get('product_id', 0); $cur_page = Url::get('page_no', 0); $table = CGlobal::TABLE_PRODUCTS_PRODUCT; $aryExtraField = array(); $aryExtraProduct = array(); $aryProduct = array(); $aryData = array(); $query = ''; $fq = array(); if ($cat_product_id > 0 && $product_id > 0) { $aryExtra = array(); $table = SoLib::getTableProduct($cat_product_id, $product_id); $aryExtra = DB::get_row('SELECT name,extra_fields FROM ' . $table . ' WHERE id= ' . $product_id . ' '); if ($aryExtra['extra_fields'] != '') { $objJSON = new Services_JSON(); $aryExtraProduct = objectToArray($objJSON->decode($aryExtra['extra_fields'])); } $aryExtraField = $this->getListExtraField($cat_product_id); //if($cat_product_id > 0) { // $query .= '( published:1 AND category_id:'.$cat_product_id.' AND min_price:[1 TO *] AND max_price:[1 TO *]) AND '; //} //else { // $query .= '( published:1 AND min_price:[1 TO *] AND max_price:[1 TO *]) AND '; //} $fq[] = "published:1 AND status:1"; if ($cat_product_id > 0) { $query .= '( category_id:' . $cat_product_id . ' AND min_price:[1 TO *] AND max_price:[1 TO *]) AND '; } else { $query .= '( min_price:[1 TO *] AND max_price:[1 TO *]) AND '; } $querySolr = ''; $querySolr = $this->buildQueryFromTolerancesAndWeightOfExtraField($aryExtraField, $aryExtraProduct); if ($querySolr == '') { if (strlen($query) > 0) { $query = substr($query, 0, strlen($query) - 4); } } else { $query .= '(' . $querySolr . ')'; } //add them dieu kien search name de cho chinh xac if ($aryExtra['name'] != '') { $objLib = new SoLib(); $query .= ' AND name:' . $objLib->escapeSolrKeyword(trim($aryExtra['name'])); } //if($query != '') { // //} //if (strlen($query) > 0) { // $query = substr($query, 0, (strlen($query) - 4)); //} //var_dump($query); $params = array(); $params['fl'] = 'id, name, min_price, max_price, num_classified, images, date, description'; //$params['fq'] = "-id : $product_id"; $fq[] = "-id : {$product_id}"; $params['fq'] = $fq; if ($query != "") { $solr = Solr::getInstanceProduct(); $start = 0; $offset = self::NUMBER_PER_PAGE; $responseCheck = $solr->search($query, 0, 0); $total_row = 0; $paging = ''; if ($responseCheck) { if ($responseCheck->getHttpStatus() == 200) { $total_row = $responseCheck->response->numFound; if ($total_row > 0) { $url_path = 'ajax.php?act=so_advanced&code=get_list_product_extra_field&cat_product_id=' . $cat_product_id . '&product_id=' . $product_id; BMPaging::AjaxPagingSolr($paging, $start, $total_row, $offset, self::NUMBER_PAGE_SHOW, 'page_no', true, $url_path, 'paging_ajax_extra_field_template'); $response = $solr->search($query, $start, $offset, $params); if ($response->getHttpStatus() == 200) { if ($response->response->numFound > 0) { $i = 0; foreach ($response->response->docs as $doc) { $aryProduct[$i]['id'] = $doc->id; $aryProduct[$i]['name'] = $doc->name; $aryProduct[$i]['min_price'] = number_format($doc->min_price, 0, '.', '.'); $aryProduct[$i]['max_price'] = number_format($doc->max_price, 0, '.', '.'); $aryProduct[$i]['num_classified'] = $doc->num_classified; $aryProduct[$i]['description'] = $doc->description; $aryProduct[$i]['images'] = SoImg::getImage($doc->images, $doc->id, SoImg::FOLDER_PRODUCT, $doc->date, '70x0'); $i++; } } } else { $aryData['msg'] = 'Query solr thất bại.'; $aryData['intIsOK'] = -1; } if (is_array($aryProduct) && count($aryProduct) > 0) { global $display; $display->add('aryProduct', $aryProduct); $display->add('paging', $paging); $display->add('total_row', $total_row); $aryHtml = $display->output('list_product_extra_field', true, 'SoBoxAdvanced'); $aryData['htmlProduct'] = $aryHtml; $aryData['intIsOK'] = 1; } } } else { $aryData['msg'] = 'Query solr thất bại.'; $aryData['intIsOK'] = -1; } } } } echo json_encode($aryData); exit; }
); if($db->insert('make', $in)){ echo "ADDED $pretty\n"; } } unset($sel); unset($count); unset($in); } */ // https://api.edmunds.com/api/vehicle/v2/bmw/models?state=new&year=2015&category=Sedan&view=basic&fmt=json&api_key=hydhk9uvdaa29frpw6dw9hwe $types = array(1 => 'car', 2 => 'truck', 3 => 'suv', 4 => 'van'); foreach ($makes as $key => $value) { $getMakeID = "SELECT makeID FROM make WHERE makeNice LIKE '" . $value . "'"; $res = $db->get_row($getMakeID); echo "{$value}\n"; echo "{$res[0]}\n"; foreach ($types as $id => $name) { $url = $conf['apiurl'] . $value . '/models?state=new&year=' . $conf['apiyr'] . '&category=' . $conf[$name] . '&view=basic&fmt=json&api_key=' . $conf['apikey']; $results = json_decode(file_get_contents($url), true); sleep(2); foreach ($results['models'] as $x => $model) { $cq = "SELECT * FROM model WHERE makeID = '{$res[0]}' AND modelNice = '{$model['niceName']}'"; $check = $db->num_rows($query); if ($check == 0) { $add = array('make' => $res['0'], 'name' => $model['name'], 'modelNice' => $model['niceName'], 'type' => $id); $db->insert('model', $add); echo "Added {$model['name']}\n"; } unset($check);
echo "</table>"; echo "<table width=350>"; echo "<tr><td>"; $did = $_GET['did']; $vale = get_devolucion($_GET['did']); echo "<br>dev:{$did}..{$vale}</td></tr>"; echo "</table>"; //if ($notaventa) //echo "<br><br>Nota de venta por: ".dinero($notaventa); echo "<table width=350 border=2>"; echo "<tr><td>"; if ($vale > 0) { get_vale($_GET['did']); } $query = "SELECT tipomov_id FROM devolucion\n\t\t\tWHERE devolucion_id=" . $_GET['did']; list($tipomov_id) = $database->get_row($query); if ($vale && $tipomov_id == 3) { $query = "SELECT cliente.total_ultimo,devolucion.fecha,cliente.abono,cliente.saldo FROM cliente,devolucion\n\t\t\tWHERE cliente.cliente_id=devolucion.cliente_id AND devolucion_id={$did}"; list($saldo_ultimo, $fecha, $abono, $saldo) = $database->get_row($query); plandepagos($saldo_ultimo, $fecha, $abono, $saldo); } echo "</td></tr>"; echo "</table>"; echo $total_credito; echo $total_contado; echo $total_iva_credito; echo $total_iva_contado; $total = round($total_credito + $total_iva_credito); $saldo = $saldo_anterior - $total; // echo "<br><br>Sesion:<br>"; // ********DEBUG********** // foreach ($_SESSION as $k => $v) { echo "<br>[$k] => $v \n";}
/** * Select a group from the DB by its name * @param string A group name * @return mixed A UserGroup object, or boolean false */ public static function get_by_name( $name ) { return DB::get_row( 'SELECT * FROM {groups} WHERE name=?', array( $name ), 'UserGroup' ); }
/** * Generate a new slug for the post. * * @return string The slug */ private function setslug() { // determine the base value from: // - the new slug // If the slug is new and has a length if ( isset( $this->newfields['slug'] ) && $this->newfields['slug'] != '' ) { $value = $this->newfields['slug']; } // - the new empty slug whilst in draft or progressing directly to published or scheduled from draft. // - Also allow changing of slug whilst in scheduled state // // This happens when a draft is being updated, or a post is being directly published or scheduled, // or an existing scheduled or published post is being updated, but not made into a draft // // If a new slug is set, and it doesn't have a length elseif ( isset( $this->newfields['slug'] ) && $this->newfields['slug'] == '' ) { // If the existing status of the post is draft, no matter what status it is being changed to if ( $this->fields['status'] == Post::status( 'draft' ) || ( // or the existing status is not draft and the new status is not draft $this->fields['status'] != Post::status( 'draft' ) && $this->newfields['status'] != Post::status( 'draft' ) ) ) { // And a new title is set, use the new title if ( isset( $this->newfields['title'] ) && $this->newfields['title'] != '' ) { $value = $this->newfields['title']; } // Otherwise, use the existing title else { $value = $this->fields['title']; } } } // - the existing slug // If there is an existing slug, and it has a length elseif ( $this->fields['slug'] != '' ) { $value = $this->fields['slug']; } // - the new post title // If there is a new title, and it has a length elseif ( isset( $this->newfields['title'] ) && $this->newfields['title'] != '' ) { $value = $this->newfields['title']; } // - the existing post title // If there is an existing title, and it has a length elseif ( $this->fields['title'] != '' ) { $value = $this->fields['title']; } // - default //Nothing else worked. Default to 'Post' else { $value = 'Post'; } // make sure our slug is unique $slug = Plugins::filter( 'post_setslug', $value ); $slug = Utils::slugify( $slug ); $postfix = ''; $postfixcount = 0; do { if ( ! $slugcount = DB::get_row( 'SELECT COUNT(slug) AS ct FROM {posts} WHERE slug = ?;', array( $slug . $postfix ) ) ) { Utils::debug( DB::get_errors() ); exit; } if ( $slugcount->ct != 0 ) { $postfix = "-" . ( ++$postfixcount ); } } while ( $slugcount->ct != 0 ); return $this->newfields['slug'] = $slug . $postfix; }