예제 #1
0
function CCFormatNumber($NumberToFormat, $FormatArray, $DataType = ccsFloat, $isDBFormat = false)
{
    global $CCSLocales;
    global $CCSIsXHTML;
    $Result = "";
    if (is_array($FormatArray) && strlen($NumberToFormat)) {
        $IsExtendedFormat = $FormatArray[0];
        $IsNegative = $NumberToFormat < 0;
        $NumberToFormat = abs($NumberToFormat);
        $NumberToFormat *= $FormatArray[7];
        if ($IsExtendedFormat) {
            $DecimalSeparator = !is_null($FormatArray[2]) ? $FormatArray[2] : ($isDBFormat ? "." : $CCSLocales->GetFormatInfo("DecimalSeparator"));
            $PeriodSeparator = !is_null($FormatArray[3]) ? $FormatArray[3] : ($isDBFormat ? "" : $CCSLocales->GetFormatInfo("GroupSeparator"));
            $ObligatoryBeforeDecimal = 0;
            $DigitsBeforeDecimal = 0;
            $BeforeDecimal = $FormatArray[5];
            $AfterDecimal = !is_null($FormatArray[6]) ? $FormatArray[6] : ($DataType != ccsInteger ? $isDBFormat ? 100 : $CCSLocales->GetFormatInfo("DecimalDigits") : 0);
            if (is_array($BeforeDecimal)) {
                for ($i = 0; $i < sizeof($BeforeDecimal); $i++) {
                    if ($BeforeDecimal[$i] == "0") {
                        $ObligatoryBeforeDecimal++;
                        $DigitsBeforeDecimal++;
                    } else {
                        if ($BeforeDecimal[$i] == "#") {
                            $DigitsBeforeDecimal++;
                        }
                    }
                }
            }
            $ObligatoryAfterDecimal = 0;
            $DigitsAfterDecimal = 0;
            if (is_array($AfterDecimal)) {
                for ($i = 0; $i < sizeof($AfterDecimal); $i++) {
                    if ($AfterDecimal[$i] == "0") {
                        $ObligatoryAfterDecimal++;
                        $DigitsAfterDecimal++;
                    } else {
                        if ($AfterDecimal[$i] == "#") {
                            $DigitsAfterDecimal++;
                        }
                    }
                }
            }
            $NumberToFormat = number_format($NumberToFormat, $DigitsAfterDecimal, ".", "");
            $NumberParts = explode(".", $NumberToFormat);
            $LeftPart = $NumberParts[0];
            if ($LeftPart == "0") {
                $LeftPart = "";
            }
            $RightPart = isset($NumberParts[1]) ? $NumberParts[1] : "";
            $j = strlen($LeftPart);
            if (is_array($BeforeDecimal)) {
                $RankNumber = 0;
                $i = sizeof($BeforeDecimal);
                while ($i > 0 || $j > 0) {
                    if ($i > 0 && ($BeforeDecimal[$i - 1] == "#" || $BeforeDecimal[$i - 1] == "0") || $j > 0 && $i < 1) {
                        $RankNumber++;
                        $CurrentSeparator = $RankNumber % 3 == 1 && $RankNumber > 3 && $j > 0 ? $PeriodSeparator : "";
                        if ($ObligatoryBeforeDecimal > 0 && $j < 1) {
                            $Result = "0" . $CurrentSeparator . $Result;
                        } else {
                            if ($j > 0) {
                                $Result = $LeftPart[$j - 1] . $CurrentSeparator . $Result;
                            }
                        }
                        $j--;
                        $ObligatoryBeforeDecimal--;
                        $DigitsBeforeDecimal--;
                        if ($DigitsBeforeDecimal == 0 && $j > 0) {
                            for (; $j > 0; $j--) {
                                $RankNumber++;
                                $CurrentSeparator = $RankNumber % 3 == 1 && $RankNumber > 3 && $j > 0 ? $PeriodSeparator : "";
                                $Result = $LeftPart[$j - 1] . $CurrentSeparator . $Result;
                            }
                        }
                    } else {
                        if ($i > 0) {
                            $BeforeDecimal[$i - 1] = str_replace("##", "#", $BeforeDecimal[$i - 1]);
                            $BeforeDecimal[$i - 1] = str_replace("00", "0", $BeforeDecimal[$i - 1]);
                            $Result = $BeforeDecimal[$i - 1] . $Result;
                        }
                    }
                    $i--;
                }
            }
            // Left part after decimal
            $RightResult = "";
            $IsRightNumber = false;
            if (is_array($AfterDecimal)) {
                $IsZero = true;
                for ($i = sizeof($AfterDecimal); $i > 0; $i--) {
                    if ($AfterDecimal[$i - 1] == "#" || $AfterDecimal[$i - 1] == "0") {
                        if ($DigitsAfterDecimal > $ObligatoryAfterDecimal) {
                            if ($RightPart[$DigitsAfterDecimal - 1] != "0") {
                                $IsZero = false;
                            }
                            if (!$IsZero) {
                                $RightResult = $RightPart[$DigitsAfterDecimal - 1] . $RightResult;
                                $IsRightNumber = true;
                            }
                        } else {
                            $RightResult = $RightPart[$DigitsAfterDecimal - 1] . $RightResult;
                            $IsRightNumber = true;
                        }
                        $DigitsAfterDecimal--;
                    } else {
                        $AfterDecimal[$i - 1] = str_replace("##", "#", $AfterDecimal[$i - 1]);
                        $AfterDecimal[$i - 1] = str_replace("00", "0", $AfterDecimal[$i - 1]);
                        $RightResult = $AfterDecimal[$i - 1] . $RightResult;
                    }
                }
            }
            if ($IsRightNumber) {
                $Result .= $DecimalSeparator;
            }
            $Result .= $RightResult;
            if (!$FormatArray[4] && $IsNegative && $Result) {
                $Result = "-" . $Result;
            }
        } else {
            $DecimalSeparator = !is_null($FormatArray[2]) ? $FormatArray[2] : ($isDBFormat ? "." : $CCSLocales->GetFormatInfo("DecimalSeparator"));
            $PeriodSeparator = !is_null($FormatArray[3]) ? $FormatArray[3] : ($isDBFormat ? "" : $CCSLocales->GetFormatInfo("GroupSeparator"));
            $AfterDecimal = !is_null($FormatArray[1]) ? $FormatArray[1] : ($DataType != ccsInteger ? $isDBFormat ? 100 : $CCSLocales->GetFormatInfo("DecimalDigits") : 0);
            $Result = number_format($NumberToFormat, $AfterDecimal, '.', ',');
            $Result = str_replace(".", '---', $Result);
            $Result = str_replace(",", '+++', $Result);
            $Result = str_replace("---", $DecimalSeparator, $Result);
            $Result = str_replace("+++", $PeriodSeparator, $Result);
            $Result = $FormatArray[5] . $Result . $FormatArray[6];
            if (!$FormatArray[4] && $IsNegative) {
                $Result = "-" . $Result;
            }
        }
        if (!$FormatArray[8]) {
            $Result = CCToHTML($Result);
        }
    } elseif (strlen($NumberToFormat)) {
        if ($DataType != ccsInteger) {
            $DecimalSeparator = $isDBFormat ? "." : $CCSLocales->GetFormatInfo("DecimalSeparator");
            $Result = str_replace(",", $DecimalSeparator, $NumberToFormat);
            $Result = str_replace(".", $DecimalSeparator, $Result);
        } else {
            $Result = $NumberToFormat;
        }
    }
    if (is_array($FormatArray) && strlen($FormatArray[9])) {
        if ($CCSIsXHTML) {
            $Result = "<span style=\"color: " . $FormatArray[9] . "\">" . $Result . "</span>";
        } else {
            $Result = "<FONT COLOR=\"" . $FormatArray[9] . "\">" . $Result . "</FONT>";
        }
    }
    return $Result;
}
예제 #2
0
파일: title.php 프로젝트: Okwori/iRadiology
 function Show()
 {
     $Tpl =& CCGetTemplate($this);
     global $FileName;
     global $CCSLocales;
     global $CCSUseAmp;
     $Error = "";
     if (!$this->Visible) {
         return;
     }
     $this->CCSEventResult = CCGetEvent($this->CCSEvents, "BeforeSelect", $this);
     $this->DataSource->open();
     $is_next_record = $this->ReadAllowed && $this->DataSource->next_record();
     $this->IsEmpty = !$is_next_record;
     $this->CCSEventResult = CCGetEvent($this->CCSEvents, "BeforeShow", $this);
     if (!$this->Visible) {
         return;
     }
     $this->Attributes->Show();
     $this->Button_Submit->Visible = $this->Button_Submit->Visible && ($this->InsertAllowed || $this->UpdateAllowed || $this->DeleteAllowed);
     $ParentPath = $Tpl->block_path;
     $EditableGridPath = $ParentPath . "/EditableGrid " . $this->ComponentName;
     $EditableGridRowPath = $ParentPath . "/EditableGrid " . $this->ComponentName . "/Row";
     $Tpl->block_path = $EditableGridRowPath;
     $this->RowNumber = 0;
     $NonEmptyRows = 0;
     $EmptyRowsLeft = $this->EmptyRows;
     $this->ControlsVisible["title_id"] = $this->title_id->Visible;
     $this->ControlsVisible["title"] = $this->title->Visible;
     $this->ControlsVisible["CheckBox_Delete"] = $this->CheckBox_Delete->Visible;
     if ($is_next_record || $EmptyRowsLeft && $this->InsertAllowed) {
         do {
             $this->RowNumber++;
             if ($is_next_record) {
                 $NonEmptyRows++;
                 $this->DataSource->SetValues();
             }
             if (!$is_next_record || !$this->DeleteAllowed) {
                 $this->CheckBox_Delete->Visible = false;
             }
             if (!$this->FormSubmitted && $is_next_record) {
                 $this->CachedColumns["title_id"][$this->RowNumber] = $this->DataSource->CachedColumns["title_id"];
                 $this->CheckBox_Delete->SetValue(false);
                 $this->title_id->SetValue($this->DataSource->title_id->GetValue());
                 $this->title->SetValue($this->DataSource->title->GetValue());
             } elseif ($this->FormSubmitted && $is_next_record) {
                 $this->title_id->SetText("");
                 $this->title_id->SetValue($this->DataSource->title_id->GetValue());
                 $this->title->SetText($this->FormParameters["title"][$this->RowNumber], $this->RowNumber);
                 $this->CheckBox_Delete->SetText($this->FormParameters["CheckBox_Delete"][$this->RowNumber], $this->RowNumber);
             } elseif (!$this->FormSubmitted) {
                 $this->CachedColumns["title_id"][$this->RowNumber] = "";
                 $this->title_id->SetText("");
                 $this->title->SetText("");
             } else {
                 $this->title_id->SetText("");
                 $this->title->SetText($this->FormParameters["title"][$this->RowNumber], $this->RowNumber);
                 $this->CheckBox_Delete->SetText($this->FormParameters["CheckBox_Delete"][$this->RowNumber], $this->RowNumber);
             }
             $this->Attributes->SetValue("rowNumber", $this->RowNumber);
             $this->CCSEventResult = CCGetEvent($this->CCSEvents, "BeforeShowRow", $this);
             $this->Attributes->Show();
             $this->title_id->Show($this->RowNumber);
             $this->title->Show($this->RowNumber);
             $this->CheckBox_Delete->Show($this->RowNumber);
             if (isset($this->RowsErrors[$this->RowNumber]) && $this->RowsErrors[$this->RowNumber] != "") {
                 $Tpl->setblockvar("RowError", "");
                 $Tpl->setvar("Error", $this->RowsErrors[$this->RowNumber]);
                 $this->Attributes->Show();
                 $Tpl->parse("RowError", false);
             } else {
                 $Tpl->setblockvar("RowError", "");
             }
             $Tpl->setvar("FormScript", $this->FormScript($this->RowNumber));
             $Tpl->parse();
             if ($is_next_record) {
                 if ($this->FormSubmitted) {
                     $is_next_record = $this->RowNumber < $this->UpdatedRows;
                     if ($this->DataSource->CachedColumns["title_id"] == $this->CachedColumns["title_id"][$this->RowNumber]) {
                         if ($this->ReadAllowed) {
                             $this->DataSource->next_record();
                         }
                     }
                 } else {
                     $is_next_record = $this->RowNumber < $this->PageSize && $this->ReadAllowed && $this->DataSource->next_record();
                 }
             } else {
                 $EmptyRowsLeft--;
             }
         } while ($is_next_record || $EmptyRowsLeft && $this->InsertAllowed);
     } else {
         $Tpl->block_path = $EditableGridPath;
         $this->Attributes->Show();
         $Tpl->parse("NoRecords", false);
     }
     $Tpl->block_path = $EditableGridPath;
     $this->Button_Submit->Show();
     $this->Cancel->Show();
     if ($this->CheckErrors()) {
         $Error = ComposeStrings($Error, $this->Errors->ToString());
         $Error = ComposeStrings($Error, $this->DataSource->Errors->ToString());
         $Tpl->SetVar("Error", $Error);
         $Tpl->Parse("Error", false);
     }
     $CCSForm = $this->ComponentName;
     $this->HTMLFormAction = $FileName . "?" . CCAddParam(CCGetQueryString("QueryString", ""), "ccsForm", $CCSForm);
     $Tpl->SetVar("Action", !$CCSUseAmp ? $this->HTMLFormAction : str_replace("&", "&amp;", $this->HTMLFormAction));
     $Tpl->SetVar("HTMLFormName", $this->ComponentName);
     $Tpl->SetVar("HTMLFormEnctype", $this->FormEnctype);
     if (!$CCSUseAmp) {
         $Tpl->SetVar("HTMLFormProperties", "method=\"POST\" action=\"" . $this->HTMLFormAction . "\" name=\"" . $this->ComponentName . "\"");
     } else {
         $Tpl->SetVar("HTMLFormProperties", "method=\"post\" action=\"" . str_replace("&", "&amp;", $this->HTMLFormAction) . "\" id=\"" . $this->ComponentName . "\"");
     }
     $Tpl->SetVar("FormState", CCToHTML($this->GetFormState($NonEmptyRows)));
     $Tpl->parse();
     $Tpl->block_path = $ParentPath;
     $this->DataSource->close();
 }
