mirror of
https://github.com/alchemy-fr/Phraseanet.git
synced 2025-10-10 11:33:17 +00:00
332 lines
17 KiB
PHP
332 lines
17 KiB
PHP
<?php
|
|
|
|
/*
|
|
* This file is part of Phraseanet
|
|
*
|
|
* (c) 2005-2013 Alchemy
|
|
*
|
|
* For the full copyright and license information, please view the LICENSE
|
|
* file that was distributed with this source code.
|
|
*/
|
|
|
|
use Alchemy\Phrasea\Application;
|
|
|
|
/**
|
|
*
|
|
* @license http://opensource.org/licenses/gpl-3.0 GPLv3
|
|
* @link www.phraseanet.com
|
|
*/
|
|
function giveMeBases(Application $app, $usr = null)
|
|
{
|
|
$conn = $app['phraseanet.appbox']->get_connection();
|
|
|
|
$inscriptions = null;
|
|
|
|
$usrerRegis = null;
|
|
|
|
if ($usr != null) {
|
|
|
|
$sqlU = 'SELECT sbas.dbname, time_limited, UNIX_TIMESTAMP( limited_from ) AS limited_from,
|
|
UNIX_TIMESTAMP( limited_to ) AS limited_to, bas.server_coll_id,
|
|
usr.usr_id, basusr.actif, demand.en_cours, demand.refuser
|
|
FROM (usr, bas, sbas)
|
|
LEFT JOIN basusr
|
|
ON ( usr.usr_id = basusr.usr_id
|
|
AND bas.base_id = basusr.base_id )
|
|
LEFT JOIN demand
|
|
ON ( demand.usr_id = usr.usr_id
|
|
AND bas.base_id = demand.base_id )
|
|
WHERE bas.active >0 AND bas.sbas_id = sbas.sbas_id
|
|
AND usr.usr_id = :usr_id AND model_of = 0';
|
|
|
|
$stmt = $conn->prepare($sqlU);
|
|
$stmt->execute([':usr_id' => $usr]);
|
|
$rsU = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
|
$stmt->closeCursor();
|
|
|
|
if (count($rsU) == 0) {
|
|
return null;
|
|
}
|
|
|
|
foreach ($rsU as $rowU) {
|
|
if ( ! isset($usrerRegis[$rowU['dbname']]))
|
|
$usrerRegis[$rowU['dbname']] = null;
|
|
|
|
if ( ! is_null($rowU['actif']) || ! is_null($rowU['en_cours'])) {
|
|
|
|
$usrerRegis[$rowU['dbname']][$rowU['server_coll_id']] = true;
|
|
if ($rowU['actif'] == '0')
|
|
$usrerRegis[$rowU['dbname']][$rowU['server_coll_id']] = 'NONACTIF';
|
|
elseif ($rowU['time_limited'] == '1' && ! ($rowU['limited_from'] >= time() && $rowU['limited_to'] <= time()))
|
|
$usrerRegis[$rowU['dbname']][$rowU['server_coll_id']] = 'OUTTIME';
|
|
elseif ($rowU['time_limited'] == '1' && ($rowU['limited_from'] > time() && $rowU['limited_to'] < time()))
|
|
$usrerRegis[$rowU['dbname']][$rowU['server_coll_id']] = 'INTIME';
|
|
elseif ($rowU['en_cours'] == '1')
|
|
$usrerRegis[$rowU['dbname']][$rowU['server_coll_id']] = 'WAIT';
|
|
elseif ($rowU['refuser'] == '1')
|
|
$usrerRegis[$rowU['dbname']][$rowU['server_coll_id']] = 'REFUSE';
|
|
}
|
|
}
|
|
}
|
|
|
|
foreach ($app['phraseanet.appbox']->get_databoxes() as $databox) {
|
|
$collname = $basname = null;
|
|
$sbas_id = $databox->get_sbas_id();
|
|
$inscriptions[$sbas_id] = [];
|
|
$inscriptions[$sbas_id]['CGU'] = false;
|
|
$inscriptions[$sbas_id]['CGUrelease'] = false;
|
|
$inscriptions[$sbas_id]['inscript'] = false;
|
|
$inscriptions[$sbas_id]['CollsCGU'] = null;
|
|
$inscriptions[$sbas_id]['Colls'] = null;
|
|
$inscriptions[$sbas_id]['CollsRegistered'] = null;
|
|
$inscriptions[$sbas_id]['CollsWait'] = null;
|
|
$inscriptions[$sbas_id]['CollsRefuse'] = null;
|
|
$inscriptions[$sbas_id]['CollsIntime'] = null;
|
|
$inscriptions[$sbas_id]['CollsOuttime'] = null;
|
|
$inscriptions[$sbas_id]['CollsNonactif'] = null;
|
|
|
|
foreach ($databox->get_collections() as $key => $coll) {
|
|
$collname[$key] = $coll->get_label($app['locale.I18n']);
|
|
$basname[$key] = $coll->get_coll_id();
|
|
}
|
|
$sbpcgu = '';
|
|
|
|
$xml = $databox->get_sxml_structure();
|
|
if ($xml) {
|
|
foreach ($xml->xpath('/record/caninscript') as $caninscript) {
|
|
if ($inscriptions[$sbas_id]['inscript'] === false)
|
|
$inscriptions[$sbas_id]['inscript'] = ((string) $caninscript == "1");
|
|
}
|
|
foreach ($xml->xpath('/record/cgu') as $sbpcgu) {
|
|
foreach ($sbpcgu->attributes() as $a => $b) {
|
|
if ($a == "release")
|
|
$inscriptions[$sbas_id]['CGUrelease'] = (string) $b;
|
|
}
|
|
$inscriptions[$sbas_id]['CGU'] = (string) $sbpcgu->saveXML();
|
|
}
|
|
}
|
|
$baseInscript = $inscriptions[$sbas_id]['inscript'];
|
|
foreach ($databox->get_collections() as $collection) {
|
|
$cguColl = false;
|
|
|
|
$collInscript = $baseInscript;
|
|
$cguSpec = false;
|
|
if (false !== $xml = simplexml_load_string($collection->get_prefs())) {
|
|
foreach ($xml->xpath('/baseprefs/caninscript') as $caninscript) {
|
|
$tmp = (string) $caninscript;
|
|
if ($tmp === "1")
|
|
$collInscript = true;
|
|
elseif ($tmp === "0")
|
|
$collInscript = false;
|
|
}
|
|
if ($collInscript) {
|
|
$cguCollRelease = false;
|
|
|
|
if ($inscriptions[$sbas_id]['inscript'] === false)
|
|
$inscriptions[$sbas_id]['inscript'] = ! ! $collInscript;
|
|
|
|
foreach ($xml->xpath('/baseprefs/cgu') as $bpcgu) {
|
|
foreach ($bpcgu->attributes() as $a => $b) {
|
|
if ($a == "release")
|
|
$cguCollRelease = (string) $b;
|
|
}
|
|
$cguColl = (string) $bpcgu->saveXML();
|
|
}
|
|
if ($cguColl) {
|
|
$cguSpec = true;
|
|
} else {
|
|
if ( ! isset($usrerRegis[$databox->get_dbname()][$collection->get_coll_id()]))
|
|
$inscriptions[$sbas_id]['Colls'][$collection->get_coll_id()] = $collection->get_label($app['locale.I18n']);
|
|
}
|
|
}
|
|
}
|
|
$lacgu = $cguColl ? $cguColl : (string) $sbpcgu;
|
|
|
|
if (isset($usrerRegis[$databox->get_dbname()]) && isset($usrerRegis[$databox->get_dbname()][$collection->get_coll_id()])) {
|
|
if ($usrerRegis[$databox->get_dbname()][$collection->get_coll_id()] === "WAIT")
|
|
$inscriptions[$sbas_id]['CollsWait'][$collection->get_coll_id()] = $lacgu;
|
|
elseif ($usrerRegis[$databox->get_dbname()][$collection->get_coll_id()] === "REFUSE")
|
|
$inscriptions[$sbas_id]['CollsRefuse'][$collection->get_coll_id()] = $lacgu;
|
|
elseif ($usrerRegis[$databox->get_dbname()][$collection->get_coll_id()] === "INTIME")
|
|
$inscriptions[$sbas_id]['CollsIntime'][$collection->get_coll_id()] = $lacgu;
|
|
elseif ($usrerRegis[$databox->get_dbname()][$collection->get_coll_id()] === "OUTTIME")
|
|
$inscriptions[$sbas_id]['CollsOuttime'][$collection->get_coll_id()] = $lacgu;
|
|
elseif ($usrerRegis[$databox->get_dbname()][$collection->get_coll_id()] === "NONACTIF")
|
|
$inscriptions[$sbas_id]['CollsNonactif'][$collection->get_coll_id()] = $lacgu;
|
|
elseif ($usrerRegis[$databox->get_dbname()][$collection->get_coll_id()] === true)
|
|
$inscriptions[$sbas_id]['CollsRegistered'][$collection->get_coll_id()] = $lacgu;
|
|
} elseif (! $cguSpec && $collInscript) {//ne va pas.. si l'inscriptio na la coll est explicitement non autorise, je refuse'
|
|
$inscriptions[$sbas_id]['Colls'][$collection->get_coll_id()] = $collection->get_label($app['locale.I18n']);
|
|
} elseif ($cguSpec) {
|
|
$inscriptions[$sbas_id]['CollsCGU'][$collection->get_coll_id()]['name'] = $collection->get_label($app['locale.I18n']);
|
|
$inscriptions[$sbas_id]['CollsCGU'][$collection->get_coll_id()]['CGU'] = $cguColl;
|
|
$inscriptions[$sbas_id]['CollsCGU'][$collection->get_coll_id()]['CGUrelease'] = $cguCollRelease;
|
|
}
|
|
}
|
|
}
|
|
|
|
return $inscriptions;
|
|
}
|
|
|
|
function giveMeBaseUsr(Application $app, $usr)
|
|
{
|
|
$noDemand = true;
|
|
|
|
$out = '<table border="0" style="table-layout:fixed;font-size:11px;" cellspacing=0 width="100%">' .
|
|
'<tr>' .
|
|
'<td style="width:180px; text-align:right"> </td>' .
|
|
'<td width="15px" style="width:15px"> </td>' .
|
|
'<td style="width:180px;"> </td>' .
|
|
'</tr>';
|
|
|
|
$inscriptions = giveMeBases($app, $usr);
|
|
foreach ($inscriptions as $sbasId => $baseInsc) {
|
|
//je presente la base
|
|
if (($baseInsc['CollsRegistered'] || $baseInsc['CollsRefuse'] || $baseInsc['CollsWait'] || $baseInsc['CollsIntime'] || $baseInsc['CollsOuttime'] || $baseInsc['CollsNonactif'] || $baseInsc['CollsCGU'] || $baseInsc['Colls']))//&& $baseInsc['inscript'])
|
|
$out .= '<tr><td colspan="3" style="text-align:center;"><h3>' . phrasea::sbas_labels($sbasId, $app) . '</h3></td></tr>';
|
|
|
|
if ($baseInsc['CollsRegistered']) {
|
|
foreach ($baseInsc['CollsRegistered'] as $collId => $isTrue) {
|
|
$base_id = phrasea::baseFromColl($sbasId, $collId, $app);
|
|
$out .= '<tr><td colspan="3" style="text-align:center;">' . _('login::register: acces authorise sur la collection ') . phrasea::bas_labels($base_id, $app);
|
|
if (trim($isTrue) != '')
|
|
$out .= ' <a class="inscriptlink" href="/include/cguUtils.php?action=PRINT&bas=' . $sbasId . '&col=' . $collId . '">' . _('login::register::CGU: lire les CGU') . '</a>';
|
|
$out .= '</td></tr>';
|
|
}
|
|
$out .= '<tr style="height:5px;"><td></td></tr>';
|
|
}
|
|
if ($baseInsc['CollsRefuse']) {
|
|
foreach ($baseInsc['CollsRefuse'] as $collId => $isTrue) {
|
|
$base_id = phrasea::baseFromColl($sbasId, $collId, $app);
|
|
$out .= '<tr><td colspan="3" style="text-align:center;"><span style="color:red;">' . _('login::register: acces refuse sur la collection ') . phrasea::bas_labels($base_id, $app) . '</span>';
|
|
if (trim($isTrue) != '')
|
|
$out .= ' <a class="inscriptlink" href="/include/cguUtils.php?action=PRINT&bas=' . $sbasId . '&col=' . $collId . '">' . _('login::register::CGU: lire les CGU') . '</a>';
|
|
$out .= '</td></tr>';
|
|
}
|
|
$out .= '<tr style="height:5px;"><td></td></tr>';
|
|
}
|
|
if ($baseInsc['CollsWait']) {
|
|
foreach ($baseInsc['CollsWait'] as $collId => $isTrue) {
|
|
$base_id = phrasea::baseFromColl($sbasId, $collId, $app);
|
|
$out .= '<tr><td colspan="3" style="text-align:center;"><span style="color:orange;">' . _('login::register: en attente d\'acces sur') . ' ' . phrasea::bas_labels($base_id, $app) . '</span>';
|
|
if (trim($isTrue) != '')
|
|
$out .= ' <a class="inscriptlink" href="/include/cguUtils.php?action=PRINT&bas=' . $sbasId . '&col=' . $collId . '">' . _('login::register::CGU: lire les CGU') . '</a>';
|
|
$out .= '</td></tr>';
|
|
}
|
|
$out .= '<tr style="height:5px;"><td></td></tr>';
|
|
}
|
|
if ($baseInsc['CollsIntime']) {
|
|
foreach ($baseInsc['CollsIntime'] as $collId => $isTrue) {
|
|
$base_id = phrasea::baseFromColl($sbasId, $collId, $app);
|
|
$out .= '<tr><td colspan="3" style="text-align:center;">' . _('login::register: acces temporaire sur') . phrasea::bas_labels($base_id, $app) . '</span>';
|
|
if (trim($isTrue) != '')
|
|
$out .= ' <a class="inscriptlink" href="/include/cguUtils.php?action=PRINT&bas=' . $sbasId . '&col=' . $collId . '">' . _('login::register::CGU: lire les CGU') . '</a>';
|
|
$out .= '</td></tr>';
|
|
}
|
|
$out .= '<tr style="height:5px;"><td></td></tr>';
|
|
}
|
|
if ($baseInsc['CollsOuttime']) {
|
|
foreach ($baseInsc['CollsOuttime'] as $collId => $isTrue) {
|
|
$base_id = phrasea::baseFromColl($sbasId, $collId, $app);
|
|
$out .= '<tr><td colspan="3" style="text-align:center;"><span style="color:red;">' . _('login::register: acces temporaire termine sur ') . phrasea::bas_labels($base_id, $app) . '</span>';
|
|
if (trim($isTrue) != '')
|
|
$out .= ' <a class="inscriptlink" href="/include/cguUtils.php?action=PRINT&bas=' . $sbasId . '&col=' . $collId . '">' . _('login::register::CGU: lire les CGU') . '</a>';
|
|
$out .= '</td></tr>';
|
|
}
|
|
$out .= '<tr style="height:5px;"><td></td></tr>';
|
|
}
|
|
if ($baseInsc['CollsNonactif']) {
|
|
foreach ($baseInsc['CollsNonactif'] as $collId => $isTrue) {
|
|
$base_id = phrasea::baseFromColl($sbasId, $collId, $app);
|
|
$out .= '<tr><td colspan="3" style="text-align:center;"><span style="color:red;">' . _('login::register: acces supendu sur') . phrasea::bas_labels($base_id, $app) . '</span>';
|
|
if (trim($isTrue) != '')
|
|
$out .= ' <a class="inscriptlink" href="/include/cguUtils.php?action=PRINT&bas=' . $sbasId . '&col=' . $collId . '">' . _('login::register::CGU: lire les CGU') . '</a>';
|
|
$out .= '</td></tr>';
|
|
}
|
|
$out .= '<tr style="height:5px;"><td></td></tr>';
|
|
}
|
|
|
|
$out .= '<tr style="height:5px;"><td></td></tr>';
|
|
if (($baseInsc['CollsCGU'] || $baseInsc['Colls']) && $baseInsc['inscript']) {// il y a des coll ou s'inscrire !
|
|
$noDemand = false;
|
|
|
|
if ($baseInsc['Colls']) {//des coll ou on peut s'inscrire sans cgu specifiques
|
|
//je check si ya des cgu pour la base
|
|
if ($baseInsc['CGU']) {
|
|
$out .= '<tr><td colspan="3" style="text-align:center;">' . _('login::register: L\'acces aux bases ci-dessous implique l\'acceptation des Conditions Generales d\'Utilisation (CGU) suivantes') . '</td></tr>';
|
|
$out .= '<tr><td colspan="3" style="text-align:center;"><div style="width:90%;height:120px;text-align:left;overflow:auto;">' . $baseInsc['CGU'] . '</div></td></tr>';
|
|
}
|
|
foreach ($baseInsc['Colls'] as $collId => $collName) {
|
|
$base_id = phrasea::baseFromColl($sbasId, $collId, $app);
|
|
$out .= '<tr>' .
|
|
'<td style="text-align:right;">' . $collName . '</td>' .
|
|
'<td></td>' .
|
|
'<td class="TD_R" style="width:200px;">' .
|
|
'<input style="width:15px;" class="checkbox" type="checkbox" name="demand[]" value="' . $base_id . '" >' .
|
|
'<span>' . _('login::register: Faire une demande d\'acces') . '</span>' .
|
|
'</td>' .
|
|
'</tr>';
|
|
}
|
|
}
|
|
if ($baseInsc['CollsCGU']) {
|
|
foreach ($baseInsc['CollsCGU'] as $collId => $collDesc) {
|
|
$base_id = phrasea::baseFromColl($sbasId, $collId, $app);
|
|
$out .= '<tr><td colspan="3" style="text-align:center;"><hr style="width:80%"/></td></tr>' .
|
|
'<tr><td colspan="3" style="text-align:center;">' . _('login::register: L\'acces aux bases ci-dessous implique l\'acceptation des Conditions Generales d\'Utilisation (CGU) suivantes') . '</td></tr>' .
|
|
'<tr>' .
|
|
'<td colspan="3" style="text-align:center;">' .
|
|
'<div style="width:90%;height:120px;text-align:left;overflow:auto;">' . $collDesc['CGU'] . '</div>' .
|
|
'</td>' .
|
|
'</tr>' .
|
|
'<tr >' .
|
|
'<td style="text-align:right;">' . $collDesc['name'] . '</td>' .
|
|
'<td></td>' .
|
|
'<td class="TD_R" style="width:200px;">' .
|
|
'<input style="width:15px;" class="checkbox" type="checkbox" name="demand[]" value="' . $base_id . '" >' .
|
|
'<span>' . _('login::register: Faire une demande d\'acces') . '</span>' .
|
|
'</td>' .
|
|
'</tr>';
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
$out .= '</table>';
|
|
|
|
return ['tab' => $out, 'demandes' => $noDemand];
|
|
}
|
|
|
|
function giveModInscript($usr, $lng)
|
|
{
|
|
$out = '<html lang="' . $app['session.I18n'] . '">' .
|
|
'<head>' .
|
|
'</head>' .
|
|
'<body>' .
|
|
'<div style="width:600px;height:20px;text-align:center;margin:0">' . _('admin::compte-utilisateur actuellement, acces aux bases suivantes : ') . ' :</div>' .
|
|
'<form id="conf_mod" target="_self" action="mod_inscript.php" method="post">' .
|
|
'<div style="width:400px;center;margin:0 100px;">';
|
|
|
|
$demandes = giveMeBaseUsr($app, $usr);
|
|
|
|
$out .= $demandes['tab'];
|
|
|
|
$noDemand = $demandes['demandes'];
|
|
$out .= '</div>' .
|
|
'<input type="hidden" value="' . $lng . '" name="lng">' .
|
|
'<input type="hidden" value="SEND" name="act">' .
|
|
'<input type="hidden" value="' . $usr . '" name="usrid">' .
|
|
'</form>';
|
|
|
|
if ($noDemand) {
|
|
$out .= '<div style="margin:10px 0;width:600px;text-align:center;">' . _('login::register: Vous avez acces a toutes les collections de toutes les bases') . '</div>';
|
|
} else {
|
|
$out .= '<div style="margin:10px 0;width:600px;text-align:center;"><input type="button" value="' . _('login::register: confirmer la demande') . '" onclick="document.getElementById(\'conf_mod\').submit();" /></a></div>';
|
|
}
|
|
|
|
$out .= '</div>' .
|
|
'</body>' .
|
|
'</html>';
|
|
|
|
return $out;
|
|
}
|