Rejestracja sklada sie z 3 czesci
1) PREZENTACJA (VIEW):
<?php
// Registration Module View
$l = SowaCms::login();
JScript
::vars("SowaCms.vars",isset($vars)?
$vars:""); $t = new HtmlTable();
$t->script(SowaCms::cms_url("module")."js/sowa_validate.js");
$t->script(SowaCms::cms_url("module")."js/Registration.js");
if($l)
$t->trlb("PLEASE UPDATE YOUR REGISTRATION INFORMATION","class='label_box'");
else
$t->trlb("PLEASE ENTER YOUR REGISTRATION INFORMATION","class='label_box'");
$t->trtd("align=center");
$f = new HtmlFieldSet("Account Informaton","class='legend'","style='margin:3px;width:99%'");
$f->trtd("align=center");
$c = new HtmlTable("cellspacing=5");
$c->tr();$c->tdlb("* First Name","class='label_input'");
$c->tdlb("* Last Name","class='label_input'");
$c->tr();$c->tdtext("customer.first_name","class='text' style='width:255px'","customer.last_name",$l?$l->first_name:"");
$c->tdtext("customer.last_name","class='text' style='width:255px'","customer.address1",$l?$l->last_name:"");
$c->tr();$c->tdlb("Address1","class='label_input' colspan=3");
$c->trtd("colspan=2");$c->text("customer.address1","class='text' style='width:515px' colspna=2","customer.address2",$l?$l->address1:"");
$c->tr();$c->tdlb("Address2","class='label_input' colspan=3");
$c->trtd("colspan=2");$c->text("customer.address2","class='text' style='width:515px' colspna=2","customer.city",$l?$l->address2:"");
$c->trtd("colspan=2");
$ts = new HtmlTable();
$ts->tr(); $ts->tdlb("City","class='label_input'");
$ts->tdlb("State","class='label_input'");
$ts->tdlb("Zip","class='label_input'");
$ts->tr(); $c->tdtext("customer.city","class='text' style='width:275px' colspan=2","customer.state",$l?$l->city:"");
$c->td();$c->sp();$c->select("customer.state",$states,"class='options'",$l?$l->state:"");
$c->sp();$c->tdtext("customer.zip","class='text' style='width:98px'","customer.phone",$l?$l->zip:"");
$c->tr();$c->tdlb("Phone Number","class='label_input'");
$c->tdlb("* Email Address","class='label_input'");
$c->tr();$c->td("align=left"); $c->text("customer.phone","class='text' style='width:150px'","customer.email",$l?$l->phone:"");
$c->tdtext("customer.email","class='text' style='width:255px'",$l?"customer.password":"customer.user_name",$l?$l->email:"");
$c->tr();$c->tdlb("* User Name","class='label_input'".($l?" disabled=true":""));
$c->tdlb("* Password","class='label_input'");
$c->tr();$c->td("align=left");$c->text("customer.user_name","class='text' style='width:150px'".($l?" disabled=true":""),"customer.password",$l?$l->user_name:"");
$c->tdpassword("customer.password","class='text' style='width:255px'","customer.first_name",$l?$l->password:"");
$t->trtd("align=right style='padding-top:5px'");
if($l) {
$t->button("No Thanks","Registration_onThanks()","class='button' style='width:80px'");$t->sp();
$t->button("Update Account","Registration_onSubmit(event,1)","class='button' style='width:120px'","button.submit");
}
else {
$t->button("No Thanks","Registration_onThanks()","class='button' style='width:80px'");$t->sp();
$t->button("Submit","Registration_onSubmit(event,0)","class='button' style='width:80px'","button.submit");
}
$t->trh("5px");
$d = new Div("dialog.message","style='left:0;top:0;visibility:hidden;position:absolute'");
$__no_last_page_uri = 1;
?>
2) VALIDACJA i WYSLANIEM AJAX-em requestu do Serwisu (CONTROLLER)
function Registration() {
}
function Registration_onSubmit(event, mode) {
if(!SowaCms._onLoad)
return ;
Validate.reset();
Validate.validate("customer.first_name","Missing First Name");
Validate.validate("customer.last_name","Missing Last Name");
Validate.validate("customer.email","Email Missing",Validate.email(),"Invalid Email");
Validate.validate("customer.user_name","Missing User Name");
Validate.validate("customer.password","Missing Password");
if(Validate.getError()) {
Dialog.message("dialog.message", event, 0, mode?"MY ACCOUNT":"REGISTRATION ERROR",Validate.getError(),"Validate.setFocus()");
return Dialog.modal("dialog.message");
}
Dialog.decision("dialog.message",event,0, mode?"MY ACCOUNT":"REGISTARTION","Do you want to "+(mode?"update my account":"submit registration")+" ?","Registration_onSubmit_Yes("+mode+")","Gui.setFocus('customer.first_name')");
Dialog.modal("dialog.message");
}
function Registration_onSubmit_Yes(mode) {
var cust = Gui.objectFromView("customer","first_name;last_name;address1;address2;city;state;zip;phone;email;user_name
password");
cust.account_id = SowaCms.accountId();
Gui.disableElement("button.submit");
Dialog.info("dialog.message",Gui._mouseX, Gui._mouseY, mode?"MY ACCOUNT":"REGISTRATION","Your request is processing ...");
Dialog.modal("dialog.message");
MyService.service(SowaCms.cmsUrl("module")+"ModuleServices.php","registration",
[["sa","cust",cust],
["sr",Registration_onSubmit_Yes_response]]);
function Registration_onSubmit_Yes_response(body, args, error) {
Gui.enableElement("button.submit");
if(error)
return Dialog.message( "dialog.message",Gui._mouseX, Gui._mouseY, mode?"MY ACCOUNT ERROR":"REGISTRATION ERROR",error, "Gui.setFocus('customer.user_name')");
if(mode) {
if(SowaCms.CMS_LAST_PAGE_URI)
SowaCms.location(SowaCms.CMS_LAST_PAGE_URI);
else
SowaCms.home();
}
else {
if(SowaCms.vars.login_page)
SowaCms.location(SowaCms.vars.login_page);
else
SowaCms.home();
}
}
}
function Registration_onThanks() {
if(!SowaCms._onLoad)
return ;
if(SowaCms.CMS_LAST_PAGE_URI)
SowaCms.location(SowaCms.CMS_LAST_PAGE_URI);
else
SowaCms.home();
}
function onLoad() {
Gui.init();
SowaCms.onLoad();
Gui.setFocus("customer.first_name");
}
3) SERWIS WYKONUJACY REJESTRACJE (MODEL)
<?php
// Registration Service
include_once("SowaService.inc");
$log = SowaCms::log();
$db = SowaCms::db();
$ses = SowaCms::ses();
$_req = new Request();
switch($_req->service()) {
case "registration":$cust = $_req->arg("cust");
$user = SowaCms::login();
if($user) {
$db->update_object("cms_customer",$cust,"user_id={$user->user_id}");
$user = $_db->query_object("cms_customer","*","user_id={$user->user_id}");
$user->name = $user->first_name." ".$user->last_name;
$user->cms_url = CMS_URL;
$ses->sarg("_login_user",$user);
}
else {
$cust->create_date = $_db->get_date_time();
$db->insert_object("cms_customer",$cust,"",1);
if(!$db->insert_id())
$_req->error("User name '".$cust->user_name."' already exists, try other.");
}
break;
default: {
$_req->error("Service '".$_SERVER['PHP_SELF']."/".$_req->service()."' not Implemented");
}
}
$_req->response();
?>
Czyli jak mozna zauwazyc jest to klasyczny model MVC (Model–view–controller)