ultimatepp/examples/AddressBookWeb/Pages.icpp
cxl a85868e22b .cosmetics
git-svn-id: svn://ultimatepp.org/upp/trunk@5151 f0d560ea-af0d-0410-9eb7-867de7ffcac7
2012-07-08 13:16:09 +00:00

74 lines
1.4 KiB
Text

#include "AddressBook.h"
void Persons(Http& http)
{
ValueArray person;
SqlBool where;
String s = http["search"];
if(!IsNull(s)) {
s << '%';
where = Like(FIRSTNAME, s) || Like(LASTNAME, s) || Like(EMAIL, s);
}
ValueMap vm;
Sql sql;
sql * Select(ID, FIRSTNAME, LASTNAME, EMAIL)
.From(PERSON)
.Where(where)
.OrderBy(LASTNAME, FIRSTNAME);
while(sql.Fetch(vm))
person.Add(vm);
http("PERSON", person);
};
SKYLARK(HomePage, "")
{
Persons(http);
http.RenderResult("AddressBookWeb/Index");
}
SKYLARK(CatchAll, "**")
{
http.Redirect(HomePage);
}
SKYLARK(SubmitNew, "submit/create:POST")
{
SQL * http.Insert(PERSON);
http.Redirect(HomePage);
}
SKYLARK(New, "person/create")
{
http("ACTION", SubmitNew).RenderResult("AddressBookWeb/Dialog");
}
SKYLARK(SubmitEdit, "submit/edit/*:POST")
{
SQL * http.Update(PERSON).Where(ID == http.Int(0));
http.Redirect(HomePage);
}
SKYLARK(Edit, "person/*/edit")
{
int id = http.Int(0);
Sql sql;
sql * Select(FIRSTNAME, LASTNAME, EMAIL)
.From(PERSON)
.Where(ID == id);
if(!sql.Fetch()) {
http.Redirect(HomePage);
return;
}
http
(sql)
("ID", id)
("ACTION", SubmitEdit, id)
.RenderResult("AddressBookWeb/Dialog");
}
SKYLARK(Delete, "person/*/delete")
{
SQL * Delete(PERSON).Where(ID == atoi(http[0]));
DeleteFile(ConfigFile(atoi(http[0]) + ".data"));
http.Redirect(HomePage);
}