<?

// Level 5 이하만 사용 가능
$func->checkLevelModal(5);

// Delete 기능 제한 (Admin : 1 만 가능)
$permit = array("1");
if (in_array($_SESSION['ss_LEVEL'], $permit)) {
    $setTag = "ENABLED";
}
else $setTag = "DISABLED";	

$add_srchquery = "";
$add_query = "";

// searching
if($key_word) {

	$key_wordStr = urldecode(trim($key_word));
	$add_srchquery .= " AND  ((m_userid LIKE '%$key_wordStr%') OR (m_firstname LIKE '%$key_wordStr%') OR (m_cell LIKE '%$key_wordStr%'))";
}

// sorting
if($switch) {
	$switched = $func -> switchOrder($switch, $switched);
	$add_query .= " ORDER BY $switch $switched ";
	$switched = $switch . "^" . $switched;
}else if($switched) {
	$switched1 = explode("^", $switched);
	$add_query .= " ORDER BY $switched1[0] $switched1[1] ";
} else {
	$add_query .= " ORDER BY m_uid DESC";
}

$getSWHStr = $switched;

// $query = "SELECT * FROM tbl_sampletypes 
// INNER JOIN tbl_members ON (tbl_sampletypes.t_uid = tbl_members.m_gid) 
// where tbl_members.m_uid != ''  
// ORDER BY tbl_members.m_uid DESC ";

//total record
$query = "SELECT COUNT(m_uid) FROM tbl_member
					WHERE m_uid <> '' AND m_status != 'D' " . $add_allquery . $add_srchquery . $add_query;

$total_count=$jdb->rQuery($query, "record query error");
//echo "<br><br><br><br><br>[$total_count][$query]<br>";

//페이징변수설정
if(!$page) $page = 1;

if(!$list_count) $list_count = $INIT_PAGECNT; //출력리스트 갯수
if(!$page_count) $page_count = $INIT_PAGEVIEWCNT; //출력페이지 갯수

$list_number = $total_count - (($page-1)*$list_count);
$start_number = $list_count * ($page-1);

$add_query .= " LIMIT $start_number, $INIT_PAGECNT";
$query = "SELECT * FROM tbl_member
					WHERE m_uid <> '' AND m_status != 'D' " . $add_allquery . $add_srchquery . $add_query;
//echo "[$query]";

$result=$jdb->nQuery($query, "list error");

while($list=mysqli_fetch_array($result, MYSQLI_ASSOC)) {
	for($i=0; $i<sizeof($list); $i++) {
		//list($key, $value) = each($list);
		foreach ( (Array) $list as $key => $value )
		$$key = $value;
	}

	//$logindateStr = $func -> convertFormat ($MLOGINDATE, 1);
	//$signupdateStr = $func -> convertFormat ($MSIGNUPDATE, 1);
		
	//$qry = "SELECT CNAME  FROM tbl_company WHERE CUID = '$MCOMPANY' ";
	//$rtd=$jdb->fQuery($qry, "fetch query error"); 
	//if ($MCOMPANY == "0" || $MCOMPANY == "") $companyStr = "-";
	//else $companyStr = $rtd[CNAME];
	
	$m_cell = preg_replace('/[^A-Za-z0-9\-]/', '', $m_cell);
	$m_cell = str_replace("-", "", $m_cell);
	$m_cellSTR = substr ($m_cell, 0, 3)."-".substr ($m_cell, 3, 3)."-".substr ($m_cell, 6, 4);
	
	$m_firstnameSTR = str_replace("\\", "", $m_firstname);
	$m_lastnameSTR = str_replace("\\", "", $m_lastname);
	$m_initialSTR = str_replace("\\", "", $m_initial);
	$m_statusSTR = $arrStatus[$m_status];
	$m_levelSTR = $arrMemberLevel[$m_level];
	
	//$qry_driver = "SELECT m_firstname, m_lastname FROM tbl_member WHERE m_uid = '$c_driveruid' ";
	//$rt_driver = $jdb->fQuery($qry_driver, "fetch query error");

	if ($setTag == "ENABLED") {
		$OPTIONstr = "<a class=\"deleteClass btn-member\" data-toggle=\"modal\" data-target=\"#myModalDelete\" data-id=\"$m_uid\"><i class=\"bi bi-x-circle icon-delete\"></i></a>";
		//$OPTIONTITLEstr = "OPTION";
	}
	else {
		$OPTIONstr = "";
		//$OPTIONTITLEstr = "";
	}

	$strList .= "

            <tr>
              <td>$list_number</td>
              <td><a onclick=\"#\" class=\"modifyMember\" data-toggle=\"modal\" data-target=\"#myModalMemberInfo\" data-id=\"$m_uid\" style=\"cursor:pointer;cursor:hand;\"><b style=\"ustomer-info-detail\">$m_userid</b></a></td>
              <td>$m_firstnameSTR</td>
              <td>$m_lastnameSTR</td>
              <td>$m_initialSTR</td>
              <td>$m_cellSTR</td>
              <td>$m_statusSTR </td>
              <td>$m_levelSTR </td>
              <td>$OPTIONstr</td>
            </tr>

	";

	$list_number--;
}


