Example #1
0
 /**
  * Setups the folder
  */
 public function setup()
 {
     $userId = api_get_user_id();
     $sessionId = api_get_session_id();
     $userInfo = $this->connector->user;
     $courseInfo = $this->connector->course;
     if (!empty($courseInfo)) {
         $coursePath = api_get_path(SYS_COURSE_PATH);
         $courseDir = $courseInfo['directory'] . '/document';
         $baseDir = $coursePath . $courseDir;
         // Creates shared folder
         if (!file_exists($baseDir . '/shared_folder')) {
             $title = get_lang('UserFolders');
             $folderName = '/shared_folder';
             //$groupId = 0;
             $visibility = 0;
             create_unexisting_directory($courseInfo, $userId, $sessionId, 0, null, $baseDir, $folderName, $title, $visibility);
         }
         // Creates user-course folder
         if (!file_exists($baseDir . '/shared_folder/sf_user_' . $userId)) {
             $title = $userInfo['complete_name'];
             $folderName = '/shared_folder/sf_user_' . $userId;
             $visibility = 1;
             create_unexisting_directory($courseInfo, $userId, $sessionId, 0, null, $baseDir, $folderName, $title, $visibility);
         }
     }
 }
 /**
  * Create a group
  * @param string $name The name for this group
  * @param int $category_id
  * @param int $tutor The user-id of the group's tutor
  * @param int $places How many people can subscribe to the new group
  */
 public static function create_group($name, $category_id, $tutor, $places)
 {
     $courseObj = api_get_user_course_entity();
     $_course = api_get_course_info();
     $session_id = api_get_session_id();
     $currentCourseRepository = $_course['path'];
     $category = self::get_category($category_id);
     $places = intval($places);
     if ($category) {
         if ($places == 0) {
             //if the amount of users per group is not filled in, use the setting from the category
             $places = $category['max_student'];
         } else {
             if ($places > $category['max_student'] && $category['max_student'] != 0) {
                 $places = $category['max_student'];
             }
         }
         $docState = $category['doc_state'];
         $calendarState = $category['calendar_state'];
         $workState = $category['work_state'];
         $anonuncementState = $category['announcements_state'];
         $forumState = $category['forum_state'];
         $wikiState = $category['wiki_state'];
         $chatState = $category['chat_state'];
         $selfRegAllowed = $category['self_reg_allowed'];
         $selfUnregAllowed = $category['self_unreg_allowed'];
     } else {
         $docState = self::TOOL_PRIVATE;
         $calendarState = self::TOOL_PRIVATE;
         $workState = self::TOOL_PRIVATE;
         $anonuncementState = self::TOOL_PRIVATE;
         $forumState = self::TOOL_PRIVATE;
         $wikiState = self::TOOL_PRIVATE;
         $chatState = self::TOOL_PRIVATE;
         $selfRegAllowed = 0;
         $selfUnregAllowed = 0;
     }
     $group = new CGroupInfo();
     $group->setName($name)->setStatus(1)->setDescription('')->setMaxStudent($places)->setAnnouncementsState($anonuncementState)->setDocState($docState)->setCalendarState($calendarState)->setChatState($chatState)->setForumState($forumState)->setWikiState($wikiState)->setWorkState($workState)->setSelfUnregistrationAllowed($selfUnregAllowed)->setSelfRegistrationAllowed($selfRegAllowed)->setSessionId($session_id)->setCourse($courseObj)->setCategoryId($category_id)->setDescription('');
     $em = Database::getManager();
     $em->persist($group);
     $em->flush();
     $lastId = $group->getIid();
     if ($lastId) {
         $desired_dir_name = '/' . api_replace_dangerous_char($name) . '_groupdocs';
         $my_path = api_get_path(SYS_COURSE_PATH) . $currentCourseRepository . '/document';
         $newFolderData = create_unexisting_directory($_course, api_get_user_id(), $session_id, $lastId, null, $my_path, $desired_dir_name, null, 1);
         $unique_name = $newFolderData['path'];
         $group->setId($lastId);
         $group->setSecretDirectory($unique_name);
         $group->setName($name);
         $em->merge($group);
         $em->flush();
         // create a forum if needed
         if ($forumState >= 0) {
             require_once api_get_path(SYS_CODE_PATH) . 'forum/forumconfig.inc.php';
             require_once api_get_path(SYS_CODE_PATH) . 'forum/forumfunction.inc.php';
             $forum_categories = get_forum_categories();
             if (empty($forum_categories)) {
                 $categoryParam = array('forum_category_title' => get_lang('GroupForums'));
                 store_forumcategory($categoryParam);
                 $forum_categories = get_forum_categories();
             }
             $counter = 0;
             foreach ($forum_categories as $key => $value) {
                 if ($counter == 0) {
                     $forum_category_id = $key;
                 }
                 $counter++;
             }
             // A sanity check.
             if (empty($forum_category_id)) {
                 $forum_category_id = 0;
             }
             $values = array();
             $values['forum_title'] = $name;
             $values['group_id'] = $lastId;
             $values['forum_category'] = $forum_category_id;
             $values['allow_anonymous_group']['allow_anonymous'] = 0;
             $values['students_can_edit_group']['students_can_edit'] = 0;
             $values['approval_direct_group']['approval_direct'] = 0;
             $values['allow_attachments_group']['allow_attachments'] = 1;
             $values['allow_new_threads_group']['allow_new_threads'] = 1;
             $values['default_view_type_group']['default_view_type'] = api_get_setting('forum.default_forum_view');
             $values['group_forum'] = $lastId;
             if ($forumState == '1') {
                 $values['public_private_group_forum_group']['public_private_group_forum'] = 'public';
             } elseif ($forumState == '2') {
                 $values['public_private_group_forum_group']['public_private_group_forum'] = 'private';
             } elseif ($forumState == '0') {
                 $values['public_private_group_forum_group']['public_private_group_forum'] = 'unavailable';
             }
             store_forum($values);
         }
     }
     return $lastId;
 }
Example #3
0
    exit;
}

$courseInfo = api_get_course_info();
$folderName = 'captures';
$documentId = DocumentManager::get_document_id($courseInfo, '/'.$folderName);
$path = null;
if (empty($documentId)) {
    $course_dir = $courseInfo['path'] . '/document';
    $sys_course_path = api_get_path(SYS_COURSE_PATH);
    $dir = $sys_course_path . $course_dir;
    $createdDir = create_unexisting_directory(
        $courseInfo,
        api_get_user_id(),
        api_get_session_id(),
        null,
        null,
        $dir,
        '/'.$folderName,
        $folderName
    );
    if ($createdDir) {
        $path = '/'.$folderName;
    }
} else {
    $data = DocumentManager::get_document_data_by_id($documentId, $courseInfo['code']);
    $path = $data['path'];
}

