3 require_once('code/tasks.php');
5 $GLOBALS['tasks_form_recipient'] = "fixme@example.com";
7 define('TASKS_DB_FIELDS', 'title,url,description,state');
10 require_once('code/wfpl/template.php');
11 require_once('code/wfpl/format.php');
12 require_once('code/wfpl/messages.php');
13 require_once('code/wfpl/email.php');
14 require_once('code/db_connect.php');
16 function tasks_get_fields() {
17 $title = format_oneline($_REQUEST['title']);
18 $url = format_oneline($_REQUEST['url']);
19 $description = format_unix($_REQUEST['description']);
21 tasks_tem_sets($title, $url, $description);
23 return array($title, $url, $description);
26 function tasks_tem_sets($title, $url, $description) {
27 tem_set('title', $title);
29 tem_set('description', $description);
32 function tasks_main() {
37 tem_show('main_body');
40 function _tasks_main() {
41 $edit_id = format_int($_REQUEST['tasks_edit_id']);
42 unset($_REQUEST['tasks_edit_id']);
44 # add hidden field for database id of row we're editing
45 tem_set('tasks_edit_id', $edit_id);
49 $delete_id = format_int($_REQUEST['tasks_delete_id']);
50 unset($_REQUEST['tasks_delete_id']);
52 db_delete('tasks', 'where id=%i', $delete_id);
53 message('Task deleted.');
55 return './tasks.html';
62 if(isset($_REQUEST['title'])) {
63 list($title, $url, $description) = tasks_get_fields();
65 if("you're happy with the POSTed values") {
67 db_update('tasks', 'title,url,description,state', $title, $url, $description, $state, $paid = 0, 'where id=%i', $edit_id);
68 message('Task updated.');
72 if(isset($_REQUEST['save_draft'])) {
75 $state = TASK_NEEDS_QUOTE;
77 $client_id = 4; # FIXME
78 db_insert('tasks', 'client_id,title,url,description,state,paid', $client_id, $title, $url, $description, $state, $paid);
79 message('Task saved.');
82 if($GLOBALS['tasks_form_recipient'] != "fixme@example.com") {
83 $to = $GLOBALS['tasks_form_recipient'];
86 if(isset($_REQUEST['email']) and valid_email($_REQUEST['email'])) {
87 $reply_to = $_REQUEST['email'];
88 if($_REQUEST['name'] and ereg('^[a-zA-Z0-9_\' -]*$', $_REQUEST['name']) !== false) {
89 $reply_to = "$_REQUEST[name] <$reply_to>";
92 $subject = 'tasks form submitted';
93 $message = tem_run('tasks.email.txt');
96 if(email($from, $to, $subject, $message, $reply_to, $cc, $bcc)) {
97 message('Due to an internal error, your message could not be sent. Please try again later.');
101 if($error !== true) {
102 tem_show('thankyou');
106 # otherwise, we display the form again. tasks_get_fields() has
107 # already put the posted values back into the template engine, so they will
108 # show up in the form fields. You should add some message asking people to
109 # fix their entry in whatever way you require.
111 # we've recieved an edit id, but no data. So we grab the values to be edited from the database
112 list($client_id, $ord, $title, $url, $description, $state, $paid) = db_get_row('tasks', TASKS_DB_FIELDS, 'where id=%i', $edit_id);
113 tasks_tem_sets($client_id, $ord, $title, $url, $description, $state, $paid);
115 # form not submitted, you can set default values like so:
116 #tem_set('client_id', 'Yes');
119 # this has to be later in the file because it requres that client_id be set already
121 tem_show('edit_msg');