jeudi 27 juillet 2017

Show different HTML on page depending on origin file's directory location using PHP

I am working on my employer's website and I am relatively new to PHP. I am decent at deciphering code others have written, but I can't seem to figure out how to write additional code to integrate into the current page's PHP. I'm trying to figure out a way to display an image instead of displaying the ordered list if the file is not in a directory that has pre-defined "links" on spelled out.

The site that I am working on is http://ift.tt/1KfChnZ and the following is code that uses an array to choose what links go in the rightNav bar depending on what directory the html file is located in:

(An example of a page with a rightNav with links is this page: http://ift.tt/2v1K87D

An example of a page with no links is this page: http://ift.tt/2uGJ46I)

<?PHP

/*
Array:
    0:URL (Path, or URL.  If a Path it must be an absolute link. ie: starts with a /).
    1:Text (Try to limit length).
    2:Icon (Glyph Sets:Font-Awesome).
*/






if(isset($n)){
switch($n)
{
    case "High School":
        $links = [
            ["/highschool/principal.html","Principal","<i class='fa fa-user' aria-hidden='true'></i>"],
            ["/highschool/Guidance","Guidance & Scholarships","<i class='fa fa-map' aria-hidden='true'></i>"],
            ["/highschool/lrc/index.htm","Library","<i class='fa fa-book' aria-hidden='true'></i>"],
            ["/district/athletics.html","Athletics","<i class='fa fa-futbol-o' aria-hidden='true'></i>"],
            ["/highschool/clubs/index.html","Clubs & Groups","<i class='fa fa-coffee' aria-hidden='true'></i>"],
            ["/highschool/boosterClub/","Booster Club","<i class='fa fa-arrow-circle-up' aria-hidden='true'></i>"],
            ["/highschool/chsband/index.html","Band","<i class='fa fa-music' aria-hidden='true'></i>"],
            ["/highschool/attachment/2017courseBook.pdf","2017 Course Book","<i class='fa fa-list-alt' aria-hidden='true'></i>"],
            ["http://ift.tt/2v1OeN7","Claymont On-line Learning","<i class='fa fa-globe' aria-hidden='true'></i>"],
            ["/highschool/bellschedule/bell_schedule.htm","Bell Schedule","<i class='fa fa-bell' aria-hidden='true'></i>"],
            ["/attachment/handbook/CHS_Handbook.pdf","Student Handbook","<i class='fa fa-list-ul' aria-hidden='true'></i>"],
            ["http://ift.tt/2uGODlL","Video Editing","<i class='fa fa-video-camera' aria-hidden='true'></i>"],
            ["/highschool/about-mustang/","Mustang","<i class='fa fa-paw' aria-hidden='true'></i>"]         
        ];
        break;

    case "Middle School":
        $links = [
            ["cjhslrc/index_new.html","Library","<i class='fa fa-book' aria-hidden='true'></i>"],
            ["/district/athletics.html","Athletics","<i class='fa fa-futbol-o' aria-hidden='true'></i>"],
            ["http://ift.tt/2v1OeN7","Claymont On-line Learning","<i class='fa fa-globe' aria-hidden='true'></i>"],
            ["/juniorhigh/bellschedule/bell_schedule.htm","Bell Schedule","<i class='fa fa-bell' aria-hidden='true'></i>"],
            ["/attachment/handbook/CMS_Handbook.pdf","Student Handbook","<i class='fa fa-list-ul' aria-hidden='true'></i>"],
            ["/juniorhigh/attachment/dcInfo.PDF","DC Trip","<i class='fa fa-university' aria-hidden='true'></i>"],
            ["/juniorhigh/attachment/7tripPit.PDF","Pittsburgh Trip","<i class='fa fa-map' aria-hidden='true'></i>"],
            ["http://ift.tt/2v1D6jt","Guidance","<i class='fa fa-map' aria-hidden='true'></i>"],
            ["/juniorhigh/honorroll/02-16.html","Honor Roll","<i class='fa fa-bars' aria-hidden='true'></i>"],
            ["/juniorhigh/PrincipalNewsletter.html","Principal's Newsletters","<i class='fa fa-newspaper-o' aria-hidden='true'></i>"],
            ["/attachment/supply/middleSuppyList.pdf","Supply List","<i class='fa fa-newspaper-o' aria-hidden='true'></i>"]             
        ];
        break;

    case "Intermediate":
        $links = [
            ["attachment/newsMar17.pdf","March <br>Newsletter","<i class='fa fa-newspaper-o' aria-hidden='true'></i>"],
            ["attachment/events.pdf","Events","<i class='fa fa-calendar' aria-hidden='true'></i>"],
            ["LRC/index_new.html","Library","<i class='fa fa-book' aria-hidden='true'></i>"],
            ["http://ift.tt/2uGwZyb","Guidance","<i class='fa fa-map' aria-hidden='true'></i>"],
            ["dare/darekg/index.html","D.A.R.E.","<i class='fa fa-child' aria-hidden='true'></i>"],
            ["http://ift.tt/2v1OP1n","Harcourt School","<i class='fa fa-book' aria-hidden='true'></i>"],
            ["http://ift.tt/1bHYQwp","Study Island","<i class='fa fa-tree' aria-hidden='true'></i>"],
            ["video.html","Video Gallery","<i class='fa fa-video-camera' aria-hidden='true'></i>"],
            ["/attachment/handbook/CIS_Handbook.pdf","Student Handbook","<i class='fa fa-list-ul' aria-hidden='true'></i>"],
            ["photoGallery.html","Photo Gallery","<i class='fa fa-photo' aria-hidden='true'></i>"],
            ["http://ift.tt/2v0WRI0","Renaissance <br>Parent Connection","<i class='fa fa-user' aria-hidden='true'></i>"],
            ["/attachment/supply/intermediateSuppyList.pdf","Supply List","<i class='fa fa-pencil' aria-hidden='true'></i>"]            
        ];
        break;

    case "Elementary":
        $links = [
            ["attachments/newsletter/may17.pdf","May <br>Newsletter","<i class='fa fa-newspaper-o' aria-hidden='true'></i>"],
            ["LRC/index_new.html","Library","<i class='fa fa-book' aria-hidden='true'></i>"],
            ["/attachment/handbook/Elementary_Handbook.pdf","Student Handbook","<i class='fa fa-list-ul' aria-hidden='true'></i>"],
            ["http://ift.tt/2v0WRI0","Renaissance <br>Parent Connection","<i class='fa fa-user' aria-hidden='true'></i>"],
            ["/attachment/supply/elementarySuppyList.pdf","Supply List","<i class='fa fa-pencil' aria-hidden='true'></i>"]          
        ];
        break;

    case "Primary":
        $links = [
            ["attachments/apr17.pdf","April <br>Newsletter","<i class='fa fa-newspaper-o' aria-hidden='true'></i>"],
            ["gallery/gallery.html","Photo Gallery","<i class='fa fa-photo' aria-hidden='true'></i>"],
            ["lrc/index_new.html","Library","<i class='fa fa-book' aria-hidden='true'></i>"],
            ["trentoninfo.htm","General Information","<i class='fa fa-info-circle' aria-hidden='true'></i>"],
            ["/attachment/handbook/Primary_Handbook.pdf","Student Handbook","<i class='fa fa-list-ul' aria-hidden='true'></i>"],
            ["/attachment/supply/primarySuppyList.pdf","Supply List","<i class='fa fa-pencil' aria-hidden='true'></i>"],
            ["http://ift.tt/2v0WRI0","Renaissance <br>Parent Connection","<i class='fa fa-user' aria-hidden='true'></i>"]
        ];
        break;

    case "Preschool":
        $links = [
            ["pre/pre.html","Message from the Principal","<i class='fa fa-envelope' aria-hidden='true'></i>"],
            ["FAMILY_HANDBOOK_WEB.pdf","Family Handbook","<i class='fa fa-list-ul' aria-hidden='true'></i>"],
            ["SNACK_12-13.pdf","Snack Calendar","<i class='fa fa-calendar' aria-hidden='true'></i>"],
            ["/attachment/supply/preschoolSuppyList.PDF","Supply List","<i class='fa fa-pencil' aria-hidden='true'></i>"],
            ["History.html","History","<i class='fa fa-clock-o' aria-hidden='true'></i>"],
            ["attachment/2017application.pdf","Preschool Application","<i class='fa fa-file' aria-hidden='true'></i>"],
            ["/district/Wellness/KindImmun.htm","Immunization<br> Information","<i class='fa fa-medkit' aria-hidden='true'></i>"],
            ["LRC_DISTRICT.PDF","LRC Newsletter","<i class='fa fa-book' aria-hidden='true'></i>"],
            ["http://ift.tt/2uGAtB3?","Symbaloo","<i class='fa fa-arrows' aria-hidden='true'></i>"]
        ];
        break;

    default:
        $links = [];
        break;
}
}else{
    $links = [];

}   



?>


<nav id="navRight" class="dispBox">
<h3>Links</h3>
    <ul>
    <?PHP
    if(count($links)!= 0){
        foreach($links as $link){
            $url = $link[0];
            $text = $link[1];
            $icon = $link[2];   
            echo ("<li><a href='$url'>$text$icon</a></li>");        

        //<li><a href="cjhslrc/index_new.html">Library<i class="fa fa-book" aria-hidden="true"></i></a></li>

        }}
    ?>


    </ul>
</nav>
<?PHP ?>

Aucun commentaire:

Enregistrer un commentaire