/**
  * 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();
 }