Viewing Records Based on the User Account

12 posts by 2 authors in: Forums > CMS Builder
Last Post: March 1, 2011   (RSS)

Hi Everyone

I am having a bit of a problem getting my application to display only records created by a specific user. It displays all the records, not just the chosen user. Below is the code I used.

<?php // load viewer library
$libraryPath = 'nptAdmin/lib/viewer_functions.php';
$dirsToCheck = array('C:/wamp/www/','','../','../../','../../../');
foreach ($dirsToCheck as $dir) { if (@include_once("$dir$libraryPath")) { break; }}
if (!function_exists('getRecords')) { die("Couldn't load viewer library, check filepath in sourcecode."); } // load records
list($pdrRecords, $pdrMetaData) = getRecords(array(
'tableName' => 'pdr',
// 'where' => whereRecordNumberInUrl(1),
'loadUploads' => '0',
'limit' => '1',
));
$pdrRecord = @$pdrRecords[0]; // get first record




// load records
list($accountsRecords, $accountsMetaData) = getRecords(array(
'tableName' => 'accounts',
'loadUploads' => '0',
));



?>

...............

<center>
<table>
<th><a href="index.php?orderBy=<?php echo (@$_REQUEST['orderBy']!="organization")? "organization" : "organization DESC" ?>">Organization</a></th>
<th><a href="index.php?orderBy=<?php echo (@$_REQUEST['orderBy']!="position_title")? "position_title" : "position_title DESC" ?>">Position Title</a></th>
<th><a href="index.php?orderBy=<?php echo (@$_REQUEST['orderBy']!="position_number")? "position_number" : "position_number DESC" ?>">Position Number</a></th>



