more work on web order process
authorkonrad <konrad@6e3c4bff-ac9f-4ac1-96c5-d2ea494d3e33>
Mon, 10 Jan 2011 21:05:14 +0000 (21:05 +0000)
committerkonrad <konrad@6e3c4bff-ac9f-4ac1-96c5-d2ea494d3e33>
Mon, 10 Jan 2011 21:05:14 +0000 (21:05 +0000)
implement web login settings for gui

git-svn-id: https://silmor.de/svn/softmagic/smoke/trunk@705 6e3c4bff-ac9f-4ac1-96c5-d2ea494d3e33

17 files changed:
src/dialogs/customerdlg.cpp
src/dialogs/customerdlg.h
wob/db/customer.wolf
wob/transact/customer.wolf
www/inc/classes/autoload.php
www/inc/classes/basevars.php [new file with mode: 0644]
www/inc/global_functions.php
www/inc/loader_nonadmin.php
www/inc/rendering/cart_listing.php
www/inc/wext/customer.php
www/inc/wext/webcart.php
www/index.php
www/template/en/cart.html
www/template/en/loginerror.html [new file with mode: 0644]
www/template/en/orderlogin.html [new file with mode: 0644]
www/template/en/resetlogin.txt [new file with mode: 0644]
www/template/en/vouchers.html [new file with mode: 0644]

index 7a96063..2c1f843 100644 (file)
@@ -24,6 +24,7 @@
 #include <QLabel>
 #include <QLineEdit>
 #include <QListView>
+#include <QMenu>
 #include <QMessageBox>
 #include <QPushButton>
 #include <QSignalMapper>
@@ -227,6 +228,10 @@ MCustomerDialog::MCustomerDialog(MOCustomer c,QWidget*par)
        vl->addWidget(tab=new QTabWidget);
        tab->addTab(w=new QWidget,tr("Customer"));
        
+       QMenu*menu=new QMenu(this);
+       menu->addAction(tr("Change Mail Address"),this,SLOT(changeMail()));
+       menu->addAction(tr("Reset Password"),this,SLOT(resetLogin()));
+       
        w->setLayout(gl=new QGridLayout);
        int lc=0;
        gl->addWidget(new QLabel(tr("Name:")),lc,0);
@@ -239,7 +244,7 @@ MCustomerDialog::MCustomerDialog(MOCustomer c,QWidget*par)
        gl->addWidget(new QLabel(tr("Web-Login/eMail:")),++lc,0);
        gl->addWidget(m_mail=new QLabel(m_cust.email()),lc,1);
        gl->addWidget(p=new QPushButton(tr("Edit Login")),++lc,1);
-       p->setEnabled(false);//TODO: implement edit customer login
+       p->setMenu(menu);
        gl->setRowMinimumHeight(++lc,10);
        gl->addWidget(new QLabel(tr("Comment:")),++lc,0,1,2);
        gl->addWidget(m_comm=new QTextEdit,++lc,0,1,2);
@@ -356,6 +361,26 @@ void MCustomerDialog::save()
                m_cust=cc.getcustomer();
        }
 }
+
+void MCustomerDialog::changeMail()
+{
+       QString mail=QInputDialog::getText(this, tr("Change Mail Address"), tr("Please enter the mail address for this customer to log into the web portal:"),QLineEdit::Normal, m_mail->text());
+       if(mail!=""){
+               m_mail->setText(mail);
+               m_cust.setemail(mail);
+       }
+}
+
+void MCustomerDialog::resetLogin()
+{
+       MTResetCustomerPassword rcp=req->queryResetCustomerPassword(m_cust.customerid());
+       if(rcp.hasError())
+               QMessageBox::warning(this,tr("Warning"),tr("Error while resetting password: %1").arg(rcp.errorString()));
+       else
+               QMessageBox::information(this,tr("Password Reset"),tr("A password reset mail has been sent to the customer."));
+}
+
+
 /********************************************************************************/
 
 MContactTableDelegate::MContactTableDelegate(QObject*p)
index 0538f6c..97f77bf 100644 (file)
@@ -243,6 +243,10 @@ class MCustomerDialog:public QDialog
                void addContact();
                /**internal: remove contact*/
                void removeContact();
+               ///internal: change mail address
+               void changeMail();
+               ///internal: send a reset mail
+               void resetLogin();
                
        private:
                MOCustomer m_cust;
