phpScheduleIt
May 19, 2013, 02:42:28 PM *
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: Resources invisible without permission (v.1.2.8)  (Read 4511 times)
hd
Newbie
*

Karma: 0
Posts: 5


« on: May 21, 2008, 04:34:20 AM »

In my install, I have a lot of resources and use permissions to limit who can use them (some are in distant physical locations). So, I wanted to clean up the presentation of the schedule so that users can only see the resources they have permission for. This change also refers to the setting of $conf['app']['use_perms'] in config.php. If permissions are used, only permitted resources are shown, otherwise all resources are shown.

This change applies to the print_reservations() function in Schedule.class.php. Around line 215 , wrap the canShowReservation call in a condition check:

change: $shown = $this->canShowReservation($viewable_date, $cur_resource)
to: if ($shown = $this->canShowReservation($viewable_date, $cur_resource) || $conf['app']['use_perms'] == 0) {

Don't forget the closing brace at the end of the function!

Hope this useful to someone out there.

hd
Logged
StamfordRob
Newbie
*

Karma: 0
Posts: 17


« Reply #1 on: August 08, 2008, 09:34:18 AM »

I am using the same version and when replaced i get HTTP500 Page cannot be displayed.  Any ideas??  Thanks..r
Logged

Life is like a roll of toilet paper, I just don't know how far into the roll I am.
hd
Newbie
*

Karma: 0
Posts: 5


« Reply #2 on: August 08, 2008, 06:43:17 PM »

You may have misplaced the closing brace. Could you post the whole section you modified so I can have a look at it?

hd
Logged
StamfordRob
Newbie
*

Karma: 0
Posts: 17


« Reply #3 on: August 20, 2008, 03:41:03 PM »

hi.. sorry i have been on other projects.. i copied the section where the change is.. roughly row 215-275..

thanks

r


Code:
            // If the date has not passed, resource is active and user has permission,
            //  or the user is the admin allow reservations to be made
            //$shown = $this->canShowReservation($viewable_date, $cur_resource);
            if ($shown = $this->canShowReservation($viewable_date, $cur_resource) || $conf['app']['use_perms'] == 0) {

            $color = 'cellColor' . ($count%2);
            print_name_cell($current_date, $id, $name, $shown, $this->scheduleType == BLACKOUT_ONLY, $this->scheduleid, $approval, $color);

            $index = $id;
            if (isset($this->res[$index])) {
                for ($i = 0; $i < count($this->res[$index]); $i++) {
                    $rs = $this->res[$index][$i];
                    // If it doesnt start sometime today, end sometime today, or surround today, just skip over it
                    if (
                        !(($rs['start_date'] >= $current_date && $rs['start_date'] <= $current_date)
                        || ($rs['end_date'] >= $current_date && $rs['end_date'] <= $current_date)
                        || ($rs['start_date'] <= $current_date && $rs['end_date'] >= $current_date))
                       ) {
                        continue;
                    }

                    // Just skip the reservation if the ending date/time is todays start time
                    if ($rs['end_date'] == $current_date && $rs['endtime'] == $this->startDay) { continue; }

                    // If the reservation starts before or ends after todays date, just pretend it ends today so it shows correctly
                    if ($rs['start_date'] < $current_date) {
                        $rs['starttime'] = $this->startDay;
                    }
                    if ($rs['end_date'] > $current_date) {
                        $rs['endtime'] = $this->endDay;
                    }

                    // Print out row of reservations
                    $thisStart = $rs['starttime'];
                    $thisEnd = $rs['endtime'];

                    if ($thisStart < $this->startDay && $thisEnd > $this->startDay)
                        $thisStart = $this->startDay;
                    else if ($thisStart < $this->startDay && $thisEnd <= $this->startDay)
                        continue;    // Ignore reservation, its off the schedule

                    if ($thisStart < $this->endDay && $thisEnd > $this->endDay)
                        $thisEnd = $this->endDay;
                    else if ($thisStart >= $this->endDay && $thisEnd > $this->startDay)
                        continue;    // Ignore reservation, its off the schedule

                    $colspan = intval(($thisEnd - $thisStart) / $this->timespan);

                    $this->move_to_starting_col($rs, $thisStart, $prevTime, $this->timespan, $id, $current_date, $shown, $color);

                    if ($rs['is_blackout'] == 1)
                        $this->write_blackout($rs, $colspan);
                    else
                        $this->write_reservation($rs, $colspan, $viewable_date);

                    // Set prevTime to this reservation's ending time
                    $prevTime = $thisEnd;
                }
            }

            $this->finish_row($this->endDay, $prevTime, $this->timespan, $id, $current_date, $shown, $color);
        }
    }

    /**
    * Return the formatted and timezone adjusted date
    * @param int $ts time stamp for date to format
    * @return formatted date
    */
    function get_display_date() {
return Time::formatReservationDate($this->_date['current'], $this->startDay, null, 'schedule_daily');
    }
Logged

Life is like a roll of toilet paper, I just don't know how far into the roll I am.
hd
Newbie
*

Karma: 0
Posts: 5


« Reply #4 on: August 20, 2008, 11:17:31 PM »

Hi StamfordRob,

I've made a fairly large change to the way the function is handled since the original post. The original code relied on the user's permission to add a booking, meaning that past reservations could not be viewed. This revision fixes that issue. Below is the entire function:

