<script type="text/javascript">
    function openURL()
    {
        window.location.href="index.php?fuse=knowledgebase&view=KB_AddArticle";
    }
    
    function publishArticle()
    {
        var checkbox = document.form.articleid;
        var articlesChecked = "";
        var totalArticles = checkbox.length;
        for (var i = 0; i < totalArticles; i++){
            if (checkbox[i].checked){
                articlesChecked = checkbox[i].value + "," + articlesChecked;
            }                    
        }                
        params = "&articleId=" + articlesChecked;        
        new Ajax.Request( 'index.php?fuse=knowledgebase&action=KB_PublishArticle',
          {
              method        : 'post',
              parameters    : params,
              onSuccess     : showResponse,
              onComplete    : function(request) {        setStatus(lang('Article Published'), 500)}
          }
        );
        
    }
    
    function showResponse(originalRequest)
	{				    
	    var response = originalRequest.responseText;
        alert (response);
        window.location.reload( false );
	}

    function filterArticles()
    {
        var selectOption = document.getElementById('filterByPublishStatus').value;
        window.location.href= "index.php?fuse=knowledgebase&view=KB_manageArticlesView&filter=" + selectOption;
    }

    function moveArticles()
    {
        document.form.action = "index.php?fuse=knowledgebase&action=KB_MoveArticles";
        return true;
    }
