예제 #1
0
/**
 * Affiche le whois d'un domaine
 * @param string $domain
 * @return mixed 
 */
function whois_domain($domain)
{
    if (!is_string($domain) || !preg_match('`^[a-z]{1,}([-\\.][a-z]+)+$`i', $domain)) {
        return false;
        // not a valid domain ?
    }
    function query_server($domain, $server = 'whois.iana.org')
    {
        $response = '';
        if ($fsk = fsockopen($server, 43, $errno, $errstr, 2)) {
            fputs($fsk, $domain . "\r\n");
            // CRLF as per RFC3912
            while (!feof($fsk)) {
                $response .= fgets($fsk, 1024);
            }
            @fclose($fsk);
        }
        if (preg_match('`^[\\s]*whois[\\s]*(?:server[\\s]*)?:[\\s]*([-a-z\\.]+)[\\s]*$`mi', $response, $m)) {
            $server = $m[1];
            return $server;
        } else {
            return $response;
        }
    }
    $response_or_next_server = 'whois.iana.org';
    $i = 5;
    // max 5 queries for avoid loop
    while (preg_match('`^[-a-z\\.]+$`', $response_or_next_server)) {
        if (!$i--) {
            return null;
        }
        $response_or_next_server = query_server($domain, $response_or_next_server);
    }
    return $response_or_next_server;
}
예제 #2
0
function query_dvd($mysqli, $xml, &$Hash, &$rsDVDVMGM)
{
    $dvdTag = $xml->DVD[0];
    $attributes = $dvdTag->attributes();
    $Hash = $attributes["Hash"];
    $strSQL = "SELECT " . QUERY_SET . " FROM DVDVMGM " . "WHERE Hash = '" . $Hash . "' AND Active = 1 " . "ORDER BY Revision DESC;";
    $rsDVDVMGM = query_server($mysqli, $strSQL);
}
예제 #3
0
function getPrimaryKey($mysqli, $table, $field, $where)
{
    $strSQL = "SELECT `{$field}` FROM `{$table}` WHERE {$where};";
    $rs = query_server($mysqli, $strSQL);
    if (!is_array($Cols = $rs->fetch_row())) {
        return -1;
    }
    return $Cols[0];
}
예제 #4
0
function submit($mysqli, $xml, $XmlVersion)
{
    /*
        query_server($mysqli, "TRUNCATE TABLE `DVDAUDIOSTREAM`;");
        query_server($mysqli, "TRUNCATE TABLE `DVDAUDIOSTREAMEX`;");
        query_server($mysqli, "TRUNCATE TABLE `DVDSUBPICSTREAM`;");
        query_server($mysqli, "TRUNCATE TABLE `DVDVIDEOSTREAM`;");
        query_server($mysqli, "TRUNCATE TABLE `DVDFILE`;");
        query_server($mysqli, "TRUNCATE TABLE `DVDPTTVMG`;");
        query_server($mysqli, "TRUNCATE TABLE `DVDPTTVTS`;");
        query_server($mysqli, "TRUNCATE TABLE `DVDUNIT`;");
        query_server($mysqli, "TRUNCATE TABLE `DVDCELL`;");
        query_server($mysqli, "TRUNCATE TABLE `DVDPROGRAM`;");
        query_server($mysqli, "TRUNCATE TABLE `DVDPGC`;");
        query_server($mysqli, "TRUNCATE TABLE `DVDVTS`;");
        query_server($mysqli, "TRUNCATE TABLE `DVDVMGM`;");
    */
    // Start a transaction
    query_server($mysqli, "START TRANSACTION;");
    foreach ($xml->DVD as $tagDVDVMGM) {
        $attributes = $tagDVDVMGM->attributes();
        $Hash = value_or_null($attributes["Hash"]);
        $SubmitterIP = value_or_null($_SERVER['REMOTE_ADDR']);
        $Album = value_or_null($tagDVDVMGM->Album);
        $OriginalAlbum = value_or_null($tagDVDVMGM->OriginalAlbum);
        $AlbumArtist = value_or_null($tagDVDVMGM->AlbumArtist);
        $Genre = value_or_null($tagDVDVMGM->Genre);
        $Cast = value_or_null($tagDVDVMGM->Cast);
        $Crew = value_or_null($tagDVDVMGM->Crew);
        $Director = value_or_null($tagDVDVMGM->Director);
        $Screenplay = value_or_null($tagDVDVMGM->Screenplay);
        $Producer = value_or_null($tagDVDVMGM->Producer);
        $Editing = value_or_null($tagDVDVMGM->Editing);
        $Cinematography = value_or_null($tagDVDVMGM->Cinematography);
        $Country = value_or_null($tagDVDVMGM->Country);
        $OriginalLanguage = value_or_null($tagDVDVMGM->OriginalLanguage);
        $ReleaseDate = date_or_null($tagDVDVMGM->ReleaseDate);
        $SpecialFeatures = value_or_null($tagDVDVMGM->SpecialFeatures);
        $EAN_UPC = value_or_null($tagDVDVMGM->EAN_UPC);
        $Storyline = value_or_null($tagDVDVMGM->Storyline);
        $Submitter = value_or_null($tagDVDVMGM->Submitter);
        $Client = value_or_null($tagDVDVMGM->Client);
        $Remarks = value_or_null($tagDVDVMGM->Remarks);
        $Keywords = value_or_null($tagDVDVMGM->Keywords);
        $RegionProhibited1 = value_or_null($attributes["RegionProhibited1"]);
        $RegionProhibited2 = value_or_null($attributes["RegionProhibited2"]);
        $RegionProhibited3 = value_or_null($attributes["RegionProhibited3"]);
        $RegionProhibited4 = value_or_null($attributes["RegionProhibited4"]);
        $RegionProhibited5 = value_or_null($attributes["RegionProhibited5"]);
        $RegionProhibited6 = value_or_null($attributes["RegionProhibited6"]);
        $RegionProhibited7 = value_or_null($attributes["RegionProhibited7"]);
        $RegionProhibited8 = value_or_null($attributes["RegionProhibited8"]);
        $VersionNumberMajor = value_or_null($attributes["VersionNumberMajor"]);
        $VersionNumberMinor = value_or_null($attributes["VersionNumberMinor"]);
        $NumberOfVolumes = value_or_null($attributes["NumberOfVolumes"]);
        $VolumeNumber = value_or_null($attributes["VolumeNumber"]);
        $SideID = value_or_null($attributes["SideID"]);
        if ($Submitter == DEFSUBMITTER) {
            $Submitter = null;
        }
        // Check if dataset exists
        $found = FALSE;
        /* Feature #884: deactivated unstable feature for rev 0.40
        
                $strSQL = "SELECT `idDVDVMGM`, `RowLastChanged`, `RowCreationDate`, `Submitter`, `SubmitterIP` FROM `DVDVMGM` ".
                            "WHERE `Hash` = '" . $Hash . "' AND `Active` = 1 " .
                            "ORDER BY `Revision` DESC;";
        
                $rsDVDVMGM = query_server($mysqli, $strSQL);
        
                if (is_array($Cols = $rsDVDVMGM->fetch_row()))
                {
                    $idDVDVMGM          = $Cols[0];
                    $RowLastChanged     = $Cols[1];
                    $RowCreationDate    = $Cols[2];
                    $LastSubmitter      = $Cols[3];
                    $LastSubmitterIP    = $Cols[4];
        
                    // TODO: maybe check submission time
                    if ($Submitter == $LastSubmitter && $SubmitterIP == $LastSubmitterIP)
                    {
                        $found = TRUE;
                    }
                }
        
                $rsDVDVMGM->close();
        */
        if (!$found) {
            // Not found: insert new
            $strSQL = "INSERT INTO `DVDVMGM` (`Hash`, `Album`, `AlbumArtist`, `Genre`, `Cast`, `Crew`, `Director`, `Country`, `ReleaseDate`, `SpecialFeatures`, `EAN_UPC`, `Storyline`, `Remarks`, `Submitter`, `SubmitterIP`, `Client`, `Keywords`, `RegionProhibited1`, `RegionProhibited2`, `RegionProhibited3`, `RegionProhibited4`, `RegionProhibited5`, `RegionProhibited6`, `RegionProhibited7`, `RegionProhibited8`, `VersionNumberMajor`, `VersionNumberMinor`, `NumberOfVolumes`, `VolumeNumber`, `SideID`, `OriginalAlbum`, `Screenplay`, `Producer`, `Editing`, `Cinematography`, `OriginalLanguage`) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?);";
            $stmt = $mysqli->prepare($strSQL);
            if (!$stmt) {
                $ResponseText = "Error preparing insert statement for DVDVMGM table.\nSQL Error: " . $mysqli->error . "\nSQL State: " . $mysqli->sqlstate;
                throw new Exception($ResponseText, XMLRESULT_SQL_ERROR);
            }
            if (!$stmt->bind_param("sssssssssssssssssiiiiiiiiiiiiissssss", $Hash, $Album, $AlbumArtist, $Genre, $Cast, $Crew, $Director, $Country, $ReleaseDate, $SpecialFeatures, $EAN_UPC, $Storyline, $Remarks, $Submitter, $SubmitterIP, $Client, $Keywords, $RegionProhibited1, $RegionProhibited2, $RegionProhibited3, $RegionProhibited4, $RegionProhibited5, $RegionProhibited6, $RegionProhibited7, $RegionProhibited8, $VersionNumberMajor, $VersionNumberMinor, $NumberOfVolumes, $VolumeNumber, $SideID, $OriginalAlbum, $Screenplay, $Producer, $Editing, $Cinematography, $OriginalLanguage)) {
                $ResponseText = "Error binding parameters for DVDVMGM table.\nSQL Error: " . $mysqli->error . "\nSQL State: " . $mysqli->sqlstate;
                $stmt->close();
                $stmt = null;
                throw new Exception($ResponseText, XMLRESULT_SQL_ERROR);
            }
            if (!$stmt->execute()) {
                $ResponseText = "Error executing statement on DVDVMGM table.\nSQL Error: " . $mysqli->error . "\nSQL State: " . $mysqli->sqlstate;
                $stmt->close();
                $stmt = null;
                throw new Exception($ResponseText, XMLRESULT_SQL_ERROR);
            }
            $idDVDVMGM = $mysqli->insert_id;
            $stmt->close();
            $stmt = null;
            // Physical structure
            $tagPhysical = $tagDVDVMGM->physical;
            foreach ($tagPhysical->DVDVTS as $tagDVDVTS) {
                // Insert DVDVTS (Video Title Set)
                $attributes = $tagDVDVTS->attributes();
                $TitleSetNo = $attributes["TitleSetNo"];
                $VersionNumberMajor = value_or_null($attributes["VersionNumberMajor"]);
                $VersionNumberMinor = value_or_null($attributes["VersionNumberMinor"]);
                $strSQL = "INSERT INTO `DVDVTS` (`DVDVMGMKey`, `TitleSetNo`, `VersionNumberMajor`, `VersionNumberMinor`) VALUES (?, ?, ?, ?);";
                $stmt = $mysqli->prepare($strSQL);
                if (!$stmt) {
                    $ResponseText = "Error preparing insert statement for DVDVTS table.\nSQL Error: " . $mysqli->error . "\nSQL State: " . $mysqli->sqlstate;
                    throw new Exception($ResponseText, XMLRESULT_SQL_ERROR);
                }
                if (!$stmt->bind_param("iiii", $idDVDVMGM, $TitleSetNo, $VersionNumberMajor, $VersionNumberMinor)) {
                    $ResponseText = "Error binding parameters for DVDVTS table.\nSQL Error: " . $mysqli->error . "\nSQL State: " . $mysqli->sqlstate;
                    $stmt->close();
                    throw new Exception($ResponseText, XMLRESULT_SQL_ERROR);
                }
                if (!$stmt->execute()) {
                    $ResponseText = "Error executing statement on DVDVTS table.\nSQL Error: " . $mysqli->error . "\nSQL State: " . $mysqli->sqlstate;
                    $stmt->close();
                    throw new Exception($ResponseText, XMLRESULT_SQL_ERROR);
                }
                $idDVDVTS = $mysqli->insert_id;
                $stmt->close();
                foreach ($tagDVDVTS->DVDPGC as $tagDVDPGC) {
                    // Insert DVDPGC (Program Chain)
                    $attributes = $tagDVDPGC->attributes();
                    $ProgramChainNo = value_or_null($attributes["Number"]);
                    $EntryPGC = value_or_null($attributes["EntryPGC"]);
                    $strSQL = "INSERT INTO `DVDPGC` (`DVDVTSKey`, `ProgramChainNo`, `EntryPGC`) VALUES (?, ?, ?);";
                    $stmt = $mysqli->prepare($strSQL);
                    if (!$stmt) {
                        $ResponseText = "Error preparing insert statement for DVDPGC table.\nSQL Error: " . $mysqli->error . "\nSQL State: " . $mysqli->sqlstate;
                        throw new Exception($ResponseText, XMLRESULT_SQL_ERROR);
                    }
                    if (!$stmt->bind_param("iii", $idDVDVTS, $ProgramChainNo, $EntryPGC)) {
                        $ResponseText = "Error binding parameters for DVDPGC table.\nSQL Error: " . $mysqli->error . "\nSQL State: " . $mysqli->sqlstate;
                        $stmt->close();
                        throw new Exception($ResponseText, XMLRESULT_SQL_ERROR);
                    }
                    if (!$stmt->execute()) {
                        $ResponseText = "Error executing statement on DVDPGC table.\nSQL Error: " . $mysqli->error . "\nSQL State: " . $mysqli->sqlstate;
                        $stmt->close();
                        throw new Exception($ResponseText, XMLRESULT_SQL_ERROR);
                    }
                    $idDVDPGC = $mysqli->insert_id;
                    $stmt->close();
                    foreach ($tagDVDPGC->DVDPROGRAM as $tagDVDPROGRAM) {
                        // Insert DVDPGC (Program)
                        $attributes = $tagDVDPROGRAM->attributes();
                        $ProgramNo = value_or_null($attributes["Number"]);
                        $strSQL = "INSERT INTO `DVDPROGRAM` (`DVDPGCKey`, `ProgramNo`) VALUES (?, ?);";
                        $stmt = $mysqli->prepare($strSQL);
                        if (!$stmt) {
                            $ResponseText = "Error preparing insert statement for chapter table.\nSQL Error: " . $mysqli->error . "\nSQL State: " . $mysqli->sqlstate;
                            throw new Exception($ResponseText, XMLRESULT_SQL_ERROR);
                        }
                        if (!$stmt->bind_param("ii", $idDVDPGC, $ProgramNo)) {
                            $ResponseText = "Error binding parameters for chapter table.\nSQL Error: " . $mysqli->error . "\nSQL State: " . $mysqli->sqlstate;
                            $stmt->close();
                            throw new Exception($ResponseText, XMLRESULT_SQL_ERROR);
                        }
                        if (!$stmt->execute()) {
                            $ResponseText = "Error executing statement on chapter table.\nSQL Error: " . $mysqli->error . "\nSQL State: " . $mysqli->sqlstate;
                            $stmt->close();
                            throw new Exception($ResponseText, XMLRESULT_SQL_ERROR);
                        }
                        $idDVDPROGRAM = $mysqli->insert_id;
                        $stmt->close();
                        foreach ($tagDVDPROGRAM->DVDCELL as $tagDVDCELL) {
                            // Insert DVDCELL (Cell)
                            $attributes = $tagDVDCELL->attributes();
                            $CellNo = value_or_null($attributes["Number"]);
                            $CellType = value_or_null($attributes["CellType"]);
                            $BlockType = value_or_null($attributes["BlockType"]);
                            $SeamlessMultiplex = value_or_null($attributes["SeamlessMultiplex"]);
                            $Interleaved = value_or_null($attributes["Interleaved"]);
                            $SCRdiscontinuity = value_or_null($attributes["SCRdiscontinuity"]);
                            $SeamlessAngleLinkedInDSI = value_or_null($attributes["SeamlessAngleLinkedInDSI"]);
                            $VOBStillMode = value_or_null($attributes["VOBStillMode"]);
                            $StopsTrickPlay = value_or_null($attributes["StopsTrickPlay"]);
                            $CellStillTime = value_or_null($attributes["CellStillTime"]);
                            $CellCommand = value_or_null($attributes["CellCommand"]);
                            $PlayTime = value_or_null($attributes["PlayTime"]);
                            $FrameRate = value_or_null($attributes["FrameRate"]);
                            $FirstVOBUStartSector = value_or_null($attributes["FirstVOBUStartSector"]);
                            $FirstILVUEndSector = value_or_null($attributes["FirstILVUEndSector"]);
                            $LastVOBUStartSector = value_or_null($attributes["LastVOBUStartSector"]);
                            $LastVOBUEndSector = value_or_null($attributes["LastVOBUEndSector"]);
                            $VOBidn = value_or_null($attributes["VOBidn"]);
                            $CELLidn = value_or_null($attributes["CELLidn"]);
                            $NumberOfVOBIds = value_or_null($attributes["NumberOfVOBIds"]);
                            $strSQL = "INSERT INTO `DVDCELL` (`DVDPROGRAMKey`, `CellNo`, `CellType`, `BlockType`, `SeamlessMultiplex`, `Interleaved`, `SCRdiscontinuity`, `SeamlessAngleLinkedInDSI`, `VOBStillMode`, `StopsTrickPlay`, `CellStillTime`, `CellCommand`, `PlayTime`, `FrameRate`, `FirstVOBUStartSector`, `FirstILVUEndSector`, `LastVOBUStartSector`, `LastVOBUEndSector`, `VOBidn`, `CELLidn`, `NumberOfVOBIds`) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?);";
                            $stmt = $mysqli->prepare($strSQL);
                            if (!$stmt) {
                                $ResponseText = "Error preparing insert statement for DVDCELL table.\nSQL Error: " . $mysqli->error . "\nSQL State: " . $mysqli->sqlstate;
                                throw new Exception($ResponseText, XMLRESULT_SQL_ERROR);
                            }
                            if (!$stmt->bind_param("iissiiiiiiiiiiiiiiiii", $idDVDPROGRAM, $CellNo, $CellType, $BlockType, $SeamlessMultiplex, $Interleaved, $SCRdiscontinuity, $SeamlessAngleLinkedInDSI, $VOBStillMode, $StopsTrickPlay, $CellStillTime, $CellCommand, $PlayTime, $FrameRate, $FirstVOBUStartSector, $FirstILVUEndSector, $LastVOBUStartSector, $LastVOBUEndSector, $VOBidn, $CELLidn, $NumberOfVOBIds)) {
                                $ResponseText = "Error binding parameters for DVDCELL table.\nSQL Error: " . $mysqli->error . "\nSQL State: " . $mysqli->sqlstate;
                                $stmt->close();
                                throw new Exception($ResponseText, XMLRESULT_SQL_ERROR);
                            }
                            if (!$stmt->execute()) {
                                $ResponseText = "Error executing statement on DVDCELL table.\nSQL Error: " . $mysqli->error . "\nSQL State: " . $mysqli->sqlstate;
                                $stmt->close();
                                throw new Exception($ResponseText, XMLRESULT_SQL_ERROR);
                            }
                            $idDVDCELL = $mysqli->insert_id;
                            $stmt->close();
                            foreach ($tagDVDCELL->DVDUNIT as $tagDVDUNIT) {
                                // Insert DVDUNIT (Unit)
                                $attributes = $tagDVDUNIT->attributes();
                                $UnitNo = value_or_null($attributes["Number"]);
                                $StartSector = value_or_null($attributes["StartSector"]);
                                $EndSector = value_or_null($attributes["EndSector"]);
                                $strSQL = "INSERT INTO `DVDUNIT` (`DVDCELLKey`, `UnitNo`, `StartSector`, `EndSector`) VALUES (?, ?, ?, ?);";
                                $stmt = $mysqli->prepare($strSQL);
                                if (!$stmt) {
                                    $ResponseText = "Error preparing insert statement for DVDUNIT table.\nSQL Error: " . $mysqli->error . "\nSQL State: " . $mysqli->sqlstate;
                                    throw new Exception($ResponseText, XMLRESULT_SQL_ERROR);
                                }
                                if (!$stmt->bind_param("iiii", $idDVDCELL, $UnitNo, $StartSector, $EndSector)) {
                                    $ResponseText = "Error binding parameters for DVDUNIT table.\nSQL Error: " . $mysqli->error . "\nSQL State: " . $mysqli->sqlstate;
                                    $stmt->close();
                                    throw new Exception($ResponseText, XMLRESULT_SQL_ERROR);
                                }
                                if (!$stmt->execute()) {
                                    $ResponseText = "Error executing statement on DVDUNIT table.\nSQL Error: " . $mysqli->error . "\nSQL State: " . $mysqli->sqlstate;
                                    $stmt->close();
                                    throw new Exception($ResponseText, XMLRESULT_SQL_ERROR);
                                }
                                //$idDVDUNIT = $mysqli->insert_id;
                                $stmt->close();
                            }
                        }
                    }
                }
                // DVDVIDEOSTREAM
                foreach ($tagDVDVTS->DVDVIDEOSTREAM as $tagDVDVIDEOSTREAM) {
                    addVideoStream($mysqli, $tagDVDVIDEOSTREAM, null, $idDVDVTS);
                }
                // DVDAUDIOSTREAM
                foreach ($tagDVDVTS->DVDAUDIOSTREAM as $tagDVDAUDIOSTREAM) {
                    addAudioStream($mysqli, $tagDVDAUDIOSTREAM, null, $idDVDVTS);
                }
                // DVDAUDIOSTREAMEX
                foreach ($tagDVDVTS->DVDAUDIOSTREAMEX as $audiostreamExTag) {
                    addAudioStreamEx($mysqli, $audiostreamExTag, $idDVDVTS);
                }
                // DVDSUBPICSTREAM
                foreach ($tagDVDVTS->DVDSUBPICSTREAM as $tagDVDSUBPICSTREAM) {
                    addSubpictureStream($mysqli, $tagDVDSUBPICSTREAM, null, $idDVDVTS);
                }
                // Fileset
                foreach ($tagDVDVTS->DVDFILE as $tagDVDFILE) {
                    addFileset($mysqli, $tagDVDFILE, null, $idDVDVTS);
                }
            }
            // Virtual structure
            $tagVirtual = $tagDVDVMGM->virtual;
            foreach ($tagVirtual->DVDPTTVMG as $tagDVDPTTVMG) {
                // Insert DVDPTTVMG (Video Title Set)
                $attributes = $tagDVDPTTVMG->attributes();
                $Title = value_or_null($tagDVDPTTVMG->Title);
                $TitleSetNo = value_or_null($attributes["TitleSetNo"]);
                $PlaybackType = value_or_null($attributes["PlaybackType"]);
                $NumberOfVideoAngles = value_or_null($attributes["NumberOfVideoAngles"]);
                $ParentalMgmMaskVMG = value_or_null($attributes["ParentalMgmMaskVMG"]);
                $ParentalMgmMaskVTS = value_or_null($attributes["ParentalMgmMaskVTS"]);
                $NumberOfVideoAngles = value_or_null($attributes["NumberOfVideoAngles"]);
                $VideoTitleSetNo = value_or_null($attributes["VideoTitleSetNo"]);
                $TitleNo = value_or_null($attributes["TitleNo"]);
                $strSQL = "INSERT INTO `DVDPTTVMG` (`DVDVMGMKey`, `TitleSetNo`, `Title`, `PlaybackType`, `NumberOfVideoAngles`, `ParentalMgmMaskVMG`, `ParentalMgmMaskVTS`, `VideoTitleSetNo`, `TitleNo`) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?);";
                $stmt = $mysqli->prepare($strSQL);
                if (!$stmt) {
                    $ResponseText = "Error preparing insert statement for DVDPTTVMG table.\nSQL Error: " . $mysqli->error . "\nSQL State: " . $mysqli->sqlstate;
                    throw new Exception($ResponseText, XMLRESULT_SQL_ERROR);
                }
                if (!$stmt->bind_param("iisiiiiii", $idDVDVMGM, $TitleSetNo, $Title, $PlaybackType, $NumberOfVideoAngles, $ParentalMgmMaskVMG, $ParentalMgmMaskVTS, $VideoTitleSetNo, $TitleNo)) {
                    $ResponseText = "Error binding parameters for DVDPTTVMG table.\nSQL Error: " . $mysqli->error . "\nSQL State: " . $mysqli->sqlstate;
                    $stmt->close();
                    throw new Exception($ResponseText, XMLRESULT_SQL_ERROR);
                }
                if (!$stmt->execute()) {
                    $ResponseText = "Error executing statement on DVDPTTVMG table.\nSQL Error: " . $mysqli->error . "\nSQL State: " . $mysqli->sqlstate;
                    $stmt->close();
                    throw new Exception($ResponseText, XMLRESULT_SQL_ERROR);
                }
                $idDVDPTTVMG = $mysqli->insert_id;
                $stmt->close();
                foreach ($tagDVDPTTVMG->DVDPTTVTS as $tagDVDPTTVTS) {
                    // Insert DVDPTTVTS (Chapter)
                    $attributes = $tagDVDPTTVTS->attributes();
                    $Title = value_or_null($tagDVDPTTVTS->Title);
                    $Artist = value_or_null($tagDVDPTTVTS->Artist);
                    $ProgramChainNo = value_or_null($attributes["ProgramChainNo"]);
                    $ProgramNo = value_or_null($attributes["ProgramNo"]);
                    $PttTitleSetNo = value_or_null($attributes["PttTitleSetNo"]);
                    $PttChapterNo = value_or_null($attributes["Number"]);
                    $TitleSetNo = value_or_null($attributes["TitleSetNo"]);
                    $strSQL = "INSERT INTO `DVDPTTVTS` (`DVDPTTVMGKey`, `Artist`, `Title`, `ProgramChainNo`, `ProgramNo`, `PttTitleSetNo`, `PttChapterNo`, `TitleSetNo`) VALUES (?, ?, ?, ?, ?, ?, ?, ?);";
                    $stmt = $mysqli->prepare($strSQL);
                    if (!$stmt) {
                        $ResponseText = "Error preparing insert statement for DVDPTTVTS table.\nSQL Error: " . $mysqli->error . "\nSQL State: " . $mysqli->sqlstate;
                        throw new Exception($ResponseText, XMLRESULT_SQL_ERROR);
                    }
                    if (!$stmt->bind_param("issiiiii", $idDVDPTTVMG, $Artist, $Title, $ProgramChainNo, $ProgramNo, $PttTitleSetNo, $PttChapterNo, $TitleSetNo)) {
                        $ResponseText = "Error binding parameters for DVDPTTVTS table.\nSQL Error: " . $mysqli->error . "\nSQL State: " . $mysqli->sqlstate;
                        $stmt->close();
                        throw new Exception($ResponseText, XMLRESULT_SQL_ERROR);
                    }
                    if (!$stmt->execute()) {
                        $ResponseText = "Error executing statement on DVDPTTVTS table.\nSQL Error: " . $mysqli->error . "\nSQL State: " . $mysqli->sqlstate;
                        $stmt->close();
                        throw new Exception($ResponseText, XMLRESULT_SQL_ERROR);
                    }
                    //$idDVDPTTVTS = $mysqli->insert_id;
                    $stmt->close();
                }
            }
            // DVDVIDEOSTREAM
            foreach ($tagDVDVMGM->DVDVIDEOSTREAM as $tagDVDVIDEOSTREAM) {
                addVideoStream($mysqli, $tagDVDVIDEOSTREAM, $idDVDVMGM, null);
            }
            // DVDAUDIOSTREAM
            foreach ($tagDVDVMGM->DVDAUDIOSTREAM as $tagDVDAUDIOSTREAM) {
                addAudioStream($mysqli, $tagDVDAUDIOSTREAM, $idDVDVMGM, null);
            }
            // DVDSUBPICSTREAM
            foreach ($tagDVDVMGM->DVDSUBPICSTREAM as $tagDVDSUBPICSTREAM) {
                addSubpictureStream($mysqli, $tagDVDSUBPICSTREAM, $idDVDVMGM, null);
            }
            // Fileset
            foreach ($tagDVDVMGM->DVDFILE as $tagDVDFILE) {
                addFileset($mysqli, $tagDVDFILE, $idDVDVMGM, null);
            }
        } else {
            // Found: do an update
            $strSQL = "UPDATE `DVDVMGM` SET `Album` = ?, `AlbumArtist` = ?, `Genre` = ?, `Cast` = ?, `Crew` = ?, `Director` = ?, `Country` = ?, `ReleaseDate` = ?, `SpecialFeatures` = ?, `EAN_UPC` = ?, `Storyline` = ?, `Remarks` = ?, `Submitter` = ?, `SubmitterIP` = ?, `Client` = ?, `Keywords` = ?, `RegionProhibited1` = ?, `RegionProhibited2` = ?, `RegionProhibited3` = ?, `RegionProhibited4` = ?, `RegionProhibited5` = ?, `RegionProhibited6` = ?, `RegionProhibited7` = ?, `RegionProhibited8` = ?, `VersionNumberMajor` = ?, `VersionNumberMinor` = ?, `NumberOfVolumes` = ?, `VolumeNumber` = ?, `OriginalAlbum` = ?, `Screenplay` = ?, `Producer` = ?, `Editing` = ?, `Cinematography` = ?, `OriginalLanguage` = ?, `SideID` = ? WHERE `idDVDVMGM` = ?;";
            $stmt = $mysqli->prepare($strSQL);
            if (!$stmt) {
                $ResponseText = "Error preparing update statement for DVDVMGM table.\nSQL Error: " . $mysqli->error . "\nSQL State: " . $mysqli->sqlstate;
                throw new Exception($ResponseText, XMLRESULT_SQL_ERROR);
            }
            if (!$stmt->bind_param("ssssssssssssssssiiiiiiiiiiiissssssii", $Album, $AlbumArtist, $Genre, $Cast, $Crew, $Director, $Country, $ReleaseDate, $SpecialFeatures, $EAN_UPC, $Storyline, $Remarks, $Submitter, $SubmitterIP, $Client, $Keywords, $RegionProhibited1, $RegionProhibited2, $RegionProhibited3, $RegionProhibited4, $RegionProhibited5, $RegionProhibited6, $RegionProhibited7, $RegionProhibited8, $VersionNumberMajor, $VersionNumberMinor, $NumberOfVolumes, $VolumeNumber, $OriginalAlbum, $Screenplay, $Producer, $Editing, $Cinematography, $OriginalLanguage, $SideID, $idDVDVMGM)) {
                $ResponseText = "Error binding parameters for DVDVMGM table.\nSQL Error: " . $mysqli->error . "\nSQL State: " . $mysqli->sqlstate;
                $stmt->close();
                $stmt = null;
                throw new Exception($ResponseText, XMLRESULT_SQL_ERROR);
            }
            if (!$stmt->execute()) {
                $ResponseText = "Error executing statement on DVDVMGM table.\nSQL Error: " . $mysqli->error . "\nSQL State: " . $mysqli->sqlstate;
                $stmt->close();
                $stmt = null;
                throw new Exception($ResponseText, XMLRESULT_SQL_ERROR);
            }
            $stmt->close();
            $stmt = null;
            // Physical structure
            $tagPhysical = $tagDVDVMGM->physical;
            foreach ($tagPhysical->DVDVTS as $tagDVDVTS) {
                // Update DVDVTS (Video Title Set)
                $attributes = $tagDVDVTS->attributes();
                $TitleSetNo = $attributes["TitleSetNo"];
                $VersionNumberMajor = value_or_null($attributes["VersionNumberMajor"]);
                $VersionNumberMinor = value_or_null($attributes["VersionNumberMinor"]);
                $idDVDVTS = getPrimaryKey($mysqli, "DVDVTS", "idDVDVTS", "`DVDVMGMKey` = {$idDVDVMGM} AND `TitleSetNo` = {$TitleSetNo}");
                $strSQL = "UPDATE `DVDVTS` SET `TitleSetNo` = ?, `VersionNumberMajor` = ?, `VersionNumberMinor` = ? WHERE `idDVDVTS` = ?;";
                $stmt = $mysqli->prepare($strSQL);
                if (!$stmt) {
                    $ResponseText = "Error preparing update statement for DVDVTS table.\nSQL Error: " . $mysqli->error . "\nSQL State: " . $mysqli->sqlstate;
                    throw new Exception($ResponseText, XMLRESULT_SQL_ERROR);
                }
                if (!$stmt->bind_param("iiii", $TitleSetNo, $VersionNumberMajor, $VersionNumberMinor, $idDVDVTS)) {
                    $ResponseText = "Error binding parameters for DVDVTS table.\nSQL Error: " . $mysqli->error . "\nSQL State: " . $mysqli->sqlstate;
                    $stmt->close();
                    throw new Exception($ResponseText, XMLRESULT_SQL_ERROR);
                }
                if (!$stmt->execute()) {
                    $ResponseText = "Error executing statement on DVDVTS table.\nSQL Error: " . $mysqli->error . "\nSQL State: " . $mysqli->sqlstate;
                    $stmt->close();
                    throw new Exception($ResponseText, XMLRESULT_SQL_ERROR);
                }
                $stmt->close();
                foreach ($tagDVDVTS->DVDPGC as $tagDVDPGC) {
                    // Update DVDPGC (Program Chain)
                    $attributes = $tagDVDPGC->attributes();
                    $ProgramChainNo = value_or_null($attributes["Number"]);
                    $EntryPGC = value_or_null($attributes["EntryPGC"]);
                    $idDVDPGC = getPrimaryKey($mysqli, "DVDPGC", "idDVDPGC", "`DVDVTSKey` = {$idDVDVTS} AND `ProgramChainNo` = {$ProgramChainNo}");
                    $strSQL = "UPDATE `DVDPGC` SET `EntryPGC` = ? WHERE `idDVDPGC` = ?;";
                    $stmt = $mysqli->prepare($strSQL);
                    if (!$stmt) {
                        $ResponseText = "Error preparing insert statement for DVDPGC table.\nSQL Error: " . $mysqli->error . "\nSQL State: " . $mysqli->sqlstate;
                        throw new Exception($ResponseText, XMLRESULT_SQL_ERROR);
                    }
                    if (!$stmt->bind_param("ii", $EntryPGC, $idDVDPGC)) {
                        $ResponseText = "Error binding parameters for DVDPGC table.\nSQL Error: " . $mysqli->error . "\nSQL State: " . $mysqli->sqlstate;
                        $stmt->close();
                        throw new Exception($ResponseText, XMLRESULT_SQL_ERROR);
                    }
                    if (!$stmt->execute()) {
                        $ResponseText = "Error executing statement on DVDPGC table.\nSQL Error: " . $mysqli->error . "\nSQL State: " . $mysqli->sqlstate;
                        $stmt->close();
                        throw new Exception($ResponseText, XMLRESULT_SQL_ERROR);
                    }
                    $stmt->close();
                    foreach ($tagDVDPGC->DVDPROGRAM as $tagDVDPROGRAM) {
                        // Update DVDPGC (Program)
                        $attributes = $tagDVDPROGRAM->attributes();
                        $ProgramNo = value_or_null($attributes["Number"]);
                        // Nothing to update...
                        $idDVDPROGRAM = getPrimaryKey($mysqli, "DVDPROGRAM", "idDVDPROGRAM", "`DVDPGCKey` = {$idDVDPGC} AND `ProgramNo` = {$ProgramNo}");
                        foreach ($tagDVDPROGRAM->DVDCELL as $tagDVDCELL) {
                            // Update DVDCELL (Cell)
                            $attributes = $tagDVDCELL->attributes();
                            $CellNo = value_or_null($attributes["Number"]);
                            $CellType = value_or_null($attributes["CellType"]);
                            $BlockType = value_or_null($attributes["BlockType"]);
                            $SeamlessMultiplex = value_or_null($attributes["SeamlessMultiplex"]);
                            $Interleaved = value_or_null($attributes["Interleaved"]);
                            $SCRdiscontinuity = value_or_null($attributes["SCRdiscontinuity"]);
                            $SeamlessAngleLinkedInDSI = value_or_null($attributes["SeamlessAngleLinkedInDSI"]);
                            $VOBStillMode = value_or_null($attributes["VOBStillMode"]);
                            $StopsTrickPlay = value_or_null($attributes["StopsTrickPlay"]);
                            $CellStillTime = value_or_null($attributes["CellStillTime"]);
                            $CellCommand = value_or_null($attributes["CellCommand"]);
                            $PlayTime = value_or_null($attributes["PlayTime"]);
                            $FrameRate = value_or_null($attributes["FrameRate"]);
                            $FirstVOBUStartSector = value_or_null($attributes["FirstVOBUStartSector"]);
                            $FirstILVUEndSector = value_or_null($attributes["FirstILVUEndSector"]);
                            $LastVOBUStartSector = value_or_null($attributes["LastVOBUStartSector"]);
                            $LastVOBUEndSector = value_or_null($attributes["LastVOBUEndSector"]);
                            $VOBidn = value_or_null($attributes["VOBidn"]);
                            $CELLidn = value_or_null($attributes["CELLidn"]);
                            $NumberOfVOBIds = value_or_null($attributes["NumberOfVOBIds"]);
                            $idDVDCELL = getPrimaryKey($mysqli, "DVDCELL", "idDVDCELL", "`DVDPROGRAMKey` = {$idDVDPROGRAM} AND `CellNo` = {$CellNo}");
                            $strSQL = "UPDATE `DVDCELL` SET `CellType` = ?, `BlockType` = ?, `SeamlessMultiplex` = ?, `Interleaved` = ?, `SCRdiscontinuity` = ?, `SeamlessAngleLinkedInDSI` = ?, `VOBStillMode` = ?, `StopsTrickPlay` = ?, `CellStillTime` = ?, `CellCommand` = ?, `PlayTime` = ?, `FrameRate` = ?, `FirstVOBUStartSector` = ?, `FirstILVUEndSector` = ?, `LastVOBUStartSector` = ?, `LastVOBUEndSector` = ?, `VOBidn` = ?, `CELLidn` = ?, `NumberOfVOBIds` = ? WHERE `idDVDCELL` = ?;";
                            $stmt = $mysqli->prepare($strSQL);
                            if (!$stmt) {
                                $ResponseText = "Error preparing insert statement for DVDCELL table.\nSQL Error: " . $mysqli->error . "\nSQL State: " . $mysqli->sqlstate;
                                throw new Exception($ResponseText, XMLRESULT_SQL_ERROR);
                            }
                            if (!$stmt->bind_param("ssiiiiiiiiiiiiiiiiii", $CellType, $BlockType, $SeamlessMultiplex, $Interleaved, $SCRdiscontinuity, $SeamlessAngleLinkedInDSI, $VOBStillMode, $StopsTrickPlay, $CellStillTime, $CellCommand, $PlayTime, $FrameRate, $FirstVOBUStartSector, $FirstILVUEndSector, $LastVOBUStartSector, $LastVOBUEndSector, $VOBidn, $CELLidn, $NumberOfVOBIds, $idDVDCELL)) {
                                $ResponseText = "Error binding parameters for DVDCELL table.\nSQL Error: " . $mysqli->error . "\nSQL State: " . $mysqli->sqlstate;
                                $stmt->close();
                                throw new Exception($ResponseText, XMLRESULT_SQL_ERROR);
                            }
                            if (!$stmt->execute()) {
                                $ResponseText = "Error executing statement on DVDCELL table.\nSQL Error: " . $mysqli->error . "\nSQL State: " . $mysqli->sqlstate;
                                $stmt->close();
                                throw new Exception($ResponseText, XMLRESULT_SQL_ERROR);
                            }
                            $stmt->close();
                            foreach ($tagDVDCELL->DVDUNIT as $tagDVDUNIT) {
                                // Update DVDUNIT (Unit)
                                $attributes = $tagDVDUNIT->attributes();
                                $UnitNo = value_or_null($attributes["Number"]);
                                $StartSector = value_or_null($attributes["StartSector"]);
                                $EndSector = value_or_null($attributes["EndSector"]);
                                $strSQL = "UPDATE `DVDUNIT` SET `StartSector` = ?, `EndSector` = ? WHERE `DVDCELLKey` = ? AND `UnitNo` = ?;";
                                $stmt = $mysqli->prepare($strSQL);
                                if (!$stmt) {
                                    $ResponseText = "Error preparing insert statement for DVDUNIT table.\nSQL Error: " . $mysqli->error . "\nSQL State: " . $mysqli->sqlstate;
                                    throw new Exception($ResponseText, XMLRESULT_SQL_ERROR);
                                }
                                if (!$stmt->bind_param("iiii", $StartSector, $EndSector, $idDVDCELL, $UnitNo)) {
                                    $ResponseText = "Error binding parameters for DVDUNIT table.\nSQL Error: " . $mysqli->error . "\nSQL State: " . $mysqli->sqlstate;
                                    $stmt->close();
                                    throw new Exception($ResponseText, XMLRESULT_SQL_ERROR);
                                }
                                if (!$stmt->execute()) {
                                    $ResponseText = "Error executing statement on DVDUNIT table.\nSQL Error: " . $mysqli->error . "\nSQL State: " . $mysqli->sqlstate;
                                    $stmt->close();
                                    throw new Exception($ResponseText, XMLRESULT_SQL_ERROR);
                                }
                                //$idDVDUNIT = $mysqli->insert_id;
                                $stmt->close();
                            }
                        }
                    }
                }
                // DVDVIDEOSTREAM
                foreach ($tagDVDVTS->DVDVIDEOSTREAM as $tagDVDVIDEOSTREAM) {
                    updateVideoStream($mysqli, $tagDVDVIDEOSTREAM, null, $idDVDVTS);
                }
                // DVDAUDIOSTREAM
                foreach ($tagDVDVTS->DVDAUDIOSTREAM as $tagDVDAUDIOSTREAM) {
                    updateAudioStream($mysqli, $tagDVDAUDIOSTREAM, null, $idDVDVTS);
                }
                // DVDAUDIOSTREAMEX
                foreach ($tagDVDVTS->DVDAUDIOSTREAMEX as $audiostreamExTag) {
                    updateAudioStreamEx($mysqli, $audiostreamExTag, $idDVDVTS);
                }
                // DVDSUBPICSTREAM
                foreach ($tagDVDVTS->DVDSUBPICSTREAM as $tagDVDSUBPICSTREAM) {
                    updateSubpictureStream($mysqli, $tagDVDSUBPICSTREAM, null, $idDVDVTS);
                }
                // Fileset
                foreach ($tagDVDVTS->DVDFILE as $tagDVDFILE) {
                    updateFileset($mysqli, $tagDVDFILE, null, $idDVDVTS);
                }
            }
            // Virtual structure
            $tagVirtual = $tagDVDVMGM->virtual;
            foreach ($tagVirtual->DVDPTTVMG as $tagDVDPTTVMG) {
                // Update DVDPTTVMG (Video Title Set)
                $attributes = $tagDVDPTTVMG->attributes();
                $Title = value_or_null($tagDVDPTTVMG->Title);
                $TitleSetNo = value_or_null($attributes["TitleSetNo"]);
                $PlaybackType = value_or_null($attributes["PlaybackType"]);
                $NumberOfVideoAngles = value_or_null($attributes["NumberOfVideoAngles"]);
                $ParentalMgmMaskVMG = value_or_null($attributes["ParentalMgmMaskVMG"]);
                $ParentalMgmMaskVTS = value_or_null($attributes["ParentalMgmMaskVTS"]);
                $NumberOfVideoAngles = value_or_null($attributes["NumberOfVideoAngles"]);
                $VideoTitleSetNo = value_or_null($attributes["VideoTitleSetNo"]);
                $TitleNo = value_or_null($attributes["TitleNo"]);
                $idDVDPTTVMG = getPrimaryKey($mysqli, "DVDPTTVMG", "idDVDPTTVMG", "`DVDVMGMKey` = {$idDVDVMGM} AND `TitleSetNo` = {$TitleSetNo}");
                $strSQL = "UPDATE `DVDPTTVMG` SET `Title` = ?, `PlaybackType` = ?, `NumberOfVideoAngles` = ?, `ParentalMgmMaskVMG` = ?, `ParentalMgmMaskVTS` = ?, `VideoTitleSetNo` = ?, `TitleNo` = ? WHERE `idDVDPTTVMG` = ?;";
                $stmt = $mysqli->prepare($strSQL);
                if (!$stmt) {
                    $ResponseText = "Error preparing insert statement for DVDPTTVMG table.\nSQL Error: " . $mysqli->error . "\nSQL State: " . $mysqli->sqlstate;
                    throw new Exception($ResponseText, XMLRESULT_SQL_ERROR);
                }
                if (!$stmt->bind_param("siiiiiii", $Title, $PlaybackType, $NumberOfVideoAngles, $ParentalMgmMaskVMG, $ParentalMgmMaskVTS, $VideoTitleSetNo, $TitleNo, $idDVDPTTVMG)) {
                    $ResponseText = "Error binding parameters for DVDPTTVMG table.\nSQL Error: " . $mysqli->error . "\nSQL State: " . $mysqli->sqlstate;
                    $stmt->close();
                    throw new Exception($ResponseText, XMLRESULT_SQL_ERROR);
                }
                if (!$stmt->execute()) {
                    $ResponseText = "Error executing statement on DVDPTTVMG table.\nSQL Error: " . $mysqli->error . "\nSQL State: " . $mysqli->sqlstate;
                    $stmt->close();
                    throw new Exception($ResponseText, XMLRESULT_SQL_ERROR);
                }
                $stmt->close();
                foreach ($tagDVDPTTVMG->DVDPTTVTS as $tagDVDPTTVTS) {
                    // Update DVDPTTVTS (Chapter)
                    $attributes = $tagDVDPTTVTS->attributes();
                    $Title = value_or_null($tagDVDPTTVTS->Title);
                    $Artist = value_or_null($tagDVDPTTVTS->Artist);
                    $ProgramChainNo = value_or_null($attributes["ProgramChainNo"]);
                    $ProgramNo = value_or_null($attributes["ProgramNo"]);
                    $PttTitleSetNo = value_or_null($attributes["PttTitleSetNo"]);
                    $PttChapterNo = value_or_null($attributes["Number"]);
                    $TitleSetNo = value_or_null($attributes["TitleSetNo"]);
                    $strSQL = "UPDATE `DVDPTTVTS` SET `Artist` = ?, `Title` = ?, `ProgramChainNo` = ?, `ProgramNo` = ?, `PttTitleSetNo` = ?, TitleSetNo = ? WHERE `DVDPTTVMGKey` = ? AND `PttChapterNo` = ? ;";
                    $stmt = $mysqli->prepare($strSQL);
                    if (!$stmt) {
                        $ResponseText = "Error preparing insert statement for DVDPTTVTS table.\nSQL Error: " . $mysqli->error . "\nSQL State: " . $mysqli->sqlstate;
                        throw new Exception($ResponseText, XMLRESULT_SQL_ERROR);
                    }
                    if (!$stmt->bind_param("ssiiiiii", $Artist, $Title, $ProgramChainNo, $ProgramNo, $PttTitleSetNo, $TitleSetNo, $idDVDPTTVMG, $PttChapterNo)) {
                        $ResponseText = "Error binding parameters for DVDPTTVTS table.\nSQL Error: " . $mysqli->error . "\nSQL State: " . $mysqli->sqlstate;
                        $stmt->close();
                        throw new Exception($ResponseText, XMLRESULT_SQL_ERROR);
                    }
                    if (!$stmt->execute()) {
                        $ResponseText = "Error executing statement on DVDPTTVTS table.\nSQL Error: " . $mysqli->error . "\nSQL State: " . $mysqli->sqlstate;
                        $stmt->close();
                        throw new Exception($ResponseText, XMLRESULT_SQL_ERROR);
                    }
                    //$idDVDPTTVTS = $mysqli->insert_id;
                    $stmt->close();
                }
            }
            // DVDVIDEOSTREAM
            foreach ($tagDVDVMGM->DVDVIDEOSTREAM as $tagDVDVIDEOSTREAM) {
                updateVideoStream($mysqli, $tagDVDVIDEOSTREAM, $idDVDVMGM, null);
            }
            // DVDAUDIOSTREAM
            foreach ($tagDVDVMGM->DVDAUDIOSTREAM as $tagDVDAUDIOSTREAM) {
                updateAudioStream($mysqli, $tagDVDAUDIOSTREAM, $idDVDVMGM, null);
            }
            // DVDSUBPICSTREAM
            foreach ($tagDVDVMGM->DVDSUBPICSTREAM as $tagDVDSUBPICSTREAM) {
                updateSubpictureStream($mysqli, $tagDVDSUBPICSTREAM, $idDVDVMGM, null);
            }
            // Fileset
            foreach ($tagDVDVMGM->DVDFILE as $tagDVDFILE) {
                updateFileset($mysqli, $tagDVDFILE, $idDVDVMGM, null);
            }
        }
    }
    // Commit the transaction
    $rs = query_server($mysqli, "COMMIT;");
}