Proyectos de Subversion Moodle

Rev

Rev 1 | | Comparar con el anterior | Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
1 efrain 1
<?php
2
// This file is part of Moodle - http://moodle.org/
3
//
4
// Moodle is free software: you can redistribute it and/or modify
5
// it under the terms of the GNU General Public License as published by
6
// the Free Software Foundation, either version 3 of the License, or
7
// (at your option) any later version.
8
//
9
// Moodle is distributed in the hope that it will be useful,
10
// but WITHOUT ANY WARRANTY; without even the implied warranty of
11
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
// GNU General Public License for more details.
13
//
14
// You should have received a copy of the GNU General Public License
15
// along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
16
 
17
/**
18
 * ODS file writer.
19
 * The xml used here is derived from output of LibreOffice 3.6.4
20
 *
21
 * The design is based on Excel writer abstraction by Eloy Lafuente and others.
22
 *
23
 * @package   core
24
 * @copyright 2006 Petr Skoda {@link http://skodak.org}
25
 * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
26
 */
27
 
28
defined('MOODLE_INTERNAL') || die();
29
 
30
 
31
/**
32
 * ODS workbook abstraction.
33
 *
34
 * @package   core
35
 * @copyright 2006 Petr Skoda {@link http://skodak.org}
36
 * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
37
 */
38
class MoodleODSWorkbook {
39
    protected $worksheets = array();
40
    protected $filename;
41
 
42
    public function __construct($filename) {
43
        $this->filename = $filename;
44
    }
45
 
46
    /**
47
     * Create one Moodle Worksheet.
48
     *
49
     * @param string $name Name of the sheet
50
     * @return MoodleODSWorksheet
51
     */
52
    public function add_worksheet($name = '') {
53
        $ws = new MoodleODSWorksheet($name, $this->worksheets);
54
        $this->worksheets[] = $ws;
55
        return $ws;
56
    }
57
 
58
    /**
59
     * Create one Moodle Format.
60
     *
61
     * @param array $properties array of properties [name]=value;
62
     *                          valid names are set_XXXX existing
63
     *                          functions without the set_ part
64
     *                          i.e: [bold]=1 for set_bold(1)...Optional!
65
     * @return MoodleODSFormat
66
     */
67
    public function add_format($properties = array()) {
68
        return new MoodleODSFormat($properties);
69
    }
70
 
71
    /**
72
     * Close the Moodle Workbook.
73
     */
74
    public function close() {
75
        global $CFG;
76
        require_once($CFG->libdir . '/filelib.php');
77
 
78
        $writer = new MoodleODSWriter($this->worksheets);
79
        $contents = $writer->get_file_content();
80
 
81
        send_file($contents, $this->filename, 0, 0, true, true, $writer->get_ods_mimetype());
82
    }
83
 
84
    /**
85
     * Not required to use.
86
     * @param string $filename Name of the downloaded file
87
     */
88
    public function send($filename) {
89
        $this->filename = $filename;
90
    }
91
 
92
}
93
 
94
 
95
/**
96
 * ODS Cell abstraction.
97
 *
98
 * @package   core
99
 * @copyright 2013 Petr Skoda {@link http://skodak.org}
100
 * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
101
 */
102
class MoodleODSCell {
103
    public $value;
104
    public $type;
105
    public $format;
106
    public $formula;
1441 ariadna 107
    /**
108
     * @var array Contains the number of rows and columns spanned by the merged cell.
109
     *            'rows' => integer, the number of rows the cell spans.
110
     *            'columns' => integer, the number of columns the cell spans.
111
     */
112
    public $merge;
1 efrain 113
}
114
 
115
 
116
/**
117
 * ODS Worksheet abstraction.
118
 *
119
 * @package   core
120
 * @copyright 2006 Petr Skoda {@link http://skodak.org}
121
 * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
122
 */
