if (isset($_GET['loadLists'])) { $t = array(); $field_id = (int) $_GET['fid']; $t['total'] = 0; $q = $db->dq("SELECT * FROM {mytinytodo_lists} WHERE field_id = ? ORDER BY ow ASC, id ASC", array($field_id)); while ($r = $q->fetch_assoc($q)) { $t['total']++; $t['list'][] = prepareList($r); } jsonExit($t); } elseif (isset($_GET['loadTasks'])) { stop_gpc($_GET); $listId = (int) _get('list'); $sqlWhere = $inner = ''; if ($listId == -1) { $userLists = getUserListsSimple(); foreach ($userLists as $userList) { check_read_access($userList); } $sqlWhere .= " AND {mytinytodo_todos}.list_id IN (" . implode(array_keys($userLists), ',') . ") "; } else { check_read_access($listId); $sqlWhere .= " AND {mytinytodo_todos}.list_id=" . $listId; } if (_get('compl') == 0) { $sqlWhere .= ' AND compl=0'; } $tag = trim(_get('t')); if ($tag != '') { $at = explode(',', $tag); $tagIds = array();
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; }