Example #1
0
function allowed()
{
    if (checkValidLogin()) {
        return;
    }
    Atomik::redirect('home');
    return;
}
Example #2
0
	public static function getModelBuilder($name)
	{
		if (!class_exists($name, false)) {
			$modelFile = Atomik::path($name . '.php', DbPlugin::$config['model_dirs']);
			include $modelFile;
		}
		
		return Atomik_Model_Builder_Factory::get($name);
	}
Example #3
0
function createManTable($manufacturers)
{
    foreach ($manufacturers as $man) {
        echo '<tr>';
        echo '<td><a href="' . Atomik::url('manpage', array(manufacturerid => $man['manufacturerid'])) . '" title="' . $man['mname'] . '">' . $man['mname'] . '</a></td>';
        echo '<td>' . (int) $man['score'] . '</td>';
        echo '<tr>';
    }
}
Example #4
0
 public function analytics($link, $section, $count = '')
 {
     $accents = array('é', 'û');
     $noaccents = array('e', 'u');
     $today = str_replace($accents, $noaccents, $this->analyticsDate());
     $template = Atomik::get('request.template');
     $issue = Atomik::get('issue');
     $link .= "/?utm_source={$template}-{$today}&amp;utm_medium={$template}&amp;utm_content={$section}-{$count}&amp;utm_campaign={$issue}";
     return $link;
 }
Example #5
0
function createCarTable($cars)
{
    foreach ($cars as $car) {
        echo '<tr>';
        echo '<td><a href="' . Atomik::url('carpage', array(carid => $car['carid'])) . '" title="' . $car['cname'] . '">' . $car['cname'] . '</a></td>';
        echo '<td><a href="' . Atomik::url('manpage', array(manufacturerid => $car['manufacturerid'])) . '" title="' . $car['mname'] . '">' . $car['mname'] . '</a></td>';
        echo '<td>' . $car['score'] . '</td>';
        echo '<tr>';
    }
}
	public function modelSearch(Atomik_Model_Builder $builder)
	{
		$html = '<form action="' . Atomik::url() . '" class="model-search" method="post">Search: '
				. '<input type="text" name="search" value="' . A('search', '', $_POST) . '" /><select name="searchBy">';
		
		foreach ($builder->getFields() as $field) {
			$html .= sprintf("<option value=\"%s\" %s>%s</option>\n", 
				$field->name, 
				isset($_POST['searchBy']) && $_POST['searchBy'] == $field->name ? 'selected="selected"' : '',
				$field->getLabel()
			);
		}
		
		$html .= '</select><input type="submit" value="search" /></form>';
		return $html;
	}
<?php

/* The page for handling adding and removing cars from the database. After login check, the POST array is examined for input.
   Depending on the input a new car is either added to the database or removed from the database. Notable is that also the comments
   about the car are deleted, something which didn't happen in early versions :) */
Atomik::needed('logincheck');
allowed();
if ($_POST['add']) {
    $rule = array('name' => array('required' => true), 'manufacturerkey' => array('required' => true), 'imagename' => array('required' => true));
    if (($data = Atomik::filter($_POST, $rule)) === false) {
        Atomik::flash('Invalid form', 'error');
        Atomik::redirect('carmanagement');
    }
    Atomik_DB::insert('car', $data);
} elseif ($_POST['delete']) {
    $rule = array('carid' => array('required' => true));
    if (($data = Atomik::filter($_POST, $rule)) === false) {
        Atomik::flash('Invalid form', 'error');
        Atomik::redirect('carmanagement');
    }
    echo "Trying to delete carid";
    Atomik_DB::delete('car', $data);
    Atomik_DB::delete('carcomment', $data);
}
Atomik::redirect('carmanagement');
Example #8
0
<?php

/* Comment posting logic. Run-of-the-mill database insertion, only notable thing being the comment text length limit imposed
   by the substr() function on row 13 */
