예제 #1
0
    check_write_access();
    $listId = (int) _post('list');
    $publish = (int) _post('publish');
    $db->ex("UPDATE {mytinytodo_lists} SET published=?,d_created=? WHERE id={$listId}", array($publish ? 1 : 0, time()));
    module_invoke_all('mytinytodo_publish_list', array('list' => $listId, 'publish' => $publish));
    jsonExit(array('total' => 1));
} elseif (isset($_GET['moveTask'])) {
    check_write_access();
    $id = (int) _post('id');
    $fromId = (int) _post('from');
    $toId = (int) _post('to');
    $result = moveTask($id, $toId);
    $t = array('total' => $result ? 1 : 0);
    if ($fromId == -1 && $result && ($r = $db->sqa("SELECT * FROM {mytinytodo_todos} WHERE id={$id}"))) {
        module_invoke_all('mytinytodo_move_task', array('list' => $listId, 'from' => $fromId, 'to' => $toId));
        $t['list'][] = prepareTaskRow($r);
    }
    jsonExit($t);
} elseif (isset($_GET['changeListOrder'])) {
    check_write_access();
    stop_gpc($_POST);
    $order = (array) _post('order');
    $t = array();
    $t['total'] = 0;
    if ($order) {
        $a = array();
        $setCase = '';
        foreach ($order as $ow => $id) {
            $id = (int) $id;
            $a[] = $id;
            $setCase .= "WHEN id={$id} THEN {$ow}\n";
예제 #2
0
    jsonExit(array('total' => 1));
} elseif (isset($_GET['publishList'])) {
    check_write_access();
    $listId = (int) _post('list');
    $publish = (int) _post('publish');
    $db->ex("UPDATE {$db->prefix}lists SET published=?,d_created=? WHERE id={$listId}", array($publish ? 1 : 0, time()));
    jsonExit(array('total' => 1));
} elseif (isset($_GET['moveTask'])) {
    check_write_access();
    $id = (int) _post('id');
    $fromId = (int) _post('from');
    $toId = (int) _post('to');
    $result = moveTask($id, $toId);
    $t = array('total' => $result ? 1 : 0);
    if ($fromId == -1 && $result && ($r = $db->sqa("SELECT * FROM {$db->prefix}todolist WHERE id={$id}"))) {
        $t['list'][] = prepareTaskRow($r, loadLists($db, ''));
    }
    jsonExit($t);
} elseif (isset($_GET['changeListOrder'])) {
    check_write_access();
    stop_gpc($_POST);
    $order = (array) _post('order');
    $t = array();
    $t['total'] = 0;
    if ($order) {
        $a = array();
        $setCase = '';
        foreach ($order as $ow => $id) {
            $id = (int) $id;
            $a[] = $id;
            $setCase .= "WHEN id={$id} THEN {$ow}\n";
예제 #3
0
function loadTasks($listId, $compl = 0, $tag = '', $s = '', $sort = 0, $setCompl = 0, $setNotification = null)
{
    $db = DBConnection::instance();
    $sqlWhere = $inner = '';
    if ($listId == -1) {
        $userLists = getUserListsSimple();
        $sqlWhere .= " AND {$db->prefix}todolist.list_id IN (" . implode(array_keys($userLists), ',') . ") ";
    } else {
        $sqlWhere .= " AND {$db->prefix}todolist.list_id=" . $listId;
    }
    if ($compl == 0) {
        $sqlWhere .= ' AND compl=0';
    }
    $tag = trim($tag);
    if ($tag != '') {
        $at = explode(',', $tag);
        $tagIds = array();
        $tagExIds = array();
        foreach ($at as $i => $atv) {
            $atv = trim($atv);
            if ($atv == '' || $atv == '^') {
                continue;
            }
            if (substr($atv, 0, 1) == '^') {
                $tagExIds[] = getTagId(substr($atv, 1));
            } else {
                $tagIds[] = getTagId($atv);
            }
        }
        if (sizeof($tagIds) > 1) {
            $inner .= "INNER JOIN (SELECT task_id, COUNT(tag_id) AS c FROM {$db->prefix}tag2task WHERE list_id={$listId} AND tag_id IN (" . implode(',', $tagIds) . ") GROUP BY task_id) AS t2t ON id=t2t.task_id";
            $sqlWhere = " AND c=" . sizeof($tagIds);
            //overwrite sqlWhere!
        } elseif ($tagIds) {
            $inner .= "INNER JOIN {$db->prefix}tag2task ON {$db->prefix}todolist.id={$db->prefix}tag2task.task_id";
            $sqlWhere .= " AND {$db->prefix}tag2task.tag_id = " . $tagIds[0];
        }
        if ($tagExIds) {
            $sqlWhere .= " AND id NOT IN (SELECT DISTINCT task_id FROM {$db->prefix}tag2task WHERE list_id={$listId} AND tag_id IN (" . implode(',', $tagExIds) . "))";
            //DISTINCT ?
        }
    }
    $s = trim($s);
    if ($s != '') {
        $sqlWhere .= " AND (title LIKE " . $db->quoteForLike("%%%s%%", $s) . " OR note LIKE " . $db->quoteForLike("%%%s%%", $s) . ")";
    }
    $sort = $sort;
    $sqlSort = "ORDER BY compl ASC, ";
    if ($sort == 1) {
        $sqlSort .= "prio DESC, ddn ASC, duedate ASC, ow ASC";
    } elseif ($sort == 101) {
        $sqlSort .= "prio ASC, ddn DESC, duedate DESC, ow DESC";
    } elseif ($sort == 2) {
        $sqlSort .= "ddn ASC, duedate ASC, prio DESC, ow ASC";
    } elseif ($sort == 102) {
        $sqlSort .= "ddn DESC, duedate DESC, prio ASC, ow DESC";
    } elseif ($sort == 3) {
        $sqlSort .= "d_created ASC, prio DESC, ow ASC";
    } elseif ($sort == 103) {
        $sqlSort .= "d_created DESC, prio ASC, ow DESC";
    } elseif ($sort == 4) {
        $sqlSort .= "d_edited ASC, prio DESC, ow ASC";
    } elseif ($sort == 104) {
        $sqlSort .= "d_edited DESC, prio ASC, ow DESC";
    } else {
        $sqlSort .= "ow ASC";
    }
    $t = array();
    $t['total'] = 0;
    $t['list'] = array();
    $q = $db->dq("SELECT *, duedate IS NULL AS ddn FROM {$db->prefix}todolist {$inner} WHERE 1=1 {$sqlWhere} {$sqlSort}");
    while ($r = $q->fetch_assoc($q)) {
        $t['total']++;
        $t['list'][] = prepareTaskRow($r);
    }
    if ($setCompl && have_write_access($listId)) {
        $bitwise = $compl == 0 ? 'taskview & ~1' : 'taskview | 1';
        $db->dq("UPDATE {$db->prefix}lists SET taskview={$bitwise} WHERE id={$listId}");
    }
    if (($setNotification === '0' || $setNotification === '1') && have_write_access($listId)) {
        if ($setNotification == 1) {
            NotificationListener::enableNotification(NotificationListener::LISTENER_TYPE_LIST, $listId);
        } else {
            NotificationListener::disableNotification(NotificationListener::LISTENER_TYPE_LIST, $listId);
        }
    }
    return $t;
}
예제 #4
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;
}