예제 #1
0
 function User($newSignupid)
 {
     CommonTools::initializeCommonObjects($this);
     @session_start();
     // Throws notice if session started already
     $this->sessionId = session_id();
     $this->newSignupid = $newSignupid;
     $this->unconfirmedSignupExists = false;
     $this->selectSessionDataFromDatabase();
     // TODO Somehow I feel that this class has not been made at its best way
     // Maybe I should check that better later
     // Check if there is unconfirmed signups for this session and start
     // new session if not already started
     if ($this->getUnconfirmedSignupExists()) {
         if ($this->getOldSignupId() == $this->newSignupid) {
             // User hasn't confirm the current signup
             $this->unconfirmedSignupIsNotTheSameAsThis = false;
             $this->selectPositionFromDatabase();
         } else {
             // User hasn't confirm some other signup
             $this->unconfirmedSignupIsNotTheSameAsThis = true;
         }
     } else {
         if ($this->newSignupid >= 0) {
             // Not any old confirmed signups. This means also that the
             // session is new, because session handler newer generates two
             // same session id's (well, it may generate two identical id's
             // but that's very very rare)
             // FIXME SOMETHING FAILS HERE!
             $this->insertSessionDataToDatabase();
         }
     }
 }
예제 #2
0
 function UserAnswers($answers, $userId = -1, $position = -1)
 {
     CommonTools::initializeCommonObjects($this);
     $this->userId = $userId;
     $this->setAnswers($answers);
     $this->setPosition($position);
 }
예제 #3
0
 function Question($question, $type, $options, $public, $required, $signupId = -1, $id = -1)
 {
     CommonTools::initializeCommonObjects($this);
     // Check parameters
     if (!is_array($options)) {
         $this->debugger->error("Question constructor: Options parameter must be an array", "Question");
     }
     // Check parameters
     $allowed_types = array('text', 'textarea', 'radio', 'dropdown', 'checkbox', 'email');
     if (!in_array($type, $allowed_types)) {
         $this->debugger->error("Question constructor: Question has wrong type attribute", "Question");
     }
     if (!is_bool($public)) {
         $this->debugger->error("Question constructor: public must be boolean type", "Question");
     }
     if (!is_bool($required)) {
         $this->debugger->error("Question constructor: required must be boolean type", "Question");
     }
     $this->question = $question;
     $this->type = $type;
     $this->options = $options;
     $this->public = $public;
     $this->required = $required;
     $this->signupId = $signupId;
     $this->id = $id;
     $this->debugger->debug("Created new Question: Id: {$id} Question: {$question}, Type: {$type}, Public: {$public}, Required: {$required}", "Question");
     if (count($options) > 0) {
         $this->debugger->debugVar($options, "options", "Question");
     }
     // $this->debugger->error("Voi h**o");
 }
예제 #4
0
 function Email($address)
 {
     // Initializes the debugger
     CommonTools::initializeCommonObjects($this);
     if (!Email::isValidEmail($address)) {
         $this->debugger->error("The email address is invalid");
     } else {
         $this->address = $address;
     }
 }
