Files
zurawik.pl/Admin/controller/UtilsController.php
2026-05-15 20:23:25 +02:00

367 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
class UtilsController extends MainController implements ControllerInterface
{
public function IndexAction($param){
}
/*
* Sote DEcrypt User Data
*
*
*/
function TestDecryptAction($param) {
if (function_exists("mcrypt_module_open"))
{
Utils::ArrayDisplay('jest');
}
else
{
Utils::ArrayDisplay('nie ma');
}
$encrypted = "8rJL4bjQiv+qO2s2q3VVZwQuqfo=";
$shopLicence = "2021-0924-0001-5422-e032-c32f";
$key = md5($shopLicence);
$string = $encrypted;
Utils::ArrayDisplay("baza: ".$string);
$string = base64_decode($encrypted);
Utils::ArrayDisplay("base64_decode: ".$string);
/* Open module, and create IV */
$td = mcrypt_module_open('des', '', 'cfb', '');
Utils::ArrayDisplay($td);
$key = substr($key, 0, mcrypt_enc_get_key_size($td));
Utils::ArrayDisplay($key);
$iv_size = mcrypt_enc_get_iv_size($td);
$iv = substr($string, 0, $iv_size);
$string = substr($string, $iv_size);
Utils::ArrayDisplay("base64_decode: ".$string);
/* Initialize encryption handle */
if (mcrypt_generic_init($td, $key, $iv) != -1)
{
/* Encrypt data */
$c_t = @mdecrypt_generic($td, $string);
Utils::ArrayDisplay("Encrypt data: ".$c_t);
mcrypt_generic_deinit($td);
mcrypt_module_close($td);
Utils::ArrayDisplay($c_t);
}
}
/*
* Sote DEcrypt User Data
*
*
*/
function TestEncryptAction($param) {
if (function_exists("mcrypt_module_open"))
{
Utils::ArrayDisplay('jest');
}
else
{
Utils::ArrayDisplay('nie ma');
}
$toEncrypt = "Skrzyszów 97a";
$shopLicence = "2013-0419-0001-3329-52c4-440b";
$key = md5($shopLicence);
$string = $toEncrypt;
/* Open module, and create IV */
$td = mcrypt_module_open('des', '', 'cfb', '');
$key = substr($key, 0, mcrypt_enc_get_key_size($td));
$iv_size = mcrypt_enc_get_iv_size($td);
$iv = mcrypt_create_iv($iv_size, MCRYPT_DEV_URANDOM);
/* Initialize encryption handle */
if (mcrypt_generic_init($td, $key, $iv) != -1)
{
/* Encrypt data */
/**
* Hack for warning error message that $string is empty.
*/
if (empty($string))
$c_t = @mcrypt_generic($td, $string);
else
$c_t = mcrypt_generic($td, $string);
mcrypt_generic_deinit($td);
mcrypt_module_close($td);
$c_t = $iv . $c_t;
$decrypted = base64_encode($c_t);
Utils::ArrayDisplay($decrypted);
}
}
public function DecryptUserDataAction($param) {
$dalData = StUserDataDAL::GetDalDataObj();
$dalData->setCondition(array());
//$dalData->setLimit(10);
$arrayObj = StUserDataDAL::GetResult($dalData);
//Utils::ArrayDisplay($arrayObj);
$arrayObjDescrypted = array();
/*
* dekodowanie ze starej wersji
*
*
*/
foreach ($arrayObj as $obj) {
$obj->SetAddress(StUserData::Decrypt($obj->getAddress()));
$obj->SetaddressMore(StUserData::Decrypt($obj->getaddressMore()));
$obj->Setcode(StUserData::Decrypt($obj->getcode()));
$obj->Setcompany(StUserData::Decrypt($obj->getcompany()));
$obj->Setflat(StUserData::Decrypt($obj->getflat()));
$obj->Sethouse(StUserData::Decrypt($obj->gethouse()));
$obj->Setpesel(StUserData::Decrypt($obj->getpesel()));
$obj->Setphone(StUserData::Decrypt($obj->getphone()));
$obj->Setregion(StUserData::Decrypt($obj->getregion()));
$obj->Setstreet(StUserData::Decrypt($obj->getstreet()));
$obj->Settown(StUserData::Decrypt($obj->gettown()));
$arrayObjDescrypted[] = $obj;
}
/*
* Kodowaie do nowej wersji
*
*
*/
$arrayObjEncrypted = array();
foreach ($arrayObjDescrypted as $obj) {
// $obj->SetAddress(StUserData::Encrypt($obj->getAddress()));
// $obj->SetaddressMore(StUserData::Encrypt($obj->getaddressMore()));
// $obj->Setcode(StUserData::Encrypt($obj->getcode()));
// $obj->Setcompany(StUserData::Encrypt($obj->getcompany()));
// $obj->Setflat(StUserData::Encrypt($obj->getflat()));
// $obj->Sethouse(StUserData::Encrypt($obj->gethouse()));
// $obj->Setpesel(StUserData::Encrypt($obj->getpesel()));
// $obj->Setphone(StUserData::Encrypt($obj->getphone()));
// $obj->Setregion(StUserData::Encrypt($obj->getregion()));
// $obj->Setstreet(StUserData::Encrypt($obj->getstreet()));
// $obj->Settown(StUserData::Encrypt($obj->gettown()));
// $obj->setUpdatedAt(Utils::GetNowDate());
StUserDataDAL::Save($obj);
$arrayObjEncrypted[] = $obj;
}
Utils::ArrayDisplay($arrayObjDescrypted);
}
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 = 'st_user_data';
$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/Utils/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/Utils/templateModelDAL.tpl') . '?>';
//Utils::ArrayDisplay($outputDAL);
$file = fopen(PATH_MODEL_TMP . $className . 'DAL.class.php', "w");
fwrite($file, $outputDAL);
fclose($file);
}
public function UpdateFieldAction($param) {
$arrayTableField = array(
'mf_article_description' => array('description', 'shortnote'),
'mf_dictionary' => array('replacement'),
'mf_article_box' => array('description', 'shortnote'),
'st_webpage' => array('opt_other_link', 'opt_content'),
'st_webpage_i18n' => array('other_link', 'content')
);
$stringToReplace = 'https://aem.hean.pl';
$stringReplace = 'https://hean.pl';
foreach ($arrayTableField as $table => $arrayField) {
//$table = '';
foreach ($arrayField as $field) {
$sql = "UPDATE $table SET $field = REPLACE($field, '$stringToReplace', '$stringReplace') WHERE $field LIKE '%$stringToReplace%'";
Utils::ArrayDisplay($sql);
// $db = Registry::Get('db');
// $stmt = $db->prepare($sql)->execute($sql);
}
}
}
/**
* preDispatch
* @param array $param
* @return null
*/
public function preDispatch($param){
$this->Run($param);
$this->AddScript('dropDown.js');
$this->AddScript('structure.js');
$this->AddScript('Dosia.js');
$this->AddScript('Link.js');
$this->AddScript('drag-drop-folder-tree.js');
// //$this->AddScript('Validator.js');
$this->AddScript('calendar.js');
$this->RunShared('Auth', array());
$this->RunShared('Structure', $param);
$this->smarty->assign('idStucture', SessionProxy::GetValue('idStructure'));
$this->smarty->assign('lang', 'pl');
$this->smarty->assign('titleAdmin', 'Pliki');
$this->smarty->assign('activeTab', 'index');
}
/**
* postDispatch
* @param array $param
* @return null
*/
public function postDispatch($param){
}
}