Frontend Permissions

silvered.dragon 21 Oct, 2013
Hi my friends,
I'm here for another question cause I really like chrono projects so I want to use this the best way that I can,so..question is:
I want that everyone one can view my autogenerated list but if a logged user push on the block button(binary_field with publish joomla icon)then only the logged user will have the permission to edit the selected record.Can you suggest me some documentation? Problem is that if I allow only owner to edit a record than the block button will always return acces denied even if the user_id field is 0 or not filled in my database table. only way to make this works is to manualy edit from phpmyadmin the user_id field to be the same as the logged user. I think I need somwthing like:

IF user_id = 0
THEN fields are editable from everyone
IF user_id = user_id
THEN logged user will have permissione to edit

Thank you
GreyHead 21 Oct, 2013
Hi silvered.dragon,

Sorry, I don't know how to do that; Max may have some suggestions though.

Bob
silvered.dragon 21 Oct, 2013
thank you greyhead.. I think that this can be done editing something in frontend advanced permission.. waiting for max's reply๐Ÿ˜ถ
Max_admin 23 Oct, 2013
Hi,

There is no way to switch the permissions, but maybe you can switch the value of the field, instead of displaying a binary field, just display a static image (no link), or don't display it at all!

If you have a custom list then its easy to do this, if you have an auto listing then just use the "auto listing event".

Regards,
Max
Max, ChronoForms developer
ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
silvered.dragon 23 Oct, 2013
sorry max can't understand this, how can I edit the value of a field like cf_user_id to current_user_id directly from the frontend listing? i thik that is possible to directly edit only binary fields not a generic field.
silvered.dragon 23 Oct, 2013
The best thing for me should be a button in toolbar menu and if I select a record and then press this button, a field called user_id will be filled with the id of current logged user, and from permission settings I allow to edit field only by owner..but toolbar functions are only _ADD_,_EDIT_,_DELETE_,_BINARY_๐Ÿ˜Ÿ
Max_admin 25 Oct, 2013
I have another easier idea, just create a new column and add a custom link called "claim" or whatever, and point the link to a custom event in your form, you will also need to register this custom event in your connection (there is a place for that under the "Front or Admin Editing"), now in your custom event in the form you will need to update the record with the user id as you want.

Regards,
Max
Max, ChronoForms developer
ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
silvered.dragon 25 Oct, 2013

I have another easier idea, just create a new column and add a custom link called "claim" or whatever, and point the link to a custom event in your form, you will also need to register this custom event in your connection (there is a place for that under the "Front or Admin Editing"), now in your custom event in the form you will need to update the record with the user id as you want.



Hi max and thank you for your reply.
I understood your idea but as you know I'm not so good with code so please be patient and help me to close this project.
in order:
db_name is disponibilita
table_name is form_disponibilita
field that I want to fill with "current user logged id" is user_id

1 - first think is to add a new column to my database, I will call this claim
? - what kind of data I have to choose for this column(VARCHAR,INT ecc)
2 - next step is to go through advanced wizard editor and add a new custom code event to the edit form connected with my cc list,the name of this form is "form_disponibilita_edit", and I will call the custom event claim that will fill the user_id field with "current user logged id"
? - please max can you suggest me some lines of code to place in this action? I will do the best that I can to edit your code and make it works with my database.
3 - now I have to go in cc-->frontend list settings-->linkable fields and place a link to my custom actions
? - I can't understand the syntax of this field, can you please tell me the right link?
4 - final step is to register my custom action in cc-->frotend editing
? - I can see a lot of fields here, first is custom data task and then I can see list event and list action order, witch is the correct one?
5 - in the end I have to setup right permissions in frontend editing
thank you max take your time and help me with this I will sure validate my installation when I will solve this!
silvered.dragon 28 Oct, 2013
So I put a custom code in an event called claim that works and fill a new field called current_user_id with the correct id, but I can't understand how to pass the correct record identifier cf_id to the code, in this example I have manualy put a specific record that have a field input_reference filled with 222222, this works but can't understand how to replace this with the selected cf_id. I have put a linkable field with this code "test:claim&cf_id={cf_id}" and the debugger show me the correct cf_id, how can I insert this in my code?

<?php
$user =& JFactory::getUser();
$con=mysqli_connect("localhost","root","debian","disponibilita");
// Check connection
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}

mysqli_query($con,"UPDATE form_disponibilita SET current_user_id= $user->id
WHERE input_reference = '222222'");

mysqli_close($con);
?>
silvered.dragon 28 Oct, 2013
ok this is the right code:

<?php
$cf_id = JRequest::getVar('cf_id');
$user =& JFactory::getUser();
$con=mysqli_connect("localhost","root","debian","disponibilita");
// Check connection
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}

mysqli_query($con,"UPDATE form_disponibilita SET current_user_id= $user->id
WHERE cf_id = $cf_id");

mysqli_close($con);
?>


I'll post lather for other problems
silvered.dragon 28 Oct, 2013
ok I think that this is the last step:
problem is that at the first acces current_user_id column is filled with 0 that dismatch from the current logged user id and if I allow update permission only to the owner then no one can lock the rows with him current_id cause I always receive acces denied. so to solve this I have to allow the editing permissions to user_id=current_user_id and to user_id = 0 but I have no idea how to do the second one..
silvered.dragon 29 Oct, 2013
OK I DID IT!
this is the right code that is making exactly what I had in my mind:
if I click on the linkable field then the entire row will be editable only from my account until the same account will click again on the unlock field.
<?php
//ob_start();
$cf_id = JRequest::getVar('cf_id');
$user =& JFactory::getUser();
$con=mysqli_connect("localhost","root","debian","disponibilita"); 
$result= mysqli_query($con,"SELECT current_user_id FROM form_disponibilita WHERE cf_id = $cf_id");
$current_user_id=$result->fetch_array();
// Check della connessione al database
 if (mysqli_connect_errno())
   {
   echo "Failed to connect to MySQL: " . mysqli_connect_error();
   }
 //Check dei permessi
if ($current_user_id['0'] == '0')     //lock
   {
echo '<img src="./images/dispo/bloccata.jpg" border=0>'; 
mysqli_query($con,"UPDATE form_disponibilita SET current_user_id= $user->id WHERE cf_id = $cf_id");
mysqli_query($con,"UPDATE form_disponibilita SET input_status=0 WHERE cf_id = $cf_id");
  }
elseif($current_user_id['0'] == $user->id)    //unlock
{
echo '<img src="./images/dispo/sbloccata.jpg" border=0>'; 
mysqli_query($con,"UPDATE form_disponibilita SET current_user_id= 0 WHERE cf_id = $cf_id");
mysqli_query($con,"UPDATE form_disponibilita SET input_status=1 WHERE cf_id = $cf_id");
}
else
 {
//echo "accesso negato";       //acces denied
echo '<img src="./images/dispo/access_denied.jpg" border=0>';  
}
mysqli_close($con);
?> 

I never open a book of php or mysql in my entire life but patience is more important the anything else๐Ÿ™‚ only one last question.. IS there a way to have a custom icon instead of a linkable field using autolisting? I would like to change the linkable field "lock/unlock" with an icon but maybe this is impossible using autolisting..right?
Max_admin 07 Nov, 2013
Hi silvered.dragon,

First, congratulations!๐Ÿ™‚

You can have an icon easily in custom listing, but in auto listing you will need to use the "auto listing event", also, new V5 has easier way to do this in auto listing.

Regards,
Max
Max, ChronoForms developer
ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
This topic is locked and no more replies can be posted.