$rule = array('carid' => array('required' => true), 'manufacturerid' => array('required' => true), 'commenttext' => array('required' => true), 'usernickname' => array('required' => true));
if (($data = Atomik::filter($_POST, $rule)) === false) {
    Atomik::flash('Invalid form', 'error');
    Atomik::redirect('carpage&carid=' . $_POST['carid']);
}
$data['commenttext'] = substr($data['commenttext'], 0, 100);
Atomik_DB::insert('carcomment', $data);
Atomik::redirect('carpage&carid=' . $_POST['carid']);
Example #9
0
   The function uses Elo Rating System (http://en.wikipedia.org/wiki/Elo_rating_system/) to determine the adjustments in scoring. The new scores are then
   injected into the database and user is redirected to home */
function calculateNewScores($winnerA, $loserB)
{
    $Qa = pow(10, $winnerA / 400);
    $Qb = pow(10, $loserB / 400);
    $expectedA = $Qa / ($Qa + $Qb);
    $expectedB = 1 - $expectedA;
    $newWinner = (int) ($winnerA + 30 * (1 - $expectedA));
    $newLoser = (int) ($loserB + 30 * (0 - $expectedB));
    if ($newLoser < 150) {
        $newLoser = 150;
    }
    return array($newWinner, $newLoser);
}
$winnerscore = 0;
$loserscore = 0;
$scoreboard = A('db:select carid, score from car');
while ($row = $scoreboard->fetch()) {
    if ($row['carid'] == $_POST['winner']) {
        $winnerscore = $row['score'];
    }
    if ($row['carid'] == $_POST['loser']) {
        $loserscore = $row['score'];
    }
}
$newscores = calculateNewScores($winnerscore, $loserscore);
Atomik_DB::update('car', array('score' => $newscores[0]), array('carid' => $_POST['winner']));
Atomik_DB::update('car', array('score' => $newscores[1]), array('carid' => $_POST['loser']));
Atomik::redirect('home');
Example #10
0
	/**
	 * Returns an Atomik_Db_Script object
	 * 
	 * @return Atomik_Db_Script
	 */
	public static function getDbScript($filter = array(), $echo = false)
	{
		$filter = array_map('ucfirst', $filter);
		
		require_once 'Atomik/Db/Script.php';
		require_once 'Atomik/Db/Script/Output/Text.php';
		require_once 'Atomik/Db/Script/File.php';
		
		$script = new Atomik_Db_Script();
		$script->setOutputHandler(new Atomik_Db_Script_Output_Text($echo));
		
		// plugins
        foreach (Atomik::getLoadedPlugins(true) as $plugin => $path) {
            if ((count($filter) && in_array($plugin, $filter)) || !count($filter)) {
	            if (@is_dir($path . '/models')) {
	                $script->addScripts(Atomik_Db_Script_Model::getScriptFromDir($path . '/models'));
	            }
	            if (@is_dir($path . '/sql')) {
	                $script->addScripts(Atomik_Db_Script_File::getScriptFromDir($path . '/sql'));
	            }
            }
        }
        
        // app
        if ((count($filter) && in_array('App', $filter)) || !count($filter)) {
            foreach (Atomik::path(self::$config['model_dirs'], true) as $path) {
                if (@is_dir($path)) {
                    $script->addScripts(Atomik_Db_Script_Model::getScriptFromDir($path));
                }
            }
            foreach (Atomik::path(self::$config['sql_dirs'], true) as $path) {
                if (@is_dir($path)) {
                    $script->addScripts(Atomik_Db_Script_File::getScriptFromDir($path));
                }
            }
        }
		
		Atomik::fireEvent('Db::Script', array($script, $paths));
		return $script;
	}
Example #11
0
 /**
  * Creates the cache directory when the init command is used.
  * Needs the console plugin
  *
  * @param array $args
  */
 public static function onConsoleInit($args)
 {
     foreach (Atomik::path(self::$config['dir'], true) as $directory) {
     	/* creates cache directory */
     	ConsolePlugin::mkdir($directory, 1);
     	
     	/* sets permissions to 777 */
     	ConsolePlugin::println('Setting permissions', 2);
     	if (!@chmod($directory, 0777)) {
     		ConsolePlugin::fail();
     	}
     	ConsolePlugin::success();
     }
 }
Example #12
0
<?php

/* This script fetches the cars from database, shuffles the result and picks the two topmost ones to display on the page */
$carresult = A('db:carselection');
$allcars = $carresult->fetchAll();
shuffle($allcars);
$leftcar = $allcars[0];
$rightcar = $allcars[1];
Atomik::set('scripts', array_merge(Atomik::get('scripts'), array('assets/js/create_selection_form.js')));
Example #13
0
<?php

/* Another admin page, so admin rights are checked right off the bat. If everything checks out, the manufacturers and cars are loaded from database and placed
   in $carsarray and $manarray variables */
Atomik::needed('logincheck');
allowed();
$manufacturers = A("db: select manufacturerid as manid, name from manufacturer");
$cars = A("db: select carid, name from car");
$carsarray = $cars->fetchAll();
$manarray = $manufacturers->fetchAll();
Example #14
0
<?php

/* Also exactly the same as carpage.post.php. The pages are basically identical. I might've even saved some code if I'd done them
   as one page. But then, this whole exercise has been a learning experience unlike anything else. It is a good thing to
   save certain oversights so you can retrospectively follow your progress. Am I right? */
$rule = array('manufacturerid' => array('required' => true), 'commenttext' => array('required' => true), 'usernickname' => array('required' => true));
if (($data = Atomik::filter($_POST, $rule)) === false) {
    Atomik::flash('Invalid form', 'error');
    Atomik::redirect('manpage&manufacturerid=' . $_POST['manufacturerid']);
}
$data['commenttext'] = substr($data['commenttext'], 0, 100);
Atomik_DB::insert('manufacturercomment', $data);
Atomik::redirect('manpage&manufacturerid=' . $_POST['manufacturerid']);
Example #15
0
}

