function definition()
 {
     global $CFG, $DB, $OUTPUT, $USER;
     $mform =& $this->_form;
     $cm = $this->_customdata['cm'];
     // visible elements
     //
     //add all booked users to form
     $mform->addElement('html', '<h5>' . get_string('bookedusers', 'booking') . ':</h5>');
     if ($this->_customdata['bookedusers']) {
         foreach ($this->_customdata['bookedusers'] as $user) {
             if (empty($user->imagealt)) {
                 $user->imagealt = '';
             }
             $userData = $DB->get_record('booking_answers', array('optionid' => $this->_customdata['bookingdata']->id, 'userid' => $user->id));
             $checkMark = "&nbsp;";
             if ($userData->completed == '1') {
                 $checkMark = "&#x2713;";
             }
             $arrow = "&nbsp;";
             if (isset($user->usersOnList) && $user->usersOnList == '1') {
                 $arrow = "&#11014;";
             }
             $mform->addElement('advcheckbox', "user[{$user->id}]", $arrow . $checkMark . " <a href=\"{$CFG->wwwroot}/user/view.php?id={$user->id}\">" . fullname($user) . "</a>", $userData->timecreated > 0 ? ' ' . userdate($userData->timecreated, get_string('strftimedatefullshort')) : '', array('class' => 'modbooking', 'group' => $this->_customdata['bookingdata']->id + 1));
         }
         $this->add_checkbox_controller($this->_customdata['bookingdata']->id + 1);
     } else {
         $mform->addElement('html', '<p>' . get_string('nousers', 'booking') . '</p>');
     }
     //add all waiting list users to form
     if (!empty($this->_customdata['waitinglistusers'])) {
         $mform->addElement('html', '<h5>' . get_string('waitinglistusers', 'booking') . ':</h5>');
         if ($this->_customdata['waitinglistusers']) {
             foreach ($this->_customdata['waitinglistusers'] as $user) {
                 if (empty($user->imagealt)) {
                     $user->imagealt = '';
                 }
                 $mform->addElement('advcheckbox', "user[{$user->id}]", "<a href=\"{$CFG->wwwroot}/user/view.php?id={$user->id}\">" . fullname($user) . "</a>", '', array('id' => 'budala', 'group' => $this->_customdata['bookingdata']->id));
             }
             $this->add_checkbox_controller($this->_customdata['bookingdata']->id);
         }
     }
     //-------------------------------------------------------------------------------
     // buttons
     $buttonarray = array();
     $buttonarray[] =& $mform->createElement('static', 'onlylabel', '', '<span class="bookinglabelname">' . get_string('withselected', 'booking') . '</span>');
     if (!$this->_customdata['bookingdata']->autoenrol && has_capability('mod/booking:communicate', context_module::instance($cm->id))) {
         $buttonarray[] =& $mform->createElement('submit', 'subscribetocourse', get_string('subscribetocourse', 'booking'));
     }
     if (has_capability('mod/booking:deleteresponses', context_module::instance($cm->id))) {
         $buttonarray[] =& $mform->createElement("submit", 'deleteusers', get_string('booking:deleteresponses', 'booking'));
     }
     if (has_capability('mod/booking:communicate', context_module::instance($cm->id))) {
         $buttonarray[] =& $mform->createElement("submit", 'sendpollurl', get_string('booking:sendpollurl', 'booking'));
         $buttonarray[] =& $mform->createElement("submit", 'sendcustommessage', get_string('sendcustommessage', 'booking'));
     }
     if (booking_check_if_teacher($this->_customdata['bookingdata'], $USER) || has_capability('mod/booking:updatebooking', context_module::instance($cm->id))) {
         $buttonarray[] =& $mform->createElement("submit", 'activitycompletion', get_string('confirmactivitycompletion', 'booking'));
         if ($this->_customdata['bookingdata']->conectedoption > 0) {
             $buttonarray[] =& $mform->createElement("submit", 'booktootherbooking', get_string('booktootherbooking', 'booking'));
         }
     }
     $mform->addGroup($buttonarray, 'buttonar', '', array(' '), false);
     //hidden elements
     $mform->addElement('hidden', 'id', $this->_customdata['bookingdata']->cmid);
     $mform->setType('id', PARAM_INT);
     $mform->addElement('hidden', 'bookingid', $this->_customdata['bookingdata']->bookingid);
     $mform->setType('bookingid', PARAM_INT);
     $mform->addElement('hidden', 'optionid', $this->_customdata['bookingdata']->id);
     $mform->setType('optionid', PARAM_INT);
 }
