PageRenderTime 33ms CodeModel.GetById 8ms RepoModel.GetById 0ms app.codeStats 0ms

/inc/amfphp/Amfphp/Services/ec_admin_reviews.php

https://github.com/EmranAhmed/wp-easycart
PHP | 131 lines | 71 code | 22 blank | 38 comment | 17 complexity | d54cb89428209d786d1440e9c61a01d9 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_reviews
  19. {
  20. function ec_admin_reviews() {
  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 == 'getreviews') return array('admin');
  43. else if($methodName == 'deletereview') return array('admin');
  44. else if($methodName == 'updatereview') return array('admin');
  45. else return null;
  46. }
  47. //HELPER - used to escape out SQL calls
  48. function escape($sql)
  49. {
  50. $args = func_get_args();
  51. foreach($args as $key => $val)
  52. {
  53. $args[$key] = mysql_real_escape_string($val);
  54. }
  55. $args[0] = $sql;
  56. return call_user_func_array('sprintf', $args);
  57. }
  58. //review functions
  59. function getreviews($startrecord, $limit, $orderby, $ordertype, $filter) {
  60. //Create SQL Query
  61. $query= mysql_query("SELECT SQL_CALC_FOUND_ROWS ec_review.*, UNIX_TIMESTAMP(ec_review.date_submitted) AS date_submitted, ec_product.model_number, ec_product.title as product_title, ec_product.activate_in_store, ec_product.image1, ec_product.price FROM ec_review LEFT JOIN ec_product ON ec_product.product_id = ec_review.product_id WHERE ec_review.review_id != '' ".$filter." ORDER BY ". $orderby ." ". $ordertype . " LIMIT ". $startrecord .", ". $limit."");
  62. $totalquery=mysql_query("SELECT FOUND_ROWS()");
  63. $totalrows = mysql_fetch_object($totalquery);
  64. //if results, convert to an array for use in flash
  65. if(mysql_num_rows($query) > 0) {
  66. while ($row=mysql_fetch_object($query)) {
  67. $row->totalrows=$totalrows;
  68. $returnArray[] = $row;
  69. }
  70. return($returnArray); //return array results if there are some
  71. } else {
  72. $returnArray[] = "noresults";
  73. return $returnArray; //return noresults if there are no results
  74. }
  75. }
  76. function deletereview($reviewid) {
  77. //Create SQL Query
  78. $deletesql = $this->escape("DELETE FROM ec_review WHERE ec_review.review_id = '%s'", $reviewid);
  79. //Run query on database;
  80. mysql_query($deletesql);
  81. //if no errors, return their current Client ID
  82. //if results, convert to an array for use in flash
  83. if(!mysql_error()) {
  84. $returnArray[] ="success";
  85. return($returnArray); //return array results if there are some
  86. } else {
  87. $returnArray[] = "error";
  88. return $returnArray; //return noresults if there are no results
  89. }
  90. }
  91. function updatereview($reviewid, $review) {
  92. //convert object to array
  93. $review = (array)$review;
  94. //Create SQL Query
  95. $sql = $this->escape("UPDATE ec_review SET ec_review.approved='%s', ec_review.title='%s', ec_review.description='%s', ec_review.rating='%s' WHERE ec_review.review_id = '%s'", $review['approved'], $review['reviewtitle'],$review['reviewdescription'],$review['rating'],$reviewid);
  96. //Run query on database;
  97. mysql_query($sql);
  98. //if no errors, return their current Client ID
  99. //if results, convert to an array for use in flash
  100. if(!mysql_error()) {
  101. $returnArray[] ="success";
  102. return($returnArray); //return array results if there are some
  103. } else {
  104. $returnArray[] = "error";
  105. return $returnArray; //return noresults if there are no results
  106. }
  107. }
  108. }//close class
  109. ?>