if (empty($path)) {
    exit;
}
Example #4
0
                // Get the document data from the ID
                $document_data = DocumentManager::get_document_data_by_id($_POST['dir_id'], api_get_course_id(), false, $sessionId);
                if ($sessionId != 0 && !$document_data) {
                    // If there is a session defined and asking for the
                    // document * from the session* didn't work, try it from
                    // the course (out of a session context)
                    $document_data = DocumentManager::get_document_data_by_id($_POST['dir_id'], api_get_course_id(), false, 0);
                }
                $curdirpath = $document_data['path'];
            }
            $added_slash = $curdirpath == '/' ? '' : '/';
            $dir_name = $curdirpath . $added_slash . api_replace_dangerous_char($post_dir_name);
            $dir_name = disable_dangerous_file($dir_name);
            $dir_check = $base_work_dir . $dir_name;
            $visibility = empty($groupId) ? null : 1;
            $newFolderData = create_unexisting_directory($courseInfo, api_get_user_id(), $sessionId, $groupId, $to_user_id, $base_work_dir, $dir_name, $post_dir_name, $visibility);
            if (!empty($newFolderData)) {
                $message = Display::return_message(get_lang('DirCr') . ' ' . $newFolderData['title'], 'confirmation');
            } else {
                $message = Display::return_message(get_lang('CannotCreateDir'), 'error');
            }
        }
        Display::addFlash($message);
    }
    // Show them the form for the directory name
    if (isset($_GET['createdir'])) {
        $dirForm = DocumentManager::create_dir_form($document_id);
    }
}
/* 	VISIBILITY COMMANDS */
if ($is_allowed_to_edit) {
Example #5
0
             $form .= '<dt>' . "\n" . '<label for="comment">' . get_lang('Comment') . '</label>' . '</dt>' . "\n" . '<dd>' . '<textarea rows=2 cols=50 id="comment" name="comment">' . claro_htmlspecialchars($oldComment) . '</textarea>' . "\n" . '</dd>' . "\n";
         }
         $form .= '</dl>' . '</fieldset>' . '<p><span class="required">*</span>&nbsp;' . get_lang('Denotes required fields') . '</p>' . "\n" . '<input type="submit" value="' . get_lang('Ok') . '" />&nbsp; ' . claro_html_button(claro_htmlspecialchars(Url::Contextualize($_SERVER['PHP_SELF'] . '?cmd=exChDir&file=' . base64_encode($cwd))), get_lang('Cancel')) . '</form>';
         $dialogBox->form($form);
     }
 }
 /*= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
                        UPLOAD RELATED IMAGE FILES
   = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = */
 if ('submitImage' == $cmd) {
     $uploadImgFileNb = sizeof($_FILES['imgFile']);
     if ($uploadImgFileNb > 0) {
         // Try to create  a directory to store the image files
         $_REQUEST['relatedFile'] = secure_file_path($_REQUEST['relatedFile']);
         $imgDirectory = $_REQUEST['relatedFile'] . '_files';
         $imgDirectory = create_unexisting_directory($baseWorkDir . $imgDirectory);
         // set the makeInvisible command param appearing later in the script
         $mkInvisibl = str_replace($baseWorkDir, '', $imgDirectory);
         // move the uploaded image files into the corresponding image directory
         // Try to create  a directory to store the image files
         $newImgPathList = move_uploaded_file_collection_into_directory($_FILES['imgFile'], $imgDirectory);
         if (!empty($newImgPathList)) {
             $newImgPathList = array_map('rawurlencode', $newImgPathList);
             // rawurlencode() does too much. We don't need to replace '/' by '%2F'
             $newImgPathList = str_replace('%2F', '/', $newImgPathList);
             replace_img_path_in_html_file($_REQUEST['imgFilePath'], $newImgPathList, $baseWorkDir . $_REQUEST['relatedFile']);
         }
     }
     // end if ($uploadImgFileNb > 0)
 }
 // end if ($submitImage)
