Page 1 of 1

Email - 'Requested JSON parse failed'

Posted: Fri Apr 24, 2015 3:35 pm
by Tinka
Hi Nubuilder experts!

I am sending mail by using the nuEmail() JavaScript function in nucommon.js. My PHP version is 5.6.7.
A pdf report is attached. Everything works fine as globaladmin.

On my email button I have this OnCLick :

Code: Select all

nuEmail('002','','xxx@clin.au.dk','Vare nr #var_nr# oprettet','Der er oprettet en ny vare i bestillingssystemet af #var_user#. \r\nSe venligst vedhaeftet fil. ','Varenr #var_nr#.pdf');

When using the email function as either user or admin (2 different access levels) an alert comes up "Requested JSON parse failed" from the nuemail form and the record is not saved.
But the email with attached report is sent anyway!
The users can print the same report by calling nurunPDF ('002') just fine. This report does not use a Criteria form. These user access levels have access to the nuBuilder EMAIL form.

Of course I want to avoid this alert and just send the email/save this record.
I have had a look at the EMAIL forms sql and javascript, but can't see a cause there.

In the Debug, nurunpdf.php causes a syntax error (but the same debug message is created when email is sent by globeadmin)(I replaced sensitive information):

Code: Select all

===USER==========



===PDO MESSAGE=== 

SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '2015-04-17 09:11:01' , ADD `zzzsys_report_log_added_by` VARCHAR(10) DEFAULT 'glo' at line 1

===SQL=========== 

