2011-08-18 08:31:15 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								< ? php  if  (  !  defined ( 'BASEPATH' ))  exit ( 'No direct script access allowed' );  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								class  User  extends  CI_Controller  {  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									/* Displays all notes in a list */ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									public  function  index () 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									{ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										$this -> load -> model ( 'user_model' ); 
							 
						 
					
						
							
								
									
										
										
										
											2011-08-20 00:12:13 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										if ( ! $this -> user_model -> authorize ( 99 ))  {  $this -> session -> set_flashdata ( 'notice' ,  'You\'re not allowed to do that!' );  redirect ( 'dashboard' );  } 
							 
						 
					
						
							
								
									
										
										
										
											2011-08-18 08:31:15 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										$data [ 'results' ]  =  $this -> user_model -> users (); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										$this -> load -> view ( 'layout/header' ); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										$this -> load -> view ( 'user/main' ,  $data ); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										$this -> load -> view ( 'layout/footer' ); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									function  add ()  { 
							 
						 
					
						
							
								
									
										
										
										
											2011-08-18 09:27:53 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										$this -> load -> model ( 'user_model' ); 
							 
						 
					
						
							
								
									
										
										
										
											2011-08-20 00:12:13 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										if ( ! $this -> user_model -> authorize ( 99 ))  {  $this -> session -> set_flashdata ( 'notice' ,  'You\'re not allowed to do that!' );  redirect ( 'dashboard' );  } 
							 
						 
					
						
							
								
									
										
										
										
											2011-08-18 09:27:53 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										
							 
						 
					
						
							
								
									
										
										
										
											2011-08-18 08:31:15 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
										$this -> load -> library ( 'form_validation' ); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2011-08-18 09:27:53 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										$this -> form_validation -> set_rules ( 'user_name' ,  'Username' ,  'required' ); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										$this -> form_validation -> set_rules ( 'user_email' ,  'E-mail' ,  'required' ); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										$this -> form_validation -> set_rules ( 'user_password' ,  'Password' ,  'required' ); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										$this -> form_validation -> set_rules ( 'user_type' ,  'Type' ,  'required' ); 
							 
						 
					
						
							
								
									
										
										
										
											2011-09-27 03:45:07 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										$this -> form_validation -> set_rules ( 'user_firstname' ,  'First name' ,  'required' ); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										$this -> form_validation -> set_rules ( 'user_lastname' ,  'Last name' ,  'required' ); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										$this -> form_validation -> set_rules ( 'user_callsign' ,  'Callsign' ,  'required' ); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										$this -> form_validation -> set_rules ( 'user_locator' ,  'Locator' ,  'required' ); 
							 
						 
					
						
							
								
									
										
										
										
											2011-09-28 06:47:25 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										$this -> form_validation -> set_rules ( 'user_timezone' ,  'Timezone' ,  'required' ); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										// Get timezones
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										$data [ 'timezones' ]  =  $this -> user_model -> timezones (); 
							 
						 
					
						
							
								
									
										
										
										
											2011-08-18 08:31:15 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										if  ( $this -> form_validation -> run ()  ==  FALSE ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										{ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											$this -> load -> view ( 'layout/header' ); 
							 
						 
					
						
							
								
									
										
										
										
											2011-08-18 09:27:53 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											if ( $this -> input -> post ( 'user_name' )) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											{ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												$data [ 'user_name' ]  =  $this -> input -> post ( 'user_name' ); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												$data [ 'user_email' ]  =  $this -> input -> post ( 'user_email' ); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												$data [ 'user_password' ]  =  $this -> input -> post ( 'user_password' ); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												$data [ 'user_type' ]  =  $this -> input -> post ( 'user_type' ); 
							 
						 
					
						
							
								
									
										
										
										
											2011-09-27 03:45:07 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
												$data [ 'user_firstname' ]  =  $this -> input -> post ( 'user_firstname' ); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												$data [ 'user_lastname' ]  =  $this -> input -> post ( 'user_lastname' ); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												$data [ 'user_callsign' ]  =  $this -> input -> post ( 'user_callsign' ); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												$data [ 'user_locator' ]  =  $this -> input -> post ( 'user_locator' ); 
							 
						 
					
						
							
								
									
										
										
										
											2011-09-28 06:47:25 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
												$data [ 'user_timezone' ]  =  $this -> input -> post ( 'user_timezone' ); 
							 
						 
					
						
							
								
									
										
										
										
											2011-08-18 09:27:53 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
												$this -> load -> view ( 'user/add' ,  $data ); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											}  else  { 
							 
						 
					
						
							
								
									
										
										
										
											2011-09-28 06:47:25 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
												$this -> load -> view ( 'user/add' ,  $data ); 
							 
						 
					
						
							
								
									
										
										
										
											2011-08-18 09:27:53 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											} 
							 
						 
					
						
							
								
									
										
										
										
											2011-08-18 08:31:15 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
											$this -> load -> view ( 'layout/footer' ); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										else 
							 
						 
					
						
							
								
									
										
										
										
											2011-08-18 09:27:53 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										{ 
							 
						 
					
						
							
								
									
										
										
										
											2011-09-28 06:47:25 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											switch ( $this -> user_model -> add ( $this -> input -> post ( 'user_name' ),  $this -> input -> post ( 'user_password' ),  $this -> input -> post ( 'user_email' ),  $this -> input -> post ( 'user_type' ),  $this -> input -> post ( 'user_firstname' ),  $this -> input -> post ( 'user_lastname' ),  $this -> input -> post ( 'user_callsign' ),  $this -> input -> post ( 'user_locator' ),  $this -> input -> post ( 'user_timezone' )))  { 
							 
						 
					
						
							
								
									
										
										
										
											2011-08-20 00:12:13 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
												// Check for errors
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												case  EUSERNAMEEXISTS : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
													$data [ 'username_error' ]  =  'Username <b>' . $this -> input -> post ( 'user_name' ) . '</b> already in use!' ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
													break ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												case  EEMAILEXISTS : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
													$data [ 'email_error' ]  =  'E-mail address <b>' . $this -> input -> post ( 'user_email' ) . '</b> already in use!' ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
													break ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												case  EPASSWORDINVALID : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
													$data [ 'password_error' ]  =  'Invalid password!' ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
													break ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												// All okay, return to user screen
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												case  OK : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
													$this -> session -> set_flashdata ( 'notice' ,  'User ' . $this -> input -> post ( 'user_name' ) . ' added' ); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
													redirect ( 'user' ); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
													return ; 
							 
						 
					
						
							
								
									
										
										
										
											2011-08-18 09:27:53 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											} 
							 
						 
					
						
							
								
									
										
										
										
											2011-08-20 00:12:13 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											$this -> load -> view ( 'layout/header' ); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											$data [ 'user_name' ]  =  $this -> input -> post ( 'user_name' ); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											$data [ 'user_email' ]  =  $this -> input -> post ( 'user_email' ); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											$data [ 'user_password' ]  =  $this -> input -> post ( 'user_password' ); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											$data [ 'user_type' ]  =  $this -> input -> post ( 'user_type' ); 
							 
						 
					
						
							
								
									
										
										
										
											2011-09-27 03:45:07 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											$data [ 'user_firstname' ]  =  $this -> input -> post ( 'user_firstname' ); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											$data [ 'user_lastname' ]  =  $this -> input -> post ( 'user_lastname' ); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											$data [ 'user_callsign' ]  =  $this -> input -> post ( 'user_callsign' ); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											$data [ 'user_locator' ]  =  $this -> input -> post ( 'user_locator' ); 
							 
						 
					
						
							
								
									
										
										
										
											2011-08-20 00:12:13 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											$this -> load -> view ( 'user/add' ,  $data ); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											$this -> load -> view ( 'layout/footer' ); 
							 
						 
					
						
							
								
									
										
										
										
											2011-08-18 08:31:15 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
										} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									function  edit ()  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										$this -> load -> model ( 'user_model' ); 
							 
						 
					
						
							
								
									
										
										
										
											2011-08-20 03:33:37 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										if (( ! $this -> user_model -> authorize ( 99 ))  &&  ( $this -> session -> userdata ( 'user_id' )  !=  $this -> uri -> segment ( 3 )))  {  $this -> session -> set_flashdata ( 'notice' ,  'You\'re not allowed to do that!' );  redirect ( 'dashboard' );  } 
							 
						 
					
						
							
								
									
										
										
										
											2011-08-18 08:31:15 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
										$query  =  $this -> user_model -> get_by_id ( $this -> uri -> segment ( 3 )); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										$this -> load -> library ( 'form_validation' ); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										$this -> form_validation -> set_rules ( 'user_name' ,  'Username' ,  'required' ); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										$this -> form_validation -> set_rules ( 'user_email' ,  'E-mail' ,  'required' ); 
							 
						 
					
						
							
								
									
										
										
										
											2011-08-20 03:33:37 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										if ( $this -> session -> userdata ( 'user_type' )  ==  99 ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										{ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											$this -> form_validation -> set_rules ( 'user_type' ,  'Type' ,  'required' ); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										} 
							 
						 
					
						
							
								
									
										
										
										
											2011-09-28 06:47:25 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										$this -> form_validation -> set_rules ( 'user_firstname' ,  'First name' ,  'required' ); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										$this -> form_validation -> set_rules ( 'user_lastname' ,  'Last name' ,  'required' ); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										$this -> form_validation -> set_rules ( 'user_callsign' ,  'Callsign' ,  'required' ); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										$this -> form_validation -> set_rules ( 'user_locator' ,  'Locator' ,  'required' ); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										$this -> form_validation -> set_rules ( 'user_timezone' ,  'Timezone' ,  'required' ); 
							 
						 
					
						
							
								
									
										
										
										
											2011-08-18 08:31:15 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2011-09-28 06:47:25 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										// Get timezones
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										$data [ 'timezones' ]  =  $this -> user_model -> timezones (); 
							 
						 
					
						
							
								
									
										
										
										
											2011-08-18 08:31:15 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										if  ( $this -> form_validation -> run ()  ==  FALSE ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										{ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											$this -> load -> view ( 'layout/header' ); 
							 
						 
					
						
							
								
									
										
										
										
											2011-08-20 03:33:37 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											$q  =  $query -> row (); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											$data [ 'id' ]  =  $q -> user_id ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											if ( $this -> input -> post ( 'user_name' ))  { 
							 
						 
					
						
							
								
									
										
										
										
											2011-08-20 00:12:13 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
												$data [ 'user_name' ]  =  $this -> input -> post ( 'user_name' ); 
							 
						 
					
						
							
								
									
										
										
										
											2011-08-20 03:33:37 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											}  else  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												$data [ 'user_name' ]  =  $q -> user_name ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											if ( $this -> input -> post ( 'user_email' ))  { 
							 
						 
					
						
							
								
									
										
										
										
											2011-08-20 00:12:13 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
												$data [ 'user_email' ]  =  $this -> input -> post ( 'user_email' ); 
							 
						 
					
						
							
								
									
										
										
										
											2011-08-20 03:33:37 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											}  else  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												$data [ 'user_email' ]  =  $q -> user_email ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											if ( $this -> input -> post ( 'user_password' ))  { 
							 
						 
					
						
							
								
									
										
										
										
											2011-08-20 00:12:13 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
												$data [ 'user_password' ]  =  $this -> input -> post ( 'user_password' ); 
							 
						 
					
						
							
								
									
										
										
										
											2011-08-20 03:33:37 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											}  else  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												$data [ 'user_password' ]  =  $q -> user_password ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											if ( $this -> input -> post ( 'user_type' ))  { 
							 
						 
					
						
							
								
									
										
										
										
											2011-08-20 00:12:13 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
												$data [ 'user_type' ]  =  $this -> input -> post ( 'user_type' ); 
							 
						 
					
						
							
								
									
										
										
										
											2011-08-20 03:33:37 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											}  else  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												$data [ 'user_type' ]  =  $q -> user_type ; 
							 
						 
					
						
							
								
									
										
										
										
											2011-08-20 00:12:13 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											} 
							 
						 
					
						
							
								
									
										
										
										
											2011-08-20 03:33:37 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											if ( $this -> input -> post ( 'user_callsign' ))  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												$data [ 'user_callsign' ]  =  $this -> input -> post ( 'user_callsign' ); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											}  else  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												$data [ 'user_callsign' ]  =  $q -> user_callsign ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											if ( $this -> input -> post ( 'user_locator' ))  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												$data [ 'user_locator' ]  =  $this -> input -> post ( 'user_locator' ); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											}  else  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												$data [ 'user_locator' ]  =  $q -> user_locator ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											if ( $this -> input -> post ( 'user_firstname' ))  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												$data [ 'user_firstname' ]  =  $this -> input -> post ( 'user_firstname' ); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											}  else  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												$data [ 'user_firstname' ]  =  $q -> user_firstname ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											if ( $this -> input -> post ( 'user_lastname' ))  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												$data [ 'user_lastname' ]  =  $this -> input -> post ( 'user_lastname' ); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											}  else  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												$data [ 'user_lastname' ]  =  $q -> user_lastname ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2011-09-28 06:47:25 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											if ( $this -> input -> post ( 'user_callsign' ))  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												$data [ 'user_callsign' ]  =  $this -> input -> post ( 'user_callsign' ); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											}  else  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												$data [ 'user_callsign' ]  =  $q -> user_callsign ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											if ( $this -> input -> post ( 'user_locator' ))  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												$data [ 'user_locator' ]  =  $this -> input -> post ( 'user_locator' ); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											}  else  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												$data [ 'user_locator' ]  =  $q -> user_locator ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											if ( $this -> input -> post ( 'user_timezone' ))  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												$data [ 'user_timezone' ]  =  $this -> input -> post ( 'user_timezone' ); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											}  else  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												$data [ 'user_timezone' ]  =  $q -> user_timezone ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2011-08-20 00:12:13 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											$this -> load -> view ( 'user/edit' ,  $data ); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											$this -> load -> view ( 'layout/footer' ); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										else 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										{ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											unset ( $data ); 
							 
						 
					
						
							
								
									
										
										
										
											2011-08-20 03:33:37 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											switch ( $this -> user_model -> edit ( $this -> input -> post ()))  { 
							 
						 
					
						
							
								
									
										
										
										
											2011-08-20 00:12:13 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
												// Check for errors
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												case  EUSERNAMEEXISTS : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
													$data [ 'username_error' ]  =  'Username <b>' . $this -> input -> post ( 'user_name' ) . '</b> already in use!' ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
													break ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												case  EEMAILEXISTS : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
													$data [ 'email_error' ]  =  'E-mail address <b>' . $this -> input -> post ( 'user_email' ) . '</b> already in use!' ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
													break ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												case  EPASSWORDINVALID : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
													$data [ 'password_error' ]  =  'Invalid password!' ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
													break ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												// All okay, return to user screen
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												case  OK : 
							 
						 
					
						
							
								
									
										
										
										
											2011-08-20 04:14:16 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
													if ( $this -> session -> userdata ( 'user_id' )  ==  $this -> input -> post ( 'id' ))  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
														$this -> session -> set_flashdata ( 'notice' ,  'User ' . $this -> input -> post ( 'user_name' ) . ' edited' ); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
														redirect ( 'user/profile' ); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
													}  else  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
														$this -> session -> set_flashdata ( 'notice' ,  'User ' . $this -> input -> post ( 'user_name' ) . ' edited' ); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
														redirect ( 'user' ); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
													} 
							 
						 
					
						
							
								
									
										
										
										
											2011-08-20 00:12:13 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
													return ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											$this -> load -> view ( 'layout/header' ); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											$data [ 'user_name' ]  =  $this -> input -> post ( 'user_name' ); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											$data [ 'user_email' ]  =  $this -> input -> post ( 'user_email' ); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											$data [ 'user_password' ]  =  $this -> input -> post ( 'user_password' ); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											$data [ 'user_type' ]  =  $this -> input -> post ( 'user_type' ); 
							 
						 
					
						
							
								
									
										
										
										
											2011-09-28 06:47:25 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											$data [ 'user_firstname' ]  =  $this -> input -> post ( 'user_firstname' ); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											$data [ 'user_lastname' ]  =  $this -> input -> post ( 'user_lastname' ); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											$data [ 'user_callsign' ]  =  $this -> input -> post ( 'user_callsign' ); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											$data [ 'user_locator' ]  =  $this -> input -> post ( 'user_locator' ); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											$data [ 'user_timezone' ]  =  $this -> input -> post ( 'user_timezone' ); 
							 
						 
					
						
							
								
									
										
										
										
											2011-08-18 08:31:15 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
											$this -> load -> view ( 'user/edit' ,  $data ); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											$this -> load -> view ( 'layout/footer' ); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										} 
							 
						 
					
						
							
								
									
										
										
										
											2011-08-20 00:12:13 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2011-08-20 03:33:37 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									function  profile ()  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										$this -> load -> model ( 'user_model' ); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										$query  =  $this -> user_model -> get_by_id ( $this -> session -> userdata ( 'user_id' )); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										$this -> load -> view ( 'layout/header' ); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										$data  =  $query -> row (); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										$this -> load -> view ( 'user/profile' ,  $data ); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										$this -> load -> view ( 'layout/footer' ); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2011-08-20 00:12:13 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									function  delete ()  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										$this -> load -> model ( 'user_model' ); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										if ( ! $this -> user_model -> authorize ( 99 ))  {  $this -> session -> set_flashdata ( 'notice' ,  'You\'re not allowed to do that!' );  redirect ( 'dashboard' );  } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										$query  =  $this -> user_model -> get_by_id ( $this -> uri -> segment ( 3 )); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										$this -> load -> library ( 'form_validation' ); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										$this -> form_validation -> set_rules ( 'id' ,  'user_id' ,  'required' ); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										$data  =  $query -> row (); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										if  ( $this -> form_validation -> run ()  ==  FALSE ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										{ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											$this -> load -> view ( 'layout/header' ); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											$this -> load -> view ( 'user/delete' ,  $data ); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											$this -> load -> view ( 'layout/footer' ); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										} 
							 
						 
					
						
							
								
									
										
										
										
											2011-08-18 08:31:15 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
										else 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										{ 
							 
						 
					
						
							
								
									
										
										
										
											2011-08-20 00:12:13 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											if ( $this -> user_model -> delete ( $data -> user_id )) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											{ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												$this -> session -> set_flashdata ( 'notice' ,  'User deleted' ); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												redirect ( 'user' ); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											}  else  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												$this -> session -> set_flashdata ( 'notice' ,  '<b>Database error:</b> Could not delete user!' ); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												redirect ( 'user' ); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											} 
							 
						 
					
						
							
								
									
										
										
										
											2011-08-18 08:31:15 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
										} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									function  login ()  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										$this -> load -> model ( 'user_model' ); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										$query  =  $this -> user_model -> get ( $this -> input -> post ( 'user_name' )); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										$this -> load -> library ( 'form_validation' ); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										$this -> form_validation -> set_rules ( 'user_name' ,  'Username' ,  'required' ); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										$this -> form_validation -> set_rules ( 'user_password' ,  'Password' ,  'required' ); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										$data  =  $query -> row (); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										if  ( $this -> form_validation -> run ()  ==  FALSE ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										{ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											$this -> load -> view ( 'layout/header' ); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											$this -> load -> view ( 'user/login' ,  $data ); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											$this -> load -> view ( 'layout/footer' ); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										else 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										{ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											if ( $this -> user_model -> login ()  ==  1 )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												$this -> session -> set_flashdata ( 'notice' ,  'User logged in' ); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												$this -> user_model -> update_session ( $data -> user_id ); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												redirect ( 'dashboard' ); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											}  else  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												$this -> session -> set_flashdata ( 'notice' ,  'Incorrect username or password!' ); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												redirect ( 'user/login' ); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									function  logout ()  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										$this -> load -> model ( 'user_model' ); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										$user_name  =  $this -> session -> userdata ( 'user_name' ); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										$this -> user_model -> clear_session (); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										$this -> session -> set_flashdata ( 'notice' ,  'User ' . $user_name . ' logged out.' ); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										redirect ( 'dashboard' ); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}