Suggestions for an Attendance Tracking application?

23 posts by 4 authors in: Forums > CMS Builder
Last Post: May 29, 2013   (RSS)

By gregThomas - May 13, 2013

Hi Jerry,

I would make a full back up of both the site and the database just to be on the safe side! You can back up the database under the general settings section of the CMS admin area. 

This code should do as you require, it gets the salon_name from the attendance_test section based on the id of the attendee in the form at the bottom of the page. If you want to change it to search the email address as well you could change the mysql_get statement to this:

$loggedInUser = mysql_get('attendance_test', null, "email_address = '"$_REQUEST['email_address']."' OR attendee_number = '". $_REQUEST['attendee_number']."'");

So this statement will retrieve the first record from the attendance_test section, where either the email address or attendee number match. 

Thanks!

Greg

Greg Thomas







PHP Programmer - interactivetools.com

By gkornbluth - May 13, 2013

Oh, I see. In this case, the $loggedInUser in user is really the one who has submitted the form.

Jerry Kornbluth

The first CMS Builder reference book is now available on-line!







Take advantage of a free 3 month trial subscription, only for CMSB users, at: http://www.thecmsbcookbook.com/trial.php

By gkornbluth - May 13, 2013 - edited: May 14, 2013

Hi Greg,

I must be close because nothing blew up in my face, and your approach worked for pulling data from a text field (first_name) and inserting it into a variable, (which was the second part of my original question)

However, it doesn't work for salon_name, which is a multi value list field that normally gets it's values from the record number and labels from the title field of another editor called Names. (sorry I didn't mention that earlier)

I broke this down to separate viewers to try to hone in on the problem.

I hope it’s something simple.

Jerry Kornbluth

_______________________________________________________________

The first viewer, using the record number as a match, updates all appropriate fields including the salon_ name field, but replaces that with MMM, regardless of the previous value,  and in the record, also regardless of the previous value, I end up with a “Previous Selection (no longer in list) MMM” error in the list field.

I also get a Notice: Undefined variable: salon_name in /hsphere/local/home/a887307/elleschorrphotography.com/salon-sign-in-MMM-ID.php on line 29

// Check for attendee ID number. Update record if ID number is found.
      if (@$_REQUEST['attendee_number']  && !$errorsAndAlerts) {  
          $loggedInUser = mysql_get('attendance_test', $_REQUEST['attendee_number']);
           if(!$salon_name){
       // ***line 29***
$salon_name = 'MMM';
      }
      elseif($salon_name == 'MMM' ){
      $salon_name = 'MMM';
      }
    elseif($salon_name == 'AWC' ){
      $salon_name = 'AWC/MMM';
    } elseif($salon_name == 'AWC/MMM' ){
      $salon_name = 'AWC/MMM';
    }      
    
          $lecturedate =  date("m-y, ") ;
                 
        $query = "UPDATE `{$TABLE_PREFIX}attendance_test` SET
                     
          salon_name       = '$salon_name',
          mmm_attended     = CONCAT(mmm_attended, '$lecturedate'),
          updatedByUserNum = '".mysql_escape( $CMS_USER['num'] )."',
          updatedDate      = NOW()
          WHERE num        = '".mysql_escape( $_REQUEST['attendee_number'] )."'";
                     $loggedInUser = mysql_get('salon_listings', $_REQUEST['attendee_number']);
                        $first_name = @$loggedInUser['first_name']; ;
        mysql_query($query) or die("MySQL Error:<br/>\n". htmlspecialchars(mysql_error()) . "\n");
        $userNum = mysql_insert_id();

      // on success
      unset($_REQUEST['attendee_number'], $_REQUEST['first_name'], $_REQUEST['last_name'], $_REQUEST['email_address']); // clear form
   
      $errorsAndAlerts = "Thanks, $first_name. We've signed you in, and we're ready for the next guest.";
    }
    }
    
__________________________________


The second viewer, using the email address field for a match, updates all appropriate fields except the salon_ name field. No errors are shown.

