mirror of
https://github.com/alchemy-fr/Phraseanet.git
synced 2025-10-14 13:33:14 +00:00
V 3.5 RC 1
This commit is contained in:
71
lib/classes/Controller/Admin/Fields.class.php
Normal file
71
lib/classes/Controller/Admin/Fields.class.php
Normal file
@@ -0,0 +1,71 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of Phraseanet
|
||||
*
|
||||
* (c) 2005-2010 Alchemy
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
/**
|
||||
*
|
||||
* @package
|
||||
* @license http://opensource.org/licenses/gpl-3.0 GPLv3
|
||||
* @link www.phraseanet.com
|
||||
*/
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\HttpKernel\Exception\HttpException;
|
||||
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
|
||||
use Silex\Application;
|
||||
use Silex\ControllerProviderInterface;
|
||||
use Silex\ControllerCollection;
|
||||
|
||||
class Controller_Admin_Fields implements ControllerProviderInterface
|
||||
{
|
||||
|
||||
public function connect(Application $app)
|
||||
{
|
||||
$appbox = appbox::get_instance();
|
||||
$session = $appbox->get_session();
|
||||
// $session->close_storage();
|
||||
|
||||
$controllers = new ControllerCollection();
|
||||
|
||||
|
||||
$controllers->get('/checkmulti/', function() use ($app, $appbox)
|
||||
{
|
||||
$request = $app['request'];
|
||||
$multi = ($request->get('multi') === 'true');
|
||||
|
||||
$metadata = databox_field::load_class_from_xpath($request->get('source'));
|
||||
|
||||
$datas = array(
|
||||
'result' => ($multi === $metadata->is_multi())
|
||||
, 'is_multi' => $metadata->is_multi()
|
||||
);
|
||||
|
||||
return new Response(p4string::jsonencode($datas));
|
||||
});
|
||||
|
||||
$controllers->get('/checkreadonly/', function() use ($app, $appbox)
|
||||
{
|
||||
$request = $app['request'];
|
||||
$readonly = ($request->get('readonly') === 'true');
|
||||
|
||||
$metadata = databox_field::load_class_from_xpath($request->get('source'));
|
||||
|
||||
$datas = array(
|
||||
'result' => ($readonly === $metadata->is_readonly())
|
||||
, 'is_readonly' => $metadata->is_readonly()
|
||||
);
|
||||
|
||||
return new Response(p4string::jsonencode($datas));
|
||||
});
|
||||
|
||||
return $controllers;
|
||||
}
|
||||
|
||||
}
|
199
lib/classes/Controller/Admin/Publications.class.php
Normal file
199
lib/classes/Controller/Admin/Publications.class.php
Normal file
@@ -0,0 +1,199 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of Phraseanet
|
||||
*
|
||||
* (c) 2005-2010 Alchemy
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
/**
|
||||
*
|
||||
* @package
|
||||
* @license http://opensource.org/licenses/gpl-3.0 GPLv3
|
||||
* @link www.phraseanet.com
|
||||
*/
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\HttpKernel\Exception\HttpException;
|
||||
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
|
||||
use Silex\Application;
|
||||
use Silex\ControllerProviderInterface;
|
||||
use Silex\ControllerCollection;
|
||||
|
||||
class Controller_Admin_Publications implements ControllerProviderInterface
|
||||
{
|
||||
|
||||
public function connect(Application $app)
|
||||
{
|
||||
$appbox = appbox::get_instance();
|
||||
$session = $appbox->get_session();
|
||||
|
||||
$controllers = new ControllerCollection();
|
||||
|
||||
$controllers->get('/list/', function() use ($app, $appbox)
|
||||
{
|
||||
$user = User_Adapter::getInstance($appbox->get_session()->get_usr_id(), $appbox);
|
||||
$feeds = Feed_Collection::load_all($appbox, $user);
|
||||
|
||||
$template = 'admin/publications/list.html';
|
||||
|
||||
$twig = new supertwig();
|
||||
$twig->addFilter(array('formatdate' => 'phraseadate::getDate'));
|
||||
|
||||
return $twig->render($template, array('feeds' => $feeds));
|
||||
});
|
||||
|
||||
|
||||
$controllers->post('/create/', function() use ($app, $appbox)
|
||||
{
|
||||
|
||||
$user = User_Adapter::getInstance($appbox->get_session()->get_usr_id(), $appbox);
|
||||
$request = $app['request'];
|
||||
|
||||
$feed = Feed_Adapter::create($appbox, $user, $request->get('title'), $request->get('subtitle'));
|
||||
|
||||
if($request->get('public') == '1')
|
||||
$feed->set_public (true);
|
||||
elseif ($request->get('base_id'))
|
||||
$feed->set_collection(collection::get_from_base_id($request->get('base_id')));
|
||||
|
||||
return $app->redirect('/admin/publications/list/');
|
||||
});
|
||||
|
||||
|
||||
$controllers->get('/feed/{id}/', function($id) use ($app, $appbox)
|
||||
{
|
||||
$feed = new Feed_Adapter($appbox, $id);
|
||||
|
||||
$template = 'admin/publications/fiche.html';
|
||||
|
||||
$twig = new supertwig();
|
||||
$twig->addFilter(
|
||||
array(
|
||||
'formatdate' => 'phraseadate::getDate'
|
||||
)
|
||||
);
|
||||
|
||||
return $twig->render($template
|
||||
, array(
|
||||
'feed' => $feed
|
||||
, 'error' => $app['request']->get('error')
|
||||
)
|
||||
);
|
||||
});
|
||||
|
||||
|
||||
$controllers->post('/feed/{id}/update/', function($id) use ($app, $appbox)
|
||||
{
|
||||
|
||||
$feed = new Feed_Adapter($appbox, $id);
|
||||
$user = User_Adapter::getInstance($appbox->get_session()->get_usr_id(), $appbox);
|
||||
|
||||
if (!$feed->is_owner($user))
|
||||
return $app->redirect('/admin/publications/feed/' . $id . '/?error=' . _('You are not the owner of this feed, you can not edit it'));
|
||||
|
||||
$request = $app['request'];
|
||||
|
||||
try
|
||||
{
|
||||
$collection = collection::get_from_base_id($request->get('base_id'));
|
||||
}
|
||||
catch (Exception $e)
|
||||
{
|
||||
$collection = null;
|
||||
}
|
||||
|
||||
$feed->set_title($request->get('title'));
|
||||
$feed->set_subtitle($request->get('subtitle'));
|
||||
$feed->set_collection($collection);
|
||||
$feed->set_public($request->get('public'));
|
||||
|
||||
return $app->redirect('/admin/publications/list/');
|
||||
});
|
||||
|
||||
|
||||
$controllers->post('/feed/{id}/iconupload/', function($id) use ($app, $appbox)
|
||||
{
|
||||
$feed = new Feed_Adapter($appbox, $id);
|
||||
$user = User_Adapter::getInstance($appbox->get_session()->get_usr_id(), $appbox);
|
||||
|
||||
if (!$feed->is_owner($user))
|
||||
return new Response('ERROR:you are not allowed');
|
||||
|
||||
if ($_FILES['Filedata']['error'] !== 0)
|
||||
return new Response('ERROR:error while upload');
|
||||
|
||||
$file = new system_file($_FILES['Filedata']['tmp_name']);
|
||||
if (!in_array($file->get_mime(), array('image/jpeg', 'image/jpg', 'image/gif')))
|
||||
return new Response('ERROR:bad filetype');
|
||||
|
||||
if ($file->getSize() > 200000)
|
||||
return new Response('ERROR:file too large');
|
||||
|
||||
$datas = $file->get_technical_datas();
|
||||
if (!isset($datas[system_file::TC_DATAS_WIDTH]) || !isset($datas[system_file::TC_DATAS_HEIGHT]))
|
||||
return new Response('ERROR:file is not square');
|
||||
|
||||
if ($datas[system_file::TC_DATAS_WIDTH] != $datas[system_file::TC_DATAS_HEIGHT])
|
||||
return new Response('ERROR:file is not square');
|
||||
|
||||
$feed->set_icon($file);
|
||||
unlink($file->getPathname());
|
||||
|
||||
return new Response('FILEHREF:' . $feed->get_icon_url() . '?' . mt_rand(100000, 999999));
|
||||
});
|
||||
|
||||
$controllers->post('/feed/{id}/addpublisher/', function($id) use ($app, $appbox)
|
||||
{
|
||||
$error = '';
|
||||
try
|
||||
{
|
||||
$request = $app['request'];
|
||||
$user = User_Adapter::getInstance($request->get('usr_id'), $appbox);
|
||||
$feed = new Feed_Adapter($appbox, $id);
|
||||
$feed->add_publisher($user);
|
||||
}
|
||||
catch (Exception $e)
|
||||
{
|
||||
$error = $e->getMessage();
|
||||
}
|
||||
|
||||
return $app->redirect('/admin/publications/feed/' . $id . '/');
|
||||
});
|
||||
|
||||
|
||||
$controllers->post('/feed/{id}/removepublisher/', function($id) use ($app, $appbox)
|
||||
{
|
||||
try
|
||||
{
|
||||
$request = $app['request'];
|
||||
|
||||
$feed = new Feed_Adapter($appbox, $id);
|
||||
$publisher = new Feed_Publisher_Adapter($appbox, $request->get('publisher_id'));
|
||||
$user = $publisher->get_user();
|
||||
if ($feed->is_publisher($user) === true && $feed->is_owner($user) === false)
|
||||
$publisher->delete();
|
||||
}
|
||||
catch (Exception $e)
|
||||
{
|
||||
$error = $e->getMessage();
|
||||
}
|
||||
|
||||
return $app->redirect('/admin/publications/feed/' . $id . '/?err=' . $error);
|
||||
});
|
||||
|
||||
$controllers->post('/feed/{id}/delete/', function($id) use ($app, $appbox)
|
||||
{
|
||||
$feed = new Feed_Adapter($appbox, $id);
|
||||
$feed->delete();
|
||||
|
||||
return $app->redirect('/admin/publications/list/');
|
||||
})->assert('id', '\d+');
|
||||
|
||||
return $controllers;
|
||||
}
|
||||
|
||||
}
|
140
lib/classes/Controller/Admin/Subdefs.class.php
Normal file
140
lib/classes/Controller/Admin/Subdefs.class.php
Normal file
@@ -0,0 +1,140 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of Phraseanet
|
||||
*
|
||||
* (c) 2005-2010 Alchemy
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
/**
|
||||
*
|
||||
* @package
|
||||
* @license http://opensource.org/licenses/gpl-3.0 GPLv3
|
||||
* @link www.phraseanet.com
|
||||
*/
|
||||
class Controller_Admin_Subdefs
|
||||
{
|
||||
|
||||
/**
|
||||
*
|
||||
* @var databox
|
||||
*/
|
||||
protected $databox;
|
||||
|
||||
/**
|
||||
*
|
||||
* @param http_request $request
|
||||
* @param databox $databox
|
||||
* @return controller_admin_subdefs
|
||||
*/
|
||||
public function __construct(http_request $request, databox &$databox)
|
||||
{
|
||||
$this->databox = $databox;
|
||||
if ($request->has_post_datas())
|
||||
{
|
||||
$parm = $request->get_parms('delete_subdef', 'add_subdef', 'subdefs');
|
||||
|
||||
$add_subdef = array('class' => null, 'name' => null, 'group' => null);
|
||||
foreach ($add_subdef as $k => $v)
|
||||
{
|
||||
if (!isset($parm['add_subdef'][$k]) || trim($parm['add_subdef'][$k]) === '')
|
||||
unset($add_subdef[$k]);
|
||||
else
|
||||
$add_subdef[$k] = $parm['add_subdef'][$k];
|
||||
}
|
||||
|
||||
if ($parm['delete_subdef'])
|
||||
{
|
||||
$delete_subef = explode('_', $parm['delete_subdef']);
|
||||
$group = $delete_subef[0];
|
||||
$name = $delete_subef[1];
|
||||
|
||||
$subdefs = $this->databox->get_subdef_structure();
|
||||
$subdefs->delete_subdef($group, $name);
|
||||
}
|
||||
elseif (count($add_subdef) === 3)
|
||||
{
|
||||
$subdefs = $this->databox->get_subdef_structure();
|
||||
|
||||
$group = $add_subdef['group'];
|
||||
$name = $add_subdef['name'];
|
||||
$class = $add_subdef['class'];
|
||||
|
||||
$subdefs->add_subdef($group, $name, $class);
|
||||
}
|
||||
else
|
||||
{
|
||||
$subdefs = $this->databox->get_subdef_structure();
|
||||
|
||||
$options = array();
|
||||
|
||||
foreach ($parm['subdefs'] as $post_sub)
|
||||
{
|
||||
$post_sub_ex = explode('_', $post_sub);
|
||||
$group = $post_sub_ex[0];
|
||||
$name = $post_sub_ex[1];
|
||||
|
||||
$parm_loc = $request->get_parms($post_sub . '_class', $post_sub . '_downloadable');
|
||||
|
||||
$class = $parm_loc[$post_sub . '_class'];
|
||||
$downloadable = $parm_loc[$post_sub . '_downloadable'];
|
||||
|
||||
$defaults = array('path', 'baseurl', 'meta', 'mediatype');
|
||||
foreach ($defaults as $def)
|
||||
{
|
||||
$parm_loc = $request->get_parms($post_sub . '_' . $def);
|
||||
|
||||
if ($def == 'meta' && !$parm_loc[$post_sub . '_' . $def])
|
||||
{
|
||||
$parm_loc[$post_sub . '_' . $def] = "no";
|
||||
}
|
||||
|
||||
$options[$def] = $parm_loc[$post_sub . '_' . $def];
|
||||
}
|
||||
|
||||
$parm_loc = $request->get_parms($post_sub . '_mediatype');
|
||||
$mediatype = $parm_loc[$post_sub . '_mediatype'];
|
||||
$parm_loc = $request->get_parms($post_sub . '_' . $mediatype);
|
||||
|
||||
if (isset($parm_loc[$post_sub . '_' . $mediatype]))
|
||||
{
|
||||
foreach ($parm_loc[$post_sub . '_' . $mediatype] as $option => $value)
|
||||
{
|
||||
if ($option == 'resolution' && $mediatype == 'image')
|
||||
$option = 'dpi';
|
||||
$options[$option] = $value;
|
||||
}
|
||||
}
|
||||
$subdefs->set_subdef($group, $name, $class, $downloadable, $options);
|
||||
}
|
||||
}
|
||||
|
||||
return phrasea::redirect('/admin/subdefs.php?p0=' . $databox->get_sbas_id());
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return controller_admin_subdefs
|
||||
*/
|
||||
public function render()
|
||||
{
|
||||
|
||||
$twig = new supertwig();
|
||||
$twig->display(
|
||||
'admin/subdefs.twig',
|
||||
array(
|
||||
'databox' => $this->databox,
|
||||
'subdefs' => $this->databox->get_subdef_structure()
|
||||
)
|
||||
);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
}
|
367
lib/classes/Controller/Admin/Users.class.php
Normal file
367
lib/classes/Controller/Admin/Users.class.php
Normal file
@@ -0,0 +1,367 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of Phraseanet
|
||||
*
|
||||
* (c) 2005-2010 Alchemy
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
/**
|
||||
*
|
||||
* @package
|
||||
* @license http://opensource.org/licenses/gpl-3.0 GPLv3
|
||||
* @link www.phraseanet.com
|
||||
*/
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\HttpKernel\Exception\HttpException;
|
||||
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
|
||||
use Silex\Application;
|
||||
use Silex\ControllerProviderInterface;
|
||||
use Silex\ControllerCollection;
|
||||
|
||||
class Controller_Admin_Users implements ControllerProviderInterface
|
||||
{
|
||||
|
||||
public function connect(Application $app)
|
||||
{
|
||||
$appbox = appbox::get_instance();
|
||||
$session = $appbox->get_session();
|
||||
|
||||
$controllers = new ControllerCollection();
|
||||
|
||||
|
||||
$controllers->post('/rights/', function() use ($app)
|
||||
{
|
||||
$request = $app['request'];
|
||||
$rights = new module_admin_route_users_edit($request);
|
||||
|
||||
$template = 'admin/editusers.twig';
|
||||
$twig = new supertwig();
|
||||
$twig->addFilter(array('bas_name' => 'phrasea::bas_names'));
|
||||
$twig->addFilter(array('sbas_name' => 'phrasea::sbas_names'));
|
||||
$twig->addFilter(array('sbasFromBas' => 'phrasea::sbasFromBas'));
|
||||
$twig->addFilter(array('geoname_name_from_id' => 'geonames::name_from_id'));
|
||||
|
||||
return $twig->render($template, $rights->get_users_rights());
|
||||
}
|
||||
);
|
||||
|
||||
$controllers->get('/rights/', function() use ($app)
|
||||
{
|
||||
$request = $app['request'];
|
||||
$rights = new module_admin_route_users_edit($request);
|
||||
|
||||
$template = 'admin/editusers.twig';
|
||||
$twig = new supertwig();
|
||||
$twig->addFilter(array('bas_name' => 'phrasea::bas_names'));
|
||||
$twig->addFilter(array('sbas_name' => 'phrasea::sbas_names'));
|
||||
$twig->addFilter(array('sbasFromBas' => 'phrasea::sbasFromBas'));
|
||||
$twig->addFilter(array('geoname_name_from_id' => 'geonames::name_from_id'));
|
||||
|
||||
return $twig->render($template, $rights->get_users_rights());
|
||||
}
|
||||
);
|
||||
|
||||
$controllers->post('/delete/', function() use ($app)
|
||||
{
|
||||
$request = $app['request'];
|
||||
|
||||
|
||||
|
||||
$module = new module_admin_route_users_edit($request);
|
||||
$module->delete_users();
|
||||
|
||||
return $app->redirect('/admin/users/search/');
|
||||
}
|
||||
);
|
||||
|
||||
$controllers->post('/rights/apply/', function() use ($app)
|
||||
{
|
||||
$datas = array('error' => true);
|
||||
|
||||
try
|
||||
{
|
||||
$request = $app['request'];
|
||||
$rights = new module_admin_route_users_edit($request);
|
||||
$rights->apply_rights();
|
||||
$rights->apply_infos();
|
||||
|
||||
$datas = array('error' => false);
|
||||
}
|
||||
catch (Exception $e)
|
||||
{
|
||||
$datas['message'] = $e->getMessage();
|
||||
}
|
||||
|
||||
return new Response(
|
||||
p4string::jsonencode($datas)
|
||||
, 200
|
||||
, array('Content-Type' => 'application/json')
|
||||
);
|
||||
}
|
||||
);
|
||||
|
||||
$controllers->post('/rights/quotas/', function() use ($app)
|
||||
{
|
||||
$request = $app['request'];
|
||||
$rights = new module_admin_route_users_edit($request);
|
||||
|
||||
$template = 'admin/editusers_quotas.twig';
|
||||
$twig = new supertwig();
|
||||
$twig->addFilter(array('bas_name' => 'phrasea::bas_names'));
|
||||
$twig->addFilter(array('sbas_name' => 'phrasea::sbas_names'));
|
||||
$twig->addFilter(array('sbasFromBas' => 'phrasea::sbasFromBas'));
|
||||
|
||||
return $twig->render($template, $rights->get_quotas());
|
||||
}
|
||||
);
|
||||
|
||||
$controllers->post('/rights/quotas/apply/', function() use ($app)
|
||||
{
|
||||
$request = $app['request'];
|
||||
$rights = new module_admin_route_users_edit($request);
|
||||
$rights->apply_quotas();
|
||||
|
||||
return;
|
||||
}
|
||||
);
|
||||
|
||||
$controllers->post('/rights/time/', function() use ($app)
|
||||
{
|
||||
$request = $app['request'];
|
||||
$rights = new module_admin_route_users_edit($request);
|
||||
|
||||
$template = 'admin/editusers_timelimit.twig';
|
||||
$twig = new supertwig();
|
||||
$twig->addFilter(array('bas_name' => 'phrasea::bas_names'));
|
||||
$twig->addFilter(array('sbas_name' => 'phrasea::sbas_names'));
|
||||
$twig->addFilter(array('sbasFromBas' => 'phrasea::sbasFromBas'));
|
||||
|
||||
return $twig->render($template, $rights->get_time());
|
||||
}
|
||||
);
|
||||
|
||||
$controllers->post('/rights/time/apply/', function() use ($app)
|
||||
{
|
||||
$request = $app['request'];
|
||||
$rights = new module_admin_route_users_edit($request);
|
||||
$rights->apply_time();
|
||||
|
||||
return;
|
||||
}
|
||||
);
|
||||
|
||||
$controllers->post('/rights/masks/', function() use ($app)
|
||||
{
|
||||
$request = $app['request'];
|
||||
$rights = new module_admin_route_users_edit($request);
|
||||
|
||||
$template = 'admin/editusers_masks.twig';
|
||||
$twig = new supertwig();
|
||||
$twig->addFilter(array('bas_name' => 'phrasea::bas_names'));
|
||||
$twig->addFilter(array('sbas_name' => 'phrasea::sbas_names'));
|
||||
$twig->addFilter(array('sbasFromBas' => 'phrasea::sbasFromBas'));
|
||||
|
||||
return $twig->render($template, $rights->get_masks());
|
||||
}
|
||||
);
|
||||
|
||||
$controllers->post('/rights/masks/apply/', function() use ($app)
|
||||
{
|
||||
$request = $app['request'];
|
||||
$rights = new module_admin_route_users_edit($request);
|
||||
$rights->apply_masks();
|
||||
|
||||
return;
|
||||
}
|
||||
);
|
||||
|
||||
$controllers->post('/search/', function() use ($app)
|
||||
{
|
||||
$request = $app['request'];
|
||||
$users = new module_admin_route_users($request);
|
||||
$template = 'admin/users.html';
|
||||
|
||||
$twig = new supertwig();
|
||||
$twig->addFilter(array('floor' => 'floor'));
|
||||
$twig->addFilter(array('getDate' => 'phraseadate::getDate'));
|
||||
|
||||
return $twig->render($template, $users->search($request));
|
||||
}
|
||||
);
|
||||
|
||||
$controllers->get('/search/', function() use ($app)
|
||||
{
|
||||
$request = $app['request'];
|
||||
$users = new module_admin_route_users($request);
|
||||
$template = 'admin/users.html';
|
||||
|
||||
$twig = new supertwig();
|
||||
$twig->addFilter(array('floor' => 'floor'));
|
||||
$twig->addFilter(array('getDate' => 'phraseadate::getDate'));
|
||||
|
||||
return $twig->render($template, $users->search($request));
|
||||
}
|
||||
);
|
||||
|
||||
$controllers->get('/typeahead/search/', function() use ($app, $appbox)
|
||||
{
|
||||
$request = $app['request'];
|
||||
$user_query = new User_Query($appbox);
|
||||
|
||||
$user = User_Adapter::getInstance($appbox->get_session()->get_usr_id(), $appbox);
|
||||
$like_value = $request->get('term');
|
||||
$rights = $request->get('filter_rights') ? : array();
|
||||
$have_right = $request->get('have_right') ? : array();
|
||||
$have_not_right = $request->get('have_not_right') ? : array();
|
||||
$on_base = $request->get('on_base') ? : array();
|
||||
|
||||
|
||||
$elligible_users = $user_query->on_sbas_where_i_am($user->ACL(), $rights)
|
||||
->like(User_Query::LIKE_EMAIL, $like_value)
|
||||
->like(User_Query::LIKE_FIRSTNAME, $like_value)
|
||||
->like(User_Query::LIKE_LASTNAME, $like_value)
|
||||
->like(User_Query::LIKE_LOGIN, $like_value)
|
||||
->like_match(User_Query::LIKE_MATCH_OR)
|
||||
->who_have_right($have_right)
|
||||
->who_have_not_right($have_not_right)
|
||||
->on_base_ids($on_base)
|
||||
->execute()->get_results();
|
||||
|
||||
$datas = array();
|
||||
|
||||
foreach ($elligible_users as $user)
|
||||
{
|
||||
$datas[] = array(
|
||||
'email' => $user->get_email() ? : ''
|
||||
, 'login' => $user->get_login() ? : ''
|
||||
, 'name' => $user->get_display_name() ? : ''
|
||||
, 'id' => $user->get_id()
|
||||
);
|
||||
}
|
||||
|
||||
return new Response(p4string::jsonencode($datas), 200, array('Content-type' => 'application/json'));
|
||||
});
|
||||
|
||||
|
||||
$controllers->post('/create/', function() use ($app)
|
||||
{
|
||||
|
||||
$datas = array('error' => false, 'message' => '', 'data' => null);
|
||||
try
|
||||
{
|
||||
$request = $app['request'];
|
||||
$module = new module_admin_route_users($request);
|
||||
if ($request->get('template') == '1')
|
||||
{
|
||||
$user = $module->create_template();
|
||||
}
|
||||
else
|
||||
{
|
||||
$user = $module->create_newuser();
|
||||
}
|
||||
if (!($user instanceof User_Adapter))
|
||||
throw new Exception('Unknown error');
|
||||
|
||||
$datas['data'] = $user->get_id();
|
||||
}
|
||||
catch (Exception $e)
|
||||
{
|
||||
$datas['error'] = true;
|
||||
$datas['message'] = $e->getMessage();
|
||||
}
|
||||
|
||||
return new Response(p4string::jsonencode($datas));
|
||||
}
|
||||
);
|
||||
|
||||
$controllers->post('/export/csv/', function() use ($appbox, $app)
|
||||
{
|
||||
$request = $app['request'];
|
||||
$user_query = new User_Query($appbox);
|
||||
|
||||
$user = User_Adapter::getInstance($appbox->get_session()->get_usr_id(), $appbox);
|
||||
$like_value = $request->get('like_value');
|
||||
$like_field = $request->get('like_field');
|
||||
$on_base = $request->get('base_id') ? : null;
|
||||
$on_sbas = $request->get('sbas_id') ? : null;
|
||||
|
||||
$elligible_users = $user_query->on_bases_where_i_am($user->ACL(), array('canadmin'))
|
||||
->like($like_field, $like_value)
|
||||
->on_base_ids($on_base)
|
||||
->on_sbas_ids($on_sbas);
|
||||
|
||||
$offset = 0;
|
||||
$geoname = new geonames();
|
||||
$buffer = array();
|
||||
|
||||
$buffer[] = array(
|
||||
'ID'
|
||||
, 'Login'
|
||||
, _('admin::compte-utilisateur nom')
|
||||
, _('admin::compte-utilisateur prenom')
|
||||
, _('admin::compte-utilisateur email')
|
||||
, 'CreationDate'
|
||||
, 'ModificationDate'
|
||||
, _('admin::compte-utilisateur adresse')
|
||||
, _('admin::compte-utilisateur ville')
|
||||
, _('admin::compte-utilisateur code postal')
|
||||
, _('admin::compte-utilisateur pays')
|
||||
, _('admin::compte-utilisateur telephone')
|
||||
, _('admin::compte-utilisateur fax')
|
||||
, _('admin::compte-utilisateur poste')
|
||||
, _('admin::compte-utilisateur societe')
|
||||
, _('admin::compte-utilisateur activite')
|
||||
);
|
||||
do
|
||||
{
|
||||
$elligible_users->limit($offset, 20);
|
||||
$offset += 20;
|
||||
|
||||
$results = $elligible_users->execute()->get_results();
|
||||
|
||||
foreach ($results as $user)
|
||||
{
|
||||
$buffer[] = array(
|
||||
$user->get_id()
|
||||
, $user->get_login()
|
||||
, $user->get_lastname()
|
||||
, $user->get_firstname()
|
||||
, $user->get_email()
|
||||
, phraseadate::format_mysql($user->get_creation_date())
|
||||
, phraseadate::format_mysql($user->get_modification_date())
|
||||
, $user->get_address()
|
||||
, $user->get_city()
|
||||
, $user->get_zipcode()
|
||||
, $geoname->get_country($user->get_geonameid())
|
||||
, $user->get_tel()
|
||||
, $user->get_fax()
|
||||
, $user->get_job()
|
||||
, $user->get_company()
|
||||
, $user->get_position()
|
||||
);
|
||||
}
|
||||
}
|
||||
while (count($results) > 0);
|
||||
|
||||
$out = format::arr_to_csv($buffer);
|
||||
|
||||
$headers = array(
|
||||
'Content-type' => 'text/csv'
|
||||
, 'Content-Disposition' => 'attachment; filename=export.txt;'
|
||||
);
|
||||
$response = new Response($out, 200, $headers);
|
||||
$response->setCharset('UTF-8');
|
||||
|
||||
return $response;
|
||||
}
|
||||
);
|
||||
|
||||
return $controllers;
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user