123
class MoodleODSWorksheet {
124
    public $data = array();
125
    public $columns = array();
126
    public $rows = array();
127
    public $showgrid = true;
128
    public $name;
129
    /** @var int Max number of rows in the sheet. */
130
    public $maxr = 0;
131
    /** @var int Max number of cols in the sheet. */
132
    public $maxc = 0;
133
 
134
    /**
135
     * Constructs one Moodle Worksheet.
136
     *
137
     * @param string $name The name of the file
138
     * @param array $worksheets existing worksheets
139
     */
140
    public function __construct($name, array $worksheets) {
141
        // Replace any characters in the name that Excel cannot cope with.
142
        $name = strtr($name, '[]*/\?:', '       ');
143
 
144
        if ($name === '') {
145
            // Name is required!
146
            $name = 'Sheet'.(count($worksheets)+1);
147
        }
148
 
149
        $this->name = $name;
150
    }
151
 
152
    /**
153
     * Write one string somewhere in the worksheet.
154
     *
155
     * @param integer $row    Zero indexed row
156
     * @param integer $col    Zero indexed column
157
     * @param string  $str    The string to write
158
     * @param mixed   $format The XF format for the cell
159
     */
160
    public function write_string($row, $col, $str, $format = null) {
161
        if (!isset($this->data[$row][$col])) {
162
            $this->data[$row][$col] = new MoodleODSCell();
163
        }
164
        if (is_array($format)) {
165
            $format = new MoodleODSFormat($format);
166
        }
167
        $this->data[$row][$col]->value = $str;
168
        $this->data[$row][$col]->type = 'string';
169
        $this->data[$row][$col]->format = $format;
170
        $this->data[$row][$col]->formula = null;
171
    }
172
 
173
    /**
174
     * Write one number somewhere in the worksheet.
175
     *
176
     * @param integer $row    Zero indexed row
177
     * @param integer $col    Zero indexed column
178
     * @param float   $num    The number to write
179
     * @param mixed   $format The XF format for the cell
180
     */
181
    public function write_number($row, $col, $num, $format = null) {
182
        if (!isset($this->data[$row][$col])) {
183
            $this->data[$row][$col] = new MoodleODSCell();
184
        }
185
        if (is_array($format)) {
186
            $format = new MoodleODSFormat($format);
187
        }
188
        $this->data[$row][$col]->value = $num;
189
        $this->data[$row][$col]->type = 'float';
190
        $this->data[$row][$col]->format = $format;
191
        $this->data[$row][$col]->formula = null;
192
    }
193
 
194
    /**
195
     * Write one url somewhere in the worksheet.
196
     *
197
     * @param integer $row    Zero indexed row
198
     * @param integer $col    Zero indexed column
199
     * @param string  $url    The url to write
200
     * @param mixed   $format The XF format for the cell
201
     */
202
    public function write_url($row, $col, $url, $format = null) {
203
        if (!isset($this->data[$row][$col])) {
204
            $this->data[$row][$col] = new MoodleODSCell();
205
        }
206
        if (is_array($format)) {
207
            $format = new MoodleODSFormat($format);
208
        }
209
        $this->data[$row][$col]->value = $url;
210
        $this->data[$row][$col]->type = 'string';
211
        $this->data[$row][$col]->format = $format;
212
        $this->data[$row][$col]->formula = null;
213
    }
214
 
215
    /**
216
     * Write one date somewhere in the worksheet.
217
     *
218
     * @param integer $row    Zero indexed row
219
     * @param integer $col    Zero indexed column
220
     * @param string  $date    The url to write
221
     * @param mixed   $format The XF format for the cell
222
     */
223
    public function write_date($row, $col, $date, $format = null) {
224
        if (!isset($this->data[$row][$col])) {
225
            $this->data[$row][$col] = new MoodleODSCell();
226
        }
227
        if (is_array($format)) {
228
            $format = new MoodleODSFormat($format);
229
        }
230
        $this->data[$row][$col]->value = $date;
231
        $this->data[$row][$col]->type = 'date';
232
        $this->data[$row][$col]->format = $format;
233
        $this->data[$row][$col]->formula = null;
234
    }
235
 
236
    /**
237
     * Write one formula somewhere in the worksheet.
238
     *
239
     * @param integer $row    Zero indexed row
240
     * @param integer $col    Zero indexed column
241
     * @param string  $formula The formula to write
242
     * @param mixed   $format The XF format for the cell
243
     */
244
    public function write_formula($row, $col, $formula, $format = null) {
245
        if (!isset($this->data[$row][$col])) {
246
            $this->data[$row][$col] = new MoodleODSCell();
247
        }
248
        if (is_array($format)) {
249
            $format = new MoodleODSFormat($format);
250
        }
251
        $this->data[$row][$col]->formula = $formula;
252
        $this->data[$row][$col]->format = $format;
253
        $this->data[$row][$col]->value = null;
254
        $this->data[$row][$col]->format = null;
255
    }
256
 
257
    /**
258
     * Write one blank somewhere in the worksheet.
259
     *
260
     * @param integer $row    Zero indexed row
261
     * @param integer $col    Zero indexed column
262
     * @param mixed   $format The XF format for the cell
263
     */
264
    public function write_blank($row, $col, $format = null) {
265
        if (is_array($format)) {
266
            $format = new MoodleODSFormat($format);
267
        }
268
        $this->write_string($row, $col, '', $format);
269
    }
270
 
271
    /**
272
     * Write anything somewhere in the worksheet,
273
     * type will be automatically detected.
274
     *
275
     * @param integer $row    Zero indexed row
276
     * @param integer $col    Zero indexed column
277
     * @param mixed   $token  What we are writing
278
     * @param mixed   $format The XF format for the cell
279
     */
280
    public function write($row, $col, $token, $format = null) {
281
        // Analyse what are we trying to send.
282
        if (preg_match("/^([+-]?)(?=\d|\.\d)\d*(\.\d*)?([Ee]([+-]?\d+))?$/", $token)) {
283
            // Match number
284
            return $this->write_number($row, $col, $token, $format);
285
        } elseif (preg_match("/^[fh]tt?p:\/\//", $token)) {
286
            // Match http or ftp URL
287
            return $this->write_url($row, $col, $token, '', $format);
288
        } elseif (preg_match("/^mailto:/", $token)) {
289
            // Match mailto:
290
            return $this->write_url($row, $col, $token, '', $format);
291
        } elseif (preg_match("/^(?:in|ex)ternal:/", $token)) {
292
            // Match internal or external sheet link
293
            return $this->write_url($row, $col, $token, '', $format);
294
        } elseif (preg_match("/^=/", $token)) {
295
            // Match formula
296
            return $this->write_formula($row, $col, $token, $format);
297
        } elseif (preg_match("/^@/", $token)) {
298
            // Match formula
299
            return $this->write_formula($row, $col, $token, $format);
300
        } elseif ($token == '') {
301
            // Match blank
302
            return $this->write_blank($row, $col, $format);
303
        } else {
304
            // Default: match string
305
            return $this->write_string($row, $col, $token, $format);
306
        }
307
    }
308
 
309
    /**
310
     * Sets the height (and other settings) of one row.
311
     *
312
     * @param integer $row    The row to set
313
     * @param integer $height Height we are giving to the row (null to set just format without setting the height)
314
     * @param mixed   $format The optional format we are giving to the row
315
     * @param bool    $hidden The optional hidden attribute
316
     * @param integer $level  The optional outline level (0-7)
317
     */
318
    public function set_row($row, $height, $format = null, $hidden = false, $level = 0) {
319
        if (is_array($format)) {
320
            $format = new MoodleODSFormat($format);
321
        }
322
        if ($level < 0) {
323
            $level = 0;
324
        } else if ($level > 7) {
325
            $level = 7;
326
        }
327
        if (!isset($this->rows[$row])) {
328
            $this->rows[$row] = new stdClass();
329
        }
330
        if (isset($height)) {
331
            $this->rows[$row]->height = $height;
332
        }
333
        $this->rows[$row]->format = $format;
334
        $this->rows[$row]->hidden = $hidden;
335
        $this->rows[$row]->level  = $level;
336
    }
337
 
338
    /**
339
     * Sets the width (and other settings) of one column.
340
     *
341
     * @param integer $firstcol first column on the range
342
     * @param integer $lastcol  last column on the range
343
     * @param integer $width    width to set (null to set just format without setting the width)
344
     * @param mixed   $format   The optional format to apply to the columns
345
     * @param bool    $hidden   The optional hidden attribute
346
     * @param integer $level    The optional outline level (0-7)
347
     */
348
    public function set_column($firstcol, $lastcol, $width, $format = null, $hidden = false, $level = 0) {
349
        if (is_array($format)) {
350
            $format = new MoodleODSFormat($format);
351
        }
352
        if ($level < 0) {
353
            $level = 0;
354
        } else if ($level > 7) {
355
            $level = 7;
356
        }
357
        for($i=$firstcol; $i<=$lastcol; $i++) {
358
            if (!isset($this->columns[$i])) {
359
                $this->columns[$i] = new stdClass();
360
            }
361
            if (isset($width)) {
362
                $this->columns[$i]->width = $width*6.15; // 6.15 is a magic constant here!
363
            }
364
            $this->columns[$i]->format = $format;
365
            $this->columns[$i]->hidden = $hidden;
366
            $this->columns[$i]->level  = $level;
367
        }
368
    }
369
 
370
    /**
371
     * Set the option to hide gridlines on the printed page.
372
     */
373
    public function hide_gridlines() {
374
        // Not implemented - always off.
375
    }
376
 
377
    /**
378
     * Set the option to hide gridlines on the worksheet (as seen on the screen).
379
     */
380
    public function hide_screen_gridlines() {
381
        $this->showgrid = false;
382
    }
383
 
384
    /**
385
     * Insert a 24bit bitmap image in a worksheet.
386
     *
387
     * @param integer $row     The row we are going to insert the bitmap into
388
     * @param integer $col     The column we are going to insert the bitmap into
389
     * @param string  $bitmap  The bitmap filename
390
     * @param integer $x       The horizontal position (offset) of the image inside the cell.
391
     * @param integer $y       The vertical position (offset) of the image inside the cell.
392
     * @param integer $scale_x The horizontal scale
393
     * @param integer $scale_y The vertical scale
394
     */
395
    public function insert_bitmap($row, $col, $bitmap, $x = 0, $y = 0, $scale_x = 1, $scale_y = 1) {
396
        // Not implemented.
397
    }
398
 
399
    /**
400
     * Merges the area given by its arguments.
401
     *
402
     * @param integer $first_row First row of the area to merge
403
     * @param integer $first_col First column of the area to merge
404
     * @param integer $last_row  Last row of the area to merge
405
     * @param integer $last_col  Last column of the area to merge
406
     */
407
    public function merge_cells($first_row, $first_col, $last_row, $last_col) {
408
        if ($first_row > $last_row or $first_col > $last_col) {
409
            return;
410
        }
411
 
412
        if (!isset($this->data[$first_row][$first_col])) {
413
            $this->data[$first_row][$first_col] = new MoodleODSCell();
414
        }
415
 
416
        $this->data[$first_row][$first_col]->merge = array('rows'=>($last_row-$first_row+1), 'columns'=>($last_col-$first_col+1));
417
    }
418
}
419
 
420
 
421
/**
422
 * ODS cell format abstraction.
423
 *
424
 * @package   core
425
 * @copyright 2006 Petr Skoda {@link http://skodak.org}
426
 * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
427
 */
