require_once('DBTable.php');
class ContributionHistoryTable extends DBTable {
function __construct ($dbTSP) {
$this->db = $dbTSP;
$this->tableName = 'ContributionHistory';
$this->fieldList = array('ContributionID', 'UserID', 'ContributionDate', 'Contribution');
$this->primaryKey = 'ContributionID';
$this->tplDir = 'ContributionHistory';
}
function addContribution ($user_id, $date, $contribution) {
$values = array('UserID' => $user_id, 'ContributionDate' => $date, 'Contribution' => $contribution);
DBQuery::insertRow($this->db, $this->tableName, $values);
}
function getContributionBetweenDates ($userId, $startDate, $endDate) {
$subQuery = "ContributionDate >= '$startDate' AND ContributionDate <= '$endDate'";
$values = DBQuery::getRows($this->db, $this->tableName, array(), array('UserID' => $userId), array($subQuery), 0, 1000, 'ContributionDate', true);
return $values;
}
}
?>
require_once('DBTable.php');
class DataCallTable extends DBTable {
function __construct ($dbTSP) {
$this->db = $dbTSP;
$this->tableName = 'DataCall';
$this->fieldList = array('id', 'date', 'user_id', 'market_direction', 'best_fund', 'worst_fund');
$this->primaryKey = 'id';
$this->tplDir = 'DataCall';
}
function addDataCall ($date, $user_id, $market_direction, $best_fund, $worst_fund) {
$values = array('date' => $date, 'user_id' => $user_id, 'market_direction' => $market_direction, 'best_fund' => $best_fund, 'worst_fund' => $worst_fund);
DBQuery::insertRow($this->db, $this->tableName, $values);
}
function getDataCallID ($date, $user_id) {
//$subQuery = array('date' => $date, 'user_id' => $user_id);
$subQuery = "date = '$date' AND user_id = $user_id";
$vals = DBQuery::getRows($this->db, $this->tableName, array('id'), array(), array($subQuery), 0, 1);
if (count($vals) == 0) {
return false;
} else {
return $vals[0]['id'];
}
}
function getDataCallResult ($date, $element, $value) {
$subQuery = "date = '$date' AND $element = '$value'";
$vals = DBQuery::getRows($this->db, $this->tableName, array('id'), array(), array($subQuery));
if (count($vals) == 0) {
return false;
} else {
return count($vals);
}
}
function getDataCallFundPerformer ($date, $element) {
$subQuery = "date = '$date'";
if ($element == "best_fund") {
$vals = DBQuery::getRows($this->db, $this->tableName, array('best_fund'), array(), array($subQuery));
} else {
$vals = DBQuery::getRows($this->db, $this->tableName, array('worst_fund'), array(), array($subQuery));
}
if (count($vals) > 0) {
$fund = array();
if ($element == "best_fund") {
for ($i=0; $i < count($vals); $i++) {
$funds[] = $vals[$i]['best_fund'];
}
} else {
for ($i=0; $i < count($vals); $i++) {
$funds[] = $vals[$i]['worst_fund'];
}
}
// get total times counted for each fund
$funds = array_count_values($funds);
// get most selected fund(s)
$funds = array_keys($funds, max($funds));
$returnVal = "";
for ($i=0; $i < count($funds); $i++) {
$returnVal .= strtoupper($funds[$i]) . " Fund, ";
}
// remove ", " and return
return substr($returnVal, 0, -2);
} else {
return false;
}
}
}
?>
require_once('DBTable.php');
class DataCallResultsTable extends DBTable {
function __construct ($dbTSP) {
$this->db = $dbTSP;
$this->tableName = 'DataCallResults';
$this->fieldList = array('id', 'date', 'bulls', 'bears', 'spread', 'ratio', 'best', 'worst');
$this->primaryKey = 'id';
$this->tplDir = 'DataCallResults';
}
function addDataCallResult ($date, $bulls, $bears, $spread, $ratio, $best, $worst) {
$values = array('date' => $date, 'bulls' => $bulls, 'bears' => $bears, 'spread' => $spread, 'ratio' => $ratio, 'best' => $best, 'worst' => $worst);
DBQuery::insertRow($this->db, $this->tableName, $values);
}
function getDataCallResults ($number) {
$values = DBQuery::getRows($this->db, $this->tableName, array(), array(), array(), 0, $number, 'date', true);
if (count($values) == 0) {
return false;
} else {
return $values;
}
}
}
?>
class avg {
var $data = array();
var $num;
var $ret;
function __construct($num, $ret='') {
$this->num = (int)$num;
if ($this->num < 1) die('invalid average number');
$this->ret = $ret;
}
function next($value) {
$this->data[] = (float)$value;
if (count($this->data) > $this->num) {
array_shift($this->data);
return array_sum($this->data)/$this->num;
} else {
return $this->ret;
}
}
}
?>
class SessionObject {
var $user_id;
var $username;
var $user_email;
function __construct ($user_id, $username, $user_email) {
$this->user_id = $user_id;
$this->username = $username;
$this->user_email = $user_email;
}
function getUserId () {
return $this->user_id;
}
function getUserName () {
return $this->username;
}
function getEmail () {
return $this->user_email;
}
}
?>
require_once('DBTable.php');
class WatchGroupsTable extends DBTable {
function __construct ($dbTSP) {
$this->db = $dbTSP;
$this->tableName = 'WatchGroups';
$this->fieldList = array('WatchGroupID', 'UserID', 'WatchGroupName');
$this->primaryKey = 'WatchGroupID';
}
function addWatchGroup ($userId, $groupName) {
//Get local variables
include(__DIR__.'/../includes/vars.php');
$values = array('UserID' => $userId, 'WatchGroupName' => $groupName);
$return = DBQuery::insertRow($this->db, $this->tableName, $values);
return $return;
}
function delWatchGroups ($userId, $watchGroupIdList) {
require_once(__DIR__.'/QueryGenerator.php');
$watchGroupIdList = array_map(array('QueryGenerator', 'quoteString'), $watchGroupIdList);
$predefChecks = array("WatchGroupID IN (" . implode(',', $watchGroupIdList) . ")");
$return = DBQuery::deleteRows($this->db, $this->tableName, array('UserID' => $userId), $predefChecks);
return $return;
}
function getWatchGroups ($userId, $limit=5000) {
$return = DBQuery::getRows($this->db, $this->tableName, array(), array('UserID' => $userId), array(), 0, $limit, 'WatchGroupName', true);
return $return;
}
}
?>
require_once('DBTable.php');
class WatchTable extends DBTable {
function __construct ($dbTSP) {
$this->db = $dbTSP;
$this->tableName = 'Watch';
$this->fieldList = array('WatchID', 'UserID', 'UserWatchedID', 'DateAdded', 'WatchGroupID');
$this->primaryKey = 'WatchID';
$this->tplDir = 'Watch';
}
function preDisplayList (&$filter, $rowsDisplayed, $start, &$order, &$desc) {
require('loginBB.php');
$filter['UserID'] = $_SESSION['PHPBB_UID'];
$order = 'WatchID';
$desc = true;
}
function postDisplayList ($values, $smarty) {
require_once(__DIR__.'/UserLoginTable.php');
$loginTable = new UserLoginTable($this->db);
foreach ($values as $idx => $val) {
$values[$idx]['UserName'] = $loginTable->getUserName($val['UserWatchedID']);
}
$smarty->assign('PrevAction', $_SESSION['PREV_ACTION']);
unset($_SESSION['PREV_ACTION']);
$smarty->assign('Heading', 'My Alerts');
return $values;
}
function addWatch ($userId, $userWatchedId) {
//Get local variables
include(__DIR__.'/../includes/vars.php');
$values = array('UserID' => $userId, 'UserWatchedID' => $userWatchedId, 'DateAdded' => gmdate('Y-m-d H:i:s', time()-($EST*3600)));
DBQuery::insertRow($this->db, $this->tableName, $values);
}
function findWatch ($userId, $userWatchedId) {
$vals = DBQuery::getRows($this->db, $this->tableName, array('WatchID'), array('UserID' => $userId, 'UserWatchedID' => $userWatchedId));
return (count($vals) > 0) ? $vals[0]['WatchID'] : 0;
}
function delWatch ($userId, $watchIdList) {
require_once(__DIR__.'/QueryGenerator.php');
$watchIdList = array_map(array('QueryGenerator', 'quoteString'), $watchIdList);
$predefChecks = array("WatchID IN (" . implode(',', $watchIdList) . ")");
$return = DBQuery::deleteRows($this->db, $this->tableName, array('UserID' => $userId), $predefChecks);
return $return;
}
function getWatchCount ($UserWatchedID) {
$vars = DBQuery::getRows($this->db, $this->tableName, array('WatchID'), array('UserWatchedID' => $UserWatchedID));
return count($vars);
}
function getWatchers ($UserWatchedID) {
$vars = DBQuery::getRows($this->db, $this->tableName, array('UserID'), array('UserWatchedID' => $UserWatchedID));
return $vars;
}
}
?>
function getNextSunday() {
if (date('D') == "Sun") {
$nextSunday = date('F d, Y');
} else {
$nextSunday = date('F d, Y', strtotime('next Sunday'));
}
return $nextSunday;
}
function rollTDbackward($datestring,$inclusive = 0) {
require_once(__DIR__.'/../classes/HolidayTable.php');
$eastern_timezone = new DateTimeZone('America/New_York');
$pointer = new DateTime($datestring,$eastern_timezone);
$pointer->setTimezone($eastern_timezone);
$holidays = holidays::year($pointer->format('Y'));
$holidays = array_merge(array_values($holidays),array_values(holidays::year($pointer->format('Y')+1)));
if ($inclusive == 0) {
$pointer->modify('-1 day');
}
while ($pointer->format('N') >= 6 || array_search($pointer->format("Y-m-d"),$holidays) != FALSE) {
$pointer->modify('-1 day');
}
return $pointer->format('Y-m-d');
}
function rollTDforeward($datestring,$inclusive = 0) {
require_once(__DIR__.'/../classes/HolidayTable.php');
$eastern_timezone = new DateTimeZone('America/New_York');
$pointer = new DateTime($datestring,$eastern_timezone);
$pointer->setTimezone($eastern_timezone);
$holidays = holidays::year($pointer->format('Y'));
$holidays = array_merge(array_values($holidays),array_values(holidays::year($pointer->format('Y')+1)));
if ($inclusive == 0) {
$pointer->modify('+1 day');
}
while ($pointer->format('N') >= 6 || array_search($pointer->format("Y-m-d"),$holidays) != FALSE) {
$pointer->modify('+1 day');
}
return $pointer->format('Y-m-d');
}
function multiarray_search($arrayVet, $campo, $valor) {
while(isset($arrayVet[key($arrayVet)])) {
if($arrayVet[key($arrayVet)][$campo] == $valor) {
return key($arrayVet);
}
next($arrayVet);
}
return -1;
}
function arrayKey_sum($array, $key) {
$total = 0;
foreach($array as $subarr) {
if (isset($subarr[$key])) {
$total += $subarr[$key];
}
}
return $total;
}
/**
* Truncates text.
*
* Cuts a string to the length of $length and replaces the last characters
* with the ending if the text is longer than length.
*
* @param string $text String to truncate.
* @param integer $length Length of returned string, including ellipsis.
* @param string $ending Ending to be appended to the trimmed string.
* @param boolean $exact If false, $text will not be cut mid-word
* @param boolean $considerHtml If true, HTML tags would be handled correctly
* @return string Trimmed string.
*/
function truncate($text, $length = 100, $ending = '...', $exact = true, $considerHtml = false) {
if ($considerHtml) {
// if the plain text is shorter than the maximum length, return the whole text
if (strlen(preg_replace('/<.*?>/', '', $text)) <= $length) {
return $text;
}
// splits all html-tags to scanable lines
preg_match_all('/(<.+?>)?([^<>]*)/s', $text, $lines, PREG_SET_ORDER);
$total_length = strlen($ending);
$open_tags = array();
$truncate = '';
foreach ($lines as $line_matchings) {
// if there is any html-tag in this line, handle it and add it (uncounted) to the output
if (!empty($line_matchings[1])) {
// if it's an "empty element" with or without xhtml-conform closing slash (f.e.
)
if (preg_match('/^<(\s*.+?\/\s*|\s*(img|br|input|hr|area|base|basefont|col|frame|isindex|link|meta|param)(\s.+?)?)>$/is', $line_matchings[1])) {
// do nothing
// if tag is a closing tag (f.e. )
} else if (preg_match('/^<\s*\/([^\s]+?)\s*>$/s', $line_matchings[1], $tag_matchings)) {
// delete tag from $open_tags list
$pos = array_search($tag_matchings[1], $open_tags);
if ($pos !== false) {
unset($open_tags[$pos]);
}
// if tag is an opening tag (f.e. )
} else if (preg_match('/^<\s*([^\s>!]+).*?>$/s', $line_matchings[1], $tag_matchings)) {
// add tag to the beginning of $open_tags list
array_unshift($open_tags, strtolower($tag_matchings[1]));
}
// add html-tag to $truncate'd text
$truncate .= $line_matchings[1];
}
// calculate the length of the plain text part of the line; handle entities as one character
$content_length = strlen(preg_replace('/&[0-9a-z]{2,8};|[0-9]{1,7};|[0-9a-f]{1,6};/i', ' ', $line_matchings[2]));
if ($total_length+$content_length> $length) {
// the number of characters which are left
$left = $length - $total_length;
$entities_length = 0;
// search for html entities
if (preg_match_all('/&[0-9a-z]{2,8};|[0-9]{1,7};|[0-9a-f]{1,6};/i', $line_matchings[2], $entities, PREG_OFFSET_CAPTURE)) {
// calculate the real length of all entities in the legal range
foreach ($entities[0] as $entity) {
if ($entity[1]+1-$entities_length <= $left) {
$left--;
$entities_length += strlen($entity[0]);
} else {
// no more characters left
break;
}
}
}
$truncate .= substr($line_matchings[2], 0, $left+$entities_length);
// maximum lenght is reached, so get off the loop
break;
} else {
$truncate .= $line_matchings[2];
$total_length += $content_length;
}
// if the maximum length is reached, get off the loop
if($total_length>= $length) {
break;
}
}
} else {
if (strlen($text) <= $length) {
return $text;
} else {
$truncate = substr($text, 0, $length - strlen($ending));
}
}
// if the words shouldn't be cut in the middle...
if (!$exact) {
// ...search the last occurance of a space...
$spacepos = strrpos($truncate, ' ');
if (isset($spacepos)) {
// ...and cut the text in this position
$truncate = substr($truncate, 0, $spacepos);
}
}
// add the defined ending to the text
$truncate .= $ending;
if($considerHtml) {
// close all unclosed html-tags
foreach ($open_tags as $tag) {
$truncate .= '' . $tag . '>';
}
}
return $truncate;
}
?>