mirror of
https://github.com/alchemy-fr/Phraseanet.git
synced 2025-10-15 05:53:13 +00:00
V 3.5 RC 1
This commit is contained in:
37
lib/classes/module/Admin.php
Normal file
37
lib/classes/module/Admin.php
Normal file
@@ -0,0 +1,37 @@
|
||||
<?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 Silex\Application;
|
||||
|
||||
return call_user_func(
|
||||
function()
|
||||
{
|
||||
$app = new Application();
|
||||
|
||||
$app->mount('/publications', new Controller_Admin_Publications());
|
||||
$app->mount('/users', new Controller_Admin_Users());
|
||||
$app->mount('/fields', new Controller_Admin_Fields());
|
||||
$app->mount('/tests/connection', new Controller_Utils_ConnectionTest());
|
||||
$app->mount('/tests/pathurl', new Controller_Utils_PathFileTest());
|
||||
|
||||
$app->error(function(\Exception $e)
|
||||
{
|
||||
return $e->getMessage();
|
||||
});
|
||||
|
||||
return $app;
|
||||
});
|
455
lib/classes/module/Lightbox.php
Normal file
455
lib/classes/module/Lightbox.php
Normal file
@@ -0,0 +1,455 @@
|
||||
<?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;
|
||||
|
||||
return call_user_func(
|
||||
function()
|
||||
{
|
||||
$appbox = appbox::get_instance();
|
||||
|
||||
$session = $appbox->get_session();
|
||||
|
||||
$app = new Silex\Application();
|
||||
|
||||
$app->get('/', function () use ($session, $appbox)
|
||||
{
|
||||
User_Adapter::updateClientInfos((6));
|
||||
$basket_collection = new basketCollection($appbox, $session->get_usr_id());
|
||||
$twig = new supertwig();
|
||||
$twig->addFilter(array('nl2br' => 'nl2br'));
|
||||
$browser = Browser::getInstance();
|
||||
|
||||
$template = 'lightbox/index.twig';
|
||||
if (!$browser->isNewGeneration() && !$browser->isMobile())
|
||||
$template = 'lightbox/IE6/index.twig';
|
||||
|
||||
$output = $twig->render($template, array(
|
||||
'baskets_collection' => $basket_collection,
|
||||
'module_name' => 'Lightbox',
|
||||
'module' => 'lightbox'
|
||||
)
|
||||
);
|
||||
$response = new Response($output);
|
||||
$response->setCharset('UTF-8');
|
||||
|
||||
return $response;
|
||||
}
|
||||
);
|
||||
|
||||
$app->get('/ajax/NOTE_FORM/{sselcont_id}/', function($sselcont_id) use ($session, $appbox)
|
||||
{
|
||||
$browser = Browser::getInstance();
|
||||
if (!$browser->isMobile())
|
||||
return new Response('');
|
||||
|
||||
$twig = new supertwig();
|
||||
$twig->addFilter(array('nl2br' => 'nl2br'));
|
||||
$basket_element = basket_element_adapter::getInstance($sselcont_id);
|
||||
$template = '/lightbox/note_form.twig';
|
||||
$output = $twig->render($template, array('basket_element' => $basket_element, 'module_name' => ''));
|
||||
|
||||
return new Response($output);
|
||||
}
|
||||
)->assert('sselcont_id', '\d+');
|
||||
|
||||
$app->get('/ajax/LOAD_BASKET_ELEMENT/{sselcont_id}/', function($sselcont_id)
|
||||
{
|
||||
$twig = new supertwig();
|
||||
$twig->addFilter(array('nl2br' => 'nl2br', 'formatoctet' => 'p4string::format_octets'));
|
||||
|
||||
$browser = Browser::getInstance();
|
||||
|
||||
if ($browser->isMobile())
|
||||
{
|
||||
$basket_element = basket_element_adapter::getInstance($sselcont_id);
|
||||
|
||||
$output = $twig->render('lightbox/basket_element.twig', array(
|
||||
'basket_element' => $basket_element,
|
||||
'module_name' => $basket_element->get_record()->get_title()
|
||||
)
|
||||
);
|
||||
|
||||
return new Response($output);
|
||||
}
|
||||
else
|
||||
{
|
||||
$template_options = 'lightbox/sc_options_box.twig';
|
||||
$template_agreement = 'lightbox/agreement_box.twig';
|
||||
$template_selector = 'lightbox/selector_box.twig';
|
||||
$template_note = 'lightbox/sc_note.twig';
|
||||
$template_preview = 'common/preview.html';
|
||||
$template_caption = 'common/caption.html';
|
||||
|
||||
if (!$browser->isNewGeneration())
|
||||
{
|
||||
$template_options = 'lightbox/IE6/sc_options_box.twig';
|
||||
$template_agreement = 'lightbox/IE6/agreement_box.twig';
|
||||
}
|
||||
$appbox = appbox::get_instance();
|
||||
$usr_id = $appbox->get_session()->get_usr_id();
|
||||
|
||||
$basket_element = basket_element_adapter::getInstance($sselcont_id);
|
||||
$basket = basket_adapter::getInstance($appbox, $basket_element->get_ssel_id(), $usr_id);
|
||||
|
||||
$ret = array();
|
||||
$ret['number'] = $basket_element->get_record()->get_number();
|
||||
$ret['title'] = $basket_element->get_record()->get_title();
|
||||
|
||||
$ret['preview'] = $twig->render($template_preview, array('record' => $basket_element->get_record(), 'not_wrapped' => true));
|
||||
$ret['options_html'] = $twig->render($template_options, array('basket_element' => $basket_element));
|
||||
$ret['agreement_html'] = $twig->render($template_agreement, array('basket' => $basket, 'basket_element' => $basket_element));
|
||||
$ret['selector_html'] = $twig->render($template_selector, array('basket_element' => $basket_element));
|
||||
$ret['note_html'] = $twig->render($template_note, array('basket_element' => $basket_element));
|
||||
$ret['caption'] = $twig->render($template_caption, array('view' => 'preview', 'record' => $basket_element->get_record()));
|
||||
$output = p4string::jsonencode($ret);
|
||||
|
||||
return new Response($output, 200, array('Content-Type' => 'application/json'));
|
||||
}
|
||||
}
|
||||
)->assert('sselcont_id', '\d+');
|
||||
|
||||
|
||||
|
||||
|
||||
$app->get('/ajax/LOAD_FEED_ITEM/{entry_id}/{item_id}/', function($entry_id, $item_id)
|
||||
{
|
||||
$twig = new supertwig();
|
||||
$twig->addFilter(array('nl2br' => 'nl2br', 'formatoctet' => 'p4string::format_octets'));
|
||||
|
||||
$appbox = appbox::get_instance();
|
||||
$entry = Feed_Entry_Adapter::load_from_id($appbox, $entry_id);
|
||||
$item = new Feed_Entry_Item($appbox, $entry, $item_id);
|
||||
|
||||
$browser = Browser::getInstance();
|
||||
|
||||
if ($browser->isMobile())
|
||||
{
|
||||
$output = $twig->render('lightbox/feed_element.twig', array(
|
||||
'feed_element' => $item,
|
||||
'module_name' => $item->get_record()->get_title()
|
||||
)
|
||||
);
|
||||
|
||||
return new Response($output);
|
||||
}
|
||||
else
|
||||
{
|
||||
$template_options = 'lightbox/sc_options_box.twig';
|
||||
$template_preview = 'common/preview.html';
|
||||
$template_caption = 'common/caption.html';
|
||||
|
||||
if (!$browser->isNewGeneration())
|
||||
{
|
||||
$template_options = 'lightbox/IE6/sc_options_box.twig';
|
||||
}
|
||||
$usr_id = $appbox->get_session()->get_usr_id();
|
||||
|
||||
$ret = array();
|
||||
$ret['number'] = $item->get_record()->get_number();
|
||||
$ret['title'] = $item->get_record()->get_title();
|
||||
|
||||
$ret['preview'] = $twig->render($template_preview, array('record' => $item->get_record(), 'not_wrapped' => true));
|
||||
$ret['options_html'] = $twig->render($template_options, array('basket_element' => $item));
|
||||
$ret['caption'] = $twig->render($template_caption, array('view' => 'preview', 'record' => $item->get_record()));
|
||||
|
||||
|
||||
$ret['agreement_html'] = $ret['selector_html'] = $ret['note_html'] = '';
|
||||
|
||||
|
||||
$output = p4string::jsonencode($ret);
|
||||
|
||||
return new Response($output, 200, array('Content-type' => 'application/json'));
|
||||
}
|
||||
}
|
||||
)->assert('entry_id', '\d+')->assert('item_id', '\d+');
|
||||
|
||||
$app->get('/validate/{ssel_id}/', function ($ssel_id) use ($session, $appbox)
|
||||
{
|
||||
|
||||
User_Adapter::updateClientInfos((6));
|
||||
|
||||
$browser = Browser::getInstance();
|
||||
|
||||
$basket_collection = new basketCollection($appbox, $session->get_usr_id());
|
||||
$basket = basket_adapter::getInstance($appbox, $ssel_id, $session->get_usr_id());
|
||||
|
||||
if ($basket->is_valid())
|
||||
{
|
||||
$basket->get_first_element()->load_users_infos();
|
||||
}
|
||||
|
||||
$twig = new supertwig();
|
||||
|
||||
$twig->addFilter(array('nl2br' => 'nl2br'));
|
||||
|
||||
$template = 'lightbox/validate.twig';
|
||||
|
||||
if (!$browser->isNewGeneration() && !$browser->isMobile())
|
||||
$template = 'lightbox/IE6/validate.twig';
|
||||
|
||||
$response = new Response($twig->render($template, array(
|
||||
'baskets_collection' => $basket_collection,
|
||||
'basket' => $basket,
|
||||
'local_title' => strip_tags($basket->get_name()),
|
||||
'module' => 'lightbox',
|
||||
'module_name' => _('admin::monitor: module validation')
|
||||
)
|
||||
));
|
||||
$response->setCharset('UTF-8');
|
||||
|
||||
return $response;
|
||||
}
|
||||
)->assert('ssel_id', '\d+');
|
||||
|
||||
$app->get('/compare/{ssel_id}/', function ($ssel_id) use ($session, $appbox)
|
||||
{
|
||||
|
||||
User_Adapter::updateClientInfos((6));
|
||||
|
||||
$browser = Browser::getInstance();
|
||||
|
||||
$basket_collection = new basketCollection($appbox, $session->get_usr_id());
|
||||
$basket = basket_adapter::getInstance($appbox, $ssel_id, $session->get_usr_id());
|
||||
|
||||
if ($basket->is_valid())
|
||||
{
|
||||
$basket->get_first_element()->load_users_infos();
|
||||
}
|
||||
|
||||
$twig = new supertwig();
|
||||
|
||||
$twig->addFilter(array('nl2br' => 'nl2br'));
|
||||
|
||||
$template = 'lightbox/validate.twig';
|
||||
|
||||
if (!$browser->isNewGeneration() && !$browser->isMobile())
|
||||
$template = 'lightbox/IE6/validate.twig';
|
||||
|
||||
$response = new Response($twig->render($template, array(
|
||||
'baskets_collection' => $basket_collection,
|
||||
'basket' => $basket,
|
||||
'local_title' => strip_tags($basket->get_name()),
|
||||
'module' => 'lightbox',
|
||||
'module_name' => _('admin::monitor: module validation')
|
||||
)
|
||||
));
|
||||
$response->setCharset('UTF-8');
|
||||
|
||||
return $response;
|
||||
}
|
||||
)->assert('ssel_id', '\d+');
|
||||
|
||||
|
||||
|
||||
$app->get('/feeds/entry/{entry_id}/', function ($entry_id) use ($session, $appbox)
|
||||
{
|
||||
|
||||
User_Adapter::updateClientInfos((6));
|
||||
|
||||
$browser = Browser::getInstance();
|
||||
|
||||
$feed_entry = Feed_Entry_Adapter::load_from_id($appbox, $entry_id);
|
||||
|
||||
$twig = new supertwig();
|
||||
|
||||
$twig->addFilter(array('nl2br' => 'nl2br'));
|
||||
|
||||
$template = 'lightbox/feed.twig';
|
||||
|
||||
if (!$browser->isNewGeneration() && !$browser->isMobile())
|
||||
$template = 'lightbox/IE6/feed.twig';
|
||||
|
||||
$output = $twig->render($template, array(
|
||||
'feed_entry' => $feed_entry,
|
||||
'first_item' => array_shift($feed_entry->get_content()),
|
||||
'local_title' => $feed_entry->get_title(),
|
||||
'module' => 'lightbox',
|
||||
'module_name' => _('admin::monitor: module validation')
|
||||
)
|
||||
);
|
||||
$response = new Response($output, 200);
|
||||
$response->setCharset('UTF-8');
|
||||
|
||||
return $response;
|
||||
}
|
||||
)->assert('entry_id', '\d+');
|
||||
|
||||
$app->get('/ajax/LOAD_REPORT/{ssel_id}/', function($ssel_id) use ($appbox, $app)
|
||||
{
|
||||
$twig = new supertwig();
|
||||
$twig->addFilter(array('nl2br' => 'nl2br'));
|
||||
|
||||
$browser = Browser::getInstance();
|
||||
|
||||
$template = 'lightbox/basket_content_report.twig';
|
||||
|
||||
$basket = basket_adapter::getInstance($appbox, $ssel_id, $appbox->get_session()->get_usr_id());
|
||||
|
||||
$response = new Response($twig->render($template, array('basket' => $basket)));
|
||||
$response->setCharset('UTF-8');
|
||||
|
||||
return $response;
|
||||
}
|
||||
)->assert('ssel_id', '\d+');
|
||||
|
||||
$app->post('/ajax/SET_NOTE/{sselcont_id}/', function ($sselcont_id) use ($app)
|
||||
{
|
||||
$output = array('error' => true, 'datas' => _('Erreur lors de l\'enregistrement des donnees'));
|
||||
try
|
||||
{
|
||||
$request = $app['request'];
|
||||
$note = $request->get('note');
|
||||
|
||||
$basket_element = basket_element_adapter::getInstance($sselcont_id);
|
||||
$basket_element->set_note($note);
|
||||
$twig = new supertwig();
|
||||
$twig->addFilter(array('nl2br' => 'nl2br'));
|
||||
|
||||
$browser = Browser::getInstance();
|
||||
|
||||
if ($browser->isMobile())
|
||||
{
|
||||
$datas = $twig->render('lightbox/sc_note.twig', array('basket_element' => $basket_element));
|
||||
|
||||
$output = array('error' => false, 'datas' => $datas);
|
||||
}
|
||||
else
|
||||
{
|
||||
$template = 'lightbox/sc_note.twig';
|
||||
|
||||
$datas = $twig->render($template, array('basket_element' => $basket_element));
|
||||
|
||||
$output = array('error' => false, 'datas' => $datas);
|
||||
}
|
||||
}
|
||||
catch (Exception $e)
|
||||
{
|
||||
return new Response('Bad Request : ' . $e->getMessage() . $e->getFile() . $e->getLine(), 400);
|
||||
}
|
||||
|
||||
$output = p4string::jsonencode($output);
|
||||
|
||||
return new Response($output, 200, array('Content-Type' => 'application/json'));
|
||||
}
|
||||
)->assert('sselcont_id', '\d+');
|
||||
|
||||
$app->post('/ajax/SET_ELEMENT_AGREEMENT/{sselcont_id}/', function($sselcont_id) use ($app)
|
||||
{
|
||||
$request = $app['request'];
|
||||
$agreement = (int) $request->get('agreement');
|
||||
|
||||
$ret = array(
|
||||
'error' => true,
|
||||
'releasable' => false,
|
||||
'datas' => _('Erreur lors de la mise a jour des donnes ')
|
||||
);
|
||||
try
|
||||
{
|
||||
$appbox = appbox::get_instance();
|
||||
|
||||
$basket_element = basket_element_adapter::getInstance($sselcont_id);
|
||||
$basket_element->set_agreement($agreement);
|
||||
$basket = basket_adapter::getInstance($appbox, $basket_element->get_ssel_id(), $appbox->get_session()->get_usr_id());
|
||||
|
||||
$ret = array(
|
||||
'error' => false
|
||||
, 'datas' => ''
|
||||
, 'releasable' => $basket->is_releasable() ? _('Do you want to send your report ?') : false
|
||||
);
|
||||
}
|
||||
catch (Exception $e)
|
||||
{
|
||||
return new Response('Bad Request', 400);
|
||||
}
|
||||
$output = p4string::jsonencode($ret);
|
||||
|
||||
return new Response($output, 200, array('Content-Type' => 'application/json'));
|
||||
}
|
||||
)->assert('sselcont_id', '\d+');
|
||||
|
||||
|
||||
$app->post('/ajax/SET_RELEASE/{ssel_id}/', function($ssel_id) use ($session, $appbox)
|
||||
{
|
||||
$basket = basket_adapter::getInstance($appbox, $ssel_id, $appbox->get_session()->get_usr_id());
|
||||
|
||||
$datas = array('error' => true, 'datas' => _('Erreur lors de l\'enregistrement des donnees'));
|
||||
try
|
||||
{
|
||||
$appbox->get_connection()->beginTransaction();
|
||||
$basket->set_released();
|
||||
$datas = array('error' => false, 'datas' => _('Envoie avec succes'));
|
||||
$appbox->get_connection()->commit();
|
||||
}
|
||||
catch (Exception $e)
|
||||
{
|
||||
$appbox->get_connection()->rollBack();
|
||||
|
||||
return new Response('Bad Request', 400);
|
||||
}
|
||||
$output = p4string::jsonencode($datas);
|
||||
|
||||
$response = new Response($output, 200, array('Content-Type' => 'application/json'));
|
||||
$response->setCharset('UTF-8');
|
||||
|
||||
return $response;
|
||||
}
|
||||
)->assert('ssel_id', '\d+');
|
||||
|
||||
|
||||
|
||||
$app->error(function($e)
|
||||
{
|
||||
$twig = new supertwig();
|
||||
$registry = registry::get_instance();
|
||||
|
||||
$template = 'lightbox/error.twig';
|
||||
|
||||
if ($registry->get('GV_debug'))
|
||||
{
|
||||
$options = array(
|
||||
'module' => 'validation',
|
||||
'module_name' => _('admin::monitor: module validation'),
|
||||
'error' => sprintf(
|
||||
'%s in %s on line %s '
|
||||
, $e->getMessage()
|
||||
, $e->getFile()
|
||||
, $e->getLine()
|
||||
)
|
||||
);
|
||||
}
|
||||
else
|
||||
{
|
||||
$options = array(
|
||||
'module' => 'validation',
|
||||
'module_name' => _('admin::monitor: module validation'),
|
||||
'error' => ''
|
||||
);
|
||||
}
|
||||
$output = $twig->render($template, $options);
|
||||
$response = new Response($output, 404);
|
||||
$response->setCharset('UTF-8');
|
||||
|
||||
return $response;
|
||||
});
|
||||
|
||||
return $app;
|
||||
}
|
||||
);
|
227
lib/classes/module/Overview.php
Normal file
227
lib/classes/module/Overview.php
Normal file
@@ -0,0 +1,227 @@
|
||||
<?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;
|
||||
|
||||
return call_user_func(
|
||||
function()
|
||||
{
|
||||
$appbox = appbox::get_instance();
|
||||
$session = $appbox->get_session();
|
||||
|
||||
$app = new Silex\Application();
|
||||
|
||||
|
||||
$deliver_content = function(Session_Handler $session, record_adapter $record, $subdef, $watermark, $stamp, $app)
|
||||
{
|
||||
|
||||
$file = $record->get_subdef($subdef);
|
||||
if ($file->get_baseurl() !== '')
|
||||
{
|
||||
return $app->redirect($file->get_url());
|
||||
}
|
||||
|
||||
$pathIn = $pathOut = $file->get_pathfile();
|
||||
|
||||
if ($watermark === true && $file->get_type() === media_subdef::TYPE_IMAGE)
|
||||
{
|
||||
$pathOut = recordutils_image::watermark($record->get_base_id(), $record->get_record_id());
|
||||
}
|
||||
elseif ($stamp === true && $file->get_type() === media_subdef::TYPE_IMAGE)
|
||||
{
|
||||
$pathOut = recordutils_image::stamp($record->get_base_id(), $record->get_record_id());
|
||||
}
|
||||
|
||||
|
||||
$log_id = null;
|
||||
try
|
||||
{
|
||||
$registry = registry::get_instance();
|
||||
$logger = $session->get_logger($record->get_databox());
|
||||
$log_id = $logger->get_id();
|
||||
|
||||
$referrer = 'NO REFERRER';
|
||||
|
||||
if (isset($_SERVER['HTTP_REFERER']))
|
||||
$referrer = $_SERVER['HTTP_REFERER'];
|
||||
|
||||
$record->log_view($log_id, $referrer, $registry->get('GV_sit'));
|
||||
}
|
||||
catch (Exception $e)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
return set_export::stream_file($pathOut, $file->get_file(), $file->get_mime(), 'attachment');
|
||||
};
|
||||
|
||||
$app->get('/datafiles/{sbas_id}/{record_id}/{subdef}/', function($sbas_id, $record_id, $subdef) use ($app, $session, $deliver_content)
|
||||
{
|
||||
|
||||
$databox = databox::get_instance((int) $sbas_id);
|
||||
$record = new record_adapter($sbas_id, $record_id);
|
||||
|
||||
$record->get_type();
|
||||
|
||||
if (!$session->is_authenticated())
|
||||
throw new Exception_Session_NotAuthenticated();
|
||||
|
||||
$user = User_Adapter::getInstance($session->get_usr_id(), appbox::get_instance());
|
||||
|
||||
if (!$user->ACL()->has_access_to_subdef($record, $subdef))
|
||||
throw new Exception_UnauthorizedAction();
|
||||
|
||||
$stamp = false;
|
||||
$watermark = !$user->ACL()->has_right_on_base($record->get_base_id(), 'nowatermark');
|
||||
|
||||
if ($watermark)
|
||||
{
|
||||
$subdef_class = $databox
|
||||
->get_subdef_structure()
|
||||
->get_subdef($record->get_type(), $subdef)
|
||||
->get_class();
|
||||
|
||||
if ($subdef_class == databox_subdefAbstract::CLASS_PREVIEW && $user->ACL()->has_preview_grant($record))
|
||||
{
|
||||
$watermark = false;
|
||||
}
|
||||
elseif ($subdef_class == databox_subdefAbstract::CLASS_DOCUMENT && $user->ACL()->has_hd_grant($record))
|
||||
{
|
||||
$watermark = false;
|
||||
}
|
||||
}
|
||||
|
||||
if ($watermark)
|
||||
{
|
||||
if (basket_element_adapter::is_in_validation_session($record, $user))
|
||||
{
|
||||
$watermark = false;
|
||||
}
|
||||
elseif (basket_element_adapter::has_been_received($record, $user))
|
||||
{
|
||||
$watermark = false;
|
||||
}
|
||||
}
|
||||
|
||||
return $deliver_content($session, $record, $subdef, $watermark, $stamp, $app);
|
||||
})->assert('sbas_id', '\d+')->assert('record_id', '\d+');
|
||||
|
||||
|
||||
$app->get('/permalink/v1/{label}/{sbas_id}/{record_id}/{key}/{subdef}/view/'
|
||||
, function($label, $sbas_id, $record_id, $key, $subdef)
|
||||
{
|
||||
|
||||
$databox = databox::get_instance((int) $sbas_id);
|
||||
$record = media_Permalink_Adapter::challenge_token($databox, $key, $record_id, $subdef);
|
||||
if (!($record instanceof record_adapter))
|
||||
throw new Exception('bad luck');
|
||||
$twig = new supertwig();
|
||||
$twig->addFilter(array('formatoctet' => 'p4string::format_octets'));
|
||||
|
||||
return $twig->render('overview.twig', array('subdef_name' => $subdef, 'module_name' => 'overview', 'module' => 'overview', 'view' => 'overview', 'record' => $record));
|
||||
})->assert('sbas_id', '\d+')->assert('record_id', '\d+');
|
||||
|
||||
|
||||
$app->get('/permalink/v1/{label}/{sbas_id}/{record_id}/{key}/{subdef}/'
|
||||
, function($label, $sbas_id, $record_id, $key, $subdef) use ($app, $session, $deliver_content)
|
||||
{
|
||||
$databox = databox::get_instance((int) $sbas_id);
|
||||
$record = media_Permalink_Adapter::challenge_token($databox, $key, $record_id, $subdef);
|
||||
if (!($record instanceof record_adapter))
|
||||
throw new Exception('bad luck');
|
||||
|
||||
$watermark = $stamp = false;
|
||||
|
||||
if ($session->is_authenticated())
|
||||
{
|
||||
$user = User_Adapter::getInstance($session->get_usr_id(), appbox::get_instance());
|
||||
|
||||
$watermark = !$user->ACL()->has_right_on_base($record->get_base_id(), 'nowatermark');
|
||||
|
||||
if ($watermark)
|
||||
{
|
||||
if (basket_element_adapter::is_in_validation_session($record, $user))
|
||||
{
|
||||
$watermark = false;
|
||||
}
|
||||
elseif (basket_element_adapter::has_been_received($record, $user))
|
||||
{
|
||||
$watermark = false;
|
||||
}
|
||||
}
|
||||
|
||||
return $deliver_content($session, $record, $subdef, $watermark, $stamp, $app);
|
||||
}
|
||||
else
|
||||
{
|
||||
$collection = collection::get_from_base_id($record->get_base_id());
|
||||
switch ($collection->get_pub_wm())
|
||||
{
|
||||
default:
|
||||
case 'none':
|
||||
$watermark = false;
|
||||
break;
|
||||
case 'stamp':
|
||||
$stamp = true;
|
||||
break;
|
||||
case 'wm':
|
||||
$watermark = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return $deliver_content($session, $record, $subdef, $watermark, $stamp, $app);
|
||||
}
|
||||
)
|
||||
->assert('sbas_id', '\d+')->assert('record_id', '\d+');
|
||||
|
||||
|
||||
$app->error(function (\Exception $e)
|
||||
{
|
||||
if ($e instanceof Exception_Session_NotAuthenticated)
|
||||
{
|
||||
$code = 403;
|
||||
$message = 'Forbidden';
|
||||
}
|
||||
elseif ($e instanceof Exception_NotAllowed)
|
||||
{
|
||||
$code = 403;
|
||||
$message = 'Forbidden';
|
||||
}
|
||||
elseif ($e instanceof Exception_NotFound)
|
||||
{
|
||||
$code = 404;
|
||||
$message = 'Not Found';
|
||||
}
|
||||
else
|
||||
{
|
||||
$code = 404;
|
||||
$message = 'Not Found';
|
||||
}
|
||||
|
||||
return new Response($message, $code);
|
||||
});
|
||||
|
||||
|
||||
|
||||
|
||||
return $app;
|
||||
}
|
||||
);
|
79
lib/classes/module/Prod.php
Normal file
79
lib/classes/module/Prod.php
Normal file
@@ -0,0 +1,79 @@
|
||||
<?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\Response;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Silex\Application;
|
||||
|
||||
return call_user_func(function()
|
||||
{
|
||||
$twig = new supertwig();
|
||||
|
||||
$app = new Application();
|
||||
|
||||
$app->mount('/records/edit', new Controller_Prod_Records_Edit());
|
||||
$app->mount('/records/movecollection', new Controller_Prod_Records_MoveCollection());
|
||||
$app->mount('/bridge/', new Controller_Prod_Records_Bridge());
|
||||
$app->mount('/feeds', new Controller_Prod_Records_Feed());
|
||||
$app->mount('/tooltip', new Controller_Prod_Records_Tooltip());
|
||||
|
||||
$app->error(function (\Exception $e, $code) use ($app, $twig)
|
||||
{
|
||||
if ($e instanceof Bridge_Exception)
|
||||
{
|
||||
$request = $app['request'];
|
||||
|
||||
$params = array(
|
||||
'message' => $e->getMessage()
|
||||
, 'file' => $e->getFile()
|
||||
, 'line' => $e->getLine()
|
||||
, 'r_method' => $request->getMethod()
|
||||
, 'r_action' => $request->getRequestUri()
|
||||
, 'r_parameters' => ($request->getMethod() == 'GET' ? array() : $request->request->all())
|
||||
);
|
||||
|
||||
if ($e instanceof Bridge_Exception_ApiConnectorNotConfigured)
|
||||
{
|
||||
$params = array_merge($params, array('account' => $app['current_account']));
|
||||
|
||||
return new response($twig->render('/prod/actions/Bridge/notconfigured.twig', $params), 200);
|
||||
}
|
||||
elseif ($e instanceof Bridge_Exception_ApiConnectorNotConnected)
|
||||
{
|
||||
$params = array_merge($params, array('account' => $app['current_account']));
|
||||
|
||||
return new response($twig->render('/prod/actions/Bridge/disconnected.twig', $params), 200);
|
||||
}
|
||||
elseif ($e instanceof Bridge_Exception_ApiConnectorAccessTokenFailed)
|
||||
{
|
||||
$params = array_merge($params, array('account' => $app['current_account']));
|
||||
|
||||
return new response($twig->render('/prod/actions/Bridge/disconnected.twig', $params), 200);
|
||||
}
|
||||
elseif ($e instanceof Bridge_Exception_ApiDisabled)
|
||||
{
|
||||
$params = array_merge($params, array('api' => $e->get_api()));
|
||||
|
||||
return new response($twig->render('/prod/actions/Bridge/deactivated.twig', $params), 200);
|
||||
}
|
||||
return new response($twig->render('/prod/actions/Bridge/error.twig', $params), 200);
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
return $app;
|
||||
});
|
75
lib/classes/module/Root.php
Normal file
75
lib/classes/module/Root.php
Normal file
@@ -0,0 +1,75 @@
|
||||
<?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;
|
||||
|
||||
return call_user_func(function()
|
||||
{
|
||||
$app = new Application();
|
||||
|
||||
if (!setup::is_installed())
|
||||
{
|
||||
return $app->redirect("/setup/")->send();
|
||||
}
|
||||
|
||||
$app->get('/', function() use ($app)
|
||||
{
|
||||
$browser = Browser::getInstance();
|
||||
if ($browser->isMobile())
|
||||
return $app->redirect("/login/?redirect=/lightbox");
|
||||
elseif ($browser->isNewGeneration())
|
||||
return $app->redirect("/login/?redirect=/prod");
|
||||
else
|
||||
return $app->redirect("/login/?redirect=/client");
|
||||
});
|
||||
|
||||
$app->get('robots.txt', function() use ($app)
|
||||
{
|
||||
require dirname(__FILE__) . "/../lib/bootstrap.php";
|
||||
$appbox = appbox::get_instance();
|
||||
|
||||
$registry = $appbox->get_registry();
|
||||
|
||||
if ($registry->get('GV_allow_search_engine') === true)
|
||||
{
|
||||
$buffer = "User-Agent: *\n"
|
||||
. "Allow: /\n";
|
||||
}
|
||||
else
|
||||
{
|
||||
$buffer = "User-Agent: *\n"
|
||||
. "Disallow: /\n";
|
||||
}
|
||||
|
||||
$response = new Response($buffer, 200, array('Content-Type: text/plain'));
|
||||
$response->setCharset('UTF-8');
|
||||
|
||||
return $response;
|
||||
});
|
||||
|
||||
$app->mount('/feeds/', new Controller_RSSFeeds());
|
||||
|
||||
/**
|
||||
* Mount all aps
|
||||
*/
|
||||
return $app;
|
||||
}
|
||||
);
|
80
lib/classes/module/Setup.php
Normal file
80
lib/classes/module/Setup.php
Normal file
@@ -0,0 +1,80 @@
|
||||
<?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\Response;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Silex\Application;
|
||||
|
||||
return call_user_func(function()
|
||||
{
|
||||
$app = new Silex\Application();
|
||||
|
||||
$app['install'] = false;
|
||||
$app['upgrade'] = false;
|
||||
|
||||
$app->before(function($a) use ($app)
|
||||
{
|
||||
if (setup::is_installed())
|
||||
{
|
||||
$appbox = appbox::get_instance();
|
||||
|
||||
if (!$appbox->need_major_upgrade())
|
||||
throw new Exception_Setup_PhraseaAlreadyInstalled();
|
||||
|
||||
$app['upgrade'] = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
$app['install'] = true;
|
||||
}
|
||||
|
||||
return;
|
||||
});
|
||||
|
||||
|
||||
$app->get('/', function() use ($app)
|
||||
{
|
||||
if ($app['install'] === true)
|
||||
return $app->redirect('/setup/installer/');
|
||||
if ($app['upgrade'] === true)
|
||||
return $app->redirect('/setup/upgrader/');
|
||||
});
|
||||
|
||||
|
||||
$app->mount('/installer/', new Controller_Setup_Installer());
|
||||
$app->mount('/upgrader/', new Controller_Setup_Upgrader());
|
||||
$app->mount('/test', new Controller_Utils_PathFileTest());
|
||||
$app->mount('/connection_test', new Controller_Utils_ConnectionTest());
|
||||
|
||||
$app->error(function($e) use ($app)
|
||||
{
|
||||
if ($e instanceof Exception_Setup_PhraseaAlreadyInstalled)
|
||||
return $app->redirect('/login');
|
||||
|
||||
return new Response(
|
||||
sprintf(
|
||||
'Error %s @%s:%s'
|
||||
, $e->getFile()
|
||||
, $e->getLine()
|
||||
, $e->getMessage()
|
||||
)
|
||||
, 500
|
||||
);
|
||||
});
|
||||
|
||||
return $app;
|
||||
});
|
85
lib/classes/module/admin.class.php
Normal file
85
lib/classes/module/admin.class.php
Normal file
@@ -0,0 +1,85 @@
|
||||
<?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.
|
||||
*/
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @license http://opensource.org/licenses/gpl-3.0 GPLv3
|
||||
* @link www.phraseanet.com
|
||||
*/
|
||||
class module_admin
|
||||
{
|
||||
|
||||
function getTree($position=false)
|
||||
{
|
||||
$appbox = appbox::get_instance();
|
||||
$session = $appbox->get_session();
|
||||
|
||||
$usr_id = $session->get_usr_id();
|
||||
|
||||
$user = User_Adapter::getInstance($usr_id, $appbox);
|
||||
|
||||
$available = array(
|
||||
'connected'
|
||||
, 'registrations'
|
||||
, 'taskmanager'
|
||||
, 'base'
|
||||
, 'bases'
|
||||
, 'collection'
|
||||
, 'user'
|
||||
, 'users'
|
||||
);
|
||||
|
||||
$feature = 'connected';
|
||||
$featured = false;
|
||||
$position = explode(':', $position);
|
||||
if (count($position) > 0)
|
||||
{
|
||||
if (in_array($position[0], $available))
|
||||
{
|
||||
$feature = $position[0];
|
||||
if (isset($position[1]))
|
||||
$featured = $position[1];
|
||||
}
|
||||
}
|
||||
|
||||
$databoxes = $off_databoxes = array();
|
||||
foreach ($appbox->get_databoxes() as $databox)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (!$user->ACL()->has_access_to_sbas($databox->get_sbas_id()))
|
||||
continue;
|
||||
|
||||
$connbas = $databox->get_connection();
|
||||
}
|
||||
catch (Exception $e)
|
||||
{
|
||||
$off_databoxes[] = $databox;
|
||||
continue;
|
||||
}
|
||||
$databoxes[] = $databox;
|
||||
}
|
||||
|
||||
$params = array(
|
||||
'feature' => $feature
|
||||
, 'featured' => $featured
|
||||
, 'databoxes' => $databoxes
|
||||
, 'off_databoxes' => $off_databoxes
|
||||
);
|
||||
|
||||
$twig = new supertwig();
|
||||
return $twig->render('admin/tree.html.twig', $params);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
169
lib/classes/module/admin/route/users.class.php
Normal file
169
lib/classes/module/admin/route/users.class.php
Normal file
@@ -0,0 +1,169 @@
|
||||
<?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 module_admin_route_users
|
||||
{
|
||||
|
||||
protected $request;
|
||||
/**
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $results;
|
||||
/**
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $query_parms;
|
||||
/**
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
protected $usr_id;
|
||||
|
||||
public function __construct(Symfony\Component\HttpFoundation\Request $request)
|
||||
{
|
||||
$this->request = $request;
|
||||
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function search(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;
|
||||
$results_quantity = (int) $request->get('per_page');
|
||||
$results_quantity = ($results_quantity < 10 || $results_quantity > 50) ? 20 : $results_quantity;
|
||||
|
||||
$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")
|
||||
, 'ord' => $request->get("ord")
|
||||
, 'per_page' => $results_quantity
|
||||
, 'offset_start' => $offset_start
|
||||
);
|
||||
|
||||
$user = User_Adapter::getInstance($session->get_usr_id(), $appbox);
|
||||
$query = new User_Query($appbox);
|
||||
|
||||
if (is_array($request->get('base_id')))
|
||||
$query->on_base_ids($request->get('base_id'));
|
||||
elseif (is_array($request->get('sbas_id')))
|
||||
$query->on_sbas_ids($request->get('sbas_id'));
|
||||
|
||||
$this->results = $query->sort_by($request->get("srt"), $request->get("ord"))
|
||||
->like($request->get('like_field'), $request->get('like_value'))
|
||||
->get_inactives($request->get('inactives'))
|
||||
->include_templates(true)
|
||||
->on_bases_where_i_am($user->ACL(), array('canadmin'))
|
||||
->limit($offset_start, $results_quantity)
|
||||
->execute();
|
||||
|
||||
try
|
||||
{
|
||||
$invite_id = User_Adapter::get_usr_id_from_login('invite');
|
||||
$invite = User_Adapter::getInstance($invite_id, $appbox);
|
||||
}
|
||||
catch (Exception $e)
|
||||
{
|
||||
$invite = User_Adapter::create($appbox, 'invite', 'invite', '', false);
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
$autoregister_id = User_Adapter::get_usr_id_from_login('autoregister');
|
||||
$autoregister = User_Adapter::getInstance($autoregister_id, $appbox);
|
||||
}
|
||||
catch (Exception $e)
|
||||
{
|
||||
$autoregister = User_Adapter::create($appbox, 'autoregister', 'autoregister', '', false);
|
||||
}
|
||||
|
||||
foreach ($this->query_parms as $k => $v)
|
||||
{
|
||||
if (is_null($v))
|
||||
$this->query_parms[$k] = false;
|
||||
}
|
||||
|
||||
return array(
|
||||
'users' => $this->results,
|
||||
'parm' => $this->query_parms,
|
||||
'invite_user' => $invite,
|
||||
'autoregister_user' => $autoregister
|
||||
);
|
||||
}
|
||||
|
||||
public function create_newuser()
|
||||
{
|
||||
$email = $this->request->get('value');
|
||||
|
||||
if(!mail::validateEmail($email))
|
||||
{
|
||||
throw new Exception_InvalidArgument(_('Invalid mail address'));
|
||||
}
|
||||
|
||||
$appbox = appbox::get_instance();
|
||||
|
||||
$conn = $appbox->get_connection();
|
||||
$sql = 'SELECT usr_id FROM usr WHERE usr_mail = :email';
|
||||
$stmt = $conn->prepare($sql);
|
||||
$stmt->execute(array(':email' => $email));
|
||||
$row = $stmt->fetch(PDO::FETCH_ASSOC);
|
||||
$count = count($row);
|
||||
|
||||
if (!is_array($row) || $count == 0)
|
||||
{
|
||||
$created_user = User_Adapter::create($appbox, $email, random::generatePassword(16), $email, false, false);
|
||||
$this->usr_id = $created_user->get_id();
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->usr_id = $row['usr_id'];
|
||||
$created_user = User_Adapter::getInstance($this->usr_id, $appbox);
|
||||
}
|
||||
|
||||
return $created_user;
|
||||
}
|
||||
|
||||
public function create_template()
|
||||
{
|
||||
$name = $this->request->get('value');
|
||||
|
||||
if(trim($name) === '')
|
||||
{
|
||||
throw new Exception_InvalidArgument(_('Invalid template name'));
|
||||
}
|
||||
|
||||
$appbox = appbox::get_instance();
|
||||
$user = User_Adapter::getInstance($appbox->get_session()->get_usr_id(), $appbox);
|
||||
|
||||
$created_user = User_Adapter::create($appbox, $name, random::generatePassword(16), null, false, false);
|
||||
$created_user->set_template($user);
|
||||
$this->usr_id = $user->get_id();
|
||||
|
||||
return $created_user;
|
||||
}
|
||||
|
||||
}
|
639
lib/classes/module/admin/route/users/edit.class.php
Normal file
639
lib/classes/module/admin/route/users/edit.class.php
Normal file
@@ -0,0 +1,639 @@
|
||||
<?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 module_admin_route_users_edit
|
||||
{
|
||||
|
||||
protected $request;
|
||||
|
||||
/**
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $users = array();
|
||||
|
||||
/**
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $users_datas;
|
||||
|
||||
/**
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
protected $base_id;
|
||||
|
||||
/**
|
||||
*
|
||||
* @param Symfony\Component\HttpFoundation\Request $request
|
||||
* @return module_admin_route_users_edit
|
||||
*/
|
||||
public function __construct(Symfony\Component\HttpFoundation\Request $request)
|
||||
{
|
||||
$this->users = explode(';', $request->get('users'));
|
||||
|
||||
$this->request = $request;
|
||||
$appbox = appbox::get_instance();
|
||||
$session = $appbox->get_session();
|
||||
|
||||
$users = array();
|
||||
foreach ($this->users as $usr_id)
|
||||
{
|
||||
$usr_id = (int) $usr_id;
|
||||
|
||||
if ($usr_id > 0)
|
||||
$users[$usr_id] = $usr_id;
|
||||
}
|
||||
|
||||
$this->users = $users;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function delete_users()
|
||||
{
|
||||
$appbox = appbox::get_instance();
|
||||
foreach ($this->users as $usr_id)
|
||||
{
|
||||
$user = User_Adapter::getInstance($usr_id, $appbox);
|
||||
$this->delete_user($user);
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
protected function delete_user(User_Adapter $user)
|
||||
{
|
||||
$appbox = appbox::get_instance();
|
||||
$session = $appbox->get_session();
|
||||
|
||||
$list = array_keys(User_Adapter::getInstance($session->get_usr_id(), $appbox)->ACL()->get_granted_base(array('canadmin')));
|
||||
|
||||
$user->ACL()->revoke_access_from_bases($list);
|
||||
if ($user->ACL()->is_phantom())
|
||||
$user->delete();
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function get_users_rights()
|
||||
{
|
||||
$appbox = appbox::get_instance();
|
||||
$session = $appbox->get_session();
|
||||
$list = array_keys(User_Adapter::getInstance($session->get_usr_id(), $appbox)->ACL()->get_granted_base(array('canadmin')));
|
||||
|
||||
$sql = "SELECT
|
||||
b.sbas_id,
|
||||
b.base_id,
|
||||
sum(actif) as actif,
|
||||
sum(canputinalbum) as canputinalbum,
|
||||
sum(candwnldpreview) as candwnldpreview,
|
||||
sum(candwnldhd) as candwnldhd,
|
||||
sum(cancmd) as cancmd,
|
||||
sum(nowatermark) as nowatermark,
|
||||
|
||||
sum(canaddrecord) as canaddrecord,
|
||||
sum(canmodifrecord) as canmodifrecord,
|
||||
sum(chgstatus) as chgstatus,
|
||||
sum(candeleterecord) as candeleterecord,
|
||||
sum(imgtools) as imgtools,
|
||||
|
||||
sum(canadmin) as canadmin,
|
||||
sum(canreport) as canreport,
|
||||
sum(canpush) as canpush,
|
||||
sum(manage) as manage,
|
||||
sum(modify_struct) as modify_struct,
|
||||
|
||||
sum(sbu.bas_modif_th) as bas_modif_th,
|
||||
sum(sbu.bas_manage) as bas_manage,
|
||||
sum(sbu.bas_modify_struct) as bas_modify_struct,
|
||||
sum(sbu.bas_chupub) as bas_chupub,
|
||||
|
||||
sum(time_limited) as time_limited,
|
||||
DATE_FORMAT(limited_from,'%Y%m%d') as limited_from,
|
||||
DATE_FORMAT(limited_to,'%Y%m%d') as limited_to,
|
||||
|
||||
sum(restrict_dwnld) as restrict_dwnld,
|
||||
sum(remain_dwnld) as remain_dwnld,
|
||||
sum(month_dwnld_max) as month_dwnld_max,
|
||||
|
||||
mask_xor as maskxordec,
|
||||
bin(mask_xor) as maskxorbin,
|
||||
mask_and as maskanddec,
|
||||
bin(mask_and) as maskandbin
|
||||
|
||||
FROM (usr u, bas b, sbas s)
|
||||
LEFT JOIN (basusr bu)
|
||||
ON (bu.base_id = b.base_id AND u.usr_id = bu.usr_id)
|
||||
LEFT join sbasusr sbu
|
||||
ON (sbu.sbas_id = b.sbas_id AND u.usr_id = sbu.usr_id)
|
||||
WHERE ( (u.usr_id = " . implode(' OR u.usr_id = ', $this->users) . " )
|
||||
AND b.sbas_id = s.sbas_id
|
||||
AND (b.base_id = '" . implode("' OR b.base_id = '", $list) . "'))
|
||||
GROUP BY b.base_id
|
||||
ORDER BY s.ord, s.sbas_id, b.ord, b.base_id ";
|
||||
|
||||
$stmt = $appbox->get_connection()->prepare($sql);
|
||||
$stmt->execute();
|
||||
$rs = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
||||
$stmt->closeCursor();
|
||||
|
||||
$sql = 'SELECT base_id, sum(1) as access FROM basusr
|
||||
WHERE (usr_id = ' . implode(' OR usr_id = ', $this->users) . ')
|
||||
AND (base_id = ' . implode(' OR base_id = ', $list) . ')
|
||||
GROUP BY base_id';
|
||||
$stmt = $appbox->get_connection()->prepare($sql);
|
||||
$stmt->execute();
|
||||
$access = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
||||
$stmt->closeCursor();
|
||||
|
||||
$base_ids = array();
|
||||
foreach ($access as $acc)
|
||||
{
|
||||
$base_ids[$acc['base_id']] = $acc;
|
||||
}
|
||||
unset($access);
|
||||
|
||||
foreach ($rs as $k => $row)
|
||||
{
|
||||
$rs[$k]['access'] = array_key_exists($row['base_id'], $base_ids) ? $base_ids[$row['base_id']]['access'] : '0';
|
||||
foreach ($row as $dk => $data)
|
||||
{
|
||||
if (is_null($data))
|
||||
$rs[$k][$dk] = '0';
|
||||
}
|
||||
}
|
||||
|
||||
$this->users_datas = $rs;
|
||||
$out = array(
|
||||
'datas' => $this->users_datas,
|
||||
'users' => $this->users,
|
||||
'users_serial' => implode(';', $this->users),
|
||||
'base_id' => $this->base_id,
|
||||
'main_user' => null
|
||||
);
|
||||
|
||||
if (count($this->users) == 1)
|
||||
{
|
||||
$usr_id = array_pop($this->users);
|
||||
$out['main_user'] = User_Adapter::getInstance($usr_id, $appbox);
|
||||
}
|
||||
|
||||
return $out;
|
||||
}
|
||||
|
||||
public function get_quotas()
|
||||
{
|
||||
$this->base_id = (int) $this->request->get('base_id');
|
||||
|
||||
// $this->base_id = (int) $parm['base_id'];
|
||||
|
||||
$sql = "SELECT u.usr_id, restrict_dwnld, remain_dwnld, month_dwnld_max
|
||||
FROM (usr u INNER JOIN basusr bu ON u.usr_id = bu.usr_id)
|
||||
WHERE u.usr_id = " . implode(' OR u.usr_id = ', $this->users) . "
|
||||
AND bu.base_id = :base_id";
|
||||
|
||||
$conn = connection::getPDOConnection();
|
||||
$stmt = $conn->prepare($sql);
|
||||
$stmt->execute(array(':base_id' => $this->base_id));
|
||||
$rs = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
||||
$stmt->closeCursor();
|
||||
|
||||
$this->users_datas = $rs;
|
||||
|
||||
return array(
|
||||
'datas' => $this->users_datas,
|
||||
'users' => $this->users,
|
||||
'users_serial' => implode(';', $this->users),
|
||||
'base_id' => $this->base_id
|
||||
);
|
||||
}
|
||||
|
||||
public function get_masks()
|
||||
{
|
||||
$this->base_id = (int) $this->request->get('base_id');
|
||||
|
||||
$sql = "SELECT BIN(mask_and) AS mask_and, BIN(mask_xor) AS mask_xor
|
||||
FROM basusr
|
||||
WHERE usr_id IN (" . implode(',', $this->users) . ")
|
||||
AND base_id = :base_id";
|
||||
|
||||
$conn = connection::getPDOConnection();
|
||||
$stmt = $conn->prepare($sql);
|
||||
$stmt->execute(array(':base_id' => $this->base_id));
|
||||
$rs = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
||||
$stmt->closeCursor();
|
||||
|
||||
|
||||
$msk_and = null;
|
||||
$msk_xor = null;
|
||||
$tbits_and = array();
|
||||
$tbits_xor = array();
|
||||
|
||||
$nrows = 0;
|
||||
|
||||
for ($bit = 0; $bit < 64; $bit++)
|
||||
$tbits_and[$bit] = $tbits_xor[$bit] = array("nset" => 0);
|
||||
|
||||
foreach ($rs as $row)
|
||||
{
|
||||
$sta_xor = strrev($row["mask_xor"]);
|
||||
for ($bit = 0; $bit < strlen($sta_xor); $bit++)
|
||||
$tbits_xor[$bit]["nset"] += substr($sta_xor, $bit, 1) != "0" ? 1 : 0;
|
||||
|
||||
$sta_and = strrev($row["mask_and"]);
|
||||
for ($bit = 0; $bit < strlen($sta_and); $bit++)
|
||||
$tbits_and[$bit]["nset"] += substr($sta_and, $bit, 1) != "0" ? 1 : 0;
|
||||
|
||||
$nrows++;
|
||||
}
|
||||
|
||||
$tbits_left = array();
|
||||
$tbits_right = array();
|
||||
|
||||
$sbas_id = phrasea::sbasFromBas($this->base_id);
|
||||
$databox = databox::get_instance($sbas_id);
|
||||
$status = $databox->get_statusbits();
|
||||
|
||||
foreach ($status as $bit => $datas)
|
||||
{
|
||||
$tbits_left[$bit]["nset"] = 0;
|
||||
$tbits_left[$bit]["name"] = $datas["labeloff"];
|
||||
$tbits_left[$bit]["icon"] = $datas["img_off"];
|
||||
|
||||
$tbits_right[$bit]["nset"] = 0;
|
||||
$tbits_right[$bit]["name"] = $datas["labelon"];
|
||||
$tbits_right[$bit]["icon"] = $datas["img_on"];
|
||||
}
|
||||
|
||||
$vand_and = $vand_or = $vxor_and = $vxor_or = "0000";
|
||||
|
||||
for ($bit = 4; $bit < 64; $bit++)
|
||||
{
|
||||
if (($tbits_and[$bit]["nset"] != 0 && $tbits_and[$bit]["nset"] != $nrows) || ($tbits_xor[$bit]["nset"] != 0 && $tbits_xor[$bit]["nset"] != $nrows))
|
||||
{
|
||||
if (isset($tbits_left[$bit]) && isset($tbits_right[$bit]))
|
||||
{
|
||||
$tbits_left[$bit]["nset"] = 2;
|
||||
$tbits_right[$bit]["nset"] = 2;
|
||||
}
|
||||
$vand_and = "1" . $vand_and;
|
||||
$vand_or = "0" . $vand_or;
|
||||
$vxor_and = "1" . $vxor_and;
|
||||
$vxor_or = "0" . $vxor_or;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (isset($tbits_left[$bit]) && isset($tbits_right[$bit]))
|
||||
{
|
||||
$tbits_left[$bit]["nset"] = (($tbits_and[$bit]["nset"] == $nrows && $tbits_xor[$bit]["nset"] == 0) || $tbits_and[$bit]["nset"] == 0 ) ? 1 : 0;
|
||||
$tbits_right[$bit]["nset"] = (($tbits_and[$bit]["nset"] == $nrows && $tbits_xor[$bit]["nset"] == $nrows) || $tbits_and[$bit]["nset"] == 0 ) ? 1 : 0;
|
||||
}
|
||||
$vand_and = ($tbits_and[$bit]["nset"] == 0 ? "0" : "1") . $vand_and;
|
||||
$vand_or = ($tbits_and[$bit]["nset"] == $nrows ? "1" : "0") . $vand_or;
|
||||
$vxor_and = ($tbits_xor[$bit]["nset"] == 0 ? "0" : "1") . $vxor_and;
|
||||
$vxor_or = ($tbits_xor[$bit]["nset"] == $nrows ? "1" : "0") . $vxor_or;
|
||||
}
|
||||
}
|
||||
|
||||
$this->users_datas = array(
|
||||
'tbits_left' => $tbits_left,
|
||||
'tbits_right' => $tbits_right,
|
||||
'vand_and' => $vand_and,
|
||||
'vand_or' => $vand_or,
|
||||
'vxor_and' => $vxor_and,
|
||||
'vxor_or' => $vxor_or
|
||||
);
|
||||
|
||||
return array(
|
||||
'datas' => $this->users_datas,
|
||||
'users' => $this->users,
|
||||
'users_serial' => implode(';', $this->users),
|
||||
'base_id' => $this->base_id
|
||||
);
|
||||
}
|
||||
|
||||
public function get_time()
|
||||
{
|
||||
$this->base_id = (int) $this->request->get('base_id');
|
||||
|
||||
$sql = "SELECT u.usr_id, time_limited, limited_from, limited_to
|
||||
FROM (usr u INNER JOIN basusr bu ON u.usr_id = bu.usr_id)
|
||||
WHERE u.usr_id = " . implode(' OR u.usr_id = ', $this->users) . "
|
||||
AND bu.base_id = :base_id";
|
||||
|
||||
$conn = connection::getPDOConnection();
|
||||
$stmt = $conn->prepare($sql);
|
||||
$stmt->execute(array(':base_id' => $this->base_id));
|
||||
$rs = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
||||
$stmt->closeCursor();
|
||||
|
||||
$time_limited = -1;
|
||||
$limited_from = $limited_to = false;
|
||||
|
||||
foreach ($rs as $row)
|
||||
{
|
||||
if ($time_limited < 0)
|
||||
$time_limited = $row['time_limited'];
|
||||
if ($time_limited < 2 && $row['time_limited'] != $row['time_limited'])
|
||||
$time_limited = 2;
|
||||
|
||||
if ($limited_from !== '' && trim($row['limited_from']) != '0000-00-00 00:00:00')
|
||||
{
|
||||
$limited_from = $limited_from === false ? $row['limited_from'] : (($limited_from == $row['limited_from']) ? $limited_from : '');
|
||||
}
|
||||
if ($limited_to !== '' && trim($row['limited_to']) != '0000-00-00 00:00:00')
|
||||
{
|
||||
$limited_to = $limited_to === false ? $row['limited_to'] : (($limited_to == $row['limited_to']) ? $limited_to : '');
|
||||
}
|
||||
}
|
||||
|
||||
if ($limited_from)
|
||||
{
|
||||
$date_obj_from = new DateTime($limited_from);
|
||||
$limited_from = $date_obj_from->format('Y-m-d');
|
||||
}
|
||||
if ($limited_to)
|
||||
{
|
||||
$date_obj_to = new DateTime($limited_to);
|
||||
$limited_to = $date_obj_to->format('Y-m-d');
|
||||
}
|
||||
|
||||
$datas = array('time_limited' => $time_limited, 'limited_from' => $limited_from, 'limited_to' => $limited_to);
|
||||
|
||||
$this->users_datas = $datas;
|
||||
|
||||
return array(
|
||||
'datas' => $this->users_datas,
|
||||
'users' => $this->users,
|
||||
'users_serial' => implode(';', $this->users),
|
||||
'base_id' => $this->base_id
|
||||
);
|
||||
}
|
||||
|
||||
public function apply_rights()
|
||||
{
|
||||
$appbox = appbox::get_instance();
|
||||
$session = $appbox->get_session();
|
||||
$request = http_request::getInstance();
|
||||
$ACL = User_Adapter::getInstance($session->get_usr_id(), $appbox)->ACL();
|
||||
$base_ids = array_keys($ACL->get_granted_base(array('canadmin')));
|
||||
|
||||
$update = $create = $delete = $create_sbas = $update_sbas = array();
|
||||
|
||||
foreach ($base_ids as $base_id)
|
||||
{
|
||||
$rights = array(
|
||||
'access',
|
||||
'actif',
|
||||
'canputinalbum',
|
||||
'nowatermark',
|
||||
'candwnldpreview',
|
||||
'candwnldhd',
|
||||
'cancmd',
|
||||
'canaddrecord',
|
||||
'canmodifrecord',
|
||||
'chgstatus',
|
||||
'candeleterecord',
|
||||
'imgtools',
|
||||
'canadmin',
|
||||
'canreport',
|
||||
'canpush',
|
||||
'manage',
|
||||
'modify_struct'
|
||||
);
|
||||
foreach ($rights as $k => $right)
|
||||
{
|
||||
if (($right == 'access' && !$ACL->has_access_to_base($base_id))
|
||||
|| ($right != 'access' && !$ACL->has_right_on_base($base_id, $right)))
|
||||
{
|
||||
unset($rights[$k]);
|
||||
continue;
|
||||
}
|
||||
$rights[$k] = $right . '_' . $base_id;
|
||||
}
|
||||
$parm = $request->get_parms_from_serialized_datas($rights, 'values');
|
||||
|
||||
foreach ($parm as $p => $v)
|
||||
{
|
||||
if (trim($v) == '')
|
||||
continue;
|
||||
|
||||
$serial = explode('_', $p);
|
||||
$base_id = array_pop($serial);
|
||||
|
||||
$p = implode('_', $serial);
|
||||
|
||||
if ($p == 'access')
|
||||
{
|
||||
if ($v === '1')
|
||||
{
|
||||
$create_sbas[phrasea::sbasFromBas($base_id)] = phrasea::sbasFromBas($base_id);
|
||||
$create[] = $base_id;
|
||||
}
|
||||
else
|
||||
$delete[] = $base_id;
|
||||
}
|
||||
else
|
||||
{
|
||||
$create_sbas[phrasea::sbasFromBas($base_id)] = phrasea::sbasFromBas($base_id);
|
||||
$update[$base_id][$p] = $v;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$sbas_ids = $ACL->get_granted_sbas();
|
||||
|
||||
foreach ($sbas_ids as $databox)
|
||||
{
|
||||
$rights = array(
|
||||
'bas_modif_th',
|
||||
'bas_manage',
|
||||
'bas_modify_struct',
|
||||
'bas_chupub'
|
||||
);
|
||||
foreach ($rights as $k => $right)
|
||||
{
|
||||
if (!$ACL->has_right_on_sbas($databox->get_sbas_id(), $right))
|
||||
{
|
||||
unset($rights[$k]);
|
||||
continue;
|
||||
}
|
||||
$rights[$k] = $right . '_' . $databox->get_sbas_id();
|
||||
}
|
||||
|
||||
$parm = $request->get_parms_from_serialized_datas($rights, 'values');
|
||||
|
||||
foreach ($parm as $p => $v)
|
||||
{
|
||||
if (trim($v) == '')
|
||||
continue;
|
||||
|
||||
$serial = explode('_', $p);
|
||||
$sbas_id = array_pop($serial);
|
||||
|
||||
$p = implode('_', $serial);
|
||||
|
||||
$update_sbas[$sbas_id][$p] = $v;
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($this->users as $usr_id)
|
||||
{
|
||||
try
|
||||
{
|
||||
$appbox->get_connection()->beginTransaction();
|
||||
|
||||
$user = User_Adapter::getInstance($usr_id, $appbox);
|
||||
$user->ACL()->revoke_access_from_bases($delete)
|
||||
->give_access_to_base($create)
|
||||
->give_access_to_sbas($create_sbas);
|
||||
|
||||
foreach ($update as $base_id => $rights)
|
||||
{
|
||||
$user->ACL()->update_rights_to_base($base_id, $rights);
|
||||
}
|
||||
|
||||
foreach ($update_sbas as $sbas_id => $rights)
|
||||
{
|
||||
$user->ACL()->update_rights_to_sbas($sbas_id, $rights);
|
||||
}
|
||||
|
||||
$appbox->get_connection()->commit();
|
||||
|
||||
$user->ACL()->revoke_unused_sbas_rights();
|
||||
|
||||
unset($user);
|
||||
}
|
||||
catch (Exception $e)
|
||||
{
|
||||
$appbox->get_connection()->rollBack();
|
||||
}
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function apply_infos()
|
||||
{
|
||||
if (count($this->users) != 1)
|
||||
{
|
||||
return $this;
|
||||
}
|
||||
|
||||
$appbox = appbox::get_instance();
|
||||
$session = $appbox->get_session();
|
||||
$request = http_request::getInstance();
|
||||
|
||||
$infos = array(
|
||||
'gender'
|
||||
, 'first_name'
|
||||
, 'last_name'
|
||||
, 'email'
|
||||
, 'address'
|
||||
, 'zip'
|
||||
, 'geonameid'
|
||||
, 'function'
|
||||
, 'company'
|
||||
, 'activite'
|
||||
, 'telephone'
|
||||
, 'fax'
|
||||
);
|
||||
|
||||
$parm = $request->get_parms_from_serialized_datas($infos, 'user_infos');
|
||||
|
||||
foreach ($this->users as $usr_id)
|
||||
{
|
||||
|
||||
if (!mail::validateEmail($parm['email']))
|
||||
throw new Exception_InvalidArgument(_('Email addess is not valid'));
|
||||
|
||||
$user = User_Adapter::getInstance($usr_id, $appbox);
|
||||
$user->set_firstname($parm['first_name'])
|
||||
->set_lastname($parm['last_name'])
|
||||
->set_email($parm['email'])
|
||||
->set_address($parm['address'])
|
||||
->set_zip($parm['zip'])
|
||||
->set_geonameid($parm['geonameid'])
|
||||
->set_position($parm['function'])
|
||||
->set_job($parm['activite'])
|
||||
->set_company($parm['company'])
|
||||
->set_tel($parm['telephone'])
|
||||
->set_fax($parm['fax']);
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function apply_quotas()
|
||||
{
|
||||
$this->base_id = (int) $this->request->get('base_id');
|
||||
|
||||
foreach ($this->users as $usr_id)
|
||||
{
|
||||
$user = User_Adapter::getInstance($usr_id, appbox::get_instance());
|
||||
if ($this->request->get('quota'))
|
||||
$user->ACL()->set_quotas_on_base($this->base_id, $this->request->get('droits'), $this->request->get('restes'));
|
||||
else
|
||||
$user->ACL()->remove_quotas_on_base($this->base_id);
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function apply_masks()
|
||||
{
|
||||
$this->base_id = (int) $this->request->get('base_id');
|
||||
|
||||
$vand_and = $this->request->get('vand_and');
|
||||
$vand_or = $this->request->get('vand_or');
|
||||
$vxor_and = $this->request->get('vxor_and');
|
||||
$vxor_or = $this->request->get('vxor_or');
|
||||
|
||||
if ($vand_and && $vand_or && $vxor_and && $vxor_or)
|
||||
{
|
||||
foreach ($this->users as $usr_id)
|
||||
{
|
||||
$user = User_Adapter::getInstance($usr_id, appbox::get_instance());
|
||||
|
||||
$user->ACL()->set_masks_on_base($this->base_id, $vand_and, $vand_or, $vxor_and, $vxor_or);
|
||||
}
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function apply_time()
|
||||
{
|
||||
|
||||
$this->base_id = (int) $this->request->get('base_id');
|
||||
|
||||
$dmin = $this->request->get('dmin') ? new DateTime($this->request->get('dmin')) : null;
|
||||
$dmax = $this->request->get('dmax') ? new DateTime($this->request->get('dmax')) : null;
|
||||
|
||||
$activate = $this->request->get('limit');
|
||||
|
||||
foreach ($this->users as $usr_id)
|
||||
{
|
||||
$user = User_Adapter::getInstance($usr_id, appbox::get_instance());
|
||||
|
||||
$user->ACL()->set_limits($this->base_id, $activate, $dmin, $dmax);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
433
lib/classes/module/api/OAuthv2.php
Normal file
433
lib/classes/module/api/OAuthv2.php
Normal file
@@ -0,0 +1,433 @@
|
||||
<?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 OAuth2 Connector
|
||||
*
|
||||
* @see http://oauth.net/2/
|
||||
* @uses http://code.google.com/p/oauth2-php/
|
||||
*
|
||||
* @license http://opensource.org/licenses/gpl-3.0 GPLv3
|
||||
* @link www.phraseanet.com
|
||||
*/
|
||||
require_once dirname(__FILE__) . "/../../../../lib/bootstrap.php";
|
||||
require_once dirname(__FILE__) . "/../../../../lib/classes/API/OAuth2/Autoloader.class.php";
|
||||
bootstrap::register_autoloads();
|
||||
API_OAuth2_Autoloader::register();
|
||||
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\HttpKernel\Exception\HttpExceptionInterface;
|
||||
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
|
||||
|
||||
return call_user_func(function()
|
||||
{
|
||||
$app = new Silex\Application();
|
||||
|
||||
$app->register(new Silex\Provider\ValidatorServiceProvider(), array(
|
||||
'validator.class_path' => __DIR__ . '/../../../../lib/vendor/symfony/src',
|
||||
));
|
||||
|
||||
|
||||
$app['appbox'] = function()
|
||||
{
|
||||
return appbox::get_instance();
|
||||
};
|
||||
|
||||
$app['supertwig'] = $app->share(function()
|
||||
{
|
||||
$twig = new supertwig();
|
||||
$twig->addFilter(array('prettyDate' => 'phraseadate::getPrettyString'));
|
||||
|
||||
return $twig;
|
||||
});
|
||||
|
||||
$app['oauth'] = function($app)
|
||||
{
|
||||
return new API_OAuth2_Adapter($app['appbox']);
|
||||
};
|
||||
|
||||
|
||||
$app['user'] = function($app)
|
||||
{
|
||||
if ($app['appbox']->get_session()->is_authenticated())
|
||||
{
|
||||
$user = user_adapter::getInstance(
|
||||
$app['appbox']->get_session()->get_usr_id()
|
||||
, $app['appbox']
|
||||
);
|
||||
|
||||
return $user;
|
||||
}
|
||||
else
|
||||
{
|
||||
return null;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Protected Closure
|
||||
* @var Closure
|
||||
* @return Symfony\Component\HttpFoundation\Response
|
||||
*/
|
||||
$app['response'] = $app->protect(function ($template, $variable) use ($app)
|
||||
{
|
||||
$response = new Response(
|
||||
$app['supertwig']->render($template, $variable)
|
||||
, 200
|
||||
, array('Content-Type' => 'text/html')
|
||||
);
|
||||
$response->setCharset('UTF-8');
|
||||
|
||||
return $response;
|
||||
});
|
||||
|
||||
|
||||
/* * *******************************************************************
|
||||
* AUTHENTIFICATION API
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* AUTHORIZE ENDPOINT
|
||||
*
|
||||
* Authorization endpoint - used to obtain authorization from the
|
||||
* resource owner via user-agent redirection.
|
||||
*/
|
||||
$authorize_func = function() use ($app)
|
||||
{
|
||||
$request = $app['request'];
|
||||
$oauth2_adapter = $app['oauth'];
|
||||
$twig = $app['supertwig'];
|
||||
$session = $app['appbox']->get_session();
|
||||
|
||||
//Check for auth params, send error or redirect if not valid
|
||||
$params = $oauth2_adapter->getAuthorizationRequestParameters($request);
|
||||
|
||||
$authenticated = $session->is_authenticated();
|
||||
$app_authorized = false;
|
||||
$errorMessage = false;
|
||||
|
||||
$client = API_OAuth2_Application::load_from_client_id($app['appbox'], $params['client_id']);
|
||||
|
||||
$oauth2_adapter->setClient($client);
|
||||
|
||||
$action_accept = $request->get("action_accept", null);
|
||||
$action_login = $request->get("action_login", null);
|
||||
|
||||
|
||||
$template = "api/auth/end_user_authorization.twig";
|
||||
$custom_template = $app['appbox']->get_registry()->get('GV_RootPath') . 'config/templates/web/api/auth/end_user_authorization/' . $client->get_id() . '.twig';
|
||||
if (file_exists($custom_template))
|
||||
{
|
||||
$template = 'api/auth/end_user_authorization/' . $client->get_id() . '.twig';
|
||||
}
|
||||
|
||||
if (!$authenticated)
|
||||
{
|
||||
if ($action_login !== null)
|
||||
{
|
||||
try
|
||||
{
|
||||
$login = $request->get("login");
|
||||
$password = $request->get("password");
|
||||
$auth = new Session_Authentication_Native($app['appbox'], $login, $password);
|
||||
$session->authenticate($auth);
|
||||
}
|
||||
catch (Exception $e)
|
||||
{
|
||||
$params = array(
|
||||
"auth" => $oauth2_adapter
|
||||
, "session" => $session
|
||||
, "errorMessage" => true
|
||||
, "user" => $app['user']
|
||||
);
|
||||
$html = $twig->render($template, $params);
|
||||
|
||||
return new Response($html, 200, array("content-type" => "text/html"));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$params = array(
|
||||
"auth" => $oauth2_adapter
|
||||
, "session" => $session
|
||||
, "errorMessage" => $errorMessage
|
||||
, "user" => $app['user']
|
||||
);
|
||||
$html = $twig->render($template, $params);
|
||||
|
||||
return new Response($html, 200, array("content-type" => "text/html"));
|
||||
}
|
||||
}
|
||||
|
||||
//check if current client is alreadu authorized by current user
|
||||
$user_auth_clients = API_OAuth2_Application::load_authorized_app_by_user($app['appbox'], $app['user']);
|
||||
|
||||
foreach ($user_auth_clients as $auth_client)
|
||||
{
|
||||
if ($client->get_client_id() == $auth_client->get_client_id())
|
||||
$app_authorized = true;
|
||||
}
|
||||
|
||||
$account = $oauth2_adapter->updateAccount($session->get_usr_id());
|
||||
$params['account_id'] = $account->get_id();
|
||||
|
||||
if (!$app_authorized && $action_accept === null)
|
||||
{
|
||||
$params = array(
|
||||
"auth" => $oauth2_adapter
|
||||
, "session" => $session
|
||||
, "errorMessage" => $errorMessage
|
||||
, "user" => $app['user']
|
||||
);
|
||||
|
||||
$html = $twig->render($template, $params);
|
||||
|
||||
return new Response($html, 200, array("content-type" => "text/html"));
|
||||
}
|
||||
elseif (!$app_authorized && $action_accept !== null)
|
||||
{
|
||||
$app_authorized = !!$action_accept;
|
||||
$account->set_revoked(!$app_authorized);
|
||||
}
|
||||
|
||||
//if native app show template
|
||||
if ($oauth2_adapter->isNativeApp($params['redirect_uri']))
|
||||
{
|
||||
$params = $oauth2_adapter->finishNativeClientAuthorization($app_authorized, $params);
|
||||
$html = $twig->render("api/auth/native_app_access_token.twig", $params);
|
||||
|
||||
return new Response($html, 200, array("content-type" => "text/html"));
|
||||
}
|
||||
else
|
||||
{
|
||||
$oauth2_adapter->finishClientAuthorization($app_authorized, $params);
|
||||
}
|
||||
};
|
||||
|
||||
$route = '/authorize';
|
||||
$app->get($route, $authorize_func);
|
||||
$app->post($route, $authorize_func);
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* TOKEN ENDPOINT
|
||||
* Token endpoint - used to exchange an authorization grant for an access token.
|
||||
*/
|
||||
$route = '/token';
|
||||
$app->post($route, function() use ($app)
|
||||
{
|
||||
$app['oauth']->grantAccessToken();
|
||||
ob_flush();
|
||||
flush();
|
||||
|
||||
return;
|
||||
});
|
||||
|
||||
|
||||
/**
|
||||
* MANAGEMENT APPS
|
||||
*
|
||||
*
|
||||
*/
|
||||
/**
|
||||
* list of all authorized apps by logged user
|
||||
*/
|
||||
$route = '/applications';
|
||||
$app->get($route, function() use ($app)
|
||||
{
|
||||
$apps = API_OAuth2_Application::load_app_by_user($app['appbox'], $app['user']);
|
||||
|
||||
return $app['response']('api/auth/applications.twig', array("apps" => $apps, 'user' => $app['user']));
|
||||
});
|
||||
|
||||
/**
|
||||
* list of apps created by user
|
||||
*/
|
||||
$route = "/applications/dev";
|
||||
$app->get($route, function() use ($app)
|
||||
{
|
||||
$rs = API_OAuth2_Application::load_dev_app_by_user($app['appbox'], $app['user']);
|
||||
|
||||
return $app['response']('api/auth/application_dev.twig', array("apps" => $rs));
|
||||
});
|
||||
|
||||
/**
|
||||
* display a new app form
|
||||
*/
|
||||
$route = "/applications/dev/new";
|
||||
$app->get($route, function() use ($app)
|
||||
{
|
||||
$var = array("violations" => null);
|
||||
|
||||
return $app['response']('api/auth/application_dev_new.twig', $var);
|
||||
});
|
||||
|
||||
|
||||
|
||||
$route = "/applications/dev/create";
|
||||
$app->post($route, function() use ($app)
|
||||
{
|
||||
$submit = false;
|
||||
$post = new API_OAuth2_Form_DevApp($app['request']);
|
||||
$violations = $app['validator']->validate($post);
|
||||
|
||||
if ($violations->count() == 0)
|
||||
$submit = true;
|
||||
|
||||
$request = $app['request'];
|
||||
|
||||
if ($submit)
|
||||
{
|
||||
$application = API_OAuth2_Application::create($app['appbox'], $app['user'], $request->get('name'));
|
||||
$application->set_description($request->get('description'))
|
||||
->set_redirect_uri($request->get('callback'))
|
||||
->set_type($request->get('type'))
|
||||
->set_website($request->get('website'));
|
||||
|
||||
return $app->redirect("/api/oauthv2/applications/dev/" . $application->get_id() . "/show");
|
||||
}
|
||||
|
||||
$var = array(
|
||||
"violations" => $violations,
|
||||
"form" => $post
|
||||
);
|
||||
|
||||
return $app['response']('api/auth/application_dev_new.twig', $var);
|
||||
});
|
||||
|
||||
|
||||
/**
|
||||
* show details of app identified by its id
|
||||
*/
|
||||
$route = "/applications/dev/{id}/show";
|
||||
$app->get($route, function($id) use ($app)
|
||||
{
|
||||
$client = new API_OAuth2_Application($app['appbox'], $id);
|
||||
$token = $client->get_user_account($app['user'])->get_token()->get_value();
|
||||
$var = array("app" => $client, "user" => $app['user'], "token" => $token);
|
||||
|
||||
return $app['response']('api/auth/application_dev_show.twig', $var);
|
||||
});
|
||||
|
||||
/**
|
||||
* revoke access from a user to the app
|
||||
* identified by account id
|
||||
*/
|
||||
$route = "/applications/revoke_access/";
|
||||
$app->post($route, function() use ($app)
|
||||
{
|
||||
$result = array("ok" => false);
|
||||
try
|
||||
{
|
||||
$account = new API_OAuth2_Account($app['appbox'], $app['request']->get('account_id'));
|
||||
$account->set_revoked((bool) $app['request']->get('revoke'));
|
||||
$result['ok'] = true;
|
||||
}
|
||||
catch (Exception $e)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
return new Response(json_encode($result), 200, array("content-type" => "application/json"));
|
||||
});
|
||||
|
||||
$route = "/applications/{id}/generate_access_token/";
|
||||
$app->post($route, function($id) use ($app)
|
||||
{
|
||||
$result = array("ok" => false);
|
||||
try
|
||||
{
|
||||
$client = new API_OAuth2_Application($app['appbox'], $id);
|
||||
$account = $client->get_user_account($app['user']);
|
||||
|
||||
$token = $account->get_token();
|
||||
|
||||
if ($token instanceof API_OAuth2_Token)
|
||||
$token->renew();
|
||||
else
|
||||
$token = API_OAuth2_Token::create($app['appbox'], $account);
|
||||
|
||||
$result = array(
|
||||
"ok" => true
|
||||
, 'token' => $token->get_value()
|
||||
);
|
||||
}
|
||||
catch (Exception $e)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
return new response(json_encode($result), 200, array("content-type" => "application/json"));
|
||||
});
|
||||
|
||||
$route = "/applications/oauth_callback";
|
||||
$app->post($route, function() use ($app)
|
||||
{
|
||||
$app_id = $app['request']->request->get("app_id");
|
||||
$app_callback = $app["request"]->request->get("callback");
|
||||
$result = array("success" => false);
|
||||
try
|
||||
{
|
||||
$client = new API_OAuth2_Application($app['appbox'], $app_id);
|
||||
$client->set_redirect_uri($app_callback);
|
||||
$result['success'] = true;
|
||||
}
|
||||
catch (Exception $e)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
return new Response(json_encode($result), 200, array("content-type" => "application/json"));
|
||||
});
|
||||
|
||||
$route = "/applications/{id}";
|
||||
$app->delete($route, function($id) use ($app)
|
||||
{
|
||||
$result = array("success" => false);
|
||||
try
|
||||
{
|
||||
$client = new API_OAuth2_Application($app['appbox'], $id);
|
||||
$client->delete();
|
||||
$result['success'] = true;
|
||||
}
|
||||
catch (Exception $e)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
return new Response(json_encode($result), 200, array("content-type" => "application/json"));
|
||||
});
|
||||
/**
|
||||
* *******************************************************************
|
||||
*
|
||||
* Route Errors
|
||||
*
|
||||
*/
|
||||
$app->error(function (Exception $e) use ($app)
|
||||
{
|
||||
if ($e instanceof NotFoundHttpException || $e instanceof Exception_NotFound)
|
||||
{
|
||||
return new Response('The requested page could not be found.', 404);
|
||||
}
|
||||
|
||||
$code = $e instanceof HttpExceptionInterface ? $e->getStatusCode() : 500;
|
||||
|
||||
return new Response('We are sorry, but something went terribly wrong.<br />' . $e->getMessage(), $code);
|
||||
});
|
||||
|
||||
|
||||
return $app;
|
||||
});
|
748
lib/classes/module/api/V1.php
Normal file
748
lib/classes/module/api/V1.php
Normal file
@@ -0,0 +1,748 @@
|
||||
<?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 APIv1
|
||||
* @license http://opensource.org/licenses/gpl-3.0 GPLv3
|
||||
* @link www.phraseanet.com
|
||||
*/
|
||||
/**
|
||||
* Application Routage for API v1
|
||||
*/
|
||||
require_once dirname(__FILE__) . "/../../../../lib/classes/API/OAuth2/Autoloader.class.php";
|
||||
require_once dirname(__FILE__) . "/../../../../lib/bootstrap.php";
|
||||
|
||||
bootstrap::register_autoloads();
|
||||
API_OAuth2_Autoloader::register();
|
||||
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpKernel\Exception;
|
||||
|
||||
return call_user_func(function(){
|
||||
|
||||
|
||||
$app = new Silex\Application();
|
||||
|
||||
$app["appbox"] = appbox::get_instance();
|
||||
|
||||
/**
|
||||
* Associated user to related token
|
||||
* @var User_Adapter
|
||||
*/
|
||||
$app['p4user'] = null;
|
||||
|
||||
/**
|
||||
* @var API_OAuth2_Token
|
||||
*/
|
||||
$app['token'] = null;
|
||||
|
||||
/**
|
||||
* Protected Closure
|
||||
* @var Closure
|
||||
* @return Symfony\Component\HttpFoundation\Response
|
||||
*/
|
||||
$app['response'] = $app->protect(function ($result)
|
||||
{
|
||||
$response = new Response(
|
||||
$result->format()
|
||||
, $result->get_http_code()
|
||||
, array('Content-Type' => $result->get_content_type())
|
||||
);
|
||||
$response->setCharset('UTF-8');
|
||||
|
||||
return $response;
|
||||
});
|
||||
|
||||
/**
|
||||
* Api Service
|
||||
* @var Closure
|
||||
*/
|
||||
$app['api'] = function () use ($app)
|
||||
{
|
||||
return new API_V1_adapter(false, $app["appbox"]);
|
||||
};
|
||||
|
||||
|
||||
|
||||
$parseRoute = function ($route, Response $response)
|
||||
{
|
||||
$ressource = $general = $aspect = $action = null;
|
||||
$exploded_route = explode('/', p4string::delFirstSlash((p4string::delEndSlash($route))));
|
||||
if (sizeof($exploded_route) > 0 && $response->isOk())
|
||||
{
|
||||
$ressource = $exploded_route[0];
|
||||
|
||||
if (sizeof($exploded_route) == 2 && (int) $exploded_route[1] == 0)
|
||||
{
|
||||
$general = $exploded_route[1];
|
||||
}
|
||||
else
|
||||
{
|
||||
switch ($ressource)
|
||||
{
|
||||
case API_V1_Log::DATABOXES_RESSOURCE :
|
||||
if ((int) $exploded_route[1] > 0 && sizeof($exploded_route) == 3)
|
||||
$aspect = $exploded_route[2];
|
||||
break;
|
||||
case API_V1_Log::RECORDS_RESSOURCE :
|
||||
if ((int) $exploded_route[1] > 0 && sizeof($exploded_route) == 4)
|
||||
{
|
||||
if (!isset($exploded_route[3]))
|
||||
$aspect = "record";
|
||||
elseif (preg_match("/^set/", $exploded_route[3]))
|
||||
$action = $exploded_route[3];
|
||||
else
|
||||
$aspect = $exploded_route[3];
|
||||
}
|
||||
break;
|
||||
case API_V1_Log::BASKETS_RESSOURCE :
|
||||
if ((int) $exploded_route[1] > 0 && sizeof($exploded_route) == 3)
|
||||
{
|
||||
if (preg_match("/^set/", $exploded_route[2]) || preg_match("/^delete/", $exploded_route[2]))
|
||||
$action = $exploded_route[2];
|
||||
else
|
||||
$aspect = $exploded_route[2];
|
||||
}
|
||||
break;
|
||||
case API_V1_Log::FEEDS_RESSOURCE :
|
||||
if ((int) $exploded_route[1] > 0 && sizeof($exploded_route) == 3)
|
||||
$aspect = $exploded_route[2];
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
return array('ressource' => $ressource, 'general' => $general, 'aspect' => $aspect, 'action' => $action);
|
||||
};
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* oAuth verification process
|
||||
*/
|
||||
$app->before(function($request) use ($app)
|
||||
{
|
||||
$session = $app["appbox"]->get_session();
|
||||
$oauth2_adapter = new API_OAuth2_Adapter($app["appbox"]);
|
||||
$oauth2_adapter->verifyAccessToken();
|
||||
|
||||
$app['p4user'] = User_Adapter::getInstance($oauth2_adapter->get_usr_id(), $app["appbox"]);
|
||||
$app['token'] = API_OAuth2_Token::load_by_oauth_token($app["appbox"], $oauth2_adapter->getToken());
|
||||
|
||||
if ($session->is_authenticated())
|
||||
return;
|
||||
if ($oauth2_adapter->has_ses_id())
|
||||
{
|
||||
try
|
||||
{
|
||||
$session->restore($app['p4user'], $oauth2_adapter->get_ses_id());
|
||||
|
||||
return;
|
||||
}
|
||||
catch (Exception $e)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
$auth = new Session_Authentication_None($app['p4user']);
|
||||
$session->authenticate($auth);
|
||||
$oauth2_adapter->remember_this_ses_id($session->get_ses_id());
|
||||
|
||||
return;
|
||||
});
|
||||
|
||||
|
||||
/**
|
||||
* oAUth log process
|
||||
*/
|
||||
$app->after(function (Request $request, Response $response) use ($app, $parseRoute)
|
||||
{
|
||||
$account = $app['token']->get_account();
|
||||
$pathInfo = $request->getPathInfo();
|
||||
$route = $parseRoute($pathInfo, $response);
|
||||
$log = API_V1_Log::create(
|
||||
$app["appbox"],
|
||||
$account,
|
||||
$request->getMethod() . " " . $pathInfo,
|
||||
$response->getStatusCode(),
|
||||
$response->headers->get('content-type'),
|
||||
$route['ressource'],
|
||||
$route['general'],
|
||||
$route['aspect'],
|
||||
$route['action']);
|
||||
});
|
||||
|
||||
/**
|
||||
* Method Not Allowed Closure
|
||||
*/
|
||||
$bad_request_exception = function()
|
||||
{
|
||||
throw new API_V1_exception_badrequest();
|
||||
};
|
||||
|
||||
/**
|
||||
* *******************************************************************
|
||||
* Route : /databoxes/list/FORMAT/
|
||||
*
|
||||
* Method : GET
|
||||
*
|
||||
* Parameters :
|
||||
*
|
||||
*/
|
||||
$route = '/databoxes/list/';
|
||||
$app->get(
|
||||
$route, function() use ($app)
|
||||
{
|
||||
return $app['response']($app['api']->get_databoxes($app['request']));
|
||||
}
|
||||
);
|
||||
|
||||
/**
|
||||
* *******************************************************************
|
||||
*
|
||||
* Route /databoxes/DATABOX_ID/collections/FORMAT/
|
||||
*
|
||||
* Method : GET
|
||||
*
|
||||
* Parameters ;
|
||||
* DATABOX_ID : required INT
|
||||
*/
|
||||
$route = '/databoxes/{databox_id}/collections/';
|
||||
$app->get(
|
||||
$route, function($databox_id) use ($app)
|
||||
{
|
||||
$result = $app['api']->get_databox_collections($app['request'], $databox_id);
|
||||
|
||||
return $app['response']($result);
|
||||
}
|
||||
)->assert('databox_id', '\d+');
|
||||
|
||||
$app->get('/databoxes/{any_id}/collections/', $bad_request_exception);
|
||||
|
||||
|
||||
/**
|
||||
* *******************************************************************
|
||||
* Route /databoxes/DATABOX_ID/status/FORMAT/
|
||||
*
|
||||
* Method : GET
|
||||
*
|
||||
* Parameters ;
|
||||
* DATABOX_ID : required INT
|
||||
*
|
||||
*/
|
||||
$route = '/databoxes/{databox_id}/status/';
|
||||
$app->get(
|
||||
$route, function($databox_id) use ($app)
|
||||
{
|
||||
$result = $app['api']->get_databox_status($app['request'], $databox_id);
|
||||
|
||||
return $app['response']($result);
|
||||
}
|
||||
)->assert('databox_id', '\d+');
|
||||
|
||||
$app->get('/databoxes/{any_id}/status/', $bad_request_exception);
|
||||
|
||||
/**
|
||||
* Route /databoxes/DATABOX_ID/metadatas/FORMAT/
|
||||
*
|
||||
* Method : GET
|
||||
*
|
||||
* Parameters ;
|
||||
* DATABOX_ID : required INT
|
||||
*/
|
||||
$route = '/databoxes/{databox_id}/metadatas/';
|
||||
$app->get(
|
||||
$route, function($databox_id) use ($app)
|
||||
{
|
||||
$result = $app['api']->get_databox_metadatas($app['request'], $databox_id);
|
||||
|
||||
return $app['response']($result);
|
||||
}
|
||||
)->assert('databox_id', '\d+');
|
||||
|
||||
$app->get('/databoxes/{any_id}/metadatas/', $bad_request_exception);
|
||||
|
||||
/**
|
||||
* Route /databoxes/DATABOX_ID/termsOfUse/FORMAT/
|
||||
*
|
||||
* Method : GET
|
||||
*
|
||||
* Parameters ;
|
||||
* DATABOX_ID : required INT
|
||||
*/
|
||||
$route = '/databoxes/{databox_id}/termsOfUse/';
|
||||
$app->get(
|
||||
$route, function($databox_id) use ($app)
|
||||
{
|
||||
$result = $app['api']->get_databox_terms($app['request'], $databox_id);
|
||||
|
||||
return $app['response']($result);
|
||||
}
|
||||
)->assert('databox_id', '\d+');
|
||||
|
||||
$app->get('/databoxes/{any_id}/termsOfUse/', $bad_request_exception);
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Route : /records/search/FORMAT/
|
||||
*
|
||||
* Method : GET or POST
|
||||
*
|
||||
* Parameters :
|
||||
* bases[] : array
|
||||
* status[] : array
|
||||
* fields[] : array
|
||||
* record_type : boolean
|
||||
* media_type : string
|
||||
*
|
||||
* Response :
|
||||
* Array of record objects
|
||||
*
|
||||
*/
|
||||
$route = '/records/search/';
|
||||
$app->post(
|
||||
$route, function() use ($app)
|
||||
{
|
||||
$result = $app['api']->search_records($app['request']);
|
||||
|
||||
return $app['response']($result);
|
||||
}
|
||||
);
|
||||
|
||||
|
||||
/**
|
||||
* Route : /records/DATABOX_ID/RECORD_ID/metadatas/FORMAT/
|
||||
*
|
||||
* Method : GET
|
||||
*
|
||||
* Parameters :
|
||||
* DATABOX_ID : required INT
|
||||
* RECORD_ID : required INT
|
||||
*
|
||||
*/
|
||||
$route = '/records/{databox_id}/{record_id}/metadatas/';
|
||||
$app->get(
|
||||
$route, function($databox_id, $record_id) use ($app)
|
||||
{
|
||||
$result = $app['api']->get_record_metadatas($app['request'], $databox_id, $record_id);
|
||||
|
||||
return $app['response']($result);
|
||||
}
|
||||
)->assert('databox_id', '\d+')->assert('record_id', '\d+');
|
||||
|
||||
$app->get('/records/{any_id}/{anyother_id}/metadatas/', $bad_request_exception);
|
||||
|
||||
/**
|
||||
* Route : /records/DATABOX_ID/RECORD_ID/status/FORMAT/
|
||||
*
|
||||
* Method : GET
|
||||
*
|
||||
* Parameters :
|
||||
* DATABOX_ID : required INT
|
||||
* RECORD_ID : required INT
|
||||
*
|
||||
*/
|
||||
$route = '/records/{databox_id}/{record_id}/status/';
|
||||
$app->get(
|
||||
$route, function($databox_id, $record_id) use ($app)
|
||||
{
|
||||
$result = $app['api']->get_record_status($app['request'], $databox_id, $record_id);
|
||||
|
||||
return $app['response']($result);
|
||||
}
|
||||
)->assert('databox_id', '\d+')->assert('record_id', '\d+');
|
||||
|
||||
$app->get('/records/{any_id}/{anyother_id}/status/', $bad_request_exception);
|
||||
|
||||
/**
|
||||
* Route : /records/DATABOX_ID/RECORD_ID/related/FORMAT/
|
||||
*
|
||||
* Method : GET
|
||||
*
|
||||
* Parameters :
|
||||
* DATABOX_ID : required INT
|
||||
* RECORD_ID : required INT
|
||||
*
|
||||
*/
|
||||
$route = '/records/{databox_id}/{record_id}/related/';
|
||||
$app->get(
|
||||
$route, function($databox_id, $record_id) use ($app)
|
||||
{
|
||||
$result = $app['api']->get_record_related($app['request'], $databox_id, $record_id);
|
||||
|
||||
return $app['response']($result);
|
||||
}
|
||||
)->assert('databox_id', '\d+')->assert('record_id', '\d+');
|
||||
|
||||
$app->get('/records/{any_id}/{anyother_id}/related/', $bad_request_exception);
|
||||
|
||||
/**
|
||||
* Route : /records/DATABOX_ID/RECORD_ID/embed/FORMAT/
|
||||
*
|
||||
* Method : GET
|
||||
*
|
||||
* Parameters :
|
||||
* DATABOX_ID : required INT
|
||||
* RECORD_ID : required INT
|
||||
*
|
||||
*/
|
||||
$route = '/records/{databox_id}/{record_id}/embed/';
|
||||
$app->get(
|
||||
$route, function($databox_id, $record_id) use ($app)
|
||||
{
|
||||
$result = $app['api']->get_record_embed($app['request'], $databox_id, $record_id);
|
||||
|
||||
return $app['response']($result);
|
||||
}
|
||||
)->assert('databox_id', '\d+')->assert('record_id', '\d+');
|
||||
|
||||
$app->get('/records/{any_id}/{anyother_id}/embed/', $bad_request_exception);
|
||||
|
||||
/**
|
||||
* Route : /records/DATABOX_ID/RECORD_ID/setmetadatas/FORMAT/
|
||||
*
|
||||
* Method : POST
|
||||
*
|
||||
* Parameters :
|
||||
* DATABOX_ID : required INT
|
||||
* RECORD_ID : required INT
|
||||
*
|
||||
*/
|
||||
$route = '/records/{databox_id}/{record_id}/setmetadatas/';
|
||||
$app->post(
|
||||
$route, function($databox_id, $record_id) use ($app)
|
||||
{
|
||||
$result = $app['api']->set_record_metadatas($app['request'], $databox_id, $record_id);
|
||||
|
||||
return $app['response']($result);
|
||||
}
|
||||
)->assert('databox_id', '\d+')->assert('record_id', '\d+');
|
||||
|
||||
$app->post('/records/{any_id}/{anyother_id}/setmetadatas/', $bad_request_exception);
|
||||
|
||||
/**
|
||||
* Route : /records/DATABOX_ID/RECORD_ID/setstatus/FORMAT/
|
||||
*
|
||||
* Method : POST
|
||||
*
|
||||
* Parameters :
|
||||
* DATABOX_ID : required INT
|
||||
* RECORD_ID : required INT
|
||||
*
|
||||
*/
|
||||
$route = '/records/{databox_id}/{record_id}/setstatus/';
|
||||
$app->post(
|
||||
$route, function($databox_id, $record_id) use ($app)
|
||||
{
|
||||
$result = $app['api']->set_record_status($app['request'], $databox_id, $record_id);
|
||||
|
||||
return $app['response']($result);
|
||||
}
|
||||
)->assert('databox_id', '\d+')->assert('record_id', '\d+');
|
||||
|
||||
$app->post('/records/{any_id}/{anyother_id}/setstatus/', $bad_request_exception);
|
||||
|
||||
|
||||
/**
|
||||
* Route : /records/DATABOX_ID/RECORD_ID/setcollection/FORMAT/
|
||||
*
|
||||
* Method : POST
|
||||
*
|
||||
* Parameters :
|
||||
* DATABOX_ID : required INT
|
||||
* RECORD_ID : required INT
|
||||
*
|
||||
*/
|
||||
$route = '/records/{databox_id}/{record_id}/setcollection/';
|
||||
$app->post(
|
||||
$route, function($databox_id, $record_id) use ($app)
|
||||
{
|
||||
$result = $app['api']->set_record_collection($app['request'], $databox_id, $record_id);
|
||||
|
||||
return $app['response']($result);
|
||||
}
|
||||
)->assert('databox_id', '\d+')->assert('record_id', '\d+');
|
||||
$app->post('/records/{wrong_databox_id}/{wrong_record_id}/setcollection/', $bad_request_exception);
|
||||
|
||||
|
||||
$route = '/records/{databox_id}/{record_id}/';
|
||||
$app->get($route, function($databox_id, $record_id) use ($app)
|
||||
{
|
||||
$result = $app['api']->get_record($app['request'], $databox_id, $record_id);
|
||||
|
||||
return $app['response']($result);
|
||||
})->assert('databox_id', '\d+')->assert('record_id', '\d+');
|
||||
$app->get('/records/{any_id}/{anyother_id}/', $bad_request_exception);
|
||||
|
||||
/**
|
||||
* Route : /baskets/list/FORMAT/
|
||||
*
|
||||
* Method : POST
|
||||
*
|
||||
* Parameters :
|
||||
*
|
||||
*/
|
||||
$route = '/baskets/list/';
|
||||
$app->get(
|
||||
$route, function() use ($app)
|
||||
{
|
||||
$result = $app['api']->search_baskets($app['request']);
|
||||
|
||||
return $app['response']($result);
|
||||
}
|
||||
);
|
||||
|
||||
|
||||
/**
|
||||
* Route : /baskets/add/FORMAT/
|
||||
*
|
||||
* Method : POST
|
||||
*
|
||||
* Parameters :
|
||||
*
|
||||
*/
|
||||
$route = '/baskets/add/';
|
||||
$app->post(
|
||||
$route, function() use ($app)
|
||||
{
|
||||
$result = $app['api']->create_basket($app['request']);
|
||||
|
||||
return $app['response']($result);
|
||||
}
|
||||
);
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Route : /baskets/BASKET_ID/content/FORMAT/
|
||||
*
|
||||
* Method : GET
|
||||
*
|
||||
* Parameters :
|
||||
* BASKET_ID : required INT
|
||||
*
|
||||
*/
|
||||
$route = '/baskets/{basket_id}/content/';
|
||||
$app->get(
|
||||
$route, function($basket_id) use ($app)
|
||||
{
|
||||
$result = $app['api']->get_basket($app['request'], $basket_id);
|
||||
|
||||
return $app['response']($result);
|
||||
}
|
||||
)->assert('basket_id', '\d+');
|
||||
$app->get('/baskets/{wrong_basket_id}/content/', $bad_request_exception);
|
||||
|
||||
|
||||
/**
|
||||
* Route : /baskets/BASKET_ID/settitle/FORMAT/
|
||||
*
|
||||
* Method : GET
|
||||
*
|
||||
* Parameters :
|
||||
* BASKET_ID : required INT
|
||||
*
|
||||
*/
|
||||
$route = '/baskets/{basket_id}/setname/';
|
||||
$app->post(
|
||||
$route, function($basket_id) use ($app)
|
||||
{
|
||||
$result = $app['api']->set_basket_title($app['request'], $basket_id);
|
||||
|
||||
return $app['response']($result);
|
||||
}
|
||||
)->assert('basket_id', '\d+');
|
||||
$app->post('/baskets/{wrong_basket_id}/setname/', $bad_request_exception);
|
||||
|
||||
|
||||
/**
|
||||
* Route : /baskets/BASKET_ID/setdescription/FORMAT/
|
||||
*
|
||||
* Method : POST
|
||||
*
|
||||
* Parameters :
|
||||
* BASKET_ID : required INT
|
||||
*
|
||||
*/
|
||||
$route = '/baskets/{basket_id}/setdescription/';
|
||||
$app->post(
|
||||
$route, function($basket_id) use ($app)
|
||||
{
|
||||
$result = $app['api']->set_basket_description($app['request'], $basket_id);
|
||||
|
||||
return $app['response']($result);
|
||||
}
|
||||
)->assert('basket_id', '\d+');
|
||||
$app->post('/baskets/{wrong_basket_id}/setdescription/', $bad_request_exception);
|
||||
|
||||
/**
|
||||
* Route : /baskets/BASKET_ID/delete/FORMAT/
|
||||
*
|
||||
* Method : POST
|
||||
*
|
||||
* Parameters :
|
||||
* BASKET_ID : required INT
|
||||
*
|
||||
*/
|
||||
$route = '/baskets/{basket_id}/delete/';
|
||||
$app->post(
|
||||
$route, function($basket_id) use ($app)
|
||||
{
|
||||
$result = $app['api']->delete_basket($app['request'], $basket_id);
|
||||
|
||||
return $app['response']($result);
|
||||
}
|
||||
)->assert('basket_id', '\d+');
|
||||
$app->post('/baskets/{wrong_basket_id}/delete/', $bad_request_exception);
|
||||
|
||||
|
||||
/**
|
||||
* Route : /feeds/list/FORMAT/
|
||||
*
|
||||
* Method : POST
|
||||
*
|
||||
* Parameters :
|
||||
*
|
||||
*/
|
||||
// public function search_publications(\Symfony\Component\HttpFoundation\Request $app['request']);
|
||||
|
||||
|
||||
$route = '/feeds/list/';
|
||||
$app->get(
|
||||
$route, function() use ($app)
|
||||
{
|
||||
$result = $app['api']->search_publications($app['request'], $app['p4user']);
|
||||
|
||||
return $app['response']($result);
|
||||
}
|
||||
);
|
||||
|
||||
/**
|
||||
* Route : /feeds/PUBLICATION_ID/content/FORMAT/
|
||||
*
|
||||
* Method : GET
|
||||
*
|
||||
* Parameters :
|
||||
* PUBLICATION_ID : required INT
|
||||
*
|
||||
*/
|
||||
// public function get_publication(\Symfony\Component\HttpFoundation\Request $app['request'], $publication_id);
|
||||
|
||||
$route = '/feeds/{feed_id}/content/';
|
||||
$app->get(
|
||||
$route, function($feed_id) use ($app)
|
||||
{
|
||||
$result = $app['api']->get_publication($app['request'], $feed_id, $app['p4user']);
|
||||
|
||||
return $app['response']($result);
|
||||
}
|
||||
)->assert('feed_id', '\d+');
|
||||
$app->get('/feeds/{wrong_feed_id}/content/', $bad_request_exception);
|
||||
|
||||
/**
|
||||
* *******************************************************************
|
||||
*
|
||||
* Route Errors
|
||||
*
|
||||
*/
|
||||
$app->error(function (\Exception $e) use ($app)
|
||||
{
|
||||
|
||||
if ($e instanceof API_V1_exception_methodnotallowed)
|
||||
$code = API_V1_result::ERROR_METHODNOTALLOWED;
|
||||
elseif ($e instanceof Exception\MethodNotAllowedHttpException)
|
||||
$code = API_V1_result::ERROR_METHODNOTALLOWED;
|
||||
elseif ($e instanceof API_V1_exception_badrequest)
|
||||
$code = API_V1_result::ERROR_BAD_REQUEST;
|
||||
elseif ($e instanceof API_V1_exception_forbidden)
|
||||
$code = API_V1_result::ERROR_FORBIDDEN;
|
||||
elseif ($e instanceof API_V1_exception_unauthorized)
|
||||
$code = API_V1_result::ERROR_UNAUTHORIZED;
|
||||
elseif ($e instanceof API_V1_exception_internalservererror)
|
||||
$code = API_V1_result::ERROR_INTERNALSERVERERROR;
|
||||
// elseif ($e instanceof API_V1_exception_notfound)
|
||||
// $code = API_V1_result::ERROR_NOTFOUND;
|
||||
elseif ($e instanceof Exception_NotFound)
|
||||
$code = API_V1_result::ERROR_NOTFOUND;
|
||||
elseif ($e instanceof Exception\NotFoundHttpException)
|
||||
$code = API_V1_result::ERROR_NOTFOUND;
|
||||
else
|
||||
$code = API_V1_result::ERROR_INTERNALSERVERERROR;
|
||||
|
||||
$result = $app['api']->get_error_message($app['request'], $code);
|
||||
|
||||
return $app['response']($result);
|
||||
});
|
||||
//// public function get_version();
|
||||
////
|
||||
////
|
||||
//// /**
|
||||
//// * Route : /records/DATABOX_ID/RECORD_ID/addtobasket/FORMAT/
|
||||
//// *
|
||||
//// * Method : POST
|
||||
//// *
|
||||
//// * Parameters :
|
||||
//// * DATABOX_ID : required INT
|
||||
//// * RECORD_ID : required INT
|
||||
//// *
|
||||
//// */
|
||||
//// public function add_record_tobasket(\Symfony\Component\HttpFoundation\Request $app['request'], $databox_id, $record_id);
|
||||
////
|
||||
////
|
||||
//// /**
|
||||
//// * Route : /feeds/PUBLICATION_ID/remove/FORMAT/
|
||||
//// *
|
||||
//// * Method : GET
|
||||
//// *
|
||||
//// * Parameters :
|
||||
//// * PUBLICATION_ID : required INT
|
||||
//// *
|
||||
//// */
|
||||
//// public function remove_publications(\Symfony\Component\HttpFoundation\Request $app['request'], $publication_id);
|
||||
////
|
||||
////
|
||||
//// /**
|
||||
//// * Route : /users/search/FORMAT/
|
||||
//// *
|
||||
//// * Method : POST-GET
|
||||
//// *
|
||||
//// * Parameters :
|
||||
//// *
|
||||
//// */
|
||||
//// public function search_users(\Symfony\Component\HttpFoundation\Request $app['request']);
|
||||
////
|
||||
//// /**
|
||||
//// * Route : /users/USER_ID/access/FORMAT/
|
||||
//// *
|
||||
//// * Method : GET
|
||||
//// *
|
||||
//// * Parameters :
|
||||
//// * USER_ID : required INT
|
||||
//// *
|
||||
//// */
|
||||
//// public function get_user_acces(\Symfony\Component\HttpFoundation\Request $app['request'], $usr_id);
|
||||
////
|
||||
//// /**
|
||||
//// * Route : /users/add/FORMAT/
|
||||
//// *
|
||||
//// * Method : POST
|
||||
//// *
|
||||
//// * Parameters :
|
||||
//// *
|
||||
//// */
|
||||
//// public function add_user(\Symfony\Component\HttpFoundation\Request $app['request']);
|
||||
return $app;
|
||||
|
||||
});
|
42
lib/classes/module/client.class.php
Normal file
42
lib/classes/module/client.class.php
Normal file
@@ -0,0 +1,42 @@
|
||||
<?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.
|
||||
*/
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @license http://opensource.org/licenses/gpl-3.0 GPLv3
|
||||
* @link www.phraseanet.com
|
||||
*/
|
||||
class module_client
|
||||
{
|
||||
|
||||
public function getLanguage($lng)
|
||||
{
|
||||
$registry = registry::get_instance();
|
||||
$out = array();
|
||||
$out['createWinInvite'] = _('paniers:: Quel nom souhaitez vous donner a votre panier ?');
|
||||
$out['chuNameEmpty'] = _('paniers:: Quel nom souhaitez vous donner a votre panier ?');
|
||||
$out['noDLok'] = _('export:: aucun document n\'est disponible au telechargement');
|
||||
$out['confirmRedirectAuth'] = _('invite:: Redirection vers la zone d\'authentification, cliquez sur OK pour continuer ou annulez');
|
||||
$out['serverName'] = $registry->get('GV_ServerName');
|
||||
$out['serverError'] = _('phraseanet::erreur: Une erreur est survenue, si ce probleme persiste, contactez le support technique');
|
||||
$out['serverTimeout'] = _('phraseanet::erreur: La connection au serveur Phraseanet semble etre indisponible');
|
||||
$out['serverDisconnected'] = _('phraseanet::erreur: Votre session est fermee, veuillez vous re-authentifier');
|
||||
$out['confirmDelBasket'] = _('paniers::Vous etes sur le point de supprimer ce panier. Cette action est irreversible. Souhaitez-vous continuer ?');
|
||||
$out['annuler'] = _('boutton::annuler');
|
||||
$out['fermer'] = _('boutton::fermer');
|
||||
$out['renewRss'] = _('boutton::renouveller');
|
||||
|
||||
return p4string::jsonencode($out);
|
||||
}
|
||||
|
||||
}
|
||||
|
45
lib/classes/module/console/aboutAuthors.class.php
Normal file
45
lib/classes/module/console/aboutAuthors.class.php
Normal file
@@ -0,0 +1,45 @@
|
||||
<?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.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @todo write tests
|
||||
*
|
||||
* @package
|
||||
* @license http://opensource.org/licenses/gpl-3.0 GPLv3
|
||||
* @link www.phraseanet.com
|
||||
*/
|
||||
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
|
||||
use Symfony\Component\Console\Input\InputArgument;
|
||||
use Symfony\Component\Console\Input\InputInterface;
|
||||
use Symfony\Component\Console\Input\InputOption;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
use Symfony\Component\Console\Command\Command;
|
||||
|
||||
class module_console_aboutAuthors extends Command
|
||||
{
|
||||
|
||||
public function __construct($name = null)
|
||||
{
|
||||
parent::__construct($name);
|
||||
|
||||
$this->setDescription('List authors and contributors');
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function execute(InputInterface $input, OutputInterface $output)
|
||||
{
|
||||
$output->writeln(file_get_contents(dirname(__FILE__) . '/../../../../AUTHORS'));
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
}
|
45
lib/classes/module/console/aboutLicense.class.php
Normal file
45
lib/classes/module/console/aboutLicense.class.php
Normal file
@@ -0,0 +1,45 @@
|
||||
<?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.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @todo write tests
|
||||
*
|
||||
* @package
|
||||
* @license http://opensource.org/licenses/gpl-3.0 GPLv3
|
||||
* @link www.phraseanet.com
|
||||
*/
|
||||
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
|
||||
use Symfony\Component\Console\Input\InputArgument;
|
||||
use Symfony\Component\Console\Input\InputInterface;
|
||||
use Symfony\Component\Console\Input\InputOption;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
use Symfony\Component\Console\Command\Command;
|
||||
|
||||
class module_console_aboutLicense extends Command
|
||||
{
|
||||
|
||||
public function __construct($name = null)
|
||||
{
|
||||
parent::__construct($name);
|
||||
|
||||
$this->setDescription('This program license');
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function execute(InputInterface $input, OutputInterface $output)
|
||||
{
|
||||
$output->writeln(file_get_contents(dirname(__FILE__) . '/../../../../LICENSE'));
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
}
|
56
lib/classes/module/console/schedulerStart.class.php
Normal file
56
lib/classes/module/console/schedulerStart.class.php
Normal file
@@ -0,0 +1,56 @@
|
||||
<?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 KonsoleKomander
|
||||
* @license http://opensource.org/licenses/gpl-3.0 GPLv3
|
||||
* @link www.phraseanet.com
|
||||
*/
|
||||
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
|
||||
use Symfony\Component\Console\Input\InputArgument;
|
||||
use Symfony\Component\Console\Input\InputInterface;
|
||||
use Symfony\Component\Console\Input\InputOption;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
use Symfony\Component\Console\Command\Command;
|
||||
|
||||
class module_console_schedulerStart extends Command
|
||||
{
|
||||
|
||||
public function __construct($name = null)
|
||||
{
|
||||
parent::__construct($name);
|
||||
|
||||
$this->setDescription('Start the scheduler');
|
||||
$this->setHelp(
|
||||
"You should use launch the command and finish it with `&`"
|
||||
. " to return to the console\n\n"
|
||||
. "\tie : <info>bin/console scheduler:start &</info>"
|
||||
);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function execute(InputInterface $input, OutputInterface $output)
|
||||
{
|
||||
if(!setup::is_installed())
|
||||
{
|
||||
throw new RuntimeException('Phraseanet is not set up');
|
||||
}
|
||||
|
||||
require_once dirname(__FILE__) . '/../../../../lib/bootstrap.php';
|
||||
|
||||
$scheduler = new task_Scheduler();
|
||||
$scheduler->run($output, true);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
}
|
62
lib/classes/module/console/schedulerState.class.php
Normal file
62
lib/classes/module/console/schedulerState.class.php
Normal file
@@ -0,0 +1,62 @@
|
||||
<?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 KonsoleKomander
|
||||
* @license http://opensource.org/licenses/gpl-3.0 GPLv3
|
||||
* @link www.phraseanet.com
|
||||
*/
|
||||
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
|
||||
use Symfony\Component\Console\Input\InputArgument;
|
||||
use Symfony\Component\Console\Input\InputInterface;
|
||||
use Symfony\Component\Console\Input\InputOption;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
use Symfony\Component\Console\Command\Command;
|
||||
|
||||
class module_console_schedulerState extends Command
|
||||
{
|
||||
public function __construct($name = null)
|
||||
{
|
||||
parent::__construct($name);
|
||||
|
||||
$this->setDescription('Get scheduler state');
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function execute(InputInterface $input, OutputInterface $output)
|
||||
{
|
||||
if(!setup::is_installed())
|
||||
{
|
||||
throw new RuntimeException('Phraseanet is not set up');
|
||||
}
|
||||
|
||||
require_once dirname(__FILE__) . '/../../../../lib/bootstrap.php';
|
||||
|
||||
$appbox = appbox::get_instance();
|
||||
$task_manager = new task_manager($appbox);
|
||||
|
||||
$state = $task_manager->get_scheduler_state();
|
||||
|
||||
if ($state['schedstatus'] == 'started')
|
||||
$output->writeln(sprintf(
|
||||
'Scheduler is %s on pid %d'
|
||||
, $state['schedstatus']
|
||||
, $state['schedpid']
|
||||
));
|
||||
else
|
||||
$output->writeln(sprintf('Scheduler is %s', $state['schedstatus']));
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
}
|
53
lib/classes/module/console/schedulerStop.class.php
Normal file
53
lib/classes/module/console/schedulerStop.class.php
Normal file
@@ -0,0 +1,53 @@
|
||||
<?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 KonsoleKomander
|
||||
* @license http://opensource.org/licenses/gpl-3.0 GPLv3
|
||||
* @link www.phraseanet.com
|
||||
*/
|
||||
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
|
||||
use Symfony\Component\Console\Input\InputArgument;
|
||||
use Symfony\Component\Console\Input\InputInterface;
|
||||
use Symfony\Component\Console\Input\InputOption;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
use Symfony\Component\Console\Command\Command;
|
||||
|
||||
class module_console_schedulerStop extends Command
|
||||
{
|
||||
|
||||
public function __construct($name = null)
|
||||
{
|
||||
parent::__construct($name);
|
||||
|
||||
$this->setDescription('Stop the scheduler');
|
||||
|
||||
return $this;
|
||||
}
|
||||
public function execute(InputInterface $input, OutputInterface $output)
|
||||
{
|
||||
if(!setup::is_installed())
|
||||
{
|
||||
throw new RuntimeException('Phraseanet is not set up');
|
||||
}
|
||||
|
||||
require_once dirname(__FILE__) . '/../../../../lib/bootstrap.php';
|
||||
|
||||
$appbox = appbox::get_instance();
|
||||
$task_manager = new task_manager($appbox);
|
||||
|
||||
$task_manager->set_sched_status(task_manager::STATUS_SCHED_TOSTOP);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
}
|
101
lib/classes/module/console/systemBackupDB.class.php
Normal file
101
lib/classes/module/console/systemBackupDB.class.php
Normal file
@@ -0,0 +1,101 @@
|
||||
<?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 KonsoleKomander
|
||||
* @license http://opensource.org/licenses/gpl-3.0 GPLv3
|
||||
* @link www.phraseanet.com
|
||||
*/
|
||||
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
|
||||
use Symfony\Component\Console\Input\InputArgument;
|
||||
use Symfony\Component\Console\Input\InputInterface;
|
||||
use Symfony\Component\Console\Input\InputOption;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
use Symfony\Component\Console\Command\Command;
|
||||
|
||||
class module_console_systemBackupDB extends Command
|
||||
{
|
||||
|
||||
public function __construct($name = null)
|
||||
{
|
||||
parent::__construct($name);
|
||||
|
||||
$dir = sprintf(
|
||||
'%s/config/'
|
||||
, dirname(dirname(dirname(dirname(dirname(__FILE__)))))
|
||||
);
|
||||
|
||||
$this->setDescription('Backup Phraseanet Databases');
|
||||
|
||||
$this->addArgument('directory', null, 'The directory where to backup', $dir);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function execute(InputInterface $input, OutputInterface $output)
|
||||
{
|
||||
if (!setup::is_installed())
|
||||
{
|
||||
throw new RuntimeException('Phraseanet is not set up');
|
||||
}
|
||||
|
||||
require_once dirname(__FILE__) . '/../../../../lib/bootstrap.php';
|
||||
|
||||
$output->write('Phraseanet is going to be backup...', true);
|
||||
|
||||
$appbox = appbox::get_instance();
|
||||
|
||||
$this->dump_base($appbox, $input, $output);
|
||||
|
||||
foreach ($appbox->get_databoxes() as $databox)
|
||||
{
|
||||
$this->dump_base($databox, $input, $output);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
protected function dump_base(base $base, InputInterface $input, OutputInterface $output)
|
||||
{
|
||||
$date_obj = new DateTime();
|
||||
|
||||
$filename = sprintf(
|
||||
'%s%s_%s.sql'
|
||||
, p4string::addEndSlash($input->getArgument('directory'))
|
||||
, $base->get_dbname()
|
||||
, $date_obj->format('Y_m_d_H_i_s')
|
||||
);
|
||||
|
||||
$output->write(sprintf('Generating %s ... ', $filename));
|
||||
|
||||
$command = sprintf(
|
||||
'mysqldump --host %s --port %s --user %s --password=%s'
|
||||
. ' --database %s --default-character-set=utf8 > %s'
|
||||
, $base->get_host()
|
||||
, $base->get_port()
|
||||
, $base->get_user()
|
||||
, $base->get_passwd()
|
||||
, $base->get_dbname()
|
||||
, escapeshellarg($filename)
|
||||
);
|
||||
|
||||
system($command);
|
||||
|
||||
if (file_exists($filename) && filesize($filename) > 0)
|
||||
$output->writeln('OK');
|
||||
else
|
||||
$output->writeln('<error>Failed</error>');
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
}
|
99
lib/classes/module/console/systemClearCache.class.php
Normal file
99
lib/classes/module/console/systemClearCache.class.php
Normal file
@@ -0,0 +1,99 @@
|
||||
<?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\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
|
||||
use Symfony\Component\Finder\Finder;
|
||||
use Symfony\Component\Console\Input\InputArgument;
|
||||
use Symfony\Component\Console\Input\InputInterface;
|
||||
use Symfony\Component\Console\Input\InputOption;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
use Symfony\Component\Console\Command\Command;
|
||||
|
||||
class module_console_systemClearCache extends Command
|
||||
{
|
||||
|
||||
public function __construct($name = null)
|
||||
{
|
||||
parent::__construct($name);
|
||||
|
||||
$this->setDescription('Empty cache directories, clear Memcached, Redis if avalaible');
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function execute(InputInterface $input, OutputInterface $output)
|
||||
{
|
||||
$files = $dirs = array();
|
||||
$finder = new Finder();
|
||||
$finder
|
||||
->files()
|
||||
->exclude('.git')
|
||||
->exclude('.svn')
|
||||
->in(array(
|
||||
dirname(__FILE__) . '/../../../../tmp/cache_minify/'
|
||||
, dirname(__FILE__) . '/../../../../tmp/cache_twig/'
|
||||
))
|
||||
;
|
||||
$count = 1;
|
||||
foreach ($finder as $file)
|
||||
{
|
||||
$files[$file->getPathname()] = $file->getPathname();
|
||||
$count++;
|
||||
}
|
||||
|
||||
$finder = new Finder();
|
||||
$finder
|
||||
->directories()
|
||||
->in(array(
|
||||
dirname(__FILE__) . '/../../../../tmp/cache_minify'
|
||||
, dirname(__FILE__) . '/../../../../tmp/cache_twig'
|
||||
))
|
||||
->exclude('.git')
|
||||
->exclude('.svn')
|
||||
;
|
||||
foreach ($finder as $file)
|
||||
{
|
||||
$dirs[$file->getPathname()] = $file->getPathname();
|
||||
printf('%4d) %s' . PHP_EOL, $count, $file->getPathname());
|
||||
$count++;
|
||||
}
|
||||
|
||||
foreach ($files as $file)
|
||||
{
|
||||
unlink($file);
|
||||
}
|
||||
foreach ($dirs as $dir)
|
||||
{
|
||||
rmdir($dir);
|
||||
}
|
||||
|
||||
if(setup::is_installed())
|
||||
{
|
||||
$registry = registry::get_instance();
|
||||
$cache = cache_adapter::get_instance($registry);
|
||||
if($cache->ping())
|
||||
{
|
||||
$cache->flush();
|
||||
}
|
||||
}
|
||||
|
||||
$output->write('Finished !', true);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
}
|
108
lib/classes/module/console/systemConfigCheck.class.php
Normal file
108
lib/classes/module/console/systemConfigCheck.class.php
Normal file
@@ -0,0 +1,108 @@
|
||||
<?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.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @todo write tests
|
||||
*
|
||||
* @package KonsoleKomander
|
||||
* @license http://opensource.org/licenses/gpl-3.0 GPLv3
|
||||
* @link www.phraseanet.com
|
||||
*/
|
||||
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
|
||||
use Symfony\Component\Console\Input\InputArgument;
|
||||
use Symfony\Component\Console\Input\InputInterface;
|
||||
use Symfony\Component\Console\Input\InputOption;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
use Symfony\Component\Console\Command\Command;
|
||||
|
||||
class module_console_systemConfigCheck extends Command
|
||||
{
|
||||
|
||||
public function __construct($name = null)
|
||||
{
|
||||
parent::__construct($name);
|
||||
|
||||
$this->setDescription('Check the configuration');
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function execute(InputInterface $input, OutputInterface $output)
|
||||
{
|
||||
if (!function_exists('_'))
|
||||
{
|
||||
$output->writeln('<error>YOU MUST ENABLE GETTEXT SUPPORT TO USE PHRASEANET</error>');
|
||||
$output->writeln('Canceled');
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (setup::is_installed())
|
||||
{
|
||||
$registry = registry::get_instance();
|
||||
|
||||
$output->writeln(_('*** CHECK BINARY CONFIGURATION ***'));
|
||||
$this->processConstraints(setup::check_binaries($registry), $output);
|
||||
$output->writeln("");
|
||||
}
|
||||
else
|
||||
{
|
||||
$registry = new Setup_Registry();
|
||||
}
|
||||
|
||||
$output->writeln(_('*** FILESYSTEM CONFIGURATION ***'));
|
||||
$this->processConstraints(setup::check_writability($registry), $output);
|
||||
$output->writeln("");
|
||||
$output->writeln(_('*** CHECK CACHE OPCODE ***'));
|
||||
$this->processConstraints(setup::check_cache_opcode(), $output);
|
||||
$output->writeln("");
|
||||
$output->writeln(_('*** CHECK CACHE SERVER ***'));
|
||||
$this->processConstraints(setup::check_cache_server(), $output);
|
||||
$output->writeln("");
|
||||
$output->writeln(_('*** CHECK PHP CONFIGURATION ***'));
|
||||
$this->processConstraints(setup::check_php_configuration(), $output);
|
||||
$output->writeln("");
|
||||
$output->writeln(_('*** CHECK PHP EXTENSIONS ***'));
|
||||
$this->processConstraints(setup::check_php_extension(), $output);
|
||||
$output->writeln("");
|
||||
$output->writeln(_('*** CHECK PHRASEA ***'));
|
||||
$this->processConstraints(setup::check_phrasea(), $output);
|
||||
$output->writeln("");
|
||||
$output->writeln(_('*** CHECK SYSTEM LOCALES ***'));
|
||||
$this->processConstraints(setup::check_system_locales(), $output);
|
||||
$output->writeln("");
|
||||
|
||||
$output->write('Finished !', true);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
protected function processConstraints(Setup_ConstraintsIterator $constraints, OutputInterface &$output)
|
||||
{
|
||||
foreach ($constraints as $constraint)
|
||||
{
|
||||
$this->processConstraint($constraint, $output);
|
||||
}
|
||||
}
|
||||
|
||||
protected function processConstraint(Setup_Constraint $constraint, OutputInterface &$output)
|
||||
{
|
||||
if ($constraint->is_ok())
|
||||
$output->writeln("\t\t<info>" . $constraint->get_message() . '</info>');
|
||||
elseif ($constraint->is_blocker())
|
||||
$output->writeln("\t!!!\t<error>" . $constraint->get_message() . '</error>');
|
||||
else
|
||||
$output->writeln("\t/!\\\t<comment>" . $constraint->get_message() . '</comment>');
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
}
|
124
lib/classes/module/console/systemTemplateGenerator.class.php
Normal file
124
lib/classes/module/console/systemTemplateGenerator.class.php
Normal file
@@ -0,0 +1,124 @@
|
||||
<?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 KonsoleKomander
|
||||
* @license http://opensource.org/licenses/gpl-3.0 GPLv3
|
||||
* @link www.phraseanet.com
|
||||
*/
|
||||
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
|
||||
use Symfony\Component\Console\Input\InputArgument;
|
||||
use Symfony\Component\Console\Input\InputInterface;
|
||||
use Symfony\Component\Console\Input\InputOption;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
use Symfony\Component\Console\Command\Command;
|
||||
|
||||
class module_console_systemTemplateGenerator extends Command
|
||||
{
|
||||
|
||||
public function __construct($name = null)
|
||||
{
|
||||
parent::__construct($name);
|
||||
|
||||
$this->setDescription('Generate template files');
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function execute(InputInterface $input, OutputInterface $output)
|
||||
{
|
||||
require_once dirname(__FILE__) . '/../../../../lib/vendor/Twig/lib/Twig/Autoloader.php';
|
||||
require_once dirname(__FILE__) . '/../../../../lib/vendor/Twig-extensions/lib/Twig/Extensions/Autoloader.php';
|
||||
|
||||
|
||||
Twig_Autoloader::register();
|
||||
Twig_Extensions_Autoloader::register();
|
||||
|
||||
|
||||
$tplDir = dirname(__FILE__) . '/../../../../templates/';
|
||||
$tmpDir = dirname(__FILE__) . '/../../../../tmp/cache_twig/';
|
||||
$loader = new Twig_Loader_Filesystem($tplDir);
|
||||
|
||||
$twig = new Twig_Environment($loader, array(
|
||||
'cache' => $tmpDir,
|
||||
'auto_reload' => true
|
||||
));
|
||||
$twig->addExtension(new Twig_Extensions_Extension_I18n());
|
||||
|
||||
|
||||
$twig->addFilter('serialize', new Twig_Filter_Function('serialize'));
|
||||
$twig->addFilter('sbas_names', new Twig_Filter_Function('phrasea::sbas_names'));
|
||||
$twig->addFilter('sbas_name', new Twig_Filter_Function('phrasea::sbas_names'));
|
||||
$twig->addFilter('unite', new Twig_Filter_Function('p4string::format_octets'));
|
||||
$twig->addFilter('stristr', new Twig_Filter_Function('stristr'));
|
||||
$twig->addFilter('implode', new Twig_Filter_Function('implode'));
|
||||
$twig->addFilter('stripdoublequotes', new Twig_Filter_Function('stripdoublequotes'));
|
||||
$twig->addFilter('phraseadate', new Twig_Filter_Function('phraseadate::getPrettyString'));
|
||||
$twig->addFilter('format_octets', new Twig_Filter_Function('p4string::format_octets'));
|
||||
$twig->addFilter('geoname_display', new Twig_Filter_Function('geonames::name_from_id'));
|
||||
$twig->addFilter('get_collection_logo', new Twig_Filter_Function('collection::getLogo'));
|
||||
$twig->addFilter('nl2br', new Twig_Filter_Function('nl2br'));
|
||||
$twig->addFilter('floor', new Twig_Filter_Function('floor'));
|
||||
$twig->addFilter('bas_name', new Twig_Filter_Function('phrasea::bas_names'));
|
||||
$twig->addFilter('bas_names', new Twig_Filter_Function('phrasea::bas_names'));
|
||||
$twig->addFilter('basnames', new Twig_Filter_Function('phrasea::bas_names'));
|
||||
$twig->addFilter('urlencode', new Twig_Filter_Function('urlencode'));
|
||||
$twig->addFilter('sbasFromBas', new Twig_Filter_Function('phrasea::sbasFromBas'));
|
||||
$twig->addFilter('str_replace', new Twig_Filter_Function('str_replace'));
|
||||
$twig->addFilter('strval', new Twig_Filter_Function('strval'));
|
||||
$twig->addFilter('key_exists', new Twig_Filter_Function('array_key_exists'));
|
||||
$twig->addFilter('array_keys', new Twig_Filter_Function('array_keys'));
|
||||
$twig->addFilter('round', new Twig_Filter_Function('round'));
|
||||
$twig->addFilter('formatdate', new Twig_Filter_Function('phraseadate::getDate'));
|
||||
$twig->addFilter('getPrettyDate', new Twig_Filter_Function('phraseadate::getPrettyString'));
|
||||
$twig->addFilter('prettyDate', new Twig_Filter_Function('phraseadate::getPrettyString'));
|
||||
$twig->addFilter('formatoctet', new Twig_Filter_Function('p4string::format_octet'));
|
||||
$twig->addFilter('getDate', new Twig_Filter_Function('phraseadate::getDate'));
|
||||
$twig->addFilter('geoname_name_from_id', new Twig_Filter_Function('geonames::name_from_id'));
|
||||
|
||||
|
||||
$n_ok = $n_error = 0;
|
||||
|
||||
foreach (new RecursiveIteratorIterator(new RecursiveDirectoryIterator($tplDir), RecursiveIteratorIterator::LEAVES_ONLY) as $file)
|
||||
{
|
||||
if (strpos($file, '/.svn/') !== false)
|
||||
continue;
|
||||
if (substr($file->getFilename(), 0, 1) === '.')
|
||||
continue;
|
||||
|
||||
try
|
||||
{
|
||||
$twig->loadTemplate(str_replace($tplDir, '', $file));
|
||||
$output->writeln('' . $file . '');
|
||||
$n_ok++;
|
||||
}
|
||||
catch (Exception $e)
|
||||
{
|
||||
$output->writeln('<error>' . $e->getMessage() . '</error>');
|
||||
$n_error++;
|
||||
}
|
||||
}
|
||||
|
||||
$output->writeln("");
|
||||
$output->write(sprintf('%d templates generated. ', $n_ok));
|
||||
|
||||
if ($n_error > 0)
|
||||
{
|
||||
$output->write(sprintf('<error>%d templates failed.</error>', $n_error));
|
||||
}
|
||||
|
||||
$output->writeln("");
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
}
|
79
lib/classes/module/console/systemUpgrade.class.php
Normal file
79
lib/classes/module/console/systemUpgrade.class.php
Normal file
@@ -0,0 +1,79 @@
|
||||
<?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.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @todo write tests
|
||||
*
|
||||
* @package KonsoleKomander
|
||||
* @license http://opensource.org/licenses/gpl-3.0 GPLv3
|
||||
* @link www.phraseanet.com
|
||||
*/
|
||||
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
|
||||
use Symfony\Component\Console\Input\InputArgument;
|
||||
use Symfony\Component\Console\Input\InputInterface;
|
||||
use Symfony\Component\Console\Input\InputOption;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
use Symfony\Component\Console\Command\Command;
|
||||
|
||||
class module_console_systemUpgrade extends Command
|
||||
{
|
||||
|
||||
public function __construct($name = null)
|
||||
{
|
||||
parent::__construct($name);
|
||||
|
||||
$this->setDescription('Upgrade Phraseanet to the lastest version');
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function execute(InputInterface $input, OutputInterface $output)
|
||||
{
|
||||
if(!setup::is_installed())
|
||||
{
|
||||
throw new RuntimeException('Phraseanet is not set up');
|
||||
}
|
||||
|
||||
require_once dirname(__FILE__) . '/../../../../lib/bootstrap.php';
|
||||
|
||||
$output->write('Phraseanet is going to be upgraded', true);
|
||||
$dialog = $this->getHelperSet()->get('dialog');
|
||||
|
||||
do
|
||||
{
|
||||
$continue = mb_strtolower($dialog->ask($output, '<question>' . _('Continuer ?') . ' (Y/n)</question>', 'Y'));
|
||||
}
|
||||
while (!in_array($continue, array('y', 'n')));
|
||||
|
||||
|
||||
if ($continue == 'y')
|
||||
{
|
||||
try
|
||||
{
|
||||
$output->write('<info>Upgrading...</info>', true);
|
||||
$appbox = appbox::get_instance();
|
||||
$upgrader = new Setup_Upgrade($appbox);
|
||||
$advices = $appbox->forceUpgrade($upgrader);
|
||||
}
|
||||
catch (Exception $e)
|
||||
{
|
||||
$output->writeln(sprintf('<error>An error occured while upgrading : %s </error>', $e->getMessage()));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$output->write('<info>Canceled</info>', true);
|
||||
}
|
||||
$output->write('Finished !', true);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
}
|
70
lib/classes/module/console/tasklist.class.php
Normal file
70
lib/classes/module/console/tasklist.class.php
Normal file
@@ -0,0 +1,70 @@
|
||||
<?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.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @todo write tests
|
||||
*
|
||||
* @package KonsoleKomander
|
||||
* @license http://opensource.org/licenses/gpl-3.0 GPLv3
|
||||
* @link www.phraseanet.com
|
||||
*/
|
||||
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
|
||||
use Symfony\Component\Console\Input\InputArgument;
|
||||
use Symfony\Component\Console\Input\InputInterface;
|
||||
use Symfony\Component\Console\Input\InputOption;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
use Symfony\Component\Console\Command\Command;
|
||||
|
||||
class module_console_tasklist extends Command
|
||||
{
|
||||
|
||||
public function __construct($name = null)
|
||||
{
|
||||
parent::__construct($name);
|
||||
|
||||
$this->setDescription('List tasks');
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function execute(InputInterface $input, OutputInterface $output)
|
||||
{
|
||||
if(!setup::is_installed())
|
||||
{
|
||||
throw new RuntimeException('Phraseanet is not set up');
|
||||
}
|
||||
|
||||
require_once dirname(__FILE__) . '/../../../../lib/bootstrap.php';
|
||||
|
||||
$appbox = appbox::get_instance();
|
||||
$task_manager = new task_manager($appbox);
|
||||
$tasks = $task_manager->get_tasks();
|
||||
|
||||
if(count($tasks) === 0)
|
||||
$output->writeln ('No tasks on your install !');
|
||||
|
||||
foreach($tasks as $task)
|
||||
{
|
||||
$this->print_task($task, $output);
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
||||
protected function print_task(task_abstract $task, OutputInterface &$output)
|
||||
{
|
||||
$message = $task->get_task_id()."\t".($task->get_status() )."\t".$task->get_title();
|
||||
$output->writeln($message);
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
74
lib/classes/module/console/taskrun.class.php
Normal file
74
lib/classes/module/console/taskrun.class.php
Normal file
@@ -0,0 +1,74 @@
|
||||
<?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.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @todo write tests
|
||||
*
|
||||
* @package KonsoleKomander
|
||||
* @license http://opensource.org/licenses/gpl-3.0 GPLv3
|
||||
* @link www.phraseanet.com
|
||||
*/
|
||||
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
|
||||
use Symfony\Component\Console\Input\InputArgument;
|
||||
use Symfony\Component\Console\Input\InputInterface;
|
||||
use Symfony\Component\Console\Input\InputOption;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
use Symfony\Component\Console\Command\Command;
|
||||
|
||||
class module_console_taskrun extends Command
|
||||
{
|
||||
|
||||
public function __construct($name = null)
|
||||
{
|
||||
parent::__construct($name);
|
||||
|
||||
$this->addArgument('task_id', InputArgument::REQUIRED, 'The task_id to run');
|
||||
$this->addOption(
|
||||
'runner'
|
||||
, 'r'
|
||||
, InputOption::VALUE_REQUIRED
|
||||
, 'The name of the runner (manual, scheduler...)'
|
||||
, task_abstract::RUNNER_MANUAL
|
||||
);
|
||||
$this->setDescription('Run task');
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function execute(InputInterface $input, OutputInterface $output)
|
||||
{
|
||||
if(!setup::is_installed())
|
||||
{
|
||||
throw new RuntimeException('Phraseanet is not set up');
|
||||
}
|
||||
|
||||
require_once dirname(__FILE__) . '/../../../../lib/bootstrap.php';
|
||||
|
||||
$task_id = (int) $input->getArgument('task_id');
|
||||
|
||||
if ($task_id <= 0 || strlen($task_id) !== strlen($input->getArgument('task_id')))
|
||||
throw new \RuntimeException('Argument must be an Id.');
|
||||
|
||||
$appbox = appbox::get_instance();
|
||||
$task_manager = new task_manager($appbox);
|
||||
$task = $task_manager->get_task($task_id);
|
||||
|
||||
$runner = task_abstract::RUNNER_SCHEDULER;
|
||||
if ($input->getOption('runner') === task_abstract::RUNNER_MANUAL)
|
||||
$runner = task_abstract::RUNNER_MANUAL;
|
||||
|
||||
$task->run($runner);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
||||
}
|
165
lib/classes/module/prod.class.php
Normal file
165
lib/classes/module/prod.class.php
Normal file
@@ -0,0 +1,165 @@
|
||||
<?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 module_prod
|
||||
{
|
||||
|
||||
public function get_random()
|
||||
{
|
||||
return md5(time() . mt_rand(100000, 999999));
|
||||
}
|
||||
|
||||
public function get_search_datas()
|
||||
{
|
||||
$search_datas = array(
|
||||
'bases' => array(),
|
||||
'dates' => array(),
|
||||
'fields' => array()
|
||||
);
|
||||
|
||||
$bases = $fields = $dates = array();
|
||||
$appbox = appbox::get_instance();
|
||||
$session = $appbox->get_session();
|
||||
$user = User_Adapter::getInstance($session->get_usr_id(), $appbox);
|
||||
$searchSet = $user->getPrefs('search');
|
||||
|
||||
foreach ($user->ACL()->get_granted_sbas() as $databox)
|
||||
{
|
||||
$sbas_id = $databox->get_sbas_id();
|
||||
|
||||
$bases[$sbas_id] = array(
|
||||
'thesaurus' => (trim($databox->get_thesaurus()) != ""),
|
||||
'cterms' => false,
|
||||
'collections' => array(),
|
||||
'sbas_id' => $sbas_id
|
||||
);
|
||||
|
||||
foreach($user->ACL()->get_granted_base(array(), array($databox->get_sbas_id())) as $coll)
|
||||
{
|
||||
$selected = ($searchSet &&
|
||||
isset($searchSet->bases) &&
|
||||
isset($searchSet->bases->$sbas_id)) ? (in_array($coll->get_base_id(), $searchSet->bases->$sbas_id)) : true;
|
||||
$bases[$sbas_id]['collections'][] =
|
||||
array(
|
||||
'selected' => $selected,
|
||||
'base_id' => $coll->get_base_id()
|
||||
);
|
||||
}
|
||||
|
||||
$meta_struct = $databox->get_meta_structure();
|
||||
foreach ($meta_struct as $meta)
|
||||
{
|
||||
if (!$meta->is_indexable())
|
||||
continue;
|
||||
$id = $meta->get_id();
|
||||
$name = $meta->get_name();
|
||||
if ($meta->get_type() == 'date')
|
||||
{
|
||||
if (isset($dates[$id]))
|
||||
$dates[$id]['sbas'][] = $sbas_id;
|
||||
else
|
||||
$dates[$id] = array('sbas' => array($sbas_id), 'fieldname' => $name);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (isset($fields[$name]))
|
||||
$fields[$name]['sbas'][] = $sbas_id;
|
||||
else
|
||||
$fields[$name] = array('sbas' => array($sbas_id), 'fieldname' => $name, 'id' => $id);
|
||||
}
|
||||
}
|
||||
|
||||
if (!$bases[$sbas_id]['thesaurus'])
|
||||
continue;
|
||||
if (!$user->ACL()->has_right_on_sbas($sbas_id, 'bas_modif_th'))
|
||||
continue;
|
||||
|
||||
if (simplexml_load_string($databox->get_cterms()))
|
||||
{
|
||||
$bases[$sbas_id]['cterms'] = true;
|
||||
}
|
||||
}
|
||||
|
||||
$search_datas['fields'] = $fields;
|
||||
$search_datas['dates'] = $dates;
|
||||
$search_datas['bases'] = $bases;
|
||||
|
||||
return $search_datas;
|
||||
}
|
||||
|
||||
function getLanguage($lng = false)
|
||||
{
|
||||
$appbox = appbox::get_instance();
|
||||
$session = $appbox->get_session();
|
||||
$lng = $lng ? $lng : Session_Handler::get_locale();
|
||||
$registry = $appbox->get_registry();
|
||||
|
||||
$out = array();
|
||||
$out['thesaurusBasesChanged'] = _('prod::recherche: Attention : la liste des bases selectionnees pour la recherche a ete changee.');
|
||||
$out['confirmDel'] = _('paniers::Vous etes sur le point de supprimer ce panier. Cette action est irreversible. Souhaitez-vous continuer ?');
|
||||
$out['serverError'] = _('phraseanet::erreur: Une erreur est survenue, si ce probleme persiste, contactez le support technique');
|
||||
$out['serverName'] = $registry->get('GV_ServerName');
|
||||
$out['serverTimeout'] = _('phraseanet::erreur: La connection au serveur Phraseanet semble etre indisponible');
|
||||
$out['serverDisconnected'] = _('phraseanet::erreur: Votre session est fermee, veuillez vous re-authentifier');
|
||||
$out['hideMessage'] = _('phraseanet::Ne plus afficher ce message');
|
||||
$out['confirmGroup'] = _('Supprimer egalement les documents rattaches a ces regroupements');
|
||||
$out['confirmDelete'] = _('reponses:: Ces enregistrements vont etre definitivement supprimes et ne pourront etre recuperes. Etes vous sur ?');
|
||||
$out['cancel'] = _('boutton::annuler');
|
||||
$out['deleteTitle'] = _('boutton::supprimer');
|
||||
$out['edit_hetero'] = _('prod::editing valeurs heterogenes, choisir \'remplacer\', \'ajouter\' ou \'annuler\'');
|
||||
$out['confirm_abandon'] = _('prod::editing::annulation: abandonner les modification ?');
|
||||
$out['loading'] = _('phraseanet::chargement');
|
||||
$out['valider'] = _('boutton::valider');
|
||||
$out['annuler'] = _('boutton::annuler');
|
||||
$out['rechercher'] = _('boutton::rechercher');
|
||||
$out['renewRss'] = _('boutton::renouveller');
|
||||
$out['candeletesome'] = _('Vous n\'avez pas les droits pour supprimer certains documents');
|
||||
$out['candeletedocuments'] = _('Vous n\'avez pas les droits pour supprimer ces documents');
|
||||
$out['needTitle'] = _('Vous devez donner un titre');
|
||||
$out['newPreset'] = _('Nouveau modele');
|
||||
$out['fermer'] = _('boutton::fermer');
|
||||
$out['feed_require_fields'] = _('Vous n\'avez pas rempli tous les champ requis');
|
||||
$out['feed_require_feed'] = _('Vous n\'avez pas selectionne de fil de publication');
|
||||
$out['removeTitle'] = _('panier::Supression d\'un element d\'un reportage');
|
||||
$out['confirmRemoveReg'] = _('panier::Attention, vous etes sur le point de supprimer un element du reportage. Merci de confirmer votre action.');
|
||||
$out['advsearch_title'] = _('phraseanet::recherche avancee');
|
||||
$out['bask_rename'] = _('panier:: renommer le panier');
|
||||
$out['reg_wrong_sbas'] = _('panier:: Un reportage ne peux recevoir que des elements provenants de la base ou il est enregistre');
|
||||
$out['error'] = _('phraseanet:: Erreur');
|
||||
$out['warningDenyCgus'] = _('cgus :: Attention, si vous refuser les CGUs de cette base, vous n\'y aures plus acces');
|
||||
$out['cgusRelog'] = _('cgus :: Vous devez vous reauthentifier pour que vos parametres soient pris en compte.');
|
||||
$out['editDelMulti'] = _('edit:: Supprimer %s du champ dans les records selectionnes');
|
||||
$out['editAddMulti'] = _('edit:: Ajouter %s au champ courrant pour les records selectionnes');
|
||||
$out['editDelSimple'] = _('edit:: Supprimer %s du champ courrant');
|
||||
$out['editAddSimple'] = _('edit:: Ajouter %s au champ courrant');
|
||||
$out['cantDeletePublicOne'] = _('panier:: vous ne pouvez pas supprimer un panier public');
|
||||
$out['wrongsbas'] = _('panier:: Un reportage ne peux recevoir que des elements provenants de la base ou il est enregistre');
|
||||
$out['max_record_selected'] = _('Vous ne pouvez pas selectionner plus de 400 enregistrements');
|
||||
$out['confirmRedirectAuth'] = _('invite:: Redirection vers la zone d\'authentification, cliquez sur OK pour continuer ou annulez');
|
||||
$out['error_test_publi'] = _('Erreur : soit les parametres sont incorrects, soit le serveur distant ne repond pas');
|
||||
$out['test_publi_ok'] = _('Les parametres sont corrects, le serveur distant est operationnel');
|
||||
$out['some_not_published'] = _('Certaines publications n\'ont pu etre effectuees, verifiez vos parametres');
|
||||
$out['error_not_published'] = _('Aucune publication effectuee, verifiez vos parametres');
|
||||
$out['warning_delete_publi'] = _('Attention, en supprimant ce preregalge, vous ne pourrez plus modifier ou supprimer de publications prealablement effectues avec celui-ci');
|
||||
$out['some_required_fields'] = _('edit::certains documents possedent des champs requis non remplis. Merci de les remplir pour valider votre editing');
|
||||
$out['nodocselected'] = _('Aucun document selectionne');
|
||||
|
||||
return p4string::jsonencode($out);
|
||||
}
|
||||
|
||||
}
|
324
lib/classes/module/prod/route/records/abstract.class.php
Normal file
324
lib/classes/module/prod/route/records/abstract.class.php
Normal file
@@ -0,0 +1,324 @@
|
||||
<?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 module_prod_route_records_abstract
|
||||
{
|
||||
|
||||
/**
|
||||
*
|
||||
* @var set_selection
|
||||
*/
|
||||
protected $selection;
|
||||
|
||||
/**
|
||||
*
|
||||
* @var boolean
|
||||
*/
|
||||
protected $is_possible;
|
||||
|
||||
/**
|
||||
*
|
||||
* @var Array
|
||||
*/
|
||||
protected $elements_received;
|
||||
|
||||
/**
|
||||
*
|
||||
* @var Array
|
||||
*/
|
||||
protected $single_grouping;
|
||||
|
||||
/**
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
protected $sbas_id;
|
||||
|
||||
/**
|
||||
*
|
||||
* @var boolean
|
||||
*/
|
||||
protected $has_many_sbas;
|
||||
|
||||
/**
|
||||
*
|
||||
* @var Array
|
||||
*/
|
||||
protected $required_rights = array();
|
||||
|
||||
/**
|
||||
*
|
||||
* @var Array
|
||||
*/
|
||||
protected $required_sbas_rights = array();
|
||||
|
||||
/**
|
||||
*
|
||||
* @var boolean
|
||||
*/
|
||||
protected $works_on_unique_sbas = false;
|
||||
|
||||
/**
|
||||
*
|
||||
* @var <type>
|
||||
*/
|
||||
protected $request;
|
||||
protected $flatten_groupings = false;
|
||||
|
||||
/**
|
||||
*
|
||||
* @var boolean
|
||||
*/
|
||||
protected $is_basket = false;
|
||||
|
||||
/**
|
||||
*
|
||||
* @var basket_adapter
|
||||
*/
|
||||
protected $original_basket;
|
||||
|
||||
/**
|
||||
*
|
||||
* @return action_move
|
||||
*/
|
||||
public function __construct(Symfony\Component\HttpFoundation\Request $request)
|
||||
{
|
||||
// $parm = $this->request->get_parms("lst", "ssel");
|
||||
|
||||
$this->request = $request;
|
||||
$this->selection = new set_selection();
|
||||
$appbox = appbox::get_instance();
|
||||
$usr_id = $appbox->get_session()->get_usr_id();
|
||||
|
||||
if (trim($request->get('ssel')) !== '')
|
||||
{
|
||||
$basket = basket_adapter::getInstance($appbox, $request->get('ssel'), $usr_id);
|
||||
|
||||
if ($basket->is_grouping() && $this->flatten_groupings === true)
|
||||
{
|
||||
foreach ($basket->get_elements() as $basket_element)
|
||||
{
|
||||
/* @var $basket_element basket_element_adapter */
|
||||
$this->selection->add_element($basket_element->get_record());
|
||||
}
|
||||
}
|
||||
elseif($basket->is_grouping())
|
||||
{
|
||||
$grouping = new record_adapter($basket->get_sbas_id(), $basket->get_record_id());
|
||||
$this->selection->add_element($grouping);
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->selection->load_basket($basket);
|
||||
$this->is_basket = true;
|
||||
}
|
||||
$this->original_basket = $basket;
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->selection->load_list(explode(";", $request->get('lst')), $this->flatten_groupings);
|
||||
}
|
||||
$this->elements_received = $this->selection->get_count();
|
||||
|
||||
$this->single_grouping = ($this->get_count_actionable() == 1 &&
|
||||
$this->get_count_actionable_groupings() == 1);
|
||||
|
||||
$this->examinate_selection();
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Tells if the original selection was a basket
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function is_basket()
|
||||
{
|
||||
return $this->is_basket;
|
||||
}
|
||||
|
||||
/**
|
||||
* If the original selection was a basket, returns the basket object
|
||||
*
|
||||
* @return basket_adapter
|
||||
*/
|
||||
public function get_original_basket()
|
||||
{
|
||||
return $this->original_basket;
|
||||
}
|
||||
|
||||
protected function examinate_selection()
|
||||
{
|
||||
$this->selection->grep_authorized($this->required_rights, $this->required_sbas_rights);
|
||||
|
||||
if ($this->works_on_unique_sbas === true)
|
||||
{
|
||||
$this->sbas_ids = $this->selection->get_distinct_sbas_ids();
|
||||
|
||||
$this->is_possible = count($this->sbas_ids) == 1;
|
||||
|
||||
$this->has_many_sbas = count($this->sbas_ids) > 1;
|
||||
|
||||
$this->sbas_id = $this->is_possible ? array_pop($this->sbas_ids) : false;
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Is action applies on single grouping
|
||||
*
|
||||
* @return <type>
|
||||
*/
|
||||
public function is_single_grouping()
|
||||
{
|
||||
return $this->single_grouping;
|
||||
}
|
||||
|
||||
/**
|
||||
* When action on a single grouping, returns the image of himself
|
||||
*
|
||||
* @return record_adapter
|
||||
*/
|
||||
public function get_grouping_head()
|
||||
{
|
||||
if (!$this->is_single_grouping())
|
||||
throw new Exception('Cannot use ' . __METHOD__ . ' here');
|
||||
foreach ($this->get_elements() as $record)
|
||||
|
||||
return $record;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get elements for the action
|
||||
*
|
||||
* @return Array
|
||||
*/
|
||||
public function get_elements()
|
||||
{
|
||||
return $this->selection->get_elements();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if elements comes from many sbas
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function has_many_sbas()
|
||||
{
|
||||
return $this->has_many_sbas;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if the action is possible with the current elements
|
||||
* for the user
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function is_possible()
|
||||
{
|
||||
return $this->is_possible;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the number of elements on which the action can not be done
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function get_count_not_actionable()
|
||||
{
|
||||
return $this->get_count_element_received() - $this->get_count_actionable();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the number of elements on which the action can be done
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function get_count_actionable()
|
||||
{
|
||||
return $this->selection->get_count();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the number of groupings on which the action can be done
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function get_count_actionable_groupings()
|
||||
{
|
||||
return $this->selection->get_count_groupings();
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the number of elements receveid when starting action
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function get_count_element_received()
|
||||
{
|
||||
return $this->elements_received;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return sbas_ids of the current selection
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function get_sbas_id()
|
||||
{
|
||||
return $this->sbas_id;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the selection as a serialized string base_id"_"record_id
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function get_serialize_list()
|
||||
{
|
||||
if ($this->is_single_grouping())
|
||||
|
||||
return $this->get_grouping_head()->get_serialize_key();
|
||||
else
|
||||
|
||||
return $this->selection->serialize_list();
|
||||
}
|
||||
|
||||
public function get_request()
|
||||
{
|
||||
return $this->request;
|
||||
}
|
||||
|
||||
public function set_request($request)
|
||||
{
|
||||
$this->request = $request;
|
||||
}
|
||||
|
||||
public function grep_records(Closure $closure)
|
||||
{
|
||||
foreach ($this->selection->get_elements() as $record)
|
||||
{
|
||||
if (!$closure($record))
|
||||
$this->selection->remove_element($record);
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
}
|
21
lib/classes/module/prod/route/records/bridge.class.php
Normal file
21
lib/classes/module/prod/route/records/bridge.class.php
Normal file
@@ -0,0 +1,21 @@
|
||||
<?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.
|
||||
*/
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @license http://opensource.org/licenses/gpl-3.0 GPLv3
|
||||
* @link www.phraseanet.com
|
||||
*/
|
||||
class module_prod_route_records_bridge extends module_prod_route_records_abstract
|
||||
{
|
||||
|
||||
}
|
607
lib/classes/module/prod/route/records/edit.class.php
Normal file
607
lib/classes/module/prod/route/records/edit.class.php
Normal file
@@ -0,0 +1,607 @@
|
||||
<?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 module_prod_route_records_edit extends module_prod_route_records_abstract
|
||||
{
|
||||
|
||||
/**
|
||||
*
|
||||
* @var Array
|
||||
*/
|
||||
protected $javascript_fields;
|
||||
|
||||
/**
|
||||
*
|
||||
* @var Array
|
||||
*/
|
||||
protected $fields;
|
||||
|
||||
/**
|
||||
*
|
||||
* @var Array
|
||||
*/
|
||||
protected $javascript_status;
|
||||
|
||||
/**
|
||||
*
|
||||
* @var Array
|
||||
*/
|
||||
protected $javascript_sugg_values;
|
||||
|
||||
/**
|
||||
*
|
||||
* @var Array
|
||||
*/
|
||||
protected $javascript_elements;
|
||||
|
||||
/**
|
||||
*
|
||||
* @var Array
|
||||
*/
|
||||
protected $required_rights = array('canmodifrecord');
|
||||
|
||||
/**
|
||||
*
|
||||
* @var boolean
|
||||
*/
|
||||
protected $works_on_unique_sbas = true;
|
||||
protected $has_thesaurus = false;
|
||||
|
||||
|
||||
|
||||
public function __construct(Symfony\Component\HttpFoundation\Request $request)
|
||||
{
|
||||
$appbox = appbox::get_instance();
|
||||
|
||||
parent::__construct($request);
|
||||
|
||||
|
||||
if ($this->is_single_grouping())
|
||||
{
|
||||
$record = array_pop($this->selection->get_elements());
|
||||
$children = $record->get_children();
|
||||
foreach ($children as $child)
|
||||
{
|
||||
$this->selection->add_element($child);
|
||||
}
|
||||
$n = count($children);
|
||||
$this->elements_received = $this->selection->get_count() + $n - 1;
|
||||
$this->examinate_selection();
|
||||
}
|
||||
if ($this->is_possible())
|
||||
{
|
||||
$this->generate_javascript_fields()
|
||||
->generate_javascript_sugg_values()
|
||||
->generate_javascript_status()
|
||||
->generate_javascript_elements();
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function propose_editing()
|
||||
{
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function has_thesaurus()
|
||||
{
|
||||
return $this->has_thesaurus;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return JSON data for UI
|
||||
*
|
||||
* @return String
|
||||
*/
|
||||
public function get_javascript_elements_ids()
|
||||
{
|
||||
return p4string::jsonencode(array_keys($this->javascript_elements));
|
||||
}
|
||||
|
||||
/**
|
||||
* Return JSON data for UI
|
||||
*
|
||||
* @return String
|
||||
*/
|
||||
public function get_javascript_elements()
|
||||
{
|
||||
return p4string::jsonencode($this->javascript_elements);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return JSON data for UI
|
||||
*
|
||||
* @return String
|
||||
*/
|
||||
public function get_javascript_sugg_values()
|
||||
{
|
||||
return p4string::jsonencode($this->javascript_sugg_values);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return JSON data for UI
|
||||
*
|
||||
* @return String
|
||||
*/
|
||||
public function get_javascript_status()
|
||||
{
|
||||
return p4string::jsonencode($this->javascript_status);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return JSON data for UI
|
||||
*
|
||||
* @return String
|
||||
*/
|
||||
public function get_javascript_fields()
|
||||
{
|
||||
return p4string::jsonencode(($this->javascript_fields));
|
||||
}
|
||||
|
||||
/**
|
||||
* Return statusbit informations on database
|
||||
*
|
||||
* @return Array
|
||||
*/
|
||||
public function get_status()
|
||||
{
|
||||
return $this->javascript_status;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return fields informations on database
|
||||
*
|
||||
* @return Array
|
||||
*/
|
||||
public function get_fields()
|
||||
{
|
||||
return $this->fields;
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate data for JSON UI
|
||||
*
|
||||
* @return action_edit
|
||||
*/
|
||||
protected function generate_javascript_elements()
|
||||
{
|
||||
$_lst = array();
|
||||
$appbox = appbox::get_instance();
|
||||
$session = $appbox->get_session();
|
||||
$user = User_Adapter::getInstance($session->get_usr_id(), $appbox);
|
||||
$twig = new supertwig();
|
||||
|
||||
foreach ($this->selection as $record)
|
||||
{
|
||||
$indice = $record->get_number();
|
||||
$_lst[$indice] = array(
|
||||
'bid' => $record->get_base_id(),
|
||||
'rid' => $record->get_record_id(),
|
||||
'sselcont_id' => null,
|
||||
'_selected' => false
|
||||
);
|
||||
|
||||
$_lst[$indice]['statbits'] = array();
|
||||
if ($user->ACL()->has_right_on_base($record->get_base_id(), 'chgstatus'))
|
||||
{
|
||||
foreach ($this->javascript_status as $n => $s)
|
||||
{
|
||||
$tmp_val = substr(strrev($record->get_status()), $n, 1);
|
||||
$_lst[$indice]['statbits'][$n]['value'] = ($tmp_val == '1') ? '1' : '0';
|
||||
$_lst[$indice]['statbits'][$n]['dirty'] = false;
|
||||
}
|
||||
}
|
||||
$_lst[$indice]['fields'] = array();
|
||||
$_lst[$indice]['originalname'] = '';
|
||||
|
||||
$_lst[$indice]['originalname'] = $record->get_original_name();
|
||||
|
||||
foreach ($record->get_caption()->get_fields() as $field)
|
||||
{
|
||||
$meta_struct_id = $field->get_meta_struct_id();
|
||||
if (!isset($this->javascript_fields[$meta_struct_id]))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
$_lst[$indice]['fields'][$meta_struct_id] = array(
|
||||
'dirty' => false,
|
||||
'meta_id' => $field->get_meta_id(),
|
||||
'meta_struct_id' => $meta_struct_id,
|
||||
'value' => $field->get_value()
|
||||
);
|
||||
}
|
||||
|
||||
$_lst[$indice]['subdefs'] = array('thumbnail' => null, 'preview' => null);
|
||||
|
||||
$thumbnail = $record->get_thumbnail();
|
||||
|
||||
|
||||
$_lst[$indice]['subdefs']['thumbnail'] = array(
|
||||
'url' => $thumbnail->get_url()
|
||||
, 'w' => $thumbnail->get_width()
|
||||
, 'h' => $thumbnail->get_height()
|
||||
);
|
||||
|
||||
$_lst[$indice]['preview'] = $twig->render('common/preview.html', array('record' => $record));
|
||||
|
||||
try
|
||||
{
|
||||
$_lst[$indice]['subdefs']['preview'] = $record->get_subdef('preview');
|
||||
}
|
||||
catch (Exception $e)
|
||||
{
|
||||
|
||||
}
|
||||
$_lst[$indice]['type'] = $record->get_type();
|
||||
}
|
||||
|
||||
$this->javascript_elements = $_lst;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate data for JSON UI
|
||||
*
|
||||
* @return action_edit
|
||||
*/
|
||||
protected function generate_javascript_sugg_values()
|
||||
{
|
||||
$done = array();
|
||||
$T_sgval = array();
|
||||
foreach ($this->selection as $record)
|
||||
{
|
||||
/* @var $record record_adapter */
|
||||
$base_id = $record->get_base_id();
|
||||
$record_id = $record->get_record_id();
|
||||
$databox = $record->get_databox();
|
||||
|
||||
if (isset($done[$base_id]))
|
||||
continue;
|
||||
|
||||
$T_sgval['b' . $base_id] = array();
|
||||
$collection = collection::get_from_base_id($base_id);
|
||||
|
||||
if ($sxe = simplexml_load_string($collection->get_prefs()))
|
||||
{
|
||||
$z = $sxe->xpath('/baseprefs/sugestedValues');
|
||||
|
||||
if (!$z || !is_array($z))
|
||||
continue;
|
||||
|
||||
foreach ($z[0] as $ki => $vi) // les champs
|
||||
{
|
||||
|
||||
$field = $databox->get_meta_structure()->get_element_by_name($ki);
|
||||
if (!$field)
|
||||
continue; // champ inconnu dans la structure ?
|
||||
if (!$vi)
|
||||
continue;
|
||||
|
||||
$T_sgval['b' . $base_id][$field->get_id()] = array();
|
||||
foreach ($vi->value as $oneValue) // les valeurs sug
|
||||
{
|
||||
$T_sgval['b' . $base_id][$field->get_id()][] =
|
||||
(string) $oneValue;
|
||||
}
|
||||
}
|
||||
}
|
||||
unset($collection);
|
||||
$done[$base_id] = true;
|
||||
}
|
||||
$this->javascript_sugg_values = $T_sgval;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate data for JSON UI
|
||||
*
|
||||
* @return action_edit
|
||||
*/
|
||||
protected function generate_javascript_status()
|
||||
{
|
||||
$_tstatbits = array();
|
||||
$appbox = appbox::get_instance();
|
||||
$session = $appbox->get_session();
|
||||
$user = User_Adapter::getInstance($session->get_usr_id(), $appbox);
|
||||
|
||||
if ($user->ACL()->has_right('changestatus'))
|
||||
{
|
||||
$status = databox_status::getDisplayStatus();
|
||||
if (isset($status[$this->get_sbas_id()]))
|
||||
{
|
||||
foreach ($status[$this->get_sbas_id()] as $n => $statbit)
|
||||
{
|
||||
$_tstatbits[$n] = array();
|
||||
$_tstatbits[$n]['label0'] = $statbit['labeloff'];
|
||||
$_tstatbits[$n]['label1'] = $statbit['labelon'];
|
||||
$_tstatbits[$n]['img_off'] = $statbit['img_off'];
|
||||
$_tstatbits[$n]['img_on'] = $statbit['img_on'];
|
||||
$_tstatbits[$n]['_value'] = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$this->javascript_status = $_tstatbits;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate data for JSON UI
|
||||
*
|
||||
* @return action_edit
|
||||
*/
|
||||
protected function generate_javascript_fields()
|
||||
{
|
||||
$_tfields = $fields = array();
|
||||
|
||||
$this->has_thesaurus = false;
|
||||
|
||||
$databox = databox::get_instance($this->get_sbas_id());
|
||||
$meta_struct = $databox->get_meta_structure();
|
||||
|
||||
foreach ($meta_struct as $meta)
|
||||
{
|
||||
$fields[] = $meta;
|
||||
$this->generate_field($meta);
|
||||
}
|
||||
|
||||
$this->fields = $fields;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
protected function generate_field(databox_field $meta)
|
||||
{
|
||||
$i = count($this->javascript_fields);
|
||||
|
||||
switch ($meta->get_type())
|
||||
{
|
||||
case 'datetime':
|
||||
$format = _('phraseanet::technique::datetime-edit-format');
|
||||
$explain = _('phraseanet::technique::datetime-edit-explain');
|
||||
break;
|
||||
case 'date':
|
||||
$format = _('phraseanet::technique::date-edit-format');
|
||||
$explain = _('phraseanet::technique::date-edit-explain');
|
||||
break;
|
||||
case 'time':
|
||||
$format = _('phraseanet::technique::time-edit-format');
|
||||
$explain = _('phraseanet::technique::time-edit-explain');
|
||||
break;
|
||||
default:
|
||||
$format = $explain = "";
|
||||
break;
|
||||
}
|
||||
|
||||
$regfield = ($meta->is_regname() || $meta->is_regdesc() || $meta->is_regdate());
|
||||
|
||||
|
||||
$separator = $meta->get_separator();
|
||||
|
||||
$datas = array(
|
||||
'meta_struct_id' => $meta->get_id()
|
||||
, 'name' => $meta->get_name()
|
||||
, '_status' => 0
|
||||
, '_value' => ''
|
||||
, '_sgval' => array()
|
||||
, 'required' => $meta->is_required()
|
||||
, 'readonly' => $meta->is_readonly()
|
||||
, 'type' => $meta->get_type()
|
||||
, 'format' => $format
|
||||
, 'explain' => $explain
|
||||
, 'tbranch' => $meta->get_tbranch()
|
||||
, 'maxLength' => $meta->get_source()->maxlength()
|
||||
, 'minLength' => $meta->get_source()->minLength()
|
||||
, 'regfield' => $regfield
|
||||
, 'multi' => $meta->is_multi()
|
||||
, 'separator' => $separator
|
||||
);
|
||||
|
||||
if (trim($meta->get_tbranch()) !== '')
|
||||
$this->has_thesaurus = true;
|
||||
|
||||
$this->javascript_fields[$meta->get_id()] = $datas;
|
||||
}
|
||||
|
||||
/**
|
||||
* Substitute Head file of groupings and save new Desc
|
||||
*
|
||||
* @param http_request $request
|
||||
* @return action_edit
|
||||
*/
|
||||
public function execute(Symfony\Component\HttpFoundation\Request $request)
|
||||
{
|
||||
$appbox = appbox::get_instance();
|
||||
if ($request->get('act_option') == 'SAVEGRP' && $request->get('newrepresent'))
|
||||
{
|
||||
try
|
||||
{
|
||||
$reg_record = $this->get_grouping_head();
|
||||
$reg_sbas_id = $reg_record->get_base_id();
|
||||
|
||||
$newsubdef_reg = new record_adapter($reg_sbas_id, $request->get('newrepresent'));
|
||||
|
||||
if ($newsubdef_reg->get_type() !== 'image')
|
||||
throw new Exception('A reg image must come from image data');
|
||||
|
||||
foreach ($newsubdef_reg->get_subdefs() as $name => $value)
|
||||
{
|
||||
$pathfile = $value->get_pathfile();
|
||||
$system_file = new system_file($pathfile);
|
||||
$reg_record->substitute_subdef($name, $system_file);
|
||||
}
|
||||
}
|
||||
catch (Exception $e)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
if (!is_array($request->get('mds')))
|
||||
|
||||
return $this;
|
||||
|
||||
$sbas_id = (int) $request->get('sbid');
|
||||
$databox = databox::get_instance($sbas_id);
|
||||
$meta_struct = $databox->get_meta_structure();
|
||||
$write_edit_el = false;
|
||||
$date_obj = new DateTime();
|
||||
foreach ($meta_struct->get_elements() as $meta_struct_el)
|
||||
{
|
||||
if ($meta_struct_el->get_metadata_namespace() == "PHRASEANET" && $meta_struct_el->get_metadata_tagname() == 'tf-editdate')
|
||||
$write_edit_el = $meta_struct_el;
|
||||
}
|
||||
|
||||
$elements = $this->selection->get_elements();
|
||||
|
||||
foreach ($request->get('mds') as $rec)
|
||||
{
|
||||
try
|
||||
{
|
||||
$record = $databox->get_record($rec['record_id']);
|
||||
}
|
||||
catch (Exception $e)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
$key = $record->get_serialize_key();
|
||||
|
||||
if (!array_key_exists($key, $elements))
|
||||
continue;
|
||||
|
||||
$statbits = $rec['status'];
|
||||
$editDirty = $rec['edit'];
|
||||
|
||||
if ($editDirty == '0')
|
||||
$editDirty = false;
|
||||
else
|
||||
$editDirty = true;
|
||||
|
||||
if (is_array($rec['metadatas']))
|
||||
{
|
||||
$record->set_metadatas($rec['metadatas']);
|
||||
}
|
||||
|
||||
if ($write_edit_el instanceof databox_field)
|
||||
{
|
||||
$fields = $record->get_caption()->get_fields(array($write_edit_el->get_name()));
|
||||
$field = array_pop($fields);
|
||||
|
||||
$metas = array(
|
||||
array(
|
||||
'meta_struct_id' => $write_edit_el->get_id()
|
||||
, 'meta_id' => ($field ? $field->get_meta_id() : null)
|
||||
, 'value' => array($date_obj->format('Y-m-d h:i:s'))
|
||||
)
|
||||
);
|
||||
|
||||
$record->set_metadatas($metas);
|
||||
}
|
||||
|
||||
$newstat = $record->get_status();
|
||||
$statbits = ltrim($statbits, 'x');
|
||||
if (!in_array($statbits, array('', 'null')))
|
||||
{
|
||||
$mask_and = ltrim(str_replace(
|
||||
array('x', '0', '1', 'z'), array('1', 'z', '0', '1'), $statbits), '0');
|
||||
if ($mask_and != '')
|
||||
$newstat = databox_status::operation_and_not($newstat, $mask_and);
|
||||
|
||||
$mask_or = ltrim(str_replace('x', '0', $statbits), '0');
|
||||
|
||||
if ($mask_or != '')
|
||||
$newstat = databox_status::operation_or($newstat, $mask_or);
|
||||
|
||||
$record->set_binary_status($newstat);
|
||||
}
|
||||
|
||||
$record->write_metas();
|
||||
|
||||
if ($statbits != '')
|
||||
{
|
||||
$appbox->get_session()
|
||||
->get_logger($record->get_databox())
|
||||
->log($record, Session_Logger::EVENT_STATUS, '', '');
|
||||
}
|
||||
if ($editDirty)
|
||||
{
|
||||
$appbox->get_session()
|
||||
->get_logger($record->get_databox())
|
||||
->log($record, Session_Logger::EVENT_EDIT, '', '');
|
||||
}
|
||||
}
|
||||
|
||||
return $this;
|
||||
|
||||
// foreach ($trecchanges as $fname => $fchange)
|
||||
// {
|
||||
// $bool = false;
|
||||
// if ($regfields && $parm['act_option'] == 'SAVEGRP'
|
||||
// && $fname == $regfields['regname'])
|
||||
// {
|
||||
// try
|
||||
// {
|
||||
// $basket = basket_adapter::getInstance($parm['ssel']);
|
||||
// $basket->name = implode(' ', $fchange['values']);
|
||||
// $basket->save();
|
||||
// $bool = true;
|
||||
// }
|
||||
// catch (Exception $e)
|
||||
// {
|
||||
// echo $e->getMessage();
|
||||
// }
|
||||
// }
|
||||
// if ($regfields && $parm['act_option'] == 'SAVEGRP'
|
||||
// && $fname == $regfields['regdesc'])
|
||||
// {
|
||||
// try
|
||||
// {
|
||||
// $basket = basket_adapter::getInstance($parm['ssel']);
|
||||
// $basket->desc = implode(' ', $fchange['values']);
|
||||
// $basket->save();
|
||||
// $bool = true;
|
||||
// }
|
||||
// catch (Exception $e)
|
||||
// {
|
||||
// echo $e->getMessage();
|
||||
// }
|
||||
// }
|
||||
// if ($bool)
|
||||
// {
|
||||
// try
|
||||
// {
|
||||
// $basket = basket_adapter::getInstance($parm['ssel']);
|
||||
// $basket->delete_cache();
|
||||
// }
|
||||
// catch (Exception $e)
|
||||
// {
|
||||
//
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// return $this;
|
||||
}
|
||||
|
||||
}
|
51
lib/classes/module/prod/route/records/feed.class.php
Normal file
51
lib/classes/module/prod/route/records/feed.class.php
Normal file
@@ -0,0 +1,51 @@
|
||||
<?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 module_prod_route_records_feed extends module_prod_route_records_abstract
|
||||
{
|
||||
|
||||
/**
|
||||
*
|
||||
* @var Array
|
||||
*/
|
||||
protected $required_sbas_rights = array('cbas_chupub');
|
||||
/**
|
||||
*
|
||||
* @var boolean
|
||||
*/
|
||||
protected $works_on_unique_sbas = true;
|
||||
protected $flatten_groupings = true;
|
||||
|
||||
public function __construct(Symfony\Component\HttpFoundation\Request $request)
|
||||
{
|
||||
$appbox = appbox::get_instance();
|
||||
|
||||
parent::__construct($request);
|
||||
|
||||
if ($this->is_single_grouping())
|
||||
{
|
||||
$record = array_pop($this->selection->get_elements());
|
||||
foreach ($record->get_children() as $child)
|
||||
{
|
||||
$this->selection->add_element($child);
|
||||
}
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
}
|
127
lib/classes/module/prod/route/records/move.class.php
Normal file
127
lib/classes/module/prod/route/records/move.class.php
Normal file
@@ -0,0 +1,127 @@
|
||||
<?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 module_prod_route_records_move extends module_prod_route_records_abstract
|
||||
{
|
||||
/**
|
||||
*
|
||||
* @var Array
|
||||
*/
|
||||
protected $required_rights = array('candeleterecord');
|
||||
/**
|
||||
*
|
||||
* @var Array
|
||||
*/
|
||||
protected $available_destinations;
|
||||
/**
|
||||
*
|
||||
*/
|
||||
protected $works_on_unique_sbas = true;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @return action_move
|
||||
*/
|
||||
public function __construct(Symfony\Component\HttpFoundation\Request $request)
|
||||
{
|
||||
parent::__construct($request);
|
||||
$this->evaluate_destinations();
|
||||
|
||||
return $this;
|
||||
}
|
||||
/**
|
||||
* Check which collections can receive the documents
|
||||
*
|
||||
* @return action_move
|
||||
*/
|
||||
protected function evaluate_destinations()
|
||||
{
|
||||
$this->available_destinations = array();
|
||||
|
||||
if (!$this->is_possible)
|
||||
|
||||
return $this;
|
||||
|
||||
$appbox = appbox::get_instance();
|
||||
$session = $appbox->get_session();
|
||||
$user = User_Adapter::getInstance($session->get_usr_id(), $appbox);
|
||||
|
||||
$this->available_destinations = array_keys($user->ACL()->get_granted_base(array('canaddrecord'), array($this->sbas_id)));
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an array of base_id
|
||||
*
|
||||
* @return Array
|
||||
*/
|
||||
public function available_destination()
|
||||
{
|
||||
return $this->available_destinations;
|
||||
}
|
||||
|
||||
public function propose()
|
||||
{
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param http_request $request
|
||||
* @return action_move
|
||||
*/
|
||||
public function execute(Symfony\Component\HttpFoundation\Request $request)
|
||||
{
|
||||
$appbox = appbox::get_instance();
|
||||
$session = $appbox->get_session();
|
||||
$user = User_Adapter::getInstance($session->get_usr_id(), $appbox);
|
||||
|
||||
$base_dest =
|
||||
$user->ACL()->has_right_on_base($request->get('base_id'), 'canaddrecord') ?
|
||||
$request->get('base_id') : false;
|
||||
|
||||
if (!$this->is_possible())
|
||||
throw new Exception('This action is not possible');
|
||||
|
||||
if ($request->get("chg_coll_son") == "1")
|
||||
{
|
||||
foreach ($this->selection as $record)
|
||||
{
|
||||
if (!$record->is_grouping())
|
||||
continue;
|
||||
foreach ($record->get_children() as $child)
|
||||
{
|
||||
if (!$user->ACL()->has_right_on_base(
|
||||
$child->get_base_id(), 'candeleterecord'))
|
||||
continue;
|
||||
$this->selection->add_element($child);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$collection = collection::get_from_base_id($base_dest);
|
||||
|
||||
foreach ($this->selection as $record)
|
||||
{
|
||||
$record->move_to_collection($collection, $appbox);
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
905
lib/classes/module/report.class.php
Normal file
905
lib/classes/module/report.class.php
Normal file
@@ -0,0 +1,905 @@
|
||||
<?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 module_report
|
||||
* @license http://opensource.org/licenses/gpl-3.0 GPLv3
|
||||
* @link www.phraseanet.com
|
||||
*/
|
||||
class module_report
|
||||
{
|
||||
|
||||
/**
|
||||
* Start date of the report
|
||||
* @var string - timestamp
|
||||
*/
|
||||
protected $dmin;
|
||||
/**
|
||||
* End date of the report
|
||||
* @var string - timestamp
|
||||
*/
|
||||
protected $dmax;
|
||||
/**
|
||||
* Id of the base we want to connect
|
||||
* @var int
|
||||
*/
|
||||
protected $sbas_id;
|
||||
/**
|
||||
* Id of the current app's box user
|
||||
* @var int
|
||||
*/
|
||||
protected $user_id;
|
||||
/**
|
||||
* The result of the report
|
||||
* @var array
|
||||
*/
|
||||
public $report = array();
|
||||
/**
|
||||
* The title of the report
|
||||
* @var string
|
||||
*/
|
||||
protected $title = '';
|
||||
/**
|
||||
* default displayed value in the formated tab
|
||||
* @var array
|
||||
*/
|
||||
protected $display = array();
|
||||
/**
|
||||
* ?
|
||||
* @var <array>
|
||||
*/
|
||||
protected $default_display = array();
|
||||
/**
|
||||
* Contain all the field from the sql request
|
||||
* @var array
|
||||
*/
|
||||
protected $champ = array();
|
||||
/**
|
||||
* result of the report
|
||||
* @var array
|
||||
*/
|
||||
protected $result = array();
|
||||
/**
|
||||
* The id of all collections from a databox
|
||||
* @var string
|
||||
*/
|
||||
protected $list_coll_id = '';
|
||||
/**
|
||||
* The number of record displayed by page if enable limit is false
|
||||
* @var int
|
||||
*/
|
||||
protected $nb_record = 30;
|
||||
/**
|
||||
* The current number of the page where are displaying the results
|
||||
* @var int
|
||||
*/
|
||||
protected $nb_page = 1;
|
||||
/**
|
||||
* check if there is a previous page
|
||||
* @var <bool>
|
||||
*/
|
||||
protected $previous_page = false;
|
||||
/**
|
||||
* check if there is a next page
|
||||
* @var <bool>
|
||||
*/
|
||||
protected $next_page = false;
|
||||
/**
|
||||
*
|
||||
* @var int total of result
|
||||
*/
|
||||
protected $total = 0;
|
||||
/**
|
||||
* the request executed
|
||||
*/
|
||||
protected $req = '';
|
||||
/**
|
||||
* the request executed
|
||||
*/
|
||||
protected $params = array();
|
||||
/**
|
||||
* do we display next and previous button
|
||||
* @var bool
|
||||
*/
|
||||
protected $display_nav = false;
|
||||
/**
|
||||
* do we display the configuration button
|
||||
* @var <bool>
|
||||
*/
|
||||
protected $config = true;
|
||||
/**
|
||||
* gettext tags for days
|
||||
* @var <array>
|
||||
*/
|
||||
protected $jour;
|
||||
/**
|
||||
* gettext tags for month
|
||||
* @var <array>
|
||||
*/
|
||||
protected $month;
|
||||
/**
|
||||
* The name of the database
|
||||
* @var string
|
||||
*/
|
||||
protected $dbname;
|
||||
/**
|
||||
* The periode displayed in a string of the report
|
||||
* @var string
|
||||
*/
|
||||
protected $periode;
|
||||
/**
|
||||
* filter executed on report choose by the user
|
||||
* @var array;
|
||||
*/
|
||||
protected $tab_filter = array();
|
||||
/**
|
||||
* column displayed in the report choose by the user
|
||||
* @var <array>
|
||||
*/
|
||||
protected $active_column = array();
|
||||
/**
|
||||
* array that contains the string displayed
|
||||
* foreach filters
|
||||
* @var <array>
|
||||
*/
|
||||
protected $posting_filter = array();
|
||||
/**
|
||||
* The ORDER BY filters of the query
|
||||
* by default is empty
|
||||
* @var array
|
||||
*/
|
||||
protected $tab_order = array();
|
||||
/**
|
||||
* define columns that are boundable
|
||||
* @var <array>
|
||||
*/
|
||||
protected $bound = array();
|
||||
/**
|
||||
* do we display print button
|
||||
* @var <bool>
|
||||
*/
|
||||
protected $print = true;
|
||||
/**
|
||||
* do we display csv button
|
||||
* @var <bool>
|
||||
*/
|
||||
protected $csv = true;
|
||||
/**
|
||||
* do we enable limit filter for the report
|
||||
* @var bool
|
||||
*/
|
||||
protected $enable_limit = true;
|
||||
/**
|
||||
* gettext correspondance for all available columns in report
|
||||
* @var array
|
||||
*/
|
||||
protected $cor = array();
|
||||
/**
|
||||
* group result of a report this is the name ogf the grouped column
|
||||
* @var string
|
||||
*/
|
||||
protected $groupby;
|
||||
/**
|
||||
* disbale or enable pretty string useful for export in csv
|
||||
* @var boolean
|
||||
*/
|
||||
protected $pretty_string = true;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
protected $cor_query = array();/* ~*~*~*~*~*~*~*~*~*~*~*~ */
|
||||
/* METHODS, VARIABLES */
|
||||
/* ~*~*~*~*~*~*~*~*~*~*~*~ */
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
*
|
||||
* @name report::__construct()
|
||||
* @param $arg1 the minimal date of the report
|
||||
* @param $arg2 the maximal date of the report
|
||||
* @param $sbas_id the id of the base where we want to connect
|
||||
*/
|
||||
public function __construct($d1, $d2, $sbas_id, $collist)
|
||||
{
|
||||
$appbox = appbox::get_instance();
|
||||
$session = $appbox->get_session();
|
||||
$this->dmin = $d1;
|
||||
$this->dmax = $d2;
|
||||
$this->sbas_id = $sbas_id;
|
||||
$this->list_coll_id = $collist;
|
||||
$this->user_id = $session->get_usr_id();
|
||||
$this->periode = phraseadate::getPrettyString(new DateTime($d1))
|
||||
. ' - ' . phraseadate::getPrettyString(new DateTime($d2));
|
||||
$this->dbname = phrasea::sbas_names($sbas_id);
|
||||
$this->cor = $this->setCor();
|
||||
$this->jour = $this->setDay();
|
||||
$this->month = $this->setMonth();
|
||||
}
|
||||
|
||||
public function getUser_id()
|
||||
{
|
||||
return $this->user_id;
|
||||
}
|
||||
|
||||
public function getParams()
|
||||
{
|
||||
return $this->params;
|
||||
}
|
||||
|
||||
public function setUser_id($user_id)
|
||||
{
|
||||
$this->user_id = $user_id;
|
||||
}
|
||||
|
||||
|
||||
public function getSbas_id()
|
||||
{
|
||||
return $this->sbas_id;
|
||||
}
|
||||
|
||||
public function setSbas_id($sbas_id)
|
||||
{
|
||||
$this->sbas_id = $sbas_id;
|
||||
}
|
||||
|
||||
public function setPrettyString($bool)
|
||||
{
|
||||
$this->pretty_string = $bool;
|
||||
}
|
||||
|
||||
public function getPrettyString()
|
||||
{
|
||||
return $this->pretty_string;
|
||||
}
|
||||
|
||||
public function setTitle($title)
|
||||
{
|
||||
$this->title = $title;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function setCsv($bool)
|
||||
{
|
||||
$this->csv = $bool;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getCsv()
|
||||
{
|
||||
return $this->csv;
|
||||
}
|
||||
|
||||
public function setFilter(array $filter)
|
||||
{
|
||||
$this->tab_filter = $filter;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function setPeriode($periode)
|
||||
{
|
||||
$this->periode = $periode;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function setRequest($sql)
|
||||
{
|
||||
$this->req = $sql;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public function getPeriode()
|
||||
{
|
||||
return $this->periode;
|
||||
}
|
||||
|
||||
public function setpostingFilter($filter)
|
||||
{
|
||||
$this->posting_filter = $filter;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getPostingFilter()
|
||||
{
|
||||
return $this->posting_filter;
|
||||
}
|
||||
|
||||
public function setLimit($page, $limit)
|
||||
{
|
||||
$this->nb_page = $page;
|
||||
$this->nb_record = $limit;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getGroupBy()
|
||||
{
|
||||
return $this->groupby;
|
||||
}
|
||||
|
||||
public function setGroupBy($groupby)
|
||||
{
|
||||
$this->groupby = $groupby;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function setActiveColumn(array $active_column)
|
||||
{
|
||||
$this->active_column = $active_column;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getActiveColumn()
|
||||
{
|
||||
return $this->active_column;
|
||||
}
|
||||
|
||||
public function setConfig($bool)
|
||||
{
|
||||
$this->config = $bool;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getConfig()
|
||||
{
|
||||
return $this->config;
|
||||
}
|
||||
|
||||
public function setPrint($bool)
|
||||
{
|
||||
$this->print = $bool;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getPrint()
|
||||
{
|
||||
return $this->print;
|
||||
}
|
||||
|
||||
public function setHasLimit($bool)
|
||||
{
|
||||
$this->enable_limit = $bool;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getHasLimit()
|
||||
{
|
||||
return $this->enable_limit;
|
||||
}
|
||||
|
||||
public function setBound($column, $bool)
|
||||
{
|
||||
if ($bool)
|
||||
{
|
||||
$this->bound[$column] = 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->bound[$column] = 0;
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getBound()
|
||||
{
|
||||
return $this->bound;
|
||||
}
|
||||
|
||||
public function setOrder($champ, $order)
|
||||
{
|
||||
$this->tab_order['champ'] = $champ;
|
||||
$this->tab_order['order'] = $order;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getTitle()
|
||||
{
|
||||
return $this->title;
|
||||
}
|
||||
|
||||
public function getDisplay()
|
||||
{
|
||||
return $this->display;
|
||||
}
|
||||
|
||||
public function getEnableLimit()
|
||||
{
|
||||
return $this->enable_limit;
|
||||
}
|
||||
|
||||
public function getSbasId()
|
||||
{
|
||||
return $this->sbas_id;
|
||||
}
|
||||
|
||||
public function getDmin()
|
||||
{
|
||||
return $this->dmin;
|
||||
}
|
||||
|
||||
public function getDmax()
|
||||
{
|
||||
return $this->dmax;
|
||||
}
|
||||
|
||||
public function getResult()
|
||||
{
|
||||
return $this->result;
|
||||
}
|
||||
|
||||
public function setResult(array $rs)
|
||||
{
|
||||
$this->result = $rs;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getOrder($k = false)
|
||||
{
|
||||
if ($k === false)
|
||||
|
||||
return $this->tab_order;
|
||||
return $this->tab_order[$k];
|
||||
}
|
||||
|
||||
public function getNbPage()
|
||||
{
|
||||
return $this->nb_page;
|
||||
}
|
||||
|
||||
public function getNbRecord()
|
||||
{
|
||||
return $this->nb_record;
|
||||
}
|
||||
|
||||
public function getTabFilter()
|
||||
{
|
||||
return $this->tab_filter;
|
||||
}
|
||||
|
||||
public function getUserId()
|
||||
{
|
||||
return $this->user_id;
|
||||
}
|
||||
|
||||
public function getListCollId()
|
||||
{
|
||||
return $this->list_coll_id;
|
||||
}
|
||||
|
||||
public function getReq()
|
||||
{
|
||||
return $this->req;
|
||||
}
|
||||
|
||||
public function getTransQueryString()
|
||||
{
|
||||
return $this->cor_query;
|
||||
}
|
||||
|
||||
public function getTotal()
|
||||
{
|
||||
return $this->total;
|
||||
}
|
||||
|
||||
public function setTotal($total)
|
||||
{
|
||||
$this->total = $total;
|
||||
}
|
||||
public function getDefault_display()
|
||||
{
|
||||
return $this->default_display;
|
||||
}
|
||||
|
||||
public function setDefault_display($default_display)
|
||||
{
|
||||
$this->default_display = $default_display;
|
||||
}
|
||||
|
||||
public function getChamps()
|
||||
{
|
||||
return $this->champ;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Retourne un objet qui genere la requete selon le type de report
|
||||
* @param string $domain
|
||||
* @return module_report_sqlconnexion
|
||||
*/
|
||||
public function sqlBuilder($domain)
|
||||
{
|
||||
switch ($domain)
|
||||
{
|
||||
case 'connexion' :
|
||||
return new module_report_sqlconnexion($this);
|
||||
break;
|
||||
case 'download' :
|
||||
return new module_report_sqldownload($this);
|
||||
break;
|
||||
case 'question' :
|
||||
return new module_report_sqlquestion($this);
|
||||
break;
|
||||
case 'action' :
|
||||
return new module_report_sqlaction($this);
|
||||
break;
|
||||
default:
|
||||
return $this->req;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
protected function setChamp($rs)
|
||||
{
|
||||
$row = array_shift($rs);
|
||||
|
||||
$this->champ = is_array($row) ? array_keys($row) : array();
|
||||
$this->default_display = is_array($row) ? array_keys($row) : array();
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
* initialise les configuration des columns ex : boundable, linkable orderable
|
||||
* etc .. par defaut ou celle passe en parametre par $tab
|
||||
* @param array $tab
|
||||
* @param string $groupby
|
||||
* @return void
|
||||
*/
|
||||
protected function setDisplay($tab, $groupby = false)
|
||||
{
|
||||
if ($tab == false && $groupby == false)
|
||||
$this->initDefaultConfigColumn($this->default_display);
|
||||
elseif ($groupby != false && $tab == false)
|
||||
$this->initDefaultConfigColumn($this->champ);
|
||||
elseif ($tab != false)
|
||||
$this->setConfigColumn($tab);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
protected function setReport()
|
||||
{
|
||||
$registry = registry::get_instance();
|
||||
$this->report['dbid'] = $this->sbas_id;
|
||||
$this->report['periode'] = $this->periode;
|
||||
$this->report['dbname'] = $this->dbname;
|
||||
$this->report['dmin'] = $this->dmin;
|
||||
$this->report['dmax'] = $this->dmax;
|
||||
$this->report['server'] = $registry->get('GV_ServerName');
|
||||
$this->report['filter'] = $this->tab_filter;
|
||||
$this->report['posting_filter'] = $this->posting_filter;
|
||||
$this->report['active_column'] = $this->active_column;
|
||||
$this->report['default_display'] = $this->default_display;
|
||||
$this->report['config'] = $this->config;
|
||||
$this->report['total'] = $this->total;
|
||||
$this->report['display_nav'] = $this->display_nav;
|
||||
$this->report['nb_record'] = $this->nb_record;
|
||||
$this->report['page'] = $this->nb_page;
|
||||
$this->report['previous_page'] = $this->previous_page;
|
||||
$this->report['next_page'] = $this->next_page;
|
||||
$this->report['title'] = $this->title;
|
||||
$this->report['allChamps'] = $this->champ;
|
||||
$this->report['display'] = $this->display;
|
||||
$this->report['result'] = $this->result;
|
||||
$this->report['print'] = $this->print;
|
||||
$this->report['csv'] = $this->csv;
|
||||
}
|
||||
|
||||
/**
|
||||
* etablis les correspondance entre gettext et le nom des columns du report
|
||||
* @return array
|
||||
*/
|
||||
private function setCor()
|
||||
{
|
||||
return array(
|
||||
'user' => _('report:: utilisateur'),
|
||||
'coll_id' => _('report:: collections'),
|
||||
'connexion' => _('report:: Connexion'),
|
||||
'comment' => _('report:: commentaire'),
|
||||
'search' => _('report:: question'),
|
||||
'date' => _('report:: date'),
|
||||
'ddate' => _('report:: date'),
|
||||
'fonction' => _('report:: fonction'),
|
||||
'activite' => _('report:: activite'),
|
||||
'pays' => _('report:: pays'),
|
||||
'societe' => _('report:: societe'),
|
||||
'nb' => _('report:: nombre'),
|
||||
'pourcent' => _('report:: pourcentage'),
|
||||
'telechargement' => _('report:: telechargement'),
|
||||
'record_id' => _('report:: record id'),
|
||||
'final' => _('report:: type d\'action'),
|
||||
'xml' => _('report:: sujet'),
|
||||
'file' => _('report:: fichier'),
|
||||
'mime' => _('report:: type'),
|
||||
'size' => _('report:: taille'),
|
||||
'copyright' => _('report:: copyright'),
|
||||
'final' => _('phraseanet:: sous definition')
|
||||
);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
* etablis les correspondance entre gettext et le nom des jours du report
|
||||
* @return array
|
||||
*/
|
||||
private function setDay()
|
||||
{
|
||||
return Array(
|
||||
1 => _('phraseanet::jours:: lundi'),
|
||||
2 => _('phraseanet::jours:: mardi'),
|
||||
3 => _('phraseanet::jours:: mercredi'),
|
||||
4 => _('phraseanet::jours:: jeudi'),
|
||||
5 => _('phraseanet::jours:: vendredi'),
|
||||
6 => _('phraseanet::jours:: samedi'),
|
||||
7 => _('phraseanet::jours:: dimanche'));
|
||||
}
|
||||
|
||||
/**
|
||||
* etablis les correspondance entre gettext et le nom des mois du report
|
||||
* @return array
|
||||
*/
|
||||
private function setMonth()
|
||||
{
|
||||
return array(
|
||||
_('janvier'),
|
||||
_('fevrier'),
|
||||
_('mars'),
|
||||
_('avril'),
|
||||
_('mai'),
|
||||
_('juin'),
|
||||
_('juillet'),
|
||||
_('aout'),
|
||||
_('septembre'),
|
||||
_('octobre'),
|
||||
_('novembre'),
|
||||
_('decembre')
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* effectue le mechanism de pagination
|
||||
* @param resultset $rs
|
||||
*/
|
||||
protected function calculatePages($rs)
|
||||
{
|
||||
if ($this->nb_record && $this->total > $this->nb_record)
|
||||
{
|
||||
$this->previous_page = $this->nb_page - 1;
|
||||
if ($this->previous_page == 0)
|
||||
$this->previous_page = false;
|
||||
|
||||
$test = ($this->total / $this->nb_record);
|
||||
if ($this->nb_page == intval(ceil($test)))
|
||||
$this->next_page = false;
|
||||
else
|
||||
$this->next_page = $this->nb_page + 1;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* on ne montre le formulaire que si il y'a plus de resultat que de nombre
|
||||
* de record que l'on veut afficher
|
||||
*/
|
||||
protected function setDisplayNav()
|
||||
{
|
||||
if ($this->total > $this->nb_record)
|
||||
$this->display_nav = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @desc Initialize the configuration foreach column displayed in the report
|
||||
* @param array $display contain the conf's variables
|
||||
* @return void
|
||||
*/
|
||||
protected function initDefaultConfigColumn($display)
|
||||
{
|
||||
$array = array();
|
||||
foreach ($display as $key => $value)
|
||||
$array[$value] = array("", 0, 0, 0, 0);
|
||||
$this->setConfigColumn($array);
|
||||
}
|
||||
|
||||
/**
|
||||
* @desc Set your own configuration for each column displayed in the html table
|
||||
* @param array $tab contain your conf's variables
|
||||
* array( 'field' =>
|
||||
* array('title of the colum', '1 = order ON / 0 = order OFF',
|
||||
* '1 = bound ON / 0 = bound OFF')
|
||||
* @example $tab = array('user' => array('user list', 1, 0),
|
||||
* 'id' => array(user id, 0, 0)); etc ..
|
||||
* @return void
|
||||
*/
|
||||
protected function setConfigColumn($tab)
|
||||
{
|
||||
|
||||
foreach ($tab as $column => $row)
|
||||
{
|
||||
foreach ($row as $ind => $value)
|
||||
{
|
||||
$def = false;
|
||||
if (array_key_exists($column, $this->cor))
|
||||
{
|
||||
$title_text = $this->cor[$column];
|
||||
$def = true;
|
||||
}
|
||||
empty($row[0]) ? $title = $column : $title = $row[0];
|
||||
|
||||
$sort = $row[1];
|
||||
array_key_exists($column, $this->bound) ?
|
||||
$bound = $this->bound[$column] : $bound = $row[2];
|
||||
$filter = (isset($row[3]) ? $row[3] : 0);
|
||||
$groupby = $row[4];
|
||||
$config = array(
|
||||
'title' => $title,
|
||||
'sort' => $sort,
|
||||
'bound' => $bound,
|
||||
'filter' => $filter,
|
||||
'groupby' => $groupby
|
||||
);
|
||||
$def ? $config['title'] = $title_text : "";
|
||||
|
||||
$this->display[$column] = $config;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @desc build the final formated array which contains all the result,
|
||||
* we construct the html code from this array
|
||||
* @param array $tab pass the configcolumn parameter to this tab
|
||||
* @return the formated array
|
||||
*/
|
||||
public function buildReport($tab = false, $groupby = false, $on = false)
|
||||
{
|
||||
if (sizeof($this->report) > 0)
|
||||
|
||||
return $this->report;
|
||||
$conn = connection::getPDOConnection($this->sbas_id);
|
||||
|
||||
$this->buildReq($groupby, $on);
|
||||
|
||||
try
|
||||
{
|
||||
try
|
||||
{
|
||||
$stmt = $conn->prepare($this->req);
|
||||
$stmt->execute($this->params);
|
||||
$rs = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
||||
$stmt->closeCursor();
|
||||
}
|
||||
catch(PDOException $e)
|
||||
{
|
||||
echo $e->getMessage();
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
//set request field
|
||||
$this->setChamp($rs);
|
||||
//set display
|
||||
$this->setDisplay($tab, $groupby);
|
||||
//construct results
|
||||
$this->buildResult($rs);
|
||||
//calculate prev and next page
|
||||
$this->calculatePages($rs);
|
||||
//do we display navigator ?
|
||||
$this->setDisplayNav();
|
||||
//assign all variables
|
||||
$this->setReport();
|
||||
|
||||
return $this->report;
|
||||
}
|
||||
catch (Exception $e)
|
||||
{
|
||||
echo $e->getMessage();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @desc return the text between the node we are looking for
|
||||
* @param string $unXml the XML string
|
||||
* @param string $champ the node
|
||||
* @return string
|
||||
*/
|
||||
public static function getChamp($unXml, $champ, $attribut = false)
|
||||
{
|
||||
$ret = "";
|
||||
$sxe = simplexml_load_string($unXml);
|
||||
if ($sxe)
|
||||
{
|
||||
if ($attribut)
|
||||
{
|
||||
foreach ($sxe->$champ->attributes() as $a => $b)
|
||||
{
|
||||
if ($a == $attribut)
|
||||
{
|
||||
$ret.= $b;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$z = $sxe->xpath('/description/' . $champ);
|
||||
|
||||
if (!$z)
|
||||
$z = $sxe->xpath('/record/description/' . $champ);
|
||||
|
||||
if ($z && is_array($z))
|
||||
{
|
||||
$ret .= $z[0];
|
||||
}
|
||||
}
|
||||
}
|
||||
$ret = trim($ret);
|
||||
if ($ret == "" || $ret == null)
|
||||
$ret = "<i>" . _('report:: non-renseigne') . "</i>";
|
||||
|
||||
return $ret;
|
||||
}
|
||||
|
||||
public static function getPreff($sbasid)
|
||||
{
|
||||
$tab = array();
|
||||
$tab["struct"] = "";
|
||||
$tab['champs'] = array();
|
||||
|
||||
$databox = databox::get_instance((int) $sbasid);
|
||||
$tab['struct'] = $databox->get_structure();
|
||||
|
||||
$sxe = $databox->get_sxml_structure();
|
||||
if ($sxe)
|
||||
{
|
||||
$z = $sxe->xpath('/record/description');
|
||||
if ($z && is_array($z))
|
||||
{
|
||||
foreach ($z[0] as $ki => $vi)
|
||||
{
|
||||
foreach ($vi->attributes() as $a => $b)
|
||||
{
|
||||
if ($a == "report" && $b == 1)
|
||||
$tab['champs'][] = $ki;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $tab['champs'];
|
||||
}
|
||||
|
||||
public static function getHost($url)
|
||||
{
|
||||
$parse_url = parse_url(trim($url));
|
||||
$result = isset($parse_url['host']) ? $parse_url['host'] : array_shift(explode('/', $parse_url['path'], 2));
|
||||
|
||||
return trim($result);
|
||||
}
|
||||
|
||||
}
|
1188
lib/classes/module/report/activity.class.php
Normal file
1188
lib/classes/module/report/activity.class.php
Normal file
File diff suppressed because it is too large
Load Diff
148
lib/classes/module/report/add.class.php
Normal file
148
lib/classes/module/report/add.class.php
Normal file
@@ -0,0 +1,148 @@
|
||||
<?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 module_report
|
||||
* @license http://opensource.org/licenses/gpl-3.0 GPLv3
|
||||
* @link www.phraseanet.com
|
||||
*/
|
||||
class module_report_add extends module_report
|
||||
{
|
||||
|
||||
protected $cor_query = array(
|
||||
'user' => 'log.user',
|
||||
'site' => 'log.site',
|
||||
'societe' => 'log.societe',
|
||||
'pays' => 'log.pays',
|
||||
'activite' => 'log.activite',
|
||||
'fonction' => 'log.fonction',
|
||||
'usrid' => 'log.usrid',
|
||||
'getter' => 'd.final',
|
||||
'date' => "DATE(d.date)",
|
||||
'id' => 'd.id',
|
||||
'log_id' => 'd.log_id',
|
||||
'record_id' => 'd.record_id',
|
||||
'final' => 'd.final',
|
||||
'comment' => 'd.comment',
|
||||
'size' => 's.size'
|
||||
);
|
||||
|
||||
/**
|
||||
* constructor
|
||||
*
|
||||
* @name download::__construct()
|
||||
* @param $arg1 start date of the report
|
||||
* @param $arg2 end date of the report
|
||||
* @param $sbas_id id of the databox
|
||||
*/
|
||||
public function __construct($arg1, $arg2, $sbas_id, $collist)
|
||||
{
|
||||
parent::__construct($arg1, $arg2, $sbas_id, $collist);
|
||||
$this->title = _('report:: document ajoute');
|
||||
}
|
||||
|
||||
/**
|
||||
* @desc build the specified requete
|
||||
* @param $obj $conn the current connection to databox
|
||||
* @return string
|
||||
*/
|
||||
protected function buildReq($groupby = false, $on = false)
|
||||
{
|
||||
$s = $this->sqlBuilder('action')->setGroupBy($groupby)->setOn($on)
|
||||
->setAction('add')->buildSql();
|
||||
$this->req = $s->getSql();
|
||||
$this->params = $s->getParams();
|
||||
$this->total = $s->getTotalRows();
|
||||
}
|
||||
|
||||
public function colFilter($field, $on = false)
|
||||
{
|
||||
$s = $this->sqlBuilder('action')->setAction('add');
|
||||
$var = $s->sqlDistinctValByField($field);
|
||||
$sql = $var['sql'];
|
||||
$params = $var['params'];
|
||||
$stmt = $s->getConnBas()->prepare($sql);
|
||||
$stmt->execute($params);
|
||||
$rs = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
||||
$stmt->closeCursor();
|
||||
|
||||
$ret = array();
|
||||
|
||||
$appbox = appbox::get_instance();
|
||||
|
||||
foreach ($rs as $row)
|
||||
{
|
||||
$value = $row['val'];
|
||||
$caption = $value;
|
||||
if ($field == "getter")
|
||||
{
|
||||
try
|
||||
{
|
||||
$user = User_Adapter::getInstance($value, $appbox);
|
||||
$caption = $user->get_display_name();
|
||||
}
|
||||
catch (Exception $e)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
elseif ($field == 'date')
|
||||
$caption = phraseadate::getPrettyString(new DateTime($value));
|
||||
elseif ($field == 'size')
|
||||
$caption = p4string::format_octets($value);
|
||||
|
||||
$ret[] = array('val' => $caption, 'value' => $value);
|
||||
}
|
||||
|
||||
return $ret;
|
||||
}
|
||||
|
||||
protected function buildResult($rs)
|
||||
{
|
||||
$i = 0;
|
||||
$pref = parent::getPreff($this->sbas_id);
|
||||
foreach ($rs as $row)
|
||||
{
|
||||
foreach ($this->champ as $key => $value)
|
||||
{
|
||||
if ($row[$value])
|
||||
{
|
||||
if ($value == 'date')
|
||||
{
|
||||
$this->result[$i][$value] = $this->pretty_string ? phraseadate::getPrettyString(new DateTime($row[$value])) : $row[$value];
|
||||
}
|
||||
elseif ($value == 'size')
|
||||
{
|
||||
$this->result[$i][$value] = p4string::format_octets($row[$value]);
|
||||
}
|
||||
else
|
||||
$this->result[$i][$value] = $row[$value];
|
||||
}
|
||||
else
|
||||
{
|
||||
if ($value == 'comment')
|
||||
{
|
||||
$this->result[$i][$value] = ' ';
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->result[$i][$value] = '<i>' . _('report:: non-renseigne') . '</i>';
|
||||
}
|
||||
}
|
||||
}
|
||||
$i++;
|
||||
if ($i >= $this->nb_record)
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
199
lib/classes/module/report/connexion.class.php
Normal file
199
lib/classes/module/report/connexion.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 module_report
|
||||
* @license http://opensource.org/licenses/gpl-3.0 GPLv3
|
||||
* @link www.phraseanet.com
|
||||
*/
|
||||
class module_report_connexion extends module_report
|
||||
{
|
||||
|
||||
protected $cor_query = array(
|
||||
'user' => 'log.user'
|
||||
, 'usrid' => 'log.usrid'
|
||||
, 'ddate' => 'log.date'
|
||||
, 'societe' => 'log.societe'
|
||||
, 'pays' => 'log.pays'
|
||||
, 'activite' => 'log.activite'
|
||||
, 'fonction' => 'log.fonction'
|
||||
, 'site' => 'log.site'
|
||||
, 'sit_session' => 'log.sit_session'
|
||||
, 'coll_list' => 'log.coll_list'
|
||||
, 'appli' => 'log.appli'
|
||||
, 'ip' => 'log.ip'
|
||||
);
|
||||
|
||||
/**
|
||||
* constructor
|
||||
*
|
||||
* @name connexion::__construct()
|
||||
* @param $arg1 start date of the report
|
||||
* @param $arg2 end date of the report
|
||||
* @param $sbas_id id of the databox
|
||||
*/
|
||||
public function __construct($arg1, $arg2, $sbas_id, $collist)
|
||||
{
|
||||
parent::__construct($arg1, $arg2, $sbas_id, $collist);
|
||||
$this->title = _('report::Connexions');
|
||||
}
|
||||
|
||||
/**
|
||||
* @desc build the specified requete
|
||||
* @param $obj $conn the current connection to databox
|
||||
* @return string
|
||||
*/
|
||||
protected function buildReq($groupby = false)
|
||||
{
|
||||
$sql = $this->sqlBuilder('connexion');
|
||||
$sql = $sql->setGroupBy($groupby);
|
||||
$sql = $sql->buildSql();
|
||||
$this->req = $sql->getSql();
|
||||
$this->params = $sql->getParams();
|
||||
$this->total = $sql->getTotalRows();
|
||||
}
|
||||
|
||||
/**
|
||||
* @desc build the list with all distinct result
|
||||
* @param string $field the field from the request displayed in a array
|
||||
* @return string $liste
|
||||
*/
|
||||
public function colFilter($field)
|
||||
{
|
||||
$ret = array();
|
||||
$s = $this->sqlBuilder('connexion');
|
||||
$var = $s->sqlDistinctValByField($field);
|
||||
$sql = $var['sql'];
|
||||
$params = $var['params'];
|
||||
|
||||
$stmt = $s->getConnBas()->prepare($sql);
|
||||
$stmt->execute($params);
|
||||
$rs = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
||||
$stmt->closeCursor();
|
||||
|
||||
foreach ($rs as $row)
|
||||
{
|
||||
$value = $row['val'];
|
||||
if ($field == "appli")
|
||||
$caption = implode(' ', phrasea::modulesName(@unserialize($value)));
|
||||
elseif ($field == 'ddate')
|
||||
$caption = phraseadate::getPrettyString(new DateTime($value));
|
||||
else
|
||||
$caption = $row['val'];
|
||||
$ret[] = array('val' => $caption, 'value' => $value);
|
||||
}
|
||||
|
||||
return $ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* @desc build the result from the specified sql
|
||||
* @param array $champ all the field from the request displayed in a array
|
||||
* @param string $sql the request from buildreq
|
||||
* @return $this->result
|
||||
*/
|
||||
protected function buildResult($rs)
|
||||
{
|
||||
$i = 0;
|
||||
|
||||
foreach ($rs as $row)
|
||||
{
|
||||
if ($this->enable_limit && ($i > $this->nb_record))
|
||||
break;
|
||||
foreach ($this->champ as $key => $value)
|
||||
{
|
||||
if (!isset($row[$value]))
|
||||
{
|
||||
$this->result[$i][$value] = '<i>' . _('report:: non-renseigne') . '</i>';
|
||||
continue;
|
||||
}
|
||||
|
||||
if ($value == 'coll_list')
|
||||
{
|
||||
$coll = explode(",", $row[$value]);
|
||||
$this->result[$i][$value] = "";
|
||||
foreach ($coll as $id)
|
||||
{
|
||||
if ($this->result[$i][$value] != "")
|
||||
{
|
||||
$this->result[$i][$value].= " / ";
|
||||
$this->result[$i][$value] .= phrasea::bas_names(phrasea::baseFromColl($this->sbas_id, $id));
|
||||
}
|
||||
elseif ($this->result[$i][$value] == "")
|
||||
{
|
||||
$this->result[$i][$value] = phrasea::bas_names(phrasea::baseFromColl($this->sbas_id, $id));
|
||||
}
|
||||
}
|
||||
}
|
||||
elseif ($value == 'appli')
|
||||
{
|
||||
$applis = false;
|
||||
if (($applis = @unserialize($row[$value])) !== false)
|
||||
{
|
||||
if (empty($applis))
|
||||
{
|
||||
$this->result[$i][$value] = '<i>' . _('report:: non-renseigne') . '</i>';
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->result[$i][$value] = implode(' ', phrasea::modulesName($applis));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->result[$i][$value] = '<i>' . _('report:: non-renseigne') . '</i>';
|
||||
}
|
||||
}
|
||||
elseif ($value == 'ddate')
|
||||
{
|
||||
$this->result[$i][$value] = $this->pretty_string ?
|
||||
phraseadate::getPrettyString(new DateTime($row[$value])) :
|
||||
$row[$value];
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->result[$i][$value] = $row[$value];
|
||||
}
|
||||
}
|
||||
$i++;
|
||||
}
|
||||
}
|
||||
|
||||
public static function getNbConn($dmin, $dmax, $sbas_id, $list_coll_id)
|
||||
{
|
||||
$conn = connection::getPDOConnection($sbas_id);
|
||||
$registry = registry::get_instance();
|
||||
|
||||
$datefilter = module_report_sqlfilter::constructDateFilter($dmin, $dmax);
|
||||
$collfilter = module_report_sqlfilter::constructCollectionFilter($list_coll_id);
|
||||
|
||||
$params = array(':site_id' => $registry->get('GV_sit'));
|
||||
$params = array_merge($params, $datefilter['params'], $collfilter['params']);
|
||||
|
||||
$finalfilter = $datefilter['sql'] . ' AND ';
|
||||
$finalfilter .= '(' . $collfilter['sql'] . ') AND ';
|
||||
$finalfilter .= 'log_date.site = :site_id';
|
||||
|
||||
$sql = "SELECT COUNT(usrid) as nb
|
||||
FROM log as log_date
|
||||
WHERE " . $finalfilter;
|
||||
|
||||
$stmt = $conn->prepare($sql);
|
||||
$stmt->execute($params);
|
||||
$row = $stmt->fetch(PDO::FETCH_ASSOC);
|
||||
$stmt->closeCursor();
|
||||
|
||||
return (int) $row['nb'];
|
||||
}
|
||||
|
||||
}
|
||||
|
367
lib/classes/module/report/dashboard.class.php
Normal file
367
lib/classes/module/report/dashboard.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 module_report
|
||||
* @license http://opensource.org/licenses/gpl-3.0 GPLv3
|
||||
* @link www.phraseanet.com
|
||||
*/
|
||||
class module_report_dashboard implements module_report_dashboard_componentInterface
|
||||
{
|
||||
|
||||
/**
|
||||
* objet user
|
||||
* @var user
|
||||
*/
|
||||
public $usr;
|
||||
|
||||
/**
|
||||
* @la date mini du report
|
||||
* @var <string>
|
||||
*/
|
||||
public $dmin;
|
||||
|
||||
/**
|
||||
* @desc la date maxi du report
|
||||
* @var <string>
|
||||
*/
|
||||
public $dmax;
|
||||
|
||||
/**
|
||||
* @desc le tableau qui contient toutes les collections ou l'utilisateur
|
||||
* a le droit de report
|
||||
* @var <array>
|
||||
*/
|
||||
public $authorizedCollection = array();
|
||||
|
||||
/**
|
||||
* @desc le tableau qui contient le dashboard
|
||||
* @var <array>
|
||||
*/
|
||||
public $dashboard = array();
|
||||
|
||||
/**
|
||||
* @des le nombre par defaut de resultats afficher par categorie
|
||||
* @var <int>
|
||||
*/
|
||||
public $nbtop = 10;
|
||||
|
||||
/**
|
||||
* @desc la periode par defaut d'affichage du dashboard
|
||||
* @var <string>
|
||||
*/
|
||||
public $periode = '-1 month';
|
||||
|
||||
/**
|
||||
* @desc le sbasid de la base ou on effectue le report
|
||||
* @var <int>
|
||||
*/
|
||||
public $sbasid;
|
||||
|
||||
/**
|
||||
* @desc Construit un dashboard selon les droits du usrid, si sbas vaut null
|
||||
* c'est un report sur toutes les bases, sinon sur le sbasid
|
||||
* @param <int> $usrid
|
||||
* @param <int> $sbasid
|
||||
*/
|
||||
public function __construct($usr, $sbasid = null)
|
||||
{
|
||||
$this->usr = $usr;
|
||||
if (is_null($sbasid))
|
||||
$this->sbasid = 'all';
|
||||
else
|
||||
$this->sbasid = $sbasid;
|
||||
$this->initDate();
|
||||
$this->setAuthCollection();
|
||||
$this->getPlotLegendDay($this->dmin);
|
||||
}
|
||||
|
||||
/**
|
||||
* @desc genere le report
|
||||
* @return dashboard_main
|
||||
*/
|
||||
public function execute()
|
||||
{
|
||||
$this->setReport();
|
||||
$this->process();
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @desc modifier les date du report
|
||||
* @param Datetime $dmin
|
||||
* @param Datetime $dmax
|
||||
* @return <void>
|
||||
*/
|
||||
public function setDate($dmin, $dmax)
|
||||
{
|
||||
$dmin = new Datetime($dmin);
|
||||
$dmax = new Datetime($dmax);
|
||||
|
||||
$dmax->modify('+23 hours +59 minutes +59 seconds');
|
||||
|
||||
$this->dmax = $dmax->format('d-m-Y');
|
||||
$this->dmin = $dmin->format('d-m-Y');
|
||||
|
||||
$this->getPlotLegendDay($this->dmin, $this->dmax);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
* @desc return la liste des collection authoriséee
|
||||
* @return <array>
|
||||
*/
|
||||
public function authorizedCollection()
|
||||
{
|
||||
return $this->authorizedCollection;
|
||||
}
|
||||
|
||||
/**
|
||||
* @desc return le titre de la date
|
||||
* @param <string> $d vaut 'dmin' ou 'dmax'
|
||||
* @return <string>
|
||||
*/
|
||||
public function getTitleDate($d)
|
||||
{
|
||||
if ($d == 'dmax')
|
||||
{
|
||||
$datetime = new Datetime($this->dmax);
|
||||
|
||||
return phraseadate::getPrettyString($datetime);
|
||||
}
|
||||
elseif ($d == 'dmin')
|
||||
{
|
||||
$datetime = new Datetime($this->dmin);
|
||||
|
||||
return phraseadate::getPrettyString($datetime);
|
||||
}
|
||||
else
|
||||
throw new Exception('argument must be string dmin or dmax');
|
||||
}
|
||||
|
||||
/**
|
||||
* @desc check if a dashboard is valid
|
||||
* @return <bool>
|
||||
*/
|
||||
public function isValid()
|
||||
{
|
||||
if (isset($this->dashboard) && sizeof($this->dashboard) > 0)
|
||||
return true;
|
||||
else
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @desc return le dashboard
|
||||
* @return <array>
|
||||
*/
|
||||
public function getDash()
|
||||
{
|
||||
return $this->dashboard;
|
||||
}
|
||||
|
||||
/**
|
||||
* @desc construct the legend for charts
|
||||
* if dmax === false dmax = now();
|
||||
* @param <Datetime> $dmin
|
||||
* @param <Datetime> $dmax
|
||||
* @return <void>
|
||||
*/
|
||||
protected function getPlotLegendDay($dmin, $dmax = false)
|
||||
{
|
||||
if (!$dmax)
|
||||
{
|
||||
$date = new Datetime();
|
||||
$dmax = $date->format('d-m-Y');
|
||||
}
|
||||
else
|
||||
{
|
||||
$date = new Datetime($dmax);
|
||||
$dmax = $date->format('d-m-Y');
|
||||
}
|
||||
$this->legendDay[] = phraseadate::getPrettyString($date);
|
||||
|
||||
while ($dmin != $dmax)
|
||||
{
|
||||
$date->modify('-1 day');
|
||||
$dmax = $date->format('d-m-Y');
|
||||
$this->legendDay[] = phraseadate::getPrettyString($date);
|
||||
$this->nb_days++;
|
||||
}
|
||||
$this->legendDay = array_reverse($this->legendDay);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
* @desc merge tous les resultats dans dashboard
|
||||
* @return <void>
|
||||
*/
|
||||
public function process()
|
||||
{
|
||||
$tri = $this->group()->tri();
|
||||
$x = $tri->getDash();
|
||||
$a = $tri->top()->getTop($this->nbtop);
|
||||
$this->dashboard = array();
|
||||
foreach ($a as $k => $v)
|
||||
{
|
||||
if (array_key_exists($k, $x))
|
||||
{
|
||||
$x[$k] = $v;
|
||||
}
|
||||
}
|
||||
$this->dashboard = $x;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
* @desc init dmin and dmax
|
||||
* @return <void>
|
||||
*/
|
||||
protected function initDate()
|
||||
{
|
||||
$datetime = new Datetime();
|
||||
$this->dmax = $datetime->format('d-m-Y');
|
||||
$datetime->modify($this->periode);
|
||||
$this->dmin = $datetime->format('d-m-Y');
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
* @desc construit un array avec tous les collections ou l'utilisateur
|
||||
* a le droit de reporting
|
||||
* @return <array>
|
||||
*/
|
||||
public function getAllColl()
|
||||
{
|
||||
$all_coll = array();
|
||||
|
||||
$base_ids = $this->usr->ACL()->get_granted_base(array('canreport'));
|
||||
|
||||
foreach ($base_ids as $base_id => $collection)
|
||||
{
|
||||
$databox = $collection->get_databox();
|
||||
$sbas_id = $databox->get_sbas_id();
|
||||
if (!isset($all_coll[$sbas_id]))
|
||||
{
|
||||
$all_coll[$sbas_id] = array();
|
||||
$all_coll[$sbas_id]['name_sbas'] = $databox->get_viewname();
|
||||
}
|
||||
$all_coll[$sbas_id]['sbas_collections'][] = array(
|
||||
'base_id' => $base_id,
|
||||
'sbas_id' => $sbas_id,
|
||||
'coll_id' => $collection->get_base_id(),
|
||||
'name' => $collection->get_name()
|
||||
);
|
||||
}
|
||||
|
||||
return $all_coll;
|
||||
}
|
||||
|
||||
/**
|
||||
* @des set authorizedCollection
|
||||
* @return <void>
|
||||
*/
|
||||
protected function setAuthCollection()
|
||||
{
|
||||
$all_coll = $this->getAllColl();
|
||||
|
||||
foreach ($all_coll as $sbas => $info)
|
||||
{
|
||||
$listeColl = array();
|
||||
|
||||
foreach ($info['sbas_collections'] as $key => $value)
|
||||
{
|
||||
$listeColl[] = (int) $value['coll_id'];
|
||||
}
|
||||
|
||||
$this->authorizedCollection[] = array(
|
||||
'sbas_id' => (int) $sbas,
|
||||
'coll' => implode(',', $listeColl),
|
||||
'name' => phrasea::sbas_names($sbas)
|
||||
);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
* @desc la liste des base authorisee sous forme de string
|
||||
* @param <string> $separotor
|
||||
* @return string
|
||||
*/
|
||||
public function getListeBase($separator)
|
||||
{
|
||||
$all_coll = $this->getAllColl();
|
||||
$liste = '';
|
||||
foreach ($all_coll as $sbas => $info)
|
||||
{
|
||||
$liste .= phrasea::sbas_names($sbas) . ' ' . $separator . ' ';
|
||||
}
|
||||
|
||||
return $liste;
|
||||
}
|
||||
|
||||
/**
|
||||
* @desc Foreach authorized collection, fill the dashboard
|
||||
* with an object dashboard
|
||||
* @return <void>
|
||||
*/
|
||||
protected function setReport()
|
||||
{
|
||||
$i = 0;
|
||||
foreach ($this->authorizedCollection as $key => $value)
|
||||
{
|
||||
$sbasid = $value['sbas_id'];
|
||||
$coll = $value['coll'];
|
||||
try
|
||||
{
|
||||
if ($this->sbasid != "all")
|
||||
{
|
||||
if ($this->sbasid == $sbasid)
|
||||
{
|
||||
$this->dashboard[$sbasid] = module_report_dashboard_feed::getInstance(
|
||||
$sbasid, $coll, $this->dmin, $this->dmax
|
||||
);
|
||||
break;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->dashboard[$sbasid] = module_report_dashboard_feed::getInstance(
|
||||
$sbasid, $coll, $this->dmin, $this->dmax
|
||||
);
|
||||
}
|
||||
}
|
||||
catch (Exception $e)
|
||||
{
|
||||
|
||||
}
|
||||
$i++;
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return dashboard_group
|
||||
*/
|
||||
public function group()
|
||||
{
|
||||
return new module_report_dashboard_group($this);
|
||||
}
|
||||
|
||||
}
|
@@ -0,0 +1,25 @@
|
||||
<?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 module_report
|
||||
* @license http://opensource.org/licenses/gpl-3.0 GPLv3
|
||||
* @link www.phraseanet.com
|
||||
*/
|
||||
interface module_report_dashboard_componentInterface
|
||||
{
|
||||
public function process();
|
||||
|
||||
public function getDash();
|
||||
|
||||
public function isValid();
|
||||
}
|
283
lib/classes/module/report/dashboard/feed.class.php
Normal file
283
lib/classes/module/report/dashboard/feed.class.php
Normal file
@@ -0,0 +1,283 @@
|
||||
<?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 module_report
|
||||
* @license http://opensource.org/licenses/gpl-3.0 GPLv3
|
||||
* @link www.phraseanet.com
|
||||
*/
|
||||
class module_report_dashboard_feed implements module_report_dashboard_componentInterface
|
||||
{
|
||||
|
||||
/**
|
||||
* @desc la date mini des resultats
|
||||
* @var <string>
|
||||
*/
|
||||
public $dmin;
|
||||
/**
|
||||
* @desc la date maxi des resultats
|
||||
* @var <string>
|
||||
*/
|
||||
public $dmax;
|
||||
/**
|
||||
* @desc version sql de la date mini
|
||||
* @var <string>
|
||||
*/
|
||||
public $dminsql;
|
||||
/**
|
||||
* @desc version sql de la date maxi
|
||||
* @var <string>
|
||||
*/
|
||||
public $dmaxsql;
|
||||
/**
|
||||
* @desc le sbasid de la base sur lequel on effectue les requetes
|
||||
* @var <int>
|
||||
*/
|
||||
public $sbasid;
|
||||
/**
|
||||
* @la liste des collections séparés par une virgule
|
||||
* sur laquelle on effectue les requetes
|
||||
* @var <string>
|
||||
*/
|
||||
public $collection;
|
||||
/**
|
||||
* @desc le tableau qui contien les resultats
|
||||
* @var <array>
|
||||
*/
|
||||
public $report = array();
|
||||
|
||||
/**
|
||||
* @desc return l'objet stockee dans le cache si i l existe sinon instancie
|
||||
* un nouveau objet dashboard_feed
|
||||
* @param <int> $sbasid
|
||||
* @param <string> $sbas_coll
|
||||
* @param <string> $dmin
|
||||
* @param <string> $dmax
|
||||
* @return self
|
||||
*/
|
||||
public static function getInstance($sbasid, $sbas_coll, $dmin, $dmax)
|
||||
{
|
||||
$appbox = appbox::get_instance();
|
||||
$cache_id = 'feed_' . md5($sbasid . '_' . $sbas_coll . '_' . $dmin . '_' . $dmax);
|
||||
|
||||
try
|
||||
{
|
||||
return $appbox->get_data_from_cache($cache_id);
|
||||
}
|
||||
catch (Exception $e)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
$tmp = new self($sbasid, $sbas_coll, $dmin, $dmax);
|
||||
|
||||
$appbox->set_data_to_cache($tmp, $cache_id);
|
||||
|
||||
return $tmp;
|
||||
}
|
||||
|
||||
/**
|
||||
* @desc Remplis les resultats bruts pour valeures passees en param
|
||||
* @param <int> $sbasid
|
||||
* @param <string> $sbas_collection, les collection sous forme de string
|
||||
* séparés par une virgule
|
||||
* @param <string> $dmin, Y-m-d
|
||||
* @param <string> $dmax, Y-m-d
|
||||
*/
|
||||
public function __construct($sbasid, $sbas_collection, $dmin, $dmax)
|
||||
{
|
||||
$conn = connection::getPDOConnection($sbasid);
|
||||
$this->dmin = $dmin;
|
||||
$this->dmax = $dmax;
|
||||
$this->dminsql = $this->dateToSqlDate('dmin');
|
||||
$this->dmaxsql = $this->dateToSqlDate('dmax');
|
||||
$this->sbasid = $sbasid;
|
||||
$this->collection = $sbas_collection;
|
||||
$this->process();
|
||||
}
|
||||
|
||||
/**
|
||||
* @desc return les date dormate pour les requetes sql;
|
||||
* @param <string> $d, vaut 'dmin' ou 'dmax'
|
||||
* @return Datetime
|
||||
*/
|
||||
private function dateToSqlDate($d)
|
||||
{
|
||||
if ($d == 'dmax')
|
||||
{
|
||||
$datetime = new Datetime($this->dmax);
|
||||
|
||||
return phraseadate::format_mysql($datetime);
|
||||
}
|
||||
elseif ($d == 'dmin')
|
||||
{
|
||||
$datetime = new Datetime($this->dmin);
|
||||
|
||||
return phraseadate::format_mysql($datetime);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @desc fill the dash results for the current sbas
|
||||
* @return <void>
|
||||
*/
|
||||
public function process()
|
||||
{
|
||||
try
|
||||
{
|
||||
//Get number of DLs
|
||||
$this->report['nb_dl'] = module_report_download::getNbDl(
|
||||
$this->dminsql,
|
||||
$this->dmaxsql,
|
||||
$this->sbasid,
|
||||
$this->collection
|
||||
);
|
||||
//Get Number of connexions
|
||||
$this->report['nb_conn'] = module_report_connexion::getNbConn(
|
||||
$this->dminsql,
|
||||
$this->dmaxsql,
|
||||
$this->sbasid,
|
||||
$this->collection
|
||||
);
|
||||
$registry = registry::get_instance();
|
||||
if ($registry->get('GV_anonymousReport') == false)
|
||||
{
|
||||
/**
|
||||
* get Top ten user of
|
||||
* number of dl doc, prev
|
||||
* number of weight dl by doc, prev
|
||||
*/
|
||||
$top = module_report_activity::topTenUser(
|
||||
$this->dminsql,
|
||||
$this->dmaxsql,
|
||||
$this->sbasid,
|
||||
$this->collection
|
||||
);
|
||||
|
||||
$this->report['top_ten_user_doc'] = $top['top_ten_doc'];
|
||||
$this->report['top_ten_user_prev'] = $top['top_ten_prev'];
|
||||
$this->report['top_ten_user_poiddoc'] = $top['top_ten_poiddoc'];
|
||||
$this->report['top_ten_user_poidprev'] = $top['top_ten_poidprev'];
|
||||
}
|
||||
|
||||
/**
|
||||
* get avtivity by hour
|
||||
*/
|
||||
$this->report['activity'] = module_report_activity::activity(
|
||||
$this->dminsql,
|
||||
$this->dmaxsql,
|
||||
$this->sbasid,
|
||||
$this->collection
|
||||
);
|
||||
|
||||
// get activty by day
|
||||
$this->report['activity_day'] = module_report_activity::activityDay(
|
||||
$this->dminsql,
|
||||
$this->dmaxsql,
|
||||
$this->sbasid,
|
||||
$this->collection
|
||||
);
|
||||
// get Most document and preview DL
|
||||
$topdl = module_report_download::getTopDl(
|
||||
$this->dminsql,
|
||||
$this->dmaxsql,
|
||||
$this->sbasid,
|
||||
$this->collection
|
||||
);
|
||||
|
||||
$this->report['top_dl_preview'] = $topdl['preview'];
|
||||
$this->report['top_dl_document'] = $topdl['document'];
|
||||
|
||||
if ($registry->get('GV_anonymousReport') == false)
|
||||
{
|
||||
// get users that ask the most questions
|
||||
$this->report['ask'] = module_report_activity::activityQuestion(
|
||||
$this->dminsql,
|
||||
$this->dmaxsql,
|
||||
$this->sbasid,
|
||||
$this->collection
|
||||
);
|
||||
}
|
||||
//get the refferer
|
||||
$this->report['top_ten_site'] = module_report_activity::activiteTopTenSiteView(
|
||||
$this->dminsql,
|
||||
$this->dmaxsql,
|
||||
$this->sbasid,
|
||||
$this->collection
|
||||
);
|
||||
//Get the most asked questions
|
||||
$this->report['top_ten_question'] = module_report_activity::activiteTopQuestion(
|
||||
$this->dminsql,
|
||||
$this->dmaxsql,
|
||||
$this->sbasid,
|
||||
$this->collection
|
||||
);
|
||||
|
||||
//get the number of added docuùments
|
||||
$this->report['activity_added'] = module_report_activity::activiteAddedDocument(
|
||||
$this->dminsql,
|
||||
$this->dmaxsql,
|
||||
$this->sbasid,
|
||||
$this->collection
|
||||
);
|
||||
|
||||
//get number of edited document
|
||||
$this->report['activity_edited'] = module_report_activity::activiteEditedDocument(
|
||||
$this->dminsql,
|
||||
$this->dmaxsql,
|
||||
$this->sbasid,
|
||||
$this->collection
|
||||
);
|
||||
if ($registry->get('GV_anonymousReport') == false)
|
||||
{
|
||||
//get users that add the most documents
|
||||
$this->report['top_ten_added'] = module_report_activity::activiteAddedTopTenUser(
|
||||
$this->dminsql,
|
||||
$this->dmaxsql,
|
||||
$this->sbasid,
|
||||
$this->collection
|
||||
);
|
||||
}
|
||||
}
|
||||
catch(PDOException $e)
|
||||
{
|
||||
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
* @desc return variable that contains the results
|
||||
* @return <array>
|
||||
*/
|
||||
public function getDash()
|
||||
{
|
||||
return $this->report;
|
||||
}
|
||||
|
||||
/**
|
||||
* @desc check if the results are valid
|
||||
* @return <bool>
|
||||
*/
|
||||
public function isValid()
|
||||
{
|
||||
if (isset($this->report) && sizeof($this->report) > 0)
|
||||
|
||||
return true;
|
||||
else
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
109
lib/classes/module/report/dashboard/group.class.php
Normal file
109
lib/classes/module/report/dashboard/group.class.php
Normal file
@@ -0,0 +1,109 @@
|
||||
<?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 module_report
|
||||
* @license http://opensource.org/licenses/gpl-3.0 GPLv3
|
||||
* @link www.phraseanet.com
|
||||
*/
|
||||
class module_report_dashboard_group implements module_report_dashboard_componentInterface
|
||||
{
|
||||
|
||||
public $group_dash;
|
||||
public $dashboard = array();
|
||||
private $valid = false;
|
||||
|
||||
/**
|
||||
* @desc group the dashboard
|
||||
*/
|
||||
public function __construct(module_report_dashboard $report)
|
||||
{
|
||||
if ($report->isValid())
|
||||
{
|
||||
$this->valid = true;
|
||||
$this->dashboard = $report->getDash();
|
||||
}
|
||||
$this->process();
|
||||
}
|
||||
|
||||
/**
|
||||
* @desc GROUP the dashboard
|
||||
* @return <void>
|
||||
*/
|
||||
public function process()
|
||||
{
|
||||
if ($this->valid)
|
||||
{
|
||||
if (is_null($this->group_dash))
|
||||
$this->group_dash = array();
|
||||
foreach ($this->dashboard as $key => $dash)
|
||||
{
|
||||
if (is_object($dash) &&
|
||||
$dash instanceof module_report_dashboard_feed &&
|
||||
$dash->isValid())
|
||||
{
|
||||
$onedash = $dash->getDash();
|
||||
foreach ($onedash as $typeofreport => $value)
|
||||
{
|
||||
if (is_array($value) && sizeof($value) == 0)
|
||||
continue;
|
||||
else
|
||||
{
|
||||
$this->group_dash[$typeofreport][] = $value;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new Exception("cannot group on a none dashboard object");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
* @desc check if the grouped dash is valid
|
||||
* @return <bool>
|
||||
*/
|
||||
public function isValid()
|
||||
{
|
||||
if (isset($this->group_dash) && sizeof($this->group_dash) > 0)
|
||||
|
||||
return true;
|
||||
else
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @desc return the results
|
||||
* @return <array>
|
||||
*/
|
||||
public function getDash()
|
||||
{
|
||||
return $this->group_dash;
|
||||
}
|
||||
|
||||
/**
|
||||
* @desc Tri de grouped dash
|
||||
* @return dashboard_merge
|
||||
*/
|
||||
public function tri()
|
||||
{
|
||||
return new module_report_dashboard_merge($this);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
221
lib/classes/module/report/dashboard/merge.class.php
Normal file
221
lib/classes/module/report/dashboard/merge.class.php
Normal file
@@ -0,0 +1,221 @@
|
||||
<?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 module_report
|
||||
* @license http://opensource.org/licenses/gpl-3.0 GPLv3
|
||||
* @link www.phraseanet.com
|
||||
*/
|
||||
class module_report_dashboard_merge implements module_report_dashboard_componentInterface
|
||||
{
|
||||
|
||||
public $sort = array();
|
||||
public $sorted = array();
|
||||
private $currentkey;
|
||||
private $valid = false;
|
||||
|
||||
/**
|
||||
* @desc tri le dashboard
|
||||
* @param dashboard_group $dash_organize
|
||||
*/
|
||||
public function __construct(module_report_dashboard_group $dash_organize)
|
||||
{
|
||||
if ($dash_organize->isValid())
|
||||
{
|
||||
$this->valid = true;
|
||||
$this->sort = $dash_organize->getDash();
|
||||
}
|
||||
$this->process();
|
||||
}
|
||||
|
||||
/**
|
||||
* @des main function execute the process of triage
|
||||
* @return <void>
|
||||
*/
|
||||
public function process()
|
||||
{
|
||||
if ($this->valid)
|
||||
{
|
||||
foreach ($this->sort as $key => $value)
|
||||
{
|
||||
$this->currentkey = $key;
|
||||
switch ($this->currentkey)
|
||||
{
|
||||
case "nb_conn":
|
||||
$this->sum();
|
||||
break;
|
||||
case "nb_dl":
|
||||
$this->sum();
|
||||
break;
|
||||
case "activity":
|
||||
$this->triActivity();
|
||||
$this->toString();
|
||||
break;
|
||||
case "activity_day":
|
||||
$this->triActivity();
|
||||
$this->toString();
|
||||
break;
|
||||
case "activity_edited":
|
||||
$this->triActivity();
|
||||
$this->toString();
|
||||
break;
|
||||
case "activity_added":
|
||||
$this->triActivity();
|
||||
$this->toString();
|
||||
break;
|
||||
case "top_ten_user_doc":
|
||||
$this->triTopTen();
|
||||
break;
|
||||
case "top_ten_user_prev":
|
||||
$this->triTopTen();
|
||||
break;
|
||||
case "top_ten_user_poiddoc":
|
||||
$this->triTopTen();
|
||||
break;
|
||||
case "top_ten_user_poidprev":
|
||||
$this->triTopTen();
|
||||
break;
|
||||
case "top_dl_preview":
|
||||
$this->triTopTen();
|
||||
break;
|
||||
case "top_dl_document":
|
||||
$this->triTopTen();
|
||||
break;
|
||||
case "top_ten_question":
|
||||
$this->triTopTen();
|
||||
break;
|
||||
case "ask":
|
||||
$this->triTopTen();
|
||||
break;
|
||||
case "top_ten_site":
|
||||
$this->triTopTen();
|
||||
break;
|
||||
case "top_ten_added":
|
||||
$this->triTopTen();
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return le dashboard trie
|
||||
* @return <type>
|
||||
*/
|
||||
public function getDash()
|
||||
{
|
||||
return $this->sorted;
|
||||
}
|
||||
|
||||
/**
|
||||
* @desc check si les resultats sont valides
|
||||
* @return <bool>
|
||||
*/
|
||||
public function isValid()
|
||||
{
|
||||
if (isset($this->sorted) && sizeof($this->sorted) > 0)
|
||||
|
||||
return true;
|
||||
else
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return <void>
|
||||
*/
|
||||
private function sum()
|
||||
{
|
||||
$this->sorted[$this->currentkey] = 0;
|
||||
foreach ($this->sort[$this->currentkey] as $k => $v)
|
||||
$this->sorted[$this->currentkey] += $v;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
* @desc Tri all result of activity type
|
||||
* @return <void>
|
||||
*/
|
||||
private function triActivity()
|
||||
{
|
||||
foreach ($this->sort[$this->currentkey] as $sbas => $val)
|
||||
{
|
||||
foreach ($val as $key => $value)
|
||||
{
|
||||
|
||||
isset($this->sorted[$this->currentkey][$key]) ?
|
||||
$this->sorted[$this->currentkey][$key] += $value :
|
||||
$this->sorted[$this->currentkey][$key] = $value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @desc force value to string values
|
||||
* this is the format to respect for displaying float results in
|
||||
* SVG google charts
|
||||
*
|
||||
* @return void;
|
||||
*/
|
||||
private function toString()
|
||||
{
|
||||
foreach ($this->sorted[$this->currentkey] as $k => $v)
|
||||
$this->sorted[$this->currentkey][$k] =
|
||||
(string) number_format($v, 2, '.', '');
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
* @desc tri all result of top ten type
|
||||
* @return void
|
||||
*/
|
||||
private function triTopTen()
|
||||
{
|
||||
foreach ($this->sort[$this->currentkey] as $sbas => $val)
|
||||
{
|
||||
foreach ($val as $id => $info)
|
||||
{
|
||||
foreach ($info as $k => $v)
|
||||
{
|
||||
if (is_int($v) || is_float($v))
|
||||
isset($this->sorted[$this->currentkey][$id][$k]) ?
|
||||
$this->sorted[$this->currentkey][$id][$k] += $v :
|
||||
$this->sorted[$this->currentkey][$id][$k] = $v;
|
||||
elseif (is_string($v))
|
||||
$this->sorted[$this->currentkey][$id][$k] = $v;
|
||||
else
|
||||
$this->sorted[$this->currentkey][$id][$k] = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
* @desc get only the number of result we wants
|
||||
* @return dashboard_order
|
||||
*/
|
||||
public function top()
|
||||
{
|
||||
return new module_report_dashboard_sort($this);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
190
lib/classes/module/report/dashboard/sort.class.php
Normal file
190
lib/classes/module/report/dashboard/sort.class.php
Normal file
@@ -0,0 +1,190 @@
|
||||
<?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 module_report
|
||||
* @license http://opensource.org/licenses/gpl-3.0 GPLv3
|
||||
* @link www.phraseanet.com
|
||||
*/
|
||||
class module_report_dashboard_sort implements module_report_dashboard_componentInterface
|
||||
{
|
||||
|
||||
public $arrayToSort = array();
|
||||
public $arraySorted = array();
|
||||
|
||||
public function __construct(module_report_dashboard_merge $tridash)
|
||||
{
|
||||
if ($tridash->isValid())
|
||||
{
|
||||
$this->arrayToSort = $tridash->getDash();
|
||||
}
|
||||
$this->process();
|
||||
}
|
||||
|
||||
public function process()
|
||||
{
|
||||
foreach ($this->arrayToSort as $key => $value)
|
||||
{
|
||||
switch ($key)
|
||||
{
|
||||
case "top_ten_user_doc":
|
||||
$this->arraySorted[$key] = $this->array_orderby(
|
||||
$this->arrayToSort[$key],
|
||||
'nb',
|
||||
SORT_DESC
|
||||
);
|
||||
break;
|
||||
case "top_ten_user_prev":
|
||||
$this->arraySorted[$key] = $this->array_orderby(
|
||||
$this->arrayToSort[$key],
|
||||
'nb',
|
||||
SORT_DESC
|
||||
);
|
||||
break;
|
||||
case "top_ten_user_poiddoc":
|
||||
$this->arraySorted[$key] = $this->array_orderby(
|
||||
$this->arrayToSort[$key],
|
||||
'nb',
|
||||
SORT_DESC
|
||||
);
|
||||
break;
|
||||
case "top_ten_user_poidprev":
|
||||
$this->arraySorted[$key] = $this->array_orderby(
|
||||
$this->arrayToSort[$key],
|
||||
'nb',
|
||||
SORT_DESC
|
||||
);
|
||||
break;
|
||||
case "top_dl_preview":
|
||||
$this->arraySorted[$key] = $this->array_orderby(
|
||||
$this->arrayToSort[$key],
|
||||
'nb',
|
||||
SORT_DESC
|
||||
);
|
||||
break;
|
||||
case "top_dl_document":
|
||||
$this->arraySorted[$key] = $this->array_orderby(
|
||||
$this->arrayToSort[$key],
|
||||
'nb',
|
||||
SORT_DESC
|
||||
);
|
||||
break;
|
||||
case "top_ten_question":
|
||||
$this->arraySorted[$key] = $this->array_orderby(
|
||||
$this->arrayToSort[$key],
|
||||
'nb',
|
||||
SORT_DESC
|
||||
);
|
||||
break;
|
||||
case "ask":
|
||||
$this->arraySorted[$key] = $this->array_orderby(
|
||||
$this->arrayToSort[$key],
|
||||
'nb',
|
||||
SORT_DESC
|
||||
);
|
||||
break;
|
||||
case "top_ten_site":
|
||||
$this->arraySorted[$key] = $this->array_orderby(
|
||||
$this->arrayToSort[$key],
|
||||
'nb',
|
||||
SORT_DESC
|
||||
);
|
||||
break;
|
||||
case "top_ten_added":
|
||||
$this->arraySorted[$key] = $this->array_orderby(
|
||||
$this->arrayToSort[$key],
|
||||
'nb',
|
||||
SORT_DESC
|
||||
);
|
||||
break;
|
||||
default;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @desc tri les tableaux en fonction des parametres qu'on lui passe c'est la
|
||||
* fonction array_multisort qui est appelée
|
||||
* p1 : le tableau a trier, p2: la clef du tableau sur lequel on effectue le
|
||||
* tri, p3 SORT_DESC ou SORT_ASC,
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
private function array_orderby()
|
||||
{
|
||||
//arguments
|
||||
$args = func_get_args();
|
||||
//data = first argument
|
||||
$data = array_shift($args);
|
||||
|
||||
foreach ($args as $n => $field)
|
||||
{
|
||||
if (is_string($field)) // = clef
|
||||
{
|
||||
$tmp = array();
|
||||
foreach ($data as $key => $row)
|
||||
$tmp[$key] = $row[$field];
|
||||
$args[$n] = &$tmp;
|
||||
}
|
||||
else
|
||||
$args[$n] = &$field;
|
||||
}
|
||||
$args[] = &$data;
|
||||
|
||||
call_user_func_array("array_multisort", $args);
|
||||
|
||||
return array_pop($args);
|
||||
}
|
||||
|
||||
public function isValid()
|
||||
{
|
||||
if (isset($this->arraySorted) && sizeof($this->arraySorted) > 0)
|
||||
return true;
|
||||
else
|
||||
return false;
|
||||
}
|
||||
|
||||
public function getDash()
|
||||
{
|
||||
return $this->arraySorted;
|
||||
}
|
||||
|
||||
public function getTop($nbtop)
|
||||
{
|
||||
if (!is_int($nbtop))
|
||||
return array();
|
||||
|
||||
$tmp = array();
|
||||
|
||||
if ($this->isValid())
|
||||
{
|
||||
foreach ($this->arraySorted as $k => $v)
|
||||
{
|
||||
$i = 0;
|
||||
$tmp[$k] = array();
|
||||
foreach ($v as $a)
|
||||
{
|
||||
if ($i < $nbtop)
|
||||
array_push($tmp[$k], $a);
|
||||
else
|
||||
break;
|
||||
$i++;
|
||||
}
|
||||
}
|
||||
}
|
||||
return $tmp;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
281
lib/classes/module/report/download.class.php
Normal file
281
lib/classes/module/report/download.class.php
Normal file
@@ -0,0 +1,281 @@
|
||||
<?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 module_report
|
||||
* @license http://opensource.org/licenses/gpl-3.0 GPLv3
|
||||
* @link www.phraseanet.com
|
||||
*/
|
||||
class module_report_download extends module_report
|
||||
{
|
||||
|
||||
protected $cor_query = array(
|
||||
'user' => 'log.user',
|
||||
'site' => 'log.site',
|
||||
'societe' => 'log.societe',
|
||||
'pays' => 'log.pays',
|
||||
'activite' => 'log.activite',
|
||||
'fonction' => 'log.fonction',
|
||||
'usrid' => 'log.usrid',
|
||||
'coll_id' => 'record.coll_id',
|
||||
'xml' => 'record.xml',
|
||||
'ddate' => "log.date",
|
||||
'id' => 'log_docs.id',
|
||||
'log_id' => 'log_docs.log_id',
|
||||
'record_id' => 'log_docs.record_id',
|
||||
'final' => 'log_docs.final',
|
||||
'comment' => 'log_docs.comment',
|
||||
'size' => 'subdef.size',
|
||||
'mime' => 'subdef.mime',
|
||||
'file' => 'subdef.file'
|
||||
);
|
||||
|
||||
/**
|
||||
* constructor
|
||||
*
|
||||
* @name download::__construct()
|
||||
* @param $arg1 start date of the report
|
||||
* @param $arg2 end date of the report
|
||||
* @param $sbas_id id of the databox
|
||||
*/
|
||||
public function __construct($arg1, $arg2, $sbas_id, $collist)
|
||||
{
|
||||
parent::__construct($arg1, $arg2, $sbas_id, $collist);
|
||||
$this->title = _('report:: telechargements');
|
||||
}
|
||||
|
||||
/**
|
||||
* @desc build the specified requete
|
||||
* @param $obj $conn the current connection to databox
|
||||
* @return string
|
||||
*/
|
||||
protected function buildReq($groupby = false, $on = false)
|
||||
{
|
||||
$sql = $this->sqlBuilder('download')
|
||||
->setOn($on)->setGroupBy($groupby)->buildSql();
|
||||
|
||||
$this->req = $sql->getSql();
|
||||
$this->params = $sql->getParams();
|
||||
$this->total = $sql->getTotalRows();
|
||||
}
|
||||
|
||||
public function colFilter($field, $on = false)
|
||||
{
|
||||
$ret = array();
|
||||
$s = $this->sqlBuilder('download');
|
||||
$var = $s->sqlDistinctValByField($field);
|
||||
$sql = $var['sql'];
|
||||
$params = $var['params'];
|
||||
|
||||
$registry = registry::get_instance();
|
||||
|
||||
$stmt = $s->getConnBas()->prepare($sql);
|
||||
$stmt->execute($params);
|
||||
$rs = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
||||
$stmt->closeCursor();
|
||||
|
||||
foreach ($rs as $row)
|
||||
{
|
||||
$value = $row['val'];
|
||||
if ($field == 'coll_id')
|
||||
{
|
||||
$caption = phrasea::bas_names(phrasea::baseFromColl($this->sbas_id, $value));
|
||||
}
|
||||
elseif ($field == 'ddate')
|
||||
$caption = phraseadate::getPrettyString(new DateTime($value));
|
||||
elseif ($field == 'size')
|
||||
$caption = p4string::format_octets($value);
|
||||
else
|
||||
$caption = $value;
|
||||
$ret[] = array('val' => $caption, 'value' => $value);
|
||||
}
|
||||
|
||||
return $ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* @desc build the result from the specified sql
|
||||
* @param array $champ all the field from the request displayed in a array
|
||||
* @param string $sql the request from buildreq
|
||||
* @return $this->result
|
||||
*/
|
||||
protected function buildResult($rs)
|
||||
{
|
||||
$i = 0;
|
||||
$pref = parent::getPreff($this->sbas_id);
|
||||
|
||||
foreach ($rs as $row)
|
||||
{
|
||||
if ($this->enable_limit && ($i > $this->nb_record))
|
||||
break;
|
||||
foreach ($this->champ as $column)
|
||||
{
|
||||
$this->formatResult($column, $row[$column], $pref, $i);
|
||||
}
|
||||
$i++;
|
||||
}
|
||||
}
|
||||
|
||||
private function formatResult($column, $value, $pref, $i)
|
||||
{
|
||||
if ($value)
|
||||
{
|
||||
if ($column == 'coll_id')
|
||||
$this->result[$i][$column] = $this->formatCollId($value);
|
||||
elseif ($column == 'xml' && (sizeof($pref) > 0))
|
||||
{
|
||||
foreach ($pref as $field)
|
||||
{
|
||||
$this->result[$i][$field] = parent::getChamp($value, $field);
|
||||
}
|
||||
}
|
||||
elseif ($column == 'ddate')
|
||||
$this->result[$i][$column] = $this->formatDateValue($value);
|
||||
elseif ($column == 'size')
|
||||
$this->result[$i][$column] = p4string::format_octets($value);
|
||||
else
|
||||
$this->result[$i][$column] = $value;
|
||||
}
|
||||
else
|
||||
{
|
||||
if ($column == 'comment')
|
||||
$this->result[$i][$column] = '';
|
||||
else
|
||||
$this->result[$i][$column] = $this->formatEmptyValue();
|
||||
}
|
||||
}
|
||||
|
||||
private function formatEmptyValue()
|
||||
{
|
||||
return '<i>' . _('report:: non-renseigne') . '</i>';
|
||||
}
|
||||
|
||||
private function formatDateValue($value)
|
||||
{
|
||||
$datetime = new DateTime($value);
|
||||
$dateString = $datetime->format(DATE_ATOM);
|
||||
|
||||
return $this->pretty_string ?
|
||||
phraseadate::getPrettyString($datetime) : $dateString;
|
||||
}
|
||||
|
||||
private function formatCollId($value)
|
||||
{
|
||||
return phrasea::bas_names(phrasea::baseFromColl($this->sbas_id, $value));
|
||||
}
|
||||
|
||||
public static function getNbDl($dmin, $dmax, $sbas_id, $list_coll_id)
|
||||
{
|
||||
$conn = connection::getPDOConnection($sbas_id);
|
||||
$registry = registry::get_instance();
|
||||
|
||||
$params = array(':site_id' => $registry->get('GV_sit'));
|
||||
$datefilter = module_report_sqlfilter::constructDateFilter($dmin, $dmax);
|
||||
$collfilter = module_report_sqlfilter::constructCollectionFilter($list_coll_id);
|
||||
$params = array_merge($params, $datefilter['params'], $collfilter['params']);
|
||||
|
||||
$finalfilter = $datefilter['sql'] . ' AND ';
|
||||
$finalfilter .= $collfilter['sql'] . ' AND ';
|
||||
$finalfilter .= 'log.site = :site_id';
|
||||
|
||||
$sql = '
|
||||
SELECT SUM(1) AS nb
|
||||
FROM ( log
|
||||
INNER JOIN log_docs as log_date ON log.id = log_date.log_id
|
||||
INNER JOIN record on log_date.record_id = record.record_id
|
||||
)
|
||||
WHERE (
|
||||
' . $finalfilter . '
|
||||
)
|
||||
AND (
|
||||
log_date.action = \'download\'
|
||||
OR log_date.action = \'mail\'
|
||||
)
|
||||
ORDER BY log_date.date DESC
|
||||
';
|
||||
$stmt = $conn->prepare($sql);
|
||||
$stmt->execute($params);
|
||||
$row = $stmt->fetch(PDO::FETCH_ASSOC);
|
||||
$stmt->closeCursor();
|
||||
|
||||
return $row ? $row['nb'] : 0;
|
||||
}
|
||||
|
||||
public static function getTopDl($dmin, $dmax, $sbas_id, $list_coll_id)
|
||||
{
|
||||
$conn = connection::getPDOConnection($sbas_id);
|
||||
$registry = registry::get_instance();
|
||||
|
||||
$params = array(':site_id' => $registry->get('GV_sit'));
|
||||
$datefilter = module_report_sqlfilter::constructDateFilter($dmin, $dmax);
|
||||
$collfilter = module_report_sqlfilter::constructCollectionFilter($list_coll_id);
|
||||
$params = array_merge($params, $datefilter['params'], $collfilter['params']);
|
||||
|
||||
$finalfilter = "";
|
||||
$array = array(
|
||||
'preview' => array(),
|
||||
'document' => array()
|
||||
);
|
||||
|
||||
$finalfilter .= $datefilter['sql'] . ' AND ';
|
||||
$finalfilter .= $collfilter['sql'] . ' AND ';
|
||||
$finalfilter .= 'log.site = :site_id';
|
||||
|
||||
|
||||
$sql = '
|
||||
SELECT record.record_id as id, SUM(1) AS nb, subdef.name, record.xml
|
||||
FROM ( log
|
||||
INNER JOIN log_docs as log_date ON log.id = log_date.log_id
|
||||
INNER JOIN record ON log_date.record_id = record.record_id
|
||||
INNER JOIN subdef ON subdef.record_id = record.record_id
|
||||
)
|
||||
WHERE (
|
||||
' . $finalfilter . '
|
||||
)
|
||||
AND ( log_date.action = \'download\'
|
||||
OR log_date.action = \'mail\'
|
||||
)
|
||||
AND subdef.name = log_date.final
|
||||
GROUP BY id, name
|
||||
ORDER BY nb DESC
|
||||
';
|
||||
|
||||
$stmt = $conn->prepare($sql);
|
||||
$stmt->execute($params);
|
||||
$rs = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
||||
$stmt->closeCursor();
|
||||
|
||||
foreach ($rs as $row)
|
||||
{
|
||||
$k = $row['id'] . '_' . $sbas_id;
|
||||
$orig_name = parent::getChamp($row['xml'], 'doc', 'originalname');
|
||||
if ($row['name'] == 'document')
|
||||
{
|
||||
$array[$row['name']][$k]['nb'] = (int) $row['nb'];
|
||||
$array[$row['name']][$k]['lib'] = $orig_name;
|
||||
$array[$row['name']][$k]['sbasid'] = $sbas_id;
|
||||
$array[$row['name']][$k]['id'] = $row['id'];
|
||||
}
|
||||
elseif ($row['name'] == "preview")
|
||||
{
|
||||
$array[$row['name']][$k]['nb'] = (int) $row['nb'];
|
||||
$array[$row['name']][$k]['lib'] = $orig_name;
|
||||
$array[$row['name']][$k]['sbasid'] = $sbas_id;
|
||||
$array[$row['name']][$k]['id'] = $row['id'];
|
||||
}
|
||||
}
|
||||
|
||||
return $array;
|
||||
}
|
||||
|
||||
}
|
||||
|
154
lib/classes/module/report/edit.class.php
Normal file
154
lib/classes/module/report/edit.class.php
Normal file
@@ -0,0 +1,154 @@
|
||||
<?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 module_report
|
||||
* @license http://opensource.org/licenses/gpl-3.0 GPLv3
|
||||
* @link www.phraseanet.com
|
||||
*/
|
||||
class module_report_edit extends module_report
|
||||
{
|
||||
|
||||
protected $cor_query = array(
|
||||
'user' => 'log.user',
|
||||
'site' => 'log.site',
|
||||
'societe' => 'log.societe',
|
||||
'pays' => 'log.pays',
|
||||
'activite' => 'log.activite',
|
||||
'fonction' => 'log.fonction',
|
||||
'usrid' => 'log.usrid',
|
||||
'getter' => 'd.final',
|
||||
'date' => "DATE(d.date)",
|
||||
'id' => 'd.id',
|
||||
'log_id' => 'd.log_id',
|
||||
'record_id' => 'd.record_id',
|
||||
'final' => 'd.final',
|
||||
'comment' => 'd.comment',
|
||||
'size' => 's.size'
|
||||
);
|
||||
|
||||
/**
|
||||
* constructor
|
||||
*
|
||||
* @name download::__construct()
|
||||
* @param $arg1 start date of the report
|
||||
* @param $arg2 end date of the report
|
||||
* @param $sbas_id id of the databox
|
||||
*/
|
||||
public function __construct($arg1, $arg2, $sbas_id, $collist)
|
||||
{
|
||||
parent::__construct($arg1, $arg2, $sbas_id, $collist);
|
||||
$this->title = _('report:: document ajoute');
|
||||
}
|
||||
|
||||
/**
|
||||
* @desc build the specified requete
|
||||
* @param $obj $conn the current connection to databox
|
||||
* @return string
|
||||
*/
|
||||
protected function buildReq($groupby = false, $on = false)
|
||||
{
|
||||
$s = $this->sqlBuilder('action')->setGroupBy($groupby)->setOn($on)
|
||||
->setAction('edit')->buildSql();
|
||||
$this->req = $s->getSql();
|
||||
$this->params = $s->getParams();
|
||||
$this->total = $s->getTotalRows();
|
||||
}
|
||||
|
||||
public function colFilter($field, $on = false)
|
||||
{
|
||||
$s = $this->sqlBuilder('action')->setAction('edit');
|
||||
$var = $s->sqlDistinctValByField($field);
|
||||
$sql = $var['sql'];
|
||||
$params = $var['params'];
|
||||
|
||||
$stmt = $s->getConnBas()->prepare($sql);
|
||||
$stmt->execute($params);
|
||||
$rs = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
||||
$stmt->closeCursor();
|
||||
|
||||
$appbox = appbox::get_instance();
|
||||
|
||||
$ret = array();
|
||||
foreach ($rs as $row)
|
||||
{
|
||||
$value = $row['val'];
|
||||
$caption = $value;
|
||||
if ($field == "getter")
|
||||
{
|
||||
try
|
||||
{
|
||||
$user = User_Adapter::getInstance($value, $appbox);
|
||||
$caption = $user->get_display_name();
|
||||
}
|
||||
catch (Exception $e)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
elseif ($field == 'date')
|
||||
{
|
||||
$caption = phraseadate::getPrettyString(new DateTime($value));
|
||||
}
|
||||
elseif ($field == 'size')
|
||||
{
|
||||
$caption = p4string::format_octets($value);
|
||||
}
|
||||
|
||||
$ret[] = array('val' => $caption, 'value' => $value);
|
||||
}
|
||||
|
||||
return $ret;
|
||||
}
|
||||
|
||||
protected function buildResult($rs)
|
||||
{
|
||||
$i = 0;
|
||||
$pref = parent::getPreff($this->sbas_id);
|
||||
|
||||
foreach ($rs as $row)
|
||||
{
|
||||
if ($i >= $this->nb_record)
|
||||
break;
|
||||
foreach ($this->champ as $key => $value)
|
||||
{
|
||||
if ($row[$value])
|
||||
{
|
||||
if ($value == 'date')
|
||||
{
|
||||
$this->result[$i][$value] = $this->pretty_string ? phraseadate::getPrettyString(new DateTime($row[$value])) : $row[$value];
|
||||
}
|
||||
elseif ($value == 'size')
|
||||
{
|
||||
$this->result[$i][$value] = p4string::format_octets($row[$value]);
|
||||
}
|
||||
else
|
||||
$this->result[$i][$value] = $row[$value];
|
||||
}
|
||||
else
|
||||
{
|
||||
if ($value == 'comment')
|
||||
{
|
||||
$this->result[$i][$value] = ' ';
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->result[$i][$value] = '<i>' . _('report:: non-renseigne') . '</i>';
|
||||
}
|
||||
}
|
||||
}
|
||||
$i++;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
135
lib/classes/module/report/filter.class.php
Normal file
135
lib/classes/module/report/filter.class.php
Normal file
@@ -0,0 +1,135 @@
|
||||
<?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 module_report
|
||||
* @license http://opensource.org/licenses/gpl-3.0 GPLv3
|
||||
* @link www.phraseanet.com
|
||||
*/
|
||||
class module_report_filter
|
||||
{
|
||||
|
||||
private $posting_filter = array();
|
||||
private $cor_query = array();
|
||||
private $active_column = array();
|
||||
private $trans = array(
|
||||
'user' => 'phraseanet::utilisateurs',
|
||||
'ddate' => 'report:: date',
|
||||
'ip' => 'report:: IP',
|
||||
'appli' => 'report:: modules',
|
||||
'fonction' => 'report::fonction',
|
||||
'activite' => 'report::activite',
|
||||
'pays' => 'report::pays',
|
||||
'societe' => 'report::societe',
|
||||
'record_id' => 'report:: record id',
|
||||
'final' => 'phraseanet:: sous definition',
|
||||
'coll_id' => 'report:: collections',
|
||||
'comment' => 'report:: commentaire',
|
||||
'search' => 'report:: question',
|
||||
'xml' => 'report:: description'
|
||||
);
|
||||
|
||||
public function __construct($current_filter, $correspondance)
|
||||
{
|
||||
$this->tab_filter = $current_filter;
|
||||
$this->cor_query = $correspondance;
|
||||
}
|
||||
|
||||
private function checkSameFilter($field, $operator, $value)
|
||||
{
|
||||
$test = true;
|
||||
if (sizeof($this->tab_filter) > 0)
|
||||
{
|
||||
foreach ($this->tab_filter as $filters => $a_filter)
|
||||
{
|
||||
if (in_array($field, $a_filter) &&
|
||||
in_array($operator, $a_filter) && in_array($value, $a_filter))
|
||||
{
|
||||
$test = false;
|
||||
break;
|
||||
}
|
||||
elseif (in_array($field, $a_filter) &&
|
||||
in_array($operator, $a_filter) && !in_array($value, $a_filter))
|
||||
{
|
||||
$a_filter['v'] = $value;
|
||||
$test = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $test;
|
||||
}
|
||||
|
||||
public function addFilter($field, $operator, $value)
|
||||
{
|
||||
if ($this->checkSameFilter($field, $operator, $value))
|
||||
$this->tab_filter[] = array('f' => $field, 'o' => $operator, 'v' => $value);
|
||||
}
|
||||
|
||||
public function getPostingFilter()
|
||||
{
|
||||
if (sizeof($this->tab_filter) > 0)
|
||||
{
|
||||
foreach ($this->tab_filter as $key => $filter)
|
||||
{
|
||||
if (empty($filter['v']))
|
||||
$value = _('report:: non-renseigne');
|
||||
else
|
||||
$value = $filter['v'];
|
||||
|
||||
if (array_key_exists($filter['f'], $this->trans))
|
||||
$field = _($this->trans[$filter['f']]);
|
||||
else
|
||||
$field = $filter['f'];
|
||||
|
||||
if ($filter['f'] == 'appli')
|
||||
{
|
||||
$value = implode(' ', phrasea::modulesName(@unserialize($value)));
|
||||
}
|
||||
elseif ($filter['f'] == "ddate")
|
||||
{
|
||||
$value = phraseadate::getPrettyString(new DateTime($value));
|
||||
}
|
||||
|
||||
$this->posting_filter[] = array('f' => $field, 'v' => $value);
|
||||
}
|
||||
}
|
||||
|
||||
return $this->posting_filter;
|
||||
}
|
||||
|
||||
public function removeFilter($field)
|
||||
{
|
||||
foreach ($this->tab_filter as $key => $value)
|
||||
{
|
||||
if ($value['f'] == $field)
|
||||
unset($this->tab_filter[$key]);
|
||||
}
|
||||
}
|
||||
|
||||
public function getActiveColumn()
|
||||
{
|
||||
foreach ($this->tab_filter as $key => $value)
|
||||
{
|
||||
$this->active_column[] = $value['f'];
|
||||
}
|
||||
|
||||
return $this->active_column;
|
||||
}
|
||||
|
||||
public function getTabFilter()
|
||||
{
|
||||
return $this->tab_filter;
|
||||
}
|
||||
|
||||
}
|
645
lib/classes/module/report/nav.class.php
Normal file
645
lib/classes/module/report/nav.class.php
Normal file
@@ -0,0 +1,645 @@
|
||||
<?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 module_report
|
||||
* @license http://opensource.org/licenses/gpl-3.0 GPLv3
|
||||
* @link www.phraseanet.com
|
||||
*/
|
||||
class module_report_nav extends module_report
|
||||
{
|
||||
|
||||
/**
|
||||
* @desc total of record on current report
|
||||
* @var string
|
||||
*/
|
||||
public $total_pourcent = null;
|
||||
public $config = false;
|
||||
public $cor_query = array(
|
||||
'user' => 'log.user',
|
||||
'site' => 'log.site',
|
||||
'societe' => 'log.societe',
|
||||
'pays' => 'log.pays',
|
||||
'activite' => 'log.activite',
|
||||
'fonction' => 'log.fonction',
|
||||
'usrid' => 'log.usrid',
|
||||
'coll_id' => 'record.coll_id',
|
||||
'xml' => 'record.xml',
|
||||
'ddate' => "log.date",
|
||||
'id' => 'log_docs.id',
|
||||
'log_id' => 'log_docs.log_id',
|
||||
'record_id' => 'log_docs.record_id',
|
||||
'final' => 'log_docs.final',
|
||||
'comment' => 'log_docs.comment',
|
||||
'size' => 'subdef.size'
|
||||
);
|
||||
|
||||
/**
|
||||
* constructor
|
||||
*
|
||||
* @name nav::__construct()
|
||||
* @param $arg1 start date of the report
|
||||
* @param $arg2 end date of the report
|
||||
* @param $sbas_id databox id
|
||||
*/
|
||||
public function __construct($arg1, $arg2, $sbas_id, $collist)
|
||||
{
|
||||
parent::__construct($arg1, $arg2, $sbas_id, $collist);
|
||||
$this->total_pourcent = $this->setTotalPourcent();
|
||||
}
|
||||
|
||||
private function setTotalPourcent()
|
||||
{
|
||||
$registry = registry::get_instance();
|
||||
$x = $this->getTransQueryString();
|
||||
|
||||
$s = new module_report_sql($this);
|
||||
$filter = $s->getFilters();
|
||||
|
||||
$params = array();
|
||||
$report_filter = $filter->getReportFilter();
|
||||
$coll_filter = $filter->getCollectionFilter();
|
||||
$site_filter = $filter->getGvSitFilter();
|
||||
$params = array_merge($report_filter['params'], $coll_filter['params'], $site_filter['params']);
|
||||
|
||||
$sql = '
|
||||
SELECT
|
||||
SUM(1) AS total
|
||||
FROM log
|
||||
WHERE (' . $report_filter['sql'] . '
|
||||
AND nav != TRIM(\'\')
|
||||
)
|
||||
AND ' . $site_filter['sql'] . '
|
||||
AND (' . $coll_filter['sql'] . ')';
|
||||
|
||||
$stmt = $s->getConnBas()->prepare($sql);
|
||||
$stmt->execute($params);
|
||||
$row = $stmt->fetch(PDO::FETCH_ASSOC);
|
||||
$stmt->closeCursor();
|
||||
|
||||
return $row['total'];
|
||||
}
|
||||
|
||||
/**
|
||||
* @desc empty $champ, $result, $display, $display_value
|
||||
* @return void
|
||||
*/
|
||||
private function initialize()
|
||||
{
|
||||
$this->report['legend'] = array();
|
||||
$this->report['value'] = array();
|
||||
$this->result = array();
|
||||
$this->champ = array();
|
||||
$this->default_display = array();
|
||||
$this->display = array();
|
||||
}
|
||||
|
||||
/**
|
||||
* @desc return the filter to generate the good request
|
||||
* @param object $conn the current connexion to appbox
|
||||
* @return string
|
||||
*/
|
||||
private function getFilter()
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
* @desc report the browser used by users
|
||||
* @param array $tab config for the html table
|
||||
* @return tab
|
||||
*/
|
||||
public function buildTabNav($tab = false)
|
||||
{
|
||||
$i = 0;
|
||||
|
||||
$registry = registry::get_instance();
|
||||
|
||||
$s = new module_report_sql($this);
|
||||
$filter = $s->getFilters();
|
||||
$this->title = _('report:: navigateur');
|
||||
|
||||
if (is_null($this->total_pourcent))
|
||||
{
|
||||
return $this->report;
|
||||
}
|
||||
|
||||
$params = array();
|
||||
$report_filter = $filter->getReportFilter();
|
||||
$params = array_merge($params, $report_filter['params']);
|
||||
|
||||
$sql = '
|
||||
SELECT
|
||||
nav,
|
||||
COUNT(nav) AS nb,
|
||||
ROUND(
|
||||
( COUNT(nav) / ' . $this->total_pourcent . ' * 100),
|
||||
1
|
||||
) AS pourcent
|
||||
FROM log
|
||||
WHERE (' . $report_filter['sql'] . '
|
||||
AND nav != TRIM(\'\')
|
||||
)
|
||||
GROUP BY nav
|
||||
ORDER BY pourcent DESC';
|
||||
|
||||
$this->initialize();
|
||||
|
||||
$stmt = $s->getConnBas()->prepare($sql);
|
||||
$stmt->execute($params);
|
||||
$rs = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
||||
$stmt->closeCursor();
|
||||
|
||||
$this->setChamp($rs);
|
||||
$this->setDisplay($tab);
|
||||
|
||||
foreach ($rs as $row)
|
||||
{
|
||||
foreach ($this->champ as $key => $value)
|
||||
{
|
||||
$this->result[$i][$value] = ($value == 'pourcent') ? $row[$value] . '%' : $row[$value];
|
||||
}
|
||||
$this->report['value'][] = $row['nb'];
|
||||
$this->report['legend'][] = $row['nav'];
|
||||
$i++;
|
||||
}
|
||||
|
||||
$this->total = sizeof($this->result);
|
||||
$this->calculatePages($rs);
|
||||
$this->setDisplayNav();
|
||||
$this->setReport();
|
||||
|
||||
return $this->report;
|
||||
}
|
||||
|
||||
/**
|
||||
* @desc report the OS from user
|
||||
* @param array $tab config for the html table
|
||||
* @return array
|
||||
*/
|
||||
public function buildTabOs($tab = false)
|
||||
{
|
||||
|
||||
$registry = registry::get_instance();
|
||||
$s = new module_report_sql($this);
|
||||
$filter = $s->getFilters();
|
||||
$i = 0;
|
||||
$this->title = _('report:: Plateforme');
|
||||
|
||||
if (is_null($this->total_pourcent))
|
||||
{
|
||||
return $this->report;
|
||||
}
|
||||
|
||||
$params = array();
|
||||
$report_filter = $filter->getReportFilter();
|
||||
$params = array_merge($params, $report_filter['params']);
|
||||
|
||||
$sql = '
|
||||
SELECT
|
||||
os,
|
||||
COUNT(os) AS nb,
|
||||
ROUND((COUNT(os)/' . $this->total_pourcent . '*100),1) AS pourcent
|
||||
FROM log
|
||||
WHERE ( ' . $report_filter['sql'] . '
|
||||
AND os != TRIM(\'\')
|
||||
)
|
||||
GROUP BY os
|
||||
ORDER BY pourcent DESC';
|
||||
|
||||
$this->initialize();
|
||||
|
||||
$stmt = $s->getConnBas()->prepare($sql);
|
||||
$stmt->execute($params);
|
||||
$rs = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
||||
$stmt->closeCursor();
|
||||
|
||||
$this->setChamp($rs);
|
||||
$this->setDisplay($tab);
|
||||
|
||||
foreach ($rs as $row)
|
||||
{
|
||||
foreach ($this->champ as $key => $value)
|
||||
{
|
||||
$this->result[$i][$value] = ($value == 'pourcent') ? $row[$value] . '%' : $row[$value];
|
||||
}
|
||||
$i++;
|
||||
$this->report['value'][] = $row['nb'];
|
||||
$this->report['legend'][] = $row['os'];
|
||||
}
|
||||
$this->total = sizeof($this->result);
|
||||
$this->calculatePages($rs);
|
||||
$this->setDisplayNav();
|
||||
$this->setReport();
|
||||
|
||||
return $this->report;
|
||||
}
|
||||
|
||||
/**
|
||||
* @desc report the resolution that are using the users
|
||||
* @param array $tab config for the html table
|
||||
* @return array
|
||||
*/
|
||||
public function buildTabRes($tab = false)
|
||||
{
|
||||
|
||||
$registry = registry::get_instance();
|
||||
$s = new module_report_sql($this);
|
||||
$filter = $s->getFilters();
|
||||
$this->title = _('report:: resolution');
|
||||
$i = 0;
|
||||
if (is_null($this->total_pourcent))
|
||||
{
|
||||
return($this->report);
|
||||
}
|
||||
|
||||
$params = array();
|
||||
$report_filter = $filter->getReportFilter();
|
||||
$params = array_merge($params, $report_filter['params']);
|
||||
|
||||
$sql = '
|
||||
SELECT
|
||||
res,
|
||||
COUNT(res) AS nb,
|
||||
ROUND((COUNT(res)/ ' . $this->total_pourcent . '*100),1) AS pourcent
|
||||
FROM log
|
||||
WHERE (' . $report_filter['sql'] . '
|
||||
AND res != TRIM(\'\')
|
||||
)
|
||||
GROUP BY res
|
||||
ORDER BY pourcent DESC
|
||||
LIMIT 0, 10';
|
||||
|
||||
$this->initialize();
|
||||
|
||||
|
||||
$stmt = $s->getConnBas()->prepare($sql);
|
||||
$stmt->execute($params);
|
||||
$rs = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
||||
$stmt->closeCursor();
|
||||
|
||||
$this->setChamp($rs);
|
||||
$this->setDisplay($tab);
|
||||
|
||||
foreach ($rs as $row)
|
||||
{
|
||||
foreach ($this->champ as $key => $value)
|
||||
{
|
||||
$this->result[$i][$value] = ($value == 'pourcent') ?
|
||||
$row[$value] . '%' : $row[$value];
|
||||
}
|
||||
$i++;
|
||||
$this->report['value'][] = $row['nb'];
|
||||
$this->report['legend'][] = $row['res'];
|
||||
}
|
||||
|
||||
$this->total = sizeof($this->result);
|
||||
$this->calculatePages($rs);
|
||||
$this->setDisplayNav();
|
||||
$this->setReport();
|
||||
|
||||
return $this->report;
|
||||
}
|
||||
|
||||
/**
|
||||
* @desc report the combination (OS - Navigateur) that are using the users
|
||||
* @param array $tab config for the html table
|
||||
*/
|
||||
public function buildTabCombo($tab = false)
|
||||
{
|
||||
$s = new module_report_sql($this);
|
||||
$filter = $s->getFilters();
|
||||
$this->title = _('report:: navigateurs et plateforme');
|
||||
$i = 0;
|
||||
if (is_null($this->total_pourcent))
|
||||
{
|
||||
return($this->report);
|
||||
}
|
||||
|
||||
$params = array();
|
||||
$report_filter = $filter->getReportFilter();
|
||||
$params = array_merge($params, $report_filter['params']);
|
||||
|
||||
$sql = "
|
||||
SELECT
|
||||
CONCAT( nav, '-', os ) AS combo,
|
||||
COUNT( CONCAT( nav, '-', os ) ) AS nb,
|
||||
ROUND(
|
||||
(COUNT( CONCAT( nav ,'-', os ))/" . $this->total_pourcent . "*100),
|
||||
1) AS pourcent
|
||||
FROM log
|
||||
WHERE (" . $report_filter['sql'] . "
|
||||
AND nav != TRIM( '' )
|
||||
)
|
||||
AND os != TRIM( '' )
|
||||
GROUP BY combo
|
||||
ORDER BY nb DESC
|
||||
LIMIT 0 , 10";
|
||||
|
||||
$this->initialize();
|
||||
|
||||
$stmt = $s->getConnBas()->prepare($sql);
|
||||
$stmt->execute($params);
|
||||
$rs = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
||||
$stmt->closeCursor();
|
||||
|
||||
$this->setChamp($rs);
|
||||
$this->setDisplay($tab);
|
||||
|
||||
foreach ($rs as $row)
|
||||
{
|
||||
foreach ($this->champ as $key => $value)
|
||||
{
|
||||
$this->result[$i][$value] = ($value == 'pourcent') ?
|
||||
$row[$value] . '%' : $row[$value];
|
||||
}
|
||||
$i++;
|
||||
$this->report['value'][] = $row['nb'];
|
||||
$this->report['legend'][] = $row['combo'];
|
||||
}
|
||||
$this->total = sizeof($this->result);
|
||||
$this->calculatePages($rs);
|
||||
$this->setDisplayNav();
|
||||
$this->setReport();
|
||||
|
||||
return $this->report;
|
||||
}
|
||||
|
||||
/**
|
||||
* @desc report the most consulted module by the users
|
||||
* @param array $tab
|
||||
* @return array
|
||||
*/
|
||||
public function buildTabModule($tab = false)
|
||||
{
|
||||
$this->initialize();
|
||||
$registry = registry::get_instance();
|
||||
$s = new module_report_sql($this);
|
||||
$filter = $s->getFilters();
|
||||
$this->title = _('report:: modules');
|
||||
$x = array();
|
||||
$tab_appli = array();
|
||||
|
||||
if (is_null($this->total_pourcent))
|
||||
{
|
||||
return($this->report);
|
||||
}
|
||||
|
||||
$params = array();
|
||||
$report_filter = $filter->getReportFilter();
|
||||
$params = array_merge($params, $report_filter['params']);
|
||||
|
||||
$sql = '
|
||||
SELECT
|
||||
appli
|
||||
FROM log
|
||||
WHERE (' . $report_filter['sql'] . '
|
||||
AND appli != \'a:0:{}\'
|
||||
)
|
||||
GROUP BY appli
|
||||
ORDER BY appli DESC
|
||||
';
|
||||
|
||||
$this->initialize();
|
||||
|
||||
$stmt = $s->getConnBas()->prepare($sql);
|
||||
$stmt->execute($params);
|
||||
$rs = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
||||
$stmt->closeCursor();
|
||||
|
||||
foreach ($rs as $row)
|
||||
{
|
||||
$applis = false;
|
||||
if (($applis = @unserialize($row['appli'])) !== false)
|
||||
array_push($x, phrasea::modulesName($applis));
|
||||
else
|
||||
array_push($x, 'NULL');
|
||||
}
|
||||
foreach ($x as $key => $tab_value)
|
||||
{
|
||||
if (is_array($tab_value))
|
||||
{
|
||||
foreach ($tab_value as $key2 => $value)
|
||||
{
|
||||
if (!isset($tab_appli[$value]))
|
||||
$tab_appli[$value] = 0;
|
||||
$tab_appli[$value]++;
|
||||
}
|
||||
}
|
||||
}
|
||||
$total = array_sum($tab_appli);
|
||||
|
||||
$this->setChamp($rs);
|
||||
$this->setDisplay($tab);
|
||||
|
||||
foreach ($tab_appli as $appli => $nb)
|
||||
{
|
||||
$pourcent = round(($nb / $total) * 100, 1);
|
||||
foreach ($this->champ as $key => $value)
|
||||
{
|
||||
$this->result[] = array(
|
||||
'appli' => $appli,
|
||||
'nb' => $nb,
|
||||
'pourcent' => $pourcent . '%'
|
||||
);
|
||||
}
|
||||
$this->report['value'][] = $nb;
|
||||
$this->report['legend'][] = $appli;
|
||||
}
|
||||
$this->total = sizeof($this->result);
|
||||
$this->calculatePages($rs);
|
||||
$this->setDisplayNav();
|
||||
$this->setReport();
|
||||
|
||||
return $this->report;
|
||||
}
|
||||
|
||||
/**
|
||||
* @desc report basic user informations
|
||||
* @param int $val user id
|
||||
* @param array $tab config for the html table
|
||||
* @param string $on the field
|
||||
* @return array
|
||||
*/
|
||||
public function buildTabGrpInfo($req, array $params, $val, $tab = false, $on = false)
|
||||
{
|
||||
|
||||
$this->initialize();
|
||||
$registry = registry::get_instance();
|
||||
empty($on) ? $on = false : "";
|
||||
$filter_id_apbox = $filter_id_datbox = array();
|
||||
$conn = connection::getPDOConnection();
|
||||
$conn2 = connection::getPDOConnection($this->sbas_id);
|
||||
|
||||
|
||||
$datefilter = array();
|
||||
|
||||
if ($this->dmin && $this->dmax)
|
||||
{
|
||||
$params = array(':dmin' => $this->dmin, ':dmax' => $this->dmax);
|
||||
$datefilter = "date > :dmin AND date < :dmax";
|
||||
}
|
||||
|
||||
$this->title = sprintf(_('report:: Information sur les utilisateurs correspondant a %s'), $val);
|
||||
|
||||
if ($on)
|
||||
{
|
||||
if (!empty($req))
|
||||
{
|
||||
$stmt = $conn2->prepare($req);
|
||||
$stmt->execute($params);
|
||||
$rsu = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
||||
$stmt->closeCursor();
|
||||
|
||||
foreach ($rsu as $row_user)
|
||||
{
|
||||
$filter_id_apbox[] = "usr_id = " . (int) $row_user['usrid'];
|
||||
$filter_id_datbox[] = "log.usrid = " . (int) $row_user['usrid'];
|
||||
}
|
||||
$filter_id_apbox = implode(' OR ', $filter_id_apbox);
|
||||
$filter_id_datbox = implode(' OR ', $filter_id_datbox);
|
||||
}
|
||||
|
||||
$sql = "
|
||||
SELECT
|
||||
usr_login as identifiant,
|
||||
usr_nom as nom,
|
||||
usr_mail as mail,
|
||||
adresse, tel
|
||||
FROM usr
|
||||
WHERE $on = :value AND (" . $filter_id_apbox . ")";
|
||||
}
|
||||
else
|
||||
{
|
||||
$sql = '
|
||||
SELECT
|
||||
usr_login AS identifiant,
|
||||
usr_nom AS nom,
|
||||
usr_mail AS mail,
|
||||
adresse,
|
||||
tel
|
||||
FROM usr
|
||||
WHERE (usr_id = :value)';
|
||||
}
|
||||
|
||||
$params2 = array(':value' => $val);
|
||||
$stmt = $conn->prepare($sql);
|
||||
$stmt->execute($params2);
|
||||
$rs = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
||||
$stmt->closeCursor();
|
||||
|
||||
$this->setChamp($rs);
|
||||
$this->setDisplay($tab);
|
||||
|
||||
foreach ($rs as $row)
|
||||
{
|
||||
foreach ($row as $fieldname => $value)
|
||||
$row[$fieldname] = $value ? $value : _('report:: non-renseigne');
|
||||
$this->result[] = $row;
|
||||
}
|
||||
if ($on == false)
|
||||
{
|
||||
$login = empty($this->result[0]['identifiant']) ?
|
||||
_('phraseanet::utilisateur inconnu') :
|
||||
$this->result[0]['identifiant'];
|
||||
|
||||
$this->title = sprintf(
|
||||
_('report:: Information sur l\'utilisateur %s'), $login
|
||||
);
|
||||
}
|
||||
$this->calculatePages($rs);
|
||||
$this->setDisplayNav();
|
||||
$this->setReport();
|
||||
|
||||
return $this->report;
|
||||
}
|
||||
|
||||
/**
|
||||
* @desc return basic information about a record
|
||||
* @param $ses session id
|
||||
* @param $bid base id
|
||||
* @param $rid record id
|
||||
* @param $tab config for the html table
|
||||
* @return array
|
||||
*/
|
||||
public function buildTabUserWhat($bid, $rid, $tab = false)
|
||||
{
|
||||
$sbas_id = phrasea::sbasFromBas($bid);
|
||||
$record = new record_adapter($sbas_id, $rid);
|
||||
|
||||
$this->setDisplay($tab);
|
||||
$this->initialize();
|
||||
$this->champ = array(
|
||||
'photo',
|
||||
'record_id',
|
||||
'date',
|
||||
'type',
|
||||
'titre',
|
||||
'taille'
|
||||
);
|
||||
|
||||
$document = $record->get_subdef('document');
|
||||
$this->title = sprintf(
|
||||
_('report:: Information sur l\'enregistrement numero %d'), (int) $rid);
|
||||
|
||||
|
||||
$x = $record->get_thumbnail();
|
||||
$this->result = array(
|
||||
'photo' =>
|
||||
"<img style='width:" . $x->get_width() . "px;height:" . $x->get_height() . "px;'
|
||||
src='" . $x->get_url() . "'>"
|
||||
, 'record_id' => $record->get_record_id()
|
||||
, 'date' => phraseadate::getPrettyString($document->get_creation_date())
|
||||
, 'type' => $document->get_mime()
|
||||
, 'titre' => $record->get_title()
|
||||
, 'taille' => $document->get_size()
|
||||
);
|
||||
|
||||
$this->setDisplayNav();
|
||||
$this->setReport();
|
||||
|
||||
return $this->report;
|
||||
}
|
||||
|
||||
public function buildTabInfoNav($tab = false, $navigator)
|
||||
{
|
||||
$conn = connection::getPDOConnection($this->sbas_id);
|
||||
$this->title = sprintf(
|
||||
_('report:: Information sur le navigateur %s'), $navigator);
|
||||
|
||||
|
||||
$params = array(':browser' => $navigator);
|
||||
|
||||
$sql = "SELECT DISTINCT(version) as version, COUNT(version) as nb
|
||||
FROM log
|
||||
WHERE nav = :browser
|
||||
GROUP BY version
|
||||
ORDER BY nb DESC";
|
||||
|
||||
$stmt = $conn->prepare($sql);
|
||||
$stmt->execute($params);
|
||||
$rs = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
||||
$stmt->closeCursor();
|
||||
|
||||
$this->setChamp($rs);
|
||||
$this->setDisplay($tab);
|
||||
|
||||
$this->result = $rs;
|
||||
$this->total = sizeof($this->result);
|
||||
$this->calculatePages($rs);
|
||||
$this->setDisplayNav();
|
||||
$this->setReport();
|
||||
|
||||
return $this->report;
|
||||
}
|
||||
|
||||
}
|
155
lib/classes/module/report/push.class.php
Normal file
155
lib/classes/module/report/push.class.php
Normal file
@@ -0,0 +1,155 @@
|
||||
<?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 module_report
|
||||
* @license http://opensource.org/licenses/gpl-3.0 GPLv3
|
||||
* @link www.phraseanet.com
|
||||
*/
|
||||
class module_report_push extends module_report
|
||||
{
|
||||
|
||||
protected $cor_query = array(
|
||||
'user' => 'log.user',
|
||||
'site' => 'log.site',
|
||||
'societe' => 'log.societe',
|
||||
'pays' => 'log.pays',
|
||||
'activite' => 'log.activite',
|
||||
'fonction' => 'log.fonction',
|
||||
'usrid' => 'log.usrid',
|
||||
'getter' => 'd.final',
|
||||
'date' => "DATE(d.date)",
|
||||
'id' => 'd.id',
|
||||
'log_id' => 'd.log_id',
|
||||
'record_id' => 'd.record_id',
|
||||
'final' => 'd.final',
|
||||
'comment' => 'd.comment',
|
||||
'size' => 's.size'
|
||||
);
|
||||
|
||||
/**
|
||||
* constructor
|
||||
*
|
||||
* @name download::__construct()
|
||||
* @param $arg1 start date of the report
|
||||
* @param $arg2 end date of the report
|
||||
* @param $sbas_id id of the databox
|
||||
*/
|
||||
public function __construct($arg1, $arg2, $sbas_id, $collist)
|
||||
{
|
||||
parent::__construct($arg1, $arg2, $sbas_id, $collist);
|
||||
$this->title = _('report:: document ajoute');
|
||||
}
|
||||
|
||||
/**
|
||||
* @desc build the specified requete
|
||||
* @param $obj $conn the current connection to databox
|
||||
* @return string
|
||||
*/
|
||||
protected function buildReq($groupby = false, $on = false)
|
||||
{
|
||||
$s = $this->sqlBuilder('action')->setGroupBy($groupby)->setOn($on)
|
||||
->setAction('push')->buildSql();
|
||||
$this->req = $s->getSql();
|
||||
$this->params = $s->getParams();
|
||||
$this->total = $s->getTotalRows();
|
||||
}
|
||||
|
||||
public function colFilter($field, $on = false)
|
||||
{
|
||||
$s = $this->sqlBuilder('action')->setAction('push');
|
||||
$var = $s->sqlDistinctValByField($field);
|
||||
$sql = $var['sql'];
|
||||
$params = $var['params'];
|
||||
|
||||
$stmt = $s->getConnBas()->prepare($sql);
|
||||
$stmt->execute($params);
|
||||
$rs = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
||||
$stmt->closeCursor();
|
||||
|
||||
$ret = array();
|
||||
|
||||
foreach ($rs as $row)
|
||||
{
|
||||
$value = $row['val'];
|
||||
$caption = $value;
|
||||
if ($field == "getter")
|
||||
{
|
||||
try
|
||||
{
|
||||
$user = User_Adapter::getInstance($value, $appbox);
|
||||
$caption = $user->get_display_name();
|
||||
}
|
||||
catch (Exception $e)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
elseif ($field == 'date')
|
||||
{
|
||||
$caption = phraseadate::getPrettyString(new DateTime($value));
|
||||
}
|
||||
elseif ($field == 'size')
|
||||
{
|
||||
$caption = p4string::format_octets($value);
|
||||
}
|
||||
|
||||
$ret[] = array('val' => $caption, 'value' => $value);
|
||||
}
|
||||
|
||||
return $ret;
|
||||
}
|
||||
|
||||
protected function buildResult($rs)
|
||||
{
|
||||
$i = 0;
|
||||
$pref = parent::getPreff($this->sbas_id);
|
||||
|
||||
foreach ($rs as $row)
|
||||
{
|
||||
if ($i >= $this->nb_record)
|
||||
break;
|
||||
foreach ($this->champ as $key => $value)
|
||||
{
|
||||
if ($row[$value])
|
||||
{
|
||||
if ($value == 'date')
|
||||
{
|
||||
$this->result[$i][$value] = $this->pretty_string ?
|
||||
phraseadate::getPrettyString(new DateTime($row[$value])) :
|
||||
$row[$value];
|
||||
}
|
||||
elseif ($value == 'size')
|
||||
{
|
||||
$this->result[$i][$value] = p4string::format_octets($row[$value]);
|
||||
}
|
||||
else
|
||||
$this->result[$i][$value] = $row[$value];
|
||||
}
|
||||
else
|
||||
{
|
||||
if ($value == 'comment')
|
||||
{
|
||||
$this->result[$i][$value] = ' ';
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->result[$i][$value] = '<i>' . _('report:: non-renseigne') . '</i>';
|
||||
}
|
||||
}
|
||||
}
|
||||
$i++;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
117
lib/classes/module/report/question.class.php
Normal file
117
lib/classes/module/report/question.class.php
Normal file
@@ -0,0 +1,117 @@
|
||||
<?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 module_report
|
||||
* @license http://opensource.org/licenses/gpl-3.0 GPLv3
|
||||
* @link www.phraseanet.com
|
||||
*/
|
||||
class module_report_question extends module_report
|
||||
{
|
||||
|
||||
protected $cor_query = array(
|
||||
'user' => 'log.user'
|
||||
, 'usrid' => 'log.usrid'
|
||||
, 'ddate' => 'log_search.date'
|
||||
, 'date' => 'log_search.date'
|
||||
, 'societe' => 'log.societe'
|
||||
, 'pays' => 'log.pays'
|
||||
, 'activite' => 'log.activite'
|
||||
, 'fonction' => 'log.fonction'
|
||||
, 'site' => 'log.site'
|
||||
, 'sit_session' => 'log.sit_session'
|
||||
, 'coll_list' => 'log.coll_list'
|
||||
, 'appli' => 'log.appli'
|
||||
, 'ip' => 'log.ip'
|
||||
);
|
||||
|
||||
/**
|
||||
* constructor
|
||||
*
|
||||
* @name download::__construct()
|
||||
* @param $arg1 start date of the report
|
||||
* @param $arg2 end date of the report
|
||||
* @param $sbas_id id of the databox
|
||||
*/
|
||||
public function __construct($arg1, $arg2, $sbas_id, $collist)
|
||||
{
|
||||
parent::__construct($arg1, $arg2, $sbas_id, $collist);
|
||||
$this->title = _('report:: question');
|
||||
}
|
||||
|
||||
/**
|
||||
* @desc build the specified requete
|
||||
* @param $obj $conn the current connection to databox
|
||||
* @return string
|
||||
*/
|
||||
protected function buildReq($groupby = false)
|
||||
{
|
||||
$sql = $this->sqlBuilder('question')->setGroupBy($groupby)->buildSql();
|
||||
$this->req = $sql->getSql();
|
||||
$this->params = $sql->getParams();
|
||||
$this->total = $sql->getTotalRows();
|
||||
}
|
||||
|
||||
public function colFilter($field)
|
||||
{
|
||||
$ret = array();
|
||||
$s = $this->sqlBuilder('question');
|
||||
$var = $s->sqlDistinctValByField($field);
|
||||
$sql = $var['sql'];
|
||||
$params = $var['params'];
|
||||
$stmt = $s->getConnBas()->prepare($sql);
|
||||
$stmt->execute($params);
|
||||
$rs = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
||||
$stmt->closeCursor();
|
||||
|
||||
foreach ($rs as $row)
|
||||
{
|
||||
$value = $row['val'];
|
||||
if ($field == 'appli')
|
||||
$caption = implode(' ', phrasea::modulesName(@unserialize($row['val'])));
|
||||
elseif ($field == "ddate")
|
||||
$caption = phraseadate::getPrettyString(new DateTime($value));
|
||||
else
|
||||
$caption = $row['val'];
|
||||
$ret[] = array('val' => $caption, 'value' => $value);
|
||||
}
|
||||
|
||||
return $ret;
|
||||
}
|
||||
|
||||
protected function buildResult($rs)
|
||||
{
|
||||
$tab = array();
|
||||
$i = 0;
|
||||
foreach ($rs as $row)
|
||||
{
|
||||
if ($this->enable_limit && ($i > $this->nb_record))
|
||||
break;
|
||||
foreach ($this->champ as $key => $value)
|
||||
{
|
||||
if ($row[$value])
|
||||
{
|
||||
if ($value == 'ddate')
|
||||
$this->result[$i][$value] =
|
||||
$this->pretty_string ? phraseadate::getPrettyString(new DateTime($row[$value])) : $row[$value];
|
||||
else
|
||||
$this->result[$i][$value] = $row[$value];
|
||||
}
|
||||
else
|
||||
$this->result[$i][$value] = "<i>" . _('report:: non-renseigne') . "</i>";
|
||||
}
|
||||
$i++;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
131
lib/classes/module/report/sql.class.php
Normal file
131
lib/classes/module/report/sql.class.php
Normal file
@@ -0,0 +1,131 @@
|
||||
<?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 module_report
|
||||
* @license http://opensource.org/licenses/gpl-3.0 GPLv3
|
||||
* @link www.phraseanet.com
|
||||
*/
|
||||
class module_report_sql
|
||||
{
|
||||
|
||||
/**
|
||||
*
|
||||
* @var connection_PDO
|
||||
*/
|
||||
public $conn;
|
||||
/**
|
||||
*
|
||||
* @var connection_PDO
|
||||
*/
|
||||
public $connbas;
|
||||
/**
|
||||
*
|
||||
* @var module_report_sqlfilter
|
||||
*/
|
||||
public $filter;
|
||||
public $sql;
|
||||
public $params;
|
||||
public $total_row;
|
||||
public $enable_limit;
|
||||
public $groupby = false;
|
||||
public $on = false;
|
||||
|
||||
public function __construct(module_report $report)
|
||||
{
|
||||
$this->conn = connection::getPDOConnection();
|
||||
$this->connbas = connection::getPDOConnection($report->getSbasId());
|
||||
$this->filter = new module_report_sqlfilter($report);
|
||||
$this->sql = '';
|
||||
$this->params = array();
|
||||
$this->total_row = 0;
|
||||
$this->enable_limit = $report->getEnableLimit();
|
||||
}
|
||||
|
||||
public function setGroupBy($groupby)
|
||||
{
|
||||
$this->groupby = $groupby;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getGroupby()
|
||||
{
|
||||
return $this->groupby;
|
||||
}
|
||||
|
||||
public function setOn($on)
|
||||
{
|
||||
$this->on = $on;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getOn()
|
||||
{
|
||||
return $this->on;
|
||||
}
|
||||
|
||||
public function setFilter(module_report_sqlfilter $filter)
|
||||
{
|
||||
$this->filter = $filter;
|
||||
}
|
||||
/**
|
||||
*
|
||||
* @return module_report_sqlfilter
|
||||
*/
|
||||
public function getFilters()
|
||||
{
|
||||
return $this->filter;
|
||||
}
|
||||
|
||||
public function getSql()
|
||||
{
|
||||
return $this->sql;
|
||||
}
|
||||
|
||||
public function getParams()
|
||||
{
|
||||
return $this->params;
|
||||
}
|
||||
|
||||
public function getTotalRows()
|
||||
{
|
||||
return $this->total_row;
|
||||
}
|
||||
|
||||
public function setTotalrows($total)
|
||||
{
|
||||
$this->total_row = $total;
|
||||
}
|
||||
|
||||
public function getTransQuery($champ)
|
||||
{
|
||||
$tanslation = $this->filter->getCorFilter();
|
||||
if (array_key_exists($champ, $tanslation))
|
||||
|
||||
return $tanslation[$champ];
|
||||
else
|
||||
|
||||
return $champ;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return connection_PDO
|
||||
*/
|
||||
public function getConnBas()
|
||||
{
|
||||
return $this->connbas;
|
||||
}
|
||||
|
||||
}
|
23
lib/classes/module/report/sqlReportInterface.class.php
Normal file
23
lib/classes/module/report/sqlReportInterface.class.php
Normal file
@@ -0,0 +1,23 @@
|
||||
<?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 module_report
|
||||
* @license http://opensource.org/licenses/gpl-3.0 GPLv3
|
||||
* @link www.phraseanet.com
|
||||
*/
|
||||
interface module_report_sqlReportinterface
|
||||
{
|
||||
public function buildSql();
|
||||
|
||||
public function sqlDistinctValByField($field);
|
||||
}
|
147
lib/classes/module/report/sqlaction.class.php
Normal file
147
lib/classes/module/report/sqlaction.class.php
Normal file
@@ -0,0 +1,147 @@
|
||||
<?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 module_report
|
||||
* @license http://opensource.org/licenses/gpl-3.0 GPLv3
|
||||
* @link www.phraseanet.com
|
||||
*/
|
||||
class module_report_sqlaction extends module_report_sql implements module_report_sqlReportInterface
|
||||
{
|
||||
|
||||
private $action = 'add';
|
||||
|
||||
public function __construct(module_report $report)
|
||||
{
|
||||
parent::__construct($report);
|
||||
}
|
||||
|
||||
public function setAction($action)
|
||||
{
|
||||
//possible action
|
||||
$a = array('edit', 'add', 'push', 'validate');
|
||||
if (in_array($action, $a))
|
||||
$this->action = $action;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getAction()
|
||||
{
|
||||
return $this->action;
|
||||
}
|
||||
|
||||
public function buildSql()
|
||||
{
|
||||
if ($this->groupby == false)
|
||||
{
|
||||
$params = array(':action' => $this->action);
|
||||
$site_filter = $this->filter->getGvSitFilter()?: array('params' => array(), 'sql' => false);
|
||||
$report_filter = $this->filter->getReportFilter() ?: array('params' => array(), 'sql' => false);
|
||||
$record_filter = $this->filter->getRecordFilter() ?: array('params' => array(), 'sql' => false);
|
||||
$params = array_merge($params, $site_filter['params'], $report_filter['params'], $record_filter['params']);
|
||||
|
||||
$this->sql =
|
||||
"
|
||||
SELECT log.usrid, log.user , d.final as getter, d.record_id, d.date, s.*
|
||||
FROM (log_docs as d
|
||||
INNER JOIN log ON " . $site_filter['sql'] . "
|
||||
AND log.id = d.log_id
|
||||
INNER JOIN record ON record.record_id = d.record_id
|
||||
LEFT JOIN subdef as s ON s.record_id=d.record_id and s.name='document')
|
||||
WHERE";
|
||||
|
||||
$this->sql .= $report_filter['sql'] . " AND (d.action = :action)";
|
||||
|
||||
$this->sql .= $record_filter['sql'] ? " AND (" . $record_filter['sql'] . ")" : "";
|
||||
|
||||
$this->sql .= $this->filter->getOrderFilter();
|
||||
|
||||
$stmt = $this->getConnBas()->prepare($this->sql);
|
||||
|
||||
$this->total = $stmt->rowCount();
|
||||
$stmt->closeCursor();
|
||||
|
||||
$this->sql .= $this->filter->getLimitFilter() ?: '';
|
||||
|
||||
$this->params = $params;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
$params = array(':action' => $this->action);
|
||||
$site_filter = $this->filter->getGvSitFilter()?: array('params' => array(), 'sql' => false);
|
||||
$report_filter = $this->filter->getReportFilter() ?: array('params' => array(), 'sql' => false);
|
||||
$record_filter = $this->filter->getRecordFilter() ?: array('params' => array(), 'sql' => false);
|
||||
$params = array_merge($params, $site_filter['params'], $report_filter['params'], $record_filter['params']);
|
||||
|
||||
$this->sql = "
|
||||
SELECT TRIM(" . $this->getTransQuery($this->groupby) . ")
|
||||
as " . $this->groupby . ",
|
||||
SUM(1) as nombre
|
||||
FROM (log_docs as d
|
||||
INNER JOIN log ON " . $site_filter['sql'] . "
|
||||
AND log.id = d.log_id
|
||||
INNER JOIN record ON record.record_id = d.record_id
|
||||
LEFT JOIN subdef as s ON s.record_id=d.record_id and s.name='document')
|
||||
WHERE ";
|
||||
|
||||
$this->sql .= $report_filter['sql'] . " AND (d.action = :action)";
|
||||
|
||||
$this->sql .= $record_filter['sql'] ? "AND (" . $record_filter['sql'] . ")" : "";
|
||||
|
||||
$this->sql .= " GROUP BY " . $this->groupby;
|
||||
$this->sql .= $this->filter->getOrderFilter();
|
||||
|
||||
$this->params = $params;
|
||||
|
||||
$stmt = $this->getConnBas()->prepare($this->sql);
|
||||
$stmt->execute($params);
|
||||
$this->total = $stmt->rowCount();
|
||||
$stmt->closeCursor();
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function sqlDistinctValByField($field)
|
||||
{
|
||||
|
||||
$params = array();
|
||||
$site_filter = $this->filter->getGvSitFilter();
|
||||
$date_filter = $this->filter->getDateFilter();
|
||||
|
||||
$params = array_merge($params, $site_filter['params'], $date_filter['params']);//, $record_filter ? $record_filter['params'] : array()
|
||||
|
||||
$sql = "
|
||||
SELECT DISTINCT(" . $this->getTransQuery($field) . ") as val
|
||||
FROM (log_docs as d
|
||||
INNER JOIN log ON (" . $site_filter['sql'] . "
|
||||
AND log.id = d.log_id
|
||||
AND " . $date_filter['sql'] . ")
|
||||
INNER JOIN record ON (record.record_id = d.record_id)
|
||||
LEFT JOIN subdef as s ON (s.record_id=d.record_id AND s.name='document'))
|
||||
WHERE ";
|
||||
|
||||
if ($this->filter->getReportFilter())
|
||||
{
|
||||
$report_filter = $this->filter->getReportFilter();
|
||||
$sql .= $report_filter['sql'] . " AND (d.action = :action)";
|
||||
$params = array_merge($params, $report_filter['params'], array(':action' => $this->action));
|
||||
}
|
||||
$this->sql .= $this->filter->getOrderFilter();
|
||||
$this->params = $params;
|
||||
|
||||
return array('sql' => $sql, 'params' => $params);
|
||||
}
|
||||
|
||||
}
|
103
lib/classes/module/report/sqlconnexion.class.php
Normal file
103
lib/classes/module/report/sqlconnexion.class.php
Normal file
@@ -0,0 +1,103 @@
|
||||
<?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 module_report
|
||||
* @license http://opensource.org/licenses/gpl-3.0 GPLv3
|
||||
* @link www.phraseanet.com
|
||||
*/
|
||||
class module_report_sqlconnexion extends module_report_sql
|
||||
implements module_report_sqlReportInterface
|
||||
{
|
||||
|
||||
public function __construct(module_report $report)
|
||||
{
|
||||
parent::__construct($report);
|
||||
}
|
||||
|
||||
public function buildSql()
|
||||
{
|
||||
$report_filter = $this->filter->getReportFilter();
|
||||
$params = $report_filter['params'];
|
||||
|
||||
$this->params = $params;
|
||||
if ($this->groupby == false)
|
||||
{
|
||||
$this->sql = "
|
||||
SELECT
|
||||
user,
|
||||
usrid,
|
||||
log.date as ddate,
|
||||
log.societe,
|
||||
log.pays,
|
||||
log.activite,
|
||||
log.fonction,
|
||||
site,
|
||||
sit_session,
|
||||
coll_list,
|
||||
appli,
|
||||
ip
|
||||
FROM log";
|
||||
|
||||
$this->sql .= " WHERE " . $report_filter['sql'];
|
||||
$this->sql .= $this->filter->getOrderFilter() ?: '';
|
||||
|
||||
|
||||
$stmt = $this->connbas->prepare($this->sql);
|
||||
$stmt->execute($params);
|
||||
$this->total_row = $stmt->rowCount();
|
||||
$stmt->closeCursor();
|
||||
if($this->enable_limit)
|
||||
$this->sql .= $this->filter->getLimitFilter() ?: '';
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->sql = "
|
||||
SELECT TRIM(" . $this->getTransQuery($this->groupby) . ")
|
||||
as " . $this->groupby . ", SUM(1) as nb
|
||||
FROM log ";
|
||||
|
||||
if ($report_filter['sql'])
|
||||
$this->sql .= " WHERE " . $report_filter['sql'];
|
||||
|
||||
$this->sql .= " GROUP BY " . $this->groupby;
|
||||
$this->sql .= $this->filter->getOrderFilter() ?: '';
|
||||
|
||||
|
||||
|
||||
$stmt = $this->connbas->prepare($this->sql);
|
||||
$stmt->execute($params);
|
||||
$this->total_row = $stmt->rowCount();
|
||||
$stmt->closeCursor();
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function sqlDistinctValByField($field)
|
||||
{
|
||||
$report_filter = $this->filter->getReportFilter();
|
||||
$params = $report_filter['params'];
|
||||
|
||||
$sql = 'SELECT DISTINCT(' . $this->getTransQuery($field) . ') as val
|
||||
FROM log ';
|
||||
|
||||
if ($report_filter['sql'])
|
||||
$sql .= ' WHERE ' . $report_filter['sql'];
|
||||
|
||||
$sql .= ' ORDER BY val ASC';
|
||||
|
||||
return array('sql' => $sql, 'params' => $params);
|
||||
}
|
||||
|
||||
}
|
182
lib/classes/module/report/sqldownload.class.php
Normal file
182
lib/classes/module/report/sqldownload.class.php
Normal file
@@ -0,0 +1,182 @@
|
||||
<?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 module_report
|
||||
* @license http://opensource.org/licenses/gpl-3.0 GPLv3
|
||||
* @link www.phraseanet.com
|
||||
*/
|
||||
class module_report_sqldownload extends module_report_sql implements module_report_sqlReportInterface
|
||||
{
|
||||
|
||||
public function __construct(module_report $report)
|
||||
{
|
||||
parent::__construct($report);
|
||||
}
|
||||
|
||||
public function buildSql()
|
||||
{
|
||||
$registry = registry::get_instance();
|
||||
$report_filters = $this->filter->getReportFilter();
|
||||
$record_filters = $this->filter->getRecordFilter() ?: array('sql'=>'', 'params'=> array());
|
||||
$this->params = array_merge($report_filters['params'], $record_filters['params']);
|
||||
|
||||
if ($this->groupby == false)
|
||||
{
|
||||
$this->sql = "
|
||||
SELECT
|
||||
log.user,
|
||||
log.site,
|
||||
log.societe,
|
||||
log.pays,
|
||||
log.activite,
|
||||
log.fonction,
|
||||
log.usrid,
|
||||
record.coll_id,
|
||||
record.xml,
|
||||
log_docs.date AS ddate,
|
||||
log_docs.id,
|
||||
log_docs.log_id,
|
||||
log_docs.record_id,
|
||||
log_docs.final,
|
||||
log_docs.comment
|
||||
FROM (log
|
||||
INNER JOIN log_docs ON log.id = log_docs.log_id
|
||||
INNER JOIN record ON log_docs.record_id = record.record_id
|
||||
)
|
||||
WHERE ";
|
||||
|
||||
$this->sql .= $report_filters['sql'] ? : '';
|
||||
|
||||
$this->sql .= ' AND ( log_docs.action = \'download\' OR log_docs.action = \'mail\')';
|
||||
|
||||
$this->sql .= empty($record_filters['sql']) ? '' : ' AND ( ' . $record_filters['sql'] . ' )';
|
||||
|
||||
$this->sql .= $this->filter->getOrderFilter() ?: '';
|
||||
|
||||
$stmt = $this->connbas->prepare($this->sql);
|
||||
$stmt->execute($this->params);
|
||||
$this->total_row = $stmt->rowCount();
|
||||
$stmt->closeCursor();
|
||||
|
||||
$this->sql .= $this->filter->getLimitFilter() ?: '';
|
||||
}
|
||||
else
|
||||
{
|
||||
$name = $this->groupby;
|
||||
$field = $this->getTransQuery($this->groupby);
|
||||
|
||||
if ($name == 'record_id' && $this->on == 'DOC')
|
||||
{
|
||||
$this->sql = '
|
||||
SELECT
|
||||
TRIM( ' . $field . ' ) AS ' . $name . ',
|
||||
SUM(1) AS telechargement,
|
||||
record.coll_id,
|
||||
record.xml,
|
||||
log_docs.final,
|
||||
log_docs.comment,
|
||||
subdef.size,
|
||||
subdef.file,
|
||||
subdef.mime
|
||||
FROM ( log
|
||||
INNER JOIN log_docs ON log.id = log_docs.log_id
|
||||
INNER JOIN record ON log_docs.record_id = record.record_id
|
||||
INNER JOIN subdef ON (log_docs.record_id = subdef.record_id
|
||||
AND subdef.name = log_docs.final
|
||||
)
|
||||
)
|
||||
WHERE
|
||||
';
|
||||
}
|
||||
elseif ($this->on == 'DOC')
|
||||
{
|
||||
$this->sql = '
|
||||
SELECT
|
||||
TRIM(' . $field . ') AS ' . $name . ',
|
||||
SUM(1) AS telechargement
|
||||
FROM ( log
|
||||
INNER JOIN log_docs ON log.id = log_docs.log_id
|
||||
INNER JOIN record ON log_docs.record_id = record.record_id
|
||||
INNER JOIN subdef ON ( log_docs.record_id = subdef.record_id
|
||||
AND subdef.name = log_docs.final
|
||||
)
|
||||
)
|
||||
WHERE
|
||||
';
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
$this->sql = '
|
||||
SELECT
|
||||
TRIM( ' . $this->getTransQuery($this->groupby) . ') AS ' . $name . ',
|
||||
SUM(1) AS nombre
|
||||
FROM ( log
|
||||
INNER JOIN log_docs ON log.id = log_docs.log_id
|
||||
INNER JOIN record ON log_docs.record_id = record.record_id
|
||||
INNER JOIN subdef ON (record.record_id = subdef.record_id AND subdef.name = "document")
|
||||
)
|
||||
WHERE ';
|
||||
}
|
||||
|
||||
$this->sql .= $report_filters['sql'];
|
||||
|
||||
$this->sql .= ' AND ( log_docs.action = \'download\' OR log_docs.action = \'mail\')';
|
||||
|
||||
$this->sql .= empty($record_filters['sql']) ? '' : ' AND ( ' . $record_filters['sql'] . ' )';
|
||||
|
||||
$this->sql .= $this->on == 'DOC' ? 'AND subdef.name = \'document\' ' : '';
|
||||
|
||||
$this->sql .= ' GROUP BY ' . $this->groupby;
|
||||
|
||||
$this->sql .= ( $name == 'record_id' && $this->on == 'DOC') ? ' , final' : '';
|
||||
|
||||
if ($this->filter->getOrderFilter()) $this->sql .= $this->filter->getOrderFilter();
|
||||
|
||||
$stmt = $this->connbas->prepare($this->sql);
|
||||
$stmt->execute($this->params);
|
||||
$this->total = $stmt->rowCount();
|
||||
$stmt->closeCursor();
|
||||
|
||||
$this->sql .= $this->filter->getLimitFilter() ?: '';
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function sqlDistinctValByField($field)
|
||||
{
|
||||
$report_filters = $this->filter->getReportFilter();
|
||||
$params = array_merge($report_filters['params']);
|
||||
$this->params = $params;
|
||||
|
||||
$sql = '
|
||||
SELECT DISTINCT( ' . $this->getTransQuery($field) . ' ) AS val
|
||||
FROM (log
|
||||
INNER JOIN log_docs ON log.id = log_docs.log_id
|
||||
INNER JOIN record ON log_docs.record_id = record.record_id
|
||||
INNER JOIN subdef ON log_docs.record_id = subdef.record_id)
|
||||
WHERE ';
|
||||
|
||||
$sql .= $report_filters['sql'];
|
||||
$sql .= ' AND (log_docs.action = ' .
|
||||
'\'download\'OR log_docs.action = \'mail\')';
|
||||
|
||||
$sql .= $this->on == 'DOC' ? 'AND subdef.name = \'document\'' : '';
|
||||
$sql .= $this->filter->getOrderFilter() ? : '';
|
||||
$sql .= $this->filter->getLimitFilter() ? : '';
|
||||
|
||||
return array('sql' => $sql, 'params' => $params);
|
||||
}
|
||||
|
||||
}
|
281
lib/classes/module/report/sqlfilter.class.php
Normal file
281
lib/classes/module/report/sqlfilter.class.php
Normal file
@@ -0,0 +1,281 @@
|
||||
<?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 module_report
|
||||
* @license http://opensource.org/licenses/gpl-3.0 GPLv3
|
||||
* @link www.phraseanet.com
|
||||
*/
|
||||
class module_report_sqlfilter
|
||||
{
|
||||
|
||||
public $conn;
|
||||
private $filter;
|
||||
private $cor_query = array();
|
||||
|
||||
public function __construct(module_report $report)
|
||||
{
|
||||
$this->conn = connection::getPDOConnection($report->getSbasid());
|
||||
|
||||
if (is_array($report->getTransQueryString()))
|
||||
$this->cor_query = $report->getTransQueryString();
|
||||
|
||||
$this->buildFilter($report);
|
||||
}
|
||||
|
||||
public static function constructDateFilter($dmin, $dmax)
|
||||
{
|
||||
return array(
|
||||
'sql' => ($dmin && $dmax ? ' log_date.date > :date_min AND log_date.date < :date_max ' : false)
|
||||
, 'params' => ($dmin && $dmax ? array(':date_min' => $dmin, ':date_max' => $dmax) : array())
|
||||
);
|
||||
}
|
||||
|
||||
public static function constructCollectionFilter($list_coll_id)
|
||||
{
|
||||
$ret = array('sql' => '', 'params' => array());
|
||||
$coll_filter = array();
|
||||
foreach (explode(',', $list_coll_id) as $val)
|
||||
{
|
||||
$coll_filter [] = " position('," . (int) $val . ",' in concat(',' ,coll_list, ',')) > 0 ";
|
||||
}
|
||||
$ret['sql'] = implode(' OR ', $coll_filter);
|
||||
|
||||
return $ret;
|
||||
}
|
||||
|
||||
public function getCorFilter()
|
||||
{
|
||||
return $this->cor_query;
|
||||
}
|
||||
|
||||
public function getReportFilter()
|
||||
{
|
||||
$finalfilter = '';
|
||||
$registry = registry::get_instance();
|
||||
|
||||
$params = array(':log_site' => $registry->get('GV_sit'));
|
||||
|
||||
if ($this->filter['date'])
|
||||
{
|
||||
$finalfilter .= $this->filter['date']['sql'] . ' AND ';
|
||||
$params = array_merge($params, $this->filter['date']['params']);
|
||||
}
|
||||
if ($this->filter['user'])
|
||||
{
|
||||
$finalfilter .= $this->filter['user']['sql'] . ' AND ';
|
||||
$params = array_merge($params, $this->filter['user']['params']);
|
||||
}
|
||||
if ($this->filter['collection'])
|
||||
{
|
||||
$finalfilter .= '(' . $this->filter['collection']['sql'] . ') AND ';
|
||||
$params = array_merge($params, $this->filter['collection']['params']);
|
||||
}
|
||||
$finalfilter .= ' log.site = :log_site';
|
||||
|
||||
return array('sql' => $finalfilter, 'params' => $params);
|
||||
}
|
||||
|
||||
public function getGvSitFilter()
|
||||
{
|
||||
$registry = registry::get_instance();
|
||||
$params = array();
|
||||
$sql = '';
|
||||
|
||||
if ($registry->is_set('GV_sit'))
|
||||
{
|
||||
$sql = 'log.site = :log_site_gv_filter';
|
||||
$params[':log_site_gv_filter'] = $registry->get('GV_sit');
|
||||
}
|
||||
|
||||
return array('sql' => $sql, 'params' => $params);
|
||||
}
|
||||
|
||||
public function getUserIdFilter($id)
|
||||
{
|
||||
return array('sql' => "log.usrid = :usr_id_filter", 'params' => array(':usr_id_filter' => $id));
|
||||
}
|
||||
|
||||
public function getDateFilter()
|
||||
{
|
||||
return $this->filter['date'];
|
||||
}
|
||||
|
||||
public function getUserFilter()
|
||||
{
|
||||
return $this->filter['user'];
|
||||
}
|
||||
|
||||
public function getCollectionFilter()
|
||||
{
|
||||
return $this->filter['collection'];
|
||||
}
|
||||
|
||||
public function getRecordFilter()
|
||||
{
|
||||
return $this->filter['record'];
|
||||
}
|
||||
|
||||
public function getLimitFilter()
|
||||
{
|
||||
return $this->filter['limit'];
|
||||
}
|
||||
|
||||
public function getOrderFilter()
|
||||
{
|
||||
return $this->filter['order'];
|
||||
}
|
||||
|
||||
private function dateFilter(module_report $report)
|
||||
{
|
||||
$this->filter['date'] = false;
|
||||
if ($report->getDmin() && $report->getDmax())
|
||||
{
|
||||
$this->filter['date'] = array(
|
||||
'sql' => ' (log.date > :date_min_f AND log.date < :date_max_f) '
|
||||
, 'params' => array(
|
||||
':date_min_f' => $report->getDmin()
|
||||
, ':date_max_f' => $report->getDmax()
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
private function userFilter(module_report $report)
|
||||
{
|
||||
$this->filter['user'] = false;
|
||||
$f = $report->getTabFilter();
|
||||
|
||||
if (sizeof($f) > 0)
|
||||
{
|
||||
$filter = array();
|
||||
$params = array();
|
||||
$n = 0;
|
||||
foreach ($f as $field => $value)
|
||||
{
|
||||
if (array_key_exists($value['f'], $this->cor_query))
|
||||
$value['f'] = $this->cor_query[$value['f']];
|
||||
|
||||
if ($value['o'] == 'LIKE')
|
||||
{
|
||||
$filter[] = $value['f'] . ' ' . $value['o'] . ' \'%' . str_replace(array("'", '%'), array("\'", '\%'), ' :user_filter' . $n) . '%\'';
|
||||
$params[':user_filter' . $n] = $value['v'];
|
||||
}
|
||||
elseif ($value['o'] == 'OR')
|
||||
{
|
||||
$filter[] = $value['f'] . ' ' . $value['o'] . ' :user_filter' . $n;
|
||||
$params[':user_filter' . $n] = $value['v'];
|
||||
}
|
||||
else
|
||||
{
|
||||
$filter[] = $value['f'] . ' ' . $value['o'] . ' :user_filter' . $n;
|
||||
$params[':user_filter' . $n] = $value['v'];
|
||||
}
|
||||
|
||||
$n++;
|
||||
}
|
||||
$filter_user = array('sql' => implode(' AND ', $filter), 'params' => $params);
|
||||
|
||||
$this->filter['user'] = $filter_user;
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
private function collectionFilter(module_report $report)
|
||||
{
|
||||
$this->filter['collection'] = false;
|
||||
$coll_filter = array();
|
||||
|
||||
if ($report->getUserId() == '')
|
||||
|
||||
return;
|
||||
|
||||
$tab = explode(",", $report->getListCollId());
|
||||
if(count($tab) > 0)
|
||||
{
|
||||
foreach ($tab as $val)
|
||||
{
|
||||
$coll_filter[] = " position('," . (int) $val . ",' in concat(',' ,coll_list, ',')) > 0 ";
|
||||
}
|
||||
$this->filter['collection'] = array('sql' => implode(' OR ', $coll_filter), 'params' => array());
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
private function recordFilter(module_report $report)
|
||||
{
|
||||
$this->filter['record'] = false;
|
||||
$dl_coll_filter = $params = array();
|
||||
$n = 0;
|
||||
if (($report->getUserId() != ''))
|
||||
{
|
||||
$tab = explode(",", $report->getListCollId());
|
||||
foreach ($tab as $val)
|
||||
{
|
||||
$dl_coll_filter[] = "record.coll_id = :record_fil" . $n;
|
||||
$params[":record_fil" . $n] = $val;
|
||||
$n++;
|
||||
}
|
||||
$this->filter['record'] = array('sql' => implode(' OR ', $dl_coll_filter), 'params' => $params);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
private function orderFilter(module_report $report)
|
||||
{
|
||||
$this->filter['order'] = false;
|
||||
if (sizeof($report->getOrder()) > 0)
|
||||
{
|
||||
$this->filter['order'] = " ORDER BY "
|
||||
. $this->cor_query[$report->getOrder('champ')]
|
||||
. ' ' . $report->getOrder('order');
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
private function limitFilter(module_report $report)
|
||||
{
|
||||
$p = $report->getNbPage();
|
||||
$r = $report->getNbRecord();
|
||||
|
||||
$this->filter['limit'] = false;
|
||||
if ($p && $r)
|
||||
{
|
||||
$limit_inf = (int)($p - 1) * $r;
|
||||
$limit_sup = (int) $r;
|
||||
$this->filter['limit'] = " LIMIT " . $limit_inf . ', ' . $limit_sup;
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
private function buildFilter(module_report $report)
|
||||
{
|
||||
$this->dateFilter($report);
|
||||
$this->limitFilter($report);
|
||||
$this->orderFilter($report);
|
||||
$this->recordFilter($report);
|
||||
$this->userFilter($report);
|
||||
$this->collectionFilter($report);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
110
lib/classes/module/report/sqlquestion.class.php
Normal file
110
lib/classes/module/report/sqlquestion.class.php
Normal file
@@ -0,0 +1,110 @@
|
||||
<?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 module_report
|
||||
* @license http://opensource.org/licenses/gpl-3.0 GPLv3
|
||||
* @link www.phraseanet.com
|
||||
*/
|
||||
class module_report_sqlquestion extends module_report_sql implements module_report_sqlReportInterface
|
||||
{
|
||||
|
||||
public function __construct(module_report $report)
|
||||
{
|
||||
parent::__construct($report);
|
||||
}
|
||||
|
||||
public function buildSql()
|
||||
{
|
||||
$params = array();
|
||||
$report_filter = $this->filter->getReportFilter();
|
||||
$params = array_merge($params, $report_filter['params']);
|
||||
$this->params = $params;
|
||||
|
||||
if ($this->groupby == false)
|
||||
{
|
||||
$this->sql =
|
||||
"
|
||||
SELECT
|
||||
log_search.date ddate,
|
||||
search,
|
||||
usrid,
|
||||
user,
|
||||
pays,
|
||||
societe,
|
||||
activite,
|
||||
fonction
|
||||
FROM `log_search`
|
||||
INNER JOIN log
|
||||
ON log.id = log_search.log_id
|
||||
";
|
||||
|
||||
|
||||
$this->sql .= " WHERE " . $report_filter['sql'];
|
||||
|
||||
$this->sql .= $this->filter->getOrderFilter() ?: '';
|
||||
|
||||
$stmt = $this->connbas->prepare($this->sql);
|
||||
$stmt->execute($params);
|
||||
$this->total_row = $stmt->rowCount();
|
||||
$stmt->closeCursor();
|
||||
|
||||
$this->sql .= $this->filter->getLimitFilter() ?: '';
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->sql = "
|
||||
SELECT
|
||||
TRIM(" . $this->getTransQuery($this->groupby) . ") as " . $this->groupby . ",
|
||||
SUM(1) as nb
|
||||
FROM `log_search`
|
||||
INNER JOIN log
|
||||
ON log.id = log_search.log_id
|
||||
";
|
||||
|
||||
$this->sql .= " WHERE " . $report_filter['sql'];
|
||||
$this->sql .= " GROUP BY " . $this->groupby;
|
||||
$this->sql .= " ORDER BY nb DESC";
|
||||
|
||||
$stmt = $this->connbas->prepare($this->sql);
|
||||
$stmt->execute($params);
|
||||
$this->total_row = $stmt->rowCount();
|
||||
$stmt->closeCursor();
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function sqlDistinctValByField($field)
|
||||
{
|
||||
$params = array();
|
||||
$report_filter = $this->filter->getReportFilter();
|
||||
$params = array_merge($params, $report_filter['params']);
|
||||
|
||||
$sql = "
|
||||
SELECT DISTINCT(" . $this->getTransQuery($field) . ") as val
|
||||
FROM `log_search`
|
||||
INNER JOIN log
|
||||
ON log.id = log_search.log_id
|
||||
";
|
||||
|
||||
if ($report_filter['sql'])
|
||||
$sql .= ' WHERE ' . $report_filter['sql'];
|
||||
|
||||
$sql .= " ORDER BY " . $this->getTransQuery($field) . " ASC";
|
||||
|
||||
return array('sql' => $sql, 'params' => $params);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
155
lib/classes/module/report/validate.class.php
Normal file
155
lib/classes/module/report/validate.class.php
Normal file
@@ -0,0 +1,155 @@
|
||||
<?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 module_report
|
||||
* @license http://opensource.org/licenses/gpl-3.0 GPLv3
|
||||
* @link www.phraseanet.com
|
||||
*/
|
||||
class module_report_validate extends module_report
|
||||
{
|
||||
|
||||
protected $cor_query = array(
|
||||
'user' => 'log.user',
|
||||
'site' => 'log.site',
|
||||
'societe' => 'log.societe',
|
||||
'pays' => 'log.pays',
|
||||
'activite' => 'log.activite',
|
||||
'fonction' => 'log.fonction',
|
||||
'usrid' => 'log.usrid',
|
||||
'getter' => 'd.final',
|
||||
'date' => "DATE(d.date)",
|
||||
'id' => 'd.id',
|
||||
'log_id' => 'd.log_id',
|
||||
'record_id' => 'd.record_id',
|
||||
'final' => 'd.final',
|
||||
'comment' => 'd.comment',
|
||||
'size' => 's.size'
|
||||
);
|
||||
|
||||
/**
|
||||
* constructor
|
||||
*
|
||||
* @name download::__construct()
|
||||
* @param $arg1 start date of the report
|
||||
* @param $arg2 end date of the report
|
||||
* @param $sbas_id id of the databox
|
||||
*/
|
||||
public function __construct($arg1, $arg2, $sbas_id, $collist)
|
||||
{
|
||||
parent::__construct($arg1, $arg2, $sbas_id, $collist);
|
||||
$this->title = _('report:: document ajoute');
|
||||
}
|
||||
|
||||
/**
|
||||
* @desc build the specified requete
|
||||
* @param $obj $conn the current connection to databox
|
||||
* @return string
|
||||
*/
|
||||
protected function buildReq($groupby = false, $on = false)
|
||||
{
|
||||
$s = $this->sqlBuilder('action')->setGroupBy($groupby)->setOn($on)
|
||||
->setAction('validate')->buildSql();
|
||||
$this->req = $s->getSql();
|
||||
$this->params = $s->getParams();
|
||||
$this->total = $s->getTotalRows();
|
||||
}
|
||||
|
||||
public function colFilter($field, $on = false)
|
||||
{
|
||||
$s = $this->sqlBuilder('action')->setAction('validate');
|
||||
$var = $s->sqlDistinctValByField($field);
|
||||
$sql = $var['sql'];
|
||||
$params = $var['params'];
|
||||
|
||||
$stmt = $s->getConnBas()->prepare($sql);
|
||||
$stmt->execute($params);
|
||||
$rs = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
||||
$stmt->closeCursor();
|
||||
|
||||
$ret = array();
|
||||
|
||||
foreach ($rs as $row)
|
||||
{
|
||||
$value = $row['val'];
|
||||
$caption = $value;
|
||||
if ($field == "getter")
|
||||
{
|
||||
try
|
||||
{
|
||||
$user = User_Adapter::getInstance($value, $appbox);
|
||||
$caption = $user->get_display_name();
|
||||
}
|
||||
catch (Exception $e)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
elseif ($field == 'date')
|
||||
{
|
||||
$caption = phraseadate::getPrettyString(new DateTime($value));
|
||||
}
|
||||
elseif ($field == 'size')
|
||||
{
|
||||
$caption = p4string::format_octets($value);
|
||||
}
|
||||
|
||||
$ret[] = array('val' => $caption, 'value' => $value);
|
||||
}
|
||||
|
||||
return $ret;
|
||||
}
|
||||
|
||||
protected function buildResult($rs)
|
||||
{
|
||||
$i = 0;
|
||||
$pref = parent::getPreff($this->sbas_id);
|
||||
|
||||
foreach ($rs as $row)
|
||||
{
|
||||
if ($i >= $this->nb_record)
|
||||
break;
|
||||
foreach ($this->champ as $key => $value)
|
||||
{
|
||||
if ($row[$value])
|
||||
{
|
||||
if ($value == 'date')
|
||||
{
|
||||
$this->result[$i][$value] = $this->pretty_string ?
|
||||
phraseadate::getPrettyString(new DateTime($row[$value])) :
|
||||
$row[$value];
|
||||
}
|
||||
elseif ($value == 'size')
|
||||
{
|
||||
$this->result[$i][$value] = p4string::format_octets($row[$value]);
|
||||
}
|
||||
else
|
||||
$this->result[$i][$value] = $row[$value];
|
||||
}
|
||||
else
|
||||
{
|
||||
if ($value == 'comment')
|
||||
{
|
||||
$this->result[$i][$value] = ' ';
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->result[$i][$value] = '<i>' . _('report:: non-renseigne') . '</i>';
|
||||
}
|
||||
}
|
||||
}
|
||||
$i++;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user