コード例 #1
0
ファイル: lanch_nzap_view.class.php プロジェクト: GGF/baza4
 public function createsl($rec)
 {
     extract($rec);
     $excel = file_get_contents($this->getDir() . $template);
     if ($fileext == "xml") {
         // усли шаблон xml файл
         // заменяем в xml файле данные попадающие под шаблон _имя_ на переменную имя из $rec
         preg_match_all('/_([0-9a-z]+)_/', $excel, $matchesarray);
         for ($i = 0; $i < count($matchesarray[0]); $i++) {
             $excel = str_replace($matchesarray[0][$i], ${$matchesarray[1][$i]}, $excel);
         }
     } elseif ($fileext == "xls") {
         // а шаблон может быть и xls файлом,
         if (fileserver::savefile("{$filename}.txt", $rec)) {
             $url = "http://baza3.mpp/?level=getdata&getdata[act]=checksl&slid={$number}";
             try {
                 $barcode = new QR_Code(-1, QR_ErrorCorrectLevel::H);
                 $barcode->addData($url);
                 $barcode->make();
                 $imgbarcode = new QR_CodeImage($barcode, 150, 150, 10);
                 $imgbarcode->draw();
                 $imgbarcode->store("{$filename}.jpg");
                 $imgbarcode->finish();
                 @chmod("{$filename}.jpg", 0777);
             } catch (Exception $ex) {
                 console::getInstance()->out($ex->getMessage());
                 console::getInstance()->out($ex->getTraceAsString());
             }
             /*$barcode = new BarcodeQR();
               $barcode->url($url);
               $barcode->draw(150, "{$filename}.png");
               */
         } else {
             $out = "Не удалось создать файл txt";
             return false;
         }
         // а сам xls запишитеся ниже
     } else {
         // вернем ошибку или в будущем как-то обработаем файл
         return false;
     }
     // сохранить
     if (fileserver::savefile($filename, $excel)) {
         Output::assign('sllink', fileserver::sharefilelink($filename));
         Output::assign('slid', $lanch_id);
         $out = $this->fetch('partylink.tpl') . ($last ? '<script>reload_table();</script>' : '');
     } else {
         $out = "Не удалось записать файл";
         $out = false;
     }
     // вернуть ссылку на файл
     return $out;
 }
コード例 #2
0
ファイル: QR_CodeImage.class.php プロジェクト: GGF/baza4
 /**
  * Draw the image
  */
 public function draw()
 {
     $moduleCount = $this->qrcode->getModuleCount();
     $tileWidth = $this->width / $moduleCount;
     $tileHeight = $this->height / $moduleCount;
     $this->img = imagecreatetruecolor($this->width, $this->height);
     if ($this->img) {
         $fg = imagecolorallocate($this->img, 0, 0, 0);
         if ($fg === false) {
             $this->finish();
             throw new QR_CodeImageException('Could not allocate foreground color!');
         }
         $bg = imagecolorallocate($this->img, 255, 255, 255);
         if ($bg === false) {
             $this->finish();
             throw new QR_CodeImageException('Could not allocate background color!');
         }
         for ($row = 0; $row < $moduleCount; $row++) {
             for ($col = 0; $col < $moduleCount; $col++) {
                 $fillStyle = $this->qrcode->isDark($row, $col) ? $fg : $bg;
                 $x = round($col * $tileWidth);
                 $y = round($row * $tileHeight);
                 $w = ceil(($col + 1) * $tileWidth) - floor($col * $tileWidth);
                 if ($x + $w > $this->width) {
                     $w = $this->width - $x;
                 }
                 $h = ceil(($row + 1) * $tileWidth) - floor($row * $tileWidth);
                 if ($y + $h > $this->height) {
                     $h = $this->height - $y;
                 }
                 if (!imagefilledrectangle($this->img, $x, $y, $x + $w, $y + $h, $fillStyle)) {
                     $this->finish();
                     throw new QR_CodeImageException(sprintf('Could not fill the rectangle using desired coordinates (x = %d, y = %d, w = %d, h = %d, c = %d)', $x, $y, $w, $h, $fillStyle));
                 }
             }
         }
     } else {
         throw new QR_CodeImageException('Could not create true color image buffer!');
     }
 }
コード例 #3
0
ファイル: QR_Util.class.php プロジェクト: GGF/baza4
 /**
  * Calculate the lost point
  * 
  * @param QR_Code $qrCode
  * 
  * @return number
  */
 public function getLostPoint(QR_Code $qrCode)
 {
     $moduleCount = $qrCode->getModuleCount();
     $lostPoint = 0;
     // Level 1
     for ($row = 0; $row < $moduleCount; $row++) {
         for ($col = 0; $col < $moduleCount; $col++) {
             $sameCount = 0;
             $dark = $qrCode->isDark($row, $col);
             for ($r = -1; $r <= 1; $r++) {
                 if ($row + $r < 0 || $moduleCount <= $row + $r) {
                     continue;
                 }
                 for ($c = -1; $c <= 1; $c++) {
                     if ($col + $c < 0 || $moduleCount <= $col + $c) {
                         continue;
                     }
                     if ($r == 0 && $c == 0) {
                         continue;
                     }
                     if ($dark == $qrCode->isDark($row + $r, $col + $c)) {
                         $sameCount++;
                     }
                 }
             }
             if ($sameCount > 5) {
                 $lostPoint += 3 + $sameCount - 5;
             }
         }
     }
     // Level 2
     for ($row = 0; $row < $moduleCount - 1; $row++) {
         for ($col = 0; $col < $moduleCount - 1; $col++) {
             $count = 0;
             if ($qrCode->isDark($row, $col)) {
                 $count++;
             }
             if ($qrCode->isDark($row + 1, $col)) {
                 $count++;
             }
             if ($qrCode->isDark($row, $col + 1)) {
                 $count++;
             }
             if ($qrCode->isDark($row + 1, $col + 1)) {
                 $count++;
             }
             if ($count == 0 || $count == 4) {
                 $lostPoint += 3;
             }
         }
     }
     // Level 3
     for ($row = 0; $row < $moduleCount; $row++) {
         for ($col = 0; $col < $moduleCount - 6; $col++) {
             if ($qrCode->isDark($row, $col) && !$qrCode->isDark($row, $col + 1) && $qrCode->isDark($row, $col + 2) && $qrCode->isDark($row, $col + 3) && $qrCode->isDark($row, $col + 4) && !$qrCode->isDark($row, $col + 5) && $qrCode->isDark($row, $col + 6)) {
                 $lostPoint += 40;
             }
         }
     }
     for ($col = 0; $col < $moduleCount; $col++) {
         for ($row = 0; $row < $moduleCount - 6; $row++) {
             if ($qrCode->isDark($row, $col) && !$qrCode->isDark($row + 1, $col) && $qrCode->isDark($row + 2, $col) && $qrCode->isDark($row + 3, $col) && $qrCode->isDark($row + 4, $col) && !$qrCode->isDark($row + 5, $col) && $qrCode->isDark($row + 6, $col)) {
                 $lostPoint += 40;
             }
         }
     }
     // Level 4
     $darkCount = 0;
     for ($col = 0; $col < $moduleCount; $col++) {
         for ($row = 0; $row < $moduleCount; $row++) {
             if ($qrCode->isDark($row, $col)) {
                 $darkCount++;
             }
         }
     }
     $ratio = abs(100 * $darkCount / $moduleCount / $moduleCount - 50) / 5;
     $lostPoint += $ratio * 10;
     return $lostPoint;
 }