Example #1
0
 public static function Delete()
 {
     $results = [];
     $test = QueryFactory::Build("delete");
     $test->From("users")->Where(["email", "=", "asd"])->Limit();
     self::testing("Delete");
     $qinfo = DatabaseManager::Query($test);
     self::testQuery($test, true, 1, $qinfo->RowCount());
     $results[count($results)] = $qinfo;
     $qinfo = DatabaseManager::Query($test);
     self::testQuery($test, false, 0, $qinfo->RowCount());
     $results[count($results)] = $qinfo;
     return $results;
 }
Example #2
0
function process($curr)
{
    echo $curr["name"] . ": ";
    echo $curr["frequency"] . "<br>";
    //if need to run task
    if (strtotime($curr["frequency"], $curr["lastRun"]) < time()) {
        //run job
        include __DIR__ . '/' . $curr["name"];
        //update last run time
        $ran = QueryFactory::Build('update');
        $ran->Table("schedule")->Set(["lastRun", time()])->Where(["name", '=', $curr["name"]]);
        $success = DatabaseManager::Query($ran);
        //for testing
        if ($success->RowCount() > 0) {
            echo $curr['name'] . " updated";
        } else {
            echo $curr['name'] . " failed";
        }
    }
}
Example #3
0
 public static function updateElement($id, $column, $value)
 {
     $update = QueryFactory::Build("update");
     //new update query
     $update->Table("users")->Where(["id", "=", $id])->Set([$column, $value]);
     //update the query
     $res = DatabaseManager::Query($update);
     // execute the query
     if ($res->RowCount() == 1) {
         return true;
     }
     return false;
 }
Example #4
0
 public function getDataTableRowCount()
 {
     $query = QueryFactory::Build('select');
     $query->Select('id')->From('enrollment_form');
     $enrolCount = DatabaseManager::Query($query);
     $query = QueryFactory::Build('select');
     $query->Select('id')->From('questionnaire_form');
     $questCount = DatabaseManager::Query($query);
     $query = QueryFactory::Build('select');
     $query->Select('id')->From('parq_form');
     $parqCount = DatabaseManager::Query($query);
     /*
     uncomment when assessments are working and done
     $query = QueryFactory::Build('select');
     $query->Select('id')->From('assessment');
     $enrolCount = DatabaseManager::Query($query);
     */
     // add the value for assessments when they are done
     $value_array = array($enrolCount->RowCount(), $questCount->RowCount(), $parqCount->RowCount());
     return $value_array;
 }
Example #5
0
<?php

$name = basename(__FILE__, ".php");
$table = new CreateTable($name);
$table->AddColumn("id")->SetAutoIncrement();
$table->AddColumn("title")->MakeVarChar(100);
$table->AddColumn("content")->MakeText();
$table->AddColumn("created")->MakeInt();
$table->AddColumn("updated")->MakeInt();
$table->AddColumn("viewby")->MakeTinyInt()->DefaultValue(0);
$info = array();
$insert = QueryFactory::Build("insert");
$info[] = $insert->Into($name)->Set(["title", 'Welcome to Sit and Be Fit "Feel the difference" Project!'], ["content", '<p>Welcome to the Feel the Difference project website. We are reaching' . 'out to adults 55+ and/or those managing chronic conditions with an invitation' . 'to participate in an important research study to determine the effectiveness' . 'of the Sit and Be Fit exercise program</p>' . '<iframe width="100%" height="360" src="https://www.youtube.com/embed/31Ew1ogQqpE" frameborder="0" allowfullscreen></iframe>'], ["created", "UNIX_TIMESTAMP()"], ["viewby", UserLevel::Anon]);
return [$table, $info];
Example #6
0
 private function set($name, $enabled)
 {
     //format string
     $str = $this->formatString();
     //update
     $update = QueryFactory::Build('update');
     $update->Table('settings')->Set(['enabled', $enabled])->Where(['name', '=', $name]);
     if (strlen($str) > 2) {
         $update->Table('settings')->Set(['value', $str]);
     }
     $cinfo = DatabaseManager::Query($update);
     if ($cinfo->RowCount() != 1) {
         return "our servers are having issues please try again later";
     }
     return false;
 }
