<commit_before><?php
//
// Description
// ===========
// This function will check the user has access to the services module,
// and return a list of other modules enabled for the business.
//
// Arguments
// =========
// ciniki:
// business_id: 		The ID of the business the request is for.
// method:				The method requested in the services module.
// service_id:			The ID of the service, if specified to check if the user
//						has access to.
// req_id:				The first ID to lookup.  This is used to check some methods
//						have access to a specified service or task.
// req2_id:				The second ID to lookup.  This is used to check some methods
//						have access to a specified service or task.
// 
// Returns
// =======
//
function ciniki_services_checkAccess($ciniki, $business_id, $method, $req_id, $req2_id) {
	//
	// Check if the business is active and the module is enabled
	//
	ciniki_core_loadMethod($ciniki, 'ciniki', 'businesses', 'private', 'checkModuleAccess');
	$rc = ciniki_businesses_checkModuleAccess($ciniki, $business_id, 'ciniki', 'services');
	if( $rc['stat'] != 'ok' ) {
		return $rc;
	}
	if( isset($rc['modules']) ) {
		$modules = $rc['modules'];
	} else {
		$modules = array();
	}

	if( !isset($rc['ruleset']) ) {
		return array('stat'=>'fail', 'err'=>array('pkg'=>'ciniki', 'code'=>'833', 'msg'=>'No permissions granted'));
	}

	// FIXME: Check if this is needed
	//	//
	//	// Sysadmins are allowed full access, except for deleting.
	//	//
	//	if( $method != 'ciniki.services.delete' ) {
	//		if( ($ciniki['session']['user']['perms'] & 0x01) == 0x01 ) {
	//			return array('stat'=>'ok', 'modules'=>$modules);
//		}
//	}
//
	//
	// Users who are an owner or employee of a business can see the business services
	//
	$strsql = "SELECT business_id, user_id FROM ciniki_business_users "
		. "WHERE business_id = '" . ciniki_core_dbQuote($ciniki, $business_id) . "' "
		. "AND user_id = '" . ciniki_core_dbQuote($ciniki, $ciniki['session']['user']['id']) . "' "
		. "AND package = 'ciniki' "
		. "AND (permission_group = 'owners' OR permission_group = 'employees') "
		. "";
	ciniki_core_loadMethod($ciniki, 'ciniki', 'core', 'private', 'dbHashQuery');
	$rc = ciniki_core_dbHashQuery($ciniki, $strsql, 'ciniki.businesses', 'user');
	if( $rc['stat'] != 'ok' ) {
		return $rc;
	}
	//
	// If the user has permission, return ok
	//<commit_msg>Fixed bug with checkAccess not looking for active users, signup not assigning proper status to business_user, and lists not working when adding a new painting<commit_after><?php
//
// Description
// ===========
// This function will check the user has access to the services module,
// and return a list of other modules enabled for the business.
//
// Arguments
// =========
// ciniki:
// business_id: 		The ID of the business the request is for.
// method:				The method requested in the services module.
// service_id:			The ID of the service, if specified to check if the user
//						has access to.
// req_id:				The first ID to lookup.  This is used to check some methods
//						have access to a specified service or task.
// req2_id:				The second ID to lookup.  This is used to check some methods
//						have access to a specified service or task.
// 
// Returns
// =======
//
function ciniki_services_checkAccess($ciniki, $business_id, $method, $req_id, $req2_id) {
	//
	// Check if the business is active and the module is enabled
	//
	ciniki_core_loadMethod($ciniki, 'ciniki', 'businesses', 'private', 'checkModuleAccess');
	$rc = ciniki_businesses_checkModuleAccess($ciniki, $business_id, 'ciniki', 'services');
	if( $rc['stat'] != 'ok' ) {
		return $rc;
	}
	if( isset($rc['modules']) ) {
		$modules = $rc['modules'];
	} else {
		$modules = array();
	}

	if( !isset($rc['ruleset']) ) {
		return array('stat'=>'fail', 'err'=>array('pkg'=>'ciniki', 'code'=>'833', 'msg'=>'No permissions granted'));
	}

	// FIXME: Check if this is needed
	//	//
	//	// Sysadmins are allowed full access, except for deleting.
	//	//
	//	if( $method != 'ciniki.services.delete' ) {
	//		if( ($ciniki['session']['user']['perms'] & 0x01) == 0x01 ) {
	//			return array('stat'=>'ok', 'modules'=>$modules);
//		}
//	}
//
	//
	// Users who are an owner or employee of a business can see the business services
	//
	$strsql = "SELECT business_id, user_id FROM ciniki_business_users "
		. "WHERE business_id = '" . ciniki_core_dbQuote($ciniki, $business_id) . "' "
		. "AND user_id = '" . ciniki_core_dbQuote($ciniki, $ciniki['session']['user']['id']) . "' "
		. "AND package = 'ciniki' "
		. "AND status = 10 "
		. "AND (permission_group = 'owners' OR permission_group = 'employees') "
		. "";
	ciniki_core_loadMethod($ciniki, 'ciniki', 'core', 'private', 'dbHashQuery');
	$rc = ciniki_core_dbHashQuery($ciniki, $strsql, 'ciniki.businesses', 'user');
	if( $rc['stat'] != 'ok' ) {
		return $rc;
	}
	//
	// If the user has permission, return ok
	//
{'fraction_non_alphanumeric': 0.1772875816993464, 'fraction_numerical': 0.004901960784313725, 'mean_word_length': 3.476234003656307, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2937343', 'n_tokens_mistral': 1724, 'n_tokens_neox': 1639, 'n_words': 499}