Ejemplo n.º 1
0
<?php

$Validator->useSession();
setRedirect('referer');
$scheme_id = !empty($_GET['id']) ? (int) $_GET['id'] : null;
$Validator->validate($scheme_id, 'int', 'ID*2');
if ($Validator->hasErrors()) {
    return;
}
$table = new Tables\Schemes();
$scheme = $table->by('user_id', getUser()->id)->get($scheme_id);
if (!$scheme) {
    return $Validator->setError(__('Scheme with given ID not found.'));
}
$table->delete($scheme_id);
$Ase->happen('cache_update', ['schemes']);
$Validator->setSuccessMessage(__('Scheme deleted.'));
setRedirect('schemes');
Ejemplo n.º 2
0
<?php

$validation_rules = ['id' => ['int', 'ID'], 'name' => ['presence', __('Name')]];
$Validator->validateArray($_POST, $validation_rules);
if ($errors = $Validator->getErrors()) {
    return $Javascript->setErrors($errors)->output();
}
$scheme_id = !empty($_POST['id']) ? (int) $_POST['id'] : null;
$update = !!$scheme_id;
$table = new \Tables\Schemes();
if ($update) {
    // May the current user edit this scheme part?
    $scheme_part = $table->by('user_id', getUser()->id)->get($scheme_id);
    if (!$scheme_part) {
        return $Javascript->setError(__('You are not authorized to edit this scheme.'))->output();
    }
}
if ($update) {
    $table->update($_POST, $scheme_id);
} else {
    $data = $_POST;
    $data['user_id'] = getUser()->id;
    $scheme_id = $table->create($data);
}
# Update scheme scheme parts table.
$table = new \Tables\SchemeSchemeParts();
if ($update) {
    // Delete existing scheme scheme parts.
    $table->by('scheme_id', $scheme_id)->delete();
}
// Add new scheme scheme parts.
Ejemplo n.º 3
0
<?php

$scheme_id = !empty($_GET['id']) ? (int) $_GET['id'] : null;
$page_title = __(sprintf('%s scheme', $scheme_id ? 'Edit' : 'New'));
$scheme_parts = [];
$Crumbs->addCrumb($page_title);
$page_controls = [['text' => __('Back'), 'url' => $Crumbs->getPreviousPageUrl()]];
// Handle edit instead of new:
if ($scheme_id) {
    $table = new Tables\Schemes();
    $scheme = $table->get($scheme_id);
    if (!$scheme) {
        return $Template->output('error', 404);
    } elseif ($scheme->user_id != getUser()->id) {
        return $Template->output('error', 403);
    }
    $page_controls[] = ['text' => __('Delete'), 'url' => 'action/schemes/delete?id=' . $scheme_id, 'confirm_message' => true];
    $scheme_parts = $scheme->getSchemeParts();
}
$Template->output('header', ['title' => $page_title, 'nav_active' => 'schemes']);
$Template->output('page_controls', $page_controls);
$Template->output('validator/status');
?>

<script src="js/page_specific/schemes/scheme.js"></script>
<form action="ajaxa/schemes/save" method="post" class="odf_ajax">

	<?php 
if ($scheme_id) {
    ?>
		<input type="hidden" name="id" value="<?php