/engines/inc/portfolio/func.php

https://github.com/masterscript/DLE-module-Portfolio · PHP · 288 lines · 221 code · 66 blank · 1 comment · 33 complexity · ff84d1cb68738739d75dae0a2ddd9986 MD5 · raw file

  1. <?php
  2. function getCountries ()
  3. {
  4. global $db;
  5. $country = get_vars ( 'portfolio_country' );
  6. if ( ! $country )
  7. {
  8. $db->query ( "SELECT * FROM " . PREFIX . "_portfolio_geo WHERE is_country = 'YES'" );
  9. $country = array ();
  10. while ( $row = $db->get_row () )
  11. {
  12. $country[ $row[ 'id' ]] = $row;
  13. }
  14. set_vars( 'portfolio_country', $country );
  15. }
  16. return $country;
  17. }
  18. function getRegions ( $country_id )
  19. {
  20. global $db;
  21. $db->query ( "SELECT * FROM " . PREFIX . "_portfolio_geo WHERE is_region = 'YES' AND country_id = '{$country_id}'" );
  22. $region = array ();
  23. while ( $row = $db->get_row () )
  24. {
  25. $region[ $row[ 'id' ]] = $row;
  26. }
  27. return $region;
  28. }
  29. function getTowns( $region_id )
  30. {
  31. global $db;
  32. $db->query ( "SELECT * FROM " . PREFIX . "_portfolio_geo WHERE is_town = 'YES' AND region_id = '{$region_id}'" );
  33. $towns = array ();
  34. while ( $row = $db->get_row () )
  35. {
  36. $towns[ $row[ 'id' ]] = $row;
  37. }
  38. return $towns;
  39. }
  40. function getTowns_marked( $region_id )
  41. {
  42. global $db;
  43. $db->query ( "SELECT * FROM " . PREFIX . "_portfolio_geo WHERE is_town = 'YES' AND region_id = '{$region_id}'" );
  44. $towns = array ();
  45. while ( $row = $db->get_row () )
  46. { $towns[ $row[ 'id' ]] = $row;
  47. }
  48. $towns['add_new_city']['name'] = " - add new city - ";
  49. $towns['blank_string']['name'] = "";
  50. return $towns;
  51. }
  52. function getOptions ( $values, $sel = 0 )
  53. {
  54. if ( ! is_array ( $values ))
  55. {
  56. return "";
  57. }
  58. $options = array ();
  59. foreach ( $values as $id => $value )
  60. {
  61. $selected = $id == $sel ? ' selected' : '';
  62. $options[] = "<option value=\"" . $id . "\" {$selected}>" . stripslashes ( $value[ 'name' ] ) . "</option>";
  63. }
  64. return implode ( "\n", $options );
  65. }
  66. function clearGeoCache()
  67. {
  68. @unlink ( ENGINE_DIR . '/cache/system/portfolio_country.php' );
  69. @unlink ( ENGINE_DIR . '/cache/system/portfolio_services.php' );
  70. }
  71. function getServices ()
  72. {
  73. global $db;
  74. $buffer = get_vars ( 'portfolio_services' );
  75. if ( ! $buffer )
  76. {
  77. $db->query ( "SELECT * FROM " . PREFIX . "_portfolio_services" );
  78. while ( $row = $db->get_row () )
  79. {
  80. $buffer[ $row['id' ]] = $row;
  81. }
  82. set_vars ( 'portfolio_services', $buffer );
  83. }
  84. return $buffer;
  85. }
  86. function showImages ( $user_id )
  87. {
  88. $full_temp_folder = ROOT_DIR . '/uploads/portfolio/sample/' . $user_id . '/';
  89. $files = @scandir ( $full_temp_folder );
  90. $allowed_ext = array ( 'png', 'jpg', 'jpeg', 'gif' );
  91. $buffer = <<<HTML
  92. <table cellpadding="4" cellspacing="0">
  93. HTML;
  94. $count = 0;
  95. if ( ! is_array ( $files ))
  96. {
  97. return "";
  98. }
  99. foreach ( $files as $file_name )
  100. {
  101. if ( $file_name != '.' and $file_name != '..' )
  102. {
  103. $file_ext = strtolower ( end ( explode ( ".", $file_name )));
  104. if ( in_array ( $file_ext, $allowed_ext ))
  105. {
  106. $count ++;
  107. if ( $count == 1 )
  108. {
  109. $buffer .= "<tr>";
  110. }
  111. $buffer .= <<<HTML
  112. <td style="padding:6px">
  113. <a href="/uploads/portfolio/sample/{$user_id}/{$file_name}" onclick="return hs.expand(this); return false;"><img src="/uploads/portfolio/sample/{$user_id}/mini/{$file_name}" border="0" /></a>
  114. </td>
  115. HTML;
  116. if ( $count > 2 )
  117. {
  118. $count = 0;
  119. $buffer .= "</tr>";
  120. }
  121. }
  122. }
  123. }
  124. $buffer .= "</table>";
  125. return $buffer;
  126. }
  127. function showLastImages ( $numbers_images ){
  128. global $db;
  129. $query_id_lastimg = $db->query ( "SELECT * FROM " . PREFIX . "_portfolio_images ORDER BY " . PREFIX . "_portfolio_images.added_date DESC LIMIT {$numbers_images} " );
  130. $count = 0;
  131. $buffer = <<<HTML
  132. <table cellpadding="4" cellspacing="0">
  133. HTML;
  134. while ( $row = $db->get_row ( $query_id_lastimg ) ){
  135. $user_row = $db->super_query ( "SELECT user_name FROM " . PREFIX . "_portfolio WHERE user_id = '{$row['user_id']}'" );
  136. $count ++;
  137. if ( $count == 1 ){
  138. $buffer .= "<tr>";
  139. }
  140. $buffer = $buffer . <<<HTML
  141. <td style="padding:20px">
  142. <a "href="/uploads/portfolio/sample/{$row['user_id']}/{$row['image_name']}" onclick="return hs.expand(this); return false;"><img src="/uploads/portfolio/sample/{$row['user_id']}/mini/{$row['image_name']}" border="0" /></a>
  143. <div>äîäàâ êóëiíàð</div>
  144. <a href="/portfolio/{$user_row['user_name']}/">{$user_row['user_name']}</a>
  145. </td>
  146. HTML;
  147. if ( $count > 2 ){
  148. $count = 0;
  149. $buffer = $buffer . "</tr>";
  150. }
  151. }
  152. $buffer = $buffer . "</table>";
  153. return $buffer;
  154. }
  155. function getImages ( $user_id )
  156. {
  157. $full_temp_folder = ROOT_DIR . '/uploads/portfolio/sample/' . $user_id . '/';
  158. $files = @scandir ( $full_temp_folder );
  159. $allowed_ext = array ( 'png', 'jpg', 'jpeg', 'gif' );
  160. if ( is_array ( $files ))
  161. {
  162. $images = <<<HTML
  163. <script type="text/javascript">
  164. function del_img ( file_name )
  165. {
  166. //$('#fotos').html('<img src="/engine/modules/portfolio/img/loading.gif" border="0" />');
  167. $.post( '/index.php', { do: 'portfolio', act: 'ajax', sub_act: 'del_foto', foto: file_name, user_id: '{$user_id}' }, function ( data ) {
  168. $('#fotos').html( data );
  169. });
  170. }
  171. </script>
  172. <table cellpadding="4" cellspacing="0" border="0">
  173. HTML;
  174. $flag = 0;
  175. foreach ( $files as $file_name )
  176. {
  177. if ( $file_name != '.' and $file_name != '..' )
  178. {
  179. $file_ext = strtolower ( end ( explode ( ".", $file_name )));
  180. if ( in_array ( $file_ext, $allowed_ext ))
  181. {
  182. $flag ++;
  183. if ( $flag == 1 )
  184. {
  185. $images .= "<tr>\n";
  186. }
  187. $images .= <<<HTML
  188. <td style="padding:6px; border:1px dotted #c4c4c4; width:160px;" align="center">
  189. <img src="/uploads/portfolio/sample/{$user_id}/mini/{$file_name}" border="0" />
  190. <div style="padding-top:10px;"><img src="/engine/modules/portfolio/img/cancel.png" style="cursor:pointer;" title="Âèäàëèòè" onClick="del_img('{$file_name}');" /></div>
  191. </td>
  192. HTML;
  193. if ( $flag == 3 )
  194. {
  195. $flag = 0;
  196. $images .= "</tr>\n";
  197. }
  198. }
  199. }
  200. }
  201. $images .= "</table>";
  202. }
  203. return $images;
  204. }
  205. function getLangDate ( $timestamp )
  206. {
  207. global $lang, $config;
  208. $_TIME = time ();
  209. if( date( Ymd, $timestamp ) == date( Ymd, $_TIME ) )
  210. {
  211. return $lang['time_heute'] . langdate( ", H:i", $timestamp );
  212. }
  213. elseif( date( Ymd, $timestamp ) == date( Ymd, ($_TIME - 86400) ) )
  214. {
  215. return $lang['time_gestern'] . langdate( ", H:i", $timestamp );
  216. }
  217. else
  218. {
  219. return langdate( "j F Y H:i", $timestamp );
  220. }
  221. }
  222. ?>