I wanted a main menu item that would allow users to edit their own profile. To do this it required more than I thought originally.
I found if your Content Type (for a User NOT an Article) permissions are set as "edit own", Seblod does NOT work. You get a "You are not allowed to access this resource" error. Anyone else confirm this?
So you must set permissions as "edit". However, this means ANYONE can edit anyone's profile merely by editing the id of the URL, e.g. option=com_cck&view=form&layout=edit&type=applicants&id=64&Itemid=38. Not so desirable...
So, I wrote some code that allows you to put an "Edit My Profile" link in your menu. Some caveats:
- You must put the code at the top of your master template
- Your content type is saved from the standard User Content Type
- The code below assumes you want Registered users ONLY to edit their own profile
Also, p.s. I have read across the forums (v2 & v3) Joomla does NOT allow you to view User Details as pure content. Admins is this TRUE?
define( '_JEXEC', 1 );
define('JPATH_BASE', dirname(__FILE__) );
define( 'DS', DIRECTORY_SEPARATOR );
require_once ( JPATH_BASE .DS.'includes'.DS.'defines.php' );
require_once ( JPATH_BASE .DS.'includes'.DS.'framework.php' );
$mainframe =& JFactory::getApplication('site');
$mainframe->initialise();
$mainframe->route();
$user =& JFactory::getUser();
$usrid = $user->get('id');
$grparray = $user->get('groups');
$sum = count($grparray);
for ($i=0; $i<$sum; $i++) {
$grpid = $grparray[$i];
}
$getGroups = JAccess::getGroupsByUser($usrid);
$sum2 = count($getGroups);
for ($i=0; $i<$sum2; $i++) {
$newgrpid = $getGroups[$i];
}
// Append associative array elements
function array_push_associative(&$arr) {
$args = func_get_args();
foreach ($args as $arg) {
if (is_array($arg)) {
foreach ($arg as $key => $value) {
$arr[$key] = $value;
$ret++;
}
}else{
$arr[$arg] = "";
}
}
return $ret;
}
//$selfUrl = $_SERVER['PHP_SELF'];
$urlCCK = array();
foreach($_GET as $key => $value) {
array_push_associative($urlCCK, $items = array("$key" => "$value"));
}
// IF current user is in the Registered Group and their id is NOT equal to the URL's, then there's a problem.
if (
($newgrpid == 2) && // you may need to tweak this for ACL
($urlCCK['option'] == 'com_cck') &&
($urlCCK['view'] == 'form') &&
($urlCCK['layout'] == 'edit') &&
($urlCCK['type'] == 'applicants') && // makes this the name of your CCK User Profile form
($urlCCK['id'] != $usrid)
) {
header('Location: index.php'); // go to a page you set
exit;
}