function allowed() { if (checkValidLogin()) { return; } Atomik::redirect('home'); return; }
<?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'); }
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 /* 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']);
<?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');
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');
<?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);
<?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']);
<?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');
<?php if (!Atomik::has('request/name')) { Atomik::redirect('index'); } $modelName = Atomik::get('request/name'); $builder = Atomik_Backend_Models::getModelBuilder($modelName); $models = new Atomik_Model_Query(); $models->from($builder)->filter(Atomik::get('request/filters', array())); if (isset($_POST['search'])) { $models->where($_POST['searchBy'] . ' LIKE ?', '%' . $_POST['search'] . '%'); } $columns = array(); foreach ($builder->getFields() as $field) { if (($builder->isFieldThePrimaryKey($field) || $builder->isFieldPartOfReference($field) || $field->hasOption('admin-hide-in-list')) && !$field->hasOption('admin-show-in-list')) { continue; } $columns[$field->name] = $field->getLabel(); } $editUrl = Atomik::get('request/editUrl', Atomik::url('models/edit', array('name' => $modelName))); $deleteUrl = Atomik::get('request/deleteUrl', Atomik::url('models/delete', array('name' => $modelName)));