public function setValue($pRecordID, $pClone, $pValue)
 {
     $type = $this->objectProperty['sob_all_type'];
     if ($type == 'display') {
         //---replace any hashes with variables
         $sql = replaceVariablesInString($this->TT, $this->objectProperty['sob_display_sql'], $this->recordID);
         //---run sql and use the first row and colomn as the value for this field
         $t = nuRunQuery($sql);
         $r = db_fetch_row($t);
         return formatTextValue($r[0], $this->objectProperty['sob_display_format']);
     }
     if ($type == 'dropdown') {
         if ($pRecordID == '-1' or $pClone and $this->objectProperty['sob_all_clone'] != '1') {
             //---get default value from sob_text_default_value_sql
             if ($this->objectProperty['sob_dropdown_default_value_sql'] == '') {
                 return '';
             }
             //---replace any hashes with variables
             $sql = replaceVariablesInString($this->TT, $this->objectProperty['sob_dropdown_default_value_sql'], $this->recordID);
             //---run sql and use the first row and colomn as the default value for this field
             $t = nuRunQuery($sql);
             $r = db_fetch_row($t);
             return $r[0];
         }
         return $pValue;
         //---return value already in record
     }
     if ($type == 'lookup') {
         if ($pRecordID == '-1' or $pClone and $this->objectProperty['sob_all_clone'] != '1') {
             //---get default value from sob_text_default_value_sql
             if ($this->objectProperty['sob_lookup_default_value_sql'] == '') {
                 $this->lookupArray['id'] = '';
                 $this->lookupArray['code'] = '';
                 $this->lookupArray['description'] = '';
                 return '';
             }
             $defaultValueSQL = replaceVariablesInString('', $this->objectProperty['sob_lookup_default_value_sql'], '');
             $T = nuRunQuery($defaultValueSQL);
             $R = db_fetch_row($T);
             $pValue = $R[0];
         }
         //-------
         //--get sql from lookup form
         $lookupFormID = $this->objectProperty['sob_lookup_zzsysform_id'];
         $t = nuRunQuery("SELECT * FROM zzsys_form WHERE zzsys_form_id = '{$lookupFormID}'");
         $r = db_fetch_object($t);
         $TT = $this->TT;
         $browseTable = $TT;
         eval($r->sfo_custom_code_run_before_browse);
         $SQLwithGlobalValues = replaceVariablesInString($this->TT, $r->sfo_sql, '');
         $SQLwithRecordValues = getSqlRecordValues($SQLwithGlobalValues, $this->parentForm->recordAndFieldValues);
         $SQL = new sqlString($SQLwithRecordValues);
         //-------
         //			$SQL                                = new sqlString(replaceVariablesInString($this->TT,$this->objectProperty['sob_lookup_sql'], ''));
         tofile('sql step 1==' . $this->objectProperty['sob_lookup_sql']);
         $SQL->setWhere("WHERE " . $this->objectProperty['sob_lookup_id_field'] . " = '{$pValue}'");
         $SQL->removeAllFields();
         $SQL->addField($this->objectProperty['sob_lookup_id_field']);
         $SQL->addField($this->objectProperty['sob_lookup_code_field']);
         $SQL->addField($this->objectProperty['sob_lookup_description_field']);
         $T = nuRunQuery($SQL->SQL);
         tofile('step 111');
         $R = db_fetch_row($T);
         $this->lookupArray['id'] = $R[0];
         $this->lookupArray['code'] = $R[1];
         $this->lookupArray['description'] = $R[2];
         return $pValue;
         //---return value already in record
     }
     if ($type == 'inarray') {
         if ($pRecordID == '-1' or $pClone and $this->objectProperty['sob_all_clone'] != '1') {
             //---get default value from sob_text_default_value_sql
             if ($this->objectProperty['sob_inarray_default_value_sql'] == '') {
                 return '';
             }
             //---replace any hashes with variables
             $sql = replaceVariablesInString($this->TT, $this->objectProperty['sob_inarray_default_value_sql'], $this->recordID);
             //---run sql and use the first row and column as the default value for this field
             $t = nuRunQuery($sql);
             $r = db_fetch_row($t);
             return $r[0];
         }
         return $pValue;
         //---return value already in record
     }
     if ($type == 'password') {
         return $pValue;
     }
     if ($type == 'text') {
         if ($pRecordID == '-1' or $pClone and $this->objectProperty['sob_all_clone'] != '1') {
             //---get default value from sob_text_default_value_sql
             if ($this->objectProperty['sob_text_default_value_sql'] == '') {
                 return formatTextValue('', $this->objectProperty['sob_text_format']);
             }
             //---replace any hashes with variables
             $sql = replaceVariablesInString($this->TT, $this->objectProperty['sob_text_default_value_sql'], $this->recordID);
             //---run sql and use the first row and colomn as the default value for this field
             $t = nuRunQuery($sql);
             $r = db_fetch_row($t);
             return formatTextValue($r[0], $this->objectProperty['sob_text_format']);
         }
         return formatTextValue($pValue, $this->objectProperty['sob_text_format']);
         //---return value already in record
     }
     if ($type == 'textarea') {
         if ($pRecordID == '-1' or $pClone and $this->objectProperty['sob_all_clone'] != '1') {
             //---get default value from sob_text_default_value_sql
             if ($this->objectProperty['sob_textarea_default_value_sql'] == '') {
                 return '';
             }
             //---replace any hashes with variables
             $sql = replaceVariablesInString($this->TT, $this->objectProperty['sob_textarea_default_value_sql'], $this->recordID);
             //---run sql and use the first row and colomn as the default value for this field
             $t = nuRunQuery($sql);
             $r = db_fetch_row($t);
             return $r[0];
         }
         return $pValue;
         //---return value already in record
     }
 }
