session_start();
$ses = $_GET['ses'];
$form_ses = $_GET['form_ses'];
$report = $_GET['r'];
$dir = $_GET['dir'];
include "../{$dir}/database.php";
include 'common.php';
if (activityPasswordNeeded($report)) {
    $session = nuSession($ses, false);
    if ($session->foundOK == '') {
        print 'you have been logged out..';
        return;
    }
}
$formValue = getSelectionFormVariables($form_ses);
$setup = nuSetup();
$T = nuRunQuery("SELECT * FROM zzsys_activity WHERE sat_all_code = '{$report}'");
$A = db_fetch_object($T);
//----------allow for custom code----------------------------------------------
$globalValue = getglobalValue($ses);
//----------create an array of hash variables that can be used in any "hashString"
$sesVariables = recordToHashArray('zzsys_session', 'zzsys_session_id', $ses);
//--session values (access level and user etc. )
$sysVariables = sysVariablesToHashArray($form_ses);
//--values in sysVariables from the calling lookup page
$arrayOfHashVariables = joinHashArrays($sysVariables, $sesVariables);
//--join the arrays together
$newFormArray = arrayToHashArray($formValue);
$arrayOfHashVariables = joinHashArrays($arrayOfHashVariables, $newFormArray);
//--join the arrays together
eval(replaceHashVariablesWithValues($arrayOfHashVariables, $A->sat_procedure_code));
 function loadAfterConstruct($theFormID, $theRecordID, $clone, $delete, $runActivity, $dir, $ses, $tempObjectTable, $session)
 {
     $this->access_level = $session->sss_access_level;
     $this->session_id = $session->sss_session_id;
     $this->zzsys_user_id = $session->sss_zzsys_user_id;
     $this->zzsys_user_group_name = $session->sss_zzsys_user_group_name;
     $this->startTime = time();
     $this->objectTableName = $tempObjectTable;
     $this->customDirectory = $dir;
     $this->session = $ses;
     $this->formsessionID = uniqid('1');
     nuRunQuery("DELETE FROM zzsys_variable WHERE sva_id = '{$this->formsessionID}'");
     $this->formID = $theFormID;
     //---Primary Key of zzsys_form Table
     $this->form = formFields($theFormID);
     $this->recordID = $theRecordID;
     //---ID of displayed record (-1 means a new record)
     setnuVariable($this->formsessionID, nuDateAddDays(Today(), 2), 'recordID', $this->recordID);
     $this->cloning = $clone;
     //---Whether this will be a new record cloned from $formID's record
     $this->delete = $delete;
     $this->setup = nuSetup();
     //----------create an array of hash variables that can be used in any "hashString"
     if ($this->form->sfo_report_selection != '1') {
         $T = nuRunQuery("SELECT " . $this->form->sfo_table . ".* FROM " . $this->form->sfo_table . " WHERE " . $this->form->sfo_primary_key . " = '{$this->recordID}'");
         $this->recordValues = db_fetch_array($T);
         $this->arrayOfHashVariables = recordToHashArray($this->form->sfo_table, $this->form->sfo_primary_key, $this->recordID);
         //--values of this record
     }
     $this->arrayOfHashVariables['#recordID#'] = $theRecordID;
     //--this record's id
     $this->arrayOfHashVariables['#id#'] = $theRecordID;
     //--this record's id
     $this->arrayOfHashVariables['#clone#'] = $clone;
     //--if it is a clone
     $this->arrayOfHashVariables['#formSessionID#'] = $this->formsessionID;
     //--form session id
     $sVariables = recordToHashArray('zzsys_session', 'zzsys_session_id', $ses);
     //--session values (access level and user etc. )
     $this->arrayOfHashVariables = joinHashArrays($this->arrayOfHashVariables, $sVariables);
     //--join the arrays together
     $nuHashVariables = $this->arrayOfHashVariables;
     //--added by sc 23-07-2009
     //----------allow for custom code----------------------------------------------
     //--replace hash variables then run code
     $runCode = replaceHashVariablesWithValues($this->arrayOfHashVariables, $this->form->sfo_custom_code_run_before_open);
     if ($_GET['debug'] != '') {
         tofile('sfo_custom_code_run_before_open hash variables : debug value:' . $_GET['debug']);
         tofile(print_r($this->arrayOfHashVariables, true));
         tofile($runCode);
     }
     eval($runCode);
     if ($newRecordID != '') {
         $this->recordID = $newRecordID;
     }
     //-----------custom code end---------------------------------------------------
     $this->runActivity = $runActivity;
     //----defaultJSfunctions needs $formTabs populated first
     $this->defaultJSfunctions();
     $this->createActionButtonsHTML();
 }
 public function buildControls($sectionNumber, $canGrow, $record)
 {
     //tofile("Build Controls");
     $s = '';
     $setup = nuSetup();
     $dq = '"';
     //tofile("Count Controls ".count($this->report->Controls));
     for ($i = 0; $i < count($this->report->Controls); $i++) {
         if ($this->report->Controls[$i]->Section == $sectionNumber) {
             //tofile("Get Control");
             $Name = $this->report->Controls[$i]->Name;
             $Source = $this->report->Controls[$i]->ControlSource;
             $Controltype = $this->report->Controls[$i]->ControlType;
             //tofile("Control Type: ".$this->report->Controls[$i]->ControlType);
             $Top = $this->toScale($this->report->Controls[$i]->Top);
             $Width = $this->toScale($this->report->Controls[$i]->Width);
             $Height = $this->toScale($this->report->Controls[$i]->Height);
             $Left = $this->toScale($this->report->Controls[$i]->Left);
             $Section = $this->report->Controls[$i]->Section;
             $Fontname = $this->report->Controls[$i]->FontName;
             $Fontsize = $this->report->Controls[$i]->FontSize;
             if (intval($Fontsize) >= 12) {
                 $Fontsize = $Fontsize - 4;
             } else {
                 if (intval($Fontsize) == 11) {
                     $Fontsize = $Fontsize - 3;
                 } else {
                     if (intval($Fontsize) <= 10) {
                         $Fontsize = $Fontsize - 2;
                     }
                 }
             }
             $Fontweight = $this->report->Controls[$i]->FontWeight;
             $Fontname = iif($Fontname == null, 'Arial', $Fontname);
             $Fontname = iif($Fontname != 'Arial', 'Arial', $Fontname);
             $Fontweight = iif($Fontweight == 'bold', 'B', '');
             $Caption = $this->report->Controls[$i]->Caption;
             $ln = iif($Caption == '', 2, 0);
             $TextAlign = $this->report->Controls[$i]->TextAlign;
             $TextAlign = $this->GetTextAlign($TextAlign);
             $ForeColor = $this->report->Controls[$i]->ForeColor;
             $BackColor = $this->report->Controls[$i]->BackColor;
             $BackStyle = $this->report->Controls[$i]->BackStyle;
             $BorderWidth = $this->report->Controls[$i]->BorderWidth;
             $BorderColor = $this->report->Controls[$i]->BorderColor;
             $Format = $this->report->Controls[$i]->Format;
             $Decimal = $this->report->Controls[$i]->DecimalPlaces;
             $IsHyperlink = $this->report->Controls[$i]->IsHyperlink;
             $ReportTag = $this->report->Controls[$i]->Tag;
             $LikeClause = $this->report->Controls[$i]->SmartTags;
             $LikeClause = str_replace("\"", "", $LikeClause);
             //$ForeColor					= $this->html2rgb('#'.$ForeColor);
             //$BackColor 					= $this->html2rgb('#'.$BackColor);
             //$BorderColor 				= $this->html2rgb('#'.$BorderColor);
             /*if ($BackColor == '' || $BackColor == strtolower('#FFFFFF') || $BackColor == strtolower('FFFFFF')) {
             			$BackStyle = 0;
             		} else {
             			$BackStyle = 1;
             		}*/
             $ForeColor = iif(substr($ForeColor, 0, 1) == '#', $ForeColor, '#' . $ForeColor);
             $BackColor = iif(substr($BackColor, 0, 1) == '#', $BackColor, '#' . $BackColor);
             $BorderColor = iif(substr($BorderColor, 0, 1) == '#', $BorderColor, '#' . $BorderColor);
             $ForeColor = $this->html2rgb($ForeColor);
             $BackColor = $this->html2rgb($BackColor);
             $BorderColor = $this->html2rgb($BorderColor);
             $this->SetTextColor($ForeColor[0], $ForeColor[1], $ForeColor[2]);
             $this->SetFillColor($BackColor[0], $BackColor[1], $BackColor[2]);
             $this->SetDrawColor($BorderColor[0], $BorderColor[1], $BorderColor[2]);
             if ($BorderWidth > 0) {
                 $this->SetLineWidth($BorderWidth / 100);
                 $BorderWidth = 1;
             }
             //$BorderWidth = 1;
             //$Top = (($this->stackheight + $Top)/100) + 0.3;
             $Left = $Left / 100 + 0.2;
             //$Width = ($Width / 100) + 0.002;
             $Width = $Width / 100;
             $Height = $Height / 100;
             $Top = ($this->stackheight + $Top * 1.0) / 100 + 0.25;
             //========================================================================================
             if ($this->controlType($this->report->Controls[$i]->ControlType) == 'page break') {
                 $this->justDidPageBreak = true;
                 $this->hasExplicitPageBreak = true;
                 continue;
             }
             if ($this->controlType($this->report->Controls[$i]->ControlType) == 'image') {
                 $thetag = $this->report->Controls[$i]->ControlSource;
                 $imageCode = $this->report->Controls[$i]->Graph;
                 //-- the code (sim_code in zzsys_image)
                 $thedir = $_GET['dir'];
                 for ($a = 0; $a < count($this->fields); $a++) {
                     //-----replace any strings, with hashes around them, in the querystring that match
                     //-----fieldnames in the table
                     //-----with values from the table
                     //-----e.g. id=#ID# could become id=007
                     $thetag = str_replace('#' . $this->fields[$a] . '#', $record[$this->fields[$a]], $thetag);
                 }
                 $thetag = str_replace(" ", "%20", $thetag);
                 // Escapes any spaces in the parameters/arguments
                 //tofile("Graph Tag: ".$thetag);
                 $imageT = nuRunQuery("SELECT zzsys_image_id FROM zzsys_image WHERE sim_code = '{$imageCode}'");
                 $imageR = db_fetch_row($imageT);
                 $s = $s . "   <div  style='position:absolute;left:{$Left};top:{$Top};height:{$Height}'>\n";
                 $s = $s . "      <img src='formimage.php?dir={$thedir}&iid={$imageR['0']}&{$thetag}'>\n";
                 $s = $s . "   </div>\n";
                 //tofile("http://dev.nubuilder.com/productionnu2/formimage.php?dir=$thedir&iid=$imageR[0]&$thetag");
                 $logo = fopen("http://dev.nubuilder.com/productionnu2/formimage.php?dir=" . $thedir . "&iid=" . $imageR[0] . "&" . $thetag, "r");
                 file_put_contents('temp' . $this->imagecount . '.png', $logo);
                 if (filesize('temp' . $this->imagecount . '.png') > 0) {
                     $im = imagecreatefrompng('temp' . $this->imagecount . '.png');
                     imageinterlace($im, 0);
                     imagepng($im, 'temp' . $this->imagecount . '.png');
                     $imageDimensions = getimagesize('temp' . $this->imagecount . '.png');
                     $imageWidth = $imageDimensions[0] * 0.01;
                     $imageHeight = $imageDimensions[1] * 0.01;
                     $this->Image('temp' . $this->imagecount . '.png', $Left, $Top, $imageWidth, $imageHeight);
                 }
                 unlink('temp' . $this->imagecount . '.png');
                 $this->imagecount++;
                 $this->Rect($Left, $Top, $imageWidth, $imageHeight, 'D');
                 continue;
             }
             //========================================================================================
             if ($this->controlType($this->report->Controls[$i]->ControlType) == 'graph' || $this->report->Controls[$i]->ControlType == 'Graph') {
                 if ($this->controlType($this->report->Controls[$i]->ControlType) == 'graph') {
                     $thetag = $this->report->Controls[$i]->ControlSource;
                     $thename = $this->report->Controls[$i]->Graph;
                     tofile("lowercase graph: " . $thetag);
                 } else {
                     if ($this->report->Controls[$i]->ControlType == 'Graph') {
                         $thetag = $this->report->Controls[$i]->ControlSource;
                         $thename = $this->report->Controls[$i]->Graph;
                         tofile("uppercase graph: " . $thetag);
                     }
                 }
                 $thedir = $_GET['dir'];
                 for ($a = 0; $a < count($this->fields); $a++) {
                     //-----replace any strings, with hashes around them, in the querystring that match
                     //-----fieldnames in the table
                     //-----with values from the table
                     //-----e.g. id=#ID# could become id=007
                     $thetag = str_replace('#' . $this->fields[$a] . '#', $record[$this->fields[$a]], $thetag);
                 }
                 $addSession = '&ses=' . $_GET['ses'];
                 $thetag = str_replace(" ", "%20", $thetag);
                 // Escapes any spaces in the parameters/arguments
                 //tofile("Graph Tag: ".$thetag);
                 $logo = fopen("http://www.nubuilder.com/productionnu2/graph_report.php?dir={$thedir}{$addSession}&activityID={$this->reportID}&graph_name={$thename}&{$thetag}", "r");
                 file_put_contents('temp' . $this->imagecount . '.png', $logo);
                 $imageDimensions = getimagesize('temp' . $this->imagecount . '.png');
                 $imageWidth = $imageDimensions[0] * 0.01;
                 $imageHeight = $imageDimensions[1] * 0.01;
                 $this->Image('temp' . $this->imagecount . '.png', $Left, $Top, $imageWidth, $imageHeight);
                 unlink('temp' . $this->imagecount . '.png');
                 $this->imagecount++;
                 $this->Rect($Left, $Top, $imageWidth, $imageHeight, 'D');
             }
             //========================================================================================
             if ($this->controlType($this->report->Controls[$i]->ControlType) == 'label' || $this->report->Controls[$i]->ControlType == 'Label') {
                 if (substr($this->report->Controls[$i]->ControlSource, 0, 4) == '<img') {
                     //tofile("Test Caption ".$this->GetImageLink($ReportClass->Controls[$i]->Caption));
                     //tofile("Show Header fields ".$Name." ".$Source." ".$Caption." ".$Fontname." P".$PageNumber." ".$Top);
                     $this->SetXY($Left, $Top);
                     $output = $this->parse($this->report->Controls[$i]->ControlSource);
                     $image_properties = $this->GetImageSourceAndDimensions($output);
                     if (substr($image_properties['source'], -4, 4) == '.jpg' || substr($image_properties['source'], -4, 4) == '.png') {
                         $this->Image($image_properties['source'], $Left, $Top, $image_properties['width'], $image_properties['height']);
                     }
                     continue;
                 }
                 if ($this->report->Controls[$i]->Tag != $this->report->Controls[$i]->ControlType) {
                     //tofile("Check Tag ".$this->report->Controls[$i]->Tag);
                     //$s                  = $s . "      <div class='$Name' style='position:absolute;top:$Top;height:$Height'><img src='$setup->seStartingDirectory/reports/".$this->report->Controls[$i]->Tag.".jpg'></div>\n";
                     $this->SetXY($Left, $Top);
                     //$this->Image($setup->seStartingDirectory."/reports/".$ReportClass->Controls[$i]->Tag.".jpg",$Left,$Top,$Width,$Height);
                     if ($ReportClass->Controls[$i]->Caption != '') {
                         $this->SetFont($Fontname, $Fontweight, $Fontsize);
                         $this->SetXY($Left, $Top);
                         $this->Cell($Width, $Height, $Caption, $BorderWidth, $ln, $TextAlign);
                         //tofile("Caption: ".$Caption);
                     }
                     continue;
                 }
                 if ($Source == '="Page " & [Page] & " of " & [Pages]' || $Source == 'Page #thePageNumber# of #totalNumberOfPages#') {
                     $Caption = "Page " . $this->pageNumber . " of " . $GLOBALS['TotalPages'];
                     $this->SetFont($Fontname, $Fontweight, $Fontsize);
                     $this->SetXY($Left, $Top);
                     $this->Cell($Width, $Height, $Caption, $BorderWidth, $ln, $TextAlign, $BackStyle);
                     $s = $s . "   <div class='{$Name}'>Page #thePageNumber# of #totalNumberOfPages#</div>\n";
                     continue;
                 } else {
                     if ($Source == '=Date()' || $Source == '=Now()') {
                         if ($Format == '' || $Format == '20' || $Format == 'Long Date') {
                             $formattedValue = date('d-M-Y H:i');
                         } else {
                             $formattedValue = date($this->accessDateFormatToPHPDateFormat($Format));
                         }
                         $Caption = $formattedValue;
                         $this->SetFont($Fontname, $Fontweight, $Fontsize);
                         $this->SetXY($Left, $Top);
                         $this->Cell($Width, $Height, $Caption, $BorderWidth, $ln, $TextAlign, $BackStyle);
                         $s = $s . "      <div class='{$Name}' style='position:absolute;top:{$Top};height:{$Height}'>{$formattedValue}</div>\n";
                         continue;
                     }
                 }
                 $s = $s . "      <div class='{$Name}' style='position:absolute;top:{$Top};height:{$Height}'>" . $this->report->Controls[$i]->Caption . "</div>\n";
                 if (strlen($Caption) == 1 && $BorderWidth >= 1) {
                     $this->SetDrawColor($BorderColor[0], $BorderColor[1], $BorderColor[2]);
                     $this->SetFillColor($BorderColor[0], $BorderColor[1], $BorderColor[2]);
                     $BackStyle = 1;
                 }
                 $this->SetFont($Fontname, $Fontweight, $Fontsize);
                 //tofile("Label: ".$this->report->Controls[$i]->ControlSource);
                 $output = $this->parse($this->report->Controls[$i]->Caption);
                 if ($output[0]['innerhtml'] == null) {
                     //tofile("Label used: ".$this->report->Controls[$i]->Caption);
                     $break_variants = array("<br />", "<BR />", "<br/>", "<BR/>");
                     $string = str_replace($break_variants, "<br>", $this->report->Controls[$i]->Caption);
                     $lines = explode("<br>", $string);
                     if (sizeof($lines) > 1) {
                         $string = "";
                         for ($j = 0; $j < sizeof($lines); $j++) {
                             $lines[$j] = trim($lines[$j]);
                             $string = $string . $lines[$j] . "\n";
                         }
                     }
                     if (sizeof($lines) > 1) {
                         //tofile("more than 1 line");
                         $Height = $this->CalculateLineHeight($Fontsize);
                         $this->SplitLines($Width, $Height, $string, $BorderWidth, $ln, $TextAlign, $BackColor, $BackStyle, $Left, $Top, 0, $i);
                     } else {
                         //tofile("1 line only");
                         $this->SetXY($Left, $Top);
                         $this->Cell($Width, $Height, $this->report->Controls[$i]->Caption, $BorderWidth, $ln, $TextAlign, $BackStyle);
                     }
                 } else {
                     $this->SetXY($Left, $Top);
                     $this->SetHTMLAttributes($Width, $Height, $output, $BorderWidth, $ln, $TextAlign, $BackColor, $BackStyle, $Left, $Top);
                 }
                 //$this->Cell($Width,$Height,$r[$ReportClass->Controls[$i]->ControlSource],$BorderWidth,$ln,$TextAlign,$BackColor);
                 //$this->SetFont($Fontname,$Fontweight,$Fontsize);
                 //$this->SetXY($Left, $Top);
                 //$this->Cell($Width,$Height,$Caption,$BorderWidth,$ln,$TextAlign,$BackStyle);
             }
             //========================================================================================
             if ($this->controlType($this->report->Controls[$i]->ControlType) == 'text area' || $this->report->Controls[$i]->ControlType == 'Field') {
                 $formattedValue = $record[$this->report->Controls[$i]->ControlSource];
                 $formattedValue = str_replace("&nbsp;", " ", $formattedValue);
                 $formattedValue = str_replace("&nbsp", " ", $formattedValue);
                 if ($this->report->Controls[$i]->Tag != '') {
                     $s = $s . "      <div class='{$Name}' style='position:absolute;top:{$Top};height:{$Height}'><img src='{$setup->seStartingDirectory}/reports/" . $this->report->Controls[$i]->Tag . ".jpg'></div>\n";
                 }
                 //Sum
                 $theSource = $this->report->Controls[$i]->ControlSource;
                 //tofile("Source: ".strtoupper(substr($theSource, 0, 8)));
                 if (substr($theSource, 0, 6) == '=Sum([' or strtoupper(substr($theSource, 0, 10)) == '=PERCENT([' or substr($theSource, 0, 4) == 'sum(' or strtoupper(substr($theSource, 0, 8)) == 'PERCENT(') {
                     $sumIt = substr($theSource, 0, 6) == '=Sum([' || substr($theSource, 0, 4) == 'sum(';
                     //tofile(substr($theSource, 0, 10)." flag ".$sumIt);
                     if ($sumIt) {
                         //--if the sum function
                         $SumOn = str_replace('=Sum([', '', $theSource);
                         $SumOn = str_replace('])', '', $SumOn);
                         $SumOn = str_replace('sum(', '', $SumOn);
                         $SumOn = str_replace(')', '', $SumOn);
                         $selectFields = 'sum(' . $SumOn . '_Sum) as answer ';
                     } else {
                         //--if the Percent function
                         $SumOn = substr($theSource, 8);
                         //tofile("Sum On: ".$SumOn);
                         $SumOn = str_replace(']', '', $SumOn);
                         //-- remove right square brackets
                         $SumOn = str_replace('[', '', $SumOn);
                         //-- remove left square brackets
                         $SumOn = str_replace(')', '', $SumOn);
                         //-- remove only right bracket
                         $SumOn = str_replace(' ', '', $SumOn);
                         //-- remove any spaces
                         $theFields = explode(',', $SumOn);
                         //-- split left and right field
                         $selectFields = 'sum(' . $theFields[0] . '_Sum) as divideIt, sum(' . $theFields[1] . '_Sum) as BYY ';
                         //tofile("Select Fields: ".$selectFields);
                     }
                     $SectionLevel = $this->sectionLevel($sectionNumber);
                     for ($ii = 0; $ii <= $SectionLevel; $ii++) {
                         if ($ii == 0) {
                             if ($this->report->Groups[$ii]->Field != '') {
                                 $whereClause = $this->report->Groups[$ii]->Field . " = {$dq}" . $record[$this->report->Groups[$ii]->Field] . "{$dq}";
                             }
                         } else {
                             if ($this->report->Groups[$ii]->Field != '') {
                                 $whereClause = $whereClause . ' AND ' . $this->report->Groups[$ii]->Field . " = {$dq}" . $record[$this->report->Groups[$ii]->Field] . "{$dq}";
                             }
                         }
                     }
                     $SumOn = trim($SumOn);
                     if (strlen($SectionLevel) == 0) {
                         $whereClause = "SELECT {$selectFields} FROM {$this->sumTT}";
                     } else {
                         $whereClause = "SELECT {$selectFields} FROM {$this->sumTT} WHERE {$whereClause}";
                     }
                     $t1 = nuRunQuery($whereClause);
                     $r1 = mysql_fetch_row($t1);
                     $formattedValue = $r1[0];
                     //tofile("Sum Value: ".$formattedValue);
                     if (!$sumIt) {
                         //---using the 'PERCENT' function
                         if ($r1[1] == 0) {
                             $formattedValue = 0;
                             //--because nothing can be divided by zero
                         } else {
                             $formattedValue = $r1[0] / $r1[1] * 100;
                         }
                     }
                     if ($Format == 'Fixed') {
                         if ($r1[0] != '') {
                             $formattedValue = number_format($r1[0], $Decimal);
                         }
                     }
                     //format of the result of the sum
                     if ($Format == 'Currency') {
                         if ($r1[0] != '') {
                             $formattedValue = "\$" . number_format($r1[0], 2);
                             $formattedValue = str_replace('$-', '-$', $formattedValue);
                         }
                     }
                     $formattedValue = formatTextValue($formattedValue, $Format);
                     $Caption = $formattedValue;
                     $this->SetFont($Fontname, $Fontweight, $Fontsize);
                     $this->SetXY($Left, $Top);
                     $this->Cell($Width, $Height, $this->SetStringByWidth($Caption, $Width - 0.1), $BorderWidth, $ln, $TextAlign, $BackStyle);
                     $s = $s . "      <div class='{$Name}' style='position:absolute;top:{$Top};height:{$Height}'>{$formattedValue}</div>\n";
                 } else {
                     //page display
                     if ($Source == '="Page " & [Page] & " of " & [Pages]' || $Source == 'Page #thePageNumber# of #totalNumberOfPages#') {
                         $Caption = "Page " . $this->pageNumber . " of " . $GLOBALS['TotalPages'];
                         $this->SetFont($Fontname, $Fontweight, $Fontsize);
                         $this->SetXY($Left, $Top);
                         $this->Cell($Width, $Height, $Caption, $BorderWidth, $ln, $TextAlign, $BackStyle);
                         $s = $s . "   <div class='{$Name}'>Page #thePageNumber# of #totalNumberOfPages#</div>\n";
                     } else {
                         //date display
                         if ($Source == '=Date()' or $Source == '=Now()') {
                             if ($Format == '' || $Format == '20' || $Format == 'Long Date') {
                                 $formattedValue = date('d-M-Y H:i');
                             } else {
                                 $formattedValue = date($this->accessDateFormatToPHPDateFormat($Format));
                             }
                             //$formattedValue     = date($this->accessDateFormatToPHPDateFormat($Format));
                             $Caption = $formattedValue;
                             $this->SetFont($Fontname, $Fontweight, $Fontsize);
                             $this->SetXY($Left, $Top);
                             $this->Cell($Width, $Height, $Caption, $BorderWidth, $ln, $TextAlign, $BackStyle);
                             $s = $s . "      <div class='{$Name}' style='position:absolute;top:{$Top};height:{$Height}'>{$formattedValue}</div>\n";
                         } else {
                             //format number
                             if ($Format == 'Fixed') {
                                 if ($record[$this->report->Controls[$i]->ControlSource] != '') {
                                     $formattedValue = number_format($record[$this->report->Controls[$i]->ControlSource], $Decimal);
                                 }
                             }
                             //currency number
                             if ($Format == 'Currency') {
                                 $formattedValue = "\$" . number_format($record[$this->report->Controls[$i]->ControlSource], 2);
                                 $formattedValue = str_replace('$-', '-$', $formattedValue);
                             }
                             //date format (no todate() and now())
                             if (substr($Format, 0, 2) == 'dd' or substr($Format, 0, 2) == 'mm' or substr($Format, 0, 2) == 'yy' or substr($Format, 0, 2) == 'hh' or substr($Format, 0, 2) == 'nn' or substr($Format, 0, 2) == 'ss') {
                                 //for sql format case yyyy-mm-dd
                                 if (substr($formattedValue, 4, 1) == '-' and substr($formattedValue, 7, 1) == '-') {
                                     $timestamp = mktime(0, 0, 0, substr($formattedValue, 5, 2), substr($formattedValue, 8, 2), substr($formattedValue, 0, 4));
                                     $formattedValue = date($this->accessDateFormatToPHPDateFormat($Format), $timestamp);
                                 }
                             }
                             $formattedValue = formatTextValue($formattedValue, $Format);
                             //tofile($formattedValue);
                             if ($this->report->Controls[$i]->CanGrow == 'True' and $canGrow) {
                                 //$oldValue               = $formattedValue;
                                 $lines = $this->SplitAndWordWrapText($formattedValue, $Width);
                                 if (sizeof($lines) > 1) {
                                     $string = "";
                                     for ($j = 0; $j < sizeof($lines); $j++) {
                                         $lines[$j] = trim($lines[$j]);
                                         $string = $string . $lines[$j] . "<br>";
                                     }
                                 }
                                 $this->SetFont($Fontname, $Fontweight, $Fontsize);
                                 if (sizeof($lines) > 1) {
                                     //tofile("more than 1 line");
                                     $Height = $this->CalculateLineHeight($Fontsize);
                                     $this->SplitLines($Width, $Height, $string, $BorderWidth, $ln, $TextAlign, $BackColor, $BackStyle, $Left, $Top, sizeof($lines), $i);
                                 } else {
                                     //tofile("1 line only");
                                     $this->SetXY($Left, $Top);
                                     $this->Cell($Width, $Height, $lines[0], $BorderWidth, $ln, $TextAlign, $BackStyle);
                                 }
                                 /*$formattedValue         = wordwrap($formattedValue, iif(is_numeric($ReportTag) == false,10,$ReportTag), "<br />"); 
                                 									$formattedValue         = nl2br($formattedValue);
                                 
                                 									$lines                  = substr_count($formattedValue, "<br />")+1;
                                 									$defaultHeight          = $Height;
                                 									//$Height                 = $Height * iif($lines == 0, 1, $lines);
                                 									if($this->growBy < $Height - $defaultHeight){
                                 										$this->growBy       = $Height - $defaultHeight;
                                 									}
                                     								$this->SetFont($Fontname,$Fontweight,$Fontsize);
                                     								$this->SetXY($Left, $Top);
                                 
                                     								$this->Cell($Width,$Height,$this->SetStringByWidth($formattedValue,$Width-0.1),$BorderWidth,$ln,$TextAlign,$BackStyle);*/
                             } else {
                                 $Caption = $formattedValue;
                                 $output = $this->parse($Caption);
                                 //tofile("Test Caption: ".$Caption);
                                 $this->SetFont($Fontname, $Fontweight, $Fontsize);
                                 $this->SetXY($Left, $Top);
                                 if ($BackColor == '' || $BackColor == strtolower('#FFFFFF') || $BackColor == strtolower('FFFFFF')) {
                                     $BackStyle = 0;
                                 } else {
                                     $BackStyle = 1;
                                 }
                                 if ($output[0]['innerhtml'] == null) {
                                     //tofile($this->GetStringWidth($Caption)." ".$Width." ".$Caption);
                                     $this->Cell($Width, $Height, $this->SetStringByWidth($Caption, $Width - 0.1), $BorderWidth, $ln, $TextAlign, $BackStyle);
                                 } else {
                                     $this->SetHTMLAttributes($Width, $Height, $output, $BorderWidth, $ln, $TextAlign, $BackColor, $BackStyle, $Left, $Top);
                                 }
                                 //tofile($BorderColor[0]." ".$BorderColor[1]." ".$BorderColor[2]);
                                 //tofile("Border Width: ".$BorderWidth);
                                 $s = $s . "      <div class='{$Name}' style='position:absolute;top:{$Top};height:{$Height}'>{$formattedValue}</div>\n";
                             }
                         }
                     }
                 }
             }
         }
     }
     return $s;
 }
 function __construct($theFormID, $theRecordID, $clone, $delete, $runActivity, $dir, $ses)
 {
     $this->startTime = time();
     $this->customDirectory = $dir;
     $this->session = $ses;
     $this->formsessionID = uniqid('1');
     $this->formID = $theFormID;
     //---Primary Key of sysform Table
     $this->form = formFields($theFormID);
     $this->recordID = $theRecordID;
     //---ID of displayed record (-1 means a new record)
     if ($_GET['r'] == '') {
         //-----no 'r' passed means it hasn't been called from a lookup
         $this->holdingValues = 0;
         nuRunQuery("DELETE FROM zzsys_small_form_value WHERE sfv_form_record = '{$this->formID}{$this->recordID}{$this->session}'");
     } else {
         $this->holdingValues = 1;
     }
     //		$T                       = nuRunQuery("SELECT COUNT(*) FROM zzsys_small_form_value WHERE sfv_form_record = '$theFormID$theRecordID$ses' GROUP BY sfv_form_record");
     //		$R                       = db_fetch_row($T);
     //		$this->holdingValues     = iif($R[0]=='',0,1);
     //----------allow for custom code----------------------------------------------
     if ($this->form->sfo_custom_code_run_before_open != '') {
         eval($this->form->sfo_custom_code_run_before_open);
     }
     //-----------custom code end---------------------------------------------------
     $this->cloning = $clone;
     //---Whether this will be a new record cloned from $formID's record
     $this->delete = $delete;
     $this->setup = nuSetup();
     $formID = $this->form->zzsys_form_id;
     $formTableName = $this->form->sfo_table;
     $formPrimaryKey = $this->form->sfo_primary_key;
     $T = nuRunQuery("SELECT * FROM {$formTableName} WHERE {$formPrimaryKey} = '{$this->recordID}'");
     $this->recordValues = db_fetch_array($T);
     $this->runActivity = $runActivity;
     $this->defaultJSfunctions();
     $this->createActionButtonsHTML();
 }
 public function buildControls($sectionNumber, $canGrow, $record)
 {
     $s = '';
     $setup = nuSetup();
     $dq = '"';
     $sortedControls = $this->sortSectionControlsByTopPositionOrder($sectionNumber, $this->report->Controls);
     for ($j = 0; $j < count($sortedControls); $j++) {
         $pSection = $sortedControls[$j]["Section"];
         $pName = $sortedControls[$j]["Name"];
         $pControlSource = $sortedControls[$j]["Source"];
         $i = $this->getDisplayControlIndex($pSection, $pName, $pControlSource);
         if ($this->report->Controls[$i]->Section == $sectionNumber) {
             $Name = $this->report->Controls[$i]->Name;
             $Source = $this->report->Controls[$i]->ControlSource;
             $ControlType = $this->report->Controls[$i]->ControlType;
             $Top = $this->toScale($this->report->Controls[$i]->Top);
             $Width = $this->toScale($this->report->Controls[$i]->Width);
             $Height = $this->toScale($this->report->Controls[$i]->Height);
             $Left = $this->toScale($this->report->Controls[$i]->Left);
             $Section = $this->report->Controls[$i]->Section;
             $Fontname = $this->report->Controls[$i]->FontName;
             $Fontsize = $this->report->Controls[$i]->FontSize;
             $Format = $this->report->Controls[$i]->Format;
             $Decimal = $this->report->Controls[$i]->DecimalPlaces;
             $IsHyperlink = $this->report->Controls[$i]->IsHyperlink;
             $ReportTag = $this->report->Controls[$i]->Tag;
             $Report = $this->report->Controls[$i]->Report;
             $Parameters = $this->report->Controls[$i]->Parameters;
             $LikeClause = $this->report->Controls[$i]->SmartTags;
             $LikeClause = str_replace("\"", "", $LikeClause);
             //image
             if ($this->sectionGrow == 1 && $sectionNumber != 0) {
                 $Top = $Top + $this->sectionGrowStack;
             }
             //========================================================================================
             if ($this->controlType($this->report->Controls[$i]->ControlType) == 'page break') {
                 $this->justDidPageBreak = true;
                 $this->hasExplicitPageBreak = true;
             }
             //========================================================================================
             if ($this->controlType($this->report->Controls[$i]->ControlType) == 'graph') {
                 $thetag = $this->report->Controls[$i]->ControlSource;
                 $thename = $this->report->Controls[$i]->Graph;
                 $thedir = $_GET['dir'];
                 for ($a = 0; $a < count($this->fields); $a++) {
                     //-----replace any strings, with hashes around them, in the querystring that match
                     //-----fieldnames in the table
                     //-----with values from the table
                     //-----e.g. id=#ID# could become id=007
                     $thetag = str_replace('#' . $this->fields[$a] . '#', $record[$this->fields[$a]], $thetag);
                 }
                 $addSession = '&ses=' . $_GET['ses'];
                 $s = $s . "   <div  style='position:absolute;left:{$Left};top:{$Top};height:{$Height}'>\n";
                 $s = $s . "      <img src='graph_report.php?dir={$thedir}{$addSession}&activityID={$this->reportID}&graph_name={$thename}&{$thetag}'>\n";
                 $s = $s . "   </div>\n";
             }
             //========================================================================================
             if ($this->controlType($this->report->Controls[$i]->ControlType) == 'image') {
                 $thetag = $this->report->Controls[$i]->ControlSource;
                 $imageCode = $this->report->Controls[$i]->Graph;
                 //-- the code (sim_code in zzsys_image)
                 $thedir = $_GET['dir'];
                 for ($a = 0; $a < count($this->fields); $a++) {
                     //-----replace any strings, with hashes around them, in the querystring that match
                     //-----fieldnames in the table
                     //-----with values from the table
                     //-----e.g. id=#ID# could become id=007
                     $thetag = str_replace('#' . $this->fields[$a] . '#', $record[$this->fields[$a]], $thetag);
                 }
                 $imageT = nuRunQuery("SELECT zzsys_image_id FROM zzsys_image WHERE sim_code = '{$imageCode}'");
                 $imageR = db_fetch_row($imageT);
                 $s = $s . "   <div  style='position:absolute;left:{$Left};top:{$Top};height:{$Height}'>\n";
                 $s = $s . "      <img src='formimage.php?dir={$thedir}&iid={$imageR['0']}&{$thetag}'>\n";
                 $s = $s . "   </div>\n";
             }
             //========================================================================================
             if ($this->controlType($this->report->Controls[$i]->ControlType) == 'label') {
                 if ($Source == '=Date()' || $Source == '=Now()') {
                     if ($Format == '' || $Format == '20' || $Format == 'Long Date') {
                         $formattedValue = date('d-M-Y H:i');
                     } else {
                         $formattedValue = date($this->accessDateFormatToPHPDateFormat($Format));
                     }
                     //$Caption = $formattedValue;
                     $s = $s . "      <div class='{$Name}' style='position:absolute;top:{$Top};height:{$Height}'>{$formattedValue}</div>\n";
                 } else {
                     if ($Source == '="Page " & [Page] & " of " & [Pages]') {
                         $formattedValue = "Page #thePageNumber# of #totalNumberOfPages#";
                         $s = $s . "      <div class='{$Name}' style='position:absolute;top:{$Top};height:{$Height}'>{$formattedValue}</div>\n";
                         //echo $s."<br>";
                     } else {
                         $s = $s . "      <div class='{$Name}' style='position:absolute;top:{$Top};height:{$Height}'>" . $this->report->Controls[$i]->Caption . "</div>\n";
                     }
                 }
             }
             //========================================================================================
             if ($this->controlType($this->report->Controls[$i]->ControlType) == 'text area') {
                 //--Field
                 $displayValue = $record[$this->report->Controls[$i]->ControlSource];
                 //Sum
                 $theSource = $this->report->Controls[$i]->ControlSource;
                 $builtInFunction = false;
                 //============numbering pages (using a label)=======================================
                 //---- Page #thePageNumber# of #totalNumberOfPages#      eg. Page 6 of 12
                 //==================================================================================
                 if ($theSource == '="Page " & [Page] & " of " & [Pages]' || $theSource == 'Page #thePageNumber# of #totalNumberOfPages#') {
                     $displayValue = "Page #thePageNumber# of #totalNumberOfPages#";
                 }
                 if (strtoupper($theSource) == '=NOW()' || strtoupper($theSource) == '=DATE()') {
                     if ($Format == '' || $Format == '20' || $Format == 'Long Date') {
                         $displayValue = date('d-M-Y H:i');
                     } else {
                         $displayValue = date($this->accessDateFormatToPHPDateFormat($Format));
                     }
                 }
                 if (strtoupper(substr($theSource, 0, 4)) == 'SUM(') {
                     //--sum for header or footer sections
                     $sumField = substr($theSource, 4, -1);
                     $selectFields = 'SUM(' . trim($sumField) . '_Sum) as answer ';
                     $groupSQL = $this->getGroupBySql($this->sectionLevel($sectionNumber), $selectFields, $record);
                     $t1 = nuRunQuery($groupSQL);
                     $r1 = mysql_fetch_row($t1);
                     $displayValue = $r1[0];
                 }
                 if (strtoupper(substr($theSource, 0, 6)) == '=SUM([') {
                     //--if the sum function
                     $sumField = substr($theSource, 6, -2);
                     $selectFields = 'SUM(' . trim($sumField) . '_Sum) as answer ';
                     $groupSQL = $this->getGroupBySql($this->sectionLevel($sectionNumber), $selectFields, $record);
                     $t1 = nuRunQuery($groupSQL);
                     $r1 = mysql_fetch_row($t1);
                     $displayValue = $r1[0];
                 }
                 if (strtoupper(substr($theSource, 0, 8)) == 'PERCENT(') {
                     //--percent of 2 sums
                     $sumField = substr($theSource, 8, -1);
                     $sumFields = array();
                     $sumFields = explode(',', $sumField);
                     $selectFields = 'SUM(' . trim($sumFields[0]) . '_Sum) as answer1, SUM(' . trim($sumFields[1]) . '_Sum) as answer2 ';
                     $groupSQL = $this->getGroupBySql($this->sectionLevel($sectionNumber), $selectFields, $record);
                     $t1 = nuRunQuery($groupSQL);
                     $r1 = mysql_fetch_row($t1);
                     if ($r1[1] == 0) {
                         $displayValue = 0;
                         //--because nothing can be divided by zero
                     } else {
                         $displayValue = $r1[0] / $r1[1] * 100;
                     }
                 }
                 $displayValue = formatTextValue($displayValue, $Format);
                 if ($this->report->Controls[$i]->CanGrow == 'True' and $canGrow) {
                     $oldValue = $displayValue;
                     $break_variants = array("<br>", "<BR>", "<br />", "<BR />", "<br/>", "<BR/>");
                     $displayValue = str_replace($break_variants, "\n", $displayValue);
                     if ($this->report->nuBuilder == '1') {
                         $textWidth = str_replace('px', '', $this->report->Controls[$i]->Width) / ($this->report->Controls[$i]->FontSize / 2);
                         $displayValue = wordwrap($displayValue, $textWidth, "<br />");
                     } else {
                         $displayValue = wordwrap($displayValue, iif($ReportTag == '', 10, $ReportTag), "<br />");
                     }
                     $displayValue = nl2br($displayValue);
                     $lines = substr_count($displayValue, "<br />") + 1;
                     $linesArray = explode("<br />", $displayValue);
                     if ($lines <= 5) {
                         $Height = $Fontsize * 1.2;
                     } else {
                         if ($lines > 5 && $lines <= 15) {
                             $Height = $Fontsize * 1.3;
                         } else {
                             if ($lines > 15 && $lines <= 25) {
                                 $Height = $Fontsize * 1.4;
                             } else {
                                 if ($lines > 25) {
                                     $Height = $Fontsize * 1.5;
                                 }
                             }
                         }
                     }
                     $defaultHeight = $Height;
                     $Height = $Height * $lines;
                     $this->growByHeight = $this->growByHeight + $Height;
                     if ($this->growBy < $Height - $defaultHeight) {
                         $this->growBy = $Height - $defaultHeight;
                         if ($sectionNumber != 0) {
                             $sectionHeight = $this->toScale($this->report->Sections[$sectionNumber]->Height);
                             $growByHeight = $this->growBy;
                             $growString = "";
                             $pos = count($linesArray) - 1;
                             if ($this->growAddHeight == 0) {
                                 $this->growAddHeight = $this->thisPageLength;
                             }
                             if ($this->growAddHeight + $growByHeight > $this->useablePageLength) {
                                 for ($k = count($linesArray) - 1; $k >= 0; $k--) {
                                     $Height = $defaultHeight * $k;
                                     $this->growBy = $Height - $defaultHeight;
                                     $growByHeight = $this->growBy + $sectionHeight;
                                     if ($this->growAddHeight + $growByHeight < $this->useablePageLength) {
                                         $pos = $k;
                                         $this->attachGroupHeaderFieldGrowByText($this->report->Controls[$i]);
                                         $this->growBySectionNumber = $Section;
                                         break;
                                     }
                                 }
                                 for ($k = 0; $k < $pos; $k++) {
                                     $growString = $growString . $linesArray[$k] . "<br />";
                                 }
                                 $index = 0;
                                 for ($k = $pos; $k < count($linesArray); $k++) {
                                     $this->nextPageGrowText[$index] = $linesArray[$k];
                                     $index++;
                                 }
                                 $displayValue = $growString;
                             } else {
                                 $this->growAddHeight = $this->growAddHeight + $growByHeight;
                             }
                             $this->growByHeight = $Height;
                             $this->sectionGrowStack = $growByHeight;
                             $this->sectionGrow = 1;
                         }
                     }
                     if ($sectionNumber != 0) {
                         $this->growByTotal = $this->growByTotal + $Height;
                     }
                     $s = $s . "      <div class='{$Name}' style='position:absolute;top:{$Top};height:{$this->growByHeight}'>{$displayValue}</div>\n";
                 } else {
                     //------create drilldown-------------------
                     if ($Report != '') {
                         $reportlink = $Report;
                         $sessionlink = $_GET['ses'];
                         $formsessionlink = $_GET['form_ses'];
                         $dirlink = $_GET['dir'];
                         $displayValue = "<a class='{$Name}' href='runreport.php?x=1&dir={$dir}&ses={$sessionlink}&form_ses={$formsessionlink}&r={$Report}'>{$displayValue}</a>";
                     }
                     //-----------------------------------------
                     $s = $s . "      <div class='{$Name}' style='position:absolute;top:{$Top};height:{$Height}'>{$displayValue}</div>\n";
                 }
             }
         }
     }
     return $s;
 }
