phpScheduleIt
June 20, 2013, 12:26:01 AM *
Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
News: phpScheduleIt 2.4.2 has been released!
 
   Home   Help Login Register  
Pages: [1]
  Print  
Author Topic: Blacking out Range of Time  (Read 520 times)
robpet72
Jr. Member
**

Karma: 1
Posts: 55


« on: January 09, 2012, 12:58:51 PM »

I think I know the answer, but I'm  hoping I'm wrong, because I don't like it.

I have about 5 resources.  I have modified the program to allow certain non-admins to edit blackouts.
We start with the entire calendar blacked out and they free up the time the resource is available.

I went through and blacked out each 1/2 hour time slot for each resource.

They want to un-blackout full ranges in the day (similar to booking a couple of hours at a time).  Is this possible?


Thanks


rob
Logged
Nick
Administrator
Hero Member
*****

Karma: 15
Posts: 5506


WWW
« Reply #1 on: January 09, 2012, 01:43:48 PM »

Without writing some custom code, you'd have to do this per day per resource  Undecided
Logged
robpet72
Jr. Member
**

Karma: 1
Posts: 55


« Reply #2 on: January 17, 2012, 07:04:13 PM »

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:

Code:
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 Smiley 

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.
Code:
<?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_SERVERDB_USERDB_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
Logged
Nick
Administrator
Hero Member
*****

Karma: 15
Posts: 5506


WWW
« Reply #3 on: January 23, 2012, 01:57:24 PM »

Very nice!
Logged
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2006-2007, Simple Machines Valid XHTML 1.0! Valid CSS!