/** * Get the statistics for a certain month, grouped by day and host * @param date Minimum date * @return Array of data */ public static function month_by_day($start_date) { // Calculate end of this month $end_date = mktime(23, 59, 59, date('m', $start_date) + 1, 0, date('Y', $start_date)); $query = Database::getDB()->prepare(' SELECT ip, UNIX_TIMESTAMP(date) AS date, SUM(bytes_out) bytes_out, SUM(bytes_in) bytes_in FROM ' . Config::$database['prefix'] . 'combined WHERE date BETWEEN :start_date AND :end_date GROUP BY ip, DAY(date) ORDER BY date, ip'); $query->execute(array('start_date' => Database::date($start_date), 'end_date' => Database::date($end_date))); // Start with an empty array for all the days of the month $day_base = date('Y-m-', $start_date); $days = array(); for ($i = 1, $count = date('t', $start_date); $i <= $count; $i++) { $days[$day_base . str_pad($i, 2, '0', STR_PAD_LEFT)] = 0; } $data = array(); while ($row = $query->fetchObject()) { // Check if this IP is on the list of IPs that should be shown if (!empty(Config::$include_ips) && !in_array($row->ip, Config::$include_ips)) { continue; } // Does this host have a data entry yet? if (!isset($data[$row->ip])) { $data[$row->ip] = $days; } $row->bytes_total = $row->bytes_in + $row->bytes_out; $data[$row->ip][date('Y-m-d', $row->date)] = $row->bytes_total; } return $data; }
private function confirm_query($query = "") { if (!$query) { $output = "Database Query Failed : " . mysqli_error($this->connection) . "\n"; $output .= "\nLast Sql Query: " . $this->last_query . " Time: " . Database::date(); Log::add($output, LOG_DB); die($output); return false; } }
public function __construct($sh_id, $sc_id, $qty, $price, $b_s, $stock_ini_price) { $this->sh_id = $sh_id; $this->sc_id = $sc_id; $this->qty = $qty; $this->price = $price; $this->b_s = $b_s; $this->s_m_p = $stock_ini_price; $this->date = Database::date(); $this->set = true; }
/** * Get the statistics for a certain day * @param string IP address of host * @param date Minimum date * @return Array of data */ public static function day($ip, $date) { // Calculate the last second of this day $start_date = $date; $end_date = mktime(23, 59, 59, date('m', $date), date('d', $date), date('Y', $date)); $query = Database::getDB()->prepare(' SELECT ip, UNIX_TIMESTAMP(date) AS date, bytes_out, bytes_in FROM ' . Config::$database['prefix'] . 'combined WHERE date BETWEEN :start_date AND :end_date AND ip = :ip ORDER BY date DESC'); $query->execute(array('start_date' => Database::date($start_date), 'end_date' => Database::date($end_date), 'ip' => $ip)); $data = array(); $totals = (object) array('bytes_out' => 0, 'bytes_in' => 0, 'bytes_total' => 0); while ($row = $query->fetchObject()) { $row->bytes_total = $row->bytes_in + $row->bytes_out; $data[] = $row; $totals->bytes_in += $row->bytes_in; $totals->bytes_out += $row->bytes_out; $totals->bytes_total += $row->bytes_total; } return (object) array('data' => $data, 'totals' => $totals); }
public static function add($sc_id, $data, $p_change, $live_date) { global $database; $sc_id = (int) $sc_id; $data = $database->escape_value($data); $p_change = (int) $p_change; $date = Database::date(); $price_value = (double) (Stock::getCurPrice($sc_id) * (1.0 + (double) ((double) $p_change / (double) 100.0))); $query = "INSERT INTO " . self::$table . " (sc_id,data,date_uploaded,p_change,live_date,status,price_value,done)"; $query .= "\tVALUES({$sc_id},'" . $data . "'" . ",'{$date}',{$p_change},'{$live_date}',0,{$price_value},0);"; $run = $database->query($query); if ($run) { return true; } else { //TODO:When news update fails! return false; } }
public static function addToMarket($sc_id, $s_price, $date = null) { $database = new Database(); $date = is_null($date) ? Database::date() : $date; $query = "INSERT INTO " . self::$table . " (sc_id,cur_val,date_t)"; $query .= " VALUES ({$sc_id},{$s_price},'{$date}')"; $run = $database->query($query); if ($run) { unset($database); return true; } else { unset($database); return false; } }
public static function addProduct($name, $info, $price, $qty) { global $database; $name = $database->escape_value($name); $info = $database->escape_value($info); $price = (int) $price; $qty = (int) $qty; $date = Database::date(); $query = "INSERT INTO " . self::$table_rp . " (product_name,product_info,price,qty,date,in_stock)"; $query .= " VALUES ('" . $name . "','" . $info . "',{$price},{$qty},'{$date}',1)"; $run = $database->query($query); if ($run) { return true; } else { return false; } }
<?php require '..' . DIRECTORY_SEPARATOR . 'config' . DIRECTORY_SEPARATOR . 'bootstrap.config.php'; $Email_ID = "*****@*****.**"; $Token = "This is a Fake Token."; $User_Name = "Ankit"; //Date the user was added $Signup_date = Database::date(); $Mobile = 1234567899; $College = "DTU"; User::add_new_user($Email_ID, $Token, $User_Name, $Signup_date, $Mobile, $College);
public function addStock($sc_id, $qty, $stock_cur_price) { //Checks if some quantity of stock is already present or not $search = in_array($sc_id, array_column($this->holder_stocks, 'sc_id')); $search_index = array_search($sc_id, array_column($this->holder_stocks, 'sc_id')); $database = new Database(); if ($search) { //check the searching algorithm $id = $this->holder_stocks[$search_index]['id']; $query = "SELECT s_qty,pur_price FROM " . self::$table; $query .= " WHERE id = " . $id . " LIMIT 1"; $run = $database->query($query); if ($run) { $details = $database->fetch_array($run); $new_qty = $details['s_qty']; $new_qty += $qty; $old_price = $details['pur_price']; $new_price = (int) (($old_price + $stock_cur_price) / 2); $query = "UPDATE " . self::$table; $query .= " SET s_qty=" . $new_qty . ", pur_price=" . $new_price; $query .= " WHERE id =" . $id; $run = $database->query($query); if ($run) { $trs = new Transaction($this->sh_id, $sc_id, $qty, $stock_cur_price, 1, $stock_cur_price); $trs->save(); $this->getStocks(); return true; } else { Log::add("Failed to update purchase stock st:{$sc_id} for sh:{$this->sh_id} qty:{$qty} pur_price:{$stock_cur_price}", LOG_MANUAL); return false; } } else { Log::add("Failed to update purchase stock st:{$sc_id} for sh:{$this->sh_id} qty:{$qty} pur_price:{$stock_cur_price}", LOG_MANUAL); return false; } } else { $query = "INSERT INTO " . self::$table . " (sh_id,sc_id,s_qty,pur_price,s_date)"; $query .= " VALUES ({$this->sh_id},{$sc_id},{$qty},{$stock_cur_price},'" . Database::date() . "')"; $run = $database->query($query); if ($run) { $holder = new StockHolder($this->sh_id); $holder->incS_Company(); $trs = new Transaction($this->sh_id, $sc_id, $qty, $stock_cur_price, 1, $stock_cur_price); $trs->save(); $this->getStocks(); return true; } else { Log::add("Failed to update purchase stock st:{$sc_id} for sh:{$this->sh_id} qty:{$qty} pur_price:{$stock_cur_price}", LOG_MANUAL); return false; } } /* *Querying the databse again to search for the stockss if available or not $database = new Database(); $query = "SELECT s_qty FROM ".self::$table; $query .= "WHERE sh_id = ".$this->sh_id." AND sc_id = "$sc_id; $run = $database->query($query); if($run && ($database->num_rows($run)>0)){ //When user already has tht companies stocks }else{ //when no stocks of that company is present }*/ }