Beispiel #1
0
 public function redeem($sh_id)
 {
     global $database;
     global $session;
     $holder = new StockHolder($sh_id);
     if ($this->qty > 0) {
         if ($holder->cur_amt > $this->price) {
             $date = Database::date();
             $query = "INSERT INTO " . self::$table_ru . " (sh_id,p_id,date)";
             $query .= " VALUES ({$sh_id},{$this->id},'{$date}')";
             $run = $database->query($query);
             if ($run) {
                 $holder->amtUpdate($holder->cur_amt - $this->price);
                 $holder->redeemed();
                 $this->reduce_qty(1);
                 return true;
             } else {
                 $session->message('Your Request Couldn\'t Be Processed At This Moment Please Try Again');
                 return false;
             }
         } else {
             $session->message('You Dont Have Enough Virtual Money To Buy This Product');
             return false;
         }
     }
 }
Beispiel #2
0
 public static function add_new_holder($user)
 {
     $database = new Database();
     $user_id = $user['id'];
     $cur_amt = self::$initial_amount;
     $leader_position = StockHolder::count();
     $query = "INSERT INTO " . self::$table . " (u_id,cur_amt,leader_pos) ";
     $query .= " VALUES ({$user_id},{$cur_amt},{$leader_position});";
     $result = $database->query($query);
     if ($result) {
         $query2 = "SELECT id FROM " . self::$table . " WHERE u_id = " . $user_id . " LIMIT 1 ;";
         $shid = $database->query($query2);
         if ($shid) {
             $shid = $database->fetch_array($shid);
             $shid = $shid['id'];
         }
         unset($database);
         return $shid;
     } else {
         unset($database);
         return false;
     }
 }
Beispiel #3
0
 public static function add_new_user($user_id, $token, $name, $signup_d, $phone, $college)
 {
     $database = new Database();
     $id_array = array();
     $user_id = $database->escape_value(trim($user_id));
     $name = $database->escape_value(trim($name));
     $signup_d = $database->escape_value(trim($signup_d));
     $phone = $database->escape_value(trim($phone));
     $college = $database->escape_value(trim($college));
     $query = "INSERT INTO " . self::$table . " (user_id,token,name,signup_d,phone,college)";
     $query .= " VALUES ('{$user_id}','{$token}','{$name}','{$signup_d}',{$phone},'{$college}');";
     $success = $database->query($query);
     $query_id = "SELECT id FROM " . self::$table . " WHERE user_id='{$user_id}'";
     $success_query_id = $database->query($query_id);
     if ($success && $success_query_id) {
         $user_fetch = $database->fetch_array($success_query_id);
         if ($user_fetch) {
             $id_array['u_id'] = $user_fetch['id'];
             $add_success = StockHolder::add_new_holder($user_fetch);
             $id_array['sh_id'] = $add_success;
         } else {
             $id_array['uid'] = null;
             $add_success = null;
         }
         if ($add_success) {
             unset($database);
             return $id_array;
         } else {
             unset($database);
             return $id_array;
         }
     } else {
         unset($database);
         return false;
     }
 }
Beispiel #4
0
				<p style="font-family:sans-serif;font-size:1em;"><strong> Visit MarketPlace To View And Buy Stocks</strong> 
				</p>
			</div>
			<a class="button green icon-chevron-right" href="portfolio.php" style="float:right;">Marketplace
					</a>
			<div class="alert alert-warnning" style="clear:both;margin-bottom:0px;margin-top:2em;">
				<p style="font-family:sans-serif;font-size:1em;"><strong>Visit News & Updates To View News and Updates about Stocks and Virtual World</strong> 
				</p>
			</div>
			<a class="button green icon-chevron-right" href="portfolio.php" style="float:right;">News &amp; Updates
					</a>
			</div>
			<div class="span6">
				<h1>Leader Board &nbsp;&nbsp;&nbsp;<a class="button icon-chevron-right" href="leaderboard.php">View All </a></h1>
				<?php 
$positions = StockHolder::getLeaderBoard(10);
?>
				<table class="stacked">
				<thead>
					<tr>
						<th>Rank</th>
						<th>Name</th>
						<th>Status</th>
						<th>Assets Worth <i class="icon-money"></i></th>
					</tr>
				</thead>
				<tbody>
					
						<?php 
