Example #1
0
function convertStringToDate($date, $separator = '-', $format = 'Y-m-d')
{
    $order = str_replace('-', '', $format);
    if (TRUE === isDateValid($date, $separator, $order)) {
        return DateTime::createFromFormat('Y-m-d', $date);
    }
    throw new \Exception("Cannot convert '{$date}' to a DateTime value.");
}
 public function handleInput($get, $post)
 {
     if (!empty($get)) {
         if (isset($get['ni'])) {
             if (($ni = (int) $get['ni']) < 1) {
                 throw new Exception("Neplatná hodnota parametru \"ni\": {$ni}");
             }
             $this->id = $ni;
         }
         if (isset($get['ng'])) {
             if (($ng = (int) $get['ng']) < 1) {
                 throw new Exception("Neplatná hodnota parametru \"ng\": {$ng}");
             }
             $this->ngid = $ng;
         }
         if (isset($get['error'])) {
             $this->error = true;
         }
     }
     if ($this->id == 0 && $this->ngid == 0) {
         throw new Exception("Minimálně jeden z parametrů \"ni\" a \"ng\" je povinný!");
     }
     if (!empty($post) && !$this->read_only) {
         switch ($post['cmd']) {
             case 'speichern':
                 $xpost = strip_gpc_slashes($post);
                 $this->name = $xpost['nazev'];
                 $this->author = $xpost['autor'];
                 $this->sample = $this->parseFckEditorInput($xpost['kni_ta1']);
                 $this->content = $this->parseFckEditorInput($xpost['kni_ta2']);
                 $this->when = $xpost['kdy'];
                 $this->start = $xpost['od'];
                 $this->end = $xpost['do'];
                 if ($this->name == '') {
                     $this->name = 'Unbenannt';
                     $this->error = true;
                 }
                 if (!isDateValid($this->when)) {
                     $this->when = date('j.n.Y');
                     $this->error = true;
                 }
                 if (!isDateValid($this->start)) {
                     $this->start = date('j.n.Y');
                     $this->error = true;
                 }
                 if (!isDateValid($this->end)) {
                     $this->end = date('j.n.Y');
                     $this->error = true;
                 }
                 $this->saveData();
                 if ($this->id) {
                     $qs1 = "&ni={$this->id}";
                 } elseif ($this->ngid) {
                     $qs1 = "&ng={$this->ngid}";
                 }
                 $qs2 = "?ng={$this->ngid}";
                 $this->redirection = $this->error ? KIWI_EDIT_NEWSITEM . "?error{$qs1}" : KIWI_NEWS . $qs2;
                 break;
             default:
                 throw new Exception('Neočekávaný příkaz formuláře: ' . __CLASS__);
         }
     }
 }
Example #3
0
                 if (strcmp($grid_step2_column_data["grid_step2_column" . $columnno . "_date_between_to_days_range"], "") == 0) {
                     $grid_step2_column_data["grid_step2_column" . $columnno . "_date_between_to_days_range"] = 0;
                 }
                 if (!is_numeric($grid_step2_column_data["grid_step2_column" . $columnno . "_date_between_to_days_range"])) {
                     addError("creategrid.date.between.range.invalidnumber");
                     $grid_step2_column_data["grid_step2_column" . $columnno . "_date_between_to_days_range"] = "";
                 }
             } else {
                 if (strcmp($grid_step2_column_data["grid_step2_column" . $columnno . "_date_to"], "customdate") == 0) {
                     $grid_step2_column_data["grid_step2_column" . $columnno . "_date_to_customvalue"] = isset($_POST['grid_step2_date_to_customvalue']) ? $_POST['grid_step2_date_to_customvalue'] : "";
                     $customvalue = true;
                     if (strcmp($grid_step2_column_data["grid_step2_column" . $columnno . "_date_to_customvalue"], "") == 0) {
                         $grid_step2_column_data["grid_step2_column" . $columnno . "_date_to_customvalue"] = "";
                         $customvalue = false;
                     }
                     if ($customvalue && !isDateValid($grid_step2_column_data["grid_step2_column" . $columnno . "_date_to_customvalue"])) {
                         $grid_step2_column_data["grid_step2_column" . $columnno . "_date_to_customvalue"] = "";
                         addError("creategrid.date.between.customvalue.invalid");
                     }
                 }
             }
         }
     }
 } else {
     if (strcmp($grid_step2_column_datatype, "autogen") == 0) {
         $grid_step2_column_data["grid_step2_column" . $columnno . "_autogen_prefix"] = isset($_POST['grid_step2_autogen_prefix']) ? $_POST['grid_step2_autogen_prefix'] : "";
         $grid_step2_column_data["grid_step2_column" . $columnno . "_autogen_suffix"] = isset($_POST['grid_step2_autogen_suffix']) ? $_POST['grid_step2_autogen_suffix'] : "";
         $grid_step2_column_data["grid_step2_column" . $columnno . "_autogen_content"] = isset($_POST['grid_step2_autogen_content']) ? $_POST['grid_step2_autogen_content'] : "";
         if (strcmp(trim($grid_step2_column_data["grid_step2_column" . $columnno . "_autogen_content"]), "") == 0) {
             addError("creategrid.autogen.content.missing");
         } else {