Exemplo n.º 1
0
 /**
  * Tries to obtain a lock with a name given by the string $lockname, 
  * using a timeout of $timeout seconds. Returns 1 if the lock was obtained 
  * successfully, 0 if the attempt timed out 
  * (for example, because another client has previously locked the name),
  * or NULL if an error occurred
  * If a name has been locked by one client, any request by another client
  * for a lock with the same name is blocked.
  * 
  * @param string $lockname
  * @param number $timeout in seconds
  * @throws UnexpectedValueException if there is already an active lock
  * @return integer 1 if the lock was obtained successfully, 0 if the attempt timed out 
  */
 public static function get($lockname, $timeout = 10)
 {
     if (self::$current !== null) {
         throw new UnexpectedValueException(sprintf('could not acquire new lock, %s still active'));
     }
     $ok = DBManager::get()->fetchColumn("SELECT GET_LOCK(?,?)", array(self::lockname($lockname), $timeout));
     if ($ok) {
         self::$current = $lockname;
     }
     return $ok;
 }
Exemplo n.º 2
0
 /**
  * A person applies for a course.
  */
 function apply_action()
 {
     $user_id = $GLOBALS['user']->id;
     $courseset = CourseSet::getSetForCourse($this->course_id);
     $this->course_name = PageLayout::getTitle();
     if ($courseset) {
         $errors = $courseset->checkAdmission($user_id, $this->course_id);
         if (count($errors)) {
             $this->courseset_message = $courseset->toString(true);
             $this->admission_error = MessageBox::error(_("Die Anmeldung war nicht erfolgreich."), $errors);
             foreach ($courseset->getAdmissionRules() as $rule) {
                 $admission_form .= $rule->getInput();
             }
             if ($admission_form) {
                 $this->admission_form = $admission_form;
             }
         } else {
             if ($courseset->isSeatDistributionEnabled()) {
                 if ($courseset->hasAlgorithmRun()) {
                     if ($courseset->getSeatDistributionTime()) {
                         $msg = _("Die Plätze in dieser Veranstaltung wurden automatisch verteilt.");
                     }
                     if (StudipLock::get('enrolment' . $this->course_id)) {
                         $course = Course::find($this->course_id);
                         if ($course->getFreeSeats() && !$course->getNumWaiting()) {
                             $enrol_user = true;
                         } else {
                             if ($course->isWaitlistAvailable()) {
                                 $seminar = new Seminar($course);
                                 if ($seminar->addToWaitlist($user_id, 'last')) {
                                     $msg_details[] = sprintf(_("Alle Plätze sind belegt, Sie wurden daher auf Platz %s der Warteliste gesetzt."), $maxpos);
                                 }
                             } else {
                                 $this->admission_error = MessageBox::error(_("Die Anmeldung war nicht erfolgreich. Alle Plätze sind belegt und es steht keine Warteliste zur Verfügung."));
                             }
                         }
                     } else {
                         $this->admission_error = MessageBox::error(_("Die Anmeldung war wegen technischer Probleme nicht erfolgreich. Bitte versuchen Sie es später noch einmal."));
                     }
                 } else {
                     $msg = _("Die Plätze in dieser Veranstaltung werden automatisch verteilt.");
                     if ($limit = $courseset->getAdmissionRule('LimitedAdmission')) {
                         $msg_details[] = sprintf(_("Diese Veranstaltung gehört zu einem Anmeldeset mit %s Veranstaltungen. Sie können maximal %s davon belegen. Bei der Verteilung werden die von Ihnen gewünschten Prioritäten berücksichtigt."), count($courseset->getCourses()), $limit->getMaxNumber());
                         $this->user_max_limit = $limit->getMaxNumberForUser($user_id);
                         if (get_config('IMPORTANT_SEMNUMBER')) {
                             $order = "ORDER BY VeranstaltungsNummer, Name";
                         } else {
                             $order = "ORDER BY Name";
                         }
                         $this->priocourses = Course::findMany($courseset->getCourses(), $order);
                         $this->user_prio = AdmissionPriority::getPrioritiesByUser($courseset->getId(), $user_id);
                         $this->max_limit = $limit->getMaxNumber();
                         $this->prio_stats = AdmissionPriority::getPrioritiesStats($courseset->getId());
                         $this->already_claimed = count($this->user_prio);
                     } else {
                         $this->priocourses = Course::find($this->course_id);
                         $this->already_claimed = array_key_exists($this->course_id, AdmissionPriority::getPrioritiesByUser($courseset->getId(), $user_id));
                     }
                     $msg_details[] = _("Zeitpunkt der automatischen Verteilung: ") . strftime("%x %X", $courseset->getSeatDistributionTime());
                     $this->num_claiming = count(AdmissionPriority::getPrioritiesByCourse($courseset->getId(), $this->course_id));
                     if ($this->already_claimed) {
                         $msg_details[] = _("Sie sind bereits für die Verteilung angemeldet.");
                     }
                 }
                 $this->courseset_message = MessageBox::info($msg, $msg_details);
             } else {
                 $enrol_user = true;
             }
         }
     } else {
         $enrol_user = true;
     }
     if ($enrol_user) {
         $course = Seminar::GetInstance($this->course_id);
         if ($course->admission_prelim) {
             if (!$course->isStudygroup() && $course->admission_prelim_txt && !Request::submitted('apply')) {
                 $this->admission_prelim_txt = $course->admission_prelim_txt;
                 $this->admission_prelim_comment = Config::get()->ADMISSION_PRELIM_COMMENT_ENABLE;
                 $this->admission_form = $this->render_template_as_string('course/enrolment/prelim');
             } else {
                 if (Request::get('admission_comment')) {
                     $admission_comment = get_fullname() . ': ' . Request::get('admission_comment');
                 } else {
                     $admission_comment = '';
                 }
                 if ($course->addPreliminaryMember($user_id, $admission_comment)) {
                     if ($course->isStudygroup()) {
                         if (StudygroupModel::isInvited($user_id, $this->course_id)) {
                             // an invitation exists, so accept the join request automatically
                             $status = 'autor';
                             StudygroupModel::accept_user(get_username($user_id), $this->course_id);
                             StudygroupModel::cancelInvitation(get_username($user_id), $this->course_id);
                             $success = sprintf(_("Sie wurden in die Veranstaltung %s als %s eingetragen."), $course->getName(), get_title_for_status($status, 1));
                             PageLayout::postMessage(MessageBox::success($success));
                         } else {
                             $success = sprintf(_("Sie wurden auf die Anmeldeliste der Studiengruppe %s eingetragen. Die Moderatoren der Studiengruppe können Sie jetzt freischalten."), $course->getName());
                             PageLayout::postMessage(MessageBox::success($success));
                         }
                     } else {
                         $success = sprintf(_("Sie wurden in die Veranstaltung %s vorläufig eingetragen."), $course->getName());
                         PageLayout::postMessage(MessageBox::success($success));
                     }
                 }
             }
         } else {
             $status = 'autor';
             if ($course->addMember($user_id, $status)) {
                 $success = sprintf(_("Sie wurden in die Veranstaltung %s als %s eingetragen."), $course->getName(), get_title_for_status($status, 1));
                 PageLayout::postMessage(MessageBox::success($success));
                 $this->enrol_user = true;
                 if (StudygroupModel::isInvited($user_id, $this->course_id)) {
                     // delete an existing invitation
                     StudygroupModel::cancelInvitation(get_username($user_id), $this->course_id);
                 }
             }
         }
         unset($this->courseset_message);
     }
     StudipLock::release();
 }