global $current_identifier;
$str_trimmed_data = trim($data);
-
+
if (!empty($str_trimmed_data)) {
$size = count($path);
if ($size > 0) {
$parent_item_id = 0;
}
- if (isset($items[$current_item_id]['parent_content_id']) && is_array($items[$current_item_id])) {
-
+ if (array_key_exists($current_item_id, $items) && is_array($items[$current_item_id]) && isset($items[$current_item_id]['parent_content_id'])) {
/* this item already exists, append the title */
/* this fixes {\n, \t, `, &} characters in elements */
$package_base_name_url = md5(time());
}
$ext = pathinfo($_FILES['file']['name']);
-$ext = $ext['extension'];
+$ext = array_key_exists('extension', $ext) ? $ext['extension'] : '';
if ($ext != 'zip') {
$msg->addError('IMPORTDIR_IMS_NOTVALID');
} else {
header('Location: '.$_SERVER['HTTP_REFERER']);
}
- if (file_exists($full_filename)) @unlink($full_filename);
+ if (isset($full_filename) && file_exists($full_filename)) @unlink($full_filename);
exit;
}
$items = rehash($items);
//debug($items);exit;
foreach ($items as $item_id => $content_info)
-{
+{
//formatting field, default 1
$content_formatting = 1; //CONTENT_TYPE_CONTENT
+ $lti_offset[$content_info['parent_content_id']] = 0;
//don't want to display glossary as a page
- if ($content_info['href']== 'glossary.xml'){
+ if (isset($content_info['href']) && $content_info['href'] == 'glossary.xml'){
continue;
}
//if discussion tools, add it to the list of unhandled dts
- if ($content_info['type']=='imsdt_xmlv1p0'){
+ if (isset($content_info['type']) && $content_info['type'] == 'imsdt_xmlv1p0'){
//if it will be taken care after (has dependency), then move along.
if (in_array($item_id, $avail_dt)){
$lti_offset[$content_info['parent_content_id']]++;
//check dependency immediately, then handles it
$head = '';
- if (is_array($content_info['dependency']) && !empty($content_info['dependency'])){
+ if (isset($content_info['dependency']) && is_array($content_info['dependency']) && !empty($content_info['dependency'])){
foreach($content_info['dependency'] as $dependency_ref){
//check if this is a discussion tool dependency
- if ($items[$dependency_ref]['type']=='imsdt_xmlv1p0'){
+ if (array_key_exists($dependency_ref, $items) && $items[$dependency_ref]['type']=='imsdt_xmlv1p0'){
$items[$item_id]['forum'][$dependency_ref] = $items[$dependency_ref]['href'];
}
//check if this is a QTI dependency
- if (strpos($items[$dependency_ref]['type'], 'imsqti_xmlv1p2/imscc_xmlv1p0') !== false){
+ if (array_key_exists($dependency_ref, $items) && strpos($items[$dependency_ref]['type'], 'imsqti_xmlv1p2/imscc_xmlv1p0') !== false){
$items[$item_id]['tests'][$dependency_ref] = $items[$dependency_ref]['href'];
}
}
// remote href
- if (preg_match('/^http.*:\/\//', trim($content_info['href'])) )
+ if (isset($content_info['href']) && preg_match('/^http.*:\/\//', trim($content_info['href'])) )
{
$content = '<a href="'.$content_info['href'].'" target="_blank">'.$content_info['title'].'</a>';
}
if ($content_type == 'IMS Common Cartridge'){
//to handle import with purely images but nothing else
//don't need a content base path for it.
- $content_new_path = $content_info['new_path'];
+ $content_new_path = isset($content_info['new_path']) ? $content_info['new_path'] : '';
$content_info['new_path'] = '';
}
if (isset($content_info['href'], $xml_base_path)) {
}
$content_parent_id = $cid;
if ($content_info['parent_content_id'] !== 0) {
- $content_parent_id = $items[$content_info['parent_content_id']]['real_content_id'];
+ $content_parent_id = isset($items[$content_info['parent_content_id']]) ? $items[$content_info['parent_content_id']]['real_content_id'] : 0;
//if it's not there, use $cid
if (!$content_parent_id){
$content_parent_id = $cid;
}
//handles weblinks
- if ($content_info['type']=='imswl_xmlv1p0'){
+ if (isset($content_info['type']) && $content_info['type']=='imswl_xmlv1p0'){
$weblinks_parser = new WeblinksParser();
- $xml_content = @file_get_contents($import_path . $content_info['href']);
- $weblinks_parser->parse($xml_content);
- $content_info['title'] = $weblinks_parser->getTitle();
- $content = $weblinks_parser->getUrl();
- $content_folder_type = CONTENT_TYPE_WEBLINK;
- $content_formatting = 2;
+ $xml_content = @file_get_contents($import_path . $content_info['file'][0]);
+ if ($weblinks_parser->parse($xml_content)) {
+ $content_info['title'] = $weblinks_parser->getTitle();
+ $content = $weblinks_parser->getUrl();
+ $content_folder_type = CONTENT_TYPE_WEBLINK;
+ $content_formatting = 2;
+ }
}
//if this file is a test_xml, create a blank page instead, for imscc.
- if (preg_match('/((.*)\/)*tests\_[0-9]+\.xml$/', $content_info['href'])
- || preg_match('/imsqti\_(.*)/', $content_info['type'])) {
+ if ((isset($content_info['href']) && preg_match('/((.*)\/)*tests\_[0-9]+\.xml$/', $content_info['href']))
+ || (isset($content_info['type']) && preg_match('/imsqti\_(.*)/', $content_info['type']))) {
$content = ' ';
}
if ($content_formatting!=CONTENT_TYPE_WEBLINK){
$content_folder_type = (!isset($content_info['type'])?CONTENT_TYPE_FOLDER:CONTENT_TYPE_CONTENT);
}
-
- $items[$item_id]['real_content_id'] = $contentDAO->Create($_course_id, intval($content_parent_id),
- ($content_info['ordering'] + $my_offset - $lti_offset[$content_info['parent_content_id']] + 1),
- 0, $content_formatting, "", $content_info['new_path'], $content_info['title'],
- $content, $head, 1, $content_info['test_message'], $content_folder_type);
-
-
+ $result = $contentDAO->Create($_course_id, intval($content_parent_id),
+ ($content_info['ordering'] + $my_offset - (array_key_exists($content_info['parent_content_id'], $lti_offset) ? $lti_offset[$content_info['parent_content_id']] : 0) + 1),
+ 0, $content_formatting, "", $content_info['new_path'], $content_info['title'],
+ $content, $head, 1, array_key_exists('test_message',$content_info) ? $content_info['test_message'] : '', $content_folder_type);
+ if ($result)
+ $items[$item_id]['real_content_id'] = $result;
+ else {
+ $msg->addError(array('IMPORT_CARTRIDGE_FAILED', 'course_id='.$_course_id.', $item_id='.$item_id.', $content_parent_id='.$content_parent_id.', title="'.$content_info['title'].'"'."\n"));
+ }
/* get the tests associated with this content */
- if (!empty($items[$item_id]['tests']) || strpos($items[$item_id]['type'], 'imsqti_xmlv1p2/imscc_xmlv1p0') !== false){
+ if (!empty($items[$item_id]['tests']) || (isset($items[$item_id]['type']) && strpos($items[$item_id]['type'], 'imsqti_xmlv1p2/imscc_xmlv1p0') !== false)){
$qti_import = new QTIImport($import_path);
if (isset($items[$item_id]['tests'])){
$loop_var = $items[$item_id]['tests'];
}
}
- } elseif ($items[$item_id]['type']=='imsdt_xmlv1p0'){
+ } elseif (isset($items[$item_id]['type']) && $items[$item_id]['type']=='imsdt_xmlv1p0'){
//optimize this, repeated codes as above
$dt_parser = new DiscussionToolsParser();
$dt_import = new DiscussionToolsImport();