Forums

About to give up... Can anyone help?

markswift 23 Sep, 2009
Hi all,

Firstly let me say my attitude is not down to the Chrono product line, but that fact I am failing to create the website I promised a client.

Basically I am creating a website which will allow certain companies access to certain categories of the site (Each category has its own menu item linking to the category table view). I intend to use JUGA for the ACL, creating a group for each company, and applying the company groups to each category (I also have a problem with this right now as it appears you have to set the permissions for each article to ensure it works, if anyone knows anything about this, I would be grateful).

Now onto my hopeful use of the Form and Connectivity.

A feature of JUGA is to allow the creation of access codes, which can then be inputted by the user, when a code is successfully inputted it automatically moves the user to the group assigned to the user code (Got me so far?) Example: In JUGA create group 'company 1', then create access code '123456' linked to 'company 1' with a maximum hit count of 10. The user can now enter this access code in the frontend and automatically be moved to the JUGA group 'company 1'. They can do this 10 times.

Seems simple enough up to now..

What I would like the use the Chrono products for is to restrict registrations based on availability and existence of JUGA access codes. i.e. the user can only sign up if a valid access code exists with remaining hits. This enables me to retain an open registration form, but will only allow client with valid codes to sign up new users.

I do not actually think this will be so hard for an experienced programmer, but unfortunately while handy with Joomla and Fireworks etc, my PHP is pretty bad.

I have attached a screenshot taken from MYPHPADMIN, showing the table containing the access code details.

As you can see what I need to be able to do is create a new registration form, and add a text field where the user can input the access code. What I then need is for the field to be verified against the jos_juga_codes table, example

Does the code exist? (title) Is the code activated (published)? Does (hits) = less than (times_allowed)?

If so, let the user successfully register, if not show an error message.

I think this is just a basic database query and is possible to do using Forms and Connectivity?

If they can be solved my client will most certainly subscribe to both products.

I hope someone can help, apologise for the long winded post.

Mark
GreyHead 23 Sep, 2009
Hi markswift,

The attachment didn't make it but I don't think that is important.

Caution: I don't know JUGA so this reply doesn't take into account any of JUGA's features or limitations!!

Yes, you can certainly set up a registration form in ChronoForms (use the Joomle Registration Plugin) and include a databse query to check if e.g. count(some_column) < 10 and have the registration conditional on that.

That said - whilst not terribly difficult it's not a completely trivial piece of code either. Happy to help if we can.

Bob
markswift 23 Sep, 2009
Hi Greyhead,

Your reply is such a relief, my experience of support in the past, especially gratis support is not the best.

I am sure I can create the registration form using Chronoforms, if I do this can you help me with the query and how to input it? I believe the query I require should be pretty easy just case of checking if the value exists (the code) and checking if there are any hits left.

I tried to re-attach the file showing the tables, but it showed an error saying the board had passed its attachment quota...

Mark
GreyHead 23 Sep, 2009
Hi Mark,

Sorry about the attachment, I had no idea that we'd hit the limit. I've increased it.

Create a simple registration form with the minimum number of fields that you need. Configure and enable the ChronoForms Joomla Registration Plugin to work with it.

In the Joomla Registration Plugin Before Code box put something like
<?php
$user_code = JRequest::getVar('user_code', '', 'post');
$db =& JFactory::getDBO();
$query = "
  SELECT COUNT(*) 
    FROM `#__some_table`
    WHERE `some_column` = '$user_code' ;
";
$db->setQuery($query);
$count = $db->loadResult();
if ( $count >= 10 ) {
  echo "tough luck";
  return;
}
?>

That's very rough and you will need to fill in the correct values in various places. And I don't think that 'return' will work to stop the registration but we can check the correct code when you get near that point.

Bob
markswift 23 Sep, 2009
Greyhead,

You Sir are a star, I am making the form as we speak and will report back soon.

Thank you again!

Mark
markswift 23 Sep, 2009
Greyhead,

*deleted as I am stupid*

Ok, I have made the registration form, I have also created a text field in the form where the user can input their access code,the field has the id "text_22" in the form.

The table which holds the code in the db is called "jos_juga_codes", the access code column (which they will input in the above text field) is called "title", the number of hits allowed column is called "times_allowed" and total hits so far column is called "hits".

