<commit_before><?php
    require_once "session.php";
    require_once "include.php";
    require_once "Template.php";


    $sessionUserId = $_SESSION[ 'sessionUserId' ];

    if ( Empty( $sessionUserId )) {
        $sessionUserId = -1;
    }
    $hdnUserId = $sessionUserId;


    $selTemplate = array_key_exists( 'selTemplate', $_REQUEST ) ? $_REQUEST[ 'selTemplate' ] : null;
    if ( null === $selTemplate ) {
        // get current template from db
        $CurTemplateSQL = "SELECT i_TemplateId
                             FROM UserTemplate
                            WHERE i_UID = $sessionUserId";

        $CurTemplateSQLId = mysql_query( $CurTemplateSQL );

        $objCurTemplate = mysql_fetch_object( $CurTemplateSQLId );

        if ( $objCurTemplate ) {
            $selTemplate = $objCurTemplate->i_TemplateId;
        }
    }
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
    <head>
    <?php
        echo "<title>$siteTitle - Edit Your Template</title>";
    ?>
    </head>
    <body>
    <a href="main.php">return to index</a> |
    <a href="TemplateHelp.html">Get your helpfile here!</a> |
    <a href="editstyles.php">jump to stylesheets</a>
<?php

    $properties = array(
        'btnSaveTemplate'
        , 'selTemplate'
        , 'btnNewTemplate'
        , 'btnPickPublic'
        , 'btnSaveTemplate'
        , 'btnMakeMine'
        , 'txtHeader'
        , 'txtComment'
        , 'txtFooter'
        , 'chkTemplatePublic'
        , 'iTemplatePublic'
        , 'txtTemplateName'
        , 'hdnTemplateId'
    );

    foreach ( $properties as $property ) {
        $$property = array_key_exists( $property, $_REQUEST ) ? $_REQUEST[ $property ] : null;
    }

    if ( !Empty( $btnSaveTemplate ) ) {
        $template = new Template( $db );

        $iTemplatePublic = 0;
        if ( $chkTemplatePublic == "on" ) {
            $iTemplatePublic = 1;
        }

	if ( -1 == $hdnTemplateId ) {
            $selTemplate = $template->create( 
                $hdnUserId, $iTemplatePublic, 
                $txtHeader, $txtComment, $txtFooter, 
                $txtTemplateName
            );
        } else {
            $template->update( 
                $hdnTemplateId, $hdnUserId, $iTemplatePublic, 
                $txtHeader, $txtComment, $txtFooter, 
                $txtTemplateName
            );
        }
    }

    // Save the template preference change if required
    if (!Empty($_REQUEST[ 'btnMakeMine' ] )) {
        $TempQuery = " DELETE FROM UserTemplate WHERE i_UID = $hdnUserId";
        $TempQueryId = mysql_query( $TempQuery );

        $TempQuery = "INSERT INTO UserTemplate VALUES ($hdnUserId, $hdnTemplateId)";
        $TempQueryId = mysql_query( $TempQuery );

        echo $TempQuery;
    }

    //  get a drop-down of all the users templates.
    $TemplateQuery = "SELECT i_TemplateID
                           , vc_TemplateName
                        FROM Template
                       WHERE i_UID = $hdnUserId
                    ORDER BY i_TemplateID";
    $TemplateQueryId = mysql_query ($TemplateQuery, $link);

    echo "<form name=\"frmSelection\" action=\"edittemplate.php\" method=\"post\">\n";
    echo "Your Templates: <select name=\"selTemplate\">\n";
    if ( Empty($selTemplate) && !Empty($hdnTemplateId)) {
        $selTemplate = $hdnTemplateId;
    }
    while ( $Templates = mysql_fetch_object($TemplateQueryId) ) {
        echo "<option value=\"".$Templates->i_TemplateID."\"";
        if ( $Templates->i_TemplateID == $selTemplate ) {
            echo " selected";
        }
        echo ">";
        echo "[$Templates->i_TemplateID] $Templates->vc_TemplateName</option>\n";
    }
    echo "</select>\n";

    echo "<input type=\"submit\" name=\"btnPickUserTemplate\" value=\"View/Edit Your Template\">\n";
    echo "<br>\n";

    echo "</form>\n";

    //  get a drop-down of all the public templates.
    $TemplateQuery = "SELECT i_TemplateID, vc_TemplateName
                                        FROM Template
                                        WHERE b_Public = 1
                                        ORDER BY i_TemplateID";
    $TemplateQueryId = mysql_query ($TemplateQuery, $link);

    echo "<form name=\"frmSelection\" action=\"edittemplate.php\" method=\"post\">\n";
    echo "Public Templates: <select name=\"selTemplate\">\n";
    while ( $Templates = mysql_fetch_object($TemplateQueryId) ) {
        echo "<option value=\"$Templates->i_TemplateID\"";
        if ( $_REQUEST[ 'selTemplate' ] == $Templates->i_TemplateID ) {
            echo " selected";
        }
        echo ">[$Templates->i_TemplateID] $Templates->vc_TemplateName</option>\n";
    }
    echo "</select>\n";

    echo "<input type=\"submit\" name=\"btnPickPublic\" value=\"View Public Template\">\n";
    echo "<br>\n";

    echo "</form>\n";


    //  if an editable style is already selected (default to user's current style, or if the button for a new stylesheet is selected)
    if (  Empty($btnMakeMine)
                && (($selTemplate > -1) || !Empty( $btnNewTemplate ))
                && Empty($btnPickPublic) || !Empty($btnSaveTemplate)
    ) {
        // When "save template" is hit, the selected template value
        // isn't loaded, but the hidden form value is.
        // therefore make the selected template value the hidden one.
        if ( ( Empty($selTemplate) || $selTemplate == -1 )
                && $hdnTemplateId > 0
        ) {
            $selTemplate = $hdnTemplateId;
        }
        // Create a text area
        echo "<form name=\"frmTemplate\" action=\"edittemplate.php\" method=\"post\">";
        echo "<input type=\"hidden\" name=\"hdnTemplateId\" value=\"";
        if ( !Empty( $btnNewTemplate ) ) {
            // if the button for a new stylesheet has been selected
            // set the hidden stylesheet id to -1 to indicate "new"
            echo "-1\">";<commit_msg>Added link to view site with selected template<commit_after><?php
    require_once "session.php";
    require_once "include.php";
    require_once "Template.php";


    $sessionUserId = $_SESSION[ 'sessionUserId' ];

    if ( Empty( $sessionUserId )) {
        $sessionUserId = -1;
    }
    $hdnUserId = $sessionUserId;


    $selTemplate = array_key_exists( 'selTemplate', $_REQUEST ) ? $_REQUEST[ 'selTemplate' ] : null;
    if ( null === $selTemplate ) {
        // get current template from db
        $CurTemplateSQL = "SELECT i_TemplateId
                             FROM UserTemplate
                            WHERE i_UID = $sessionUserId";

        $CurTemplateSQLId = mysql_query( $CurTemplateSQL );

        $objCurTemplate = mysql_fetch_object( $CurTemplateSQLId );

        if ( $objCurTemplate ) {
            $selTemplate = $objCurTemplate->i_TemplateId;
        }
    }
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
    <head>
    <?php
        echo "<title>$siteTitle - Edit Your Template</title>";
    ?>
    </head>
    <body>
    <a href="main.php">return to index</a> |
    <a href="TemplateHelp.html">Get your helpfile here!</a> |
    <a href="editstyles.php">jump to stylesheets</a> |
<?php

    $properties = array(
        'btnSaveTemplate'
        , 'selTemplate'
        , 'btnNewTemplate'
        , 'btnPickPublic'
        , 'btnSaveTemplate'
        , 'btnMakeMine'
        , 'txtHeader'
        , 'txtComment'
        , 'txtFooter'
        , 'chkTemplatePublic'
        , 'iTemplatePublic'
        , 'txtTemplateName'
        , 'hdnTemplateId'
    );

    foreach ( $properties as $property ) {
        $$property = array_key_exists( $property, $_REQUEST ) ? $_REQUEST[ $property ] : null;
    }

    if ( !Empty( $btnSaveTemplate ) ) {
        $template = new Template( $db );

        $iTemplatePublic = 0;
        if ( $chkTemplatePublic == "on" ) {
            $iTemplatePublic = 1;
        }

	if ( -1 == $hdnTemplateId ) {
            $selTemplate = $template->create( 
                $hdnUserId, $iTemplatePublic, 
                $txtHeader, $txtComment, $txtFooter, 
                $txtTemplateName
            );
        } else {
            $template->update( 
                $hdnTemplateId, $hdnUserId, $iTemplatePublic, 
                $txtHeader, $txtComment, $txtFooter, 
                $txtTemplateName
            );
        }
    }

    // Save the template preference change if required
    if (!Empty($_REQUEST[ 'btnMakeMine' ] )) {
        $TempQuery = " DELETE FROM UserTemplate WHERE i_UID = $hdnUserId";
        $TempQueryId = mysql_query( $TempQuery );

        $TempQuery = "INSERT INTO UserTemplate VALUES ($hdnUserId, $hdnTemplateId)";
        $TempQueryId = mysql_query( $TempQuery );

        echo $TempQuery;
    }

    //  get a drop-down of all the users templates.
    $TemplateQuery = "SELECT i_TemplateID
                           , vc_TemplateName
                        FROM Template
                       WHERE i_UID = $hdnUserId
                    ORDER BY i_TemplateID";
    $TemplateQueryId = mysql_query ($TemplateQuery, $link);

    echo "<form name=\"frmSelection\" action=\"edittemplate.php\" method=\"post\">\n";
    echo "Your Templates: <select name=\"selTemplate\">\n";
    if ( Empty($selTemplate) && !Empty($hdnTemplateId)) {
        $selTemplate = $hdnTemplateId;
    }
    while ( $Templates = mysql_fetch_object($TemplateQueryId) ) {
        echo "<option value=\"".$Templates->i_TemplateID."\"";
        if ( $Templates->i_TemplateID == $selTemplate ) {
            echo " selected";
        }
        echo ">";
        echo "[$Templates->i_TemplateID] $Templates->vc_TemplateName</option>\n";
    }
    echo "</select>\n";

    echo "<input type=\"submit\" name=\"btnPickUserTemplate\" value=\"View/Edit Your Template\">\n";
    echo "<br>\n";
    echo "<a href=\"main.php?TemplateID=$selTemplate\">

    echo "</form>\n";

    //  get a drop-down of all the public templates.
    $TemplateQuery = "SELECT i_TemplateID, vc_TemplateName
                                        FROM Template
                                        WHERE b_Public = 1
                                        ORDER BY i_TemplateID";
    $TemplateQueryId = mysql_query ($TemplateQuery, $link);

    echo "<form name=\"frmSelection\" action=\"edittemplate.php\" method=\"post\">\n";
    echo "Public Templates: <select name=\"selTemplate\">\n";
    while ( $Templates = mysql_fetch_object($TemplateQueryId) ) {
        echo "<option value=\"$Templates->i_TemplateID\"";
        if ( $_REQUEST[ 'selTemplate' ] == $Templates->i_TemplateID ) {
            echo " selected";
        }
        echo ">[$Templates->i_TemplateID] $Templates->vc_TemplateName</option>\n";
    }
    echo "</select>\n";

    echo "<input type=\"submit\" name=\"btnPickPublic\" value=\"View Public Template\">\n";
    echo "<br>\n";

    echo "</form>\n";

    echo "<a href=\"main.php?TemplateID=$selTemplate\">View site with selected template</a>";

    //  if an editable style is already selected (default to user's current style, or if the button for a new stylesheet is selected)
    if (  Empty($btnMakeMine)
                && (($selTemplate > -1) || !Empty( $btnNewTemplate ))
                && Empty($btnPickPublic) || !Empty($btnSaveTemplate)
    ) {
        // When "save template" is hit, the selected template value
        // isn't loaded, but the hidden form value is.
        // therefore make the selected template value the hidden one.
        if ( ( Empty($selTemplate) || $selTemplate == -1 )
                && $hdnTemplateId > 0
        ) {
            $selTemplate = $hdnTemplateId;
        }
        // Create a text area
        echo "<form name=\"frmTemplate\" action=\"edittemplate.php\" method=\"post\">";
        echo "<input type=\"hidden\" name=\"hdnTemplateId\" value=\"";
        if ( !Empty( $btnNewTemplate ) ) {
            // if the button for a new stylesheet has been selected
            // set the hidden stylesheet id to -1 to indicate "new"
            echo "-1\">";
{'fraction_non_alphanumeric': 0.13674643542066206, 'fraction_numerical': 0.0021679312932543983, 'mean_word_length': 2.065950920245399, 'pattern_counts': {'":': 0, '<': 74, '<?xml version=': 0, '>': 98, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 8, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1497521', 'n_tokens_mistral': 3491, 'n_tokens_neox': 3396, 'n_words': 826}