Example #7
0
             $delete = QueryFactory::Build("delete")->From("users")->Where(["id", "=", $id]);
             $res = DatabaseManager::Query($delete);
             if ($res->RowCount() > 0) {
                 $msg = ["User successfully deleted", 1];
             } else {
                 $msg = ["Error deleting user or user does not exist", 0];
             }
         }
     } else {
         if (isset($_GET['adduser']) && isset($_POST)) {
             $activated = $_POST['activated'] === "1" ? 1 : 0;
             UserModel::Register($_POST['email'], $_POST['pass'], $activated, $_POST['accesslevel']);
         }
     }
 }
 $select = QueryFactory::Build("select")->Select('id', 'email', 'pLevel', 'created', 'activated')->From("users")->Where(['id', '!=', $user->id, "AND"], ['pLevel', '<=', $user->AccessLevel]);
 $res = DatabaseManager::Query($select);
 if ($res->RowCount() < 1) {
     $res = false;
 } else {
     if ($res->RowCount() < 2) {
         $res = [$res->Result()];
     } else {
         $res = $res->Result();
     }
 }
 if ($res) {
     $page .= PartialParser::Parse('div', ["classes" => "header", "content" => "Registered Users"]);
     $header = createHeader(array_merge(["Edit"], array_keys($res[0]), [""]));
 }
 $formElements = "";
