Esempio n. 1
0
 public function toArray() : array
 {
     $arr = get_object_vars($this);
     foreach ($arr as $key => $value) {
         if (Utility::charAt($key, 0) == '_') {
             unset($arr[$key]);
         }
     }
     return $arr;
 }
Esempio n. 2
0
 public function main()
 {
     $name = Utility::cleanString($_POST["name"]);
     $notes = Utility::cleanString($_POST["notes"]);
     $is_chapter = Utility::cleanBoolean($_POST["is_chapter"]);
     $all_day_event = !$is_chapter && Utility::cleanBoolean($_POST["is_all_day"]);
     $start = Utility::getDateTimeFromDateYmdHis(Utility::cleanString($_POST["time_start"]));
     $end = Utility::getDateTimeFromDateYmdHis(Utility::cleanString($_POST["time_end"]));
     $is_repeating = !$is_chapter && Utility::cleanBoolean($_POST["is_repeating"]);
     $n_times = Utility::cleanInt($_POST["n_times"], 2);
     $repeat_type = Utility::cleanInt($_POST["repeat_type"], Group::TYPE_DAYS, Group::TYPE_YEARS);
     if ($name == "") {
         $this->setError(self::$E_INVALID_NAME);
     } else {
         if (!$all_day_event && !$start) {
             $this->setError(self::$E_INVALID_DATE_START);
         } else {
             if (!$all_day_event && !$is_chapter && !$end) {
                 $this->setError(self::$E_INVALID_DATE_END);
             } else {
                 if (!$all_day_event && $end <= $start) {
                     $this->setError(self::$E_INVALID_DATE_END_BEFORE_START);
                 } else {
                     if ($is_repeating) {
                         if ($n_times === false) {
                             $this->setError(self::$E_INVALID_REPEAT_TIME);
                         } else {
                             if ($repeat_type === false) {
                                 $this->setError(self::$E_INVALID_REPEAT_TYPE);
                             }
                         }
                     }
                 }
             }
         }
     }
     if ($this->hasError()) {
         return [];
     }
     $_events = [];
     if ($all_day_event) {
         $start = $start ?: null;
         $end = $end ?: null;
     }
     if (!$is_repeating) {
         $_event = new Event($this->_pdo);
         $_event->create($name, $notes, $all_day_event, $is_chapter, $this->_auth->getUser(), $end, $start);
         $_events[] = $_event;
     } else {
         $_group = new Group($this->_pdo);
         $_group->create($name, $notes, $all_day_event, $is_chapter, $n_times, $this->_auth->getUser(), $repeat_type, $start, $end);
         $_events = $_group->generateEvents();
     }
     return $_events;
 }
Esempio n. 3
0
 public function startWorker()
 {
     $this->_queue->watch($this->tube);
     $this->_pdo->disconnect();
     while ($job = $this->_queue->reserve()) {
         $this->_pdo->connect();
         $data = json_decode($job->getData(), true);
         $this->performActions($data);
         unset($data);
         $this->_queue->delete($job);
         $this->_pdo->disconnect();
         if (Utility::isDevServer()) {
             exit;
         }
     }
 }
Esempio n. 4
0
<?php

