~sit-developers/sit/master

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
<?php
// kb.php - Browse knowledge base articles
//
// SiT (Support Incident Tracker) - Support call tracking system
// Copyright (C) 2010-2014 The Support Incident Tracker Project
// Copyright (C) 2000-2009 Salford Software Ltd. and Contributors
//
// This software may be used and distributed according to the terms
// of the GNU General Public License, incorporated herein by reference.
//
// Authors: Ivan Lucas, Tom Gerrard

// This Page Is Valid XHTML 1.0 Transitional!  1Nov05

require ('core.php');
$permission = PERM_KB_VIEW; // View KB
require (APPLICATION_LIBPATH . 'functions.inc.php');

// This page requires authentication
require (APPLICATION_LIBPATH . 'auth.inc.php');

// External variables
$search_string = cleanvar($_REQUEST['search_string']);
$mode = cleanvar($_REQUEST['mode']);

$title = $strBrowseKB;
$rssfeedurl = "kb_rss.php?c=".md5($_SESSION['username'] . md5($CONFIG['db_password']));
$rssfeedtitle = "{$strKnowledgeBase}: {$strRecent}";
include (APPLICATION_INCPATH . 'htmlheader.inc.php');
if (empty($mode) && empty($search_string)) $mode = 'RECENT';
if (empty($search_string) AND empty($mode)) $search_string = 'a';
echo "<h2>".icon('kb', 32, $title)." ";
echo "{$title}</h2>";
plugin_do('kb');
if (strtolower($mode) == 'recent') echo "<h4>{$strArticlesPublishedRecently}</h4>";
elseif (strtolower($mode) == 'today') echo "<h4>{$strArticlesPublishedToday}</h4>";

echo "<form action='{$_SERVER['PHP_SELF']}' method='get'>";
echo "<table summary='alphamenu' class='maintable'>";
echo "<tr><td align='center'>";
echo "<input type='text' name='search_string' /><input type='submit' value=\"{$strGo}\" />";
echo "</td></tr>";
echo "<tr><td class='alphamenu'>";
echo "<a href='{$_SERVER['PHP_SELF']}?mode=RECENT'>{$strRecent}</a>";
echo alpha_index("{$_SERVER['PHP_SELF']}?search_string=");
echo " | <a href='kb_article.php'>{$strNew}</a>";
echo "</td></tr>";
echo "</table>";
echo "</form>";
echo "<br />";

// ---------------------------------------------
// SQL Queries:

if (mb_strlen(utf8_decode($search_string)) > 4)
{
    // Find Software
    $sql = "SELECT * FROM `{$dbSoftware}` WHERE name LIKE '%{$search_string}%' LIMIT 20";
    $result = mysql_query($sql);
    if (mysql_error()) trigger_error("MySQL Query Error ".mysql_error(), E_USER_WARNING);
    echo "<p align='center'><strong>{$strSkills}</strong>: ";
    $softcount = mysql_num_rows($result);
    $count = 1;
    $colcount = 1;
    while ($software = mysql_fetch_object($result))
    {
        echo "{$software->name}";
        if ($count<$softcount) echo ", ";
        if ($colcount >= 4)
        {
            $colcount = 0;
            echo "<br />";
        }
        $count++; $colcount++;
    }
    echo "</p>\n";
}
// Find Articles
$sql = "SELECT * FROM `{$dbKBArticles}` ";
if (strtolower($mode) == 'myarticles') $sql .= "WHERE author='{$sit[2]}' ";
if (!empty($search_string) AND $search_string != '*')
{
    $sql .= "WHERE ";
    $search_string_len = mb_strlen($search_string);
    if (is_numeric($search_string))
    {
        $sql .= "docid=('{$search_string}') ";
    }
    elseif (mb_strtoupper(mb_substr($search_string, 0, mb_strlen($CONFIG['kb_id_prefix']))) == mb_strtoupper($CONFIG['kb_id_prefix']))
    {
        $sql .= "docid='" . mb_substr($search_string, mb_strlen($CONFIG['kb_id_prefix']))."' ";
    }
    elseif ($search_string_len<=2)
    {
        $sql .= "SUBSTRING(title,1,$search_string_len)=('{$search_string}') ";
    }
    else
    {
        $sql .= "title LIKE '%{$search_string}%' OR keywords LIKE '%{$search_string}%' ";
    }
}
if (strtolower($mode) == 'recent') $sql .= "ORDER BY docid DESC LIMIT 20";

