<main>
  <div class="container-fluid">

    <div class="row align-items-center justify-content-between pt-2">
      <div class="col-auto mb-3">
        <h2>
            <b>who</b>
        </h2>
      </div>
      <div class="col-12 col-xl-auto mb-3">
        <!--<a class="btn btn-xs btn-success" href="?op=who&op2=add">Add</a>-->
      </div>
    </div> 


      <?php
      switch($op2) {

        case "edit";
            edit($_GET['id']);
            break;
      
        case "copy";
            //print_r($_POST);
            $sql4 = "select * from who order by id desc limit 1";
            $res4 = mysqli_query($db, $sql4);
            $rw4 = mysqli_fetch_assoc($res4);
            $id2=$rw4['id']+1;

            $sql = "select * from who where id=".$_GET['id'];
            $res = mysqli_query($db, $sql);
            $r = mysqli_fetch_assoc($res);

            $idata=array(
              'id'=>$id2,
              'name'=>$r['name']."_",
              'slug'=>slug($r['name'])."_",
              'update_at'=>time(),
              'del'=>0,
            );
            Insert($db,"who",$idata);
                           
            list_who($q,$col,$sort);
            break;
    
        case "edit2";
            //addProduk();
            //echo "<pre>"; print_r($_POST); echo "</pre>";
            //echo "<pre>"; print_r($_FILES); echo "</pre>";
            $udata=array(
                'name'=>$_POST['name'],
                'image'=>$_POST['image'],
                'slug'=>slug($_POST['slug']),
                //'url_logo'=>$_POST['url_logo'],
                //'company'=>$_POST['company'],
                //'img'=>$_POST['img'],
                //'web'=>$_POST['web'],
                //'update_at'=>time(),
            );
            Update($db,"who",$udata,"id=".$_POST['id'],0);
            
            if(isset($_FILES['file']['tmp_name']) && ($_FILES['file']['tmp_name']!='')) {
                UploadImage($_POST,$_FILES,'who');
            }
            
            if(isset($_POST['url_img_src']) && ($_POST['url_img_src']!='')) {
                CopyUrlImage($_POST,'who');
            }

            list_who($q,$col,$sort);
            //editNetwork($_POST['id']);
            break;

            
        case "delete";
          delete($db,"who","id=".$_GET['id']);
          list_who($q,$col,$sort);
          break;

        case "list";
        default;
        list_who($q,$col,$sort);
      }
      
      ?>
          
  </div>
</main>                    

<?php
function list_who($q,$col,$sort) {
    global $db,$ar;    
    //print_r($ar);
    ?>
           
    <h3>List</h3>        
    <table class="table table-bordered" id="dataTable" width="100%" cellspacing="0">
        <thead>
            <tr>
                <th>ID</th>
                <th>Name</th>
                <th>Slug</th>
                <th>Image</th>
                <th>Img</th>
                <th>del</th>
                <th>daily</th>
                <th>weekly</th>
                <th>uAt</th>
                <th>Menu</th>
            </tr>
        </thead>

        <tbody>
        <?php
        $sql = "select * from `who` where id>0 ";
        
        
        //$sql .= " and st=1";
        $res = mysqli_query($db, $sql);
        //echo $sql;
        while($rw = mysqli_fetch_assoc($res)) {
        if($rw['image']!='') {
          $image='<a href="'.$rw['image'].'" target="_blank">'.$rw['image'].'</a>';
        } else {
          $image='';
        }

        if($rw['img']!='') {
          $img='<a href="'.$ar['img_url'].''.$rw['img'].'" target="_blank">'.$rw['img'].'</a>';
        } else {
          $img='';
        }

        ?>
        
          <tr>
            <td><?=$rw['id'];?></td>
            <td><?=$rw['name'];?></td>
            <td><?=$rw['slug'];?></td>
            <td><?=$image;?></td>
            <td><?=$img;?></td>
            <td class="text-right"><?=$rw['del'];?></td>
            <td class="text-right"><?=ang2($rw['daily_count']);?></td>
            <td class="text-right"><?=ang2($rw['weekly_count']);?></td>
            <td class="text-right"><?=date("Y-m-d H.i.s",$rw['update_at']);?></td>
            <td>
            <a class="btn btn-xs btn-success" href="?op=who&op2=copy&id=<?=$rw['id'];?>">copy</a>
            <a class="btn btn-xs btn-primary" href="?op=who&op2=edit&id=<?=$rw['id'];?>">edit</a> 
            <a class="btn btn-xs btn-danger" href="?op=who&op2=del&id=<?=$rw['id'];?>">del</a>
            </td>
          </tr>
        <?php
        }
        ?>  
            
        </tbody>
    </table>
    <?php
}

function edit($id) {
    global $db,$ar;
    
    $sql = "select * from `who` where id=".$id;
    $res = mysqli_query($db, $sql);
    //echo $sql;
    $rw = mysqli_fetch_assoc($res);  
    ?>

    <h3>Edit</h3>
    <form action="index.php?op=who&op2=edit2" method="post" enctype="multipart/form-data">
        <input type="hidden" name="id" value="<?=$id;?>">
        <input type="hidden" name="file_type" value="image">

        <div class="form-group row">
            <div class="col-sm-2">
              <label for="name" class="label">name</label>
              <input type="text" class="form-control" name="name" value="<?=$rw['name'];?>">
            </div>
            <div class="col-sm-2">
              <label for="slug" class="label">slug</label>
              <input type="text" class="form-control" name="slug" value="<?=$rw['slug'];?>">
            </div>                        
            <div class="col-sm-8">
              <label for="slug" class="label">url img src</label>
              <input type="text" class="form-control" name="url_img_src">
            </div>                        
        </div>

        <div class="form-group row">
            <div class="col-sm-10 offset-sm-2 text-right">
                <button type="submit" name="submit" class="btn btn-primary">Update</button>
            </div>
        </div>
    </form>   
    <?php
    echo viewImage("who",$id);
}
?>
/home/u1731472/public_html/
sub/cpapp_ekbis/inc/inc.who.php