/**
 * Echoes HTML code for booking table with all booking options and booking status
 * @param $booking object containing complete details of the booking instance
 * @param $user object of current user
 * @param $cm course module object
 * @param $allresponses array of all responses
 * @param $sorturl
 * @param $urlParams - fparameters of url
 * @param $optionid - if is set, show only this option
 * @return void
 */
function booking_show_form($booking, $user, $cm, $allresponses, $sorturl = '', $urlParams = array(), $optionid = NULL)
{
    global $DB, $OUTPUT;
    //$optiondisplay is an array of the display info for a booking $cdisplay[$optionid]->text  - text name of option.
    //                                                                            ->maxanswers -maxanswers for this option
    //                                                                            ->full - whether this option is full or not. 0=not full, 1=full
    //									      ->maxoverbooking - waitinglist places dor option
    //									      ->waitingfull - whether waitinglist is full or not 0=not, 1=full
    $bookingfull = false;
    $cdisplay = new stdClass();
    if ($booking->booking->limitanswers) {
        //set bookingfull to true by default if limitanswers.
        $bookingfull = true;
        $waitingfull = true;
    }
    $context = context_module::instance($cm->id);
    $table = NULL;
    $displayoptions = new stdClass();
    $displayoptions->para = false;
    $tabledata = array();
    $current = array();
    $rowclasses = array();
    $hidden = "";
    foreach ($urlParams as $key => $value) {
        if (!in_array($key, array('searchText', 'searchLocation', 'searchInstitution'))) {
            $hidden .= '<input value="' . $value . '" type="hidden" name="' . $key . '">';
        }
    }
    $labelBooking = empty($booking->booking->lblbooking) ? get_string('booking', 'booking') : $booking->booking->lblbooking;
    $labelLocation = empty($booking->booking->lbllocation) ? get_string('location', 'booking') : $booking->booking->lbllocation;
    $labelInstitution = empty($booking->booking->lblinstitution) ? get_string('institution', 'booking') : $booking->booking->lblinstitution;
    $labelSearchName = empty($booking->booking->lblname) ? get_string('searchName', 'booking') : $booking->booking->lblname;
    $labelSearchSurname = empty($booking->booking->lblsurname) ? get_string('searchSurname', 'booking') : $booking->booking->lblsurname;
    $row = new html_table_row(array($labelBooking, $hidden . '<form><input value="' . $urlParams['searchText'] . '" type="text" id="searchText" name="searchText">', "", ""));
    $tabledata[] = $row;
    $rowclasses[] = "";
    $row = new html_table_row(array($labelLocation, $hidden . '<input value="' . $urlParams['searchLocation'] . '" type="text" id="searchLocation" name="searchLocation">', "", ""));
    $tabledata[] = $row;
    $rowclasses[] = "";
    $row = new html_table_row(array($labelInstitution, $hidden . '<input value="' . $urlParams['searchInstitution'] . '" type="text" id="searchInstitution" name="searchInstitution">', "", ""));
    $tabledata[] = $row;
    $rowclasses[] = "";
    $row = new html_table_row(array($labelSearchName, '<form>' . $hidden . '<input value="' . $urlParams['searchName'] . '" type="text" id="searchName" name="searchName">', "", ""));
    $tabledata[] = $row;
    $rowclasses[] = "";
    $row = new html_table_row(array($labelSearchSurname, '<input value="' . $urlParams['searchSurname'] . '" type="text" id="searchSurname" name="searchSurname">', "", ""));
    $tabledata[] = $row;
    $rowclasses[] = "";
    $row = new html_table_row(array("", '<input id="searchButton" type="submit" value="' . get_string('search') . '"><input id="buttonclear" type="button" value="' . get_string('reset', 'booking') . '"></form>', "", ""));
    $tabledata[] = $row;
    $rowclasses[] = "";
    $table = new html_table();
    $table->head = array('', '', '');
    $table->data = $tabledata;
    $table->id = "tableSearch";
    if (empty($urlParams['searchText']) && empty($urlParams['searchLocation']) && empty($urlParams['searchName']) && empty($urlParams['searchInstitution']) && empty($urlParams['searchSurname'])) {
        $table->attributes = array('style' => "display: none;");
    }
    echo html_writer::table($table);
    $table = NULL;
    $displayoptions = new stdClass();
    $displayoptions->para = false;
    $tabledata = array();
    $rowclasses = array();
    $underlimit = $booking->booking->maxperuser == 0;
    $underlimit = $underlimit || booking_get_user_booking_count($booking, $user, $allresponses) < $booking->booking->maxperuser;
    // Show only one option
    if (isset($optionid)) {
        foreach ($booking->options as $option) {
            if ($optionid != $option->id) {
                unset($booking->options[$option->id]);
            }
        }
    }
    if (isset($booking->options)) {
        foreach ($booking->options as $option) {
            $current = array();
            $optiondisplay = new stdClass();
            $optiondisplay->delete = "";
            $optiondisplay->button = "";
            $hiddenfields = array('answer' => $option->id);
            $myBooking = $DB->get_record('booking_answers', array('userid' => $user->id, 'optionid' => $option->id));
            $inpast = $option->courseendtime && $option->courseendtime < time();
            $extraclass = $inpast ? ' inpast' : '';
            if ($myBooking) {
                // If I'm booked
                if ($booking->booking->allowupdate and $option->status != 'closed') {
                    $buttonoptions = array('id' => $cm->id, 'action' => 'delbooking', 'optionid' => $option->id, 'sesskey' => $user->sesskey);
                    $url = new moodle_url('view.php', $buttonoptions);
                    $optiondisplay->delete = $OUTPUT->single_button($url, empty($booking->booking->btncancelname) ? get_string('cancelbooking', 'booking') : $booking->booking->btncancelname, 'post') . '<br />';
                } else {
                    $optiondisplay->button = "";
                }
                if ($myBooking->waitinglist) {
                    $rowclasses[] = "mod-booking-watinglist" . $extraclass;
                    $optiondisplay->booked = get_string('onwaitinglist', 'booking');
                } else {
                    $rowclasses[] = "mod-booking-booked" . $extraclass;
                    if ($inpast) {
                        $optiondisplay->booked = get_string('bookedpast', 'booking');
                    } else {
                        $optiondisplay->booked = get_string('booked', 'booking');
                    }
                }
            } else {
                $optiondisplay->booked = get_string('notbooked', 'booking');
                $rowclasses[] = $extraclass;
                $buttonoptions = array('answer' => $option->id, 'id' => $cm->id, 'sesskey' => $user->sesskey);
                $url = new moodle_url('view.php', $buttonoptions);
                $url->params($hiddenfields);
                $optiondisplay->button = $OUTPUT->single_button($url, empty($booking->booking->btnbooknowname) ? get_string('booknow', 'booking') : $booking->booking->btnbooknowname, 'post');
            }
            if ($option->limitanswers && $option->status == "full" || $option->status == "closed" || !$underlimit) {
                $optiondisplay->button = '';
            }
            if ($booking->booking->cancancelbook == 0 && $option->courseendtime > 0 && $option->courseendtime < time()) {
                $optiondisplay->button = '';
                $optiondisplay->delete = '';
            }
            // Dont display button Book now if it's disabled
            if ($option->disablebookingusers) {
                $optiondisplay->button = '';
            }
            // check if user ist logged in
            if (has_capability('mod/booking:choose', $context, $user->id, false)) {
                //don't show booking button if the logged in user is the guest user.
                $bookingbutton = $optiondisplay->button;
            } else {
                $bookingbutton = get_string('havetologin', 'booking') . "<br />";
            }
            if (!$option->limitanswers) {
                $stravailspaces = get_string("unlimited", 'booking');
            } else {
                $stravailspaces = get_string("placesavailable", "booking") . ": " . $option->availspaces . " / " . $option->maxanswers . "<br />" . get_string("waitingplacesavailable", "booking") . ": " . $option->availwaitspaces . " / " . $option->maxoverbooking;
            }
            if (has_capability('mod/booking:readresponses', $context) || booking_check_if_teacher($option, $user)) {
                $numberofresponses = $option->count;
                $optiondisplay->manage = "<a href=\"report.php?id={$cm->id}&optionid={$option->id}\">" . get_string("viewallresponses", "booking", $numberofresponses) . "</a>";
            } else {
                $optiondisplay->manage = "";
            }
            $optiondisplay->bookotherusers = "";
            $cTeachers = $DB->count_records("booking_teachers", array("optionid" => $option->id, 'bookingid' => $option->bookingid));
            $teachers = $DB->get_records("booking_teachers", array("optionid" => $option->id, 'bookingid' => $option->bookingid));
            $niceTeachers = array();
            $printTeachers = "";
            if ($cTeachers > 0) {
                $printTeachers = "<p>";
                $printTeachers .= (empty($booking->booking->lblteachname) ? get_string('teachers', 'booking') : $booking->booking->lblteachname) . ': ';
                foreach ($teachers as $teacher) {
                    $tmpuser = $DB->get_record('user', array('id' => $teacher->userid));
                    $niceTeachers[] = fullname($tmpuser);
                }
                $printTeachers .= implode(', ', $niceTeachers);
                $printTeachers .= "</p>";
            }
            $additionalInfo = '';
            if (strlen($option->location) > 0) {
                $additionalInfo .= '<p>' . get_string('location', "booking") . ': ' . $option->location . '</p>';
            }
            if (strlen($option->institution) > 0) {
                $additionalInfo .= '<p>' . get_string('institution', "booking") . ': ' . $option->institution . '</p>';
            }
            if (strlen($option->address) > 0) {
                $additionalInfo .= '<p>' . get_string('address', "booking") . ': ' . $option->address . '</p>';
            }
            $row = new html_table_row(array("<span id=\"option{$option->id}\"></span>" . $bookingbutton . $optiondisplay->booked . '
		<br />' . get_string($option->status, "booking") . '
		<br />' . $optiondisplay->delete . $optiondisplay->manage . '
		<br />' . $optiondisplay->bookotherusers, "<b>" . format_text($option->text . ' ', FORMAT_MOODLE, $displayoptions) . "</b>" . "<p>" . $option->description . "</p>" . $printTeachers . $additionalInfo, $option->coursestarttimetext . " " . get_string('to', "booking") . " <br />" . $option->courseendtimetext, $stravailspaces));
            $tabledata[] = $row;
        }
    }
    $table = new html_table();
    $table->attributes['class'] = 'box generalbox boxaligncenter boxwidthwide booking';
    $table->attributes['style'] = '';
    $table->data = array();
    $strselect = get_string("select", "booking");
    $strbooking = get_string("booking", "booking");
    if (strlen($booking->booking->eventtype) > 0) {
        $strbooking = $booking->booking->eventtype;
    }
    $strdate = '<a href="' . $sorturl . '">' . get_string("coursedate", "booking") . '</a>';
    $stravailability = get_string("availability", "booking");
    $table->head = array($strselect, $strbooking, $strdate, $stravailability);
    $table->align = array("left", "left", "left", "left");
    $table->rowclasses = $rowclasses;
    $table->data = $tabledata;
    echo html_writer::table($table);
}
    echo '<input type="button" id="checknone" value="' . get_string('deselectall') . '" /> ';
    echo '</div>';
    echo '<div>';
    if (!$bookingData->booking->autoenrol && has_capability('mod/booking:communicate', context_module::instance($cm->id))) {
        if ($bookingData->option->courseid > 0) {
            echo '<input type="submit" name="subscribetocourse" value="' . get_string('subscribetocourse', 'booking') . '" />';
        }
    }
    if (has_capability('mod/booking:deleteresponses', context_module::instance($cm->id))) {
        echo '<input type="submit" name="deleteusers" value="' . get_string('booking:deleteresponses', 'booking') . '" />';
    }
    if (has_capability('mod/booking:communicate', context_module::instance($cm->id))) {
        echo '<input type="submit" name="sendpollurl" value="' . get_string('booking:sendpollurl', 'booking') . '" />';
        echo '<input type="submit" name="sendcustommessage" value="' . get_string('sendcustommessage', 'booking') . '" />';
    }
    if (booking_check_if_teacher($bookingData->option, $USER) || has_capability('mod/booking:updatebooking', context_module::instance($cm->id))) {
        echo '<input type="submit" name="activitycompletion" value="' . (empty($bookingData->booking->btncacname) ? get_string('confirmactivitycompletion', 'booking') : $bookingData->booking->btncacname) . '" />';
        if ($bookingData->option->conectedoption > 0) {
            echo '<input type="submit" name="booktootherbooking" value="' . get_string('booktootherbooking', 'booking') . '" />';
        }
    }
    echo '</div>';
    echo '</form>';
    $onlyOneURL = new moodle_url('/mod/booking/view.php', array('id' => $id, 'optionid' => $optionid, 'action' => 'showonlyone', 'whichview' => 'showonlyone'));
    $onlyOneURL->set_anchor('goenrol');
    echo '<br>' . html_writer::start_span('') . get_string('onlythisbookingurl', 'booking') . ': ' . html_writer::link($onlyOneURL, $onlyOneURL, array()) . html_writer::end_span();
    echo '<br>' . html_writer::start_span('') . get_string('pollurl', 'booking') . ': ' . html_writer::link($bookingData->option->pollurl, $bookingData->option->pollurl, array()) . ($bookingData->option->pollsend ? ' &#x2713;' : '') . html_writer::end_span();
    $PAGE->requires->js_init_call('M.mod_booking.init');
    echo $OUTPUT->footer();
} else {
    if ($download == "ods" or $download == "xls" && has_capability('mod/booking:downloadresponses', $context)) {
示例#4
0
     $selectedusers = array_keys($fromform->user, 1);
     if (empty($selectedusers)) {
         redirect($url, get_string('selectatleastoneuser', 'booking', $bookingData->option->howmanyusers), 5);
     }
     $sendmessageurl = new moodle_url('/mod/booking/sendmessage.php', array('id' => $id, 'optionid' => $optionid, 'uids' => serialize($selectedusers)));
     redirect($sendmessageurl);
 } else {
     if (isset($fromform->activitycompletion) && (booking_check_if_teacher($bookingData->option, $USER) || has_capability('mod/booking:readresponses', $context)) && confirm_sesskey()) {
         $selectedusers = array_keys($fromform->user, 1);
         if (empty($selectedusers)) {
             redirect($url, get_string('selectatleastoneuser', 'booking', $bookingData->option->howmanyusers), 5);
         }
         booking_activitycompletion($selectedusers, $bookingData->booking, $cm->id, $optionid);
         redirect($url, get_string('activitycompletionsuccess', 'booking'), 5);
     } else {
         if (isset($fromform->booktootherbooking) && (booking_check_if_teacher($bookingData->option, $USER) || has_capability('mod/booking:readresponses', $context)) && confirm_sesskey()) {
             $selectedusers = array_keys($fromform->user, 1);
             if (empty($selectedusers)) {
                 redirect($url, get_string('selectatleastoneuser', 'booking', $bookingData->option->howmanyusers), 5);
             }
             if (count($selectedusers) > $bookingData->canBookToOtherBooking) {
                 redirect($url, get_string('toomuchusersbooked', 'booking', $bookingData->canBookToOtherBooking), 5);
             }
             $tmpcmid = $DB->get_record_sql("SELECT cm.id FROM {course_modules} cm JOIN {modules} md ON md.id = cm.module JOIN {booking} m ON m.id = cm.instance WHERE md.name = 'booking' AND cm.instance = ?", array($bookingData->booking->conectedbooking));
             $tmpBooking = new booking_option($tmpcmid->id, $bookingData->option->conectedoption);
             foreach ($selectedusers as $value) {
                 $user = new stdClass();
                 $user->id = $value;
                 $tmpBooking->user_submit_response($user);
             }
             redirect($url, get_string('userssucesfullybooked', 'booking', $bookingData->canBookToOtherBooking), 5);
                foreach ($users as $user) {
                    if (!$bookingoption->user_delete_response($user->id)) {
                        $unsubscribesuccess = false;
                        print_error('cannotremovesubscriber', 'forum', $errorurl->out(), $user->id);
                    }
                }
            } else {
                if ($unsubscribe && (!has_capability('mod/booking:deleteresponses', $context) || booking_check_if_teacher($bookingoption->option, $USER))) {
                    print_error('nopermission', null, $errorurl->out());
                }
            }
        }
        $subscriberselector->invalidate_selected_users();
        $existingselector->invalidate_selected_users();
        $bookingoption->update_booked_users();
        $subscriberselector->set_potential_users($bookingoption->potentialusers);
        $existingselector->set_potential_users($bookingoption->bookedvisibleusers);
    }
}
echo $OUTPUT->header();
echo html_writer::tag('div', html_writer::link(new moodle_url('/mod/booking/report.php', array('id' => $cm->id, 'optionid' => $optionid)), get_string('backtoresponses', 'booking')), array('style' => 'width:100%; font-weight: bold; text-align: right;'));
if ($subscribesuccess || $unsubscribesuccess) {
    if ($subscribesuccess) {
        echo $OUTPUT->container(get_string('allchangessave', 'booking'), 'important', 'notice');
    }
    if ($unsubscribesuccess && (has_capability('mod/booking:deleteresponses', $context) || booking_check_if_teacher($bookingoption->option, $USER))) {
        echo $OUTPUT->container(get_string('allchangessave', 'booking'), 'important', 'notice');
    }
}
echo $bookingoutput->subscriber_selection_form($existingselector, $subscriberselector);
echo $OUTPUT->footer();