Welcome to the nuBuilder forums!

Please register and login to view forums and other content only available to registered users.

"Before Save" code works as globeadmin, not as user

Locked
anorman
Posts: 66
Joined: Wed Apr 04, 2012 11:34 pm

"Before Save" code works as globeadmin, not as user

Unread post by anorman »

Hello,

I have a before save routine I created on a specific page (It actually generates a custom ticket number using another database table, and a couple other minor validation/settings of POST variables before the form gets processed, such as setting a field to the currently logged in user, etc..

When I am on as globeadmin, everything works perfectly. If I am logged into the system as a user who has access to the form and can infact create a new record, the before save routine doesn't seem to work at all. The unique ticket id is never generated (The field is left blank when saved), and it won't put the username in the field for "entered by currently logged in user" (Appears as globeadmin when logged in as such, blank when anyone else).

Is there a security setting I am missing somewhere that I need to grant? The user already has access to the form .

Thanks,

Andre
admin
Site Admin
Posts: 2781
Joined: Mon Jun 15, 2009 2:23 am
nuBuilder Version: 4.5
Been thanked: 1 time

Re: "Before Save" code works as globeadmin, not as user

Unread post by admin »

Andre,

Have you tried removing all the code and using nuDebug(), to see if it gets there?

Steven
anorman
Posts: 66
Joined: Wed Apr 04, 2012 11:34 pm

Re: "Before Save" code works as globeadmin, not as user

Unread post by anorman »

I have not, but shall try and see what happens..
admin
Site Admin
Posts: 2781
Joined: Mon Jun 15, 2009 2:23 am
nuBuilder Version: 4.5
Been thanked: 1 time

Re: "Before Save" code works as globeadmin, not as user

Unread post by admin »

ok
anorman
Posts: 66
Joined: Wed Apr 04, 2012 11:34 pm

Re: "Before Save" code works as globeadmin, not as user

Unread post by anorman »

Hi Steven,

Sorry it took so long to run the test..

Anyway, I just did as you suggested..

I put an nudebug in as the first statement in the function that records the user that is logged in..

When I am logged in as globeadmin, a debug message is generated and indicates that it was "globeadmin" logged in.

When I am a standard user, no debug message is created.

In the "user access" section I have the form granted access to the group that the user is part of (and in fact, if I attempt to generate a work order it does so, it just doesn't create the work order number or record the user that created it. (Those fields are left blank, as both are calculated in the "before save" routine)..

Here is the "before save" code as it appears in the form.. I left the debug message in so you can see where is placed, etc..

Thanks for any help/suggestions you can give me..

- Andre

--------------------------- BEFORE SAVE CODE HERE ------------------------------------------------------------

date_default_timezone_set('America/New_York');

nuDebug("Made it! as " . #zzsys_user_id#);
// First let's check -- if this is a new ticket, we must pre-process some fields
// Generate a ticket number, etc..

if (#recordID# == '-1')
{
// GENERATE INVOICE NUMBER CODE STARTS HERE
// Now let's start building out INVoice number
$INVnum = 'WO' . date('ymd');

// we insert this into our invocesused table, then count how many times this appears..
// that gives us our -xx for the last part of the invoice

nuRunQuery("INSERT into worktickets (ticknum) VALUES ('" . $INVnum . "')");

$INVq = nuRunQuery("SELECT count(ticknum) as number from worktickets where ticknum = '" . $INVnum . "'");

$qqq = db_fetch_object($INVq);
$txtnum = $qqq->number;
$iterate = (int)$txtnum;
$INVnum = $INVnum . "-" . str_pad($iterate,2,"0",STR_PAD_LEFT);
$_POST['tik_number'] = $INVnum;
// INVOICE CREATED -- Stuffed into post data

// Next, we need to add userid and date to post data
$_POST['tik_enteredby'] = #zzsys_user_id#;

}
massiws
Posts: 503
Joined: Thu May 24, 2012 2:08 am
Location: Milan, Italy
Contact:

Re: "Before Save" code works as globeadmin, not as user

Unread post by massiws »

anorman,

have you tryed to quote the hash variables?

ex:

Code: Select all

nuDebug("Made it! as " . "#zzsys_user_id#");
...
if ("#recordID#" == '-1')
...
$_POST['tik_enteredby'] = "#zzsys_user_id#";
anorman
Posts: 66
Joined: Wed Apr 04, 2012 11:34 pm

Re: "Before Save" code works as globeadmin, not as user

Unread post by anorman »

I have not, but I will certainly give it a shot.. Is there a need to quote those when you are not a globeadmin? (It works as is when globeadmin is logged in.. No worky when anyone else is logged in, even though the users have access to the form)..

Thanks for the suggestion. I will try and get back to you..

- Andre
massiws
Posts: 503
Joined: Thu May 24, 2012 2:08 am
Location: Milan, Italy
Contact:

Re: "Before Save" code works as globeadmin, not as user

Unread post by massiws »

Andre,
anorman wrote:Is there a need to quote those when you are not a globeadmin?
No, but I think compare strings and numbers like this is not correct:

Code: Select all

if (12345 == '-1')
...
$_POST['tik_enteredby'] = 1502a6f691f31e;
;)
admin
Site Admin
Posts: 2781
Joined: Mon Jun 15, 2009 2:23 am
nuBuilder Version: 4.5
Been thanked: 1 time

Re: "Before Save" code works as globeadmin, not as user

Unread post by admin »

.
Locked