Пример #1
0
 /**
  * TODO update this to match hotspots instead of copying matching
  * Export the question part as a matrix-choice, with only one possible answer per line.
  */
 function imsExportResponses($questionIdent, $questionStatment, $questionDesc = '', $questionMedia = '')
 {
     global $charset;
     $this->answerList = $this->getAnswersList(true);
     $questionMedia = api_get_path(WEB_COURSE_PATH) . api_get_course_path() . '/document/images/' . $questionMedia;
     $mimetype = mime_content_type($questionMedia);
     if (empty($mimetype)) {
         $mimetype = 'image/jpeg';
     }
     $text = '      <p>' . $questionStatment . '</p>' . "\n";
     $text .= '      <graphicOrderInteraction responseIdentifier="hotspot_' . $questionIdent . '">' . "\n";
     $text .= '        <prompt>' . $questionDesc . '</prompt>' . "\n";
     $text .= '        <object type="' . $mimetype . '" width="250" height="230" data="' . $questionMedia . '">-</object>' . "\n";
     if (is_array($this->answerList)) {
         foreach ($this->answerList as $key => $answer) {
             $key = $answer['id'];
             $answerTxt = $answer['answer'];
             $len = api_strlen($answerTxt);
             //coords are transformed according to QTIv2 rules here: http://www.imsproject.org/question/qtiv2p1pd/imsqti_infov2p1pd.html#element10663
             $coords = '';
             $type = 'default';
             switch ($answer['hotspot_type']) {
                 case 'square':
                     $type = 'rect';
                     $res = array();
                     $coords = preg_match('/^\\s*(\\d+);(\\d+)\\|(\\d+)\\|(\\d+)\\s*$/', $answer['hotspot_coord'], $res);
                     $coords = $res[1] . ',' . $res[2] . ',' . ((int) $res[1] + (int) $res[3]) . "," . ((int) $res[2] + (int) $res[4]);
                     break;
                 case 'circle':
                     $type = 'circle';
                     $res = array();
                     $coords = preg_match('/^\\s*(\\d+);(\\d+)\\|(\\d+)\\|(\\d+)\\s*$/', $answer['hotspot_coord'], $res);
                     $coords = $res[1] . ',' . $res[2] . ',' . sqrt(pow($res[1] - $res[3], 2) + pow($res[2] - $res[4]));
                     break;
                 case 'poly':
                     $type = 'poly';
                     $coords = str_replace(array(';', '|'), array(',', ','), $answer['hotspot_coord']);
                     break;
                 case 'delineation':
                     $type = 'delineation';
                     $coords = str_replace(array(';', '|'), array(',', ','), $answer['hotspot_coord']);
                     break;
             }
             $text .= '        <hotspotChoice shape="' . $type . '" coords="' . $coords . '" identifier="' . $key . '"/>' . "\n";
         }
     }
     $text .= '      </graphicOrderInteraction>' . "\n";
     $out = $text;
     return $out;
 }
Пример #2
0
 /**
  * Uploads an author image to the upload/learning_path/images directory
  * @param	array	The image array, coming from the $_FILES superglobal
  * @return	boolean	True on success, false on error
  */
 function upload_image($image_array)
 {
     $image_moved = false;
     if (!empty($image_array['name'])) {
         $upload_ok = process_uploaded_file($image_array);
         $has_attachment = true;
     } else {
         $image_moved = true;
     }
     if ($upload_ok) {
         if ($has_attachment) {
             $courseDir = api_get_course_path() . '/upload/learning_path/images';
             $sys_course_path = api_get_path(SYS_COURSE_PATH);
             $updir = $sys_course_path . $courseDir;
             // Try to add an extension to the file if it hasn't one
             $new_file_name = add_ext_on_mime(stripslashes($image_array['name']), $image_array['type']);
             if (!filter_extension($new_file_name)) {
                 //Display :: display_error_message(get_lang('UplUnableToSaveFileFilteredExtension'));
                 $image_moved = false;
             } else {
                 $file_extension = explode('.', $image_array['name']);
                 $file_extension = strtolower($file_extension[sizeof($file_extension) - 1]);
                 $new_file_name = uniqid('') . '.' . $file_extension;
                 $new_path = $updir . '/' . $new_file_name;
                 //$result= @move_uploaded_file($image_array['tmp_name'], $new_path);
                 // resize the image
                 include_once api_get_path(LIBRARY_PATH) . 'image.lib.php';
                 $temp = new image($image_array['tmp_name']);
                 $picture_infos = @getimagesize($image_array['tmp_name']);
                 // $picture_infos[0]-> width
                 if ($picture_infos[0] > 104) {
                     $thumbwidth = 104;
                 } else {
                     $thumbwidth = $picture_infos[0];
                 }
                 if ($picture_infos[1] > 96) {
                     $new_height = 96;
                 } else {
                     $new_height = $picture_infos[1];
                 }
                 //$new_height = round(($thumbwidth/$picture_infos[0])*$picture_infos[1]);
                 $temp->resize($thumbwidth, $new_height, 0);
                 $type = $picture_infos[2];
                 $result = false;
                 switch ($type) {
                     case 2:
                         $result = $temp->send_image('JPG', $new_path);
                         break;
                     case 3:
                         $result = $temp->send_image('PNG', $new_path);
                         break;
                     case 1:
                         $result = $temp->send_image('GIF', $new_path);
                         break;
                 }
                 $temp->resize($thumbwidth, $new_height, 0);
                 $type = $picture_infos[2];
                 $result = false;
                 switch ($type) {
                     case 2:
                         $result = $temp->send_image('JPG', $new_path);
                         break;
                     case 3:
                         $result = $temp->send_image('PNG', $new_path);
                         break;
                     case 1:
                         $result = $temp->send_image('GIF', $new_path);
                         break;
                 }
                 // Storing the image filename
                 if ($result) {
                     $image_moved = true;
                     $this->set_preview_image($new_file_name);
                     return true;
                 }
             }
         }
     }
     return false;
 }
Пример #3
0
 /**
  * Displays the menu of question types
  * @param Exercise $objExercise
  */
 public static function display_type_menu(Exercise $objExercise)
 {
     $feedback_type = $objExercise->feedback_type;
     $exerciseId = $objExercise->id;
     // 1. by default we show all the question types
     $question_type_custom_list = self::get_question_type_list();
     if (!isset($feedback_type)) {
         $feedback_type = 0;
     }
     if ($feedback_type == 1) {
         //2. but if it is a feedback DIRECT we only show the UNIQUE_ANSWER type that is currently available
         $question_type_custom_list = array(UNIQUE_ANSWER => self::$questionTypes[UNIQUE_ANSWER], HOT_SPOT_DELINEATION => self::$questionTypes[HOT_SPOT_DELINEATION]);
     } else {
         unset($question_type_custom_list[HOT_SPOT_DELINEATION]);
     }
     echo '<div class="actionsbig">';
     echo '<ul class="question_menu">';
     $modelType = $objExercise->getModelType();
     foreach ($question_type_custom_list as $i => $a_type) {
         if ($modelType == EXERCISE_MODEL_TYPE_COMMITTEE) {
             if ($a_type[1] != 'FreeAnswer') {
                 continue;
             }
         }
         // include the class of the type
         require_once $a_type[0];
         // get the picture of the type and the langvar which describes it
         $img = $explanation = '';
         eval('$img = ' . $a_type[1] . '::$typePicture;');
         eval('$explanation = get_lang(' . $a_type[1] . '::$explanationLangVar);');
         echo '<li>';
         echo '<div class="icon_image_content">';
         if ($objExercise->exercise_was_added_in_lp == true) {
             $img = pathinfo($img);
             $img = $img['filename'] . '_na.' . $img['extension'];
             echo Display::return_icon($img, $explanation, array(), ICON_SIZE_BIG);
         } else {
             echo '<a href="admin.php?' . api_get_cidreq() . '&newQuestion=yes&answerType=' . $i . '&exerciseId=' . $exerciseId . '">' . Display::return_icon($img, $explanation, array(), ICON_SIZE_BIG) . '</a>';
         }
         echo '</div>';
         echo '</li>';
     }
     echo '<li>';
     echo '<div class="icon_image_content">';
     if ($objExercise->exercise_was_added_in_lp == true) {
         echo Display::return_icon('database_na.png', get_lang('GetExistingQuestion'));
     } else {
         if ($feedback_type == 1) {
             //echo $url = '<a href="question_pool.php?'.api_get_cidreq().'&type=1&fromExercise='.$exerciseId.'">';
         } else {
             //echo $url = '<a href="question_pool.php?'.api_get_cidreq().'&fromExercise='.$exerciseId.'">';
         }
         echo $url = '<a href="' . api_get_path(WEB_PUBLIC_PATH) . 'courses/' . api_get_course_path() . '/' . api_get_session_id() . '/exercise/' . $exerciseId . '/question-pool">';
         echo Display::return_icon('database.png', get_lang('GetExistingQuestion'));
     }
     echo '</a>';
     echo '</div></li>';
     echo '</ul>';
     echo '</div>';
 }
Пример #4
0
     // Add introduction section page.
     break;
 case 'js_api_refresh':
     if ($debug > 0) error_log('New LP - js_api_refresh action triggered', 0);
     if (!$lp_found) { error_log('New LP - No learnpath given for js_api_refresh', 0); require 'lp_message.php'; }
     if (isset($_REQUEST['item_id'])) {
         $htmlHeadXtra[] = $_SESSION['oLP']->get_js_info($_REQUEST['item_id']);
     }
     require 'lp_message.php';
     break;
 case 'return_to_course_homepage':
     if (!$lp_found) { error_log('New LP - No learnpath given for stats', 0); require 'lp_list.php'; }
     else {
         $_SESSION['oLP']->save_current();
         $_SESSION['oLP']->save_last();
         $url = api_get_path(WEB_COURSE_PATH).api_get_course_path().'/index.php?id_session='.api_get_session_id();
         if (isset($_GET['redirectTo']) && $_GET['redirectTo'] == 'lp_list') {
             $url = 'lp_controller.php?'.api_get_cidreq();
         }
         header('location: '.$url);
         exit;
     }
     break;
 case 'search':
     /* Include the search script, it's smart enough to know when we are
      * searching or not.
      */
     require 'lp_list_search.php';
     break;
 case 'impress':
     if ($debug > 0)
