/**
  * dynamically output of  RSS feeds to display them in Cooliris
  *
  * @param integer $catid
  * @param integer $catallpages, Count of pages, if navigation active, otherwise 1
  * @param integer $currentpage, current site if navigation active, otherwise 0
  * @param array $rows, Pictures
  */
 function Joom_GetXMLFeed($catid, $catallpages, $currentpage, $rows)
 {
     $config = Joom_getConfig();
     header('Content-type: text/xml');
     $this->thumbnailpath = _JOOM_LIVE_SITE . $config->jg_paththumbs;
     $this->picturepath = _JOOM_LIVE_SITE . $config->jg_pathimages;
     $this->origpicturepath = _JOOM_LIVE_SITE . $config->jg_pathoriginalimages;
     $this->absolut_origpicturepath = JPATH_ROOT . DS . $config->jg_pathoriginalimages;
     $this->catid = $catid;
     $this->catpath = Joom_GetCatPath($this->catid);
     $this->catallpages = $catallpages;
     $this->currentpage = $currentpage;
     $this->rows = $rows;
     ob_clean();
     echo $this->Joom_GetRSS();
     exit;
 }
 /**
  * JAVA Applet upload
  * @param Kategorie id of destination category
  */
 function Upload_AppletReceive_Backend($catid)
 {
     // If the applet checks for the serverProtocol, it issues a HEAD request
     // -> Simply return an empty doc.
     if ($_SERVER['REQUEST_METHOD'] == 'HEAD') {
         jexit();
     }
     $config = Joom_getConfig();
     $database =& JFactory::getDBO();
     $user =& JFactory::getUser();
     $debugoutput = '';
     //The Applet recognize an error with the text 'JOOMGALLERYUPLOADERROR'
     //and shows them within an JS alert box
     //check common requirements
     //no catid
     if ($catid == 0) {
         jexit('JOOMGALLERYUPLOADERROR ' . JText::_('JGA_JUPLOAD_YOU_MUST_SELECT_CATEGORY'));
     }
     //non common title
     if (!$config->jg_useorigfilename && empty($this->gentitle)) {
         jexit('JOOMGALLERYUPLOADERROR ' . JText::_('JGA_JUPLOAD_PICTURE_MUST_HAVE_TITLE'));
     }
     //Category path
     $catpath = Joom_GetCatPath($catid);
     foreach ($_FILES as $file => $fileArray) {
         //If 'delete originals' chosen in backend and the picture
         //shall be uploaded resized this will be done locally in the applet
         //then only the detail picture will be uploaded
         //therefore adjust path of destination category
         if ($config->jg_delete_original && $config->jg_resizetomaxwidth) {
             $no_original = true;
             $picpath = $config->jg_pathimages;
         } else {
             $no_original = false;
             $picpath = $config->jg_pathoriginalimages;
         }
         $screenshot = $fileArray["tmp_name"];
         $screenshot_name = $fileArray["name"];
         $screenshot_name = Joom_FixFilename($screenshot_name);
         $tag = strtolower(JFile::getExt($screenshot_name));
         //check the possible available memory for picture resizing
         //if not available echo error message and continue with next picture
         if ($this->Upload_CheckMemory($debugoutput, $screenshot, $tag) == false) {
             $this->debug = 1;
             continue;
         }
         //Create new filename
         //if generic filename setted in backend use them
         if ($config->jg_useorigfilename) {
             $screenshot_name = Joom_FixFilename($screenshot_name);
             $newfilename = $this->Upload_GenFilename($screenshot_name, $tag);
         } else {
             $screenshot_name = Joom_FixFilename($this->gentitle);
             $newfilename = $this->Upload_GenFilename($screenshot_name, $tag);
         }
         //Move uploaded picture in destination folder (original or details)
         if (strlen($screenshot) > 0 && $screenshot != 'none') {
             $returnval = JFile::upload($screenshot, JPATH_ROOT . DS . $picpath . $catpath . $newfilename);
             if (!$returnval) {
                 $debugoutput .= JText::_('JGA_WRONG_FILENAME') . ': ' . JPATH_ROOT . DS . $picpath . $catpath . $newfilename . '<br />';
                 $this->debug = 1;
                 continue;
             }
             Joom_Chmod(JPath::clean(JPATH_ROOT . DS . $picpath . $catpath . $newfilename));
             if (!$returnval) {
                 $debugoutput .= JPath::clean(JPATH_ROOT . DS . $picpath . $catpath . $newfilename) . ': ' . JText::_('JGA_CHECK_PERMISSIONS');
                 $this->Upload_Rollback($debugoutput, JPATH_ROOT . DS . $picpath . $catpath . $newfilename, null, null);
                 $this->debug = 1;
                 continue;
             }
             //Create thumbnail
             $returnval = Joom_ResizeImage($debugoutput, JPATH_ROOT . DS . $picpath . $catpath . $newfilename, JPATH_ROOT . DS . $config->jg_paththumbs . $catpath . $newfilename, $config->jg_useforresizedirection, $config->jg_thumbwidth, $config->jg_thumbheight, $config->jg_thumbcreation, $config->jg_thumbquality);
             if (!$returnval) {
                 $debugoutput .= JText::_('JGA_WRONG_FILENAME') . ': ' . JPATH_ROOT . DS . $config->jg_paththumbs . $catpath . $newfilename;
                 $this->Upload_Rollback($debugoutput, JPATH_ROOT . DS . $picpath . $catpath . $newfilename, null, JPATH_ROOT . DS . $config->jg_paththumbs . $catpath . $newfilename);
                 $this->debug = 1;
                 continue;
             }
             $debugoutput .= JText::_('JGA_THUMBNAIL_CREATED') . "\n";
             //evtl. create detail picture
             //not if 'delete originals' and resize setted in backend
             //In this case the applet made the resize and upload the detail picture
             if (!$no_original) {
                 if ($config->jg_resizetomaxwidth && ($this->create_special_gif != 1 || $tag != 'gif' && $tag != 'png')) {
                     $returnval = Joom_ResizeImage($debugoutput, JPATH_ROOT . DS . $picpath . $catpath . $newfilename, JPATH_ROOT . DS . $config->jg_pathimages . $catpath . $newfilename, false, $config->jg_maxwidth, false, $config->jg_thumbcreation, $config->jg_picturequality, true);
                     if (!$returnval) {
                         $debugoutput .= JText::_('JGA_WRONG_FILENAME') . ': ' . JPATH_ROOT . DS . $config->jg_paththumbs . $catpath . $newfilename;
                         continue;
                     }
                     $debugoutput .= JText::_('JGA_RESIZED_TO_MAXWIDTH') . "\n";
                 } else {
                     $returnval = JFile::copy($picpath . $catpath . $newfilename, $config->jg_pathimages . $catpath . $newfilename, JPATH_ROOT);
                     if (!$returnval) {
                         $debugoutput .= JText::_('JGA_PROBLEM_COPYING ') . $config->jg_pathimages . $catpath . $newfilename;
                         $this->Upload_Rollback($debugoutput, JPATH_ROOT . DS . $picpath . $catpath . $newfilename, null, JPATH_ROOT . DS . $config->jg_paththumbs . $catpath . $newfilename);
                         $this->debug = 1;
                         continue;
                     }
                 }
                 $returnval = Joom_Chmod(JPath::clean(JPATH_ROOT . DS . $config->jg_pathimages . $catpath . $newfilename));
                 if (!$returnval) {
                     $debugoutput .= JPATH_ROOT . DS . $config->jg_pathimages . $catpath . $newfilename . ' ' . JText::_('JGA_CHECK_PERMISSIONS');
                     $this->Upload_Rollback($debugoutput, JPATH_ROOT . DS . $picpath . $catpath . $newfilename, JPATH_ROOT . DS . $config->jg_pathimages . $catpath . $newfilename, JPATH_ROOT . DS . $config->jg_paththumbs . $catpath . $newfilename);
                     $this->debug = 1;
                     continue;
                 }
             }
             //Delete original picture only if setted in upload window
             //not if setted in backend
             if ($config->jg_delete_original == 2 && $this->original_delete == 1) {
                 if (JFile::delete(JPATH_ROOT . DS . $config->jg_pathoriginalimages . $catpath . $newfilename)) {
                     $debugoutput .= JText::_('JGA_ORIGINAL_DELETED');
                 } else {
                     $debugoutput .= JText::_('JGA_PROBLEM_DELETING_ORIGINAL') . ': ' . JPath::clean(JPATH_ROOT . DS . $config->jg_pathoriginalimages) . ' ' . JText::_('JGA_CHECK_PERMISSIONS');
                     $this->Upload_Rollback($debugoutput, JPATH_ROOT . DS . $picpath . $catpath . $newfilename, JPATH_ROOT . DS . $config->jg_pathimages . $catpath . $newfilename, JPATH_ROOT . DS . $config->jg_paththumbs . $catpath . $newfilename);
                     $this->debug = 1;
                 }
             }
             //new entry for ordering
             $ordering = $this->Upload_GetOrdering($config->jg_uploadorder, $catid);
             $batchtime = mktime();
             if ($config->jg_useorigfilename) {
                 $fileextensionlength = strlen($tag);
                 $filenamelength = strlen($screenshot_name);
                 $imgname = substr($screenshot_name, -$filenamelength, -$fileextensionlength - 1);
             } else {
                 $imgname = $this->gentitle;
             }
             $query = "INSERT INTO #__joomgallery(id, catid, imgtitle, imgauthor,\n            imgtext, imgdate, imgcounter, imgvotes,\n            imgvotesum, published, imgfilename, imgthumbname,\n            checked_out,owner,approved, ordering)\n            VALUES\n            (NULL, '{$catid}', '{$imgname}', '{$this->photocred}',\n            '{$this->gendesc}', '{$batchtime}', '0', '0',\n            '0', '1', '{$newfilename}', '{$newfilename}',\n            '0', '" . $user->get('id') . "', 1, '{$ordering}')";
             $database->setQuery($query);
             if (!$database->query()) {
                 $debugoutput .= $database->getErrorMsg();
                 $this->Upload_Rollback($debugoutput, JPATH_ROOT . DS . $picpath . $catpath . $newfilename, JPATH_ROOT . DS . $config->jg_pathimages . $catpath . $newfilename, JPATH_ROOT . DS . $config->jg_paththumbs . $catpath . $newfilename);
                 $this->debug = 1;
             }
         } else {
             $debugoutput .= JText::_('JGA_WRONG_FILENAME');
             $this->debug = 1;
         }
     }
     if ($this->debug) {
         echo "\nJOOMGALLERYUPLOADERROR\n";
     } else {
         echo "\nJOOMGALLERYUPLOADSUCCESS\n";
     }
     echo $debugoutput;
     jexit();
 }
 /**
 * Loeschen eines Bildes
 */
 function Joom_User_DeletePic()
 {
     $config = Joom_getConfig();
     $mainframe =& JFactory::getApplication('site');
     $database =& JFactory::getDBO();
     $user =& JFactory::getUser();
     jimport('joomla.filesystem.file');
     if ($this->userid != $user->get('id') && !$this->adminlogged) {
         $mainframe->redirect(JRoute::_($this->userpanel_url . _JOOM_ITEMID, false), JText::_('JGS_ALERT_NOT_ALLOWED_DELETE_PICTURE'));
     }
     if ($this->picid) {
         $row = new mosjoomgallery($database);
         $row->load($this->picid);
         $catpath = Joom_GetCatPath($row->catid);
         //Detailbild loeschen
         if (JFile::delete(JPATH_ROOT . DS . $config->jg_pathimages . DS . $catpath . $row->imgfilename)) {
             //Thumb loeschen
             if (JFile::delete(JPATH_ROOT . DS . $config->jg_paththumbs . DS . $catpath . $row->imgthumbname)) {
                 // ggf. Originalbild loeschen
                 if (file_exists(JPATH_ROOT . DS . $config->jg_pathoriginalimages . $catpath . $row->imgfilename)) {
                     JFile::delete(JPATH_ROOT . DS . $config->jg_pathoriginalimages . $catpath . $row->imgfilename);
                 }
                 //Kommentare loeschen
                 $database->setQuery(" DELETE \n                                FROM \n                                  #__joomgallery_comments\n                                WHERE \n                                  cmtpic={$this->picid}\n                              ");
                 if (!$database->query()) {
                     echo "<script> alert('" . $database->getErrorMsg() . "'); window.history.go(-1); </script>\n";
                 }
                 //Namensschilder loeschen
                 $database->setQuery(" DELETE \n                                FROM \n                                  #__joomgallery_nameshields\n                                WHERE \n                                  nid = {$this->picid}\n                              ");
                 if (!$database->query()) {
                     echo "<script> alert('" . $database->getErrorMsg() . "'); window.history.go(-1); </script>\n";
                 }
                 //Bild loeschen
                 $database->setQuery(" DELETE \n                                FROM \n                                  #__joomgallery\n                                WHERE \n                                  id = {$this->picid}\n                              ");
                 if (!$database->query()) {
                     echo "<script> alert('" . $database->getErrorMsg() . "'); window.history.go(-1); </script>\n";
                 }
             } else {
                 die(JText::_('JGS_COULD_NOT_DELETE_THUMBNAIL_FILE'));
             }
         } else {
             die(JText::_('JGS_COULD_NOT_DELETE_PICTURE_FILE'));
         }
         $mainframe->redirect(JRoute::_($this->userpanel_url . _JOOM_ITEMID, false), JText::_('JGS_ALERT_PICTURE_AND_COMMENTS_DELETED'));
     }
 }
    /**
     * Aenderung der Eintraege zu dem Bild
     *
     * @param unknown_type $row
     */
    function Joom_User_EditPic_HTML(&$row, &$clist)
    {
        $config = Joom_getConfig();
        $user =& JFactory::getUser();
        $catpath = Joom_GetCatPath($row->catid);
        ?>
  <div class="sectiontableheader">
    <?php 
        echo JText::_('JGS_EDIT_PICTURE');
        ?>
 
  </div>
  <div class="jg_editpicture">
    <form action = "<?php 
        echo JRoute::_('index.php?option=com_joomgallery&func=savepic' . _JOOM_ITEMID);
        ?>
" method="post" name="adminForm"
    enctype="multipart/form-data" onsubmit="return joom_checkme2();" >
    <div class="jg_uprow">
      <div class="jg_uptext">
        <?php 
        echo JText::_('JGS_TITLE');
        ?>
:
      </div>
      <input class="inputbox" type="text" name="imgtitle" size="42" maxlength="100"
      value = "<?php 
        echo htmlspecialchars($row->imgtitle, ENT_QUOTES, 'UTF-8');
        ?>
" />
    </div>
    <div class="jg_uprow">
      <div class="jg_uptext">
        <?php 
        echo JText::_('JGS_CATEGORY');
        ?>
:
      </div>
      <?php 
        echo $clist;
        ?>
    </div>
    <div class="jg_uprow">
      <div class="jg_uptext">
        <?php 
        echo JText::_('JGS_DESCRIPTION');
        ?>
:
      </div>
      <textarea class="inputbox" cols="40" rows="5" name="imgtext"><?php 
        echo htmlspecialchars($row->imgtext, ENT_QUOTES, 'UTF-8');
        ?>
</textarea>
    </div>
    <div class="jg_uprow">
      <div class="jg_uptext">
        <?php 
        echo JText::_('JGS_AUTHOR_OWNER');
        ?>
:
      </div>
      <b><?php 
        echo $user->get('username');
        ?>
</b>
    </div>
    <div class="jg_uprow">
      <div class="jg_uptext">
        <?php 
        echo JText::_('JGS_PICTURE');
        ?>
:
      </div>
      <img src="<?php 
        echo _JOOM_LIVE_SITE . $config->jg_paththumbs . $catpath . $row->imgthumbname;
        ?>
" name="imagelib" width="80" border="2" alt="<?php 
        echo JText::_('JGS_THUMBNAIL_PREVIEW');
        ?>
" />
    </div>
    <div class="jg_txtrow">
      <input type="submit" value="<?php 
        echo JText::_('JGS_SAVE');
        ?>
" class="button" />
      <input type="button" name="Button" value="<?php 
        echo JText::_('JGS_CANCEL');
        ?>
"
        onclick = "javascript:location.href='<?php 
        echo JRoute::_('index.php?option=com_joomgallery&func=userpanel' . _JOOM_ITEMID, false);
        ?>
';"
        class="button" />
    </div>
    <input type="hidden" name="id" value="<?php 
        echo $row->id;
        ?>
" />
    </form>
  </div>
<?php 
    }
    function Joom_ShowCategoryBody_HTML(&$rows, &$rowcounter, &$colum, $order_by, &$order_dir)
    {
        global $id;
        $config = Joom_getConfig();
        $document =& JFactory::getDocument();
        $mainframe =& JFactory::getApplication('site');
        $database =& JFactory::getDBO();
        $user =& JFactory::getUser();
        //wenn jg_cooliris = true, dann zusaetzlich XML im head aufbauen
        if ($config->jg_cooliris && count($rows) > 0) {
            $href = _JOOM_LIVE_SITE . $this->viewcategory_url . $this->catid . '&startpage=' . $this->catstartpage . '&cooliris=1' . _JOOM_ITEMID;
            $attribs = array('id' => 'joomgallery', 'type' => 'application/rss+xml', 'title' => 'Cooliris');
            $document->addHeadLink($href, 'alternate', 'rel', $attribs);
            if ($config->jg_coolirislink) {
                $document->addScript('http://lite.piclens.com/current/piclens.js');
                echo '<a id="jg_cooliris" href="javascript:PicLensLite.start({feedUrl:\'' . _JOOM_LIVE_SITE . $this->viewcategory_url . $this->catid . '&startpage=' . $this->catstartpage . _JOOM_ITEMID . '&cooliris=1\'});">' . JText::_('JGS_COOLIRISLINK_TEXT') . '</a>';
            }
        }
        if (!$config->jg_showtitle && !$config->jg_showhits && !$config->jg_showauthor && !$config->jg_showowner && !$config->jg_showcatrate && !$config->jg_showcatcom && !$config->jg_showcatdescription) {
            $show_text = false;
        } else {
            $show_text = true;
        }
        $num_rows = ceil(count($rows) / $colum);
        $index = 0;
        $count_pics = count($rows);
        ?>
  <a name="category"></a>
<?php 
        if ($count_pics > 0) {
            for ($row_count = 0; $row_count < $num_rows; $row_count++) {
                $linecolor = ($row_count + 1) % 2 + 1;
                ?>
  <div class="jg_row <?php 
                if ($linecolor == 1) {
                    echo "sectiontableentry1";
                } else {
                    echo "sectiontableentry2";
                }
                ?>
">
<?php 
                for ($col_count = 0; $col_count < $colum && $index < $count_pics; $col_count++) {
                    $ii = 1;
                    $row1 = $rows[$index];
                    if ($config->jg_showpicasnew) {
                        $isnew = Joom_CheckNew($row1->imgdate, $config->jg_daysnew);
                    }
                    $catpath = Joom_GetCatPath($row1->cid);
                    if ($config->jg_showdetailpage == 0 && $user->get('aid') != 0 || $config->jg_showdetailpage == 1) {
                        $link = Joom_OpenImage($config->jg_detailpic_open, $row1->id, $catpath, $row1->cid, $row1->imgfilename, $row1->imgtitle, $row1->imgtext);
                    } else {
                        $link = "javascript:alert('" . JText::_('JGS_ALERT_NO_DETAILVIEW_FOR_GUESTS', true) . "')";
                    }
                    ?>
    <div class="jg_element_cat">
      <a href="<?php 
                    echo $link;
                    ?>
" class="jg_catelem_photo">
        <img src="<?php 
                    echo _JOOM_LIVE_SITE . $config->jg_paththumbs . $catpath . $row1->imgthumbname;
                    ?>
" class="jg_photo" alt="<?php 
                    echo $row1->imgtitle;
                    ?>
" />
      </a>
<?php 
                    if ($show_text) {
                        ?>
      <div class="jg_catelem_txt">
        <ul>
<?php 
                        if ($config->jg_showtitle || $config->jg_showpicasnew) {
                            ?>
          <li>
<?php 
                            if ($config->jg_showtitle) {
                                ?>
            <b><?php 
                                echo $row1->imgtitle;
                                ?>
</b>
<?php 
                            }
                            if ($config->jg_showpicasnew) {
                                ?>
            <?php 
                                echo $isnew;
                                ?>
&nbsp;
<?php 
                            }
                            ?>
          </li>
<?php 
                        }
                        if ($config->jg_showauthor) {
                            if ($row1->imgauthor) {
                                $authorowner = $row1->imgauthor;
                            } elseif ($config->jg_showowner) {
                                $authorowner = Joom_GetDisplayName($row1->owner);
                            } else {
                                $authorowner = JText::_('JGS_NO_DATA');
                            }
                            ?>
          <li>
            <?php 
                            echo JText::_('JGS_AUTHOR') . ": " . $authorowner;
                            ?>
&nbsp;
          </li>
<?php 
                        }
                        if ($config->jg_showhits) {
                            ?>
          <li>
            <?php 
                            echo JText::_('JGS_HITS') . ": " . $row1->imgcounter;
                            ?>
&nbsp;
          </li>
<?php 
                        }
                        if ($config->jg_showcatrate) {
                            if ($row1->imgvotes > 0) {
                                $fimgvotesum = number_format($row1->imgvotesum / $row1->imgvotes, 2, ',', '.');
                                if ($row1->imgvotes == 1) {
                                    $frating = $fimgvotesum . ' (' . $row1->imgvotes . ' ' . JText::_('JGS_ONE_VOTE') . ')';
                                } else {
                                    $frating = $fimgvotesum . ' (' . $row1->imgvotes . ' ' . JText::_('JGS_VOTES') . ')';
                                }
                            } else {
                                $frating = JText::_('JGS_NO_VOTES');
                            }
                            ?>
          <li>
            <?php 
                            echo JText::_('JGS_RATING') . ": " . $frating;
                            ?>
&nbsp;
          </li>
<?php 
                        }
                        if ($config->jg_showcatcom) {
                            # Check how many comments exist
                            $database->setQuery(" SELECT \n                                        COUNT(cmtid)\n                                      FROM \n                                        #__joomgallery_comments\n                                      WHERE \n                                               cmtpic = '{$row1->id}' \n                                        AND published ='1' \n                                        AND approved = '1'\n                                    ");
                            $comments = $database->LoadResult();
                            ?>
          <li>
            <?php 
                            echo JText::_('JGS_COMMENTS') . ": " . $comments;
                            ?>
 
          </li>
<?php 
                        }
                        if ($config->jg_showcatdescription == 1 && $row1->imgtext) {
                            ?>
          <li>
            <?php 
                            echo JText::_('JGS_DESCRIPTION') . ": " . $row1->imgtext;
                            ?>
&nbsp;
          </li>
<?php 
                        }
                        $mainframe->triggerEvent('onAfterDisplayJoomThumb', array($row1->id));
                        $li_tag_set = false;
                        if (is_file(JPath::clean(JPATH_ROOT . DS . $config->jg_pathoriginalimages . $catpath . $row1->imgfilename)) || $config->jg_downloadfile != 1) {
                            if ($config->jg_showcategorydownload == 1 && $user->get('aid') >= 1 || $config->jg_showcategorydownload == 2 && $user->get('aid') == 2 || $config->jg_showcategorydownload == 3) {
                                ?>
          <li>
            <a href="<?php 
                                echo JRoute::_('index.php?option=com_joomgallery&func=download&catid=' . $row1->catid . '&id=' . $row1->id . _JOOM_ITEMID);
                                ?>
"
                onMouseOver="return overlib('<?php 
                                echo JText::_('JGS_DOWNLOAD_TOOLTIP_TEXT', true);
                                ?>
', CAPTION, '<?php 
                                echo JText::_('JGS_DOWNLOAD_TOOLTIP_CAPTION', true);
                                ?>
', BELOW, RIGHT);" onmouseout="return nd();">
              <img src="<?php 
                                echo _JOOM_LIVE_SITE . 'components/com_joomgallery/assets/images/download.png';
                                ?>
" alt="<?php 
                                echo JText::_('JGS_DOWNLOAD_TOOLTIP_CAPTION');
                                ?>
" class="pngfile jg_icon" />
            </a>
<?php 
                                $li_tag_set = true;
                            } elseif ($config->jg_showcategorydownload == 1 && $user->get('aid') < 1) {
                                ?>
          <li>
            <span onMouseOver="return overlib('<?php 
                                echo JText::_('JGS_DOWNLOAD_TOOLTIP_TEXT_LOGIN', true);
                                ?>
', CAPTION, '<?php 
                                echo JText::_('JGS_DOWNLOAD_TOOLTIP_CAPTION', true);
                                ?>
', BELOW, RIGHT);" onmouseout="return nd();" >
              <img src="<?php 
                                echo _JOOM_LIVE_SITE . 'components/com_joomgallery/assets/images/download_gr.png';
                                ?>
" alt="<?php 
                                echo JText::_('JGS_DOWNLOAD_TOOLTIP_CAPTION');
                                ?>
"  class="pngfile jg_icon" />
            </span>
<?php 
                                $li_tag_set = true;
                            }
                        }
                        if ($config->jg_favourites == 1 && $config->jg_showcategoryfavourite) {
                            if ($config->jg_showdetailfavourite == 0 && $user->get('aid') >= 1 || $config->jg_showdetailfavourite == 1 && $user->get('aid') == 2 || $config->jg_usefavouritesforpubliczip == 1 && $user->get('aid') < 1) {
                                if ($config->jg_usefavouritesforzip == 1 || $config->jg_usefavouritesforpubliczip == 1 && $user->get('aid') < 1) {
                                    if (!$li_tag_set) {
                                        $li_tag_set = true;
                                        ?>
          <li>
<?php 
                                    }
                                    ?>
            <a href="<?php 
                                    echo JRoute::_('index.php?option=com_joomgallery&func=addpicture&id=' . $row1->id . '&catid=' . $row1->catid . _JOOM_ITEMID);
                                    ?>
"
                onMouseOver="return overlib('<?php 
                                    echo JText::_('JGS_ZIP_ADD_PICTURE_TOOLTIP_TEXT', true);
                                    ?>
', CAPTION, '<?php 
                                    echo JText::_('JGS_ZIP_ADD_PICTURE_TOOLTIP_CAPTION', true);
                                    ?>
', BELOW, RIGHT);" onmouseout="return nd();" >
              <img src="<?php 
                                    echo _JOOM_LIVE_SITE . 'components/com_joomgallery/assets/images/basket_put.png';
                                    ?>
" alt="<?php 
                                    echo JText::_('JGS_ZIP_ADD_PICTURE_TOOLTIP_CAPTION');
                                    ?>
"  class="pngfile jg_icon" />
            </a>
<?php 
                                } else {
                                    if (!$li_tag_set) {
                                        $li_tag_set = true;
                                        ?>
          <li>
<?php 
                                    }
                                    ?>
            <a href="<?php 
                                    echo JRoute::_('index.php?option=com_joomgallery&func=addpicture&id=' . $row1->id . '&catid=' . $row1->catid . _JOOM_ITEMID);
                                    ?>
"
                onMouseOver="return overlib('<?php 
                                    echo JText::_('JGS_FAV_ADD_PICTURE_TOOLTIP_TEXT', true);
                                    ?>
', CAPTION, '<?php 
                                    echo JText::_('JGS_FAV_ADD_PICTURE_TOOLTIP_CAPTION', true);
                                    ?>
', BELOW, RIGHT);" onmouseout="return nd();">
              <img src="<?php 
                                    echo $this->assetsimages_url . 'star.png';
                                    ?>
" alt="<?php 
                                    echo JText::_('JGS_FAV_ADD_PICTURE_TOOLTIP_CAPTION');
                                    ?>
" class="pngfile jg_icon" />
            </a>
<?php 
                                }
                            } elseif ($config->jg_favouritesshownotauth == 1) {
                                if ($config->jg_usefavouritesforzip == 1) {
                                    if (!$li_tag_set) {
                                        $li_tag_set = true;
                                        ?>
          <li>
<?php 
                                    }
                                    ?>
            <span onMouseOver="return overlib('<?php 
                                    echo JText::_('JGS_ZIP_ADD_PICTURE_NOT_ALLOWED_TOOLTIP_TEXT', true);
                                    ?>
', CAPTION, '<?php 
                                    echo JText::_('JGS_ZIP_ADD_PICTURE_TOOLTIP_CAPTION', true);
                                    ?>
', BELOW, RIGHT);" onmouseout="return nd();" >
              <img src="<?php 
                                    echo $this->assetsimages_url . 'basket_put_gr.png';
                                    ?>
" alt="<?php 
                                    echo JText::_('JGS_ZIP_ADD_PICTURE_TOOLTIP_CAPTION');
                                    ?>
"  class="pngfile jg_icon" />
            </span>
<?php 
                                } else {
                                    if (!$li_tag_set) {
                                        $li_tag_set = true;
                                        ?>
          <li>
<?php 
                                    }
                                    ?>
            <span onMouseOver="return overlib('<?php 
                                    echo JText::_('JGS_FAV_ADD_PICTURE_NOT_ALLOWED_TOOLTIP_TEXT', true);
                                    ?>
', CAPTION, '<?php 
                                    echo JText::_('JGS_FAV_ADD_PICTURE_TOOLTIP_CAPTION', true);
                                    ?>
', BELOW, RIGHT);" onmouseout="return nd();" >
              <img src="<?php 
                                    echo $this->assetsimages_url . 'star_gr.png';
                                    ?>
" alt="<?php 
                                    echo JText::_('JGS_FAV_ADD_PICTURE_TOOLTIP_CAPTION');
                                    ?>
"  class="pngfile jg_icon" />
            </span>
<?php 
                                }
                            }
                        }
                        if ($li_tag_set) {
                            ?>
          </li>
<?php 
                        }
                        ?>
        </ul>
      </div>
<?php 
                    }
                    ?>
    </div>
<?php 
                    $index++;
                }
                // for loop over cols in row
                ?>
    <div class="jg_clearboth"></div>
  </div>
<?php 
                $ii++;
            }
            // for loop over rows
            if ($config->jg_showcathead) {
                ?>
    <div class="sectiontableheader">
      &nbsp; 
    </div>
<?php 
            }
        }
        // if count($pics) > 0
    }
    /**
     * Category manager
     *
     * @param array $rows database rows of categeories
     * @param string $search
     * @param string $slist
     * @param string $olist
     * @param object $pageNav
     */
    function Joom_ShowCategories_HTML(&$rows, $search, &$slist, &$olist, $pageNav)
    {
        $config = Joom_getConfig();
        $database =& JFactory::getDBO();
        jimport('joomla.filesystem.file');
        ?>
<div id="overDiv" style="position:absolute; visibility:hidden; z-index:1000;"></div>
<script language="Javascript" src="../includes/js/overlib_mini.js"></script>
<form action="index.php" method="post" name="adminForm">
<table cellpadding="4" cellspacing="0" border="0" width="100%">
  <tr>
    <td width="100%"></td>
    <td>
      <?php 
        echo JText::_('JGA_SEARCH') . ':';
        ?>
<br />
      <input type="text" name="search" value="<?php 
        echo $search;
        ?>
"
       class="inputbox" onChange="document.adminForm.submit();" />
    </td>
    <td nowrap>
      <?php 
        echo JText::_('JGA_SORT_BY_ORDER');
        ?>
<br />
      <?php 
        echo $olist;
        ?>
    </td>
    <td>
      <?php 
        echo JText::_('JGA_SORT_BY_TYPE');
        ?>
<br />
      <?php 
        echo $slist;
        ?>
    </td>
  </tr>
  <tr>
    <td width="100%"></td>
  </tr>
</table>
<table width="100%" border="0" cellpadding="4" cellspacing="0" class="adminlist">
  <tr>
    <th width="20">
      <input type="checkbox" name="toggle" value=""
       onclick="checkAll(<?php 
        echo count($rows);
        ?>
);" />
    </th>
    <th width="10%"></th>
    <th width="5%" align="left">ID</th>
    <th width="85%" class="title">
      <?php 
        echo JText::_('JGA_CATEGORY');
        ?>
    </th>
    <th nowrap align="left">
      <?php 
        echo JText::_('JGA_PARENT_CATEGORY');
        ?>
    </th>
    <th nowrap>
      <?php 
        echo JText::_('JGA_PUBLISHED');
        ?>
    </th>
    <th width="5%">
      <?php 
        echo JText::_('JGA_OWNER');
        ?>
    </th>
    <th width="5%">
      <?php 
        echo JText::_('JGA_TYPE');
        ?>
    </th>
    <th nowrap>
      <?php 
        echo JText::_('JGA_HIT');
        ?>
    </th>
    <th colspan="2" nowrap>
      <div align="center">
        <?php 
        echo JText::_('JGA_REORDER');
        ?>
      </div>
    </th>
    <th align="center">
      <a href="javascript: saveorder(<?php 
        echo count($rows) - 1;
        ?>
)">
        <img src="images/filesave.png" border="0" width="16" height="16"
         alt="<?php 
        echo JText::_('JGA_SAVE_ORDER');
        ?>
