Background Knowledge
The Search Plugin for TaskFreak! created by DaDaemon and xdu v0.0.1 (March 26, 2007) was designed to create a simple, quick search capability of the tasks title and description. As well it only searched through he current task view (tasks visible at the time) and tasks that are not completed. For some this was not what was desired and would rather have the Search Plugin search through all tasks weather completed or not and as well search through the comments of tasks along with the title and description. I’ll show you how this is done using Searcher, bchristie and davidlmansfield instructions posted on the TaskFreak! Forums.
Solution – Add the Ability to Search All Tasks
Edit the “index.php” located in the root of TaskFreak! as follows. We will be working in the “Load Tasks” section to just above the “Task Order” section. This solution was posted by Searcher at Re: Quick ‘n’ Dirty Search Plugin.
Code Before
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 | $arrFilters = array(); // --- filter: project --- if ($pProject) { // load tasks for specific project $sqlFilter = 'ii.projectId = \''.$pProject.'\''; $pLink=Tzn::concatUrl($pLink,'sProject='.$pProject); } else if (!$objUser->checkLevel(6)) { // user can only access his own projects if ($objUserProjectList->rMore()) { $arrProject = array(); while($objTmp = $objUserProjectList->rNext()) { $arrProject[] = $objTmp->id; } if ($objUser->checkLevel(13)) { $arrProject[] = '0'; } $sqlFilter = 'ii.projectId IN ('.implode(',',$arrProject).')'; unset($arrProject); $objUserProjectList->rReset(); } } $objItemList->addWhere($sqlFilter); // --- filter: user --- $pUser = intval($_REQUEST['sUser']); if (!isset($_REQUEST['sUser']) && @constant('FRK_DEFAULT_VIEW_OWN_TASKS')) { // default view is own tasks only $pUser = $objUser->id; } if($_REQUEST['sUser'] == 'myprojects' && $_SESSION['selUser']){ $objItemList->addWhere('ii.authorId='.$_SESSION['selUser']); } elseif ($pUser) { $objItemList->addWhere('ii.memberId = \''.$pUser.'\''); $_SESSION['selUser'] = $pUser; $pDefaultUserId = $pUser; } else { unset($_SESSION['selUser']); session_unregister('selUser'); $pDefaultUserId = $objUser->id; // by default, show own tasks /* if (!$objUser->checkLevel(1)) { // admin can see all $objItemList->addWhere('(ii.memberId='.$objUser->id .' OR ii.authorId='.$objUser->id.')'); } */ } $pLink=Tzn::concatUrl($pLink,'sUser='.$pUser); // --- private tasks -------------------------------------------------------- $arrFilter[] = 'showPrivate=0'; if ($objUser->checkLevel(12)) { // show internal tasks $arrFilter[] = 'showPrivate=1'; } $arrFilter[] = '(showPrivate=2 AND (ii.memberId='.$objUser->id .' OR ii.authorId='.$objUser->id.'))'; $objItemList->addWhere('('.implode(' OR ',$arrFilter).')'); // --- filter: context --- if ($_REQUEST['sContext']) { $pContext = Tzn::getHttp($_REQUEST['sContext'],true); $objItemList->addWhere('context = \''.$pContext.'\''); $pLink=Tzn::concatUrl($pLink,'sContext='.$pContext); } $sqlFilter = ''; $pShow = ($_REQUEST['show'])?$_REQUEST['show']:'today'; $pLink=Tzn::concatUrl($pLink,'show='.$pShow); $pKeepNoDead = intval(@constant('FRK_NO_DEADLINE_KEEP') -1) * 86400; // --- Filter per date ----------------------------------------------------- switch ($pShow) { case 'all': break; case 'future': // show coming tasks and late tasks (undone only) $sqlFilter = '((deadlineDate >= \'' .strftime(TZN_DATE_SQL,PRJ_DTE_NOW).'\' AND statusKey < ' .FRK_STATUS_LEVELS.')'.' OR statusKey < '.FRK_STATUS_LEVELS.')'; // show uncompleted tasks with no deadline $sqlFilter .= ' OR (deadlineDate = \'9999-00-00\' AND statusKey < ' .FRK_STATUS_LEVELS.')'; break; case 'past': // show past tasks and already done $sqlFilter = '(deadlineDate < \'' .strftime(TZN_DATE_SQL,PRJ_DTE_NOW).'\' OR statusKey = ' .FRK_STATUS_LEVELS.')'; break; case 'today': // show all future tasks (done + undone) and late tasks $pKeepNoDead = intval(@constant('FRK_NO_DEADLINE_KEEP') -1) * 86400; $sqlFilter = '(statusKey = '.FRK_STATUS_LEVELS.' AND statusDate > \'' .gmdate('Y-m-d 00:00:00',time()-$pKeepNoDead).'\') '; // hide far future tasks ? $tmpFilter = ''; if (@constant('FRK_DEFAULT_FAR_FUTURE_HIDE')) { $tmp = intval(FRK_DEFAULT_FAR_FUTURE_HIDE) * 86400; $tmpFilter .= 'deadlineDate < \'' .gmdate('Y-m-d 00:00:00',time()+$tmp).'\''; } // show tasks with no deadline ? if (@constant('FRK_NO_DEADLINE_TOO')) { // yes if ($tmpFilter) { $sqlFilter .= 'OR ('.$tmpFilter .' OR deadlineDate = \'9999-00-00\')' . ' AND statusKey < '.FRK_STATUS_LEVELS; } else { $sqlFilter .= ' OR statusKey < '.FRK_STATUS_LEVELS; } } else { // don't show uncompleted non planned tasks if ($tmpFilter) { $sqlFilter .= ' OR ('.$tmpFilter.' AND statusKey < ' .FRK_STATUS_LEVELS.')'; } else { $sqlFilter .= ' OR (deadlineDate <> \'9999-00-00\' AND statusKey < ' .FRK_STATUS_LEVELS.')'; } } if (@constant('FRK_DEFAULT_CURRENT_TASKS')) { $objItemList->setPagination(FRK_DEFAULT_CURRENT_TASKS); } break; default: break; } // -TODO- Add filter current project only (no completed, no cancelled) // echo '<p>&</p><p>-</p><p>-</p>'.$sqlFilter; if ($sqlFilter) { $objItemList->addDateFilter($sqlFilter); } // search filter $pSearch = ($_REQUEST['search']); if ($pSearch) { $sqlFilter = '(ii.title LIKE \'%'.$pSearch.'%\' OR ii.description LIKE \'%'.$pSearch.'%\')'; $objItemList->addWhere($sqlFilter); } |
Code After
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 | $pSearch = ($_REQUEST['search']); if ($pSearch) { $sqlFilter = '(ii.title LIKE \'%'.$pSearch.'%\' OR ii.description LIKE \'%'.$pSearch.'%\')'; $objItemList->addWhere($sqlFilter); } else { $arrFilters = array(); // --- filter: project --- if ($pProject) { // load tasks for specific project $sqlFilter = 'ii.projectId = \''.$pProject.'\''; $pLink=Tzn::concatUrl($pLink,'sProject='.$pProject); } else if (!$objUser->checkLevel(6)) { // user can only access his own projects if ($objUserProjectList->rMore()) { $arrProject = array(); while($objTmp = $objUserProjectList->rNext()) { $arrProject[] = $objTmp->id; } if ($objUser->checkLevel(13)) { $arrProject[] = '0'; } $sqlFilter = 'ii.projectId IN ('.implode(',',$arrProject).')'; unset($arrProject); $objUserProjectList->rReset(); } } $objItemList->addWhere($sqlFilter); // --- filter: user --- $pUser = intval($_REQUEST['sUser']); if (!isset($_REQUEST['sUser']) && @constant('FRK_DEFAULT_VIEW_OWN_TASKS')) { // default view is own tasks only $pUser = $objUser->id; } if($_REQUEST['sUser'] == 'myprojects' && $_SESSION['selUser']){ $objItemList->addWhere('ii.authorId='.$_SESSION['selUser']); } elseif ($pUser) { $objItemList->addWhere('ii.memberId = \''.$pUser.'\''); $_SESSION['selUser'] = $pUser; $pDefaultUserId = $pUser; } else { unset($_SESSION['selUser']); session_unregister('selUser'); $pDefaultUserId = $objUser->id; // by default, show own tasks /* if (!$objUser->checkLevel(1)) { // admin can see all $objItemList->addWhere('(ii.memberId='.$objUser->id .' OR ii.authorId='.$objUser->id.')'); } */ } $pLink=Tzn::concatUrl($pLink,'sUser='.$pUser); // --- private tasks -------------------------------------------------------- $arrFilter[] = 'showPrivate=0'; if ($objUser->checkLevel(12)) { // show internal tasks $arrFilter[] = 'showPrivate=1'; } $arrFilter[] = '(showPrivate=2 AND (ii.memberId='.$objUser->id .' OR ii.authorId='.$objUser->id.'))'; $objItemList->addWhere('('.implode(' OR ',$arrFilter).')'); // --- filter: context --- if ($_REQUEST['sContext']) { $pContext = Tzn::getHttp($_REQUEST['sContext'],true); $objItemList->addWhere('context = \''.$pContext.'\''); $pLink=Tzn::concatUrl($pLink,'sContext='.$pContext); } $sqlFilter = ''; $pShow = ($_REQUEST['show'])?$_REQUEST['show']:'today'; $pLink=Tzn::concatUrl($pLink,'show='.$pShow); $pKeepNoDead = intval(@constant('FRK_NO_DEADLINE_KEEP') -1) * 86400; // --- Filter per date ----------------------------------------------------- switch ($pShow) { case 'all': break; case 'future': // show coming tasks and late tasks (undone only) $sqlFilter = '((deadlineDate >= \'' .strftime(TZN_DATE_SQL,PRJ_DTE_NOW).'\' AND statusKey < ' .FRK_STATUS_LEVELS.')'.' OR statusKey < '.FRK_STATUS_LEVELS.')'; // show uncompleted tasks with no deadline $sqlFilter .= ' OR (deadlineDate = \'9999-00-00\' AND statusKey < ' .FRK_STATUS_LEVELS.')'; break; case 'past': // show past tasks and already done $sqlFilter = '(deadlineDate < \'' .strftime(TZN_DATE_SQL,PRJ_DTE_NOW).'\' OR statusKey = ' .FRK_STATUS_LEVELS.')'; break; case 'today': // show all future tasks (done + undone) and late tasks $pKeepNoDead = intval(@constant('FRK_NO_DEADLINE_KEEP') -1) * 86400; $sqlFilter = '(statusKey = '.FRK_STATUS_LEVELS.' AND statusDate > \'' .gmdate('Y-m-d 00:00:00',time()-$pKeepNoDead).'\') '; // hide far future tasks ? $tmpFilter = ''; if (@constant('FRK_DEFAULT_FAR_FUTURE_HIDE')) { $tmp = intval(FRK_DEFAULT_FAR_FUTURE_HIDE) * 86400; $tmpFilter .= 'deadlineDate < \'' .gmdate('Y-m-d 00:00:00',time()+$tmp).'\''; } // show tasks with no deadline ? if (@constant('FRK_NO_DEADLINE_TOO')) { // yes if ($tmpFilter) { $sqlFilter .= 'OR ('.$tmpFilter .' OR deadlineDate = \'9999-00-00\')' . ' AND statusKey < '.FRK_STATUS_LEVELS; } else { $sqlFilter .= ' OR statusKey < '.FRK_STATUS_LEVELS; } } else { // don't show uncompleted non planned tasks if ($tmpFilter) { $sqlFilter .= ' OR ('.$tmpFilter.' AND statusKey < ' .FRK_STATUS_LEVELS.')'; } else { $sqlFilter .= ' OR (deadlineDate <> \'9999-00-00\' AND statusKey < ' .FRK_STATUS_LEVELS.')'; } } if (@constant('FRK_DEFAULT_CURRENT_TASKS')) { $objItemList->setPagination(FRK_DEFAULT_CURRENT_TASKS); } break; default: break; } // -TODO- Add filter current project only (no completed, no cancelled) // echo '<p>&</p><p>-</p><p>-</p>'.$sqlFilter; if ($sqlFilter) { $objItemList->addDateFilter($sqlFilter); } } |
Solution – Add Ability to Also Search within Task Comments
Edit the “index.php” located in the root of TaskFreak! as follows. We will be working in just below the heading section of the “Load Tasks”. This solution was posted by davidlmansfield at [PATCH] [Search Plugin] include tasks matching in comment fields.
Code Before
39 40 41 42 43 44 | // search filter $pSearch = ($_REQUEST['search']); if ($pSearch) { $sqlFilter = '(ii.title LIKE \'%'.$pSearch.'%\' OR ii.description LIKE \'%'.$pSearch.'%\')'; $objItemList->addWhere($sqlFilter); } |
Code After
39 40 41 42 43 44 | // search filter $pSearch = ($_REQUEST['search']); if ($pSearch) { $sqlFilter = '(ii.title LIKE \'%'.$pSearch.'%\' OR ii.description LIKE \'%'.$pSearch.'%\' OR ii.itemId in (select itemId from '.$objItemList->gTable('itemComment').' where body LIKE \'%'.$pSearch.'%\'))'; $objItemList->addWhere($sqlFilter); } |
Solution – Stop SQL Injections
Edit the “index.php” located in the root of TaskFreak! as follows. We will be working in just below the heading section of the “Load Tasks”. This solution was posted by bchristie at Re: Quick ‘n’ Dirty Search Plugin.
Code Before
39 40 | // search filter $pSearch = ($_REQUEST['search']); |
Code After
39 40 | // search filter $pSearch = isset($_REQUEST['search'])?mysql_real_escape_string($_REQUEST['search']):false; |
PlanetMySQL Voting: Vote UP / Vote DOWN