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 # replace every character in $str with " "
17 function tonbsp($matches) {
18 return str_repeat(' ', strlen($matches[0]) * 2);
21 # encode as html, make it display newlines and leading spaces
22 function enc_htmlbrtab($str) {
23 $str = enc_htmlbr($str);
24 $str = preg_replace_callback("|^ *|m", tonbsp, $str);
28 function tasks_get_fields() {
29 $title = format_oneline($_REQUEST['title']);
30 $url = format_oneline($_REQUEST['url']);
31 $description = format_unix($_REQUEST['description']);
33 tasks_tem_sets($title, $url, $description);
35 return array($title, $url, $description);
38 function tasks_tem_sets($title, $url, $description) {
39 tem_set('title', $title);
41 tem_set('description', $description);
44 function tasks_main() {
46 $GLOBALS['url'] = this_url();
50 if(isset($_REQUEST['tasks_id'])) {
51 $ret = tasks_display_main();
55 tem_show('display_body');
57 $ret = tasks_edit_main();
61 tem_show('edit_body');
64 tem_show('main_body');
67 function tasks_display_main() {
68 $task_id = format_int($_REQUEST['tasks_id']);;
69 $row = db_get_row('tasks', 'title,url,description,state', 'where id=%i', $task_id);
71 list($title, $url, $description, $state) = $row;
72 tem_set('task_id', $task_id);
73 tem_set('title', $title);
75 tem_set('description', $description);
76 tem_set('state', task_state_pretty($state));
77 if($state == TASK_BUG) {
78 tem_show('bug_title');
80 tem_show('normal_title');
83 message("Task #$task_id not found");
88 function tasks_edit_main() {
89 $state = TASK_DRAFT; # will be overwritten
90 $edit_id = format_int($_REQUEST['tasks_edit_id']);
91 unset($_REQUEST['tasks_edit_id']);
93 # add hidden field for database id of row we're editing
94 tem_set('tasks_edit_id', $edit_id);
97 $state = db_get_value('tasks', 'state', 'where id=%i', $edit_id);
100 if(isset($_REQUEST['tasks_new_bug'])) {
101 tem_show('bug_submit');
104 tem_show('normal_submits');
107 if($state == TASK_BUG) {
108 tem_show('bug_instructions');
110 tem_show('normal_instructions');
113 $delete_id = format_int($_REQUEST['tasks_delete_id']);
114 unset($_REQUEST['tasks_delete_id']);
116 db_delete('tasks', 'where id=%i', $delete_id);
117 message('Task deleted.');
119 return './tasks.html';
122 if(isset($_REQUEST['title'])) {
123 list($title, $url, $description) = tasks_get_fields();
126 if(isset($_REQUEST['save_draft'])) {
128 } elseif(isset($_REQUEST['save_bug'])) {
131 $state = TASK_NEEDS_QUOTE;
134 if("you're happy with the POSTed values") {
136 db_update('tasks', 'title,url,description,state', $title, $url, $description, $state, 'where id=%i', $edit_id);
137 message('Task updated.');
141 $client_id = 4; # FIXME
142 db_insert('tasks', 'client_id,title,url,description,state,paid', $client_id, $title, $url, $description, $state, $paid);
143 message('Task saved.');
145 if($GLOBALS['tasks_form_recipient'] != "fixme@example.com") {
146 $to = $GLOBALS['tasks_form_recipient'];
149 if(isset($_REQUEST['email']) and valid_email($_REQUEST['email'])) {
150 $reply_to = $_REQUEST['email'];
151 if($_REQUEST['name'] and ereg('^[a-zA-Z0-9_\' -]*$', $_REQUEST['name']) !== false) {
152 $reply_to = "$_REQUEST[name] <$reply_to>";
155 $subject = 'tasks form submitted';
156 $message = tem_run('tasks.email.txt');
159 if(email($from, $to, $subject, $message, $reply_to, $cc, $bcc)) {
160 message('Due to an internal error, your message could not be sent. Please try again later.');
164 if($error !== true) {
168 # otherwise, we display the form again. tasks_get_fields() has
169 # already put the posted values back into the template engine, so they will
170 # show up in the form fields. You should add some message asking people to
171 # fix their entry in whatever way you require.
173 # we've recieved an edit id, but no data. So we grab the values to be edited from the database
174 list($client_id, $ord, $title, $url, $description, $state, $paid) = db_get_row('tasks', TASKS_DB_FIELDS, 'where id=%i', $edit_id);
175 tasks_tem_sets($client_id, $ord, $title, $url, $description, $state, $paid);
177 # form not submitted, you can set default values like so:
178 #tem_set('client_id', 'Yes');
181 # this has to be later in the file because it requres that client_id be set already
183 tem_show('edit_msg');
184 } elseif($state == TASK_BUG) {