public function saveUnregistered() { /* @var $peep Signup_Peep Current signup person */ $peep = $this->peep; /* @var $slot Signup_Slot Current slot peep is requesting */ $slot = $this->slot; $db = new PHPWS_DB('signup_peeps'); $db->addWhere('slot_id', $peep->slot_id); // lock carries over to saving of peep. $db->setLock('signup_peeps', 'read'); /** * Check peeps table to count the number of registrations for the * requested slot * (addColumn has "count" indicated) */ $db->addColumn('id', null, null, true); $db->addWhere('registered', 1); /** * @var $filled Number of registered peeps in the slot */ $filled = $db->select('one'); /** * See if the peep previous signed up for this sheet. If multiple is * allowed, previous is automatically false */ if ($this->sheet->multiple) { $previous = false; } else { $db->reset(); $db->addWhere('sheet_id', $peep->sheet_id); $db->addWhere('email', $peep->email); $db->addColumn('id'); /* @var $previous integer */ $previous = $db->select('one'); } if (PHPWS_Error::logIfError($previous)) { $this->forwardMessage(dgettext('signup', 'An error occurred when trying to save your application.'), dgettext('signup', 'Sorry')); $this->sendMessage(); return false; } elseif ($previous) { $this->forwardMessage(dgettext('signup', 'You cannot signup for more than one slot.'), dgettext('signup', 'Sorry')); $this->sendMessage(); return false; } if ($slot->openings <= $filled) { $this->message = dgettext('signup', 'Sorry, the slot you chose is no longer available.'); return false; } $peep->registered = 0; $peep->hashcheck = md5(rand()); $peep->timeout = time() + SIGNUP_WINDOW; if (PHPWS_Error::logIfError($peep->save())) { $db->unlockTables(); return false; } else { // success $db->unlockTables(); if (PHPWS_Error::logIfError($this->emailRegistration())) { $peep->delete(); $this->forwardMessage(dgettext('signup', 'There is a problem with our email server. Please try again later.'), dgettext('signup', 'Sorry')); $this->sendMessage(); return false; } else { return true; } } }