Пример #1
0
}

$iterator = 0;

if (!isset($_REQUEST['maxDocForm'])) {
    $_REQUEST['maxDocForm'] = 0;
}

while ($iterator <= $_REQUEST['maxDocForm']) {
    $iterator++;
    if (isset($_REQUEST['submitInsertedDocument']) && isset($_POST['insertDocument_' . $iterator])) {
        $insertDocument = str_replace('..', '', $_POST['insertDocument_' . $iterator]);
        $filenameDocument = $_POST['filenameDocument_' . $iterator];
        $sourceDoc = $baseWorkDir . $insertDocument;

        if (check_name_exist($sourceDoc)) { // source file exists ?
            // check if a module of this course already used the same document
            $sql = "SELECT *
                    FROM `lp_module` AS M, `lp_asset` AS A
                    WHERE A.`module_id` = M.`module_id`
                      AND A.`path` LIKE ?s
                      AND M.`contentType` = ?s
                      AND M.`course_id` = ?d";
            $thisDocumentModule = Database::get()->queryArray($sql, $insertDocument, CTDOCUMENT_, $course_id);
            $num = count($thisDocumentModule);
            $basename = substr($insertDocument, strrpos($insertDocument, '/') + 1);

            if ($num == 0) {
                // create new module
                $insertedModule_id = Database::get()->query("INSERT INTO `lp_module`
                        (`course_id`, `name` , `comment`, `contentType`, `launch_data`)
Пример #2
0
/**
 * Moves a file or a directory to an other area
 *
 * @author - Hugues Peeters <*****@*****.**>
 * @param  - $source (String) - the path of file or directory to move
 * @param  - $target (String) - the path of the new area
 * @param  bool $forceMove Whether to force a move or to make a copy (safer but slower) and then delete the original
 * @return - bolean - true if the move succeed
 *           bolean - false otherwise.
 * @see    - move() uses check_name_exist() and copyDirTo() functions
 */
function move($source, $target, $forceMove = false)
{
    if (check_name_exist($source)) {
        $file_name = basename($source);
        /* File case */
        if (is_file($source)) {
            if ($forceMove) {
                rename($source, $target . '/' . $file_name);
            } else {
                copy($source, $target . '/' . $file_name);
                unlink($source);
            }
            return true;
        } elseif (is_dir($source)) {
            /* Directory */
            if ($forceMove) {
                rename($source, $target);
            } else {
                copyDirTo($source, $target);
            }
            return true;
        }
    } else {
        return false;
    }
}
Пример #3
0
 // end if cmd == rqEdit
 /*= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
                             CREATE DIRECTORY
   = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = */
 /*
  * The code begin with STEP 2
  * so it allows to return to STEP 1
  * if STEP 2 unsucceds
  */
 /*------------------------------------------------------------------------
                                  STEP 2
   ------------------------------------------------------------------------*/
 if ('exMkDir' == $cmd) {
     $newDirName = replace_dangerous_char(trim($_REQUEST['newName']));
     $cwd = secure_file_path($cwd);
     if (check_name_exist($baseWorkDir . $cwd . '/' . $newDirName)) {
         $dialogBox->error(get_lang('A file with this name already exists.'));
         $cmd = 'rqMkDir';
     } else {
         claro_mkdir($baseWorkDir . $cwd . '/' . $newDirName, CLARO_FILE_PERMISSIONS);
         $comment = isset($_REQUEST['comment']) ? trim($_REQUEST['comment']) : '';
         if (!empty($comment) && $courseContext) {
             update_db_info('update', $cwd . '/' . $newDirName, array('comment' => $comment));
         }
         $dialogBox->success(get_lang("Directory created"));
         $eventNotifier->notifyCourseEvent("document_file_added", claro_get_current_course_id(), claro_get_current_tool_id(), $cwd . '/' . $newDirName, claro_get_current_group_id(), "0");
     }
 }
 /*------------------------------------------------------------------------
                                  STEP 1
   ------------------------------------------------------------------------*/
Пример #4
0
function claro_rename_file($oldFilePath, $newFilePath)
{
    if (realpath($oldFilePath) == realpath($newFilePath)) {
        return true;
    }
    /* CHECK IF THE NEW NAME HAS AN EXTENSION */
    if (!preg_match('/[[:print:]]+\\.[[:alnum:]]+$/', $newFilePath) and preg_match('/[[:print:]]+\\.([[:alnum:]]+)$/', $oldFilePath, $extension)) {
        $newFilePath .= '.' . $extension[1];
    }
    /* PREVENT FILE NAME WITH PHP EXTENSION */
    $newFilePath = php2phps($newFilePath);
    /* REPLACE CHARACTER POTENTIALY DANGEROUS FOR THE SYSTEM */
    $newFilePath = dirname($newFilePath) . '/' . replace_dangerous_char(my_basename($newFilePath));
    if (check_name_exist($newFilePath) && $newFilePath != $oldFilePath) {
        return false;
    } else {
        if (rename($oldFilePath, $newFilePath)) {
            return $newFilePath;
        } else {
            return false;
        }
    }
}
Пример #5
0
/**
 * Rename a file or a directory
 *
 * @param  - $filePath (string) - complete path of the file or the directory
 * @param  - $newFileName (string) - new name for the file or the directory
 * @return - string  - new file path if it succeeds
 *         - boolean - false otherwise
 * @see    - rename() uses the check_name_exist() and php2phps() functions
 */
function claro_rename_file($oldFilePath, $newFilePath)
{
    if (realpath($oldFilePath) == realpath($newFilePath)) {
        return true;
    }
    /* CHECK IF THE NEW NAME HAS AN EXTENSION */
    if (!is_dir($oldFilePath)) {
        $ext_new = get_file_extension($newFilePath);
        $ext_old = get_file_extension($oldFilePath);
        if (empty($ext_new) && !empty($ext_old)) {
            $newFilePath .= '.' . $ext_old;
        }
    }
    /* PREVENT FILE NAME WITH PHP EXTENSION */
    $newFilePath = get_secure_file_name($newFilePath);
    /* REPLACE CHARACTER POTENTIALY DANGEROUS FOR THE SYSTEM */
    $newFilePath = dirname($newFilePath) . '/' . replace_dangerous_char(basename($newFilePath));
    if (check_name_exist($newFilePath) && $newFilePath != $oldFilePath) {
        return false;
    } else {
        if (check_name_exist($oldFilePath)) {
            if (rename($oldFilePath, $newFilePath)) {
                return $newFilePath;
            } else {
                return false;
            }
        } else {
            return false;
        }
    }
}
Пример #6
0
/**
 * Install a specific module to the platform
 * @param string $modulePath path to the module
 * @param bool $skipCheckDir skip checking if module directory already exists (default false)
 * @return array( backlog, int )
 *      backlog object containing the messages
 *      int moduleId if the install process suceeded, false otherwise
 * @todo remove the need of the Backlog and use Exceptions instead
 */
function install_module($modulePath, $skipCheckDir = false, $registerModuleInCourses = false)
{
    $backlog = new Backlog();
    $moduleId = false;
    if (false === ($module_info = readModuleManifest($modulePath))) {
        claro_delete_file($modulePath);
        $backlog->failure(claro_failure::get_last_failure());
    } else {
        //check if a module with the same LABEL is already installed, if yes, we cancel everything
        // TODO extract from install function should be tested BEFORE calling install_module
        if (!$skipCheckDir && check_name_exist(get_module_path($module_info['LABEL']) . '/')) {
            $backlog->failure(get_lang('Module %module is already installed on your platform', array('%module' => $module_info['LABEL'])));
            // claro_delete_file($modulePath);
            // TODO : add code to point on existing instance of tool.
            // TODO : how to overwrite . prupose uninstall ?
        } else {
            //3- Save the module information into DB
            if (false === ($moduleId = register_module_core($module_info))) {
                claro_delete_file($modulePath);
                $backlog->failure(claro_failure::get_last_failure());
                $backlog->failure(get_lang('Module registration failed'));
            } else {
                //in case of tool type module, the dock can not be selected and must added also now
                if ('tool' == $module_info['TYPE']) {
                    // TODO FIXME handle failure
                    register_module_tool($moduleId, $module_info);
                }
                if (array_key_exists('DEFAULT_DOCK', $module_info)) {
                    foreach ($module_info['DEFAULT_DOCK'] as $dock) {
                        // TODO FIXME handle failure
                        add_module_in_dock($moduleId, $dock);
                    }
                }
                //4- Rename the module repository with label
                $currentPlace = realpath($modulePath) . '/';
                $destPath = get_module_path($module_info['LABEL']);
                claro_mkdir(get_path('rootSys') . 'module/', CLARO_FILE_PERMISSIONS, true);
                if (!@rename($currentPlace, $destPath)) {
                    $backlog->failure(get_lang("Error while renaming module folder") . ' from:' . $currentPlace . ' to:' . $destPath);
                } else {
                    // force access rights on module root dir after rename() because some modules written on M$ Win$#!t are causing issues
                    chmod($destPath, CLARO_FILE_PERMISSIONS);
                    //5-Include the local 'install.sql' and 'install.php' file of the module if they exist
                    if (isset($installSqlScript)) {
                        unset($installSqlScript);
                    }
                    $installSqlScript = get_module_path($module_info['LABEL']) . '/setup/install.sql';
                    if (file_exists($installSqlScript)) {
                        $sql = file_get_contents($installSqlScript);
                        if (!empty($sql)) {
                            $sql = str_replace('__CL_MAIN__', get_conf('mainTblPrefix'), $sql);
                            if (claro_sql_multi_query($sql) === false) {
                                $backlog->failure(get_lang('Sql installation query failed'));
                            } else {
                                $backlog->failure(get_lang('Sql installation query succeeded'));
                            }
                        }
                    }
                    // generate the conf if a def file exists
                    if (file_exists(get_module_path($module_info['LABEL']) . '/conf/def/' . $module_info['LABEL'] . '.def.conf.inc.php')) {
                        require_once dirname(__FILE__) . '/../config.lib.inc.php';
                        $config = new Config($module_info['LABEL']);
                        list($confMessage, $status) = generate_conf($config);
                        $backlog->info($confMessage);
                    }
                    // call install.php after initialising database in case it requires database to run
                    if (isset($installPhpScript)) {
                        unset($installPhpScript);
                    }
                    $installPhpScript = get_module_path($module_info['LABEL']) . '/setup/install.php';
                    if (file_exists($installPhpScript)) {
                        language::load_translation();
                        language::load_locale_settings();
                        language::load_module_translation($module_info['LABEL']);
                        load_module_config($module_info['LABEL']);
                        // FIXME this is very dangerous !!!!
                        require $installPhpScript;
                        $backlog->info(get_lang('Module installation script called'));
                    }
                    $moduleInfo = get_module_info($moduleId);
                    if ($registerModuleInCourses && $moduleInfo['type'] == 'tool' && $moduleId) {
                        list($backlog2, $success2) = register_module_in_courses($moduleId);
                        if ($success2) {
                            $backlog->success(get_lang('Module installed in all courses'));
                        } else {
                            $backlog->append($backlog2);
                        }
                    }
                    //6- cache file with the module's include must be renewed after installation of the module
                    if (!generate_module_cache()) {
                        $backlog->failure(get_lang('Module cache update failed'));
                    } else {
                        $backlog->success(get_lang('Module cache update succeeded'));
                    }
                }
            }
        }
    }
    return array($backlog, $moduleId);
}
Пример #7
0
/**
 * Create a new group
 *
 * @param  string $groupName - name of the group
 * @param  integer $maxMember  - max user allowed for this group
 * @return integer : id of the new group
 *
 * @copyright   (c) 2001-2011, Universite catholique de Louvain (UCL)
 */
function create_group($prefixGroupName, $maxMember)
{
    require_once dirname(__FILE__) . '/forum.lib.php';
    require_once dirname(__FILE__) . '/fileManage.lib.php';
    $tbl_cdb_names = claro_sql_get_course_tbl();
    $tbl_groups = $tbl_cdb_names['group_team'];
    // Check name of group
    $sql = "SELECT name FROM  `" . $tbl_groups . "` WHERE name LIKE  '" . claro_sql_escape($prefixGroupName) . "%'";
    $existingGroupList = claro_sql_query_fetch_all_cols($sql);
    $existingGroupList = $existingGroupList['name'];
    $i = 1;
    do {
        $groupName = $prefixGroupName . str_pad($i, 4, ' ', STR_PAD_LEFT);
        $i++;
        if ($i - 2 > count($existingGroupList)) {
            die($groupName . 'infiniteloop');
        }
    } while (in_array($groupName, $existingGroupList));
    /**
     * Create a directory allowing group student to upload documents
     */
    //  Create a Unique ID path preventing other enter
    $globalPath = $GLOBALS['coursesRepositorySys'] . $GLOBALS['currentCourseRepository'] . '/group/';
    do {
        $groupRepository = str_replace(' ', '_', substr(uniqid(substr($groupName, 0, 19) . ' ', ''), 0, 30));
    } while (check_name_exist($globalPath . $groupRepository));
    claro_mkdir($globalPath . $groupRepository, CLARO_FILE_PERMISSIONS);
    /*
     * Insert a new group in the course group table and keep its ID
     */
    $sql = "INSERT INTO `" . $tbl_groups . "`\n            SET name = '" . $groupName . "',\n               `maxStudent`  = " . (is_null($maxMember) ? 'NULL' : "'" . (int) $maxMember . "'") . ",\n                secretDirectory = '" . claro_sql_escape($groupRepository) . "'";
    $createdGroupId = claro_sql_query_insert_id($sql);
    /*
     * Create a forum for the group in the forum table
     */
    if (is_tool_activated_in_course(get_tool_id_from_module_label('CLFRM'), claro_get_current_course_id()) && is_tool_activated_in_groups(claro_get_current_course_id(), 'CLFRM')) {
        create_forum($groupName . ' - ' . strtolower(get_lang('Forum')), '', 2, (int) GROUP_FORUMS_CATEGORY, '', $createdGroupId);
    }
    if (is_tool_activated_in_course(get_tool_id_from_module_label('CLWIKI'), claro_get_current_course_id()) && is_tool_activated_in_groups(claro_get_current_course_id(), 'CLWIKI')) {
        require_once get_module_path('CLWIKI') . '/lib/lib.createwiki.php';
        create_wiki($createdGroupId, $groupName . ' - Wiki');
    }
    return $createdGroupId;
}
 /**
  * Move a file or a directory to an other area
  *
  * @author - Hugues Peeters <*****@*****.**>
  * @param  - $source (String) - the path of file or directory to move
  * @param  - $target (String) - the path of the new area
  * @return - bolean - true if the move succeed
  *           bolean - false otherwise.
  * @see    - move() uses check_name_exist() and copyDirTo() functions
  */
 function move($source, $target)
 {
     if (check_name_exist($source)) {
         $fileName = basename($source);
         if (check_name_exist($target . "/" . $fileName)) {
             return false;
         } else {
             /*** File case ***/
             if (@is_file($source)) {
                 @copy($source, $target . "/" . $fileName);
                 @unlink($source);
                 return true;
             } elseif (@is_dir($source)) {
                 // check to not copy the directory inside itself
                 if (ereg("^" . $source, $target)) {
                     return false;
                 } else {
                     $this->copyDirTo($source, $target);
                     return true;
                 }
             }
         }
     } else {
         return false;
     }
 }
Пример #9
0
    $dialogBox = '';
}
if (!isset($style)) {
    $style = '';
}
$iterator = 0;
if (!isset($_REQUEST['maxDocForm'])) {
    $_REQUEST['maxDocForm'] = 0;
}
while ($iterator <= $_REQUEST['maxDocForm']) {
    $iterator++;
    if (isset($_REQUEST['submitInsertedDocument']) && isset($_POST['insertDocument_' . $iterator])) {
        $insertDocument = str_replace('..', '', $_POST['insertDocument_' . $iterator]);
        $filenameDocument = $_POST['filenameDocument_' . $iterator];
        $sourceDoc = $baseWorkDir . $insertDocument;
        if (check_name_exist($sourceDoc)) {
            // source file exists ?
            // check if a module of this course already used the same document
            $sql = "SELECT *\n                    FROM `lp_module` AS M, `lp_asset` AS A\n                    WHERE A.`module_id` = M.`module_id`\n                      AND A.`path` LIKE ?s\n                      AND M.`contentType` = ?s\n                      AND M.`course_id` = ?d";
            $thisDocumentModule = Database::get()->queryArray($sql, $insertDocument, CTDOCUMENT_, $course_id);
            $num = count($thisDocumentModule);
            $basename = substr($insertDocument, strrpos($insertDocument, '/') + 1);
            if ($num == 0) {
                // create new module
                $insertedModule_id = Database::get()->query("INSERT INTO `lp_module`\n                        (`course_id`, `name` , `comment`, `contentType`, `launch_data`)\n                        VALUES (?d, ?s, ?s, ?s, '')", $course_id, $filenameDocument, $langDefaultModuleComment, CTDOCUMENT_)->lastInsertID;
                // create new asset
                $insertedAsset_id = Database::get()->query("INSERT INTO `lp_asset`\n                        (`path` , `module_id` , `comment`)\n                        VALUES (?s, ?d, '')", $insertDocument, $insertedModule_id)->lastInsertID;
                Database::get()->query("UPDATE `lp_module`\n                        SET `startAsset_id` = ?d\n                        WHERE `module_id` = ?d\n                        AND `course_id` = ?d", $insertedAsset_id, $insertedModule_id, $course_id);
                // determine the default order of this Learning path
                $order = 1 + intval(Database::get()->querySingle("SELECT MAX(`rank`) AS max\n                        FROM `lp_rel_learnPath_module`\n                        WHERE `learnPath_id` = ?d", $_SESSION['path_id'])->max);
                // finally : insert in learning path
Пример #10
0
/**
 * Moves a file or a directory to an other area
 *
 * @author - Hugues Peeters <*****@*****.**>
 * @param  - $source (String) - the path of file or directory to move
 * @param  - $target (String) - the path of the new area
 * @param  bool $forceMove Whether to force a move or to make a copy (safer but slower) and then delete the original
 * @param	bool $moveContent In some cases (including migrations), we need to move the *content* and not the folder itself
 * @return - bolean - true if the move succeed
 *           bolean - false otherwise.
 * @see    - move() uses check_name_exist() and copyDirTo() functions
 */
function move($source, $target, $forceMove = false, $moveContent = false)
{
    if (check_name_exist($source)) {
        $file_name = basename($source);
        $isWindowsOS = api_is_windows_os();
        $canExec = function_exists('exec');
        /* File case */
        if (is_file($source)) {
            if ($forceMove && !$isWindowsOS && $canExec) {
                exec('mv ' . $source . ' ' . $target . '/' . $file_name);
            } else {
                copy($source, $target . '/' . $file_name);
                unlink($source);
            }
            return true;
        } elseif (is_dir($source)) {
            /* Directory */
            if ($forceMove && !$isWindowsOS && $canExec) {
                if ($moveContent) {
                    $base = basename($source);
                    exec('mv ' . $source . '/* ' . $target . $base . '/');
                    exec('rm -rf ' . $source);
                } else {
                    exec('mv $source $target');
                }
            } else {
                copyDirTo($source, $target);
            }
            return true;
        }
    } else {
        return false;
    }
}
Пример #11
0
/**
 * Moves a file or a directory to an other area
 *
 * @author - Hugues Peeters <*****@*****.**>
 * @param  - $source (String) - the path of file or directory to move
 * @param  - $target (String) - the path of the new area
 * @return - bolean - true if the move succeed
 *           bolean - false otherwise.
 * @see    - move() uses check_name_exist() and copyDirTo() functions
 */
function move($source, $target)
{
    if (check_name_exist($source)) {
        $file_name = basename($source);
        if (check_name_exist($target . '/' . $file_name)) {
            return false;
        } else {
            /* File case */
            if (is_file($source)) {
                copy($source, $target . '/' . $file_name);
                unlink($source);
                return true;
            } elseif (is_dir($source)) {
                // Check to not copy the directory inside itself
                if (ereg('^' . $source . '/', $target . '/')) {
                    // TODO: ereg() function is deprecated in PHP 5.3
                    return false;
                } else {
                    copyDirTo($source, $target);
                    return true;
                }
            }
        }
    } else {
        return false;
    }
}
function move($source, $target)
{
    if (check_name_exist($source)) {
        $fileName = basename($source);
        if (check_name_exist($target . '/' . $fileName)) {
            return false;
        } else {
            /*** File case ***/
            if (is_file($source)) {
                copy($source, $target . '/' . $fileName);
                unlink($source);
                return true;
            } elseif (is_dir($source)) {
                // check to not copy the directory inside itself
                if (ereg('^' . $source . '*', $target)) {
                    return false;
                } else {
                    copyDirTo($source, $target);
                    return true;
                }
            }
        }
    } else {
        return false;
    }
}