Autor Tópico: Contol Aplication and Grid aplication  (Lida 3730 vezes)

anakbinus

  • Visitante
Contol Aplication and Grid aplication
« Online: Dezembro 02, 2008, 03:00:16 am »
Heloo Guys.

I try to make a web aplication using scriptcase, this aplication have login page and showing customer database record where depend who login user. If user in Brazil login to this application, so this user only can read customer reord in brasil. also if user in Indonesia login, so user in indonesia so can read only customer record in Indonesia.

Database: User
- Username (primary key)
- Password
- IDbranch
- role

Database: customer
- Customer name
- Phone
- IDBranch

Database: Branch
-IDBranch
-Branchname

the question is where I put session? in grid aplication or control application?
does anyone have sample script?

please reply in english.


Ajeng
- Indonesia'n Female-

j.arteiro

  • Visitante
Re: Contol Aplication and Grid aplication
« Responder #1 Online: Dezembro 02, 2008, 12:09:25 pm »
Dear Anakbinus,


its easy to create this application.

You need to create a control application, and insert two fields, calling login and password. for exemplo.

on event "onvalidate", you need to use a macro sc_lookup, to find if this user is registred and get his informations.


--------------------------------  exemplo of onvaliddate event -------------------------------

function insert_session($login) {

sc_lookup(return_func, "SELECT Username, IDbranch, role FROM User WHERE Username='$login'");
sc_lookup(return_branchname, "SELECT Branchname FROM Branch WHERE IDbranch='{return_func[0][1]}'");

[login_site_checked]={return_func[0][0]};
[IDbranch_site_checked]={return_func[0][1]};
[role_site_checked]={return_func[0][2]};
[Brachname_site_checked]={return_branchname[0][0]};

}


sc_lookup(return, "SELECT COUTN(Username) FROM User WHERE Username='{login}' AND Password='{password}'");

if ({return[0][0]}>0) {

echo "<script> alert('Welcome to my site'); </script>";

insert_session({login});

sc_redir(my_next_application);


}
else
echo "<script> alert('User dont found.'); </script>";

--------------------------------  END exemplo of onvaliddate event -------------------------------

In macro sc_redir(); , my_next_application is the application name that will calling after validate.

in next application, to call session variable, you use:

$login_user=[login_site_checked];
$IDbranch_user=[IDbranch_site_checked];
$role_user=[role_site_checked];
$Brachname_user=[Brachname_site_checked];

and to filter the result of consult application, you need to use a macro sc_select_where();, there is a tutorial of this macro in the end.





--------------------------------  tutorial sc_lookup -------------------------------
sc_lookup(dataset, "sql command", "connection")

sc_lookup (dataset, "SQLcommand", "connection")

This macro allows the user to execute SQL commands and have access to the "dataset" proceeding from the command. The "dataset" is available, in the array shape (line/column).

To access the dataset, see the sc_select macro.

 

 

The "connection" parameter is optional, being necessary, only, if the command is executed in a database different from that specified for the application.

Ex:
sc_lookup(dataset, "select customer_id, customer_name, credit_limit from customers" );

To have access to the first line (recordset), we will have:
{customer_id} = {dataset[0][0]};
{customer_name} = {dataset[0][1]};
{credit_limit } = {dataset[0][2]};

To have access to the second line (recordset), we will have:
{customer_id} = {dataset[1][0]};
{customer_name} = {dataset[1][1]};
{credit_limit} = {dataset[1][2]};

If occurs error in the execution of the sql command, the variable attributed to the dataset will return as "false" and the error message will be available in the "dataset_erro" variable.

It is, also, important, verifies if the select returned data, to prevent the access to unexisting variables, once the output array only will be created if the select command returns data.

Ex:
sc_lookup(my_data, "select customer_id, customer_name, credit_limit from customers");
if ({my_data} === false)
{
echo "Access error. Message=". {my_data_erro} ;
}
elseif (empty({my_data}))
{
echo "Select command didn't return data";
}
else
{
{customer_id} = {my_data[0][0]};
{customer_name} = {my_data[0][1]};
{credit_limit} = {my_data[0][2]};
}

The SQL command also can be composed of application fields (local variables) or of global variables:

Ex:
sc_lookup(dataset, "select order_value from orders where clienteid = '{customer_id} ' and salesman_id = [var_glo_salesman]");

P.S: In any circunstance, the command must be finished with point and comma ";".
--------------------------------  END tutorial sc_lookup -------------------------------




--------------------------------  tutorial sc_redir -------------------------------
sc_redir(apl, parm1; parm2; ..., target)

sc_redir (apl, parm1; parm2; ..., target)


This macro has the aim to redirect the processing to other application or URL.
If the redirecting application use parameters, these must be passed in the following manner:
1) After the name of the application, use the comma delimitator (,)
2) Inform the name of the parameter, the equality (=) and the value or variable to be attibuted.
3) Having more than a parameter, use the point and comma delimitator (;)
4) The target can be informed in which the application will be opened (default=_self), being: _self, _parent or _blank.

Ex1: Application without parameters nor target
if ([glo_usr] == “test”)
{
sc_redir(aplx.php);
}

Ex2: Application with parameters and without target.
if ([glo_usr] == “test”)
{
sc_redir(aplx.php, parm1={var_test}; parm2=”xxx”);
}

Ex3: Application without parameters and with target
if ([glo_usr] == “test”)
{
sc_redir(aplx.php, "", "_parent");
}

Ex4: Application with parameter and target.
if ([glo_usr] == “test”)
{
sc_redir(aplx.php, parm1={var_test}; parm2=”xxx”, "_blank");
}

Ex5: URL
if ([glo_usr] == “test”)
{
sc_redir(http://www.my_page.com);
}
--------------------------------  END tutorial sc_redir -------------------------------





--------------------------------  tutorial sc_select_where  -------------------------------
sc_select_where(add)

sc_select_where (add)


Is possible, in time of consult execution, add a field/condition to the WHERE clause of the search.

Ex:
if (empty({sc_where_current}))
{
sc_select_where(add) = "where campoX > [var_glo_where]";
}
else
{
sc_select_where(add) = "AND campoX > [var_glo_where]";
}

Obs: This command must be in the context of "proccess before the select".
--------------------------------  END tutorial sc_select_where -------------------------------