" />
      </a>
    </th>
  </tr>
<?php 
        $k = 0;
        $i = 0;
        for ($i = 0, $n = count($rows); $i < $n; $i++) {
            $row =& $rows[$i];
            $catpath = Joom_GetCatPath($row->cid);
            ?>
  <tr class="row<?php 
            echo $k;
            ?>
">
    <td width="20">
      <input type="checkbox" id="cb<?php 
            echo $i;
            ?>
" name="cid[]"
       value="<?php 
            echo $row->cid;
            ?>
" onClick="isChecked(this.checked);" />
    </td>
    <td width="10%">
<?php 
            if ($row->catimage != '') {
                if (JFile::exists(JPATH_ROOT . DS . $config->jg_paththumbs . $catpath . $row->catimage)) {
                    $imginfo = getimagesize(JPath::clean(JPATH_ROOT . DS . $config->jg_paththumbs . $catpath . $row->catimage));
                    $imgsource = _JOOM_LIVE_SITE . $config->jg_paththumbs . $catpath . $row->catimage;
                    $srcWidth = $imginfo[0];
                    $srcHeight = $imginfo[1];
                    $thumbexists = 1;
                } else {
                    $thumbexists = 0;
                }
                if ($thumbexists) {
                    ?>
      <a href="#" onmouseover="return overlib('<img src=\'<?php 
                    echo $imgsource;
                    ?>
\' />',WIDTH,<?php 
                    echo $srcWidth;
                    ?>
, HEIGHT,<?php 
                    echo $srcHeight;
                    ?>
)"  onmouseout="return nd()"; alt=""/>
        <img src="<?php 
                    echo $imgsource;
                    ?>
" border="0" width="24" height="24" />
      </a>
<?php 
                } else {
                    ?>
      &nbsp;
<?php 
                }
            }
            ?>
    </td>
    <td width="5%" ><?php 
            echo $row->cid;
            ?>
