edit_stocks.php

来自「股票监视器是一个简单的实用工具」· PHP 代码 · 共 187 行

PHP
187
字号
<?php/** PHP STOCK TRACKER* -----------------* A multi-user utility for creating and managing stock* watchlists and historical analysis.* Copyright (C) 2005 Joshua Eldridge (joshuae74@hotmail.com)*** This program is free software; you can redistribute it and/or modify* it under the terms of the GNU General Public License as published by* the Free Software Foundation; either version 2 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, write to the Free Software* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA** See the COPYING file for full details.*/// Prevent this page from being accessed directly as// it should always be called from within index.phpif (!defined('IN_VALID')) {  die("Error: This File Cannot Be Accessed Directly");}require_once('inc/navigation.inc.php');/* If this page was POSTed, it must bean add or edit. Deletes are GET *//*The status variable will be used to report the resultsof all actions back to the user; success or failure*/$status = '';$error = false;if($_SERVER['REQUEST_METHOD'] == 'POST') {  // Normalize user input, so all symbols are UPPER  $symbol = strtoupper(getCleanVar($_POST, 'stock_symbol'));  $quote = new Quote($symbol);  // This will add the stock to the users watch list  if(!$quote->is_new()) {    $quote->add_to_list($_SESSION['user_id']);    $status .= '<font color="red"><b>Added ' . $symbol . ' to WatchList!</b></font><br>';  } else {  // The stock entered wasn't found in the lookup table, maybe we should add it?    if($quote->is_valid() === true) {      $quote->save_info();      $status .= '<font color="red"><b>Successfully Added/Modified ' . $symbol . '!</b></font><br>';    } else {      $status .= '<font color="red"><b>' . $symbol . ' Doesn\'t Exist!</b></font> <a href="http://finance.yahoo.com/q?s=' . $symbol . '">Try Yahoo!</a><br>';      $error = true;    }  }  // Add history if the option was checked on the form  if($_POST['add_history'] == 'on' && $error == false) {	  // Check to see if this already has data in the table	  if(check_history($symbol) > 0) {		// Data Exists -- don't write history		$status .= '<font color="red"><b>History Already Exists for ' . $symbol . '!</b></font><br>';	  } else {		$data = get_historical_data($symbol);		if($data != '') {   		  $quote = new Quote($symbol);		  for($i=1; $i<count($data); $i++) {			$quote->trade_date = date('Y-n-j', strtotime($data[$i][0]));			$quote->opened = $data[$i][1];			$quote->high = $data[$i][2];			$quote->low = $data[$i][3];			$quote->last_trade = $data[$i][4];			$quote->volume = $data[$i][5];			$quote->save_data();		  }		$status .= '<font color="red"><b>Successfully Added History for ' . $symbol . '!</b></font><br>';		}	}  }  // Clean up the quote object so it won't populate on the page once it's gone/updated/added  unset($quote);  /*   Reset session varibles as they may have changed (additions or deletions).  */  unset($_SESSION['user_stocks']);  unset($_SESSION['user_highs']);}    if(checkSecureGet() === true) {  $symbol = getCleanVar($_GET, 'symbol');  if($symbol != '') {    $quote = new Quote($symbol);    if(getCleanVar($_GET, 'do') == 'delete') {      $quote->delete_stock($_SESSION['user_id']);	    $status .= '<font color="red"><b>Deleted ' . $symbol . '!</b></font><br>';    }  // Clean up the quote object so it won't populate on the page once it's gone/updated/added  unset($quote);  /*   Reset session varibles as they may have changed (additions or deletions).  */  unset($_SESSION['user_stocks']);  unset($_SESSION['user_highs']);  }}echo $status;?><form name="add_stock" action="<?= $_SERVER['PHP_SELF'] ?>?pg=edit_stocks" method="POST"><table cellpadding="2" cellspacing="0" border="1"><tr><td><table cellpadding="5" cellspacing="0" bgcolor="<?= $row_secondary ?>">	<tr>		<td>Symbol:</td><td><input type="text" name="stock_symbol" value="" size="3"></td>	</tr><tr>		<td>Add History?</td><td><input type="checkbox" name="add_history"></td>	</tr><tr>		<td colspan="2"><input type="submit" value="Add Stock to WatchList"></td>	</tr></table></td></tr></table></form><?/* If this is the first time the page has been visited, there is a good chance that the session already has all the information we need*/if(!isset($_SESSION['user_stocks'])) {  $_SESSION['user_stocks'] = get_stocks_list($_SESSION['user_id']);}/*If this isn't a new user with no stocks in their watchlist, run routines to dump the existing user stocks into manageable chunks*/if(count($_SESSION['user_stocks']) == 0) {	exit();}$html = '<table cellpadding="4" cellspacing="0"><tr>';foreach($_SESSION['user_stocks'] as $stock) {	// Break the stock symbols into manageable chunks by first letter	static $counter = 8;	static $first_letter_header = '';	$stock_first_letter = substr($stock['stock_symbol'],0,1);	// Set the number of columns for the output tables	$number_of_columns = 8;	if($first_letter_header != $stock_first_letter) {			// This is a new category (first letter) so close the open table and			// Print the new Letter, and open a new table		$html .= '</tr></table><h3>' . $stock_first_letter . '</h3><table cellpadding="4" cellspacing="0"><tr>';		$first_letter_header = $stock_first_letter;		$counter = 8;	}	if($counter/$number_of_columns == 1) {		// Start a new row		($bgcolor == $row_primary) ? $bgcolor = $row_secondary : $bgcolor = $row_primary;		$html .= '</tr><tr bgcolor="' . $bgcolor . '">';		$counter = 1;	} else {		$counter++;	}	$html .= '<td><a href="?pg=edit_stocks&symbol=' . $stock['stock_symbol'] . '&do=delete"><span class="red">X</span></a></td>';	$html .= '<td>' . $stock['stock_symbol'] .'</td>';}$html .= '</table>';echo $html;?>

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?