简体   繁体   中英

Adding 'Select All' to a filter

I have successfully set up a filter for a calendar that displays the upcoming jobs for different users where you can choose the user you want to see the jobs for. Now, I want to add a 'select all' to the filter so that it shows the jobs for everyone rather than just the specified user.
I have done my research and found a similar question but it doesn't quite apply to my situation (that question used an input form field whereas mine uses the database to create the filter and so that response won't work for me), before I get my question marked as a duplicate which I don't believe it is. Here is the page code:

if (isset($_REQUEST['id'])) {
     $workDetails = GetWork($_REQUEST['id']);
     $accountName = $_REQUEST['accountname'];
     $accountId = $_REQUEST['accountid'];
}
if(isset($_REQUEST['inassigneduser'])){
     $inassigneduser = $_REQUEST['inassigneduser'];
}else{
     $inassigneduser = $_SESSION['userid'];
}

echo "<h2 class='title'>Planned Works</h2><hr class='red'/>";
?>
<table style="margin-bottom:10px;">
<tr>
<td style='width:120px;'><span class='title'>Assigned To:&nbsp;&nbsp;</span> 
</td>
<td id="plannedworkusers" style='width:170px;text-align:left;'><?php echo 
GetUserCombo($inassigneduser, true, "inassigneduser","All");?></td><td 
style='text-align:left;'></td>
<td style='text-align:left;'><a href='#' class='button' 
name='filterassigneduser' >Filter</a></td>
</tr>
</table>
<?php
echo "<div id='calendar' style='float:left; width:100%; margin-left:10px;'> 
</div>";
$events = '';
$events = GetHolidaysForCal($inassigneduser);

And my functions.php file:

function GetHolidaysForCal($inassigneduser)
{
     mysql_connect(DB_HOST, DB_USER, DB_PASS);
     mysql_select_db(DB_NAME) or die("Unable to select database");
     $eventArray = array();

     $sql = "SELECT w.*, c.name AS contactname, a.name AS accountname
        FROM works w, contact c, account a
        WHERE w.id = c.worksid
        AND w.accountid = a.id
        AND c.contacttype = 0
  AND w.assignedtouser = $inassigneduser
        AND (w.infracompletiondate != '0000-00-00'
                OR w.meteringcompletiondate != '0000-00-00'
                OR w.meterremovaldate != '0000-00-00'
                OR w.servicedisconnectiondate != '0000-00-00'
                OR w.gt1date != '0000-00-00'
                OR w.sitesurveydate != '0000-00-00'
                OR w.infrastructurestartdate != '0000-00-00'
      OR w.liveanddeadcheckdate != '0000-00-00')

        ORDER BY w.infracompletiondate ASC, w.meteringcompletiondate ASC ";
     $result = mysql_query($sql);
     $eventstr = "";
     $color = 'black';

I hope that will provide enough information, any help with how to add this 'select all' option would be greatly appreciated!

After a lot of trial and error, I finally managed to figure it out on my own. Below is the code for my functions.php file which I edited.

$sql = "SELECT w.*, c.name AS contactname, a.name AS accountname
        FROM works w, contact c, account a
        WHERE w.id = c.worksid
        AND w.accountid = a.id
        AND c.contacttype = 0";

 //Added code
  if ($inassigneduser != "all") {
    $sql .= " AND w.assignedtouser = " . $inassigneduser;
  }

        $sql .= " AND (w.infracompletiondate != '0000-00-00'
                OR w.meteringcompletiondate != '0000-00-00'
                OR w.meterremovaldate != '0000-00-00'
                OR w.servicedisconnectiondate != '0000-00-00'
                OR w.gt1date != '0000-00-00'
                OR w.sitesurveydate != '0000-00-00'
                OR w.infrastructurestartdate != '0000-00-00'
      OR w.liveanddeadcheckdate != '0000-00-00')

        ORDER BY w.infracompletiondate ASC, w.meteringcompletiondate ASC ";

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM