Ejemplo n.º 1
0
    $v = new Valitron\Validator($_POST);
    $v->rule('required', array('newTitle'));
    $v->labels(array(
        'newTitle' => "$langTheField $langTitle"
    ));    
    if($v->validate()) {
        $newTitle = $_POST['newTitle'];
        $newContent = $_POST['newContent'];
        $refobjid = ($_POST['refobjid'] == "0") ? $_POST['refcourse'] : $_POST['refobjid'];
        if (!empty($_POST['id'])) { //existing note
            $id = intval(getDirectReference($_POST['id']));
            Notes::update_note($id, $newTitle, $newContent, $refobjid);
            Session::Messages($langNoteModify, 'alert-success');
            redirect_to_home_page('main/notes/index.php');        
        } else { // new note
            $id = Notes::add_note($newTitle, $newContent, $refobjid);
            if (!empty($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest') {
                echo $langNoteAdd;
                exit;
            }
            Session::Messages($langNoteAdd, 'alert-success');
            redirect_to_home_page('main/notes/index.php');
        }
    } else {
        $new_or_modify = empty($_POST['id']) ? "addNote=1" : "modify=$_POST[id]";
        Session::flashPost()->Messages($langFormErrors)->Errors($v->errors());
        redirect_to_home_page("main/notes/index.php?$new_or_modify");
    }
} // end of if $submit

/* delete */