$modelName = Atomik::get('request/name');
$returnUrl = Atomik::get('request/returnUrl', Atomik::url('models/list', array('name' => $modelName)));
$builder = Atomik_Backend_Models::getModelBuilder($modelName);

$actionString = 'created';
$title = __('Create a new') . ' %s';
$message = __('A %s has been created', strtolower($modelName));

$model = $modelName;
if (Atomik::has('request/id')) {
	$model = Atomik_Model::find($builder, Atomik::get('request/id'));
	$actionString = 'modified';
	$title = __('Edit') . ' %s: ' . $model;
	$message = __('%s %s has been modified', $modelName, $model);
}

$form = new Atomik_Model_Form($model, array('form-', 'admin-form-'));
$form->setAction(Atomik::url());
$form->setOption('cancel-url', $returnUrl);

if ($form->hasData()) {
	if ($form->isValid()) {
		$model = $form->getModel();
		$model->save();
		Backend_Activity::create('Models', $message, __(ucfirst($actionString) . ' by') . ' %s');
		Atomik::redirect($returnUrl, false);
	}
	Atomik::flash($form->getValidationMessages(), 'error');
}
<?php

/* Quite similar to the carmanagement-business.php. Only difference is that when deleting a manufacturer,
   also the cars and comments associated with those cars are deleted. A car cannot exist without a manufacturer,
   is the reasoning behind this logic. */
Atomik::needed('logincheck');
allowed();
if ($_POST['submit'] == 'add') {
    $rule = array('name' => array('required' => true), 'imagename' => array('required' => true));
    if (($data = Atomik::filter($_POST, $rule)) === false) {
        Atomik::flash('Invalid form', 'error');
        Atomik::redirect('manufacturermanagement');
    }
    Atomik_DB::insert('manufacturer', $data);
} elseif ($_POST['submit'] == 'delete') {
    $rule = array('manufacturerkey' => array('required' => true));
    if (($data = Atomik::filter($_POST, $rule)) === false) {
        Atomik::flash('Invalid form', 'error');
        Atomik::redirect('manufacturermanagement');
    }
    Atomik_DB::delete('car', $data);
    $data = array('manufacturerid' => $data['manufacturerkey']);
    Atomik_DB::delete('manufacturer', $data);
    Atomik_DB::delete('carcomment', $data);
    Atomik_DB::delete('manufacturercomment', $data);
}
Atomik::redirect('manufacturermanagement');
	protected function _getUrl($field, $value = '')
	{
		return Atomik::url(null, array('filters' => array($field => $value)));
	}
Example #18
0
<?php