function build_report_object()
{
    $GLOBALS['time'] = array();
    $ses = $_GET['ses'];
    $form_ses = $_GET['form_ses'];
    $report = $_GET['r'];
    $dir = $_GET['dir'];
    $get_array = array();
    $emailer = $_GET['emailer'];
    while (list($key, $value) = each($_GET)) {
        $get_array["#{$key}#"] = $value;
    }
    include_once "../{$dir}/database.php";
    include_once 'common.php';
    //--------security check-------------------------------
    if ($emailer != '1') {
        if (activityPasswordNeeded($report)) {
            $session = nuSession($ses, false);
            if ($session->foundOK == '') {
                print 'you have been logged out..';
                return;
            }
        }
    }
    //---------------------------------------------------
    $id = uniqid('1');
    $thedate = date('Y-m-d H:i:s');
    $dq = '"';
    $setup = nuSetup();
    $T = nuRunQuery("SELECT * FROM zzsys_activity WHERE sat_all_code = '{$report}'");
    $activity = db_fetch_object($T);
    //----------allow for custom code----------------------------------------------
    //--already done now..	eval($activity->sat_report_display_code);   //---(Reporting Class)
    $displayClass = new Reporting();
    $REPORT = new REPORT($displayClass, $dir, $ses);
    if ($activity->zzsys_activity_id == '') {
        print 'No Such Report...';
        return;
    }
    $viewer = $session->sss_zzsys_user_id;
    $s = "INSERT INTO zzsys_report_log (zzsys_report_log_id, ";
    $s .= "srl_zzsys_activity_id, srl_date ,srl_viewer) ";
    $s .= "VALUES ('{$id}', '{$report}', '{$thedate}', '{$viewer}')";
    nuRunQuery($s);
    $s = "SELECT count(*), MAX(sva_expiry_date) FROM zzsys_variable ";
    $s .= "WHERE sva_id = '{$form_ses}' ";
    $s .= "GROUP BY sva_expiry_date";
    $t1 = nuRunQuery($s);
    $r1 = db_fetch_row($t1);
    $numberOfVariables = $r1[0];
    $expiryDate = $r1[1];
    if ($numberOfVariables == 0) {
        //---must have at least 1 variable
        print 'Report has Expired...';
        return;
    }
    $s = "DELETE FROM zzsys_variable ";
    $s .= "WHERE sva_id = '{$form_ses}' ";
    $s .= "AND sva_name = 'ReportTitle'";
    nuRunQuery($s);
    setnuVariable($form_ses, $expiryDate, 'ReportTitle', $activity->sat_all_description);
    $TT = TT();
    //--Temp table name
    //----------create an array of hash variables that can be used in any "hashString"
    $sesVariables = recordToHashArray('zzsys_session', 'zzsys_session_id', $ses);
    //--session values (access level and user etc. )
    $sesVariables['#dataTable#'] = $TT;
    $sesVariables['#TT#'] = $TT;
    $GLOBALS['TT'] = $TT;
    $dataTable = $TT;
    $sysVariables = sysVariablesToHashArray($form_ses);
    //--values in sysVariables from the calling lookup page
    $arrayOfHashVariables = joinHashArrays($sysVariables, $sesVariables);
    //--join the arrays together
    $formValue = array();
    while (list($key, $value) = each($sesVariables)) {
        $formValue[substr($key, 1, -1)] = $value;
    }
    //-------------------------------build $TT with PHP----------------------------------------
    $v = getSelectionFormVariables($form_ses);
    $hashV = arrayToHashArray($v);
    $arrayOfHashVariables = joinHashArrays($arrayOfHashVariables, $hashV);
    //--join the arrays together
    $REPORT->tablesUsed = getSelectionFormTempTableNames($form_ses, $v);
    //--temp tables to delete when finished
    $formValue = $v;
    $nuHashVariables = $arrayOfHashVariables;
    //--added by sc 23-07-2009
    eval(replaceHashVariablesWithValues($arrayOfHashVariables, $activity->sat_report_data_code));
    $REPORT->no_data = addVariablesToTT($TT, $v);
    nuRunQuery("ALTER TABLE `{$TT}` ADD `nu__id` INT NOT NULL AUTO_INCREMENT PRIMARY KEY FIRST");
    $REPORT->nuloopThroughRecords($TT);
}
 function __construct($theFormID, $thePageNumber, $theOrderBy, $isDescending, $theSearchString, $subformPrefix, $objectID, $recordID)
 {
     $this->TT = TT();
     //---temp table name
     $this->theFormID = $theFormID;
     $this->objectID = $objectID;
     $this->recordID = $recordID;
     $this->rowPrefix = $subformPrefix;
     $this->PageNo = $thePageNumber;
     $this->orderBy = $theOrderBy;
     $this->isDescending = $isDescending;
     $this->form = formFields($theFormID);
     if ($objectID == '') {
         $this->callingForm = formFields($theFormID);
     } else {
         $this->isLookup = true;
         $t = nuRunQuery("SELECT sob_lookup_zzsysform_id FROM zzsys_object WHERE zzsys_object_id = '{$objectID}'");
         $r = db_fetch_row($t);
         $this->callingForm = formFields($r[0]);
         while (list($key, $va) = each($_POST)) {
             $uniq = uniqid('1');
             $key = str_replace("'", "\\'", $key);
             nuRunQuery("INSERT INTO zzsys_small_form_value (zzsys_small_form_value_id, sfv_form_record, sfv_name, sfv_value) VALUES ('{$uniq}', '{$theFormID}{$this->recordID}{$ses}" . $_GET['ses'] . "', '{$key}', '{$va}')");
         }
     }
     $this->searchString = $theSearchString;
     $this->pageLength = 10;
     $this->rowHeight = 20;
     $this->startTime = time();
     $this->setup = nuSetup();
     $this->getColumnInfo($this->callingForm->zzsys_form_id);
     $this->defaultJSfunctions();
     if ($this->callingForm->sfo_sql_run_before_display != '') {
         $beforeDisplaySQL = replaceVariablesInString($this->TT, $this->callingForm->sfo_sql_run_before_display, '');
         $sqlStatements = array();
         $sqlStatements = explode(';', $beforeDisplaySQL);
         //---create a tempfile to be used later as object is being built.
         for ($i = 0; $i < count($sqlStatements); $i++) {
             if (trim($sqlStatements[$i]) != '') {
                 nuRunQuery($sqlStatements[$i]);
             }
         }
     }
     $this->SQL = new sqlString(replaceVariablesInString($this->TT, $this->callingForm->sfo_sql, ''));
     $this->buildWhereClause($theSearchString);
     $this->SQL->setWhere($this->pageWhereClause);
     $this->SQL->setOrderBy($this->buildOrderBy());
     $this->pageBody = $this->buildBody();
     $this->pageHeader = $this->buildHeader();
 }
 public function buildControls($sectionNumber, $canGrow, $record)
 {
     $s = '';
     $setup = nuSetup();
     $dq = '"';
     for ($i = 0; $i < count($this->report->Controls); $i++) {
         if ($this->report->Controls[$i]->Section == $sectionNumber) {
             $Name = $this->report->Controls[$i]->Name;
             $Source = $this->report->Controls[$i]->ControlSource;
             $Controltype = $this->report->Controls[$i]->Controltype;
             $Top = $this->toScale($this->report->Controls[$i]->Top);
             $Width = $this->toScale($this->report->Controls[$i]->Width);
             $Height = $this->toScale($this->report->Controls[$i]->Height);
             $Left = $this->toScale($this->report->Controls[$i]->Left);
             $Section = $this->report->Controls[$i]->Section;
             $Fontname = $this->report->Controls[$i]->FontName;
             $Fontsize = $this->report->Controls[$i]->FontSize;
             $Format = $this->report->Controls[$i]->Format;
             $Decimal = $this->report->Controls[$i]->DecimalPlaces;
             $IsHyperlink = $this->report->Controls[$i]->IsHyperlink;
             $ReportTag = $this->report->Controls[$i]->Tag;
             $LikeClause = $this->report->Controls[$i]->SmartTags;
             $LikeClause = str_replace("\"", "", $LikeClause);
             //image
             //========================================================================================
             if ($this->controlType($this->report->Controls[$i]->ControlType) == 'page break') {
                 $GLOBALS['pageBreak'] = true;
                 $s = "</div><div style='height:0'></div><div>";
             }
             //========================================================================================
             if ($this->controlType($this->report->Controls[$i]->ControlType) == 'graph') {
                 $thetag = $this->report->Controls[$i]->ControlSource;
                 $thename = $this->report->Controls[$i]->Graph;
                 $thedir = $_GET['dir'];
                 for ($a = 0; $a < count($this->fields); $a++) {
                     //-----replace any strings, with hashes around them, in the querystring that match
                     //-----fieldnames in the table
                     //-----with values from the table
                     //-----e.g. id=#ID# could become id=007
                     $thetag = str_replace('#' . $this->fields[$a] . '#', $record[$this->fields[$a]], $thetag);
                 }
                 $s = $s . "   <div  style='position:absolute;left:{$Left};top:{$Top};height:{$Height}'>\n";
                 $s = $s . "      <img src='graph_report.php?dir={$thedir}&activityID={$this->reportID}&graph_name={$thename}&{$thetag}'>\n";
                 $s = $s . "   </div>\n";
             }
             //========================================================================================
             if ($this->controlType($this->report->Controls[$i]->ControlType) == 'label') {
                 $s = $s . "      <div class='{$Name}' style='position:absolute;top:{$Top};height:{$Height}'>" . $this->report->Controls[$i]->Caption . "</div>\n";
             }
             //========================================================================================
             if ($this->controlType($this->report->Controls[$i]->ControlType) == 'text area') {
                 $formattedValue = $record[$this->report->Controls[$i]->ControlSource];
                 //Sum
                 $theSource = $this->report->Controls[$i]->ControlSource;
                 if (substr($theSource, 0, 6) == '=Sum([' or strtoupper(substr($theSource, 0, 10)) == '=PERCENT([') {
                     $sumIt = substr($theSource, 0, 6) == '=Sum([';
                     if ($sumIt) {
                         //--if the sum function
                         $SumOn = str_replace('=Sum([', '', $theSource);
                         $SumOn = str_replace('])', '', $SumOn);
                         $selectFields = 'sum(' . $SumOn . '_Sum)';
                     } else {
                         //--if the Percent function
                         $SumOn = substr($theSource, 10);
                         $SumOn = str_replace(']', '', $SumOn);
                         //-- remove right square brackets
                         $SumOn = str_replace('[', '', $SumOn);
                         //-- remove left square brackets
                         $SumOn = str_replace(')', '', $SumOn);
                         //-- remove only right bracket
                         $SumOn = str_replace(' ', '', $SumOn);
                         //-- remove any spaces
                         $theFields = explode(',', $SumOn);
                         //-- split left and right field
                         $selectFields = 'sum(' . $theFields[0] . '_Sum) as divideIt, sum(' . $theFields[1] . '_Sum) as BYY ';
                     }
                     $SectionLevel = $this->sectionLevel($sectionNumber);
                     for ($ii = 0; $ii <= $SectionLevel; $ii++) {
                         if ($ii == 0) {
                             if ($this->report->Groups[$ii]->Field != '') {
                                 $whereClause = $this->report->Groups[$ii]->Field . " = {$dq}" . $record[$this->report->Groups[$ii]->Field] . "{$dq}";
                             }
                         } else {
                             if ($this->report->Groups[$ii]->Field != '') {
                                 $whereClause = $whereClause . ' AND ' . $this->report->Groups[$ii]->Field . " = {$dq}" . $record[$this->report->Groups[$ii]->Field] . "{$dq}";
                             }
                         }
                     }
                     $SumOn = trim($SumOn);
                     if (strlen($SectionLevel) == 0) {
                         $whereClause = "SELECT {$selectFields} FROM {$this->sumTT}";
                     } else {
                         $whereClause = "SELECT {$selectFields} FROM {$this->sumTT} WHERE {$whereClause}";
                     }
                     $t1 = nuRunQuery($whereClause);
                     $r1 = mysql_fetch_row($t1);
                     $formattedValue = $r1[0];
                     if (!$sumIt) {
                         //---using the 'PERCENT' function
                         if ($r1[1] == 0) {
                             $formattedValue = 0;
                             //--because nothing can be divided by zero
                         } else {
                             $formattedValue = $r1[0] / $r1[1] * 100;
                         }
                     }
                     if ($Format == 'Fixed') {
                         if ($r1[0] != '') {
                             $formattedValue = number_format($r1[0], $Decimal);
                         }
                     }
                     //format of the result of the sum
                     if ($Format == 'Currency') {
                         if ($r1[0] != '') {
                             $formattedValue = "\$" . number_format($r1[0], 2);
                             $formattedValue = str_replace('$-', '-$', $formattedValue);
                         }
                     }
                     $s = $s . "      <div class='{$Name}' style='position:absolute;top:{$Top};height:{$Height}'>{$formattedValue}</div>\n";
                 } else {
                     //page display
                     if ($Source == '="Page " & [Page] & " of  " & [Pages]') {
                         $s = $s . "   <div class='{$Name}'>Page #thePageNumber# of #totalNumberOfPages#</div>\n";
                     } else {
                         //date display
                         if ($Source == '=Date()' or $Source == '=Now()') {
                             $formattedValue = date($this->accessDateFormatToPHPDateFormat($Format));
                             $s = $s . "      <div class='{$Name}' style='position:absolute;top:{$Top};height:{$Height}'>{$formattedValue}</div>\n";
                         } else {
                             //format number
                             if ($Format == 'Fixed') {
                                 if ($record[$this->report->Controls[$i]->ControlSource] != '') {
                                     $formattedValue = number_format($record[$this->report->Controls[$i]->ControlSource], $Decimal);
                                 }
                             }
                             //currency number
                             if ($Format == 'Currency') {
                                 $formattedValue = "\$" . number_format($record[$this->report->Controls[$i]->ControlSource], 2);
                                 $formattedValue = str_replace('$-', '-$', $formattedValue);
                             }
                             //date format (no todate() and now())
                             if (substr($Format, 0, 2) == 'dd' or substr($Format, 0, 2) == 'mm' or substr($Format, 0, 2) == 'yy' or substr($Format, 0, 2) == 'hh' or substr($Format, 0, 2) == 'nn' or substr($Format, 0, 2) == 'ss') {
                                 //for sql format case yyyy-mm-dd
                                 if (substr($formattedValue, 4, 1) == '-' and substr($formattedValue, 7, 1) == '-') {
                                     $timestamp = mktime(0, 0, 0, substr($formattedValue, 5, 2), substr($formattedValue, 8, 2), substr($formattedValue, 0, 4));
                                     $formattedValue = date($this->accessDateFormatToPHPDateFormat($Format), $timestamp);
                                 }
                             }
                             if ($this->report->Controls[$i]->CanGrow == 'True' and $canGrow) {
                                 $oldValue = $formattedValue;
                                 if ($this->report->nuBuilder == '1') {
                                     $textWidth = str_replace('px', '', $this->report->Controls[$i]->Width) / ($this->report->Controls[$i]->FontSize / 2);
                                     $formattedValue = wordwrap($formattedValue, $textWidth, "<br />");
                                 } else {
                                     $formattedValue = wordwrap($formattedValue, iif($ReportTag == '', 10, $ReportTag), "<br />");
                                 }
                                 $formattedValue = nl2br($formattedValue);
                                 $lines = substr_count($formattedValue, "<br />") + 1;
                                 $defaultHeight = $Height;
                                 $Height = $Height * $lines;
                                 if ($this->growBy < $Height - $defaultHeight) {
                                     $this->growBy = $Height - $defaultHeight;
                                 }
                                 $s = $s . "      <div class='{$Name}' style='position:absolute;top:{$Top};height:{$Height}'>{$formattedValue}</div>\n";
                             } else {
                                 $s = $s . "      <div class='{$Name}' style='position:absolute;top:{$Top};height:{$Height}'>{$formattedValue}</div>\n";
                             }
                         }
                     }
                 }
             }
         }
     }
     return $s;
 }
 function loadAfterConstruct($theFormID, $thePageNumber, $theOrderBy, $isDescending, $theSearchString, $subformPrefix, $dir, $ses, $form_ses, $zzsys_user_id)
 {
     $this->TT = TT();
     //---temp table name
     $this->rowPrefix = $subformPrefix;
     $this->customDirectory = $dir;
     $this->session = $ses;
     $this->form_session = $form_ses;
     $this->PageNo = $thePageNumber;
     $this->orderBy = $theOrderBy;
     $this->isDescending = $isDescending;
     $this->oldFormID = $theFormID;
     $this->theFormID = $this->getFormID($theFormID);
     $this->searchString = $theSearchString;
     $this->pageLength = 27;
     $this->rowHeight = 20;
     $this->startTime = time();
     $this->setup = nuSetup();
     $this->getColumnInfo($this->theFormID);
     $this->form = formFields($this->theFormID);
     $this->defaultJSfunctions();
     $this->zzsys_user_id = $zzsys_user_id;
     //----------create an array of hash variables that can be used in any "hashString"
     $sesVariables = recordToHashArray('zzsys_session', 'zzsys_session_id', $ses);
     //--session values (access level and user etc. )
     $sesVariables['#TT#'] = $this->TT;
     $sesVariables['#browseTable#'] = $this->TT;
     $sesVariables['#formSessionID#'] = $form_ses;
     $sysVariables = sysVariablesToHashArray($form_ses);
     //--values in sysVariables from the calling lookup page
     $this->arrayOfHashVariables = joinHashArrays($sysVariables, $sesVariables);
     //--join the arrays together
     $nuHashVariables = $this->arrayOfHashVariables;
     //--added by sc 23-07-2009
     //----------allow for custom code----------------------------------------------
     $globalValue = getglobalValue($this->session);
     $browseTable = $this->TT;
     eval(replaceHashVariablesWithValues($this->arrayOfHashVariables, $this->form->sfo_custom_code_run_before_browse));
     $this->old_sql_string = $this->form->sfo_sql;
     $this->new_sql_string = replaceHashVariablesWithValues($this->arrayOfHashVariables, $this->form->sfo_sql);
     $s = "\n/*\n old : {$this->old_sql_string} \n*/\n";
     $s = $s . "\n/*\n new : {$this->new_sql_string} \n*/\n";
     $this->appendJSfuntion($s);
     $this->SQL = new sqlString($this->new_sql_string);
     $this->buildWhereClause($theSearchString);
     $this->SQL->setWhere($this->pageWhereClause);
     $this->SQL->setOrderBy($this->buildOrderBy());
     $this->pageBody = $this->buildBody();
     $this->pageHeader = $this->buildHeader();
 }
 public function buildControls($sectionNumber, $canGrow, $record)
 {
     $s = '';
     $setup = nuSetup();
     $dq = '"';
     for ($i = 0; $i < count($this->report->Controls); $i++) {
         if ($this->report->Controls[$i]->Section == $sectionNumber) {
             $Name = $this->report->Controls[$i]->Name;
             $Source = $this->report->Controls[$i]->ControlSource;
             $Controltype = $this->report->Controls[$i]->Controltype;
             $Top = $this->toScale($this->report->Controls[$i]->Top);
             $Width = $this->toScale($this->report->Controls[$i]->Width);
             $Height = $this->toScale($this->report->Controls[$i]->Height);
             $Left = $this->toScale($this->report->Controls[$i]->Left);
             $Section = $this->report->Controls[$i]->Section;
             $Fontname = $this->report->Controls[$i]->FontName;
             $Fontsize = $this->report->Controls[$i]->FontSize - 1;
             $Fontweight = $this->report->Controls[$i]->FontWeight;
             $Fontname = iif($Fontname == null, 'Arial', $Fontname);
             $Fontname = iif($Fontname != 'Arial', 'Arial', $Fontname);
             $Fontweight = iif($Fontweight == 'bold', 'B', '');
             $Caption = $this->report->Controls[$i]->Caption;
             $ln = iif($Caption == '', 2, 0);
             $TextAlign = $this->report->Controls[$i]->TextAlign;
             $TextAlign = $this->GetTextAlign($TextAlign);
             $ForeColor = $this->report->Controls[$i]->ForeColor;
             $BackColor = $this->report->Controls[$i]->BackColor;
             $BackStyle = $this->report->Controls[$i]->BackStyle;
             $BorderWidth = $this->report->Controls[$i]->BorderWidth;
             $BorderColor = $this->report->Controls[$i]->BorderColor;
             $Format = $this->report->Controls[$i]->Format;
             $Decimal = $this->report->Controls[$i]->DecimalPlaces;
             $IsHyperlink = $this->report->Controls[$i]->IsHyperlink;
             $ReportTag = $this->report->Controls[$i]->Tag;
             $LikeClause = $this->report->Controls[$i]->SmartTags;
             $LikeClause = str_replace("\"", "", $LikeClause);
             $ForeColor = $this->html2rgb('#' . $ForeColor);
             $BackColor = $this->html2rgb('#' . $BackColor);
             $BorderColor = $this->html2rgb('#' . $BorderColor);
             $this->SetTextColor($ForeColor[0], $ForeColor[1], $ForeColor[2]);
             $this->SetFillColor($BackColor[0], $BackColor[1], $BackColor[2]);
             $this->SetDrawColor($BorderColor[0], $BorderColor[1], $BorderColor[2]);
             if ($BorderWidth > 0) {
                 $this->SetLineWidth($BorderWidth / 100);
                 $BorderWidth = 1;
             }
             //$Top = (($this->stackheight + $Top)/100) + 0.3;
             $Left = $Left / 100 + 0.2;
             //$Width = ($Width / 100) + 0.002;
             $Width = $Width / 100;
             $Height = $Height / 100;
             $Top = ($this->stackheight + $Top) / 100 + 0.2;
             //image
             //========================================================================================
             if ($this->controlType($this->report->Controls[$i]->ControlType) == 'page break') {
                 $s = '';
                 if ($this->pageFooter) {
                     $top = $this->totalLength;
                     $height = $this->useablePageLength - $this->thisPageLength - $this->toScale($this->report->Sections[$sectionNumber]->Height);
                     $this->setCurrentLength($height);
                     $s = $s . "</div><div style='top:{$Top};height:{$Height}'></div><div>";
                 }
                 $this->growBy = $Height;
                 return $s;
             }
             //========================================================================================
             if ($this->controlType($this->report->Controls[$i]->ControlType) == 'graph') {
                 $thetag = $this->report->Controls[$i]->Tag;
                 $thename = $this->report->Controls[$i]->Name;
                 $thedir = $_GET['dir'];
                 for ($a = 0; $a < count($this->fields); $a++) {
                     //-----replace any strings, with hashes around them, in the querystring that match
                     //-----fieldnames in the table
                     //-----with values from the table
                     //-----e.g. id=#ID# could become id=007
                     $thetag = str_replace('#' . $this->fields[$a] . '#', $record[$this->fields[$a]], $thetag);
                 }
                 $s = $s . "   <div  style='position:absolute;left:{$Left};top:{$Top};height:{$Height}'>\n";
                 $s = $s . "      <img src='graph_report.php?dir={$thedir}&activityID={$this->reportID}&graph_name={$thename}&{$thetag}'>\n";
                 $s = $s . "   </div>\n";
                 $logo = file_get_contents("http://www.nubuilder.com/productionnu2/graph_report.php?dir={$thedir}&activityID={$this->reportID}&graph_name={$thename}&{$thetag}");
                 $fp = fopen('temp' . $this->imagecount . '.png', 'w');
                 fwrite($fp, $logo);
                 fclose($fp);
                 $imageDimensions = getimagesize('temp' . $this->imagecount . '.png');
                 $imageWidth = $imageDimensions[0] * 0.01;
                 $imageHeight = $imageDimensions[1] * 0.01;
                 $this->Image('temp' . $this->imagecount . '.png', $Left, $Top, $imageWidth, $imageHeight);
                 unlink('temp' . $this->imagecount . '.png');
                 $this->imagecount++;
                 $this->Rect($Left, $Top, $imageWidth, $imageHeight, 'D');
                 //$this->SetXY($Left, $Top);
                 //$this->Cell($Width+0.5,$Height+0.5, "", 1);
                 //tofile("Graph Stack Height: ".$this->stackheight);
                 //tofile("Image $Top");
                 //$this->Image("graph_report.php?dir=$thedir&activityID=$this->reportID&graph_name=$thename&$thetag",$Left,$Top,$Width,$Height);
             }
             //========================================================================================
             if ($this->controlType($this->report->Controls[$i]->ControlType) == 'label') {
                 if ($this->report->Controls[$i]->Tag != '') {
                     $s = $s . "      <div class='{$Name}' style='position:absolute;top:{$Top};height:{$Height}'><img src='{$setup->seStartingDirectory}/reports/" . $this->report->Controls[$i]->Tag . ".jpg'></div>\n";
                     $this->SetXY($Left, $Top);
                     $this->Image($setup->seStartingDirectory . "/reports/" . $ReportClass->Controls[$i]->Tag . ".jpg", $Left, $Top, $Width, $Height);
                     if ($ReportClass->Controls[$i]->Caption != '') {
                         $this->SetFont($Fontname, $Fontweight, $Fontsize);
                         $this->SetXY($Left, $Top);
                         $this->Cell($Width, $Height, $Caption, $BorderWidth, $ln, $TextAlign);
                     }
                     continue;
                 }
                 $s = $s . "      <div class='{$Name}' style='position:absolute;top:{$Top};height:{$Height}'>" . $this->report->Controls[$i]->Caption . "</div>\n";
                 if (strlen($Caption) == 1 && $BorderWidth >= 1) {
                     $this->SetDrawColor($BorderColor[0], $BorderColor[1], $BorderColor[2]);
                     $this->SetFillColor($BorderColor[0], $BorderColor[1], $BorderColor[2]);
                     $BackStyle = 1;
                 }
                 //tofile("Show Header fields ".$Name." ".$Source." ".$Caption." ".$Fontname." P".$PageNumber." ".$Top." ".$OldTop);
                 $this->SetFont($Fontname, $Fontweight, $Fontsize);
                 $this->SetXY($Left, $Top);
                 $this->Cell($Width, $Height, $Caption, $BorderWidth, $ln, $TextAlign, $BackStyle);
                 //tofile("Caption: ".$Caption." Top: ".$Top." Stack Height: ".$this->stackheight);
                 //tofile("UsablePageLength: ".$this->useablePageLength." ThisPageLength: ".$this->thisPageLength." SectionHeight: ".$this->report->Sections[$sectionNumber]->Height);
             }
             //========================================================================================
             if ($this->controlType($this->report->Controls[$i]->ControlType) == 'text area') {
                 $formattedValue = $record[$this->report->Controls[$i]->ControlSource];
                 if ($this->report->Controls[$i]->Tag != '') {
                     $s = $s . "      <div class='{$Name}' style='position:absolute;top:{$Top};height:{$Height}'><img src='{$setup->seStartingDirectory}/reports/" . $this->report->Controls[$i]->Tag . ".jpg'></div>\n";
                 }
                 //Sum
                 $theSource = $this->report->Controls[$i]->ControlSource;
                 if (substr($theSource, 0, 6) == '=Sum([' or strtoupper(substr($theSource, 0, 10)) == '=PERCENT([') {
                     $sumIt = substr($theSource, 0, 6) == '=Sum([';
                     if ($sumIt) {
                         //--if the sum function
                         $SumOn = str_replace('=Sum([', '', $theSource);
                         $SumOn = str_replace('])', '', $SumOn);
                         $selectFields = 'sum(' . $SumOn . '_Sum)';
                     } else {
                         //--if the Percent function
                         $SumOn = substr($theSource, 10);
                         $SumOn = str_replace(']', '', $SumOn);
                         //-- remove right square brackets
                         $SumOn = str_replace('[', '', $SumOn);
                         //-- remove left square brackets
                         $SumOn = str_replace(')', '', $SumOn);
                         //-- remove only right bracket
                         $SumOn = str_replace(' ', '', $SumOn);
                         //-- remove any spaces
                         $theFields = explode(',', $SumOn);
                         //-- split left and right field
                         $selectFields = 'sum(' . $theFields[0] . '_Sum) as divideIt, sum(' . $theFields[1] . '_Sum) as BYY ';
                     }
                     $SectionLevel = $this->sectionLevel($sectionNumber);
                     for ($ii = 0; $ii <= $SectionLevel; $ii++) {
                         if ($ii == 0) {
                             if ($this->report->Groups[$ii]->Field != '') {
                                 $whereClause = $this->report->Groups[$ii]->Field . " = {$dq}" . $record[$this->report->Groups[$ii]->Field] . "{$dq}";
                             }
                         } else {
                             if ($this->report->Groups[$ii]->Field != '') {
                                 $whereClause = $whereClause . ' AND ' . $this->report->Groups[$ii]->Field . " = {$dq}" . $record[$this->report->Groups[$ii]->Field] . "{$dq}";
                             }
                         }
                     }
                     $SumOn = trim($SumOn);
                     if (strlen($SectionLevel) == 0) {
                         $whereClause = "SELECT {$selectFields} FROM {$this->sumTT}";
                     } else {
                         $whereClause = "SELECT {$selectFields} FROM {$this->sumTT} WHERE {$whereClause}";
                     }
                     $t1 = nuRunQuery($whereClause);
                     $r1 = mysql_fetch_row($t1);
                     $formattedValue = $r1[0];
                     if (!$sumIt) {
                         //---using the 'PERCENT' function
                         if ($r1[1] == 0) {
                             $formattedValue = 0;
                             //--because nothing can be divided by zero
                         } else {
                             $formattedValue = $r1[0] / $r1[1] * 100;
                         }
                     }
                     if ($Format == 'Fixed') {
                         if ($r1[0] != '') {
                             $formattedValue = number_format($r1[0], $Decimal);
                         }
                     }
                     //format of the result of the sum
                     if ($Format == 'Currency') {
                         if ($r1[0] != '') {
                             $formattedValue = "\$" . number_format($r1[0], 2);
                             $formattedValue = str_replace('$-', '-$', $formattedValue);
                         }
                     }
                     $s = $s . "      <div class='{$Name}' style='position:absolute;top:{$Top};height:{$Height}'>{$formattedValue}</div>\n";
                 } else {
                     //page display
                     if ($Source == '="Page " & [Page] & " of  " & [Pages]') {
                         $Caption = "Page " . $this->pageNumber . " of " . $GLOBALS['TotalPages'];
                         $this->SetFont($Fontname, $Fontweight, $Fontsize);
                         $this->SetXY($Left, $Top);
                         $this->Cell($Width, $Height, $Caption, $BorderWidth, $ln, $TextAlign, $BackStyle);
                         $s = $s . "   <div class='{$Name}'>Page #thePageNumber# of #totalNumberOfPages#</div>\n";
                     } else {
                         //date display
                         if ($Source == '=Date()' or $Source == '=Now()') {
                             $formattedValue = date($this->accessDateFormatToPHPDateFormat($Format));
                             $Caption = $formattedValue;
                             $this->SetFont($Fontname, $Fontweight, $Fontsize);
                             $this->SetXY($Left, $Top);
                             $this->Cell($Width, $Height, $Caption, $BorderWidth, $ln, $TextAlign, $BackStyle);
                             $s = $s . "      <div class='{$Name}' style='position:absolute;top:{$Top};height:{$Height}'>{$formattedValue}</div>\n";
                         } else {
                             //format number
                             if ($Format == 'Fixed') {
                                 if ($record[$this->report->Controls[$i]->ControlSource] != '') {
                                     $formattedValue = number_format($record[$this->report->Controls[$i]->ControlSource], $Decimal);
                                 }
                             }
                             //currency number
                             if ($Format == 'Currency') {
                                 $formattedValue = "\$" . number_format($record[$this->report->Controls[$i]->ControlSource], 2);
                                 $formattedValue = str_replace('$-', '-$', $formattedValue);
                             }
                             //date format (no todate() and now())
                             if (substr($Format, 0, 2) == 'dd' or substr($Format, 0, 2) == 'mm' or substr($Format, 0, 2) == 'yy' or substr($Format, 0, 2) == 'hh' or substr($Format, 0, 2) == 'nn' or substr($Format, 0, 2) == 'ss') {
                                 //for sql format case yyyy-mm-dd
                                 if (substr($formattedValue, 4, 1) == '-' and substr($formattedValue, 7, 1) == '-') {
                                     $timestamp = mktime(0, 0, 0, substr($formattedValue, 5, 2), substr($formattedValue, 8, 2), substr($formattedValue, 0, 4));
                                     $formattedValue = date($this->accessDateFormatToPHPDateFormat($Format), $timestamp);
                                 }
                             }
                             if ($this->report->Controls[$i]->CanGrow == 'True' and $canGrow) {
                                 $oldValue = $formattedValue;
                                 $formattedValue = wordwrap($formattedValue, iif($ReportTag == '', 10, $ReportTag), "<br />");
                                 $formattedValue = nl2br($formattedValue);
                                 $lines = substr_count($formattedValue, "<br />") + 1;
                                 $defaultHeight = $Height;
                                 $Height = $Height * iif($lines == 0, 1, $lines);
                                 if ($this->growBy < $Height - $defaultHeight) {
                                     $this->growBy = $Height - $defaultHeight;
                                 }
                                 //									$s                      = $s . "      <div class='$Name' style='position:absolute;top:$Top;height:$Height'>$oldValue</div>\n";
                                 $s = $s . "      <div class='{$Name}' style='position:absolute;top:{$Top};height:{$Height}'>{$formattedValue}</div>\n";
                             } else {
                                 $Caption = $formattedValue;
                                 $this->SetFont($Fontname, $Fontweight, $Fontsize);
                                 $this->SetXY($Left, $Top);
                                 $this->Cell($Width, $Height, $Caption, $BorderWidth, $ln, $TextAlign, $BackStyle);
                                 //tofile($BorderColor[0]." ".$BorderColor[1]." ".$BorderColor[2]);
                                 //tofile("Border Width: ".$BorderWidth);
                                 $s = $s . "      <div class='{$Name}' style='position:absolute;top:{$Top};height:{$Height}'>{$formattedValue}</div>\n";
                             }
                         }
                     }
                 }
             }
         }
     }
     return $s;
 }
function nuSession($id, $newPage = '')
{
    if ($_COOKIE['security_check'] != $id) {
        $id = $id . 'x';
    }
    //change to invalid $id
    $setup = nuSetup();
    $time = time();
    $allowed = $setup->set_time_out_minutes * 60;
    $s = "SELECT IF({$time} - sss_session_seconds <= {$allowed}, '1', '') AS foundOK, ";
    $s = $s . "zzsys_session.*, {$time} AS the_time FROM zzsys_session WHERE zzsys_session_id = '{$id}' ";
    $t = nuRunQuery($s);
    $r = db_fetch_object($t);
    $T = nuRunQuery("UPDATE zzsys_session SET sss_session_seconds = '" . time() . "' WHERE zzsys_session_id = '{$id}' ");
    if ($r->foundOK == '') {
        nuRunQuery("DELETE FROM zzsys_session WHERE zzsys_session_id = '{$id}'");
    }
    return $r;
}