// Check for first name, last name, and duplicate email address. Update record if email address is found.
      if (!@$_REQUEST['attendee_number'] && $count > 0 && !$errorsAndAlerts) {
        $loggedInUser = mysql_get('attendance_test', null, "email_address = '" . $_REQUEST['email_address']."'");
            $salon_name = $loggedInUser['salon_name'];
    if(!$salon_name){
      $salon_name = 'MMM';
    }elseif($salon_name == 'MMM' ){
      $salon_name = 'MMM';
    } elseif($salon_name == 'AWC' ){
      $salon_name = 'AWC/MMM';
    }
    elseif($salon_name == 'AWC/MMM' ){
      $salon_name = 'AWC/MMM';
    }      
            @$_REQUEST['first_name']=ucwords(@$_REQUEST['first_name']);        
            @$_REQUEST['last_name']=ucwords(@$_REQUEST['last_name']);    
     $lecturedate =  date("m-y, ") ;
                 
      $query = "UPDATE `{$TABLE_PREFIX}attendance_test` SET
        first_name          = '".mysql_escape( $_REQUEST['first_name'] )."',
        last_name           = '".mysql_escape( $_REQUEST['last_name'] )."',
        salon_name          = '$salon_name',
        mmm_attended        = CONCAT(mmm_attended, '$lecturedate'),
        updatedByUserNum    = '".mysql_escape( $CMS_USER['num'] )."',
        updatedDate         = NOW()
        WHERE email_address = '".mysql_escape( $_REQUEST['email_address'] )."'";
      mysql_query($query) or die("MySQL Error:<br/>\n". htmlspecialchars(mysql_error()) . "\n");
      $userNum = mysql_insert_id();

      // on success
      unset($_REQUEST['first_name'], $_REQUEST['last_name'], $_REQUEST['email_address']); // clear form
      $errorsAndAlerts = "Thanks, we've signed you in, and we're ready for the next guest.";
    }
    
    }

The first CMS Builder reference book is now available on-line!







Take advantage of a free 3 month trial subscription, only for CMSB users, at: http://www.thecmsbcookbook.com/trial.php

By gregThomas - May 14, 2013

Hi Jerry,

The issue with your first viewer is that your not setting the $salon_name variable first. You need to add this line:

     $loggedInUser = mysql_get('attendance_test', null, "email_address = '" . $_REQUEST['email_address']."'");
     $salon_name = $loggedInUser['salon_name'];
     if(!$salon_name){       
       // ***line 29***
       $salon_name = 'MMM';

I think the second issue is that you don't have MMM is your drop down list as an option, what values are you using for you list values?

The second viewer I'm not sure what the issue is. What happens if you do a showme on the $salon_name variable just before the database gets updated? Try this and see what gets returned:

// Check for first name, last name, and duplicate email address. Update record if email address is found.
if (!@$_REQUEST['attendee_number'] && $count > 0 && !$errorsAndAlerts) {
  $loggedInUser = mysql_get('attendance_test', null, "email_address = '" . $_REQUEST['email_address']."'");
  $salon_name = $loggedInUser['salon_name'];
    if(!$salon_name){
      $salon_name = 'MMM';
    }elseif($salon_name == 'MMM' ){
      $salon_name = 'MMM';
    }elseif($salon_name == 'AWC' ){
      $salon_name = 'AWC/MMM';
    }elseif($salon_name == 'AWC/MMM' ){
      $salon_name = 'AWC/MMM';
    }
    @$_REQUEST['first_name']=ucwords(@$_REQUEST['first_name']);
    @$_REQUEST['last_name']=ucwords(@$_REQUEST['last_name']);
    $lecturedate =  date("m-y, ") ;
    showme($salon_name); 
    exit;
    $query = "UPDATE `{$TABLE_PREFIX}attendance_test` SET
        first_name          = '".mysql_escape( $_REQUEST['first_name'] )."',
        last_name           = '".mysql_escape( $_REQUEST['last_name'] )."',
        salon_name          = '$salon_name',
        mmm_attended        = CONCAT(mmm_attended, '$lecturedate'),
        updatedByUserNum    = '".mysql_escape( $CMS_USER['num'] )."',
        updatedDate         = NOW()
        WHERE email_address = '".mysql_escape( $_REQUEST['email_address'] )."'";

    mysql_query($query) or die("MySQL Error:<br/>\n". htmlspecialchars(mysql_error()) . "\n");
    $userNum = mysql_insert_id();
    // on success
    unset($_REQUEST['first_name'], $_REQUEST['last_name'], $_REQUEST['email_address']);
    $errorsAndAlerts = "Thanks, we've signed you in, and we're ready for the next guest.";
  }
}

