diff --git a/include/ajax.kbase.php b/include/ajax.kbase.php index 10266e242d680d7fb231831dab3c95c54ef05f9c..90eb1c2e6ecd5a2fbf0c1df6d9f70e7c6b69391c 100644 --- a/include/ajax.kbase.php +++ b/include/ajax.kbase.php @@ -63,5 +63,31 @@ class KbaseAjaxAPI extends AjaxController { return $resp; } + + function manageFaqAccess($id) { + global $ost, $thisstaff; + + if (!$thisstaff) + Http::response(403, 'Agent login required'); + if (!$thisstaff->hasPerm(FAQ::PERM_MANAGE)) + Http::response(403, 'Access denied'); + if (!($faq = FAQ::lookup($id))) + Http::response(404, 'No such faq article'); + + $form = new FaqAccessMgmtForm($_POST ?: $faq->getHashTable()); + + if ($_POST && $form->isValid()) { + $clean = $form->getClean(); + $faq->ispublished = $clean['ispublished']; + $faq->save(); + Http::response(201, 'Have a nice day'); + } + + $title = __("Manage FAQ Access"); + $verb = __('Update'); + $path = ltrim($ost->get_path_info(), '/'); + + include STAFFINC_DIR . 'templates/quick-add.tmpl.php'; + } } ?> diff --git a/include/class.faq.php b/include/class.faq.php index 361518d282bdeefa6d59b9cd6ad00c136cb4acc7..75ef048d163f1c77adb85242487c513c3d6dd36d 100644 --- a/include/class.faq.php +++ b/include/class.faq.php @@ -40,10 +40,7 @@ class FAQ extends VerySimpleModel { 'broker' => 'GenericAttachments', ), 'topics' => array( - 'constraint' => array( - 'faq_id' => 'FaqTopic.faq_id' - ), - 'null' => true, + 'reverse' => 'FaqTopic.faq', ), ), ); @@ -58,7 +55,6 @@ class FAQ extends VerySimpleModel { 'primary' => true, )); - var $topics; var $_local; var $_attachments; @@ -113,28 +109,19 @@ class FAQ extends VerySimpleModel { function getHelpTopicsIds() { $ids = array(); - foreach ($this->getHelpTopics() as $topic) - $ids[] = $topic->getId(); + foreach ($this->getHelpTopics() as $T) + $ids[] = $T->topic->getId(); return $ids; } function getHelpTopicNames() { $names = array(); - foreach ($this->getHelpTopics() as $topic) - $names[] = $topic->getFullName(); + foreach ($this->getHelpTopics() as $T) + $names[] = $T->topic->getFullName(); return $names; } function getHelpTopics() { - //XXX: change it to obj (when needed)! - - if (!isset($this->topics)) { - $this->topics = Topic::objects()->filter(array( - 'topic_id__in' => FaqTopic::objects()->filter(array( - 'faq_id' => $this->getId(), - ))->values('topic_id'), - )); - } return $this->topics; } @@ -251,14 +238,10 @@ class FAQ extends VerySimpleModel { } } - $sql='DELETE FROM '.FAQ_TOPIC_TABLE.' WHERE faq_id='.db_input($this->getId()); - if($ids) - $sql.=' AND topic_id NOT IN('.implode(',', db_input($ids)).')'; - - if (!db_query($sql)) - return false; - - Signal::send('model.updated', $this); + if ($ids) + $this->topics->filter(Q::not(array('topic_id__in' => $ids)))->delete(); + else + $this->topics->delete(); } function saveTranslations($vars) { @@ -422,11 +405,11 @@ class FAQ extends VerySimpleModel { $this->notes = Format::sanitize($vars['notes']); $this->keywords = ' '; + $this->updateTopics($vars['topics']); + if (!$this->save()) return false; - $this->updateTopics($vars['topics']); - // General attachments (for all languages) // --------------------- // Delete removed attachments. @@ -485,6 +468,7 @@ class FaqTopic extends VerySimpleModel { static $meta = array( 'table' => FAQ_TOPIC_TABLE, 'pk' => array('faq_id', 'topic_id'), + 'select_related' => 'topic', 'joins' => array( 'faq' => array( 'constraint' => array( @@ -499,4 +483,19 @@ class FaqTopic extends VerySimpleModel { ), ); } -?> + +class FaqAccessMgmtForm +extends AbstractForm { + function buildFields() { + return array( + 'ispublished' => new ChoiceField(array( + 'label' => __('Listing Type'), + 'choices' => array( + FAQ::VISIBILITY_PRIVATE => __('Internal'), + FAQ::VISIBILITY_PUBLIC => __('Public'), + FAQ::VISIBILITY_FEATURED => __('Featured'), + ), + )), + ); + } +} diff --git a/include/staff/faq-view.inc.php b/include/staff/faq-view.inc.php index be15f6f7ef2c71c302d68e04fa4a09ee23364106..2fe5159646e8fda535dc6027399ef4bbbd7b9bf7 100644 --- a/include/staff/faq-view.inc.php +++ b/include/staff/faq-view.inc.php @@ -14,12 +14,13 @@ $category=$faq->getCategory(); <div class="pull-right sidebar faq-meta"> <?php if ($attachments = $faq->getLocalAttachments()->all()) { ?> <section> - <strong><?php echo __('Attachments');?>:</strong> + <header><?php echo __('Attachments');?>:</header> <?php foreach ($attachments as $att) { ?> <div> - <a href="<?php echo $att->file->getDownloadUrl(); ?>" class="no-pjax"> - <i class="icon-file"></i> - <?php echo Format::htmlchars($att->file->name); ?> + <i class="icon-paperclip pull-left"></i> + <a target="_blank" href="<?php echo $att->file->getDownloadUrl(); ?>" + class="attachment no-pjax"> + <?php echo Format::htmlchars($att->getFilename()); ?> </a> </div> <?php } ?> @@ -28,9 +29,9 @@ $category=$faq->getCategory(); <?php if ($faq->getHelpTopics()->count()) { ?> <section> - <strong><?php echo __('Help Topics'); ?></strong> -<?php foreach ($faq->getHelpTopics() as $topic) { ?> - <div><?php echo $topic->getFullName(); ?></div> + <header><?php echo __('Help Topics'); ?></header> +<?php foreach ($faq->getHelpTopics() as $T) { ?> + <div><?php echo $T->topic->getFullName(); ?></div> <?php } ?> </section> <?php } ?> @@ -60,7 +61,7 @@ if ($otherLangs) { ?> <div> <strong><?php echo $faq->isPublished()?__('Published'):__('Internal'); ?></strong> </div> -<a href="#"><?php echo __('manage access'); ?></a> +<a data-dialog="ajax.php/kb/faq/<?php echo $faq->getId(); ?>/access" href="#"><?php echo __('manage access'); ?></a> </section> </div> @@ -90,7 +91,7 @@ if ($thisstaff->hasPerm(FAQ::PERM_MANAGE)) { ?> </div> <div class="faded"><?php echo __('Last updated');?> - <?php echo Format::relativeTime(Misc::db2gmtime($category->getUpdateDate())); ?> + <?php echo Format::relativeTime(Misc::db2gmtime($faq->getUpdateDate())); ?> </div> <br/> <div class="thread-body bleed"> @@ -107,7 +108,7 @@ if ($thisstaff->hasPerm(FAQ::PERM_MANAGE)) { ?> <?php csrf_token(); ?> <input type="hidden" name="do" value="manage-faq"> <input type="hidden" name="id" value="<?php echo $faq->getId(); ?>"> - <button name="a" class="button" value="delete"><?php echo __('Delete FAQ'); ?></button> + <button name="a" class="red button" value="delete"><?php echo __('Delete FAQ'); ?></button> </form> <?php } ?> diff --git a/include/staff/staffmembers.inc.php b/include/staff/staffmembers.inc.php index 68fca554cfdb1b4a8adf2471d50c53a436ca5128..0fd390cb7b870fc3883e6f44542b08034f230d89 100644 --- a/include/staff/staffmembers.inc.php +++ b/include/staff/staffmembers.inc.php @@ -185,7 +185,7 @@ $agents->limit($pageNav->getLimit())->offset($pageNav->getStart()); Format::htmlchars((string) $agent->getName()); ?></a></td> <td><?php echo $agent->getUserName(); ?></td> <td><?php echo $agent->isActive() ? __('Active') :'<b>'.__('Locked').'</b>'; ?><?php - echo $agent->onvacation ? '<small>(<i>'.__('vacation').'</i>)</small>' : ''; ?></td> + echo $agent->onvacation ? ' <small>(<i>'.__('vacation').'</i>)</small>' : ''; ?></td> <td><a href="departments.php?id=<?php echo $agent->getDeptId(); ?>"><?php diff --git a/scp/ajax.php b/scp/ajax.php index bdaf0a45483e7548617fd0c3715493f738ba130e..36d9a847a44cf431fdd994fc1c5bd53f57a6c3cf 100644 --- a/scp/ajax.php +++ b/scp/ajax.php @@ -37,7 +37,8 @@ $dispatcher = patterns('', url('^/kb/', patterns('ajax.kbase.php:KbaseAjaxAPI', # Send ticket-id as a query arg => canned-response/33?ticket=83 url_get('^canned-response/(?P<id>\d+).(?P<format>json|txt)', 'cannedResp'), - url_get('^faq/(?P<id>\d+)', 'faq') + url('^faq/(?P<id>\d+)/access', 'manageFaqAccess'), + url_get('^faq/(?P<id>\d+)$', 'faq') )), url('^/content/', patterns('ajax.content.php:ContentAjaxAPI', url_get('^log/(?P<id>\d+)', 'log'), diff --git a/scp/css/scp.css b/scp/css/scp.css index a71a023879270907372cdc8dcdfc36736a3dec66..72c174d07e8c5ed530e8d876b273a2bfe9b34e5d 100644 --- a/scp/css/scp.css +++ b/scp/css/scp.css @@ -349,7 +349,6 @@ a.userPref { background:url(../images/icons/user_preferences.gif) } a.userPasswd { background:url(../images/icons/change_password.gif) } a.preferences { background:url(../images/icons/settings.gif) } -a.attachment { background:url(../images/icons/attachment.gif ) } a.api { background:url(../images/icons/api.png) } a.newapi { background:url(../images/icons/new_api.png) } @@ -2689,3 +2688,11 @@ table.grid.form caption { border-top-left-radius: 3px; border-bottom-left-radius: 3px; } +a.attachment { + padding-left: 1.2em; + display: block; +} +.sidebar section header { + font-weight: bold; + margin-bottom: 0.3em; +}