Exemplo n.º 1
0
 public static function getInstance()
 {
     if (null === self::$instance) {
         self::$instance = new self();
     }
     return self::$instance;
 }
Exemplo n.º 2
0
function smarty_function_modules($params, &$smarty)
{
    $mod_con = new Controller_Module($params, RoutingEngine::getSmarty());
    $mod_names = array_safe($params, "list");
    $mod_list = explode(",", $mod_names);
    $modules = array();
    $unplaced_modules = array();
    $counts = array("3" => 0, "4" => 0, "5" => 0);
    foreach ($mod_list as $mod_code) {
        $mod_name = Module::$hash[$mod_code];
        if (!method_exists($mod_con, $mod_name)) {
            continue;
        }
        $module = $mod_con->{$mod_name}();
        if ($module->size) {
            $modules[$module->size][] = $module;
            $counts[$module->size]++;
        } else {
            $unplaced_modules[] = $module;
        }
    }
    foreach ($unplaced_modules as $module) {
        asort($counts);
        current($counts);
        $modules[key($counts)][] = $module;
        $counts[key($counts)]++;
    }
    RoutingEngine::getSmarty()->assign("modules", $modules);
    return RoutingEngine::getSmarty()->fetch("modules/module_master.tpl");
}
Exemplo n.º 3
0
 public function training()
 {
     if (!isset($_GET["username"])) {
         exit;
     }
     $user = User::fromUsername($_GET["username"]);
     $t_items = TrainingLog::getItemsForUser($user->uid);
     $feed = new Rss_Feed("Training entries for {$user->username}", "http://{$_SERVER["SERVER_NAME"]}", "Includes the training data for a given user.");
     $feed->pubDate = date(DATE_RSS);
     $feed->defineImageForFeed(new Rss_Image("running logo", "http://byroni.us", "http://runndaily.com/img/logo.png"));
     foreach ($t_items as $item) {
         $rss_item = new Rss_Item();
         $rss_item->guid = "http://{$_SERVER["SERVER_NAME"]}/training/view/{$item->tid}";
         $rss_item->link = "http://{$_SERVER["SERVER_NAME"]}/training/view/{$item->tid}";
         $rss_item->description = "{$item->date} : {$item->distance} miles";
         $rss_item->pubDate = date(DATE_RSS, $item->date);
         $rss_item->title = "{$user->username} logged an entry on " . date("F j, Y, g:i a", $item->date);
         $feed->addItemToFeed($rss_item);
     }
     //die(var_dump($feed));
     RoutingEngine::getSmarty()->assign("RssFeed", $feed);
     $rss_out = RoutingEngine::getSmarty()->fetch("generic/rss.tpl");
     header("Content-Type: application/rss+xml");
     echo $rss_out;
 }
Exemplo n.º 4
0
 private function __construct()
 {
     $this->classloader = Classloader::getInstance();
     $this->classloader->initLoadLib();
     $this->dataConnector = DataConnector::getInstance();
     $this->routingEngine = RoutingEngine::getInstance();
     $this->templateEngine = TemplateEngine::getInstance();
 }
Exemplo n.º 5
0
 function leave()
 {
     if (!isset($_POST["e_eid"])) {
         RoutingEngine::returnAjax("Error.");
     }
     $eid = $_POST["e_eid"];
     $result = Event::removeAttendeeFromEvent($eid);
     RoutingEngine::returnAjax($result, true);
 }
Exemplo n.º 6
0
 public function action_delete()
 {
     RoutingEngine::setPage("runnDAILY", "PV__300");
     if (!isset($_POST["go_id"])) {
         Page::redirect("/goals");
     }
     Goal::deleteGoal($_POST["go_id"]);
     Page::redirect("/goals");
 }
Exemplo n.º 7
0
 public function browse()
 {
     $format = isset($_GET["format"]) ? $_GET["format"] : "html";
     if ($format == "ajax") {
         $uid = $_GET["uid"];
         $page_no = $_GET["page"];
         $logs = Log::getAllActivityForUserPaged($uid, 5, $page_no);
         RoutingEngine::getSmarty()->assign("logs", $logs);
         RoutingEngine::getSmarty()->assign("uid", $uid);
         RoutingEngine::getSmarty()->assign("page_no", $page_no + 1);
         exit(RoutingEngine::getSmarty()->fetch("log/log_list.tpl"));
     }
 }
Exemplo n.º 8
0
 public function actionCancel()
 {
     RoutingEngine::setPage("runnDAILY Requests", "PV__300");
     $cid = $_POST["cid"];
     $confirmation = Confirmation::fetch($cid);
     $result = false;
     if ($confirmation->uid_from == User::$current_user->uid) {
         $result = $confirmation->delete();
     }
     //Javascript is expecting an object with result and cid
     $output = array("cid" => $cid, "result" => $result);
     RoutingEngine::returnAjax($output, true);
 }
