sync with gateway moved to defs
diff --git a/erpnext/home/doctype/company_control/company_control.py b/erpnext/home/doctype/company_control/company_control.py
index 63f8b71..567f9f6 100644
--- a/erpnext/home/doctype/company_control/company_control.py
+++ b/erpnext/home/doctype/company_control/company_control.py
@@ -71,7 +71,10 @@
 			pr.save(1)
 		
 		# Update Membership Type at Gateway
-		if cint(webnotes.conn.get_value('Control Panel', None, 'sync_with_gateway')):
+		import webnotes.defs
+		from webnotes.utils import cint
+		if hasattr(webnotes.defs, 'sync_with_gateway') and \
+				cint(webnotes.defs.sync_with_gateway) or 0:		
 			if 'System Manager' in role_list : membership_type = 'Administrator'
 			else : membership_type = 'Member'
 
diff --git a/erpnext/home/page/my_company/my_company.py b/erpnext/home/page/my_company/my_company.py
index d3a7bc7..f2a2522 100644
--- a/erpnext/home/page/my_company/my_company.py
+++ b/erpnext/home/page/my_company/my_company.py
@@ -54,7 +54,10 @@
 	args = json.loads(args)
 	webnotes.conn.sql("update tabProfile set enabled=0, docstatus=2 where name=%s", args['user'])
 	# erpnext-saas
-	if cint(webnotes.conn.get_value('Control Panel', None, 'sync_with_gateway')):
+	import webnotes.defs
+	from webnotes.utils import cint
+	if hasattr(webnotes.defs, 'sync_with_gateway') and \
+			cint(webnotes.defs.sync_with_gateway) or 0:	
 		from server_tools.gateway_utils import remove_user_gateway
 		remove_user_gateway(args['user'])
 	
@@ -65,7 +68,10 @@
 def add_user(args):
 	args = json.loads(args)
 	# erpnext-saas
-	if cint(webnotes.conn.get_value('Control Panel', None, 'sync_with_gateway')):
+	import webnotes.defs
+	from webnotes.utils import cint
+	if hasattr(webnotes.defs, 'sync_with_gateway') and \
+			cint(webnotes.defs.sync_with_gateway) or 0:
 		from server_tools.gateway_utils import add_user_gateway
 		add_user_gateway(args)
 	
@@ -183,7 +189,10 @@
 	webnotes.conn.set_value('Profile', args['user'], 'login_before', args.get('login_before'))
 
 	if 'new_password' in args:
-		if cint(webnotes.conn.get_value('Control Panel',None,'sync_with_gateway')):
+		import webnotes.defs
+		from webnotes.utils import cint
+		if hasattr(webnotes.defs, 'sync_with_gateway') and \
+				cint(webnotes.defs.sync_with_gateway) or 0:			
 			import server_tools.gateway_utils
 			res = server_tools.gateway_utils.change_password('', args['new_password'], args['user'], args['sys_admin_pwd'])
 			if 'Traceback' not in res['message']:
diff --git a/erpnext/home/page/profile_settings/profile_settings.py b/erpnext/home/page/profile_settings/profile_settings.py
index fb633fd..9b9f890 100644
--- a/erpnext/home/page/profile_settings/profile_settings.py
+++ b/erpnext/home/page/profile_settings/profile_settings.py
@@ -27,8 +27,11 @@
 	
 	if not webnotes.conn.sql('select name from tabProfile where name=%s and password=password(%s)', (webnotes.session['user'], arg['old_password'])):
 		webnotes.msgprint('Old password is not correct', raise_exception=1)
-			
-	if cint(webnotes.conn.get_value('Control Panel',None,'sync_with_gateway')):
+	
+	import webnotes.defs
+	from webnotes.utils import cint
+	if hasattr(webnotes.defs, 'sync_with_gateway') and \
+			cint(webnotes.defs.sync_with_gateway) or 0:	
 		import server_tools.gateway_utils
 		webnotes.msgprint(server_tools.gateway_utils.change_password(arg['old_password'], arg['new_password'])['message'])
 
diff --git a/erpnext/startup/event_handlers.py b/erpnext/startup/event_handlers.py
index 7db56bd..107a5d7 100644
--- a/erpnext/startup/event_handlers.py
+++ b/erpnext/startup/event_handlers.py
@@ -26,9 +26,11 @@
 	if login_manager.user not in ('Guest', None, '') and webnotes.conn.cur_db_name!='accounts' and webnotes.conn.get_value('Control Panel', 'Control Panel', 'account_id')!='s5u011':
 		try:
 			login_manager = login_as(login_manager)
-			update_account_details()
-			import server_tools.gateway_utils
-			server_tools.gateway_utils.check_login(login_manager.user)
+			if hasattr(webnotes.defs, 'sync_with_gateway') and \
+					cint(webnotes.defs.sync_with_gateway) or 0:
+				update_account_details()
+				import server_tools.gateway_utils
+				server_tools.gateway_utils.check_login(login_manager.user)
 			
 		except ImportError:
 			pass
@@ -157,6 +159,8 @@
 # logout the user from SSO
 #
 def on_logout(login_manager):
-	if cint(webnotes.conn.get_value('Control Panel', None, 'sync_with_gateway')):
+	import webnotes.defs
+	if hasattr(webnotes.defs, 'sync_with_gateway') and \
+			cint(webnotes.defs.sync_with_gateway) or 0:
 		from server_tools.gateway_utils import logout_sso
 		logout_sso(user=login_manager.user)
diff --git a/erpnext/utilities/page/users/users.py b/erpnext/utilities/page/users/users.py
index f2bb1a5..ec01479 100644
--- a/erpnext/utilities/page/users/users.py
+++ b/erpnext/utilities/page/users/users.py
@@ -83,7 +83,10 @@
 	webnotes.conn.set_value('Profile', args['user'], 'enabled', int(args.get('enabled',0)) or 0)
 
 	if args.get('new_password') and args.get('sys_admin_pwd'):
-		if cint(webnotes.conn.get_value('Control Panel',None,'sync_with_gateway')):
+		import webnotes.defs
+		from webnotes.utils import cint
+		if hasattr(webnotes.defs, 'sync_with_gateway') and \
+				cint(webnotes.defs.sync_with_gateway) or 0:
 			import server_tools.gateway_utils
 			res = server_tools.gateway_utils.change_password('', args['new_password'], 
 				args['user'], args['sys_admin_pwd'])
@@ -104,7 +107,10 @@
 def add_user(args):
 	args = json.loads(args)
 	# erpnext-saas
-	if cint(webnotes.conn.get_value('Control Panel', None, 'sync_with_gateway')):
+	import webnotes.defs
+	from webnotes.utils import cint
+	if hasattr(webnotes.defs, 'sync_with_gateway') and \
+			cint(webnotes.defs.sync_with_gateway) or 0:	
 		from server_tools.gateway_utils import add_user_gateway
 		add_user_gateway(args)
 	
@@ -169,7 +175,10 @@
 	webnotes.conn.sql("update tabProfile set enabled=0, docstatus=2 where name=%s", 
 		webnotes.form_dict['uid'])
 	# erpnext-saas
-	if int(webnotes.conn.get_value('Control Panel', None, 'sync_with_gateway')):
+	import webnotes.defs
+	from webnotes.utils import cint
+	if hasattr(webnotes.defs, 'sync_with_gateway') and \
+			cint(webnotes.defs.sync_with_gateway) or 0:
 		from server_tools.gateway_utils import remove_user_gateway
 		remove_user_gateway(webnotes.form_dict['uid'])