<commit_before><?php

include('./dbconf.php');


function __getSingleValue($returnValue, $table, $whereCol, $whereValue){


    $db = new DataBase();
    $sql = "SELECT DISTINCT " . $returnValue . " FROM " . $table . " WHERE " . $whereCol . " = '" . $whereValue . "'";
    $result = $db->query($sql);

    if ($result->num_rows > 0) {
        // output data of each row
        while($row = $result->fetch_assoc()) {
            $returnresult =  $row[$returnValue];
        }
    } else {
        $returnresult = 0;
    }
    return $returnresult;

}




function __getPageList(){

    $db = new DataBase();

    $sql = "SELECT * FROM " . $db::PAGE_TABLENAME;
    $result = $db->query($sql);

    if ($result->num_rows > 0) {
        echo "<table><tr><th>Id</th><th>Title</th><th></th><th></th></tr>";
        while($row = $result->fetch_assoc()) {
            echo "<tr>
        <td>" . $row[$db::PAGE_IDCOL] . "</td>
        <td>" . $db::PAGE_TITLECOL . "</td>
        <td><a href='/admin/editpage.php?page=" . $row[$db::PAGE_TITLECOL] . "'><i class='fa fa-edit'></i>Edit</a></td>
        <td><a href='#'><i class='fa fa-trash'></i>Delete</a></td>
        </tr>";
        }
        echo "</table>";
    } else {
        echo "0 results";
    }
//$db->close();
}

function __getPageFile($pageId) {
    $db = new DataBase();
    $resultTitle = "";
    $sql = "SELECT " . $db::PAGE_TITLECOL . " FROM " . $db::PAGE_TABLENAME . " WHERE " . $db::PAGE_IDCOL  . " = " . $pageId;
    $result = $db->query($sql);

    if ($result->num_rows > 0) {
        while($row = $result->fetch_assoc()) {
            $resultTitle =  $row[$db::PAGE_TITLECOL];
        }
    } else {
        echo "0 results";
    }
    $pageFileName = strtolower(str_replace(array('  ', ' '), '-', preg_replace('/[^a-zA-Z0-9 s]/', '', trim($resultTitle)))) . ".php";
    return $pageFileName;


}



function __getContent($pageId){

    $db = new DataBase();

    $sql = "SELECT " . $db::PAGECONTENT_CONTENTCOL . " FROM " . $db::PAGECONTENT_TABLENAME . " WHERE " . $db::PAGECONTENT_PAGEIDCOL  . " = " . $pageId;

    $result = $db->query($sql);

    if ($result->num_rows > 0) {
        while($row = $result->fetch_assoc()) {
            echo "<p>" . $row[$db::PAGECONTENT_CONTENTCOL] . "<p>";
        }
    }
//$db->close();
}



function __getTitle($pageId){

    $db = new DataBase();

    $sql = "SELECT * FROM pages WHERE idpages = " . $pageId;
    $result = $db->query($sql);

    if ($result->num_rows > 0) {
        while($row = $result->fetch_assoc()) {
            echo $row["title"];
        }
    } else {
        echo "0 results";
    }
//$db->close();
}



function __getLinkList(){
    $db = new DataBase();
    $sql = "SELECT " . $db::PAGE_TITLECOL . " FROM " . $db::PAGE_TABLENAME;
    $result = $db->query($sql);

    if ($result->num_rows > 0) {
        while($row = $result->fetch_assoc()) {
            $title = $row[$db::PAGE_TITLECOL];
            $URLtitle = strtolower(str_replace(array('  ', ' '), '-', preg_replace('/[^a-zA-Z0-9 s]/', '', trim($row[$db::PAGE_TITLECOL]))));
            if($row[$db::PAGE_TITLECOL] == "Home"){
                echo "<li><a href='/" . $db::ROOTURL . "'>" . $title . "</a></li>";
            }else{
                echo "<li><a href='" . $db::ROOTURL . "/" . $URLtitle . "/'>" . $title . "</a></li>";
            }
        }
    } else {
        echo "0 results";
    }
//$db->close();
}