Пример #5
0
         error_log('New LP - No learnpath given for js_api_refresh', 0);
         require 'lp_message.php';
     }
     if (isset($_REQUEST['item_id'])) {
         $htmlHeadXtra[] = $_SESSION['oLP']->get_js_info($_REQUEST['item_id']);
     }
     require 'lp_message.php';
     break;
 case 'return_to_course_homepage':
     if (!$lp_found) {
         error_log('New LP - No learnpath given for stats', 0);
         require 'lp_list.php';
     } else {
         $_SESSION['oLP']->save_current();
         $_SESSION['oLP']->save_last();
         header('location: ' . api_get_path(WEB_COURSE_PATH) . api_get_course_path() . '/index.php?id_session=' . api_get_session_id());
         exit;
     }
     break;
 case 'search':
     /* Include the search script, it's smart enough to know when we are
      * searching or not.
      */
     require 'lp_list_search.php';
     break;
 case 'impress':
     if ($debug > 0) {
         error_log('New LP - view action triggered', 0);
     }
     if (!$lp_found) {
         error_log('New LP - No learnpath given for view', 0);
Пример #6
0
 /**
  * Imports a zip file (presumably AICC) into the Dokeos structure
  * @param	string	Zip file info as given by $_FILES['userFile']
  * @return	string	Absolute path to the AICC config files directory or empty string on error
  */
 function import_package($zip_file_info, $current_dir = '')
 {
     if ($this->debug > 0) {
         error_log('In aicc::import_package(' . print_r($zip_file_info, true) . ',"' . $current_dir . '") method', 0);
     }
     //ini_set('error_log','E_ALL');
     $maxFilledSpace = 1000000000;
     $zip_file_path = $zip_file_info['tmp_name'];
     $zip_file_name = $zip_file_info['name'];
     if ($this->debug > 0) {
         error_log('New LP - aicc::import_package() - Zip file path = ' . $zip_file_path . ', zip file name = ' . $zip_file_name, 0);
     }
     $course_rel_dir = api_get_course_path() . '/scorm';
     //scorm dir web path starting from /courses
     $course_sys_dir = api_get_path(SYS_COURSE_PATH) . $course_rel_dir;
     //absolute system path for this course
     $current_dir = replace_dangerous_char(trim($current_dir), 'strict');
     //current dir we are in, inside scorm/
     if ($this->debug > 0) {
         error_log('New LP - aicc::import_package() - Current_dir = ' . $current_dir, 0);
     }
     //$uploaded_filename = $_FILES['userFile']['name'];
     //get name of the zip file without the extension
     if ($this->debug > 0) {
         error_log('New LP - aicc::import_package() - Received zip file name: ' . $zip_file_path, 0);
     }
     $file_info = pathinfo($zip_file_name);
     $filename = $file_info['basename'];
     $extension = $file_info['extension'];
     $file_base_name = str_replace('.' . $extension, '', $filename);
     //filename without its extension
     $this->zipname = $file_base_name;
     //save for later in case we don't have a title
     if ($this->debug > 0) {
         error_log('New LP - aicc::import_package() - Base file name is : ' . $file_base_name, 0);
     }
     $new_dir = replace_dangerous_char(trim($file_base_name), 'strict');
     $this->subdir = $new_dir;
     if ($this->debug > 0) {
         error_log('New LP - aicc::import_package() - Subdir is first set to : ' . $this->subdir, 0);
     }
     /*
     		if( check_name_exist($course_sys_dir.$current_dir."/".$new_dir) )
     		{
     			$dialogBox = get_lang('FileExists');
     			$stopping_error = true;
     		}
     */
     $zipFile = new pclZip($zip_file_path);
     // Check the zip content (real size and file extension)
     $zipContentArray = $zipFile->listContent();
     $package_type = '';
     //the type of the package. Should be 'aicc' after the next few lines
     $package = '';
     //the basename of the config files (if 'courses.crs' => 'courses')
     $at_root = false;
     //check if the config files are at zip root
     $config_dir = '';
     //the directory in which the config files are. May remain empty
     $files_found = array();
     $subdir_isset = false;
     //the following loop should be stopped as soon as we found the right config files (.crs, .au, .des and .cst)
     foreach ($zipContentArray as $thisContent) {
         if (preg_match('~.(php.*|phtml)$~i', $thisContent['filename'])) {
             //if a php file is found, do not authorize (security risk)
             if ($this->debug > 1) {
                 error_log('New LP - aicc::import_package() - Found unauthorized file: ' . $thisContent['filename'], 0);
             }
             return api_failure::set_failure('php_file_in_zip_file');
         } elseif (preg_match('?.*/aicc/$?', $thisContent['filename'])) {
             //if a directory named 'aicc' is found, package type = aicc, but continue
             //because we need to find the right AICC files
             if ($this->debug > 1) {
                 error_log('New LP - aicc::import_package() - Found aicc directory: ' . $thisContent['filename'], 0);
             }
             $package_type = 'aicc';
         } else {
             //else, look for one of the files we're searching for (something.crs case insensitive)
             $res = array();
             if (preg_match('?^(.*)\\.(crs|au|des|cst|ore|pre|cmp)$?i', $thisContent['filename'], $res)) {
                 if ($this->debug > 1) {
                     error_log('New LP - aicc::import_package() - Found AICC config file: ' . $thisContent['filename'] . '. Now splitting: ' . $res[1] . ' and ' . $res[2], 0);
                 }
                 if ($thisContent['filename'] == basename($thisContent['filename'])) {
                     if ($this->debug > 2) {
                         error_log('New LP - aicc::import_package() - ' . $thisContent['filename'] . ' is at root level', 0);
                     }
                     $at_root = true;
                     if (!is_array($files_found[$res[1]])) {
                         $files_found[$res[1]] = $this->config_exts;
                         //initialise list of expected extensions (defined in class definition)
                     }
                     $files_found[$res[1]][strtolower($res[2])] = $thisContent['filename'];
                     $subdir_isset = true;
                 } else {
                     if (!$subdir_isset) {
                         if (preg_match('?^.*/aicc$?i', dirname($thisContent['filename']))) {
                             //echo "Cutting subdir<br/>";
                             $this->subdir .= '/' . substr(dirname($thisContent['filename']), 0, -5);
                         } else {
                             //echo "Not cutting subdir<br/>";
                             $this->subdir .= '/' . dirname($thisContent['filename']);
                         }
                         $subdir_isset = true;
                     }
                     if ($this->debug > 2) {
                         error_log('New LP - aicc::import_package() - ' . $thisContent['filename'] . ' is not at root level - recording subdir ' . $this->subdir, 0);
                     }
                     $config_dir = dirname($thisContent['filename']);
                     //just the relative directory inside scorm/
                     if (!is_array($files_found[basename($res[1])])) {
                         $files_found[basename($res[1])] = $this->config_exts;
                     }
                     $files_found[basename($res[1])][strtolower($res[2])] = basename($thisContent['filename']);
                 }
                 $package_type = 'aicc';
             } else {
                 if ($this->debug > 3) {
                     error_log('New LP - aicc::import_package() - File ' . $thisContent['filename'] . ' didnt match any check', 0);
                 }
             }
         }
         $realFileSize += $thisContent['size'];
     }
     if ($this->debug > 2) {
         error_log('New LP - aicc::import_package() - $files_found: ' . print_r($files_found, true), 0);
     }
     if ($this->debug > 1) {
         error_log('New LP - aicc::import_package() - Package type is now ' . $package_type, 0);
     }
     $mandatory = false;
     foreach ($files_found as $file_name => $file_exts) {
         $temp = (!empty($files_found[$file_name]['crs']) and !empty($files_found[$file_name]['au']) and !empty($files_found[$file_name]['des']) and !empty($files_found[$file_name]['cst']));
         if ($temp) {
             if ($this->debug > 1) {
                 error_log('New LP - aicc::import_package() - Found all config files for ' . $file_name, 0);
             }
             $mandatory = true;
             $package = $file_name;
             //store base config file name for reuse in parse_config_files()
             $this->config_basename = $file_name;
             //store filenames for reuse in parse_config_files()
             $this->config_files = $files_found[$file_name];
             //get out, we only want one config files set
             break;
         }
     }
     if ($package_type == '' or $mandatory != true) {
         return api_failure::set_failure('not_aicc_content');
     }
     if (!enough_size($realFileSize, $course_sys_dir, $maxFilledSpace)) {
         return api_failure::set_failure('not_enough_space');
     }
     // it happens on Linux that $new_dir sometimes doesn't start with '/'
     if ($new_dir[0] != '/') {
         $new_dir = '/' . $new_dir;
     }
     //cut trailing slash
     if ($new_dir[strlen($new_dir) - 1] == '/') {
         $new_dir = substr($new_dir, 0, -1);
     }
     /*
     --------------------------------------
     	Uncompressing phase
     --------------------------------------
     */
     /*
     	We need to process each individual file in the zip archive to
     	- add it to the database
     	- parse & change relative html links
     	- make sure the filenames are secure (filter funny characters or php extensions)
     */
     if (is_dir($course_sys_dir . $new_dir) or @mkdir($course_sys_dir . $new_dir)) {
         // PHP method - slower...
         if ($this->debug >= 1) {
             error_log('New LP - Changing dir to ' . $course_sys_dir . $new_dir, 0);
         }
         $saved_dir = getcwd();
         chdir($course_sys_dir . $new_dir);
         $unzippingState = $zipFile->extract();
         for ($j = 0; $j < count($unzippingState); $j++) {
             $state = $unzippingState[$j];
             //TODO fix relative links in html files (?)
             $extension = strrchr($state["stored_filename"], ".");
             //if($this->debug>1){error_log('New LP - found extension '.$extension.' in '.$state['stored_filename'],0);}
         }
         if (!empty($new_dir)) {
             $new_dir = $new_dir . '/';
         }
         //rename files, for example with \\ in it
         if ($dir = @opendir($course_sys_dir . $new_dir)) {
             if ($this->debug == 1) {
                 error_log('New LP - Opened dir ' . $course_sys_dir . $new_dir, 0);
             }
             while ($file = readdir($dir)) {
                 if ($file != '.' && $file != '..') {
                     $filetype = "file";
                     if (is_dir($course_sys_dir . $new_dir . $file)) {
                         $filetype = "folder";
                     }
                     //TODO RENAMING FILES CAN BE VERY DANGEROUS AICC-WISE, avoid that as much as possible!
                     //$safe_file=replace_dangerous_char($file,'strict');
                     $find_str = array('\\', '.php', '.phtml');
                     $repl_str = array('/', '.txt', '.txt');
                     $safe_file = str_replace($find_str, $repl_str, $file);
                     if ($safe_file != $file) {
                         //@rename($course_sys_dir.$new_dir,$course_sys_dir.'/'.$safe_file);
                         $mydir = dirname($course_sys_dir . $new_dir . $safe_file);
                         if (!is_dir($mydir)) {
                             $mysubdirs = split('/', $mydir);
                             $mybasedir = '/';
                             foreach ($mysubdirs as $mysubdir) {
                                 if (!empty($mysubdir)) {
                                     $mybasedir = $mybasedir . $mysubdir . '/';
                                     if (!is_dir($mybasedir)) {
                                         @mkdir($mybasedir);
                                         if ($this->debug == 1) {
                                             error_log('New LP - Dir ' . $mybasedir . ' doesnt exist. Creating.', 0);
                                         }
                                     }
                                 }
                             }
                         }
                         @rename($course_sys_dir . $new_dir . $file, $course_sys_dir . $new_dir . $safe_file);
                         if ($this->debug == 1) {
                             error_log('New LP - Renaming ' . $course_sys_dir . $new_dir . $file . ' to ' . $course_sys_dir . $new_dir . $safe_file, 0);
                         }
                     }
                     //set_default_settings($course_sys_dir,$safe_file,$filetype);
                 }
             }
             closedir($dir);
             chdir($saved_dir);
         }
     } else {
         return '';
     }
     return $course_sys_dir . $new_dir . $config_dir;
 }
Пример #7
0
$document_data = DocumentManager::get_document_data_by_id($_GET['id'], api_get_course_id(), true);
if (empty($document_data)) {
    if (api_is_in_group()) {
        $group_properties = GroupManager::get_group_properties(api_get_group_id());
        $document_id = DocumentManager::get_document_id(api_get_course_info(), $group_properties['directory']);
        $document_data = DocumentManager::get_document_data_by_id($document_id, api_get_course_id());
    }
}
$document_id = $document_data['id'];
$dir = $document_data['path'];
//make some vars
$wamidir = $dir;
if ($wamidir == "/") {
    $wamidir = "";
}
$wamiurlplay = api_get_path(WEB_COURSE_PATH) . api_get_course_path() . '/document' . $wamidir . "/";
$is_allowed_to_edit = api_is_allowed_to_edit(null, true);
// Please, do not modify this dirname formatting
if (strstr($dir, '..')) {
    $dir = '/';
}
if ($dir[0] == '.') {
    $dir = substr($dir, 1);
}
if ($dir[0] != '/') {
    $dir = '/' . $dir;
}
if ($dir[strlen($dir) - 1] != '/') {
    $dir .= '/';
}
$filepath = api_get_path(SYS_COURSE_PATH) . $_course['path'] . '/document' . $dir;
Пример #8
0
 /**
  * @return string
  */
 public static function getCustomWebIconPath()
 {
     // Check if directory exists or create it if it doesn't
     $dir = api_get_path(WEB_COURSE_PATH) . api_get_course_path() . '/upload/course_home_icons/';
     return $dir;
 }
<?php

/* For licensing terms, see /license.txt */
use Chamilo\CoreBundle\Framework\Container;
/* @todo move this file in the inc/ajax/ folder */
/**
 * Glossary ajax request code
 * @package chamilo.glossary
 */
/**
 * Search a term and return description from a glossary.
 */
$charset = api_get_system_encoding();
//replace image path
$path_image = api_get_path(WEB_COURSE_PATH) . api_get_course_path();
$path_image_search = '../../courses/' . api_get_course_path();
if (isset($_POST['glossary_id']) && $_POST['glossary_id'] == strval(intval($_POST['glossary_id']))) {
    $glossary_id = Security::remove_XSS($_POST['glossary_id']);
    $glossary_description_by_id = GlossaryManager::get_glossary_term_by_glossary_id($glossary_id);
    $glossary_description_by_id = str_replace($path_image_search, $path_image, $glossary_description_by_id);
    echo api_xml_http_response_encode($glossary_description_by_id);
} elseif (isset($_POST['glossary_data']) && $_POST['glossary_data'] == 'true') {
    //get_glossary_terms
    $glossary_data = GlossaryManager::get_glossary_terms();
    $glossary_all_data = array();
    if (count($glossary_data) > 0) {
        foreach ($glossary_data as $glossary_index => $glossary_value) {
            $glossary_all_data[] = $glossary_value['id'] . '__|__|' . $glossary_value['name'];
        }
        $glossary_all_data = implode('[|.|_|.|-|.|]', $glossary_all_data);
        echo api_xml_http_response_encode($glossary_all_data);
Пример #10
0
                            'target' => '_self',
                            'onclick' => 'javascript: window.parent.API.save_asset();'
                        )
                    );


    echo '</div>';
?>
        <!-- end header -->

        <!-- Author image preview -->
        <div id="author_image">
            <div id="author_icon">
                <?php
                if ($_SESSION['oLP']->get_preview_image() != '') {
                    $picture = getimagesize(api_get_path(SYS_COURSE_PATH).api_get_course_path().'/upload/learning_path/images/'.$_SESSION['oLP']->get_preview_image());
                    $style = null;
                    if ($picture['1'] < 96) {
                        $style = ' style="padding-top:'.((94 -$picture['1'])/2).'px;" ';
                    }
                    $size = ($picture['0'] > 104 && $picture['1'] > 96 )? ' width="104" height="96" ': $style;
                    $my_path = $_SESSION['oLP']->get_preview_image_path();
                    echo '<img src="'.$my_path.'">';
                } else {
                    echo Display :: display_icon('unknown_250_100.jpg');
                }
                ?>
            </div>
            <div id="lp_navigation_elem">
                <?php echo $navigation_bar; ?>
                <div id="progress_bar">
Пример #11
0
    $hp_count = Database::num_rows($res);
}
$total = $total_exercises + $hp_count;
if ($is_allowedToEdit && $origin != 'learnpath') {
    echo '<a href="exercise_admin.php?' . api_get_cidreq() . '">' . Display::return_icon('new_exercice.png', get_lang('NewEx'), '', ICON_SIZE_MEDIUM) . '</a>';
    echo '<a href="question_create.php?' . api_get_cidreq() . '">' . Display::return_icon('new_question.png', get_lang('AddQ'), '', ICON_SIZE_MEDIUM) . '</a>';
    // Question category
    echo '<a href="tests_category.php">';
    echo Display::return_icon('question_category_show.gif', get_lang('QuestionCategory'));
    echo '</a>';
    if (api_is_platform_admin()) {
        echo '<a href="tests_category.php?type=global">';
        echo Display::return_icon('folder_global_category.png', get_lang('QuestionGlobalCategory'), array(), ICON_SIZE_MEDIUM);
        echo '</a>';
    }
    echo '<a href="' . api_get_path(WEB_PUBLIC_PATH) . 'courses/' . api_get_course_path() . '/' . api_get_session_id() . '/exercise/question-pool">';
    echo Display::return_icon('database.png', get_lang('QuestionPool'), array('style' => 'width:32px'));
    echo '</a>';
    echo '<a href="media.php?' . api_get_cidreq() . '">';
    echo Display::return_icon('media.png', get_lang('Media'), array(), ICON_SIZE_MEDIUM);
    echo '</a>';
    // end question category
    echo '<a href="hotpotatoes.php?' . api_get_cidreq() . '">' . Display::return_icon('import_hotpotatoes.png', get_lang('ImportHotPotatoesQuiz'), '', ICON_SIZE_MEDIUM) . '</a>';
    // link to import qti2 ...
    echo '<a href="qti2.php?' . api_get_cidreq() . '">' . Display::return_icon('import_qti2.png', get_lang('ImportQtiQuiz'), '', ICON_SIZE_MEDIUM) . '</a>';
    echo '<a href="upload_exercise.php?' . api_get_cidreq() . '">' . Display::return_icon('import_excel.png', get_lang('ImportExcelQuiz'), '', ICON_SIZE_MEDIUM) . '</a>';
}
if ($is_allowedToEdit) {
    echo '</div>';
    // closing the actions div
    echo '<div id="message"></div>';
Пример #12
0
}
$full_file_name = api_get_path(SYS_COURSE_PATH) . api_get_course_path() . '/upload/announcements/' . $doc_url;
//if the rewrite rule asks for a directory, we redirect to the document explorer
if (is_dir($full_file_name)) {
    //remove last slash if present
    //$doc_url = ($doc_url{strlen($doc_url)-1}=='/')?substr($doc_url,0,strlen($doc_url)-1):$doc_url;
    //mod_rewrite can change /some/path/ to /some/path// in some cases, so clean them all off (René)
    while ($doc_url[$dul = strlen($doc_url) - 1] == '/') {
        $doc_url = substr($doc_url, 0, $dul);
    }
    //create the path
    $document_explorer = api_get_path(WEB_COURSE_PATH) . api_get_course_path();
    // home course path
    //redirect
    header('Location: ' . $document_explorer);
}
$tbl_announcement_attachment = Database::get_course_table(TABLE_ANNOUNCEMENT_ATTACHMENT);
// launch event
Event::event_download($doc_url);
$course_id = api_get_course_int_id();
$doc_url = Database::escape_string($doc_url);
$sql = "SELECT filename FROM {$tbl_announcement_attachment}\n  \t  \tWHERE c_id = {$course_id} AND path LIKE BINARY '{$doc_url}'";
$result = Database::query($sql);
if (Database::num_rows($result) > 0) {
    $row = Database::fetch_array($result);
    $title = str_replace(' ', '_', $row['filename']);
    if (Security::check_abs_path($full_file_name, api_get_path(SYS_COURSE_PATH) . api_get_course_path() . '/upload/announcements/')) {
        DocumentManager::file_send_for_download($full_file_name, true, $title);
    }
}
exit;
Пример #13
0
/**
 * Get the file contents for an assigment
 * @param int $id
 * @param array $course_info
 * @param int Session ID
 * @return array|bool
 */