index f893ae9..d5d7de1 100644 (file)
                <!--online login data-->
                <Column name="email" type="string" null="yes"/>
                <Column name="passwd" type="string:64" null="yes"/> <!-- salted SHA-1 hash of passwd -->
+               <!-- password reset -->
+               <Column name="rstcode" type="string" null="yes"/>
+               <Column name="rsttill" type="int64" null="yes"/>
+               <!-- customer flags, like newsletter, etc. -->
+               <Column name="cflags" type="string" null="yes"/>
        </Table>
        <Table name="address" backup="yes">
                <Column name="addressid" type="seq64" primarykey="yes"/>
index 797e1c4..00af319 100644 (file)
                        <Var name="country" type="Country"/>
                </Output>
        </Transaction>
+       
+       <Transaction name="ResetCustomerPassword">
+               <Input>
+                       <Var name="customerid" type="int"/>
+               </Input>
+               <Call lang="php" method="WOCustomer::resetPassword($this);"/>
+       </Transaction>
 </Wolf>
\ No newline at end of file
index 54017a2..4c520c1 100644 (file)
@@ -7,4 +7,5 @@
 wob_autoclass('LanguageManager','./inc/classes/language_manager.php');
 wob_autoclass('ConfigManager','./inc/classes/config_manager.php');
 wob_autoclass('Websession','./inc/classes/websession.php');
+wob_autoclass('BaseVars','./inc/classes/basevars.php');
 ?>
