/**
  * Used to convert copied from document
  * @param string $originalPath
  * @param string $convertedPath
  * @param string $convertedTitle
  * @return bool
  */
 function convertCopyDocument($originalPath, $convertedPath, $convertedTitle)
 {
     $_course = api_get_course_info();
     $ids = array();
     $originalPathInfo = pathinfo($originalPath);
     $convertedPathInfo = pathinfo($convertedPath);
     $this->base_work_dir = $originalPathInfo['dirname'];
     $this->file_path = $originalPathInfo['basename'];
     $this->created_dir = $convertedPathInfo['basename'];
     $ppt2lpHost = api_get_setting('ppt_to_lp.host');
     $permissionFile = api_get_permissions_for_new_files();
     $permissionFolder = api_get_permissions_for_new_directories();
     if (file_exists($this->base_work_dir . '/' . $this->created_dir)) {
         return $ids;
     }
     if ($ppt2lpHost == 'localhost') {
         if (IS_WINDOWS_OS) {
             // IS_WINDOWS_OS has been defined in main_api.lib.php
             $converterPath = str_replace('/', '\\', api_get_path(SYS_PATH) . 'main/inc/lib/ppt2png');
             $classPath = $converterPath . ';' . $converterPath . '/jodconverter-2.2.2.jar;' . $converterPath . '/jodconverter-cli-2.2.2.jar';
             $cmd = 'java -Dfile.encoding=UTF-8 -jar "' . $classPath . '/jodconverter-2.2.2.jar"';
         } else {
             $converterPath = api_get_path(SYS_PATH) . 'main/inc/lib/ppt2png';
             $classPath = ' -Dfile.encoding=UTF-8 -jar jodconverter-cli-2.2.2.jar';
             $cmd = 'cd ' . $converterPath . ' && java ' . $classPath . ' ';
         }
         $cmd .= ' -p ' . api_get_setting('ppt_to_lp.port');
         // Call to the function implemented by child.
         $cmd .= ' "' . $this->base_work_dir . '/' . $this->file_path . '"  "' . $this->base_work_dir . '/' . $this->created_dir . '"';
         // To allow openoffice to manipulate docs.
         @chmod($this->base_work_dir, $permissionFolder);
         @chmod($this->base_work_dir . '/' . $this->file_path, $permissionFile);
         $locale = $this->original_locale;
         // TODO: Improve it because we're not sure this locale is present everywhere.
         putenv('LC_ALL=' . $locale);
         $files = array();
         $return = 0;
         $shell = exec($cmd, $files, $return);
         // TODO: Chown is not working, root keep user privileges, should be www-data
         @chown($this->base_work_dir . '/' . $this->created_dir, 'www-data');
         @chmod($this->base_work_dir . '/' . $this->created_dir, $permissionFile);
         if ($return != 0) {
             // If the java application returns an error code.
             switch ($return) {
                 // Can't connect to openoffice.
                 case 1:
                     $this->error = get_lang('CannotConnectToOpenOffice');
                     break;
                     // Conversion failed in openoffice.
                 // Conversion failed in openoffice.
                 case 2:
                     $this->error = get_lang('OogieConversionFailed');
                     break;
                     // Conversion can't be launch because command failed.
                 // Conversion can't be launch because command failed.
                 case 255:
                     $this->error = get_lang('OogieUnknownError');
                     break;
             }
             DocumentManager::delete_document($_course, $this->created_dir, $this->base_work_dir);
             return false;
         }
     } else {
         /*
          * @TODO Create method to use webservice
         // get result from webservices
         $result = $this->_get_remote_ppt2lp_files($file);
         $result = unserialize(base64_decode($result));
         
         // Save remote images to server
         chmod($this->base_work_dir.$this->created_dir, api_get_permissions_for_new_directories());
         if (!empty($result['images'])) {
             foreach ($result['images'] as $image => $img_data) {
                 $image_path = $this->base_work_dir.$this->created_dir;
                 @file_put_contents($image_path . '/' . $image, base64_decode($img_data));
                 @chmod($image_path . '/' . $image, 0777);
             }
         }
         
         // files info
         $files = $result['files'];
         */
     }
     if (file_exists($this->base_work_dir . '/' . $this->created_dir)) {
         // Register Files to Document tool
         $ids[] = add_document($_course, '/' . $this->created_dir, 'file', filesize($this->base_work_dir . '/' . $this->created_dir), $convertedTitle, sprintf(get_lang('FileConvertedFromXToY'), strtoupper($originalPathInfo['extension']), strtoupper($convertedPathInfo['extension'])), 0, true, null, api_get_session_id());
         chmod($this->base_work_dir, $permissionFolder);
     }
     return $ids;
 }
