Advertisement
Guest User

Untitled

a guest
May 11th, 2017
546
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.51 KB | None | 0 0
  1. <style>
  2. .add {
  3. float: right;
  4. }
  5.  
  6. .joblist {
  7. float: right;
  8.  
  9. }
  10.  
  11. .inputas {
  12. float: left;
  13. width: 50px;
  14. }
  15.  
  16. .checkbox {
  17. margin: 15px;
  18. }
  19.  
  20. </style>
  21. <?php
  22. /**
  23. * Created by PhpStorm.
  24. * User: Dev minion
  25. * Date: 5/9/2017
  26. * Time: 7:10 PM
  27. */
  28. // Creating the widget
  29.  
  30. //-----------------------------------------------------
  31. /*
  32. $servername = "localhost";
  33. $username = "username";
  34. $password = "password";
  35. $dbname = "myDB";
  36.  
  37. // Create connection
  38. $conn = new mysqli($servername, $username, $password, $dbname);
  39. // Check connection
  40. if ($conn->connect_error) {
  41. die("Connection failed: " . $conn->connect_error);
  42. }
  43.  
  44. $sql = "INSERT INTO MyGuests (firstname, lastname, email)
  45. VALUES ('John', 'Doe', 'john@example.com')";
  46.  
  47. if ($conn->query($sql) === TRUE) {
  48. echo "New record created successfully";
  49. } else {
  50. echo "Error: " . $sql . "<br>" . $conn->error;
  51. }
  52.  
  53. $conn->close();
  54. */
  55.  
  56. //-----------------------------------------------------------
  57.  
  58. class vaidas_todo_widget extends WP_Widget
  59. {
  60.  
  61. function __construct()
  62. {
  63. parent::__construct(
  64. 'vaidas_todo',
  65. __('To-do-listas', 'wpb_widget_domain'),
  66. array('description' => __('Mano darbu listai', 'wpb_widget_domain'),)
  67. );
  68. }
  69.  
  70.  
  71. public function widget($args, $instance)
  72. {
  73. $title = apply_filters('widget_title', $instance['title']);
  74.  
  75. // if (!empty($title))
  76. ///
  77. global $wpdb;
  78. $results = $wpdb->get_results('SELECT * FROM `mytable`', ARRAY_A);
  79.  
  80.  
  81. ?>
  82.  
  83.  
  84. <div class="mainWidget">
  85. <div id="widget">
  86. <h1><?php echo $title ; ?></h1>
  87. <form id="todoInsert" action="/action_page.php">
  88. <div>Add new item</div>
  89. <div>
  90. <input class="inputas" type="text" name="toDoItem" size="30" value="Bla bla bla"><br>
  91. <input class="add" type="submit" value="Add">
  92. </div>
  93. </form>
  94.  
  95.  
  96. <?php
  97.  
  98. foreach ($results as $item):
  99.  
  100. ?>
  101. <div>
  102. <input class="checkbox" type="checkbox"
  103. name="done" <?php if ($item['Done'] == 1) echo 'checked'; ?>/>
  104. <label class="joblist">
  105. <?php
  106. echo $item['Name'];
  107. ?>
  108. </label>
  109. </div>
  110.  
  111. <?php endforeach; ?>
  112.  
  113.  
  114. </form>
  115. </div>
  116. </div>
  117.  
  118.  
  119. <?php
  120.  
  121.  
  122. //echo __('Hello, World!', 'wpb_widget_domain');
  123. }
  124.  
  125. // Widget Backend
  126. public function form($instance)
  127. {
  128. if (isset($instance['title'])) {
  129. $title = $instance['title'];
  130. } else {
  131. $title = __('New title', 'wpb_widget_domain');
  132. }
  133. // Widget admin form
  134. ?>
  135. <p>
  136. <label for="<?php echo $this->get_field_id('title'); ?>"><?php _e('Title:'); ?></label>
  137. <input class="widefat" id="<?php echo $this->get_field_id('title'); ?>"
  138. name="<?php echo $this->get_field_name('title'); ?>" type="text"
  139. value="<?php echo esc_attr($title); ?>"/>
  140. </p>
  141. <?php
  142. }
  143.  
  144. // Updating widget replacing old instances with new
  145. public function update($new_instance, $old_instance)
  146. {
  147. $instance = array();
  148. $instance['title'] = (!empty($new_instance['title'])) ? strip_tags($new_instance['title']) : '';
  149. return $instance;
  150. }
  151. } // Class wpb_widget ends here
  152.  
  153. // Register and load the widget
  154. function vaidas_todo_load_widget()
  155. {
  156. register_widget('vaidas_todo_widget');
  157. }
  158.  
  159. add_action('widgets_init', 'vaidas_todo_load_widget');
  160.  
  161. /** Step 2 (from text above). */
  162. add_action('admin_menu', 'my_plugin_menu');
  163.  
  164. /** Step 1. */
  165. function my_plugin_menu()
  166. {
  167. add_options_page('My Plugin Options', 'My Plugin', 'manage_options', 'my-unique-identifier', 'my_plugin_options');
  168. }
  169.  
  170. function validate() {
  171. $a=$_POST['toDoItemm'];
  172.  
  173.  
  174. }
  175.  
  176. /** Step 3. */
  177. function my_plugin_options()
  178. {
  179. if (!current_user_can('manage_options')) {
  180. wp_die(__('You do not have sufficient permissions to access this page.'));
  181. }
  182.  
  183.  
  184. echo '<div class="wrap">';
  185. echo '<p>Here is where the form would go if I actually had options.</p>';
  186. echo '<h1><a>to-do admin panel</a></h1>';
  187. if (isset($_POST['toDoItemm'])){
  188. echo $_POST['toDoItemm'];
  189. }
  190. echo '<form method="POST" onsubmit="return validate()" action="">';
  191. echo '<div>';
  192. echo '<input class="input" type="text" name="toDoItemm" value="To-do panel title"/><br>';
  193. echo '<input class="save" type="submit" value="Save">';
  194. echo '</div>';
  195. echo '</form>';
  196. echo '<form>';
  197. echo '<div>';
  198.  
  199. global $wpdb;
  200. $results = $wpdb->get_results('SELECT * FROM `mytable`', ARRAY_A);
  201.  
  202.  
  203. foreach ($results as $item):
  204.  
  205. echo '<input class="delete" type="submit" value="Delete">';
  206. if ($item['Done'] == 1) $checkedtekstas = 'checked="checked"'; else $checkedtekstas = '';
  207. echo '<input class="checkbox" type="checkbox" name="Done"' . $checkedtekstas . '/><br>';
  208.  
  209. echo '<label class="joblist">';
  210.  
  211. echo $item['Name'];
  212. echo '</label>';
  213.  
  214. endforeach;
  215.  
  216. echo '</div>';
  217. echo '</form>';
  218.  
  219.  
  220. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement