Viewing file: module.php (10.32 KB) -rw-r--r-- Select action/file-type: (+) | (+) | (+) | Code (+) | Session (+) | (+) | SDB (+) | (+) | (+) | (+) | (+) | (+) |
<?
function PetitionsCustomFunc(&$row)
{
$r = "<a href=\"/admin-asynch.php?mod=Petitions&generate&petition_id={$row['petition_id']}\"><img src=\"/admin/images/print.png\" border=\"0\" /></a> ";
if ($row['petition_status'] > 0)
$r .= "<img src=\"/admin/images/on.png\" />";
else
$r .= "<img src=\"/admin/images/off.png\" />";
$row["custom"] = "<div style=\"white-space:nowrap;\">".$r."</div>";
}
class Petitions
{
var $UserMode = false;
var $AdminMode = false;
var $SearchMode = false;
var $PanelMode = false;
var $UserAsynchMode = false;
var $AdminAsynchMode = true;
var $PersonsTable;
var $QuestionsTable;
var $Directory;
var $ClassName = 'Petitions';
var $RowsByPage = 10;
function Petitions()
{
$this->Directory = dirname(__FILE__);
$this->PersonsTable = new AMTable2('users');
$this->PersonsTable->AddIndexField('user_id');
$this->PersonsTable->Module($this->ClassName);
$this->PersonsTable->AddPositionField("person_position");
$this->QuestionsTable = new AMTable2('petitions');
$this->QuestionsTable->Module($this->ClassName);
$this->QuestionsTable->AddIndexField('petition_id');
}
function UserAsynch()
{
}
function GetPersonsUserTable()
{
}
function User()
{
}
function Menu()
{
global $ALANG;
if (isset($_GET['mod']) && ($_GET['mod'] == $this->ClassName))
{
return array(
array('title' => 'Список усіх петицій', 'link' => '?mod='.$this->ClassName.'&questions&list'),
array('title' => 'Список нових петицій', 'link' => '?mod='.$this->ClassName.'&questions&new&list'),
);
} else
return "";
}
function Admin()
{
global $ALANG, $alang, $_LANG_ID;
$smarty = GetAdminSmarty($this->ClassName);
if (isset($_GET['questions']) && isset($_GET['new']))
{
$fields = array("petition_date", "petition_theme", "custom", "petition_text");
$captions = array("Дата надходження", "Тема", "", "Текст");
$conditions = array("(petition_user_id = user_id) AND (petition_status = 0)");
$order = "petition_date DESC";
$multiple = array("delete");
$links = array("checkbox", "delete", "edit");
$params = array("id" => "petitions", "tables" => array('users'), "function" => PetitionsCustomFunc);
$html = $this->QuestionsTable->GetAdminTable($fields, $captions, $conditions, $order, $links, $multiple, $params);
$result['Title'] = "Список петицій";
$result['Content'] = $html;
return $result;
}
if (isset($_GET['questions']) && isset($_GET['list']))
{
$fields = array("petition_date", "petition_theme", "custom", "petition_text");
$captions = array("Дата надходження", "Тема", "", "Текст");
$conditions = array("petition_user_id = user_id");
$order = "petition_date DESC";
$multiple = array("delete");
$links = array("checkbox", "delete", "edit");
$params = array("id" => "petitions", "tables" => array('users'), "function" => PetitionsCustomFunc);
$html = $this->QuestionsTable->GetAdminTable($fields, $captions, $conditions, $order, $links, $multiple, $params);
$result['Title'] = "Список петицій";
$result['Content'] = $html;
return $result;
}
if (isset($_GET['edit']) && isset($_GET['petition_id']))
{
if (isset($_POST['edit']))
{
$row = $this->QuestionsTable->GetRowById($_GET['petition_id']);
$this->QuestionsTable->Update($_POST, $_GET['petition_id']);
/*if ($_POST['petition_status'] == 1) {
$f = file_get_contents("http://petitions.zt-rada.gov.ua/list/FGDEFSA/{$_GET['petition_id']}");
}*/
header("Location: ?mod=".$this->ClassName."&questions&list");
die;
}
$row = $this->QuestionsTable->GetRowById($_GET['petition_id']);
$user = $this->PersonsTable->GetRowById($row['petition_user_id']);
foreach($row as $key => $value)
$smarty->assign($key, $value);
if (is_array($user))
foreach($user as $key => $value)
$smarty->assign($key, $value);
$smarty->assign('oper', 'edit');
$persons = $this->PersonsTable->GetRows();
$smarty->assign('persons', $persons);
$result['Title'] = $ALANG['QuestionsEdit'];
$result['Content'] = $smarty->fetch('question.tpl');
return $result;
}
if (isset($_GET['NewQuestionsList']))
{
$t = new AMAdminTable("SELECT AMCMS_persons.*, question_id, question_author_name, question_date, question_text, question_person_id, person_id, question_send_date,question_show FROM AMCMS_questions, AMCMS_persons WHERE (person_id = question_person_id) AND (question_show='N') ORDER BY question_date DESC", "question_id");
$r =
$t->AllowCheckBox();
$t->AllowAjaxDelete($this->ClassName, 'questionDelete');
$t->AllowEdit ('mod='.$this->ClassName.'&QuestionEdit&New');
$t->AddField('person_name_'.$DefaultAdminLanguage, $ALANG['question_person_Short']);
$t->AddField('question_date', $ALANG['question_date_Short'], true);
$t->AddField('question_author_name', $ALANG['question_author_Short']);
$t->AddCustomField(QuestionsCustomFunc);
$t->AddField('question_text', $ALANG['question_text_Short']);
$result['pagename'] = $ALANG['NewQuestionsList'];
$result['pagetitle'] = $ALANG['NewQuestionsList'];
$result['Content'] = $t->Fetch();
return $result;
}
}
function AdminAsynch()
{
global $ALANG, $alang;
if (isset($_GET['generate']) && isset($_GET['petition_id']))
{
$question = $this->QuestionsTable->GetRowById($_GET['petition_id']);
$person = $this->PersonsTable->GetRowById($question['petition_user_id']);
require "modules-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(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('Петиції - #'.$_GET['petition_id']);
die;
}
if (isset($_GET['question_id']) && isset($_POST['edit']))
{
$row = $this->QuestionsTable->GetRowById($_GET['question_id']);
$this->QuestionsTable->Update($_POST, $_GET['question_id']);
$res["status"] = "ok";
echo json_encode($res);
return;
}
if (isset($_GET['question_id']) && isset($_GET['send']))
{
$row = $this->QuestionsTable->GetRowById($_GET['question_id']);
$date = GetCurrentDateAndTime();
$headers = "Content-type: text/html; charset=utf-8 \r\n";
$headers .= "From: ".GetParam('answer_email_deliver_name')." <".GetParam('answer_email_deliver').">\r\n";
mail($row['question_author_email'], GetParam('answer_email_theme'), $row['question_answer'],$headers);
$sql = "UPDATE AMCMS_questions SET question_send_date = '$date' WHERE question_id = '{$_GET['question_id']}'";
mysql_query($sql);
$res["date"] = GetUsefulDate($date, true, true);
$res["status"] = "ok";
echo json_encode($res);
return;
}
$this->QuestionsTable->Run($_POST);
$this->PersonsTable->Run($_POST);
}
}
$Modules ['Petitions'] = new Petitions();
?>
|