@ -1,4 +1,5 @@
package controller ;
import Common ;
import haxe . Utf8 ;
import sugoi . form . Form ;
@ -6,14 +7,11 @@ import sugoi.form.elements.Selectbox;
import sugoi . form . validators . EmailValidator ;
import sugoi . tools . Utils ;
class Member extends Controller
{
public function n e w ( )
{
class Member extends Controller {
public function n e w ( ) {
super ( ) ;
if ( ! app . user . canAccessMembership ( ) ) throw Redirect ( " / " ) ;
if ( ! app . user . canAccessMembership ( ) )
throw Redirect ( " / " ) ;
}
@ logged
@ -25,65 +23,73 @@ class Member extends Controller
var uids = db . UserAmap . manager . search ( $amap == app . user . getAmap ( ) , false ) ;
var uids = Lambda . map ( uids , function ( ua ) return ua . user . id ) ;
if ( args != null && args . search != null ) {
// SEARCH
browse = function ( index : Int , limit : Int ) {
var search = " % " + StringTools . trim ( args . search ) + " % " ;
return db . User . manager . search (
( $lastName . like ( search ) ||
$lastName2 . like ( search ) ||
$address1 . like ( search ) ||
$address2 . like ( search ) ||
$firstName . like ( search ) ||
$firstName2 . like ( search )
) & & $id in uids , { orderBy : - id } , false ) ;
return db . User . manager . search ( ( $lastName . like ( search ) || $lastName2 . like ( search ) || $address1 . like ( search ) || $address2 . like ( search )
| | $firstName . like ( search ) || $firstName2 . like ( search ) )
& & $id in uids ,
{
orderBy : - id
} , false ) ;
}
view . search = args . search ;
} e lse if ( args != null && args . select != null ) {
// SELECTION
switch ( args . select ) {
c ase " n o c o n t r a c t " :
if ( app . params . exists ( " c s v " ) ) {
sugoi . tools . Csv . printCsvDataFromObjects ( Lambda . array ( db . User . getUsers_NoContracts ( ) ) , [ " f i r s t N a m e " , " l a s t N a m e " , " e m a i l " ] , t . _ ( " W i t h o u t c o n t r a c t s " ) ) ;
sugoi . tools . Csv . printCsvDataFromObjects ( Lambda . array ( db . User . getUsers_NoContracts ( ) ) , [ " f i r s t N a m e " , " l a s t N a m e " , " e m a i l " ] ,
t . _ ( " W i t h o u t c o n t r a c t s " ) ) ;
return ;
} e lse {
browse = function ( index : Int , limit : Int ) { return db . User . getUsers_NoContracts ( index , limit ) ; }
browse = function ( index : Int , limit : Int ) {
return db . User . getUsers_NoContracts ( index , limit ) ;
}
}
c ase " c o n t r a c t " :
if ( app . params . exists ( " c s v " ) ) {
sugoi . tools . Csv . printCsvDataFromObjects ( Lambda . array ( db . User . getUsers_Contracts ( ) ) , [ " f i r s t N a m e " , " l a s t N a m e " , " e m a i l " ] , t . _ ( " W i t h o r d e r s " ) ) ;
sugoi . tools . Csv . printCsvDataFromObjects ( Lambda . array ( db . User . getUsers_Contracts ( ) ) , [ " f i r s t N a m e " , " l a s t N a m e " , " e m a i l " ] ,
t . _ ( " W i t h o r d e r s " ) ) ;
return ;
} e lse {
browse = function ( index : Int , limit : Int ) { return db . User . getUsers_Contracts ( index , limit ) ; }
browse = function ( index : Int , limit : Int ) {
return db . User . getUsers_Contracts ( index , limit ) ;
}
}
c ase " n o m e m b e r s h i p " :
if ( app . params . exists ( " c s v " ) ) {
sugoi . tools . Csv . printCsvDataFromObjects ( Lambda . array ( db . User . getUsers_NoMembership ( ) ) , [ " f i r s t N a m e " , " l a s t N a m e " , " e m a i l " ] , t . _ ( " M e m b e r s h i p s t o b e r e n e w e d " ) ) ;
sugoi . tools . Csv . printCsvDataFromObjects ( Lambda . array ( db . User . getUsers_NoMembership ( ) ) , [ " f i r s t N a m e " , " l a s t N a m e " , " e m a i l " ] ,
t . _ ( " M e m b e r s h i p s t o b e r e n e w e d " ) ) ;
return ;
} e lse {
browse = function ( index : Int , limit : Int ) { return db . User . getUsers_NoMembership ( index , limit ) ; }
browse = function ( index : Int , limit : Int ) {
return db . User . getUsers_NoMembership ( index , limit ) ;
}
}
c ase " n e w u s e r s " :
if ( app . params . exists ( " c s v " ) ) {
sugoi . tools . Csv . printCsvDataFromObjects ( Lambda . array ( db . User . getUsers_NewUsers ( ) ) , [ " f i r s t N a m e " , " l a s t N a m e " , " e m a i l " ] , t . _ ( " N e v e r c o n n e c t e d " ) ) ;
sugoi . tools . Csv . printCsvDataFromObjects ( Lambda . array ( db . User . getUsers_NewUsers ( ) ) , [ " f i r s t N a m e " , " l a s t N a m e " , " e m a i l " ] ,
t . _ ( " N e v e r c o n n e c t e d " ) ) ;
return ;
} e lse {
browse = function ( index : Int , limit : Int ) { return db . User . getUsers_NewUsers ( index , limit ) ; }
browse = function ( index : Int , limit : Int ) {
return db . User . getUsers_NewUsers ( index , limit ) ;
}
}
d efault :
throw t . _ ( " U n k n o w n s e l e c t i o n " ) ;
}
view . select = args . select ;
} e lse {
if ( app . params . exists ( " c s v " ) ) {
var headers = [ " f i r s t N a m e " , " l a s t N a m e " , " e m a i l " , " p h o n e " , " f i r s t N a m e 2 " , " l a s t N a m e 2 " , " e m a i l 2 " , " p h o n e 2 " , " a d d r e s s 1 " , " a d d r e s s 2 " , " z i p C o d e " , " c i t y " ] ;
sugoi . tools . Csv . printCsvDataFromObjects ( Lambda . array ( db . User . manager . search ( $id in uids , { orderBy : lastName } , false ) ) , headers , t . _ ( " M e m b e r s " ) ) ;
var headers = [
" f i r s t N a m e " , " l a s t N a m e " , " e m a i l " , " p h o n e " , " f i r s t N a m e 2 " , " l a s t N a m e 2 " , " e m a i l 2 " , " p h o n e 2 " , " a d d r e s s 1 " , " a d d r e s s 2 " , " z i p C o d e " , " c i t y "
] ;
sugoi . tools . Csv . printCsvDataFromObjects ( Lambda . array ( db . User . manager . search ( $id in uids , { orderBy : lastName } , false ) ) , headers ,
t . _ ( " M e m b e r s " ) ) ;
return ;
} e lse {
// default display
@ -103,14 +109,12 @@ class Member extends Controller
}
view . waitingList = db . WaitingList . manager . count ( $group == app . user . amap ) ;
}
/ * *
* Move to waiting list
* /
function doMovetowl ( u : db . User ) {
var ua = db . UserAmap . get ( u , app . user . amap , true ) ;
ua . delete ( ) ;
@ -120,8 +124,6 @@ class Member extends Controller
wl . insert ( ) ;
throw Ok ( " / m e m b e r " , u . getName ( ) + " " + t . _ ( " i s n o w o n w a i t i n g l i s t . " ) ) ;
}
/ * *
@ -129,18 +131,13 @@ class Member extends Controller
* /
@ tpl ( ' m e m b e r / w a i t i n g . m t t ' )
function doWaiting ( ? args : { ? add : db . User , ? remove : db . User } ) {
if ( args != null ) {
if ( args . add != null ) {
service . WaitingListService . approveRequest ( args . add , app . user . amap ) ;
throw Ok ( " / m e m b e r / w a i t i n g " , t . _ ( " M e m b e r s h i p r e q u e s t a c c e p t e d " ) ) ;
} e lse if ( args . remove != null ) {
service . WaitingListService . cancelRequest ( args . remove , app . user . amap ) ;
throw Ok ( " / m e m b e r / w a i t i n g " , t . _ ( " M e m b e r s h i p r e q u e s t r e f u s e d " ) ) ;
}
}
@ -151,21 +148,17 @@ class Member extends Controller
* Send an invitation to a new member
* /
function doInviteMember ( u : db . User ) {
if ( checkToken ( ) ) {
u . sendInvitation ( app . user . amap ) ;
throw Ok ( ' / m e m b e r / v i e w / ' + u . id , t . _ ( " I n v i t a t i o n s e n t . " ) ) ;
}
}
/ * *
* Invite ' n e v e r l o g g e d ' users
* /
function doInvite ( ) {
if ( checkToken ( ) ) {
var users = db . User . getUsers_NewUsers ( ) ;
try {
for ( u in users ) {
@ -181,16 +174,14 @@ class Member extends Controller
throw Ok ( ' / m e m b e r ' , t . _ ( " C o n g r a t u l a t i o n s , y o u j u s t s e n t < b > : : u s e r L e n g t h : : < / b > i n v i t a t i o n s " , { userLength : users . length } ) ) ;
}
}
@ tpl ( " m e m b e r / v i e w . m t t " )
function doView ( member : db . User ) {
view . member = member ;
var userAmap = db . UserAmap . get ( member , app . user . amap ) ;
if ( userAmap == null ) throw Error ( " / m e m b e r " , t . _ ( " T h i s p e r s o n d o e s n o t b e l o n g t o y o u r g r o u p " ) ) ;
if ( userAmap == null )
throw Error ( " / m e m b e r " , t . _ ( " T h i s p e r s o n d o e s n o t b e l o n g t o y o u r g r o u p " ) ) ;
view . userAmap = userAmap ;
view . canLoginAs = ( db . UserAmap . manager . count ( $userId == member . id ) == 1 && app . user . isAmapManager ( ) ) || app . user . isAdmin ( ) ;
@ -199,12 +190,16 @@ class Member extends Controller
var row = { constOrders : new Array < UserOrder > ( ) , varOrders : new Map < String , Array < UserOrder > > ( ) } ;
// commandes fixes
var contracts = db . Contract . manager . search ( $type == db . Contract . TYPE_CONSTORDERS && $amap == app . user . amap && $endDate > DateTools . delta ( Date . now ( ) , - 1000.0 * 60 * 60 * 24 * 30 ) , false ) ;
var contracts = db . Contract . manager . search ( $type == db . Contract . TYPE_CONSTORDERS
& & $amap == app . user . amap
& & $endDate > DateTools . delta ( Date . now ( ) , - 1000.0 * 60 * 60 * 24 * 30 ) , false ) ;
var orders = member . getOrdersFromContracts ( contracts ) ;
row . constOrders = service . OrderService . prepare ( orders ) ;
// commandes variables groupées par date de distrib
var contracts = db . Contract . manager . search ( $type == db . Contract . TYPE_VARORDER && $amap == app . user . amap && $endDate > DateTools . delta ( Date . now ( ) , - 1000.0 * 60 * 60 * 24 * 30 ) , false ) ;
var contracts = db . Contract . manager . search ( $type == db . Contract . TYPE_VARORDER
& & $amap == app . user . amap
& & $endDate > DateTools . delta ( Date . now ( ) , - 1000.0 * 60 * 60 * 24 * 30 ) , false ) ;
var distribs = new Map < String , List < db . UserContract > > ( ) ;
for ( c in contracts ) {
var ds = c . getDistribs ( ) ;
@ -215,9 +210,9 @@ class Member extends Controller
if ( ! distribs . exists ( k ) ) {
distribs . set ( k , orders ) ;
} e lse {
var v = distribs . get ( k ) ;
for ( o in orders ) v . add ( o ) ;
for ( o in orders )
v . add ( o ) ;
distribs . set ( k , v ) ;
}
}
@ -229,10 +224,8 @@ class Member extends Controller
row . varOrders . set ( k , d2 ) ;
}
view . userContracts = row ;
checkToken ( ) ; // to insert a token in tpl
}
/ * *
@ -241,12 +234,13 @@ class Member extends Controller
* @ param amap
* /
function doLoginas ( member : db . User , amap : db . Amap ) {
if ( ! app . user . isAdmin ( ) ) {
if ( ! app . user . isAmapManager ( ) ) return ;
if ( member . isAdmin ( ) ) return ;
if ( db . UserAmap . manager . count ( $userId == member . id ) > 1 ) return ;
if ( ! app . user . isAmapManager ( ) )
return ;
if ( member . isAdmin ( ) )
return ;
if ( db . UserAmap . manager . count ( $userId == member . id ) > 1 )
return ;
}
App . current . session . setUser ( member ) ;
@ -256,20 +250,26 @@ class Member extends Controller
@ tpl ( ' m e m b e r / l a s t M e s s a g e s . m t t ' )
function doLastMessages ( member : db . User ) {
var out = new Array < { date : Date , subject : String , success : String , failure : String } > ( ) ;
var out = new Array < {
date : Date ,
subject : String ,
success : String ,
failure : String
} > ( ) ;
var threeMonth = DateTools . delta ( Date . now ( ) , - 1000.0 * 60 * 60 * 24 * 30.5 * 3 ) ;
for ( m in sugoi . db . BufferedMail . manager . search ( $remoteId == app . user . amap . id && $cdate > threeMonth , { limit : 10 , orderBy : - cdate } ) ) {
var status: sugoi . mail . IMailer . MailerResult = m . status ;
if ( status != null && status . get ( member . email ) != null ) {
var r = m . getMailerResultMessage ( member . email ) ;
out . push ( { date : m . cdate , subject : m . title , success : r . success , failure : r . failure } ) ;
out . push ( {
date : m . cdate ,
subject : m . title ,
success : r . success ,
failure : r . failure
} ) ;
}
}
view . emails = out ;
}
@ -279,8 +279,8 @@ class Member extends Controller
* /
@ tpl ( ' f o r m . m t t ' )
function doEdit ( member : db . User ) {
if ( member . isAdmin ( ) && ! app . user . isAdmin ( ) ) throw Error ( " / " , t . _ ( " Y o u c a n n o t m o d i f y t h e a c c o u n t o f a n a d m i n i s t r a t o r " ) ) ;
if ( member . isAdmin ( ) && ! app . user . isAdmin ( ) )
throw Error ( " / " , t . _ ( " Y o u c a n n o t m o d i f y t h e a c c o u n t o f a n a d m i n i s t r a t o r " ) ) ;
var form = sugoi . form . Form . fromSpod ( member ) ;
@ -290,7 +290,6 @@ class Member extends Controller
form . removeElement ( form . getElement ( " l d a t e " ) ) ;
form . removeElement ( form . getElement ( " a p i K e y " ) ) ;
var isReg = member . isFullyRegistred ( ) ;
var groupNum = db . UserAmap . manager . count ( $userId == member . id ) ;
@ -310,7 +309,6 @@ class Member extends Controller
}
if ( form . checkToken ( ) ) {
if ( app . user . amap . flags . has ( db . Amap . AmapFlags . PhoneRequired ) && form . getValueOf ( " p h o n e " ) == null ) {
throw Error ( " / m e m b e r / e d i t / " + member . id , t . _ ( " P h o n e n u m b e r i s r e q u i r e d i n t h i s g r o u p . " ) ) ;
}
@ -320,17 +318,16 @@ class Member extends Controller
// check that the given emails are not already used elsewhere
var sim = db . User . getSameEmail ( member . email , member . email2 ) ;
for ( s in sim ) {
if ( s . id == member . id ) sim . remove ( s ) ;
if ( s . id == member . id )
sim . remove ( s ) ;
}
if ( sim . length > 0 ) {
// Let's merge the 2 users if it has no orders.
var id = sim . first ( ) . id ;
if ( db . UserContract . manager . search ( $userId == id || $userId2 == id , false ) . length == 0 ) {
// merge
member . merge ( sim . first ( ) ) ;
app . session . addMessage ( t . _ ( " T h i s e - m a i l w a s u s e d b y a n o t h e r u s e r a c c o u n t . A s t h i s u s e r a c c o u n t w a s n o t u s e d , i t h a s b e e n m e r g e d i n t o t h e c u r r e n t u s e r a c c o u n t . " ) ) ;
} e lse {
var str = t . _ ( " W a r n i n g , t h i s e - m a i l o r t h i s n a m e a l r e a d y e x i s t s f o r a n o t h e r a c c o u n t : " ) ;
str += Lambda . map ( sim , function ( u ) return " < a h r e f = ' / m e m b e r / v i e w / " + u . id + " ' > " + u . getCoupleName ( ) + " < / a > " ) . join ( " , " ) ;
@ -339,28 +336,33 @@ class Member extends Controller
}
}
if ( ! isReg ) member . setPass ( form . getValueOf ( " p a s s " ) ) ;
if ( ! isReg )
member . setPass ( form . getValueOf ( " p a s s " ) ) ;
member . update ( ) ;
if ( ! App . config . DEBUG && groupNum == 1 ) {
// warn the user that his email has been updated
if ( form . getValueOf ( " e m a i l " ) != member . email ) {
var m = new sugoi . mail . Mail ( ) ;
m . setSender ( App . config . get ( " d e f a u l t _ e m a i l " ) , t . _ ( " C a g e t t e . n e t " ) ) ;
m . addRecipient ( member . email ) ;
m . setSubject ( t . _ ( " C h a n g e y o u r e - m a i l i n y o u r a c c o u n t C a g e t t e . n e t " ) ) ;
m . setHtmlBody ( app . processTemplate ( " m a i l / m e s s a g e . m t t " , { text : app . user . getName ( ) + t . _ ( " j u s t m o d i f i e d y o u r e - m a i l i n y o u r a c c o u n t C a g e t t e . n e t . < b r / > Y o u r e - m a i l i s n o w : " ) + form . getValueOf ( " e m a i l " ) } ) ) ;
m . setHtmlBody ( app . processTemplate ( " m a i l / m e s s a g e . m t t " ,
{ text : app . user . getName ( )
+ t . _ ( " j u s t m o d i f i e d y o u r e - m a i l i n y o u r a c c o u n t C a g e t t e . n e t . < b r / > Y o u r e - m a i l i s n o w : " )
+ form . getValueOf ( " e m a i l " ) } ) ) ;
App . sendMail ( m ) ;
}
if ( form . getValueOf ( " e m a i l 2 " ) != member . email2 && member . email2 != null ) {
var m = new sugoi . mail . Mail ( ) ;
m . setSender ( App . config . get ( " d e f a u l t _ e m a i l " ) , " C a g e t t e . n e t " ) ;
m . setSender ( App . config . get ( " d e f a u l t _ e m a i l " ) , t . _ ( " C a g e t t e . n e t " ) ) ;
m . addRecipient ( member . email2 ) ;
m . setSubject ( t . _ ( " C h a n g e t h e e - m a i l o f y o u r a c c o u n t C a g e t t e . n e t " ) ) ;
m . setHtmlBody ( app . processTemplate ( " m a i l / m e s s a g e . m t t " , { text : app . user . getName ( ) + t . _ ( " j u s t m o d i f i e d y o u r e - m a i l i n y o u r a c c o u n t C a g e t t e . n e t . < b r / > Y o u r e - m a i l i s n o w : " ) + form . getValueOf ( " e m a i l 2 " ) } ) ) ;
m . setHtmlBody ( app . processTemplate ( " m a i l / m e s s a g e . m t t " ,
{ text : app . user . getName ( )
+ t . _ ( " j u s t m o d i f i e d y o u r e - m a i l i n y o u r a c c o u n t C a g e t t e . n e t . < b r / > Y o u r e - m a i l i s n o w : " )
+ form . getValueOf ( " e m a i l 2 " ) } ) ) ;
App . sendMail ( m ) ;
}
}
@ -369,19 +371,24 @@ class Member extends Controller
}
view . form = form ;
}
/ * *
* Remove a user from this group
* /
function doDelete ( user : db . User , ? args : { confirm : Bool , token : String } ) {
if ( checkToken ( ) ) {
if ( ! app . user . canAccessMembership ( ) ) throw t . _ ( " Y o u c a n n o t d o t h a t . " ) ;
if ( user . id == app . user . id ) throw Error ( " / m e m b e r / v i e w / " + user . id , t . _ ( " Y o u c a n n o t d e l e t e y o u r s e l f . " ) ) ;
if ( ! app . user . canAccessMembership ( ) )
throw t . _ ( " Y o u c a n n o t d o t h a t . " ) ;
if ( user . id == app . user . id )
throw Error ( " / m e m b e r / v i e w / " + user . id , t . _ ( " Y o u c a n n o t d e l e t e y o u r s e l f . " ) ) ;
if ( Lambda . count ( user . getOrders ( app . user . amap ) , function ( x ) return x . quantity > 0 ) > 0 && ! args . confirm ) {
throw Error ( " / m e m b e r / v i e w / " + user . id , t . _ ( " W a r n i n g , t h i s a c c o u n t h a s o r d e r s . < a c l a s s = ' b t n b t n - d e f a u l t b t n - x s ' h r e f = ' / m e m b e r / d e l e t e / : : u s e r i d : : ? t o k e n = : : a r g s t o k e n : : & c o n f i r m = 1 ' > R e m o v e a n y w a y < / a > " , { userid : user . id , argstoken : args . token } ) ) ;
throw Error ( " / m e m b e r / v i e w / " + user . id ,
t . _ ( " W a r n i n g , t h i s a c c o u n t h a s o r d e r s . < a c l a s s = ' b t n b t n - d e f a u l t b t n - x s ' h r e f = ' / m e m b e r / d e l e t e / : : u s e r i d : : ? t o k e n = : : a r g s t o k e n : : & c o n f i r m = 1 ' > R e m o v e a n y w a y < / a > " ,
{
userid : user . id ,
argstoken : args . token
} ) ) ;
}
var ua = db . UserAmap . get ( user , app . user . amap , true ) ;
@ -398,8 +405,8 @@ class Member extends Controller
@ tpl ( ' f o r m . m t t ' )
function doMerge ( user : db . User ) {
if ( ! app . user . canAccessMembership ( ) ) throw Error ( " / " , " A c t i o n i n t e r d i t e " ) ;
if ( ! app . user . canAccessMembership ( ) )
throw Error ( " / " , " A c t i o n i n t e r d i t e " ) ;
view . title = t . _ ( " M e r g e a n a c c o u n t w i t h a n o t h e r o n e " ) ;
view . text = t . _ ( " T h i s a c t i o n a l l o w s y o u t o m e r g e t w o a c c o u n t s ( w h e n y o u h a v e d u p l i c a t e s i n t h e d a t a b a s e f o r e x a m p l e ) . < b r / > C o n t r a c t s o f a c c o u n t 2 w i l l b e m o v e d t o a c c o u n t 1 , a n d a c c o u n t 2 w i l l b e d e l e t e d . W a r n i n g , i t i s n o t p o s s i b l e t o c a n c e l t h i s a c t i o n . " ) ;
@ -414,7 +421,6 @@ class Member extends Controller
form . addElement ( mlist ) ;
if ( form . checkToken ( ) ) {
var m1 = Std . parseInt ( form . getElement ( " m e m b e r 1 " ) . value ) ;
var m2 = Std . parseInt ( form . getElement ( " m e m b e r 2 " ) . value ) ;
var m1 = db . User . manager . get ( m1 , true ) ;
@ -426,8 +432,10 @@ class Member extends Controller
// change usercontracts
var contracts = db . UserContract . manager . search ( $user == m2 || $user2 == m2 , true ) ;
for ( c in contracts ) {
if ( c . user . id == m2 . id ) c . user = m1 ;
if ( c . user2 != null && c . user2 . id == m2 . id ) c . user2 = m1 ;
if ( c . user . id == m2 . id )
c . user = m1 ;
if ( c . user2 != null && c . user2 . id == m2 . id )
c . user2 = m1 ;
c . update ( ) ;
}
@ -453,27 +461,23 @@ class Member extends Controller
m2 . delete ( ) ;
throw Ok ( " / m e m b e r / v i e w / " + m1 . id , t . _ ( " B o t h a c c o u n t s h a v e b e e n m e r g e d " ) ) ;
}
view . form = form ;
}
@ tpl ( ' m e m b e r / i m p o r t . m t t ' )
function doImport ( ? args : { confirm : Bool } ) {
var step = 1 ;
var request = Utils . getMultipart ( 1024 * 1024 * 4 ) ; // 4mb
// on recupere le contenu de l'upload
var data = request . get ( " f i l e " ) ;
if ( data != null ) {
var csv = new sugoi . tools . Csv ( ) ;
csv . setHeaders ( [ t . _ ( " F i r s t n a m e " ) , t . _ ( " L a s t n a m e " ) , t . _ ( " E - m a i l " ) , t . _ ( " M o b i l e p h o n e " ) , t . _ ( " P a r t n e r ' s f i r s t n a m e " ) , t . _ ( " P a r t n e r ' s l a s t n a m e " ) , t . _ ( " P a r t n e r ' s e - m a i l " ) , t . _ ( " P a r t n e r ' s M o b i l e p h o n e " ) , t . _ ( " A d d r e s s 1 " ) , t . _ ( " A d d r e s s 2 " ) , t . _ ( " P o s t c o d e " ) , t . _ ( " C i t y " ) ] ) ;
csv . setHeaders ( [
t . _ ( " F i r s t n a m e " ) , t . _ ( " L a s t n a m e " ) , t . _ ( " E - m a i l " ) , t . _ ( " M o b i l e p h o n e " ) , t . _ ( " P a r t n e r ' s f i r s t n a m e " ) , t . _ ( " P a r t n e r ' s l a s t n a m e " ) ,
t . _ ( " P a r t n e r ' s e - m a i l " ) , t . _ ( " P a r t n e r ' s M o b i l e p h o n e " ) , t . _ ( " A d d r e s s 1 " ) , t . _ ( " A d d r e s s 2 " ) , t . _ ( " P o s t c o d e " ) , t . _ ( " C i t y " ) ] ) ;
// utf8 encode if needed
try {
@ -491,17 +495,20 @@ class Member extends Controller
// cleaning
for ( user in unregistred . copy ( ) ) {
// check nom+prenom
if ( user [ 0 ] == null || user [ 1 ] == null ) {
throw Error ( " / m e m b e r / i m p o r t " , t . _ ( " Y o u m u s t f i l l t h e n a m e a n d t h e f i r s t n a m e o f t h e p e r s o n . T h i s l i n e i s i n c o m p l e t e : " ) + user ) ;
}
if ( user [ 2 ] == null ) {
throw Error ( " / m e m b e r / i m p o r t " , t . _ ( " E a c h p e r s o n m u s t h a v e a n e - m a i l t o b e a b l e t o l o g i n . : : u s e r 0 : : : : u s e r 1 : : d o n ' t h a v e o n e . " , { user0 : user [ 0 ] , user1 : user [ 1 ] } ) + user ) ;
throw Error ( " / m e m b e r / i m p o r t " ,
t . _ ( " E a c h p e r s o n m u s t h a v e a n e - m a i l t o b e a b l e t o l o g i n . : : u s e r 0 : : : : u s e r 1 : : d o n ' t h a v e o n e . " ,
{ user0 : user [ 0 ] , user1 : user [ 1 ] } ) + user ) ;
}
// uppercase du nom
if ( user [ 1 ] != null ) user [ 1 ] = user [ 1 ] . toUpperCase ( ) ;
if ( user [ 5 ] != null ) user [ 5 ] = user [ 5 ] . toUpperCase ( ) ;
if ( user [ 1 ] != null )
user [ 1 ] = user [ 1 ] . toUpperCase ( ) ;
if ( user [ 5 ] != null )
user [ 5 ] = user [ 5 ] . toUpperCase ( ) ;
// lowercase email
if ( user [ 2 ] != null ) {
user [ 2 ] = user [ 2 ] . toLowerCase ( ) ;
@ -515,7 +522,6 @@ class Member extends Controller
// utf-8 check
for ( row in unregistred . copy ( ) ) {
for ( i in 0 ... row . length ) {
var t = row [ i ] ;
if ( t != " " && t != null ) {
@ -548,7 +554,6 @@ class Member extends Controller
}
}
app . session . data . csvUnregistered = unregistred ;
app . session . data . csvRegistered = registred ;
@ -557,13 +562,12 @@ class Member extends Controller
step = 2 ;
}
if ( args != null && args . confirm ) {
// import unregistered members
var i: Iterable < Dynamic > = cast app . session . data . csvUnregistered ;
for ( u in i ) {
if ( u [ 0 ] == null || u [ 0 ] == " n u l l " || u [ 0 ] == " " ) continue ;
if ( u [ 0 ] == null || u [ 0 ] == " n u l l " || u [ 0 ] == " " )
continue ;
var user = new db . User ( ) ;
user . firstName = u [ 0 ] ;
@ -579,7 +583,8 @@ class Member extends Controller
user . email2 = u [ 6 ] ;
if ( user . email2 != null && user . email2 != " n u l l " && ! EmailValidator . check ( user . email2 ) ) {
App . log ( u ) ;
throw t . _ ( " T h e E - m a i l o f t h e p a r t n e r o f : : u s e r F i r s t N a m e : : : : u s e r L a s t N a m e : : ' : : u s e r E m a i l : : ' i s i n v a l i d , p l e a s e c h e c k y o u r f i l e " , { userFirstName : user . firstName , userLastName : user . lastName , userEmail : user . email2 } ) ;
throw t . _ ( " T h e E - m a i l o f t h e p a r t n e r o f : : u s e r F i r s t N a m e : : : : u s e r L a s t N a m e : : ' : : u s e r E m a i l : : ' i s i n v a l i d , p l e a s e c h e c k y o u r f i l e " ,
{ userFirstName : user . firstName , userLastName : user . lastName , userEmail : user . email2 } ) ;
}
user . phone2 = u [ 7 ] ;
user . address1 = u [ 8 ] ;
@ -601,7 +606,8 @@ class Member extends Controller
var email2 = u [ 6 ] ;
var us = db . User . getSameEmail ( email , email2 ) ;
var userAmaps = db . UserAmap . manager . search ( $amap == app . user . amap && $userId in Lambda . map ( us , function ( u ) return u . id ) , false ) ;
var userAmaps = db . UserAmap . manager . search ( $amap == app . user . amap
& & $userId in Lambda . map ( us , function ( u ) return u . id ) , false ) ;
// member exists but is not member of this group.
if ( userAmaps . length == 0 ) {
@ -630,8 +636,8 @@ class Member extends Controller
@ tpl ( " u s e r / i n s e r t . m t t " )
public function doInsert ( ) {
if ( ! app . user . canAccessMembership ( ) ) throw Error ( " / " , t . _ ( " F o r b i d d e n a c t i o n " ) ) ;
if ( ! app . user . canAccessMembership ( ) )
throw Error ( " / " , t . _ ( " F o r b i d d e n a c t i o n " ) ) ;
var m = new db . User ( ) ;
var form = sugoi . form . Form . fromSpod ( m ) ;
@ -645,17 +651,16 @@ class Member extends Controller
form . getElement ( " e m a i l 2 " ) . addValidator ( new EmailValidator ( ) ) ;
if ( form . isValid ( ) ) {
// check doublon de User et de UserAmap
var userSims = db . User . getSameEmail ( form . getValueOf ( " e m a i l " ) , form . getValueOf ( " e m a i l 2 " ) ) ;
view . userSims = userSims ;
var userAmaps = db . UserAmap . manager . search ( $amap == app . user . amap && $userId in Lambda . map ( userSims , function ( u ) return u . id ) , false ) ;
var userAmaps = db . UserAmap . manager . search ( $amap == app . user . amap
& & $userId in Lambda . map ( userSims , function ( u ) return u . id ) , false ) ;
view . userAmaps = userAmaps ;
if ( userAmaps . length > 0 ) {
// user deja enregistré dans cette amap
throw Error ( ' / m e m b e r / v i e w / ' + userAmaps . first ( ) . user . id , t . _ ( " T h i s p e r s o n i s a l r e a d y m e m b e r o f t h i s g r o u p " ) ) ;
} e lse if ( userSims . length > 0 ) {
// des users existent avec ce nom ,
// if (userSims.length == 1) {
@ -672,7 +677,6 @@ class Member extends Controller
} * /
return ;
} e lse {
if ( app . user . amap . flags . has ( db . Amap . AmapFlags . PhoneRequired ) && form . getValueOf ( " p h o n e " ) == null ) {
throw Error ( " / m e m b e r / i n s e r t " , t . _ ( " P h o n e n u m b e r i s r e q u i r e d i n t h i s g r o u p . " ) ) ;
}
@ -691,29 +695,30 @@ class Member extends Controller
if ( form . getValueOf ( " w a r n A m a p M a n a g e r " ) == " 1 " ) {
var url = " h t t p : / / " + App . config . HOST + " / m e m b e r / v i e w / " + u . id ;
var text = t . _ ( " : : a d m i n : : j u s t k e y e d - i n c o n t a c t d e t a i l s o f a n e w m e m b e r : < b r / > < s t r o n g > : : n e w M e m b e r : : < / s t r o n g > < b r / > < a h r e f = ' : : u r l : : ' > S e e c o n t a c t d e t a i l s < / a > " , { admin : app . user . getName ( ) , newMember : u . getCoupleName ( ) , url : url } ) ;
App . quickMail (
app . user . getAmap ( ) . contact . email ,
app . user . amap . name + " - " + t . _ ( " N e w m e m b e r " ) + " : " + u . getCoupleName ( ) ,
app . processTemplate ( " m a i l / m e s s a g e . m t t " , { text : text } )
) ;
var text = t . _ ( " : : a d m i n : : j u s t k e y e d - i n c o n t a c t d e t a i l s o f a n e w m e m b e r : < b r / > < s t r o n g > : : n e w M e m b e r : : < / s t r o n g > < b r / > < a h r e f = ' : : u r l : : ' > S e e c o n t a c t d e t a i l s < / a > " ,
{
admin : app . user . getName ( ) ,
newMember : u . getCoupleName ( ) ,
url : url
} ) ;
App . quickMail ( app . user . getAmap ( ) . contact . email , app . user . amap . name + " - " + t . _ ( " N e w m e m b e r " ) + " : " + u . getCoupleName ( ) ,
app . processTemplate ( " m a i l / m e s s a g e . m t t " , {
text : text
} ) ) ;
}
throw Ok ( ' / m e m b e r / ' , t . _ ( " T h i s p e r s o n i s n o w m e m b e r o f t h e g r o u p " ) ) ;
}
}
view . form = form ;
}
/ * *
* user payments history
* /
@ tpl ( ' m e m b e r / p a y m e n t s . m t t ' )
function doPayments ( m : db . User ) {
service . PaymentService . updateUserBalance ( m , app . user . amap ) ;
var browse: Int -> Int -> List < Dynamic > ;
@ -737,5 +742,4 @@ class Member extends Controller
view . credit = db . UserAmap . manager . search ( $amap == app . user . amap && $balance > 0 , false ) ;
view . debt = db . UserAmap . manager . search ( $amap == app . user . amap && $balance < 0 , false ) ;
}
}