function formatConfirmedAnswerRow($answersByUser, $questions, $position, $adminMode)
 {
     $configurations = CommonTools::getConfigurations();
     $webRoot = $configurations->webRoot;
     $rowClass = SignupGadgetAnswerFormater::getRowClass();
     $return = "<tr class=\"{$rowClass}\">";
     $debugger = CommonTools::getDebugger();
     $debugger->debugVar($answersByUser, "answerByUser", "formatConfirmedAnswerRow");
     $return .= "<td class=\"answer-position\">" . $answersByUser->getPosition() . "</td>";
     $lastAnswer = null;
     // Could be any answer, not only last answer
     foreach ($questions as $question) {
         // Gets answer to questin
         $answerObject = $answersByUser->getAnswerToQuestion($question->getId());
         if ($answerObject == null) {
             // We get null-values when the signup machine gets more options added after users
             // have already submitted their answers. So in order not to truly mess up the
             // nice table we are creating, add an empty table cell.
             $return .= '<td class="answer"></td>';
         } else {
             if (is_a($answerObject, "Answer")) {
                 $return .= "<td class=\"answer\">" . $answerObject->getReadableAnswer() . "</td>";
                 $lastAnswer = $answerObject;
             } else {
                 // Joku virheilmotus tähänkö?
             }
         }
     }
     if ($adminMode && $lastAnswer != null) {
         $return .= "<td class=\"edit-answer\"><a href=\"" . $webRoot . "admin/editanswer/" . $lastAnswer->getSignupId() . "/?userid=" . $lastAnswer->getUserId() . "\">[muokkaa]</a></td>";
         $return .= "<td class=\"delete-answer\"><a href=\"" . $webRoot . "admin/deleteanswer/" . $lastAnswer->getSignupId() . "/?userid=" . $lastAnswer->getUserId() . "\">[poista]</a></td>";
     }
     $return .= "</tr>\n";
     return $return;
 }
 function formatConfirmedAnswerRow($answersByUser, $questions, $position, $adminMode)
 {
     $configurations = CommonTools::getConfigurations();
     $webRoot = $configurations->webRoot;
     $rowClass = SignupGadgetAnswerFormater::getRowClass();
     $return = "<tr class=\"{$rowClass}\">";
     $debugger = CommonTools::getDebugger();
     $debugger->debugVar($answersByUser, "answerByUser", "formatConfirmedAnswerRow");
     $return .= "<td class=\"answer-position\">" . $answersByUser->getPosition() . "</td>";
     $lastAnswer = null;
     // Could be any answer, not only last answer
     foreach ($questions as $question) {
         // Gets answer to questin
         $answerObject = $answersByUser->getAnswerToQuestion($question->getId());
         if (is_a($answerObject, "Answer")) {
             $return .= "<td class=\"answer\">" . $answerObject->getReadableAnswer() . "</td>";
             $lastAnswer = $answerObject;
         } else {
             // Joku virheilmotus tähänkö?
         }
     }
     if ($adminMode && $lastAnswer != null) {
         $return .= "<td class=\"edit-answer\"><a href=\"" . $webRoot . "admin/editanswer/" . $lastAnswer->getSignupId() . "/?userid=" . $lastAnswer->getUserId() . "\">[muokkaa]</a></td>";
         $return .= "<td class=\"delete-answer\"><a href=\"" . $webRoot . "admin/deleteanswer/" . $lastAnswer->getSignupId() . "/?userid=" . $lastAnswer->getUserId() . "\">[poista]</a></td>";
     }
     $return .= "</tr>\n";
     return $return;
 }
 function formatQuestionCheckbox($question, $value)
 {
     $return = "";
     $return .= "<div class=\"question-container\">";
     $return .= "<p class=\"question-label\"><span>" . $question->getQuestion() . "</span>";
     if ($question->getRequired()) {
         $return .= " <span class=\"required\">*</span>";
     }
     $return .= "</p>";
     $i = 0;
     foreach ($question->getOptions() as $option) {
         $selected = "";
         $debugger = CommonTools::getDebugger();
         // $debugger->debug("Option: $option, inArray: " . in_array($option, $value), "questionCheckbox");
         $debugger->debugVar($value, "value", "checkBox");
         if (is_array($value) && in_array($option, $value)) {
             $selected = "checked=\"checked\"";
         }
         $option = htmlentities($option);
         $return .= "<p class=\"question-checkbox-label\"><input class=\"question-checkbox\" type=\"checkbox\" name=\"" . $question->getId() . "-{$i}\" size=\"30\" value=\"{$option}\" {$selected} />{$option}</p>";
         $i++;
     }
     $return .= "</div>";
     return $return;
 }
예제 #4
0
 function arrayToReadableFormat($array)
 {
     $arrayString = "";
     $atLeastOneValueSet = false;
     foreach ($array as $id) {
         if ($id >= 0) {
             $arrayString .= "{$id}, ";
             $atLeastOneValueSet = true;
         } else {
             $debugger = CommonTools::getDebugger();
             $debugger->error("The array must include only positive integer values", "idArrayToSql");
         }
     }
     if ($atLeastOneValueSet) {
         // Remove last comma
         $arrayString = substr($arrayString, 0, -2);
     }
     return $arrayString;
 }
 function formatDateTimeSelect($namePrefix, $title, $value = -1)
 {
     $day = -1;
     $month = -1;
     $year = -1;
     $hour = -1;
     $minutes = -1;
     if ($value > 0) {
         $date = getdate($value);
         $day = $date["mday"];
         $month = $date["mon"];
         $year = $date["year"];
         $hour = $date["hours"];
         $minutes = $date["minutes"];
     }
     $debugger = CommonTools::getDebugger();
     $debugger->debug("Day {$day}, Month {$month}, Year {$year}, Hour {$hour}, Minutes {$minutes}", "formatDateTimeSelect");
     $return = "";
     $return .= "<div class=\"date-select-container\">";
     $return .= "<p class=\"date-select-title\">{$title}</p>\n";
     $return .= "<select name=\"" . $namePrefix . "day\">\n";
     $return .= SignupGadgetEditFormater::getDayOptions($day);
     $return .= "</select>\n";
     $return .= "<select name=\"" . $namePrefix . "month\">\n";
     $return .= SignupGadgetEditFormater::getMonthOptions($month);
     $return .= "</select>\n";
     $return .= "<select name=\"" . $namePrefix . "year\">\n";
     $return .= SignupGadgetEditFormater::getYearOptions($year);
     $return .= "</select>\n";
     $return .= "<span>klo: </span>\n";
     $return .= "<select name=\"" . $namePrefix . "hour\">\n";
     $return .= SignupGadgetEditFormater::getHourOptions($hour);
     $return .= "</select>\n";
     $return .= "<select name=\"" . $namePrefix . "minutes\">\n";
     $return .= SignupGadgetEditFormater::getMinuteOptions(5, $minutes);
     $return .= "</select>\n\n";
     $return .= "</div>";
     return $return;
 }
예제 #6
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;
 }