Projekt

Obecné

Profil

« Předchozí | Další » 

Revize 8ef8fa46

Přidáno uživatelem Tomáš Pašek před téměř 4 roky(ů)

oprava insertu

Zobrazit rozdíly:

application/model/DB.php
542 542
         if (array_key_exists("context", $_POST) && $_POST['context'] != "") {
543 543
                $query .= " context, ";
544 544
                $values .= " :context, ";
545
            }
545
         }
546 546
                $query .= " date, ";
547 547
                $values .=  " CURRENT_DATE, ";
548 548

  
......
657 657

  
658 658
    // ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||| Tabulka dd_manuscript |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
659 659

  
660
        if (array_key_exists("wordform_id", $_POST) && $_POST['wordform_id'] != "") {
661
            $query = "SELECT * FROM dd_manuscript WHERE ";
662
            $query .= " wordform_id = :wordform_id ;";
663

  
664
            $this->stmt = $this->pdo->prepare($query);
665
                if (array_key_exists("wordform_id", $_POST) && $_POST['wordform_id'] != "") {
666
                    $this->stmt->bindParam(':wordform_id', $_POST['wordform_id'], PDO::PARAM_INT);
667
                }
668
                $this->stmt->execute();
669
                $result = $this->stmt->fetchAll();
670

  
671
                $to_insert = [];
672
                $contained = [];
673
                $found = false;
674
                $integerIDs = [];
675

  
676
                foreach ($result as $res) {
677
                    $integerIDs = array_map('intval', explode(',', $_POST['manuscript']));
678
                    foreach ($integerIDs as $new_value){
679
                        if($new_value == $res['manuscript']){
680
                            $found = true;
681
                            array_push($contained, $new_value);
682
                        }
683
                    }
684
                    if($found == false){
685
                        array_push($to_delete, $res);
686
                    }
687
                    $found = false;
688
                }
689
                $to_insert = array_diff($integerIDs, $contained);
660
                $to_insert = array_map('intval', explode(',', $_POST['manuscript']));
690 661
                foreach ($to_insert as $id_to_insert){
691 662
                    $query = "INSERT INTO dd_manuscript VALUES ( ";
692 663
                    $query .= " :wordform_id , ";
693 664
                    $query .= " " . $id_to_insert . " ); ";
694 665

  
695 666
                    $this->stmt = $this->pdo->prepare($query);
696
                    if (array_key_exists("wordform_id", $_POST) && $_POST['wordform_id'] != "") {
697
                        $this->stmt->bindParam(':wordform_id', $_POST['wordform_id'], PDO::PARAM_INT);
698
                    }
667
                    $this->stmt->bindParam(':wordform_id', $result[0]["max"], PDO::PARAM_INT);
699 668
                    $this->stmt->execute();
700 669
                }
701 670
        }
702 671

  
703 672

  
704
    }
705

  
706 673
    function remove(){
707 674
        // ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||| Tabulka dd_manuscript |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
708 675
        if (array_key_exists("id", $_POST) && $_POST['id'] != "") {

Také k dispozici: Unified diff