ÿþ/ *  
 R u n   t h i s   s c r i p t   o n   t h e   d a t a b a s e   c o n t a i n i n g   v e r s i o n   2 . 0 . 2 8 3 0   o f   G a l l e r y   S e r v e r   P r o .  
 T h i s   s c r i p t   p r o v i d e s   b u g   f i x e s   t o   f o u r   s t o r e d   p r o c e d u r e s   a n d   a d d s   o n e   u s e r   d e f i n e d   f u n c t i o n .  
 * /  
 G O  
 S E T   N U M E R I C _ R O U N D A B O R T   O F F  
 G O  
 S E T   A N S I _ P A D D I N G   O N  
 G O  
 S E T   A N S I _ W A R N I N G S   O N  
 G O  
 S E T   C O N C A T _ N U L L _ Y I E L D S _ N U L L   O N  
 G O  
 S E T   A R I T H A B O R T   O N  
 G O  
 S E T   Q U O T E D _ I D E N T I F I E R   O N  
 G O  
 S E T   A N S I _ N U L L S   O N  
 G O  
 I F   E X I S T S   ( S E L E C T   *   F R O M   t e m p d b . . s y s o b j e c t s   W H E R E   i d = O B J E C T _ I D ( ' t e m p d b . . # t m p E r r o r s ' ) )   D R O P   T A B L E   # t m p E r r o r s  
 G O  
 C R E A T E   T A B L E   # t m p E r r o r s   ( E r r o r   i n t )  
 G O  
 S E T   X A C T _ A B O R T   O N  
 G O  
 S E T   T R A N S A C T I O N   I S O L A T I O N   L E V E L   R E A D   C O M M I T T E D  
 G O  
 B E G I N   T R A N S A C T I O N  
 G O  
 P R I N T   N ' A l t e r i n g   [ d b o ] . [ g s _ S y n c h r o n i z e S a v e ] '  
 G O  
 A L T E R   P R O C E D U R E   [ d b o ] . [ g s _ S y n c h r o n i z e S a v e ]  
 	 ( @ S y n c h I D   n c h a r ( 5 0 ) ,   @ G a l l e r y I d   i n t ,   @ S y n c h S t a t e   i n t ,   @ T o t a l F i l e s   i n t ,   @ C u r r e n t F i l e I n d e x   i n t )  
 A S  
 S E T   N O C O U N T ,   X A C T _ A B O R T   O N  
 / *   U P D A T E   t h e   s y n c h r o n i z e   t a b l e   w i t h   t h e   s p e c i f i e d   d a t a .   * /  
  
 / *   C h e c k   i f   a n o t h e r   s y n c h r o n i z a t i o n   i s   i n   p r o g r e s s .   R e t u r n   w i t h   e r r o r   c o d e   i f   i t   i s .   * /  
 I F   E X I S T S ( S E L E C T   *   F R O M   [ g s _ S y n c h r o n i z e ]   W H E R E   F K G a l l e r y I D   =   @ G a l l e r y I d   A N D   S y n c h I D   < >   @ S y n c h I D   A N D   ( S y n c h S t a t e   =   1   O R   S y n c h S t a t e   =   2 ) )  
 B E G I N  
 	 R E T U R N   2 5 0 0 0 0  
 E N D  
  
 B E G I N   T R A N  
 I F   E X I S T S   ( S E L E C T   *   F R O M   [ g s _ S y n c h r o n i z e ]   W I T H   ( U P D L O C K ,   H O L D L O C K )   W H E R E   F K G a l l e r y I D   =   @ G a l l e r y I d )  
 	 U P D A T E   [ g s _ S y n c h r o n i z e ]  
 	 S E T   S y n c h I D   =   @ S y n c h I D ,  
 	 	 F K G a l l e r y I d   =   @ G a l l e r y I d ,  
 	 	 S y n c h S t a t e   =   @ S y n c h S t a t e ,  
 	 	 T o t a l F i l e s   =   @ T o t a l F i l e s ,  
 	 	 C u r r e n t F i l e I n d e x   =   @ C u r r e n t F i l e I n d e x  
 	 W H E R E   F K G a l l e r y I D   =   @ G a l l e r y I d  
 E L S E  
 	 I N S E R T   [ g s _ S y n c h r o n i z e ]   ( S y n c h I D ,   F K G a l l e r y I D ,   S y n c h S t a t e ,   T o t a l F i l e s ,   C u r r e n t F i l e I n d e x )  
 	 V A L U E S   ( @ S y n c h I D ,   @ G a l l e r y I d ,   @ S y n c h S t a t e ,   @ T o t a l F i l e s ,   @ C u r r e n t F i l e I n d e x )  
 C O M M I T  
  
 R E T U R N  
 G O  
 I F   @ @ E R R O R < > 0   A N D   @ @ T R A N C O U N T > 0   R O L L B A C K   T R A N S A C T I O N  
 G O  
 I F   @ @ T R A N C O U N T = 0   B E G I N   I N S E R T   I N T O   # t m p E r r o r s   ( E r r o r )   S E L E C T   1   B E G I N   T R A N S A C T I O N   E N D  
 G O  
 P R I N T   N ' A l t e r i n g   [ d b o ] . [ g s _ V e r i f y M i n i m u m R e c o r d s ] '  
 G O  
 A L T E R   P R O C E D U R E   [ d b o ] . [ g s _ V e r i f y M i n i m u m R e c o r d s ]  
 (  
 	 @ G a l l e r y I D   i n t  
 )  
 A S  
 S E T   N O C O U N T ,   X A C T _ A B O R T   O N  
 / *   V e r i f y   t h a t   c e r t a i n   t a b l e s   h a v e   t h e   r e q u i r e d   r e c o r d s ,   i n s e r t i n g   t h e m   i f   n e c e s s a r y .   T h i s   p r o c   i s   d e s i g n e d    
 t o   b e   r u n   e a c h   t i m e   t h e   a p p l i c a t i o n   s t a r t s .   T h i s   p r o c   i s   e s p e c i a l l y   i m p o r t a n t   t h e   f i r s t   t i m e   G a l l e r y   S e r v e r    
 i s   r u n   a s   G a l l e r y   S e r v e r   d e p e n d s   o n   t h i s   p r o c   t o   i n s t a l l   t h e   d e f a u l t   s e t   o f   d a t a .  
  
 G a l l e r y :   T h i s   t a b l e   r e q u i r e s   a t   l e a s t   o n e   r e c o r d   t o   r e p r e s e n t   t h e   c u r r e n t   g a l l e r y .   I f   n o   r e c o r d s   a r e  
 	 	 	 f o u n d ,   o n e   i s   i n s e r t e d   w i t h   a   I D   e q u a l   t o   t h e   @ G a l l e r y I D   p a r a m e t e r .  
 A l b u m :   T h i s   t a b l e   r e q u i r e s   a t   l e a s t   o n e   r e c o r d   t o   r e p r e s e n t   t h e   r o o t   a l b u m .   I f   n o   r e c o r d s   a r e   f o u n d ,    
               a   n e w   r e c o r d   r e p r e s e n t i n g   t h e   r o o t   a l b u m   i s   a d d e d .  
 S y n c h r o n i z e :   T h i s   t a b l e   r e q u i r e s   o n e   r e c o r d   f o r   e a c h   g a l l e r y .   I t   s t o r e s   t h e   c u r r e n t   s t a t e   o f   a   s y n c h r o n i z a t i o n ,  
 	 	 	 i f   o n e   i s   i n   p r o g r e s s .   W h e n   a   s y n c h r o n i z a t i o n   i s   n o t   i n   p r o g r e s s ,   t h e   S y n c h S t a t e   f i e l d   s h o u l d   b e   z e r o  
 	 	 	 f o r   t h i s   g a l l e r y .  
 * /  
  
 / *   * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *   * /  
 - -                     C h e c k   t h e   G a l l e r y   t a b l e  
 / *   * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *   * /  
 B E G I N   T R A N  
 I F   N O T   E X I S T S   ( S E L E C T   *   F R O M   [ g s _ G a l l e r y ]   W I T H   ( U P D L O C K ,   H O L D L O C K )   W H E R E   G a l l e r y I D   =   @ G a l l e r y I D )  
 B E G I N  
 	 I N S E R T   g s _ G a l l e r y   ( G a l l e r y I d ,   D e s c r i p t i o n )  
 	 V A L U E S   ( @ G a l l e r y I d ,   ' M y   G a l l e r y ' )  
 E N D  
 C O M M I T  
  
 / *   * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *   * /  
 - -                     C h e c k   t h e   A l b u m   t a b l e  
 / *   * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *   * /  
 B E G I N   T R A N  
 I F   N O T   E X I S T S   ( S E L E C T   *   F R O M   [ g s _ A l b u m ]   W I T H   ( U P D L O C K ,   H O L D L O C K )   W H E R E   A l b u m P a r e n t I D   =   0   A N D   F K G a l l e r y I D   =   @ G a l l e r y I D )  
 B E G I N  
     / *   T h e   a l b u m   t a b l e   d o e s   n o t   h a v e   a   r o o t   a l b u m   f o r   t h e   s p e c i f i e d   g a l l e r y .   I n s e r t   o n e .   * /  
     I N S E R T   [ g s _ A l b u m ]   ( A l b u m P a r e n t I D ,   F K G a l l e r y I d ,   T i t l e ,   D i r e c t o r y N a m e ,   S u m m a r y ,   T h u m b n a i l M e d i a O b j e c t I D ,   S e q ,   C r e a t e d B y ,   D a t e A d d e d ,   L a s t M o d i f i e d B y ,   D a t e L a s t M o d i f i e d ,   O w n e d B y ,   I s P r i v a t e )  
     V A L U E S   ( 0 ,   @ G a l l e r y I D ,   ' A l l   a l b u m s ' ,   ' ' , ' W e l c o m e   t o   G a l l e r y   S e r v e r   P r o ! ' ,   0 ,   0 ,   ' g s _ V e r i f y M i n i m u m R e c o r d s ' ,   G E T D A T E ( ) ,   ' g s _ V e r i f y M i n i m u m R e c o r d s ' ,   G E T D A T E ( ) ,   ' g s _ V e r i f y M i n i m u m R e c o r d s ' ,   0 )  
 E N D    
 C O M M I T  
  
 / *   * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *   * /  
 - -                     C h e c k   t h e   S y n c h r o n i z e   t a b l e  
 / *   * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *   * /  
 B E G I N   T R A N  
 I F   E X I S T S   ( S E L E C T   *   F R O M   [ g s _ S y n c h r o n i z e ]   W I T H   ( U P D L O C K ,   H O L D L O C K )   W H E R E   F K G a l l e r y I D   =   @ G a l l e r y I D )  
 B E G I N   - -   R e s e t   r e c o r d   t o   c l e a r   o u t   a n y   p r e v i o u s   s y n c h r o n i z a t i o n  
 	 U P D A T E   g s _ S y n c h r o n i z e  
 	 S E T   S y n c h I D   =   ' ' ,  
 	 S y n c h S t a t e   =   0 ,  
 	 T o t a l F i l e s   =   0 ,  
 	 C u r r e n t F i l e I n d e x   =   0  
 	 W H E R E   F K G a l l e r y I D   =   @ G a l l e r y I d  
 E N D  
 E L S E  
 B E G I N  
 	 I N S E R T   I N T O   g s _ S y n c h r o n i z e   ( S y n c h I D ,   F K G a l l e r y I D ,   S y n c h S t a t e ,   T o t a l F i l e s ,   C u r r e n t F i l e I n d e x )  
 	 V A L U E S   ( ' ' , @ G a l l e r y I d ,   0 ,   0 ,   0 )  
 E N D  
 C O M M I T  
  
 R E T U R N  
 G O  
 I F   @ @ E R R O R < > 0   A N D   @ @ T R A N C O U N T > 0   R O L L B A C K   T R A N S A C T I O N  
 G O  
 I F   @ @ T R A N C O U N T = 0   B E G I N   I N S E R T   I N T O   # t m p E r r o r s   ( E r r o r )   S E L E C T   1   B E G I N   T R A N S A C T I O N   E N D  
 G O  
 P R I N T   N ' A l t e r i n g   [ d b o ] . [ g s _ R o l e U p d a t e ] '  
 G O  
 A L T E R   P R O C E D U R E   [ d b o ] . [ g s _ R o l e U p d a t e ]  
 (  
 	 @ G a l l e r y I d   i n t ,   @ R o l e N a m e   n v a r c h a r ( 2 5 6 ) ,   @ A l l o w V i e w A l b u m s A n d O b j e c t s   b i t ,   @ A l l o w V i e w O r i g i n a l I m a g e   b i t ,  
 	 @ A l l o w A d d C h i l d A l b u m   b i t ,   @ A l l o w A d d M e d i a O b j e c t   b i t ,   @ A l l o w E d i t A l b u m   b i t ,   @ A l l o w E d i t M e d i a O b j e c t   b i t ,  
 	 @ A l l o w D e l e t e C h i l d A l b u m   b i t ,   @ A l l o w D e l e t e M e d i a O b j e c t   b i t ,   @ A l l o w S y n c h r o n i z e   b i t ,   @ H i d e W a t e r m a r k   b i t ,  
 	 @ A l l o w A d m i n i s t e r S i t e   b i t  
 )  
 A S  
 S E T   N O C O U N T ,   X A C T _ A B O R T   O N  
  
 / *   U p d a t e   t h e   s p e c i f i e d   r o l e .   I f   t h e   r o l e   d o e s   n o t   e x i s t ,   a s s u m e   i t   i s   n e w   a n d   c a l l   t h e   i n s e r t   p r o c .   * /  
 B E G I N   T R A N  
 I F   E X I S T S   ( S E L E C T   *   F R O M   [ g s _ R o l e ]   W I T H   ( U P D L O C K ,   H O L D L O C K )   W H E R E   F K G a l l e r y I d   =   @ G a l l e r y I d   A N D   R o l e N a m e   =   @ R o l e N a m e )  
 B E G I N  
 	 U P D A T E   [ g s _ R o l e ]  
 	 S E T   A l l o w V i e w A l b u m s A n d O b j e c t s   =   @ A l l o w V i e w A l b u m s A n d O b j e c t s ,  
 	 	 A l l o w V i e w O r i g i n a l I m a g e   =   @ A l l o w V i e w O r i g i n a l I m a g e ,  
 	 	 A l l o w A d d C h i l d A l b u m   =   @ A l l o w A d d C h i l d A l b u m ,  
 	 	 A l l o w A d d M e d i a O b j e c t   =   @ A l l o w A d d M e d i a O b j e c t ,  
 	 	 A l l o w E d i t A l b u m   =   @ A l l o w E d i t A l b u m ,  
 	 	 A l l o w E d i t M e d i a O b j e c t   =   @ A l l o w E d i t M e d i a O b j e c t ,  
 	 	 A l l o w D e l e t e C h i l d A l b u m   =   @ A l l o w D e l e t e C h i l d A l b u m ,  
 	 	 A l l o w D e l e t e M e d i a O b j e c t   =   @ A l l o w D e l e t e M e d i a O b j e c t ,  
 	 	 A l l o w S y n c h r o n i z e   =   @ A l l o w S y n c h r o n i z e ,  
 	 	 H i d e W a t e r m a r k   =   @ H i d e W a t e r m a r k ,    
 	 	 A l l o w A d m i n i s t e r S i t e   =   @ A l l o w A d m i n i s t e r S i t e  
 	 W H E R E   F K G a l l e r y I d   =   @ G a l l e r y I d   A N D   R o l e N a m e   =   @ R o l e N a m e  
 E N D  
 E L S E  
 B E G I N  
 	 E X E C U T E   [ d b o ] . [ g s _ R o l e I n s e r t ]    
 	 	 @ G a l l e r y I d ,  
 	 	 @ R o l e N a m e ,  
 	 	 @ A l l o w V i e w A l b u m s A n d O b j e c t s ,  
 	 	 @ A l l o w V i e w O r i g i n a l I m a g e ,  
 	 	 @ A l l o w A d d C h i l d A l b u m ,  
 	 	 @ A l l o w A d d M e d i a O b j e c t ,  
 	 	 @ A l l o w E d i t A l b u m ,  
 	 	 @ A l l o w E d i t M e d i a O b j e c t ,  
 	 	 @ A l l o w D e l e t e C h i l d A l b u m ,  
 	 	 @ A l l o w D e l e t e M e d i a O b j e c t ,  
 	 	 @ A l l o w S y n c h r o n i z e ,  
 	 	 @ H i d e W a t e r m a r k ,  
 	 	 @ A l l o w A d m i n i s t e r S i t e  
 E N D  
 C O M M I T  
  
 R E T U R N  
 G O  
 I F   @ @ E R R O R < > 0   A N D   @ @ T R A N C O U N T > 0   R O L L B A C K   T R A N S A C T I O N  
 G O  
 I F   @ @ T R A N C O U N T = 0   B E G I N   I N S E R T   I N T O   # t m p E r r o r s   ( E r r o r )   S E L E C T   1   B E G I N   T R A N S A C T I O N   E N D  
 G O  
 P R I N T   N ' A l t e r i n g   [ d b o ] . [ g s _ I n i t i a l i z e G a l l e r y S e r v e r P r o ] '  
 G O  
 A L T E R   P R O C E D U R E   [ d b o ] . [ g s _ I n i t i a l i z e G a l l e r y S e r v e r P r o ]  
 (  
 	 @ G a l l e r y I D   i n t ,  
 	 @ A p p l i c a t i o n N a m e   n v a r c h a r ( 5 1 2 ) ,  
 	 @ S y s A d m i n R o l e N a m e   n v a r c h a r ( 2 5 6 ) ,  
 	 @ S y s A d m i n R o l e N a m e D e s c r i p t i o n   n v a r c h a r ( 2 5 6 ) ,  
 	 @ A d m i n E m a i l   n v a r c h a r ( 2 5 6 ) ,  
 	 @ A d m i n U s e r N a m e   n v a r c h a r ( 2 5 6 ) ,  
 	 @ A d m i n P a s s w o r d   n v a r c h a r ( 2 5 6 ) ,  
 	 @ P a s s w o r d F o r m a t   i n t   =   0 , 	 - -   0   =   c l e a r   t e x t ,   1   =   e n c r y p t e d  
 	 @ C r e a t e S a m p l e s   b i t   =   1  
 )  
 A S  
 S E T   N O C O U N T   O N  
  
 / *   T h i s   p r o c e d u r e   i s   c a l l e d   f r o m   t h e   w e b   i n s t a l l e r .   I t   s e t s   u p   t h e   a d m i n i s t r a t o r   u s e r   a n d   e n s u r e s    
 c e r t a i n   t a b l e s   h a v e   d e f a u l t   r e c o r d s .   * /  
  
 / *   * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *   * /  
 - -           V e r i f y   c e r t a i n   t a b l e s   h a v e   d e f a u l t   r e c o r d s  
 / *   * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *   * /  
 E X E C   d b o . g s _ V e r i f y M i n i m u m R e c o r d s   @ G a l l e r y I D  
  
 / *   * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *   * /  
 - -                                     M e m b e r s h i p   R o u t i n e s  
 / *   * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *   * /  
 D E C L A R E   @ A p p l i c a t i o n I D   u n i q u e i d e n t i f i e r  
 D E C L A R E   @ A p p l i c a t i o n A l r e a d y E x i s t s   b i t  
 D E C L A R E   @ R o o t A l b u m I d   i n t  
 D E C L A R E   @ A d m i n U s e r I d   u n i q u e i d e n t i f i e r  
  
 I F   ( N O T   E X I S T S   ( S E L E C T   n a m e   F R O M   s y s o b j e c t s   W H E R E   ( n a m e   =   N ' a s p n e t _ A p p l i c a t i o n s ' )   A N D   ( t y p e   =   ' U ' ) ) )  
 	 R E T U R N   - -   N o   M e m b e r s h i p   t a b l e s   i n   t h i s   d a t a b a s e .   U s e r   p r e s u m a b l y   w a n t s   t o   c o n n e c t   t o   a   M e m b e r s h i p   i n f r a s t r u c t u r e   i n    
 	 	 	 	   - -   a   r e m o t e   d a t a b a s e .   T h i s   m u s t   b e   d o n e   m a n u a l l y   s o   l e t ' s   j u s t   e x i t .  
 	  
 - -   G e t   r o o t   a l b u m   I D  
 S E L E C T   @ R o o t A l b u m I d   =   A l b u m I D   F R O M   g s _ A l b u m   W H E R E   ( A l b u m P a r e n t I D   =   0 )  
  
 - - G e t   o r   C r e a t e   t h e   A p p l i c a t i o n   I D .  
 - - A n   A p p l i c a t i o n N a m e / I D   c a n   e x i s t   i n   m o r e   t h a n   o n e   s i t e ,   s o   i t   d o e s   n o t   n e e d   t o   b e   u n i q u e  
 S e t   @ A p p l i c a t i o n I D   =   n u l l  
  
 S e l e c t   @ A p p l i c a t i o n I D   =   A p p l i c a t i o n I d   F R O M   a s p n e t _ A p p l i c a t i o n s   w h e r e     L o w e r e d A p p l i c a t i o n N a m e   =   L o w e r ( @ A p p l i c a t i o n N a m e )  
  
  
 I F ( @ A p p l i c a t i o n I D   i s     n u l l )  
 B E G I N   / *   A p p l i c a t i o n   d o e s n ' t   e x i s t   s o   l e t ' s   c r e a t e   i t   * /  
 	 E X E C   a s p n e t _ A p p l i c a t i o n s _ C r e a t e A p p l i c a t i o n   @ A p p l i c a t i o n N a m e ,   @ A p p l i c a t i o n I d   =   @ A p p l i c a t i o n I D   O U T P U T  
 	 S e t   @ A p p l i c a t i o n A l r e a d y E x i s t s   =   0  
 E N D  
 E L S E  
 	 S e t   @ A p p l i c a t i o n A l r e a d y E x i s t s   =   1  
  
 / *   * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *   * /  
 / *   I f   G a l l e r y   S e r v e r   P r o   a p p   d o e s n ' t   e x i s t ,   c r e a t e   s y s   a d m i n    
 	   r o l e   a n d   a d m i n   u s e r ;   o t h e r w i s e   c r e a t e   t h e   r o l e   a n d   u s e r  
 	   o n l y   i f   t h e y   d o n ' t   a l r e a d y   e x i s t .   * /  
 / *   * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *   * /  
 I F ( @ A p p l i c a t i o n A l r e a d y E x i s t s   =   0 )  
 B E G I N  
 	 / *   * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *   * /  
 	 - - 	 	 	 G a l l e r y   S e r v e r   P r o   a p p   e x i s t s  
 	 - -           C r e a t e   s y s t e m   a d m i n i s t r a t o r   r o l e  
 	 / *   * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *   * /  
 	 I N S E R T   I N T O   [ a s p n e t _ R o l e s ]   ( [ R o l e I d ] ,   [ A p p l i c a t i o n I d ] ,   [ R o l e N a m e ] ,   [ L o w e r e d R o l e N a m e ] ,   [ D e s c r i p t i o n ] )  
 	 V A L U E S   ( n e w I D ( ) ,   @ A p p l i c a t i o n I D ,   @ S y s A d m i n R o l e N a m e ,   L o w e r ( @ S y s A d m i n R o l e N a m e ) ,   @ S y s A d m i n R o l e N a m e D e s c r i p t i o n ) 	  
  
 	 / *   * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *   * /  
 	 - -                                           C r e a t e   a d m i n   u s e r  
 	 / *   * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *   * /  
 	 S e t   @ A d m i n U s e r I d   =   n e w i d ( )  
  
 	 I N S E R T   I N T O   [ a s p n e t _ U s e r s ]   ( [ U s e r I d ] ,   [ A p p l i c a t i o n I d ] ,   [ U s e r N a m e ] ,   [ L o w e r e d U s e r N a m e ] ,   [ M o b i l e A l i a s ] ,   [ I s A n o n y m o u s ] ,   [ L a s t A c t i v i t y D a t e ] )    
 	 	 V A L U E S   ( @ A d m i n U s e r I d ,   @ A p p l i c a t i o n I D ,   @ A d m i n U s e r N a m e ,   L o w e r ( @ A d m i n U s e r N a m e ) ,   N U L L ,   0 ,   g e t d a t e ( ) )  
  
 	 I N S E R T   I N T O   [ a s p n e t _ M e m b e r s h i p ]   ( [ A p p l i c a t i o n I d ] ,   [ U s e r I d ] ,   [ P a s s w o r d ] ,   [ P a s s w o r d F o r m a t ] ,   [ P a s s w o r d S a l t ] ,   [ M o b i l e P I N ] ,   [ E m a i l ] ,   [ L o w e r e d E m a i l ] ,   [ P a s s w o r d Q u e s t i o n ] ,   [ P a s s w o r d A n s w e r ] ,   [ I s A p p r o v e d ] ,   [ C r e a t e D a t e ] ,   [ L a s t L o g i n D a t e ] ,   [ L a s t P a s s w o r d C h a n g e d D a t e ] ,   [ C o m m e n t ] ,   F a i l e d P a s s w o r d A n s w e r A t t e m p t W i n d o w S t a r t ,   F a i l e d P a s s w o r d A n s w e r A t t e m p t C o u n t ,   F a i l e d P a s s w o r d A t t e m p t W i n d o w S t a r t ,   F a i l e d P a s s w o r d A t t e m p t C o u n t ,   L a s t L o c k o u t D a t e ,   I s L o c k e d O u t )    
 	 	 V A L U E S   ( @ A p p l i c a t i o n I D ,   @ A d m i n U s e r I d ,     @ A d m i n P a s s w o r d ,   @ P a s s w o r d F o r m a t ,     N ' D V Z T k t x e M z D t X R 7 e i k 7 C d w = = ' ,   N U L L ,   @ A d m i n E m a i l ,         N U L L ,                         N U L L ,                               N U L L ,                         1 ,                         g e t d a t e ( ) ,         g e t d a t e ( ) ,               g e t d a t e ( ) ,                                   N U L L ,                                   ' 1 7 5 3 - 0 1 - 0 1 ' ,                                                             0 ,                                                               ' 1 7 5 3 - 0 1 - 0 1 ' ,                                               0 ,                                                     ' 1 7 5 3 - 0 1 - 0 1 ' ,             0 )  
  
 	 / *   * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *   * /  
 	 - -   A d d   n e w   a d m i n   u s e r   t o   a l l   r o l e s   f o r   t h i s   a p p l i c a t i o n ,   w h i c h    
 	 - -   w i l l   p r o b a b l y   j u s t   b e   t h e   s y s t e m   a d m i n   r o l e   w e   c r e a t e d .  
 	 / *   * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *   * /  
 	 I N S E R T   I N T O   a s p n e t _ U s e r s I n R o l e s   ( U s e r I d ,   R o l e I d )    
 	 S E L E C T   @ A d m i n U s e r I d ,   R o l e I d   F R O M   a s p n e t _ R o l e s   W H E R E   A p p l i c a t i o n I d   =   @ A p p l i c a t i o n I D  
  
 	 / *   * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *   * /  
 	 - -   C r e a t e   g a l l e r y   s e r v e r   r o l e   t h a t   a p p l i e s   t o   r o o t   a l b u m .  
 	 / *   * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *   * /  
 	 I N S E R T   I N T O   [ g s _ R o l e ]   ( F K G a l l e r y I d ,   R o l e N a m e ,   A l l o w V i e w A l b u m s A n d O b j e c t s ,   A l l o w V i e w O r i g i n a l I m a g e ,   A l l o w A d d C h i l d A l b u m ,  
 	 	 A l l o w A d d M e d i a O b j e c t ,   A l l o w E d i t A l b u m ,   A l l o w E d i t M e d i a O b j e c t ,   A l l o w D e l e t e C h i l d A l b u m ,   A l l o w D e l e t e M e d i a O b j e c t ,    
 	 	 A l l o w S y n c h r o n i z e ,   H i d e W a t e r m a r k ,   A l l o w A d m i n i s t e r S i t e )  
 	 V A L U E S   ( @ G a l l e r y I D ,   @ S y s A d m i n R o l e N a m e ,   1 ,   1 ,   1 , 	 1 ,   1 ,   1 ,   1 ,   1 ,   1 ,   0 ,   1 )  
 	  
 	 I N S E R T   I N T O   [ g s _ R o l e _ A l b u m ]   ( F K R o l e N a m e ,   F K A l b u m I d )  
 	 V A L U E S   ( @ S y s A d m i n R o l e N a m e ,   @ R o o t A l b u m I d )  
 E N D  
 E L S E   - -   G a l l e r y   S e r v e r   P r o   a p p   a l r e a d y   e x i s t s   ( @ A p p l i c a t i o n A l r e a d y E x i s t s   =   1 )  
 B E G I N  
 	 - -   D o e s   a d m i n   u s e r   e x i s t   f o r   t h i s   a p p l i c a t i o n ?   C r e a t e   i t   i f   n o t .    
 	 S e t   @ A d m i n U s e r I d   =   N U L L  
 	 S E L E C T   @ A d m i n U s e r I d   =   U s e r I d   F R O M   a s p n e t _ U s e r s   W H E R E   ( U s e r N a m e   =   @ A d m i n U s e r N a m e )   A N D   ( A p p l i c a t i o n I d   =   @ A p p l i c a t i o n I D )  
 	  
 	 I F   @ A d m i n U s e r I d   =   N U L L  
 	 B E G I N   - -   A d m i n   u s e r   d o e s   n o t   e x i s t .   C r e a t e   i t .  
 	 	 S e t   @ A d m i n U s e r I d   =   n e w i d ( )  
  
 	 	 I N S E R T   I N T O   [ a s p n e t _ U s e r s ]   ( [ U s e r I d ] ,   [ A p p l i c a t i o n I d ] ,   [ U s e r N a m e ] ,   [ L o w e r e d U s e r N a m e ] ,   [ M o b i l e A l i a s ] ,   [ I s A n o n y m o u s ] ,   [ L a s t A c t i v i t y D a t e ] )    
 	 	 	 V A L U E S   ( @ A d m i n U s e r I d ,   @ A p p l i c a t i o n I D ,   @ A d m i n U s e r N a m e ,   L o w e r ( @ A d m i n U s e r N a m e ) ,   N U L L ,   0 ,   g e t d a t e ( ) )  
  
 	 	 I N S E R T   I N T O   [ a s p n e t _ M e m b e r s h i p ]   ( [ A p p l i c a t i o n I d ] ,   [ U s e r I d ] ,   [ P a s s w o r d ] ,           [ P a s s w o r d F o r m a t ] ,   [ P a s s w o r d S a l t ] ,                             [ M o b i l e P I N ] ,   [ E m a i l ] ,   [ L o w e r e d E m a i l ] ,   [ P a s s w o r d Q u e s t i o n ] ,   [ P a s s w o r d A n s w e r ] ,   [ I s A p p r o v e d ] ,   [ C r e a t e D a t e ] ,   [ L a s t L o g i n D a t e ] ,   [ L a s t P a s s w o r d C h a n g e d D a t e ] ,   [ C o m m e n t ] ,   F a i l e d P a s s w o r d A n s w e r A t t e m p t W i n d o w S t a r t ,   F a i l e d P a s s w o r d A n s w e r A t t e m p t C o u n t ,   F a i l e d P a s s w o r d A t t e m p t W i n d o w S t a r t ,   F a i l e d P a s s w o r d A t t e m p t C o u n t ,   L a s t L o c k o u t D a t e ,   I s L o c k e d O u t )    
 	 	 	 V A L U E S   ( @ A p p l i c a t i o n I D ,   @ A d m i n U s e r I d ,     @ A d m i n P a s s w o r d ,   @ P a s s w o r d F o r m a t ,       N ' D V Z T k t x e M z D t X R 7 e i k 7 C d w = = ' ,   N U L L ,               @ A d m i n E m a i l ,         N U L L ,                         N U L L ,                               N U L L ,                         1 ,                         g e t d a t e ( ) ,         g e t d a t e ( ) ,               g e t d a t e ( ) ,                                   N U L L ,                                   ' 1 7 5 3 - 0 1 - 0 1 ' ,                                                             0 ,                                                               ' 1 7 5 3 - 0 1 - 0 1 ' ,                                               0 ,                                                     ' 1 7 5 3 - 0 1 - 0 1 ' ,             0 )  
 	 E N D  
 	 E L S E  
 	 B E G I N   - -   A d m i n   u s e r   e x i s t s .   M a k e   s u r e   p a s s w o r d   m a t c h e s   t h e   o n e   p a s s e d   t o   t h i s   p r o c e d u r e  
 	 	 U P D A T E   a s p n e t _ M e m b e r s h i p  
 	 	 S E T   P a s s w o r d   =   @ A d m i n P a s s w o r d ,   P a s s w o r d F o r m a t   =   @ P a s s w o r d F o r m a t  
 	 	 W H E R E   U s e r I d   =   @ A d m i n U s e r I d  
 	 E N D  
  
 	 - -   D o e s   s y s   a d m i n   r o l e   e x i s t   f o r   t h i s   a p p l i c a t i o n ?   C r e a t e   i t   i f   n o t .  
 	 I F   N O T   E X I S T S ( S E L E C T   *   F R O M   [ a s p n e t _ R o l e s ]   W H E R E   R o l e N a m e   =   @ S y s A d m i n R o l e N a m e   A N D   A p p l i c a t i o n I d   =   @ A p p l i c a t i o n I D )  
 	 	 I N S E R T   I N T O   [ a s p n e t _ R o l e s ]   ( [ R o l e I d ] ,   [ A p p l i c a t i o n I d ] ,   [ R o l e N a m e ] ,   [ L o w e r e d R o l e N a m e ] ,   [ D e s c r i p t i o n ] )  
 	 	 	 V A L U E S   ( n e w I D ( ) ,   @ A p p l i c a t i o n I D ,   @ S y s A d m i n R o l e N a m e ,   L o w e r ( @ S y s A d m i n R o l e N a m e ) ,   @ S y s A d m i n R o l e N a m e D e s c r i p t i o n ) 	  
 	 	    
 	 - -   M a k e   s u r e   a d m i n   u s e r   i s   p a r t   o f   s y s   a d m i n   r o l e .  
 	 I F   N O T   E X I S T S ( S E L E C T   a s p n e t _ U s e r s I n R o l e s . *  
 	 	 	 	 	 	 	 	 F R O M   a s p n e t _ U s e r s I n R o l e s   I N N E R   J O I N   a s p n e t _ R o l e s   O N   a s p n e t _ U s e r s I n R o l e s . R o l e I d   =   a s p n e t _ R o l e s . R o l e I d  
 	 	 	 	 	 	 	 	 W H E R E   a s p n e t _ U s e r s I n R o l e s . U s e r I d   =   @ A d m i n U s e r I d   A N D   a s p n e t _ R o l e s . R o l e N a m e   =   @ S y s A d m i n R o l e N a m e   A N D   a s p n e t _ R o l e s . A p p l i c a t i o n I d   =   @ A p p l i c a t i o n I D )  
 	 	 I N S E R T   I N T O   a s p n e t _ U s e r s I n R o l e s   ( U s e r I d ,   R o l e I d )    
 	 	 S E L E C T   @ A d m i n U s e r I d ,   R o l e I d   F R O M   a s p n e t _ R o l e s   W H E R E   R o l e N a m e   =   @ S y s A d m i n R o l e N a m e   A N D   A p p l i c a t i o n I d   =   @ A p p l i c a t i o n I D  
  
 	 - -   M a k e   s u r e   s y s   a d m i n   r o l e   i s   a   g a l l e r y   s e r v e r   r o l e   a s s i g n e d   t o   t h e   r o o t   a l b u m .  
 	 I F   N O T   E X I S T S ( S E L E C T   *   F R O M   [ g s _ R o l e ]   W H E R E   R o l e N a m e   =   @ S y s A d m i n R o l e N a m e   A N D   F K G a l l e r y I d   =   @ G a l l e r y I D )  
 	 	 I N S E R T   I N T O   [ g s _ R o l e ]   ( F K G a l l e r y I d ,   R o l e N a m e ,   A l l o w V i e w A l b u m s A n d O b j e c t s ,   A l l o w V i e w O r i g i n a l I m a g e ,   A l l o w A d d C h i l d A l b u m ,  
 	 	 	 A l l o w A d d M e d i a O b j e c t ,   A l l o w E d i t A l b u m ,   A l l o w E d i t M e d i a O b j e c t ,   A l l o w D e l e t e C h i l d A l b u m ,   A l l o w D e l e t e M e d i a O b j e c t ,    
 	 	 	 A l l o w S y n c h r o n i z e ,   H i d e W a t e r m a r k ,   A l l o w A d m i n i s t e r S i t e )  
 	 	 V A L U E S   ( @ G a l l e r y I D ,   @ S y s A d m i n R o l e N a m e ,   1 ,   1 ,   1 , 	 1 ,   1 ,   1 ,   1 ,   1 ,   1 ,   0 ,   1 )  
 	  
 	 I F   N O T   E X I S T S ( S E L E C T   *   F R O M   [ g s _ R o l e _ A l b u m ]   W H E R E   F K R o l e N a m e   =   @ S y s A d m i n R o l e N a m e )  
 	 	 I N S E R T   I N T O   [ g s _ R o l e _ A l b u m ]   ( F K R o l e N a m e ,   F K A l b u m I d )  
 	 	 V A L U E S   ( @ S y s A d m i n R o l e N a m e ,   @ R o o t A l b u m I d )  
 E N D 	  
  
 I F   @ C r e a t e S a m p l e s   =   1  
 B E G I N  
 	 D E C L A R E   @ n e w A l b u m I d   i n t  
 	 D E C L A R E   @ n e w M e d i a O b j e c t I d   i n t  
 	  
 	 / *   C r e a t e   a n   a l b u m   c a l l e d   S a m p l e s .   * /  
 	 I N S E R T   [ g s _ A l b u m ]   ( A l b u m P a r e n t I D ,   F K G a l l e r y I D ,   T i t l e ,   D i r e c t o r y N a m e ,   S u m m a r y ,   T h u m b n a i l M e d i a O b j e c t I D ,   S e q ,   D a t e S t a r t ,   D a t e E n d ,   C r e a t e d B y ,   D a t e A d d e d ,   L a s t M o d i f i e d B y ,   D a t e L a s t M o d i f i e d ,   O w n e d B y ,   I s P r i v a t e )  
 	 V A L U E S   ( @ R o o t A l b u m I d ,   @ G a l l e r y I D ,   ' S a m p l e s ' ,   ' S a m p l e s ' ,   ' D e a t h   V a l l e y ' ,   0 ,   1 ,   G E T D A T E ( ) ,   D A T E A D D ( w e e k ,   2 ,   G E T D A T E ( ) ) ,   @ A d m i n U s e r N a m e ,   G E T D A T E ( ) ,   @ A d m i n U s e r N a m e ,   G E T D A T E ( ) ,   @ A d m i n U s e r N a m e ,   0 )  
  
 	 S E T   @ n e w A l b u m I d   =   S C O P E _ I D E N T I T Y ( )  
 	  
 	 I N S E R T   [ g s _ M e d i a O b j e c t ]   ( H a s h K e y ,   F K A l b u m I D ,   T h u m b n a i l F i l e n a m e ,   T h u m b n a i l W i d t h ,   T h u m b n a i l H e i g h t ,  
 	   T h u m b n a i l S i z e K B ,   O p t i m i z e d F i l e n a m e ,   O p t i m i z e d W i d t h ,   O p t i m i z e d H e i g h t ,   O p t i m i z e d S i z e K B ,  
 	   O r i g i n a l F i l e n a m e ,   O r i g i n a l W i d t h ,   O r i g i n a l H e i g h t ,   O r i g i n a l S i z e K B ,   T i t l e ,   S e q ,   C r e a t e d B y ,    
 	   D a t e A d d e d ,   L a s t M o d i f i e d B y ,   D a t e L a s t M o d i f i e d ,   I s P r i v a t e )  
 	 V A L U E S   ( ' 4 C - A 8 - D 6 - E 6 - 8 8 - 2 9 - 2 8 - B E - 3 A - 7 9 - E F - 0 B - F 5 - 9 B - 2 D - E E ' ,   @ n e w A l b u m I d ,   ' z T h u m b _ D e a t h V a l l e y . j p e g ' ,   1 1 5 ,   8 6 ,  
 	   2 ,   ' D e a t h V a l l e y . j p e g ' ,   6 4 0 ,   4 8 0 ,   4 8 ,   ' D e a t h V a l l e y . j p e g ' ,   6 4 0 ,   4 8 0 ,   4 8 ,   ' D e a t h   V a l l e y ,   C a l i f o r n i a ' ,   1 ,   @ A d m i n U s e r N a m e ,  
 	   G E T D A T E ( ) ,   @ A d m i n U s e r N a m e ,   G E T D A T E ( ) ,   0 )  
    
 	 S E T   @ n e w M e d i a O b j e c t I d   =   S C O P E _ I D E N T I T Y ( )  
 	  
 	 / *   S e t   t h i s   n e w   i m a g e   a s   t h e   t h u m b n a i l   f o r   t h e   a l b u m   * /  
 	 U P D A T E   [ g s _ A l b u m ]   S E T   T h u m b n a i l M e d i a O b j e c t I D   =   @ n e w M e d i a O b j e c t I d   W H E R E   A l b u m I D   =   @ n e w A l b u m I d  
 E N D  
 R E T U R N  
 G O  
 I F   @ @ E R R O R < > 0   A N D   @ @ T R A N C O U N T > 0   R O L L B A C K   T R A N S A C T I O N  
 G O  
 I F   @ @ T R A N C O U N T = 0   B E G I N   I N S E R T   I N T O   # t m p E r r o r s   ( E r r o r )   S E L E C T   1   B E G I N   T R A N S A C T I O N   E N D  
 G O  
 P R I N T   N ' C r e a t i n g   [ d b o ] . [ g s _ G e t V e r s i o n ] '  
 / * * * * * *   O b j e c t :     U s e r D e f i n e d F u n c t i o n   [ d b o ] . [ g s _ G e t V e r s i o n ]         S c r i p t   D a t e :   1 1 / 2 4 / 2 0 0 7   * * * * * * /  
 I F     E X I S T S   ( S E L E C T   *   F R O M   d b o . s y s o b j e c t s   W H E R E   i d   =   O B J E C T _ I D ( N ' [ d b o ] . [ g s _ G e t V e r s i o n ] ' )   A N D   x t y p e   i n   ( N ' F N ' ,   N ' I F ' ,   N ' T F ' ) )  
 D R O P   F U N C T I O N   [ d b o ] . [ g s _ G e t V e r s i o n ]  
 G O  
 C R E A T E   F U N C T I O N   [ d b o ] . [ g s _ G e t V e r s i o n ] ( )  
 R E T U R N S  
       V A R C H A R ( 2 5 5 )  
 A S  
 B E G I N  
       R E T U R N   ' 2 . 0 . 2 8 8 6 '  
 E N D  
 G O  
 I F   @ @ E R R O R < > 0   A N D   @ @ T R A N C O U N T > 0   R O L L B A C K   T R A N S A C T I O N  
 G O  
 I F   @ @ T R A N C O U N T = 0   B E G I N   I N S E R T   I N T O   # t m p E r r o r s   ( E r r o r )   S E L E C T   1   B E G I N   T R A N S A C T I O N   E N D  
 G O  
 I F   E X I S T S   ( S E L E C T   *   F R O M   # t m p E r r o r s )   R O L L B A C K   T R A N S A C T I O N  
 G O  
 P R I N T   N ' C o n f i g u r i n g   p e r m i s s i o n   f o r   u s e r   d e f i n e d   f u n c t i o n   [ d b o ] . [ g s _ G e t V e r s i o n ] '  
 G R A N T   E X E C U T E   O N   [ d b o ] . [ g s _ G e t V e r s i o n ]   T O   [ g s _ G a l l e r y S e r v e r P r o R o l e ]  
 G O  
 I F   @ @ E R R O R < > 0   A N D   @ @ T R A N C O U N T > 0   R O L L B A C K   T R A N S A C T I O N  
 G O  
 I F   @ @ T R A N C O U N T = 0   B E G I N   I N S E R T   I N T O   # t m p E r r o r s   ( E r r o r )   S E L E C T   1   B E G I N   T R A N S A C T I O N   E N D  
 G O  
 I F   E X I S T S   ( S E L E C T   *   F R O M   # t m p E r r o r s )   R O L L B A C K   T R A N S A C T I O N  
 G O  
 I F   @ @ T R A N C O U N T > 0   B E G I N  
 P R I N T   ' T h e   d a t a b a s e   u p d a t e   s u c c e e d e d . '  
 C O M M I T   T R A N S A C T I O N  
 E N D  
 E L S E   P R I N T   ' T h e   d a t a b a s e   u p d a t e   f a i l e d . '  
 G O  
 D R O P   T A B L E   # t m p E r r o r s  
 G O  
 