if( $total_count < 1 ) {
	$strList = "
		<tr><td colspan='9' align=center height='30'><B>No Data</B></td></tr>
		";
}


addLog ("add", "MEMBER LIST", "VIEW", $lguserid, $query, $lgno);

?>


<SCRIPT LANGUAGE=JAVASCRIPT>
<!--
function goSearch(f){
    var f = document.form1;
    if(trim(f.key_word.value).length < 1){
        alert('Enter keyword.');
        f.key_word.focus();
        return false;
    }
}
//-->
</SCRIPT>


<SCRIPT TYPE="TEXT/JAVASCRIPT">
    $(function () {
        $(".deleteClass").click(function () {
            var my_id_value = $(this).data('id');
            $(".modal-footer #m_uid").val(my_id_value);
        })
    });
</SCRIPT>


<script>
$(document).ready(function(){

		 $('.modifyMember').click(function(){
		   
			   var mmuid = $(this).data('id');

			   // AJAX request
			   $.ajax({
					    url: 'lib/member_lib.php',
					    type: 'post',
					    data: {muid: mmuid},
					    success: function(response){ 
					      // Add response in Modal body
					      $('.modal-content-modifyMember').html(response);

					      // Display Modal
					      //$('#myModalModify').modal('show'); 
					    }
		  	});
		 });
});
</script>




<!-- Start of Modal -->
<div class="container">

  <!-- Modal -->
  <div class="modal fade customer-info" id="myModalMemberInfo"  aria-labelledby="myModalMemberInfoLabel" aria-hidden="true">
    <div class="modal-dialog" role="document" >
    
      <!-- Modal content-->
      <div class="modal-content modal-content-modifyMember" >

      </div>
      
    </div>
  </div>
  
</div>
<!-- End of Modal -->


<div class="container">
            
  <!-- Modal -->
  <div class="modal fade" id="myModalDelete" data-backdrop="static" role="dialog">
    <div class="modal-dialog">
    
      <!-- Modal content-->
      <div class="modal-content">
        <div class="modal-header">
                    <h4 class="modal-title">MESSAGE</h4>
                    <button type="button" class="btn" data-dismiss="modal" aria-label="Close" style="color:#fff;"><i class="bi bi-x"></i></button>
        </div>
        <div class="modal-body">
          <p>Are you sure to delete?</p>
        </div>
        <div class="modal-footer">

		        <FORM NAME=newModalDeleteForm METHOD=POST ACTION="/lib/user_process.php" id="newModalDeleteForm">
							<input type=hidden name=m_uid id=m_uid value="">
							<input type=hidden name=mode value="delete">
		        	<input type=hidden name=actionStr value="MEMBERINFO">

							<input type=hidden name=switched value="<?=$getSWHStr?>">
							<input type=hidden name=page value="<?=$page?>">
							<input type=hidden name=key_word value="<?=$key_word?>">
							<input type=hidden name=column value="<?=$column?>">
							<input type=hidden name=sorting_type value="<?=$sorting_type?>">
							<input type=hidden name=switch value="<?=$switch?>">

            <div class="text-center grid-layout-col-2">
              <button type="button" class="btn-gray" data-dismiss="modal">NO</button>
              <button type="submit" class="btn-sub">YES</button>
            </div>

						</FORM>    
				                              
        </div>
      </div>
      
    </div>
  </div>
  