Example #6
0
        $img_directory = str_replace('.', '_', $_POST['related_file'] . "_files");
        $folderData = create_unexisting_directory($_course, $_user['user_id'], api_get_session_id(), $to_group_id, $to_user_id, $base_work_dir, $img_directory);
        $missing_files_dir = $folderData['path'];
        //put the uploaded files in the new directory and get the paths
        $paths_to_replace_in_file = move_uploaded_file_collection_into_directory($_course, $_FILES['img_file'], $base_work_dir, $missing_files_dir, $_user['user_id'], $to_group_id, $to_user_id, $max_filled_space);
        //open the html file and replace the paths
        replace_img_path_in_html_file($_POST['img_file_path'], $paths_to_replace_in_file, $base_work_dir . $_POST['related_file']);
        //update parent folders
        item_property_update_on_folder($_course, $_POST['curdirpath'], $_user['user_id']);
    }
}
//they want to create a directory
if (isset($_POST['create_dir']) && $_POST['dirname'] != '') {
    $added_slash = $path == '/' ? '' : '/';
    $dir_name = $path . $added_slash . api_replace_dangerous_char($_POST['dirname']);
    $created_dir = create_unexisting_directory($_course, $_user['user_id'], api_get_session_id(), $to_group_id, $to_user_id, $base_work_dir, $dir_name, $_POST['dirname']);
    if ($created_dir) {
        Display::display_normal_message(get_lang('DirCr'));
        $path = $created_dir;
    } else {
        display_error(get_lang('CannotCreateDir'));
    }
}
if (isset($_GET['createdir'])) {
    //create the form that asks for the directory name
    $new_folder_text = '<form action="' . api_get_self() . '" method="POST">';
    $new_folder_text .= '<input type="hidden" name="curdirpath" value="' . $path . '"/>';
    $new_folder_text .= get_lang('NewDir') . ' ';
    $new_folder_text .= '<input type="text" name="dirname"/>';
    $new_folder_text .= '<input type="submit" name="create_dir" value="' . get_lang('Ok') . '"/>';
    $new_folder_text .= '</form>';
Example #7
0
/**
 * This recursive function can be used during the upgrade process form older
 * versions of Chamilo
 * It crawls the given directory, checks if the file is in the DB and adds
 * it if it's not
 *
 * @param array $courseInfo
 * @param array $userInfo
 * @param string $base_work_dir
 * @param string $folderPath
 * @param int $sessionId
 * @param int $groupId
 * @param bool $output
 * @param array $parent
 * @param string $uploadPath
 *
 */
function add_all_documents_in_folder_to_database($courseInfo, $userInfo, $base_work_dir, $folderPath, $sessionId = 0, $groupId = 0, $output = false, $parent = array())
{
    if (empty($userInfo) || empty($courseInfo)) {
        return false;
    }
    $userId = $userInfo['user_id'];
    // Open dir
    $handle = opendir($folderPath);
    $files = array();
    if (is_dir($folderPath)) {
        // Run trough
        while ($file = readdir($handle)) {
            if ($file == '.' || $file == '..') {
                continue;
            }
            $parentPath = null;
            if (!empty($parent) && isset($parent['path'])) {
                $parentPath = $parent['path'];
                if ($parentPath == '/') {
                    $parentPath = null;
                }
            }
            $completePath = $parentPath . '/' . $file;
            $sysFolderPath = $folderPath . '/' . $file;
            // Is directory?
            if (is_dir($sysFolderPath)) {
                $newFolderData = create_unexisting_directory($courseInfo, $userId, $sessionId, $groupId, null, $base_work_dir, $completePath, null, null, true);
                $files[$file] = $newFolderData;
                // Recursive
                add_all_documents_in_folder_to_database($courseInfo, $userInfo, $base_work_dir, $sysFolderPath, $sessionId, $groupId, $output, $newFolderData);
            } else {
                // Rename
                $uploadedFile = array('name' => $file, 'tmp_name' => $sysFolderPath, 'size' => filesize($sysFolderPath), 'type' => null, 'from_file' => true, 'move_file' => true);
                handle_uploaded_document($courseInfo, $uploadedFile, $base_work_dir, $parentPath, $userId, $groupId, null, 0, 'overwrite', $output, false, null, $sessionId);
            }
        }
    }
}
Example #8
0
           Always session_id should be zero. Always should be created from a base course, never from a session.*/
        if (!file_exists($base_work_dir . '/shared_folder')) {
            $usf_dir_title = get_lang('SharedFolder');
            $usf_dir_name = '/shared_folder';
            $visibility = 0;
            create_unexisting_directory($_course, $userId, $sessionId, 0, $to_user_id, $base_work_dir, $usf_dir_name, $usf_dir_title, $visibility);
        }
        // Create dynamic user shared folder
        if (!file_exists($base_work_dir . '/shared_folder/sf_user_' . $userId)) {
            $usf_dir_title = $userInfo['complete_name'];
            $usf_dir_name = '/shared_folder/sf_user_' . $userId;
            $visibility = 1;
            create_unexisting_directory($_course, $userId, $sessionId, 0, $to_user_id, $base_work_dir, $usf_dir_name, $usf_dir_title, $visibility);
        }
    } else {
        // Create shared folder session
        if (!file_exists($base_work_dir . '/shared_folder_session_' . $sessionId)) {
            $usf_dir_title = get_lang('SharedFolder') . ' (' . $sessionName . ')';
            $usf_dir_name = '/shared_folder_session_' . $sessionId;
            $visibility = 0;
            create_unexisting_directory($_course, $userId, $sessionId, 0, $to_user_id, $base_work_dir, $usf_dir_name, $usf_dir_title, $visibility);
        }
        // Create dynamic user shared folder into a shared folder session.
        if (!file_exists($base_work_dir . '/shared_folder_session_' . $sessionId . '/sf_user_' . $userId)) {
            $usf_dir_title = $userInfo['complete_name'] . ' (' . $sessionName . ')';
            $usf_dir_name = '/shared_folder_session_' . $sessionId . '/sf_user_' . $userId;
            $visibility = 1;
            create_unexisting_directory($_course, $userId, $sessionId, 0, $to_user_id, $base_work_dir, $usf_dir_name, $usf_dir_title, $visibility);
        }
    }
}
 /**
  * @param array $course
  * @param string $lp_name
  * @return array
  */
 public function generate_lp_folder($course, $lp_name = null)
 {
     $filepath = '';
     $dir = '/learning_path/';
     if (empty($lp_name)) {
         $lp_name = $this->name;
     }
     $folder = self::generate_learning_path_folder($course);
     // Creating LP folder
     if ($folder) {
         //Limits title size
         $title = api_substr(api_replace_dangerous_char($lp_name), 0, 80);
         $dir = $dir . $title;
         $filepath = api_get_path(SYS_COURSE_PATH) . $course['path'] . '/document';
         if (!is_dir($filepath . '/' . $dir)) {
             $folderData = create_unexisting_directory($course, api_get_user_id(), 0, 0, 0, $filepath, $dir, $lp_name);
             if (!empty($folderData)) {
                 $folder = true;
             }
         } else {
             $folder = true;
         }
         $dir = $dir . '/';
         if ($folder) {
             $filepath = api_get_path(SYS_COURSE_PATH) . $course['path'] . '/document' . $dir;
         }
     }
     $array = array('dir' => $dir, 'filepath' => $filepath, 'folder' => $folder);
     return $array;
 }