\ No newline at end of file
diff --git a/www/inc/classes/basevars.php b/www/inc/classes/basevars.php
new file mode 100644 (file)
index 0000000..3c4155b
--- /dev/null
@@ -0,0 +1,152 @@
+<?
+// (c) Konrad Rosenbaum, 2011
+// protected under the GNU AGPL version 3 or at your option any newer
+// see COPYING.AGPL
+
+/** \page templates Templates
+\section tpl_base Base Variables
+
+There are some variables available for all templates.<p>
+
+\param script.* variables contain URLs for different modes of the web site:<br>
+<table frame="1" border="1">
+<tr><td><tt>script.root</tt></td><td>root URL for the index.php script</td></tr>
+<tr><td><tt>script.this</tt></td><td>the URL of the currently called script mode</td></tr>
+<tr><td><tt>script.index</tt></td><td>URL of the list index</td></tr>
+<tr><td><tt>script.eventDetails</tt></td><td>URL for event detail pages, append the event ID to it to complete it</td></tr>
+<tr><td><tt>script.eventOrder</tt></td><td>URL for ordering tickets for a specific event, arguments are expected as POST or GET parameters</td></tr>
+<tr><td><tt>script.vouchers</tt></td><td>URL for listing vouchers</td></tr>
+<tr><td><tt>script.voucherOrder</tt></td><td>URL for ordering vouchers, arguments are expected as POST or GET parameters</td></tr>
+<tr><td><tt>script.removeItem</tt></td><td>URL for removing tickets/vouchers/items from the cart, arguments are expected as POST or GET parameters</td></tr>
+<tr><td><tt>script.shop</tt></td><td>URL for listing shop items</td></tr>
+<tr><td><tt>script.cart</tt></td><td>URL of the cart, the cart must exist when calling it, otherwise a cookie error will be displayed</td></tr>
+<tr><td><tt>script.mycart</tt></td><td>URL of the cart that transparently creates the cart if it does not exist yet</td></tr>
+<tr><td><tt>script.checkout</tt></td><td>URL to check out the cart</td></tr>
+<tr><td><tt>script.setlanguage</tt></td><td>URL for setting the language cookie, add the language code to it to complete it</td></tr>
+</table><p>
+\param inputnames.* variables contain names for specific form input elements:<br>
+<table frame="1" border="1">
+<tr><td><tt>inputnames.amountTickets</tt></td><td>amount of tickets to be ordered</td></tr>
+<tr><td><tt>inputnames.event</tt></td><td>contains the event ID</td></tr>
+<tr><td><tt>inputnames.mode</tt></td><td>contains the display mode</td></tr>
+<tr><td><tt>inputnames.cartid</tt></td><td>ID of the cart of the current customer, usually the cart cookie is used instead</td></tr>
+</table><p>
+\param cartcookie variable contains the name of the cookie that contains the cart ID.<p>
+\param lang variable is an object of type LanguageManager - it represents translations done for the language the user has chosen.<p>
+
+
+\section tpl_error error.html
+
+This template is used whenever an error occurs during processing.
+
+\param ErrorText the text to be shown for an error
+\param ErrorTrace a full ASCII version of an exception trace. This is only filled if the <tt>$WebShowErrors</tt> option is set to <tt>true</tt> in the config.php file.
+**/
+
+class BaseVars{
+
+///if Twig is not yet initialized: initialize it, sets the $twig variable to the interpreter
+static public function initTwig(){
+       global $twig;
+       if(!isset($twig))self::initTwigPriv();
+}
+
+/// \internal actually initializes Twig
+static private function initTwigPriv()
+{
+       Twig_Autoloader::register();
+       global $loader,$twig,$twigoptions,$twigextensions;
+       $loader = new Twig_Loader_Filesystem(LanguageManager::singleton()->templateFolders());
+       $twig = new Twig_Environment($loader, $twigoptions );
+       foreach($twigextensions as $te){
+               $t='Twig_Extension_'.$te;
+               $twig->addExtension(new $t());
+       }
+       $twig->addExtension(new LangFilterExtension);
+       $twig->addExtension(new SmokeFilterExtension);
+}
+
+/// initializes the $basevars array
+public static function init(){
+       global $basevars;
+       if(!isset($basevars))self::initPriv();
+}
+
+/// \internal actually initializes $basevars
+public static function initPriv(){
+       global $basevars,$_SERVER,$BaseUrl;
+       self::initBaseUrlPriv();
+       //basic variables shared by all templates
+       // script URLs
+       $basevars['script']['root']=$BaseUrl;
+       $basevars['script']['this']=$BaseUrl;
+       if(isset($_SERVER['QUERY_STRING']) && $_SERVER['QUERY_STRING']!="")
+               $basevars['script']['this'].="?".$_SERVER['QUERY_STRING'];
+       $basevars['script']['index']=$BaseUrl."?mode=index";
+       $basevars['script']['eventDetails']=$BaseUrl."?mode=eventDetails&event=";
+       $basevars['script']['eventOrder']=$BaseUrl."?mode=eventOrder";
+       $basevars['script']['vouchers']=$BaseUrl."?mode=vouchers";
+       $basevars['script']['voucherOrder']=$BaseUrl."?mode=voucherOrder";
+       $basevars['script']['shop']=$BaseUrl."?mode=shop";
+       $basevars['script']['cart']=$BaseUrl."?mode=cart";
+       $basevars['script']['mycart']=$BaseUrl."?mode=mycart";
+       $basevars['script']['checkout']=$BaseUrl."?mode=checkout";
+       $basevars['script']['removeItem']=$BaseUrl."?mode=removeItem";
+       $basevars['script']['orderLogin']=$BaseUrl."?mode=orderLogin";
+       $basevars['script']['customerLogin']=$BaseUrl."?mode=customerLogin";
+       $basevars['script']['customerRegistration']=$BaseUrl."?mode=customerRegistration";
+       $basevars['script']['customerResetLogin']=$BaseUrl."?mode=customerResetLogin";
+       //$basevars['script']['orderOverview']=$BaseUrl."?mode=orderOverview";
+       //$basevars['script']['editShippingAddress']=$BaseUrl."?mode=editShippingAddress";
+       //$basevars['script']['editOrderComments']=$BaseUrl."?mode=editOrderComments";
+       $basevars['script']['setlanguage']=$BaseUrl."?mode=setlanguage&lang=";
+       // form elements
+       $basevars['inputnames']['amountTickets']="amountTickets";
+       $basevars['inputnames']['event']="event";
+       $basevars['inputnames']['ticket']="event";
+       $basevars['inputnames']['voucher']="voucher";
+       $basevars['inputnames']['mode']="mode";
+       $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']['firstname']='customer_firstname';
+       $basevars['inputnames']['login']['title']='customer_title';
+       //end of basevars
+}
+
+private static function initBaseUrlPriv(){
+       global $BaseUrl,$_SERVER;
+       //check whether it is already set
+       if(!isset($BaseUrl))$BaseUrl="";
+       if($BaseUrl!="")return;
+       //reconstruct
+       $BaseUrl="http";
+       // HTTPS?
+       if(isset($_SERVER["HTTPS"])){
+               if($_SERVER["HTTPS"]!="" && $_SERVER["HTTPS"]!="off")
+                       $BaseUrl.="s";
+       }
+       $BaseUrl.="://";
+       // host name
+       if(isset($_SERVER["SERVER_NAME"]))$BaseUrl.=$_SERVER["SERVER_NAME"];
+       else if(isset($_SERVER["HTTP_HOST"]))$BaseUrl.=$_SERVER["HTTP_HOST"];
+       else $BaseUrl="";//darn! no host found
+       // add path, correct machine.php to index.php
+       $pl=explode("/",$_SERVER["SCRIPT_NAME"]);
+       $path="";
+       $last=array_pop($pl);
+       foreach($pl as $p){
+               if($p=="")continue;
+               $path.="/".$p;
+       }
+       $pl=explode(".",$last);
+       if(count($pl)!=2)$path.="/".$last;
+       else $path.="/index.".$pl[1];
+       $BaseUrl.=$path;
+}
+
+//end of class
+}
+
+?>
\ No newline at end of file
index 8d56643..56c253f 100644 (file)
@@ -15,10 +15,11 @@ function isEmpty($var)
        return empty($var);
 }
 
