$title = trim(_post('title')); //New Fields $contact = trim(_post('contact')); $contactdate = parse_duedate(trim(_post('contactdate'))); $contacttypes = $_POST['contacttypes']; $reminderdate = strtotime($_POST['reminderdate']); $reminderemail = trim(_post('reminderemail')); $remindernote = str_replace("\r\n", "\n", trim(_post('remindernote'))); $note = str_replace("\r\n", "\n", trim(_post('note'))); $prio = (int) _post('prio'); if ($prio < -1000000) { $prio = -1000000; } elseif ($prio > 1000000) { $prio = 1000000; } $duedate = parse_duedate(trim(_post('duedate'))); $t = array(); $t['total'] = 0; if ($title == '') { jsonExit($t); } $listId = $db->sq("SELECT list_id FROM {mytinytodo_todos} WHERE id={$id}"); $tags = trim(_post('tags')); $db->ex("BEGIN"); $db->ex("DELETE FROM {mytinytodo_tag2task} WHERE task_id={$id}"); $aTags = prepareTags($tags); if ($aTags) { $tags = implode(',', $aTags['tags']); $tags_ids = implode(',', $aTags['ids']); addTaskTags($id, $aTags['ids'], $listId); }
function addTask($db, $listId, $title, $tag, $note = null, $priority = null, $duedate = null, $tags = null) { $t = array(); $t['total'] = 0; $title = trim($title); if ($title == '') { return $t; } if ($note) { $note = str_replace("\r\n", "\n", trim($note)); } else { $note = ""; } $duedate = parse_duedate(trim($duedate)); $prio = 0; if ($tags) { $tags = trim($tags); } else { $tags = ''; } if (Config::get('smartsyntax') != 0) { $a = parse_smartsyntax($title); if ($a === false) { jsonExit($t); } $title = $a['title']; $prio = $a['prio']; $tags = ($tags ? $tags . "," : "") . $a['tags']; } if ($priority) { $prio = (int) $priority; } if ($prio < -1) { $prio = -1; } elseif ($prio > 2) { $prio = 2; } if (Config::get('autotag')) { $tags .= ',' . _post('tag'); } $ow = 1 + (int) $db->sq("SELECT MAX(ow) FROM {$db->prefix}todolist WHERE list_id={$listId} AND compl=0"); $db->ex("BEGIN"); $db->dq("INSERT INTO {$db->prefix}todolist (uuid,list_id,title,d_created,d_edited,ow,prio,note,duedate) VALUES(?,?,?,?,?,?,?,?,?)", array(generateUUID(), $listId, $title, time(), time(), $ow, $prio, $note, $duedate)); $id = $db->last_insert_id(); if ($tags != '') { $aTags = prepareTags($tags); if ($aTags) { addTaskTags($id, $aTags['ids'], $listId); $db->ex("UPDATE {$db->prefix}todolist SET tags=?,tags_ids=? WHERE id={$id}", array(implode(',', $aTags['tags']), implode(',', $aTags['ids']))); } } $db->ex("COMMIT"); $r = $db->sqa("SELECT * FROM {$db->prefix}todolist WHERE id={$id}"); $t['list'][] = prepareTaskRow($r, loadLists($db, '')); $t['total'] = 1; return $t; }