public function generate(CoreExt_Controller_Page_Interface $instance) { $this->setHeader(); $viewBase = new Core_View($instance); $viewBase->titulo = $this->_titulo; $viewBase->addForm($instance); $html = $viewBase->MakeHeadHtml(); foreach ($viewBase->clsForm as $form) { $html .= $form->Gerar(); } $html .= $form->getAppendedOutput(); $html .= $viewBase->MakeFootHtml(); echo $html; }
/** * */ protected function initView() { $this->view = Core_View::getInstance(); $this->view->addHelper(new Admin_View_BaseHelper()); $this->view->addHelper(new Admin_View_MessagesHelper()); $this->view->addHelper(new Admin_View_PagingHelper()); }
/** * @param $host * @param $user * @param $pass * @param $name * @param string $driver */ public function __construct($host, $user, $pass, $name, $driver = 'pgsql') { try { parent::__construct($driver . ':dbname=' . $name . ';host=' . $host, $user, $pass); } catch (Exception $e) { if (!cfg()->dev_mode && Core_Request::getInstance()->getRoute('module') == 'default') { $view = Core_View::getInstance(); $view->setLayoutFile('$maintenance/db_connect.phtml'); $view->displayLayout(); die; } else { print get_class($e) . ': ' . $e->getMessage() . PHP_EOL; die; } } if (cfg()->dev_mode) { $this->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); } else { $this->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_SILENT); } $this->setAttribute(PDO::ATTR_STATEMENT_CLASS, array('Core_Db_Statement', array($this))); if (cfg()->dev_mode) { // Core_Debug::getInstance()->initPdoDebug($this); } }
public function generate(CoreExt_Controller_Page_Interface $instance) { require_once 'Core/View.php'; $viewBase = new Core_View($instance); $viewBase->titulo = 'i-Educar - Redefinição senha'; $instance->titulo = 'Redefinição senha'; $viewBase->addForm($instance); //$viewBase->Formular(); $html = $viewBase->MakeHeadHtml(); foreach ($viewBase->clsForm as $form) { $html .= $form->RenderHTML(); } $html .= $form->getAppendedOutput(); $html .= $viewBase->MakeFootHtml(); echo $html; }
/** * */ public static function checkPermissions() { $request = Core_Request::getInstance(); // permissions structure $data = array('module' => $request->getRoute('module'), 'controller' => $request->getRoute('controller'), 'action' => $request->getRoute('action')); $model = Admin_PermissionsModel::getInstance(); $flag = $model->getFlag($data); // $flag = 0 - is a free acces of the page if ($flag === 0) { return true; } if (!$flag) { // we need to check that method exist $model->add($data); } else { if (!s()->user->id) { // @todo Core_View::getInstance()->addFlashMessage(__('Please Login'), 'danger'); Core_Response::getInstance()->setStatus(1)->redirect('admin')->toJson(); } if (!Core_Bit::check(s()->user->access['permissions'], $flag)) { // well an owner has ALL access $role_rs = Admin_RolesModel::get(array('id' => s()->user->role_id)); if ($role_rs->is_owner === 1 || s()->user->is_developer === 1) { return true; } Core_View::getInstance()->addFlashMessage(__('You Don\'t have permission to access this page'), 'danger'); Core_Response::getInstance()->setStatus(1)->redirect('admin')->toJson(); } } }
public static function getInstance() { if (null == self::$_instance) { self::$_instance = new self(); } return self::$_instance; }
public function __construct($templateFile, $smConf = array(), $filter = true) { $this->template = $templateFile; $this->smarty = new Smarty(); $template_dir = array('Module', 'themes/default', 'themes'); $this->smarty->template_dir = $template_dir; array_walk($this->smarty->template_dir, array("Core_View", "addPath"), INCLUDE_PATH); $this->smarty->plugins_dir = array("Core/SmartyPlugins", "libraries/Smarty/plugins/"); array_walk($this->smarty->plugins_dir, array("Core_View", "addPath"), INCLUDE_PATH); $this->smarty->compile_dir = "tmp/templates_c"; Core_View::addPath($this->smarty->compile_dir, null, USER_PATH); $this->smarty->cache_dir = "tmp/cache"; Core_View::addPath($this->smarty->cache_dir, null, USER_PATH); /* $error_reporting = $smConf->error_reporting; if($error_reporting != (string)(int)$error_reporting) { $error_reporting = self::bitwise_eval($error_reporting); } $this->smarty->error_reporting = $error_reporting; $this->smarty->assign('tag', 'Core=' . Version::VERSION); if($filter) { $this->smarty->load_filter('output', 'cachebuster'); $this->smarty->load_filter('output', 'ajaxcdn'); $this->smarty->load_filter('output', 'trimwhitespace'); } */ }
/** * @throws Exception */ protected function loadCfg() { $match_id = PHP_SAPI == 'cli' ? $this->getRequest()->getArgv(1) : $this->getRequest()->cfg_id; cfg()->load($match_id, Core_Cfg::MATCH_TYPE_ID); Core_View::getInstance()->disableLayout(); if (PHP_SAPI != 'cli') { p404('only admin or cli sapi'); } }
function viewDaily() { $api = new Module_Plans_API(); $week_date = Core_Common::getRequestVar('week_date', null, 'string'); $daily_plans = $api->getDailyPlans($week_date); $view = Core_View::factory('daily'); $view->plans = $daily_plans; $view->week_date = $week_date; $view->coach = $_SESSION['coach']; echo $view->render(); }
/** * @param array $connectionParams */ public static function init(array $connectionParams) { if (!dibi::isConnected()) { try { $connection = dibi::connect(array('driver' => $connectionParams['driver'], 'host' => $connectionParams['host'], 'dsn' => 'mysql:host=' . $connectionParams['host'] . ';dbname=' . $connectionParams['db'] . '', 'persistent' => true, 'username' => $connectionParams['user'], 'password' => $connectionParams['pass'], 'database' => $connectionParams['db'], 'charset' => isset($connectionParams['charset']) ? $connectionParams['charset'] : 'utf8', 'result' => array('detectTypes' => true, 'formatDate' => "Y-m-d", 'formatDateTime' => 'Y-m-d H:i:s'), 'profiler' => array('run' => true), 'flags' => MYSQLI_CLIENT_COMPRESS)); $panel = new Dibi\Bridges\Tracy\Panel(); $panel->register($connection); } catch (DibiException $e) { dd($e->getMessage()); $view = Core_View::getInstance(); $view->setLayoutFile('$maintenance/db_connect.phtml'); $view->displayLayout(); die; } } }
/** * @return mixed */ public final function getView() { return Core_View::getInstance(); }
public function dispatch() { $controller = $this->_dispatchInfo['controller']; $action = $this->_dispatchInfo['action']; $params = $this->_dispatchInfo['params']; // 储存URL参数 if ($params) { Core_Request::getInstance()->setParams($params); } // 如果抛出异常,则由异常处理器处理 if ($controller == 'Core_Exception_Error') { $className = $controller; $classPath = SYS_PATH . DIRECTORY_SEPARATOR . str_replace('_', DIRECTORY_SEPARATOR, $controller) . '.php'; } else { $className = "Controller" . "_" . ucfirst($controller); $classPath = APP_PATH . DIRECTORY_SEPARATOR . str_replace('_', DIRECTORY_SEPARATOR, $className) . '.php'; } // 先检测文件是否查找 if (!file_exists($classPath)) { throw new Core_Exception_Fatal('Unable To find file - ' . $classPath); } // 然后再包含文件 require $classPath; if (!class_exists($className)) { throw new Core_Exception_Fatal('Unable to find controller - ' . $classPath); } $controllerObj = new $className(); $actionMethod = $action . 'Action'; // 方法不存在 if (!method_exists($controllerObj, $actionMethod)) { throw new Core_Exception_Fatal('Unable to find action - ' . $className . '::' . $actionMethod, 404); } $result = call_user_func(array($controllerObj, $actionMethod)); if (isset($controllerObj->autoRender) && $controllerObj->autoRender) { if (null === $result || $result !== false) { $tpl = $controllerObj->getTpl() ?: strtolower($controller) . DS . strtolower($action); $tplFilePath = template($tpl); if (!is_file($tplFilePath)) { throw new Core_Exception_Fatal('Unable to find template - ' . $tplFilePath); } Core_View::getInstance()->display($tpl); } } }
function viewLaps() { $api = new Module_SessionGraphs_API(); $session_date = Core_Common::getRequestVar('session_date', null, 'string'); $lap_num = Core_Common::getRequestVar('lap_num', null, 'string'); $view = Core_View::factory('sessionlaps'); $view->session_date = $session_date; $view->lap_num = $lap_num; $session = $api->getSession($session_date); $laps = $api->getLaps($session_date); $lap = $laps[$lap_num - 1]; $zones = $api->getZones($session_date, $lap['start_time'], $lap['end_time']); $view->zones = $zones; $view->laps = $laps; $view->lap = $lap; $session_labels = array(); $session_labels[] = array("label" => 'Date', "value" => $session['session_date'], "id" => 'session_date', "units" => ''); $session_labels[] = array("label" => 'Duration', "value" => $session['duration'], "id" => 'duration', "units" => ''); $session_labels[] = array("label" => 'Distance', "value" => $session['distance'], "id" => 'distance', "units" => 'km'); $session_labels[] = array("label" => 'Avg Speed', "value" => $session['avg_speed'], "id" => 'avg_speed', "units" => 'km/h'); $session_labels[] = array("label" => 'Max Speed', "value" => $session['max_speed'], "id" => 'max_speed', "units" => 'km/h'); $session_labels[] = array("label" => 'Avg Heart Rate', "value" => $session['avg_heartrate'], "id" => 'avg_heartrate', "units" => 'bpm'); $session_labels[] = array("label" => 'Max Heart Rate', "value" => $session['max_heartrate'], "id" => 'max_heartrate', "units" => 'bpm'); $session_labels[] = array("label" => 'Avg Heart Percent', "value" => $session['avg_heartrate_percent'], "id" => 'avg_heartrate_percent', "units" => '%'); $session_labels[] = array("label" => 'Max Heart Percent', "value" => $session['max_heartrate_percent'], "id" => 'max_heartrate_percent', "units" => '%'); $session_labels[] = array("label" => 'Energy', "value" => round($session['calories'] * 4.184), "id" => 'calories', "units" => 'kJ'); $session_labels[] = array("label" => 'Total Ascent', "value" => $session['total_ascent'], "id" => 'total_ascent', "units" => 'm'); $session_labels[] = array("label" => 'Total Descent', "value" => $session['total_descent'], "id" => 'total_descent', "units" => 'm'); $view->session = $session_labels; echo $view->render(); }
/** * @see Core_Controller_Page_Interface#generate($instance) */ public function generate(CoreExt_Controller_Page_Interface $instance) { require_once 'Core/View.php'; Core_View::generate($instance); }
/** * View the parts on a bike. * * @return The Webpage Text */ function viewBike() { $api = new Module_UserManagement_API(); $bike_id = Core_Common::getRequestVar('id', null, 'int'); $view = Core_View::factory('viewBike'); $view->bikes = $api->getBikes(); $view->parts = $api->getBikeData($bike_id); echo $view->render(); }
/** * default exception handler * @param Exception $exception * @param Core_View $view */ public static function defaultExceptionHandler($exception, $view) { $view->displayAjax($exception->getMessage(), array(), $exception->getCode()); }
public function display($tpl, $data = null) { $this->_loadMeta(); return Core_View::getInstance()->display($tpl, $data); }
/** * */ protected function disableLayout() { Core_View::getInstance()->disableLayout(); }
/** * Render view script * @param string $script - path to view script */ public function render($script) { return $this->_view->render($script); }
/** * Create a new user */ function signup() { $form = new Module_Login_SignUpForm(); $view = Core_View::factory('signup'); $view->errorMessage = ""; if ($form->validate()) { $api = new Module_Login_API(); $user_api = new Module_UserManagement_API(); $login = $form->getSubmitValue('form_login'); $password = $form->getSubmitValue('form_password'); $password2 = $form->getSubmitValue('form_passwordconfirm'); $email = $form->getSubmitValue('form_email'); /* Check the passwords match */ try { /* Check if the username exists */ if ($api->getUser($login)) { throw new Exception('The username is already taken'); } /* Check the passwords */ if ($password !== $password2) { throw new Exception('The passwords do not match'); } $user_api->createUser($login, $password, $email); Core_Url::redirectToUrl('index.php'); } catch (Exception $e) { $view->errorMessage = $e->getMessage(); } } $view->addForm($form); $view->subTemplate = 'genericForm.tpl'; echo $view->render(); }
function view() { $view = Core_View::factory('dashboard'); echo $view->render(); }
/** * 异常处理 * @return [type] [description] */ public function handle() { header('HTTP/1.1 500 Server Error'); Core_View::getInstance()->display('error/500.php'); }
/** * */ protected function initView() { $this->view = Core_View::getInstance(); }
function viewUpload() { $form = new SessionUploadForm(); $view = Core_View::factory('sessionsfileupload'); $view->UploadStatusMsg = ""; $view->UploadStatus = "Error"; if ($form->validate()) { $timer = new Benchmark_Timer(); $timer->start(); $upload = $form->getSubmitValue('upload'); $timer->setMarker('Decode Sessions - Start'); exec('/usr/local/bin/fitdecode -s ' . $upload['tmp_name'], $xml_session); $xml_session = implode("\n", $xml_session); $sessions = parseSessions($xml_session); $timer->setMarker('Decode Sessions - End'); /* There should only be one session */ if (is_array($sessions)) { $session = $sessions[0]; unset($sessions); } $db = Zend_Registry::get('db'); $db->beginTransaction(); try { $api = new Module_Sessions_API(); /* Insert the session data into the database */ $api->createSessionFull($session->start_time, 'E1', 'Untitled', $session->total_timer_time, $session->total_distance, $session->total_calories, $session->avg_heart_rate, $session->max_heart_rate, $session->avg_speed, $session->max_speed, $session->total_ascent, $session->total_descent, ''); /* Find the seconds since epoch so we can do simple maths */ $ftime = strptime($session->start_time, '%FT%T%z'); $session_epoch = mktime($ftime['tm_hour'], $ftime['tm_min'], $ftime['tm_sec'], 1, $ftime['tm_yday'] + 1, $ftime['tm_year'] + 1900); $session_timestamp = $session->start_time; unset($session); unset($sessions); $timer->setMarker('Decode Records - Start'); exec('/usr/local/bin/fitdecode -r ' . $upload['tmp_name'], $xml_records); $xml_records = implode("\n", $xml_records); $records_input = parseRecords($xml_records, $session_epoch); $timer->setMarker('Decode Records - End'); if (is_array($records_input)) { $record_prev = $records_input[0]; } /* Get the array of records, removing duplicates */ $records = array(); foreach ($records_input as $record) { if (!isset($record_last) || $record_last->interval != $record->interval) { $records[] = $record; } $record_last = $record; } unset($records_input); unset($record_last); $UserAPI = Module_UserManagement_API::getInstance(); $user = $UserAPI->getUser(); /* Add the matching data points */ foreach ($records as $record) { /* Skip duplicates, they will cause issues in graphs */ if (!isset($record->power)) { $record->power = $api->getPower($record->gradient, $record->temperature, $record->altitude, $record->speed, $record->speed - $record_prev->speed, $record->interval - $record_prev->interval, $user['rider_weight'], $user['bike_weight']); } $record_prev = $record; } unset($user); unset($UserAPI); $timer->setMarker('Record insertion - start'); $api->insertAllSessionData($session_timestamp, $records); /* Insert all the data */ $timer->setMarker('Record insertion - end'); /* Calculate the climbs */ $climbs = $api->getClimbCategories(); $timer->setMarker('Climb - Start'); $min_climb = $climbs[0]; /* 500m with an average gradient of more than 3% (cat 5)*/ /* Find the points that have a distance of 500m */ $window_distance = 0; $window_altitude = 0; $cat = -1; $climb_num = 1; $num_records = count($records); $num_climbs = count($climbs); for ($front = 0, $back = 0; $front < $num_records; $front++) { $window_distance += $records[$front]->delta_distance * 1000; $window_altitude += $records[$front]->delta_altitude; if ($window_distance > $min_climb['min_distance']) { $window_gradient = $window_altitude / $window_distance * 100; /* Check if we have found the start of a climb */ if ($cat == -1 && $window_gradient >= $climbs[$cat + 1]['min_gradient']) { $cat++; /* Go through and find the minimum height */ $min = $back; for ($i = $back; $i < $front; $i++) { if ($records[$i]->altitude <= $records[$min]->altitude) { $min = $i; } } $climb['bottom'] = $records[$min]->interval; $climb['min_altitude'] = $records[$min]->altitude; } /* Check if we have finished the climb */ if ($cat != -1 && $window_gradient < $climbs[$cat]['min_gradient']) { /* Need to go back and find the maximum altitude */ $max = $back; for ($i = $back; $i < $front; $i++) { if ($records[$i]->altitude > $records[$max]->altitude) { $max = $i; } } $climb['top'] = $records[$max]->interval; $climb['max_altitude'] = $records[$max]->altitude; /* Get the max gradient */ $climb['gradient_max'] = $records[$min]->gradient; for ($i = $min; $i <= $max; $i++) { if ($climb['gradient_max'] < $records[$i]->gradient) { $climb['gradient_max'] = $records[$i]->gradient; } } /* Tally the totals */ $climb['total_climbed'] = 0; for ($i = $min + 1; $i <= $max; $i++) { $climb['total_climbed'] += $records[$i]->delta_altitude; } $climb['total_distance'] = round($records[$max]->distance - $records[$min]->distance, 2); $climb['gradient_avg'] = round($climb['total_climbed'] / ($climb['total_distance'] * 1000) * 100, 2); /* Find the category of the climb */ $cat = -1; while ($cat + 1 < $num_climbs && $climb['gradient_avg'] >= $climbs[$cat + 1]['min_gradient'] && $climb['total_distance'] * 1000 >= $climbs[$cat + 1]['min_distance'] && $climb['total_climbed'] >= $climbs[$cat + 1]['min_height']) { $cat++; } $climb['cat'] = $cat; if ($cat != -1) { /* Store it into the database */ $api->insertClimb($session_timestamp, $climb_num++, $climb['bottom'], $climb['top'], $climb['gradient_avg'], $climb['gradient_max'], $climb['total_distance'], $climb['total_climbed'], $climb['min_altitude'], $climb['max_altitude']); /* Start search for the next climb */ $front = $max; $back = $max; $window_distance = 0; $window_altitude = 0; } else { /* It was a false climb, either not steep enough, * too short, and the window just masked this * Keep searching for the next climb */ } $cat = -1; } /* Move the back of the window up */ while ($window_distance > $min_climb['min_distance'] && $back < $num_records) { $window_distance -= $records[$back]->delta_distance * 1000; $window_altitude -= $records[$back]->delta_altitude; $back++; } } } $timer->setMarker('Climb - End'); /* * Bikes * userid * name * description * type, TT or Road * weight * picture? * Assign a bike to an exercise session at creation time? */ unset($records); $timer->setMarker('Laps - Start'); exec('/usr/local/bin/fitdecode -l ' . $upload['tmp_name'], $xml_laps); $xml_laps = implode("\n", $xml_laps); $laps = parseLaps($xml_laps); $timer->setMarker('Laps - End'); $lap_num = 1; foreach ($laps as $lap) { $ftime = strptime($lap->start_time, '%FT%T%z'); $start_epoch = mktime($ftime['tm_hour'], $ftime['tm_min'], $ftime['tm_sec'], 1, $ftime['tm_yday'] + 1, $ftime['tm_year'] + 1900); $lap_start = $start_epoch - $session_epoch; $api->insertLap($session_timestamp, $lap_num, $lap_start, $lap->start_position_lat, $lap->start_position_long, $lap->total_timer_time, $lap->total_elapsed_time, $lap->total_calories, $lap->avg_heart_rate, $lap->max_heart_rate, $lap->avg_speed, $lap->max_speed, $lap->total_ascent, $lap->total_descent, $lap->total_distance); $lap_num++; } //$timer->display(); $db->commit(); $plans = Module_Plans_API::getInstance(); $view->planned = $plans->getClosestPlan($session_timestamp); $view->session_timestamp = $session_timestamp; $view->UploadStatusMsg = "Is this session the planned exercise session on at ere"; $view->UploadStatus = "Success"; } catch (Exception $e) { $db->rollback(); $view->UploadStatusMsg = "Failed to upload"; $view->UploadStatus = "Error"; echo $e->getMessage(); } $timer->display(); } $view->addForm($form); $view->subTemplate = 'genericForm.tpl'; echo $view->render(); }
/** * @param null $reason * @param null $type */ public static function p404($reason = null, $type = null) { header('HTTP/1.0 404 Not Found'); $view = Core_View::getInstance(); if (is_file($view->getDirectory() . '$maintenance/404.phtml')) { $view->reason = $reason; $view->type = $type; $view->backtrace = debug_backtrace(); $view->setLayoutFile('$maintenance/404.phtml'); $view->enableLayout(); $view->displayLayout(); } else { print '<h1>Page Not Found!</h1>'; if ($reason) { print '<pre>' . $reason . '</pre>'; } print '<pre>'; debug_print_backtrace(); print '</pre>'; } die; }
public function handle() { header('HTTP/1.1 404 Not Found'); Core_View::getInstance()->display('error/404.php'); }