yeshuadesign

loja virtual

Mar 20th, 2016
184
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.74 KB | None | 0 0
  1. <?php
  2. class Site extends BD{
  3.  
  4. private $conexao;
  5.  
  6. public function getData(){
  7. $data = getdate();
  8. $diaHoje = date('d');
  9. $array_meses = array(1 => "Janeiro", 2 => "Fevereiro", 3 => "Março", 4 => "Abril", 5 => "Maio", 6 => "Junho", 7 => "Julho", 8 => "Agosto", 9 => "Setembro", 10 => "Outubro", 11 => "Novembro", 12 => "Dezembro",);
  10. $horaAgora = date('H:i');
  11. $mesgetdate = $data['mon'];
  12. $anoAtual = date('Y');
  13.  
  14. return 'Hoje, '.$diaHoje.' de '.$array_meses[$mesgetdate].' de '.$anoAtual.' às '.$horaAgora.'';
  15. }//armazena e mostra string hora atual
  16.  
  17. public function getMenu(){
  18. $imagem_cat = '<img src="'.PATH.'/images/arrow.png" border="0"/>';
  19. $pegar_categorias = "SELECT * FROM `loja_categorias` ORDER BY id DESC";
  20. $executar = self::conn()->prepare($pegar_categorias);
  21. $executar->execute();
  22. if($executar->rowCount() == 0){}else{
  23. while($categoria = $executar->fetchObject()){
  24. echo '<li><a href="'.PATH.'/categoria/'.$categoria->slug.'">'.$categoria->titulo.'';
  25.  
  26. $pegar_subcategorias = "SELECT * FROM `loja_subcategorias` WHERE id_cat = ?";
  27. $executar_sub = self::conn()->prepare($pegar_subcategorias);
  28. $executar_sub->execute(array($categoria->id));
  29. if($executar_sub->rowCount() == 0){echo '</li>';}else{
  30. echo '<ul>';
  31. while($subcategoria = $executar_sub->fetchObject()){
  32. echo'<li>'.$imagem_cat.'<a href="'.PATH.'/categoria/'.$categoria->slug.'/'.$subcategoria->slug.'">'.$subcategoria->titulo.'</a></li>';
  33. }//termina while subcategoria
  34. echo '</ul></li>';
  35. }//termina else dos resultados da subcategoria
  36.  
  37. }//termina while categorias
  38. }//termina else
  39. }//termina função getMenu
  40.  
  41. public function getBanners(){
  42. $sqlBanners = "SELECT * FROM `loja_banner` ORDER BY id ASC LIMIT 5";
  43. return self::conn()->query($sqlBanners);
  44. }//pega os banners do slide principal
  45.  
  46. public function getProdutosHome($limit = false){
  47. if($limit == false){
  48. $query = "SELECT * FROM `loja_produtos` ORDER BY id DESC";
  49. }else{
  50. $query = "SELECT * FROM `loja_produtos` ORDER BY id DESC LIMIT $limit";
  51. }
  52. return self::conn()->query($query);
  53. }
  54.  
  55. public function atualizarViewCat($slug){
  56. $strSql = "UPDATE `loja_categorias` SET views = views+1 WHERE slug = ?";
  57. $executar_view = self::conn()->prepare($strSql);
  58. $executar_view->execute(array($slug));
  59. }//atualiza views da categoria
  60.  
  61. public function atualizarViewSub($slug){
  62. $strSql = "UPDATE `loja_subcategorias` SET views = views+1 WHERE slug = ?";
  63. $executar_view = self::conn()->prepare($strSql);
  64. $executar_view->execute(array($slug));
  65. }//atualiza views da subcategoria
  66.  
  67. public function inserir($tabela, $dados){
  68. $pegarCampos = array_keys($dados);
  69. $contarCampos = count($pegarCampos);
  70. $pegarValores = array_values($dados);
  71. $contarValores = count($pegarValores);
  72.  
  73. $sql = "INSERT INTO $tabela (";
  74. if($contarCampos == $contarValores){
  75. foreach($pegarCampos as $campo){
  76. $sql .= $campo.', ';
  77. }
  78. $sql = substr_replace($sql, ")", -2, 1);
  79. $sql .= "VALUES (";
  80.  
  81. for($i = 0; $i <$contarValores; $i++){
  82. $sql .= "?, ";
  83. $i;
  84. }
  85.  
  86. $sql = substr_replace($sql, ")", -2, 1);
  87. }else{
  88. return false;
  89. }
  90.  
  91. try{
  92. $inserir = self::conn()->prepare($sql);
  93. if($inserir->execute($pegarValores)){
  94. return true;
  95. }else{
  96. return false;
  97. }
  98. }catch(PDOException $e){
  99. return false;
  100. }
  101. }
  102.  
  103. public function selecionar($tabela, $dados, $condicao = false, $order = false){
  104. $pegarValores = implode(', ', $dados);
  105. $contarValores = count($pegarValores);
  106.  
  107. if($condicao == false){
  108. if($contarValores > 0){
  109. if($order != 'false'){
  110. $sql = "SELECT $pegarValores FROM $tabela ORDER BY $order";
  111. }else{
  112. $sql = "SELECT $pegarValores FROM $tabela";
  113. }
  114. $this->conexao = self::conn()->prepare($sql);
  115. $this->conexao->execute();
  116. return $this->conexao;
  117. }
  118. }else{
  119. $pegarCondCampos = array_keys($condicao);
  120. $contarCondCampos = count($pegarCondCampos);
  121. $pegarCondValores = array_values($condicao);
  122.  
  123. $sql = "SELECT $pegarValores FROM $tabela WHERE ";
  124. foreach($pegarCondCampos as $campoCondicao){
  125. $sql .= $campoCondicao." = ? AND ";
  126. }
  127. $sql = substr_replace($sql, "", -5, 5);
  128.  
  129. foreach($pegarCondValores as $condValores){
  130. $dadosExec[] = $condValores;
  131. }
  132. if($order){$sql .= " ORDER BY $order";}
  133. $this->conexao = self::conn()->prepare($sql);
  134. $this->conexao->execute($dadosExec);
  135. return $this->conexao;
  136. }
  137. }
  138.  
  139. public function listar(){
  140. $lista = $this->conexao->fetchAll();
  141. return $lista;
  142. }
  143.  
  144. public function sendMail($subject, $msg, $from, $nomefrom, $destino, $nomedestino){
  145. require_once "mailer/class.phpmailer.php";
  146. $mail = new PHPMailer();//Instancia a classe PHPMailer
  147.  
  148. $mail->isSMTP();//Habilita envio smtp
  149. $mail->SMTPAuth = true;//autentica o envio smtp
  150. $mail->Host = 'mail.gmail.com';
  151. $mail->Port = '25';
  152.  
  153. //começar o envio do email
  154. $mail->from = $from;//email de quem envia
  155. $mail->FromName = $namefrom;//nome de quem envia
  156.  
  157. $mail->isHTML(true);//seta que é HTML o email
  158. $mail->Subject = utf8_decode($subject);
  159. $mail->Body = utf8_decode($msg);
  160. $mail->AddAddress($destino, utf8_decode($nomedestino));
  161.  
  162. if($mail->Send()){
  163. return true;
  164. }else{
  165. return false;
  166. }
  167. }
  168.  
  169. function upload($tmp, $name, $nome, $larguraP, $pasta){
  170.  
  171. $explode = explode('.', $name);
  172. $ext = end($explode);
  173. if($ext=='jpg' || $ext == 'JPG' || $ext == 'jpeg' || $ext == 'JPEG'){
  174. $img = imagecreatefromjpeg($tmp);
  175. }elseif($ext == 'png'){
  176. $img = imagecreatefrompng($tmp);
  177. }elseif($ext == 'gif'){
  178. $img = imagecreatefromgif($tmp);
  179. }
  180. list($larg, $alt) = getimagesize($tmp);
  181. $x = $larg;
  182. $y = $alt;
  183. $largura = ($x>$larguraP) ? $larguraP : $x;
  184. $altura = ($largura*$y)/$x;
  185.  
  186. if($altura>$larguraP){
  187. $altura = $larguraP;
  188. $largura = ($altura*$x)/$y;
  189. }
  190. $nova = imagecreatetruecolor($largura, $altura);
  191. imagecopyresampled($nova, $img, 0,0,0,0, $largura, $altura, $x, $y);
  192.  
  193. imagejpeg($nova, $pasta.$nome);
  194. imagedestroy($img);
  195. imagedestroy($nova);
  196. return (file_exists($pasta.$nome)) ? true : false;
  197. }
  198.  
  199. }
  200. ?>
Advertisement
Add Comment
Please, Sign In to add comment