Let me know what the outcome is. 

Thanks!

Greg

Greg Thomas







PHP Programmer - interactivetools.com

By gkornbluth - May 14, 2013 - edited: May 14, 2013

Greg,

AH HA..

For the first issue, (a pretty dumb copy/paste mistake... Sorry) after inserting the $salon_name = $loggedInUser['salon_name'];, a  showme($salon_name); comes up with the record number of the Name table value that was inserted into the salon_name field. So if it's AWC then the showme returns 1 which is the record number in the Names table, and for MMM it returns 2 which is again, the record number in the Names table (no errors, but no updated salon_name field)

For the second issue, a  showme($salon_name); comes up with the record number of the Name table value that was inserted into the salon_name field as above. ( no updated salon_name field )

Suggestions?

And thanks for the help.

Jerry Kornbluth

The first CMS Builder reference book is now available on-line!







Take advantage of a free 3 month trial subscription, only for CMSB users, at: http://www.thecmsbcookbook.com/trial.php

By gregThomas - May 14, 2013

Hi Jerry,

It sounds like the issue is that the values you're adding to the database are not the same values that appear in the list. For the salon_name list field, can the user select a single value, or is it a multivalue list or checkbox field? So AWC has a num of 1, and MMM has a value of 2, do you have a value for both AWC/MMM  together? 

Thanks!

Greg

Greg Thomas







PHP Programmer - interactivetools.com

By gkornbluth - May 14, 2013 - edited: May 14, 2013

It's a multi value list and there's a value (5) for AWC/MMM

seems like I'm trying to match alpha values but numeric ones are being returned...

eventually, I'll need to address the idea that there might be more than 2 salons

maybe this list idea is not the best approach

Jerry

The first CMS Builder reference book is now available on-line!







Take advantage of a free 3 month trial subscription, only for CMSB users, at: http://www.thecmsbcookbook.com/trial.php

By gregThomas - May 15, 2013

Hi Jerry,

I think the list idea is probably a good approach, you just need to pass the num values into the table as opposed to titles. Something like this might work:

    $loggedInUser = mysql_get('attendance_test', $_REQUEST['attendee_number']);
    $salon_name = @$loggedInUser['salon_name'];
    if(!$salon_name){
      $salon_name = 2;
    }elseif($salon_name == '1' ){
      $salon_name = '5';
    }

So assuming the num value for AWC is 1, MMM is 2 and AWC/MMM is 5, I've converted the previous $salon_name system to use the num values instead. 

Thanks!

Greg

Greg Thomas







PHP Programmer - interactivetools.com

By gkornbluth - May 15, 2013

Hi Greg,

I'm concerned that this approach is becoming more dependent on custom coding and less dynamic in nature, which is going to be extremely cumbersome as the number of lecture series increases.

The goal is to add a value to the salon_names field in such a way that the format that's expected by the search fields in the report viewer is maintained.

Those search criteria values are currently drawn from the Names database to keep their format consistent.

How would you approach this to achieve the goal.

I remember doing something like <?php foreach($numToName as $num => $name): ?><option value="<?php echo $num;?>"><?php echo $name;?>  but don't have any idea if it would be helpful and if so, how to use it in this situation.

Thanks,

Jerry Kornbluth

The first CMS Builder reference book is now available on-line!







Take advantage of a free 3 month trial subscription, only for CMSB users, at: http://www.thecmsbcookbook.com/trial.php