source: trunk/www/dch/shiftinfo.php@ 19634

Last change on this file since 19634 was 18880, checked in by Daniela Dorner, 7 years ago
fix to avoid errors when used on command line, changes as discussed in telcon
File size: 4.5 KB
Line 
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>
14Who is on shift?
15(from <a href='https://www.fact-project.org/shift'>FACT shift plan<a>
16and <a href='https://www.fact-project.org/logbook/memberlist.php'>FACT logbook<a>)
17
18<?php
19
20//find out if php was started with command-line or on browswer
21//echo php_sapi_name();
22//echo PHP_SAPI;
23if (strcmp(php_sapi_name(), "cli")==0 && $argv)
24{
25 parse_str(implode('&', array_slice($argv, 1)), $_GET);
26 $_SERVER["REMOTE_USER"]="FACT";
27}
28
29if (isset($_GET['date']))
30 $today=date("Ymd", strtotime($_GET["date"]));
31else
32{
33 if (date("H")>8)
34 $today=date("Ymd", mktime(0,0,0,date("m"), date("d"), date("Y")));
35 else
36 $today=date("Ymd",strtotime(date("Y-m-d", mktime(0,0,0,date("m"), date("d"), date("Y")))." -1 day"));
37}
38
39
40function send_email($date, $msg_part)
41{
42 $to = "fact-online@lists.phys.ethz.ch";
43 $subject = $date.": shifter-info missing";
44 $msg = "WARNING: No shifter-info available for ".$date."\n\n";
45 $msg .= $msg_part;
46
47 if (!mail($to, $subject, $msg, 'From:observations@fact-project.org'))
48 echo "Sending warning email failed.<br>\n\n";
49}
50
51function get_userinfo($db, $username)
52{
53 // this is getting exactly one entry from the DB, since we get only
54 // one username, which is unique in the DB.
55 // contactinfo and availability need to be queried as else PHP complains
56 // in the function userinfo_to_string(), but for shifter they can/should be empty
57 $query="SELECT username as login, usertitle as name, email, fid5 as mobile, fid7 as skype, '' as contactinfo, '' as availability
58 FROM logbook.userfields
59 LEFT JOIN logbook.users
60 ON (uid=ufid)
61 WHERE username='".$username."'";
62 $result = $db->query($query);
63 $all = $result->fetch_assoc();
64 $result->free();
65 return $all;
66}
67
68
69function get_expertinfo($db)
70{
71 $query="SELECT username as login, usertitle as name, email, fid5 as mobile, fid7 as skype, fid8 as contactinfo, fid6 as availability
72 FROM logbook.userfields
73 LEFT JOIN logbook.users ON (uid=ufid)
74 LEFT JOIN memberlist.experts
75 ON (ufid=userid)
76 WHERE now() < stop and now() > start";
77 $result = $db->query($query);
78 $all = $result->fetch_all(MYSQLI_ASSOC);
79 $result->free();
80 return $all;
81}
82
83function userinfo_to_string($userinfo)
84{
85 $s = $userinfo['name'] . "[" .$userinfo['login']."]" . ": <br>";
86 if (str_replace(' ', '', $userinfo['contactinfo']))
87 $s .= $userinfo['contactinfo']."<br>";
88 else
89 {
90 $s .= " email:" . $userinfo['email'] . "<br>";
91 $s .= " mobile:" . $userinfo['mobile'] . "<br>";
92 $s .= " skype:" . $userinfo['skype'] . "<br>";
93 }
94 if ((strcmp($_SERVER['REMOTE_USER'], "FACT")==0) && str_replace(' ', '', $userinfo['availability']))
95 $s .= "availability information: <br>".$userinfo['availability']."<br>";
96 return $s;
97}
98
99function send_warning_mail_to_user($userinfo, $today)
100{
101 $msg = "Dear " . $userinfo['name'] . "[".$userinfo['login']."]," ."\n\n";
102 $msg .= "please insert your 'Shifthelper Mobile Phone Number' in ";
103 $msg .= ' https://www.fact-project.org/logbook/usercp.php?action=profile';
104 send_email($today, $msg);
105}
106
107echo "<br> &nbsp;&nbsp;Night: ".$today." (date of sunset) <br>";
108$query="SELECT u FROM calendar.Data WHERE CONCAT(y, LPAD(m+1, 2, 0), LPAD(d,2,0))='".$today."'";
109$query.=" AND NOT x=1 AND u NOT in('ISDC','ETHZ','TUDO','UNIWUE')";
110include ("db.php");
111$db = new mysqli($host, $user, $pw, $database);
112$db->set_charset("utf8");
113$result = $db->query($query);
114$numrows=mysqli_num_rows($result);
115if ($numrows==0)
116 send_email($today, "Whoever is on shift, please insert your name to the shift calendar!\n");
117else
118 echo "&nbsp;&nbsp;Contact Info Shiftcrew: <br>\n ";
119echo "<ul>\n";
120while ($row = $result->fetch_assoc())
121{
122 $userinfo = get_userinfo($db, $row['u']);
123 if ($userinfo['name'])
124 {
125 echo "<li>".userinfo_to_string($userinfo)."</li>\n";
126 if (!$userinfo['mobile'])
127 send_warning_mail_to_user($userinfo, $today);
128 }
129}
130echo "</ul>\n <br>\n <br>\n ";
131$result->free();
132
133echo "Expert-On-Call Contact Info: <br>\n <ul>\n";
134
135foreach (get_expertinfo($db) as $expertinfo)
136{
137 echo "<li>".userinfo_to_string($expertinfo)."</li><br>\n";
138
139}
140echo "</ul>\n";
141?>
142
143</body>
144</html>
Note: See TracBrowser for help on using the repository browser.