Merge branch '1.9.x' of github.com:chamilo/chamilo-lms into nuevo

1.9.x
Julio Montoya 11 years ago
commit c143fdcd07
  1. 153
      main/admin/course_intro_pdf_import.php
  2. 81
      main/admin/course_list.php
  3. 5
      main/admin/index.php
  4. 1
      main/coursecopy/classes/CourseBuilder.class.php
  5. 5
      main/coursecopy/classes/CourseRestorer.class.php
  6. 2
      main/document/document.inc.php
  7. 2
      main/document/document.php
  8. BIN
      main/img/capture.png
  9. BIN
      main/img/icons/32/capture.png
  10. 23
      main/inc/ajax/session.ajax.php
  11. 17
      main/inc/lib/course.lib.php
  12. 18
      main/inc/lib/course_description.lib.php
  13. 22
      main/inc/lib/fileUpload.lib.php
  14. 5
      main/inc/lib/main_api.lib.php

@ -0,0 +1,153 @@
<?php
/* For licensing terms, see /license.txt */
/**
* This tool allows platform admins to upload a massive amount of PDFs to be
* uploaded in each course
* @package chamilo.admin
*/
/**
* Initialization
*/
$language_file = array('admin', 'document');
$cidReset = true;
require '../inc/global.inc.php';
$this_section = SECTION_PLATFORM_ADMIN;
api_protect_admin_script();
// temporary configuration of in which folder to upload the file in each course. Should default to '', and start with a '/' and end without it, if defined
$subDir = '';
//require_once api_get_path(LIBRARY_PATH).'fileManage.lib.php';
//require_once api_get_path(LIBRARY_PATH).'import.lib.php';
require_once api_get_path(LIBRARY_PATH).'fileUpload.lib.php';
$tool_name = get_lang('ImportPDFIntroToCourses');
$interbreadcrumb[] = array('url' => 'index.php', 'name' => get_lang('PlatformAdmin'));
set_time_limit(0);
Display :: display_header($tool_name);
if ($_POST['formSent']) {
if (empty($_FILES['import_file']['tmp_name'])) {
$error_message = get_lang('UplUploadFailed');
Display :: display_error_message($error_message, false);
} else {
$allowed_file_mimetype = array('zip');
$ext_import_file = substr($_FILES['import_file']['name'], (strrpos($_FILES['import_file']['name'], '.') + 1));
if (!in_array($ext_import_file, $allowed_file_mimetype)) {
Display :: display_error_message(get_lang('YouMustImportAZipFile'));
} else {
$errors = import_pdfs($courses, $subDir);
if (count($errors) == 0) {
save_data($courses);
}
}
}
}
if (count($errors) != 0) {
$error_message = '<ul>';
foreach ($errors as $index => $error_course) {
$error_message .= '<li>'.get_lang('Course').': '.$error_course['Title'].' ('.$error_course['Code'].')</li>';
}
$error_message .= '</ul>';
Display :: display_normal_message($error_message, false);
}
?>
<form method="post" action="<?php echo api_get_self(); ?>" enctype="multipart/form-data" style="margin: 0px;">
<legend><?php echo $tool_name; ?></legend>
<div class="control-group">
<label><?php echo get_lang('ImportZipFileLocation'); ?></label>
<div class="control">
<input type="file" name="import_file"/>
</div>
</div>
<div class="control-group">
<div class="control">
<button type="submit" class="save" value="<?php echo get_lang('Import'); ?>"><?php echo get_lang('Import'); ?></button>
</div>
</div>
<input type="hidden" name="formSent" value="1"/>
</form>
<div style="clear: both;"></div>
<p><?php echo get_lang('PDFsMustLookLike'); ?> :</p>
<blockquote>
<pre>
<strong>CourseCode</strong>_<strong>NameOfDocument</strong>_<strong>CourseName</strong>.pdf
e.g.
MAT101_Introduction_Mathematics-101.pdf
MAT102_Introduction_Mathematics-102.pdf
ENG101_Introduction_English-101.pdf
</pre>
</blockquote>
<?php
Display :: display_footer();
/**
* Import PDFs
* @param string Filename
* @param string The subdirectory in which to put the files in each course
*/
function import_pdfs($file, $subDir = '/') {
global $_configuration;
$baseDir = api_get_path(SYS_ARCHIVE_PATH);
$uploadPath = 'pdfimport/';
$errors = array ();
if (!is_dir($baseDir.$uploadPath)) {
@mkdir($baseDir.$uploadPath);
}
if (!unzip_uploaded_file($_FILES['import_file'], $uploadPath, $baseDir, 1024*1024*1024)) {
error_log('Could not unzip uploaded file in '.__FILE__.', line '.__LINE__);
return $errors;
}
require_once api_get_path(LIBRARY_PATH).'course_description.lib.php';
require_once api_get_path(LIBRARY_PATH).'app_view.php';
require_once '../course_description/course_description_controller.php';
$list = scandir($baseDir.$uploadPath);
foreach ($list as $file) {
if (substr($file,0,1) == '.' or !is_file($baseDir.$uploadPath.$file)) {
continue;
}
$parts = preg_split('/_/',$file);
$course = api_get_course_info($parts[0]);
if (count($course) > 0) {
// Build file info because handle_uploaded_document() needs it (name, type, size, tmp_name)
$fileSize = filesize($baseDir.$uploadPath.$file);
$docId = add_document($course, $subDir.'/'.$file, 'file', $fileSize, $parts[1].' '.substr($parts[2],0,-4));
if ($docId > 0) {
if (!is_file($baseDir.$uploadPath.$file)) {
error_log($baseDir.$uploadPath.$file.' does not exists in '.__FILE__);
}
if (is_file(api_get_path(SYS_COURSE_PATH).$course['path'].'/document'.$subDir.'/'.$file)) {
error_log(api_get_path(SYS_COURSE_PATH).$course['path'].'/document'.$subDir.'/'.$file.' exists at destination in '.__FILE__);
}
if (!is_writeable(api_get_path(SYS_COURSE_PATH).$course['path'].'/document'.$subDir)) {
error_log('Destination '.api_get_path(SYS_COURSE_PATH).$course['path'].'/document'.$subDir.' is NOT writeable in '.__FILE__);
}
// Place each file in its folder in each course
$move = rename($baseDir.$uploadPath.$file, api_get_path(SYS_COURSE_PATH).$course['path'].'/document'.$subDir.'/'.$file);
api_item_property_update($course, TOOL_DOCUMENT, $docId, 'DocumentAdded', api_get_user_id());
// Redo visibility
api_set_default_visibility(TOOL_DOCUMENT, $docId);
$errors[] = array('Line' => 0, 'Code' => $course['code'], 'Title' => $course['title']);
// Now add a link to the file from the Course description tool
$link = '<p>Sílabo de la asignatura <a href="'.api_get_path(WEB_CODE_PATH).'document/document.php?cidReq='.$course['code'].'&id_session=0&gidReq=0&action=download&id='.$docId.'" target="_blank"><img src="'.api_get_path(WEB_IMG_PATH).'icons/32/pdf.png"></a></p>';
$course_description = new CourseDescription();
$session_id = api_get_session_id();
$course_description->set_course_id($course['real_id']);
$course_description->set_session_id($session_id);
$course_description->set_title('Presentación de la asignatura');
$course_description->set_content($link);
$course_description->set_description_type(1);
$course_description->insert();
}
} else {
error_log($parts[0].' is not a course, apparently');
}
}
return $errors;
}

