Advertisement
plas71k

bd => decded

Feb 27th, 2013
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 12.04 KB | None | 0 0
  1. <?php
  2. /*
  3. * @ Pirate-Sky Crew :: PHP Decoder v2
  4. * @ Author: pLa$71k
  5. * @ Web: http://pirate-sky.com
  6. * @ Pirate-Sky Crew © 2008 - 2013
  7. */
  8.  
  9. if (class_exists('db')) {
  10.     return;
  11. }
  12. class db
  13. {
  14.     var $query = "";
  15.     var $db = "";
  16.     function db()
  17.     {
  18.         global $global;
  19.         $this->db = @mysql_connect($global['dbhost'], $global['dbusername'], $global['dbpassword']);
  20.         if (!$this->db)
  21.             die($this->debug(true));
  22.         mysql_set_charset('utf8', $this->db);
  23.         $selectdb = @mysql_select_db($global['dbdatabase']);
  24.         if (!$selectdb)
  25.             die($this->debug());
  26.     }
  27.     function select($query, $maxRows = 0, $pageNum = 0, $outputFieldsName = false)
  28.     {
  29.         $this->query = $query;
  30.         if ($maxRows > 0) {
  31.             $startRow = $pageNum * $maxRows;
  32.             $query    = sprintf("%s LIMIT %d, %d", $query, $startRow, $maxRows);
  33.         }
  34.         $result = mysql_query($query, $this->db);
  35.         if ($this->error())
  36.             die($this->debug());
  37.         $output = false;
  38.         $fields = false;
  39.         if ($outputFieldsName) {
  40.             for ($n = 0; $n < mysql_num_fields($result); $n++) {
  41.                 $fields[$n] = mysql_field_name($result, $n);
  42.             }
  43.         }
  44.         for ($n = 0; $n < mysql_num_rows($result); $n++) {
  45.             $row        = mysql_fetch_assoc($result);
  46.             $output[$n] = $row;
  47.         }
  48.         if ($outputFieldsName) {
  49.             return array(
  50.                 $output,
  51.                 $fields
  52.             );
  53.         }
  54.         return $output;
  55.     }
  56.     function misc($query)
  57.     {
  58.         $this->query = $query;
  59.         $result      = mysql_query($query, $this->db);
  60.         if ($this->error())
  61.             die($this->debug());
  62.         if ($result == TRUE) {
  63.             return TRUE;
  64.         } else {
  65.             return FALSE;
  66.         }
  67.     }
  68.     function numrows($query)
  69.     {
  70.         $this->query = $query;
  71.         $result      = mysql_query($query, $this->db);
  72.         return mysql_num_rows($result);
  73.     }
  74.     function paginate($numRows, $maxRows, $pageNum = 0, $pageVar = "page", $class = "txtLink")
  75.     {
  76.         global $lang;
  77.         $navigation  = "";
  78.         $totalPages  = ceil($numRows / $maxRows);
  79.         $queryString = "";
  80.         if (!empty($_SERVER['QUERY_STRING'])) {
  81.             $params    = explode("&", $_SERVER['QUERY_STRING']);
  82.             $newParams = array();
  83.             foreach ($params as $param) {
  84.                 if (stristr($param, $pageVar) == false) {
  85.                     array_push($newParams, $param);
  86.                 }
  87.             }
  88.             if (count($newParams) != 0) {
  89.                 $queryString = "&" . htmlentities(implode("&", $newParams));
  90.             }
  91.         }
  92.         $currentPage = $_SERVER['PHP_SELF'];
  93.         if ($totalPages > 1) {
  94.             $navigation  = $lang['misc']['pages'];
  95.             $upper_limit = $pageNum + 3;
  96.             $lower_limit = $pageNum - 3;
  97.             if ($pageNum > 0) {
  98.                 if (($pageNum - 2) > 0) {
  99.                     $first = sprintf("%s?" . $pageVar . "=%d%s", $currentPage, 0, $queryString);
  100.                     $navigation .= "<a href='" . $first . "' class='" . $class . "'>&laquo;</a> ";
  101.                 }
  102.                 $prev = sprintf("%s?" . $pageVar . "=%d%s", $currentPage, max(0, $pageNum - 1), $queryString);
  103.                 $navigation .= "<a href='" . $prev . "' class='" . $class . "'>&laquo;</a> ";
  104.             }
  105.             for ($i = 0; $i < $totalPages; $i++) {
  106.                 $pageNo = $i + 1;
  107.                 if ($i == $pageNum) {
  108.                     $navigation .= "&nbsp;<strong>[" . $pageNo . "]</strong>&nbsp;";
  109.                 } elseif ($i !== $pageNum && $i < $upper_limit && $i > $lower_limit) {
  110.                     $noLink = sprintf("%s?" . $pageVar . "=%d%s", $currentPage, $i, $queryString);
  111.                     $navigation .= "&nbsp;<a href='" . $noLink . "' class='" . $class . "'>" . $pageNo . "</a>&nbsp;";
  112.                 } elseif (($i - $lower_limit) == 0) {
  113.                     $navigation .= "&hellip;";
  114.                 }
  115.             }
  116.             if (($pageNum + 1) < $totalPages) {
  117.                 $next = sprintf("%s?" . $pageVar . "=%d%s", $currentPage, min($totalPages, $pageNum + 1), $queryString);
  118.                 $navigation .= "<a href='" . $next . "' class='" . $class . "'>&raquo;</a> ";
  119.                 if (($pageNum + 3) < $totalPages) {
  120.                     $last = sprintf("%s?" . $pageVar . "=%d%s", $currentPage, $totalPages - 1, $queryString);
  121.                     $navigation .= "<a href='" . $last . "' class='" . $class . "'>&raquo;</a>";
  122.                 }
  123.             }
  124.         }
  125.         return $navigation;
  126.     }
  127.     function insert($tablename, $record)
  128.     {
  129.         if (!is_array($record))
  130.             die($this->debug("array", "Insert", $tablename));
  131.         $count = 0;
  132.         foreach ($record as $key => $val) {
  133.             if ($count == 0) {
  134.                 $fields = "`" . $key . "`";
  135.                 $values = $this->mySQLSafe($val);
  136.             } else {
  137.                 $fields .= ", " . "`" . $key . "`";
  138.                 $values .= ", " . $this->mySQLSafe($val);
  139.             }
  140.             $count++;
  141.         }
  142.         $query       = "INSERT INTO " . $tablename . " (" . $fields . ") VALUES (" . $values . ")";
  143.         $this->query = $query;
  144.         mysql_query($query, $this->db);
  145.         if ($this->error())
  146.             die($this->debug());
  147.         if ($this->affected() > 0)
  148.             return true;
  149.         else
  150.             return false;
  151.     }
  152.     function update($tablename, $record, $where)
  153.     {
  154.         if (!is_array($record))
  155.             die($this->debug("array", "Update", $tablename));
  156.         $count = 0;
  157.         foreach ($record as $key => $val) {
  158.             if ($count == 0)
  159.                 $set = "`" . $key . "`" . "=" . $this->mySQLSafe($val);
  160.             else
  161.                 $set .= ", " . "`" . $key . "`" . "= " . $this->mySQLSafe($val);
  162.             $count++;
  163.         }
  164.         $query       = "UPDATE " . $tablename . " SET " . $set . " WHERE " . $where;
  165.         $this->query = $query;
  166.         mysql_query($query, $this->db);
  167.         if ($this->error())
  168.             die($this->debug());
  169.         if ($this->affected() > 0)
  170.             return true;
  171.         else
  172.             return false;
  173.     }
  174.     function increment($tablename, $record, $where)
  175.     {
  176.         if (!is_array($record))
  177.             die($this->debug("array", "Update", $tablename));
  178.         $count = 0;
  179.         foreach ($record as $key => $val) {
  180.             if ($count == 0)
  181.                 $set = "`" . $key . "`" . "=" . "`" . $key . "`" . "+1";
  182.             else
  183.                 $set .= "`" . $key . "`" . "=" . "`" . $key . "`" . "+1";
  184.             $count++;
  185.         }
  186.         $query       = "UPDATE " . $tablename . " SET " . $set . " WHERE " . $where;
  187.         $this->query = $query;
  188.         mysql_query($query, $this->db);
  189.         if ($this->error())
  190.             die($this->debug());
  191.         if ($this->affected() > 0)
  192.             return true;
  193.         else
  194.             return false;
  195.     }
  196.     function decrement($tablename, $record, $where)
  197.     {
  198.         if (!is_array($record))
  199.             die($this->debug("array", "Update", $tablename));
  200.         $count = 0;
  201.         foreach ($record as $key => $val) {
  202.             if ($count == 0)
  203.                 $set = "`" . $key . "`" . "=" . "`" . $key . "`" . "-1";
  204.             else
  205.                 $set .= "`" . $key . "`" . "=" . "`" . $key . "`" . "-1";
  206.             $count++;
  207.         }
  208.         $query       = "UPDATE " . $tablename . " SET " . $set . " WHERE " . $where;
  209.         $this->query = $query;
  210.         mysql_query($query, $this->db);
  211.         if ($this->error())
  212.             die($this->debug());
  213.         if ($this->affected() > 0)
  214.             return true;
  215.         else
  216.             return false;
  217.     }
  218.     function categoryNos($cat_id, $sign, $amount = 1)
  219.     {
  220.         global $global;
  221.         if ($cat_id > 0) {
  222.             do {
  223.                 $record['noProducts'] = " noProducts " . $sign . $amount;
  224.                 $where                = "cat_id = " . $cat_id;
  225.                 $this->update($global['dbprefix'] . "CubeCart_category", $record, $where, "");
  226.                 $query  = "SELECT cat_father_id FROM " . $global['dbprefix'] . "CubeCart_category WHERE cat_id = " . $cat_id;
  227.                 $cfi    = $this->select($query);
  228.                 $cat_id = $cfi['0']['cat_father_id'];
  229.             } while ($cat_id > 0);
  230.         }
  231.     }
  232.     function delete($tablename, $where, $limit = "")
  233.     {
  234.         $query = "DELETE from " . $tablename . " WHERE " . $where;
  235.         if ($limit != "")
  236.             $query .= " LIMIT " . $limit;
  237.         $this->query = $query;
  238.         mysql_query($query, $this->db);
  239.         if ($this->error())
  240.             die($this->debug());
  241.         if ($this->affected() > 0) {
  242.             return TRUE;
  243.         } else {
  244.             return FALSE;
  245.         }
  246.     }
  247.     function mySQLSafe($value, $quote = "'")
  248.     {
  249.         $value = str_replace(array(
  250.             "\'",
  251.             "'"
  252.         ), "&#39;", $value);
  253.         if (get_magic_quotes_gpc()) {
  254.             $value = stripslashes($value);
  255.         }
  256.         if (version_compare(phpversion(), "4.3.0") == "-1") {
  257.             $value = mysql_escape_string($value);
  258.         } else {
  259.             $value = mysql_real_escape_string($value);
  260.         }
  261.         $value = $quote . trim($value) . $quote;
  262.         return $value;
  263.     }
  264.     function debug($type = "", $action = "", $tablename = "")
  265.     {
  266.         switch ($type) {
  267.             case "connect":
  268.                 $message = "MySQL Error Occured";
  269.                 $result  = mysql_errno() . ": " . mysql_error();
  270.                 $query   = "";
  271.                 $output  = "Could not connect to the database. Be sure to check that your database connection settings are correct and that the MySQL server in running.";
  272.                 break;
  273.             case "array":
  274.                 $message = $action . " Error Occured";
  275.                 $result  = "Could not update " . $tablename . " as variable supplied must be an array.";
  276.                 $query   = "";
  277.                 $output  = "Sorry an error has occured accessing the database. Be sure to check that your database connection settings are correct and that the MySQL server in running.";
  278.                 break;
  279.             default:
  280.                 if (mysql_errno($this->db)) {
  281.                     $message = "MySQL Error Occured";
  282.                     $result  = mysql_errno($this->db) . ": " . mysql_error($this->db);
  283.                     $output  = "Sorry an error has occured accessing the database. Be sure to check that your database connection settings are correct and that the MySQL server in running.";
  284.                 } else {
  285.                     $message = "MySQL Query Executed Succesfully.";
  286.                     $result  = mysql_affected_rows($this->db) . " Rows Affected";
  287.                     $output  = "view logs for details";
  288.                 }
  289.                 $linebreaks = array(
  290.                     "\n",
  291.                     "\r"
  292.                 );
  293.                 if ($this->query != "")
  294.                     $query = "QUERY = " . str_replace($linebreaks, " ", $this->query);
  295.                 else
  296.                     $query = "";
  297.                 break;
  298.         }
  299.         $output = "<b style='font-family: Arial, Helvetica, sans-serif; color: #0B70CE;'>" . $message . "</b><br />\n<span style='font-family: Arial, Helvetica, sans-serif; color: #000000;'>" . $result . "</span><br />\n<p style='Courier New, Courier, mono; border: 1px dashed #666666; padding: 10px; color: #000000;'>" . $query . "</p>\n";
  300.         return $output;
  301.     }
  302.     function error()
  303.     {
  304.         if (mysql_errno($this->db))
  305.             return true;
  306.         else
  307.             return false;
  308.     }
  309.     function insertid()
  310.     {
  311.         return mysql_insert_id($this->db);
  312.     }
  313.     function affected()
  314.     {
  315.         return mysql_affected_rows($this->db);
  316.     }
  317.     function close()
  318.     {
  319.         mysql_close($this->db);
  320.     }
  321. }
  322. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement