PageRenderTime 60ms CodeModel.GetById 21ms RepoModel.GetById 0ms app.codeStats 0ms

/framework/lib/function_lib.php

https://bitbucket.org/designbyheart/original
PHP | 1621 lines | 1383 code | 135 blank | 103 comment | 128 complexity | 54f62472d52d9e56833be90e0a1c3f54 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. Setting active item in left menu
  4. @param page name, link name: $selPage
  5. @returns activeClass
  6. */
  7. function activeMenu($selPage)
  8. {
  9. global $page;
  10. if ($page == $selPage) {
  11. return 'class="active"';
  12. }
  13. return "";
  14. }
  15. //getting users browser language
  16. function get_client_language($availableLanguages, $default = 'en')
  17. {
  18. if (isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])) {
  19. $langs = explode(',', $_SERVER['HTTP_ACCEPT_LANGUAGE']);
  20. foreach ($langs as $value) {
  21. $choice = substr($value, 0, 2);
  22. if (in_array($choice, $availableLanguages)) {
  23. return $choice;
  24. }
  25. }
  26. }
  27. return $default;
  28. }
  29. function skype($skypeName, $isChat = false)
  30. {
  31. if (!$isChat) {
  32. return '<script type="text/javascript" src="http://download.skype.com/share/skypebuttons/js/skypeCheck.js"></script>
  33. <a href="skype:' . $skypeName . '?call"><img src="http://download.skype.com/share/skypebuttons/buttons/call_blue_white_124x52.png" style="border: none;" width="124" height="52" alt="Skype Me™!" /></a>';
  34. } else {
  35. return '<script type="text/javascript" src="http://download.skype.com/share/skypebuttons/js/skypeCheck.js"></script>
  36. <a href="skype:' . $skypeName . '?chat"><img src="http://download.skype.com/share/skypebuttons/buttons/chat_blue_white_164x52.png" style="border: none;" width="164" height="52" alt="Chat with me" /></a>';
  37. }
  38. }
  39. function data_uri($file, $mime)
  40. {
  41. $contents = file_get_contents($file);
  42. $base64 = base64_encode($contents);
  43. echo "data:$mime;base64,$base64";
  44. }
  45. function userRoleSel($role, $type)
  46. {
  47. if ($role == $type) {
  48. return ' selected ';
  49. }
  50. }
  51. function getPageUrl()
  52. {
  53. $pageURL = 'http';
  54. if ($_SERVER["HTTPS"] == "on") {
  55. $pageURL .= "s";
  56. }
  57. $pageURL .= "://";
  58. if ($_SERVER["SERVER_PORT"] != "80") {
  59. $pageURL .= $_SERVER["SERVER_NAME"] . ":" . $_SERVER["SERVER_PORT"] . $_SERVER["REQUEST_URI"];
  60. } else {
  61. $pageURL .= $_SERVER["SERVER_NAME"] . $_SERVER["REQUEST_URI"];
  62. }
  63. return $pageURL;
  64. }
  65. function cleanQuery($string)
  66. {
  67. if (get_magic_quotes_gpc()) // prevents duplicate backslashes
  68. {
  69. $string = stripslashes($string);
  70. }
  71. if (phpversion() >= '4.3.0') {
  72. $string = mysql_real_escape_string($string);
  73. } else {
  74. $string = mysql_escape_string($string);
  75. }
  76. return $string;
  77. }
  78. function trans($sr, $en)
  79. {
  80. if (!isset($_SESSION['lang'])) {
  81. $_SESSION['lang'] = 'sr';
  82. }
  83. $translated = "";
  84. switch ($_SESSION['lang']) {
  85. case 'sr':
  86. default:
  87. $translated = $sr;
  88. break;
  89. case 'en':
  90. $translated = $en;
  91. break;
  92. }
  93. return $translated;
  94. }
  95. function redirect_to($location = null)
  96. {
  97. if ($location != null) {
  98. header("Location: {$location}");
  99. exit;
  100. }
  101. }
  102. function rearrange($arr)
  103. {
  104. foreach ($arr as $key => $all) {
  105. foreach ($all as $i => $val) {
  106. $new[$i][$key] = $val;
  107. }
  108. }
  109. return $new;
  110. }
  111. function uploadPhoto($file, $oldFile, $W, $tSW, $tSH, $tMW, $tMH, $fName)
  112. {
  113. if ($oldFile != '' && file_exists(ROOT_DIR . 'images/gallery/' . $oldFile)) {
  114. unlink(ROOT_DIR . 'images/gallery/' . $oldFile);
  115. }
  116. if ($oldFile != '' && file_exists(ROOT_DIR . 'images/gallery/thumbsS/' . $oldFile)) {
  117. unlink(ROOT_DIR . 'images/gallery/thumbsS/' . $oldFile);
  118. }
  119. if ($oldFile != '' && file_exists(ROOT_DIR . 'images/gallery/thumbsM/' . $oldFile)) {
  120. unlink(ROOT_DIR . 'images/gallery/thumbsM/' . $oldFile);
  121. }
  122. move_uploaded_file($file["tmp_name"], ROOT_DIR . "images/gallery/" . $fName);
  123. $targetPath = ROOT_DIR . 'images/gallery/';
  124. // echo "<img src=".$targetPath.$fName;
  125. $targetFile = str_replace('//', '/', $targetPath) . $fName;
  126. $targetThumbM = str_replace('//', '/', $targetPath . "thumbsM/") . $fName;
  127. $targetThumbS = str_replace('//', '/', $targetPath . "thumbsS/") . $fName;
  128. $filename = $targetFile;
  129. // if(!file_exists(ROOT_DIR.'images/gallery/'.$targetFile)){
  130. // return true;
  131. // }
  132. list($width, $height, $type, $attr) = getimagesize($targetFile);
  133. $t_filenameS = $targetThumbS;
  134. $t_filenameM = $targetThumbM;
  135. // Get new dimensions
  136. list($width, $height) = getimagesize($targetFile);
  137. $new_width = $W;
  138. //230, 245
  139. $thumbM_width = $tMW;
  140. $thumbS_width = $tSW;
  141. $ratio = $width / $new_width;
  142. $thumbS_ratio = $width / $thumbS_width;
  143. $thumbM_ratio = $width / $thumbM_width;
  144. $new_height = $height / $ratio;
  145. $thumbM_height = $height / $thumbM_ratio;
  146. $thumbS_height = $height / $thumbS_ratio;
  147. if ($thumbS_height > $tSH) {
  148. $thumbS_height = $tSH;
  149. $thS_ratio = $height / $tSH;
  150. $thumbS_width = $width / $thS_ratio;
  151. }
  152. if ($thumbM_height > $tMH) {
  153. $thumbM_height = $tMH;
  154. $thM_ratio = $height / $tMH;
  155. $thumbM_width = $width / $thM_ratio;
  156. }
  157. if ($file['type'] == 'image/jpeg') {
  158. $image_p = imagecreatetruecolor($new_width, $new_height);
  159. $image = imagecreatefromjpeg($filename);
  160. imagecopyresampled($image_p, $image, 0, 0, 0, 0, $new_width, $new_height, $width, $height);
  161. // Output
  162. imagejpeg($image_p, $filename, 100);
  163. #kreiranje thumba
  164. $image_tM = imagecreatetruecolor($thumbM_width, $thumbM_height);
  165. $image_tS = imagecreatetruecolor($thumbS_width, $thumbS_height);
  166. $thumbS = $image;
  167. $thumbM = $image;
  168. imagecopyresampled($image_tM, $thumbM, 0, 0, 0, 0, $thumbM_width, $thumbM_height, $width, $height);
  169. imagecopyresampled($image_tS, $thumbS, 0, 0, 0, 0, $thumbS_width, $thumbS_height, $width, $height);
  170. // Output
  171. imagejpeg($image_tS, $t_filenameS, 100);
  172. imagejpeg($image_tM, $t_filenameM, 100);
  173. // return true;
  174. }
  175. if ($file['type'] == 'image/gif') {
  176. $image_p = imagecreatetruecolor($new_width, $new_height);
  177. $trnprt_indx = imagecolortransparent($image_p);
  178. if ($trnprt_indx >= 0) {
  179. // Get the original image's transparent color's RGB values
  180. $trnprt_color = imagecolorsforindex($image, $trnprt_indx);
  181. // Allocate the same color in the new image resource
  182. $trnprt_indx = imagecolorallocate($image_p, $trnprt_color['red'], $trnprt_color['green'], $trnprt_color['blue']);
  183. // Completely fill the background of the new image with allocated color.
  184. imagefill($image_p, 0, 0, $trnprt_indx);
  185. // Set the background color for new image to transparent
  186. imagecolortransparent($image_p, $trnprt_indx);
  187. }
  188. //$image_p = imagecolortransparent($image_p, 0,0,0);
  189. $image = imagecreatefromgif($filename);
  190. imagecopyresampled($image_p, $image, 0, 0, 0, 0, $new_width, $new_height, $width, $height);
  191. // Output
  192. imagegif($image_p, $filename, 100);
  193. #kreiranje thumba
  194. $image_tS = imagecreatetruecolor($thumbS_width, $thumbS_height);
  195. $trnprt_indx = imagecolortransparent($image);
  196. if ($trnprt_indx >= 0) {
  197. // Get the original image's transparent color's RGB values
  198. $trnprt_color = imagecolorsforindex($image, $trnprt_indx);
  199. // Allocate the same color in the new image resource
  200. $trnprt_indx = imagecolorallocate($image_tS, $trnprt_color['red'], $trnprt_color['green'], $trnprt_color['blue']);
  201. $trnprt_indx = imagecolorallocate($image_tM, $trnprt_color['red'], $trnprt_color['green'], $trnprt_color['blue']);
  202. // Completely fill the background of the new image with allocated color.
  203. imagefill($image_tS, 0, 0, $trnprt_indx);
  204. imagefill($image_tM, 0, 0, $trnprt_indx);
  205. // Set the background color for new image to transparent
  206. imagecolortransparent($image_tS, $trnprt_indx);
  207. imagecolortransparent($image_tM, $trnprt_indx);
  208. }
  209. // $image_t = imagecolortransparent($thumb_width, $thumb_height, 0,0,0);
  210. $thumbS = $image;
  211. $thumbM = $image;
  212. imagecopyresampled($image_tS, $thumbS, 0, 0, 0, 0, $thumbS_width, $thumbS_height, $width, $height);
  213. imagecopyresampled($image_tM, $thumbM, 0, 0, 0, 0, $thumbM_width, $thumbM_height, $width, $height);
  214. // Output
  215. imagegif($image_tS, $t_filenameM, 100);
  216. imagegif($image_tM, $t_filenameS, 100);
  217. // return true;
  218. }
  219. if ($file['type'] == 'image/png') {
  220. $image = @imagecreatefrompng($filename);
  221. $image_p = imagecreatetruecolor($new_width, $new_height);
  222. // Turn off transparency blending (temporarily)
  223. imagealphablending($image_p, false);
  224. // Create a new transparent color for image
  225. $color = imagecolorallocatealpha($image_p, 0, 0, 0, 127);
  226. // Completely fill the background of the new image with allocated color.
  227. imagefill($image_p, 0, 0, $color);
  228. // Restore transparency blending
  229. imageSaveAlpha($image_p, true);
  230. imagecopyresampled($image_p, $image, 0, 0, 0, 0, $new_width, $new_height, $width, $height);
  231. // Output
  232. imagepng($image_p, $filename, 9);
  233. #kreiranje thumba
  234. $image_tS = imagecreatetruecolor($thumbS_width, $thumbS_height);
  235. $image_tM = imagecreatetruecolor($thumbM_width, $thumbM_height);
  236. $thumbM = $image;
  237. $thumbS = $image;
  238. // Turn off transparency blending (temporarily)
  239. imagealphablending($image_tM, false);
  240. imagealphablending($image_tS, false);
  241. // Create a new transparent color for image
  242. $color = imagecolorallocatealpha($image_tS, 0, 0, 0, 127);
  243. $color = imagecolorallocatealpha($image_tM, 0, 0, 0, 127);
  244. // Completely fill the background of the new image with allocated color.
  245. imagefill($image_tS, 0, 0, $color);
  246. imagefill($image_tM, 0, 0, $color);
  247. // Restore transparency blending
  248. imageSaveAlpha($image_tS, true);
  249. imageSaveAlpha($image_tM, true);
  250. @imagecopyresampled($image_tS, $thumbS, 0, 0, 0, 0, $thumbS_width, $thumbS_height, $width, $height);
  251. @imagecopyresampled($image_tM, $thumbM, 0, 0, 0, 0, $thumbM_width, $thumbM_height, $width, $height);
  252. // Output
  253. imagepng($image_tS, $t_filenameS, 9);
  254. imagepng($image_tM, $t_filenameM, 9);
  255. }
  256. }
  257. function uploadPhotoCat($file, $oldFile, $W, $fName)
  258. {
  259. // global $name;
  260. if ($oldFile != '' && file_exists(ROOT_DIR . 'images/gallery/' . $oldFile)) {
  261. unlink(ROOT_DIR . 'images/gallery/' . $oldFile);
  262. }
  263. move_uploaded_file($file["tmp_name"], ROOT_DIR . "images/gallery/" . $fName);
  264. $targetPath = ROOT_DIR . 'images/gallery/';
  265. // echo "<img src=".$targetPath.$fName;
  266. $targetFile = str_replace('//', '/', $targetPath) . $fName;
  267. $filename = $targetFile;
  268. // if(!file_exists(ROOT_DIR.'images/gallery/'.$targetFile)){
  269. // return true;
  270. // }
  271. list($width, $height, $type, $attr) = getimagesize($targetFile);
  272. // Get new dimensions
  273. list($width, $height) = getimagesize($targetFile);
  274. $new_width = $W;
  275. //230, 245
  276. $ratio = $width / $new_width;
  277. $new_height = $height / $ratio;
  278. if ($file['type'] == 'image/jpeg') {
  279. $image_p = imagecreatetruecolor($new_width, $new_height);
  280. $image = imagecreatefromjpeg($filename);
  281. imagecopyresampled($image_p, $image, 0, 0, 0, 0, $new_width, $new_height, $width, $height);
  282. // Output
  283. imagejpeg($image_p, $filename, 100);
  284. }
  285. if ($file['type'] == 'image/gif') {
  286. $image_p = imagecreatetruecolor($new_width, $new_height);
  287. $trnprt_indx = imagecolortransparent($image_p);
  288. if ($trnprt_indx >= 0) {
  289. // Get the original image's transparent color's RGB values
  290. $trnprt_color = imagecolorsforindex($image, $trnprt_indx);
  291. // Allocate the same color in the new image resource
  292. $trnprt_indx = imagecolorallocate($image_p, $trnprt_color['red'], $trnprt_color['green'], $trnprt_color['blue']);
  293. // Completely fill the background of the new image with allocated color.
  294. imagefill($image_p, 0, 0, $trnprt_indx);
  295. // Set the background color for new image to transparent
  296. imagecolortransparent($image_p, $trnprt_indx);
  297. }
  298. //$image_p = imagecolortransparent($image_p, 0,0,0);
  299. $image = imagecreatefromgif($filename);
  300. imagecopyresampled($image_p, $image, 0, 0, 0, 0, $new_width, $new_height, $width, $height);
  301. // Output
  302. imagegif($image_p, $filename, 100);
  303. }
  304. if ($file['type'] == 'image/png') {
  305. $image = @imagecreatefrompng($filename);
  306. $image_p = imagecreatetruecolor($new_width, $new_height);
  307. // Turn off transparency blending (temporarily)
  308. imagealphablending($image_p, false);
  309. // Create a new transparent color for image
  310. $color = imagecolorallocatealpha($image_p, 0, 0, 0, 127);
  311. // Completely fill the background of the new image with allocated color.
  312. imagefill($image_p, 0, 0, $color);
  313. // Restore transparency blending
  314. imageSaveAlpha($image_p, true);
  315. imagecopyresampled($image_p, $image, 0, 0, 0, 0, $new_width, $new_height, $width, $height);
  316. // Output
  317. imagepng($image_p, $filename, 9);
  318. }
  319. }
  320. function cleanFileName($file)
  321. {
  322. $file = preg_replace("/[^a-zA-Z0-9.\/_|+ -]/", '', $file);
  323. $file = strtolower(trim($file, '-'));
  324. return $file;
  325. }
  326. function imageResize($fileName, $NewWith, $NewHeight)
  327. {
  328. $W = $NewWith;
  329. $tSW = 100;
  330. $tSH = 60;
  331. $tMW = 180;
  332. $tMH = 100;
  333. $targetFile = ROOT_DIR . 'images/gallery/' . $fileName;
  334. list($width, $height, $type, $attr) = getimagesize($targetFile);
  335. // echo imgType($type);
  336. //echo $width;
  337. if ($width != 600) {
  338. $targetPath = ROOT_DIR . 'images/gallery/';
  339. $targetFile = str_replace('//', '/', $targetPath) . $fileName;
  340. $targetThumbM = str_replace('//', '/', $targetPath . "thumbsM/") . $fileName;
  341. $targetThumbS = str_replace('//', '/', $targetPath . "thumbsS/") . $fileName;
  342. $new_width = $W;
  343. //230, 245
  344. $thumbM_width = $tMW;
  345. $thumbS_width = $tSW;
  346. $ratio = $width / $new_width;
  347. $thumbS_ratio = $width / $thumbS_width;
  348. $thumbM_ratio = $width / $thumbM_width;
  349. $new_height = $height / $ratio;
  350. $thumbM_height = $height / $thumbM_ratio;
  351. $thumbS_height = $height / $thumbS_ratio;
  352. if ($thumbS_height > $tSH) {
  353. $thumbS_height = $tSH;
  354. $thS_ratio = $height / $tSH;
  355. $thumbS_width = $width / $thS_ratio;
  356. }
  357. if ($thumbM_height > $tMH) {
  358. $thumbM_height = $tMH;
  359. $thM_ratio = $height / $tMH;
  360. $thumbM_width = $width / $thM_ratio;
  361. }
  362. if (imgType($type) == 'jpg') {
  363. $image_p = imagecreatetruecolor($new_width, $new_height);
  364. $image = imagecreatefromjpeg($targetFile);
  365. imagecopyresampled($image_p, $image, 0, 0, 0, 0, $new_width, $new_height, $width, $height);
  366. // Output
  367. imagejpeg($image_p, $targetFile, 100);
  368. #kreiranje thumba
  369. $image_tM = imagecreatetruecolor($thumbM_width, $thumbM_height);
  370. $image_tS = imagecreatetruecolor($thumbS_width, $thumbS_height);
  371. $thumbS = $image;
  372. $thumbM = $image;
  373. imagecopyresampled($image_tM, $thumbM, 0, 0, 0, 0, $thumbM_width, $thumbM_height, $width, $height);
  374. imagecopyresampled($image_tS, $thumbS, 0, 0, 0, 0, $thumbS_width, $thumbS_height, $width, $height);
  375. // Output
  376. imagejpeg($image_tS, $targetThumbS, 100);
  377. imagejpeg($image_tM, $targetThumbM, 100);
  378. }
  379. }
  380. if ($type == 'gif') {
  381. $image_p = imagecreatetruecolor($new_width, $new_height);
  382. $trnprt_indx = imagecolortransparent($image_p);
  383. if ($trnprt_indx >= 0) {
  384. // Get the original image's transparent color's RGB values
  385. $trnprt_color = imagecolorsforindex($image, $trnprt_indx);
  386. // Allocate the same color in the new image resource
  387. $trnprt_indx = imagecolorallocate($image_p, $trnprt_color['red'], $trnprt_color['green'], $trnprt_color['blue']);
  388. // Completely fill the background of the new image with allocated color.
  389. imagefill($image_p, 0, 0, $trnprt_indx);
  390. // Set the background color for new image to transparent
  391. imagecolortransparent($image_p, $trnprt_indx);
  392. //$image_p = imagecolortransparent($image_p, 0,0,0);
  393. $image = imagecreatefromgif($targetFile);
  394. imagecopyresampled($image_p, $image, 0, 0, 0, 0, $new_width, $new_height, $width, $height);
  395. // Output
  396. imagegif($image_p, $targetFile, 100);
  397. #kreiranje thumba
  398. $image_tS = imagecreatetruecolor($thumbS_width, $thumbS_height);
  399. $trnprt_indx = imagecolortransparent($image);
  400. if ($trnprt_indx >= 0) {
  401. // Get the original image's transparent color's RGB values
  402. $trnprt_color = imagecolorsforindex($image, $trnprt_indx);
  403. // Allocate the same color in the new image resource
  404. $trnprt_indx = imagecolorallocate($image_tS, $trnprt_color['red'], $trnprt_color['green'], $trnprt_color['blue']);
  405. $trnprt_indx = imagecolorallocate($image_tM, $trnprt_color['red'], $trnprt_color['green'], $trnprt_color['blue']);
  406. // Completely fill the background of the new image with allocated color.
  407. imagefill($image_tS, 0, 0, $trnprt_indx);
  408. imagefill($image_tM, 0, 0, $trnprt_indx);
  409. // Set the background color for new image to transparent
  410. imagecolortransparent($image_tS, $trnprt_indx);
  411. imagecolortransparent($image_tM, $trnprt_indx);
  412. }
  413. // $image_t = imagecolortransparent($thumb_width, $thumb_height, 0,0,0);
  414. $thumbS = $image;
  415. $thumbM = $image;
  416. imagecopyresampled($image_tS, $thumbS, 0, 0, 0, 0, $thumbS_width, $thumbS_height, $width, $height);
  417. imagecopyresampled($image_tM, $thumbM, 0, 0, 0, 0, $thumbM_width, $thumbM_height, $width, $height);
  418. // Output
  419. imagegif($image_tS, $targetThumbS, 100);
  420. imagegif($image_tM, $targetThumbM, 100);
  421. // return true;
  422. }
  423. if ($type == 'png') {
  424. $image = @imagecreatefrompng($targetFile);
  425. $image_p = imagecreatetruecolor($new_width, $new_height);
  426. // Turn off transparency blending (temporarily)
  427. imagealphablending($image_p, false);
  428. // Create a new transparent color for image
  429. $color = imagecolorallocatealpha($image_p, 0, 0, 0, 127);
  430. // Completely fill the background of the new image with allocated color.
  431. imagefill($image_p, 0, 0, $color);
  432. // Restore transparency blending
  433. imageSaveAlpha($image_p, true);
  434. imagecopyresampled($image_p, $image, 0, 0, 0, 0, $new_width, $new_height, $width, $height);
  435. // Output
  436. imagepng($image_p, $targetFile, 9);
  437. #kreiranje thumba
  438. $image_tS = imagecreatetruecolor($thumbS_width, $thumbS_height);
  439. $image_tM = imagecreatetruecolor($thumbM_width, $thumbM_height);
  440. $thumbM = $image;
  441. $thumbS = $image;
  442. // Turn off transparency blending (temporarily)
  443. imagealphablending($image_tM, false);
  444. imagealphablending($image_tS, false);
  445. // Create a new transparent color for image
  446. $color = imagecolorallocatealpha($image_tS, 0, 0, 0, 127);
  447. $color = imagecolorallocatealpha($image_tM, 0, 0, 0, 127);
  448. // Completely fill the background of the new image with allocated color.
  449. imagefill($image_tS, 0, 0, $color);
  450. imagefill($image_tM, 0, 0, $color);
  451. // Restore transparency blending
  452. imageSaveAlpha($image_tS, true);
  453. imageSaveAlpha($image_tM, true);
  454. @imagecopyresampled($image_tS, $thumbS, 0, 0, 0, 0, $thumbS_width, $thumbS_height, $width, $height);
  455. @imagecopyresampled($image_tM, $thumbM, 0, 0, 0, 0, $thumbM_width, $thumbM_height, $width, $height);
  456. // Output
  457. imagepng($image_tS, $targetThumbS, 9);
  458. imagepng($image_tM, $targetThumbM, 9);
  459. }
  460. }
  461. }
  462. function imgType($id)
  463. {
  464. switch ($id) {
  465. case 1:
  466. return "gif";
  467. break;
  468. case 2:
  469. return "jpg";
  470. break;
  471. case 3:
  472. return "png";
  473. break;
  474. }
  475. }
  476. function trunc($string, $length)
  477. {
  478. settype($string, 'string');
  479. settype($length, 'integer');
  480. $output = '';
  481. for ($a = 0; $a < $length AND $a < strlen($string); $a++) {
  482. $output .= $string[$a];
  483. }
  484. if (strlen($string) > $length) {
  485. $output .= '...';
  486. }
  487. return ($output);
  488. }
  489. function formatDate($date)
  490. {
  491. $month = date('M ', strtotime($date));
  492. if (isset($_SESSION['lang']) && $_SESSION['lang'] == 'sr') {
  493. $months = array('Januar', 'Februar', 'Mart', 'April', 'Maj', 'Jun', 'Jul', 'Avgust', 'Septembar', 'Oktobar', 'Novembar', 'Decembar');
  494. $month = $months[date("n", strtotime($date)) - 1];
  495. }
  496. $date = date('d. ', strtotime($date)) . $month . date(' Y. ', strtotime($date));
  497. return $date;
  498. }
  499. function timeStampToDate($tS, $time = NULL)
  500. {
  501. if ($tS == 0) {
  502. return '';
  503. }
  504. $month = date('M ', ($tS));
  505. if (isset($_SESSION['lang']) && $_SESSION['lang'] == 'sr') {
  506. $months = array('Januar', 'Februar', 'Mart', 'April', 'Maj', 'Jun', 'Jul', 'Avgust', 'Septembar', 'Oktobar', 'Novembar', 'Decembar');
  507. $month = $months[date("n", ($tS)) - 1];
  508. }
  509. if ($time) {
  510. return date('d. ', $tS) . $month . date(' Y. ', ($tS)) . date("H:m:s", $tS);
  511. }
  512. $tS = date('d. ', $tS) . $month . date(' Y. ', ($tS));
  513. return $tS;
  514. }
  515. function getImage($refID, $ref, $count)
  516. {
  517. $img = Gallery::find_by_reference($ref, $refID, $count);
  518. if (!$img) {
  519. $img = "defaultCat.png";
  520. } else {
  521. if ($count < 2) {
  522. if (count($img) > 1) {
  523. $img = array_shift($img);
  524. }
  525. $img = $img->file;
  526. } else {
  527. $images = array();
  528. foreach ($img as $i) {
  529. $images[] = $i->file;
  530. }
  531. $img = $images;
  532. }
  533. }
  534. return $img;
  535. }
  536. function getGallery($id, $type)
  537. {
  538. $gallery = array_filter(Gallery::find_by_sql("SELECT id, file from gallery where refID = '" . $id . "' and type = '{$type}'"));
  539. if (count($gallery) > 1) {
  540. $gallery = array_shift($gallery);
  541. }
  542. // $gallery = Gallery::find_by_sql("SELECT id, file from gallery where refID = '" . $id . "' and type = '{$type}'");
  543. // $gallery = array_shift($gallery);
  544. if (isset($gallery) && $gallery) {
  545. if (is_array($gallery)) {
  546. $g = $gallery[0];
  547. return $g->file;
  548. } else {
  549. return $gallery->file;
  550. }
  551. } else {
  552. return NULL;
  553. }
  554. }
  555. function getGalleryList($id, $type)
  556. {
  557. // $gallery = array_shift(Gallery::find_by_sql("SELECT id, file from gallery where refID = '" . $id . "' and type = '{$type}'"));
  558. $gallery = Gallery::find_by_sql("SELECT id, file from gallery where refID = '" . $id . "' and type = '{$type}'");
  559. $galleryList = array();
  560. foreach ($gallery as $g) {
  561. $galleryList[] = $g->file;
  562. }
  563. if (count($galleryList)) {
  564. return $galleryList;
  565. } else {
  566. return NULL;
  567. }
  568. }
  569. function breadCrumb($path)
  570. {
  571. global $page;
  572. for ($i = count($path) - 1; $i > -1; $i--) {
  573. $c = $path[$i];
  574. if (count($path) > 1 || $page == 'proizvod') {
  575. echo '<a href="' . SITE_ROOT . 'kategorija/' . $c->id . '/' . urlSafe(trans($c->name_sr, $c->name_en)) . '">' . trans($c->name_sr, $c->name_en) . '</a>';
  576. } else {
  577. echo '<a class="active" href="#">' . trans($c->name_sr, $c->name_en) . '</a>';
  578. }
  579. }
  580. }
  581. function urlSafe($str, $replace = array(), $delimiter = '-')
  582. {
  583. setlocale(LC_ALL, 'en_US.UTF8');
  584. if (!empty($replace)) {
  585. $str = str_replace((array)$replace, ' ', $str);
  586. }
  587. $clean = iconv('UTF-8', 'ASCII//TRANSLIT', $str);
  588. $clean = preg_replace("/[^a-zA-Z0-9\/_|+ -]/", '', $clean);
  589. $clean = strtolower(trim($clean, '-'));
  590. $clean = preg_replace("/[\/_|+ -]+/", $delimiter, $clean);
  591. return $clean;
  592. }
  593. function findSubCatsOption($category = NULL)
  594. {
  595. ?>
  596. <option value="0">Izaberi kategoriju</option>
  597. <?php
  598. $categories = Category::find_by_sql("SELECT id, name_sr, parent_cat FROM category where parent_cat = 0 order by name_sr ASC");
  599. foreach ($categories as $cat) : ?>
  600. <option value="<?=$cat->id?>"
  601. <?php if ($category && $category->id > 0) {
  602. if (isset($category->id) && $cat->id == $category->parent_cat) {
  603. echo 'selected';
  604. }
  605. }?>
  606. ><?=$cat->name_sr;?> [glavna]
  607. </option>
  608. <?php
  609. $sCats = Category::find_children($cat->id);
  610. if ($sCats) {
  611. foreach ($sCats as $sC) {
  612. if ($cat->parent_id > 0) {
  613. $inset = '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&rarr;';
  614. } else {
  615. $inset = '&nbsp;&nbsp;&rarr;';
  616. }
  617. $sel = '';
  618. if ($sC->id == $_GET['id']) {
  619. $sel = ' selected';
  620. }
  621. ?>
  622. <option value="<?=$sC->id?>"<?=$sel?>><?=$inset . $sC->name_sr?></option>
  623. <?php
  624. $sCs = Category::find_children($sC->id);
  625. if ($sCs) {
  626. foreach ($sCs as $ssC) {
  627. if ($sC->parent_id > 0) {
  628. $inset = '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&rarr;';
  629. } else {
  630. $inset = '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&rarr;';
  631. }
  632. $sel = '';
  633. if ($ssC->id == $_GET['id']) {
  634. $sel = ' selected';
  635. }
  636. ?>
  637. <option value="<?=$ssC->id?>"<?=$sel?> style="color:red"><?=$inset . $ssC->name_sr?></option>
  638. <?php
  639. //showing sub sub categories
  640. $ssCs = Category::find_children($ssC->id);
  641. if ($ssCs) {
  642. foreach ($ssCs as $ssCs) {
  643. $inset = '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&rarr;';
  644. $sel = '';
  645. if ($ssCs->id == $_GET['id']) {
  646. $sel = ' selected';
  647. }
  648. ?>
  649. <option value="<?=$ssCs->id?>"<?=$sel?>
  650. style="color:red"><?=$inset . $ssCs->name_sr?></option>
  651. <?php
  652. }
  653. $sssCs = Category::find_children($ssCs->id);
  654. if ($sssCs) {
  655. foreach ($sssCs as $sssCs) {
  656. $inset = '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&rarr;';
  657. $sel = '';
  658. if ($sssCs->id == $_GET['id']) {
  659. $sel = ' selected';
  660. }
  661. ?>
  662. <option value="<?=$sssCs->id?>"<?=$sel?>
  663. style="color:red"><?=$inset . $sssCs->name_sr?></option>
  664. <?php
  665. }
  666. }
  667. }
  668. }
  669. }
  670. }
  671. }
  672. endforeach;
  673. }
  674. function similarProducts($product, $limit)
  675. {
  676. // <<<<<<< HEAD
  677. $sql = "SELECT * from product where product.category = (select id from category where name_sr = '" . $product->category . "') and id !=" . $product->id . " LIMIT " . $limit;
  678. $prods = Product::find_by_sql($sql);
  679. // =======
  680. // $prods = Product::find_by_sql("SELECT * from product where product.name_sr !='{$product->name_sr}' AND product.category in (select id from category where category.name_sr = '{$product->category}'");
  681. // >>>>>>> 568b584f21a2a444fe7a05bbd33ee55b6901c069
  682. if ($prods) {
  683. echo '<h2>' . trans("Ostali proizvodi iz ove kategorije", 'Other products in this category') . '</h2>';
  684. echo '<div class="proizvodi">';
  685. foreach ($prods as $p):
  686. $img = SITE_ROOT . 'images/gallery/thumbsM/defaultCat.png';
  687. $gallery = getGallery($p->id, 'product');
  688. if ($gallery) {
  689. $img = SITE_ROOT . 'images/gallery/' . $gallery;
  690. } ?>
  691. <div class="box">
  692. <span class="title">
  693. <a href="<?=SITE_ROOT?>proizvod/<?=$p->id?>/<?=cleanFileName(trans($p->name_sr, $p->name_en))?>">
  694. <?=trans($p->name_sr, $p->name_en);?>
  695. </a>
  696. </span>
  697. <a href="<?=SITE_ROOT?>proizvod/<?=$p->id?>/<?=cleanFileName(trans($p->name_sr, $p->name_en))?>"
  698. class="img-link">
  699. <span>
  700. <img src="<?=$img?>" alt="<?=trans($p->name_sr, $p->name_en)?>"/>
  701. </span>
  702. </a>
  703. <?php //TODO:: dodati kasnije poruci link ?>
  704. <span class="korpa" style="display:none"><a href="#">poruči <span
  705. class="icon-shopping-cart"></span></a></span>
  706. </div>
  707. <?php endforeach;
  708. echo '</div>';
  709. }
  710. }
  711. function isCLientLogin()
  712. {
  713. global $session;
  714. if (isset($session->client_id) && $session->client_id != '' || isset($_SESSION['clientID'])) {
  715. return $_SESSION['clientID'];
  716. }
  717. return false;
  718. }
  719. function checkEmail($email)
  720. {
  721. //Perform a basic syntax-Check
  722. //If this check fails, there's no need to continue
  723. if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
  724. return false;
  725. }
  726. //extract host
  727. list($email, $host) = explode("@", $email);
  728. //check, if host is accessible
  729. if (!checkdnsrr($host, "MX") && !checkdnsrr($host, "A")) {
  730. return false;
  731. }
  732. return true;
  733. }
  734. function sendMail($to, $mail_subject, $template, $header, $redirectSucc, $redirectErr)
  735. {
  736. $send = 0;
  737. $result = mail($to, $mail_subject, $template, $header);
  738. if ($result) {
  739. if ($redirectSucc != '') {
  740. $_SESSION['message'] = trans("Poruka je uspešno poslata.", 'Message is sent successfully.');
  741. $_SESSION['mType'] = 2;
  742. redirect_to($redirectSucc);
  743. }
  744. } else {
  745. if ($redirectErr != '') {
  746. $_SESSION['message'] = trans("Poruka nije poslata. Pokusajte ponovo", 'Message has NOT been sent. Please try again');
  747. $_SESSION['mType'] = 4;
  748. redirect_to($redirectErr);
  749. }
  750. }
  751. }
  752. function clearFileName($string, $force_lowercase = true, $anal = false)
  753. {
  754. $strip = array("~", "`", "!", "@", "#", "$", "%", "^", "&", "*", "(", ")", "_", "=", "+", "[", "{", "]",
  755. "}", "\\", "|", ";", ":", "\"", "'", "&#8216;", "&#8217;", "&#8220;", "&#8221;", "&#8211;", "&#8212;",
  756. "—", "–", ",", "<", ">", "/", "?");
  757. $clean = trim(str_replace($strip, "", strip_tags($string)));
  758. $clean = preg_replace('/\s+/', "-", $clean);
  759. $clean = ($anal) ? preg_replace("/[^a-zA-Z0-9]/", "", $clean) : $clean;
  760. return ($force_lowercase) ?
  761. (function_exists('mb_strtolower')) ?
  762. mb_strtolower($clean, 'UTF-8') :
  763. strtolower($clean) :
  764. $clean;
  765. }
  766. function makeSearch($term)
  767. {
  768. $results = array();
  769. $searchProducts = Product::search($term);
  770. if ($searchProducts) {
  771. $results[] = array("products" => $searchProducts);
  772. }
  773. return $results;
  774. }
  775. function encode($val, $base = 62, $chars = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ')
  776. {
  777. // can't handle numbers larger than 2^31-1 = 2147483647
  778. $str = '';
  779. do {
  780. $i = $val % $base;
  781. $str = $chars[$i] . $str;
  782. $val = ($val - $i) / $base;
  783. } while ($val > 0);
  784. return $str;
  785. }
  786. function decode($str, $base = 62, $chars = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ')
  787. {
  788. $len = strlen($str);
  789. $val = 0;
  790. $arr = array_flip(str_split($chars));
  791. for ($i = 0; $i < $len; ++$i) {
  792. $val += $arr[$str[$i]] * pow($base, $len - $i - 1);
  793. }
  794. return $val;
  795. }
  796. function cleanInput($input)
  797. {
  798. $search = array(
  799. '@<script[^>]*?>.*?</script>@si', // Strip out javascript
  800. '@<[\/\!]*?[^<>]*?>@si', // Strip out HTML tags
  801. '@<style[^>]*?>.*?</style>@siU', // Strip style tags properly
  802. '@<![\s\S]*?--[ \t\n\r]*>@' // Strip multi-line comments
  803. );
  804. $output = preg_replace($search, '', $input);
  805. return $output;
  806. }
  807. function galleryImg($g, $type, $thumbs = TRUE, $limit = NULL)
  808. {
  809. if (!$limit) {
  810. $limit = 1;
  811. }
  812. $gallery = Gallery::find_by_reference($g, $type, $limit);
  813. if (!$gallery) {
  814. return '<img src="' . SITE_ROOT . 'assets/img/defaultCat.jpg" >';
  815. }
  816. if (count($gallery) == 1) {
  817. return '<img src="' . SITE_ROOT . 'images/gallery/thumbsM/' . $gallery->file . '" >';
  818. }
  819. foreach ($gallery as $gl) {
  820. if ($thumbs == TRUE) {
  821. return '<img src="' . SITE_ROOT . 'images/gallery/thumbsM/' . $gl->file . '" >';
  822. } else {
  823. return '<img src="' . SITE_ROOT . 'images/gallery/' . $gl->file . '" >';
  824. }
  825. }
  826. }
  827. function printClean($ar)
  828. {
  829. echo "<pre>";
  830. print_r($ar);
  831. echo "</pre>";
  832. }
  833. function normalize($name)
  834. {
  835. return ucfirst(strtolower(strip_tags(trim($name))));
  836. }
  837. function isLogged()
  838. {
  839. global $session;
  840. if ($session->user_id == '') {
  841. return false;
  842. } else {
  843. $user = User::find_by_id($session->user_id);
  844. return $user;
  845. }
  846. }
  847. function getCategoryName($id)
  848. {
  849. $c = Category::find_by_id($id);
  850. if ($c) {
  851. return trans($c->name_sr, $c->name_en);
  852. } else {
  853. return '';
  854. }
  855. }
  856. function translateField($field)
  857. {
  858. switch ($field) {
  859. case 'speedCopyA4Color':
  860. return trans('Brzina kopiranja A4 kolor', '');
  861. break;
  862. case 'speedCopyA4Black':
  863. return trans('Brzina kopiranja A4 crno belo', '');
  864. break;
  865. case 'speedCopyA3Color':
  866. return trans('Brzina kopiranja A3 kolor', '');
  867. break;
  868. case 'speedCopyA3Black':
  869. return trans('Brzina kopiranja A3 crno belo', '');
  870. break;
  871. case 'firstCopyColor':
  872. return trans('Vreme prve kopije kolor', '');
  873. break;
  874. case 'firstCopyBlack':
  875. return trans('Vreme prve kopije crno belo', '');
  876. break;
  877. case 'heatingTime':
  878. return trans('Vreme zagrevanja', '');
  879. break;
  880. case 'copyResolution':
  881. return trans('Rezolucija kopiranja', '');
  882. break;
  883. case 'gradation':
  884. return trans('Gradacija', '');
  885. break;
  886. case 'mutliplyCopy':
  887. return trans('Multipliciranje kopije', '');
  888. break;
  889. case 'formatOrig':
  890. return trans('Format originala', '');
  891. break;
  892. case 'zoom':
  893. return trans('Uvećanje', '');
  894. break;
  895. case 'copyFunction':
  896. return trans('Funkcije kopiranja', '');
  897. break;
  898. case 'printSpeedA4Color':
  899. return trans('Brzina štampanja A4 kolor', '');
  900. break;
  901. case 'printSpeedA4Black':
  902. return trans('Brzina štampanja A4 crno belo', '');
  903. break;
  904. case 'printSpeedA3Color':
  905. return trans('Brzina štampanja A3 kolor', '');
  906. break;
  907. case 'printSpeedA3Black':
  908. return trans('Brzina štampanja A3 crno belo', '');
  909. break;
  910. case 'firstCopyPrintColor':
  911. return trans('Vreme prvog otiska kolor', '');
  912. break;
  913. case 'firstCopyPrintBlack':
  914. return trans('Vreme prvog otiska crno belo', '');
  915. break;
  916. case 'printRes':
  917. return trans('Rezolucija štampanja', '');
  918. break;
  919. case 'processor':
  920. return trans('Procesor', '');
  921. break;
  922. case 'driver':
  923. return trans('Drajver', '');
  924. break;
  925. case 'os':
  926. return trans('Operativni sistemi', '');
  927. break;
  928. case 'fonts':
  929. return trans('Fontovi štampača', '');
  930. break;
  931. case 'printFunctions':
  932. return trans('Funkcije štampe', '');
  933. break;
  934. case 'scanSpeedColor':
  935. return trans('Brzina skeniranja kolor', '');
  936. break;
  937. case 'scanSpeedBlack':
  938. return trans('Brzina skeniranja crno belo', '');
  939. break;
  940. case 'scanRes':
  941. return trans('Rezolucija skeniranja', '');
  942. break;
  943. case 'scanMethods':
  944. return trans('Načini skeniranja', '');
  945. break;
  946. case 'scanFormats':
  947. return trans('Formati skeniranog fajla', '');
  948. break;
  949. case 'scanDestination':
  950. return trans('Destinacije skeniranja', '');
  951. break;
  952. case 'faxStandard':
  953. return trans('Faks standard', '');
  954. break;
  955. case 'faxTransmit':
  956. return trans('Prenos faksa', '');
  957. break;
  958. case 'faxRes':
  959. return trans('Rezolucija faksa (maksimalna)', '');
  960. break;
  961. case 'faxCompression':
  962. return trans('Kompresija faksa', '');
  963. break;
  964. case 'faxModem':
  965. return trans('Faks modem', '');
  966. break;
  967. case 'faxDestination':
  968. return trans('Destinacije faksiranja', '');
  969. break;
  970. case 'faxFunctions':
  971. return trans('Funkcije faksa', '');
  972. break;
  973. case 'hddMax':
  974. return trans('Maksimalan broj lokacija za skladištenje na HDD', '');
  975. break;
  976. case 'memory':
  977. return trans('Memorija', '');
  978. break;
  979. case 'documentsMax':
  980. return trans('Maksimalan broj dokumenata koje je moguće sačuvati', '');
  981. break;
  982. case 'storageType':
  983. return trans('Tipovi sistemskih skladišta', '');
  984. break;
  985. case 'storageSystemType':
  986. return trans('Tipovi sistemskih skladišta', '');
  987. break;
  988. case 'hddFunctions':
  989. return trans('Funkcionalnost hard diska', '');
  990. break;
  991. case 'hdd':
  992. return trans('Hard disk', '');
  993. break;
  994. case 'compConnection':
  995. return trans('Povezivanje sa računarom', '');
  996. break;
  997. case 'networkProtocols':
  998. return trans('Mrežni protokoli', '');
  999. break;
  1000. case 'paperFormat':
  1001. return trans('Format papira', '');
  1002. break;
  1003. case 'paperWeight':
  1004. return trans('Težina papira', '');
  1005. break;
  1006. case 'inputCapacity':
  1007. return trans('Kapacitet ulaznog papira', '');
  1008. break;
  1009. case 'outputCapacity':
  1010. return trans('Kapacitet izlaznog papira', '');
  1011. break;
  1012. case 'monthly':
  1013. return trans('Maksimalni mesečni obim', '');
  1014. break;
  1015. case 'initialToner':
  1016. return trans('Inicijalni toner', '');
  1017. break;
  1018. case 'tonerDeclaration':
  1019. return trans('Deklaracija tonera (5%)', '');
  1020. break;
  1021. case 'energyConsumption':
  1022. return trans('Potrošnja električne energije', '');
  1023. break;
  1024. case 'dimensions':
  1025. return trans('Dimenzije uređaja (Š x D x V) mm', '');
  1026. break;
  1027. case 'weight':
  1028. return trans('Težina uređaja', '');
  1029. break;
  1030. case 'security':
  1031. return trans('Bezbednost', '');
  1032. break;
  1033. case 'software':
  1034. return trans('Prateći softver', '');
  1035. break;
  1036. case 'users':
  1037. return trans('Upravljanje korisnicima', '');
  1038. break;
  1039. case 'optional':
  1040. return trans('Opcioni uređaji', '');
  1041. break;
  1042. }
  1043. }
  1044. function findImageForProduct($id)
  1045. {
  1046. $galls = Gallery::find_by_productID($id, 'product');
  1047. if (count($galls) > 0) {
  1048. if ($galls) {
  1049. $g = array_shift($galls);
  1050. return $g->file;
  1051. }
  1052. }
  1053. return false;
  1054. }
  1055. function formatMoney($number, $fractional = false)
  1056. {
  1057. if ($fractional) {
  1058. $number = sprintf('%.2f', $number);
  1059. }
  1060. while (true) {
  1061. $replaced = preg_replace('/(-?\d+)(\d\d\d)/', '$1.$2', $number);
  1062. if ($replaced != $number) {
  1063. $number = $replaced;
  1064. } else {
  1065. break;
  1066. }
  1067. }
  1068. return $number;
  1069. }
  1070. function intToDate($timeInt)
  1071. {
  1072. return date('d.m.Y', $timeInt);
  1073. }
  1074. function rand_uniqid($in, $to_num = false, $pad_up = false, $passKey = null)
  1075. {
  1076. $index = "abcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
  1077. if ($passKey !== null) {
  1078. // Although this function's purpose is to just make the
  1079. // ID short - and not so much secure,
  1080. // you can optionally supply a password to make it harder
  1081. // to calculate the corresponding numeric ID
  1082. for ($n = 0; $n < strlen($index); $n++) {
  1083. $i[] = substr($index, $n, 1);
  1084. }
  1085. $passhash = hash('sha256', $passKey);
  1086. $passhash = (strlen($passhash) < strlen($index))
  1087. ? hash('sha512', $passKey)
  1088. : $passhash;
  1089. for ($n = 0; $n < strlen($index); $n++) {
  1090. $p[] = substr($passhash, $n, 1);
  1091. }
  1092. array_multisort($p, SORT_DESC, $i);
  1093. $index = implode($i);
  1094. }
  1095. $base = strlen($index);
  1096. if ($to_num) {
  1097. // Digital number <<-- alphabet letter code
  1098. $in = strrev($in);
  1099. $out = 0;
  1100. $len = strlen($in) - 1;
  1101. for ($t = 0; $t <= $len; $t++) {
  1102. $bcpow = bcpow($base, $len - $t);
  1103. $out = $out + strpos($index, substr($in, $t, 1)) * $bcpow;
  1104. }
  1105. if (is_numeric($pad_up)) {
  1106. $pad_up--;
  1107. if ($pad_up > 0) {
  1108. $out -= pow($base, $pad_up);
  1109. }
  1110. }
  1111. $out = sprintf('%F', $out);
  1112. $out = substr($out, 0, strpos($out, '.'));
  1113. } else {
  1114. // Digital number -->> alphabet letter code
  1115. if (is_numeric($pad_up)) {
  1116. $pad_up--;
  1117. if ($pad_up > 0) {
  1118. $in += pow($base, $pad_up);
  1119. }
  1120. }
  1121. $out = "";
  1122. for ($t = floor(log($in, $base)); $t >= 0; $t--) {
  1123. $bcp = bcpow($base, $t);
  1124. $a = floor($in / $bcp) % $base;
  1125. $out = $out . substr($index, $a, 1);
  1126. $in = $in - ($a * $bcp);
  1127. }
  1128. $out = strrev($out); // reverse
  1129. }
  1130. return $out;
  1131. }
  1132. function price($product)
  1133. {
  1134. global $client;
  1135. if ($client) {
  1136. $prices = Price::find_by_product_with_group($product, $client->client_category);
  1137. if ($prices) {
  1138. if ($_SESSION['lang'] != 'sr') {
  1139. $pr = $prices->amount / Euro::latest();
  1140. return round($pr, 2);
  1141. } else {
  1142. return $prices->amount;
  1143. }
  1144. }
  1145. }
  1146. return false;
  1147. }
  1148. function alphaID($in, $to_num = false, $pad_up = false, $passKey = null)
  1149. {
  1150. if ($in == '') {
  1151. return;
  1152. }
  1153. $index = "bcdfghijklmnpqrstvwxyz0123456789BCDFGHIJKLMNPQRSTVWXYZ";
  1154. $base = strlen($index);
  1155. if ($to_num) {
  1156. // Digital number <<-- alphabet letter code
  1157. $in = strrev($in);
  1158. $out = 0;
  1159. $len = strlen($in) - 1;
  1160. for ($t = 0; $t <= $len; $t++) {
  1161. $bcpow = bcpow($base, $len - $t);
  1162. $out = $out + strpos($index, substr($in, $t, 1)) * $bcpow;
  1163. }
  1164. if (is_numeric($pad_up)) {
  1165. $pad_up--;
  1166. if ($pad_up > 0) {
  1167. $out -= pow($base, $pad_up);
  1168. }
  1169. }
  1170. } else {
  1171. // Digital number -->> alphabet letter code
  1172. if (is_numeric($pad_up)) {
  1173. $pad_up--;
  1174. if ($pad_up > 0) {
  1175. $in += pow($base, $pad_up);
  1176. }
  1177. }
  1178. $out = "";
  1179. for ($t = floor(log10($in) / log10($base)); $t >= 0; $t--) {
  1180. $a = floor($in / bcpow($base, $t));
  1181. $out = $out . substr($index, $a, 1);
  1182. $in = $in - ($a * bcpow($base, $t));
  1183. }
  1184. $out = strrev($out); // reverse
  1185. }
  1186. return $out;
  1187. }
  1188. function cleanHTML($text)
  1189. {
  1190. $text = preg_replace(
  1191. array(
  1192. // Remove invisible content
  1193. '@<head[^>]*?>.*?</head>@siu',
  1194. '@<style[^>]*?>.*?</style>@siu',
  1195. '@<script[^>]*?.*?</script>@siu',
  1196. '@<object[^>]*?.*?</object>@siu',
  1197. '@<embed[^>]*?.*?</embed>@siu',
  1198. '@<applet[^>]*?.*?</applet>@siu',
  1199. '@<noframes[^>]*?.*?</noframes>@siu',
  1200. '@<noscript[^>]*?.*?</noscript>@siu',
  1201. '@<noembed[^>]*?.*?</noembed>@siu',
  1202. // Add line breaks before and after blocks
  1203. '@</?((address)|(blockquote)|(center)|(del))@iu',
  1204. '@</?((div)|(h[1-9])|(ins)|(isindex)|(p)|(pre))@iu',
  1205. '@</?((dir)|(dl)|(dt)|(dd)|(li)|(menu)|(ol)|(ul))@iu',
  1206. '@</?((table)|(th)|(td)|(caption))@iu',
  1207. '@</?((form)|(button)|(fieldset)|(legend)|(input))@iu',
  1208. '@</?((label)|(select)|(optgroup)|(option)|(textarea))@iu',
  1209. '@</?((frameset)|(frame)|(iframe))@iu',
  1210. ),
  1211. array(
  1212. ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', "$0", "$0", "$0", "$0", "$0", "$0", "$0", "$0",), $text);
  1213. // you can exclude some html tags here, in this case B and A tags
  1214. return strip_tags($text, '<b><br><p><h1><h2><h3><h4><h5><ul><ol><li><strong><a>');
  1215. }
  1216. function readExcell($file)
  1217. {
  1218. /** Error reporting */
  1219. error_reporting(E_ALL);
  1220. // set_time_limit(0);
  1221. date_default_timezone_set('Europe/London');
  1222. if (file_exists(CSV . $file)) {
  1223. $rows = array();
  1224. // $objPHPExcel = PHPExcel_IOFactory::createReaderForFile(CSV . $file);
  1225. // $objPHPExcel->setReadDataOnly(true);
  1226. $objPHPExcel = PHPExcel_IOFactory::load(CSV . $file);
  1227. //$objWorksheet = $objPHPExcel->load(CSV);
  1228. $objWorksheet = $objPHPExcel->getActiveSheet();
  1229. // print_r($objWorksheet);
  1230. $rowIndex = 0;
  1231. /* echo "<pre>";
  1232. print_r($objWorksheet->getRowIterator());
  1233. echo "</pre>";*/
  1234. foreach ($objWorksheet->getRowIterator() as $row) {
  1235. $cells = array();
  1236. if ($rowIndex > -1) {
  1237. $cellIterator = $row->getCellIterator();
  1238. $cellIterator->setIterateOnlyExistingCells(false); // This loops all cells,
  1239. // even if it is not set.
  1240. // By default, only cells
  1241. // that are set will be
  1242. // iterated.
  1243. $i = 1;
  1244. foreach ($cellIterator as $cell) {
  1245. $cells[$i] = $cell->getFormattedValue();
  1246. $i++;
  1247. }
  1248. }
  1249. $rows[$rowIndex] = $cells;
  1250. $rowIndex++;
  1251. }
  1252. return $rows;
  1253. } else {
  1254. echo "<p>Traženi fajl: <strong>$file</strong> ne postoji.</p>";
  1255. return false;
  1256. }
  1257. }
  1258. function fieldValue($fieldName)
  1259. {
  1260. $field = '';
  1261. switch ($fieldName) {
  1262. case 'Ime':
  1263. $field = "name_sr";
  1264. break;
  1265. case 'Interni kat. broj':
  1266. $field = "plD";
  1267. break;
  1268. case 'Osnovni kat. broj':
  1269. $field = "mainCatID";
  1270. break;
  1271. case 'Dodatni ser. brojevi':
  1272. $field = "secondIDs";
  1273. break;
  1274. case 'Atribut set':
  1275. $field = "attributeSet";
  1276. break;
  1277. case 'Osnovna cena':
  1278. $field = "price";
  1279. break;
  1280. case 'PDV':
  1281. $field = "pdv";
  1282. break;
  1283. // case 'PDV':
  1284. // $field = "pdv";
  1285. // break;
  1286. // case 'PDV':
  1287. // $field = "pdv";
  1288. // break;
  1289. // case 'PDV':
  1290. // $field = "pdv";
  1291. // break;
  1292. // case 'PDV':
  1293. // $field = "pdv";
  1294. // break;
  1295. // case 'PDV':
  1296. // $field = "pdv";
  1297. // break;
  1298. // case 'PDV':
  1299. // $field = "pdv";
  1300. // break;
  1301. // case 'PDV':
  1302. // $field = "pdv";
  1303. // break;
  1304. // case 'PDV':
  1305. // $field = "pdv";
  1306. // break;
  1307. // case 'PDV':
  1308. // $field = "pdv";
  1309. // break;
  1310. // case 'PDV':
  1311. // $field = "pdv";
  1312. // break;
  1313. // case 'PDV':
  1314. // $field = "pdv";
  1315. // break;
  1316. // case 'PDV':
  1317. // $field = "pdv";
  1318. // break;
  1319. // case 'PDV':
  1320. // …

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