Add prod refactor

Fix issue

Conflicts:

	lib/Alchemy/Phrasea/Controller/Prod/Share.php
	lib/Alchemy/Phrasea/Controller/User/Notifications.php
	lib/Alchemy/Phrasea/Controller/User/Preferences.php
	templates/web/common/dialog_export.html.twig
This commit is contained in:
Nicolas Le Goff
2012-10-09 19:50:10 +02:00
parent b95954791e
commit cde9ce18ae
13 changed files with 1282 additions and 427 deletions

View File

@@ -35,6 +35,7 @@ use Alchemy\Phrasea\Controller\Admin\Users;
use Alchemy\Phrasea\Controller\Prod\Basket;
use Alchemy\Phrasea\Controller\Prod\Bridge;
use Alchemy\Phrasea\Controller\Prod\Edit;
use Alchemy\Phrasea\Controller\Prod\Export;
use Alchemy\Phrasea\Controller\Prod\Feed;
use Alchemy\Phrasea\Controller\Prod\Language;
use Alchemy\Phrasea\Controller\Prod\Lazaret;
@@ -51,11 +52,12 @@ use Alchemy\Phrasea\Controller\Prod\Tools;
use Alchemy\Phrasea\Controller\Prod\Tooltip;
use Alchemy\Phrasea\Controller\Prod\TOU;
use Alchemy\Phrasea\Controller\Prod\Upload;
use Alchemy\Phrasea\Controller\Prod\UserPreferences;
use Alchemy\Phrasea\Controller\Prod\UsrLists;
use Alchemy\Phrasea\Controller\Prod\WorkZone;
use Alchemy\Phrasea\Controller\Utils\ConnectionTest;
use Alchemy\Phrasea\Controller\Utils\PathFileTest;
use Alchemy\Phrasea\Controller\User\Notifications;
use Alchemy\Phrasea\Controller\User\Preferences;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpFoundation\RedirectResponse;
@@ -127,7 +129,6 @@ return call_user_func(function($environment = null) {
$app->mount('/admin/tests/connection', new ConnectionTest());
$app->mount('/admin/tests/pathurl', new PathFileTest());
$app->mount('/prod/UserPreferences/', new UserPreferences());
$app->mount('/prod/query/', new Query());
$app->mount('/prod/order/', new Order());
$app->mount('/prod/baskets', new Basket());
@@ -141,6 +142,8 @@ return call_user_func(function($environment = null) {
$app->mount('/prod/bridge/', new Bridge());
$app->mount('/prod/push/', new Push());
$app->mount('/prod/printer/', new Printer());
$app->mount('/prod/share/', new Share());
$app->mount('/prod/export/', new Export());
$app->mount('/prod/TOU/', new TOU());
$app->mount('/prod/feeds', new Feed());
$app->mount('/prod/tooltip', new Tooltip());
@@ -150,6 +153,9 @@ return call_user_func(function($environment = null) {
$app->mount('/prod/upload/', new Upload());
$app->mount('/prod/', new Prod());
$app->mount('/user/preferences/', new Preferences());
$app->mount('/user/notifications/', new Notifications());
$app->error(function(\Exception $e) use ($app) {
$request = $app['request'];

View File

@@ -0,0 +1,296 @@
<?php
/*
* This file is part of Phraseanet
*
* (c) 2005-2012 Alchemy
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Alchemy\Phrasea\Controller\Prod;
use Silex\Application;
use Silex\ControllerProviderInterface;
use Symfony\Component\Filesystem\Filesystem;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
/**
*
* @license http://opensource.org/licenses/gpl-3.0 GPLv3
* @link www.phraseanet.com
*/
class Export implements ControllerProviderInterface
{
/**
* {@inheritDoc}
*/
public function connect(Application $app)
{
$controllers = $app['controllers_factory'];
$controllers->before(function(Request $request) use ($app) {
$app['firewall']->requireNotGuest();
});
/**
* Display multi export
*
* name : export_multi_export
*
* description : Display multi export
*
* method : POST
*
* parameters : none
*
* return : HTML Response
*/
$controllers->post('/multi-export/', $this->call('displayMultiExport'))
->bind('export_multi_export');
/**
* Export by mail
*
* name : export_mail
*
* description : Export by mail
*
* method : POST
*
* parameters : none
*
* return : JSON Response
*/
$controllers->post('/mail/', $this->call('exportMail'))
->bind('export_mail');
/**
* Export by FTP
*
* name : export_ftp
*
* description : Export by FTP
*
* method : POST
*
* parameters : none
*
* return : JSON Response
*/
$controllers->post('/ftp/', $this->call('exportFtp'))
->bind('export_ftp');
/**
* Test FTP connexion
*
* name : export_ftp_test
*
* description : Test a FTP connexion
*
* method : POST
*
* parameters : none
*
* return : JSON Response
*/
$controllers->post('/ftp/test/', $this->call('testFtpConnexion'))
->bind('export_ftp_test');
return $controllers;
}
/**
* Display form to export documents
*
* @param Application $app
* @param Request $request
* @return Response
*/
public function displayMultiExport(Application $app, Request $request)
{
$download = new \set_export($app, $request->request->get('lst', ''), (int) $request->request->get('ssel'), $request->request->get('story'));
return new Response($app['twig']->render('common/dialog_export.html.twig', array(
'download' => $download,
'ssttid' => $request->request->get('ssel'),
'lst' => $download->serialize_list(),
'default_export_title' => $app['phraseanet.registry']->get('GV_default_export_title'),
'choose_export_title' => $app['phraseanet.registry']->get('GV_choose_export_title')
)));
}
/**
* Test a FTP connexion
*
* @param Application $app
* @param Request $request
* @return JsonResponse
*/
public function testFtpConnexion(Application $app, Request $request)
{
if (!$request->isXmlHttpRequest()) {
$app->abort(400);
}
$success = false;
try {
$ftpClient = $app['phraseanet.ftp.client']($request->request->get('addr', ''), 21, 90, !!$request->request->get('ssl'));
$ftpClient->login($request->request->get('login', ''), $request->request->get('pwd', ''));
$ftpClient->close();
$msg = _('Connection to FTP succeed');
$success = true;
} catch (Exception $e) {
$msg = sprintf(_('Error while connecting to FTP'));
}
return $app->json(array(
'success' => $success,
'message' => $msg
));
}
/**
*
* @param Application $app
* @param Request $request
* @return JsonResponse
*/
public function exportFtp(Application $app, Request $request)
{
$download = new \set_exportftp($app, $request->request->get('lst'), $request->request->get('ssttid'));
if (null === $address = $request->request->get('addr')) {
$app->abort(400, _('Missing ftp adress'));
}
if (null === $login = $request->request->get('login')) {
$app->abort(400, _('Missing ftp lofin'));
}
if (null === $destFolder = $request->request->get('destfolder')) {
$app->abort(400, _('Missing destination folder'));
}
if (null === $folderTocreate = $request->request->get('NAMMKDFOLD')) {
$app->abort(400, _('Missing folder to create'));
}
if (null === $subdefs = $request->request->get('obj')) {
$app->abort(400, _('Missing subdefs to export'));
}
if (count($download->get_display_ftp()) == 0) {
return $app->json(array('success' => false, 'message' => _('Documents can be sent by FTP')));
} else {
try {
$download->prepare_export($app['phraseanet.user'], $app['filesystem'], $request->request->get('obj'), false, $request->request->get('businessfields'));
$download->export_ftp($request->request->get('user_dest'), $address, $login, $request->request->get('pwd', ''), $request->request->get('ssl'), $request->request->get('nbretry'), $request->request->get('passif'), $destFolder, $folderTocreate, $request->request->get('logfile'));
return $app->json(array(
'success' => true,
'message' => _('Export saved in the waiting queue')
));
} catch (Exception $e) {
return $app->json(array(
'success' => false,
'message' => _('Something gone wrong')
));
}
}
}
public function exportMail(Application $app, Request $request)
{
set_time_limit(0);
session_write_close();
ignore_user_abort(true);
//prepare export
$download = new \set_export($app, $request->get('lst', ''), $request->get('ssttid', ''));
$list = $download->prepare_export($app['phraseanet.user'], $app['filesystem'], $request->get('obj'), $request->get("type") == "title" ? : false, $request->get('businessfields'));
$list['export_name'] = sprintf("%s.zip", $download->getExportName());
$list['email'] = $request->get("destmail", "");
$destMails = array();
//get destination mails
foreach (explode(";", $list['email']) as $mail) {
if (filter_var($mail, FILTER_VALIDATE_EMAIL)) {
$destMails[] = $mail;
} else {
$app['events-manager']->trigger('__EXPORT_MAIL_FAIL__', array(
'usr_id' => $app['phraseanet.user']->get_id(),
'lst' => $request->get('lst', ''),
'ssttid' => $request->get('ssttid', ''),
'dest' => $mail,
'reason' => \eventsmanager_notify_downloadmailfail::MAIL_NO_VALID
));
}
}
//generate validation token
$endDateObject = new \DateTime('+1 day');
$token = \random::getUrlToken($app, \random::TYPE_EMAIL, false, $endDateObject, serialize($list));
if (count($destMails) > 0 && $token) {
//zip documents
\set_export::build_zip(new Filesystem(), $token, $list, $app['phraseanet.registry']->get('GV_RootPath') . 'tmp/download/' . $token . '.zip');
$remaingEmails = $destMails;
$url = $app['phraseanet.registry']->get('GV_ServerName') . 'mail-export/' . $token . '/';
$from = array(
'name' => $app['phraseanet.user']->get_display_name(),
'email' => $app['phraseanet.user']->get_email()
);
//send mails
foreach ($destMails as $key => $mail) {
if (\mail::send_documents($app, trim($mail), $url, $from, $endDateObject, $request->get('textmail'), $request->get('reading_confirm') == '1' ? : false)) {
unset($remaingEmails[$key]);
}
}
//some mails failed
if (count($remaingEmails) > 0) {
foreach ($remaingEmails as $mail) {
$app['events-manager']->trigger('__EXPORT_MAIL_FAIL__', array(
'usr_id' => $app['phraseanet.user']->get_id(),
'lst' => $request->get('lst', ''),
'ssttid' => $request->get('ssttid', ''),
'dest' => $mail,
'reason' => \eventsmanager_notify_downloadmailfail::MAIL_FAIL
));
}
}
} elseif (!$token && count($destMails) > 0) { //couldn't generate token
foreach ($destMails as $mail) {
$app['events-manager']->trigger('__EXPORT_MAIL_FAIL__', array(
'usr_id' => $app['phraseanet.user']->get_id(),
'lst' => $request->get('lst', ''),
'ssttid' => $request->get('ssttid', ''),
'dest' => $mail,
'reason' => 0
));
}
}
}
/**
* Prefix the method to call with the controller class name
*
* @param string $method The method to call
* @return string
*/
private function call($method)
{
return sprintf('%s::%s', __CLASS__, $method);
}
}

View File

@@ -101,6 +101,7 @@ class Language implements ControllerProviderInterface
$out['feedbackCanContribute'] = _('User contribute to the feedback');
$out['feedbackCanSeeOthers'] = _('User can see others choices');
$out['forceSendDocument'] = _('Force sending of the document ?');
$out['export'] = _('Export');
return $app->json($out);
});

View File

@@ -13,7 +13,9 @@ namespace Alchemy\Phrasea\Controller\Prod;
use Silex\Application;
use Silex\ControllerProviderInterface;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
/**
*
@@ -31,7 +33,27 @@ class Query implements ControllerProviderInterface
$app['firewall']->requireAuthentication();
});
$controllers->post('/', function(Application $app, Request $request) {
$controllers->post('/', $this->call('query'))
->bind('prod_query');
$controllers->post('/answer-train/', $this->call('queryAnswerTrain'))
->bind('preview_answer_train');
$controllers->post('/reg-train/', $this->call('queryRegTrain'))
->bind('preview_reg_train');
return $controllers;
}
/**
* Query Phraseanet to fetch records
*
* @param Application $app
* @param Request $request
* @return JsonResponse
*/
public function query(Application $app, Request $request)
{
$query = (string) $request->request->get('qry');
$mod = $app['phraseanet.user']->getPrefs('view');
@@ -200,8 +222,60 @@ class Query implements ControllerProviderInterface
$json['form'] = $form;
return $app->json($json);
});
}
return $controllers;
/**
*
* @param Application $app
* @param Request $request
* @return JsonResponse
*/
public function queryAnswerTrain(Application $app, Request $request)
{
$searchEngine = null;
if (($options = unserialize($request->request->get('options_serial'))) !== false) {
$searchEngine = new \searchEngine_adapter($app);
$searchEngine->set_options($options);
}
$pos = $request->request->get('pos');
$query = $request->request->get('query');
$record = new \record_preview($app, 'RESULT', $pos, '', '', $searchEngine, $query);
return $app->json(array(
'current' => $app['twig']->render('prod/preview/result_train.html.twig', array(
'records' => $record->get_train($pos, $query, $searchEngine),
'selected' => $pos
))
));
}
/**
*
* @param Application $app
* @param Request $request
* @return Response
*/
public function queryRegTrain(Application $app, Request $request)
{
$record = new \record_preview($app, 'REG', $request->request->get('pos'), $request->request->get('cont'));
return $app['twig']->render('prod/preview/reg_train.html.twig', array(
'container_records' => $record->get_container()->get_children(),
'record' => $record
));
}
/**
* Prefix the method to call with the controller class name
*
* @param string $method The method to call
* @return string
*/
private function call($method)
{
return sprintf('%s::%s', __CLASS__, $method);
}
}

View File

@@ -14,6 +14,7 @@ namespace Alchemy\Phrasea\Controller\Prod\Record;
use Alchemy\Phrasea\Controller\RecordsRequest;
use Silex\Application;
use Silex\ControllerProviderInterface;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
@@ -39,12 +40,54 @@ class Property implements ControllerProviderInterface
}
});
/**
* Display records property
*
* name : display_property
*
* description : Display records property
*
* method : GET
*
* parameters : none
*
* return : HTML Response
*/
$controllers->get('/', $this->call('displayProperty'))
->bind('display_property');
/**
* Change records status
*
* name : change_status
*
* description : Change records status
*
* method : POST
*
* parameters : none
*
* return : JSON Response
*/
$controllers->post('/status/', $this->call('changeStatus'))
->bind('change_status');
/**
* Change records type
*
* name : change_type
*
* description : Change records type
*
* method : POST
*
* parameters : none
*
* return : JSON Response
*/
$controllers->post('/type/', $this->call('changeType'))
->bind('change_type');
return $controllers;
}
@@ -69,30 +112,13 @@ class Property implements ControllerProviderInterface
if (!$app['phraseanet.user']->ACL()->has_hd_grant($record) ||
!$app['phraseanet.user']->ACL()->has_preview_grant($record)) {
try {
$conn = $record->get_databox()->get_connection();
$sql = sprintf('SELECT record_id FROM record WHERE ((status ^ %s) & %s) = 0 AND record_id = :record_id', $app['phraseanet.user']->ACL()->get_mask_xor($record->get_base_id()), $app['phraseanet.user']->ACL()->get_mask_and($record->get_base_id()));
$stmt = $conn->prepare($sql);
$stmt = $record->get_databox()->get_connection()->prepare(sprintf('SELECT record_id FROM record WHERE ((status ^ %s) & %s) = 0 AND record_id = :record_id', $app['phraseanet.user']->ACL()->get_mask_xor($record->get_base_id()), $app['phraseanet.user']->ACL()->get_mask_and($record->get_base_id())));
$stmt->execute(array(':record_id' => $record->get_record_id()));
if (0 === $stmt->rowCount()) {
$toRemove[] = $key;
}
$stmt->closeCursor();
unset($stmt);
} catch (Exception $e) {
$toRemove[] = $key;
}
}
}
foreach ($toRemove as $key) {
$records->remove($key);
}
foreach ($records as $record) {
} else {
//perform logic
$sbasId = $record->get_databox()->get_sbas_id();
if (!isset($nRec[$sbasId])) {
@@ -113,7 +139,7 @@ class Property implements ControllerProviderInterface
$recordsType[$sbasId][$record->get_type()] = array();
}
$recordsType[$sbasId][$record->get_type()] = $record;
$recordsType[$sbasId][$record->get_type()][] = $record;
if (!isset($statusBit[$sbasId])) {
@@ -131,6 +157,18 @@ class Property implements ControllerProviderInterface
}
}
$stmt->closeCursor();
unset($stmt);
} catch (\Exception $e) {
$toRemove[] = $key;
}
}
}
foreach ($toRemove as $key) {
$records->remove($key);
}
foreach ($records->databoxes() as $databox) {
$sbasId = $databox->get_sbas_id();
foreach ($statusBit[$sbasId] as $bit => $values) {
@@ -138,14 +176,21 @@ class Property implements ControllerProviderInterface
}
}
return $app['twig']->render('prod/actions/Property/index.html.twig', array(
return new Response($app['twig']->render('prod/actions/Property/index.html.twig', array(
'records' => $records,
'statusBit' => $statusBit,
'recordsType' => $recordsType,
'nRec' => $nRec
));
)));
}
/**
* Change record status
*
* @param Application $app
* @param Request $request
* @return JsonResponse
*/
public function changeStatus(Application $app, Request $request)
{
$applyStatusToChildren = $request->request->get('apply_to_children', array());
@@ -157,12 +202,16 @@ class Property implements ControllerProviderInterface
$sbasId = $record->get_databox()->get_sbas_id();
//update record
$updated[$record->get_serialize_key()] = $this->updateRecordStatus($record, $postStatus);
if (null !== $updatedStatus = $this->updateRecordStatus($record, $postStatus)) {
$updated[$record->get_serialize_key()] = $updatedStatus;
}
//update children if current record is a story
if (isset($applyStatusToChildren[$sbasId]) && $record->is_grouping()) {
foreach ($record->get_children() as $child) {
$updated[$record->get_serialize_key()] = $this->updateRecordStatus($child, $postStatus);
if (null !== $updatedStatus = $this->updateRecordStatus($child, $postStatus)) {
$updated[$record->get_serialize_key()] = $updatedStatus;
}
}
}
}
@@ -170,6 +219,43 @@ class Property implements ControllerProviderInterface
return $app->json(array('success' => true, 'updated' => $updated), 201);
}
/**
* Change record type
*
* @param Application $app
* @param Request $request
* @return type
*/
public function changeType(Application $app, Request $request)
{
$typeLst = $request->request('types', array());
$records = RecordsRequest::fromRequest($app, $request, false, array('modifyrecord'));
$forceType = $request->request('force_types', '');
$updated = array();
foreach ($records as $record) {
try {
$recordType = !empty($forceType) ? $forceType : (isset($typeLst[$record->get_serialize_key()]) ? $typeLst[$record->get_serialize_key()] : null);
if ($recordType) {
$record->setType($recordType);
$updated[$record->get_serialize_key()] = $recordType;
}
} catch (\Exception $e) {
}
}
return $app->json(array('success' => true, 'updated' => $updated), 201);
}
/**
* Set new status to selected record
*
* @param \record_adapter $record
* @param array $postStatus
* @return array|null
*/
private function updateRecordStatus(\record_adapter $record, Array $postStatus)
{
$sbasId = $record->get_databox()->get_sbas_id();
@@ -190,6 +276,8 @@ class Property implements ControllerProviderInterface
'new_status' => $newStatus
);
}
return null;
}
/**

View File

@@ -126,19 +126,6 @@ class Root implements ControllerProviderInterface
));
});
$controllers->post('/multi-export/', function(Application $app, Request $request) {
$download = new \set_export($app, $request->request->get('lst', ''), (int) $request->request->get('ssel'), $request->request->get('story'));
return $app['twig']->render('common/dialog_export.html.twig', array(
'download' => $download,
'ssttid' => (int) $request->request->get('ssel'),
'lst' => $download->serialize_list(),
'default_export_title' => $app['phraseanet.registry']->get('GV_default_export_title'),
'choose_export_title' => $app['phraseanet.registry']->get('GV_choose_export_title')
));
});
return $controllers;
}
}

View File

@@ -0,0 +1,95 @@
<?php
/*
* This file is part of Phraseanet
*
* (c) 2005-2012 Alchemy
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Alchemy\Phrasea\Controller\Prod;
use Silex\Application;
use Silex\ControllerProviderInterface;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
/**
*
* @license http://opensource.org/licenses/gpl-3.0 GPLv3
* @link www.phraseanet.com
*/
class Share implements ControllerProviderInterface
{
/**
* {@inheritDoc}
*/
public function connect(Application $app)
{
$controllers = $app['controllers_factory'];
$controllers->before(function(Request $request) use ($app) {
$response = $app['firewall']->requireNotGuest();
if ($response instanceof Response) {
return $response;
}
});
/**
* Share a record
*
* name : share_record
*
* description : Share a record
*
* method : GET
*
* parameters : none
*
* return : HTML Response
*/
$controllers->get('/record/{base_id}/{record_id}/', $this->call('shareRecord'))
->before(function(Request $request) use ($app) {
$app['firewall']->requireRightOnBase(\phrasea::sbasFromBas($app, $request->attributes->get('base_id')), 'bas_chupub');
})
->bind('share_record');
return $controllers;
}
/**
* Share a record
*
* @param Application $app
* @param Request $request
* @param integer $base_id
* @param integer $record_id
* @return Response
*/
public function shareRecord(Application $app, Request $request, $base_id, $record_id)
{
$record = new \record_adapter($app, \phrasea::sbasFromBas($app, $base_id), $record_id);
if ( ! $app['phraseanet.user']->ACL()->has_access_to_subdef($record, 'preview')){
$app->abort(403);
}
return new Response($app['twig']->render('prod/Share/record.html.twig', array(
'record' => $record,
)));
}
/**
* Prefix the method to call with the controller class name
*
* @param string $method The method to call
* @return string
*/
private function call($method)
{
return sprintf('%s::%s', __CLASS__, $method);
}
}

View File

@@ -1,68 +0,0 @@
<?php
/*
* This file is part of Phraseanet
*
* (c) 2005-2012 Alchemy
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Alchemy\Phrasea\Controller\Prod;
use Silex\Application;
use Silex\ControllerProviderInterface;
use Symfony\Component\HttpFoundation\Request;
/**
*
* @license http://opensource.org/licenses/gpl-3.0 GPLv3
* @link www.phraseanet.com
*/
class UserPreferences implements ControllerProviderInterface
{
public function connect(Application $app)
{
$controllers = $app['controllers_factory'];
$controllers->before(function(Request $request) use ($app) {
$app['firewall']->requireAuthentication();
});
$controllers->post('/save/', $this->call('savePreference'));
return $controllers;
}
public function savePreference(Application $app, Request $request)
{
$ret = array('success' => false, 'message' => _('Error while saving preference'));
try {
$ret = $app['phraseanet.user']->setPrefs($request->request->get('prop'), $request->request->get('value'));
if ($ret == $request->request->get('value'))
$output = "1"; else
$output = "0";
$ret = array('success' => true, 'message' => _('Preference saved !'));
} catch (\Exception $e) {
}
return $app->json($ret);
}
/**
* Prefix the method to call with the controller class name
*
* @param string $method The method to call
* @return string
*/
private function call($method)
{
return sprintf('%s::%s', __CLASS__, $method);
}
}

View File

@@ -0,0 +1,123 @@
<?php
/*
* This file is part of Phraseanet
*
* (c) 2005-2012 Alchemy
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Alchemy\Phrasea\Controller\User;
use Silex\Application;
use Silex\ControllerProviderInterface;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\JsonResponse;
/**
*
* @license http://opensource.org/licenses/gpl-3.0 GPLv3
* @link www.phraseanet.com
*/
class Notifications implements ControllerProviderInterface
{
/**
* {@inheritDoc}
*/
public function connect(Application $app)
{
$controllers = $app['controllers_factory'];
$controllers->before(function(Request $request) use ($app) {
$app['firewall']->requireNotGuest();
});
/**
* Read all notifications
*
* name : read_notifications_full
*
* description : Read full notification
*
* method : GET
*
* parameters : none
*
* return : JSON Response
*/
$controllers->get('/', $this->call('listNotifications'))
->bind('get_notifications');
/**
* Read notifications
*
* name : read_notifications
*
* description : Read notification
*
* method : GET
*
* parameters : none
*
* return : JSON Response
*/
$controllers->post('/read/', $this->call('setNotificationsReaded'))
->bind('');
return $controllers;
}
/**
* Get the new notifications
*
* @param Application $app
* @param Request $request
* @return JsonResponse
*/
public function setNotificationsReaded(Application $app, Request $request)
{
if(!$request->isXmlHttpRequest()) {
$app->abort(400);
}
try {
$app['events-manager']->read(explode('_', (string) $request->query->get('notifications')), $app['phraseanet.user']->get_id());
return $app->json(array('success' => true, 'message' => ''));
} catch (Exception $e) {
return $app->json(array('success' => false, 'message' => $e->getMessage()));
}
}
/**
* Get all notifications
*
* @param Application $app
* @param Request $request
* @return JsonResponse
*/
public function listNotifications(Application $app, Request $request)
{
if(!$request->isXmlHttpRequest()) {
$app->abort(400);
}
$page = (int) $request->query->get('page', 1);
return $app->json($app['events-manager']->get_json_notifications(($page < 1 ? 1 : $page)));
}
/**
* Prefix the method to call with the controller class name
*
* @param string $method The method to call
* @return string
*/
private function call($method)
{
return sprintf('%s::%s', __CLASS__, $method);
}
}

View File

@@ -0,0 +1,133 @@
<?php
/*
* This file is part of Phraseanet
*
* (c) 2005-2012 Alchemy
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Alchemy\Phrasea\Controller\User;
use Silex\Application;
use Silex\ControllerProviderInterface;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\JsonResponse;
/**
*
* @license http://opensource.org/licenses/gpl-3.0 GPLv3
* @link www.phraseanet.com
*/
class Preferences implements ControllerProviderInterface
{
/**
* {@inheritDoc}
*/
public function connect(Application $app)
{
$controllers = $app['controllers_factory'];
$controllers->before(function(Request $request) use ($app) {
$app['firewall']->requireAuthentication();
});
/**
* Save preferences
*
* name : save_pref
*
* description : Save User preferences
*
* method : POST
*
* parameters : none
*
* return : JSON Response
*/
$controllers->post('/', $this->call('saveUserPref'))
->bind('save_pref');
/**
* Save CSS preferences
*
* name : save_css_pref
*
* description : Save CSS preferences
*
* method : POST
*
* parameters : none
*
* return : JSON Response
*/
$controllers->post('/temporary/', $this->call('saveTemporaryPref'))
->bind('save_css_pref');
return $controllers;
}
/**
* Save user production preferenes
*
* @param Application $app
* @param Request $request
* @return JsonResponse
*/
public function saveTemporaryPref(Application $app, Request $request)
{
if(!$request->isXmlHttpRequest()) {
$app->abort(400);
}
$prop = $request->request->get('prop');
$value = $request->request->get('value');
$success = false;
if($prop && $value) {
$app['session']->set('pref.' . $prop, $value);
$success = true;
}
return new JsonResponse(array('success' => $success));
}
/**
* Save css production preferenes
*
* @param Application $app
* @param Request $request
* @return JsonResponse
*/
public function saveUserPref(Application $app, Request $request)
{
if(!$request->isXmlHttpRequest()) {
$app->abort(400);
}
$msg = _('Error while saving preference');
$prop = $request->request->get('prop');
$value = $request->request->get('value');
$success = false;
if($prop && $value) {
$success = ! ! $app['phraseanet.user']->setPrefs($prop, $value);
$msg = _('Preference saved !');
}
return new JsonResponse(array('success' => $success, 'message' => $msg));
}
/**
* Prefix the method to call with the controller class name
*
* @param string $method The method to call
* @return string
*/
private function call($method)
{
return sprintf('%s::%s', __CLASS__, $method);
}
}