function getFileContents($id, $course_info, $sessionId = 0)
{
    $id = intval($id);
    if (empty($course_info) || empty($id)) {
        return false;
    }
    if (empty($sessionId)) {
        $sessionId = api_get_session_id();
    }

    $tbl_student_publication = Database::get_course_table(TABLE_STUDENT_PUBLICATION);

    if (!empty($course_info['real_id'])) {
        $sql = 'SELECT * FROM '.$tbl_student_publication.'
                WHERE c_id = '.$course_info['real_id'].' AND id = "'.$id.'"';
        $result = Database::query($sql);
        if ($result && Database::num_rows($result)) {
            $row = Database::fetch_array($result, 'ASSOC');
            $full_file_name = api_get_path(SYS_COURSE_PATH).api_get_course_path().'/'.$row['url'];

            $item_info = api_get_item_property_info(api_get_course_int_id(), 'work', $row['id'], $sessionId);
            allowOnlySubscribedUser(api_get_user_id(), $row['parent_id'], $course_info['real_id']);

            if (empty($item_info)) {
                api_not_allowed();
            }

            /*
            field show_score in table course :
                0 =>    New documents are visible for all users
                1 =>    New documents are only visible for the teacher(s)
            field visibility in table item_property :
                0 => eye closed, invisible for all students
                1 => eye open
            field accepted in table c_student_publication :
                0 => eye closed, invisible for all students
                1 => eye open
            ( We should have visibility == accepted, otherwise there is an
            inconsistency in the Database)
            field value in table c_course_setting :
                0 => Allow learners to delete their own publications = NO
                1 => Allow learners to delete their own publications = YES

            +------------------+-------------------------+------------------------+
            |Can download work?| doc visible for all = 0 | doc visible for all = 1|
            +------------------+-------------------------+------------------------+
            |  visibility = 0  | editor only             | editor only            |
            |                  |                         |                        |
            +------------------+-------------------------+------------------------+
            |  visibility = 1  | editor                  | editor                 |
            |                  | + owner of the work     | + any student          |
            +------------------+-------------------------+------------------------+
            (editor = teacher + admin + anybody with right api_is_allowed_to_edit)
            */

            $work_is_visible = ($item_info['visibility'] == 1 && $row['accepted'] == 1);
            $doc_visible_for_all = ($course_info['show_score'] == 1);

            $is_editor = api_is_allowed_to_edit(true, true, true);
            $student_is_owner_of_work = user_is_author($row['id'], $row['user_id']);

            if ($is_editor ||
                ($student_is_owner_of_work) ||
                ($doc_visible_for_all && $work_is_visible)
            ) {
                $title = $row['title'];
                if (array_key_exists('filename', $row) && !empty($row['filename'])) {
                    $title = $row['filename'];
                }
                $title = str_replace(' ', '_', $title);
                event_download($title);
                if (Security::check_abs_path(
                    $full_file_name,
                    api_get_path(SYS_COURSE_PATH).api_get_course_path().'/')
                ) {
                    return array(
                        'path' => $full_file_name,
                        'title' => $title
                    );
                }
            }
        }
    }

    return false;
}
Пример #14
0
 /**
  * Function export last wiki page version to document area
  * @param int $doc_id wiki page id
  *
  * @author Juan Carlos Raña <*****@*****.**>
  */
 public function export2doc($doc_id)
 {
     $_course = $this->courseInfo;
     $groupId = api_get_group_id();
     $data = self::get_wiki_data($doc_id);
     if (empty($data)) {
         return false;
     }
     $wikiTitle = $data['title'];
     $wikiContents = $data['content'];
     $template = '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
         <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="{LANGUAGE}" lang="{LANGUAGE}">
         <head>
         <title>{TITLE}</title>
         <meta http-equiv="Content-Type" content="text/html; charset={ENCODING}" />
         <style type="text/css" media="screen, projection">
         /*<![CDATA[*/
         {CSS}
         /*]]>*/
         </style>
         {ASCIIMATHML_SCRIPT}</head>
         <body dir="{TEXT_DIRECTION}">
         {CONTENT}
         </body>
         </html>';
     $css_file = api_get_path(TO_SYS, WEB_CSS_PATH) . api_get_setting('stylesheets') . '/default.css';
     if (file_exists($css_file)) {
         $css = @file_get_contents($css_file);
     } else {
         $css = '';
     }
     // Fixing some bugs in css files.
     $root_rel = api_get_path(REL_PATH);
     $css_path = 'main/css/';
     $theme = api_get_setting('stylesheets') . '/';
     $css = str_replace('behavior:url("/main/css/csshover3.htc");', '', $css);
     $css = str_replace('main/', $root_rel . 'main/', $css);
     $css = str_replace('images/', $root_rel . $css_path . $theme . 'images/', $css);
     $css = str_replace('../../img/', $root_rel . 'main/img/', $css);
     $asciimathmal_script = api_contains_asciimathml($wikiContents) || api_contains_asciisvg($wikiContents) ? '<script src="' . api_get_path(TO_REL, SCRIPT_ASCIIMATHML) . '" type="text/javascript"></script>' . "\n" : '';
     $template = str_replace(array('{LANGUAGE}', '{ENCODING}', '{TEXT_DIRECTION}', '{TITLE}', '{CSS}', '{ASCIIMATHML_SCRIPT}'), array(api_get_language_isocode(), api_get_system_encoding(), api_get_text_direction(), $wikiTitle, $css, $asciimathmal_script), $template);
     if (0 != $groupId) {
         $groupPart = '_group' . $groupId;
         // and add groupId to put the same document title in different groups
         $group_properties = GroupManager::get_group_properties($groupId);
         $groupPath = $group_properties['directory'];
     } else {
         $groupPart = '';
         $groupPath = '';
     }
     $exportDir = api_get_path(SYS_COURSE_PATH) . api_get_course_path() . '/document' . $groupPath;
     $exportFile = api_replace_dangerous_char($wikiTitle) . $groupPart;
     $wikiContents = trim(preg_replace("/\\[[\\[]?([^\\]|]*)[|]?([^|\\]]*)\\][\\]]?/", "\$1", $wikiContents));
     //TODO: put link instead of title
     $wikiContents = str_replace('{CONTENT}', $wikiContents, $template);
     // replace relative path by absolute path for courses, so you can see items into this page wiki (images, mp3, etc..) exported in documents
     if (api_strpos($wikiContents, '../../courses/') !== false) {
         $web_course_path = api_get_path(WEB_COURSE_PATH);
         $wikiContents = str_replace('../../courses/', $web_course_path, $wikiContents);
     }
     $i = 1;
     //only export last version, but in new export new version in document area
     while (file_exists($exportDir . '/' . $exportFile . '_' . $i . '.html')) {
         $i++;
     }
     $wikiFileName = $exportFile . '_' . $i . '.html';
     $exportPath = $exportDir . '/' . $wikiFileName;
     file_put_contents($exportPath, $wikiContents);
     $doc_id = add_document($_course, $groupPath . '/' . $wikiFileName, 'file', filesize($exportPath), $wikiTitle);
     api_item_property_update($_course, TOOL_DOCUMENT, $doc_id, 'DocumentAdded', api_get_user_id(), $groupId);
     return $doc_id;
 }