Atomik::set(array('plugins' => array('Db' => array('dsn' => 'sqlite:example.db'), 'Session', 'Flash', 'Errors' => array('catch_errors' => true)), 'atomik.debug' => true, 'app.layout' => '_layout'));
<?php

Atomik::loadHelper('autoComplete');

class ModelAutoCompleteHelper extends AutoCompleteHelper
{
	protected $field;
	
	public function modelAutoComplete($id, $model, $field)
	{
		$this->field = $field;
		$query = Atomik_Model_Query::create()->from($model)->where('LOWER(' . $field . ') LIKE ?')->limit(10);
		return $this->autoComplete($id, $query);
	}
	
	public function getFilteredData($query, $value)
	{
		$query->setParam(0, $value . '%');
		$rows = Atomik_Model::query($query);
		
		$data = array();
		foreach ($rows as $row) {
			$data[$row->getPrimaryKey()] = $row->{$this->field};
		}
		
		return $data;
	}
}
Example #20
0
<?php

require 'vendor/autoload.php';
Atomik::run();
Atomik::needed('logincheck');
allowed();
if ($_POST['add']) {
    $rule = array('adminnick' => array('required' => true), 'adminpassword' => array('required' => true));
    if (($data = Atomik::filter($_POST, $rule)) === false) {
        Atomik::flash('Invalid form', 'error');
        Atomik::redirect('loginmanagement');
    }
    $hashpassword = md5($data['adminpassword']);
    $data['adminpassword'] = $hashpassword;
    $searchresult = A('db: select adminid from admin where adminnick=\'' . $data['adminnick'] . '\'');
    $datarow = $searchresult->fetch();
    if (empty($datarow)) {
        Atomik_DB::insert('admin', $data);
        Atomik::redirect('loginmanagement');
    }
    Atomik::flash('Admin with similar username already exists', 'error');
    Atomik::redirect('loginmanagement');
} elseif ($_POST['delete']) {
    $rule = array('adminid' => array('required' => true));
    if (($data = Atomik::filter($_POST, $rule)) === false) {
        Atomik::flash('Invalid form', 'error');
        Atomik::redirect('loginmanagement');
    }
    if ($data['adminid'] == $_SESSION['adminid']) {
        Atomik::flash("Can't delete a session you are currently logged in as", 'error');
        Atomik::redirect('loginmanagement');
    }
    Atomik_DB::delete('admin', $data);
    Atomik::redirect('loginmanagement');
}
<?php

Atomik::loadHelper('dataTable');

class DbDataTableHelper extends DataTableHelper
{
	public function dbDataTable($id = null, Atomik_Db_Query $query = null, $options = array())
	{
		$this->dataTable($id, array(), $options);
		
		if ($this->options['sortColumn']) {
			$query->orderBy($this->options['sortColumn'], $this->options['sortOrder']);
		}
		
		$countQuery = clone $query;
		$result = $countQuery->count()->execute();
		$numberOfRows = $result->fetchColumn();
		$result->closeCursor();
		
		$this->options['paginateData'] = false;
		$this->options['sortData'] = false;
		$this->options['numberOfRows'] = $numberOfRows;
		
		$offset = ($this->options['currentPage'] - 1) * $this->options['rowsPerPage'];
		$query->limit($offset, $this->options['rowsPerPage']);
		
		$this->setData($query->execute());
		
		return $this;
	}
}
Example #23
0
<?php

/* Another simple script. If someone is already logged in, but wanders to the login page, he is redirected to the admin home page */
Atomik::needed('logincheck');
if (checkValidLogin()) {
    Atomik::redirect('adminhome');
}
Example #24
0
 public function offsetUnset($key)
 {
     return Atomik::delete($key);
 }
 public function annonceUne($url, $img)
 {
     $data = new DataController($url);
     $db = Atomik::get('db');
     $this->title = $data->fetchTitle('h1', 1);
     $this->text = $data->fetchCalendarText();
     $this->link = $data->fetchLink();
     $funtionName = __FUNCTION__;
     $this->viewOutput = Atomik::render('blocs/leadArticle', array('title' => $this->title, 'text' => $this->text, 'link' => $this->link, 'img' => $img, 'section' => $funtionName));
     echo $this->viewOutput;
 }
 public function index()
 {
     $json = file_get_contents(Atomik::get('base_dir') . '/app/models/magazines.json');
     $this->newsletters = json_decode($json, true);
 }
