session_start();
$sess=session_id();
//ini_set("display_errors","1");
//ERROR_REPORTING(E_ALL);
define("DOMAIN_NAME","MethodAdvisors.com");
define("SITE_NAME","Method Advisors");
define("ADMIN_EMAIL","drewmckenna@gmail.com");
define("INTRANET_TITLE","Method Advisors 2009");
require_once("class.database.php");
/////Functions
function mailhead($emailfrom, $emailto, $subject, $content, $type) {
//headers
$headers = "From: $emailfrom <$emailfrom>" . "\n";
$headers .= "Reply-To: $emailfrom"."\n";
$headers .= "Return-Path: $emailfrom" . "\n"; // these two to set reply address
$headers .= "Message-ID: <".time()."@".DOMAIN_NAME.">"."\n";
$headers .= "X-Mailer: ".SITE_NAME." Email Function"."\n"; // These two to help avoid spam-filters
$headers .= "Date: ".date("r")."\n";
$headers .= "MIME-Version: 1.0\n" .
$headers .= "Content-Type: text/".$type."\n";
$headers .= "User-Agent: ".$_SERVER['HTTP_USER_AGENT']."\n";
if(mail($emailto,$subject,$content, $headers, '-f'.$emailfrom)){
return true;
}else{
return false;
}
}
function smtp_mail($emailfrom, $emailto, $subject, $content, $type) {
require_once('mailer/class.phpmailer.php');
$mail = new PHPMailer(true); // the true param means it will throw exceptions on errors, which we need to catch
$mail->IsSMTP(); // telling the class to use SMTP
$mail->SMTPDebug = 0; // enables SMTP debug information (for testing)
$mail->SMTPAuth = true; // enable SMTP authentication
$mail->SMTPSecure = "ssl"; // sets the prefix to the servier
$mail->Host = "mail.sgfclients.com"; // sets GMAIL as the SMTP server
$mail->Port = 465; // set the SMTP port for the GMAIL server
$mail->Username = "mailsend@sgfclients.com"; // GMAIL username
$mail->Password = "sgfmailer"; // GMAIL password
$mail->AddAddress($emailto, $emailto);
$mail->SetFrom($emailfrom, $emailfrom);
$mail->AddReplyTo($emailfrom, $emailfrom);
$mail->Subject = $subject;
$mail->MsgHTML($content);
if($mail->Send()){
return true;
sleep(1);
}else{
return false;
}
}
function generate_password($length = 10) {
$allowable_characters = "abcdefghijklmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ23456789";
$ps_len = strlen($allowable_characters);
mt_srand((double)microtime()*1000000);
$pass = "";
for($i = 0; $i < $length; $i++) {
$pass .= $allowable_characters[mt_rand(0,$ps_len-1)];
}
return $pass;
}
function isEven($number){
$result = $number % 2;
if($result == 0){
return true;
}else{
return false;
}
}
function hide_mailto($mail,$type='') {
$chars = preg_split("//", $mail, -1, PREG_SPLIT_NO_EMPTY);
if($type == 'email'){
$new_mail = "".$new_mail2."";
}
return $new_mail;
}
function truncate($string, $max = 20, $replacement = '') {
if (strlen($string) <= $max)
{
return $string;
}
$leave = $max - strlen ($replacement);
return substr_replace($string, $replacement, $leave);
}
function ifblank($str,$ending='') {
if($str>''){
return $str.$ending;
}else{
return '';
}
}
function strip_num_rows($row) {
$nr = array();
foreach($row as $k=>$v) {
if(!is_numeric($k)) {
$nr[$k] = $v;
}
}
return $nr;
}
function print_rpre($arr='', $hide = false ) {
echo $hide ? '
' : '';
print_r($arr);
echo '
';
}
function getFileExtension($str) {
$i = explode(".",$str);
return strtolower(array_pop($i));
}
function test_TEST() {
echo 'HAI';
}
function get_files_by_type_fileyear($type='', $fundyear=0, $user_id=0) { // terrible for grabbing just years. make new function
global $year;
$cats=array('fund'=>'Fund/Legal Documents','misc'=>'Miscellaneous Documents','transfer'=>'Transfer Notices','quarter'=>'Quarterly/Annual Reports');
$category = $cats[$type];
if($fundyear && $category && $user_id) {
$user = get_user_by_id($user_id, 'f');
$db = new database();
$sql = "SELECT * FROM files f, users_accts u ";
$sql .= "WHERE u.uid=f.FileCompanyID AND f.FileCat='$category' ";
if(isset($user['where_sql']) && $user['where_sql']!='') { $sql .= $user['where_sql']; }
/* if($user['utype']=='Company' || $user['utype']=='Client') { $sql .= " AND f.FileCompanyID=".$user['CompanyID']." "; } */
if($user['utype']=='Company' || $user['utype']=='Client') { $sql .= " AND FIND_IN_SET( " . $user['CompanyID'] . ", f.FileCompanyID )"; }
/*
if($type == 'misc' || $type == 'fund') {
$sql .= "AND f.FileFund LIKE '%$year%' AND f.FileDate LIKE '%$fundyear%' ORDER BY f.FileCat DESC, f.FileDate DESC";
} else if($type == 'quarter') {
$sql .= "AND f.display_year LIKE '%$fundyear%' AND f.FileFund LIKE '%$year%' ORDER BY f.FileCat DESC, f.display_year DESC, f.FileDate DESC";
} else {
$sql .= "AND f.FileDate LIKE '%$fundyear%' AND f.FileFund = $year ORDER BY f.FileCat DESC, f.FileDate DESC";
}
*/
if($type == 'misc' || $type == 'fund') {
$sql .= "AND f.FileFund LIKE '$year' AND f.FileDate LIKE '%$fundyear%' ORDER BY f.FileCat DESC, f.FileDate DESC";
} else if($type == 'quarter') {
$sql .= "AND f.display_year LIKE '%$fundyear%' AND f.FileFund LIKE '$year' ORDER BY f.FileCat DESC, f.display_year DESC, f.FileDate DESC";
} else {
$sql .= "AND f.FileDate LIKE '%$fundyear%' AND f.FileFund LIKE '$year' ORDER BY f.FileCat DESC, f.FileDate DESC";
}
$db->query($sql);
$rows = array();
$years = array();
while($row = $db->get_row()) {
$rows[] = strip_num_rows($row);
}
return $rows;
} else {
return false;
}
}
function get_fund_file_years($type='', $fundyear=0, $user_id=0) { // terrible for grabbing just years. make new function
$cats=array('fund'=>'Fund/Legal Documents','misc'=>'Miscellaneous Documents','transfer'=>'Transfer Notices','quarter'=>'Quarterly/Annual Reports');
$category = $cats[$type];
if($fundyear && $category && $user_id) {
$db = new database();
$sql = "SELECT DISTINCT YEAR(FileDate) as file_year, (SELECT DISTINCT display_year) as display_year FROM files f, users_accts u ";
$sql .= "WHERE u.uid=f.FileCompanyID AND f.FileCat='$category' ";
$sql .= "AND f.FileFund LIKE '%$fundyear%' ORDER BY f.FileCat DESC, f.FileDate DESC";
$db->query($sql);
$years = array();
while($row = $db->get_row()) {
$years[$row['file_year']] = 1;
if($row['display_year']) {
$years[$row['display_year']] = 1;
}
}
return $years;
} else {
return false;
}
}
function print_file_headers_and_tables($type='', $year='', $user_id=0) {
if($type && $year && $user_id) {
$cats=array('fund'=>'Fund/Legal Documents','misc'=>'Miscellaneous Documents','transfer'=>'Transfer Notices','quarter'=>'Quarterly/Annual Reports');
$category = $cats[$type];
$arr = array();
$fund_years = get_fund_file_years($type, $year, $user_id);
$user = get_user_by_id($user_id);
$count = 0;
?>
Notice: Undefined variable: category in /home/forge/methodadvisors.com/intranet/includes/include.php on line 220
foreach($fund_years as $k=>$v) {
$files = get_files_by_type_fileyear($type, $k, $user_id);
if(empty($files)) {
//echo 'No Files.';
} else { ?>
}
$count++;
}
if($count == 0) { ?>
There are no files under this category.
}
}
}
function get_permissions_by_user($user) {
if($user) {
$user_id = $user['uid'];
$company_id = $user['CompanyID'];
$db = new database();
$cperms = array();
if($user['utype'] == 'Client') {
$db->query("SELECT perms FROM `users_accts` WHERE `uid` = $company_id");
$rows = array();
while($row = $db->get_row()) {
$rows[] = strip_num_rows($row);
}
$cperms = array_shift($rows);
} else if($user['utype'] == 'Consultant') {
$db->query("SELECT * FROM `consultant_companies` WHERE `cuid` = '$user_id' GROUP BY `ccomid`");
$where=array();
while($company=$db->get_row()) {
if($company['ccomid'] !='') {
$where[] = $company['ccomid'];
}
}
$companies = 'WHERE uid IN ('.implode(', ',$where).')';
$db->query("SELECT DISTINCT perms FROM `users_accts` $companies");
$rows = array();
while($row = $db->get_row()) {
$rows[] = strip_num_rows($row);
}
$cperms = array_shift($rows);
}
$db->query("SELECT perms FROM `users_accts` WHERE `uid` = '$user_id' LIMIT 1");
$rows = array();
while($row = $db->get_row()) {
$rows[] = strip_num_rows($row);
}
$r = array_shift($rows);
$perms = implode(" ", array_merge($r, $cperms));
if(!empty($perms)) {
return str_replace('-', ', ', $perms);
} else {
return false;
}
}
}
function get_user_by_email($email='') {
if($email) {
$email = strtolower($email);
$db = new database();
$db->query("SELECT uid FROM `users_accts` WHERE LOWER(`email`) = '$email' LIMIT 1");
$rows = array();
while($row = $db->get_row()) {
$rows[] = strip_num_rows($row);
}
if(!empty($rows)) {
$arr = array_shift($rows);
if($user = get_user_by_id($arr['uid'])) {
return $user;
} else {
return false;
}
}
} else {
return false;
}
}
function get_user_by_id($user_id=0, $sql_prefix = false) {
if($user_id) {
$sql_prefix = $sql_prefix ? $sql_prefix . '.' : '';
$db = new database();
$db->query("SELECT * FROM `users_accts` WHERE `uid` = '$user_id' LIMIT 1");
$where = array();
while($row = $db->get_row()) {
$rows[] = strip_num_rows($row);
// this is for companies specifically
$db->query("SELECT * FROM `consultant_companies` WHERE `cuid` = '$user_id' GROUP BY `ccomid`");
$where=array();
while($company=$db->get_row()) {
if($company['ccomid'] !='') {
$where[] = $company['ccomid'];
}
}
}
if(!empty($where)) {
$rows[0]['where_sql'] = ' AND ' . $sql_prefix . 'FileCompanyID IN ('.implode(', ',$where).') ';
}
if( $rows[0]['utype'] == 'Consultant' ) {
$rows[0]['where_sql'] = ' AND ( ';
foreach( $where as $possibility ) $company[] = ' FIND_IN_SET( ' . $possibility . ', ' . $sql_prefix . 'FileCompanyID )';
$rows[0]['where_sql'] .= implode(' OR', $company);
$rows[0]['where_sql'] .= ' ) ';
}
$rows[0]['perms'] = get_permissions_by_user($rows[0]);
return array_shift($rows);
} else {
return false;
}
}
function get_file_by_id($file_id=0) {
if($file_id) {
$db = new database();
$db->query("SELECT * FROM `files` WHERE `FileID` = '$file_id' LIMIT 1");
$where = array();
while($row = $db->get_row()) {
$rows[] = strip_num_rows($row);
}
return array_shift($rows);
} else {
return false;
}
}
function get_all_companies() {
$db = new database();
$db->query("SELECT * FROM `users_accts` WHERE `utype` = 'Company' ");
$where = array();
while($row = $db->get_row()) {
$rows[] = strip_num_rows($row);
}
return $rows;
}
function get_header() { ?>
Method Advisors
}
function redirect_to( $location = NULL){
if ($location != NULL) {
header("Location: {$location}");
exit;
}
}
$google_analytics='';
?>
Warning: Cannot modify header information - headers already sent by (output started at /home/forge/methodadvisors.com/intranet/includes/include.php:220) in /home/forge/methodadvisors.com/intranet/controllers/Common.class.php on line 88
Notice: Undefined variable: _SESSION in /home/forge/methodadvisors.com/intranet/controllers/Common.class.php on line 90