Exemplo n.º 9
0
 public function view()
 {
     if (!isset($_GET["gid"])) {
         Page::redirect("/community/");
     }
     $gid = $_GET["gid"];
     $group = Group::fromGroupID($gid);
     RoutingEngine::getSmarty()->assign("group_view", $group);
     RoutingEngine::getSmarty()->assign("user_is_member", Group::userIsMember($gid));
     RoutingEngine::getSmarty()->assign("user_can_edit", Group::userCanEdit($gid));
     RoutingEngine::getSmarty()->assign("group_view_anoun", Group::getAnnouncement($gid));
     RoutingEngine::getSmarty()->assign("group_view_member_list", Group::getMembers($gid));
     RoutingEngine::getSmarty()->assign("group_view_activity", Log::getActivityByAid(null, $gid, array(500)));
 }
Exemplo n.º 10
0
 public function search()
 {
     RoutingEngine::setPage("runnDAILY", "PV__300");
     if (!isset($_POST["u_search"]) || $_POST["u_search"] == "") {
         echo "<p>Please enter a search term.</p>";
         exit;
     }
     //$user_list = User::searchForUser($_POST["u_search"]);
     $user = $_POST["u_search"];
     $user_list = User::sql()->select("u_uid, u_username")->where("u_username LIKE ? OR u_email LIKE ?", "%" . $user . "%", "%" . $user . "%")->limit(40)->execute(false, true);
     RoutingEngine::getSmarty()->assign("user_list", $user_list);
     $output = RoutingEngine::getSmarty()->fetch("community/_user_search_result.tpl");
     echo $output;
     exit;
 }
Exemplo n.º 11
0
 public function view($common)
 {
     RoutingEngine::setPage("runnDAILY About", "PV__400");
     $pages = array("admin_elevation", "about_contact", "about_credits", "about_index", "community_index", "community_view_user", "confirmation_index", "goals_index", "goals_create", "home_index", "home_register", "messages_index", "routes_view", "routes_create", "routes_index", "training_create", "training_index");
     if (in_array($common, $pages)) {
         $output = RoutingEngine::getSmarty()->fetch("help/_pages/{$common}.tpl");
     } else {
         $feedback = new Message();
         $feedback->uid_from = User::$current_user->uid;
         $feedback->uid_to = null;
         $feedback->message = "Please create a help page for " . $_SERVER["HTTP_REFERER"];
         $feedback->subject = null;
         $feedback->type = 2;
         $feedback->create();
         $output = RoutingEngine::getSmarty()->fetch("help/_pages/none.tpl");
     }
     echo $output;
     die;
 }
Exemplo n.º 12
0
 /**
  * Normal render 
  * @param string $view
  */
 public function renderAsHTML($view = 'index')
 {
     $routingEngine = RoutingEngine::getInstance();
     $templateEngine = TemplateEngine::getInstance();
     $templateEngine->loadDesign();
     $templateEngine->loadView($routingEngine->controller, $routingEngine->action);
     $templateEngine->setTitle($routingEngine->controller . ' > ' . $routingEngine->action);
     $templateEngine->render($this);
 }
Exemplo n.º 13
0
<?php

//phpinfo();
//die("Configuring the server.");
$_SERVER["TIME_START"] = microtime(true);
DEFINE("PUBLIC_ROOT", dirname(__FILE__));
DEFINE("ROOT", dirname(PUBLIC_ROOT));
DEFINE("SYSTEM_ROOT", ROOT . "/system");
DEFINE("CLASS_ROOT", SYSTEM_ROOT . "/class");
require SYSTEM_ROOT . "/config.php";
session_start();
RoutingEngine::getInstance()->authenticateUser();
$request = explode("?", $_SERVER["REQUEST_URI"]);
$engine = RoutingEngine::getInstance()->initialize($request[0]);
$engine->renderRequest();
RoutingEngine::getInstance()->persistUserData();
Exemplo n.º 14
0
 public function action_copy_view()
 {
     RoutingEngine::setPage("runnDAILY Routes", "PV__300");
     $route = new Route($_POST);
     if ($route->copy()) {
         Notification::add("Your route - {$route->name} - was copied.");
         Page::redirect("/routes/view/{$route->id}");
     }
     Notification::add("There was an error copying the route.  Try again.");
     Page::redirect("/routes/view/{$route->id}");
 }
Exemplo n.º 15
0
 public function ajax_elevation_update_all()
 {
     $result = Database::getDB()->query("\r\n\t\t\tSELECT r_id, r_name, r_points\r\n\t\t\tFROM routes\r\n\t\t\tWHERE\r\n\t\t\t\tr_elevation IS NULL\r\n\t\t\tLIMIT 10\r\n\t\t") or die(Database::getDB()->error);
     $routes = array();
     while ($row = $result->fetch_assoc()) {
         $routes[] = new Route($row);
     }
     $result->close();
     $results = array();
     foreach ($routes as $route) {
         $result = $route->_updateElevationData();
         if (!$result) {
             $result = $route->_setElevationToChecked();
         }
         $results[] = $result;
     }
     RoutingEngine::returnAjaxForm(true, $results);
 }
