Version 5, last updated by sinus at March 23, 2008 02:19 UTC

1) Get the POST data:

$_POST['token']
this will be checked against $_SESSION['token']. If not equal, then throw an exception

$_POST['notes']
this is the note to be saved into the database. If saving into the DB, use $MyFilter->filterContentForDB($_POST['notes']. This will filter the note for anyone who included shit in the textarea. Then, for the browser display, use $MyFilter->filterContentForDisplay($_POST['notes']).

$_POST['tags']
The tags -- comma-separated

$_POST['parent_id']
The parent_id, this only has a value when Edit is clicked.

2) Save the notes in skeedl_notes

require_once('models/Notes.php');
$Notes = new Notes();
$data = array();
//$data = $_POST;
$data['notes'] = $MyFilter->filterContentForDB($_POST['notes']);
$data['notes'] = $MyFilter->filterContentForDisplay($data['notes']);
if($_POST['parent_id']) {
    $data['parent_id'] = $_POST['parent_id'];
}
$data['datetime_posted']  = date('Y-m-d H:i:s');
$Notes->insert($data);

3) Save ownership of note in skeedl_users_notes

require_once('models/UsersNotes.php');
$UsersNotes = new UserNotes();
$notesuser = array();
$notesuser['username']   = $this->view->user->username;
$notesuser['notes_id']   = $Notes->_lastInsertId;
//$notesuser['is_owner'] = 'yes';
$UsersNotes->insert($notesuser);

4) Parse the comma-separated tags and save in skeedl_users_tags

require_once('models/UsersTags.php');
$UsersTags = new UsersTags();
$tags = array();
$tags = explode(',',$_POST['tags']);
$data['tags'] = '';
foreach($tags AS $tag) {
    $clean_tags_for_db      = array();
    $clean_tags_for_db['username']  = $this->view->user->username;
    $clean_tags_for_db['tag']       = $MyFilter->filterContentForDB(trim($tag));
    $clean_tags_for_db['notes_id']  = $Notes->_lastInsertId;
    
    if(strlen(trim($tag)) > 0) { //only save tags that are not empty
        $data['tags']                   .= $MyFilter->filterContentForDisplay($tag).',';    
        $UsersTags->insert($clean_tags_for_db);
        unset($clean_tags_for_db);
    }
    
}