<?php /* :folding=explicit:collapseFolds=1:*/ $PAGE_LIMIT = 10; $RATE_LIMIT = 10; // implicit login {{{ if (empty($_SESSION['user']) && isset($_COOKIE['passport']) && isset($_COOKIE['user'])) { $_GET['asdasdasd'] = $_COOKIE['passport']; // лениво экранировать отдельно $pass = cm_get('asdasdasd', 'str'); // экранируем как гет $id = (int) $_COOKIE['user']; $user = $db->q2assoc("\n\t\tSELECT *\n\t\tFROM user\n\t\tWHERE id = {$id} AND secret_code = '{$pass}';", true); if ($user && $user['allow_cookies'] == 'Y') { $user['logged'] = true; $_SESSION['user'] = $user; } else { $_SESSION['user'] = array('logged' => false); } } // }}} function discussion($discussion_id) { /* {{{ */ global $coms, $db; $GLOBALS['AJAX_COMMENTS'] = true; unset($_GET['q']); require_once 'discussion.inc'; discussion_comments($discussion_id, $coms, $top); /* $coms = $db->q2assoc("SELECT * FROM comment WHERE discussion_id = $discussion_id ORDER BY post_date;"); // 1 run: build index
function HelpTopic() { /* {{{ */ $n = cm_get('Name', 'str'); // get topic id $r = $db->q2assoc(' SELECT ht.id FROM help_topic ht WHERE name = \'' . $n . '\' LIMIT 1;', true); $topic_id = (int) $r['id']; if (!$topic_id) { echo php2js(array('name' => $n)); break; } // get author's topic content edition $r = $db->q2assoc(' SELECT id FROM help_topic_content WHERE topic_id = ' . $topic_id . ' AND state_id = 1 AND author_id = ' . $_SESSION['user']['id'] . ' LIMIT 1;', true); $max_id = (int) $r['id']; $r = $db->q2assoc(' SELECT ht.*, htc.text as content, ' . $max_id . ' as not_approved FROM help_topic ht INNER JOIN help_topic_content htc ON ' . ($max_id ? 'htc.topic_id = ht.id' : 'htc.id = ht.content_id') . ' WHERE ' . ($max_id ? 'htc.id = ' . $max_id : 'ht.id = ' . $topic_id) . ' LIMIT 1;', true); $r['name'] = $n; echo php2js($r); /* }}} */ }
function weekly() { $year_week = cm_get('year_week', 'string') or $year_week = date('Y_W'); list($year, $week) = split('_', $year_week); $year = (int) $year; $week = (int) $week; if (isset($_GET['go'])) { $week += $_GET['go'] == 'prev' ? -1 : 1; if ($week == 0) { $year--; $week = 53; } elseif ($week == 54) { $year++; $week = 1; } } lg($week . ' week of ' . $year . ' year'); $first_jan = mktime(0, 0, 0, 1, 1, $year); $weekday_first_jan = (int) strftime('%w', $first_jan); $delta = 4 - $weekday_first_jan; if ($delta < 0) { $delta = $delta + 7; } $first_week_start = $first_jan + ($delta - 3) * 86400; $nth_week_start = $first_week_start + 86400 * 7 * ($week - 1); $nth_week_end = $nth_week_start + 86400 * 7 - 1; $date_start = db_date($nth_week_start); $date_end = db_date($nth_week_end); $sql_breakdown = ' SELECT SUM(outlay.value) AS sum, c.name FROM outlay INNER JOIN outlay_category c ON c.id = outlay.outlay_category_id WHERE outlay.created_at BETWEEN "' . $date_start . '" AND "' . $date_end . '" GROUP BY c.name '; $this->tpl->add('breakdown', db_fetch_all($sql_breakdown)); $sql = ' SELECT outlay.*, c.name, user.name as author_name, DAY(outlay.created_at) as weekday FROM outlay INNER JOIN outlay_category c ON c.id = outlay.outlay_category_id LEFT JOIN user ON user.id = outlay.user_id WHERE outlay.created_at BETWEEN "' . $date_start . '" AND "' . $date_end . '" ORDER BY MONTH(outlay.created_at), weekday ASC, c.name ASC, outlay.created_at '; $outlay_records = db_fetch_all($sql); $weekdata = array(); $prev_weekday = -1; $day->total = 0; $day->last_record_time = 0; $day->items = array(); $cat->total = 0; $cat->items = array(); $prev_cat = ''; foreach ($outlay_records as $outlay) { // add old category to day, if new cat or new day if ($prev_cat && $outlay->name !== $prev_cat || $prev_weekday !== -1 && $prev_weekday !== $outlay->weekday) { $day->total += $cat->total; $day->items[] = $cat; $last_record_time = $cat->items[count($cat->items) - 1]->created_at; if ($day->last_record_time < $last_record_time) { $day->last_record_time = $last_record_time; } $cat = new stdClass(); $cat->total = 0; $cat->items = array(); } // add old day to week, if new day if ($prev_weekday !== -1 && $prev_weekday !== $outlay->weekday) { $last_cat = $day->items[count($day->items) - 1]; $last_record_time = $last_cat->items[count($last_cat->items) - 1]->created_at; if ($day->last_record_time < $last_record_time) { $day->last_record_time = $last_record_time; } $weekdata[] = $day; $day = new stdClass(); $day->total = 0; $day->items = array(); } $cat->total += $outlay->value; $cat->items[] = $outlay; $prev_weekday = $outlay->weekday; $prev_cat = $outlay->name; } if ($prev_cat) { $day->total += $cat->total; $day->items[] = $cat; $last_record_time = $cat->items[count($cat->items) - 1]->created_at; if ($day->last_record_time < $last_record_time) { $day->last_record_time = $last_record_time; } } if ($prev_weekday !== -1) { $weekdata[] = $day; } $this->tpl->add('index', $outlay); $this->tpl->add('weekdata', $weekdata); $this->tpl->add('year', $year); //die(date('Y_W', $first_week_start)); $this->tpl->add('week', $week); $this->tpl->view('outlay.index'); }