Viewing file: controller.inc.php (9.99 KB) -rw-r--r-- Select action/file-type: (+) | (+) | (+) | Code (+) | Session (+) | (+) | SDB (+) | (+) | (+) | (+) | (+) | (+) |
<?php class List_Controller{ public static function MailAction() {
} public static function AddAction($params) { header("Location: https://e-dem.in.ua/zhytomyr"); die; switch(count($params)) { case 1: if ($params[0] == 'ajax') { if (List_Model::AddPetition($_POST)) { $res['ok'] = true; echo json_encode($res); die; } else { $res['ok'] = false; $res['error'] = 'Помилка заповнення форми'; echo json_encode($res); die; } } if ($params[0] == 'ok') { return array('Title' => 'Додавання петиції', 'Content' => List_View::ListAddOK()); } break; default: if (!Users_Model::IsAuthorized()) Main_Controller::Redirect('/users/login'); return array('Title' => 'Додавання електронної петиції', 'Content' => List_View::Add()); } } public static function GetRTFFileAction($param) { if (!Users_Model::IsAdmin()) return; $id = $param[0];
$question = List_Model::GetPetitionByIdForAdmin($id); $person = Users_Model::GetUserById($question['petition_user_id']); require "alien/phprtflite/lib/PHPRtfLite.php"; PHPRtfLite::registerAutoloader();
$rtf = new PHPRtfLite(); $sect = $rtf->addSection(); $table = $sect->addTable(); $table->addColumn("5"); $table->addColumn("10");
$par = new PHPRtfLite_ParFormat(); $par->setIndentRight(0); $par->setIndentLeft(1); $par->setBackgroundColor('#FFFFFF'); $par->setSpaceBefore(12);
$table->addRows(1); $row = 1; $cell = $table->getCell($row, 1); $cell->writeText("Дата надходження петиції: ", new PHPRtfLite_Font(12), new PHPRtfLite_ParFormat('left')); $cell = $table->getCell($row++, 2); $cell->writeText(Main_Model::GetUsefulDate("{$question['petition_date']}", true, true), new PHPRtfLite_Font(12), new PHPRtfLite_ParFormat('left'));
$table->addRows(1); $cell = $table->getCell($row, 1); $cell->writeText("Автор петиції: ", new PHPRtfLite_Font(12), new PHPRtfLite_ParFormat('left')); $cell = $table->getCell($row++, 2); $cell->writeText("{$person['user_firstname']} {$person['user_lastname']} {$person['user_middlename']}", new PHPRtfLite_Font(12), new PHPRtfLite_ParFormat('left'));
$table->addRows(1); $cell = $table->getCell($row, 1); $cell->writeText("E-mail автора: ", new PHPRtfLite_Font(12), new PHPRtfLite_ParFormat('left')); $cell = $table->getCell($row++, 2); $cell->writeText("{$person['user_email']}", new PHPRtfLite_Font(12), new PHPRtfLite_ParFormat('left'));
$table->addRows(1); $cell = $table->getCell($row, 1); $cell->writeText("Тема: ", new PHPRtfLite_Font(12), new PHPRtfLite_ParFormat('left')); $cell = $table->getCell($row++, 2); $cell->writeText("{$question['petition_theme']}", new PHPRtfLite_Font(12), new PHPRtfLite_ParFormat('left'));
$table->addRows(1); $cell = $table->getCell($row, 1); $cell->writeText("Текст петиції: ", new PHPRtfLite_Font(12), new PHPRtfLite_ParFormat('left')); $cell = $table->getCell($row++, 2); $cell->writeText("{$question['petition_text']}", new PHPRtfLite_Font(12), new PHPRtfLite_ParFormat('left'));
$rtf->sendRtf('Петиції - #'.$id); die;
} public static function PetitionAction($params) { if (!Users_Model::IsAdmin()) return; $operation = $params[0]; $id = (int)$params[1]; $text = $_POST['text']; if ($id > 0) { if ($operation == 'confirm') List_Model::ConfirmPetition($id); if ($operation == 'reject') self::DeleteAction(array($id), $text); } header("Location: /list/view/$id"); die; } public static function AnswerAction($params) { if (!Users_Model::IsAdmin()) return; if($_SERVER['REQUEST_METHOD'] == 'GET') { $row = List_Model::GetPetitionByIdForAdmin(intval($params[0])); echo json_encode($row); die; } if($_SERVER['REQUEST_METHOD'] == 'POST') { $petition_answer_text = $_POST['petition_answer_text']; $id = (int)$params[0]; $res = array(); if ($id > 0) { if ($_POST['publish'] === 'true') $status = 3; else $status = 2; List_Model::SetPetitionAnswer($petition_answer_text, $id, $status); $res['ok'] = true; $res['message'] = 'Текст петиції збережено'; echo json_encode($res); die; } else { $res['ok'] = false; $res['message'] = 'Помилка збереження петиції'; echo json_encode($res); die; } } } public static function EditAction($params) { if (!Users_Model::IsAdmin()) return; if($_SERVER['REQUEST_METHOD'] == 'GET') { $row = List_Model::GetPetitionByIdForAdmin(intval($params[0])); echo json_encode($row); die; } if($_SERVER['REQUEST_METHOD'] == 'POST') { $theme = $_POST['petition_theme']; $text = $_POST['petition_text']; $num = $_POST['petition_number']; $id = (int)$params[0]; $res = array(); if (strlen($theme) > 5 && strlen($text) > 5 && $id > 0) { List_Model::EditPetition($theme, $text, $num, $id); $res['ok'] = true; $res['message'] = 'Текст петиції збережено'; echo json_encode($res); die; } else { $res['ok'] = false; $res['message'] = 'Помилка збереження петиції'; echo json_encode($res); die; }} } public static function DeleteAction($params) { if (!Users_Model::IsAdmin()) return; if($_SERVER['REQUEST_METHOD'] == 'POST') { $id = (int)$params[0]; $text = $_POST['text']; $sendMail = $_POST['sendmail']; List_Model::SetDeleteStatusOfPetition($id, $text, $sendMail); $res['ok'] = true; $res['message'] = 'Петицію видалено'; echo json_encode($res); die; } } public static function RestoreAction($params) { if (!Users_Model::IsAdmin()) return; if($_SERVER['REQUEST_METHOD'] == 'POST') { $id = (int)$params[0]; List_Model::RestorePetition($id); $res['ok'] = true; $res['message'] = 'Петицію відновлено'; echo json_encode($res); die; } } public static function ViewAction($params) { switch(count($params)) { case 1: if (intval($params[0]) > 0) { if (Users_Model::IsAdmin()) $row = List_Model::GetPetitionByIdForAdmin(intval($params[0])); else $row = List_Model::GetPetitionById(intval($params[0])); if ($row['petition_status'] == 0 && !Users_Model::IsAdmin() || empty($row['petition_id'])) { Main_Controller::Error(404); return; } return array('Title' => $row['petition_theme'], 'Content' => List_View::PetitionView(intval($params[0]))); } break; default: return array( 'Title' => 'Список петицій', 'Content' => List_View::GetList()); } } public static function JsonListAction($params) { $sort = (int)$_POST['sort']; $start = (int)$_POST['start']; $count = (int)$_POST['count']; $status = (int)$_POST['status']; if ($start < 0) $start = 0; if ($count < 20) $count = 20; if (($status <= 0 || $status > 4) && !Users_Model::IsAdmin()) $status = 1; $res = array(); if (!isset($_POST['start'])) { $res['count'] = List_Model::GetPetitionsCount($status); $res['maxcount'] = Params_Model::VotesCount(10); } $res['rows'] = List_Model::GetPetitionsList($sort, $start, $count, $status); echo json_encode($res); die; } public static function SignAction($params) { $id = intval($params[0]); if (($id > 0) && Users_Model::IsAuthorized()) { $result = List_Model::SignPetition($id); if ($result['status']) { $res['ok'] = true; $res['error'] = $result['message']; echo json_encode($res); die; } else { $res['ok'] = false; $res['error'] = $result['message']; echo json_encode($res); die;
} } } public static function SearchAction() { } public static function IndexAction() { } }
|