This topic is locked
[SOLVED]

 One page list for every single day

1/4/2012 5:05:31 AM
PHPRunner General questions
T
technoserv author

Hi everybody.

I have list of appointments with 20 records every day and everything multiplied for 3 months.(the number is not every day the same).

I would like to see in list records page, one day every page with a button page + or page - to go on and back. how can I do? I use phprunner 5.3. thanks.

C
cgphp 1/4/2012

You can filter the list page in the "List page: Before SQL query" event:

$strWhereClause = whereAdd("day(date_field) ='".date("d")."'",strWhereClause);



You have to implement the logic for the + and - buttons. The date("d") should be associated to a session or post variable.

T
technoserv author 1/4/2012



You can filter the list page in the "List page: Before SQL query" event:

$strWhereClause = whereAdd("day(date_field) ='".date("d")."'",strWhereClause);



You have to implement the logic for the + and - buttons. The date("d") should be associated to a session or post variable.


Hi Cristian.

Thanks very much for your reply.
I put this filter in event but the query show nothing, blank page (no records found).

My field date is colled "giorno_app" and I put this string code:
$strWhereClause = whereAdd("day(giorno_app) ='".date("d")."'",strWhereClause);
forget something? mistake something?
Marco.

C
cgphp 1/4/2012

Do you have records for today's day?

T
technoserv author 1/5/2012

Good Morning.
No. I have records from the next day (tomorrow) and of the days to happen.

C
cgphp 1/5/2012

You have to change the above code as follow:

$strWhereClause = whereAdd("day(giorno_app) ='".$_SESSION['day']."'",strWhereClause);


where $_SESSION['day'] is the variable associated to the click on the + and - buttons.

T
technoserv author 1/5/2012

It gives an error:
Fatal error: Function name must be a string in C:\AppServ\www\orgagenda_new\include\appuntamenti_events.php on line 246
I have another $strWhereClause. A group filter for give permission to look list. I put your code before.
$strWhereClause = whereAdd("day(giorno_app) = '".$_SESSION('day')."'",$strWhereClause);
if ($_SESSION["GroupID"] !="administrators")