예제 #2
0
 /**
  * deletes groups and their data.
  * @author Christophe Gesche <*****@*****.**>
  * @author Hugues Peeters <*****@*****.**>
  * @author Bart Mollet
  * @param  mixed   $groupIdList - group(s) to delete. It can be a single id
  *                                (int) or a list of id (array).
  * @param string $course_code Default is current course
  * @return integer              - number of groups deleted.
  */
 public static function delete_groups($group_ids, $course_code = null)
 {
     $course_info = api_get_course_info($course_code);
     $course_id = $course_info['real_id'];
     // Database table definitions
     $group_table = Database::get_course_table(TABLE_GROUP);
     $forum_table = Database::get_course_table(TABLE_FORUM);
     $group_ids = is_array($group_ids) ? $group_ids : array($group_ids);
     $group_ids = array_map('intval', $group_ids);
     if (!api_is_platform_admin() && api_is_course_coach()) {
         // A coach can only delete courses from his session
         for ($i = 0; $i < count($group_ids); $i++) {
             if (!api_is_element_in_the_session(TOOL_GROUP, $group_ids[$i])) {
                 array_splice($group_ids, $i, 1);
                 $i--;
             }
         }
         if (count($group_ids) == 0) {
             return 0;
         }
     }
     // Unsubscribe all users
     self::unsubscribe_all_users($group_ids);
     $sql = "SELECT iid, secret_directory, session_id\n                FROM {$group_table}\n                WHERE c_id = {$course_id} AND iid IN (" . implode(' , ', $group_ids) . ")";
     $db_result = Database::query($sql);
     while ($group = Database::fetch_object($db_result)) {
         // move group-documents to garbage
         $source_directory = api_get_path(SYS_COURSE_PATH) . $course_info['path'] . "/document" . $group->secret_directory;
         //File to renamed
         $destination_dir = api_get_path(SYS_COURSE_PATH) . $course_info['path'] . "/document" . $group->secret_directory . '_DELETED_' . $group->iid;
         if (!empty($group->secret_directory)) {
             //Deleting from document tool
             DocumentManager::delete_document($course_info, $group->secret_directory, $source_directory);
             if (file_exists($source_directory)) {
                 if (api_get_setting('permanently_remove_deleted_files') == 'true') {
                     // Delete
                     my_delete($source_directory);
                 } else {
                     // Rename
                     rename($source_directory, $destination_dir);
                 }
             }
         }
     }
     // delete the groups
     $sql = "DELETE FROM " . $group_table . " WHERE c_id = {$course_id} AND iid IN ('" . implode("' , '", $group_ids) . "')";
     Database::query($sql);
     $sql = "DELETE FROM " . $forum_table . " WHERE c_id = {$course_id} AND forum_of_group IN ('" . implode("' , '", $group_ids) . "')";
     Database::query($sql);
     return Database::affected_rows($result);
 }
예제 #3
0
 /**
  *
  * Delete documents from a session in a course.
  * @param array $courseInfo
  * @param int $sessionId
  *
  * @return bool
  */
 public function deleteDocumentsFromSession($courseInfo, $sessionId)
 {
     if (empty($courseInfo)) {
         return false;
     }
     if (empty($sessionId)) {
         return false;
     }
     $itemPropertyTable = Database::get_course_table(TABLE_ITEM_PROPERTY);
     $documentTable = Database::get_course_table(TABLE_DOCUMENT);
     $conditionSession = api_get_session_condition($sessionId, true, false, 'd.session_id');
     //get invisible folders
     $sql = "SELECT DISTINCT d.id, path\n                FROM {$itemPropertyTable} i\n                INNER JOIN {$documentTable} d\n                ON (i.c_id = d.c_id)\n                WHERE\n                    d.id = i.ref AND\n                    i.tool = '" . TOOL_DOCUMENT . "'\n                    {$conditionSession} AND\n                    i.c_id = {$courseInfo['real_id']} AND\n                    d.c_id = {$courseInfo['real_id']} ";
     $result = Database::query($sql);
     $documents = Database::store_result($result, 'ASSOC');
     if ($documents) {
         $course_dir = $courseInfo['directory'] . '/document';
         $sys_course_path = api_get_path(SYS_COURSE_PATH);
         $base_work_dir = $sys_course_path . $course_dir;
         foreach ($documents as $document) {
             $documentId = $document['id'];
             DocumentManager::delete_document($courseInfo, null, $base_work_dir, $sessionId, $documentId);
         }
     }
 }