@ -115,7 +115,50 @@ function get_course_data($from, $number_of_items, $column, $direction) {
}
return $courses;
}
/**
* Get course data to display filtered by session name
*/
function get_course_data_by_session($from, $number_of_items, $column, $direction) {
$course_table = Database::get_main_table(TABLE_MAIN_COURSE);
$session_rel_course = Database::get_main_table(TABLE_MAIN_SESSION_COURSE);
$session = Database::get_main_table(TABLE_MAIN_SESSION);
$sql = "SELECT c.code AS col0,
c.title AS col1,
c.code AS col2,
c.course_language AS col3,
c.category_code AS col4,
c.subscribe AS col5,
c.unsubscribe AS col6,
c.code AS col7,
c.visibility AS col8,
c.directory as col9,
c.visual_code
FROM $course_table c
INNER JOIN $session_rel_course r ON c.code = r.course_code
INNER JOIN $session s ON r.id_session = s.id
";
if (isset($_GET['session'])) {
$session = Database::escape_string(trim($_GET['session']));
$sql.= " WHERE s.name LIKE '%" . $session . "%'";
}
$sql .= " ORDER BY col$column $direction ";
$sql .= " LIMIT $from,$number_of_items";
$res = Database::query($sql);
$courses = array ();
while ($course = Database::fetch_array($res)) {
// Place colour icons in front of courses.
$show_visual_code = $course['visual_code'] != $course[2] ? Display::label($course['visual_code'], 'info') : null;
$course[1] = get_course_visibility_icon($course[8]).'<a href="'.api_get_path(WEB_COURSE_PATH).$course[9].'/index.php">'.$course[1].'</a> '.$show_visual_code;
$course[5] = $course[5] == SUBSCRIBE_ALLOWED ? get_lang('Yes') : get_lang('No');
$course[6] = $course[6] == UNSUBSCRIBE_ALLOWED ? get_lang('Yes') : get_lang('No');
$course_rem = array($course[0], $course[1], $course[2], $course[3], $course[4], $course[5], $course[6], $course[7]);
$courses[] = $course_rem;
}
return $courses;
}
/**
* Filter to display the edit-buttons
*/
@ -252,6 +295,34 @@ if (isset ($_GET['search']) && $_GET['search'] == 'advanced') {
$form->addElement('style_submit_button', 'submit', get_lang('SearchCourse'), 'class="btn"');
$form->addElement('static', 'search_advanced_link', null, '<a href="course_list.php?search=advanced">'.get_lang('AdvancedSearch').'</a>');
//Create a filter by session
/*$sessionFilter = new FormValidator('course_filter', 'get', '', '', array('class'=> 'form-search'), false);
$url = api_get_path(WEB_AJAX_PATH).'session.ajax.php?a=search_session';
$sessionFilter->addElement('select_ajax', 'session_name', get_lang('SearchCourseBySession'), null, array('url' => $url));
$actions = '
<script type="text/javascript">
<!--
function jumpMenu(targ,selObj,restore){ // v3.0
eval(targ+".location=\'"+selObj.options[selObj.selectedIndex].value+"\'");
if (restore) selObj.selectedIndex=0;
}
$(function() {
//alert($);
//jumpMenu(\'parent\',this,0)
$(\'ul.select2-results .select2-result-label\').on(\'click\',function(){
console.log($(\'ul.select2-results li\'));
});
//console.log($(\'#s2id_session_name\'));
$(\'.select2-chosen\').on(\'change\',function(){
console.log(\'test\');
});
});
//-->
</script>';*/
//$actions .= $sessionFilter->return_form();
$actions .= '<div style="float: right; ">';
$actions .= '<a href="course_add.php">'.Display::return_icon('new_course.png', get_lang('AddCourse'),'',ICON_SIZE_MEDIUM).'</a> ';
@ -261,8 +332,14 @@ if (isset ($_GET['search']) && $_GET['search'] == 'advanced') {
$actions .= '</div>';
$actions .= $form->return_form();
// Create a sortable table with the course data
$table = new SortableTable('courses', 'get_number_of_courses', 'get_course_data', 2);
if (isset ($_GET['search']) && $_GET['search'] == 'session') {
// Create a sortable table with the course data filtered by session
$table = new SortableTable('courses', 'get_number_of_courses', 'get_course_data_by_session', 2);
} else {
// Create a sortable table with the course data
$table = new SortableTable('courses', 'get_number_of_courses', 'get_course_data', 2);
}
$parameters=array();
if (isset ($_GET['keyword'])) {

@ -120,13 +120,14 @@ if (api_is_platform_admin()) {
$items[] = array('url'=>'course_category.php', 'label' => get_lang('AdminCategories'));
$items[] = array('url'=>'subscribe_user2course.php', 'label' => get_lang('AddUsersToACourse'));
$items[] = array('url'=>'course_user_import.php', 'label' => get_lang('ImportUsersToACourse'));
//$items[] = array('url'=>'course_intro_pdf_import.php', 'label' => get_lang('ImportPDFIntroToCourses'));
if (api_get_setting('gradebook_enable_grade_model') == 'true') {
$items[] = array('url'=>'grade_models.php', 'label' => get_lang('GradeModel'));
$items[] = array('url'=>'grade_models.php', 'label' => get_lang('GradeModel'));
}
if (isset($extAuthSource) && isset($extAuthSource['ldap']) && count($extAuthSource['ldap']) > 0) {
$items[] = array('url'=>'ldap_import_students.php', 'label' => get_lang('ImportLDAPUsersIntoCourse'));
$items[] = array('url'=>'ldap_import_students.php', 'label' => get_lang('ImportLDAPUsersIntoCourse'));
}
$blocks['courses']['items'] = $items;
$blocks['courses']['extra'] = null;

@ -76,6 +76,7 @@ class CourseBuilder
$this->course->path = api_get_path(SYS_COURSE_PATH).$_course['path'].'/';
$this->course->backup_path = api_get_path(SYS_COURSE_PATH).$_course['path'];
$this->course->encoding = api_get_system_encoding(); //current platform encoding
// db_name is deprecated (only one database now)
$this->course->db_name = $_course['dbName'];
$this->course->info = $_course;
}

@ -89,6 +89,7 @@ class CourseRestorer
/**
* Create a new CourseRestorer
* @param array Course object as returned by other coursebuilder classes (see copy_course.php)
*/
public function __construct($course)
{
@ -106,9 +107,9 @@ class CourseRestorer
/**
* Set the file-option
* @param constant $options What to do with files with same name (FILE_SKIP, FILE_RENAME or FILE_OVERWRITE)
* @param constant $options What to do with files with same name (FILE_SKIP, FILE_RENAME or FILE_OVERWRITE). Default is to skip the copy of files that already exist
*/
function set_file_option($option)
function set_file_option($option = FILE_SKIP)
{
$this->file_option = $option;
}

@ -777,7 +777,7 @@ function create_dir_form($current_dir_id) {
$form->addElement('hidden', 'dir_id', intval($document_id));
$form->addElement('hidden', 'id', intval($current_dir_id));
$form->addElement('header', '', get_lang('CreateDir'));
$form->addElement('text', 'dirname', get_lang('NewDir'));
$form->addElement('text', 'dirname', get_lang('NewDir'), array('autofocus' => 'autofocus'));
$form->addElement('style_submit_button', 'submit', get_lang('CreateFolder'), 'class="add"');
$new_folder_text = $form->return_form();
return $new_folder_text;

@ -1072,7 +1072,7 @@ if ($is_allowed_to_edit || $group_member_with_upload_rights || is_my_shared_fold
echo Display::display_icon('upload_file.png', get_lang('UplUploadDocument'), '', ICON_SIZE_MEDIUM).'</a>';
}
echo '<a href="#" style="margin-top:-5px;" id="jcapture">';
echo '<a href="#" id="jcapture">';
echo Display::display_icon('capture.png', get_lang('CatchScreenCasts'), '', ICON_SIZE_MEDIUM).'</a>';
// Create directory

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.1 KiB

@ -24,6 +24,29 @@ switch ($action) {
unset($list_sessions);
}
break;
case 'search_session':
if (api_is_platform_admin()) {
$results = SessionManager::get_sessions_list(array('s.name LIKE' => "%".$_REQUEST['q']."%"));
$results2 = array();
if (!empty($results)) {
foreach ($results as $item) {
$item2 = array();
foreach ($item as $id => $internal ){
if ($id == 'id') {
$item2[$id] = $internal;
}
if ($id == 'name') {
$item2['text'] = $internal;
}
}
$results2[] = $item2;
}
echo json_encode($results2);
} else {
echo json_encode(array());
}
}
break;
default:
echo '';
}

@ -91,6 +91,23 @@ class CourseManager
create_default_course_gradebook($course_info['code'], $params['gradebook_model_id']);
}
}
// If parameter defined, copy the contents from a specific
// template course into this new course
if (!empty($_configuration['course_creation_use_template'])) {
// Include the necessary libraries to generate a course copy
require_once api_get_path(LIBRARY_PATH).'fileManage.lib.php';
require_once api_get_path(SYS_CODE_PATH).'coursecopy/classes/CourseBuilder.class.php';
require_once api_get_path(SYS_CODE_PATH).'coursecopy/classes/CourseRestorer.class.php';
require_once api_get_path(SYS_CODE_PATH).'coursecopy/classes/CourseSelectForm.class.php';
// Call the course copy object
$originCourse = api_get_course_info_by_id($_configuration['course_creation_use_template']);
$originCourse['official_code'] = $originCourse['code'];
$cb = new CourseBuilder(null, $originCourse);
$course = $cb->build(null, $originCourse['code']);
$cr = new CourseRestorer($course);
$cr->set_file_option();
$cr->restore($course_info['id']); //course_info[id] is the course.code value (I know...)
}
return $course_info;
}
}

