$type=sql_select("SELECT * FROM `UserAngelTypes` JOIN `AngelTypes` ON (`UserAngelTypes`.`angeltype_id` = `AngelTypes`.`id`) WHERE `AngelTypes`.`id` = '".sql_escape($type_id)."' AND (`AngelTypes`.`restricted` = 0 OR (`UserAngelTypes`.`user_id` = '".sql_escape($user['UID'])."' AND NOT `UserAngelTypes`.`confirm_user_id` IS NULL)) LIMIT 1");
if(sql_num_query("SELECT * FROM `User` WHERE `UID`='".sql_escape($user_id)."' LIMIT 1")==0){
redirect(page_link_to('user_shifts'));
}
if(isset($_REQUEST['angeltype_id'])&&test_request_int('angeltype_id')&&sql_num_query("SELECT * FROM `AngelTypes` WHERE `id`='".sql_escape($_REQUEST['angeltype_id'])."' LIMIT 1")>0){
$selected_type_id=$_REQUEST['angeltype_id'];
}
}
if(sql_num_query("SELECT * FROM `ShiftEntry` WHERE `SID`='".sql_escape($shift['SID'])."' AND `UID` = '".sql_escape($user_id)."'")){
returnerror("This angel does already have an entry for this shift.",true);
engelsystem_error('Unable to create shift entry.');
}
if($type['restricted']==0&&sql_num_query("SELECT * FROM `UserAngelTypes` INNER JOIN `AngelTypes` ON `AngelTypes`.`id` = `UserAngelTypes`.`angeltype_id` WHERE `angeltype_id` = '".sql_escape($selected_type_id)."' AND `user_id` = '".sql_escape($user_id)."' ")==0){
sql_query("INSERT INTO `UserAngelTypes` (`user_id`, `angeltype_id`) VALUES ('".sql_escape($user_id)."', '".sql_escape($selected_type_id)."')");
}
$user_source=User($user_id);
engelsystem_log("User ".User_Nick_render($user_source)." signed up for shift ".$shift['name']." from ".date("Y-m-d H:i",$shift['start'])." to ".date("Y-m-d H:i",$shift['end']));
success(_("You are subscribed. Thank you!").' <a href="'.page_link_to('user_myshifts').'">'._("My shifts").' »</a>');
redirect(shift_link($shift));
}
if(in_array('user_shifts_admin',$privileges)){
$users=sql_select("SELECT *, (SELECT count(*) FROM `ShiftEntry` WHERE `freeloaded`=1 AND `ShiftEntry`.`UID`=`User`.`UID`) AS `freeloaded` FROM `User` ORDER BY `Nick`");
engelsystem_error('Unable to delete shift entry.');
}
engelsystem_log("Deleted ".User_Nick_render($shift_entry_source)."'s shift: ".$shift_entry_source['name']." at ".$shift_entry_source['Name']." from ".date("Y-m-d H:i",$shift_entry_source['start'])." to ".date("Y-m-d H:i",$shift_entry_source['end'])." as ".$shift_entry_source['angel_type']);