</td>
    <td width="85%" >
      <div align="left">
        <a href="#edit" onclick="return listItemTask('cb<?php 
            echo $i;
            ?>
',
                                                     'editcatg')">
<?php 
            if ($row->parent > 0) {
                ?>
        &nbsp; &raquo;
<?php 
            }
            ?>
        <?php 
            echo $row->name;
            ?>
        </a>
      </div>
    </td>
    <td  align="center" nowrap>
      <?php 
            echo Joom_ShowCategoryPath($row->parent);
            ?>
    </td>
<?php 
            $task = $row->published ? 'unpublishcatg' : 'publishcatg';
            $img = $row->published ? 'tick.png' : 'publish_x.png';
            ?>
    <td width="10%" align="center" nowrap>
      <a href="javascript: void(0);"
       onClick="return listItemTask('cb<?php 
            echo $i;
            ?>
','<?php 
            echo $task;
            ?>
')">
        <img src="images/<?php 
            echo $img;
            ?>
" border="0" alt="" />
      </a>
    </td>
    <td width="5%" align="center">
<?php 
            if ($row->owner != null) {
                $owner = JFactory::getUser($row->owner);
                ?>
    <?php 
                echo Joom_GetDisplayName($row->owner, true);
                ?>
    [<?php 
                echo $config->jg_realname ? $owner->get('username') : $owner->get('name');
                ?>
&nbsp;(<?php 
                echo $row->owner;
                ?>
)]
<?php 
            } else {
                ?>
      Administrator[def]
<?php 
            }
            ?>
    </td>
    <td width="5%" align="center">
<?php 
            if ($row->owner != null) {
                ?>
      <img src="../includes/js/ThemeOffice/users.png"
       alt="<?php 
                echo JText::_('JGA_USER_UPLOAD');
                ?>
"
       title="<?php 
                echo JText::_('JGA_USER_UPLOAD');
                ?>
" />
<?php 
            } else {
                ?>
      <img src="../includes/js/ThemeOffice/credits.png"
       alt="<?php 
                echo JText::_('JGA_ADMIN_UPLOAD');
                ?>
"
       title="<?php 
                echo JText::_('JGA_ADMIN_UPLOAD');
                ?>
" />
<?php 
            }
            ?>
    </td>
    
    <td width="10%" align="center" nowrap>
      <?php 
            echo $row->groupname;
            ?>
    </td>
    <td>
<?php 
            if ($i > 0 || $i + $pageNav->limitstart > 0) {
                ?>
      <div align="center">
        <a href="#reorder" onclick="return listItemTask('cb<?php 
                echo $i;
                ?>
',
                                                        'orderupcatg')">
          <img src="images/uparrow.png" border="0"<?php 
                /* portierung: width und height entfernt */
                ?>
           alt="<?php 
                echo JText::_('JGA_UP');
                ?>
" />
        </a>
      </div>
<?php 
            } else {
                ?>
          &nbsp;
<?php 
            }
            ?>
    </td>
    <td>
<?php 
            if ($i < $n - 1 || $i + $pageNav->limitstart < $pageNav->total - 1) {
                ?>
      <div align="center">
        <a href="#reorder" onclick="return listItemTask('cb<?php 
                echo $i;
                ?>
',
                                                        'orderdowncatg')">
          <img src="images/downarrow.png" border="0"<?php 
                /* portierung: width und height entfernt */
                ?>
           alt="<?php 
                echo JText::_('JGA_DOWN');
                ?>
" />
        </a>
      </div>
<?php 
            }
            ?>
    </td>
    <td align="center">
      <input type="text" name="order[]" size="5" value="<?php 
            echo $row->ordering;
            ?>
"
       class="text_area" style="text-align: center" />
    </td>
<?php 
            $k = 1 - $k;
            ?>
  </tr>
<?php 
        }
        ?>
  <tr>
    <td colspan="12">
      <?php 
        echo $pageNav->getListFooter();
        ?>
    </td>
  </tr>
</table>
<input type="hidden" name="option" value="<?php 
        echo _JOOM_OPTION;
        ?>
" />
<input type="hidden" name="task" value="categories" />
<input type="hidden" name="boxchecked" value="0" />
<input type="hidden" name="returntask" value="catg" />
</form>
<?php 
    }
