Files
zurawik.pl/Admin/controller/CalcController.php
2026-05-15 18:33:51 +02:00

326 lines
11 KiB
PHP
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<?php
/**
* $Id$
* Słownki
*
*/
class CalcController extends MainController implements ControllerInterface {
const CONTENT_PER_PAGE = 50;
/**
* Domyślna metoda
*
*/
public function IndexAction($param) {
if (isset($param['type'])) {
SessionProxy::SetValue('typeCalc', $param['type']);
} else {
$param['type'] = 1;
}
SessionProxy::SetValue('typeCalc', $param['type']);
$dalData = MfParametersDAL::GetDalDataObj();
$dalData->addCondition('type', $param['type']);
$dalData->setSortBy('sort');
$arrayObjParameters = MfParametersDAL::GetResult($dalData);
//Utils::ArrayDisplay($arrayObjParameters);
//===grupowanie====
$arrayParam = array();
$arrayGroupParam = array();
foreach ($arrayObjParameters as $objParam) {
$idLink = $objParam->GetLinkId();
$arrayGroupParam[$objParam->GetLinkId()][] = $objParam;
}
$this->smarty->assign('arrayObj', $arrayObjParameters);
$this->smarty->assign('arrayGroupParam', $arrayGroupParam);
}
public function AddAction($param) {
$objParameters = new MfParameters();
$objParameters->setType(SessionProxy::GetValue('typeCalc'));
$this->smarty->assign('obj', $objParameters);
if (Request::GetPost('doCategoryEdit')) {
Utils::ArrayDisplay(Request::GetAllPost());
$out = array();
$validator = new Validator(Request::GetAllPost());
$data = Request::GetAllPost();
$validator->IsEmpty('name', 'Pole nazwa musi zostać wypełnione.');
$out = $validator->GetErrorList();
$publication = Request::Get('publication');
$publication ? $publication = 1 : $publication = '0';
$priceProgres = Request::Get('price_progres');
$priceProgres ? $priceProgres = 1 : $priceProgres = '0';
$objParameters->setPublication($publication);
$objParameters->setPrice($data['price']);
$objParameters->setLinkId($data['link_id']);
$objParameters->setName($data['name']);
$objParameters->setOpis($data['opis']);
$objParameters->setPriceProgres($priceProgres);
$objParameters->setCountProgres($data['count_progres']);
$objParameters->setUnit($data['unit']);
if (empty($out)) {
//Utils::ArrayDisplay($objParameters);
$idParameters = MfParametersDAL::Save($objParameters);
$this->AddRedirectInfo('Zapisano', 'ok', Router::GenerateUrl('editConfig', array('Calc' => 'Index', 'type' => $objParameters->getType())));
} else {
$this->smarty->assign('obj', $objParameters);
$this->smarty->assign('info', 'Pola obowiązkowe muszą zostać wypełnione.');
$this->smarty->assign('type', 'error');
foreach ($out as $item) {
$error[$item['field']] = $item['msg'];
}
$this->smarty->assign('error', $error);
}
}
}
public function EditAction($param) {
$objParameters = MfParametersDAL::GetById($param['id']);
$this->smarty->assign('obj', $objParameters);
if (Request::GetPost('doCategoryEdit')) {
Utils::ArrayDisplay(Request::GetAllPost());
$out = array();
$validator = new Validator(Request::GetAllPost());
$data = Request::GetAllPost();
$validator->IsEmpty('name', 'Pole nazwa musi zostać wypełnione.');
$out = $validator->GetErrorList();
$publication = Request::Get('publication');
$publication ? $publication = 1 : $publication = '0';
$priceProgres = Request::Get('price_progres');
$priceProgres ? $priceProgres = 1 : $priceProgres = '0';
$objParameters->setPublication($publication);
$objParameters->setPrice($data['price']);
$objParameters->setLinkId($data['link_id']);
$objParameters->setName($data['name']);
$objParameters->setOpis($data['opis']);
$objParameters->setCountProgres($data['count_progres']);
$objParameters->setPriceProgres($priceProgres);
$objParameters->setUnit($data['unit']);
if (empty($out)) {
//Utils::ArrayDisplay($objParameters);
$idParameters = MfParametersDAL::Save($objParameters);
$this->AddRedirectInfo('Zapisano', 'ok', Router::GenerateUrl('editConfig', array('Calc' => 'Index', 'type' => $objParameters->getType())));
} else {
$this->smarty->assign('obj', $objParameters);
$this->smarty->assign('info', 'Pola obowiązkowe muszą zostać wypełnione.');
$this->smarty->assign('type', 'error');
foreach ($out as $item) {
$error[$item['field']] = $item['msg'];
}
$this->smarty->assign('error', $error);
}
}
}
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);
}
public function GenerateModAction($param) {
MFLog::Info(__FUNCTION__);
//require_once('../core/lib/Smarty/Smarty.class.php');
//$smarty = new Smarty();
// $smarty->template_dir = Config::Get('PATH_SMARTY_TEMPLATE');
// $smarty->compile_dir = Config::Get('PATH_SMARTY_COMPILE');
$db = Registry::Get('db');
$sql = " select table_name from information_schema.tables where table_schema <> 'information_schema' ";
$stmt = $db->prepare($sql)
->execute($sql);
$tables = $stmt->FetchAllRow();
foreach ($tables as $table) {
$tableName = $table[0];
$className = ucfirst(Utils::SQLName2PHPName($tableName));
$this->smarty->assign('tableName', $tableName);
$this->smarty->assign('className', $className);
// zaleĹĽne obiekty/tabele dziaĹa dopiero od mySQL 5.1.16
// $sql = " select table_name from referential_constraints where constraint_schema <> 'information_schema' and referenced_table_name = '$tableName' ";
// $stmt = $db->prepare($sql)
// ->execute($sql);
//
// $refTableNames = array();
//
// $refTables = $stmt->FetchAllRow();
// foreach ($refTables as $refTable) {
// $tmp_name = Utils::SQLName2PHPName($refTable[0]);
// $refTables[$refTable[0]] = $tmp_name;
// }
//
// $smarty->assign('refTables', $refTables);
// kolumny tabeli dla obiektu
$sql = " select column_name from information_schema.columns where table_name='$tableName'; ";
$stmt = $db->prepare($sql)
->execute($sql);
$columnNames = array();
$columns = $stmt->FetchAllRow();
foreach ($columns as $column) {
if ($column[0] === 'id_' . $tableName) {
$tmp_name = 'id';
} else {
$tmp_name = Utils::SQLName2PHPName($column[0]);
}
$columnNames[$column[0]] = $tmp_name;
}
$this->smarty->assign('columnNames', $columnNames);
$output = '<?php' . $this->smarty->fetch('templateModel.tpl') . '?>';
$file = fopen(PATH_MODEL_TMP . $className . '.class.php', "w");
fwrite($file, $output);
fclose($file);
$outputDAL = '<?php' . $this->smarty->fetch('templateModelDAL.tpl') . '?>';
$file = fopen(PATH_MODEL_TMP . $className . 'DAL.class.php', "w");
fwrite($file, $outputDAL);
fclose($file);
}
}
public function GenOneModelAction($param) {
// kolumny tabeli dla obiektu
$tableName = 'fk_maps';
$db = Registry::Get('db');
$sql = " select column_name from information_schema.columns where table_name='$tableName'; ";
$stmt = $db->prepare($sql)
->execute($sql);
$className = ucfirst(Utils::SQLName2PHPName($tableName));
$this->smarty->assign('tableName', $tableName);
$this->smarty->assign('className', $className);
$columnNames = array();
$columns = $stmt->fetchAllAssoc();
//Utils::ArrayDisplay($columns);
//$columns = $stmt->FetchAllRow();
foreach ($columns as $column) {
//Utils::ArrayDisplay($column);
if ($column['COLUMN_NAME'] === 'id_mf_participant') {
$tmp_name = 'id';
} else {
$tmp_name = Utils::SQLName2PHPName($column['COLUMN_NAME']);
}
$columnNames[$column['COLUMN_NAME']] = $tmp_name;
}
//Utils::ArrayDisplay($this->smarty);
$this->smarty->assign('columnNames', $columnNames);
$output = '<?php' . $this->smarty->fetch('partial/Calc/templateModel.tpl') . '?>';
//Utils::ArrayDisplay($this->smarty);
$file = fopen(PATH_MODEL_TMP . $className . '.class.php', "w");
fwrite($file, $output);
fclose($file);
$outputDAL = '<?php' . $this->smarty->fetch('partial/Calc/templateModelDAL.tpl') . '?>';
$file = fopen(PATH_MODEL_TMP . $className . 'DAL.class.php', "w");
fwrite($file, $outputDAL);
fclose($file);
}
/**
* Metoda wspolna
*
*/
public function preDispatch($param) {
$this->RunShared('Auth', $param);
$this->Run($param);
$admin = AuthDAL::GetAdmin();
$this->user = $admin;
$this->smarty->assign('titleAdmin', 'Formularz');
$struct = array(
//'User' => array('User' => 'Index'),
'Parametry' => array('Calc' => 'Index', 'type' => 1),
//'Parametry mieszkanie' => array('Calc' => 'Index', 'type' => 2),
'Treści' => array('HomeSite' => 'EditArticle')
);
$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) {
}
}
?>