예제 #4
0
             if ($permissions != COURSEMANAGER) {
                 if ($debug > 0) {
                     error_log("Upload from videoconf not allowed !!!", 0);
                 }
                 die;
                 // this user is not allowed to add upload documents
             }
             /*==== DELETE ====*/
             $path = str_replace('../', '', $_REQUEST["path"]);
             if (substr($path, 0, strlen(VIDEOCONF_UPLOAD_PATH)) != VIDEOCONF_UPLOAD_PATH) {
                 if ($debug > 0) {
                     error_log("Delete from videoconf for " + $path + " NOT ALLOWED", 0);
                 }
                 die;
             }
             DocumentManager::delete_document($_course, $path, $coursePath);
             echo "<result>OK</result>";
             // We have to return something to OpenLaszlo
         }
     }
 } else {
     if ($action == "download") {
         /*==== DOWNLOAD ====*/
         //check if the document is in the database
         if (!DocumentManager::get_document_id($_course, $_REQUEST['file'])) {
             //file not found!
             if ($debug > 0) {
                 error_log("404 " . $_REQUEST["file"]);
             }
             header("HTTP/1.0 404 Not Found");
             $error404 = '<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">';
예제 #5
0
                        $fullPath = $doc;
                        //get Ajaxfilemanager
                        $chamiloPath = substr($fullPath, strlen($mainPath) - strlen($fullPath) - 1);
                        //find base_work_dir
                        $course_dir = $_course['path'] . "/document";
                        //get Chamilo
                        $sys_course_path = api_get_path(SYS_COURSE_PATH);
                        //get Chamilo
                        $base_work_dir = $sys_course_path . $course_dir;
                        // sample c:/xampp/htdocs/chamilo2009beta/courses/JUAN2009/document
                        //delete file
                        if (!$is_allowed_to_edit && DocumentManager::check_readonly($_course, api_get_user_id(), $chamiloPath)) {
                            $error = get_lang('CantDeleteReadonlyFiles');
                            //From Chamilo to Ajaxfilemanager
                        } else {
                            $deleted = DocumentManager::delete_document($_course, $chamiloPath, $base_work_dir);
                            //deleted by Chamilo
                            //$file->delete($doc); // disabled deleted by ajaxfilemanager
                        }
                    } else {
                        $file->delete($doc);
                        //deleted by ajaxfilemanager
                        event_system(LOG_USER_PERSONAL_DOC_DELETED, 'document_path', $doc);
                        event_system(LOG_MY_FOLDER_DELETE, LOG_MY_FOLDER_PATH, $doc);
                    }
                    //////end bridge to Chamilo
                }
            }
        }
    }
}
예제 #6
0
                    case 'delete':
                        // Check all documents scheduled for deletion
                        // If one of them is read-only, abandon deletion
                        // Note: this is only executed once
                        if (!$readonlyAlreadyChecked) {
                            foreach ($files as $id) {
                                if (!$is_allowed_to_edit) {
                                    if (DocumentManager::check_readonly($courseInfo, api_get_user_id(), null, $id, false, $sessionId)) {
                                        $messages .= Display::return_message(get_lang('CantDeleteReadonlyFiles'), 'error');
                                        break 2;
                                    }
                                }
                            }
                            $readonlyAlreadyChecked = true;
                        }
                        $deleteDocument = DocumentManager::delete_document($courseInfo, null, $base_work_dir, $sessionId, $documentId, $groupId);
                        if (!empty($deleteDocument)) {
                            $messages .= Display::return_message(get_lang('DocDeleted') . ': ' . $data['title'], 'confirmation');
                        }
                        break;
                }
            }
        }
        // endforeach
        Display::addFlash($messages);
    }
}
$dirForm = null;
/* 	CREATE DIRECTORY */
//Only teacher and all users into their group and any user into his/her shared folder
if ($is_allowed_to_edit || $group_member_with_upload_rights || DocumentManager::is_my_shared_folder(api_get_user_id(), $curdirpath, $sessionId)) {
예제 #7
0
    if (isset($_POST['action'])) {
        switch ($_POST['action']) {
            case 'delete':
                foreach ($_POST['path'] as $index => &$path) {
                    if (!$is_allowed_to_edit) {
                        if (DocumentManager::check_readonly($_course, api_get_user_id(), $path)) {
                            Display::display_error_message(get_lang('CantDeleteReadonlyFiles'));
                            break 2;
                        }
                    }
                }
                foreach ($_POST['path'] as $index => &$path) {
                    if (in_array($path, array('/audio', '/flash', '/images', '/shared_folder', '/video', '/chat_files', '/certificates'))) {
                        continue;
                    } else {
                        $delete_document = DocumentManager::delete_document($_course, $path, $base_work_dir);
                    }
                }
                if (!empty($delete_document)) {
                    Display::display_confirmation_message(get_lang('DocDeleted'));
                }
                break;
        }
    }
}
/*	CREATE DIRECTORY */
//Only teacher and all users into their group and any user into his/her shared folder
if ($is_allowed_to_edit || $group_member_with_upload_rights || is_my_shared_folder(api_get_user_id(), $curdirpath, $session_id)) {
    // Create directory with $_POST data
    if (isset($_POST['create_dir']) && $_POST['dirname'] != '') {
        // Needed for directory creation
예제 #8
0
 /**
  * {@inheritdoc}
  */
 public function rm($hash)
 {
     // elfinder does not delete the file
     //parent::rm($hash);
     $this->setConnectorFromPlugin();
     if ($this->allow()) {
         $path = $this->decode($hash);
         $stat = $this->stat($path);
         $stat['realpath'] = $path;
         $this->removed[] = $stat;
         $realFilePath = $path;
         $coursePath = $this->getCourseDocumentSysPath();
         $filePath = str_replace($coursePath, '/', $realFilePath);
         \DocumentManager::delete_document($this->connector->course, $filePath, $coursePath);
         return true;
     }
     return false;
 }
예제 #9
0
 /**
  * Delete directories recursively.
  * @param string $relative the relative path to be deleted.
  * @return boolean true if deleted, false otherwise.
  */
 function _delDir($relative)
 {
     $fullpath = Files::makePath($this->getBaseDir(), $relative);
     //we can delete recursively	even if there are images in the dir
     //if($this->countFiles($fullpath) <= 0) {
     // now we use the default delete_document function
     //return Files::delFolder($fullpath,true); //delete recursively.
     global $_course;
     if (isset($_course) && !empty($_course) && isset($_course['code'])) {
         $path_dir = substr($fullpath, strpos($fullpath, '/document/') + 9, -1);
         //
         $base_dir = substr($fullpath, 0, strlen($fullpath) - strlen($path_dir));
         //
         return DocumentManager::delete_document($_course, $path_dir, $base_dir);
     } else {
         if ($this->countFiles($fullpath) <= 0) {
             return Files::delFolder($fullpath, true);
         } else {
             return false;
         }
     }
 }
예제 #10
0
파일: lp.php 프로젝트: daffef/chamilo-lms
/**
 * @param array $params
 * @return int|string
 */
function WSDeleteLp($params)
{
    global $debug;
    if (!WSHelperVerifyKey($params)) {
        return return_error(WS_ERROR_SECRET_KEY);
    }
    require_once api_get_path(SYS_CODE_PATH) . 'newscorm/learnpathList.class.php';
    require_once api_get_path(SYS_CODE_PATH) . 'newscorm/learnpath.class.php';
    require_once api_get_path(SYS_CODE_PATH) . 'newscorm/learnpathItem.class.php';
    $courseIdName = $params['course_id_name'];
    $courseIdValue = $params['course_id_value'];
    $lpId = $params['lp_id'];
    $sessionIdName = isset($params['session_id_name']) ? $params['session_id_name'] : null;
    $sessionIdValue = isset($params['session_id_value']) ? $params['session_id_value'] : null;
    $courseInfo = CourseManager::getCourseInfoFromOriginalId($courseIdValue, $courseIdName);
    if (empty($courseInfo)) {
        if ($debug) {
            error_log("Course not found: {$courseIdName} : {$courseIdValue}");
        }
        return 'Course not found';
    }
    $courseId = $courseInfo['real_id'];
    $courseCode = $courseInfo['code'];
    $sessionId = 0;
    /*
    if (!empty($sessionIdName) && !empty($sessionIdValue)) {
        $sessionId = SessionManager::get_session_id_from_original_id(
            $sessionIdValue,
            $sessionIdName
        );
    
        if (empty($sessionId)) {
    
            if ($debug) error_log('Session not found');
            return 'Session not found';
        }
    }
    */
    $lp = new learnpath($courseCode, $lpId, null);
    if ($lp) {
        if ($debug) {
            error_log("LP deleted {$lpId}");
        }
        $course_dir = $courseInfo['directory'] . '/document';
        $sys_course_path = api_get_path(SYS_COURSE_PATH);
        $base_work_dir = $sys_course_path . $course_dir;
        $items = $lp->get_flat_ordered_items_list($lpId, 0, $courseId);
        if (!empty($items)) {
            /** @var $item learnpathItem */
            foreach ($items as $itemId) {
                $item = new learnpathItem($itemId, null, $courseId);
                if ($item) {
                    $documentId = $item->get_path();
                    if ($debug) {
                        error_log("lp item id found #{$itemId}");
                    }
                    $documentInfo = DocumentManager::get_document_data_by_id($documentId, $courseInfo['code'], false, $sessionId);
                    if (!empty($documentInfo)) {
                        if ($debug) {
                            error_log("Document id deleted #{$documentId}");
                        }
                        DocumentManager::delete_document($courseInfo, null, $base_work_dir, $sessionId, $documentId);
                    } else {
                        if ($debug) {
                            error_log("No document found for id #{$documentId}");
                        }
                    }
                } else {
                    if ($debug) {
                        error_log("Document not found #{$itemId}");
                    }
                }
            }
        }
        $lp->delete($courseInfo, $lpId, 'remove');
        return 1;
    }
    return 0;
}
 public function convert_document($file, $action_after_conversion = 'make_lp')
 {
     $_course = api_get_course_info();
     $this->file_name = pathinfo($file['name'], PATHINFO_FILENAME);
     // Create the directory
     $result = $this->generate_lp_folder($_course, $this->file_name);
     // Create the directory
     $this->base_work_dir = api_get_path(SYS_COURSE_PATH) . $_course['path'] . '/document';
     ///learning_path/ppt_dirname directory
     $this->created_dir = substr($result['dir'], 0, strlen($result['dir']) - 1);
     $this->file_path = $this->created_dir . '/' . api_replace_dangerous_char($file['name'], 'strict');
     //var_dump($this->file_name, $this->file_path, $this->base_work_dir, $this->created_dir);
     /*
              * Original code
             global $_course, $_user, $_configuration;
     $this->file_name = (strrpos($file['name'], '.') > 0 ? substr($file['name'], 0, strrpos($file['name'], '.')) : $file['name']);
             $this->file_name = replace_dangerous_char($this->file_name, 'strict');
             $this->file_name = strtolower($this->file_name);
     $visio_dir = ($action_after_conversion == 'add_docs_to_visio') ? VIDEOCONF_UPLOAD_PATH : '';
     $this->file_path = $visio_dir.'/'.$this->file_name.'.'.pathinfo($file['name'], PATHINFO_EXTENSION);
     $dir_name = $visio_dir.'/'.$this->file_name;
     
     // Create the directory.
             $this->base_work_dir = api_get_path(SYS_COURSE_PATH).$_course['path'].'/document';
     $this->created_dir = FileManager::create_unexisting_directory($_course, $_user['user_id'], api_get_session_id(), 0, 0, $this->base_work_dir, $dir_name);
         var_dump($this->file_name, $this->file_path, $this->base_work_dir, $this->created_dir);
     */
     $ppt2lp_host = api_get_setting('service_ppt2lp', 'host');
     if ($ppt2lp_host == 'localhost') {
         move_uploaded_file($file['tmp_name'], $this->base_work_dir . '/' . $this->file_path);
         //var_dump( $this->base_work_dir.$this->created_dir.$this->file_path);
         $perm = api_get_setting('permissions_for_new_files');
         if (IS_WINDOWS_OS) {
             // IS_WINDOWS_OS has been defined in api.lib.php
             $converter_path = str_replace('/', '\\', api_get_path(SYS_PATH) . 'main/inc/lib/ppt2png');
             $class_path = $converter_path . ';' . $converter_path . '/jodconverter-2.2.2.jar;' . $converter_path . '/jodconverter-cli-2.2.2.jar';
             //$cmd = 'java -cp "'.$class_path.'" DokeosConverter';
             $cmd = 'java -Dfile.encoding=UTF-8 -cp "' . $class_path . '" DokeosConverter';
         } else {
             $converter_path = api_get_path(SYS_PATH) . 'main/inc/lib/ppt2png';
             //$class_path = '-cp .:jodconverter-2.2.1.jar:jodconverter-cli-2.2.1.jar';
             $class_path = ' -Dfile.encoding=UTF-8 -cp .:jodconverter-2.2.2.jar:jodconverter-cli-2.2.2.jar';
             $cmd = 'cd ' . $converter_path . ' && java ' . $class_path . ' DokeosConverter';
         }
         $cmd .= ' -p ' . api_get_setting('service_ppt2lp', 'port');
         // Call to the function implemented by child.
         $cmd .= $this->add_command_parameters();
         // To allow openoffice to manipulate docs.
         @chmod($this->base_work_dir, 0777);
         @chmod($this->base_work_dir . $this->created_dir, 0777);
         @chmod($this->base_work_dir . $this->file_path, 0777);
         $locale = $this->original_locale;
         // TODO: Improve it because we're not sure this locale is present everywhere.
         putenv('LC_ALL=' . $locale);
         $files = array();
         $return = 0;
         $shell = exec($cmd, $files, $return);
         if ($return != 0) {
             // If the java application returns an error code.
             switch ($return) {
                 // Can't connect to openoffice.
                 case 1:
                     $this->error = get_lang('CannotConnectToOpenOffice');
                     break;
                     // Conversion failed in openoffice.
                 // Conversion failed in openoffice.
                 case 2:
                     $this->error = get_lang('OogieConversionFailed');
                     break;
                     // Conversion can't be launch because command failed.
                 // Conversion can't be launch because command failed.
                 case 255:
                     $this->error = get_lang('OogieUnknownError');
                     break;
             }
             DocumentManager::delete_document($_course, $this->created_dir, $this->base_work_dir);
             return false;
         }
     } else {
         // get result from webservices
         $result = $this->_get_remote_ppt2lp_files($file);
         $result = unserialize(base64_decode($result));
         // Save remote images to server
         chmod($this->base_work_dir . $this->created_dir, api_get_permissions_for_new_directories());
         if (!empty($result['images'])) {
             foreach ($result['images'] as $image => $img_data) {
                 $image_path = $this->base_work_dir . $this->created_dir;
                 @file_put_contents($image_path . '/' . $image, base64_decode($img_data));
                 @chmod($image_path . '/' . $image, 0777);
             }
         }
         // files info
         $files = $result['files'];
     }
     if (!empty($files)) {
         // Create lp
         $this->lp_id = learnpath::add_lp($_course['id'], $this->file_name, '', 'guess', 'manual');
         // Call to the function implemented by child following action_after_conversion parameter.
         switch ($action_after_conversion) {
             case 'make_lp':
                 $this->make_lp($files);
                 break;
             case 'add_docs_to_visio':
                 $this->add_docs_to_visio($files);
                 break;
         }
         chmod($this->base_work_dir, api_get_permissions_for_new_directories());
     }
     return $this->first_item;
 }