@ -1,4 +1,5 @@
package controller ;
import Common ;
import haxe . Utf8 ;
import sugoi . form . Form ;
@ -6,111 +7,114 @@ 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
@ tpl ( ' m e m b e r / d e f a u l t . m t t ' )
function doDefault ( ? args : { ? search : String , ? select : String } ) {
function doDefault ( ? args : { ? search : String , ? select : String } ) {
checkToken ( ) ;
var browse: Int -> Int -> List < Dynamic > ;
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
// 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 ) ;
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 ) ;
}
view . search = args . search ;
} e lse if ( args != null && args . select != null ) {
// SELECTION
} e lse if ( args != null && args . select != null ) {
//SELECTION
switch ( args . select ) {
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 ) ; }
} e lse {
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 ) ; }
} e lse {
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 " :
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 ) ; }
} e lse {
browse = function ( index : Int , limit : Int ) {
return db . User . getUsers_NoMembership ( index , limit ) ;
}
}
c ase " n e w u s e r s " :
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 ) ; }
} e lse {
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 {
} 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
} e lse {
// default display
browse = function ( index : Int , limit : Int ) {
return db . User . manager . search ( $id in uids , { limit : [ index , limit ] , orderBy : lastName } , false ) ;
return db . User . manager . search ( $id in uids , { limit : [ index , limit ] , orderBy : lastName } , false ) ;
}
}
}
var count = uids . length ;
var rb = new sugoi . tools . ResultsBrowser ( count , ( args . select != null || args . search != null ) ? 1000 : 10 , browse ) ;
var rb = new sugoi . tools . ResultsBrowser ( count , ( args . select != null || args . search != null ) ? 1000 : 10 , browse ) ;
view . members = rb ;
if ( args . select == null || args . select != " n e w u s e r s " ) {
//count new users
// count new users
view . newUsers = db . User . getUsers_NewUsers ( ) . length ;
}
view . waitingList = db . WaitingList . manager . count ( $group == app . user . amap ) ;
}
/ * *
* Move to waiting list
* /
function doMovetowl ( u : db . User ) {
function doMovetowl ( u : db . User ) {
var ua = db . UserAmap . get ( u , app . user . amap , true ) ;
ua . delete ( ) ;
@ -119,93 +123,84 @@ class Member extends Controller
wl . group = app . user . amap ;
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 . " ) ) ;
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 . " ) ) ;
}
/ * *
* Display waiting list
* /
@ 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 " ) ) ;
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 " ) ) ;
}
}
view . waitingList = db . WaitingList . manager . search ( $group == app . user . amap , { orderBy : - date } ) ;
view . waitingList = db . WaitingList . manager . search ( $group == app . user . amap , { orderBy : - date } ) ;
}
/ * *
* Send an invitation to a new member
* /
function doInviteMember ( u : db . User ) {
if ( checkToken ( ) ) {
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 . " ) ) ;
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 ) {
try {
for ( u in users ) {
u . sendInvitation ( app . user . amap ) ;
Sys . sleep ( 0.2 ) ;
}
} c atch ( e : S t r i n g ) {
if ( e . indexOf ( " c u r l " ) > - 1 ) {
} c atch ( e : S t r i n g ) {
if ( e . indexOf ( " c u r l " ) > - 1 ) {
App . current . logError ( e , haxe . CallStack . toString ( haxe . CallStack . exceptionStack ( ) ) ) ;
throw Error ( " / m e m b e r " , t . _ ( " A n e r r o r o c c u r r e d w h i l e s e n d i n g e m a i l s , p l e a s e r e t r y " ) ) ;
}
}
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 } ) ) ;
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 ( ) ;
//orders
var row = { constOrders : new Array < UserOrder > ( ) , varOrders : new Map < String , Array < UserOrder > > ( ) } ;
// orders
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 ) ;
// 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 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 distribs = new Map < String , List < db . UserContract > > ( ) ;
// 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 distribs = new Map < String , List < db . UserContract > > ( ) ;
for ( c in contracts ) {
var ds = c . getDistribs ( ) ;
for ( d in ds ) {
@ -214,25 +209,23 @@ class Member extends Controller
if ( orders . length > 0 ) {
if ( ! distribs . exists ( k ) ) {
distribs . set ( k , orders ) ;
} e lse {
} 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 ) ;
}
}
}
}
for ( k in distribs . keys ( ) ) {
for ( k in distribs . keys ( ) ) {
var d = distribs . get ( k ) ;
var d2 = service . OrderService . prepare ( d ) ;
row . varOrders . set ( k , d2 ) ;
row . varOrders . set ( k , d2 ) ;
}
view . userContracts = row ;
checkToken ( ) ; //to insert a token in tpl
checkToken ( ) ; // to insert a token in tpl
}
/ * *
@ -241,35 +234,42 @@ 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 . isAdmin ( ) ) {
if ( ! app . user . isAmapManager ( ) )
return ;
if ( member . isAdmin ( ) )
return ;
if ( db . UserAmap . manager . count ( $userId == member . id ) > 1 )
return ;
}
App . current . session . setUser ( member ) ;
App . current . session . data . amapId = amap . id ;
throw Redirect ( " / m e m b e r / v i e w / " + member . id ) ;
throw Redirect ( " / m e m b e r / v i e w / " + member . id ) ;
}
@ 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 } > ( ) ;
function doLastMessages ( member : db . User ) {
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 ) {
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,127 +279,134 @@ 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 ) ;
//cleaning
form . removeElement ( form . getElement ( " r i g h t s " ) ) ;
form . removeElement ( form . getElement ( " l a n g " ) ) ;
form . removeElement ( form . getElement ( " l d a t e " ) ) ;
form . removeElement ( form . getElement ( " a p i K e y " ) ) ;
// cleaning
form . removeElement ( form . getElement ( " r i g h t s " ) ) ;
form . removeElement ( form . getElement ( " l a n g " ) ) ;
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 ) ;
//an administrator can modify a user's email only if he's not member elsewhere
if ( groupNum > 1 ) {
// an administrator can modify a user's email only if he's not member elsewhere
if ( groupNum > 1 ) {
form . removeElementByName ( " e m a i l " ) ;
form . removeElementByName ( " e m a i l 2 " ) ;
app . session . addMessage ( t . _ ( " F o r s e c u r i t y r e a s o n s , y o u c a n n o t m o d i f y t h e e - m a i l o f t h i s p e r s o n b e c a u s e t h i s p e r s o n i s a m e m b e r o f m o r e t h a n 1 g r o u p . " ) ) ;
}
//an administrator can modify a user's pass only if he's a not registred user.
if ( ! isReg ) {
// an administrator can modify a user's pass only if he's a not registred user.
if ( ! isReg ) {
app . session . addMessage ( t . _ ( " T h i s p e r s o n d i d n o t d e f i n e y e t a p a s s w o r d . Y o u a r e e x c e p t i o n a l y a u t h o r i z e d t o d o i t . P l e a s e d o n ' t f o r g e t t o t e l l t h i s p e r s o n . " ) ) ;
form . getElement ( " p a s s " ) . required = false ;
} e lse {
form . removeElement ( form . getElement ( " p a s s " ) ) ;
} e lse {
form . removeElement ( form . getElement ( " p a s s " ) ) ;
}
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 . " ) ) ;
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 . " ) ) ;
}
form . toSpod ( member ) ;
//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 ) ;
// 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 ( sim . length > 0 ) {
//Let's merge the 2 users if it has no orders.
// 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 ( ) ) ;
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 ( " , " ) ;
str += " " + t . _ ( " T h e s e a c c o u n t s c a n ' t b e m e r g e d b e c a u s e t h e s e c o n d a c c o u n t h a s o r d e r s " ) ;
str += " " + t . _ ( " T h e s e a c c o u n t s c a n ' t b e m e r g e d b e c a u s e t h e s e c o n d a c c o u n t h a s o r d e r s " ) ;
throw Error ( " / m e m b e r / e d i t / " + member . id , str ) ;
}
}
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
// 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 ) {
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 ) ;
}
}
throw Ok ( ' / m e m b e r / v i e w / ' + member . id , t . _ ( " T h i s m e m b e r h a s b e e d u p d a t e d " ) ) ;
throw Ok ( ' / m e m b e r / v i e w / ' + member . id , t . _ ( " T h i s m e m b e r h a s b e e d u p d a t e d " ) ) ;
}
view . form = form ;
}
/ * *
* Remove a user from this group
* /
function doDelete ( user : db . User , ? args : { confirm : Bool , token : String } ) {
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 ( 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 } ) ) ;
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
} ) ) ;
}
var ua = db . UserAmap . get ( user , app . user . amap , true ) ;
if ( ua != null ) {
ua . delete ( ) ;
throw Ok ( " / m e m b e r " , t . _ ( " : : u s e r : : h a s b e e n r e m o v e d f r o m y o u r g r o u p " , { user : user . getName ( ) } ) ) ;
} e lse {
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 \" : : a m a p n a m e : : \" " , { amapname : app . user . amap . name } ) ) ;
throw Ok ( " / m e m b e r " , t . _ ( " : : u s e r : : h a s b e e n r e m o v e d f r o m y o u r g r o u p " , { user : user . getName ( ) } ) ) ;
} e lse {
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 \" : : a m a p n a m e : : \" " , { amapname : app . user . amap . name } ) ) ;
}
} e lse {
throw Redirect ( " / m e m b e r / v i e w / " + user . id ) ;
} e lse {
throw Redirect ( " / m e m b e r / v i e w / " + user . id ) ;
}
}
@ 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 . " ) ;
@ -407,80 +414,77 @@ class Member extends Controller
var form = new Form ( " m e r g e " ) ;
var members = app . user . amap . getMembers ( ) ;
var members = Lambda . array ( Lambda . map ( members , function ( x ) return { key : Std . string ( x . id ) , value : x . getName ( ) } ) ) ;
var members = Lambda . array ( Lambda . map ( members , function ( x ) return { key : Std . string ( x . id ) , value : x . getName ( ) } ) ) ;
var mlist = new Selectbox ( " m e m b e r 1 " , t . _ ( " A c c o u n t 1 " ) , members , Std . string ( user . id ) ) ;
form . addElement ( mlist ) ;
form . addElement ( mlist ) ;
var mlist = new Selectbox ( " m e m b e r 2 " , t . _ ( " A c c o u n t 2 " ) , members ) ;
form . addElement ( mlist ) ;
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 ) ;
var m2 = db . User . manager . get ( m2 , true ) ;
var m1 = db . User . manager . get ( m1 , true ) ;
var m2 = db . User . manager . get ( m2 , true ) ;
//if (m1.amapId != m2.amapId) throw "ils ne sont pas de la même amap !";
// if (m1.amapId != m2.amapId) throw "ils ne sont pas de la même amap !";
//on prend tout à m2 pour donner à m1
//change usercontracts
var contracts = db . UserContract . manager . search ( $user == m2 || $user2 == m2 , true ) ;
// on prend tout à m2 pour donner à m1
// 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 ( ) ;
}
//group memberships
// group memberships
var adh = db . UserAmap . manager . search ( $user == m2 , true ) ;
for ( a in adh ) {
for ( a in adh ) {
a . user = m1 ;
a . update ( ) ;
}
//change contacts
var contacts = db . Contract . manager . search ( $contact == m2 , true ) ;
// change contacts
var contacts = db . Contract . manager . search ( $contact == m2 , true ) ;
for ( c in contacts ) {
c . contact = m1 ;
c . update ( ) ;
}
//if (m2.amap.contact == m2) {
//m1.amap.lock();
//m1.amap.contact = m1;
//m1.amap.update();
//}
// if (m2.amap.contact == m2) {
// m1.amap.lock();
// m1.amap.contact = m1;
// m1.amap.update();
// }
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 } ) {
function doImport ( ? args : { confirm : Bool } ) {
var step = 1 ;
var request = Utils . getMultipart ( 1024 * 1024 * 4 ) ; //4mb
var request = Utils . getMultipart ( 1024 * 1024 * 4 ) ; // 4mb
//on recupere le contenu de l'upload
// on recupere le contenu de l'upload
var data = request . get ( " f i l e " ) ;
if ( data != null ) {
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 {
if ( ! haxe . Utf8 . validate ( data ) ) {
// utf8 encode if needed
try {
if ( ! haxe . Utf8 . validate ( data ) ) {
data = haxe . Utf8 . encode ( data ) ;
}
} c atch ( e : D y n a m i c ) { }
} c atch ( e : D y n a m i c ) { }
var unregistred = csv . importDatas ( data ) ;
/ * var checkEmail = function ( email ) {
@ -489,55 +493,57 @@ class Member extends Controller
}
} * /
//cleaning
for ( user in unregistred . copy ( ) ) {
//check nom+prenom
// 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 ( ) ;
//lowercase email
if ( user [ 2 ] != null ) {
// uppercase du nom
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 ( ) ;
//checkEmail(user[2]);
// checkEmail(user[2]);
}
if ( user [ 6 ] != null ) {
if ( user [ 6 ] != null ) {
user [ 6 ] = user [ 6 ] . toLowerCase ( ) ;
//checkEmail(user[6]);
// checkEmail(user[6]);
}
}
//utf-8 check
for ( row in unregistred . copy ( ) ) {
for ( i in 0 ... row . length ) {
// utf-8 check
for ( row in unregistred . copy ( ) ) {
for ( i in 0 ... row . length ) {
var t = row [ i ] ;
if ( t != " " && t != null ) {
try {
try {
if ( ! Utf8 . validate ( t ) ) {
t = Utf8 . encode ( t ) ;
}
} c atch ( e : D y n a m i c ) { }
} c atch ( e : D y n a m i c ) { }
row [ i ] = t ;
}
}
}
//put already registered people in another list
// put already registered people in another list
var registred = [ ] ;
for ( r in unregistred . copy ( ) ) {
//var firstName = r[0];
//var lastName = r[1];
// var firstName = r[0];
// var lastName = r[1];
var email = r [ 2 ] ;
//var firstName2 = r[4];
//var lastName2 = r[5];
// var firstName2 = r[4];
// var lastName2 = r[5];
var email2 = r [ 6 ] ;
var us = db . User . getSameEmail ( email , email2 ) ;
@ -548,7 +554,6 @@ class Member extends Controller
}
}
app . session . data . csvUnregistered = unregistred ;
app . session . data . csvRegistered = registred ;
@ -557,20 +562,19 @@ class Member extends Controller
step = 2 ;
}
if ( args != null && args . confirm ) {
//import unregistered members
var i : Iterable < Dynamic > = cast app . session . data . csvUnregistered ;
// 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 ] ;
user . lastName = u [ 1 ] ;
user . email = u [ 2 ] ;
if ( user . email != null && user . email != " n u l l " && ! EmailValidator . check ( user . email ) ) {
throw t . _ ( " T h e E - m a i l : : u s e r e m a i l : : i s i n v a l i d , p l e a s e m o d i f y y o u r f i l e " , { useremail : user . email } ) ;
if ( user . email != null && user . email != " n u l l " && ! EmailValidator . check ( user . email ) ) {
throw t . _ ( " T h e E - m a i l : : u s e r e m a i l : : i s i n v a l i d , p l e a s e m o d i f y y o u r f i l e " , { useremail : user . email } ) ;
}
user . phone = u [ 3 ] ;
@ -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 ] ;
@ -594,16 +599,17 @@ class Member extends Controller
ua . insert ( ) ;
}
//import registered members
var i : Iterable < Array < String > > = cast app . session . data . csvRegistered ;
// import registered members
var i: Iterable < Array < String > > = cast app . session . data . csvRegistered ;
for ( u in i ) {
var email = u [ 2 ] ;
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.
// member exists but is not member of this group.
if ( userAmaps . length == 0 ) {
var ua = new db . UserAmap ( ) ;
ua . user = us . first ( ) ;
@ -620,7 +626,7 @@ class Member extends Controller
}
if ( step == 1 ) {
//reset import when back to import page
// reset import when back to import page
app . session . data . csvUnregistered = null ;
app . session . data . csvRegistered = null ;
}
@ -630,60 +636,58 @@ 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 ) ;
form . removeElement ( form . getElement ( " l a n g " ) ) ;
form . removeElement ( form . getElement ( " r i g h t s " ) ) ;
form . removeElement ( form . getElement ( " p a s s " ) ) ;
form . removeElement ( form . getElement ( " l d a t e " ) ) ;
form . removeElement ( form . getElement ( " a p i K e y " ) ) ;
form . removeElement ( form . getElement ( " l d a t e " ) ) ;
form . removeElement ( form . getElement ( " a p i K e y " ) ) ;
form . addElement ( new sugoi . form . elements . Checkbox ( " w a r n A m a p M a n a g e r " , t . _ ( " S e n d a n E - m a i l t o t h e p e r s o n i n c h a r g e o f t h e g r o u p " ) , true ) ) ;
form . getElement ( " e m a i l " ) . addValidator ( new EmailValidator ( ) ) ;
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 " ) ) ;
// 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
// 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) {
// si yen a qu'un on l'inserte
var ua = new db . UserAmap ( ) ;
ua . user = userSims . first ( ) ;
ua . amap = app . user . amap ;
ua . insert ( ) ;
throw Ok ( ' / m e m b e r / ' , t . _ ( " T h i s p e r s o n a l r e a d y h a d a n a c c o u n t o n C a g e t t e . n e t , a n d i s n o w m e m b e r o f y o u r g r o u p . " ) ) ;
} e lse if ( userSims . length > 0 ) {
// des users existent avec ce nom ,
// if (userSims.length == 1) {
// si yen a qu'un on l'inserte
var ua = new db . UserAmap ( ) ;
ua . user = userSims . first ( ) ;
ua . amap = app . user . amap ;
ua . insert ( ) ;
throw Ok ( ' / m e m b e r / ' , t . _ ( " T h i s p e r s o n a l r e a d y h a d a n a c c o u n t o n C a g e t t e . n e t , a n d i s n o w m e m b e r o f y o u r g r o u p . " ) ) ;
/ * } e lse {
//demander validation avant d'inserer le userAmap
//TODO
throw Error ( ' / m e m b e r ' , t . _ ( " N o t p o s s i b l e t o a d d t h i s p e r s o n b e c a u s e t h e r e a r e a l r e a d y s o m e p e o p l e i n t h e d a t a b a s e h a v i n g t h e s a m e f i r s t n a m e a n d n a m e . P l e a s e c o n t a c t t h e a d m i n i s t r a t o r . " ) + userSims ) ;
} * /
return ;
} e lse {
if ( app . user . amap . flags . has ( db . Amap . AmapFlags . PhoneRequired ) && form . getValueOf ( " p h o n e " ) == null ) {
} 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 . " ) ) ;
}
//insert user
// insert user
var u = new db . User ( ) ;
form . toSpod ( u ) ;
u . lang = app . user . lang ;
u . insert ( ) ;
//insert userAmap
// insert userAmap
var ua = new db . UserAmap ( ) ;
ua . user = u ;
ua . amap = app . user . getAmap ( ) ;
@ -691,38 +695,39 @@ 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 ) {
function doPayments ( m : db . User ) {
service . PaymentService . updateUserBalance ( m , app . user . amap ) ;
var browse: Int -> Int -> List < Dynamic > ;
var browse: Int -> Int -> List < Dynamic > ;
//default display
// default display
browse = function ( index : Int , limit : Int ) {
return db . Operation . getOperationsWithIndex ( m , app . user . amap , index , limit , true ) ;
return db . Operation . getOperationsWithIndex ( m , app . user . amap , index , limit , true ) ;
}
var count = db . Operation . countOperations ( m , app . user . amap ) ;
var count = db . Operation . countOperations ( m , app . user . amap ) ;
var rb = new sugoi . tools . ResultsBrowser ( count , 10 , browse ) ;
view . rb = rb ;
view . member = m ;
@ -732,10 +737,9 @@ class Member extends Controller
}
@ tpl ( ' m e m b e r / b a l a n c e . m t t ' )
function doBalance ( ) {
function doBalance ( ) {
view . balanced = db . UserAmap . manager . search ( $amap == app . user . amap && $balance == 0.0 , false ) ;
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 ) ;
}
}