add details view for collection & databox; add sphinxconf; add users import & export;

add tests
This commit is contained in:
Nicolas Le Goff
2012-08-14 17:33:11 +02:00
parent b66f9b01f9
commit e62d1e924c
33 changed files with 2372 additions and 2237 deletions

View File

@@ -24,6 +24,7 @@ use Alchemy\Phrasea\Controller\Admin\Bas;
use Alchemy\Phrasea\Controller\Admin\Databases; use Alchemy\Phrasea\Controller\Admin\Databases;
use Alchemy\Phrasea\Controller\Admin\Database; use Alchemy\Phrasea\Controller\Admin\Database;
use Alchemy\Phrasea\Controller\Admin\Setup; use Alchemy\Phrasea\Controller\Admin\Setup;
use Alchemy\Phrasea\Controller\Admin\Sphinx;
use Alchemy\Phrasea\Controller\Utils\ConnectionTest; use Alchemy\Phrasea\Controller\Utils\ConnectionTest;
use Alchemy\Phrasea\Controller\Utils\PathFileTest; use Alchemy\Phrasea\Controller\Utils\PathFileTest;
@@ -37,6 +38,7 @@ return call_user_func(
$app->mount('/database', new Database()); $app->mount('/database', new Database());
$app->mount('/databases', new Databases()); $app->mount('/databases', new Databases());
$app->mount('/setup', new Setup()); $app->mount('/setup', new Setup());
$app->mount('/sphinx', new Sphinx());
$app->mount('/connected-users', new ConnectedUsers()); $app->mount('/connected-users', new ConnectedUsers());
$app->mount('/publications', new Publications()); $app->mount('/publications', new Publications());
$app->mount('/users', new Users()); $app->mount('/users', new Users());

View File

@@ -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; return $controllers;
} }
@@ -956,9 +973,9 @@ class Bas implements ControllerProviderInterface
$pref = array('status' => null, 'xml' => null); $pref = array('status' => null, 'xml' => null);
if ($ki == "status") { if ($ki == "status") {
$pref['status'] = $vi; $pref['status'] = $vi;
} else if ($ki != "sugestedValues") { } else if ($ki != "sugestedValues") {
$pref['xml'] = $vi->asXML(); $pref['xml'] = $vi->asXML();
} }
$basePrefs[] = $pref; $basePrefs[] = $pref;
@@ -966,7 +983,7 @@ class Bas implements ControllerProviderInterface
} }
} }
if($updateMsg = $request->get('update')) { if ($updateMsg = $request->get('update')) {
switch ($updateMsg) { switch ($updateMsg) {
case 'ok'; case 'ok';
$updateMsg = _('forms::operation effectuee OK'); $updateMsg = _('forms::operation effectuee OK');
@@ -1010,7 +1027,6 @@ class Bas implements ControllerProviderInterface
$msg = _('Coult not load XML'); $msg = _('Coult not load XML');
$success = false; $success = false;
} }
} catch (\Exception $e) { } catch (\Exception $e) {
} }
@@ -1018,6 +1034,95 @@ class Bas implements ControllerProviderInterface
return $app->json(array('success' => $success, 'msg' => $msg)); 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 * Prefix the method to call with the controller class name
* *

View File

@@ -530,7 +530,7 @@ class Database implements ControllerProviderInterface
*/ */
public function createDatabase(Application $app, Request $request) 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'); return $app->redirect('/admin/databases/?error=no-empty');
} }
@@ -986,9 +986,7 @@ class Database implements ControllerProviderInterface
$databox = $app['phraseanet.appbox']->get_databox($databox_id); $databox = $app['phraseanet.appbox']->get_databox($databox_id);
$out = array('total' => array('totobj' => 0, 'totsiz' => 0, 'mega' => '0', 'giga' => '0'), 'result' => array()); $out = array('total' => array('totobj' => 0, 'totsiz' => 0, 'mega' => '0', 'giga' => '0'), 'result' => array());
// echo '<pre>';
// var_dump($databox->get_record_details($request->get('sort')));
// echo '</pre>';
foreach ($databox->get_record_details($request->get('sort')) as $vgrp) { foreach ($databox->get_record_details($request->get('sort')) as $vgrp) {
$last_k1 = $last_k2 = null; $last_k1 = $last_k2 = null;

View File

@@ -52,20 +52,6 @@ class Databases implements ControllerProviderInterface
*/ */
$controllers->get('/', $this->call('getDatabases'))->bind('admin_databases'); $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 * 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 * @param \Silex\Application $app

View File

@@ -0,0 +1,71 @@
<?php
/*
* This file is part of Phraseanet
*
* (c) 2005-2012 Alchemy
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Alchemy\Phrasea\Controller\Admin;
/**
*
* @license http://opensource.org/licenses/gpl-3.0 GPLv3
* @link www.phraseanet.com
*/
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Silex\Application;
use Silex\ControllerProviderInterface;
/**
*
* @license http://opensource.org/licenses/gpl-3.0 GPLv3
* @link www.phraseanet.com
*/
class Sphinx implements ControllerProviderInterface
{
public function connect(Application $app)
{
$controllers = $app['controllers_factory'];
$controllers->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;
}
}

View File

@@ -576,7 +576,349 @@ class Users implements ControllerProviderInterface
return $app->redirect('/admin/users/demands/?demands=ok'); 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; 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;
}
} }

View File

@@ -56,4 +56,27 @@ class format
return implode("\n", $lines); 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;
}
}
} }

View File

@@ -9,7 +9,7 @@
<li>{% trans 'phraseanet:: adresse' %} : {{ collection.get_databox().get_serialized_server_info() }}</li> <li>{% trans 'phraseanet:: adresse' %} : {{ collection.get_databox().get_serialized_server_info() }}</li>
<li>{% trans 'admin::base:collection: numero de collection distante' %} : {{ collection.get_coll_id() }}</li> <li>{% trans 'admin::base:collection: numero de collection distante' %} : {{ collection.get_coll_id() }}</li>
<li>{% 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 }}</li> <li>{% 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 }}</li>
<li>{{ collection.get_record_amount() }} records</li> <li>{{ collection.get_record_amount() }} records <a target='_self' href='/admin/bas/{{ collection.get_base_id() }}/informations/details/'>{% trans 'phraseanet:: details' %}</a></li>
</ul> </ul>
{% if user.ACL.has_right_on_base(app.request.get('bas_id'), 'manage') %} {% if user.ACL.has_right_on_base(app.request.get('bas_id'), 'manage') %}

View File

@@ -0,0 +1,47 @@
<div class="header">
<h1>{{ collection.get_name() }} <small>{% trans "Details" %}</small></h1>
</div>
<table class="table table-bordered">
<thead>
<tr>
<th>{% trans 'admin::base: objet' %}</th>
<th>{% trans 'admin::base: nombre' %}</th>
<th>{% trans 'admin::base: poids' %} (Mo)</th>
<th>{% trans 'admin::base: poids' %} (Go)</th>
</tr>
</thead>
<tbody>
{% for row in table['result'] %}
<tr style='backgound-color:{{ loop.index is even ? '#ccc' : '#fff' }}'>
<td>{{ row['name'] }}</td>
<td>{{ row['amount'] }}</td>
<td>{{ row['mega'] }}</td>
<td>{{ row['giga'] }}</td>
</tr>
{% endfor %}
{% set totals = table['total'] %}
<tfoot>
<tr>
<th>
{% trans 'Total' %}
</th>
<th>
{{ totals['totobj'] }}
</th>
<th>
{{ totals['mega'] }}
</th>
<th>
{{ totals['giga'] }}
</th>
</tr>
</tfoot>
</tbody>
</table>
<div>
<a class='btn btn-mini' href='/admin/bas/{{ collection.get_base_id() }}/'>{% trans 'boutton::retour' %}</a>
</div>

View File

@@ -4,7 +4,7 @@
{% endif %} {% endif %}
{% if createBase %} {% 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 %} {% endif %}
</script> </script>
@@ -27,7 +27,7 @@
{% if sbas | length > 0 %} {% if sbas | length > 0 %}
{% for key, value in sbas %} {% for key, value in sbas %}
<li> <li>
<a href='database.php?p0={{ key }}' target='_self'> <a href='/admin/database/{{ key }}/' target='_self'>
<img src="{{ value['image'] }}" /> {{ value['name'] }} ({% trans "version" %} {{ value['version'] }}) {{ value['server_info'] }} <img src="{{ value['image'] }}" /> {{ value['name'] }} ({% trans "version" %} {{ value['version'] }}) {{ value['server_info'] }}
</a> </a>
</li> </li>

View File

@@ -181,7 +181,7 @@
</div> </div>
{% endif %} {% endif %}
<div id="printLogoDIV_OK"> <div id="printLogoDIV_OK">
<img id="printLogo" src="/print/sbas_id " /> <img id="printLogo" src="/print/{{ databox.get_sbas_id() }} " />
{% if user.ACL().has_right_on_sbas(databox.get_sbas_id(), "bas_manage") %} {% if user.ACL().has_right_on_sbas(databox.get_sbas_id(), "bas_manage") %}
<a href="javascript:void();return(false);" onclick="deleteLogoPdf();return(false);"> <a href="javascript:void();return(false);" onclick="deleteLogoPdf();return(false);">
{% trans "admin::base:collection: supprimer le logo" %} {% trans "admin::base:collection: supprimer le logo" %}

