Closed Thread
Page 1 of 2 12 LastLast
Results 1 to 10 of 11

Thread: Need help with a stupid checkbox....

  1. #1
    Parabola's Avatar
    Parabola is offline Programming Professional
    Join Date
    Jul 2009
    Location
    Texas
    Posts
    336
    Blog Entries
    4
    Rep Power
    13

    Question Need help with a stupid checkbox....

    So sad... I can do sql and other stuff with javascript.... but I can't do a stupid checkbox.... someone please help me.
    Here's the code for the input window that pops up first:
    Code:
    <?php
    session_start
    ();

    require_once(
    '../../config.db.php');
    require_once(
    '../../config.inc.php');
    require_once(
    "Functions/corp.functions.php");

    $action = (isset($_POST['action'])) ? ($_POST['action']) : ($_GET['action']);
    $link mysql_connect($myDbConfig->server,$myDbConfig->user,$myDbConfig->pass) or die(mysql_error());
    mysql_select_db($myDbConfig->db) or die(mysql_error());

    switch (
    $action){
        case 
    'form':
            
    getForm();
            break;
        default:
            break;
    }

    mysql_close($link);
    exit(
    0);

    function 
    getForm(){
        
        
    $userID $_SESSION['UserID'];
        
    $reportNo $_GET['repID'];
        
    ?>    
        // Add the additional 'advanced' VTypes
        Ext.apply(Ext.form.VTypes, {
          dateRange: function(val, field) {
            var date = field.parseDate(val);
            
            // We need to force the picker to update values to recaluate the disabled dates display
            var dispUpd = function(picker) {
              var ad = picker.activeDate;
              picker.activeDate = null;
              picker.update(ad);
            };
            
            if (field.startDateField) {
              var sd = Ext.getCmp(field.startDateField);
              sd.maxValue = date;
              if (sd.menu && sd.menu.picker) {
                sd.menu.picker.maxDate = date;
                dispUpd(sd.menu.picker);
              }
            } else if (field.endDateField) {
              var ed = Ext.getCmp(field.endDateField);
              ed.minValue = date;
              if (ed.menu && ed.menu.picker) {
                ed.menu.picker.minDate = date;
                dispUpd(ed.menu.picker);
              }
            }
            /*     Always return true since we're only using this vtype to set the min/max allowed values 
                (these are tested for after the vtype test) */
                
            return true;
        }});


        var itemsForm = getForm();
        
        
        function getForm(){
            var date = new Date();
            var sdate = new Date();
            var edate = new Date();
            
            // set start date to first day  of month and end date to last day
            // PHP will handle previous month of Jan (Dec of 'previous year')
            sdate.setMonth(sdate.getMonth()-1,1);
            edate.setMonth(edate.getMonth(),0);
            
            var startDate = new Ext.form.DateField({
                fieldLabel: 'Start Date',
                format: 'm/d/Y',
                name: 'start',
                id: 'startDate',
                endDateField: 'endDate',
                hiddenName: 'start',
                allowBlank: false,
                vtype: 'dateRange',
                maxValue: date,
                value: sdate
            });
                
            var endDate = new Ext.form.DateField({
                fieldLabel: 'End Date',
                format: 'm/d/Y',
                name: 'end',
                vtype: 'dateRange',
                id: 'endDate',
                startDateField: 'startDate',                
                hiddenName: 'end',
                allowBlank: false,
                maxValue: date,
                value: edate
            });
            
            var vHuman = new Ext.form.Checkbox({
                boxLabel: 'DMs',
                checked: true,
                value: isHuman
            });

            var vHouse = new Ext.form.Checkbox({
                boxLabel: 'House',
                checked: false,
                value: isHouse
            });  
            
            var itemsForm = new Ext.form.FormPanel({
                border: false, 
                height: 230, 
                id: 'itemsform',
                method:'POST',
                url:'reports/scheduler/newreport.php',
                baseParams: {userid: <?php echo $userID?>, reportid: <?php echo $reportNo?>}, 
                items:[startDate, endDate, vHuman, vHouse]
            });
            
            return itemsForm;
        }
    <?php
    }
    ?>
    and the code that actually runs the sql query and gets the data (yes, i know I haven't done anything with the checkbox data yet in sql... need this solved first)

    Code:
    <?php
        
    require_once('c:/htdocs/corp/config.inc.php');
        require_once(
    'c:/htdocs/corp/config.db.php');
        require_once(
    "Functions/corp.functions.php");
        require_once(
    "Logger/class.Logger.php");
        require_once(
    "Reports/class.ReportInstance.php");
        
        
    //$cfg['LOGGER_LEVEL'] = LOGGER_DEBUG; //all levels logged
        //$cfg['LOGGER_LEVEL'] = LOGGER_INFO; //loggs levels info,notice,warning,error,critical
        //$cfg['LOGGER_LEVEL'] = LOGGER_NOTICE; //loggs levels notice,warning,error,critical
        //$cfg['LOGGER_LEVEL'] = LOGGER_WARNING; //loggs levels warning,error,critical
        //$cfg['LOGGER_LEVEL'] = LOGGER_ERROR; //loggs levels error,critical
        
    $cfg['LOGGER_LEVEL'] = LOGGER_CRITICAL//loggs levels critical
        
        
    define('THIS_FILE','SalesDMGPReport.php');
        
    define('LOG_FILE','CORP');
        
        try{
            
    $conString "mysql://".$myDbConfig->user."@".$myDbConfig->server."/".$myDbConfig->db."?password=".$myDbConfig->pass."&logname=CORP";
            
    Logger::register('CORP',$conString);
        }catch(
    Exception $e){
            throw new 
    Exception($e->getMessage());
        }
        
        try{
            
    $log Logger::getInstance(LOG_FILE);
        }catch(
    Exception $e){
            throw new 
    Exception($e->getMessage());
        }
        
        
    $log->logMessage('Parsing arguments....',LOGGER_DEBUG,THIS_FILE);
        
    $riID $argv[1];
        if(!isset(
    $riID)){
            
    $log->logMessage("Missing required arguments",LOGGER_CRITICAL,THIS_FILE);
            throw new 
    Exception("Invalid arguments");
            exit(
    0);
        }else{
            
    $log->logMessage('Retrieved argument '.$riID,LOGGER_DEBUG,THIS_FILE);
        }
        
        
        
    $log->logMessage("Connecting to the ".$myDbConfig->db." database",LOGGER_DEBUG,THIS_FILE);
        
    $link = @mysql_connect($myDbConfig->server,$myDbConfig->user,$myDbConfig->pass);
        
    mysql_select_db($myDbConfig->db);
        
        
    $log->logMessage("Creating report instance using ID - ".$riID,LOGGER_DEBUG,THIS_FILE);
        
    $riObject = new ReportInstance($riID,$log,THIS_FILE);
        
    $userID $riObject->getSubmittingUser();
        
        
    $log->logMessage("Retrieving Criteria from the ReportInstanceObject",LOGGER_DEBUG,THIS_FILE);
        
    $log->logMessage(print_r($riObject,true),LOGGER_DEBUG,THIS_FILE);
        
        
        
    $sdate date('Y-m-d',strtotime($riObject->criteria['start']->getValue()));
        
    $edate date('Y-m-d',strtotime($riObject->criteria['end']->getValue()));

        
    $vhuman $riObject->criteria['vHuman']->getValue();
        
    $vhouse $riObject->criteria['vHouse']->getValue();
        
    $log->logMessage("Retrieving results",LOGGER_DEBUG,THIS_FILE);
        
        echo 
    $vhuman;
        echo 
    $vhouse;
        
        
    $data reportFunc($sdate,$edate,$vhuman,$vhouse,$log);
        
        
    writeFile($log,$data,$riID.'_1_1.json');
        
    $note "For ".$sdate." to ".$edate;
        
    $riObject->setNote($note);
        
    $riObject->setStatus('C');

        exit(
    1);
        
        
    /********************************************************************************************************************************
        *************************    FUNCTION(S)     ************************************************************************************
        *********************************************************************************************************************************/        
        
        
    function reportFunc($sdate,$edate,$vhuman,$vhouse,$log){
            
    $log->logMessage("date range { $sdate - $edate }",LOGGER_DEBUG,THIS_FILE);
            
            
    $arr=array();
            
            
    $sql  ="SELECT h.DistrictManager, ROUND(SUM(l.ShipQuantity * l.Price), 2) AS Sales, ROUND(SUM(l.ShipQuantity * l.Cost), 2) AS CostOfGoods, ";
            
    $sql .=" ROUND(((SUM(l.Price * l.ShipQuantity) - SUM(l.ShipQuantity * l.Cost)) / SUM(l.Price * l.ShipQuantity)) * 100, 2) AS GPP, ";
            
    $sql .=" ROUND(SUM(l.Price * l.ShipQuantity) - SUM(l.ShipQuantity * l.Cost), 2) AS GPD, ROUND(AVG(CommissionRate), 2) as AvgComm";
            
    $sql .=" FROM invoices_saleshead h INNER JOIN invoices_salesline l ";
            
    $sql .=" ON h.InvoiceNumber = l.InvoiceNumber";
            
    $sql .=" WHERE (l.InvoiceDate >= '$sdate') AND (l.InvoiceDate <= '$edate')";
            
    $sql .=" AND (l.ShipQuantity != 0) AND (l.Price != 0)";
            
    $sql .=" GROUP BY h.DistrictManager ORDER BY h.DistrictManager";
            
    // 
            //echo $sql;
            
    $rs mysql_query($sql) or die(mysql_error());
            
            while(
    $obj=mysql_fetch_object($rs)){
                
    $arr[]=$obj;
            }
            
            return 
    json_encode($arr);
        }
    ?>
    PLEASE help me.... this is for work, I'm tired, I've looked through many resources.... I feel stupid..lol
    Also- the date parameters work fine.

    Note to John, WingedPanther, Jaan, or Orjan- I made this post originally in Java forum, please erase it... thanks.
    Programmer (n): An organism that can turn caffeine into code.
    Programming would be so much easier without all the users.

  2. CODECALL Circuit advertisement
    Join Date
    Always
    Location
    Advertising world
    Posts
    Many

     
  3. #2
    Jordan Guest

    Re: Need help with a stupid checkbox....

    I didn't look through the code because I don't know what you are trying to do exactly.

  4. #3
    Join Date
    Jul 2006
    Posts
    16,491
    Blog Entries
    75
    Rep Power
    143

    Re: Need help with a stupid checkbox....

    A checkbox is normally part of a form tag. It's just an input tag with type="checkbox"
    HTML Forms and Input
    Programming is a branch of mathematics.
    My CodeCall Blog | My Personal Blog

  5. #4
    Parabola's Avatar
    Parabola is offline Programming Professional
    Join Date
    Jul 2009
    Location
    Texas
    Posts
    336
    Blog Entries
    4
    Rep Power
    13

    Re: Need help with a stupid checkbox....

    Ok, here's the deal... I finally realized what I was doing wrong, I didn't give the checkbox a name, so the value wasn't being passed. But now, I have a whole new issue.
    But first, allow me to explain what the goal is and what's going on.
    This report is supposed to pull up sales totals for Sales Reps for the company. Now, some sales territories, DM's, are vacant, and therefore in sql are marked as nonhuman (we have a field in sql, which is logical, named Human).
    The report (before being run) needs to have the option of showing Human (real Dm's), House (vacant DM Territories), or both. The manager wants me to use checkboxes for these options. Now, here's the new issue I am having: the values are passed, but only if the checkbox is checked. If it is not checked, it passes NO value to the scirpt.php file. RAWR! this breaks the code.
    Anyways, here is the updated code: (abridged as well, no need to repost entire files...)

    INPUT FILE:
    Code:
            var vHuman = new Ext.form.Checkbox({
                boxLabel: 'DMs',
                checked: true,
                name: 'human'
            });

            var vHouse = new Ext.form.Checkbox({
                boxLabel: 'House',
                checked: true,
                name: 'house'
            });
            
            var itemsForm = new Ext.form.FormPanel({
                border: false, 
                height: 230, 
                id: 'itemsform',
                method:'POST',
                url:'reports/scheduler/newreport.php',
                baseParams: {userid: <?php echo $userID?>, reportid: <?php echo $reportNo?>}, 
                items:[startDate, endDate, vHuman, vHouse]
            });
            
            return itemsForm;
        }
    SCRIPT FILE:
    Code:
    $vHuman = ($riObject->criteria['human']->getValue() == 'on');
        
    $vHouse = ($riObject->criteria['house']->getValue() == 'on');
        
    $sdate date('Y-m-d',strtotime($riObject->criteria['start']->getValue()));
        
    $edate date('Y-m-d',strtotime($riObject->criteria['end']->getValue()));

        
    $log->logMessage("Retrieving results",LOGGER_DEBUG,THIS_FILE);

        echo 
    '$vHuman = ';
        echo 
    $vHuman;
        echo 
    '$vHouse = ';
        echo 
    $vHouse;

        
        
        
    $data reportFunc($sdate,$edate,$vHouse,$vHuman,$log);
        
        
    writeFile($log,$data,$riID.'_1_1.json');
        
    $note "For ".$sdate." to ".$edate;
        
    $riObject->setNote($note);
        
    $riObject->setStatus('C');

        exit(
    1);
        
        
    /********************************************************************************************************************************
        *************************    FUNCTION(S)     ************************************************************************************
        *********************************************************************************************************************************/        
        
        
    function reportFunc($sdate,$edate,$vHouse,$vHuman,$log){
            
    $log->logMessage("date range { $sdate - $edate }",LOGGER_DEBUG,THIS_FILE);
            
            
    $arr=array();
            
            
    $sql  ="SELECT h.DistrictManager, ROUND(SUM(l.ShipQuantity * l.Price), 2) AS Sales, ROUND(SUM(l.ShipQuantity * l.Cost), 2) AS CostOfGoods, ";
            
    $sql .=" ROUND(((SUM(l.Price * l.ShipQuantity) - SUM(l.ShipQuantity * l.Cost)) / SUM(l.Price * l.ShipQuantity)) * 100, 2) AS GPP, ";
            
    $sql .=" ROUND(SUM(l.Price * l.ShipQuantity) - SUM(l.ShipQuantity * l.Cost), 2) AS GPD, ROUND(AVG(CommissionRate), 2) as AvgComm";
            
    $sql .=" FROM sales_districtmanagers d INNER JOIN invoices_saleshead h on d.DistrictManager = h.DistrictManager";
            
    $sql .=" INNER JOIN invoices_salesline l";
            
    $sql .=" ON h.InvoiceNumber = l.InvoiceNumber";
            
    $sql .=" WHERE (l.InvoiceDate >= '$sdate') AND (l.InvoiceDate <= '$edate')";
            
    $sql .=" AND (l.ShipQuantity != 0) AND (l.Price != 0) ";
            if(
    $vHuman AND !$vHouse){
            
    $sql .=" AND d.Human ";
            }
            elseif(!
    $vHuman AND $vHouse){
            
    $sql .=" AND !d.Human ";
            }
            
    $sql .=" GROUP BY h.DistrictManager ORDER BY h.DistrictManager";

            
    $rs mysql_query($sql) or die(mysql_error());
            
            while(
    $obj=mysql_fetch_object($rs)){
                
    $arr[]=$obj;
            }
            
            return 
    json_encode($arr);
        }
    ?> 
    This works great... so long as both checkboxes are checked. If only one checkbox, i.e. DM's, is checked, and House is not... the script breaks.
    Programmer (n): An organism that can turn caffeine into code.
    Programming would be so much easier without all the users.

  6. #5
    yuvi is offline Newbie
    Join Date
    Aug 2009
    Posts
    4
    Rep Power
    0

    Re: Need help with a stupid checkbox....

    Quote Originally Posted by Parabola View Post
    Now, here's the new issue I am having: the values are passed, but only if the checkbox is checked. If it is not checked, it passes NO value to the scirpt.php file. RAWR! this breaks the code.

    ...

    SCRIPT FILE:
    Code:
    $vHuman = ($riObject->criteria['human']->getValue() == 'on');
        
    $vHouse = ($riObject->criteria['house']->getValue() == 'on');
        ...
    ?> 
    This works great... so long as both checkboxes are checked. If only one checkbox, i.e. DM's, is checked, and House is not... the script breaks.
    So the problem on the php side is that you are having an "unset" variable? Maybe you can simply use the isset() method?


    Btw, this is where it breaks?
    $riObject->criteria['human']
    Ciao!

  7. #6
    Join Date
    Jul 2006
    Posts
    16,491
    Blog Entries
    75
    Rep Power
    143

    Re: Need help with a stupid checkbox....

    If a checkbox is not checked, it is not passed as part of the form data.
    Radio buttons make work better, as you can then have three values to check.
    Programming is a branch of mathematics.
    My CodeCall Blog | My Personal Blog

  8. #7
    Parabola's Avatar
    Parabola is offline Programming Professional
    Join Date
    Jul 2009
    Location
    Texas
    Posts
    336
    Blog Entries
    4
    Rep Power
    13

    Talking Re: Need help with a stupid checkbox....

    Congratulations yuvi the Newbie! Welcome to CodeCall!
    lol
    It's fixed, using the isset() function like yuvi said. Thanks much, very appreciated. +rep! (even though I don't have much to give lol)
    Here's the final code, if anyone ever runs into this (very abridged)

    INPUT:
    HTML Code:
    		var vHuman = new Ext.form.Checkbox({
    			boxLabel: 'DMs',
    			checked: true,
    			name: 'human'
    		});
    
    		var vHouse = new Ext.form.Checkbox({
    			boxLabel: 'House',
    			checked: false,
    			name: 'house'
    		});
    		
    		var itemsForm = new Ext.form.FormPanel({
    	    	border: false, 
    			height: 230, 
    			id: 'itemsform',
    			method:'POST',
    			url:'reports/scheduler/newreport.php',
    			baseParams: {userid: <?php echo $userID; ?>, reportid: <?php echo $reportNo; ?>}, 
    	    	items:[startDate, endDate, vHuman, vHouse]
    	    });
    		
    		return itemsForm;
    	}

    SCRIPT:
    Code:
        $vHuman = isset($riObject->criteria['human']);
        
    $vHouse = isset($riObject->criteria['house']);
        if (
    $vHouse == null){
            
    $vHouse false;
            }
        if (
    $vHuman == null){
            
    $vHuman false;
            }
        
    $sdate date('Y-m-d',strtotime($riObject->criteria['start']->getValue()));
        
    $edate date('Y-m-d',strtotime($riObject->criteria['end']->getValue()));

        
    $log->logMessage("Retrieving results",LOGGER_DEBUG,THIS_FILE);

        
    $data reportFunc($sdate,$edate,$log,$vHouse,$vHuman);
        
        
    writeFile($log,$data,$riID.'_1_1.json');
        
    $note "For ".$sdate." to ".$edate." For Everyone";
        if ((
    $vHuman == true) && ($vHouse == false)){
            
    $note "For ".$sdate." to ".$edate." For DM's Only";
        }
        if ((
    $vHuman == true) && ($vHouse == false)){
            
    $note "For ".$sdate." to ".$edate." For House Only";
        }
        
    $riObject->setNote($note);
        
    $riObject->setStatus('C');

        exit(
    1);
        
        
    /********************************************************************************************************************************
        *************************    FUNCTION(S)     ************************************************************************************
        *********************************************************************************************************************************/        
        
        
    function reportFunc($sdate,$edate,$log,$vHouse,$vHuman){
            
    $log->logMessage("date range { $sdate - $edate }",LOGGER_DEBUG,THIS_FILE);
            
            
    $arr=array();
            
            
    $sql  ="SELECT h.DistrictManager, ROUND(SUM(l.ShipQuantity * l.Price), 2) AS Sales, ROUND(SUM(l.ShipQuantity * l.Cost), 2) AS CostOfGoods, ";
            
    $sql .=" ROUND(((SUM(l.Price * l.ShipQuantity) - SUM(l.ShipQuantity * l.Cost)) / SUM(l.Price * l.ShipQuantity)) * 100, 2) AS GPP, ";
            
    $sql .=" ROUND(SUM(l.Price * l.ShipQuantity) - SUM(l.ShipQuantity * l.Cost), 2) AS GPD, ROUND(AVG(CommissionRate), 2) as AvgComm";
            
    $sql .=" FROM sales_districtmanagers d INNER JOIN invoices_saleshead h on d.DistrictManager = h.DistrictManager";
            
    $sql .=" INNER JOIN invoices_salesline l";
            
    $sql .=" ON h.InvoiceNumber = l.InvoiceNumber";
            
    $sql .=" WHERE (l.InvoiceDate >= '$sdate') AND (l.InvoiceDate <= '$edate')";
            
    $sql .=" AND (l.ShipQuantity != 0) AND (l.Price != 0) ";
            if((
    $vHuman == true) && ($vHouse == false)){
            
    $sql .=" AND (d.Human = '1') ";
            }
            if((
    $vHuman == false) && ($vHouse == true)){
            
    $sql .=" AND (d.Human = '0') ";
            }
            
    $sql .=" GROUP BY h.DistrictManager ORDER BY h.DistrictManager";

            
    $rs mysql_query($sql) or die(mysql_error());
            
            while(
    $obj=mysql_fetch_object($rs)){
                
    $arr[]=$obj;
            } 
    Programmer (n): An organism that can turn caffeine into code.
    Programming would be so much easier without all the users.

  9. #8
    yuvi is offline Newbie
    Join Date
    Aug 2009
    Posts
    4
    Rep Power
    0

    Smile Re: Need help with a stupid checkbox....

    Quote Originally Posted by Parabola View Post
    Congratulations yuvi the Newbie! Welcome to CodeCall!
    lol
    It's fixed, using the isset() function like yuvi said. Thanks much, very appreciated. +rep! (even though I don't have much to give lol)
    Great! I'm happy it worked

    Ciao!
    Yuvi

  10. #9
    Parabola's Avatar
    Parabola is offline Programming Professional
    Join Date
    Jul 2009
    Location
    Texas
    Posts
    336
    Blog Entries
    4
    Rep Power
    13

    Re: Need help with a stupid checkbox....

    One last update: isset() was returning either null or true, So as you saw in last post, I used a stupid if null then make false code. I redid that part:

    Code:
        $vHuman = (isset($riObject->criteria['human']) ? true false); 
    Programmer (n): An organism that can turn caffeine into code.
    Programming would be so much easier without all the users.

  11. #10
    yuvi is offline Newbie
    Join Date
    Aug 2009
    Posts
    4
    Rep Power
    0

    Re: Need help with a stupid checkbox....

    Quote Originally Posted by Parabola View Post
    One last update: isset() was returning either null or true, So as you saw in last post, I used a stupid if null then make false code. I redid that part:

    Code:
        $vHuman = (isset($riObject->criteria['human']) ? true false); 
    Are you sure isset() was returning null? Theoretically it should return a boolean (h t t p://ch2.php.net/isset). So you can simply do:
    Code:
        $vHuman = isset($riObject->criteria['human']; 

Closed Thread
Page 1 of 2 12 LastLast

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. I want to use a checkbox value to get another field
    By Alhazred in forum JavaScript and CSS
    Replies: 1
    Last Post: 10-13-2011, 10:47 PM
  2. PHP and Checkbox
    By justsachin4u in forum PHP Development
    Replies: 4
    Last Post: 08-11-2011, 08:28 AM
  3. how to add checkbox on groupbox
    By Amonijack in forum Pascal and Delphi
    Replies: 3
    Last Post: 03-13-2011, 11:18 AM
  4. Listbox to Checkbox
    By Christoph in forum Visual Basic Programming
    Replies: 11
    Last Post: 07-19-2009, 12:11 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts