Ignore:
Timestamp:
12/13/16 06:18:42 (8 years ago)
Author:
dneise
Message:
combine with shifthelper

- make utf8 complliant
- don't use contact info anymore
- break out some functions, less varnames with numbers 1 2 3
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/www/dch/shiftinfo.php

    r18208 r18681  
    1212
    1313<a href='https://www.fact-project.org/smartfact'>Is FACT taking data?</a><br><br>
    14 Who is on shift? 
     14Who is on shift?
    1515(from <a href='https://www.fact-project.org/shift'>FACT shift plan<a>
    1616and <a href='https://www.fact-project.org/logbook/memberlist.php'>FACT logbook<a>)
    1717
    18 <!--#!/usr/bin/php-->
    1918<?php
    2019
     
    3231}
    3332
     33
    3434function send_email($date, $msg_part)
    3535{
    36     //echo "WARNING: no shift crew found -> need to send email.<br>\n";
    3736    $to = "fact-online@lists.phys.ethz.ch";
    38     //$to = "dorner@astro.uni-wuerzburg.de";
    3937    $subject = $date.": shifter-info missing";
    4038    $msg = "WARNING: No shifter-info available for ".$date."\n\n";
     
    4543}
    4644
     45function get_userinfo($db, $username)
     46{
     47    // this is getting exactly one entry from the DB, since we get only
     48    // one username, which is unique in the DB.
     49    $query="SELECT username as login, usertitle as name, email, fid5 as mobile, fid7 as skype
     50        FROM logbook.userfields
     51        LEFT JOIN logbook.users
     52        ON (uid=ufid)
     53        WHERE username='".$username."'";
     54    $result  = $db->query($query);
     55    $all = $result->fetch_assoc();
     56    $result->free();
     57    return $all;
     58}
     59
     60
     61function get_expertinfo($db)
     62{
     63
     64    $query="SELECT username as login, usertitle as name, email, fid5 as mobile, fid7 as skype
     65        FROM logbook.userfields
     66        LEFT JOIN logbook.users ON (uid=ufid)
     67        LEFT JOIN memberlist.experts
     68        ON (ufid=userid)
     69        WHERE now() < stop and now() > start";
     70    $result  = $db->query($query);
     71    $all = $result->fetch_all(MYSQLI_ASSOC);
     72    $result->free();
     73    return $all;
     74}
     75
     76function userinfo_to_string($userinfo){
     77    $s = $userinfo['name'] . "[" .$userinfo['login']."]" . ": <br>";
     78    $s .= "    email:" . $userinfo['email'] . "<br>";
     79    $s .= "    mobile:" . $userinfo['mobile'] . "<br>";
     80    $s .= "    skype:" . $userinfo['skype'] . "<br>";
     81    return $s;
     82}
     83
     84function send_warning_mail_to_user($userinfo){
     85    $msg = "Dear " . $userinfo['name'] . "[".$userinfo['login']."]" ."\n\n";
     86    $msg .= ", please insert your 'Shifthelper Mobile Phone Number' in ";
     87    $msg .= ' https://www.fact-project.org/logbook/usercp.php?action=profile';
     88    send_email($today, $msg);
     89
     90}
    4791
    4892echo "<br> &nbsp;&nbsp;Night: ".$today." (date of sunset) <br>";
    4993$query="SELECT u FROM calendar.Data WHERE CONCAT(y, LPAD(m+1, 2, 0), LPAD(d,2,0))='".$today."'";
    50 //excluding experts and institutes (apart from 'moon')
    5194$query.=" AND NOT x=1 AND u NOT in('ISDC','ETHZ','TUDO','UNIWUE')";
    5295include ("db.php");
    53 $db_id = mysql_connect($host, $user, $pw);
    54 $result  = mysql_query($query);
    55 $numrows=mysql_num_rows($result);
     96$db = new mysqli($host, $user, $pw, $database);
     97$db->set_charset("utf8");
     98$result  = $db->query($query);
     99$numrows=mysqli_num_rows($result);
    56100if ($numrows==0)
    57101    send_email($today, "Whoever is on shift, please insert your name to the shift calendar!\n");
     
    59103    echo "&nbsp;&nbsp;Contact Info Shiftcrew: <br>\n ";
    60104echo "<ul>\n";
    61 while ($row = mysql_fetch_row($result))
     105while ($row = $result->fetch_assoc())
    62106{
    63     $query2="SELECT usertitle, fid8 FROM logbook.userfields LEFT JOIN logbook.users ON (uid=ufid) WHERE username='".$row[0]."'";
    64     $result2  = mysql_query($query2);
    65     while ($row2 = mysql_fetch_row($result2))
    66     {
    67         echo "<li>".$row2[0].": ".$row2[1]."</li>\n";
    68         if (!$row2[1])
    69             send_email($today, "Dear ".$row2[0].", please insert your 'Contact Info' in your logbook user-profile!");
     107   
     108    $userinfo = get_userinfo($db, $row['u']);
     109    if ($userinfo['name']){
     110        echo "<li>".userinfo_to_string($userinfo)."</li>\n";
     111        if (!$userinfo['mobile'])
     112            send_warning_mail_to_user($userinfo);
    70113    }
    71     mysql_free_result($result2);
    72114}
    73115echo "</ul>\n <br>\n <br>\n ";
    74 mysql_free_result($result);
     116$result->free();
    75117
    76118echo "Expert-On-Call Contact Info: <br>\n <ul>\n";
    77 $query3="SELECT usertitle, fid8 FROM logbook.userfields LEFT JOIN logbook.users ON (uid=ufid) LEFT JOIN memberlist.experts ON (ufid=userid) WHERE now() < stop and now() > start";
    78 $result3  = mysql_query($query3);
    79 while ($row3 = mysql_fetch_row($result3))
    80 {
    81     echo "<li>".$row3[0].": ".$row3[1]."</li>\n";
     119
     120foreach (get_expertinfo($db) as $expertinfo) {
     121    echo "<li>".userinfo_to_string($expertinfo)."</li><br>\n";
     122
    82123}
    83 mysql_free_result($result3);
    84124echo "</ul>\n";
    85 
    86 /*
    87 echo "General Contact Info: <br>\n <ul>\n";
    88 $query4="SELECT usertitle, fid8 FROM logbook.userfields LEFT JOIN logbook.users ON (uid=ufid) WHERE username='dorner'";
    89 $result4  = mysql_query($query4);
    90 while ($row4 = mysql_fetch_row($result4))
    91 {
    92     echo "<li>".$row4[0].": ".$row4[1]."</li>\n";
    93 }
    94 mysql_free_result($result4);
    95 echo "</ul>\n";
    96 */
    97 
    98125?>
    99126
Note: See TracChangeset for help on using the changeset viewer.