if (!api_is_allowed_to_edit()) {
         api_not_allowed(true);
     }
     if ($debug > 0) {
         error_log('New LP - add_lp action triggered', 0);
     }
     $_REQUEST['learnpath_name'] = trim($_REQUEST['learnpath_name']);
     if (!empty($_REQUEST['learnpath_name'])) {
         $_SESSION['refresh'] = 1;
         if (isset($_SESSION['post_time']) && $_SESSION['post_time'] == $_REQUEST['post_time']) {
             require 'lp_add.php';
         } else {
             $_SESSION['post_time'] = $_REQUEST['post_time'];
             //Kevin Van Den Haute: changed $_REQUEST['learnpath_description'] by '' because it's not used
             //old->$new_lp_id = learnpath::add_lp(api_get_course_id(), $_REQUEST['learnpath_name'], $_REQUEST['learnpath_description'], 'dokeos', 'manual', '');
             $new_lp_id = learnpath::add_lp(api_get_course_id(), Security::remove_XSS($_REQUEST['learnpath_name']), '', 'dokeos', 'manual', '');
             //learnpath::toggle_visibility($new_lp_id,'v');
             //Kevin Van Den Haute: only go further if learnpath::add_lp has returned an id
             if (is_numeric($new_lp_id)) {
                 //TODO maybe create a first module directly to avoid bugging the user with useless queries
                 $_SESSION['oLP'] = new learnpath(api_get_course_id(), $new_lp_id, api_get_user_id());
                 //$_SESSION['oLP']->add_item(0,-1,'dokeos_chapter',$_REQUEST['path'],'Default');
                 require 'lp_build.php';
             }
         }
     } else {
         require 'lp_add.php';
     }
     break;
 case 'admin_view':
     if (!api_is_allowed_to_edit()) {
 /**
  * @param string $file
  * @param string $action_after_conversion
  * @return bool|int
  */
 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']);
     //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 = api_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 = 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('ppt_to_lp.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 main_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('ppt_to_lp.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($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');
         // make sure we have a course code available for later
         $this->cc = $_course['id'];
         // 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;
 }
             require 'lp_add.php';
         } else {
             $_SESSION['post_time'] = $_REQUEST['post_time'];
             if (isset($_REQUEST['activate_start_date_check']) && $_REQUEST['activate_start_date_check'] == 1) {
                 $publicated_on = $_REQUEST['publicated_on'];
                 $publicated_on = $publicated_on['Y'] . '-' . $publicated_on['F'] . '-' . $publicated_on['d'] . ' ' . $publicated_on['H'] . ':' . $publicated_on['i'] . ':00';
             } else {
                 $publicated_on = null;
             }
             if (isset($_REQUEST['activate_end_date_check']) && $_REQUEST['activate_end_date_check'] == 1) {
                 $expired_on = $_REQUEST['expired_on'];
                 $expired_on = $expired_on['Y'] . '-' . $expired_on['F'] . '-' . $expired_on['d'] . ' ' . $expired_on['H'] . ':' . $expired_on['i'] . ':00';
             } else {
                 $expired_on = null;
             }
             $new_lp_id = learnpath::add_lp(api_get_course_id(), Security::remove_XSS($_REQUEST['lp_name']), '', 'chamilo', 'manual', '', $publicated_on, $expired_on, $_REQUEST['category_id']);
             if (is_numeric($new_lp_id)) {
                 // TODO: Maybe create a first module directly to avoid bugging the user with useless queries
                 $_SESSION['oLP'] = new learnpath(api_get_course_id(), $new_lp_id, api_get_user_id());
                 //require 'lp_build.php';
                 $url = api_get_self() . '?action=add_item&type=step&lp_id=' . intval($new_lp_id);
                 header('Location: ' . $url);
                 exit;
             }
         }
     } else {
         require 'lp_add.php';
     }
     break;
 case 'admin_view':
     if (!$is_allowed_to_edit) {
Esempio n. 4
0
/**
 * @param array $params
 * @return null|soap_fault
 */
function WSCreateLp($params)
{
    global $debug;
    if (!WSHelperVerifyKey($params)) {
        return return_error(WS_ERROR_SECRET_KEY);
    }
    if ($debug) {
        error_log('WSCreateLp');
    }
    $courseIdName = $params['course_id_name'];
    $courseIdValue = $params['course_id_value'];
    $lpName = $params['lp_name'];
    $lpItemList = $params['lp_item_list'];
    /*$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');
        }
    }
    $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';
            }
        }*/
    $lpId = learnpath::add_lp($courseCode, $lpName, '', 'chamilo', 'manual');
    if ($lpId) {
        if ($debug) {
            error_log('LP created');
        }
        $lp = new learnpath($courseCode, $lpId, null);
        $previousId = 0;
        foreach ($lpItemList as $lpItem) {
            $info = pathinfo($lpItem['filename']);
            $extension = $info['extension'];
            $data = base64_decode($lpItem['data']);
            $documentId = $lp->create_document($courseInfo, $data, $info['filename'], $extension);
            if ($documentId) {
                if ($debug) {
                    error_log("Document created {$documentId}");
                    $itemId = $lp->add_item(null, $previousId, 'document', $documentId, $lpItem['title'], '', '');
                    $previousId = $itemId;
                    if ($itemId) {
                        if ($debug) {
                            error_log("Item added");
                        }
                    } else {
                        if ($debug) {
                            error_log("Item not added");
                        }
                    }
                }
            } else {
                if ($debug) {
                    error_log("Document NOT created");
                }
            }
        }
        return 1;
    } else {
        if ($debug) {
            error_log('LP not created');
        }
    }
    return 0;
}