View File

@@ -203,7 +203,7 @@ class eventsmanager_broker
$data['next'] = '<a href="#" onclick="print_notifications(' . ((int) $page + 1) . ');return false;">' . _('charger d\'avantages de notifications') . '</a>';
}
return p4string::jsonencode($datas);
return p4string::jsonencode($data);
}
public function get_unread_notifications_number()

View File

@@ -76,25 +76,19 @@
</div>
{% endmacro %}
{% if app['phraseanet.registry'].get('GV_needAuth2DL') and app['phraseanet.user'].is_guest() %}
<script type="text/javascript">
p4.Dialog.get(1).Close();
parent.login({act:"dwnl",lst:"{{ lst }}",SSTTID:"{{ ssttid }}"});
</script>
{% else %}
{% if download.get_total_download() <= 0 and download.get_total_order() <= 0 and download.get_total_ftp() <= 0%}
<div class="buttons_line" style="text-align: left;">
<p>{% trans 'Les documents ne peuvent pas etre exportes' %}</p>
<button type="button" class="close_button">{% trans 'boutton::fermer'%}</button>
</div>
{% endif %}
<div class="tabs">
<ul>
{% if download.get_total_download() > 0 %}
<li><a href="#download">{% trans 'export:: telechargement' %}</a></li>
<li><a href="#sendmail">{% trans 'export:: envoi par mail' %}</a></li>
{% endif %}
{% if download.get_total_order() > 0 %}
<li><a href="#order">{% trans 'export:: commande' %}</a></li>
{% endif %}
{% if download.get_total_ftp() > 0 %}
<li><a href="#ftp">{% trans 'export:: FTP' %}</a></li>
{% endif %}
</ul>
{% if download.get_total_download() > 0 %}
<div id="download">
@@ -233,14 +227,8 @@
{% endtrans %}
</label>
</div>
{% endif %}
<div class="buttons_line">
<button type="button" class="sendmail_button btn btn-inverse">{% trans 'boutton::envoyer'%}</button>
<img class="sendmail_button_loader" src="/skins/icons/loader404040.gif" style="visibility:hidden;margin:0 5px;"/>
<button type="button" class="close_button btn btn-inverse">{% trans 'boutton::annuler'%}</button>
</div>
</form>
<iframe style="display:none;" name="sendmail_target"></iframe>
</div>
</div>
</div>
{% endif %}
@@ -270,6 +258,42 @@
{% endfor %}
</div>
{% endif %}
<div class="buttons_line">
<button type="button" class="sendmail_button btn btn-inverse">{% trans 'boutton::envoyer'%}</button>
<img class="sendmail_button_loader" src="/skins/icons/loader404040.gif" style="visibility:hidden;margin:0 5px;"/>
<button type="button" class="close_button btn btn-inverse">{% trans 'boutton::annuler'%}</button>
</div>
</form>
<iframe style="display:none;" name="sendmail_target"></iframe>
</div>
</div>
{% endif %}
{% if download.get_total_order() > 0 %}
<div id="order">
{% for name, values in download.get_display_orderable() %}
{% if values.available > 0 %}
<div class='well-small'>
{% set docs_orderable = values.available %}
{% trans %}{{docs_orderable}} documents commandes{% endtrans %}
{% set docs_not_orderable = values.total - values.available %}
{% if docs_not_orderable > 0%}
{% trans %}{{docs_not_orderable}} documents ne peuvent pas etre commandes{% endtrans %}
{% endif %}
{% set title%}
{% trans 'Documents indisponibles' %}
{% endset %}
{% if values.refused|length > 0 %}
{% set title%}
{% trans 'Documents indisponibles' %}
{% endset %}
<a href="#" class="undisposable_link" title="{{title|trim}}"> + </a>
<div style="display:none;" class="undisposable">
<div><i>{% trans 'La sous resolution n\'est pas disponible pour les documents suivants' %}</i></div>
{% for datas in values.refused%}
{{ thumbnail.format(datas, 80, 80,'', true, false) }}
{% endfor %}
</div>
{% endif %}
</div>
{% endif %}
{% endfor %}
@@ -352,11 +376,16 @@
</div>
</div>
<div class="control-group">
<label class="control-label" for="usr_zip_code">{% trans 'admin::compte-utilisateur code postal' %} *</label>
<div class="controls">
<input id="usr_zip_code" type="text" name="cpostal" name="cpostal" class="required" value="{{ app['phraseanet.user'].get_zipcode() }}"/>
</div>
{% if app['phraseanet.registry'].get('GV_requireTOUValidationForExport') == true %}
<div class="well-small">
<label for="TOU_acceptOrder" class="checkbox">
<input type="checkbox" name="TOU_accept" id="TOU_acceptOrder" value="1" />
{% set beginning_link = '<a href="/prod/TOU/" class="TOUview">' %}
{% set end_link = '</a>' %}
{% trans %}
By checking this box, you accept {{ beginning_link }} Terms of Use {{ end_link }}
{% endtrans %}
</label>
</div>
<div class="control-group">
@@ -372,11 +401,46 @@
<input type="text" id="usr_fax" name="fax" value="{{ app['phraseanet.user'].get_fax() }}"/>
</div>
</div>
<div>
<p>{% trans 'export::mail: fichiers joint' %}</p>
{% for name, values in download.get_display_ftp() %}
{% if values.available > 0 %}
<div class="well-small">
<label for="ftp_{{name}}" class="checkbox">
<input class="{{values.class}}" type="checkbox" id="ftp_{{name}}" name="obj[]" value="{{name}}" />
{{values.label}} {% if values.total != values.available %}{{values.available}}/{{values.total}}{% endif %} ({{values.size | formatOctets}}))
{% if values.refused|length > 0 %}
{% set title%}
{% trans 'Documents indisponibles' %}
{% endset %}
<a href="#" class="undisposable_link" title="{{title|trim}}"> + </a>
{% endif %}
</label>
{% if values.refused|length > 0 %}
<div style="display:none;" class="well-small undisposable">
<div><i>{% trans 'La sous resolution n\'est pas disponible pour les documents suivants' %}</i></div>
{% for datas in values.refused%}
{{ thumbnail.format(datas, 80, 80,'', true, false) }}
{% endfor %}
</div>
{% endif %}
</div>
{% endif %}
{% endfor %}
</div>
{% if download.has_business_fields_access() %}
<div class="businessfields well-small" style="margin-left:20px;display:none;">
<label for="business_ftp" class="checkbox">
<input type="checkbox" name="businessfields" id="business_ftp" value="1" />
{% trans 'Include Business-fields in caption' %}
</label>
</div>
{% endif %}
{% if app['phraseanet.registry'].get('GV_requireTOUValidationForExport') == true %}
<div class="well-small">
<label for="TOU_acceptOrder" class="checkbox">
<input type="checkbox" name="TOU_accept" id="TOU_acceptOrder" value="1" />
<label for="TOU_acceptFTP" class="checkbox">
<input type="checkbox" name="TOU_accept" id="TOU_acceptFTP" value="1" />
{% set beginning_link = '<a href="/prod/TOU/" class="TOUview">' %}
{% set end_link = '</a>' %}
{% trans %}
@@ -424,7 +488,7 @@
<p>{% trans 'export::mail: fichiers joint' %}</p>
{% for name, values in download.get_display_ftp() %}
{% if values.available > 0 %}
<div class="well-small">
<div style="margin: 10px 0 20px 0; padding: 0 10px;">
<label for="ftp_{{name}}" class="checkbox">
<input class="{{values.class}}" type="checkbox" id="ftp_{{name}}" name="obj[]" value="{{name}}" />
{{values.label}} {% if values.total != values.available %}{{values.available}}/{{values.total}}{% endif %} ({{values.size | formatOctets}}))
@@ -436,7 +500,7 @@
{% endif %}
</label>
{% if values.refused|length > 0 %}
<div style="display:none;" class="well-small undisposable">
<div style="display:none;" class="undisposable">
<div><i>{% trans 'La sous resolution n\'est pas disponible pour les documents suivants' %}</i></div>
{% for datas in values.refused%}
{{ thumbnail.format(datas, 80, 80,'', true, false) }}
@@ -448,7 +512,7 @@
{% endfor %}
</div>
{% if download.has_business_fields_access() %}
<div class="businessfields well-small" style="margin-left:20px;display:none;">
<div class="businessfields" style="margin-left:20px;display:none;">
<label for="business_ftp" class="checkbox">
<input type="checkbox" name="businessfields" id="business_ftp" value="1" />
{% trans 'Include Business-fields in caption' %}
@@ -457,7 +521,7 @@
{% endif %}
{% if app['phraseanet.registry'].get('GV_requireTOUValidationForExport') == true %}
<div class="well-small">
<div style="margin:0 20px;">
<label for="TOU_acceptFTP" class="checkbox">
<input type="checkbox" name="TOU_accept" id="TOU_acceptFTP" value="1" />
{% set beginning_link = '<a href="/prod/TOU/" class="TOUview">' %}
@@ -749,4 +813,4 @@
});
});
</script>
</div>
{% endif %}

