function createsubcategory() { JRequest::checkToken() or jexit('Invalid Token'); $task = $this->input->get('task', '', 'string'); $post['title'] = $this->input->get('subcategoryname', '', 'string'); $post['description'] = $this->input->get('phocagallerycreatesubcatdescription', '', 'string'); $post['parent_id'] = $this->input->get('parentcategoryid', 0, 'int'); $task = $this->input->get('task', '', 'string'); $post['title'] = $this->input->get('subcategoryname', '', 'string'); $post['description'] = $this->input->get('phocagallerycreatesubcatdescription', '', 'string'); $post['parent_id'] = $this->input->get('parentcategoryid', 0, 'int'); $catid = $this->input->get('catid', '', 'string'); $tab = $this->input->get('tab', 0, 'int'); $Itemid = $this->input->get('Itemid', 0, 'int'); $limitStart = $this->input->get('limitstart', 0, 'int'); $catid = (int) $catid; $paramsC = JComponentHelper::getParams('com_phocagallery'); $maxCreateCatChar = $paramsC->get('max_create_cat_char', 1000); $enableUserSubCatApprove = $paramsC->get('enable_usersubcat_approve', 0); $enableDirectSubCat = $paramsC->get('enable_direct_subcat', 0); $post['description'] = substr($post['description'], 0, (int) $maxCreateCatChar); $post['alias'] = $post['title']; //PhocaGalleryText::getAliasName($post['title']); $post['aliasfolder'] = PhocaGalleryText::getAliasName($post['title']); $model = $this->getModel('user'); $userSubCatCount = $paramsC->get('user_subcat_count', 5); $user = JFactory::getUser(); $post['approved'] = 0; $id = $catid; if ($enableUserSubCatApprove == 0) { $post['approved'] = 1; } if ($limitStart > 0) { $limitStartUrl = '&limitstart=' . $limitStart; } else { $limitStartUrl = ''; } // Lang $userLang = PhocaGalleryUser::getUserLang(); $post['language'] = $userLang['lang']; $neededAccessLevels = PhocaGalleryAccess::getNeededAccessLevels(); $access = PhocaGalleryAccess::isAccess($user->getAuthorisedViewLevels(), $neededAccessLevels); $app = JFactory::getApplication(); // USER IS NOT LOGGED if (!$access) { $app->enqueueMessage($this->_loginstr); $app->redirect($this->_loginurl); exit; } if ($enableDirectSubCat != 1) { $msg = JText::_('COM_PHOCAGALLERY_NOT_AUTHORISED_ACTION'); $app->enqueueMessage($msg); $this->setRedirect(JRoute::_('index.php?option=com_phocagallery&view=category&id=' . $id . '&tab=' . $tab . '&Itemid=' . $Itemid . $limitStartUrl, false)); return; } if ((int) $post['parent_id'] < 1) { $msg = JText::_('COM_PHOCAGALLERY_PARENT_CATEGORY_NOT_SELECTED'); $app->enqueueMessage($msg); $this->setRedirect(JRoute::_('index.php?option=com_phocagallery&view=category&id=' . $id . '&tab=' . $tab . '&Itemid=' . $Itemid . $limitStartUrl, false)); return; } // $isOwnerCategory = $model->isOwnerCategory($this->_user->id, (int)$post['parent_id']); // $limitStartUrl = $this->getLimitStartUrl(0, 'subcat', (int)$isOwnerCategory ); // if(!$isOwnerCategory) { // $msg = JText::_( 'COM_PHOCAGALLERY_PARENT_CATEGORY_NOT_ASSIGNED_TO_USER' ); // $app->redirect(JRoute::_($this->_url. $limitStartUrl->subcat . $limitStartUrl->image, false), $msg); // exit; // } $subCatCount = $model->getCountUserSubCat($user->id); $subCatCount = (int) $subCatCount + 1; if ((int) $subCatCount > (int) $userSubCatCount) { $msg = JText::_('COM_PHOCAGALLERY_MAX_SUBCAT_COUNT_REACHED'); $app->enqueueMessage($msg); $this->setRedirect(JRoute::_('index.php?option=com_phocagallery&view=category&id=' . $id . '&tab=' . $tab . '&Itemid=' . $Itemid . $limitStartUrl, false)); return; } $ownerMainCategory = $model->getOwnerMainCategory($user->id); if (!$ownerMainCategory) { // - - - - - // NEW // - - - - - $msg = ''; // Create an user folder on the server $userFolder = PhocaGalleryText::getAliasName($user->username) . '-' . substr($post['aliasfolder'], 0, 10) . '-' . substr(md5(uniqid(time())), 0, 4); $errorMsg = ''; $createdFolder = PhocaGalleryFileFolder::createFolder($userFolder, $errorMsg); if ($errorMsg != '') { $msg = JText::_('COM_PHOCAGALLERY_ERROR_FOLDER_CREATING') . ': ' . JText::_($errorMsg); $app->enqueueMessage($msg); $this->setRedirect(JRoute::_('index.php?option=com_phocagallery&view=category&id=' . $id . '&tab=' . $tab . '&Itemid=' . $Itemid . $limitStartUrl, false)); return false; } } else { $userFolder = $ownerMainCategory->userfolder; } if ($post['title'] != '') { $post['access'] = 0; $post['image_position'] = 'left'; $post['published'] = 1; $post['accessuserid'] = '-1'; $post['uploaduserid'] = $user->id; $post['deleteuserid'] = $user->id; $post['userfolder'] = $userFolder; $post['owner_id'] = $user->id; $id = $model->store($post); if ($id && $id > 0) { $msg = JText::_('COM_PHOCAGALLERY_SUCCESS_CREATING_CATEGORY'); } else { $msg = JText::_('COM_PHOCAGALLERY_ERROR_CREATING_CATEGORY'); } } else { $msg = JText::_('COM_PHOCAGALLERY_ERROR_TITLE'); } $app->enqueueMessage($msg); $this->setRedirect(JRoute::_('index.php?option=com_phocagallery&view=category&id=' . $id . '&Itemid=' . $Itemid . $limitStartUrl, false)); }
function createcategory() { $app = JFactory::getApplication(); JRequest::checkToken() or jexit('Invalid Token'); $task = JRequest::getVar('task', '', 'post', 'string', 0); $post['title'] = JRequest::getVar('categoryname', '', 'post', 'string', 0); $post['description'] = JRequest::getVar('phocagallerycreatecatdescription', '', 'post', 'string', 0); $paramsC = JComponentHelper::getParams('com_phocagallery'); $maxCreateCatChar = $paramsC->get('max_create_cat_char', 1000); $enableUserCatApprove = (int) $paramsC->get('enable_usercat_approve', 0); $post['description'] = substr($post['description'], 0, (int) $maxCreateCatChar); $post['alias'] = $post['title']; //PhocaGalleryText::getAliasName($post['title']); $post['aliasfolder'] = PhocaGalleryText::getAliasName($post['title']); $post['approved'] = 0; if ($enableUserCatApprove == 0) { $post['approved'] = 1; } // Lang $userLang = PhocaGalleryUser::getUserLang(); $post['language'] = $userLang['lang']; /* switch ($this->tmpl['userucplang']){ case 2: $registry = new JRegistry; $registry->loadJSON($user->params); $lang = $registry->get('language','*'); $this->tmpl['userucplangvalue'] = '<input type="hidden" name="language" value="'.$lang.'" />'; break; case 3: $lang = JFactory::getLanguage()->getTag(); $this->tmpl['userucplangvalue'] = '<input type="hidden" name="language" value="*" />'; break; default: case 1: $this->tmpl['userucplangvalue'] = '<input type="hidden" name="language" value="*" />'; break; }*/ $limitStartUrl = new JObject(); $limitStartUrl->subcat = '&limitstartsubcat=' . $this->_limitstartsubcat; $limitStartUrl->image = '&limitstartsubcat=' . $this->_limitstartimage; $neededAccessLevels = PhocaGalleryAccess::getNeededAccessLevels(); $access = PhocaGalleryAccess::isAccess($this->_user->authorisedLevels(), $neededAccessLevels); // user is logged in if ($access) { if ($post['title'] != '') { $model = $this->getModel('user'); // Owner can have only one main category - check it $ownerMainCategory = $model->getOwnerMainCategory($this->_user->id); // User has no category, he (she) can create one if (!$ownerMainCategory) { // - - - - - // NEW // - - - - - $msg = ''; // Create an user folder on the server $this->_userFolder = PhocaGalleryText::getAliasName($this->_user->username) . '-' . substr($post['aliasfolder'], 0, 10) . '-' . substr(md5(uniqid(time())), 0, 4); $errorMsg = ''; $createdFolder = PhocaGalleryFileFolder::createFolder($this->_userFolder, $errorMsg); if ($errorMsg != '') { $msg = JText::_('COM_PHOCAGALLERY_ERROR_FOLDER_CREATING') . ': ' . JText::_($errorMsg); } // ----------------------------------- // Folder Created, all right if ($msg == '') { // Set default values $post['access'] = 0; //$post['access'] = 1; $post['parent_id'] = 0; $post['image_position'] = 'left'; $post['published'] = 1; $post['accessuserid'] = '-1'; $post['uploaduserid'] = $this->_user->id; $post['deleteuserid'] = $this->_user->id; $post['userfolder'] = $this->_userFolder; $post['owner_id'] = $this->_user->id; // Create new category $id = $model->store($post); if ($id && $id > 0) { $msg = JText::_('COM_PHOCAGALLERY_SUCCESS_SAVING_CATEGORY'); $errUploadMsg = ''; $succeeded = ''; PhocaGalleryControllerUser::saveUser('', $succeeded, $errUploadMsg); //$msg .= '<br />' . $errUploadMsg; } else { $msg = JText::_('COM_PHOCAGALLERY_ERROR_SAVING_CATEGORY'); } } } else { if ($post['title'] != '') { // - - - - - // EDIT // - - - - - $post['id'] = $ownerMainCategory->id; $id = $model->store($post); if ($id && $id > 0) { $msg = JText::_('COM_PHOCAGALLERY_SUCCESS_SAVING_CATEGORY'); } else { $msg = JText::_('COM_PHOCAGALLERY_ERROR_SAVING_CATEGORY'); } } } } else { $msg = JText::_('COM_PHOCAGALLERY_ERROR_TITLE'); } $this->setRedirect(JRoute::_($this->_url . $limitStartUrl->subcat . $limitStartUrl->image, false), $msg); } else { $app = JFactory::getApplication(); $app->redirect($this->_loginurl, $this->_loginstr); exit; } }