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:
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
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
}
?>
PLEASE help me.... this is for work, I'm tired, I've looked through many resources.... I feel stupid..lolCode:<?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);
}
?>
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.
I didn't look through the code because I don't know what you are trying to do exactly.
A checkbox is normally part of a form tag. It's just an input tag with type="checkbox"
HTML Forms and Input
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:
SCRIPT 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;
}
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.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);
}
?>
Programmer (n): An organism that can turn caffeine into code.
Programming would be so much easier without all the users.
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.
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.
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.
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks