--- wancfg_zaptel.pl	2009-03-18 09:55:51.000000000 -0400
+++ ../wancfg_zaptel_new/wancfg_zaptel.pl	2009-03-17 19:21:54.000000000 -0400
@@ -612,9 +625,12 @@
 			if ( ! -d "$wanpipe_conf_dir/scripts" ) {
 				exec_command("mkdir -p $wanpipe_conf_dir/scripts");
 			} 
-						
 			exec_command("cp -f $current_dir/templates/$zaptel_cfg_script $wanpipe_conf_dir/scripts/start");
-			
+		} elsif(-e "$wanpipe_conf_dir/scripts/start") {
+				print ("\nWould you like to remove old wanrouter start scripts ?\n");
+				if (&prompt_user_list("YES","NO","") eq 'YES'){
+					exec_command("rm -rf $wanpipe_conf_dir/scripts/start");
+				}
 		}
 	}
 }
@@ -698,11 +714,55 @@
 					"Save cfg: Restart Asterisk & Wanpipe when convenient",
 					"Save cfg: Stop Asterisk & Wanpipe now", 
 					"Save cfg: Stop Asterisk & Wanpipe when convenient",
+					"Save cfg: Save cfg only", 
 					"Do not save cfg: Exit",
 					"");
 	}
 
 	
+	if ($res =~ m/cfg only/){
+		
+
+		print "\nRemoving old configuration files...\n";
+
+        	exec_command("rm -f $wanpipe_conf_dir/wanpipe*.conf");
+
+        	gen_wanrouter_rc();
+
+        	print "\nCopying new Wanpipe configuration files...\n";
+        	copy_config_files();
+        	if($num_bri_devices != 0){
+                	print "\nCopying new sangoma_brid configuration files ($bri_conf_file_t)...\n";
+                	exec_command("cp -f $bri_conf_file $bri_conf_file_t");
+                	exec_command("cp -f $woomera_conf_file $woomera_conf_file_t");
+        	}
+        	if ($zaptel_dahdi_installed==$TRUE){
+                	if($config_zaptel==$TRUE){
+                        	if ($num_zaptel_config !=0){
+                                	print "\nCopying new $zaptel_string configuration file ($zaptel_conf_file_t)...\n";
+                                	exec_command("cp -f $zaptel_conf_file $zaptel_conf_file_t");
+                        	}
+                	}
+        	}
+
+        	if ($config_zapata==$TRUE || $is_trixbox==$TRUE){
+                	if ($num_zaptel_config !=0){
+                        	print "\nCopying new $zapata_string configuration files ($zapata_conf_file_t)...\n";
+                        	exec_command("cp -f $zapata_conf_file $zapata_conf_file_t");
+                	}
+        	}
+                print "Saving files only\n";
+
+		if ($os_type_list =~ m/FreeBSD/){
+        	config_boot_freebsd();
+		} else {
+        		config_boot_linux();
+			}
+
+                exit 0;
+	}
+
+
 	if ($res =~ m/Exit/){
 		print "No changes made to your configuration files\n";
 		exit 0;
@@ -748,10 +808,6 @@
 				}
 			}
 
-
-
-
-
 		}else {
 			print "\nAsterisk is not running...\n";
 		}