So basically I need the user to input the code in "text_22", then the form should check if that code is valid in table "jos_juga_codes" by looking in the "title" column, if it is, it should check to ensure "hits" is less than "times_allowed", if this all checks out then the registration goes ahead. If the code does not exist it should display an error and prevent registration.

🙄

P.S. I still cannot upload attachments error = "Sorry, the board attachment quota has been reached."
markswift 24 Sep, 2009
Bob,

I have been trying to figure out the code, but I am useless😟

Any ideas based on the above post?

Thanks again for all your help.

Mark
markswift 24 Sep, 2009

Bob,

I have been trying to figure out the code, but I am useless😟

Any ideas based on the above post?

Thanks again for all your help.

Mark



Bob / Anyone?

I just cannot figure out what code I need to enter in the before box to make this query...

😢

Mark
Mizpah 25 Sep, 2009
HI Mark,

I am actually in the process of developing a site, using JUGA and Chrono, and may be doing somthing quite similar - albiet I am Using AEC subscription manager for subscriptions, JUGA for permissions, and I have a form (not a reg form) that loads (or doesnt load) based on:

'get the userid -> Is the sub active - > how many uploads are there -> how many are uploaded -> 'do stuff' '

I include part of the code below in case it helps, it probably does a few more things but shows the principle! Note its not touching the registration, but its looking at data to decide if to do somthing or not - in this case, load a form.

<?php
//Get the currently logged in Joomla User, set to $userid
$user =& JFactory::getUser();
$userid = $user->get('id');

// Get number of uploads by logged in user, set to $uploaded
$query = "SELECT COUNT('cf_id') FROM `jos_chronoforms_cars` WHERE `status` = 'forsale' AND `cf_user_id` = "." ".$userid." " ; 
$result = mysql_query($query); 
$row = mysql_fetch_array($result);
$uploaded = $row[0];

// Get the status of the logged in users subscription, set to $status
// Get the number of allowed uploads based on the subscription above, set to $upallow 
$query = "
  SELECT a.`status`, c.`uploads`
    FROM `jos_acctexp_subscr` AS a
      JOIN `jos_carsaving_uploads` AS c ON a.`plan` = c.`plan`
    WHERE a.`userid` = ".$userid." ;
";
$result = mysql_query($query);
$rows = mysql_num_rows($result);
$row = mysql_fetch_array($result);
$status = $row[0] ;
$upallow = $row[1] ;
?> 
<!-- The below is a debug block to show the values obtained -->
<div>
<span class="alert">
<p>
Here are the current $vars and the values:<br />
The logged in user: <?php echo $userid ; ?><br />
The number of live uploads: <?php echo $uploaded ; ?><br />
The status of the subscription: <?php echo $status ; ?><br />
The number of uploads allowed by the subscription: <?php echo $upallow ; ?> 
</p>
</span>
</div>
<!-- This if/else block checks the $vars to determine if the form can be used.  The form is contained within the final else statement. -->
<?php 
if ( $userid == '0') {
?>
<div>
<!-- This is the condition for userid 0 (admin or test link)) -->
<span class="note"><p>Hmm, have you clicked the test link again ? Logged in user is userid 0 !!</p></span>
</div>
<?php
} elseif ( $status != 'Active') {
?>
<div>
<!-- This condition states that the sub is not active  To Do: Need to add  case statement here for each possibility! -->
<p> I am sorry there is a problem with your subscription! </p>
</div>
<?php
} elseif ( $uploaded >= $upallow) {
?>
<div>
<!-- This condition states that uploads are exceeded for the subscription -->
<p> It looks like you have exceeded your upload allowance for this subscription! </p>
</div>
<?php
} else {
?>
<!-- No other conditions apply, all is well with the world (For Once!) so load the form! -->
<div> 
(form woudl go here)
</div>
<?php
}
?>


have you tried to crate a page that just gets the data you need adds it to variables, and then outputs them as echos ? That woudl let you know if you issue is getting the correct data, or if its doing somthign with the data :twisted:

I will be around tommorow afternoon so will check the thread to see if I can help!
markswift 25 Sep, 2009
Hi Mizpah,

