Azyrus
Newbie
Karma: 0
Posts: 28
|
 |
« on: May 14, 2012, 11:20:08 PM » |
|
Hi guys, handy little code to use if you add custom fields you most likely will want to search them at some point. The example will be adding a field to search a reservations teacher, green highlighted code/php needs to be ADDED.
There are 3 files that need to be edited: phpscheduleit/usage.php phpscheduleit/templates/usage.template.php phpscheduleit/lib/db/UsageDB.class.php
First phpscheduleit/usage.php: 96 $summarysearch = $_POST['summarysearch']; 97 $summarytype = $_POST['summarytype']; 98 $teachersearch = $_POST['teachersearch']; 99 $teachertype = $_POST['teachertype'];
101 $res = $db->get_reservations($scheduleids, $memberids, $machids, $startDateMin, $startDateMax, $endDateMin, $endDateMax, $starttimeMin, $starttimeMax, $endtimeMin, $endtimeMax, $summarysearch, $summarytype, $teachersearch, $teachertype);
Secondly phpscheduleit/templates/usage.template.php: 287 <tr class="cellColor"> 288 <td class="formNames"><?php echo translate('Summary')?>:</td> 289 <td> 290 <input type="radio" name="summarytype" value="anywhere" checked="checked" /><?php echo translate('Contains')?> 291 <input type="radio" name="summarytype" value="beginning" /><?php echo translate('Begins with')?> 292 <input type="text" name="summarysearch" class="textbox" /> 293 </td> 294 </tr> <Insert new code below here as a new search row> 295 <tr class="cellColor"> 296 <td class="formNames">Teacher's Name:</td> 297 <td> 298 <input type="radio" name="teachertype" value="anywhere" checked="checked" /><?php echo translate('Contains')?> 299 <input type="radio" name="teachertype" value="beginning" /><?php echo translate('Begins with')?> 300 <input type="text" name="teachersearch" class="textbox" /> 301 </td> 302 </tr>
Thirdly phpscheduleit/lib/db/UsageDB.class.php: 76 function get_reservations($scheduleids, $memberids, $machids, $startDateMin, $startDateMax, $endDateMin, $endDateMax, $starttimeMin, $starttimeMax, $endtimeMin, $endtimeMax, $summarysearch, $searchtype, $teachersearch, $teachertype) {
197 // Summary search clause 198 if (!empty($summarysearch)) { 199 if ($searchtype != 'beginning') { 200 $where .= ' AND res.summary LIKE "%' . $summarysearch . '%" '; 201 } 202 else { 203 $where .= ' AND res.summary LIKE "' . $summarysearch . '%" '; 204 } 205 } <Insert new code below here as a new search row> 206 // Summary search clause 207 if (!empty($teachersearch)) { 208 if ($teachertype != 'beginning') { 209 $where .= ' AND res.teacher LIKE "%' . $teachersearch . '%" '; 210 } 211 else { 212 $where .= ' AND res.teacher LIKE "' . $teachersearch . '%" '; 213 } 214 }
Change all fields to relevant names to your actual field name, you could simply copy and paste the summary sections of code and replace summary with your field name.
|