diff --git a/main/newscorm/learnpath.class.php b/main/newscorm/learnpath.class.php index 279c71c453..d84eb5de50 100644 --- a/main/newscorm/learnpath.class.php +++ b/main/newscorm/learnpath.class.php @@ -717,11 +717,11 @@ class learnpath { "'local','')"; //if($this->debug>2){error_log('New LP - Inserting new lp '.$sql_insert,0);} - + $res_insert = api_sql_query($sql_insert); $id = Database::get_last_insert_id(); - + if($id>0){ return $id; @@ -2010,7 +2010,7 @@ class learnpath { } /** - * Returns the package type ('scorm','aicc','scorm2004','dokeos',...) + * Returns the package type ('scorm','aicc','scorm2004','dokeos','ppt'...) * * Generally, the package provided is in the form of a zip file, so the function * has been written to test a zip file. If not a zip, the function will return the @@ -2026,6 +2026,12 @@ class learnpath { $file_info = pathinfo($file_name); $filename = $file_info['basename'];//name including extension $extension = $file_info['extension'];//extension only + + if(in_array($extension,array('ppt','odp'))) + { + return 'ppt'; + } + $file_base_name = str_replace('.'.$extension,'',$filename); //filename without its extension $zipFile = new pclZip($file_path); diff --git a/main/newscorm/lp_upload.php b/main/newscorm/lp_upload.php index a68a92df44..1c0ef11714 100644 --- a/main/newscorm/lp_upload.php +++ b/main/newscorm/lp_upload.php @@ -77,6 +77,12 @@ if ($_SERVER['REQUEST_METHOD'] == 'POST' $oAICC->set_proximity($proximity); $oAICC->set_maker($maker); $oAICC->set_jslib('aicc_api.php'); + break; + case 'ppt': + require_once('presentation.class.php'); + $o_ppt = new presentation(); + $o_ppt -> convert_presentation($_FILES['user_file']); + break; case '': default: diff --git a/main/newscorm/presentation.class.php b/main/newscorm/presentation.class.php new file mode 100644 index 0000000000..8877849b53 --- /dev/null +++ b/main/newscorm/presentation.class.php @@ -0,0 +1,97 @@ + + * @license GNU/GPL - See Dokeos license directory for details + */ +/** + * Defines the "aicc" child of class "learnpath" + * @package dokeos.learnpath.aicc + */ + +class presentation extends learnpath { + + /** + * Class constructor. Based on the parent constructor. + * @param string Course code + * @param integer Learnpath ID in DB + * @param integer User ID + */ + function presentation($course_code=null,$resource_id=null,$user_id=null) { + if($this->debug>0){error_log('In presentation::presentation()',0);} + if(!empty($course_code) and !empty($resource_id) and !empty($user_id)) + { + parent::learnpath($course_code, $resource_id, $user_id); + }else{ + //do nothing but still build the presentation object + } + } + + function convert_presentation($file){ + + global $_course, $_user; + + + // get properties of ppt file + $document_datas = DocumentManager::get_all_document_data($_course, $file); + $to_group_id = (empty($document_datas['to_group_id'])) ? 0 : $document_datas['to_group_id']; + $to_user_id = (empty($document_datas['to_user_id'])) ? null : $document_datas['to_user_id']; + + //create the directory + $added_slash = '/'; + $dir_name = $added_slash.substr($file['name'], 0, strrpos($file['name'],'.')); + $base_work_dir = api_get_path(SYS_COURSE_PATH).$_course['path'].'/document/'; + $created_dir = create_unexisting_directory($_course,$_user['user_id'],$to_group_id,$to_user_id,$base_work_dir,$dir_name); + + move_uploaded_file($file['tmp_name'],$base_work_dir.$file['name']); + $file = $base_work_dir.$file['name']; + chmod($file,0777); + /* + * exec java application + * the parameters of the program are : + * - javacommand on this server ; + * - host where openoffice is running; + * - port with which openoffice is listening + * - file to convert + * - folder where put the slides + * - ftppassword if required + * The program fills $files with the list of slides created + */ + $cmd = 'cd '.api_get_path(LIBRARY_PATH).'ppt2png && ./launch_ppt2png.sh java localhost 2002 "'.$file.'" "'.$base_work_dir.$created_dir.'"'; + + chmod ($base_work_dir.$created_dir,0777); + + $shell = exec($cmd, $files, $return); + + chmod ($base_work_dir.$created_dir,0744); + if($return != 0) { //if the java application returns an error code + DocumentManager::delete_document($_course, $dir_name, $base_work_dir); + } + + else { + // create lp + $learnpath_name = 'lp_'; + $learnpath_name .= basename($file); + $learnpath_name = substr($learnpath_name,0, strrpos($learnpath_name,'.')); + + $this->lp_id = learnpath::add_lp($_course['id'], $learnpath_name,'','guess','manual'); + $previous = 0; + foreach($files as $file){ + $document_id = add_document($_course,$created_dir.'/'.$file,'file',filesize($base_work_dir.$created_dir.'/'.$file),$file); + if ($document_id){ + //put the document in item_property update + api_item_property_update($_course,TOOL_DOCUMENT,$document_id,'DocumentAdded',$_SESSION['_uid'],$to_group_id,$to_user_id); + + $infos = pathinfo($file); + $slide_name = substr($infos['basename'],0,strpos($infos['basename'],'.')); + $previous = learnpath::add_item(0, $previous, 'document', $document_id, $slide_name, 0); + + } + } + } + + } + +} +?>