function __getAdminLinkList(){
    $db = new DataBase();
    $sql = "SELECT * FROM " . $db::ADMINPAGES_TABLENAME;
    $result = $db->query($sql);
    if ($result->num_rows > 0) {
        while($row = $result->fetch_assoc()) {
            if($row[$db::ADMINPAGES_PARENTIDCOL] == null || $row[$db::ADMINPAGES_PARENTIDCOL] == ""){
                $title = $row[$db::ADMINPAGES_TITLECOL];
                $URLtitle = strtolower(str_replace(array('  ', ' '), '-', preg_replace('/[^a-zA-Z0-9 s]/', '', trim($row[$db::ADMINPAGES_TITLECOL]))));
                if($row[$db::ADMINPAGES_TITLECOL] == "Home"){
                    echo "<li><a href='" . $db::ROOTURL . "'><i class='" . $row[$db::ADMINPAGES_ICONCOL] . "'></i>" . $title . "</a></li>";
                }else{
                    echo "<li><a href='" . $db::ROOTURL . "/" . $URLtitle . "'><i class='" . $row[$db::ADMINPAGES_ICONCOL] . "'></i>" . $title . "</a>";
                    $sql2 = "SELECT * FROM " . $db::ADMINPAGES_TABLENAME;
                    $result2 = $db->query($sql2);
                    $ul = 0;
                    $ulSet = false;
                    while($subrow = $result2->fetch_assoc()) {
                        $ul++;
                        $title = $subrow[$db::ADMINPAGES_TITLECOL];
                        $URLtitle = strtolower(str_replace(array('  ', ' '), '-', preg_replace('/[^a-zA-Z0-9 s]/', '', trim($subrow[$db::ADMINPAGES_TITLECOL]))));
                        if ($subrow[$db::ADMINPAGES_PARENTIDCOL] == $row[$db::ADMINPAGES_IDCOL]){
                            if ($ulSet == false){
                                echo "<ul>";
                                $ulSet = true;
                            }
                            echo "<li><a href='" . $db::ROOTURL . "/" . $URLtitle . "'><i class='" . $subrow[$db::ADMINPAGES_ICONCOL] . "'></i>" . $title . "</a></li>";
                        }
                    }
                    if ($ulSet==true){
                        echo "</ul>";
                    }
                    echo "</li>";
                }
            }
        }
    }else {
        echo "0 results";
    }
}

function __getPhotoAlbum($albumId){
    $db = new DataBase();
    $albumTitle = __getSingleValue($db::PHOTOALBUMS_TITLECOL, $db::PHOTOALBUMS_TABLENAME, $db::PHOTOALBUMS_IDCOL, $albumId);
    $albumDate = __getSingleValue($db::PHOTOALBUMS_DATECOL, $db::PHOTOALBUMS_TABLENAME, $db::PHOTOALBUMS_IDCOL, $albumId);
    $albumDateString = date("F j, Y", strtotime($albumDate));
    $albumDescription = __getSingleValue($db::PHOTOALBUMS_DESCRIPTIONCOL, $db::PHOTOALBUMS_TABLENAME, $db::PHOTOALBUMS_IDCOL, $albumId);
    $photographer = __getSingleValue($db::PHOTOALBUMS_PHOTOGRAPHERCOL, $db::PHOTOALBUMS_TABLENAME, $db::PHOTOALBUMS_IDCOL, $albumId);
    $photographerStripped = strtolower(str_replace(array('  ', ' '), '-', preg_replace('/[^a-zA-Z0-9 s]/', '', trim($photographer))));
    $photoCount = __getSingleValue($db::PHOTOALBUMS_ALBUMSIZECOL, $db::PHOTOALBUMS_TABLENAME, $db::PHOTOALBUMS_IDCOL, $albumId);
    $sql = "SELECT * FROM " . $db::PHOTOS_TABLENAME . " WHERE " . $db::PHOTOS_ALBUMIDCOL . " = " . $albumId;
    $result = $db->query($sql);
    if ($result->num_rows > 0) {
    //TODO Description at all photos    $photoCount = $result->num_rows;

        echo "<div class='col-4 photoalbum-link'>";
            echo "<div class='panel bg-noise bg-white fg-black no-padding'>";
                echo "<div class='no-padding album-thumb'>";
                    echo "<a onclick='showPhoto($albumId, $photoCount, 1)' href='#photoalbum'><img src='/images/photoalbums/" . $albumTitle . "-" . $albumDate . "-" . $photographerStripped . ".jpg' alt='" . $albumTitle . "' class='' /></a>";
                echo "</div>";
                echo "<div>";
                    echo "<h3>" .  $albumTitle . "</h3>";
                    echo "<p class='album-date'>" . $albumDateString . "</p>";
                    echo "<p>" . $albumDescription . "</p>";
                    echo "<p>Photos by " . $photographer . "</p>";
                    echo "<a onclick='showPhoto($albumId, $photoCount, 1)' href='#photoalbum' class='button bg-setonescap-red'> Watch photos</a>";
                echo "</div>";
            echo "</div>";

        echo "</div>";

    } else {
        echo "0 results albun";
    }
    //$db->close();
}