$strWhereClause = whereAdd($strWhereClause, "cliente_app='".$_SESSION["UserID"]."'");
else
{

C
cgphp 1/5/2012
$strWhereClause = whereAdd("day(giorno_app) = '".$_SESSION['day']."'",$strWhereClause);
if ($_SESSION["GroupID"] !="administrators")

$strWhereClause = whereAdd("cliente_app='".$_SESSION["UserID"]."'",$strWhereClause);
T
technoserv author 1/7/2012

Fatal error: Function name must be a string in C:\AppServ\..\..\appuntamenti_events.php on line...
:-(

C
cgphp 1/7/2012

It's difficult to say what's happening without a look at the full code of the "Before SQL query" event.

T
technoserv author 1/7/2012

This is the entire code of appuntamenti_events.php.

In the end there is your code.
<?php

class eventclass_appuntamenti extends eventsBase

{

function eventclass_appuntamenti()

{

// fill list of events

$this->events["AfterAdd"]=true;

$this->events["AfterEdit"]=true;

$this->events["BeforeQueryList"]=true;

// onscreen events

}

// Captchas functions

// handlers

// After record added

function AfterAdd(&$values,&$keys,$inline)

{
//** Check if specific record exists ****

global $conn;

$strSQLExists = "select * from contratti where cliente_con='".$values["cliente_app"]."' and trattamento_con='".$values["trattamento_app"]."' and attivo_con='1' and rimanenti_con='0'";

$rsExists = db_query($strSQLExists,$conn);

$data=db_fetch_array($rsExists);

if($data)

{

global $conn;

$strSQLInsert = "INSERT INTO attivita (id_app_att, giorno_att, ora_att, cliente_att, grp_tratt_att, trattamento_att, abbon_cl_att, lavorante_att) SELECT id_app, giorno_app, ora_app, cliente_app, grp_tratt_app, trattamento_app, '1', lavorante_app FROM appuntamenti ORDER BY id_app desc LIMIT 1";

db_exec($strSQLInsert,$conn);

// if record exists do something

}

else

{

global $conn;

$strSQLInsert = "INSERT INTO attivita (id_app_att, giorno_att, ora_att, cliente_att, grp_tratt_att, trattamento_att, abbon_cl_att, lavorante_att) SELECT id_app, giorno_app, ora_app, cliente_app, grp_tratt_app, trattamento_app, '0', lavorante_app FROM appuntamenti ORDER BY id_app desc LIMIT 1";

db_exec($strSQLInsert,$conn);

// if dont exist do something else

}

//** Redirect to another page ****

header("Location: appuntamenti_list.php");

exit();

// Place event code here.

// Use "Add Action" button to add code snippets.

;

}

// function AfterAdd

// After record updated

function AfterEdit(&$values,$where,&$oldvalues,&$keys,$inline)

{

//** Insert a record into another table ****

global $conn;

$strSQLExists = "select * from attivita where id_app_att='".$values["id_app"]."'";

$rsExists = db_query($strSQLExists,$conn);

$data=db_fetch_array($rsExists);

if($data)

{

$strSQLSave = "UPDATE attivita SET giorno_att='".$values["giorno_app"]."' WHERE id_att='".$data["id_att"]."'";

db_exec($strSQLSave,$conn);

$strSQLSave = "UPDATE attivita SET ora_att='".$values["ora_app"]."' WHERE id_att='".$data["id_att"]."'";

db_exec($strSQLSave,$conn);

$strSQLSave = "UPDATE attivita SET cliente_att='".$values["cliente_app"]."' WHERE id_att='".$data["id_att"]."'";

db_exec($strSQLSave,$conn);

$strSQLSave = "UPDATE attivita SET grp_tratt_att='".$values["grp_tratt_app"]."' WHERE id_att='".$data["id_att"]."'";

db_exec($strSQLSave,$conn);

$strSQLSave = "UPDATE attivita SET trattamento_att='".$values["trattamento_app"]."' WHERE id_att='".$data["id_att"]."'";

db_exec($strSQLSave,$conn);

$strSQLSave = "UPDATE attivita SET lavorante_att='".$values["lavorante_app"]."' WHERE id_att='".$data["id_att"]."'";

db_exec($strSQLSave,$conn);

$strSQLSave = "UPDATE attivita SET note_att='".$values["note_app"]."' WHERE id_att='".$data["id_att"]."'";

db_exec($strSQLSave,$conn);

// if record exists do something

}

else

{

$strSQLSave = "";

// if dont exist do something else

}

// Place event code here.

// Use "Add Action" button to add code snippets.

//** Redirect to another page ****

header("Location:appuntamenti_list.php");

exit();

// Place event code here.

// Use "Add Action" button to add code snippets.

;

}

// function AfterEdit
// List page: Before SQL query

function BeforeQueryList(&$strSQL,&$strWhereClause,&$strOrderBy)

{

$strWhereClause = whereAdd("day(giorno_app) = '".$_SESSION('day')."'",$strWhereClause);

if ($_SESSION["GroupID"] !="administrators")

$strWhereClause = whereAdd("cliente_app='".$_SESSION["UserID"]."'",$strWhereClause);

// Place event code here.

// Use "Add Action" button to add code snippets.

;

}

// function BeforeQueryList
// onscreen events
}

?>

C
cgphp 1/7/2012

$_SESSION['day'] not $_SESSION('day')

T
technoserv author 1/7/2012

Hi Cristian.
there is not error now but the answer of the query is blank page, No record found.
I forget to say you that in the principal query, there is already a filter.
SELECT id_app,

giorno_app,

ora_app,

fine_app,

cliente_app,

grp_tratt_app,

trattamento_app,

lavorante_app,

web_app,

note_app

FROM appuntamenti

WHERE (giorno_app >= CURDATE()+1)

ORDER BY giorno_app, ora_app
giorno_app is day field

ora_app is time field
Without your code it shows all records in order of day (giorno_app) and time(ora_app) sterting from tomorrow.

C
cgphp 1/7/2012

The whereAdd function concatenates the where clauses.

If the answer of the query is a blank page, make sure the $_SESSION['day'] is not empty.
Debug the code echoing the session variable:

echo "session day: ".$_SESSION['day'];

$strWhereClause = whereAdd("day(giorno_app) = '".$_SESSION['day']."'",$strWhereClause);
if ($_SESSION["GroupID"] !="administrators")

$strWhereClause = whereAdd("cliente_app='".$_SESSION["UserID"]."'",$strWhereClause);
T
technoserv author 1/7/2012

The apage is without error but it show
session day:
Debug shoes nothing
yes, $_SESSION['day'] is empty.

C
cgphp 1/7/2012

As I said, $_SESSION['day'] is the variable associated to the click on the + and - buttons. You have to implement the logic for the buttons to filter list by day.

T
technoserv author 1/9/2012

Ok. I'm sorry. I had not undestand.
If you Can, may i have an explain how to create - and + link or button with associated $_SESSION['day'] variable?
If you cannot, where I can find explanations?
Thanks.

T
technoserv author 1/11/2012

thank you very much Cristian.

I will try to make the buttons as you you have said.

thanks endless still