<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');
global $configverssion_id; global $configapp_version; global $userID; global $server; global $LANG; 
$resellerID = getReseller();
//=== List page stuffs =============
$page = 1; $setLimit = 30;
if(isset($_GET["page"])) $page = (int)$_GET["page"];
$pageLimit = ($page * $setLimit) - $setLimit; 
$pageurl=$_SERVER['REQUEST_URI']."?";
if(count($_GET)) { $pageurl = $_SERVER['REQUEST_URI'].'&'; }
$trans = array("s=d_o" => "", "s=d_n" => "", "s=r_h" => "", "s=r_l" => "", "s=s_r" => "", "s=s_u" => "", "s=s_q" => "", "s=s_c" => "", "s=s_f" => "", "s=s_p" => "");
$pageurl = strtr($pageurl,$trans);
$pageurl = str_replace('&&','&',$pageurl);
//====End ==============
define('TITLE','API');
if(userRole()>2) {
	header('location: index.php');	
}
$today = date('Y-m-d'); $time = strtotime($today.'-1 months'); $lastMonth = date("Y-m", $time); $time = strtotime($today.'-1 years'); $lastYear = date("Y", $time);
?>
<?php hasModulePermission('view api')?>
<div class="row no-m-t no-m-b">
 	<div class="col s12 m12 l12">
        <div class="card">
            <div class="card-content"><?=$LANG['aapi_intro']?></div>
        </div>
    </div>
 </div>

 <div class="row no-m-t no-m-b">
     <div class="col s12 m6 l6">  
         <div class="card card-white">
             <div class="card-content">  
                    <span class="card-title"><?=$LANG['API Endpoint']?></span> 
                    <table class="highlight">               
                    	<tr>
                        	<td><strong><?=$LANG['HTTP URL']?></strong></td>
                            <td><a><?=home_base_url().'smsAPI'?></a></td>
                        </tr>
                        <tr>
                        	<td><strong><?=$LANG['HTTP Method']?></strong></td>
                            <td><?=$LANG['POST or GET']?></td>
                        </tr>
                    </table>
             </div>
         </div>  
     </div>           
     <div class="col s12 m6 l6">  
         <div class="card card-white">
             <div class="card-content">  
                    <span class="card-title"><?=$LANG['My API Credentails']?> 
                    <?php if(!empty(userData($userID,'api_key')) || !empty(userData($userID,'api_token'))) { ?>      
                    <a id="apis-button" class="btn blue right" href="#"><?=$LANG['Generate New Key']?></a> 
                    <span id="apis-spin" class="btn-flat" style="display: none;"><i class="fa fa-spinner fa-spin"></i> <strong><?=$LANG['Please wait']?>...</strong></span>
                    <?php } ?>
                    </span>    
              <?php if(empty(userData($userID,'api_key')) || empty(userData($userID,'api_token'))) { ?>      
                    <div class="card deep-orange accent-1">
                        <div class="card-content white-text"><?=$LANG['aenable_api']?></div>
                    </div>
                    <button id="api-button" class="btn green darken-4"><i class="fa fa-check"></i> <?=$LANG['Enable API Access']?> </button>
                     <span id="api-spin" class="btn-flat" style="display: none;"><i class="fa fa-spinner fa-spin"></i> <strong><?=$LANG['Please wait']?>...</strong></span>
              <?php } else { ?>      
                     <table class="highlight">               
                    	<tr>
                        	<td><strong><?=$LANG['API Key']?></strong></td>
                            <td><?=userData($userID,'api_key')?></td>
                        </tr>
                        <tr>
                        	<td><strong><?=$LANG['API Token']?></strong></td>
                            <td><?=userData($userID,'api_token')?></td>
                        </tr>
                    </table>   
              <?php } ?>               
             </div>
         </div>  
     </div> 
 </div>
  <?php if(!empty(userData($userID,'api_key')) ) { ?>   
  <div class="row no-m-t no-m-b">    
     <div class="col s12 m12 l12">  
          <div class="card card-white">
             <div class="card-content">  
               <div class="row no-m-t no-m-b">   
                 <div class="col s12 m6 l5">  
                 <span class="card-title"><?=$LANG['White-Listed IP Addresses']?> </span>
                 <p class="blue-text"><?=$LANG['Enter a comma separated list of IP addresses you want to allow access to your API credentials<br>Leave empty to disable this feature']?></p>
                 </div>
                 <div class="col s12 m6 l7">  
                     <div class="input-field col s12">
                            <textarea id="ip_addresses" class="materialize-textarea" length="1960"><?=v3updates20200401_GETLISTIP($userID)?></textarea>
                            <label for="ip_addresses"><?=$LANG['White-listed IP addresses']?></label>
                    </div>
                     <button id="ips-button" class="btn green darken-4" type="submit"><i class="fa fa-save"></i> <?=$LANG['Save Settings']?> </button>
                        <span id="ips-spin" class="btn-flat" style="display: none;"><i class="fa fa-spinner fa-spin"></i> <strong><?=$LANG['Please wait']?>...</strong></span>
                 </div>
 				
                </div>                
             </div>
          </div>
     </div>            
 </div> 
 <?php } ?>   
 
 <div class="row no-m-t no-m-b">    
     <div class="col s12 m12 l12"> 
         <div class="card card-white">
             <div class="card-content "> 
             	<!-- api set-->
                <h5><?=$LANG['Create User Account']?></h5>
                <h6 class="green-text"><strong><?=$LANG['Sample Request']?></strong></h6>
				<ul class="collection s12 m6 l6">
                    <li class="collection-item"><a><?=home_base_url().'smsAPI'?>?auth&adminapikey=Your_ADMIN_API_KEY&adminapitoken=YOUR_ADMIN_API_TOKEN&first_name=CUSTOMER_FIRST_NAME&last_name=email=CUSTOMER_EMAIL&password=CUSTOMER_PASSWORD&phone=CUSTOMER_PHONE </a> </li>
                </ul>
                <h6 class="green-text"><strong><?=$LANG['Parameters']?></strong></h6>
				<ul class="collection s12 m6 l6">
                    <li class="collection-item"><a>adminapikey</a>: <?=$LANG['Supper Admin API Key']?> <span class="red-text">(<?=$LANG['required']?>)</span></li>
                    <li class="collection-item"><a>adminapitoken</a>: <?=$LANG['Supper Admin API Token']?> <span class="red-text">(<?=$LANG['required']?>)</span></li>
                    <li class="collection-item"><a>first_name</a>: <?=$LANG['Customer\'s First Name']?> <span class="red-text">(<?=$LANG['required']?>)</span></li>
                    <li class="collection-item"><a>last_name</a>: <?=$LANG['Customer\'s Last Name']?> <span class="red-text">(<?=$LANG['required']?>)</span></li>
                    <li class="collection-item"><a>phone</a>: <?=$LANG['Customer\'s Phone Number']?> <span class="red-text">(<?=$LANG['required']?>)</span></li>
                    <li class="collection-item"><a>username</a>: <?=$LANG['Customer\'s Email Address']?> <span class="red-text">(<?=$LANG['required']?>)</span></li>
                    <li class="collection-item"><a>password</a>: <?=$LANG['Customer\'s Password']?> <span class="red-text">(<?=$LANG['required']?>)</span></li>
                </ul>	
                <h6 class="green-text"><strong><?=$LANG['Sample Success Response (JSON)']?></strong></h6>
				<ul class="collection s12 m6 l6">
                    <li class="collection-item">
                    <pre>
                    {
                        "id": "123"
                        "request": "createcustomer",
                        "status": "success",
                        "first_name": "John",
                        "last_name": "Smith",
                        "email": "jsmith@example.com",
                        "phone": "1234567890"
                    }   
                    </pre>
                    </li>
                </ul>
                <h6 class="green-text"><strong><?=$LANG['Sample Error Response (JSON)']?></strong></h6>
				<ul class="collection s12 m6 l6">
                    <li class="collection-item">
                    <pre>
                    {
                        "request": "createcustomer",
                        "status": "error",
                        "message": "Email Already Exist"
                    }   
                    </pre>
                    </li>
                </ul>
                
                <!-- api set-->
                <h5><?=$LANG['Authenticating User Account']?></h5>
                <h6 class="green-text"><strong><?=$LANG['Sample Request']?></strong></h6>
				<ul class="collection s12 m6 l6">
                    <li class="collection-item"><a><?=home_base_url().'smsAPI'?>?auth&adminapikey=Your_ADMIN_API_KEY&adminapitoken=YOUR_ADMIN_API_TOKEN&username=CUSTOMER_EMAIL&password=CUSTOMER_PASSWORD </a> </li>
                </ul>
                <h6 class="green-text"><strong><?=$LANG['Parameters']?></strong></h6>
				<ul class="collection s12 m6 l6">
                    <li class="collection-item"><a>adminapikey</a>: <?=$LANG['Supper Admin API Key']?> <span class="red-text">(<?=$LANG['required']?>)</span></li>
                    <li class="collection-item"><a>adminapitoken</a>: <?=$LANG['Supper Admin API Token']?> <span class="red-text">(<?=$LANG['required']?>)</span></li>
                    <li class="collection-item"><a>username</a>: <?=$LANG['Customer\'s Email Address']?> <span class="red-text">(<?=$LANG['required']?>)</span></li>
                    <li class="collection-item"><a>password</a>: <?=$LANG['Customer\'s Password']?> <span class="red-text">(<?=$LANG['required']?>)</span></li>
                </ul>	
                <h6 class="green-text"><strong><?=$LANG['Sample Success Response (JSON)']?></strong></h6>
				<ul class="collection s12 m6 l6">
                    <li class="collection-item">
                    <pre>
                    {
                        "request": "auth",
                        "status": "success",
                        "first_name": "John",
                        "last_name": "Smith",
                        "email": "jsmith@example.com",
                        "phone": "1234567890",
                        "apikey": "xxxxxxxxxxxxxxxxxxxxxxxxxxxx",
                        "apitoken": "xxxxxxxxxxxxxxxxxxxxxxxxxxx"
                    }   
                    </pre>
                    </li>
                </ul>
                <h6 class="green-text"><strong><?=$LANG['Sample Error Response (JSON)']?></strong></h6>
				<ul class="collection s12 m6 l6">
                    <li class="collection-item">
                    <pre>
                    {
                        "request": "auth",
                        "status": "error",
                        "message": "Incorrect Login Credentails"
                    }   
                    </pre>
                    </li>
                </ul>
                
                <!-- api set-->
                <h5><?=$LANG['Sending SMS']?></h5>
                <h6 class="green-text"><strong><?=$LANG['Sample Request']?></strong></h6>
				<ul class="collection s12 m6 l6">
                    <li class="collection-item"><a><?=home_base_url().'smsAPI'?>?sendsms&apikey=Your_API_KEY&apitoken=YOUR_API_TOKEN&type=sms&from=SENDERID&to=123456&text=My+first+text&scheduledate=<?=date('Y-m-d H:i:s')?>&route=0 </a> </li>
                </ul>
                <h6 class="green-text"><strong><?=$LANG['Parameters']?></strong></h6>
				<ul class="collection s12 m6 l6">
                    <li class="collection-item"><a>apikey</a>: <?=$LANG['You unique API Key']?> <span class="red-text">(<?=$LANG['required']?>)</span></li>
                    <li class="collection-item"><a>apitoken</a>: <?=$LANG['You unique API Token']?> <span class="red-text">(<?=$LANG['required']?>)</span></li>
                    <li class="collection-item"><a>type</a>: <?=$LANG['Message Type']?> <strong><?=$LANG['Eg. sms, voice, unicode, flash, mms, whatsapp (default is sms)']?> </strong> <span class="red-text">(<?=$LANG['required']?>)</span></li>
                    <li class="collection-item"><a>from</a>: <?=$LANG['Your Sender ID']?> <span class="red-text">(<?=$LANG['required']?>)</span></li>
                    <li class="collection-item"><a>to</a>: <?=$LANG['Destination Number (country code)']?> <span class="red-text">(<?=$LANG['required']?>)</span></li>
                    <li class="collection-item"><a>text</a>: <?=$LANG['Your message text (url encoded)']?> <span class="red-text">(<?=$LANG['required for sms, unicode, flash']?>)</span></li>
                    <li class="collection-item"><a>file</a>: <?=$LANG['Voice file URL (for voice message) or Multimedia file URL (for mms or whatsapp message)']?> <span class="purple-text">(<?=$LANG['optional']?>)</span></li>
                    <li class="collection-item"><a>language</a>: <?=$LANG['Language of voice message']?> <span class="red-text">(<?=$LANG['required for text-to-speach']?>)</span></li>
                    <li class="collection-item"><a>duration</a>: <?=$LANG['Duration of your voice message in seconds']?> <span class="red-text">(<?=$LANG['required for voice']?>)</span></li>
                    <li class="collection-item"><a>scheduledate</a>: <?=$LANG['Date and Time to send message (YYYY-MM-DD HH:mm:ss)']?> <span class="purple-text">(<?=$LANG['optional']?>)</span></li>
                    <li class="collection-item"><a>route</a>: <?=$LANG['ID of gateway/route to use for the message. Set to 0 to use system default routing rules']?> <span class="red-text">(<?=$LANG['optional']?>)</span></li>                    
                </ul>	
                <h6 class="green-text"><strong><?=$LANG['Sample Success Response (JSON)']?></strong></h6>
				<ul class="collection s12 m6 l6">
                    <li class="collection-item">
                    <pre>
                    {
                        "request": "sendsms",
                        "status": "queued",
                        "group_id": "1234",
                        "date": "<?=date('Y-m-d H:i:s')?>"
                    }   
                    </pre>
                    </li>
                </ul>
                <h6 class="green-text"><strong><?=$LANG['Sample Error Response (JSON)']?></strong></h6>
				<ul class="collection s12 m6 l6">
                    <li class="collection-item">
                    <pre>
                    {
                        "request": "sendsms",
                        "status": "error",
                        "message": "Sender ID not allowed"
                    }   
                    </pre>
                    </li>
                </ul>
                
                <!-- api set-->
                <h5><?=$LANG['Check SMS Status']?></h5>
                <h6 class="green-text"><strong><?=$LANG['Sample Request']?></strong></h6>
				<ul class="collection s12 m6 l6">
                    <li class="collection-item"><a><?=home_base_url().'smsAPI'?>&groupstatus&apikey=Your_API_KEY&apitoken=YOUR_API_TOKEN&groupid=1234 </a></li>
                </ul>
                <h6 class="green-text"><strong><?=$LANG['Parameters']?></strong></h6>
				<ul class="collection s12 m6 l6">
                	<li class="collection-item"><a>apikey</a>: <?=$LANG['You unique API Key']?> <span class="red-text">(<?=$LANG['required']?>)</span></li>
                    <li class="collection-item"><a>apitoken</a>: <?=$LANG['You unique API Token']?> <span class="red-text">(<?=$LANG['required']?>)</span></li>
                    <li class="collection-item"><a>groupid</a>: <?=$LANG['The group_id returned by sendsms request']?> <span class="red-text">(<?=$LANG['required']?>)</span></li>
                </ul>	
                <h6 class="green-text"><strong><?=$LANG['Sample Success Response (JSON)']?></strong></h6>
				<ul class="collection s12 m6 l6">
                    <li class="collection-item">
                    <pre>
                    {
                        "request": "groupstatus",
                        "status": "success",
                        "group_id": "1234",
                        "group_status": "sent",
                        "recipients": [
                            {
                                "id": "21",
                                "to": "231235433",
                                "status": "failed"
                            },
                            {
                                "id": "22",
                                "to": "4471235433",
                                "status": "sent"
                            },
                            {
                                "id": "25",
                                "to": "1871235433",
                                "status": "queued"
                            }
                        ],
                        "date": "<?=date('Y-m-d H:i:s')?>"
                    }   
                    </pre>
                    </li>
                </ul>
                <h6 class="green-text"><strong><?=$LANG['Sample Error Response (JSON)']?></strong></h6>
				<ul class="collection s12 m6 l6">
                    <li class="collection-item">
                    <pre>
                    {
                        "request": "groupstatus",
                        "status": "error",
                        "message": "Error message",
                    }   
                    </pre>
                    </li>
                </ul>
                
                 <!-- api set-->
                <h5><?=$LANG['Read SMS Inbox']?></h5>
                <h6 class="green-text"><strong><?=$LANG['Sample Request']?></strong></h6>
				<ul class="collection s12 m6 l6">
                    <li class="collection-item"><a><?=home_base_url().'smsAPI'?>?getinbox&apikey=Your_API_KEY&apitoken=YOUR_API_TOKEN&list=unread </a></li>
                </ul>
                <h6 class="green-text"><strong><?=$LANG['Parameters']?></strong></h6>
				<ul class="collection s12 m6 l6">
                	<li class="collection-item"><a>apikey</a>: <?=$LANG['You unique API Key']?> <span class="text-red"><span class="red-text">(<?=$LANG['required']?>)</span></span></li>
                    <li class="collection-item"><a>apitoken</a>: <?=$LANG['You unique API Token']?> <span class="red-text">(<?=$LANG['required']?>)</span></li>
                    <li class="collection-item"><a>list</a>: <?=$LANG['"all" will return all messages while "unread" will return only unread messages (default is unread)']?> <span class="purple-text">(<?=$LANG['optional']?>)</span></li>
                </ul>	
                <h6 class="green-text"><strong><?=$LANG['Sample Success Response (JSON)']?></strong></h6>
				<ul class="collection s12 m6 l6">
                    <li class="collection-item">
                    <pre>
                    {
                        "request": "getinbox",
                        "status": "success",
                        "inbox": [
                            {
                                "id": "12",
                                "from": "123456789",
                                "to": "2347015272",
                                "message": "Hi. This is message 1",
                                "date": "<?=date('Y-m-d H:i:s')?>"
                            },
                            {
                                "id": "26",
                                "from": "447882892",
                                "to": "2347015272",
                                "message": "Hi again. This is message 2",
                                "date": "<?=date('Y-m-d H:i:s')?>"
                            }
                       ]
                    }   
                    </pre>
                    </li>
                </ul>
                <h6 class="green-text"><strong><?=$LANG['Sample Error Response (JSON)']?></strong></h6>
				<ul class="collection s12 m6 l6">
                    <li class="collection-item">
                    <pre>
                    {
                        "request": "getinbox",
                        "status": "error",
                        "message": "Error",
                    }   
                    </pre>
                    </li>
                </ul>
                
                 <!-- api set-->
                <h5><?=$LANG['Credit Balance']?></h5>
                <h6 class="green-text"><strong><?=$LANG['Sample Request']?></strong></h6>
				<ul class="collection s12 m6 l6">
                    <li class="collection-item"><a><?=home_base_url().'smsAPI'?>?balance&apikey=Your_API_KEY&apitoken=YOUR_API_TOKEN </a></li>
                </ul>
                <h6 class="green-text"><strong><?=$LANG['Parameters']?></strong></h6>
				<ul class="collection s12 m6 l6">
                	<li class="collection-item"><a>apikey</a>: <?=$LANG['You unique API Key']?> <span class="red-text">(<?=$LANG['required']?>)</span></li>
                    <li class="collection-item"><a>apitoken</a>: <?=$LANG['You unique API Token']?> <span class="red-text">(<?=$LANG['required']?>)</span></li>
                </ul>	
                <h6 class="green-text"><strong><?=$LANG['Sample Success Response (JSON)']?></strong></h6>
				<ul class="collection s12 m6 l6">
                    <li class="collection-item">
                    <pre>
                    {
                        "balance": "12345"
                    }   
                    </pre>
                    </li>
                </ul>
                <h6 class="green-text"><strong><?=$LANG['Sample Error Response (JSON)']?></strong></h6>
				<ul class="collection s12 m6 l6">
                    <li class="collection-item">
                    <pre>
                    {
                        "request": "balance",
                        "status": "error",
                        "message": "Invalid user",
                    }   
                    </pre>
                    </li>
                </ul>
                
                <?php global $hooks; $hooks->do_action('OnAPIView'); ?>
             </div>
         </div>
     </div>
       
 </div>     
