/**
     * asks user to choose what files to upload
     */
    function showUploadStep3()
    {
        $catid = rsgInstance::getInt('catid', null);
        $uploadstep = rsgInstance::getInt('uploadstep', null);
        $numberOfUploads = rsgInstance::getInt('numberOfUploads', null);
        ?>
        <script language="javascript" type="text/javascript">
        function submitbutton(pressbutton) {
        var form = document.form3;
            form.submit();
        }
        </script>
        <form name="form3" action="index2.php?option=com_rsgallery2&task=upload" method="post" enctype="multipart/form-data">
        <input type="hidden" name="uploadStep" value="4" />
        <input type="hidden" name="catid" value="<?php 
        echo $catid;
        ?>
" />
        <input type="hidden" name="numberOfUploads" value="<?php 
        echo $numberOfUploads;
        ?>
" />
        <table width="100%">
        <tr>
            <td width="300">&nbsp;</td>
            <td>
            <table class="adminform">
            <tr>
                <th colspan="2"><font size="4"><?php 
        echo JText::_('Step 3');
        ?>
</font></td>
            </tr>
            <?php 
        for ($t = 1; $t < $numberOfUploads + 1; $t++) {
            ?>
            <tr>
                <td colspan="2">
                    <table width="100%" cellpadding="1" cellspacing="1">
                    <tr>
                        <td colspan="2"><strong><?php 
            echo JText::_('Image');
            echo "&nbsp;" . $t;
            ?>
</strong></td>
                    </tr>
                    <tr>
                        <td><?php 
            echo JText::_('Gallery name');
            ?>
:</td>
                        <td><strong><?php 
            echo galleryUtils::getCatnameFromId($catid);
            ?>
</strong></td>
                    </tr>
                    <tr>
                        <td valign="top" width="100"><?php 
            echo JText::_('Title') . " " . $t;
            ?>
:</td>
                        <td>
                        <input name="imgTitle[]" type="text" class="inputbox" size="40" />
                        </td>
                    </tr>
                    <tr>
                        <td valign="top"><?php 
            echo JText::_('File') . " " . $t;
            ?>
:</td>
                        <td>
                        <input class="inputbox" name="images[]" type="file" size="30" />
                        </td>
                    </tr>
                    <tr>
                        <td valign="top"><?php 
            echo JText::_('Description') . " " . $t;
            ?>
</td>
                        <td>
                        <textarea class="inputbox" cols="35" rows="3" name="descr[]"></textarea>
                        </td>
                    </tr>
                    <tr class="row1">
                    <th colspan="2">&nbsp;</th>
                    </tr>
                    </table>
                    </td>
                    </tr>
              <?php 
        }
        ?>
              </table>
              </td>
                <td width="300">&nbsp;</td>
            </tr>
            </table>
</form>
        <?php 
    }
    /**
     * This function will show the 5 last uploaded images
     */
    function latestImages()
    {
        global $rows;
        $my = JFactory::getUser();
        $database = JFactory::getDBO();
        $lastweek = mktime(0, 0, 0, date("m"), date("d") - 7, date("Y"));
        $lastweek = date("Y-m-d H:m:s", $lastweek);
        $database->setQuery("SELECT * FROM #__rsgallery2_files WHERE date >= '{$lastweek}' and published=1 ORDER BY id DESC LIMIT 0,5");
        $rows = $database->loadObjectList();
        if (count($rows) > 0) {
            foreach ($rows as $row) {
                ?>
            <tr>
                <td><?php 
                echo $row->name;
                ?>
</td>
                <td><?php 
                echo galleryUtils::getCatnameFromId($row->gallery_id);
                ?>
</td>
                <td><?php 
                echo $row->date;
                ?>
</td>
                <td><?php 
                echo galleryUtils::genericGetUsername($row->userid);
                ?>
</td>
            </tr>
            <?php 
            }
        } else {
            echo "<tr><td colspan=\"4\">" . JText::_('No new entries') . "</td></tr>";
        }
    }
    function batchupload_2($ziplist, $extractDir)
    {
        /* Info for javascript on input element names and values:
        		Step 2
        		Button: Upload --> 	task=save_batchupload
        		Delete checkbox name: 	delete[1]
        		Item title field name:	ptitle[]
        		Gallery select name:	category[]
        		Description area name:	descr[]
        		*/
        global $rsgOption;
        JHTML::_('behavior.mootools');
        $database = JFactory::getDBO();
        //Get variables from form
        $selcat = rsgInstance::getInt('selcat', null);
        $ftppath = rsgInstance::getVar('ftppath', null);
        $xcat = rsgInstance::getInt('xcat', null);
        $batchmethod = rsgInstance::getVar('batchmethod', null);
        ?>
		<script language="javascript" type="text/javascript">
        <!--
        function submitbutton(pressbutton) {
            var form = document.adminForm,
				missingCat = false,
				categories = $$('#adminForm input[name^=category]', '#adminForm select[name^=category]');
           
            for (i=0 ; i<categories.length ; i++) {
				if (categories[i].value <= 0) {
					alert("<?php 
        echo JText::_('All images must be part of a galery');
        ?>
"+' (#'+i+')');
					return;
					missingCat = true;
					break;
				}
            }

			if (pressbutton == 'save_batchupload'){
				if (missingCat == true) {
					alert("<?php 
        echo JText::_('All images must be part of a galery');
        ?>
");
				}
				else {
					form.submit();
				}
			}
        }
        //-->
        </script>

        <form action="index2.php" method="post" name="adminForm" id="adminForm">
        <table class="adminform">
        <tr>
            <th colspan="5" class="sectionname"><font size="4"><?php 
        echo JText::_('Step 2');
        ?>
</font></th>
        </tr>
        <tr>
        <?php 
        // Initialize k (the column reference) to zero.
        $k = 0;
        $i = 0;
        foreach ($ziplist as $filename) {
            $k++;
            //Check if filename is dir
            if (is_dir(JPATH_ROOT . '/media/' . $extractDir . '/' . $filename)) {
                continue;
            } else {
                //Check if file is allowed
                $allowed_ext = array('gif', 'jpg', 'png');
                $allowedVideo_ext = array('flv', 'avi', 'mov');
                $ext = fileHandler::getImageType(JPATH_ROOT . '/media/' . $extractDir . '/' . $filename);
                if (in_array($ext, $allowedVideo_ext)) {
                    // build preview image
                    $basePath = JPATH_SITE . '/media/' . $extractDir . '/';
                    require_once JPATH_RSGALLERY2_ADMIN . 'includes/video.utils.php';
                    Ffmpeg::capturePreviewImage($basePath . $filename, $basePath . $filename . '.png');
                    $displayImage = $filename . '.png';
                    $i++;
                } else {
                    if (!in_array($ext, $allowed_ext)) {
                        continue;
                    } else {
                        $displayImage = $filename;
                        $i++;
                    }
                }
            }
            ?>
            <td align="center" valign="top" bgcolor="#CCCCCC">
                <table class="adminform" border="0" cellspacing="1" cellpadding="1">
                    <tr>
                        <th colspan="2">&nbsp;</th>
                    </tr>
                    <tr>
                        <td colspan="2" align="right"><?php 
            echo JText::_('Delete');
            ?>
 #<?php 
            echo $i - 1;
            ?>
: <input type="checkbox" name="delete[<?php 
            echo $i - 1;
            ?>
]" value="true" /></td>
                    </tr>
                    <tr>
                        <td align="center" colspan="2"><img src="<?php 
            echo JURI_SITE . "/media/" . $extractDir . "/" . $displayImage;
            ?>
" alt="" border="1" width="100" align="center" /></td>
                    </tr>
                    <input type="hidden" value="<?php 
            echo $filename;
            ?>
" name="filename[]" />
                    <tr>
                        <td><?php 
            echo JText::_('Title');
            ?>
</td>
                        <td>
                            <input type="text" name="ptitle[]" size="15" />
                        </td>
                    </tr>
                    <tr>
                        <td><?php 
            echo JText::_('Gallery');
            ?>
</td>
                        <td><?php 
            if ($selcat == 1 && $xcat !== '0') {
                ?>
                                <input type="text" name="cat_text" value="<?php 
                echo htmlspecialchars(stripslashes(galleryUtils::getCatnameFromId($xcat)));
                ?>
" readonly />
                                <input type="hidden" name="category[]" value="<?php 
                echo $xcat;
                ?>
" />
                                <?php 
            } else {
                echo galleryUtils::galleriesSelectList(null, 'category[]', false);
            }
            ?>
                        </td>
                    </tr>
                    <tr>
                        <td><?php 
            echo JText::_('Description');
            ?>
</td>
                        <td><textarea cols="15" rows="2" name="descr[]"></textarea></td>
                    </tr>
                </table>
            </td>
            <?php 
            if ($k == 5) {
                echo "</tr><tr>";
                $k = 0;
            }
        }
        ?>
			</table>

			<input type="hidden" name="teller" value="<?php 
        echo $i;
        ?>
" />
			<input type="hidden" name="extractdir" value="<?php 
        echo $extractDir;
        ?>
" />
			<input type="hidden" name="option" value="com_rsgallery2" />
        	<input type="hidden" name="rsgOption" value="<?php 
        echo $rsgOption;
        ?>
" />
			<input type="hidden" name="task" value="save_batchupload" />

			</form>
        <?php 
    }
    /**
     * This will show the images, available to the logged in users in the My Galleries screen
     * under the tab "My Images".
     * @param array Result array with image details for the logged in users
     * @param array Result array with pagenav details
     */
    function showMyImages($images, $pageNav)
    {
        global $rsgAccess;
        JHTML::_('behavior.tooltip');
        ?>
        <table width="100%" class="adminlist" border="1">
        <tr>
            <td colspan="4"><h3><?php 
        echo JText::_('My Images');
        ?>
</h3></td>
        </tr>
        <tr>
            <th colspan="4"><div align="right"><?php 
        echo $pageNav->getLimitBox();
        ?>
</div></th>
        </tr>
        <tr>
            <th><?php 
        echo JText::_('Name');
        ?>
</th>
            <th><?php 
        echo JText::_('Gallery');
        ?>
</th>
            <th width="75"><?php 
        echo JText::_('Delete');
        ?>
</th>
            <th width="75"><?php 
        echo JText::_('Edit');
        ?>
</th>
        </tr>
        
        <?php 
        if (count($images) > 0) {
            ?>
            <script type="text/javascript">
					//<![CDATA[
				function deleteImage(id)
				{
					var yesno = confirm ('<?php 
            echo JText::_('Are you sure you want to delete this image?');
            ?>
');
					if (yesno == true) {
						location = 'index.php?option=com_rsgallery2&rsgOption=myGalleries&task=deleteItem&id='+id;
					}
				}
				//]]>
            </script>
            <?php 
            foreach ($images as $image) {
                global $rsgConfig;
                ?>
                <tr>
                    <td>
                        <?php 
                if (!$rsgAccess->checkGallery('up_mod_img', $image->gallery_id)) {
                    echo $image->name;
                } else {
                    //tooltip: tip, tiptitle, tipimage, tiptext, url, depreciated bool=1
                    echo JHTML::tooltip('<img src="' . JURI::root() . $rsgConfig->get('imgPath_thumb') . '/' . $image->name . '.jpg" alt="' . $image->name . '" />', $image->name, "", htmlspecialchars($image->title, ENT_QUOTES, 'UTF-8') . '&nbsp;(' . $image->name . ')', "index.php?option=com_rsgallery2&rsgOption=myGalleries&task=editItem&id=" . $image->id, 1);
                }
                ?>
                    </td>
                    <td><?php 
                echo galleryUtils::getCatnameFromId($image->gallery_id);
                ?>
</td>
                    <td>
                        <?php 
                if (!$rsgAccess->checkGallery('del_img', $image->gallery_id)) {
                    ?>
                            <div align="center">
                                <img src="<?php 
                    echo JURI_SITE;
                    ?>
/components/com_rsgallery2/images/no_delete.png" alt="" width="12" height="12" >
                            </div>
                            <?php 
                } else {
                    ?>
                        <a href="javascript:deleteImage(<?php 
                    echo $image->id;
                    ?>
);">
                            <div align="center">
                                <img src="<?php 
                    echo JURI_SITE;
                    ?>
/components/com_rsgallery2/images/delete.png" alt="" width="12" height="12" >
                            </div>
                        </a>
                        <?php 
                }
                ?>
                    </td>
                    <td>
                        <?php 
                if (!$rsgAccess->checkGallery('up_mod_img', $image->gallery_id)) {
                    ?>
                            <div align="center">
                                <img src="<?php 
                    echo JURI_SITE;
                    ?>
/components/com_rsgallery2/images/no_edit.png" alt="" width="15" height="15" >
                            </div>
                            <?php 
                } else {
                    ?>
                        <a href="<?php 
                    echo JRoute::_("index.php?option=com_rsgallery2&rsgOption=myGalleries&task=editItem&id={$image->id}");
                    ?>
">
                        <div align="center">
                            <img src="<?php 
                    echo JURI_SITE;
                    ?>
/components/com_rsgallery2/images/edit.png" alt="" width="15" height="15" >
                        </div>
                        </a>
                        <?php 
                }
                ?>
                    </td>
                </tr>
                <?php 
            }
        } else {
            ?>
            <tr><td colspan="4"><?php 
            echo JText::_('No images in user galleries');
            ?>
</td></tr>
            <?php 
        }
        ?>
            <tr>
                <th colspan="4">
                	<div align="center">
                		<?php 
        echo $pageNav->getPagesLinks();
        echo "<br>" . $pageNav->getPagesCounter();
        ?>
                	</div>
                </th>
            </tr>
            </table>
            <?php 
    }