 <?php 
if (!isset($_SESSION)){
  session_start();
}
include('accesscheck2.php');
require_once 'Connections/courier.php';
require_once 'functions/functions.php';

if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 
{
  if (PHP_VERSION < 6) {
    $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
  }

  $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);

  switch ($theType) {
    case "text":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;    
    case "long":
    case "int":
      $theValue = ($theValue != "") ? intval($theValue) : "NULL";
      break;
    case "double":
      $theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
      break;
    case "date":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;
    case "defined":
      $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
      break;
  }
  return $theValue;
}
}
$query = mysql_query("SELECT * FROM sms_templates", $courier);

?>  
   <style type="text/css">
 table tbody tr:hover {
            cursor: pointer;
        }
        .form-control-mine{
            color: #333333;
background-color: #ffffff;
border: 1px solid #e5e5e5;
padding: 3px 8px;
font-size: 14px;}
    </style>
    
    <ul class="page-breadcrumb breadcrumb" id="next_previous_id">
    <li class="btn-group">
                <button style="height: 35px;" type="button" class="btn green dropdown-toggle" data-toggle="dropdown" data-hover="dropdown" data-delay="1000" data-close-others="true">
                    <span>Menu</span> <i class="icon-angle-down"></i>
                </button>
        <ul class="dropdown-menu pull-right" role="menu">
                   <li onclick="getstep('sms_templates');"><a href="#"><i class="icon-refresh"></i> Refresh </a></li>
                   <li onclick="process_information_sms('sms/sms_step.php', 'add_sms_template', 'sms_templates_wrapper')"><a href="#"><i class="icon-plus"></i> Add New SMS Template </a></li>
                   <li onclick="getstep('sms_page');"><a href="#"><i class="icon-envelope-alt"></i> SMS Page </a></li>
                </ul>
            </li>
        </ul>



        <div class="page-bar">
    <ul class="page-breadcrumb">
        <li>
            <i class="icon-home"></i>
            <a href="index.html">Home</a>
            <i class="fa fa-angle-right"></i>
        </li>
        <li>
            <span>Dashboard</span>
        </li>
    </ul>
    <div class="page-toolbar">
        <div class="btn-group pull-right">
            <button type="button" class="btn btn-fit-height grey-salt dropdown-toggle" data-toggle="dropdown" data-hover="dropdown" data-delay="1000" data-close-others="true"> Actions
                <i class="fa fa-angle-down"></i>
            </button>
            <ul class="dropdown-menu pull-right" role="menu">
                <li onclick="getstep('sms_templates');">
                    <a href="#">
                        <i class="icon-refresh"></i> Refresh</a>
                    </li>
                    <li onclick="process_information_sms('sms/sms_step.php', 'add_sms_template', 'sms_templates_wrapper');">
                    <a href="#">
                        <i class="icon-plus"></i> Add New SMS Template</a>
                    </li>
                    <li onclick="getstep('sms_page');">
                        <a href="#">
                            <i class="icon-envelope-alt"></i> SMS Page</a>
                        </li>

                    </ul>
                </div>
            </div>
        </div>
        <br><br>


    <form name="form" style="" onsubmit="process_information_sms('sms/sms_step.php','save_sms_template','');return false;">
