you cannot add users with the same loginname, and you cannot remove the user you are currently logged
   in as, which ensures that there is always atleast one admin user existing on the system */
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);
<?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');
Beispiel #3
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']);
Beispiel #4
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']);
<?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');