<?php
$home = getenv('WEB');
require_once($home . '/html/event_bibliography/include/event_header.php');
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <meta http-equiv="content-script-type" content="text/html/javascript" />
        <meta name="viewport" content="user-scalable = yes", content="width=device-width" />
        <title>Event Index</title>
        <link rel="icon" href="/images/favicon.ico" type="image/ico" />
        <link rel="stylesheet" type="text/css" href="/css/iscschema.css" />
        <script type="text/javascript" src="/js/iscsearchfuncs.js"></script>
        <script type="text/javascript" src="https://maps.googleapis.com/maps/api/js?key=AIzaSyDqQ8URr5QcsVL8PMixpJxMjxG8omQwbsc&libraries=drawing"></script>


    </head>
    <body onload="load()">
        <div id="container">

            <?php include("$home/html/include/header.php"); ?>

            <div id="maingeneral">

                <div id="content">
                    <!-- Loading Left Menu -->

                    <?php include("include/leftmenu.php"); ?>

                    <!-- Text area next to leftmenu. -->
                    <div id="rightinner">
                        <div id="title-bib">
                            <h3 align="center"><b>Event Index</b></h3>
                            <hr></hr>


                            <p>Here we list seismic events in the Event Bibliography sorted by event origin time. For older events click on the time windows below. For many relevant events the code, chosen from the scientific literature, is also listed to help users to identify a particular known event. For example, TOHOKU2011 is the code for the great Tohoku earthquake of 11 March, 2011.</p>


                             <div>
                                <table>
                                    <tr>
                                        <td><a href="eventindex.php">2010-<?php echo $yearnow;?>   </a></td>
                                        <td><a href="eventindex0509.php">2005-2009    </a></td>
                                        <td><a href="eventindex0004.php">2000-2004    </a></td>
                                        <td><a href="eventindex9099.php">1990-1999    </a></td>
                                        <td><a href="eventindex8089.php">1980-1989    </a></td>
                                        <td><a href="eventindex7079.php">1970-1979    </a></td>
                                        <td><a href="eventindex6069.php">1960-1969    </a></td>
                                        <td><a href="eventindex0059.php">1900-1959    </a></td>
                                        <!-- Button for Most Studied Events -->
                                        <!--td style="padding-left: 25px"><form method="link" action="moststudied.php"><input type="submit" class="button white medium num" value="Most Studied Events"/></form></td>-->
                                    </tr>
                                </table>
                                 <h3>Results for: 2010 to <?php echo date('Y');?></h3>
                            </div>
                            <p>To search, click on the appropriate ISC event.</p>


                                <p>
                                <table class="sortable">
                                <thead>
                                <tr align="right" style="cursor: pointer !important">
                                    <th><b>ISC event</b></th><td><b>Agency</b></th><th align="center"><b>Origin Time</b></th><th><b>Lat</b></th><th><b>Lon</b></th><th align="right"><b>Depth</b></th><th><b>Magn</b></th><th><b>N</b></th><th><b>Event code</b></th>
                                </tr>

                                </thead>
                                    <?php
                                    $evidall = array();
                                    $query1->execute();
                                    while ($evid = $query1->fetch()) {
                                         array_push($evidall, $evid[0]);
                                    }

                                    foreach ($evidall as $evid) {
                                        # print ("$result1[0] $result1[5] </br>");

                                        $sq = $db_conn->prepare("SELECT h.isc_evid,h.day,h.lat,h.lon,h.grn,e.etype,h.author,h.depth
                                                                       FROM isc.hypocenter h, isc.event e
                                                                      WHERE e.evid = h.isc_evid
                                                                        AND h.hypid = h.pref_hypid
                                                                        AND h.hypid = e.prime_hyp
                                                                        AND e.evid = $evid");
                                        $sq->execute();
                                        $result1 = $sq->fetch();

                                        $sqbibid = $db_conn->prepare("SELECT count(bibid)
                                                                       FROM isc.biblio_event
                                                                 WHERE evid = $evid");
                                        $sqbibid->execute();
                                        $countbib = $sqbibid->fetch();

                                        $sqcode = $db_conn->prepare("SELECT COALESCE(code,'')
                                                                       FROM isc.biblio_event_code
                                                                 WHERE evid = $evid");
                                        $sqcode->execute();
                                        $code = $sqcode->fetch();

                                        $query2 = $db_conn->prepare("SELECT COALESCE(n.author,'UK'),COALESCE(n.magnitude,-9.9),COALESCE(n.magtype,'UK')
                FROM isc.netmag n, isc.hypocenter h
               WHERE h.hypid = h.pref_hypid
                 AND n.hypid = h.hypid
                 AND h.isc_evid = $evid
                 AND ( h.deprecated is NULL OR h.deprecated = 'P' )
                 AND ( n.deprecated is NULL OR n.deprecated = 'M' )
                 AND (n.magtype not like '%tmp' and n.magtype not like '%mx' and n.magtype not like '%1' and upper(n.magtype) not like 'ME%' OR n.magtype is null)
                 AND n.author not in ('ISCJB','EIDC','ISC1','DJA','ERE','BKK','ISCJB')
            ORDER BY (case n.author    when 'GCMT'      then 0
                                       when 'HRVD'      then 1
                                       when 'HRV'       then 2
                                       when 'ISC'       then 3
                                       when 'NEIC'      then 4
                                       when 'NEIS'      then 5
                                       when 'USGS'      then 6
                                       when 'IDC'       then 7
                                       when 'MOS'       then 8
                                       when 'CSEM'      then 9
                                       else 10
                         end) limit 1");

                                        $query2->execute();


                                        $result2 = $query2->fetch();

                                        #if (strlen($result2[1]) == 0) {
                                        #    $result2[1] = "";
                                        #}

                                        #if ($result2[2] == "MW") {
                                        #    $result2[2] = "Mw";
                                        #}
                                        #if ($result2[2] == "MS") {
                                        #    $result2[2] = "Ms";
                                        #}
                                        #if (strlen($result2[0]) == 0) {
                                        #    $result2[0] = "";
                                        #} else {
                                        #    $result2[0] = ("($result2[0]) =");
                                        #}


                                        $result2[1] = number_format($result2[1], 1);
                                        $result1[2] = number_format($result1[2], 2);
                                        $result1[3] = number_format($result1[3], 2);
                                        $result1[7] = number_format($result1[7], 1);


                                        $query3 = $db_conn->prepare("SELECT b.bibid,b.title,COALESCE(journal,series),coalesce(year,9999),coalesce(volume,''),coalesce(issue,''),coalesce(page1,''),coalesce(page2,''),coalesce(doi,'')
    FROM isc.bibliography b, isc.biblio_event e FULL JOIN isc.biblio_event_code c ON e.evid = c.evid
   WHERE e.bibid = b.bibid
     AND c.evid = '$evid'
ORDER BY b.year desc");
                                        $query3->execute();








                                        #

#            1       2     3     4     5     6      7         8
#SELECT h.isc_evid,h.day,h.lat,h.lon,h.grn,e.etype,h.author,h.depth
                                        printf("<tr align=\"right\"><td><a href=\"/cgi-bin/FormatBibprint.pl?evid=$evid\" target=\"_blank\">$result1[0]</a></td><td>$result1[6]</td><td>$result1[1]</td><td>$result1[2]</td><td>$result1[3]</td><td>$result1[7]</td><td>$result2[1]</td><td>$countbib[0]</td><td>$code[0]</td></tr>");
                                    }
                                    ?>
                                </table>
                            </p>




                        </div>
                    </div>
                    <!-- Text below leftmenu --->
                    <div>

                    </div>



                </div>

            </div>
<?php include("$home/html/include/footer.php"); ?>
        </div>
    </body>
</html>
