コード例 #1
0
ファイル: grid.php プロジェクト: linuxwhy/tiki-1
 /** drawRows
  * Draws out a defined set of rows from the sheet.
  * @param $sheet The data container.
  * @param $begin The index of the begining row. (included)
  * @param $end The index of the end row (excluded)
  */
 function drawRows(TikiSheet &$sheet)
 {
     $sheetlib = TikiLib::lib('sheet');
     $beginRow = $sheet->getRangeBeginRow();
     $endRow = $sheet->getRangeEndRow();
     $beginCol = $sheet->getRangeBeginCol();
     $endCol = $sheet->getRangeEndCol();
     for ($i = $beginRow; $i < $endRow; $i++) {
         $td = "";
         $trStyleHeight = "";
         $trHeight = "20px";
         $trHeightIsSet = false;
         for ($j = $beginCol; $j < $endCol; $j++) {
             $width = $height = '';
             if (!empty($sheet->cellInfo[$i][$j])) {
                 extract($sheet->cellInfo[$i][$j]);
             }
             $append = '';
             if ($width > 1) {
                 $append .= " colspan='{$width}'";
             }
             if ($height > 1) {
                 $append .= " rowspan='{$height}'";
             }
             if (!empty($sheet->calcGrid[$i][$j])) {
                 $append .= ' data-formula="=' . str_replace('"', "'", $sheet->calcGrid[$i][$j]['calculation']) . '"';
             }
             if (isset($sheet->dataGrid[$i][$j]['value'])) {
                 $data = $sheet->dataGrid[$i][$j]['value'];
             } else {
                 $data = '';
             }
             $format = $sheet->cellInfo[$i][$j]['format'];
             if (!empty($format)) {
                 $data = TikiSheetDataFormat::$format($data);
             }
             $style = $sheet->cellInfo[$i][$j]['style'];
             if (!empty($style)) {
                 //we have to sanitize the css style here
                 $tdStyle = "";
                 $color = $sheetlib->get_attr_from_css_string($style, "color", "");
                 $bgColor = $sheetlib->get_attr_from_css_string($style, "background-color", "");
                 $tdHeight = '';
                 if ($trHeightIsSet == false) {
                     $trHeight = $sheetlib->get_attr_from_css_string($style, "height", "20px");
                     $trHeightIsSet = true;
                 }
                 if ($color) {
                     $tdStyle .= "color:{$color};";
                 }
                 if ($bgColor) {
                     $tdStyle .= "background-color:{$bgColor};";
                 }
                 $tdHeight = $trHeight;
                 if ($tdHeight) {
                     $tdStyle .= "height:{$tdHeight};";
                     $append .= " height='" . str_replace("px", "", $tdHeight) . "'";
                 }
                 $append .= " style='{$tdStyle}'";
             }
             $class = $sheet->cellInfo[$i][$j]['class'];
             if (!empty($class)) {
                 $append .= ' class="' . $class . '"';
             }
             if ($this->parseOutput && $sheet->parseValues == 'y') {
                 global $tikilib;
                 // only parse if we have non-alphanumeric or space chars
                 if (mb_ereg_match('[^A-Za-z0-9\\s]', $data)) {
                     // needs to be multibyte regex here
                     $data = $tikilib->parse_data($data, array('suppress_icons' => true));
                 }
                 if (strpos($data, '<p>') === 0) {
                     // remove containing <p> tag
                     $data = substr($data, 3);
                     if (strrpos($data, '</p>') === strlen($data) - 4) {
                         $data = substr($data, 0, -4);
                     }
                 }
             }
             $td .= "\t\t\t<td" . $append . ">{$data}</td>\n";
         }
         if (!empty($td)) {
             $this->output .= "\t\t<tr style='height: {$trHeight};' height='" . str_replace("px", "", $trHeight) . "'>\n";
             $this->output .= $td;
             $this->output .= "\t\t</tr>\n";
         }
     }
 }