app=$app; if($intern){ return; } $this->app->ActionHandlerInit($this); $this->app->DB->DisableHTMLClearing(true); $this->app->ActionHandler("create","WikiCreate"); $this->app->ActionHandler("edit","WikiEdit"); $this->app->ActionHandler("delete","WikiDelete"); $this->app->ActionHandler("rename","WikiRename"); $this->app->ActionHandler("new","WikiNew"); $this->app->ActionHandler("alle","WikiAlle"); $this->app->ActionHandler("dateien","WikiDateien"); $this->app->ActionHandler("list","WikiList"); $this->app->ActionHandler("settings","WikiSettings"); $this->app->ActionHandler("getfile","WikiGetFile"); $this->app->ActionHandler("faq","WikiFaq"); $this->app->ActionHandler("changelog","WikiChangelog"); $this->app->ActionHandler("minidetailsites","WikiMinidetailSites"); $this->app->ActionHandler("minidetailfaq","WikiMinidetailFaq"); $this->app->ActionHandler("minidetailchangelog","WikiMinidetailChangelog"); $this->app->DefaultActionHandler("list"); $this->app->ActionHandlerListen($app); } /** * @return bool */ public function runInstallFromJson() { ignore_user_abort(true); $this->app->erp->SetKonfigurationValue('wiki_install', 0); $workspaces = $this->getAllWorkspaces(); $foundWorkspace = false; if(!empty($workspaces)) { foreach($workspaces as $workspace) { if($workspace['name'] === 'XentralHandbuch' || $workspace['foldername'] === 'XentralHandbuch') { $foundWorkspace = true; if($workspace['savein'] !== 'userdata') { $this->app->DB->Update( sprintf( "UPDATE wiki_workspace SET savein = 'userdata' WHERE id =%d", $workspace['id'] ) ); } break; } } } if(!$foundWorkspace) { $this->app->DB->Insert( "INSERT INTO wiki_workspace (name, description, active, foldername, savein) VALUE ('XentralHandbuch','',1,'XentralHandbuch','userdata')" ); } $ret = $this->fromUserData(); $workspace = $this->getWorkspaceByName('XentralHandbuch'); if(!empty($workspace['id'])){ $this->app->DB->Update( sprintf( "UPDATE `datei_stichwoerter` AS `ds` INNER JOIN `wiki` AS `w` ON `ds`.objekt LIKE 'Wiki' AND ds.parameter = w.id SET ds.parameter2 = %d WHERE w.wiki_workspace_id = %d", $workspace['id'],$workspace['id'] ) ); } return $ret; } public function Install() { $this->app->erp->RegisterHook('inline_tooltip','wiki','WikiInlineTooltip'); $this->app->erp->RegisterHook('appstoreModulelistToShow','wiki','WikiAppstoreModulelistToShow'); $this->app->erp->RegisterHook('appstoreModuleDetailToShow','wiki','WikiAppstoreModuleDetailToShow'); $this->app->erp->RegisterHook('welcome_news','wiki','WikiWelcomeNews'); $this->app->erp->RegisterHook('dateibrowser_tablesearch_list_swhere2','wiki','WikiDateiBrowserTableSearch'); $this->getAllWorkspaces(); $this->runInstallFromJson(); $this->app->erp->SetKonfigurationValue('wiki_install', 1); } /** * @param string $swhere2 */ public function WikiDateiBrowserTableSearch(&$swhere2) { $workspace = $this->getWorkspaceByName('XentralHandbuch'); if(empty($workspace)) { return; } $swhere2 .= sprintf(" AND (ds.objekt NOT LIKE 'Wiki' OR ds.parameter2 <> '%d') ", $workspace['id']); } public function WikiWelcomeNews() { if(!$this->app->erp->RechteVorhanden('wiki', 'list')) { return; } $workspace = $this->getWorkspaceByName('XentralHandbuch'); if(empty($workspace)) { return; } $version_revision = ''; include dirname(dirname(__DIR__)).'/version.php'; $wiki = $this->getArticleByName('changelog'.$version_revision, $workspace['id']); if(empty($wiki)) { return; } $this->app->Tpl->Add( 'UPDATEBUTTONS_HOOK1', '{|Änderungen zur Version ' .$version_revision.'|}' ); } /** * @param array $module */ public function WikiAppstoreModuleDetailToShow(&$module) { $workspace = $this->getWorkspaceByName('XentralHandbuch'); if(empty($workspace)) { return; } $wikis = $this->app->DB->SelectArr( sprintf( "SELECT w.* FROM `wiki` AS `w` WHERE w.`wiki_workspace_id` = %d AND w.`name` = '%s' ORDER BY w.`name`, w.`language` = '' DESC, w.language = 'default ' DESC", $workspace['id'], $this->app->DB->real_escape_string($module['key']) ) ); if(empty($wikis)) { return; } $name = ''; foreach($wikis as $wiki) { if($wiki['name'] === $name) { continue; } $name = $wiki['name']; $module['helpdesk'] = 'index.php?module=wiki&action=list&workspace='.$workspace['id'].'&cmd='.$name; } } /** * @param array $modules */ public function WikiAppstoreModulelistToShow(&$modules) { $workspace = $this->getWorkspaceByName('XentralHandbuch'); if(empty($workspace)) { return; } $modulList = []; $nameToModule = []; if(!empty($modules['kauf'])) { foreach($modules['kauf'] as $key => $module) { if(!empty($module['key']) && $module['key'] !== 'appstore_extern') { $modulList[] = $this->app->DB->real_escape_string($module['key']); $nameToModule[$module['key']] = ['kauf', $key]; } } } if(!empty($modules['installiert'])) { foreach($modules['installiert'] as $key => $module) { if(!empty($module['key']) && $module['key'] !== 'appstore_extern') { $modulList[] = $this->app->DB->real_escape_string($module['key']); $nameToModule[$module['key']] = ['installiert', $key]; } } } $wikis = $this->app->DB->SelectArr( sprintf( "SELECT w.* FROM `wiki` AS `w` WHERE w.`wiki_workspace_id` = %d AND w.`name` IN ('%s') ORDER BY w.`name`, w.`language` = '' DESC, w.language = 'default ' DESC", $workspace['id'], implode("','", $modulList) ) ); if(empty($wikis)) { return; } $name = ''; foreach($wikis as $wiki) { if($wiki['name'] === $name) { continue; } $name = $wiki['name']; if(empty($nameToModule[$name])) { continue; } $modules[$nameToModule[$name][0]][$nameToModule[$name][1]]['helpdesk'] = 'index.php?module=wiki&action=list&workspace='.$workspace['id'].'&cmd='.$name; } } /** * @param string $folder */ public function changeUserdataRights($folder = '') { if(empty($folder)) { $folder = $this->getUserDataFolder(); $workspace = $this->getWorkspaceByName('XentralHandbuch'); $folder .= $workspace['foldername']; } if(!is_dir($folder) && !@mkdir($folder,0777,true) && !is_dir($folder)) { return; } @chmod($folder, 0777); $handle = @opendir($folder); if(!$handle) { return; } $folders = []; while($entry = @readdir($handle)) { if(strpos($entry,'.') === 0) { continue; } if(is_file($folder.'/'.$entry)) { @chmod($folder.'/'.$entry, 0666); } if(!is_dir($folder.'/'.$entry)) { continue; } $folders[] = $folder.'/'.$entry; } closedir($handle); if(empty($folders)) { return; } foreach($folders as $subfolder) { $this->changeUserdataRights($subfolder); } } /** * @param array $arr * @param string $prefix * * @return string */ public function drawMenuFromArray($arr, $prefix = '') { $html = ''; if(empty($arr)) { return $html; } $actlvl = 0; foreach($arr as $key => $row) { $newLvl = $row['lvl']; if($newLvl > $actlvl) { for($i = $actlvl; $i < $newLvl; $i++) { if($i === 0) { $html .= ''; } return $html.'
'; } /** * @param string $html * @param int $maxLvl * @param string $prefix * * @return array */ public function parseMenuFromHtml($html, $maxLvl = 3, $prefix = '') { $headers = []; $html = str_replace( [ '

 

', '

 

', '

 

', '


', '


', '


', '


', '


', '


', '


', '


', '


', '

', '

', '

', ], [ ' ', ' ', ' ', '

', '

', '

', '

', '

', '

', ' ', ' ', ' ', ], $html ); if(preg_match_all( sprintf( '/]*)>([^<]+)<\/h([1-%d]{1})>/i', $maxLvl, $maxLvl ),$html,$matches,PREG_OFFSET_CAPTURE)) { foreach($matches[0] as $i => $match) { $headers[] = ['lvl' => $matches[1][$i][0], 'text' => $matches[3][$i][0], 'pos' => $matches[0][$i][1]]; if($prefix === '') { continue; } if(!empty($matches[2][$i][0]) && preg_match_all('/(.*)(id="([^"]+)")(.*)/', $matches[2][$i][0],$matches2,PREG_OFFSET_CAPTURE)) { if(!empty($matches2[2][0][0])) { $matches[2][$i][0] = str_replace($matches2[2][0][0], ' ', $matches[2][$i][0]); } } $html = str_replace( $match[0], ''.$matches[3][$i][0].'', $html ); } } return [$headers, $html]; } public function WikiInlineTooltip(&$inline, &$tooltip, &$module, &$action, $id, $module2) { $actModule = !empty($module2)?$module2:$module; if(empty($actModule)) { return; } $moduleOld = $module; $module = $actModule; $extraLinks = []; $content = ''; list($poId, $link, $oldLink) = [null,null,null]; $oldAction = $action; if(empty($inline[$actModule])) { $action = 'default'; if(!empty($link)) { $inline[$actModule]['default']['link'] = $link; } $inline[$actModule][$oldAction]['link'] = $link; } elseif(!empty($inline[$actModule][$action])) { if(empty($inline[$actModule][$action]['link']) && !empty($link)) { $inline[$actModule][$action]['link'] = $link; } } elseif(!empty($inline[$actModule]['default'])) { $action = 'default'; $inline[$actModule][$action] = $inline[$actModule]['default']; if(!empty($link)) { $inline[$actModule]['default']['link'] = $link; } } else { $action = 'default'; if(!empty($link)) { $inline[$actModule]['default']['link'] = $link; $inline[$actModule][$oldAction]['link'] = $link; } } if(!empty($oldLink)) { $extraLinks[$oldLink] = $oldLinkDescription; } if(!empty($extraLinks)) { $inline[$actModule][$action]['extralinks3'] = $extraLinks; $inline[$actModule][$oldAction]['extralinks3'] = $extraLinks; } $linkContent = ''; if(!empty($content)) { $inline[$actModule][$action]['extradescription'] = $content;// '

Vorschau

'.$content.'
'; $inline[$actModule][$oldAction]['extradescription'] = $content;//'

Vorschau

'.$content.'
'; $linkContent = $content; } /** @var Wiki $wiki */ //$wiki = $this->app->erp->LoadModul('wiki'); $workspace = $this->getWorkspaceByName('XentralHandbuch'); if(!empty($workspace)){ //$this->checkWiki($actModule, $content, $wiki); $inline[$actModule][$action]['handbook'] = ''; $wiki = $this->getArticleByName($actModule,$workspace['id']); $content = $wiki['content']; $menu = null; if(!empty($content)){ list($menu, $content) = $this->parseMenuFromHtml($content); } if(empty($linkContent)) { $listLink = ''; if(!empty($wiki)) { $listLink = ' ' .'(Handbuch im neuen Tab öffnen)' .'
'; $linkToWiki = "index.php?module=wiki&action=list&workspace=".$workspace['id'].'&cmd='.$wiki['name'].""; $this->app->Tpl->Add("LINKTOWIKI", $linkToWiki); } $inline[$actModule][$action]['handbook'] = ''; $inline[$actModule][$oldAction]['handbook'] = ''; if(!empty($menu)) { ##$inline[$actModule][$action]['handbook'] .= '

Inhaltsverzeichnis

'.$listLink.$this->drawMenuFromArray($menu); if($action !== $oldAction){ ##$inline[$actModule][$oldAction]['handbook'] .= '

Inhaltsverzeichnis

' . $listLink . $this->drawMenuFromArray($menu); } } else { $inline[$actModule][$action]['handbook'] .= $listLink; if($action !== $oldAction){ $inline[$actModule][$oldAction]['handbook'] .= $listLink; } } $inline[$actModule][$action]['handbook'] .= $content . '
'; $inline[$actModule][$oldAction]['handbook'] .= $content . '
'; } else{ if(!empty($menu)) { ##$inline[$actModule][$action]['handbook'] .= '

Inhaltsverzeichnis

'.$this->drawMenuFromArray($menu); } $inline[$actModule][$action]['handbook'] .= $content . '
'; } if(!empty($wiki)) { /*$inline[$actModule][$action]['extraheading'] = '';*/ $inline[$actModule][$action]['extralinks3'] = [ 'index.php?module=wiki&action=edit&workspace='.$workspace['id'].'&cmd='.$wiki['name'] => 'Wiki' ]; unset($inline[$actModule][$action]['extralinks']); $faqs = $this->app->DB->SelectArr(sprintf("SELECT question,answer FROM wiki_faq WHERE wiki_id = %d", $wiki['id'])); if(!empty($faqs)) { $inline[$actModule][$action]['faqs'] = $faqs; if($action !== $oldAction && empty($inline[$actModule][$oldAction]['faqs'])) { $inline[$actModule][$oldAction]['faqs'] = $faqs; } } $inline[$actModule][$action]['extmenu'] = '
  • Bearbeiten
  • '; if($oldAction !== $action){ $inline[$actModule][$oldAction]['extmenu'] = $inline[$actModule][$action]['extmenu']; } } else { } if($oldAction !== $action){ $inline[$actModule][$oldAction]['handbook'] = $inline[$actModule][$action]['handbook']; } } if(empty($inline[$actModule][$action]['handbook'])){ $inline[$actModule][$action]['handbook'] = ' '; //$inline[$actModule][$action]['extralinks3']; $inline[$actModule][$oldAction]['handbook'] = ' '; //$inline[$actModule][$oldAction]['extralinks3']; } $action = $oldAction; if($module !== $moduleOld) { $inline[$moduleOld] = $inline[$module]; } $module = $moduleOld; } /** * @param ApplicationCore $app * @param string $name * @param array $erlaubtevars * * @return array */ public function TableSearch($app, $name, $erlaubtevars) { switch($name) { case 'wiki_changelog': $id = $this->app->Secure->GetGET('id'); $wiki = $this->app->DB->SelectRow(sprintf('SELECT name, id, wiki_workspace_id FROM wiki WHERE id = %d', $id)); if(!empty($wiki)) { $ids = $this->app->DB->SelectFirstCols( sprintf( "SELECT id FROM wiki WHERE wiki_workspace_id = %d AND name = '%s'", $wiki['wiki_workspace_id'], $this->app->DB->real_escape_string($wiki['name']) ) ); } else{ $ids = $this->app->DB->SelectFirstCols( sprintf( 'SELECT id FROM wiki WHERE parent_id = %d OR id = %d', $id, $id ) ); $ids = $this->app->DB->SelectFirstCols( sprintf( 'SELECT id FROM wiki WHERE parent_id IN (%s) OR id IN (%s)', implode(',', $ids), implode(',', $ids) ) ); } $result = []; $result['allowed']['wiki'] = ['faq']; $result['heading'] = ['','Datum','Bearbeiter','Kommentar','']; $result['width'] = ['1%','20%','40','50%', '1%']; $result['findcols'] = ['open','wc.created_at','wc.created_by','wc.comment', 'wc.id']; $result['searchsql'] = ['wc.comment']; $result['menucol'] = 4; $result['sql'] = "SELECT wc.id, 'app->Conf->WFconf['defaulttheme']}/images/details_open.png class=details>' as open, DATE_FORMAT(wc.created_at,'%d.%m.%Y %H:%i:%s'),wc.created_by, wc.comment, wc.id FROM wiki_changelog AS wc INNER JOIN wiki AS w ON wc.wiki_id = w.id"; $result['menu'] = '
    ' .'' .'' .'' .'
    '; $result['where'] = sprintf(' w.id in (%s)', implode(',', $ids))." AND w.comment <> '' "; $result['moreinfo'] = true; $result['moreinfoaction'] = 'changelog'; break; case 'wiki_faq': $id = $this->app->Secure->GetGET('id'); $wiki = $this->app->DB->SelectRow(sprintf('SELECT name, id, wiki_workspace_id FROM wiki WHERE id = %d', $id)); if(!empty($wiki)) { $ids = $this->app->DB->SelectFirstCols( sprintf( "SELECT id FROM wiki WHERE wiki_workspace_id = %d AND name = '%s'", $wiki['wiki_workspace_id'], $this->app->DB->real_escape_string($wiki['name']) ) ); } else{ $ids = $this->app->DB->SelectFirstCols( sprintf( 'SELECT id FROM wiki WHERE parent_id = %d OR id = %d', $id, $id ) ); $ids = $this->app->DB->SelectFirstCols( sprintf( 'SELECT id FROM wiki WHERE parent_id IN (%s) OR id IN (%s)', implode(',', $ids), implode(',', $ids) ) ); } $result = []; $result['allowed']['wiki'] = ['faq']; $result['heading'] = ['','Seite','Sprache','Frage','Menü']; $result['width'] = ['1%','40','20%','50%', '1%']; $result['findcols'] = ['open','w.name','w.language','wf.question', 'wf.id']; $result['searchsql'] = ['w.name','wf.question']; $result['menucol'] = 4; $result['sql'] = "SELECT wf.id, 'app->Conf->WFconf['defaulttheme']}/images/details_open.png class=details>' as open, w.name, w.language, wf.question, wf.id FROM wiki_faq AS wf INNER JOIN wiki AS w ON wf.wiki_id = w.id"; $result['menu'] = '
    ' .'' .'ändern' .' ' .'löschen' .'' .'
    '; $result['where'] = sprintf(' w.id in (%s)', implode(',', $ids)); $result['moreinfo'] = true; $result['moreinfoaction'] = 'faq'; break; case 'wiki_sites': $workspace = $this->getUserWorkspace(); $result = []; $result['allowed']['wiki'] = ['settings']; $result['heading'] = ['','Seite','Sprache','Menü']; $result['width'] = ['1%','40','20%', '1%']; $result['findcols'] = ['open','w.name','w.language', 'w.id']; $result['searchsql'] = ['w.name']; $result['menucol'] = 3; $result['sql'] = "SELECT w.id, 'app->Conf->WFconf['defaulttheme']}/images/details_open.png class=details>' as open, w.name, w.language, w.id FROM wiki AS w"; $result['menu'] = '
    ' .'' .'zur Seite' .'' .'
    '; $result['where'] = sprintf(' w.wiki_workspace_id = %d', $workspace); $result['moreinfo'] = true; $result['moreinfoaction'] = 'sites'; break; case 'wiki_workspaces': $result = []; $result['allowed']['wiki'] = array('settings'); $result['heading'] = ['Bezeichnung','Speicherort','Aktiv', 'Menü']; $result['width'] = ['54%','40','5%', '1%']; $result['findcols'] = array('ww.name','ww.active','ww.savein', 'ww.id'); $result['searchsql'] = array('ww.name'); $result['sql'] = "SELECT ww.id, ww.name,IF(ww.savein = 'userdata','Userdata','Datenbank'), IF(ww.active,'ja','-'), ww.id FROM wiki_workspace AS ww"; $result['count'] = 'SELECT COUNT(ww.id) FROM wiki_workspace AS ww'; $result['menucol'] = 4; $result['menu'] = '
    ' . 'Editieren' . ' ' . 'Übersicht' . ' ' . 'Löschen' . '
    '; $result['where'] = 'ww.id > 0'; break; case 'wiki_files': $id = (int)$app->Secure->GetGET('id'); $workspace = $this->getUserWorkspace(); $wikiname = (string)$app->Secure->GetGET('cmd'); if ($wikiname === 'wiki_files') { $wikiname = (string)$app->Secure->GetGET('smodule', 'nohtml'); } // ID der Wiki-Page ermitteln if($id === 0 && !empty($wikiname)){ $id = (int)$app->DB->Select(sprintf('SELECT w.id FROM `wiki` AS w WHERE w.name = \'%s\' LIMIT 1',$wikiname)); } $heading = array('', 'Vorschau', 'Titel', 'Stichwort', 'Version', 'Größe', 'Ersteller', 'Bemerkung', 'Datum', 'Sortierung', 'Menü'); $width = array('1%', '10%', '40%', '15%', '5%', '10%', '15%', '10%', '10%', '15%', '10%', '5%', '1%'); $findcols = array('open', 'd.id', 'CONCAT(d.titel, \' \', v1.dateiname)', 's.subjekt', 'v1.version', "if(v1.size!='',if(v1.size > 1024*1024,CONCAT(ROUND(v1.size/1024/1024,2),' MB'),CONCAT(ROUND(v1.size/1024,2),' KB')),'')", 'v1.ersteller', 'v1.bemerkung', 'v1.datum', 's.sort', 's.id'); $searchsql = array('d.titel', 's.subjekt', 'v1.version', "if(v1.size!='',if(v1.size > 1024*1024,CONCAT(ROUND(v1.size/1024/1024,2),' MB'),CONCAT(ROUND(v1.size/1024,2),' KB')),'')", 'v1.ersteller', 'v1.bemerkung', 'v1.dateiname', "DATE_FORMAT(v1.datum, '%d.%m.%Y')"); $menu = '
    '; $menu .= ''; $menu .= 'Bild auswählen'; $menu .= ''; $menu .= ' '; $menu .= ''; $menu .= 'Bild löschen'; $menu .= ''; $menu .= '
    '; $menucol = 10; $alignright = [5, 6, 10]; if(!function_exists('imagejpeg')){ $img = "'Conf->WFconf['defaulttheme']}/images/icon_img_error.png title=\"Keine GD-Erweiterung installiert\" />'"; }else{ $img = "concat('')"; } // SQL statement $sql = "SELECT SQL_CALC_FOUND_ROWS d.id, 'Conf->WFconf['defaulttheme']}/images/details_open.png\" class=\"details\">' AS open, {$img}, IF(d.titel != '', CONCAT(d.titel, '
    ', v1.dateiname, ''), v1.dateiname), s.subjekt, v1.version, IF(v1.size != '', IF(v1.size > 1024 * 1024, CONCAT(ROUND(v1.size / 1024 / 1024, 2), ' MB'), CONCAT(ROUND(v1.size / 1024, 2),' KB')), '') AS groesse, v1.ersteller, v1.bemerkung, DATE_FORMAT(v1.datum, '%d.%m.%Y'), s.sort, d.id FROM datei AS d LEFT JOIN datei_stichwoerter AS s ON d.id = s.datei LEFT JOIN ( SELECT dv.datei, MAX(dv.version) AS version FROM datei_version AS dv GROUP BY dv.datei ) AS v2 ON v2.datei = d.id LEFT JOIN datei_version AS v1 ON v1.datei = v2.datei AND v1.version = v2.version "; $parameter = $id; $where = " s.objekt LIKE 'Wiki' AND s.parameter = '{$parameter}' AND d.geloescht = 0 "; $count = " SELECT COUNT(d.id) AS anzahl FROM datei AS d LEFT JOIN datei_stichwoerter AS s ON d.id = s.datei LEFT JOIN ( SELECT dv.datei FROM datei_version AS dv GROUP BY dv.datei ) v ON v.datei = d.id WHERE $where"; $result = [ 'alignright' => $alignright, 'heading' => $heading, 'width' => $width, 'findcols' => $findcols, 'searchsql' => $searchsql, 'menu' => $menu, 'menucol' => $menucol, 'moreinfo' => true, 'moreinfomodule' => 'dateien', 'sql' => $sql, 'where' => $where, 'count' => $count, ]; break; } // Nicht erlaubt Keys aus Result entfernen foreach ($result as $key => $value) { if (!in_array($key, $erlaubtevars, true)) { unset($result[$key]); } } return !empty($result) ? $result : []; } public function WikiMinidetailChangelog() { $id = $this->app->Secure->GetGET('id'); $iframe = $this->app->Secure->GetGET('iframe'); if(empty($iframe)) { echo ''; $this->app->ExitXentral(); } $content = $this->app->DB->Select(sprintf('SELECT content FROM wiki_changelog WHERE id = %d', $id)); echo $content; $this->app->ExitXentral(); } public function WikiMinidetailFaq() { $id = $this->app->Secure->GetGET('id'); $iframe = $this->app->Secure->GetGET('iframe'); if(empty($iframe)) { echo ''; $this->app->ExitXentral(); } $content = $this->app->DB->Select(sprintf('SELECT answer FROM wiki_faq WHERE id = %d', $id)); echo $content; $this->app->ExitXentral(); } public function WikiMinidetailSites() { $id = $this->app->Secure->GetGET('id'); $iframe = $this->app->Secure->GetGET('iframe'); if(empty($iframe)) { echo ''; $this->app->ExitXentral(); } $content = $this->app->DB->Select(sprintf('SELECT content FROM wiki WHERE id = %d', $id)); echo $content; $this->app->ExitXentral(); } public function WikiFaq() { $command = $this->app->Secure->GetGET('command'); if($command === 'deletefaq') { $wikiFaqId = $this->app->Secure->GetPOST('wikifaqid'); $success = 0; if($wikiFaqId > 0) { $this->deleteFaqInUserdata($wikiFaqId); $this->app->DB->Delete( sprintf( 'DELETE FROM wiki_faq WHERE id = %d', $wikiFaqId ) ); if($this->app->DB->affected_rows() > 0) { $success = 1; } } header('Content-Type: application/json'); echo json_encode(['success' => $success]); $this->app->ExitXentral(); } if($command === 'savefaq') { $id = $this->app->Secure->GetPOST('id'); $wikiFaqId = $this->app->Secure->GetPOST('wikifaqid'); $answer = $this->app->Secure->GetPOST('answer'); $question = $this->app->Secure->GetPOST('question'); $oldWiki = empty($wikiFaqId)?null:$this->app->DB->SelectRow( sprintf( 'SELECT * FROM wiki_faq WHERE id = %d', $wikiFaqId ) ); if(empty($wikiFaqId) && !empty($id)) { $this->app->DB->Insert(sprintf("INSERT INTO wiki_faq (wiki_id) VALUES (%d)", $id)); $wikiFaqId = $this->app->DB->GetInsertID(); } if(!empty($wikiFaqId)) { if(!empty($oldWiki['question']) && $this->app->DB->real_escape_string($oldWiki['question']) != $question) { $this->deleteFaqInUserdata($wikiFaqId); } $this->app->DB->Update( sprintf( "UPDATE wiki_faq SET answer = '%s', question = '%s', created_by = '%s', updated_at = NOW() WHERE id = %d", $answer, $question, $this->app->DB->real_escape_string($this->app->User->GetName()), $wikiFaqId ) ); $this->saveFaqInUserdata($wikiFaqId); } $wikiFaq = $wikiFaqId <= 0?null:$this->app->DB->SelectRow( sprintf('SELECT * FROM wiki_faq WHERE id = %d', $wikiFaqId) ); if(empty($wikiFaq)) { $wikiFaq = ['id' => 0, 'answer' => '', 'question' => '']; } header('Content-Type: application/json'); echo json_encode($wikiFaq); $this->app->ExitXentral(); } if($command === 'getfaq') { $wikiFaqId = $this->app->Secure->GetPOST('wikifaqid'); $wikiFaq = $wikiFaqId <= 0?null:$this->app->DB->SelectRow( sprintf( 'SELECT * FROM wiki_faq WHERE id = %d', $wikiFaqId ) ); if(empty($wikiFaq)) { $wikiFaq = ['id' => 0, 'answer' => '', 'question' => '']; } header('Content-Type: application/json'); echo json_encode($wikiFaq); $this->app->ExitXentral(); } $this->WikiMenu(); $workspace =$this->getUserWorkspace(); $language = $this->getUserLanguage(); $cmd = $this->app->Secure->GetGET('cmd'); $id = $this->app->Secure->GetGET('id'); if(!empty($id)) { $this->app->Tpl->Set('ID', $id); } else { $wiki = $this->getArticleByName($cmd, $workspace, $language); if(empty($wiki) && !empty($language)){ $wiki = $this->getArticleByName($cmd, $workspace); } if(!empty($wiki)){ $this->app->Tpl->Set('ID', $wiki['id']); } } $this->app->YUI->TableSearch('TAB1', 'wiki_faq','show','','',basename(__FILE__),__CLASS__); //$this->app->YUI->CkEditor('popupanswer','wiki',['ckeditor5'=>true,'min-height'=>'250']); $this->app->YUI->CkEditor('popupanswer','wiki'); $this->app->Tpl->Parse('PAGE', 'wiki_faq.tpl'); } public function WikiChangelog() { $this->WikiMenu(); $this->app->YUI->TableSearch('TAB1','wiki_changelog','show','','',basename(__FILE__),__CLASS__); $this->app->Tpl->Parse('PAGE', 'wiki_changelog.tpl'); } public function WikiGetFileCache() { $this->WikiGetFile(true); } public function WikiGetFile($exit = false) { $workspacefolder = $this->app->Secure->GetGET('workspacefolder', 'nothtml','', true); $article = $this->app->Secure->GetGET('article', 'nothtml','', true); $fileid = $this->app->Secure->GetGET('fileid', 'nothtml','', true); $path = $this->getUserDataFolder().$workspacefolder.'/files/'.$article.'/'.$fileid; $name = $article; if(is_file($path)) { if ( strpos ( $_SERVER [ 'HTTP_USER_AGENT' ], "MSIE" ) > 0 ) { $header_name = 'Content-Disposition: attachment; filename="' . rawurlencode ( $name ) . '"' ; } else { $header_name = 'Content-Disposition: attachment; filename*=UTF-8\'\'' . rawurlencode ( $name ) ; } $contenttype= $this->app->erp->content_type($name); if(empty($contenttype)) { $contenttype = mime_content_type($path); } //required, or it might try to send the serving //document instead of the file header('Cache-Control: public, max-age=14400, s-maxage=14400'); header('Pragma: '); header('Expires: '.date('D, d M Y H:i:s e'), time()+14400); header("Content-Type: $contenttype"); header('Content-Length: ' .(string)(empty($path)?0:@filesize($path)) ); //header('Content-Disposition: inline; filename="'.$name.'"'); //$name = $this->Dateinamen($name); //header('Content-Disposition: attachment; filename="'.$name.'"'); header($header_name); if(!empty($path) && $file = fopen($path, 'rb')){ while( (!feof($file)) && (connection_status()==0) ){ print(fread($file, 1024*8)); flush(); } fclose($file); } } if($exit) { exit; } $this->app->ExitXentral(); } public function WikiSettings() { $command = $this->app->Secure->GetGET('command'); if($command === 'openworkspace') { $id = $this->app->Secure->GetPOST('id'); $workspace = $this->app->DB->SelectRow( sprintf( 'SELECT * FROM wiki_workspace WHERE id = %d', $id ) ); if(empty($workspace)) { $workspace = [ 'name' =>'', 'id' => 0, 'active' => 1, 'savein' => '' ]; } header('Content-Type: application/json'); echo json_encode($workspace); $this->app->ExitXentral(); } if($command === 'saveworkspace') { $id = $this->app->Secure->GetPOST('id'); $active= $this->app->Secure->GetPOST('active'); $name = $this->app->Secure->GetPOST('name'); $savein = $this->app->Secure->GetPOST('savein'); $status = 0; if(empty($id)) { $this->app->DB->Insert( sprintf( "INSERT INTO wiki_workspace (id, name, description, active, savein) VALUES (NULL, '%s', '', %d,'%s')", $name, $active, $savein ) ); $status = $this->app->DB->GetInsertID()>0?1:0; } else { $this->app->DB->Update( sprintf( "UPDATE wiki_workspace SET name = '%s', active = %d, savein = '%s' WHERE id = %d", $name, $active, $savein, $id ) ); if($this->app->DB->error()) { $status = 0; } elseif($this->app->DB->Select( sprintf( 'SELECT id FROM wiki_workspace WHERE id = %d', $id ) )) { $status = 1; } } header('Content-Type: application/json'); echo json_encode(['status' => $status]); $this->app->ExitXentral(); } if($command === 'deleteworkspace') { $id = $this->app->Secure->GetPOST('id'); $status = 0; if($this->app->DB->Select(sprintf('SELECT id FROM wiki_workspace WHERE id = %d', $id))) { if($this->app->DB->Select(sprintf('SELECT id FROM wiki WHERE wiki_workspace_id = %d', $id))) { $this->app->DB->Update(sprintf('UPDATE wiki_workspace SET active = 0 WHERE id = %d', $id)); } else { $this->app->DB->Delete(sprintf('DELETE FROM wiki_workspace WHERE id = %d', $id)); } } header('Content-Type: application/json'); echo json_encode(['status' => $status]); $this->app->ExitXentral(); } $this->WikiMenu(); $this->app->erp->MenuEintrag('#','Neu'); $this->app->YUI->TableSearch('TAB1','wiki_workspaces','show','','',basename(__FILE__),__CLASS__); $this->app->YUI->TableSearch('TABSITES','wiki_sites','show','','',basename(__FILE__),__CLASS__); $this->app->Tpl->Parse('PAGE', 'wiki_settings.tpl'); } /** * @return string */ public function getUserDataFolder() { $folder = rtrim($this->app->Conf->WFuserdata).'/wiki/'; if(!is_dir($folder) && !@mkdir($folder,0777, true) && !is_dir($folder)) { return $folder; } return $folder; } /** * @return bool */ public function fromUserData() { $folder = $this->getUserDataFolder(); $workspaces = $this->getFilesAndFolders($folder); if(empty($workspaces) || empty($workspaces['folders'])) { return false; } $workspaces = $workspaces['folders']; $workspaces = array_flip($workspaces); foreach($workspaces as $workspaceKey => $workspace) { $workspaces[$workspaceKey] = 0; } $workSpacesInDb = $this->getAllWorkspaces(); foreach($workspaces as $workspace => $workspaceId) { $found = false; if(!empty($workSpacesInDb)) { foreach($workSpacesInDb as $workSpaceInDb) { if($workSpaceInDb['foldername'] === $workspace) { $workspaces[$workspace] = $workSpaceInDb['id']; $found = true; break; } } } if(!$found) { $this->app->DB->Insert( sprintf( "INSERT INTO wiki_workspace (name, foldername, savein, active) VALUES ('%s', '%s', 'userdata', 1)", $this->app->DB->real_escape_string(ucfirst($workspace)), $this->app->DB->real_escape_string($workspace) ) ); $workspaces[$workspace] = (int)$this->app->DB->GetInsertID(); } } $allLanguages = $this->app->erp->GetSelectSprachenListe(); unset($allLanguages[0]); $allLanguages = array_unique(array_merge(['default'], array_keys($allLanguages))); foreach($workspaces as $workspace => $workspaceId) { if(empty($workspaceId)) { continue; } $workspaceFolders = $this->getFilesAndFolders($folder.$workspace); if(empty($workspaceFolders) || empty($workspaceFolders['folders'])) { continue; } $workspaceFolders = $workspaceFolders['folders']; $languages = array_intersect($allLanguages, $workspaceFolders); if(empty($languages)) { continue; } foreach($languages as $language) { $articles = $this->getFilesAndFolders($folder . $workspace . '/' . $language); if(empty($articles) || empty($articles['files'])) { continue; } $articles = $articles['files']; foreach($articles as $article) { @chmod($folder . $workspace . '/' . $language.'/'.$article, 0666); $articleContent = file_get_contents($folder . $workspace . '/' . $language.'/'.$article); $articleContent = strip_tags( $articleContent, '