public function index() { $data = $this->read($this->current_name); if (!empty($data)) { $data = cache_remember('ledger.index.' . (string) auth('id'), function () use($data) { $arr = array(); foreach ($data as $key => $value) { $total_got = 0; $total_pay = 0; foreach ($value as $k2 => $v2) { $ex = explode(':|', $v2); if ($ex['0'] === '1') { $total_pay += intval($ex['2']); } else { $total_got += intval($ex['2']); } } $compute = $total_got - $total_pay; $arr[$key] = array('0' => array('value' => $compute, 'color' => $compute < 0 ? '#F7464A' : '#0EA606', 'highlight' => $compute < 0 ? '#FF5A5E' : '#2EEC24', 'label' => 'ยอดหักล้าง'), '1' => array('value' => $total_pay, 'color' => '#E97720', 'highlight' => '#F98C38', 'label' => 'รายจ่าย'), '2' => array('value' => $total_got, 'color' => '#0A4DB1', 'highlight' => '#1365E1', 'label' => 'รายรับ')); } return json_encode($arr); }); } else { $data = 'null'; } return $this->view('ledger/index', compact('data')); }
public function run() { if (role_check(0)) { $data = cache_remember('admin.major.list', function () { $major = new \app\models\Faculty(); return $major->getAllMajor(); }); return $this->view('layouts/loginbox', compact('data')); } return $this->view('layouts/loginbox'); }
public function run() { $data = cache_remember('user.inactive.' . auth('id'), function () { $user = new \app\models\User(); return $user->getActiveData(auth('id')); }); if ($data['active'] === '1') { $_SESSION['auth']['active'] = '1'; cache_forgot('user.inactive.' . auth('id')); echo '<div class="alert alert-success">คุณได้รับการยืนยันแล้วว่า ข้อมูลถูกต้องและเป็นสมาชิกของสาขานี้ กรุณา reload page</div>'; } }
public function getJson() { $news = cache_remember('p.getJson.news.' . user('major'), function () { $news = new \app\models\News(); return json_encode($news->getNewsList()); }); $user = cache_remember('user.get.members.' . user('major'), function () { $user = new \app\models\User(); return json_encode($user->getMembers(true)); }); $gbnews = cache_remember('home.gbnews', function () { $gbnews = new \app\models\GbNews(); return json_encode($gbnews->lists(6)); }); echo '{ "news":' . $news . ', "users":' . $user . ', "gbnews":' . $gbnews . ' }'; }
public function get($act) { switch ($act) { case 'members': echo cache_remember('user.get.members.' . user('major'), function () { $user = new User(); return json_encode($user->getMembers(true)); }, 1440); break; } }
private function eNews($id = null) { if (is_post()) { $this->loadHelper('Validator'); $data = array('title' => strip_tags(validate('required', 'title')), 'content' => validate('required', 'content'), 'updated_at' => date('Y-m-d H:i:s')); $id = validate('required', 'token'); if (validator($data) && !is_null($id)) { $id = base64_decode($id); if (!preg_match('/^[0-9]+$/', $id)) { exit('401'); } $news = new \app\models\News(); if ($_POST['c_readIn'] === 'on') { $data['readIn'] = null; } if ($news->updateNews($data, $id)) { cache_forgot('p.n.' . $id); cache_forgot('p.getJson.news.' . user('major')); } return redirect(''); } } else { if (preg_match('/^[0-9]+$/', $id)) { $data = cache_remember('p.n.' . $id, function () use($id) { $news = new \app\models\News(); $data = $news->getNews($id); if (!empty($data)) { return $data; } return false; }); if (!is_null($data) && $data['major_id'] === user('major')) { return $this->view('editNews', compact('data')); } } return $this->view('errors/404'); } }