samedi 27 février 2016

PHP Conditional logic troubles row 2 won't work without row 1

I'm working on a project that I grew frustrated with because I think I may have been a little to happy with conditional logics. The website is eqcalendar.com and it's for a private entity.

My objective is to make this user friendly so anyone in this group can access a .txt file, edit the variables, and they show up appropriately.

I was trying to make it that if a variable was left blank that no characters would show up but that if the variables are filled, they will show up.

I want to repeat this for 1 day a week spanning out to three months. As I finished day 1, I went onto day 2 but day 2 will not work unless all variables are defined in day 1.

I was also making it possible to turn the day off if the date was not filled, it would add a css inline display: none;. It was working but now it won't. I found the more if statements I add, the less seems to be cooperative.

I've noticed the same thing with the jQuery toggle. The more I add, then no other month will work.

This is supposed to be a simple web app for mobile devices. I have the following elements that I've included:

Above the DOCTYPE, I have the PHP calling in the .txt file

<?php
$title = "EQ Calendar";
include 'planner.txt'; ?>

The planner.txt file looks like the following:

/*** MONTH 1 ***/
$month1 = "February";

    /** WEEK 1 **/
        $m1w1_Day               =   "07";
        $m1w1_Chapter           =   "4";
        $m1w1_Chapter_Header    =   "Test";
        $m1w1_Chapter_Link      =   "Testing";
        $m1w1_Conf_Header       =   "Tester";
        $m1w1_Conf_Speaker      =   "Dieter";
        $m1w1_Conf_Link         =   "http://www.google.com";
        $m1w1_Teacher           =   "Steven Scott";
        $m1w1_Other             =   "Presidency Message";

    /** WEEK 2 **/
        $m1w2_Day               =   "14";
        $m1w2_Chapter           =   "";
        $m1w2_Chapter_Header    =   "";
        $m1w2_Chapter_Link      =   "";
        $m1w2_Teacher           =   "";
        $m1w2_Other             =   "Stake Conference";

    /** WEEK 3 **/
        $m1w3_Day               =   "21";
        $m1w3_Chapter           =   "2";
        $m1w3_Chapter_Header    =   "My Peace I Give unto You";
        $m1w3_Chapter_Link      =   "";
        $m1w3_Teacher           =   "Joshua Hayes";
        $m1w3_Other             =   "";

    /** WEEK 4 **/
        $m1w4_Day               =   "28";
        $m1w4_Chapter           =   "";
        $m1w4_Chapter_Header    =   "";
        $m1w4_Chapter_Link      =   "";
        $m1w4_Conf_Header       =   "Be Not Afraid, Only Believe by Dieter F. Uchtdorf";
        $m1w4_Conf_Speaker      =   "Dieter F. Uchtdorf";
        $m1w4_Conf_Link         =   "";
        $m1w4_Teacher           =   "Jory Wahlen";
        $m1w4_Other             =   "";

    /** WEEK 5 **/
        $m1w5_Day               =   "";
        $m1w5_Chapter           =   "";
        $m1w5_Chapter_Header    =   "";
        $m1w5_Chapter_Link      =   "";
        $m1w5_Conf_Header       =   "";
        $m1w5_Conf_Speaker      =   "";
        $m1w5_Conf_Link         =   "";
        $m1w5_Teacher           =   "";
        $m1w5_Other             =   "";

The PHP code within the index.php is as follows:

<div class="top-header">
                <h1><?php echo $month1 ?> <span><i class="fa fa-close month1"></i></span></h1>
            </div>
            <div class="col-md-2 col-sm-2"></div>
            <div class="col-md-8 col-sm-8">
                <p <?php if (empty($m1w1_Day)) { echo "style='display:none;'"; } ?>><strong><?php echo $m1w1_Day ?></strong> <i class="fa fa-ellipsis-v"></i>
                <?php
                    if ($m1w1_Chapter !== "") {
                        if (empty($m1w1_Chapter)) {
                            return null;
                        } else {
                            echo "Ch. $m1w1_Chapter &ndash;";
                        }
                        if (empty($m1w1_Chapter_Header)) {
                            return null;
                        } elseif ($m1w1_Chapter_Link == "") {
                            echo " $m1w1_Chapter_Header";
                            if (empty($m1w1_Teacher)) { return null; } else { echo " &ndash; $m1w1_Teacher"; }
                        } else {
                            echo " <a href='$m1w1_Chapter_Link'>$m1w1_Chapter_Header</a>";
                            if (empty($m1w1_Teacher)) { return null; } else { echo " &ndash; $m1w1_Teacher"; }
                        }
                    } elseif ($m1w1_Conf_Header !== "") {
                        if (empty($m1w1_Conf_Header)) {
                            return null;
                        } elseif ($m1w1_Conf_Link == "") {
                            echo " $m1w1_Conf_Header";
                        } else {
                            echo " <a href='$m1w1_Conf_Link'>$m1w1_Conf_Header</a>";
                        }
                        if (empty($m1w1_Conf_Speaker)) {
                            return null;
                        } else {
                            echo " by $m1w1_Conf_Speaker";
                            if (empty($m1w1_Teacher)) { return null; } else { echo " &ndash; $m1w1_Teacher"; } 
                        }
                    } else {
                        echo "$m1w1_Other";
                        if (empty($m1w1_Teacher)) { return null; } else { echo " &ndash; $m1w1_Teacher"; }
                    }
                ?></p>
            </div>

My goal is to be able to repeat this code weekly and monthly. Am I missing any elements that is preventing me from isolating the if conditional to a single variable that is interfering with the other ifs?

Aucun commentaire:

Enregistrer un commentaire