if (strtolower($mode) == 'today') $sql .= " WHERE published > '".date('Y-m-d')."' ORDER BY published DESC";

$result = mysql_query($sql);
if (mysql_error()) trigger_error("MySQL Query Error ".mysql_error(), E_USER_WARNING);

if (mysql_num_rows($result) >= 1)
{
    echo "<p align='center'><strong>{$strResults}</strong> :</p>";
    echo "<table align='center' width='98%'>";
    echo "<tr>";
    echo colheader('id',$strID, FALSE);
    echo colheader('title', $strTitle, FALSE);
    echo colheader('date', $strDate, FALSE);
    echo colheader('author', $strAuthor, FALSE);
    echo colheader('keywords',$strKeywords, FALSE);
    echo "</tr>\n";
    $shade = 'shade1';
    while ($kbarticle = mysql_fetch_object($result))
    {
        if (empty($kbarticle->title)) $kbarticle->title = $strUntitled;
        else $kbarticle->title = $kbarticle->title;

        if (is_numeric($kbarticle->author))
        {
            $kbarticle->author = user_realname($kbarticle->author);
        }
        else
        {
            $kbarticle->author = $kbarticle->author;
        }
        echo "<tr class='{$shade}'>";
        echo "<td>".icon('kb', 16)." {$CONFIG['kb_id_prefix']}".leading_zero(4,$kbarticle->docid)."</td>";
        echo "<td>";
        // Lookup what software this applies to
        $ssql = "SELECT * FROM `{$dbKBSoftware}` AS kbs, `{$dbSoftware}` AS s WHERE kbs.softwareid = s.id ";
        $ssql .= "AND kbs.docid = '{$kbarticle->docid}' ORDER BY s.name";
        $sresult = mysql_query($ssql);
        if (mysql_error()) trigger_error("MySQL Query Error ".mysql_error(), E_USER_WARNING);
        $rowcount = mysql_num_rows($sresult);
        if ($rowcount >= 1 AND $rowcount < 3)
        {
            $count = 1;
            while ($kbsoftware = mysql_fetch_object($sresult))
            {
                echo $kbsoftware->name;
                if ($count < $rowcount) echo ", ";
                $count++;
            }
        }
        elseif ($rowcount >= 4)
        {
            echo "Various";
        }
        echo "<br /><a href='kb_view_article.php?id={$kbarticle->docid}' class='info'>{$kbarticle->title}";
        $asql = "SELECT LEFT(content,400) FROM `{$dbKBContent}` WHERE docid='{$kbarticle->docid}' ORDER BY id ASC LIMIT 1";
        $aresult = mysql_query($asql);
        if (mysql_error()) trigger_error("MySQL Query Error ".mysql_error(), E_USER_WARNING);
        list($content) = mysql_fetch_row($aresult);
        $content = strip_tags(remove_slashes($content));
        echo "<span>{$content}</span>";
        echo "</a>";
        echo "</td>";
        echo "<td>".ldate($CONFIG['dateformat_date'], mysql2date($kbarticle->published))."</td>";
        echo "<td>".user_realname($kbarticle->author)."</td>";
        echo "<td>{$kbarticle->keywords}</td>";
        echo "</tr>\n";
        if ($shade == 'shade1') $shade = 'shade2';
        else $shade = 'shade1';
    }
    echo "</table>\n";
}
else
{
    echo "<p align='center'>{$strNoResults}</p>";
}

echo "<p align='center'><a href='kb_article.php'>{$strNew}</a></p>";

include (APPLICATION_INCPATH . 'htmlfooter.inc.php');

?>