Exemplo n.º 16
0
 public function logoff()
 {
     $_SESSION['login'] = false;
     session_destroy();
     RoutingEngine::getInstance()->redirect('index.php');
 }
Exemplo n.º 17
0
 public function credits()
 {
     RoutingEngine::setPage("runnDAILY About", "PV__400");
 }
Exemplo n.º 18
0
 public function actionDelete()
 {
     RoutingEngine::setPage("Messages | runnDAILY", "PV__300");
     if (!isset($_POST["msg_convo_id"])) {
         Page::redirect("/messages");
     }
     $message = new Message($_POST);
     $read_count = Message::markConvoRead($message->convo_id);
     if ($read_count > 0) {
         Message::updateCount(User::$current_user->uid, -$read_count);
         User::$current_user->msg_new -= $read_count;
         RoutingEngine::getInstance()->persistUserData();
     }
     $message->delete();
     Page::redirect("/messages");
 }
Exemplo n.º 19
0
 function ajax_remove_notification()
 {
     RoutingEngine::setPage("runnDAILY User Remove Notification", "PV__300");
     if (!isset($_POST["id"])) {
         return false;
     }
     $id = $_POST["id"];
     Notification::remove($id);
     RoutingEngine::getInstance()->persistUserData();
     RoutingEngine::returnAjax(true);
 }
Exemplo n.º 20
0
 public function delete()
 {
     RoutingEngine::setPage("runnDAILY", "PV__100");
     $message = new Message($_POST);
     exit(json_encode($message->deleteByType(2)));
 }
Exemplo n.º 21
0
 public function settings()
 {
     RoutingEngine::setPage("runnDAILY Settings", "PV__300");
 }
Exemplo n.º 22
0
 public function summary()
 {
     RoutingEngine::setPage("runnDAILY Training Summary", "PV__300");
     $this_week = new DateRange();
     $this_week->getWeekRange();
     $data_this_week = TrainingLog::getItemsForUserForGoalPercent(User::$current_user->uid, $this_week->start, $this_week->end);
     $last_week = new DateRange();
     $last_week->getWeekRange("today", -1);
     $data_last_week = TrainingLog::getItemsForUserForGoalPercent(User::$current_user->uid, $last_week->start, $last_week->end);
     $overall = TrainingLog::getSummaryOverall(User::$current_user->uid);
     //var_dump($data_this_week, $data_last_week, $overall);
     RoutingEngine::getSmarty()->assign("this_week", $this_week);
     RoutingEngine::getSmarty()->assign("last_week", $last_week);
     RoutingEngine::getSmarty()->assign("overall", $overall);
     RoutingEngine::getSmarty()->assign("data_this_week", $data_this_week);
     RoutingEngine::getSmarty()->assign("data_last_week", $data_last_week);
     $output = RoutingEngine::getSmarty()->fetch("training/_summary.tpl");
     echo $output;
     die;
 }
Exemplo n.º 23
0
 public function userCanEdit($gid)
 {
     return RoutingEngine::getInstance()->requirePermission("GP__100", $gid);
 }
Exemplo n.º 24
0
 public static function setPage($title = "runnDAILY", $perm = "PV__100", $default = false)
 {
     if ($default && self::$_isPageSet) {
         return;
     }
     self::getInstance()->requirePermission($perm, null, true);
     self::getInstance()->page->title = $title;
     self::$_isPageSet = true;
 }
Exemplo n.º 25
0
 /**
  * @param $as_object
  * @param $arr_on_single
  * @param $arr_index
  * @return mixed
  */
 function execute($as_object = false, $arr_on_single = false, $arr_index = null)
 {
     //set some defaults if needed
     if (!$this->_has_select) {
         $this->select("*");
     }
     if (!$this->_has_limit) {
         $this->limit(100);
     }
     $sql = $this->_get_full_sql();
     if (count($this->_bind_vals)) {
         $stmt = Database::getDB()->prepare($sql);
         $types = $this->_sql_all_bind_types();
         call_user_func_array(array($stmt, "bind_param"), array_merge(array($types), $this->_bind_vals));
         $stmt->execute() or RoutingEngine::throwException($stmt->error);
         $stmt->store_result();
     } else {
         $stmt = Database::getDB()->query($sql);
     }
     $results = array();
     while ($row = $stmt->fetch_assoc()) {
         if ($as_object) {
             $obj = new $this->_class($row);
             if (count($this->_left_joins)) {
                 foreach ($this->_left_joins as $table) {
                     $type = $this->_tables_classes[$table];
                     $obj->{$type} = new $type($row);
                 }
             }
             $results[] = $obj;
         } else {
             if (isset($arr_index)) {
                 $results[$row[$arr_index]] = $row;
             } else {
                 $results[] = $row;
             }
         }
     }
     $stmt->close();
     $return = !$arr_on_single && count($results) == 1 ? $results[0] : $results;
     if ($this->_has_debug) {
         var_dump($return);
     }
     return $return;
 }
Exemplo n.º 26
0
 public function index()
 {
     RoutingEngine::setPage("runnDAILY Guides", "PV__400");
 }