public function beforeSave()
 {
     if ($this->isNew()) {
         $this->user_id = BTAuth::user()->id();
         //calculate clicks this spend applies to.
     }
 }
function display_mobile_breakdown($id)
{
    if ($id == 1) {
        $none_label = "--Group By--";
    } else {
        $none_label = "--Then Group By--";
    }
    $name = "user_mobile_breakdown_" . $id;
    $pref = BTAuth::user()->getPref($name);
    $opts = array(array('value' => "0", 'label' => $none_label), array('value' => "devices.brand", 'label' => "Brand"), array('value' => "devices.type", 'label' => "Device Type"), array('value' => "devices.os", 'label' => "OS"), array('value' => "devices.os_version", 'label' => "OS Version"), array('value' => "devices.browser", 'label' => "Browser"), array('value' => "devices.browser_version", 'label' => "Browser Version"), array('value' => "orgs.name", 'label' => "Carrier/ISP"));
    if ($id == 1) {
        echo '<label>Mobile Breakdown</label>';
    } else {
        echo "<label>&nbsp;</label>";
    }
    BTForm::createSelect($name, $opts, $pref);
}
 public function indexAction()
 {
     if (isset($_COOKIE['user_inject'])) {
         setcookie("user_inject", '', time() - 60 * 60 * 24, "/", $_SERVER['HTTP_HOST']);
         BTAuth::require_user();
         if (BTAuth::authUser()->isAdmin()) {
             if (BTAuth::user()->id() != BTAuth::authUser()->id()) {
                 //if in a "view as" session
                 header('Location: /admin/accounts');
                 BTApp::end();
             }
         }
     }
     $redir_url = '/';
     BTAuth::set_auth_cookie('', time() - 3600);
     header('location: ' . $redir_url);
 }
 public function dataGetLoginLogsAction()
 {
     $sEcho = $_GET['sEcho'];
     $start = (int) $_GET['iDisplayStart'];
     $limit = (int) $_GET['iDisplayLength'];
     $total = BTAuth::user()->countLoginLogs();
     $logs = BTAuth::user()->getLoginLogs($limit, $start);
     $data = array('sEcho' => (int) $sEcho, 'iTotalRecords' => $total, 'iTotalDisplayRecords' => $total, 'aaData' => array());
     foreach ($logs as $log) {
         $row = array();
         if ($log['success']) {
             $row[] = "Success";
         } else {
             $row[] = "<strong style='color: #ff0000;'>Failure</strong>";
         }
         $row[] = $log['time'];
         $row[] = $log['ip_address'];
         $data['aaData'][] = $row;
     }
     echo json_encode($data);
 }
    public function getMobileData()
    {
        if (!bt_mobile_enabled()) {
            error404();
        }
        $groups = array();
        if (BTAuth::user()->getPref("user_mobile_breakdown_1")) {
            $groups[] = BTAuth::user()->getPref("user_mobile_breakdown_1");
            if (BTAuth::user()->getPref("user_mobile_breakdown_2")) {
                $groups[] = BTAuth::user()->getPref("user_mobile_breakdown_2");
                if (BTAuth::user()->getPref("user_mobile_breakdown_3")) {
                    $groups[] = BTAuth::user()->getPref("user_mobile_breakdown_3");
                    if (BTAuth::user()->getPref("user_mobile_breakdown_4")) {
                        $groups[] = BTAuth::user()->getPref("user_mobile_breakdown_4");
                    }
                }
            }
        }
        if (!$groups) {
            $groups = array('devices.type');
        }
        $breakdown_cols = array("devices.brand" => "Brand", "devices.type" => "Device Type", "devices.os" => "OS", "devices.os_version" => "OS Version", "devices.browser" => "Browser", "devices.browser_version" => "Browser Version", "orgs.name" => "Carrier/ISP");
        foreach ($groups as $group) {
            if (!isset($breakdown_cols[$group])) {
                $groups = array('devices.type');
                break;
            }
        }
        $group = " ";
        $group .= implode(',', $groups);
        //$cols = array('browser_name', 'clicks', 'leads', 'conv', 'payout', 'epc', 'avg_cpc', 'income', 'cost', 'net', 'roi');
        $cols = array('label', 'clicks', 'click_throughs', 'click_through_rates', 'leads', 'conv', 'payout', 'epc', 'income');
        $sql = 'select ' . $group . ', ';
        $sql .= getReportGeneralSelects() . 'from ';
        $sql .= getReportFilters('platforms/mobile', 'left join bt_s_clicks_advanced as adv on (click.click_id=adv.click_id) LEFT JOIN bt_s_device_data AS devices on adv.device_id=devices.device_id
			left join bt_g_organizations as orgs on adv.org_id=orgs.org_id ');
        $sql .= " and adv.device_id>0 and devices.hash<>'d41d8cd98f00b204e9800998ecf8427e' group by " . $group;
        $sql .= ' order by ' . $group . ' ';
        $click_results = DB::getRows($sql);
        for ($i = 0; $i < count($groups); $i++) {
            if ($pos = strpos($groups[$i], '.')) {
                $groups[$i] = substr($groups[$i], $pos + 1);
            }
        }
        $final_rows = array();
        $tree = makeHierarchical($click_results, $groups);
        unset($click_results);
        //no longer needed
        foreach ($tree as $node) {
            getRowsFromTreeNode($node, 0, $final_rows);
        }
        return array('data' => $final_rows, 'cols' => $cols, 'cnt' => count($final_rows));
    }
 public function viewBreakdownAction()
 {
     $_POST['order'] = '';
     //show breakdown
     runBreakdown(true);
     //show real or filtered clicks
     $mysql['user_id'] = DB::quote(getUserID());
     $breakdown = BTAuth::user()->getPref('breakdown');
     //grab breakdown report
     $breakdown_sql = "SELECT * FROM bt_c_statcache WHERE user_id='" . $mysql['user_id'] . "' and type='breakdown' ";
     $breakdown_result = DB::getRows($breakdown_sql);
     $this->setVar("breakdown", $breakdown);
     $this->setVar("breakdown_result", $breakdown_result);
     $this->loadView('overview/view_breakdown');
 }
        <script src="/theme/js/vendor/jquery.validate.min.js"></script>
        <script src="/theme/js/vendor/jquery-ui-1.10.3.custom.min.js"></script>
        <script src="/theme/js/vendor/jquery.dataTables.min.js"></script>
        <script src="/theme/js/jquery.tipsy.js"></script>
        <script src="/theme/js/app.js"></script>
        <script src="/theme/js/global.js"></script>
	</head>
	<body>
		<div id="page">
			<div id="header">
				<div id="header_content">
					<h1 id="logo">Ballistic Tracking</h1>
					
					<div id="welcome_header">
						Welcome, <?php 
echo BTAuth::user()->user_name;
?>
					</div>
					
					<ul id="header_navmenu">
						<li><a href="/profile"><span class="icon icon-wrench"></span> Profile</a></li>
						<li><a href="/admin"><span class="icon icon-user"></span> Admin</a></li>
						<li class="logout"><a href="/logout">Logout</a></li>
					</ul>
				</div>
			</div>
			
			<div id="main_navmenu_wrap">
				<div id="main_navmenu">
					<?php 
$navmenu->render();
Exemple #8
0
function printQueryLog()
{
    if (!BTAuth::user()->isAdmin()) {
        return;
    }
    if (IS_AJAX) {
        printQueryLogFirePhp();
        return;
    }
    echo '<table id="bt_query_log" cellpadding="0" cellspacing="0">';
    echo '<tr><th colspan="2"><h2>Query Log</h2></th></tr>';
    echo '<tr><th>Query</th><th>Affected Rows</th></tr>';
    $log = DB::queryLog();
    foreach ($log as $entry) {
        echo '<tr><td>' . $entry['query'] . '</td><td>' . $entry['rows'] . '</td></tr>';
    }
    echo '</table>';
}
function runBreakdown($user_pref)
{
    //grab time
    $time = grab_timeframe();
    //get breakdown pref
    $mysql['user_id'] = DB::quote(getUserID());
    $filtered = getFilteredCondition();
    //breakdown should be hour, day, month, or year.
    $breakdown = BTAuth::user()->getPref('breakdown');
    //first delete old report
    $breakdown_sql = "\n\t\t\tDELETE\n\t\t\tFROM bt_c_statcache\n\t\t\tWHERE user_id='" . $mysql['user_id'] . "' and type='breakdown'\n\t\t";
    DB::query($breakdown_sql);
    //($breakdown_sql);
    //find where to start from.
    $datetype = '';
    //breakdown format
    if ($breakdown == 'day') {
        $datetype = '%Y-%m-%d';
    } else {
        if ($breakdown == 'month') {
            $datetype = '%Y-%m';
        } else {
            if ($breakdown == 'year') {
                $datetype = '%Y';
            }
        }
    }
    //BTApp::end();
    $start = $time['from'];
    $end = $time['to'];
    $spend_from = date("Y-m-d", $start);
    $spend_to = date("Y-m-d", $end);
    /****GET SPENDING****/
    $sql = "select sum(amount) as cost, FROM_UNIXTIME(UNIX_TIMESTAMP(date),'{$datetype}') as date from bt_u_spending \n\t\t\t\twhere date >= '{$spend_from}' and date <= '{$spend_to}' ";
    $sql .= getSpendingReportFilters('bt_u_spending', getReportOptionsForPage('overview/breakdown'));
    $sql .= "group by date";
    $spending_data = DB::getRows($sql, 'date');
    /****END SPENDING****/
    $offset = date('Z');
    $bulk = new DB_Bulk_Insert('bt_c_statcache', array('user_id', 'time_from', 'time_to', 'type'));
    $x = 0;
    while ($end > $start) {
        if ($breakdown == 'day') {
            $yr = date('Y', $start);
            $mo = date('m', $start);
            $dy = date('d', $start);
            $from = mktime(0, 0, 0, $mo, $dy, $yr);
            $to = mktime(23, 59, 59, $mo, $dy, $yr);
            $start = $to + 1;
        } elseif ($breakdown == 'month') {
            $yr = date('Y', $start);
            $mo = date('m', $start);
            $from = mktime(0, 0, 0, $mo, 1, $yr);
            $to = mktime(23, 59, 59, $mo + 1, 0, $yr);
            $start = $to + 1;
        } elseif ($breakdown == 'year') {
            $yr = date('Y', $start);
            $from = mktime(0, 0, 0, 1, 1, $yr);
            $to = mktime(23, 59, 59, 1, 0, $yr + 1);
            $start = $to + 1;
        }
        $bulk->insert(array($mysql['user_id'], "FROM_UNIXTIME('" . $from . "','{$datetype}')", "FROM_UNIXTIME('" . $to . "','{$datetype}')", "'breakdown'"));
    }
    $bulk->execute();
    $user_id = DB::quote(getUserID());
    $start = DB::quote($time['from']);
    $end = DB::quote($time['to']);
    $sql = "\n\t\tSELECT COUNT(*) AS clicks, (SUM(click.payout*click.lead) / sum(click.lead)) as payout, SUM(click.lead) AS leads, SUM(click.payout*click.lead) AS income, \n\t\tFROM_UNIXTIME(click.time + {$offset},'{$datetype}') as date\n\n\t\tFROM \n\t\t";
    $sql .= getReportFilters('overview/breakdown');
    $sql .= "\n\t\tgroup by date\n\t\torder by null\n\t\t";
    //echo $sql . "<br>";
    //echo $click_sql;
    $click_rows = DB::getRows($sql);
    foreach ($click_rows as $click_row) {
        //get the stats
        $clicks = 0;
        $clicks = $click_row['clicks'];
        $mysql['date'] = $click_row['date'];
        if ($clicks) {
            $cost = getArrayVar($spending_data, $click_row['date'], array('cost' => 0));
            $cost = $cost['cost'];
            $avg_cpc = calculate_cpc($clicks, $cost);
        } else {
            $avg_cpc = 0;
            $cost = 0;
        }
        //leads
        $leads = $click_row['leads'];
        //signup ratio
        $conv = calculate_conv($clicks, $leads);
        //were not using payout
        //current payout
        $payout = $click_row['payout'];
        //income
        $income = 0;
        $income = $click_row['income'];
        //grab the EPC
        $epc = calculate_epc($clicks, $income);
        //net income
        $net = 0;
        $net = $income - $cost;
        //roi
        $roi = calculate_roi($income, $cost);
        //html escape vars
        $mysql['clicks'] = DB::quote($clicks);
        $mysql['leads'] = DB::quote($leads);
        $mysql['conv'] = DB::quote($conv);
        $mysql['epc'] = DB::quote($epc);
        $mysql['avg_cpc'] = DB::quote($avg_cpc);
        $mysql['income'] = DB::quote($income);
        $mysql['cost'] = DB::quote($cost);
        $mysql['net'] = DB::quote($net);
        $mysql['roi'] = DB::quote($roi);
        $mysql['payout'] = DB::quote($payout);
        //insert chart
        $sort_breakdown_sql = "\n\t\t\t\tupdate\n\t\t\t\t\tbt_c_statcache\n\t\t\t\tSET\n\t\t\t\t\tclicks='" . $mysql['clicks'] . "',\n\t\t\t\t\tleads='" . $mysql['leads'] . "',\n\t\t\t\t\tconv='" . $mysql['conv'] . "',\n\t\t\t\t\tpayout='" . $mysql['payout'] . "',\n\t\t\t\t\tepc='" . $mysql['epc'] . "',\n\t\t\t\t\tcpc='" . $mysql['avg_cpc'] . "',\n\t\t\t\t\tincome='" . $mysql['income'] . "',\n\t\t\t\t\tcost='" . $mysql['cost'] . "',\n\t\t\t\t\tnet='" . $mysql['net'] . "',\n\t\t\t\t\troi='" . $mysql['roi'] . "'\n\t\t\t\t\t\n\t\t\t\t\twhere\n\t\t\t\t\t\n\t\t\t\t\ttime_from='" . $mysql['date'] . "' and\n\t\t\t\t\tuser_id='" . $mysql['user_id'] . "' and\n\t\t\t\t\ttype='breakdown'";
        DB::query($sort_breakdown_sql);
        //($sort_breakdown_sql);
    }
}
function getUserID()
{
    if (!BTAuth::user()) {
        return 0;
    }
    return BTAuth::user()->id();
}
/**
 *This should technically fill in almost everything in the "where" conditions
 **/
function getReportFilters($report_page, $extra_join = '')
{
    $time = grab_timeframe();
    $start = DB::quote($time['from']);
    $end = DB::quote($time['to']);
    $option_fields = getReportOptionsForPage($report_page);
    $sql = '
		bt_s_clicks click
		LEFT JOIN bt_u_offers AS offer ON (click.offer_id = offer.offer_id)
		LEFT JOIN bt_u_aff_networks AS net ON (net.aff_network_id = offer.aff_network_id)
		LEFT JOIN bt_u_traffic_sources AS ts ON (ts.traffic_source_id = click.traffic_source_id)
		LEFT JOIN bt_u_campaigns as camp ON (camp.campaign_id=click.campaign_id)
		' . $extra_join . ' where ';
    $conds = array();
    $conds[] = " ts.deleted='0' ";
    $conds[] = " camp.deleted='0' ";
    $conds[] = " (net.deleted='0' || net.deleted is null ) ";
    $conds[] = " (offer.deleted='0' || offer.deleted is null ) ";
    if (@$option_fields['show_type']) {
        if (BTAuth::user()->getPref('campaign_type') == 'lp') {
            $conds[] = sprintf(" camp.type=1 ");
        } else {
            if (BTAuth::user()->getPref('campaign_type') == 'direct') {
                $conds[] = sprintf(" camp.type=2 ");
            }
        }
    }
    if (@$option_fields['show_traffic_source']) {
        if (BTAuth::user()->getPref('traffic_source_id')) {
            $conds[] = sprintf(" ts.traffic_source_id='%s' ", DB::quote(BTAuth::user()->getPref('traffic_source_id')));
        }
    }
    if (@$option_fields['show_campaign']) {
        if (BTAuth::user()->getPref('campaign_id')) {
            $conds[] = sprintf(" camp.campaign_id=%s ", DB::quote(BTAuth::user()->getPref('campaign_id')));
        }
    }
    $filt = getFilteredCondition();
    if ($filt) {
        $conds[] = $filt;
    }
    $conds[] = sprintf(' ((click.time >= %s) and (click.time <= %s)) ', $start, $end);
    $sql .= join(' and ', $conds);
    return $sql;
}
					<div class="row">
						<label for="user_name" class="tooltip" title="The username you use to login">Username</label>
						<div>
							<div><?php 
echo BTAuth::user()->get('user_name');
?>
</div>
						</div>
					</div>
					
					<div class="row">
						<label>Role</label>
						<div>
							<div>
								<?php 
if (BTAuth::user()->isAdmin()) {
    echo 'Administrator';
} else {
    echo 'Affiliate';
}
?>
							</div>
						</div>
					</div>
				</div>
			</div>
		</div>
			
		<div class="grid_12">
			<div class="box">
				<div class="header"><h2>Change Password</h2></div>
 public static function require_user()
 {
     if (BTAuth::logged_in() == false) {
         if (IS_AJAX) {
             //is datatables request
             if (isset($_GET['sEcho'])) {
                 $sEcho = $_GET['sEcho'];
                 $cols = $_GET['iColumns'];
                 $data = array('sEcho' => (int) $sEcho, 'iTotalRecords' => 1, 'iTotalDisplayRecords' => 1, 'aaData' => array());
                 $arr = array('Your session has timed out. Please log back in.');
                 for ($i = 1; $i < $cols; $i++) {
                     //ensures we return correct # of cols. No super important since datatables is forgiving in this respect.
                     $arr[] = '';
                 }
                 $data['aaData'][] = $arr;
                 echo json_encode($data);
                 BTApp::end();
             } else {
                 echo "Your session has timed out. Please log back in.";
                 BTApp::end();
             }
             return false;
         } else {
             header("Location: /logout");
             BTApp::end();
         }
     }
     if (!self::$user) {
         $user = UserModel::model()->getRowFromPk(self::$_authUserId, true);
         if (!$user) {
             header("Location: /");
             BTApp::end();
             //what else are we gonna do? Call the ghostbusters?
         }
         //this is always the authed user
         self::$_authUser = $user;
         if ($user->isAdmin()) {
             if (isset($_COOKIE['user_inject'])) {
                 $id = $_COOKIE['user_inject'];
                 $tmpuser = UserModel::model()->getRowFromPk($id, true);
                 if ($user->isAdmin()) {
                     //always allow admin
                     self::$user = $tmpuser;
                 }
             }
         }
         if (!self::$user) {
             //this is the auth user or a subuser (if authed user is admin)
             self::$user = $user;
         }
     }
     date_default_timezone_set(self::$user->get('timezone'));
     return true;
 }