tra('Sheet'), 'documentation' => 'PluginSheet', 'description' => tra('Display data from a TikiSheet'), 'prefs' => [ 'wikiplugin_sheet', 'feature_sheet' ], 'body' => tra('Spreadsheet Heading'), 'iconname' => 'table', 'introduced' => 1, 'tags' => [ 'basic' ], 'params' => [ 'id' => [ 'required' => false, 'name' => tra('Spreadsheet ID'), 'description' => tr('Internal ID of the TikiSheet. Either %0id%1 or %0url%1 is required.', '', ''), 'filter' => 'digits', 'accepted' => 'Spreadsheet ID number', 'default' => '', 'since' => '1', 'profile_reference' => 'sheet', ], 'url' => [ 'required' => false, 'name' => tra('Sheet Url Location'), 'description' => tr('Internal URL of the Table to use as a spreadsheet. Either %0id%1 or %0url%1 is required.', '', ''), 'filter' => 'url', 'default' => '', 'since' => '6.0' ], 'simple' => [ 'required' => false, 'name' => tra('Simple'), 'description' => tr( 'Show a simple table view (Default: %0 = jquery.sheet view if feature enabled).', 'n' ), 'filter' => 'alpha', 'default' => 'n', 'since' => '5.0', 'options' => [ ['text' => '', 'value' => ''], ['text' => tra('Yes'), 'value' => 'y'], ['text' => tra('No'), 'value' => 'n'] ] ], 'width' => [ 'required' => false, 'name' => tra('Width'), 'description' => tr('Width in pixels or percentage. Default value is page width, for example, %0200px%1 or %0100%%1', '', ''), 'filter' => 'text', 'accepted' => 'Number of pixels followed by \'px\' or percent followed by %).', 'default' => 'Page width', 'since' => '6.0' ], 'height' => [ 'required' => false, 'name' => tra('Height'), 'description' => tra('Height in pixels or percentage. Default value is complete spreadsheet height.'), 'filter' => 'text', 'accepted' => 'Number of pixels followed by \'px\' or percent followed by %).', 'default' => 'Spreadsheet height', 'since' => '5.0' ], 'editable' => [ 'required' => false, 'name' => tra('Editable'), 'description' => tra('Show edit button. Default is to show depending on user\'s permissions.'), 'filter' => 'alpha', 'accepted' => 'y or n', 'default' => 'y', 'since' => '6.0', 'options' => [ ['text' => '', 'value' => ''], ['text' => tra('Yes'), 'value' => 'y'], ['text' => tra('No'), 'value' => 'n'] ] ], 'subsheets' => [ 'required' => false, 'name' => tra('Show subsheets'), 'description' => tra('Show multi-sheets (default is to show)'), 'filter' => 'alpha', 'accepted' => 'y or n', 'default' => 'y', 'since' => '6.0', 'options' => [ ['text' => '', 'value' => ''], ['text' => tra('Yes'), 'value' => 'y'], ['text' => tra('No'), 'value' => 'n'] ] ], 'range' => [ 'required' => false, 'name' => tra('Range'), 'description' => tr('Show a range of cells (or single cell). Default shows all. e.g. %0D1:F3%1 or %0e14:e14%1', '', ''), 'filter' => 'text', 'accepted' => 'Cell range, e.g. "D1:F3" or "e14:e14"', 'default' => 'All cells', 'since' => '6.0', ], 'class' => [ 'required' => false, 'name' => tra('CSS Class'), 'description' => tra('Apply custom CSS class to the containing div.'), 'filter' => 'text', 'accepted' => 'Any valid CSS class', 'default' => '', 'since' => '6.0', ], ], ]; } function wikiplugin_sheet($data, $params) { global $tiki_p_edit_sheet, $tiki_p_edit, $tiki_p_admin_sheet, $tiki_p_admin, $prefs, $user, $page; extract($params, EXTR_SKIP); $style = (isset($height)) ? "height: $height !important;" : ''; $style .= (isset($width)) ? "width: $width;" : ''; // $urlHeight = (isset($height)) ? "&height=$height" : ''; // $urlHeight .= (isset($width)) ? "&width=$width" : ''; $urlHeight = (isset($height)) ? "&height=100" : ''; // not setting any height or width in the sheet params created for me the literal '...&height=100%&...' or '...&width=100%&...' in the url with a 400 error (bad request). Hardcoding to 100 (instead of 100%) to avoid this error until a better fix is found $urlHeight .= (isset($width)) ? "&width=100" : ''; // not setting any height or width in the sheet params created for me the literal '...&height=100%&...' or '...&width=100%&...' in the url with a 400 error (bad request). Hardcoding to 100 (instead of 100%) to avoid this error until a better fix is found $editable = isset($editable) && $editable == 'n' ? false : true; $subsheets = isset($subsheets) && $subsheets == 'n' ? false : true; $class = (isset($class)) ? " $class" : ''; $sheetlib = TikiLib::lib("sheet"); $tikilib = TikiLib::lib('tiki'); $smarty = TikiLib::lib('smarty'); static $index = 0; ++$index; if (empty($id) && empty($url)) { if ($tiki_p_edit_sheet != 'y' || $tiki_p_edit != 'y') { return ("missing id parameter for plugin
"); } else { if (isset($_POST['create_sheet'], $_POST['index']) && $index == $_POST['index']) { // Create a new sheet and rewrite page $sheetId = $sheetlib->replace_sheet(null, tra('New sheet in page: ') . $page, '', $user); $page = htmlentities($page); $content = htmlentities($data); $formId = "form$index"; $smarty->loadPlugin('smarty_function_ticket'); $ticket = smarty_function_ticket([], $smarty->getEmptyInternalTemplate()); return <<
$ticket
~/np~ EOF; } else { $label = tra('Create New Sheet'); return <<

~/np~ EOF; } } } $sheet = new TikiSheet(); if (empty($url)) { $info; if (! empty($id)) { $info = $sheetlib->get_sheet_info($id); } if (empty($info)) { return tra("Error loading spreadsheet"); } $objectperms = Perms::get('sheet', $id); if (! $objectperms->view_sheet && ! ($user && $info['author'] == $user)) { return (tra('Permission denied')); } // Build required objects $db = new TikiSheetDatabaseHandler($id); //$out = new TikiSheetOutputHandler($data); // Fetch sheet from database $sheet->import($db); } else { if (! isset($simple)) { $simple = 'y'; } } $calcOff = ''; if (! empty($range)) { $sheet->setRange($range); $calcOff = ',calcOff: true'; } // Grab sheet output if (isset($url)) { $file = file_get_contents($url); $pathInfo = pathinfo($url); if ($pathInfo['extension'] == 'csv') { $handler = new TikiSheetCSVHandler($url); $grid = new TikiSheet(); $grid->import($handler); $ret = $grid->getTableHtml(true, null, false); } else { $sheet->parseValues = true; $ret = file_get_contents($url); } } else { $ret = ($sheet->getTableHtml($subsheets)); } if (strpos($ret, 'setup_jquery_sheet(); $headerlib->add_jq_onready( '$("div#tiki_sheet' . $index . '").each(function() { $(this).sheet($.extend($.sheet.tikiOptions,{ editable:false' . $calcOff . '})); $(\'.icon-pdf\').parent().click(function(){storeSortTable("#tiki_sheet' . $index . '",$("#tiki_sheet' . $index . '").html())}); });' ); } $ret = '
' . $ret . '
'; if ($editable && ($objectperms->edit_sheet || $objectperms->admin_sheet || $tiki_p_admin == 'y')) { $smarty->loadPlugin('smarty_function_button'); //If you've given the sheet a url, you can't edit it, disable if not possible if (! isset($url)) { $button_params = ['_text' => tra("Edit Sheet"), '_script' => "tiki-view_sheets.php?sheetId=$id&parse=edit$urlHeight&page=$page", '_class' => "tiki_sheeteditbtn"]; } $ret .= smarty_function_button($button_params, $smarty->getEmptyInternalTemplate()); } return '~np~' . $ret . '~/np~'; }