function getMessages($fromMessageId = 0, $messageType = 0, $maxMessags = 1) { $msgType = $messageType; if ($msgType != 0) { $msgType = "WHERE type='" . $msgType . "'"; } else { $msgType = ""; } try { $db = new PDO("sqlite:" . $this->dbName, $this->dbLogin, $this->dbPass); $db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); } catch (PDOException $errorExcept) { die("Error with Database: " . $errorExcept); } $result = null; // if ($fromMessageId>0) { // $range_sql = "WHERE id>=".$fromMessageId." AND id<".($fromMessageId+$maxMessags)." "; // } else { // $range_sql = ""; // } // $result = $db->query ("SELECT * FROM messages ".$range_sql.$msgType." ORDER BY date DESC LIMIT ".$maxMessags); $result = $db->query("SELECT * FROM messages ORDER BY date DESC LIMIT " . $fromMessageId . "," . $maxMessags); $messagesData = array(); $aid = 0; while ($row = $result->fetchObject()) { $messagesData[$aid] = $row; $user = new class_User(); $userFullName = $user->getUser('id', $messagesData[$aid]->user_id); $messagesData[$aid]->userFullName = $userFullName->login; $aid++; } return $messagesData; }
function authUser($userName, $userPass) { $userName = strip_tags($userName); $userPass = strip_tags($userPass); $userDataRec = new class_User(); $userData = $userDataRec->getUser("login", strtolower($userName)); $passHash = md5($userPass); $passDbHash = $userData->password; $authOk = false; if ($passHash != $passDbHash) { $authOk = false; } else { $authOk = true; } return $authOk; }
$messagesCount = $get_messages->getMessagesCount(); if (isset($_GET['page'])) { $page = $_GET['page'] - 1; } else { $page = 0; } $start = abs($page * $configData->maxShowPosts); $messages = $get_messages->getMessages($start, 0, $configData->maxShowPosts); // Assign messages to Smarty template $smarty->assign('messages', $messages); // Pages $t_pages = ceil($messagesCount / $configData->maxShowPosts); $pagesText = ''; for ($tstep = 1; $tstep <= $t_pages; $tstep++) { if ($tstep - 1 == $page) { $pagesText .= "<strong>[" . $tstep . "]</strong> "; } else { $pagesText .= '<a href="' . $_SERVER['PHP_SELF'] . '?page=' . $tstep . '">' . $tstep . "</a> "; } } $smarty->assign("Pages", $pagesText); // Show page $userEcho = new class_User(); $userEcho2 = $userEcho->authUser("admin", "amaga911"); echo (int) $userEcho2; $smarty->display('index.tpl'); ?> </body> </html>