function Joom_LightboxImages($start, $end, $orderclause = null, $catid, $id)
{
    global $func;
    $config = Joom_getConfig();
    $database =& JFactory::getDBO();
    $user =& JFactory::getUser();
    if (($func == 'viewcategory' && $config->jg_detailpic_open > 3 && ($config->jg_showdetailpage == 1 || $config->jg_showdetailpage == 0 && $user->get('aid') > 0) || $func == 'detail' && ($config->jg_bigpic == 1 && $user->get('aid') > 0 || $config->jg_bigpic == 2) && $config->jg_bigpic_open > 3) && $end != 0 && $start < $end && $config->jg_lightbox_slide_all == 1) {
        if ($orderclause == null) {
            if ($config->jg_secondorder != '' && $config->jg_thirdorder == '') {
                $orderclause = "a." . $config->jg_firstorder . ", a." . $config->jg_secondorder;
            } elseif ($config->jg_secondorder != '' && $config->jg_thirdorder != '') {
                $orderclause = "a." . $config->jg_firstorder . ", a." . $config->jg_secondorder . ", a." . $config->jg_thirdorder;
            } else {
                $orderclause = "a." . $config->jg_firstorder;
            }
        }
        if ($func == 'detail') {
            $type = $end == 1 ? "before" : "after";
            $database->setQuery(" SELECT \n                              COUNT(id)\n                            FROM \n                              #__joomgallery\n                            WHERE \n                                      catid = {$catid} \n                              AND approved  = '1' \n                              AND published = '1'\n                          ");
            $end = $database->loadResult();
        }
        $database->setQuery(" SELECT \n                            id, \n                            imgfilename, \n                            imgthumbname, \n                            imgtitle\n                          FROM \n                            #__joomgallery AS a\n                          LEFT JOIN \n                            #__joomgallery_catg AS c ON c.cid=a.catid\n                          WHERE \n                               a.published = '1' \n                            AND a.catid    = {$catid} \n                            AND a.approved = '1' \n                            AND c.access  <= '" . $user->get('aid') . "'\n                          ORDER BY \n                            {$orderclause}\n                          LIMIT {$start}," . ($end - $start));
        $rows = $database->loadObjectList();
        $zaehl = 0;
        $check = 0;
        if ($func == 'detail' && $type == 'after') {
            while ($rows[$zaehl]->id != $id) {
                $zaehl++;
            }
            $zaehl++;
        } elseif ($func == 'detail' && $type == 'before' && $rows[$zaehl]->id == $id) {
            $check = 1;
        }
        echo "  <div class=\"jg_displaynone\">\n";
        while ($zaehl < sizeof($rows) && $check != 1) {
            if ($func == 'detail' && $type == 'before' && $rows[$zaehl]->id == $id) {
                $check = 1;
            }
            $row = $rows[$zaehl];
            $catpath = Joom_GetCatPath($catid);
            if ($func == 'detail' && is_file(JPath::clean(JPATH_ROOT . DS . $config->jg_pathoriginalimages . $catpath . $row->imgfilename)) || $func == 'viewcategory') {
                $link = Joom_OpenImage($config->jg_bigpic_open, $row->id, $catpath, $catid, $row->imgfilename, $row->imgtitle, '');
                echo "    <a href=\"" . $link . "\">" . $row->id . "</a>\n";
            }
            $zaehl++;
        }
        echo "  </div>\n";
    }
}
    /**
     * Class constructor
     *
     */
    function Joom_DetailView()
    {
        include_once JPATH_COMPONENT . DS . 'includes' . DS . 'html' . DS . 'joom.viewdetails.html.php';
        jimport('joomla.filesystem.file');
        $this->_mainframe =& JFactory::getApplication('site');
        $database =& JFactory::getDBO();
        $user =& JFactory::getUser();
        $config = Joom_getConfig();
        $this->id = JRequest::getInt('id', 0);
        $this->slideshow = trim(Joom_mosGetParam('jg_slideshow', '', 'post'));
        if ($config->jg_showdetailaccordion) {
            $this->toggler = 'class="joomgallery-toggler"';
            $this->slider = 'class="joomgallery-slider"';
        } else {
            $this->toggler = 'class="joomgallery-notoggler"';
            $this->slider = '';
        }
        $database->setQuery(" SELECT\n                            c.access AS access,\n                            c.name AS name,\n                            c.cid AS cid\n                          FROM\n                            #__joomgallery_catg AS c\n                          LEFT JOIN\n                            #__joomgallery AS a ON a.catid = c.cid\n                          WHERE\n                            a.id = {$this->id}\n                        ");
        if (!($catinfo = $database->loadObject())) {
            $this->_mainframe->redirect(JRoute::_('index.php?option=com_joomgallery&view=gallery' . _JOOM_ITEMID, false), JText::_('JGS_ALERT_NOT_ALLOWED_VIEW_PICTURE'));
        }
        $this->c_access = $catinfo->access;
        $this->cattitle = $catinfo->name;
        if ($user->get('aid') < $this->c_access) {
            $this->_mainframe->redirect(JRoute::_('index.php?option=com_joomgallery&view=gallery' . _JOOM_ITEMID, false), JText::_('JGS_ALERT_NOT_ALLOWED_VIEW_PICTURE'));
        }
        $database->setQuery(" SELECT\n                            a.id,\n                            a.catid,\n                            a.imgtitle,\n                            a.imgauthor,\n                            a.imgtext,\n                            a.imgdate,\n                            a.imgcounter,\n                            a.imgvotes,\n                            a.imgvotesum,\n                            a.published,\n                            a.imgfilename,\n                            a.imgthumbname,\n                            a.checked_out,\n                            a.owner,\n                            a.approved,\n                            a.useruploaded,\n                            a.ordering,\n                            u.username,\n                            ROUND(imgvotesum/imgvotes, 2) AS rating\n                          FROM\n                            #__joomgallery AS a\n                          LEFT JOIN\n                            #__users AS u ON u.id = a.owner\n                          WHERE\n                                a.id        = " . $this->id . "\n                            AND a.approved  = '1'\n                            AND a.published = '1'\n                        ");
        $result1 = $database->loadObject();
        $this->id = $result1->id;
        $this->catid = $result1->catid;
        $this->imgtitle = $result1->imgtitle;
        $this->imgauthor = $result1->imgauthor;
        $this->imgtext = $result1->imgtext;
        $this->imgdate = $result1->imgdate;
        $this->imgcounter = $result1->imgcounter;
        $this->imgvotes = $result1->imgvotes;
        $this->imgvotesum = $result1->imgvotesum;
        $this->published = $result1->published;
        $this->imgfilename = $result1->imgfilename;
        $this->imgthumbname = $result1->imgthumbname;
        $this->checked_out = $result1->checked_out;
        $this->imgowner = $result1->owner;
        $this->approved = $result1->approved;
        $this->useruploaded = $result1->useruploaded;
        $this->ordering = $result1->ordering;
        $this->imgownerid = $result1->username;
        $this->rating = $result1->rating;
        if ($this->published != 1 && $this->approved != 1) {
            $this->_mainframe->redirect(JRoute::_('index.php?option=com_joomgallery&view=gallery' . _JOOM_ITEMID, false), JText::_('JGS_ALERT_NOPICTURE_OR_NOTAPPROVED'));
        }
        $this->catpath = Joom_GetCatPath($this->catid);
        $this->joom_thumbnailpath = $config->jg_paththumbs . $this->catpath;
        $this->joom_picturepath = $config->jg_pathimages . $this->catpath;
        $this->joom_originalpath = $config->jg_pathoriginalimages . $this->catpath;
        $this->joom_thumbnailsource = $config->jg_paththumbs . $this->catpath . $this->imgfilename;
        $this->joom_picturesource = $config->jg_pathimages . $this->catpath . $this->imgfilename;
        $this->joom_originalsource = $config->jg_pathoriginalimages . $this->catpath . $this->imgfilename;
        $this->joom_componenturl = 'index.php?option=com_joomgallery';
        $this->joom_assetspath = 'components/com_joomgallery/assets/';
        $this->picture_src = '';
        if ($config->jg_watermark == 1) {
            $this->picture_src = _JOOM_LIVE_SITE . $this->joom_componenturl . '&amp;func=watermark&amp;catid=' . $this->catid . '&amp;id=' . $this->id . str_replace('&', '&amp;', _JOOM_ITEMID);
        } else {
            $this->picture_src = _JOOM_LIVE_SITE . $this->joom_picturesource;
        }
        if (JFile::exists(JPATH_ROOT . DS . $this->joom_originalsource)) {
            $imginfo_ori = getimagesize(JPath::clean(JPATH_ROOT . DS . $this->joom_originalsource));
            $this->originalimgsize = filesize(JPath::clean(JPATH_ROOT . DS . $this->joom_originalsource));
            $this->foriginalimgsize = number_format($this->originalimgsize / 1024, 2, ",", ".") . " KB";
        } else {
            $imginfo_ori[0] = 0;
            $imginfo_ori[1] = 0;
            $this->foriginalimgsize = JText::_('JGS_NO_ORIGINAL_FILE');
        }
        $imginfo = getimagesize(JPath::clean(JPATH_ROOT . DS . $this->joom_picturesource));
        $imgsize = filesize(JPath::clean(JPATH_ROOT . DS . $this->joom_picturesource));
        $this->fimgsize = number_format($imgsize / 1024, 2, ',', '.') . ' KB';
        $this->srcWidth_ori = $imginfo_ori[0];
        $this->srcHeight_ori = $imginfo_ori[1];
        $this->srcWidth = $imginfo[0];
        $this->srcHeight = $imginfo[1];
        $this->fimgdate = strftime($config->jg_dateformat, $this->imgdate);
        $this->frating = number_format($this->rating, 2, ',', '.');
        if ($config->jg_secondorder != '' && $config->jg_thirdorder == '') {
            $orderclause = $config->jg_firstorder . ', ' . $config->jg_secondorder;
        } elseif ($config->jg_secondorder != '' && $config->jg_thirdorder != '') {
            $orderclause = $config->jg_firstorder . ', ' . $config->jg_secondorder . ', ' . $config->jg_thirdorder;
        } else {
            $orderclause = $config->jg_firstorder;
        }
        $database->setQuery(" SELECT\n                            *\n                          FROM\n                            #__joomgallery\n                          WHERE\n                                    catid = " . $this->catid . "\n                            AND approved  = '1'\n                            AND published = '1'\n                          ORDER BY\n                            {$orderclause}\n                        ");
        $this->rows = $database->loadObjectList();
        ?>
  <a name="joomimg"></a>
<?php 
        if ($config->jg_showdetailtitle == 1) {
            HTML_Joom_Detail::Joom_ShowPictureTitle_HTML();
        }
        if (($config->jg_bigpic == 1 && $user->get('aid') > 0 || $config->jg_bigpic == 2) && !$this->slideshow && JFile::exists(JPATH_ROOT . DS . $this->joom_originalsource) && ($this->srcWidth_ori > $this->srcWidth && $this->srcHeight_ori > $this->srcHeight)) {
            $this->link = Joom_OpenImage($config->jg_bigpic_open, $this->id, $this->catpath, $this->catid, $this->imgfilename, $this->imgtitle, $this->imgtext);
        } else {
            $this->link = '';
        }
        if ($this->slideshow == false) {
            Joom_LightboxImages(0, 1, 0, $this->catid, $this->id);
        }
        $this->Joom_ShowPicture();
        if ($config->jg_slideshow) {
            $this->Joom_ShowSlideshow();
        }
        $this->Joom_PagingCategory();
        if (!$this->slideshow) {
            Joom_LightboxImages(0, 2, 0, $this->catid, $this->id);
        }
        if ($config->jg_minis) {
            $this->Joom_ShowMinis();
        }
        if ($config->jg_showdetailtitle == 2) {
            HTML_Joom_Detail::Joom_ShowPictureTitle_HTML();
        }
        $modules = Joom_getModules('detailbtm');
        if (count($modules)) {
            $document =& JFactory::getDocument();
            $renderer = $document->loadRenderer('module');
            $style = -2;
            $params = array('style' => $style);
            foreach ($modules as $module) {
                ?>
  <div class="jg_module">
<?php 
                if ($module->showtitle) {
                    ?>
    <div class="sectiontableheader">
      <h4>
        <?php 
                    echo $module->title;
                    ?>
&nbsp;
      </h4>
    </div>
<?php 
                }
                echo $renderer->render($module, $params);
                ?>
  </div>
<?php 
            }
        }
        if ($config->jg_showdetail) {
            $this->Joom_ShowPictureData();
        }
        # Update View counter
        $this->imgcounter++;
        if ($config->jg_watermark == 0) {
            $database->setQuery(" UPDATE\n                              #__joomgallery\n                            SET\n                              imgcounter = " . $this->imgcounter . "\n                            WHERE\n                              id = " . $this->id . "\n                          ");
            $database->query();
        }
        if ($config->jg_slideshow) {
            HTML_Joom_Detail::Joom_ShowSlideshow_HTML();
        }
        //******************************************************************************
        //wenn die Slideshow aktiviert ist, sind die folgenden Abfragen hinfaellig
        if ($this->slideshow) {
            return;
        }
        //******************************************************************************
        $modules = Joom_GetModules('detailpane');
        if (count($modules)) {
            HTML_Joom_Detail::Joom_ShowModules_HTML($modules);
        }
        if ($config->jg_showexifdata && extension_loaded('exif') && function_exists('exif_read_data')) {
            include_once JPATH_COMPONENT . DS . 'includes' . DS . 'exif' . DS . 'joom.exifdata.php';
        }
        if ($config->jg_showiptcdata) {
            include_once JPATH_COMPONENT . DS . 'includes' . DS . 'iptc' . DS . 'joom.iptcdata.php';
        }
        if ($config->jg_showrating) {
            HTML_Joom_Detail::Joom_ShowVotingArea_HTML();
        }
        if ($config->jg_bbcodelink) {
            $show_img = false;
            $show_url = false;
            if ($config->jg_bbcodelink == 1 || $config->jg_bbcodelink == 3) {
                $show_img = true;
            }
            if ($config->jg_bbcodelink == 2 || $config->jg_bbcodelink == 3) {
                $show_url = true;
            }
            HTML_Joom_Detail::Joom_ShowBBCodeLink_HTML($this->picture_src, $show_img, $show_url);
        }
        if ($config->jg_showcomment) {
            //darf der Besucher Kommentare eingeben
            if ($config->jg_anoncomment || !$config->jg_anoncomment && $user->get('id')) {
                $allowcomment = 1;
            } else {
                $allowcomment = 0;
            }
            HTML_Joom_Detail::Joom_ShowCommentsHead_HTML();
            if ($config->jg_showcommentsarea == 2) {
                HTML_Joom_Detail::Joom_ShowCommentsArea_HTML($allowcomment);
                HTML_Joom_Detail::Joom_BuildCommentsForm_HTML($allowcomment);
            } else {
                HTML_Joom_Detail::Joom_BuildCommentsForm_HTML($allowcomment);
                HTML_Joom_Detail::Joom_ShowCommentsArea_HTML($allowcomment);
            }
            HTML_Joom_Detail::Joom_ShowCommentsEnd_HTML();
        }
        if ($config->jg_send2friend) {
            HTML_Joom_Detail::Joom_ShowSend2FriendArea_HTML();
        }
    }
    function Joom_ShowSpecials_HTML($tl_title, $rows, $sorting)
    {
        $config = Joom_getConfig();
        $database =& JFactory::getDBO();
        $user =& JFactory::getUser();
        $num_rows = ceil(count($rows) / $config->jg_toplistcols);
        $index = 0;
        $line = 1;
        ?>
  <div class="jg_topview">
    <div class="sectiontableheader">
      <?php 
        echo $tl_title;
        ?>
&nbsp;
    </div>
<?php 
        $count_rows = count($rows);
        if ($count_rows) {
            for ($row_count = 0; $row_count < $num_rows; $row_count++) {
                $line++;
                $linecolor = $line % 2 + 1;
                ?>
    <div class="jg_row <?php 
                if ($linecolor == 1) {
                    echo "sectiontableentry1";
                } else {
                    echo "sectiontableentry2";
                }
                ?>
">
<?php 
                for ($col_count = 0; $col_count < $config->jg_toplistcols && $index < $count_rows; $col_count++) {
                    $row1 = $rows[$index];
                    ?>
      <div class="jg_topelement">
<?php 
                    $catpath = Joom_GetCatPath($row1->catid);
                    if ($config->jg_showdetailpage == 0 && $user->get('aid') != 0 || $config->jg_showdetailpage == 1) {
                        $link = Joom_OpenImage($config->jg_detailpic_open, $row1->id, $catpath, $row1->catid, $row1->imgfilename, $row1->imgtitle, $row1->imgtext);
                    } else {
                        $link = "javascript:alert('" . JText::_('JGS_ALERT_NO_DETAILVIEW_FOR_GUESTS', true) . "')";
                    }
                    ?>
        <div  class="jg_topelem_photo">
          <a href="<?php 
                    echo $link;
                    ?>
">
            <img src="<?php 
                    echo _JOOM_LIVE_SITE . $config->jg_paththumbs . $catpath . $row1->imgthumbname;
                    ?>
" class="jg_photo" alt="<?php 
                    echo $row1->imgtitle;
                    ?>
" />
          </a>
        </div>
        <div class="jg_topelem_txt">
          <ul>
            <li>
              <b><?php 
                    echo $row1->imgtitle;
                    ?>
</b>
            </li>
            <li>
              <?php 
                    echo JText::_('JGS_CATEGORY') . ':';
                    ?>
              <a href="<?php 
                    echo JRoute::_('index.php?option=com_joomgallery&func=viewcategory&catid=' . $row1->catid . _JOOM_ITEMID);
                    ?>
">
                <?php 
                    echo $row1->name;
                    ?>
              </a>
            </li>
<?php 
                    if ($config->jg_showauthor) {
                        if ($row1->imgauthor) {
                            $authorowner = $row1->imgauthor;
                        } elseif ($config->jg_showowner) {
                            $authorowner = Joom_GetDisplayName($row1->owner);
                        } else {
                            $authorowner = JText::_('JGS_NO_DATA');
                        }
                        ?>
            <li>
              <?php 
                        echo JText::_('JGS_AUTHOR') . ': ' . $authorowner;
                        ?>
&nbsp;
            </li>
<?php 
                    }
                    if ($config->jg_showhits) {
                        ?>
            <li>
              <?php 
                        echo JText::_('JGS_HITS') . ': ' . $row1->imgcounter;
                        ?>
&nbsp;
            </li>
<?php 
                    }
                    if ($config->jg_showcatrate) {
                        ?>
            <li>
<?php 
                        if ($row1->imgvotes > 0) {
                            $fimgvotesum = number_format($row1->imgvotesum / $row1->imgvotes, 2, ',', '');
                            if ($row1->imgvotes == 1) {
                                $frating = $fimgvotesum . ' (' . $row1->imgvotes . ' ' . JText::_('JGS_ONE_VOTE') . ')';
                            } else {
                                $frating = $fimgvotesum . ' (' . $row1->imgvotes . ' ' . JText::_('JGS_VOTES') . ')';
                            }
                        } else {
                            $frating = '(' . JText::_('JGS_NO_RATINGS') . ')';
                        }
                        ?>
              <?php 
                        echo JText::_('JGS_RATING') . ': ' . $frating;
                        ?>
            </li>
<?php 
                    }
                    if ($config->jg_showcatcom) {
                        # Check how many comments exist
                        $database->setQuery(" SELECT \n                                    COUNT(*)\n                                  FROM \n                                    #__joomgallery_comments\n                                  WHERE \n                                           cmtpic = '{$row1->id}' \n                                    AND approved  = '1' \n                                    AND published = '1'\n                                ");
                        $comments = $database->LoadResult();
                        ?>
            <li>
<?php 
                        switch ($comments) {
                            case 0:
                                ?>
              <?php 
                                echo JText::_('JGS_NO_COMMENTS');
                                ?>
&nbsp;
<?php 
                                break;
                            case 1:
                                ?>
              <?php 
                                echo $comments . ' ' . JText::_('JGS_COMMENT');
                                ?>
&nbsp;
<?php 
                                break;
                            default:
                                ?>
              <?php 
                                echo $comments . ' ' . JText::_('JGS_COMMENTS');
                                ?>
&nbsp;
<?php 
                                break;
                        }
                        ?>
            </li>
<?php 
                        if ($sorting == 'lastcomment' && $config->jg_showthiscomment) {
                            for ($ii = 0; $ii < $comments; $ii++) {
                                $userid = $row1->userid;
                                $cmtname = $row1->cmtname;
                                if ($userid > 0) {
                                    $cmtname = $row1->username;
                                }
                                $cmttext = $row1->cmttext;
                                $cmtdate = $row1->cmtdate;
                                #$cmtdate = strftime( "%d-%m-%Y %H:%M:%S", $cmtdate );
                                $cmtdate = strftime($config->jg_dateformat, $cmtdate);
                            }
                            ?>
            <li>
<?php 
                            if ($userid > 0) {
                                ?>
			        <?php 
                                echo Joom_GetDisplayName($userid, false);
                            } else {
                                echo $cmtname;
                            }
                            echo ' ' . JText::_('JGS_WROTE') . ' (' . JText::_('JGS_AT') . ' ' . $cmtdate . '):';
                            $cmttext = Joom_ProcessText($cmttext);
                            if ($config->jg_smiliesupport) {
                                $smileys = Joom_GetSmileys();
                                foreach ($smileys as $i => $sm) {
                                    $cmttext = str_replace($i, '<img src="' . $sm . '" border="0" alt="' . $i . '" title="' . $i . '" />', $cmttext);
                                }
                            }
                            ?>
              <?php 
                            echo stripslashes($cmttext);
                            ?>
&nbsp;
            </li>
<?php 
                        }
                    }
                    ?>
          </ul>
        </div>
      </div>
<?php 
                    $index++;
                }
                ?>
      <div class="jg_clearboth"></div>
    </div>
<?php 
            }
        }
        ?>
  </div>
<?php 
    }
    /**
     * HTML output of the mini thumbnails for the JoomBu
     *
     *@param array DB result
     */
    function Joom_ShowMinis_HTML($rows)
    {
        $mainframe =& JFactory::getApplication('site');
        $document =& JFactory::getDocument();
        $config = Joom_getConfig();
        // template CSS is usually not loaded now, but it's better to have it
        $load_template_css = true;
        // make available in the plugin params?
        if ($load_template_css) {
            $template = $mainframe->getTemplate();
            $template_file = false;
            if (is_file(JPATH_THEMES . DS . $template . DS . 'css' . DS . 'template.css')) {
                $template_file = 'templates/' . $template . '/css/template.css';
            } else {
                if (is_file(JPATH_THEMES . DS . $template . DS . 'css' . DS . 'template_css.css')) {
                    $template_file = 'templates/' . $template . '/css/template_css.css';
                }
            }
            if ($load_template_css) {
                $document->addStyleSheet(_JOOM_LIVE_SITE . $template_file);
                // to avoid scroll bar with some templates
                $document->addStyleDeclaration("    body{\n      height:90%;\n    }");
            }
        }
        // for overlib effect # at the moment always loaded by joom.javascript.php
        #$document->addScript(_JOOM_LIVE_SITE.'includes/js/overlib_mini.js');
        // for accordion
        $document->addStyleSheet('components/com_joomgallery/assets/css/joom_detail.css');
        JHTML::_('behavior.mootools');
        #$document->addScript('components/com_joomgallery/assets/js/accordion/js/accordion.js');
        $script = "\n    window.addEvent('domready', function(){ \n      new Accordion(\$\$('h4.joomgallery-toggler'), \$\$('div.joomgallery-slider'), \n        {onActive: function(toggler, i) { \n          toggler.addClass('joomgallery-toggler-down'); \n          toggler.removeClass('joomgallery-toggler'); },\n         onBackground: function(toggler, i) { \n          toggler.addClass('joomgallery-toggler'); \n          toggler.removeClass('joomgallery-toggler-down'); },\n          duration: 300,display:-1,show:1,opacity: false,alwaysHide: true}); });";
        $document->addScriptDeclaration($script);
        // JavaScript for inserting the tag
        $script = "\n    function insertJoomPluWithId(jg_id) {\n      jg_detail = document.getElementById('jg_bu_detail').checked;\n      jg_linked = document.getElementById('jg_bu_linked').checked;\n      jg_align  = document.getElementById('jg_bu_align').value;\n      if(jg_detail) {\n        jg_detail = ' detail';\n      } else {\n        jg_detail = '';\n      }\n      if(jg_linked) {\n        jg_linked = '';\n      } else {\n        jg_linked = ' not linked';\n      }\n      if(jg_align) {\n        jg_align  = ' ' + jg_align;\n      } else {\n        jg_align  = '';\n      }\n      jg_plu_tag  = '{joomplu:' + jg_id + jg_detail + jg_linked + jg_align + '}';\n      window.parent.jInsertEditorText(jg_plu_tag, 'text');\n      window.parent.document.getElementById('sbox-window').close();\n    }";
        $document->addScriptDeclaration($script);
        ?>
<div class="gallery minigallery">
  <div class="jg_header">
    <?php 
        echo JText::_('JGS_BU_INTRO');
        ?>
  </div>
  <div class="sectiontableheader">
    <h4 class="joomgallery-toggler">
      <?php 
        echo JText::_('JGS_BU_EXTENDED');
        ?>
&nbsp;
    </h4>
  </div>
  <div class="joomgallery-slider">
    <div class="jg_bu_extended_options">
      <span class="jg_bu_extended_option_left">
        <?php 
        echo JText::_('JGS_BU_DETAIL');
        ?>
&nbsp;
        <input type="checkbox" id="jg_bu_detail">
      </span>
      <span class="jg_bu_extended_option_middle">
        <?php 
        echo JText::_('JGS_BU_LINKED');
        ?>
&nbsp;
        <input type="checkbox" id="jg_bu_linked" checked="checked">
      </span>
      <span class="jg_bu_extended_option_right">
        <?php 
        echo JText::_('JGS_BU_ALIGN');
        ?>
        <select id="jg_bu_align">
          <option value="">
          </option>
          <option value="right">
            <?php 
        echo JText::_('JGS_BU_ALIGN_RIGHT');
        ?>
&nbsp;
          </option>
          <option value="left">
            <?php 
        echo JText::_('JGS_BU_ALIGN_LEFT');
        ?>
&nbsp;
          </option>
        </select>
      </span>
    </div>
  </div>
  <div class="sectiontableheader">
    <h4 class="joomgallery-toggler">
      <?php 
        echo JText::_('JGS_BU_SEARCH');
        ?>
    </h4>
  </div>
  <div class="joomgallery-slider">
    <div class="jg_bu_search">
    <form action="index.php?option=com_joomgallery&func=joomplu&tmpl=component&e_name=text" method="post">
<?php 
        echo $this->_pagination->getListFooter();
        ?>
      <div class="jg_bu_filter">
        <?php 
        echo Jtext::_('JGS_FILTER_BY_CATEGORY');
        ?>
&nbsp;
<?php 
        echo Joom_ShowDropDownCategoryList($this->catid, 'catid', 'onchange="this.form.submit();"');
        ?>
      </div>
    </form>
    </div>
  </div>
  <div class="jg_bu_minis">
<?php 
        foreach ($rows as $row) {
            if (!$this->catid) {
                $catpath = Joom_GetCatPath($row->catid);
                $cat_name = true;
            } else {
                $catpath = $this->catpath;
                $cat_name = false;
            }
            ?>
    <div class="jg_bu_mini">
<?php 
            if ($row->imgthumbname != '' && is_file(JPath::clean(JPATH_ROOT . DS . $config->jg_paththumbs . $catpath . $row->imgthumbname))) {
                $tnfile = JPath::clean(JPATH_ROOT . DS . $config->jg_paththumbs . $catpath . $row->imgthumbname);
                $tnfile = str_replace(' ', '%20', $tnfile);
                $imginfo = getimagesize($tnfile);
                $srcLink = _JOOM_LIVE_SITE . $config->jg_paththumbs . $catpath . $row->imgthumbname;
                $srcWidth = $imginfo[0];
                $srcHeight = $imginfo[1];
                $overlib = Joom_ShowMiniJoom_HTML::getOverlibHtml($row, $srcLink, $cat_name);
                ?>
      <a href="javascript:insertJoomPluWithId('<?php 
                echo $row->id;
                ?>
');" onmouseover="return overlib('<?php 
                echo $overlib;
                ?>
',WIDTH,<?php 
                echo $srcWidth;
                ?>
,<?php 
                /* HEIGHT,<?php echo $srcHeight; ?>,*/
                ?>
ABOVE)" onmouseout="return nd()" >
        <img src="<?php 
                echo _JOOM_LIVE_SITE . $config->jg_paththumbs . $catpath . $row->imgthumbname;
                ?>
" border="0" height="40" width="40" alt="Thumbnail" /></a>
<?php 
            } else {
                ?>
      <div class="jg_bu_no_mini" onmouseover="return overlib('<?php 
                echo sprintf(JText::_('JGS_NO_THUMB_TOOLTIP_TEXT', true), $row->id, $row->imgtitle);
                ?>
', CAPTION, '<?php 
                echo JText::_('JGS_NO_THUMB');
                ?>
', BELOW, RIGHT)" onmouseout="return nd()" >
        <?php 
                echo JText::_('JGS_NO_THUMB');
                ?>
&nbsp;
      </div>
<?php 
            }
            ?>
    </div>
<?php 
        }
        if (!count($rows)) {
            ?>
    <div class="jg_bu_no_images">
      <?php 
            echo JText::_('JGS_NO_IMAGES');
            ?>
&nbsp;
    </div>
<?php 
        }
        ?>
  </div>
