Page 1 of 1

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

Posted: Tue Dec 04, 2012 9:15 pm
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

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

Posted: Wed Dec 05, 2012 6:29 am
by admin
Andre,

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

Steven

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

Posted: Wed Dec 05, 2012 3:06 pm
by anorman
I have not, but shall try and see what happens..

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

Posted: Thu Dec 06, 2012 1:35 am
by admin
ok

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

Posted: Wed Dec 19, 2012 4:24 pm
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#;

}

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

Posted: Wed Dec 19, 2012 11:16 pm
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#";

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

Posted: Thu Dec 20, 2012 9:11 pm
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

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

Posted: Sat Dec 22, 2012 5:09 am
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;
;)

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

Posted: Fri Dec 28, 2012 12:02 am
by admin
.