PageRenderTime 181ms CodeModel.GetById 78ms app.highlight 89ms RepoModel.GetById 1ms app.codeStats 0ms

/Common.php

https://bitbucket.org/yourphppro/phpscratchandwin
PHP | 2359 lines | 2233 code | 43 blank | 83 comment | 89 complexity | f1a14e75723a8867d7aae4d93243e2aa MD5 | raw file

Large files files are truncated, but you can click here to view the full file

   1<?php
   2/*
   3##############################################################################
   4# PHP Scratch And Win                                           Version 4.04 #
   5# Copyright 2012                                          www.YourPHPPro.com #
   6#                                                                            #
   7# For questions concerning licensing, please read license.txt                #
   8##############################################################################
   9*/
  10
  11include(RelativePath . "/config.php");
  12
  13// Define version number
  14define ("phpScratchAndWin_VersionNumber", "4.04");
  15
  16//Include Files @0-ED610940
  17include(RelativePath . "/Classes.php");
  18include(RelativePath . "/db_adapter.php");
  19//End Include Files
  20
  21//Connection Settings @0-FAEC1DEB
  22$CCConnectionSettings = array (
  23    "Connection" => array(
  24        "Type" => "MySQL",
  25        "DBLib" => "MySQL",
  26        "Database" => "" . CONSTANT("phpScratchAndWin_Database") . "",
  27        "Host" => "" . CONSTANT("phpScratchAndWin_Server") . "",
  28        "Port" => "",
  29        "User" => "" . CONSTANT("phpScratchAndWin_Username") . "",
  30        "Password" => "" . CONSTANT("phpScratchAndWin_Password") . "",
  31        "Persistent" => true,
  32        "DateFormat" => array("yyyy", "-", "mm", "-", "dd", " ", "HH", ":", "nn", ":", "ss"),
  33        "BooleanFormat" => array("Y", "N", ""),
  34        "Uppercase" => false
  35    )
  36);
  37//End Connection Settings
  38
  39//Initialize Common Variables @0-A81EBFE9
  40$PHPVersion = explode(".",  phpversion());
  41if (($PHPVersion[0] < 4) || ($PHPVersion[0] == 4  && $PHPVersion[1] < 1)) {
  42    echo "Sorry. This program requires PHP 4.1 and above to run. You may upgrade your php at <a href='http://www.php.net/downloads.php'>http://www.php.net/downloads.php</a>";
  43    exit;
  44}
  45if (CCGetUserAddr() != $_SERVER["REMOTE_ADDR"]) { CCLogoutUser(); }
  46
  47define("TemplatePath", RelativePath);
  48define("ServerURL", ((isset($_SERVER["HTTPS"]) && strtolower($_SERVER["HTTPS"]) == "on") ? "https://" : "http://" ). preg_replace("/:\d+$/", "", $_SERVER["HTTP_HOST"] ? $_SERVER["HTTP_HOST"] : $_SERVER["SERVER_NAME"]) . ($_SERVER["SERVER_PORT"] != 80 ? ":" . $_SERVER["SERVER_PORT"] : "") . substr($_SERVER["PHP_SELF"], 0, strlen($_SERVER["PHP_SELF"]) - strlen(PathToCurrentPage . FileName)) . "/");
  49define("SecureURL", "");
  50
  51$FileEncoding = "";
  52$CCSIsXHTML = false;
  53$CCSUseAmp = false;
  54$CipherBox = array();
  55$CipherKey = array();
  56$CCSLocales = new clsLocales(RelativePath);
  57$CCSLocales->AddLocale("en", Array("en", "US", array("Y", "N", ""), 2, ".", ",", array("January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"), array("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"), array("Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"), array("Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"), array("S", "M", "T", "W", "T", "F", "S"), array("m", "/", "d", "/", "yyyy"), array("dddd", ", ", "mmmm", " ", "dd", ", ", "yyyy"), array("h", ":", "nn", " ", "tt"), array("h", ":", "nn", ":", "ss", " ", "tt"), "AM", "PM", 0, false, "", "windows-1252", "CP1252", array(1, 7)));
  58$CCSLocales->DefaultLocale = strtolower("en");
  59$CCSLocales->Init();
  60$Charset = "";
  61
  62if ($PHPLocale = $CCSLocales->GetFormatInfo("PHPLocale"))
  63    setlocale(LC_ALL, $PHPLocale);
  64CCConvertDataArrays();
  65$CCProjectStyle = "Gourd";
  66$CCProjectDesign = "";
  67CCSelectProjectStyle();
  68CCSelectProjectDesign();
  69//for compatibility
  70$ShortWeekdays = $CCSLocales->GetFormatInfo("WeekdayShortNames");
  71$Weekdays = $CCSLocales->GetFormatInfo("WeekdayNames");
  72$ShortMonths =  $CCSLocales->GetFormatInfo("MonthShortNames");
  73$Months = $CCSLocales->GetFormatInfo("MonthNames");
  74
  75define("ccsInteger", 1);
  76define("ccsFloat", 2);
  77define("ccsSingle", ccsFloat); //alias
  78define("ccsText", 3);
  79define("ccsDate", 4);
  80define("ccsBoolean", 5);
  81define("ccsMemo", 6);
  82
  83define("ccsGet", 1);
  84define("ccsPost", 2);
  85
  86define("ccsTimestamp", 0);
  87define("ccsYear", 1);
  88define("ccsMonth", 2);
  89define("ccsDay", 3);
  90define("ccsHour", 4);
  91define("ccsMinute", 5);
  92define("ccsSecond", 6);
  93define("ccsMilliSecond", 7);
  94define("ccsAmPm", 8);
  95define("ccsShortMonth", 9);
  96define("ccsFullMonth", 10);
  97define("ccsWeek", 11);
  98define("ccsGMT", 12);
  99define("ccsAppropriateYear", 13);
 100$CCSDesign = "";
 101define("CCS_ENCRYPTION_KEY_FOR_COOKIE", '85432b8x595h73lU');
 102
 103$DefaultDateFormat = array("mm", "/", "dd", "/", "yyyy");
 104
 105$MainPage = new clsMainPage();
 106//End Initialize Common Variables
 107
 108//Connection Connection Class @-282545EC
 109class clsDBConnection extends DB_Adapter
 110{
 111    function clsDBConnection()
 112    {
 113        $this->Initialize();
 114    }
 115
 116    function Initialize()
 117    {
 118        global $CCConnectionSettings;
 119        $this->SetProvider($CCConnectionSettings["Connection"]);
 120        parent::Initialize();
 121        $this->DateLeftDelimiter = "'";
 122        $this->DateRightDelimiter = "'";
 123    }
 124
 125    function OptimizeSQL($SQL)
 126    {
 127        $PageSize = (int) $this->PageSize;
 128        if (!$PageSize) return $SQL;
 129        $Page = $this->AbsolutePage ? (int) $this->AbsolutePage : 1;
 130        if (strcmp($this->RecordsCount, "CCS not counted"))
 131            $SQL .= (" LIMIT " . (($Page - 1) * $PageSize) . "," . $PageSize);
 132        else
 133            $SQL .= (" LIMIT " . (($Page - 1) * $PageSize) . "," . ($PageSize + 1));
 134        return $SQL;
 135    }
 136
 137}
 138//End Connection Connection Class
 139
 140
 141//CCToHTML @0-93F44B0D
 142function CCToHTML($Value)
 143{
 144  return htmlspecialchars($Value);
 145}
 146//End CCToHTML
 147
 148//CCToURL @0-88FAFE26
 149function CCToURL($Value)
 150{
 151  return urlencode($Value);
 152}
 153//End CCToURL
 154
 155//CCGetEvent @0-7AE506F3
 156function CCGetEvent($events, $event_name, & $sender)
 157{
 158  $result = true;
 159  $function_name = (is_array($events) && isset($events[$event_name])) ? $events[$event_name] : "";
 160  if($function_name && function_exists($function_name))
 161    $result = call_user_func_array($function_name, array(& $sender));
 162  return $result;
 163}
 164//End CCGetEvent
 165
 166//CCGetParentContainer @0-0CD41DEB
 167function & CCGetParentContainer(& $object)
 168{
 169  $i = & $object;
 170  while ($i && !($i->ComponentType == "Page" || $i->ComponentType == "IncludablePage" || $i->ComponentType == "Directory" || $i->ComponentType == "Path" || $i->ComponentType == "EditableGrid" || $i->ComponentType == "Grid" || $i->ComponentType == "Record" || $i->ComponentType == "Report" || $i->ComponentType == "Calendar"))
 171    $i = & $i->Parent;
 172  return $i;
 173}
 174//End CCGetParentContainer
 175
 176//CCGetMasterPagePath @0-1C2548FD
 177function CCGetMasterPagePath(& $object) {
 178  $i = & $object;
 179  while ($i && !(isset($i->MasterPage) && $i->MasterPage != null)) {
 180    $i = & $i->Parent;
 181  }
 182  return (isset($i->MasterPage)) ? $i->PathToCurrentPage : "";
 183}
 184//End CCGetMasterPagePath
 185
 186//CCGetParentPage @0-AD47469D
 187function & CCGetParentPage(& $object)
 188{
 189  $i = & $object;
 190  while ($i && !($i->ComponentType == "Page" || $i->ComponentType == "IncludablePage"))
 191    $i = & $i->Parent;
 192  return $i;
 193}
 194//End CCGetParentPage
 195
 196//CCGetValueHTML @0-B8903145
 197function CCGetValueHTML(&$db, $fieldname)
 198{
 199  return CCToHTML($db->f($fieldname));
 200}
 201//End CCGetValueHTML
 202
 203//CCGetValue @0-36EF6396
 204function CCGetValue(&$db, $fieldname)
 205{
 206  return $db->f($fieldname);
 207}
 208//End CCGetValue
 209
 210//CCGetSession @0-F4650E55
 211function CCGetSession($parameter_name, $default_value = "")
 212{
 213    session_start();
 214    $result = isset($_SESSION[$parameter_name]) ? $_SESSION[$parameter_name] : $default_value;
 215    session_write_close();
 216    return $result;
 217}
 218//End CCGetSession
 219
 220//CCSetSession @0-025730A6
 221function CCSetSession($param_name, $param_value)
 222{
 223    session_start();
 224    $_SESSION[$param_name] = $param_value;
 225    session_write_close();
 226}
 227//End CCSetSession
 228
 229//CCGetCookie @0-6B04B9B5
 230function CCGetCookie($parameter_name)
 231{
 232    return isset($_COOKIE[$parameter_name]) ? $_COOKIE[$parameter_name] : "";
 233}
 234//End CCGetCookie
 235
 236//CCSetCookie @0-1968C877
 237function CCSetCookie($parameter_name, $param_value, $expired = -1, $path = "/", $domain = "", $secured = false, $http_only = false)
 238{
 239  if ($expired == -1)
 240    $expired = time() + 3600 * 24 * 366;
 241  elseif ($expired && $expired < time())
 242    $expired = time() + $expired;
 243  setcookie ($parameter_name, $param_value, $expired, $path, $domain, $secured, $http_only);
 244}
 245//End CCSetCookie
 246
 247//CCStrip @0-E1370054
 248function CCStrip($value)
 249{
 250  if(get_magic_quotes_gpc() != 0)
 251  {
 252    if(is_array($value))
 253      foreach($value as $key=>$val)
 254        $value[$key] = stripslashes($val);
 255    else
 256      $value = stripslashes($value);
 257  }
 258  return $value;
 259}
 260//End CCStrip
 261
 262//CCGetParam @0-3BB7E2D4
 263function CCGetParam($parameter_name, $default_value = "")
 264{
 265    $parameter_value = "";
 266    if(isset($_POST[$parameter_name]))
 267        $parameter_value = CCStrip($_POST[$parameter_name]);
 268    else if(isset($_GET[$parameter_name]))
 269        $parameter_value = CCStrip($_GET[$parameter_name]);
 270    else
 271        $parameter_value = $default_value;
 272    return $parameter_value;
 273}
 274//End CCGetParam
 275
 276//CCGetParamStartsWith @0-4BE76C1A
 277function CCGetParamStartsWith($prefix)
 278{
 279    $parameter_name = "";
 280    foreach($_POST as $key => $value) {
 281        if(preg_match ("/^" . $prefix . "_\d+$/i", $key)) {
 282            $parameter_name = $key;
 283            break;
 284        }
 285    }
 286    if($parameter_name === "") {
 287        foreach($_GET as $key => $value) {
 288            if(preg_match ("/^" . $prefix . "_\d+$/i", $key)) {
 289                $parameter_name = $key;
 290                break;
 291            }
 292        }
 293    }
 294    return $parameter_name;
 295}
 296//End CCGetParamStartsWith
 297
 298//CCGetFromPost @0-393586D2
 299function CCGetFromPost($parameter_name, $default_value = "")
 300{
 301    return isset($_POST[$parameter_name]) ? CCStrip($_POST[$parameter_name]) : $default_value;
 302}
 303//End CCGetFromPost
 304
 305//CCGetFromGet @0-90CF1921
 306function CCGetFromGet($parameter_name, $default_value = "")
 307{
 308    return isset($_GET[$parameter_name]) ? CCStrip($_GET[$parameter_name]) : $default_value;
 309}
 310//End CCGetFromGet
 311
 312//CCToSQL @0-422F5B92
 313function CCToSQL($Value, $ValueType)
 314{
 315  if(!strlen($Value))
 316  {
 317    return "NULL";
 318  }
 319  else
 320  {
 321    if($ValueType == ccsInteger || $ValueType == ccsFloat)
 322    {
 323      return doubleval(str_replace(",", ".", $Value));
 324    }
 325    else
 326    {
 327      return "'" . str_replace("'", "''", $Value) . "'";
 328    }
 329  }
 330}
 331//End CCToSQL
 332
 333//CCDLookUp @0-AD41DC8E
 334function CCDLookUp($field_name, $table_name, $where_condition, &$db)
 335{
 336  $sql = "SELECT " . $field_name . ($table_name ? " FROM " . $table_name : "") . ($where_condition ? " WHERE " . $where_condition : "");
 337  return CCGetDBValue($sql, $db);
 338}
 339//End CCDLookUp
 340
 341//CCGetDBValue @0-6DCF4DC4
 342function CCGetDBValue($sql, &$db)
 343{
 344  $db->query($sql);
 345  $dbvalue = $db->next_record() ? $db->f(0) : "";
 346  return $dbvalue;
 347}
 348//End CCGetDBValue
 349
 350//CCGetListValues @0-74F64ABA
 351function CCGetListValues(&$db, $sql, $where = "", $order_by = "", $bound_column = "", $text_column = "", $dbformat = "", $datatype = "", $errorclass = "", $fieldname = "", $DSType = dsSQL)
 352{
 353    $errors = new clsErrors();
 354    $values = "";
 355    if(!strlen($bound_column))
 356        $bound_column = 0;
 357    if(!strlen($text_column))
 358        $text_column = 1;
 359    if ($DSType == dsProcedure && $db->DB == "MSSQL" && count($db->Binds))
 360        $db->execute($sql);
 361    else
 362        $db->query(CCBuildSQL($sql, $where, $order_by));
 363    if ($db->next_record())
 364    {
 365        do
 366        {
 367            $bound_column_value = $db->f($bound_column);
 368            if($bound_column_value === false) {$bound_column_value = "";}
 369            list($bound_column_value, $errors) = CCParseValue($bound_column_value, $dbformat, $datatype, $errors, $fieldname);
 370            $values[] = array($bound_column_value, $db->f($text_column));
 371        } while ($db->next_record());
 372    }
 373    if (is_string($errorclass)) {
 374        return $values;
 375    } else {
 376        $errorclass->AddErrors($errors);
 377        return array($values, $errorclass);
 378    }
 379}
 380
 381//End CCGetListValues
 382
 383//CCParseValue @0-DCA2A586
 384  function CCParseValue($ParsingValue, $Format, $DataType, $ErrorClass, $FieldName, $isDBFormat = false)
 385  {
 386    global $CCSLocales;
 387    $errors = new clsErrors();
 388    $varResult = "";
 389    if(CCCheckValue($ParsingValue, $DataType))
 390      $varResult = $ParsingValue;
 391    else if(strlen($ParsingValue))
 392    {
 393      switch ($DataType)
 394      {
 395        case ccsDate:
 396          $DateValidation = true;
 397          if (CCValidateDateMask($ParsingValue, $Format)) {
 398            $varResult = CCParseDate($ParsingValue, $Format);
 399            if(!CCValidateDate($varResult)) {
 400              $DateValidation = false;
 401              $varResult = "";
 402            }
 403          } else {
 404            $DateValidation = false;
 405          }
 406          if(!$DateValidation && $ErrorClass->Count() == 0) {
 407            if (is_array($Format)) {
 408              $FormatString = join("", $Format);
 409            } else {
 410              $FormatString = $Format;
 411            }
 412            $errors->addError($CCSLocales->GetText('CCS_IncorrectFormat', array($FieldName, $FormatString)));
 413          }
 414          break;
 415        case ccsBoolean:
 416          if (CCValidateBoolean($ParsingValue, $Format)) {
 417            $varResult = CCParseBoolean($ParsingValue, $Format);
 418          } else if($ErrorClass->Count() == 0) {
 419            if (is_array($Format)) {
 420              $FormatString = CCGetBooleanFormat($Format);
 421            } else {
 422              $FormatString = $Format;
 423            }
 424            $errors->addError($CCSLocales->GetText('CCS_IncorrectFormat', array($FieldName, $FormatString)));
 425          }
 426          break;
 427        case ccsInteger:
 428          if (CCValidateNumber($ParsingValue, $Format, $isDBFormat))
 429            $varResult = CCParseInteger($ParsingValue, $Format, $isDBFormat);
 430          else if($ErrorClass->Count() == 0)
 431            $errors->addError($CCSLocales->GetText('CCS_IncorrectFormat', array($FieldName, $Format)));
 432          break;
 433        case ccsFloat:
 434          if (CCValidateNumber($ParsingValue, $Format, $isDBFormat))
 435            $varResult = CCParseFloat($ParsingValue, $Format, $isDBFormat);
 436          else if($ErrorClass->Count() == 0)
 437            $errors->addError($CCSLocales->GetText('CCS_IncorrectFormat', array($FieldName, $Format)));
 438          break;
 439        case ccsText:
 440        case ccsMemo:
 441          $varResult = strval($ParsingValue);
 442          break;
 443      }
 444    }
 445  if (is_string($ErrorClass)) {
 446    return $varResult;
 447  } else {
 448    $ErrorClass->AddErrors($errors);
 449    return array($varResult, $ErrorClass);
 450  }
 451}
 452
 453//End CCParseValue
 454
 455//CCFormatValue @0-A384E38C
 456  function CCFormatValue($Value, $Format, $DataType, $isDBFormat = false)
 457  {
 458    switch($DataType)
 459    {
 460      case ccsDate:
 461        $Value = CCFormatDate($Value, $Format);
 462        break;
 463      case ccsBoolean:
 464        $Value = CCFormatBoolean($Value, $Format);
 465        break;
 466      case ccsInteger:
 467      case ccsFloat:
 468      case ccsSingle:
 469        $Value = CCFormatNumber($Value, $Format, $DataType, $isDBFormat);
 470        break;
 471      case ccsText:
 472      case ccsMemo:
 473        $Value = strval($Value);
 474        break;
 475    }
 476    return $Value;
 477  }
 478
 479//End CCFormatValue
 480
 481//CCBuildSQL @0-9C1D4901
 482function CCBuildSQL($sql, $where = "", $order_by = "")
 483{
 484    if (!$sql) return "";
 485    if(strlen($where)) $where = " WHERE " . $where;
 486    if(strlen($order_by)) $order_by = " ORDER BY " . $order_by;
 487    if(stristr($sql,"{SQL_Where}") || stristr($sql,"{SQL_OrderBy}")) {
 488        $sql = str_replace("{SQL_Where}", $where, $sql);
 489        $sql = str_replace("{SQL_OrderBy}", $order_by, $sql);
 490        return $sql;
 491    }
 492    $sql .= $where . $order_by;
 493    return $sql;
 494}
 495
 496//End CCBuildSQL
 497
 498//CCBuildInsert @0-6433D327
 499function CCBuildInsert($table, & $Fields, & $Connection)
 500{
 501    $fields = array();
 502    $values = array();
 503    foreach ($Fields as $Field) {
 504        if (!isset($Field["OmitIfEmpty"]) || !$Field["OmitIfEmpty"] || !is_null($Field["Value"])) {
 505            $fields[] = $Field["Name"];
 506            if ($Field["DataType"] == ccsMemo && ($Connection->DB == "Oracle" || $Connection->DB == "OracleOCI")) {
 507                $values[] = ":" . $Field["Name"];
 508                $Connection->Bind($Field["Name"], $Field["Value"], -1);
 509            }else{
 510                $values[] = $Connection->ToSQL($Field["Value"], $Field["DataType"]);
 511            }
 512        }
 513    }
 514  return count($fields) ? "INSERT INTO " . $table . " (" . implode(", ", $fields) . ") VALUES(" . implode(", ", $values) . ")" : "";
 515
 516}
 517
 518//End CCBuildInsert
 519
 520//CCBuildUpdate @0-E2594C39
 521function CCBuildUpdate($table, & $Fields, & $Connection)
 522{
 523    $pairs = array();
 524    foreach ($Fields as $Field) {
 525        if (!isset($Field["OmitIfEmpty"]) || !$Field["OmitIfEmpty"] || !is_null($Field["Value"])) {
 526            if ($Field["DataType"] == ccsMemo && ($Connection->DB == "Oracle" || $Connection->DB == "OracleOCI")) {
 527                $value = ":" . $Field["Name"];
 528                $Connection->Bind($Field["Name"], $Field["Value"], -1);
 529            }else{
 530                $value = $Connection->ToSQL($Field["Value"], $Field["DataType"]);
 531            }
 532            $pairs[] = $Field["Name"] . " = " . $value;
 533        }
 534    }
 535  return count($pairs) ? "UPDATE " . $table . " SET " . implode(", ", $pairs) : "";
 536
 537}
 538
 539//End CCBuildUpdate
 540
 541//CCGetRequestParam @0-AC78F6A0
 542function CCGetRequestParam($ParameterName, $Method, $DefaultValue = "")
 543{
 544    $ParameterValue = $DefaultValue;
 545    if($Method == ccsGet && isset($_GET[$ParameterName]))
 546        $ParameterValue = CCStrip($_GET[$ParameterName]);
 547    else if($Method == ccsPost && isset($_POST[$ParameterName]))
 548        $ParameterValue = CCStrip($_POST[$ParameterName]);
 549    return $ParameterValue;
 550}
 551//End CCGetRequestParam
 552
 553//CCGetQueryString @0-CDA71B06
 554function CCGetQueryString($CollectionName, $RemoveParameters)
 555{
 556    $querystring = "";
 557    $postdata = "";
 558    if($CollectionName == "Form")
 559        $querystring = CCCollectionToString($_POST, $RemoveParameters);
 560    else if($CollectionName == "QueryString")
 561        $querystring = CCCollectionToString($_GET, $RemoveParameters);
 562    else if($CollectionName == "All")
 563    {
 564        $querystring = CCCollectionToString($_GET, $RemoveParameters);
 565        $postdata = CCCollectionToString($_POST, $RemoveParameters);
 566        if(strlen($postdata) > 0 && strlen($querystring) > 0)
 567            $querystring .= "&" . $postdata;
 568        else
 569            $querystring .= $postdata;
 570    }
 571    else
 572        die("1050: Common Functions. CCGetQueryString Function. " .
 573            "The CollectionName contains an illegal value.");
 574    return $querystring;
 575}
 576//End CCGetQueryString
 577
 578//CCCollectionToString @0-F45EFAFC
 579function CCCollectionToString($ParametersCollection, $RemoveParameters)
 580{
 581  $Result = "";
 582  if(is_array($ParametersCollection))
 583  {
 584    reset($ParametersCollection);
 585    foreach($ParametersCollection as $ItemName => $ItemValues)
 586    {
 587      $Remove = false;
 588      if(is_array($RemoveParameters))
 589      {
 590        foreach($RemoveParameters as $key => $val)
 591        {
 592          if($val == $ItemName)
 593          {
 594            $Remove = true;
 595            break;
 596          }
 597        }
 598      }
 599      if(!$Remove)
 600      {
 601        if(is_array($ItemValues))
 602          for($J = 0; $J < sizeof($ItemValues); $J++)
 603            $Result .= "&" . urlencode(CCStrip($ItemName)) . "[]=" . urlencode(CCStrip($ItemValues[$J]));
 604        else
 605           $Result .= "&" . urlencode(CCStrip($ItemName)) . "=" . urlencode(CCStrip($ItemValues));
 606      }
 607    }
 608  }
 609
 610  if(strlen($Result) > 0)
 611    $Result = substr($Result, 1);
 612  return $Result;
 613}
 614//End CCCollectionToString
 615
 616//CCMergeQueryStrings @0-5BB2EE59
 617function CCMergeQueryStrings($LeftQueryString, $RightQueryString = "")
 618{
 619  $QueryString = $LeftQueryString;
 620  if($QueryString === "")
 621    $QueryString = $RightQueryString;
 622  else if($RightQueryString !== "")
 623    $QueryString .= '&' . $RightQueryString;
 624
 625  return $QueryString;
 626}
 627//End CCMergeQueryStrings
 628
 629//CCAddParam @0-5D96DB6B
 630function CCAddParam($querystring, $ParameterName, $ParameterValue)
 631{
 632    $queryStr = null; $paramStr = null;
 633    if (strpos($querystring, '?') !== false)
 634        list($queryStr, $paramStr) = explode('?', $querystring);
 635    else if (strpos($querystring, '=') !== false)
 636        $paramStr = $querystring;
 637    else
 638        $queryStr = $querystring;
 639    $paramStr = $paramStr ? '&' . $paramStr : '';
 640    $paramStr = preg_replace ('/&' . $ParameterName . '(\[\])?=[^&]*/', '', $paramStr);
 641    if(is_array($ParameterValue)) {
 642        foreach($ParameterValue as $key => $val) {
 643            $paramStr .= "&" . urlencode($ParameterName) . "[]=" . urlencode($val);
 644        }
 645    } else {
 646        $paramStr .= "&" . urlencode($ParameterName) . "=" . urlencode($ParameterValue);
 647    }
 648    $paramStr = ltrim($paramStr, '&');
 649    return $queryStr ? $queryStr . '?' . $paramStr : $paramStr;
 650}
 651//End CCAddParam
 652
 653//CCRemoveParam @0-8DE77C37
 654function CCRemoveParam($querystring, $ParameterName)
 655{
 656$queryStr = null; $paramStr = null;
 657    if (strpos($querystring, '?') !== false)
 658        list($queryStr, $paramStr) = explode('?', $querystring);
 659    else if (strpos($querystring, '=') !== false)
 660        $paramStr = $querystring;
 661    else
 662        $queryStr = $querystring;
 663    $paramStr = $paramStr ? '&' . $paramStr : '';
 664    $paramStr = preg_replace ('/&' . $ParameterName . '(\[\])?=[^&]*/', '', $paramStr);
 665    $paramStr = ltrim($paramStr, '&');
 666    return $queryStr ? $queryStr . '?' . $paramStr : $paramStr;
 667}
 668//End CCRemoveParam
 669
 670//CCGetOrder @0-27B4AC18
 671function CCGetOrder($DefaultSorting, $SorterName, $SorterDirection, $MapArray)
 672{
 673  if(is_array($MapArray) && isset($MapArray[$SorterName]))
 674    if(strtoupper($SorterDirection) == "DESC")
 675      $OrderValue = ($MapArray[$SorterName][1] != "") ? $MapArray[$SorterName][1] : $MapArray[$SorterName][0] . " DESC";
 676    else
 677      $OrderValue = $MapArray[$SorterName][0];
 678  else
 679    $OrderValue = $DefaultSorting;
 680
 681  return $OrderValue;
 682}
 683//End CCGetOrder
 684
 685//CCGetDateArray @0-37E8EF24
 686function CCGetDateArray($timestamp = "")
 687{
 688  $DateArray = array(0, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
 689  if(!strlen($timestamp) && !is_int($timestamp)) {
 690    $timestamp = time();
 691  }
 692
 693  $DateArray[ccsTimestamp] = $timestamp;
 694  $DateArray[ccsYear] = @date("Y", $timestamp);
 695  $DateArray[ccsMonth] = @date("n", $timestamp);
 696  $DateArray[ccsDay] = @date("j", $timestamp);
 697  $DateArray[ccsHour] = @date("G", $timestamp);
 698  $DateArray[ccsMinute] = @date("i", $timestamp);
 699  $DateArray[ccsSecond] = @date("s", $timestamp);
 700
 701  return $DateArray;
 702}
 703//End CCGetDateArray
 704
 705//CCFormatDate @0-5FD7EA36
 706function CCFormatDate($DateToFormat, $FormatMask)
 707{
 708
 709  global $CCSLocales;
 710
 711  if(!is_array($DateToFormat) && strlen($DateToFormat))
 712    $DateToFormat = CCGetDateArray($DateToFormat);
 713
 714  if(is_array($FormatMask) && is_array($DateToFormat))
 715  {
 716    $WeekdayNames = $CCSLocales->GetFormatInfo("WeekdayNames");
 717    $WeekdayShortNames = $CCSLocales->GetFormatInfo("WeekdayShortNames");
 718    $WeekdayNarrowNames = $CCSLocales->GetFormatInfo("WeekdayNarrowNames");
 719    $MonthNames = $CCSLocales->GetFormatInfo("MonthNames");
 720    $MonthShortNames = $CCSLocales->GetFormatInfo("MonthShortNames");
 721
 722    $FormattedDate = "";
 723    for($i = 0; $i < sizeof($FormatMask); $i++)
 724    {
 725      switch ($FormatMask[$i])
 726      {
 727        case "GeneralDate":
 728          $FormattedDate .= CCFormatDate($DateToFormat, $CCSLocales->GetFormatInfo("GeneralDate"));
 729          break;
 730        case "LongDate":
 731          $FormattedDate .= CCFormatDate($DateToFormat, $CCSLocales->GetFormatInfo("LongDate"));
 732          break;
 733        case "ShortDate":
 734          $FormattedDate .= CCFormatDate($DateToFormat, $CCSLocales->GetFormatInfo("ShortDate"));
 735          break;
 736        case "LongTime":
 737          $FormattedDate .= CCFormatDate($DateToFormat, $CCSLocales->GetFormatInfo("LongTime"));
 738          break;
 739        case "ShortTime":
 740          $FormattedDate .= CCFormatDate($DateToFormat, $CCSLocales->GetFormatInfo("ShortTime"));
 741          break;
 742        case "d":
 743          $FormattedDate .= $DateToFormat[ccsDay];
 744          break;
 745        case "dd":
 746          $FormattedDate .= sprintf("%02d", $DateToFormat[ccsDay]);
 747          break;
 748        case "ddd":
 749          $FormattedDate .= $WeekdayShortNames[CCDayOfWeek($DateToFormat) - 1];
 750          break;
 751        case "dddd":
 752          $FormattedDate .= $WeekdayNames[CCDayOfWeek($DateToFormat) - 1];
 753          break;
 754        case "wi":
 755          $FormattedDate .= $WeekdayNarrowNames[CCDayOfWeek($DateToFormat) - 1];
 756          break;
 757        case "w":
 758          $FormattedDate .= CCDayOfWeek($DateToFormat);
 759          break;
 760        case "ww":
 761          $FormattedDate .= ceil((7 + date("z", $DateToFormat[ccsTimestamp]) - date("w", $DateToFormat[ccsTimestamp])) / 7);
 762          break;
 763        case "m":
 764          $FormattedDate .= $DateToFormat[ccsMonth];
 765          break;
 766        case "mm":
 767          $FormattedDate .= sprintf("%02d", $DateToFormat[ccsMonth]);
 768          break;
 769        case "mmm":
 770          $FormattedDate .= $MonthShortNames[$DateToFormat[ccsMonth] - 1];
 771          break;
 772        case "mmmm":
 773          $FormattedDate .= $MonthNames[$DateToFormat[ccsMonth] - 1];
 774          break;
 775        case "q":
 776          $FormattedDate .= ceil($DateToFormat[ccsMonth] / 3);
 777          break;
 778        case "y":
 779          $FormattedDate .= CCDayOfYear($DateToFormat);
 780          break;
 781        case "yy":
 782          $FormattedDate .= substr($DateToFormat[ccsYear], 2);
 783          break;
 784        case "yyyy":
 785          $FormattedDate .= sprintf("%04d", $DateToFormat[ccsYear]);
 786          break;
 787        case "h":
 788          $FormattedDate .= ($DateToFormat[ccsHour] % 12 == 0 ) ? 12 : $DateToFormat[ccsHour] % 12;
 789          break;
 790        case "hh":
 791          $FormattedDate .= sprintf("%02d", $DateToFormat[ccsHour] % 12 == 0 ? 12 : $DateToFormat[ccsHour] % 12);
 792          break;
 793        case "H":
 794          $FormattedDate .= $DateToFormat[ccsHour];
 795          break;
 796        case "HH":
 797          $FormattedDate .= sprintf("%02d", $DateToFormat[ccsHour]);
 798          break;
 799        case "n":
 800          $FormattedDate .= $DateToFormat[ccsMinute];
 801          break;
 802        case "nn":
 803          $FormattedDate .= sprintf("%02d", $DateToFormat[ccsMinute]);
 804          break;
 805        case "s":
 806          $FormattedDate .= $DateToFormat[ccsSecond];
 807          break;
 808        case "ss":
 809          $FormattedDate .= sprintf("%02d", $DateToFormat[ccsSecond]);
 810          break;
 811        case "S":
 812          $FormattedDate .= $DateToFormat[ccsMilliSecond] + 0;
 813          break;
 814        case "AM/PM":
 815        case "A/P":
 816          $FormattedDate .=  $DateToFormat[ccsHour] < 12 ? "AM" : "PM";
 817          break;
 818        case "am/pm":
 819        case "a/p":
 820          $FormattedDate .=  $DateToFormat[ccsHour] < 12 ? "am" : "pm";
 821          break;
 822        case "tt":
 823          $FormattedDate .=  $DateToFormat[ccsHour] < 12 ? $CCSLocales->GetFormatInfo("AMDesignator") : $CCSLocales->GetFormatInfo("PMDesignator");
 824          break;
 825        case "GMT":
 826          if (strlen($DateToFormat[ccsGMT]))
 827            $GMT = intval($DateToFormat[ccsGMT]);
 828          else
 829            $GMT = intval(date("Z", $DateToFormat[ccsTimestamp]) / (60 * 60));
 830          $GMT = sprintf("%02d", $GMT);
 831          $GMT = $GMT > 0 ? "+" . $GMT : $GMT;
 832          $FormattedDate .= $GMT;
 833          break;
 834        default:
 835          $FormattedDate .= $FormatMask[$i];
 836          break;
 837      }
 838    }
 839  }
 840  else
 841  {
 842    $FormattedDate = "";
 843  }
 844  return $FormattedDate;
 845}
 846//End CCFormatDate
 847
 848//CCValidateDate @0-1DFF5582
 849function CCValidateDate($ValidatingDate)
 850{
 851  $IsValid = true;
 852  if(is_array($ValidatingDate))
 853    if (count($ValidatingDate) != 14)
 854      $IsValid = false;
 855    elseif ($ValidatingDate[ccsMonth] != 0 &&
 856      $ValidatingDate[ccsDay] != 0 &&
 857      $ValidatingDate[ccsYear] != 0)
 858      $IsValid = checkdate($ValidatingDate[ccsMonth], $ValidatingDate[ccsDay], $ValidatingDate[ccsYear]);
 859
 860  return $IsValid;
 861}
 862//End CCValidateDate
 863
 864//CCValidateDateMask @0-6A1F5673
 865function CCValidateDateMask($ValidatingDate, $FormatMask)
 866{
 867  $IsValid = true;
 868  if(is_array($FormatMask) && strlen($ValidatingDate))
 869  {
 870    $RegExp = CCGetDateRegExp($FormatMask);
 871    $IsValid = preg_match($RegExp[0], $ValidatingDate, $matches);
 872  }
 873
 874  return $IsValid;
 875}
 876//End CCValidateDateMask
 877
 878//CCParseDate @0-5F189BA0
 879function CCParseDate($ParsingDate, $FormatMask)
 880{
 881  global $CCSLocales;
 882  if(is_array($FormatMask) && strlen($ParsingDate))
 883  {
 884    $DateArray = array(0, "1", "", "1", "", "", "", "", "", "", "", "", "", "");
 885    $RegExp = CCGetDateRegExp($FormatMask);
 886    $IsValid = preg_match($RegExp[0], $ParsingDate, $matches);
 887    for($i = 1; $i < sizeof($matches); $i++)
 888      $DateArray[$RegExp[$i]] = $matches[$i];
 889
 890    if(!$DateArray[ccsMonth] && ($DateArray[ccsFullMonth] || $DateArray[ccsShortMonth]))
 891    {
 892      if($DateArray[ccsFullMonth])
 893        $DateArray[ccsMonth] = CCGetIndex($CCSLocales->GetFormatInfo("MonthNames"), $DateArray[ccsFullMonth], true) + 1;
 894      else if($DateArray[ccsShortMonth])
 895        $DateArray[ccsMonth] = CCGetIndex($CCSLocales->GetFormatInfo("MonthShortNames"), $DateArray[ccsShortMonth], true) + 1;
 896    } else {
 897      $DateArray[ccsMonth] = intval($DateArray[ccsMonth]);
 898    }
 899
 900    if (!$DateArray[ccsMonth])
 901      $DateArray[ccsMonth] = 1;
 902
 903    if(intval($DateArray[ccsDay]) == 0) {
 904      $DateArray[ccsDay] = 1;
 905    } else {
 906      $DateArray[ccsDay] = intval($DateArray[ccsDay]);
 907    }
 908
 909    if ($DateArray[ccsAmPm])
 910      if (strtoupper(substr($DateArray[ccsAmPm], 0, 1)) == "A" || $DateArray[ccsAmPm] == $CCSLocales->GetFormatInfo("AMDesignator"))
 911        $DateArray[ccsHour] = $DateArray[ccsHour] == 12 ? 0 : $DateArray[ccsHour];
 912      elseif ($DateArray[ccsHour] < 12)
 913        $DateArray[ccsHour] += 12;
 914
 915    if(strlen($DateArray[ccsYear]) == 2)
 916      if($DateArray[ccsYear] < 70)
 917        $DateArray[ccsYear] = "20" . $DateArray[ccsYear];
 918      else
 919        $DateArray[ccsYear] = "19" . $DateArray[ccsYear];
 920
 921    if($DateArray[ccsYear] < 1971 && $DateArray[ccsYear] > 0)
 922      $DateArray[ccsAppropriateYear] = $DateArray[ccsYear] + intval((2000 - $DateArray[ccsYear]) / 28) * 28;
 923    else if($DateArray[ccsYear] > 2030)
 924      $DateArray[ccsAppropriateYear] = $DateArray[ccsYear] - intval(($DateArray[ccsYear] - 2000) / 28) * 28;
 925    else
 926      $DateArray[ccsAppropriateYear] = $DateArray[ccsYear];
 927
 928    $DateArray[ccsHour] = intval($DateArray[ccsHour]);
 929    $DateArray[ccsMinute] = intval($DateArray[ccsMinute]);
 930    $DateArray[ccsSecond] = intval($DateArray[ccsSecond]);
 931
 932    $DateArray[ccsTimestamp] = @mktime ($DateArray[ccsHour], $DateArray[ccsMinute], $DateArray[ccsSecond], $DateArray[ccsMonth], $DateArray[ccsDay], $DateArray[ccsAppropriateYear]);
 933    if(!CCValidateDate($DateArray)) $ParsingDate = "";
 934    else $ParsingDate = $DateArray;
 935
 936  }
 937
 938  return $ParsingDate;
 939}
 940//End CCParseDate
 941
 942//CCGetDateRegExp @0-F17A33B6
 943function CCGetDateRegExp($FormatMask)
 944{
 945  global $CCSLocales;
 946  $RegExp = false;
 947  if(is_array($FormatMask))
 948  {
 949    $masks = array(
 950      "d" => array("(\d{1,2})", ccsDay),
 951      "dd" => array("(\d{2})", ccsDay),
 952      "ddd" => array("(" . join("|", $CCSLocales->GetFormatInfo("WeekdayShortNames")) . ")", ccsWeek),
 953      "dddd" => array("(" . join("|", $CCSLocales->GetFormatInfo("WeekdayNames")) . ")", ccsWeek),
 954      "w" => array("\d"), "ww" => array("\d{1,2}"),
 955      "m" => array("(\d{1,2})", ccsMonth), "mm" => array("(\d{2})", ccsMonth),
 956      "mmm" => array("(" . join("|", $CCSLocales->GetFormatInfo("MonthShortNames")) . ")", ccsShortMonth),
 957      "mmmm" => array("(" . join("|", $CCSLocales->GetFormatInfo("MonthNames")) . ")", ccsFullMonth),
 958      "y" => array("\d{1,3}"), "yy" => array("(\d{2})", ccsYear),
 959      "yyyy" => array("(\d{4})", ccsYear), "q" => array("\d"),
 960      "h" => array("(\d{1,2})", ccsHour), "hh" => array("(\d{2})", ccsHour),
 961      "H" => array("(\d{1,2})", ccsHour), "HH" => array("(\d{2})", ccsHour),
 962      "n" => array("(\d{1,2})", ccsMinute), "nn" => array("(\d{2})", ccsMinute),
 963      "s" => array("(\d{1,2})", ccsSecond), "ss" => array("(\d{2})", ccsSecond),
 964      "AM/PM" => array("(AM|PM)", ccsAmPm), "am/pm" => array("(am|pm)", ccsAmPm),
 965      "A/P" => array("(A|P)", ccsAmPm), "a/p" => array("(a|p)", ccsAmPm),
 966      "a/p" => array("(a|p)", ccsAmPm),
 967      "tt" => array("(" . $CCSLocales->GetFormatInfo("AMDesignator") . "|" . $CCSLocales->GetFormatInfo("PMDesignator") . ")", ccsAmPm),
 968      "GMT" => array("([\+\-]\d{1,2})", ccsGMT),
 969      "S" => array("(\d{1,6})", ccsMilliSecond)
 970    );
 971    $RegExp[0] = "";
 972    $RegExpIndex = 1;
 973    $is_date = false; $is_datetime = false;
 974    for($i = 0; $i < sizeof($FormatMask); $i++)
 975    {
 976      if ($FormatMask[$i] == "GeneralDate")
 977      {
 978        $reg = CCGetDateRegExp($CCSLocales->GetFormatInfo("GeneralDate"));
 979        $RegExp[0] .= substr($reg[0], 2, strlen($reg[0]) - 5);
 980        $is_datetime = true;
 981        for ($j=1; $j < sizeof($reg); $j++) {
 982          $RegExp[$RegExpIndex++] = $reg[$j];
 983        }
 984      }
 985      else if ($FormatMask[$i] == "LongDate" || $FormatMask[$i] == "ShortDate")
 986      {
 987        $reg = CCGetDateRegExp($CCSLocales->GetFormatInfo($FormatMask[$i]));
 988        $RegExp[0] .= substr($reg[0], 2, strlen($reg[0]) - 5);
 989        $is_date = true;
 990        for ($j=1; $j < sizeof($reg); $j++) {
 991          $RegExp[$RegExpIndex++] = $reg[$j];
 992        }
 993      }
 994      else if ($FormatMask[$i] == "LongTime" || $FormatMask[$i] == "ShortTime")
 995      {
 996        $reg = CCGetDateRegExp($CCSLocales->GetFormatInfo($FormatMask[$i]));
 997        $RegExp[0] .= substr($reg[0], 2, strlen($reg[0]) - 5);
 998        for ($j=1; $j < sizeof($reg); $j++) {
 999          $RegExp[$RegExpIndex++] = $reg[$j];
1000        }
1001      }
1002      else if(isset($masks[$FormatMask[$i]]))
1003      {
1004        $MaskArray = $masks[$FormatMask[$i]];
1005        if($i == 0 && ($MaskArray[1] == ccsYear || $MaskArray[1] == ccsMonth
1006          || $MaskArray[1] == ccsFullMonth || $MaskArray[1] == ccsWeek || $MaskArray[1] == ccsDay))
1007          $is_date = true;
1008        else if($is_date && !$is_datetime && $MaskArray[1] == ccsHour)
1009          $is_datetime = true;
1010        $RegExp[0] .= $MaskArray[0];
1011        if($is_datetime) $RegExp[0] .= "?";
1012        for($j = 1; $j < sizeof($MaskArray); $j++)
1013          $RegExp[$RegExpIndex++] = $MaskArray[$j];
1014      }
1015      else
1016      {
1017        if($is_date && !$is_datetime && $i < sizeof($FormatMask) && $masks[$FormatMask[$i + 1]][1] == ccsHour)
1018          $is_datetime = true;
1019        $RegExp[0] .= CCAddEscape($FormatMask[$i]);
1020        if($is_datetime) $RegExp[0] .= "?";
1021      }
1022    }
1023    $RegExp[0] = str_replace(" ", "\s*", $RegExp[0]);
1024    $RegExp[0] = "/^" . $RegExp[0] . "$/i";
1025  }
1026
1027  return $RegExp;
1028}
1029//End CCGetDateRegExp
1030
1031//CCAddEscape @0-06D50C27
1032function CCAddEscape($FormatMask)
1033{
1034  $meta_characters = array("\\", "^", "\$", ".", "[", "|", "(", ")", "?", "*", "+", "{", "-", "]", "/");
1035  for($i = 0; $i < sizeof($meta_characters); $i++)
1036    $FormatMask = str_replace($meta_characters[$i], "\\" . $meta_characters[$i], $FormatMask);
1037  return $FormatMask;
1038}
1039//End CCAddEscape
1040
1041//CCGetIndex @0-8DB8E12C
1042function CCGetIndex($ArrayValues, $Value, $IgnoreCase = true)
1043{
1044  $index = false;
1045  for($i = 0; $i < sizeof($ArrayValues); $i++)
1046  {
1047    if(($IgnoreCase && strtoupper($ArrayValues[$i]) == strtoupper($Value)) || ($ArrayValues[$i] == $Value))
1048    {
1049      $index = $i;
1050      break;
1051    }
1052  }
1053  return $index;
1054}
1055//End CCGetIndex
1056
1057//CCFormatNumber @0-ECA37772
1058function CCFormatNumber($NumberToFormat, $FormatArray, $DataType = ccsFloat, $isDBFormat = false)
1059{
1060  global $CCSLocales;
1061  global $CCSIsXHTML;
1062  $Result = "";
1063  if(is_array($FormatArray) && strlen($NumberToFormat))
1064  {
1065    $IsExtendedFormat = $FormatArray[0];
1066    $IsNegative = ($NumberToFormat < 0);
1067    $NumberToFormat = abs($NumberToFormat);
1068    $NumberToFormat *= $FormatArray[7];
1069
1070    if($IsExtendedFormat) // Extended format
1071    {
1072      $DecimalSeparator        = !is_null($FormatArray[2]) ? $FormatArray[2] : ".";
1073      $PeriodSeparator         = !is_null($FormatArray[3]) ? $FormatArray[3] : ",";
1074
1075      $ObligatoryBeforeDecimal = 0;
1076      $DigitsBeforeDecimal = 0;
1077      $BeforeDecimal = $FormatArray[5];
1078      $AfterDecimal = !is_null($FormatArray[6]) ? $FormatArray[6] : ($DataType != ccsInteger ? 100 : 0);
1079      if(is_array($BeforeDecimal)) {
1080        for($i = 0; $i < sizeof($BeforeDecimal); $i++) {
1081          if($BeforeDecimal[$i] == "0") {
1082            $ObligatoryBeforeDecimal++;
1083            $DigitsBeforeDecimal++;
1084          } else if($BeforeDecimal[$i] == "#")
1085            $DigitsBeforeDecimal++;
1086        }
1087      }
1088      $ObligatoryAfterDecimal = 0;
1089      $DigitsAfterDecimal = 0;
1090      if(is_array($AfterDecimal)) {
1091        for($i = 0; $i < sizeof($AfterDecimal); $i++) {
1092          if($AfterDecimal[$i] == "0") {
1093            $ObligatoryAfterDecimal++;
1094            $DigitsAfterDecimal++;
1095          } else if($AfterDecimal[$i] == "#")
1096            $DigitsAfterDecimal++;
1097        }
1098      }
1099
1100      $NumberToFormat = number_format($NumberToFormat, $DigitsAfterDecimal, ".", "");
1101      $NumberParts = explode(".", $NumberToFormat);
1102
1103      $LeftPart = $NumberParts[0];
1104      if($LeftPart == "0") $LeftPart = "";
1105      $RightPart = isset($NumberParts[1]) ? $NumberParts[1] : "";
1106      $j = strlen($LeftPart);
1107
1108      if(is_array($BeforeDecimal))
1109      {
1110        $RankNumber = 0;
1111        $i = sizeof($BeforeDecimal);
1112        while ($i > 0 || $j > 0)
1113        {
1114          if(($i > 0 && ($BeforeDecimal[$i - 1] == "#" || $BeforeDecimal[$i - 1] == "0")) || ($j > 0 && $i < 1)) {
1115            $RankNumber++;
1116            $CurrentSeparator = ($RankNumber % 3 == 1 && $RankNumber > 3 && $j > 0) ? $PeriodSeparator : "";
1117            if($ObligatoryBeforeDecimal > 0 && $j < 1)
1118              $Result = "0" . $CurrentSeparator . $Result;
1119            else if($j > 0)
1120              $Result = $LeftPart[$j - 1] . $CurrentSeparator . $Result;
1121            $j--;
1122            $ObligatoryBeforeDecimal--;
1123            $DigitsBeforeDecimal--;
1124            if($DigitsBeforeDecimal == 0 && $j > 0)
1125              for(;$j > 0; $j--)
1126              {
1127                $RankNumber++;
1128                $CurrentSeparator = ($RankNumber % 3 == 1 && $RankNumber > 3 && $j > 0) ? $PeriodSeparator : "";
1129                $Result = $LeftPart[$j - 1] . $CurrentSeparator . $Result;
1130              }
1131          }
1132          else if ($i > 0) {
1133            $BeforeDecimal[$i - 1] = str_replace("##", "#", $BeforeDecimal[$i - 1]);
1134            $BeforeDecimal[$i - 1] = str_replace("00", "0", $BeforeDecimal[$i - 1]);
1135            $Result = $BeforeDecimal[$i - 1] . $Result;
1136          }
1137          $i--;
1138        }
1139      }
1140
1141      // Left part after decimal
1142      $RightResult = "";
1143      $IsRightNumber = false;
1144      if(is_array($AfterDecimal))
1145      {
1146        $IsZero = true;
1147        for($i = sizeof($AfterDecimal); $i > 0; $i--) {
1148          if($AfterDecimal[$i - 1] == "#" || $AfterDecimal[$i - 1] == "0") {
1149            if($DigitsAfterDecimal > $ObligatoryAfterDecimal) {
1150              if($RightPart[$DigitsAfterDecimal - 1] != "0")
1151                $IsZero = false;
1152              if(!$IsZero)
1153              {
1154                $RightResult = $RightPart[$DigitsAfterDecimal - 1] . $RightResult;
1155                $IsRightNumber = true;
1156              }
1157            } else {
1158              $RightResult = $RightPart[$DigitsAfterDecimal - 1] . $RightResult;
1159              $IsRightNumber = true;
1160            }
1161            $DigitsAfterDecimal--;
1162          } else {
1163            $AfterDecimal[$i - 1] = str_replace("##", "#", $AfterDecimal[$i - 1]);
1164            $AfterDecimal[$i - 1] = str_replace("00", "0", $AfterDecimal[$i - 1]);
1165            $RightResult = $AfterDecimal[$i - 1] . $RightResult;
1166          }
1167        }
1168      }
1169
1170      if($IsRightNumber)
1171        $Result .= $DecimalSeparator ;
1172
1173      $Result .= $RightResult;
1174
1175      if(!$FormatArray[4] && $IsNegative && $Result)
1176        $Result = "-" . $Result;
1177    }
1178    else // Simple format
1179    {
1180      $DecimalSeparator = !is_null($FormatArray[2]) ? $FormatArray[2] : ".";
1181      $PeriodSeparator = !is_null($FormatArray[3]) ? $FormatArray[3] : ",";
1182      $AfterDecimal = !is_null($FormatArray[1]) ? $FormatArray[1] : ($DataType != ccsInteger ? 100 : 0);
1183
1184      $Result = number_format($NumberToFormat, $AfterDecimal, '.', ',');
1185      $Result = str_replace(".", '---', $Result);
1186      $Result = str_replace(",", '+++', $Result);
1187      $Result = str_replace("---", $DecimalSeparator, $Result);
1188      $Result = str_replace("+++", $PeriodSeparator, $Result);
1189      $Result = $FormatArray[5] . $Result . $FormatArray[6];
1190      if(!$FormatArray[4] && $IsNegative)
1191        $Result = "-" . $Result;
1192
1193    }
1194
1195    if(!$FormatArray[8])
1196      $Result = CCToHTML($Result);
1197
1198  }
1199  else
1200    $Result = $NumberToFormat;
1201
1202  if(is_array($FormatArray) && strlen($FormatArray[9])) {
1203    if($CCSIsXHTML) {
1204      $Result = "<span style=\"color: " . $FormatArray[9] . "\">" . $Result . "</span>";
1205    } else {
1206    $Result = "<FONT COLOR=\"" . $FormatArray[9] . "\">" . $Result . "</FONT>";
1207    }
1208  }
1209
1210  return $Result;
1211}
1212//End CCFormatNumber
1213
1214//CCValidateNumber @0-C3F4C267
1215function CCValidateNumber($NumberValue, $FormatArray, $isDBFormat = false)
1216{
1217  $is_valid = true;
1218  if(strlen($NumberValue))
1219  {
1220    $NumberValue = CCCleanNumber($NumberValue, $FormatArray, $isDBFormat);
1221    $is_valid = is_numeric($NumberValue);
1222  }
1223  return $is_valid;
1224}
1225
1226//End CCValidateNumber
1227
1228//CCParseNumber @0-3F28B3F3
1229function CCParseNumber($NumberValue, $FormatArray, $DataType, $isDBFormat = false)
1230{
1231  $NumberValue = CCCleanNumber($NumberValue, $FormatArray, $isDBFormat);
1232  if(is_array($FormatArray) && strlen($NumberValue))
1233  {
1234
1235    if($FormatArray[4]) // Contains parenthesis
1236      $NumberValue = - abs(doubleval($NumberValue));
1237
1238    $NumberValue /= $FormatArray[7];
1239  }
1240
1241  if(strlen($NumberValue))
1242  {
1243    if($DataType == ccsFloat)
1244      $NumberValue = doubleval($NumberValue);
1245    else
1246      $NumberValue = round($NumberValue, 0);
1247  }
1248
1249  return $NumberValue;
1250}
1251//End CCParseNumber
1252
1253//CCCleanNumber @0-AFA6FB0D
1254function CCCleanNumber($NumberValue, $FormatArray, $isDBFormat = false)
1255{
1256  if(is_array($FormatArray))
1257  {
1258    $IsExtendedFormat = $FormatArray[0];
1259
1260    if($IsExtendedFormat) // Extended format
1261    {
1262      $BeforeDecimal = $FormatArray[5];
1263      $AfterDecimal = $FormatArray[6];
1264
1265      if(is_array($BeforeDecimal))
1266      {
1267        for($i = sizeof($BeforeDecimal); $i > 0; $i--) {
1268          if($BeforeDecimal[$i - 1] != "#" && $BeforeDecimal[$i - 1] != "0")
1269          {
1270            $search = $BeforeDecimal[$i - 1];
1271            $search = ($search == "##" || $search == "00") ? $search[0] : $search;
1272            $NumberValue = str_replace($search, "", $NumberValue);
1273          }
1274        }
1275      }
1276
1277      if(is_array($AfterDecimal))
1278      {
1279        for($i = sizeof($AfterDecimal); $i > 0; $i--) {
1280          if($AfterDecimal[$i - 1] != "#" && $AfterDecimal[$i - 1] != "0")
1281          {
1282            $search = $AfterDecimal[$i - 1];
1283            $search = ($search == "##" || $search == "00") ? $search[0] : $search;
1284            $NumberValue = str_replace($search, "", $NumberValue);
1285          }
1286        }
1287      }
1288    }
1289    else // Simple format
1290    {
1291      if(strlen($FormatArray[5]))
1292        $NumberValue = str_replace($FormatArray[5], "", $NumberValue);
1293      if(strlen($FormatArray[6]))
1294        $NumberValue = str_replace($FormatArray[6], "", $NumberValue);
1295    }
1296    $DecimalSeparator = !is_null($FormatArray[2]) ? $FormatArray[2] : ".";
1297    $PeriodSeparator = !is_null($FormatArray[3]) ? $FormatArray[3] : ",";
1298
1299    $NumberValue = str_replace($PeriodSeparator, "", $NumberValue); // Period separator
1300    $NumberValue = str_replace($DecimalSeparator, ".", $NumberValue); // Decimal separator
1301
1302    if(strlen($FormatArray[9]))
1303    {
1304      if($CCSIsXHTML) {
1305        $NumberValue = str_replace("<span style=\"color: " . $FormatArray[9] . "\">", "", $NumberValue);
1306        $NumberValue = str_replace("</span>", "", $NumberValue);
1307      } else {
1308      $NumberValue = str_replace("<FONT COLOR=\"" . $FormatArray[9] . "\">", "", $NumberValue);
1309      $NumberValue = str_replace("</FONT>", "", $NumberValue);
1310    }
1311    }
1312    return $NumberValue;
1313  }
1314  $NumberValue = str_replace(",", ".", $NumberValue);
1315  $NumberValue = preg_replace("/^(-?)(\\.\\d+)$/", "\${1}0\${2}", $NumberValue);
1316
1317  return $NumberValue;
1318}
1319//End CCCleanNumber
1320
1321//CCParseInteger @0-08035527
1322function CCParseInteger($NumberValue, $FormatArray, $isDBFormat = false)
1323{
1324  return CCParseNumber($NumberValue, $FormatArray, ccsInteger, $isDBFormat);
1325}
1326//End CCParseInteger
1327
1328//CCParseFloat @0-89DDFF62
1329function CCParseFloat($NumberValue, $FormatArray, $isDBFormat = false)
1330{
1331  return CCParseNumber($NumberValue, $FormatArray, ccsFloat, $isDBFormat);
1332}
1333//End CCParseFloat
1334
1335//CCValidateBoolean @0-DFB0ECFA
1336function CCValidateBoolean($BooleanValue, $Format)
1337{
1338  return $BooleanValue == ""
1339     || strtolower($BooleanValue) == "true"
1340     || strtolower($BooleanValue) == "false"
1341     || strval($BooleanValue) == "0"
1342     || strval($BooleanValue) == "1"
1343     || (is_array($Format)
1344        && (strtolower($BooleanValue) == strtolower($Format[0])
1345            || strtolower($BooleanValue) == strtolower($Format[1])
1346            || strtolower($BooleanValue) == strtolower($Format[2])));
1347}
1348//End CCValidateBoolean
1349
1350//CCFormatBoolean @0-5B3F5CF9
1351function CCFormatBoolean($BooleanValue, $Format)
1352{
1353  $Result = $BooleanValue;
1354
1355  if(is_array($Format)) {
1356    if($BooleanValue == 1)
1357      $Result = $Format[0];
1358    else if(strval($BooleanValue) == "0" || $BooleanValue === false)
1359      $Result = $Format[1];
1360    else
1361      $Result = $Format[2];
1362  }
1363
1364  return $Result;
1365}
1366//End CCFormatBoolean
1367
1368//CCParseBoolean @0-1DA49599
1369function CCParseBoolean($Value, $Format)
1370{
1371  if (is_array($Format)) {
1372    if (strtolower(strval($Value)) == strtolower(strval($Format[0])))
1373      return true;
1374    if (strtolower(strval($Value)) == strtolower(strval($Format[1])))
1375      return false;
1376    if (strtolower(strval($Value)) == strtolower(strval($Format[2])))
1377      return "";
1378  }
1379  if (strval($Value) == "0" || strtolower(strval($Value)) == "false")
1380    return false;
1381  if (strval($Value) == "1" || strtolower(strval($Value)) == "true")
1382    return true;
1383  return "";
1384}
1385//End CCParseBoolean
1386
1387//CCGetBooleanFormat @0-B9D3DA0C
1388function CCGetBooleanFormat($Format)
1389{
1390  $FormatString = "";
1391  if(is_array($Format))
1392  {
1393    for($i = 0; $i < sizeof($Format); $i++) {
1394      if(strlen($Format[$i])) {
1395        if(strlen($FormatString)) $FormatString .= ";";
1396        $FormatString .= $Format[$i];
1397      }
1398    }
1399  }
1400  return $FormatString;
1401}
1402//End CCGetBooleanFormat
1403
1404//CCCompareValues @0-8D9B429E
1405function CCCompareValues($Value1,$Value2,$DataType = ccsText, $Format = "")
1406{
1407  switch ($DataType) {
1408    case ccsInteger:
1409    case ccsFloat:
1410      if(strcmp(trim($Value1),"") == 0 || strcmp(trim($Value2),"") == 0)
1411        return strcmp($Value1, $Value2);
1412      else if($Value1 > $Value2)
1413        return 1;
1414      else if($Value1 < $Value2)
1415        return -1;
1416      else
1417        return 0;
1418
1419    case ccsText:
1420    case ccsMemo:
1421      return strcmp($Value1,$Value2);
1422
1423    case ccsBoolean:
1424      if (is_bool($Value1))
1425        $val1=$Value1;
1426      else if (strlen($Value1)!= 0 && CCValidateBoolean($Value1,$Format))
1427        $val1=CCParseBoolean($Value1,$Format);
1428      else
1429        return 1;
1430
1431      if (is_bool($Value2))
1432        $val2=$Value2;
1433      else if (strlen($Value2)!= 0 && CCValidateBoolean($Value2,$Format))
1434        $val2=CCParseBoolean($Value2,$Format);
1435      else
1436        return 1;
1437
1438      return $val1 xor $val2;
1439
1440    case ccsDate:
1441      if (is_array($Value1) && is_array($Value2)) {
1442        $compare = array(ccsYear, ccsMonth, ccsDay, ccsHour, ccsMinute, ccsSecond);
1443        foreach ($compare as $ind => $val) {
1444          if ($Value1[$val] < $Value2[$val])
1445            return -1;
1446          elseif ($Value1[$val] > $Value2[$val])
1447            return 1;
1448        }
1449        return 0;
1450      } else if(is_array($Value1)) {
1451        $FormattedValue = CCFormatValue($Value1, $Format, $DataType);
1452        return CCCompareValues($FormattedValue, $Value2);
1453      } else if(is_array($Value2)) {
1454        $FormattedValue = CCFormatValue($Value2, $Format, $DataType);
1455        return CCCompareValues($Value1,$FormattedValue);
1456      } else {
1457        return CCCompareValues($Value1,$Value2);
1458      }
1459
1460  }
1461}
1462//End CCCompareValues
1463
1464//CCDateAdd @0-FD3E5738
1465function CCDateAdd($date, $value) {
1466  if (CCValidateDate($date)) {
1467    $FormatArray = array("yyyy", "-", "mm", "-", "dd", " ", "HH", ":", "nn", ":", "ss");
1468    $value = strtolower($value);
1469    preg_match_all("/([-+]?)(\\d+)\\s*(year(s?)…

Large files files are truncated, but you can click here to view the full file