</div>
<?php 
    }
 /**
  * creates directories and the database entry for a category
  * @param object holds information about the new category
  * @return boolean true if success
  */
 function Joom_Migrate_CreateCategory($cat)
 {
     jimport('joomla.filesystem.file');
     //some checks
     if (!isset($cat->id)) {
         return false;
     }
     if (!isset($cat->name)) {
         $cat->name = 'no cat name';
     }
     if (!isset($cat->parent)) {
         $cat->parent = 0;
     }
     if (!isset($cat->description)) {
         $cat->description = '';
     }
     if (!isset($cat->ordering)) {
         $cat->ordering = 0;
     }
     if (!isset($cat->published)) {
         $cat->published = 0;
     }
     if (!isset($cat->owner)) {
         $cat->owner = 'NULL';
     }
     if (!isset($cat->catimage)) {
         $cat->catimage = '';
     }
     if (!isset($cat->img_position)) {
         $cat->img_position = 0;
     }
     //make the name safe
     JFilterOutput::objectHTMLSafe($cat->name);
     //if the new category should be assigned as subcategory...
     if ($cat->parent) {
         //save the category path of parent category in a variable
         $parentpath = Joom_GetCatPath($cat->parent);
         // otherwise let it empty
     } else {
         $parentpath = '';
     }
     //creation of category path
     //cleaning of category title with function Joom_FixFilename
     //so special chars are converted and underscore removed
     //affects only the category path
     $newcatname = Joom_FixCatname($cat->name);
     //add a undersore and the category id
     //affects only the category path
     $newcatname = $newcatname . '_' . $cat->id;
     //prepend - if exists - the parent category path
     $catpath = $parentpath . $newcatname;
     //create the paths of category for originals, pictures, thumbnails
     $cat_originalpath = JPath::clean(JPATH_ROOT . DS . $this->_config->jg_pathoriginalimages . $catpath);
     $cat_picturepath = JPath::clean(JPATH_ROOT . DS . $this->_config->jg_pathimages . $catpath);
     $cat_thumbnailpath = JPath::clean(JPATH_ROOT . DS . $this->_config->jg_paththumbs . $catpath);
     $result = array();
     $result[] = JFolder::create($cat_originalpath);
     $result[] = JFile::copy(JPATH_COMPONENT_SITE . DS . 'assets' . DS . 'index.html', $cat_originalpath . DS . 'index.html');
     $result[] = JFolder::create($cat_picturepath);
     $result[] = JFile::copy(JPATH_COMPONENT_SITE . DS . 'assets' . DS . 'index.html', $cat_picturepath . DS . 'index.html');
     $result[] = JFolder::create($cat_thumbnailpath);
     $result[] = JFile::copy(JPATH_COMPONENT_SITE . DS . 'assets' . DS . 'index.html', $cat_thumbnailpath . DS . 'index.html');
     //create database entry
     $query = "INSERT INTO #__joomgallery_catg\n                (cid, name, parent, description, ordering, access, published, owner, catimage, img_position, catpath)\n              VALUES\n                (" . $cat->id . ",\n                 '" . $cat->name . "',\n                 " . $cat->parent . ",\n                 '" . $cat->description . "',\n                 " . $cat->ordering . ",\n                 " . $cat->access . ",\n                 " . $cat->published . ",\n                 " . $cat->owner . ",\n                 '" . $cat->catimage . "',\n                 " . $cat->img_position . ",\n                 '" . $catpath . "')";
     $this->_db->setQuery($query);
     $result['db'] = $this->_db->query();
     if (!$result['db']) {
         $this->Joom_Migrate_SetError($this->_db->getErrorMsg(), true);
     }
     if (!in_array(false, $result)) {
         $this->Joom_Migrate_WriteLogfile("Category " . $cat->id . " created: " . $cat->name);
         return true;
     } else {
         $this->Joom_Migrate_WriteLogfile(" -> Error creating category " . $cat->id . ": " . $cat->name);
         return false;
     }
 }
 /**
  * creates a new category out of the information of the given object
  *
  * @param object  should hold all the information about the new category
  * @return int/boolean id of the created category on success, false otherwise
  */
 function createCategory($obj)
 {
     $database =& JFactory::getDBO();
     jimport('joomla.filesystem.file');
     /*JTable::addIncludePath(JPATH_ADMINISTRATOR.DS.'components'.DS.'com_joomgallery'.DS.'tables');
       $row = & JTable::getInstance('joomgallerycategories', 'Table');*/
     /* deprecated (use JTable instead as shown above): */
     require_once JPATH_ADMINISTRATOR . DS . 'components' . DS . 'com_joomgallery' . DS . 'joomgallery.class.php';
     $row = new mosCatgs($database);
     $row->bind($obj);
     //store data in the database
     if (!$row->store()) {
         return false;
     }
     //now we have the id of the new category
     //and the catpath can be built
     $row->catpath = Joom_FixFilename($row->name) . '_' . $row->cid;
     if ($row->parent) {
         $row->catpath = Joom_GetCatPath($row->parent) . $row->catpath;
     }
     //so store again
     if (!$row->store()) {
         return false;
     }
     //create necessary folders and files
     $origpath = JPATH_ROOT . DS . $this->_jg_config->jg_pathoriginalimages . $row->catpath;
     $imgpath = JPATH_ROOT . DS . $this->_jg_config->jg_pathimages . $row->catpath;
     $thumbpath = JPATH_ROOT . DS . $this->_jg_config->jg_paththumbs . $row->catpath;
     $index = JPATH_SITE . DS . 'components' . DS . 'com_joomgallery' . DS . 'assets' . DS . 'index.html';
     $result = array();
     $result[] = JFolder::create($origpath);
     $result[] = JFile::copy($index, $origpath . DS . 'index.html');
     $result[] = JFolder::create($imgpath);
     $result[] = JFile::copy($index, $imgpath . DS . 'index.html');
     $result[] = JFolder::create($thumbpath);
     $result[] = JFile::copy($index, $thumbpath . DS . 'index.html');
     if (in_array(false, $result)) {
         return false;
     } else {
         return $row->cid;
     }
 }
    function Joom_ShowFavourites_HTML2($rows, $showDownloadIcon)
    {
        $config = Joom_getConfig();
        $database =& JFactory::getDBO();
        $user =& JFactory::getUser();
        ?>
  <div class="sectiontableheader">
    <?php 
        echo $this->Output('HEADING');
        ?>
 
  </div>
  <div class="jg_fav_switchlayout">
    <a href="<?php 
        echo JRoute::_('index.php?option=com_joomgallery&func=switchlayout' . _JOOM_ITEMID);
        ?>
">
      <?php 
        echo JText::_('JGS_FAV_SWITCH_LAYOUT');
        ?>
 
    </a>
  </div>
  <div class="jg_fav_clearlist">
    <a href="<?php 
        echo JRoute::_('index.php?option=com_joomgallery&func=removeall' . _JOOM_ITEMID);
        ?>
">
      <?php 
        echo JText::_('JGS_FAV_REMOVE_ALL');
        ?>
 
    </a>
  </div>
  <div class="sectiontableheader">
    <div class="jg_up_entry">
      <div class="jg_up_ename">
        <?php 
        echo JText::_('JGS_PICTURE_NAME');
        ?>
 
      </div>
      <div class="jg_up_ehits">
        <?php 
        echo JText::_('JGS_HITS');
        ?>
 
      </div>
      <div class="jg_up_ecat">
        <?php 
        echo JText::_('JGS_CATEGORY');
        ?>
 
      </div>
      <div class="jg_up_eact">
        <?php 
        echo JText::_('JGS_ACTION');
        ?>
 
      </div>
    </div>
  </div>
  <?php 
        $k = 0;
        if (count($rows)) {
            foreach ($rows as $row) {
                $k = 1 - $k;
                $p = $k + 1;
                $catpath = Joom_GetCatPath($row->catid);
                ?>
  <div class="<?php 
                echo "sectiontableentry" . $p;
                ?>
">
    <div class="jg_up_entry">
<?php 
                if ($row->approved) {
                    $link = Joom_OpenImage($config->jg_detailpic_open, $row->id, $catpath, $row->catid, $row->imgfilename, $row->imgtitle, $row->imgtext);
                }
                if ($config->jg_showminithumbs) {
                    ?>
      <div class="jg_up_ename">
<?php 
                    if ($row->imgthumbname != '') {
                        if ($row->approved) {
                            ?>
        <a href="<?php 
                            echo $link;
                            ?>
">
<?php 
                        }
                        ?>
          <img src="<?php 
                        echo _JOOM_LIVE_SITE . $config->jg_paththumbs . $catpath . $row->imgthumbname;
                        ?>
" border="0" height="30" alt="" />
<?php 
                        if ($row->approved) {
                            ?>
        </a>
<?php 
                        }
                    }
                } else {
                    ?>
        <div class="jg_floatleft">
          <img src="<?php 
                    echo _JOOM_LIVE_SITE . 'components/com_joomgallery/assets/images/arrow.png';
                    ?>
" class="pngfile jg_icon"  alt="arrow" />
        </div>
<?php 
                }
                if ($row->approved) {
                    ?>
        <a href="<?php 
                    echo $link;
                    ?>
"> 
<?php 
                }
                ?>
        <?php 
                echo $row->imgtitle;
                ?>
 
<?php 
                if ($row->approved) {
                    ?>
        </a>
<?php 
                }
                ?>
      </div>
      <div class="jg_up_ehits">
        <?php 
                echo $row->imgcounter;
                ?>
 
      </div>
      <div class="jg_up_ecat">
        <a href="<?php 
                echo JRoute::_('index.php?option=com_joomgallery&func=viewcategory&catid=' . $row->catid . _JOOM_ITEMID);
                ?>
">
          <?php 
                echo Joom_CategoryPathLink($row->catid, false);
                ?>
 
        </a>
      </div>
<?php 
                // Download Icon
                if ($showDownloadIcon == 1) {
                    ?>
      <div class="jg_up_esub1">
        <a href="<?php 
                    echo JRoute::_('index.php?option=com_joomgallery&func=download&catid=' . $row->catid . '&id=' . $row->id . _JOOM_ITEMID);
                    ?>
"
          onMouseOver="return overlib('<?php 
                    echo JText::_('JGS_DOWNLOAD_TOOLTIP_TEXT', true);
                    ?>
', CAPTION, '<?php 
                    echo JText::_('JGS_DOWNLOAD_TOOLTIP_CAPTION', true);
                    ?>
', BELOW, RIGHT);" onmouseout="return nd();">
        <img src="<?php 
                    echo _JOOM_LIVE_SITE . 'components/com_joomgallery/assets/images/download.png';
                    ?>
" border="0" width="16" height="16" alt="<?php 
                    echo JText::_('JGS_DOWNLOAD_TOOLTIP_CAPTION');
                    ?>
" class="pngfile jg_icon" /></a>
      </div>
<?php 
                } elseif ($showDownloadIcon == -1) {
                    ?>
      <div class="jg_up_esub1" onMouseOver="return overlib('<?php 
                    echo JText::_('JGS_DOWNLOAD_TOOLTIP_TEXT_LOGIN', true);
                    ?>
', CAPTION, '<?php 
                    echo JText::_('JGS_DOWNLOAD_TOOLTIP_CAPTION', true);
                    ?>
', BELOW, RIGHT);" onmouseout="return nd();" >
        <img src="<?php 
                    echo _JOOM_LIVE_SITE . 'components/com_joomgallery/assets/images/download_gr.png';
                    ?>
" alt="<?php 
                    echo JText::_('JGS_DOWNLOAD_TOOLTIP_CAPTION');
                    ?>
"  class="pngfile jg_icon" />
      </div>
<?php 
                }
                ?>
      <div class="jg_up_esub2">
        <a href="<?php 
                echo JRoute::_('index.php?option=com_joomgallery&func=removepicture&id=' . $row->id . _JOOM_ITEMID);
                ?>
"
          onMouseOver="return overlib('<?php 
                echo $this->Output('REMOVE_TOOLTIP_TEXT');
                ?>
', CAPTION, '<?php 
                echo $this->Output('REMOVE_TOOLTIP_CAPTION');
                ?>
', BELOW, RIGHT);" onmouseout="return nd();">
        <img src="<?php 
                echo _JOOM_LIVE_SITE . 'components/com_joomgallery/assets/images/basket_remove.png';
                ?>
" alt="<?php 
                echo $this->Output('REMOVE_TOOLTIP_CAPTION');
                ?>
" class="pngfile jg_icon" /></a>
      </div>
<?php 
                if ($row->imgowner && $row->imgowner == $user->get('id')) {
                    ?>
      <div class="jg_up_esub3">
        <a href="<?php 
                    echo JRoute::_('index.php?option=com_joomgallery&func=editpic&uid=' . $user->get('id') . '&id=' . $row->id . _JOOM_ITEMID);
                    ?>
" title="<?php 
                    echo JText::_('JGS_EDIT');
                    ?>
">
          <img src= "<?php 
                    echo _JOOM_LIVE_SITE;
                    ?>
components/com_joomgallery/assets/images/edit.png" border="0" width="16" height="16" alt="<?php 
                    echo JText::_('JGS_EDIT');
                    ?>
" class="pngfile jg_icon" />
        </a>
      </div>
      <div class="jg_up_esub4">
        <a href="javascript:if (confirm('<?php 
                    echo JText::_('JGS_ALERT_SURE_DELETE_SELECTED_ITEM', true);
                    ?>
')){ location.href='<?php 
                    echo JRoute::_('index.php?option=com_joomgallery&func=deletepic&uid=' . $user->get('id') . '&id=' . $row->id . _JOOM_ITEMID, false);
                    ?>
';}" title="<?php 
                    echo JText::_('JGS_DELETE');
                    ?>
">
          <img src="<?php 
                    echo _JOOM_LIVE_SITE;
                    ?>
components/com_joomgallery/assets/images/edit_trash.png" border="0" width="16" height="16" alt="<?php 
                    echo JText::_('JGS_DELETE');
                    ?>
" class="pngfile jg_icon" />
        </a>
      </div>
<?php 
                }
                ?>
    </div>
  </div>
<?php 
            }
        } else {
            $p = $k + 1;
            ?>
  <div class="jg_txtrow">
    <div class="<?php 
            echo "sectiontableentry" . $p;
            ?>
">
      <img src="<?php 
            echo _JOOM_LIVE_SITE . 'components/com_joomgallery/assets/images/arrow.png';
            ?>
" class="pngfile jg_icon" alt="arrow" />
    <?php 
            echo $this->Output('NO_PICS');
            ?>
 
    </div>
  </div>
<?php 
        }
        ?>
  <div class="sectiontableheader">
    &nbsp;
  </div>
<?php 
    }
 /**
  * Delete picture(s) from directory and database
  *
  * @param    Array  $cid: id's of pictures to be deleted
  */
 function Joom_RemovePictures($ids)
 {
     $mainframe =& JFactory::getApplication('administrator');
     $database =& JFactory::getDBO();
     $config = Joom_getConfig();
     jimport('joomla.filesystem.file');
     //one or more pictures
     if (!is_array($ids) || count($ids) < 1) {
         //no picture(s) -> error message and abort
         $msg = JText::_('JGA_ALERT_SELECT_AN_ITEM_TO_DELETE');
         $mainframe->redirect('index.php?option=' . _JOOM_OPTION . '&act=pictures', $msg, 'error');
     }
     //two arrays, one for the succesful deleted, one for the pictures with
     //error in actions
     //TODO: error messages
     $deleted_items = array();
     $notdeleted_items = array();
     // loop through array
     foreach ($ids as $id) {
         //database query to get the category, name of picture and thumb
         $database->setQuery("SELECT id, catid, imgfilename, imgthumbname\n          FROM #__joomgallery\n          WHERE id = {$id}");
         if ($database->query()) {
             $row = $database->loadObject();
             //catpath for category
             $catpath = Joom_GetCatPath($row->catid);
             //database query to check if there are other pictures with this thumbnail
             //assigned and how many
             $database->setQuery("SELECT COUNT(id)\n            FROM #__joomgallery\n            WHERE imgthumbname = '" . $row->imgthumbname . "'\n            AND id != '" . $row->id . "'\n            AND catid = '" . $row->catid . "'");
             $count = $database->loadResult();
             //database query to check if there are other pictures with this detail
             //or original assigned ad how many
             $database->setQuery("SELECT COUNT(id)\n            FROM #__joomgallery\n            WHERE imgfilename = '" . $row->imgfilename . "'\n            AND id != '" . $row->id . "'\n            AND catid = '" . $row->catid . "'");
             $count2 = $database->loadResult();
             //delete the thumbnail if there are no other pictures
             //in same category assigned to it
             if ($count < 1) {
                 if (!JFile::delete(JPATH_ROOT . DS . $config->jg_paththumbs . $catpath . $row->imgthumbname)) {
                     //if thumbnail is not deleteable error message and abort
                     Joom_AlertErrorMessages(0, $row->catid, JPath::clean(JPATH_ROOT . DS . $config->jg_paththumbs . $catpath), $row->imgthumbname);
                 }
             }
             //delete the detail if there are no other detail and
             //originals from same category assigned to it
             if ($count2 < 1) {
                 if (!JFile::delete(JPATH_ROOT . DS . $config->jg_pathimages . $catpath . $row->imgfilename)) {
                     //if detail is not deleteable error message and abort
                     Joom_AlertErrorMessages(0, $row->catid, JPath::clean(JPATH_ROOT . DS . $config->jg_pathimages . $catpath), $row->imgfilename);
                 }
                 //original exists?
                 if (JFile::exists(JPATH_ROOT . DS . $config->jg_pathoriginalimages . $catpath . $row->imgfilename)) {
                     //delete it
                     if (!JFile::delete(JPATH_ROOT . DS . $config->jg_pathoriginalimages . $catpath . $row->imgfilename)) {
                         //if original is not deleteable error message and abort
                         Joom_AlertErrorMessages(0, $row->catid, JPath::clean(JPATH_ROOT . DS . $config->jg_pathoriginalimages . $catpath), $row->imgfilename);
                     }
                 }
             }
             //not succesful database query
         } else {
             echo "<script> alert('" . $database->getErrorMsg() . "');\n              window.history.go(-1); </script>\n";
         }
         //TODO aha: better wrap the following DB actions in 'begin...commit/rollback'
         //to get consistence in case of error
         //delete the database entry of picture
         $database->setQuery("DELETE\n          FROM #__joomgallery\n          WHERE id = {$id}");
         if (!$database->query()) {
             echo "<script> alert('" . $database->getErrorMsg() . "');\n              window.history.go(-1); </script>\n";
         }
         //delete the corresponding database entries in comments
         $database->setQuery("DELETE\n          FROM #__joomgallery_comments\n          WHERE cmtpic = {$id}");
         if (!$database->query()) {
             echo "<script> alert('" . $database->getErrorMsg() . "');\n              window.history.go(-1); </script>\n";
         }
         //delete the corresponding database entries in nameshields
         $database->setQuery("DELETE\n          FROM #__joomgallery_nameshields\n          WHERE npicid = {$id}");
         if (!$database->query()) {
             echo "<script> alert('" . $database->getErrorMsg() . "');\n              window.history.go(-1); </script>\n";
         }
         //add the id of succesful deleted picture to array
         array_push($deleted_items, $id);
     }
     $mainframe->redirect('index.php?option=' . _JOOM_OPTION . '&act=pictures');
 }
 function Joom_GetPath($orig, $second, $catid)
 {
     $config = Joom_getConfig();
     //Defines imagepath || Definiert den richtigen Pfad zu dem Bild
     $catpath = Joom_GetCatPath($catid);
     if ($orig == 1 && $second != 0) {
         $path = $config->jg_pathoriginalimages;
     } else {
         $path = $config->jg_pathimages;
     }
     return JPath::clean(JPATH_ROOT . DS . $path . DS . $catpath);
 }
    /**
     * Move pictures
     *
     * @param int $id
     * @param string $Lists
     * @param array of objects $items
     */
    function Joom_ShowMovePictures_HTML($id, &$Lists, &$items)
    {
        $config = Joom_getConfig();
        $database =& JFactory::getDBO();
        jimport('joomla.filesystem.file');
        ?>
<form action="index.php" method="post" name="adminForm" >
<table cellpadding="4" cellspacing="0" border="0" width="100%">
  <tr>
    <td align="center">
      <b><?php 
        echo JText::_('JGA_MOVE_PICTURE_TO_CATEGORY');
        ?>
:</b> <?php 
        echo $Lists['catgs'];
        ?>
    </td>
  </tr>
</table>
<table cellpadding="4" cellspacing="0" border="0" width="100%" class="adminlist">
  <tr>
    <td align="left" valign="top" width="20%">
      <strong>
        <?php 
        echo JText::_('JGA_PICTURES_TO_MOVE');
        ?>
:
      </strong>
    </td>
  </tr>
</table>
<table cellpadding="4" cellspacing="0" border="0" width="100%" class="adminlist">
  <tr>
    <th width="5%"></th>
    <th class="title" width="40%">
      <?php 
        echo JText::_('JGA_TITLE');
        ?>
    </th>
    <th width="55%">
      <div align="left">
        <?php 
        echo JText::_('JGA_PREVIOUS_CATEGORY');
        ?>
      </div>
    </th>
  </tr>

<?php 
        foreach ($items as $item) {
            $catpath = Joom_GetCatPath($item->catid);
            ?>
  <tr>
    <td>
      <img src="<?php 
            echo _JOOM_LIVE_SITE . $config->jg_paththumbs . $catpath . $item->imgfilename;
            ?>
"
        border="0" width="24" height="24" alt="" />
    </td>
    <td align="left">
      <?php 
            echo $item->imgtitle;
            ?>
    </td>
    <td>
      <div align="left">
        <?php 
            echo Joom_ShowCategoryPath($item->catid);
            ?>
      </div>
    </td>
  </tr>
<?php 
        }
        ?>
  <tr>
    <th align="center" colspan="3">
    </th>
  </tr>
</table>
<input type="hidden" name="option" value="<?php 
        echo _JOOM_OPTION;
        ?>
" />
<input type="hidden" name="task" value="savemovepic" />
<input type="hidden" name="boxchecked" value="1" />
<?php 
        foreach ($id as $ids) {
            echo "\n <input type=\"hidden\" name=\"id[]\" value=\"{$ids}\" />";
        }
        ?>
</form>
<?php 
    }
 /**
  * Deletes the folders and the database entry of category
  *
  * @param    integer   $catid: id of category, e.g. 10
  */
 function Joom_DeleteCategory($catid)
 {
     $database =& JFactory::getDBO();
     $config = Joom_getConfig();
     $mainframe =& JFactory::getApplication('administrator');
     //path of category
     $catpath = Joom_GetCatPath($catid);
     //compose the paths for originals, pictures, thumbs
     $catorigdir = JPath::clean(JPATH_ROOT . DS . $config->jg_pathoriginalimages . $catpath);
     $catpicdir = JPath::clean(JPATH_ROOT . DS . $config->jg_pathimages . $catpath);
     $catthumbdir = JPath::clean(JPATH_ROOT . DS . $config->jg_paththumbs . $catpath);
     //check with function Joom_CheckEmptyDirectory()
     //if folders are empty and writeable (permissions set for deletion)
     Joom_CheckEmptyDirectory($catorigdir, $catid);
     Joom_CheckEmptyDirectory($catpicdir, $catid);
     Joom_CheckEmptyDirectory($catthumbdir, $catid);
     //delete the folder in originals
     $resorig = JFolder::delete($catorigdir);
     //if not succesful, output an error message and abort
     if (!$resorig) {
         Joom_AlertErrorMessages(0, $catid, $catorigdir, 0);
     }
     //delete the folder in pictures
     $respic = JFolder::delete($catpicdir);
     //if not succesful....
     if (!$respic) {
         //try to recreate the folder in originals
         $resdiro = Joom_MakeDirectory($catorigdir);
         //if not succesful, output an error message and abort
         if ($resdiro != 0) {
             if ($resdiro == -1) {
                 Joom_AlertErrorMessages(0, $catid, $catorigdir, 0);
             }
             if ($resdiro == -2) {
                 Joom_AlertErrorMessages(0, $catid, $catorigdir, 0);
             }
         } else {
             //if not succesful, output an error message and abort
             Joom_AlertErrorMessages(0, $catid, $catpicdir, 0);
         }
     }
     //delete the thumbnail folder
     $resthumb = JFolder::delete($catthumbdir);
     //if not succesful....
     if (!$resthumb) {
         //try to recreate the folder in originals
         $resdiro = Joom_MakeDirectory($catorigdir);
         //if not succesful, output an error message and abort
         if ($resdiro != 0) {
             if ($resdiro == -1) {
                 Joom_AlertErrorMessages(0, $catid, $catorigdir, 0);
             }
             if ($resdiro == -2) {
                 Joom_AlertErrorMessages(0, $catid, $catorigdir, 0);
             }
         } else {
             //if not succesful, output an error message about thumbnail folder and abort
             Joom_AlertErrorMessages(0, $catid, $catthumbdir, 0);
         }
         //and try to recreate the folder in pictures
         $resdirp = Joom_MakeDirectory($catpicdir);
         //if not succesful in recreation,  output an error message and abort
         if ($resdirp != 0) {
             if ($resdirp == -1) {
                 Joom_AlertErrorMessages(0, $catid, $catpicdir, 0);
             }
             if ($resdirp == -2) {
                 Joom_AlertErrorMessages(0, $catid, $catpicdir, 0);
             }
         } else {
             //if not succesful, output an error message about picture folder and abort
             Joom_AlertErrorMessages(0, $catid, $catpicdir, 0);
         }
     }
     //delete database entry if all folders succesfully deleted
     $database->setQuery("DELETE\n        FROM #__joomgallery_catg\n        WHERE cid = {$catid}");
     $database->query();
     echo $database->getErrorMsg();
     //update of ordering
     $fp = new mosCatgs($database);
     $fp->reorder();
     //delete the userstate variable 'catid' if exists
     $mainframe->setUserState('joom.pictures.catid', '0');
 }
    /**
    * Single upload
    * The user choose single picture files and upload them
    * concurrent uploads can be modified in backend
    * @param Category ID
    */
    function Upload_Singles($catid)
    {
        $config = Joom_getConfig();
        $mainframe =& JFactory::getApplication('site');
        $database =& JFactory::getDBO();
        $user =& JFactory::getUser();
        jimport('joomla.filesystem.file');
        $debugoutput = '';
        //no user logged in
        if (!$user->get('id')) {
            $mainframe->redirect(JRoute::_('index.php?option=com_joomgallery' . _JOOM_ITEMID, false), JText::_('JGS_YOU_ARE_NOT_LOGGED'));
        }
        $catpath = Joom_GetCatPath($catid);
        $debugoutput .= '<p />';
        for ($i = 0; $i < $config->jg_maxuploadfields; $i++) {
            $screenshot = $this->arrscreenshot["tmp_name"][$i];
            $screenshot_name = $this->arrscreenshot["name"][$i];
            $screenshot_filesize = $this->arrscreenshot["size"][$i];
            $ii = $i + 1;
            //Any picture entry at position?
            //(4=UPLOAD_ERR_NO_FILE constant since PHP 4.3.0)
            //if not continue with next entry
            if ($this->arrscreenshot['error'][$i] == 4) {
                continue;
            }
            //Check for path exploits, and replace spaces
            $screenshot_name = Joom_FixFilename($screenshot_name);
            // Get extension
            $tag = strtolower(JFile::getExt($screenshot_name));
            if ($config->jg_useruploadnumber == 1) {
                $filecounter = $i + 1;
                $praefix = substr($screenshot_name, 0, strpos(strtolower($screenshot_name), $tag) - 1);
                $newfilename = $this->Upload_GenFilename($praefix, $tag, $filecounter);
            } else {
                $newfilename = $this->Upload_GenFilename($screenshot_name, $tag);
            }
            //Picture size must not exceed the setting in backend
            //except for Admin/SuperAdmin
            if ($screenshot_filesize > $config->jg_maxfilesize && !$this->adminlogged) {
                $debugoutput .= JText::_('JGS_ALERT_MAX_ALLOWED_FILESIZE') . " " . $config->jg_maxfilesize . " " . JText::_('JGS_ALERT_BYTES');
                continue;
            }
            //Check for right format
            if ($tag == 'jpeg' || $tag == 'jpg' || $tag == 'jpe' || $tag == 'gif' || $tag == 'png') {
                $debugoutput .= '<hr />Position: ' . $ii . '<br />';
                $debugoutput .= $ii . ". " . $screenshot_name . "<br />";
                //if picture already exists
                if (file_exists(JPath::clean(JPATH_ROOT . DS . $config->jg_pathimages . $catpath . $newfilename))) {
                    $debugoutput .= JText::_('JGS_ALERT_SAME_PICTURE_ALREADY_EXIST');
                    continue;
                }
                // We'll assume that this file is ok because with open_basedir,
                // we can move the file, but may not be able to access it until it's moved
                $returnval = JFile::upload($screenshot, JPATH_ROOT . DS . $config->jg_pathoriginalimages . DS . $catpath . $newfilename);
                if (!$returnval) {
                    $debugoutput .= JText::_('JGS_WRONG_FILENAME') . ': ' . JPATH_ROOT . DS . $config->jg_pathoriginalimages . $catpath . $newfilename . '<br />';
                    continue;
                }
                $debugoutput .= JText::_('JGS_UPLOAD_COMPLETE') . '...<br />';
                if (!($img_info = getimagesize(JPath::clean(JPATH_ROOT . DS . $config->jg_pathoriginalimages . $catpath . $newfilename)))) {
                    // getimagesize didn't find a valid image or this is
                    // some sort of hacking attempt
                    JFile::delete(JPATH_ROOT . DS . $config->jg_pathoriginalimages . DS . $catpath . $newfilename);
                    jexit();
                }
                //check the possible available memory for picture resizing
                //if not available echo error message and continue with next picture
                if ($this->Upload_CheckMemory($debugoutput, JPATH_ROOT . DS . $config->jg_pathoriginalimages . DS . $catpath . $newfilename, $tag) == false) {
                    $this->Upload_Rollback($debugoutput, JPATH_ROOT . DS . $config->jg_pathoriginalimages . $catpath . $newfilename, null, null);
                    continue;
                }
                // create thumb
                $returnval = Joom_ResizeImage($debugoutput, JPATH_ROOT . DS . $config->jg_pathoriginalimages . $catpath . $newfilename, JPATH_ROOT . DS . $config->jg_paththumbs . $catpath . $newfilename, $config->jg_useforresizedirection, $config->jg_thumbwidth, $config->jg_thumbheight, $config->jg_thumbcreation, $config->jg_thumbquality);
                if (!$returnval) {
                    $debugoutput .= JText::_('JGS_WRONG_FILENAME') . ': ' . JPATH_ROOT . DS . $config->jg_paththumbs . $catpath . $newfilename;
                    $this->Upload_Rollback($debugoutput, JPATH_ROOT . DS . $config->jg_pathoriginalimages . $catpath . $newfilename, null, null);
                    continue;
                }
                $debugoutput .= JText::_('JGS_THUMBNAIL_CREATED') . '...<br />';
                //create detail picture
                if ($config->jg_resizetomaxwidth && ($config->jg_special_gif_upload == 0 || $this->create_special_gif != 1 || $tag != 'gif' && $tag != 'png')) {
                    $returnval = Joom_ResizeImage($debugoutput, JPATH_ROOT . DS . $config->jg_pathoriginalimages . $catpath . $newfilename, JPATH_ROOT . DS . $config->jg_pathimages . $catpath . $newfilename, false, $config->jg_maxwidth, false, $config->jg_thumbcreation, $config->jg_picturequality, true);
                    if (!$returnval) {
                        $debugoutput .= JText::_('JGS_WRONG_FILENAME') . ': ' . JPATH_ROOT . DS . $config->jg_pathimages . $catpath . $newfilename;
                        $this->Upload_Rollback($debugoutput, JPATH_ROOT . DS . $config->jg_pathoriginalimages . $catpath . $newfilename, null, JPATH_ROOT . DS . $config->jg_paththumbs . $catpath . $newfilename);
                        continue;
                    }
                    $debugoutput .= JText::_('JGS_RESIZED_TO_MAXWIDTH') . '<br />';
                } else {
                    $returnval = JFile::copy($config->jg_pathoriginalimages . $catpath . $newfilename, $config->jg_pathimages . $catpath . $newfilename, JPATH_ROOT);
                    if (!$returnval) {
                        $debugoutput .= JText::_('JGS_PROBLEM_COPYING ') . $config->jg_pathimages . $catpath . $newfilename;
                        $this->Upload_Rollback($debugoutput, JPATH_ROOT . DS . $config->jg_pathoriginalimages . $catpath . $newfilename, null, JPATH_ROOT . DS . $config->jg_paththumbs . $catpath . $newfilename);
                        continue;
                    }
                }
                if ($config->jg_delete_original_user == 1 || $config->jg_delete_original_user == 2 && $this->original_delete == 1) {
                    if (JFile::delete(JPATH_ROOT . DS . $config->jg_pathoriginalimages . $catpath . $newfilename)) {
                        $debugoutput .= JText::_('JGS_ORIGINAL_DELETED') . '<br />';
                    } else {
                        $debugoutput .= JText::_('JGS_PROBLEM_DELETING_ORIGINAL') . ' - ' . JText::_('JGS_CHECK_PERMISSIONS');
                        $this->Upload_Rollback($debugoutput, null, JPATH_ROOT . DS . $config->jg_pathimages . $catpath . $newfilename, JPATH_ROOT . DS . $config->jg_paththumbs . $catpath . $newfilename);
                        continue;
                    }
                }
                $ordering = $this->Upload_GetOrdering($config->jg_uploadorder, $catid);
                $row = new mosjoomgallery($database);
                if (!$row->bind($_POST, JText::_('JGS_APPROVED_OWNER_PUBLISHED'))) {
                    $this->Upload_Rollback($debugoutput, JPATH_ROOT . DS . $config->jg_pathoriginalimages . $catpath . $newfilename, JPATH_ROOT . DS . $config->jg_pathimages . $catpath . $newfilename, JPATH_ROOT . DS . $config->jg_paththumbs . $catpath . $newfilename);
                    echo "<script> alert('" . $row->getError() . "'); window.history.go(-1); </script>\n";
                    jexit();
                }
                $row->imgdate = mktime();
                $row->owner = $user->get('id');
                $row->published = 1;
                //Upload from admin/superadmin are approved
                if ($config->jg_approve == 1 && !$this->adminlogged) {
                    $row->approved = 0;
                } else {
                    $row->approved = 1;
                }
                $row->imgfilename = $newfilename;
                $row->imgthumbname = $newfilename;
                $row->useruploaded = 1;
                $row->ordering = $ordering;
                //Wenn im Backend die Vergabe von lfd. Nummern eingestellt wurde
                //wird dem Bildtitel die lfd. Nummer (+1) hinzugefügt
                if ($config->jg_useruploadnumber) {
                    $row->imgtitle = $row->imgtitle . '_' . $filecounter;
                }
                if (!$row->store()) {
                    $this->Upload_Rollback($debugoutput, JPATH_ROOT . DS . $config->jg_pathoriginalimages . $catpath . $newfilename, JPATH_ROOT . DS . $config->jg_pathimages . $catpath . $newfilename, JPATH_ROOT . DS . $config->jg_paththumbs . $catpath . $newfilename);
                    $debugoutput .= $row->getError();
                    continue;
                } else {
                    // E-Mail ueber ein neues Bild an die User, die global als User Email-Empfang
                    // erlaubt haben TODO -> In Backend-Konfig einstellen bzw. deaktivieren
                    /* TODO
                       // portierung: /administrator/components/com_messages/tables/message.php anstatt administrator/components/com_messages/messages.class.php
                       require_once(JPATH_ADMINISTRATOR.DS.'components'.DS.'com_messages'.DS.'tables'.DS.'message.php' );
                       $database->setQuery("SELECT id
                           FROM #__users
                           WHERE sendEmail='1'");
                       $users = $database->loadResultArray();
                       foreach ($users as $user_id) {
                         $msg = new TableMessage($database); // portierung: TableMessage anstatt mosMessage
                         $msg->send($user->get('id'),
                         $user_id,
                         JText::_('JGS_NEW_PICTURE_UPLOADED'),
                         sprintf( JText::_('JGS_NEW_CONTENT_SUBMITTED') . " %s " . JText::_('JGS_TITLED') ." %s.",
                         $user->get('username'),
                         $row->imgtitle));
                       }
                       */
                    $debugoutput .= JText::_('JGS_ALERT_PICTURE_SUCCESSFULLY_ADDED') . '<br />';
                    $debugoutput .= JText::_('JGS_NEW_FILENAME') . ': ' . $newfilename . '<br /><br />';
                }
            } else {
                $debugoutput .= JText::_('JGS_ALERT_INVALID_IMAGE_TYPE');
                continue;
            }
        }
        echo $debugoutput;
        ?>
    <p>
      <img src="<?php 
        echo _JOOM_LIVE_SITE . 'components/com_joomgallery/assets/images/arrow.png';
        ?>
" class="pngfile jg_icon" alt="arrow" />
      <a href="<?php 
        echo JRoute::_('index.php?option=com_joomgallery&func=showupload' . _JOOM_ITEMID);
        ?>
">
        <?php 
        echo JText::_('JGS_MORE_UPLOADS');
        ?>
      </a>
    </p>
    <p>
      <img src="<?php 
        echo _JOOM_LIVE_SITE . 'components/com_joomgallery/assets/images/arrow.png';
        ?>
" class="pngfile jg_icon" alt="arrow" />
      <a href="<?php 
        echo JRoute::_('index.php?option=com_joomgallery&func=userpanel' . _JOOM_ITEMID);
        ?>
">
        <?php 
        echo JText::_('JGS_BACK_TO_USER_PANEL');
        ?>
      </a>
    </p>
    <p>
      <img src="<?php 
        echo _JOOM_LIVE_SITE . 'components/com_joomgallery/assets/images/arrow.png';
        ?>
" class="pngfile jg_icon" alt="arrow" />
      <a href="<?php 
        echo JRoute::_('index.php?option=com_joomgallery&startpage=1' . _JOOM_ITEMID);
        ?>
">
        <?php 
        echo JText::_('JGS_BACK_TO_GALLERY');
        ?>
      </a>
    </p>
<?php 
    }
    /**
     * Comments manager
     *
     * @param string $rows
     * @param string $search
     * @param object $pageNav
     */
    function Joom_ShowComments_HTML(&$rows, &$search, &$pageNav)
    {
        $config = Joom_getConfig();
        $database =& JFactory::getDBO();
        jimport('joomla.filesystem.file');
        ?>
<script  type="text/javascript" src="<?php 
        echo _JOOM_LIVE_SITE;
        ?>
includes/js/overlib_mini.js"></script>
<form action="index.php" method="post" name="adminForm">
<table cellpadding="4" cellspacing="0" border="0" width="100%">
  <tr>
    <td width="100%"></td>
    <td>
      <?php 
        echo JText::_('JGA_SEARCH');
        ?>
    </td>
    <td>
      <input type="text" name="search" value="<?php 
        echo $search;
        ?>
" class="inputbox" onChange="document.adminForm.submit();" />
    </td>
  </tr>
</table>
<table cellpadding="4" cellspacing="0" border="0" width="100%" class="adminlist">
  <tr>
    <th width="20">
      <input type="checkbox" name="toggle" value="" onclick="checkAll(<?php 
        echo count($rows);
        ?>
);" />
    </th>
    <th class="title" width="15%">
      <div align="left">
        <?php 
        echo JText::_('JGA_AUTHOR');
        ?>
      </div>
    </th>
    <th width="35%">
      <div align="left">
        <?php 
        echo JText::_('JGA_TEXT');
        ?>
      </div>
    </th>
    <th width="10%">
      <div align="center">
      <?php 
        echo JText::_('JGA_IP');
        ?>
      </div>
    </th>
    <th width="10%">
      <?php 
        echo JText::_('JGA_PUBLISHED');
        ?>
    </th>
    <th width="10%">
      <?php 
        echo JText::_('JGA_APPROVED');
        ?>
    </th>
    <th width="10%">
      <?php 
        echo JText::_('JGA_PICTURE');
        ?>
    </th>
    <th width="24"></th>
    <th width="15%">
      <?php 
        echo JText::_('JGA_DATE');
        ?>
    </th>
  </tr>