Пример #15
0
 /**
  * Imports a zip file into the Chamilo structure
  * @param    string    Zip file info as given by $_FILES['userFile']
  * @return    string    Absolute path to the imsmanifest.xml file or empty string on error
  */
 function import_package($zip_file_info, $current_dir = '')
 {
     if ($this->debug > 0) {
         error_log('In scorm::import_package(' . print_r($zip_file_info, true) . ',"' . $current_dir . '") method', 0);
     }
     $maxFilledSpace = DocumentManager::get_course_quota();
     $zip_file_path = $zip_file_info['tmp_name'];
     $zip_file_name = $zip_file_info['name'];
     if ($this->debug > 1) {
         error_log('New LP - import_package() - zip file path = ' . $zip_file_path . ', zip file name = ' . $zip_file_name, 0);
     }
     // scorm dir web path starting from /courses
     $course_rel_dir = api_get_course_path() . '/scorm';
     $course_sys_dir = api_get_path(SYS_COURSE_PATH) . $course_rel_dir;
     // Absolute system path for this course.
     if (!is_dir($course_sys_dir)) {
         mkdir($course_sys_dir, api_get_permissions_for_new_directories());
     }
     $current_dir = api_replace_dangerous_char(trim($current_dir), 'strict');
     // Current dir we are in, inside scorm/
     if ($this->debug > 1) {
         error_log('New LP - import_package() - current_dir = ' . $current_dir, 0);
     }
     //$uploaded_filename = $_FILES['userFile']['name'];
     // Get name of the zip file without the extension.
     if ($this->debug > 1) {
         error_log('New LP - Received zip file name: ' . $zip_file_path, 0);
     }
     $file_info = pathinfo($zip_file_name);
     $filename = $file_info['basename'];
     $extension = $file_info['extension'];
     $file_base_name = str_replace('.' . $extension, '', $filename);
     // Filename without its extension.
     $this->zipname = $file_base_name;
     // Save for later in case we don't have a title.
     if ($this->debug > 1) {
         error_log("New LP - base file name is : " . $file_base_name, 0);
     }
     $new_dir = api_replace_dangerous_char(trim($file_base_name), 'strict');
     $this->subdir = $new_dir;
     if ($this->debug > 1) {
         error_log("New LP - subdir is first set to : " . $this->subdir, 0);
     }
     $zipFile = new PclZip($zip_file_path);
     // Check the zip content (real size and file extension).
     $zipContentArray = $zipFile->listContent();
     $package_type = '';
     $at_root = false;
     $manifest = '';
     $realFileSize = 0;
     $manifest_list = array();
     // The following loop should be stopped as soon as we found the right imsmanifest.xml (how to recognize it?).
     foreach ($zipContentArray as $thisContent) {
         $file = $thisContent['filename'];
         //error_log('Looking at  '.$thisContent['filename'], 0);
         if (preg_match('~.(php.*|phtml)$~i', $file)) {
             $this->set_error_msg("File {$file} contains a PHP script");
             //return api_failure::set_failure('php_file_in_zip_file');
         } elseif (stristr($thisContent['filename'], 'imsmanifest.xml')) {
             //error_log('Found imsmanifest at '.$thisContent['filename'], 0);
             if ($thisContent['filename'] == basename($thisContent['filename'])) {
                 $at_root = true;
             } else {
                 //$this->subdir .= '/'.dirname($thisContent['filename']);
                 if ($this->debug > 2) {
                     error_log("New LP - subdir is now " . $this->subdir, 0);
                 }
             }
             $package_type = 'scorm';
             $manifest_list[] = $thisContent['filename'];
             $manifest = $thisContent['filename'];
             //just the relative directory inside scorm/
         } else {
             // Do nothing, if it has not been set as scorm somewhere else, it stays as '' default.
         }
         $realFileSize += $thisContent['size'];
     }
     // Now get the shortest path (basically, the imsmanifest that is the closest to the root).
     $shortest_path = $manifest_list[0];
     $slash_count = substr_count($shortest_path, '/');
     foreach ($manifest_list as $manifest_path) {
         $tmp_slash_count = substr_count($manifest_path, '/');
         if ($tmp_slash_count < $slash_count) {
             $shortest_path = $manifest_path;
             $slash_count = $tmp_slash_count;
         }
     }
     $this->subdir .= '/' . dirname($shortest_path);
     // Do not concatenate because already done above.
     $manifest = $shortest_path;
     if ($this->debug > 1) {
         error_log('New LP - Package type is now ' . $package_type, 0);
     }
     // && defined('CHECK_FOR_SCORM') && CHECK_FOR_SCORM)
     if ($package_type == '') {
         if ($this->debug > 1) {
             error_log('New LP - Package type is empty', 0);
         }
         return api_failure::set_failure('not_scorm_content');
     }
     // It happens on Linux that $new_dir sometimes doesn't start with '/'
     if ($new_dir[0] != '/') {
         $new_dir = '/' . $new_dir;
     }
     if ($new_dir[strlen($new_dir) - 1] == '/') {
         $new_dir = substr($new_dir, 0, -1);
     }
     $isDir = is_dir($course_sys_dir . $new_dir);
     if ($isDir == false) {
         mkdir($course_sys_dir . $new_dir, api_get_permissions_for_new_directories());
         $isDir = is_dir($course_sys_dir . $new_dir);
     }
     /* Uncompressing phase */
     /*
         We need to process each individual file in the zip archive to
         - add it to the database
         - parse & change relative html links
         - make sure the filenames are secure (filter funny characters or php extensions)
     */
     if ($isDir) {
         if (!FileManager::enough_size($realFileSize, $course_sys_dir, $maxFilledSpace)) {
             if ($this->debug > 1) {
                 error_log('New LP - Not enough space to store package', 0);
             }
             return api_failure::set_failure('not_enough_space');
         }
         // PHP method - slower...
         if ($this->debug >= 1) {
             error_log('New LP - Changing dir to ' . $course_sys_dir . $new_dir, 0);
         }
         $saved_dir = getcwd();
         chdir($course_sys_dir . $new_dir);
         $unzippingState = $zipFile->extract();
         for ($j = 0; $j < count($unzippingState); $j++) {
             $state = $unzippingState[$j];
             // TODO: Fix relative links in html files (?)
             $extension = strrchr($state['stored_filename'], '.');
             if ($this->debug >= 1) {
                 error_log('New LP - found extension ' . $extension . ' in ' . $state['stored_filename'], 0);
             }
         }
         if (!empty($new_dir)) {
             $new_dir = $new_dir . '/';
         }
         // Rename files, for example with \\ in it.
         if ($this->debug >= 1) {
             error_log('New LP - try to open: ' . $course_sys_dir . $new_dir, 0);
         }
         if ($dir = @opendir($course_sys_dir . $new_dir)) {
             if ($this->debug >= 1) {
                 error_log('New LP - Opened dir ' . $course_sys_dir . $new_dir, 0);
             }
             while ($file = readdir($dir)) {
                 if ($file != '.' && $file != '..') {
                     $filetype = 'file';
                     if (is_dir($course_sys_dir . $new_dir . $file)) {
                         $filetype = 'folder';
                     }
                     // TODO: RENAMING FILES CAN BE VERY DANGEROUS SCORM-WISE, avoid that as much as possible!
                     //$safe_file = replace_dangerous_char($file, 'strict');
                     $find_str = array('\\', '.php', '.phtml');
                     $repl_str = array('/', '.txt', '.txt');
                     $safe_file = str_replace($find_str, $repl_str, $file);
                     if ($this->debug >= 1) {
                         error_log('Comparing:  ' . $safe_file, 0);
                     }
                     if ($this->debug >= 1) {
                         error_log('and:  ' . $file, 0);
                     }
                     if ($safe_file != $file) {
                         $mydir = dirname($course_sys_dir . $new_dir . $safe_file);
                         if (!is_dir($mydir)) {
                             $mysubdirs = split('/', $mydir);
                             $mybasedir = '/';
                             foreach ($mysubdirs as $mysubdir) {
                                 if (!empty($mysubdir)) {
                                     $mybasedir = $mybasedir . $mysubdir . '/';
                                     if (!is_dir($mybasedir)) {
                                         @mkdir($mybasedir, api_get_permissions_for_new_directories());
                                         if ($this->debug >= 1) {
                                             error_log('New LP - Dir ' . $mybasedir . ' doesnt exist. Creating.', 0);
                                         }
                                     }
                                 }
                             }
                         }
                         @rename($course_sys_dir . $new_dir . $file, $course_sys_dir . $new_dir . $safe_file);
                         if ($this->debug >= 1) {
                             error_log('New LP - Renaming ' . $course_sys_dir . $new_dir . $file . ' to ' . $course_sys_dir . $new_dir . $safe_file, 0);
                         }
                     }
                 }
             }
             closedir($dir);
             chdir($saved_dir);
             api_chmod_R($course_sys_dir . $new_dir, api_get_permissions_for_new_directories());
             if ($this->debug > 1) {
                 error_log('New LP - changed back to init dir: ' . $course_sys_dir . $new_dir, 0);
             }
         }
     } else {
         return '';
     }
     return $course_sys_dir . $new_dir . $manifest;
 }
