availability.php
/**
 * This function expects the $inputs array to contain at least a key 'sprint_id' and 
 * a number of keys with format k_<resource-id>_<year>-<month>-<day>. for each found item, It will add an
 * availability record for the given resource id on the given date, where the value represents the number of hours.
 * Before inserting availability records, all existing records for the given sprint will be deleted.
 * 
 * @param unknown_type $inputs
 */
This function expects the $inputs array to contain at least a key 'sprint_id' and
a number of keys with format k__--. for each found item, It will add an
availability record for the given resource id on the given date, where the value represents the number of hours.
Before inserting availability records, all existing records for the given sprint will be deleted.


This function expects the $inputs array to contain at least a key ' sprint_id ' and a number of keys with format k__ -- . for each found item It will add an availability record for the given resource id on the given date where the value represents the number of hours . Before inserting availability records all existing records for the given sprint will be deleted .
function change_availability( &$inputs)
{
	global $database;
	$sprint_id = $database->escape( $inputs['sprint_id']);
	$insert_array = Array();
	$count = 0;
	foreach ( $inputs as $key => $value)
	{
	    $value = intval( $value); 
		if (preg_match('/k_(\d+)_(\d{4}-\d+-\d+)/', $key, $key_parts))
		{
			$insert_array[] = "($sprint_id, $key_parts[1], '$key_parts[2]', $value)";
			++$count;
		}
	}
	if ($count)
	{
		$insert_string = implode(',', $insert_array);
		$database->exec( "INSERT INTO availability(sprint_id, resource_id, date, hours) VALUES $insert_string " .
		        "ON DUPLICATE KEY UPDATE hours = VALUES( hours)");
	}
	return get_availability( $inputs);
}
function change_availability ( & $ inputs ) { global $ database ; $ sprint_id = $ database -> escape ( $ inputs [ 'sprint_id' ] ) ; $ insert_array = Array ( ) ; $ count = 0 ; foreach ( $ inputs as $ key => $ value ) { $ value = intval ( $ value ) ; if ( preg_match ( '/k_(\d+)_(\d{4}-\d+-\d+)/' , $ key , $ key_parts ) ) { $ insert_array [ ] = " ( $ sprint_id ,  $ key_parts [ 1 ] , ' $ key_parts [ 2 ] ',  $ value ) " ; ++ $ count ; } } if ( $ count ) { $ insert_string = implode ( ',' , $ insert_array ) ; $ database -> exec ( " INSERT INTO availability(sprint_id, resource_id, date, hours) VALUES  $ insert_string " . " ON DUPLICATE KEY UPDATE hours = VALUES( hours) " ) ; } return get_availability ( $ inputs ) ; }
This function expects the $inputs array to contain at least a key 'sprint_id' and
 a number of keys with format k_<resource-id>_<year>-<month>-<day>.
This function expects the $inputs array to contain at least a key ' sprint_id ' and a number of keys with format k_<resource - id > _<year > - <month > - <day > .
// force intval to be numeric