Example #1
0
function module_add_article()
{
    global $flashformid;
    echo "\n<!-- start add article -->";
    $all_ok = true;
    // Error checking
    // create short variable names
    $edit = $_REQUEST['editarticle'];
    // Is this an edit operation?
    // User has confirmed a previewed article, get values from session
    if (isset($_REQUEST['previewconfirmed'])) {
        $author = $_SESSION['author'];
        $title = $_SESSION['title'];
        $intro = $_SESSION['intro'];
        $body = $_SESSION['body'];
        $priority = $_SESSION['priority'];
        $date_posted = $_SESSION['date_posted'];
        $time_posted = $_SESSION['time_posted'];
        $comment_to = $_SESSION['comment_to'];
        $articleid = $_SESSION['articleid'];
        $category = $_SESSION['category'];
        $is_draft = $_SESSION['is_draft'];
    } else {
        $author = $_POST['author'];
        $title = $_POST['title'];
        $intro = $_POST['intro'];
        $body = $_POST['body'];
        $priority = $_POST['priority'];
        $date_posted = $_POST['year'] . "-" . $_POST['month'] . "-" . $_POST['day'];
        $time_posted = $_POST['hours'] . ":" . $_POST['minutes'];
        $comment_to = $_POST['comment_to'];
        $articleid = $_POST['articleid'];
        $category = $_REQUEST['category'];
        $category = 0;
        $is_draft = $_POST['is_draft'];
        $article_form_id = $_REQUEST['article_form_id'];
    }
    // Replace form-given time with real time if this is a comment
    if ($comment_to > 0) {
        $date_posted = date("Y") . "-" . date("m") . "-" . date("d");
        $time_posted = date("H") . ":" . date("i");
    } else {
    }
    // Can occur if someone posts after session is deleted. Return whatever
    // contents is sent to us.
    global $anyone_comments;
    if (!$anyone_comments && !is_logged_in()) {
        echo "Du må være innlogget for å kunne kommentere; dersom du ikke gjør noe på nettstedet i løpet av omtrent 25 minutter blir du logget ut. Teksten du forsøkte å poste følger under. " . "Merk den og bruk CTRL+C for å kopiere den og CTRL+V for å lime den inn i et tekstfelt når du har logget inn igjen.<br/><br/>";
        echo $body;
        return;
    }
    // Reject if this isn't a comment and user has no posting rights
    if ($comment_to < 1 && !is_logged_in()) {
        echo "Du har ikke tillatelse til å legge inn artikler.";
        echo "Antakelig ser du dette fordi du ikke har gjort noe på nettstedet de siste 20 minuttene, slik at du har blitt automatisk utlogget. Teksten du forsøkte å poste følger under. Merk den og bruk CTRL+C for å lage en kopi og CTRL+V til å lime den inn i et tekstfelt når du har logget inn igjen.<br/>";
        echo $body;
        return;
    }
    /* If the unique form ID doesn't match with the current session counter, we do _nothing */
    /* since this is most likely the result of the user tumbling back and forth. 
     * If the session has timed out (because the user has been writing too long, hopefully)
     * we still accept the new post (i.e. NEW_SESSION is TRUE).
     */
    /*
    global $NEW_SESSION;
    if($NEW_SESSION == TRUE)
    	echo "1";
    else
    	echo "0";
    */
    if (isset($article_form_id) && $flashformid != $article_form_id || $NEW_SESSION == TRUE) {
        echo "Kommentar innsendt tidligere, eller du har logget ut. Du prøvde å poste dette: <br/>";
        echo $body;
    } else {
        $preview = $_REQUEST['preview'];
        $_SESSION['editarticle'] = "true";
        save_form_article();
        if (!($_SESSION['valid_user'] || $comment_to && article_exists($comment_to))) {
            echo "Du må være en registrert bruker for å kunne legge inn artikler.";
        } else {
            if ($_SESSION['valid_user']) {
                $author_username = $_SESSION['valid_user'];
            } else {
                $author_username = '';
            }
            if (!$author || !$body || !$date_posted || !$time_posted) {
                $all_ok = false;
                $error_msg .= "Forfatter, tidspunkt og tekst må fylles inn.";
            }
            if (!$comment_to && !$title) {
                $all_ok = false;
                $error_msg .= " Tittel må være med!";
            }
            if (!(is_valid_alphanum($author) && is_valid_alphanum($title))) {
                $all_ok = false;
                $error_msg .= "Systemutvikleren gnir sitt fjes i grusen og beklager på det dypeste at forfatterfelt og tittelfelt nå inneholder et eller annet spesialtegn som ikke er godkjent. Ta vennligst kontakt snarest slik at deres personlige programmeringskonsulent kan rette opp denne pinlige feilen.";
            }
            $title = addslashes(strip_tags($title));
            $author = addslashes(strip_tags($author));
            $date_posted = addslashes(strip_tags($date_posted));
            $time_posted = addslashes(strip_tags($time_posted));
            $body = addslashes(strip_tags($body, "<a> <img> <br> <i> <b> <div>"));
            $category = addslashes(strip_tags($category));
            if ($is_draft == "ON") {
                $is_draft = 1;
                $log_description .= "savedraft,";
            } else {
                $is_draft = 'NULL';
            }
            if (!$comment_to > 0) {
                $comment_to = 'NULL';
            } else {
                $log_description .= "comment,";
            }
            // Inserting into DB
            if ($edit) {
                $log_description .= "editarticle,";
                $query = "UPDATE articles SET title=\"{$title}\", author=\"{$author}\", intro=\"{$intro}\", body=\"{$body}\", date_posted=\"{$date_posted}\", time_posted=\"{$time_posted}\", comment_to={$comment_to}, priority=\"{$priority}\", picture_url=\"{$picture_url}\", category=\"{$category}\", is_draft={$is_draft} WHERE articleid=" . $articleid . ";";
            } else {
                $log_description .= "newarticle,";
                $query = "INSERT INTO articles (title, author, author_username, body, date_posted, time_posted, comment_to, is_draft, view_count) VALUES(\"{$title}\", \"{$author}\", \"{$author_username}\",  \"{$body}\", \"{$date_posted}\", \"{$time_posted}\", {$comment_to},{$is_draft},0);";
            }
            if ($all_ok == true) {
                if (isset($preview)) {
                    echo "<div class=\"header2\">" . stripslashes($_REQUEST['title']) . "</div>";
                    echo "<div class=\"metatext\"><span class=\"author\">Av: " . $_REQUEST['author'];
                    if (isset($_SESSION['valid_user'])) {
                        echo "  (" . $_SESSION['valid_user'] . ").</span>";
                    } else {
                        echo "  (" . $unknown_author . ").</span>";
                    }
                    echo "<span class=\"time\">Lagt opp: " . date_nor_sql($date_posted) . ", " . $time_posted . "</span></div>";
                    echo "<div class=\"textbody\">" . stripslashes(nl2br($_REQUEST['body'])) . "</div>";
                    form_start_post();
                    form_submit("previewconfirmed", "Lagre artikkel");
                    if (isset($edit)) {
                        form_hidden("editarticle", "editarticle");
                    }
                    form_hidden("m_c", "module_add_article");
                    form_end();
                    form_start_post();
                    if (isset($edit)) {
                        form_hidden("edit", "edit");
                    }
                    form_hidden("articleid", $articleid);
                    form_submit("backtoedit", "Rediger artikkel");
                    form_hidden("m_c", "module_enter_article");
                    form_end();
                    echo "<br/><br/>";
                    do_cancel_article_form();
                } else {
                    $result = DB_insert($query);
                    if ($result > 0) {
                        global $logtype;
                        global $eventdesc;
                        if ($edit) {
                            if ($comment_to > 0) {
                                write_log_entry($articleid, $logtype['comment'], $log_description);
                            } else {
                                write_log_entry($articleid, $logtype['article'], $log_description);
                            }
                        } else {
                            if ($comment_to > 0) {
                                write_log_entry(mysql_insert_id(), $logtype['comment'], $log_description);
                            } else {
                                write_log_entry(mysql_insert_id(), $logtype['article'], $log_description);
                            }
                        }
                        $_SESSION['flashformid'] = $flashformid + 1;
                        if ($comment_to != 'NULL') {
                            echo "Kommentar lagt til! Godt sagt, forhåpentligvis. Husk Vær Varsom-plakaten.<br/>";
                            form_start_get();
                            form_submit("submit", "Gå tilbake til artikkelen");
                            form_hidden("m_c", "m_va");
                            form_hidden("articleid", $comment_to);
                            form_end();
                            unset_form_article();
                        } else {
                            if ($edit) {
                                echo "Redigering fullført. Håper det ble bedre.";
                                if ($is_draft != 'NULL') {
                                    echo " Denne artikkelen er lagret og er tilgjengelig fra din profilside. " . "Den blir ikke lagt ut på forsiden eller gjort tilgjengelig  gjennom artikkelsøk.";
                                }
                                unset_form_article();
                            } else {
                                echo "Ny artikkel lagt inn! Husk: Sist gang noen sjekket, var det bare 1 av 10 lesere som gadd &aring kommentere. ;)";
                                if ($is_draft != 'NULL') {
                                    echo "Denne artikkelen er lagret og er tilgjengelig fra din profilside. " . "Den blir ikke lagt ut på forsiden eller gjort tilgjengelig  gjennom artikkelsøk.";
                                }
                                unset_form_article();
                            }
                        }
                    } else {
                        echo $query;
                        echo "Artikkel ikke lagt opp, databaseproblem.";
                    }
                }
            } else {
                echo $error_msg;
            }
        }
    }
}
Example #2
0
function module_admininput()
{
    // adminpage, stop here if not logged in/right access-level
    if (!isValidAdmin()) {
        echo getString("not_valid_admin", "Administratorside, du må logge inn for å få tilgang her");
        return;
    }
    $inputaction = $_REQUEST['inputaction'];
    if ($inputaction == "addarticle") {
        save_form_article();
        $title = $_REQUEST['title'];
        $author = $_REQUEST['author'];
        $author_username = $_REQUEST['author_username'];
        $date_posted = $_REQUEST['year'] . "-" . $_REQUEST['month'] . "-" . $_REQUEST['day'];
        $time_posted = $_REQUEST['hours'] . ":" . $_REQUEST['minutes'];
        $comment_to = $_REQUEST['comment_to'];
        $is_draft = $_REQUEST['is_draft'];
        $body = $_REQUEST['body'];
        if ($is_draft == "ON") {
            $is_draft = 1;
            $log_description .= "savedraft,";
        } else {
            $is_draft = 'NULL';
        }
        if (strlen($comment_to) < 1) {
            $comment_to = "NULL";
            $log_description .= "savenewarticle,";
        } else {
            $log_description .= "savenewcomment,";
        }
        $query = "INSERT INTO articles (title, author, author_username, body, date_posted, time_posted, comment_to, is_draft, view_count) VALUES(\"{$title}\", \"{$author}\", \"{$author_username}\",  \"{$body}\", \"{$date_posted}\", \"{$time_posted}\", {$comment_to},{$is_draft},0);";
        echo $query;
        $result = DB_insert($query);
        global $logtype;
        if ($result) {
            echo "Artikkel lagt inn med id: " . mysql_insert_id();
            unset_form_article();
            if ($comment_to != "NULL") {
                $log_description .= "commentadded!,";
                write_log_entry(mysql_insert_id(), $logtype['comment'], $log_description);
            } else {
                $log_description .= "articleadded!,";
                write_log_entry(mysql_insert_id(), $logtype['article'], $log_description);
            }
        } else {
            echo "Oops: " . mysql_error();
        }
    } else {
        form_start_post();
        echo '<table class="default_table">';
        echo '<tr><td>Forfatter</td><td>';
        form_textfield("author", stripslashes($_SESSION['author']));
        echo '</td></tr>';
        echo '<tr><td>Forfatter_brukernavn</td><td>';
        form_textfield("author_username", stripslashes($_SESSION['author']));
        echo '</td></tr>';
        echo '<tr><td>Tittel</td><td class="form_article_title">';
        form_textfield("title", stripslashes(fix_quotes($_SESSION['title'])));
        echo '</td></tr>';
        echo '<tr><td>Dato</td><td>';
        form_datewidget($_SESSION['date_posted']);
        echo '</td></tr>';
        echo '<tr><td>Tidspunkt</td><td>';
        form_timewidget($_SESSION['time_posted']);
        echo '</td></tr>';
        echo '<tr><td>Kommentar til</td><td>';
        form_textfield("comment_to", $_SESSION['comment_to']);
        echo '</td></tr>';
        if ($_SESSION['is_draft'] == "ON") {
            echo '<tr><td>Bare lagre, <br/>ikke publiser</td><td>';
            form_checkbox("is_draft", "ON", "1");
            echo '</td></tr>';
        } else {
            echo '<tr><td>Bare lagre, <br/>ikke publiser</td><td>';
            form_checkbox("is_draft", "ON", "0");
            echo '</td></tr>';
        }
        echo '<tr><td colspan=2 class="form_article_text">';
        form_textarea("body", stripslashes($_SESSION['body']), 30, 10);
        echo '</td></tr>';
        echo '<tr><td colspan=2>';
        form_submit("Button", "Lagre artikkelen");
        echo '</td></tr>';
        echo '<tr><td colspan=2>';
        form_submit("preview", "Forhåndsvis artikkel");
        echo '</td></tr>';
        form_hidden("m_c", "module_admininput");
        form_hidden("inputaction", "addarticle");
        form_hidden("articleid", $_SESSION['articleid']);
        if (isset($edit)) {
            form_hidden("editarticle", "editarticle");
        }
        echo '</table>';
        form_end();
    }
}