Example #1
0
        $t['total']++;
        $t['list'][] = prepareTaskRow($r, $tz);
    }
    echo json_encode($t);
    exit;
} elseif (isset($_GET['newTask'])) {
    check_write_access();
    stop_gpc($_POST);
    $t = array();
    $t['total'] = 0;
    $listId = (int) _post('list');
    $title = trim(_post('title'));
    $prio = 0;
    $tags = '';
    if (!isset($config['smartsyntax']) || $config['smartsyntax'] != 0) {
        $a = parse_smartsyntax($title);
        if ($a === false) {
            echo json_encode($t);
            exit;
        }
        $title = $a['title'];
        $prio = $a['prio'];
        $tags = $a['tags'];
    }
    if ($title == '') {
        echo json_encode($t);
        exit;
    }
    if (isset($config['autotag']) && $config['autotag']) {
        $tags .= ',' . _post('tag');
    }
Example #2
0
        foreach ($order as $ow => $id) {
            $id = (int) $id;
            $a[] = $id;
            $setCase .= "WHEN id={$id} THEN {$ow}\n";
        }
        $ids = implode($a, ',');
        $db->dq("UPDATE {mytinytodo_lists} SET d_edited=?, ow = CASE\n {$setCase} END WHERE id IN ({$ids})", array(time()));
        module_invoke_all('mytinytodo_change_list_order', array('list' => $listId, 'order' => $order));
        $t['total'] = 1;
    }
    jsonExit($t);
} elseif (isset($_GET['parseTaskStr'])) {
    check_write_access();
    stop_gpc($_POST);
    $t = array('title' => trim(_post('title')), 'prio' => 0, 'tags' => '');
    if (Config::get('smartsyntax') != 0 && false !== ($a = parse_smartsyntax($t['title']))) {
        $t['title'] = $a['title'];
        $t['prio'] = $a['prio'];
        $t['tags'] = $a['tags'];
    }
    jsonExit($t);
} elseif (isset($_GET['clearCompletedInList'])) {
    check_write_access();
    stop_gpc($_POST);
    $t = array();
    $t['total'] = 0;
    $listId = (int) _post('list');
    $db->ex("BEGIN");
    $db->ex("DELETE FROM {mytinytodo_tag2task} WHERE task_id IN (SELECT id FROM {mytinytodo_todos} WHERE list_id=? and compl=1)", array($listId));
    $result = $db->ex("DELETE FROM {mytinytodo_todos} WHERE list_id={$listId} and compl=1");
    $t['total'] = $result->affected();
Example #3
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;
}