Esempio n. 1
0
 function setPrimaryResourceType($primary_resource_id, $type_id)
 {
     include_once TR_INCLUDE_PATH . 'classes/DAO/PrimaryResourcesTypesDAO.class.php';
     $primaryResourcesTypesDAO = new PrimaryResourcesTypesDAO();
     $primaryResourcesTypesDAO->Create($primary_resource_id, $type_id);
 }
Esempio n. 2
0
                 $result = false;
                 break;
             }
         }
     }
     if ($result) {
         // delete according definition of primary resources and alternatives for adapted content
         $filename = '../' . $pathext . $filename;
         // 1. delete secondary resources types
         $secondaryResourcesTypesDAO = new SecondaryResourcesTypesDAO();
         $secondaryResourcesTypesDAO->DeleteByResourceName($filename);
         // 2. delete secondary resources
         $secondaryResourcesDAO = new SecondaryResourcesDAO();
         $secondaryResourcesDAO->DeleteByResourceName($filename);
         // 3. delete primary resources types
         $primaryResourcesTypesDAO = new PrimaryResourcesTypesDAO();
         $primaryResourcesTypesDAO->DeleteByResourceName($filename);
         // 4. delete primary resources
         $primaryResourcesDAO = new PrimaryResourcesDAO();
         $primaryResourcesDAO->DeleteByResourceName($filename);
         $msg->addFeedback('ACTION_COMPLETED_SUCCESSFULLY');
     }
 }
 /* delete directory */
 if (isset($_POST['listofdirs'])) {
     $checkbox = explode(',', $_POST['listofdirs']);
     $count = count($checkbox);
     $result = true;
     for ($i = 0; $i < $count; $i++) {
         $filename = $checkbox[$i];
         if (strpos($filename, '..') !== false) {
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;
    }
}