<?php 
	

	class Members{
		
		public $db;
		public function __construct(){
			$this->db = new mysqli(DB_SERVER, DB_USERNAME, DB_PASSWORD, DB_DATABASE);
			mysqli_set_charset($this->db,"utf8");
			if(mysqli_connect_errno()) {
	 
				echo "Error: Could not connect to database.";
	 
			exit;
 
			}
		}

	function selectlimit($table, $columns, $where, $start, $limit, $order){
            $start=$start*$limit;
            $a = array();
            $w = "";
            foreach ($where as $key => $value) {
                $w .= " and " .$key. " = ".$value;
                $a[":".$key] = $value;
            }
			 $countorderby=count($order);
			 $ord=" order by ";
			foreach ($order as $key => $value) {
                $orderby .= " " .$key. "  ".$value.",";
            }
			$orderby=substr($orderby, 0, -1);
			if($countorderby>0){
			$orderby=$ord.$orderby;
			}
			 
			//$orderby .="order by businessid DESC,title ASC";
             $result = array();
			 $join=" join tbl_user_type on tbl_members.typeid=tbl_user_type.typeid ";
              $sql = mysqli_query($this->db, "select ".$columns." from ".$table." ".$join." where 1=1 ". $w.$orderby." limit ".$start.",".$limit);
              while ($result = mysqli_fetch_array($sql)) {
             $data[] = $result;
              }
             return $data;
            
         
    }	
public function submembers($catid,$c,$page,$site_url,$limitpage){
	 
	$sql_subcategories=mysqli_query($this->db,"select * from tbl_user_type join tbl_members on tbl_members.typeid=tbl_user_type.typeid where tbl_members.parent_id='$catid'");
	if(mysqli_num_rows($sql_subcategories)>0){
		while($result_list_subcategories=mysqli_fetch_array($sql_subcategories)){
			$subcategories[]=$result_list_subcategories;
		}
	}
	//return $subcategories;
	$c=$c+1;
		
		foreach($subcategories as $subcategory){
				$d="-";		
						for($i=0;$i<$c;$i++){
						$d.=$d;	
						}
				 
                   /* $valexist=$helper->datapresent($table,"parent_id",$subcategory['memberid']);
				    $valexist2=$helper->datapresent("tbl_members","typeid",$subcategory['memberid']);*/
				      ?>
                     <tr>
                  <td> </td>
                  <td><?php echo $d." ". $subcategory['firstname']." ".$subcategory['middlename']." ".$subcategory['lastname'];?></td>
                  <td><?php echo $subcategory['email'];?></td>
                  <td><?php echo $subcategory['title'];?></td>
                  <td> <?php
				  if($subcategory['image']!=""){
				?> 
                <img src="<?php echo $site_url;?>thumb.php?src=<?php echo $site_url;?>images/users/<?php echo $subcategory['image'];?>&h=50&w=50"/>
                <?php
				  }
				  ?></td>
                  <td>
                   <?php
				  if(isset($_SESSION['userid'])){
					 
					?>
                     <a href="<?php echo $site_url;?>admin/allappraisals.php?userid=<?php echo $subcategory['memberid'];?>&start=<?php echo $limitpage; ?>"><span class="label label-success">Appraisals</span></a>
                    <?php
				  }
				  else {
					 ?>
                  <a href="<?php echo $site_url;?>admin/appraisals.php?userid=<?php echo $subcategory['memberid'];?>&start=<?php echo $limitpage; ?>"><span class="label label-success">Appraisals</span></a>
                  <?php
				  }
				  ?>
                  </td>
                   <?php
				  if(isset($_SESSION['userid'])){
					?>
                  <td>
                  <?php
				   
				  if($subcategory['status']==1){
				  ?>
<a href="<?php echo $site_url;?>admin/<?php echo $page;?>?mode=pending&contentid=<?php echo $subcategory["memberid"];?>&start=<?php echo $limitpage;?>"><span class="label label-success">Approved</span></a>
                  <?php
				  }
				  else {
				  ?>
				  <a href="<?php echo $site_url;?>admin/<?php echo $page;?>?mode=approve&contentid=<?php echo $subcategory["memberid"];?>&start=<?php echo $limitpage;?>"><span class="label label-danger">Pending</span></a>
                  <?php
				  }
				  ?>
                  </td>
                  <td><a href="<?php echo $site_url;?>admin/<?php echo $page;?>?mode=edit&contentid=<?php echo $subcategory["memberid"];?>&start=<?php echo $limitpage;?>"><span class="label label-primary"><i class="fa fa-edit"></i> Edit</span></a>
                   <a href="<?php echo $site_url;?>admin/<?php echo $page;?>?mode=delete&contentid=<?php echo $subcategory["memberid"];?>&start=<?php echo $limitpage;?>" onclick="return getConfirmation()"><span class="label label-danger"><i class="fa fa-times"></i> Delete</span></a>
                   </td>
                   <?php
				  }
				  ?>
                   
                </tr>
                    
                    
					<?php
					$subcategories=$this->submembers($subcategory['memberid'],$c,$page,$site_url,$limitpage);
					}
					
	
}
    	

	}
?>