<?php 
        $k = 0;
        for ($i = 0, $n = count($rows); $i < $n; $i++) {
            $row =& $rows[$i];
            $task = $row->published ? 'unpublishcmt' : 'publishcmt';
            $img = $row->published ? 'tick.png' : 'publish_x.png';
            $taska = $row->approved ? 'rejectcmt' : 'approvecmt';
            $imga = $row->approved ? 'tick.png' : 'publish_x.png';
            ?>
  <tr class="<?php 
            echo "row{$k}";
            ?>
">
    <td>
      <input type="checkbox" id="cb<?php 
            echo $i;
            ?>
" name="id[]" value="<?php 
            echo $row->cmtid;
            ?>
" onclick="isChecked(this.checked);" />
    </td>
    <td>
      <div align="left">
<?php 
            if ($row->userid > 0) {
                echo Joom_GetDisplayName($row->userid, false);
            } else {
                echo $row->cmtname;
            }
            ?>
      </div>
    </td>
    <td>
      <div align="left">
<?php 
            $cmttext = Joom_ProcessText($row->cmttext);
            ?>
        <?php 
            echo $cmttext;
            ?>
      </div>
    </td>
    <td>
      <div align="center">
        <?php 
            echo $row->cmtip;
            ?>
      </div>
    </td>
    <td align='center'>
      <a href="javascript: void(0);" onClick="return listItemTask('cb<?php 
            echo $i;
            ?>
','<?php 
            echo $task;
            ?>
')">
        <img src="images/<?php 
            echo $img;
            ?>
" border="0" alt="" /><?php 
            /* portierung: width und height entfernt */
            ?>
      </a>
    </td>
    <td align='center'>
      <a href="javascript: void(0);" onClick="return listItemTask('cb<?php 
            echo $i;
            ?>
','<?php 
            echo $taska;
            ?>
')">
        <img src="images/<?php 
            echo $imga;
            ?>
" border="0" alt="" /><?php 
            /* portierung: width und height entfernt */
            ?>
      </a>
    </td>
    <td width="10%" align="center">
      <?php 
            echo $row->cmtpic;
            ?>
    </td>
    <td>
<?php 
            $database->setQuery("SELECT imgthumbname\n            FROM #__joomgallery\n            WHERE id = '{$row->cmtpic}'");
            $is_imgthumbname = $database->loadResult();
            $database->setQuery("SELECT catid\n            FROM #__joomgallery\n            WHERE id = '{$row->cmtpic}'");
            $is_catid = $database->loadResult();
            $catpath = Joom_GetCatPath($is_catid);
            if (JFile::exists(JPATH_ROOT . DS . $config->jg_paththumbs . $catpath . $is_imgthumbname)) {
                $imginfo = getimagesize(JPath::clean(JPATH_ROOT . DS . $config->jg_paththumbs . $catpath . $is_imgthumbname));
                $imgsource = _JOOM_LIVE_SITE . $config->jg_paththumbs . $catpath . $is_imgthumbname;
                $srcWidth = $imginfo[0];
                $srcHeight = $imginfo[1];
                $thumbexists = 1;
            } else {
                $thumbexists = 0;
            }
            if ($thumbexists) {
                ?>
      <a href="<?php 
                echo _JOOM_LIVE_SITE;
                ?>
index.php?option=<?php 
                echo _JOOM_OPTION;
                ?>
&amp;func=detail&amp;id=<?php 
                echo $row->cmtpic;
                ?>
" onmouseover="return overlib('<img src=\'<?php 
                echo $imgsource;
                ?>
\' />',WIDTH,<?php 
                echo $srcWidth;
                ?>
, HEIGHT,<?php 
                echo $srcHeight;
                ?>
)"  onmouseout="return nd()";target="_blank">
        <img src="<?php 
                echo $imgsource;
                ?>
" border="0" width="24" height="24" alt="" />
      </a>
<?php 
            } else {
                ?>
      &nbsp;
<?php 
            }
            ?>

    </td>
    <td width="10%" align="center">
      <?php 
            echo strftime($config->jg_dateformat, $row->cmtdate);
            ?>
    </td>
<?php 
            $k = 1 - $k;
            ?>
  </tr>
<?php 
        }
        ?>
  <tr>
    <td colspan="9">
      <?php 
        echo $pageNav->getListFooter();
        ?>
    </td>
  </tr>
</table>
<input type="hidden" name="option" value="<?php 
        echo _JOOM_OPTION;
        ?>
" />
<input type="hidden" name="task" value="comments" />
<input type="hidden" name="boxchecked" value="0" />
</form>
<?php 
    }
/**
 * recreates thumbnails of the selected images
 * if original image is existent, detail image will be recreated, too.
 */
function Joom_Recreate()
{
    jimport('joomla.filesystem.file');
    $mainframe =& JFactory::getApplication('administrator');
    $database =& JFactory::getDBO();
    $config = Joom_GetConfig();
    $cids = $mainframe->getUserStateFromRequest('joom.recreate.ids', 'id', array(), 'array');
    $thumb_count = $mainframe->getUserState('joom.recreate.thumbcount');
    $img_count = $mainframe->getUserState('joom.recreate.imgcount');
    $row = new mosjoomgallery($database);
    // before first loop check for selected images
    if (is_null($thumb_count) and !count($cids)) {
        return array(false, JText::_('JGA_NO_IMAGES_SELECTED'));
    }
    //Check the maximum execution time of the script
    //set secure setting of the real execution time
    $max_execution_time = @ini_get('max_execution_time');
    //try to set the max execution time to 60s if lower than
    //if not succesful the return value will be the old time, so use this
    if ($max_execution_time < 60) {
        #@ini_set('max_execution_time','60');
        $max_execution_time = @ini_get('max_execution_time');
    }
    $maxtime = (int) $max_execution_time * 0.8;
    $starttime = time();
    $debugoutput = '';
    //loop through selected images
    foreach ($cids as $key => $cid) {
        $row->load($cid);
        //catpath for category
        $catpath = Joom_GetCatPath($row->catid);
        $orig = JPATH_ROOT . DS . $config->jg_pathoriginalimages . $catpath . $row->imgfilename;
        $img = JPATH_ROOT . DS . $config->jg_pathimages . $catpath . $row->imgfilename;
        $thumb = JPATH_ROOT . DS . $config->jg_paththumbs . $catpath . $row->imgthumbname;
        //check if there is an original image
        if (JFile::exists($orig)) {
            $orig_existent = true;
        } else {
            //if not, use detail image to create thumbnail
            $orig_existent = false;
            if (JFile::exists($img)) {
                $orig = $img;
            } else {
                JError::raiseWarning(100, JText::sprintf('JGA_IMG_NOT_EXISTENT', $img));
                $mainframe->setUserState('joom.recreate.cids', array());
                $mainframe->setUserState('joom.recreate.count', null);
                return false;
            }
        }
        //TODO: move image into a trash instead of deleting immediately for possible rollback
        JFile::delete($thumb);
        $return = Joom_ResizeImage($debugoutput, $orig, $thumb, $config->jg_useforresizedirection, $config->jg_thumbwidth, $config->jg_thumbheight, $config->jg_thumbcreation, $config->jg_thumbquality);
        if (!$return) {
            JError::raiseWarning(100, JText::sprintf('JGA_COULD_NOT_CREATE_THUMB', $thumb));
            $mainframe->setUserState('joom.recreate.cids', array());
            $mainframe->setUserState('joom.recreate.thumbcount', null);
            $mainframe->setUserState('joom.recreate.imgcount', null);
            return false;
        }
        $mainframe->enqueueMessage(JText::sprintf('JGA_SUCCESSFULLY_CREATED_THUMB', $row->id, $row->imgtitle));
        $thumb_count++;
        if ($orig_existent) {
            //TODO: move image into a trash instead of deleting immediately for possible rollback
            JFile::delete($img);
            $return = Joom_ResizeImage($debugoutput, $orig, $img, false, $config->jg_maxwidth, false, $config->jg_thumbcreation, $config->jg_picturequality, true);
            if (!$return) {
                JError::raiseWarning(100, JText::sprintf('JGA_COULD_NOT_CREATE_IMG', $img));
                $this->_mainframe->setUserState('joom.recreate.cids', array());
                $this->_mainframe->setUserState('joom.recreate.thumbcount', null);
                $this->_mainframe->setUserState('joom.recreate.imgcount', null);
                return false;
            }
        }
        $mainframe->enqueueMessage(JText::sprintf('JGA_SUCCESSFULLY_CREATED_IMG', $row->id, $row->imgtitle));
        $img_count++;
        unset($cids[$key]);
        //check remaining time
        $timeleft = -(time() - $starttime - $maxtime);
        if ($timeleft <= 0 and count($cids)) {
            $mainframe->setUserState('joom.recreate.cids', $cids);
            $mainframe->setUserState('joom.recreate.thumbcount', $thumb_count);
            $mainframe->setUserState('joom.recreate.imgcount', $img_count);
            $mainframe->redirect('index.php?option=' . _JOOM_OPTION . '&task=recreate', JText::_('JGA_REDIRECT'));
        }
    }
    $mainframe->setUserState('joom.recreate.cids', array());
    $mainframe->setUserState('joom.recreate.thumbcount', null);
    $mainframe->setUserState('joom.recreate.imgcount', null);
    return array($thumb_count, $img_count);
}