PageRenderTime 70ms CodeModel.GetById 31ms 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
Possible License(s): GPL-3.0

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

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