This product was discontinued on July 1st 2012, however all existing customers will continue to receive support as per their maintenance agreement. Learn more.

Interspire Knowledge Manager Customization Guide

Chapter1.Introduction

Welcome

Thank you for purchasing Interspire Knowledge Manager - The fastest, smartest way to start and manage your own FAQ and knowledge base system.

Interspire Knowledge Manager is the only solution you need if you're looking to launch your own customizable knowledge base in an extremely short amount of time. From its extensible customization options to its simple content creation process, Interspire Knowledge Manager leads the way in knowledge base authoring for everyone... regardless of technical ability.

Interspire Knowledge Manager can be set up and ready to go in less than 5 minutes or extended and customised to suit your specific needs. To get started setting up Interspire Knowledge Manager on your server read the installation guide. This guide will help you once you have Interspire Knowledge Manager installed and wish to customise it to suit your needs.

License and Legal Disclaimer

Copyright 2008 Interspire Knowledge Manager and BigCommerce Pty Ltd (referred to as BigCommerce from here on in) - All Rights Reserved. THIS COPYRIGHT INFORMATION MUST REMAIN INTACT AND MAY NOT BE MODIFIED IN ANY WAY.

When you purchased this software you agreed to accept the terms of this Agreement. This Agreement is a legal contract, which specifies the terms of the license and warranty limitation between you and 'BigCommerce'. You should carefully read the following terms and conditions before installing or using this software. Unless you have a different license agreement obtained from 'BigCommerce', installation or use of this software indicates your acceptance of the license and warranty limitation terms contained in this Agreement. If you do not agree to the terms of this Agreement, promptly delete and destroy all copies of the Software.

Versions of the Software: Only one licensed copy of Interspire Knowledge Manager may be used on one web site.

License to Redistribute: Distributing the software and/or documentation with other products (commercial or otherwise) by any means without prior written permission from 'BigCommerce' is forbidden. All rights to the Interspire Knowledge Manager software and documentation not expressly granted under this Agreement are reserved to 'BigCommerce'.

Disclaimer of Warranty: THIS SOFTWARE AND ACCOMPANYING DOCUMENTATION ARE PROVIDED "AS IS" AND WITHOUT WARRANTIES AS TO PERFORMANCE OF MERCHANTABILITY OR ANY OTHER WARRANTIES WHETHER EXPRESSED OR IMPLIED. BECAUSE OF THE VARIOUS HARDWARE AND SOFTWARE ENVIRONMENTS INTO WHICH Interspire Knowledge Manager MAY BE USED, NO WARRANTY OF FITNESS FOR A PARTICULAR PURPOSE IS OFFERED. THE USER MUST ASSUME THE ENTIRE RISK OF USING THIS PROGRAM. ANY LIABILITY OF 'BigCommerce' WILL BE LIMITED EXCLUSIVELY TO PRODUCT REPLACEMENT OR REFUND OF PURCHASE PRICE. IN NO CASE SHALL 'BigCommerce' BE LIABLE FOR ANY INCIDENTAL, SPECIAL OR CONSEQUENTIAL DAMAGES OR LOSS, INCLUDING, WITHOUT LIMITATION, LOST PROFITS OR THE INABILITY TO USE EQUIPMENT OR ACCESS DATA, WHETHER SUCH DAMAGES ARE BASED UPON A BREACH OF EXPRESS OR IMPLIED WARRANTIES, BREACH OF CONTRACT, NEGLIGENCE, STRICT TORT, OR ANY OTHER LEGAL THEORY. THIS IS TRUE EVEN IF 'BigCommerce' IS ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. IN NO CASE WILL 'Interpire' OR LIABILITY EXCEED THE AMOUNT OF THE LICENSE FEE ACTUALLY PAID BY LICENSEE TO 'BigCommerce'.

Warning: This program is protected by copyright law. Unauthorized reproduction or distribution of this program, or any portion of it, may result in severe civil and criminal penalties, and will be prosecuted to the maximum extent possible under the law.

Chapter2.Customisation

Introduction

Interspire Knowledge Manager uses an innovative templating system, which allows you to choose from a list of templates, rearrange your content, edit the style of your site, and edit or create your own panels, which -- like the panels provided -- can be placed anywhere on your site.

The Interspire Knowledge Manager release package contains a number of built-in templates that you are free to use. It is simple to install additional templates. The site templates are located in the /templates/ directory of the Interspire Knowledge Manager application. A template with the name CVS will not be selectable from the settings page so avoid using this name for your template.

A number of elements make up the Interspire Knowledge Manager templates. These are explained below:

  • Layout Files - HTML template files are used to design the layout of each page. The files consist of HTML with place holders to indicate where the content will be rendered. Different types of content include panels, page data, and config data.

  • Panels - Panels contain PHP code to render static or dynamic content, or to perform a specific task. They are positioned on your pages by the HTML template files. Panels may contain other panels, however you want to be careful to limit the depth of including panels or the performance of your site will suffer. Panels are kept in the Interspire Knowledge Manager/templates/<TemplateName>/Panels directory.

  • Images - Each template has its own images to match. These are kept in the Interspire Knowledge Manager/templates/<TemplateName>/Images/ directory.

  • Snippets - Snippets are fragments of html which are usually used multiple times. They may be things like a <ol> tag or a table row. Depending on the snippet they may also have placeholders in them. Snippets are kept in the Interspire Knowledge Manager/templates/<TemplateName>/Snippets directory.

  • Style Sheets - Style sheets are used to help with the layout of each page and to apply the theme, including fonts, colors, sizes, etc.

  • Misc Files - The Interspire Knowledge Manager templates each require a preview file called Preview.jpg. This image is located in the Interspire Knowledge Manager/templates/<TemplateName>/ directory. It can be viewed when selecting a template in the installer or on the settings page. Javascript files are kept in the Interspire Knowledge Manager/templates/<TemplateName/js directory (for the supplied templates).

