$conn = mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME); if (mysqli_connect_errno()) { die('Connection Error: ' . mysqli_connect_error()); } $options = get_option('db-query-queries'); /* most queries are saved with escaping quotes */ $query = stripslashes($options[$_GET['id']]['query']); $result = @mysqli_query($conn, $query); if (!$result) { die('Couldn\'t execute query. ' . mysqli_error($conn)); } while ($column = mysqli_fetch_field($result)) { $columns[] = $column->name; } /* get this user's role permissions */ $role_can = DB_Viewer_Editor::get_role_permissions($_GET['id']); for ($i = 0; $i < count($columns); $i++) { $editor_option = $i == 0 || !$role_can->edit ? "" : "editor: {type: 'text'}"; $column_model[] = "{field: '" . $columns[$i] . "', title: '" . $columns[$i] . "', width: 60, sortable: true, " . $editor_option . "}"; } if ($role_can->edit) { $remove_link = $role_can->remove ? "'<a class=\"icon-remove\" style=\"text-decoration: none; padding: 0px 5px;\" href=\"#\" onclick=\"deleterow( this )\"> </a>';" : "'';"; /* build datagrid columns */ $action_column = array("{field: 'action', title: 'Action', width: 60, align: 'center',", "formatter: function( value, row, index ) {", "if ( row.editing ) {", "var s = '<a class=\"icon-save\" style=\"text-decoration: none; padding: 0px 5px;\" href=\"#\" onclick=\"saverow( this )\"> </a> ';", "var c = '<a class=\"icon-cancel\" style=\"text-decoration: none; padding: 0px 5px;\" href=\"#\" onclick=\"cancelrow( this )\"> </a>';", "return s+c;", "}", "else {", "var e = '<a class=\"icon-edit\" style=\"text-decoration: none; padding: 0px 5px;\" href=\"#\" onclick=\"editrow( this )\"> </a> ';", "var d = {$remove_link}", "return e + d;", "}", "}", "}"); $column_model[] = implode('', $action_column); } ?> <link rel="stylesheet" href="css/icon.css" type="text/css" media="all" /> <link rel="stylesheet" href="css/easyui.css" type="text/css" media="all" /> <script type="text/javascript" src="js/jquery.min.js"></script> <script type="text/javascript" src="js/jquery.easyui.min.js"></script>
/** * output shortcode inside the posts */ public function shortcode($atts) { extract(shortcode_atts(array('id' => '0'), $atts)); /* we need to return our data instead of printing, or it would show always before any content */ ob_start(); /* get this user's role permissions */ $role_can = DB_Viewer_Editor::get_role_permissions($atts['id']); //if ( $role_can->view ): ?> <script type="text/javascript"> /* this piece is needed to make the iframe the same size of the datagrid inside shortcode-html.php */ function resizeIframe( obj ) { obj.style.height = obj.contentWindow.document.body.scrollHeight + 'px'; } </script> <iframe src="<?php echo $this->plugin_url; ?> /shortcode-html.php?id=<?php echo $atts['id']; ?> &can_edit=<?php echo $role_can->edit; ?> &can_remove=<?php echo $role_can->remove; ?> " width="100%" scrolling="no" onload="javascript:resizeIframe( this );"></iframe> <?php //else: ?> <!--<img src="<?php echo $this->plugin_url . '/access-denied.jpg'; ?> " title="You're not authorized to view this page!" />--> <?php //endif; return ob_get_clean(); }