Example #2
0
 public function setValue($pRecordID, $pClone, $pValue)
 {
     $type = $this->objectProperty['sob_all_type'];
     $this->objectType = $this->objectProperty['sob_all_type'];
     if ($type == 'display') {
         //---replace any hashes with variables
         $sql = replaceVariablesInString($this->TT, $this->objectProperty['sob_display_sql'], $this->recordID);
         //---run sql and use the first row and colomn as the value for this field
         if (trim($sql) == '') {
             return '';
         }
         $t = nuRunQuery($sql);
         $r = db_fetch_row($t);
         return formatTextValue($r[0], $this->objectProperty['sob_display_format']);
     }
     if ($type == 'dropdown') {
         if ($this->activity or $pRecordID == '-1' or $pClone and $this->objectProperty['sob_all_clone'] != '1') {
             //---get default value from sob_text_default_value_sql
             if ($this->objectProperty['sob_dropdown_default_value_sql'] == '') {
                 return '';
             }
             //---replace any hashes with variables
             $sql = replaceVariablesInString($this->TT, $this->objectProperty['sob_dropdown_default_value_sql'], $this->recordID);
             //---run sql and use the first row and colomn as the default value for this field
             $t = nuRunQuery($sql);
             $r = db_fetch_row($t);
             return $r[0];
         }
         return $pValue;
         //---return value already in record
     }
     if ($type == 'lookup') {
         if ($pValue == '' or $this->activity or $pRecordID == '-1' or $pClone and $this->objectProperty['sob_all_clone'] != '1') {
             //---get default value from sob_text_default_value_sql
             if ($this->objectProperty['sob_lookup_default_value_sql'] == '') {
                 $this->lookupArray['id'] = '';
                 $this->lookupArray['code'] = '';
                 $this->lookupArray['description'] = '';
                 return '';
             }
             $defaultValueSQL = replaceVariablesInString('', $this->objectProperty['sob_lookup_default_value_sql'], '');
             $T = nuRunQuery($defaultValueSQL);
             $R = db_fetch_row($T);
             $pValue = $R[0];
         }
         //--get sql from lookup form
         if ($this->objectProperty['sob_lookup_load_zzsysform_id'] == '') {
             $lookupFormID = $this->objectProperty['sob_lookup_zzsysform_id'];
         } else {
             $lookupFormID = $this->objectProperty['sob_lookup_load_zzsysform_id'];
         }
         $t = nuRunQuery("SELECT * FROM zzsys_form WHERE zzsys_form_id = '{$lookupFormID}'");
         $r = db_fetch_object($t);
         $browseTable = $this->TT;
         $TT = $this->TT;
         $this->parentForm->arrayOfHashVariables['#formSessionID#'] = $this->parentForm->formsessionID;
         $this->parentForm->arrayOfHashVariables['#browseTable#'] = $this->TT;
         $this->parentForm->arrayOfHashVariables['#TT#'] = $this->TT;
         eval(replaceHashVariablesWithValues($this->parentForm->arrayOfHashVariables, $r->sfo_custom_code_run_before_browse));
         //--replace hash variables then run code
         $r->sfo_sql = replaceHashVariablesWithValues($this->parentForm->arrayOfHashVariables, $r->sfo_sql);
         //--replace hash variables
         $SQL = new sqlString($r->sfo_sql);
         if ($SQL->getWhere() == '') {
             $SQL->setWhere("WHERE " . $this->objectProperty['sob_lookup_id_field'] . " = '{$pValue}'");
         } else {
             $SQL->setWhere($SQL->getWhere() . " AND (" . $this->objectProperty['sob_lookup_id_field'] . " = '{$pValue}')");
         }
         $SQL->removeAllFields();
         $SQL->addField($this->objectProperty['sob_lookup_id_field']);
         $SQL->addField($this->objectProperty['sob_lookup_code_field']);
         if ($this->objectProperty['sob_lookup_description_field'] == '') {
             $SQL->addField("''");
         } else {
             $SQL->addField($this->objectProperty['sob_lookup_description_field']);
         }
         if ($_GET['debug'] != '') {
             tofile('SQL lookup hash variables : debug value:' . $_GET['debug']);
             tofile(print_r($this->parentForm->arrayOfHashVariables, true));
             tofile($SQL->SQL);
         }
         $T = nuRunQuery($SQL->SQL);
         /*            $lookupform                         = formFields($this->objectProperty['sob_lookup_zzsysform_id']);
         
         		    $fld1                               = $this->objectProperty['sob_lookup_id_field'];
         		    $fld2                               = $this->objectProperty['sob_lookup_code_field'];
         	    	if($this->objectProperty['sob_lookup_description_field']==''){
             		    $fld3                           = '"" AS desc ';
             		}else{
             		    $fld3                           = $this->objectProperty['sob_lookup_description_field'];
         		    }
             		$T = nuRunQuery("SELECT $fld1, $fld2, $fld3 FROM $lookupform->sfo_table WHERE $lookupform->sfo_primary_key = '$pValue'");
         */
         $R = db_fetch_row($T);
         $this->lookupArray['id'] = $R[0];
         $this->lookupArray['code'] = $R[1];
         $this->lookupArray['description'] = $R[2];
         //		    if($browseTable!=''){nuRunQuery("DROP TABLE IF EXISTS `$this->TT`");}
         return $pValue;
         //---return value already in record
     }
     if ($type == 'inarray') {
         if ($this->activity or $pRecordID == '-1' or $pClone and $this->objectProperty['sob_all_clone'] != '1') {
             //---get default value from sob_text_default_value_sql
             if ($this->objectProperty['sob_inarray_default_value_sql'] == '') {
                 return '';
             }
             //---replace any hashes with variables
             $sql = replaceVariablesInString($this->TT, $this->objectProperty['sob_inarray_default_value_sql'], $this->recordID);
             //---run sql and use the first row and column as the default value for this field
             $t = nuRunQuery($sql);
             $r = db_fetch_row($t);
             return $r[0];
         }
         return $pValue;
         //---return value already in record
     }
     if ($type == 'password') {
         return $pValue;
     }
     if ($type == 'text') {
         if ($this->activity or $pRecordID == '-1' or $pClone and $this->objectProperty['sob_all_clone'] != '1') {
             //---get default value from sob_text_default_value_sql
             if ($this->objectProperty['sob_text_default_value_sql'] == '') {
                 return formatTextValue('', $this->objectProperty['sob_text_format']);
             }
             //---replace any hashes with variables
             $sql = replaceVariablesInString($this->TT, $this->objectProperty['sob_text_default_value_sql'], $this->recordID);
             //---run sql and use the first row and colomn as the default value for this field
             $t = nuRunQuery($sql);
             $r = db_fetch_row($t);
             return formatTextValue($r[0], $this->objectProperty['sob_text_format']);
         }
         return formatTextValue($pValue, $this->objectProperty['sob_text_format']);
         //---return value already in record
     }
     if ($type == 'textarea') {
         if ($this->activity or $pRecordID == '-1' or $pClone and $this->objectProperty['sob_all_clone'] != '1') {
             //---get default value from sob_text_default_value_sql
             if ($this->objectProperty['sob_textarea_default_value_sql'] == '') {
                 return '';
             }
             //---replace any hashes with variables
             $sql = replaceVariablesInString($this->TT, $this->objectProperty['sob_textarea_default_value_sql'], $this->recordID);
             //---run sql and use the first row and colomn as the default value for this field
             $t = nuRunQuery($sql);
             $r = db_fetch_row($t);
             return $r[0];
         }
         return $pValue;
         //---return value already in record
     }
 }
 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 calcFunction($nuFunction, $pControl, $pRecord, $pGroup, $pReport)
{
    $FieldList = array();
    $strip_out = array('=', 'SUM', 'PERCENT', 'sum', 'precent', 'Sum', 'Percent', '(', ')', '[', ']', ' ');
    //--strings to strip out of source
    if ($nuFunction == 1 or $nuFunction == 2) {
        //--sum or percent function
        if ($pReport->no_data) {
            return 0;
        }
        $field_list = str_replace($strip_out, '', $pControl->source);
        $fields = explode(',', $field_list);
        if ($nuFunction == 1) {
            $selectFields = "SUM(" . $fields[0] . "_Sum) as answerA ";
        } else {
            $selectFields = "SUM(" . $fields[0] . "_Sum) as answerA, SUM(" . $fields[1] . "_Sum) as answerB ";
        }
        $groupSQL = $pReport->getGroupBySql($pReport->sectionLevel($pControl->section), $selectFields, $pRecord);
        $t = nuRunQuery($groupSQL);
        $r = mysql_fetch_row($t);
        if ($nuFunction == 1) {
            return formatTextValue($r[0], $pControl->format);
        } else {
            if ($r[0] == 0) {
                return formatTextValue(0, $pControl->format);
            } else {
                return formatTextValue($r[0] / $r[1], $pControl->format);
            }
        }
    }
    if ($nuFunction == 3 or $nuFunction == 4) {
        //--date or now function
        $formats = textFormatsArray();
        $n = date("H:i:s");
        $d = date($formats[$pControl->format]->phpdate);
        if ($nuFunction == 4) {
            //--now function
            $d = "{$d} {$n}";
        }
        return $d;
    }
}
 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;
 }
 public function buildBody()
 {
     $percentAmount = 1;
     $select = '';
     $dq = '"';
     $this->SQL->removeAllFields();
     $s = "<table >{$this->CRLF}";
     $s = $s . "<tr >{$this->CRLF}";
     for ($i = 0; $i < count($this->Column); $i++) {
         $this->SQL->addField($this->Column[$i]->sbr_display);
         $a = align($this->Column[$i]->sbr_align);
         $s = $s . "{$this->TAB}<th align='{$a}' bgcolor='lightgrey'>{$this->CRLF}";
         $desc = iif($i == $this->orderBy and $this->isDescending == '', '1', '');
         $s = $s . "{$this->TAB}{$this->TAB}<a href='#' onclick='newOrder({$dq}{$i}{$dq}, {$dq}{$desc}{$dq})'>" . $this->Column[$i]->sbr_title . "</a>{$this->CRLF}";
         $s = $s . "{$this->TAB}</th>{$this->CRLF}";
     }
     $s = $s . "</tr>{$this->CRLF}";
     $page = ($this->PageNo - 1) * $this->pageLength;
     tofile("{$page}              = ({$this->PageNo} -1) * {$this->pageLength}");
     $this->SQL->addField($this->callingForm->sfo_primary_key);
     $primaryKeyNumber = count($this->SQL->fields) - 1;
     $t = nuRunQuery($this->SQL->SQL . " LIMIT {$page}, 9");
     $top = -15;
     $row = 0;
     while ($r = db_fetch_row($t)) {
         $theID = $r[$primaryKeyNumber];
         $rowname = 'rw' . substr('0' . $row, -2);
         $param = '"' . $rowname . '"';
         $left = 0;
         $top = $top + $this->rowHeight;
         $s = $s . "<tr id='browse'>{$this->CRLF}";
         $color = iif($color == 'Gainsboro', 'white', 'Gainsboro');
         for ($i = 0; $i < count($this->Column); $i++) {
             $w = $this->Column[$i]->sbr_width * $percentAmount;
             $a = align($this->Column[$i]->sbr_align);
             $s = $s . "{$this->TAB}<td bgcolor='{$color}' align='{$a}'>{$this->CRLF}";
             if ($i == 0) {
                 if ($this->isLookup) {
                     $theObject = $this->objectID;
                     $s = $s . "{$this->TAB}{$this->TAB}&nbsp;<a href='formlookupsmall.php?x=1&f={$this->theFormID}&ob={$theObject}&r={$theID}&fr=" . $_GET['fr'] . "&dir=" . $_GET['dir'] . "&ses=" . $_GET['ses'] . "'>" . formatTextValue($r[$i], $this->Column[$i]->sbr_format) . "</a>&nbsp;{$this->CRLF}";
                 } else {
                     $s = $s . "{$this->TAB}{$this->TAB}&nbsp;<a href='formsmall.php?x=1&f={$this->theFormID}&fr={$theID}&dir=" . $_GET['dir'] . "&ses=" . $_GET['ses'] . "'>" . formatTextValue($r[$i], $this->Column[$i]->sbr_format) . "</a>&nbsp;{$this->CRLF}";
                 }
             } else {
                 $s = $s . "{$this->TAB}{$this->TAB}&nbsp;" . formatTextValue($r[$i], $this->Column[$i]->sbr_format) . "&nbsp;{$this->CRLF}";
             }
             $s = $s . "{$this->TAB}</td>{$this->CRLF}";
         }
         $s = $s . "{$this->TAB}</tr>{$this->CRLF}";
         $row = $row + 1;
     }
     $s = $s . '</table>';
     return $s;
 }
 public function buildBody()
 {
     $left = 0;
     $pageWidth = 968;
     $percentAmount = 1;
     $select = '';
     $this->SQL->removeAllFields();
     $s = "<div id='BorderDiv'  class='nuborder' class='unselected' style='overflow:hidden;position:absolute;top:80; left:10;  width:972;    height:600' ></div>{$CRLF}";
     $s = $s . "<div id='browse' class='unselected' style='vertical-align:text-bottom;visibility:visible;overflow:hidden;position:absolute;top:85; left:12;  width:{$pageWidth};  height:30'  >{$this->CRLF}";
     for ($i = 0; $i < count($this->Column); $i++) {
         $this->SQL->addField($this->Column[$i]->sbr_display);
         $w = $this->Column[$i]->sbr_width * $percentAmount;
         $a = align($this->Column[$i]->sbr_align);
         $s = $s . "{$this->TAB}<div class='unselected' style='overflow:hidden;position:absolute;text-align:{$a};top:0;left:{$left};width:{$w};height:20'>{$this->CRLF}";
         $desc = iif($i == $this->orderBy and $this->isDescending == '', '1', '');
         $s = $s . "{$this->TAB}{$this->TAB}<span style='cursor:hand;font-size:x-small;font-family:tahoma;font-weight:bold;height:50' id='title{$i}' onmouseout='TOUT(this)' onmouseover='TIN(this)' onclick='runOrder({$i}, \"{$desc}\")'>&nbsp;" . $this->Column[$i]->sbr_title . "&nbsp;</span>{$this->CRLF}";
         $s = $s . "{$this->TAB}</div>{$this->CRLF}";
         $left = $left + $w;
     }
     $s = $s . "</div>{$this->CRLF}";
     $s = $s . "<div id='browse' class='browse' style='visibility:visible;overflow:hidden;position:absolute;top:105; left:12;  width:{$pageWidth};  height:556'  >{$this->CRLF}";
     $page = ($this->PageNo - 1) * $this->pageLength;
     $this->SQL->addField($this->form->sfo_primary_key);
     $primaryKeyNumber = count($this->SQL->fields) - 1;
     //tofile('browse sql:'.$this->SQL->SQL);
     $t = nuRunQuery($this->SQL->SQL . " LIMIT {$page}, 27");
     $top = -10;
     $row = 0;
     while ($r = db_fetch_row($t)) {
         $theID = '"' . $r[$primaryKeyNumber] . '"';
         $rowname = 'rw' . substr('0' . $row, -2);
         $param = '"' . $rowname . '"';
         $left = 0;
         $top = $top + $this->rowHeight;
         for ($i = 0; $i < count($this->Column); $i++) {
             $w = $this->Column[$i]->sbr_width * $percentAmount;
             $a = align($this->Column[$i]->sbr_align);
             $s = $s . "{$this->TAB}<div onmouseover='MIN({$param})' onmouseout='MOUT({$param})' onclick='doIt({$theID})' class='browse' id='{$rowname}{$i}' style='cursor:hand;text-align:{$a};top:{$top};left:{$left};width:{$w};height:{$this->rowHeight}'>{$this->CRLF}";
             $s = $s . "{$this->TAB}{$this->TAB}&nbsp;" . formatTextValue($r[$i], $this->Column[$i]->sbr_format) . "&nbsp;{$this->CRLF}";
             $s = $s . "{$this->TAB}</div>{$this->CRLF}";
             $left = $left + $w;
         }
         $w = iif($left < $pageWidth, $pageWidth - $left, 0);
         $s = $s . "{$this->TAB}<div onmouseover='MIN({$param})' onmouseout='MOUT({$param})' onclick='doIt({$theID})' class='browse' id='{$rowname}{$i}' style='cursor:hand;top:{$top};left:{$left};width:{$w};height:{$this->rowHeight}'>{$this->CRLF}";
         $s = $s . "{$this->TAB}</div>{$this->CRLF}";
         // allow keyboad movement
         $s = $s . "{$this->TAB}<div onmouseover='MIN({$param})' onmouseout='MOUT({$param})' class='browse' id='hidden{$rowname}{$i}' style='top:{$top};left:{$left};width:0;height:{$this->rowHeight}'>{$this->CRLF}";
         $s = $s . "{$this->TAB}<input onfocus='MIN({$param})' onblur='MOUT({$param})' >{$this->CRLF}";
         $s = $s . "{$this->TAB}</div>{$this->CRLF}";
         $row = $row + 1;
     }
     $s = $s . '</div>';
     //------print login name
     $slogin = "******";
     $t = nuRunQuery("SELECT * FROM zzsys_user WHERE zzsys_user_id = '{$this->zzsys_user_id}'");
     $r = db_fetch_object($t);
     if ($this->form->sfo_help != '') {
         $help = "title='help' onclick='openHelp(" . '"' . $this->form->zzsys_form_id . '")' . "'";
     } else {
         $help = "";
     }
     if ($r->sus_login_name == '') {
         $r->sus_login_name = 'globeadmin';
     }
     $slogin = $slogin . "<span id='nuuser' class='unselected' style='font-size:10;font-weight:normal' {$help} >{$r->sus_login_name}&nbsp;</span></div>{$CRLF}";
     $slogin = $slogin . "<div id='BorderDiv3'   class='nuborder' style='overflow:hidden;position:absolute;top:664;left:12;width:200;height:15;text-align:left' >{$CRLF}";
     $slogin = $slogin . "<span id='powered' class='unselected' style='font-size:10;font-weight:normal'>Powered by nuBuilder</span></div>{$CRLF}";
     return $s . $slogin;
 }