예제 #5
0
 /**
  * Constructor for a signup gadget. If you are:
  * a) Creating a fresh new gadget, ID value should be a negative
  *    and other parameters should be set properly
  * b) Getting gadget data from database by ID, ID should be set properly
  *    and other parameters are unimportant (not set)
  * c) Creating a new gadget of which data you already know, all of the
  *    parameters should be set properly (this fits for editing gadget)
  *
  * The default value <!notset!> means that the title or description is not set.
  * This is a bit dump way to do this but I couldn't figure out any better.
  * First, the <!notset!> value was relpaced by null, but it did not work if
  * user had not set the description (and then the description was empty string).
  * PHP converts null value to empty string, so empty value and value which was
  * really null mixed up.
  */
 function SignupGadget($id = -1, $title = "<!notset!>", $description = "<!notset!>", $event_date = -1, $opens = -1, $closes = -1, $send_confirmation = false, $confirmation_message = "<!notset!>")
 {
     CommonTools::initializeCommonObjects($this);
     $this->debugger->debug("Trying to create a new signup gadget object " . "with parameters id: {$id}, title: {$title}, description: {$description}, " . "event_date: {$event_date}, opens: {$opens}, closes: {$closes}", "SignupGadget");
     // Situation a) - new gadget
     if ($id < 0 && $title != "<!notset!>" && $description != "<!notset!>" && $event_date >= 0 && $opens >= 0 && $closes >= 0 && $confirmation_message != "<!notset!>") {
         // Set field values
         $this->title = $title;
         $this->description = $description;
         $this->event_date = $event_date;
         $this->opens = $opens;
         $this->closes = $closes;
         $this->send_confirmation = $send_confirmation;
         $this->confirmation_message = $confirmation_message;
         // Create disposable password
         $password = CommonTools::generatePassword();
         $this->password = $password;
     } else {
         if ($id >= 0 && $title == "<!notset!>" && $description == "<!notset!>" && $event_date < 0 && $opens < 0 && $closes < 0 && $confirmation_message == "<!notset!>") {
             // Set id and the data from database
             $this->id = $id;
             $this->selectSignupGadgetById();
             $this->selectQuestionsFromDatabase();
             // Get answers if needed
             if ($this->isOpen() || $this->isClosed()) {
                 $this->selectAnswersFromDatabase();
             }
         } else {
             if ($id >= 0 && $title != "<!notset!>" && $description != "<!notset!>" && $event_date >= 0 && $opens >= 0 && $closes >= 0 && $confirmation_message != "<!notset!>") {
                 // Set field values
                 $this->id = $id;
                 $this->title = $title;
                 $this->description = $description;
                 $this->event_date = $event_date;
                 $this->opens = $opens;
                 $this->closes = $closes;
                 $this->send_confirmation = $send_confirmation;
                 $this->confirmation_message = $confirmation_message;
             } else {
                 $this->debugger->debug("Invalid parameters for SignupGadget. " . "You should respect one of the three situations which " . "are listed on a constructor function", "SignupGadget");
                 $this->debugger->error("Invalid parameters for SignupGadget", "SignupGadget");
             }
         }
     }
     $this->debugger->debug("Created new signup gadget with values: " . "{$id}, {$title}, {$description}, " . $this->getReadableEventdate() . ", " . $this->getReadableOpeningTime() . ", " . $this->getReadableClosingTime(), "SignupGadget");
     // Remove unconfirmed signups
     $this->removeUnconfirmedSignups();
 }
예제 #6
0
 function Answer($answer, $userId, $question)
 {
     CommonTools::initializeCommonObjects($this);
     // Check parameters
     if (!is_a($question, "Question")) {
         $this->debugger->error("Answer constructor: Question parameter must be object of class Question", "Answer");
     }
     if ($question->getType() == "checkbox") {
         if (!is_array($answer)) {
             $this->debugger->error("Answer constructor: If question is checkbox question answer parameter must be an array", "Answer");
         }
     }
     $this->question = $question;
     $this->signupId = $question->getSignupId();
     $this->userId = intval($userId);
     $this->answer = $answer;
 }
예제 #7
0
 /**
  * Luo uuden käyttäjälle lähetettävän vahvistusviestin
  * @param string message Viesti käyttäjälle
  * @param string email Käyttäjän email
  * @param SignupGadget signupgadget Tiedot ilmosta
  * @param array answers vastaukset masiinaan
  */
 public function ConfirmationMail($message, Email $email, $signupGadget, $answers = null)
 {
     CommonTools::initializeCommonObjects($this);
     $this->message = $message;
     $this->email = $email;
     $this->signupGadget = $signupGadget;
     $this->answers = $answers;
     if (!is_a($email, 'Email')) {
         $this->debugger->error("email parameter must be an instance of Email class");
     }
     // Tulostetaan ilmoittautumisen vahvistus vain jos käyttäjän id on annettu
     if ($answers != null) {
         $questions = $this->signupGadget->getAllQuestions();
         $this->message .= "\n\n*** Ilmoittautumisesi tiedot ***\n\n";
         foreach ($answers as $answer) {
             // Gets answer to question
             if (is_a($answer, "Answer")) {
                 $this->message .= $answer->getQuestion()->getQuestion() . ": " . $answer->getReadableAnswer() . "\n";
             } else {
                 // Tähän joku virhe?
             }
         }
     }
 }
예제 #8
0
 function SignupGadgets()
 {
     CommonTools::initializeCommonObjects($this);
     $this->signupGadgets = array();
 }