function createCategory() { global $mainframe; JRequest::checkToken() or jexit('Invalid Token'); $user =& JFactory::getUser(); $view = JRequest::getVar('view', '', 'post', '', 0); $post['title'] = JRequest::getVar('categoryname', '', 'post', 'string', 0); $post['description'] = JRequest::getVar('phocagallerycreatecatdescription', '', 'post', 'string', 0); $Itemid = JRequest::getVar('Itemid', 0, '', 'int'); $tab = JRequest::getVar('tab', 0, '', 'int'); // Params $paramsC = JComponentHelper::getParams('com_phocagallery'); // UCP is disabled (security reasons) $enable_user_cp = $paramsC->get('enable_user_cp', 0); if ($enable_user_cp == 0) { $mainframe->redirect(JURI::base(true), JText::_("User Control Panel is disabled")); exit; } $maxCreateCatChar = $paramsC->get('max_create_cat_char', 1000); $post['description'] = substr($post['description'], 0, (int) $maxCreateCatChar); $post['alias'] = PhocaGalleryHelper::getAliasName($post['title']); // user is logged in if ($user->aid > 0 && $user->id > 0) { if ($post['title'] != '') { $model = $this->getModel('user'); $userCatId = $model->getUserCategory($user->id); // User has no category, he (she) can create one if (empty($userCatId->id)) { // NEW $msg = ''; // Create an user folder on the server $userFolder = PhocaGalleryHelper::getAliasName($user->username) . '-' . substr($post['alias'], 0, 10) . '-' . substr(md5(uniqid(time())), 0, 4); $createdFolderError = ''; $createdFolder = PhocaGalleryHelper::createFolder($userFolder); $createdFolderError = preg_match("/.\\[PhocaError\\]/i", $createdFolder); if ($createdFolderError) { $msg = JText::_('Error Folder Creating') . ': ' . str_replace('[PhocaError]', '', $createdFolder); } // ----------------------------------- // 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['params'] = 'accessuserid=-1;' . 'uploaduserid=' . $user->id . ';' . 'deleteuserid=' . $user->id . ';' . 'userfolder=' . $userFolder . ';'; // Create new category $id = $model->store($post); if ($id && $id > 0) { $data['userid'] = $user->id; $data['catid'] = $id; $userCategoryId = $model->storeUserCategory($data); if ($userCategoryId && $userCategoryId > 0) { $msg = JText::_('Phoca Gallery User Control Category Saved'); } else { $msg = JText::_('Error Saving Phoca Gallery User Control Category'); } } else { $msg = JText::_('Error Saving Phoca Gallery User Control Category'); } } } else { if ($post['title'] != '') { // EDIT $post['id'] = $userCatId->categoryid; $id = $model->store($post); if ($id && $id > 0) { $msg = JText::_('Phoca Gallery User Control Category Edited'); } else { $msg = JText::_('Error Editing Phoca Gallery User Control Category'); } } } } else { $msg = JText::_('ERROR CREATE CATEGORY PHOCA GALLERY - TITLE'); } $this->setRedirect(JRoute::_('index.php?option=com_phocagallery&view=user&tab=' . $tab . '&Itemid=' . $Itemid, false), $msg); } else { $this->setRedirect(JRoute::_('index.php?option=com_user&view=login', false), JText::_("NOT AUTHORISED TO DO ACTION")); exit; } }