public static function index() { $count = new Utilities(); $count->countDrinks(); $drinks = Drink::findAll(); View::make('drink/index.html', array('drinks' => $drinks, 'count' => $count)); }
public function __call($name, $arguments) { $file = ''; foreach ($arguments as $key => $argument) { if (empty($argument)) { unset($arguments[$key]); continue; } if (!is_array($argument)) { continue; } if (isset($argument['folder'])) { $file .= $argument['folder']; unset($arguments[$key]); } } if (!empty($arguments)) { $filename = array(implode('.', $arguments), $name, self::FILE_EXTENSION); } else { $filename = array($name, self::FILE_EXTENSION); } $file .= '/' . implode('.', $filename); if (file_exists(CONTRIB_PATH . self::FOLDER . $file)) { header('Cache-Control: no-store, no-cache, must-revalidate, max-age=0'); header('Etag: ' . md5(file_get_contents(CONTRIB_PATH . self::FOLDER . $file))); header('Vary: *'); header('Last-Modified: ' . gmdate('D, d M Y H:i:s', filemtime(CONTRIB_PATH . self::FOLDER . $file)) . ' GMT'); header('Content-type: ' . Utilities::getMimeType(self::FILE_EXTENSION)); echo file_get_contents(CONTRIB_PATH . self::FOLDER . $file); exit; } else { $this->bye(); } }
public function get($qid, $class, $student) { if ($student != USERNAME) { Permissions::TA_GATE($qid, $class, USERNAME); } $config = Utilities::get_configuration($qid, $class); $class_dir = Utilities::get_class_base($qid, $class); $assns = Utilities::get_all_directories($class_dir . "/" . $config->submissions_dir); $student_submissions = array(); foreach ($assns as $assn) { $a_dir = $class_dir . "/" . $config->submissions_dir . "/" . $assn; $all_subs = Utilities::get_all_directories($a_dir); foreach ($all_subs as $sub) { $sunetid = Utilities::get_sunetid($sub); if ($sunetid == $student) { $test = $a_dir . "/" . $sub; if (is_dir($test)) { $student_submissions[] = array("assn" => $assn, "dir" => $sub); } } } } //print_r($student_submissions); $this->smarty->assign("student", $student); $this->smarty->assign("submissions", $student_submissions); $this->smarty->display("student.html"); }
/** * @method POST */ function pay() { // get token $token = Utilities::ValidateJWTToken(apache_request_headers()); // check if token is not null if ($token != NULL) { // parse request parse_str($this->request->data, $request); $site = Site::GetBySiteId($token->SiteId); $siteId = $site['SiteId']; $email = $site['PrimaryEmail']; $status = 'Active'; $stripe_token = $request['token']; $plan = $request['plan']; // set API key Stripe::setApiKey(STRIPE_SECRET_KEY); // create a new customer and subscribe them to the plan $customer = Stripe_Customer::create(array("card" => $stripe_token, "plan" => $plan, "email" => $email)); // get back the id and the end period for the plan $id = $customer->id; // get subscription information $subscription = $customer->subscriptions->data[0]; $subscriptionId = $subscription->id; $stripe_status = $subscription->status; $stripe_plan = $subscription->plan->id; $stripe_planname = $subscription->plan->name; // subscribe to a plan Site::Subscribe($siteId, $status, $plan, 'stripe', $subscriptionId, $customerId); // return a json response return new Tonic\Response(Tonic\Response::OK); } else { return new Tonic\Response(Tonic\Response::UNAUTHORIZED); } }
public static function error($message, $class = "N/A", $method = "N/A") { if (LOG_LEVEL == "ERROR") { Utilities::checkSize(LOG_FOLDER . "debug.log"); error_log("/r/n[ERROR] " . date("Y-m-d h:i:s") . " - [" . str_pad($class, 20, " ") . "] - [" . str_pad($method, 20, " ") . "] - " . $message . "", 3, LOG_FOLDER . "error.log"); } }
/** * Create a new translatable email * * @param DBObject $context * @param string $translation_id * @param array $variables * * @return TranslatableEmail */ public static function create($translation_id, $variables) { $email = new self(); // Get translation data and variables $email->translation_id = $translation_id; $email->variables = array(); if ($variables) { foreach ($variables as $k => $v) { // Convert DBObject types to type/id pairs for saving if ($v instanceof DBObject) { $v = array('dbobject_type' => get_class($v), 'dbobject_id' => $v->id); } $email->variables[$k] = $v; } } // Add meta $email->created = time(); // Generate token until it is indeed unique $email->token = Utilities::generateUID(function ($token) { $statement = DBI::prepare('SELECT * FROM ' . TranslatableEmail::getDBTable() . ' WHERE token = :token'); $statement->execute(array(':token' => $token)); $data = $statement->fetch(); return !$data; }); $email->save(); return $email; }
public static function register($device_uuid) { $parts = explode(" ", microtime()); $data = array('id' => $parts[1] . round($parts[0] * 1000), 'secret_key' => \Utilities::getRandomCode(64), 'device_uuid' => $device_uuid); $inserted = static::instance()->createEntity($data)->save(); return $inserted ? static::instance()->getEntity($data['id']) : null; }
function __construct($message, $type) { $bootstrap = false; if (!empty(Utilities::FindKey('BootstrapMessages', $GLOBALS['Config']))) { $bootstrap = Utilities::FindKey('BootstrapMessages', $GLOBALS['Config']); } switch (strtoupper($type)) { default: case 'ERR': case 'ERROR': $style = 'danger'; break; case 'SUCC': case 'SUCCESS': $style = 'success'; break; case 'WARN': case 'WARNING': $style = 'warning'; break; case 'INFO': case 'INFORMATION': $style = 'info'; break; } if ($bootstrap === true) { $message = '<p class="alert alert-' . $style . '" role="alert">' . $message . '</p>'; } echo $message; }
/** * @method POST */ function form() { // parse request parse_str($this->request->data, $request); $siteUniqId = SITE_UNIQ_ID; $pageUniqId = $request['pageUniqId']; $body = $request['body']; $site = Site::GetBySiteUniqId($siteUniqId); $page = Page::GetByPageUniqId($pageUniqId); if ($site != null && $page != null) { $subject = 'RespondCMS: Form Submission [' . $site['Name'] . ': ' . $page['Name'] . ']'; $content = '<h3>Site Information</h3>' . '<table>' . '<tr>' . '<td style="padding: 5px 25px 5px 0;">Site:</td>' . '<td style="padding: 5px 0">' . $site['Name'] . '</td>' . '</tr>' . '<tr>' . '<td style="padding: 5px 25px 5px 0;">Page:</td>' . '<td style="padding: 5px 0">' . $page['Name'] . '</td>' . '</tr>' . '</table>' . '<h3>Form Details</h3>' . $body; // send an email $headers = 'MIME-Version: 1.0' . "\r\n"; $headers .= 'Content-type: text/html; charset=utf-8' . "\r\n"; $headers .= 'From: ' . $site['PrimaryEmail'] . "\r\n" . 'Reply-To: ' . $site['PrimaryEmail'] . "\r\n"; // sends the email $to = $site['PrimaryEmail']; $from = $site['PrimaryEmail']; $fromName = $site['Name']; Utilities::SendEmail($to, $from, $fromName, $subject, $content); // return a successful response (200) return new Tonic\Response(Tonic\Response::OK); } else { // unauthorized access return new Tonic\Response(Tonic\Response::UNAUTHORIZED); } }
protected function getEntryCategories($entries) { $cat_arr = array(); if (isset($entries[0]['data2'])) { foreach ($entries as $e) { $cat_url = strtolower(Utilities::makeUrl($e['data2'])); if (!isset($cat_arr[$cat_url])) { $cat_arr[$cat_url] = array('category-url' => "{$this->url0}/category/{$cat_url}", 'category-name' => $e['data2'], 'count' => 1); } else { $cat_arr[$cat_url]['count'] += 1; } } /* * Sort the array */ usort($cat_arr, "CategorizedGallery::cmp"); /* * Load the template into a variable */ $template = UTILITIES::loadTemplate($this->url0 . '-category.inc'); return UTILITIES::parseTemplate(array_values($cat_arr), $template); } else { return NULL; } }
function get($request) { // admin Only Utilities::checkAdmin(); $db = Database::obtain(); $response = new Response($request); $this->tm->smarty->assign('title', 'Admin Infos Tours'); $no_tours = $db->query_first("SELECT count(*) AS no FROM " . TABLE_TOURS); $no_tours = $no_tours['no']; $last_page = ceil($no_tours / $this->rows); //this makes sure the page number isn't below one, or more than our maximum pages if ($this->page < 1) { $this->page = 1; } elseif ($this->page > $last_page) { $this->page = $last_page; } $max = 'LIMIT ' . ($this->page - 1) * $this->rows . ',' . $this->rows; $tours = $db->fetch_array("SELECT * FROM `" . TABLE_TOURS . "` " . $max); $this->tm->smarty->assign('lastpage', $last_page); $this->tm->smarty->assign('pagenum', $this->page); $em = GeocacheManager::getInstance(); $tours_obj = array(); foreach ($tours as $tour) { $tours_obj[] = $geocacheManager = $em->fetchTour($tour['webcode']); } $this->tm->smarty->assign('tours', $tours_obj); $body = $this->tm->render('admin_info_tour'); $response->code = Response::OK; $response->addHeader('Content-type', 'text/html'); $response->body = $body; return $response; }
/** * Retrieves a list of models based on the current search/filter conditions. * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions. */ public function search() { // Warning: Please modify the following code to remove attributes that // should not be searched. $criteria = new CDbCriteria(); if (isset($this->city)) { $this->city = Utilities::getLookupIdByValue(Constants::$city_lookup_code, $this->city); } if (isset($this->blood_group)) { $this->blood_group = Utilities::getLookupIdByValue(Constants::$bloodgrp_lookup_code, $this->blood_group); } if (isset($this->area)) { $this->area = Utilities::getLookupIdByValue(Constants::$area_lookup_code, $this->area); } $criteria->compare('request_id', $this->request_id); $criteria->compare('name', $this->name, true); $criteria->compare('city', $this->city); $criteria->compare('state', $this->state); $criteria->compare('number', $this->number, true); $criteria->compare('date', $this->date, true); $criteria->compare('blood_group', $this->blood_group); $criteria->compare('area', $this->area); $criteria->compare('status', $this->status, true); $criteria->compare('remarks', $this->remarks, true); $criteria->compare('donor', $this->donor); return new CActiveDataProvider($this, array('criteria' => $criteria)); }
public function __construct($title, $message, $code = 500, Exception $previous = null) { $this->title = $title; parent::__construct($message, $code, $previous); Utilities::statusCode($code, $title); Utilities::sendHeaders(); }
/** * StringsHandler constructor. */ public function __construct() { $config = Config::getInstance(); $adapterClass = __NAMESPACE__ . '\\ConfigAdapter\\' . Utilities::formatClassName($config->get('strings_adapter', 'ini')); $this->adapter = new $adapterClass('strings'); $this->loadStrings(); }
public function admin_reset_password($token = null) { if ($this->Auth->loggedIn()) { $this->redirect('/admin/index'); } if (!isset($token)) { if ($this->request->is('post')) { $user = $this->User->findByEmail($this->request->data['User']['email']); if (empty($user)) { $this->Session->setFlash('W bazie nie ma takiego adresu e-mail', 'flash_warning'); $this->redirect('/admin/users/reset_password'); } $token = Utilities::token(); $this->adminSendMail($this->request->data['User']['email'], 'kAdmin - resetowanie hasła', 'reset_password', array('username' => $user['User']['username'], 'link' => '<a href="' . Router::url('/admin/users/reset_password/' . $token, true) . '">' . Router::url('/admin/users/reset_password/' . $token . $user['User']['id'], true) . '</a>')); $this->User->id = $user['User']['id']; $this->User->saveField('token', $token); $this->set('afterPost', true); } } else { $user = $this->User->findByToken($token); if (empty($user)) { throw new NotFoundException('Podany token jest nieprawidłowy.'); } $pass = substr(str_shuffle('abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!$'), 0, 6); $this->User->id = $user['User']['id']; $this->User->save(array('token' => null, 'password' => $pass), false); $this->adminSendMail($user['User']['email'], 'kAdmin - resetowanie hasła', 'new_password', array('password' => $pass, 'username' => $user['User']['username'])); $this->set('afterReset', true); } }
/** * Updates a particular model. * If update is successful, the browser will be redirected to the 'view' page. * @param integer $id the ID of the model to be updated */ public function actionUpdate($id) { $model = $this->loadModel($id); // Uncomment the following line if AJAX validation is needed // $this->performAjaxValidation($model); if (isset($_POST['DonationRequest'])) { $model->attributes = $_POST['DonationRequest']; $model->city = Utilities::getLookupIdByValue(Constants::$city_lookup_code, $model->city); $model->blood_group = Utilities::getLookupIdByValue(Constants::$bloodgrp_lookup_code, $model->blood_group); $model->area = Utilities::getLookupIdByValue(Constants::$area_lookup_code, $model->area); $model->state = $model->city0->lookup_parent_id; if (!Utilities::checkDateFormat($model->date)) { $model->date = DateTime::createFromFormat('d/M/yyyy', $model->date)->format('Y-m-d'); } if ($model->save()) { if ($model->status == "Donor Assigned") { $donor = UserDetails::model()->findByPk($model->donor); $donor->last_donation_date = date("Y-m-d"); $donor->donation_status = 'Y'; $donor->save(false); } $this->redirect(array('view', 'id' => $model->request_id)); } } $model->city = $model->city0->lookup_value; $model->area = $model->area0->lookup_value; $model->blood_group = $model->bloodGroup->lookup_value; //$model->date = DateTime::createFromFormat('Y-m-d', $model->date )->format('d/M/y'); $this->render('update', array('model' => $model)); }
/** * @param GeocodeCached $geocode Previously stored geoLocation information * @param string $currentDate date for showtimes to load, advisable to pass it in * @param int $dateOffset number of days from the current dates * @return TheatreData[] an array of schema TheatreData, see below for description * * Organized in the format => * * ``` * * TheatreData : [ * 'theatre' => [ * ...fields from theatre table, MUST contain name and address..., * ] * 'movies' => MovieData[] * ] * * MovieData : [ * 'movie' => [ * ...fields from movie table, MUST contain title..., * ] * 'showtimes' => ShowtimeData[] * ] * * ShowtimeData: [ * ...fields from showtime table, must conatin show_date, show_time & type... * ] * ``` */ public function loadShowtimes(GeocodeCached $geocode, $currentDate = null, $dateOffset = 0) { $params = ['country' => $geocode->country_iso, 'event_date' => \Utilities::dateFromOffset($currentDate ?: date('Y-m-d'), $dateOffset)]; \SystemLogger::debug('Begining API Request to Tripican'); $start = microtime(true); $allCinemaMovieShowtimes = TripicanDataLoader::GetCinemaMovieShowtimes($this->apiClient, $params); \SystemLogger::debug('Request to API completed in :', microtime(true) - $start); $theatres = []; foreach ($allCinemaMovieShowtimes as $cinemaMovieShowtimes) { $theatre = $cinemaMovieShowtimes['cinema']; $id = $theatre['id']; if (!isset($theatres[$id])) { $theatres[$id] = ['theatre' => ['name' => $theatre['centre_name'], 'address' => $this->_getAddress($theatre), 'longitude' => $theatre['place']['long'], 'latitude' => $theatre['place']['lat']], 'movies' => []]; } $theatreData =& $theatres[$id]; foreach ($cinemaMovieShowtimes['movie_showtimes'] as $movieShowtimes) { $movie = $movieShowtimes['movie']; $mId = $movie['id']; if (!isset($theatreData['movies'][$mId])) { $theatreData['movies'][$mId] = ['movie' => ['title' => $movie['title'], 'genre' => $movie['genre'][0], 'user_rating' => isset($movie['imdb_rating']) ? floatval($movie['imdb_rating'][0] / 10.0) : null, 'poster_url' => $movie['poster'], 'rated' => $movie['rated'][0], 'runtime' => $movie['duration']], 'showtimes' => []]; } $movieData =& $theatreData['movies'][$mId]; foreach ($movieShowtimes['showtimes'] as $showtime) { $movieData['showtimes'][] = ['show_date' => $showtime['event_date'], 'show_time' => $showtime['event_time'], 'type' => $this->_getMapType($showtime['type']), 'url' => $showtime['online_ticketing'] ? $showtime['url'] : null]; } } } array_walk($theatres, function (&$t) { $t['movies'] = array_values($t['movies']); }); if (!empty($theatres)) { $this->overrideDistanceCompute(); } return array_values($theatres); }
public function loginView() { $users = User::all(); if (count($users) == 0) { $token = Utilities::generateTokenForm(); $action = $this->app->urlFor('add_admin'); $vars = array(); if (isset($_SESSION['vars'])) { $vars = $_SESSION['vars']; unset($_SESSION['vars']); } $this->view = new NewAdmin($action, $token['token'], $vars); $this->view->display(); } else { $action = $this->app->urlFor('login_post'); $token = Utilities::generateTokenForm(); $vars = array(); if (isset($_SESSION['vars'])) { $vars = $_SESSION['vars']; unset($_SESSION['vars']); } $this->view = new LoginView($action, $token['token'], $vars); $this->view->display(); } }
/** * Find a controller based on the parsed request path */ protected function findController() { $parts = $this->path; $className = '\\Controllers\\'; array_pop($parts); $dir = APPLICATION_PATH . '/controllers/'; foreach ($parts as $part) { if (file_exists($dir . $part . '.php')) { $this->controller = $dir . $part . '.php'; $this->controllerClassName = $className . Utilities::formatClassName($part); return; } if (!is_dir($dir . $part . '/')) { break; } $dir .= $part . '/'; if (file_exists($dir . 'Index.php')) { $this->controller = $dir . 'Index.php'; $this->controllerClassName = $className . 'Index'; return; } } if (file_exists($dir . 'Index.php')) { $this->controller = $dir . 'Index.php'; $this->controllerClassName = $className . 'Index'; } }
public function __construct($Object) { $this->CachePath = getcwd() . DS . "Cache" . DS . "Compile" . DS . $Object . DS; $this->CacheExtension = '.fnc'; $this->CacheLife = 86400; $this->CacheObject = $Object; $this->CacheLocale = Utilities::GetLanguage(true); }
public static function singleton() { if (!isset(self::$instance)) { $c = __CLASS__; self::$instance = new $c(); } return self::$instance; }
public function formatTableName(TableInformation $table) { $table_names = []; foreach ($this->tables as $table_object) { $table_names[] = $table_object->name; } return Utilities::formatObjectName($table->name, $table_names); }
public static function mkdirs($file) { $dir = dirname($file); if (!file_exists($dir)) { Utilities::mkdirs($dir); mkdir($dir); } }
function testTitleMimeType() { $this->assertEqual('application/epub+zip', Utilities::titleMimeType('x/y/test.epub')); $this->assertEqual('application/vnd.amazon.ebook', Utilities::titleMimeType('test.azw')); $this->assertEqual('application/x-mobipocket-ebook', Utilities::titleMimeType('test.mobi')); $this->assertEqual('text/plain', Utilities::titleMimeType(self::FIXT . '/test.unknown-format')); $this->assertEqual('application/xml', Utilities::titleMimeType(self::FIXT . '/atom.rng')); }
public static function Initialize() { Autoloader::InitialCheck(); Autoloader::LoadConfig(); Autoloader::LoadComponents(); if (Autoloader::$IsDebugEnabled) { Autoloader::$PageLoadTime = Utilities::PageLoadTime(true); } }
public function joinMaestroView($attempt = 0) { $attempt = strip_tags(htmlspecialchars($attempt)); $attempt = filter_var($attempt, FILTER_SANITIZE_NUMBER_INT); $attempt = filter_var($attempt, FILTER_VALIDATE_INT); $attempt = intval($attempt); $this->view = new JoinView($this->app->urlFor('admin-maestro-post'), Utilities::createToken(), $attempt); $this->view->display(); }
public function register($user_name, $password, $first_name, $last_name) { if (!is_null(UserModel::findFirst(array('user_name' => $user_name)))) { return UserHandler::ERROR_EXISTS; } $user = UserModel::create(array('user_name' => $user_name, 'password' => Utilities::hash($password, static::$salt), 'first_name' => $first_name, 'last_name' => $last_name, 'lang' => I18N::lang())); $this->_login($user); return $user; }
static function fileExists($file) { $page = self::getFilePath($file); if (!file_exists($page)) { Utilities::log("Cannot find file for render {$page}"); return false; } return true; }
public function testEncryptDecrypt() { $treasure = "The quick brown fox jumped over the lazy dogs."; $salt = "I am the keymaster."; $iv = Utilities::newIv(); $encrypted = Utilities::encrypt($salt, $iv, $treasure); $decrypted = Utilities::decrypt($salt, $iv, $encrypted); $this->assertEquals($treasure, $decrypted); }
public function get($qid, $class, $assn) { Permissions::TA_GATE($qid, $class, USERNAME); $assn_dir = Utilities::get_assn_base($qid, $class, $assn); $students = Utilities::get_all_directories($assn_dir); $this->smarty->assign("class", $class); $this->smarty->assign("assn", $assn); $this->smarty->assign("students", $students); $this->smarty->display("assignment.html"); }