PageRenderTime 51ms CodeModel.GetById 23ms RepoModel.GetById 0ms app.codeStats 0ms

/inc/amfphp/Amfphp/Services/ec_admin_pricepoints.php

https://github.com/EmranAhmed/wp-easycart
PHP | 151 lines | 88 code | 20 blank | 43 comment | 21 complexity | c89287a275d5238a253a8a1f8322ac92 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_pricepoints
  19. {
  20. function ec_admin_pricepoints() {
  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 == 'getpricepoints') return array('admin');
  43. else if($methodName == 'updatepricepoint') return array('admin');
  44. else if($methodName == 'deletepricepoint') return array('admin');
  45. else if($methodName == 'addpricepoint') return array('admin');
  46. else return null;
  47. }
  48. //HELPER - used to escape out SQL calls
  49. function escape($sql)
  50. {
  51. $args = func_get_args();
  52. foreach($args as $key => $val)
  53. {
  54. $args[$key] = mysql_real_escape_string($val);
  55. }
  56. $args[0] = $sql;
  57. return call_user_func_array('sprintf', $args);
  58. }
  59. //price point functions
  60. function getpricepoints() {
  61. //Create SQL Query
  62. $sql = "SELECT ec_pricepoint.* FROM ec_pricepoint ORDER BY ec_pricepoint.order ASC";
  63. $result = mysql_query($sql);
  64. //if results, convert to an array for use in flash
  65. if(mysql_num_rows($result) > 0) {
  66. while ($row=mysql_fetch_object($result)) {
  67. $returnArray[] = $row;
  68. }
  69. return($returnArray); //return array results if there are some
  70. } else {
  71. $returnArray[] = "noresults";
  72. return $returnArray; //return noresults if there are no results
  73. }
  74. }
  75. function updatepricepoint($id, $pricepoint) {
  76. //convert object to array
  77. $pricepoint = (array)$pricepoint;
  78. //Create SQL Query
  79. $sql = $this->escape("UPDATE ec_pricepoint SET ec_pricepoint.is_less_than = '%s', ec_pricepoint.is_greater_than = '%s', ec_pricepoint.low_point = '%s', ec_pricepoint.high_point = '%s', ec_pricepoint.order = '%s' WHERE ec_pricepoint.pricepoint_id = '%s'", $pricepoint['lessthan'], $pricepoint['greaterthan'], $pricepoint['lowpoint'], $pricepoint['highpoint'], $pricepoint['pricepointorder'], $id);
  80. //Run query on database;
  81. mysql_query($sql);
  82. //if no errors, return their current Client ID
  83. //if results, convert to an array for use in flash
  84. if(!mysql_error()) {
  85. $returnArray[] ="success";
  86. return($returnArray); //return array results if there are some
  87. } else {
  88. $returnArray[] = "error";
  89. return $returnArray; //return noresults if there are no results
  90. }
  91. }
  92. function deletepricepoint($id) {
  93. //Create SQL Query
  94. $sql = $this->escape("DELETE FROM ec_pricepoint WHERE ec_pricepoint.pricepoint_id = %s", $id);
  95. //Run query on database;
  96. mysql_query($sql);
  97. //if no errors, return their current Client ID
  98. //if results, convert to an array for use in flash
  99. if(!mysql_error()) {
  100. $returnArray[] ="success";
  101. return($returnArray); //return array results if there are some
  102. } else {
  103. $returnArray[] = "error";
  104. return $returnArray; //return noresults if there are no results
  105. }
  106. }
  107. function addpricepoint($pricepoint) {
  108. //convert object to array
  109. $pricepoint = (array)$pricepoint;
  110. //Create SQL Query
  111. $sql = sprintf("Insert into ec_pricepoint(ec_pricepoint.pricepoint_id, ec_pricepoint.is_less_than, ec_pricepoint.is_greater_than, ec_pricepoint.low_point, ec_pricepoint.high_point, ec_pricepoint.order)
  112. values(null, '%s', '%s', '%s', '%s', '%s')",
  113. mysql_real_escape_string($pricepoint['lessthan']),
  114. mysql_real_escape_string($pricepoint['greaterthan']),
  115. mysql_real_escape_string($pricepoint['lowpoint']),
  116. mysql_real_escape_string($pricepoint['highpoint']),
  117. mysql_real_escape_string($pricepoint['pricepointorder']));
  118. //Run query on database;
  119. mysql_query($sql);
  120. //if no errors, return their current Client ID
  121. //if results, convert to an array for use in flash
  122. if(!mysql_error()) {
  123. $returnArray[] ="success";
  124. return($returnArray); //return array results if there are some
  125. } else {
  126. $returnArray[] = "error";
  127. return $returnArray; //return noresults if there are no results
  128. }
  129. }
  130. }//close class
  131. ?>