/**
    * 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 
    }
 /**
 * Sicherung der Aenderungen an dem Bild
 */
 function Joom_User_SavePic()
 {
     $config = Joom_getConfig();
     $mainframe =& JFactory::getApplication('site');
     $database =& JFactory::getDBO();
     $user =& JFactory::getUser();
     jimport('joomla.filesystem.file');
     $row = new mosjoomgallery($database);
     //bestehenden DB Eintrag einlesen
     $row->load($this->picid);
     //alte Angaben sichern
     $catid_old = $row->catid;
     $catpath_old = Joom_GetCatPath($row->catid);
     if (!$row->bind($_POST)) {
         echo "<script> alert('" . $row->getError() . "'); window.history.go(-1); </script>\n";
         exit;
     }
     if (get_magic_quotes_gpc()) {
         $row->imgtitle = stripslashes($row->imgtitle);
         $row->imgtext = stripslashes($row->imgtext);
     }
     //wenn sich die Kategorie geaendert hat, die Bilddateien verschieben
     if ($catid_old != $row->catid) {
         $catpathold = $catpath_old;
         $catpathnew = Joom_GetCatPath($row->catid);
         $cat_originalpathold = JPath::clean(JPATH_ROOT . DS . $config->jg_pathoriginalimages . $catpath_old);
         $cat_picturepathold = JPath::clean(JPATH_ROOT . DS . $config->jg_pathimages . $catpath_old);
         $cat_thumbnailpathold = JPath::clean(JPATH_ROOT . DS . $config->jg_paththumbs . $catpath_old);
         $cat_originalpathnew = JPath::clean(JPATH_ROOT . DS . $config->jg_pathoriginalimages . $catpathnew);
         $cat_picturepathnew = JPath::clean(JPATH_ROOT . DS . $config->jg_pathimages . $catpathnew);
         $cat_thumbnailpathnew = JPath::clean(JPATH_ROOT . DS . $config->jg_paththumbs . $catpathnew);
         JFile::move($cat_originalpathold . $row->imgfilename, $cat_originalpathnew . $row->imgfilename);
         JFile::move($cat_picturepathold . $row->imgfilename, $cat_picturepathnew . $row->imgfilename);
         JFile::move($cat_thumbnailpathold . $row->imgfilename, $cat_thumbnailpathnew . $row->imgfilename);
     }
     if (!$row->store()) {
         echo "<script> alert('" . $row->getError() . "'); window.history.go(-1); </script>\n";
         exit;
     }
     $mainframe->redirect(JRoute::_($this->userpanel_url . _JOOM_ITEMID, false), JText::_('JGS_ALERT_PICTURE_SUCCESSFULLY_UPDATED'));
 }
 /**
  * Saves a via EDIT in picture manager modified picture
  * @param bool $clearPicVotes true=clear votes
  */
 function Joom_SaveEditPicture($clearPicVotes = false)
 {
     $mainframe =& JFactory::getApplication('administrator');
     $database =& JFactory::getDBO();
     $row = new mosjoomgallery($database);
     if (!$row->bind($_POST)) {
         echo "<script> alert('" . $row->getError() . "'); window.history.go(-1); </script>\n";
         exit;
     }
     if (get_magic_quotes_gpc()) {
         $row->imgtitle = stripslashes($row->imgtitle);
         $row->imgtext = stripslashes($row->imgtext);
         $row->imgauthor = stripslashes($row->imgauthor);
     }
     //clear votes if "clear" checked
     if ($clearPicVotes) {
         $row->imgvotes = 0;
         $row->imgvotesum = 0;
         // delete votes for picture
         $query = "DELETE FROM #__joomgallery_votes WHERE picid = {$row->id}";
         $database->setQuery($query);
         if (!$database->query()) {
             echo "<script> alert('" . $database->getErrorMsg() . "'); window.history.go(-1); </script>\n";
             exit;
         }
     }
     if (!$row->store()) {
         echo "<script> alert('" . $row->getError() . "'); window.history.go(-1); </script>\n";
         exit;
     }
     $mainframe->redirect('index.php?option=' . _JOOM_OPTION . '&act=pictures');
 }