PageRenderTime 76ms CodeModel.GetById 33ms 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
  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?)|month(s?)|day(s?)|hour(s?)|minute(s?)|second(s?)|week(s?)|[ymdwhns])/", $value, $pieces);
  1335. for($i=0; $i<count($pieces[0]); $i++) {
  1336. $rel = $pieces[1][$i] == "-" ? -$pieces[2][$i] : $pieces[2][$i];
  1337. $BackMonth = false;
  1338. switch($pieces[3][$i]) {
  1339. case "years":
  1340. case "year":
  1341. case "y":
  1342. $date[ccsYear] += $rel;
  1343. $BackMonth = true;
  1344. break;
  1345. case "months":
  1346. case "month":
  1347. case "m":
  1348. $date[ccsMonth] += $rel;
  1349. $BackMonth = true;
  1350. break;
  1351. case "weeks":
  1352. case "week":
  1353. case "w":
  1354. $date[ccsDay] += $rel * 7;
  1355. break;
  1356. case "days":
  1357. case "day":
  1358. case "d":
  1359. $date[ccsDay] += $rel;
  1360. break;
  1361. case "hours":
  1362. case "hour":
  1363. case "h":
  1364. $date[ccsHour] += $rel;
  1365. break;
  1366. case "minutes":
  1367. case "minute":
  1368. case "min":
  1369. case "n":
  1370. $date[ccsMinute] += $rel;
  1371. break;
  1372. case "seconds":
  1373. case "second":
  1374. case "sec":
  1375. case "s":
  1376. $date[ccsSecond] += $rel;
  1377. break;
  1378. }
  1379. if ($date[ccsSecond] >= 60) {
  1380. $date[ccsMinute] += floor($date[ccsSecond] / 60);
  1381. $date[ccsSecond] = $date[ccsSecond] % 60;
  1382. } elseif ($date[ccsSecond] < 0) {
  1383. $date[ccsMinute] += floor($date[ccsSecond] / 60);
  1384. $date[ccsSecond] = (($date[ccsSecond]) % 60 + 60) % 60;
  1385. }
  1386. if ($date[ccsMinute] >= 60) {
  1387. $date[ccsHour] += floor($date[ccsMinute] / 60);
  1388. $date[ccsMinute] = $date[ccsMinute] % 60;
  1389. } elseif ($date[ccsMinute] < 0) {
  1390. $date[ccsHour] += floor($date[ccsMinute] / 60);
  1391. $date[ccsMinute] = ($date[ccsMinute] % 60 + 60) % 60;
  1392. }
  1393. if ($date[ccsHour] >= 24) {
  1394. $date[ccsDay] += floor($date[ccsHour] / 24);
  1395. $date[ccsHour] = $date[ccsHour] % 24;
  1396. } elseif ($date[ccsHour] < 0) {
  1397. $date[ccsDay] += floor($date[ccsHour] / 24);
  1398. $date[ccsHour] = ($date[ccsHour] % 24 + 24) % 24;
  1399. }
  1400. if ($date[ccsMonth] > 12) {
  1401. $date[ccsYear] += floor(($date[ccsMonth] - 1) / 12);
  1402. $date[ccsMonth] = ($date[ccsMonth] - 1) % 12 + 1;
  1403. } elseif ($date[ccsMonth] < 1) {
  1404. $date[ccsYear] += floor(($date[ccsMonth] - 1) / 12);
  1405. $date[ccsMonth] = (($date[ccsMonth] - 1) % 12 + 12) % 12 + 1;
  1406. }
  1407. $days = CCDaysInMonth($date[ccsYear], $date[ccsMonth]);
  1408. if($BackMonth && $date[ccsDay] > $days) {
  1409. $date[ccsDay] = $days;
  1410. } else {
  1411. while ($date[ccsDay] > $days) {
  1412. $date[ccsMonth] += 1;
  1413. if ($date[ccsMonth] > 12) {
  1414. $date[ccsYear] += 1;
  1415. $date[ccsMonth] = 1;
  1416. }
  1417. $date[ccsDay] = $date[ccsDay] - $days;
  1418. $days = CCDaysInMonth($date[ccsYear], $date[ccsMonth]);
  1419. }
  1420. }
  1421. if($BackMonth && $date[ccsDay] < 1) {
  1422. $date[ccsDay] = 1;
  1423. } else {
  1424. $tmpDate = "";
  1425. while ($date[ccsDay] < 1) {
  1426. if ($tmpDate == "")
  1427. $tmpDate = CCParseDate(CCFormatDate($date, array("yyyy","-","mm","-01")), array("yyyy","-","mm","-","dd"));
  1428. $tmpDate = CCDateAdd($tmpDate, "-1month");
  1429. $days = CCDaysInMonth($tmpDate[ccsYear], $tmpDate[ccsMonth]);
  1430. $date[ccsMonth] -= 1;
  1431. if ($date[ccsMonth] == 0) {
  1432. $date[ccsYear] -= 1;
  1433. $date[ccsMonth] = 12;
  1434. }
  1435. $date[ccsDay] = $date[ccsDay] + $days;
  1436. }
  1437. }
  1438. }
  1439. $date[ccsTimestamp] = @mktime ($date[ccsHour], $date[ccsMinute], $date[ccsSecond], $date[ccsMonth], $date[ccsDay], $date[ccsYear]);
  1440. return $date;
  1441. }
  1442. return false;
  1443. }
  1444. //End CCDateAdd
  1445. //CCDaysInMonth @0-4DFC9A98
  1446. function CCDaysInMonth($year, $month) {
  1447. switch ($month) {
  1448. case 4:
  1449. case 6:
  1450. case 9:
  1451. case 11:
  1452. return 30;
  1453. case 2:
  1454. if ($year % 4)
  1455. return 28;
  1456. elseif ($year % 100)
  1457. return 29;
  1458. elseif ($year % 400)
  1459. return 28;
  1460. else return 29;
  1461. default:
  1462. return 31;
  1463. }
  1464. }
  1465. //End CCDaysInMonth
  1466. //CCDayOfWeek @0-479679B3
  1467. function CCDayOfWeek($date) {
  1468. //return 1 - Sun, 2 - Mon, 3 - Tue ...
  1469. $year = $date[ccsYear];
  1470. $month = $date[ccsMonth];
  1471. $day = $date[ccsDay];
  1472. $century = $year - ( $year % 100 );
  1473. $base = array( 3, 2, 0, 5 );
  1474. $base = $base[(($century - 1500) / 100 + 16) % 4];
  1475. $twelves = intval(($year - $century )/12);
  1476. $rem = ($year - $century) % 12;
  1477. $fours = intval($rem / 4);
  1478. $doomsday = $base + ($twelves + $rem + $fours) % 7;
  1479. $doomsday = $doomsday % 7;
  1480. $base = array( 0, 0, 7, 4, 9, 6, 11, 8, 5, 10, 7, 12 );
  1481. if (CCDaysInMonth($year, 2) == 29) {
  1482. $base[0] = 32;
  1483. $base[1] = 29;
  1484. } else {
  1485. $base[0] = 31;
  1486. $base[1] = 28;
  1487. }
  1488. $on = $day - $base[$month - 1];
  1489. $on = $on % 7;
  1490. return ($doomsday + $on + 7) % 7 + 1;
  1491. }
  1492. //End CCDayOfWeek
  1493. //CCDayOfYear @0-D35E28C6
  1494. function CCDayOfYear($date) {
  1495. $days = 0;
  1496. for ($month = 1; $month < $date[ccsMonth]; $month++)
  1497. $days += CCDaysInMonth($date[ccsYear], $month);
  1498. return $days + $date[ccsDay];
  1499. }
  1500. //End CCDayOfYear
  1501. //CCConvertEncoding @0-5177A761
  1502. function CCConvertEncoding($text, $from, $to)
  1503. {
  1504. return $text;
  1505. }
  1506. //End CCConvertEncoding
  1507. //CCConvertEncodingArray @0-1A109043
  1508. function CCConvertEncodingArray($array, $from="", $to="")
  1509. {
  1510. if (strlen($from) && strlen($to) && strcasecmp($from, $to)) {
  1511. foreach ($array as $key => $value)
  1512. $array[$key] = is_array($value) ? CCConvertEncodingArray($value, $from, $to) : CCConvertEncoding($value, $from, $to);
  1513. }
  1514. return $array;
  1515. }
  1516. //End CCConvertEncodingArray
  1517. //CCConvertDataArrays @0-67F649CD
  1518. function CCConvertDataArrays($from="", $to="")
  1519. {
  1520. global $FileEncoding;
  1521. global $TemplateEncoding;
  1522. if ($from == "")
  1523. $from = $TemplateEncoding;
  1524. if ($to == "")
  1525. $to = $FileEncoding;
  1526. if (strlen($from) && strlen($to) && strcmp($from, $to)) {
  1527. $_POST = CCConvertEncodingArray($_POST, $from, $to);
  1528. $_GET = CCConvertEncodingArray($_GET, $from, $to);
  1529. }
  1530. }
  1531. //End CCConvertDataArrays
  1532. //CCGetOriginalFileName @0-16048768
  1533. function CCGetOriginalFileName($value)
  1534. {
  1535. return preg_match("/^\d{14,}\./", $value) ? substr($value, strpos($value, ".") + 1) : $value;
  1536. }
  1537. //End CCGetOriginalFileName
  1538. //ComposeStrings @0-09CE565D
  1539. function ComposeStrings($str1, $str2, $delimiter = null)
  1540. {
  1541. global $CCSIsXHTML;
  1542. if(is_null($delimiter)) {
  1543. $delimiter = $CCSIsXHTML ? "<br />" : "<BR>";
  1544. }
  1545. return $str1 . (strlen($str1) && strlen($str2) ? $delimiter : "") . $str2;
  1546. }
  1547. //End ComposeStrings
  1548. //CCSelectProjectStyle @0-F430A08A
  1549. function CCSelectProjectStyle() {
  1550. global $CCProjectStyle;
  1551. $QueryStyle = CCGetFromGet("style");
  1552. if ($QueryStyle) {
  1553. CCSetProjectStyle($QueryStyle);
  1554. CCSetSession("style", $CCProjectStyle);
  1555. return;;
  1556. }
  1557. if (CCSetProjectStyle(CCGetSession("style")))
  1558. return;
  1559. }
  1560. //End CCSelectProjectStyle
  1561. //CCSetProjectStyle @0-E7A8832F
  1562. function CCSetProjectStyle($NewStyle) {
  1563. global $CCProjectStyle;
  1564. $NewStyle = trim($NewStyle);
  1565. if ($NewStyle && file_exists(RelativePath . "/Styles/" . $NewStyle . "/Style.css")) {
  1566. $CCProjectStyle = $NewStyle;
  1567. return true;
  1568. }
  1569. return false;
  1570. }
  1571. //End CCSetProjectStyle
  1572. //CCSelectProjectDesign @0-E62BEB46
  1573. function CCSelectProjectDesign() {
  1574. global $CCProjectDesign;
  1575. }
  1576. //End CCSelectProjectDesign
  1577. //CCSetProjectDesign @0-004D9DEA
  1578. function CCSetProjectDesign($NewDesign) {
  1579. global $CCProjectDesign;
  1580. $NewDesign = trim($NewDesign);
  1581. if ($NewDesign && is_dir(RelativePath . "/Designs/" . $NewDesign . "/")) {
  1582. $CCProjectDesign = $NewDesign;
  1583. return true;
  1584. }
  1585. return false;
  1586. }
  1587. //End CCSetProjectDesign
  1588. //CCStrLen @0-3660E806
  1589. function CCStrLen($str, $encoding = false) {
  1590. return strlen($str);
  1591. }
  1592. //End CCStrLen
  1593. //CCGetTemplate @0-D8640D95
  1594. function & CCGetTemplate(& $Component = null) {
  1595. global $Tpl;
  1596. if ($Component == null) return $Tpl;
  1597. $TplClassName = "clsTemplate";
  1598. $parent_page = & CCGetParentPage($Component);
  1599. if (!isset($parent_page->Tpl) || !($parent_page->Tpl instanceof $TplClassName)) { return $Tpl; }
  1600. else { return $parent_page->Tpl; }
  1601. }
  1602. //End CCGetTemplate
  1603. //CCInitializeDetails @0-95E75FA7
  1604. function CCInitializeDetails(& $Component, $ComponentType)
  1605. {
  1606. global $MainPage;
  1607. $json = $_POST["CCSDetailControls"];
  1608. $JsonParser = new Services_JSON(SERVICES_JSON_LOOSE_TYPE);
  1609. $controls = $JsonParser->decode(stripslashes($json));
  1610. $_POST = array_merge($_POST, $controls);
  1611. $_GET["ccsForm"] = $Component->ComponentName;
  1612. $ComponentClassName = get_class($Component);
  1613. $parent_page = & CCGetParentPage($Component);
  1614. if ($parent_page->ComponentType == "IncludablePage") {
  1615. $Component = new $ComponentClassName("", $parent_page);
  1616. $Component->Initialize();
  1617. $parent_page->BindEvents();
  1618. } else {
  1619. $Component = new $ComponentClassName("", $MainPage);
  1620. $Component->Initialize();
  1621. BindEvents();
  1622. }
  1623. if ($ComponentType == "EditableGrid") {
  1624. $Component->GetFormParameters();
  1625. }
  1626. return $Component->Validate();
  1627. }
  1628. //End CCInitializeDetails
  1629. //CCSubStr @0-552E6589
  1630. function CCSubStr($str, $offset, $length = null, $encoding = false) {
  1631. return is_null($length) ? substr($str, $offset) : substr($str, $offset, $length);
  1632. }
  1633. //End CCSubStr
  1634. //CCStrPos @0-BA504839
  1635. function CCStrPos($haystack, $needle, $offset = "", $encoding = false) {
  1636. return strpos($haystack, $needle, $offset);
  1637. }
  1638. //End CCStrPos
  1639. //CCCheckSSL @0-A8E1366D
  1640. function CCCheckSSL()
  1641. {
  1642. $HTTPS = isset($_SERVER["HTTPS"]) ? strtolower($_SERVER["HTTPS"]) : "";
  1643. if($HTTPS != "on")
  1644. {
  1645. echo "SSL connection error. This page can be accessed only via secured connection.";
  1646. exit;
  1647. }
  1648. }
  1649. //End CCCheckSSL
  1650. //GenerateCaptchaCode @0-BCA1E0E9
  1651. function GenerateCaptchaCode($letters, $sesVariableName, $width, $height, $length, $rot, $br, $w1, $w2, $noise) {
  1652. $restricted = "|cp|cb|ck|c6|c9|rn|rm|mm|co|do|cl|db|qp|qb|dp|";
  1653. $res = new clsQuadraticPaths();
  1654. $t = ""; $code = ""; $r = "";
  1655. for ($i = 0; $i < $length; $i++) {
  1656. $r = intval((count($letters)) * (mt_rand(0, 99)/100));
  1657. while (strpos("|" . substr($code, -strlen($code), 1) . $letters[$r][0] . "|", $restricted) !== false) {
  1658. $r = intval((count($letters)) * (mt_rand(0, 99)/100));
  1659. }
  1660. $code = $code . $letters[$r][0];
  1661. $t = new clsQuadraticPaths();
  1662. $t->LoadFromArray($letters[$r]);
  1663. $t->Wave(2 * $w2 * (mt_rand(0, 99)/100) - $w2);
  1664. $t->Rotate(2 * $rot * (mt_rand(0, 99)/100) - $rot);
  1665. $t->Normalize(0, 100);
  1666. if (($t->MaxX - $t->MinX) > 100) {
  1667. $t->Normalize(100, 100);
  1668. }
  1669. $t->Addition(($i - 1) * $t->MaxY, 0);
  1670. $res->AddPaths($t);
  1671. }
  1672. $res->Rotate(90);
  1673. $res->Wave(2 * $w1 * (mt_rand(0, 99)/100) - $w1);
  1674. $res->Rotate(-90);
  1675. $res->Broke($br, $br);
  1676. $res->Normalize($width - 12, $height - 12);
  1677. $res->Addition(6, 6);
  1678. $res->Mix();
  1679. $res->Noises($noise);
  1680. CCSetSession($sesVariableName, $code);
  1681. return $res->ToString();
  1682. }
  1683. //End GenerateCaptchaCode
  1684. //file_get_contents @0-4991CB3D
  1685. if (!function_exists('file_get_contents')) {
  1686. function file_get_contents($filename, $incpath = false, $resource_context = null)
  1687. {
  1688. if (false === $fh = fopen($filename, 'rb', $incpath)) {
  1689. trigger_error('file_get_contents() failed to open stream: No such file or directory', E_USER_WARNING);
  1690. return false;
  1691. }
  1692. clearstatcache();
  1693. if ($fsize = @filesize($filename)) {
  1694. $data = fread($fh, $fsize);
  1695. } else {
  1696. $data = '';
  1697. while (!feof($fh)) {
  1698. $data .= fread($fh, 8192);
  1699. }
  1700. }
  1701. fclose($fh);
  1702. return $data;
  1703. }
  1704. }
  1705. //End file_get_contents
  1706. //CCSecurityRedirect @0-ADFE9D99
  1707. function CCSecurityRedirect($GroupsAccess, $URL)
  1708. {
  1709. global $_SERVER;
  1710. $ReturnPage = isset($_SERVER["REQUEST_URI"]) ? $_SERVER["REQUEST_URI"] : "";
  1711. if(!strlen($ReturnPage)) {
  1712. $ReturnPage = isset($_SERVER["SCRIPT_NAME"]) ? $_SERVER["SCRIPT_NAME"] : "";
  1713. $QueryString = CCGetQueryString("QueryString", "");
  1714. if($QueryString !== "")
  1715. $ReturnPage .= "?" . $QueryString;
  1716. }
  1717. $ErrorType = CCSecurityAccessCheck($GroupsAccess);
  1718. if($ErrorType != "success")
  1719. {
  1720. if(!strlen($URL))
  1721. $Link = ServerURL . "admin/login.php";
  1722. else
  1723. $Link = $URL;
  1724. header("Location: " . $Link . "?ret_link=" . urlencode($ReturnPage) . "&type=" . $ErrorType);
  1725. exit;
  1726. }
  1727. }
  1728. //End CCSecurityRedirect
  1729. //CCSecurityAccessCheck @0-7B496647
  1730. function CCSecurityAccessCheck($GroupsAccess)
  1731. {
  1732. $ErrorType = "success";
  1733. if(!strlen(CCGetUserID()))
  1734. {
  1735. $ErrorType = "notLogged";
  1736. }
  1737. else
  1738. {
  1739. $GroupID = CCGetGroupID();
  1740. if(!strlen($GroupID))
  1741. {
  1742. $ErrorType = "groupIDNotSet";
  1743. }
  1744. else
  1745. {
  1746. if(!CCUserInGroups($GroupID, $GroupsAccess))
  1747. $ErrorType = "illegalGroup";
  1748. }
  1749. }
  1750. return $ErrorType;
  1751. }
  1752. //End CCSecurityAccessCheck
  1753. //CCGetUserID @0-6FAFFFAE
  1754. function CCGetUserID()
  1755. {
  1756. return CCGetSession("UserID");
  1757. }
  1758. //End CCGetUserID
  1759. //CCGetGroupID @0-89F10997
  1760. function CCGetGroupID()
  1761. {
  1762. return CCGetSession("GroupID");
  1763. }
  1764. //End CCGetGroupID
  1765. //CCGetUserLogin @0-ACD25564
  1766. function CCGetUserLogin()
  1767. {
  1768. return CCGetSession("UserLogin");
  1769. }
  1770. //End CCGetUserLogin
  1771. //CCGetUserPassword @0-FF9DADAF
  1772. function CCGetUserPassword()
  1773. {
  1774. return CCGetSession("UserPassword");
  1775. }
  1776. //End CCGetUserPassword
  1777. //CCGetUserAddr @0-608F4AF1
  1778. function CCGetUserAddr()
  1779. {
  1780. return CCGetSession("UserAddr");
  1781. }
  1782. //End CCGetUserAddr
  1783. //CCUserInGroups @0-9F7F30EA
  1784. function CCUserInGroups($GroupID, $GroupsAccess)
  1785. {
  1786. $Result = "";
  1787. if(strlen($GroupsAccess))
  1788. {
  1789. $Result = (strpos(";" . $GroupsAccess . ";", ";" . $GroupID . ";") !== false);
  1790. }
  1791. else
  1792. {
  1793. $Result = true;
  1794. }
  1795. return $Result;
  1796. }
  1797. //End CCUserInGroups
  1798. //CCCipherInit @0-034764F6
  1799. function CCCipherInit($key) {
  1800. global $CipherBox, $CipherKey;
  1801. $temp = '';
  1802. $idx1 = 0;
  1803. $idx2 = 0;
  1804. $keyLength = strlen($key);
  1805. for ($idx1 = 0; $idx1 < 256; $idx1++) {
  1806. $CipherBox[$idx1] = $idx1;
  1807. $CipherKey[$idx1] = ord($key[$idx1 % $keyLength]);
  1808. }
  1809. for ($idx1 = 0; $idx1 < 256; $idx1++) {
  1810. $idx2 = ($idx2 + $CipherBox[$idx1] + $CipherKey[$idx1]) % 256;
  1811. $temp = $CipherBox[$idx1];
  1812. $CipherBox[$idx1] = $CipherBox[$idx2];
  1813. $CipherBox[$idx2] = $temp;
  1814. }
  1815. }
  1816. //End CCCipherInit
  1817. //CCEncryptString @0-1D38A95F
  1818. function CCEncryptString($inputStr, $key) {
  1819. return strtoupper(CCBytesToHex(CCCipherEnDeCrypt($inputStr, $key)));
  1820. }
  1821. //End CCEncryptString
  1822. //CCDecryptString @0-548844D9
  1823. function CCDecryptString($inputStr, $key) {
  1824. return CCBytesToString(CCCipherEnDeCrypt(CCHexToBytes($inputStr), $key));
  1825. }
  1826. //End CCDecryptString
  1827. //CCCipherEnDeCrypt @0-D1CE45DA
  1828. function CCCipherEnDeCrypt($inputStr, $key) {
  1829. global $CipherBox;
  1830. $result = array();
  1831. $i = 0;
  1832. $j = 0;
  1833. CCCipherInit($key);
  1834. for ($a = 0; $a < strlen($inputStr); $a++) {
  1835. $i = ($i + 1) % 256;
  1836. $j = ($j + $CipherBox[$i]) % 256;
  1837. $temp = $CipherBox[$i];
  1838. $CipherBox[$i] = $CipherBox[$j];
  1839. $CipherBox[$j] = $temp;
  1840. $k = $CipherBox[(($CipherBox[$i] + $CipherBox[$j]) % 256)];
  1841. $crypted = ord($inputStr[$a]) ^ $k;
  1842. $result[$a] = $crypted;
  1843. }
  1844. return $result;
  1845. }
  1846. //End CCCipherEnDeCrypt
  1847. //CCBytesToString @0-48925391
  1848. function CCBytesToString($bytesArray) {
  1849. $result = '';
  1850. foreach ($bytesArray as $byte) {
  1851. $result .= chr($byte);
  1852. }
  1853. return $result;
  1854. }
  1855. //End CCBytesToString
  1856. //CCBytesToHex @0-AC21C0B4
  1857. function CCBytesToHex($bytesArray) {
  1858. $result = '';
  1859. foreach ($bytesArray as $byte) {
  1860. $tmp = dechex($byte);
  1861. $result .= str_repeat("0", 2 - strlen($tmp)) . $tmp;
  1862. }
  1863. return $result;
  1864. }
  1865. //End CCBytesToHex
  1866. //CCHexToBytes @0-DE5FE7C5
  1867. function CCHexToBytes($hexstr) {
  1868. $result = '';
  1869. $num = 0;
  1870. for ($i = 0; $i < strlen($hexstr); $i += 2) {
  1871. $num = hexdec(substr($hexstr, $i, 1)) * 16;
  1872. $num += hexdec(substr($hexstr, $i + 1, 1));
  1873. $result .= chr($num);
  1874. }
  1875. return $result;
  1876. }
  1877. //End CCHexToBytes
  1878. //CCLoginUser @0-CC35F8C4
  1879. function CCLoginUser($login, $password)
  1880. {
  1881. CCLogoutUser();
  1882. $db = new clsDBConnection();
  1883. $SQL = "SELECT User_ID, User_Access, User_Password FROM Users WHERE User_Name=" . $db->ToSQL($login, ccsText) . " AND User_Password=AES_ENCRYPT(" . $db->ToSQL($password, ccsText) . ", 'SQKe0njtmg3/fPpEy2GouQ==')";
  1884. $db->query($SQL);
  1885. $Result = $db->next_record();
  1886. if ($Result) {
  1887. CCSetSession("UserID", $db->f("User_ID"));
  1888. CCSetSession("UserLogin", $login);
  1889. CCSetSession("UserPassword", $password);
  1890. CCSetSession("GroupID", $db->f("User_Access"));
  1891. CCSetSession("UserAddr", $_SERVER["REMOTE_ADDR"]);
  1892. }
  1893. return $Result;
  1894. }
  1895. //End CCLoginUser
  1896. //CCLogoutUser @0-91ACDE66
  1897. function CCLogoutUser()
  1898. {
  1899. CCSetSession("UserID", "");
  1900. CCSetSession("UserLogin", "");
  1901. CCSetSession("UserPassword", "");
  1902. CCSetSession("GroupID", "");
  1903. CCSetSession("UserAddr", "");
  1904. }
  1905. //End CCLogoutUser
  1906. #########
  1907. # Return Number of Plays today
  1908. #########
  1909. if (!function_exists('Custom_GetPlaysToday')) {
  1910. function Custom_GetPlaysToday() {
  1911. $DBConnection = new clsDBConnection();
  1912. $Result = CCGetDBValue("SELECT Count(*) FROM Tickets WHERE Ticket_Played='Yes' AND (TO_DAYS(NOW()) - TO_DAYS(Ticket_DrawDate)<1)", $DBConnection);
  1913. if ($Result) {
  1914. return $Result;
  1915. } else {
  1916. return "-";
  1917. }
  1918. }
  1919. }
  1920. #########
  1921. # Return Number of Wins Today
  1922. #########
  1923. if (!function_exists('Custom_GetWinsToday')) {
  1924. function Custom_GetWinsToday() {
  1925. $DBConnection = new clsDBConnection();
  1926. $Result = CCGetDBValue("SELECT Count(*) FROM Tickets WHERE Ticket_Played='Yes' AND Ticket_Winner='Yes' AND (TO_DAYS(NOW()) - TO_DAYS(Ticket_DrawDate)<1)", $DBConnection);
  1927. if ($Result) {
  1928. return $Result;
  1929. } else {
  1930. return "-";
  1931. }
  1932. }
  1933. }
  1934. #########
  1935. # Return Number of Wins this Month
  1936. #########
  1937. if (!function_exists('Custom_GetWinsThisMonth')) {
  1938. function Custom_GetWinsThisMonth() {
  1939. $DBConnection = new clsDBConnection();
  1940. $Result = CCGetDBValue("SELECT Count(*) FROM Tickets WHERE (TO_DAYS(NOW()) - TO_DAYS(Ticket_DrawDate) <= DAYOFMONTH(NOW())) AND Ticket_Played='Yes' AND Ticket_Winner='Yes'", $DBConnection);
  1941. if ($Result) {
  1942. return $Result;
  1943. } else {
  1944. return "-";
  1945. }
  1946. }
  1947. }
  1948. #########
  1949. # Return Number of Plays this Month
  1950. #########
  1951. if (!function_exists('Custom_GetPlaysThisMonth')) {
  1952. function Custom_GetPlaysThisMonth() {
  1953. $DBConnection = new clsDBConnection();
  1954. $Result = CCGetDBValue("SELECT Count(*) FROM Tickets WHERE (TO_DAYS(NOW()) - TO_DAYS(Ticket_DrawDate) <= DAYOFMONTH(NOW())) AND Ticket_Played='Yes'", $DBConnection);
  1955. if ($Result) {
  1956. return $Result;
  1957. } else {
  1958. return "-";
  1959. }
  1960. }
  1961. }
  1962. #########
  1963. # Return Number of Wins for a Week
  1964. #########
  1965. if (!function_exists('Custom_GetWinsThisWeek')) {
  1966. function Custom_GetWinsThisWeek() {
  1967. $DBConnection = new clsDBConnection();
  1968. $Result = CCGetDBValue("SELECT Count(*) FROM Tickets WHERE Week(Ticket_DrawDate) = Week(NOW()) AND Year(Ticket_DrawDate)=Year(NOW()) AND Ticket_Played='Yes' AND Ticket_Winner='Yes'", $DBConnection);
  1969. if ($Result) {
  1970. return $Result;
  1971. } else {
  1972. return "-";
  1973. }
  1974. }
  1975. }
  1976. #########
  1977. # Return Number of Plays for a Week
  1978. #########
  1979. if (!function_exists('Custom_GetPlaysThisWeek')) {
  1980. function Custom_GetPlaysThisWeek() {
  1981. $DBConnection = new clsDBConnection();
  1982. $Result = CCGetDBValue("SELECT Count(*) FROM Tickets WHERE Week(Ticket_DrawDate) = Week(NOW()) AND Year(Ticket_DrawDate)=Year(NOW()) AND Ticket_Played='Yes'", $DBConnection);
  1983. if ($Result) {
  1984. return $Result;
  1985. } else {
  1986. return "-";
  1987. }
  1988. }
  1989. }
  1990. #########
  1991. # Return Number of Non-Winning Tickets
  1992. #########
  1993. if (!function_exists('Custom_GetTotalNonWinningTickets')) {
  1994. function Custom_GetTotalNonWinningTickets() {
  1995. $DBConnection = new clsDBConnection();
  1996. $Result = CCGetDBValue("SELECT Count(*) FROM Tickets WHERE Ticket_Played='Yes' AND Ticket_Winner='No';", $DBConnection);
  1997. if ($Result) {
  1998. return $Result;
  1999. } else {
  2000. return "-";
  2001. }
  2002. }
  2003. }
  2004. #########
  2005. # Return Number of Non-Played Tickets
  2006. #########
  2007. if (!function_exists('Custom_GetTotalNonPlayedTickets')) {
  2008. function Custom_GetTotalNonPlayedTickets() {
  2009. $DBConnection = new clsDBConnection();
  2010. $Result = CCGetDBValue("SELECT Count(*) FROM Tickets WHERE Ticket_Played='No';", $DBConnection);
  2011. if ($Result) {
  2012. return $Result;
  2013. } else {
  2014. return "-";
  2015. }
  2016. }
  2017. }
  2018. #########
  2019. # Return Number of Winning Tickets
  2020. #########
  2021. if (!function_exists('Custom_GetTotalWinningTickets')) {
  2022. function Custom_GetTotalWinningTickets() {
  2023. $DBConnection = new clsDBConnection();
  2024. $Result = CCGetDBValue("SELECT Count(*) FROM Tickets WHERE Ticket_Winner='Yes';", $DBConnection);
  2025. if ($Result) {
  2026. return $Result;
  2027. } else {
  2028. return "-";
  2029. }
  2030. }
  2031. }
  2032. #########
  2033. # Simple validation to check correctness of email address
  2034. #########
  2035. if (!function_exists('Custom_ValidateEmail')) {
  2036. function Custom_ValidateEmail($Email_Address) {
  2037. return preg_match('/^[-!#$%&\'*+\\.\/0-9=?A-Z^_`{|}~]+'.
  2038. '@'.
  2039. '([-0-9A-Z]+\.)+'.
  2040. '([0-9A-Z]){2,4}$/i',strtolower(trim($Email_Address)));
  2041. }
  2042. }
  2043. #########
  2044. # Simple Random Text Generator for creating Ticket Serial #
  2045. #########
  2046. if (!function_exists('Custom_GenerateTicketSerial')) {
  2047. function Custom_GenerateTicketSerial() {
  2048. // Lets define the characters to use in the Ticket Serial #.
  2049. $Ticket_Array = str_split('ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZ012345678901234567890123456789');
  2050. $Ticket_Count = count($Ticket_Array);
  2051. $Ticket_SerialNumber = "";
  2052. for ($a=0; $a<6; $a++) {
  2053. $Ticket_SerialNumber .= $Ticket_Array[mt_rand(0,$Ticket_Count-1)];
  2054. }
  2055. $Ticket_SerialNumber .= "-";
  2056. for ($a=0; $a<6; $a++) {
  2057. $Ticket_SerialNumber .= $Ticket_Array[mt_rand(0,$Ticket_Count-1)];
  2058. }
  2059. // $Ticket_SerialNumber = implode('', array_slice($Ticket_Array,0,6)) . "-" . implode('',array_slice($Ticket_Array,7,6));
  2060. // $Ticket_SerialNumber = strtoupper(base_convert(mt_rand(0x39AA400, 0x81BF0FFF), 10, 36) . "-" . base_convert(mt_rand(0x39AA400, 0x81BF0FFF), 10, 36));
  2061. // $Ticket_SerialNumber = strtoupper(base_convert(mt_rand(0x19A100, 0x39AA3FF), 10, 36)) . "-" . strtoupper(base_convert(mt_rand(0x19A100, 0x39AA3FF), 10, 36))
  2062. return $Ticket_SerialNumber;
  2063. }
  2064. }
  2065. #########
  2066. # Simple Function to Calculate Odds
  2067. #########
  2068. if (!function_exists('Custom_CalculateOdds')) {
  2069. function Custom_CalculateOdds() {
  2070. $Odds = intval(1/(((pow(CONSTANT("phpScratchAndWin_HighNumber"),2)*12)-(CONSTANT("phpScratchAndWin_HighNumber")*24)+14)/pow(CONSTANT("phpScratchAndWin_HighNumber"),4)));
  2071. return $Odds;
  2072. }
  2073. }
  2074. #########
  2075. # Simple Function to Validate Ticket Serial Number
  2076. #########
  2077. if (!function_exists('Custom_ValidateTicket')) {
  2078. function Custom_ValidateTicket($Ticket) {
  2079. if (preg_match("/^[A-Z0-9]{6}-[A-Z0-9]{6}$/", $Ticket)==1) {
  2080. // Ticket Value
  2081. return TRUE;
  2082. } else {
  2083. return FALSE;
  2084. }
  2085. }
  2086. }
  2087. #########
  2088. # Simple Random Number Generator using random.org
  2089. #########
  2090. if (!function_exists('Custom_GetRandomNumber')) {
  2091. function Custom_GetRandomNumber($Min="1", $Max="500") {
  2092. if (CONSTANT("phpScratchAndWin_UseRandomOrg")=="1") {
  2093. // Open a socket to random.org waiting 5 seconds max - for connect and for retrieving number.
  2094. $fp = fsockopen("www.random.org", 80, $errno, $errstr, 5);
  2095. if ($fp) {
  2096. $request = "GET /cgi-bin/randnum?num=1&min=" . $Min . "&max=" . $Max . "&col=1 HTTP/1.0\r\n";
  2097. $request .= "Host: www.random.org\r\n";
  2098. $request .= "Referer: http://phpScratchAndWin.yourphppro.com/\r\n";
  2099. $request .= "User-Agent: " . CONSTANT("phpScratchAndWin_Title") . "\r\n\r\n";
  2100. fputs($fp, $request);
  2101. unset($request);
  2102. stream_set_timeout($fp,5);
  2103. // Get the retrieved information
  2104. while (!feof($fp)) {
  2105. $ReturnedValue .= fgets($fp, 128);
  2106. }
  2107. // Retrieve only the number. Delete everything else.
  2108. list(, $ReturnedValue) = explode("\r\n\r\n", $ReturnedValue,2);
  2109. if ($ReturnedValue==0) {
  2110. if (!function_exists('mt_rand')) {
  2111. $ReturnedValue=intval(rand($Min, $Max));
  2112. } else {
  2113. // Lets use mt_rand if it exists
  2114. $ReturnedValue=intval(mt_rand($Min, $Max));
  2115. }
  2116. }
  2117. } else {
  2118. // If we were not able to connect, or it timed out, lets create our own random number
  2119. if (!function_exists('mt_rand')) {
  2120. $ReturnedValue=intval(rand($Min, $Max));
  2121. } else {
  2122. // Lets use mt_rand if it exists
  2123. $ReturnedValue=intval(mt_rand($Min, $Max));
  2124. }
  2125. }
  2126. } else {
  2127. if (!function_exists('mt_rand')) {
  2128. $ReturnedValue=intval(rand($Min, $Max));
  2129. } else {
  2130. $ReturnedValue=intval(mt_rand($Min, $Max));
  2131. }
  2132. }
  2133. return $ReturnedValue;
  2134. }
  2135. }
  2136. #########
  2137. # Check to see what the latest version number is.
  2138. #########
  2139. if (!function_exists('Custom_VersionCheck')) {
  2140. function Custom_VersionCheck() {
  2141. // Check the version number and compare it to current application version.
  2142. // Return TRUE if it is current - Return FALSE if it is out-of-date.
  2143. $fp = fsockopen ("phpscratchandwin.yourphppro.com", 80, $errno, $errstr, 5);
  2144. if ($fp) {
  2145. fputs ($fp, "GET /version.txt HTTP/1.1\r\nReferer: " . CONSTANT("phpScratchAndWin_URL") . "\r\nHost: phpscratchandwin.yourphppro.com\r\n\r\n");
  2146. stream_set_timeout($fp,5);
  2147. // Retrieve only 1024 bytes of data after the headers
  2148. while($VersionCheck = fgets($fp,1024)) {
  2149. if($VersionCheck == "\r\n") {
  2150. break;
  2151. }
  2152. }
  2153. $VersionCheck = rtrim(fgets($fp, 1024));
  2154. } else {
  2155. // If we were not able to connect, or it timed out, lets set to default values
  2156. $VersionCheck=CONSTANT("phpScratchAndWin_VersionNumber");
  2157. }
  2158. $VersionCheck = explode(".", $VersionCheck);
  2159. $CurrentVersionCheck = explode(".", CONSTANT("phpScratchAndWin_VersionNumber"));
  2160. if (($CurrentVersionCheck[0] < $VersionCheck[0]) || ($CurrentVersionCheck[0] == $VersionCheck[0] && $CurrentVersionCheck[1] < $VersionCheck[1])) {
  2161. return FALSE;
  2162. } else {
  2163. return TRUE;
  2164. }
  2165. }
  2166. }
  2167. ?>