コード例 #1
0
ファイル: show.php プロジェクト: Alphenus/ilmomasiina-php
require_once "classes/SignupGadgets.php";
require_once "classes/Debugger.php";
require_once "classes/SignupGadget.php";
require_once "classes/CommonTools.php";
require_once "classes/SignupGadgetAnswerFormater.php";
/* Implementations of the most critical classes */
$configurations = new Configurations();
$page = new Page(1);
$debugger = new Debugger();
$database = new Database();
// Create gadget and get the data from database
$signupId = $request->getSignupId();
$sort = CommonTools::GET("sort");
$signupGadget = new SignupGadget($signupId);
$signupGadget->sortAnswers($sort);
$passwordFromUser = CommonTools::POST("password");
// Prints title and description
$page->addContent("<h1>" . $signupGadget->getTitle() . "</h1>");
$page->addContent("<i>" . $signupGadget->getDescription() . "</i>");
$password = $signupGadget->getPassword();
if ($passwordFromUser == null || $passwordFromUser != $password) {
    $page->addContent("<h3>Anna salasana</h3>");
    $page->addContent("<form method=\"post\" action=\"" . $configurations->webRoot . "showanswers/{$signupId}\">");
    $page->addContent("<p>Salasana:</p>");
    $page->addContent("<input type=\"password\" title=\"Kirjoita salasana\" name=\"password\" />");
    $page->addContent("<input type=\"submit\" value=\"OK\" /></form>");
} else {
    // Check the state of signup (open/close/not yet open)
    if ($signupGadget->isOpen()) {
        $page->addContent("<p class=\"signupOpen\">Ilmoittautuminen on auki</p>");
        $page->addContent(SignupGadgetAnswerFormater::getAnswersInPrintableFormat($signupGadget, true));
コード例 #2
0
ファイル: save.php プロジェクト: Alphenus/ilmomasiina-php
function parseNormalAnswer($question)
{
    global $userId;
    $answerFromPost = CommonTools::POST($question->getId());
    return new Answer($answerFromPost, $userId, $question);
}
コード例 #3
0
 /**
  * Creates a new signup gadget directly from POST variables from previous
  * page. If you are creating totally new signup gadget you must not change
  * the value of the id, but if you are going to edit previously existing
  * signup gadget you should set proper value to id parameter
  *
  * @param id ID of the signup gadget. If you are creating a totally new
  * signup gadget, ignore this parameter.
  */
 function createSignupGadgetFromPost($id = -1)
 {
     // Gets data from POST variables
     $question_num = CommonTools::POST('question_num');
     $title = CommonTools::POST('title');
     $description = CommonTools::POST('description');
     $event_day = CommonTools::POST('event_day');
     $event_month = CommonTools::POST('event_month');
     $event_year = CommonTools::POST('event_year');
     $event_hour = CommonTools::POST('event_hour');
     $event_minutes = CommonTools::POST('event_minutes');
     $opens_day = CommonTools::POST('opens_day');
     $opens_month = CommonTools::POST('opens_month');
     $opens_year = CommonTools::POST('opens_year');
     $opens_hour = CommonTools::POST('opens_hour');
     $opens_minutes = CommonTools::POST('opens_minutes');
     $closes_day = CommonTools::POST('closes_day');
     $closes_month = CommonTools::POST('closes_month');
     $closes_year = CommonTools::POST('closes_year');
     $closes_hour = CommonTools::POST('closes_hour');
     $closes_minutes = CommonTools::POST('closes_minutes');
     $send_confirmation = CommonTools::POST('send_confirmation');
     // Convert string value to boolean
     if ($send_confirmation == "true") {
         $send_confirmation = true;
     } else {
         $send_configuration = false;
     }
     $confirmation_message = CommonTools::POST('mailmessage');
     // Make timestamps
     $event_date = mktime($event_hour, $event_minutes, 0, $event_month, $event_day, $event_year);
     $opens = mktime($opens_hour, $opens_minutes, 0, $opens_month, $opens_day, $opens_year);
     $closes = mktime($closes_hour, $closes_minutes, 0, $closes_month, $closes_day, $closes_year);
     // Create signup gadget with or without id
     $signupGadget = null;
     if ($id < 0) {
         $signupGadget = new SignupGadget(-1, $title, $description, $event_date, $opens, $closes, $send_confirmation, $confirmation_message);
     } else {
         $signupGadget = new SignupGadget($id, $title, $description, $event_date, $opens, $closes, $send_confirmation, $confirmation_message);
     }
     /*
      * Then find the questions. The question count is known, and they are in
      * increasing order, but there might be removed numbers if user has
      * removed questions while filling the form (for example 1,2,5,7,9...)
      */
     // Is email-field already set
     $hasEmail = false;
     for ($i = 0, $questions_founded = 0; $questions_founded < $question_num; $i++) {
         // Is the question set?
         if (!isset($_POST["question_{$i}"])) {
             continue;
         } else {
             if ($_POST["question_{$i}"] == "") {
                 $questions_founded++;
                 continue;
             } else {
                 // Get the question
                 $questionId = CommonTools::POST("id_{$i}");
                 $question = CommonTools::POST("question_{$i}");
                 // Question
                 $type = CommonTools::POST("type_{$i}");
                 // Question type
                 $options_num = CommonTools::POST("optionsnum_{$i}");
                 // Count of options
                 $public = CommonTools::POST("public_{$i}");
                 // Is it public?
                 $required = CommonTools::POST("required_{$i}");
                 // Is it required?
                 $public = CommonTools::checkboxToBoolean($public);
                 $required = CommonTools::checkboxToBoolean($required);
                 if ($type == "email") {
                     if ($hasEmail) {
                         // Not more than one email is allowed
                         $debugger = CommonTools::getDebugger();
                         $debugger->error("Vain yksi sähköpostikenttä on sallittu");
                     } else {
                         // If confirmation mail is enabled, email is required
                         if ($send_confirmation) {
                             $required = true;
                         }
                         $hasEmail = true;
                     }
                 }
                 // Let's get the selected options of multiple choice questions
                 $options = array();
                 if ($options_num > 0 && $type != "text" && $type != "textarea" && $type != "email") {
                     for ($j = 0, $options_founded = 0; $options_founded < $options_num; $j++) {
                         // Option can be empty if user has removed options while
                         // filling the form
                         if (!isset($_POST["options_{$i}-{$j}"])) {
                             continue;
                         } else {
                             if ($_POST["options_{$i}-{$j}"] == "") {
                                 $options_founded++;
                                 continue;
                             } else {
                                 // Found an option!
                                 $option = CommonTools::POST("options_{$i}-{$j}");
                                 array_push($options, $option);
                                 $options_founded++;
                             }
                         }
                     }
                 }
                 // Options
                 // All information of the current question has been get, so
                 // let's put the question to signupGadget
                 if ($id >= 0 && $questionId >= 0) {
                     $questionObject = new Question($question, $type, $options, $public, $required, $id, $questionId);
                 } else {
                     if ($id >= 0) {
                         $questionObject = new Question($question, $type, $options, $public, $required, $id);
                     } else {
                         $questionObject = new Question($question, $type, $options, $public, $required);
                     }
                 }
                 $signupGadget->addQuestion($questionObject);
                 // Increase the question found variable
                 $questions_founded++;
             }
         }
     }
     // questions
     // If confirmation mail is enabled, email must be asked from the user
     if ($signupGadget->getSendConfirmationMail() && !$hasEmail) {
         $debugger = CommonTools::getDebugger();
         $debugger->error("Sähköpostikenttä pitää olla käytössä, jos haluat lähettää käyttäjälle vahvistusviestin");
     }
     return $signupGadget;
 }