Advertisement
Guest User

Untitled

a guest
Jul 23rd, 2018
275
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.21 KB | None | 0 0
  1. <?php
  2.  
  3. /*********************************************************************************
  4. * Filename: common.php
  5. * Realizzato da Domenico Aliotta
  6. * Centro Regionale di Competenza Produzioni Agroalimentari
  7. *********************************************************************************/
  8.  
  9.  
  10. error_reporting (E_ALL ^ E_NOTICE);
  11. include("./template.php");
  12. //===============================
  13. // Database Connection Definition
  14. //-------------------------------
  15. //produttori Connection begin
  16.  
  17. include("./db_mysql.inc");
  18.  
  19. define("DATABASE_NAME","my_dbpiante");
  20. define("DATABASE_USER","dbpiante");
  21. define("DATABASE_PASSWORD","***mypassword***");
  22. define("DATABASE_HOST","localhost");
  23.  
  24.  
  25. // Database Initialize
  26. $db = new DB_Sql();
  27. $db->Database = DATABASE_NAME;
  28. $db->User = DATABASE_USER;
  29. $db->Password = DATABASE_PASSWORD;
  30. $db->Host = DATABASE_HOST;
  31.  
  32. // produttori Connection end
  33.  
  34. //===============================
  35. // Site Initialization
  36. //-------------------------------
  37. // Obtain the path where this site is located on the server
  38. //-------------------------------
  39. $app_path = ".";
  40. //===============================
  41.  
  42. //===============================
  43. // Common functions
  44. //-------------------------------
  45. // Convert non-standard characters to HTML
  46. //-------------------------------
  47. function tohtml($strValue)
  48. {
  49. return htmlspecialchars($strValue);
  50. }
  51.  
  52. //-------------------------------
  53. // Convert value to URL
  54. //-------------------------------
  55. function tourl($strValue)
  56. {
  57. return urlencode($strValue);
  58. }
  59.  
  60. //-------------------------------
  61. // Obtain specific URL Parameter from URL string
  62. //-------------------------------
  63. function get_param($param_name)
  64. {
  65. global $HTTP_POST_VARS;
  66. global $HTTP_GET_VARS;
  67.  
  68. $param_value = "";
  69. if(isset($HTTP_POST_VARS[$param_name]))
  70. $param_value = $HTTP_POST_VARS[$param_name];
  71. else if(isset($HTTP_GET_VARS[$param_name]))
  72. $param_value = $HTTP_GET_VARS[$param_name];
  73.  
  74. return $param_value;
  75. }
  76.  
  77. function get_session($param_name)
  78. {
  79. global $HTTP_POST_VARS;
  80. global $HTTP_GET_VARS;
  81. global ${$param_name};
  82.  
  83. $param_value = "";
  84. if(!isset($HTTP_POST_VARS[$param_name]) && !isset($HTTP_GET_VARS[$param_name]) && session_is_registered($param_name))
  85. $param_value = ${$param_name};
  86.  
  87. return $param_value;
  88. }
  89.  
  90. function set_session($param_name, $param_value)
  91. {
  92. global ${$param_name};
  93. if(session_is_registered($param_name))
  94. session_unregister($param_name);
  95. ${$param_name} = $param_value;
  96. session_register($param_name);
  97. }
  98.  
  99. function is_number($string_value)
  100. {
  101. if(is_numeric($string_value) || !strlen($string_value))
  102. return true;
  103. else
  104. return false;
  105. }
  106.  
  107. //-------------------------------
  108. // Convert value for use with SQL statament
  109. //-------------------------------
  110. function tosql($value, $type)
  111. {
  112. if(!strlen($value))
  113. return "NULL";
  114. else
  115. if($type == "Number")
  116. return str_replace (",", ".", doubleval($value));
  117. else
  118. {
  119. if(get_magic_quotes_gpc() == 0)
  120. {
  121. $value = str_replace("'","''",$value);
  122. $value = str_replace("\\","\\\\",$value);
  123. }
  124. else
  125. {
  126. $value = str_replace("\\'","''",$value);
  127. $value = str_replace("\\\"","\"",$value);
  128. }
  129.  
  130. return "'" . $value . "'";
  131. }
  132. }
  133.  
  134. function strip($value)
  135. {
  136. if(get_magic_quotes_gpc() == 0)
  137. return $value;
  138. else
  139. return stripslashes($value);
  140. }
  141.  
  142. function db_fill_array($sql_query)
  143. {
  144. global $db;
  145. $db_fill = new DB_Sql();
  146. $db_fill->Database = $db->Database;
  147. $db_fill->User = $db->User;
  148. $db_fill->Password = $db->Password;
  149. $db_fill->Host = $db->Host;
  150.  
  151. $db_fill->query($sql_query);
  152. if ($db_fill->next_record())
  153. {
  154. do
  155. {
  156. $ar_lookup[$db_fill->f(0)] = $db_fill->f(1);
  157. } while ($db_fill->next_record());
  158. return $ar_lookup;
  159. }
  160. else
  161. return false;
  162.  
  163. }
  164.  
  165. //-------------------------------
  166. // Deprecated function - use get_db_value($sql)
  167. //-------------------------------
  168. function dlookup($table_name, $field_name, $where_condition)
  169. {
  170. $sql = "SELECT " . $field_name . " FROM " . $table_name . " WHERE " . $where_condition;
  171. return get_db_value($sql);
  172. }
  173.  
  174.  
  175. //-------------------------------
  176. // Lookup field in the database based on SQL query
  177. //-------------------------------
  178. function get_db_value($sql)
  179. {
  180. global $db;
  181. $db_look = new DB_Sql();
  182. $db_look->Database = $db->Database;
  183. $db_look->User = $db->User;
  184. $db_look->Password = $db->Password;
  185. $db_look->Host = $db->Host;
  186.  
  187. $db_look->query($sql);
  188. if($db_look->next_record())
  189. return $db_look->f(0);
  190. else
  191. return "";
  192. }
  193.  
  194. //-------------------------------
  195. // Obtain Checkbox value depending on field type
  196. //-------------------------------
  197. function get_checkbox_value($value, $checked_value, $unchecked_value, $type)
  198. {
  199. if(!strlen($value))
  200. return tosql($unchecked_value, $type);
  201. else
  202. return tosql($checked_value, $type);
  203. }
  204.  
  205. //-------------------------------
  206. // Obtain lookup value from array containing List Of Values
  207. //-------------------------------
  208. function get_lov_value($value, $array)
  209. {
  210. $return_result = "";
  211.  
  212. if(sizeof($array) % 2 != 0)
  213. $array_length = sizeof($array) - 1;
  214. else
  215. $array_length = sizeof($array);
  216. reset($array);
  217.  
  218. for($i = 0; $i < $array_length; $i = $i + 2)
  219. {
  220. if($value == $array[$i]) $return_result = $array[$i+1];
  221. }
  222.  
  223. return $return_result;
  224. }
  225.  
  226. //-------------------------------
  227. // Verify user's security level and redirect to login page if needed
  228. //-------------------------------
  229.  
  230. function check_security($security_level)
  231. {
  232. global $UserRights;
  233. if(!session_is_registered("UserID"))
  234. {
  235. header ("Location: Login.php?querystring=" . urlencode($_SERVER["QUERY_STRING"]) . "&ret_page=" . urlencode($_SERVER["REQUEST_URI"]));
  236. exit;
  237. }
  238. else
  239. if(!session_is_registered("UserRights") || $UserRights < $security_level)
  240. {
  241. header ("Location: Login.php?querystring=" . urlencode($_SERVER["QUERY_STRING"]) . "&ret_page=" . urlencode($_SERVER["REQUEST_URI"] ));
  242.  
  243. exit;
  244. }
  245. }
  246.  
  247. //===============================
  248. // GlobalFuncs begin
  249. // GlobalFuncs end
  250. //===============================
  251. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement