function custom_bulk_action() { if ($_REQUEST["post_type"] != $this->type) { return; } global $wpdb; $wp_list_table = _get_list_table('WP_Posts_List_Table'); if ($wp_list_table->current_action() == 'view') { if (substr($_REQUEST['post_type'], 0, 4) == 'item') { $sendback = add_query_arg('itemids', $_REQUEST['post'], 'edit.php?page=view&post_type=itembasket'); wp_redirect($sendback); exit; } if ($_REQUEST['post_type'] == 'learnout') { $sendback = add_query_arg('learnoutids', $_REQUEST['post'], 'edit.php?page=view&post_type=itembasket'); wp_redirect($sendback); exit; } if ($_REQUEST['post_type'] == 'review') { $sendback = add_query_arg('reviewids', $_REQUEST['post'], 'edit.php?page=view&post_type=itembasket'); wp_redirect($sendback); exit; } } if ($wp_list_table->current_action() == 'mark' || $wp_list_table->current_action() == 'unmark') { if (substr($_REQUEST['post_type'], 0, 4) == 'item') { /* get array of postids */ $postids = $_REQUEST['post']; if (!is_array($postids)) { $postids = [$postids]; } if (count($postids) > 0) { $sql = sprintf("UPDATE {$wpdb->prefix}eal_item SET flag = %d WHERE id IN (%s)", $wp_list_table->current_action() == 'mark' ? 1 : 0, join(",", $postids)); $wpdb->query($sql); } } } if ($wp_list_table->current_action() == 'setpublished' || $wp_list_table->current_action() == 'setpending' || $wp_list_table->current_action() == 'setdraft') { $status = "publish"; if ($wp_list_table->current_action() == 'setpending') { $status = "pending"; } if ($wp_list_table->current_action() == 'setdraft') { $status = "draft"; } /* get array of postids */ $postids = $_REQUEST['post']; if (!is_array($postids)) { $postids = [$postids]; } if (count($postids) > 0) { $sql = sprintf("UPDATE {$wpdb->posts} SET post_status = '%s' WHERE id IN (%s)", $status, join(",", $postids)); $wpdb->query($sql); } } /* Add Items to Basket */ if ($wp_list_table->current_action() == 'add_to_basket') { /* get array of postids */ $postids = $_REQUEST['post']; if (!is_array($postids)) { $postids = [$postids]; } $basket_old = RoleTaxonomy::getCurrentBasket(); // get_user_meta(get_current_user_id(), 'itembasket', true); if ($basket_old == null) { $basket_old = array(); } if (count($basket_old) == 0) { $basket_old = [-1]; } // dummy basket to make sure SQLL works /* get Items from Learning Outcomes */ $sql = "SELECT P.id FROM {$wpdb->prefix}eal_item I JOIN {$wpdb->prefix}posts P ON (P.ID = I.ID) WHERE P.post_parent = 0 AND "; $sql .= sprintf('( %1$s IN (%2$s) OR I.id IN (%3$s) )', $_REQUEST['post_type'] == 'learnout' ? 'I.learnout_id' : 'I.id', join(", ", $postids), join(", ", $basket_old)); $itemids = $wpdb->get_col($sql); RoleTaxonomy::setCurrentBasket($itemids); // $x = update_user_meta( get_current_user_id(), 'itembasket', $itemids); } if ($wp_list_table->current_action() == 'remove_from_basket') { $b_old = RoleTaxonomy::getCurrentBasket(); // get_user_meta(get_current_user_id(), 'itembasket', true); $b_new = $b_old; if (isset($_REQUEST["post"])) { $b_new = array_diff($b_old, $_REQUEST['post']); } if ($_REQUEST['itemid'] != null) { $b_new = array_diff($b_old, [$_REQUEST['itemid']]); } if ($_REQUEST['itemids'] != null) { $b_new = array_diff($b_old, $_REQUEST['itemids']); } RoleTaxonomy::setCurrentBasket($b_new); // $x = update_user_meta( get_current_user_id(), 'itembasket', $b_new, $b_old ); } }
public function WPCB_posts_where($where, $checktype = TRUE) { global $wp_query, $wpdb; if ($wp_query->query["post_type"] == $this->type || !$checktype) { // if all items are considered --> consider all type starting with "item" if ($this->type == "item") { $where = str_replace("{$wpdb->posts}.post_type = 'item'", "{$wpdb->posts}.post_type LIKE 'item%'", $where); } // if current role type = author --> show all items except drafts from others if (RoleTaxonomy::getCurrentRoleType() == "author") { $where .= "AND ({$wpdb->posts}.post_status != 'draft' OR {$wpdb->posts}.post_author = " . get_current_user_id() . ")"; } if (isset($_REQUEST["item_type"]) && $_REQUEST['item_type'] != "0") { $where .= " AND I.type = '{$_REQUEST['item_type']}'"; } if (isset($_REQUEST["post_status"]) && $_REQUEST['post_status'] != "0") { $where .= " AND {$wpdb->posts}.post_status = '" . $_REQUEST['post_status'] . "'"; } if (isset($_REQUEST["learnout_id"])) { $where .= " AND L.id = {$_REQUEST['learnout_id']}"; } if (isset($_REQUEST['item_author'])) { $where .= " AND {$wpdb->posts}.post_author \t\t\t= " . $_REQUEST['item_author']; } if (isset($_REQUEST['item_points'])) { $where .= " AND I.points \t= " . $_REQUEST['item_points']; } if (isset($_REQUEST['level_FW']) && $_REQUEST['level_FW'] > 0) { $where .= " AND I.level_FW \t= " . $_REQUEST['level_FW']; } if (isset($_REQUEST['level_PW']) && $_REQUEST['level_PW'] > 0) { $where .= " AND I.level_PW \t= " . $_REQUEST['level_PW']; } if (isset($_REQUEST['level_KW']) && $_REQUEST['level_KW'] > 0) { $where .= " AND I.level_KW\t= " . $_REQUEST['level_KW']; } if (isset($_REQUEST['learnout_id'])) { $where .= " AND I.learnout_id = " . $_REQUEST['learnout_id']; } if (isset($_REQUEST['flag'])) { if ($_REQUEST['flag'] == 1) { $where .= " AND I.flag = 1"; } if ($_REQUEST['flag'] == 2) { $where .= " AND (I.flag != 1 OR I.flag IS NULL)"; } } if (isset($_REQUEST['taxonomy']) && $_REQUEST['taxonomy'] > 0) { $children = get_term_children($_REQUEST['taxonomy'], RoleTaxonomy::getCurrentRoleDomain()["name"]); array_push($children, $_REQUEST['taxonomy']); $where .= sprintf(' AND %1$s.ID IN (SELECT TR.object_id FROM %2$s TT JOIN %3$s TR ON (TT.term_taxonomy_id = TR.term_taxonomy_id) WHERE TT.term_id IN ( %4$s ))', $wpdb->posts, $wpdb->term_taxonomy, $wpdb->term_relationships, implode(', ', $children)); } if ($this->type == "itembasket") { $where = str_replace("{$wpdb->posts}.post_type = 'itembasket'", "{$wpdb->posts}.post_type LIKE 'item%'", $where); $basket = RoleTaxonomy::getCurrentBasket(); // get_user_meta(get_current_user_id(), 'itembasket', true); if (is_array($basket) && count($basket) > 0) { $where .= " AND I.ID IN (" . implode(",", $basket) . ") "; } else { $where .= " AND (1=2) "; } } } return $where; }
function set_eal_admin_menu_entries() { /* remove standard menu entries */ remove_menu_page('index.php'); //Dashboard remove_menu_page('edit.php'); //Posts remove_menu_page('upload.php'); //Media remove_menu_page('edit.php?post_type=page'); //Pages remove_menu_page('edit-comments.php'); //Comments remove_menu_page('themes.php'); //Appearance // remove_menu_page( 'plugins.php' ); //Plugins // remove_menu_page( 'users.php' ); //Users remove_menu_page('tools.php'); //Tools // remove_menu_page( 'options-general.php' ); //Settings // add_menu_page('eal_page_items', 'Items', 'administrator', 'eal_page_items', 'create_eal_page_items', '', 1); // add_menu_page('My Page Title', 'My Menu Title', 'manage_options', 'my-menu', 'my_menu_output' ); // add_menu_page('My Custom Page', 'My Custom Page', 'manage_options', 'my-top-level-slug'); // add_submenu_page( 'my-top-level-slug', 'My Custom Page', 'My Custom Page', 'manage_options', 'my-top-level-slug'); global $menu, $submenu; add_menu_page('eal_page_items', 'Items', 'edit_posts', 'edit.php?post_type=item', '', 'dashicons-format-aside', 31); add_submenu_page('edit.php?post_type=item', 'All Items', '<div class="dashicons-before dashicons-format-aside" style="display:inline"> </div> All Items', 'edit_posts', 'edit.php?post_type=item'); add_submenu_page('edit.php?post_type=item', 'Single Choice', '<div class="dashicons-before dashicons-marker" style="display:inline"> </div> Single Choice', 'edit_posts', 'edit.php?post_type=itemsc'); add_submenu_page('edit.php?post_type=item', 'Multiple Choice', '<div class="dashicons-before dashicons-forms" style="display:inline"> </div> Multiple Choice', 'edit_posts', 'edit.php?post_type=itemmc'); add_submenu_page('edit.php?post_type=item', 'Import', '<div class="dashicons-before dashicons-upload" style="display:inline"> </div> Import', 'edit_posts', 'import-items', array('PAG_Item_Import', 'createPage')); add_submenu_page('edit.php?post_type=item', 'Reviews', '<div class="dashicons-before dashicons-admin-comments" style="display:inline"> </div> Reviews', 'edit_posts', 'edit.php?post_type=review'); $domain = RoleTaxonomy::getCurrentRoleDomain(); /* TODO: first sub menu should open menu */ // $menuslug = 'metadata'; $taxurl = 'edit-tags.php?taxonomy=' . $domain["name"]; $taxurlredirect = add_query_arg('redirect', $taxurl, 'edit.php?post_type=learnout'); // add_menu_page('eal_page_metadata', 'Metadata', 'edit_posts', $menuslug, '' /* array ('PAG_Metadata', 'createTable')*/, 'dashicons-tag', 32); // add_submenu_page( $menuslug, $domain["label"], '<div class="dashicons-before dashicons-networking" style="display:inline"> </div> ' . $domain["label"], 'edit_posts', $taxurl); // add_submenu_page( $menuslug, 'Import', '<div class="dashicons-before dashicons-upload" style="display:inline"> </div> Import', 'edit_posts', 'import', 'WPCB_import_topics'); // add_submenu_page( $menuslug, 'Learning Outcomes', '<div class="dashicons-before dashicons-welcome-learn-more" style="display:inline"> </div> Learn. Outcomes', 'edit_posts', 'edit.php?post_type=learnout'); add_menu_page('eal_page_metadata', 'Metadata', 'edit_posts', 'edit.php?post_type=learnout', '', 'dashicons-tag', 32); add_submenu_page('edit.php?post_type=learnout', 'Learning Outcomes', '<div class="dashicons-before dashicons-welcome-learn-more" style="display:inline"> </div> Learn. Outcomes', 'edit_posts', 'edit.php?post_type=learnout'); if ($domain["name"] != "") { add_submenu_page('edit.php?post_type=learnout', $domain["label"], '<div class="dashicons-before dashicons-networking" style="display:inline"> </div> ' . $domain["label"], 'edit_posts', $taxurl); } // add_submenu_page( 'edit.php?post_type=learnout', 'Import', '<div class="dashicons-before dashicons-upload" style="display:inline"> </div> Import', 'edit_posts', 'import', 'WPCB_import_topics'); add_submenu_page('edit.php?post_type=learnout', 'Import', '<div class="dashicons-before dashicons-upload" style="display:inline"> </div> Import', 'edit_posts', 'import-taxonomy', array('PAG_Taxonomy_Import', 'createPage')); // LEZTE // add_menu_page('eal_page_metadata', 'Metadata', 'edit_posts', 'metadata', '' /* array ('PAG_Metadata', 'createTable')*/, 'dashicons-tag', 32); // add_submenu_page( 'metadata', $domain["label"], '<div class="dashicons-before dashicons-networking" style="display:inline"> </div> ' . $domain["label"], 'edit_posts', $taxurl); // add_submenu_page( 'metadata', 'Import', '<div class="dashicons-before dashicons-upload" style="display:inline"> </div> Import', 'edit_posts', 'import', 'WPCB_import_topics'); // add_submenu_page( 'metadata', 'Learning Outcomes', '<div class="dashicons-before dashicons-welcome-learn-more" style="display:inline"> </div> Learn. Outcomes', 'edit_posts', 'edit.php?post_type=learnout'); $c = count(RoleTaxonomy::getCurrentBasket()); // $c = count(get_user_meta(get_current_user_id(), 'itembasket', true)); add_menu_page('eal_page_basket', 'Item Basket <span class="update-plugins count-1"><span class="plugin-count">' . $c . '</span></span>', 'edit_posts', 'edit.php?post_type=itembasket', '', 'dashicons-cart', 34); add_submenu_page('edit.php?post_type=itembasket', 'Table', '<div class="dashicons-before dashicons-format-aside" style="display:inline"> </div> Table', 'edit_posts', 'edit.php?post_type=itembasket'); add_submenu_page('edit.php?post_type=itembasket', 'Explorer', '<div class="dashicons-before dashicons-chart-pie" style="display:inline"> </div> Explorer', 'edit_posts', 'ist-blueprint', array('PAG_Explorer', 'createPage')); add_submenu_page('edit.php?post_type=itembasket', 'Viewer', '<div class="dashicons-before dashicons-exerpt-view" style="display:inline"> </div> Viewer', 'edit_posts', 'view', array('PAG_Basket', 'createPageView')); add_submenu_page('edit.php?post_type=itembasket', 'Generator', '<div class="dashicons-before dashicons-admin-generic" style="display:inline"> </div> Generator', 'edit_posts', 'generator', array('PAG_Generator', 'createPage')); }
public static function createPageView() { $itemids = array(); /* try to get learning outcomes */ $post_label = "Learning Outcome"; if ($_REQUEST['learnoutid'] != null) { $itemids = [$_REQUEST['learnoutid']]; } if ($_REQUEST['learnoutids'] != null) { if (is_array($_REQUEST['learnoutids'])) { $itemids = $_REQUEST['learnoutids']; } if (is_string($_REQUEST['learnoutids'])) { $itemids = explode(",", $_REQUEST["learnoutids"]); } } if (count($itemids) == 0) { // no learning outcomes found --> get reviews $post_label = "Review"; if ($_REQUEST['reviewid'] != null) { $itemids = [$_REQUEST['reviewid']]; } if ($_REQUEST['reviewids'] != null) { if (is_array($_REQUEST['reviewids'])) { $itemids = $_REQUEST['reviewids']; } if (is_string($_REQUEST['reviewids'])) { $itemids = explode(",", $_REQUEST["reviewids"]); } } } if (count($itemids) == 0) { // nothing found --> get items $post_label = "Item"; if ($_REQUEST['itemid'] != null) { $itemids = [$_REQUEST['itemid']]; } if ($_REQUEST['itemids'] != null) { if (is_array($_REQUEST['itemids'])) { $itemids = $_REQUEST['itemids']; } if (is_string($_REQUEST['itemids'])) { $itemids = explode(",", $_REQUEST["itemids"]); } } // fallback: get items from basket if (count($itemids) == 0) { $itemids = RoleTaxonomy::getCurrentBasket(); } // get_user_meta(get_current_user_id(), 'itembasket', true); } $html_list = ""; $html_select = "<form><select onChange='for (x=0; x<this.form.nextSibling.childNodes.length; x++) { this.form.nextSibling.childNodes[x].style.display = ((this.value<0) || (this.value==x)) ? \"block\" : \"none\"; }'>"; $html_select .= sprintf('<option value="-1" selected>[All %1$d %2$ss]</option>', count($itemids), $post_label); $count = 0; $items = array(); foreach ($itemids as $item_id) { $post = get_post($item_id); if ($post == null) { continue; } $item = null; if ($post->post_type == 'itemsc') { $item = new EAL_ItemSC(); } if ($post->post_type == 'itemmc') { $item = new EAL_ItemMC(); } if ($post->post_type == 'learnout') { $item = new EAL_LearnOut(); } if ($post->post_type == 'review') { $item = new EAL_Review(); } if ($item != null) { $item->loadById($item_id); $html_select .= sprintf("<option value='%d'>%s</option>", $count, $post->post_type == 'review' ? $item->getItem()->title : $item->title); $html_list .= sprintf("<div style='margin-top:2em;'><hr/>%s<br style='clear:both;'/></div>", substr($post->post_type, 0, 4) == "item" ? CPT_Item::getHTML_Item($item, FALSE) : ($post->post_type == 'learnout' ? CPT_LearnOut::getHTML_LearnOut($item) : CPT_Review::getHTML_Review($item))); $count++; array_push($items, $item); } } $html_select .= "</select> <input type='checkbox' checked \r\n\t\t\tonChange='for (x=0; x<this.form.nextSibling.childNodes.length; x++) { this.form.nextSibling.childNodes[x].querySelector(\"#postbox-container-1\").style.display = (this.checked==true) ? \"block\" : \"none\"; }'/> Show Metadata</form>"; if ($post_label == "Item") { $html_info = sprintf("<form style='margin-top:5em' enctype='multipart/form-data' action='admin.php?page=view&download=1&itemids=%s' method='post'><table class='form-table'><tbody'>", implode(",", $itemids)); $html_info .= sprintf("<tr><th style='padding-top:0px; padding-bottom:0px;'><label>%s</label></th>", "Number of Items"); $html_info .= sprintf("<td style='padding-top:0px; padding-bottom:0px;'>"); $html_info .= sprintf("<input style='width:5em' type='number' value='%d' readonly/>", count($items)); $html_info .= sprintf("</td></tr>"); // Min / Max for all categories $categories = array("type", "dim", "level", "topic1"); foreach ($categories as $category) { $html_info .= sprintf("<tr><th style='padding-bottom:0.5em;'><label>%s</label></th></tr>", EAL_Item::$category_label[$category]); foreach (PAG_Explorer::groupBy($category, $items, NULL, true) as $catval => $catitems) { $html_info .= sprintf("<tr><td style='padding-top:0px; padding-bottom:0px;'><label>%s</label></td>", $category == "topic1" ? $catval : EAL_Item::$category_value_label[$category][$catval]); $html_info .= sprintf("<td style='padding-top:0px; padding-bottom:0px;'>"); $html_info .= sprintf("<input style='width:5em' type='number' value='%d' readonly/>", count($catitems)); $html_info .= sprintf("</td></tr>"); } } $html_info .= sprintf("<tr><th><button type='submit' name='action' value='download'>Download</button></th><tr>"); $html_info .= sprintf("</tbody></table></form></div>"); } printf('<div class="wrap"><h1>%1$s Viewer</h1>', $post_label); if ($_REQUEST['download'] == '1') { $ilias = new EXP_Ilias(); $link = $ilias->generateExport($itemids); printf("<h2><a href='%s'>Download</a></h2>", $link); } if (count($itemids) > 1 || count($itemids) == 1) { print $html_select; print "<div style='margin-top:2em'>{$html_list}{$html_info}</div>"; } else { print "<div style='margin-top:2em'>{$html_list}</div>"; } print "</div>"; }