move change mail into its own transaction
authorkonrad <konrad@6e3c4bff-ac9f-4ac1-96c5-d2ea494d3e33>
Mon, 7 Feb 2011 21:14:58 +0000 (21:14 +0000)
committerkonrad <konrad@6e3c4bff-ac9f-4ac1-96c5-d2ea494d3e33>
Mon, 7 Feb 2011 21:14:58 +0000 (21:14 +0000)
git-svn-id: https://silmor.de/svn/softmagic/smoke/trunk@722 6e3c4bff-ac9f-4ac1-96c5-d2ea494d3e33

src/dialogs/customerdlg.cpp
wob/transact/customer.wolf
www/inc/wext/customer.php

index 2c1f843..b3839ab 100644 (file)
@@ -366,6 +366,11 @@ 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!=""){
+               MTChangeCustomerMail ccm=req->queryChangeCustomerMail(m_cust.customerid(),mail);
+               if(ccm.hasError()){
+                       QMessageBox::warning(this,tr("Warning"),tr("Unable to set new email: %1").arg(ccm.errorString()));
+                       return;
+               }
                m_mail->setText(mail);
                m_cust.setemail(mail);
        }
index e438fca..2710452 100644 (file)
@@ -59,7 +59,7 @@
        </Transaction>
        
        <Transaction name="ChangeCustomer">
-               <Doc>changes customer data</Doc>
+               <Doc>changes customer data (except online data)</Doc>
                <Input>
                        <Var name="customer" type="Customer"/>
                </Input>
                        <Var name="customer" type="Customer"/>
                </Output>
        </Transaction>
+
+       <Transaction name="ChangeCustomerMail">
+               <Doc>changes customer login data</Doc>
+               <Input>
+                       <Var name="customerid" type="int"/>
+                       <Var name="email" type="string"/>
+               </Input>
+               <Call lang="php" method="WOCustomer::changeCustomerMail($this);"/>
+               <Output>
+                       <Var name="customer" type="Customer"/>
+               </Output>
+       </Transaction>
        
        <Transaction name="DeleteCustomer">
                <Doc>deletes a customer - usually by merging info into another customer</Doc>
index 48e7cda..4dba57a 100644 (file)
@@ -65,6 +65,7 @@ class WOCustomer extends WOCustomerAbstract
                //create customer
                $cc->toTablecustomer($ct);
                $ct->revert("passwd");
+               $ct->revert("email");
                $ct->revert("rstcode");
                $ct->revert("rsttill");
                if($ct->isChanged())$ct->update();
@@ -245,6 +246,26 @@ class WOCustomer extends WOCustomerAbstract
                $trans->setcontacttype(WOContactType::fromTablecontacttype($tab));
        }
        
+       /**called from ChangeCustomerMail transaction*/
+       public static function changeCustomerMail($trans)
+       {
+               global $db;
+               $cc=$trans->getcustomerid();
+               $ct=WTcustomer::getFromDB($cc);
+               if(!is_a($ct,"WTcustomer")){
+                       $trans->abortWithError(tr("Customer does not exist in the database."));
+                       return;
+               }
+               //try to set new mail
+               $ct->email=$trans->getemail();
+               if(!$ct->update()){
+                       $trans->abortWithError(tr("This email already exists in the database."));
+                       return;
+               }
+               //set return value
+               $trans->setcustomer(WOCustomer::fromTablecustomer($ct));
+       }
+       
        ///the ResetCustomerPassword transaction
        public static function resetPassword($trans)
        {