Пример #1
0
function addComment($uid, $pid, $comment, $server = FALSE, $testing = FALSE, $important = FALSE)
{
    $purifier = new HTMLPurifier();
    $textComment = strip_tags($comment);
    $cleanComment = $purifier->purify($comment);
    if ($server == TRUE) {
        $typeName = "Server";
    } else {
        if ($testing == TRUE) {
            $typeName = "Testsolver";
        } else {
            $typeName = getCommentTypeName($uid, $pid);
            if ($typeName === NULL) {
                return;
            }
            setFlag($uid, $pid, 0);
        }
    }
    $sql = sprintf("SELECT id FROM comment_type WHERE name='%s'", mysql_real_escape_string($typeName));
    $type = get_element($sql);
    $sql = sprintf("INSERT INTO comments (uid, comment, type, pid) VALUES ('%s', '%s', '%s', '%s')", mysql_real_escape_string($uid), mysql_real_escape_string($cleanComment), mysql_real_escape_string($type), mysql_real_escape_string($pid));
    query_db($sql);
    if ($typeName == "Testsolver") {
        emailComment($uid, $pid, $textComment, TRUE, $important);
    } else {
        emailComment($uid, $pid, $textComment, FALSE, $important);
    }
}
function setDestFlagsToSrcFlags($dest_mbox, $src_mbox, $msg_no)
{
    global $debug;
    if (isFlagSet($src_mbox, $msg_no, "Seen")) {
        if ($debug) {
            print "Seen was set.  Setting on dest server\n";
        }
        if (!setFlag($dest_mbox, $msg_no, "\\Seen")) {
            if ($debug) {
                print "ERROR - Seen Flag not set for message {$msg_no} on dest server\n";
            }
        }
    } else {
        if ($debug) {
            print "Seen was NOT set\n";
        }
    }
    if (isFlagSet($src_mbox, $msg_no, "Answered")) {
        if ($debug) {
            print "Answered was set.  Setting on dest server\n";
        }
        if (!setFlag($dest_mbox, $msg_no, "\\Answered")) {
            if ($debug) {
                print "ERROR - Answered Flag not set for message {$msg_no} on dest server\n";
            }
        }
    } else {
        if ($debug) {
            print "Answered was NOT set\n";
        }
    }
    if (isFlagSet($src_mbox, $msg_no, "Flagged")) {
        if ($debug) {
            print "Flagged was set.  Setting on dest server\n";
        }
        if (!setFlag($dest_mbox, $msg_no, "\\Flagged")) {
            if ($debug) {
                print "ERROR - Flagged Flag not set for message {$msg_no} on dest server\n";
            }
        }
    } else {
        if ($debug) {
            print "Flagged was NOT set\n";
        }
    }
    if (isFlagSet($src_mbox, $msg_no, "Deleted")) {
        if ($debug) {
            print "Deleted was set.  Setting on dest server\n";
        }
        if (!setFlag($dest_mbox, $msg_no, "\\Deleted")) {
            if ($debug) {
                print "ERROR - Deleted Flag not set for message {$msg_no} on dest server\n";
            }
        }
    } else {
        if ($debug) {
            print "Deleted was NOT set\n";
        }
    }
    if (isFlagSet($src_mbox, $msg_no, "Draft")) {
        if ($debug) {
            print "Draft was set.  Setting on dest server\n";
        }
        if (!setFlag($dest_mbox, $msg_no, "\\Draft")) {
            if ($debug) {
                print "ERROR - Draft Flag not set for message {$msg_no} on dest server\n";
            }
        }
    } else {
        if ($debug) {
            print "Draft was NOT set\n";
        }
    }
}
Пример #3
0
 function calculateAttentionScore()
 {
     global $user;
     logit(INFO, "Starting Attention Score Calculator");
     $att = new AttentionAlerts();
     $med = new Meds();
     $user = new User();
     $trends = new UserMetrics();
     //check for flag
     if ($time = getFlag("MetiAttentionRun")) {
         $e = round((time() - $time) / 60, 2);
         //get hours
         if ($e > 360) {
             logit(WARN, "Error: calculateAttentionScore says it's been running for 6 hours " . __FILE__ . " on line: " . __LINE__);
         }
         logit(REPORT, " MetiAttention run aborted because it says it's still running. (Runtime: {$e} minutes, flag: MetiAttentionRun) in " . __FILE__ . " on line: " . __LINE__);
         return false;
     } else {
         setFlag("MetiAttentionRun", time());
     }
     //ok flags are fine let's run this. Round up them doggies
     $sql = "SELECT * FROM users WHERE userType = 1 AND disabled = 0 ";
     if ($rc = dbQuery($sql)) {
         while ($row = dbFetch($rc)) {
             if (CLI_ECHO) {
                 logit(INFO, "uRec: {$row["uRec"]}");
             }
             $uRec = $row["uRec"];
             $user->setUser($uRec);
             $user->getUser();
             //$trends->setUser();
             //$trends->getLatestSurveyCats();
             $this->attentionAggregate = array();
             $this->attentionAggregate["meds"] = 0;
             $this->attentionAggregate["survey"] = 0;
             $this->attentionAggregate["activity"] = 0;
             $this->attentionAggregate["medsAbs"] = 0;
             //remove med related scres
             $sql = "DELETE FROM attentionFlags WHERE uRec = '{$uRec}' AND (type = '{$att->attentionMeds}' OR type = '{$att->attentionMedAbs}') ";
             if ($rctemp = dbQuery($sql)) {
                 //calc med score.
                 $sql = "SELECT * FROM userMedCompliance WHERE uRec = '{$uRec}' AND period = '30' AND days = '30' ";
                 if ($rcMed = dbQuery($sql)) {
                     $med30 = array();
                     $med30Abs = array();
                     while ($rowMed = dbFetch($rcMed)) {
                         $med30[$rowMed["medId"]] = $rowMed["taken"] / $rowMed["doses"];
                         //if patient has reported more than 50% record med compliance
                         if ($rowMed["doses"] and $rowMed["unreported"] / $rowMed["doses"] < 0.5) {
                             $med30Abs[$rowMed["medId"]] = $rowMed["taken"] / $rowMed["doses"];
                         }
                     }
                 } else {
                     logit(WARN, " DB Error:  {$sql} in " . __FILE__ . " on line: " . __LINE__);
                 }
                 //calculate abs med compliance
                 if (is_array($med30) or is_array($med30Abs)) {
                     $med->setUser();
                     $med->getUserMeds(TRUE, FALSE);
                 }
                 if (is_array($med30Abs)) {
                     $temp = array();
                     //let's write flags for each
                     foreach ($med30Abs as $key => $value) {
                         $score = 0;
                         if ($value < 0.8) {
                             if ($value < 0.6) {
                                 $score = 3;
                             } elseif ($value < 0.7) {
                                 $score = 2;
                             } else {
                                 $score = 1;
                             }
                             $temp[] = $score;
                             $in = "";
                             $in["uRec"] = $uRec;
                             $in["ref"] = $key;
                             $in["weight"] = $score;
                             $in["type"] = $att->attentionMedAbs;
                             $in["note"] = $med->userMeds[$key]["medOther"] . " compliance is " . round($value * 100, 0) . "%";
                             $in["expire"] = dbDate("+7 days");
                             $sql = "INSERT INTO attentionFlags " . makeSql($in, "insert");
                             if ($rcTemp = dbQuery($sql)) {
                             } else {
                                 logit(WARN, " DB Error:  {$sql} in " . __FILE__ . " on line: " . __LINE__);
                             }
                         }
                     }
                     //end for
                     //get highest score
                     if (count($temp) > 0) {
                         $this->attentionAggregate["medsAbs"] = max($temp);
                     }
                 }
                 $medAlertList = array();
                 //calculate window trend for med compliance
                 //ok we got all of the 30s now let's get the 7s
                 if (is_array($med30)) {
                     foreach ($med30 as $key => $value) {
                         $sql = "SELECT * FROM userMedCompliance WHERE medId = '{$key}' AND uRec = '{$uRec}' AND period = '7' AND days = '7' ";
                         if ($rcMed = dbQuery($sql)) {
                             while ($rowMed = dbFetch($rcMed)) {
                                 $med7 = $rowMed["taken"] / $rowMed["doses"];
                                 if ($value > 0) {
                                     $d = ($med7 - $value) / $value;
                                     $delta = round($d * 100);
                                 } else {
                                     $delta = 0;
                                 }
                                 //got the delta, now let's calc att score
                                 $medScore = 0;
                                 if (is_numeric($delta) and $delta < -19) {
                                     if ($delta < -60) {
                                         $medScore = 3;
                                     } elseif ($delta < -40) {
                                         $medScore = 2;
                                     } else {
                                         $medScore = 1;
                                     }
                                     $this->attentionAggregate["meds"] = max($this->attentionAggregate["meds"], $medScore);
                                     //save score for this med.
                                     $in = "";
                                     $in["uRec"] = $uRec;
                                     $in["ref"] = $key;
                                     $in["weight"] = $medAlertList[] = $medScore;
                                     $in["type"] = $att->attentionMeds;
                                     $in["note"] = $med->userMeds[$key]["medOther"] . " compliance has declined by " . abs($delta) . "%";
                                     $in["expire"] = dbDate("+7 days");
                                     $sql = "INSERT INTO attentionFlags " . makeSql($in, "insert");
                                     if ($rcTemp = dbQuery($sql)) {
                                     } else {
                                         logit(WARN, " DB Error:  {$sql} in " . __FILE__ . " on line: " . __LINE__);
                                     }
                                 }
                             }
                         } else {
                             logit(WARN, " DB Error:  {$sql} in " . __FILE__ . " on line: " . __LINE__);
                         }
                     }
                     //end med 30 loop
                 }
                 //aggregate meds
                 //if (count($medAlertList) > 0 ) $this->attentionAggregate["meds"] = array_sum($medAlertList) / count($medAlertList);
             } else {
                 logit(WARN, " DB Error:  {$sql} in " . __FILE__ . " on line: " . __LINE__);
             }
             //lookup survey
             $sql = "DELETE FROM attentionFlags WHERE uRec = '{$uRec}' AND type = '{$att->attentionSurvey}' ";
             if ($rctemp = dbQuery($sql)) {
                 $trends->setUser();
                 $s = $trends->getLatestSurveyCats();
                 $delta = $s["min"];
                 $surveyScore = 0;
                 if (is_numeric($delta) and $delta < -11) {
                     if ($delta < -39) {
                         $surveyScore = 3;
                     } elseif ($delta < -19) {
                         $surveyScore = 2;
                     } else {
                         $surveyScore = 1;
                     }
                     $this->attentionAggregate["survey"] = max($this->attentionAggregate["survey"], $surveyScore);
                     //save score
                     $in = "";
                     $in["uRec"] = $uRec;
                     $in["ref"] = 0;
                     $in["weight"] = $surveyScore;
                     $in["type"] = $att->attentionSurvey;
                     $in["note"] = "We\\'ve noticed a drop in some survey answers in the past 30 days.";
                     $in["expire"] = dbDate("+7 days");
                     $sql = "INSERT INTO attentionFlags " . makeSql($in, "insert");
                     if ($rcTemp = dbQuery($sql)) {
                     } else {
                         logit(WARN, " DB Error:  {$sql} in " . __FILE__ . " on line: " . __LINE__);
                     }
                 }
             } else {
                 logit(WARN, " DB Error:  {$sql} in " . __FILE__ . " on line: " . __LINE__);
             }
             //lookup activity
             $sql = "DELETE FROM attentionFlags WHERE uRec = '{$uRec}' AND type = '{$att->attentionActivity}' ";
             if ($rctemp = dbQuery($sql)) {
                 $delta = $row["activityChange"];
                 $activityScore = 0;
                 if (is_numeric($delta) and $delta < -19) {
                     if ($delta < -59) {
                         $activityScore = 3;
                     } elseif ($delta < -39) {
                         $activityScore = 2;
                     } else {
                         $activityScore = 1;
                     }
                     $this->attentionAggregate["activity"] = $activityScore;
                     //save score
                     $in = "";
                     $in["uRec"] = $uRec;
                     $in["ref"] = 0;
                     $in["weight"] = $activityScore;
                     $in["type"] = $att->attentionActivity;
                     $in["note"] = "C3HealthLink interaction has dropped by " . abs($delta) . "% in the past 30 days.";
                     $in["expire"] = dbDate("+7 days");
                     $sql = "INSERT INTO attentionFlags " . makeSql($in, "insert");
                     if ($rcTemp = dbQuery($sql)) {
                     } else {
                         logit(WARN, " DB Error:  {$sql} in " . __FILE__ . " on line: " . __LINE__);
                     }
                 }
             }
             //let's get the other alert scores
             $sqlArr = array();
             $sqlArr["attentionDiaryRank"] = "SELECT MAX(weight) FROM attentionFlags WHERE uRec= {$uRec} AND type = {$att->attentionDiaryRank} ";
             $sqlArr["attentionDiaryKeyword"] = "SELECT MAX(weight) FROM attentionFlags WHERE uRec= {$uRec} AND type = {$att->attentionDiaryKeyword} ";
             $sqlArr["attentionSideEffect"] = "SELECT MAX(weight) FROM attentionFlags WHERE uRec= {$uRec} AND type = {$att->attentionSideEffect} ";
             $sqlArr["attentionMedComment"] = "SELECT MAX(weight) FROM attentionFlags WHERE uRec= {$uRec} AND type = {$att->attentionMedComment} ";
             foreach ($sqlArr as $key => $value) {
                 $this->attentionAggregate[$key] = 0;
                 if ($rcTemp = dbQuery($value)) {
                     if ($rowTemp = dbFetch($rcTemp)) {
                         $t = array_pop($rowTemp);
                         if ($t) {
                             $this->attentionAggregate[$key] = $t;
                         }
                         //logit(INFO,"$key : {$this->attentionAggregate[$key]}");
                     }
                 } else {
                     logit(WARN, " DB Error:  {$sql} in " . __FILE__ . " on line: " . __LINE__);
                 }
             }
             //logit(INFO,"ME: ".print_r($this->attentionAggregate,1));
             //calculate
             /*
             	The max score is 18 but it's very rare anyone will hit max in all six categories so we assume anything above 6 is a red alert
             */
             $attAggTotal = array_sum($this->attentionAggregate);
             if ($attAggTotal > 0 and $attAggTotal < 4) {
                 $attScore = 2;
             } elseif ($attAggTotal > 3 and $attAggTotal < 7) {
                 $attScore = 3;
             } elseif ($attAggTotal > 6) {
                 $attScore = 4;
             } elseif ($user->active) {
                 $attScore = 1;
             } else {
                 $attScore = 0;
             }
             //logit(INFO,"SCORE: $attScore\t MEAN: $attAggMean\tTOTAL: $attAggTotal\tMAX: $attMax");
             //				$sql = "UPDATE users SET attScore = $attScore WHERE uRec = '$uRec' ";
             //				if (!$rcTemp = dbQuery($sql)) logit(WARN,"Error:  in ".__FILE__." on line: ".__LINE__);
         }
         //urec loop
     } else {
         logit(WARN, " DB Error:  {$sql} in " . __FILE__ . " on line: " . __LINE__);
     }
     clearFlag("MetiAttentionRun");
     logit(INFO, "Ending Attention Score Calculator");
     return true;
 }
Пример #4
0
    header("Location: " . URL . "/puzzle.php?pid={$pid}");
    exit(0);
}
if (isset($_POST['killPuzzle'])) {
    $pid = $_POST['pid'];
    changeStatus($uid, $pid, getDeadStatusId());
    header("Location: " . URL . "/puzzle.php?pid={$pid}");
    exit(0);
}
if (isset($_POST['setflag'])) {
    $pid = $_POST['pid'];
    $flag = $_POST['flag'];
    if ($flag) {
        setFlag($uid, $pid, 1);
    } else {
        setFlag($uid, $pid, 0);
    }
    header("Location: " . URL . "/puzzle.php?pid={$pid}");
    exit(0);
}
if (isset($_POST['markunseen'])) {
    $pid = $_POST['pid'];
    markUnseen($uid, $pid);
    header("Location: " . URL);
    exit(0);
}
if (isset($_POST['setUserTestTeam'])) {
    $tid = $_POST['tid'];
    //echo "tid=$tid";
    //echo "<br>uid=$uid";
    setUserTestTeam($uid, $tid);