Layout, Panel and Snippet files may contain placeholders for dynamically generated content. The name and description of each type of placeholder is given here.

  • Global variables - Allows you to define a variable in PHP's global scope to be output as part of a panel. For example, if you had this code in your ParsePanel function: $GLOBALS["Test"] = "testing"; Then you would add this place holder into your panels HTML file to output its value: %%GLOBAL_Test%%

  • Page data - At this time only the %%Page.Title%% variable is available in Interspire Knowledge Manager

  • Config data - The following variables are available

    • %%Config.ImagePath%% - The path to the Images directory for the current templates

    • %%Config.HomePath%% - The path to the Interspire Knowledge Manager installation

    • %%Config.Current.KnowledgebaseUrl%% - The path to the Interspire Knowledge Manager installation (the same as %%Config.HomePath%%, left in for compatability reasons)

    • %%Config.KnowledgebaseName%% - The name of the knowledge base

  • Language data - Allows you to insert a language constant into your panel. Language variables are defined in the /includes/language/front_language.ini file. To output an already defined language variable, you would add this placeholder to your HTML panel file: %%LNG_hpPopularArticles%%

  • Snippet data - If you want to include snippet placeholders in your code, you must define the entry in the $GLOBALS['SNIPPETS'] associative array for the placeholder. You can then use the value of that entry by using %%SNIPPET_Name%% where Name is the key in the associative array for the data you want.

  • Panel Files - Defined by using %%Panel.PanelName%% where PanelName is the name of the panel in the templates/<TemplateName/Panels directory without the file extension.

  • External Files - Defined by using %%Include.Path%% where Path is the path to the file you want to include. Path may be a local filesystem path such as /var/www/mywebsite/header.php or it may be a remote file specified with the full http://www.example.com/dir/file.html address. It can also refer to a file in the panels folder of the template.

    Local files may have PHP in them which will get executed, however any remote files (ones included with http://) that include PHP will not have the PHP code parsed. In both cases any placeholders in the file which are available to panels will be replaced.

Layout Files

Layout Files are responsible for starting the template initialization process. Layout files in Interspire Knowledge Manager don't contain any content, instead they contain placeholders indicating where other types of content should go.

The types of placeholders that can be used in a layout file are

  • Panel

  • Page data

  • Config data

  • Global data

  • Language data

Layout files themselves can not be included inside of anything else.

Panels

Panels are made up of HTML and PHP to render that HTML. Panels can interact with the objects in the Interspire Knowledge Manager framework.

Each panel may have a PHP file in the display directory with the same name where you would setup any custom placeholders. So for PageFooter.html you would create a file named PageFooter.php in the display directory with the contents (to start with) of

<?php

AKB_PAGEFOOTER extends AKB_PANEL
{

function SetPanelSettings()
{
}
}

?>

The name of the class is the uppercase version of the file name with AKB_ prepended to the start and any instances of the word panel replaced with _PANEL. The class function that gets called is always SetPanelSettings inside of the panel's class, however this may call other functions inside or outside of the class to get whatever information you wish to display in the panel.

The types of placeholders that can be used in a panel file are:

  • Panel

  • Global data

  • Language data

Panel files can be included in:

  • Layout Files

  • Panel Files

Snippets

The types of placeholders that can be used in a snippet file are:

  • Page data

  • Config data

  • Global data

  • Language data

Panel files can be include in:

  • Layout Files

  • Panel Files

Style Sheets

Style Sheet Files

Style sheets are used to help with the layout of each page and to apply the theme, including fonts, colors, sizes, etc. Each template contains 2 style sheets, located in the templates/<TemplateName>/Styles directory.

  • Styles.css - General styles used on the pages of your site.

  • WindowStyles.css - Styles used on all pop-up windows, such as 'Print Article'.

The Windows template contains 2 additional stylesheets relating to it's tree panel.

  • tab.css - Styles for the look and feel of the tab layout of the left panel

  • xtree.css - Styles relating to the look and feel of the javascript tree used for navigation

Container Styles

A couple of common container styles include (note, they aren't necessarily part of every template)

  • GlobalContainer - This style is typically applied to a <div> tag wrapped around the entire page immediately inside the <form> tags.

  • PageContainer - This style is typically applied to a <table> tag that defines the position of the page header, page body, and page footer.

  • HeaderContainer - This style is typically applied to a <td> tag inside the PageContainer that helps position the page header.

  • BodyContainer - This style is typically applied to a <td> tag inside the PageContainer that helps position the body of your page.

  • FooterContainer - This style is typically applied to a <td> tag inside the PageContainer that helps position the page footer.

Body Styles (Columns) The page body is typically divided into columns. These are cells of a table with the class "BodyColumns". The classes are:

  • BodyColumns - The style typically applied to the <table> tag that defines the body columns.

  • LeftColumn - The style typically applied to the leftmost <td> tag inside the BodyColumns table.

  • CentreColumn - The style typically applied to the centre <td> tag inside the BodyColumns table.

  • RightColumn - The style typically applied to the rightmost <td> tag inside the BodyColumns table.

The column styles can be adjusted to change background colors, borders, spacing, even the styles of child content.

Panel Styles

Note: The following instructions may not apply to all templates and are simple a rough guide based on the built-in templates.

Each panel has the class of 'Panel', as well a panel specific class, which is usually the name of the panel. You can edit the design of the panel by opening the Styles.css file and searching for the class name (ie. the name of the panel). If it doesn't exist, then you can create the class yourself.

To edit styles that are applied to all panels or panels in a specific area, you can use the 'Panel' class. You'll notice that the headings in the centre column are declared using .CentreColumn .Heading rather than .CentreColumn .Panel .Heading. This format is for simplicity, however both methods have the same effect. Form Styles The forms are broken down into the following styles:

  • FieldLabel - The style of all form field labels.

  • Field400 - The style of a field that is 400px wide.

These width specific styles are used on forms with a uniformed field width.

  • FieldFull - The style of a field that is 100% wide.

  • Field - The style of any other field

  • FormButton - The style of all form submit and cancel buttons

Applying a Template

There are two places where you can select a template to apply to your site: in the installer and on the settings page in the control panel. When selecting a template you will see the preview image:

To view a larger preview, click the 'Click to Enlarge' link. This will bring up a new window containing the full size preview image. To select a template, simply select the template in the drop down list and then click on the form submit button.

Custom Templates

It's not difficult to set up your own totally customizable template and control its look, feel, and even behavior, of your site. There are two ways to get started: You can either create a new directory in the /templates/ directory of the Interspire Knowledge Manager application and use the instructions below to create all of the files, or you can copy an existing template and place it into the /templates/ directory then use the instructions below to make the changes you want.

Just follow the steps below to set up your template: Note: The default HTML forms already exists.

  1. Panels - Panels are the content displayed on your site. You'll need to add these first or there won't be anything to display.

  2. HTML Template Files - HTML template files are used to specify the layout of each page. Start by adding these to your template. See HTML Template Files for more.

  3. Style Sheets - Style sheets are used to help with the layout of each page and to apply fonts, colors, sizes, etc. Now add these to your template. See Style Sheets for more.

  4. Images - Each template typically has its own collection of images. You'll need to add these to the templates/<TemplateName>/Images/ directory.

  5. Preview Image - Each template needs a preview image. Once your template is set up, take a screenshot of it and save it to the templates/<TemplateName>/Preview.jpg file.

Thinking Ahead

The most important thing to take into consideration before starting any customisation is how you should make customisations in a way that will allow you to upgrade Interspire Knowledge Manager when a new version is released, without losing your changes. The best way to do this is to create your own template.

The reason that creating your own template is the best way to avoid your changes being overwritten is that when you get the new version, updating becomes a simple matter of uploading all the files (except the config.php one of course) over the top of your exisiting installation.

To start with, try out each of the included templates and then choose the one which most closely mirrors your needs. If you are unsure which to choose, the Default template uses css to create it's layout as well as it's look and feel so that should be a pretty good starting point.

Once you've chosen the template you're going to base your customised version on, make a copy of it and give it a name, such as "MyTemplate". This can be almost anything you want, but you must follow these guidelines:

  • It can not be named CVS. The code on the settings page explicitly hides this directory to make things a little nicer on us during development.

  • It must only contain the standard english characters (a-z, A-Z, 0-9, _ - or +).

Your custom template

Now that you have your own template, what's next? Well, the way most people get started with customising their template is to make changes to the style sheet. Say for example we decided that the Default template was what we were going to base our custom template off of, however we want our design to stretch out to fill the whole browser window. What we would do is edit the Styles.css for our custom template (in the Styles directory) and change the two instances of width: 750px; to width: 100%; to make the contents stretch to fill the whole window. For more details on how to get started with style sheets, there is a guide at Webmonkey that can help you get started.

Language Packs

Interspire Knowledge Manager is completely language packed and all language variables are stored in PHP INI files. The language variables for the front end of Interspire Knowledge Manager are stored in the /includes/language/front_language.ini file, whereas the language variables for the control panel are stored in the /includes/language/back_language.ini file. If you'd like to convert your site to a language other than English, you can simply edit these 2 language files to change the variables as needed. Also, if you notice a language placeholder in the panel files that you want to change, follow these steps:

  1. Add your new language variable into the language file.

  2. Edit the panel file, which is located in templates/{Template Name}/panels and add a place holder for the language variable. A language variable place holder looks like this: %%LNG_{Language_Variable_Name}%% For example: %%LNG_myTest%%

Chapter3.Integration

Active Response System

Interspire Knowledge Manager has a built-in contact system that your knowledgebase visitors can use to send questions/comments. This can optionally be disabled from the control panel by unchecking the "Enable Contact Page" option.

Also, you can choose how to receive your visitors questions/comments: via email, or via email and having them saved as pending questions in your Interspire Knowledge Manager control panel. If you are not familiar with the Active Response System, please click here.

The power of Interspire Knowledge Manager's Active Response System lies in the ability to add it to any page on your web site. Follow the steps below to add Interspire Knowledge Manager's Active Response System to any page on your web site. For our example, we will create a simple form with a text box.

  • Create a new web page. Let's call it ars_test.html

  • In the <head> section of the page, add these lines:

    Example3.1.Example code required in head of file to enable ARS

    <script type="text/javascript">var akbPath = '[PATH_TO_KB]';</script>
    
    <script type="text/javascript" src="[PATH_TO_KB]/javascript/ars.js"></script>
    <link rel="stylesheet" type="text/css" href="[PATH_TO_KB]/templates/Classic/Styles.css">
    

    Replace [PATH_TO_KB] with the complete path to the directory where you have Interspire Knowledge Manager installed, such as http://www.mywebsite.com/Interspire Knowledge Manager -- Do not include any trailing slashes.

    Note

    Your form and Interspire Knowledge Manager MUST be the same domain otherwise the ARS system won't work because of the browsers security settings.

  • Next, we'll create a text box. When you type anything into this text box, Interspire Knowledge Manager's Active Response System will use JavaScript and client-side XML to retrieve a list of questions in your knowledgebase that match what is typed. Add this text box to your page:

    Example3.2.Example code required to enable ARS in a text box

    <textarea name="Message" id="Message" class="Field300" rows="8" onkeyup="ARS(this.id); "></textarea>
    
    <div id="SearchResults"></div>
  • Example3.2.5.Optional Example code to limit the ARS to a particular category [Active KB NX2.6+ Only]

    As of Interspire Knowledge Manager NX2.6, it's possible to specify a select box of categories to narrow down search results.

    To do this create a select box with an id of 'categories' and add the categories that you wish to search on. The value attribute of each category must match up with the category name from your Interspire Knowledge Manager database. Note that a blank value in the select box will search on all categories.

    <select id="categories">
    <option value="">No Category</option>
    <option value="Product Updates">Product Updates</option>
    
    <option value="Registration">Registration</option>
    </select>
    
  • Here's an example using a copy of Interspire Knowledge Manager NX2 setup on Interspire.com. Note that this works on all modern web browsers, including Mozilla:

  • Alternatively, if you didn't want to include the whole Interspire Knowledge Manager style sheet in the page with your text area, you could remove the line that references the stylesheet.

    Example3.3.Line To remove to not include the Interspire Knowledge Manager style sheet

    <link rel="stylesheet" type="text/css" href="[PATH_TO_KB]/templates/Classic/Styles.css">

    Example3.4.Example styles to format the look of the ARS popup

    <style type="text/css">
    .FieldInfo
    {
        width: 400px;
        padding: 10px;
        background-color: #FFFFE7;
        border: solid 1px #CACACA;
        overflow: auto;
        font: normal 12px Verdana;
    }
    .FieldInfo li
    {
        margin-bottom: 15px;
    }
    .CloseIcon
    {
        float: right;
        cursor: pointer;
    }
    
    </style>

Using the API

Introduction

Interspire Knowledge Manager uses an API (or Application Programming Interface) for its data creation, deletion and updating. The files for this API are in the Interspire Knowledge Manager/lib/api directory. The file class.api.php is the parent class which is inherited by each sub class and handles all data orientated tasks. Child classes are responsible for defining things like the table names to store data, which fields are valid and how to check if they are valid or not.

Creating

If you wanted to create a category programmatically, you would define the values you wanted to create in the $_POST PHP super global variable and then create a new API_CATEGORY class and call it's create() function, like this:

Example3.5.Creating a category programmatically

<?php

$_POST['name'] = 'My Test Category';
$_POST['description'] = 'A test category created programmatically';
$_POST['parentid'] = 0;   // A parentid of 0 is a top level category
$_POST['pass'] = '';      // Don't put a password on this category
$_POST['icon'] = '1.gif'; // We'll just use the default icon

// The init file handles all the things like connecting to the database and including our API files
require_once('/path/to/Interspire Knowledge Manager/init.php');

// We need to include the language file in case the API gives us an error
$GLOBALS['AKB_LANG'] = parse_ini_file('/path/to/Interspire Knowledge Manager/includes/language/front_language.ini');

$c = new API_CATEGORY();

$newid = $c->create();

if ($newid > 0) {
    echo "Category created successfully<br />\n";
} else {
    echo "There was a problem creating the category, reason: ".$c->error."<br />\n";
}

?>

Example3.6.Creating a comment programmatically

<?php

$_POST['questionid'] = 130; // Id of the question the comment is to be associated with
$_POST['name']       = 'Joe Bloggs'; // Name of the commenter
$_POST['email']      = 'joe@example.com';   // Email of the person commenting
$_POST['comment']    = 'Creating comments programmatically is fun !'; // The users comment
$_POST['status']     = 'pending'; // Can be pending, approved or disapproved

// The init file handles all the things like connecting to the database and including our API files
require_once('/path/to/Interspire Knowledge Manager/init.php');

// We need to include the language file in case the API gives us an error
$GLOBALS['AKB_LANG'] = parse_ini_file('/path/to/Interspire Knowledge Manager/includes/language/front_language.ini');

$c = new API_COMMENT();

$newid = $c->create();

if ($newid > 0) {
    echo "Comment created successfully<br />\n";
} else {
    echo "There was a problem creating the comment, reason: ".$c->error."<br />\n";
}

?>

Example3.7.Creating a glossary term programmatically

<?php

$_POST['word']        = 'programmatically'; // The glossary term
$_POST['description'] = 'Using programming to accomplish a task.'; // The definition of the word

// The init file handles all the things like connecting to the database and including our API files
require_once('/path/to/Interspire Knowledge Manager/init.php');

// We need to include the language file in case the API gives us an error
$GLOBALS['AKB_LANG'] = parse_ini_file('/path/to/Interspire Knowledge Manager/includes/language/front_language.ini');

$g = new API_GLOSSARY();

$newid = $g->create();

if ($newid > 0) {
    echo "Glossary term created successfully<br />\n";
} else {
    echo "There was a problem creating the glossary term, reason: ".$g->error."<br />\n";
}

?>

Example3.8.Creating a group programmatically

<?php

// The init file handles all the things like connecting to the database and including our API files
require_once('/path/to/Interspire Knowledge Manager/init.php');

// We need to include the language file in case the API gives us an error
$GLOBALS['AKB_LANG'] = parse_ini_file('/path/to/Interspire Knowledge Manager/includes/language/front_language.ini');

$g = new API_GROUP();

$_POST['name']        = 'Sales and support'; // The name of the group
$_POST['contactable'] = 1; // Optional, display the group on the contact page (0 = default, no, 1 = yes)

// Set the group permissions to their defaults
$g->perms   = $g->defaultPerms;
$g->applies = $g->defaultApplies;

$g->perms['question']['create'] = true; // Allow users in this group to create questions,
                                        // Refer to the lib/api/class.group.php file for the other permissions you can set

$newid = $g->create();

if ($newid > 0) {
    echo "Group created successfully<br />\n";
} else {
    echo "There was a problem creating the group, reason: ".$g->error."<br />\n";
}

?>

Example3.9.Creating a question programmatically

<?php

$_POST['title']            = 'My dynamically created question'; // The title of the question
$_POST['answer']           = '<b>Hooray</b> we have added a question !'; // The answer to the question
$_POST['related']          = '1,3,5,7,9'; // Command seperated list of related question ids
$_POST['detectrelated']    = 0; // Should we detect related questions or use those specified (0 = use specified, 1 = auto detect)
$_POST['visible']          = 1; // Is the question visible or not (0 = hidden, 1 = visible)
$_POST['userid']           = 1; // The user id of the person who created the question
$_POST['views']            = 0; // How many times has this question been viewed
$_POST['posvotes']         = 0; // Number of positive votes
$_POST['negvotes']         = 0; // Number of negative votes
$_POST['score']            = 0; // Score for ranking
$_POST['emailed']          = 0; // Counter of how many times this question has been emailed to a friend
$_POST['sortorder']        = 0; // Search results are ordered by sortorder before their name
$_POST['metakeywords']     = 'dynamic, question, generated'; // Keywords for the meta tags
$_POST['metadescription']  = 'Dynamically created question'; // Description for the meta tags

$_POST['lastupdated'] = '2006-10-26 11:00:00'; // Lastupdated is optional - if you don't specify it the current time will be used


// The init file handles all the things like connecting to the database and including our API files
require_once('/path/to/Interspire Knowledge Manager/init.php');

// We need to include the language file in case the API gives us an error
$GLOBALS['AKB_LANG'] = parse_ini_file('/path/to/Interspire Knowledge Manager/includes/language/front_language.ini');

$q = new API_QUESTION();

$newid = $q->create();

if ($newid > 0) {
    echo "Question created successfully<br />\n";
} else {
    echo "There was a problem creating the question, reason: ".$q->error."<br />\n";
}

?>

Example3.10.Creating a rating programmatically

A rating is used for keeping track of who has rated which question, to try and cut down on questions being rated by the same person thousands of times

<?php

// The init file handles all the things like connecting to the database and including our API files
require_once('/path/to/Interspire Knowledge Manager/init.php');

// We need to include the language file in case the API gives us an error
$GLOBALS['AKB_LANG'] = parse_ini_file('/path/to/Interspire Knowledge Manager/includes/language/front_language.ini');

$r = new API_RATING();

$_SERVER['REMOTE_ADDR'] = '127.0.0.1'; // Manually set the ip our request is coming from
$_POST['questionid']    = 1337; // The questionid that was being rated

$newid = $r->create();

if ($newid > 0) {
    echo "Rating created successfully<br />\n";
} else {
    echo "There was a problem creating the rating, reason: ".$r->error."<br />\n";
}

?>

Example3.11.Creating a submitted question programmatically

<?php

$_POST['name']     = 'Joe Bloggs'; // The name of the submitter
$_POST['email']    = 'joe@example.com'; // The submitter's email address
$_POST['subject']  = 'I have a question'; // The subject of their question
$_POST['question'] = 'Why is the sky blue ?'; // The actual question

// The init file handles all the things like connecting to the database and including our API files
require_once('/path/to/Interspire Knowledge Manager/init.php');

// We need to include the language file in case the API gives us an error
$GLOBALS['AKB_LANG'] = parse_ini_file('/path/to/Interspire Knowledge Manager/includes/language/front_language.ini');

$sq = new API_SUBMITTEDQUESTION();

$newid = $sq->create();

if ($newid > 0) {
    echo "Submitted question created successfully<br />\n";
} else {
    echo "There was a problem creating the submitted question, reason: ".$sq->error."<br />\n";
}

?>

Example3.12.Creating a subscriber programmatically

When a subscriber is created, the date is recorded automatically. By default the users is set to be unconfirmed. If you want to confirm them you have to update the user after they have been created.

<?php

$_POST['email']      = 'joe@example.com'; // The subscriber's email address
$_POST['questionid'] = 130; // The id of the question the person has subscribed to

// The init file handles all the things like connecting to the database and including our API files
require_once('/path/to/Interspire Knowledge Manager/init.php');

// We need to include the language file in case the API gives us an error
$GLOBALS['AKB_LANG'] = parse_ini_file('/path/to/Interspire Knowledge Manager/includes/language/front_language.ini');

$sub = new API_SUBSCRIBER();

$newid = $sub->create();

if ($newid > 0) {
    echo "Subscriber created successfully<br />\n";
} else {
    echo "There was a problem creating the subscriber, reason: ".$sub->error."<br />\n";
}

?>

Example3.13.Creating a user programmatically

<?php

$_POST['username']   = 'jbloggs'; // The users login
$_POST['password']   = 'password'; // The user's password. This will be encrypted before saving so no need to encrypt it yourself
$_POST['firstname']  = 'Joe'; // The users first name
$_POST['lastname']   = 'Bloggs'; // The users last name
$_POST['status']     = 1; // Is the user account active ? (0 = disabled, 1 = active)

// The init file handles all the things like connecting to the database and including our API files
require_once('/path/to/Interspire Knowledge Manager/init.php');

// We need to include the language file in case the API gives us an error
$GLOBALS['AKB_LANG'] = parse_ini_file('/path/to/Interspire Knowledge Manager/includes/language/front_language.ini');

$u = new API_USER();

$newid = $u->create();

if ($newid > 0) {
    echo "User created successfully<br />\n";
} else {
    echo "There was a problem creating the user, reason: ".$u->error."<br />\n";
}

?>

Updating

Let's say we wanted to take our previous example and update the the name of the category to "My Updated Test Category". Assuming we knew the id of the category we want to update, then updating it is simple.

Example3.14.Updating a category programmatically

<?php

// The init file handles all the things like connecting to the database and including our API files
require_once('/path/to/Interspire Knowledge Manager/init.php');

// We need to include the language file in case the API gives us an error
$GLOBALS['AKB_LANG'] = parse_ini_file('/path/to/Interspire Knowledge Manager/includes/language/front_language.ini');

$c = new API_CATEGORY();
$c->load(130); // Assuming the category you want to update has the id 130 in the database

$_POST['name']         = 'My Updated Test Category';
$_POST['metakeywords'] = 'dynamic, question, generated, updated';

if ($c->save()) {
   echo "Question updated successfully<br />\n";
} else {
   echo "There was a problem updating the question, reason: ".$c->error."<br />\n";
}

?>

Example3.15.Updating a comment programmatically

<?php

// The init file handles all the things like connecting to the database and including our API files
require_once('/path/to/Interspire Knowledge Manager/init.php');

// We need to include the language file in case the API gives us an error
$GLOBALS['AKB_LANG'] = parse_ini_file('/path/to/Interspire Knowledge Manager/includes/language/front_language.ini');

$c = new API_COMMENT();
$c->load(1337); // Assuming the comment you want to update has the id 1337 in the database

$_POST['status'] = 'approved';

if ($c->save()) {
   echo "Question updated successfully<br />\n";
} else {
   echo "There was a problem updating the question, reason: ".$c->error."<br />\n";
}

?>

Example3.16.Updating a glossary term programmatically

<?php

// The init file handles all the things like connecting to the database and including our API files
require_once('/path/to/Interspire Knowledge Manager/init.php');

// We need to include the language file in case the API gives us an error
$GLOBALS['AKB_LANG'] = parse_ini_file('/path/to/Interspire Knowledge Manager/includes/language/front_language.ini');

$g = new API_GLOSSARY();
$g->load(130); // Assuming the glossary term you want to update has the id 130 in the database

$_POST['description'] = $g->description.' In this case it is by using PHP'; // Append some text to our exisiting description

if ($g->save()) {
   echo "Glossary term updated successfully<br />\n";
} else {
   echo "There was a problem updating the glossary term, reason: ".$g->error."<br />\n";
}

?>

Example3.17.Updating a group programmatically

<?php

// The init file handles all the things like connecting to the database and including our API files
require_once('/path/to/Interspire Knowledge Manager/init.php');

// We need to include the language file in case the API gives us an error
$GLOBALS['AKB_LANG'] = parse_ini_file('/path/to/Interspire Knowledge Manager/includes/language/front_language.ini');

$g = new API_GROUP();
$g->load(130); // Assuming the group you want to update has the id 130 in the database

$_POST['name'] = 'Sales';

if ($g->save()) {
   echo "Group updated successfully<br />\n";
} else {
   echo "There was a problem updating the group, reason: ".$g->error."<br />\n";
}

?>

Example3.18.Updating a question programmatically

<?php

// The init file handles all the things like connecting to the database and including our API files
require_once('/path/to/Interspire Knowledge Manager/init.php');

// We need to include the language file in case the API gives us an error
$GLOBALS['AKB_LANG'] = parse_ini_file('/path/to/Interspire Knowledge Manager/includes/language/front_language.ini');

$q = new API_QUESTION();
$q->load(130); // Assuming the question you want to update has the id 130 in the database

$_POST['title'] = 'My Updated Question Title';

if ($q->save()) {
   echo "Category updated successfully<br />\n";
} else {
   echo "There was a problem updating the category, reason: ".$q->error."<br />\n";
}

?>

Example3.19.Updating a rating programmatically

<?php

// The init file handles all the things like connecting to the database and including our API files
require_once('/path/to/Interspire Knowledge Manager/init.php');

// We need to include the language file in case the API gives us an error
$GLOBALS['AKB_LANG'] = parse_ini_file('/path/to/Interspire Knowledge Manager/includes/language/front_language.ini');

$r = new API_RATING();
$r->load(130); // Assuming the rating you want to update has the id 130 in the database

$_POST['ip'] = '192.168.0.1';

if ($r->save()) {
   echo "Rating updated successfully<br />\n";
} else {
   echo "There was a problem updating the rating, reason: ".$r->error."<br />\n";
}

?>

Example3.20.Updating a submitted question programmatically

<?php

// The init file handles all the things like connecting to the database and including our API files
require_once('/path/to/Interspire Knowledge Manager/init.php');

// We need to include the language file in case the API gives us an error
$GLOBALS['AKB_LANG'] = parse_ini_file('/path/to/Interspire Knowledge Manager/includes/language/front_language.ini');

$sq = new API_SUBMITTEDQUESTION();
$sq->load(130); // Assuming the submitted question you want to update has the id 130 in the database

$_POST['email'] = 'mbloggs@example.com';
$_POST['name'] = 'Mary Bloggs';
$_POST['subject'] = 'Has Joe been using my computer again ?';

if ($sq->save()) {
   echo "Submitted question updated successfully<br />\n";
} else {
   echo "There was a problem updating the submitted question, reason: ".$sq->error."<br />\n";
}

?>

Example3.21.Updating a subscriber programmatically

This example is a little more specific then the others to demonstrate how to access values after you have performed a load()

<?php

// The init file handles all the things like connecting to the database and including our API files
require_once('/path/to/Interspire Knowledge Manager/init.php');

// We need to include the language file in case the API gives us an error
$GLOBALS['AKB_LANG'] = parse_ini_file('/path/to/Interspire Knowledge Manager/includes/language/front_language.ini');

$sub = new API_SUBSCRIBER();
$sub->load(130); // Assuming the subscriber you want to update has the id 130 in the database

// Once we have loaded an entry, it's values are available as class variables
if ($sub->confirmed == 0 && $sub->confirmcode == $_POST['confirmcode']) {
   $_POST['confirmd'] = 1;
}

if ($sub->save()) {
   echo "Subscriber confirmed successfully<br />\n";
} else {
   echo "There was a problem confirming the subscriber, reason: ".$sub->error."<br />\n";
}

?>

Example3.22.Updating a user programmatically

This example also shows you how to use the find() function to find the row by any unique column on it's database table.

<?php

// The init file handles all the things like connecting to the database and including our API files
require_once('/path/to/Interspire Knowledge Manager/init.php');

// We need to include the language file in case the API gives us an error
$GLOBALS['AKB_LANG'] = parse_ini_file('/path/to/Interspire Knowledge Manager/includes/language/front_language.ini');

$u = new API_USER();
$u->load(130); // Assuming the user you want to update has the id 130 in the database

$_POST['password'] = 'newpass';

if ($u->save()) {
   echo "Password updated successfully<br />\n";
} else {
   echo "There was a problem updating the users password, reason: ".$u->error."<br />\n";
}


// Since the user table has a unique index on the username field, we can also load a value by name
$u2 = new API_USER();
$u2->find('username', 'jbloggs');

$_POST['password'] = 'joesnewpass';
if ($u2->save()) {
   echo "Password updated successfully<br />\n";
} else {
   echo "There was a problem updating the users password, reason: ".$u2->error."<br />\n";
}

?>

Deleting

Deleting can be done in two ways. You can delete a single entry or you can delete multiple entries. The functions for doing this are delete and multiDelete respectively. Here is an example of each. Deleting is the same for all items using the API so only 4 examples are show for both styles of deleting to save space. All you have to do is adjust the line which creates a new API object to your specific needs.

Deleting a single item

Example3.23.Deleting a category programmatically

<?php

// The init file handles all the things like connecting to the database and including our API files
require_once('/path/to/Interspire Knowledge Manager/init.php');

// We need to include the language file in case the API gives us an error
$GLOBALS['AKB_LANG'] = parse_ini_file('/path/to/Interspire Knowledge Manager/includes/language/front_language.ini');

$c = new API_CATEGORY();

// Delete the category with the id 130
if ($c->delete(130)) {
    echo "The category has been deleted successfully<br />\n";
} else {
    echo "There was a problem deleting the category, reason: ".$c->error."<br />\n";
}

?>

Example3.24.Deleting a comment programmatically

<?php

// The init file handles all the things like connecting to the database and including our API files
require_once('/path/to/Interspire Knowledge Manager/init.php');

// We need to include the language file in case the API gives us an error
$GLOBALS['AKB_LANG'] = parse_ini_file('/path/to/Interspire Knowledge Manager/includes/language/front_language.ini');

$c = new API_COMMENT();

// Delete the comment with the id 1337
if ($c->delete(1337)) {
    echo "The comment has been deleted successfully<br />\n";
} else {
    echo "There was a problem deleting the comment, reason: ".$c->error."<br />\n";
}

?>

Example3.25.Deleting a glossary term programmatically

<?php

// The init file handles all the things like connecting to the database and including our API files
require_once('/path/to/Interspire Knowledge Manager/init.php');

// We need to include the language file in case the API gives us an error
$GLOBALS['AKB_LANG'] = parse_ini_file('/path/to/Interspire Knowledge Manager/includes/language/front_language.ini');

$g = new API_GLOSSARY();

// Delete the glossary term with the id 130
if ($g->delete(130)) {
    echo "The glossary term has been deleted successfully<br />\n";
} else {
    echo "There was a problem deleting the glossary term, reason: ".$g->error."<br />\n";
}

?>

Example3.26.Deleting a question programmatically

<?php

// The init file handles all the things like connecting to the database and including our API files
require_once('/path/to/Interspire Knowledge Manager/init.php');

// We need to include the language file in case the API gives us an error
$GLOBALS['AKB_LANG'] = parse_ini_file('/path/to/Interspire Knowledge Manager/includes/language/front_language.ini');

$q = new API_QUESTION();

// Delete the question with the id 130
if ($q->delete(130)) {
    echo "The question has been deleted successfully<br />\n";
} else {
    echo "There was a problem deleting the question, reason: ".$q->error."<br />\n";
}

?>

Deleting multiple items

Example3.27.Deleting multiple categories programmatically

<?php

// The init file handles all the things like connecting to the database and including our API files
require_once('/path/to/Interspire Knowledge Manager/init.php');

// We need to include the language file in case the API gives us an error
$GLOBALS['AKB_LANG'] = parse_ini_file('/path/to/Interspire Knowledge Manager/includes/language/front_language.ini');

$c = new API_CATEGORY();

// Delete the categories with the id's 1, 2, 3, 4 or 5
$ids_to_delete = array (1, 2, 3, 4, 5);

if ($c->multiDelete($ids_to_delete);) {
    echo "The categories have been deleted successfully<br />\n";
} else {
    echo "There was a problem deleting the categories, reason: ".$c->error."<br />\n";
}

?>

Example3.28.Deleting multiple comments programmatically

<?php

// The init file handles all the things like connecting to the database and including our API files
require_once('/path/to/Interspire Knowledge Manager/init.php');

// We need to include the language file in case the API gives us an error
$GLOBALS['AKB_LANG'] = parse_ini_file('/path/to/Interspire Knowledge Manager/includes/language/front_language.ini');

$c = new API_COMMENT();

// Delete the categories with the id's 1, 2, 3, 4 or 5
$ids_to_delete = array (1, 2, 3, 4, 5);

if ($c->multiDelete($ids_to_delete);) {
    echo "The comments have been deleted successfully<br />\n";
} else {
    echo "There was a problem deleting the comments, reason: ".$c->error."<br />\n";
}

?>

Example3.29.Deleting multiple glossary terms programmatically

<?php

// The init file handles all the things like connecting to the database and including our API files
require_once('/path/to/Interspire Knowledge Manager/init.php');

// We need to include the language file in case the API gives us an error
$GLOBALS['AKB_LANG'] = parse_ini_file('/path/to/Interspire Knowledge Manager/includes/language/front_language.ini');

$g = new API_GLOSSARY();

// Delete the glossary terms with the id's 1, 2, 3, 4 or 5
$ids_to_delete = array (1, 2, 3, 4, 5);

if ($g->multiDelete($ids_to_delete);) {
    echo "The glossary terms have been deleted successfully<br />\n";
} else {
    echo "There was a problem deleting the glossary terms, reason: ".$g->error."<br />\n";
}

?>

Example3.30.Deleting multiple questions programmatically

<?php

// The init file handles all the things like connecting to the database and including our API files
require_once('/path/to/Interspire Knowledge Manager/init.php');

// We need to include the language file in case the API gives us an error
$GLOBALS['AKB_LANG'] = parse_ini_file('/path/to/Interspire Knowledge Manager/includes/language/front_language.ini');

$q = new API_QUESTION();

// Delete the questions with the id's 1, 2, 3, 4 or 5
$ids_to_delete = array (1, 2, 3, 4, 5);

if ($q->multiDelete($ids_to_delete);) {
    echo "The questions have been deleted successfully<br />\n";
} else {
    echo "There was a problem deleting the questions, reason: ".$q->error."<br />\n";
}

?>