%s
', __('No quiz available!','abctest_lbl')); } echo ''; } public static function mainform($rows, $action) { $actions = array('' => '', 'insert' => 'admin.php?page=abctest&do=insert', 'edit' => '?page=abctest&do=update'); ?> prefix . "abctest_main"; $fields = self::dbfields(); $rows_affected = $wpdb->insert( $table_name, $fields ); if ($rows_affected > 0) { self::$message = __('Data were entered.','abctest_lbl'); self::$msgstatus = 'updated'; } else { self::$message = __('There was an error! Can not insert data.','abctest_lbl'); self::$msgstatus = 'error'; } return $rows_affected; } public static function edit() { global $wpdb; $sql = sprintf("SELECT * FROM %sabctest_main WHERE id_test = %d", $wpdb->prefix, $_GET['id']); $rslt = $wpdb->get_results($sql); self::mainform($rslt, $_GET['do']); } public static function update() { global $wpdb; $table_name = $wpdb->prefix . "abctest_main"; $fields = self::dbfields(); $rows_affected = $wpdb->update( $table_name, $fields, array('id_test' => $_POST['irecord']), NULL, array('%d') ); if ($rows_affected > 0) { self::$message = __('The data have been updated.','abctest_lbl'); self::$msgstatus = 'updated'; } else { self::$message = __('There was an error! Can not update the data.','abctest_lbl'); self::$msgstatus = 'error'; } return $rows_affected; } public static function delete() { global $wpdb; $sql = sprintf("DELETE FROM %sabctest_main WHERE id_test = %d", $wpdb->prefix, $_GET['id']); $wpdb->query($sql); // cancella dati correlati $sql = sprintf("DELETE FROM %sabctest_options WHERE id_test = %d", $wpdb->prefix, $_GET['id']); $wpdb->query($sql); self::$message = __('The data have been deleted.','abctest_lbl'); self::$msgstatus = 'updated'; // Implementare cancellazione immagine /* $deletefile = self::$uploadfolder . $_GET['file']; if ( file_exists( $deletefile ) ) { unlink($deletefile); } */ } public static function dbfields() { $arrFields = array('test_title' => $_POST['test_title'], 'test_text' => $_POST['test_text'], 'test_result_a' => $_POST['test_result_a'], 'test_result_b' => $_POST['test_result_b'], 'test_result_c' => $_POST['test_result_c']); //'bgimage' => $_FILES['bgimage']['name'], /* $upfile = self::upload(); if ( ! empty($upfile) ) { $fup = array("bgimage" => $upfile); $arrFields = array_merge((array) $arrFields, (array) $fup); } */ return $arrFields; } public static function install() { global $wpdb; require_once(ABSPATH . 'wp-admin/includes/upgrade.php'); // Prima tabella $table_name = $wpdb->prefix . "abctest_main"; $sql = "CREATE TABLE " . $table_name . " ( id_test bigint(11) NOT NULL AUTO_INCREMENT, test_title varchar(255) DEFAULT NULL, test_text longtext, test_image varchar(255) DEFAULT NULL, test_result_a longtext, test_result_b longtext, test_result_c longtext, absolute_url text, PRIMARY KEY (id_test) );"; // Seconda tabella $table_name = $wpdb->prefix . "abctest_options"; $sql .= "CREATE TABLE " . $table_name . " ( id_option bigint(11) NOT NULL AUTO_INCREMENT, id_test bigint(20) DEFAULT '0', options_introduction longtext, option_a text, option_b text, option_c text, options_order int(11) DEFAULT '0', PRIMARY KEY (id_option) );"; dbDelta($sql); } } // end abcTest register_activation_hook(__FILE__, array('abcTest', 'install')); add_action('admin_menu', array('abcTest', 'admin_abc_test')); /* Tiny MCE */ add_filter('admin_head','show_tinyMCE'); function show_tinyMCE() { wp_enqueue_script( 'common' ); wp_enqueue_script( 'jquery-color' ); wp_print_scripts('editor'); if (function_exists('add_thickbox')) add_thickbox(); wp_print_scripts('media-upload'); if (function_exists('wp_tiny_mce')) wp_tiny_mce(); wp_admin_css(); wp_enqueue_script('utils'); do_action("admin_print_styles-post-php"); do_action('admin_print_styles'); remove_all_filters('mce_external_plugins'); } if ( is_admin() ) { add_action('init', array('abcTest', 'init')); // add_action('admin_print_scripts-' . abcTest::$CurrentPage, 'add_scripts'); add_action('admin_print_scripts-tools_page_options', 'add_scripts'); } function add_scripts() { wp_register_style('abctest_css', plugins_url('css/abctest_style.css', __FILE__)); wp_enqueue_style('abctest_css'); wp_enqueue_script( array("jquery", "jquery-ui-core", "interface", "jquery-ui-sortable", "wp-lists", "jquery-ui-sortable") ); wp_register_script('abctest_script', plugins_url('js/abctest_functions.js', __FILE__)); wp_enqueue_script( 'abctest_script' ); } /* FRONT END */ if (! is_admin() ) { add_shortcode( 'abctest', array('abcTestFrontEnd', 'shortcode_handler') ); add_action('init', array('abcTestFrontEnd','frontscripts')); } ?>