</div>


  <main id="main" class="main">

    <!-- ======= Breadcrumbs ======= -->
    <div class="breadcrumbs">
      <div class="container">

        <div class="d-flex justify-content-between align-items-center">
          <h2>MEMBER</h2>
          <ol>
            <li><a href="index.html">HOME</a></li>
            <li>MEMBER</li>
          </ol>
        </div>

      </div>
    </div><!-- End Breadcrumbs -->

    <section class="page">


      <div class="container" data-aos="fade-up">

        <div class="wrap-border">
            <table class="table-search-customer">
              <tr>
                <!--td class="td-title">
                  <select name="name" id="name" class="custom-select">
                    <option value="jk">J.K.</option>
                    <option value="hs">H.S.</option>
                    <option value="Hold">Hold</option>
                  </select>
                </td-->
                <td class="td-title">

                    <div class="search-container">
<FORM METHOD=POST NAME=form1 ONSUBMIT='return goSearch(this)' action='<?=$_SERVER["PHP_SELF"]?>'>                    	
                    	<INPUT TYPE=HIDDEN NAME=view VALUE='member_list'>				
                        <input class="" type="text" placeholder="Search.." name="key_word" value='<?=$key_word?>'>
                        <button type="submit"><i class="bi-search"></i></button>
</FORM>
                    </div>

                </td>
                <td align="right">

<? if ($setTag == "ENABLED") { ?>                	
                    <a onclick=# class="btn-add modifyMember" data-toggle="modal" data-target="#myModalMemberInfo" data-id="" style="cursor:pointer;cursor:hand;">ADD</a>
<? } ?>
                    	
                </td>

              </tr>

            </table>
        </div><!--wrap-border-->


