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

/inc/amfphp/Amfphp/Services/ec_admin_settings.php

https://github.com/EmranAhmed/wp-easycart
PHP | 250 lines | 174 code | 27 blank | 49 comment | 42 complexity | 3ac57f931b601a6ef5ac09d10db69be8 MD5 | raw file
  1. <?php
  2. /*
  3. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  4. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  5. //All Code and Design is copyrighted by Level Four Development, llc
  6. //
  7. //Level Four Development, LLC provides this code "as is" without warranty of any kind, either express or implied,
  8. //including but not limited to the implied warranties of merchantability and/or fitness for a particular purpose.
  9. //
  10. //Only licnesed users may use this code and storfront for live purposes. All other use is prohibited and may be
  11. //subject to copyright violation laws. If you have any questions regarding proper use of this code, please
  12. //contact Level Four Development, llc and EasyCart prior to use.
  13. //
  14. //All use of this storefront is subject to our terms of agreement found on Level Four Development, llc's website.
  15. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  16. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  17. */
  18. class ec_admin_settings
  19. {
  20. function ec_admin_settings() {
  21. /*load our connection settings
  22. if( file_exists( '../../../../wp-easycart-data/connection/ec_conn.php' ) ) {
  23. require_once('../../../../wp-easycart-data/connection/ec_conn.php');
  24. } else {
  25. require_once('../../../connection/ec_conn.php');
  26. };*/
  27. //set our connection variables
  28. $dbhost = DB_HOST;
  29. $dbname = DB_NAME;
  30. $dbuser = DB_USER;
  31. $dbpass = DB_PASSWORD;
  32. global $wpdb;
  33. define ('WP_PREFIX', $wpdb->prefix);
  34. //make a connection to our database
  35. $this->conn = mysql_connect($dbhost, $dbuser, $dbpass);
  36. mysql_select_db ($dbname);
  37. mysql_query("SET CHARACTER SET utf8", $this->conn);
  38. mysql_query("SET NAMES 'utf8'", $this->conn);
  39. }
  40. //secure all of the services for logged in authenticated users only
  41. public function _getMethodRoles($methodName){
  42. if ($methodName == 'gettimezones') return array('admin');
  43. else if($methodName == 'getsitesettings') return array('admin');
  44. else if($methodName == 'updatesitesettings') return array('admin');
  45. else if($methodName == 'clearmenustatistics') return array('admin');
  46. else if($methodName == 'clearproductstatistics') return array('admin');
  47. else if($methodName == 'insertregcode') return array('admin');
  48. else return null;
  49. }
  50. //HELPER - used to escape out SQL calls
  51. function escape($sql)
  52. {
  53. $args = func_get_args();
  54. foreach($args as $key => $val)
  55. {
  56. $args[$key] = mysql_real_escape_string($val);
  57. }
  58. $args[0] = $sql;
  59. return call_user_func_array('sprintf', $args);
  60. }
  61. function gettimezones() {
  62. //Create SQL Query
  63. $sql = $this->escape("SELECT ec_timezone.* FROM ec_timezone ORDER BY ec_timezone.timezone_id ASC");
  64. // Run query on database
  65. $result = mysql_query($sql);
  66. //if results, convert to an array for use in flash
  67. if(mysql_num_rows($result) > 0) {
  68. while ($row=mysql_fetch_object($result)) {
  69. $returnArray[] = $row;
  70. }
  71. return($returnArray); //return array results if there are some
  72. } else {
  73. $returnArray[] = "noresults";
  74. return $returnArray; //return noresults if there are no results
  75. }
  76. }
  77. //convert our max upload file string from 32M or 64M size to bytes
  78. function convertBytes( $value ) {
  79. if ( is_numeric( $value ) ) {
  80. return $value;
  81. } else {
  82. $value_length = strlen($value);
  83. $qty = substr( $value, 0, $value_length - 1 );
  84. $unit = strtolower( substr( $value, $value_length - 1 ) );
  85. switch ( $unit ) {
  86. case 'k':
  87. $qty *= 1024;
  88. break;
  89. case 'm':
  90. $qty *= 1048576;
  91. break;
  92. case 'g':
  93. $qty *= 1073741824;
  94. break;
  95. }
  96. return $qty;
  97. }
  98. }
  99. //site settings functions
  100. function getsitesettings() {
  101. if (WP_PREFIX) {
  102. $dbprefix = WP_PREFIX; //use special prefix
  103. } else {
  104. $dbprefix = 'wp_'; //else use default
  105. }
  106. if(ini_get('upload_max_filesize')) {
  107. $maxuploadsize = $this->convertBytes(ini_get('upload_max_filesize'));
  108. } else {
  109. $maxuploadsize = 10000000;
  110. }
  111. //Create SQL Query
  112. $query_settings = mysql_query( "SELECT ec_setting.* FROM ec_setting WHERE ec_setting.setting_id = 1" );
  113. $query_options = mysql_query( "
  114. SELECT
  115. wp_options0.option_value AS WPstorepage,
  116. wp_options1.option_value AS WP_currency_seperator,
  117. wp_options2.option_value AS WP_decimal_symbol,
  118. wp_options3.option_value AS WP_decimal_places,
  119. wp_options4.option_value AS WP_currency_symbol
  120. FROM
  121. ".$dbprefix."options wp_options0, ".$dbprefix."options wp_options1, ".$dbprefix."options wp_options2, ".$dbprefix."options wp_options3, ".$dbprefix."options wp_options4
  122. WHERE
  123. wp_options0.option_name = 'ec_option_storepage' AND
  124. wp_options1.option_name = 'ec_option_currency_thousands_seperator' AND
  125. wp_options2.option_name = 'ec_option_currency_decimal_symbol' AND
  126. wp_options3.option_name = 'ec_option_currency_decimal_places' AND
  127. wp_options4.option_name = 'ec_option_currency'");
  128. $row = mysql_fetch_object( $query_settings );
  129. if( $query_options && mysql_num_rows( $query_options ) > 0 ){
  130. $row2 = mysql_fetch_object( $query_options );
  131. $row->WPstorepage = $row2->WPstorepage;
  132. $row->WP_currency_seperator = $row2->WP_currency_seperator;
  133. $row->WP_decimal_symbol = $row2->WP_decimal_symbol;
  134. $row->WP_decimal_places = $row2->WP_decimal_places;
  135. $row->WP_currency_symbol = $row2->WP_currency_symbol;
  136. $row->maxuploadsize = $maxuploadsize;
  137. $returnArray[] = $row;
  138. return($returnArray);
  139. } else {
  140. $row->WPstorepage = "";
  141. $row->WP_currency_seperator = "";
  142. $row->WP_decimal_symbol = "";
  143. $row->WP_decimal_places = "";
  144. $row->WP_currency_symbol = "";
  145. $row->maxuploadsize = $maxuploadsize;
  146. $returnArray[] = $row;
  147. return($returnArray);
  148. }
  149. }
  150. function updatesitesettings($settings) {
  151. //convert object to array
  152. $settings = (array)$settings;
  153. //Create SQL Query
  154. $sql = sprintf("UPDATE ec_setting SET ec_setting.site_url='%s', ec_setting.timezone='%s' WHERE ec_setting.setting_id = 1",
  155. mysql_real_escape_string($settings['siteURL']),
  156. mysql_real_escape_string($settings['timezone']));
  157. //Run query on database;
  158. mysql_query($sql);
  159. //if no errors, return their current Client ID
  160. //if results, convert to an array for use in flash
  161. if(!mysql_error()) {
  162. $returnArray[] ="success";
  163. return($returnArray); //return array results if there are some
  164. } else {
  165. $sqlerror = mysql_error();
  166. $error = explode(" ", $sqlerror);
  167. if ($error[0] == "Duplicate") {
  168. $returnArray[] = "duplicate";
  169. return $returnArray; //return noresults if there are no results
  170. } else {
  171. $returnArray[] = "error";
  172. return $returnArray; //return noresults if there are no results
  173. }
  174. }
  175. }
  176. function clearmenustatistics() {
  177. //Create SQL Query
  178. $sql = sprintf("UPDATE ec_menulevel1, ec_menulevel2, ec_menulevel3 SET ec_menulevel1.clicks = 0, ec_menulevel2.clicks = 0, ec_menulevel3.clicks = 0");
  179. //Run query on database;
  180. mysql_query($sql);
  181. //if no errors, return their current Client ID
  182. //if results, convert to an array for use in flash
  183. if(!mysql_error()) {
  184. $returnArray[] ="success";
  185. return($returnArray); //return array results if there are some
  186. } else {
  187. $returnArray[] = "error";
  188. return $returnArray; //return noresults if there are no results
  189. }
  190. }
  191. function clearproductstatistics() {
  192. //Create SQL Query
  193. $sql = sprintf("UPDATE ec_product SET ec_product.views = 0");
  194. //Run query on database;
  195. mysql_query($sql);
  196. //if no errors, return their current Client ID
  197. //if results, convert to an array for use in flash
  198. if(!mysql_error()) {
  199. $returnArray[] ="success";
  200. return($returnArray); //return array results if there are some
  201. } else {
  202. $returnArray[] = "error";
  203. return $returnArray; //return noresults if there are no results
  204. }
  205. }
  206. function insertregcode($regcode) {
  207. //Create SQL Query
  208. $sql = sprintf("UPDATE ec_setting SET ec_setting.reg_code='%s' WHERE ec_setting.setting_id = 1",
  209. mysql_real_escape_string($regcode));
  210. //Run query on database;
  211. mysql_query($sql);
  212. //if no errors, return their current Client ID
  213. //if results, convert to an array for use in flash
  214. if(!mysql_error()) {
  215. $returnArray[] ="success";
  216. return($returnArray); //return array results if there are some
  217. } else {
  218. $returnArray[] = "error";
  219. return $returnArray; //return noresults if there are no results
  220. }
  221. }
  222. }//close class
  223. ?>