コード例 #1
0
ファイル: MoveCollection.php プロジェクト: nlegoff/Phraseanet
 public function apply(Application $app, Request $request)
 {
     $records = RecordsRequest::fromRequest($app, $request, false, ['candeleterecord']);
     $datas = ['success' => false, 'message' => ''];
     try {
         if (null === $request->request->get('base_id')) {
             $datas['message'] = $app->trans('Missing target collection');
             return $app->json($datas);
         }
         if (!$app['acl']->get($app['authentication']->getUser())->has_right_on_base($request->request->get('base_id'), 'canaddrecord')) {
             $datas['message'] = $app->trans("You do not have the permission to move records to %collection%", ['%collection%', \phrasea::bas_labels($request->request->get('base_id'), $app)]);
             return $app->json($datas);
         }
         try {
             $collection = \collection::get_from_base_id($app, $request->request->get('base_id'));
         } catch (\Exception_Databox_CollectionNotFound $e) {
             $datas['message'] = $app->trans('Invalid target collection');
             return $app->json($datas);
         }
         foreach ($records as $record) {
             $record->move_to_collection($collection, $app['phraseanet.appbox']);
             if ($request->request->get("chg_coll_son") == "1") {
                 foreach ($record->get_children() as $child) {
                     if ($app['acl']->get($app['authentication']->getUser())->has_right_on_base($child->get_base_id(), 'candeleterecord')) {
                         $child->move_to_collection($collection, $app['phraseanet.appbox']);
                     }
                 }
             }
         }
         $ret = ['success' => true, 'message' => $app->trans('Records have been successfuly moved')];
     } catch (\Exception $e) {
         $ret = ['success' => false, 'message' => $app->trans('An error occured')];
     }
     return $app->json($ret);
 }
コード例 #2
0
ファイル: download.php プロジェクト: nlegoff/Phraseanet
 private function formatCollId($value)
 {
     return phrasea::bas_labels(phrasea::baseFromColl($this->sbas_id, $value, $this->app), $this->app);
 }
