<?php


	require_once __DIR__.'/common.php';

	if ($_SERVER['REQUEST_METHOD'] === 'POST') {

			extract($_REQUEST);

			switch ($action) {


				 case 'userProfileList':

					/* Start total Row Count */
					$params2['totalRowCount'] = "yes";
					$params2['searchStr'] = trim($search['value']);
					$response = $adminAPI->userListAPI($params2);

					$result["recordsFiltered"] = $response['userlist'];
                    $result["recordsTotal"] = $response['userlist'];

                    /* End total Row Count */

                    /* Start Page Data Count */
					$columNo = $order[0]['column'];
					$params['orderColName'] = $columns[$columNo]['name'];
					$params['orderDir'] = $order[0]['dir'];
					$params['start'] = $start;
					$params['length'] = $length;
					$params['searchStr'] = trim($search['value']);

					//For Sorting via Sr No. 
					if($columNo==0 && $params['orderDir']=='asc')
						$srNo = $result["recordsFiltered"]-$start;
					else
						$srNo = $start;

					$response = $adminAPI->userListAPI($params);
					$datalist = $response['userlist'];
					$data = array();
					if(!empty($datalist)): 
                    	$i=$start;
                        foreach ($datalist as $list):
                            $data[$i][] = ($columNo==0 && $params['orderDir']=='asc' ? $srNo-- : ++$srNo);
                        	$data[$i][] = $list['id'];
                        	$data[$i][] = $list['refer_id'];
                            $data[$i][] = ucwords($list['name'].' '.$list['last_name']);
                            $data[$i][] = isset($list['totalPV']) ? $list['totalPV'] : 0;
                            $data[$i][] = $list['sponsor_by'];
							$data[$i][] = $list['sponsor_id'];
                            $data[$i][] = $list['mobile_number'];
                            $data[$i][] = date('d-m-Y H:i:s',strtotime($list['date_entered']));
                            $data[$i][] = $list['customer_id'];


							$i++;
                        endforeach;
                    endif;

                    $result["data"] = $data;
                    $result["draw"] = $draw;

                    /* End Page Data Count */
					echo json_encode($result);
				break;


			



				
			}
	}
		else {
			
			include_once '../logout.php';
		}

?>