View File

@@ -1,3 +1,5 @@
{% import 'common/thumbnail.html.twig' as thumbnail %}
{% set nbReceivedDocuments = records.received().count() %}
{% set nbEditableDocuments = records.count() %}
@@ -8,8 +10,8 @@
</ul>
<div id='property-statut'>
<p class="header" style='text-align:center;'>
<h4>
<p class="header">
<h4 style='text-align:center;'>
{% trans %}
You have selected one document.
{% plural nbReceivedDocuments %}
@@ -42,8 +44,8 @@
</tr>
</thead>
<tbody>
<tr>
<td colspan="6" style='font-size:11px;'>
<tr style='border-bottom:1px solid #FFF;'>
<td colspan="6" style='font-size:11px;text-align:center'>
{% if nbRecords == 0 and nbStories > 0 %}
<i>({% trans %}Status edition of stories{% endtrans %})</i>
{% elseif nbRecords > 0 and nbStories == 0 %}
@@ -61,7 +63,7 @@
{% set inverse = 1 %}
{% endif %}
<tr>
<td colspan="6">
<td colspan="6" style='text-align:center;'>
<h6>{{ values['name']|title }}</h6>
</td>
</tr>
@@ -74,7 +76,7 @@
{% endif %}
</td>
<td style='text-align:right'>
<label for="status-radio-{{ sbasId ~ "-" ~ bit ~ '-off'}}">
<label for="status-radio-{{ sbasId ~ "-" ~ bit ~ '-off'}}" {% if inverse == 2 %}style='color:#FF3333'{% endif%}>
{{ values['labeloff']|default('off') }}
</label>
</td>
@@ -85,7 +87,7 @@
<input id="status-radio-{{ sbasId ~ "-" ~ bit ~ '-on'}}" type="radio" name="status[{{ sbasId }}][{{ bit }}]" value="1" {% if inverse == 0 %}checked="checked"{% endif %}/>
</td>
<td style='text-align:left'>
<label for="status-radio-{{ sbasId ~ "-" ~ bit ~ '-on'}}">
<label for="status-radio-{{ sbasId ~ "-" ~ bit ~ '-on'}}" {% if inverse == 2 %}style='color:#FF3333'{% endif%}>
{{ values['labelon']|default('on') }}
</label>
</td>
@@ -114,19 +116,73 @@
</div>
</form>
</div>
<div id='property-type'>TODO</div>
<div id='property-type'>
{% set typesEnum = [
constant('\\Alchemy\\Phrasea\\Media\\Type\\Type::TYPE_AUDIO'),
constant('\\Alchemy\\Phrasea\\Media\\Type\\Type::TYPE_VIDEO'),
constant('\\Alchemy\\Phrasea\\Media\\Type\\Type::TYPE_DOCUMENT'),
constant('\\Alchemy\\Phrasea\\Media\\Type\\Type::TYPE_FLASH'),
constant('\\Alchemy\\Phrasea\\Media\\Type\\Type::TYPE_IMAGE')
]
%}
<form name="change-records-type" action="/prod/records/property/type/" method="POST">
<div class='well-small 'style="text-align:center;">
<select name='force_types' style="width:250px">
<option value="">{% trans 'Apply to all selected documents' %}</option>
{% for option in typesEnum %}
<option value="{{ option }}">{{ option }}</option>
{% endfor %}
</select>
</div>
<input name="lst" type="hidden" value="{{ records.serializedList() }}"/>
{% for sbasId,databoxTypes in recordsType %}
<h2 style="text-align:center;" clas="header">{{ sbasId|sbas_names(app) }}</h2>
{% for currentType, recordsByType in databoxTypes %}
<ul class="thumbnails" style="margin:20px auto;">
{% for record in recordsByType %}
<li class="span2">
<div class="thumbnail" style='min-height:205px'>
{{ thumbnail.format(record.get_thumbnail(), 160, 120, '', false, false) }}
<div class="caption">
<h5>{{ record.get_title() }}</h5>
<p>
<select name="types[{{record.get_serialize_key()}}]" style='width:100%'>
{% for option in typesEnum %}
<option value="{{ option }}" {{ record.is_grouping() ? "disabled='disabled'": "" }} {{ option == record.get_type() ? "selected='selected'" : '' }}>{{ option }}</option>
{% endfor %}
</select>
</p>
</div>
</div>
</li>
{% endfor %}
</ul>
{% endfor %}
{% endfor %}
<div class="form-actions">
<button type="button" class="btn btn-primary submiter">{% trans "Apply changes" %}</button>
<button type="button" class="btn">{% trans "Cancel" %}</button>
</div>
</form>
</div>
</div>
<script type="text/javascript">
$(document).ready(function(){
$("#tabs-records-property").tabs();
var $dialog = p4.Dialog.get(1);
var $dialogBox = $dialog.getDomElement();
var form = $("form[name=change-records-status]", $dialogBox);
var button = $(".submiter", form);
var button = $(".submiter", $dialogBox);
button.bind("click", function(){
var form = $(this).closest("form");
$.ajax({
type: form.attr("method"),
url: form.attr("action"),