<? if ($aaaa == 1) { ?>
        <div class="wrap-border">

          <form action=""  class="form-customer">
            <table class="table-search-customer">
              <tr>
                <td class="td-title">
                  <select name="name" id="name" class="custom-select">
                    <option value="jk">J.K.</option>
                    <option value="hs">H.S.</option>
                    <option value="Hold">Hold</option>
                  </select>
                </td>
                <td class="td-title">


                    <div class="search-container">
                        <input class="" type="text" placeholder="Search.." name="search">
                        <button type="submit"><i class="bi-search"></i></button>
                    </div>


                </td>
                <td align="right">
                    <button type="button" class="btn btn-add" data-bs-toggle="modal" data-bs-target="#add-acct-staff-modal" data-add-acct-staff-type="standard-access">ADD</button>
                                <!-- Modal add-acct-staff Form -->
                                <div id="add-acct-staff-modal" class="modal fade customer-info">
                                  <div class="modal-dialog" role="document">
                                    <div class="modal-content">
                                      <div class="modal-header">
                                        <h4 class="modal-title">USER INFORMATION</h4>
                                        <button type="button" class="btn" data-bs-dismiss="modal" aria-label="Close" style="color:#fff;"><i class="bi bi-x"></i></button>
                                      </div>
                                      <div class="modal-body">
                                        <form method="POST" action="#">
                                          <table class="tb-info-box">
                
                                            <tr>
                                              <td class="td-title-info">User ID</td>
                                              <td class="td-text-info">
                                                <input type="text" id="userid" name="userid" placeholder="name@company.com">
                                              </td>
                                            </tr>
                
                                            <tr>
                                              <td class="td-title-info">Password</td>
                                              <td class="td-text-info">
                                                <input type="text" id="password" name="password" placeholder="********">
                                              </td>
                                            </tr>
                
                                            <tr>
                                              <td class="td-title-info">Re-Password</td>
                                              <td class="td-text-info">
                                                <input type="text" id="repassword" name="repassword" placeholder="********">
                                              </td>
                                            </tr>
                
                                            <tr>
                                              <td class="td-title-info">Frist Name</td>
                                              <td class="td-text-info">
                                                <input type="text" id="firstname" name="firstname" placeholder="Dustin">
                                              </td>
                                            </tr>
                
                                            <tr>
                                              <td class="td-title-info">Last Name</td>
                                              <td class="td-text-info">
                                                <input type="text" id="lastname" name="lastname" placeholder="Choi">
                                              </td>
                                            </tr>
                
                                            <tr>
                                              <td class="td-title-info">Phone</td>
                                              <td class="td-text-info">
                                                <input type="number" id="phone" name="phone" placeholder="1-123-456-7890">
                                              </td>
                                            </tr>
                
                                            <tr>
                                              <td class="td-title-info">Ext.</td>
                                              <td class="td-text-info">
                                                <input type="text" id="ext" name="ext" placeholder="123">
                                              </td>
                                            </tr>
                
                                            <tr>
                                              <td class="td-title-info">Cell</td>
                                              <td class="td-text-info">
                                                <input type="number" id="cell" name="cell" placeholder="1-123-456-7890">
                                              </td>
                                            </tr>
                
                                            <tr>
                                              <td class="td-title-info">Last Login Date</td>
                                              <td class="td-text-info">
                                                <input type="date" id="lastlogindate" name="lastlogindate">
                                              </td>
                                            </tr>     
                                            
                                            <tr>
                                              <td class="td-title-info">Signup Date</td>
                                              <td class="td-text-info">
                                                <input type="date" id="signupdate" name="signupdate">
                                              </td>
                                            </tr>     
                                                                        
                                            <tr>
                                              <td class="td-title-info">Login No</td>
                                              <td class="td-text-info">
                                                <input type="number" id="loginnum" name="loginnum" placeholder="1234545">
                                              </td>
                                            </tr>
                                                                        
                                            <tr>
                                              <td class="td-title-info">Status</td>
                                              <td class="td-text-info">
                                                <select id="status" name="status" class="custom-select">
                                                  <option value="allow">Allow</option>
                                                  <option value="deny">Deny</option>
                                                </select>
                                              </td>
                                            </tr>
                                            
                                            <tr>
                                              <td class="td-title-info">Level</td>
                                              <td class="td-text-info">
                                                <select id="level" name="level" class="custom-select">
                                                  <option value="admin">Admin</option>
                                                  <option value="staff">Staff</option>
                                                  <option value="manager">Manager</option>
                                                  <option value="driver">Driver</option>
                                                </select>
                                              </td>
                                            </tr>
                                            
                                                                        
                                            <tr>
                                              <td class="td-title-info">Access</td>
                                              <td class="td-text-info">
                                                <select id="access" name="access" class="custom-select">
                                                  <option value="local">Local</option>
                                                  <option value="internet">Internet</option>
                                                </select>
                                              </td>
                                            </tr>
                
                                            <tr>
                                              <td class="td-title-info">Memo</td>
                                              <td class="td-text-info">
                                                <textarea id="memo" class="textarea" name="memo" rows="4" cols="20">
                
                                                </textarea>
                                              </td>
                                            </tr>
                                          </table>
                                          <br>
                                          <div class="text-center grid-layout-col-2">
                                            <button type="submit" class="btn-sub">ADD</button>
                                            <button type="submit" class="btn-gray">CLOSE</button>
                                          </div>
                                        </form>
                                      </div>
                                    </div><!-- modal-content ends -->
                                  </div><!-- modal-dialog ends -->
                                </div>
                                <!-- Modal add-acct-staff Form Ends -->
                
                  </td>

              </tr>

            </table>
  
          </form>
        </div><!--wrap-border-->
<? } ?>


  
        

        <div class="wrap-overflow customer-info">
          <table class="tb-list">
            <tr>
                <th>No</th>
                <th class="td-restaurant">User ID</th>
                <th class="td-restaurant">First Name</th>
                <th class="td-restaurant">Last Name</th>
                <th>Initial</th>
                <th class="th-width-phone">Cell</th>
                <th>Type</th>
                <th>Status</th>
                <th>Option</th>
            </tr>

