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 if(isset($_REQUEST['tasks_new_bug'])) {
50 tem_show('bug_submit');
52 tem_show('normal_submits');
55 $delete_id = format_int($_REQUEST['tasks_delete_id']);
56 unset($_REQUEST['tasks_delete_id']);
58 db_delete('tasks', 'where id=%i', $delete_id);
59 message('Task deleted.');
61 return './tasks.html';
68 if(isset($_REQUEST['title'])) {
69 list($title, $url, $description) = tasks_get_fields();
72 if(isset($_REQUEST['save_draft'])) {
74 } elseif(isset($_REQUEST['save_bug'])) {
77 $state = TASK_NEEDS_QUOTE;
80 if("you're happy with the POSTed values") {
82 db_update('tasks', 'title,url,description,state', $title, $url, $description, $state, 'where id=%i', $edit_id);
83 message('Task updated.');
87 $client_id = 4; # FIXME
88 db_insert('tasks', 'client_id,title,url,description,state,paid', $client_id, $title, $url, $description, $state, $paid);
89 message('Task saved.');
91 if($GLOBALS['tasks_form_recipient'] != "fixme@example.com") {
92 $to = $GLOBALS['tasks_form_recipient'];
95 if(isset($_REQUEST['email']) and valid_email($_REQUEST['email'])) {
96 $reply_to = $_REQUEST['email'];
97 if($_REQUEST['name'] and ereg('^[a-zA-Z0-9_\' -]*$', $_REQUEST['name']) !== false) {
98 $reply_to = "$_REQUEST[name] <$reply_to>";
101 $subject = 'tasks form submitted';
102 $message = tem_run('tasks.email.txt');
105 if(email($from, $to, $subject, $message, $reply_to, $cc, $bcc)) {
106 message('Due to an internal error, your message could not be sent. Please try again later.');
110 if($error !== true) {
114 # otherwise, we display the form again. tasks_get_fields() has
115 # already put the posted values back into the template engine, so they will
116 # show up in the form fields. You should add some message asking people to
117 # fix their entry in whatever way you require.
119 # we've recieved an edit id, but no data. So we grab the values to be edited from the database
120 list($client_id, $ord, $title, $url, $description, $state, $paid) = db_get_row('tasks', TASKS_DB_FIELDS, 'where id=%i', $edit_id);
121 tasks_tem_sets($client_id, $ord, $title, $url, $description, $state, $paid);
123 # form not submitted, you can set default values like so:
124 #tem_set('client_id', 'Yes');
127 # this has to be later in the file because it requres that client_id be set already
129 tem_show('edit_msg');