180 lines
4.5 KiB
PHP
180 lines
4.5 KiB
PHP
<?php
|
|
/**
|
|
* $Id$
|
|
* Słownki
|
|
*
|
|
*/
|
|
class DictionaryController extends MainController implements ControllerInterface {
|
|
|
|
|
|
|
|
const CONTENT_PER_PAGE = 50;
|
|
|
|
/**
|
|
* Domyślna metoda
|
|
*
|
|
*/
|
|
public function IndexAction($param) {
|
|
|
|
//Utils::ArrayDisplay($param);
|
|
//$dalData->setCount(true);
|
|
if (isset($param['location'])) {
|
|
$location = 1;
|
|
} else {
|
|
$location = 0;
|
|
}
|
|
|
|
|
|
$limit = Utils::PageConfigure($this->smarty, $param, ceil( MfDictionaryDAL::GetResult(array('lang' => "'pl'", 'location' => $location), array(), null, null, true)), self::CONTENT_PER_PAGE);
|
|
|
|
$arrayObjDict = MfDictionaryDAL::GetResult(array('lang' => "'pl'", 'location' => $location), array(), $limit, 'mf_dictionary.keyword ASC');
|
|
|
|
//Utils::ArrayDisplay($arrayObjDict);
|
|
$this->smarty->assign('arrayObjDict', $arrayObjDict);
|
|
}
|
|
|
|
public function AjaxIndexAction($param) {
|
|
$this->SetAjaxRender();
|
|
$where = '';
|
|
if (isset($param['location'])) {
|
|
$location = 1;
|
|
} else {
|
|
$location = 0;
|
|
}
|
|
|
|
$search= trim(Request::GetPost('search'));
|
|
$arraySearch = explode(' ', $search);
|
|
if (count($arraySearch) > 0) {
|
|
$where = ' ( ';
|
|
foreach ($arraySearch as $key => $search) {
|
|
$where .= $key == 0 ? '' : ' OR ';
|
|
$where .= ' mf_dictionary.keyword LIKE "%'.addslashes($search).'%" ';
|
|
}
|
|
$where .= ' ) ';
|
|
}
|
|
|
|
$limit = Utils::PageConfigure($this->smarty, $param, ceil( MfDictionaryDAL::GetResult(array('lang' => "'pl'", 'location' => $location, '' => array('condition' => '', 'value' => $where)), array(), null, null, true)), 600);
|
|
|
|
$arrayObjDict = MfDictionaryDAL::GetResult(array('lang' => "'pl'", 'location' => $location, ' ' => array('condition' => '', 'value' => $where)), array(), $limit, 'mf_dictionary.keyword ASC');
|
|
|
|
//Utils::ArrayDisplay($arrayObjDict);
|
|
$this->smarty->assign('arrayObjDict', $arrayObjDict);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function EditAction($param) {
|
|
|
|
if (isset($param['id'])) {
|
|
|
|
|
|
$arrayObjDict = MfDictionaryDAL::GetResult(array('id_mf_dictionary' => $param['id']), array(), 1, 'mf_dictionary.keyword ASC');
|
|
if (!(count($arrayObjDict) > 0)) {
|
|
$this->AddRedirect(Router::GenerateUrl('DictLabel', array("Dictionary" => 'Index')));
|
|
}
|
|
|
|
|
|
|
|
if (Request::GetPost('doDictEdit')) {
|
|
$post = Request::GetAllPost(false);
|
|
//Utils::ArrayDisplay($post);
|
|
|
|
foreach ($post['replacement'] as $langDict => $replacement) {
|
|
|
|
|
|
|
|
$arrayObjDict = MfDictionaryDAL::GetResult(array('keyword' => "'".$post['keyword']."'", 'lang' => "'".$langDict."'"), array(), 1, 'mf_dictionary.keyword ASC');
|
|
//Utils::ArrayDisplay($arrayObjDict);
|
|
if (key_exists(0, $arrayObjDict)) {
|
|
$objDict = $arrayObjDict[0];
|
|
$objDict->SetReplacement($replacement);
|
|
MfDictionaryDAL::Save($objDict);
|
|
}
|
|
}
|
|
|
|
|
|
$this->AddRedirect(Router::GenerateUrl('DictLabel', array("Dictionary" => 'Index')), 0);
|
|
|
|
}
|
|
|
|
$arrayObjDict = MfDictionaryDAL::GetResult(array('id_mf_dictionary' => $param['id']), array(), 1, 'mf_dictionary.keyword ASC');
|
|
if (!(count($arrayObjDict) > 0)) {
|
|
$this->AddRedirect(Router::GenerateUrl('DictLabel', array("Dictionary" => 'Index')), 0);
|
|
}
|
|
|
|
|
|
$this->smarty->assign('objDict', $arrayObjDict[0]);
|
|
} else {
|
|
$this->AddRedirect(Router::GenerateUrl('DictLabel', array("Dictionary" => 'Index')), 0);
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
public function DeleteAction($param) {
|
|
|
|
|
|
$arrayObjDict = MfDictionaryDAL::GetResult(array('id_mf_dictionary' => $param['id']), array(), 1, 'mf_dictionary.keyword ASC');
|
|
if (count($arrayObjDict) > 0) {
|
|
MfDictionaryDAL::DeleteByKey($arrayObjDict[0]->GetKeyword());
|
|
|
|
}
|
|
|
|
|
|
|
|
$this->AddRedirect(Router::GenerateUrl('DictLabel', array("Dictionary" => 'Index')), 0);
|
|
}
|
|
|
|
/**
|
|
* Metoda wspolna
|
|
*
|
|
*/
|
|
public function preDispatch($param) {
|
|
|
|
$this->RunShared('Auth', $param);
|
|
$this->Run($param);
|
|
$admin = AuthDAL::GetAdmin();
|
|
$this->user = $admin;
|
|
|
|
$this->smarty->assign('titleAdmin', 'Administracja');
|
|
$panelMenu = ARRAY_PANEL_MENU;
|
|
$struct = $panelMenu['layout'];
|
|
|
|
$this->smarty->assign('structure',$this->renderStruct($struct));
|
|
|
|
}
|
|
|
|
private function renderStruct($struct){
|
|
$return = '';
|
|
|
|
foreach($struct AS $k => $row){
|
|
$return .= '<li><a href="' . Router::GenerateUrl('dictpig',$row).'">'.$k.'</a></li>';
|
|
}
|
|
|
|
$html = '<ul>';
|
|
$html .= $return;
|
|
$html .= '</ul>';
|
|
|
|
|
|
return $html;
|
|
}
|
|
|
|
/**
|
|
*
|
|
*
|
|
*/
|
|
public function postDispatch($param) {
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
?>
|