Пример #16
0
             }
         } else {
             $error = true;
         }
     }
     if (!$error) {
         // Full backup
         $course = CourseArchiver::read_course($filename, $delete_file);
     }
 }
 if (!$error && $course->has_resources()) {
     $cr = new CourseRestorer($course);
     $cr->set_file_option($_POST['same_file_name_option']);
     $cr->restore();
     Display::display_normal_message(get_lang('ImportFinished'));
     echo '<a class="btn" href="' . api_get_path(WEB_COURSE_PATH) . api_get_course_path() . '/index.php">' . get_lang('CourseHomepage') . '</a>';
 } else {
     if (!$error) {
         Display::display_warning_message(get_lang('NoResourcesInBackupFile'));
         echo '<a class="btn" href="import_backup.php?' . api_get_cidreq() . '">' . get_lang('TryAgain') . '</a>';
     } elseif ($filename === false) {
         Display::display_error_message(get_lang('ArchivesDirectoryNotWriteableContactAdmin'));
         echo '<a class="btn" href="import_backup.php?' . api_get_cidreq() . '">' . get_lang('TryAgain') . '</a>';
     } else {
         if ($filename == '') {
             Display::display_error_message(get_lang('SelectBackupFile'));
             echo '<a class="btn" href="import_backup.php?' . api_get_cidreq() . '">' . get_lang('TryAgain') . '</a>';
         } else {
             Display::display_error_message(get_lang('UploadError'));
             echo '<a class="btn" href="import_backup.php?' . api_get_cidreq() . '">' . get_lang('TryAgain') . '</a>';
         }
Пример #17
0
 /**
  * Uploads an author image to the upload/learning_path/images directory
  * @param    array    The image array, coming from the $_FILES superglobal
  * @return    boolean    True on success, false on error
  */
 public function upload_image($image_array)
 {
     $image_moved = false;
     if (!empty($image_array['name'])) {
         $upload_ok = FileManager::process_uploaded_file($image_array);
         $has_attachment = true;
     } else {
         $image_moved = true;
     }
     if ($upload_ok) {
         if ($has_attachment) {
             $courseDir = api_get_course_path() . '/upload/learning_path/images';
             $sys_course_path = api_get_path(SYS_COURSE_PATH);
             $updir = $sys_course_path . $courseDir;
             // Try to add an extension to the file if it hasn't one.
             $new_file_name = FileManager::add_ext_on_mime(stripslashes($image_array['name']), $image_array['type']);
             if (!FileManager::filter_extension($new_file_name)) {
                 //Display :: display_error_message(get_lang('UplUnableToSaveFileFilteredExtension'));
                 $image_moved = false;
             } else {
                 $file_extension = explode('.', $image_array['name']);
                 $file_extension = strtolower($file_extension[sizeof($file_extension) - 1]);
                 $filename = uniqid('');
                 $new_file_name = $filename . '.' . $file_extension;
                 $new_path = $updir . '/' . $new_file_name;
                 // Resize the image.
                 $temp = new Image($image_array['tmp_name']);
                 $picture_infos = $temp->get_image_info();
                 if ($picture_infos['width'] > 104) {
                     $thumbwidth = 104;
                 } else {
                     $thumbwidth = $picture_infos['width'];
                 }
                 if ($picture_infos['height'] > 96) {
                     $new_height = 96;
                 } else {
                     $new_height = $picture_infos['height'];
                 }
                 $temp->resize($thumbwidth, $new_height, 0);
                 $result = $temp->send_image($new_path);
                 // Storing the image filename.
                 if ($result) {
                     $image_moved = true;
                     $this->set_preview_image($new_file_name);
                     //Resize to 64px to use on course homepage
                     $temp->resize(64, 64, 0);
                     $temp->send_image($updir . '/' . $filename . '.64.' . $file_extension);
                     return true;
                 }
             }
         }
     }
     return false;
 }
Пример #18
0
function CreateServerFolder($folderPath, $lastFolder = null)
{
    global $Config;
    $sParent = GetParentFolder($folderPath);
    // Ensure the folder path has no double-slashes, or mkdir may fail on certain platforms
    while (strpos($folderPath, '//') !== false) {
        $folderPath = str_replace('//', '/', $folderPath);
    }
    // Check if the parent exists, or create it.
    if (!empty($sParent) && !file_exists($sParent)) {
        //prevents agains infinite loop when we can't create root folder
        if (!is_null($lastFolder) && $lastFolder === $sParent) {
            return "Can't create {$folderPath} directory";
        }
        $sErrorMsg = CreateServerFolder($sParent, $folderPath);
        if ($sErrorMsg != '') {
            return $sErrorMsg;
        }
    }
    if (!file_exists($folderPath)) {
        // Turn off all error reporting.
        error_reporting(0);
        $php_errormsg = '';
        // Enable error tracking to catch the error.
        ini_set('track_errors', '1');
        if (isset($Config['ChmodOnFolderCreate']) && !$Config['ChmodOnFolderCreate']) {
            mkdir($folderPath);
        } else {
            $permissions = 0777;
            // $permissions = 0770 ;
            if (isset($Config['ChmodOnFolderCreate'])) {
                $permissions = $Config['ChmodOnFolderCreate'];
            }
            // To create the folder with 0777 permissions, we need to set umask to zero.
            //$oldumask = umask(0) ;
            mkdir($folderPath, $permissions);
            //umask( $oldumask ) ;
        }
        // While we are in a course: Registering the newly created folder in the course's database.
        if (api_is_in_course()) {
            global $_course, $_user;
            $repository_path = api_get_path(REL_COURSE_PATH) . api_get_course_path() . '/document/';
            $to_group_id = 0;
            if (api_is_in_group()) {
                global $group_properties;
                $to_group_id = $group_properties['id'];
            }
            $folder_path = preg_replace("/^.*" . TOOL_DOCUMENT . "/", "", $folderPath);
            //
            $folder_path = preg_replace("/\\/\$/", "", $folder_path);
            // should be done in 1 regexp I guess ...
            // $folder_path = substr($folderPath, strpos($folderPath, $repository_path) + strlen($repository_path) - 1);
            $folder_name = explode('/', $folder_path);
            $folder_name = $folder_name[count($folder_name) - 1];
            $doc_id = add_document($_course, $folder_path, 'folder', 0, $folder_name);
            api_item_property_update($_course, TOOL_DOCUMENT, $doc_id, 'FolderCreated', $_user['user_id'], $to_group_id);
        }
        $sErrorMsg = $php_errormsg;
        // Restore the configurations.
        ini_restore('track_errors');
        ini_restore('error_reporting');
        return $sErrorMsg;
    } else {
        return '';
    }
}
Пример #19
0
        //include needed librabries for treatment
        $result_log = import_exercise($_FILES['uploadedExercise']['name']);
        //display the result message (fail or success)
        $dialogBox = '';
        foreach ($result_log as $log) {
            $dialogBox .= $log . '<br>';
        }
        break;
}
//----------------------------------
// FIND INFORMATION
//----------------------------------
//empty!
//----------------------------------
// DISPLAY
//----------------------------------
include api_get_path(INCLUDE_PATH) . '/header.inc.php';
//display title
// Tool introduction
// TODO: These settings to be checked when it is possible.
Display::display_introduction_section(TOOL_QUIZ, array('CreateDocumentWebDir' => api_get_path(WEB_COURSE_PATH) . api_get_course_path() . '/document/', 'CreateDocumentDir' => '../../../courses/' . api_get_course_path() . '/document/', 'BaseHref' => api_get_path(WEB_COURSE_PATH) . api_get_course_path() . '/'));
//Display Forms or dialog box(if needed)
if (isset($dialogBox)) {
    echo Display::display_normal_message($dialogBox, false);
}
//display content
if (isset($display)) {
    echo $display;
}
//footer display
include api_get_path(INCLUDE_PATH) . '/footer.inc.php';
Пример #20
0
if (isset($_GET['curdirpath']) && $_GET['curdirpath'] == '/certificates' && isset($_GET['set_preview']) && $_GET['set_preview'] == strval(intval($_GET['set_preview']))) {
    if (isset($_GET['set_preview'])) {
        // Generate document HTML
        $content_html = DocumentManager::replace_user_info_into_html(api_get_user_id(), api_get_course_id(), api_get_session_id(), true);
        $filename = 'certificate_preview/' . api_get_unique_id() . '.png';
        $qr_code_filename = api_get_path(SYS_ARCHIVE_PATH) . $filename;
        $temp_folder = api_get_path(SYS_ARCHIVE_PATH) . 'certificate_preview';
        if (!is_dir($temp_folder)) {
            mkdir($temp_folder, api_get_permissions_for_new_directories());
        }
        $qr_code_web_filename = api_get_path(WEB_ARCHIVE_PATH) . $filename;
        $certificate = new Certificate();
        $text = $certificate->parse_certificate_variables($content_html['variables']);
        $result = $certificate->generate_qr($text, $qr_code_filename);
        $new_content_html = $content_html['content'];
        $path_image = api_get_path(WEB_COURSE_PATH) . api_get_course_path() . '/document/images/gallery';
        $new_content_html = str_replace('../images/gallery', $path_image, $new_content_html);
        $path_image_in_default_course = api_get_path(WEB_CODE_PATH) . 'default_course_document';
        $new_content_html = str_replace('/main/default_course_document', $path_image_in_default_course, $new_content_html);
        $new_content_html = str_replace(SYS_CODE_PATH . 'img/', api_get_path(WEB_IMG_PATH), $new_content_html);
        Display::display_reduced_header();
        echo '<style>body {background:none;}</style>
              <style media="print" type="text/css"> #print_div { visibility:hidden; } </style>';
        echo '<a href="javascript:window.print();" style="float:right; padding:4px;" id="print_div">
              <img src="../img/printmgr.gif" alt="' . get_lang('Print') . '"/>' . get_lang('Print') . '</a>';
        if (is_file($qr_code_filename) && is_readable($qr_code_filename)) {
            $new_content_html = str_replace('((certificate_barcode))', Display::img($qr_code_web_filename), $new_content_html);
        }
        print_r($new_content_html);
        exit;
    }
Пример #21
0
     if ($forum['forum_of_group'] == '0') {
         $show_forum = true;
     } else {
         $show_forum = GroupManager::user_has_access($user_id, $forum['forum_of_group'], GroupManager::GROUP_TOOL_FORUM);
     }
 }
 if ($show_forum) {
     $form_count++;
     $mywhatsnew_post_info = isset($whatsnew_post_info[$forum['forum_id']]) ? $whatsnew_post_info[$forum['forum_id']] : null;
     $html = '<div class="panel panel-default forum">';
     $html .= '<div class="panel-body">';
     $forum_image = '';
     $imgForum = '';
     // Showing the image
     if (!empty($forum['forum_image'])) {
         $image_path = api_get_path(WEB_COURSE_PATH) . api_get_course_path() . '/upload/forum/images/' . $forum['forum_image'];
         $image_size = api_getimagesize($image_path);
         $img_attributes = '';
         if (!empty($image_size)) {
             //limit display width and height to 100px
             $img_attributes = ' style="width:80px" height="80px"';
             $imgForum = "<img src=\"{$image_path}\" {$img_attributes}>";
         } else {
             $imgForum = '';
         }
         $forum_image = $imgForum;
     } else {
         if ($forum['forum_of_group'] == '0') {
             $forum_image = Display::return_icon('forum_group.png', get_lang('GroupForum'), null, ICON_SIZE_LARGE);
         } else {
             $forum_image = Display::return_icon('forum.png', get_lang('Forum'), null, ICON_SIZE_LARGE);
Пример #22
0
 /**
  * @param $user_id
  * @param $course_code
  * @param bool $is_preview
  * @param bool $hide_print_button
  * @return array
  */
 public static function get_user_certificate_content($user_id, $course_code, $is_preview = false, $hide_print_button = false)
 {
     // Generate document HTML
     $content_html = DocumentManager::replace_user_info_into_html($user_id, $course_code, $is_preview);
     $new_content_html = null;
     $variables = null;
     $contentHead = null;
     if (isset($content_html['content'])) {
         $new_content = explode('</head>', $content_html['content']);
         $new_content_html = $new_content[1];
         $contentHead = $new_content[0];
     }
     if (isset($content_html['variables'])) {
         $variables = $content_html['variables'];
     }
     $path_image = api_get_path(WEB_COURSE_PATH) . api_get_course_path($course_code) . '/document/images/gallery';
     $new_content_html = str_replace('../images/gallery', $path_image, $new_content_html);
     $path_image_in_default_course = api_get_path(WEB_CODE_PATH) . 'default_course_document';
     $new_content_html = str_replace('/main/default_course_document', $path_image_in_default_course, $new_content_html);
     $new_content_html = str_replace(SYS_CODE_PATH . 'img/', api_get_path(WEB_IMG_PATH), $new_content_html);
     //add print header
     if ($hide_print_button == false) {
         $print = '<style media="print" type="text/css">#print_div {visibility:hidden;}</style>';
         $print .= '<a href="javascript:window.print();" style="float:right; padding:4px;" id="print_div"><img src="' . api_get_path(WEB_CODE_PATH) . 'img/printmgr.gif" alt="' . get_lang('Print') . '" /> ' . get_lang('Print') . '</a>';
     }
     // Add header
     $new_content_html = $contentHead . $print . '</head>' . $new_content_html;
     return array('content' => $new_content_html, 'variables' => $variables);
 }
Пример #23
0
}
$course_id = api_get_course_int_id();
if ($audio_recorder_studentview == 'false') {
    $width = 295;
    $height = 90;
    $player = 'recorder2.swf';
    $server = (api_get_setting('service_visio', 'visio_use_rtmpt') == 'true' ? 'rtmpt://' : 'rtmp://') . api_get_setting('service_visio', 'visio_host') . ':' . (api_get_setting('service_visio', 'visio_use_rtmpt') == 'true' ? '80' : api_get_setting('service_visio', 'visio_port')) . '/recorder';
    $post_uri = urlencode($web_path . 'conference/audiopost.php?course_code=' . api_get_course_id() . '&user_id=' . api_get_user_id() . '&checker=' . md5(api_get_course_id() . api_get_user_id() . gmdate('Ymd')));
    $filename = 'lpi' . $audio_recorder_item_id . '-' . gmdate('YmdHis') . api_get_user_id() . '.flv';
    // Using -z- as fields splitter.
    $path_to_lzx = $web_path . 'conference/' . $player . '?server=' . urlencode($server) . '&postURI=' . $post_uri . '&filename=' . $filename;
} else {
    $width = 295;
    $height = 24;
    $player = 'player2.swf';
    $cp = api_get_course_path();
    $docs = Database::get_course_table(TABLE_DOCUMENT);
    $select = "SELECT * FROM {$docs} " . " WHERE c_id = {$course_id} AND path like BINARY '/audio/lpi" . intval($audio_recorder_item_id) . "-%' AND filetype='file' " . " ORDER BY path DESC";
    $res = Database::query($select);
    if (Database::num_rows($res) > 0) {
        $row = Database::fetch_array($res);
        //$filepath = api_get_path(WEB_COURSE_PATH).$cp.'/document'.$row['path'];
        $duration = getFLVDuration(api_get_path(SYS_COURSE_PATH) . $cp . '/document' . $row['path']);
        $filepath = api_get_path(WEB_CODE_PATH) . 'document/download.php?' . api_get_cidreq() . '&doc_url=' . $row['path'];
        $path_to_lzx = $web_path . 'conference/' . $player . '?uri=' . urlencode($filepath) . '&autostart=true&duration=' . $duration;
    }
}
if (!empty($path_to_lzx)) {
    $recorder_content = sprintf("<object type=\"application/x-shockwave-flash\" data=\"%s\" " . "width='{$width}' height='{$height}'>" . "<param name=\"movie\" value=\"%s\">" . "<param name=\"quality\" value=\"high\">" . "<param name=\"scale\" value=\"noscale\">" . "<param name=\"salign\" value=\"LT\">" . "<param name=\"menu\" value=\"false\"></object>", $path_to_lzx, $path_to_lzx);
    if ($audio_recorder_studentview == 'false') {
        echo '<script type="text/javascript">
Пример #24
0
/**
 * This function deletes the forum image if exists
 *
 * @param int forum id
 * @return boolean true if success
 * @author Julio Montoya <*****@*****.**>
 * @version february 2006, dokeos 1.8
 */
function delete_forum_image($forum_id)
{
    $table_forums = Database::get_course_table(TABLE_FORUM);
    $course_id = api_get_course_int_id();
    $forum_id = intval($forum_id);
    $sql = "SELECT forum_image FROM {$table_forums}\n            WHERE forum_id = '" . $forum_id . "' AND c_id = {$course_id}";
    $result = Database::query($sql);
    $row = Database::fetch_array($result);
    if ($row['forum_image'] != '') {
        $del_file = api_get_path(SYS_COURSE_PATH) . api_get_course_path() . '/upload/forum/images/' . $row['forum_image'];
        return @unlink($del_file);
    } else {
        return false;
    }
}
     require 'lp_message.php';
     break;
 case 'return_to_course_homepage':
     if (!$lp_found) {
         error_log('New LP - No learnpath given for stats', 0);
         require 'lp_list.php';
     } else {
         $_SESSION['oLP']->save_current();
         $_SESSION['oLP']->save_last();
         //declare variables to be used in lp_stats.php
         $lp_id = $_SESSION['oLP']->get_id();
         $list = $_SESSION['oLP']->get_flat_ordered_items_list($lp_id);
         $user_id = api_get_user_id();
         $stats_charset = $_SESSION['oLP']->encoding;
         //header('location: ../course_home/course_home.php?'.api_get_cidreq()); // This is not the preferable way to go to the homepage.
         header('location: ' . api_get_path(WEB_COURSE_PATH) . api_get_course_path() . '/index.php');
     }
     break;
 case 'search':
     /* Include the search script, it's smart enough to know when we are
      * searching or not
      */
     require 'lp_list_search.php';
     break;
 default:
     if ($debug > 0) {
         error_log('New LP - default action triggered', 0);
     }
     //$_SESSION['refresh'] = 1;
     require 'lp_list.php';
     break;
Пример #26
0
<?php

/* For licensing terms, see /license.txt */
/**
 * Script managing the learnpath upload. To best treat the uploaded file, make sure we can identify it.
 * @package chamilo.learnpath
 * @author Yannick Warnier <*****@*****.**>
 */
// Flag to allow for anonymous user - needs to be set before global.inc.php.
$use_anonymous = true;
//require_once '../inc/global.inc.php';
$course_dir = api_get_course_path() . '/scorm';
$course_sys_dir = api_get_path(SYS_COURSE_PATH) . $course_dir;
if (empty($_POST['current_dir'])) {
    $current_dir = '';
} else {
    $current_dir = api_replace_dangerous_char(trim($_POST['current_dir']));
}
$uncompress = 1;
/*
 * Check the request method in place of a variable from POST
 * because if the file size exceed the maximum file upload
 * size set in php.ini, all variables from POST are cleared !
 */
$user_file = isset($_GET['user_file']) ? $_GET['user_file'] : array();
$user_file = $user_file ? $user_file : array();
$is_error = isset($user_file['error']) ? $user_file['error'] : false;
if (isset($_POST) && $is_error) {
    throw new \Exception(get_lang('UplFileTooBig'));
    unset($_FILES['user_file']);
} else {
Пример #27
0
    if (!empty($mycourselptheme) && $mycourselptheme != -1 && $mycourselptheme == 1) {
        //LP theme picker
        $theme_select = $form->addElement('select_theme', 'lp_theme', get_lang('Theme'));
        $form->applyFilter('lp_theme', 'trim');
        $s_theme = $_SESSION['oLP']->get_theme();
        $theme_select->setSelected($s_theme);
        //default
    }
}
// Author
$form->addElement('html_editor', 'lp_author', get_lang('Author'), array('size' => 80), array('ToolbarSet' => 'LearningPathAuthor', 'Width' => '100%', 'Height' => '150px'));
$form->applyFilter('lp_author', 'html_filter');
// LP image
$form->add_progress_bar();
if (strlen($_SESSION['oLP']->get_preview_image()) > 0) {
    $show_preview_image = '<img src=' . api_get_path(WEB_COURSE_PATH) . api_get_course_path() . '/upload/learning_path/images/' . $_SESSION['oLP']->get_preview_image() . '>';
    $form->addElement('label', get_lang('ImagePreview'), $show_preview_image);
    $form->addElement('checkbox', 'remove_picture', null, get_lang('DelImage'));
}
$label = $_SESSION['oLP']->get_preview_image() != '' ? get_lang('UpdateImage') : get_lang('AddImage');
$form->addElement('file', 'lp_preview_image', array($label, get_lang('ImageWillResizeMsg')));
$form->addRule('lp_preview_image', get_lang('OnlyImagesAllowed'), 'filetype', array('jpg', 'jpeg', 'png', 'gif'));
// Search terms (only if search is activated).
if (api_get_setting('search_enabled') === 'true') {
    $specific_fields = get_specific_field_list();
    foreach ($specific_fields as $specific_field) {
        $form->addElement('text', $specific_field['code'], $specific_field['name']);
        $filter = array('c_id' => "'" . api_get_course_int_id() . "'", 'field_id' => $specific_field['id'], 'ref_id' => $_SESSION['oLP']->lp_id, 'tool_id' => '\'' . TOOL_LEARNPATH . '\'');
        $values = get_specific_field_values_list($filter, array('value'));
        if (!empty($values)) {
            $arr_str_values = array();
 /**
  * Gets the list of included resources as a list of absolute or relative paths of
  * resources included in the current item. This allows for a better SCORM export.
  * The list will generally include pictures, flash objects, java applets, or any other
  * stuff included in the source of the current item. The current item is expected
  * to be an HTML file. If it is not, then the function will return and empty list.
  * @param    string    type (one of the Chamilo tools) - optional (otherwise takes the current item's type)
  * @param    string    path (absolute file path) - optional (otherwise takes the current item's path)
  * @param    int        level of recursivity we're in
  * @return    array    List of file paths. An additional field containing 'local' or 'remote' helps determine if the file should be copied into the zip or just linked
  */
 public function get_resources_from_source($type = null, $abs_path = null, $recursivity = 1)
 {
     $max = 5;
     if ($recursivity > $max) {
         return array();
     }
     if (!isset($type)) {
         $type = $this->get_type();
     }
     if (!isset($abs_path)) {
         $path = $this->get_file_path();
         $abs_path = api_get_path(SYS_COURSE_PATH) . api_get_course_path() . '/' . $path;
         //echo "Abs path coming from item : ".$abs_path."<br />\n";
     }
     /*
      else {
      echo "Abs path coming from param: ".$abs_path."<br />\n";
      }
     */
     //error_log(str_repeat(' ',$recursivity).'Analyse file '.$abs_path, 0);
     $files_list = array();
     $type = $this->get_type();
     switch ($type) {
         case TOOL_DOCUMENT:
         case TOOL_QUIZ:
         case 'sco':
             // Get the document and, if HTML, open it.
             if (is_file($abs_path)) {
                 // for now, read the whole file in one go (that's gonna be a problem when the file is too big).
                 $info = pathinfo($abs_path);
                 $ext = $info['extension'];
                 switch (strtolower($ext)) {
                     case 'html':
                     case 'htm':
                     case 'shtml':
                     case 'css':
                         $wanted_attributes = array('src', 'url', '@import', 'href', 'value');
                         // Parse it for included resources.
                         $file_content = file_get_contents($abs_path);
                         // Get an array of attributes from the HTML source.
                         $attributes = DocumentManager::parse_HTML_attributes($file_content, $wanted_attributes);
                         // Look at 'src' attributes in this file
                         foreach ($wanted_attributes as $attr) {
                             if (isset($attributes[$attr])) {
                                 // Find which kind of path these are (local or remote).
                                 $sources = $attributes[$attr];
                                 foreach ($sources as $source) {
                                     // Skip what is obviously not a resource.
                                     if (strpos($source, "+this.")) {
                                         continue;
                                     }
                                     // javascript code - will still work unaltered.
                                     if (strpos($source, '.') === false) {
                                         continue;
                                     }
                                     // No dot, should not be an external file anyway.
                                     if (strpos($source, 'mailto:')) {
                                         continue;
                                     }
                                     // mailto link.
                                     if (strpos($source, ';') && !strpos($source, '&amp;')) {
                                         continue;
                                     }
                                     // Avoid code - that should help.
                                     if ($attr == 'value') {
                                         if (strpos($source, 'mp3file')) {
                                             $files_list[] = array(substr($source, 0, strpos($source, '.swf') + 4), 'local', 'abs');
                                             $mp3file = substr($source, strpos($source, 'mp3file=') + 8);
                                             if (substr($mp3file, 0, 1) == '/') {
                                                 $files_list[] = array($mp3file, 'local', 'abs');
                                             } else {
                                                 $files_list[] = array($mp3file, 'local', 'rel');
                                             }
                                         } elseif (strpos($source, 'flv=') === 0) {
                                             $source = substr($source, 4);
                                             if (strpos($source, '&') > 0) {
                                                 $source = substr($source, 0, strpos($source, '&'));
                                             }
                                             if (strpos($source, '://') > 0) {
                                                 if (strpos($source, api_get_path(WEB_PATH)) !== false) {
                                                     // We found the current portal url.
                                                     $files_list[] = array($source, 'local', 'url');
                                                 } else {
                                                     // We didn't find any trace of current portal.
                                                     $files_list[] = array($source, 'remote', 'url');
                                                 }
                                             } else {
                                                 $files_list[] = array($source, 'local', 'abs');
                                             }
                                             continue;
                                             // Skipping anything else to avoid two entries (while the others can have sub-files in their url, flv's can't).
                                         }
                                     }
                                     if (strpos($source, '://') > 0) {
                                         // Cut at '?' in a URL with params.
                                         if (strpos($source, '?') > 0) {
                                             $second_part = substr($source, strpos($source, '?'));
                                             if (strpos($second_part, '://') > 0) {
                                                 // If the second part of the url contains a url too, treat the second one before cutting.
                                                 $pos1 = strpos($second_part, '=');
                                                 $pos2 = strpos($second_part, '&');
                                                 $second_part = substr($second_part, $pos1 + 1, $pos2 - ($pos1 + 1));
                                                 if (strpos($second_part, api_get_path(WEB_PATH)) !== false) {
                                                     // We found the current portal url.
                                                     $files_list[] = array($second_part, 'local', 'url');
                                                     $in_files_list[] = learnpathItem::get_resources_from_source(TOOL_DOCUMENT, $second_part, $recursivity + 1);
                                                     if (count($in_files_list) > 0) {
                                                         $files_list = array_merge($files_list, $in_files_list);
                                                     }
                                                 } else {
                                                     // We didn't find any trace of current portal.
                                                     $files_list[] = array($second_part, 'remote', 'url');
                                                 }
                                             } elseif (strpos($second_part, '=') > 0) {
                                                 if (substr($second_part, 0, 1) === '/') {
                                                     // Link starts with a /, making it absolute (relative to DocumentRoot).
                                                     $files_list[] = array($second_part, 'local', 'abs');
                                                     $in_files_list[] = learnpathItem::get_resources_from_source(TOOL_DOCUMENT, $second_part, $recursivity + 1);
                                                     if (count($in_files_list) > 0) {
                                                         $files_list = array_merge($files_list, $in_files_list);
                                                     }
                                                 } elseif (strstr($second_part, '..') === 0) {
                                                     // Link is relative but going back in the hierarchy.
                                                     $files_list[] = array($second_part, 'local', 'rel');
                                                     $dir = dirname($abs_path);
                                                     $new_abs_path = realpath($dir . '/' . $second_part);
                                                     $in_files_list[] = learnpathItem::get_resources_from_source(TOOL_DOCUMENT, $new_abs_path, $recursivity + 1);
                                                     if (count($in_files_list) > 0) {
                                                         $files_list = array_merge($files_list, $in_files_list);
                                                     }
                                                 } else {
                                                     // No starting '/', making it relative to current document's path.
                                                     if (substr($second_part, 0, 2) == './') {
                                                         $second_part = substr($second_part, 2);
                                                     }
                                                     $files_list[] = array($second_part, 'local', 'rel');
                                                     $dir = dirname($abs_path);
                                                     $new_abs_path = realpath($dir . '/' . $second_part);
                                                     $in_files_list[] = learnpathItem::get_resources_from_source(TOOL_DOCUMENT, $new_abs_path, $recursivity + 1);
                                                     if (count($in_files_list) > 0) {
                                                         $files_list = array_merge($files_list, $in_files_list);
                                                     }
                                                 }
                                             }
                                             // Leave that second part behind now.
                                             $source = substr($source, 0, strpos($source, '?'));
                                             if (strpos($source, '://') > 0) {
                                                 if (strpos($source, api_get_path(WEB_PATH)) !== false) {
                                                     // We found the current portal url.
                                                     $files_list[] = array($source, 'local', 'url');
                                                     $in_files_list[] = learnpathItem::get_resources_from_source(TOOL_DOCUMENT, $source, $recursivity + 1);
                                                     if (count($in_files_list) > 0) {
                                                         $files_list = array_merge($files_list, $in_files_list);
                                                     }
                                                 } else {
                                                     // We didn't find any trace of current portal.
                                                     $files_list[] = array($source, 'remote', 'url');
                                                 }
                                             } else {
                                                 // No protocol found, make link local.
                                                 if (substr($source, 0, 1) === '/') {
                                                     // Link starts with a /, making it absolute (relative to DocumentRoot).
                                                     $files_list[] = array($source, 'local', 'abs');
                                                     $in_files_list[] = learnpathItem::get_resources_from_source(TOOL_DOCUMENT, $source, $recursivity + 1);
                                                     if (count($in_files_list) > 0) {
                                                         $files_list = array_merge($files_list, $in_files_list);
                                                     }
                                                 } elseif (strstr($source, '..') === 0) {
                                                     // Link is relative but going back in the hierarchy.
                                                     $files_list[] = array($source, 'local', 'rel');
                                                     $dir = dirname($abs_path);
                                                     $new_abs_path = realpath($dir . '/' . $source);
                                                     $in_files_list[] = learnpathItem::get_resources_from_source(TOOL_DOCUMENT, $new_abs_path, $recursivity + 1);
                                                     if (count($in_files_list) > 0) {
                                                         $files_list = array_merge($files_list, $in_files_list);
                                                     }
                                                 } else {
                                                     // No starting '/', making it relative to current document's path.
                                                     if (substr($source, 0, 2) == './') {
                                                         $source = substr($source, 2);
                                                     }
                                                     $files_list[] = array($source, 'local', 'rel');
                                                     $dir = dirname($abs_path);
                                                     $new_abs_path = realpath($dir . '/' . $source);
                                                     $in_files_list[] = learnpathItem::get_resources_from_source(TOOL_DOCUMENT, $new_abs_path, $recursivity + 1);
                                                     if (count($in_files_list) > 0) {
                                                         $files_list = array_merge($files_list, $in_files_list);
                                                     }
                                                 }
                                             }
                                         }
                                         // Found some protocol there.
                                         if (strpos($source, api_get_path(WEB_PATH)) !== false) {
                                             // We found the current portal url.
                                             $files_list[] = array($source, 'local', 'url');
                                             $in_files_list[] = learnpathItem::get_resources_from_source(TOOL_DOCUMENT, $source, $recursivity + 1);
                                             if (count($in_files_list) > 0) {
                                                 $files_list = array_merge($files_list, $in_files_list);
                                             }
                                         } else {
                                             // We didn't find any trace of current portal.
                                             $files_list[] = array($source, 'remote', 'url');
                                         }
                                     } else {
                                         // No protocol found, make link local.
                                         if (substr($source, 0, 1) === '/') {
                                             // Link starts with a /, making it absolute (relative to DocumentRoot).
                                             $files_list[] = array($source, 'local', 'abs');
                                             $in_files_list[] = learnpathItem::get_resources_from_source(TOOL_DOCUMENT, $source, $recursivity + 1);
                                             if (count($in_files_list) > 0) {
                                                 $files_list = array_merge($files_list, $in_files_list);
                                             }
                                         } elseif (strstr($source, '..') === 0) {
                                             // Link is relative but going back in the hierarchy.
                                             $files_list[] = array($source, 'local', 'rel');
                                             $dir = dirname($abs_path);
                                             $new_abs_path = realpath($dir . '/' . $source);
                                             $in_files_list[] = learnpathItem::get_resources_from_source(TOOL_DOCUMENT, $new_abs_path, $recursivity + 1);
                                             if (count($in_files_list) > 0) {
                                                 $files_list = array_merge($files_list, $in_files_list);
                                             }
                                         } else {
                                             // No starting '/', making it relative to current document's path.
                                             if (strpos($source, 'width=') || strpos($source, 'autostart=')) {
                                                 continue;
                                             }
                                             if (substr($source, 0, 2) == './') {
                                                 $source = substr($source, 2);
                                             }
                                             $files_list[] = array($source, 'local', 'rel');
                                             $dir = dirname($abs_path);
                                             $new_abs_path = realpath($dir . '/' . $source);
                                             $in_files_list[] = learnpathItem::get_resources_from_source(TOOL_DOCUMENT, $new_abs_path, $recursivity + 1);
                                             if (count($in_files_list) > 0) {
                                                 $files_list = array_merge($files_list, $in_files_list);
                                             }
                                         }
                                     }
                                 }
                             }
                         }
                         break;
                     default:
                         break;
                 }
             } else {
                 // The file could not be found.
                 return false;
             }
             break;
         default:
             // Ignore.
             break;
     }
     //error_log(str_repeat(' ', $recursivity), 'found files '.print_r($files_list, true), 0);
     //return $files_list;
     $checked_files_list = array();
     $checked_array_list = array();
     foreach ($files_list as $idx => $file) {
         if (!empty($file[0])) {
             if (!in_array($file[0], $checked_files_list)) {
                 $checked_files_list[] = $files_list[$idx][0];
                 $checked_array_list[] = $files_list[$idx];
             }
         }
     }
     return $checked_array_list;
 }
Пример #29
0
    $group_properties = GroupManager::get_group_properties($groupId);
    // Level correction for group documents.
    if (!empty($group_properties['directory'])) {
        $count_dir = $count_dir > 0 ? $count_dir - 1 : 0;
    }
}
$relative_url = '';
for ($i = 0; $i < $count_dir; $i++) {
    $relative_url .= '../';
}
// We do this in order to avoid the condition in html_editor.php ==> if ($this -> fck_editor->Config['CreateDocumentWebDir']=='' || $this -> fck_editor->Config['CreateDocumentDir']== '')
if ($relative_url == '') {
    $relative_url = '/';
}
$is_allowed_to_edit = api_is_allowed_to_edit(null, true);
$html_editor_config = array('ToolbarSet' => $is_allowed_to_edit ? 'Documents' : 'DocumentsStudent', 'Width' => '100%', 'Height' => '500', 'FullPage' => true, 'InDocument' => true, 'CreateDocumentDir' => $relative_url, 'CreateDocumentWebDir' => empty($group_properties['directory']) ? api_get_path(WEB_COURSE_PATH) . $_course['path'] . '/document/' : api_get_path(WEB_COURSE_PATH) . api_get_course_path() . '/document' . $group_properties['directory'] . '/', 'BaseHref' => api_get_path(WEB_COURSE_PATH) . $_course['path'] . '/document' . $dir);
if ($is_certificate_mode) {
    $html_editor_config['CreateDocumentDir'] = api_get_path(WEB_COURSE_PATH) . $_course['path'] . '/document/';
    $html_editor_config['CreateDocumentWebDir'] = api_get_path(WEB_COURSE_PATH) . $_course['path'] . '/document/';
    $html_editor_config['BaseHref'] = api_get_path(WEB_COURSE_PATH) . $_course['path'] . '/document' . $dir;
}
$filepath = api_get_path(SYS_COURSE_PATH) . $_course['path'] . '/document' . $dir;
if (!is_dir($filepath)) {
    $filepath = api_get_path(SYS_COURSE_PATH) . $_course['path'] . '/document/';
    $dir = '/';
}
if (!$is_certificate_mode) {
    $req_gid = null;
    if (api_is_in_group()) {
        $req_gid = '&amp;gidReq=' . $groupId;
        $interbreadcrumb[] = array("url" => "../group/group_space.php?gidReq=" . $groupId, "name" => get_lang('GroupSpace'));
Пример #30
0
function FileUpload($resourceType, $currentFolder, $sCommand)
{
    if (!isset($_FILES)) {
        global $_FILES;
    }
    $sErrorNumber = '0';
    $sFileName = '';
    if (isset($_FILES['NewFile']) && !is_null($_FILES['NewFile']['tmp_name'])) {
        global $Config;
        $oFile = $_FILES['NewFile'];
        // Map the virtual path to the local server path.
        $sServerDir = ServerMapFolder($resourceType, $currentFolder, $sCommand);
        // Get the uploaded file name.
        $sFileName = $oFile['name'];
        $sFileName = SanitizeFileName($sFileName, $oFile['type']);
        $sOriginalFileName = $sFileName;
        // Get the extension.
        $sExtension = substr($sFileName, strrpos($sFileName, '.') + 1);
        $sExtension = strtolower($sExtension);
        if (isset($Config['SecureImageUploads'])) {
            if (($isImageValid = IsImageValid($oFile['tmp_name'], $sExtension)) === false) {
                $sErrorNumber = '202';
            }
        }
        if (isset($Config['HtmlExtensions'])) {
            if (!IsHtmlExtension($sExtension, $Config['HtmlExtensions']) && ($detectHtml = DetectHtml($oFile['tmp_name'])) === true) {
                $sErrorNumber = '202';
            }
        }
        // Check if it is an allowed extension.
        if (!$sErrorNumber && IsAllowedExt($sExtension, $resourceType)) {
            $iCounter = 0;
            while (true) {
                $sFilePath = $sServerDir . $sFileName;
                if (is_file($sFilePath)) {
                    $iCounter++;
                    $sFileName = RemoveExtension($sOriginalFileName) . '(' . $iCounter . ').' . $sExtension;
                    $sErrorNumber = '0';
                    // Change $sErrorNumber '201' to '0' to allow create record files renamed
                } else {
                    move_uploaded_file($oFile['tmp_name'], $sFilePath);
                    if (is_file($sFilePath)) {
                        if (isset($Config['ChmodOnUpload']) && !$Config['ChmodOnUpload']) {
                            break;
                        }
                        $permissions = 0777;
                        if (isset($Config['ChmodOnUpload']) && $Config['ChmodOnUpload']) {
                            $permissions = $Config['ChmodOnUpload'];
                        }
                        //$oldumask = umask(0) ;
                        chmod($sFilePath, $permissions);
                        //umask( $oldumask ) ;
                    }
                    break;
                }
            }
            if (file_exists($sFilePath)) {
                //previous checks failed, try once again
                if (isset($isImageValid) && $isImageValid === -1 && IsImageValid($sFilePath, $sExtension) === false) {
                    @unlink($sFilePath);
                    $sErrorNumber = '202';
                } else {
                    if (isset($detectHtml) && $detectHtml === -1 && DetectHtml($sFilePath) === true) {
                        @unlink($sFilePath);
                        $sErrorNumber = '202';
                    }
                }
            }
        } else {
            $sErrorNumber = '202';
        }
    } else {
        $sErrorNumber = '202';
    }
    if ($sErrorNumber == '0') {
        // While we are in a course: Registering the newly uploaded file in the course's database.
        if (api_is_in_course()) {
            global $_course, $_user;
            $repository_path = api_get_path(REL_COURSE_PATH) . api_get_course_path() . '/document/';
            $to_group_id = 0;
            if (api_is_in_group()) {
                global $group_properties;
                $to_group_id = $group_properties['id'];
            }
            if (file_exists($sFilePath)) {
                $file_path = substr($sFilePath, strpos($sFilePath, $repository_path) + strlen($repository_path) - 1);
                $path = explode('/', $file_path);
                $file_name = $path[count($path) - 1];
                $path[count($path) - 1] = '';
                $folder_path = '/' + implode('/', $path);
                $file_size = @filesize($sFilePath);
                $doc_id = add_document($_course, $file_path, 'file', $file_size, $file_name);
                api_item_property_update($_course, TOOL_DOCUMENT, $doc_id, 'DocumentAdded', $_user['user_id'], $to_group_id);
                item_property_update_on_folder($_course, $folder_path, $_user['user_id']);
            }
        }
    }
    $sFileUrl = CombinePaths(GetResourceTypePath($resourceType, $sCommand), $currentFolder);
    $sFileUrl = CombinePaths($sFileUrl, $sFileName);
    SendUploadResults($sErrorNumber, $sFileUrl, $sFileName);
    exit;
}