$basevars['inputnames']['login']['name']='customer_mail';
$basevars['inputnames']['login']['passwd']='customer_passwd';
$basevars['inputnames']['login']['passwdrepeat']='customer_passwd2';
- $basevars['inputnames']['login']['name']='customer_name';
+ $basevars['inputnames']['login']['lastname']='customer_name';
$basevars['inputnames']['login']['firstname']='customer_firstname';
$basevars['inputnames']['login']['title']='customer_title';
$basevars['inputnames']['address']['setaddress']='setaddr';
$basevars['inputnames']['address']['createaddress']='createaddr';
- $basevars['inputnames']['address']['name']='name';
- $basevars['inputnames']['address']['addr1']='addr1';
- $basevars['inputnames']['address']['addr2']='addr2';
- $basevars['inputnames']['address']['city']='city';
- $basevars['inputnames']['address']['state']='state';
- $basevars['inputnames']['address']['country']='country';
+ $basevars['inputnames']['address']['name']='addr_name';
+ $basevars['inputnames']['address']['addr1']='addr_line1';
+ $basevars['inputnames']['address']['addr2']='addr_line2';
+ $basevars['inputnames']['address']['city']='addr_city';
+ $basevars['inputnames']['address']['zip']='addr_zip';
+ $basevars['inputnames']['address']['state']='addr_state';
+ $basevars['inputnames']['address']['country']='addr_country';
//end of basevars
}
\param script.customerLogin the page to call for logging in
\param script.customerRegistration the page to call for registering a new customer
- \param customer_name the name of the customer (or an empty string if unknown)
+ \param customer_name the name (mail) of the customer (or an empty string if unknown)
*/
/** creates a login page
$list["customer_name"]=$cust->getemail();
}
}
+ $list['countries']=WOCountry::fromTableArraycountry(WTcountry::selectFromDB("","ORDER BY countryname"));
//display
$p=$twig->loadTemplate("login.html");
return $p->render($list);
The loginerror.html template is used to render customer login and registering errors.
- \param errorType the type of error: "login" - the login failed (wrong mail or password), "exist" - an account with the same mail already exists, "mismatch" - the new passwords do no match
+ \param errorType the type of error: "login" - the login failed (wrong mail or password), "exist" - an account with the same mail already exists, "mismatch" - the new passwords do no match, "create" for unspecified errors during creation of the new account (e.g. missing or invalid parameters)
\param backUrl the URL to call back to the login page
*/
redirectHome(array("mode"=>$next));
}
+ ///attempts to register a customer: if ok it creates a new customer object and redirects to the createaddress page, otherwise it shows the loginerror page
static public function registerCustomer()
{
- global $HTTPARGS,$db,$basevars;
- die ("not implemented");
+ global $HTTPARGS,$db,$basevars,$twig;
+ //check whether params are there
+ $nameidx=$basevars['inputnames']['login']['name'];
+ $passidx=$basevars['inputnames']['login']['passwd'];
+ $passidx2=$basevars['inputnames']['login']['passwdrepeat'];
+ if(!isset($HTTPARGS[$nameidx]) || !isset($HTTPARGS[$passidx]) || !isset($HTTPARGS[$passidx2]))
+ return self::loginError("create");
+ //check whether the chosen email is valid and does not exist yet
+ $mail=$HTTPARGS[$nameidx];
+ $ct=WTcustomer::selectFromDB("email=".$db->escapeString($mail));
+ if(count($ct)>0)
+ return self::loginError("exist");
+ //check the password
+ $pass=$HTTPARGS[$passidx];$pass2=$HTTPARGS[$passidx2];
+ if($pass != $pass2 || $pass=="")return self::loginError("mismatch");
+ //create customer
+ $ct=WTcustomer::newRow();
+ $ct->email=$mail;
+ $ct->passwd=Session::passwdHash($pass);
+ if(isset($HTTPARGS[$basevars['inputnames']['login']['firstname']]))
+ $ct->firstname=$HTTPARGS[$basevars['inputnames']['login']['firstname']];
+ if(isset($HTTPARGS[$basevars['inputnames']['login']['lastname']]))
+ $ct->name=$HTTPARGS[$basevars['inputnames']['login']['lastname']];
+ if(isset($HTTPARGS[$basevars['inputnames']['login']['title']]))
+ $ct->title=$HTTPARGS[$basevars['inputnames']['login']['title']];
+ if(!$ct->insert())
+ return self::loginError("create");
+ //create address
+ $addr=WTaddress::newRow();
+ $addr->customerid=$ct->customerid;
+ $addr->lastused=time();
+ if(isset($HTTPARGS[$basevars['inputnames']['address']['addr1']]))
+ $addr->addr1=$HTTPARGS[$basevars['inputnames']['address']['addr1']];
+ if(isset($HTTPARGS[$basevars['inputnames']['address']['addr2']]))
+ $addr->addr2=$HTTPARGS[$basevars['inputnames']['address']['addr2']];
+ if(isset($HTTPARGS[$basevars['inputnames']['address']['city']]))
+ $addr->city=$HTTPARGS[$basevars['inputnames']['address']['city']];
+ if(isset($HTTPARGS[$basevars['inputnames']['address']['zip']]))
+ $addr->zipcode=$HTTPARGS[$basevars['inputnames']['address']['zip']];
+ if(isset($HTTPARGS[$basevars['inputnames']['address']['state']]))
+ $addr->state=$HTTPARGS[$basevars['inputnames']['address']['state']];
+ $addr->insert();
+ //attempt to set countryid (done separately since it is a foreign key and not quite as essential
+ if(isset($HTTPARGS[$basevars['inputnames']['address']['country']]))
+ $addr->countryid=$HTTPARGS[$basevars['inputnames']['address']['country']];
+ $addr->update();
+ //log into cart
+ $cartid=WebCart::getCart();
+ if($cartid==""){
+ $p=$twig->loadTemplate("carterror.html");
+ return $p->render($basevars);
+ }
+ //get customer data
+ $cart=WTcart::getFromDB($cartid);
+ $cart->customerid=$ct->customerid;
+ $cart->update();
+ //get address if there is none yet
+ if($cart->deliveryaddress==false){
+ $addrs=WTaddress::selectFromDB("customerid=".$ct->customerid,"ORDER BY lastused DESC");
+ if(count($addrs)>0){
+ $cart->deliveryaddress=$addrs[0]->addressid;
+ $cart->update();
+ }
+ }
+ //store in session
+ $sess=WOWebSession::getOrCreateWebSession();
+ $st=WTwebsession::getFromDB($sess->getsessionid());
+ $st->customerid=$ct->customerid;
+ $st->update();
+ //go to checkout page
+ redirectHome(array("mode"=>"checkout"));
}
};
{# the create account dialog #}
<div id="creatediv">
<form action="{{script.customerRegistration}}" method="POST">
+ Please enter a valid email address and a secure password for your account. All order information will be sent to this email address. You will need the password to order tickets and to see your order status - anyone who knows this password can order in your name. If you forget your password you can reset it at any time.<br/>
<table>
<tr><td>E-mail address:</td><td><input type="text" name="{{inputnames.login.name}}" value="{{customer_name}}" /></td></tr>
<tr><td>Select a Password:</td><td><input type="password" name="{{inputnames.login.passwd}}"/></td></tr>
<tr><td>Repeat Password:</td><td><input type="password" name="{{inputnames.login.passwdrepeat}}"/></td></tr>
</table><p/>
+ Please enter an address to which your order will be sent:<br/>
<table>
<tr><td>Title:</td><td>
<input type="text" name="{{inputnames.login.title}}" id="titleinput" width="6" />
<a href="javascript:void selectTitle('Frau')">Frau</a>
</div>
</td></tr>
- <tr><td>Name:</td><td><input type="text" name="{{inputnames.login.name}}"/></td></tr>
+ <tr><td>Last Name:</td><td><input type="text" name="{{inputnames.login.lastname}}"/></td></tr>
<tr><td>First Name:</td><td><input type="text" name="{{inputnames.login.firstname}}"/></td></tr>
+ <tr><td>Address:</td><td><input type="text" name="{{inputnames.address.addr1}}"/><br/>
+ <input type="text" name="{{inputnames.address.addr2}}"/></td></tr>
+ <tr><td>City:</td><td><input type="text" name="{{inputnames.address.city}}"/></td></tr>
+ <tr><td>ZIP code:</td><td><input type="text" name="{{inputnames.address.zip}}"/></td></tr>
+ <tr><td>State:</td><td><input type="text" name="{{inputnames.address.state}}"/></td></tr>
+ <tr><td>Country:</td><td><select name="{{inputnames.address.country}}">
+ {% for ctry in countries %}
+ <option value="{{ctry.id}}">{{ctry.name}}</option>
+ {% endfor %}
+ </select></td></tr>
</table><p/>
<input type="submit" value="Create Account"/>
</form>