Hello, I am wondering if someone can give some help on using two arrays to build a drop down, and save the values for each of them when needed without
the constants colliding. Here is some information about the arrays used and the current foreach I use to build it.
Here is the current foreach loop that will build the drop down. It is basically taking the share_type array and foreaching through it. (The few if
statements in there are just hiding a few of the choices if certain circumstances are met)
// block out anything except agent shares when asked
if ( $lock_to_share_type_agent )
{
$html .= '<option value="'. SHARE_TYPE_AGENT .'" selected="selected">'. $share_types[SHARE_TYPE_AGENT] .'</option>';
include_once(BASE_PATH .'/web/customer/lib/share/read.php');
foreach( $share_types as $key => $value )
{
// don't show File Share type if network_fs_enabled is 0
if ( $key == SHARE_TYPE_FS && $server_info['network_fs_enabled'] == 0 && $server_info['server_type'] == SERVER_TYPE_OSB_WINDOWS ) continue;
// make sure account has access to agent services and that the server has agent support turned on
if ( $key == SHARE_TYPE_AGENT && (!$agent_service_available || !$server_agent_enabled) ) continue;
Now what I want to do now is incorporate another array ($share_protocols) as seen above to display next to the file share if that is picked. I have tried doing
something like seen below, but the constant values seem to be colliding. The problem is I need to save the constant value from the first array ($share_type),
and also the constant value from the 2nd array if we are using it ($share_protocol) In a perfect world the drop down would be:
File Share - CIFS
File Share - SSHFS
File Share - NCPFS
then the rest...
Saving both the share type (File Share) and the share protocol (CIFS, or SSHFS, or NCPFS) depending on what is selected.
If anyone has any input I would greatly appreciate it. It is a bit hard to explain what I am trying to do so I apologize if it is confusing/overwheling.
First: you can help us to help you by making use of this forum's [php]...[/php] bbcode tags around your code samples.
Anyway, if I correctly followed all of that, it sounds like you just need an if/else within the foreach loop after the "continue;", where you either check if $key is SHARE_TYPE_FS or check if the $value is "file share", and if so put in a foreach loop on the second array at that point to output its options/values, then the rest of the code for the outer foreach loop would be in an ensuing else block.
"Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
~ Terry Pratchett in Nation
thanks NogDog. Sorry about the formatting. I will remember that for next time. So for displaying purposes, that if statement you suggested worked perfectly. There is one last thing that I need to be able to do though, and was wondering if you could provide any help.
PHP Code:
foreach( $share_types as $key => $value ) { // only show types that make sense for current server selection if ( $server_info !== false && !in_array($key, $share_types_by_server_type[$server_info["server_type"]]) ) continue;
// don't show deprecated types for new shares if ( share_type_is_deprecated($key) && $share_id == 0 ) continue;
// don't show agent in dropdown when server already has an agent share if ($key == SHARE_TYPE_AGENT && isset($server_has_agent_share_list[$server_id]) && $server_has_agent_share_list[$server_id]['type'] == SHARE_TYPE_AGENT && $server_info['server_type'] == SERVER_TYPE_OSB_WINDOWS && empty($field_data)) continue;
// don't show File Share type if network_fs_enabled is 0 if ( $key == SHARE_TYPE_FS && $server_info['network_fs_enabled'] == 0 && $server_info['server_type'] == SERVER_TYPE_OSB_WINDOWS ) continue;
// make sure account has access to email services if ( !$email_service_available && ($key == SHARE_TYPE_EMAIL_EXCHANGE || $key == SHARE_TYPE_EMAIL_GROUPWISE) ) continue;
// make sure account has access to agent services and that the server has agent support turned on if ( $key == SHARE_TYPE_AGENT && (!$agent_service_available || !$server_agent_enabled) ) continue;
if ( $key == SHARE_TYPE_FS ) { foreach ($share_protocols as $protocol_key => $value_protocol) { if ($protocol_key == SHARE_FS_PROTOCOL_SSHFS && $server_info['server_type'] == SERVER_TYPE_OSB_WINDOWS) continue; if ($protocol_key == SHARE_FS_PROTOCOL_NCPFS && $server_info['server_type'] == SERVER_TYPE_OSB_WINDOWS) continue; if ($protocol_key == SHARE_FS_PROTOCOL_NCPFS && ($server_info['server_type'] == SERVER_TYPE_OSB_UNIX_SSHFS || $server_info['server_type'] == SERVER_TYPE_OSB_OSX)) continue; if ($protocol_key == SHARE_FS_PROTOCOL_CIFS && ($server_info['server_type'] == SERVER_TYPE_OSB_UNIX_SSHFS || $server_info['server_type'] == SERVER_TYPE_OSB_OSX)) continue; if ($protocol_key == SHARE_FS_PROTOCOL_SSHFS && $server_info['server_type'] == SERVER_TYPE_OSB_NETWARE) continue; if ($protocol_key == SHARE_FS_PROTOCOL_NCPFS && $server_info['server_type'] == SERVER_TYPE_OSB_NETWARE && empty($field_data)) continue;
This will display the correct contents without a problem. The only thing else that I need to be able to achieve is saving information to the database. So the select name is 'type' which is what the $key will save to, which does without a problem. However, I have another column in my database ('protocol_type') that I need to be able to save the value to as well if they have chosen SHARE_TYPE_FS. If they don't choose SHARE_TYPE_FS, I could save the value as 0 or null...but I just don't know where I could include this code to do so.
I should add that in order to save they 'type' I can do so because it is named on the select (my save function will save it based on grabbing it because it is part of the field data)
I also could be doing something completely wrong or out of the norm, so if you noticed anything feel free to tell me if I should be doing something another way or if it is a bad idea.
Bookmarks