forked from ZwiiCMS-Team/ZwiiCampus
Backup et restore okay
This commit is contained in:
parent
be7073e63f
commit
9d9db5b8ed
@ -86,16 +86,16 @@ class course extends common
|
|||||||
&& $this->getCoursesByUser($this->getUser('id'), $this->getUser('group'))
|
&& $this->getCoursesByUser($this->getUser('id'), $this->getUser('group'))
|
||||||
) {
|
) {
|
||||||
foreach ($this->getCoursesByUser($this->getUser('id'), $this->getUser('group')) as $courseId => $courseValue) {
|
foreach ($this->getCoursesByUser($this->getUser('id'), $this->getUser('group')) as $courseId => $courseValue) {
|
||||||
$categorieUrl = helper::baseUrl() . 'course/swap/' . $courseId;
|
|
||||||
$authorId = $this->getData(['course', $courseId, 'author']);
|
|
||||||
$author = isset($authorId)
|
$author = isset($authorId)
|
||||||
? sprintf('%s %s', $this->getData(['user', $authorId, 'firstname']), $this->getData(['user', $authorId, 'lastname']))
|
? sprintf('%s %s', $this->getData(['user', $authorId, 'firstname']), $this->getData(['user', $authorId, 'lastname']))
|
||||||
: '';
|
: '';
|
||||||
|
$info = sprintf('<strong>%s<br /></strong>Auteur : %s<br />Id : %s<br />', $courseValue['title'], $author, $courseId);
|
||||||
|
$categorieUrl = helper::baseUrl() . 'course/swap/' . $courseId;
|
||||||
$access = self::$courseAccess[$courseValue['access']];
|
$access = self::$courseAccess[$courseValue['access']];
|
||||||
$enrolment = self::$courseEnrolment[$courseValue['enrolment']];
|
$enrolment = self::$courseEnrolment[$courseValue['enrolment']];
|
||||||
$description = sprintf('%s<br />%s<br />%s<br />', $courseValue['description'], $access, $enrolment);
|
$description = sprintf('<strong>%s</strong><br />Accès : %s<br />Inscription : %s<br />', $courseValue['description'], $access, $enrolment);
|
||||||
self::$courses[] = [
|
self::$courses[] = [
|
||||||
$courseValue['title'],
|
$info,
|
||||||
//$author,
|
//$author,
|
||||||
'<a href="' . $categorieUrl . '" target="_blank">' . $description . '</a>',
|
'<a href="' . $categorieUrl . '" target="_blank">' . $description . '</a>',
|
||||||
template::button('categoryUser' . $courseId, [
|
template::button('categoryUser' . $courseId, [
|
||||||
@ -113,11 +113,6 @@ class course extends common
|
|||||||
'value' => template::ico('download-cloud'),
|
'value' => template::ico('download-cloud'),
|
||||||
'help' => 'Sauvegarder'
|
'help' => 'Sauvegarder'
|
||||||
]),
|
]),
|
||||||
template::button('courseUpload' . $courseId, [
|
|
||||||
'href' => helper::baseUrl() . 'course/restore/',
|
|
||||||
'value' => template::ico('upload-cloud'),
|
|
||||||
'help' => 'Restaurer',
|
|
||||||
]),
|
|
||||||
template::button('courseDelete' . $courseId, [
|
template::button('courseDelete' . $courseId, [
|
||||||
'class' => 'courseDelete buttonRed',
|
'class' => 'courseDelete buttonRed',
|
||||||
'href' => helper::baseUrl() . 'course/delete/' . $courseId,
|
'href' => helper::baseUrl() . 'course/delete/' . $courseId,
|
||||||
@ -1401,61 +1396,102 @@ class course extends common
|
|||||||
$this->isPost()
|
$this->isPost()
|
||||||
) {
|
) {
|
||||||
|
|
||||||
$zipName = $this->getInput('courseRestoreFile', null, true);
|
// Récupérer le dossier du profil
|
||||||
|
$userPath = $this->getData(['profil', $this->getuser('group'), $this->getuser('profil'), 'folder', 'path']);
|
||||||
|
$userPath = $userPath === '' ? self::$siteContent : $userPath;
|
||||||
|
// Fichier avec le bon chemin selon le profil
|
||||||
|
$zipName = self::FILE_DIR . 'source/' . $userPath . '/' . $this->getInput('courseRestoreFile', null, true);
|
||||||
|
|
||||||
|
// Existence de l'archive
|
||||||
if (
|
if (
|
||||||
$zipName !== '' &&
|
$zipName !== '' &&
|
||||||
file_exists($zipName)
|
file_exists($zipName)
|
||||||
) {
|
) {
|
||||||
// Init variables de retour
|
// Init variables de retour
|
||||||
$success = false;
|
$success = false;
|
||||||
$notification = '';
|
$notification = '';
|
||||||
// Dossier temporaire
|
// Dossier temporaire
|
||||||
$tempFolder = uniqid();
|
$tempFolder = uniqid();
|
||||||
// Ouvrir le zip
|
// Ouvrir le zip
|
||||||
$zip = new ZipArchive();
|
$zip = new ZipArchive();
|
||||||
if ($zip->open($zipName) === TRUE) {
|
if ($zip->open($zipName) === TRUE) {
|
||||||
mkdir(self::TEMP_DIR . $tempFolder, 0755);
|
mkdir(self::TEMP_DIR . $tempFolder, 0755);
|
||||||
$zip->extractTo(self::TEMP_DIR . $tempFolder);
|
$zip->extractTo(self::TEMP_DIR . $tempFolder);
|
||||||
$modele = '';
|
// Drapeaux de gestion des erreurs
|
||||||
// Archive de thème ?
|
$success = false;
|
||||||
if (
|
$notification = '';
|
||||||
file_exists(self::TEMP_DIR . $tempFolder . '/site/data/custom.css')
|
// Récupérer les données de base à intégrer
|
||||||
and file_exists(self::TEMP_DIR . $tempFolder . '/site/data/theme.css')
|
$courseData = array();
|
||||||
and file_exists(self::TEMP_DIR . $tempFolder . '/site/data/theme.json')
|
if (file_exists(self::TEMP_DIR . $tempFolder . '/course.json')) {
|
||||||
) {
|
$courseData = json_decode(file_get_contents(self::TEMP_DIR . $tempFolder . '/course.json'), true);
|
||||||
$modele = 'theme';
|
// Lire l'id du cours
|
||||||
}
|
$courseIds = array_keys($courseData);
|
||||||
if (
|
;
|
||||||
file_exists(self::TEMP_DIR . $tempFolder . '/site/data/admin.json')
|
$courseId = $courseIds[0];
|
||||||
and file_exists(self::TEMP_DIR . $tempFolder . '/site/data/admin.css')
|
$success = true;
|
||||||
) {
|
} else {
|
||||||
$modele = 'admin';
|
// Pas une archive d'espace
|
||||||
}
|
$notification = helper::translate('Archive invalide');
|
||||||
if (!empty($modele)) {
|
}
|
||||||
// traiter l'archive
|
if ($success && $courseId) {
|
||||||
$success = $zip->extractTo('.');
|
|
||||||
|
|
||||||
// Traitement
|
// récupérer les inscriptions disponibles
|
||||||
|
$enrolmentData = array();
|
||||||
// traitement d'erreur
|
if (file_exists(self::TEMP_DIR . $tempFolder . '/enrolment.json')) {
|
||||||
$notification = $success ? helper::translate('Thème importé') : helper::translate('Erreur lors de l\'extraction, vérifiez les permissions');
|
$enrolmentData = json_decode(file_get_contents(self::TEMP_DIR . $tempFolder . '/enrolment.json'), true);
|
||||||
} else {
|
}
|
||||||
// pas une archive de thème
|
|
||||||
$success = false;
|
|
||||||
$notification = helper::translate('Archive de thème invalide');
|
|
||||||
}
|
|
||||||
// Supprimer le dossier temporaire même si le thème est invalide
|
|
||||||
$this->deleteDir(self::TEMP_DIR . $tempFolder);
|
|
||||||
$zip->close();
|
|
||||||
} else {
|
|
||||||
// erreur à l'ouverture
|
|
||||||
$success = false;
|
|
||||||
$notification = helper::translate('Impossible d\'ouvrir l\'archive');
|
|
||||||
}
|
|
||||||
return (['success' => $success, 'notification' => $notification]);
|
|
||||||
}
|
|
||||||
|
|
||||||
return (['success' => false, 'notification' => helper::translate('Archive non spécifiée ou introuvable')]);
|
// Créer le dossier absent
|
||||||
|
if (!is_dir(self::DATA_DIR . $courseId)) {
|
||||||
|
mkdir(self::DATA_DIR . $courseId);
|
||||||
|
$notification = sprintf(helper::translate('Importation terminée : l\'espace %s a été créé'), $courseId);
|
||||||
|
} else {
|
||||||
|
$notification = sprintf(helper::translate('Importation terminée : l\'espace %s a été actualisé'), $courseId);
|
||||||
|
}
|
||||||
|
|
||||||
|
// traiter l'archive
|
||||||
|
$success = $zip->extractTo(self::DATA_DIR . $courseId);
|
||||||
|
$zip->close();
|
||||||
|
|
||||||
|
// Effacer les données de transport
|
||||||
|
unlink(self::DATA_DIR . $courseId . '/course.json');
|
||||||
|
unlink(self::DATA_DIR . $courseId . '/enrolment.json');
|
||||||
|
|
||||||
|
// Fusionne les deux tableaux
|
||||||
|
$c = $this->getData(['course']);
|
||||||
|
$courseData = array_merge($c, $courseData);
|
||||||
|
$e = $this->getData(['enrolment']);
|
||||||
|
$enrolmentData = array_merge($e, $enrolmentData);
|
||||||
|
|
||||||
|
// Sauvegarde les bases
|
||||||
|
$this->setData(['course', $courseData]);
|
||||||
|
$this->setData(['enrolment', $enrolmentData]);
|
||||||
|
|
||||||
|
// traitement d'erreur en cas de problème de désachivage
|
||||||
|
$notification = $success ? $notification : helper::translate('Erreur lors de l\'extraction, vérifiez les permissions');
|
||||||
|
}
|
||||||
|
// Supprimer le dossier temporaire même si le thème est invalide
|
||||||
|
$this->deleteDir(self::TEMP_DIR . $tempFolder);
|
||||||
|
} else {
|
||||||
|
// erreur à l'ouverture
|
||||||
|
$success = false;
|
||||||
|
$notification = helper::translate('Impossible d\'ouvrir l\'archive');
|
||||||
|
}
|
||||||
|
// Valeurs en sortie
|
||||||
|
$this->addOutput([
|
||||||
|
'redirect' => helper::baseUrl() . 'course',
|
||||||
|
'state' => $success,
|
||||||
|
'notification' => $notification,
|
||||||
|
]);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
// Valeurs en sortie
|
||||||
|
$this->addOutput([
|
||||||
|
'redirect' => helper::baseUrl() . 'course',
|
||||||
|
'state' => $success,
|
||||||
|
'notification' => $notification,
|
||||||
|
]);
|
||||||
|
|
||||||
}
|
}
|
||||||
// Valeurs en sortie
|
// Valeurs en sortie
|
||||||
@ -1508,10 +1544,11 @@ class course extends common
|
|||||||
if ($courseId === 'home') {
|
if ($courseId === 'home') {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
// Si un utilisateur connecté est admin aou auteur, c'est autorisé
|
// Si un utilisateur connecté est admin ou auteur, c'est autorisé
|
||||||
if (
|
if (
|
||||||
$this->getUser('password') === $this->getInput('ZWII_USER_PASSWORD') &&
|
$this->getUser('password') === $this->getInput('ZWII_USER_PASSWORD') &&
|
||||||
$this->getUser('group') === self::GROUP_ADMIN || $this->getUser('id') === $this->getData(['user', $courseId, 'author'])
|
($this->getUser('group') === self::GROUP_ADMIN ||
|
||||||
|
$this->getUser('id') === $this->getData(['course', $courseId, 'author']))
|
||||||
) {
|
) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -47,11 +47,6 @@ $(document).ready(function () {
|
|||||||
target: 5,
|
target: 5,
|
||||||
orderable: false,
|
orderable: false,
|
||||||
searchable: false
|
searchable: false
|
||||||
},
|
|
||||||
{
|
|
||||||
target: 6,
|
|
||||||
orderable: false,
|
|
||||||
searchable: false
|
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
});
|
});
|
||||||
|
@ -7,25 +7,40 @@
|
|||||||
]); ?>
|
]); ?>
|
||||||
</div>
|
</div>
|
||||||
<?php if ($this->getUser('group') === self::GROUP_ADMIN): ?>
|
<?php if ($this->getUser('group') === self::GROUP_ADMIN): ?>
|
||||||
<div class="col1 offset9">
|
<div class="col1 offset8">
|
||||||
<?php echo template::button('courseCategory', [
|
<?php echo template::button('courseUpload', [
|
||||||
'href' => helper::baseUrl() . 'course/category',
|
'href' => helper::baseUrl() . 'course/restore/',
|
||||||
'value' => template::ico('table'),
|
'value' => template::ico('upload-cloud'),
|
||||||
'help' => 'Catégories'
|
'help' => 'Restaurer'
|
||||||
]); ?>
|
]); ?>
|
||||||
</div>
|
</div>
|
||||||
<div class="col1 ">
|
<div class="col1">
|
||||||
<?php echo template::button('courseAdd', [
|
<?php echo template::button('courseCategory', [
|
||||||
'class' => 'buttonGreen',
|
'href' => helper::baseUrl() . 'course/category',
|
||||||
'href' => helper::baseUrl() . 'course/add',
|
'value' => template::ico('table'),
|
||||||
'value' => template::ico('plus'),
|
'help' => 'Catégories'
|
||||||
'help' => 'Ajouter un espace'
|
]); ?>
|
||||||
]); ?>
|
</div>
|
||||||
</div>
|
<div class="col1">
|
||||||
|
<?php echo template::button('courseAdd', [
|
||||||
|
'class' => 'buttonGreen',
|
||||||
|
'href' => helper::baseUrl() . 'course/add',
|
||||||
|
'value' => template::ico('plus'),
|
||||||
|
'help' => 'Ajouter un espace'
|
||||||
|
]); ?>
|
||||||
|
</div>
|
||||||
|
<?php else: ?>
|
||||||
|
<div class="col1 offset10">
|
||||||
|
<?php echo template::button('courseUpload', [
|
||||||
|
'href' => helper::baseUrl() . 'course/restore/',
|
||||||
|
'value' => template::ico('upload-cloud'),
|
||||||
|
'help' => 'Restaurer depuis le dossier de l\'espace ' . self::$siteContent
|
||||||
|
]); ?>
|
||||||
|
</div>
|
||||||
<?php endif; ?>
|
<?php endif; ?>
|
||||||
</div>
|
</div>
|
||||||
<?php if($module::$courses): ?>
|
<?php if ($module::$courses): ?>
|
||||||
<?php echo template::table([3, 4, 1, 1, 1, 1, 1], $module::$courses, ['Titre court', 'Description', '', '', '', '', ''], ['id' => 'dataTables']); ?>
|
<?php echo template::table([3, 4, 1, 1, 1, 1], $module::$courses, ['Titre court', 'Description', '', '', '', ''], ['id' => 'dataTables']); ?>
|
||||||
<?php else: ?>
|
<?php else: ?>
|
||||||
<?php echo template::speech('Aucun espace'); ?>
|
<?php echo template::speech('Aucun espace'); ?>
|
||||||
<?php endif; ?>
|
<?php endif; ?>
|
@ -17,7 +17,7 @@
|
|||||||
<div class="col12">
|
<div class="col12">
|
||||||
<div class="block">
|
<div class="block">
|
||||||
<h4>
|
<h4>
|
||||||
<?php echo helper::translate('Sélectionner une archive'); ?>
|
<?php echo sprintf('%s : %s', helper::translate('Restaurer depuis le dossier de l\'espace id'), self::$siteContent ); ?>
|
||||||
</h4>
|
</h4>
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col10 offset1">
|
<div class="col10 offset1">
|
||||||
|
Loading…
Reference in New Issue
Block a user