[SOLVED]FEU and Uploads Module
[SOLVED]FEU and Uploads Module
I am hoping someone can help me.
I am attempting to create an Uploads category when a user registers via selfreg. When they register it will also write to the Uploads table and automatically create the entry. Once this has been created the user can then sign on via FEU and access only their category.
I am unable to create a trigger function on SQL, so i'm wondering if there is or could be some template and/or back end script that would allow selfreg to create two entries.
I hope that explains it well.
Please and thank you to all!
I am attempting to create an Uploads category when a user registers via selfreg. When they register it will also write to the Uploads table and automatically create the entry. Once this has been created the user can then sign on via FEU and access only their category.
I am unable to create a trigger function on SQL, so i'm wondering if there is or could be some template and/or back end script that would allow selfreg to create two entries.
I hope that explains it well.
Please and thank you to all!
Last edited by dromstad on Mon Aug 01, 2011 5:46 pm, edited 1 time in total.
Re: FEU and Uploads Module
I think you can use cmsms events and a UDT to accomplish this. There's little info on events in the forum and I guess you have to digg in the code of Selfreg also.
I don't know for sure, but as an alternative maybe the UserDirectory module can be of help too?
I don't know for sure, but as an alternative maybe the UserDirectory module can be of help too?
Re: FEU and Uploads Module
I did start on something similar, but abandoned it due to lack of time. It was to automatically create a gallery in the Gallery module for each new user and link that to an uploads category for each user.
I think jos showed in another post some API-like functions to create user galleries, but this was done before that, so I attacked the database directly. Anyway, that does not affect the part where the uploads category is created.
This was done on
CMSMS Version 1.9.2
Gallery 1.4.3
SelfRegistration 1.6.7
Uploads 1.11.5
FrontEndUsers 1.12.8
There's probably some deprecated syntax in there, but it worked at the time.
Maybe there is something here you can reuse.
UDT addUserGallery
Attached to event OnCreateUser in Frontend User Management module and event onUserRegistered in the Self Registration Module.
UDT uploadUserGallery
Attached to event OnUpload in the Uploads module
I think jos showed in another post some API-like functions to create user galleries, but this was done before that, so I attacked the database directly. Anyway, that does not affect the part where the uploads category is created.
This was done on
CMSMS Version 1.9.2
Gallery 1.4.3
SelfRegistration 1.6.7
Uploads 1.11.5
FrontEndUsers 1.12.8
There's probably some deprecated syntax in there, but it worked at the time.
Maybe there is something here you can reuse.
UDT addUserGallery
Attached to event OnCreateUser in Frontend User Management module and event onUserRegistered in the Self Registration Module.
Code: Select all
$gCms = cmsms();
if (!$gCms->modules['Gallery']['object']) {return;}
if (!$gCms->modules['Uploads']['object']) {return;}
$feu = $gCms->modules['FrontEndUsers']['object'];
if (!$feu) {return;}
$uname = $params['name'] ? $params['name'] : $params['username'];
$uid = $params['id'];
if (!$uname || !$uid) {return;}
$result=$feu->AddGroup( "User_" . $uname, "Group for user " . $uname);
if (!$result[0]) {return;}
$gid=$result[1];
if (!$feu->AssignUserToGroup( $uid, $gid)) {return;}
$db =& $gCms->GetDb();
$category_id= $db->GenID( cms_db_prefix () . "module_uploads_categories_seq");
$category_name = "UserGallery/" . $uname;
$category_desc = "User gallery for " . $uname;
$category_path = "images/Gallery/UserGallery/" . $uname;
$category_listable = 1;
$category_deletable = 0;
$category_expires_hrs = 0;
$category_scannable = 0;
$query = "INSERT INTO " . cms_db_prefix() . "module_uploads_categories
(upload_category_id, upload_category_name, upload_category_description,
upload_category_path, upload_category_listable, upload_category_deletable,
upload_category_expires_hrs, upload_category_scannable, upload_category_groups)
VALUES (?,?,?,?,?,?,?,?,?)";
$dbresult = $db->Execute( $query, array (
$category_id,
$category_name,
$category_desc,
$category_path,
$category_listable,
$category_deletable,
$category_expires_hrs,
$category_scannable,
$gid));
if (!$dbresult) {return;}
$conf =& $gCms->GetConfig();
if (!mkdir( $conf['uploads_path'] . "/" . $category_path, 0770)) {return;}
$query = "SELECT fileid FROM " . cms_db_prefix() . "module_gallery WHERE filename='UserGallery/' AND filepath='' LIMIT 1";
$parent_id = $db->getOne( $query );
if (!$parent_id) {return;}
$query = "INSERT INTO " . cms_db_prefix() . "module_gallery
(fileid, filename, filepath, filedate, fileorder,
active, defaultfile, galleryid, title, comment)
VALUES (0, ?, ?, NOW(), ?, ?, ?, ?, ?, ?)";
$dbresult = $db->Execute( $query, array (
$uname . "/",
"UserGallery",
0,1,0,
$parent_id,
$uname,
"User gallery for " . $uname));
Attached to event OnUpload in the Uploads module
Code: Select all
$gCms = cmsms();
if (!$gCms->modules['FrontEndUsers']['object']) {return;}
if (!$gCms->modules['Uploads']['object']) {return;}
if (!$gCms->modules['Gallery']['object']) {return;}
$db =& $gCms->GetDb();
$gallery= $params['category'];
$filename = $params['name'];
$title = $params['summary'];
$comment = $params['description'];
if ( !ereg( "^UserGallery/(.+)", $gallery, $capture) ) {return;}
$uname = $capture[1];
$query = "SELECT fileid FROM " . cms_db_prefix() . "module_gallery WHERE filepath='UserGallery' AND filename='" . $uname . "/' LIMIT 1";
$parent_id = $db->getOne( $query );
if (!$parent_id) {return;}
$query = "INSERT INTO " . cms_db_prefix() . "module_gallery
(fileid, filename, filepath, filedate, fileorder,
active, defaultfile, galleryid, title, comment)
VALUES (0, ?, ?, NOW(), ?, ?, ?, ?, ?, ?)";
$dbresult = $db->Execute( $query, array (
$filename,
$gallery,
0,1,0,
$parent_id,
$title,
$comment));
Re: FEU and Uploads Module
Thank you for the ideas!
Jos - I am not familiar with events, but will see if there is anything there
andershz, thank you! I will disect this code and see if I could possibly make it work.
This whole smarty thing is awesome! but confusing at the same time.
Jos - I am not familiar with events, but will see if there is anything there
andershz, thank you! I will disect this code and see if I could possibly make it work.
This whole smarty thing is awesome! but confusing at the same time.
Re: FEU and Uploads Module
While i decipher the code,
maybe this will be a workaround for now.
Manually create the Uploads category,
but my question is how do I call the category in the template
to look at the FEU username?
module= Uploads category=?? action=upload
sorry i'm very new to this CMS world
maybe this will be a workaround for now.
Manually create the Uploads category,
but my question is how do I call the category in the template
to look at the FEU username?
module= Uploads category=?? action=upload
sorry i'm very new to this CMS world
Re: FEU and Uploads Module
You mean something like this?
You need the CustomContent module for this to work.
Code: Select all
{if $ccuser->loggedin()}
{Uploads mode=upload category=$customcontent_loginname}
{else}
<h1>Login</h1>
{/if}
Re: FEU and Uploads Module
I didn't think about that method, that would prompt for a login rather than error...i think.
I went this method:
In the Template:
and created a UDT and put it in the smarty logic of the pages.
I was amazed it worked, but i like the custom content approach better.
I played around with the code all night regarding creating the Uploads Category, It's not working
I stripped out the gallery scripting as I can't get the module to install. but it should still create the category.
I used your code, but to no avail.
Any suggestions on your code or a different approach?
Thank you for all of the help.
I went this method:
In the Template:
Code: Select all
{cms_module module="Uploads" category="$username" mode="upload"}
Code: Select all
$gCms = cmsms();
$feusers =& $gCms->modules['FrontEndUsers']['object'];
$uid = $feusers->LoggedInID();
$username = $feusers->LoggedInName();
I played around with the code all night regarding creating the Uploads Category, It's not working