<?php foreach ($accountsRecords as $record): ?>
<tr>
<td>
<?php echo $record['organization'] ?>
</td>
<td>
<?php echo $record['position_title'] ?>
</td>
<td>
<a href="<?php echo $record['_link'] ?>"><?php echo $record['position_number'] ?></a>
[/#800000] </td>
</tr>



<?php endforeach ?>
</table>


The output of the code in red is "pdr/PDRdetails.php?27", which is partially correct. The user number is correct, but the output should look like this "pdr/PDRdetails.php?createdByUserNum=27".

Any ideas how I can fix this?

Ragi
--
northernpenguin
Northern Penguin Technologies

"Any sufficiently advanced technology
is indistinguishable from magic."
........Arthur C. Clarke

Re: [northernpenguin] Viewing Records Based on the User Account

By Jason - February 24, 2011

Hi Ragi,

How are you determining which user's records to display? Is it just based on the link the user clicks?

If you just need to change your link, I would suggest constructing the link manually like this:

<a href="pdr/PDRdetails.php?createdByUserNum=<?php echo $record['createdByUserNum'] ?>"><?php echo $record['position_number'] ?></a>

Hope this helps
---------------------------------------------------
Jason Sauchuk - Project Manager
interactivetools.com

Hire me! Save time by getting our experts to help with your project.
http://www.interactivetools.com/consulting/

Re: [northernpenguin] Viewing Records Based on the User Account

By Jason - February 24, 2011

Hi Ragi,

I'm assuming these records are being created by a form, not through CMS Builder. If so, check your script that creates these records and make sure you're not setting createdByUserNum to zero. Also check the record in CMS Builder and see if a created by name appears at the top.

Hope this helps.
---------------------------------------------------
Jason Sauchuk - Project Manager
interactivetools.com

Hire me! Save time by getting our experts to help with your project.
http://www.interactivetools.com/consulting/

Re: [Jason] Viewing Records Based on the User Account

Jason: The user logs into Builder to create the record. The createdByUserNum is correct. For example, If I enter the URI manually with PDRdetails.php?createdByUserNum=27 on the end, it works correctly. I have attached the two files I use to view the records. I use the Web Membersip Plugin to create the account, the user logs into Builder to create his records, but can view them from the website.

Ragi
--
northernpenguin
Northern Penguin Technologies

"Any sufficiently advanced technology
is indistinguishable from magic."
........Arthur C. Clarke
Attachments:

index_034.php 4K

pdrdetails.php 3K

Re: [northernpenguin] Viewing Records Based on the User Account

By Jason - February 25, 2011

Hi Ragi,

Using '_link' will put the record's num at the end of the url, not the user num of the person who created it. The problem taking place is going to be difficult for me to diagnose without being able to see the script in action.

You said when you were manually creating your links you were always getting a 0 for createdByUserNum? One thing you can do is when your outputing your records, try this:

<?php die( showme( $record ) ); ?>

This will show you all the contents of $record and then stop the script. Look to see that createdByUserNum has the proper value.

Give that a try and let me know what it outputs for you.
thanks
---------------------------------------------------
Jason Sauchuk - Project Manager
interactivetools.com

Hire me! Save time by getting our experts to help with your project.
http://www.interactivetools.com/consulting/

Re: [Jason] Viewing Records Based on the User Account

By northernpenguin - February 28, 2011 - edited: February 28, 2011

Jason: Here is the output as requested. I placed it in the PDRdetails.php file after the listing of the results.

Array( [num] => 3 [createdDate] => 2011-02-10 13:44:23 [createdByUserNum] => 19 [updatedDate] => 2011-02-10 13:44:23 [updatedByUserNum] => 19 [dragSortOrder] => 30 [critical_task] =>

Develop posting plot [expected_result] =>

Trainees will be posted with minimal delays to overall training time. [reference] =>

MARCORD 9-20 [_filename] => lt-p-gt-Develop-posting-plot-lt-p-gt [_link] => PDRdetails.php?lt-p-gt-Develop-posting-plot-lt-p-gt-3 [createdBy.num] => 19 [createdBy.createdDate] => 2011-02-08 09:34:52 [createdBy.createdByUserNum] => 1 [createdBy.updatedDate] => 2011-02-25 09:52:45 [createdBy.updatedByUserNum] => 1 [createdBy.fullname] => Peter Veltheim [createdBy.email] => peter.veltheim@forces.gc.ca [createdBy.username] => DMTE 2-7 [createdBy.expiresDate] => 2011-02-08 00:00:00 [createdBy.neverExpires] => 1 [createdBy.isAdmin] => 0 [createdBy.disabled] => 0 [createdBy.accessGroup] => [createdBy.position_description] => [createdBy.accessList] => [createdBy.organization] => CMS [createdBy.position_title] => DMTE 2-7 [createdBy.position_number] => 7654565 [createdBy._filename] => [createdBy._link] => PDRdetails.php?19)

I also uploaded the output in a txt file as its easier to read!
--
northernpenguin
Northern Penguin Technologies

"Any sufficiently advanced technology
is indistinguishable from magic."
........Arthur C. Clarke
Attachments:

results.txt 2K

Re: [northernpenguin] Viewing Records Based on the User Account

By Jason - February 28, 2011

Hi,

Okay, your output look like what we would expect. So this code:

<a href="pdr/PDRdetails.php?createdByUserNum=<?php echo $record['createdByUserNum'] ?>"><?php echo $record['position_number'] ?></a>

Should work. When you run this code, do you still get createdByUserNum = 0?

Give this code a try and let me know what your results are.

Thanks.
---------------------------------------------------
Jason Sauchuk - Project Manager
interactivetools.com

Hire me! Save time by getting our experts to help with your project.
http://www.interactivetools.com/consulting/

Re: [Jason] Viewing Records Based on the User Account

Jason: I don't know if this is related, but I noticed an error in the index.php file. I placed the foll statement in the foreach loop in index.php (attached):

<?php die( showme( $accountsRecords ) ); ?>


I noticed that the array that is printed has 18 entries, equivalent to all the user accounts. However, only 4 of those accounts are related to the pdr table. Therefore, I believe that I need to add a where statement at the top of the file:

// load records
list($accountsRecords, $accountsMetaData) = getRecords(array(
'tableName' => 'accounts',
'where' => '????',
'loadUploads' => '0',
));

--
northernpenguin
Northern Penguin Technologies

"Any sufficiently advanced technology
is indistinguishable from magic."
........Arthur C. Clarke
Attachments:

index_035.php 4K

Re: [northernpenguin] Viewing Records Based on the User Account

By Jason - February 28, 2011

Hi,

Yes, you would have to write a "where" clause to only return certain user records. What are you using to decide which should be in a the list and which shouldn't?
---------------------------------------------------
Jason Sauchuk - Project Manager
interactivetools.com

Hire me! Save time by getting our experts to help with your project.
http://www.interactivetools.com/consulting/