Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <style>
- .add {
- float: right;
- }
- .joblist {
- float: right;
- }
- .inputas {
- float: left;
- width: 50px;
- }
- .checkbox {
- margin: 15px;
- }
- </style>
- <?php
- /**
- * Created by PhpStorm.
- * User: Dev minion
- * Date: 5/9/2017
- * Time: 7:10 PM
- */
- // Creating the widget
- //-----------------------------------------------------
- /*
- $servername = "localhost";
- $username = "username";
- $password = "password";
- $dbname = "myDB";
- // Create connection
- $conn = new mysqli($servername, $username, $password, $dbname);
- // Check connection
- if ($conn->connect_error) {
- die("Connection failed: " . $conn->connect_error);
- }
- $sql = "INSERT INTO MyGuests (firstname, lastname, email)
- VALUES ('John', 'Doe', 'john@example.com')";
- if ($conn->query($sql) === TRUE) {
- echo "New record created successfully";
- } else {
- echo "Error: " . $sql . "<br>" . $conn->error;
- }
- $conn->close();
- */
- //-----------------------------------------------------------
- class vaidas_todo_widget extends WP_Widget
- {
- function __construct()
- {
- parent::__construct(
- 'vaidas_todo',
- __('To-do-listas', 'wpb_widget_domain'),
- array('description' => __('Mano darbu listai', 'wpb_widget_domain'),)
- );
- }
- public function widget($args, $instance)
- {
- $title = apply_filters('widget_title', $instance['title']);
- // if (!empty($title))
- ///
- global $wpdb;
- $results = $wpdb->get_results('SELECT * FROM `mytable`', ARRAY_A);
- ?>
- <div class="mainWidget">
- <div id="widget">
- <h1><?php echo $title ; ?></h1>
- <form id="todoInsert" action="/action_page.php">
- <div>Add new item</div>
- <div>
- <input class="inputas" type="text" name="toDoItem" size="30" value="Bla bla bla"><br>
- <input class="add" type="submit" value="Add">
- </div>
- </form>
- <?php
- foreach ($results as $item):
- ?>
- <div>
- <input class="checkbox" type="checkbox"
- name="done" <?php if ($item['Done'] == 1) echo 'checked'; ?>/>
- <label class="joblist">
- <?php
- echo $item['Name'];
- ?>
- </label>
- </div>
- <?php endforeach; ?>
- </form>
- </div>
- </div>
- <?php
- //echo __('Hello, World!', 'wpb_widget_domain');
- }
- // Widget Backend
- public function form($instance)
- {
- if (isset($instance['title'])) {
- $title = $instance['title'];
- } else {
- $title = __('New title', 'wpb_widget_domain');
- }
- // Widget admin form
- ?>
- <p>
- <label for="<?php echo $this->get_field_id('title'); ?>"><?php _e('Title:'); ?></label>
- <input class="widefat" id="<?php echo $this->get_field_id('title'); ?>"
- name="<?php echo $this->get_field_name('title'); ?>" type="text"
- value="<?php echo esc_attr($title); ?>"/>
- </p>
- <?php
- }
- // Updating widget replacing old instances with new
- public function update($new_instance, $old_instance)
- {
- $instance = array();
- $instance['title'] = (!empty($new_instance['title'])) ? strip_tags($new_instance['title']) : '';
- return $instance;
- }
- } // Class wpb_widget ends here
- // Register and load the widget
- function vaidas_todo_load_widget()
- {
- register_widget('vaidas_todo_widget');
- }
- add_action('widgets_init', 'vaidas_todo_load_widget');
- /** Step 2 (from text above). */
- add_action('admin_menu', 'my_plugin_menu');
- /** Step 1. */
- function my_plugin_menu()
- {
- add_options_page('My Plugin Options', 'My Plugin', 'manage_options', 'my-unique-identifier', 'my_plugin_options');
- }
- function validate() {
- $a=$_POST['toDoItemm'];
- }
- /** Step 3. */
- function my_plugin_options()
- {
- if (!current_user_can('manage_options')) {
- wp_die(__('You do not have sufficient permissions to access this page.'));
- }
- echo '<div class="wrap">';
- echo '<p>Here is where the form would go if I actually had options.</p>';
- echo '<h1><a>to-do admin panel</a></h1>';
- if (isset($_POST['toDoItemm'])){
- echo $_POST['toDoItemm'];
- }
- echo '<form method="POST" onsubmit="return validate()" action="">';
- echo '<div>';
- echo '<input class="input" type="text" name="toDoItemm" value="To-do panel title"/><br>';
- echo '<input class="save" type="submit" value="Save">';
- echo '</div>';
- echo '</form>';
- echo '<form>';
- echo '<div>';
- global $wpdb;
- $results = $wpdb->get_results('SELECT * FROM `mytable`', ARRAY_A);
- foreach ($results as $item):
- echo '<input class="delete" type="submit" value="Delete">';
- if ($item['Done'] == 1) $checkedtekstas = 'checked="checked"'; else $checkedtekstas = '';
- echo '<input class="checkbox" type="checkbox" name="Done"' . $checkedtekstas . '/><br>';
- echo '<label class="joblist">';
- echo $item['Name'];
- echo '</label>';
- endforeach;
- echo '</div>';
- echo '</form>';
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement