Okay, so a range isn't going to do it, and they want it to be much faster. So I decided to change the write_blackout function using jQuery to make it work faster.
I changed this function in schedule.template.php to:
function write_blackout($colspan, $viewable, $blackoutid, $summary = '', $showsummary = 0) {
global $conf;
$color = '#' . $conf['ui']['blackout'][0]['color'];
$hover = '#' . $conf['ui']['blackout'][0]['hover'];
$text = '#' . $conf['ui']['blackout'][0]['text'];
$chars = 4 * $colspan;
$js = '';
/* if ($viewable) {
$js = "onclick=\"reserve('m','','','$blackoutid','','1');\" ";
if ($showsummary && $summary->isVisible())
{
$js .= "onmouseover=\"ssum(event,'" . preg_replace("/[\n\r]+/", '<br/>', addslashes($summary->toScheduleHover())) . "');\" onmouseout=\"hsum();\"";
}
}
else {
if ($showsummary != 0 && $summary->isVisible())
$js = "onmouseover=\"ssum(event,'" . preg_replace("/[\n\r]+/", '<br/>', addslashes($summary->toScheduleHover())) . "');\" onmouseout=\"hsum();\"";
}
$summary_text = $summary->toScheduleCell();
$cellSummary = '';
if ($summary_text != $summary->EMPTY_SUMMARY)
{
$cellSummary = "<div class=\"inlineSummary\">$summary_text</div>";
}
*/
echo "<td colspan=\"$colspan\" id=\"".$blackoutid."\" style=\"color:$text;background-color:$color;\" $js>$cellSummary</td>";
$user = new User(Auth::getCurrentID());
$perms = $user->get_perms();
$has_permission = false; // Check user is allowed to modify this reservation
foreach ($perms as $val){
if($val == "Manage Blackouts"){
$has_permission = true; // Check user is allowed to modify this reservation
}
}
if($has_permission){
?>
<script>
$(document).ready(function(){
$("#<?php echo $blackoutid; ?>").live('click',function() {
var val = '<?php echo $blackoutid; ?>';
if (confirm('Do you really want to remove this Blackout?')) {
jQuery.post('templates/delblackout.php',{name:val});
// alert('You removed blackout id: ' + val);
}
window.location.reload(true);
});
});
</script>
<?php
}
}
The $has_permission is a function I create to not make users administrators, but to still allow them to have permissions like working on blackout times. As Admins they are far too dangerous
To manage this, I created a new schedule called "Hidden Functions", made it not active, added resources, and then linked the users that should have it.
I then created this file, and put it in the templates folder. It is named delblackout.php.
<?php
define("DB_SERVER", "localhost");
define("DB_USER", "USERNAME OF DATABASE USER");
define("DB_PASS", "PASSWORD OF DATABASE USER");
define("DB_NAME", "DATABASE NAME");
$link = mysql_connect(DB_SERVER, DB_USER, DB_PASS);
if(!$link) {
die('Failed to connect to server: ' . mysql_error());
}
//Select database
$db = mysql_select_db(DB_NAME);
if(!$db) {
die("Unable to select database");
}
$name = $_POST['name'];
$qry = "DELETE FROM reservations WHERE resid = '".$name."'";
$result = mysql_query($qry) or die(mysql_error());
?>
And now, voila! Just a click on a blackout time (for those that have permission, it even works on the Bookings page), they will get a confirm, for a two-click blackout removal, and no extra pop-up box. And if they are comfortable with that, I can/will remove the Confirm if statement, and make it a one-click deal.
Hope this helps others.
rob