I used your code, but to no avail.
Any suggestions on your code or a different approach?
Thank you for all of the help.
Re: FEU and Uploads Module
It wouldn't prompt for a login, unless you put code to do that in the {else} clause.
As for creating the Uploads Category not working, the code is quite old, so things might have changed since I tried it the last time.
What versions of CMSMS, Uploads, FEusers, SelfReg are you using?
As for creating the Uploads Category not working, the code is quite old, so things might have changed since I tried it the last time.
What versions of CMSMS, Uploads, FEusers, SelfReg are you using?
Re: FEU and Uploads Module
Looking at the do_addcategory php it looks like the code should work like a charm...but i'm not a pro, I appreciate you looking into it.
CMS Version
1.9.4.2
Uploads
1.12
FrontEndUsers
1.12.16
SelfRegistration
1.6.10
CMS Version
1.9.4.2
Uploads
1.12
FrontEndUsers
1.12.16
SelfRegistration
1.6.10
Re: FEU and Uploads Module
What exactly is it that doesn't work?
I installed a brand new test site with
CMS Made Simple 1.9.4.2 "Faanui"
CGExtensions 1.26.3
SelfRegistration 1.6.10
FrontEndUsers 1.12.16
Uploads 1.12
CustomContent 1.7.3
I had some problem with SelfRegistration even before I installed any of my own code, it looks like I've hit bugs 6705 & 6499.
(If they are bugs, could be some misconfiguration as well).
http://dev.cmsmadesimple.org/bug/view/6705
http://dev.cmsmadesimple.org/bug/view/6499
Anyway, I got around that by deselecting
"Require the user to confirm registration via email"
in the SelfRegistration preferences.
Now it seems you must have at least one group defined in FrontEndUsers to be able to create users, and to create a group you need at least one property.
So if you don't have any existing groups and properties you can create some dummy values. I created a group called Users and set that as the default for new users.
Create an UDT with the following content:
The file permissions in the mkdir command could perhaps be set tighter than 0777, depending on your server setup.
Next, attach that UDT to event OnCreateUser in module Frontend User Management, and to event onUserRegistered in the Self Registration Module.
Then, create a login page something like this: (Turn of WYSIWYG & caching)
The group name should be of an existing group.
Create an upload page something like this: (Turn of WYSIWYG & caching)
That works for me, both for users created by the admin and for users creating themselves using SelfReg.
You must have all the modules listed at the top of this post installed.
Note that this is just a base. For example, error handling is missing, and there is no protection against user names that might contain characters invalid (or undesirable) in directory names.
I installed a brand new test site with
CMS Made Simple 1.9.4.2 "Faanui"
CGExtensions 1.26.3
SelfRegistration 1.6.10
FrontEndUsers 1.12.16
Uploads 1.12
CustomContent 1.7.3
I had some problem with SelfRegistration even before I installed any of my own code, it looks like I've hit bugs 6705 & 6499.
(If they are bugs, could be some misconfiguration as well).
http://dev.cmsmadesimple.org/bug/view/6705
http://dev.cmsmadesimple.org/bug/view/6499
Anyway, I got around that by deselecting
"Require the user to confirm registration via email"
in the SelfRegistration preferences.
Now it seems you must have at least one group defined in FrontEndUsers to be able to create users, and to create a group you need at least one property.
So if you don't have any existing groups and properties you can create some dummy values. I created a group called Users and set that as the default for new users.
Create an UDT with the following content:
Code: Select all
$gCms = cmsms();
$propname="x";
#The name of an existing FrontEndUser property to assign to the new group.
#Could be a dummy property.
#If no property is assigned to the group there will be an error when trying to edit the group.
if (!$gCms->modules['Uploads']['object']) {return;}
$feu = $gCms->modules['FrontEndUsers']['object'];
if (!$feu) {return;}
$uname = $params['name'] ? $params['name'] : $params['username'];
$uid = $params['id'];
if (!$uname || !$uid) {return;}
$result=$feu->AddGroup( "User_" . $uname, "Group for user " . $uname);
if (!$result[0]) {return;}
$gid=$result[1];
if (!$feu->AssignUserToGroup( $uid, $gid)) {return;}
if (!$feu->AddGroupPropertyRelation( $gid, $propname, 1, -1, 1)) {return;}
$db =& $gCms->GetDb();
$category_id= $db->GenID( cms_db_prefix () . "module_uploads_categories_seq");
$category_name = "User_" . $uname;
$category_desc = "User category for " . $uname;
$category_path = "User_" . $uname;
$category_listable = 1;
$category_deletable = 0;
$category_expires_hrs = 0;
$category_scannable = 0;
$query = "INSERT INTO " . cms_db_prefix() . "module_uploads_categories
(upload_category_id, upload_category_name, upload_category_description,
upload_category_path, upload_category_listable, upload_category_deletable,
upload_category_expires_hrs, upload_category_scannable, upload_category_groups)
VALUES (?,?,?,?,?,?,?,?,?)";
$dbresult = $db->Execute( $query, array (
$category_id,
$category_name,
$category_desc,
$category_path,
$category_listable,
$category_deletable,
$category_expires_hrs,
$category_scannable,
$gid));
if (!$dbresult) {return;}
$conf =& $gCms->GetConfig();
if (!mkdir( $conf['uploads_path'] . "/" . $category_path, 0777)) {return;}
Next, attach that UDT to event OnCreateUser in module Frontend User Management, and to event onUserRegistered in the Self Registration Module.
Then, create a login page something like this: (Turn of WYSIWYG & caching)
Code: Select all
{cms_module module=FrontEndUsers}
{if $ccuser->loggedin()}
{cms_module module=FrontEndUsers form=changesettings}
{else}
{cms_module module=SelfRegistration group=Users}
{/if}
Create an upload page something like this: (Turn of WYSIWYG & caching)
Code: Select all
{if $ccuser->loggedin()}
{Uploads mode=upload category=User_$customcontent_loginname}
{else}
You must log in
{/if}
You must have all the modules listed at the top of this post installed.
Note that this is just a base. For example, error handling is missing, and there is no protection against user names that might contain characters invalid (or undesirable) in directory names.
Re: FEU and Uploads Module
works perfectly!
The part that wasn't working was the Uploads category not being created. But this seems to have solved it.
Thank you for taking the time and energy it is MUCH appreciated!
Dave
The part that wasn't working was the Uploads category not being created. But this seems to have solved it.
Thank you for taking the time and energy it is MUCH appreciated!
Dave