#!/bin/bash

# Title:   qpage_menu.bash
# Purpose: shell script to setup a menu for sendign send snpp pages 
# Pagers:  adj		1735446
#	   pager5798	5104485798
#	   pager6348	5104486348

# qpage configuration file:  
#      /etc/qpage.servers
#          snpp.airtouch.com:4444
#          snpp.skytel.com:7777

# basic command syntax: /usr/local/bin/qpage  -p5104486348 "test"

function host_menu {
BOLD=$(tput smso)
NOBOLD=$(tput rmso)
while true
do
        clear
        cat <<- ENDMENU

    ${BOLD}Send A SNPP Page (v..00000001)${NOBOLD}
	  
  ${BOLD}Choice${NOBOLD}      ${BOLD}Person${NOBOLD}		${BOLD}Number${NOBOLD}
    1         Anthony		1735446
    2         Adrian		5104485798
    3         David or John	5104486348
    4         all		all
    
    Choose 1-4, or any other key to exit.

	ENDMENU

valid_pager
enter_message
send_page

done
}

# ask them for the pager and check to see if it is valid
function valid_pager {
    #PS3old="$PS3"
    #PS3="Choose Pager: "
    echo -e "Choose Pager: \c"
    read Choice    

    case "$Choice"
    in
        1 ) 	echo "Pagging adj"
	    	export Pagger="1735446";;
	2 )	echo "Pagging Adrian"
		export Pagger="5104485798";;
	3 )	echo "Pagging David or John"
		export Pagger="5104486348";;
	4 )	echo "Pagging everyone"
		export Pagger="1735446, 5104485798, 5104486348";;
		
	* )     echo "You selected $1, exiting program."
		exit 0;;
    esac
     # Return the Prompt
     #PS3="$PS3old"
     return
}

function enter_message {
   echo "Pelease type your message."
   echo "Abort with ctrl-c."
   read Message
}

function send_page {
   if ( /usr/local/bin/qpage  -p"$Pagger" "$Message" )
   then 
       echo "message sent successfully"
       sleep 2
   else
       echo "error sednding message: $0"
   fi   
}
host_menu 
