From 021f8c6441d252516cf13b0388c1189e5a5f89d1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Loguercio?= Date: Thu, 21 Apr 2016 19:46:48 -0500 Subject: [PATCH 01/23] Fix url opengraph code for social wall --- app/Resources/public/css/base.css | 12 ++++++++ main/inc/ajax/social.ajax.php | 6 ++-- main/inc/lib/social.lib.php | 21 +++++++++----- main/social/profile.php | 46 +++++++++++++++++++++++++++++-- 4 files changed, 74 insertions(+), 11 deletions(-) diff --git a/app/Resources/public/css/base.css b/app/Resources/public/css/base.css index ec8a76f70e..aef58e26a5 100644 --- a/app/Resources/public/css/base.css +++ b/app/Resources/public/css/base.css @@ -708,6 +708,18 @@ a.personal_agenda:hover, a.personal_agenda:hover { .social-home-anonymous-online { width: 200px; } +.social-thumbnail { + padding: 0px; +} +.social-title { + font-size: 18px; + font-family: helvetica, arial, sans-serif; + color: #000; +} +.social-description { + padding: 8px; + color: #000; +} .menulist { margin: 0px; diff --git a/main/inc/ajax/social.ajax.php b/main/inc/ajax/social.ajax.php index 2a44c40fa0..cf6680d181 100755 --- a/main/inc/ajax/social.ajax.php +++ b/main/inc/ajax/social.ajax.php @@ -225,13 +225,15 @@ switch ($action) { // Read the Url using OpenGraph and returns the hyperlinks content case 'readUrlWithOpenGraph': $url = isset($_POST['social_wall_new_msg_main']) ? $_POST['social_wall_new_msg_main'] : ''; + $url = trim($url); $html = ''; - if (SocialManager::verifyUrl($url) == true){ + if (SocialManager::verifyUrl($url) == true && !$_SESSION['ogSearch']) { + $_SESSION['ogSearch'] = true; $html = Security::remove_XSS( SocialManager::readContentWithOpenGraph($url) ); } - echo utf8_decode($html); + echo $html; break; default: echo ''; diff --git a/main/inc/lib/social.lib.php b/main/inc/lib/social.lib.php index dabfd84a90..584590312f 100755 --- a/main/inc/lib/social.lib.php +++ b/main/inc/lib/social.lib.php @@ -1565,16 +1565,21 @@ class SocialManager extends UserManager */ public static function readContentWithOpenGraph($link) { + $domain = parse_url($link); + $domain['scheme'] = isset($domain['scheme']) ? $domain['scheme'] : 'http'; + $domain['host'] = isset($domain['host']) ? $domain['host'] : $domain['path'] ? $domain['path'] : $link; + $graph = OpenGraph::fetch($link); if (!$graph) { return false; } + $url = $graph->url; $image = $graph->image; - $domain = empty($url) ? parse_url($link) : parse_url($url); + $description = $graph->description; $domain = $domain['scheme'].'://'.$domain['host']; // Trick to verify if the Image Url Exist because of some bad metatag dev - if (self::verifyUrl($image) == false){ + if (self::verifyUrl($image) == false && $image){ if (!($image[0] == '/')){ $domain = $domain . '/'; } @@ -1582,11 +1587,13 @@ class SocialManager extends UserManager } $title = $graph->title; - $html = '
'; - $html .= '

'.$title.'

'; - $html .= empty($image) ? '' : '
'; - $html .= empty($graph->description) ? '' : '

'.$graph->description.'

'; - $html .= ''.$link.''; + $html = ''; return $html; diff --git a/main/social/profile.php b/main/social/profile.php index 687b7daad1..adbe69a578 100755 --- a/main/social/profile.php +++ b/main/social/profile.php @@ -27,6 +27,10 @@ $show_full_profile = true; //social tab $this_section = SECTION_SOCIAL; +//Default OpenGraph search time +unset($_SESSION['ogSearch']); +$_SESSION['ogSearch'] = false; + //Initialize blocks $social_extra_info_block = null; $social_course_block = null; @@ -301,8 +305,11 @@ $socialAutoExtendLink = Display::url( // Added a Jquery Function to return the Preview of OpenGraph URL Content $htmlHeadXtra[] = ''; From 8372f72f4541b800758c52ceda6a4ba2ccd27934 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Loguercio?= Date: Mon, 25 Apr 2016 17:59:15 -0500 Subject: [PATCH 02/23] Implement better design for social wall messages and OpenGraph markup --- app/Resources/public/css/base.css | 6 +++++ main/inc/ajax/social.ajax.php | 3 +-- main/inc/lib/social.lib.php | 27 +++++++------------- main/social/profile.php | 42 +------------------------------ 4 files changed, 17 insertions(+), 61 deletions(-) diff --git a/app/Resources/public/css/base.css b/app/Resources/public/css/base.css index aef58e26a5..cba0efcc52 100644 --- a/app/Resources/public/css/base.css +++ b/app/Resources/public/css/base.css @@ -720,6 +720,12 @@ a.personal_agenda:hover, a.personal_agenda:hover { padding: 8px; color: #000; } +.social-image { + max-height: 300px; +} +.social-host { + color: #999; +} .menulist { margin: 0px; diff --git a/main/inc/ajax/social.ajax.php b/main/inc/ajax/social.ajax.php index cf6680d181..cc139129b9 100755 --- a/main/inc/ajax/social.ajax.php +++ b/main/inc/ajax/social.ajax.php @@ -227,8 +227,7 @@ switch ($action) { $url = isset($_POST['social_wall_new_msg_main']) ? $_POST['social_wall_new_msg_main'] : ''; $url = trim($url); $html = ''; - if (SocialManager::verifyUrl($url) == true && !$_SESSION['ogSearch']) { - $_SESSION['ogSearch'] = true; + if (SocialManager::verifyUrl($url) == true) { $html = Security::remove_XSS( SocialManager::readContentWithOpenGraph($url) ); diff --git a/main/inc/lib/social.lib.php b/main/inc/lib/social.lib.php index 584590312f..a73789804b 100755 --- a/main/inc/lib/social.lib.php +++ b/main/inc/lib/social.lib.php @@ -1565,34 +1565,25 @@ class SocialManager extends UserManager */ public static function readContentWithOpenGraph($link) { - $domain = parse_url($link); - $domain['scheme'] = isset($domain['scheme']) ? $domain['scheme'] : 'http'; - $domain['host'] = isset($domain['host']) ? $domain['host'] : $domain['path'] ? $domain['path'] : $link; - + if(strpos($link,"://")===false && substr($link,0,1)!="/") $link = "http://".$link; $graph = OpenGraph::fetch($link); + $link = parse_url($link); + $host = $link['host'] ? strtoupper($link['host']) : $link['path']; if (!$graph) { return false; } - $url = $graph->url; $image = $graph->image; $description = $graph->description; - $domain = $domain['scheme'].'://'.$domain['host']; - // Trick to verify if the Image Url Exist because of some bad metatag dev - if (self::verifyUrl($image) == false && $image){ - if (!($image[0] == '/')){ - $domain = $domain . '/'; - } - $image = $domain . $image; - } $title = $graph->title; - $html = ''; @@ -1914,7 +1905,7 @@ class SocialManager extends UserManager $post = $message['html']; $comment = SocialManager::getWallMessagesHTML($userId, $friendId, $message['id']); - $html .= $post.$comment; + $html .= Display::panel($post.$comment, ''); } return $html; diff --git a/main/social/profile.php b/main/social/profile.php index adbe69a578..e74de75882 100755 --- a/main/social/profile.php +++ b/main/social/profile.php @@ -27,10 +27,6 @@ $show_full_profile = true; //social tab $this_section = SECTION_SOCIAL; -//Default OpenGraph search time -unset($_SESSION['ogSearch']); -$_SESSION['ogSearch'] = false; - //Initialize blocks $social_extra_info_block = null; $social_course_block = null; @@ -291,8 +287,7 @@ $social_wall_block = $wallSocialAddPost; // Social Post Wall $posts = SocialManager::getWallMessagesByUser($my_user_id, $friendId) ; -$posts = empty($posts) ? '

'.get_lang("NoPosts").'

' : $posts; -$social_post_wall_block = Display::panel($posts, get_lang('Posts')); +$social_post_wall_block = empty($posts) ? '

'.get_lang("NoPosts").'

' : $posts; $socialAutoExtendLink = Display::url( get_lang('SeeMore'), @@ -339,41 +334,6 @@ $(document).ready(function() { } }); }); - - getUrl.keyup(function(e) { - if (e.keyCode == 32) { - if (matchUrl.test(getUrl.val())) { - $.ajax({ - contentType: "application/x-www-form-urlencoded", - beforeSend: function() { - $("[name=\'wall_post_button\']").prop( "disabled", true ); - $(".panel-preview").hide(); - $(".spinner").html("' . - '
' . - '' . - '

' . get_lang('Loading') . ' ' . get_lang('Preview') . '

' . - '
' . - '"); - }, - type: "POST", - url: "' . api_get_path(WEB_AJAX_PATH) . 'social.ajax.php?a=readUrlWithOpenGraph", - data: "social_wall_new_msg_main=" + getUrl.val(), - success: function(response) { - $("[name=\'wall_post_button\']").prop( "disabled", false ); - if (!response == false) { - $(".spinner").html(""); - $(".panel-preview").show(); - $(".url_preview").html(response); - $("[name=\'url_content\']").val(response); - $(".url_preview img").addClass("img-responsive"); - } else { - $(".spinner").html(""); - } - } - }); - } - } - }); }); '; From a46ac3f5db2729771cf431504f6717a475c37a90 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Loguercio?= Date: Wed, 27 Apr 2016 18:10:47 -0500 Subject: [PATCH 03/23] Added Post popularity and improve design in social wall --- app/Resources/public/css/base.css | 22 ++++++++++++++++------ main/inc/lib/social.lib.php | 5 ++--- 2 files changed, 18 insertions(+), 9 deletions(-) diff --git a/app/Resources/public/css/base.css b/app/Resources/public/css/base.css index cba0efcc52..076b1f9f27 100644 --- a/app/Resources/public/css/base.css +++ b/app/Resources/public/css/base.css @@ -723,7 +723,11 @@ a.personal_agenda:hover, a.personal_agenda:hover { .social-image { max-height: 300px; } -.social-host { +.social-host p {; + padding: 10px; + margin-top: 5px; + margin-bottom: 5px; + line-height: 22px; color: #999; } @@ -4008,6 +4012,12 @@ i.size-32.icon-new-work{ max-width: 50px; max-height: 50px; } +.top-mediapost { + border-bottom: 1px solid #ECF0F1; +} +.popularity-mediapost { + margin-bottom: 30px; +} .top-mediapost .user-image, .sub-mediapost .user-image { @@ -4035,13 +4045,13 @@ i.size-32.icon-new-work{ } .top-mediapost .msg-content p, .sub-mediapost .rep-post .msg-content p{ - border-top:1px solid #ECF0F1; - padding-top: 10px; - padding-bottom: 10px; + /* border-top:1px solid #ECF0F1; */ + /* padding-top: 10px; */ + /* padding-bottom: 20px; */ margin-top: 5px; - margin-bottom: 5px; + margin-bottom: 20px; line-height: 22px; - padding-left: 10px; + /* padding-left: 10px; */ padding-right: 10px; color: #666666; } diff --git a/main/inc/lib/social.lib.php b/main/inc/lib/social.lib.php index a73789804b..8b6b240f19 100755 --- a/main/inc/lib/social.lib.php +++ b/main/inc/lib/social.lib.php @@ -1554,6 +1554,7 @@ class SocialManager extends UserManager $html .= '

'. Security::remove_XSS($message['content']).'

'; $html .= '
'; $html .= ''; // end mediaPost + $html .= '
0 '.get_lang('Votes').'
'; return $html; } @@ -1581,9 +1582,7 @@ class SocialManager extends UserManager $html .= '
'; $html .= ''; $html .= empty($description) ? '' : ''.$description.''; - $html .= '
'; - $html .= '
'; - $html .= empty($host) ? '' : ''; + $html .= empty($host) ? '' : '

'.$host.'

'; $html .= '
'; $html .= ''; From e91382db59367f4acfdb8e47b318fa0f47e8734c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Loguercio?= Date: Wed, 25 May 2016 12:31:43 -0500 Subject: [PATCH 04/23] App Bootstrap Cache version changes --- app/bootstrap.php.cache | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/app/bootstrap.php.cache b/app/bootstrap.php.cache index 09b077c768..35212edfb3 100644 --- a/app/bootstrap.php.cache +++ b/app/bootstrap.php.cache @@ -2428,12 +2428,12 @@ protected $booted = false; protected $name; protected $startTime; protected $loadClassCache; -const VERSION ='2.8.4-DEV'; -const VERSION_ID = 20804; +const VERSION ='2.8.6'; +const VERSION_ID = 20806; const MAJOR_VERSION = 2; const MINOR_VERSION = 8; -const RELEASE_VERSION = 4; -const EXTRA_VERSION ='DEV'; +const RELEASE_VERSION = 6; +const EXTRA_VERSION =''; const END_OF_MAINTENANCE ='11/2018'; const END_OF_LIFE ='11/2019'; public function __construct($environment, $debug) @@ -2883,8 +2883,9 @@ return true; } public function findFile($class) { -if (false === $file = apcu_fetch($this->prefix.$class)) { -apcu_store($this->prefix.$class, $file = $this->decorated->findFile($class)); +$file = apcu_fetch($this->prefix.$class, $success); +if (!$success) { +apcu_store($this->prefix.$class, $file = $this->decorated->findFile($class) ?: null); } return $file; } From 50835f07bab26700ea26469312f709bd21514955 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Loguercio?= Date: Wed, 25 May 2016 18:06:22 -0500 Subject: [PATCH 05/23] Added Post Answer better design and fix popularity vote --- app/Resources/public/css/base.css | 8 +++++ main/inc/ajax/social.ajax.php | 2 ++ main/inc/lib/social.lib.php | 40 +++++++++++++++-------- src/Chamilo/CoreBundle/Entity/Message.php | 30 +++++++++++++++++ 4 files changed, 67 insertions(+), 13 deletions(-) diff --git a/app/Resources/public/css/base.css b/app/Resources/public/css/base.css index e47a135ee6..0e020e4f0e 100644 --- a/app/Resources/public/css/base.css +++ b/app/Resources/public/css/base.css @@ -725,6 +725,10 @@ a.personal_agenda:hover, a.personal_agenda:hover { .social-image { max-height: 300px; } +.social-post-answers { + padding-right: 0px; + padding-left: 0px; +} .social-host p {; padding: 10px; margin-top: 5px; @@ -3849,6 +3853,10 @@ i.size-32.icon-new-work{ } .popularity-mediapost { margin-bottom: 30px; + font-size: 1.2em; +} +.popularity-vote-found { + color: #FFD700; } .top-mediapost .user-image, .sub-mediapost .user-image diff --git a/main/inc/ajax/social.ajax.php b/main/inc/ajax/social.ajax.php index cc139129b9..66a3ce22af 100755 --- a/main/inc/ajax/social.ajax.php +++ b/main/inc/ajax/social.ajax.php @@ -234,6 +234,8 @@ switch ($action) { } echo $html; break; + case 'voteMsg': + default: echo ''; } diff --git a/main/inc/lib/social.lib.php b/main/inc/lib/social.lib.php index 052e3d5b23..2a6af05a39 100755 --- a/main/inc/lib/social.lib.php +++ b/main/inc/lib/social.lib.php @@ -1359,6 +1359,7 @@ class SocialManager extends UserManager send_date, content, parent_id, + votes, (SELECT ma.path FROM $tblMessageAttachment ma WHERE ma.message_id = tm.id ) as path, (SELECT ma.filename FROM $tblMessageAttachment ma @@ -1419,23 +1420,28 @@ class SocialManager extends UserManager $url = api_get_path(WEB_CODE_PATH).'social/profile.php?u='.$userIdLoop; $media = ''; $media .= '
'; - if ($isOwnWall) { - $media .= '
'; - $media .= 'x'; - $media .= '
'; - } - $media .= '
'; + $media .= ''; + $media .= ''; - $media .= '
'; - $media .= '

'.Security::remove_XSS($message['content']).'

'; - $media .= '
'; + $media .= '
'; + if ($isOwnWall) { + $media .= ''; + } $formattedList .= $media; } @@ -1567,7 +1573,13 @@ class SocialManager extends UserManager $html .= '

'. Security::remove_XSS($message['content']).'

'; $html .= ''; $html .= ''; // end mediaPost - $html .= '
0 '.get_lang('Votes').'
'; + + // Popularity post functionality + $classIcon = 'fa fa-star-o'; + if (intval($message['votes'])) { + $classIcon = 'fa fa-star popularity-vote-found'; + } + $html .= '
'.$message['votes'].'
'; return $html; } @@ -1579,7 +1591,9 @@ class SocialManager extends UserManager */ public static function readContentWithOpenGraph($link) { - if(strpos($link,"://")===false && substr($link,0,1)!="/") $link = "http://".$link; + if (strpos($link, "://") === false && substr($link, 0, 1) != "/") { + $link = "http://".$link; + } $graph = OpenGraph::fetch($link); $link = parse_url($link); $host = $link['host'] ? strtoupper($link['host']) : $link['path']; diff --git a/src/Chamilo/CoreBundle/Entity/Message.php b/src/Chamilo/CoreBundle/Entity/Message.php index 06afd82893..6a094c5a97 100644 --- a/src/Chamilo/CoreBundle/Entity/Message.php +++ b/src/Chamilo/CoreBundle/Entity/Message.php @@ -75,6 +75,13 @@ class Message */ private $updateDate; + /** + * @var integer + * + * @ORM\Column(name="votes", type="integer", nullable=true) + */ + private $votes; + /** * @var integer * @@ -302,4 +309,27 @@ class Message { return $this->id; } + + /** + * Set votes + * + * @param integer $votes + * @return integer + */ + public function setVotes($votes) + { + $this->votes = $votes; + + return $this; + } + + /** + * Get votes + * + * @return integer + */ + public function getVotes() + { + return $this->votes; + } } From a308cb81ff467d6017395ef35afcb677e09ff35b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Loguercio?= Date: Fri, 24 Jun 2016 19:13:38 -0500 Subject: [PATCH 06/23] WIP - Import from Moodle --- main/course_info/maintenance.php | 3 + main/coursecopy/import_moodle.php | 58 +++++++++++++++++++ main/inc/lib/MoodleImport.lib.php | 25 ++++++++ .../default/coursecopy/import_moodle.tpl | 4 ++ 4 files changed, 90 insertions(+) create mode 100644 main/coursecopy/import_moodle.php create mode 100644 main/inc/lib/MoodleImport.lib.php create mode 100644 main/template/default/coursecopy/import_moodle.tpl diff --git a/main/course_info/maintenance.php b/main/course_info/maintenance.php index bc70304701..3e7e27eedd 100755 --- a/main/course_info/maintenance.php +++ b/main/course_info/maintenance.php @@ -30,6 +30,9 @@ echo Display::page_header($nameTools);

  • +

  • + +
  • diff --git a/main/coursecopy/import_moodle.php b/main/coursecopy/import_moodle.php new file mode 100644 index 0000000000..edbabd2cac --- /dev/null +++ b/main/coursecopy/import_moodle.php @@ -0,0 +1,58 @@ + + * @package chamilo.backup + */ + +require_once '../inc/global.inc.php'; +require_once '../inc/lib/MoodleImport.lib.php'; + +$current_course_tool = TOOL_COURSE_MAINTENANCE; +api_protect_course_script(true); + +// Check access rights (only teachers are allowed here) +if (!api_is_allowed_to_edit()) { + api_not_allowed(true); +} + +// Remove memory and time limits as much as possible as this might be a long process... +if (function_exists('ini_set')) { + api_set_memory_limit('256M'); + ini_set('max_execution_time', 1800); +} + +// Section for the tabs +$this_section = SECTION_COURSES; + +// Breadcrumbs +$interbreadcrumb[] = array( + 'url' => '../course_info/maintenance.php', + 'name' => get_lang('Maintenance') +); + +$form = new FormValidator('import_moodle'); +$form->addFile('moodle_file', get_lang('MoodleFile')); +$form->addButtonImport(get_lang('Import')); + +if ($form->validate()) { + $file = $_FILES['moodle_file']['tmp_name']; + $moodleImport = new MoodleImport(); + var_dump($moodleImport->readMoodleFile($file)); +} + +$templateName = get_lang('ImportFromMoodle'); + +$template = new Template($templateName); +$infoMsg = Display::return_message(get_lang('ImportFromMoodleInstructions')); +$template->assign('info_msg', $infoMsg); +$template->assign('form', $form->returnForm()); +$content = $template->fetch('default/coursecopy/import_moodle.tpl'); + +$template->assign('header', $templateName); +$template->assign('content', $content); + +$template->display_one_col_template(); \ No newline at end of file diff --git a/main/inc/lib/MoodleImport.lib.php b/main/inc/lib/MoodleImport.lib.php new file mode 100644 index 0000000000..4e89b690d3 --- /dev/null +++ b/main/inc/lib/MoodleImport.lib.php @@ -0,0 +1,25 @@ + + * @package chamilo.library + */ + +class MoodleImport +{ + /** + * @param resource $file *.* mbz file moodle course backup + * @return bool + */ + public function readMoodleFile($file) + { + if (is_file($file) && is_readable($file) && ($xml = @file_get_contents($file))) { + $package = new PclZip($file); + $packageContent = $package->listContent(); + return $packageContent; + } + } +} \ No newline at end of file diff --git a/main/template/default/coursecopy/import_moodle.tpl b/main/template/default/coursecopy/import_moodle.tpl new file mode 100644 index 0000000000..07a5bc4770 --- /dev/null +++ b/main/template/default/coursecopy/import_moodle.tpl @@ -0,0 +1,4 @@ +{{ info_msg }} +
    +
    +{{ form }} \ No newline at end of file From 7c2e9f49ba0a277845ddab00a1047ff17f04fe09 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Loguercio?= Date: Thu, 7 Jul 2016 20:12:12 -0500 Subject: [PATCH 07/23] WIP - MoodleImport 90% --- main/coursecopy/import_moodle.php | 4 +- main/inc/lib/MoodleImport.lib.php | 198 +++++++++++++++++++++++++++++- 2 files changed, 196 insertions(+), 6 deletions(-) diff --git a/main/coursecopy/import_moodle.php b/main/coursecopy/import_moodle.php index edbabd2cac..14b351051a 100644 --- a/main/coursecopy/import_moodle.php +++ b/main/coursecopy/import_moodle.php @@ -39,9 +39,9 @@ $form->addFile('moodle_file', get_lang('MoodleFile')); $form->addButtonImport(get_lang('Import')); if ($form->validate()) { - $file = $_FILES['moodle_file']['tmp_name']; + $file = $_FILES['moodle_file']; $moodleImport = new MoodleImport(); - var_dump($moodleImport->readMoodleFile($file)); + $moodleImport->readMoodleFile($file); } $templateName = get_lang('ImportFromMoodle'); diff --git a/main/inc/lib/MoodleImport.lib.php b/main/inc/lib/MoodleImport.lib.php index 4e89b690d3..96f23ebc48 100644 --- a/main/inc/lib/MoodleImport.lib.php +++ b/main/inc/lib/MoodleImport.lib.php @@ -11,15 +11,205 @@ class MoodleImport { /** - * @param resource $file *.* mbz file moodle course backup + * Read and validate the moodleFile + * + * @param resource $uploadedFile *.* mbz file moodle course backup * @return bool */ - public function readMoodleFile($file) + public function readMoodleFile($uploadedFile) { - if (is_file($file) && is_readable($file) && ($xml = @file_get_contents($file))) { + $file = $uploadedFile['tmp_name']; + + if (is_file($file) && is_readable($file)) { $package = new PclZip($file); $packageContent = $package->listContent(); - return $packageContent; + $mainFileKey = 0; + foreach ($packageContent as $index => $value) { + if ($value['filename'] == 'moodle_backup.xml') { + $mainFileKey = $index; + break; + } + } + + if (!$mainFileKey) { + Display::addFlash(Display::return_message(get_lang('FailedToImportThisIsNotAMoodleFile'), 'error')); + } + + $folder = api_get_unique_id(); + $destinationDir = api_get_path(SYS_ARCHIVE_PATH).$folder; + mkdir($destinationDir, api_get_permissions_for_new_directories(), true); + + $package->extract( + PCLZIP_OPT_PATH, + $destinationDir + ); + + $xml = @file_get_contents($destinationDir.'/moodle_backup.xml'); + + $doc = new DOMDocument(); + $res = @$doc->loadXML($xml); + if ($res) { + $activities = $doc->getElementsByTagName('activity'); + foreach ($activities as $activity) { + if ($activity->childNodes->length) { + $currentItem = []; + + foreach($activity->childNodes as $item) { + $currentItem[$item->nodeName] = $item->nodeValue; + } + + $moduleName = $currentItem['modulename']; + switch ($moduleName) { + case 'duh!': + require_once '../forum/forumfunction.inc.php'; + $catForumValues = []; + + // Read the current forum module xml. + $moduleDir = $currentItem['directory']; + $moduleXml = @file_get_contents($destinationDir.'/'.$moduleDir.'/forum.xml'); + $moduleValues = $this->readForumModule($moduleXml); + + // Create a Forum category based on Moodle forum type. + $catForumValues['forum_category_title'] = $moduleValues['type']; + $catForumValues['forum_category_comment'] = ''; + $catId = store_forumcategory($catForumValues); + $forumValues = []; + $forumValues['forum_title'] = $moduleValues['name']; + $forumValues['forum_image'] = ''; + $forumValues['forum_comment'] = $moduleValues['intro']; + $forumValues['forum_category'] = $catId; + + $result = store_forum($forumValues); + break; + case 'quiz': + + break; + case 'resource': + // Read the current resource module xml. + $moduleDir = $currentItem['directory']; + $moduleXml = @file_get_contents($destinationDir.'/'.$moduleDir.'/resource.xml'); + $filesXml = @file_get_contents($destinationDir.'/files.xml'); + $moduleValues = $this->readResourceModule($moduleXml); + $fileInfo = $this->readMainFilesXml($filesXml, $moduleValues['contextid']); + var_dump($moduleValues); + var_dump($fileInfo); + + break; + case 'url': + + break; + } + } + } + } } + + return $packageContent[$mainFileKey]; } + + /** + * Read and validate the forum module XML + * + * @param resource $moduleXml XML file + * @return mixed | array if is a valid xml file, false otherwise + */ + public function readForumModule($moduleXml) + { + $moduleDoc = new DOMDocument(); + $moduleRes = @$moduleDoc->loadXML($moduleXml); + if ($moduleRes) { + $activities = $moduleDoc->getElementsByTagName('forum'); + $currentItem = []; + foreach ($activities as $activity) { + if ($activity->childNodes->length) { + foreach ($activity->childNodes as $item) { + $currentItem[$item->nodeName] = $item->nodeValue; + } + } + } + + return $currentItem; + } + + return false; + } + + /** + * Read and validate the resource module XML + * + * @param resource $moduleXml XML file + * @return mixed | array if is a valid xml file, false otherwise + */ + public function readResourceModule($moduleXml) + { + $moduleDoc = new DOMDocument(); + $moduleRes = @$moduleDoc->loadXML($moduleXml); + if ($moduleRes) { + $activities = $moduleDoc->getElementsByTagName('resource'); + $mainActivity = $moduleDoc->getElementsByTagName('activity'); + $contextId = $mainActivity->item(0)->getAttribute('contextid'); + $currentItem = []; + foreach ($activities as $activity) { + if ($activity->childNodes->length) { + foreach($activity->childNodes as $item) { + $currentItem[$item->nodeName] = $item->nodeValue; + } + } + } + + $currentItem['contextid'] = $contextId; + return $currentItem; + } + + return false; + } + + /** + * Search the current file resource in main Files XML + * + * @param resource $filesXml XML file + * @param int $contextId + * @return mixed | array if is a valid xml file, false otherwise + */ + public function readMainFilesXml($filesXml, $contextId) + { + $moduleDoc = new DOMDocument(); + $moduleRes = @$moduleDoc->loadXML($filesXml); + if ($moduleRes) { + $activities = $moduleDoc->getElementsByTagName('file'); + $currentItem = []; + foreach ($activities as $activity) { + if ($activity->childNodes->length) { + $isThisItemThatIWant = false; + foreach($activity->childNodes as $item) { + if (!$isThisItemThatIWant && $item->nodeName == 'contenthash') { + $currentItem['contenthash'] = $item->nodeValue; + } + if ($item->nodeName == 'contextid' && intval($item->nodeValue) == intval($contextId) && !$isThisItemThatIWant) { + $isThisItemThatIWant = true; + continue; + } + + if ($isThisItemThatIWant && $item->nodeName == 'filename') { + $currentItem['filename'] = $item->nodeValue; + } + + if ($isThisItemThatIWant && $item->nodeName == 'mimetype' && $item->nodeValue == 'document/unknown') { + break; + } + + if ($isThisItemThatIWant && $item->nodeName == 'mimetype' && $item->nodeValue !== 'document/unknown') { + $currentItem['mimetype'] = $item->nodeValue; + break 2; + } + } + } + } + + return $currentItem; + } + + return false; + } + } \ No newline at end of file From b4737f716c44341f1a8995cccd3466dfa43fe029 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Loguercio?= Date: Thu, 7 Jul 2016 20:12:12 -0500 Subject: [PATCH 08/23] WIP - MoodleImport 90% --- main/coursecopy/import_moodle.php | 4 +- main/inc/lib/MoodleImport.lib.php | 371 +++++++++++++++++++++++++++++- main/inc/lib/fileUpload.lib.php | 48 +++- 3 files changed, 407 insertions(+), 16 deletions(-) diff --git a/main/coursecopy/import_moodle.php b/main/coursecopy/import_moodle.php index edbabd2cac..14b351051a 100644 --- a/main/coursecopy/import_moodle.php +++ b/main/coursecopy/import_moodle.php @@ -39,9 +39,9 @@ $form->addFile('moodle_file', get_lang('MoodleFile')); $form->addButtonImport(get_lang('Import')); if ($form->validate()) { - $file = $_FILES['moodle_file']['tmp_name']; + $file = $_FILES['moodle_file']; $moodleImport = new MoodleImport(); - var_dump($moodleImport->readMoodleFile($file)); + $moodleImport->readMoodleFile($file); } $templateName = get_lang('ImportFromMoodle'); diff --git a/main/inc/lib/MoodleImport.lib.php b/main/inc/lib/MoodleImport.lib.php index 4e89b690d3..c99dd8396d 100644 --- a/main/inc/lib/MoodleImport.lib.php +++ b/main/inc/lib/MoodleImport.lib.php @@ -11,15 +11,378 @@ class MoodleImport { /** - * @param resource $file *.* mbz file moodle course backup + * Read and validate the moodleFile + * + * @param resource $uploadedFile *.* mbz file moodle course backup * @return bool */ - public function readMoodleFile($file) + public function readMoodleFile($uploadedFile) { - if (is_file($file) && is_readable($file) && ($xml = @file_get_contents($file))) { + $file = $uploadedFile['tmp_name']; + + if (is_file($file) && is_readable($file)) { $package = new PclZip($file); $packageContent = $package->listContent(); - return $packageContent; + $mainFileKey = 0; + foreach ($packageContent as $index => $value) { + if ($value['filename'] == 'moodle_backup.xml') { + $mainFileKey = $index; + break; + } + } + + if (!$mainFileKey) { + Display::addFlash(Display::return_message(get_lang('FailedToImportThisIsNotAMoodleFile'), 'error')); + } + + $folder = api_get_unique_id(); + $destinationDir = api_get_path(SYS_ARCHIVE_PATH).$folder; + $coursePath = api_get_path(SYS_COURSE_PATH).api_get_course_path().'/'; + $courseInfo = api_get_course_info(); + + mkdir($destinationDir, api_get_permissions_for_new_directories(), true); + + $package->extract( + PCLZIP_OPT_PATH, + $destinationDir + ); + + $xml = @file_get_contents($destinationDir.'/moodle_backup.xml'); + + $doc = new DOMDocument(); + $res = @$doc->loadXML($xml); + if ($res) { + $activities = $doc->getElementsByTagName('activity'); + foreach ($activities as $activity) { + if ($activity->childNodes->length) { + $currentItem = []; + + foreach($activity->childNodes as $item) { + $currentItem[$item->nodeName] = $item->nodeValue; + } + + $moduleName = isset($currentItem['modulename']) ? $currentItem['modulename'] : false; + switch ($moduleName) { + case 'forum1': + require_once '../forum/forumfunction.inc.php'; + $catForumValues = []; + + // Read the current forum module xml. + $moduleDir = $currentItem['directory']; + $moduleXml = @file_get_contents($destinationDir.'/'.$moduleDir.'/'.$moduleName.'.xml'); + $moduleValues = $this->readForumModule($moduleXml); + + // Create a Forum category based on Moodle forum type. + $catForumValues['forum_category_title'] = $moduleValues['type']; + $catForumValues['forum_category_comment'] = ''; + $catId = store_forumcategory($catForumValues); + $forumValues = []; + $forumValues['forum_title'] = $moduleValues['name']; + $forumValues['forum_image'] = ''; + $forumValues['forum_comment'] = $moduleValues['intro']; + $forumValues['forum_category'] = $catId; + + store_forum($forumValues); + break; + case 'quiz': + + // Read the current quiz module xml. + $moduleDir = $currentItem['directory']; + $moduleXml = @file_get_contents($destinationDir.'/'.$moduleDir.'/'.$moduleName.'.xml'); + $questionsXml = @file_get_contents($destinationDir.'/questions.xml'); + $moduleValues = $this->readQuizModule($moduleXml); + foreach ($moduleValues['question_instances'] as $index => $question) { + $questionsValues = $this->readMainQuestionsXml($questionsXml, $question['questionid']); + //$moduleValues['question_instances'][$index] = + } + + break; + case 'resource1': + // Read the current resource module xml. + $moduleDir = $currentItem['directory']; + $moduleXml = @file_get_contents($destinationDir.'/'.$moduleDir.'/'.$moduleName.'.xml'); + $filesXml = @file_get_contents($destinationDir.'/files.xml'); + $moduleValues = $this->readResourceModule($moduleXml); + $mainFileModuleValues = $this->readMainFilesXml($filesXml, $moduleValues['contextid']); + $fileInfo = array_merge($moduleValues, $mainFileModuleValues, $currentItem); + $documentPath = $coursePath.'document/'; + $currentResourceFilePath = $destinationDir.'/files/'; + $dirs = new RecursiveDirectoryIterator($currentResourceFilePath); + foreach(new RecursiveIteratorIterator($dirs) as $file) { + if (is_file($file) && strpos($file, $fileInfo['contenthash']) !== false) { + $files = []; + $files['file']['name'] = $fileInfo['filename']; + $files['file']['tmp_name'] = $file->getPathname(); + $files['file']['type'] = $fileInfo['mimetype']; + $files['file']['error'] = 0; + $files['file']['size'] = $fileInfo['filesize']; + $files['file']['from_file'] = true; + $files['file']['move_file'] = true; + $_POST['language'] = $courseInfo['language']; + $_POST['moodle_import'] = true; + + DocumentManager::upload_document( + $files, + '/', + $fileInfo['title'], + '', + null, + null, + true, + true + ); + } + } + + break; + case 'url1': + // Read the current url module xml. + $moduleDir = $currentItem['directory']; + $moduleXml = @file_get_contents($destinationDir.'/'.$moduleDir.'/'.$moduleName.'.xml'); + $moduleValues = $this->readUrlModule($moduleXml); + $_POST['title'] = $moduleValues['name']; + $_POST['url'] = $moduleValues['externalurl']; + $_POST['description'] = $moduleValues['intro']; + $_POST['category_id'] = 0; + $_POST['target'] = '_blank'; + + Link::addlinkcategory("link"); + break; + } + } + } + } + } + + //removeDir($destinationDir); + return $packageContent[$mainFileKey]; + } + + /** + * Read and validate the forum module XML + * + * @param resource $moduleXml XML file + * @return mixed | array if is a valid xml file, false otherwise + */ + public function readForumModule($moduleXml) + { + $moduleDoc = new DOMDocument(); + $moduleRes = @$moduleDoc->loadXML($moduleXml); + if ($moduleRes) { + $activities = $moduleDoc->getElementsByTagName('forum'); + $currentItem = []; + foreach ($activities as $activity) { + if ($activity->childNodes->length) { + foreach ($activity->childNodes as $item) { + $currentItem[$item->nodeName] = $item->nodeValue; + } + } + } + + return $currentItem; } + + return false; } + + /** + * Read and validate the resource module XML + * + * @param resource $moduleXml XML file + * @return mixed | array if is a valid xml file, false otherwise + */ + public function readResourceModule($moduleXml) + { + $moduleDoc = new DOMDocument(); + $moduleRes = @$moduleDoc->loadXML($moduleXml); + if ($moduleRes) { + $activities = $moduleDoc->getElementsByTagName('resource'); + $mainActivity = $moduleDoc->getElementsByTagName('activity'); + $contextId = $mainActivity->item(0)->getAttribute('contextid'); + $currentItem = []; + foreach ($activities as $activity) { + if ($activity->childNodes->length) { + foreach($activity->childNodes as $item) { + $currentItem[$item->nodeName] = $item->nodeValue; + } + } + } + + $currentItem['contextid'] = $contextId; + return $currentItem; + } + + return false; + } + + /** + * Read and validate the url module XML + * + * @param resource $moduleXml XML file + * @return mixed | array if is a valid xml file, false otherwise + */ + public function readUrlModule($moduleXml) + { + $moduleDoc = new DOMDocument(); + $moduleRes = @$moduleDoc->loadXML($moduleXml); + if ($moduleRes) { + $activities = $moduleDoc->getElementsByTagName('url'); + $currentItem = []; + foreach ($activities as $activity) { + if ($activity->childNodes->length) { + foreach ($activity->childNodes as $item) { + $currentItem[$item->nodeName] = $item->nodeValue; + } + } + } + + return $currentItem; + } + + return false; + } + + /** + * Read and validate the quiz module XML + * + * @param resource $moduleXml XML file + * @return mixed | array if is a valid xml file, false otherwise + */ + public function readQuizModule($moduleXml) + { + $moduleDoc = new DOMDocument(); + $moduleRes = @$moduleDoc->loadXML($moduleXml); + if ($moduleRes) { + $activities = $moduleDoc->getElementsByTagName('quiz'); + $currentItem = []; + foreach ($activities as $activity) { + if ($activity->childNodes->length) { + foreach ($activity->childNodes as $item) { + $currentItem[$item->nodeName] = $item->nodeValue; + } + } + } + + $questions = $moduleDoc->getElementsByTagName('question_instance'); + + $questionList = []; + $counter = 0; + foreach ($questions as $question) { + if ($question->childNodes->length) { + foreach ($question->childNodes as $item) { + $questionList[$counter][$item->nodeName] = $item->nodeValue; + } + $counter++; + } + + } + $currentItem['question_instances'] = $questionList; + return $currentItem; + } + + return false; + } + + /** + * Search the current file resource in main Files XML + * + * @param resource $filesXml XML file + * @param int $contextId + * @return mixed | array if is a valid xml file, false otherwise + */ + public function readMainFilesXml($filesXml, $contextId) + { + $moduleDoc = new DOMDocument(); + $moduleRes = @$moduleDoc->loadXML($filesXml); + if ($moduleRes) { + $activities = $moduleDoc->getElementsByTagName('file'); + $currentItem = []; + foreach ($activities as $activity) { + if ($activity->childNodes->length) { + $isThisItemThatIWant = false; + foreach($activity->childNodes as $item) { + if (!$isThisItemThatIWant && $item->nodeName == 'contenthash') { + $currentItem['contenthash'] = $item->nodeValue; + } + if ($item->nodeName == 'contextid' && intval($item->nodeValue) == intval($contextId) && !$isThisItemThatIWant) { + $isThisItemThatIWant = true; + continue; + } + + if ($isThisItemThatIWant && $item->nodeName == 'filename') { + $currentItem['filename'] = $item->nodeValue; + } + + if ($isThisItemThatIWant && $item->nodeName == 'filesize') { + $currentItem['filesize'] = $item->nodeValue; + } + + if ($isThisItemThatIWant && $item->nodeName == 'mimetype' && $item->nodeValue == 'document/unknown') { + break; + } + + if ($isThisItemThatIWant && $item->nodeName == 'mimetype' && $item->nodeValue !== 'document/unknown') { + $currentItem['mimetype'] = $item->nodeValue; + break 2; + } + } + } + } + + return $currentItem; + } + + return false; + } + + /** + * Search the current quiestion resource in main Questions XML + * + * @param resource $questionsXml XML file + * @param int $questionId + * @return mixed | array if is a valid xml file, false otherwise + */ + public function readMainQuestionsXml($questionsXml, $questionId) + { + $moduleDoc = new DOMDocument(); + $moduleRes = @$moduleDoc->loadXML($questionsXml); + if ($moduleRes) { + $questions = $moduleDoc->getElementsByTagName('question'); + $currentItem = []; + foreach ($questions as $question) { + if (intval($question->getAttribute('id')) == $questionId) { + if ($question->childNodes->length) { + $questionType = ''; + foreach($question->childNodes as $item) { + $currentItem[$item->nodeName] = $item->nodeValue; + if ($item->nodeName == 'qtype') { + $questionType = $item->nodeValue; + } + + if ($item->nodeName == 'plugin_qtype_'.$questionType.'_question') { + $answer = $item->getElementsByTagName('answer'); + $currentItem['plugin_qtype_'.$questionType.'_question'] = []; + $answerId = 0; + foreach ($answer as $value) { + $answerId = $value->getAttribute('id'); + if ($value->childNodes) { + foreach ($value->childNodes as $aItem) { + $currentItem['plugin_qtype_'.$questionType.'_question'] = [$aItem->nodeName => $aItem->nodeValue]; + } + } + } + + + } + } + } + } + } + var_dump($currentItem); + return $currentItem; + } + + return false; + } + } \ No newline at end of file diff --git a/main/inc/lib/fileUpload.lib.php b/main/inc/lib/fileUpload.lib.php index 1a3b6b5dd1..11a066532d 100755 --- a/main/inc/lib/fileUpload.lib.php +++ b/main/inc/lib/fileUpload.lib.php @@ -582,16 +582,30 @@ function handle_uploaded_document( // Display success message to user if ($output) { - Display::display_confirmation_message( - get_lang('UplUploadSucceeded') . '
    ' . get_lang('UplFileSavedAs') .' '.$documentTitle, - false - ); + if (isset($_POST['moodle_import'])) { + Display::addFlash( + Display::display_confirmation_message( + get_lang('UplUploadSucceeded') . '
    ' . get_lang('UplFileSavedAs') . ' ' . $documentTitle, + false, + true + ) + ); + } else { + Display::display_confirmation_message( + get_lang('UplUploadSucceeded') . '
    ' . get_lang('UplFileSavedAs') . ' ' . $documentTitle, + false + ); + } } return $filePath; } else { if ($output) { - Display::display_error_message(get_lang('UplUnableToSaveFile')); + if (isset($_POST['moodle_import'])) { + Display::addFlash(Display::display_error_message(get_lang('UplUnableToSaveFile'), false, true)); + } else { + Display::display_error_message(get_lang('UplUnableToSaveFile')); + } } return false; @@ -601,7 +615,11 @@ function handle_uploaded_document( // Only save the file if it doesn't exist or warn user if it does exist if (file_exists($fullPath) && $docId) { if ($output) { - Display::display_error_message($cleanName.' '.get_lang('UplAlreadyExists')); + if (isset($_POST['moodle_import'])) { + Display::addFlash(Display::display_error_message($cleanName.' '.get_lang('UplAlreadyExists'), false, true)); + } else { + Display::display_error_message($cleanName.' '.get_lang('UplAlreadyExists')); + } } } else { if (moveUploadedFile($uploadedFile, $fullPath)) { @@ -648,10 +666,20 @@ function handle_uploaded_document( // Display success message to user if ($output) { - Display::display_confirmation_message( - get_lang('UplUploadSucceeded').'
    '.$documentTitle, - false - ); + if (isset($_POST['moodle_import'])) { + Display::addFlash( + Display::display_confirmation_message( + get_lang('UplUploadSucceeded') . '
    ' . $documentTitle, + false, + true + ) + ); + } else { + Display::display_confirmation_message( + get_lang('UplUploadSucceeded') . '
    ' . $documentTitle, + false + ); + } } return $filePath; From 6212dedd3d4e9ad7552b0933de8803c6da27c548 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Loguercio?= Date: Sat, 9 Jul 2016 14:11:39 -0500 Subject: [PATCH 09/23] Added 2 quiz questions support (Multichoise, Multianswer) --- main/inc/lib/MoodleImport.lib.php | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/main/inc/lib/MoodleImport.lib.php b/main/inc/lib/MoodleImport.lib.php index c99dd8396d..5456a622dd 100644 --- a/main/inc/lib/MoodleImport.lib.php +++ b/main/inc/lib/MoodleImport.lib.php @@ -95,6 +95,7 @@ class MoodleImport $questionsValues = $this->readMainQuestionsXml($questionsXml, $question['questionid']); //$moduleValues['question_instances'][$index] = } + exit; break; case 'resource1': @@ -352,6 +353,7 @@ class MoodleImport foreach ($questions as $question) { if (intval($question->getAttribute('id')) == $questionId) { if ($question->childNodes->length) { + $currentItem['questionid'] = $questionId; $questionType = ''; foreach($question->childNodes as $item) { $currentItem[$item->nodeName] = $item->nodeValue; @@ -362,17 +364,19 @@ class MoodleImport if ($item->nodeName == 'plugin_qtype_'.$questionType.'_question') { $answer = $item->getElementsByTagName('answer'); $currentItem['plugin_qtype_'.$questionType.'_question'] = []; - $answerId = 0; - foreach ($answer as $value) { - $answerId = $value->getAttribute('id'); - if ($value->childNodes) { - foreach ($value->childNodes as $aItem) { - $currentItem['plugin_qtype_'.$questionType.'_question'] = [$aItem->nodeName => $aItem->nodeValue]; - } + for ($i = 0; $i <= $answer->length - 1; $i++) { + $currentItem['plugin_qtype_'.$questionType.'_question'][$i]['answerid'] = $answer->item($i)->getAttribute('id'); + foreach ($answer->item($i)->childNodes as $properties) { + $currentItem['plugin_qtype_'.$questionType.'_question'][$i][$properties->nodeName] = $properties->nodeValue; } } - + $typeValues = $item->getElementsByTagName($questionType); + for ($i = 0; $i <= $typeValues->length - 1; $i++) { + foreach ($typeValues->item($i)->childNodes as $properties) { + $currentItem[$questionType.'_values'][$properties->nodeName] = $properties->nodeValue; + } + } } } } From 5b8f725faa937ead2d8d4ff8a1bb50135fbd5449 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Loguercio?= Date: Mon, 11 Jul 2016 17:35:42 -0500 Subject: [PATCH 10/23] Inserting quiz and questions import support --- main/inc/lib/MoodleImport.lib.php | 132 +++++++++++++++++++++++++++++- 1 file changed, 128 insertions(+), 4 deletions(-) diff --git a/main/inc/lib/MoodleImport.lib.php b/main/inc/lib/MoodleImport.lib.php index 5456a622dd..305bc7d6c9 100644 --- a/main/inc/lib/MoodleImport.lib.php +++ b/main/inc/lib/MoodleImport.lib.php @@ -87,14 +87,49 @@ class MoodleImport case 'quiz': // Read the current quiz module xml. + // The quiz case is the very complicate process of all the import. + // Please if you want to review the script, try to see the readingXML functions. + // The readingXML functions in this clases do all the mayor work here. + $moduleDir = $currentItem['directory']; $moduleXml = @file_get_contents($destinationDir.'/'.$moduleDir.'/'.$moduleName.'.xml'); $questionsXml = @file_get_contents($destinationDir.'/questions.xml'); $moduleValues = $this->readQuizModule($moduleXml); + + // At this point we got all the prepared resources from Moodle file + // $moduleValues variable contains all the necesary info to the quiz import + // var_dump($moduleValues['question_instances']); // <-- uncomment this to see the final array + + // Lets do this ... + $exercise = new Exercise(); + $exercise->updateTitle(Exercise::format_title_variable($moduleValues['name'])); + $exercise->updateDescription($moduleValues['intro']); + $exercise->updateAttempts($moduleValues['attempts_number']); + $exercise->updateFeedbackType(0); + $exercise->setRandom(intval($moduleValues['shufflequestions']) + 1); + $exercise->updateRandomAnswers($moduleValues['shuffleanswers']); + $exercise->updateExpiredTime($moduleValues['timelimit']); + + if ($moduleValues['questionsperpage'] == 1) { + $exercise->updateType(2); + } else { + $exercise->updateType(1); + } + + // Create the new Quiz + $exercise->save(); + + // Ok, we got the Quiz and create it, now its time to add the Questions foreach ($moduleValues['question_instances'] as $index => $question) { $questionsValues = $this->readMainQuestionsXml($questionsXml, $question['questionid']); - //$moduleValues['question_instances'][$index] = + $moduleValues['question_instances'][$index] = $questionsValues; + // Add the matched chamilo question type to the array + $moduleValues['question_instances'][$index]['chamilo_qtype'] = $this->matchMoodleChamiloQuestionTypes($moduleValues['question_instances'][$index]['qtype']); + + var_dump($moduleValues['question_instances'][$index]); + $questionInstance = Question::getInstance($moduleValues['question_instances'][$index]['chamilo_qtype']); } + exit; break; @@ -362,7 +397,7 @@ class MoodleImport } if ($item->nodeName == 'plugin_qtype_'.$questionType.'_question') { - $answer = $item->getElementsByTagName('answer'); + $answer = $item->getElementsByTagName($this->getQuestionTypeAnswersTag($questionType)); $currentItem['plugin_qtype_'.$questionType.'_question'] = []; for ($i = 0; $i <= $answer->length - 1; $i++) { $currentItem['plugin_qtype_'.$questionType.'_question'][$i]['answerid'] = $answer->item($i)->getAttribute('id'); @@ -371,10 +406,18 @@ class MoodleImport } } - $typeValues = $item->getElementsByTagName($questionType); + $typeValues = $item->getElementsByTagName($this->getQuestionTypeOptionsTag($questionType)); for ($i = 0; $i <= $typeValues->length - 1; $i++) { foreach ($typeValues->item($i)->childNodes as $properties) { $currentItem[$questionType.'_values'][$properties->nodeName] = $properties->nodeValue; + if ($properties->nodeName == 'sequence') { + $sequence = $properties->nodeValue; + $sequenceIds = explode(',', $sequence); + foreach ($sequenceIds as $qId) { + $questionMatch = $this->readMainQuestionsXml($questionsXml, $qId); + $currentItem['plugin_qtype_'.$questionType.'_question'][] = $questionMatch; + } + } } } } @@ -382,11 +425,92 @@ class MoodleImport } } } - var_dump($currentItem); + + $this->traverseArray($currentItem, ['#text', 'question_hints', 'tags']); return $currentItem; } return false; } + /** + * return the correct question type options tag + * + * @param string $questionType name + * @return string question type tag + */ + public function getQuestionTypeOptionsTag($questionType) + { + switch ($questionType) { + case 'match': + case 'ddmatch': + return 'matchoptions'; + break; + default: + return $questionType; + break; + } + } + + /** + * return the correct question type answers tag + * + * @param string $questionType name + * @return string question type tag + */ + public function getQuestionTypeAnswersTag($questionType) + { + switch ($questionType) { + case 'match': + case 'ddmatch': + return 'match'; + break; + default: + return 'answer'; + break; + } + } + + /** + * + * @param string $moodleQuestionType + * @return integer Chamilo question type + */ + public function matchMoodleChamiloQuestionTypes($moodleQuestionType) + { + switch ($moodleQuestionType) { + case 'multichoice': + return UNIQUE_ANSWER; + break; + case 'multianswer': + case 'shortanswer': + case 'match': + return FILL_IN_BLANKS; + break; + case 'essay': + return FREE_ANSWER; + case 'truefalse': + return MULTIPLE_ANSWER_TRUE_FALSE; + } + } + + + /** + * Litle utility to delete the unuseful tags + * + * @param $array + * @param $keys + */ + public function traverseArray(&$array, $keys) { + foreach ($array as $key => &$value) { + if (is_array($value)) { + $this->traverseArray($value, $keys); + } else { + if (in_array($key, $keys)){ + unset($array[$key]); + } + } + } + } + } \ No newline at end of file From e93792596af82df620a70fe4560780fb3595f64d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Loguercio?= Date: Mon, 11 Jul 2016 19:50:15 -0500 Subject: [PATCH 11/23] WIP - Quiz 90% --- main/inc/lib/MoodleImport.lib.php | 140 ++++++++++++++++++++++++++++-- 1 file changed, 131 insertions(+), 9 deletions(-) diff --git a/main/inc/lib/MoodleImport.lib.php b/main/inc/lib/MoodleImport.lib.php index 305bc7d6c9..cda57e44dd 100644 --- a/main/inc/lib/MoodleImport.lib.php +++ b/main/inc/lib/MoodleImport.lib.php @@ -63,7 +63,7 @@ class MoodleImport $moduleName = isset($currentItem['modulename']) ? $currentItem['modulename'] : false; switch ($moduleName) { - case 'forum1': + case 'forum': require_once '../forum/forumfunction.inc.php'; $catForumValues = []; @@ -123,17 +123,41 @@ class MoodleImport foreach ($moduleValues['question_instances'] as $index => $question) { $questionsValues = $this->readMainQuestionsXml($questionsXml, $question['questionid']); $moduleValues['question_instances'][$index] = $questionsValues; + // Set Question Type + $qType = $moduleValues['question_instances'][$index]['qtype']; // Add the matched chamilo question type to the array - $moduleValues['question_instances'][$index]['chamilo_qtype'] = $this->matchMoodleChamiloQuestionTypes($moduleValues['question_instances'][$index]['qtype']); - - var_dump($moduleValues['question_instances'][$index]); + $moduleValues['question_instances'][$index]['chamilo_qtype'] = $this->matchMoodleChamiloQuestionTypes($qType); $questionInstance = Question::getInstance($moduleValues['question_instances'][$index]['chamilo_qtype']); - } + $questionInstance->updateTitle($moduleValues['question_instances'][$index]['name']); + $questionInstance->updateDescription($moduleValues['question_instances'][$index]['questiontext']); + $questionInstance->updateLevel(1); + $questionInstance->updateCategory(0); + + //Save normal question if NOT media + if ($questionInstance->type != MEDIA_QUESTION) { + $questionInstance->save($exercise->id); + + // modify the exercise + $exercise->addToList($questionInstance->id); + $exercise->update_question_positions(); + } + + $objAnswer = new Answer($questionInstance->id); + + foreach ($moduleValues['question_instances'][$index]['plugin_qtype_'.$qType.'_question'] as $slot => $answer) { + $questionWeighting = $this->processAnswers($qType, $objAnswer, $answer, $slot + 1); + } - exit; + // saves the answers into the data base + $objAnswer->save(); + + // sets the total weighting of the question + $questionInstance->updateWeighting($questionWeighting); + $questionInstance->save(); + } break; - case 'resource1': + case 'resource': // Read the current resource module xml. $moduleDir = $currentItem['directory']; $moduleXml = @file_get_contents($destinationDir.'/'.$moduleDir.'/'.$moduleName.'.xml'); @@ -171,7 +195,7 @@ class MoodleImport } break; - case 'url1': + case 'url': // Read the current url module xml. $moduleDir = $currentItem['directory']; $moduleXml = @file_get_contents($destinationDir.'/'.$moduleDir.'/'.$moduleName.'.xml'); @@ -190,7 +214,7 @@ class MoodleImport } } - //removeDir($destinationDir); + removeDir($destinationDir); return $packageContent[$mainFileKey]; } @@ -489,9 +513,107 @@ class MoodleImport break; case 'essay': return FREE_ANSWER; + break; case 'truefalse': return MULTIPLE_ANSWER_TRUE_FALSE; + break; + } + } + + /** + * Process Moodle Answers to Chamilo + * + * @param string $questionType + * @param object $objAnswer + * @param array $answerValues + * @param integer $position + * @return integer db response + */ + public function processAnswers($questionType, $objAnswer, $answerValues, $position) + { + switch ($questionType) { + case 'multichoice': + return $this->processUniqueAnswer($objAnswer, $answerValues, $position) ; + break; + case 'multianswer': + case 'shortanswer': + case 'match': + break; + case 'essay': + break; + case 'truefalse': + break; + } + } + + /** + * Process Chamilo Unique Answer + * + * @param object $objAnswer + * @param array $answerValues + * @param integer $position + * @return integer db response + */ + public function processUniqueAnswer($objAnswer, $answerValues, $position) + { + $questionWeighting = $nbrGoodAnswers = 0; + $correct = intval($answerValues['fraction']) ? intval($answerValues['fraction']) : 0; + $answer = $answerValues['answertext']; + $comment = $answerValues['feedback']; + $weighting = $answerValues['fraction']; + $weighting = abs($weighting); + if ($weighting > 0) { + $questionWeighting += $weighting; + } + $goodAnswer = $correct ? true : false; + + $objAnswer->createAnswer( + $answer, + $goodAnswer, + $comment, + $weighting, + $position, + null, + null, + '' + ); + + return $questionWeighting; + } + + /** + * Process Chamilo FillBlanks + * + * @param object $objAnswer + * @param array $answerValues + * @param integer $position + * @return integer db response + */ + public function processFillBlanks($objAnswer, $answerValues, $position) + { + $questionWeighting = $nbrGoodAnswers = 0; + $correct = intval($answerValues['fraction']) ? intval($answerValues['fraction']) : 0; + $answer = $answerValues['answertext']; + $comment = $answerValues['feedback']; + $weighting = $answerValues['fraction']; + $weighting = abs($weighting); + if ($weighting > 0) { + $questionWeighting += $weighting; } + $goodAnswer = $correct ? true : false; + + $objAnswer->createAnswer( + $answer, + $goodAnswer, + $comment, + $weighting, + $position, + null, + null, + '' + ); + + return $questionWeighting; } From 80ef92201d062c4ea37abdbbc795ebd12cb57935 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Loguercio?= Date: Tue, 12 Jul 2016 20:58:26 -0500 Subject: [PATCH 12/23] Added Support to Fill in Blanks and Free_Answer (match && ddmatch still in working) --- main/inc/lib/MoodleImport.lib.php | 209 ++++++++++++++++++++++-------- 1 file changed, 152 insertions(+), 57 deletions(-) diff --git a/main/inc/lib/MoodleImport.lib.php b/main/inc/lib/MoodleImport.lib.php index cda57e44dd..522ff6ff05 100644 --- a/main/inc/lib/MoodleImport.lib.php +++ b/main/inc/lib/MoodleImport.lib.php @@ -98,7 +98,7 @@ class MoodleImport // At this point we got all the prepared resources from Moodle file // $moduleValues variable contains all the necesary info to the quiz import - // var_dump($moduleValues['question_instances']); // <-- uncomment this to see the final array + // var_dump($moduleValues); // <-- uncomment this to see the final array // Lets do this ... $exercise = new Exercise(); @@ -106,8 +106,20 @@ class MoodleImport $exercise->updateDescription($moduleValues['intro']); $exercise->updateAttempts($moduleValues['attempts_number']); $exercise->updateFeedbackType(0); - $exercise->setRandom(intval($moduleValues['shufflequestions']) + 1); + + // Match shuffle question with chamilo + switch ($moduleValues['shufflequestions']) { + case '0': + $exercise->setRandom(0); + break; + case '1': + $exercise->setRandom(-1); + break; + default: + $exercise->setRandom(0); + } $exercise->updateRandomAnswers($moduleValues['shuffleanswers']); + // @todo divide to minutes $exercise->updateExpiredTime($moduleValues['timelimit']); if ($moduleValues['questionsperpage'] == 1) { @@ -123,37 +135,31 @@ class MoodleImport foreach ($moduleValues['question_instances'] as $index => $question) { $questionsValues = $this->readMainQuestionsXml($questionsXml, $question['questionid']); $moduleValues['question_instances'][$index] = $questionsValues; - // Set Question Type + // Set Question Type from Moodle XML element $qType = $moduleValues['question_instances'][$index]['qtype']; // Add the matched chamilo question type to the array $moduleValues['question_instances'][$index]['chamilo_qtype'] = $this->matchMoodleChamiloQuestionTypes($qType); $questionInstance = Question::getInstance($moduleValues['question_instances'][$index]['chamilo_qtype']); - $questionInstance->updateTitle($moduleValues['question_instances'][$index]['name']); - $questionInstance->updateDescription($moduleValues['question_instances'][$index]['questiontext']); - $questionInstance->updateLevel(1); - $questionInstance->updateCategory(0); - - //Save normal question if NOT media - if ($questionInstance->type != MEDIA_QUESTION) { - $questionInstance->save($exercise->id); - - // modify the exercise - $exercise->addToList($questionInstance->id); - $exercise->update_question_positions(); - } + if ($questionInstance) { + $questionInstance->updateTitle($moduleValues['question_instances'][$index]['name']); + $questionInstance->updateDescription($moduleValues['question_instances'][$index]['questiontext']); + $questionInstance->updateLevel(1); + $questionInstance->updateCategory(0); + + //Save normal question if NOT media + if ($questionInstance->type != MEDIA_QUESTION) { + $questionInstance->save($exercise->id); + + // modify the exercise + $exercise->addToList($questionInstance->id); + $exercise->update_question_positions(); + } - $objAnswer = new Answer($questionInstance->id); + $questionList = $moduleValues['question_instances'][$index]['plugin_qtype_'.$qType.'_question']; + $currentQuestion = $moduleValues['question_instances'][$index]; - foreach ($moduleValues['question_instances'][$index]['plugin_qtype_'.$qType.'_question'] as $slot => $answer) { - $questionWeighting = $this->processAnswers($qType, $objAnswer, $answer, $slot + 1); + $result = $this->processAnswers($questionList, $qType, $questionInstance, $currentQuestion); } - - // saves the answers into the data base - $objAnswer->save(); - - // sets the total weighting of the question - $questionInstance->updateWeighting($questionWeighting); - $questionInstance->save(); } break; @@ -211,7 +217,11 @@ class MoodleImport } } } + } else { + return false; } + } else { + return false; } removeDir($destinationDir); @@ -523,25 +533,86 @@ class MoodleImport /** * Process Moodle Answers to Chamilo * + * @param array $questionList * @param string $questionType - * @param object $objAnswer - * @param array $answerValues - * @param integer $position + * @param object $questionInstance Question/Answer instance + * @param array $currentQuestion * @return integer db response */ - public function processAnswers($questionType, $objAnswer, $answerValues, $position) + public function processAnswers($questionList, $questionType, $questionInstance, $currentQuestion) { switch ($questionType) { case 'multichoice': - return $this->processUniqueAnswer($objAnswer, $answerValues, $position) ; + $objAnswer = new Answer($questionInstance->id); + $questionWeighting = 0; + foreach ($questionList as $slot => $answer) { + $this->processUniqueAnswer($objAnswer, $answer, $slot + 1, $questionWeighting); + } + + // saves the answers into the data base + $objAnswer->save(); + // sets the total weighting of the question + $questionInstance->updateWeighting($questionWeighting); + $questionInstance->save(); + + return true; break; case 'multianswer': + $objAnswer = new Answer($questionInstance->id); + + $placeholder = $currentQuestion['questiontext']; + + $optionsValues = []; + + foreach ($questionList as $slot => $subQuestion) { + $qtype = $subQuestion['qtype']; + $optionsValues[] = $this->processFillBlanks($objAnswer, $subQuestion, $subQuestion['plugin_qtype_'.$qtype.'_question'], $placeholder, $slot + 1); + } + + $answerOptionsWeight = '::'; + $answerOptionsSize = ''; + $questionWeighting = 0; + foreach ($optionsValues as $index => $value) { + $questionWeighting += $value['weight']; + $answerOptionsWeight .= $value['weight'].','; + $answerOptionsSize .= $value['size'].','; + } + + $answerOptionsWeight = substr($answerOptionsWeight, 0, -1); + $answerOptionsSize = substr($answerOptionsSize, 0, -1); + + $suffleAnswers = isset($subQuestion[$qtype.'_values']['shuffleanswers']) ? $subQuestion[$qtype.'_values']['shuffleanswers'] : false; + + if ($suffleAnswers) { + $answerOptions = $answerOptionsWeight.':'.$answerOptionsSize.':0@'.$suffleAnswers; + } else { + $answerOptions = $answerOptionsWeight.':'.$answerOptionsSize.':0@'; + } + + $placeholder = $placeholder.$answerOptions; + + $questionInstance->updateWeighting($questionWeighting); + $questionInstance->updateDescription(''); + $questionInstance->save(); + $objAnswer->createAnswer($placeholder, 0, '', 0, 1); + $objAnswer->save(); case 'shortanswer': case 'match': + case 'ddmatch': + // Not Supported Yet + return false; break; case 'essay': + $questionWeighting = $currentQuestion['defaultmark']; + $questionInstance->updateWeighting($questionWeighting); + $questionInstance->save(); break; case 'truefalse': + // Not Supported Yet + return false; + break; + default: + return false; break; } } @@ -552,11 +623,11 @@ class MoodleImport * @param object $objAnswer * @param array $answerValues * @param integer $position + * @param integer $questionWeighting * @return integer db response */ - public function processUniqueAnswer($objAnswer, $answerValues, $position) + public function processUniqueAnswer($objAnswer, $answerValues, $position, &$questionWeighting) { - $questionWeighting = $nbrGoodAnswers = 0; $correct = intval($answerValues['fraction']) ? intval($answerValues['fraction']) : 0; $answer = $answerValues['answertext']; $comment = $answerValues['feedback']; @@ -577,43 +648,67 @@ class MoodleImport null, '' ); - - return $questionWeighting; } /** * Process Chamilo FillBlanks * * @param object $objAnswer + * @param array $question * @param array $answerValues + * @param string $placeholder * @param integer $position * @return integer db response */ - public function processFillBlanks($objAnswer, $answerValues, $position) + public function processFillBlanks($objAnswer, $question, $answerValues, &$placeholder, $position) { - $questionWeighting = $nbrGoodAnswers = 0; - $correct = intval($answerValues['fraction']) ? intval($answerValues['fraction']) : 0; - $answer = $answerValues['answertext']; - $comment = $answerValues['feedback']; - $weighting = $answerValues['fraction']; - $weighting = abs($weighting); - if ($weighting > 0) { - $questionWeighting += $weighting; - } - $goodAnswer = $correct ? true : false; + switch ($question['qtype']) { + case 'multichoice': + $optionsValues = []; + + $correctAnswer = ''; + $othersAnswer = ''; + foreach ($answerValues as $answer) { + $correct = intval($answer['fraction']); + if ($correct) { + $correctAnswer .= $answer['answertext'].'|'; + $optionsValues['weight'] = $answer['fraction']; + $optionsValues['size'] = '200'; + } else { + $othersAnswer .= $answer['answertext'].'|'; + } + } + $currentAnswers = $correctAnswer.$othersAnswer; + $currentAnswers = '['.substr($currentAnswers, 0, -1).']'; + $placeholder = str_replace("{#$position}", $currentAnswers, $placeholder); - $objAnswer->createAnswer( - $answer, - $goodAnswer, - $comment, - $weighting, - $position, - null, - null, - '' - ); + return $optionsValues; + + break; + case 'shortanswer': + $optionsValues = []; + + $correctAnswer = ''; + + foreach ($answerValues as $answer) { + $correct = intval($answer['fraction']); + if ($correct) { + $correctAnswer .= $answer['answertext']; + $optionsValues['weight'] = $answer['fraction']; + $optionsValues['size'] = '200'; + } + } + + $currentAnswers = '['.$correctAnswer.']'; + $placeholder = str_replace("{#$position}", $currentAnswers, $placeholder); + + return $optionsValues; - return $questionWeighting; + break; + default: + return false; + break; + } } From 43d5f6735a8cee0add188f31f53d297de8b335ed Mon Sep 17 00:00:00 2001 From: Angel Fernando Quiroz Campos Date: Wed, 13 Jul 2016 17:29:05 -0500 Subject: [PATCH 13/23] Improve code on restore documents - refs #8113 --- .../Component/CourseCopy/CourseRestorer.php | 1034 ++++++++--------- 1 file changed, 516 insertions(+), 518 deletions(-) diff --git a/src/Chamilo/CourseBundle/Component/CourseCopy/CourseRestorer.php b/src/Chamilo/CourseBundle/Component/CourseCopy/CourseRestorer.php index 29060ddd19..23fe58dc75 100644 --- a/src/Chamilo/CourseBundle/Component/CourseCopy/CourseRestorer.php +++ b/src/Chamilo/CourseBundle/Component/CourseCopy/CourseRestorer.php @@ -294,490 +294,364 @@ class CourseRestorer { $course_info = api_get_course_info($destination_course_code); - if ($this->course->has_resources(RESOURCE_DOCUMENT)) { - $table = Database :: get_course_table(TABLE_DOCUMENT); - $resources = $this->course->resources; - $path = api_get_path(SYS_COURSE_PATH).$this->course->destination_path.'/'; - - foreach ($resources[RESOURCE_DOCUMENT] as $id => $document) { - if (empty($document->item_properties[0]['id_session'])) { - $my_session_id = 0; - } else { - $my_session_id = $session_id; - } + if (!$this->course->has_resources(RESOURCE_DOCUMENT)) { + return; + } - if ($document->file_type == FOLDER) { - $visibility = $document->item_properties[0]['visibility']; - $new = substr($document->path, 8); + $table = Database :: get_course_table(TABLE_DOCUMENT); + $resources = $this->course->resources; + $path = api_get_path(SYS_COURSE_PATH).$this->course->destination_path.'/'; - $folderList = explode('/', $new); - $tempFolder = ''; + foreach ($resources[RESOURCE_DOCUMENT] as $id => $document) { + $my_session_id = empty($document->item_properties[0]['id_session']) ? 0 : $session_id; - // Check if the parent path exists. - foreach ($folderList as $folder) { - $folderToCreate = $tempFolder.$folder; - $sysFolderPath = $path.'document'.$folderToCreate; - $tempFolder .= $folder.'/'; + if ($document->file_type == FOLDER) { + $visibility = $document->item_properties[0]['visibility']; + $new = substr($document->path, 8); - if (empty($folderToCreate)) { - continue; - } + $folderList = explode('/', $new); + $tempFolder = ''; - $title = $document->title; - if (empty($title)) { - $title = basename($sysFolderPath); - } + // Check if the parent path exists. + foreach ($folderList as $folder) { + $folderToCreate = $tempFolder.$folder; + $sysFolderPath = $path.'document'.$folderToCreate; + $tempFolder .= $folder.'/'; - // File doesn't exist in file system. - if (!is_dir($sysFolderPath)) { - // Creating directory - create_unexisting_directory( - $course_info, - api_get_user_id(), - $my_session_id, - 0, - 0, - $path.'document', - $folderToCreate, - $title, - $visibility - ); - } else { - // File exist in file system. - $documentData = DocumentManager::get_document_id( - $course_info, - $folderToCreate, - $my_session_id - ); - - if (empty($documentData)) { - /* This means the folder exists in the - filesystem but not in the DB, trying to fix it */ - add_document( - $course_info, - $folderToCreate, - 'folder', - 0, - $title, - null, - null, - false, - null, - $my_session_id - ); - } - } + if (empty($folderToCreate)) { + continue; } - } elseif ($document->file_type == DOCUMENT) { - //Checking if folder exists in the database otherwise we created it - $dir_to_create = dirname($document->path); - if (!empty($dir_to_create) && $dir_to_create != 'document' && $dir_to_create != '/') { - if (is_dir($path.dirname($document->path))) { - $sql = "SELECT id FROM $table - WHERE - c_id = ".$this->destination_course_id." AND - path = '/".self::DBUTF8escapestring(substr(dirname($document->path), 9))."'"; - $res = Database::query($sql); - if (Database::num_rows($res) == 0) { - //continue; - $visibility = $document->item_properties[0]['visibility']; - $new = '/'.substr(dirname($document->path), 9); - $title = $document->title; - if (empty($title)) { - $title = str_replace('/', '', $new); - } + $title = $document->title; + if (empty($title)) { + $title = basename($sysFolderPath); + } - // This code fixes the possibility for a file without a directory entry to be - $document_id = add_document( - $course_info, - $new, - 'folder', - 0, - $title, - null, - null, - false - ); + // File doesn't exist in file system. + if (!is_dir($sysFolderPath)) { + // Creating directory + create_unexisting_directory( + $course_info, + api_get_user_id(), + $my_session_id, + 0, + 0, + $path.'document', + $folderToCreate, + $title, + $visibility + ); - $itemProperty = isset($document->item_properties[0]) ? $document->item_properties[0] : ''; - $insertUserId = isset($itemProperty['insert_user_id']) ? $itemProperty['insert_user_id'] : api_get_user_id(); - $toGroupId = isset($itemProperty['to_group_id']) ? $itemProperty['to_group_id'] : 0; - $toUserId = isset($itemProperty['to_user_id']) ? $itemProperty['to_user_id'] : null; + continue; + } - $insertUserId = $this->checkUserId($insertUserId); - $toUserId = $this->checkUserId($toUserId, true); + // File exist in file system. + $documentData = DocumentManager::get_document_id($course_info, $folderToCreate, $my_session_id); - api_item_property_update( - $course_info, - TOOL_DOCUMENT, - $document_id, - 'FolderCreated', - $insertUserId, - $toGroupId, - $toUserId, - null, - null, - $my_session_id - ); - } - } + if (!empty($documentData)) { + continue; } - if (file_exists($path.$document->path)) { - switch ($this->file_option) { - case FILE_OVERWRITE: - $origin_path = $this->course->backup_path.'/'.$document->path; - - if (file_exists($origin_path)) { - copy($origin_path, $path.$document->path); - $sql = "SELECT id FROM $table - WHERE - c_id = ".$this->destination_course_id." AND - path = '/".self::DBUTF8escapestring(substr($document->path, 9))."'"; - - $res = Database::query($sql); - $count = Database::num_rows($res); - - if ($count == 0) { - $params = [ - 'path' => "/".self::DBUTF8(substr($document->path, 9)), - 'c_id' => $this->destination_course_id, - 'comment'=> self::DBUTF8($document->comment), - 'title' => self::DBUTF8($document->title), - 'filetype' => self::DBUTF8($document->file_type), - 'size' => self::DBUTF8($document->size), - 'session_id' => $my_session_id, - 'readonly' => 0 - ]; - - $document_id = Database::insert($table, $params); - - if ($document_id) { - $sql = "UPDATE $table SET id = iid WHERE iid = $document_id"; - Database::query($sql); - } - $this->course->resources[RESOURCE_DOCUMENT][$id]->destination_id = $document_id; + /* This means the folder exists in the + filesystem but not in the DB, trying to fix it */ + add_document( + $course_info, + $folderToCreate, + 'folder', + 0, + $title, + null, + null, + false, + null, + $my_session_id + ); + } + } elseif ($document->file_type == DOCUMENT) { + //Checking if folder exists in the database otherwise we created it + $dir_to_create = dirname($document->path); - $itemProperty = isset($document->item_properties[0]) ? $document->item_properties[0] : ''; - $insertUserId = isset($itemProperty['insert_user_id']) ? $itemProperty['insert_user_id'] : api_get_user_id(); - $toGroupId = isset($itemProperty['to_group_id']) ? $itemProperty['to_group_id'] : 0; - $toUserId = isset($itemProperty['to_user_id']) ? $itemProperty['to_user_id'] : null; + if (!empty($dir_to_create) && $dir_to_create != 'document' && $dir_to_create != '/') { + if (is_dir($path.dirname($document->path))) { + $sql = "SELECT id FROM $table + WHERE + c_id = ".$this->destination_course_id." AND + path = '/".self::DBUTF8escapestring(substr(dirname($document->path), 9))."'"; + $res = Database::query($sql); + if (Database::num_rows($res) == 0) { + //continue; + $visibility = $document->item_properties[0]['visibility']; + $new = '/'.substr(dirname($document->path), 9); + $title = $document->title; + if (empty($title)) { + $title = str_replace('/', '', $new); + } - $insertUserId = $this->checkUserId($insertUserId); - $toUserId = $this->checkUserId($toUserId, true); + // This code fixes the possibility for a file without a directory entry to be + $document_id = add_document( + $course_info, + $new, + 'folder', + 0, + $title, + null, + null, + false + ); - api_item_property_update( - $course_info, - TOOL_DOCUMENT, - $document_id, - 'DocumentAdded', - $insertUserId, - $toGroupId, - $toUserId, - null, - null, - $my_session_id - ); - } else { - $obj = Database::fetch_object($res); - $document_id = $obj->id; - $params = [ - 'path' => "/".self::DBUTF8(substr($document->path, 9)), - 'c_id' => $this->destination_course_id, - 'comment'=> self::DBUTF8($document->comment), - 'title' => self::DBUTF8($document->title), - 'filetype' => self::DBUTF8($document->file_type), - 'size' => self::DBUTF8($document->size), - 'session_id' => $my_session_id, - ]; - - Database::update( - $table, - $params, - [ - 'c_id = ? AND path = ?' => [ - $this->destination_course_id, - "/".self::DBUTF8escapestring(substr($document->path, 9)), - ] - ] - ); + $itemProperty = isset($document->item_properties[0]) ? $document->item_properties[0] : ''; + $insertUserId = isset($itemProperty['insert_user_id']) ? $itemProperty['insert_user_id'] : api_get_user_id(); + $toGroupId = isset($itemProperty['to_group_id']) ? $itemProperty['to_group_id'] : 0; + $toUserId = isset($itemProperty['to_user_id']) ? $itemProperty['to_user_id'] : null; - $this->course->resources[RESOURCE_DOCUMENT][$id]->destination_id = $obj->id; + $insertUserId = $this->checkUserId($insertUserId); + $toUserId = $this->checkUserId($toUserId, true); - $itemProperty = isset($document->item_properties[0]) ? $document->item_properties[0] : ''; - $insertUserId = isset($itemProperty['insert_user_id']) ? $itemProperty['insert_user_id'] : api_get_user_id(); - $toGroupId = isset($itemProperty['to_group_id']) ? $itemProperty['to_group_id'] : 0; - $toUserId = isset($itemProperty['to_user_id']) ? $itemProperty['to_user_id'] : null; + api_item_property_update( + $course_info, + TOOL_DOCUMENT, + $document_id, + 'FolderCreated', + $insertUserId, + $toGroupId, + $toUserId, + null, + null, + $my_session_id + ); + } + } + } - $insertUserId = $this->checkUserId($insertUserId); - $toUserId = $this->checkUserId($toUserId, true); + if (file_exists($path.$document->path)) { + switch ($this->file_option) { + case FILE_OVERWRITE: + $origin_path = $this->course->backup_path.'/'.$document->path; - api_item_property_update( - $course_info, - TOOL_DOCUMENT, - $obj->id, - 'default', - $insertUserId, - $toGroupId, - $toUserId, - null, - null, - $my_session_id - ); - } + if (file_exists($origin_path)) { + copy($origin_path, $path.$document->path); + $sql = "SELECT id FROM $table + WHERE + c_id = ".$this->destination_course_id." AND + path = '/".self::DBUTF8escapestring(substr($document->path, 9))."'"; - // Replace old course code with the new destination code + $res = Database::query($sql); + $count = Database::num_rows($res); - $file_info = pathinfo($path.$document->path); + if ($count == 0) { + $params = [ + 'path' => "/".self::DBUTF8(substr($document->path, 9)), + 'c_id' => $this->destination_course_id, + 'comment'=> self::DBUTF8($document->comment), + 'title' => self::DBUTF8($document->title), + 'filetype' => self::DBUTF8($document->file_type), + 'size' => self::DBUTF8($document->size), + 'session_id' => $my_session_id, + 'readonly' => 0 + ]; - if (in_array($file_info['extension'], array('html', 'htm'))) { - $content = file_get_contents($path.$document->path); - if (UTF8_CONVERT) $content = utf8_encode($content); - $content = DocumentManager::replace_urls_inside_content_html_from_copy_course( - $content, - $this->course->code, - $this->course->destination_path, - $this->course->backup_path, - $this->course->info['path'] - ); - file_put_contents($path.$document->path,$content); + $document_id = Database::insert($table, $params); + + if ($document_id) { + $sql = "UPDATE $table SET id = iid WHERE iid = $document_id"; + Database::query($sql); } + $this->course->resources[RESOURCE_DOCUMENT][$id]->destination_id = $document_id; + + $itemProperty = isset($document->item_properties[0]) ? $document->item_properties[0] : ''; + $insertUserId = isset($itemProperty['insert_user_id']) ? $itemProperty['insert_user_id'] : api_get_user_id(); + $toGroupId = isset($itemProperty['to_group_id']) ? $itemProperty['to_group_id'] : 0; + $toUserId = isset($itemProperty['to_user_id']) ? $itemProperty['to_user_id'] : null; + $insertUserId = $this->checkUserId($insertUserId); + $toUserId = $this->checkUserId($toUserId, true); + + api_item_property_update( + $course_info, + TOOL_DOCUMENT, + $document_id, + 'DocumentAdded', + $insertUserId, + $toGroupId, + $toUserId, + null, + null, + $my_session_id + ); + } else { + $obj = Database::fetch_object($res); + $document_id = $obj->id; $params = [ + 'path' => "/".self::DBUTF8(substr($document->path, 9)), + 'c_id' => $this->destination_course_id, 'comment'=> self::DBUTF8($document->comment), 'title' => self::DBUTF8($document->title), + 'filetype' => self::DBUTF8($document->file_type), 'size' => self::DBUTF8($document->size), + 'session_id' => $my_session_id, ]; + Database::update( $table, $params, [ - 'c_id = ? AND id = ?' => [ + 'c_id = ? AND path = ?' => [ $this->destination_course_id, - $document_id, - ], + "/".self::DBUTF8escapestring(substr($document->path, 9)), + ] ] ); - } - - break; - case FILE_SKIP: - $sql = "SELECT id FROM $table - WHERE - c_id = ".$this->destination_course_id." AND - path='/".self::DBUTF8escapestring(substr($document->path, 9))."'"; - $res = Database::query($sql); - $obj = Database::fetch_object($res); - $this->course->resources[RESOURCE_DOCUMENT][$id]->destination_id = $obj->id; - break; - case FILE_RENAME: - $i = 1; - $ext = explode('.', basename($document->path)); - if (count($ext) > 1) { - $ext = array_pop($ext); - $file_name_no_ext = substr($document->path, 0, - (strlen($ext) + 1)); - $ext = '.'.$ext; - } else { - $ext = ''; - $file_name_no_ext = $document->path; - } - $new_file_name = $file_name_no_ext.'_'.$i.$ext; - $file_exists = file_exists($path.$new_file_name); - while ($file_exists) { - $i ++; - $new_file_name = $file_name_no_ext.'_'.$i.$ext; - $file_exists = file_exists($path.$new_file_name); - } - - if (!empty($session_id)) { - - $document_path = explode('/',$document->path,3); - $course_path = $path; - $orig_base_folder = $document_path[1]; - $orig_base_path = $course_path.$document_path[0].'/'.$document_path[1]; - - if (is_dir($orig_base_path)) { - - $new_base_foldername = $orig_base_folder; - $new_base_path = $orig_base_path; - - if ($_SESSION['orig_base_foldername'] != $new_base_foldername) { - unset($_SESSION['new_base_foldername']); - unset($_SESSION['orig_base_foldername']); - unset($_SESSION['new_base_path']); - } - - $folder_exists = file_exists($new_base_path); - if ($folder_exists) { - $_SESSION['orig_base_foldername'] = $new_base_foldername; // e.g: carpeta1 in session - $x = ''; - while ($folder_exists) { - $x = $x + 1; - $new_base_foldername = $document_path[1].'_'.$x; - $new_base_path = $orig_base_path.'_'.$x; - if ($_SESSION['new_base_foldername'] == $new_base_foldername) { - break; - } - $folder_exists = file_exists($new_base_path); - } - $_SESSION['new_base_foldername'] = $new_base_foldername; - $_SESSION['new_base_path'] = $new_base_path; - } - - if (isset($_SESSION['new_base_foldername']) && isset($_SESSION['new_base_path'])) { - $new_base_foldername = $_SESSION['new_base_foldername']; - $new_base_path = $_SESSION['new_base_path']; - } - - $dest_document_path = $new_base_path.'/'.$document_path[2]; // e.g: "/var/www/wiener/courses/CURSO4/document/carpeta1_1/subcarpeta1/collaborative.png" - $basedir_dest_path = dirname($dest_document_path); // e.g: "/var/www/wiener/courses/CURSO4/document/carpeta1_1/subcarpeta1" - $base_path_document = $course_path.$document_path[0]; // e.g: "/var/www/wiener/courses/CURSO4/document" - $path_title = '/'.$new_base_foldername.'/'.$document_path[2]; - - copy_folder_course_session( - $basedir_dest_path, - $base_path_document, - $session_id, - $course_info, - $document, - $this->course_origin_id - ); - if (file_exists($course_path.$document->path)) { - copy($course_path.$document->path, $dest_document_path); - } + $this->course->resources[RESOURCE_DOCUMENT][$id]->destination_id = $obj->id; - //Replace old course code with the new destination code see BT#1985 - if (file_exists($dest_document_path)) { - $file_info = pathinfo($dest_document_path); - if (in_array($file_info['extension'], array('html','htm'))) { - $content = file_get_contents($dest_document_path); - if (UTF8_CONVERT) { - $content = utf8_encode($content); - } - $content = DocumentManager::replace_urls_inside_content_html_from_copy_course( - $content, - $this->course->code, - $this->course->destination_path, - $this->course->backup_path, - $this->course->info['path'] - ); - file_put_contents($dest_document_path, $content); - } - } + $itemProperty = isset($document->item_properties[0]) ? $document->item_properties[0] : ''; + $insertUserId = isset($itemProperty['insert_user_id']) ? $itemProperty['insert_user_id'] : api_get_user_id(); + $toGroupId = isset($itemProperty['to_group_id']) ? $itemProperty['to_group_id'] : 0; + $toUserId = isset($itemProperty['to_user_id']) ? $itemProperty['to_user_id'] : null; - $params = [ - 'path' => self::DBUTF8($path_title), - 'c_id' => $this->destination_course_id, - 'comment'=> self::DBUTF8($document->comment), - 'title' => self::DBUTF8(basename($path_title)), - 'filetype' => self::DBUTF8($document->file_type), - 'size' => self::DBUTF8($document->size), - 'session_id' => $my_session_id, - ]; - - $document_id = Database::insert($table, $params); - - if ($document_id) { - $sql = "UPDATE $table SET id = iid WHERE iid = $document_id"; - Database::query($sql); - } + $insertUserId = $this->checkUserId($insertUserId); + $toUserId = $this->checkUserId($toUserId, true); - $this->course->resources[RESOURCE_DOCUMENT][$id]->destination_id = $document_id; + api_item_property_update( + $course_info, + TOOL_DOCUMENT, + $obj->id, + 'default', + $insertUserId, + $toGroupId, + $toUserId, + null, + null, + $my_session_id + ); + } - $itemProperty = isset($document->item_properties[0]) ? $document->item_properties[0] : ''; - $insertUserId = isset($itemProperty['insert_user_id']) ? $itemProperty['insert_user_id'] : api_get_user_id(); - $toGroupId = isset($itemProperty['to_group_id']) ? $itemProperty['to_group_id'] : 0; - $toUserId = isset($itemProperty['to_user_id']) ? $itemProperty['to_user_id'] : null; + // Replace old course code with the new destination code - $insertUserId = $this->checkUserId($insertUserId); - $toUserId = $this->checkUserId($toUserId, true); + $file_info = pathinfo($path.$document->path); - api_item_property_update( - $course_info, - TOOL_DOCUMENT, + if (in_array($file_info['extension'], array('html', 'htm'))) { + $content = file_get_contents($path.$document->path); + if (UTF8_CONVERT) $content = utf8_encode($content); + $content = DocumentManager::replace_urls_inside_content_html_from_copy_course( + $content, + $this->course->code, + $this->course->destination_path, + $this->course->backup_path, + $this->course->info['path'] + ); + file_put_contents($path.$document->path,$content); + } + + $params = [ + 'comment'=> self::DBUTF8($document->comment), + 'title' => self::DBUTF8($document->title), + 'size' => self::DBUTF8($document->size), + ]; + Database::update( + $table, + $params, + [ + 'c_id = ? AND id = ?' => [ + $this->destination_course_id, $document_id, - 'DocumentAdded', - $insertUserId, - $toGroupId, - $toUserId, - null, - null, - $my_session_id - ); - } else { - if (file_exists($path.$document->path)) { - copy($path.$document->path, $path.$new_file_name); - } - //Replace old course code with the new destination code see BT#1985 - if (file_exists($path.$new_file_name)) { - $file_info = pathinfo($path.$new_file_name); - if (in_array($file_info['extension'], array('html','htm'))) { - $content = file_get_contents($path.$new_file_name); - if (UTF8_CONVERT) { - $content = utf8_encode($content); - } - $content = DocumentManager::replace_urls_inside_content_html_from_copy_course( - $content, - $this->course->code, - $this->course->destination_path, - $this->course->backup_path, - $this->course->info['path'] - ); - file_put_contents($path.$new_file_name, $content); + ], + ] + ); + } + + break; + case FILE_SKIP: + $sql = "SELECT id FROM $table + WHERE + c_id = ".$this->destination_course_id." AND + path='/".self::DBUTF8escapestring(substr($document->path, 9))."'"; + $res = Database::query($sql); + $obj = Database::fetch_object($res); + $this->course->resources[RESOURCE_DOCUMENT][$id]->destination_id = $obj->id; + break; + case FILE_RENAME: + $i = 1; + $ext = explode('.', basename($document->path)); + if (count($ext) > 1) { + $ext = array_pop($ext); + $file_name_no_ext = substr($document->path, 0, - (strlen($ext) + 1)); + $ext = '.'.$ext; + } else { + $ext = ''; + $file_name_no_ext = $document->path; + } + $new_file_name = $file_name_no_ext.'_'.$i.$ext; + $file_exists = file_exists($path.$new_file_name); + while ($file_exists) { + $i ++; + $new_file_name = $file_name_no_ext.'_'.$i.$ext; + $file_exists = file_exists($path.$new_file_name); + } + + if (!empty($session_id)) { + + $document_path = explode('/',$document->path,3); + $course_path = $path; + $orig_base_folder = $document_path[1]; + $orig_base_path = $course_path.$document_path[0].'/'.$document_path[1]; + + if (is_dir($orig_base_path)) { + + $new_base_foldername = $orig_base_folder; + $new_base_path = $orig_base_path; + + if ($_SESSION['orig_base_foldername'] != $new_base_foldername) { + unset($_SESSION['new_base_foldername']); + unset($_SESSION['orig_base_foldername']); + unset($_SESSION['new_base_path']); + } + + $folder_exists = file_exists($new_base_path); + if ($folder_exists) { + $_SESSION['orig_base_foldername'] = $new_base_foldername; // e.g: carpeta1 in session + $x = ''; + while ($folder_exists) { + $x = $x + 1; + $new_base_foldername = $document_path[1].'_'.$x; + $new_base_path = $orig_base_path.'_'.$x; + if ($_SESSION['new_base_foldername'] == $new_base_foldername) { + break; } + $folder_exists = file_exists($new_base_path); } + $_SESSION['new_base_foldername'] = $new_base_foldername; + $_SESSION['new_base_path'] = $new_base_path; + } - $params = [ - 'path' => "/".self::DBUTF8escapestring(substr($new_file_name, 9)), - 'c_id' => $this->destination_course_id, - 'comment'=> self::DBUTF8($document->comment), - 'title' => self::DBUTF8($document->title), - 'filetype' => self::DBUTF8($document->file_type), - 'size' => self::DBUTF8($document->size), - 'session_id' => $my_session_id, - ]; - - $document_id = Database::insert($table, $params); - - if ($document_id) { - $sql = "UPDATE $table SET id = iid WHERE iid = $document_id"; - Database::query($sql); - - $this->course->resources[RESOURCE_DOCUMENT][$id]->destination_id = $document_id; - - $itemProperty = isset($document->item_properties[0]) ? $document->item_properties[0] : ''; - $insertUserId = isset($itemProperty['insert_user_id']) ? $itemProperty['insert_user_id'] : api_get_user_id(); - $toGroupId = isset($itemProperty['to_group_id']) ? $itemProperty['to_group_id'] : 0; - $toUserId = isset($itemProperty['to_user_id']) ? $itemProperty['to_user_id'] : null; - - $insertUserId = $this->checkUserId($insertUserId); - $toUserId = $this->checkUserId($toUserId, true); - - api_item_property_update( - $course_info, - TOOL_DOCUMENT, - $document_id, - 'DocumentAdded', - $insertUserId, - $toGroupId, - $toUserId, - null, - null, - $my_session_id - ); - } - } - } else { + if (isset($_SESSION['new_base_foldername']) && isset($_SESSION['new_base_path'])) { + $new_base_foldername = $_SESSION['new_base_foldername']; + $new_base_path = $_SESSION['new_base_path']; + } + + $dest_document_path = $new_base_path.'/'.$document_path[2]; // e.g: "/var/www/wiener/courses/CURSO4/document/carpeta1_1/subcarpeta1/collaborative.png" + $basedir_dest_path = dirname($dest_document_path); // e.g: "/var/www/wiener/courses/CURSO4/document/carpeta1_1/subcarpeta1" + $base_path_document = $course_path.$document_path[0]; // e.g: "/var/www/wiener/courses/CURSO4/document" + $path_title = '/'.$new_base_foldername.'/'.$document_path[2]; + + copy_folder_course_session( + $basedir_dest_path, + $base_path_document, + $session_id, + $course_info, + $document, + $this->course_origin_id + ); - copy($this->course->backup_path.'/'.$document->path, $path.$new_file_name); + if (file_exists($course_path.$document->path)) { + copy($course_path.$document->path, $dest_document_path); + } //Replace old course code with the new destination code see BT#1985 - if (file_exists($path.$new_file_name)) { - $file_info = pathinfo($path.$new_file_name); + if (file_exists($dest_document_path)) { + $file_info = pathinfo($dest_document_path); if (in_array($file_info['extension'], array('html','htm'))) { - $content = file_get_contents($path.$new_file_name); + $content = file_get_contents($dest_document_path); if (UTF8_CONVERT) { $content = utf8_encode($content); } @@ -788,15 +662,15 @@ class CourseRestorer $this->course->backup_path, $this->course->info['path'] ); - file_put_contents($path.$new_file_name, $content); + file_put_contents($dest_document_path, $content); } } $params = [ + 'path' => self::DBUTF8($path_title), 'c_id' => $this->destination_course_id, - 'path' => "/".self::DBUTF8escapestring(substr($new_file_name, 9)), 'comment'=> self::DBUTF8($document->comment), - 'title' => self::DBUTF8($document->title), + 'title' => self::DBUTF8(basename($path_title)), 'filetype' => self::DBUTF8($document->file_type), 'size' => self::DBUTF8($document->size), 'session_id' => $my_session_id, @@ -831,102 +705,226 @@ class CourseRestorer null, $my_session_id ); - } - break; - - } // end switch - } else { - // end if file exists - //make sure the source file actually exists - if (is_file($this->course->backup_path.'/'.$document->path) && - is_readable($this->course->backup_path.'/'.$document->path) && - is_dir(dirname($path.$document->path)) && - is_writeable(dirname($path.$document->path)) - ) { - //echo 'Copying'; - copy($this->course->backup_path.'/'.$document->path, $path.$document->path); + } else { + if (file_exists($path.$document->path)) { + copy($path.$document->path, $path.$new_file_name); + } + //Replace old course code with the new destination code see BT#1985 + if (file_exists($path.$new_file_name)) { + $file_info = pathinfo($path.$new_file_name); + if (in_array($file_info['extension'], array('html','htm'))) { + $content = file_get_contents($path.$new_file_name); + if (UTF8_CONVERT) { + $content = utf8_encode($content); + } + $content = DocumentManager::replace_urls_inside_content_html_from_copy_course( + $content, + $this->course->code, + $this->course->destination_path, + $this->course->backup_path, + $this->course->info['path'] + ); + file_put_contents($path.$new_file_name, $content); + } + } - //Replace old course code with the new destination code see BT#1985 - if (file_exists($path.$document->path)) { - $file_info = pathinfo($path.$document->path); - if (in_array($file_info['extension'], array('html','htm'))) { - $content = file_get_contents($path.$document->path); - if (UTF8_CONVERT) { - $content = utf8_encode($content); + $params = [ + 'path' => "/".self::DBUTF8escapestring(substr($new_file_name, 9)), + 'c_id' => $this->destination_course_id, + 'comment'=> self::DBUTF8($document->comment), + 'title' => self::DBUTF8($document->title), + 'filetype' => self::DBUTF8($document->file_type), + 'size' => self::DBUTF8($document->size), + 'session_id' => $my_session_id, + ]; + + $document_id = Database::insert($table, $params); + + if ($document_id) { + $sql = "UPDATE $table SET id = iid WHERE iid = $document_id"; + Database::query($sql); + + $this->course->resources[RESOURCE_DOCUMENT][$id]->destination_id = $document_id; + + $itemProperty = isset($document->item_properties[0]) ? $document->item_properties[0] : ''; + $insertUserId = isset($itemProperty['insert_user_id']) ? $itemProperty['insert_user_id'] : api_get_user_id(); + $toGroupId = isset($itemProperty['to_group_id']) ? $itemProperty['to_group_id'] : 0; + $toUserId = isset($itemProperty['to_user_id']) ? $itemProperty['to_user_id'] : null; + + $insertUserId = $this->checkUserId($insertUserId); + $toUserId = $this->checkUserId($toUserId, true); + + api_item_property_update( + $course_info, + TOOL_DOCUMENT, + $document_id, + 'DocumentAdded', + $insertUserId, + $toGroupId, + $toUserId, + null, + null, + $my_session_id + ); } - $content = DocumentManager::replace_urls_inside_content_html_from_copy_course( - $content, - $this->course->code, - $this->course->destination_path, - $this->course->backup_path, - $this->course->info['path'] - ); - file_put_contents($path.$document->path, $content); } - } + } else { - $params = [ - 'c_id' => $this->destination_course_id, - 'path' => "/".self::DBUTF8(substr($document->path, 9)), - 'comment'=> self::DBUTF8($document->comment), - 'title' => self::DBUTF8($document->title), - 'filetype' => self::DBUTF8($document->file_type), - 'size' => self::DBUTF8($document->size), - 'session_id' => $my_session_id, - 'readonly' => 0 - ]; + copy($this->course->backup_path.'/'.$document->path, $path.$new_file_name); - $document_id = Database::insert($table, $params); + //Replace old course code with the new destination code see BT#1985 + if (file_exists($path.$new_file_name)) { + $file_info = pathinfo($path.$new_file_name); + if (in_array($file_info['extension'], array('html','htm'))) { + $content = file_get_contents($path.$new_file_name); + if (UTF8_CONVERT) { + $content = utf8_encode($content); + } + $content = DocumentManager::replace_urls_inside_content_html_from_copy_course( + $content, + $this->course->code, + $this->course->destination_path, + $this->course->backup_path, + $this->course->info['path'] + ); + file_put_contents($path.$new_file_name, $content); + } + } - if ($document_id) { - $sql = "UPDATE $table SET id = iid WHERE iid = $document_id"; - Database::query($sql); + $params = [ + 'c_id' => $this->destination_course_id, + 'path' => "/".self::DBUTF8escapestring(substr($new_file_name, 9)), + 'comment'=> self::DBUTF8($document->comment), + 'title' => self::DBUTF8($document->title), + 'filetype' => self::DBUTF8($document->file_type), + 'size' => self::DBUTF8($document->size), + 'session_id' => $my_session_id, + ]; + + $document_id = Database::insert($table, $params); + + if ($document_id) { + $sql = "UPDATE $table SET id = iid WHERE iid = $document_id"; + Database::query($sql); + } + + $this->course->resources[RESOURCE_DOCUMENT][$id]->destination_id = $document_id; + + $itemProperty = isset($document->item_properties[0]) ? $document->item_properties[0] : ''; + $insertUserId = isset($itemProperty['insert_user_id']) ? $itemProperty['insert_user_id'] : api_get_user_id(); + $toGroupId = isset($itemProperty['to_group_id']) ? $itemProperty['to_group_id'] : 0; + $toUserId = isset($itemProperty['to_user_id']) ? $itemProperty['to_user_id'] : null; + + $insertUserId = $this->checkUserId($insertUserId); + $toUserId = $this->checkUserId($toUserId, true); + + api_item_property_update( + $course_info, + TOOL_DOCUMENT, + $document_id, + 'DocumentAdded', + $insertUserId, + $toGroupId, + $toUserId, + null, + null, + $my_session_id + ); } + break; - $this->course->resources[RESOURCE_DOCUMENT][$id]->destination_id = $document_id; + } // end switch + } else { + // end if file exists + //make sure the source file actually exists + if (is_file($this->course->backup_path.'/'.$document->path) && + is_readable($this->course->backup_path.'/'.$document->path) && + is_dir(dirname($path.$document->path)) && + is_writeable(dirname($path.$document->path)) + ) { + //echo 'Copying'; + copy($this->course->backup_path.'/'.$document->path, $path.$document->path); + + //Replace old course code with the new destination code see BT#1985 + if (file_exists($path.$document->path)) { + $file_info = pathinfo($path.$document->path); + if (in_array($file_info['extension'], array('html','htm'))) { + $content = file_get_contents($path.$document->path); + if (UTF8_CONVERT) { + $content = utf8_encode($content); + } + $content = DocumentManager::replace_urls_inside_content_html_from_copy_course( + $content, + $this->course->code, + $this->course->destination_path, + $this->course->backup_path, + $this->course->info['path'] + ); + file_put_contents($path.$document->path, $content); + } + } - $itemProperty = isset($document->item_properties[0]) ? $document->item_properties[0] : ''; - $insertUserId = isset($itemProperty['insert_user_id']) ? $itemProperty['insert_user_id'] : api_get_user_id(); - $toGroupId = isset($itemProperty['to_group_id']) ? $itemProperty['to_group_id'] : 0; - $toUserId = isset($itemProperty['to_user_id']) ? $itemProperty['to_user_id'] : null; + $params = [ + 'c_id' => $this->destination_course_id, + 'path' => "/".self::DBUTF8(substr($document->path, 9)), + 'comment'=> self::DBUTF8($document->comment), + 'title' => self::DBUTF8($document->title), + 'filetype' => self::DBUTF8($document->file_type), + 'size' => self::DBUTF8($document->size), + 'session_id' => $my_session_id, + 'readonly' => 0 + ]; - $insertUserId = $this->checkUserId($insertUserId); - $toUserId = $this->checkUserId($toUserId, true); + $document_id = Database::insert($table, $params); - api_item_property_update( - $course_info, - TOOL_DOCUMENT, - $document_id, - 'DocumentAdded', - $insertUserId, - $toGroupId, - $toUserId, - null, - null, - $my_session_id - ); - } else { - if (is_file($this->course->backup_path.'/'.$document->path) && - is_readable($this->course->backup_path.'/'.$document->path) - ) { - error_log('Course copy generated an ignoreable error while trying to copy '.$this->course->backup_path.'/'.$document->path.': file not found'); - } - if (!is_dir(dirname($path.$document->path))) { - error_log('Course copy generated an ignoreable error while trying to copy to '.dirname($path.$document->path).': directory not found'); - } - if (!is_writeable(dirname($path.$document->path))) { - error_log('Course copy generated an ignoreable error while trying to copy to '.dirname($path.$document->path).': directory not writeable'); - } - } - } // end file doesn't exist - } - } // end for each + if ($document_id) { + $sql = "UPDATE $table SET id = iid WHERE iid = $document_id"; + Database::query($sql); + } - // Delete sessions for the copy the new folder in session - unset($_SESSION['new_base_foldername']); - unset($_SESSION['orig_base_foldername']); - unset($_SESSION['new_base_path']); - } + $this->course->resources[RESOURCE_DOCUMENT][$id]->destination_id = $document_id; + + $itemProperty = isset($document->item_properties[0]) ? $document->item_properties[0] : ''; + $insertUserId = isset($itemProperty['insert_user_id']) ? $itemProperty['insert_user_id'] : api_get_user_id(); + $toGroupId = isset($itemProperty['to_group_id']) ? $itemProperty['to_group_id'] : 0; + $toUserId = isset($itemProperty['to_user_id']) ? $itemProperty['to_user_id'] : null; + + $insertUserId = $this->checkUserId($insertUserId); + $toUserId = $this->checkUserId($toUserId, true); + + api_item_property_update( + $course_info, + TOOL_DOCUMENT, + $document_id, + 'DocumentAdded', + $insertUserId, + $toGroupId, + $toUserId, + null, + null, + $my_session_id + ); + } else { + if (is_file($this->course->backup_path.'/'.$document->path) && + is_readable($this->course->backup_path.'/'.$document->path) + ) { + error_log('Course copy generated an ignoreable error while trying to copy '.$this->course->backup_path.'/'.$document->path.': file not found'); + } + if (!is_dir(dirname($path.$document->path))) { + error_log('Course copy generated an ignoreable error while trying to copy to '.dirname($path.$document->path).': directory not found'); + } + if (!is_writeable(dirname($path.$document->path))) { + error_log('Course copy generated an ignoreable error while trying to copy to '.dirname($path.$document->path).': directory not writeable'); + } + } + } // end file doesn't exist + } + } // end for each + + // Delete sessions for the copy the new folder in session + unset($_SESSION['new_base_foldername']); + unset($_SESSION['orig_base_foldername']); + unset($_SESSION['new_base_path']); } /** From 5cd9e77f8eea8167a062788f202dff85fa03fc67 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Loguercio?= Date: Wed, 13 Jul 2016 17:31:59 -0500 Subject: [PATCH 14/23] Added Display::addFlash() to move_uploaded_files - Resf #8262 --- main/work/upload.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/main/work/upload.php b/main/work/upload.php index cd6b065ef5..98574322c5 100755 --- a/main/work/upload.php +++ b/main/work/upload.php @@ -105,6 +105,11 @@ if ($form->validate()) { if ($is_allowed_to_edit) { $script = 'work_list_all.php'; } + if (!$result) { + Display::addFlash(Display::return_message(get_lang('UploadError'), 'error')); + } else { + Display::addFlash(Display::return_message(get_lang('UplUploadSucceeded'), 'success')); + } header('Location: '.api_get_path(WEB_CODE_PATH).'work/'.$script.'?'.api_get_cidreq().'&id='.$work_id); exit; } else { From 4151d1fa16e34d993afad6a8ae5e09c894c7275b Mon Sep 17 00:00:00 2001 From: Yannick Warnier Date: Wed, 13 Jul 2016 17:43:01 -0500 Subject: [PATCH 15/23] Fix installer's allow-registration option: 'approval' option was never saved to database --- main/install/install.lib.php | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/main/install/install.lib.php b/main/install/install.lib.php index 313556353b..0fe3f878c0 100755 --- a/main/install/install.lib.php +++ b/main/install/install.lib.php @@ -1671,13 +1671,13 @@ function display_configuration_settings_form( } else { $html .= '
    '; $html .= ''; $html .= ''; $html .= ''; $html .= '
    '; } @@ -1965,9 +1965,10 @@ function installSettings( $allowTeacherSelfRegistration, $installationProfile = '' ) { - $allowRegistration = $allowRegistration ? 'true' : 'false'; + //$allowRegistration = $allowRegistration ? 'true' : 'false'; $allowTeacherSelfRegistration = $allowTeacherSelfRegistration ? 'true' : 'false'; + error_log($allowRegistration); // Use PHP 5.3 to avoid issue with weird peripherical auto-installers like travis-ci $settings = array( 'Institution' => $organizationName, From 5cd232cf00c6e0c1a57d58abf4a5c2d1e48885df Mon Sep 17 00:00:00 2001 From: Yannick Warnier Date: Wed, 13 Jul 2016 17:44:10 -0500 Subject: [PATCH 16/23] Fix installer's allow-registration option: 'approval' option was never saved to database (2) --- main/install/index.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/main/install/index.php b/main/install/index.php index b9139242b4..3104eb5ce1 100755 --- a/main/install/index.php +++ b/main/install/index.php @@ -258,8 +258,8 @@ if (!isset($_GET['running'])) { $checkEmailByHashSent = 0; $ShowEmailNotCheckedToStudent = 1; $userMailCanBeEmpty = 1; - $allowSelfReg = 1; - $allowSelfRegProf = 1; + $allowSelfReg = 'approval'; + $allowSelfRegProf = 1; //by default, a user can register as teacher (but moderation might be in place) $encryptPassForm = 'bcrypt'; if (!empty($_GET['profile'])) { $installationProfile = api_htmlentities($_GET['profile'], ENT_QUOTES); @@ -570,7 +570,7 @@ if (@$_POST['step2']) { $encryptPassForm = 'none'; } - $allowSelfReg = false; + $allowSelfReg = 'approval'; $tmp = get_config_param_from_db('allow_registration'); if (!empty($tmp)) { $allowSelfReg = $tmp; @@ -616,7 +616,7 @@ if (@$_POST['step2']) { echo get_lang('AdminLogin') . ' : ' . $loginForm . '
    '; echo get_lang('AdminPass') . ' : ' . $passForm . '

    '; /* TODO: Maybe this password should be hidden too? */ } - + $allowSelfRegistrationLiteral = ($allowSelfReg == 'true') ? get_lang('Yes') : ($allowSelfReg == 'approval' ? get_lang('Approval') : get_lang('No')); echo get_lang('AdminFirstName').' : '.$adminFirstName, '
    ', get_lang('AdminLastName').' : '.$adminLastName, '
    '; echo get_lang('AdminEmail').' : '.$emailForm; ?>

    @@ -626,7 +626,7 @@ if (@$_POST['step2']) {

    '.$dbNameForm; ?>
    -
    +
    From a1b4247b65dd8e50e0267ed79953e61c26c6e285 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Loguercio?= Date: Wed, 13 Jul 2016 17:57:29 -0500 Subject: [PATCH 17/23] Removed allow_browser_sniffer settings from platform - Refs #8319 --- .../Schema/V111/Version20160713180000.php | 39 +++++++++++++++++++ main/install/data.sql | 3 -- 2 files changed, 39 insertions(+), 3 deletions(-) create mode 100644 app/Migrations/Schema/V111/Version20160713180000.php diff --git a/app/Migrations/Schema/V111/Version20160713180000.php b/app/Migrations/Schema/V111/Version20160713180000.php new file mode 100644 index 0000000000..f6f30603fd --- /dev/null +++ b/app/Migrations/Schema/V111/Version20160713180000.php @@ -0,0 +1,39 @@ +addSql("DELETE FROM settings_current WHERE variable = 'allow_browser_sniffer'"); + $this->addSql("DELETE FROM settings_options WHERE variable = 'allow_browser_sniffer'"); + } + + /** + * @param Schema $schema + * @throws \Doctrine\DBAL\DBALException + * @throws \Doctrine\DBAL\Schema\SchemaException + */ + public function down(Schema $schema) + { + $this->addSql("INSERT INTO settings_current (variable, subkey, type, category, selected_value, title, comment, scope, subkeytext, access_url_changeable) VALUES ('allow_browser_sniffer', NULL, 'radio', 'Tuning', 'false', 'AllowBrowserSnifferTitle','AllowBrowserSnifferComment',NULL,NULL, 0)"); + $this->addSql("INSERT INTO settings_options (variable, value, display_text) VALUES ('allow_browser_sniffer','true','Yes') "); + $this->addSql("INSERT INTO settings_options (variable, value, display_text) VALUES ('allow_browser_sniffer','false','No') "); + } +} \ No newline at end of file diff --git a/main/install/data.sql b/main/install/data.sql index 1065037819..4349ed8764 100644 --- a/main/install/data.sql +++ b/main/install/data.sql @@ -269,7 +269,6 @@ VALUES ('languagePriority4', NULL, 'radio', 'Languages', 'platform_lang','LanguagePriority4Title', 'LanguagePriority4Comment', NULL, NULL, 0), ('login_is_email', NULL, 'radio', 'Platform', 'false', 'LoginIsEmailTitle', 'LoginIsEmailComment', NULL, NULL, 0), ('courses_default_creation_visibility', NULL, 'radio', 'Course', '2', 'CoursesDefaultCreationVisibilityTitle', 'CoursesDefaultCreationVisibilityComment', NULL, NULL, 1), -('allow_browser_sniffer', NULL, 'radio', 'Tuning', 'false', 'AllowBrowserSnifferTitle', 'AllowBrowserSnifferComment', NULL, NULL, 0), ('gradebook_enable_grade_model', NULL, 'radio', 'Gradebook', 'false', 'GradebookEnableGradeModelTitle', 'GradebookEnableGradeModelComment', NULL, NULL, 1), ('teachers_can_change_grade_model_settings', NULL, 'radio', 'Gradebook', 'true', 'TeachersCanChangeGradeModelSettingsTitle', 'TeachersCanChangeGradeModelSettingsComment', NULL, NULL, 1), ('gradebook_default_weight', NULL, 'textfield', 'Gradebook', '100', 'GradebookDefaultWeightTitle', 'GradebookDefaultWeightComment', NULL, NULL, 0), @@ -596,8 +595,6 @@ VALUES ('courses_default_creation_visibility', '2', 'OpenToThePlatform'), ('courses_default_creation_visibility', '1', 'Private'), ('courses_default_creation_visibility', '0', 'CourseVisibilityClosed'), -('allow_browser_sniffer', 'true', 'Yes'), -('allow_browser_sniffer', 'false', 'No'), ('teachers_can_change_score_settings', 'true', 'Yes'), ('teachers_can_change_score_settings', 'false', 'No'), ('teachers_can_change_grade_model_settings', 'true', 'Yes'), From 3562bbc2ad81c266a18e2d3d56ec130378d51244 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Loguercio?= Date: Wed, 13 Jul 2016 18:28:40 -0500 Subject: [PATCH 18/23] Added User Tag Filter to subscribe users to sessions - Refs #8302 --- main/session/add_users_to_session.php | 71 +++++++++++++++++++-------- 1 file changed, 51 insertions(+), 20 deletions(-) diff --git a/main/session/add_users_to_session.php b/main/session/add_users_to_session.php index 75b8564f76..5ad58a43c5 100644 --- a/main/session/add_users_to_session.php +++ b/main/session/add_users_to_session.php @@ -51,11 +51,21 @@ $new_field_list = array(); if (is_array($extra_field_list)) { foreach ($extra_field_list as $extra_field) { //if is enabled to filter and is a "'; echo ''; foreach ($new_field['data'] as $option) { $checked=''; - if (isset($_POST[$varname])) { - if ($_POST[$varname]==$option[1]) { - $checked = 'selected="true"'; - } - } - echo ''; - } - echo ''; - echo '  '; + if ($fieldtype == ExtraField::FIELD_TYPE_TAG) { + if (isset($_POST[$varname])) { + if ($_POST[$varname] == $option['tag']) { + $checked = 'selected="true"'; + } + } + echo ''; + } else { + if (isset($_POST[$varname])) { + if ($_POST[$varname] == $option[1]) { + $checked = 'selected="true"'; + } + } + echo ''; + } + } + echo ''; + $extraHidden = $fieldtype == ExtraField::FIELD_TYPE_TAG ? '' : ''; + echo $extraHidden; + echo '  '; } echo ''; echo '

    '; From d0e66faeb727512481633946942275b5abc5889f Mon Sep 17 00:00:00 2001 From: Angel Fernando Quiroz Campos Date: Wed, 13 Jul 2016 18:39:35 -0500 Subject: [PATCH 19/23] Fix import course validating foreign keys - refs #8113 --- main/inc/lib/api.lib.php | 43 ++++++++++++++++--- .../Component/CourseCopy/CourseRestorer.php | 4 +- .../CourseBundle/Entity/CItemProperty.php | 20 ++++++--- 3 files changed, 53 insertions(+), 14 deletions(-) diff --git a/main/inc/lib/api.lib.php b/main/inc/lib/api.lib.php index f1e2601c5d..f7a371adce 100644 --- a/main/inc/lib/api.lib.php +++ b/main/inc/lib/api.lib.php @@ -3583,6 +3583,8 @@ function api_item_property_update( return false; } + $em = Database::getManager(); + // Definition of variables. $tool = Database::escape_string($tool); $item_id = intval($item_id); @@ -3802,14 +3804,41 @@ function api_item_property_update( // Insert if no entries are found (can only happen in case of $last_edit_type switch is 'default'). if ($result == false || Database::affected_rows($result) == 0) { - $sessionCondition = empty($session_id) ? "NULL" : "'$session_id'"; - $sql = "INSERT INTO $tableItemProperty (c_id, tool,ref,insert_date,insert_user_id,lastedit_date,lastedit_type, lastedit_user_id, $to_field, visibility, start_visible, end_visible, session_id) - VALUES ($course_id, '$tool', $item_id, '$time', $user_id, '$time', '$last_edit_type', $user_id, $toValueCondition, $visibility, $startVisible, $endVisible, $sessionCondition)"; - Database::query($sql); - $id = Database::insert_id(); + $objCourse = $em->find('ChamiloCoreBundle:Course', intval($course_id)); + $objTime = new DateTime('now', new DateTimeZone('UTC')); + $objUser = $em->find('ChamiloUserBundle:User', intval($user_id)); + $objGroup = $em->find('ChamiloCourseBundle:CGroupInfo', intval($to_group_id)); + $objToUser = $em->find('ChamiloUserBundle:User', intval($to_user_id)); + $objSession = $em->find('ChamiloCoreBundle:Session', intval($session_id)); + + $startVisibleDate = !empty($start_visible) ? new DateTime($start_visible, new DateTimeZone('UTC')) : null; + $endVisibleDate = !empty($endVisibleDate) ? new DateTime($endVisibleDate, new DateTimeZone('UTC')) : null; + + $cItemProperty = new \Chamilo\CourseBundle\Entity\CItemProperty($objCourse); + $cItemProperty + ->setTool($tool) + ->setRef($item_id) + ->setInsertDate($objTime) + ->setInsertUser($objUser) + ->setLasteditDate($objTime) + ->setLasteditType($last_edit_type) + ->setGroup($objGroup) + ->setToUser($objToUser) + ->setVisibility($visibility) + ->setStartVisible($startVisibleDate) + ->setEndVisible($endVisibleDate) + ->setSession($objSession); + + $em->persist($cItemProperty); + $em->flush(); + + $id = $cItemProperty->getIid(); + if ($id) { - $sql = "UPDATE $tableItemProperty SET id = iid WHERE iid = $id"; - Database::query($sql); + $cItemProperty->setId($id); + $em->merge($cItemProperty); + $em->flush(); + return false; } } diff --git a/src/Chamilo/CourseBundle/Component/CourseCopy/CourseRestorer.php b/src/Chamilo/CourseBundle/Component/CourseCopy/CourseRestorer.php index 23fe58dc75..7d0b74827e 100644 --- a/src/Chamilo/CourseBundle/Component/CourseCopy/CourseRestorer.php +++ b/src/Chamilo/CourseBundle/Component/CourseCopy/CourseRestorer.php @@ -2603,9 +2603,9 @@ class CourseRestorer if ($lp->lp_type =='2') { // if is an sco $old_refs[$new_item_id]= $ref; - } else { + } elseif (isset($new_item_ids[$ref])) { $old_refs[$new_item_id]= $new_item_ids[$ref]; - } + } } $prerequisite_ids[$new_item_id] = $item['prerequisite']; diff --git a/src/Chamilo/CourseBundle/Entity/CItemProperty.php b/src/Chamilo/CourseBundle/Entity/CItemProperty.php index 9674a9e4c4..0e8f3acfdd 100644 --- a/src/Chamilo/CourseBundle/Entity/CItemProperty.php +++ b/src/Chamilo/CourseBundle/Entity/CItemProperty.php @@ -126,12 +126,13 @@ class CItemProperty /** * CItemProperty constructor. + * @param Course $course */ public function __construct(Course $course) { $this->course = $course; - $this->insertDate = new \DateTime(); - $this->lasteditDate = new \DateTime(); + $this->insertDate = new \DateTime('now', new \DateTimeZone('UTC')); + $this->lasteditDate = new \DateTime('now', new \DateTimeZone('UTC')); } /** @@ -189,7 +190,7 @@ class CItemProperty * * @return CItemProperty */ - public function setLasteditDate($lasteditDate) + public function setLasteditDate(\DateTime $lasteditDate) { $this->lasteditDate = $lasteditDate; @@ -309,7 +310,7 @@ class CItemProperty * * @return CItemProperty */ - public function setStartVisible($startVisible) + public function setStartVisible(\DateTime $startVisible = null) { $this->startVisible = $startVisible; @@ -333,7 +334,7 @@ class CItemProperty * * @return CItemProperty */ - public function setEndVisible($endVisible) + public function setEndVisible(\DateTime $endVisible = null) { $this->endVisible = $endVisible; @@ -474,4 +475,13 @@ class CItemProperty return $this; } + + /** + * Get iid + * @return int + */ + public function getIid() + { + return $this->iid; + } } From 239901e2ee5e75a9e2f7bb59136b62e0dff9d00c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Loguercio?= Date: Wed, 13 Jul 2016 18:53:31 -0500 Subject: [PATCH 20/23] Minor Code PSR fixes --- main/inc/lib/MoodleImport.lib.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/main/inc/lib/MoodleImport.lib.php b/main/inc/lib/MoodleImport.lib.php index 522ff6ff05..0bb9e8f523 100644 --- a/main/inc/lib/MoodleImport.lib.php +++ b/main/inc/lib/MoodleImport.lib.php @@ -57,7 +57,7 @@ class MoodleImport if ($activity->childNodes->length) { $currentItem = []; - foreach($activity->childNodes as $item) { + foreach ($activity->childNodes as $item) { $currentItem[$item->nodeName] = $item->nodeValue; } @@ -174,7 +174,7 @@ class MoodleImport $documentPath = $coursePath.'document/'; $currentResourceFilePath = $destinationDir.'/files/'; $dirs = new RecursiveDirectoryIterator($currentResourceFilePath); - foreach(new RecursiveIteratorIterator($dirs) as $file) { + foreach (new RecursiveIteratorIterator($dirs) as $file) { if (is_file($file) && strpos($file, $fileInfo['contenthash']) !== false) { $files = []; $files['file']['name'] = $fileInfo['filename']; @@ -272,7 +272,7 @@ class MoodleImport $currentItem = []; foreach ($activities as $activity) { if ($activity->childNodes->length) { - foreach($activity->childNodes as $item) { + foreach ($activity->childNodes as $item) { $currentItem[$item->nodeName] = $item->nodeValue; } } @@ -370,7 +370,7 @@ class MoodleImport foreach ($activities as $activity) { if ($activity->childNodes->length) { $isThisItemThatIWant = false; - foreach($activity->childNodes as $item) { + foreach ($activity->childNodes as $item) { if (!$isThisItemThatIWant && $item->nodeName == 'contenthash') { $currentItem['contenthash'] = $item->nodeValue; } @@ -424,7 +424,7 @@ class MoodleImport if ($question->childNodes->length) { $currentItem['questionid'] = $questionId; $questionType = ''; - foreach($question->childNodes as $item) { + foreach ($question->childNodes as $item) { $currentItem[$item->nodeName] = $item->nodeValue; if ($item->nodeName == 'qtype') { $questionType = $item->nodeValue; From c06f0b775c5873466a1827d007a1b6df87b4b402 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Loguercio?= Date: Wed, 13 Jul 2016 18:55:47 -0500 Subject: [PATCH 21/23] Rename MoodleImport.lib.php to MoodleImport.class.php - Refs BT#11209 --- main/coursecopy/import_moodle.php | 2 +- main/inc/lib/{MoodleImport.lib.php => MoodleImport.class.php} | 0 2 files changed, 1 insertion(+), 1 deletion(-) rename main/inc/lib/{MoodleImport.lib.php => MoodleImport.class.php} (100%) diff --git a/main/coursecopy/import_moodle.php b/main/coursecopy/import_moodle.php index 14b351051a..0f3aec57b0 100644 --- a/main/coursecopy/import_moodle.php +++ b/main/coursecopy/import_moodle.php @@ -9,7 +9,7 @@ */ require_once '../inc/global.inc.php'; -require_once '../inc/lib/MoodleImport.lib.php'; +require_once '../inc/lib/MoodleImport.class.php'; $current_course_tool = TOOL_COURSE_MAINTENANCE; api_protect_course_script(true); diff --git a/main/inc/lib/MoodleImport.lib.php b/main/inc/lib/MoodleImport.class.php similarity index 100% rename from main/inc/lib/MoodleImport.lib.php rename to main/inc/lib/MoodleImport.class.php From 7ad027db2fa4440f34255abb3c2734e18ff517b1 Mon Sep 17 00:00:00 2001 From: Yannick Warnier Date: Wed, 13 Jul 2016 20:31:43 -0500 Subject: [PATCH 22/23] Update language terms --- main/lang/english/trad4all.inc.php | 9 ++++++++- main/lang/french/trad4all.inc.php | 7 +++++++ main/lang/spanish/trad4all.inc.php | 8 ++++++++ 3 files changed, 23 insertions(+), 1 deletion(-) diff --git a/main/lang/english/trad4all.inc.php b/main/lang/english/trad4all.inc.php index c019954bc9..8c4ee59742 100644 --- a/main/lang/english/trad4all.inc.php +++ b/main/lang/english/trad4all.inc.php @@ -1459,7 +1459,7 @@ $UpgradeBase = "Upgrade database"; $ErrorsFound = "errors found"; $Maintenance = "Backup"; $Upgrade = "Upgrade Chamilo"; -$Website = "Chamilo website"; +$Website = "Website"; $Documentation = "Documentation"; $Contribute = "Contribute"; $InfoServer = "Server Information"; @@ -7814,8 +7814,15 @@ $CourseCreationSplashScreenComment = "The course splash screen show a series of $WorksReport = "Assignments report"; $AccumulateScormTime = "Accumulate SCORM session time"; $AccumulateScormTimeInfo = "When enabled, the session time for SCORM learning paths will be cumulative, otherwise, it will only be counted from the last update time."; +$CalendarStartDate = "Start date"; $DownloadTasksPackage = "Download assignments package"; $UploadCorrectionsPackage = "Upload corrections package"; $IconsModeSVGTitle = "SVG icons mode"; $IconsModeSVGComment = "By enabling this option, all icons that have an SVG version will prefer the SVG format to PNG. This will give a much better icons quality but some icons might still have some rendering size issue, and some browsers might not support it."; +$FilterByTags = "Filter by tags"; +$ImportFromMoodle = "Import from Moodle"; +$ImportFromMoodleInfo = "Import a Moodle course backup file (.mbz) into this Chamilo course"; +$ImportFromMoodleInstructions = "The Moodle import feature might not support all content types from Moodle, given the fact that not all features are the same, and that Moodle and Chamilo both evolve continuously and rapidly. This import feature should be considered a work in progress. Please check https://support.chamilo.org/projects/chamilo-18/wiki/Moodle_import for more information."; +$MoodleFile = "Moodle course file"; +$FailedToImportThisIsNotAMoodleFile = "Failed to import: this doesn't seem to be a Moodle course backup file (.mbz)"; ?> \ No newline at end of file diff --git a/main/lang/french/trad4all.inc.php b/main/lang/french/trad4all.inc.php index 7d6f8c10e8..5001b52ade 100644 --- a/main/lang/french/trad4all.inc.php +++ b/main/lang/french/trad4all.inc.php @@ -7761,8 +7761,15 @@ $CourseCreationSplashScreenComment = "L'écran d'accueil de création de cours m $WorksReport = "Rapport"; $AccumulateScormTime = "Temps cumulatif SCORM"; $AccumulateScormTimeInfo = "Si activé, le temps de session pour les parcours SCORM sera cumulatif. Sinon, il sera uniquement compté depuis le dernier temps de connexion."; +$CalendarStartDate = "Date de début"; $DownloadTasksPackage = "Télécharger tous les travaux"; $UploadCorrectionsPackage = "Envoyer un paquet de travaux"; $IconsModeSVGTitle = "Mode SVG des icônes"; $IconsModeSVGComment = "Cette option, lorsqu'elle est activée, préférera les icônes au format vectoriel SVG aux icônes bitmap PNG. Cela donnera un rendu beaucoup plus fin, mais certaines icônes pourraient avoir de petits problèmes de dimensions, et quelques navigateurs pourraient ne pas supporter ce format."; +$FilterByTags = "Filtrer par tag"; +$ImportFromMoodle = "Importer depuis Moodle"; +$ImportFromMoodleInfo = "Importer un fichier de backup de cours de Moodle (.mbz) dans ce cours de Chamilo"; +$ImportFromMoodleInstructions = "La fonctionnalité d'importation peut ne pas supporter tous les types de contenus de Moodle, étant donné le fait que les fonctionnalités ne sont pas toutes identiques, et que Moodle et Chamilo continuent d'évoluer continuellement et rapidement. Cette fonctionnalité d'import devrait être considérée comme un travail en cours. Merci de réviser la page suivante pour plus d'information: https://support.chamilo.org/projects/chamilo-18/wiki/Moodle_import"; +$MoodleFile = "Fichier de cours de Moodle"; +$FailedToImportThisIsNotAMoodleFile = "Problème rencontré lors de l'importation: le fichier soumis ne semble pas être un fichier de backup de cours de Moodle (.mbz)"; ?> \ No newline at end of file diff --git a/main/lang/spanish/trad4all.inc.php b/main/lang/spanish/trad4all.inc.php index 2788698b00..0dfbcf3068 100644 --- a/main/lang/spanish/trad4all.inc.php +++ b/main/lang/spanish/trad4all.inc.php @@ -7833,7 +7833,15 @@ $CourseCreationSplashScreenComment = "La pantalla de bienvenida muestra una seri $WorksReport = "Reporte de tareas"; $AccumulateScormTime = "Acumular tiempo de sesión SCORM"; $AccumulateScormTimeInfo = "Cuando se activa, el tiempo de una sesión para una secuencia de aprendizaje SCORM será acumulativo, de lo contrario, sólo se contará desde el momento de la última actualización."; +$CalendarStartDate = "Fecha de inicio"; $DownloadTasksPackage = "Descargar tareas en paquete"; +$UploadCorrectionsPackage = "Subir un paquete de correcciones"; $IconsModeSVGTitle = "Modo SVG de iconos"; $IconsModeSVGComment = "Esta opción permite, si es activada, preferir el formato vectorial SVG al formato bitmap PNG para todos los iconos que tienen tal versión. Esto permite obtener una calidad de iconos mucho más fina, pero algunos iconos podrían tener problemas de tamaño, y algunos navegadores podrían no soportarlas."; +$FilterByTags = "Filtrar por tags"; +$ImportFromMoodle = "Importar desde Moodle"; +$ImportFromMoodleInfo = "Importar un archivo de backup de curso de Moodle (.mbz) dentro de este curso de Chamilo"; +$ImportFromMoodleInstructions = "La funcionalidad de importación desde Moodle podría no soportar todos los tipos de contenido de Moodle, dado el hecho que no todas las funcionalidades existen en ambas plataformas, y que Moodle y Chamilo siguen evolucionando contínuamente y rápidamente. Esta funcionalidad de importación debería ser considerada como un trabajo en progreso. Consulte la página siguiente para mayor información: https://support.chamilo.org/projects/chamilo-18/wiki/Moodle_import"; +$MoodleFile = "Archivo de curso de Moodle"; +$FailedToImportThisIsNotAMoodleFile = "La importación tuvo un problema: este archivo no parece ser un archivo de backup de curso de Moodle (.mbz)"; ?> \ No newline at end of file From 307f729c994ff8fa58a0e973d2086780ab81d9e2 Mon Sep 17 00:00:00 2001 From: Yannick Warnier Date: Thu, 14 Jul 2016 11:25:10 -0500 Subject: [PATCH 23/23] Fix little issue on install - refs CT#8337 --- main/install/index.php | 2 +- main/install/install.lib.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/main/install/index.php b/main/install/index.php index 3104eb5ce1..37a54c80a6 100755 --- a/main/install/index.php +++ b/main/install/index.php @@ -946,7 +946,7 @@ if (@$_POST['step2']) { $connection->executeQuery("ALTER TABLE faq_question ADD CONSTRAINT FK_4A55B05912469DE2 FOREIGN KEY (category_id) REFERENCES faq_category (id);"); */ // Add version table - $connection->executeQuery('CREATE TABLE version (version varchar(255), PRIMARY KEY(version));'); + $connection->executeQuery('CREATE TABLE version (id int unsigned NOT NULL AUTO_INCREMENT, version varchar(255), PRIMARY KEY(id));'); // Tickets $table = Database::get_main_table(TABLE_TICKET_PROJECT); diff --git a/main/install/install.lib.php b/main/install/install.lib.php index 0fe3f878c0..880691bcb5 100755 --- a/main/install/install.lib.php +++ b/main/install/install.lib.php @@ -2198,7 +2198,7 @@ function finishInstallation( $files = $finder->files()->in($path); foreach ($files as $version) { $version = str_replace(['Version', '.php' ], '', $version->getFilename()); - $sql = "INSERT INTO version VALUES ('$version')"; + $sql = "INSERT INTO version (version) VALUES ('$version')"; Database::query($sql); } }