PageRenderTime 45ms CodeModel.GetById 19ms RepoModel.GetById 1ms app.codeStats 0ms

/inc/amfphp/Amfphp/Services/ec_admin_states.php

https://github.com/EmranAhmed/wp-easycart
PHP | 147 lines | 85 code | 19 blank | 43 comment | 21 complexity | 748c23c80062e7c621d41e688ccece53 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_states
  19. {
  20. function ec_admin_states() {
  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 == 'getstates') return array('admin');
  43. else if($methodName == 'updatestate') return array('admin');
  44. else if($methodName == 'deletestate') return array('admin');
  45. else if($methodName == 'addstate') 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. function getstates() {
  60. //Create SQL Query
  61. $sql = $this->escape("SELECT ec_state.* FROM ec_state ORDER BY ec_state.sort_order ASC");
  62. // Run query on database
  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. //state list functions
  76. //get state list is handled above
  77. function updatestate($id, $countryid, $iso2, $name, $sortorder) {
  78. //Create SQL Query
  79. $sql = $this->escape("UPDATE ec_state SET ec_state.name_sta='%s', ec_state.code_sta='%s', ec_state.idcnt_sta='%s', ec_state.sort_order='%s' WHERE ec_state.id_sta = '%s'", $name, $iso2, $countryid, $sortorder, $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 deletestate($id) {
  93. //Create SQL Query
  94. $sql = sprintf("DELETE FROM ec_state WHERE ec_state.id_sta = $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 addstate($countryid, $iso2, $name, $sortorder) {
  108. //Create SQL Query
  109. $sql = sprintf("Insert into ec_state(ec_state.id_sta, ec_state.name_sta, ec_state.code_sta, ec_state.idcnt_sta, ec_state.sort_order)
  110. values(null, '%s', '%s', '%s', '%s')",
  111. mysql_real_escape_string($name),
  112. mysql_real_escape_string($iso2),
  113. mysql_real_escape_string($countryid),
  114. mysql_real_escape_string($sortorder));
  115. //Run query on database;
  116. mysql_query($sql);
  117. //if no errors, return their current Client ID
  118. //if results, convert to an array for use in flash
  119. if(!mysql_error()) {
  120. $returnArray[] ="success";
  121. return($returnArray); //return array results if there are some
  122. } else {
  123. $returnArray[] = "error";
  124. return $returnArray; //return noresults if there are no results
  125. }
  126. }
  127. }//close class
  128. ?>