<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Coyne Technology Systems &#187; WHMCS</title>
	<atom:link href="http://blog.coynetechsystems.com/topics/whmcs/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.coynetechsystems.com</link>
	<description>The Technology Station</description>
	<lastBuildDate>Wed, 21 Sep 2011 16:40:45 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Automatically Creating WHMCS Knowledgebase Sitemaps</title>
		<link>http://blog.coynetechsystems.com/whmcs/automatically-creating-whmcs-knowledgebase-sitemaps-224/</link>
		<comments>http://blog.coynetechsystems.com/whmcs/automatically-creating-whmcs-knowledgebase-sitemaps-224/#comments</comments>
		<pubDate>Wed, 02 Jun 2010 18:42:22 +0000</pubDate>
		<dc:creator>kevin</dc:creator>
				<category><![CDATA[WHMCS]]></category>
		<category><![CDATA[add-on]]></category>
		<category><![CDATA[how-to]]></category>
		<category><![CDATA[knowledgebase]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[script]]></category>
		<category><![CDATA[sitemap]]></category>

		<guid isPermaLink="false">http://www.coynetechsystems.com/blog/?p=224</guid>
		<description><![CDATA[WHMCS is a client management, billing, and support solution and is widely used as the back end system to manage Web Hosting sites. WHMCS includes a built in knowledge base system where the administrator can create categories and articles to support clients in performing common web hosting tasks. In version 4.1.1 of WHMCS, the ability to use [...]]]></description>
			<content:encoded><![CDATA[<p><a title="WHMCS Home Page" href="http://www.whmcs.com/members/aff.php?aff=4861" target="_blank">WHMCS</a> is a client management, billing, and support solution and is widely used as the back end system to manage Web Hosting sites. WHMCS includes a built in knowledge base system where the administrator can create categories and articles to support clients in performing common web hosting tasks. In version 4.1.1 of WHMCS, the ability to use Search Engine Optimized (SEO) file names from the knowledge base (KB) is available. Creating sitemaps for theses were often tedious and error prone since each sitemap entry had to be added manually from the KB article title. This article describes the WHMCS admin add on module to overcome this manual entry and automatically generate the sitemap file from the WHMCS database entries.<span id="more-224"></span></p>
<p>A sitemap file is an XML file that defines the pages that you provide to search engines that you specify the files that are to be indexed in your site.  By using this protocol, you specify the exact pages that want the search engines to find, even though they may be database driven, or difficult to find through deep links on your site.  Sitemap files can be indexes where they contain a list of other sitemap files or sitemap entries containing links to web pages.  More information on the sitemaps protocol can be found at <a title="Sitemaps Home Page" href="http://www.sitemaps.org" target="_blank">sitemaps.org</a>.</p>
<p>This add on reads the knowledge base categories and articles from the WHMCS database tables and generates a list of the SEO titles from those table entries in a sitemap entry file.  It then reads the specified sitemap file, if it exists, and matches up the database table entries with the entries in the sitemap file.  If there are KB categories or articles that are not included in the sitemap file, the WHMCS admin is given the ability to add the articles to the sitemap file.  If the categories and articles are already in the sitemap file, then the WHMCS admin has the ability to update the timestamp in the sitemap file or remove the item from the sitemap file entirely.  The sitemap file can also contain additional static entries that will be listed in a separate table at the bottom of the page.   The WHMCS admin then has the ability to remove or update the timestamps on the static items.</p>
<p>The problem with creating sitemap entries from the WHMCS database is that the KB articles and categories are generated from the database versus stored as files in the file system which would contain timestamps of when the file was last written.  The WHMCS database does not store the time the article or category is updated so there is no way to know when the last update to the article was made.  To overcome this in the add on, the WHMCS admin must manually specify when to update the sitemap lastmod time of the articles by checking the box in the update column and re-generating the sitemap file.</p>
<p>To access this WHMCS module, the admin logs in and selects the Addon Modules menu item under the Utilities Menu.  From there, they are presented with a list of add on modules available.  If the KB Sitemap Generator was installed correctly, the module is listed as Kb Sitemap Gen.  Clicking on this title will access the module, which first must be installed.  To install, select the button that says &#8220;Install&#8221;.  This will create an additional WHMCS database table which will hold the sitemap file name.</p>
<p>Once the add on module is installed, the module presents three general areas of information. 1) WHMCS and Sitemap File information, 2) Table to manage WHMCS KB database data in the sitemap file, and 3) Table to manage static sitemap tables.</p>
<p>The WHMCS and Sitemap File information shows the WHMCS Root Path which is the path WHMCS believes it is installed in.  This URL path will be used to generate the URL in the sitemap file.  The next entry in this area shows the file path that the sitemap file will be created or exists in.  It defaults to the path where WHMCS is installed plus the file name &#8220;kbsitemap.xml&#8221;.  The file name and location can be changed by entering optional additional path information and file name and pressing the &#8220;Set File&#8221; button.  This will cause the add on module to store the new file location in its database table and will be available for future use of the module.  The input box will accept additional path information as well, so the sitemap file could reside in a different location.  For example setting the file to ../kbsitemap.xml will generate a sitemap file one directory higher than the WHMCS install directory.</p>
<p>The &#8220;Files From WHMCS KB Database&#8221; table lists the Type, URL , LastMod, and three check boxes to Add, Update, or Remove the item.  The Type is whether the item is a Category or an Article and each type is displayed with a different color in the table.  The URL is the address that is generated from the WHMCS installed directory plus the knowledge base sub-directory, plus the category or article id from the database, and finally the SEO friendly filename generated from the title or name of the article or category.  The LastMod column is the LastMod time from the sitemap if the item is in the sitemap, otherwise it is empty if it has not been generated.  The three check box columns allow the admin to manage the items in the sitemap file and all changes are made when the user presses the &#8220;Make Changes To Sitemap&#8221; button at the bottom of the admin module.  If the item is already in the sitemap file, the Add check box will be disabled and if the item is not yet in the sitemap file, the Update and Remove check boxes will be disabled.</p>
<p>The following image shows the WHMCS and Sitemap File Information as well as the begining of the table that lists the Files From WHMCS KB database.</p>
<div id="attachment_270" class="wp-caption aligncenter" style="width: 310px"><a href="http://www.coynetechsystems.com/blog/wp-content/uploads/2010/06/KBSMgen_top.jpg"><img class="size-medium wp-image-270" title="KB Sitemap Generator Top Half" src="http://www.coynetechsystems.com/blog/wp-content/uploads/2010/06/KBSMgen_top-300x148.jpg" alt="KB Sitemap Generator Top Half" width="300" height="148" /></a><p class="wp-caption-text">KB Sitemap Generator Top Half</p></div>
<p style="text-align: center;">&nbsp;</p>
<p>In addition to the sitemap information generated from the WHMCS database, this add on module can also manage additional static sitemap file information.  Beneath the Files From WHMCS KB Database area, the add on module will display sitemap entries that are not generated from the WHMCS knowledge base database tables.  These could include static entries or KB article and category that were manually entered and contained spelling or format errors.  The image below shows several entries that were static entries for the affiliates, tutorials, downloads, and announcements pages.  From this table the admin can Update or Remove the items in the sitemap file.</p>
<p>The image below shows the bottom of the WHMCS KB database table items as well as the static sitemap items.</p>
<div id="attachment_271" class="wp-caption aligncenter" style="width: 310px"><a href="http://www.coynetechsystems.com/blog/wp-content/uploads/2010/06/KBSMgen_bottom.jpg"><img class="size-medium wp-image-271" title="KB Sitemap Generator Bottom Half" src="http://www.coynetechsystems.com/blog/wp-content/uploads/2010/06/KBSMgen_bottom-300x207.jpg" alt="KB Sitemap Generator Bottom Half" width="300" height="207" /></a><p class="wp-caption-text">KB Sitemap Generator Bottom Half</p></div>
<p>Now you can add your automatically generated sitemap to a sitemap index file.  For more information on using sitemaps and sitemap index files, click on the <a title="Building A Comprehensive Sitemap for SEO" href="http://www.coynetechsystems.com/blog/web-site/building-a-comprehensive-sitemap-for-seo-160/" target="_self">link to the article &#8221;Building A Comprehensive Sitemap for SEO&#8221; in our blog</a>.</p>
<p>This add on was developed for WHMCS version 4.1.1.   For more information on WHMCS, visit their <a title="WHMCS Home PAge" href="http://www.whmcs.com/members/aff.php?aff=4861" target="_blank">home page</a>.</p>
<p>You can download the script as a zip file for free in <a title="WHMCS Knowledgebase Sitemap Generator" href="http://www.coynetechsystems.com/shop/index.php?main_page=product_info&amp;cPath=4&amp;products_id=9" target="_self">our shop by following this link</a>.  Installation instructions can be found in the text file contained in the zip file.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.coynetechsystems.com/whmcs/automatically-creating-whmcs-knowledgebase-sitemaps-224/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Flagging WHMCS Announcements For Display Outside The Billing System</title>
		<link>http://blog.coynetechsystems.com/whmcs/flagging-whmcs-announcements-for-display-outside-the-billing-system-130/</link>
		<comments>http://blog.coynetechsystems.com/whmcs/flagging-whmcs-announcements-for-display-outside-the-billing-system-130/#comments</comments>
		<pubDate>Mon, 22 Mar 2010 17:24:42 +0000</pubDate>
		<dc:creator>kevin</dc:creator>
				<category><![CDATA[WHMCS]]></category>
		<category><![CDATA[announcements]]></category>
		<category><![CDATA[billing system]]></category>
		<category><![CDATA[database]]></category>
		<category><![CDATA[external]]></category>
		<category><![CDATA[home]]></category>
		<category><![CDATA[MySQL]]></category>
		<category><![CDATA[phpMyAdmin]]></category>

		<guid isPermaLink="false">http://www.coynetechsystems.com/blog/?p=130</guid>
		<description><![CDATA[WHMCS is a client management and billing support system primarily used as the back-end system for managing web hosting websites. Among other things, WHMCS includes the ability to send announcements to clients as messages in the hosting area, RSS feeds, or emails. Many articles have been written on how to include the announcements into custom [...]]]></description>
			<content:encoded><![CDATA[<p><a title="WHMCS Home Page" href="http://www.whmcs.com/members/aff.php?aff=4861" target="_blank">WHMCS</a> is a client management and billing support system primarily used as the back-end system for managing web hosting websites. Among other things, WHMCS includes the ability to send announcements to clients as messages in the hosting area, RSS feeds, or emails. Many articles have been written on how to include the announcements into custom developed webpages outside of the WHMCS billing system such as including them in a static home page for the site. In some cases you may wish to send an announcement about a potential change or upgrade that you would want to send to your clients, but may not be appropriate for your home page. This article will explain what is needed to selectively display announcements on the home page and create a WHMCS add-on module to allow control over which announcements are displayed on the external page.<span id="more-130"></span></p>
<p>The WHMCS system consists of code written in the <a title="PHP Language Home Page" href="http://www.php.net" target="_blank">PHP language </a>with a <a title="MySQL Home Page" href="http://www.mysql.com" target="_blank">MySQL</a> database backend. The PHP code is obscured from viewing by a tool called Ioncube however the database is freely viewable and editable using standard MySQL tools such as <a title="phpMyAdmin Home Page" href="http://www.phpmyadmin.net" target="_blank">phpMyAdmin</a>. Normally the obscured code would cause a problem in creating modifications to databases and using the data, but the developers of WHMCS had the forethought to include the ability to create add-on modules within the WHMCS system. An add-on module is simply some PHP code that can be written and is called by the WHMCS system to display the information that the add-on provides.  Any information that needs to be displayed by the add-on module can be displayed within the WHMCS administration panels and can interact with the WHMCS database to retrieve and store information.</p>
<p>The add-on discussed in this article will add an additonal column to the WHMCS announcement table and create the code to interact with the column data.  When this add-on is installed, it is available in WHMCS under the &#8216;Utilities&#8217; tab and selecting the &#8216;Addon Modules&#8217; menu item.</p>
<p>Normally the PHP code to get the announcements from the database and show them on the home page looks something like this:<br />
<code><br />
$result = mysql_query("SELECT * FROM tblannouncements WHERE published='on' ORDER BY id DESC LIMIT 3");<br />
if (mysql_num_rows($result) == 0) {<br />
echo '&lt;p&gt;There are no new announcements.&lt;/p&gt;';<br />
} else {<br />
while($data = mysql_fetch_array ($result))<br />
{<br />
$id = $data['id'];<br />
$date = $data['date'];<br />
$announcement = $data['announcement'];<br />
$title = $data['title'];<br />
$date = formatdate($date);<br />
echo'&lt;div&gt;&lt;span&gt;'.$date.' - '.$title.' &lt;a href="/hosting/announcements.php?id='.$id.'"&gt;&lt;img src="/images/more.gif" width="30" height="15" alt="Display More News Detail" /&gt;&lt;/a&gt;&lt;/span&gt;&lt;/div&gt;';<br />
echo'&lt;img align="middle" src="/images/news_sep.gif" alt="" width="237" height="2" /&gt;';<br />
}<br />
echo'&lt;div&gt;&lt;span&gt;News &amp;amp; announcements: &lt;a href="/hosting/announcements.php"&gt;view more&lt;/a&gt;&lt;/span&gt;&lt;/div&gt;';<br />
}<br />
</code></p>
<p>This code will query the WHMCS database (connecting to the database not shown) and get all of the announcements from the &#8216;tblannoucements&#8217; table.  It loops through each returned row and prints out the data from each row in HTML format to be displayed on the page.  Now let&#8217;s add our customization to the mix.<br />
The first thing to do when creating the add-on is to BACKUP THE DATABASE!  This module will make modifications to the structure of the database and table data. Any incorrect code has the ability to wipe out the WHMCS tables or data, so you have been warned.</p>
<p>This WHMCS add-on has 4 overall stages:</p>
<ol>
<li>Pre-install</li>
<li>Install</li>
<li>Operational</li>
<li>Uninstall</li>
</ol>
<p>The WHMCS add-on system will check to see if the add-on is installed. If it is not, we are in the Pre-install stage. Our add-on will install an addtional column to the WHMCS MySQL announcement table, so the check to see if is installed will consists of querying the database for our column in the table:<br />
<code>if(!mysql_num_rows(mysql_query("SHOW COLUMNS FROM tblannouncements LIKE 'show_frontpage'")))</code></p>
<p>This simply asks the database to see if there are any columns named show_frontpage and if there is nothing returned, we complete the Pre-install stage. In the Pre-install stage, we show some HTML code to tell the user the add-on is not installed and display a button for them to click on to install the add-on:<br />
<code><br />
if(!$_GET['install']){<br />
echo '&lt;h1&gt;Not Yet Installed&lt;/h1&gt;<br />
&lt;p&gt;This add-on defines an additional field for the announcements table for display on external pages such as the home page.&lt;/p&gt;<br />
&lt;p&gt;To install it, click on the button below.&lt;/p&gt;<br />
&lt;p&gt;&lt;input type="button" value="Install Homepage Annoucements" onclick="window.location=\''.$modulelink.'&amp;install=true\'"&gt;&lt;/p&gt;';<br />
}<br />
</code><br />
This section of code is inclosed in a conditional block that checks the parameters passed to the page to determine if the user pressed the install button or not. If the install parameter is not set, the user has not requested installation of the add-on yet. The button has an onclick handler for the install button that when clicked, sends us back to this page with the install $_GET parameter set to true which will execute the else conditional block.  The $modulelink PHP variable is a pre-defined WHMCS name for our add-on.   Once this code is executed, when we return to this page, we will be in the Install stage and perform the the actual installation of the add-on which is defined by these lines:<br />
<code><br />
} else {<br />
// request install, create the table and send us back to this file<br />
$query = "ALTER TABLE tblannouncements ADD `show_frontpage` BOOL NOT NULL DEFAULT 0";<br />
$result=mysql_query($query);<br />
header("Location: $modulelink");<br />
exit;<br />
}<br />
</code><br />
This code creates a MySQL query string and sends it to the MySQL database. The query creates a column called show_frontpage in the existing WHMCS table tblannouncements.  This field is a BOOL field that cannot be null and has a default of zero when new items are added to the table.  Once the query is executed, the header function sends us back to this file with no install parameter set. When we test if the column exists after running this code, it will be true, and we will continue on to the Operational phase.</p>
<p>The Operational phase is where we perform any work we want to do with the add-on. There are three conditional blocks within the Operational phase. The second which we will talk about first is where there are no POST variables passed to the add-on. In this case, we simply display a table with all of the announcements listed and a check box next to them that is filled in with the yes-no value on whether to display the announcement on the front page. We get this information by getting all the information out of the announcements table and loop through each row returned printing the data out to the client.  This is done whether we complete the first conditional block or not.</p>
<div><code><br />
// show the table of announcements and the checkboxes for whether to show them on the home page<br />
echo '<br />
&lt;form method="post" action="'.$modulelink.'"&gt;<br />
&lt;div&gt;<br />
&lt;table width="100%" border="0" cellspacing="1" cellpadding="3"&gt;<br />
&lt;tr&gt;&lt;th&gt;ID&lt;/th&gt;&lt;th&gt;Date&lt;/th&gt;&lt;th&gt;Announcement Title&lt;/th&gt;&lt;th&gt;Show in Homepage&lt;/th&gt;&lt;/tr&gt;<br />
';<br />
$query = "SELECT * FROM tblannouncements WHERE `published`='on'";<br />
$result=mysql_query($query);<br />
if(!$result) {<br />
die("Unable to execute query ".$sql."\n".mysql_error()."\n".mysql_errno()."\n");<br />
}<br />
if(mysql_num_rows($result) &gt; 0) {<br />
while($data = mysql_fetch_array($result)) {<br />
$id = $data["id"];<br />
$date = $data["date"];<br />
$title= $data["title"];<br />
$announce_id = $data["announcements_id"];<br />
if(isset($data["show_frontpage"]) &amp;&amp; ($data["show_frontpage"] == 1)) {<br />
$show = " checked";<br />
} else {<br />
$show = "";<br />
}<br />
echo "&lt;tr&gt;&lt;td&gt;".$id."&lt;/td&gt;&lt;td&gt;".$date."&lt;/td&gt;&lt;td&gt;".$title."&lt;/td&gt;&lt;td&gt;&lt;input type=checkbox name=announcements_id[] value='".$id."'".$show."&gt;&lt;/td&gt;&lt;/tr&gt;\n";<br />
}<br />
} else {<br />
echo "&lt;tr&gt;&lt;td colspan='3' align='center'&gt;No Announcements Found&lt;/td&gt;&lt;/tr&gt;";<br />
}<br />
echo "<br />
&lt;/table&gt;<br />
&lt;/div&gt;<br />
&lt;p align='center'&gt;&lt;input type='submit' value='Save Changes'&gt;&lt;/p&gt;<br />
&lt;p align='left'&gt;&lt;input type='button' value='Uninstall' onclick='window.location=\"".$modulelink."&amp;uninstall=true\"'&gt;&lt;/p&gt;<br />
&lt;/form&gt;<br />
";</code></div>
<p>The first conditional block that we skipped over temporarily, is when the user makes changes to the check boxes to change the display of the annoucement. In this case there will be a $_POST variable called announcements_id with values that will be fill in to the show_frontpage column that is passed to the script. When this variable has data, the first thing we do is to go to the tblannouncments table and set each show_frontpage column value to zero.  This is because the array that is passed back to us in the $_POST variable does not include unset values, only set values, so we cannot determine which ones were set before showing the page, so we just quickly clear them all.  Next we loop through each returned checkbox array item and set the show_frontpage values to one where the user had selected values in the check boxes.  This is the code that performs these actions:<br />
<code><br />
// the table already exists in the database, get the values from the $_POST var if any<br />
if ($_POST["announcements_id"]) {<br />
$upquery = "UPDATE tblannouncements SET show_frontpage=0";<br />
$result = mysql_query($upquery);<br />
$announcements_id = sanitize($_POST["announcements_id"]);<br />
// create a query to update values in the column based on the passed parameters<br />
while (list($key,$val) = @each ($announcements_id)) {<br />
$newquery = "UPDATE tblannouncements SET show_frontpage=1 WHERE id=".$val;<br />
$result=mysql_query($newquery);<br />
}<br />
}<br />
</code><br />
Now lets go back to our original code that displays the announcments in the home page and make the changes.  The only change necessary is how we select the items out of the database.  Using this new show_frontpage column we simply change the filter to only get the the results that have that column set:<br />
<code><br />
$result = mysql_query("SELECT * FROM tblannouncements<span style="color: #003300;"> <span style="color: #800000;">WHERE show_frontpage=1</span></span> ORDER BY id DESC LIMIT 3");<br />
</code><br />
Now we can selectively display announcements in pages that are outside the WHMCS billing system.</p>
<p><a title="WHMCS Homepage Announcements Download" href="http://www.coynetechsystems.com/shop/index.php?main_page=product_info&amp;cPath=4&amp;products_id=6">The full source code for this article can be found in a zip file in our shop by following this link.</a></p>
<p>To install from the zip file, create a directory in the &lt;WHMCS&gt;/modules/admin/ directory called &#8216;homepage_announcements&#8217; without the quotes and place the PHP file in this directory.  Log into your WHMCS and select &#8216;Addon Modules&#8217; from the &#8216;Utilities&#8217; Menu and you should see a item titled &#8216;Homepage Announcements&#8217;.  Clicking on that will allow the module to be installed.</p>
<p>Note that this script was built and tested to work with WHMCS version 4.1.1.  Any upgrades or changes to the WHMCS version may overwrite the changes here.  Ensure you backup your database before you install upgrades to WHMCS.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.coynetechsystems.com/whmcs/flagging-whmcs-announcements-for-display-outside-the-billing-system-130/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Creating a WHMCS Knowledgebase Report</title>
		<link>http://blog.coynetechsystems.com/whmcs/creating-a-whmcs-knowledgebase-report-197/</link>
		<comments>http://blog.coynetechsystems.com/whmcs/creating-a-whmcs-knowledgebase-report-197/#comments</comments>
		<pubDate>Wed, 06 Jan 2010 16:51:53 +0000</pubDate>
		<dc:creator>kevin</dc:creator>
				<category><![CDATA[WHMCS]]></category>
		<category><![CDATA[custom report]]></category>
		<category><![CDATA[knowledgebase]]></category>
		<category><![CDATA[report]]></category>
		<category><![CDATA[usage]]></category>

		<guid isPermaLink="false">http://www.coynetechsystems.com/blog/?p=197</guid>
		<description><![CDATA[WHMCS is a client management, billing, and support solution and is widely used as the back end system to manage Web Hosting sites. WHMCS includes a built in knowledgebase system where the administrator can create articles to support clients in performing common topics. Since the knowledgebase is the first area of support for the users, [...]]]></description>
			<content:encoded><![CDATA[<p><a title="WHMCS Home Page" href="http://www.whmcs.com/members/aff.php?aff=4861" target="_blank">WHMCS </a>is a client management, billing, and support solution and is widely used as the back end system to manage Web Hosting sites. WHMCS includes a built in knowledgebase system where the administrator can create articles to support clients in performing common topics. Since the knowledgebase is the first area of support for the users, It would be helpful to have a report on the knowledgebase articles to see the most used articles. This article walks through creating a custom report to show the most used articles in the knowledgebase.<span id="more-197"></span></p>
<p>WHMCS has a quick and easy way to generate reports as add-ons to the core WHMCS functionality. They are implemented by creating a PHP script file and setting some predefined variables within the script. Uploading the file to the correct directory installs the file to be used in the WHMCS admin area. The hardest part is getting the correct data out of the WHMCS database for use.</p>
<p>The requirement for this report was to display the top 20 articles from the knowledgebase along with their category and the additional information that is stored for articles (number of votes cast, number of people that found it useful, and whether it is a private article only visible to logged in clients).<br />
Start by creating a empty PHP file and giving it a useful file name. For this report we named this file knowledgebase_usage.php. We then copied the contents of the <a href="http://wiki.whmcs.com/Reports">sample given under the documentation for the WHMCS reports</a> into the empty file and fill in the obvious information for the description, header text, and footer text.</p>
<p>Next, we needed to determine what fields we would like to display for each article and the titles for them. Looking at the WHMCS database structure with a <a href="http://www.phpmyadmin.net">database tool such as phpMyAdmin</a>, the categories are stored in a separate table from the articles and are linked with a link table, so we will have to join these tables to get all of the information about the articles.</p>
<p>The articles table stores the number of views, the total number of votes on whether the user found it useful, the number of those votes that found it useful , and whether the article is for private clients only. We will display each of these values in our report.</p>
<p>Now that we have this information we can create the table headings. Back in the knowledgebase_usage.php, we create the array for the headings:</p>
<p><code>$reportdata["tableheadings"] = array("Category","Title","Views","Stats","Is Private");</code></p>
<p>We also have the information to create our SQL query statement. We have to select the title,views, useful, votes, and private columns from the tblknowledgebase table and the name column from the tblknowledgebasecats table and join them through the tblknowedgebaselinks table. Also we want to sort them by the most views and only show the top 20 articles. Our SQL statement looks like this:</p>
<p><code>SELECT `title`, `views`, `useful`, `votes`, `private`, `name` FROM `tblknowledgebase` LEFT JOIN `tblknowledgebaselinks` on `tblknowledgebase`.`id`=`tblknowledgebaselinks`.`articleid` LEFT JOIN `tblknowledgebasecats` on `tblknowledgebaselinks`.`categoryid`=`tblknowledgebasecats`.`id` ORDER BY `views` DESC, name LIMIT 0,20</code></p>
<p>We execute the query and for each row that is returned, extract the data, perform some formatting and put the values we want displayed into the existing report data variable:</p>
<p><code>$result=mysql_query($query);<br />
while($data = mysql_fetch_array($result)) {<br />
$category = $data["name"];<br />
$title = $data["title"];<br />
$views = $data["views"];<br />
$useful = $data["useful"];<br />
$votes = $data["votes"];<br />
$stats = $useful." (".$votes.")";<br />
$private = $data["private"];<br />
$reportdata["tablevalues"][] = array($category,$title,$views,$stats,$private);<br />
}</code></p>
<p>Upload this file to the WHMCS/modules/reports directory and the report will appear when logged in to the admin area and clicking on the reports tab. The name of the report on the Reports page will be the file name with underscores turned into spaces and each word capitalized so for this report it will take knowledgebase_usage.php and title it ‘Knowledgebase Usage’ in the Report list.</p>
<p>The source code for this report is free and can be found as a <a href="http://www.coynetechsystems.com/shop/index.php?main_page=product_info&amp;cPath=4&amp;products_id=3">downloadable zip file product in our shop</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.coynetechsystems.com/whmcs/creating-a-whmcs-knowledgebase-report-197/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

