/**
* Given an ID of an instance of this module, 
* this function will permanently delete the instance 
* and any data that depends on it.  
* @param int $id the instance to be deleted
* @return boolean true if success, false otherwise
*/
function scheduler_delete_instance($id)
{
    global $CFG;
    if (!($scheduler = get_record('scheduler', 'id', "{$id}"))) {
        return false;
    }
    $result = true;
    # Delete any dependent records here #
    if (!delete_records('scheduler', 'id', $scheduler->id)) {
        $result = false;
    }
    $oldslots = get_records('scheduler_slots', 'schedulerid', $scheduler->id, '', 'id, id');
    if ($oldslots) {
        foreach (array_keys($oldslots) as $slotId) {
            // will delete appointements and remaining related events
            scheduler_delete_slot($slotId);
        }
    }
    return $result;
}
     }
     print_heading(get_string('slotsadded', 'scheduler', $countslots));
     break;
     /************************************ Deleting a slot ***********************************************/
 /************************************ Deleting a slot ***********************************************/
 case 'deleteslot':
     $slotid = required_param('slotid', PARAM_INT);
     scheduler_delete_slot($slotid);
     break;
     /************************************ Deleting multiple slots ***********************************************/
 /************************************ Deleting multiple slots ***********************************************/
 case 'deleteslots':
     $slotids = required_param('items', PARAM_RAW);
     $slots = explode(",", $slotids);
     foreach ($slots as $aSlotId) {
         scheduler_delete_slot($aSlotId);
     }
     break;
     /************************************ Students were seen ***************************************************/
 /************************************ Students were seen ***************************************************/
 case 'saveseen':
     // get required param
     $slotid = required_param('slotid', PARAM_INT);
     $seen = optional_param('seen', array(), PARAM_RAW);
     $appointments = scheduler_get_appointments($slotid);
     if (is_array($seen)) {
         foreach ($appointments as $anAppointment) {
             $anAppointment->attended = in_array($anAppointment->id, $seen) ? 1 : 0;
             $anAppointment->timemodified = time();
             $anAppointment->appointmentnote = str_replace("'", "\\'", $anAppointment->appointmentnote);
             if (!update_record('scheduler_appointment', $anAppointment)) {