View File

@@ -205,10 +205,9 @@
function reloadTree(position, click){ function reloadTree(position, click){
$.ajax({ $.ajax({
type: "POST", type: "GET",
url: "adminFeedback.php", url: "/admin/tree/",
data: { data: {
action : 'TREE',
position : position position : position
}, },
success: function(datas){ success: function(datas){

View File

@@ -0,0 +1,19 @@
<form class="well form-inline" method='post' action='/admin/sphinx/configuration/'>
<select name="charset_tables[]" multiple="multiple">
{% for charset, charset_obj in configuration.get_available_charsets() %}
<option value='{{ charset }}' {{ charset in options['charset_tables'] ? "selected='selected'" : "" }}>{{ charset_obj.get_name() }}</option>
{% endfor %}
</select>
<select name="libstemmer[]" multiple="multiple">
{% for stemme in configuration.get_available_libstemmer() %}
<option value='{{ stemme }}' {{ stemme in options['libstemmer'] ? "selected='selected'" : "" }}>{{ stemme }}</option>
{% endfor %}
</select>
<button class='btn btn-primary'>{% trans 'boutton::valider' %}</button>
</form>
<textarea style="width:100%;height:70%">
{{ configuration.get_configuration(options) }}
</textarea>

View File

@@ -22,13 +22,13 @@
<span>Setup</span> <span>Setup</span>
</a> </a>
</li> </li>
{% if registry.get('GV_sphinx') %} {% if registry.get('GV_sphinx') %}
<li> <li>
<a target="right" href="/admin/sphinxconf.php"> <a target="right" href="/admin/sphinx/configuration/" class="ajax">
<span>Sphinx Conf</span> <span>Sphinx Conf</span>
</a> </a>
</li> </li>
{% endif %} {% endif %}
{% endif %} {% endif %}
<li class="{% if feature == 'connected' %}selected{% endif %}"> <li class="{% if feature == 'connected' %}selected{% endif %}">
@@ -46,7 +46,6 @@
</a> </a>
</li> </li>
<li class="{% if feature == 'registrations' %}selected{% endif %}"> <li class="{% if feature == 'registrations' %}selected{% endif %}">
{#<a target="right" href="demand.php?act=LISTUSERS">#}
<a target="right" href="/admin/users/demands/" class="ajax"> <a target="right" href="/admin/users/demands/" class="ajax">
<img src="/skins/admin/Demandes.png" /> <img src="/skins/admin/Demandes.png" />
<span>{% trans 'admin::utilisateurs: demandes en cours' %}</span> <span>{% trans 'admin::utilisateurs: demandes en cours' %}</span>

View File

@@ -0,0 +1,47 @@
<div class="header">
<h1>{% trans 'Upload a "csv" file for users creation' %}</h1>
</div>
{% if app.request.get('error') is not none %}
{% set error = app.request.get('error') %}
<div class="alert alert-error">
<button class="close" data-dismiss="alert" type="button">×</button>
{% 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 %}
</div>
{% endif %}
{% if errors is defined and errors is not none and errors|length > 0 %}
<div class="alert alert-error">
<button class="close" data-dismiss="alert" type="button">×</button>
<ul class="unstyled">
{% for error in errors %}
<li>{{ error }}</li>
{% endfor%}
</ul>
</div>
{% endif %}
<div>
<div class='well-small'>
<a href="/admin/users/import/example/user/"> <i class="icon-share"></i> {% trans 'You can download an example by clicking here' %}</a>
</div>
<div class='well-small'>
<a href="/admin/users/import/example/rtf/"> <i class="icon-share"></i> {% trans 'You can download the documentation here' %}</a>
</div>
<form class ='well' method="post" target="_self" action="/admin/users/import/file/" ENCTYPE="multipart/form-data" >
{% trans "User's file " %} : <input name="file" type="file" />
<div class="form-actions">
<button class='btn btn-primary'>{% trans 'Send this file' %}</button>
<a href="" target='/admin/users/search/' class='btn'>{% trans 'boutton::retour' %}</a>
</div>
</form>
</div>

View File

@@ -0,0 +1,22 @@
<div class="header">
<h1>{% trans 'Apply a model' %} <small>({{ nb_user_to_add }} {% trans 'Users' %})</small></h1>
</div>
{% if nb_user_to_add > 0 and models|length > 0 %}
<form method="post" name="importform2" action="/admin/users/import/" ENCTYPE="multipart/form-data" >
<textarea style="display:none;" name="sr">{{ array_serialized }}</textarea>
<select name="modelToApply">
{% for model in models %}
<option value='{{ model['usr_id'] }}'>{{ model['usr_login'] }}</option>
{% endfor %}
</select>
<div class="form-actions">
<button class="btn btn-primary" type="submit">Save changes</button>
<button class="btn">Cancel</button>
</div>
</form>
{% elseif models|length == 0 %}
<div class="alert alert-block">
{% trans 'You need define a model before importing a list of users' %}
</div>
{% endif %}

View File

@@ -3,12 +3,24 @@
{% block content %} {% block content %}
{% if app.request.get('user-updated') is not none%}
<div class="alert alert-success">
<button class="close" data-dismiss="alert" type="button">×</button>
{% 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 %}
</div>
{% endif %}
<div id="users_page"> <div id="users_page">
<h1>{% trans 'Users' %}</h1> <h1>{% trans 'Users' %}</h1>
<p class="admin_head_opts"> <p class="admin_head_opts">
<a class="user_adder" href="#">{% trans 'admin::user: nouvel utilisateur' %}</a> <a class="user_adder" href="#">{% trans 'admin::user: nouvel utilisateur' %}</a>
<a class="template_adder" href="#">{% trans 'admin::user: nouveau template' %}</a> <a class="template_adder" href="#">{% trans 'admin::user: nouveau template' %}</a>
<a href="javascript:void();return(false);" onclick="importlist();return(false);">{% trans 'admin::user: import d\'utilisateurs' %}</a> / <a href="/admin/users/import/file/" target='right'>{% trans 'admin::user: import d\'utilisateurs' %}</a> /
<a href="javascript:void();return(false);" onclick="exportlist();return(false);">{% trans 'admin::user: export d\'utilisateurs' %}</a> <a href="javascript:void();return(false);" onclick="exportlist();return(false);">{% trans 'admin::user: export d\'utilisateurs' %}</a>
<a class="invite_modifier" href="#">{% trans 'Reglages:: reglages d acces guest' %}</a> <a class="invite_modifier" href="#">{% trans 'Reglages:: reglages d acces guest' %}</a>
<input type="hidden" value="{{invite_user.get_id()}}" name="invite_user_id"/> <input type="hidden" value="{{invite_user.get_id()}}" name="invite_user_id"/>
@@ -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() function exportlist()
{ {
$('#export_form').submit(); $('#export_form').submit();

View File

@@ -0,0 +1,150 @@
<?php
require_once __DIR__ . '/../../../../PhraseanetWebTestCaseAuthenticatedAbstract.class.inc';
class AdminDashboardTest extends \PhraseanetWebTestCaseAuthenticatedAbstract
{
protected $client;
protected $StubbedACL;
public function createApplication()
{
$app = require __DIR__ . '/../../../../../lib/Alchemy/Phrasea/Application/Admin.php';
$app['debug'] = true;
unset($app['exception_handler']);
return $app;
}
public function setUp()
{
parent::setUp();
$this->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());
}
}

View File

@@ -0,0 +1,800 @@
<?php
require_once __DIR__ . '/../../../../PhraseanetWebTestCaseAuthenticatedAbstract.class.inc';
class BasTest extends \PhraseanetWebTestCaseAuthenticatedAbstract
{
protected $client;
protected $StubbedACL;
public function createApplication()
{
$app = require __DIR__ . '/../../../../../lib/Alchemy/Phrasea/Application/Admin.php';
$app['debug'] = true;
unset($app['exception_handler']);
return $app;
}
public function setUp()
{
parent::setUp();
$this->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' => '<?xml version="1.0" encoding="UTF-8"?> <baseprefs> <status>0</status> <sugestedValues> <Object> <value>aa</value> </Object> </sugestedValues> </baseprefs>'
), 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) {
}
}
}

View File

@@ -0,0 +1,30 @@
<?php
require_once __DIR__ . '/../../../../PhraseanetWebTestCaseAuthenticatedAbstract.class.inc';
class ConnectedUserTest extends \PhraseanetWebTestCaseAuthenticatedAbstract
{
protected $client;
public function createApplication()
{
$app = require __DIR__ . '/../../../../../lib/Alchemy/Phrasea/Application/Admin.php';
$app['debug'] = true;
unset($app['exception_handler']);
return $app;
}
public function setUp()
{
parent::setUp();
$this->client = $this->createClient();
}
public function testgetSlash()
{
$this->client->request('GET', '/connected-users/');
$this->assertTrue($this->client->getResponse()->isOk());
}
}

View File

@@ -1,185 +0,0 @@
<?php
require_once __DIR__ . '/../../../../PhraseanetWebTestCaseAuthenticatedAbstract.class.inc';
class DashboardTest extends \PhraseanetWebTestCaseAuthenticatedAbstract
{
protected $client;
public function createApplication()
{
$app = require __DIR__ . '/../../../../../lib/Alchemy/Phrasea/Application/Admin.php';
$app['debug'] = true;
unset($app['exception_handler']);
return $app;
}
public function setUp()
{
parent::setUp();
$this->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());
}
}

View File

@@ -0,0 +1,446 @@
<?php
require_once __DIR__ . '/../../../../PhraseanetWebTestCaseAuthenticatedAbstract.class.inc';
class DatabaseTest extends \PhraseanetWebTestCaseAuthenticatedAbstract
{
protected $client;
protected $StubbedACL;
public function createApplication()
{
$app = require __DIR__ . '/../../../../../lib/Alchemy/Phrasea/Application/Admin.php';
$app['debug'] = true;
unset($app['exception_handler']);
return $app;
}
public function setUp()
{
parent::setUp();
$this->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);
}
}

View File

@@ -0,0 +1,80 @@
<?php
require_once __DIR__ . '/../../../../PhraseanetWebTestCaseAuthenticatedAbstract.class.inc';
class DatabasesTest extends \PhraseanetWebTestCaseAuthenticatedAbstract
{
protected $client;
protected $StubbedACL;
public function createApplication()
{
$app = require __DIR__ . '/../../../../../lib/Alchemy/Phrasea/Application/Admin.php';
$app['debug'] = true;
unset($app['exception_handler']);
return $app;
}
public function setUp()
{
parent::setUp();
$this->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/');
}
}

View File

@@ -198,7 +198,7 @@ class DescriptionTest extends \PhraseanetWebTestCaseAuthenticatedAbstract
$appbox = $this->app['phraseanet.appbox']; $appbox = $this->app['phraseanet.appbox'];
$session = $appbox->get_session(); $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); $session->authenticate($auth);
$databox = array_shift($appbox->get_databoxes()); $databox = array_shift($appbox->get_databoxes());
@@ -231,7 +231,7 @@ class DescriptionTest extends \PhraseanetWebTestCaseAuthenticatedAbstract
$appbox = $this->app['phraseanet.appbox']; $appbox = $this->app['phraseanet.appbox'];
$session = $appbox->get_session(); $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); $session->authenticate($auth);
$databox = array_shift($appbox->get_databoxes()); $databox = array_shift($appbox->get_databoxes());

View File

@@ -0,0 +1,77 @@
<?php
require_once __DIR__ . '/../../../../PhraseanetWebTestCaseAuthenticatedAbstract.class.inc';
class SetupTest extends \PhraseanetWebTestCaseAuthenticatedAbstract
{
protected $client;
protected $StubbedACL;
public function createApplication()
{
$app = require __DIR__ . '/../../../../../lib/Alchemy/Phrasea/Application/Admin.php';
$app['debug'] = true;
unset($app['exception_handler']);
return $app;
}
public function setUp()
{
parent::setUp();
$this->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());
}
}

View File

@@ -0,0 +1,77 @@
<?php
require_once __DIR__ . '/../../../../PhraseanetWebTestCaseAuthenticatedAbstract.class.inc';
class SphinxTest extends \PhraseanetWebTestCaseAuthenticatedAbstract
{
protected $client;
protected $StubbedACL;
public function createApplication()
{
$app = require __DIR__ . '/../../../../../lib/Alchemy/Phrasea/Application/Admin.php';
$app['debug'] = true;
unset($app['exception_handler']);
return $app;
}
public function setUp()
{
parent::setUp();
$this->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());
}
}

View File

@@ -34,14 +34,14 @@ class ControllerSubdefsTest extends \PhraseanetWebTestCaseAuthenticatedAbstract
$this->assertTrue($this->client->getResponse()->isOk()); $this->assertTrue($this->client->getResponse()->isOk());
} }
public function getName() public function getSubdefName()
{ {
return 'testname' . time() . mt_rand(10000, 99999); return 'testname' . time() . mt_rand(10000, 99999);
} }
public function testPostRouteAddSubdef() public function testPostRouteAddSubdef()
{ {
$name = $this->getName(); $name = $this->getSubdefName();
$this->client->request("POST", "/subdefs/" . $this->databox->get_sbas_id() . "/", array('add_subdef' => array( $this->client->request("POST", "/subdefs/" . $this->databox->get_sbas_id() . "/", array('add_subdef' => array(
'class' => 'thumbnail', 'class' => 'thumbnail',
'name' => $name, 'name' => $name,
@@ -56,7 +56,7 @@ class ControllerSubdefsTest extends \PhraseanetWebTestCaseAuthenticatedAbstract
public function testPostRouteDeleteSubdef() public function testPostRouteDeleteSubdef()
{ {
$subdefs = $this->databox->get_subdef_structure(); $subdefs = $this->databox->get_subdef_structure();
$name = $this->getName(); $name = $this->getSubdefName();
$subdefs->add_subdef("image", $name, "thumbnail"); $subdefs->add_subdef("image", $name, "thumbnail");
$this->client->request("POST", "/subdefs/" . $this->databox->get_sbas_id() . "/", array('delete_subdef' => 'image_' . $name)); $this->client->request("POST", "/subdefs/" . $this->databox->get_sbas_id() . "/", array('delete_subdef' => 'image_' . $name));
$this->assertTrue($this->client->getResponse()->isRedirect()); $this->assertTrue($this->client->getResponse()->isRedirect());
@@ -71,7 +71,7 @@ class ControllerSubdefsTest extends \PhraseanetWebTestCaseAuthenticatedAbstract
public function testPostRouteAddSubdefWithNoParams() public function testPostRouteAddSubdefWithNoParams()
{ {
$subdefs = $this->databox->get_subdef_structure(); $subdefs = $this->databox->get_subdef_structure();
$name = $this->getName(); $name = $this->getSubdefName();
$subdefs->add_subdef("image", $name, "thumbnail"); $subdefs->add_subdef("image", $name, "thumbnail");
$this->client->request("POST", "/subdefs/" . $this->databox->get_sbas_id() . "/" $this->client->request("POST", "/subdefs/" . $this->databox->get_sbas_id() . "/"
, array('subdefs' => array( , array('subdefs' => array(

View File

@@ -1,725 +0,0 @@
<?php
/*
* This file is part of Phraseanet
*
* (c) 2005-2012 Alchemy
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
use Symfony\Component\HttpFoundation\File\File as SymfoFile;
/**
*
* @license http://opensource.org/licenses/gpl-3.0 GPLv3
* @link www.phraseanet.com
*/
/* @var $Core \Alchemy\Phrasea\Core */
$Core = require_once __DIR__ . "/../../lib/bootstrap.php";
$appbox = appbox::get_instance($Core);
$session = $appbox->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'] = '<div style="color:#FF0000">' . _('admin::base:collection le fichier envoye est trop volumineux.') . ' 64Ko </div>';
} elseif ($_FILES['newLogo']['error']) {
$msg['SENDMINILOGO'] = '<div style="color:#FF0000">' . _('forms::erreur lors de l\'envoi du fichier') . '</div>';
} 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'] = '<div style="color:#FF0000">' . _('admin::base:collection le fichier envoye est trop volumineux.') . " 64Ko" . "</div>";
} elseif ($_FILES['newWm']['error']) {
$msg['SENDWM'] = '<div style="color:#FF0000">' . _('forms::erreur lors de l\'envoi du fichier') . "</div>"; // 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'] = '<div style="color:#FF0000">' . $e->getMessage() . "</div>";
}
unlink($_FILES['newWm']["tmp_name"]);
}
} elseif ($parm['act'] == "DELWM") {
try {
$appbox->write_collection_pic($collection, null, collection::PIC_WM);
} catch (Exception $e) {
$msg['DELWM'] = '<div style="color:#FF0000">' . $e->getMessage() . "</div>";
}
}
break;
case 'SENDSTAMPLOGO':
if (isset($_FILES['newStampLogo'])) {
if ($_FILES['newStampLogo']['size'] > 1024 * 1024) {
$msg['SENDSTAMPLOGO'] = '<div style="color:#FF0000">' . _('admin::base:collection le fichier envoye est trop volumineux.') . ' 1Mo </div>';
} elseif ($_FILES['newStampLogo']['error']) {
$msg['SENDSTAMPLOGO'] = '<div style="color:#FF0000">' . _('forms::erreur lors de l\'envoi du fichier') . '</div>'; // 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'] = '<div style="color:#FF0000">' . $e->getMessage() . "</div>";
}
unlink($_FILES['newStampLogo']["tmp_name"]);
}
}
break;
case 'DELSTAMPLOGO':
try {
$appbox->write_collection_pic($collection, null, collection::PIC_STAMP);
} catch (Exception $e) {
$msg['DELSTAMPLOGO'] = '<div style="color:#FF0000">' . $e->getMessage() . "</div>";
}
break;
case 'SENDPRESENTPICT':
if (isset($_FILES['newPresentPict'])) {
if ($_FILES['newPresentPict']['size'] > 1024 * 1024 * 2) {
$msg['SENDPRESENTPICT'] = '<div style="color:#FF0000">' . _('admin::base:collection le fichier envoye est trop volumineux.') . ' 2Mo </div>';
} elseif ($_FILES['newPresentPict']['error']) {
$msg['SENDPRESENTPICT'] = '<div style="color:#FF0000">' . _('forms::erreur lors de l\'envoi du fichier') . '</div>'; // 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'] = '<div style="color:#FF0000">' . $e->getMessage() . "</div>";
}
unlink($_FILES['newPresentPict']["tmp_name"]);
}
}
break;
case 'DELPRESENTPICT':
try {
$appbox->write_collection_pic($collection, null, collection::PIC_PRESENTATION);
} catch (Exception $e) {
$msg['DELPRESENTPICT'] = '<div style="color:#FF0000">' . $e->getMessage() . "</div>";
}
@unlink($registry->get('GV_RootPath') . 'config/presentation/' . $base_id);
break;
}
function showMsg($k)
{
global $msg;
if (isset($msg[$k]))
echo($msg[$k]);
}
phrasea::headers();
?>
<html lang="<?php echo $session->get_I18n(); ?>">
<head>
<link type="text/css" rel="stylesheet" href="/include/minify/f=include/jslibs/jquery-ui-1.8.17/css/ui-lightness/jquery-ui-1.8.17.custom.css,skins/common/main.css,skins/admin/admincolor.css" />
<script type="text/javascript" src="/include/minify/f=include/jslibs/jquery-1.7.1.js"></script>
<script type="text/javascript" src="/include/jslibs/jquery-ui-1.8.17/js/jquery-ui-1.8.17.custom.min.js"></script>
<script type="text/javascript">
var ntask = 0 ;
function sendForm(act)
{
document.forms["manageColl"].target = "";
document.forms["manageColl"].act.value = act;
document.forms["manageColl"].submit();
}
function emptyColl(collname)
{
if(confirm("<?php echo _('admin::base:collection: etes vous sur de vider la collection ?') ?>"))
{
$.ajax({
type: "POST",
url: "/admin/adminFeedback.php?action=EMPTYCOLL",
dataType: 'json',
data: {
sbas_id:<?php echo $sbas_id ?>,
coll_id:<?php echo $distant_coll_id ?>
},
success: function(data){
alert(data.message);
return;
}
});
}
}
function askUnmountColl()
{
if(confirm("<?php echo _('admin::base:collection: etes vous sur de demonter cette collection ?') ?>"))
sendForm('UMOUNTCOLL');
}
function showDetails(sta)
{
document.forms["manageColl"].sta.value = sta;
sendForm('');
}
function enabledPublication(bool)
{
if(bool)
{
if(confirm("<?php echo _('admin::base:collection: etes vous sur de publier cette collection ?') ?>"))
sendForm('ENABLED');
}
else
{
if(confirm("<?php echo _('admin::base:collection: etes vous sur darreter la publication de cette collection') ?>"))
sendForm('DISABLED');
}
}
<?php
if ($refreshFinder) {
print(" parent.reloadTree('base:" . $sbas_id . "');\n");
}
?>
</script>
<style>
.logo_boxes
{
margin:5px 5px 5px 10px;
padding-top:5px;
border-top:2px solid black;
}
a:link,a:visited{
text-decoration:none;
color:#666;
}
a:hover{
text-decoration:underline;
color:black;
}
</style>
<style>
.ui-autocomplete {
max-height: 200px;
overflow-y: auto;
/* prevent horizontal scrollbar */
overflow-x: hidden;
/* add padding to account for vertical scrollbar */
padding-right: 20px;
}
/* IE 6 doesn't support max-height
* we use height instead, but this forces the menu to always be this tall
*/
* html .ui-autocomplete {
height: 200px;
}
.ui-autocomplete-loading { background: white url('/skins/icons/ui-anim_basic_16x16.gif') right center no-repeat; }
</style>
<script type="text/javascript">
$(document).ready(function(){
$( ".admin_adder" ).autocomplete({
source: "/admin/users/typeahead/search/?have_not_right[]=order_master&on_base[]=<?php echo $base_id; ?>",
minLength: 2,
select: function( event, ui ) {
var form = $('#admin_adder');
$('input[name="admins[]"]:last', form).val(ui.item.id);
form.submit();
}
}).data( "autocomplete" )._renderItem = function( ul, item ) {
var email = item.email ? '<br/>'+item.email : '';
var login = item.login != item.name ? " ("+ item.login +")" : '';
return $( "<li></li>" )
.data( "item.autocomplete", item )
.append( "<a>" + item.name + login + email + "</a>" )
.appendTo( ul );
};
});
</script>
</head>
<body>
<h1>
<?php echo _('phraseanet:: collection'); ?> <b><?php echo $collection->get_name(); ?></b>
</h1>
<div style='margin:3px 0 3px 10px;'>
<?php echo _('phraseanet:: adresse'); ?> : <?php echo $addr; ?>&nbsp;
</div>
<?php showMsg('ACTDONE') ?>
<div style='margin:3px 0 3px 10px;'>
<?php echo _('admin::base:collection: numero de collection distante'); ?> : <?php echo $distant_coll_id; ?>&nbsp;
</div>
<div style="margin:3px 0 3px 10px;">
<?php echo _('admin::base:collection: etat de la collection') . " : " . ( $collection->is_active() ? _('admin::base:collection: activer la collection') : _('admin::base:collection: descativer la collection') ) ?>&nbsp;
</div>
<div style="margin:3px 0 3px 10px;">
<?php
echo $collection->get_record_amount() . ' records' . "\n";
if ($parm["sta"] == "" || $parm["sta"] == NULL || $parm["sta"] == 0) {
?>
(<a href="javascript:void(0);" onclick="showDetails(1);return(false);">
<?php echo _('phraseanet:: details') ?>
</a>)
<br />
<?php
} else {
$trows = $collection->get_record_details();
?>
(<a href="javascript:void(0);" onclick="showDetails(0);return(false);">
<?php echo _('admin::base: masquer les details') ?>
</a>)
<br />
<br />
<table class="ulist">
<col width=180px>
<col width=100px>
<col width=60px>
<col width=80px>
<col width=70px>
<thead>
<tr>
<th>
<?php
if ($parm["srt"] == "obj")
print('<img src="/skins/icons/tsort_desc.gif">&nbsp;');
print(_('admin::base: objet'));
?>
</th>
<th>
<?php echo _('admin::base: nombre') ?>
</th>
<th>
<?php echo _('admin::base: poids') ?> (Mo)
</th>
<th>
<?php echo _('admin::base: poids') ?> (Go)
</th>
</tr>
</thead>
<tbody>
<?php
$totobj = 0;
$totsiz = "0"; // les tailles de fichiers sont calculees avec bcmath
foreach ($trows as $vrow) {
$midobj = 0;
$midsiz = "0";
$last_k1 = $last_k2 = null;
if ($vrow["amount"] > 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);
?>
<tr>
<td>
<?php
if ($last_k2 !== $vrow["name"]) {
print($last_k2 = $vrow["name"]);
}
?>
</td>
<td style="text-align:right">
&nbsp;
<?php echo $vrow["amount"] ?>
&nbsp;
</td>
<td style="text-align:right">
&nbsp;
<?php printf("%.2f", $mega) ?>
&nbsp;
</td>
<td style="text-align:right">
&nbsp;
<?php sprintf("%.2f", $giga) ?>
&nbsp;
</td>
</tr>
<?php
}
$totobj += $midobj;
if (extension_loaded("bcmath"))
$totsiz = bcadd($totsiz, $midsiz, 0);
else
$totsiz += $midsiz;
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);
?>
<tr>
<td style="text-align:right">
<i>total</i>
</td>
<td style="text-align:right; TEXT-DECORATION:overline">
&nbsp;
<?php echo $midobj ?>
&nbsp;
</td>
<td style="text-align:right; TEXT-DECORATION:overline">
&nbsp;
<?php printf("%.2f", $mega) ?>
&nbsp;
</td>
<td style="text-align:right; TEXT-DECORATION:overline">
&nbsp;
<?php printf("%.2f", $giga) ?>
&nbsp;
</td>
</tr>
<tr>
<td colspan="4">
<hr />
</td>
</tr>
<?php
}
if (extension_loaded("bcmath"))
$mega = bcdiv($totsiz, 1024 * 1024, 5);
else
$mega = $totsiz / (1024 * 1024);
if (extension_loaded("bcmath"))
$giga = bcdiv($totsiz, 1024 * 1024 * 1024, 5);
else
$giga = $totsiz / (1024 * 1024 * 1024);
?>
<tr>
<td colspan="" style="text-align:right">
<b>total</b>
</td>
<td style="text-align:right;">
&nbsp;
<b><?php echo $totobj ?></b>
&nbsp;
</td>
<td style="text-align:right;">
&nbsp;
<b><?php printf("%.2f", $mega) ?></b>
&nbsp;
</td>
<td style="text-align:right;">
&nbsp;
<b><?php printf("%.2f", $giga) ?></b>
&nbsp;
</td>
</tr>
</tbody>
</table>
<?php
}
?>
</div>
<?php
if ($ACL->has_right_on_base($base_id, 'manage')) {
$pub_wm = $collection->get_pub_wm();
?>
<form id="admin_adder" action="/admin/collection.php" method="post">
<input type="hidden" name="p0" value="<?php echo $sbas_id ?>" />
<input type="hidden" name="p1" value="<?php echo $base_id ?>" />
<?php echo _('admin::collection:: Gestionnaires des commandes') ?>
<div>
<?php
$query = new User_Query($appbox);
$admins = $query->on_base_ids(array($base_id))
->who_have_right(array('order_master'))
->execute()->get_results();
foreach ($admins as $usr_id => $user) {
?>
<div><input name="admins[]" type="checkbox" value="<?php echo $user->get_id() ?>" id="adm_<?php echo $user->get_id() ?>" checked /><label for="adm_<?php echo $user->get_id() ?>"><?php echo $user->get_display_name(); ?></label></div>
<?php
}
?>
<div><?php echo _('setup:: ajouter un administrateur des commandes') ?></div>
<input class="admin_adder"/>
<input type="hidden" name="admins[]"/>
<input type="submit" value="<?php echo _('boutton::valider') ?>" />
</div>
</form>
<form method="post" name="manageColl" action="./collection.php" target="???" onsubmit="return(false);" ENCTYPE="multipart/form-data" >
<input type="hidden" name="srt" value="<?php echo $parm["srt"] ?>" />
<input type="hidden" name="ord" value="<?php echo $parm["ord"] ?>" />
<input type="hidden" name="act" value="???" />
<input type="hidden" name="p0" value="<?php echo $sbas_id ?>" />
<input type="hidden" name="p1" value="<?php echo $base_id ?>" />
<input type="hidden" name="sta" value="<?php echo $parm["sta"] ?>" />
<?php echo _('admin::collection:: presentation des elements lors de la diffusion aux utilisateurs externes (publications)') ?>
<div>
<input type='radio' name='pub_wm' onchange="sendForm('pub_wm');return(false);" <?php echo ($pub_wm == 'none' ? 'checked' : '') ?> value='none' /> <?php echo _('admin::colelction::presentation des elements : rien') ?>
<input type='radio' name='pub_wm' onchange="sendForm('pub_wm');return(false);" <?php echo ($pub_wm == 'wm' ? 'checked' : '') ?> value='wm' /> <?php echo _('admin::colelction::presentation des elements : watermark') ?>
<input type='radio' name='pub_wm' onchange="sendForm('pub_wm');return(false);" <?php echo ($pub_wm == 'stamp' ? 'checked' : '') ?> value='stamp' /> <?php echo _('admin::colelction::presentation des elements : stamp') ?>
</div>
<div style='margin:13px 0 3px 10px;'>
<a href="javascript:void();return(false);" onclick="sendForm('ASKRENAMECOLL');return(false);">
<img src="/skins/icons/edit_0.gif" style='vertical-align:middle'/>
<?php echo _('admin::base:collection: renommer la collection') ?>
</a>
<?php
if ($parm['act'] == "ASKRENAMECOLL") {
?>
<div style='margin:13px 0 3px 10px;'>
<?php echo _('admin::base:collection: Nom de la nouvelle collection : ') ?>
<input type="text" name="p2" id="p2" value="<?php echo $collection->get_name(); ?>" />
<input type="button" value="<?php echo _('boutton::envoyer') ?>" onclick="sendForm('APPLYNEWNAMECOLL');"/>
<input type="button" value="<?php echo _('boutton::annuler') ?>" onclick="sendForm('');"/>
</div>
<?php
} else {
?>
<input type="hidden" name="p2" value="<?php echo $parm["p2"] ?>" />
<?php
}
?>
</div>
<div style='margin:13px 0 3px 10px;'>
<a href="javascript:void();return(false);" onclick="enabledPublication(<?php echo($collection->is_active() ? "false" : "true") ?>);return(false);">
<img src='/skins/icons/db-remove.png' style='vertical-align:middle'/>
<?php echo( $collection->is_active() ? _('admin::base:collection: descativer la collection') : _('admin::base:collection: activer la collection')) ?>
</a>
</div>
<div style='margin:3px 0 3px 10px;'>
<a href="javascript:void();return(false);" onclick="emptyColl('<?php p4string::MakeString($collection->get_name(), "js") ?>');return(false);">
<img src='/skins/icons/trash.png' style='vertical-align:middle'/>
<?php echo _('admin::base:collection: vider la collection') ?>
</a>
</div>
<div style='margin:3px 0 3px 10px;'>
<a href="javascript:void();return(false);" onclick="sendForm('ASKDELETECOLL');return(false);">
<img src='/skins/icons/delete.gif' style='vertical-align:middle'/>
<?php echo _('boutton::supprimer') ?>
</a>
</div>
<?php
if ($parm['act'] == "ASKDELETECOLL") {
?>
<div style='margin:13px 0 3px 10px;'>
<?php echo _('admin::collection: Confirmez vous la suppression de cette collection ?') ?><br/>
<div style='margin:5px 0;'>
<input type="button" value="<?php echo _('boutton::valider') ?>" onclick="sendForm('DODELETECOLL');"/>
<input type="button" value="<?php echo _('boutton::annuler') ?>" onclick="sendForm('');"/>
</div>
</div>
<?php
}
}
?>
<div class='logo_boxes'>
<div style="font-size:11px;font-weight:bold;margin:0px 3px 10px 0px;">
<?php echo _('admin::base:collection: minilogo actuel') ?> :
<?php showMsg('SENDMINILOGO') ?>
</div>
<?php
if ($ACL->has_right_on_base($base_id, 'manage')) {
if (file_exists($registry->get('GV_RootPath') . 'config/minilogos/' . $base_id)) {
?>
<div style='margin:0 0 5px 0;'>
<?php echo $collection->getLogo($base_id) ?>
<a href="javascript:void();return(false);" onclick="sendForm('DELMINILOGO');return(false);">
<?php echo _('boutton::supprimer') ?>
</a>
</div>
<?php
} else {
?>
<!-- <?php echo _('admin::base:collection: aucun fichier (minilogo, watermark ...)') ?><br /><br /> -->
<input name="newLogo" type="file" />
<input type="button" value="<?php echo _('boutton::envoyer') ?>" onclick="sendForm('SENDMINILOGO');"/>
<?php
}
}
?>
</div>
<div class='logo_boxes'>
<div style="font-size:11px;font-weight:bold;margin:0px 3px 10px 0px;">
Watermark :
<?php showMsg('SENDWM') ?>
</div>
<?php
if ($ACL->has_right_on_base($base_id, 'manage')) {
if (file_exists($registry->get('GV_RootPath') . 'config/wm/' . $collection->get_base_id())) {
?>
<div style='margin:0 0 5px 0;'>
<?php echo $collection->getWatermark($base_id) ?>
<a href="javascript:void();return(false);" onclick="sendForm('DELWM');return(false);">
<?php echo _('boutton::supprimer') ?>
</a>
</div>
<?php
} else {
?>
<!-- <?php echo _('admin::base:collection: aucun fichier (minilogo, watermark ...)') ?><br /><br /> -->
<input name="newWm" type="file" />
<input type="button" value="<?php echo _('boutton::envoyer') ?>" onclick="sendForm('SENDWM');"/>
<?php
}
}
?>
</div>
<div class='logo_boxes'>
<div style="font-size:11px;font-weight:bold;margin:0px 3px 10px 0px;">
StampLogo :
<?php showMsg('SENDSTAMPLOGO') ?>
</div>
<?php
if ($ACL->has_right_on_base($base_id, 'manage')) {
if (file_exists($registry->get('GV_RootPath') . 'config/stamp/' . $base_id)) {
?>
<div style='margin:0 0 5px 0;'>
<?php echo $collection->getStamp($base_id) ?>
<a href="javascript:void();return(false);" onclick="sendForm('DELSTAMPLOGO');return(false);">
<?php echo _('boutton::supprimer') ?>
</a>
</div>
<?php
} else {
?>
<input name="newStampLogo" type="file" />
<input type='button' value="<?php echo _('boutton::envoyer') ?>" onclick="sendForm('SENDSTAMPLOGO');"/>
<?php
}
}
?>
</div>
<div class='logo_boxes'>
<div style="font-size:11px;font-weight:bold;margin:0px 3px 10px 0px;">
<?php echo _('admin::base:collection: image de presentation : ') ?>
<?php showMsg('SENDPRESENTPICT') ?>
</div>
<?php
if ($ACL->has_right_on_base($base_id, 'manage')) {
if (file_exists($registry->get('GV_RootPath') . 'config/presentation/' . $base_id)) {
?>
<div style='margin:0 0 5px 0;'>
<?php echo $collection->getPresentation($base_id) ?>
<a href="javascript:void();return(false);" onclick="sendForm('DELPRESENTPICT');return(false);">
<?php echo _('boutton::supprimer') ?>
</a>
</div>
<?php
} else {
?>
<input name="newPresentPict" type="file" />
<input type="button" value="<?php echo _('boutton::envoyer') ?>" onclick="sendForm('SENDPRESENTPICT');return(false);"/>
<br/>( max : 650x200 )
<?php
}
}
?>
</div>
</form>
</body>
</html>

View File

@@ -1,702 +0,0 @@
<?php
/*
* This file is part of Phraseanet
*
* (c) 2005-2012 Alchemy
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
use Symfony\Component\HttpFoundation\File\File as SymfoFile;
/**
*
* @license http://opensource.org/licenses/gpl-3.0 GPLv3
* @link www.phraseanet.com
*/
/* @var $Core \Alchemy\Phrasea\Core */
$Core = require_once __DIR__ . "/../../lib/bootstrap.php";
$appbox = appbox::get_instance($Core);
$session = $appbox->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;
}
}
?>
<script type="text/javascript">
<?php
if ($parm['act']) {
print("reloadTree('base:" . $parm['p0'] . "');");
}
?>
function sendLogopdf()
{
document.forms["flpdf"].target = "";
document.forms["flpdf"].act.value = "SENDLOGOPDF";
$('form[name="flpdf"]').trigger('submit');
}
function deleteLogoPdf()
{
if(confirm("<?php echo _('admin::base: Supprimer le logo pour impression') ?>"))
{
$.ajax({
type: "POST",
url: "/admin/adminFeedback.php",
dataType: 'json',
data: { action:"DELLOGOPDF", p0:<?php echo $sbas_id ?>},
success: function(data){
$("#printLogoDIV_OK").hide();
$("#printLogoDIV_NONE").show();
}
});
}
}
function reindex()
{
if(confirm('<?php echo str_replace("'", "\'", _('Confirmez-vous la re-indexation de la base ?')); ?>'))
{
$.ajax({
type: "POST",
url: "/admin/adminFeedback.php",
dataType: 'json',
data: { action:"REINDEX", sbas_id:<?php echo $sbas_id ?>},
success: function(data){
}
});
}
}
function makeIndexable(el)
{
$.ajax({
type: "POST",
url: "/admin/adminFeedback.php",
dataType: 'json',
data: { action:"DELLOGOPDF", p0:<?php echo $sbas_id ?>},
success: function(data){
$("#printLogoDIV_OK").hide();
$("#printLogoDIV_NONE").show();
}
});
}
function reindex()
{
if(confirm('<?php echo str_replace("'", "\'", _('Confirmez-vous la re-indexation de la base ?')); ?>'))
{
$.ajax({
type: "POST",
url: "/admin/adminFeedback.php",
dataType: 'json',
data: { action:"REINDEX", sbas_id:<?php echo $sbas_id ?>},
success: function(data){
}
});
}
}
function makeIndexable(el)
{
$.ajax({
type: "POST",
url: "/admin/adminFeedback.php",
dataType: 'json',
data: { action:"MAKEINDEXABLE", sbas_id:<?php echo $sbas_id ?>, INDEXABLE:(el.checked?'1':'') },
success: function(data){
}
});
}
var __viewname = ""; // global will be updated by refreshContent
function chgViewName()
{
if( (newAlias = prompt("<?php echo(_('admin::base: Alias')) ?> :", __viewname)) != null)
{
$.ajax({
type: "POST",
url: "/admin/adminFeedback.php",
dataType: 'json',
data: { action:"CHGVIEWNAME", sbas_id:<?php echo $sbas_id ?>, viewname:newAlias},
success: function(data){
}
});
}
}
function emptyBase()
{
if(confirm("<?php echo _('admin::base: Confirmer le vidage complet de la base') ?>"))
{
$.ajax({
type: "POST",
url: "/admin/adminFeedback.php?action=EMPTYBASE",
dataType: 'json',
data: { sbas_id:<?php echo $sbas_id ?> },
success: function(data){
alert(data.message);
}
});
}
}
function clearAllLog()
{
if(confirm("<?php echo _('admin::base: Confirmer la suppression de tous les logs') ?>"))
{
$.ajax({
type: "POST",
url: "/admin/adminFeedback.php",
dataType: 'json',
data: { action:"CLEARALLLOG", sbas_id:<?php echo $sbas_id ?>
},
success: function(data){
}
});
}
};
setTimeout("refreshContent();", 6000);
function deleteBase()
{
$.ajax({
type: "POST",
url: "/admin/adminFeedback.php",
dataType: 'json',
data: { action:"P_BAR_INFO", sbas_id:<?php echo $sbas_id ?> },
success: function(data){
if(data.records > 0)
{
alert("<?php echo(_('admin::base: vider la base avant de la supprimer')) ?>");
}
else
{
if(confirm("<?php echo _('admin::base: Confirmer la suppression de la base') ?>"))
{
$.ajax({
type: "POST",
url: "/admin/adminFeedback.php",
dataType: 'json',
data: { action:"DELETEBASE", sbas_id:<?php echo $sbas_id ?> },
success: function(data){
if(data.err == 0) // ok
{
parent.$("#TREE_DATABASES").trigger('click');
parent.reloadTree("bases");
}
else
{
if(data.errmsg)
alert(data.errmsg);
}
}
});
}
}
}
});
}
function clearAllLog()
{
if(confirm("<?php echo _('admin::base: Confirmer la suppression de tous les logs') ?>"))
{
$.ajax({
type: "POST",
url: "/admin/adminFeedback.php",
dataType: 'json',
data: { action:"CLEARALLLOG", sbas_id:<?php echo $sbas_id ?>
},
success: function(data){
}
});
}
}
function mountColl()
{
$('#mount_coll').toggle();
}
function activateColl()
{
$('#activate_coll').toggle();
}
function umountBase()
{
if(confirm("<?php echo _('admin::base: Confirmer vous l\'arret de la publication de la base') ?>"))
{
document.forms["manageDatabase"].target = "";
document.forms["manageDatabase"].act.value = "";
document.forms["manageDatabase"].sta.value = sta;
$('form[name="manageDatabase"]').trigger('submit');
}
}
function showDetails(sta)
{
document.forms["manageDatabase"].target = "";
document.forms["manageDatabase"].act.value = "";
document.forms["manageDatabase"].sta.value = sta;
$('form[name="manageDatabase"]').trigger('submit');
}
function chgOrd(srt)
{
document.forms["manageDatabase"].target = "";
document.forms["manageDatabase"].act.value = "";
document.forms["manageDatabase"].sta.value = "1";
document.forms["manageDatabase"].srt.value = srt;
$('form[name="manageDatabase"]').trigger('submit');
}
function refreshContent()
{
$.ajax({
type: "POST",
url: "/admin/adminFeedback.php",
dataType: 'json',
data: { action:"P_BAR_INFO", sbas_id:"<?php echo $sbas_id ?>"},
success: function(data){
__viewname = data.viewname;
if(data.viewname == '') {
$("#viewname").html("<i><?php echo(_('admin::base: aucun alias')) ?></i>");
} else {
$("#viewname").html("<b>"+data.viewname+"</b>");
}
$("#nrecords").text(data.records);
$("#is_indexable").attr('checked', data.indexable);
$("#xml_indexed").text(data.xml_indexed);
$("#thesaurus_indexed").text(data.thesaurus_indexed);
if(data.records > 0)
{
var p;
p = 100*data.xml_indexed/data.records;
$("#xml_indexed_bar").width(Math.round(2*p)); // 0..200px
$("#xml_indexed_percent").text((Math.round(p*100)/100)+" %");
p = 100*data.thesaurus_indexed/data.records;
$("#thesaurus_indexed_bar").width(Math.round(2*p));
$("#thesaurus_indexed_percent").text((Math.round(p*100)/100)+" %");
}
if(data.printLogoURL)
{
$("#printLogo").attr("src", data.printLogoURL);
$("#printLogoDIV_NONE").hide();
$("#printLogoDIV_OK").show();
}
else
{
$("#printLogoDIV_OK").hide();
$("#printLogoDIV_NONE").show();
}
}
});
}
$(document).ready(function(){
refreshContent();
});
</script>
<?php
$out = "";
?>
<div class="db_box">
<h2><?php echo $databox->get_serialized_server_info(); ?></h2>
<p>ID : <?php echo($sbas_id) ?></p>
<p>
<?php echo(_("admin::base: Alias")) ?> : <span id="viewname"></span>
<?php
if ($user->ACL()->has_right_on_sbas($sbas_id, "bas_manage")) {
?>
<img src="/skins/icons/edit_0.gif" onclick="chgViewName();return(false);" />
<?php
}
?>
</p>
</div>
<?php
$nrecords = $databox->get_record_amount();
$out .= "<p>";
// stats sur la base distante
$out .= _('admin::base: nombre d\'enregistrements sur la base :') . ' ' . '<span id="nrecords"></span> ';
if ((int) $parm["sta"] < 1) {
$out .= " (<a href=\"javascript:void(0);\" onclick=\"showDetails(1);return(false);\">" . _('phraseanet:: details') . "</a>)";
} else {
$unique_keywords = $databox->get_unique_keywords();
$out .= ", &nbsp;";
$out .= _('admin::base: nombre de mots uniques sur la base : ') . ' ' . $unique_keywords;
$indexes = $databox->get_index_amount();
$out .= ", &nbsp;";
$out .= _('admin::base: nombre de mots indexes sur la base') . ' ' . $indexes;
if ($registry->get('GV_thesaurus')) {
$thits = $databox->get_thesaurus_hits();
$out .= ", &nbsp;";
$out .= _('admin::base: nombre de termes de Thesaurus indexes :') . ' ' . $thits;
}
$out .= " (<a href=\"javascript:void(0);\" onclick=\"showDetails(0);return(false);\">" . _('admin::base: masquer les details') . "</a>)<br />\n";
$trows = $databox->get_record_details($parm['srt']);
$out .= "<table class=\"ulist\"><col width=180px><col width=100px><col width=60px><col width=80px><col width=70px>\n";
$out .= "<thead> <tr>";
$out .= "<th onClick=\"chgOrd('col');\">";
if ($parm["srt"] == "col")
$out .= "<img src=\"/skins/icons/tsort_desc.gif\">&nbsp;";
$out .= _('phraseanet:: collection') . "</th>";
$out .= "<th onClick=\"chgOrd('obj');\">";
if ($parm["srt"] == "obj")
$out .= "<img src=\"/skins/icons/tsort_desc.gif\">&nbsp;";
$out .= _('admin::base: objet') . "</th>";
$out .= "<th>" . _('admin::base: nombre') . "</th>";
$out .= "<th>" . _('admin::base: poids') . " (Mo)</th>";
$out .= "<th>" . _('admin::base: poids') . " (Go)</th>";
$out .= "</tr> </thead><tbody>";
$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 .= "<tr>\n";
if ($last_k1 !== $vrow["coll_id"]) {
if ((int) $vrow["lostcoll"] <= 0) {
$out .= "<td>" . $vrow["asciiname"] . "</td>\n";
} else {
$out .= "<td style=\"color:red\"><i>" . _('admin::base: enregistrements orphelins') . " </i>" . sprintf("(coll_id=%s)", $vrow["coll_id"]) . "</td>";
}
$last_k1 = $vrow["coll_id"];
} else {
$out .= "<td></td>\n";
}
if ($last_k2 !== $vrow["name"])
$out .= "<td>" . ($last_k2 = $vrow["name"]) . "</td>\n";
else
$out .= "<td></td>\n";
$out .= "<td style=\"text-align:right\">&nbsp;" . $vrow["n"] . "&nbsp;</td>\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 .= "<td style=\"text-align:right\">&nbsp;" . sprintf("%.2f", $mega) . "&nbsp;</td>\n";
$out .= "<td style=\"text-align:right\">&nbsp;" . sprintf("%.2f", $giga) . "&nbsp;</td>\n";
$out .= "</tr>\n";
}
// $last_k1 = null;
}
$totobj += $midobj;
if (extension_loaded("bcmath"))
$totsiz = bcadd($totsiz, $midsiz, 0);
else
$totsiz += $midsiz;
$out .= "<tr>\n";
$out .= "<td></td>\n";
$out .= "<td style=\"text-align:right\"><i>" . _('report:: total') . "</i></td>\n";
$out .= "<td style=\"text-align:right; TEXT-DECORATION:overline\">&nbsp;" . $midobj . "&nbsp;</td>\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 .= "<td style=\"text-align:right; TEXT-DECORATION:overline\">&nbsp;" . sprintf("%.2f", $mega) . "&nbsp;</td>\n";
$out .= "<td style=\"text-align:right; TEXT-DECORATION:overline\">&nbsp;" . sprintf("%.2f", $giga) . "&nbsp;</td>\n";
$out .= "</tr>\n";
$out .= "</tbody></table>";
$out .= "</p>";
}
}
print($out);
?>
<div id="INDEX_P_BAR">
<div style="height: 35px;">
<p>
<?php echo(_("admin::base: document indexes en utilisant la fiche xml")); ?> :
<span id="xml_indexed"></span>
</p>
<div id="xml_indexed_bar"></div>
<div id="xml_indexed_percent"></div>
</div>
<div style="height: 35px;">
<p>
<?php echo(_("admin::base: document indexes en utilisant le thesaurus")); ?> :
<span id="thesaurus_indexed"></span>
</p>
<div id="thesaurus_indexed_bar"></div>
<div id="thesaurus_indexed_percent"></div>
</div>
</div>
<?php
if ($user->ACL()->has_right_on_sbas($sbas_id, "bas_manage")) {
?>
<div style="margin: 9px 0;">
<label class="checkbox" for="is_indexable<?php echo($parm["p0"]); ?>">
<input type="checkbox" id="is_indexable" onclick="makeIndexable(this)" />
<?php echo(_("admin::base: Cette base est indexable")); ?>
</label>
<div id="make_indexable_ajax_status" style="display:none">&nbsp;</div>
</div>
<p>
<a onclick="reindex();return(false);">
<?php echo(_("base:: re-indexer")); ?>
</a>
</p>
<br />
<p>
<a href="newcoll.php?act=GETNAME&p0=<?php echo($parm["p0"]); ?>">
<img src="/skins/icons/create_coll.png" style="vertical-align:middle"/>
<?php echo(_("admin::base:collection: Creer une collection")); ?>
</a>
</p>
<?php
$mountable_colls = $databox->get_mountable_colls();
if (count($mountable_colls) > 0) {
?>
<p>
<a href="#" onclick="mountColl();">
<img src="/skins/icons/create_coll.png" style="vertical-align:middle" />
<?php echo(_("admin::base:collection: Monter une collection")); ?>
</a>
</p>
<div id="mount_coll" style="display:none;">
<form method="post" action="database.php" target="_self">
<select name="coll_id">
<?php
foreach ($mountable_colls as $coll_id => $name) {
?>
<option value="<?php echo $coll_id ?>"><?php echo $name ?></option>
<?php
}
?>
</select>
<?php
$colls = $user->ACL()->get_granted_base(array("canadmin"));
if (count($colls) > 0) {
?>
<p><?php echo _("admin::base:collection: Vous pouvez choisir une collection de reference pour donenr des acces ") ?></p>
<select name="othcollsel" >
<option><?php echo _("choisir") ?></option>
<?php
foreach ($colls as $base_id => $collection)
echo "<option value='" . $base_id . "'>" . $collection->get_name() . '</option>';
?>
</select>
<?php
}
?>
<input type="hidden" name="p0" value="<?php echo $sbas_id; ?>" />
<input type="hidden" name="act" value="MOUNT" />
<button type="submit" class="btn"><?php echo _("Monter"); ?></button>
</form>
</div>
<?php
}
$activable_colls = $databox->get_activable_colls();
if (count($activable_colls) > 0) {
?>
<p>
<a href="#" onclick="activateColl();">
<img src="/skins/icons/create_coll.png" style="vertical-align:middle"/>
<?php echo(_("Activer une collection")); ?>
</a>
</p>
<div id="activate_coll" style="display:none;">
<form method="post" action="database.php" target="_self">
<select name="base_id">
<?php
foreach ($activable_colls as $base_id) {
?>
<option value="<?php echo $base_id ?>"><?php echo phrasea::bas_names($base_id) ?></option>
<?php
}
?>
</select>
<input type="hidden" name="p0" value="<?php echo $sbas_id; ?>"/>
<input type="hidden" name="act" value="ACTIVATE"/>
<button type="submit"><?php echo _("Activer"); ?></button>
</form>
</div>
<?php
}
?>
<p>
<a onclick="clearAllLog();return(false);">
<img src="/skins/icons/clearLogs.png" style="vertical-align:middle"/>
<?php echo(_("admin::base: supprimer tous les logs")); ?>
</a>
</p>
<p>
<a onclick="umountBase();return(false);">
<img src="/skins/icons/db-remove.png" style="vertical-align:middle"/>
<?php echo(_("admin::base: arreter la publication de la base")); ?>
</a>
</p>
<p>
<a onclick="emptyBase();return(false);">
<img src="/skins/icons/trash.png" style="vertical-align:middle"/>
<?php echo(_("admin::base: vider la base")); ?>
</a>
</p>
<p>
<a onclick="deleteBase();return(false);">
<img src="/skins/icons/delete.gif" style="vertical-align:middle"/>
<?php echo(_("admin::base: supprimer la base")); ?>
</a>
</p>
<?php
}
?>
</div><!-- /db_box -->
<!-- minilogo pour print pdf -->
<div class="logo_box">
<hr>
<h4><?php echo(_("admin::base: logo impression PDF")) ?></h4>
<?php echo($printLogoUploadMsg) ?>
<div id="printLogoDIV_OK">
<img id="printLogo" src="/print/<?php echo $sbas_id ?>" />
<?php
if ($user->ACL()->has_right_on_sbas($sbas_id, "bas_manage")) {
?>
<a href="javascript:void();return(false);" onclick="deleteLogoPdf();return(false);">
<?php echo(_("admin::base:collection: supprimer le logo")) ?>
</a>
<?php
}
?>
</div>
<div id="printLogoDIV_NONE">
<?php echo(_("admin::base:collection: aucun fichier (minilogo, watermark ...)")) ?>
<form method="post" name="flpdf" action="./database.php" target="???" onsubmit="return(false);" ENCTYPE="multipart/form-data">
<input type="hidden" name="p0" value="<?php echo($parm["p0"]); ?>" />
<input type="hidden" name="sta" value="" />
<input type="hidden" name="srt" value="" />
<input type="hidden" name="act" value="" />
<input type="hidden" name="tid" value="" />
<?php
if ($user->ACL()->has_right_on_sbas($sbas_id, "bas_manage")) {
?>
<input name="newLogoPdf" type="file" />
<input type="button" class="btn" value="<?php echo(_("boutton::envoyer")); ?>" onclick="sendLogopdf();" />
<br />
<?php echo(_("admin::base: envoyer un logo (jpeg 35px de hauteur max)"));
}
?>
</form>
</div>
</div>
<form method="post" name="manageDatabase" action="./database.php" target="???">
<input type="hidden" name="p0" value="<?php echo($parm["p0"]) ?>" />
<input type="hidden" name="sta" value="0" />
<input type="hidden" name="srt" value="" />
<input type="hidden" name="act" value="???" />
<input type="hidden" name="tid" value="???" />
</form>

View File

@@ -1,455 +0,0 @@
<?php
/*
* This file is part of Phraseanet
*
* (c) 2005-2012 Alchemy
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
/**
*
* @license http://opensource.org/licenses/gpl-3.0 GPLv3
* @link www.phraseanet.com
*/
/* @var $Core \Alchemy\Phrasea\Core */
$Core = require_once __DIR__ . "/../../lib/bootstrap.php";
$appbox = appbox::get_instance($Core);
$session = $appbox->get_session();
$usr_id = $session->get_usr_id();
$user = User_Adapter::getInstance($usr_id, $appbox);
phrasea::headers();
?>
<html lang="<?php echo $session->get_I18n(); ?>">
<head>
<link type="text/css" rel="stylesheet" href="/include/minify/f=skins/common/main.css" />
<link type="text/css" rel="stylesheet" href="/include/minify/f=skins/admin/admincolor.css" />
<style type="text/css">
BODY
{
text-align:left;
}
A
{ COLOR : #000000; font-weight:900; TEXT-DECORATION: none}
A:hover
{ COLOR : #000000; font-weight:900; TEXT-DECORATION: underline}
A:link
{ COLOR : #000000; font-weight:900; TEXT-DECORATION: none}
A:visited
{ COLOR : #000000; font-weight:900; TEXT-DECORATION: none}
A:active
{ COLOR : #000000; font-weight:900; TEXT-DECORATION: none}
</style>
<script type="text/javascript">
function gostep3()
{
document.forms['importform2'].act.value = "STEP3";
document.forms['importform2'].submit();
}
function gostep1()
{
document.forms['importform2'].act.value = "";
document.forms['importform2'].submit();
}
function rloadusr()
{
parent.imp0rloadusr();
}
</script>
</head>
<body>
<?php
function read_csv($filename)
{
$separateur = ",";
// pb sinon qd venant de 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;
}
}
$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("<br /><font color=\"#FF0000\">ERROR : " . $_FILES['fileusers']['error'] . "</font><br />");
$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 ++;
}
}
}
?>
<div style="position:relative;top:20px">
<center>
<?php echo $nbcreation ?> users was created.
<br>
<br>
<script type="text/javascript">
parent.needrefresh = true;
</script>
<a href="javascript:self.close();" >Close</a>
</center>
</div>
<?php
} elseif ($parm["act"] == "STEP2" && isset($_FILES['fileusers'])) {
######### STEP 2 ##########################
?>
<div style="position:relative;"><a href="javascript:void(return false);" onclick="gostep1();return(false);"><< Back</a></div>
<small><br></small><center>
<?php
if ($_FILES['fileusers']['error'] == UPLOAD_ERR_OK)
$filename = $_FILES['fileusers']["tmp_name"];
$ARRAY = read_csv("$filename");
// on verifie les noms de colones
$logindefined = false;
$pwddefined = false;
$loginNew = NULL;
$out = "";
$nbusrToadd = 0;
for ($j = 0; $j < sizeof($ARRAY[0]); $j ++ ) { // affiche colonne par colonne
$ARRAY[0][$j] = mb_strtolower($ARRAY[0][$j]);
if ( ! isset($equivalenceToMysqlField[$ARRAY[0][$j]])) {
$out .= "<br> - 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.= "<br> - Row \"login\" is missing, script has stopped !";
if ( ! $pwddefined)
$outTmp.= "<br> - Row \"password\" is missing, script has stopped !";
if ($out != "")
$out.="\n<br> ";
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 \"<i><b>" . $loginToadd . "</b></i>\" is already defined in the file (line " . $loginNew[$loginToadd] . ").";
else {
if (User_Adapter::get_usr_id_from_login($loginToadd)) {
$out2.= " Login \"<i><b>" . $loginToadd . "</b></i>\" 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 .= "<br>Line " . ( $i + 1) . " :";
$out .= "$out2<br>";
}
else
$nbusrToadd ++;
}
}
}
}
if ($out != "") { // on affiche les erreurs
?>
<div style="color:#ffffff;background-color:#FF0000;font-size:11px;width:100px;"><b>&nbsp;Warning&nbsp;</b></div>
<div style="width:488px;height:120px; overflow:auto; border:#FF0000 1px solid;font-size:12px;padding:4px;text-align:left;">
<?php echo $out ?>
</div>
<?php
} else {
}
// le nombre d'ajout (non en erreur) et choix de quel "model" appliquer sur eux
echo "<br>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]);
/* -------------------------------------------------- */
?>
<br>
<form method="post" name="importform2" action="./import.php?u=<?php echo mt_rand() ?>" onsubmit="return(false);" ENCTYPE="multipart/form-data" >
<input type="hidden" name="act" value="" />
<textarea style="display:none;" name="sr"><?php echo serialize($ARRAY) ?></textarea>
<?php
if ($nbusrToadd > 0 && count($models) > 0) {
echo "<br>Select a model to apply on users :";
echo " <select name=\"modelToAplly\" >";
foreach ($models as $oneMod)
echo "<option value=\"" . $oneMod["usr_id"] . "\">" . $oneMod["usr_login"];
echo " </select>";
?>
<br><br><a href="javascript:self.close();" >Cancel</a> &nbsp;&nbsp;&nbsp;&nbsp; <a href="javascript:gostep3();">Add <?php echo $nbusrToadd ?> users</a>
<?php
} elseif (count($models) == 0) {
?>
<br>
<font color="#FF0000">you need define a model before importing a list of users.</font>
<br>
<br>
<a href="javascript:self.close();" >Close</a>
</center>
<?php
} else {
?>
<br>
<a href="javascript:self.close();" >Close</a>
</center>
<?php
}
?>
</form>
<?php
} else {
// On propose l'upload
?>
<center>
Upload a "csv" file CSV for users creation
<br>
<small>you can <a href="./exampleImportUsers.csv" target="_blank">download an example by clicking here</a><br />and <a href="./Fields.rtf" target="_blank">his documentation here</a></small>
<br><br>
<form method="post" name="importform" target="_self" action="./import.php?u=<?php echo mt_rand() ?>" onsubmit="return(false);" ENCTYPE="multipart/form-data" >
<input type="hidden" name="act" value="STEP2" />
User's file : <input name="fileusers" type="file" />
<br>
<br>
<br>
<br>
<a href="javascript:void();return(false);" onclick="document.forms['importform'].submit();return(false);">Send this file</a>
</form>
</center>
<?php
}
?>
</body>
</html>

View File

@@ -1,48 +0,0 @@
<?php
/*
* This file is part of Phraseanet
*
* (c) 2005-2012 Alchemy
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
/**
*
* @license http://opensource.org/licenses/gpl-3.0 GPLv3
* @link www.phraseanet.com
*/
/* @var $Core \Alchemy\Phrasea\Core */
$Core = require_once __DIR__ . "/../../lib/bootstrap.php";
$appbox = appbox::get_instance($Core);
$session = $appbox->get_session();
phrasea::headers();
?>
<html lang="<?php echo $session->get_I18n(); ?>">
<head>
<link type="text/css" rel="stylesheet" href="/include/minify/f=skins/common/main.css" />
<link type="text/css" rel="stylesheet" href="/include/minify/f=skins/admin/admincolor.css" />
<script type="text/javascript">
var needrefresh = false;
var oMyObject = parent.window.dialogArguments;
var myOpener = oMyObject.myOpener;
function imp0rloadusr()
{
myOpener.document.forms[0].action = "/admin/users/search/";
myOpener.document.forms[0].submit();
}
window.onbeforeunload = function()
{
if(needrefresh)
imrloadusr();
};
</script>
</head>
<body>
<iframe style="z-index:1; visibility:visible; position:absolute; top:0px; left:0px; width:543px; height:300px;border:0px" scrolling="yes" id="idHFrameIW" src="import.php" name="HFrameIW"></iframe>
</body>
</html>

View File

@@ -1,64 +0,0 @@
<?php
/*
* This file is part of Phraseanet
*
* (c) 2005-2012 Alchemy
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
/**
*
* @license http://opensource.org/licenses/gpl-3.0 GPLv3
* @link www.phraseanet.com
*/
require_once __DIR__ . "/../../lib/bootstrap.php";
$registry = registry::get_instance();
$request = http_request::getInstance();
$parms = $request->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)
);
?>
<form>
<select name="charset_tables[]" multiple="multiple">
<?php
foreach ($sphinx_conf->get_available_charsets() as $charset => $charset_obj) {
echo "<option value='" . $charset . "' " . (in_array($charset, $selected_charsets) ? "selected='selected'" : "") . ">" . $charset_obj->get_name() . "</option>";
}
?>
</select>
<select name="libstemmer[]" multiple="multiple">
<?php
foreach ($sphinx_conf->get_available_libstemmer() as $stemme) {
echo "<option value='" . $stemme . "' " . (in_array($stemme, $selected_libstemmer) ? "selected='selected'" : "") . ">" . $stemme . "</option>";
}
?>
</select>
<button type="submit">valide</button>
</form>
<textarea style="width:100%;height:70%">
<?php
echo $sphinx_conf->get_configuration($options);
?>
</textarea>