예제 #3
0
 function Show($RowNumber = "")
 {
     $Tpl = CCGetTemplate($this);
     global $CCSIsXHTML;
     $this->EventResult = CCGetEvent($this->CCSEvents, "BeforeShow", $this);
     $BRValue = $CCSIsXHTML ? "<br />" : "<BR>";
     $CheckedValue = $CCSIsXHTML ? "checked=\"checked\"" : "CHECKED";
     $SelectedValue = $CCSIsXHTML ? "selected=\"selected\"" : "SELECTED";
     $ControlName = $RowNumber === "" ? $this->Name : $this->Name . "_" . $RowNumber;
     if ($this->Multiple) {
         $ControlName = $ControlName . "[]";
     }
     if (!$this->Visible) {
         $Tpl->SetVar($this->Name . "_Name", $ControlName);
         $Tpl->SetVar($this->Name, "");
         if ($Tpl->BlockExists($this->BlockName)) {
             $Tpl->setblockvar($this->BlockName, "");
         }
         return;
     }
     $this->Attributes->Show();
     $MasterPath = CCGetMasterPagePath($this);
     if (strlen($MasterPath)) {
         global $PathToCurrentMasterPage;
         $PathToCurrentMasterPage = $MasterPath;
         $Tpl->SetVar("CCS_PathToMasterPage", $PathToCurrentMasterPage);
     }
     $Tpl->SetVar($this->Name . "_Name", $ControlName);
     switch ($this->ControlType) {
         case ccsLabel:
             $value = $this->GetText();
             if (!$this->HTML) {
                 $value = CCToHTML($value);
                 $value = str_replace("\n", $BRValue, $value);
             }
             $Tpl->SetVar($this->Name, $value);
             $Tpl->ParseSafe($this->BlockName, false);
             break;
         case ccsReportLabel:
             $value = $this->GetText();
             if (strlen($this->EmptyText) && !strlen($value)) {
                 $value = $this->EmptyText;
             }
             if (!$this->HTML) {
                 $value = CCToHTML($value);
                 $value = str_replace("\n", $BRValue, $value);
                 $value = str_replace("\r", "", $value);
             }
             $Tpl->SetVar($this->Name, $value);
             $Tpl->ParseSafe($this->BlockName, false);
             break;
         case ccsTextBox:
         case ccsTextArea:
         case ccsImage:
         case ccsHidden:
             $Tpl->SetVar($this->Name, CCToHTML($this->GetText()));
             $Tpl->ParseSafe($this->BlockName, false);
             break;
         case ccsLink:
             if ($this->HTML) {
                 $Tpl->SetVar($this->Name, $this->GetText());
             } else {
                 $value = CCToHTML($this->GetText());
                 $value = str_replace("\n", $BRValue, $value);
                 $Tpl->SetVar($this->Name, $value);
             }
             $Tpl->SetVar($this->Name . "_Src", $this->GetLink());
             $Tpl->ParseSafe($this->BlockName, false);
             break;
         case ccsImageLink:
             $Tpl->SetVar($this->Name . "_Src", CCToHTML($this->GetText()));
             $Tpl->SetVar($this->Name, $this->GetLink());
             $Tpl->ParseSafe($this->BlockName, false);
             break;
         case ccsCheckBox:
             if ($this->Value) {
                 $Tpl->SetVar($this->Name, $CheckedValue);
             } else {
                 $Tpl->SetVar($this->Name, "");
             }
             $Tpl->ParseSafe($this->BlockName, false);
             break;
         case ccsRadioButton:
             $BlockToParse = "RadioButton " . $this->Name;
             $Tpl->SetBlockVar($BlockToParse, "");
             if (is_array($this->Values)) {
                 for ($i = 0; $i < sizeof($this->Values); $i++) {
                     $Value = $this->Values[$i][0];
                     $this->Attributes->SetValue("optionNumber", $i + 1);
                     $this->Attributes->Objects["optionNumber"]->Show();
                     $Text = $this->HTML ? $this->Values[$i][1] : CCToHTML($this->Values[$i][1]);
                     $Selected = CCCompareValues($Value, $this->Value, $this->DataType, $this->Format) == 0 ? $CheckedValue : "";
                     $TextValue = CCToHTML(CCFormatValue($Value, $this->Format, $this->DataType, $this->Format));
                     $Tpl->SetVar("Value", $TextValue);
                     $Tpl->SetVar("Check", $Selected);
                     $Tpl->SetVar("Description", $Text);
                     $Tpl->Parse($BlockToParse, true);
                 }
             }
             break;
         case ccsCheckBoxList:
             $BlockToParse = "CheckBoxList " . $this->Name;
             $Tpl->SetBlockVar($BlockToParse, "");
             if (is_array($this->Values)) {
                 for ($i = 0; $i < sizeof($this->Values); $i++) {
                     $Value = $this->Values[$i][0];
                     $this->Attributes->SetValue("optionNumber", $i + 1);
                     $this->Attributes->Objects["optionNumber"]->Show();
                     $TextValue = CCToHTML(CCFormatValue($Value, $this->Format, $this->DataType));
                     $Text = $this->HTML ? $this->Values[$i][1] : CCToHTML($this->Values[$i][1]);
                     if ($this->Multiple && is_array($this->Value)) {
                         $Selected = "";
                         foreach ($this->Value as $Val) {
                             if (CCCompareValues($Value, $Val, $this->DataType, $this->Format) == 0) {
                                 $Selected = " " . $CheckedValue;
                                 break;
                             }
                         }
                     } else {
                         $Selected = CCCompareValues($Value, $this->Value, $this->DataType, $this->Format) == 0 ? " " . $CheckedValue : "";
                     }
                     $Tpl->SetVar("Value", $TextValue);
                     $Tpl->SetVar("Check", $Selected);
                     $Tpl->SetVar("Description", $Text);
                     $Tpl->Parse($BlockToParse, true);
                 }
             }
             break;
         case ccsListBox:
             $Options = "";
             if (is_array($this->Values)) {
                 for ($i = 0; $i < sizeof($this->Values); $i++) {
                     $Value = $this->Values[$i][0];
                     $TextValue = CCToHTML(CCFormatValue($Value, $this->Format, $this->DataType));
                     $Text = CCToHTML($this->Values[$i][1]);
                     if ($this->Multiple && is_array($this->Value)) {
                         $Selected = "";
                         foreach ($this->Value as $Val) {
                             if (CCCompareValues($Value, $Val, $this->DataType, $this->Format) == 0) {
                                 $Selected = " " . $SelectedValue;
                                 break;
                             }
                         }
                     } else {
                         $Selected = CCCompareValues($Value, $this->Value, $this->DataType, $this->Format) == 0 ? " " . $SelectedValue : "";
                     }
                     $Options .= $CCSIsXHTML ? "<option value=\"" . $TextValue . "\"" . $Selected . ">" . $Text . "</option>\n" : "<OPTION VALUE=\"" . $TextValue . "\"" . $Selected . ">" . $Text . "</OPTION>\n";
                 }
             }
             $Tpl->SetVar($this->Name . "_Options", $Options);
             $Tpl->ParseSafe($this->BlockName, false);
             break;
         case ccsPageBreak:
             $Tpl->SetVar($this->Name, $this->Text);
     }
 }