/** * change the visibility of a course * * @return void */ function change_visibility_action() { if ((Config::get()->ALLOW_DOZENT_VISIBILITY || $GLOBALS['perm']->have_perm('admin')) && !LockRules::Check($GLOBALS['SessionSeminar'], 'seminar_visibility') && Seminar_Session::check_ticket(Request::option('studip_ticket'))) { $course = Course::findCurrent(); if (!$course->visible) { StudipLog::log('SEM_VISIBLE', $course->id); $course->visible = 1; $msg = _("Die Veranstaltung wurde sichtbar gemacht."); } else { StudipLog::log('SEM_INVISIBLE', $course->id); $course->visible = 0; $msg = _("Die Veranstaltung wurde versteckt."); } if ($course->store()) { PageLayout::postMessage(MessageBox::success($msg)); } } $this->redirect($this->url_for('/index')); }
public static function removeCourseFromSet($set_id, $course_id) { $db = DBManager::get(); $ok = $db->execute("DELETE FROM seminar_courseset WHERE set_id=? AND seminar_id=? LIMIT 1", array($set_id, $course_id)); if ($ok) { StudipLog::log('SEM_CHANGED_ACCESS', $course_id, null, 'Entfernung von Anmeldeset', sprintf('Anmeldeset: %s', $set_id)); //Delete priorities AdmissionPriority::unsetAllPrioritiesForCourse($course_id); } return $ok; }
/** * This action remove a user from course * @param $course_id */ public function decline_action($course_id, $waiting = null) { $current_seminar = Seminar::getInstance($course_id); $ticket_check = Seminar_Session::check_ticket(Request::option('studipticket')); if (LockRules::Check($course_id, 'participants')) { $lockdata = LockRules::getObjectRule($course_id); PageLayout::postMessage(MessageBox::error(sprintf(_("Sie können sich nicht von der Veranstaltung <b>%s</b> abmelden."), htmlReady($current_seminar->name)))); if ($lockdata['description']) { PageLayout::postMessage(MessageBox::info(formatLinks($lockdata['description']))); } $this->redirect('my_courses/index'); return; } if (Request::option('cmd') == 'back') { $this->redirect('my_courses/index'); return; } if (Request::option('cmd') != 'kill' && Request::option('cmd') != 'kill_admission') { if ($current_seminar->admission_binding && Request::get('cmd') != 'suppose_to_kill_admission' && !LockRules::Check($current_seminar->getId(), 'participants')) { PageLayout::postMessage(MessageBox::error(sprintf(_("Die Veranstaltung <b>%s</b> ist als <b>bindend</b> angelegt.\n Wenn Sie sich abmelden wollen, müssen Sie sich an die Lehrende der Veranstaltung wenden."), htmlReady($current_seminar->name)))); $this->redirect('my_courses/index'); return; } if (Request::get('cmd') == 'suppose_to_kill') { // check course admission list(, $admission_end_time) = @array_values($current_seminar->getAdmissionTimeFrame()); $admission_enabled = $current_seminar->isAdmissionEnabled(); $admission_locked = $current_seminar->isAdmissionLocked(); if ($admission_enabled || $admission_locked || (int) $current_seminar->admission_prelim == 1) { $message = sprintf(_('Wollen Sie sich von der teilnahmebeschränkten Veranstaltung "%s" wirklich abmelden? Sie verlieren damit die Berechtigung für die Veranstaltung und müssen sich ggf. neu anmelden!'), $current_seminar->name); } else { if (isset($admission_end_time) && $admission_end_time < time()) { $message = sprintf(_('Wollen Sie sich von der teilnahmebeschränkten Veranstaltung "%s" wirklich abmelden? Der Anmeldzeitraum ist abgelaufen und Sie können sich nicht wieder anmelden!'), $current_seminar->name); } else { $message = sprintf(_('Wollen Sie sich von der Veranstaltung "%s" wirklich abmelden?'), $current_seminar->name); } } $this->flash['cmd'] = 'kill'; } else { if (admission_seminar_user_get_position($GLOBALS['user']->id, $course_id) === false) { $message = sprintf(_('Wollen Sie sich von der Anmeldeliste der Veranstaltung "%s" wirklich abmelden?'), $current_seminar->name); } else { $message = sprintf(_('Wollen Sie sich von der Warteliste der Veranstaltung "%s" wirklich abmelden? Sie verlieren damit die bereits erreichte Position und müssen sich ggf. neu anmelden!'), $current_seminar->name); } $this->flash['cmd'] = 'kill_admission'; } $this->flash['decline_course'] = true; $this->flash['course_id'] = $course_id; $this->flash['message'] = $message; $this->flash['studipticket'] = Seminar_Session::get_ticket(); $this->redirect('my_courses/index'); return; } else { if (!LockRules::Check($course_id, 'participants') && $ticket_check && Request::option('cmd') != 'back' && Request::get('cmd') != 'kill_admission') { $query = "DELETE FROM seminar_user WHERE user_id = ? AND Seminar_id = ?"; $statement = DBManager::get()->prepare($query); $statement->execute(array($GLOBALS['user']->id, $course_id)); if ($statement->rowCount() == 0) { PageLayout::postMessage(MessageBox::error(_('In der ausgewählten Veranstaltung wurde die gesuchten Personen nicht gefunden und konnte daher nicht ausgetragen werden.'))); } else { // LOGGING StudipLog::log('SEM_USER_DEL', $course_id, $GLOBALS['user']->id, 'Hat sich selbst ausgetragen'); // enable others to do something after the user has been deleted NotificationCenter::postNotification('UserDidLeaveCourse', $course_id, $GLOBALS['user']->id); // Delete from statusgroups RemovePersonStatusgruppeComplete(get_username(), $course_id); // Are successor available update_admission($course_id); PageLayout::postMessage(MessageBox::success(sprintf(_("Erfolgreich von Veranstaltung <b>%s</b> abgemeldet."), htmlReady($current_seminar->name)))); } } else { // LOGGING StudipLog::log('SEM_USER_DEL', $course_id, $GLOBALS['user']->id, 'Hat sich selbst aus der Warteliste ausgetragen'); if ($current_seminar->isAdmissionEnabled()) { $prio_delete = AdmissionPriority::unsetPriority($current_seminar->getCourseSet()->getId(), $GLOBALS['user']->id, $course_id); } $query = "DELETE FROM admission_seminar_user WHERE user_id = ? AND seminar_id = ?"; $statement = DBManager::get()->prepare($query); $statement->execute(array($GLOBALS['user']->id, $course_id)); if ($statement->rowCount() || $prio_delete) { //Warteliste neu sortieren renumber_admission($course_id); //Pruefen, ob es Nachruecker gibt update_admission($course_id); PageLayout::postMessage(MessageBox::success(sprintf(_("Der Eintrag in der Anmelde- bzw. Warteliste der Veranstaltung <b>%s</b> wurde aufgehoben.\n Wenn Sie an der Veranstaltung teilnehmen wollen, müssen Sie sich erneut bewerben."), htmlReady($current_seminar->name)))); } } $this->redirect('my_courses/index'); return; } }
/** * Logs an event to the database after a certain action took place along with * the ids of the range object the action possibly affected. You can provide * additional info as well as debug information. * * @deprecated use StudipLog::log() instead * @param String $action Name of the action that took place * @param mixed $affected Range id that was affected by the action, if any * @param mixed $coaffected Range id that was possibly affected as well * @param mixed $info Information to add to the event * @param mixed $dbg_info Debug information to add to the event * @param mixed $user_id Provide null for the current user id **/ function log_event($action, $affected = null, $coaffected = null, $info = null, $dbg_info = null, $user_id = null) { return StudipLog::log($action, $affected, $coaffected, $info, $dbg_info, $user_id); }
/** * Set the visibility of a course */ public function set_visibility_action() { $result = false; $visibilites = Request::getArray('visibility'); $all_courses = Request::getArray('all_sem'); $errors = array(); if (!empty($all_courses)) { foreach ($all_courses as $course_id) { $course = Course::find($course_id); $visibility = isset($visibilites[$course_id]) ? 1 : 0; if ((int) $course->visible == $visibility) { continue; } $course->setValue('visible', $visibility); if (!$course->store()) { $errors[] = $course->name; } else { $result = true; StudipLog::log($visibility ? 'SEM_VISIBLE' : 'SEM_INVISIBLE', $course->id); } } if ($result) { PageLayout::postMessage(MessageBox::success(_('Die Sichtbarkeit wurde bei den gewünschten Veranstatungen erfolgreich geändert!'))); } if ($errors) { PageLayout::postMessage(MessageBox::error(_('Bei den folgenden Veranstaltungen ist ein Fehler aufgetreten'), array_map('htmlReady', $errors))); } } $this->redirect('admin/courses/index'); }
/** * adds user with given id on waitinglist * * @param string $user_id * @param string $which_end 'last' or 'first' * @return integer 1 if successfull */ public function addToWaitlist($user_id, $which_end = 'last') { if (AdmissionApplication::exists(array($user_id, $this->id)) || CourseMember::find(array($this->id, $user_id))) { return false; } switch ($which_end) { // Append users to waitlist end. case 'last': $maxpos = DBManager::get()->fetchColumn("SELECT MAX(`position`) FROM `admission_seminar_user` WHERE `seminar_id`=? AND `status`='awaiting'", array($this->id)); $waitpos = $maxpos+1; break; // Prepend users to waitlist start. case 'first': default: // Move all others on the waitlist up by the number of people to add. DBManager::get()->execute("UPDATE `admission_seminar_user` SET `position`=`position`+1 WHERE `seminar_id`=? AND `status`='awaiting'", array($this->id)); $waitpos = 1; } $new_admission_member = new AdmissionApplication(); $new_admission_member->user_id = $user_id; $new_admission_member->position = $waitpos; $new_admission_member->status = 'awaiting'; $new_admission_member->seminar_id = $this->id; if ($new_admission_member->store()) { StudipLog::log('SEM_USER_ADD', $this->id, $user_id, 'awaiting', 'Auf Warteliste gesetzt, Position: ' . $waitpos); $this->course->resetRelation('admission_applicants'); return 1; } return false; }
/** * This function updates an admission procedure * * The function checks, if user could be insert to the seminar. * The User gets a message, if he is inserted to the seminar * * @param string seminar_id the seminar_id of the seminar to calculate * @param boolean send_message should a system-message be send? * */ function normal_update_admission($seminar_id, $send_message = TRUE) { $messaging=new messaging; //Daten holen / Abfrage ob ueberhaupt begrenzt $seminar = Seminar::GetInstance($seminar_id); if($seminar->isAdmissionEnabled()){ $sem_preliminary = ($seminar->admission_prelim == 1); $cs = $seminar->getCourseSet(); //Veranstaltung einfach auffuellen (nach Lostermin und Ende der Kontingentierung) if (!$seminar->admission_disable_waitlist_move && $cs->hasAlgorithmRun()) { //anzahl der freien Plaetze holen $count = (int)$seminar->getFreeAdmissionSeats(); //Studis auswaehlen, die jetzt aufsteigen koennen $query = "SELECT user_id, username FROM admission_seminar_user LEFT JOIN auth_user_md5 USING (user_id) WHERE seminar_id = ? AND status = 'awaiting' ORDER BY position LIMIT " . (int)$count; $statement = DBManager::get()->prepare($query); $statement->execute(array($seminar->getId())); $temp = $statement->fetchAll(PDO::FETCH_ASSOC); foreach ($temp as $row) { //ok, here ist the "colored-group" meant (for grouping on meine_seminare), not the grouped seminars as above! $group = select_group($seminar->getSemesterStartTime()); if (!$sem_preliminary) { $query = "INSERT INTO seminar_user (user_id, Seminar_id, status, gruppe, mkdate) VALUES (?, ?, 'autor', ?, UNIX_TIMESTAMP())"; $statement = DBManager::get()->prepare($query); $statement->execute(array( $row['user_id'], $seminar->getId(), $group )); $affected = $statement->rowCount(); NotificationCenter::postNotification('UserDidEnterCourse', $seminar->getId(), $row['user_id']); } else { $query = "UPDATE admission_seminar_user SET status = 'accepted' WHERE user_id = ? AND seminar_id = ?"; $statement = DBManager::get()->prepare($query); $statement->execute(array( $row['user_id'], $seminar->getId() )); $affected = $statement->rowCount(); } if ($affected > 0) { $log_message = 'Wurde automatisch aus der Warteliste in die Veranstaltung eingetragen.'; StudipLog::log('SEM_USER_ADD', $seminar->getId(), $row['user_id'], $sem_preliminary ? 'accepted' : 'autor', $log_message); if (!$sem_preliminary) { $query = "DELETE FROM admission_seminar_user WHERE user_id = ? AND seminar_id = ?"; $statement = DBManager::get()->prepare($query); $statement->execute(array( $row['user_id'], $seminar->getId() )); $affected = $statement->rowCount(); } else { $affected = 0; } //User benachrichtigen if (($sem_preliminary || $affected > 0) && $send_message) { setTempLanguage($row['user_id']); if (!$sem_preliminary) { $message = sprintf (_('Sie sind in die Veranstaltung **%s (%s)** eingetragen worden, da für Sie ein Platz frei geworden ist. Ab sofort finden Sie die Veranstaltung in der Übersicht Ihrer Veranstaltungen. Damit sind Sie auch für die Präsenzveranstaltung zugelassen.'), $seminar->getName(), $seminar->getFormattedTurnus(true)); } else { $message = sprintf (_('Sie haben den Status vorläufig akzeptiert in der Veranstaltung **%s (%s)** erhalten, da für Sie ein Platz freigeworden ist.'), $seminar->getName(), $seminar->getFormattedTurnus(true)); } $subject = sprintf(_("Teilnahme an der Veranstaltung %s"),$seminar->getName()); restoreLanguage(); $messaging->insert_message($message, $row['username'], '____%system%____', FALSE, FALSE, '1', FALSE, $subject, true); } } } //Warteposition der restlichen User neu eintragen renumber_admission($seminar_id, FALSE); } $seminar->restore(); } }
function setTime($start, $end) { if ($start == 0 || $end == 0) { return false; } if ($this->date != $start || $this->end_time != $end) { // validate the passed variables: they have to be ints and $start // has to be smaller than $end if ($this->validate($start, $end)) { $before = $this->toString(); // if the time-span has been shortened, keep the room-assignment, // otherwise remove it. if ($this->resource_id) { if ($start >= $this->date && $end <= $this->end_time) { $this->shrinkAssign($start, $end); } else { $this->killAssign(); } } $this->date = $start; $this->end_time = $end; $after = $this->toString(); // logging if ($before) { StudipLog::log("SINGLEDATE_CHANGE_TIME", $this->range_id, $before, $before . ' -> ' . $after); } else { StudipLog::log("SEM_ADD_SINGLEDATE", $this->range_id, $after); } return true; } return false; } return false; }
/** * Notify users that they couldn't get a seat but are now on the waiting * list for a given course. * * @param Array $user_list Users to be notified * @param Course $course The course without waiting list * @param int $prio User's priority for the given course. */ private function addUsersToWaitlist($user_list, $course, $prio = null) { $maxpos = $course->admission_applicants->findBy('status', 'awaiting')->orderBy('position desc')->val('position'); foreach ($user_list as $chosen_one) { $maxpos++; $new_admission_member = new AdmissionApplication(); $new_admission_member->user_id = $chosen_one; $new_admission_member->position = $maxpos; $new_admission_member->status = 'awaiting'; $course->admission_applicants[] = $new_admission_member; if ($new_admission_member->store()) { setTempLanguage($chosen_one); $message_title = sprintf(_('Teilnahme an der Veranstaltung %s'), $course->name); $message_body = sprintf(_('Sie wurden leider im Losverfahren der Veranstaltung **%s** __nicht__ ausgelost. Sie wurden jedoch auf Position %s auf die Warteliste gesetzt. Das System wird Sie automatisch eintragen und benachrichtigen, sobald ein Platz für Sie frei wird.'), $course->name, $maxpos); if ($prio) { $message_body .= "\n" . sprintf(_("Sie hatten für diese Veranstaltung die Priorität %s gewählt."), $prio[$chosen_one]); } messaging::sendSystemMessage($chosen_one, $message_title, $message_body); restoreLanguage(); StudipLog::log('SEM_USER_ADD', $course->id, $chosen_one, 'awaiting', 'Auf Warteliste gelost, Position: ' . $maxpos); } } }
/** * Stores this cycle. * @return int number of changed rows */ public function store() { $cycle = parent::findByMetadate_id($this->metadate_id); //create new entry in seminare_cycle_date if (!$cycle) { $result = parent::store(); if ($result) { $new_dates = $this->createTerminSlots(); foreach ($new_dates as $semester_dates) { foreach ($semester_dates['dates'] as $date) { $result += $date->store(); } } StudipLog::log('SEM_ADD_CYCLE', $this->seminar_id, NULL, $this->toString()); return $result; } return 0; } //change existing cycledate, changes also corresponding single dates $old_cycle = SeminarCycleDate::find($this->metadate_id); if (!parent::store()) { return false; } if (mktime($this->start_time) >= mktime($old_cycle->start_time) && mktime($this->end_time) <= mktime($old_cycle->end_time) && $this->weekday == $old_cycle->weekday && $this->end_offset == $old_cycle->end_offset) { $update_count = 0; foreach ($this->getAllDates() as $date) { $tos = $date->date; $toe = $date->end_time; //Update future dates if ($toe > time()) { $date->date = mktime(date('G', strtotime($this->start_time)), date('i', strtotime($this->start_time)), 0, date('m', $tos), date('d', $tos), date('Y', $tos)); $date->end_time = mktime(date('G', strtotime($this->end_time)), date('i', strtotime($this->end_time)), 0, date('m', $toe), date('d', $toe), date('Y', $toe)); } if ($date->isDirty()) { $date->store(); $update_count++; } } StudipLog::log('SEM_CHANGE_CYCLE', $this->seminar_id, NULL, $old_cycle->toString() . ' -> ' . $this->toString()); return $update_count; } //collect topics for existing future dates (CourseDate) $topics = array(); foreach ($this->getAllDates() as $date) { if ($date->end_time >= time()) { $topics_tmp = CourseTopic::findByTermin_id($date->termin_id); if (!empty($topics_tmp)) { $topics[] = $topics_tmp; } //uncomment below $date->delete(); } } $new_dates = $this->createTerminSlots(time()); $topic_count = 0; $update_count = 0; foreach ($new_dates as $semester_dates) { foreach ($semester_dates['dates'] as $date) { if ($date instanceof CourseDate) { if (isset($topics[$topic_count])) { $date->topics = $topics[$topic_count]; $topic_count++; } } $date->store(); $update_count++; } } StudipLog::log('SEM_CHANGE_CYCLE', $this->seminar_id, NULL, $old_cycle->toString() . ' -> ' . $this->toString()); return $update_count; }
/** * unset priority for given user,set and course * reorder remaining priorities * * @param String courseSetId * @param String userId * @param String courseId * @return int Number of affected rows, if any. */ public static function unsetPriority($courseSetId, $userId, $courseId) { $db = DBManager::get(); $deleted = $db->execute("DELETE FROM priorities WHERE user_id=? AND seminar_id=? AND set_id=? LIMIT 1", array($userId, $courseId, $courseSetId)); if ($deleted) { $priovar = md5($courseSetId . $userId); $db->exec("SET @{$priovar}:=0"); $db->execute("UPDATE priorities SET priority = @{$priovar}:=@{$priovar}+1 WHERE user_id=? AND set_id=? ORDER BY priority", array($userId, $courseSetId)); StudipLog::log('SEM_USER_DEL', $courseId, $userId, 'Anmeldung zur Platzvergabe zurückgezogen', sprintf('Anmeldeset: %s', $courseSetId)); } return $deleted; }