Example #1
0
    /**
     * @param $problem_id int
     * @return object problem
     */
    function get_problem($problem_id)
    {
        /* {{{ */
        /* TODO: Check owner */
        return db_fetch_one('
			SELECT
				p.id,
				p.name,
				p.deadline,
				p.description,
				p.priority,
				p.state_id,
				p.owner_id,
				p.is_actual,
				p.create_date,
				s.date as sol_date,
				s.comment as sol_comment,
				s.id as sol_id,
				s.is_active,
				c.icon as cat_icon,
				c.id as cat_id,
				c.name as cat_name
			FROM
				problem p LEFT JOIN 
				solution s ON p.id = s.problem_id LEFT JOIN
				problem_category c ON p.category_id = c.id
			WHERE
				p.id = ' . (int) $problem_id . '
			LIMIT 1;
		');
        /* }}} */
    }
Example #2
0
function db_fetch_value($sql, $defaultValue = null)
{
    $one = db_fetch_one($sql);
    if ($one == null) {
        return $defaultValue;
    }
    foreach ($one as $k => $v) {
        return $v;
    }
    return $defaultValue;
}
Example #3
0
    function init()
    {
        if (!$this->screen) {
            $this->screen = 'cheatsheets';
        }
        switch (count($this->path)) {
            case 2:
                $this->screen = 'view_cheatsheet';
                $this->tpl->add('cheatsheet', db_fetch_one('
				SELECT * FROM cs_cheatsheet cs INNER JOIN cs_cheat c ON cs.id = c.cheatsheet_id  WHERE name = "' . db_escape($this->path[1]) . '"
			'));
                die('SELECT * FROM cs_cheatsheet cs INNER JOIN cs_cheat c ON cs.id = c.cheatsheet_id  WHERE name = "' . db_escape($this->path[1]) . '"');
        }
    }
Example #4
0
function db_total_rows()
{
    $row = db_fetch_one("SELECT FOUND_ROWS() AS total");
    return (int) $row['total'];
}
Example #5
0
<?php

$post = get_post();
$pelanggan = db_fetch_one('SELECT * FROM pelanggan WHERE email = ?', array($post['email']));
$result = array('success' => false, 'message' => 'Email atau password salah !');
if ($pelanggan && md5($post['password']) == $pelanggan['password']) {
    csrf_protect();
    $result['success'] = true;
    $result['message'] = '';
    unset($pelanggan['password']);
    set_session('pelanggan', $pelanggan);
}
sleep(1);
// test doank
print json_encode($result);
Example #6
0
 public static function getCodeByPhone($phone)
 {
     $sql = "SELECT *FROM VerifyCode WHERE phone=?";
     bindParams($sql, array($phone));
     $r = db_fetch_one($sql);
     return $r;
 }
         } else {
             $simpan = db_query("INSERT INTO products (name, slug, category) VALUES (?, ?, ?)", array($name, $slug, $category));
             if ($simpan) {
                 echo "Data berhasil disimpan";
             } else {
                 echo "Data gagal disimpan";
             }
         }
     }
     break;
 case 'update':
     $id = $post['id'];
     $name = $post['name'];
     $slug = $post['slug'];
     $category = $post['category'];
     $cek = db_fetch_one("SELECT * FROM products WHERE slug = ? AND id <> ?", array($slug, $id));
     if (!$name || !$slug || !$category) {
         echo "Data tidak lengkap !";
     } else {
         if (!empty($cek)) {
             echo "Sudah ada data slug yang sama !";
         } else {
             $ubah = db_query("UPDATE products SET name = ?, slug = ?, category = ? WHERE id = ?", array($name, $slug, $category, $id));
             if ($ubah) {
                 echo "Data berhasil diubah";
             } else {
                 echo "Data gagal diubah";
             }
         }
     }
     break;
Example #8
0
     // todo: список категорий
     print_topics_list("t.category_id = {$param}");
     $title = 'Топики по категории';
     /* }}} */
     break;
 case 'tag':
     /* По тэгу {{{ */
     $tag = mb_strtolower(urldecode($param), 'utf-8');
     print_topics_list("EXISTS (\n\t\t\tSELECT * \n\t\t\tFROM topics_tags tt INNER JOIN tag \n\t\t\tWHERE tag.name = '{$tag}' AND tt.topic_id = t.id AND tt.tag_id = tag.id\n\t\t)");
     $title = "Топики c тэгом {$tag}";
     /* }}} */
     break;
 case 'post':
     /* {{{ */
     settype($param, 'int');
     $topic = db_fetch_one("SELECT t.* FROM topic t WHERE id = {$param};", true);
     $c = $topic['content'];
     //preg_replace(array('/\n(\n)+/','/\n/'),array('</p><p>','<br/>'),trim($topic['content']));
     echo '<div class="topic_title">' . $topic['title'] . '</div>';
     echo '<div class="topic_info">';
     echo '<div class="content">' . $c . '</div>';
     $tags = db_fetch_array("\n\t\t\tSELECT t.name FROM topics_tags tt\n\t\t\tINNER JOIN tag t ON t.id = tt.tag_id\n\t\t\tWHERE tt.topic_id = {$param}\n\t\t\tORDER BY tt.id;\n\t\t", 'name');
     if (count($tags)) {
         $x = array();
         foreach ($tags as $row) {
             $x[] = '<a href="/read/tag/' . $row . '">' . $row . '</a>';
         }
         echo '<div class="tags">' . join(', ', $x) . '</div>';
     }
     echo '</div>';
     if ($topic['discussion_id']) {
Example #9
0
 function edit()
 {
     $this->tpl->add('outlay', db_fetch_one('SELECT * FROM outlay WHERE id = ' . $this->entity_id));
     parent::edit();
 }
Example #10
0
        $aFilteringRules[] = "`" . $aColumns[$i] . "` LIKE '%" . db_escape($input['sSearch_' . $i]) . "%'";
    }
}
if (!empty($aFilteringRules)) {
    $sWhere = " WHERE " . implode(" AND ", $aFilteringRules);
} else {
    $sWhere = "";
}
$aQueryColumns = array();
foreach ($aColumns as $col) {
    if ($col != ' ') {
        $aQueryColumns[] = $col;
    }
}
$sQuery = "SELECT SQL_CALC_FOUND_ROWS `" . implode("`, `", $aQueryColumns) . "`\n    FROM `" . $sTable . "`" . $sWhere . $sOrder . $sLimit;
$rResult = db_fetch_all($sQuery);
$tResult = db_fetch_one("SELECT FOUND_ROWS() as t");
$iFilteredTotal = $tResult['t'];
$tResult = db_fetch_one("SELECT COUNT(`" . $sIndexColumn . "`) as t FROM `" . $sTable . "`");
$iTotal = $tResult['t'];
$output = array("sEcho" => intval($input['sEcho']), "iTotalRecords" => $iTotal, "iTotalDisplayRecords" => $iFilteredTotal, "aaData" => array());
foreach ($rResult as $aRow) {
    $row = array();
    $btn = '<a href="javascript:;" onClick="showModProduct(\'' . $aRow['id'] . '\')" class="eddel">Edit</a> | <a href="javascript:;" onClick="deleteProduct(\'' . $aRow['id'] . '\')" class="eddel">Hapus</a>';
    for ($i = 0; $i < $iColumnCount; $i++) {
        $row[] = $aRow[$aColumns[$i]];
    }
    $row = array($btn, $aRow['name'], $aRow['slug'], $aRow['category']);
    $output['aaData'][] = $row;
}
echo json_encode($output);
Example #11
0
$remains = 30;
if (has_session('login_timer')) {
    $elapsed = microtime(true) - get_session('login_timer');
    $remains = round(30 - $elapsed);
    if ($elapsed >= 30) {
        unset_session('login_timer');
        $login_attempt = 1;
    }
}
if ($login_attempt == 3) {
    $result['message'] = 'Too many failed login attempts. Please try again in ' . $remains . ' seconds';
    if (!has_session('login_timer')) {
        set_session('login_timer', microtime(true));
    }
} else {
    $user = db_fetch_one('SELECT * FROM users WHERE email = ?', array($post['email']));
    if ($user && md5($post['password']) == $user['passwd']) {
        csrf_protect();
        $result['success'] = true;
        $result['message'] = '';
        unset($user['passwd']);
        set_session('user', $user);
        unset_session('login_attempt');
        unset_session('login_timer');
    } else {
        $login_attempt++;
        set_session('login_attempt', $login_attempt);
    }
}
sleep(1);
// test doank