diff --git a/library/WsScore/Pieces/v0.1/Pieces.php b/library/WsScore/Pieces/v0.1/Pieces.php index bffedfd7..6a1cf2e0 100644 --- a/library/WsScore/Pieces/v0.1/Pieces.php +++ b/library/WsScore/Pieces/v0.1/Pieces.php @@ -627,4 +627,154 @@ class Pieces extends WsScore return $output; } + /** + * Set an email associated to the command + * @param string $id + * @param string $email + * @throws SoapFault + * @return boolean + */ + public function setActeCmdEmail($id, $email) + { + $this->authenticate(); + $this->permission('actes'); + + $validator = new Zend_Validate_EmailAddress(); + if ( !$validator->isValid($email) ){ + throw new SoapFault('ERR', "Adresse email invalide."); + } + + $commandeM = new Application_Model_Sdv1GreffeCommandesAc(); + $sql = $commandeM->select() + ->where('login=?', $this->tabInfoUser['login']) + ->where('refCommande=?', $id); + try { + $result = $commandeM->fetchRow($sql); + } catch (Zend_Db_Exception $e) { + if ($this->tabInfoUser['idClient']==1) { + throw new SoapFault('ERR', $e->getMessage()); + } else { + throw new SoapFault('ERR', "Application error"); + } + } + if ( $result !== null ) { + if ( is_int($email) ) { + //Id of secondary email + } else { + $dataUpdate = array('email' => $email); + try { + $commandeM->update($dataUpdate, "refCommande='".$id."'"); + return true; + } catch (Zend_Db_Exception $e) { + if ($this->tabInfoUser['idClient']==1) { + throw new SoapFault('ERR', $e->getMessage()); + } else { + throw new SoapFault('ERR', "Application error"); + } + } + } + } + + return false; + } + + /** + * Set an email associated to the command + * @param string $id + * @param string $email + * @throws SoapFault + * @return boolean + */ + public function setBilanCmdEmail($id, $email) + { + $this->authenticate(); + $this->permission('actes'); + + $validator = new Zend_Validate_EmailAddress(); + if ( !$validator->isValid($email) ){ + throw new SoapFault('ERR', "Adresse email invalide."); + } + + $commandeM = new Application_Model_Sdv1GreffeCommandesAc(); + $sql = $commandeM->select() + ->where('login=?', $this->tabInfoUser['login']) + ->where('refCommande=?', $id); + try { + $result = $commandeM->fetchRow($sql); + } catch (Zend_Db_Exception $e) { + if ($this->tabInfoUser['idClient']==1) { + throw new SoapFault('ERR', $e->getMessage()); + } else { + throw new SoapFault('ERR', "Application error"); + } + } + if ( $result !== null ) { + if ( is_int($email) ) { + //Id of secondary email + } else { + $dateUpdate = array('email' => $email); + try { + $commandeM->update($dataUpdate, "refCommande='".$id."'"); + return true; + } catch (Zend_Db_Exception $e) { + if ($this->tabInfoUser['idClient']==1) { + throw new SoapFault('ERR', $e->getMessage()); + } else { + throw new SoapFault('ERR', "Application error"); + } + } + } + } + return false; + } + + /** + * Set an email associated to the command + * @param string $id + * @param string $email + * @throws SoapFault + * @return boolean + */ + public function setKbisCmdEmail($id, $email) + { + $this->authenticate(); + $this->permission('KBIS'); + + $validator = new Zend_Validate_EmailAddress(); + if ( !$validator->isValid($email) ){ + throw new SoapFault('ERR', "Adresse email invalide."); + } + + $commandeM = new Application_Model_Sdv1GreffeCommandesAc(); + $sql = $commandeM->select() + ->where('login=?', $this->tabInfoUser['login']) + ->where('refCommande=?', $id); + try { + $result = $commandeM->fetchRow($sql); + } catch (Zend_Db_Exception $e) { + if ($this->tabInfoUser['idClient']==1) { + throw new SoapFault('ERR', $e->getMessage()); + } else { + throw new SoapFault('ERR', "Application error"); + } + } + if ( $result !== null ) { + if ( is_int($email) ) { + //Id of secondary email + } else { + $dateUpdate = array('email' => $email); + try { + $commandeM->update($dataUpdate, "refCommande='".$id."'"); + return true; + } catch (Zend_Db_Exception $e) { + if ($this->tabInfoUser['idClient']==1) { + throw new SoapFault('ERR', $e->getMessage()); + } else { + throw new SoapFault('ERR', "Application error"); + } + } + } + } + return false; + } } \ No newline at end of file