Page 1 of 1

Application global settings table

Posted: Tue Sep 28, 2021 10:46 pm
by xtairi
Hello everyone, hello developers,

I started to learn nuBuilder and find out that there is a lot of potential and was a lot of work going into this product. Respect to the developer!

My Question:
I just want to create a table and store all global settings in it (one record). What will the table contain?
  • -Company information (Address, VAT, Phone numbers, etc)
    -Starting number for customers (after saving I will increase it)
    -Starting number for organization (after saving I will increase it)
    -Starting number for invoices (after saving I will increase it)
    -and much other
All company information from this global settings table I will need for reports (for header and footer). All entries from this table must be loaded in a global variable.
Example:

Code: Select all

$pref = "SELECT * FROM Settings WHERE Settings_id = 1";
nuRunQuery($pref);
I would like to replace a placeholder (field/label value) in the report:
Example:

Code: Select all

##COMPANYNAME## = $pref['set_company_name']
##STREET## = $pref['set_street_1']
##CITY## = $pref['set_country']
Has anyone done something like that?
I would be very happy if someone could help me.

I wish you all the best and stay healthy!
Xhezmi

Re: Application global settings table

Posted: Wed Sep 29, 2021 7:59 am
by kev1n
Hi Xhezmi,

Store the settings in global Hash Cookies:

Code: Select all

$pref = "SELECT * FROM Settings WHERE Settings_id = 1";
$t = nuRunQuery($pref);
$r = db_fetch_object($t);

nuAddToHashCookies('set_company_name', $r->set_company_name);
nuAddToHashCookies('set_street_1', $r->set_street_1);
Then use them in reports by adding those Hash Cookies:

e.g. #set_company_name#

(Lastest version from Github required, updated today)

Re: Application global settings table

Posted: Wed Sep 29, 2021 11:07 pm
by xtairi
Hi Kev1n,

Thank you very much for your answer. I have updated now to the latest version.
Where do I have to run this PHP script?

What have I done (is that correct?)
  • I've created a new procedure called "nuStartup"
    In the setup script I call the procedure

    Code: Select all

    nuRunPHPHidden('nuStartup', 1);
    Procedure name: nuStartup:

    Code: Select all

    $pref = "SELECT * FROM Settings LIMIT 1";
    $t = nuRunQuery($pref);
    $r = db_fetch_object($t);
    
    nuAddToHashCookies('set_company_name', $r->set_company_name);
    I run the report example organization list, but the the hash cookies is not replaced and is still #set_company_name#
    Report reults

    Code: Select all

     #set_company_name#
    org_name          org_city
    ---------------------------
    Company A Ltd   New York
    Company B Ltd   Switzerland
If I click the Settings button on User Home, it open direct a new form. Is there a way to open the first record in to the edit mode (without browse)? Like:

Code: Select all

SELECT * FROM Settings LIMIT 1
The Settings_id I can't use because its a long generated number :-) The Form Type for Settings is "Edit"

best regards
Xhezmi

Re: Application global settings table

Posted: Fri Oct 01, 2021 7:39 am
by kev1n
Use an Input/Button object instead of a Run object and open the form/that record with the JS nuForm()

Hash Cookies with global scope are stored in the database, zzzzsys_session.sss_hashcookies. Verify that they have been stored in that column.

Re: Application global settings table

Posted: Sat Oct 02, 2021 11:58 am
by xtairi
Hi Kev1n,

#Case 1 - Hash Cookies:
I checked the table zzzzsys_session and sss_hashcookies and it is NULL.
Procedure name: nuStartup:

Code: Select all

$pref = "SELECT * FROM Settings LIMIT 1";
$t = nuRunQuery($pref);
$r = db_fetch_object($t);

nuAddToHashCookies('set_code', $r->set_code);
nuAddToHashCookies('set_company', $r->set_company);
In the setup script I call the procedure:

Code: Select all

nuRunPHPHidden('nuStartup', 1);
In this case the values should be stored in to the zzzzsys_session.sss_hashcookies, but the filed is empty.

********************************************************

#Case 2:
You wrote "Use an Input/Button object instead of a Run object and open the form/that record with the JS nuForm()"
I done it, but there are not possible to add a vlaue from a field #SET_CODE#=1 instead of a record id.
Input Type: Button
Object: obj_btn_settings
Label: Settings
Custom Code:

Code: Select all

nuForm('6154b2eb1d56f6f', '#SET_CODE#=1', '', '', '1');
with this code it works:
I can add the Settings_id of a row. The same RECORD ID must always be present for every export and import.

Form-ID: 6154b2eb1d56f6f
Row-ID/Record-ID: 6154b332ac641b8

Code: Select all

nuForm('6154b2eb1d56f6f', '6154b332ac641b8', '', '', '1');
Form Settings:
Type: Edit
Code: SET
Description: Settings
Browse SQL:

Code: Select all

SELECT * FROM Settings
After Save PHP:

Code: Select all

$sql = "SELECT * FROM Settings WHERE Settings_id = '6154b332ac641b8'";
$cmd = nuRunQuery($sql);
$res = db_fetch_object($cmd);

nuAddToHashCookies('set_code', $res->set_code);
nuAddToHashCookies('set_company', $res->set_company);
JavaScript (Save & Close):

Code: Select all

nuDisable('nuDeleteButton');
nuDisable('nuCloneButton');

function nuAfterSave() {
   nuOpenPreviousBreadcrumb();
}

Re: Application global settings table

Posted: Sun Oct 03, 2021 6:27 pm
by xtairi
kev1n wrote:Use an Input/Button object instead of a Run object and open the form/that record with the JS nuForm()

Hash Cookies with global scope are stored in the database, zzzzsys_session.sss_hashcookies. Verify that they have been stored in that column.
Hi Kev1n,

I checked your script now and found the issue (it's not an issue but missing parameter).

#Case 1 - Hash Cookies:
I checked the table zzzzsys_session and sss_hashcookies and it is NULL. Why?

Procedure name: nuStartup:

Code: Select all

$sql = "SELECT * FROM setting WHERE setting_id = '6154b332ac641b8'";
$cmd = nuRunQuery($sql);
$res = db_fetch_object($cmd);

nuAddToHashCookies('set_company', $res->set_company, true);
nuAddToHashCookies('set_vat', $res->set_vat, true);
nuAddToHashCookies('set_email', $res->set_email, true);
A Boolean (true or false) must be added in to the call function nuAddToHashCookies, whether the variable should be global or not.

In the setup script I call the procedure:

Code: Select all

nuRunPHPHidden('nuStartup', 1);
This case is solved. Thank you for the solution and I wish you a nice evening.

best regards,
Xhezmi