mirror of
https://github.com/alchemy-fr/Phraseanet.git
synced 2025-10-15 05:53:13 +00:00
Fix #227 : Import/Export users
This commit is contained in:
@@ -88,12 +88,12 @@ class Controller_Admin_Users implements ControllerProviderInterface
|
|||||||
$request = $app['request'];
|
$request = $app['request'];
|
||||||
$rights = new module_admin_route_users_edit($request);
|
$rights = new module_admin_route_users_edit($request);
|
||||||
$rights->apply_rights();
|
$rights->apply_rights();
|
||||||
|
|
||||||
if ($app['request']->get('template'))
|
if ($app['request']->get('template'))
|
||||||
{
|
{
|
||||||
$rights->apply_template();
|
$rights->apply_template();
|
||||||
}
|
}
|
||||||
|
|
||||||
$rights->apply_infos();
|
$rights->apply_infos();
|
||||||
|
|
||||||
$datas = array('error' => false);
|
$datas = array('error' => false);
|
||||||
@@ -200,6 +200,71 @@ class Controller_Admin_Users implements ControllerProviderInterface
|
|||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
|
$controllers->post('/search/export/', 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'));
|
||||||
|
|
||||||
|
$results = $users->export($request);
|
||||||
|
|
||||||
|
$userTable = array(
|
||||||
|
array(
|
||||||
|
'ID',
|
||||||
|
'Login',
|
||||||
|
'Last Name',
|
||||||
|
'First Name',
|
||||||
|
'E-Mail',
|
||||||
|
'Created',
|
||||||
|
'Updated',
|
||||||
|
'Address',
|
||||||
|
'City',
|
||||||
|
'Zip',
|
||||||
|
'Country',
|
||||||
|
'Phone',
|
||||||
|
'Fax',
|
||||||
|
'Job',
|
||||||
|
'Company',
|
||||||
|
'Position'
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
|
foreach ($results as $user)
|
||||||
|
{
|
||||||
|
/* @var $user \User_Adapter */
|
||||||
|
$userTable[] = array(
|
||||||
|
$user->get_id(),
|
||||||
|
$user->get_login(),
|
||||||
|
$user->get_lastname(),
|
||||||
|
$user->get_firstname(),
|
||||||
|
$user->get_email(),
|
||||||
|
$user->get_creation_date()->format(DATE_ATOM),
|
||||||
|
$user->get_modification_date()->format(DATE_ATOM),
|
||||||
|
$user->get_address(),
|
||||||
|
$user->get_city(),
|
||||||
|
$user->get_zipcode(),
|
||||||
|
$user->get_country(),
|
||||||
|
$user->get_tel(),
|
||||||
|
$user->get_fax(),
|
||||||
|
$user->get_job(),
|
||||||
|
$user->get_company(),
|
||||||
|
$user->get_position()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
$CSVDatas = format::arr_to_csv($userTable);
|
||||||
|
|
||||||
|
$response = new Response($CSVDatas, 200, array('Content-Type' => 'text/plain'));
|
||||||
|
$response->headers->set('Content-Disposition', 'attachment; filename=export.txt');
|
||||||
|
|
||||||
|
return $response;
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
$controllers->post('/apply_template/', function() use ($app)
|
$controllers->post('/apply_template/', function() use ($app)
|
||||||
{
|
{
|
||||||
$request = $app['request'];
|
$request = $app['request'];
|
||||||
|
@@ -42,6 +42,43 @@ class module_admin_route_users
|
|||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function export(Symfony\Component\HttpFoundation\Request $request)
|
||||||
|
{
|
||||||
|
$appbox = appbox::get_instance();
|
||||||
|
$session = $appbox->get_session();
|
||||||
|
|
||||||
|
$offset_start = (int) $request->get('offset_start');
|
||||||
|
$offset_start = $offset_start < 0 ? 0 : $offset_start;
|
||||||
|
|
||||||
|
$this->query_parms = array(
|
||||||
|
'inactives' => $request->get('inactives')
|
||||||
|
, 'like_field' => $request->get('like_field')
|
||||||
|
, 'like_value' => $request->get('like_value')
|
||||||
|
, 'sbas_id' => $request->get('sbas_id')
|
||||||
|
, 'base_id' => $request->get('base_id')
|
||||||
|
, 'srt' => $request->get("srt", User_Query::SORT_CREATIONDATE)
|
||||||
|
, 'ord' => $request->get("ord", User_Query::ORD_DESC)
|
||||||
|
, 'offset_start' => 0
|
||||||
|
);
|
||||||
|
|
||||||
|
$user = User_Adapter::getInstance($session->get_usr_id(), $appbox);
|
||||||
|
$query = new User_Query($appbox);
|
||||||
|
|
||||||
|
if (is_array($this->query_parms['base_id']))
|
||||||
|
$query->on_base_ids($this->query_parms['base_id']);
|
||||||
|
elseif (is_array($this->query_parms['sbas_id']))
|
||||||
|
$query->on_sbas_ids($this->query_parms['sbas_id']);
|
||||||
|
|
||||||
|
$this->results = $query->sort_by($this->query_parms["srt"], $this->query_parms["ord"])
|
||||||
|
->like($this->query_parms['like_field'], $this->query_parms['like_value'])
|
||||||
|
->get_inactives($this->query_parms['inactives'])
|
||||||
|
->include_templates(false)
|
||||||
|
->on_bases_where_i_am($user->ACL(), array('canadmin'))
|
||||||
|
->execute();
|
||||||
|
|
||||||
|
return $this->results->get_results();
|
||||||
|
}
|
||||||
|
|
||||||
public function search(Symfony\Component\HttpFoundation\Request $request)
|
public function search(Symfony\Component\HttpFoundation\Request $request)
|
||||||
{
|
{
|
||||||
|
@@ -186,6 +186,23 @@
|
|||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
|
|
||||||
|
|
||||||
|
<form id="export_form" method="post" target="exportwindow" action="/admin/users/search/export/">
|
||||||
|
<input name="srt" value="{{parm['srt']}}" type="hidden" />
|
||||||
|
<input name="ord" value="{{parm.ord}}" type="hidden" />
|
||||||
|
<input name="act" value="{{parm.act}}" type="hidden" />
|
||||||
|
{% for sbas_id in parm.sbas_id %}
|
||||||
|
<input name="sbas_id[]" value="{{sbas_id}}" type="hidden" />
|
||||||
|
{% endfor %}
|
||||||
|
{% for base_id in parm.base_id %}
|
||||||
|
<input name="base_id[]" value="{{base_id}}" type="hidden" />
|
||||||
|
{% endfor %}
|
||||||
|
<input name="usr_ids" value="{{parm.usr_ids}}" type="hidden" />
|
||||||
|
<input name="like_value" value="{{parm.like_value}}" type="hidden" />
|
||||||
|
<input name="like_field" value="{{parm.like_field}}" type="hidden" />
|
||||||
|
<input name="inactives" value="{{parm.inactives}}" type="hidden" />
|
||||||
|
</form>
|
||||||
|
|
||||||
<form id="users_page_form" method="post" target="_self" action="/admin/users/search/">
|
<form id="users_page_form" method="post" target="_self" action="/admin/users/search/">
|
||||||
{{users.get_total}} resultats
|
{{users.get_total}} resultats
|
||||||
|
|
||||||
@@ -274,6 +291,10 @@
|
|||||||
window.showModalDialog ('/admin/import0.php?rand='+Math.random(),myObj, 'dialogWidth:550px;dialogHeight:330px;center:yes;help:no;status:no;scrollbars:no' );
|
window.showModalDialog ('/admin/import0.php?rand='+Math.random(),myObj, 'dialogWidth:550px;dialogHeight:330px;center:yes;help:no;status:no;scrollbars:no' );
|
||||||
|
|
||||||
}
|
}
|
||||||
|
function exportlist()
|
||||||
|
{
|
||||||
|
$('#export_form').submit();
|
||||||
|
}
|
||||||
|
|
||||||
</script>
|
</script>
|
||||||
</div>
|
</div>
|
||||||
|
Reference in New Issue
Block a user