function smarty_function_menus_dropdown($params, &$smarty) { global $LANG; if (empty($params["name_id"])) { $smarty->trigger_error("assign: missing 'name_id' parameter. This is used to give the select field a name and id value."); return; } $default = isset($params["default"]) ? $params["default"] : ""; $type = isset($params["type"]) ? $params["type"] : ""; // admin, client or "" $attributes = array("id" => $params["name_id"], "name" => $params["name_id"]); $attribute_str = ""; while (list($key, $value) = each($attributes)) { if (!empty($value)) { $attribute_str .= " {$key}=\"{$value}\""; } } $menus = ft_get_menu_list(); $rows = array("<option value=\"\">{$LANG["phrase_please_select"]}</option>"); foreach ($menus as $menu_info) { $menu_id = $menu_info["menu_id"]; $menu = $menu_info["menu"]; $menu_type = $menu_info["menu_type"]; if (!empty($type) && $menu_type != $type) { continue; } $rows[] = "<option value=\"{$menu_id}\" " . ($default == $menu_id ? "selected" : "") . ">{$menu}</option>"; } $dd = "<select {$attribute_str}>" . join("\n", $rows) . "</select>"; return $dd; }
function sc_get_menu_ids() { $menus = ft_get_menu_list(); $valid_menu_ids = array(); foreach ($menus as $menu_info) { $valid_menu_ids[] = $menu_info["menu_id"]; } return $valid_menu_ids; }
$menu_id = $request["menu_id"]; } if (isset($request["update_client_menu"])) { $info = $_POST; $info["sortable_id"] = $sortable_id; list($g_success, $g_message) = ft_update_client_menu($info); } $menu_info = ft_get_client_menu($menu_id); $num_menu_items = count($menu_info["menu_items"]); $selected_client_ids = array(); foreach ($menu_info["clients"] as $client_info) { $selected_client_ids[] = $client_info["account_id"]; } // get a list of all menus names; this is used to ensure the uniqueness of the menu names to ward // against confusion $menus = ft_get_menu_list(); $menu_names = array(); foreach ($menus as $curr_menu_info) { if ($menu_id == $curr_menu_info["menu_id"]) { continue; } $menu_names[] = "\"" . htmlspecialchars($curr_menu_info["menu"]) . "\""; } $menu_list = implode(",", $menu_names); $js = "var page_ns = {};\npage_ns.menu_names = [{$menu_list}];\nmm.num_rows = {$num_menu_items};\n"; if ($num_menu_items == 0) { $js .= "\$(function() { mm.add_menu_item_row(); });"; } // ------------------------------------------------------------------------------------------------ // compile the header information $page_vars = array();
/** * Deletes a client menu. Since it's possible for one or more clients to already be associated with the * menu, those clients will be orphaned by this action. In this situation, it refuses to delete the * menu, and lists all clients that will be affected (each a link to their account). It also provides * an option to bulk assign them to another menu. * * In all likelihood, however, the administrator will already be aware of this, having seen their names * listed in the table where they chose to delete the menu. * * @param integer $menu_id * @return array [0] T/F, [1] message */ function ft_delete_client_menu($menu_id) { global $g_table_prefix, $g_root_url, $LANG; extract(ft_process_hook_calls("start", compact("menu_id"), array()), EXTR_OVERWRITE); // confirm that there are no client accounts that currently use this menu $query = mysql_query("\r\n SELECT account_id, first_name, last_name\r\n FROM {$g_table_prefix}accounts\r\n WHERE menu_id = {$menu_id}\r\n "); $client_info = array(); while ($row = mysql_fetch_assoc($query)) { $client_info[] = $row; } if (!empty($client_info)) { $message = $LANG["notify_deleted_menu_already_assigned"]; $placeholder_str = $LANG["phrase_assign_all_listed_client_accounts_to_menu"]; $menus = ft_get_menu_list(); $dd = "<select id=\"mass_update_client_menu\">"; foreach ($menus as $menu_info) { if ($menu_info["menu_type"] == "admin") { continue; } $dd .= "<option value=\"{$menu_info["menu_id"]}\">{$menu_info["menu"]}</option>"; } $dd .= "</select>"; // a bit bad (hardcoded HTML!), but organize the account list in 3 columns $client_links_table = "<table cellspacing=\"0\" cellpadding=\"0\" width=\"100%\">\n<tr>"; $num_affected_clients = count($client_info); for ($i = 0; $i < $num_affected_clients; $i++) { $account_info = $client_info[$i]; $client_id = $account_info["account_id"]; $first_name = $account_info["first_name"]; $last_name = $account_info["last_name"]; $client_ids[] = $client_id; if ($i != 0 && $i % 3 == 0) { $client_links_table .= "</tr>\n<tr>"; } $client_links_table .= "<td width=\"33%\">• <a href=\"{$g_root_url}/admin/clients/edit.php?page=settings&client_id={$client_id}\" target=\"_blank\">{$first_name} {$last_name}</a></td>\n"; } $client_id_str = join(",", $client_ids); // close the table if ($num_affected_clients % 3 == 1) { $client_links_table .= "<td colspan=\"2\" width=\"66%\"> </td>"; } else { if ($num_affected_clients % 3 == 2) { $client_links_table .= "<td width=\"33%\"> </td>"; } } $client_links_table .= "</tr></table>"; $submit_button = "<input type=\"button\" value=\"{$LANG["phrase_update_accounts"]}\" onclick=\"window.location='index.php?page=menus&mass_assign=1&accounts={$client_id_str}&menu_id=' + \$('#mass_update_client_menu').val()\" />"; $placeholders = array("menu_dropdown" => $dd, "submit_button" => $submit_button); $mass_assign_html = "<div class=\"margin_top_large margin_bottom_large\">" . ft_eval_smarty_string($placeholder_str, $placeholders) . "</div>"; $html = $message . $mass_assign_html . $client_links_table; return array(false, $html); } // ------------------------------------------------------------ $client_account_query = mysql_query("\r\n SELECT account_id, first_name, last_name\r\n FROM {$g_table_prefix}accounts\r\n WHERE menu_id = {$menu_id}\r\n "); // delete the menu mysql_query("DELETE FROM {$g_table_prefix}menus WHERE menu_id = {$menu_id}"); mysql_query("DELETE FROM {$g_table_prefix}menu_items WHERE menu_id = {$menu_id}"); // construct the message to return to the administrator $client_accounts = array(); while ($row = mysql_fetch_assoc($client_account_query)) { $client_accounts[] = $row; } if (empty($client_accounts)) { $success = true; $message = $LANG["notify_client_menu_deleted"]; } else { $success = false; $message = $LANG["notify_client_menu_deleted_orphaned_accounts"]; $accounts_str = "<br />"; foreach ($client_accounts as $account_info) { $client_id = $account_info["account_id"]; $first_name = $account_info["first_name"]; $last_name = $account_info["last_name"]; $accounts_str .= "• <a href=\"{$g_root_url}/admin/clients/edit.php?client_id={$client_id}\" target=\"_blank\">{$first_name} {$last_name}</a><br />\n"; } $message .= $accounts_str; } return array($success, $message); }