@@ -902,7 +958,7 @@
 		@options = ("PSTN", "INTERNAL");
 	}
 	if ($silent==$FALSE){
-		printf ("Select dialplan context for AFT-%s on port %s\n", get_card_name($card_model), $card_port);
+		printf ("Select dialplan context for AFT-A%s on port %s\n", get_card_name($card_model), $card_port);
 		my $res = &prompt_user_list(@options,$def_zapata_context);
 		if($res eq "PSTN"){
 			$context="from-zaptel";
@@ -1005,7 +1061,7 @@
 	#update comments for zapata.conf or chan_dahdi.conf
 	my $zapfile="";
 	if (!open (FH,"$zapata_conf_file")) {
-# 		printf("Unable to modify $zapata_conf_file\n");
+		printf("Unable to modify $zapata_conf_file\n");
 		
 	}
 	while (<FH>) {
@@ -1734,6 +1793,13 @@
 						$num_bri_devices++;
 						$card->tdmv_span_no($current_tdmapi_span);
 						$current_tdmapi_span++;
+						if ($silent==$FALSE){
+							if ($card->hwec_mode eq "YES"){
+								$card->hw_dtmf(&prompt_hw_dtmf());
+							} else {
+								$card->hw_dtmf("NO");
+							}
+						}
 					}else{
 						printf ("%s on slot:%s bus:%s port:%s not configured\n", 												get_card_name($card->card_model), $3, $4, $5);
 						prompt_user("Press any key to continue");
@@ -1794,14 +1860,14 @@
 					$current_bri_default_tei=$def_bri_default_tei;
 				}
 				printf("\nConfiguring span:%s as TEI:%s\n", $bri_pos, $current_bri_default_tei);
-                                if($silent==$FALSE){
-                                        my @options = ("YES - Keep this setting", "NO  - Specify a different TEI");
-                                        my $res = &prompt_user_list(@options, "YES");
-                                        if ($res =~ m/NO/) {
-                                                $def_bri_default_tei_opt=$TRUE;
-                                                $current_bri_default_tei=get_bri_default_tei();	
-                                        }
-                                }
+  				if($silent==$FALSE){
+					my @options = ("YES - Keep this setting", "NO  - Specify a different TEI");
+					my $res = &prompt_user_list(@options, "YES");
+					if ($res =~ m/NO/) {
+						$def_bri_default_tei_opt=$TRUE;
+						$current_bri_default_tei=get_bri_default_tei();
+						}
+				}
 				if ($def_bri_default_tei_opt==$FALSE){
 					$bri_conf.=$a50x->gen_bri_conf($bri_pos,"bri_te", $group, $country, $operator, $conn_type, '');
 				} else { 
@@ -2333,6 +2399,7 @@
 				if($silent==$FALSE){
 					my @options = ("NORMAL", "MASTER");
 					printf ("Select clock for AFT-%s on port %s [slot:%s bus:%s span:$devnum]\n", get_card_name($card->card_model), $port, $card->pci_slot, $card->pci_bus);
+
 					$def_feclock=&prompt_user_list(@options, $def_feclock);
 				} else {
 					if($#silent_feclocks >= 0){
@@ -2358,28 +2425,7 @@
 					$def_te_ref_clock=&get_te_ref_clock(@device_normal_clocks);
 					$a10x->te_ref_clock($def_te_ref_clock);
 				}
-
-
 								
-				if ($silent==$FALSE){
-					if ($card->hwec_mode eq "YES"){
-						$card->hw_dtmf(&prompt_hw_dtmf());
-					} else {
-						$card->hw_dtmf("NO");
-					}
-				} else {
-					if($#silent_hwdtmfs >= 0){
-						$silent_hwdtmf=pop(@silent_hwdtmfs);
-					}
-					if ($card->hwec_mode eq "YES" && $no_hwdtmf==$FALSE){
-						$card->hw_dtmf($silent_hwdtmf);
-					} else {
-						$card->hw_dtmf("NO");
-					}
-				} 
-
-
-				
 				my @options="";	
 				if ($is_smg==$TRUE && $zaptel_dahdi_installed==$TRUE){
 					@options = ("PRI CPE", "PRI NET", "E & M", "E & M Wink", "FXS - Loop Start", "FXS - Ground Start", "FXS - Kewl Start", "FX0 - Loop Start", "FX0 - Ground Start", "FX0 - Kewl Start", "SS7 - Sangoma Signal Media Gateway", "No Signaling (Voice Only)");
@@ -2604,6 +2650,30 @@
 						$a10x->pri_switchtype($silent_pri_switchtype);
 					}
 				}
+
+				# prompt the user if they would like to enable HW DTMF...HW_DTMF needs to be disabled for SMG
+				if (!($a10x->signalling eq 'SS7 - Sangoma Signal Media Gateway'| $a10x->signalling eq 'No Signaling (Voice Only)')){
+					if ($silent==$FALSE){
+						printf("\n");
+						if ($card->hwec_mode eq "YES"){
+							$card->hw_dtmf(&prompt_hw_dtmf());
+						} else {
+							$card->hw_dtmf("NO");
+						}
+					} else {
+						if($#silent_hwdtmfs >= 0){
+							$silent_hwdtmf=pop(@silent_hwdtmfs);
+						}
+						if ($card->hwec_mode eq "YES" && $no_hwdtmf==$FALSE){
+							$card->hw_dtmf($silent_hwdtmf);
+						} else {
+							$card->hw_dtmf("NO");
+						}
+					}
+				}else{
+					$card->hw_dtmf("NO");
+				} 
+
 				#wanpipe gen section		
 				if( $a10x->signalling eq 'SS7 - Sangoma Signal Media Gateway' ){
 					$a10x->ss7_subinterface(1);
@@ -2731,17 +2801,17 @@
 				}elsif ($is_tdm_api == $FALSE && $is_hp_tdm_api == $FALSE ){
 					$zaptel_conf.=$a10x->gen_zaptel_conf($dchan_str);
 				}
-					$devnum++;
-					$num_digital_devices++;
-					my $msg ="\nPort ".$port." on AFT-A".$card->card_model." configuration complete...\n";
-					print "$msg";
-					if($silent==$FALSE){
-						prompt_user("Press any key to continue");
-					}
 
-				}  	
-	
+				# done with this port time to move on to the next port
+				$devnum++;
+				$num_digital_devices++;
+				my $msg ="\nPort ".$port." on AFT-A".$card->card_model." configuration complete...\n";
+				print "$msg";
+				if($silent==$FALSE){
+					prompt_user("Press any key to continue");
+				}
 
+				}				
 			} 
 
 		}
