/** * save a edited category * * @param int $cid id of category */ function Joom_SaveEditCategory(&$cid) { $config = Joom_getConfig(); $mainframe =& JFactory::getApplication('administrator'); $database =& JFactory::getDBO(); jimport('joomla.filesystem.folder'); $row = new mosCatgs($database); //read category from DB $row->load($cid); //read old parent assignment $parentold = $row->parent; //read old title $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 (intval($row->owner) == 0) { $row->owner = null; } //make the new category title safe if ($catnameold != $row->name) { JFilterOutput::objectHTMLSafe($row->name); $catname = $row->name; $catnamemodif = true; } else { $catname = $catnameold; $catnamemodif = false; } //move the category folder, if parent assignment or category name changed if ($parentold != $row->parent || $catnamemodif == true) { //save old path $catpathold = $row->catpath; $parentpathnew = Joom_GetCatPath($row->parent); //Joom_FixFilename() convert/remove special chars except the underscore //affects only catpath $catname = Joom_FixFilename($catname); $catpathnew = $parentpathnew . $catname . '_' . $row->cid; $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); //move folders //actualize catpath in DB $row->catpath = $catpathnew; //TODO error messages JFolder::move($cat_originalpathold, $cat_originalpathnew); JFolder::move($cat_picturepathold, $cat_picturepathnew); JFolder::move($cat_thumbnailpathold, $cat_thumbnailpathnew); //if parent category changes, modify catpath of all subcategories in DB $rowid = $row->cid; Joom_UpdateNewCatpath($rowid, $catpathold, $catpathnew); } if (!$row->store(true)) { echo "<script> alert('" . $row->getError() . "'); window.history.go(-1); </script>\n"; exit; } // redirect to category manager //TODO aha: message $mainframe->redirect('index.php?option=' . _JOOM_OPTION . '&act=categories'); }
/** * Update of category path in DB for subcategories if a parent category has * been moved or the name changed * recursive call to each count of depth * * @param integer $catids_values: ID(s) of the modifie category * @param string $oldpath: former rel. category path * @param string $newpath: actual rel. category path * */ function Joom_UpdateNewCatpath($catids_values, &$oldpath, &$newpath) { $database =& JFactory::getDBO(); //query for subcategories with parent in $catids_values $database->setQuery("SELECT cid\n FROM #__joomgallery_catg\n WHERE parent in ({$catids_values}) "); $subcatids = $database->loadResultArray(); if ($database->getErrorNum()) { echo $database->stderr(true); } // nothing found, return if (count($subcatids) == 0) { return; } $row = new mosCatgs($database); foreach ($subcatids as $subcatid) { $row->load($subcatid); $catpath = $row->catpath; //replace former category path with actual one $catpath = str_replace($oldpath . '/', $newpath . '/', $catpath); //and save it $row->catpath = $catpath; if (!$row->store()) { echo "<script> alert('" . $row->getError() . "'); window.history.go(-1); </script>\n"; exit; } } //split the array in comme seperated string $catids_values = implode(",", $subcatids); //call again with subcategories as parent Joom_UpdateNewCatpath($catids_values, $oldpath, $newpath); }
/** * Aendern einer bestehenden Kategorie */ function Joom_User_EditPic() { $config = Joom_getConfig(); $mainframe =& JFactory::getApplication('site'); $database =& JFactory::getDBO(); $user =& JFactory::getUser(); $row = new mosjoomgallery($database); $row->load($this->picid); if ($row->owner != $user->get('id') && !$this->adminlogged) { $mainframe->redirect(JRoute::_('index.php?option=com_joomgallery' . _JOOM_ITEMID, false), JText::_('JGS_ALERT_NOT_ALLOWED_TO_EDIT_PICTURE')); } if ($this->adminlogged) { $clist = Joom_ShowDropDownCategoryList($row->catid, 'catid'); } else { $clist = $this->Joom_User_ShowDropDownCategoryList($row->catid); } //wenn $clist = null, wurde das Bild in eine Backend-Kategorie geladen, //die nicht mehr freigeschaltet ist. Oder es handelt sich um die einzige //Kategorie. In diesem Fall nur den Text der Kategorie ausgeben if ($clist == null) { $rowcat = new mosCatgs($database); $rowcat->load($row->catid); $clist = $rowcat->name; } HTML_Joom_UserPanel::Joom_User_EditPic_HTML($row, $clist); }
/** * Move pictures * @param array $id: id's of pictures to be moved */ function Joom_SaveMovePicture($id) { $config = Joom_getConfig(); $mainframe =& JFactory::getApplication('administrator'); $database =& JFactory::getDBO(); $user =& JFactory::getUser(); jimport('joomla.filesystem.file'); //TODO: error messages //id of destination category $pictureMove = JRequest::getInt('catid', '', 'post'); //when no category chosen before if (!$pictureMove || $pictureMove == 0) { //error message and abort echo "<script> alert('" . JText::_('JGA_ALERT_PLEASE_SELECT_CATEGORY', true) . "');\n window.history.go(-1);</script>\n"; exit; //category chosen } else { //and the array contains picture if (count($id)) { //create a new array which contains the succesful moved pictures $successids = array(); //loop through array for ($i = 0; $i < count($id); $i++) { //database query for picture title and the catid from source category $database->setQuery("SELECT id, catid, imgfilename, imgthumbname\n FROM #__joomgallery\n WHERE id = {$id[$i]}"); //if succesful if ($database->query()) { //write in array $rows = $database->loadObjectList(); $row = $rows[0]; //write to class members $this->imgfilename = $row->imgfilename; $this->imgthumbname = $row->imgthumbname; $old_catid = $row->catid; //catpath for new category $catpath = Joom_GetCatPath($pictureMove); //catpath for old category $catpath_ori = Joom_GetCatPath($row->catid); //query if there are entries in which the picture file to move //is assigned and count them $database->setQuery("SELECT COUNT(id)\n FROM #__joomgallery\n WHERE imgthumbname = '" . $this->imgthumbname . "'\n AND id != '" . $id[$i] . "'\n AND catid = '" . $old_catid . "'"); $count2 = $database->loadResult(); //check if thumbnail already exists in source directory and not //exists already in destination //otherwise the file will not be copied if (JFile::exists(JPATH_ROOT . DS . $config->jg_paththumbs . $catpath_ori . $this->imgthumbname) && !JFile::exists(JPATH_ROOT . DS . $config->jg_paththumbs . $catpath . $this->imgthumbname)) { //if there is no picture remaining in source directory //which uses the picture if ($count2 < 1) { //move the thumbnail $result = JFile::move($config->jg_paththumbs . $catpath_ori . $this->imgthumbname, $config->jg_paththumbs . $catpath . $this->imgthumbname, JPATH_ROOT); //otherwise... } else { //copy the thumbnail and let it remain in source $result = JFile::copy($config->jg_paththumbs . $catpath_ori . $this->imgthumbname, $config->jg_paththumbs . $catpath . $this->imgthumbname, JPATH_ROOT); } //if not succesful error message and abort if (!$result) { Joom_AlertErrorMessages(0, 0, 0, $successids); } //set control variable according to succesful move/copy $thumb = 1; //not succesful } else { $thumb = 0; } //same procedure with detail //in case of error call previous copy/move of $database->setQuery("SELECT COUNT(id)\n FROM #__joomgallery\n WHERE imgfilename = '" . $this->imgfilename . "'\n AND id != '" . $id[$i] . "'\n AND catid = '" . $old_catid . "'"); $count = $database->loadResult(); $imgsource = JPATH_ROOT . DS . $config->jg_pathimages . $catpath_ori . $this->imgfilename; $imgdest = JPATH_ROOT . DS . $config->jg_pathimages . $catpath . $this->imgfilename; if (JFile::exists($imgsource) && !JFile::exists($imgdest)) { if ($count < 1) { $result2 = JFile::move($catpath_ori . $this->imgfilename, $catpath . $this->imgfilename, JPATH_ROOT . DS . $config->jg_pathimages); } else { $result2 = JFile::copy($catpath_ori . $this->imgfilename, $catpath . $this->imgfilename, JPATH_ROOT . DS . $config->jg_pathimages); } if (!$result2) { if ($thumb == 1) { if ($count2 < 1) { JFile::move($config->jg_paththumbs . $catpath . $this->imgthumbname, $config->jg_paththumbs . $catpath_ori . $this->imgthumbname, JPATH_ROOT); } else { JFile::delete(JPATH_ROOT . DS . $config->jg_paththumbs . $catpath . $this->imgthumbname); } } Joom_AlertErrorMessages(0, 0, 0, $successids); } $picture = 1; } else { $picture = 0; } if (JFile::exists(JPATH_ROOT . DS . $config->jg_pathoriginalimages . $catpath_ori . $this->imgfilename) && !JFile::exists(JPATH_ROOT . DS . $config->jg_pathoriginalimages . $catpath . $this->imgfilename)) { if ($count < 1) { $result3 = JFile::move($catpath_ori . $this->imgfilename, $catpath . $this->imgfilename, JPATH_ROOT . DS . $config->jg_pathoriginalimages); } else { $result3 = JFile::copy($catpath_ori . $this->imgfilename, $catpath . $this->imgfilename, JPATH_ROOT . DS . $config->jg_pathoriginalimages); } if (!$result3) { if ($thumb == 1) { if ($count2 < 1) { JFile::move($config->jg_paththumbs . $catpath . $this->imgthumbname, $config->jg_paththumbs . $catpath_ori . $this->imgthumbname, JPATH_ROOT); } else { JFile::delete(JPATH_ROOT . DS . $config->jg_paththumbs . $catpath . $this->imgthumbname); } } if ($picture == 1) { if ($count < 1) { JFile::move($config->jg_pathimages . $catpath . $this->imgfilename, $config->jg_pathimages . $catpath_ori . $this->imgfilename, JPATH_ROOT); } else { JFile::delete(JPATH_ROOT . DS . $config->jg_pathimages . $catpath . $this->imgfilename); } } Joom_AlertErrorMessages(0, 0, 0, $successids); } } //if database query not succesful error message and abort } else { echo "<script> alert('" . $database->getErrorMsg() . "');\n window.history.go(-1); </script>\n"; } //add the succesful processed picture (id) to array array_push($successids, $id[$i]); //if all folder operations for the picture succesful //modify the database entry $pic = new mosjoomgallery($database); //call Joom_MovePictures $pic->Joom_MovePictures($id[$i], $pictureMove); //new object from mosCatgs $cat = new mosCatgs($database); $cat->load($pictureMove); } } //construct the success message //count of moved pictures $total = count($successids); //TODO: MSG 'x Bilder verschoben zu y' anpassen $msg = $total . " Pictures moved to " . $cat->name; //redirect to picture manager with success message $mainframe->redirect('index.php?option=' . _JOOM_OPTION . '&act=pictures', $msg); } }