Browse Source

[svn r12915] alpha version of oogie... still a lot of things to improve (refactoring of html for example).

Eric Marguin 17 years ago
parent
commit
4c599de22b

BIN
main/img/woogie.gif


BIN
main/img/word_big.gif


BIN
main/inc/lib/ppt2png/AbstractDokeosDocumentConverter.class


BIN
main/inc/lib/ppt2png/AbstractDokeosOpenOfficeConnection.class


BIN
main/inc/lib/ppt2png/DokeosConverter.class


BIN
main/inc/lib/ppt2png/DokeosSocketOfficeConnection.class


BIN
main/inc/lib/ppt2png/OogieDocumentConverter.class


BIN
main/inc/lib/ppt2png/WoogieDocumentConverter.class


BIN
main/inc/lib/ppt2png/commons-cli-1.0.jar


BIN
main/inc/lib/ppt2png/commons-io-1.3.1.jar


BIN
main/inc/lib/ppt2png/jodconverter-2.2.0.jar


BIN
main/inc/lib/ppt2png/jodconverter-cli-2.2.0.jar


BIN
main/inc/lib/ppt2png/juh-2.2.0.jar


BIN
main/inc/lib/ppt2png/jurt-2.2.0.jar


BIN
main/inc/lib/ppt2png/oogie.jar


BIN
main/inc/lib/ppt2png/ridl-2.2.0.jar


BIN
main/inc/lib/ppt2png/slf4j-api-1.4.0.jar


BIN
main/inc/lib/ppt2png/slf4j-jdk14-1.4.0.jar


BIN
main/inc/lib/ppt2png/unoil-2.2.0.jar


+ 3 - 0
main/newscorm/lp_list.php

@@ -108,7 +108,10 @@ if(api_is_allowed_to_edit())
 		if(api_get_setting('service_ppt2lp','active')==true)
 		{
 			echo  str_repeat('&nbsp;',3).'<a href="../upload/upload_ppt.php?'.api_get_cidreq().'&curdirpath=/&tool='.TOOL_LEARNPATH.'"><img src="../img/powerpoint.gif" border="0" alt="scormbuilder" align="absmiddle">&nbsp;'.get_lang("PowerPointConvert").'</a>';
+       		echo  str_repeat('&nbsp;',3).'<a href="../upload/upload_word.php?'.api_get_cidreq().'&curdirpath=/&tool='.TOOL_LEARNPATH.'"><img src="../img/word.gif" border="0" alt="scormbuilder" align="absmiddle">&nbsp;'.get_lang("WordConvert").'</a>';
        }
+			
+       
 }
 
 echo '<table width="100%" border="0" cellspacing="2" class="data_table">';

+ 5 - 0
main/newscorm/lp_upload.php