@ -17,6 +17,7 @@
class CourseDescription
{
private $id;
private $course_id;
private $title;
private $content;
private $session_id;
@ -190,8 +191,12 @@ class CourseDescription
* first you must set description_type, title, content, progress and session_id properties with the object CourseDescription
* @return int affected rows
*/
public function insert() {
$course_id = api_get_course_int_id();
public function insert() {
if (empty($this->course_id)) {
$course_id = api_get_course_int_id();
} else {
$course_id = $this->course_id;
}
$tbl_course_description = Database::get_course_table(TABLE_COURSE_DESCRIPTION);
$sql = "INSERT IGNORE INTO $tbl_course_description SET
c_id = $course_id,
@ -421,6 +426,15 @@ class CourseDescription
$this->id = $id;
}
/**
* Set description's course id
* @param int Course ID
* @return void
*/
public function set_course_id($id) {
$this->course_id = intval($id);
}
/**
* Set description title
* @return void

@ -422,7 +422,7 @@ function dir_total_space($dir_path) {
$save_dir = getcwd();
chdir($dir_path) ;
$handle = opendir($dir_path);
$sumSize = 0;
while ($element = readdir($handle)) {
if ( $element == '.' || $element == '..') {
continue; // Skip the current and parent directories
@ -611,10 +611,10 @@ function unzip_uploaded_file($uploaded_file, $upload_path, $base_work_dir, $max_
$zip_file = new PclZip($uploaded_file['tmp_name']);
// Check the zip content (real size and file extension)
if (file_exists($uploaded_file)) {
if (file_exists($uploaded_file['tmp_name'])) {
$zip_content_array = $zip_file->listContent();
$ok_scorm = false;
$realFileSize = 0;
foreach ($zip_content_array as & $this_content) {
if (preg_match('~.(php.*|phtml)$~i', $this_content['filename'])) {
return api_failure::set_failure('php_file_in_zip_file');
@ -645,7 +645,7 @@ function unzip_uploaded_file($uploaded_file, $upload_path, $base_work_dir, $max_
}
// It happens on Linux that $upload_path sometimes doesn't start with '/'
if ($upload_path[0] != '/') {
if ($upload_path[0] != '/' && substr($base_work_dir,-1,1) != '/') {
$upload_path = '/'.$upload_path;
}
@ -669,14 +669,13 @@ function unzip_uploaded_file($uploaded_file, $upload_path, $base_work_dir, $max_
// PHP method - slower...
$save_dir = getcwd();
chdir($base_work_dir.$upload_path);
$unzippingState = $zip_file->extract();
$unzippingState = $zip_file->extract();
for ($j=0; $j < count($unzippingState); $j++) {
$state = $unzippingState[$j];
// Fix relative links in html files
$extension = strrchr($state['stored_filename'], '.');
}
if ($dir = @opendir($base_work_dir.$upload_path)) {
while ($file = readdir($dir)) {
if ($file != '.' && $file != '..') {
@ -691,7 +690,10 @@ function unzip_uploaded_file($uploaded_file, $upload_path, $base_work_dir, $max_
}
closedir($dir);
}
} else {
error_log('Could not create directory '.$base_work_dir.$upload_path.' to unzip files');
}
chdir($save_dir); // Back to previous dir position
}
}
@ -728,6 +730,7 @@ function unzip_uploaded_document($uploaded_file, $upload_path, $base_work_dir, $
$zip_content_array = (array)$zip_file->listContent();
$real_filesize = 0;
foreach($zip_content_array as & $this_content) {
$real_filesize += $this_content['size'];
}
@ -944,6 +947,7 @@ function item_property_update_on_folder($_course, $path, $user_id) {
$exploded_path = explode('/', $path);
$course_id = api_get_course_int_id();
$newpath = '';
foreach ($exploded_path as $key => & $value) {
// We don't want a slash before our first slash
if ($key != 0) {
@ -1170,7 +1174,7 @@ function replace_img_path_in_html_file($original_img_path, $new_img_path, $html_
$fp = fopen($html_file, 'r');
$buffer = fread($fp, filesize($html_file));
$new_html_content = '';
// Fix the image tags
@ -1453,7 +1457,7 @@ function build_missing_files_form($missing_files, $upload_path, $file_name) {
$added_slash = ($upload_path == '/') ? '' : '/';
$folder_id = DocumentManager::get_document_id(api_get_course_info(), $upload_path);
// Build the form
$form .= "<p><strong>".get_lang('MissingImagesDetected')."</strong></p>"
$form = "<p><strong>".get_lang('MissingImagesDetected')."</strong></p>"
."<form method=\"post\" action=\"".api_get_self()."\" enctype=\"multipart/form-data\">"
// Related_file is the path to the file that has missing images
."<input type=\"hidden\" name=\"related_file\" value=\"".$upload_path.$added_slash.$file_name."\" />"

@ -1325,9 +1325,10 @@ function api_get_cidreq($add_session_id = true, $add_group_id = true) {
*
* Now if the course_code is given, the returned array gives info about that
* particular course, not specially the current one.
* @todo Same behaviour as api_get_user_info so that api_get_course_id becomes absolete too.
* @param string Course code
* @todo Same behaviour as api_get_user_info so that api_get_course_id becomes obsolete too.
*/
function api_get_course_info($course_code = null) {
function api_get_course_info($course_code = null, $strict = false) {
if (!empty($course_code)) {
$course_code = Database::escape_string($course_code);
$course_table = Database::get_main_table(TABLE_MAIN_COURSE);

Loading…
Cancel
Save