Moodle  2.2.1
http://www.collinsharper.com
C:/xampp/htdocs/moodle/lib/odslib.class.php
Go to the documentation of this file.
00001 <?php
00002 
00003 // This file is part of Moodle - http://moodle.org/
00004 //
00005 // Moodle is free software: you can redistribute it and/or modify
00006 // it under the terms of the GNU General Public License as published by
00007 // the Free Software Foundation, either version 3 of the License, or
00008 // (at your option) any later version.
00009 //
00010 // Moodle is distributed in the hope that it will be useful,
00011 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00012 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013 // GNU General Public License for more details.
00014 //
00015 // You should have received a copy of the GNU General Public License
00016 // along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
00017 
00029 defined('MOODLE_INTERNAL') || die();
00030 
00042 class MoodleODSWorkbook {
00043     var $worksheets = array();
00044     var $filename;
00045 
00046     function MoodleODSWorkbook($filename) {
00047         $this->filename = $filename;
00048     }
00049 
00050     /* Create one Moodle Worksheet
00051      * @param string $name Name of the sheet
00052      */
00053     function &add_worksheet($name = '') {
00055         $ws = new MoodleODSWorksheet($name);
00056         $this->worksheets[] =& $ws;
00057         return $ws;
00058     }
00059 
00060     /* Create one Moodle Format
00061      * @param array $properties array of properties [name]=value;
00062      *                          valid names are set_XXXX existing
00063      *                          functions without the set_ part
00064      *                          i.e: [bold]=1 for set_bold(1)...Optional!
00065      */
00066     function &add_format($properties = array()) {
00067         $format = new MoodleODSFormat($properties);
00068         return $format;;
00069     }
00070 
00071     /* Close the Moodle Workbook
00072      */
00073     function close() {
00074         global $CFG;
00075         require_once($CFG->libdir.'/filelib.php');
00076 
00077         $dir = 'ods/'.time();
00078         make_temp_directory($dir);
00079         make_temp_directory($dir.'/META-INF');
00080         $dir = "$CFG->tempdir/$dir";
00081         $files = array();
00082 
00083         $handle = fopen("$dir/mimetype", 'w');
00084         fwrite($handle, get_ods_mimetype());
00085         $files[] = "$dir/mimetype";
00086 
00087         $handle = fopen("$dir/content.xml", 'w');
00088         fwrite($handle, get_ods_content($this->worksheets));
00089         $files[] = "$dir/content.xml";
00090 
00091         $handle = fopen("$dir/meta.xml", 'w');
00092         fwrite($handle, get_ods_meta());
00093         $files[] = "$dir/meta.xml";
00094 
00095         $handle = fopen("$dir/styles.xml", 'w');
00096         fwrite($handle, get_ods_styles());
00097         $files[] = "$dir/styles.xml";
00098 
00099         $handle = fopen("$dir/META-INF/manifest.xml", 'w');
00100         fwrite($handle, get_ods_manifest());
00101         $files[] = "$dir/META-INF";
00102 
00103         $filename = "$dir/result.ods";
00104         zip_files($files, $filename);
00105 
00106         $handle = fopen($filename, 'rb');
00107         $contents = fread($handle, filesize($filename));
00108         fclose($handle);
00109 
00110         remove_dir($dir); // cleanup the temp directory
00111 
00112         send_file($contents, $this->filename, 0, 0, true, true, 'application/vnd.oasis.opendocument.spreadsheet');
00113     }
00114 
00115     /* Not required to use
00116      * @param string $name Name of the downloaded file
00117      */
00118     function send($filename) {
00119         $this->filename = $filename;
00120     }
00121 
00122 }
00123 
00130 class MoodleODSWorksheet {
00131     var $data = array();
00132     var $columns = array();
00133     var $rows = array();
00134     var $name;
00135 
00136 
00137     /* Constructs one Moodle Worksheet.
00138      * @param string $filename The name of the file
00139      */
00140     function MoodleODSWorksheet($name) {
00141         $this->name = $name;
00142     }
00143 
00144     /* Write one string somewhere in the worksheet
00145      * @param integer $row    Zero indexed row
00146      * @param integer $col    Zero indexed column
00147      * @param string  $str    The string to write
00148      * @param mixed   $format The XF format for the cell
00149      */
00150     function write_string($row, $col, $str, $format=0) {
00151         if (!array_key_exists($row, $this->data)) {
00152             $this->data[$row] = array();
00153         }
00154         $this->data[$row][$col] = new stdClass();
00155         $this->data[$row][$col]->value = $str;
00156         $this->data[$row][$col]->type = 'string';
00157         $this->data[$row][$col]->format = $format;
00158     }
00159 
00160     /* Write one number somewhere in the worksheet
00161      * @param integer $row    Zero indexed row
00162      * @param integer $col    Zero indexed column
00163      * @param float   $num    The number to write
00164      * @param mixed   $format The XF format for the cell
00165      */
00166     function write_number($row, $col, $num, $format=0) {
00167         if (!array_key_exists($row, $this->data)) {
00168             $this->data[$row] = array();
00169         }
00170         $this->data[$row][$col] = new stdClass();
00171         $this->data[$row][$col]->value = $num;
00172         $this->data[$row][$col]->type = 'float';
00173         $this->data[$row][$col]->format = $format;
00174     }
00175 
00176     /* Write one url somewhere in the worksheet
00177      * @param integer $row    Zero indexed row
00178      * @param integer $col    Zero indexed column
00179      * @param string  $url    The url to write
00180      * @param mixed   $format The XF format for the cell
00181      */
00182     function write_url($row, $col, $url, $format=0) {
00183         if (!array_key_exists($row, $this->data)) {
00184             $this->data[$row] = array();
00185         }
00186         $this->data[$row][$col] = new stdClass();
00187         $this->data[$row][$col]->value = $url;
00188         $this->data[$row][$col]->type = 'string';
00189         $this->data[$row][$col]->format = $format;
00190     }
00191 
00192     /* Write one date somewhere in the worksheet
00193      * @param integer $row    Zero indexed row
00194      * @param integer $col    Zero indexed column
00195      * @param string  $url    The url to write
00196      * @param mixed   $format The XF format for the cell
00197      */
00198     function write_date($row, $col, $date, $format=0) {
00199         if (!array_key_exists($row, $this->data)) {
00200             $this->data[$row] = array();
00201         }
00202         $this->data[$row][$col] = new stdClass();
00203         $this->data[$row][$col]->value = $date;
00204         $this->data[$row][$col]->type = 'date';
00205         $this->data[$row][$col]->format = $format;
00206     }
00207 
00216     function write_formula($row, $col, $formula, $format=null) {
00217         // not implement
00218     }
00219 
00220     /* Write one blanck somewhere in the worksheet
00221      * @param integer $row    Zero indexed row
00222      * @param integer $col    Zero indexed column
00223      * @param mixed   $format The XF format for the cell
00224      */
00225     function write_blank($row, $col, $format=0) {
00226         if (array_key_exists($row, $this->data)) {
00227             unset($this->data[$row][$col]);
00228         }
00229     }
00230 
00231     /* Write anything somewhere in the worksheet
00232      * Type will be automatically detected
00233      * @param integer $row    Zero indexed row
00234      * @param integer $col    Zero indexed column
00235      * @param mixed   $token  What we are writing
00236      * @param mixed   $format The XF format for the cell
00237      */
00238     function write($row, $col, $token, $format=0) {
00239 
00241         if (preg_match("/^([+-]?)(?=\d|\.\d)\d*(\.\d*)?([Ee]([+-]?\d+))?$/", $token)) {
00243             return $this->write_number($row, $col, $token, $format);
00244         } elseif (preg_match("/^[fh]tt?p:\/\//", $token)) {
00246             return $this->write_url($row, $col, $token, '', $format);
00247         } elseif (preg_match("/^mailto:/", $token)) {
00249             return $this->write_url($row, $col, $token, '', $format);
00250         } elseif (preg_match("/^(?:in|ex)ternal:/", $token)) {
00252             return $this->write_url($row, $col, $token, '', $format);
00253         } elseif (preg_match("/^=/", $token)) {
00255             return $this->write_formula($row, $col, $token, $format);
00256         } elseif (preg_match("/^@/", $token)) {
00258             return $this->write_formula($row, $col, $token, $format);
00259         } elseif ($token == '') {
00261             return $this->write_blank($row, $col, $format);
00262         } else {
00264             return $this->write_string($row, $col, $token, $format);
00265         }
00266     }
00267 
00268     /* Sets the height (and other settings) of one row
00269      * @param integer $row    The row to set
00270      * @param integer $height Height we are giving to the row (null to set just format withouth setting the height)
00271      * @param mixed   $format The optional XF format we are giving to the row
00272      * @param bool    $hidden The optional hidden attribute
00273      * @param integer $level  The optional outline level (0-7)
00274      */
00275     function set_row($row, $height, $format = 0, $hidden = false, $level = 0) {
00276         $this->rows[$row] = new stdClass();
00277         $this->rows[$row]->height = $height;
00278         //$this->rows[$row]->format = $format; // TODO: fix and enable
00279         $this->rows[$row]->hidden = $hidden;
00280     }
00281 
00282     /* Sets the width (and other settings) of one column
00283      * @param integer $firstcol first column on the range
00284      * @param integer $lastcol  last column on the range
00285      * @param integer $width    width to set
00286      * @param mixed   $format   The optional XF format to apply to the columns
00287      * @param integer $hidden   The optional hidden atribute
00288      * @param integer $level    The optional outline level (0-7)
00289      */
00290     function set_column($firstcol, $lastcol, $width, $format = 0, $hidden = false, $level = 0) {
00291         for($i=$firstcol; $i<=$lastcol; $i++) {
00292             $this->columns[$i] = new stdClass();
00293             $this->columns[$i]->width = $width;
00294             //$this->columns[$i]->format = $format; // TODO: fix and enable
00295             $this->columns[$i]->hidden = $hidden;
00296 
00297         }
00298     }
00299 
00305     function hide_gridlines() {
00306         // not implement
00307     }
00308 
00314     function hide_screen_gridlines() {
00315         // not implement
00316     }
00317 
00330     function insert_bitmap($row, $col, $bitmap, $x = 0, $y = 0, $scale_x = 1, $scale_y = 1) {
00331         // not implement
00332     }
00343     function merge_cells($first_row, $first_col, $last_row, $last_col) {
00344         // not implement
00345     }
00346 }
00354 class MoodleODSFormat {
00355     var $id;
00356     var $properties;
00357 
00358     /* Constructs one Moodle Format.
00359      * @param object $workbook The internal PEAR Workbook onject we are creating
00360      */
00361     function MoodleODSFormat($properties = array()) {
00362         static $fid = 1;
00363 
00364         $this->id = $fid++;
00365 
00366         foreach($properties as $property => $value) {
00367             if(method_exists($this,"set_$property")) {
00368                 $aux = 'set_'.$property;
00369                 $this->$aux($value);
00370             }
00371         }
00372     }
00373 
00374     /* Set weight of the format
00375      * @param integer $weight Weight for the text, 0 maps to 400 (normal text),
00376      *                        1 maps to 700 (bold text). Valid range is: 100-1000.
00377      *                        It's Optional, default is 1 (bold).
00378      */
00379     function set_bold($weight = 1) {
00380         $this->properties['bold'] = $weight;
00381     }
00382 
00383     /* Set underline of the format
00384      * @param integer $underline The value for underline. Possible values are:
00385      *                           1 => underline, 2 => double underline
00386      */
00387     function set_underline($underline = 1) {
00388         $this->properties['underline'] = $underline;
00389     }
00390 
00391     /* Set italic of the format
00392      */
00393     function set_italic() {
00394         $this->properties['italic'] = true;
00395     }
00396 
00397     /* Set strikeout of the format
00398      */
00399     function set_strikeout() {
00400         $this->properties['strikeout'] = true;
00401     }
00402 
00403     /* Set outlining of the format
00404      */
00405     function set_outline() {
00406     }
00407 
00408     /* Set shadow of the format
00409      */
00410     function set_shadow() {
00411     }
00412 
00413     /* Set the script of the text
00414      * @param integer $script The value for script type. Possible values are:
00415      *                        1 => superscript, 2 => subscript
00416      */
00417     function set_script($script) {
00418     }
00419 
00420     /* Set color of the format
00421      * @param mixed $color either a string (like 'blue'), or an integer (range is [8...63])
00422      */
00423     function set_color($color) {
00424         $this->properties['color'] = $this->_get_color($color);
00425     }
00426 
00427     /* Set foreground color of the format
00428      * @param mixed $color either a string (like 'blue'), or an integer (range is [8...63])
00429      */
00430     function set_fg_color($color) {
00431     }
00432 
00433     /* Set background color of the format
00434      * @param mixed $color either a string (like 'blue'), or an integer (range is [8...63])
00435      */
00436     function set_bg_color($color) {
00437         $this->properties['bg_color'] = $this->_get_color($color);
00438     }
00439 
00440     /* Set the fill pattern of the format
00441      * @param integer Optional. Defaults to 1. Meaningful values are: 0-18
00442      *                0 meaning no background.
00443      */
00444     function set_pattern($pattern=1) {
00445     }
00446 
00447     /* Set text wrap of the format
00448      */
00449     function set_text_wrap() {
00450     }
00451 
00452     /* Set the cell alignment of the format
00453      * @param string $location alignment for the cell ('left', 'right', etc...)
00454      */
00455     function set_align($location) {
00456         switch ($location) {
00457             case 'start':
00458             case 'left':
00459                 $this->properties['align'] = 'start';
00460                 break;
00461             case 'center':
00462                 $this->properties['align'] = 'center';
00463                 break;
00464             case 'end':
00465             case 'right':
00466                 $this->properties['align'] = 'end';
00467                 break;
00468             default:
00469                 //ignore the rest == start
00470         }
00471     }
00472 
00473     /* Set the cell horizontal alignment of the format
00474      * @param string $location alignment for the cell ('left', 'right', etc...)
00475      */
00476     function set_h_align($location) {
00477         $this->set_align($location);
00478     }
00479 
00480     /* Set the cell vertical alignment of the format
00481      * @param string $location alignment for the cell ('top', 'vleft', etc...)
00482      */
00483     function set_v_align($location) {
00484         switch ($location) {
00485             case 'top':
00486                 $this->properties['v_align'] = 'top';
00487                 break;
00488             case 'bottom':
00489                 $this->properties['v_align'] = 'bottom';
00490                 break;
00491             default:
00492                 //ignore the rest == middle
00493         }
00494     }
00495 
00496     /* Set the top border of the format
00497      * @param integer $style style for the cell. 1 => thin, 2 => thick
00498      */
00499     function set_top($style) {
00500     }
00501 
00502     /* Set the bottom border of the format
00503      * @param integer $style style for the cell. 1 => thin, 2 => thick
00504      */
00505     function set_bottom($style) {
00506     }
00507 
00508     /* Set the left border of the format
00509      * @param integer $style style for the cell. 1 => thin, 2 => thick
00510      */
00511     function set_left($style) {
00512     }
00513 
00514     /* Set the right border of the format
00515      * @param integer $style style for the cell. 1 => thin, 2 => thick
00516      */
00517     function set_right($style) {
00518     }
00519 
00524     function set_border($style) {
00525     }
00526 
00527     /* Set the numerical format of the format
00528      * It can be date, time, currency, etc...
00529     /* Set the numerical format of the format
00530      * It can be date, time, currency, etc...
00531      * @param integer $num_format The numeric format
00532      */
00533     function set_num_format($num_format) {
00534     }
00535 
00536     function _get_color($name_color = '') {
00537         if (strpos($name_color, '#') === 0) {
00538             return $name_color; // no conversion needed
00539         }
00540 
00541         $colors = array('aqua'    => '#00FFFF',
00542                         'cyan'    => '#00FFFF',
00543                         'black'   => '#FFFFFF',
00544                         'blue'    => '#0000FF',
00545                         'brown'   => '#A52A2A',
00546                         'magenta' => '#FF00FF',
00547                         'fuchsia' => '#FF00FF',
00548                         'gray'    => '#A0A0A0',
00549                         'grey'    => '#A0A0A0',
00550                         'green'   => '#00FF00',
00551                         'lime'    => '#00FF00',
00552                         'navy'    => '#000080',
00553                         'orange'  => '#FF8000',
00554                         'purple'  => '#800080',
00555                         'red'     => '#FF0000',
00556                         'silver'  => '#DCDCDC',
00557                         'white'   => '#FFFFFF',
00558                         'yellow'  => '#FFFF00');
00559 
00560         if(array_key_exists($name_color, $colors)) {
00561             return $colors[$name_color];
00562         } else {
00563             return false;
00564         }
00565     }
00566 }
00567 
00568 
00569 //=============================
00570 // OpenDocument XML functions
00571 //=============================
00572 function get_ods_content(&$worksheets) {
00573 
00574 
00575     // find out the size of worksheets and used styles
00576     $formats = array();
00577     $formatstyles = '';
00578     $rowstyles = '';
00579     $colstyles = '';
00580 
00581     foreach($worksheets as $wsnum=>$ws) {
00582         $worksheets[$wsnum]->maxr = 0;
00583         $worksheets[$wsnum]->maxc = 0;
00584         foreach($ws->data as $rnum=>$row) {
00585             if ($rnum > $worksheets[$wsnum]->maxr) {
00586                 $worksheets[$wsnum]->maxr = $rnum;
00587             }
00588             foreach($row as $cnum=>$cell) {
00589                 if ($cnum > $worksheets[$wsnum]->maxc) {
00590                     $worksheets[$wsnum]->maxc = $cnum;
00591                 }
00592                 if (!empty($cell->format)) {
00593                     if (!array_key_exists($cell->format->id, $formats)) {
00594                         $formats[$cell->format->id] = $cell->format;
00595                     }
00596                 }
00597             }
00598         }
00599 
00600         foreach($ws->rows as $rnum=>$row) {
00601             if (!empty($row->format)) {
00602                 if (!array_key_exists($row->format->id, $formats)) {
00603                     $formats[$row->format->id] = $row->format;
00604                 }
00605             }
00606             if ($rnum > $worksheets[$wsnum]->maxr) {
00607                 $worksheets[$wsnum]->maxr = $rnum;
00608             }
00609             //define all column styles
00610             if (!empty($ws->rows[$rnum])) {
00611                 $rowstyles .= '
00612   <style:style style:name="ws'.$wsnum.'ro'.$rnum.'" style:family="table-row">
00613    <style:table-row-properties style:row-height="'.$row->height.'pt"/>
00614   </style:style>';
00615             }
00616         }
00617 
00618         foreach($ws->columns as $cnum=>$col) {
00619             if (!empty($col->format)) {
00620                 if (!array_key_exists($col->format->id, $formats)) {
00621                     $formats[$col->format->id] = $col->format;
00622                 }
00623             }
00624             if ($cnum > $worksheets[$wsnum]->maxc) {
00625                 $worksheets[$wsnum]->maxc = $cnum;
00626             }
00627             //define all column styles
00628             if (!empty($ws->columns[$cnum])) {
00629                 $colstyles .= '
00630   <style:style style:name="ws'.$wsnum.'co'.$cnum.'" style:family="table-column">
00631    <style:table-column-properties style:column-width="'.$col->width.'pt"/>
00632   </style:style>';
00633             }
00634         }
00635     }
00636 
00637     foreach($formats as $format) {
00638         $textprop = '';
00639         $cellprop = '';
00640         $parprop  = '';
00641         foreach($format->properties as $pname=>$pvalue) {
00642             switch ($pname) {
00643                 case 'bold':
00644                     if (!empty($pvalue)) {
00645                         $textprop .= ' fo:font-weight="bold"';
00646                     }
00647                     break;
00648                 case 'italic':
00649                     if (!empty($pvalue)) {
00650                         $textprop .= ' fo:font-style="italic"';
00651                     }
00652                     break;
00653                 case 'underline':
00654                     if (!empty($pvalue)) {
00655                         $textprop .= ' style:text-underline-color="font-color" style:text-underline-style="solid" style:text-underline-width="auto"';
00656                     }
00657                     break;
00658                 case 'strikeout':
00659                     if (!empty($pvalue)) {
00660                         $textprop .= ' style:text-line-through-style="solid"';
00661                     }
00662                     break;
00663                 case 'color':
00664                     if ($pvalue !== false) {
00665                         $textprop .= ' fo:color="'.$pvalue.'"';
00666                     }
00667                     break;
00668                 case 'bg_color':
00669                     if ($pvalue !== false) {
00670                         $cellprop .= ' fo:background-color="'.$pvalue.'"';
00671                     }
00672                     break;
00673                 case 'align':
00674                     $parprop .= ' fo:text-align="'.$pvalue.'"';
00675                     break;
00676                 case 'v_align':
00677                     $cellprop .= ' style:vertical-align="'.$pvalue.'"';
00678                     break;
00679             }
00680         }
00681         if (!empty($textprop)) {
00682             $textprop = '
00683    <style:text-properties'.$textprop.'/>';
00684         }
00685 
00686         if (!empty($cellprop)) {
00687             $cellprop = '
00688    <style:table-cell-properties'.$cellprop.'/>';
00689         }
00690 
00691         if (!empty($parprop)) {
00692             $parprop = '
00693    <style:paragraph-properties'.$parprop.'/>';
00694         }
00695 
00696         $formatstyles .= '
00697   <style:style style:name="format'.$format->id.'" style:family="table-cell">'.$textprop.$cellprop.$parprop.'
00698   </style:style>';
00699     }
00700 
00702     $buffer =
00703 '<?xml version="1.0" encoding="UTF-8"?>
00704 <office:document-content xmlns:office="urn:oasis:names:tc:opendocument:xmlns:office:1.0" xmlns:meta="urn:oasis:names:tc:opendocument:xmlns:meta:1.0" xmlns:config="urn:oasis:names:tc:opendocument:xmlns:config:1.0" xmlns:text="urn:oasis:names:tc:opendocument:xmlns:text:1.0" xmlns:table="urn:oasis:names:tc:opendocument:xmlns:table:1.0" xmlns:draw="urn:oasis:names:tc:opendocument:xmlns:drawing:1.0" xmlns:presentation="urn:oasis:names:tc:opendocument:xmlns:presentation:1.0" xmlns:dr3d="urn:oasis:names:tc:opendocument:xmlns:dr3d:1.0" xmlns:chart="urn:oasis:names:tc:opendocument:xmlns:chart:1.0" xmlns:form="urn:oasis:names:tc:opendocument:xmlns:form:1.0" xmlns:script="urn:oasis:names:tc:opendocument:xmlns:script:1.0" xmlns:style="urn:oasis:names:tc:opendocument:xmlns:style:1.0" xmlns:number="urn:oasis:names:tc:opendocument:xmlns:datastyle:1.0" xmlns:math="http://www.w3.org/1998/Math/MathML" xmlns:svg="urn:oasis:names:tc:opendocument:xmlns:svg-compatible:1.0" xmlns:fo="urn:oasis:names:tc:opendocument:xmlns:xsl-fo-compatible:1.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:xlink="http://www.w3.org/1999/xlink">
00705  <office:automatic-styles>
00706   <style:style style:name="ta1" style:family="table" style:master-page-name="Standard1">
00707    <style:table-properties table:display="true"/>
00708   </style:style>
00709   <style:style style:name="date0" style:family="table-cell"/>';
00710 
00711 $buffer .= $formatstyles;
00712 $buffer .= $rowstyles;
00713 $buffer .= $colstyles;
00714 
00715  $buffer .= '
00716  </office:automatic-styles>
00717  <office:body>
00718   <office:spreadsheet>
00719 ';
00720 
00721     foreach($worksheets as $wsnum=>$ws) {
00722 
00724         $buffer .= '<table:table table:name="' . htmlspecialchars($ws->name) . '" table:style-name="ta1">'."\n";
00725 
00726         // define column properties
00727         for($c=0; $c<=$ws->maxc; $c++) {
00728             if (array_key_exists($c, $ws->columns)) {
00729                 $extra = '';
00730                 if (!empty($ws->columns[$c]->format)) {
00731                     $extra .= ' table:default-cell-style-name="format'.$ws->columns[$c]->format->id.'"';
00732                 }
00733                 if ($ws->columns[$c]->hidden) {
00734                     $extra .= ' table:visibility="collapse"';
00735                 }
00736                 $buffer .= '<table:table-column table:style-name="ws'.$wsnum.'co'.$c.'"'.$extra.'/>'."\n";
00737             } else {
00738                 $buffer .= '<table:table-column/>'."\n";
00739             }
00740         }
00741 
00742         // print all rows
00743         for($r=0; $r<=$ws->maxr; $r++) {
00744             if (array_key_exists($r, $ws->rows)) {
00745                 $extra = '';
00746                 if (!empty($ws->rows[$r]->format)) {
00747                     $extra .= ' table:default-cell-style-name="format'.$ws->rows[$r]->format->id.'"';
00748                 }
00749                 if ($ws->rows[$r]->hidden) {
00750                     $extra .= ' table:visibility="collapse"';
00751                 }
00752                 $buffer .= '<table:table-row table:style-name="ws'.$wsnum.'ro'.$r.'"'.$extra.'>'."\n";
00753             } else {
00754                 $buffer .= '<table:table-row>'."\n";
00755             }
00756             for($c=0; $c<=$ws->maxc; $c++) {
00757                 if (isset($ws->data[$r][$c])) {
00758                     $cell = $ws->data[$r][$c];
00759                     $extra = ' ';
00760                     if (!empty($cell->format)) {
00761                         $extra = ' table:style-name="format'.$cell->format->id.'"';
00762                     }
00763                     if ($cell->type == 'date') {
00764                         $buffer .= '<table:table-cell office:value-type="date" table:style-name="date0" office:date-value="' . strftime('%Y-%m-%dT%H:%M:%S', $cell->value) . '"'.$extra.'>'
00765                                  . '<text:p>' . strftime('%Y-%m-%dT%H:%M:%S', $cell->value) . '</text:p>'
00766                                  . '</table:table-cell>'."\n";
00767                     } else if ($cell->type == 'float') {
00768                         $buffer .= '<table:table-cell office:value-type="float" office:value="' . htmlspecialchars($cell->value) . '"'.$extra.'>'
00769                                  . '<text:p>' . htmlspecialchars($cell->value) . '</text:p>'
00770                                  . '</table:table-cell>'."\n";
00771                     } else if ($cell->type == 'string') {
00772                         $buffer .= '<table:table-cell office:value-type="string" office:string-value="' . htmlspecialchars($cell->value) . '"'.$extra.'>'
00773                                  . '<text:p>' . htmlspecialchars($cell->value) . '</text:p>'
00774                                  . '</table:table-cell>'."\n";
00775                     } else {
00776                         $buffer .= '<table:table-cell office:value-type="string"'.$extra.'>'
00777                                  . '<text:p>!!Error - unknown type!!</text:p>'
00778                                  . '</table:table-cell>'."\n";
00779                     }
00780                 } else {
00781                     $buffer .= '<table:table-cell/>'."\n";
00782                 }
00783             }
00784             $buffer .= '</table:table-row>'."\n";
00785         }
00787         $buffer .= '</table:table>'."\n";
00788 
00789     }
00790 
00792     $buffer .=
00793 '  </office:spreadsheet>
00794  </office:body>
00795 </office:document-content>';
00796 
00797     return $buffer;
00798 }
00799 
00800 function get_ods_mimetype() {
00801     return 'application/vnd.oasis.opendocument.spreadsheet';
00802 }
00803 
00804 function get_ods_meta() {
00805     global $CFG, $USER;
00806 
00807     return
00808 '<?xml version="1.0" encoding="UTF-8"?>
00809 <office:document-meta xmlns:office="urn:oasis:names:tc:opendocument:xmlns:office:1.0" xmlns:meta="urn:oasis:names:tc:opendocument:xmlns:meta:1.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:xlink="http://www.w3.org/1999/xlink">
00810  <office:meta>
00811   <meta:generator>Moodle '.$CFG->version.'</meta:generator>
00812   <meta:initial-creator>'.fullname($USER, true).'</meta:initial-creator>
00813   <meta:editing-cycles>1</meta:editing-cycles>
00814   <meta:creation-date>'.strftime('%Y-%m-%dT%H:%M:%S').'</meta:creation-date>
00815   <dc:date>'.strftime('%Y-%m-%dT%H:%M:%S').'</dc:date>
00816   <dc:creator>'.fullname($USER, true).'</dc:creator>
00817  </office:meta>
00818 </office:document-meta>';
00819 }
00820 
00821 function get_ods_styles() {
00822     return
00823 '<?xml version="1.0" encoding="UTF-8"?>
00824 <office:document-styles xmlns:office="urn:oasis:names:tc:opendocument:xmlns:office:1.0" xmlns:meta="urn:oasis:names:tc:opendocument:xmlns:meta:1.0" xmlns:config="urn:oasis:names:tc:opendocument:xmlns:config:1.0" xmlns:text="urn:oasis:names:tc:opendocument:xmlns:text:1.0" xmlns:table="urn:oasis:names:tc:opendocument:xmlns:table:1.0" xmlns:draw="urn:oasis:names:tc:opendocument:xmlns:drawing:1.0" xmlns:presentation="urn:oasis:names:tc:opendocument:xmlns:presentation:1.0" xmlns:dr3d="urn:oasis:names:tc:opendocument:xmlns:dr3d:1.0" xmlns:chart="urn:oasis:names:tc:opendocument:xmlns:chart:1.0" xmlns:form="urn:oasis:names:tc:opendocument:xmlns:form:1.0" xmlns:script="urn:oasis:names:tc:opendocument:xmlns:script:1.0" xmlns:style="urn:oasis:names:tc:opendocument:xmlns:style:1.0" xmlns:number="urn:oasis:names:tc:opendocument:xmlns:datastyle:1.0" xmlns:math="http://www.w3.org/1998/Math/MathML" xmlns:svg="urn:oasis:names:tc:opendocument:xmlns:svg-compatible:1.0" xmlns:fo="urn:oasis:names:tc:opendocument:xmlns:xsl-fo-compatible:1.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:xlink="http://www.w3.org/1999/xlink">
00825  <office:styles>
00826   <style:default-style style:family="table-column">
00827    <style:table-column-properties style:column-width="75pt"/>
00828   </style:default-style>
00829   <style:default-style style:family="table-row">
00830    <style:table-row-properties style:row-height="15pt"/>
00831   </style:default-style>
00832   <style:default-style style:family="table-cell">
00833    <style:table-cell-properties fo:background-color="#ffffff" style:cell-protect="protected" style:vertical-align="middle"/>
00834    <style:text-properties fo:color="#000000" fo:font-family="Arial" fo:font-size="12pt"/>
00835   </style:default-style>
00836  </office:styles>
00837  <office:automatic-styles>
00838   <style:page-layout style:name="pm1">
00839    <style:page-layout-properties fo:margin-bottom="56.6930116pt" fo:margin-left="56.6930116pt" fo:margin-right="56.6930116pt" fo:margin-top="56.6930116pt" fo:page-height="841.89122226pt" fo:page-width="595.2766218pt" style:print="objects charts drawings zero-values" style:print-orientation="portrait"/>
00840   </style:page-layout>
00841  </office:automatic-styles>
00842  <office:master-styles>
00843   <style:master-page style:name="Standard1" style:page-layout-name="pm1">
00844    <style:header>
00845  <text:p>
00846   <text:sheet-name>???</text:sheet-name>
00847  </text:p>
00848 </style:header><style:footer>
00849  <text:p>
00850   <text:sheet-name>Page </text:sheet-name>
00851   <text:page-number>1</text:page-number>
00852  </text:p>
00853 </style:footer>
00854   </style:master-page>
00855  </office:master-styles>
00856 </office:document-styles>
00857 ';
00858 }
00859 
00860 function get_ods_manifest() {
00861     return
00862 '<?xml version="1.0" encoding="UTF-8"?>
00863 <manifest:manifest xmlns:manifest="urn:oasis:names:tc:opendocument:xmlns:manifest:1.0">
00864  <manifest:file-entry manifest:media-type="application/vnd.oasis.opendocument.spreadsheet" manifest:full-path="/"/>
00865  <manifest:file-entry manifest:media-type="text/xml" manifest:full-path="content.xml"/>
00866  <manifest:file-entry manifest:media-type="text/xml" manifest:full-path="styles.xml"/>
00867  <manifest:file-entry manifest:media-type="text/xml" manifest:full-path="meta.xml"/>
00868 </manifest:manifest>';
00869 }
 All Data Structures Namespaces Files Functions Variables Enumerations