-/** checks if given value is a valid email address */
+/** checks if given value is a valid email address 
+\returns true if the value has e-mail syntax */
 function isEmail($value)
 {
-       return ereg("^[a-zA-Z0-9\._-]+@[a-zA-Z0-9\._-]+$", $value);
+       return preg_match("/^[a-zA-Z0-9\._-]+@[a-zA-Z0-9\._-]+$/", $value) != false;
 }
 
 /**redirects the browser to index.php*/
@@ -43,4 +44,16 @@ function redirectHome(array $query=array())
        exit();
 }
 
+///redirects back to the referer page
+function redirectBack()
+{
+       global $_SERVER;
+       if(isset($_SERVER['HTTP_REFERER'])){
+               Header("Location: ".$_SERVER['HTTP_REFERER']);
+               exit();
+       }else{
+               redirectHome();
+       }
+}
+
 ?>
index 5cc3d69..50b95ee 100644 (file)
@@ -9,5 +9,14 @@ if(!$db->canUseDb())
        die("Database is not correctly configured. Giving up.");
 //TODO: convert random into class and move to framework
 include_once('./inc/classes/random.php');
+//load external Twig library
+require_once 'inc/Twig/Autoloader.php';
+
+//load web-UI specific class-files
+include('inc/classes/autoload.php');
+include("inc/rendering/autoload.php");
+//load globals
+include('inc/global_functions.php');
+
 
 ?>
\ No newline at end of file
index 8bc9679..8d8d146 100644 (file)
@@ -5,7 +5,8 @@
 // see COPYING.AGPL
 
 
-/** helper class wrapping Web Cart handling */
+/** helper class wrapping Web Cart handling logic,
+the class wrapping the tables is WOWebCart in wext/webcart.php */
 class WebCart{
 static private $cartid=false;
 
@@ -266,7 +267,7 @@ and \ref tpl_base Base Variables
 */
 static public function orderLoginPage()
 {
-       global $twig,$basevars;
+       global $twig,$basevars,$HTTPARGS;
        //get cart id and check it
        $cartid=self::getCart();
        if($cartid==""){
@@ -283,11 +284,81 @@ static public function orderLoginPage()
        }
        $list=$basevars;
        $list["cart"]=$cart;
+       $list["customer_name"]="";
+       if(isset($HTTPARGS["customer_name"]))
+               $list["customer_name"]=$HTTPARGS["customer_name"];
+       else{
+               $cust=$cart->getcustomer();
+               if(is_a($cust,"WOCustomer"))
+                       $list["customer_name"]=$cust->getemail();
+       }
        //display
        $p=$twig->loadTemplate("orderlogin.html");
        return $p->render($list);
 }
 
+
+/** \page templates Templates
+\section tpl_logerr Login Error
+
+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 backUrl the URL to call back to the login page
+*/
+
+///renders a login error page, see \ref tpl_logerr Login Error Template
+static private function loginError($errorType)
+{
+       global $basevars,$HTTPARGS,$SERVER,$twig;
+       //find some basics
+       $vars=$basevars;
+       $vars["errorType"]=$errorType;
+       //construct URL back to login page
+       if(isset($_SERVER["HTTP_REFERER"])){
+               $vars["backUrl"]=$_SERVER["HTTP_REFERER"];
+       }else{
+               $vars["backUrl"]=$basevars['script']['orderLogin'];
+       }
+       if(strstr($vars["backUrl"],"?")===false)
+               $vars["backUrl"].="?";
+       else
+               $vars["backUrl"].="&";
+       $idx=$basevars['inputnames']['login']['name'];
+       $vars["backUrl"].=$idx."=";
+       if(isset($HTTPARGS[$idx]))$vars["backUrl"].=$HTTPARGS[$idx];
+       //render page
+       $p=$twig->loadTemplate("loginerror.html");
+       return $p->render($vars);
+}
+
+///check the login of the customer, either forwards to the checkout page or shows the loginerror page
+static public function checkOrderLogin()
+{
+       global $HTTPARGS,$db,$basevars;
+       //find customer
+       $nameidx=$basevars['inputnames']['login']['name'];
+       $passidx=$basevars['inputnames']['login']['passwd'];
+       if(!isset($HTTPARGS[$nameidx]) || !isset($HTTPARGS[$passidx])){
+               return self::loginError("param");
+       }
+       $ct=WTcustomer::selectFromDB("email=".$db->escapeString($HTTPARGS[$nameidx]));
+       if(count($ct)<1){
+               return self::loginError("login");
+       }
+       //check password
+       $cust=WOCustomer::fromTablecustomer($ct[0]);
+       if(!$cust->checkPassword($HTTPARGS[$passidx])){
+               return self::loginError("login");
+       }
+}
+
+static public function registerCustomer()
+{
+       global $HTTPARGS;
+       
+}
+
 //end of WebCart
 };
 
