function consolidateDB($db_name, $file_display, $file_original, $file_thumb, $files_total)
    {
        global $rsgConfig;
        require_once JPATH_RSGALLERY2_ADMIN . '/config.rsgallery2.php';
        $file_diff = array_diff($files_total, $db_name);
        ?>
	    <script language="Javascript">
	    function db_create() {
	    	alert('Database creation does not work yet!');
	    }
	    
	    function db_createX() {
	    	var form = document.adminForm;
				form.t_id.value = t_id;
				form.g_id.value = g_id;
				form.submit();
	    }
	    </script>
	    <form method="post" action="index2.php?option=com_rsgallery2&rsgOption=maintenance&task=createDbEntries" name="adminForm">
	    <input type="hidden" name="t_id" value="" />
	    <input type="hidden" name="g_id" value="" />
	    <table width="100%" border="0">
	    	<tr>
	    	<td width="15%">&nbsp;</td>
	    	<td width="70%">
			    <table class="adminlist" border="0">
			    <tr>
			    	<td colspan="9" align="center">
				    	<div style="clear: both; margin: 3px; margin-top: 10px; padding: 5px 15px; display: block; float: left; border: 1px solid #cc0000; background: #ffffcc; text-align: left; width: 80%;">
		    				<p style="color: #CC0000;">
		    				<img src="<?php 
        echo JURI_SITE;
        ?>
/includes/js/ThemeOffice/warning.png" alt="Warning icon" />
							NOTICE:<br />Experimental at this stage. Single image regeneration works. <br /> Database entries do NOT work!.
							<?php 
        //echo JText::_('CONSDB_NOTICE');
        ?>
							</p>
						</div>
						<div class='rsg2-clr'>&nbsp;</div>
			    	</td>
			    </tr>
			    <tr>
			    	<th>#</th>
			        <th><?php 
        echo JText::_('Filename');
        ?>
</th>
			        <th align="center"><?php 
        echo JText::_('In<br>database');
        ?>
</th>
			        <th align="center"><?php 
        echo JText::_('Display<br>folder');
        ?>
</th>
		        	<th align="center"><?php 
        echo JText::_('Original<br>folder');
        ?>
</th>
			        <th align="center"><?php 
        echo JText::_('Thumb<br>folder');
        ?>
</th>
			        <th>&nbsp;</th>
			        <th align="center"><?php 
        echo JText::_('Image');
        ?>
</th>
			        <th align="center"><?php 
        echo JText::_('Action');
        ?>
</th>
			    </tr>
			    <tr>
			        <td colspan="9">&nbsp;</td>
			    </tr>
			    <?php 
        $yes = "<td align=\"center\"><img src=\"" . JURI_SITE . "administrator/images/tick.png\" alt=\"" . JText::_('Image in folder') . "\" border=\"0\"></td>";
        $no = "<td align=\"center\"><img src=\"" . JURI_SITE . "administrator/images/publish_x.png\" alt=\"" . JText::_('Image NOT in folder') . "\" border=\"0\"></td>";
        $z = 0;
        $c = 0;
        //Check database and crossreference against filesystem
        foreach ($db_name as $name) {
            $c++;
            $i = 0;
            $fid = galleryUtils::getFileIdFromName($name);
            $html = "<tr><td><input type=\"checkbox\" id=\"cb{$c}\" name=\"xid[]\" value=\"{$name}\" onclick=\"isChecked(this.checked);\" /></td><td>{$name}</td>" . $yes;
            if (in_array($name, $file_display)) {
                $i++;
                $html .= $yes;
                $display = true;
            } else {
                $z++;
                $html .= $no;
                $display = false;
            }
            if (in_array($name, $file_original)) {
                $i++;
                $html .= $yes;
                $original = true;
            } else {
                $z++;
                $html .= $no;
                $original = false;
            }
            if (in_array($name, $file_thumb)) {
                $i++;
                $html .= $yes;
                $thumb = true;
            } else {
                $z++;
                $html .= $no;
                $thumb = false;
            }
            if ($i < 3) {
                echo $html;
                ?>
			            <td>&nbsp;</td>
			            <td>
			            	<img src="<?php 
                echo imgUtils::getImgThumb($name);
                ?>
" name="image" width="<?php 
                echo $rsgConfig->get('thumb_width');
                ?>
" alt="<?php 
                echo $name;
                ?>
"/>
			            </td>
			            <td align="center">
			                <a href="index2.php?option=com_rsgallery2&rsgOption=maintenance&task=deleteImages&name=<?php 
                echo $name;
                ?>
"><?php 
                echo '[&nbsp;' . JText::_('Delete_from_database') . '&nbsp;]';
                ?>
</a><br />
			                <?php 
                if ($original == true or $display == true) {
                    ?>
			                    <a href="index2.php?option=com_rsgallery2&rsgOption=maintenance&task=createImages&id=<?php 
                    echo $fid;
                    ?>
"><?php 
                    echo '[&nbsp;' . JText::_('Create_missing_images') . '&nbsp;]';
                    ?>
</a>
			                    <?php 
                }
                ?>
			            </td></tr>
			            <?php 
            } else {
                continue;
            }
        }
        ?>
			    </tr>
			    
			    <?php 
        $zz = 0;
        $t = 0;
        //Check filesystem and crossreference against database
        foreach ($file_diff as $diff) {
            $t++;
            $y = 0;
            $html2 = "<tr><td><input type=\"checkbox\" id=\"cb{$t}\" name=\"xid[]\" value=\"{$t}\" onclick=\"isChecked(this.checked);\" /></td><td><font color=\"#FF0000\">{$diff}</font></td>{$no}";
            if (in_array($diff, $file_display)) {
                $y++;
                $html2 .= $yes;
                $display2 = true;
            } else {
                $zz++;
                $html2 .= $no;
                $display2 = false;
            }
            if (in_array($diff, $file_original)) {
                $y++;
                $html2 .= $yes;
                $original2 = true;
            } else {
                $zz++;
                $html2 .= $no;
                $original2 = false;
            }
            if (in_array($diff, $file_thumb)) {
                $y++;
                $html2 .= $yes;
                $thumb2 = true;
            } else {
                $zz++;
                $html2 .= $no;
                $thumb2 = false;
            }
            if ($y < 4) {
                echo $html2;
                ?>
			            <td>
			            	<?php 
                echo galleryUtils::galleriesSelectList(NULL, 'gallery_id[]', false, false);
                ?>
			            	<input type="hidden" name="name[]" value="<?php 
                echo $diff;
                ?>
" />
			            </td>
			            <td>
			            	<img src="<?php 
                echo imgUtils::getImgThumb($diff);
                ?>
" name="image" width="<?php 
                echo $rsgConfig->get('thumb_width');
                ?>
" />
			            </td>
			            <td align="center">
			                <a href="javascript:void();" onClick="javascript:db_create();"><?php 
                echo '[&nbsp;' . JText::_('Create_Database_entry') . '&nbsp;]';
                ?>
</a><br />
			                <a href="index2.php?option=com_rsgallery2&rsgOption=maintenance&task=deleteImages&name=<?php 
                echo $diff;
                ?>
"><?php 
                echo '[&nbsp;' . JText::_('Delete_images'), '&nbsp;]';
                ?>
</a>&nbsp;
			                <?php 
                if ($original2 == true and $display2 == true and $thumb2 == true) {
                    continue;
                } else {
                    ?>
			                    <br /><a href="index2.php?option=com_rsgallery2&rsgOption=maintenance&task=createImages&name=<?php 
                    echo $diff;
                    ?>
"><?php 
                    echo '[&nbsp;' . JText::_('Create missing images') . '&nbsp;]';
                    ?>
</a>
			                    <?php 
                }
                ?>
			            </td>
			            <?php 
            } else {
                continue;
            }
        }
        if ($t == 0 and $z == 0) {
            echo "<tr><td colspan=\"8\"><font color=\"#008000\"><strong>" . JText::_('No inconsistencies in database') . "</strong></font></td>";
        }
        ?>
			    </tr>
			    <tr>
			        <th colspan="9" align="center">
			        	<a href="index2.php?option=com_rsgallery2&rsgOption=maintenance&task=consolidateDB">Refresh</a>
			        </th>
			    </tr>
			    <!--
			    <tr>
			    	<td colspan="2"><input type="checkbox" name="toggle" value="" onclick="checkAll(<?php 
        echo count($db_name) + count($file_diff);
        ?>
);" /></td>
			    	<td colspan="5"> With selection:<br /> 
			    		<a href="javascript:void();" onClick="javascript:alert('<?php 
        echo JText::_('Not working yet');
        ?>
');"><?php 
        echo JText::_('Delete from filesystem');
        ?>
</a>&nbsp;|&nbsp; 
			    		<a href="javascript:void();" onClick="javascript:alert('<?php 
        echo JText::_('Not working yet');
        ?>
');"><?php 
        echo JText::_('Create missing images');
        ?>
</a>&nbsp;|&nbsp;
			    		<a href="javascript:void();" onClick="javascript:alert('<?php 
        echo JText::_('Not working yet');
        ?>
');"><?php 
        echo JText::_('Create database entries');
        ?>
</a>
			    	</td>
			
			    </tr>
			    -->
			    </table>
	    </td>
	    <td width="15%">&nbsp;</td>
	    </tr>
	    </table>
	    </form>
	    <?php 
    }