Esempio n. 1
0
require_once TR_INCLUDE_PATH . 'classes/DAO/ContentTestsAssocDAO.class.php';
global $_course_id;
Utility::authenticate(TR_PRIV_ISAUTHOR_OF_CURRENT_COURSE);
$testsDAO = new TestsDAO();
if (isset($_POST['submit_no'])) {
    $msg->addFeedback('CANCELLED');
    header('Location: index.php?_course_id=' . $_course_id);
    exit;
} else {
    if (isset($_POST['submit_yes'])) {
        $tid = intval($_POST['tid']);
        if ($testsDAO->Delete($tid)) {
            $testsQuestionsAssocDAO = new TestsQuestionsAssocDAO();
            $testsQuestionsAssocDAO->DeleteByTestID($tid);
            //delete test content association as well
            $contentTestsAssocDAO = new ContentTestsAssocDAO();
            $contentTestsAssocDAO->DeleteByTestID($tid);
        }
        $msg->addFeedback('ACTION_COMPLETED_SUCCESSFULLY');
        header('Location: ' . TR_BASE_HREF . 'tests/index.php?_course_id=' . $_course_id);
        exit;
    }
}
/* else: */
require_once TR_INCLUDE_PATH . 'header.inc.php';
$_GET['tid'] = intval($_GET['tid']);
$row = $testsDAO->get($_GET['tid']);
unset($hidden_vars);
$hidden_vars['tid'] = $_GET['tid'];
$hidden_vars['_course_id'] = $_course_id;
$msg->addConfirm(array('DELETE_TEST', $row['title']), $hidden_vars);
Esempio n. 2
0
 /**
  * Delete content
  * @access  public
  * @param   content ID
  * @return  true, if successful
  *          false and add error into global var $msg, if unsuccessful
  * @author  Cindy Qi Li
  */
 public function Delete($contentID)
 {
     global $msg;
     require_once TR_INCLUDE_PATH . 'classes/A4a/A4a.class.php';
     $a4a = new A4a($contentID);
     $a4a->deleteA4a();
     // delete the content tests association
     include_once TR_INCLUDE_PATH . 'classes/DAO/ContentTestsAssocDAO.class.php';
     $contentTestsAssocDAO = new ContentTestsAssocDAO();
     $contentTestsAssocDAO->DeleteByContentID($contentID);
     // delete the content forums association
     include_once TR_INCLUDE_PATH . 'classes/DAO/ContentForumsAssocDAO.class.php';
     $contentForumsAssocDAO = new ContentForumsAssocDAO();
     $contentForumsAssocDAO->DeleteByContentID($contentID);
     $sql = "DELETE FROM " . TABLE_PREFIX . "content WHERE content_id = " . $contentID;
     if ($this->execute($sql)) {
         // update the courses.modified_date to the current timestamp
         include_once TR_INCLUDE_PATH . 'classes/DAO/CoursesDAO.class.php';
         $coursesDAO = new CoursesDAO();
         $coursesDAO->updateModifiedDate($contentID, "content_id");
         return true;
     } else {
         $msg->addError('DB_NOT_UPDATED');
         return false;
     }
 }