428
class MoodleODSFormat {
429
    public $id;
430
    public $properties = array();
431
 
432
    /**
433
     * Constructs one Moodle Format.
434
     *
435
     * @param array $properties
436
     */
437
    public function __construct($properties = array()) {
438
        static $fid = 1;
439
 
440
        $this->id = $fid++;
441
 
442
        foreach($properties as $property => $value) {
443
            if (method_exists($this, "set_$property")) {
444
                $aux = 'set_'.$property;
445
                $this->$aux($value);
446
            }
447
        }
448
    }
449
 
450
    /**
451
     * Set the size of the text in the format (in pixels).
452
     * By default all texts in generated sheets are 10pt.
453
     *
454
     * @param integer $size Size of the text (in points)
455
     */
456
    public function set_size($size) {
457
        $this->properties['size'] = $size;
458
    }
459
 
460
    /**
461
     * Set weight of the format.
462
     *
463
     * @param integer $weight Weight for the text, 0 maps to 400 (normal text),
464
     *                        1 maps to 700 (bold text). Valid range is: 100-1000.
465
     *                        It's Optional, default is 1 (bold).
466
     */
467
    public function set_bold($weight = 1) {
468
        if ($weight == 1) {
469
            $weight = 700;
470
        }
471
        $this->properties['bold'] = ($weight > 400);
472
    }
473
 
474
    /**
475
     * Set underline of the format.
476
     *
477
     * @param integer $underline The value for underline. Possible values are:
478
     *                           1 => underline, 2 => double underline
479
     */
480
    public function set_underline($underline = 1) {
481
        if ($underline == 1) {
482
            $this->properties['underline'] = 1;
483
        } else if ($underline == 2) {
484
            $this->properties['underline'] = 2;
485
        } else {
486
            unset($this->properties['underline']);
487
        }
488
    }
489
 
490
    /**
491
     * Set italic of the format.
492
     */
493
    public function set_italic() {
494
        $this->properties['italic'] = true;
495
    }
496
 
497
    /**
498
     * Set strikeout of the format
499
     */
500
    public function set_strikeout() {
501
        $this->properties['strikeout'] = true;
502
    }
503
 
504
    /**
505
     * Set outlining of the format.
506
     */
507
    public function set_outline() {
508
        // Not implemented.
509
    }
510
 
511
    /**
512
     * Set shadow of the format.
513
     */
514
    public function set_shadow() {
515
        // Not implemented.
516
    }
517
 
518
    /**
519
     * Set the script of the text.
520
     *
521
     * @param integer $script The value for script type. Possible values are:
522
     *                        1 => superscript, 2 => subscript
523
     */
524
    public function set_script($script) {
525
        if ($script == 1) {
526
            $this->properties['super_script'] = true;
527
            unset($this->properties['sub_script']);
528
 
529
        } else if ($script == 2) {
530
            $this->properties['sub_script'] = true;
531
            unset($this->properties['super_script']);
532
 
533
        } else {
534
            unset($this->properties['sub_script']);
535
            unset($this->properties['super_script']);
536
        }
537
    }
538
 
539
    /**
540
     * Set color of the format.
541
     *
542
     * @param mixed $color either a string (like 'blue'), or an integer (range is [8...63])
543
     */
544
    public function set_color($color) {
545
        $this->properties['color'] = $this->parse_color($color);
546
    }
547
 
548
    /**
549
     * Not used.
550
     *
551
     * @param mixed $color
552
     */
553
    public function set_fg_color($color) {
554
        // Not implemented.
555
    }
556
 
557
    /**
558
     * Set background color of the cell.
559
     *
560
     * @param mixed $color either a string (like 'blue'), or an integer (range is [8...63])
561
     */
562
    public function set_bg_color($color) {
563
        $this->properties['bg_color'] = $this->parse_color($color);
564
    }
565
 
566
    /**
567
     * Set the cell fill pattern.
568
     *
569
     * @deprecated use set_bg_color() instead.
570
     * @param integer
571
     */
572
    public function set_pattern($pattern=1) {
573
        if ($pattern > 0) {
574
            if (!isset($this->properties['bg_color'])) {
575
                $this->properties['bg_color'] = $this->parse_color('black');
576
            }
577
        } else {
578
            unset($this->properties['bg_color']);
579
        }
580
 
581
    }
582
 
583
    /**
584
     * Set text wrap of the format
585
     */
586
    public function set_text_wrap() {
587
        $this->properties['wrap'] = true;
588
    }
589
 
590
    /**
591
     * Set the cell alignment of the format.
592
     *
593
     * @param string $location alignment for the cell ('left', 'right', 'justify', etc...)
594
     */
595
    public function set_align($location) {
596
        if (in_array($location, array('left', 'centre', 'center', 'right', 'fill', 'merge', 'justify', 'equal_space'))) {
597
            $this->set_h_align($location);
598
 
599
        } else if (in_array($location, array('top', 'vcentre', 'vcenter', 'bottom', 'vjustify', 'vequal_space'))) {
600
            $this->set_v_align($location);
601
        }
602
    }
603
 
604
    /**
605
     * Set the cell horizontal alignment of the format.
606
     *
607
     * @param string $location alignment for the cell ('left', 'right', 'justify', etc...)
608
     */
609
    public function set_h_align($location) {
610
        switch ($location) {
611
            case 'left':
612
                $this->properties['align'] = 'start';
613
                break;
614
            case 'center':
615
            case 'centre':
616
            $this->properties['align'] = 'center';
617
                break;
618
            case 'right':
619
                $this->properties['align'] = 'end';
620
                break;
621
        }
622
    }
623
 
624
    /**
625
     * Set the cell vertical alignment of the format.
626
     *
627
     * @param string $location alignment for the cell ('top', 'bottom', 'center', 'justify')
628
     */
629
    public function set_v_align($location) {
630
        switch ($location) {
631
            case 'top':
632
                $this->properties['v_align'] = 'top';
633
                break;
634
            case 'vcentre':
635
            case 'vcenter':
636
            case 'centre':
637
            case 'center':
638
                $this->properties['v_align'] = 'middle';
639
                break;
640
            default:
641
                $this->properties['v_align'] = 'bottom';
642
        }
643
    }
644
 
645
    /**
646
     * Set the top border of the format.
647
     *
648
     * @param integer $style style for the cell. 1 => thin, 2 => thick
649
     */
650
    public function set_top($style) {
651
        if ($style == 1) {
652
            $style = 0.2;
653
        } else if ($style == 2) {
654
            $style = 0.5;
655
        } else {
656
            return;
657
        }
658
        $this->properties['border_top'] = $style;
659
    }
660
 
661
    /**
662
     * Set the bottom border of the format.
663
     *
664
     * @param integer $style style for the cell. 1 => thin, 2 => thick
665
     */
666
    public function set_bottom($style) {
667
        if ($style == 1) {
668
            $style = 0.2;
669
        } else if ($style == 2) {
670
            $style = 0.5;
671
        } else {
672
            return;
673
        }
674
        $this->properties['border_bottom'] = $style;
675
    }
676
 
677
    /**
678
     * Set the left border of the format.
679
     *
680
     * @param integer $style style for the cell. 1 => thin, 2 => thick
681
     */
682
    public function set_left($style) {
683
        if ($style == 1) {
684
            $style = 0.2;
685
        } else if ($style == 2) {
686
            $style = 0.5;
687
        } else {
688
            return;
689
        }
690
        $this->properties['border_left'] = $style;
691
    }
692
 
693
    /**
694
     * Set the right border of the format.
695
     *
696
     * @param integer $style style for the cell. 1 => thin, 2 => thick
697
     */
698
    public function set_right($style) {
699
        if ($style == 1) {
700
            $style = 0.2;
701
        } else if ($style == 2) {
702
            $style = 0.5;
703
        } else {
704
            return;
705
        }
706
        $this->properties['border_right'] = $style;
707
    }
708
 
709
    /**
710
     * Set cells borders to the same style
711
     * @param integer $style style to apply for all cell borders. 1 => thin, 2 => thick.
712
     */
713
    public function set_border($style) {
714
        $this->set_top($style);
715
        $this->set_bottom($style);
716
        $this->set_left($style);
717
        $this->set_right($style);
718
    }
719
 
720
    /**
721
     * Set the numerical format of the format.
722
     * It can be date, time, currency, etc...
723
     *
724
     * @param mixed $num_format The numeric format
725
     */
726
    public function set_num_format($num_format) {
727
 
728
        $numbers = array();
729
 
730
        $numbers[1] = '0';
731
        $numbers[2] = '0.00';
732
        $numbers[3] = '#,##0';
733
        $numbers[4] = '#,##0.00';
734
        $numbers[11] = '0.00E+00';
735
        $numbers[12] = '# ?/?';
736
        $numbers[13] = '# ??/??';
737
        $numbers[14] = 'mm-dd-yy';
738
        $numbers[15] = 'd-mmm-yy';
739
        $numbers[16] = 'd-mmm';
740
        $numbers[17] = 'mmm-yy';
741
        $numbers[22] = 'm/d/yy h:mm';
742
        $numbers[49] = '@';
743
 
744
        if ($num_format !== 0 and in_array($num_format, $numbers)) {
745
            $flipped = array_flip($numbers);
746
            $this->properties['num_format'] = $flipped[$num_format];
747
        }
748
        if (!isset($numbers[$num_format])) {
749
            return;
750
        }
751
 
752
        $this->properties['num_format'] = $num_format;
753
    }
754
 
755
    /**
756
     * Standardise colour name.
757
     *
758
     * @param mixed $color name of the color (i.e.: 'blue', 'red', etc..), or an integer (range is [8...63]).
759
     * @return string the RGB color value
760
     */
761
    protected function parse_color($color) {
762
        if (strpos($color, '#') === 0) {
763
            // No conversion should be needed.
764
            return $color;
765
        }
766
 
767
        if ($color > 7 and $color < 53) {
768
            $numbers = array(
769
                8  => 'black',
770
                12 => 'blue',
771
                16 => 'brown',
772
                15 => 'cyan',
773
                23 => 'gray',
774
                17 => 'green',
775
                11 => 'lime',
776
                14 => 'magenta',
777
                18 => 'navy',
778
                53 => 'orange',
779
                33 => 'pink',
780
                20 => 'purple',
781
                10 => 'red',
782
                22 => 'silver',
783
                9  => 'white',
784
                13 => 'yellow',
785
            );
786
            if (isset($numbers[$color])) {
787
                $color = $numbers[$color];
788
            } else {
789
                $color = 'black';
790
            }
791
        }
792
 
793
        $colors = array(
794
            'aqua'    => '00FFFF',
795
            'black'   => '000000',
796
            'blue'    => '0000FF',
797
            'brown'   => 'A52A2A',
798
            'cyan'    => '00FFFF',
799
            'fuchsia' => 'FF00FF',
800
            'gray'    => '808080',
801
            'grey'    => '808080',
802
            'green'   => '00FF00',
803
            'lime'    => '00FF00',
804
            'magenta' => 'FF00FF',
805
            'maroon'  => '800000',
806
            'navy'    => '000080',
807
            'orange'  => 'FFA500',
808
            'olive'   => '808000',
809
            'pink'    => 'FAAFBE',
810
            'purple'  => '800080',
811
            'red'     => 'FF0000',
812
            'silver'  => 'C0C0C0',
813
            'teal'    => '008080',
814
            'white'   => 'FFFFFF',
815
            'yellow'  => 'FFFF00',
816
        );
817
 
818
        if (isset($colors[$color])) {
819
            return('#'.$colors[$color]);
820
        }
821
 
822
        return('#'.$colors['black']);
823
    }
824
}
825
 
