<?php
/**
 *  Copyright (C) 2021  Cover Tower LLC
 *
 *  This file is part of Roundpin, which is licensed under the
 *  GNU Affero General Public License Version 3.0. The license terms
 *  are detailed in the "LICENSE.txt" file located in the root directory.
 */

session_start();

if (isset($_POST['s_ajax_call']) && ($_POST['s_ajax_call'] == $_SESSION['validate_s_access']) && isset($_POST['sipusername']) && $_POST['sipusername'] != '') {

  $sipUser = $_POST['sipusername'];

  if (is_dir('textchat/' . $sipUser . '/uploads')) {

       array_map('unlink', glob('textchat/' . $sipUser . '/uploads/*'));

       if (rmdir('textchat/' . $sipUser . '/uploads')) {
           $cmessage = 'success';
       } else {
           $cmessage = 'failure';
       }

  } else { $cmessage = 'success'; }

  $resresult = ["note" => $cmessage];

  echo json_encode($resresult);

} else {
       header("Location: roundpin-login.php");
}

?>