Example #1
0
        $q->execute($art);
        #Get new ID
        if (!$id) {
            $id = $db->lastInsertId();
        }
        #Prepare query for pages
        $q = $db->prepare('REPLACE INTO ' . PRE . 'artstxt (id,page,cat,text,opt)
			VALUES (' . $id . ',?,' . $art['cat'] . ',?,?)');
        #Modify article pages
        foreach ($full as &$x) {
            $q->execute($x);
        }
        #Delete other pages
        $db->exec('DELETE FROM ' . PRE . 'artstxt WHERE ID=' . $id . ' AND page>' . count($full));
        #Apply changes
        $e->apply();
        #Redirect to article
        if (isset($_GET['ref']) && is_numeric($_GET['ref'])) {
            $page = $_GET['ref'] > 1 && isset($full[$_GET['ref'] - 1]) ? '/' . $_GET['ref'] : '';
            header('Location: ' . URL . url('art/' . $id . $page));
        }
        #Info + links
        $view->info($lang['saved'], array(url('art/' . $id) => sprintf($lang['see'], $art['name']), url($art['cat']) => $lang['goCat'], url('edit/1') => $lang['add1'], url('list/1') => $lang['arts'], url('list/1/' . $art['cat']) => $lang['doCat']));
        unset($e, $q, $art, $full);
        return 1;
    } catch (Exception $e) {
        $view->info($e->getMessage());
    }
} else {
    if ($id) {
        $res = $db->query('SELECT * FROM ' . PRE . 'arts WHERE ID=' . $id);