<?=$strList?>

<!--
            <tr>
              <td>1</td>

              <td>
                <button type="button" class="btn acct-staff" data-bs-toggle="modal" data-bs-target="#acct-staff-modal" data-acct-staff-type="standard-access">dustin@gmail.com</button>
               
                <div id="acct-staff-modal" class="modal fade customer-info">
                  <div class="modal-dialog" role="document">
                    <div class="modal-content">
                      <div class="modal-header">
                        <h4 class="modal-title">USER INFORMATION</h4>
                        <button type="button" class="btn" data-bs-dismiss="modal" aria-label="Close" style="color:#fff;"><i class="bi bi-x"></i></button>
                      </div>
                      <div class="modal-body">
                        <form method="POST" action="#">
                          <table class="tb-info-box">

                            <tr>
                              <td class="td-title-info">User ID</td>
                              <td class="td-text-info">
                                <input type="text" id="userid" name="userid" placeholder="name@company.com">
                              </td>
                            </tr>

                            <tr>
                              <td class="td-title-info">Password</td>
                              <td class="td-text-info">
                                <input type="text" id="password" name="password" placeholder="********">
                              </td>
                            </tr>

                            <tr>
                              <td class="td-title-info">Re-Password</td>
                              <td class="td-text-info">
                                <input type="text" id="repassword" name="repassword" placeholder="********">
                              </td>
                            </tr>

                            <tr>
                              <td class="td-title-info">Frist Name</td>
                              <td class="td-text-info">
                                <input type="text" id="firstname" name="firstname" placeholder="Dustin">
                              </td>
                            </tr>

                            <tr>
                              <td class="td-title-info">Last Name</td>
                              <td class="td-text-info">
                                <input type="text" id="lastname" name="lastname" placeholder="Choi">
                              </td>
                            </tr>

                            <tr>
                              <td class="td-title-info">Phone</td>
                              <td class="td-text-info">
                                <input type="number" id="phone" name="phone" placeholder="1-123-456-7890">
                              </td>
                            </tr>

                            <tr>
                              <td class="td-title-info">Ext.</td>
                              <td class="td-text-info">
                                <input type="text" id="ext" name="ext" placeholder="123">
                              </td>
                            </tr>

                            <tr>
                              <td class="td-title-info">Cell</td>
                              <td class="td-text-info">
                                <input type="number" id="cell" name="cell" placeholder="1-123-456-7890">
                              </td>
                            </tr>

                            <tr>
                              <td class="td-title-info">Last Login Date</td>
                              <td class="td-text-info">
                                <input type="date" id="lastlogindate" name="lastlogindate">
                              </td>
                            </tr>     
                            
                            <tr>
                              <td class="td-title-info">Signup Date</td>
                              <td class="td-text-info">
                                <input type="date" id="signupdate" name="signupdate">
                              </td>
                            </tr>     
                                                        
                            <tr>
                              <td class="td-title-info">Login No</td>
                              <td class="td-text-info">
                                <input type="number" id="loginnum" name="loginnum" placeholder="1234545">
                              </td>
                            </tr>
                                                        
                            <tr>
                              <td class="td-title-info">Status</td>
                              <td class="td-text-info">
                                <select id="status" name="status" class="custom-select">
                                  <option value="allow">Allow</option>
                                  <option value="deny">Deny</option>
                                </select>
                              </td>
                            </tr>
                            
                            <tr>
                              <td class="td-title-info">Level</td>
                              <td class="td-text-info">
                                <select id="level" name="level" class="custom-select">
                                  <option value="admin">Admin</option>
                                  <option value="staff">Staff</option>
                                  <option value="manager">Manager</option>
                                  <option value="driver">Driver</option>
                                </select>
                              </td>
                            </tr>
                            
                                                        
                            <tr>
                              <td class="td-title-info">Access</td>
                              <td class="td-text-info">
                                <select id="access" name="access" class="custom-select">
                                  <option value="local">Local</option>
                                  <option value="internet">Internet</option>
                                </select>
                              </td>
                            </tr>

                            <tr>
                              <td class="td-title-info">Memo</td>
                              <td class="td-text-info">
                                <textarea id="memo" class="textarea" name="memo" rows="4" cols="20">

                                </textarea>
                              </td>
                            </tr>
                          </table>
                          <br>
                          <div class="text-center grid-layout-col-2">
                            <button type="submit" class="btn-sub">ADD/UPDATE</button>
                            <button type="submit" class="btn-gray">CLOSE</button>
                          </div>
                        </form>
                      </div>
                    </div>
                  </div>
                </div>
              
              </td>
              <td>Dustin</td>
              <td>Choi</td>
              <td>1-123-456-7890 </td>
              <td>Staff </td>
              <td>Allow </td>
              <td><i class="bi bi-x-circle icon-delete"></i></td>
            </tr>
            
            <tr>
              <td>3</td>
              <td>dustin@gmail.com</td>
              <td>Dustin</td>
              <td>Choi</td>
              <td>1-123-456-7890 </td>
              <td>Staff </td>
              <td>Allow </td>
              <td><i class="bi bi-x-circle icon-delete"></i></td>
            </tr>

            <tr>
              <td>4</td>
              <td>dustin@gmail.com</td>
              <td>Dustin</td>
              <td>Choi</td>
              <td>1-123-456-7890 </td>
              <td>Staff </td>
              <td>Allow </td>
              <td><i class="bi bi-x-circle icon-delete"></i></td>
            </tr>
