<?php 
//ini_set('display_errors', 1);
//ini_set('display_startup_errors', 1);
//error_reporting(E_ALL);
$tenant = $_REQUEST['tenant'];

if(file_exists('../../../'.$tenant.'/config.php')){require_once('../../../'.$tenant.'/config.php');}
if(file_exists('/config.php')){require_once('/config.php');}



$stmt = $GLOBALS['con']->prepare("SELECT * FROM `writtenscheme` WHERE `clientnumber`='".$_REQUEST['clientnumber']."' AND `no`='WS00' ")or die(mysqli_error($GLOBALS['con']));
$stmt->execute();$cc=$stmt->get_result();$stmt->close();
$cn=mysqli_num_rows($cc);
if($cn<1){
    $insert = mysqli_query($GLOBALS['con'],"INSERT INTO `writtenscheme` VALUES(NULL,'".$_REQUEST['clientnumber']."','CATCHALL','System Default WS for exclusions','','WS00',NULL,'".strtotime('now')."','0','','','0','0','',NULL)")or die(mysqli_error($GLOBALS['con']));
}



$stmt = $GLOBALS['con']->prepare("SELECT * FROM `writtenscheme` WHERE `clientnumber`='".$_REQUEST['clientnumber']."' ORDER BY abs(no) ASC ")or die(mysqli_error($GLOBALS['con']));
$stmt->execute();$cc=$stmt->get_result();$stmt->close();
while($cd=mysqli_fetch_array($cc)){?>
<div class="mb-2 card p-2 list-group-item-action wsEntry w-100">
    <div class="row">
        <div class="col-8">
            <p class="p-0 m-0" style="font-size: 16px"><small><?= $cd['no']?></small>:<?= $cd['title']?></p>
        </div>
        <div class="col-4 text-end">
            <a href="javascript:void(0)" class="btn btn-info btn-sm m-0 px-3 py-2 waves-effect" onClick="editWSC('<?= $cd['id']?>')" data-toggle="tooltip" data-placement="left" title="View <?= $cd['title']?> details"><i
                   class="fad fa-search"></i></a>
            <?php if($_SESSION['usertype']=="admins" && $cd['no']!="WS00"){?><a href="javascript:void(0)" class="btn btn-danger btn-sm m-0 px-3 py-2 waves-effect" onClick="delWSC('<?= $cd['id']?>')" data-toggle="tooltip"
               data-placement="left"
               title="Remove <?= $cd['title']?>"><i class="fad fa-times"></i></a><?php }?>
        </div>
    </div>
</div>
<?php }?>
<script>

</script>