Thank you for taking the time to post the quote, I wish I could say it helped me, but the sad fact is, I am useless when it comes to PHP. I have always been able to create what I envision, but normally with some help and sleepless nights... 😲

The query I need to create is above (also quoted here for easy reference), I am sure to someone who knows PHP this could be written quite easily, but for a novice like me, well, it's just not going to happen. 🙄

The table which holds the code in the db is called "jos_juga_codes", the access code column (which they will input in the above text field) is called "title", the number of hits allowed column is called "times_allowed" and total hits so far column is called "hits".



So basically I need the user to input the code in "text_22", then the form should check if that code is valid in table "jos_juga_codes" by looking in the "title" column, if it is, it should check to ensure "hits" is less than "times_allowed", if this all checks out then the registration goes ahead. If the code does not exist it should display an error and prevent registration.



If you or Bob can help me work this out, I would be over the moon.

Thanks guys
GreyHead 25 Sep, 2009
Hi markswift,

Sorry for the delay - I plead guilty to picking off the 'quick' replies first :-(

The main piece that you need is the database query
<?php
$code = JRequest::getString('text_22', '', 'post');
if ( !$code ) {
  return;
}
$db =& JFactory::getDBO();
$query = "
  SELECT IF( `hits` < `times_allowed`, '1', '0') AS `ok`
    FROM `#__juga_codes`
    WHERE `title` = '$code' ;
";
$db->setQuery($query);
$ok = $db->loadResult();
if ( $ok )  {
  // there are hits left
} else {
  // there are no hits left
}
?>

Bob
markswift 25 Sep, 2009

Hi markswift,

Sorry for the delay - I plead guilty to picking off the 'quick' replies first :-(

The main piece that you need is the database query

<?php
$code = JRequest::getString('text_22', '', 'post');
if ( !$code ) {
  return;
}
$db =& JFactory::getDBO();
$query = "
  SELECT IF( `hits` < `times_allowed`, '1', '0') AS `ok`
    FROM `#__juga_codes`
    WHERE `title` = '$code' ;
";
$db->setQuery($query);
$ok = $db->loadResult();
if ( $ok )  {
  // there are hits left
} else {
  // there are no hits left
}
?>

Bob



Hi Bob,

Not a problem, I know I am a pain!

I tried putting it in the before reg plugin code. It does not seem to matter what I put in text_22 however, reg still goes ahead without errors, hmmmm

Also, will this prevent registration if the code does not exist at all (And can I make it display a warning to that extent), or prevent registration if the code exists but the hits are not less than the times allowed?


Mark
GreyHead 26 Sep, 2009
Hi mark,

Just back in from the garden, the sun has been shining here today.

The code isn't complete in itself. You'll need something else to take action. What have you got at the moment?

Bob
markswift 26 Sep, 2009
Hi Bob,

Firstly, sorry to drag you in... I have also been out in the garden, the weather is superb! So, what do I have so far... Nothing. A headache🙂

I only have the code you gave me above, but it did not seem to have any effect in the before section of the reg plugin.

What I need is a post a few above... (Have inserted again below, plus I tried to make it more clear to help. If this is too much, let me know and I'll go sulk in a quiet corner somewhere 😢

So basically I need the user to input the access code in "text_22" in the form, the form should then check if that code is valid in table "jos_juga_codes" by looking in the "title" column, if it is, then it should check to ensure "hits" is less than "times_allowed", if this all checks out then the registration goes ahead. If the code does not exist, or the 'hits' is not less than the 'times_allowed' it should display an error and prevent registration. Would be good to have an error for each, i.e. your code does not exist, or you have no hits left, blah blah



Thanks Bob (Again🙂 )
GreyHead 28 Sep, 2009
Hi Mark,

Just for the record here we adapted the form to use an AJAX validation for the access code, backed up by a server-side validation check.

Bob
markswift 28 Sep, 2009
Hi Bob,

I will take a look tonight, travelling today via train, plane and boat so unless my 3G stick actually works for more than 10 mins, it will be later tonight...

Thanks for the amazing support.

Mark
Mizpah 03 Oct, 2009
heya Mark - have sent yo a pm (more on the juga side), I can probably help out on the query side, however I am sure that Bob has either already sorted it, or can do a better job then me 🤣 !
This topic is locked and no more replies can be posted.