コード例 #3
0
ファイル: PDF.php プロジェクト: luisbrito/Phraseanet
 protected function print_preview($withtdm, $write_caption)
 {
     if ($withtdm === true) {
         $this->print_thumbnailGrid($this->pdf, $this->records, true);
     }
     foreach ($this->records as $krec => $rec) {
         /* @var $rec record_adapter */
         $this->pdf->AddPage();
         if ($withtdm === "CALCPAGES") {
             $rec->setNumber($this->pdf->PageNo());
         }
         $lmargin = $this->pdf->GetX();
         $himg = 0;
         $y = 0;
         $miniConv = NULL;
         $LEFT__TEXT = "";
         $LEFT__IMG = NULL;
         $RIGHT_TEXT = "";
         $RIGHT_IMG = NULL;
         $LEFT__IMG = $this->app['root.path'] . "/config/minilogos/logopdf_" . $rec->get_sbas_id() . ".jpg";
         if (!is_file($LEFT__IMG)) {
             $databox = $rec->get_databox();
             $str = $databox->get_sxml_structure();
             $vn = (string) $str->pdfPrintLogo;
             if ($vn * 1 == 1) {
                 $LEFT__TEXT = $databox->get_label($this->app['locale']);
             }
         }
         $collection = \collection::get_from_base_id($this->app, $rec->get_base_id());
         $vn = "";
         if (false !== ($str = simplexml_load_string($collection->get_prefs()))) {
             $vn = (string) $str->pdfPrintappear;
         }
         if ($vn == "" || $vn == "1") {
             $RIGHT_TEXT = \phrasea::bas_labels($rec->get_base_id(), $this->app);
         } elseif ($vn == "2") {
             $RIGHT_IMG = $this->app['root.path'] . "/config/minilogos/" . $rec->get_base_id();
         }
         $xtmp = $this->pdf->GetX();
         $ytmp = $this->pdf->GetY();
         $this->pdf->SetFont(PhraseaPDF::FONT, '', 12);
         $this->pdf->SetFillColor(220, 220, 220);
         $y = $this->pdf->GetY();
         $this->pdf->MultiCell(95, 7, $LEFT__TEXT, "LTB", "L", 1);
         $y2 = $this->pdf->GetY();
         $h = $y2 - $y;
         $this->pdf->SetY($y);
         $this->pdf->SetX(105);
         $this->pdf->Cell(95, $h, $RIGHT_TEXT, "TBR", 1, "R", 1);
         if ($LEFT__TEXT == "" && is_file($LEFT__IMG)) {
             if ($size = @getimagesize($LEFT__IMG)) {
                 $wmm = (int) $size[0] * 25.4 / 72;
                 $hmm = (int) $size[1] * 25.4 / 72;
                 if ($hmm > 6) {
                     $coeff = $hmm / 6;
                     $wmm = (int) $wmm / $coeff;
                     $hmm = (int) $hmm / $coeff;
                 }
                 $this->pdf->Image($LEFT__IMG, $xtmp + 0.5, $ytmp + 0.5, $wmm, $hmm);
             }
         }
         if ($RIGHT_IMG != NULL && is_file($RIGHT_IMG)) {
             if ($size = @getimagesize($RIGHT_IMG)) {
                 if ($size[2] == '1') {
                     if (!isset($miniConv[$RIGHT_IMG])) {
                         $tmp_filename = tempnam('minilogos/', 'gif4fpdf');
                         $img = imagecreatefromgif($RIGHT_IMG);
                         imageinterlace($img, 0);
                         imagepng($img, $tmp_filename);
                         rename($tmp_filename, $tmp_filename . '.png');
                         $miniConv[$RIGHT_IMG] = $tmp_filename . '.png';
                         $RIGHT_IMG = $tmp_filename . '.png';
                     } else {
                         $RIGHT_IMG = $miniConv[$RIGHT_IMG];
                     }
                     $wmm = (int) $size[0] * 25.4 / 72;
                     $hmm = (int) $size[1] * 25.4 / 72;
                     if ($hmm > 6) {
                         $coeff = $hmm / 6;
                         $wmm = (int) $wmm / $coeff;
                         $hmm = (int) $hmm / $coeff;
                     }
                     $tt = 0;
                     if ($hmm < 6) {
                         $tt = (6 - $hmm) / 2;
                     }
                     $this->pdf->Image($RIGHT_IMG, 200 - 0.5 - $wmm, $ytmp + 0.5 + $tt);
                 } else {
                     $wmm = (int) $size[0] * 25.4 / 72;
                     $hmm = (int) $size[1] * 25.4 / 72;
                     if ($hmm > 6) {
                         $coeff = $hmm / 6;
                         $wmm = (int) $wmm / $coeff;
                         $hmm = (int) $hmm / $coeff;
                     }
                     $this->pdf->Image($RIGHT_IMG, 200 - 0.5 - $wmm, $ytmp + 0.5);
                 }
             }
         }
         $y = $this->pdf->GetY() + 5;
         $subdef = $rec->get_subdef('preview');
         if ($subdef->get_type() !== \media_subdef::TYPE_IMAGE) {
             $subdef = $rec->get_thumbnail();
         }
         $f = $subdef->get_pathfile();
         if (!$this->app->getAclForUser($this->app->getAuthenticatedUser())->has_right_on_base($rec->get_base_id(), "nowatermark") && $subdef->get_type() == \media_subdef::TYPE_IMAGE) {
             $f = \recordutils_image::watermark($this->app, $subdef);
         }
         // original height / original width x new width = new height
         $wimg = $himg = 150;
         // preview dans un carre de 150 mm
         // 1px = 3.77952 mm
         $finalWidth = round($subdef->get_width() / 3.779528, 2);
         $finalHeight = round($subdef->get_height() / 3.779528, 2);
         $aspectH = $finalWidth / $finalHeight;
         $aspectW = $finalHeight / $finalWidth;
         if ($finalWidth > 0 && $finalHeight > 0) {
             if ($finalWidth > $finalHeight && $finalWidth > $wimg) {
                 $finalWidth = $wimg;
                 $finalHeight = $wimg * $aspectW;
             } else {
                 if ($finalHeight > $finalWidth && $finalHeight > $himg) {
                     $finalHeight = $himg;
                     $finalWidth = $himg * $aspectH;
                 } else {
                     if ($finalHeight == $finalWidth & $finalWidth > $wimg) {
                         $finalHeight = $wimg;
                         $finalWidth = $himg;
                     }
                 }
             }
         }
         $this->pdf->Image($f, (210 - $finalWidth) / 2, $y, $finalWidth, $finalHeight);
         if ($miniConv != NULL) {
             foreach ($miniConv as $oneF) {
                 unlink($oneF);
             }
         }
         $this->pdf->SetXY($lmargin, $y += $finalHeight + 5);
         $nf = 0;
         if ($write_caption) {
             foreach ($rec->get_caption()->get_fields() as $field) {
                 /* @var $field caption_field */
                 if ($nf > 0) {
                     $this->pdf->Write(6, "\n");
                 }
                 $this->pdf->SetFont(PhraseaPDF::FONT, 'B', 12);
                 $this->pdf->Write(5, $field->get_name() . " : ");
                 $this->pdf->SetFont(PhraseaPDF::FONT, '', 12);
                 $t = str_replace(["&lt;", "&gt;", "&amp;"], ["<", ">", "&"], strip_tags($field->get_serialized_values()));
                 $this->pdf->Write(5, $t);
                 $nf++;
             }
         }
     }
     return;
 }
