alert('display = ' + display); } } //--> </script> endScript; $msg = isset($_REQUEST['msg']) ? $_REQUEST['msg'] : ''; if (isset($_POST['action']) && $_POST['action'] == "AIML") { $content .= getAIMLByFileName($_POST['getFile']); } elseif (isset($_POST['action']) && $_POST['action'] == "SQL") { $content .= getSQLByFileName($_POST['getFile']); } elseif (isset($_GET['file'])) { $content .= serveFile($_GET['file'], $msg); } else { } $content .= renderMain(); $showHelp = $template->getSection('DownloadShowHelp'); $topNav = $template->getSection('TopNav'); $leftNav = $template->getSection('LeftNav'); $main = $template->getSection('Main'); $topNavLinks = makeLinks('top', $topLinks, 12); $navHeader = $template->getSection('NavHeader'); $leftNavLinks = makeLinks('left', $leftLinks, 12); $FooterInfo = getFooter(); #$msg = (empty($msg)) ? 'Test' : $msg; $errMsgClass = !empty($msg) ? "ShowError" : "HideError"; $errMsgStyle = $template->getSection($errMsgClass); $noLeftNav = ''; $noTopNav = ''; $noRightNav = $template->getSection('NoRightNav'); $headerTitle = 'Actions:';
function proc_main($user) { $data = array(); global $g_config; $deleteUrl = ajaxLink('delete'); $clearUrl = ajaxLink('clearbalance'); $chart_data = get_chart_data(); $week = json_encode($chart_data['week']); $month = json_encode($chart_data['month']); $month_label = json_encode($chart_data['month_label']); $year = json_encode($chart_data['year']); $year_label = json_encode($chart_data['year_label']); $script = <<<EOF \t \$(function(){ \t Chart.defaults.global.responsive = true; var data = { \tweek:{ \t labels: ["Monday","Tuesday", "Wednesday", "Thursday", "Friday", "Saturday","Sunday"], \t datasets: [ \t { \t label: "Spend", \t fillColor: "rgba(151,187,205,0.2)", \t strokeColor: "rgba(151,187,205,1)", \t pointColor: "rgba(151,187,205,1)", \t pointStrokeColor: "#fff", \t pointHighlightFill: "#fff", \t pointHighlightStroke: "rgba(151,187,205,1)", \t data: {$week} \t } \t ] \t}, \tmonth:{ \t labels: {$month_label}, \t datasets: [ \t \t { \t label: "Spend", \t fillColor: "rgba(151,187,205,0.2)", \t strokeColor: "rgba(151,187,205,1)", \t pointColor: "rgba(151,187,205,1)", \t pointStrokeColor: "#fff", \t pointHighlightFill: "#fff", \t pointHighlightStroke: "rgba(151,187,205,1)", \t data: {$month} \t } \t ] \t}, \tyear:{ \t labels: {$year_label}, \t datasets: [ \t \t { \t label: "Spend", \t fillColor: "rgba(151,187,205,0.2)", \t strokeColor: "rgba(151,187,205,1)", \t pointColor: "rgba(151,187,205,1)", \t pointStrokeColor: "#fff", \t pointHighlightFill: "#fff", \t pointHighlightStroke: "rgba(151,187,205,1)", \t data: {$year} \t } \t ] \t}, }; var char_list = new Array(); function draw(id){ \tif(char_list[id]){ \t\tchar_list[id].destroy(); \t} \t\$("#"+id).html('<canvas id="Total_'+id+'"></canvas>'); \tvar ctx = document.getElementById('Total_'+id).getContext("2d"); \t \tchar_list[id] = new Chart(ctx).Line(data[id],{}); \t \t\t } draw("week"); \$(document).delegate('#chartm li a','click',function(e){ \tvar ca = \$(this).attr('href'); \tvar ca = ca.substr(1); \t \tdraw(ca); }); \t\$('.delete').click(function(){ \t\tvar id = \$(this).attr('data'); \t\tif(confirm('Are you sure to delete this statement?')){ \t\t\t\$.getJSON('{$deleteUrl}',{id:id},function(result){ \t\t\t\tif(result.status == '200'){ \t\t\t\t\talert('ok'); \t\t\t\t\twindow.location.href = 'index.php'; \t\t\t\t}else{ \t\t\t\t\talert(result.message); \t\t\t\t} \t\t\t}); \t\t} \t\t \t}); \t\$('#clear-balance').click(function(){ \t\tvar id = \$(this).attr('data'); \t\tif(confirm('Are you sure to clear the balance? This will clear both your roommate\\'s balance')){ \t\t\t\$.getJSON('{$clearUrl}',{},function(result){ \t\t\t\tif(result.status == '200'){ \t\t\t\t\talert('Clear Balance Successful'); \t\t\t\t\twindow.location.href = 'index.php'; \t\t\t\t}else{ \t\t\t\t\talert('You can not delete a cleared transaction'); \t\t\t\t} \t\t\t}); \t\t} \t}); }); EOF; $form['amount'] = ''; $form['description'] = ''; if (isset($_GET['status']) && $_GET['status'] == 'ok') { $data['notice'] = array('type' => 'success', 'message' => 'Add data successfully'); } if (isset($_POST['amount']) && isset($_POST['description'])) { $payee = []; foreach ($g_config['account'] as $u) { $payee_name = 'payee_' . $u['account']; if (isset($_POST[$payee_name])) { $payee[] = $u['account']; } } if (count($payee) == NUM_OF_USR) { $payee = []; } $form['amount'] = safe($_POST['amount']); $form['description'] = safe($_POST['description']); if (!is_numeric($form['amount'])) { $data['notice'] = array('type' => 'danger', 'message' => 'The amount is not a number'); } else { if (add($form['amount'], $form['description'], join(':', $payee))) { header('Location: index.php?status=ok'); } else { $data['notice'] = array('type' => 'danger', 'message' => 'Database error'); } } } $data['user'] = $user; $data['limit'] = 20; if (isset($_GET['page'])) { $data['page'] = intval(safe($_GET['page'])); $data['current_offset'] = $data['limit'] * $data['page']; } else { $data['page'] = 0; $data['current_offset'] = 0; } $data['detail'] = get_list($data['current_offset'], $data['limit']); $data['form'] = $form; foreach ($g_config['account'] as $key => $value) { $balance = get_user_current_balance($key); $data['current_balance_user'][$key]['balance'] = $balance; $data['current_balance_user'][$key]['name'] = $g_config['account'][$key]['name']; $data['current_balance_user'][$key]['phone'] = $g_config['account'][$key]['phone']; } $data['current_balance'] = get_total_current_balance(); renderMain($data, $script); }