Beispiel #1
0
 function join_with_sub_grids($id, $date)
 {
     global $prefs, $sheetlib;
     $result1 = "";
     $result2 = "";
     $handler = new TikiSheetDatabaseHandler($id, $date);
     $handler->setReadDate($date);
     $grid = new TikiSheet();
     $grid->import($handler);
     $childSheetIds = $sheetlib->get_related_sheet_ids($grid->id);
     $i = 0;
     $grids = array($grid);
     foreach ($childSheetIds as $childSheetId) {
         $handler = new TikiSheetDatabaseHandler($childSheetId, $date);
         $handler->setReadDate($date);
         $childSheet = new TikiSheet();
         $childSheet->import($handler);
         array_push($grids, $childSheet);
         $i++;
     }
     return $grids;
 }
Beispiel #2
0
    $fileInfo = $filegallib->get_file_info($_REQUEST['fileId']);
    $handler = new TikiSheetCSVHandler($fileInfo);
    $grid = new TikiSheet();
    $grid->import($handler);
    $tableHtml[0] = $grid->getTableHtml();
    $smarty->assign('notEditable', 'true');
    if ($handler->truncated) {
        $smarty->assign('msg', tra('Spreadsheet truncated'));
    }
} else {
    //Database sheet
    $handler = new TikiSheetDatabaseHandler($_REQUEST['sheetId']);
    //We make sheet able to look at other date save
    if (isset($_REQUEST['readdate']) && !empty($_REQUEST['readdate'])) {
        $smarty->assign('read_date', $_REQUEST['readdate']);
        $handler->setReadDate($_REQUEST['readdate']);
    }
    $grid = new TikiSheet();
    $grid->import($handler);
    //ensure that sheet isn't being edited, then parse values if needed
    if ($_REQUEST['parse'] != 'edit') {
        $grid->parseValues = true;
    } else {
        $grid->parseValues = false;
    }
    $smarty->assign('parseValues', $grid->parseValues);
    $tableHtml[0] = $grid->getTableHtml(true, $_REQUEST['readdate']);
    if (strlen($relatedTrackersAsHtml) > 0) {
        $tableHtml[0] = $tableHtml[0] . $relatedTrackersAsHtml;
    }
}
Beispiel #3
0
 function diff_sheets_as_html($id, $dates = null)
 {
     global $prefs;
     $count_longest = function ($array1, $array2) {
         return max(count($array1), count($array2));
     };
     $join_with_sub_grids = function ($id, $date) {
         global $prefs;
         $handler = new TikiSheetDatabaseHandler($id, $date);
         $handler->setReadDate($date);
         $grid = new TikiSheet();
         $grid->import($handler);
         $childSheetIds = $this->get_related_sheet_ids($grid->id);
         $i = 0;
         $grids = array($grid);
         foreach ($childSheetIds as $childSheetId) {
             $handler = new TikiSheetDatabaseHandler($childSheetId, $date);
             $handler->setReadDate($date);
             $childSheet = new TikiSheet();
             $childSheet->import($handler);
             array_push($grids, $childSheet);
             $i++;
         }
         return $grids;
     };
     $sanitize_for_diff = function ($val) {
         $val = str_replace("<br/>", "<br>", $val);
         $val = str_replace("<br />", "<br>", $val);
         $val = str_replace("<br  />", "<br>", $val);
         $val = str_replace("<BR/>", "<br>", $val);
         $val = str_replace("<BR />", "<br>", $val);
         $val = str_replace("<BR  />", "<br>", $val);
         return explode("<br>", $val);
     };
     $diff_to_html = function ($changes) use($count_longest) {
         $result = array("", "");
         for ($i = 0; $i < $count_longest($changes->orig, $changes->final); $i++) {
             $class = array("", "");
             $char = array("", "");
             $vals = array(trim($changes->orig[$i]), trim($changes->final[$i]));
             if ($vals[0] && $vals[1]) {
                 if ($vals[0] != $vals[1]) {
                     $class[1] .= "diffadded";
                 }
             } else {
                 if ($vals[0]) {
                     $class[0] .= "diffadded";
                     $class[1] .= "diffdeleted";
                     $vals[1] = $vals[0];
                     $char[1] = "-";
                 } else {
                     if ($vals[1]) {
                         $class[0] .= "diffdeleted";
                         $class[1] .= "diffadded";
                         $char[1] = "+";
                     }
                 }
             }
             if ($vals[0]) {
                 $result[0] .= "<td class='{$class['0']}'>" . $char[0] . $vals[0] . "</td>";
             }
             if ($vals[1]) {
                 $result[1] .= "<td class='{$class['1']}'>" . $char[1] . $vals[1] . "</td>";
             }
         }
         return $result;
     };
     $grids1 = $join_with_sub_grids($id, $dates[0]);
     $grids2 = $join_with_sub_grids($id, $dates[1]);
     $result1 = '';
     $result2 = '';
     for ($i = 0; $i < $count_longest($grids1, $grids2); $i++) {
         //cycle through the sheets within a spreadsheet
         $result1 .= "<table title='" . $grids1[$i]->name() . "'>";
         $result2 .= "<table title='" . $grids2[$i]->name() . "'>";
         for ($row = 0; $row < $count_longest($grids1[$i]->dataGrid, $grids2[$i]->dataGrid); $row++) {
             //cycle through rows
             $result1 .= "<tr>";
             $result2 .= "<tr>";
             for ($col = 0; $col < $count_longest($grids1[$i]->dataGrid[$row], $grids2[$i]->dataGrid[$row]); $col++) {
                 //cycle through columns
                 $diff = new Text_Diff($sanitize_for_diff(html_entity_decode($grids1[$i]->dataGrid[$row][$col])), $sanitize_for_diff(html_entity_decode($grids2[$i]->dataGrid[$row][$col])));
                 $changes = $diff->getDiff();
                 //I left this diff switch, but it really isn't being used as of now, in the future we may though.
                 switch (get_class($changes[0])) {
                     case 'Text_Diff_Op_copy':
                         $values = $diff_to_html($changes[0]);
                         break;
                     case 'Text_Diff_Op_change':
                         $values = $diff_to_html($changes[0]);
                         break;
                     case 'Text_Diff_Op_delete':
                         $values = $diff_to_html($changes[0]);
                         break;
                     case 'Text_Diff_Op_add':
                         $values = $diff_to_html($changes[0]);
                         break;
                     default:
                         $values = $diff_to_html($changes[0]);
                 }
                 $result1 .= empty($values[0]) ? '<td></td>' : $values[0];
                 $result2 .= empty($values[1]) ? '<td></td>' : $values[1];
             }
             $result1 .= "</tr>";
             $result2 .= "</tr>";
         }
         $result1 .= "</table>";
         $result2 .= "</table>";
     }
     return array($result1, $result2);
 }