index 8c78274..8ac2d02 100644 (file)
@@ -64,6 +64,9 @@ class WOCustomer extends WOCustomerAbstract
                }
                //create customer
                $cc->toTablecustomer($ct);
+               $ct->revert("passwd");
+               $ct->revert("rstcode");
+               $ct->revert("rsttill");
                if($ct->isChanged())$ct->update();
                //sync addresses
                foreach($cc->getaddresses() as $addr){
@@ -241,5 +244,52 @@ class WOCustomer extends WOCustomerAbstract
                //return
                $trans->setcontacttype(WOContactType::fromTablecontacttype($tab));
        }
+       
+       ///the ResetCustomerPassword transaction
+       public static function resetPassword($trans)
+       {
+               //check for customer
+               $ct=WTcustomer::getFromDB($trans->getcustomerid());
+               if(!is_a($ct,"WTcustomer")){
+                       $trans->abortWithError(tr("Not a valid customer."));
+                       return;
+               }
+               if(!isEmail($ct->email)){
+                       $trans->abortWithError(tr("Customer has no email address."));
+                       return;
+               }
+               //set reset parameters
+               global $CustomerResetTime,$MailFrom;
+               $ct->rstcode=getRandom(160);
+               $ct->rsttill=time()+$CustomerResetTime;
+               $ct->update();
+               //init twig
+               BaseVars::initTwig();
+               BaseVars::init();
+               //gather basics and render mail
+               global $twig,$basevars;
+               $p=$twig->loadTemplate("resetlogin.txt");
+               $list['customer']=WOCustomer::fromTablecustomer($ct);
+               $list['resetUrl']=$basevars['script']['customerResetLogin']
+                       ."&customer=".urlencode($ct->email)
+                       ."&passcode=".$ct->rstcode;
+               $list['passcode']=$ct->rstcode;
+               $page=explode("\n",trim($p->render($list)));
+               //parse mail
+               if(count($page)<2)return;
+               $subject=array_shift($page);
+               $mode=0;
+               $mailtext="";$mailheader="";
+               foreach($page as $line){
+                       if($mode==0){
+                               if(trim($line)=="")$mode=1;
+                               else $mailheader.=$line."\n";
+                       }else{
+                               $mailtext.=$line."\n";
+                       }
+               }
+               //send mail
+               mb_send_mail($ct->email,$subject,$mailtext,$mailheader);
+       }
 };
 ?>
\ No newline at end of file
index 7850ed9..a1772e0 100644 (file)
@@ -3,7 +3,8 @@
 // protected under the GNU AGPL version 3 or at your option any newer
 // see COPYING.AGPL
 