function __getPhotoAlbums($band){
    $db = new DataBase();
    $sql = "SELECT DISTINCT ". $db::PHOTOALBUMS_TITLECOL .", " . $db::PHOTOALBUMS_IDCOL . ", " . $db::PHOTOALBUMS_DATECOL .<commit_msg>Add getPhotographer function<commit_after><?php

include('./dbconf.php');


function __getSingleValue($returnValue, $table, $whereCol, $whereValue){


    $db = new DataBase();
    $sql = "SELECT DISTINCT " . $returnValue . " FROM " . $table . " WHERE " . $whereCol . " = '" . $whereValue . "'";
    $result = $db->query($sql);

    if ($result->num_rows > 0) {
        // output data of each row
        while($row = $result->fetch_assoc()) {
            $returnresult =  $row[$returnValue];
        }
    } else {
        $returnresult = 0;
    }
    return $returnresult;

}




function __getPageList(){

    $db = new DataBase();

    $sql = "SELECT * FROM " . $db::PAGE_TABLENAME;
    $result = $db->query($sql);

    if ($result->num_rows > 0) {
        echo "<table><tr><th>Id</th><th>Title</th><th></th><th></th></tr>";
        while($row = $result->fetch_assoc()) {
            echo "<tr>
        <td>" . $row[$db::PAGE_IDCOL] . "</td>
        <td>" . $db::PAGE_TITLECOL . "</td>
        <td><a href='/admin/editpage.php?page=" . $row[$db::PAGE_TITLECOL] . "'><i class='fa fa-edit'></i>Edit</a></td>
        <td><a href='#'><i class='fa fa-trash'></i>Delete</a></td>
        </tr>";
        }
        echo "</table>";
    } else {
        echo "0 results";
    }
//$db->close();
}

function __getPageFile($pageId) {
    $db = new DataBase();
    $resultTitle = "";
    $sql = "SELECT " . $db::PAGE_TITLECOL . " FROM " . $db::PAGE_TABLENAME . " WHERE " . $db::PAGE_IDCOL  . " = " . $pageId;
    $result = $db->query($sql);

    if ($result->num_rows > 0) {
        while($row = $result->fetch_assoc()) {
            $resultTitle =  $row[$db::PAGE_TITLECOL];
        }
    } else {
        echo "0 results";
    }
    $pageFileName = strtolower(str_replace(array('  ', ' '), '-', preg_replace('/[^a-zA-Z0-9 s]/', '', trim($resultTitle)))) . ".php";
    return $pageFileName;


}



function __getContent($pageId){

    $db = new DataBase();

    $sql = "SELECT " . $db::PAGECONTENT_CONTENTCOL . " FROM " . $db::PAGECONTENT_TABLENAME . " WHERE " . $db::PAGECONTENT_PAGEIDCOL  . " = " . $pageId;

    $result = $db->query($sql);

    if ($result->num_rows > 0) {
        while($row = $result->fetch_assoc()) {
            echo "<p>" . $row[$db::PAGECONTENT_CONTENTCOL] . "<p>";
        }
    }
//$db->close();
}



function __getTitle($pageId){

    $db = new DataBase();

    $sql = "SELECT * FROM pages WHERE idpages = " . $pageId;
    $result = $db->query($sql);

    if ($result->num_rows > 0) {
        while($row = $result->fetch_assoc()) {
            echo $row["title"];
        }
    } else {
        echo "0 results";
    }
//$db->close();
}



function __getLinkList(){
    $db = new DataBase();
    $sql = "SELECT " . $db::PAGE_TITLECOL . " FROM " . $db::PAGE_TABLENAME;
    $result = $db->query($sql);

    if ($result->num_rows > 0) {
        while($row = $result->fetch_assoc()) {
            $title = $row[$db::PAGE_TITLECOL];
            $URLtitle = strtolower(str_replace(array('  ', ' '), '-', preg_replace('/[^a-zA-Z0-9 s]/', '', trim($row[$db::PAGE_TITLECOL]))));
            if($row[$db::PAGE_TITLECOL] == "Home"){
                echo "<li><a href='/" . $db::ROOTURL . "'>" . $title . "</a></li>";
            }else{
                echo "<li><a href='" . $db::ROOTURL . "/" . $URLtitle . "/'>" . $title . "</a></li>";
            }
        }
    } else {
        echo "0 results";
    }
//$db->close();
}


function __getAdminLinkList(){
    $db = new DataBase();
    $sql = "SELECT * FROM " . $db::ADMINPAGES_TABLENAME;
    $result = $db->query($sql);
    if ($result->num_rows > 0) {
        while($row = $result->fetch_assoc()) {
            if($row[$db::ADMINPAGES_PARENTIDCOL] == null || $row[$db::ADMINPAGES_PARENTIDCOL] == ""){
                $title = $row[$db::ADMINPAGES_TITLECOL];
                $URLtitle = strtolower(str_replace(array('  ', ' '), '-', preg_replace('/[^a-zA-Z0-9 s]/', '', trim($row[$db::ADMINPAGES_TITLECOL]))));
                if($row[$db::ADMINPAGES_TITLECOL] == "Home"){
                    echo "<li><a href='" . $db::ROOTURL . "'><i class='" . $row[$db::ADMINPAGES_ICONCOL] . "'></i>" . $title . "</a></li>";
                }else{
                    echo "<li><a href='" . $db::ROOTURL . "/" . $URLtitle . "'><i class='" . $row[$db::ADMINPAGES_ICONCOL] . "'></i>" . $title . "</a>";
                    $sql2 = "SELECT * FROM " . $db::ADMINPAGES_TABLENAME;
                    $result2 = $db->query($sql2);
                    $ul = 0;
                    $ulSet = false;
                    while($subrow = $result2->fetch_assoc()) {
                        $ul++;
                        $title = $subrow[$db::ADMINPAGES_TITLECOL];
                        $URLtitle = strtolower(str_replace(array('  ', ' '), '-', preg_replace('/[^a-zA-Z0-9 s]/', '', trim($subrow[$db::ADMINPAGES_TITLECOL]))));
                        if ($subrow[$db::ADMINPAGES_PARENTIDCOL] == $row[$db::ADMINPAGES_IDCOL]){
                            if ($ulSet == false){
                                echo "<ul>";
                                $ulSet = true;
                            }
                            echo "<li><a href='" . $db::ROOTURL . "/" . $URLtitle . "'><i class='" . $subrow[$db::ADMINPAGES_ICONCOL] . "'></i>" . $title . "</a></li>";
                        }
                    }
                    if ($ulSet==true){
                        echo "</ul>";
                    }
                    echo "</li>";
                }
            }
        }
    }else {
        echo "0 results";
    }
}


function __getPhotographer($albumTitle, $albumDate, $photographerLink){
    $db = new DataBase();
    $photographerLinkShort = (substr($photographerLink, 0, 4));

    $sql = "SELECT * FROM " . $db::PHOTOALBUMS_TABLENAME .
        " WHERE " . $db::PHOTOALBUMS_TITLECOL . " = '" . $albumTitle .
        "' AND " . $db::PHOTOALBUMS_DATECOL . " = '" . $albumDate .
        "' AND " . $db::PHOTOALBUMS_PHOTOGRAPHERCOL . " LIKE '" . $photographerLinkShort . "%'";
    $result = $db->query($sql);
    if ($result->num_rows > 0) {
        while($row = $result->fetch_assoc()) {
            return $row[$db::PHOTOALBUMS_PHOTOGRAPHERCOL];
        }
    }
}



function __getPhotoAlbum($albumId){
    $db = new DataBase();
    $albumTitle = __getSingleValue($db::PHOTOALBUMS_TITLECOL, $db::PHOTOALBUMS_TABLENAME, $db::PHOTOALBUMS_IDCOL, $albumId);
    $albumDate = __getSingleValue($db::PHOTOALBUMS_DATECOL, $db::PHOTOALBUMS_TABLENAME, $db::PHOTOALBUMS_IDCOL, $albumId);
    $albumDateString = date("F j, Y", strtotime($albumDate));
    $albumDescription = __getSingleValue($db::PHOTOALBUMS_DESCRIPTIONCOL, $db::PHOTOALBUMS_TABLENAME, $db::PHOTOALBUMS_IDCOL, $albumId);
    $photographer = __getSingleValue($db::PHOTOALBUMS_PHOTOGRAPHERCOL, $db::PHOTOALBUMS_TABLENAME, $db::PHOTOALBUMS_IDCOL, $albumId);
    $photographerStripped = strtolower(str_replace(array('  ', ' '), '-', preg_replace('/[^a-zA-Z0-9 s]/', '', trim($photographer))));
    $photoCount = __getSingleValue($db::PHOTOALBUMS_ALBUMSIZECOL, $db::PHOTOALBUMS_TABLENAME, $db::PHOTOALBUMS_IDCOL, $albumId);
    $sql = "SELECT * FROM " . $db::PHOTOS_TABLENAME . " WHERE " . $db::PHOTOS_ALBUMIDCOL . " = " . $albumId;
    $result = $db->query($sql);
    if ($result->num_rows > 0) {
    //TODO Description at all photos    $photoCount = $result->num_rows;

        echo "<div class='col-4 photoalbum-link'>";
            echo "<div class='panel bg-noise bg-white fg-black no-padding'>";
                echo "<div class='no-padding album-thumb'>";
                    echo "<a onclick='showPhoto($albumId, $photoCount, 1)' href='#photoalbum'><img src='/images/photoalbums/" . $albumTitle . "-" . $albumDate . "-" . $photographerStripped . ".jpg' alt='" . $albumTitle . "' class='' /></a>";
                echo "</div>";
                echo "<div>";
                    echo "<h3>" .  $albumTitle . "</h3>";
                    echo "<p class='album-date'>" . $albumDateString . "</p>";
                    echo "<p>" . $albumDescription . "</p>";
                    echo "<p>Photos by " . $photographer . "</p>";
                    echo "<a onclick='showPhoto($albumId, $photoCount, 1)' href='#photoalbum' rel='nofollow' class='button bg-setonescap-red'> Watch photos</a>";
                echo "</div>";
            echo "</div>";

        echo "</div>";

    } else {
        echo "0 results albun";
    }
    //$db->close();
}

function __getPhotoAlbums($band){
    $db = new DataBase();
    $sql = "SELECT DISTINCT ". $db::PHOTOALBUMS_TITLECOL .", " . $db::PHOTOALBUMS_IDCOL . ", " . $db::PHOTOALBUMS_DATECOL .
{'fraction_non_alphanumeric': 0.20719147142082756, 'fraction_numerical': 0.004396795759802445, 'mean_word_length': 2.1566539923954373, 'pattern_counts': {'":': 0, '<': 167, '<?xml version=': 0, '>': 247, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7129331', 'n_tokens_mistral': 5973, 'n_tokens_neox': 5617, 'n_words': 953}