Ejemplo n.º 1
0
<?php

require __DIR__ . '/../../../init.php';
$error = array();
if (empty($_GET['name']) && empty($_POST['name'])) {
    redirect();
}
$name = isset($_GET['name']) ? $_GET['name'] : $_POST['name'];
$trick = new Trick($db, $user->get_id());
$tag = new Tag($db, $user->get_id());
$tricks = $trick->by_name($name);
$tricks_old = array_select_prefix($tricks);
$tags_old = array_select_key($tricks, 'tag_id');
$stances_old = array_select_key($tricks, 'stance');
$directions_old = array_select_key($tricks, 'direction');
$tags_all = $tag->all();
$tags_echo = tag_ids_checkbox_ul($tags_all, $tags_old);
if (!$tags_echo) {
    redirect('/tag/create/index.php?no_tags=1');
}
if (isset($_POST['name'])) {
    if (strlen(validate_name($_POST['name'])) > 0) {
        $error['name'] = validate_name($_POST['name']);
    }
    if (isset($_POST['tag_ids']) && count($_POST['tag_ids']) == 0) {
        $error['tag_ids'] = 'no tags were selected';
    }
    if (count($error) == 0) {
        $prefixes = generate_prefixes(array_keys($_POST['stance']), array_keys($_POST['direction']), $_POST['tag_ids']);
        $delete_tricks = compare_prefixes($tricks_old, $prefixes);
        $create_tricks = compare_prefixes($prefixes, $tricks_old);