• 1

Read this first!

We do not monitor these forums. The forum is provided to exchange information and experience with other users ONLY. Forum responses are not guaranteed.

However, please submit a ticket if you have an active subscription and wish to receive support. Our ticketing system is the only way of getting in touch with RSJoomla! and receiving the official RSJoomla! Customer Support.

For more information, the Support Policy is located here.

Thank you!

TOPIC: Check CB field before access to form

Check CB field before access to form 10 years 6 months ago #25019

Hi,

I am trying to restrict access to the form to all users except those that have a "1" in a community builder field.

This is the code that I have but it does not work, any help appreciated.

$voter = JFactory::getUser();
$voterid = intval($voter->get('id'));
$flag = mysql_query("SELECT `cb_votingdiplomate` FROM `jos25_comprofiler` WHERE `user_id` ='".$voterid."');
if ($flag !=1)
$formLayout = 'Sorry either you are not logged in or you do not have voting rights.';
The administrator has disabled public write access.

Check CB field before access to form 10 years 6 months ago #25035

Hello Khennessy,

Please try this instead:
$voter = JFactory::getUser();
$voterid = intval($voter->get('id'));
 
$db->setQuery("SELECT `cb_votingdiplomate` AS canvote FROM `#__comprofiler` WHERE `user_id` ='".$voterid."'");
$result = $db->loadObjectList();
 
if ($result[0]->canvote != 1)
$formLayout = 'Sorry either you are not logged in or you do not have voting rights.'; 
Please remember that my responses aren't considered customer support, to receive customer support please submit a new customer support ticket, and we will gladly assist you.

Best Regards,
Cristian Nicolae.
The administrator has disabled public write access.

Check CB field before access to form 3 years 7 months ago #40576

OK, for many years this worked,

if (time() < strtotime("08/06/2019 09:00AM"))
{
 
echo "<font color=#ff0000><b>Voting opens on 13/08/2019 @ 9:00AM GMT<br/></b></font>";
 $formLayout = '';
}
 
 
 
 
if (time() > strtotime("09/08/2019 11:59PM"))
{
 
echo "<font color=#ff0000><b>Voting was open until 08/09/2019 @ 11:59PM GMT - Voting has closed<br/></b></font>";
 $formLayout = '';
}
 
 
global $database;
$rsuser = JFactory::getUser();
$id = $rsuser->get('id'); 
$query =("SELECT `cb_votingdiplomate` FROM `jos25_comprofiler` WHERE `id` = $id");
$db = & JFactory::getDBO(); 
$db->setQuery( $query ); 
$flag = $db->loadResult(); 
 
if ($flag != 1)
{
echo "<font color=#ff0000><b>You do not have Voting Rights!<br/></b></font>";
     $formLayout = '';
} 
 
global $database;
$rsuser = JFactory::getUser();
$id = $rsuser->get('id'); 
$database = JFactory::getDBO();
$database->setQuery("SELECT COUNT(`SubmissionId`) FROM jos25_rsform_submissions WHERE UserId=$id AND FormId='9'");
$database->query();
if (intval($database->loadResult()) >= 1)
{
     echo  "<font color=#ff0000><b>You have already submitted your votes!</b></font>";
     $formLayout = '';
} 
 
$user = JFactory::getUser();
if($user->id == 0)
$formLayout = '<p><font color="red"><strong>You must login before you can vote!</strong></font></p>';

Now it doesnt.

I have got this far (below) however the check on voting rights fails, where am I going wrong?
//Opening date US format
 
if (time() < strtotime("09/11/2020 09:00AM"))
{
 
echo "<font color=#ff0000><b>Voting opens on 11/09/2020 @ 9:00AM GMT<br/></b></font>";
 $formLayout = '';
}
//End opening date
 
 
//closing date US format
 
if (time() > strtotime("09/20/2020 11:59PM"))
{
 
echo "<font color=#ff0000><b>Voting was open until 20/09/2020 @ 11:59PM GMT - Voting has now closed<br/></b></font>";
 $formLayout = '';
}
//Close opening Date
 
//Check login status
 
$user = JFactory::getUser();
if($user->id == 0)
$formLayout = '<p><font color="red"><strong>You must login before you can vote!</strong></font></p>';
 
//End login check
 
 
//Limit submissions
 
// Define the maximum number of submissions.
$max = 1;
 
// Get the current logged in user.
$user = JFactory::getUser();
 
// Get a database connection.
$db   = JFactory::getDbo();
$query   = $db->getQuery(true);
 
// Setup the query.
$query->select('COUNT('.$db->qn('Username').')')
    ->from($db->qn('#__rsform_submissions'))
    ->where($db->qn('FormId').'='.$db->q($formId))
    ->where($db->qn('Username').'='.$db->q($user->get('username')));
    // You can also count by User ID, just replace the above with:
    // ->where($db->qn('UserId').'='.$db->q($user->get('id')));
 
$db->setQuery($query);
$counter = $db->loadResult();
 
if ($counter >= $max){
  $formLayout = '<font color=#ff0000><b>Sorry, you have already cast your vote.<br/></b></font>';
}
 
//End Submissions check
 
 
 
 
 
// Define Voting Flag rights
$voteflag = 1;
 
// Get the current logged in user.
$user = JFactory::getUser();
 
// Get a database connection.
$db   = JFactory::getDbo();
$query   = $db->getQuery(true);
 
// Setup the query.
    $query->select($db->qn('cb_votingdiplomate'))
    ->from($db->qn('#__comprofiler'))
    ->where($db->qn('id').'='.$db->q($user->get('id')));
 
$db->setQuery($query);
$flag = $db->loadResult();
 
if ($flag != $voteflag){
  $formLayout = '<font color=#ff0000><b>Sorry, you do not have voting rights.<br/></b></font>';
}
 
//End  check
Last Edit: 3 years 7 months ago by khennessy.
The administrator has disabled public write access.

Check CB field before access to form 3 years 7 months ago #40583

Ok, figured it out, Rookie error! was logged in as a different user than I was changing the voting rights flag on! :silly:

Will leave code there in case anybody else needs it!
The administrator has disabled public write access.
  • 1

Read this first!

We do not monitor these forums. The forum is provided to exchange information and experience with other users ONLY. Forum responses are not guaranteed.

However, please submit a ticket if you have an active subscription and wish to receive support. Our ticketing system is the only way of getting in touch with RSJoomla! and receiving the official RSJoomla! Customer Support.

For more information, the Support Policy is located here.

Thank you!