| 1 | <html>
|
|---|
| 2 | <head>
|
|---|
| 3 | <meta name="Author" content="The FACT Group" />
|
|---|
| 4 | <meta http-equiv="content-type" content="text/html; charset=utf-8" />
|
|---|
| 5 | <title>FACT Contact Info</title>
|
|---|
| 6 | <link rel="StyleSheet" type="text/css" href="../style.css" />
|
|---|
| 7 | </head>
|
|---|
| 8 |
|
|---|
| 9 |
|
|---|
| 10 | <body>
|
|---|
| 11 |
|
|---|
| 12 |
|
|---|
| 13 | <a href='https://www.fact-project.org/smartfact'>Is FACT taking data?</a><br><br>
|
|---|
| 14 | Who is on shift?
|
|---|
| 15 | (from <a href='https://www.fact-project.org/shift'>FACT shift plan<a>
|
|---|
| 16 | and <a href='https://www.fact-project.org/logbook/memberlist.php'>FACT logbook<a>)<br>
|
|---|
| 17 | <?php
|
|---|
| 18 |
|
|---|
| 19 | //find out if php was started with command-line or on browswer
|
|---|
| 20 | //echo php_sapi_name();
|
|---|
| 21 | //echo PHP_SAPI;
|
|---|
| 22 | if (strcmp(php_sapi_name(), "cli")==0 && $argv)
|
|---|
| 23 | {
|
|---|
| 24 | parse_str(implode('&', array_slice($argv, 1)), $_GET);
|
|---|
| 25 | $_SERVER["REMOTE_USER"]="FACT";
|
|---|
| 26 | }
|
|---|
| 27 |
|
|---|
| 28 | if (isset($_GET['date']))
|
|---|
| 29 | $today=date("Ymd", strtotime($_GET["date"]));
|
|---|
| 30 | else
|
|---|
| 31 | {
|
|---|
| 32 | if (date("H")>8)
|
|---|
| 33 | $today=date("Ymd", mktime(0,0,0,date("m"), date("d"), date("Y")));
|
|---|
| 34 | else
|
|---|
| 35 | $today=date("Ymd",strtotime(date("Y-m-d", mktime(0,0,0,date("m"), date("d"), date("Y")))." -1 day"));
|
|---|
| 36 | }
|
|---|
| 37 |
|
|---|
| 38 |
|
|---|
| 39 | function send_email($date, $msg_part)
|
|---|
| 40 | {
|
|---|
| 41 | $to = "fact-online@lists.phys.ethz.ch";
|
|---|
| 42 | $subject = $date.": shifter-info missing";
|
|---|
| 43 | $msg = "WARNING: No shifter-info available for ".$date."\n\n";
|
|---|
| 44 | $msg .= $msg_part;
|
|---|
| 45 |
|
|---|
| 46 | if (!mail($to, $subject, $msg, 'From:observations@fact-project.org'))
|
|---|
| 47 | echo "Sending warning email failed.<br>\n\n";
|
|---|
| 48 | }
|
|---|
| 49 |
|
|---|
| 50 | function get_userinfo($db, $username)
|
|---|
| 51 | {
|
|---|
| 52 | // this is getting exactly one entry from the DB, since we get only
|
|---|
| 53 | // one username, which is unique in the DB.
|
|---|
| 54 | // contactinfo and availability need to be queried as else PHP complains
|
|---|
| 55 | // in the function userinfo_to_string(), but for shifter they can/should be empty
|
|---|
| 56 | $query="SELECT username as login, usertitle as name, email, fid5 as mobile, fid7 as skype, '' as contactinfo, '' as availability
|
|---|
| 57 | FROM logbook.userfields
|
|---|
| 58 | LEFT JOIN logbook.users
|
|---|
| 59 | ON (uid=ufid)
|
|---|
| 60 | WHERE username='".$username."'";
|
|---|
| 61 | $result = $db->query($query);
|
|---|
| 62 | $all = $result->fetch_assoc();
|
|---|
| 63 | $result->free();
|
|---|
| 64 | return $all;
|
|---|
| 65 | }
|
|---|
| 66 |
|
|---|
| 67 |
|
|---|
| 68 | function get_expertinfo($db, $type)
|
|---|
| 69 | {
|
|---|
| 70 | $query="SELECT username as login, usertitle as name, email, fid5 as mobile, fid7 as skype, fid8 as contactinfo, fid6 as availability
|
|---|
| 71 | FROM logbook.userfields
|
|---|
| 72 | LEFT JOIN logbook.users ON (uid=ufid)
|
|---|
| 73 | LEFT JOIN memberlist.experts
|
|---|
| 74 | ON (ufid=userid)
|
|---|
| 75 | WHERE now() < stop and now() > start AND not isnull (".$type.")";
|
|---|
| 76 | $result = $db->query($query);
|
|---|
| 77 | $all = $result->fetch_all(MYSQLI_ASSOC);
|
|---|
| 78 | $result->free();
|
|---|
| 79 | return $all;
|
|---|
| 80 | }
|
|---|
| 81 |
|
|---|
| 82 | function userinfo_to_string($userinfo)
|
|---|
| 83 | {
|
|---|
| 84 | $s = $userinfo['name'] . "[" .$userinfo['login']."]" . ": <br>";
|
|---|
| 85 | if (str_replace(' ', '', $userinfo['contactinfo']))
|
|---|
| 86 | $s .= $userinfo['contactinfo']."<br>";
|
|---|
| 87 | else
|
|---|
| 88 | {
|
|---|
| 89 | $s .= " email:" . $userinfo['email'] . "<br>";
|
|---|
| 90 | $s .= " mobile:" . $userinfo['mobile'] . "<br>";
|
|---|
| 91 | $s .= " skype:" . $userinfo['skype'] . "<br>";
|
|---|
| 92 | }
|
|---|
| 93 | if ((strcmp($_SERVER['REMOTE_USER'], "FACT")==0) && str_replace(' ', '', $userinfo['availability']))
|
|---|
| 94 | $s .= "availability information: <br>".$userinfo['availability']."<br>";
|
|---|
| 95 | return $s;
|
|---|
| 96 | }
|
|---|
| 97 |
|
|---|
| 98 | function send_warning_mail_to_user($userinfo, $today)
|
|---|
| 99 | {
|
|---|
| 100 | $msg = "Dear " . $userinfo['name'] . "[".$userinfo['login']."]," ."\n\n";
|
|---|
| 101 | $msg .= "please insert your 'Shifthelper Mobile Phone Number' in ";
|
|---|
| 102 | $msg .= ' https://www.fact-project.org/logbook/usercp.php?action=profile';
|
|---|
| 103 | send_email($today, $msg);
|
|---|
| 104 | }
|
|---|
| 105 |
|
|---|
| 106 | echo "<br> Night: ".$today." (date of sunset) <br>";
|
|---|
| 107 | $query="SELECT u FROM calendar.Data WHERE CONCAT(y, LPAD(m+1, 2, 0), LPAD(d,2,0))='".$today."'";
|
|---|
| 108 | $query.=" AND NOT x=1 AND u NOT in('ISDC','ETHZ','TUDO','UNIWUE')";
|
|---|
| 109 | include ("db.php");
|
|---|
| 110 | $db = new mysqli($host, $user, $pw, $database);
|
|---|
| 111 | $db->set_charset("utf8");
|
|---|
| 112 | $result = $db->query($query);
|
|---|
| 113 | $numrows=mysqli_num_rows($result);
|
|---|
| 114 | if ($numrows==0)
|
|---|
| 115 | send_email($today, "Whoever is on shift, please insert your name to the shift calendar!\n");
|
|---|
| 116 | else
|
|---|
| 117 | echo " Contact Info Shiftcrew: <br>\n ";
|
|---|
| 118 | echo "<ul>\n";
|
|---|
| 119 | while ($row = $result->fetch_assoc())
|
|---|
| 120 | {
|
|---|
| 121 | $userinfo = get_userinfo($db, $row['u']);
|
|---|
| 122 | if ($userinfo['name'])
|
|---|
| 123 | {
|
|---|
| 124 | echo "<li>".userinfo_to_string($userinfo)."</li>\n";
|
|---|
| 125 | if (!$userinfo['mobile'])
|
|---|
| 126 | send_warning_mail_to_user($userinfo, $today);
|
|---|
| 127 | }
|
|---|
| 128 | }
|
|---|
| 129 | echo "</ul>\n <br>\n";
|
|---|
| 130 | $result->free();
|
|---|
| 131 |
|
|---|
| 132 | echo "Remark for MAGIC shifters: please keep in mind that FACT shifters and experts will \n ";
|
|---|
| 133 | echo "usually be asleep during the night, so that messages on skype or by email might stay \n ";
|
|---|
| 134 | echo "unnoticed until the next morning.<br>\n <br>\n ";
|
|---|
| 135 |
|
|---|
| 136 |
|
|---|
| 137 | echo "Expert-On-Call Contact Info: <br>\n <ul>\n";
|
|---|
| 138 |
|
|---|
| 139 | foreach (get_expertinfo($db, "expert") as $expertinfo)
|
|---|
| 140 | {
|
|---|
| 141 | echo "<li>".userinfo_to_string($expertinfo)."</li><br>\n";
|
|---|
| 142 |
|
|---|
| 143 | }
|
|---|
| 144 | echo "</ul>\n";
|
|---|
| 145 |
|
|---|
| 146 | echo "Flare-Expert-On-Call Contact Info: <br>\n <ul>\n";
|
|---|
| 147 |
|
|---|
| 148 | foreach (get_expertinfo($db, "flare") as $expertinfo)
|
|---|
| 149 | {
|
|---|
| 150 | echo "<li>".userinfo_to_string($expertinfo)."</li><br>\n";
|
|---|
| 151 |
|
|---|
| 152 | }
|
|---|
| 153 | echo "</ul>\n";
|
|---|
| 154 |
|
|---|
| 155 | echo "SH-Expert-On-Call Contact Info: <br>\n <ul>\n";
|
|---|
| 156 |
|
|---|
| 157 | foreach (get_expertinfo($db, "sh") as $expertinfo)
|
|---|
| 158 | {
|
|---|
| 159 | echo "<li>".userinfo_to_string($expertinfo)."</li><br>\n";
|
|---|
| 160 |
|
|---|
| 161 | }
|
|---|
| 162 | echo "</ul>\n";
|
|---|
| 163 |
|
|---|
| 164 | echo "Fallback-Shifter Contact Info: <br>\n <ul>\n";
|
|---|
| 165 |
|
|---|
| 166 | foreach (get_expertinfo($db, "fallback") as $expertinfo)
|
|---|
| 167 | {
|
|---|
| 168 | echo "<li>".userinfo_to_string($expertinfo)."</li><br>\n";
|
|---|
| 169 |
|
|---|
| 170 | }
|
|---|
| 171 | echo "</ul>\n";
|
|---|
| 172 | ?>
|
|---|
| 173 |
|
|---|
| 174 | </body>
|
|---|
| 175 | </html>
|
|---|