From e62d1e924c3e87194807808f0eab0dffbae00c48 Mon Sep 17 00:00:00 2001 From: Nicolas Le Goff Date: Tue, 14 Aug 2012 17:33:11 +0200 Subject: [PATCH] add details view for collection & databox; add sphinxconf; add users import & export; add tests --- lib/Alchemy/Phrasea/Application/Admin.php | 2 + lib/Alchemy/Phrasea/Controller/Admin/Bas.php | 113 ++- .../Phrasea/Controller/Admin/Database.php | 6 +- .../Phrasea/Controller/Admin/Databases.php | 25 - .../Phrasea/Controller/Admin/Sphinx.php | 71 ++ .../Phrasea/Controller/Admin/Users.php | 342 ++++++++ lib/classes/format.class.php | 23 + .../web/admin/collection/collection.html.twig | 2 +- .../web/admin/collection/details.html.twig | 47 + templates/web/admin/databases.html.twig | 4 +- templates/web/admin/databox/databox.html.twig | 2 +- templates/web/admin/index.html.twig | 5 +- .../web/admin/sphinx/configuration.html.twig | 19 + templates/web/admin/tree.html.twig | 7 +- templates/web/admin/user/export.html.twig | 0 .../web/admin/user/import/file.html.twig | 47 + .../web/admin/user/import/view.html.twig | 22 + templates/web/admin/users.html.twig | 21 +- .../Controller/Admin/AdminDashboardTest.php | 150 ++++ .../Phrasea/Controller/Admin/BasTest.php | 800 ++++++++++++++++++ .../Controller/Admin/ConnectedUserTest.php | 30 + .../Controller/Admin/DashboardTest.php | 185 ---- .../Phrasea/Controller/Admin/DatabaseTest.php | 446 ++++++++++ .../Controller/Admin/DatabasesTest.php | 80 ++ .../Controller/Admin/DescriptionTest.php | 4 +- .../Phrasea/Controller/Admin/SetupTest.php | 77 ++ .../Phrasea/Controller/Admin/SphinxTest.php | 77 ++ .../Phrasea/Controller/Admin/SubdefsTest.php | 8 +- www/admin/collection.php | 725 ---------------- www/admin/database.php | 702 --------------- www/admin/import.php | 455 ---------- www/admin/import0.php | 48 -- www/admin/sphinxconf.php | 64 -- 33 files changed, 2372 insertions(+), 2237 deletions(-) create mode 100644 lib/Alchemy/Phrasea/Controller/Admin/Sphinx.php create mode 100644 templates/web/admin/collection/details.html.twig create mode 100644 templates/web/admin/sphinx/configuration.html.twig create mode 100644 templates/web/admin/user/export.html.twig create mode 100644 templates/web/admin/user/import/file.html.twig create mode 100644 templates/web/admin/user/import/view.html.twig create mode 100644 tests/Alchemy/Phrasea/Controller/Admin/AdminDashboardTest.php create mode 100644 tests/Alchemy/Phrasea/Controller/Admin/BasTest.php create mode 100644 tests/Alchemy/Phrasea/Controller/Admin/ConnectedUserTest.php delete mode 100644 tests/Alchemy/Phrasea/Controller/Admin/DashboardTest.php create mode 100644 tests/Alchemy/Phrasea/Controller/Admin/DatabaseTest.php create mode 100644 tests/Alchemy/Phrasea/Controller/Admin/DatabasesTest.php create mode 100644 tests/Alchemy/Phrasea/Controller/Admin/SetupTest.php create mode 100644 tests/Alchemy/Phrasea/Controller/Admin/SphinxTest.php delete mode 100644 www/admin/collection.php delete mode 100644 www/admin/database.php delete mode 100644 www/admin/import.php delete mode 100644 www/admin/import0.php delete mode 100644 www/admin/sphinxconf.php diff --git a/lib/Alchemy/Phrasea/Application/Admin.php b/lib/Alchemy/Phrasea/Application/Admin.php index 5fa0660971..6a94e829a8 100644 --- a/lib/Alchemy/Phrasea/Application/Admin.php +++ b/lib/Alchemy/Phrasea/Application/Admin.php @@ -24,6 +24,7 @@ use Alchemy\Phrasea\Controller\Admin\Bas; use Alchemy\Phrasea\Controller\Admin\Databases; use Alchemy\Phrasea\Controller\Admin\Database; use Alchemy\Phrasea\Controller\Admin\Setup; +use Alchemy\Phrasea\Controller\Admin\Sphinx; use Alchemy\Phrasea\Controller\Utils\ConnectionTest; use Alchemy\Phrasea\Controller\Utils\PathFileTest; @@ -37,6 +38,7 @@ return call_user_func( $app->mount('/database', new Database()); $app->mount('/databases', new Databases()); $app->mount('/setup', new Setup()); + $app->mount('/sphinx', new Sphinx()); $app->mount('/connected-users', new ConnectedUsers()); $app->mount('/publications', new Publications()); $app->mount('/users', new Users()); diff --git a/lib/Alchemy/Phrasea/Controller/Admin/Bas.php b/lib/Alchemy/Phrasea/Controller/Admin/Bas.php index 91d53852fc..d5b279fe01 100644 --- a/lib/Alchemy/Phrasea/Controller/Admin/Bas.php +++ b/lib/Alchemy/Phrasea/Controller/Admin/Bas.php @@ -398,6 +398,23 @@ class Bas implements ControllerProviderInterface } }); + /** + * Get document details + * + * name : admin_document_details + * + * description : Get document details + * + * method : GET + * + * parameters : none + * + * return : HTML Response + */ + $controllers->get('/{bas_id}/informations/details/', $this->call('getDetails')) + ->assert('bas_id', '\d+') + ->bind('admin_collection_document_details'); + return $controllers; } @@ -956,9 +973,9 @@ class Bas implements ControllerProviderInterface $pref = array('status' => null, 'xml' => null); if ($ki == "status") { - $pref['status'] = $vi; + $pref['status'] = $vi; } else if ($ki != "sugestedValues") { - $pref['xml'] = $vi->asXML(); + $pref['xml'] = $vi->asXML(); } $basePrefs[] = $pref; @@ -966,7 +983,7 @@ class Bas implements ControllerProviderInterface } } - if($updateMsg = $request->get('update')) { + if ($updateMsg = $request->get('update')) { switch ($updateMsg) { case 'ok'; $updateMsg = _('forms::operation effectuee OK'); @@ -1010,7 +1027,6 @@ class Bas implements ControllerProviderInterface $msg = _('Coult not load XML'); $success = false; } - } catch (\Exception $e) { } @@ -1018,6 +1034,95 @@ class Bas implements ControllerProviderInterface return $app->json(array('success' => $success, 'msg' => $msg)); } + /** + * + * @param \Silex\Application $app + * @param \Symfony\Component\HttpFoundation\Request $request + * @param integer $databox_id + */ + public function getDetails(Application $app, Request $request, $bas_id) + { + $databox = $app['phraseanet.appbox']->get_databox(\phrasea::sbasFromBas($bas_id)); + $collection = \collection::get_from_base_id($bas_id); + + $out = array('total' => array('totobj' => 0, 'totsiz' => 0, 'mega' => '0', 'giga' => '0'), 'result' => array()); + + foreach ($collection->get_record_details() as $vrow) { + + $last_k1 = $last_k2 = null; + $outRow = array('midobj' => 0, 'midsiz' => 0); + + if ($vrow["amount"] > 0 || $last_k1 !== $vrow["coll_id"]) { + + if (extension_loaded("bcmath")) { + $outRow['midsiz'] = bcadd($outRow['midsiz'], $vrow["size"], 0); + } else { + $outRow['midsiz'] += $vrow["size"]; + } + + if ($last_k2 !== $vrow["name"]) { + $outRow['name'] = $vrow["name"]; + $last_k2 = $vrow["name"]; + } + + if (extension_loaded("bcmath")) { + $mega = bcdiv($vrow["size"], 1024 * 1024, 5); + } else { + $mega = $vrow["size"] / (1024 * 1024); + } + + if (extension_loaded("bcmath")) { + $giga = bcdiv($vrow["size"], 1024 * 1024 * 1024, 5); + } else { + $giga = $vrow["size"] / (1024 * 1024 * 1024); + } + + $outRow['mega'] = sprintf("%.2f", $mega); + $outRow['giga'] = sprintf("%.2f", $giga); + $outRow['amount'] = $vrow["amount"]; + } + + $out['total']['totobj'] += $outRow['amount']; + if (extension_loaded("bcmath")) { + $out['total']['totsiz'] = bcadd($out['total']['totsiz'], $outRow['midsiz'], 0); + } else { + $out['total']['totsiz'] += $outRow['midsiz']; + } + + if (extension_loaded("bcmath")) + $mega = bcdiv($outRow['midsiz'], 1024 * 1024, 5); + else + $mega = $outRow['midsiz'] / (1024 * 1024); + + if (extension_loaded("bcmath")) + $giga = bcdiv($outRow['midsiz'], 1024 * 1024 * 1024, 5); + else + $giga = $outRow['midsiz'] / (1024 * 1024 * 1024); + + $outRow['mega_mid_size'] = sprintf("%.2f", $mega); + $outRow['giga_mid_size'] = sprintf("%.2f", $giga); + + $out['result'][] = $outRow; + } + + if (extension_loaded("bcmath")) { + $out['total']['mega'] = bcdiv($out['total']['totsiz'], 1024 * 1024, 5); + } else { + $out['total']['mega'] = $out['total']['totsiz'] / (1024 * 1024); + } + + if (extension_loaded("bcmath")) { + $out['total']['giga'] = bcdiv($out['total']['totsiz'], 1024 * 1024 * 1024, 5); + } else { + $out['total']['giga'] = $out['total']['totsiz'] / (1024 * 1024 * 1024); + } + + return new Response($app['twig']->render('admin/collection/details.html.twig', array( + 'collection' => $collection, + 'table' => $out, + ))); + } + /** * Prefix the method to call with the controller class name * diff --git a/lib/Alchemy/Phrasea/Controller/Admin/Database.php b/lib/Alchemy/Phrasea/Controller/Admin/Database.php index 4466f5229c..6cfff2b134 100644 --- a/lib/Alchemy/Phrasea/Controller/Admin/Database.php +++ b/lib/Alchemy/Phrasea/Controller/Admin/Database.php @@ -530,7 +530,7 @@ class Database implements ControllerProviderInterface */ public function createDatabase(Application $app, Request $request) { - if ('' !== $dbName = $request->get('new_dbname', '')) { + if ('' === $dbName = $request->get('new_dbname', '')) { return $app->redirect('/admin/databases/?error=no-empty'); } @@ -986,9 +986,7 @@ class Database implements ControllerProviderInterface $databox = $app['phraseanet.appbox']->get_databox($databox_id); $out = array('total' => array('totobj' => 0, 'totsiz' => 0, 'mega' => '0', 'giga' => '0'), 'result' => array()); -// echo '
';
-//        var_dump($databox->get_record_details($request->get('sort')));
-//        echo '
'; + foreach ($databox->get_record_details($request->get('sort')) as $vgrp) { $last_k1 = $last_k2 = null; diff --git a/lib/Alchemy/Phrasea/Controller/Admin/Databases.php b/lib/Alchemy/Phrasea/Controller/Admin/Databases.php index 1bd2d8c240..a1f565ebd8 100644 --- a/lib/Alchemy/Phrasea/Controller/Admin/Databases.php +++ b/lib/Alchemy/Phrasea/Controller/Admin/Databases.php @@ -52,20 +52,6 @@ class Databases implements ControllerProviderInterface */ $controllers->get('/', $this->call('getDatabases'))->bind('admin_databases'); - /** - * Reset cache - * - * name : admin_database_new - * - * description : Reset all cache - * - * method : POST - * - * parameters : none - * - * return : Redirect Response - */ - $controllers->post('/', $this->call('postDatabases'))->bind('admin_database_new'); /** * Upgrade databases @@ -187,17 +173,6 @@ class Databases implements ControllerProviderInterface ))); } - /** - * - * @param \Silex\Application $app - * @param \Symfony\Component\HttpFoundation\Request $request - * @return \Symfony\Component\HttpFoundation\Response - */ - public function postDatabases(Application $app, Request $request) - { - - } - /** * * @param \Silex\Application $app diff --git a/lib/Alchemy/Phrasea/Controller/Admin/Sphinx.php b/lib/Alchemy/Phrasea/Controller/Admin/Sphinx.php new file mode 100644 index 0000000000..8c096b79c3 --- /dev/null +++ b/lib/Alchemy/Phrasea/Controller/Admin/Sphinx.php @@ -0,0 +1,71 @@ +get('/configuration/', function(Application $app, Request $request) { + $registry = $app['phraseanet.core']['Registry']; + + $sphinxConf = new \sphinx_configuration(); + + $selected_charsets = $registry->get('sphinx_charset_tables'); + $selected_libstemmer = $registry->get('sphinx_user_stemmer'); + + $options = array( + 'charset_tables' => ( ! is_array($selected_charsets) ? array() : $selected_charsets), + 'libstemmer' => ( ! is_array($selected_libstemmer) ? array() : $selected_libstemmer) + ); + + return new Response($app['twig']->render('admin/sphinx/configuration.html.twig', array( + 'configuration' => $sphinxConf, + 'options' => $options + ))); + }); + + $controllers->post('/configuration/', function(Application $app, Request $request) { + $registry = $app['phraseanet.core']['Registry']; + + $registry->set( + 'sphinx_charset_tables', $request->get('charset_tables', array()), \registry::TYPE_ARRAY + ); + + $registry->set( + 'sphinx_user_stemmer', $request->get('libstemmer', array()), \registry::TYPE_ARRAY + ); + + return $app->redirect('/admin/sphinx/configuration/?update=ok'); + }); + + return $controllers; + } +} diff --git a/lib/Alchemy/Phrasea/Controller/Admin/Users.php b/lib/Alchemy/Phrasea/Controller/Admin/Users.php index 645b7b2f72..000bcf81fe 100644 --- a/lib/Alchemy/Phrasea/Controller/Admin/Users.php +++ b/lib/Alchemy/Phrasea/Controller/Admin/Users.php @@ -576,7 +576,349 @@ class Users implements ControllerProviderInterface return $app->redirect('/admin/users/demands/?demands=ok'); }); + $controllers->get('/import/file/', function(Application $app, Request $request) { + + return $app['twig']->render('admin/user/import/file.html.twig'); + }); + + $controllers->post('/import/file/', function(Application $app, Request $request) { + $user = $app['phraseanet.core']->getAuthenticatedUser(); + + if ((null === $file = $request->files->get('file')) || ! $file->isValid()) { + + return $app->rediretc('/admin/import/file/?error=file'); + } + + $array = \format::csv_to_arr($file->getPathname()); + + $equivalenceToMysqlField = $this->getEquivalenceToMysqlField(); + $loginDefined = $pwdDefined = false; + $loginNew = array(); + $out = array('ignored_row' => array(), 'errors' => array()); + $nbUsrToAdd = 0; + + for ($j = 0; $j < sizeof($array[0]); $j ++ ) { + $array[0][$j] = trim(mb_strtolower($array[0][$j])); + + if ( ! isset($equivalenceToMysqlField[$array[0][$j]])) { + $out['ignored_row'][] = $array[0][$j]; + } else { + if (($equivalenceToMysqlField[$array[0][$j]]) == 'usr_login') { + $loginDefined = true; + } + + if (($equivalenceToMysqlField[$array[0][$j]]) == 'usr_password') { + $pwdDefined = true; + } + } + } + + if ( ! $loginDefined) { + + return $app->redirect('/admin/users/import/file/?error=row-login'); + } + + if ( ! $pwdDefined) { + + return $app->redirect('/admin/users/import/file/?error=row-pwd'); + } + + $nbLines = sizeof($array); + $nbCols = sizeof($array[0]); + + for ($i = 1; $i < $nbLines; $i ++ ) { + $hasVerifLogin = false; + $hasVerifPwd = false; + + for ($j = 0; $j < $nbCols; $j ++ ) { + $array[$i][$j] = trim($array[$i][$j]); + + if ( ! isset($equivalenceToMysqlField[$array[0][$j]])) { + continue; + } + + if (($equivalenceToMysqlField[$array[0][$j]]) == 'usr_login') { + $loginToAdd = $array[$i][$j]; + + if ($loginToAdd == "") { + $out['errors'][] = sprintf(_("Login line %d is empty"), $i); + } elseif (isset($loginNew[$loginToAdd])) { + $out['errors'][] = sprintf(_("Login %s is already defined in the file at line %d"), $loginToAdd, $i); + } else { + if (\User_Adapter::get_usr_id_from_login($loginToAdd)) { + $out['errors'][] = sprintf(_("Login %s already exists in database"), $loginToAdd); + } else { + $loginNew[$loginToAdd] = ($i + 1); + } + } + $hasVerifLogin = true; + } + + if (($equivalenceToMysqlField[$array[0][$j]]) == 'usr_password') { + $passwordToVerif = $array[$i][$j]; + + if ($passwordToVerif == "") { + $out['errors'][] = sprintf(_("Password is empty at line %d"), $i); + } + + $hasVerifPwd = true; + } + + if ($hasVerifLogin && $hasVerifPwd) { + $j = $nbCols; + } + + if (($j + 1) >= $nbCols) { + if (count($out['errors']) === 0) { + $nbUsrToAdd ++; + } + } + } + } + + if (count($out['errors']) > 0) { + + return $app['twig']->render('admin/user/import/file.html.twig', array( + 'errors' => $out['errors'] + )); + } else if ($nbUsrToAdd === 0) { + + return $app->redirect('/admin/users/import/file/?error=no-user'); + } else { + for ($i = 1; $i < sizeof($array); $i ++ ) { + for ($j = 0; $j < sizeof($array[0]); $j ++ ) { { + if ((isset($array[$i][$j]) && trim($array[$i][$j]) == "") || ( ! isset($equivalenceToMysqlField[$array[0][$j]]))) + unset($array[$i][$j]); + } + } + } + + $sql = " + SELECT usr.usr_id,usr.usr_login + FROM usr + INNER JOIN basusr + ON (basusr.usr_id=usr.usr_id) + WHERE usr.model_of = :usr_id + AND base_id in(" . implode(', ', array_keys($user->ACL()->get_granted_base(array('manage')))) . ") + AND usr_login not like '(#deleted_%)' + GROUP BY usr_id"; + + $stmt = $app['phraseanet.appbox']->get_connection()->prepare($sql); + $stmt->execute(array(':usr_id' => $user->get_id())); + $models = $stmt->fetchAll(\PDO::FETCH_ASSOC); + $stmt->closeCursor(); + + return $app['twig']->render('/admin/user/import/view.html.twig', array( + 'nb_user_to_add' => $nbUsrToAdd, + 'models' => $models, + 'array_serialized' => serialize($array) + )); + } + }); + + $controllers->post('/import/', function(Application $app, Request $request) { + $nbCreation = 0; + $user = $app['phraseanet.core']->getAuthenticatedUser(); + + if ((null === $serializedArray = $request->get('sr')) || ('' === $serializedArray)) { + $app->abort(400); + } + + if (null === $model = $request->get("modelToAplly")) { + $app->abort(400); + } + + $array = unserialize($serializedArray); + + $nbLines = sizeof($array); + $nbCols = sizeof($array[0]); + + $equivalenceToMysqlField = $this->getEquivalenceToMysqlField(); + + for ($i = 1; $i < $nbLines; $i ++ ) { + $curUser = null; + for ($j = 0; $j < $nbCols; $j ++ ) { + if ( ! isset($equivalenceToMysqlField[$array[0][$j]])) + continue; + if ($equivalenceToMysqlField[$array[0][$j]] == "usr_sexe" && isset($array[$i][$j])) { + switch ($array[$i][$j]) { + case "Mlle": + case "Mlle.": + case "mlle": + case "Miss": + case "miss": + case "0": + $curUser[$equivalenceToMysqlField[$array[0][$j]]] = 0; + break; + + case "Mme": + case "Madame": + case "Ms": + case "Ms.": + case "1": + $curUser[$equivalenceToMysqlField[$array[0][$j]]] = 1; + break; + + case "M": + case "M.": + case "Mr": + case "Mr.": + case "Monsieur": + case "Mister": + case "2": + $curUser[$equivalenceToMysqlField[$array[0][$j]]] = 2; + break; + } + } else { + if (isset($array[$i][$j])) { + $curUser[$equivalenceToMysqlField[$array[0][$j]]] = trim($array[$i][$j]); + } + } + } + } + + if (isset($curUser['usr_login']) && trim($curUser['usr_login']) !== '' && isset($curUser['usr_password']) && trim($curUser['usr_password']) !== "") { + $loginNotExist = ! \User_Adapter::get_usr_id_from_login($curUser['usr_login']); + + if ($loginNotExist) { + $NewUser = \User_Adapter::create($app['phraseanet.appbox'], $curUser['usr_login'], $curUser['usr_password'], $curUser['usr_mail'], false); + + $NewUser->ACL()->apply_model( + \User_Adapter::getInstance($model, $app['phraseanet.appbox']), array_keys($user->ACL()->get_granted_base(array('manage'))) + ); + + $nbCreation ++; + } + } + + return $app->redirect('/admin/users/search/?user-updated=' . $nbCreation); + }); + + + $controllers->get('/import/example/user/', function(Application $app, Request $request) { + + $file = new \SplFileInfo($app['phraseanet.core']['Registry']->get('GV_RootPath') . 'www/admin/exampleImportUsers.csv'); + + if ( ! $file->isFile()) { + $app->abort(400); + } + + $response = new Response(); + $response->setStatusCode(200); + $response->headers->set('Pragma', 'public'); + $response->headers->set('Content-Disposition', 'attachment; filename=' . $file->getFilename()); + $response->headers->set('Content-Length', $file->getSize()); + $response->headers->set('Content-Type', 'text/csv'); + $response->setContent(file_get_contents($file->getPathname())); + + $response->send(); + + return $response; + }); + + $controllers->get('/import/example/rtf/', function(Application $app, Request $request) { + + $file = new \SplFileInfo($app['phraseanet.core']['Registry']->get('GV_RootPath') . 'www/admin/Fields.rtf'); + + if ( ! $file->isFile()) { + $app->abort(400); + } + + $response = new Response(); + $response->setStatusCode(200); + $response->headers->set('Pragma', 'public'); + $response->headers->set('Content-Disposition', 'attachment; filename=' . $file->getFilename()); + $response->headers->set('Content-Length', $file->getSize()); + $response->headers->set('Content-Type', 'text/rtf'); + $response->setContent(file_get_contents($file->getPathname())); + + $response->send(); + + return $response; + }); + return $controllers; } + + private function getEquivalenceToMysqlField() + { + $equivalenceToMysqlField = array(); + + $equivalenceToMysqlField['civilite'] = 'usr_sexe'; + $equivalenceToMysqlField['gender'] = 'usr_sexe'; + $equivalenceToMysqlField['usr_sexe'] = 'usr_sexe'; + $equivalenceToMysqlField['nom'] = 'usr_nom'; + $equivalenceToMysqlField['name'] = 'usr_nom'; + $equivalenceToMysqlField['last name'] = 'usr_nom'; + $equivalenceToMysqlField['last_name'] = 'usr_nom'; + $equivalenceToMysqlField['usr_nom'] = 'usr_nom'; + $equivalenceToMysqlField['first name'] = 'usr_prenom'; + $equivalenceToMysqlField['first_name'] = 'usr_prenom'; + $equivalenceToMysqlField['prenom'] = 'usr_prenom'; + $equivalenceToMysqlField['usr_prenom'] = 'usr_prenom'; + $equivalenceToMysqlField['identifiant'] = 'usr_login'; + $equivalenceToMysqlField['login'] = 'usr_login'; + $equivalenceToMysqlField['usr_login'] = 'usr_login'; + $equivalenceToMysqlField['usr_password'] = 'usr_password'; + $equivalenceToMysqlField['password'] = 'usr_password'; + $equivalenceToMysqlField['mot de passe'] = 'usr_password'; + $equivalenceToMysqlField['usr_mail'] = 'usr_mail'; + $equivalenceToMysqlField['email'] = 'usr_mail'; + $equivalenceToMysqlField['mail'] = 'usr_mail'; + $equivalenceToMysqlField['adresse'] = 'adresse'; + $equivalenceToMysqlField['adress'] = 'adresse'; + $equivalenceToMysqlField['address'] = 'adresse'; + $equivalenceToMysqlField['ville'] = 'ville'; + $equivalenceToMysqlField['city'] = 'ville'; + $equivalenceToMysqlField['zip'] = 'cpostal'; + $equivalenceToMysqlField['zipcode'] = 'cpostal'; + $equivalenceToMysqlField['zip_code'] = 'cpostal'; + $equivalenceToMysqlField['cpostal'] = 'cpostal'; + $equivalenceToMysqlField['cp'] = 'cpostal'; + $equivalenceToMysqlField['code_postal'] = 'cpostal'; + $equivalenceToMysqlField['tel'] = 'tel'; + $equivalenceToMysqlField['telephone'] = 'tel'; + $equivalenceToMysqlField['phone'] = 'tel'; + $equivalenceToMysqlField['fax'] = 'fax'; + $equivalenceToMysqlField['job'] = 'fonction'; + $equivalenceToMysqlField['fonction'] = 'fonction'; + $equivalenceToMysqlField['function'] = 'fonction'; + $equivalenceToMysqlField['societe'] = 'societe'; + $equivalenceToMysqlField['company'] = 'societe'; + $equivalenceToMysqlField['activity'] = 'activite'; + $equivalenceToMysqlField['activite'] = 'activite'; + $equivalenceToMysqlField['pays'] = 'pays'; + $equivalenceToMysqlField['country'] = 'pays'; + $equivalenceToMysqlField['ftp_active'] = 'activeFTP'; + $equivalenceToMysqlField['compte_ftp_actif'] = 'activeFTP'; + $equivalenceToMysqlField['ftpactive'] = 'activeFTP'; + $equivalenceToMysqlField['activeftp'] = 'activeFTP'; + $equivalenceToMysqlField['ftp_adress'] = 'addrFTP'; + $equivalenceToMysqlField['adresse_du_serveur_ftp'] = 'addrFTP'; + $equivalenceToMysqlField['addrftp'] = 'addrFTP'; + $equivalenceToMysqlField['ftpaddr'] = 'addrFTP'; + $equivalenceToMysqlField['loginftp'] = 'loginFTP'; + $equivalenceToMysqlField['ftplogin'] = 'loginFTP'; + $equivalenceToMysqlField['ftppwd'] = 'pwdFTP'; + $equivalenceToMysqlField['pwdftp'] = 'pwdFTP'; + $equivalenceToMysqlField['destftp'] = 'destFTP'; + $equivalenceToMysqlField['destination_folder'] = 'destFTP'; + $equivalenceToMysqlField['dossier_de_destination'] = 'destFTP'; + $equivalenceToMysqlField['passive_mode'] = 'passifFTP'; + $equivalenceToMysqlField['mode_passif'] = 'passifFTP'; + $equivalenceToMysqlField['passifftp'] = 'passifFTP'; + $equivalenceToMysqlField['retry'] = 'retryFTP'; + $equivalenceToMysqlField['nombre_de_tentative'] = 'retryFTP'; + $equivalenceToMysqlField['retryftp'] = 'retryFTP'; + $equivalenceToMysqlField['by_default__send'] = 'defaultftpdatasent'; + $equivalenceToMysqlField['by_default_send'] = 'defaultftpdatasent'; + $equivalenceToMysqlField['envoi_par_defaut'] = 'defaultftpdatasent'; + $equivalenceToMysqlField['defaultftpdatasent'] = 'defaultftpdatasent'; + $equivalenceToMysqlField['prefix_creation_folder'] = 'prefixFTPfolder'; + $equivalenceToMysqlField['prefix_de_creation_de_dossier'] = 'prefixFTPfolder'; + $equivalenceToMysqlField['prefixFTPfolder'] = 'prefixFTPfolder'; + + return $equivalenceToMysqlField; + } } diff --git a/lib/classes/format.class.php b/lib/classes/format.class.php index b0a22549f2..dcac76574b 100644 --- a/lib/classes/format.class.php +++ b/lib/classes/format.class.php @@ -56,4 +56,27 @@ class format return implode("\n", $lines); } + + public static function csv_to_arr($filename) + { + $separateur = ","; + + // For mac + ini_set("auto_detect_line_endings", true); + + if ($FILE = fopen($filename, "r")) { + $test1 = fgetcsv($FILE, 1024, ","); + rewind($FILE); + $test2 = fgetcsv($FILE, 1024, ";"); + rewind($FILE); + if (count($test1) == 1 || ( count($test2) > count($test1) && count($test2) < 20)) + $separateur = ";"; + + while ($ARRAY[] = fgetcsv($FILE, 1024, $separateur)); + fclose($FILE); + array_pop($ARRAY); + + return $ARRAY; + } + } } diff --git a/templates/web/admin/collection/collection.html.twig b/templates/web/admin/collection/collection.html.twig index 67247b8239..2b7cd3517a 100644 --- a/templates/web/admin/collection/collection.html.twig +++ b/templates/web/admin/collection/collection.html.twig @@ -9,7 +9,7 @@
  • {% trans 'phraseanet:: adresse' %} : {{ collection.get_databox().get_serialized_server_info() }}
  • {% trans 'admin::base:collection: numero de collection distante' %} : {{ collection.get_coll_id() }}
  • {% trans 'admin::base:collection: etat de la collection' %} : {{ collection.is_active() ? "admin::base:collection: activer la collection"| trans : "admin::base:collection: descativer la collection"|trans }}
  • -
  • {{ collection.get_record_amount() }} records
  • +
  • {{ collection.get_record_amount() }} records {% trans 'phraseanet:: details' %}
  • {% if user.ACL.has_right_on_base(app.request.get('bas_id'), 'manage') %} diff --git a/templates/web/admin/collection/details.html.twig b/templates/web/admin/collection/details.html.twig new file mode 100644 index 0000000000..7cf0da49b4 --- /dev/null +++ b/templates/web/admin/collection/details.html.twig @@ -0,0 +1,47 @@ +
    +

    {{ collection.get_name() }} {% trans "Details" %}

    +
    + + + + + + + + + + + + {% for row in table['result'] %} + + + + + + + {% endfor %} + {% set totals = table['total'] %} + + + + + + + + + + +
    {% trans 'admin::base: objet' %}{% trans 'admin::base: nombre' %}{% trans 'admin::base: poids' %} (Mo){% trans 'admin::base: poids' %} (Go)
    {{ row['name'] }}{{ row['amount'] }}{{ row['mega'] }}{{ row['giga'] }}
    + {% trans 'Total' %} + + {{ totals['totobj'] }} + + {{ totals['mega'] }} + + {{ totals['giga'] }} +
    + + +
    + {% trans 'boutton::retour' %} +
    \ No newline at end of file diff --git a/templates/web/admin/databases.html.twig b/templates/web/admin/databases.html.twig index e08123d020..48f671df7e 100644 --- a/templates/web/admin/databases.html.twig +++ b/templates/web/admin/databases.html.twig @@ -4,7 +4,7 @@ {% endif %} {% if createBase %} - document.location.replace('/admin/newcoll.php?act=GETNAME&p0={{ app.request.get('sbas_id') }}'); + document.location.replace('/admin/database/{{ app.request.get('sbas_id') }}/'); {% endif %} @@ -27,7 +27,7 @@ {% if sbas | length > 0 %} {% for key, value in sbas %}
  • - + {{ value['name'] }} ({% trans "version" %} {{ value['version'] }}) {{ value['server_info'] }}
  • diff --git a/templates/web/admin/databox/databox.html.twig b/templates/web/admin/databox/databox.html.twig index 10f17b163c..90104e30e4 100644 --- a/templates/web/admin/databox/databox.html.twig +++ b/templates/web/admin/databox/databox.html.twig @@ -181,7 +181,7 @@ {% endif %}
    - + {% if user.ACL().has_right_on_sbas(databox.get_sbas_id(), "bas_manage") %} {% trans "admin::base:collection: supprimer le logo" %} diff --git a/templates/web/admin/index.html.twig b/templates/web/admin/index.html.twig index 1f45e95614..a2d751097e 100644 --- a/templates/web/admin/index.html.twig +++ b/templates/web/admin/index.html.twig @@ -205,10 +205,9 @@ function reloadTree(position, click){ $.ajax({ - type: "POST", - url: "adminFeedback.php", + type: "GET", + url: "/admin/tree/", data: { - action : 'TREE', position : position }, success: function(datas){ diff --git a/templates/web/admin/sphinx/configuration.html.twig b/templates/web/admin/sphinx/configuration.html.twig new file mode 100644 index 0000000000..661b21c5a9 --- /dev/null +++ b/templates/web/admin/sphinx/configuration.html.twig @@ -0,0 +1,19 @@ +
    + + + + + +
    + + \ No newline at end of file diff --git a/templates/web/admin/tree.html.twig b/templates/web/admin/tree.html.twig index 6b272e6e1a..1cc7e5e5e6 100644 --- a/templates/web/admin/tree.html.twig +++ b/templates/web/admin/tree.html.twig @@ -22,13 +22,13 @@ Setup
    - {% if registry.get('GV_sphinx') %} + {% if registry.get('GV_sphinx') %}
  • - + Sphinx Conf
  • - {% endif %} + {% endif %} {% endif %}
  • @@ -46,7 +46,6 @@
  • - {##} {% trans 'admin::utilisateurs: demandes en cours' %} diff --git a/templates/web/admin/user/export.html.twig b/templates/web/admin/user/export.html.twig new file mode 100644 index 0000000000..e69de29bb2 diff --git a/templates/web/admin/user/import/file.html.twig b/templates/web/admin/user/import/file.html.twig new file mode 100644 index 0000000000..a395013ee3 --- /dev/null +++ b/templates/web/admin/user/import/file.html.twig @@ -0,0 +1,47 @@ +
    +

    {% trans 'Upload a "csv" file for users creation' %}

    +
    + +{% if app.request.get('error') is not none %} + {% set error = app.request.get('error') %} +
    + + {% if error == 'file' %} + {% trans 'An error occured while upload the file. Please retry' %} + {% elseif error == 'row-login' %} + {% trans 'Row "login" is missing, script has stopped' %} + {% elseif error == 'row-pwd' %} + {% trans 'Row "password" is missing, script has stopped' %} + {% elseif error == 'no-user' %} + {% trans 'The file does not contains any user to add' %} + {% endif %} +
    +{% endif %} + +{% if errors is defined and errors is not none and errors|length > 0 %} +
    + +
      + {% for error in errors %} +
    • {{ error }}
    • + {% endfor%} +
    +
    +{% endif %} + +
    + + + +
    + {% trans "User's file " %} : +
    + + {% trans 'boutton::retour' %} +
    +
    +
    \ No newline at end of file diff --git a/templates/web/admin/user/import/view.html.twig b/templates/web/admin/user/import/view.html.twig new file mode 100644 index 0000000000..bc4c351177 --- /dev/null +++ b/templates/web/admin/user/import/view.html.twig @@ -0,0 +1,22 @@ +
    +

    {% trans 'Apply a model' %} ({{ nb_user_to_add }} {% trans 'Users' %})

    +
    + +{% if nb_user_to_add > 0 and models|length > 0 %} +
    + + +
    + + +
    +
    +{% elseif models|length == 0 %} +
    + {% trans 'You need define a model before importing a list of users' %} +
    +{% endif %} \ No newline at end of file diff --git a/templates/web/admin/users.html.twig b/templates/web/admin/users.html.twig index 751477e08d..30018642ae 100644 --- a/templates/web/admin/users.html.twig +++ b/templates/web/admin/users.html.twig @@ -3,12 +3,24 @@ {% block content %} +{% if app.request.get('user-updated') is not none%} +
    + + {% set user_count = app.request.get('user-updated') %} + {% trans %} + {{ user_count }} user has been crreated + {% plural user_count %} + {{ user_count }} users have been created + {% endtrans %} +
    +{% endif %} +

    {% trans 'Users' %}

    {% trans 'admin::user: nouvel utilisateur' %} {% trans 'admin::user: nouveau template' %} - {% trans 'admin::user: import d\'utilisateurs' %} / + {% trans 'admin::user: import d\'utilisateurs' %} / {% trans 'admin::user: export d\'utilisateurs' %} {% trans 'Reglages:: reglages d acces guest' %} @@ -279,13 +291,6 @@ }); - function importlist() - { - var myObj = new Object(); - myObj.myOpener = self; - window.showModalDialog ('/admin/import0.php?rand='+Math.random(),myObj, 'dialogWidth:550px;dialogHeight:330px;center:yes;help:no;status:no;scrollbars:no' ); - - } function exportlist() { $('#export_form').submit(); diff --git a/tests/Alchemy/Phrasea/Controller/Admin/AdminDashboardTest.php b/tests/Alchemy/Phrasea/Controller/Admin/AdminDashboardTest.php new file mode 100644 index 0000000000..a73337e416 --- /dev/null +++ b/tests/Alchemy/Phrasea/Controller/Admin/AdminDashboardTest.php @@ -0,0 +1,150 @@ +client = $this->createClient(); + $this->StubbedACL = $this->getMockBuilder('\ACL') + ->disableOriginalConstructor() + ->getMock(); + } + + public function setAdmin($bool) + { + $stubAuthenticatedUser = $this->getMockBuilder('\User_Adapter') + ->setMethods(array('is_admin','ACL')) + ->disableOriginalConstructor() + ->getMock(); + + $stubAuthenticatedUser->expects($this->any()) + ->method('is_admin') + ->will($this->returnValue($bool)); + + $this->StubbedACL->expects($this->any()) + ->method('has_right_on_base') + ->will($this->returnValue($bool)); + + $stubAuthenticatedUser->expects($this->any()) + ->method('ACL') + ->will($this->returnValue($this->StubbedACL)); + + $stubCore = $this->getMockBuilder('\Alchemy\Phrasea\Core') + ->setMethods(array('getAuthenticatedUser')) + ->getMock(); + + $stubCore->expects($this->any()) + ->method('getAuthenticatedUser') + ->will($this->returnValue($stubAuthenticatedUser)); + + $this->app['phraseanet.core'] = $stubCore; + } + + /** + * @expectedException Symfony\Component\HttpKernel\Exception\HttpException + * @covers \Alchemy\Phrasea\Controller\Admin\Dashboard::slash + * @covers \Alchemy\Phrasea\Controller\Admin\Dashboard::connect + * @covers \Alchemy\Phrasea\Controller\Admin\Dashboard::call + */ + public function testRouteDashboardUnauthorized() + { + $this->setAdmin(false); + $this->client->request('GET', '/dashboard/'); + } + + /** + * @covers \Alchemy\Phrasea\Controller\Admin\Dashboard::slash + */ + public function testRouteDashboard() + { + $this->setAdmin(true); + + $this->client->request('GET', '/dashboard/', array( + 'flush_cache' => 'ok', + 'email' => 'sent' + )); + + $this->assertTrue($this->client->getResponse()->isOk()); + } + + /** + * @covers \Alchemy\Phrasea\Controller\Admin\Dashboard::flush + */ + public function testFlushCache() + { + $this->setAdmin(true); + + $this->client->request('POST', '/dashboard/flush-cache/'); + + $this->assertTrue($this->client->getResponse()->isRedirect()); + $this->assertRegexp('/flush_cache=ok/', $this->client->getResponse()->headers->get('location')); + } + + /** + * @covers \Alchemy\Phrasea\Controller\Admin\Dashboard::sendMail + */ + public function testSendMailTest() + { + $this->setAdmin(true); + + $this->client->request('POST', '/dashboard/send-mail-test/', array( + 'email' => self::$user->get_email() + )); + + $this->assertTrue($this->client->getResponse()->isRedirect()); + $this->assertRegexp('/email=/', $this->client->getResponse()->headers->get('location')); + } + + /** + * @expectedException \Symfony\Component\HttpKernel\Exception\HttpException + * @covers \Alchemy\Phrasea\Controller\Admin\Dashboard::sendMail + */ + public function testSendMailTestBadRequest() + { + $this->setAdmin(true); + + $this->client->request('POST', '/dashboard/send-mail-test/'); + } + + /** + * @covers \Alchemy\Phrasea\Controller\Admin\Dashboard::resetAdminRights + */ + public function testResetAdminRights() + { + $this->setAdmin(true); + + $this->client->request('POST', '/dashboard/reset-admin-rights/'); + + $this->assertTrue($this->client->getResponse()->isRedirect()); + } + + /** + * @covers \Alchemy\Phrasea\Controller\Admin\Dashboard::addAdmins + */ + public function testAddAdmins() + { + $this->setAdmin(true); + + $this->client->request('POST', '/dashboard/new/', array( + 'admins' => array(self::$user->get_id()) + )); + + $this->assertTrue($this->client->getResponse()->isRedirect()); + } +} diff --git a/tests/Alchemy/Phrasea/Controller/Admin/BasTest.php b/tests/Alchemy/Phrasea/Controller/Admin/BasTest.php new file mode 100644 index 0000000000..58ba23c621 --- /dev/null +++ b/tests/Alchemy/Phrasea/Controller/Admin/BasTest.php @@ -0,0 +1,800 @@ +client = $this->createClient(); + $this->StubbedACL = $this->getMockBuilder('\ACL') + ->disableOriginalConstructor() + ->getMock(); + } + + public function setAdmin($bool) + { + $stubAuthenticatedUser = $this->getMockBuilder('\User_Adapter') + ->setMethods(array('is_admin','ACL')) + ->disableOriginalConstructor() + ->getMock(); + + $stubAuthenticatedUser->expects($this->any()) + ->method('is_admin') + ->will($this->returnValue($bool)); + + $this->StubbedACL->expects($this->any()) + ->method('has_right_on_base') + ->will($this->returnValue($bool)); + + $stubAuthenticatedUser->expects($this->any()) + ->method('ACL') + ->will($this->returnValue($this->StubbedACL)); + + $stubCore = $this->getMockBuilder('\Alchemy\Phrasea\Core') + ->setMethods(array('getAuthenticatedUser')) + ->getMock(); + + $stubCore->expects($this->any()) + ->method('getAuthenticatedUser') + ->will($this->returnValue($stubAuthenticatedUser)); + + $this->app['phraseanet.core'] = $stubCore; + } + + public function getJson($response) + { + $this->assertTrue($response->isOk()); + $this->assertEquals('application/json', $response->headers->get('Content-Type')); + $content = json_decode($response->getContent()); + $this->assertTrue(is_object($content)); + $this->assertObjectHasAttribute('success', $content, $response->getContent()); + $this->assertObjectHasAttribute('msg', $content, $response->getContent()); + + return $content; + } + + public function checkRedirection($response, $location) + { + $this->assertTrue($response->isRedirect()); +// $this->assertRegexp('/' . str_replace("/", "\/", $location) . '/', $response->headers->get('location')); + $this->assertEquals($location, $response->headers->get('location')); + } + + public function createOneCollection() + { + $collection = \collection::create(array_shift($this->app['phraseanet.appbox']->get_databoxes()), $this->app['phraseanet.appbox'], 'TESTTODELETE', $this->app['phraseanet.core']->getAuthenticatedUser()); + + $this->app['phraseanet.core']->getAuthenticatedUser()->ACL()->update_rights_to_base($collection->get_base_id(), array('canadmin' => 1)); + + return $collection; + } + + + /** + * @covers Alchemy\Phrasea\Controller\Admin\Bas::connect + * @covers Alchemy\Phrasea\Controller\Admin\Bas::getCollection + * @covers Alchemy\Phrasea\Controller\Admin\Bas::call + */ + public function testGetCollection() + { + $this->setAdmin(true); + + $this->client->request('GET', '/bas/' . self::$collection->get_base_id() . '/'); + $this->assertTrue($this->client->getResponse()->isOk()); + } + + /** + * @covers Alchemy\Phrasea\Controller\Admin\Bas::getSuggestedValues + */ + public function testGetSuggestedValues() + { + $this->setAdmin(true); + + $this->client->request('GET', '/bas/' . self::$collection->get_base_id() . '/suggested-values/'); + $this->assertTrue($this->client->getResponse()->isOk()); + } + + /** + * @covers Alchemy\Phrasea\Controller\Admin\Bas::getDetails + */ + public function testInformationsDetails() + { + $this->setAdmin(true); + + $collection = $this->createOneCollection(); + + $file = new \Alchemy\Phrasea\Border\File($this->app['phraseanet.core']['mediavorus']->guess(new \SplFileInfo(__DIR__ . '/../../../../testfiles/test001.CR2')), $collection); + \record_adapter::createFromFile($file); + + $this->client->request('GET', '/bas/' . $collection->get_base_id() . '/informations/details/'); + $this->assertTrue($this->client->getResponse()->isOk()); + + $collection->delete(); + } + + /** + * @covers Alchemy\Phrasea\Controller\Admin\Bas::submitSuggestedValues + * @expectedException \Symfony\Component\HttpKernel\Exception\HttpException + */ + public function testPostSuggestedValuesBadRequest() + { + $this->setAdmin(true); + + $this->client->request('POST', '/bas/' . self::$collection->get_base_id() . '/suggested-values/'); + } + + /** + * @expectedException \Symfony\Component\HttpKernel\Exception\HttpException + * @covers Alchemy\Phrasea\Controller\Admin\Bas::submitSuggestedValues + */ + public function testPostSuggestedValueUnauthorized() + { + $this->setAdmin(false); + + $this->client->request('POST', '/bas/' . self::$collection->get_base_id() . '/suggested-values/', array(), array(), array( + 'HTTP_ACCEPT' => 'application/json', + 'HTTP_X-Requested-With' => 'XMLHttpRequest' + )); + } + + /** + * @covers Alchemy\Phrasea\Controller\Admin\Bas::submitSuggestedValues + */ + public function testPostSuggestedValue() + { + $this->setAdmin(true); + + $this->client->request('POST', '/bas/' . self::$collection->get_base_id() . '/suggested-values/', array( + 'str' => ' 0 aa ' + ), array(), array( + 'HTTP_ACCEPT' => 'application/json', + 'HTTP_X-Requested-With' => 'XMLHttpRequest' + )); + + $json = $this->getJson($this->client->getResponse()); + $this->assertTrue($json->success); + } + + /** + * @covers Alchemy\Phrasea\Controller\Admin\Bas::enable + * @expectedException \Symfony\Component\HttpKernel\Exception\HttpException + */ + public function testPostEnableBadRequest() + { + $this->setAdmin(true); + + $this->client->request('POST', '/bas/' . self::$collection->get_base_id() . '/enable/'); + } + + /** + * @expectedException \Symfony\Component\HttpKernel\Exception\HttpException + * @covers Alchemy\Phrasea\Controller\Admin\Bas::enable + */ + public function testPostEnableUnauthorizedException() + { + $this->setAdmin(false); + + $this->client->request('POST', '/bas/' . self::$collection->get_base_id() . '/enable/'); + } + + /** + * @covers Alchemy\Phrasea\Controller\Admin\Bas::enable + */ + public function testPostEnable() + { + $this->setAdmin(true); + + $this->client->request('POST', '/bas/' . self::$collection->get_base_id() . '/enable/', array(), array(), array( + 'HTTP_ACCEPT' => 'application/json', + 'HTTP_X-Requested-With' => 'XMLHttpRequest' + )); + + $json = $this->getJson($this->client->getResponse()); + $this->assertTrue($json->success); + } + + /** + * @expectedException \Symfony\Component\HttpKernel\Exception\HttpException + * @covers Alchemy\Phrasea\Controller\Admin\Bas::disabled + */ + public function testPostDisabledBadRequest() + { + $this->setAdmin(true); + + $this->client->request('POST', '/bas/' . self::$collection->get_base_id() . '/disabled/'); + } + + /** + * @expectedException \Symfony\Component\HttpKernel\Exception\HttpException + * @covers Alchemy\Phrasea\Controller\Admin\Bas::disabled + */ + public function testPostDisabledUnauthorizedException() + { + $this->setAdmin(false); + + $this->client->request('POST', '/bas/' . self::$collection->get_base_id() . '/disabled/'); + } + + /** + * @covers Alchemy\Phrasea\Controller\Admin\Bas::disabled + */ + public function testPostDisabled() + { + $this->setAdmin(true); + + $this->client->request('POST', '/bas/' . self::$collection->get_base_id() . '/disabled/', array(), array(), array( + 'HTTP_ACCEPT' => 'application/json', + 'HTTP_X-Requested-With' => 'XMLHttpRequest' + )); + + $json = $this->getJson($this->client->getResponse()); + $this->assertTrue($json->success); + } + + /** + * @expectedException \Symfony\Component\HttpKernel\Exception\HttpException + * @covers Alchemy\Phrasea\Controller\Admin\Bas::setOrderAdmins + */ + public function testPostOrderAdminsUnauthorizedException() + { + $this->setAdmin(false); + + $this->client->request('POST', '/bas/' . self::$collection->get_base_id() . '/order/admins/'); + } + + /** + * @covers Alchemy\Phrasea\Controller\Admin\Bas::setOrderAdmins + */ + public function testPostOrderAdmins() + { + $this->setAdmin(true); + + $this->client->request('POST', '/bas/' . self::$collection->get_base_id() . '/order/admins/', array( + 'admins' => array(self::$user_alt1->get_id()) + )); + + $this->checkRedirection($this->client->getResponse(), '/admin/bas/' . self::$collection->get_base_id() . '/?operation=ok'); + } + + /** + * @expectedException \Symfony\Component\HttpKernel\Exception\HttpException + * @covers Alchemy\Phrasea\Controller\Admin\Bas::setPublicationDisplay + */ + public function testPostPublicationDisplayBadRequest() + { + $this->setAdmin(true); + + $this->client->request('POST', '/bas/' . self::$collection->get_base_id() . '/publication/display/'); + } + + /** + * @expectedException \Symfony\Component\HttpKernel\Exception\HttpException + * @covers Alchemy\Phrasea\Controller\Admin\Bas::setPublicationDisplay + */ + public function testPostPublicationDisplayUnauthorizedException() + { + $this->setAdmin(false); + + $this->client->request('POST', '/bas/' . self::$collection->get_base_id() . '/publication/display/'); + } + + /** + * @expectedException \Symfony\Component\HttpKernel\Exception\HttpException + * @covers Alchemy\Phrasea\Controller\Admin\Bas::setPublicationDisplay + */ + public function testPublicationDisplayBadRequestMissingArguments() + { + $this->setAdmin(true); + + $this->client->request('POST', '/bas/' . self::$collection->get_base_id() . '/publication/display/', array(), array(), array( + 'HTTP_ACCEPT' => 'application/json', + 'HTTP_X-Requested-With' => 'XMLHttpRequest' + )); + } + + /** + * @covers Alchemy\Phrasea\Controller\Admin\Bas::setPublicationDisplay + */ + public function testPublicationDisplay() + { + $this->setAdmin(true); + + $this->client->request('POST', '/bas/' . self::$collection->get_base_id() . '/publication/display/', array( + 'pub_wm' => 'wm', + ), array(), array( + 'HTTP_ACCEPT' => 'application/json', + 'HTTP_X-Requested-With' => 'XMLHttpRequest', + )); + + $json = $this->getJson($this->client->getResponse()); + $this->assertTrue($json->success); + } + + /** + * @expectedException \Symfony\Component\HttpKernel\Exception\HttpException + * @covers Alchemy\Phrasea\Controller\Admin\Bas::rename + */ + public function testPostNameBadRequest() + { + $this->setAdmin(true); + + $this->client->request('POST', '/bas/' . self::$collection->get_base_id() . '/rename/'); + } + + /** + * @expectedException \Symfony\Component\HttpKernel\Exception\HttpException + * @covers Alchemy\Phrasea\Controller\Admin\Bas::rename + */ + public function testPostNameUnauthorizedException() + { + $this->setAdmin(false); + + $this->client->request('POST', '/bas/' . self::$collection->get_base_id() . '/rename/'); + } + + /** + * @expectedException \Symfony\Component\HttpKernel\Exception\HttpException + * @covers Alchemy\Phrasea\Controller\Admin\Bas::rename + */ + public function testPostNameBadRequestMissingArguments() + { + $this->setAdmin(true); + + $this->client->request('POST', '/bas/' . self::$collection->get_base_id() . '/rename/', array(), array(), array( + 'HTTP_ACCEPT' => 'application/json', + 'HTTP_X-Requested-With' => 'XMLHttpRequest' + )); + } + + /** + * @covers Alchemy\Phrasea\Controller\Admin\Bas::rename + */ + public function testPostName() + { + $this->setAdmin(true); + + $this->client->request('POST', '/bas/' . self::$collection->get_base_id() . '/rename/', array( + 'name' => 'test2', + ), array(), array( + 'HTTP_ACCEPT' => 'application/json', + 'HTTP_X-Requested-With' => 'XMLHttpRequest', + )); + + $json = $this->getJson($this->client->getResponse()); + $this->assertTrue($json->success); + $this->assertEquals(self::$collection->get_name(), 'test2'); + } + + /** + * @expectedException \Symfony\Component\HttpKernel\Exception\HttpException + * @covers Alchemy\Phrasea\Controller\Admin\Bas::emptyCollection + */ + public function testPostEmptyCollectionBadRequestFormat() + { + $this->setAdmin(true); + + $this->client->request('POST', '/bas/' . self::$collection->get_base_id() . '/empty/'); + } + + /** + * @expectedException \Symfony\Component\HttpKernel\Exception\HttpException + * @covers Alchemy\Phrasea\Controller\Admin\Bas::emptyCollection + */ + public function testPostEmptyCollectionUnauthorizedException() + { + $this->setAdmin(false); + + $this->client->request('POST', '/bas/' . self::$collection->get_base_id() . '/empty/', array(), array(), array( + 'HTTP_ACCEPT' => 'application/json', + 'HTTP_X-Requested-With' => 'XMLHttpRequest', + )); + } + + /** + * @covers Alchemy\Phrasea\Controller\Admin\Bas::emptyCollection + */ + public function testPostEmptyCollection() + { + $this->setAdmin(true); + + $collection = $this->createOneCollection(); + + $file = new \Alchemy\Phrasea\Border\File($this->app['phraseanet.core']['mediavorus']->guess(new \SplFileInfo(__DIR__ . '/../../../../testfiles/test001.CR2')), $collection); + \record_adapter::createFromFile($file); + + if ($collection->get_record_amount() === 0) { + $this->markTestSkipped('No record were added'); + } + + $this->client->request('POST', '/bas/' . $collection->get_base_id() . '/empty/', array(), array(), array( + 'HTTP_ACCEPT' => 'application/json', + 'HTTP_X-Requested-With' => 'XMLHttpRequest', + )); + + $json = $this->getJson($this->client->getResponse()); + $this->assertTrue($json->success); + $this->assertEquals(0, $collection->get_record_amount()); + $collection->delete(); + } + + /** + * @expectedException \Symfony\Component\HttpKernel\Exception\HttpException + * @covers Alchemy\Phrasea\Controller\Admin\Bas::unmount + */ + public function testPostUnmountCollectionBadRequestFormat() + { + $this->setAdmin(true); + + $this->client->request('POST', '/bas/' . self::$collection->get_base_id() . '/unmount/'); + } + + /** + * @expectedException \Symfony\Component\HttpKernel\Exception\HttpException + * @covers Alchemy\Phrasea\Controller\Admin\Bas::unmount + */ + public function testPostUnmountCollectionUnauthorizedException() + { + $this->setAdmin(false); + + $this->client->request('POST', '/bas/' . self::$collection->get_base_id() . '/unmount/', array(), array(), array( + 'HTTP_ACCEPT' => 'application/json', + 'HTTP_X-Requested-With' => 'XMLHttpRequest', + )); + } + + /** + * @covers Alchemy\Phrasea\Controller\Admin\Bas::unmount + */ + public function testPostUnmountCollection() + { + $this->setAdmin(true); + + $collection = $this->createOneCollection(); + + $this->client->request('POST', '/bas/' . $collection->get_base_id() . '/unmount/', array(), array(), array( + 'HTTP_ACCEPT' => 'application/json', + 'HTTP_X-Requested-With' => 'XMLHttpRequest', + )); + + $json = $this->getJson($this->client->getResponse()); + $this->assertTrue($json->success); + + $collection->delete(); + } + + /** + * @expectedException \Symfony\Component\HttpKernel\Exception\HttpException + * @covers Alchemy\Phrasea\Controller\Admin\Bas::setMiniLogo + */ + public function testSetMiniLogoBadRequest() + { + $this->setAdmin(true); + + $this->client->request('POST', '/bas/' . self::$collection->get_base_id() . '/picture/mini-logo/'); + } + + /** + * @expectedException \Symfony\Component\HttpKernel\Exception\HttpException + * @covers Alchemy\Phrasea\Controller\Admin\Bas::setStamp + */ + public function testSetStampBadRequest() + { + $this->setAdmin(true); + + $this->client->request('POST', '/bas/' . self::$collection->get_base_id() . '/picture/stamp-logo/'); + } + + /** + * @expectedException \Symfony\Component\HttpKernel\Exception\HttpException + * @covers Alchemy\Phrasea\Controller\Admin\Bas::setWatermark + */ + public function testSetWatermarkBadRequest() + { + $this->setAdmin(true); + + $this->client->request('POST', '/bas/' . self::$collection->get_base_id() . '/picture/watermark/'); + } + + /** + * @expectedException \Symfony\Component\HttpKernel\Exception\HttpException + * @covers Alchemy\Phrasea\Controller\Admin\Bas::setBanner + */ + public function testSetBannerBadRequest() + { + $this->setAdmin(true); + + $this->client->request('POST', '/bas/' . self::$collection->get_base_id() . '/picture/banner/'); + } + + /** + * @covers Alchemy\Phrasea\Controller\Admin\Bas::setMiniLogo + */ + public function testSetMiniLogo() + { + $this->setAdmin(true); + + $target = tempnam(sys_get_temp_dir(), 'p4logo') . '.jpg'; + $this->app['phraseanet.core']['file-system']->copy(__DIR__ . '/../../../../testfiles/p4logo.jpg', $target); + $files = array( + 'newLogo' => new \Symfony\Component\HttpFoundation\File\UploadedFile($target, 'logo.jpg') + ); + $this->client->request('POST', '/bas/' . self::$collection->get_base_id() . '/picture/mini-logo/', array(), $files); + $this->checkRedirection($this->client->getResponse(), '/admin/bas/' . self::$collection->get_base_id() . '/?operation=ok'); + $this->assertEquals(1, count(\collection::getLogo(self::$collection->get_base_id()))); + } + + /** + * @expectedException \Symfony\Component\HttpKernel\Exception\HttpException + * @covers Alchemy\Phrasea\Controller\Admin\Bas::deleteLogo + */ + public function testDeleteMiniLogoBadRequestFormat() + { + $this->setAdmin(true); + + $this->client->request('DELETE', '/bas/' . self::$collection->get_base_id() . '/picture/mini-logo/'); + } + + /** + * @covers Alchemy\Phrasea\Controller\Admin\Bas::deleteLogo + */ + public function testDeleteMiniLogo() + { + if (count(\collection::getLogo(self::$collection->get_base_id())) === 0) { + $this->markTestSkipped('No logo setted'); + } + + $this->setAdmin(true); + + $this->client->request('DELETE', '/bas/' . self::$collection->get_base_id() . '/picture/mini-logo/', array(), array(), array( + 'HTTP_ACCEPT' => 'application/json', + 'HTTP_X-Requested-With' => 'XMLHttpRequest', + )); + $json = $this->getJson($this->client->getResponse()); + $this->assertTrue($json->success); + /**todo check why file is not deleted */ +// $this->assertEquals(0, count(\collection::getLogo(self::$collection->get_base_id()))); + } + + /** + * @covers Alchemy\Phrasea\Controller\Admin\Bas::setWatermark + */ + public function testSetWm() + { + $this->setAdmin(true); + + $target = tempnam(sys_get_temp_dir(), 'p4logo') . '.jpg'; + $this->app['phraseanet.core']['file-system']->copy(__DIR__ . '/../../../../testfiles/p4logo.jpg', $target); + $files = array( + 'newWm' => new \Symfony\Component\HttpFoundation\File\UploadedFile($target, 'logo.jpg') + ); + $this->client->request('POST', '/bas/' . self::$collection->get_base_id() . '/picture/watermark/', array(), $files); + $this->checkRedirection($this->client->getResponse(), '/admin/bas/' . self::$collection->get_base_id() . '/?operation=ok'); + $this->assertEquals(1, count(\collection::getWatermark(self::$collection->get_base_id()))); + } + + /** + * @expectedException \Symfony\Component\HttpKernel\Exception\HttpException + * @covers Alchemy\Phrasea\Controller\Admin\Bas::deleteWatermark + */ + public function testDeleteWmBadRequestFormat() + { + $this->setAdmin(true); + + $this->client->request('DELETE', '/bas/' . self::$collection->get_base_id() . '/picture/watermark/'); + } + + /** + * @covers Alchemy\Phrasea\Controller\Admin\Bas::deleteWatermark + */ + public function testDeleteWm() + { + if (count(\collection::getWatermark(self::$collection->get_base_id())) === 0) { + $this->markTestSkipped('No watermark setted'); + } + $this->setAdmin(true); + + $this->client->request('DELETE', '/bas/' . self::$collection->get_base_id() . '/picture/watermark/', array(), array(), array( + 'HTTP_ACCEPT' => 'application/json', + 'HTTP_X-Requested-With' => 'XMLHttpRequest', + )); + $json = $this->getJson($this->client->getResponse()); + $this->assertTrue($json->success); + /**todo check why file is not deleted */ +// $this->assertEquals(0, count(\collection::getWatermark(self::$collection->get_base_id()))); + } + + /** + * @covers Alchemy\Phrasea\Controller\Admin\Bas::setStamp + */ + public function testSetStamp() + { + $this->setAdmin(true); + + $target = tempnam(sys_get_temp_dir(), 'p4logo') . '.jpg'; + $this->app['phraseanet.core']['file-system']->copy(__DIR__ . '/../../../../testfiles/p4logo.jpg', $target); + $files = array( + 'newStamp' => new \Symfony\Component\HttpFoundation\File\UploadedFile($target, 'logo.jpg') + ); + $this->client->request('POST', '/bas/' . self::$collection->get_base_id() . '/picture/stamp-logo/', array(), $files); + $this->checkRedirection($this->client->getResponse(), '/admin/bas/' . self::$collection->get_base_id() . '/?operation=ok'); + $this->assertEquals(1, count(\collection::getStamp(self::$collection->get_base_id()))); + } + + /** + * @expectedException \Symfony\Component\HttpKernel\Exception\HttpException + * @covers Alchemy\Phrasea\Controller\Admin\Bas::deleteStamp + */ + public function testDeleteStampBadRequestFormat() + { + $this->setAdmin(true); + + $this->client->request('DELETE', '/bas/' . self::$collection->get_base_id() . '/picture/stamp-logo/'); + } + + /** + * @covers Alchemy\Phrasea\Controller\Admin\Bas::deleteStamp + */ + public function testDeleteStamp() + { + if (count(\collection::getStamp(self::$collection->get_base_id())) === 0) { + $this->markTestSkipped('No stamp setted'); + } + + $this->setAdmin(true); + + $this->client->request('DELETE', '/bas/' . self::$collection->get_base_id() . '/picture/stamp-logo/', array(), array(), array( + 'HTTP_ACCEPT' => 'application/json', + 'HTTP_X-Requested-With' => 'XMLHttpRequest', + )); + + $json = $this->getJson($this->client->getResponse()); + $this->assertTrue($json->success); + /**todo check why file is not deleted */ +// $this->assertEquals(0, count(\collection::getStamp(self::$collection->get_base_id()))); + } + + /** + * @covers Alchemy\Phrasea\Controller\Admin\Bas::setBanner + */ + public function testSetBanner() + { + $this->setAdmin(true); + + $target = tempnam(sys_get_temp_dir(), 'p4logo') . '.jpg'; + $this->app['phraseanet.core']['file-system']->copy(__DIR__ . '/../../../../testfiles/p4logo.jpg', $target); + $files = array( + 'newBanner' => new \Symfony\Component\HttpFoundation\File\UploadedFile($target, 'logo.jpg') + ); + $this->client->request('POST', '/bas/' . self::$collection->get_base_id() . '/picture/banner/', array(), $files); + $this->checkRedirection($this->client->getResponse(), '/admin/bas/' . self::$collection->get_base_id() . '/?operation=ok'); + $this->assertEquals(1, count(\collection::getPresentation(self::$collection->get_base_id()))); + } + + /** + * @expectedException \Symfony\Component\HttpKernel\Exception\HttpException + * @covers Alchemy\Phrasea\Controller\Admin\Bas::deleteBanner + */ + public function testDeleteBannerBadRequestFormat() + { + $this->setAdmin(true); + + $this->client->request('DELETE', '/bas/' . self::$collection->get_base_id() . '/picture/banner/'); + } + + /** + * @covers Alchemy\Phrasea\Controller\Admin\Bas::deleteBanner + */ + public function testDeleteBanner() + { + if (count(\collection::getPresentation(self::$collection->get_base_id())) === 0) { + $this->markTestSkipped('No Banner setted'); + } + + $this->setAdmin(true); + + $this->client->request('DELETE', '/bas/' . self::$collection->get_base_id() . '/picture/banner/', array(), array(), array( + 'HTTP_ACCEPT' => 'application/json', + 'HTTP_X-Requested-With' => 'XMLHttpRequest', + )); + + $json = $this->getJson($this->client->getResponse()); + $this->assertTrue($json->success); + /**todo check why file is not deleted */ +// $this->assertEquals(0, count(\collection::getPresentation(self::$collection->get_base_id()))); + } + + + /** + * @expectedException \Symfony\Component\HttpKernel\Exception\HttpException + * @covers Alchemy\Phrasea\Controller\Admin\Bas::getCollection + */ + public function testGetCollectionUnauthorizedException() + { + $this->setAdmin(false); + + $this->client->request('GET', '/bas/' . self::$collection->get_base_id() . '/'); + } + + /** + * @expectedException \Symfony\Component\HttpKernel\Exception\HttpException + * @covers Alchemy\Phrasea\Controller\Admin\Bas::getSuggestedValues + */ + public function testGetSuggestedValuesUnauthorizedException() + { + $this->setAdmin(false); + + $this->client->request('GET', '/bas/' . self::$collection->get_base_id() . '/suggested-values/'); + } + + /** + * @expectedException \Symfony\Component\HttpKernel\Exception\HttpException + * @covers Alchemy\Phrasea\Controller\Admin\Bas::getDetails + */ + public function testInformationsDetailsUnauthorizedException() + { + $this->setAdmin(false); + + $this->client->request('GET', '/bas/' . self::$collection->get_base_id() . '/informations/details/'); + } + + /** + * @expectedException \Symfony\Component\HttpKernel\Exception\HttpException + * @covers Alchemy\Phrasea\Controller\Admin\Bas::delete + */ + public function testDeleteCollectionBadRequestFormat() + { + $this->setAdmin(false); + + $this->client->request('DELETE', '/bas/' . self::$collection->get_base_id() . '/'); + } + + /** + * @expectedException \Symfony\Component\HttpKernel\Exception\HttpException + * @covers Alchemy\Phrasea\Controller\Admin\Bas::delete + */ + public function testDeleteCollectionUnauthorized() + { + $this->setAdmin(false); + + $this->client->request('DELETE', '/bas/' . self::$collection->get_base_id() . '/'); + } + + /** + * @covers Alchemy\Phrasea\Controller\Admin\Bas::delete + */ + public function testDeleteCollection() + { + $this->setAdmin(true); + + $collection = $this->createOneCollection(); + + $this->client->request('DELETE', '/bas/' . $collection->get_base_id() . '/',array(), array(), array( + 'HTTP_ACCEPT' => 'application/json', + 'HTTP_X-Requested-With' => 'XMLHttpRequest', + )); + + $json = $this->getJson($this->client->getResponse()); + $this->assertTrue($json->success); + try { + \collection::get_from_base_id($collection->get_base_id()); + $this->fail('Collection not deleted'); + } catch (\Exception $e) { + + } + } +} diff --git a/tests/Alchemy/Phrasea/Controller/Admin/ConnectedUserTest.php b/tests/Alchemy/Phrasea/Controller/Admin/ConnectedUserTest.php new file mode 100644 index 0000000000..78465eedab --- /dev/null +++ b/tests/Alchemy/Phrasea/Controller/Admin/ConnectedUserTest.php @@ -0,0 +1,30 @@ +client = $this->createClient(); + } + + public function testgetSlash() + { + $this->client->request('GET', '/connected-users/'); + $this->assertTrue($this->client->getResponse()->isOk()); + } +} diff --git a/tests/Alchemy/Phrasea/Controller/Admin/DashboardTest.php b/tests/Alchemy/Phrasea/Controller/Admin/DashboardTest.php deleted file mode 100644 index 9c5876c835..0000000000 --- a/tests/Alchemy/Phrasea/Controller/Admin/DashboardTest.php +++ /dev/null @@ -1,185 +0,0 @@ -client = $this->createClient(); - } - - /** - * @expectedException Symfony\Component\HttpKernel\Exception\HttpException - */ - public function testRouteDashboardUnauthorized() - { - $stubAuthenticatedUser = $this->getMockBuilder('\User_Adapter') - ->setMethods(array('is_admin')) - ->disableOriginalConstructor() - ->getMock(); - - $stubAuthenticatedUser->expects($this->any()) - ->method('is_admin') - ->will($this->returnValue(false)); - - $stubCore = $this->getMockBuilder('\Alchemy\Phrasea\Core') - ->setMethods(array('getAuthenticatedUser')) - ->getMock(); - - $stubCore->expects($this->any()) - ->method('getAuthenticatedUser') - ->will($this->returnValue($stubAuthenticatedUser)); - - $this->app['phraseanet.core'] = $stubCore; - - $this->client->request('GET', '/dashboard/'); - } - - public function testRouteDashboard() - { - $stubAuthenticatedUser = $this->getMockBuilder('\User_Adapter') - ->setMethods(array('is_admin')) - ->disableOriginalConstructor() - ->getMock(); - - $stubAuthenticatedUser->expects($this->any()) - ->method('is_admin') - ->will($this->returnValue(true)); - - $stubCore = $this->getMockBuilder('\Alchemy\Phrasea\Core') - ->setMethods(array('getAuthenticatedUser')) - ->getMock(); - - $stubCore->expects($this->any()) - ->method('getAuthenticatedUser') - ->will($this->returnValue($stubAuthenticatedUser)); - - $this->app['phraseanet.core'] = $stubCore; - - $this->client->request('GET', '/dashboard/'); - - $this->assertTrue($this->client->getResponse()->isOk()); - } - - public function testFlushCache() - { - $stubAuthenticatedUser = $this->getMockBuilder('\User_Adapter') - ->setMethods(array('is_admin')) - ->disableOriginalConstructor() - ->getMock(); - - $stubAuthenticatedUser->expects($this->any()) - ->method('is_admin') - ->will($this->returnValue(true)); - - $stubCore = $this->getMockBuilder('\Alchemy\Phrasea\Core') - ->setMethods(array('getAuthenticatedUser')) - ->getMock(); - - $stubCore->expects($this->any()) - ->method('getAuthenticatedUser') - ->will($this->returnValue($stubAuthenticatedUser)); - - $this->app['phraseanet.core'] = $stubCore; - - $this->client->request('POST', '/dashboard/flush-cache/'); - - $this->assertTrue($this->client->getResponse()->isRedirect()); - $this->assertRegexp('/flush_cache=ok/', $this->client->getResponse()->headers->get('location')); - } - - public function testSendMailTest() - { - $stubAuthenticatedUser = $this->getMockBuilder('\User_Adapter') - ->setMethods(array('is_admin')) - ->disableOriginalConstructor() - ->getMock(); - - $stubAuthenticatedUser->expects($this->any()) - ->method('is_admin') - ->will($this->returnValue(true)); - - $stubCore = $this->getMockBuilder('\Alchemy\Phrasea\Core') - ->setMethods(array('getAuthenticatedUser')) - ->getMock(); - - $stubCore->expects($this->any()) - ->method('getAuthenticatedUser') - ->will($this->returnValue($stubAuthenticatedUser)); - - $this->app['phraseanet.core'] = $stubCore; - - $this->client->request('POST', '/dashboard/send-mail-test/', array( - 'email' => self::$user->get_email() - )); - - $this->assertTrue($this->client->getResponse()->isRedirect()); - $this->assertRegexp('/email=/', $this->client->getResponse()->headers->get('location')); - } - - public function testResetAdminRights() - { - $stubAuthenticatedUser = $this->getMockBuilder('\User_Adapter') - ->setMethods(array('is_admin')) - ->disableOriginalConstructor() - ->getMock(); - - $stubAuthenticatedUser->expects($this->any()) - ->method('is_admin') - ->will($this->returnValue(true)); - - $stubCore = $this->getMockBuilder('\Alchemy\Phrasea\Core') - ->setMethods(array('getAuthenticatedUser')) - ->getMock(); - - $stubCore->expects($this->any()) - ->method('getAuthenticatedUser') - ->will($this->returnValue($stubAuthenticatedUser)); - - $this->app['phraseanet.core'] = $stubCore; - - $this->client->request('POST', '/dashboard/reset-admin-rights/'); - - $this->assertTrue($this->client->getResponse()->isRedirect()); - } - - public function testAddAdmins() - { - $stubAuthenticatedUser = $this->getMockBuilder('\User_Adapter') - ->setMethods(array('is_admin')) - ->disableOriginalConstructor() - ->getMock(); - - $stubAuthenticatedUser->expects($this->any()) - ->method('is_admin') - ->will($this->returnValue(true)); - - $stubCore = $this->getMockBuilder('\Alchemy\Phrasea\Core') - ->setMethods(array('getAuthenticatedUser')) - ->getMock(); - - $stubCore->expects($this->any()) - ->method('getAuthenticatedUser') - ->will($this->returnValue($stubAuthenticatedUser)); - - $this->app['phraseanet.core'] = $stubCore; - - $this->client->request('POST', '/dashboard/new/'); - - $this->assertTrue($this->client->getResponse()->isRedirect()); - } -} diff --git a/tests/Alchemy/Phrasea/Controller/Admin/DatabaseTest.php b/tests/Alchemy/Phrasea/Controller/Admin/DatabaseTest.php new file mode 100644 index 0000000000..c02e774fc5 --- /dev/null +++ b/tests/Alchemy/Phrasea/Controller/Admin/DatabaseTest.php @@ -0,0 +1,446 @@ +client = $this->createClient(); + $this->StubbedACL = $this->getMockBuilder('\ACL') + ->disableOriginalConstructor() + ->getMock(); + } + + public function setAdmin($bool) + { + $stubAuthenticatedUser = $this->getMockBuilder('\User_Adapter') + ->setMethods(array('is_admin','ACL')) + ->disableOriginalConstructor() + ->getMock(); + + $stubAuthenticatedUser->expects($this->any()) + ->method('is_admin') + ->will($this->returnValue($bool)); + + $this->StubbedACL->expects($this->any()) + ->method('has_right_on_base') + ->will($this->returnValue($bool)); + + $stubAuthenticatedUser->expects($this->any()) + ->method('ACL') + ->will($this->returnValue($this->StubbedACL)); + + $stubCore = $this->getMockBuilder('\Alchemy\Phrasea\Core') + ->setMethods(array('getAuthenticatedUser')) + ->getMock(); + + $stubCore->expects($this->any()) + ->method('getAuthenticatedUser') + ->will($this->returnValue($stubAuthenticatedUser)); + + $this->app['phraseanet.core'] = $stubCore; + } + + /** + * @covers \Alchemy\Phrasea\Controller\Admin\Database::getDatabase + * @covers \Alchemy\Phrasea\Controller\Admin\Database::connect + * @covers \Alchemy\Phrasea\Controller\Admin\Database::call + */ + public function testGetDatabox() + { + $this->setAdmin(true); + + $this->client->request('GET', '/database/' . self::$collection->get_sbas_id() . '/'); + $this->assertTrue($this->client->getResponse()->isOk()); + } + + /** + * @covers \Alchemy\Phrasea\Controller\Admin\Database::getReorder + */ + public function testGetCollectionOrder() + { + $this->setAdmin(true); + + $this->client->request('GET', '/database/' . self::$collection->get_sbas_id() . '/collections/order/'); + $this->assertTrue($this->client->getResponse()->isOk()); + } + + /** + * @covers \Alchemy\Phrasea\Controller\Admin\Database::getDatabaseCGU + * @expectedException \Symfony\Component\HttpKernel\Exception\HttpException + */ + public function testGetCGUHasNoRights() + { + $this->StubbedACL->expects($this->once()) + ->method('has_right_on_sbas') + ->with($this->equalTo(self::$collection->get_sbas_id()), 'bas_modify_struct') + ->will($this->returnValue(false)); + + $this->setAdmin(true); + + $this->client->request('GET', '/database/' . self::$collection->get_sbas_id() . '/cgus/'); + } + + /** + * @covers \Alchemy\Phrasea\Controller\Admin\Database::getDatabaseCGU + * @expectedException \Symfony\Component\HttpKernel\Exception\HttpException + */ + public function testGetCGU() + { + $this->setAdmin(true); + + $this->client->request('GET', '/database/' . self::$collection->get_sbas_id() . '/cgus/'); + $this->assertTrue($this->client->getResponse()->isOk()); + } + + /** + * @expectedException \Symfony\Component\HttpKernel\Exception\HttpException + * @covers \Alchemy\Phrasea\Controller\Admin\Database::progressBarInfos + */ + public function testGetInformationDocumentBadRequest() + { + $this->setAdmin(true); + + $this->client->request('GET', '/database/' . self::$collection->get_sbas_id() . '/informations/documents/'); + $this->assertTrue($this->client->getResponse()->isOk()); + } + + /** + * @covers \Alchemy\Phrasea\Controller\Admin\Database::progressBarInfos + */ + public function testGetInformationDocument() + { + $this->setAdmin(true); + + $this->client->request('GET', '/database/' . self::$collection->get_sbas_id() . '/informations/documents/', array(), array(), array( + 'HTTP_ACCEPT' => 'application/json', + 'HTTP_X-Requested-With' => 'XMLHttpRequest' + )); + + $this->assertTrue($this->client->getResponse()->isOk()); + } + + /** + * @covers \Alchemy\Phrasea\Controller\Admin\Database::getDetails + */ + public function testGetInformationDetails() + { + $this->setAdmin(true); + + $this->client->request('GET', '/database/' . self::$collection->get_sbas_id() . '/informations/details/'); + $this->assertTrue($this->client->getResponse()->isOk()); + } + + /** + * @covers \Alchemy\Phrasea\Controller\Admin\Database::getNewCollection + */ + public function testGetNewCollection() + { + $this->setAdmin(true); + + $this->client->request('GET', '/database/' . self::$collection->get_sbas_id() . '/collection/'); + $this->assertTrue($this->client->getResponse()->isOk()); + } + + /** + * @expectedException \Symfony\Component\HttpKernel\Exception\HttpException + * @covers \Alchemy\Phrasea\Controller\Admin\Database::getDatabase + */ + public function testGetDataboxUnauthorizedException() + { + $this->setAdmin(false); + + $this->client->request('GET', '/database/' . self::$collection->get_sbas_id() . '/'); + } + + /** + * @expectedException \Symfony\Component\HttpKernel\Exception\HttpException + * @covers \Alchemy\Phrasea\Controller\Admin\Database::getReorder + */ + public function testGetCollectionOrderUnauthorizedException() + { + $this->setAdmin(false); + + $this->client->request('GET', '/database/' . self::$collection->get_sbas_id() . '/collections/order/'); + } + + /** + * @expectedException \Symfony\Component\HttpKernel\Exception\HttpException + * @covers \Alchemy\Phrasea\Controller\Admin\Database::getDatabaseCGU + */ + public function testGetCGUUnauthorizedException() + { + $this->setAdmin(false); + + $this->client->request('GET', '/database/' . self::$collection->get_sbas_id() . '/cgus/'); + } + + /** + * @expectedException \Symfony\Component\HttpKernel\Exception\HttpException + * @covers \Alchemy\Phrasea\Controller\Admin\Database::getDetails + * + */ + public function testGetInformationDocumentUnauthorizedException() + { + $this->setAdmin(false); + + $this->client->request('GET', '/database/' . self::$collection->get_sbas_id() . '/informations/documents/', array(), array(), array( + 'HTTP_ACCEPT' => 'application/json', + 'HTTP_X-Requested-With' => 'XMLHttpRequest' + )); + } + + /** + * @expectedException \Symfony\Component\HttpKernel\Exception\HttpException + * @covers \Alchemy\Phrasea\Controller\Admin\Database::progressBarInfos + */ + public function testGetInformationDetailsUnauthorizedException() + { + $this->setAdmin(false); + + $this->client->request('GET', '/database/' . self::$collection->get_sbas_id() . '/informations/details/'); + } + + /** + * @expectedException \Symfony\Component\HttpKernel\Exception\HttpException + * @covers \Alchemy\Phrasea\Controller\Admin\Database::getNewCollection + */ + public function testGetNewCollectionUnauthorizedException() + { + $this->setAdmin(false); + + $this->client->request('GET', '/database/' . self::$collection->get_sbas_id() . '/collection/'); + } + + /** + * @expectedException \Symfony\Component\HttpKernel\Exception\HttpException + * @covers \Alchemy\Phrasea\Controller\Admin\Database::reindex + */ + public function testPostReindexBadRequestFormat() + { + $this->setAdmin(true); + + $this->client->request('POST', '/database/' . self::$collection->get_sbas_id() . '/reindex/'); + } + + /** + * @covers \Alchemy\Phrasea\Controller\Admin\Database::reindex + */ + public function testPostReindex() + { + $this->setAdmin(true); + + $this->client->request('POST', '/database/' . self::$collection->get_sbas_id() . '/reindex/', array(), array(), array( + 'HTTP_ACCEPT' => 'application/json', + 'HTTP_X-Requested-With' => 'XMLHttpRequest' + )); + $response = $this->client->getResponse(); + $this->assertTrue($response->isOk()); + $this->assertEquals('application/json', $response->headers->get('Content-Type')); + $content = json_decode($response->getContent()); + $this->assertTrue(is_object($content)); + $this->assertObjectHasAttribute('sbas_id', $content, $response->getContent()); + } + + /** + * @expectedException \Symfony\Component\HttpKernel\Exception\HttpException + * @covers \Alchemy\Phrasea\Controller\Admin\Database::setIndexable + */ + public function testPostIndexableBadRequestFormat() + { + $this->setAdmin(true); + + $this->client->request('POST', '/database/' . self::$collection->get_sbas_id() . '/reindex/'); + } + + /** + * @covers \Alchemy\Phrasea\Controller\Admin\Database::setIndexable + */ + public function testPostIndexable() + { + $this->setAdmin(true); + + $this->client->request('POST', '/database/' . self::$collection->get_sbas_id() . '/indexable/', array( + 'indexable' => 1 + ), array(), array( + 'HTTP_ACCEPT' => 'application/json', + 'HTTP_X-Requested-With' => 'XMLHttpRequest' + )); + + $response = $this->client->getResponse(); + $this->assertTrue($response->isOk()); + $this->assertEquals('application/json', $response->headers->get('Content-Type')); + $content = json_decode($response->getContent()); + $this->assertTrue(is_object($content)); + $this->assertObjectHasAttribute('sbas_id', $content, $response->getContent()); + + $this->assertTrue( ! ! $this->app['phraseanet.appbox']->is_databox_indexable(new \databox(self::$collection->get_sbas_id()))); + } + + /** + * @expectedException \Symfony\Component\HttpKernel\Exception\HttpException + * @covers \Alchemy\Phrasea\Controller\Admin\Database::clearLogs + */ + public function testPostClearLogBadRequestFormat() + { + $this->setAdmin(true); + + $this->client->request('POST', '/database/' . self::$collection->get_sbas_id() . '/clear-logs/'); + } + + /** + * @covers \Alchemy\Phrasea\Controller\Admin\Database::clearLogs + */ + public function testPostClearLogs() + { + $this->setAdmin(true); + + $this->client->request('POST', '/database/' . self::$collection->get_sbas_id() . '/clear-logs/', array(), array(), array( + 'HTTP_ACCEPT' => 'application/json', + 'HTTP_X-Requested-With' => 'XMLHttpRequest' + )); + + $response = $this->client->getResponse(); + $this->assertTrue($response->isOk()); + $this->assertEquals('application/json', $response->headers->get('Content-Type')); + $content = json_decode($response->getContent()); + $this->assertTrue(is_object($content)); + $this->assertObjectHasAttribute('sbas_id', $content, $response->getContent()); + } + + /** + * @expectedException \Symfony\Component\HttpKernel\Exception\HttpException + * @covers \Alchemy\Phrasea\Controller\Admin\Database::changeViewName + */ + public function testChangeViewBadRequestFormat() + { + $this->setAdmin(true); + + $this->client->request('POST', '/database/' . self::$collection->get_sbas_id() . '/view-name/'); + } + + /** + * @expectedException \Symfony\Component\HttpKernel\Exception\HttpException + * @covers \Alchemy\Phrasea\Controller\Admin\Database::changeViewName + */ + public function testPostViewNameBadRequestArguments() + { + $this->setAdmin(true); + + $this->client->request('POST', '/database/' . self::$collection->get_sbas_id() . '/view-name/', array(), array(), array( + 'HTTP_ACCEPT' => 'application/json', + 'HTTP_X-Requested-With' => 'XMLHttpRequest' + )); + } + /** + * @covers \Alchemy\Phrasea\Controller\Admin\Database::changeViewName + */ + public function testPostViewName() + { + $this->setAdmin(true); + + $this->client->request('POST', '/database/' . self::$collection->get_sbas_id() . '/view-name/', array( + 'viewname' => 'salut' + ), array(), array( + 'HTTP_ACCEPT' => 'application/json', + 'HTTP_X-Requested-With' => 'XMLHttpRequest' + )); + + $response = $this->client->getResponse(); + $this->assertTrue($response->isOk()); + $this->assertEquals('application/json', $response->headers->get('Content-Type')); + $content = json_decode($response->getContent()); + $this->assertTrue(is_object($content)); + $this->assertObjectHasAttribute('sbas_id', $content, $response->getContent()); + + $databox = new \databox(self::$collection->get_sbas_id()); + $this->assertEquals('salut', $databox->get_viewname()); + } + + /** + * @covers \Alchemy\Phrasea\Controller\Admin\Database::createDatabase + */ + public function testCreateDatabaseEmpty() + { + $this->setAdmin(true); + + $this->client->request('POST', '/database/', array( + 'new_dbname' => '' + )); + + $response = $this->client->getResponse(); + $this->assertTrue($response->isRedirect()); + $this->assertEquals('/admin/databases/?error=no-empty', $response->headers->get('location')); + } + + /** + * @covers \Alchemy\Phrasea\Controller\Admin\Database::createDatabase + */ + public function testCreateDatabaseSpecialChar() + { + $this->setAdmin(true); + + $this->client->request('POST', '/database/', array( + 'new_dbname' => 'ééààèè' + )); + + $response = $this->client->getResponse(); + $this->assertTrue($response->isRedirect()); + $this->assertEquals('/admin/databases/?error=special-chars', $response->headers->get('location')); + } + + /** + * @covers \Alchemy\Phrasea\Controller\Admin\Database::createDatabase + */ + public function testCreateDatabase() + { +// $this->setAdmin(true); +// +// $dbName = 'unit_test_db'; +// +// $conn = $this->app['phraseanet.appbox']->get_connection(); +// +// try { +// $stmt = $conn->prepare( 'CREATE DATABASE `' . $dbName . '` +// CHARACTER SET utf8 COLLATE utf8_unicode_ci'); +// $stmt->execute(); +// $stmt->closeCursor(); +// } catch (\Exception $e) { +// $this->markTestSkipped('Could not create Databox'); +// } +// +// $this->client->request('POST', '/database/', array( +// 'new_dbname' => $dbName, +// 'new_data_template' => 'fr-simple', +// )); +// +// $response = $this->client->getResponse(); +// $this->assertTrue($response->isRedirect()); +// $this->assertRegexp('/\/admin\/databases\/?success=base-ok/', $response->headers->get('location')); +// +// try { +// $stmt = $conn->prepare( 'DROP DATABASE ' . $dbName); +// $stmt->execute(); +// $stmt->closeCursor(); +// } catch (\Exception $e) { +// +// } +// +// unset($conn); + } +} diff --git a/tests/Alchemy/Phrasea/Controller/Admin/DatabasesTest.php b/tests/Alchemy/Phrasea/Controller/Admin/DatabasesTest.php new file mode 100644 index 0000000000..6f7ae986a7 --- /dev/null +++ b/tests/Alchemy/Phrasea/Controller/Admin/DatabasesTest.php @@ -0,0 +1,80 @@ +client = $this->createClient(); + $this->StubbedACL = $this->getMockBuilder('\ACL') + ->disableOriginalConstructor() + ->getMock(); + } + + public function setAdmin($bool) + { + $stubAuthenticatedUser = $this->getMockBuilder('\User_Adapter') + ->setMethods(array('is_admin', 'ACL')) + ->disableOriginalConstructor() + ->getMock(); + + $stubAuthenticatedUser->expects($this->any()) + ->method('is_admin') + ->will($this->returnValue($bool)); + + $this->StubbedACL->expects($this->any()) + ->method('has_right_on_base') + ->will($this->returnValue($bool)); + + $stubAuthenticatedUser->expects($this->any()) + ->method('ACL') + ->will($this->returnValue($this->StubbedACL)); + + $stubCore = $this->getMockBuilder('\Alchemy\Phrasea\Core') + ->setMethods(array('getAuthenticatedUser')) + ->getMock(); + + $stubCore->expects($this->any()) + ->method('getAuthenticatedUser') + ->will($this->returnValue($stubAuthenticatedUser)); + + $this->app['phraseanet.core'] = $stubCore; + } + + public function testGetSlash() + { + $this->StubbedACL->expects($this->any()) + ->method('get_granted_sbas') + ->will($this->returnValue(array(self::$collection->get_sbas_id()))); + + $this->setAdmin(true); + + $this->client->request('GET', '/databases/'); + $this->assertTrue($this->client->getResponse()->isOk()); + } + + /** + * @expectedException \Symfony\Component\HttpKernel\Exception\HttpException + */ + public function testGetSlashUnauthorizedException() + { + $this->setAdmin(false); + + $this->client->request('GET', '/databases/'); + } +} diff --git a/tests/Alchemy/Phrasea/Controller/Admin/DescriptionTest.php b/tests/Alchemy/Phrasea/Controller/Admin/DescriptionTest.php index 9e5fac2c69..b7c6e06353 100644 --- a/tests/Alchemy/Phrasea/Controller/Admin/DescriptionTest.php +++ b/tests/Alchemy/Phrasea/Controller/Admin/DescriptionTest.php @@ -198,7 +198,7 @@ class DescriptionTest extends \PhraseanetWebTestCaseAuthenticatedAbstract $appbox = $this->app['phraseanet.appbox']; $session = $appbox->get_session(); - $auth = new Session_Authentication_None(self::$user_alt1); + $auth = new Session_Authentication_None(\User_Adapter::getInstance(\User_Adapter::get_usr_id_from_login('invite'), $appbox)); $session->authenticate($auth); $databox = array_shift($appbox->get_databoxes()); @@ -231,7 +231,7 @@ class DescriptionTest extends \PhraseanetWebTestCaseAuthenticatedAbstract $appbox = $this->app['phraseanet.appbox']; $session = $appbox->get_session(); - $auth = new Session_Authentication_None(self::$user_alt1); + $auth = new Session_Authentication_None(\User_Adapter::getInstance(\User_Adapter::get_usr_id_from_login('invite'), $appbox)); $session->authenticate($auth); $databox = array_shift($appbox->get_databoxes()); diff --git a/tests/Alchemy/Phrasea/Controller/Admin/SetupTest.php b/tests/Alchemy/Phrasea/Controller/Admin/SetupTest.php new file mode 100644 index 0000000000..894055feb6 --- /dev/null +++ b/tests/Alchemy/Phrasea/Controller/Admin/SetupTest.php @@ -0,0 +1,77 @@ +client = $this->createClient(); + $this->StubbedACL = $this->getMockBuilder('\ACL') + ->disableOriginalConstructor() + ->getMock(); + } + + public function setAdmin($bool) + { + $stubAuthenticatedUser = $this->getMockBuilder('\User_Adapter') + ->setMethods(array('is_admin','ACL')) + ->disableOriginalConstructor() + ->getMock(); + + $stubAuthenticatedUser->expects($this->any()) + ->method('is_admin') + ->will($this->returnValue($bool)); + + $this->StubbedACL->expects($this->any()) + ->method('has_right_on_base') + ->will($this->returnValue($bool)); + + $stubAuthenticatedUser->expects($this->any()) + ->method('ACL') + ->will($this->returnValue($this->StubbedACL)); + + $stubCore = $this->getMockBuilder('\Alchemy\Phrasea\Core') + ->setMethods(array('getAuthenticatedUser')) + ->getMock(); + + $stubCore->expects($this->any()) + ->method('getAuthenticatedUser') + ->will($this->returnValue($stubAuthenticatedUser)); + + $this->app['phraseanet.core'] = $stubCore; + } + + public function testGetSlash() + { + $this->setAdmin(true); + + $this->client->request('GET', '/setup/'); + $this->assertTrue($this->client->getResponse()->isOk()); + } + + /** + * @expectedException \Symfony\Component\HttpKernel\Exception\HttpException + */ + public function testGetSlashUnauthorizedException() + { + $this->setAdmin(false); + + $this->client->request('GET', '/setup/'); + $this->assertTrue($this->client->getResponse()->isOk()); + } +} diff --git a/tests/Alchemy/Phrasea/Controller/Admin/SphinxTest.php b/tests/Alchemy/Phrasea/Controller/Admin/SphinxTest.php new file mode 100644 index 0000000000..389097e912 --- /dev/null +++ b/tests/Alchemy/Phrasea/Controller/Admin/SphinxTest.php @@ -0,0 +1,77 @@ +client = $this->createClient(); + $this->StubbedACL = $this->getMockBuilder('\ACL') + ->disableOriginalConstructor() + ->getMock(); + } + + public function setAdmin($bool) + { + $stubAuthenticatedUser = $this->getMockBuilder('\User_Adapter') + ->setMethods(array('is_admin','ACL')) + ->disableOriginalConstructor() + ->getMock(); + + $stubAuthenticatedUser->expects($this->any()) + ->method('is_admin') + ->will($this->returnValue($bool)); + + $this->StubbedACL->expects($this->any()) + ->method('has_right_on_base') + ->will($this->returnValue($bool)); + + $stubAuthenticatedUser->expects($this->any()) + ->method('ACL') + ->will($this->returnValue($this->StubbedACL)); + + $stubCore = $this->getMockBuilder('\Alchemy\Phrasea\Core') + ->setMethods(array('getAuthenticatedUser')) + ->getMock(); + + $stubCore->expects($this->any()) + ->method('getAuthenticatedUser') + ->will($this->returnValue($stubAuthenticatedUser)); + + $this->app['phraseanet.core'] = $stubCore; + } + + public function testGetConfiguration() + { + $this->setAdmin(true); + + $this->client->request('GET', '/sphinx/configuration/'); + $this->assertTrue($this->client->getResponse()->isOk()); + } + + /** + * @expectedException \Symfony\Component\HttpKernel\Exception\HttpException + */ + public function testGetConfigurationUnauthorizedException() + { + $this->setAdmin(false); + + $this->client->request('GET', '/sphinx/configuration/'); + $this->assertTrue($this->client->getResponse()->isOk()); + } +} diff --git a/tests/Alchemy/Phrasea/Controller/Admin/SubdefsTest.php b/tests/Alchemy/Phrasea/Controller/Admin/SubdefsTest.php index d7cda667b7..bc6b565b97 100644 --- a/tests/Alchemy/Phrasea/Controller/Admin/SubdefsTest.php +++ b/tests/Alchemy/Phrasea/Controller/Admin/SubdefsTest.php @@ -34,14 +34,14 @@ class ControllerSubdefsTest extends \PhraseanetWebTestCaseAuthenticatedAbstract $this->assertTrue($this->client->getResponse()->isOk()); } - public function getName() + public function getSubdefName() { return 'testname' . time() . mt_rand(10000, 99999); } public function testPostRouteAddSubdef() { - $name = $this->getName(); + $name = $this->getSubdefName(); $this->client->request("POST", "/subdefs/" . $this->databox->get_sbas_id() . "/", array('add_subdef' => array( 'class' => 'thumbnail', 'name' => $name, @@ -56,7 +56,7 @@ class ControllerSubdefsTest extends \PhraseanetWebTestCaseAuthenticatedAbstract public function testPostRouteDeleteSubdef() { $subdefs = $this->databox->get_subdef_structure(); - $name = $this->getName(); + $name = $this->getSubdefName(); $subdefs->add_subdef("image", $name, "thumbnail"); $this->client->request("POST", "/subdefs/" . $this->databox->get_sbas_id() . "/", array('delete_subdef' => 'image_' . $name)); $this->assertTrue($this->client->getResponse()->isRedirect()); @@ -71,7 +71,7 @@ class ControllerSubdefsTest extends \PhraseanetWebTestCaseAuthenticatedAbstract public function testPostRouteAddSubdefWithNoParams() { $subdefs = $this->databox->get_subdef_structure(); - $name = $this->getName(); + $name = $this->getSubdefName(); $subdefs->add_subdef("image", $name, "thumbnail"); $this->client->request("POST", "/subdefs/" . $this->databox->get_sbas_id() . "/" , array('subdefs' => array( diff --git a/www/admin/collection.php b/www/admin/collection.php deleted file mode 100644 index 5b6c510e98..0000000000 --- a/www/admin/collection.php +++ /dev/null @@ -1,725 +0,0 @@ -get_session(); -$registry = $appbox->get_registry(); - -$request = http_request::getInstance(); -$parm = $request->get_parms("srt", "ord", "act", "p0", "p1", "p2", "sta", 'admins', 'pub_wm'); - -$usr_id = $session->get_usr_id(); -$base_id = (int) $parm['p1']; - -$ACL = User_Adapter::getInstance($usr_id, $appbox)->ACL(); - -if ( ! $ACL->has_access_to_base($base_id)) { - phrasea::headers(403); -} - -$collection = collection::get_from_base_id($parm['p1']); - -$sbas_id = $collection->get_databox()->get_sbas_id(); -$distant_coll_id = $collection->get_coll_id(); -$addr = $collection->get_databox()->get_serialized_server_info(); - -$msg = array(); - -$refreshFinder = false; - - -if (is_array($parm['admins'])) { - $admins = array(); - - foreach ($parm['admins'] as $a) { - if (trim($a) == '') - continue; - - $admins[] = $a; - } - - if ($admins > 0) { - set_exportorder::set_order_admins($admins, $base_id); - } -} - -switch ($parm['act']) { - case 'ENABLED': - $collection->enable($appbox); - break; - case 'DISABLED'; - $collection->disable($appbox); - break; - case 'pub_wm': - if ($ACL->has_right_on_base($base_id, 'canadmin') == 1) { - $collection->set_public_presentation($parm['pub_wm']); - } - break; - case 'APPLYNEWNAMECOLL': - $collection->set_name($parm['p2']); - $refreshFinder = true; - break; - case 'UMOUNTCOLL': - $collection->unmount_collection($appbox); - $msg['ACTDONE'] = $collection->get_name() . ' ' . _('forms::operation effectuee OK'); - $refreshFinder = true; - break; - case 'DODELETECOLL': - if ($collection->get_record_amount() > 0) { - $msg['ACTDONE'] = _('admin::base:collection: vider la collection avant de la supprimer'); - } else { - $collection->unmount_collection($appbox); - $collection->delete(); - - $msg['ACTDONE'] = _('forms::operation effectuee OK'); - $refreshFinder = true; - } - break; - - case 'SENDMINILOGO': - if (isset($_FILES['newLogo'])) { - if ($_FILES['newLogo']['size'] > 65535) { - $msg['SENDMINILOGO'] = '

    ' . _('admin::base:collection le fichier envoye est trop volumineux.') . ' 64Ko
    '; - } elseif ($_FILES['newLogo']['error']) { - $msg['SENDMINILOGO'] = '
    ' . _('forms::erreur lors de l\'envoi du fichier') . '
    '; - } elseif (( $_FILES['newLogo']['error'] == UPLOAD_ERR_OK)) { - try { - $appbox->write_collection_pic($collection, new SymfoFile($_FILES['newLogo']['tmp_name']), collection::PIC_LOGO); - } catch (Exception $e) { - $msg['SENDMINILOGO'] = $e->getMessage(); - } - } - } - break; - - case 'DELMINILOGO': - try { - $collection->update_logo(null); - $appbox->write_collection_pic($collection, null, collection::PIC_LOGO); - } catch (Exception $e) { - $msg['DELMINILOGO'] = $e->getMessage(); - } - break; - - case 'SENDWM': - case 'DELWM': - - if ($parm['act'] == 'SENDWM' && isset($_FILES['newWm'])) { - if ($_FILES['newWm']['size'] > 65535) { - $msg['SENDWM'] = '
    ' . _('admin::base:collection le fichier envoye est trop volumineux.') . " 64Ko" . "
    "; - } elseif ($_FILES['newWm']['error']) { - $msg['SENDWM'] = '
    ' . _('forms::erreur lors de l\'envoi du fichier') . "
    "; // par le serveur (fichier php.ini) - } elseif (($_FILES['newWm']['error'] == UPLOAD_ERR_OK)) { - try { - $appbox->write_collection_pic($collection, new SymfoFile($_FILES['newWm']["tmp_name"]), collection::PIC_WM); - } catch (Exception $e) { - $msg['SENDWM'] = '
    ' . $e->getMessage() . "
    "; - } - unlink($_FILES['newWm']["tmp_name"]); - } - } elseif ($parm['act'] == "DELWM") { - try { - $appbox->write_collection_pic($collection, null, collection::PIC_WM); - } catch (Exception $e) { - $msg['DELWM'] = '
    ' . $e->getMessage() . "
    "; - } - } - break; - - case 'SENDSTAMPLOGO': - if (isset($_FILES['newStampLogo'])) { - if ($_FILES['newStampLogo']['size'] > 1024 * 1024) { - $msg['SENDSTAMPLOGO'] = '
    ' . _('admin::base:collection le fichier envoye est trop volumineux.') . ' 1Mo
    '; - } elseif ($_FILES['newStampLogo']['error']) { - $msg['SENDSTAMPLOGO'] = '
    ' . _('forms::erreur lors de l\'envoi du fichier') . '
    '; // par le serveur (fichier php.ini) - } elseif (( $_FILES['newStampLogo']['error'] == UPLOAD_ERR_OK)) { - try { - $appbox->write_collection_pic($collection, new SymfoFile($_FILES['newStampLogo']["tmp_name"]), collection::PIC_STAMP); - } catch (Exception $e) { - $msg['SENDSTAMPLOGO'] = '
    ' . $e->getMessage() . "
    "; - } - unlink($_FILES['newStampLogo']["tmp_name"]); - } - } - break; - - case 'DELSTAMPLOGO': - try { - $appbox->write_collection_pic($collection, null, collection::PIC_STAMP); - } catch (Exception $e) { - $msg['DELSTAMPLOGO'] = '
    ' . $e->getMessage() . "
    "; - } - break; - - case 'SENDPRESENTPICT': - if (isset($_FILES['newPresentPict'])) { - if ($_FILES['newPresentPict']['size'] > 1024 * 1024 * 2) { - $msg['SENDPRESENTPICT'] = '
    ' . _('admin::base:collection le fichier envoye est trop volumineux.') . ' 2Mo
    '; - } elseif ($_FILES['newPresentPict']['error']) { - $msg['SENDPRESENTPICT'] = '
    ' . _('forms::erreur lors de l\'envoi du fichier') . '
    '; // par le serveur (fichier php.ini) - } elseif ($_FILES['newPresentPict']['error'] == UPLOAD_ERR_OK) { - try { - $appbox->write_collection_pic($collection, new SymfoFile($_FILES['newPresentPict']["tmp_name"]), collection::PIC_PRESENTATION); - } catch (Exception $e) { - $msg['SENDPRESENTPICT'] = '
    ' . $e->getMessage() . "
    "; - } - unlink($_FILES['newPresentPict']["tmp_name"]); - } - } - break; - - case 'DELPRESENTPICT': - try { - $appbox->write_collection_pic($collection, null, collection::PIC_PRESENTATION); - } catch (Exception $e) { - $msg['DELPRESENTPICT'] = '
    ' . $e->getMessage() . "
    "; - } - @unlink($registry->get('GV_RootPath') . 'config/presentation/' . $base_id); - break; -} - -function showMsg($k) -{ - global $msg; - if (isset($msg[$k])) - echo($msg[$k]); -} -phrasea::headers(); -?> - - - - - - - - - - - - -

    - get_name(); ?> -

    -
    - :   -
    - -
    - :   -
    - -
    -is_active() ? _('admin::base:collection: activer la collection') : _('admin::base:collection: descativer la collection') ) ?>  -
    - -
    -get_record_amount() . ' records' . "\n"; - -if ($parm["sta"] == "" || $parm["sta"] == NULL || $parm["sta"] == 0) { - ?> - ( - - ) -
    - get_record_details(); - ?> - ( - - ) -
    -
    - - - - - - - - - - - - - - - - 0 || $last_k1 !== $vrow["coll_id"]) { - if (extension_loaded("bcmath")) - $midsiz = bcadd($midsiz, $vrow["size"], 0); - else - $midsiz += $vrow["size"]; - if (extension_loaded("bcmath")) - $mega = bcdiv($vrow["size"], 1024 * 1024, 5); - else - $mega = $vrow["size"] / (1024 * 1024); - if (extension_loaded("bcmath")) - $giga = bcdiv($vrow["size"], 1024 * 1024 * 1024, 5); - else - $giga = $vrow["size"] / (1024 * 1024 * 1024); - ?> - - - - - - - - - - - - - - - - - - - - - - - - -
    -  '); - print(_('admin::base: objet')); - ?> - - - - (Mo) - - (Go) -
    - - -   - -   - -   - -   - -   - -   -
    - total - -   - -   - -   - -   - -   - -   -
    -
    -
    - total - -   - -   - -   - -   - -   - -   -
    - -
    - has_right_on_base($base_id, 'manage')) { - $pub_wm = $collection->get_pub_wm(); - ?> -
    - - - -
    - on_base_ids(array($base_id)) - ->who_have_right(array('order_master')) - ->execute()->get_results(); - - foreach ($admins as $usr_id => $user) { - ?> -
    - -
    - - - - -
    -
    - -
    - " /> - " /> - - - - " /> - - - - -
    - value='none' /> - value='wm' /> - value='stamp' /> -
    - -
    - - - - - -
    - - - - -
    - - " /> - -
    - - - - - -
    -
    -
    - - -
    -
    - -
    -
    - : - -
    -has_right_on_base($base_id, 'manage')) { - if (file_exists($registry->get('GV_RootPath') . 'config/minilogos/' . $base_id)) { - ?> -
    - getLogo($base_id) ?> - - - -
    - - - - - -
    -
    -
    - Watermark : - -
    - has_right_on_base($base_id, 'manage')) { - if (file_exists($registry->get('GV_RootPath') . 'config/wm/' . $collection->get_base_id())) { - ?> -
    - getWatermark($base_id) ?> - - - -
    - - - - - -
    -
    -
    - StampLogo : - -
    - has_right_on_base($base_id, 'manage')) { - if (file_exists($registry->get('GV_RootPath') . 'config/stamp/' . $base_id)) { - ?> -
    - getStamp($base_id) ?> - - - -
    - - - - -
    -
    -
    - - -
    - has_right_on_base($base_id, 'manage')) { - if (file_exists($registry->get('GV_RootPath') . 'config/presentation/' . $base_id)) { - ?> -
    - getPresentation($base_id) ?> - - - -
    - - - -
    ( max : 650x200 ) - -
    - -
    - - - diff --git a/www/admin/database.php b/www/admin/database.php deleted file mode 100644 index b9f74d8b85..0000000000 --- a/www/admin/database.php +++ /dev/null @@ -1,702 +0,0 @@ -get_session(); -$registry = $appbox->get_registry(); -$request = http_request::getInstance(); -$parm = $request->get_parms("act", "p0", // id de la base - "sta", // afficher les stats de base (1) ou non (0) - "srt", // trier les colonnes de stats par collection (col) ou objet (obj) - "nvn", // New ViewName ( lors de l'UPD - "othcollsel", "coll_id", "base_id" -); - -if ( ! $parm["srt"]) - $parm["srt"] = "col"; - -$sbas_id = (int) $parm['p0']; -$databox = $appbox->get_databox($sbas_id); - -phrasea::headers(); - -$printLogoUploadMsg = ""; - -$user = User_Adapter::getInstance($session->get_usr_id(), $appbox); -if ($user->ACL()->has_right_on_sbas($sbas_id, 'bas_manage')) { - switch ($parm["act"]) { - case "SENDLOGOPDF": - try { - if (isset($_FILES['newLogoPdf']) && $_FILES['newLogoPdf']['error'] == UPLOAD_ERR_OK) { - if ($_FILES['newLogoPdf']['size'] < 65536) { - $appbox->write_databox_pic($databox, new SymfoFile($_FILES['newLogoPdf']["tmp_name"]), \databox::PIC_PDF); - unlink($_FILES['newLogoPdf']["tmp_name"]); - } else { - $printLogoUploadMsg = _('forms::erreur lors de l\'envoi du fichier'); - } - } else { - $printLogoUploadMsg = _('forms::erreur lors de l\'envoi du fichier'); - } - } catch (\InvalidArgumentException $e) { - $printLogoUploadMsg = _('Invalid file format'); - } catch (\Exception $e) { - $printLogoUploadMsg = _('forms::erreur lors de l\'envoi du fichier'); - } - break; - case 'MOUNT': - $appbox->get_connection()->beginTransaction(); - try { - $base_id = collection::mount_collection($sbas_id, $parm['coll_id'], $user); - if ( ! is_null($parm['othcollsel'])) { - - $query = new User_Query($appbox); - $total = $query->on_base_ids(array($parm["othcollsel"]))->get_total(); - $n = 0; - while ($n < $total) { - $results = $query->limit($n, 50)->execute()->get_results(); - foreach ($results as $user) { - $user->ACL()->duplicate_right_from_bas($parm["othcollsel"], $base_id); - } - $n+=50; - } - } - $appbox->get_connection()->commit(); - } catch (Exception $e) { - $appbox->get_connection()->rollBack(); - } - break; - case 'ACTIVATE': - try { - $collection = collection::get_from_base_id($parm['base_id']); - $collection->enable($appbox); - } catch (Exception $e) { - - } - break; - } -} -?> - - - - -
    -

    get_serialized_server_info(); ?>

    -

    ID :

    -

    - : - ACL()->has_right_on_sbas($sbas_id, "bas_manage")) { - ?> - - -

    -
    - get_record_amount(); - - $out .= "

    "; - // stats sur la base distante - $out .= _('admin::base: nombre d\'enregistrements sur la base :') . ' ' . ' '; - - if ((int) $parm["sta"] < 1) { - $out .= " (" . _('phraseanet:: details') . ")"; - } else { - $unique_keywords = $databox->get_unique_keywords(); - - $out .= ",  "; - $out .= _('admin::base: nombre de mots uniques sur la base : ') . ' ' . $unique_keywords; - - $indexes = $databox->get_index_amount(); - - $out .= ",  "; - $out .= _('admin::base: nombre de mots indexes sur la base') . ' ' . $indexes; - - if ($registry->get('GV_thesaurus')) { - $thits = $databox->get_thesaurus_hits(); - - $out .= ",  "; - $out .= _('admin::base: nombre de termes de Thesaurus indexes :') . ' ' . $thits; - } - - $out .= " (" . _('admin::base: masquer les details') . ")
    \n"; - - - $trows = $databox->get_record_details($parm['srt']); - - $out .= "\n"; - $out .= ""; - $out .= ""; - - $out .= ""; - - $out .= ""; - $out .= ""; - $out .= ""; - $out .= ""; - $totobj = 0; - $totsiz = "0"; // les tailles de fichiers sont calculees avec bcmath - foreach ($trows as $kgrp => $vgrp) { - // ksort($vgrp); - $midobj = 0; - $midsiz = "0"; - $last_k1 = $last_k2 = null; - foreach ($vgrp as $krow => $vrow) { - if ($last_k1 !== $vrow["coll_id"]) { - - } - if ($vrow["n"] > 0 || $last_k1 !== $vrow["coll_id"]) { - $midobj += $vrow["n"]; - if (extension_loaded("bcmath")) - $midsiz = bcadd($midsiz, $vrow["siz"], 0); - else - $midsiz += $vrow["siz"]; - $out .= "\n"; - if ($last_k1 !== $vrow["coll_id"]) { - if ((int) $vrow["lostcoll"] <= 0) { - $out .= "\n"; - } else { - $out .= ""; - } - $last_k1 = $vrow["coll_id"]; - } else { - $out .= "\n"; - } - if ($last_k2 !== $vrow["name"]) - $out .= "\n"; - else - $out .= "\n"; - $out .= "\n"; - if (extension_loaded("bcmath")) - $mega = bcdiv($vrow["siz"], 1024 * 1024, 5); - else - $mega = $vrow["siz"] / (1024 * 1024); - if (extension_loaded("bcmath")) - $giga = bcdiv($vrow["siz"], 1024 * 1024 * 1024, 5); - else - $giga = $vrow["siz"] / (1024 * 1024 * 1024); - $out .= "\n"; - $out .= "\n"; - $out .= "\n"; - } - // $last_k1 = null; - } - $totobj += $midobj; - if (extension_loaded("bcmath")) - $totsiz = bcadd($totsiz, $midsiz, 0); - else - $totsiz += $midsiz; - $out .= "\n"; - $out .= "\n"; - $out .= "\n"; - $out .= "\n"; - if (extension_loaded("bcmath")) - $mega = bcdiv($midsiz, 1024 * 1024, 5); - else - $mega = $midsiz / (1024 * 1024); - - if (extension_loaded("bcmath")) - $giga = bcdiv($midsiz, 1024 * 1024 * 1024, 5); - else - $giga = $midsiz / (1024 * 1024 * 1024); - $out .= "\n"; - $out .= "\n"; - $out .= "\n"; - - $out .= "
    "; - if ($parm["srt"] == "col") - $out .= " "; - $out .= _('phraseanet:: collection') . ""; - if ($parm["srt"] == "obj") - $out .= " "; - $out .= _('admin::base: objet') . "" . _('admin::base: nombre') . "" . _('admin::base: poids') . " (Mo)" . _('admin::base: poids') . " (Go)
    " . $vrow["asciiname"] . "" . _('admin::base: enregistrements orphelins') . " " . sprintf("(coll_id=%s)", $vrow["coll_id"]) . "" . ($last_k2 = $vrow["name"]) . " " . $vrow["n"] . "  " . sprintf("%.2f", $mega) . "  " . sprintf("%.2f", $giga) . " 
    " . _('report:: total') . " " . $midobj . "  " . sprintf("%.2f", $mega) . "  " . sprintf("%.2f", $giga) . " 
    "; - $out .= "

    "; - } - } - - print($out); - ?> - -
    -
    -

    - : - -

    -
    -
    -
    -
    -

    - : - -

    -
    -
    -
    -
    - ACL()->has_right_on_sbas($sbas_id, "bas_manage")) { - ?> -
    - - -
    -

    - - - -

    -
    -

    - "> - - - -

    - get_mountable_colls(); - if (count($mountable_colls) > 0) { - ?> -

    - - - - -

    - - get_activable_colls(); - if (count($activable_colls) > 0) { - ?> -

    - - - - -

    - - -

    - - - - -

    -

    - - - - -

    -

    - - - - -

    -

    - - - - -

    - - -
    - - -
    -
    -

    - -
    - - ACL()->has_right_on_sbas($sbas_id, "bas_manage")) { - ?> - - - - -
    -
    - -
    - " /> - - - - - ACL()->has_right_on_sbas($sbas_id, "bas_manage")) { - ?> - - " onclick="sendLogopdf();" /> -
    - -
    -
    -
    - -
    - " /> - - - - -
    diff --git a/www/admin/import.php b/www/admin/import.php deleted file mode 100644 index c4e589cffc..0000000000 --- a/www/admin/import.php +++ /dev/null @@ -1,455 +0,0 @@ -get_session(); - -$usr_id = $session->get_usr_id(); - -$user = User_Adapter::getInstance($usr_id, $appbox); - -phrasea::headers(); -?> - - - - - - - - - - - - count($test1) && count($test2) < 20)) - $separateur = ";"; - - - while ($ARRAY[] = fgetcsv($FILE, 1024, $separateur)); - fclose($FILE); - array_pop($ARRAY); - - return $ARRAY; - } - } - $request = http_request::getInstance(); - $parm = $request->get_parms("act", "modelToAplly", "sr"); - - $conn = $appbox->get_connection(); - - $models = null; - - if ($parm["act"] == "STEP2" || $parm["act"] == "STEP3") { - $admBasid = array_keys($user->ACL()->get_granted_base(array('manage'))); - $admBasid = implode(', ', $admBasid); - - if ($parm["act"] == "STEP2") { - $sql = "SELECT usr.usr_id,usr.usr_login - FROM usr - INNER JOIN basusr - ON (basusr.usr_id=usr.usr_id) - WHERE usr.model_of = :usr_id - AND base_id in($admBasid) - AND usr_login not like '(#deleted_%)' - GROUP BY usr_id"; - - $stmt = $conn->prepare($sql); - $stmt->execute(array(':usr_id' => $usr_id)); - $models = $stmt->fetchAll(PDO::FETCH_ASSOC); - $stmt->closeCursor(); - } - } - - $equivalenceToMysqlField['civilite'] = 'usr_sexe'; - $equivalenceToMysqlField['gender'] = 'usr_sexe'; - $equivalenceToMysqlField['usr_sexe'] = 'usr_sexe'; - $equivalenceToMysqlField['nom'] = 'usr_nom'; - $equivalenceToMysqlField['name'] = 'usr_nom'; - $equivalenceToMysqlField['last name'] = 'usr_nom'; - $equivalenceToMysqlField['last_name'] = 'usr_nom'; - $equivalenceToMysqlField['usr_nom'] = 'usr_nom'; - $equivalenceToMysqlField['first name'] = 'usr_prenom'; - $equivalenceToMysqlField['first_name'] = 'usr_prenom'; - $equivalenceToMysqlField['prenom'] = 'usr_prenom'; - $equivalenceToMysqlField['usr_prenom'] = 'usr_prenom'; - $equivalenceToMysqlField['identifiant'] = 'usr_login'; - $equivalenceToMysqlField['login'] = 'usr_login'; - $equivalenceToMysqlField['usr_login'] = 'usr_login'; - $equivalenceToMysqlField['usr_password'] = 'usr_password'; - $equivalenceToMysqlField['password'] = 'usr_password'; - $equivalenceToMysqlField['mot de passe'] = 'usr_password'; - $equivalenceToMysqlField['usr_mail'] = 'usr_mail'; - $equivalenceToMysqlField['email'] = 'usr_mail'; - $equivalenceToMysqlField['mail'] = 'usr_mail'; - $equivalenceToMysqlField['adresse'] = 'adresse'; - $equivalenceToMysqlField['adress'] = 'adresse'; - $equivalenceToMysqlField['address'] = 'adresse'; - $equivalenceToMysqlField['ville'] = 'ville'; - $equivalenceToMysqlField['city'] = 'ville'; - $equivalenceToMysqlField['zip'] = 'cpostal'; - $equivalenceToMysqlField['zipcode'] = 'cpostal'; - $equivalenceToMysqlField['zip_code'] = 'cpostal'; - $equivalenceToMysqlField['cpostal'] = 'cpostal'; - $equivalenceToMysqlField['cp'] = 'cpostal'; - $equivalenceToMysqlField['code_postal'] = 'cpostal'; - $equivalenceToMysqlField['tel'] = 'tel'; - $equivalenceToMysqlField['telephone'] = 'tel'; - $equivalenceToMysqlField['phone'] = 'tel'; - $equivalenceToMysqlField['fax'] = 'fax'; - $equivalenceToMysqlField['job'] = 'fonction'; - $equivalenceToMysqlField['fonction'] = 'fonction'; - $equivalenceToMysqlField['function'] = 'fonction'; - $equivalenceToMysqlField['societe'] = 'societe'; - $equivalenceToMysqlField['company'] = 'societe'; - $equivalenceToMysqlField['activity'] = 'activite'; - $equivalenceToMysqlField['activite'] = 'activite'; - $equivalenceToMysqlField['pays'] = 'pays'; - $equivalenceToMysqlField['country'] = 'pays'; - - $equivalenceToMysqlField['ftp_active'] = 'activeFTP'; - $equivalenceToMysqlField['compte_ftp_actif'] = 'activeFTP'; - $equivalenceToMysqlField['ftpactive'] = 'activeFTP'; - $equivalenceToMysqlField['activeftp'] = 'activeFTP'; - $equivalenceToMysqlField['ftp_adress'] = 'addrFTP'; - $equivalenceToMysqlField['adresse_du_serveur_ftp'] = 'addrFTP'; - $equivalenceToMysqlField['addrftp'] = 'addrFTP'; - $equivalenceToMysqlField['ftpaddr'] = 'addrFTP'; - $equivalenceToMysqlField['loginftp'] = 'loginFTP'; - $equivalenceToMysqlField['ftplogin'] = 'loginFTP'; - $equivalenceToMysqlField['ftppwd'] = 'pwdFTP'; - $equivalenceToMysqlField['pwdftp'] = 'pwdFTP'; - $equivalenceToMysqlField['destftp'] = 'destFTP'; - $equivalenceToMysqlField['destination_folder'] = 'destFTP'; - $equivalenceToMysqlField['dossier_de_destination'] = 'destFTP'; - $equivalenceToMysqlField['passive_mode'] = 'passifFTP'; - $equivalenceToMysqlField['mode_passif'] = 'passifFTP'; - $equivalenceToMysqlField['passifftp'] = 'passifFTP'; - $equivalenceToMysqlField['retry'] = 'retryFTP'; - $equivalenceToMysqlField['nombre_de_tentative'] = 'retryFTP'; - $equivalenceToMysqlField['retryftp'] = 'retryFTP'; - $equivalenceToMysqlField['by_default__send'] = 'defaultftpdatasent'; - $equivalenceToMysqlField['by_default_send'] = 'defaultftpdatasent'; - $equivalenceToMysqlField['envoi_par_defaut'] = 'defaultftpdatasent'; - $equivalenceToMysqlField['defaultftpdatasent'] = 'defaultftpdatasent'; - $equivalenceToMysqlField['prefix_creation_folder'] = 'prefixFTPfolder'; - $equivalenceToMysqlField['prefix_de_creation_de_dossier'] = 'prefixFTPfolder'; - $equivalenceToMysqlField['prefixFTPfolder'] = 'prefixFTPfolder'; - - if ($parm["act"] == "STEP2" && ( ! isset($_FILES['fileusers']) || (isset($_FILES['fileusers']) && $_FILES['fileusers']['error']))) { - print("
    ERROR : " . $_FILES['fileusers']['error'] . "
    "); - $parm["act"] = ""; - } - if ($parm["act"] == "STEP3") { - $nbcreation = 0; - - $ARRAY = unserialize($parm["sr"]); - $nblignes = sizeof($ARRAY); // compte le nombre de ligne - $nbcol = sizeof($ARRAY[0]); // nombre de colonne par ligne - - for ($i = 1; $i < $nblignes; $i ++ ) { // pour chaque ligne.... - $curUser = NULL; - for ($j = 0; $j < $nbcol; $j ++ ) { // affiche colonne par colonne - if ( ! isset($equivalenceToMysqlField[$ARRAY[0][$j]])) - continue; - if ($equivalenceToMysqlField[$ARRAY[0][$j]] == "usr_sexe" && isset($ARRAY[$i][$j])) { - switch ($ARRAY[$i][$j]) { - case "Mlle": - case "Mlle.": - case "mlle": - case "Miss": - case "miss": - case "0": - $curUser[$equivalenceToMysqlField[$ARRAY[0][$j]]] = 0; - break; - - case "Mme": - case "Madame": - case "Ms": - case "Ms.": - case "1": - $curUser[$equivalenceToMysqlField[$ARRAY[0][$j]]] = 1; - break; - - case "M": - case "M.": - case "Mr": - case "Mr.": - case "Monsieur": - case "Mister": - case "2": - $curUser[$equivalenceToMysqlField[$ARRAY[0][$j]]] = 2; - break; - } - } else { - if (isset($ARRAY[$i][$j])) - $curUser[$equivalenceToMysqlField[$ARRAY[0][$j]]] = trim($ARRAY[$i][$j]); - } - } - - - # on va cree ici le user et ses droits - # on verifie juste le login et le password - if (isset($curUser['usr_login']) && trim($curUser['usr_login']) !== '' && isset($curUser['usr_password']) && trim($curUser['usr_password']) !== "") { - $loginNotExist = ! User_Adapter::get_usr_id_from_login($curUser['usr_login']); - - if ($loginNotExist) { - $NewUser = User_Adapter::create($appbox, $curUser['usr_login'], $curUser['usr_password'], $curUser['usr_mail'], false); - - $newid = $NewUser->get_id(); - - $admBasid = array_keys($user->ACL()->get_granted_base(array('manage'))); - $template_user = User_Adapter::getInstance($parm["modelToAplly"], $appbox); - $NewUser->ACL()->apply_model($template_user, $admBasid); - - $nbcreation ++; - } - } - } - ?> -
    -
    - users was created. -
    -
    - - - Close -
    -
    - -
    << Back
    -
    - - Row \"" . $ARRAY[0][$j] . "\" will be ignored"; - } else { - if (($equivalenceToMysqlField[$ARRAY[0][$j]]) == 'usr_login') - $logindefined = true; - if (($equivalenceToMysqlField[$ARRAY[0][$j]]) == 'usr_password') - $pwddefined = true; - } - } - $outTmp = ""; - if ( ! $logindefined) - $outTmp.= "
    - Row \"login\" is missing, script has stopped !"; - if ( ! $pwddefined) - $outTmp.= "
    - Row \"password\" is missing, script has stopped !"; - - if ($out != "") - $out.="\n
    "; - - - if ( ! $logindefined || ! $pwddefined) - $out = $outTmp; - else { - // On continu les tests !! - // on verifie (pour chacun) que le login n'existe pas deja et aussi que les mots de passe sont pas vides - $nblignes = sizeof($ARRAY); // nombre de ligne - $nbcol = sizeof($ARRAY[0]); // nombre de colonne par ligne - - for ($i = 1; $i < $nblignes; $i ++ ) { // pour chaque ligne.... - $out2 = ""; - $hasVerifLogin = false; - $hasVerifPwd = false; - - for ($j = 0; $j < $nbcol; $j ++ ) { // colonne par colonne - $ARRAY[$i][$j] = trim($ARRAY[$i][$j]); - if ( ! isset($equivalenceToMysqlField[$ARRAY[0][$j]])) - continue; - // verif du login - if (($equivalenceToMysqlField[$ARRAY[0][$j]]) == 'usr_login') { - $loginToadd = trim($ARRAY[$i][$j]); - if ($loginToadd == "") - $out2.= " login is empty."; - elseif (isset($loginNew[$loginToadd])) - $out2.= " Le login \"" . $loginToadd . "\" is already defined in the file (line " . $loginNew[$loginToadd] . ")."; - else { - if (User_Adapter::get_usr_id_from_login($loginToadd)) { - $out2.= " Login \"" . $loginToadd . "\" already exists in database."; - } else { - $loginNew[$loginToadd] = ($i + 1); - } - } - $hasVerifLogin = true; - } - - // verif du pwd - if (($equivalenceToMysqlField[$ARRAY[0][$j]]) == 'usr_password') { - - if (trim($ARRAY[$i][$j]) == "") { - $out2.= " password is empty ."; - } - $hasVerifPwd = true; - } - - if ($hasVerifLogin && $hasVerifPwd) - $j = $nbcol; - - if (($j + 1) >= $nbcol) { - if ($out2 != "") { - $out .= "
    Line " . ( $i + 1) . " :"; - $out .= "$out2
    "; - } - else - $nbusrToadd ++; - } - } - } - } - - if ($out != "") { // on affiche les erreurs - ?> - -
     Warning 
    -
    - -
    - Number of users who's ready to be create : $nbusrToadd"; - /* ------------- ON ALLEGE LE TABLEAU ---------------- */ - for ($i = 1; $i < sizeof($ARRAY); $i ++ ) - for ($j = 0; $j < sizeof($ARRAY[0]); $j ++ ) - if ((isset($ARRAY[$i][$j]) && trim($ARRAY[$i][$j]) == "") || ( ! isset($equivalenceToMysqlField[$ARRAY[0][$j]]))) - unset($ARRAY[$i][$j]); - /* -------------------------------------------------- */ - ?> -
    -
    - - - 0 && count($models) > 0) { - echo "
    Select a model to apply on users :"; - echo " "; - ?> -

    Cancel      Add users - -
    - you need define a model before importing a list of users. -
    -
    - Close -
    - -
    - Close - - - - -
    - Upload a "csv" file CSV for users creation - -
    - you can download an example by clicking here
    and his documentation here
    -

    -
    - - User's file : -
    -
    -
    -
    - Send this file -
    -
    - - - diff --git a/www/admin/import0.php b/www/admin/import0.php deleted file mode 100644 index 670f138eed..0000000000 --- a/www/admin/import0.php +++ /dev/null @@ -1,48 +0,0 @@ -get_session(); - -phrasea::headers(); -?> - - - - - - - - - - diff --git a/www/admin/sphinxconf.php b/www/admin/sphinxconf.php deleted file mode 100644 index 93c3da60f5..0000000000 --- a/www/admin/sphinxconf.php +++ /dev/null @@ -1,64 +0,0 @@ -get_parms('charset_tables', 'libstemmer'); -if (is_array($parms['charset_tables'])) { - $registry->set('sphinx_charset_tables', $parms['charset_tables'], registry::TYPE_ARRAY); -} -if (is_array($parms['libstemmer'])) { - $registry->set('sphinx_user_stemmer', $parms['libstemmer'], registry::TYPE_ARRAY); -} - -$sphinx_conf = new sphinx_configuration(); - -$selected_charsets = $registry->get('sphinx_charset_tables'); -$selected_libstemmer = $registry->get('sphinx_user_stemmer'); - -$options = array( - 'charset_tables' => ( ! is_array($selected_charsets) ? array() : $selected_charsets) - , 'libstemmer' => ( ! is_array($selected_libstemmer) ? array() : $selected_libstemmer) -); -?> -
    - - - - - - - -
    - -