Added Excel question import from Dokeos 2 (initially developed by iflores, carefully reviewed for fixes and improvements)
parent
4314b1cc74
commit
e2128fa522
Binary file not shown.
@ -0,0 +1,296 @@ |
||||
<?php |
||||
/* For licensing terms, see /license.txt */ |
||||
/** |
||||
* Upload quiz: This script shows the upload quiz feature |
||||
* Initial work by Isaac flores on Nov 4 of 2010 |
||||
* @package chamilo.exercise |
||||
*/ |
||||
// Language files that should be included |
||||
$language_file[] = 'learnpath'; |
||||
$language_file[] = 'exercice'; |
||||
// setting the help |
||||
$help_content = 'exercise_upload'; |
||||
|
||||
// including the global Dokeos file |
||||
require_once '../inc/global.inc.php'; |
||||
require_once api_get_path(LIBRARY_PATH) . 'fileUpload.lib.php'; |
||||
require_once api_get_path(LIBRARY_PATH) . 'formvalidator/FormValidator.class.php'; |
||||
require_once api_get_path(LIBRARY_PATH) . 'pear/excelreader/reader.php'; |
||||
require_once 'exercise.class.php'; |
||||
require_once 'question.class.php'; |
||||
require_once 'unique_answer.class.php'; |
||||
require_once '../newscorm/learnpath.class.php'; |
||||
require_once '../newscorm/learnpathItem.class.php'; |
||||
|
||||
// Security check |
||||
$is_allowed_to_edit = api_is_allowed_to_edit(null, true); |
||||
if (!$is_allowed_to_edit) { |
||||
api_not_allowed(true); |
||||
} |
||||
|
||||
// setting the tabs |
||||
$this_section = SECTION_COURSES; |
||||
$htmlHeadXtra[] = "<script type='text/javascript'> |
||||
$(document).ready( function(){ |
||||
$(\"div.formw\").attr(\"style\",\"width: 73%;\"); |
||||
$(\"#img_plus_and_minus\").hide(); |
||||
}); |
||||
</script>"; |
||||
|
||||
// Action handling |
||||
lp_upload_quiz_action_handling(); |
||||
|
||||
// Display the header |
||||
if ($origin != 'learnpath') { |
||||
//so we are not in learnpath tool |
||||
Display :: display_header($nameTools, get_lang('Exercise')); |
||||
if (isset ($_GET['message'])) { |
||||
if (in_array($_GET['message'], array ('ExerciseEdited'))) { |
||||
Display :: display_confirmation_message(get_lang($_GET['message'])); |
||||
} |
||||
} |
||||
} else { |
||||
echo '<link rel="stylesheet" type="text/css" href="' . api_get_path(WEB_CODE_PATH) . 'css/default.css"/>'; |
||||
} |
||||
// display the actions |
||||
echo '<div class="actions">'; |
||||
echo lp_upload_quiz_actions(); |
||||
echo '</div>'; |
||||
|
||||
// start the content div |
||||
echo '<div id="content_with_secondary_actions" class="gradient">'; |
||||
// the main content |
||||
lp_upload_quiz_main(); |
||||
|
||||
// close the content div |
||||
echo '</div>'; |
||||
|
||||
function lp_upload_quiz_actions() { |
||||
$lp_id = Security::remove_XSS($_GET['lp_id']); |
||||
$return = ""; |
||||
$return .= '<a href="exercice.php?'.api_get_cidReq().'">'.Display::return_icon('back.png', get_lang('BackToExercisesList'),'','32').'</a>'; |
||||
$return .= '<a href="exercise_admin.php?' . api_get_cidreq() . '">' . Display :: return_icon('new_exercice.png', get_lang('NewEx'),'','32').'</a>'; |
||||
$return .= '<a href="question_create.php?' . api_get_cidreq() . '">' . Display :: return_icon('new_question.png', get_lang('AddQ'),'','32').'</a>'; |
||||
$return .= '<a href="hotpotatoes.php?' . api_get_cidreq() . '">' . Display :: return_icon('import_hotpotatoes.png', get_lang('ImportHotPotatoesQuiz'),'','32').'</a>'; |
||||
// link to import qti2 ... |
||||
$return .= '<a href="qti2.php?' . api_get_cidreq() . '">' . Display :: return_icon('import_qti2.png', get_lang('ImportQtiQuiz'),'','32') .'</a>'; |
||||
$return .= '<a href="upload_exercise.php?' . api_get_cidreq() . '">' . Display :: return_icon('import_excel.png', get_lang('ImportExcelQuiz'),'','32') .'</a>'; |
||||
return $return; |
||||
} |
||||
|
||||
function lp_upload_quiz_secondary_actions() { |
||||
$lp_id = Security::remove_XSS($_GET['lp_id']); |
||||
$return.= ''; |
||||
$return.='<a href="exercice.php?show=result&' . api_get_cidreq() . '">' . Display :: return_icon('reporting32.png', get_lang('Tracking')) . get_lang('Tracking') . '</a>'; |
||||
return $return; |
||||
} |
||||
|
||||
function lp_upload_quiz_main() { |
||||
// Database table definition |
||||
global $_course; |
||||
$table_document = Database::get_course_table(TABLE_DOCUMENT, $_course['dbName']); |
||||
$propTable = Database::get_course_table(TABLE_ITEM_PROPERTY); |
||||
// variable initialisation |
||||
$lp_id = Security::remove_XSS($_GET['lp_id']); |
||||
|
||||
$form = new FormValidator('upload', 'POST', api_get_self() . '?' . api_get_cidreq() . '&lp_id=' . $lp_id, '', 'enctype="multipart/form-data"'); |
||||
$form->addElement('html', '<div><h3>' .Display::return_icon('import_excel.png', get_lang('ImportExcelQuiz'),array('style'=>'margin-bottom:-2px;'),32). get_lang('ImportExcelQuiz') . '</h3><div><input type="file" name="user_upload_quiz" id="user_upload_quiz_id" size="20" /></div></div>'); |
||||
//button send document |
||||
$form->addElement('style_submit_button', 'submit_upload_quiz', get_lang('Validate'), 'class="upload"'); |
||||
$form->setDefaults($defaults); |
||||
|
||||
// Display the upload field |
||||
echo '<table style="text-align: left; width: 100%;" border="0" cellpadding="2"cellspacing="2"><tbody><tr>'; |
||||
echo '<td style="vertical-align: top; width: 25%;">'; |
||||
echo '<a href="../exercice/quiz_template.xls">'.Display::return_icon('export_excel.png', get_lang('DownloadExcelTemplate'),null,16).get_lang('DownloadExcelTemplate').''; |
||||
echo '</a>'; |
||||
echo '</td>'; |
||||
echo '</tr>'; |
||||
echo '<tr><td>'; |
||||
$form->display(); |
||||
echo '</td></tr></tbody></table>'; |
||||
} |
||||
|
||||
/** |
||||
* Handles a given Excel spreadsheets as in the template provided |
||||
*/ |
||||
function lp_upload_quiz_action_handling() { |
||||
global $charset, $_course, $_user, $debug; |
||||
if (!isset($_POST['submit_upload_quiz'])) { |
||||
return; |
||||
} |
||||
// Get the extension of the document. |
||||
$path_info = pathinfo($_FILES['user_upload_quiz']['name']); |
||||
// Check if the document is an Excel document |
||||
if ($path_info['extension'] != 'xls') { |
||||
return; |
||||
} |
||||
// Read the Excel document |
||||
$data = new Spreadsheet_Excel_Reader(); |
||||
// Set output Encoding. |
||||
$data->setOutputEncoding($charset); |
||||
// Reading the xls document. |
||||
$data->read($_FILES['user_upload_quiz']['tmp_name']); |
||||
// Variables |
||||
$quiz_index = 0; |
||||
$question_title_index = array(); |
||||
$question_name_index_init = array(); |
||||
$question_name_index_end = array(); |
||||
$score_index = array(); |
||||
$feedback_true_index = array(); |
||||
$feedback_false_index = array(); |
||||
$number_questions = 0; |
||||
// Reading all the first column items sequencially to create breakpoints |
||||
for ($i = 1; $i < $data->sheets[0]['numRows']; $i++) { |
||||
if ($data->sheets[0]['cells'][$i][1] == 'Quiz' && $i == 1) { |
||||
$quiz_index = $i; // Quiz title position, only occurs once |
||||
} elseif ($data->sheets[0]['cells'][$i][1] == 'Question') { |
||||
$question_title_index[] = $i; // Question title position line |
||||
$question_name_index_init[] = $i + 1; // Questions name 1st position line |
||||
$number_questions++; |
||||
} elseif ($data->sheets[0]['cells'][$i][1] == 'Score') { |
||||
$question_name_index_end[] = $i - 1; // Question name position |
||||
$score_index[] = $i; // Question score position |
||||
} elseif ($data->sheets[0]['cells'][$i][1] == 'FeedbackTrue') { |
||||
$feedback_true_index[] = $i; // FeedbackTrue position |
||||
} elseif ($data->sheets[0]['cells'][$i][1] == 'FeedbackFalse') { |
||||
$feedback_false_index[] = $i; // FeedbackFalse position |
||||
} |
||||
} |
||||
// Variables |
||||
$quiz = array(); |
||||
$question = array(); |
||||
$answer = array(); |
||||
$new_answer = array(); |
||||
$score_list = array(); |
||||
$feedback_true_list = array(); |
||||
$feedback_false_list = array(); |
||||
// Get questions |
||||
$k = $z = $q = $l = 0; |
||||
for ($i = 1; $i <= $data->sheets[0]['numRows']; $i++) { |
||||
if (is_array($data->sheets[0]['cells'][$i])) { |
||||
$column_data = $data->sheets[0]['cells'][$i]; |
||||
// Fill all column with data |
||||
for ($x = 1; $x <= $data->sheets[0]['numCols']; $x++) { |
||||
if (empty($column_data[$x])) { |
||||
$data->sheets[0]['cells'][$i][$x] = ''; |
||||
} |
||||
} |
||||
// Array filled with data |
||||
$column_data = $data->sheets[0]['cells'][$i]; |
||||
} else { |
||||
$column_data = ''; |
||||
} |
||||
// Fill quiz data |
||||
if ($quiz_index == $i) { // The title always in the first position |
||||
$quiz = $column_data; |
||||
} elseif (in_array($i, $question_title_index)) { |
||||
$question[$k] = $column_data; |
||||
$k++; |
||||
} elseif (in_array($i, $score_index)) { |
||||
$score_list[$z] = $column_data; |
||||
$z++; |
||||
} elseif (in_array($i, $feedback_true_index)) { |
||||
$feedback_true_list[$q] = $column_data; |
||||
$q++; |
||||
} elseif (in_array($i, $feedback_false_index)) { |
||||
$feedback_false_list[$l] = $column_data; |
||||
$l++; |
||||
} |
||||
} |
||||
// Get answers |
||||
for ($i = 0; $i < count($question_name_index_init); $i++) { |
||||
for ($j = $question_name_index_init[$i]; $j <= $question_name_index_end[$i]; $j++) { |
||||
if (is_array($data->sheets[0]['cells'][$j])) { |
||||
$column_data = $data->sheets[0]['cells'][$j]; |
||||
// Fill all column with data |
||||
for ($x = 1; $x <= $data->sheets[0]['numCols']; $x++) { |
||||
if (empty($column_data[$x])) { |
||||
$data->sheets[0]['cells'][$j][$x] = ''; |
||||
} |
||||
} |
||||
$column_data = $data->sheets[0]['cells'][$j]; |
||||
// Array filled of data |
||||
if (is_array($data->sheets[0]['cells'][$j]) && count($data->sheets[0]['cells'][$j]) > 0) { |
||||
$new_answer[$i][$j] = $data->sheets[0]['cells'][$j]; |
||||
} |
||||
} |
||||
} |
||||
} |
||||
$quiz_title = $quiz[2]; // Quiz title |
||||
if ($quiz_title != '') { |
||||
// Variables |
||||
$type = 2; |
||||
$random = $active = $results = $max_attempt = $expired_time = 0; |
||||
$feedback = 3; |
||||
// Quiz object |
||||
$quiz_object = new Exercise(); |
||||
$quiz_id = $quiz_object->create_quiz($quiz_title, $expired_time, $type, $random, $active, $results, $max_attempt, $feedback); |
||||
// insert into the item_property table |
||||
api_item_property_update($_course, TOOL_QUIZ, $quiz_id, 'QuizAdded', api_get_user_id()); |
||||
// Import questions |
||||
for ($i = 0; $i < $number_questions; $i++) { |
||||
// Create questions |
||||
$question_title = $question[$i][2]; // Question name |
||||
if ($question_title != '') { |
||||
$question_id = Question::create_question($quiz_id, $question_title); |
||||
} |
||||
$unique_answer = new UniqueAnswer(); |
||||
if (is_array($new_answer[$i])) { |
||||
$id = 1; |
||||
$answers_data = $new_answer[$i]; |
||||
foreach ($answers_data as $answer_data) { |
||||
$answer = $answer_data[2]; |
||||
$correct = 0; |
||||
$score = 0; |
||||
$comment = ''; |
||||
if (strtolower($answer_data[3]) == 'x') { |
||||
$correct = 1; |
||||
$score = $score_list[$i][3]; |
||||
} |
||||
if ($id == 1) { |
||||
$comment = $feedback_true_list[$i][2]; |
||||
} elseif ($id == 2) { |
||||
$comment = $feedback_false_list[$i][2]; |
||||
} |
||||
// Create answer |
||||
$unique_answer->create_answer($id, $question_id, $answer, $comment, $score, $correct); |
||||
$id++; |
||||
} |
||||
} |
||||
} |
||||
if (isset($_SESSION['lpobject'])) { |
||||
if ($debug > 0) { |
||||
error_log('New LP - SESSION[lpobject] is defined', 0); |
||||
} |
||||
$oLP = unserialize($_SESSION['lpobject']); |
||||
if (is_object($oLP)) { |
||||
if ($debug > 0) { |
||||
error_log('New LP - oLP is object', 0); |
||||
} |
||||
if ((empty($oLP->cc)) OR $oLP->cc != api_get_course_id()) { |
||||
if ($debug > 0) { |
||||
error_log('New LP - Course has changed, discard lp object', 0); |
||||
} |
||||
$oLP = null; |
||||
api_session_unregister('oLP'); |
||||
api_session_unregister('lpobject'); |
||||
} else { |
||||
$_SESSION['oLP'] = $oLP; |
||||
$lp_found = true; |
||||
} |
||||
} |
||||
} |
||||
if (isset($_SESSION['oLP']) && isset($_GET['lp_id'])) { |
||||
$previous = $_SESSION['oLP']->select_previous_item_id(); |
||||
$parent = 0; |
||||
// Add a Quiz as Lp Item |
||||
$_SESSION['oLP']->add_item($parent, $previous, TOOL_QUIZ, $quiz_id, $quiz_title, ''); |
||||
// Redirect to home page for add more content |
||||
header('location: ../newscorm/lp_controller.php?' . api_get_cidreq() . '&action=add_item&type=step&lp_id=' . Security::remove_XSS($_GET['lp_id']).'&session_id='.api_get_session_id()); |
||||
} else { |
||||
// header('location: exercice.php?' . api_get_cidreq()); |
||||
echo '<script>window.location.href = "admin.php?'.api_get_cidReq().'&exerciseId='.$quiz_id.'&session_id='.api_get_session_id().'"</script>'; |
||||
} |
||||
} |
||||
} |
After Width: | Height: | Size: 799 B |
After Width: | Height: | Size: 1.9 KiB |
@ -0,0 +1,271 @@ |
||||
<?php |
||||
define('NUM_BIG_BLOCK_DEPOT_BLOCKS_POS', 0x2c); |
||||
define('SMALL_BLOCK_DEPOT_BLOCK_POS', 0x3c); |
||||
define('ROOT_START_BLOCK_POS', 0x30); |
||||
define('BIG_BLOCK_SIZE', 0x200); |
||||
define('SMALL_BLOCK_SIZE', 0x40); |
||||
define('EXTENSION_BLOCK_POS', 0x44); |
||||
define('NUM_EXTENSION_BLOCK_POS', 0x48); |
||||
define('PROPERTY_STORAGE_BLOCK_SIZE', 0x80); |
||||
define('BIG_BLOCK_DEPOT_BLOCKS_POS', 0x4c); |
||||
define('SMALL_BLOCK_THRESHOLD', 0x1000); |
||||
// property storage offsets |
||||
define('SIZE_OF_NAME_POS', 0x40); |
||||
define('TYPE_POS', 0x42); |
||||
define('START_BLOCK_POS', 0x74); |
||||
define('SIZE_POS', 0x78); |
||||
define('IDENTIFIER_OLE', pack("CCCCCCCC",0xd0,0xcf,0x11,0xe0,0xa1,0xb1,0x1a,0xe1)); |
||||
|
||||
//echo 'ROOT_START_BLOCK_POS = '.ROOT_START_BLOCK_POS."\n"; |
||||
|
||||
//echo bin2hex($data[ROOT_START_BLOCK_POS])."\n"; |
||||
//echo "a="; |
||||
//echo $data[ROOT_START_BLOCK_POS]; |
||||
//function log |
||||
|
||||
function GetInt4d($data, $pos) |
||||
{ |
||||
$value = ord($data[$pos]) | (ord($data[$pos+1]) << 8) | (ord($data[$pos+2]) << 16) | (ord($data[$pos+3]) << 24); |
||||
if ($value>=4294967294) |
||||
{ |
||||
$value=-2; |
||||
} |
||||
return $value; |
||||
} |
||||
|
||||
|
||||
class OLERead { |
||||
var $data = ''; |
||||
|
||||
|
||||
function OLERead(){ |
||||
|
||||
|
||||
} |
||||
|
||||
function read($sFileName){ |
||||
|
||||
// check if file exist and is readable (Darko Miljanovic) |
||||
if(!is_readable($sFileName)) { |
||||
$this->error = 1; |
||||
return false; |
||||
} |
||||
|
||||
$this->data = @file_get_contents($sFileName); |
||||
if (!$this->data) { |
||||
$this->error = 1; |
||||
return false; |
||||
} |
||||
//echo IDENTIFIER_OLE; |
||||
//echo 'start'; |
||||
if (substr($this->data, 0, 8) != IDENTIFIER_OLE) { |
||||
$this->error = 1; |
||||
return false; |
||||
} |
||||
$this->numBigBlockDepotBlocks = GetInt4d($this->data, NUM_BIG_BLOCK_DEPOT_BLOCKS_POS); |
||||
$this->sbdStartBlock = GetInt4d($this->data, SMALL_BLOCK_DEPOT_BLOCK_POS); |
||||
$this->rootStartBlock = GetInt4d($this->data, ROOT_START_BLOCK_POS); |
||||
$this->extensionBlock = GetInt4d($this->data, EXTENSION_BLOCK_POS); |
||||
$this->numExtensionBlocks = GetInt4d($this->data, NUM_EXTENSION_BLOCK_POS); |
||||
|
||||
/* |
||||
echo $this->numBigBlockDepotBlocks." "; |
||||
echo $this->sbdStartBlock." "; |
||||
echo $this->rootStartBlock." "; |
||||
echo $this->extensionBlock." "; |
||||
echo $this->numExtensionBlocks." "; |
||||
*/ |
||||
//echo "sbdStartBlock = $this->sbdStartBlock\n"; |
||||
$bigBlockDepotBlocks = array(); |
||||
$pos = BIG_BLOCK_DEPOT_BLOCKS_POS; |
||||
// echo "pos = $pos"; |
||||
$bbdBlocks = $this->numBigBlockDepotBlocks; |
||||
|
||||
if ($this->numExtensionBlocks != 0) { |
||||
$bbdBlocks = (BIG_BLOCK_SIZE - BIG_BLOCK_DEPOT_BLOCKS_POS)/4; |
||||
} |
||||
|
||||
for ($i = 0; $i < $bbdBlocks; $i++) { |
||||
$bigBlockDepotBlocks[$i] = GetInt4d($this->data, $pos); |
||||
$pos += 4; |
||||
} |
||||
|
||||
|
||||
for ($j = 0; $j < $this->numExtensionBlocks; $j++) { |
||||
$pos = ($this->extensionBlock + 1) * BIG_BLOCK_SIZE; |
||||
$blocksToRead = min($this->numBigBlockDepotBlocks - $bbdBlocks, BIG_BLOCK_SIZE / 4 - 1); |
||||
|
||||
for ($i = $bbdBlocks; $i < $bbdBlocks + $blocksToRead; $i++) { |
||||
$bigBlockDepotBlocks[$i] = GetInt4d($this->data, $pos); |
||||
$pos += 4; |
||||
} |
||||
|
||||
$bbdBlocks += $blocksToRead; |
||||
if ($bbdBlocks < $this->numBigBlockDepotBlocks) { |
||||
$this->extensionBlock = GetInt4d($this->data, $pos); |
||||
} |
||||
} |
||||
|
||||
// var_dump($bigBlockDepotBlocks); |
||||
|
||||
// readBigBlockDepot |
||||
$pos = 0; |
||||
$index = 0; |
||||
$this->bigBlockChain = array(); |
||||
|
||||
for ($i = 0; $i < $this->numBigBlockDepotBlocks; $i++) { |
||||
$pos = ($bigBlockDepotBlocks[$i] + 1) * BIG_BLOCK_SIZE; |
||||
//echo "pos = $pos"; |
||||
for ($j = 0 ; $j < BIG_BLOCK_SIZE / 4; $j++) { |
||||
$this->bigBlockChain[$index] = GetInt4d($this->data, $pos); |
||||
$pos += 4 ; |
||||
$index++; |
||||
} |
||||
} |
||||
|
||||
//var_dump($this->bigBlockChain); |
||||
//echo '=====2'; |
||||
// readSmallBlockDepot(); |
||||
$pos = 0; |
||||
$index = 0; |
||||
$sbdBlock = $this->sbdStartBlock; |
||||
$this->smallBlockChain = array(); |
||||
|
||||
while ($sbdBlock != -2) { |
||||
|
||||
$pos = ($sbdBlock + 1) * BIG_BLOCK_SIZE; |
||||
|
||||
for ($j = 0; $j < BIG_BLOCK_SIZE / 4; $j++) { |
||||
$this->smallBlockChain[$index] = GetInt4d($this->data, $pos); |
||||
$pos += 4; |
||||
$index++; |
||||
} |
||||
|
||||
$sbdBlock = $this->bigBlockChain[$sbdBlock]; |
||||
} |
||||
|
||||
|
||||
// readData(rootStartBlock) |
||||
$block = $this->rootStartBlock; |
||||
$pos = 0; |
||||
$this->entry = $this->__readData($block); |
||||
|
||||
/* |
||||
while ($block != -2) { |
||||
$pos = ($block + 1) * BIG_BLOCK_SIZE; |
||||
$this->entry = $this->entry.substr($this->data, $pos, BIG_BLOCK_SIZE); |
||||
$block = $this->bigBlockChain[$block]; |
||||
} |
||||
*/ |
||||
//echo '==='.$this->entry."==="; |
||||
$this->__readPropertySets(); |
||||
|
||||
} |
||||
|
||||
function __readData($bl) { |
||||
$block = $bl; |
||||
$pos = 0; |
||||
$data = ''; |
||||
|
||||
while ($block != -2) { |
||||
$pos = ($block + 1) * BIG_BLOCK_SIZE; |
||||
$data = $data.substr($this->data, $pos, BIG_BLOCK_SIZE); |
||||
//echo "pos = $pos data=$data\n"; |
||||
$block = $this->bigBlockChain[$block]; |
||||
} |
||||
return $data; |
||||
} |
||||
|
||||
function __readPropertySets(){ |
||||
$offset = 0; |
||||
//var_dump($this->entry); |
||||
while ($offset < strlen($this->entry)) { |
||||
$d = substr($this->entry, $offset, PROPERTY_STORAGE_BLOCK_SIZE); |
||||
|
||||
$nameSize = ord($d[SIZE_OF_NAME_POS]) | (ord($d[SIZE_OF_NAME_POS+1]) << 8); |
||||
|
||||
$type = ord($d[TYPE_POS]); |
||||
//$maxBlock = strlen($d) / BIG_BLOCK_SIZE - 1; |
||||
|
||||
$startBlock = GetInt4d($d, START_BLOCK_POS); |
||||
$size = GetInt4d($d, SIZE_POS); |
||||
|
||||
$name = ''; |
||||
for ($i = 0; $i < $nameSize ; $i++) { |
||||
$name .= $d[$i]; |
||||
} |
||||
|
||||
$name = str_replace("\x00", "", $name); |
||||
|
||||
$this->props[] = array ( |
||||
'name' => $name, |
||||
'type' => $type, |
||||
'startBlock' => $startBlock, |
||||
'size' => $size); |
||||
|
||||
if (($name == "Workbook") || ($name == "Book")) { |
||||
$this->wrkbook = count($this->props) - 1; |
||||
} |
||||
|
||||
if ($name == "Root Entry") { |
||||
$this->rootentry = count($this->props) - 1; |
||||
} |
||||
|
||||
//echo "name ==$name=\n"; |
||||
|
||||
|
||||
$offset += PROPERTY_STORAGE_BLOCK_SIZE; |
||||
} |
||||
|
||||
} |
||||
|
||||
|
||||
function getWorkBook(){ |
||||
if ($this->props[$this->wrkbook]['size'] < SMALL_BLOCK_THRESHOLD){ |
||||
// getSmallBlockStream(PropertyStorage ps) |
||||
|
||||
$rootdata = $this->__readData($this->props[$this->rootentry]['startBlock']); |
||||
|
||||
$streamData = ''; |
||||
$block = $this->props[$this->wrkbook]['startBlock']; |
||||
//$count = 0; |
||||
$pos = 0; |
||||
while ($block != -2) { |
||||
$pos = $block * SMALL_BLOCK_SIZE; |
||||
$streamData .= substr($rootdata, $pos, SMALL_BLOCK_SIZE); |
||||
|
||||
$block = $this->smallBlockChain[$block]; |
||||
} |
||||
|
||||
return $streamData; |
||||
|
||||
|
||||
}else{ |
||||
|
||||
$numBlocks = $this->props[$this->wrkbook]['size'] / BIG_BLOCK_SIZE; |
||||
if ($this->props[$this->wrkbook]['size'] % BIG_BLOCK_SIZE != 0) { |
||||
$numBlocks++; |
||||
} |
||||
|
||||
if ($numBlocks == 0) return ''; |
||||
|
||||
//echo "numBlocks = $numBlocks\n"; |
||||
//byte[] streamData = new byte[numBlocks * BIG_BLOCK_SIZE]; |
||||
//print_r($this->wrkbook); |
||||
$streamData = ''; |
||||
$block = $this->props[$this->wrkbook]['startBlock']; |
||||
//$count = 0; |
||||
$pos = 0; |
||||
//echo "block = $block"; |
||||
while ($block != -2) { |
||||
$pos = ($block + 1) * BIG_BLOCK_SIZE; |
||||
$streamData .= substr($this->data, $pos, BIG_BLOCK_SIZE); |
||||
$block = $this->bigBlockChain[$block]; |
||||
} |
||||
//echo 'stream'.$streamData; |
||||
return $streamData; |
||||
} |
||||
} |
||||
|
||||
} |
||||
?> |
File diff suppressed because it is too large
Load Diff
Loading…
Reference in new issue