Example #8
0
function deactivate($id)
{
    $update = QueryFactory::Build('update');
    $update->Table('users')->Set(['activated', -1])->Where(['id', '=', $id]);
    $temp = DatabaseManager::Query($update);
    if ($temp->RowCount() == 1) {
        echo "deactivated " . $id;
    } else {
        echo "failed to deactivate " . $id;
    }
}
Example #9
0
          [^\\w\\s-]       # but char before ID is non-ID char.
        )                 # End host alternatives.
        ([\\w-]{11})      # $1: VIDEO_ID is exactly 11 chars.
        (?=[^\\w-]|$)     # Assert next char is non-ID or EOS.
        (?!               # Assert URL is not pre-linked.
          [?=&+%\\w.-]*    # Allow URL (query) remainder.
          (?:             # Group pre-linked alternatives.
            [\'"][^<>]*>  # Either inside a start tag,
          | </a>          # or inside <a> element text contents.
          )               # End recognized pre-linked alts.
        )                 # End negative lookahead assertion.
        [?=&+%\\w.-]*        # Consume any URL (query) remainder.
        ~ix', $text, $result);
    return $result[1];
}
$select = QueryFactory::Build("select")->Select("id", "title", "content", "created", "viewby")->From("articles");
$info = DatabaseManager::Query($select);
$articles = $info->Result();
// Result returns the result directly if there is only one result
// This compensates for that by wrapping the single result in an array, like multiple articles would be
// This allows for a simpler code base
if ($info->RowCount() < 2) {
    $articles = [$articles];
}
?>
<script>
    var youtubeLinkRegex = /^.*((youtu.be\/)|(v\/)|(\/u\/\w\/)|(embed\/)|(watch\?))\??v?=?([^#\&\?]*).*/;
    $(document).ready(function(){
        var editors = 0;
        var articles = $("#articlesList");
        articles.on('click', '#edit', function (e) {
Example #10
0
 public static function isQuestionnaireComplete($id)
 {
     $select = QueryFactory::Build("select");
     $select->Select('completed')->Table('questionnaire_form')->Where(['userID', '=', $id])->Limit();
     $res = DatabaseManager::Query($select);
     $resultArray = $res->Result();
     if ($res->RowCount() == 1) {
         return $res;
     }
     return false;
 }
Example #11
0
<?php

$name = "settings";
$table = new CreateTable($name);
//$table->AddColumn('id')->SetAutoIncrement();
$table->AddColumn('name')->MakeVarChar(100)->AddKey('unique');
$table->AddColumn('value')->MakeVarchar(100);
// +1 day or something like that
$table->AddColumn('enabled')->MakeBool()->DefaultValue('true');
$population = array();
$population[] = QueryFactory::Build("insert")->Into($name)->Set(["name", "forgotpassword"], ["value", "+ 50 seconds"], ["enabled", 1]);
$population[] = QueryFactory::Build("insert")->Into($name)->Set(["name", "ttl_activation"], ["value", "+1 day"]);
$population[] = QueryFactory::Build("insert")->Into($name)->Set(["name", "ttl_form"], ["value", "+1 month"]);
$population[] = QueryFactory::Build("insert")->Into($name)->Set(["name", "ttl_assessment_choice"], ["value", "+2 week"]);
$population[] = QueryFactory::Build("insert")->Into($name)->Set(["name", "ttl_assessment_complete"], ["value", "+1 month"]);
$population[] = QueryFactory::Build("insert")->Into($name)->Set(["name", "ttl_assessment_frequency"], ["value", "+3 month"]);
return [$table, $population];
Example #12
0
 private function validate($insert)
 {
     $p = $this->data;
     $insert->Set(["userID", $p['userID']]);
     if (isset($p['ArmCurl'])) {
         $insert->Set(['Armcurl', -1]);
     }
     if (isset($p['ChairStand'])) {
         $insert->Set(['Chairstand', -1]);
     }
     if (isset($p['Steptest'])) {
         $insert->Set(['StepTest', -1]);
     }
     if (isset($p['FootUpandGo'])) {
         $insert->Set(['FootUpAndGo', -1]);
     }
     if (isset($p['Unilateral'])) {
         $insert->Set(['leftunilateralbalancetest', -1]);
         $insert->Set(['rightunilateralbalancetest', -1]);
     }
     if (isset($p['Functional'])) {
         $insert->Set(['FunctionalReach', -1]);
     }
     if (isset($p['Functional']) || isset($p['Unilateral']) || isset($p['FootUpandGo']) || isset($p['Steptest']) || isset($p['ChairStand']) || isset($p['ArmCurl'])) {
         $date = QueryFactory::Build('update');
         $date->Table("users");
         $date->Set(['NextAssessment', "UNIX_TIMESTAMP()"]);
         $date->Where(["id", "=", $p["userID"]]);
         $s = DatabaseManager::Query($date);
         return $insert;
     } else {
         ?>
             <script>alert("Please select at least one assessment.");</script><?php 
     }
 }
Example #13
0
<?php

$name = basename(__FILE__, ".php");
$table = new CreateTable($name);
$table->AddColumn('id')->SetAutoIncrement();
$table->AddColumn('name')->MakeVarChar(20)->AddKey('unique');
$table->AddColumn('page')->MakeVarChar(30)->DefaultValue("index.php");
$table->AddColumn('pLevel')->MakeInt();
$populate = array();
$populate[] = QueryFactory::Build("insert")->Into($name)->Set(["name", "Home"], ["page", "index.php"]);
$populate[] = QueryFactory::Build("insert")->Into($name)->Set(["name", "About"], ["page", "about.php"]);
$populate[] = QueryFactory::Build("insert")->Into($name)->Set(["name", "Contact"], ["page", "contact.php"]);
$populate[] = QueryFactory::Build("insert")->Into($name)->Set(["name", "FAQ"], ["page", "faq.php"]);
$populate[] = QueryFactory::Build("insert")->Into($name)->Set(["name", "Assessments"], ["page", "assessments.php"]);
$populate[] = QueryFactory::Build("insert")->Into($name)->Set(["name", "Register"], ["page", "register.php"]);
$populate[] = QueryFactory::Build("insert")->Into($name)->Set(["name", "Profile"], ["page", "profile.php"], ["pLevel", 1]);
$populate[] = QueryFactory::Build("insert")->Into($name)->Set(["name", "ParQ Form"], ["page", "parQ.php"], ["pLevel", 1]);
$populate[] = QueryFactory::Build("insert")->Into($name)->Set(["name", "Logout"], ["page", "logout.php"], ["pLevel", 1]);
return [$table, $populate];
Example #14
0
            $res = DatabaseManager::Query($userQuery)->Result();
            $id = $res["id"];
            $salt = $res["salt"];
            $saltTime = $res["salt_time"];
            //if current time is greater then last salt ( When the link was created )
            // *************** BIG NOTE!!! change this update to 1 day before deploy!!! ( IN SETTINGS TABLE!!!! )
            if ($saltTime < time()) {
                // READ FROM SETTINGS TABLE TO GRAB THE SALT_TIME AND PLUG IT IN BELOW
                $select = QueryFactory::Build("select");
                $select->Select("value")->From("settings")->Where(["name", "=", "forgotpassword"])->Limit();
                $lifeTime = DatabaseManager::Query($select)->Result()['value'];
                //print_r($select->Query(true));
                //update salt and salt_time
                $salt = bin2hex(mcrypt_create_iv(22, MCRYPT_DEV_URANDOM));
                // this will generate a new salt every time if exceed 24 hrs
                $update = QueryFactory::Build("update");
                $update->Table("users")->Where(["id", "=", $id])->Set(["salt", $salt], ["salt_time", strtotime("{$lifeTime}")]);
                //update the salt and add a certain time to last salt CHANGE TO VARIABLE
                $resUpdate = DatabaseManager::Query($update);
                // execute the query
                $link = sha1($id . $salt);
            } else {
                $link = sha1($id . $salt);
            }
            Mailer::Send("{$email}", "Reset Password", "Please click on the link below to change your password, http://{$server}/resetPassword.php?id={$id}&link={$link}");
            $msg = ["Please check your email for reset password link", 1];
        }
    }
    // ******************************** FORM ENFORCEMENT REGKEY !!! *************************************************8
}
?>
Example #15
0
         // ************************************************* this block is google's recaptcha *************************************************************************
         //*********************************************** THIS IS FROM GOOGLE RECAPTCHA API ***********************************************************************
         $secret = "6LejtgYTAAAAAMlSC70hXViKkntfBVU2PBdICylx";
         // this is a secret code for reCaptcha connection
         $ip = gethostbyname($_SERVER['SERVER_NAME']);
         // this is how you grab end user's ip
         $captcha = $_POST['g-recaptcha-response'];
         $response = file_get_contents("https://www.google.com/recaptcha/api/siteverify?secret={$secret}&response={$captcha}&remoteip={$ip}");
         $captchaResult = json_decode($response, true);
         //******************************************************************************************************************************************************************************
         if ($captchaResult['success']) {
             $id = UserModel::Register($email, $password);
             // Call to Register function in UserModel, returns true if register is a success
             if ($id) {
                 //*****************   SEND ACTIVATION EMAIL ********************************
                 $userQuery = QueryFactory::Build("select");
                 $userQuery->Select("email", "created")->From("users")->Where(["id", "=", $id])->Limit();
                 $res = DatabaseManager::Query($userQuery);
                 $res = $res->Result();
                 // get result from table
                 $link = sha1($id . $res["email"] . $res["created"]);
                 // get the hash value for the link to send out
                 Mailer::Send("{$email}", "Activation Email", "Please click on the link below to activate your account, http://{$server}/activation.php?id={$id}&link={$link}");
                 $msg = ["Registration successful, please check your email for account activation", 1];
                 unset($_POST);
             }
         } else {
             $msg = ["You are not a human, registration denied! <br>", 0];
         }
     }
 }
Example #16
0
<?php

$name = "schedule";
$table = new CreateTable($name);
$table->AddColumn('id')->SetAutoIncrement();
$table->AddColumn('name')->MakeVarChar(100)->AddKey('unique');
$table->AddColumn('frequency')->MakeVarChar(100);
$table->AddColumn('lastRun')->MakeInt();
$population = array();
$population[] = QueryFactory::Build("insert")->Into($name)->Set(["name", "manageUsers.php"], ["frequency", "+1 minute"], ["lastRun", "UNIX_TIMESTAMP()"]);
$population[] = QueryFactory::Build("insert")->Into($name)->Set(["name", "test.php"], ["frequency", "+3 months"], ["lastRun", "UNIX_TIMESTAMP()"]);
//$population[] = QueryFactory::Build("insert")->Into($name)->Set(["name", "activationTimer.php"], ["frequency", "+12 hours"], ["lastRun", "UNIX_TIMESTAMP()"]);
return [$table, $population];
Example #17
0
<?php

$name = "forgotPasswordTimeout";
$table = new CreateTable($name);
$table->AddColumn('id')->SetAutoIncrement();
$table->AddColumn('creationTime')->MakeVarChar(100);
$table->AddColumn('hash')->MakeVarChar(100)->AddKey('unique');
$population = array();
$population[] = QueryFactory::Build("insert")->Into($name)->Set(["id", "0"], ["creationTime", "0"], ["hash", "0"]);
return [$table, $population];
Example #18
0
<?php

$name = "users";
$table = new CreateTable($name);
$table->AddColumn('id')->SetAutoIncrement();
$table->AddColumn('email')->MakeVarChar(100)->AddKey('unique');
$table->AddColumn('password')->MakeVarChar(100);
$table->AddColumn('pLevel')->MakeInt()->DefaultValue('1');
$table->AddColumn('created')->MakeInt();
$table->AddColumn('NextAssessment')->MakeInt()->DefaultValue(0);
$table->AddColumn('activated')->MakeBool()->DefaultValue('false');
$table->AddColumn('salt')->MakeVarChar(100)->DefaultValue(bin2hex(mcrypt_create_iv(22, MCRYPT_DEV_URANDOM)));
$table->AddColumn('salt_time')->MakeInt()->DefaultValue(0);
$population = array();
$population[] = QueryFactory::Build("insert")->Into($name)->Set(["email", "*****@*****.**"], ["password", "\$2y\$11\$593EkWGKJ.1dkCN/ivW1OOOf180ijPxRPyaUr7w79fWFJmQUNietK"], ["created", "UNIX_TIMESTAMP()"], ["pLevel", 3], ["activated", 1]);
return [$table, $population];
Example #19
0
$array = ["Chairstand" => ["30 Second Chair Stand", "Lower body strength evaluation. Assess strength for climbing stairs, walking, and getting out of a chair, car, or tub. Number of full stands that can be completed in 30 seconds with arms folded across chest. If the arms are pulled away from the chest or you rock back and forward to help you stand that is unacceptable and the test will be stopped at that point. You may rest while siting on the chair and continue if you are still within the 30 seconds.", "ChairStand", "m0APvLqZr5E"], "ArmCurl" => ["Arm Curl", "Assess upper body strength, needed for performing household and other activities involving lifting and carrying things such as groceries, suitcases and grandchildren. Number of bicep curls – lifting the weight from the arm extended up to the shoulder and back down – that can be completed in 30 seconds holding a 5 lb weight (for women) or an 8 lb weight (for men). You may not use the back to help “throw” the weight up. The weight must come up and touch the shoulder and the return to the lowered position should be with control, not just dropping the arm. You may rest in the down position and continue with lifts if you are still within the 30 seconds.", "ArmCurl", "m0APvLqZr5E"], "StepTest" => ["2-Minute Step Test", "Aerobic endurance test. Number of full steps completed in 2 minutes, raising the knee to a point halfway between the kneecap and the hip on each step. If the knee does not come up high enough you will be reminded to lift it higher. If you are testing yourself at home stand in front of a mirror so you can assess the knee height.", "Steptest", "m0APvLqZr5E"], "FootUpAndGo" => ["8 Foot Up and Go", "Assess agility and dynamic balance needed for quick maneuvering such as getting on or off a bus, getting up to attend to something in the kitchen, going to the bathroom, or getting up to answer the phone. Number of seconds it takes to get up out of a chair, walk 8 feet, turn around a cone, and return to the chair and sit down. The entire movement must be in control. You may use your hands to help get up from the chair and to sit back down.", "FootUpandGo", "m0APvLqZr5E"], "unilateralbalancetest" => ["Unilateral Balance Test", "Fall risk evaluation.  Balance test determined by how long you can stand on one foot without moving, or touching the lifted foot back to the ground.  The lifted leg may not be braced against the support leg, lift the lower leg up and to the rear till the knee is at 90 degrees. Not acceptable is excessive movement of arms or body to hold position", "Unilateral", "m0APvLqZr5E"], "FunctionalReach" => ["Functional Reach", "Assess balance in a forward motion. Reach as far forward as you can keep your arm parallel to the yardstick without touching the wall or taking a step forward. Do not overreach and risk falling.", "Functional", "m0APvLqZr5E"]];
?>
<div class="background">
<!-- Accordion -->
    
<?php 
$find = QueryFactory::Build('select');
$find->Select("Chairstand", "ArmCurl", "StepTest", "FootUpAndGo", "leftunilateralbalancetest", "rightunilateralbalancetest", "FunctionalReach")->From('assessments')->Where(['userID', '=', $user->id, "AND"], ['DateCompleted', '=', 0]);
$find->Limit();
$res = DatabaseManager::Query($find);
$result = $res->Result();
$left = $result["leftunilateralbalancetest"];
$right = $result["rightunilateralbalancetest"];
$result["unilateralbalancetest"] = [$left, $right];
unset($result["leftunilateralbalancetest"], $result["rightunilateralbalancetest"]);
$time = QueryFactory::Build('select');
$time->Select("NextAssessment")->From("users")->Where(["id", "=", $user->id])->limit();
$time = DatabaseManager::Query($time);
$time = $time->Result()["NextAssessment"];
//echo $time;
?>


    <h1 class="demoHeaders">Assessments</h1>
	 <?php 
//show next assessment date
if ($time > 0 && $time > time()) {
    echo "<h2>next assessment on " . date("F d, Y", $time) . "</h2>";
}
?>
 
Example #20
0
<?php

require_once "header.php";
$msg = "";
$id = Validator::instance()->sanitize("int", $_GET['id']);
//get the ID from the link to prevent people from inserting their own ID
// ****************************** Activate the user by ID ***********************************************************************
$select = QueryFactory::Build("select");
$select->Select("id", "email", "created", "activated")->From("users")->Where(["id", "=", $id])->Limit();
$res = DatabaseManager::Query($select);
$res = $res->Result();
if ($res["activated"] === 1) {
    $msg = ["Your account is already activated!", 1];
}
$userActivationHash = sha1($res["id"] . $res["email"] . $res["created"]);
// get user hash from database to compare against the link
if ($userActivationHash === $_GET['link']) {
    if (UserModel::updateElement($res["id"], "activated", "1")) {
        // if acctivation is a success
        $msg = ["Account activation successful!", 1];
    } else {
        $msg = ["Your account is already activated!", 0];
    }
} else {
    $msg = ["Invalid link, please try again!", 0];
}
?>


<div class="background">
	<h2><center> Activation </center></h2>
Example #21
0
<?php

//---------------------------------
//path to cronJobs file
$path = "cronJobs/";
//path to config and sessions
chdir('..');
//needed to use models
require_once "config.php";
require_once "sessions.php";
//----------------------------------------
$select = QueryFactory::Build("select");
// get all rows to users table
$select->Select("id", "email", "created", "password", "pLevel", "activated")->From("users");
// Get the results from the query execution
$res = DatabaseManager::Query($select);
if ($res->RowCount() > 1) {
    $res = $res->Result();
    foreach ($res as $row) {
        //if not admin                                get from settings?
        if (!$row["activated"] && time() > strtotime("+1 days", $row["created"])) {
            //delete user
            $del = QueryFactory::Build("delete");
            $del->Table("users")->Where(["id", "=", $row["id"]]);
            $deleted = DatabaseManager::Query($del);
        }
    }
}