@ -1,5 +1,5 @@
<?php
<?php
// $Id: CourseSelectForm.class.php 19321 2009-03-25 20:15:33 Z juliomontoya $
// $Id: CourseSelectForm.class.php 19948 2009-04-21 17:27:59 Z juliomontoya $
/*
/*
==============================================================================
==============================================================================
Dokeos - elearning and course management software
Dokeos - elearning and course management software
@ -34,8 +34,9 @@ class CourseSelectForm
/**
/**
* Display the form
* Display the form
* @param array $hidden_fiels Hidden fields to add to the form.
* @param array $hidden_fiels Hidden fields to add to the form.
* @param boolean the document array will be serialize. This is used in the course_copy.php file
*/
*/
function display_form($course, $hidden_fields = null)
function display_form($course, $hidden_fields = null, $avoid_serialize=false )
{
{
$resource_titles[RESOURCE_EVENT] = get_lang('Events');
$resource_titles[RESOURCE_EVENT] = get_lang('Events');
$resource_titles[RESOURCE_ANNOUNCEMENT] = get_lang('Announcements');
$resource_titles[RESOURCE_ANNOUNCEMENT] = get_lang('Announcements');
@ -91,8 +92,7 @@ class CourseSelectForm
<?php
<?php
//get destination course title
//get destination course title
if(!empty($hidden_fields['destination_course']))
if(!empty($hidden_fields['destination_course'])) {
{
require_once(api_get_path(LIBRARY_PATH).'course.lib.php');
require_once(api_get_path(LIBRARY_PATH).'course.lib.php');
$course_infos = CourseManager::get_course_information($hidden_fields['destination_course']);
$course_infos = CourseManager::get_course_information($hidden_fields['destination_course']);
echo '< h3 > ';
echo '< h3 > ';
@ -106,17 +106,12 @@ class CourseSelectForm
echo '< script language = "javascript" src = "'.api_get_path(WEB_CODE_PATH).'inc/lib/javascript/upload.js" type = "text/javascript" > < / script > ';
echo '< script language = "javascript" src = "'.api_get_path(WEB_CODE_PATH).'inc/lib/javascript/upload.js" type = "text/javascript" > < / script > ';
echo '< script type = "text/javascript" > var myUpload = new upload ( 1000 ) ; < / script > ';
echo '< script type = "text/javascript" > var myUpload = new upload ( 1000 ) ; < / script > ';
echo '< form method = "post" id = "upload_form" name = "course_select_form" onsubmit = "myUpload.start(\'dynamic_div\',\''.api_get_path(WEB_CODE_PATH).'img/progress_bar.gif\',\''.get_lang('PleaseStandBy').'\',\'upload_form\')" > ';
echo '< form method = "post" id = "upload_form" name = "course_select_form" onsubmit = "myUpload.start(\'dynamic_div\',\''.api_get_path(WEB_CODE_PATH).'img/progress_bar.gif\',\''.get_lang('PleaseStandBy').'\',\'upload_form\')" > ';
echo '< input type = "hidden" name = "action" value = "course_select_form" / > ';
echo '< input type = "hidden" name = "action" value = "course_select_form" / > ';
foreach ($course->resources as $type => $resources)
foreach ($course->resources as $type => $resources) {
{
if (count($resources) > 0) {
if (count($resources) > 0)
switch ($type) {
{
switch ($type)
{
case RESOURCE_LINKCATEGORY :
case RESOURCE_LINKCATEGORY :
case RESOURCE_FORUMCATEGORY :
case RESOURCE_FORUMCATEGORY :
case RESOURCE_FORUMPOST :
case RESOURCE_FORUMPOST :
@ -127,14 +122,13 @@ class CourseSelectForm
case RESOURCE_SCORM:
case RESOURCE_SCORM:
break;
break;
default :
default :
echo ' < img id = "img_'.$type.'" src = "../img/1.gif" onclick = "javascript:exp('." ' $ type ' " . ' ) ; " / > ';
echo '< img id = "img_'.$type.'" src = "../img/1.gif" onclick = "javascript:exp('." ' $ type ' " . ' ) ; " / > ';
echo ' < b onclick = "javascript:exp('." ' $ type ' " . ' ) ; " > '.$resource_titles[$type].'< / b > < br / > ';
echo '< b onclick = "javascript:exp('." ' $ type ' " . ' ) ; " > '.$resource_titles[$type].'< / b > < br / > ';
echo '< div id = "div_'.$type.'" > ';
echo '< div id = "div_'.$type.'" > ';
echo '< blockquote > ';
echo '< blockquote > ';
echo "[< a href = \"#\" onclick = \"javascript:setCheckbox('$type',true);\" > ".get_lang('All')."< / a > - < a href = \"#\" onclick = \"javascript:setCheckbox('$type',false);\" > ".get_lang('None')."< / a > ]";
echo "[< a href = \"#\" onclick = \"javascript:setCheckbox('$type',true);\" > ".get_lang('All')."< / a > - < a href = \"#\" onclick = \"javascript:setCheckbox('$type',false);\" > ".get_lang('None')."< / a > ]";
echo '< br / > ';
echo '< br / > ';
foreach ($resources as $id => $resource)
foreach ($resources as $id => $resource) {
{
echo '< input type = "checkbox" name = "resource['.$type.']['.$id.']" id = "resource['.$type.']['.$id.']" / > ';
echo '< input type = "checkbox" name = "resource['.$type.']['.$id.']" id = "resource['.$type.']['.$id.']" / > ';
echo ' < label for = "resource['.$type.']['.$id.']" > ';
echo ' < label for = "resource['.$type.']['.$id.']" > ';
$resource->show();
$resource->show();
@ -149,14 +143,16 @@ class CourseSelectForm
}
}
}
}
//Documents are avoided due the huge moun of memory that serialize function eats (when there are directories with hundred of files)
if ($avoid_serialize) {
//Documents are avoided due the huge amount of memory that the serialize php function "eats" (when there are directories with hundred/thousand of files)
// this is a known issue of serialize
$course->resources['document']= null;
$course->resources['document']= null;
}
echo '< input type = "hidden" name = "course" value = "'.base64_encode(serialize($course)).'" / > ';
echo '< input type = "hidden" name = "course" value = "'.base64_encode(serialize($course)).'" / > ';
if (is_array($hidden_fields))
if (is_array($hidden_fields)) {
{
foreach ($hidden_fields as $key => $value) {
foreach ($hidden_fields as $key => $value)
{
echo "\n";
echo "\n";
echo '< input type = "hidden" name = "'.$key.'" value = "'.$value.'" / > ';
echo '< input type = "hidden" name = "'.$key.'" value = "'.$value.'" / > ';
}
}
@ -172,16 +168,11 @@ class CourseSelectForm
function display_hidden_quiz_questions($course)
function display_hidden_quiz_questions($course)
{
{
foreach ($course->resources as $type => $resources) {
foreach ($course->resources as $type => $resources)
if (count($resources) > 0) {
{
switch ($type) {
if (count($resources) > 0)
{
switch ($type)
{
case RESOURCE_QUIZQUESTION:
case RESOURCE_QUIZQUESTION:
foreach ($resources as $id => $resource)
foreach ($resources as $id => $resource) {
{
echo '< input type = "hidden" name = "resource['.RESOURCE_QUIZQUESTION.']['.$id.'] id=" resource [ ' . RESOURCE_QUIZQUESTION . ' ] [ ' . $ id . ' ] " value = "On" / > ';
echo '< input type = "hidden" name = "resource['.RESOURCE_QUIZQUESTION.']['.$id.'] id=" resource [ ' . RESOURCE_QUIZQUESTION . ' ] [ ' . $ id . ' ] " value = "On" / > ';
}
}
break;
break;
@ -190,17 +181,14 @@ class CourseSelectForm
}
}
}
}
}
}
function display_hidden_scorm_directories($course)
function display_hidden_scorm_directories($course)
{
{
foreach ($course->resources as $type => $resources)
foreach ($course->resources as $type => $resources) {
{
if(count($resources) > 0) {
if(count($resources) > 0)
switch($type) {
{
switch($type)
{
case RESOURCE_SCORM:
case RESOURCE_SCORM:
foreach ($resources as $id=>$resource)
foreach ($resources as $id=>$resource) {
{
echo '< input type = "hidden" name = "resource['.RESOURCE_SCORM.']['.$id.'] id=" resource [ ' . RESOURCE_SCORM . ' ] [ ' . $ id . ' ] " value = "On" / > ';
echo '< input type = "hidden" name = "resource['.RESOURCE_SCORM.']['.$id.'] id=" resource [ ' . RESOURCE_SCORM . ' ] [ ' . $ id . ' ] " value = "On" / > ';
}
}
break;
break;
@ -209,21 +197,24 @@ class CourseSelectForm
}
}
}
}
/**
/**
* Get the posted course
* Get the posted course
* @param string who calls the function? It can be copy_course, create_backup, import_backup or recycle_course
* @return course The course-object with all resources selected by the user
* @return course The course-object with all resources selected by the user
* in the form given by display_form(...)
* in the form given by display_form(...)
*/
*/
function get_posted_course()
function get_posted_course($from='' )
{
{
$course = unserialize(base64_decode($_POST['course']));
$course = unserialize(base64_decode($_POST['course']));
//Create the resource DOCUMENT objects
//Create the resource DOCUMENT objects
//Loading the results from the checkboxes of the javascript
//Loading the results from the checkboxes of the javascript
$resource = $_POST['resource'][RESOURCE_DOCUMENT];
$resource = $_POST['resource'][RESOURCE_DOCUMENT];
$table_doc = Database :: get_course_table(TABLE_DOCUMENT);
$table_doc = Database :: get_course_table(TABLE_DOCUMENT);
$table_prop = Database :: get_course_table(TABLE_ITEM_PROPERTY);
$table_prop = Database :: get_course_table(TABLE_ITEM_PROPERTY);
// Searching the documents resource that have been set to null because $avoid_serialize is true in the display_form() function
if ($from=='copy_course') {
if (is_array($resource)) {
$resource = array_keys($resource);
$resource = array_keys($resource);
foreach ($resource as $resource_item) {
foreach ($resource as $resource_item) {
$sql = 'SELECT * FROM '.$table_doc.' d, '.$table_prop.' p WHERE tool = \''.TOOL_DOCUMENT.'\' AND p.ref = d.id AND p.visibility != 2 AND id = '.$resource_item.' ORDER BY path';
$sql = 'SELECT * FROM '.$table_doc.' d, '.$table_prop.' p WHERE tool = \''.TOOL_DOCUMENT.'\' AND p.ref = d.id AND p.visibility != 2 AND id = '.$resource_item.' ORDER BY path';
@ -231,7 +222,6 @@ class CourseSelectForm
while ($obj = Database::fetch_object($db_result)) {
while ($obj = Database::fetch_object($db_result)) {
$doc = new Document($obj->id, $obj->path, $obj->comment, $obj->title, $obj->filetype, $obj->size);
$doc = new Document($obj->id, $obj->path, $obj->comment, $obj->title, $obj->filetype, $obj->size);
$course->add_resource($doc);
$course->add_resource($doc);
// adding item property
// adding item property
$sql = "SELECT * FROM $table_prop WHERE TOOL = '".RESOURCE_DOCUMENT."' AND ref='".$resource_item."'";
$sql = "SELECT * FROM $table_prop WHERE TOOL = '".RESOURCE_DOCUMENT."' AND ref='".$resource_item."'";
$res = api_sql_query($sql,__FILE__,__LINE__);
$res = api_sql_query($sql,__FILE__,__LINE__);
@ -242,17 +232,32 @@ class CourseSelectForm
$course->resources[RESOURCE_DOCUMENT][$resource_item]->item_properties = $all_properties;
$course->resources[RESOURCE_DOCUMENT][$resource_item]->item_properties = $all_properties;
}
}
}
}
}
}
/*else {
$documents = $_POST['resource'][RESOURCE_DOCUMENT];
//print_r($course->resources );
foreach ($resource as $resource_item) {
echo $resource_item;
foreach($documents as $obj) {
print_r($obj);
foreach ($course->resources as $type => $resources)
if ($obj->id==$resource_item) {
{
$doc = new Document($obj->id, $obj->path, $obj->comment, $obj->title, $obj->filetype, $obj->size);
switch ($type)
print_r($doc);
{
$course->add_resource($doc);
}
}
}
}*/
if (is_array($course->resources)) {
foreach ($course->resources as $type => $resources) {
switch ($type) {
case RESOURCE_SURVEYQUESTION:
case RESOURCE_SURVEYQUESTION:
foreach($resources as $id => $obj)
foreach($resources as $id => $obj) {
{
if(!in_array($obj->survey_id,array_keys($_POST['resource'][RESOURCE_SURVEY]))) {
if(!in_array($obj->survey_id,array_keys($_POST['resource'][RESOURCE_SURVEY])))
{
unset ($course->resources[$type][$id]);
unset ($course->resources[$type][$id]);
}
}
}
}
@ -266,16 +271,13 @@ class CourseSelectForm
// Mark folders to import which are not selected by the user to import,
// Mark folders to import which are not selected by the user to import,
// but in which a document was selected.
// but in which a document was selected.
$documents = $_POST['resource'][RESOURCE_DOCUMENT];
$documents = $_POST['resource'][RESOURCE_DOCUMENT];
foreach($resources as $id => $obj)
if (is_array($resources))
{
foreach($resources as $id => $obj) {
if( $obj->file_type == 'folder' & & ! isset($_POST['resource'][RESOURCE_DOCUMENT][$id]) & & is_array($documents))
if( $obj->file_type == 'folder' & & ! isset($_POST['resource'][RESOURCE_DOCUMENT][$id]) & & is_array($documents)) {
{
foreach($documents as $id_to_check => $post_value) {
foreach($documents as $id_to_check => $post_value)
{
$obj_to_check = $resources[$id_to_check];
$obj_to_check = $resources[$id_to_check];
$shared_path_part = substr($obj_to_check->path,0,strlen($obj->path));
$shared_path_part = substr($obj_to_check->path,0,strlen($obj->path));
if($id_to_check != $id & & $obj->path == $shared_path_part)
if($id_to_check != $id & & $obj->path == $shared_path_part) {
{
$_POST['resource'][RESOURCE_DOCUMENT][$id] = 1;
$_POST['resource'][RESOURCE_DOCUMENT][$id] = 1;
break;
break;
}
}
@ -283,8 +285,8 @@ class CourseSelectForm
}
}
}
}
default :
default :
foreach ($resources as $id => $obj)
if (is_array($resources)) {
{
foreach ($resources as $id => $obj) {
$resource_is_used_elsewhere = $course->is_linked_resource($obj);
$resource_is_used_elsewhere = $course->is_linked_resource($obj);
// check if document is in a quiz (audio/video)
// check if document is in a quiz (audio/video)
if( $type == RESOURCE_DOCUMENT & & $course->has_resources(RESOURCE_QUIZ))
if( $type == RESOURCE_DOCUMENT & & $course->has_resources(RESOURCE_QUIZ))
@ -304,6 +306,8 @@ class CourseSelectForm
}
}
}
}
}
}
}
}
return $course;
return $course;
}
}
}
}