From f3cc575674d36a4b199ad691005adf09fb830ffa Mon Sep 17 00:00:00 2001 From: Nicolas Le Goff Date: Tue, 7 Aug 2012 19:45:52 +0200 Subject: [PATCH] add bas/collection controller --- config/nginx.rewrite.rules | 1 + lib/Alchemy/Phrasea/Application/Admin.php | 2 + lib/Alchemy/Phrasea/Controller/Admin/Bas.php | 895 ++++++++++++++++++ .../Phrasea/Controller/Admin/Database.php | 198 +++- lib/Alchemy/Phrasea/Controller/Admin/Root.php | 45 +- .../Mustache/Prod/Alert-Success.Mustache.html | 4 + .../web/admin/collection/collection.html.twig | 266 ++++++ templates/web/admin/tree.html.twig | 7 +- www/admin/adminFeedback.php | 221 +++-- www/admin/getinfousr.php | 62 -- www/include/minify/groupsConfig.php | 1 + 11 files changed, 1519 insertions(+), 183 deletions(-) create mode 100644 lib/Alchemy/Phrasea/Controller/Admin/Bas.php create mode 100644 templates/web/Mustache/Prod/Alert-Success.Mustache.html create mode 100644 templates/web/admin/collection/collection.html.twig delete mode 100644 www/admin/getinfousr.php diff --git a/config/nginx.rewrite.rules b/config/nginx.rewrite.rules index 2ba7f5c437..4f0d973d9a 100644 --- a/config/nginx.rewrite.rules +++ b/config/nginx.rewrite.rules @@ -6,6 +6,7 @@ rewrite ^/(mail-export)/([a-zA-Z0-9]*)\/get$ /include/download_anonymous.php?ty rewrite ^/admin/$ /admin/router.php last; rewrite ^/admin/structure/.*$ /admin/router.php last; +rewrite ^/admin/bas/.*$ /admin/router.php last; rewrite ^/admin/statusbit/.*$ /admin/router.php last; rewrite ^/admin/dashboard/.*$ /admin/router.php last; rewrite ^/admin/database/.*$ /admin/router.php last; diff --git a/lib/Alchemy/Phrasea/Application/Admin.php b/lib/Alchemy/Phrasea/Application/Admin.php index 39049d9814..5fa0660971 100644 --- a/lib/Alchemy/Phrasea/Application/Admin.php +++ b/lib/Alchemy/Phrasea/Application/Admin.php @@ -20,6 +20,7 @@ use Alchemy\Phrasea\Controller\Admin\Root; use Alchemy\Phrasea\Controller\Admin\Subdefs; use Alchemy\Phrasea\Controller\Admin\Users; use Alchemy\Phrasea\Controller\Admin\Dashboard; +use Alchemy\Phrasea\Controller\Admin\Bas; use Alchemy\Phrasea\Controller\Admin\Databases; use Alchemy\Phrasea\Controller\Admin\Database; use Alchemy\Phrasea\Controller\Admin\Setup; @@ -32,6 +33,7 @@ return call_user_func( $app->mount('/', new Root()); $app->mount('/dashboard', new Dashboard()); + $app->mount('/bas', new Bas()); $app->mount('/database', new Database()); $app->mount('/databases', new Databases()); $app->mount('/setup', new Setup()); diff --git a/lib/Alchemy/Phrasea/Controller/Admin/Bas.php b/lib/Alchemy/Phrasea/Controller/Admin/Bas.php new file mode 100644 index 0000000000..e93947a0d7 --- /dev/null +++ b/lib/Alchemy/Phrasea/Controller/Admin/Bas.php @@ -0,0 +1,895 @@ +before(function() use ($app) { + if (null !== $response = $app['phraseanet.core']['Firewall']->requireAdmin($app)) { + return $response; + } + if ( ! $app['phraseanet.core']->getAUthenticatedUser()->ACL()->has_access_to_base($app['request']->get('bas_id'), 'canadmin')) { + $app->abort(403); + } + }); + + + /** + * Get a collection + * + * name : admin_database_collection + * + * description : Get collection + * + * method : GET + * + * parameters : none + * + * return : HTML Response + */ + $controllers->get('/{bas_id}/', $this->call('getCollection')) + ->assert('bas_id', '\d+') + ->bind('admin_database_collection'); + + /** + * Delete collection + * + * name : admin_collection_delete + * + * description : Delete collection + * + * method : DELETE + * + * parameters : none + * + * return : HTML Response + */ + $controllers->delete('/{bas_id}/', $this->call('delete'))->bind('admin_collection_delete')->before(function() use ($app) { + if ( ! $app['phraseanet.core']->getAUthenticatedUser()->ACL()->has_right_on_base($app['request']->get('bas_id'), 'canadmin')) { + $app->abort(403); + } + }); + + /** + * Enable collection + * + * name : admin_collection_enable + * + * description : Enable collection + * + * method : POST + * + * parameters : none + * + * return : HTML Response + */ + $controllers->post('/{bas_id}/enable/', $this->call('enable'))->bind('admin_collection_enable')->before(function() use ($app) { + if ( ! $app['phraseanet.core']->getAUthenticatedUser()->ACL()->has_right_on_base($app['request']->get('bas_id'), 'canadmin')) { + $app->abort(403); + } + }); + + /** + * Disabled collection + * + * name : admin_collection_disabled + * + * description : Disabled collection + * + * method : POST + * + * parameters : none + * + * return : HTML Response + */ + $controllers->post('/{bas_id}/disabled/', $this->call('disabled'))->bind('admin_collection_disabled')->before(function() use ($app) { + if ( ! $app['phraseanet.core']->getAUthenticatedUser()->ACL()->has_right_on_base($app['request']->get('bas_id'), 'canadmin')) { + $app->abort(403); + } + }); + + /** + * Set new order admin + * + * name : admin_collection_order_admins + * + * description : Set new order admin + * + * method : POST + * + * parameters : none + * + * return : HTML Response + */ + $controllers->post('/{bas_id}/order/admins/', $this->call('setOrderAdmins'))->bind('admin_collection_order_admins')->before(function() use ($app) { + if ( ! $app['phraseanet.core']->getAUthenticatedUser()->ACL()->has_right_on_base($app['request']->get('bas_id'), 'canadmin')) { + $app->abort(403); + } + }); + + /** + * Set publication watermark + * + * name : admin_collection_submit_publication + * + * description : Set publication watermark + * + * method : POST + * + * parameters : none + * + * return : HTML Response + */ + $controllers->post('/{bas_id}/publication/display/', $this->call('setPublicationDisplay'))->bind('admin_collection_submit_publication')->before(function() use ($app) { + if ( ! $app['phraseanet.core']->getAUthenticatedUser()->ACL()->has_right_on_base($app['request']->get('bas_id'), 'canadmin')) { + $app->abort(403); + } + }); + + /** + * Rename a collection + * + * name : admin_collection_rename + * + * description : Rename a collection + * + * method : POST + * + * parameters : none + * + * return : HTML Response + */ + $controllers->post('/{bas_id}/rename/', $this->call('rename'))->bind('admin_collection_rename')->before(function() use ($app) { + if ( ! $app['phraseanet.core']->getAUthenticatedUser()->ACL()->has_right_on_base($app['request']->get('bas_id'), 'canadmin')) { + $app->abort(403); + } + }); + + /** + * Rename a collection + * + * name : admin_collection_empty + * + * description : Rename a collection + * + * method : POST + * + * parameters : none + * + * return : HTML Response + */ + $controllers->post('/{bas_id}/empty/', $this->call('emptyCollection'))->bind('admin_collection_empty')->before(function() use ($app) { + if ( ! $app['phraseanet.core']->getAUthenticatedUser()->ACL()->has_right_on_base($app['request']->get('bas_id'), 'canadmin')) { + $app->abort(403); + } + }); + + /** + * Unmount a collection + * + * name : admin_collection_unmount + * + * description : Unmount a collection + * + * method : POST + * + * parameters : none + * + * return : HTML Response + */ + $controllers->post('/{bas_id}/unmount/', $this->call('unmount'))->bind('admin_collection_unmount')->before(function() use ($app) { + if ( ! $app['phraseanet.core']->getAUthenticatedUser()->ACL()->has_right_on_base($app['request']->get('bas_id'), 'canadmin')) { + $app->abort(403); + } + }); + + /** + * Set a new logo + * + * name : admin_collection_submit_logo + * + * description : Set a new logo + * + * method : POST + * + * parameters : none + * + * return : HTML Response + */ + $controllers->post('/{bas_id}/picture/mini-logo/', $this->call('setLogo'))->bind('admin_collection_submit_logo')->before(function() use ($app) { + if ( ! $app['phraseanet.core']->getAUthenticatedUser()->ACL()->has_right_on_base($app['request']->get('bas_id'), 'canadmin')) { + $app->abort(403); + } + }); + + /** + * Delete a mini logo + * + * name : admin_collection_delete_logo + * + * description : Delete a mini logo + * + * method : POST + * + * parameters : none + * + * return : HTML Response + */ + $controllers->delete('/{bas_id}/picture/mini-logo/', $this->call('deleteLogo'))->bind('admin_collection_delete_logo')->before(function() use ($app) { + if ( ! $app['phraseanet.core']->getAUthenticatedUser()->ACL()->has_right_on_base($app['request']->get('bas_id'), 'canadmin')) { + $app->abort(403); + } + }); + + /** + * Set a new logo + * + * name : admin_collection_submit_logo + * + * description : Set a new logo + * + * method : POST + * + * parameters : none + * + * return : HTML Response + */ + $controllers->post('/{bas_id}/picture/watermark/', $this->call('setWatermark'))->bind('admin_collection_submit_logo')->before(function() use ($app) { + if ( ! $app['phraseanet.core']->getAUthenticatedUser()->ACL()->has_right_on_base($app['request']->get('bas_id'), 'canadmin')) { + $app->abort(403); + } + }); + + /** + * Delete a mini logo + * + * name : admin_collection_delete_logo + * + * description : Delete a mini logo + * + * method : POST + * + * parameters : none + * + * return : HTML Response + */ + $controllers->delete('/{bas_id}/picture/watermark/', $this->call('deleteWatermark'))->bind('admin_collection_delete_logo')->before(function() use ($app) { + if ( ! $app['phraseanet.core']->getAUthenticatedUser()->ACL()->has_right_on_base($app['request']->get('bas_id'), 'canadmin')) { + $app->abort(403); + } + }); + + /** + * Set a new stamp logo + * + * name : + * + * description : Set a new stamp + * + * method : POST + * + * parameters : none + * + * return : HTML Response + */ + $controllers->post('/{bas_id}/picture/stamp-logo/', $this->call('setStamp'))->bind('admin_collection_submit_stamp')->before(function() use ($app) { + if ( ! $app['phraseanet.core']->getAUthenticatedUser()->ACL()->has_right_on_base($app['request']->get('bas_id'), 'canadmin')) { + $app->abort(403); + } + }); + + /** + * Delete a stamp logo + * + * name : admin_collection_delete_stamp + * + * description : Delete a stamp + * + * method : POST + * + * parameters : none + * + * return : HTML Response + */ + $controllers->delete('/{bas_id}/picture/stamp-logo/', $this->call('deleteStamp'))->bind('admin_collection_delete_stamp')->before(function() use ($app) { + if ( ! $app['phraseanet.core']->getAUthenticatedUser()->ACL()->has_right_on_base($app['request']->get('bas_id'), 'canadmin')) { + $app->abort(403); + } + }); + + /** + * Set a new banner + * + * name : admin_collection_submit_banner + * + * description : Set a new logo + * + * method : POST + * + * parameters : none + * + * return : HTML Response + */ + $controllers->post('/{bas_id}/picture/banner/', $this->call('setBanner'))->bind('admin_collection_submit_banner')->before(function() use ($app) { + if ( ! $app['phraseanet.core']->getAUthenticatedUser()->ACL()->has_right_on_base($app['request']->get('bas_id'), 'canadmin')) { + $app->abort(403); + } + }); + + /** + * Delete a banner + * + * name : admin_collection_delete_banner + * + * description : Delete a mini logo + * + * method : POST + * + * parameters : none + * + * return : HTML Response + */ + $controllers->delete('/{bas_id}/picture/banner/', $this->call('deleteBanner'))->bind('admin_collection_delete_banner')->before(function() use ($app) { + if ( ! $app['phraseanet.core']->getAUthenticatedUser()->ACL()->has_right_on_base($app['request']->get('bas_id'), 'canadmin')) { + $app->abort(403); + } + }); + + return $controllers; + } + + /** + * + * @param \Silex\Application $app + * @param \Symfony\Component\HttpFoundation\Request $request + * @param integer $databox_id + * @param integer $bas_id + */ + public function getCollection(Application $app, Request $request, $bas_id) + { + $collection = \collection::get_from_base_id($bas_id); + + $admins = array(); + if ($app['phraseanet.core']->getAuthenticatedUser()->ACL()->has_right_on_base($bas_id, 'manage')) { + $query = new \User_Query($app['phraseanet.appbox']); + $admins = $query->on_base_ids(array($bas_id)) + ->who_have_right(array('order_master')) + ->execute() + ->get_results(); + } + return new Response($app['twig']->render('admin/collection/collection.html.twig', array( + 'collection' => $collection, + 'admins' => $admins, + ))); + } + + /** + * + * @param \Silex\Application $app + * @param \Symfony\Component\HttpFoundation\Request $request + * @param integer $bas_id + */ + public function setOrderAdmins(Application $app, Request $request, $bas_id) + { + if (count($admins = $request->get('admins', array())) > 0) { + $new_admins = array(); + + foreach ($admins as $admin) { + $new_admins[] = $admin; + } + + if (count($new_admins) > 0) { + \set_exportorder::set_order_admins(array_filter($admins), $bas_id); + } + } + + return $app->redirect('/admin/bas/'. $bas_id . '/'); + } + + /** + * + * @param \Silex\Application $app + * @param \Symfony\Component\HttpFoundation\Request $request + * @param integer $bas_id + */ + public function emptyCollection(Application $app, Request $request, $bas_id) + { + if ( ! $request->isXmlHttpRequest() || ! array_key_exists($request->getMimeType('json'), array_flip($request->getAcceptableContentTypes()))) { + $app->abort(400, _('Bad request format, only JSON is allowed')); + } + + $message = _('Collection empty successful'); + $success = false; + + try { + $collection = \collection::get_from_base_id($bas_id); + + if ($collection->get_record_amount() <= 500) { + $collection->empty_collection(500); + } else { + $settings = "\n\n" . $collection->get_bas_id() . ""; + \task_abstract::create($app['phraseanet.appbox'], 'task_period_emptyColl', $settings); + $message = _('A task has been creted, please run it to complete empty collection'); + } + + $success = true; + } catch (\Exception $e) { + $message = _('An error occurred'); + } + + return $app->json(array('success' => $success, 'message' => $message)); + } + + /** + * + * @param \Silex\Application $app + * @param \Symfony\Component\HttpFoundation\Request $request + * @param integer $bas_id + */ + public function deleteBanner(Application $app, Request $request, $bas_id) + { + if ( ! $request->isXmlHttpRequest() || ! array_key_exists($request->getMimeType('json'), array_flip($request->getAcceptableContentTypes()))) { + $app->abort(400, _('Bad request format, only JSON is allowed')); + } + + $success = false; + $msg = _('An error occured'); + + try { + $collection = \collection::get_from_base_id($bas_id); + $app['phraseanet.appbox']->write_collection_pic($collection, null, \collection::PIC_PRESENTATION); + } catch (\Exception $e) { + + } + + return $app->json(array('success' => $success, 'msg' => $msg)); + } + + /** + * + * @param \Silex\Application $app + * @param \Symfony\Component\HttpFoundation\Request $request + * @param integer $bas_id + */ + public function deleteStamp(Application $app, Request $request, $bas_id) + { + if ( ! $request->isXmlHttpRequest() || ! array_key_exists($request->getMimeType('json'), array_flip($request->getAcceptableContentTypes()))) { + $app->abort(400, _('Bad request format, only JSON is allowed')); + } + + $success = false; + $msg = _('An error occured'); + + try { + $collection = \collection::get_from_base_id($bas_id); + $app['phraseanet.appbox']->write_collection_pic($collection, null, \collection::PIC_STAMP); + } catch (\Exception $e) { + + } + + return $app->json(array('success' => $success, 'msg' => $msg)); + } + + /** + * + * @param \Silex\Application $app + * @param \Symfony\Component\HttpFoundation\Request $request + * @param integer $bas_id + */ + public function deleteWatermark(Application $app, Request $request, $bas_id) + { + if ( ! $request->isXmlHttpRequest() || ! array_key_exists($request->getMimeType('json'), array_flip($request->getAcceptableContentTypes()))) { + $app->abort(400, _('Bad request format, only JSON is allowed')); + } + + $success = false; + $msg = _('An error occured'); + + try { + $collection = \collection::get_from_base_id($bas_id); + $app['phraseanet.appbox']->write_collection_pic($collection, null, \collection::PIC_WM); + } catch (\Exception $e) { + + } + + return $app->json(array('success' => $success, 'msg' => $msg)); + } + + /** + * + * @param \Silex\Application $app + * @param \Symfony\Component\HttpFoundation\Request $request + * @param integer $bas_id + */ + public function deleteLogo(Application $app, Request $request, $bas_id) + { + if ( ! $request->isXmlHttpRequest() || ! array_key_exists($request->getMimeType('json'), array_flip($request->getAcceptableContentTypes()))) { + $app->abort(400, _('Bad request format, only JSON is allowed')); + } + + $success = false; + $msg = _('An error occured'); + + try { + $collection = \collection::get_from_base_id($bas_id); + $collection->update_logo(null); + $app['phraseanet.appbox']->write_collection_pic($collection, null, \collection::PIC_WM); + } catch (\Exception $e) { + + } + + return $app->json(array('success' => $success, 'msg' => $msg)); + } + + /** + * + * @param \Silex\Application $app + * @param \Symfony\Component\HttpFoundation\Request $request + * @param integer $bas_id + */ + public function setBanner(Application $app, Request $request, $bas_id) + { + if (null === $file = $request->files->get('newBanner')) { + $app->abort(400); + } + + /* @var $file \Symfony\Component\HttpFoundation\File\UploadedFile */ + if ($file->getClientSize() > 1024 * 1024) { + + return $app->redirect('/admin/bas/' . $bas_id . '/?upload-error=too-big'); + } + + if ($file->isValid()) { + + return $app->redirect('/admin/bas/' . $bas_id . '/?upload-error=unknow-error'); + } + + try { + $collection = \collection::get_from_base_id($bas_id); + + $app['phraseanet.appbox']->write_collection_pic($collection, $file, \collection::PIC_PRESENTATION); + + $app['filesystem']->remove($file->getPathname()); + } catch (\Exception $e) { + + return $app->redirect('/admin/bas/' . $bas_id . '/?upload-error=unknow-error'); + } + + return $app->redirect('/admin/bas/' . $bas_id . '/'); + } + + /** + * + * @param \Silex\Application $app + * @param \Symfony\Component\HttpFoundation\Request $request + * @param integer $bas_id + */ + public function setStamp(Application $app, Request $request, $bas_id) + { + if (null === $file = $request->files->get('newStamp')) { + $app->abort(400); + } + + /* @var $file \Symfony\Component\HttpFoundation\File\UploadedFile */ + if ($file->getClientSize() > 1024 * 1024) { + + return $app->redirect('/admin/bas/' . $bas_id . '/?upload-error=too-big'); + } + + if ($file->isValid()) { + + return $app->redirect('/admin/bas/' . $bas_id . '/?upload-error=unknow-error'); + } + + try { + $collection = \collection::get_from_base_id($bas_id); + + $app['phraseanet.appbox']->write_collection_pic($collection, $file, \collection::PIC_STAMP); + + $app['filesystem']->remove($file->getPathname()); + } catch (\Exception $e) { + + return $app->redirect('/admin/bas/' . $bas_id . '/?upload-error=unknow-error'); + } + + return $app->redirect('/admin/bas/' . $bas_id . '/'); + } + + /** + * + * @param \Silex\Application $app + * @param \Symfony\Component\HttpFoundation\Request $request + * @param integer $bas_id + */ + public function setWatermark(Application $app, Request $request, $bas_id) + { + if (null === $file = $request->files->get('newWm')) { + $app->abort(400); + } + + /* @var $file \Symfony\Component\HttpFoundation\File\UploadedFile */ + if ($file->getClientSize() > 65535) { + + return $app->redirect('/admin/bas/' . $bas_id . '/?upload-error=too-big'); + } + + if ($file->isValid()) { + + return $app->redirect('/admin/bas/' . $bas_id . '/?upload-error=unknow-error'); + } + + try { + $collection = \collection::get_from_base_id($bas_id); + + $app['phraseanet.appbox']->write_collection_pic($collection, $file, \collection::PIC_WM); + + $app['filesystem']->remove($file->getPathname()); + } catch (\Exception $e) { + + return $app->redirect('/admin/bas/' . $bas_id . '/?upload-error=unknow-error'); + } + + return $app->redirect('/admin/bas/' . $bas_id . '/'); + } + + /** + * + * @param \Silex\Application $app + * @param \Symfony\Component\HttpFoundation\Request $request + * @param integer $bas_id + */ + public function setMiniLogo(Application $app, Request $request, $bas_id) + { + if (null === $file = $request->files->get('newLogo')) { + $app->abort(400); + } + + /* @var $file \Symfony\Component\HttpFoundation\File\UploadedFile */ + if ($file->getClientSize() > 65535) { + + return $app->redirect('/admin/bas/' . $bas_id . '/?upload-error=too-big'); + } + + if ($file->isValid()) { + + return $app->redirect('/admin/bas/' . $bas_id . '/?upload-error=unknow-error'); + } + + try { + $collection = \collection::get_from_base_id($bas_id); + + $app['phraseanet.appbox']->write_collection_pic($collection, $file, \collection::PIC_LOGO); + + $app['filesystem']->remove($file->getPathname()); + } catch (\Exception $e) { + + return $app->redirect('/admin/bas/' . $bas_id . '/?upload-error=unknow-error'); + } + + return $app->redirect('/admin/bas/' . $bas_id . '/'); + } + + /** + * + * @param \Silex\Application $app + * @param \Symfony\Component\HttpFoundation\Request $request + * @param integer $bas_id + */ + public function delete(Application $app, Request $request, $bas_id) + { + if ( ! $request->isXmlHttpRequest() || ! array_key_exists($request->getMimeType('json'), array_flip($request->getAcceptableContentTypes()))) { + $app->abort(400, _('Bad request format, only JSON is allowed')); + } + + $success = false; + $msg = _('An error occured'); + + try { + $collection = \collection::get_from_base_id($bas_id); + + if ($collection->get_record_amount() > 0) { + $msg = _('admin::base:collection: vider la collection avant de la supprimer'); + } else { + $collection->unmount_collection($appbox); + $collection->delete(); + $success = true; + $msg = _('forms::operation effectuee OK'); + } + } catch (\Exception $e) { + + } + + return $app->json(array('success' => $success, 'msg' => $msg)); + } + + /** + * + * @param \Silex\Application $app + * @param \Symfony\Component\HttpFoundation\Request $request + * @param integer $bas_id + */ + public function unmount(Application $app, Request $request, $bas_id) + { + if ( ! $request->isXmlHttpRequest() || ! array_key_exists($request->getMimeType('json'), array_flip($request->getAcceptableContentTypes()))) { + $app->abort(400, _('Bad request format, only JSON is allowed')); + } + + if (null === $name = $request->get('name')) { + $app->abort(400, _('Missing name format')); + } + + $success = false; + $msg = _('An error occured'); + + try { + $collection = \collection::get_from_base_id($bas_id); + $collection->unmount_collection($app['phraseanet.appbox']); + $success = true; + $msg = _('forms::operation effectuee OK'); + } catch (\Exception $e) { + + } + + return $app->json(array('success' => $success, 'msg' => $msg)); + } + + /** + * + * @param \Silex\Application $app + * @param \Symfony\Component\HttpFoundation\Request $request + * @param integer $bas_id + */ + public function rename(Application $app, Request $request, $bas_id) + { + if ( ! $request->isXmlHttpRequest() || ! array_key_exists($request->getMimeType('json'), array_flip($request->getAcceptableContentTypes()))) { + $app->abort(400, _('Bad request format, only JSON is allowed')); + } + + if (null === $name = $request->get('name')) { + $app->abort(400, _('Missing name format')); + } + + $success = false; + $msg = _('An error occured'); + + try { + $collection = \collection::get_from_base_id($bas_id); + $collection->set_name($name); + $success = true; + $msg = _('forms::operation effectuee OK'); + } catch (\Exception $e) { + + } + + return $app->json(array('success' => $success, 'msg' => $msg)); + } + + /** + * + * @param \Silex\Application $app + * @param \Symfony\Component\HttpFoundation\Request $request + * @param integer $bas_id + */ + public function setPublicationDisplay(Application $app, Request $request, $bas_id) + { + if ( ! $request->isXmlHttpRequest() || ! array_key_exists($request->getMimeType('json'), array_flip($request->getAcceptableContentTypes()))) { + $app->abort(400, _('Bad request format, only JSON is allowed')); + } + + if ( ! $app['phraseanet.core']->getAuthenticatedUser()->ACL()->has_right_on_base($bas_id, 'canadmin')) { + $app->abort(403); + } + + if (null === $watermark = $request->get('pub_wm')) { + $app->abort(400, _('Missing pub_wm format')); + } + + $success = false; + $msg = _('An error occured'); + + try { + $collection = \collection::get_from_base_id($bas_id); + $collection->set_public_presentation($watermark); + $success = true; + $msg = _('forms::operation effectuee OK'); + } catch (\Exception $e) { + + } + + return $app->json(array('success' => $success, 'msg' => $msg)); + } + + /** + * + * @param \Silex\Application $application + * @param \Symfony\Component\HttpFoundation\Request $request + * @param integer $bas_id + */ + public function enabled(Application $app, Request $request, $bas_id) + { + if ( ! $request->isXmlHttpRequest() || ! array_key_exists($request->getMimeType('json'), array_flip($request->getAcceptableContentTypes()))) { + $app->abort(400, _('Bad request format, only JSON is allowed')); + } + + $success = false; + $msg = _('An error occured'); + + try { + $collection = \collection::get_from_base_id($bas_id); + $collection->enable($app['phraseanet.appbox']); + $success = true; + $msg = _('forms::operation effectuee OK'); + } catch (\Exception $e) { + + } + + return $app->json(array('success' => $success, 'msg' => $msg)); + } + + /** + * + * @param \Silex\Application $application + * @param \Symfony\Component\HttpFoundation\Request $request + * @param integer $bas_id + */ + public function disabled(Application $app, Request $request, $bas_id) + { + if ( ! $request->isXmlHttpRequest() || ! array_key_exists($request->getMimeType('json'), array_flip($request->getAcceptableContentTypes()))) { + $app->abort(400, _('Bad request format, only JSON is allowed')); + } + + $success = false; + $msg = _('An error occured'); + + try { + $collection = \collection::get_from_base_id($bas_id); + $collection->disable($app['phraseanet.appbox']); + $success = true; + $msg = _('forms::operation effectuee OK'); + } catch (\Exception $e) { + + } + + return $app->json(array('success' => $success, 'msg' => $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); + } +} diff --git a/lib/Alchemy/Phrasea/Controller/Admin/Database.php b/lib/Alchemy/Phrasea/Controller/Admin/Database.php index 2f4d603637..204a1b48aa 100644 --- a/lib/Alchemy/Phrasea/Controller/Admin/Database.php +++ b/lib/Alchemy/Phrasea/Controller/Admin/Database.php @@ -53,7 +53,8 @@ class Database implements ControllerProviderInterface * * return : HTML Response */ - $controllers->get('/{databox_id}', $this->call('getDatabase'))->bind('admin_databases'); + $controllers->get('/{databox_id}', $this->call('getDatabase')) + ->bind('admin_databases'); /** * Delete a database @@ -68,7 +69,8 @@ class Database implements ControllerProviderInterface * * return : HTML Response */ - $controllers->delete('/{databox_id}', $this->call('deleteBase'))->bind('admin_delete_databases'); + $controllers->delete('/{databox_id}', $this->call('deleteBase')) + ->bind('admin_delete_databases'); /** * Reset cache @@ -83,7 +85,8 @@ class Database implements ControllerProviderInterface * * return : Redirect Response */ - $controllers->post('/', $this->call('createDatabase'))->bind('admin_database_new'); + $controllers->post('/', $this->call('createDatabase')) + ->bind('admin_database_new'); /** * mount a database @@ -98,7 +101,42 @@ class Database implements ControllerProviderInterface * * return : Redirect Response */ - $controllers->post('/mount/', $this->call('databaseMount'))->bind('admin_database_mount'); + $controllers->post('/mount/', $this->call('databaseMount')) + ->bind('admin_database_mount'); + + /** + * Unmount a database + * + * name : admin_database_unmount + * + * description : unmount one database + * + * method : POST + * + * parameters : none + * + * return : Redirect Response + */ + $controllers->post('/{databox_id}/unmount/', $this->call('databaseUnmount')) + ->assert('databox_id', '\d+') + ->bind('admin_database_unmount'); + + /** + * Empty a database + * + * name : admin_database_empty + * + * description : empty one database + * + * method : POST + * + * parameters : none + * + * return : Redirect Response + */ + $controllers->post('/{databox_id}/empty/', $this->call('emptyDatabase')) + ->assert('databox_id', '\d+') + ->bind('admin_database_empty'); /** * Get database CGU @@ -134,6 +172,23 @@ class Database implements ControllerProviderInterface ->assert('databox_id', '\d+') ->bind('admin_update_database_cgu'); + /** + * Update document information + * + * name : admin_document_information + * + * description : Update document information + * + * method : GET + * + * parameters : none + * + * return : HTML Response + */ + $controllers->get('/{databox_id}/documents/informations/', $this->call('progressBarInfos')) + ->assert('databox_id', '\d+') + ->bind('admin_document_information'); + /** * Mount collection on collection * @@ -369,7 +424,7 @@ class Database implements ControllerProviderInterface $app->abort(400, _('Bad request format, only JSON is allowed')); } - $app['phraseanet.appbox']->set_databox_indexable($app['phraseanet.appbox']->get_databox($databox_id), ! ! $request->get('INDEXABLE', false)); + $app['phraseanet.appbox']->set_databox_indexable($app['phraseanet.appbox']->get_databox($databox_id), ! ! $request->get('INDEXABLE', false)); return $app->json(array('sbas_id' => $databox_id)); } @@ -663,7 +718,7 @@ class Database implements ControllerProviderInterface $app->abort(400, _('Bad request format, only JSON is allowed')); } - if(null === $viewName = $request->get('viewname')){ + if (null === $viewName = $request->get('viewname')) { $app->abort(400, _('Missing view name parameter')); } @@ -672,6 +727,137 @@ class Database implements ControllerProviderInterface return $app->json(array('sbas_id' => $databox_id)); } + /** + * + * @param \Silex\Application $app + * @param \Symfony\Component\HttpFoundation\Request $request + * @param type $databox_id + */ + public function unmountDatabase(Application $app, Request $request, $databox_id) + { + if ( ! $request->isXmlHttpRequest() || ! array_key_exists($request->getMimeType('json'), array_flip($request->getAcceptableContentTypes()))) { + $app->abort(400, _('Bad request format, only JSON is allowed')); + } + + $databox = $app['phraseanet.appbox']->get_databox($databox_id); + $databox->unmount_databox($app['phraseanet.appbox']); + + return $app->json(array('sbas_id' => $databox_id)); + } + + /** + * + * @param \Silex\Application $app + * @param \Symfony\Component\HttpFoundation\Request $request + * @param type $databox_id + */ + public function emptyDatabase(Application $app, Request $request, $databox_id) + { + if ( ! $request->isXmlHttpRequest() || ! array_key_exists($request->getMimeType('json'), array_flip($request->getAcceptableContentTypes()))) { + $app->abort(400, _('Bad request format, only JSON is allowed')); + } + + $message = _('Base empty successful'); + $success = false; + + try { + $databox = $app['phraseanet.appbox']->get_databox($databox_id); + + foreach ($databox->get_collections() as $collection) { + if ($collection->get_record_amount() <= 500) { + $collection->empty_collection(500); + } else { + $settings = "" . $collection->get_base_id() . ""; + \task_abstract::create($app['phraseanet.appbox'], 'task_period_emptyColl', $settings); + $message = _('A task has been creted, please run it to complete empty collection'); + } + } + + $success = true; + } catch (\Exception $e) { + $message = _('An error occurred'); + } + + return $app->json(array('success' => $success, 'message' => $message)); + } + + /** + * + * @param \Silex\Application $app + * @param \Symfony\Component\HttpFoundation\Request $request + * @param integer $databox_id + * @param integer $collection_id + */ + public function emptyCollection(Application $app, Request $request, $databox_id, $collection_id) + { + if ( ! $request->isXmlHttpRequest() || ! array_key_exists($request->getMimeType('json'), array_flip($request->getAcceptableContentTypes()))) { + $app->abort(400, _('Bad request format, only JSON is allowed')); + } + + $message = _('Collection empty successful'); + $success = false; + + try { + $databox = $app['phraseanet.appbox']->get_databox($databox_id); + $collection = \collection::get_from_coll_id($databox, $collection_id); + + if ($collection->get_record_amount() <= 500) { + $collection->empty_collection(500); + } else { + $settings = "\n\n" . $collection->get_base_id() . ""; + \task_abstract::create($app['phraseanet.appbox'], 'task_period_emptyColl', $settings); + $message = _('A task has been creted, please run it to complete empty collection'); + } + + $success = true; + } catch (\Exception $e) { + $message = _('An error occurred'); + } + + return $app->json(array('success' => $success, 'message' => $message)); + } + + /** + * + * @param \Silex\Application $app + * @param \Symfony\Component\HttpFoundation\Request $request + * @param type $databox_id + */ + public function progressBarInfos(Application $app, Request $request, $databox_id) + { + if ( ! $request->isXmlHttpRequest() || ! array_key_exists($request->getMimeType('json'), array_flip($request->getAcceptableContentTypes()))) { + $app->abort(400, _('Bad request format, only JSON is allowed')); + } + + $appbox = $app['phraseanet.appbox']; + + $ret = array( + 'sbas_id' => null, + 'indexable' => false, + 'records' => 0, + 'xml_indexed' => 0, + 'thesaurus_indexed' => 0, + 'viewname' => null, + 'printLogoURL' => NULL + ); + + $databox = $appbox->get_databox($databox_id); + $datas = $databox->get_indexed_record_amount(); + + $ret['indexable'] = $appbox->is_databox_indexable($databox); + $ret['viewname'] = (($databox->get_dbname() == $databox->get_viewname()) ? _('admin::base: aucun alias') : $databox->get_viewname()); + $ret['records'] = $databox->get_record_amount(); + $ret['sbas_id'] = $databox_id; + $ret['xml_indexed'] = $datas['xml_indexed']; + $ret['thesaurus_indexed'] = $datas['thesaurus_indexed']; + + if ($app['filesystem']->exists($app['Registry']->get('GV_RootPath') . 'config/minilogos/logopdf_' . $databox_id . '.jpg')) { + $ret['printLogoURL'] = '/print/' . $databox_id; + } + + return $app->json($ret); + } + /** * Prefix the method to call with the controller class name * diff --git a/lib/Alchemy/Phrasea/Controller/Admin/Root.php b/lib/Alchemy/Phrasea/Controller/Admin/Root.php index 109dce6a5c..c0b6e3e28e 100644 --- a/lib/Alchemy/Phrasea/Controller/Admin/Root.php +++ b/lib/Alchemy/Phrasea/Controller/Admin/Root.php @@ -97,6 +97,49 @@ class Root implements ControllerProviderInterface ); }); + $controllers->get('/tree/', function() { + if (null === $position = $request->get('position')) { + $app->abort(400, _('Missing position parameter')); + } + + return new Response($app['twig']->render(\module_admin::getTree($position))); + }); + + $controllers->get('/test-paths/', function() { + + if ( ! $request->isXmlHttpRequest() || ! array_key_exists($request->getMimeType('json'), array_flip($request->getAcceptableContentTypes()))) { + $app->abort(400, _('Bad request format, only JSON is allowed')); + } + + if (0 !== count($tests = $request->get('tests', array()))) { + + $app->abort(400, _('Missing tests parameter')); + } + + if (null !== $path = $request->get('path')) { + + $app->abort(400, _('Missing path parameter')); + } + + foreach ($tests as $test) { + switch ($test) { + case 'writeable': + if ( ! is_writable($path)) { + $result = false; + } + break; + case 'readable': + default: + if ( ! is_readable($path)) { + $result = true; + } + break; + } + } + + return $app->json(array('results' => $result)); + }); + $controllers->get('/structure/{databox_id}/', function(Application $app, Request $request, $databox_id) { if ( ! $app['phraseanet.core']->getAuthenticatedUser()->ACL()->has_right_on_sbas($databox_id, 'bas_modify_struct')) { $app->abort(403); @@ -206,7 +249,7 @@ class Root implements ControllerProviderInterface $error = true; } - return $app->json(array('success' => ! $error)); + return $app->json(array('success' => ! $error)); })->assert('databox_id', '\d+')->assert('bit', '\d+'); $controllers->post('/statusbit/{databox_id}/status/{bit}/', function(Application $app, Request $request, $databox_id, $bit) { diff --git a/templates/web/Mustache/Prod/Alert-Success.Mustache.html b/templates/web/Mustache/Prod/Alert-Success.Mustache.html new file mode 100644 index 0000000000..50d3e7f2f3 --- /dev/null +++ b/templates/web/Mustache/Prod/Alert-Success.Mustache.html @@ -0,0 +1,4 @@ +
+ + {{ content }} +
diff --git a/templates/web/admin/collection/collection.html.twig b/templates/web/admin/collection/collection.html.twig new file mode 100644 index 0000000000..67247b8239 --- /dev/null +++ b/templates/web/admin/collection/collection.html.twig @@ -0,0 +1,266 @@ + + + + + +{% if user.ACL.has_right_on_base(app.request.get('bas_id'), 'manage') %} +
+
{% trans 'admin::collection:: Gestionnaires des commandes' %}
+
+ {% if admins | length > 0 %} +
    + {% for user in admins %} +
  • + +
  • + {% endfor %} +
+ {% endif %} + +
{% trans 'setup:: ajouter un administrateur des commandes' %}
+ +
+ + + +
+
+
+ +
+
{% trans 'admin::collection:: presentation des elements lors de la diffusion aux utilisateurs externes (publications)' %}
+
+ + + +
+
+ +
+
+ +
+
+ +
+
+ + + {{ collection.is_active() ? 'admin::base:collection: descativer la collection' | trans : 'admin::base:collection: activer la collection'| trans }} + +
+ +
+ + + {% trans 'admin::base:collection: vider la collection' %} + +
+ +
+ + + {% trans 'boutton::supprimer' %} + +
+
+{% endif %} + +
+
{% trans 'admin::base:collection: minilogo actuel' %}
+ {% if collection.getLogo(app.request.get('bas_id')) is not empty %} +
{{ collection.getLogo(app.request.get('bas_id')) | raw }}
+ {% if user.ACL.has_right_on_base(app.request.get('bas_id'), 'manage') %} +
+ + + {% trans 'boutton::supprimer' %} + +
+ {% endif%} + {% elseif user.ACL.has_right_on_base(app.request.get('bas_id'), 'manage') %} + {% trans 'admin::base:collection: aucun fichier (minilogo, watermark ...)' %} +
+ + {% trans 'boutton::envoyer' %} +
+ {% endif %} +
+ +
+
Watermark
+ {% if collection.getWatermark(app.request.get('bas_id')) is not empty %} +
{{ collection.getWatermark(app.request.get('bas_id'))| raw }}
+ {% if user.ACL.has_right_on_base(app.request.get('bas_id'), 'manage') %} +
+ + + {% trans 'boutton::supprimer' %} + +
+ {% endif%} + {% elseif user.ACL.has_right_on_base(app.request.get('bas_id'), 'manage') %} + {% trans 'admin::base:collection: aucun fichier (minilogo, watermark ...)' %} +
+ + {% trans 'boutton::envoyer' %} +
+ {% endif %} +
+ +
+
StampLogo
+ {% if collection.getStamp(app.request.get('bas_id')) is not empty %} +
{{ collection.getStamp(app.request.get('bas_id'))| raw }}
+ {% if user.ACL.has_right_on_base(app.request.get('bas_id'), 'manage') %} +
+ + + {% trans 'boutton::supprimer' %} + +
+ {% endif%} + {% elseif user.ACL.has_right_on_base(app.request.get('bas_id'), 'manage') %} + {% trans 'admin::base:collection: aucun fichier (minilogo, watermark ...)' %} +
+ + {% trans 'boutton::envoyer' %} +
+ {% endif %} +
+ +
+
{% trans 'admin::base:collection: image de presentation : ' %}
+ {% if collection.getPresentation(app.request.get('bas_id')) is not empty %} +
{{ collection.getPresentation(app.request.get('bas_id'))| raw }}
+ {% if user.ACL.has_right_on_base(app.request.get('bas_id'), 'manage') %} +
+ + + {% trans 'boutton::supprimer' %} + +
+ {% endif%} + {% elseif user.ACL.has_right_on_base(app.request.get('bas_id'), 'manage') %} + {% trans 'admin::base:collection: aucun fichier (minilogo, watermark ...)' %} +
+ + {% trans 'boutton::envoyer' %} + (max : 650x200) +
+ {% endif %} +
+ + \ No newline at end of file diff --git a/templates/web/admin/tree.html.twig b/templates/web/admin/tree.html.twig index f6cbe977ef..55f66449c2 100644 --- a/templates/web/admin/tree.html.twig +++ b/templates/web/admin/tree.html.twig @@ -168,9 +168,10 @@
  • - - {{ collection.get_name() }} - + {##} + + {{ collection.get_name() }} +