Пример #1
0
 }
 $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);
 }
 $num_affected = db_update('mytinytodo_todos')->fields(array('title' => $title, 'd_edited' => time(), 'prio' => $prio, 'c_contact' => $contact, 'c_date' => $contactdate, 'c_type' => $contacttypes, 'r_date' => '', 'r_email' => '', 'r_note' => '', 'note' => $note, 'tags' => $tags, 'tags_ids' => $tags_ids, 'duedate' => $duedate))->condition('id', $id, '=')->execute();
 if ($reminderdate != '') {
     $db->ex("UPDATE {mytinytodo_todos} SET r_date=?,r_email=?, r_note=? WHERE id={$id}", array($reminderdate, $reminderemail, $remindernote));
 }
 /*
 $db->dq("UPDATE {mytinytodo_todos} SET title=?, c_contact=?, c_date=?, c_type=?, note=?,prio=?,tags=?,tags_ids=?,duedate=?,d_edited=? WHERE id=$id",
 		array($title, $contact, $contactdate, $contacttypes, $note, $prio, $tags, $tags_ids, $duedate, time()) );
 */
 $db->ex("COMMIT");
 $r = $db->sqa("SELECT * FROM {mytinytodo_todos} WHERE id={$id}");
 if ($r) {
     $r = prepareTaskRow($r);
     module_invoke_all('mytinytodo_edit_task', $r);
     $t['list'][] = $r;
Пример #2
0
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;
}