コード例 #4
0
ファイル: collection.php プロジェクト: nlegoff/Phraseanet
 public static function getLogo($base_id, Application $app, $printname = false)
 {
     $base_id_key = $base_id . '_' . ($printname ? '1' : '0');
     if (!isset(self::$_logos[$base_id_key])) {
         if (is_file($app['root.path'] . '/config/minilogos/' . $base_id)) {
             $name = phrasea::bas_labels($base_id, $app);
             self::$_logos[$base_id_key] = '<img title="' . $name . '" src="/custom/minilogos/' . $base_id . '" />';
         } elseif ($printname) {
             self::$_logos[$base_id_key] = phrasea::bas_labels($base_id, $app);
         }
     }
     return isset(self::$_logos[$base_id_key]) ? self::$_logos[$base_id_key] : '';
 }
コード例 #5
0
ファイル: FtpJob.php プロジェクト: nlegoff/Phraseanet
 private function send_mails(Application $app, FtpExport $export)
 {
     $transferts = [];
     $transfert_status = $this->translator->trans('task::ftp:Tous les documents ont ete transferes avec succes');
     foreach ($export->getElements() as $element) {
         if (!$element->isError() && $element->isDone()) {
             $transferts[] = '<li>' . $this->translator->trans('task::ftp:Record %recordid% - %filename% de la base (%databoxname% - %collectionname%) - %subdefname%', ['%recordid%' => $element->getRecordId(), '%filename%' => $element->getFilename(), '%databoxname%' => \phrasea::sbas_labels(\phrasea::sbasFromBas($app, $element->getBaseId()), $app), '%collectionname%' => \phrasea::bas_labels($element->getBaseId(), $app), $element->getSubdef(), '%subdefname%' => $element->getSubdef()]) . ' : ' . $this->translator->trans('Transfert OK') . '</li>';
         } else {
             $transferts[] = '<li>' . $this->translator->trans('task::ftp:Record %recordid% - %filename% de la base (%databoxname% - %collectionname%) - %subdefname%', ['%recordid%' => $element->getRecordId(), '%filename%' => $element->getFilename(), '%databoxname%' => \phrasea::sbas_labels(\phrasea::sbasFromBas($app, $element->getBaseId()), $app), '%collectionname%' => \phrasea::bas_labels($element->getBaseId(), $app), $element->getSubdef(), '%subdefname%' => $element->getSubdef()]) . ' : ' . $this->translator->trans('Transfert Annule') . '</li>';
             $transfert_status = $this->translator->trans('task::ftp:Certains documents n\'ont pas pu etre tranferes');
         }
     }
     if ($export->getCrash() >= $export->getNbretry()) {
         $connection_status = $this->translator->trans('Des difficultes ont ete rencontres a la connection au serveur distant');
     } else {
         $connection_status = $this->translator->trans('La connection vers le serveur distant est OK');
     }
     $text_mail_sender = $export->getTextMailSender();
     $text_mail_receiver = $export->getTextMailReceiver();
     $sendermail = $export->getSendermail();
     $ftp_server = $export->getAddr();
     $message = "\n\n----------------------------------------\n\n";
     $message = $connection_status . "\n";
     $message .= $transfert_status . "\n";
     $message .= $this->translator->trans("task::ftp:Details des fichiers") . "\n\n";
     $message .= implode("\n", $transferts);
     $sender_message = $text_mail_sender . $message;
     $receiver_message = $text_mail_receiver . $message;
     try {
         $receiver = new Receiver(null, $sendermail);
         $mail = MailSuccessFTPSender::create($app, $receiver, null, $sender_message);
         $mail->setServer($ftp_server);
         $app['notification.deliverer']->deliver($mail);
     } catch (InvalidArgumentException $e) {
     }
     try {
         $receiver = new Receiver(null, $export->getMail());
         $mail = MailSuccessFTPReceiver::create($app, $receiver, null, $receiver_message);
         $mail->setServer($ftp_server);
         $app['notification.deliverer']->deliver($mail);
     } catch (\Exception $e) {
         $this->log('debug', sprintf('Unable to deliver success message : %s', $e->getMessage()));
     }
 }
コード例 #6
0
 public function getCollectionLogo($baseId)
 {
     if (false === $this->app['filesystem']->exists(sprintf('%s/config/minilogos/%s', $this->app['root.path'], $baseId))) {
         return '';
     }
     return sprintf('<img title="%s" src="/custom/minilogos/%s" />', \phrasea::bas_labels($baseId, $this->app), $baseId);
 }