<div class="row" style="margin-top: -20px">
    <div class="col-md-12">
        <div class="portlet blue box">
            <div class="portlet-title" style="background-color: #32c5d2 !important">
                <div class="caption"><i class="icon-envelope"></i>SMS Templates Editor</div>
                <div class="tools">
                    <a href="javascript:;" class="collapse"></a>
                </div>
            </div>
            <div class="portlet-body">
                <div class="row">
                    <div class="col-md-3">
                    <table class="table table-hover table-responsive">
                    <tbody>
                        <?php $i=1; while($row = mysql_fetch_assoc($query)){ ?>
                        <tr id="sms_template_rw_<?php echo $row['id'];?>">
                            <td onclick="process_information_sms('sms/sms_step.php', 'get_sms_template', 'sms_templates_wrapper', '<?php echo $row['id'];?>')"><?php echo $i.'. '. $row['title']; ?></td>
                            <td style="width"><i onclick="delete_sms_template('sms/sms_step.php', 'delete_sms_template', '<?php echo $row['id'];?>', 'You want to Delete this SMS Template.')" style="color:red;" class="icon-trash"></i></td>
                        </tr>
                        <?php $i++; } ?>
                    </tbody>
                </table> 
                </div>
                <div class="col-md-9" id="sms_templates_wrapper">
                      <table class="table table-striped table-bordered table-hover table-responsive">
                    <tbody>
                        <tr>
                            <td style="width:15%">Title / Name</td>
                            <td>
                                <input class="form-control" type="text" name="title" id="title">
                            </td>
                        </tr>
                        <tr>
                            <td style="width:15%">Delivery Method</td>
                            <td>
                                <select onchange="if(this.value == 'Automated'){$('#repeat_wrapper').show();}else{$('#repeat_wrapper').hide();}" class="form-control" name="delivery_method" id="delivery_method">
                                    <option value="">Please Select</option>
                                    <option <?php if($row['delivery_method'] == 'Manual'){echo 'selected=""';} ?> value="Manual">Manual</option>
                                    <option <?php if($row['delivery_method'] == 'Automated'){echo 'selected=""';} ?> value="Automated">Automated</option>
                                </select>
                            </td>
                        </tr>
                        <tr id="repeat_wrapper" style="display: none;">
                            <td>Date</td>
                            <td>
                                <input type="text" name="date_time" id="date_time" class="form-control" readonly="" placeholder="Click Me">
                                <select class="form-control" name="repeat_method" id="repeat_method">
                                    <option <?php if($row['repeat_duration'] == 'No'){echo 'selected=""';} ?> value="No">No Repeat</option>
                                    <option <?php if($row['repeat_duration'] == 'Year'){echo 'selected=""';} ?> value="Year">Every Year</option>
                                    <option <?php if($row['repeat_duration'] == 'Month'){echo 'selected=""';} ?> value="Month">Every Month</option>
                                    <option <?php if($row['repeat_duration'] == 'Week'){echo 'selected=""';} ?> value="Week">Every Week</option>
                                    <option <?php if($row['repeat_duration'] == 'Day'){echo 'selected=""';} ?> value="Day">Every Day</option>
                                </select>
                            </td>
                        </tr> 
                        <tr>
                            <td>Message</td>
                            <td>
                                <b onclick="addtosms_replace('[First name]')"> [First name] </b> --
                                <b onclick="addtosms_replace('[Last name]')"> [Last name] </b> --
                                <b onclick="addtosms_replace('[Full name]')"> [Full name] </b> -- 
                                <b onclick="addtosms_replace('[Patient No]')"> [Patient No] </b> 
                                <?php if($row['title']=='BIRTHDAY WISHES'){ ?>
                                -- <b onclick="addtosms_replace('[Age]')"> [Age] </b>
                                <?php } ?>
                                <br><br>
                                <textarea required="" name="msg" class="form-control" style="height:150px;resize: none;" id="msg" onkeyup="SMSCounter(this.value.length)" onkeypress="SMSCounter(this.value.length)"><?php echo $row['sms_template'];?></textarea>
                                <p>
                                    <span id="remaining" style="font-weight: bold;color: deepskyblue" >160 characters remaining</span>
                                    <span id="" style="font-weight: bold;color:#000" > || </span>
                                    <span id="messages" style="font-weight: bold;color: deepskyblue" >1 message(s)</span>
                                    <span id="" style="font-weight: bold;color: deepskyblue;float: right" >160 / per sms</span>
                                </p>
                            </td>
                        </tr>
                        <tr>
                            <td></td>
                            <td>
                                <button type="submit" class="btn green">
                                    Save Template <i class="icon-ok"></i>
                                </button>            
                            </td>
                        </tr>
                    </tbody>
                </table> 
                </div>
                </div>
            </div>
        </div>
    </div>
         </div>
    </form>
   