foreach ($positions as $position) {
    if ($position['status'] > 0) {
Beispiel #5
0
 public function sell($sh_id, $qty = 0)
 {
     global $session;
     $database = new Database();
     $sh_id = $database->escape_value($sh_id);
     $qty = (int) $qty;
     if ($this->isFound()) {
         $StockCompany = new StockCompany($this->sc_id);
         /*
         Check if the user has the stock or not
         */
         $holder_stocks = new HolderStocks($sh_id);
         $holder = new StockHolder($sh_id);
         if ($holder_stocks->isFound()) {
             if ($holder_stocks->hasStock($this->sc_id)) {
                 $index = array_search($this->sc_id, array_column($holder_stocks->holder_stocks, 'sc_id'));
                 $qty_having = $holder_stocks->holder_stocks[$index]['s_qty'];
                 if ($qty <= $qty_having) {
                     $stock_cur_price = Stock::getCurPrice($this->sc_id);
                     //This removes stocks from holder's list
                     $holder_stocks->removeStock($this->sc_id, $qty, $stock_cur_price);
                     //Updates the price of the holder
                     $holder->amtUpdate($holder->cur_amt + $stock_cur_price * $qty);
                     return true;
                 } else {
                     $session->message("You Dont have {$qty} stocks of {$StockCompany->c_name} to sell, You only have {$qty_having} stocks");
                     return false;
                 }
             } else {
                 $session->message("You Dont have {$StockCompany->c_name} stocks to sell");
                 return false;
             }
         } else {
             return false;
         }
     } else {
         return false;
     }
 }
Beispiel #6
0
     * close all day_closings!! direct function in stockhistory
     * also update StockCompany - dayclose = cur price and dayopen = cur price as well!
     */
    $histories = array();
    $companies = array();
    $controls = array();
    $stocks = Stock::getAllStocks();
    foreach ($stocks as $stock) {
        $histories[] = new StockHistory($stock->sc_id);
        $companies[] = new StockCompany($stock->sc_id);
        $controls[] = new StockControl($stock->sc_id);
    }
    foreach ($histories as $history) {
        $history->closeDay();
    }
    foreach ($companies as $company) {
        $cur_val = Stock::getCurPrice($company->id);
        $company->updateDayClose($cur_val);
        $company->updateDayOpen($cur_val);
    }
    foreach ($controls as $control) {
        $control->setOverride(0);
        $control->writeControl();
    }
    StockHolder::updateLeaderBoard();
    /*
     * Make the settings reset once the script has ended 
     * for next execution of the script so that stocks can be initialised first
     */
    reset_setting();
}
Beispiel #7
0
<script type="text/javascript" src="js/initial.js"></script>
<header id="header">
<?php 
if ($session->is_logged_in()) {
    $user = $_SESSION['user_id'];
    $user = new User($user);
} else {
    $session->logout();
    header('Location: index.php');
}
$holder = new StockHolder($session->sh_id);
$status = $holder->nStatus();
if ($status >= 0) {
    $show = 1;
} else {
    $show = 2;
}
?>
		<!-- Navigation
		================================================== -->
		<nav class="navbar">
			<div class="navbar-inner">
				<div class="container">
					<!-- Logo -->
					<a class="brand" href="home.php">
						VSM
					</a>
					<ul class="nav" id="esum">
						<li><a href="home.php" title="Home">Home</a></li>
						<li><a href="marketplace.php" title="Marketplace">Marketplace</a></li>
						<li><a href="portfolio.php" title="Portfolio">Portfolio</a></li>
Beispiel #8
0
 public function removeStock($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;
             $purchase_price = $details['pur_price'];
             if ($new_qty > 0) {
                 $query = "UPDATE " . self::$table;
                 $query .= " SET s_qty=" . $new_qty;
                 $query .= " WHERE id =" . $id;
             } else {
                 $query = " DELETE FROM " . self::$table;
                 $query .= " WHERE id =" . $id . " LIMIT 1";
                 $holder = new StockHolder($this->sh_id);
                 $holder->decS_Company();
             }
             $run = $database->query($query);
             if ($run) {
                 $trs = new Transaction($this->sh_id, $sc_id, $qty, $stock_cur_price, -1, $purchase_price);
                 $trs->save();
                 $this->getStocks();
                 return true;
             } else {
                 Log::add("Failed to update sale stock st:{$sc_id} for sh:{$this->sh_id} qty:{$qty} sale_price:{$stock_cur_price}", LOG_MANUAL);
                 return false;
             }
         } else {
             Log::add("Failed to update sale stock st:{$sc_id} for sh:{$this->sh_id} qty:{$qty} sale_price:{$stock_cur_price}", LOG_MANUAL);
             return false;
         }
     } else {
         Log::add("A Try to sale other stocks by sh_id:{$this->sh_id}, stock:{$sc_id}, qty:{$qty}, price: {$stock_cur_price}", LOG_HACK);
         return false;
     }
 }
Beispiel #9
0
defined('SITE_ROOT') ? null : define('SITE_ROOT', dirname(dirname(dirname(dirname(__FILE__)))) . DS . "vsm");
defined('LIB_PATH') ? null : define('LIB_PATH', SITE_ROOT . DS . "includes" . DS . "lib");
defined('CONFIG_PATH') ? null : define('CONFIG_PATH', SITE_ROOT . DS . "includes" . DS . "config");
defined("LOG_PATH") ? null : define("LOG_PATH", SITE_ROOT . DS . "logs");
require_once CONFIG_PATH . DS . "database.config.php";
require_once CONFIG_PATH . DS . "constants.config.php";
//Decide The Order of the Classes properly
require_once LIB_PATH . DS . 'Log.class.php';
require_once LIB_PATH . DS . 'Database.class.php';
require_once LIB_PATH . DS . 'User.class.php';
require_once LIB_PATH . DS . 'Session.class.php';
require_once LIB_PATH . DS . 'StockHolder.class.php';
/*
	Settings for StockHolder class
*/
StockHolder::$initial_amount = 10000;
require_once LIB_PATH . DS . 'StockCompany.class.php';
require_once LIB_PATH . DS . 'Transaction.class.php';
require_once LIB_PATH . DS . 'Stock.class.php';
require_once LIB_PATH . DS . 'HolderStocks.class.php';
require_once LIB_PATH . DS . 'News.class.php';
require_once LIB_PATH . DS . 'Redeem.class.php';
require_once LIB_PATH . DS . 'StockControl.class.php';
require_once LIB_PATH . DS . 'StockHistory.class.php';
/* 
 *Lazy Loading
 */
function autoload($class)
{
    include_once LIB_PATH . DS . $class . '.class.php';
}