Beispiel #1
0
function KB_reporta()
{
    global $smcFunc, $scripturl, $user_info, $txt, $kbname, $context;
    $context['sub_template'] = 'kb_reporta';
    isAllowedTo('rparticle_kb');
    $request = $smcFunc['db_query']('', '
		SELECT title
		FROM {db_prefix}kb_articles		    
		WHERE kbnid = {int:aid}', array('aid' => (int) $_REQUEST['aid']));
    list($kbname) = $smcFunc['db_fetch_row']($request);
    $smcFunc['db_free_result']($request);
    $context['linktree'][] = array('url' => $scripturl . '?action=kb;area=reporta;aid=' . $_GET['aid'] . '', 'name' => $txt['kb_reports22'] . ' - ' . $kbname);
    if (isset($_REQUEST['save'])) {
        if (empty($_POST['description'])) {
            fatal_error($txt['kb_pls_enter_com'], false);
        }
        if (empty($_GET['aid'])) {
            fatal_error($txt['kb_ratenosel'], false);
        }
        $_POST['description'] = $smcFunc['htmlspecialchars']($_POST['description'], ENT_QUOTES);
        $_GET['aid'] = (int) $_GET['aid'];
        $mes = '' . $txt['kb_log_text13'] . '  <strong><a href="' . $scripturl . '?action=kb;area=article;cont=' . $_GET['aid'] . '">' . $kbname . '</a></strong>';
        KB_log_actions('add_report', $_GET['aid'], $mes);
        $data = array('table' => 'kb_reports', 'cols' => array('id_article' => 'int', 'id_member' => 'int', 'comment' => 'string', 'date' => 'int'));
        $values = array($_GET['aid'], $user_info['id'], $_POST['description'], time());
        $indexes = array();
        KB_InsertData($data, $values, $indexes);
        KB_cleanCache();
        redirectexit('action=kb;area=article;cont=' . $_GET['aid'] . ';reported');
    }
}
Beispiel #2
0
function KB_catadd()
{
    global $txt, $smcFunc, $scripturl, $user_info, $context;
    isAllowedTo('manage_kb');
    $context['sub_template'] = 'kb_catadd';
    $context['linktree'][] = array('url' => $scripturl . '?action=kb;area=catadd', 'name' => $txt['knowledgebasecatadd']);
    if ($context['user']['is_guest']) {
        $groupid = -1;
    } else {
        $groupid = $user_info['groups'][0];
    }
    $result = $smcFunc['db_query']('', '
	    SELECT c.kbid, c.name, p.view, c.name, c.id_parent
	    FROM {db_prefix}kb_category AS c
		LEFT JOIN {db_prefix}kb_catperm AS p ON (p.id_group = {int:groupid} AND c.kbid = p.id_cat)', array('groupid' => $groupid));
    $context['knowcat'] = array();
    while ($row = $smcFunc['db_fetch_assoc']($result)) {
        $context['knowcat'][] = $row;
    }
    $smcFunc['db_free_result']($result);
    KB_PrettyCategory();
    if (isset($_GET['save'])) {
        checkSession();
        $_POST['title'] = $smcFunc['htmlspecialchars']($_POST['title'], ENT_QUOTES);
        $_POST['description'] = $smcFunc['htmlspecialchars']($_POST['description'], ENT_QUOTES);
        $_POST['image'] = $smcFunc['htmlspecialchars']($_POST['image'], ENT_QUOTES);
        if (empty($_POST['title'])) {
            fatal_lang_error('knowledgebase_emtytitle', false);
        }
        if (empty($_POST['image'])) {
            $_POST['image'] = '';
        }
        if (isset($_POST['cat'])) {
            $context['kb_parent'] = (int) $_POST['cat'];
        } else {
            $context['kb_parent'] = 0;
        }
        $data = array('table' => 'kb_category', 'cols' => array('name' => 'string', 'description' => 'string', 'id_parent' => 'int', 'image' => 'string'));
        $values = array($_POST['title'], $_POST['description'], $context['kb_parent'], $_POST['image']);
        $indexes = array();
        KB_InsertData($data, $values, $indexes);
        KBrecountItems();
        KB_cleanCache();
        $mes = '' . $txt['kb_log_text9'] . ' <strong>' . $_POST['title'] . '</strong>';
        KB_log_actions('add_cat', 0, $mes);
        redirectexit('action=kb;area=catadd;added');
    }
}
Beispiel #3
0
function KB_perm()
{
    global $context, $txt, $cname, $scripturl, $smcFunc;
    $context['sub_template'] = 'kb_perm';
    isAllowedTo('manage_kb');
    if (!isset($_GET['save'])) {
        // Load the membergroups
        $dbresult = $smcFunc['db_query']('', "\n\t        SELECT id_group, group_name \n\t        FROM {db_prefix}membergroups \n\t        WHERE min_posts = -1 ORDER BY group_name");
        while ($row = $smcFunc['db_fetch_assoc']($dbresult)) {
            $context['groups'][$row['id_group']] = array('ID_GROUP' => $row['id_group'], 'group_name' => $row['group_name']);
        }
        $smcFunc['db_free_result']($dbresult);
        $request = $smcFunc['db_query']('', '
		    SELECT name
		    FROM {db_prefix}kb_category
		    WHERE kbid = {int:perm}', array('perm' => (int) $_GET['perm']));
        list($cname) = $smcFunc['db_fetch_row']($request);
        $smcFunc['db_free_result']($request);
        $context['linktree'][] = array('url' => $scripturl . '?action=kb;area=permcat;perm=' . $_GET['perm'] . '', 'name' => '' . $txt['kb_catperm7'] . '  - ' . $cname . '');
        // membergroup
        $dbresult = $smcFunc['db_query']('', "\n\t        SELECT c.id_cat, c.id, c.editanyarticle, c.delarticle, c.delanyarticle, c.editarticle, c.addarticle, c.view, c.id_group, m.group_name\n\t        FROM {db_prefix}kb_catperm as c \n\t\t    LEFT JOIN {db_prefix}membergroups AS m ON (m.id_group = c.id_group)\n\t\t    LEFT JOIN {db_prefix}kb_category AS a ON (a.kbid = c.id_cat)\n\t        WHERE  c.id_cat = {int:perm} AND m.id_group = c.id_group AND a.kbid = c.id_cat", array('perm' => (int) $_GET['perm']));
        $context['kb_membergroup'] = array();
        while ($row = $smcFunc['db_fetch_assoc']($dbresult)) {
            $context['kb_membergroup'][] = $row;
        }
        $smcFunc['db_free_result']($dbresult);
        // Guests
        $dbresult = $smcFunc['db_query']('', "\n\t        SELECT c.id_cat, c.id, c.editanyarticle, c.delarticle, c.delanyarticle, c.editarticle, c.addarticle, c.view, c.id_group \n\t        FROM {db_prefix}kb_catperm as c \n\t\t    LEFT JOIN {db_prefix}kb_category AS a ON (a.kbid = c.id_cat)\n\t        WHERE c.id_cat = {int:perm} AND c.id_group = -1 AND a.kbid = c.id_cat LIMIT 1", array('perm' => (int) $_GET['perm']));
        $context['kb_guest'] = array();
        while ($row = $smcFunc['db_fetch_assoc']($dbresult)) {
            $context['kb_guest'][] = $row;
        }
        $smcFunc['db_free_result']($dbresult);
        //Regular members
        $dbresult = $smcFunc['db_query']('', "\n\t        SELECT c.id_cat, c.id, c.addarticle, c.delarticle, c.delanyarticle, c.editarticle, c.editanyarticle, c.view, c.id_group \n\t        FROM {db_prefix}kb_catperm as c \n\t\t    LEFT JOIN {db_prefix}kb_category AS a ON (a.kbid = c.id_cat)\n\t        WHERE c.id_cat = {int:perm} AND c.id_group = 0 AND a.kbid = c.id_cat LIMIT 1", array('perm' => (int) $_GET['perm']));
        $context['reg_reggroup'] = array();
        while ($row = $smcFunc['db_fetch_assoc']($dbresult)) {
            $context['reg_reggroup'][] = $row;
        }
        $smcFunc['db_free_result']($dbresult);
    }
    if (isset($_GET['save'])) {
        checkSession();
        $groupname = (int) $_REQUEST['groupname'];
        $cat = (int) $_REQUEST['save'];
        $view = isset($_REQUEST['view']) ? 1 : 0;
        $addarticle = isset($_REQUEST['addarticle']) ? 1 : 0;
        $editanyarticle = isset($_REQUEST['editanyarticle']) ? 1 : 0;
        $editarticle = isset($_REQUEST['editarticle']) ? 1 : 0;
        $delarticle = isset($_REQUEST['delarticle']) ? 1 : 0;
        $delanyarticle = isset($_REQUEST['delanyarticle']) ? 1 : 0;
        $request = $smcFunc['db_query']('', '
		    SELECT kbid,name
            FROM {db_prefix}kb_category
		    WHERE kbid = {int:kbid}
            LIMIT 1', array('kbid' => $cat));
        list($nameid, $title) = $smcFunc['db_fetch_row']($request);
        $smcFunc['db_free_result']($request);
        $mes = '' . $txt['kb_log_text12'] . '  <strong><a href="' . $scripturl . '?action=kb;area=cats;cat=' . $nameid . '">' . $title . '</a></strong>';
        KB_log_actions('perm_cat', $nameid, $mes);
        // No point in given the add article permission if they cant view the category
        if ($view == 0) {
            $addarticle = 0;
        }
        if ($view == 0 && $addarticle == 1) {
            $addarticle = 0;
        }
        // Check if permission exits
        $dbresult = $smcFunc['db_query']('', "\n\t        SELECT id_group,id_cat \n\t        FROM {db_prefix}kb_catperm \n\t        WHERE id_group = {int:ig} AND id_cat = {int:ccat}", array('ig' => $groupname, 'ccat' => $cat));
        if ($smcFunc['db_affected_rows']() != 0) {
            $smcFunc['db_free_result']($dbresult);
            $query_params = array('table' => 'kb_catperm', 'set' => 'id_group = {int:ig},id_cat = {int:ccat},view = {int:view},addarticle = {int:addarticle},editanyarticle = {int:editanyarticle},editarticle = {int:editarticle},delarticle = {int:delarticle},delanyarticle = {int:delanyarticle}', 'where' => 'id_cat = {int:ccat} AND id_group = {int:ig}');
            $query_data = array('view' => (int) $view, 'ig' => $groupname, 'ccat' => (int) $cat, 'addarticle' => (int) $addarticle, 'editanyarticle' => (int) $editanyarticle, 'editarticle' => (int) $editarticle, 'delarticle' => (int) $delarticle, 'delanyarticle' => (int) $delanyarticle);
            kb_UpdateData($query_params, $query_data);
            KB_cleanCache();
            redirectexit('action=kb;area=permcat;perm=' . $cat . '');
        } else {
            // Insert into database
            $data = array('table' => 'kb_catperm', 'cols' => array('id_group' => 'int', 'id_cat' => 'int', 'view' => 'int', 'addarticle' => 'int', 'editanyarticle' => 'int', 'editarticle' => 'int', 'delarticle' => 'int', 'delanyarticle' => 'int'));
            $values = array($groupname, $cat, $view, $addarticle, $editanyarticle, $editarticle, $delarticle, $delanyarticle);
            $indexes = array();
            KB_InsertData($data, $values, $indexes);
            KB_cleanCache();
            redirectexit('action=kb;area=permcat;perm=' . $cat . '');
        }
    }
}
Beispiel #4
0
function KB_knowcont()
{
    global $smcFunc, $txt, $scripturl, $sourcedir, $boardurl, $modSettings, $user_info, $context;
    $context['sub_template'] = 'kb_knowcont';
    if (isset($_REQUEST['cont'])) {
        if (($listData = cache_get_data('kb_articles_listinfo' . $_GET['cont'] . '', 3600)) === null) {
            $params = array('table' => 'kb_articles AS a', 'call' => 'a.title,a.kbnid,a.id_cat,c.name', 'left_join' => '{db_prefix}kb_category AS c ON (a.id_cat = c.kbid)', 'where' => 'a.kbnid = {int:kbnid}');
            $data = array('kbnid' => (int) $_GET['cont']);
            $listData = KB_ListData($params, $data);
            cache_put_data('kb_articles_listinfo' . $_GET['cont'] . '', $listData, 3600);
        }
        $artname = $listData['title'];
        $aid = $listData['kbnid'];
        $cid = $listData['id_cat'];
        $cname = $listData['name'];
        if (!$aid) {
            fatal_error('' . $txt['kb_pinfi7'] . ' <strong>' . $_GET['cont'] . '</strong> ' . $txt['kb_jumpgo1'] . '', false);
        }
        $context['linktree'][] = array('url' => $scripturl . '?action=kb;area=cats;cat=' . $cid . '', 'name' => $cname);
        $context['linktree'][] = array('url' => $scripturl . '?action=kb;area=article;cont=' . $_GET['cont'] . '', 'name' => $artname);
        if (($context['know'] = cache_get_data('kb_articles' . $_GET['cont'] . '', 3600)) === null) {
            $result = $smcFunc['db_query']('', '
	            SELECT k.kbnid,k.content, k.source, k.title,k.id_cat,k.date,k.id_member,m.real_name, k.views, k.rate, k.approved
	            FROM {db_prefix}kb_articles AS k
		        LEFT JOIN {db_prefix}members AS m ON (k.id_member = m.id_member)
		        LEFT JOIN {db_prefix}attachments AS a ON (a.id_member = m.id_member)
	            WHERE kbnid = {int:kbnid}', array('kbnid' => (int) $_GET['cont']));
            $context['know'] = array();
            while ($row = $smcFunc['db_fetch_assoc']($result)) {
                $context['know'][] = array('content' => KB_parseTags($row['content'], $row['kbnid'], 3), 'title' => parse_bbc($row['title']), 'source' => parse_bbc($row['source']), 'kbnid' => $row['kbnid'], 'approved' => $row['approved'], 'views' => $row['views'], 'rate' => $row['rate'], 'date' => date('D d M Y', $row['date']), 'id_cat' => $row['id_cat'], 'id_member' => $row['id_member'], 'real_name' => $row['real_name']);
            }
            $smcFunc['db_free_result']($result);
            cache_put_data('kb_articles' . $_GET['cont'] . '', $context['know'], 3600);
        }
        $context['page_title'] = $context['know'][0]['title'];
        if ($context['know'][0]['approved'] == 0 && $context['know'][0]['id_member'] != $user_info['id'] && !allowedTo('manage_kb')) {
            fatal_lang_error('kb_articlwnot_approved', false);
        }
        KBisAllowedto($context['know'][0]['id_cat'], 'view');
        $context['kbimg'] = KB_getimages($_GET['cont']);
        if (!empty($modSettings['kb_ecom'])) {
            $context['kbcom'] = KB_getcomments($_GET['cont']);
            KB_showediter(!empty($_POST['description']) ? $_POST['description'] : '', 'description');
        }
        KB_dojprint();
        $query_params = array('table' => 'kb_articles', 'set' => 'views = views + 1', 'where' => 'kbnid = {int:kbnid}');
        $query_data = array('kbnid' => (int) $_GET['cont']);
        kb_UpdateData($query_params, $query_data);
    }
    if ($user_info['is_guest']) {
        require_once $sourcedir . '/Subs-Editor.php';
        $verificationOptions = array('id' => 'register');
        $context['visual_verification'] = create_control_verification($verificationOptions);
        $context['visual_verification_id'] = $verificationOptions['id'];
    }
    //comment
    if (isset($_REQUEST['comment'])) {
        if ($user_info['is_guest']) {
            require_once $sourcedir . '/Subs-Editor.php';
            $verificationOptions = array('id' => 'register');
            $context['visual_verification'] = create_control_verification($verificationOptions, true);
            if (is_array($context['visual_verification'])) {
                loadLanguage('Errors');
                foreach ($context['visual_verification'] as $error) {
                    fatal_error($txt['error_' . $error]);
                }
            }
        }
        isAllowedTo('com_kb');
        checkSession();
        $_POST['description'] = $smcFunc['htmlspecialchars']($_POST['description'], ENT_QUOTES);
        $_GET['arid'] = (int) $_GET['arid'];
        if (empty($_POST['description'])) {
            fatal_lang_error('knowledgebase_emtydesc', false);
        }
        $approved = allowedTo('auto_approvecom_kb') ? 1 : 0;
        $mes = '' . $txt['kb_log_text4'] . ' <strong><a href="' . $scripturl . '?action=kb;area=article;cont=' . $_GET['arid'] . '">' . $context['know'][0]['title'] . '</a></strong>';
        KB_log_actions('add_com', $_GET['arid'], $mes);
        $data = array('table' => 'kb_comments', 'cols' => array('id_article' => 'int', 'comment' => 'string', 'date' => 'int', 'id_member' => 'int', 'approved' => 'int'));
        $values = array($_GET['arid'], $_POST['description'], time(), $user_info['id'], $approved);
        $indexes = array('id_article');
        KB_InsertData($data, $values, $indexes);
        KBrecountcomments();
        KB_cleanCache();
        redirectexit('action=kb;area=article;cont=' . $_GET['arid'] . '');
    }
    if (isset($_REQUEST['commentdel'])) {
        isAllowedTo('comdel_kb');
        $mes = '' . $txt['kb_log_text3'] . ' <strong><a href="' . $scripturl . '?action=kb;area=article;cont=' . $_GET['cont'] . '">' . $context['know'][0]['title'] . '</a></strong>';
        KB_log_actions('del_com', $_GET['cont'], $mes);
        $query_params = array('table' => 'kb_comments', 'where' => 'id = {int:kbid}');
        $query_data = array('kbid' => (int) $_GET['arid']);
        KB_DeleteData($query_params, $query_data);
        KB_cleanCache();
        KBrecountcomments();
        redirectexit('action=kb;area=article;cont=' . $_GET['cont'] . '');
    }
    //approve
    if (isset($_REQUEST['approve'])) {
        checkSession('get');
        $query_params = array('table' => 'kb_articles', 'set' => 'approved = {int:one}', 'where' => 'kbnid = {int:kbnid}');
        $query_data = array('kbnid' => (int) $_REQUEST['aid'], 'one' => 1);
        kb_UpdateData($query_params, $query_data);
        $params = array('table' => 'kb_articles', 'call' => 'id_member, kbnid, title', 'where' => 'kbnid = {int:kbnid}');
        $data = array('kbnid' => (int) $_GET['aid']);
        $listData = KB_ListData($params, $data);
        $nameid = $listData['id_member'];
        $kid = $listData['kbnid'];
        $title = $listData['title'];
        $kbmes = '' . $txt['kb_aapprove1'] . ' [url=' . $scripturl . '?action=kb;area=article;cont=' . $kid . ']' . $txt['kb_aapprove2'] . '[/url] ' . $txt['kb_aapprove3'] . '';
        KB_sendpm($nameid, $txt['kb_aapprove6'], $kbmes);
        $mes = '' . $txt['kb_log_text2'] . ' <strong><a href="' . $scripturl . '?action=kb;area=article;cont=' . $kid . '">' . $title . '</a></strong>';
        KB_log_actions('app_article', $kid, $mes);
        KBrecountItems();
        KB_cleanCache();
        redirectexit('action=kb;area=article;cont=' . $_REQUEST['aid'] . '');
    }
    //unapprove
    if (isset($_REQUEST['unapprove']) && isset($_REQUEST['inap'])) {
        checkSession('get');
        $query_params = array('table' => 'kb_articles', 'set' => 'approved = {int:one}', 'where' => 'kbnid = {int:kbnid}');
        $query_data = array('kbnid' => (int) $_REQUEST['inap'], 'one' => 0);
        kb_UpdateData($query_params, $query_data);
        $params = array('table' => 'kb_articles', 'call' => 'id_member, kbnid, title', 'where' => 'kbnid = {int:kbnid}');
        $data = array('kbnid' => (int) $_GET['inap']);
        $listData = KB_ListData($params, $data);
        $nameid = $listData['id_member'];
        $kid = $listData['kbnid'];
        $title = $listData['title'];
        $kbmes = '' . $txt['kb_aapprove4'] . ' [url=' . $scripturl . '?action=kb;area=article;cont=' . $kid . ']' . $txt['kb_aapprove2'] . '[/url] ' . $txt['kb_aapprove3'] . '';
        KB_sendpm($nameid, $txt['kb_aapprove7'], $kbmes);
        $mes = '' . $txt['kb_log_text1'] . ' <strong><a href="' . $scripturl . '?action=kb;area=article;cont=' . $kid . '">' . $title . '</a></strong>';
        KB_log_actions('unapp_article', $kid, $mes);
        KBrecountItems();
        KB_cleanCache();
        redirectexit('action=kb;area=article;cont=' . $_REQUEST['inap'] . '');
    }
}
Beispiel #5
0
function KB_log_actions($action, $article_id, $reason)
{
    global $user_info, $modSettings, $smcFunc;
    if (empty($modSettings['kb_disable_log'])) {
        return;
    }
    $logoption = array('add_article' => 'kb_add_article', 'add_cat' => 'kb_add_cat', 'del_article' => 'kb_del_article', 'edit_cat' => 'kb_edit_cat', 'edit_article' => 'kb_edit_article', 'app_com' => 'kb_app_com', 'app_article' => 'kb_app_article', 'unapp_article' => 'kb_unapp_article', 'perm_cat' => 'kb_perm_cat', 'del_cat' => 'kb_del_cat', 'del_com' => 'kb_del_com', 'add_com' => 'kb_add_com', 'add_report' => 'kb_add_report', 'del_report' => 'kb_del_report');
    if (empty($logoption[$action]) || empty($modSettings[$logoption[$action]])) {
        return;
    }
    $data = array('table' => 'kb_log_actions', 'cols' => array('action' => 'string', 'article_id' => 'int', 'user_id' => 'int', 'reason' => 'string', 'time' => 'int', 'user_ip' => 'string'));
    $values = array($action, $article_id, $user_info['id'], $reason, time(), $user_info['ip']);
    $indexes = array();
    KB_InsertData($data, $values, $indexes);
}
Beispiel #6
0
function KB_rate()
{
    global $txt, $smcFunc, $user_info;
    $id = !empty($_REQUEST['kbnid']) ? (int) $_REQUEST['kbnid'] : 0;
    if (empty($id)) {
        fatal_lang_error('kb_ratenosel', false);
    }
    isAllowedTo('rate_kb');
    checkSession('get');
    $dbresult = $smcFunc['db_query']('', '
	    SELECT id_article, id_member
	    FROM {db_prefix}kb_rating
	    WHERE id_member = {int:member} AND id_article = {int:art}', array('art' => $id, 'member' => $user_info['id']));
    if ($smcFunc['db_affected_rows']() != 0) {
        fatal_lang_error('kb_rateoneonly', false);
    }
    $smcFunc['db_free_result']($dbresult);
    $value = !empty($_REQUEST['value']) ? (int) $_REQUEST['value'] : 0;
    if ($value == 0) {
        $data = array('table' => 'kb_rating', 'cols' => array('id_article' => 'int', 'id_member' => 'int', 'value' => 'int'));
        $values = array($id, $user_info['id'], 0);
        $indexes = array();
        KB_InsertData($data, $values, $indexes);
        $query_params = array('table' => 'kb_articles', 'set' => 'rate = rate - {int:one}', 'where' => 'kbnid = {int:kbnid}');
        $query_data = array('kbnid' => $id, 'one' => 1);
        kb_UpdateData($query_params, $query_data);
        $request = $smcFunc['db_query']('', '
		    SELECT rate
	        FROM {db_prefix}kb_articles
	        WHERE kbnid = {int:kbnid}', array('kbnid' => $id));
        list($quantity) = $smcFunc['db_fetch_row']($request);
        $smcFunc['db_free_result']($request);
        if ($quantity < 0) {
            $query_params1 = array('table' => 'kb_articles', 'set' => 'rate = {int:one}', 'where' => 'kbnid = {int:kbnid}');
            $query_data1 = array('kbnid' => $id, 'one' => 0);
            kb_UpdateData($query_params1, $query_data1);
        }
        KB_cleanCache();
    } else {
        $data = array('table' => 'kb_rating', 'cols' => array('id_article' => 'int', 'id_member' => 'int', 'value' => 'int'));
        $values = array($id, $user_info['id'], 1);
        $indexes = array();
        KB_InsertData($data, $values, $indexes);
        $query_params2 = array('table' => 'kb_articles', 'set' => 'rate = rate + {int:one}', 'where' => 'kbnid = {int:kbnid}');
        $query_data2 = array('kbnid' => $id, 'one' => 1);
        kb_UpdateData($query_params2, $query_data2);
        KB_cleanCache();
    }
    redirectexit('action=kb;area=article;cont=' . $id . '');
}