ALTER TABLE ___nu1553a3dab3df0e___  ADD `nu_user_id` VARCHAR(15) DEFAULT '55092cbf08968a8' , ADD `nu_user_group` VARCHAR(3) DEFAULT '001' , ADD `nu_access_level` VARCHAR(3) DEFAULT '001' , ADD `nu_user_name` VARCHAR(11) DEFAULT 'CUT' , ADD `nu_index_id` VARCHAR(6) DEFAULT 'nuhome' , ADD `nu_smtp_to_name` VARCHAR(11) DEFAULT 'CUT' , ADD `TABLE_ID` VARCHAR(22) DEFAULT '___nu1553a3dab3df0e___' , ADD `RECORD_ID` VARCHAR(15) DEFAULT '5538d9d58391ed3' , ADD `FORM_ID` VARCHAR(7) DEFAULT 'nuemail' , ADD `nu_edited_record` VARCHAR(1) DEFAULT '1' , ADD `nu_cloned_record` VARCHAR(1) DEFAULT '0' , ADD `nu_new_record` VARCHAR(1) DEFAULT '0' , ADD `to` VARCHAR(14) DEFAULT 'XXXX@clin.au.dk' , ADD `replytoname` VARCHAR(11) DEFAULT 'CUT' , ADD `replyto` VARCHAR(1) DEFAULT ' ' , ADD `from` VARCHAR(28) DEFAULT 'xxxx@gmail.com' , ADD `subject` VARCHAR(19) DEFAULT 'Vare nr 12 oprettet' , ADD `message` VARCHAR(96) DEFAULT 'Der er oprettet en ny vare i bestillingssystemet af CUT. 
Se venligst vedhaeftet fil. ' , ADD `nu_denied` VARCHAR(3) DEFAULT 'nu%' , ADD `nu_smtp_username` VARCHAR(10) DEFAULT 'CUT' , ADD `nu_smtp_password` VARCHAR(8) DEFAULT 'CUT' , ADD `nu_smtp_host` VARCHAR(23) DEFAULT 'CUT' , ADD `nu_smtp_from_address` VARCHAR(28) DEFAULT 'XXXX@gmail.com' , ADD `nu_smtp_port` VARCHAR(2) DEFAULT '25' , ADD `nu_smtp_from_name` VARCHAR(19) DEFAULT 'Varebestilling MOMA' , ADD `id` VARCHAR(4) DEFAULT '1003' , ADD `session_id` VARCHAR(15) DEFAULT '553a3d9b3b6b212' , ADD `call_type` VARCHAR(8) DEFAULT 'saveform' , ADD `cloned` VARCHAR(1) DEFAULT '0' , ADD `edited` VARCHAR(1) DEFAULT '1' , ADD `title` VARCHAR(4) DEFAULT 'Home' , ADD `tip` VARCHAR(4) DEFAULT 'Edit' , ADD `type` VARCHAR(4) DEFAULT 'Edit' , ADD `tab_number` VARCHAR(1) DEFAULT '0' , ADD `sort` VARCHAR(1) DEFAULT '0' , ADD `descending` VARCHAR(3) DEFAULT 'asc' , ADD `page_number` VARCHAR(1) DEFAULT '1' , ADD `breadcrumb` VARCHAR(1) DEFAULT '0' , ADD `object_id` VARCHAR(1) DEFAULT '1' , ADD `edit_browse` VARCHAR(5) DEFAULT 'false' , ADD `parent_record_id` VARCHAR(3) DEFAULT '002' , ADD `form_height` VARCHAR(3) DEFAULT '300' , ADD `form_width` VARCHAR(3) DEFAULT '500' , ADD `iframe` VARCHAR(1) DEFAULT '0' , ADD `schema` VARCHAR(199) DEFAULT '[{\"table\":\"bevilgruppeMM\",\"fields\":[\"bevg_bev_ext\",\"bevg_bev_idFK\",\"bevg_grp_idFK\",\"bevilgruppe_id\"]},{\"table\":\"bevilling\",\"fields\":[\"bev_extinct\",\"bev_id\",\"bev_navn\",\"bev_' , ADD `object_properties` VARCHAR(2) DEFAULT '[]' , ADD `nu_pdf_code` VARCHAR(3) DEFAULT '002' , ADD `nu_email_to` VARCHAR(24) DEFAULT 'XXX@clin.au.dk' , ADD `nu_email_subject` VARCHAR(19) DEFAULT 'Vare nr 12 oprettet' , ADD `nu_email_message` VARCHAR(97) DEFAULT 'Der er oprettet en ny vare i bestillingssystemet af Susanne Bruun. 
Se venligst vedhaeftet fil. ' , ADD `nu_email_file_name` VARCHAR(13) DEFAULT 'Varenr 12.pdf' , ADD `nu_previous_record_id` VARCHAR(15) DEFAULT '5538d9d58391ed3' , ADD `closedown` VARCHAR(1) DEFAULT '1' , ADD `validate` VARCHAR(8) DEFAULT 'printpdf' , ADD `code` VARCHAR(3) DEFAULT '002' , ADD `zzzsys_report_id` VARCHAR(15) DEFAULT '5530b205daad749' , ADD `sre_code` VARCHAR(3) DEFAULT '002' , ADD `sre_description` VARCHAR(11) DEFAULT 'Enkelt vare' , ADD `sre_group` VARCHAR(5) DEFAULT 'CUT' , ADD `sre_zzzsys_sql` VARCHAR(199) DEFAULT 'Select v.*, l.*, pr.*, be.*,fa.*,gr.*,pra.*,
p.per_navn AS bestilttil, 
pp.per_navn AS modtager,
IF(var_bestilt =\"1\",\"ja\", IF(var_bestilt= \"0\", \"nej\", \" \")) AS bestilt,
IF(var_fare =\"1\",\' , ADD `zzzsys_report_log_added_at` VARCHAR(19) DEFAULT '2015-04-17 09:11:01' , ADD `zzzsys_report_log_added_by` VARCHAR(10) DEFAULT 'globeadmin' , ADD `zzzsys_report_log_changed_at` VARCHAR(19) DEFAULT '2015-04-21 15:17:15' , ADD `zzzsys_report_log_changed_by` VARCHAR(10) DEFAULT 'globeadmin' , ADD `zzzsys_report_log_viewed_at` VARCHAR(19) DEFAULT '2015-04-24 11:53:49' , ADD `zzzsys_report_log_viewed_by` VARCHAR(10) DEFAULT 'globeadmin' , ADD `nu_date_time` VARCHAR(19) DEFAULT '2015-04-24 14:57:15' , ADD `nu_date` VARCHAR(10) DEFAULT '2015-04-24' , ADD `nu_time` VARCHAR(8) DEFAULT '14:57:15' , ADD `nu_year` VARCHAR(4) DEFAULT '2015' , ADD `nu_month` VARCHAR(2) DEFAULT '04' , ADD `nu_day` VARCHAR(2) DEFAULT '24' , ADD `nu_hour` VARCHAR(2) DEFAULT '14' , ADD `nu_minute` VARCHAR(2) DEFAULT '57' , ADD `nu_second` VARCHAR(2) DEFAULT '15' 

===BACK TRACE====

/hsphere/local/home/kadol/varer.moma.dk/nurunpdf.php - line 1066 (nuRunQuery)

/hsphere/local/home/kadol/varer.moma.dk/nurunpdf.php - line 60 (nuAddCriteriaValues)
The only thing I can see here is the difference of 'glo' and 'globaladmin' in the sql lines added to those of the report where
ADD `zzzsys_report_log_added_by` VARCHAR(10) DEFAULT 'globeadmin' ,

How can I debug this 'Requested JSON parse failed'? When using JSON view in Chrome the path and value are undefined.

BR, Tinka

Re: Email - 'Requested JSON parse failed'

Posted: Fri Apr 24, 2015 8:00 pm
by admin
Tinka,

I'll get it looked at in a couple of days.

Steven

Re: Email - 'Requested JSON parse failed'

Posted: Tue Apr 28, 2015 1:23 pm
by Tinka
Steven,

great, hope we find the bug.

Tinka

Re: Email - 'Requested JSON parse failed'

Posted: Mon May 04, 2015 5:41 am
by shane
please upload a copy of your sql file so I can debug this better

Re: Email - 'Requested JSON parse failed'

Posted: Mon May 04, 2015 11:14 am
by Tinka
Hi Shane

You mean the database?

Tinka

Re: Email - 'Requested JSON parse failed'

Posted: Tue May 05, 2015 4:48 am
by admin
Yes.

Steven

Re: Email - 'Requested JSON parse failed'

Posted: Tue May 05, 2015 9:02 am
by Tinka
database _nubuilderversion.zip
BR, Tinka

Re: Email - 'Requested JSON parse failed'

Posted: Mon May 11, 2015 12:39 pm
by Tinka
I think I located the cause for the error message:
the user is not registered with an e-mail address, as soon as I added a sus_email in the zzsys_user the "Requested JSON parse failed" disappeared.

A closer look at the PHP function nuEmail in the nucommon.php line 1563 reveals that the sus_email is used:

Code: Select all

$session         = $hashData['session_id'];
    $sql             = "SELECT * FROM  zzzsys_session INNER JOIN zzzsys_user ON sss_zzzsys_user_id = zzzsys_user_id WHERE zzzsys_session_id = '$session'";
    $t               = nuRunQuery($sql);
    $r               = db_fetch_object($t);
    if($r != null) {
        $fromname    = $r->sus_name;
        $fromaddress = $r->sus_email;
    } else {
    	$setup       = $GLOBALS['nuSetup'];                                                           //-- Read SMTP AUTH Settings from zzsys_setup table	
        $fromname    = trim($setup->set_smtp_from_name);
        $fromaddress = trim($setup->set_smtp_from_address);
So if your users are not registered with e-mail I guess you just need to modify line 1575.

BR, Tinka

Re: Email - 'Requested JSON parse failed'

Posted: Fri May 15, 2015 5:27 am
by admin
Tinka,

Our lastest build now includes a warning if there is no user email address.

Steven