Esempio n. 3
0
function print_organizations($parent_id, &$_menu, $depth, $path = '', $children, &$string)
{
    global $html_content_template, $default_html_style, $zipfile, $resources, $ims_template_xml, $parser, $my_files;
    global $used_glossary_terms, $course_id, $course_language_charset, $course_language_code;
    static $paths, $zipped_files;
    //	global $glossary;
    global $test_list, $test_zipped_files, $test_files, $test_xml_items, $use_a4a;
    global $contentManager;
    /* added by bologna*/
    //TODO***********BOLOGNA**************REMOVE ME*****************/
    global $db, $forum_list;
    //forum_list contiene tutti i forum distinti associati ai contenuti. poich� la funzione in questione � ricorsiva deve essere globale in modo che in fase di creazione dell'archivio zip i file descrittori dei forum non vengano ripetuti
    require_once TR_INCLUDE_PATH . '../home/classes/ContentUtility.class.php';
    require_once TR_INCLUDE_PATH . 'classes/DAO/ContentForumsAssocDAO.class.php';
    $space = '    ';
    $prefix = '                    ';
    if ($depth == 0) {
        $string .= '<ul>';
    }
    $top_level = $_menu[$parent_id];
    if (!is_array($paths)) {
        $paths = array();
    }
    if (!is_array($zipped_files)) {
        $zipped_files = array();
    }
    if (is_array($top_level)) {
        $counter = 1;
        $num_items = count($top_level);
        foreach ($top_level as $garbage => $content) {
            $link = '';
            //XSL characters handling
            $content['title'] = str_replace('&', '&amp;', $content['title']);
            if ($content['content_path'] && substr($content['content_path'], -1) != '/') {
                $content['content_path'] .= '/';
            }
            /* 
             * generate weblinks 
             * Reason to put it here is cause we don't want the content to be overwrittened.
             */
            if ($content['content_type'] == CONTENT_TYPE_WEBLINK) {
                $wl = new Weblinks($content['title'], $content['text']);
                $wlexport = new WeblinksExport($wl);
                $wl_xml = $wlexport->export();
                $wl_filename = 'weblinks_' . $content['content_id'] . '.xml';
                $zipfile->add_file($wl_xml, 'Weblinks/' . $wl_filename, $content['u_ts']);
                $resources .= str_replace(array('{PATH}', '{CONTENT_ID}'), array($wl_filename, $content['content_id']), $ims_template_xml['resource_weblink']);
                //Done.
                //				continue;
            }
            if ($content['content_type'] == CONTENT_TYPE_FOLDER) {
                $link .= $prefix . '<item identifier="MANIFEST01_FOLDER' . $content['content_id'] . '">' . "\n";
                $link .= $prefix . $space . '<title>' . $content['title'] . '</title>' . "\n";
            } else {
                $link .= '<item identifier="MANIFEST01_ITEM' . $content['content_id'] . '" identifierref="MANIFEST01_RESOURCE' . $content['content_id'] . '">' . "\n";
                $link .= $prefix . $space . '<title>' . $content['title'] . '</title>' . "\n{$prefix}{$space}";
            }
            $html_link = '<a href="resources/' . $content['content_path'] . $content['content_id'] . '.html" target="body">' . $content['title'] . '</a>';
            /* save the content as HTML files */
            $content['text'] = str_replace('CONTENT_DIR/', '', $content['text']);
            /* Commented by Cindy Qi Li on Jan 12, 2010
            			 * AContent does not support glossary
            			// get all the glossary terms used
            			$terms = find_terms($content['text']);
            			if (is_array($terms)) {
            				foreach ($terms[2] as $term) {
            					$used_glossary_terms[] = $term;
            				}
            			}
            */
            $f_count = count($forum_list);
            //count all distinct forum_id associated to a content page
            //la funzione è ricorsiva quindi lo devo ricavare attraverso la variabile globale forum_list
            $contentForumsAssocDAO = new ContentForumsAssocDAO();
            $forums = $contentForumsAssocDAO->getByContent($content[content_id]);
            //                    $sql = "SELECT cf.forum_id, f.title, f.description FROM (SELECT * FROM ".TABLE_PREFIX."content_forums_assoc WHERE content_id=$content[content_id]) AS cf LEFT JOIN ".TABLE_PREFIX."forums f ON cf.forum_id=f.forum_id";
            //                    $result_cf = mysql_query($sql,$db);
            $find = false;
            $forums_dependency = '';
            //template for associate Discussion Topic to the current content into the manifest
            if (is_array($forums)) {
                foreach ($forums as $current_forum) {
                    for ($j = 0; $j < $f_count; $j++) {
                        if ($forum_list[$j]['id'] == $current_forum['forum_id']) {
                            $find = true;
                        }
                    }
                    if (!$find) {
                        $forum_list[$f_count]['id'] = $current_forum['forum_id'];
                        $forum_list[$f_count]['title'] = $current_forum['title'];
                        $forum_list[$f_count]['description'] = $current_forum['description'];
                        $find = false;
                        $f_count++;
                    }
                }
                $forums_dependency .= $prefix . $space . '<dependency identifierref="Forum' . $current_forum['forum_id'] . '_R" />';
            }
            /** Test dependency **/
            require_once TR_INCLUDE_PATH . 'classes/DAO/ContentTestsAssocDAO.class.php';
            $contentTestsAssocDAO = new ContentTestsAssocDAO();
            //			$sql = 'SELECT * FROM '.TABLE_PREFIX.'content_tests_assoc WHERE content_id='.$content['content_id'];
            //			$result = mysql_query($sql, $db);
            //			while ($row = mysql_fetch_assoc($result)){
            $rows = $contentTestsAssocDAO->getByContent($content['content_id']);
            if (is_array($rows)) {
                //add test dependency on top of forum dependency
                foreach ($rows as $row) {
                    $forums_dependency .= $prefix . $space . '<dependency identifierref="MANIFEST01_RESOURCE_QTI' . $row['test_id'] . '" />';
                }
            }
            /* calculate how deep this page is: */
            $path = '../';
            if ($content['content_path']) {
                $depth = substr_count($content['content_path'], '/');
                $path .= str_repeat('../', $depth);
            }
            $content['text'] = ContentUtility::formatContent($content['text'], $content['formatting']);
            // add HTML header and footers to the files
            // use default style if <style> is not in imported html head
            $head = '';
            if ($content['use_customized_head']) {
                if (strpos(strtolower($content['head']), '<style') > 0) {
                    $head = $content['head'];
                } else {
                    if (strlen($content['head']) > 0) {
                        $head = $content['head'] . $default_html_style;
                    } else {
                        $head = $default_html_style;
                    }
                }
            }
            $content['text'] = str_replace(array('{TITLE}', '{CONTENT}', '{KEYWORDS}', '{COURSE_PRIMARY_LANGUAGE_CHARSET}', '{COURSE_PRIMARY_LANGUAGE_CODE}', '{HEAD}'), array($content['title'], $content['text'], $content['keywords'], $course_language_charset, $course_language_code, $head), $html_content_template);
            /* duplicate the paths in the content_path field in the zip file */
            if ($content['content_path']) {
                if (!in_array($content['content_path'], $paths)) {
                    $zipfile->create_dir('resources/' . $content['content_path'], time());
                    $paths[] = $content['content_path'];
                }
            }
            //add the file iff it's a content file
            if ($content['content_type'] == CONTENT_TYPE_CONTENT) {
                $zipfile->add_file($content['text'], 'resources/' . $content['content_path'] . $content['content_id'] . '.html', $content['u_ts']);
            }
            $content['title'] = htmlspecialchars($content['title']);
            /* add the resource dependancies */
            if ($my_files == null) {
                $my_files = array();
            }
            $content_files = "\n";
            $parser->parse($content['text']);
            /* generate the IMS QTI resource and files */
            //check if test export is allowed.
            $content_test_rs = $contentManager->getContentTestsAssoc($content['content_id']);
            $test_ids = array();
            //reset test ids
            //$my_files = array();		//reset myfiles.
            if (is_array($content_test_rs)) {
                foreach ($content_test_rs as $content_test_row) {
                    //export
                    $test_ids[] = $content_test_row['test_id'];
                    //the 'added_files' is for adding into the manifest file in this zip
                    $added_files = test_qti_export($content_test_row['test_id'], '', $zipfile);
                    foreach ($added_files as $xml_file => $chunk) {
                        foreach ($chunk as $xml_filename) {
                            $added_files_xml .= str_replace('{FILE}', 'resources/' . $xml_filename, $ims_template_xml['xml']);
                        }
                    }
                    //Save all the xml files in this array, and then print_organizations will add it to the manifest file.
                    $resources .= str_replace(array('{TEST_ID}', '{PATH}', '{FILES}'), array($content_test_row['test_id'], 'tests_' . $content_test_row['test_id'] . '.xml', $added_files_xml), $ims_template_xml['resource_test']);
                    /*	Taken out since we are gonna use dependency instead
                    					$test_xml_items .= str_replace(	array('{TEST_ID}'),
                    												array($content_test_row['test_id']),
                    												$ims_template_xml['test']); 
                    */
                    foreach ($test_files as $filename => $realfilepath) {
                        $zipfile->add_file(@file_get_contents($realfilepath), 'resources/' . $filename, filemtime($realfilepath));
                    }
                }
            }
            /* generate the a4a files */
            $a4a_xml_array = array();
            //http://atutor.ca/atutor/mantis/view.php?id=4593
            if ($content['formatting'] === 0) {
                $use_a4a = false;
            }
            if ($use_a4a == true) {
                $a4aExport = new A4aExport($content['content_id']);
                //				$a4aExport->setRelativePath('resources/'.$content['content_path']);
                $secondary_files = $a4aExport->getAllSecondaryFiles();
                $a4a_xml_array = $a4aExport->exportA4a();
                $my_files = array_merge($my_files, $a4aExport->getAllSecondaryFiles());
            }
            /* handle @import */
            $import_files = get_import_files($content['text']);
            if (count($import_files) > 0) {
                $my_files = array_merge($my_files, $import_files);
            }
            foreach ($my_files as $file) {
                /* filter out full urls */
                $url_parts = @parse_url($file);
                //				if (isset($url_parts['scheme'])) {
                //					continue;
                //				}
                /* file should be relative to content. let's double check */
                if (substr($file, 0, 1) == '/') {
                    continue;
                }
                if (substr($file, 0, 7) != 'http://' && substr($file, 0, 8) != 'https://') {
                    $file_path = realpath(TR_CONTENT_DIR . $course_id . '/' . $content['content_path'] . $file);
                    /* check if the path contains TR_CONTENT_DIR in it, if not, skip it, it's trying to scan through 
                     * the file system */
                    if (strpos($file_path, TR_CONTENT_DIR) !== 0) {
                        continue;
                        //skip
                    }
                    /* check if this file exists in the content dir, if not don't include it */
                    if (file_exists($file_path) && is_file($file_path) && !in_array($file_path, $zipped_files)) {
                        $zipped_files[] = $file_path;
                        $dir = substr(dirname($file_path), strlen(TR_CONTENT_DIR . $course_id));
                        if (!in_array($dir, $paths) && $dir) {
                            $dir = str_replace('\\', '/', substr($dir, 1));
                            $zipfile->create_dir('resources/' . $dir, time());
                            $paths[] = $dir;
                        }
                        $file_info = stat($file_path);
                        //remove relative path in the content_path.
                        $filepath_array = explode('/', 'resources/' . $content['content_path'] . $file);
                        $new_filepath_array = array();
                        if (in_array('..', $filepath_array)) {
                            while (!empty($filepath_array)) {
                                $temp = array_shift($filepath_array);
                                if ($temp == '..') {
                                    array_pop($new_filepath_array);
                                } else {
                                    array_push($new_filepath_array, $temp);
                                }
                            }
                            $zip_path = implode('/', $new_filepath_array);
                        } else {
                            $zip_path = 'resources/' . $content['content_path'] . $file;
                        }
                        $zipfile->add_file(@file_get_contents($file_path), $zip_path, $file_info['mtime']);
                    }
                }
                //a4a secondary files have mapping, save the ones that we want in order to add the tag in
                $a4a_secondary_files = array();
                foreach ($a4a_xml_array as $a4a_filename => $a4a_filearray) {
                    if (preg_match('/(.*)\\sto\\s(.*)/', $a4a_filename, $matches)) {
                        //save the actual file name
                        $a4a_secondary_files[$matches[1]][] = $a4a_filename;
                        //values are holders
                    }
                }
                /**
                 * A hack to fix youtube links.  one uses youtube.com?watch=xxx, the other uses youtube.com/v/xxx,
                 * in which both points to the same file, but needed different links to play.
                 * in A4a, these youtube links are always stored as "?watch=xxx", however, output.inc.php converted
                 * these to /v/xxx for rendering purposes.  Convert it back if youtube exists in url.
                 * http://atutor.ca/atutor/mantis/view.php?id=4548
                 * @harris 9/30/2010
                 */
                if (strpos($file, 'youtube.com') !== false) {
                    //apply the conversion before linking the alternatives. Otherwise it will not be added.
                    $file = ContentUtility::convertYoutubePlayURLToWatchURL($file);
                }
                // If this file has a4a alternatives, link it.
                if (isset($a4a_xml_array[$file]) || isset($a4a_secondary_files[$file])) {
                    //if this is an array, meaning that it has more than 1 alternatives, print all
                    if (substr($file, 0, 7) == 'http://' || substr($file, 0, 8) == 'https://') {
                        $name_in_file_meta = $file;
                    } else {
                        $name_in_file_meta = 'resources/' . $content['content_path'] . $file;
                    }
                    if (is_array($a4a_secondary_files[$file])) {
                        $all_secondary_files_md = '';
                        //reinitialize string to null
                        foreach ($a4a_secondary_files[$file] as $v) {
                            foreach ($a4a_xml_array[$v] as $v2) {
                                $all_secondary_files_md .= $v2;
                                //all the meta data
                            }
                        }
                        $content_files .= str_replace(array('{FILE}', '{FILE_META_DATA}'), array($name_in_file_meta, $all_secondary_files_md), $ims_template_xml['file_meta']);
                    } else {
                        $content_files .= str_replace(array('{FILE}', '{FILE_META_DATA}'), array($name_in_file_meta, $a4a_xml_array[$file]), $ims_template_xml['file_meta']);
                    }
                } else {
                    //if this file is in the test array, add an extra link to the direct file,
                    if (!empty($test_zipped_files) && in_array($file_path, $test_zipped_files)) {
                        $content_files .= str_replace('{FILE}', $file, $ims_template_xml['file']);
                    } else {
                        if (preg_match('/^http[s]?\\:/', $file) == 1) {
                            $content_files .= str_replace('{FILE}', $file, $ims_template_xml['xml']);
                        } elseif (file_exists($file_path) && is_file($file_path)) {
                            //relative link that goes beyond get.php shouldn't be added
                            //relative link that does not exist shouldn't be added.
                            $filepath_array = explode('/', $content['content_path'] . $file);
                            $new_filepath_array = array();
                            if (in_array('..', $filepath_array)) {
                                while (!empty($filepath_array)) {
                                    $temp = array_shift($filepath_array);
                                    if ($temp == '..') {
                                        array_pop($new_filepath_array);
                                    } else {
                                        array_push($new_filepath_array, $temp);
                                    }
                                }
                                $file = implode('/', $new_filepath_array);
                            } else {
                                $file = $content['content_path'] . $file;
                            }
                            $content_files .= str_replace('{FILE}', $file, $ims_template_xml['file']);
                        }
                    }
                }
                /* check if this file is one of the test xml file, if so, we need to add the dependency
                 * Note:  The file has already been added to the archieve before this is called.
                 */
                if (preg_match('/tests\\_[0-9]+\\.xml$/', $file) && !in_array($file, $test_zipped_files)) {
                    $content_files .= str_replace('{FILE}', 'QTI/' . $file, $ims_template_xml['xml']);
                    $test_zipped_files[] = $file;
                }
            }
            /******************************
             * http://www.atutor.ca/atutor/mantis/view.php?id=4383 
             */
            $my_files = array();
            /******************************/
            //add it to the resources section if it hasn't been added.
            //Weblinks have been added.
            //Folders aren't resourecs, they shouldn't be added
            if ($content['content_type'] == CONTENT_TYPE_CONTENT) {
                $resources .= str_replace(array('{CONTENT_ID}', '{PATH}', '{FILES}', '{DEPENDENCY}'), array($content['content_id'], $content['content_path'], $content_files, $forums_dependency), $ims_template_xml['resource']);
            }
            for ($i = 0; $i < $depth; $i++) {
                $link .= $space;
            }
            if (is_array($_menu[$content['content_id']])) {
                /* has children */
                $html_link = '<li>' . $html_link . '<ul>';
                for ($i = 0; $i < $depth; $i++) {
                    if ($children[$i] == 1) {
                        echo $space;
                        //$html_link = $space.$html_link;
                    } else {
                        echo $space;
                        //$html_link = $space.$html_link;
                    }
                }
            } else {
                /* doesn't have children */
                $html_link = '<li>' . $html_link . '</li>';
                if ($counter == $num_items) {
                    for ($i = 0; $i < $depth; $i++) {
                        if ($children[$i] == 1) {
                            echo $space;
                            //$html_link = $space.$html_link;
                        } else {
                            echo $space;
                            //$html_link = $space.$html_link;
                        }
                    }
                } else {
                    for ($i = 0; $i < $depth; $i++) {
                        echo $space;
                        //$html_link = $space.$html_link;
                    }
                }
                $title = $space . $title;
            }
            echo $prefix . $link;
            //			echo $title;
            echo "\n";
            $string .= $html_link . "\n";
            $depth++;
            print_organizations($content['content_id'], $_menu, $depth, $path . $counter . '.', $children, $string);
            $depth--;
            $counter++;
            for ($i = 0; $i < $depth; $i++) {
                echo $space;
            }
            //			if (!empty($_menu[$content['content_id']])){
            echo $prefix . '</item>';
            //			}
            echo "\n";
        }
        $string .= '</ul>';
        if ($depth > 0) {
            $string .= '</li>';
        }
    }
}
function save_changes($redir, $current_tab)
{
    global $contentManager, $addslashes, $msg, $_course_id, $_content_id, $stripslashes;
    $_POST['pid'] = intval($_POST['pid']);
    $_POST['_cid'] = intval($_POST['_cid']);
    $_POST['alternatives'] = intval($_POST['alternatives']);
    $_POST['title'] = trim($_POST['title']);
    $_POST['head'] = trim($_POST['head']);
    $_POST['use_customized_head'] = isset($_POST['use_customized_head']) ? $_POST['use_customized_head'] : 0;
    $_POST['body_text'] = $stripslashes(trim($_POST['body_text']));
    $_POST['weblink_text'] = trim($_POST['weblink_text']);
    $_POST['formatting'] = intval($_POST['formatting']);
    $_POST['keywords'] = $stripslashes(trim($_POST['keywords']));
    $_POST['test_message'] = trim($_POST['test_message']);
    //if weblink is selected, use it
    if ($_POST['formatting'] == CONTENT_TYPE_WEBLINK) {
        $url = $_POST['weblink_text'];
        $validated_url = isValidURL($url);
        if (!validated_url || $validated_url !== $url) {
            $msg->addError(array('INVALID_INPUT', _AT('weblink')));
        } else {
            $_POST['body_text'] = $url;
            $content_type_pref = CONTENT_TYPE_WEBLINK;
        }
    } else {
        $content_type_pref = CONTENT_TYPE_CONTENT;
    }
    /*if (!($release_date = generate_release_date())) {
    		$msg->addError('BAD_DATE');
    	}*/
    //	if ($_POST['title'] == '') {
    //		$msg->addError(array('EMPTY_FIELDS', _AT('title')));
    //	}
    //	if (!$msg->containsErrors()) {
    $orig_body_text = $_POST['body_text'];
    // used to populate a4a tables
    //		$_POST['title']			= $addslashes($_POST['title']);
    //		$_POST['body_text']		= $addslashes($_POST['body_text']);
    //		$_POST['head']  		= $addslashes($_POST['head']);
    //		$_POST['keywords']		= $addslashes($_POST['keywords']);
    //		$_POST['test_message']	= $addslashes($_POST['test_message']);
    // add or edit content
    if ($_POST['_cid']) {
        /* editing an existing page */
        $err = $contentManager->editContent($_POST['_cid'], $_POST['title'], $_POST['body_text'], $_POST['keywords'], $_POST['formatting'], $_POST['head'], $_POST['use_customized_head'], $_POST['test_message']);
        $cid = $_POST['_cid'];
    } else {
        /* insert new */
        $cid = $contentManager->addContent($_course_id, $_POST['pid'], $_POST['ordering'], $_POST['title'], $_POST['body_text'], $_POST['keywords'], $_POST['related'], $_POST['formatting'], $_POST['head'], $_POST['use_customized_head'], $_POST['test_message'], $content_type_pref);
        $_POST['_cid'] = $cid;
        $_REQUEST['_cid'] = $cid;
    }
    // re-populate a4a tables based on the new content
    populate_a4a($cid, $orig_body_text, $_POST['formatting']);
    if ($cid == 0) {
        return;
    }
    //	}
    /* insert glossary terms */
    /*
    	if (is_array($_POST['glossary_defs']) && ($num_terms = count($_POST['glossary_defs']))) {
    		global $glossary, $glossary_ids, $msg;
    
    		foreach($_POST['glossary_defs'] as $w => $d) {
    			$old_w = $w;
    			$key = in_array_cin($w, $glossary_ids);
    			$w = urldecode($w);
    			$d = $addslashes($d);
    
    			if (($key !== false) && (($glossary[$old_w] != $d) || isset($_POST['related_term'][$old_w])) ) {
    				$w = addslashes($w);
    				$related_id = intval($_POST['related_term'][$old_w]);
    				$sql = "UPDATE ".TABLE_PREFIX."glossary SET definition='$d', related_word_id=$related_id WHERE word_id=$key AND course_id=$_SESSION[course_id]";
    				$result = mysql_query($sql, $db);
    				$glossary[$old_w] = $d;
    			} else if ($key === false && ($d != '')) {
    				$w = addslashes($w);
    				$related_id = intval($_POST['related_term'][$old_w]);
    				$sql = "INSERT INTO ".TABLE_PREFIX."glossary VALUES (NULL, $_SESSION[course_id], '$w', '$d', $related_id)";
    
    				$result = mysql_query($sql, $db);
    				$glossary[$old_w] = $d;
    			}
    		}
    	}*/
    if (isset($_GET['tab'])) {
        $current_tab = intval($_GET['tab']);
    }
    if (isset($_POST['current_tab'])) {
        $current_tab = intval($_POST['current_tab']);
    }
    // adapted content: save primary content type
    if (isset($_POST['use_post_for_alt'])) {
        include_once TR_INCLUDE_PATH . 'classes/DAO/PrimaryResourcesTypesDAO.class.php';
        $primaryResourcesTypesDAO = new PrimaryResourcesTypesDAO();
        // 1. delete old primary content type
        $sql = "DELETE FROM " . TABLE_PREFIX . "primary_resources_types\n\t\t         WHERE primary_resource_id in \n\t\t               (SELECT DISTINCT primary_resource_id \n\t\t                  FROM " . TABLE_PREFIX . "primary_resources\n\t\t                 WHERE content_id=" . $cid . "\n\t\t                   AND language_code='" . $_SESSION['lang'] . "')";
        $primaryResourcesTypesDAO->execute($sql);
        // 2. insert the new primary content type
        $sql = "SELECT pr.primary_resource_id, rt.type_id\n\t\t          FROM " . TABLE_PREFIX . "primary_resources pr, " . TABLE_PREFIX . "resource_types rt\n\t\t         WHERE pr.content_id = " . $cid . "\n\t\t           AND pr.language_code = '" . $_SESSION['lang'] . "'";
        $all_types_rows = $primaryResourcesTypesDAO->execute($sql);
        if (is_array($all_types_rows)) {
            foreach ($all_types_rows as $type) {
                if (isset($_POST['alt_' . $type['primary_resource_id'] . '_' . $type['type_id']])) {
                    $primaryResourcesTypesDAO->Create($type['primary_resource_id'], $type['type_id']);
                    //					$sql = "INSERT INTO ".TABLE_PREFIX."primary_resources_types (primary_resource_id, type_id)
                    //					        VALUES (".$type['primary_resource_id'].", ".$type['type_id'].")";
                    //					$result = mysql_query($sql, $db);
                }
            }
        }
    }
    include_once TR_INCLUDE_PATH . 'classes/DAO/ContentTestsAssocDAO.class.php';
    $contentTestsAssocDAO = new ContentTestsAssocDAO();
    $test_rows = $contentTestsAssocDAO->getByContent($_POST['_cid']);
    //	$sql = 'SELECT * FROM '.TABLE_PREFIX."content_tests_assoc WHERE content_id=$_POST[cid]";
    //	$result = mysql_query($sql, $db);
    $db_test_array = array();
    if (is_array($test_rows)) {
        foreach ($test_rows as $row) {
            $db_test_array[] = $row['test_id'];
        }
    }
    if (is_array($_POST['tid']) && sizeof($_POST['tid']) > 0) {
        $toBeDeleted = array_diff($db_test_array, $_POST['tid']);
        $toBeAdded = array_diff($_POST['tid'], $db_test_array);
        //Delete entries
        if (!empty($toBeDeleted)) {
            $tids = implode(",", $toBeDeleted);
            $sql = 'DELETE FROM ' . TABLE_PREFIX . "content_tests_assoc WHERE content_id={$_POST['cid']} AND test_id IN ({$tids})";
            $contentTestsAssocDAO->execute($sql);
        }
        //Add entries
        if (!empty($toBeAdded)) {
            foreach ($toBeAdded as $i => $tid) {
                $tid = intval($tid);
                //				$sql = 'INSERT INTO '. TABLE_PREFIX . "content_tests_assoc SET content_id=$_POST[cid], test_id=$tid";
                //				$result = mysql_query($sql, $db);
                if ($contentTestsAssocDAO->Create($_POST['_cid'], $tid) === false) {
                    $msg->addError('DB_NOT_UPDATED');
                }
            }
        }
    } else {
        //All tests has been removed.
        $contentTestsAssocDAO->DeleteByContentID($_POST['_cid']);
        //		$sql = 'DELETE FROM '. TABLE_PREFIX . "content_tests_assoc WHERE content_id=$_POST[cid]";
        //		$result = mysql_query($sql, $db);
    }
    //End Add test
    //TODO*******************BOLOGNA****************REMOVE ME**************/
    /*
    	if(isset($_SESSION['associated_forum']) && !$msg->containsErrors()){
    		if($_SESSION['associated_forum']=='none'){
    			$sql = "DELETE FROM ".TABLE_PREFIX."content_forums_assoc WHERE content_id='$_POST[cid]'";
    			mysql_query($sql,$db);
    		} else {
    			$sql = "DELETE FROM ".TABLE_PREFIX."content_forums_assoc WHERE content_id='$_POST[cid]'";
    			mysql_query($sql,$db);
    			$associated_forum = $_SESSION['associated_forum'];
    			for($i=0; $i<count($associated_forum); $i++){
    				$sql="INSERT INTO ".TABLE_PREFIX."content_forums_assoc SET content_id='$_POST[cid]',forum_id='$associated_forum[$i]'";
    				mysql_query($sql,$db);
    			}
    		}
    		unset($_SESSION['associated_forum']);
    	}
    */
    if (!$msg->containsErrors() && $redir) {
        $_SESSION['save_n_close'] = $_POST['save_n_close'];
        $msg->addFeedback('ACTION_COMPLETED_SUCCESSFULLY');
        header('Location: ' . basename($_SERVER['PHP_SELF']) . '?_cid=' . $cid . SEP . 'close=' . $addslashes($_POST['save_n_close']) . SEP . 'tab=' . $addslashes($_POST['current_tab']) . SEP . 'displayhead=' . $addslashes($_POST['displayhead']) . SEP . 'alternatives=' . $addslashes($_POST['alternatives']));
        exit;
    } else {
        return;
    }
}
Esempio n. 5
0
function print_organizations($parent_id, &$_menu, $depth, $path = '', $children, &$string)
{
    global $html_content_template, $default_html_style, $zipfile, $resources, $ims_template_xml, $parser, $my_files;
    global $used_glossary_terms, $course_id, $course_language_charset, $course_language_code;
    static $paths, $zipped_files;
    global $glossary;
    global $test_zipped_files, $use_a4a, $db;
    require_once TR_INCLUDE_PATH . '../home/classes/ContentUtility.class.php';
    $space = '    ';
    $prefix = '                    ';
    if ($depth == 0) {
        $string .= '<ul>';
    }
    $top_level = $_menu[$parent_id];
    if (!is_array($paths)) {
        $paths = array();
    }
    if (!is_array($zipped_files)) {
        $zipped_files = array();
    }
    if (is_array($top_level)) {
        $counter = 1;
        $num_items = count($top_level);
        foreach ($top_level as $garbage => $content) {
            $link = '';
            if ($content['content_path']) {
                $content['content_path'] .= '/';
            }
            //if this is a folder, export it without identifierref
            if ($content['content_type'] == CONTENT_TYPE_FOLDER) {
                $link = $prevfix . '<item identifier="MANIFEST01_ITEM' . $content['content_id'] . '">' . "\n";
            } else {
                $link = $prevfix . '<item identifier="MANIFEST01_ITEM' . $content['content_id'] . '" identifierref="MANIFEST01_RESOURCE' . $content['content_id'] . '" parameters="' . htmlentities($content['test_message'], ENT_QUOTES, 'UTF-8') . '">' . "\n";
            }
            $html_link = '<a href="resources/' . $content['content_path'] . $content['content_id'] . '.html" target="body">' . $content['title'] . '</a>';
            /* save the content as HTML files */
            $content['text'] = str_replace('CONTENT_DIR/', '', $content['text']);
            /* Commented by Cindy Qi Li on Jan 12, 2010
            			 * AContent does not support glossary
            			// get all the glossary terms used
            			$terms = find_terms($content['text']);
            			if (is_array($terms)) {
            				foreach ($terms[2] as $term) {
            					$used_glossary_terms[] = $term;
            				}
            			}
            */
            /** Test dependency **/
            //			$test_dependency = '';	//Template for test
            //			$sql = 'SELECT * FROM '.TABLE_PREFIX.'content_tests_assoc WHERE content_id='.$content['content_id'];
            //			$result = mysql_query($sql, $db);
            //			while ($row = mysql_fetch_assoc($result)){
            require_once TR_INCLUDE_PATH . 'classes/DAO/ContentTestsAssocDAO.class.php';
            $contentTestsAssocDAO = new ContentTestsAssocDAO();
            $rows = $contentTestsAssocDAO->getByContent($content['content_id']);
            if (is_array($rows)) {
                //add test dependency on top of forum dependency
                foreach ($rows as $row) {
                    $test_dependency .= $prefix . $space . '<dependency identifierref="MANIFEST01_RESOURCE_QTI' . $row['test_id'] . '" />';
                }
            }
            /* calculate how deep this page is: */
            $path = '../';
            if ($content['content_path']) {
                $depth = substr_count($content['content_path'], '/');
                $path .= str_repeat('../', $depth);
            }
            $content['text'] = ContentUtility::formatContent($content['text'], $content['formatting']);
            /* add HTML header and footers to the files */
            /* use default style if <style> is not in imported html head */
            $head = '';
            if ($content['use_customized_head']) {
                if (strpos(strtolower($content['head']), '<style') > 0) {
                    $head = $content['head'];
                } else {
                    if (strlen($content['head']) > 0) {
                        $head = $content['head'] . $default_html_style;
                    } else {
                        $head = $default_html_style;
                    }
                }
            }
            $content['text'] = str_replace(array('{TITLE}', '{CONTENT}', '{KEYWORDS}', '{COURSE_PRIMARY_LANGUAGE_CHARSET}', '{COURSE_PRIMARY_LANGUAGE_CODE}', '{HEAD}'), array($content['title'], $content['text'], $content['keywords'], $course_language_charset, $course_language_code, $head), $html_content_template);
            /* duplicate the paths in the content_path field in the zip file */
            if ($content['content_path']) {
                if (!in_array($content['content_path'], $paths)) {
                    $zipfile->create_dir('resources/' . $content['content_path'], time());
                    $paths[] = $content['content_path'];
                }
            }
            $zipfile->add_file($content['text'], 'resources/' . $content['content_path'] . $content['content_id'] . '.html', $content['u_ts']);
            $content['title'] = htmlspecialchars($content['title']);
            /* add the resource dependancies */
            if ($my_files == null) {
                $my_files = array();
            }
            $content_files = "\n";
            $parser->parse($content['text']);
            /* generate the IMS QTI resource and files */
            global $contentManager;
            //check if test export is allowed.
            $content_test_rs = $contentManager->getContentTestsAssoc($content['content_id']);
            $test_ids = array();
            //reset test ids
            //$my_files = array();		//reset myfiles.
            if (is_array($content_test_rs)) {
                foreach ($content_test_rs as $content_test_row) {
                    //export
                    $test_ids[] = $content_test_row['test_id'];
                    //the 'added_files' is for adding into the manifest file in this zip
                    $added_files = test_qti_export($content_test_row['test_id'], '', $zipfile);
                    //Save all the xml files in this array, and then print_organizations will add it to the manifest file.
                    foreach ($added_files as $filename => $file_array) {
                        $my_files[] = $filename;
                        foreach ($file_array as $garbage => $filename2) {
                            if (!in_array($filename2, $my_files)) {
                                $my_files[] = $filename2;
                            }
                        }
                    }
                    //Save all the xml files in this array, and then print_organizations will add it to the manifest file.
                    $resources .= str_replace(array('{TEST_ID}', '{PATH}', '{FILES}'), array($content_test_row['test_id'], 'tests_' . $content_test_row['test_id'] . '.xml', $added_files_xml), $ims_template_xml['resource_test']);
                }
            }
            /* generate the a4a files */
            $a4a_xml_array = array();
            //http://atutor.ca/atutor/mantis/view.php?id=4593
            if ($content['formatting'] === 0) {
                $use_a4a = false;
            }
            if ($use_a4a == true) {
                $a4aExport = new A4aExport($content['content_id']);
                //				$a4aExport->setRelativePath('resources/'.$content['content_path']);
                $secondary_files = $a4aExport->getAllSecondaryFiles();
                $a4a_xml_array = $a4aExport->exportA4a();
                $my_files = array_merge($my_files, $a4aExport->getAllSecondaryFiles());
            }
            /* handle @import */
            $import_files = get_import_files($content['text']);
            if (count($import_files) > 0) {
                $my_files = array_merge($my_files, $import_files);
            }
            foreach ($my_files as $file) {
                /* filter out full urls */
                $url_parts = @parse_url($file);
                if (isset($url_parts['scheme'])) {
                    continue;
                }
                /* file should be relative to content. let's double check */
                if (substr($file, 0, 1) == '/') {
                    continue;
                }
                $file_path = realpath(TR_CONTENT_DIR . $course_id . '/' . $content['content_path'] . $file);
                /* check if this file exists in the content dir, if not don't include it */
                if (file_exists($file_path) && is_file($file_path) && !in_array($file_path, $zipped_files)) {
                    $zipped_files[] = $file_path;
                    $dir = substr(dirname($file_path), strlen(TR_CONTENT_DIR . $course_id));
                    if (!in_array($dir, $paths) && $dir) {
                        $dir = str_replace('\\', '/', substr($dir, 1));
                        $zipfile->create_dir('resources/' . $dir, time());
                        $paths[] = $dir;
                    }
                    $file_info = stat($file_path);
                    //Fixes relative paths, so folder1/folder2/../file.jpg will become just folder1/file.jpg
                    $file_save_path = str_replace(TR_CONTENT_DIR . $course_id . DIRECTORY_SEPARATOR, '', $file_path);
                    $file_save_path = str_replace('\\', '/', $file_save_path);
                    //condition checks if the file has been added, so then the test won't be added to all the subchildren
                    //leads to normal images not capable to be extracted.
                    if ((empty($test_zipped_files) || is_array($test_zipped_files) && !in_array($file_path, $test_zipped_files)) && file_exists($file_path)) {
                        $zipfile->add_file(@file_get_contents($file_path), 'resources/' . $file_save_path, $file_info['mtime']);
                        //						$test_zipped_files[] = $content['content_path'] . $file;
                        $test_zipped_files[] = $file_path;
                    } elseif (!is_array($test_zipped_files) && file_exists($file_path) && !in_array($file_path, $zipped_files)) {
                        $zipfile->add_file(@file_get_contents($file_path), 'resources/' . $file_save_path, $file_info['mtime']);
                    }
                    //a4a secondary files have mapping, save the ones that we want in order to add the tag in
                    $a4a_secondary_files = array();
                    foreach ($a4a_xml_array as $a4a_filename => $a4a_filearray) {
                        if (preg_match('/(.*)\\sto\\s(.*)/', $a4a_filename, $matches)) {
                            //save the actual file name
                            $a4a_secondary_files[$matches[1]][] = $a4a_filename;
                            //values are holders
                        }
                    }
                    // If this file has a4a alternatives, link it.
                    if (isset($a4a_xml_array[$file]) || isset($a4a_secondary_files[$file])) {
                        //if this is an array, meaning that it has more than 1 alternatives, print all
                        if (is_array($a4a_secondary_files[$file])) {
                            $all_secondary_files_md = '';
                            //reinitialize string to null
                            foreach ($a4a_secondary_files[$file] as $v) {
                                foreach ($a4a_xml_array[$v] as $v2) {
                                    $all_secondary_files_md .= $v2;
                                    //all the meta data
                                }
                            }
                            $content_files .= str_replace(array('{FILE}', '{FILE_META_DATA}'), array('resources/' . $file_save_path, $all_secondary_files_md), $ims_template_xml['file_meta']);
                        } else {
                            $content_files .= str_replace(array('{FILE}', '{FILE_META_DATA}'), array('resources/' . $file_save_path, $a4a_xml_array[$file]), $ims_template_xml['file_meta']);
                        }
                    } else {
                        //if this file is in the test array, add an extra link to the direct file,
                        if (!empty($test_zipped_files) && in_array($file_path, $test_zipped_files)) {
                            $content_files .= str_replace('{FILE}', $file_save_path, $ims_template_xml['file']);
                        } else {
                            $content_files .= str_replace('{FILE}', $file_save_path, $ims_template_xml['file']);
                        }
                    }
                }
                /* check if this file is one of the test xml file, if so, we need to add the dependency
                 * Note:  The file has already been added to the archieve before this is called.
                 */
                /* taken out as of nov 17th, used dependency instead
                				if (preg_match('/tests\_[0-9]+\.xml$/', $file) && !in_array($file, $test_zipped_files)){
                					$content_files .= str_replace('{FILE}', $file, $ims_template_xml['xml']);
                					$test_zipped_files[] = $file;
                				}
                */
            }
            /******************************/
            $resources .= str_replace(array('{CONTENT_ID}', '{PATH}', '{FILES}', '{DEPENDENCY}'), array($content['content_id'], $content['content_path'], $content_files, $test_dependency), $ims_template_xml['resource']);
            for ($i = 0; $i < $depth; $i++) {
                $link .= $space;
            }
            $title = $prefix . $space . '<title>' . $content['title'] . '</title>';
            if (is_array($_menu[$content['content_id']])) {
                /* has children */
                $html_link = '<li>' . $html_link . '<ul>';
                for ($i = 0; $i < $depth; $i++) {
                    if ($children[$i] == 1) {
                        echo $space;
                        //$html_link = $space.$html_link;
                    } else {
                        echo $space;
                        //$html_link = $space.$html_link;
                    }
                }
            } else {
                /* doesn't have children */
                $html_link = '<li>' . $html_link . '</li>';
                if ($counter == $num_items) {
                    for ($i = 0; $i < $depth; $i++) {
                        if ($children[$i] == 1) {
                            echo $space;
                            //$html_link = $space.$html_link;
                        } else {
                            echo $space;
                            //$html_link = $space.$html_link;
                        }
                    }
                } else {
                    for ($i = 0; $i < $depth; $i++) {
                        echo $space;
                        //$html_link = $space.$html_link;
                    }
                }
                $title = $space . $title;
            }
            echo $prefix . $link;
            echo $title;
            echo "\n";
            $string .= $html_link . "\n";
            $depth++;
            print_organizations($content['content_id'], $_menu, $depth, $path . $counter . '.', $children, $string);
            $depth--;
            $counter++;
            for ($i = 0; $i < $depth; $i++) {
                echo $space;
            }
            echo $prefix . '</item>';
            echo "\n";
        }
        $string .= '</ul>';
        if ($depth > 0) {
            $string .= '</li>';
        }
    }
}
Esempio n. 6
0
    } else {
        $msg->addError('IMPORT_FAILED');
        echo 'Error : ' . $archive->errorInfo(true);
    }
    FileUtility::clr_dir($import_path);
    header('Location: ' . $_SERVER['HTTP_REFERER']);
    if (file_exists($full_filename)) {
        @unlink($full_filename);
    }
    exit;
}
/* initialize DAO objects */
$coursesDAO = new CoursesDAO();
$contentDAO = new ContentDAO();
$testsQuestionsAssocDAO = new TestsQuestionsAssocDAO();
$contentTestsAssocDAO = new ContentTestsAssocDAO();
// get the course's max_quota
if (isset($_POST['_course_id'])) {
    check_available_size($_POST['_course_id']);
}
$items = array();
/* all the content pages */
$order = array();
/* keeps track of the ordering for each content page */
$path = array();
/* the hierarchy path taken in the menu to get to the current item in the manifest */
$dependency_files = array();
/* the file path for the dependency files */
/*
$items[content_id/resource_id] = array(
									'title'