/**
  * Painel de controle que gerencia as screenshots
  */
 public function panelManager()
 {
     global $ldMssql, $PANELUSER_PREMISSIONS, $SCREENSHOTS;
     if ($this->checkLogin() === false) {
         $this->loadTemplate("loginerror");
         return;
     } elseif ($PANELUSER_PREMISSIONS['SCREENSHOT'][0] == 0) {
         $this->loadTemplate("paneluser[DESACTIVE]");
         return;
     } elseif ($this->checkPermissionModule("SCREENSHOT") == false) {
         $this->loadTemplate("paneluser[ACCESSDANIED]");
         return;
     }
     if ($_GET['subAction'] == "delete") {
         if (is_numeric($_POST['id']) == false) {
             $writeRespost = "<div class=\"qdestaques\">Sem fotos para deletar.</div>";
         } else {
             $screen = $ldMssql->query("SELECT [image] FROM [dbo].[webScreenshots] WHERE " . ($this->checkLogin()->previlegy != 2 ? "[uploadBy] = '" . $_SESSION['LOGIN'] . "' AND" : "") . " [id] = " . (int) $_POST['id']);
             $screen = mssql_fetch_object($screen);
             @unlink("modules/uploads/screenshots/{$screen->image}.common.jpg");
             @unlink("modules/uploads/screenshots/{$screen->image}.small.jpg");
             $ldMssql->query("DELETE FROM [dbo].[webScreenshots] WHERE " . ($this->checkLogin()->previlegy != 2 ? "[uploadBy] = '" . $_SESSION['LOGIN'] . "' AND" : "") . " [id] = " . (int) $_POST['id']);
             $writeRespost = "<div class=\"qdestaques\">Screenshot deletada com sucesso.</div>";
         }
     } elseif ($_GET['subAction'] == "upload") {
         if (is_uploaded_file($_FILES['photo']['tmp_name']) == false) {
             $writeRespost = "<div class=\"qdestaques\">Selecione o arquivo para enviar.</div>";
         } elseif (empty($_POST['legend']) == true) {
             $writeRespost = "<div class=\"qdestaques\">Escreva uma legenda para a screenshot.</div>";
         } else {
             $dlImage = new DLImage();
             if ($dlImage->uploadImage($_FILES['photo'], true, "modules/uploads/screenshots/") == true) {
                 if ($dlImage->info['width'] > $SCREENSHOTS['MAX_WIDTH']) {
                     $common = $dlImage->resizeAndSave($SCREENSHOTS['MAX_WIDTH'], 0, false, true, false, "modules/uploads/screenshots/", "jpg", false, 'common');
                 } else {
                     $dlImage->saveImage(false, "modules/uploads/screenshots/", 'jpg', 'common');
                     $common = array(0 => NULL, $dlImage->info['width'], $dlImage->info['height']);
                 }
                 $small = $dlImage->resizeAndSave(100, 100, false, true, false, "modules/uploads/screenshots/", "jpg", false, 'small');
                 $dlImage->deleteBufferImage();
                 $ldMssql->query("INSERT INTO [dbo].[webScreenshots] ([image] ,[uploadBy] ,[date] ,[rate] ,[legend] ,[sw] ,[sy] ,[cw] ,[cy]) VALUES ('{$dlImage->finalName}' ,'{$_SESSION['LOGIN']}' ," . time() . " ,0  ,'{$_POST['legend']}' ,{$small[1]} ,{$small[2]} ,{$common[1]} ,{$common[2]})");
                 $writeRespost = "<div class=\"qdestaques2\">Screenshot enviada com sucesso.</div>";
             } else {
                 $writeRespost = "<div class=\"qdestaques\">Arquivo inválido.</div>";
             }
         }
     }
     $amountScreens = $ldMssql->query("SELECT count([id]) count FROM [dbo].[webScreenshots] WHERE [uploadBy] = '" . $_SESSION['LOGIN'] . "'");
     $this->registerVariable("SCREENSHOTS_AMOUNT", mssql_fetch_object($amountScreens)->count);
     $deleteOptScreens = $ldMssql->query("SELECT [id], [legend], [rate] FROM [dbo].[webScreenshots] " . ($this->checkLogin()->previlegy != 2 ? "WHERE [uploadBy] = '" . $_SESSION['LOGIN'] . "'" : ""));
     while ($screen = mssql_fetch_object($deleteOptScreens)) {
         $tmpOpt .= "<option value=\"{$screen->id}\">{$screen->legend} - Votos: {$screen->rate}</option>";
     }
     $this->registerVariable("SCREENSHOTS_OPTIONS_DELETE", $tmpOpt);
     $this->registerVariable("RespostWrite", $writeRespost);
     $this->loadTemplate("paneluser[SCREENSHOT]");
 }
 private function uploadPicture(array $file, $width, $height, $path, $name = false)
 {
     require "dlimage.class.php";
     $dlImage = new DLImage();
     if ($dlImage->uploadImage($file, true, $path) == true) {
         if ($dlImage->info['width'] > $width) {
             $common = $dlImage->resizeAndSave($width, 0, false, true, false, $path, "jpg", false, 'large', $name);
         } else {
             $dlImage->saveImage(false, $path, 'jpg', 'large', $name);
             $common = array(0 => NULL, $width, $height);
         }
         $small = $dlImage->resizeAndSave(150, 150, false, true, false, $path, "jpg", false, 'small', $name);
         $dlImage->deleteBufferImage();
         return true;
     }
     return false;
 }