-->

        </table>
        </div>


        <div class="container-inner">
          <div class="pagination">
            <!--a href="#" ><i class="bi bi-arrow-left"></i></a>
            <a href="#"class="active">1</a>
            <a href="#">2</a>
            <a href="#">3</a>
            <a href="#">4</a>
            <a href="#">5</a>
            <a href="#">6</a>
            <a href="#"><i class="bi bi-arrow-right"></i></a-->
					<?

					$page_string = "view=$view&key_word=$key_word&key_CTGSEQ=$key_CTGSEQ&column=$column&mode=$mode&switched=$getSWHStr";
					$paging = new PAGE('page',$total_count,$list_count,$page_count,$page,$page_string,'#c71930','','','#c71930','');

					?>
            
          </div>
        </div>

        <!--div class="row text-center">
          <div class="col-sm-4 item-inner">
          <a class="btn-sub" href="#">LIST</a>
         </div>
        </div-->

      </div>

    </section>



</div><!--container Ends-->
    </section>

  </main><!-- End #main -->




  <script>
    /**
    * Request type on click
    */
    on('show.bs.modal', '#acct-staff-modal', function(event) {
      select('#acct-staff-modal #acct-staff-type').value = event.relatedTarget.getAttribute('data-acct-staff-type')
    })

    on('show.bs.modal', '#add-acct-staff-modal', function(event) {
      select('#add-acct-staff-modal #acct-staff-type').value = event.relatedTarget.getAttribute('data-add-acct-staff-type')
    })

</script>