-
+///this is the class wrapping the cart tables,
+///the business logic class is WebCart in rendering/cart_listing.php
 class WOWebCart extends WOWebCartAbstract
 {
        /**returns is empty attribute for twig*/
index d6dde21..bd7f2ef 100644 (file)
@@ -7,14 +7,6 @@
 //basics
 include('inc/loader.php');
 include('inc/loader_nonadmin.php');
-//load web-UI specific class-files
-include('inc/classes/autoload.php');
-include("inc/rendering/autoload.php");
-//load external Twig library
-require_once 'inc/Twig/Autoloader.php';
-Twig_Autoloader::register();
-//load globals
-include('inc/global_functions.php');
 
 //unify arguments
 $HTTPARGS=$_GET;
@@ -30,89 +22,10 @@ if(isset($_GET["mode"])){
 Session::setWebSession();
 
 //initialize TWIG
-$loader = new Twig_Loader_Filesystem(LanguageManager::singleton()->templateFolders());
-$twig = new Twig_Environment($loader, $twigoptions );
-foreach($twigextensions as $te){
-       $t='Twig_Extension_'.$te;
-       $twig->addExtension(new $t());
-}
-$twig->addExtension(new LangFilterExtension);
-$twig->addExtension(new SmokeFilterExtension);
-
-
-/** \page templates Templates
-\section tpl_base Base Variables
-
-There are some variables available for all templates.<p>
-
-\param script.* variables contain URLs for different modes of the web site:<br>
-<table frame="1" border="1">
-<tr><td><tt>script.root</tt></td><td>root URL for the index.php script</td></tr>
-<tr><td><tt>script.this</tt></td><td>the URL of the currently called script mode</td></tr>
-<tr><td><tt>script.index</tt></td><td>URL of the list index</td></tr>
-<tr><td><tt>script.eventDetails</tt></td><td>URL for event detail pages, append the event ID to it to complete it</td></tr>
-<tr><td><tt>script.eventOrder</tt></td><td>URL for ordering tickets for a specific event, arguments are expected as POST or GET parameters</td></tr>
-<tr><td><tt>script.vouchers</tt></td><td>URL for listing vouchers</td></tr>
-<tr><td><tt>script.voucherOrder</tt></td><td>URL for ordering vouchers, arguments are expected as POST or GET parameters</td></tr>
-<tr><td><tt>script.removeItem</tt></td><td>URL for removing tickets/vouchers/items from the cart, arguments are expected as POST or GET parameters</td></tr>
-<tr><td><tt>script.shop</tt></td><td>URL for listing shop items</td></tr>
-<tr><td><tt>script.cart</tt></td><td>URL of the cart, the cart must exist when calling it, otherwise a cookie error will be displayed</td></tr>
-<tr><td><tt>script.mycart</tt></td><td>URL of the cart that transparently creates the cart if it does not exist yet</td></tr>
-<tr><td><tt>script.checkout</tt></td><td>URL to check out the cart</td></tr>
-<tr><td><tt>script.setlanguage</tt></td><td>URL for setting the language cookie, add the language code to it to complete it</td></tr>
-</table><p>
-\param inputnames.* variables contain names for specific form input elements:<br>
-<table frame="1" border="1">
-<tr><td><tt>inputnames.amountTickets</tt></td><td>amount of tickets to be ordered</td></tr>
-<tr><td><tt>inputnames.event</tt></td><td>contains the event ID</td></tr>
-<tr><td><tt>inputnames.mode</tt></td><td>contains the display mode</td></tr>
-<tr><td><tt>inputnames.cartid</tt></td><td>ID of the cart of the current customer, usually the cart cookie is used instead</td></tr>
-</table><p>
-\param cartcookie variable contains the name of the cookie that contains the cart ID.<p>
-\param lang variable is an object of type LanguageManager - it represents translations done for the language the user has chosen.<p>
-
-
-\section tpl_error error.html
-
-This template is used whenever an error occurs during processing.
-
-\param ErrorText the text to be shown for an error
-\param ErrorTrace a full ASCII version of an exception trace. This is only filled if the <tt>$WebShowErrors</tt> option is set to <tt>true</tt> in the config.php file.
-**/
+BaseVars::initTwig();
 
-//basic variables shared by all templates
-// script URLs
-$basevars['script']['root']=$_SERVER['SCRIPT_NAME'];
-$basevars['script']['this']=$_SERVER['REQUEST_URI'];
-$basevars['script']['index']=$_SERVER['SCRIPT_NAME']."?mode=index";
-$basevars['script']['eventDetails']=$_SERVER['SCRIPT_NAME']."?mode=eventDetails&event=";
-$basevars['script']['eventOrder']=$_SERVER['SCRIPT_NAME']."?mode=eventOrder";
-$basevars['script']['vouchers']=$_SERVER['SCRIPT_NAME']."?mode=vouchers";
-$basevars['script']['voucherOrder']=$_SERVER['SCRIPT_NAME']."?mode=voucherOrder";
-$basevars['script']['shop']=$_SERVER['SCRIPT_NAME']."?mode=shop";
-$basevars['script']['cart']=$_SERVER['SCRIPT_NAME']."?mode=cart";
-$basevars['script']['mycart']=$_SERVER['SCRIPT_NAME']."?mode=mycart";
-$basevars['script']['checkout']=$_SERVER['SCRIPT_NAME']."?mode=checkout";
-$basevars['script']['removeItem']=$_SERVER['SCRIPT_NAME']."?mode=removeItem";
-$basevars['script']['orderLogin']=$_SERVER['SCRIPT_NAME']."?mode=orderLogin";
-$basevars['script']['customerLogin']=$_SERVER['SCRIPT_NAME']."?mode=customerLogin";
-$basevars['script']['customerRegistration']=$_SERVER['SCRIPT_NAME']."?mode=customerRegistration";
-//$basevars['script']['orderOverview']=$_SERVER['SCRIPT_NAME']."?mode=orderOverview";
-//$basevars['script']['editShippingAddress']=$_SERVER['SCRIPT_NAME']."?mode=editShippingAddress";
-//$basevars['script']['editOrderComments']=$_SERVER['SCRIPT_NAME']."?mode=editOrderComments";
-$basevars['script']['setlanguage']=$_SERVER['SCRIPT_NAME']."?mode=setlanguage&lang=";
-// form elements
-$basevars['inputnames']['amountTickets']="amountTickets";
-$basevars['inputnames']['event']="event";
-$basevars['inputnames']['ticket']="event";
-$basevars['inputnames']['voucher']="voucher";
-$basevars['inputnames']['mode']="mode";
-$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']['firstname']='customer_firstname';
-$basevars['inputnames']['login']['title']='customer_title';
+//initialize basevars
+BaseVars::init();
 $basevars['inputnames']['cartid']=WebCart::cartIdName;
 $basevars['cartcookie']=WebCart::cartIdName;
 // other info
@@ -147,7 +60,6 @@ try{
                        WebCart::addVoucher();
                        break;
                case "shop":
-                       //TODO: implement
                        redirectHome();
                        break;
                case "checkout":
@@ -157,10 +69,10 @@ try{
                        $page=WebCart::orderLoginPage();
                        break;
                case "customerLogin":
-                       WebCart::checkOrderLogin();
+                       $page=WebCart::checkOrderLogin();
                        break;
                case "customerRegistration":
-                       WebCart::registerUser();
+                       $page=WebCart::registerCustomer();
                        break;
 /*             case "orderOverview":
                        orderTickets();
index ed81349..071f1cb 100644 (file)
@@ -23,7 +23,7 @@
   {% for ticket in cart.tickets %}
     {% set pricesum=ticket.price * ticket.amount %}
     <tr>
-    <td>Ticket: {{ticket.event.title}}</td>
+    <td>Ticket: {{ticket.event.title}} ({{ticket.eventprice.pricecategory.name}})</td>
     <td align="right">{{ticket.price|asMoney}}</td>
     <td align="right">{{ticket.amount}}</td>
     <td align="right">{{pricesum|asMoney}}</td>
@@ -63,7 +63,7 @@
   </table>
   
   {# actions the user may want to take #}
-  <p><a href="{{script.checkout}}">Checkout</a></p>
+  <p><a href="{{script.orderLogin}}">Checkout</a></p>
   
   {# end of the non-empty cart... #}
  {% endif %}
diff --git a/www/template/en/loginerror.html b/www/template/en/loginerror.html
new file mode 100644 (file)
index 0000000..968a459
--- /dev/null
@@ -0,0 +1,12 @@
+<html>
+<title>Login Error</title>
+<body>
+<h1>Login Error</h1>
+
+Error Type: {{errorType}}<p/>
+
+<a href="{{backUrl|raw}}">Try Again</a><p>
+
+<hr/>
+<a href="{{script.root}}">Back to Index</a>
+</html>
\ No newline at end of file
diff --git a/www/template/en/orderlogin.html b/www/template/en/orderlogin.html
new file mode 100644 (file)
index 0000000..33c126f
--- /dev/null
@@ -0,0 +1,89 @@
+{# Example Template for MagicSmoke
+   ================================
+   this one is called to show the login page for a customer
+#}
+{% extends 'layout.html' %}
+
+{% block title %}Login{% endblock %}
+
+{% block page %}
+<input type="radio" name="loginselect" value="use" onClick="toggledisplay()" id="loginselect" checked="1"/>I already have an account:<p/>
+
+{# the login dialog #}
+<div id="usediv">
+  <form action="{{script.customerLogin}}&next=checkout" method="POST">
+    <table>
+    <tr><td>E-mail address:</td><td><input type="text" name="{{inputnames.login.name}}" value="{{customer_name}}" /></td></tr>
+    <tr><td>Password:</td><td><input type="password" name="{{inputnames.login.passwd}}"/></td></tr>
+    </table><p/>
+    <input type="submit" value="Login"/>
+  </form><p/>
+</div>
+
+<input type="radio" name="loginselect" value="create" onClick="toggledisplay()"/>I do not have have an account yet: <p/>
+
+{# the create account dialog #}
+<div id="creatediv">
+  <form action="{{script.customerRegistration}}&next=checkout" method="POST">
+    <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/>
+    <table>
+    <tr><td>Title:</td><td>
+     <input type="text" name="{{inputnames.login.title}}" id="titleinput" width="6" />
+     <img src="images/arrowdown.png" onclick="showTitles()"/>
+     <div id="titlediv" class="titlediv">
+      <a href="javascript:void selectTitle('Mr.')">Mr.</a><br/>
+      <a href="javascript:void selectTitle('Mrs.')">Mrs.</a><br/>
+      <a href="javascript:void selectTitle('Herr')">Herr</a><br/>
+      <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>First Name:</td><td><input type="text" name="{{inputnames.login.firstname}}"/></td></tr>
+    </table><p/>
+    <input type="submit" value="Create Account"/>
+  </form>
+</div>
+
+<p/><hr/>
+{# in any case: allow the user to shop some more... #}
+<p><a href="{{script.root}}">Abort and Continue Shopping</a></p>
+
+{# helper JavaScript: makes one or the other dialog visible #}
+<script type="text/javascript">
+<!-- // Hide script from old browsers
+//makes the two main divs visible or invisible, used by toggledisplay
+function showDiv(use,creat)
+{
+  document.getElementById("usediv").style.display = use;
+  document.getElementById("creatediv").style.display = creat;
+}
+//called when one of the outer radio buttons is clicked:
+//finds out which div should be visible
+function toggledisplay()
+{
+  var sel=document.getElementById("loginselect");
+  if(sel.checked)
+         showDiv("block","none");
+  else
+         showDiv("none","block");
+}
+//initial view
+toggledisplay();
+
+function showTitles()
+{
+  document.getElementById("titlediv").style.display="block";
+}
+function selectTitle(title)
+{
+  document.getElementById("titlediv").style.display="none";
+  document.getElementById("titleinput").value=title;
+}
+//end of hiding -->
+</script>
+
+{% endblock page %}
diff --git a/www/template/en/resetlogin.txt b/www/template/en/resetlogin.txt
new file mode 100644 (file)
index 0000000..14eecaa
--- /dev/null
@@ -0,0 +1,22 @@
+{#
+This template contains the mail sent to a customer
+when he/she requests a password reset.
+
+The first non-empty line contains the subject,
+subsequent lines contain the headers, then an empty line
+and after that the body of the mail.
+#}
+Password Reset at MagicSmoke.silmor.de
+From: no-reply@localdomain.com
+
+Hello {{customer.title}} {{customer.name}}!
+
+You or someone else requested to change your password.
+If you do intend to change your password please click the
+link below within the next 24 hours and enter a new password 
+on the page you will see.
+
+If you do not intend to change your password please ignore
+this mail.
+
+{{resetUrl|raw}}
\ No newline at end of file
diff --git a/www/template/en/vouchers.html b/www/template/en/vouchers.html
new file mode 100644 (file)
index 0000000..518285b
--- /dev/null
@@ -0,0 +1,25 @@
+{# Example Template for MagicSmoke
+   ================================
+   this one is called to create the voucher order page
+#}
+{% extends 'layout.html' %}
+
+{% block title %}Order Vouchers{% endblock %}
+
+{% block page %}
+<form action="{{script.voucherOrder}}" method="POST">
+ Please select a voucher price:
+ <select name="{{inputnames.voucher}}">
+  {% for i in voucherprices %}
+   <option value="{{i}}">{{i|asMoney}}</option>
+  {% endfor %}
+ </select>
+ {# end of the form... just add a button... #}
+ <input type="submit" value="add to cart" />
+</form>
+<p>
+
+{# in any case: allow the user to shop some more... #}
+<p><a href="{{script.root}}">Continue Shopping</a></p>
+
+{% endblock page %}