function get_latest_new() { include '../model/news.php'; $news = new news(); $row = $news->latest_news(); if (!$news) { echo '{"result": 0, "message": "No news"}'; return; } echo '{"result": 1, "news": ['; while ($row) { echo json_encode($row); $row = $news->fetch(); if ($row) { echo ","; } } echo "]}"; return; }
private function process() { $config = services::getService('config'); $lang = services::getService('lang'); $params = services::getService('pageParams'); $mail = services::getService('mail'); // lost password if ($params->getParam('lostpassword') == 'true') { $this->lostpassword = true; $this->pwform = new formLostPassword('LostPassword'); if ($this->pwform->validate()) { // write email $user = new user(); $user->email = $this->pwform->exportValue('email'); if ($user->find(true)) { $mail->send('lostpassword', $user, $user->password); $user->password = crypt($user->password, 'dl'); $user->update(); $this->switchPage('home&msg=msg_pw_sent'); } else { $this->switchPage('home&lostpassword=true&msg=msg_no_email'); } } } else { // newsscript: write news if ($params->getParam('news') == 'writenews') { $newsform = new formNewsData("newsdata"); if ($newsform->validate()) { $new_news = new news(); $new_news->name = convertNewsSubmits($newsform->exportValue('newsname')); $new_news->abstract = convertNewsSubmits($newsform->exportValue('newsabstract')); $new_news->text = convertNewsSubmits($newsform->exportValue('newstext')); $new_news->date = time(); $new_news->lang = $newsform->exportValue('newslang'); $new_news->insert(); $newsform->freezeForm(); $this->addMsg('msg_news_submitted'); } $this->newsform = $newsform; } } // newsscript: show news headlines $shownews = new news(); $shownews->lang = $lang->getLang(); $shownews->orderBy('date DESC'); $shownews->find(); while ($shownews->fetch()) { $this->shownews[] = array('name' => $shownews->name, 'abstract' => $shownews->abstract, 'text' => $shownews->text, 'date' => date('d. m. Y', $shownews->date), 'id' => $shownews->id); } // Instantiate the HTML_QuickForm object $this->login_form = new formLogin('LoginForm'); // count resources and pools $pool_count = new pools(); $res_count = new resources(); $pool_count->wait = 0; $pool_count->find(); $res_count->find(); $this->pool_count = 0; while ($pool_count->fetch()) { ++$this->pool_count; } $this->res_count = 0; while ($res_count->fetch()) { ++$this->res_count; } // Try to validate a form if ($this->login_form->validate()) { if (loginCorrect($this->login_form->exportValue('login'), $this->login_form->exportValue('loginpassword'))) { $session = services::getService('pageParams'); if ($this->login_form->exportValue('remember')) { setcookie('login', $this->login_form->exportValue('login'), time() + 60 * 60 * 24 * 365); setcookie('password', $this->login_form->exportValue('loginpassword'), time() + 60 * 60 * 24 * 365); } else { $session->addParam('login', $this->login_form->exportValue('login'), 'session'); $session->addParam('password', $this->login_form->exportValue('loginpassword'), 'session'); } $session->addParam('msg', 'msg_login_correct', 'page'); $this->switchPage('mysite'); } else { $this->addMsg('msg_login_wrong'); } } else { if (isset($this->user)) { $this->switchPage('mysite'); } } }