<?php
include("template.php");

//$siteName = $_GET['siteName'] . " RESPONSE";
$siteName = $_POST['siteName'] . " RESPONSE";

?>

 <body>
        <header id='header'>
                <?php echo $siteName; ?></br>
                <a href="logout.php">Logout</a>
        </header>
        <section id='hyperlinks' class='leftlinks'>
        <?php
        require_once('inc/config.php');
        $permission = getUserAccessRoleByID($_SESSION['user_role_id']);
        include("mid_template.php");
         printSideLinks($currentPage, $permission);
        ?>
        </section>
        <section id='container'>
<?php
//START WRITING PHP CODE HERE

//Variables
$phone= $_GET['phone'];
$first= $_GET['first'];
$lastN= trim($_GET['last']);
$upload= $_POST['upload'];
$account="AC061dfdeaac04466783e164e3efb4c72e";
$token="AUbce970ab2c4841da8e8b902de1f5e05a";

if(isset($upload) and $upload == 'true') {
    upload();
    multiUpdate();
} else {
    singleUpdate();
}

function singleUpdate()
{
  global $phone, $first, $lastN, $account, $token;

//If last name is Empty then use first name as Business Name
if (empty($lastN)) {
  $business = $first;
  $site = '"https://storage.opencnam.com/v1/phone/+1' . $phone . '?account_sid=' . $account . '&auth_token=' . $token . '" -v -d "business=' . $business . '&language=eng&class=BUS"';
  //echo $site;
} else {
      $site = '"https://storage.opencnam.com/v1/phone/+1' . $phone . '?account_sid=' . $account . '&auth_token=' . $token . '" -v -d "first_name=' . $first . '&last_name=' . $lastN . '&language=eng&class=MOB"';
 //     echo $site;
}

    echo 'Updating phone 1' . $phone . ':</br>';
    echo '</br>';
    echo 'THIS CHANGE WILL REQUIRE UPTO 48 HOURS TO PROPAGATE TO ALL OF OUR SYSTEMS:</br>';

//Since this is not an option echo is the best bet.
    echo '</br>';
    echo '###################################################################</br>';
//$site='"https://storage.opencnam.com/v1/phone/+1'.$phone.'?account_sid='.$account.'&auth_token='.$token.'" -v -d "first_name='.$first.'&last_name='.$last.'&language=eng&class=BUS"';
    $output = shell_exec('curl ' . $site);
    echo "<pre>$output</pre>";
    echo '###################################################################</br>';
    echo '</br>';
}

function multiUpdate() {
    echo '</br>';
    echo 'THIS CHANGE WILL REQUIRE UP TO 48 HOURS TO PROPAGATE TO ALL OF OUR SYSTEMS:</br>';
    echo '</br>';
    echo '</br>';
    echo '</br>';
}

function upload() {
    $target_dir = "uploads/";
    $target_file = $target_dir . basename($_FILES["fileToUpload"]["name"]);
    $uploadOk = 1;
    $imageFileType = strtolower(pathinfo($target_file,PATHINFO_EXTENSION));

    // Check if file already exists
    if (file_exists($target_file)) {
        echo "Sorry, file already exists.";
        echo "</br>";
        $uploadOk = 0;
    }
    // Check file size
    if ($_FILES["fileToUpload"]["size"] > 500000) {
        echo "Sorry, your file is too large.";
        echo "</br>";
        $uploadOk = 0;
    }
    // Check if $uploadOk is set to 0 by an error
    if ($uploadOk == 0) {
        echo "Sorry, your file was not uploaded.";
        echo "</br>";
    // if everything is ok, try to upload file
    } else {
        if (move_uploaded_file($_FILES["fileToUpload"]["tmp_name"], $target_file)) {
            echo "The file \"". basename( $_FILES["fileToUpload"]["name"]). "\" has been uploaded.";
            echo "</br>";
        } else {
            echo "Sorry, there was an error uploading your file.";
            echo "</br>";
        }
    }
}
?>
            <!--  </section>     -->
        </section>
 <?php
    include("footer.php");
?>