require_once __DIR__ . "/../../FMA/autoload.php";
header("Content-Type: application/json");
$_pdo = new \FMA\PDO\MySQL_PDO();
$router = new AltoRouter([], "/api");
if (!\FMA\Utility::isDevServer()) {
    $router->map("GET", "[*]", function () use($_pdo) {
        return ["err" => true, "msg" => "API is still under development."];
    });
} else {
    $router->map("GET", "/organization/", function () use($_pdo) {
        return \FMA\Organization\GreekOrganization::allAsArray($_pdo);
    });
    $router->map("GET", "/organization/[i:id]/", function ($id) use($_pdo) {
        $org = \FMA\Organization\GreekOrganization::find($_pdo, $id);
        if (is_null($org)) {
            return ["err" => true, "msg" => "No organization by that id."];
        }
        return $org->toArray();
    });
    $router->map("GET", "/organization/[i:id]/chapter/", function ($id) use($_pdo) {
        $org = \FMA\Organization\GreekOrganization::find($_pdo, $id);
        if (is_null($org)) {
            return ["err" => true, "msg" => "No organization by that id."];
        }
        return \FMA\Organization\Chapter::findAllForGreekOrganizationAsArray($_pdo, $org);
    });
    $router->map("GET", "/organization/[i:id]/chapter/[i:cid]/", function ($id, $cid) use($_pdo) {
        $org = \FMA\Organization\GreekOrganization::find($_pdo, $id);
        if (is_null($org)) {
Esempio n. 5
0
 public function getDateExpires() : DateTime
 {
     return Utility::getDateTimeFromMySQLDateTime($this->date_expires);
 }
Esempio n. 6
0
 private function setVars()
 {
     date_default_timezone_set("America/Chicago");
     error_reporting(Utility::isDevServer() ? E_ALL & ~E_NOTICE : 0);
     ini_set("display_errors", Utility::isDevServer());
 }
 public function main()
 {
     $org_id = Utility::cleanInt($_POST["org_id"], 1);
     $uni_id = Utility::cleanInt($_POST["uni_id"], 1);
     $email = Utility::cleanString($_POST["university_email"]);
     $name_first = Utility::cleanString($_POST["name_first"]);
     $name_last = Utility::cleanString($_POST["name_last"]);
     $password = Utility::cleanString($_POST["password"]);
     $pledge_class = Utility::cleanString($_POST["pledge_class"]);
     $year = Utility::getDateTimeFromYear(Utility::cleanString($_POST["year"]));
     if (!$org_id) {
         $this->setError(self::$E_ORG_INVALID);
         return;
     }
     if (!$uni_id) {
         $this->setError(self::$E_UNI_INVALID);
         return;
     }
     $_org = GreekOrganization::find($this->_pdo, $org_id);
     $_uni = University::find($this->_pdo, $uni_id);
     if (is_null($_org)) {
         $this->setError(self::$E_ORG_INVALID);
         return;
     }
     if (is_null($_uni)) {
         $this->setError(self::$E_UNI_INVALID);
         return;
     }
     if (Chapter::findByOrgAndUni($this->_pdo, $_org, $_uni)) {
         $this->setError(self::$E_CHAPTER_EXISTS);
         return;
     }
     if ($name_first == "") {
         $this->setError(self::$E_NAME_F_INVALID);
         return;
     }
     if ($name_last == "") {
         $this->setError(self::$E_NAME_L_INVALID);
         return;
     }
     if (!Utility::isValidEmail($email)) {
         $this->setError(self::$E_EMAIL_INVALID);
         return;
     }
     if (User::findByEmail($this->_pdo, $email)) {
         $this->setError(self::$E_USER_EXISTS);
         return;
     }
     if ($pledge_class == "") {
         $this->setError(self::$E_PLEDGE_CLASS_INVALID);
         return;
     }
     if (!Utility::cleanInt($_POST["year"], date("Y") - 6)) {
         $this->setError(self::$E_YEAR_INVALID);
         return;
     }
     if ($year === false) {
         $this->setError(self::$E_YEAR_INVALID);
         return;
     }
     if (!Utility::isValidPassword($password)) {
         $this->setError(self::$E_PASSWORD_INVALID);
         return;
     }
     $_chapter = new Chapter($this->_pdo);
     $_chapter->create($_org, $_uni);
     $_pc = new PledgeClass($this->_pdo);
     $_pc->create($_chapter, $pledge_class);
     $_user = new User($this->_pdo);
     $_user->create($_chapter, $_pc, $name_first, $name_last, $email, $password, $year, true);
     $worker = new EmailWorker($this->_pdo);
     //TODO: Send email to user about what's next
     $worker->queueSignUpNotificationEmail($_chapter);
 }
Esempio n. 8
0
 public static function isDevServer() : bool
 {
     return Utility::stringContains(Config::getEnvironment(), ["dev", "test"], false);
 }
Esempio n. 9
0
 public function logout()
 {
     setcookie(self::$COOKIE_SESSION, "", -1);
     $is_timeout = $this->isTimedOut();
     $this->_remember = Remember::read($this->_pdo);
     if ($this->_remember) {
         $this->_remember->remove();
     }
     unset($this->_remember);
     unset($this->_user);
     session_destroy();
     session_start();
     if ($is_timeout) {
         $_SESSION[self::$SESSION_EXP] = true;
     }
     Utility::displayPage("/login/");
 }
Esempio n. 10
0
 public function getDatePaid() : DateTime
 {
     return Utility::getDateTimeFromMySQLDateTime($this->date_paid);
 }
Esempio n. 11
0
header("Content-Type: application/json");
require_once __DIR__ . "/../../FMA/autoload.php";
$_pdo = new \FMA\PDO\MySQL_PDO();
$_auth = new \FMA\Auth\SessionAuth($_pdo);
$_auth->validate();
$data = [];
if (!count($_FILES)) {
    $data = ["err" => true, "msg" => "There was an error with the file upload."];
} else {
    if (\FMA\Utility::stringStartsWith($_REQUEST["REQUEST_NAME"], "ADMIN_")) {
        $_REQUEST["REQUEST_NAME"] = str_replace("ADMIN_", "", $_REQUEST["REQUEST_NAME"]);
        if (!$_auth->getUser()->getPosition() || !$_auth->getUser()->getPosition()->isOfficer()) {
            $data = ["err" => true, "msg" => "You do not have permission to do that."];
        } else {
            if ($_REQUEST["DATA_TYPE"] == "UPLOAD_EVENT_ATTACHMENT") {
                $event_id = Utility::cleanInt($_POST["event_id"], 1);
                if (!$event_id) {
                    $data = ["err" => true, "msg" => "Invalid event ID."];
                    goto end;
                }
                $_event = \FMA\Calendar\Event::find($_pdo, $event_id);
                if (is_null($_event) || $_event->getCreator()->getChapterId() != $_auth->getUser()->getChapterId()) {
                    $data = ["err" => true, "msg" => "Invalid event ID."];
                    goto end;
                }
                try {
                    $_fs = \FMA\Config::getFileSystem();
                    $_uploader = new \FMA\File\Builder\EventFileBuilder($_pdo, $_fs, $_event);
                    $_file = $_uploader->create($_auth->getUser(), $_FILES["event_attachment"]);
                    $data = ["err" => false, "msg" => "", "file" => $_file->toArray()];
                    //TODO: Decide if an email should be sent here
Esempio n. 12
0
<?php

require_once __DIR__ . "/../../FMA/autoload.php";
header("Content-Type: application/json");
$_pdo = new \FMA\PDO\MySQL_PDO();
$_auth = new \FMA\Auth\SessionAuth($_pdo);
$router = new AltoRouter([], "/service");
$router->map("POST", "/login/", function () use($_pdo, $_auth) {
    $_auth->authenticate($_POST["email"] ?: "", $_POST["password"] ?: "");
    $user = null;
    if (!$_auth->hasError() && $_auth->getUser()) {
        $user = $_auth->getUser();
        if (\FMA\Utility::cleanBoolean($_POST["remember"])) {
            $_auth->remember();
        }
        $user = $user ? $user->toArray() : $user;
    }
    return ["err" => $_auth->hasError(), "msg" => $_auth->getErrorMessage(), "user" => $user];
});
$match = $router->match();
if ($match && !is_callable($match["target"])) {
    throw new TypeError("Target is not callable.");
} else {
    if ($match && is_callable($match["target"])) {
        $page_title = $match["name"];
        $arr = call_user_func_array($match["target"], $match["params"]);
        echo json_encode($arr, JSON_PRETTY_PRINT);
    } else {
        $page_title = "404";
        header($_SERVER["SERVER_PROTOCOL"] . " 404 Not Found");
        echo json_encode(["err" => true, "msg" => "Invalid Request URI"], JSON_PRETTY_PRINT);
Esempio n. 13
0
 public function deleteOnAndAfterDate(DateTime $date)
 {
     $this->_pdo->perform("UPDATE `event` SET is_hidden = 1 WHERE `start` >= :s", ["s" => Utility::getDateTimeForMySQLDateTime($date)]);
 }
Esempio n. 14
0
 public function getDateCreated() : DateTime
 {
     return Utility::getDateTimeFromMySQLDateTime($this->date_created);
 }
Esempio n. 15
0
<?php

header("Content-Type: application/json");
//	ini_set("html_errors", false);
require_once __DIR__ . "/../../FMA/autoload.php";
$_pdo = new \FMA\PDO\MySQL_PDO();
$_auth = new \FMA\Auth\SessionAuth($_pdo);
//Do not validate auth here, use authenticated controller
$data = [];
if ($_POST["REQUEST_NAME"] == "") {
} else {
    if (\FMA\Utility::stringStartsWith($_POST["REQUEST_NAME"], "ADMIN_")) {
        $_POST["REQUEST_NAME"] = str_replace("ADMIN_", "", $_POST["REQUEST_NAME"]);
    } else {
        $data = ["err" => true, "msg" => "Action not set."];
    }
}
echo json_encode($data, JSON_PRETTY_PRINT);
Esempio n. 16
0
 public function getDateApplied() : DateTime
 {
     return Utility::getDateTimeFromMySQLDateTime($this->date_applied);
 }
Esempio n. 17
0
 private function logEmail(\bool $success, \string $template_name, User $to_user, array $data)
 {
     $query = "INSERT INTO email_log (user_id, template, vars, successful, view_key)\n\t\t\t\t\t  VALUES (:u, :t, :v, :s, :k)";
     $this->_pdo->perform($query, ["u" => $to_user->getId(), "t" => $template_name, "v" => serialize($data), "s" => $success, "k" => Utility::getRandomString(20)]);
 }
Esempio n. 18
0
 public function isTokenExpiredAccountVerify() : bool
 {
     return Utility::getDateTimeFromMySQLDateTime($this->token_expiry_account_verify) < new DateTime();
 }
Esempio n. 19
0
 public function getTimeJoined() : DateTime
 {
     return Utility::getDateTimeFromMySQLDateTime($this->time_joined);
 }
Esempio n. 20
0
<?php

require_once __DIR__ . "/../FMA/autoload.php";
$_pdo = new \FMA\PDO\MySQL_PDO();
$in_string = file_get_contents(__DIR__ . "/../config/query_log.sql");
preg_match_all('/-- START\\s-- DATE:\\s([^\\s]*)\\s([\\S\\s]*?)\\s-- END/i', $in_string, $m, PREG_SET_ORDER);
$matches = [];
foreach ($m as $key => $match) {
    if (isset($matches[$match[1]])) {
        $matches[$match[1]] = $match[2] . "\n\n" . $matches[$match[1]];
    } else {
        $matches[$match[1]] = $match[2];
    }
}
unset($m, $match, $key);
$matches = array_reverse($matches);
foreach ($matches as $key => $value) {
    $matches[$key] = preg_split('/;(\\s*)/', $value);
}
$last_update = \FMA\Utility::getDateTimeFromMySQLDate(\FMA\Config::getLastUpdate());
foreach ($matches as $date => $queries) {
    $date = \FMA\Utility::getDateTimeFromMySQLDate($date);
    if ($date <= $last_update) {
        continue;
    }
    foreach ($queries as $query) {
        $_pdo->perform($query);
    }
}
end($matches);
\FMA\Config::setLastUpdate(key($matches));