826
 
827
/**
828
 * ODS file writer.
829
 *
830
 * @package   core
831
 * @copyright 2013 Petr Skoda {@link http://skodak.org}
832
 * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
833
 */
834
class MoodleODSWriter {
835
    protected $worksheets;
836
 
837
    public function __construct(array $worksheets) {
838
        $this->worksheets = $worksheets;
839
    }
840
 
841
    /**
842
     * Fetch the file ocntnet for the ODS.
843
     *
844
     * @return string
845
     */
846
    public function get_file_content() {
847
        $dir = make_request_directory();
848
        $filename = $dir . '/result.ods';
849
 
850
        $files = [
851
                'mimetype'              => [$this->get_ods_mimetype()],
852
                'content.xml'           => [$this->get_ods_content($this->worksheets)],
853
                'meta.xml'              => [$this->get_ods_meta()],
854
                'styles.xml'            => [$this->get_ods_styles()],
855
                'settings.xml'          => [$this->get_ods_settings()],
856
                'META-INF/manifest.xml' => [$this->get_ods_manifest()],
857
            ];
858
 
859
        $packer = get_file_packer('application/zip');
860
        $packer->archive_to_pathname($files, $filename);
861
 
862
        $contents = file_get_contents($filename);
863
 
864
        remove_dir($dir);
865
        return $contents;
866
    }
867
 
868
    protected function get_ods_content() {
869
 
870
        // Find out the size of worksheets and used styles.
871
        $formats = array();
872
        $formatstyles = '';
873
        $rowstyles = '';
874
        $colstyles = '';
875
 
876
        foreach($this->worksheets as $wsnum=>$ws) {
877
            foreach($ws->data as $rnum=>$row) {
878
                if ($rnum > $this->worksheets[$wsnum]->maxr) {
879
                    $this->worksheets[$wsnum]->maxr = $rnum;
880
                }
881
                foreach($row as $cnum=>$cell) {
882
                    if ($cnum > $this->worksheets[$wsnum]->maxc) {
883
                        $this->worksheets[$wsnum]->maxc = $cnum;
884
                    }
885
                    if (!empty($cell->format)) {
886
                        if (!array_key_exists($cell->format->id, $formats)) {
887
                            $formats[$cell->format->id] = $cell->format;
888
                        }
889
                    }
890
                }
891
            }
892
 
893
            foreach($ws->rows as $rnum=>$row) {
894
                if (!empty($row->format)) {
895
                    if (!array_key_exists($row->format->id, $formats)) {
896
                        $formats[$row->format->id] = $row->format;
897
                    }
898
                }
899
                if ($rnum > $this->worksheets[$wsnum]->maxr) {
900
                    $this->worksheets[$wsnum]->maxr = $rnum;
901
                }
902
                // Define all column styles.
903
                if (!empty($ws->rows[$rnum])) {
904
                    $rowstyles .= '<style:style style:name="ws'.$wsnum.'ro'.$rnum.'" style:family="table-row">';
905
                    if (isset($row->height)) {
906
                        $rowstyles .= '<style:table-row-properties style:row-height="'.$row->height.'pt"/>';
907
                    }
908
                    $rowstyles .= '</style:style>';
909
                }
910
            }
911
 
912
            foreach($ws->columns as $cnum=>$col) {
913
                if (!empty($col->format)) {
914
                    if (!array_key_exists($col->format->id, $formats)) {
915
                        $formats[$col->format->id] = $col->format;
916
                    }
917
                }
918
                if ($cnum > $this->worksheets[$wsnum]->maxc) {
919
                    $this->worksheets[$wsnum]->maxc = $cnum;
920
                }
921
                // Define all column styles.
922
                if (!empty($ws->columns[$cnum])) {
923
                    $colstyles .= '<style:style style:name="ws'.$wsnum.'co'.$cnum.'" style:family="table-column">';
924
                    if (isset($col->width)) {
925
                        $colstyles .= '<style:table-column-properties style:column-width="'.$col->width.'pt"/>';
926
                    }
927
                    $colstyles .= '</style:style>';
928
                }
929
            }
930
        }
931
 
932
        foreach($formats as $format) {
933
            $textprop = '';
934
            $cellprop = '';
935
            $parprop  = '';
936
            $dataformat = '';
937
            foreach($format->properties as $pname=>$pvalue) {
938
                switch ($pname) {
939
                    case 'size':
940
                        if (!empty($pvalue)) {
941
                            $textprop .= ' fo:font-size="'.$pvalue.'pt"';
942
                        }
943
                        break;
944
                    case 'bold':
945
                        if (!empty($pvalue)) {
946
                            $textprop .= ' fo:font-weight="bold"';
947
                        }
948
                        break;
949
                    case 'italic':
950
                        if (!empty($pvalue)) {
951
                            $textprop .= ' fo:font-style="italic"';
952
                        }
953
                        break;
954
                    case 'underline':
955
                        if (!empty($pvalue)) {
956
                            $textprop .= ' style:text-underline-color="font-color" style:text-underline-style="solid" style:text-underline-width="auto"';
957
                            if ($pvalue == 2) {
958
                                $textprop .= ' style:text-underline-type="double"';
959
                            }
960
                        }
961
                        break;
962
                    case 'strikeout':
963
                        if (!empty($pvalue)) {
964
                            $textprop .= ' style:text-line-through-style="solid"';
965
                        }
966
                        break;
967
                    case 'color':
968
                        if ($pvalue !== false) {
969
                            $textprop .= ' fo:color="'.$pvalue.'"';
970
                        }
971
                        break;
972
                    case 'bg_color':
973
                        if ($pvalue !== false) {
974
                            $cellprop .= ' fo:background-color="'.$pvalue.'"';
975
                        }
976
                        break;
977
                    case 'align':
978
                        $parprop .= ' fo:text-align="'.$pvalue.'"';
979
                        break;
980
                    case 'v_align':
981
                        $cellprop .= ' style:vertical-align="'.$pvalue.'"';
982
                        break;
983
                    case 'wrap':
984
                        if ($pvalue) {
985
                            $cellprop .= ' fo:wrap-option="wrap"';
986
                        }
987
                        break;
988
                    case 'border_top':
989
                        $cellprop .= ' fo:border-top="'.$pvalue.'pt solid #000000"';
990
                        break;
991
                    case 'border_left':
992
                        $cellprop .= ' fo:border-left="'.$pvalue.'pt solid #000000"';
993
                        break;
994
                    case 'border_bottom':
995
                        $cellprop .= ' fo:border-bottom="'.$pvalue.'pt solid #000000"';
996
                        break;
997
                    case 'border_right':
998
                        $cellprop .= ' fo:border-right="'.$pvalue.'pt solid #000000"';
999
                        break;
1000
                    case 'num_format':
1001
                        $dataformat = ' style:data-style-name="NUM'.$pvalue.'"';
1002
                        break;
1003
                }
1004
            }
1005
            if (!empty($textprop)) {
1006
                $textprop = '
1007
   <style:text-properties'.$textprop.'/>';
1008
            }
1009
 
1010
            if (!empty($cellprop)) {
1011
                $cellprop = '
1012
   <style:table-cell-properties'.$cellprop.'/>';
1013
            }
1014
 
1015
            if (!empty($parprop)) {
1016
                $parprop = '
1017
   <style:paragraph-properties'.$parprop.'/>';
1018
            }
1019
 
1020
            $formatstyles .= '
1021
  <style:style style:name="format'.$format->id.'" style:family="table-cell"'.$dataformat.'>'.$textprop.$cellprop.$parprop.'
1022
  </style:style>';
1023
        }
1024
 
1025
        // The text styles may be breaking older ODF validators.
1026
        $scriptstyles ='
1027
  <style:style style:name="T1" style:family="text">
1028
    <style:text-properties style:text-position="33% 58%"/>
1029
  </style:style>
1030
  <style:style style:name="T2" style:family="text">
1031
    <style:text-properties style:text-position="-33% 58%"/>
1032
  </style:style>
1033
';
1034
        // Header.
1035
        $buffer =
1036
'<?xml version="1.0" encoding="UTF-8"?>
1037
<office:document-content xmlns:office="urn:oasis:names:tc:opendocument:xmlns:office:1.0"
1038
                         xmlns:style="urn:oasis:names:tc:opendocument:xmlns:style:1.0"
1039
                         xmlns:text="urn:oasis:names:tc:opendocument:xmlns:text:1.0"
1040
                         xmlns:table="urn:oasis:names:tc:opendocument:xmlns:table:1.0"
1041
                         xmlns:draw="urn:oasis:names:tc:opendocument:xmlns:drawing:1.0"
1042
                         xmlns:fo="urn:oasis:names:tc:opendocument:xmlns:xsl-fo-compatible:1.0"
1043
                         xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:dc="http://purl.org/dc/elements/1.1/"
1044
                         xmlns:meta="urn:oasis:names:tc:opendocument:xmlns:meta:1.0"
1045
                         xmlns:number="urn:oasis:names:tc:opendocument:xmlns:datastyle:1.0"
1046
                         xmlns:presentation="urn:oasis:names:tc:opendocument:xmlns:presentation:1.0"
1047
                         xmlns:svg="urn:oasis:names:tc:opendocument:xmlns:svg-compatible:1.0"
1048
                         xmlns:chart="urn:oasis:names:tc:opendocument:xmlns:chart:1.0"
1049
                         xmlns:dr3d="urn:oasis:names:tc:opendocument:xmlns:dr3d:1.0"
1050
                         xmlns:math="http://www.w3.org/1998/Math/MathML"
1051
                         xmlns:form="urn:oasis:names:tc:opendocument:xmlns:form:1.0"
1052
                         xmlns:script="urn:oasis:names:tc:opendocument:xmlns:script:1.0"
1053
                         xmlns:ooo="http://openoffice.org/2004/office" xmlns:ooow="http://openoffice.org/2004/writer"
1054
                         xmlns:oooc="http://openoffice.org/2004/calc" xmlns:dom="http://www.w3.org/2001/xml-events"
1055
                         xmlns:xforms="http://www.w3.org/2002/xforms" xmlns:xsd="http://www.w3.org/2001/XMLSchema"
1056
                         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
1057
                         xmlns:rpt="http://openoffice.org/2005/report"
1058
                         xmlns:of="urn:oasis:names:tc:opendocument:xmlns:of:1.2"
1059
                         xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:grddl="http://www.w3.org/2003/g/data-view#"
1060
                         xmlns:tableooo="http://openoffice.org/2009/table"
1061
                         xmlns:calcext="urn:org:documentfoundation:names:experimental:calc:xmlns:calcext:1.0"
1062
                         xmlns:field="urn:openoffice:names:experimental:ooo-ms-interop:xmlns:field:1.0"
1063
                         xmlns:formx="urn:openoffice:names:experimental:ooxml-odf-interop:xmlns:form:1.0"
1064
                         xmlns:css3t="http://www.w3.org/TR/css3-text/" office:version="1.2">
1065
  <office:scripts/>
1066
  <office:font-face-decls>
1067
    <style:font-face style:name="Arial" svg:font-family="Arial" style:font-family-generic="swiss"
1068
                     style:font-pitch="variable"/>
1069
    <style:font-face style:name="Arial Unicode MS" svg:font-family="&apos;Arial Unicode MS&apos;"
1070
                     style:font-family-generic="system" style:font-pitch="variable"/>
1071
    <style:font-face style:name="Tahoma" svg:font-family="Tahoma" style:font-family-generic="system"
1072
                     style:font-pitch="variable"/>
1073
  </office:font-face-decls>
1074
  <office:automatic-styles>';
1075
        $buffer .= $this->get_num_styles();
1076
        $buffer .= '
1077
    <style:style style:name="ta1" style:family="table" style:master-page-name="Standard1">
1078
      <style:table-properties table:display="true"/>
1079
    </style:style>';
1080
 
1081
        $buffer .= $formatstyles;
1082
        $buffer .= $rowstyles;
1083
        $buffer .= $colstyles;
1084
        $buffer .= $scriptstyles;
1085
 
1086
         $buffer .= '
1087
  </office:automatic-styles>
1088
  <office:body>
1089
    <office:spreadsheet>
1090
';
1091
 
1092
        foreach($this->worksheets as $wsnum=>$ws) {
1093
 
1094
            // Worksheet header.
1095
            $buffer .= '<table:table table:name="' . htmlspecialchars($ws->name, ENT_QUOTES, 'utf-8') . '" table:style-name="ta1">'."\n";
1096
 
1097
            // Define column properties.
1098
            $level = 0;
1099
            for($c=0; $c<=$ws->maxc; $c++) {
1100
                if (array_key_exists($c, $ws->columns)) {
1101
                    $column = $ws->columns[$c];
1102
                    if ($column->level > $level) {
1103
                        while ($column->level > $level) {
1104
                            $buffer .= '<table:table-column-group>';
1105
                            $level++;
1106
                        }
1107
                    } else if ($column->level < $level) {
1108
                        while ($column->level < $level) {
1109
                            $buffer .= '</table:table-column-group>';
1110
                            $level--;
1111
                        }
1112
                    }
1113
                    $extra = '';
1114
                    if (!empty($column->format)) {
1115
                        $extra .= ' table:default-cell-style-name="format'.$column->format->id.'"';
1116
                    }
1117
                    if ($column->hidden) {
1118
                        $extra .= ' table:visibility="collapse"';
1119
                    }
1120
                    $buffer .= '<table:table-column table:style-name="ws'.$wsnum.'co'.$c.'"'.$extra.'/>'."\n";
1121
                } else {
1122
                    while ($level > 0) {
1123
                        $buffer .= '</table:table-column-group>';
1124
                        $level--;
1125
                    }
1126
                    $buffer .= '<table:table-column/>'."\n";
1127
                }
1128
            }
1129
            while ($level > 0) {
1130
                $buffer .= '</table:table-column-group>';
1131
                $level--;
1132
            }
1133
 
1134
            // Print all rows.
1135
            $level = 0;
1136
            for($r=0; $r<=$ws->maxr; $r++) {
1137
                if (array_key_exists($r, $ws->rows)) {
1138
                    $row = $ws->rows[$r];
1139
                    if ($row->level > $level) {
1140
                        while ($row->level > $level) {
1141
                            $buffer .= '<table:table-row-group>';
1142
                            $level++;
1143
                        }
1144
                    } else if ($row->level < $level) {
1145
                        while ($row->level < $level) {
1146
                            $buffer .= '</table:table-row-group>';
1147
                            $level--;
1148
                        }
1149
                    }
1150
                    $extra = '';
1151
                    if (!empty($row->format)) {
1152
                        $extra .= ' table:default-cell-style-name="format'.$row->format->id.'"';
1153
                    }
1154
                    if ($row->hidden) {
1155
                        $extra .= ' table:visibility="collapse"';
1156
                    }
1157
                    $buffer .= '<table:table-row table:style-name="ws'.$wsnum.'ro'.$r.'"'.$extra.'>'."\n";
1158
                } else {
1159
                    while ($level > 0) {
1160
                        $buffer .= '</table:table-row-group>';
1161
                        $level--;
1162
                    }
1163
                    $buffer .= '<table:table-row>'."\n";
1164
                }
1165
                for($c=0; $c<=$ws->maxc; $c++) {
1166
                    if (isset($ws->data[$r][$c])) {
1167
                        $cell = $ws->data[$r][$c];
1168
                        $extra = '';
1169
                        if (!empty($cell->format)) {
1170
                            $extra .= ' table:style-name="format'.$cell->format->id.'"';
1171
                        }
1172
                        if (!empty($cell->merge)) {
1173
                            $extra .= ' table:number-columns-spanned="'.$cell->merge['columns'].'" table:number-rows-spanned="'.$cell->merge['rows'].'"';
1174
                        }
1175
                        $pretext = '<text:p>';
1176
                        $posttext = '</text:p>';
1177
                        if (!empty($cell->format->properties['sub_script'])) {
1178
                            $pretext = $pretext.'<text:span text:style-name="T2">';
1179
                            $posttext = '</text:span>'.$posttext;
1180
                        } else if (!empty($cell->format->properties['super_script'])) {
1181
                            $pretext = $pretext.'<text:span text:style-name="T1">';
1182
                            $posttext = '</text:span>'.$posttext;
1183
                        }
1184
 
1185
                        if (isset($cell->formula)) {
1186
                            $buffer .= '<table:table-cell table:formula="of:'.$cell->formula.'"'.$extra.'></table:table-cell>'."\n";
1187
                        } else if ($cell->type == 'date') {
1188
                            $buffer .= '<table:table-cell office:value-type="date" office:date-value="' . date("Y-m-d\\TH:i:s", $cell->value) . '"'.$extra.'>'
1189
                                     . $pretext . date("Y-m-d\\TH:i:s", $cell->value) . $posttext
1190
                                     . '</table:table-cell>'."\n";
1191
                        } else if ($cell->type == 'float') {
1192
                            $buffer .= '<table:table-cell office:value-type="float" office:value="' . htmlspecialchars($cell->value, ENT_QUOTES, 'utf-8') . '"'.$extra.'>'
1193
                                     . $pretext . htmlspecialchars($cell->value, ENT_QUOTES, 'utf-8') . $posttext
1194
                                     . '</table:table-cell>'."\n";
1195
                        } else if ($cell->type == 'string') {
1196
                            $buffer .= '<table:table-cell office:value-type="string"'.$extra.'>'
1197
                                     . $pretext . htmlspecialchars($cell->value, ENT_QUOTES, 'utf-8') . $posttext
1198
                                     . '</table:table-cell>'."\n";
1199
                        } else {
1200
                            $buffer .= '<table:table-cell office:value-type="string"'.$extra.'>'
1201
                                     . $pretext . '!!Error - unknown type!!' . $posttext
1202
                                     . '</table:table-cell>'."\n";
1203
                        }
1204
                    } else {
1205
                        $buffer .= '<table:table-cell/>'."\n";
1206
                    }
1207
                }
1208
                $buffer .= '</table:table-row>'."\n";
1209
            }
1210
            while ($level > 0) {
1211
                $buffer .= '</table:table-row-group>';
1212
                $level--;
1213
            }
1214
            $buffer .= '</table:table>'."\n";
1215
 
1216
        }
1217
 
1218
        // Footer.
1219
        $buffer .= '
1220
    </office:spreadsheet>
1221
  </office:body>
1222
</office:document-content>';
1223
 
1224
        return $buffer;
1225
    }
1226
 
1227
    public function get_ods_mimetype() {
1228
        return 'application/vnd.oasis.opendocument.spreadsheet';
1229
    }
1230
 
1231
    protected function get_ods_settings() {
1232
        $buffer =
1233
'<?xml version="1.0" encoding="UTF-8"?>
1234
<office:document-settings xmlns:office="urn:oasis:names:tc:opendocument:xmlns:office:1.0"
1235
                          xmlns:xlink="http://www.w3.org/1999/xlink"
1236
                          xmlns:config="urn:oasis:names:tc:opendocument:xmlns:config:1.0"
1237
                          xmlns:ooo="http://openoffice.org/2004/office" office:version="1.2">
1238
    <office:settings>
1239
      <config:config-item-set config:name="ooo:view-settings">
1240
        <config:config-item config:name="VisibleAreaTop" config:type="int">0</config:config-item>
1241
        <config:config-item config:name="VisibleAreaLeft" config:type="int">0</config:config-item>
1242
        <config:config-item-map-indexed config:name="Views">
1243
          <config:config-item-map-entry>
1244
            <config:config-item config:name="ViewId" config:type="string">view1</config:config-item>
1245
            <config:config-item-map-named config:name="Tables">
1246
';
1247
        foreach ($this->worksheets as $ws) {
1248
            $buffer .= '               <config:config-item-map-entry config:name="'.htmlspecialchars($ws->name, ENT_QUOTES, 'utf-8').'">'."\n";
1249
            $buffer .= '                 <config:config-item config:name="ShowGrid" config:type="boolean">'.($ws->showgrid ? 'true' : 'false').'</config:config-item>'."\n";
1250
            $buffer .= '               </config:config-item-map-entry>."\n"';
1251
        }
1252
            $buffer .=
1253
'           </config:config-item-map-named>
1254
          </config:config-item-map-entry>
1255
        </config:config-item-map-indexed>
1256
      </config:config-item-set>
1257
      <config:config-item-set config:name="ooo:configuration-settings">
1258
        <config:config-item config:name="ShowGrid" config:type="boolean">true</config:config-item>
1259
      </config:config-item-set>
1260
    </office:settings>
1261
</office:document-settings>';
1262
 
1263
        return $buffer;
1264
    }
1265
    protected function get_ods_meta() {
1266
        global $CFG, $USER;
1267
 
1268
        return
1269
'<?xml version="1.0" encoding="UTF-8"?>
1270
<office:document-meta xmlns:office="urn:oasis:names:tc:opendocument:xmlns:office:1.0"
1271
                      xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:dc="http://purl.org/dc/elements/1.1/"
1272
                      xmlns:meta="urn:oasis:names:tc:opendocument:xmlns:meta:1.0"
1273
                      xmlns:ooo="http://openoffice.org/2004/office" xmlns:grddl="http://www.w3.org/2003/g/data-view#"
1274
                      office:version="1.2">
1275
    <office:meta>
1276
        <meta:generator>Moodle '.$CFG->release.'</meta:generator>
1277
        <meta:initial-creator>' . htmlspecialchars(fullname($USER, true), ENT_QUOTES, 'utf-8') . '</meta:initial-creator>
1278
        <meta:creation-date>'.date("Y-m-d\\TH:i:s").'</meta:creation-date>
1279
        <meta:document-statistic meta:table-count="1" meta:cell-count="0" meta:object-count="0"/>
1280
    </office:meta>
1281
</office:document-meta>';
1282
    }
1283
 
1284
    protected function get_ods_styles() {
1285
        return
1286
'<?xml version="1.0" encoding="UTF-8"?>
1287
<office:document-styles xmlns:office="urn:oasis:names:tc:opendocument:xmlns:office:1.0"
1288
                        xmlns:style="urn:oasis:names:tc:opendocument:xmlns:style:1.0"
1289
                        xmlns:text="urn:oasis:names:tc:opendocument:xmlns:text:1.0"
1290
                        xmlns:table="urn:oasis:names:tc:opendocument:xmlns:table:1.0"
1291
                        xmlns:draw="urn:oasis:names:tc:opendocument:xmlns:drawing:1.0"
1292
                        xmlns:fo="urn:oasis:names:tc:opendocument:xmlns:xsl-fo-compatible:1.0"
1293
                        xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:dc="http://purl.org/dc/elements/1.1/"
1294
                        xmlns:meta="urn:oasis:names:tc:opendocument:xmlns:meta:1.0"
1295
                        xmlns:number="urn:oasis:names:tc:opendocument:xmlns:datastyle:1.0"
1296
                        xmlns:presentation="urn:oasis:names:tc:opendocument:xmlns:presentation:1.0"
1297
                        xmlns:svg="urn:oasis:names:tc:opendocument:xmlns:svg-compatible:1.0"
1298
                        xmlns:chart="urn:oasis:names:tc:opendocument:xmlns:chart:1.0"
1299
                        xmlns:dr3d="urn:oasis:names:tc:opendocument:xmlns:dr3d:1.0"
1300
                        xmlns:math="http://www.w3.org/1998/Math/MathML"
1301
                        xmlns:form="urn:oasis:names:tc:opendocument:xmlns:form:1.0"
1302
                        xmlns:script="urn:oasis:names:tc:opendocument:xmlns:script:1.0"
1303
                        xmlns:ooo="http://openoffice.org/2004/office" xmlns:ooow="http://openoffice.org/2004/writer"
1304
                        xmlns:oooc="http://openoffice.org/2004/calc" xmlns:dom="http://www.w3.org/2001/xml-events"
1305
                        xmlns:rpt="http://openoffice.org/2005/report"
1306
                        xmlns:of="urn:oasis:names:tc:opendocument:xmlns:of:1.2"
1307
                        xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:grddl="http://www.w3.org/2003/g/data-view#"
1308
                        xmlns:tableooo="http://openoffice.org/2009/table"
1309
                        xmlns:calcext="urn:org:documentfoundation:names:experimental:calc:xmlns:calcext:1.0"
1310
                        xmlns:css3t="http://www.w3.org/TR/css3-text/" office:version="1.2">
1311
    <office:font-face-decls>
1312
        <style:font-face style:name="Arial" svg:font-family="Arial" style:font-family-generic="swiss"
1313
                         style:font-pitch="variable"/>
1314
        <style:font-face style:name="Arial Unicode MS" svg:font-family="&apos;Arial Unicode MS&apos;"
1315
                         style:font-family-generic="system" style:font-pitch="variable"/>
1316
        <style:font-face style:name="Tahoma" svg:font-family="Tahoma" style:font-family-generic="system"
1317
                         style:font-pitch="variable"/>
1318
    </office:font-face-decls>
1319
    <office:styles>
1320
        <style:default-style style:family="table-cell">
1321
            <style:paragraph-properties style:tab-stop-distance="1.25cm"/>
1322
        </style:default-style>
1323
        <number:number-style style:name="N0">
1324
            <number:number number:min-integer-digits="1"/>
1325
        </number:number-style>
1326
        <style:style style:name="Default" style:family="table-cell">
1327
            <style:text-properties style:font-name-asian="Arial Unicode MS" style:font-name-complex="Arial Unicode MS"/>
1328
        </style:style>
1329
        <style:style style:name="Result" style:family="table-cell" style:parent-style-name="Default">
1330
            <style:text-properties fo:font-style="italic" style:text-underline-style="solid"
1331
                                   style:text-underline-width="auto" style:text-underline-color="font-color"
1332
                                   fo:font-weight="bold"/>
1333
        </style:style>
1334
        <style:style style:name="Result2" style:family="table-cell" style:parent-style-name="Result"
1335
                     style:data-style-name="N104"/>
1336
        <style:style style:name="Heading" style:family="table-cell" style:parent-style-name="Default">
1337
            <style:table-cell-properties style:text-align-source="fix" style:repeat-content="false"/>
1338
            <style:paragraph-properties fo:text-align="center"/>
1339
            <style:text-properties fo:font-size="16pt" fo:font-style="italic" fo:font-weight="bold"/>
1340
        </style:style>
1341
        <style:style style:name="Heading1" style:family="table-cell" style:parent-style-name="Heading">
1342
            <style:table-cell-properties style:rotation-angle="90"/>
1343
        </style:style>
1344
    </office:styles>
1345
    <office:automatic-styles>
1346
        <style:page-layout style:name="Mpm1">
1347
            <style:page-layout-properties style:writing-mode="lr-tb"/>
1348
            <style:header-style>
1349
                <style:header-footer-properties fo:min-height="0.75cm" fo:margin-left="0cm" fo:margin-right="0cm"
1350
                                                fo:margin-bottom="0.25cm"/>
1351
            </style:header-style>
1352
            <style:footer-style>
1353
                <style:header-footer-properties fo:min-height="0.75cm" fo:margin-left="0cm" fo:margin-right="0cm"
1354
                                                fo:margin-top="0.25cm"/>
1355
            </style:footer-style>
1356
        </style:page-layout>
1357
        <style:page-layout style:name="Mpm2">
1358
            <style:page-layout-properties style:writing-mode="lr-tb"/>
1359
            <style:header-style>
1360
                <style:header-footer-properties fo:min-height="0.75cm" fo:margin-left="0cm" fo:margin-right="0cm"
1361
                                                fo:margin-bottom="0.25cm" fo:border="2.49pt solid #000000"
1362
                                                fo:padding="0.018cm" fo:background-color="#c0c0c0">
1363
                    <style:background-image/>
1364
                </style:header-footer-properties>
1365
            </style:header-style>
1366
            <style:footer-style>
1367
                <style:header-footer-properties fo:min-height="0.75cm" fo:margin-left="0cm" fo:margin-right="0cm"
1368
                                                fo:margin-top="0.25cm" fo:border="2.49pt solid #000000"
1369
                                                fo:padding="0.018cm" fo:background-color="#c0c0c0">
1370
                    <style:background-image/>
1371
                </style:header-footer-properties>
1372
            </style:footer-style>
1373
        </style:page-layout>
1374
    </office:automatic-styles>
1375
    <office:master-styles>
1376
        <style:master-page style:name="Default" style:page-layout-name="Mpm1">
1377
            <style:header>
1378
                <text:p>
1379
                    <text:sheet-name>???</text:sheet-name>
1380
                </text:p>
1381
            </style:header>
1382
            <style:header-left style:display="false"/>
1383
            <style:footer>
1384
                <text:p>Page
1385
                    <text:page-number>1</text:page-number>
1386
                </text:p>
1387
            </style:footer>
1388
            <style:footer-left style:display="false"/>
1389
        </style:master-page>
1390
        <style:master-page style:name="Report" style:page-layout-name="Mpm2">
1391
            <style:header>
1392
                <style:region-left>
1393
                    <text:p>
1394
                        <text:sheet-name>???</text:sheet-name>
1395
                        (<text:title>???</text:title>)
1396
                    </text:p>
1397
                </style:region-left>
1398
                <style:region-right>
1399
                    <text:p><text:date style:data-style-name="N2" text:date-value="2013-01-05">00.00.0000</text:date>,
1400
                        <text:time>00:00:00</text:time>
1401
                    </text:p>
1402
                </style:region-right>
1403
            </style:header>
1404
            <style:header-left style:display="false"/>
1405
            <style:footer>
1406
                <text:p>Page
1407
                    <text:page-number>1</text:page-number>
1408
                    /
1409
                    <text:page-count>99</text:page-count>
1410
                </text:p>
1411
            </style:footer>
1412
            <style:footer-left style:display="false"/>
1413
        </style:master-page>
1414
    </office:master-styles>
1415
</office:document-styles>';
1416
    }
1417
 
1418
    protected function get_ods_manifest() {
1419
        return
1420
'<?xml version="1.0" encoding="UTF-8"?>
1421
<manifest:manifest xmlns:manifest="urn:oasis:names:tc:opendocument:xmlns:manifest:1.0" manifest:version="1.2">
1422
 <manifest:file-entry manifest:full-path="/" manifest:version="1.2" manifest:media-type="application/vnd.oasis.opendocument.spreadsheet"/>
1423
 <manifest:file-entry manifest:full-path="meta.xml" manifest:media-type="text/xml"/>
1424
 <manifest:file-entry manifest:full-path="content.xml" manifest:media-type="text/xml"/>
1425
 <manifest:file-entry manifest:full-path="styles.xml" manifest:media-type="text/xml"/>
1426
 <manifest:file-entry manifest:full-path="settings.xml" manifest:media-type="text/xml"/>
1427
</manifest:manifest>';
1428
    }
1429
 
1430
    protected function get_num_styles() {
1431
        return '
1432
        <number:number-style style:name="NUM1">
1433
            <number:number number:decimal-places="0" number:min-integer-digits="1"/>
1434
        </number:number-style>
1435
        <number:number-style style:name="NUM2">
1436
            <number:number number:decimal-places="2" number:min-integer-digits="1"/>
1437
        </number:number-style>
1438
        <number:number-style style:name="NUM3">
1439
            <number:number number:decimal-places="0" number:min-integer-digits="1" number:grouping="true"/>
1440
        </number:number-style>
1441
        <number:number-style style:name="NUM4">
1442
            <number:number number:decimal-places="2" number:min-integer-digits="1" number:grouping="true"/>
1443
        </number:number-style>
1444
        <number:number-style style:name="NUM11">
1445
            <number:scientific-number number:decimal-places="2" number:min-integer-digits="1"
1446
                                      number:min-exponent-digits="2"/>
1447
        </number:number-style>
1448
        <number:number-style style:name="NUM12">
1449
            <number:fraction number:min-integer-digits="0" number:min-numerator-digits="1"
1450
                             number:min-denominator-digits="1"/>
1451
        </number:number-style>
1452
        <number:number-style style:name="NUM13">
1453
            <number:fraction number:min-integer-digits="0" number:min-numerator-digits="2"
1454
                             number:min-denominator-digits="2"/>
1455
        </number:number-style>
1456
        <number:date-style style:name="NUM14" number:automatic-order="true">
1457
            <number:month number:style="long"/>
1458
            <number:text>/</number:text>
1459
            <number:day number:style="long"/>
1460
            <number:text>/</number:text>
1461
            <number:year/>
1462
        </number:date-style>
1463
        <number:date-style style:name="NUM15">
1464
            <number:day/>
1465
            <number:text>.</number:text>
1466
            <number:month number:textual="true"/>
1467
            <number:text>.</number:text>
1468
            <number:year number:style="long"/>
1469
        </number:date-style>
1470
        <number:date-style style:name="NUM16" number:automatic-order="true">
1471
            <number:month number:textual="true"/>
1472
            <number:text></number:text>
1473
            <number:day number:style="long"/>
1474
        </number:date-style>
1475
        <number:date-style style:name="NUM17">
1476
            <number:month number:style="long"/>
1477
            <number:text>-</number:text>
1478
            <number:day number:style="long"/>
1479
        </number:date-style>
1480
        <number:date-style style:name="NUM22" number:automatic-order="true"
1481
                           number:format-source="language">
1482
            <number:month/>
1483
            <number:text>/</number:text>
1484
            <number:day/>
1485
            <number:text>/</number:text>
1486
            <number:year/>
1487
            <number:text></number:text>
1488
            <number:hours number:style="long"/>
1489
            <number:text>:</number:text>
1490
            <number:minutes number:style="long"/>
1491
            <number:text></number:text>
1492
            <number:am-pm/>
1493
        </number:date-style>
1494
        <number:text-style style:name="NUM49">
1495
            <number:text-content/>
1496
        </number:text-style>
1497
';
1498
    }
1499
}