Example #27
0
<?php

Atomik::set(array('app/layout' => '_layout', 'styles' => array('assets/css/main.css'), 'scripts' => array()));
/*This is where the database configuration is done. The default is a database called "coolcars"
with an user named "webapp", but these can be changed for different deployments*/
Atomik::set('plugins/Db', array('dsn' => 'pgsql:host=localhost;dbname=coolcars', 'username' => 'webapp', 'password' => ''));
Example #28
0
<?php

if (!Atomik::has('request/name') || !Atomik::has('request/id')) {
	Atomik::redirect('index');
}

$modelName = Atomik::get('request/name');
$returnUrl = Atomik::get('request/returnUrl', Atomik::url('models/list', array('name' => $modelName)));
$model = Atomik_Model::find($modelName, Atomik::get('request/id'));
$title = (string) $model;

if (!$model->delete()) {
	Atomik::flash(__('An error occured while deleting %s %s', strtolower($modelName), $title), 'error');
} else {
	Atomik::flash(__('%s %s successfully deleted', $modelName, $title), 'success');
	Backend_Activity::create('Models', __('%s %s has been deleted', $modelName, $title), __('Deleted by') . ' %s');
}

Atomik::redirect($returnUrl, false);
Example #29
0
<?php

Atomik::set(array('base_dir' => 'C:\\wamp\\www\\responsive-newsletter-maker-V3', 'plugins' => array('DebugBar' => array('include_vendors' => 'css'), 'Errors' => array('catch_errors' => true), 'Session', 'Flash', 'Controller', 'Db' => array('dsn' => 'mysql:host=localhost;dbname=newsletter_maker', 'username' => 'root', 'password' => '')), 'atomik' => array('url_rewriting' => true, 'debug' => true, 'model_dirs' => 'app/models'), 'language' => array('autodetect' => false), 'app' => array('layout' => '_layout', 'language' => 'fr', 'routes' => array('templates' => array('@name' => 'default', 'action' => 'Templates/default/index'), 'newsletter/:issue' => array('action' => 'templates/newsletter/index'), 'flash/:issue' => array('action' => 'templates/flash/index'), 'topfive/:issue' => array('action' => 'templates/topfive/index'), 'rh/:issue' => array('action' => 'templates/rh/index'), 'issues' => array('@name' => 'default', 'action' => 'Issues/default/index'), 'create/:template/audio' => array('action' => 'issues/audio/index'), 'create/:template/biologiste' => array('action' => 'issues/biologiste/index'), 'create/:template/nutrition' => array('action' => 'issues/nutrition/index'), 'create/:template/audiologyIT' => array('action' => 'issues/audioit/index'), 'create/:template/audiologyBR' => array('action' => 'issues/audiobr/index'), 'create/:template/audiologyDE' => array('action' => 'issues/audiode/index'), 'create/:template/audition' => array('action' => 'issues/audition/index'), 'create/:template/audiologyWN' => array('action' => 'issues/audiologywn/index'), 'create/:template/audioenportada' => array('action' => 'issues/audioes/index'), 'create/:template/pharma' => array('action' => 'issues/pharma/index'), 'create/:template/dentaire' => array('action' => 'issues/dentaire/index'), 'create/:template/audiology' => array('action' => 'issues/audiology/index')))));
Example #30
0
 /**
  * Resets the global store
  * 
  * If no argument are specified the store is resetted, otherwise value are set normally and the
  * state is saved.
  * 
  * @internal 
  * @see Atomik::set()
  * @param array|string $key      Can be an array to set many key/value
  * @param mixed $value
  * @param bool $dimensionize     Whether to use Atomik::_dimensionizeArray() on $key
  */
 public static function reset($key = null, $value = null, $dimensionize = true)
 {
     if ($key !== null) {
         self::set($key, $value, $dimensionize, self::$reset);
         self::set($key, $value, $dimensionize);
         return;
     }
     
     // reset
     self::$store = self::_mergeRecursive(self::$store, self::$reset);
 }