</script>
<form id="form" name="form" method="POST" action="index.php?fuse=knowledgebase&action=KB_DeleteArticle">
    <table width="100%" align="center" cellpadding="0"cellspacing="0" border="0">
        <tr>
            <td valign="top" width="25%">
            <div class="dtree">
            	<p>{dtreeOptions}</p>
            	<script type="text/javascript">
            	    d = new dTree('d');
                    <!-- BEGIN DYNAMIC BLOCK: kbCategories -->
                        d.add('{nodeId}','{nodeParentId}','{nodeName}','{nodeUrl}','{nodeSelected}');
                    <!-- END DYNAMIC BLOCK: kbCategories -->
                    {treeView}
                    d.openAll();
            	</script>
            </div>
            <!-- BEGIN DYNAMIC BLOCK: noCategories -->
            <br />
            [l]There are no categories defined for the KnowledgeBase[/l]
            <!-- END DYNAMIC BLOCK: noCategories -->            
            </td>        
            <td valign="top" nowrap width="75%">                               
                <table width="100%" cellpadding="0"cellspacing="0" border="0">
            		<tr>
            			<td class='snapshot-header-left'></td>
            			<td class='snapshot-header'><span class='snapshot-header-text'>{articlesHeader}</span></td>
            			<td class='snapshot-header' align="right">            
            				<span class='snapshot-header-text-small'>[l]Filter By:[/l]</span>
                            <select id="filterByPublishStatus" name="filterByPublishStatus" onchange="filterArticles()">
                                <option value="all" selected>--[l]All[/l]-- </option>
                                <option value="published">[l]published[/l]</option>
                                <option value="nonpublished">[l]draft[/l]</option>
                            </select>             
            			</td>
            			<td class='snapshot-header-right'></td>
            		</tr>
            	</table>
                <!-- BEGIN DYNAMIC BLOCK: noArticles -->
                    <br />
                    [l]There are no articles defined for the KnowledgeBase[/l]
                <!-- END DYNAMIC BLOCK: noArticles -->
                <!-- BEGIN DYNAMIC BLOCK: kbTableArticles -->
                <table width="100%" width="l00%" class="sort-table" id="table-1" border="0" align="center" cellpadding="0" cellspacing="0">
                    <col style="text-align: right" />
                    <col />
                    <col />
                    <col />
                    <col />
                    <thead>    
                        <tr class="{trClassHead}">
                            <td>&nbsp;</td>
                            <td align="left" width="40%">[l]title[/l]</td>
                            <td align="center" width="20%">[l]Category[/l]</td>
                            <td align="center">[l]Date Created[/l]</td>
                            <td align="center">[l]Date Modified[/l]</td>
                            <td align="center">[l]Rating[/l]</td>
                            <td align="center">[l]Draft[/l]</td>
                        </tr>
                    </thead>        
                    <tbody>
                        <!-- BEGIN DYNAMIC BLOCK: kbArticles -->
                        <tr class="{trClass}">
                            <!-- BEGIN DYNAMIC BLOCK: articleCheckbox -->
                            <td width="5">
                                <input type="checkbox" style="position:relative;top:1px;" name="articleid[]" id="articleid" value="{articleId}" onClick="checkCheckBox(this);" />
                            </td>
                            <!-- END DYNAMIC BLOCK: articleCheckbox -->
                            <td align="left" >{articleTitle}</td>
                            <td align="left" >{articleCategory}</td>
                            <td align="center" nowrap>{articleDateCreated}</td>
                            <td align="center" nowrap>{articleDateModified}</td>
                            <td align="center" nowrap>{articleRating}</td>
                            <td align="center" nowrap>{articleisDraft}</td>                            
                        </tr>        
                        <!-- END DYNAMIC BLOCK: kbArticles -->
                    <tbody>        
                </table>
                <br />                
                <input type="checkbox" name="toggleAllChk" onclick="toggleAll(this.form);"/><b>&nbsp;&nbsp;&nbsp;[l]Toggle All[/l]</b>
                <!-- END DYNAMIC BLOCK: kbTableArticles -->
                <div class="actionfooter" style="margin-top:15px">
                    <!-- BEGIN DYNAMIC BLOCK: deleteBtn -->                         
                    <input id="btnDelete" 
                           name="btnDelete" 
                           type="submit" 
                           class="button_large" 
                           value="[lh]delete article[/lh]" 
                           style="filter:alpha(opacity=50); -moz-opacity:0.4" 
                           disabled="true"
                           />&nbsp;
                    <!-- END DYNAMIC BLOCK: deleteBtn -->
                    <!-- BEGIN DYNAMIC BLOCK: addArticleBtn -->                                                                         
                    <input id="btnAddArticle"
                           name="btnAddArticle"
                           type="button" 
                           class="button_large"  
                           value="[lh]Add Article[/lh]" 
                           onclick="openURL()" 
                           />&nbsp;
                    <!-- END DYNAMIC BLOCK: addArticleBtn -->                                                 
                    <!-- BEGIN DYNAMIC BLOCK: publishArticleBtn -->                                                 
                    <input id="btnDelete"
                           name="btnPubArticle"
                           type="button" 
                           class="button_large"  
                           value="[lh]Publish Article[/lh]" 
                           style="filter:alpha(opacity=50); -moz-opacity:0.4" 
                           disabled="true"    	                           
                           onclick="publishArticle()" 
                           />&nbsp;
                    <!-- END DYNAMIC BLOCK: publishArticleBtn -->
                    <!-- BEGIN DYNAMIC BLOCK: moveArticleBtn -->                                                 
                    <input id="btnMove"
                           name="btnMoveArticle"
                           type="button" 
                           class="button_large"  
                           value="[lh]Move Article[/lh]" 
                           style="filter:alpha(opacity=50); -moz-opacity:0.4" 
                           disabled="true"    	                           
                           onclick="document.getElementById('articleCats').style.display='block'" 
                           />&nbsp;
                    <!-- END DYNAMIC BLOCK: moveArticleBtn -->                                                 
                </div>
                <!-- BEGIN DYNAMIC BLOCK: moveArticleCats -->
                <div id="articleCats" style="display:none; margin-top:15px; margin-left:20px">
                    <div style="font-weight:bold">
                        [l]Select target categorie(s) and press "Move":[/l]
                    </div>
                    <div style="margin-top:10px">
                        <select class=required name="newCategories[]" multiple="multiple" size="8">
                            <!-- BEGIN DYNAMIC BLOCK: newCategoryOption -->
                            <option value="{catId}" {catSelected} >{catLabel}</option>
                            <!-- END DYNAMIC BLOCK: newCategoryOption -->
                        </select>&nbsp;&nbsp;
                        <input type="submit" class="button_medium" value="[lh]Move[/lh]" onclick="return moveArticles()" />
                    </div>
                </div>
                <!-- END DYNAMIC BLOCK: moveArticleCats -->
            </td>
        </tr>
    </table>        
</form>
