Thread: [phpwebapp-commits] CVS: web_app/boxes/webnotes/editnote preview.html,NONE,1.1 help.html,NONE,1.1 ed
Brought to you by:
dashohoxha
Update of /cvsroot/phpwebapp/web_app/boxes/webnotes/editnote In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv1019/boxes/webnotes/editnote Added Files: preview.html help.html editnote.php editnote.js editnote.html editnote.db editnote.css edit.html Log Message: The webbox 'webnotes' can be used to append comments or notes to documentation pages or to other web pages. --- NEW FILE: preview.html --- <br /><br /> <table class="note-1" cellpadding="2" cellspacing="0"> <tr class="note-title"> <td> {{date_modified}} <strong>{{email}}</strong> </td> <td align="right"> #{{note_id}} </td> </tr> <tr class="note-text"> <td colspan="2"><tt>{{note_text}}</tt></td> </tr> </table> <table cellpadding="4" cellspacing="0"> <tr> <td align="center" width="80%"> <input type="button" class="button" value="Edit" onclick="javascript:back()" /> <input type="button" class="button" value="Submit" onclick="javascript:submit()" /> </td> </tr> </table> --- NEW FILE: help.html --- <div class="note"> <xmp>T_("HTML tags that are allowed:") <b><i><a><br><p><ol><ul><li><hr><pre><xmp> T_("After you add your note, it will be queued for approval by a moderator.")</xmp> </div> --- NEW FILE: editnote.php --- <?php /* This file is part of DocBookWiki. DocBookWiki is a web application that displays and edits DocBook documents. Copyright (C) 2004, 2005 Dashamir Hoxha, das...@us... DocBookWiki is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. DocBookWiki is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with DocBookWiki; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ class editnote extends WebObject { function init() { $this->addSVar('state', 'hidden'); // hidden | edit | preview $this->addSVar('note_id', UNDEFINED); } function on_add($event_args) { $this->setSVar('state', 'edit'); $this->setSVar('note_id', UNDEFINED); } function on_edit($event_args) { $this->setSVar('state', 'edit'); $this->setSVar('note_id', $event_args['note_id']); } function on_save($event_args) { $params = $event_args; $allowed_tags = "<b><i><a><br><p><ol><ul><li><hr><pre><xmp>"; $note = $params["note_text"]; $params["note_text"] = strip_tags($note, $allowed_tags); $params["ip"] = $_SERVER["REMOTE_ADDR"]; $params["date_modified"] = date("d-Mon-Y h:m"); $note_id = $this->getSVar('note_id'); if ($note_id==UNDEFINED) { $this->insert_new_note($params); } else { WebApp::execDBCmd("update_note", $params); } } function insert_new_note($params) { //add a new note record WebApp::execDBCmd("insert_new_note", $params); //get the note_id of the new record $rs = WebApp::openRS("get_new_note_id", $params); $note_id = $rs->Field('note_id'); //set it to the statevar note_id $this->setSVar('note_id', $note_id); //update the status from 'new' to 'edit' WebApp::execDBCmd("set_note_status", array('status'=>'edit')); } function on_preview($event_args) { $this->on_save($event_args); $this->setSVar('state', 'preview'); } function on_cancel($event_args) { $this->setSVar('state', 'hidden'); } function on_submit($event_args) { WebApp::execDBCmd("set_note_status", array('status'=>'approved')); //hide the editnote webbox $this->setSVar('state', 'hidden'); } function onRender() { $note_id = $this->getSVar('note_id'); if ($note_id==UNDEFINED) { $email = (defined('EMAIL') ? EMAIL : ''); WebApp::addVars(array( 'email' => $email, 'note_text' => '' )); } else { $rs = WebApp::openRS("get_note"); //change the date format $date = $rs->Field('date_modified'); $date = date('d-M-Y G:i', strtotime($date)); $rs->setFld('date_modified', $date); WebApp::addVars($rs->Fields()); } } } ?> --- NEW FILE: editnote.js --- // -*-C-*- /* This file is part of DocBookWiki. DocBookWiki is a web application that displays and edits DocBook documents. Copyright (C) 2004, 2005 Dashamir Hoxha, das...@us... DocBookWiki is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. DocBookWiki is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with DocBookWiki; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ function add_note() { SendEvent('editnote', 'add'); } function get_event_args() { var form = document.editnote; var email = form.email.value; var note_text = form.note_text.value; //encode_arg_value() is used to escape the semicolumns (;) inside the text var event_args = "email="+email+";"+"note_text="+encode_arg_value(note_text); return event_args; } function save() { SendEvent('editnote', 'save', get_event_args()); } function preview() { SendEvent('editnote', 'preview', get_event_args()); } function cancel() { var msg = T_("Any changes will be lost!"); if (confirm(msg)) SendEvent('editnote', 'cancel'); } function submit() { SendEvent("editnote", "submit"); } --- NEW FILE: editnote.html --- <webbox id="editnote"> <if condition="('{{state}}'=='edit')"> <div class="editnote"> <include src="{{./}}edit.html" /> <include src="{{./}}help.html" /> </div> </if> <if condition="('{{state}}'=='preview')"> <div class="editnote"> <include src="{{./}}preview.html" /> </div> </if> </webbox> --- NEW FILE: editnote.db --- <!--# -*-SQL-*- #tell emacs to use SQL mode #--> <Recordset ID="get_note"> <Query> SELECT * FROM webnotes WHERE note_id = '{{note_id}}' </Query> </Recordset> <dbCommand ID="get_new_note_id"> <Query> SELECT note_id FROM webnotes WHERE page_id = '{{page_id}}' AND email = '{{email}}' AND ip = '{{ip}}' AND status = 'new' AND note_text = '{{note_text}}' </Query> </dbCommand> <dbCommand ID="insert_new_note"> <Query> INSERT INTO webnotes SET page_id = '{{page_id}}', email = '{{email}}', ip = '{{ip}}', date_modified = NOW(), status = 'new', note_text = '{{note_text}}' </Query> </dbCommand> <dbCommand ID="update_note"> <Query> UPDATE webnotes SET page_id = '{{page_id}}', email = '{{email}}', ip = '{{ip}}', date_modified = NOW(), status = 'edit', note_text = '{{note_text}}' WHERE note_id = '{{note_id}}' </Query> </dbCommand> <dbCommand ID="set_note_status"> <Query> UPDATE webnotes SET status = '{{status}}' WHERE note_id = '{{note_id}}' </Query> </dbCommand> --- NEW FILE: editnote.css --- div.editnote { font-family:Verdana, Arial; font-size: 10pt; background: transparent; color: #000000; } div.editnote table.edit { border: solid 1px #666666; margin-top: 10px; margin-bottom: 10px; } table.edit tr.title { font-weight: bold; text-align: left; font-size: 120%; color: #444444; } table.edit tr.row-1 { background-color: #d8d8d8; } table.edit tr.row-2 { background-color: #e8e8e8; } div.editnote input { background: #f8f8f8; color: #000000; font-size: 11px; border: 1px solid #aaaaaa; padding: 3px; } div.editnote textarea { background: #f8f8f8; color: #000000; font-size: 11px; border: 1px solid #aaaaaa; overflow: auto; padding: 5px; } div.editnote div.note { background-color: #c8e0f8; border: 1px solid #4444aa; padding: 5px; margin-top: 10px; margin-bottom: 10px; } --- NEW FILE: edit.html --- <form name="editnote" onsubmit="send_note(); return false;"> <table class="edit"> <tr class="title"> <td colspan="2"><strong>T_("Add a New Note or Comment")</strong></td> </tr> <tr class="row-1"> <th>T_("Email")</th> <td> <input type="text" name="email" size="64" maxlength="128" value="{{email}}"/> </td> </tr> <tr class="row-2"> <th>T_("Note")</th> <td> <textarea type="text" name="note_text" rows="16" cols="72">{{note_text}}</textarea> </td> </tr> <tr> <td colspan="2" align="center" width="80%"> <input type="button" class="button" value="Save" onclick="javascript:save()" /> <input type="button" class="button" value="Preview" onclick="javascript:preview()" /> <input type="button" class="button" value="Cancel" onclick="javascript:cancel()" /> </td> </tr> </table> </form> |