diff --git a/include/class.faq.php b/include/class.faq.php index a9d0a5349371a05fa70fe1d94d40c6bfc84f7ace..c7a6e940d5de96d956461f549ed8e4e661340786 100644 --- a/include/class.faq.php +++ b/include/class.faq.php @@ -32,10 +32,12 @@ class FAQ extends VerySimpleModel { var $attachments; var $topics; + var $_local; function __construct() { call_user_func_array(array('parent', '__construct'), func_get_args()); - $this->attachments = new GenericAttachments($this->getId(), 'F'); + if (isset($this->faq_id)) + $this->attachments = new GenericAttachments($this->getId(), 'F'); } /* ------------------> Getter methods <--------------------- */ @@ -103,6 +105,34 @@ class FAQ extends VerySimpleModel { return $this->save(); } + function printPdf() { + global $thisstaff; + require_once(INCLUDE_DIR.'mpdf/mpdf.php'); + + $paper = 'Letter'; + if ($thisstaff) + $paper = $thisstaff->getDefaultPaperSize(); + + ob_start(); + $faq = $this; + include STAFFINC_DIR . 'templates/faq-print.tmpl.php'; + $html = ob_get_clean(); + + $pdf = new mPDF('', $paper); + // Setup HTML writing and load default thread stylesheet + $pdf->WriteHtml( + '<style> + .bleed { margin: 0; padding: 0; } + .faded { color: #666; } + .faq-title { font-size: 170%; font-weight: bold; } + .thread-body { font-family: serif; }' + .file_get_contents(ROOT_DIR.'css/thread.css') + .'</style>' + .'<div>'.$html.'</div>'); + + $pdf->Output(Format::slugify($faq->getQuestion()) . '.pdf', 'I'); + } + // Internationalization of the knowledge base function getTranslateTag($subtag) { @@ -128,7 +158,7 @@ class FAQ extends VerySimpleModel { } function _getLocal($what, $lang=false) { if (!$lang) { - $lang = Internationalization::getCurrentLanguage(); + $lang = $this->getDisplayLang(); } $translations = $this->getAllTranslations(); foreach ($translations as $t) { @@ -140,12 +170,17 @@ class FAQ extends VerySimpleModel { } return $this->ht[$what]; } + function getDisplayLang() { + if (isset($_REQUEST['kblang'])) + $lang = $_REQUEST['kblang']; + else + $lang = Internationalization::getCurrentLanguage(); + return $lang; + } function getLocalAttachments($lang=false) { - if (!$lang) { - $lang = Internationalization::getCurrentLanguage(); - } - return $this->attachments->getSeparates($lang); + return $this->attachments->getSeparates( + $lang ?: $this->getDisplayLang()); } function updateTopics($ids){ @@ -176,7 +211,7 @@ class FAQ extends VerySimpleModel { foreach ($this->getAllTranslations() as $t) { $trans = @$vars['trans'][$t->lang]; - if (!$trans || !array_filter($trans)); + if (!$trans || !array_filter($trans)) // Not updating translations continue; @@ -217,13 +252,16 @@ class FAQ extends VerySimpleModel { return true; } + function getVisibleAttachments() { + return array_merge( + $this->attachments->getSeparates() ?: array(), + $this->getLocalAttachments()); + } + function getAttachmentsLinks($separator=' ',$target='') { $str=''; - $attachments = array_merge( - $this->attachments->getSeparates() ?: array(), - $this->getLocalAttachments()); - if ($attachments) { + if ($attachments = $this->getVisibleAttachments()) { foreach($attachments as $attachment ) { /* The h key must match validation in file.php */ $hash=$attachment['key'].md5($attachment['id'].session_id().strtolower($attachment['key'])); @@ -261,7 +299,7 @@ class FAQ extends VerySimpleModel { return $faq; } - static function create($vars) { + static function create($vars=false) { $faq = parent::create($vars); $faq->created = SqlFunction::NOW(); return $faq; @@ -317,6 +355,7 @@ class FAQ extends VerySimpleModel { $this->category = $category; $this->ispublished = !!$vars['ispublished']; $this->notes = Format::sanitize($vars['notes']); + $this->keywords = ''; if (!$this->save()) return false; diff --git a/include/staff/faq-view.inc.php b/include/staff/faq-view.inc.php index 0c8824722e1a8c57bf1cf6b5dd6e64a86d7fe3f4..8a50c363d8c0c3bc6ba33644ce12c3a0deb34276 100644 --- a/include/staff/faq-view.inc.php +++ b/include/staff/faq-view.inc.php @@ -10,59 +10,106 @@ $category=$faq->getCategory(); » <a href="kb.php?cid=<?php echo $category->getId(); ?>"><?php echo $category->getName(); ?></a> <span class="faded">(<?php echo $category->isPublic()?__('Public'):__('Internal'); ?>)</span> </div> -<div class="pull-left" style="width:700px;padding-top:2px;"> -<strong style="font-size:16px;"><?php echo $faq->getQuestion() ?></strong> <span class="faded"><?php echo '('.$faq->isPublished()?__('Published').')':''; ?></span> -</div> -<div class="pull-right flush-right" style="padding-top:5px;padding-right:5px;"> + +<div class="pull-right faq-meta"> +<?php if ($attachments = $faq->getVisibleAttachments()) { ?> +<section> + <strong><?php echo __('Attachments');?>:</strong> +<?php foreach ($attachments as $att) { ?> + <div> + <a href="file.php?h=<?php echo $att['download']; ?>" class="no-pjax"> + <i class="icon-file"></i> + <?php echo Format::htmlchars($att['name']); ?> + </a> + </div> +<?php } ?> +</section> +<?php } ?> + +<?php if ($faq->getHelpTopics()->count()) { ?> +<section> + <strong><?php echo __('Help Topics'); ?></strong> +<?php foreach ($faq->getHelpTopics() as $topic) { ?> + <div><?php echo $topic->getFullName(); ?></div> +<?php } ?> +</section> +<?php } ?> + <?php -if($thisstaff->canManageFAQ()) { - echo sprintf('<a href="faq.php?id=%d&a=edit" class="Icon newHelpTopic">'.__('Edit FAQ').'</a>', - $faq->getId()); +$displayLang = $faq->getDisplayLang(); +$otherLangs = array(); +if ($cfg->getPrimaryLanguage() != $displayLang) + $otherLangs[] = $cfg->getPrimaryLanguage(); +foreach ($faq->getAllTranslations() as $T) { + if ($T->lang != $displayLang) + $otherLangs[] = $T->lang; } -?> - +if ($otherLangs) { ?> +<section> + <div><strong><?php echo __('Other Languages'); ?></strong></div> +<?php + foreach ($otherLangs as $lang) { ?> + <a href="faq.php?kblang=<?php echo $lang; ?>&id=<?php echo $faq->getId(); ?>"> + <?php echo Internationalization::getLanguageDescription($lang); ?> + </a> + <?php } ?> +</section> +<?php } ?> + +<section> +<div> + <strong><?php echo $faq->isPublished()?__('Published'):__('Internal'); ?></strong> </div> -<div class="clear"></div> -<div class="thread-body"> -<?php echo $faq->getAnswerWithImages(); ?> +<a href="#"><?php echo __('manage access'); ?></a> +</section> + +</div> + +<div class="faq-content"> +<div class="faq-manage pull-right"> + <button> + <i class="icon-print"></i> +<?php +$query = array(); +parse_str($_SERVER['QUERY_STRING'], $query); +$query['a'] = 'print'; +$query['id'] = $faq->getId(); +$query = http_build_query($query); ?> + <a href="faq.php?<?php echo $query; ?>" class="no-pjax"><?php + echo __('Print'); ?> + </a></button> +<?php +if ($thisstaff->canManageFAQ()) { ?> + <button> + <i class="icon-edit"></i> + <a href="faq.php?id=<?php echo $faq->getId(); ?>&a=edit"><?php + echo __('Edit FAQ'); ?> + </a></button> +<?php } ?> +</div> + +<div class="faq-title flush-left"><?php echo $faq->getLocalQuestion() ?> +</div> + +<div class="faded"><?php echo __('Last updated');?> + <?php echo Format::db_daydatetime($category->getUpdateDate()); ?> +</div> +<br/> +<div class="thread-body bleed"> +<?php echo $faq->getLocalAnswerWithImages(); ?> +</div> + </div> <div class="clear"></div> -<p> - <div><span class="faded"><b><?php echo __('Attachments');?>:</b></span> <?php echo $faq->getAttachmentsLinks(); ?></div> - <div><span class="faded"><b><?php echo __('Help Topics');?>:</b></span> - <?php echo ($topics=$faq->getHelpTopics())?implode(', ',$topics):' '; ?> - </div> -</p> -<div class="faded"> <?php echo __('Last updated');?> <?php echo Format::db_daydatetime($category->getUpdateDate()); ?></div> <hr> + <?php -if($thisstaff->canManageFAQ()) { - //TODO: add js confirmation.... - ?> - <div> - <form action="faq.php?id=<?php echo $faq->getId(); ?>" method="post"> - <?php csrf_token(); ?> - <input type="hidden" name="id" value="<?php echo $faq->getId(); ?>"> - <input type="hidden" name="do" value="manage-faq"> - <div> - <strong><?php echo __('Options');?>: </strong> - <select name="a" style="width:200px;"> - <option value=""><?php echo __('Select Action');?></option> - <?php - if($faq->isPublished()) { ?> - <option value="unpublish"><?php echo __('Unpublish FAQ');?></option> - <?php - }else{ ?> - <option value="publish"><?php echo __('Publish FAQ');?></option> - <?php - } ?> - <option value="edit"><?php echo __('Edit FAQ');?></option> - <option value="delete"><?php echo __('Delete FAQ');?></option> - </select> - <input type="submit" name="submit" value="<?php echo __('Go');?>"> - </div> - </form> - </div> -<?php -} +if ($thisstaff->canManageFAQ()) { ?> +<form action="faq.php?id=<?php echo $faq->getId(); ?>" method="post"> + <?php csrf_token(); ?> + <input type="hidden" name="do" value="manage-faq"> + <input type="hidden" name="id" value="<?php echo $faq->getId(); ?>"> + <button name="a" value="delete"><?php echo __('Delete FAQ'); ?></button> +</form> +<?php } ?> diff --git a/include/staff/faq.inc.php b/include/staff/faq.inc.php index e5337ec0b702103aa9a198d31823411ea9f93d5f..81230f58eac906e27048bdcafd0f4a1fe429398f 100644 --- a/include/staff/faq.inc.php +++ b/include/staff/faq.inc.php @@ -133,7 +133,7 @@ if ($faq) { ?> <li class="<?php if ($tag == $cfg->getPrimaryLanguage()) echo "active"; ?>"><a href="#lang-<?php echo $tag; ?>" title="<?php echo Internationalization::getLanguageDescription($tag); - ?>"><span class="flag flag-<?php echo strtolower($locale ?: $info['flag'] ?: $lang); ?>"></span> + ?>"><span class="flag flag-<?php echo strtolower($i['flag'] ?: $locale ?: $lang); ?>"></span> </a></li> <?php } ?> </ul> diff --git a/scp/css/scp.css b/scp/css/scp.css index ca4e4b4385d7d738bd9ab9ffdb86c6a0996dd727..255bcab8af43634e2cb9db56085d00f44a32f4e8 100644 --- a/scp/css/scp.css +++ b/scp/css/scp.css @@ -1978,6 +1978,38 @@ table.custom-info td { border-bottom: 1px dotted rgba(0,0,0,0.3); } +.faq-title { + font-size: 170%; + font-weight: 400; + padding-right: 200px; +} +.faq-content { + width: 670px; + margin: 0 15px; +} +.faq-meta { + border: 1px solid #888; + padding: 10px; + width: 200px; + background-color: #ddd; + background-color: rgba(0, 0, 0, 0.1); +} +.faq-meta section + section { + margin-top: 15px; +} + +button a { + color: ButtonText !important; + text-decoration: none; +} +button a:hover { + text-decoration: none; +} + +.bleed { + padding: 0; + margin: 0; +} .doc-desc-title { font-weight: bold; text-transform: capitalize; diff --git a/scp/faq.php b/scp/faq.php index ea4b72f7c31526cf184d2d55ac6c56d4725fe4f2..196b0862b1a2f7bb1e0b89e58bc099c40e634b22 100644 --- a/scp/faq.php +++ b/scp/faq.php @@ -72,7 +72,7 @@ if ($_POST) { __('this FAQ article')); break; case 'update': - case 'edit'; + case 'edit': if(!$faq) $errors['err'] = sprintf(__('%s: Invalid or unknown'), __('FAQ article')); elseif($faq->update($_POST,$errors)) { @@ -155,6 +155,8 @@ if($faq) { $inc='faq-view.inc.php'; if($_REQUEST['a']=='edit' && $thisstaff->canManageFAQ()) $inc='faq.inc.php'; + elseif ($_REQUEST['a'] == 'print') + return $faq->printPdf(); }elseif($_REQUEST['a']=='add' && $thisstaff->canManageFAQ()) { $inc='faq.inc.php'; } elseif($category && $_REQUEST['a']!='search') {