/** * saves a changed or a new category * * @param integer $cid, if null -> new category */ function Joom_User_SaveUserCat(&$cid) { $config = Joom_getConfig(); $mainframe =& JFactory::getApplication('site'); $database =& JFactory::getDBO(); $user =& JFactory::getUser(); jimport('joomla.filesystem.file'); $row = new mosCatgs($database); if ($cid == 0) { $database->setQuery(" SELECT \n COUNT(cid)\n FROM \n #__joomgallery_catg\n WHERE \n owner=" . $user->get('id') . " \n "); $countcat = $database->loadResult(); if ($countcat >= $config->jg_maxusercat) { $mainframe->redirect('index.php?option=com_joomgallery&func=showusercats' . _JOOM_ITEMID, false); } $newcat = true; } else { $newcat = false; //load an existing category $row->load($cid); //get old parent category $parentold = $row->parent; //get old category name $catnameold = $row->name; } //get new values if (!$row->bind($_POST)) { echo "<script> alert('" . $row->getError() . "'); window.history.go(-1); </script>\n"; exit; } if (get_magic_quotes_gpc()) { $row->name = stripslashes($row->name); $row->description = stripslashes($row->description); } if (!$newcat) { if ($catnameold != $row->name) { // Macht den neuen Kategorienamen sicher, wenn geaendert JFilterOutput::objectHTMLSafe($row->name); // Joom_FixCatname; Umlaute werden umgewandelt und alle Sonderzeichen bis auf // den Unterstrich entfernt, gilt nur fuer den catpath $catname = Joom_FixCatname($row->name); $catnamemodif = true; } else { $catname = $catnameold; $catnamemodif = false; } //Kategorieordner verschieben, wenn die Parentzuordnung oder der Kategoriename //geaendert wurde if ($parentold != $row->parent || $catnamemodif == true) { //alten Pfad sichern $catpathold = $row->catpath; //Kategoriepfad der Parent-Kategorie lesen, nur noetig wenn parent != 0 if ($row->parent != 0) { $row_parent = new mosCatgs($database); $row_parent->load($row->parent); $catpathnew = $row_parent->catpath . '/' . $catname . '_' . $row->cid; } else { $catpathnew = $catname . '_' . $row->cid; } //Kategoriepfad in DB aktualisieren $row->catpath = $catpathnew; $cat_originalpathold = JPath::clean(JPATH_ROOT . DS . $config->jg_pathoriginalimages . $catpathold); $cat_picturepathold = JPath::clean(JPATH_ROOT . DS . $config->jg_pathimages . $catpathold); $cat_thumbnailpathold = JPath::clean(JPATH_ROOT . DS . $config->jg_paththumbs . $catpathold); $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); //Ordner verschieben //TODO Fehlermeldungen JFolder::move($cat_originalpathold, $cat_originalpathnew); JFolder::move($cat_picturepathold, $cat_picturepathnew); JFolder::move($cat_thumbnailpathold, $cat_thumbnailpathnew); //wenn Parentkategorie geaendert wurde, den Catpath aller Unterkategorien //in DB anpassen $rowid = $row->cid; Joom_UpdateNewCatpath($rowid, $catpathold, $catpathnew); } if (!$row->store()) { echo "<script> alert('" . $row->getError() . "'); window.history.go(-1); </script>\n"; exit; } } else { //Neue Kategorie //Kategorienamen absichern JFilterOutput::objectHTMLSafe($row->name); // Joom_FixCatname; Umlaute werden umgewandelt und alle Sonderzeichen bis auf // den Unterstrich entfernt, gilt nur fuer den catpath $catname = Joom_FixCatname($row->name); $row->img_position = 0; $row->catimage = null; //access von der Elternkategorie erben, wenn nicht Admin/SuperAdmin if (!$this->adminlogged) { $row->owner = $user->get('id'); $rowparent = new mosCatgs($database); $rowparent->load($row->parent); $row->access = $rowparent->access; } else { $row->owner = null; } //Anlegen des DB Eintrages if (!$row->store()) { echo "<script> alert('" . $row->getError() . "'); window.history.go(-1); </script>\n"; exit; } //catpath mit vergebener cid aufbauen $parentpathnew = Joom_GetCatPath($row->parent); $catpathnew = $parentpathnew . $catname . '_' . $row->cid; $row->catpath = $catpathnew; $row->store(); //Kategorieverzeichnisse anlegen Joom_MakeDirectory(JPATH_ROOT . DS . $config->jg_pathoriginalimages . $catpathnew); Joom_MakeDirectory(JPATH_ROOT . DS . $config->jg_pathimages . $catpathnew); Joom_MakeDirectory(JPATH_ROOT . DS . $config->jg_paththumbs . $catpathnew); } // Redirect zur Kategorieuebersicht $mainframe->redirect(JRoute::_('index.php?option=com_joomgallery&func=showusercats&uid=' . $user->get('id') . _JOOM_ITEMID, false)); }
/** * cancel an action in category manager (Cancel). * */ function Joom_CancelCategory() { $mainframe =& JFactory::getApplication('administrator'); $database =& JFactory::getDBO(); $row = new mosCatgs($database); $row->bind($_POST); $row->checkin(); // redirect to category manager $mainframe->redirect('index.php?option=' . _JOOM_OPTION . '&act=categories'); }
/** * 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; } }