Example #10
0
             $details = implode("<br />\n", claro_failure::get_last_failure());
             $dialogBox->error(Backlog_Reporter::report($summary, $details));
         }
     }
 } elseif (array_key_exists('packageCandidatePath', $_REQUEST)) {
     // If the target is a zip file, it must be unpack
     // If it's a unziped package, We copye the content
     if (is_package_file($_REQUEST['packageCandidatePath'])) {
         pushClaroMessage(__LINE__ . 'packageCandidatePath is a package', 'dbg');
         $modulePath = unzip_package($_REQUEST['packageCandidatePath']);
         pushClaroMessage(__LINE__ . '<pre>$modulePath =' . var_export($modulePath, 1) . '</pre>', 'dbg');
     } elseif (file_exists($_REQUEST['packageCandidatePath'])) {
         // COPY THE FILE TO WORK REPOSITORY
         pushClaroMessage(__LINE__ . 'packageCandidatePath is a path', 'dbg');
         claro_mkdir(get_package_path());
         $modulePath = create_unexisting_directory(get_package_path() . basename($_REQUEST['packageCandidatePath']));
         claro_mkdir($modulePath);
         pushClaroMessage(__LINE__ . 'create target' . $modulePath, 'dbg');
         if (claro_copy_file($_REQUEST['packageCandidatePath'], $modulePath . '/')) {
             $modulePath .= '/' . basename($_REQUEST['packageCandidatePath']);
             $moduleInstallable = true;
         } else {
             $dialogBox->error(get_lang('Module catching failed. Check your path'));
             $moduleInstallable = false;
         }
     }
 }
 pushClaroMessage(__LINE__ . '<pre>$modulePath =' . var_export($modulePath, 1) . '</pre>', 'dbg');
 // OK TO TRY TO INSTALL ?
 if ($moduleInstallable) {
     list($backlog, $module_id) = install_module($modulePath);
Example #11
0
 /**
  * Create new directories.
  * If in safe_mode, nothing happens.
  * @return boolean true if created, false otherwise.
  */
 function processNewDir()
 {
     if ($this->config['safe_mode']) {
         return false;
     }
     if (isset($_GET['newDir']) && isset($_GET['dir'])) {
         $newDir = rawurldecode($_GET['newDir']);
         $dir = rawurldecode($_GET['dir']);
         $path = Files::makePath($this->getBaseDir(), $dir);
         $fullpath = Files::makePath($path, Files::escape($newDir));
         if (is_dir($fullpath)) {
             return false;
         } else {
             //adding to the DB
             // now the create_unexisting_directory will create the folder
             //$result = Files::createFolder($fullpath);
             global $_course;
             if (isset($_course) && !empty($_course) && isset($_course['code'])) {
                 //@todo make this str to functions
                 $base_dir = substr($path, 0, strpos($path, '/document/') + 9);
                 //
                 $new_dir = substr($fullpath, strlen($base_dir), -1);
                 //
                 create_unexisting_directory($_course, api_get_user_id(), api_get_session_id(), 0, 0, $base_dir, $new_dir, $newDir);
                 $doc_id = DocumentManager::get_document_id($_course, $new_dir);
                 api_item_property_update($_course, TOOL_DOCUMENT, $doc_id, 'invisible', api_get_user_id(), null, null, null, null, api_get_session_id());
             } else {
                 return Files::createFolder($fullpath);
             }
             return true;
         }
     }
 }
 /**
  * @param array $course
  * @param string $lp_name
  * @param int $creatorId
  *
  * @return array
  */
 public function generate_lp_folder($course, $lp_name = '', $creatorId = 0)
 {
     $filepath = '';
     $dir = '/learning_path/';
     if (empty($lp_name)) {
         $lp_name = $this->name;
     }
     $creatorId = empty($creatorId) ? api_get_user_id() : $creatorId;
     $folder = self::generate_learning_path_folder($course, $creatorId);
     // Limits title size
     $title = api_substr(api_replace_dangerous_char($lp_name), 0, 80);
     $dir = $dir . $title;
     // Creating LP folder
     $documentId = null;
     if ($folder) {
         $filepath = api_get_path(SYS_COURSE_PATH) . $course['path'] . '/document';
         if (!is_dir($filepath . '/' . $dir)) {
             $folderData = create_unexisting_directory($course, $creatorId, 0, 0, 0, $filepath, $dir, $lp_name);
             if (!empty($folderData)) {
                 $folder = true;
             }
             $documentId = $folderData['id'];
         } else {
             $folder = true;
         }
         $dir = $dir . '/';
         if ($folder) {
             $filepath = api_get_path(SYS_COURSE_PATH) . $course['path'] . '/document' . $dir;
         }
     }
     if (empty($documentId)) {
         $dir = api_remove_trailing_slash($dir);
         $documentId = DocumentManager::get_document_id($course, $dir, 0);
     }
     $array = array('dir' => $dir, 'filepath' => $filepath, 'folder' => $folder, 'id' => $documentId);
     return $array;
 }
Example #13
0
     // Needed for directory creation
     require_once api_get_path(LIBRARY_PATH) . 'fileUpload.lib.php';
     $post_dir_name = $_POST['dirname'];
     if ($post_dir_name == '../' || $post_dir_name == '.' || $post_dir_name == '..') {
         Display::display_error_message(get_lang('CannotCreateDir'));
     } else {
         if (!empty($_POST['dir_id'])) {
             $document_data = DocumentManager::get_document_data_by_id($_POST['dir_id'], api_get_course_id());
             $curdirpath = $document_data['path'];
         }
         $added_slash = $curdirpath == '/' ? '' : '/';
         $dir_name = $curdirpath . $added_slash . replace_dangerous_char($post_dir_name);
         $dir_name = disable_dangerous_file($dir_name);
         $dir_check = $base_work_dir . $dir_name;
         if (!is_dir($dir_check)) {
             $created_dir = create_unexisting_directory($_course, api_get_user_id(), api_get_session_id(), $to_group_id, $to_user_id, $base_work_dir, $dir_name, $post_dir_name);
             if ($created_dir) {
                 Display::display_confirmation_message('<span title="' . $created_dir . '">' . get_lang('DirCr') . '</span>', false);
                 // Uncomment if you want to enter the created dir
                 //$curdirpath = $created_dir;
                 //$curdirpathurl = urlencode($curdirpath);
             } else {
                 Display::display_error_message(get_lang('CannotCreateDir'));
             }
         } else {
             Display::display_error_message(get_lang('CannotCreateDir'));
         }
     }
 }
 // Show them the form for the directory name
 if (isset($_GET['createdir'])) {
Example #14
0
 /**
  * Create directory certificate
  * @param string $courseCode
  * @return void()
  */
 public static function create_directory_certificate_in_course($courseCode)
 {
     $courseInfo = api_get_course_info($courseCode);
     if (!empty($courseInfo)) {
         $to_group_id = 0;
         $to_user_id = null;
         $course_dir = $courseInfo['path'] . "/document/";
         $sys_course_path = api_get_path(SYS_COURSE_PATH);
         $base_work_dir = $sys_course_path . $course_dir;
         $base_work_dir_test = $base_work_dir . 'certificates';
         $dir_name = '/certificates';
         $post_dir_name = get_lang('CertificatesFiles');
         $visibility_command = 'invisible';
         $id = self::get_document_id_of_directory_certificate();
         if (empty($id)) {
             create_unexisting_directory($courseInfo, api_get_user_id(), api_get_session_id(), $to_group_id, $to_user_id, $base_work_dir, $dir_name, $post_dir_name, null, false);
             $id = self::get_document_id_of_directory_certificate();
             if (empty($id)) {
                 $id = add_document($courseInfo, $dir_name, 'folder', 0, $post_dir_name, null, 0, true, $to_group_id);
             }
             if (!empty($id)) {
                 api_item_property_update($courseInfo, TOOL_DOCUMENT, $id, $visibility_command, api_get_user_id());
             }
         }
     }
 }
 /**
  * Restore documents
  *
  * @param int $session_id
  * @param bool $respect_base_content
  * @param string $destination_course_code
  */
 public function restore_documents($session_id = 0, $respect_base_content = false, $destination_course_code = '')
 {
     $course_info = api_get_course_info($destination_course_code);
     if ($this->course->has_resources(RESOURCE_DOCUMENT)) {
         $table = Database::get_course_table(TABLE_DOCUMENT);
         $resources = $this->course->resources;
         $path = api_get_path(SYS_COURSE_PATH) . $this->course->destination_path . '/';
         foreach ($resources[RESOURCE_DOCUMENT] as $id => $document) {
             if (empty($document->item_properties[0]['id_session'])) {
                 $my_session_id = 0;
             } else {
                 $my_session_id = $session_id;
             }
             if ($document->file_type == FOLDER) {
                 $visibility = $document->item_properties[0]['visibility'];
                 $new = substr($document->path, 8);
                 $folderList = explode('/', $new);
                 $tempFolder = '';
                 // Check if the parent path exists.
                 foreach ($folderList as $folder) {
                     $folderToCreate = $tempFolder . $folder;
                     $sysFolderPath = $path . 'document' . $folderToCreate;
                     $tempFolder .= $folder . '/';
                     if (empty($folderToCreate)) {
                         continue;
                     }
                     $title = basename($sysFolderPath);
                     // File doesn't exist in file system.
                     if (!is_dir($sysFolderPath)) {
                         // Creating directory
                         create_unexisting_directory($course_info, api_get_user_id(), $my_session_id, 0, 0, $path . 'document', $folderToCreate, $title, $visibility);
                     } else {
                         // File exist in file system.
                         $documentData = DocumentManager::get_document_id($course_info, $folderToCreate, $my_session_id);
                         if (empty($documentData)) {
                             /* This means the folder exists in the
                                filesystem but not in the DB, trying to fix it */
                             add_document($course_info, $folderToCreate, 'folder', 0, $title, null, null, false, null, $my_session_id);
                         }
                     }
                 }
             } elseif ($document->file_type == DOCUMENT) {
                 //Checking if folder exists in the database otherwise we created it
                 $dir_to_create = dirname($document->path);
                 if (!empty($dir_to_create) && $dir_to_create != 'document' && $dir_to_create != '/') {
                     if (is_dir($path . dirname($document->path))) {
                         $sql = "SELECT id FROM {$table}\n                                    WHERE\n                                        c_id = " . $this->destination_course_id . " AND\n                                        path = '/" . self::DBUTF8escapestring(substr(dirname($document->path), 9)) . "'";
                         $res = Database::query($sql);
                         if (Database::num_rows($res) == 0) {
                             //continue;
                             $visibility = $document->item_properties[0]['visibility'];
                             $new = '/' . substr(dirname($document->path), 9);
                             $title = str_replace('/', '', $new);
                             // This code fixes the possibility for a file without a directory entry to be
                             $document_id = add_document($course_info, $new, 'folder', 0, $title, null, null, false);
                             api_item_property_update($course_info, TOOL_DOCUMENT, $document_id, 'FolderCreated', $document->item_properties[0]['insert_user_id'], $document->item_properties[0]['to_group_id'], $document->item_properties[0]['to_user_id'], null, null, $my_session_id);
                         }
                     }
                 }
                 if (file_exists($path . $document->path)) {
                     switch ($this->file_option) {
                         case FILE_OVERWRITE:
                             $origin_path = $this->course->backup_path . '/' . $document->path;
                             if (file_exists($origin_path)) {
                                 copy($origin_path, $path . $document->path);
                                 $sql = "SELECT id FROM {$table}\n                                            WHERE\n                                                c_id = " . $this->destination_course_id . " AND\n                                                path = '/" . self::DBUTF8escapestring(substr($document->path, 9)) . "'";
                                 $res = Database::query($sql);
                                 $count = Database::num_rows($res);
                                 if ($count == 0) {
                                     $params = ['path' => "/" . self::DBUTF8(substr($document->path, 9)), 'c_id' => $this->destination_course_id, 'comment' => self::DBUTF8($document->comment), 'title' => self::DBUTF8($document->title), 'filetype' => self::DBUTF8($document->file_type), 'size' => self::DBUTF8($document->size), 'session_id' => $my_session_id];
                                     $document_id = Database::insert($table, $params);
                                     if ($document_id) {
                                         $sql = "UPDATE {$table} SET id = iid WHERE iid = {$document_id}";
                                         Database::query($sql);
                                     }
                                     $this->course->resources[RESOURCE_DOCUMENT][$id]->destination_id = $document_id;
                                     api_item_property_update($course_info, TOOL_DOCUMENT, $document_id, 'DocumentAdded', $document->item_properties[0]['insert_user_id'], $document->item_properties[0]['to_group_id'], $document->item_properties[0]['to_user_id'], null, null, $my_session_id);
                                 } else {
                                     $obj = Database::fetch_object($res);
                                     $document_id = $obj->id;
                                     $params = ['path' => "/" . self::DBUTF8(substr($document->path, 9)), 'c_id' => $this->destination_course_id, 'comment' => self::DBUTF8($document->comment), 'title' => self::DBUTF8($document->title), 'filetype' => self::DBUTF8($document->file_type), 'size' => self::DBUTF8($document->size), 'session_id' => $my_session_id];
                                     Database::update($table, $params, ['c_id = ? AND path = ?' => [$this->destination_course_id, "/" . self::DBUTF8escapestring(substr($document->path, 9))]]);
                                     $this->course->resources[RESOURCE_DOCUMENT][$id]->destination_id = $obj->id;
                                     api_item_property_update($course_info, TOOL_DOCUMENT, $obj->id, 'default', $document->item_properties[0]['insert_user_id'], $document->item_properties[0]['to_group_id'], $document->item_properties[0]['to_user_id'], null, null, $my_session_id);
                                 }
                                 // Replace old course code with the new destination code
                                 $file_info = pathinfo($path . $document->path);
                                 if (in_array($file_info['extension'], array('html', 'htm'))) {
                                     $content = file_get_contents($path . $document->path);
                                     if (UTF8_CONVERT) {
                                         $content = utf8_encode($content);
                                     }
                                     $content = DocumentManager::replace_urls_inside_content_html_from_copy_course($content, $this->course->code, $this->course->destination_path, $this->course->backup_path, $this->course->info['path']);
                                     file_put_contents($path . $document->path, $content);
                                 }
                                 $params = ['comment' => self::DBUTF8($document->comment), 'title' => self::DBUTF8($document->title), 'size' => self::DBUTF8($document->size)];
                                 Database::update($table, $params, ['c_id = ? AND id = ?' => [$this->destination_course_id, $document_id]]);
                             }
                             break;
                         case FILE_SKIP:
                             $sql = "SELECT id FROM {$table}\n\t\t\t\t\t\t\t\t        WHERE\n\t\t\t\t\t\t\t\t            c_id = " . $this->destination_course_id . " AND\n\t\t\t\t\t\t\t\t            path='/" . self::DBUTF8escapestring(substr($document->path, 9)) . "'";
                             $res = Database::query($sql);
                             $obj = Database::fetch_object($res);
                             $this->course->resources[RESOURCE_DOCUMENT][$id]->destination_id = $obj->id;
                             break;
                         case FILE_RENAME:
                             $i = 1;
                             $ext = explode('.', basename($document->path));
                             if (count($ext) > 1) {
                                 $ext = array_pop($ext);
                                 $file_name_no_ext = substr($document->path, 0, -(strlen($ext) + 1));
                                 $ext = '.' . $ext;
                             } else {
                                 $ext = '';
                                 $file_name_no_ext = $document->path;
                             }
                             $new_file_name = $file_name_no_ext . '_' . $i . $ext;
                             $file_exists = file_exists($path . $new_file_name);
                             while ($file_exists) {
                                 $i++;
                                 $new_file_name = $file_name_no_ext . '_' . $i . $ext;
                                 $file_exists = file_exists($path . $new_file_name);
                             }
                             if (!empty($session_id)) {
                                 $document_path = explode('/', $document->path, 3);
                                 $course_path = $path;
                                 $orig_base_folder = $document_path[1];
                                 $orig_base_path = $course_path . $document_path[0] . '/' . $document_path[1];
                                 if (is_dir($orig_base_path)) {
                                     $new_base_foldername = $orig_base_folder;
                                     $new_base_path = $orig_base_path;
                                     $originalFolderName = Session::read('orig_base_foldername');
                                     if ($originalFolderName != $new_base_foldername) {
                                         Session::erase('new_base_foldername');
                                         Session::erase('orig_base_foldername');
                                         Session::erase('new_base_path');
                                     }
                                     $folder_exists = file_exists($new_base_path);
                                     if ($folder_exists) {
                                         Session::write('orig_base_foldername', $new_base_foldername);
                                         $x = '';
                                         while ($folder_exists) {
                                             $x = $x + 1;
                                             $new_base_foldername = $document_path[1] . '_' . $x;
                                             $new_base_path = $orig_base_path . '_' . $x;
                                             $baseFolder = Session::read('new_base_foldername');
                                             if ($baseFolder == $new_base_foldername) {
                                                 break;
                                             }
                                             $folder_exists = file_exists($new_base_path);
                                         }
                                         Session::write('new_base_foldername', $new_base_foldername);
                                         Session::write('new_base_path', $new_base_path);
                                     }
                                     $sessionVar1 = Session::read('new_base_foldername');
                                     $sessionVar2 = Session::read('new_base_path');
                                     if (isset($sessionVar) && isset($sessionVar2)) {
                                         $new_base_foldername = Session::read('new_base_foldername');
                                         $new_base_path = Session::read('new_base_path');
                                     }
                                     $dest_document_path = $new_base_path . '/' . $document_path[2];
                                     // e.g: "/var/www/wiener/courses/CURSO4/document/carpeta1_1/subcarpeta1/collaborative.png"
                                     $basedir_dest_path = dirname($dest_document_path);
                                     // e.g: "/var/www/wiener/courses/CURSO4/document/carpeta1_1/subcarpeta1"
                                     $base_path_document = $course_path . $document_path[0];
                                     // e.g: "/var/www/wiener/courses/CURSO4/document"
                                     $path_title = '/' . $new_base_foldername . '/' . $document_path[2];
                                     copy_folder_course_session($basedir_dest_path, $base_path_document, $session_id, $course_info, $document, $this->course_origin_id);
                                     if (file_exists($course_path . $document->path)) {
                                         copy($course_path . $document->path, $dest_document_path);
                                     }
                                     //Replace old course code with the new destination code see BT#1985
                                     if (file_exists($dest_document_path)) {
                                         $file_info = pathinfo($dest_document_path);
                                         if (in_array($file_info['extension'], array('html', 'htm'))) {
                                             $content = file_get_contents($dest_document_path);
                                             if (UTF8_CONVERT) {
                                                 $content = utf8_encode($content);
                                             }
                                             $content = DocumentManager::replace_urls_inside_content_html_from_copy_course($content, $this->course->code, $this->course->destination_path, $this->course->backup_path, $this->course->info['path']);
                                             file_put_contents($dest_document_path, $content);
                                         }
                                     }
                                     $params = ['path' => self::DBUTF8($path_title), 'c_id' => $this->destination_course_id, 'comment' => self::DBUTF8($document->comment), 'title' => self::DBUTF8(basename($path_title)), 'filetype' => self::DBUTF8($document->file_type), 'size' => self::DBUTF8($document->size), 'session_id' => $my_session_id];
                                     $document_id = Database::insert($table, $params);
                                     if ($document_id) {
                                         $sql = "UPDATE {$table} SET id = iid WHERE iid = {$document_id}";
                                         Database::query($sql);
                                     }
                                     $this->course->resources[RESOURCE_DOCUMENT][$id]->destination_id = $document_id;
                                     api_item_property_update($course_info, TOOL_DOCUMENT, $document_id, 'DocumentAdded', $document->item_properties[0]['insert_user_id'], $document->item_properties[0]['to_group_id'], $document->item_properties[0]['to_user_id'], null, null, $my_session_id);
                                 } else {
                                     if (file_exists($path . $document->path)) {
                                         copy($path . $document->path, $path . $new_file_name);
                                     }
                                     //Replace old course code with the new destination code see BT#1985
                                     if (file_exists($path . $new_file_name)) {
                                         $file_info = pathinfo($path . $new_file_name);
                                         if (in_array($file_info['extension'], array('html', 'htm'))) {
                                             $content = file_get_contents($path . $new_file_name);
                                             if (UTF8_CONVERT) {
                                                 $content = utf8_encode($content);
                                             }
                                             $content = DocumentManager::replace_urls_inside_content_html_from_copy_course($content, $this->course->code, $this->course->destination_path, $this->course->backup_path, $this->course->info['path']);
                                             file_put_contents($path . $new_file_name, $content);
                                         }
                                     }
                                     $params = ['path' => "/" . self::DBUTF8escapestring(substr($new_file_name, 9)), 'c_id' => $this->destination_course_id, 'comment' => self::DBUTF8($document->comment), 'title' => self::DBUTF8($document->title), 'filetype' => self::DBUTF8($document->file_type), 'size' => self::DBUTF8($document->size), 'session_id' => $my_session_id];
                                     $document_id = Database::insert($table, $params);
                                     if ($document_id) {
                                         $sql = "UPDATE {$table} SET id = iid WHERE iid = {$document_id}";
                                         Database::query($sql);
                                         $this->course->resources[RESOURCE_DOCUMENT][$id]->destination_id = $document_id;
                                         api_item_property_update($course_info, TOOL_DOCUMENT, $document_id, 'DocumentAdded', $document->item_properties[0]['insert_user_id'], $document->item_properties[0]['to_group_id'], $document->item_properties[0]['to_user_id'], null, null, $my_session_id);
                                     }
                                 }
                             } else {
                                 copy($this->course->backup_path . '/' . $document->path, $path . $new_file_name);
                                 //Replace old course code with the new destination code see BT#1985
                                 if (file_exists($path . $new_file_name)) {
                                     $file_info = pathinfo($path . $new_file_name);
                                     if (in_array($file_info['extension'], array('html', 'htm'))) {
                                         $content = file_get_contents($path . $new_file_name);
                                         if (UTF8_CONVERT) {
                                             $content = utf8_encode($content);
                                         }
                                         $content = DocumentManager::replace_urls_inside_content_html_from_copy_course($content, $this->course->code, $this->course->destination_path, $this->course->backup_path, $this->course->info['path']);
                                         file_put_contents($path . $new_file_name, $content);
                                     }
                                 }
                                 $params = ['c_id' => $this->destination_course_id, 'path' => "/" . self::DBUTF8escapestring(substr($new_file_name, 9)), 'comment' => self::DBUTF8($document->comment), 'title' => self::DBUTF8($document->title), 'filetype' => self::DBUTF8($document->file_type), 'size' => self::DBUTF8($document->size), 'session_id' => $my_session_id];
                                 $document_id = Database::insert($table, $params);
                                 if ($document_id) {
                                     $sql = "UPDATE {$table} SET id = iid WHERE iid = {$document_id}";
                                     Database::query($sql);
                                 }
                                 $this->course->resources[RESOURCE_DOCUMENT][$id]->destination_id = $document_id;
                                 api_item_property_update($course_info, TOOL_DOCUMENT, $document_id, 'DocumentAdded', $document->item_properties[0]['insert_user_id'], $document->item_properties[0]['to_group_id'], $document->item_properties[0]['to_user_id'], null, null, $my_session_id);
                             }
                             break;
                     }
                     // end switch
                 } else {
                     // end if file exists
                     //make sure the source file actually exists
                     if (is_file($this->course->backup_path . '/' . $document->path) && is_readable($this->course->backup_path . '/' . $document->path) && is_dir(dirname($path . $document->path)) && is_writeable(dirname($path . $document->path))) {
                         //echo 'Copying';
                         copy($this->course->backup_path . '/' . $document->path, $path . $document->path);
                         //Replace old course code with the new destination code see BT#1985
                         if (file_exists($path . $document->path)) {
                             $file_info = pathinfo($path . $document->path);
                             if (in_array($file_info['extension'], array('html', 'htm'))) {
                                 $content = file_get_contents($path . $document->path);
                                 if (UTF8_CONVERT) {
                                     $content = utf8_encode($content);
                                 }
                                 $content = DocumentManager::replace_urls_inside_content_html_from_copy_course($content, $this->course->code, $this->course->destination_path, $this->course->backup_path, $this->course->info['path']);
                                 file_put_contents($path . $document->path, $content);
                             }
                         }
                         $params = ['c_id' => $this->destination_course_id, 'path' => "/" . self::DBUTF8(substr($document->path, 9)), 'comment' => self::DBUTF8($document->comment), 'title' => self::DBUTF8($document->title), 'filetype' => self::DBUTF8($document->file_type), 'size' => self::DBUTF8($document->size), 'session_id' => $my_session_id];
                         $document_id = Database::insert($table, $params);
                         if ($document_id) {
                             $sql = "UPDATE {$table} SET id = iid WHERE iid = {$document_id}";
                             Database::query($sql);
                         }
                         $this->course->resources[RESOURCE_DOCUMENT][$id]->destination_id = $document_id;
                         api_item_property_update($course_info, TOOL_DOCUMENT, $document_id, 'DocumentAdded', $document->item_properties[0]['insert_user_id'], $document->item_properties[0]['to_group_id'], $document->item_properties[0]['to_user_id'], null, null, $my_session_id);
                     } else {
                         //echo 'not Copying';
                         if (is_file($this->course->backup_path . '/' . $document->path) && is_readable($this->course->backup_path . '/' . $document->path)) {
                             error_log('Course copy generated an ignoreable error while trying to copy ' . $this->course->backup_path . '/' . $document->path . ': file not found');
                         }
                         if (!is_dir(dirname($path . $document->path))) {
                             error_log('Course copy generated an ignoreable error while trying to copy to ' . dirname($path . $document->path) . ': directory not found');
                         }
                         if (!is_writeable(dirname($path . $document->path))) {
                             error_log('Course copy generated an ignoreable error while trying to copy to ' . dirname($path . $document->path) . ': directory not writeable');
                         }
                     }
                 }
                 // end file doesn't exist
             }
         }
         // end for each
         // Delete sessions for the copy the new folder in session
         Session::erase('new_base_foldername');
         Session::erase('orig_base_foldername');
         Session::erase('new_base_path');
     }
 }
 /**
  * Create a group
  * @param string $name The name for this group
  * @param int $category_id
  * @param int $tutor The user-id of the group's tutor
  * @param int $places How many people can subscribe to the new group
  */
 public static function create_group($name, $category_id, $tutor, $places)
 {
     $_course = api_get_course_info();
     $session_id = api_get_session_id();
     $course_id = $_course['real_id'];
     $currentCourseRepository = $_course['path'];
     $category = self::get_category($category_id);
     $places = intval($places);
     if ($category) {
         if ($places == 0) {
             //if the amount of users per group is not filled in, use the setting from the category
             $places = $category['max_student'];
         } else {
             if ($places > $category['max_student'] && $category['max_student'] != 0) {
                 $places = $category['max_student'];
             }
         }
         $docState = $category['doc_state'];
         $calendarState = $category['calendar_state'];
         $workState = $category['work_state'];
         $anonuncementState = $category['announcements_state'];
         $forumState = $category['forum_state'];
         $wikiState = $category['wiki_state'];
         $chatState = $category['chat_state'];
         $selfRegAllowed = $category['self_reg_allowed'];
         $selfUnregAllwoed = $category['self_unreg_allowed'];
     } else {
         $docState = self::TOOL_PRIVATE;
         $calendarState = self::TOOL_PRIVATE;
         $workState = self::TOOL_PRIVATE;
         $anonuncementState = self::TOOL_PRIVATE;
         $forumState = self::TOOL_PRIVATE;
         $wikiState = self::TOOL_PRIVATE;
         $chatState = self::TOOL_PRIVATE;
         $selfRegAllowed = 0;
         $selfUnregAllwoed = 0;
     }
     $table_group = Database::get_course_table(TABLE_GROUP);
     $sql = "INSERT INTO " . $table_group . " SET\n                c_id = {$course_id},\n                status = 1,\n                category_id='" . Database::escape_string($category_id) . "',\n                max_student = '" . $places . "',\n                doc_state = '" . $docState . "',\n                calendar_state = '" . $calendarState . "',\n                work_state = '" . $workState . "',\n                announcements_state = '" . $anonuncementState . "',\n                forum_state = '" . $forumState . "',\n                wiki_state = '" . $wikiState . "',\n                chat_state = '" . $chatState . "',\n                self_registration_allowed = '" . $selfRegAllowed . "',\n                self_unregistration_allowed = '" . $selfUnregAllwoed . "',\n                session_id='" . intval($session_id) . "'";
     Database::query($sql);
     $lastId = Database::insert_id();
     if ($lastId) {
         $sql = "UPDATE {$table_group} SET id = iid WHERE iid = {$lastId}";
         Database::query($sql);
         $desired_dir_name = '/' . api_replace_dangerous_char($name) . '_groupdocs';
         $my_path = api_get_path(SYS_COURSE_PATH) . $currentCourseRepository . '/document';
         $newFolderData = create_unexisting_directory($_course, api_get_user_id(), $session_id, $lastId, null, $my_path, $desired_dir_name, null, 1);
         $unique_name = $newFolderData['path'];
         /* Stores the directory path into the group table */
         $sql = "UPDATE " . $table_group . " SET\n                        name = '" . Database::escape_string($name) . "',\n                        secret_directory = '" . $unique_name . "'\n                    WHERE c_id = {$course_id} AND id ='" . $lastId . "'";
         Database::query($sql);
         // create a forum if needed
         if ($forumState >= 0) {
             require_once api_get_path(SYS_CODE_PATH) . 'forum/forumconfig.inc.php';
             require_once api_get_path(SYS_CODE_PATH) . 'forum/forumfunction.inc.php';
             $forum_categories = get_forum_categories();
             $values = array();
             $values['forum_title'] = $name;
             $values['group_id'] = $lastId;
             $counter = 0;
             foreach ($forum_categories as $key => $value) {
                 if ($counter == 0) {
                     $forum_category_id = $key;
                 }
                 $counter++;
             }
             // A sanity check.
             if (empty($forum_category_id)) {
                 $forum_category_id = 0;
             }
             $values['forum_category'] = $forum_category_id;
             $values['allow_anonymous_group']['allow_anonymous'] = 0;
             $values['students_can_edit_group']['students_can_edit'] = 0;
             $values['approval_direct_group']['approval_direct'] = 0;
             $values['allow_attachments_group']['allow_attachments'] = 1;
             $values['allow_new_threads_group']['allow_new_threads'] = 1;
             $values['default_view_type_group']['default_view_type'] = api_get_setting('forum.default_forum_view');
             $values['group_forum'] = $lastId;
             if ($forumState == '1') {
                 $values['public_private_group_forum_group']['public_private_group_forum'] = 'public';
             } elseif ($forumState == '2') {
                 $values['public_private_group_forum_group']['public_private_group_forum'] = 'private';
             } elseif ($forumState == '0') {
                 $values['public_private_group_forum_group']['public_private_group_forum'] = 'unavailable';
             }
             store_forum($values);
         }
     }
     return $lastId;
 }
Example #17
0
     error_log("upload" . $_FILES['Filedata']);
 }
 /*==== PERMISSION ====*/
 $permissions = CourseManager::get_user_in_course_status($user_id, $cidReq);
 if ($permissions != COURSEMANAGER) {
     if ($debug > 0) {
         error_log("Upload from videoconf not allowed !!!", 0);
     }
     die('Not allowed');
     // this user is not allowed to add upload documents
 }
 /*==== UPLOAD ====*/
 $destPath = $coursePath . VIDEOCONF_UPLOAD_PATH;
 /*==== creation of /videoconf ====*/
 if (!is_dir($destPath)) {
     $result = create_unexisting_directory($_course, $user_id, api_get_session_id(), 0, NULL, $coursePath, VIDEOCONF_UPLOAD_PATH);
     if (!$result) {
         if ($debug > 0) {
             error_log("Can't create " . $destPath . " folder", 0);
         }
     }
 }
 /*==== file upload ====*/
 $newPath = $_FILES['Filedata']['name'];
 if ($debug > 0) {
     error_log($newPath);
 }
 /*==== extension extraction ====*/
 $file_name = strrpos($newPath, '.') > 0 ? substr($newPath, 0, strrpos($newPath, '.')) : $newPath;
 $file_extension = strrpos($newPath, '.') > 0 ? substr($newPath, strrpos($newPath, '.'), 10) : '';
 if ($debug > 0) {