Code:
   
    /**
    * Print out the reservations for each resource on each day
    * @param none
    */
    function print_reservations() {
        global $conf;

        if (!$this->machids)
            return;
        $current_date = $this->_date['current'];        // Store current_date so we dont have to access the array every time

        // Repeat this whole process for each resource in the database
        for ($count = 0; $count < count($this->machids); $count++) {
            $prevTime = $this->startDay;        // Previous time holder
            $totCol = intval(($this->endDay - $this->startDay) / $this->timespan);    // Total columns holder
$cur_resource = $this->machids[$count];

            // Store info about this current resource in local vars
            $id = $cur_resource['machid'];
            $name = $cur_resource['name'];
            $status = $cur_resource['status'];
            $approval = $cur_resource['approval'];


            $shown = false;        // Default resource visiblilty to not shown
$viewable_date = $this->isViewableDate($current_date, $cur_resource['min_notice_time'], $cur_resource['max_notice_time']);

            // If the date has not passed, resource is active and user has permission,
            //  or the user is the admin allow reservations to be made

$has_permission = $this->user->has_perm($cur_resource['machid']);
if ($shown = $this->canShowReservation($viewable_date, $cur_resource) &&   $has_permission) {

            $color = 'cellColor' . ($count%2);
            print_name_cell($current_date, $id, $name, $shown, $this->scheduleType == BLACKOUT_ONLY, $this->scheduleid, $approval, $color);


            $index = $id;
            if (isset($this->res[$index])) {
                for ($i = 0; $i < count($this->res[$index]); $i++) {
                    $rs = $this->res[$index][$i];
                    // If it doesnt start sometime today, end sometime today, or surround today, just skip over it
                    if (
                        !(($rs['start_date'] >= $current_date && $rs['start_date'] <= $current_date)
                        || ($rs['end_date'] >= $current_date && $rs['end_date'] <= $current_date)
                        || ($rs['start_date'] <= $current_date && $rs['end_date'] >= $current_date))
                       ) {
                        continue;
                    }

                    // Just skip the reservation if the ending date/time is todays start time
                    if ($rs['end_date'] == $current_date && $rs['endtime'] == $this->startDay) { continue; }

                    // If the reservation starts before or ends after todays date, just pretend it ends today so it shows correctly
                    if ($rs['start_date'] < $current_date) {
                        $rs['starttime'] = $this->startDay;
                    }
                    if ($rs['end_date'] > $current_date) {
                        $rs['endtime'] = $this->endDay;
                    }


                    // Print out row of reservations
                    $thisStart = $rs['starttime'];
                    $thisEnd = $rs['endtime'];

                    if ($thisStart < $this->startDay && $thisEnd > $this->startDay)
                        $thisStart = $this->startDay;
                    else if ($thisStart < $this->startDay && $thisEnd <= $this->startDay)
                        continue;    // Ignore reservation, its off the schedule

                    if ($thisStart < $this->endDay && $thisEnd > $this->endDay)
                        $thisEnd = $this->endDay;
                    else if ($thisStart >= $this->endDay && $thisEnd > $this->startDay)
                        continue;    // Ignore reservation, its off the schedule

                    $colspan = intval(($thisEnd - $thisStart) / $this->timespan);

                    $this->move_to_starting_col($rs, $thisStart, $prevTime, $this->timespan, $id, $current_date, $shown, $color);

                    if ($rs['is_blackout'] == 1)
                        $this->write_blackout($rs, $colspan);
                    else
                        $this->write_reservation($rs, $colspan, $viewable_date);

                    // Set prevTime to this reservation's ending time
                    $prevTime = $thisEnd;
                }
            }

            $this->finish_row($this->endDay, $prevTime, $this->timespan, $id, $current_date, $shown, $color);
        }
    }}
Logged
StamfordRob
Newbie
*

Karma: 0
Posts: 17


« Reply #5 on: August 21, 2008, 09:46:48 AM »

Installed and working.. So far so good.  But going back to your post, the users cant see any previous postings. All prior days are empty.  Is that how you wanted it??

Thanks for the help.

r
Logged

Life is like a roll of toilet paper, I just don't know how far into the roll I am.
StamfordRob
Newbie
*

Karma: 0
Posts: 17


« Reply #6 on: August 21, 2008, 09:55:12 AM »

To add to that.  One thing i noticed is that they can see previous reservations in the Resource Calendar (monthly view) but as soon as you choose a date you see nothing.  I think it may be better to allow them to see the history of the units that they have permissions for, instead of blanking that out.  All they see are the previous date lines with no resources listed.  Is there something we can change to allow the users to see the history of the permissioned resources.

r
Logged

Life is like a roll of toilet paper, I just don't know how far into the roll I am.
StamfordRob
Newbie
*

Karma: 0
Posts: 17


« Reply #7 on: August 21, 2008, 10:10:39 AM »

I just noticed something else with the Schedule Calendar (Resource Calendar view).  The user can see ALL reservations not just for resources that they are permissioned for.  But again as soon as you choose a day its gone and only your permisssions show up. 

Ideas to change that?? I know that I am throwing a lot of changes out but your original modification is key, I figure I will show you other areas that are affected.

Thanks

r
Logged

Life is like a roll of toilet paper, I just don't know how far into the roll I am.
GeorgeT
Newbie
*

Karma: 0
Posts: 14


« Reply #8 on: February 27, 2009, 01:59:23 AM »

Thanks for this code it was just what I was trying to do. Have you got any tips on how to mod the permissions so that I can set permissions for resources from the registration page.
George
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!