app = $app;
if($intern) {
return;
}
$this->deactivatesModules[$this->app->Conf->WFdbname] = null;
$this->nodeactivateable = [
'appstore',
'firmendaten',
'artikel',
'auftrag',
'lieferschein',
'systemlog',
'dsgvo',
'dataprotection',
'pdfarchiv',
'orderstatus',
'welcome',
'ajax',
];
$this->app->ActionHandlerInit($this);
$this->app->ActionHandler('list', 'AppstoreList');
$this->app->ActionHandler('testmodule', 'AppStoreTestModule');
$this->app->ActionHandler('activate', 'AppstoreActivate');
$this->app->ActionHandler('deactivate', 'AppstoreDeactivate');
$this->app->ActionHandler('testen', 'AppstoreTesten');
$this->app->DefaultActionHandler('list');
$this->app->ActionHandlerListen($app);
}
public function AppStoreTestModule(): void
{
//for user-rights do not remove
}
public function addFav(): void
{
$apps = $this->getAppsList();
$module = $this->app->Secure->GetGET('module');
$id = $this->app->Secure->GetGET('id');
$module2 = $this->getSubModule($id, $module);
$favModuleName = $module;
if(!empty($apps['installiert'])) {
foreach($apps['installiert'] as $app) {
if(!empty($module2) && $app['key'] === $module2) {
$favModuleName = $app['Bezeichnung'];
break;
}
if($app['key'] === $module) {
$favModuleName = $app['Bezeichnung'];
break;
}
}
}
$this->app->Tpl->Set('FAVMODULENAME', $favModuleName);
$this->app->Tpl->Parse('BODYENDE','addfav.tpl');
}
/**
* @param int $id
* @param string $module
*
* @return string
*/
public function getSubModule($id, $module): string
{
$module2 = '';
if($id > 0) {
switch($module) {
case 'onlineshops':
$module2 = (String)$this->app->DB->Select(
sprintf(
'SELECT `modulename` FROM `shopexport` WHERE `id` = %d LIMIT 1',
$id
)
);
break;
case 'uebertragungen':
$module2 = (String)$this->app->DB->Select(
sprintf(
'SELECT `xml_pdf` FROM `uebertragungen_account` WHERE `id` = %d LIMIT 1',
$id
)
);
if(strpos($module2,'Transfer') !== 0) {
$module2 = '';
}
break;
case 'versandarten':
$module2 = (String)$this->app->DB->Select(
sprintf(
'SELECT `modul` FROM `versandarten` WHERE `id` = %d LIMIT 1',
$id
)
);
if(!empty($module2)) {
$module2 = 'versandarten_'.$module2;
}
break;
case 'zahlungsweisen':
$module2 = (String)$this->app->DB->Select(
sprintf(
'SELECT `modul` FROM `zahlungsweisen` WHERE `id` = %d LIMIT 1',
$id
)
);
if(!empty($module2)) {
$module2 = 'zahlungsweise_'.$module2;
}
break;
case 'drucker':
$module2 = (String)$this->app->DB->Select(
sprintf(
'SELECT `anbindung` FROM `drucker` WHERE `id` = %d LIMIT 1',
$id
)
);
if(strpos($module2,'Printer') !== 0) {
$module2 = '';
}
break;
case 'konten':
$module2 = (String)$this->app->DB->Select(
sprintf(
'SELECT `type` FROM `konten` WHERE `id` = %d LIMIT 1',
$id
)
);
if(!empty($module2)) {
$module2 = 'konto_'.$module2;
}
break;
}
}
return $module2;
}
/**
* @param bool $parameter
*
* @return null|string
*/
protected function sendBeta($parameter): ?string
{
$setBeta = $parameter;
$ok = null;
include_once dirname(__DIR__, 2).'/upgradesystemclient2_includekey.php';
return $ok;
}
/**
* @param array $parameter
*
* @return null|string
*/
protected function sendBuyFromDemo($parameter): ?string
{
$buyFromDemo = $parameter;
$ok = null;
include_once dirname(__DIR__, 2).'/upgradesystemclient2_includekey.php';
return $ok;
}
/**
* @param array $parameter
*
* @return null|string
*/
protected function sendBuy($parameter): ?string
{
$buy = $parameter;
$ok = null;
include_once dirname(__DIR__, 2).'/upgradesystemclient2_includekey.php';
$this->resetBuyListCache();
return $ok;
}
/**
* @return null|string
*/
protected function sendGetBuyList(): ?string
{
$getBuyList = true;
$ok = null;
include_once dirname(__DIR__, 2).'/upgradesystemclient2_includekey.php';
$this->SetKonfigurationValue('appstore_buy_lasttime', (new DateTime())->format('Y-m-d H:i:s'));
$this->SetKonfigurationValue('appstore_buy_list', $ok);
return $ok;
}
/**
* @return null|string
*/
protected function sendGetBuyInfo(): ?string
{
$getBuyInfo = true;
$ok = null;
include_once dirname(__DIR__, 2).'/upgradesystemclient2_includekey.php';
return $ok;
}
/**
* @return JsonResponse
*/
protected function HandleGetBuyInfoAjaxAction(): JsonResponse
{
$data = $this->getActualBuyInfo();
if(is_string($data)) {
$json = @json_decode($data, true);
if(!empty($json)) {
$data = $json;
}
}
$html = '';
if(!empty($data['summedAbos']['modul'])) {
$html = '
Anfrage erfolgreich ausgeführt. Sie können in etwa 15 Minuten ein Update herunterladen
'
);
return new JsonResponse(['status' => true, 'url' => 'index.php?module=appstore&action=buy&msg='.$msg]);
}
return new JsonResponse(['status' => false, 'error' => $data]);
}
/**
* @param string $module
*/
protected function addModuleForUpdateInfo($module): void
{
$modules = $this->getModulesForUpdateInfo();
if(in_array($module, $modules)) {
return;
}
$modules[] = $module;
$this->SetKonfigurationValue(
'appstore_modules_for_update_info',
json_encode($modules)
);
}
/**
* @param string $module
*/
protected function removeModuleForUpdateInfo($module): void
{
$modules = $this->getModulesForUpdateInfo(false);
if(!in_array($module, $modules)) {
return;
}
$modules = array_diff($modules, [$module]);
$this->SetKonfigurationValue(
'appstore_modules_for_update_info',
json_encode($modules)
);
}
/**
* @var bool $removeIfModuleExists
*
* @return array
*/
protected function getModulesForUpdateInfo($removeIfModuleExists = true): array
{
$modules = $this->GetBuyKonfigurationWithResetOnError('appstore_modules_for_update_info');
if(empty($modules)) {
return [];
}
$modules = json_decode($modules, true);
if(empty($modules) || !is_array($modules)) {
return [];
}
if(!$removeIfModuleExists) {
return $modules;
}
foreach($modules as $key => $module) {
if($this->app->erp->ModulVorhanden($module, true)) {
$this->removeModuleForUpdateInfo($module);
unset($modules[$key]);
}
}
return $modules;
}
public function resetBuyListCache(): void
{
$this->buyList = null;
$this->SetKonfigurationValue('appstore_buy_lasttime', '');
}
public function resetBuyInfoCache(): void
{
$this->buyInfo = null;
$this->SetKonfigurationValue('appstore_buyinfo_lasttime', '');
}
/**
* @param string $key
* @param mixed $value
*/
public function SetKonfigurationValue(string $key, $value): void
{
if(strpos($key, 'appstore_') === 0) {
$key = substr($key, 9);
}
try {
/** @var SystemConfigModule $systemConfigModule */
$systemConfigModule = $this->app->Container->get('SystemConfigModule');
$systemConfigModule->setValue('appstore', $key, (string)$value);
}
catch(Exception $e) {
}
}
/**
* @param string $key
*
* @return string|null
*/
public function GetKonfiguration(string $key): ?string
{
if(strpos($key, 'appstore_') === 0) {
$key = substr($key, 9);
}
/** @var SystemConfigModule $systemConfigModule */
$systemConfigModule = $this->app->Container->get('SystemConfigModule');
return $systemConfigModule->tryGetValue('appstore', $key);
}
/**
* @return mixed|string|null
*/
public function getActualBuyInfo()
{
if($this->buyInfo !== null) {
return $this->buyInfo;
}
$lastBuyInfo = $this->GetBuyKonfigurationWithResetOnError('appstore_buyinfo_lasttime');
try{
if(!empty($lastBuyInfo)) {
$lastBuyInfo = new DateTime($lastBuyInfo);
if($lastBuyInfo > new DateTime('-1 hour')) {
$lastBuyInfo = null;
}
else {
$lastBuyInfo = (new DateTime())->format('Y-m-d H:i:s');
}
}
else {
$lastBuyInfo = (new DateTime())->format('Y-m-d H:i:s');
}
}
catch (Exception $e) {
$lastBuyInfo = (new DateTime())->format('Y-m-d H:i:s');
}
$buyInfo = $this->GetBuyKonfigurationWithResetOnError('appstore_buyinfo_list');
$buyInfoDecoded = !empty($buyInfo) ? json_decode($buyInfo, true) : [];
$buyInfoCustomerBuy = $this->GetBuyKonfigurationWithResetOnError('appstore_buyinfo_customer_buy');
$buyInfoCustomerBuy = empty($buyInfoCustomerBuy) ? []: json_decode($buyInfoCustomerBuy, true);
$moduleMapping = $this->GetBuyKonfigurationWithResetOnError('appstore_buyinfo_module_mapping');
$moduleMapping = empty($moduleMapping) ? []: json_decode($moduleMapping, true);
$buyInfoDecoded['customer_buy'] = $buyInfoCustomerBuy;
$buyInfoDecoded['module_mapping'] = $moduleMapping;
$buyInfo = json_encode($buyInfoDecoded);
if(!empty($lastBuyInfo)) {
$buyInfo = $this->sendGetBuyInfo();
$buyInfoDecoded = json_decode($buyInfo, true);
$buyInfoCustomerBuy = null;
$moduleMapping = null;
if(isset($buyInfoDecoded['customer_buy'])){
$buyInfoCustomerBuy = $buyInfoDecoded['customer_buy'];
unset($buyInfoDecoded['customer_buy']);
}
if(isset($buyInfoDecoded['module_mapping'])){
$moduleMapping = $buyInfoDecoded['module_mapping'];
unset($buyInfoDecoded['module_mapping']);
}
$buyInfoCustomerBuy = json_encode($buyInfoCustomerBuy);
$moduleMapping = json_encode($moduleMapping);
$buyInfoPart = json_encode($buyInfoDecoded);
$this->SetKonfigurationValue(
'appstore_buyinfo_lasttime', $lastBuyInfo
);
$this->SetKonfigurationValue(
'appstore_buyinfo_list', $buyInfoPart
);
$this->SetKonfigurationValue(
'appstore_buyinfo_customer_buy', $buyInfoCustomerBuy
);
$this->SetKonfigurationValue(
'appstore_buyinfo_module_mapping', $moduleMapping
);
}
if(is_string($buyInfo)){
$json = json_decode($buyInfo, true);
if(!empty($json)) {
$buyInfo = $json;
}
}
if(!is_array($buyInfo)) {
$this->buyList = $buyInfo;
return $buyInfo;
}
$this->buyList = $buyInfo;
return $buyInfo;
}
/**
* @param string $key
*
* @return string
*/
public function GetBuyKonfigurationWithResetOnError(string $key): string
{
$value = (string)$this->GetKonfiguration($key);
if(strpos($value, 'ERROR') === 0) {
$this->SetKonfigurationValue($key, '');
return '';
}
return $value;
}
/**
* @return mixed|string|null
*/
public function getActualBuyList()
{
if($this->buyList !== null) {
return $this->buyList;
}
$lastBuyList = $this->GetBuyKonfigurationWithResetOnError('appstore_buy_lasttime');
try{
if(!empty($lastBuyList)) {
$lastBuyList = new DateTime($lastBuyList);
if($lastBuyList > new DateTime('-1 hour')) {
$lastBuyList = null;
}
else {
$lastBuyList = (new DateTime())->format('Y-m-d H:i:s');
}
}
else {
$lastBuyList = (new DateTime())->format('Y-m-d H:i:s');
}
}
catch (Exception $e) {
$lastBuyList = (new DateTime())->format('Y-m-d H:i:s');
}
$buyList = $this->GetBuyKonfigurationWithResetOnError('appstore_buy_list');
if(!empty($lastBuyList)) {
$buyList = $this->sendGetBuyList();
$this->SetKonfigurationValue('appstore_buy_lasttime', $lastBuyList);
$this->SetKonfigurationValue('appstore_buy_list', $buyList);
}
if(is_string($buyList)){
$json = json_decode($buyList, true);
if(!empty($json)) {
$buyList = $json;
}
}
if(!is_array($buyList)) {
$this->buyList = $buyList;
return $buyList;
}
$ret = [
'user' => [],
'lightuser' => [],
'modules' => [],
'modulearticle' => [],
'cloud' => [],
];
foreach($buyList as $buyItem) {
if($buyItem['typ'] === 'version') {
$ret['user'] = $buyItem;
continue;
}
if($buyItem['typ'] === 'lightuser') {
$ret['lightuser'] = $buyItem;
continue;
}
if($buyItem['typ'] === 'cloud') {
$ret['cloud'] = $buyItem;
continue;
}
$ret['modulearticle'][] = $buyItem;
$modules = explode(',', $buyItem['parameter']);
foreach($modules as $module) {
$module = trim($module);
if(empty($module) || in_array($module, $ret['modules'])) {
continue;
}
$ret['modules'][] = $module;
}
}
$this->buyList = $ret;
return $ret;
}
/**
* @param string $type
* @param int $count
*
* @return array
*/
private function isPossibleToChangeUser($type, $count)
{
$oldUser = (int)erpAPI::Ioncube_Property('maxuser');
$oldLightUser = (int)erpAPI::Ioncube_Property('maxlightuser');
$maxUser = $oldUser;
$maxLightUser = $oldLightUser;
if($type === 'user') {
$maxUser = $count;
}
elseif($type === 'lightuser') {
$maxLightUser = $count;
}
$maxTimeUser = $this->app->erp->ModulVorhanden('mitarbeiterzeiterfassung') ? $maxUser : 0;
$countActiveLightUser = 0;
if($maxLightUser > 0) {
$countActiveLightUser = (int)$this->app->DB->Select(
"SELECT COUNT(DISTINCT u.id) FROM `user` AS `u` WHERE u.activ = 1 AND u.type = 'lightuser'"
);
$countActiveStandardUser = (int)$this->app->DB->Select(
"SELECT COUNT(u.id) FROM `user` AS `u` WHERE u.activ = 1 AND u.hwtoken IS NOT NULL AND u.hwtoken <> 4"
) - $countActiveLightUser;
$countActiveTimeAccountUser = (int)$this->app->DB->Select(
"SELECT COUNT(*) FROM `user` AS `u` WHERE u.activ = 1 AND u.hwtoken = 4 AND u.type != 'lightuser'"
);
}
else{
$countActiveStandardUser = (int)$this->app->DB->Select(
"SELECT COUNT(*) FROM `user` AS `u` WHERE u.activ = 1 AND u.hwtoken <> 4"
);
$countActiveTimeAccountUser = (int)$this->app->DB->Select(
"SELECT COUNT(*) FROM `user` AS `u` WHERE u.activ = 1 AND u.hwtoken = 4"
);
}
$isStandardUserOK = $countActiveStandardUser <= $maxUser;
$isLightUserOK = $countActiveStandardUser + $countActiveTimeAccountUser + $countActiveLightUser
<= $maxTimeUser + $maxUser + $maxLightUser;
$isTimeUserOk = ($countActiveStandardUser + $countActiveTimeAccountUser)
<= $maxTimeUser + $maxUser;
if($isLightUserOK && $isStandardUserOK && $isTimeUserOk) {
return ['status' => true];
}
if($type === 'user') {
$minStandard = $countActiveStandardUser;
if($maxTimeUser > 0) {
$minStandard2 = (int)ceil(($countActiveStandardUser
+ $countActiveTimeAccountUser
+ $countActiveLightUser
- $maxLightUser)/ 2);
$minStandard3 = (int)ceil(($countActiveStandardUser + $countActiveTimeAccountUser) / 2);
}
else {
$minStandard2 = $countActiveStandardUser
+ $countActiveTimeAccountUser
+ $countActiveLightUser
- $maxLightUser;
$minStandard3 = $countActiveStandardUser + $countActiveTimeAccountUser;
}
if($minStandard2 > $minStandard) {
$minStandard = $minStandard2;
}
if($minStandard3 > $minStandard) {
$minStandard = $minStandard3;
}
if($minStandard > $maxUser) {
if($minStandard >= $oldUser) {
return [
'status' => false,
'error' => sprintf(
'Es sind %d Benutzer aktiv, Sie können keine Benutzer kündigen.
Deaktivieren Sie nicht benötigte Accounts.',
$countActiveLightUser + $countActiveTimeAccountUser + $countActiveStandardUser
)
];
}
return [
'status' => false,
'error' => sprintf(
'Es sind %d Benutzer aktiv, sie können die Benutzerzahl auf %d reduzieren oder
nicht benötigte Accounts deaktivieren.',
$countActiveLightUser + $countActiveTimeAccountUser + $countActiveStandardUser,
$minStandard
)
];
}
}
elseif($type === 'lightuser') {
$minLight = $countActiveLightUser + $countActiveTimeAccountUser + $countActiveStandardUser
- $maxUser - $maxTimeUser;
if($minLight > $maxLightUser) {
if($minLight >= $oldLightUser) {
return [
'status' => false,
'error' => sprintf(
'Es sind %d Light-User aktiv. Deaktivieren Sie nicht benötigte Accounts um fortzusetzen.',
$countActiveLightUser
)
];
}
return [
'status' => false,
'error' => sprintf(
'Es sind %d Light-User aktiv, sie können die Benutzerzahl auf %d reduzieren oder
nicht benötigte Accounts deaktivieren.',
$countActiveLightUser,
$minLight
)
];
}
}
return [
'status' => false,
'error' => sprintf(
'Es sind %d Benutzer aktiv',
$countActiveLightUser + $countActiveTimeAccountUser + $countActiveStandardUser
)
];
}
/**
* @param string $key
*
* @return array|null
*/
public function getBuyModuleFromModuleKey($key)
{
$buyList = $this->getActualBuyList();
if(empty($buyList['modulearticle'])) {
return null;
}
foreach($buyList['modulearticle'] as $mod) {
if($mod['parameter'] === $key) {
return $mod;
}
}
return null;
}
/**
* @param string $price
*
* @return string
*/
public function formatBuyPrice($price)
{
if(empty($price)) {
return $price;
}
if(substr($price, -3) === '.00') {
return substr($price, 0, -3);
}
return $price;
}
public function AppstoreBuy()
{
$this->app->Location->execute('index.php?module&appstore&action=list');
}
/**
* @return string[]
*/
protected static function getHubspotEvents()
{
return [
'RENTBUTTONHUBSPOTEVENT' => 'buyClick1',
'RENTPOPUPHUBSPOTEVENT' => 'buyClick2',
'RENTPOPUPOKHUBSPOTEVENT' => 'buyOk',
'RENTPOPUPABORTHUBSPOTEVENT' => 'buyAbort',
'RENTPOPUPERRORHUBSPOTEVENT' => 'buyError',
'RENTPOPUPINITHUBSPOTEVENT' => 'buyInit',
];
}
protected function showUpdateMessage(): void
{
if(!$this->canBuy()) {
return;
}
if($this->app->User->GetType() !== 'admin') {
return;
}
$moduleForInfos = $this->getModulesForUpdateInfo();
if(empty($moduleForInfos)) {
return;
}
$this->app->Tpl->Set(
'MESSAGE',
'Das Modul wurde zum Testen angefragt. Bitte ziehen Sie sich über den Update-Prozess in ca 10 Minuten ein Update. Sie erhalten mit diesem das Modul zum Testen.
';
if(!$json) {
$this->app->Tpl->Add('MESSAGE', $message);
}
}
else{
$message = ''."\n");
if($modullist && !empty($modullist['installiert'])) {
foreach($modullist['installiert'] as $modul) {
if(isset($modul['key']) && strpos($modul['key'], $prefix) === 0) {
$kategorie = (!empty($modul['kategorie'])) ? $modul['kategorie'] : '{|Allgemein|}';
$iconTag = $this->GetAppIconTagByCategory($kategorie);
$link = '#';
$this->app->Tpl->Add(
'MODULEINSTALLIERT',
'
'
);
$this->app->Tpl->Add(
'MODULEINSTALLIERT',
''
);
$this->app->Tpl->Add(
'MODULEINSTALLIERT',
' '.$modul['Bezeichnung'] .'
'
.(!empty($modul['beta'])?' Beta':'')
.(!empty($modul['legacy'])?' Legacy':'')
.(!empty($modul['special'])?' Special':'')
.(!empty($modul['test'])?' (Testversion Ablauf am '.$this->app->String->Convert($modul['ablaufdatum'], "%1-%2-%3", "%3.%2.%1").')':'').'
'
);
$this->app->Tpl->Add(
'MODULEINSTALLIERT',
''."\n"
);
}
}
}
}
public function Install(): void
{
$this->app->erp->CheckTable('module_status');
$this->app->erp->CheckColumn('module', 'VARCHAR(64)','module_status',"DEFAULT '' NOT NULL");
$this->app->erp->CheckColumn('active', 'TINYINT(1)','module_status','DEFAULT 0 NOT NULL');
$this->app->erp->RegisterHook('supersearch_detail', 'appstore', 'AppstoreSupersearchDetail');
$this->app->erp->RegisterHook('HeadLines', 'appstore', 'AppstoreHeadLines');
}
/**
* @param string $headline
* @param string $headline1
* @param string|array $headline2
*/
public function AppstoreHeadLines($headline, $headline1, $headline2): void
{
if((empty($headline)) && empty($headline1)) {
return;
}
if(stripos($headline, 'BETA') !== false || stripos($headline1, 'BETA') !== false ||
stripos($headline, 'LEGACY') !== false || stripos($headline1, 'LEGACY') !== false ||
stripos($headline, 'SPECIAL') !== false || stripos($headline1, 'SPECIAL') !== false ||
stripos($headline, 'PROJEKT') !== false || stripos($headline1, 'PROJEKT') !== false) {
return;
}
if(!empty($headline2) && is_string($headline2) && (stripos($headline2, 'BETA') !== false &&
stripos($headline2, 'LEGACY') !== false && stripos($headline2, 'SPECIAL') !== false) &&
stripos($headline2, 'PROJEKT') !== false) {
return;
}
if(!empty($headline2) && is_array($headline2) && (stripos(implode(' ',$headline2), 'BETA') !== false &&
stripos(implode(' ',$headline2), 'LEGACY') !== false && stripos(implode(' ', $headline2), 'SPECIAL') !== false &&
stripos(implode(' ',$headline2), 'PROJEKT') !== false)) {
return;
}
if(empty($this->app->Secure)) {
return;
}
$module = $this->app->Secure->GetGET('module');
if(empty($module)) {
return;
}
if(in_array($module,['onlineshops','shopexport','uebertragungen','versandarten','zahlungsweisen'])) {
return;
}
if(!$this->isBeta($module) && !$this->isLegacy($module) && !$this->isSpecial($module) && !$this->isProjectSensitive($module)) {
return;
}
if(!empty($headline)) {
if($this->isBeta($module)){
$this->app->erp->Headlines($headline.'
Beta');
return;
}
if($this->isLegacy($module)){
$this->app->erp->Headlines($headline.'
Legacy');
return;
}
if($this->isSpecial($module)){
$this->app->erp->Headlines($headline.'
Special');
return;
}
if($this->isProjectSensitive($module)){
//$this->app->erp->Headlines($headline.'
Projekt');
return;
}
}
if(!empty($headline1)) {
if($this->isBeta($module)){
$this->app->erp->Headlines('', $headline1.'
Beta');
return;
}
if($this->isLegacy($module)){
$this->app->erp->Headlines('', $headline1.'
Legacy');
return;
}
if($this->isSpecial($module)){
$this->app->erp->Headlines('', $headline1.'
Special');
return;
}
if($this->isProjectSensitive($module)){
//$this->app->erp->Headlines('', $headline1.'
Projekt');
return;
}
}
}
/**
* @param \Xentral\Widgets\SuperSearch\Query\DetailQuery $detailQuery
* @param \Xentral\Widgets\SuperSearch\Result\ResultDetail $detailResult
*
* @return void
*/
public function AppstoreSupersearchDetail($detailQuery, $detailResult): void
{
if ($detailQuery->getGroupKey() !== 'apps') {
return;
}
$modules = $this->BuildModuleList();
$moduleKey = $detailQuery->getItemIdentifier();
// Wiki-Inhalte aufbereiten
/** @var Wiki $wiki */
$wiki = $this->app->erp->LoadModul('wiki');
$workspace = $wiki->getWorkspaceByName('XentralHandbuch');
$workspaceId = !empty($workspace)? (int)$workspace['id'] : 0;
$wikiArticle = $wiki->getArticleByName($moduleKey, $workspaceId);
list($wikiMenuArray, $wikiArticleContent) = $wiki->parseMenuFromHtml($wikiArticle['content'], 3, 'supersearch');
$wikiMenuHtml = '
Inhaltsverzeichnis
' . $wiki->drawMenuFromArray($wikiMenuArray, 'supersearch');
$wikiContent = $wikiMenuHtml . $wikiArticleContent;
$wikiLink = !empty($wikiArticle) ? sprintf('index.php?module=wiki&action=list&workspace=%s&cmd=%s', $workspaceId, $moduleKey) : null;
// ENDE Wiki-Inhalte aufbereiten
$moduleData = isset($modules[$moduleKey]) ? $modules[$moduleKey] : false;
if (is_array($moduleData) && $moduleData['key'] === $moduleKey) {
if($this->app->erp->ModulVorhanden($moduleData['key'])){
if (!empty($moduleData['module_link'])) {
$detailResult->addButton('Zum Modul', $moduleData['module_link']);
}
}else{
$detailResult->addButton('Zum Modul', 'index.php?module=appstore&action=list&cmd=detail&app='.$moduleData['key']);
}
// Einstellungs-Button deaktivieren, falls Action-Liste leer
// Grund: Modul wurde dann noch nie aufgerufen und erpApi::RechteVorhanden() würde ein falsches Ergebnis liefern
$disableSettingsButton = empty($this->app->erp->getActionsByModule($moduleKey)) ? true : false;
// Einstellungs-Button hinzufügen
if (!$disableSettingsButton){
$hasSettingsPermission1 = $this->app->erp->RechteVorhanden($moduleKey, 'einstellungen');
$hasSettingsPermission2 = $this->app->erp->RechteVorhanden($moduleKey, 'settings');
if($hasSettingsPermission1 || $hasSettingsPermission2){
$settingsAction = $hasSettingsPermission1 ? 'einstellungen' : 'settings';
$settingsLink = sprintf('index.php?module=%s&action=%s', $moduleKey, $settingsAction);
$detailResult->addButton('Einstellungen', $settingsLink, ['target' => '_blank', 'data-icon' => 'settings']);
}
}
if (!empty($wikiLink)) {
$detailResult->addButton('Handbuch', $wikiLink, ['target' => '_blank', 'data-icon' => 'help', 'class' => 'button button-secondary']);
}
if (empty($wikiLink) && !empty($moduleData['helpdesk_link'])){
$detailResult->addButton('Handbuch', $moduleData['helpdesk_link'], ['target' => '_blank', 'data-icon' => 'help', 'class' => 'button button-secondary']);
}
if (!empty($moduleData['youtube_link'])){
$detailResult->addButton('Video', $moduleData['youtube_link'], ['target' => '_blank']);
}
if (!empty($moduleData['description'])){
$detailResult->setDescription($moduleData['description']);
}
if (!empty($wikiArticle['content'])) {
$detailResult->setDescription($wikiContent);
}
$detailResult->setTitle($moduleData['title']);
}
}
/**
* @return array
*/
public function BuildModuleList(): array
{
$apps = $this->getAppList();
// ANFANG inline.php einlesen
$sprachen = ['german','english'];
if(method_exists($this->app->User,'GetSprachen')) {
$sprachen = $this->app->User->GetSprachen();
if (in_array('deutsch', $sprachen, true) && !in_array('german', $sprachen, true)) {
$sprachen[] = 'german';
}
}
if(!is_array($sprachen)) {
return [];
}
$sprachen = array_reverse($sprachen);
$inline = [];
foreach($sprachen as $sprache) {
if(preg_match_all('/[a-zA-Z0-9\-]/', $sprache, $erg)) {
$inlineFilePath = dirname(dirname(__DIR__)) . sprintf('/languages/%s/inline.php', $sprache);
if(is_file($inlineFilePath)) {
include_once $inlineFilePath;
}
}
}
// ENDE inline.php einlesen
$modules = [];
foreach($apps as $appKey => $app) {
$modules[$appKey] = [
'key' => $appKey,
'title' => $app['Bezeichnung'],
'title2' => empty($app['Bezeichnung2'])?'': $app['Bezeichnung2'],
'module_link' => $app['Link'],
'module_link2' => empty($app['Link2'])?'':$app['Link2'],
'description' => isset($inline[$appKey]['default']['description']) ? $inline[$appKey]['default']['description'] : null,
'category' => isset($inline[$appKey]['default']['kategorie']) ? $inline[$appKey]['default']['kategorie'] : null,
'helpdesk_link' => isset($inline[$appKey]['default']['link']) ? $inline[$appKey]['default']['link'] : null,
'youtube_link' => isset($inline[$appKey]['default']['youtube']) ? 'https://youtu.be/' . $inline[$appKey]['default']['youtube'] : null,
'beta' => isset($app['beta']) ? $app['beta'] : null,
'legacy' => isset($app['legacy']) ? $app['legacy'] : false,
'special' => isset($app['special']) ? $app['special'] : false,
'popular' => !empty($app['popular']),
'project_sensitive' => isset($app['project_sensitive']) ? $app['project_sensitive'] : false
];
}
return $modules;
}
/**
* @param string $moduleName
*
* @return bool
*/
public function deactivateModule($moduleName): bool
{
if(empty($moduleName) || in_array($moduleName, $this->nodeactivateable)) {
return false;
}
if(!$this->app->erp->ModulVorhanden($moduleName, true)) {
return false;
}
$check = $this->app->DB->Select(
sprintf(
"SELECT `id` FROM `module_status` WHERE `module` = '%s' LIMIT 1",
$this->app->DB->real_escape_string($moduleName)
)
);
if($check){
$this->app->DB->Update(
sprintf(
'UPDATE `module_status` SET `active` = 0 WHERE `id` = %d', $check
)
);
}
else {
$this->app->DB->Insert(
sprintf(
'INSERT INTO `module_status` (`module`, `active`) VALUES (\'%s\', 0)',
$this->app->DB->real_escape_string($moduleName)
)
);
}
if(!isset($this->deactivatesModules[$this->app->Conf->WFdbname])
|| $this->deactivatesModules[$this->app->Conf->WFdbname] === null) {
$this->loadDeactivatedModules();
}
elseif(!in_array($moduleName, $this->deactivatesModules[$this->app->Conf->WFdbname])) {
$this->deactivatesModules[$this->app->Conf->WFdbname][] = $moduleName;
}
$obj = $this->app->loadModule($moduleName);
if(!empty($obj) && method_exists($obj, 'Uninstall')) {
$obj->Uninstall();
}
return true;
}
/**
* @param string $moduleName
*
* @return bool
*/
public function activateModule($moduleName): bool
{
if(empty($moduleName)) {
return false;
}
if(!$this->app->erp->ModulVorhanden($moduleName, true)) {
return false;
}
$check = $this->app->DB->Select(
sprintf(
"SELECT `id` FROM `module_status` WHERE `module` = '%s' LIMIT 1",
$this->app->DB->real_escape_string($moduleName)
)
);
if($check) {
$this->app->DB->Update(
sprintf(
'UPDATE `module_status` SET `active` = 1 WHERE `id` = %d', $check
)
);
}
else {
$this->app->DB->Insert(
sprintf(
'INSERT INTO `module_status` (`module`, `active`) VALUES (\'%s\', 1)',
$this->app->DB->real_escape_string($moduleName)
)
);
}
if(!isset($this->deactivatesModules[$this->app->Conf->WFdbname])
|| $this->deactivatesModules[$this->app->Conf->WFdbname] === null) {
$this->loadDeactivatedModules();
}
elseif(in_array($moduleName, $this->deactivatesModules[$this->app->Conf->WFdbname])) {
$this->deactivatesModules[$this->app->Conf->WFdbname] =
array_diff($this->deactivatesModules[$this->app->Conf->WFdbname], [$moduleName]);
}
$this->app->erp->InstallModul($moduleName);
return true;
}
/**
* @param string $moduleName
*
* @return bool
*/
public function isModuleDeactivated($moduleName): bool
{
if(empty($moduleName) || in_array($moduleName, $this->nodeactivateable)) {
return false;
}
if(!isset($this->deactivatesModules[$this->app->Conf->WFdbname])
|| $this->deactivatesModules[$this->app->Conf->WFdbname] === null) {
$this->loadDeactivatedModules();
}
return in_array($moduleName, $this->deactivatesModules[$this->app->Conf->WFdbname]);
}
/**
* @return void
*/
protected function loadDeactivatedModules(): void
{
$deactivatedModules = $this->app->DB->SelectFirstCols(
'SELECT DISTINCT `module` FROM `module_status` WHERE `active` = 0 AND `module` <> \'\''
);
$this->deactivatesModules[$this->app->Conf->WFdbname] = [];
if(empty($deactivatedModules)) {
return;
}
$this->deactivatesModules[$this->app->Conf->WFdbname] = array_diff($deactivatedModules, $this->nodeactivateable);
}
}