@@ -86,6 +86,11 @@ if ($_SERVER['REQUEST_METHOD'] == 'POST'
 			$o_ppt = new presentation();
 			$first_item_id = $o_ppt -> convert_presentation($_FILES['user_file']);				
 			break;
+		case 'woogie':
+			require_once('word_document.class.php');
+			$o_doc = new word_document();
+			$first_item_id = $o_doc -> convert_word_document($_FILES['user_file']);				
+			break;
 		case '':
 		default:
 			return api_failure::set_failure('not_a_learning_path');

+ 151 - 0
main/newscorm/word_document.class.php

@@ -0,0 +1,151 @@
+<?php //$id:$
+/**
+ * Defines the AICC class, which is meant to contain the aicc items (nuclear elements)
+ * @package dokeos.learnpath.aicc
+ * @author	Yannick Warnier <ywarnier@beeznest.org>
+ * @license	GNU/GPL - See Dokeos license directory for details
+ */
+/**
+ * Defines the "aicc" child of class "learnpath"
+ * @package dokeos.learnpath.aicc
+ */
+
+class word_document extends learnpath {
+
+	/**
+	 * Class constructor. Based on the parent constructor.
+	 * @param	string	Course code
+	 * @param	integer	Learnpath ID in DB
+	 * @param	integer	User ID
+	 */
+    function word_document($course_code=null,$resource_id=null,$user_id=null) {
+    	if($this->debug>0){error_log('In word_document::word_document()',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_word_document($file){
+    	
+    	global $_course, $_user, $_configuration;
+    
+    	$file_name = (strrpos($file['name'],'.')>0 ? substr($file['name'], 0, strrpos($file['name'],'.')) : $file['name']);
+    	$file_extension = (strrpos($file['name'],'.')>0 ? substr($file['name'], strrpos($file['name'],'.'),10) : '');
+    	
+    	
+    	$file_name = remove_accents($file_name);
+		$file_name = replace_dangerous_char($file_name,'strict');	
+		$file_name = strtolower($file_name);
+		
+		$file['name'] = $file_name.$file_extension;
+		
+		
+		$dir_name = '/'.$file_name;
+		
+		
+		// get properties of doc 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
+		
+		$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'];
+
+		$perm = api_get_setting('permissions_for_new_files');
+		
+		
+		
+		$classpath = '-cp .:*';
+		if(strpos($_ENV['OS'],'Windows') !== false)
+		{
+			$classpath = str_replace(':',';',$classpath);
+		}
+		if(strpos($_ENV['OS'],'Windows') !== false)
+		{
+			$cmd = 'cd '.str_replace('/','\\',api_get_path(SYS_PATH).'main/inc/lib/ppt2png ').$classpath.' DokeosConverter -p 2002 -d woogie "'.$file.'" "'.$base_work_dir.$created_dir.'/'.$file_name.'.html"';
+		}
+		else
+		{
+			$cmd = 'cd '.api_get_path(SYS_PATH).'main/inc/lib/ppt2png && java '.$classpath.' DokeosConverter -p 2002 -d woogie "'.$file.'" "'.$base_work_dir.$created_dir.'/'.$file_name.'.html"';
+		}
+		
+		// to allow openoffice to manipulate docs.
+		chmod ($base_work_dir.$created_dir,0777);
+		chmod($file,0777);
+
+		$shell = exec($cmd, $files, $return);
+		
+		if($return != 0) { //if the java application returns an error code
+		
+			DocumentManager::delete_document($_course, $dir_name, $base_work_dir);	 
+			return false;   	
+	    }
+	    else {
+			// create lp
+			$learnpath_name .= $file_name;
+			
+			$this->lp_id = learnpath::add_lp($_course['id'], $learnpath_name,'','guess','manual');
+			$content = file_get_contents($base_work_dir.$created_dir.'/'.$file_name.'.html');
+			
+			
+			// we get a content where ||page_break|| indicates where the page is broken
+
+			list($header, $body) = explode('<BODY',$content);
+
+			$body = '<BODY'.$body;
+			
+			
+			$pages = explode('||page_break||',$body);
+			
+			$first_item = 0;
+			
+			foreach($pages as $key=>$page_content){ // for every pages, we create a new file
+				// Tidy
+				$tidy = new tidy;
+				$config = array(
+				       'indent'         => true,
+				       'output-xhtml'   => true,
+				       'wrap'           => 200);
+				$tidy->parseString($header.$page_content, $config, 'utf8');
+				$tidy->cleanRepair();
+				$html_file = $created_dir.'-'.$key.'.html';
+				$handle = fopen($base_work_dir.$created_dir.'/'.$html_file,'w+');
+				fwrite($handle, $tidy);
+				fclose($handle);
+				
+				$document_id = add_document($_course,$created_dir.'/'.$html_file,'file',filesize($base_work_dir.$created_dir.'/'.$html_file),$html_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 = 'page'.str_repeat('0',2-strlen($key+1));
+					$previous = learnpath::add_item(0, $previous, 'document', $document_id, $slide_name, '');
+					if($first_item == 0){
+						$first_item = $previous;
+					}
+				}
+			}
+			
+			$perm = octdec(!empty($perm)?$perm:0700);
+			chmod ($base_work_dir.$created_dir,$perm);
+			chmod($file,$perm);
+			
+	    }
+	    return $first_item;   	
+	    
+    }
+		
+}
+?>

+ 152 - 0
main/upload/upload_word.php

@@ -0,0 +1,152 @@
+<?php // $Id$
+/**
+ * Action controller for the upload process. The display scripts (web forms) redirect
+ * the process here to do what needs to be done with each file.
+ * @package dokeos.upload
+ * @author Yannick Warnier <ywarnier@beeznest.org>
+ */
+/**
+ * First, initialise the script 
+ */
+// name of the language file which needs to be included
+// 'inc.php' is automatically appended to the file name
+$language_file[] = "document"; //the document file is loaded because most of the upload vocab relates to the document tool
+$language_file[] = "learnpath";
+$language_file[] = "scormdocument";
+// global settings initialisation
+// also provides access to main api (inc/lib/main_api.lib.php)
+include("../inc/global.inc.php");
+require_once(api_get_path(LIBRARY_PATH) . 'fileUpload.lib.php');
+require_once(api_get_path(LIBRARY_PATH) . 'events.lib.inc.php');
+require_once(api_get_path(LIBRARY_PATH) . 'document.lib.php');
+require_once (api_get_path(LIBRARY_PATH).'formvalidator/FormValidator.class.php');
+		
+
+$form_style= '
+<style>
+.row {
+	width: 200px;
+}
+</style>';
+
+$htmlHeadXtra[] = '<script language="javascript" src="../inc/lib/javascript/upload.js" type="text/javascript"></script>';
+$htmlHeadXtra[] = '<script type="text/javascript">
+	var myUpload = new upload(0);
+</script>';
+$htmlHeadXtra[] = $form_style;
+
+if(isset($_POST['convert'])){
+	$cwdir = getcwd();
+	require('../newscorm/lp_upload.php');
+	if(isset($o_doc) && $first_item_id != 0){
+		header('Location: ../newscorm/lp_controller.php?'.api_get_cidreq().'&lp_id='.$o_doc->lp_id.'&action=view_item&id='.$first_item_id);
+	}
+	else {
+		$errorMessage = get_lang('WoogieError');
+	}
+}
+
+event_access_tool(TOOL_UPLOAD);
+
+
+// check access permissions (edit permission is needed to add a document or a LP)
+$is_allowed_to_edit = api_is_allowed_to_edit();
+
+if(!$is_allowed_to_edit){
+	api_not_allowed(true);
+}
+
+$interbreadcrumb[]= array ("url"=>"../newscorm/lp_controller.php?action=list", "name"=> get_lang("Doc"));
+$nameTools = get_lang("WoogieConversionPowerPoint");
+Display :: display_header($nameTools);
+
+
+?>
+
+<img src="../img/woogie.gif"><br>
+<span style="color: #ff6434; font-size: 16px; font-family: Arial; margin-left: 10px;"><?php echo get_lang("WelcomeWoogieSubtitle");?></span><br>
+
+<?php
+
+$message=get_lang("WelcomeWoogieConverter");
+
+echo '<br>';
+
+$s_style="border-width: 1px;
+		 border-style: solid;
+		 margin-left: 0;
+		 margin-top: 10px;
+		 margin-bottom: 0px;
+		 min-height: 30px;
+		 padding: 5px;
+		 position: relative;
+		 width: 500px;
+		 background-color: #E5EDF9;
+		 border-color: #4171B5;
+		 color: #000;";
+
+$s_style_error="border-width: 1px;
+		 border-style: solid;
+		 margin-left: 0;
+		 margin-top: 10px;
+		 margin-bottom: 10px;
+		 min-height: 30px;
+		 padding: 5px;
+		 position: relative;
+		 width: 500px;
+		 background-color: #FFD1D1;
+		 border-color: #FF0000;
+		 color: #000;";
+
+
+echo '<div style="'.$s_style.'"><div style="float:left; margin-right:10px;"><img src="'.api_get_path(WEB_IMG_PATH)."message_normal.gif".'" alt="'.$alt_text.'" '.$attribute_list.'  /></div><div style="margin-left: 43px">'.$message.'</div></div>';
+
+if(!empty($errorMessage)){
+	echo '<div style="'.$s_style_error.'"><div style="float:left; margin-right:10px;"><img src="'.api_get_path(WEB_IMG_PATH)."message_error.gif".'" alt="'.$alt_text.'" '.$attribute_list.'  /></div><div style="margin-left: 43px">'.$errorMessage.'</div></div>';
+}
+echo '
+<style>
+.row{
+	width:90%;
+}
+div.row div.label {
+	width: 0%;
+}
+
+div.row div.formw {
+	width: 100%;
+}
+.convert_button{
+	background: url("../img/scorm.gif") 0px 0px no-repeat;
+	padding: 2px 0px 2px 22px;
+}
+
+</style>';
+$form = new FormValidator('update_course', 'POST', '', '', 'style="margin: 0;"');
+
+// build the form
+
+$form -> addElement ('html','<br>');
+
+$group = array();
+$group[] = FormValidator::createElement ('image','word_img','../img/word_big.gif','align="absbottom"');
+$group[] = FormValidator::createElement ('file', 'user_file',null);
+$group[] = FormValidator::createElement ('submit', 'convert', get_lang('ConvertToLP'), 'class="convert_button"');
+$form -> addGroup($group);
+
+$form -> addElement ('hidden', 'woogie', 'true');
+
+$form -> add_real_progress_bar(md5(rand(0,10000)), 'qf_group_1', 1, true);
+
+
+// display the form
+$form -> display();
+
+/*
+==============================================================================
+  FOOTER
+==============================================================================
+*/
+Display::display_footer();
+
+?>