function get_max_custom_rows() { return {$maxlayoutrows}; } addLoadEvent(function () { formchangemanager.add("viewlayout"); }); JAVASCRIPT; $elements = array('viewid' => array('type' => 'hidden', 'value' => $view->get('id'))); $elements['customlayoutnumrows'] = array('type' => 'hidden', 'value' => 1); $elements['layoutselect'] = array('type' => 'hidden', 'value' => $currentlayout, 'sesskey' => $USER->get('sesskey')); $elements['layoutfallback'] = array('type' => 'hidden', 'value' => $defaultlayout->id); $elements['submit'] = array('type' => 'submit', 'class' => 'btn-primary', 'value' => get_string('save')); $templatedata = array('id' => $id, 'basiclayoutoptions' => $basiclayoutoptions, 'layoutoptions' => $layoutoptions, 'currentlayout' => $currentlayout, 'clnumcolumnsoptions' => $clnumcolumnsoptions, 'clnumcolumnsdefault' => $clnumcolumnsdefault, 'columnlayoutoptions' => $columnlayoutoptions, 'customlayoutid' => $defaultlayout->id, 'customlayout' => $defaultlayoutpreview->create_preview(), 'clwidths' => $clwidths, 'maxrows' => $maxrows); $layoutform = array('name' => 'viewlayout', 'template' => 'viewlayout.php', 'templatedir' => pieform_template_dir('viewlayout.php'), 'autofocus' => false, 'templatedata' => $templatedata, 'elements' => $elements); $layoutform = pieform($layoutform); $javascript = array('jquery', 'js/jquery/jquery-ui/js/jquery-ui.min.js', 'js/customlayout.js', 'js/jquery/modernizr.custom.js'); $stylesheets[] = '<link rel="stylesheet" type="text/css" href="' . append_version_number(get_config('wwwroot') . 'js/jquery/jquery-ui/css/smoothness/jquery-ui.min.css') . '">'; $smarty = smarty($javascript, $stylesheets, array('view' => array('Row', 'removethisrow', 'rownr', 'nrrows')), array('sidebars' => false)); $smarty->assign('INLINEJAVASCRIPT', $inlinejavascript); $smarty->assign('form', $layoutform); $smarty->assign('viewid', $view->get('id')); $smarty->assign('viewtype', $view->get('type')); $smarty->assign('viewtitle', $view->get('title')); $smarty->assign('edittitle', $view->can_edit_title()); $smarty->assign('displaylink', $view->get_url()); $smarty->assign('new', $new); $smarty->assign('issiteview', $view->get('institution') == 'mahara'); if ($view->get('owner') == "0") {
public function addcustomlayout($values) { require_once get_config('libroot') . 'layoutpreviewimage.php'; $require = array('numrows'); foreach ($require as $require) { if (!array_key_exists($require, $values) || empty($values[$require])) { throw new ParamOutOfRangeException(get_string('missingparam' . $require, 'error')); } } $numrows = $values['numrows']; $alttext = ''; $rowscolssql = ''; $rowscols = array(); for ($i = 0; $i < $numrows; $i++) { if (array_key_exists('row' . ($i + 1), $values)) { $rowscolssql .= '(row = ' . ($i + 1) . ' AND columns = ' . $values['row' . ($i + 1)] . ')'; if ($i != $numrows - 1) { $rowscolssql .= ' OR '; } $widths = get_field('view_layout_columns', 'widths', 'id', $values['row' . ($i + 1)]); $hyphenatedwidths = str_replace(',', '-', $widths); $alttext .= $hyphenatedwidths; if ($i != $numrows - 1) { $alttext .= ' / '; } $rowscols[$i + 1] = $values['row' . ($i + 1)]; } } $owner = $this->owner; $group = $this->group; $institution = $this->institution; if (!empty($group)) { $owner = null; $andclause = 'AND ucl.group = ?'; $andclausevalue = $group; } else { if (!empty($institution)) { $owner = null; $andclause = 'AND ucl.institution = ?'; $andclausevalue = $institution; } else { if (isset($owner)) { $andclause = 'AND ucl.usr = ?'; $andclausevalue = $owner; } else { // no group or owner or institution set // site pages should have institution set throw new SystemException("View::addcustomlayout: No owner, group or institution set for view."); } } } // check for existing layout $sql = 'SELECT vlrc.viewlayout AS id FROM {view_layout} vl INNER JOIN {view_layout_rows_columns} vlrc ON vl.id = vlrc.viewlayout INNER JOIN ( SELECT viewlayout, COUNT(*) FROM {view_layout_rows_columns} GROUP BY viewlayout HAVING COUNT(*) = ? ) vlrc2 ON vlrc.viewlayout = vlrc2.viewlayout INNER JOIN {usr_custom_layout} ucl ON ucl.layout = vl.id WHERE (' . $rowscolssql . ') AND ( vl.iscustom = 0 OR ( vl.iscustom = 1 ' . $andclause . ' ) ) GROUP BY vlrc.viewlayout HAVING count(*) = ? LIMIT 1'; $layoutids = get_records_sql_array($sql, array($numrows, $andclausevalue, $numrows)); if ($layoutids) { $data = array('layoutid' => $layoutids[0]->id, 'newlayout' => 0); return $data; } else { db_begin(); // no existing layout of this kind, create it $newlayoutid = insert_record('view_layout', (object) array('rows' => $numrows, 'iscustom' => 1), 'id', true); if (!$newlayoutid) { db_rollback(); throw new SystemException("View::addcustomlayout: Couldn't create new layout record."); } if (isset($owner)) { $newcustomlayout = insert_record('usr_custom_layout', (object) array('usr' => $owner, 'group' => null, 'institution' => null, 'layout' => $newlayoutid)); } else { if (isset($group)) { $newcustomlayout = insert_record('usr_custom_layout', (object) array('usr' => null, 'group' => $group, 'institution' => null, 'layout' => $newlayoutid)); } else { if (isset($institution)) { $newcustomlayout = insert_record('usr_custom_layout', (object) array('usr' => null, 'group' => null, 'institution' => $institution, 'layout' => $newlayoutid)); } } } if (!$newcustomlayout) { db_rollback(); throw new SystemException("View::addcustomlayout: Couldn't create new usr custom layout record."); } for ($i = 0; $i < $numrows; $i++) { if (array_key_exists($i + 1, $rowscols)) { $widths = get_field('view_layout_columns', 'widths', 'id', $rowscols[$i + 1]); $structure['layout']['row' . ($i + 1)] = $widths; $newrec = insert_record('view_layout_rows_columns', (object) array('viewlayout' => $newlayoutid, 'row' => $i + 1, 'columns' => $rowscols[$i + 1])); if (!$newrec) { db_rollback(); throw new SystemException("View::addcustomlayout: Couldn't create new vlrc record."); } } } db_commit(); // Generate new custom layout preview. $structure['text'] = $alttext; $layoutpreview = new LayoutPreviewImage($structure); $preview = $layoutpreview->create_preview(); $data = array('layoutid' => $newlayoutid, 'newlayout' => 1, 'layoutpreview' => $preview, 'text' => $structure['text']); return $data; } }
public function updatecustomlayoutpreview($values) { global $THEME; require_once get_config('libroot') . 'layoutpreviewimage.php'; $require = array('numrows'); foreach ($require as $require) { if (!array_key_exists($require, $values) || empty($values[$require])) { throw new ParamOutOfRangeException(get_string('missingparam' . $require, 'error')); } } $numrows = $values['numrows']; $collayouts = array(); for ($i = 0; $i < $numrows; $i++) { if (array_key_exists('row' . ($i + 1), $values)) { $collayouts['row' . ($i + 1)] = $values['row' . ($i + 1)]; } } $previewimage = 'vl-'; $alttext = ''; $customlayout = array(); for ($i = 0; $i < $numrows; $i++) { $id = $collayouts['row' . ($i + 1)]; $widths = get_field('view_layout_columns', 'widths', 'id', $id); $hyphenatedwidths = str_replace(',', '-', $widths); $customlayout[$i + 1] = $hyphenatedwidths; $previewimage .= $hyphenatedwidths; $alttext .= $hyphenatedwidths; if ($i != $numrows - 1) { $previewimage .= '_'; $alttext .= ' / '; } } if (LayoutPreviewImage::preview_exists($previewimage)) { $img = get_config('wwwroot') . 'thumb.php?type=customviewlayout&cvl=' . $previewimage; $data = array('data' => $img, 'alttext' => $alttext, 'newimage' => 0); return $data; } else { // generate thumbnail images with GD $data = array(); $data['layout'] = $customlayout; $data['description'] = 'test'; $data['owner'] = 1; $previewlayoutimage = new LayoutPreviewImage($data); $newpreviewimage = $previewlayoutimage->create_preview(); if ($newpreviewimage) { $img = get_config('wwwroot') . 'thumb.php?type=customviewlayout&cvl=' . $previewimage; $data = array('data' => $img, 'alttext' => $alttext, 'newimage' => 1); return $data; } else { $msg = '<p>' . get_string('previewimagegenerationfailed', 'error') . '</p>'; $data = array('data' => $msg, 'alttext' => $alttext, 'newimage' => 0); return $data; } } }