Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

know when checkboxes are checked

Posted on 2010-01-06
3
Medium Priority
?
154 Views
Last Modified: 2012-05-09
how does this php class know that checkboxes are checked


class OWOrder {
    public $orderid;
    
    public function __construct() {
        
    }
    
    public function displayStatuses($statusid) {
        echo '<select name="statusid">';
        if($statusid == 0) {
            echo '<option value =" "> </option>';
        }
        
        $sql = "SELECT * FROM statuses WHERE active = '1' ORDER BY status";
        foreach(dbfetcharray($sql) as $r) {
            if($r['statusid'] == $statusid) { $s = " SELECTED"; } else { $s = ""; }
            echo '<option value ="'.$r['statusid'].'"'.$s.'>'.$r['status'].'</option>';
        }
        echo '</select>';
    }
    
    public function displayOrdersbyStatus($statusid) {
        $sql = "SELECT * FROM orders WHERE statusid = '$statusid'";
        
    }
    
    public function displaySearch() {
        echo '
        <form action="order.php">
        '; $this->displayStatuses("0");
        echo '
        <input type="image" value="" src="css/orange/view.jpg">
        <input type="hidden" name="a" value="vieworders">
        </form>
        ';
    }
    
    public function displayOrdersView($statusid) {
        $paymentstatuses = array("10","20","30","40","50","60","70","90","170","130","180","230");
        if(!in_array($statusid,$paymentstatuses)) {
            $orders = dbfetcharray("SELECT orders.orderid, orders.dateordered, orders.salesman, orders.BillLastName, orders.email, ebaydata.userid, ebaydata.itemid, orders.company, datediff(dd,orders.dateordered,getdate()) as age FROM orders LEFT JOIN ebaydata ON orders.orderid = ebaydata.orderid WHERE orders.statusid = '$statusid' ORDER BY orderid DESC");
            echo '
            <form action="order.php">
            '; $this->displayStatuses($statusid);
            echo '
            <input type="image" value="" src="css/orange/view.jpg">
            <input type="hidden" name="a" value="vieworders">
            </form>
            ';
            echo '<br>
                    <div class="selectarea"><b>Select: </b>&nbsp;&nbsp;<a href="#" id="selectall">All</a>&nbsp;&nbsp;|&nbsp;&nbsp;<a href="#" id="selectnone">None</a></div>
                <form action="order.php" method="POST">
                <input type="hidden" name="a" value="bulkprocess">
                <div class="roundedbox datatable">
                
                <table style="width:100%" id="orderstable">
                    <thead><th width="10">&nbsp;</th><th>JOE294OrderID</th><th>Date</th><th>Age</th><th>Salesman</th><th>Item Number</th><th>Last Name</th><th>Email</th><th>User ID</th><th>Company</th></thead>
                    <tbody>
                    ';
            foreach($orders as $o) {
                //Jan 18, 2001 9:12 AM
                //Apr 13, 2008 6:10 pm
                $d = date('M d, Y g:i A', strtotime($o['dateordered']));
                echo '<tr><td><input type="checkbox" name="orders[]" value="' . $o['orderid'] . '"></td><td><a href="order.php?orderid=' . $o['orderid'] . '">' . $o['orderid'] . '</a></td><td>' . $d . '</td><td>' . $o['age'] . '</td><td>' . $o['salesman'] . '</td><td>' . $o['itemid'] . '</td><td>' . substr($o['BillLastName'],0,20) . '</td><td>' . $o['email'] . '</td><td>' . $o['userid'] . '</td><td>' . $o['company'] . '</td></tr>';
            }
            //Print Order, Packing, CC File, Change Status, Asign Salesman
            echo '
                    </tbody>
                </table>
                </div>';

                echo '
                <script>
                //Setup Table Sorter
//                $(document).ready(function() { 
//                    $("#orderstable").tablesorter({ 
//                            // sort on the first column and third column, order asc 
//                            sortList: [[2,1]] 
//                        });
//                    
//                } );
                //Setup Select All/None
                $(\'#selectall\').click(function() {
                    $(\'#orderstable input[@type=checkbox]\').attr(\'checked\', \'checked\')
                 });
                $(\'#selectnone\').click(function() {
                    $(\'#orderstable input[@type=checkbox]\').removeAttr(\'checked\')
                 });
                </script>
                    ';
        }
        else {
            $orders = dbfetcharray("SELECT o.orderid, o.ordertype, o.dateordered, o.dateneeded, o.billlastname, o.email, o.company, 
                (SELECT TOP 1 userid from ebaydata where orderid = o.orderid) as userid, 
                (SELECT TOP 1 itemid from ebaydata where orderid = o.orderid) as itemid,
                (SELECT TOP 1 name from users where userid = o.salesman) as salesman, 
                datediff(dd,o.dateordered,getdate()) as age,
                (SELECT SUM(debit) FROM payments WHERE orderid = o.orderid) as totalpayments,
                (SELECT SUM(debit) FROM payments WHERE orderid = o.orderid AND resultcode = 'Pending') as pendingpayments,
                (SELECT SUM(debit) FROM payments WHERE orderid = o.orderid AND len(confirmation) > 0) as settledpayments,
                (SELECT SUM(subtotal) FROM orderitems WHERE orderid = o.orderid) as subtotal,
                (SELECT count(orderid) FROM orders WHERE email = o.email) as otherorders,
                (o.shippingcharge+o.insurance+o.tax) as accessorial
                FROM orders o            
                WHERE o.statusid = '$statusid' ORDER BY orderid DESC");
                
//                echo 'SQL: ' . $sql . '<br><br>';
                
            $ordercount = count($orders);
            
            

echo '
            <form action="order.php">
            '; $this->displayStatuses($statusid);
            echo '
            <input type="image" value="" src="css/orange/view.jpg">
            <input type="hidden" name="a" value="vieworders">
            <a href="assignorders.php">Assign Orders</a>
            </form>
            ';
            echo '<br>
                <div class="selectarea"><b>Select: </b>&nbsp;&nbsp;<a href="#" id="selectall">All</a>&nbsp;&nbsp;|&nbsp;&nbsp;<a href="#" id="selectnone">None</a>&nbsp;&nbsp;|&nbsp;&nbsp;<a href="#" id="selectcleared">Cleared</a>&nbsp;&nbsp;|&nbsp;&nbsp;<a href="#" id="selectuncleared">Uncleared</a>&nbsp;&nbsp;|&nbsp;&nbsp;<a href="#" id="selectunderforty">Under $40</a>&nbsp;&nbsp;|&nbsp;&nbsp;'.$ordercount.' Orders</div>
                <form action="order.php" method="POST" target="new">
                <input type="hidden" name="a" value="bulkprocess">
                <input type="hidden" name="currentstatus" value="'.$statusid.'">
                <div class="roundedbox datatable">
                    <table style="width:100%" id="orderstable">
                        <thead><th width="10">&nbsp;</th><th>JOE371OrderID</th><th>Type</th><th>Age</th><th>Date Needed</th><th>Salesman</th><th>Item</th><th>Last Name</th><th>Email</th><th>User ID</th><th>Item Number</th><th>Company</th><th>Total</th><th>Payments</th><th>Settled</th></thead>
                        <tbody>
                        ';
                //F6F28F
                foreach($orders as $o) {
                    //Totals
                    $itemtotal = money_round_usd($o['subtotal']+$o['accessorial']);
                    $total = money_round_usd($o['totalpayments']);
                    $settled = money_round_usd($o['settledpayments']);
    
                    //Process Date
                    if($o['dateneeded'] == '1900-01-01 00:00:00.000') {
                        $d = '&nbsp;';
                    } else { $d = date('M d, Y', strtotime($o['dateneeded'])); }
                    
                    //Under 40 selector
                    $u = '';
                    if(($o['subtotal']+$o['accessorial']) < 40.00) {
                        $u = ' underforty ';
                    }
                    //Cleared or uncleared
                    //$itemtotal == $total && 
                    if($total == $settled && $total != '0.00' && $total == $itemtotal) {
                        $s = " style=\"background-color:#ecfeec;color:#006600;\" class=\"cleared$u\"";
                    }
                    else if($o['pendingpayments']>0) {
                        $s = " style=\"background-color:#E1EEF5;color:#1B3C72;\" class=\"uncleared$u\"";
                    }
                    else {
                        $s = " class=\"uncleared$u\"";
                    }
                    $otherorder = "";
                    if($o['otherorders']>1) {
                        $otherorder = "&nbsp;&nbsp;&nbsp;<b>R</b>";
                    }
                    
                    echo '<tr'.$s.'><td><input type="checkbox" name="orders[]" value="' . $o['orderid'] . '"></td><td><a href="order.php?orderid=' . $o['orderid'] . '">' . $o['orderid'] . '</a>'.$otherorder.'</td><td>' . $o['ordertype'] . '</td><td>' . $o['age'] . '</td><td>' . $d . '&nbsp;</td><td>' . $o['salesman'] . '&nbsp;</td><td>' . $o['itemid'] . '&nbsp;</td><td>' . $o['billlastname'] . '&nbsp;</td><td>' . $o['email'] . '&nbsp;</td><td>' . $o['userid'] . '&nbsp;</td><td>' . $o['itemid'] . '&nbsp;</td><td>' . $o['company'] . '&nbsp;</td><td>$ ' . $itemtotal . '&nbsp;</td><td>$ ' . $total . '&nbsp;</td><td>$ ' . $settled . '&nbsp;</td></tr>
 ';
                }
                
            //Print Order, Packing, CC File, Change Status
            echo '
                    </tbody>
                </table>
                </div>
                <br>
                <input type="hidden" name="changestatus" value="">
                <input type="hidden" name="printorders" value="">
                <input type="image" src="inc/img/print_order.jpg" name="printorders" value="printfull" onClick="this.form.printorders.value=\'printfull\';">
                <input type="image" src="inc/img/print_packingslip.jpg" name="printorders" value="printpacking" onClick="this.form.printorders.value=\'printpacking\';">
                <input type="submit" name="printorders" value="GetCCRefundFile" onClick="this.form.printorders.value=\'printpacking\';">
                &nbsp;&nbsp;&nbsp;&nbsp;'; 
                $this->displayStatuses("0");
                echo '
                &nbsp;&nbsp;<input type="image" src="inc/img/change_status.jpg" name="changestatus" value="changestatus" onClick="this.form.changestatus.value=\'changestatus\';this.form.printorders.value=\'\';this.form.target=\'\';">
                &nbsp;&nbsp;<input type="image" src="inc/img/change_status.jpg" name="changestatus" value="changestatus" onClick="this.form.changestatus.value=\'changestatus\';this.form.printorders.value=\'\';this.form.target=\'\';">
                                <input type="image" src="inc/img/print_order.jpg" name="printorders" value="printfull" onClick="this.form.printorders.value=\'printfull\';">
                <script>
                //Setup Table Sorter
                $(document).ready(function() { 
                    $("#orderstable").tablesorter({ 
                            // sort on the first column and third column, order asc 
                            sortList: [[1,1]] 
                        });
                
                } );
                //Setup Select All/None/Cleared/Uncleared
                $(\'#selectall\').click(function() {
                    $(\'#orderstable input[@type=checkbox]\').attr(\'checked\', \'checked\');
                    return false;
                 });
                $(\'#selectnone\').click(function() {
                    $(\'#orderstable input[@type=checkbox]\').removeAttr(\'checked\');
                    return false;
                 });
                $(\'#selectcleared\').click(function() {
                    $(\'#orderstable tr.uncleared input[@type=checkbox]\').removeAttr(\'checked\');
                    $(\'#orderstable tr.cleared input[@type=checkbox]\').attr(\'checked\', \'checked\');
                    return false;
                 });
                $(\'#selectuncleared\').click(function() {
                    $(\'#orderstable tr.cleared input[@type=checkbox]\').removeAttr(\'checked\');
                    $(\'#orderstable tr.uncleared input[@type=checkbox]\').attr(\'checked\', \'checked\');
                    return false;
                 });
                $(\'#selectunderforty\').click(function() {
                    $(\'#orderstable input[@type=checkbox]\').removeAttr(\'checked\');
                    $(\'#orderstable tr.underforty input[@type=checkbox]\').attr(\'checked\', \'checked\');
                    return false;
                 });
                </script>
                    ';
        }
        echo '<br><br><br><br><br>';
    }
}

Open in new window

0
Comment
Question by:rgb192
  • 2
3 Comments
 
LVL 82

Accepted Solution

by:
hielo earned 2000 total points
ID: 26194509
>>how does this php class know that checkboxes are checked
it doesn't seem to be maintaining state. If this is a page that submits to itself and you want to maintain state, try (around line 165 of what you posted):
$checked=( isset($_POST['checked']) && in_array(  $o['orderid'] , $_POST['orders']) ? " checked='checked' " : "");
                    echo '<tr'.$s.'><td><input type="checkbox" name="orders[]" ' . $checked . ' value="' . $o['orderid'] . '"></td><td><a href="order.php?orderid=' . $o['orderid'] . '">' . $o['orderid'] . '</a>'.$otherorder.'</td><td>' . $o['ordertype'] . '</td><td>' . $o['age'] . '</td><td>' . $d . '&nbsp;</td><td>' . $o['salesman'] . '&nbsp;</td><td>' . $o['itemid'] . '&nbsp;</td><td>' . $o['billlastname'] . '&nbsp;</td><td>' . $o['email'] . '&nbsp;</td><td>' . $o['userid'] . '&nbsp;</td><td>' . $o['itemid'] . '&nbsp;</td><td>' . $o['company'] . '&nbsp;</td><td>$ ' . $itemtotal . '&nbsp;</td><td>$ ' . $total . '&nbsp;</td><td>$ ' . $settled . '&nbsp;</td></tr>';

Open in new window

0
 
LVL 1

Author Closing Comment

by:rgb192
ID: 31673681
thanks
0
 
LVL 82

Expert Comment

by:hielo
ID: 26194568
>>$checked=( isset($_POST['checked']) && in_array...

that should have been orders NOT checked:
$checked=( isset($_POST['orders']) && in_array...

>>thanks
You are welcome.

Regards,
Hielo
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I imagine that there are some, like me, who require a way of getting currency exchange rates for implementation in web project from time to time, so I thought I would share a solution that I have developed for this purpose. It turns out that Yaho…
This article discusses how to create an extensible mechanism for linked drop downs.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
Suggested Courses

580 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question