<?php
namespace Work\lib;
use Dever;
Class Appoint
{
	public function startBranch($id,$name,$data)
	{
		// Dever::config('base')->hook = true;
		$group = Dever::param('group',$data);
		// $id = Dever::param('id',$data);
		if ($group) {
			$res = Dever::db('work/branch')->find(array('group_id'=>$group[0]));
			if ($res && isset($id['where_id']) && $id['where_id']){
				if ($res['id'] !=  $id['where_id']){
					Dever::alert('部门已存在');
				} 
			} elseif ($res) {
				Dever::alert('部门已存在');
			}
			
		}
	}
	public function updateBranch($id,$name,$data)
	{
		// Dever::config('base')->hook = true;
		$group = Dever::param('group',$data);
		if($group) {
			$where['where_id'] = $id;
			$where['group_id'] = $group[0];
			Dever::db('work/branch')->update($where);
		}

	}

    public function insertAppoint($id,$name,$data)
    {
        $admin = Dever::load("manage/auth.info");
        $info_id = Dever::param('info_id',$data);
        if ($info_id) {
            $info = Dever::db('work/info')->find($info_id);
            // print_R($info);die;
            // if ($info['appoint_id'] != $admin['id'] && $admin['id'] != $info['audit_admin']) {
            //     Dever::alert('reload');
            // }
            if ($info['status']>=3){
                Dever::alert('reload');
            }
        }
    }
	
	public function updateAppoint($id,$name,$data)
	{
		Dever::config('base')->hook = true;
		$info_id = Dever::param('info_id',$data);
		$branch = Dever::param('admin_id',$data);
        $email = Dever::param('email',$data);
		if ($info_id ) {
			$info = Dever::db('work/info')->find($info_id);
			$admin = Dever::load('manage/auth.info');
			$admin_id = $info['audit_admin'];
			if ($info['audit_admin'] != $admin['id']) {
				$admin_id = $admin['id'];
			}
			if($info) {
				if ($branch) {
					$i['where_id'] = $info['id'];
					// if ($info['group']) {
					// 	 $group = $info['group'].',';
					// } else {
						$group = $branch[0];
					// }
					if (isset($branch[1]) && $branch[1]) {
						$i['appoint_id'] = $branch[1];
					}
					
					$i['group'] = $group;
					$i['zdate'] = time();
					$i['chdate'] = time();
					$i['status'] = 2;
					if ($i) {
						Dever::db('work/info')->update($i);
					}
				}
				$w['info_id'] = $info['id'];
				$w['admin_id'] = $admin_id;
				$w['appoint_id'] = $id;
                if (isset($branch[1]) && $branch[1]) {
                    $w['app_admin_id'] = $branch[1];
                }
                
				Dever::db('work/info_log')->insert($w);
			}
			if ($branch) {
				// $data = Dever::db('work/branch')->find(array('group_id'=>$branch[0]));
				// if ($data) {
				// 	$where['where_id'] = $data['id'];
				// 	$where['num'] = $data['num'] +1;
				// 	Dever::db('work/branch')->update($where);
				// }
				$wh['where_id'] = $id;
				$wh['group'] = $branch[0];
                if(isset($branch[1]) && $branch[1]) {
                    $wh['admin'] = $branch[1];
                }
				Dever::db('work/appoint')->update($wh);
			}
            if ($email && $email == 2) {
                $admin = Dever::db('manage/admin')->find($branch['1']);
                $res = Dever::load('work/lib/manage')->getTotal($admin['id'],'1,2');
                $work_list =Dever::url('project/database/list?project=work&table=info&search_option_dever_auth=2&search_option_state=1&[refer]', 'manage');
                $url = Dever::url('home?link=' . urlencode($work_list) . '&group=10&parent_menu=work&menu=work.my' , 'manage');
                // $url = 
                $content = '你有'.$res.'个待处理工单,<a href="'.$url.'">点此跳转至工单系统查看</a>';
                Dever::load('work/lib/cron')->send($admin['email'],$admin['username'],'你有新的工单待处理',$content);
            }
		}
	}
	#指派人
	 private $default = array
    (
        'value' => -1,
        'name' => '不选择',
    );
    private $search_default = array
    (
        'value' => -1,
        'name' => '部门',
    );
	public function get_api()
    {
        $type = Dever::input('type', 2);
        # 联动总数，默认到部门
        $level_total = Dever::input('level_total', 1);

        # 当前联动级别
        $level_num = Dever::input('level_num');

        # 一般为id
        $level_id = Dever::input('level_id');

        # 是否是搜索列表页
        $level_search = Dever::input('level_search');
        if ($level_search) {
            $default = $this->search_default;
            if ($level_num == 1) {
                $default['name'] = '部门选择';
            } elseif ($level_num == 2) {
                $default['name'] = '组员选择';
            } 
        } else {
            // echo 11;
            $default = $this->default;
        }
        // if ($level_id < 0) {
        //     Dever::alert('error');
        // }
        if ($level_num == 1) {
            $data = $this->group();

        } elseif ($level_num == 2) {
        	$data = $this->group_admin($level_id, $type);
        } 

        if (!$data) {
            Dever::alert('error');
        }

        if ($level_search || $level_num >= 1) {
            array_unshift($data, $default);
        }
        if ($level_num == 2) {
            unset($data[0]);
        }
        $result['level_total'] = $level_total;
        $result['list'] = $data;
        return $result;
    }
    public function group(){
    	$data = Dever::load('manage/company')->getGroup();
    	foreach ($data as $k => $v) {
    		$data[$k]['value'] = $v['id'];
    	}
    	return $data;
    }
    public function group_admin($level_id, $type = 1){
        $admin_id = false;
        if ($type == 2) {
            $info = Dever::db('work/branch')->find(array('group_id' => $level_id));
            if ($info) {
                $temp = explode(',', $info['group']);
                $admin_id = $temp[1] . ',' . $info['coor'];
            }
        }
        
    	$data = Dever::load('manage/company')->getAdmin($level_id, false, $admin_id);
    	foreach ($data as $k => $v) {
    		foreach ($v as $k1 => $v1) {
    			$data[$k]['value'] = $v['id'];
    			$data[$k]['name'] = $v['username'];
    		}
    	}
    	return $data;
    }
    #问题
     private $cdefault = array
    (
        'value' => -1,
        'name' => '不选择',
    );
    private $search_cdefault = array
    (
        'value' => -1,
        'name' => '问题类型描述',
    );
    #问题类型联动
    public function getCate_api()
    {
        # 联动总数，默认到部门
        $level_total = Dever::input('level_total', 1);

        # 当前联动级别
        $level_num = Dever::input('level_num');

        # 一般为id
        $level_id = Dever::input('level_id');

        # 是否是搜索列表页
        $level_search = Dever::input('level_search');
        if ($level_search) {
            $default = $this->search_cdefault;
            if ($level_num == 1) {
                $default['name'] = '问题分类名称';
            } elseif ($level_num == 2) {
                $default['name'] = '问题类型描述';
            } 
        } else {
            $default = $this->cdefault;
        }
        if ($level_num == 1) {
            $data = Dever::db('work/q_cate')->getSearchAll();

        } elseif ($level_num == 2) {
            $data = Dever::db('work/question')->getSearchAll(array('cate_id'=>$level_id));
        } 

        if (!$data) {
            Dever::alert('error');
        }

        if ($level_search || $level_num >= 1) {
            array_unshift($data, $default);
        }
        $result['level_total'] = $level_total;
        if ($level_num == 2) {
            unset($data[0]);
        }
        $result['list'] = $data;
        return $result;
    }
    public function show_api()
    {
    	$info_id = Dever::input('id');
    	$data['info'] = Dever::db('work/info')->find($info_id);
    	$ztime = $data['info']['cdate'];
    	$data['info']['cdate'] = date('Y-m-d H:i',$data['info']['cdate']);
    	$priority = Dever::db('work/priority')->find($data['info']['priority_id']);
    	$data['info']['priority_name'] = $priority['name'];
    	$data['info']['color'] = $priority['color'];
    	$admin = Dever::db('manage/admin')->find($data['info']['audit_admin']);
        // print_R($admin);die;
        $admin['group'] = explode(',',$admin['group']);
        foreach ($admin['group'] as $k => $v) {
            $group = Dever::db('manage/group')->find(array('company_id'=>$data['info']['company_id'],'id'=>$v));
        }
    	$data['info']['admin'] = $group['name'].'   /   '.$admin['username'];
		if ($data['info']['source']) {
			$source = Dever::db('work/q_source')->find($data['info']['source']);
			if ($source) {
				$data['info']['source_name'] = $source['name'];
			}
		} 
        if ($data['info']['branch_id']) {
            $branch_id = explode(',',$data['info']['branch_id']);
            if (isset($branch_id[0]) && $branch_id[0]>0) {
                $group = Dever::db('manage/group')->find($branch_id[0]);
                $data['info']['branch_name'] = '指派人：'.$group['name'];
            }
            if (isset($branch_id[1]) && $branch_id[1]>0) {
                $admin = Dever::db('manage/admin')->find($branch_id[1]);
                $data['info']['branch_name'] = $data['info']['branch_name'].'  /   '.$admin['username'];
            }
        }
		
		$data['info']['role_name'] = '';
        $data['info']['idcard'] = '';
		$user = Dever::db('work/user')->find(array('mobile'=>$data['info']['mobile']));
		if ($user) {
			$data['info']['user_name'] = $user['name'];
			$data['info']['mobile'] = $user['mobile'];
            if(isset($user['idcard']) && $user['idcard']) {
                $data['info']['idcard'] = '身份证号码：'.$user['idcard'];
            }
			
			if ($user['agent_uid'] && $user['agent_uid']>0) {
				$member = Dever::db('agent/member')->find($user['agent_uid']);
				if ($member && $member['role']) {
					$role = Dever::db('setting/role')->find($member['role']);
					if ($role) {
						$data['info']['role_name'] = '代理商角色：'.$role['name'];
					}
				}
			}
		}
		$data['info']['cate_name'] = '';
        $data['info']['product_name'] = '';
         $data['info']['question_name'] ='';
		if ($data['info']['cate_id']) {
            $cate_id = explode(',',$data['info']['cate_id']);
            if (isset($cate_id[0]) && $cate_id[0]) {
                $cate = Dever::db('work/q_cate')->find($cate_id[0]);
                if ($cate) {
                    $data['info']['cate_name'] = $cate['name'];
                }
            } else {
                $cate = array();
            }
            if (isset($cate_id[1]) && $cate_id[1]) {
                $question = Dever::db('work/question')->find($cate_id[1]);
                if ($question) {
                    $product = Dever::db('work/product')->find($question['product_id']);
                    if ($product) {
                        $data['info']['product_name'] = $product['name'];
                    }
                    $data['info']['question_name'] = $question['name'];
                }
            } else {
                $question = array();
            }
			
			if ($data['info']['cate_name'] && $data['info']['question_name']) {
				$data['info']['cate_name'] = $data['info']['cate_name'].'      /       '.$data['info']['question_name'];
			}
		}
		if ($data['info']['pic']) {
			$data['info']['pic'] = explode(',',$data['info']['pic']);
		}
		$data['info_log'] = Dever::db('work/info_log')->getAll(array('info_id'=>$info_id));
		foreach ($data['info_log'] as $k => $v) {
            $data['info_log'][$k]['admin_group'] = '';
			$data['info_log'][$k]['cdate'] = date('Y-m-d H:i:s',$v['cdate']);
			$admin = Dever::db('manage/admin')->find($v['admin_id']);
            $admin['group'] = explode(',',$admin['group']);
            if (isset($admin['group']) && $admin['group']) {
                foreach ($admin['group'] as $k1 => $v1) {
                    $admin_group = Dever::db('manage/group')->find(array('company_id'=>$data['info']['company_id'],'id'=>$v1));
                    if ($admin_group) {
                        $data['info_log'][$k]['admin_group'] = $admin_group['name'].'   /   '.$admin['username'];
                    }
                }
            }
            
    		$appoint = Dever::db('work/appoint')->find($v['appoint_id']);
    		if (isset($appoint) && $appoint) {
    			$data['info_log'][$k]['desc'] = $appoint['desc'];
    			$appoint_admin = explode(',',$appoint['admin_id']);
                if (isset($appoint_admin[0])) {
                    $appoint_group = Dever::db('manage/group')->find($appoint_admin[0]);
                } else {
                    $appoint_group = array();
                }
                if (isset($appoint_admin[1]) && $appoint_admin[1]) {
                    $appoint_ad = Dever::db('manage/admin')->find($appoint_admin[1]);
                } else {
                    $appoint_ad = array();
                }
        		
        		
        		if ($appoint_group && $appoint_ad) {
        			$data['info_log'][$k]['appoint_admin'] = '指派人：'. $appoint_group['name'].'   /   '.$appoint_ad['username'];
        		}
    		}
    		
    		$data['info_log'][$k]['image'] = '';
			if ($appoint['video']) {
				$data['info_log'][$k]['video'] = $appoint['video'];
			}
			if ($appoint['pic']) {
				$data['info_log'][$k]['pic'] = explode(',',$appoint['pic']);
			}
		}
		$data['s_zhi'] = array();
		$data['s_zhi']['cdate'] = date('Y-m-d H:i',time());

		$data['zhi'] = Dever::db('work/appoint')->getAll(array('info_id'=>$info_id));
		foreach ($data['zhi'] as $k => $v) {
			$time = $v['cdate'] - $ztime;
			$data['zhi'][$k]['time'] = floor($time%86400/3600).'小时'.floor($time%3600/60).'分钟'.floor($time%60).'秒';
			$admin = explode(',',$v['admin_id']);
            if (isset($admin[0]) && $admin[0]) {
                $group = Dever::db('manage/group')->find($admin[0]);
            } else {
                $group = array();
            }
			if (isset($admin[1]) && $admin[1]) {
                $adm = Dever::db('manage/admin')->find($admin[1]);
                if ($adm) {
                    $adm_username = $adm['username'];
                }
            } else {
                $adm_username = '';
            }
        	if ($group && $admin) {
                $data['zhi'][$k]['admin'] = $group['name'].'   /   '.$adm_username;
            } else {
                $data['zhi'][$k]['admin'] = '';
            }
        	
        	$data['zhi'][$k]['cdate'] = date('Y-m-d H:i',$v['cdate']);
        	$info_log = Dever::db('work/info_log')->find(array('appoint_id'=>$v['id']));
        	if ($info_log && $info_log['fdate']) {
        		$data['zhi'][$k]['finish'] = '完成关闭';
        		$data['zhi'][$k]['time'] ='';
        	} else {
        		if ($info_log && $info_log['cloce_date']) {
        			$data['zhi'][$k]['finish'] = '取消关闭';
        			$data['zhi'][$k]['time'] ='';
        		} else {
        			$data['zhi'][$k]['finish'] = '';
        			$data['zhi'][$k]['time'] = floor($time%86400/3600).'小时'.floor($time%3600/60).'分钟'.floor($time%60).'秒';
        		}
        	}
		}
        $data['jilu'] = array();
        if (!$data['zhi']) {
            if ($data['info']['fdate']) {
                // $time = $data['info']['fdate']-$ztime;
                $data['jilu']['time'] = date('Y-m-d H:i',$data['info']['fdate']);
                if ($data['info']['status'] == 3) {
                    $data['jilu']['finish'] = '完成关闭';
                } elseif ($data['info']['status'] == 4) {
                     $data['jilu']['finish'] = '取消关闭';
                }
             }
        }
        if ($data['info']['status'] < 3) {
            $data['hui'] = Dever::url('project/database/update?project=work&table=appoint&search_option_info_id='.$info_id, 'manage');
        } 
    	return Dever::render('index', $data);
    }
    
    public function back_api(){
    	$mobile = Dever::input('mobile');
    	
        $data = array();
        if ($mobile) {
        	if(!preg_match('/^1[3|5|6|7|8|9]\d{9}$/', $mobile)){
        		// Dever::alert('代理商手机号不正确');
            return  '代理商手机号不正确';
        }
        	$user = Dever::db('work/user')->find(array('mobile'=>$mobile));
        	if (!$user) {
                $data['user']['mobile'] = $mobile;
                $data['user']['type'] = '无系统关联关系';
                $data['user']['work'] = Dever::url('project/database/update?project=work&table=info&menu=work&search_option_mobile='.$mobile, 'manage');
                // print_R($data);die;
        		 return Dever::render('back', $data);
        	}
        	if ($user){
        		$table = array();
        		$user['role_name'] = '';
        		$user['type'] = '';
        		if ($user['agent_uid'] && $user['agent_uid'] > 0) {
        			$member = Dever::db('agent/member')->find($user['agent_uid']);
        			
        			if ($member['role']) {
        				$role = Dever::db('setting/role')->find($member['role']);
        				if ($role) {
        					$user['role_name'] = $role['name'];
         				}
        			}
        			$user['type'] = '代理商';
        			if ($user['option_uid'] && $user['option_uid']>0) {
        				$user['type'] = $user['type'].'<br/>期权账户';
        			}
        			if ($user['passport_uid'] && $user['passport_uid']>0) {
        				$user['type'] = $user['type'].'<br/>小程序';
        			}
                    $user['type'] = $user['type'].'<br/>客服系统用户';
	                
        		} else {
        			if ($user['option_uid'] && $user['option_uid']>0) {
        				$user['type'] = '期权账户';
        				if ($user['passport_uid'] && $user['passport_uid']>0) {
	        				$user['type'] = $user['type'].'<br/>小程序';
	        			}
                        $user['type'] = $user['type'].'<br/>客服系统用户';
        			} else {
        				if ($user['passport_uid'] && $user['passport_uid']>0) {
	        				$user['type'] = '小程序';
                            $user['type'] = $user['type'].'<br/>客服系统用户';
	        			} else {
                            $user['type'] = '客服系统用户';
	        				// $user['type'] = '无系统关联关系';
	        			}
        			}
        		}
        		if ($user['agent_uid']) {
        			$user['order'] = Dever::url('project/database/list?project=agent&table=order&p=1&search_option_mid='.$user['agent_uid'], 'manage');
        			$user['agent'] = Dever::url('project/database/list?project=agent&table=member_area&mid='.$user['agent_uid'].'&page_type=1&search_auth=1&page_type=1&jump=19','manage');
        			$user['soft'] = Dever::url('project/database/list?project=agent&table=soft_cash&search_option_mid='.$user['agent_uid'], 'manage');
        		}
        		if ($user['option_uid']) {
        			$user['option'] = Dever::url('project/database/list?project=option&table=member&search_option_id='.$user['option_uid'], 'manage');
        		}
        		$user['work'] = Dever::url('project/database/update?project=work&table=info&menu=work&search_option_mobile='.$mobile, 'manage');
        		$data['user'] = $user;
        		$data['info'] = Dever::db('work/info')->getHAll(array('mobile'=>$mobile));
        		$config = Dever::db('work/info')->config['config_status'];
        		foreach($data['info'] as $k => $v) {
        			$data['info'][$k]['cdate'] = date('Y-m-d H:i',$v['cdate']);
        			$data['info'][$k]['fdate'] = date('Y-m-d H:i',$v['fdate']);
        			$cate = Dever::db('work/q_cate')->find(array('id'=>$v['cate_id']));
        			$data['info'][$k]['cate_name'] = $cate['name'];
        			$you = Dever::db('work/priority')->find(array('id'=>$v['priority_id']));
        			$data['info'][$k]['you'] = $you['name'];
                    $v['branch_id'] = explode(',',$v['branch_id']);
                    if (isset($v['branch_id'][0]) && $v['branch_id'][0]>0){
                        $group = Dever::db('manage/group')->find(array('id'=>$v['branch_id'][0],'company_id'=>$v['company_id']));
                        $data['info'][$k]['branch'] = $group['name'];
                    }
                    if (isset($v['branch_id'][1]) && $v['branch_id'][1]>0){
                        $admin = Dever::db('manage/admin')->find(array('id'=>$v['branch_id'][1]));
                        $data['info'][$k]['branch'] = $group['name'].'/'.$admin['username'];
                    }
        			
        			
        			$data['info'][$k]['status'] = Dever::status($config,$v['status']);
        			$data['info'][$k]['url'] = Dever::url('lib/appoint.show&id='.$v['id'],'work');
        			if ($v['status']<3) {
        				$data['info'][$k]['zhipai'] =  Dever::url('project/database/update?project=work&table=appoint&search_option_info_id='.$v['id'], 'manage');
        			} else {
        				$data['info'][$k]['zhipai'] = '';
        			}
        			
        		}
        		
            }
            $data['page'] = Dever::page("current");
        }
        return Dever::render('back', $data);
    }

    public function callback_api(){
        $mobile = Dever::input('phone');
        $type = Dever::input('type');
        
        $data = array();
        if ($mobile) {
            $state = 2;
            if(!preg_match('/^1[3|5|6|7|8|9]\d{9}$/', $mobile)){
                // Dever::alert('代理商手机号不正确');
                $state = 1;
                if ($type == 1) {
                    return  '手机号不正确';
                }
            }

            if ($state == 1) {
                $data = array();
                return Dever::render('callback', $data); 
            }
            $data['user']['title'] = '电话号码';
            $data['user']['mobile'] = $mobile;
            $data['user']['username'] = $mobile;
            $member = Dever::db('agent/member')->find(array('mobile'=>$mobile));
            $option = Dever::db('option/member')->find(array('mobile'=>$mobile));
            $passport = Dever::db('passport/user')->find(array('mobile'=>$mobile));
            $work = Dever::db('work/user')->find(array('mobile'=>$mobile));
            $user = array();
            $data['user']['order'] = '';
            $data['user']['agent'] = '';
            $data['user']['soft'] = '';
            $data['user']['option'] = '';
            $user['role'] = '';
            if (!$member && !$option && !$passport && !$work) {
                 $user['name'] = $mobile;
                 $user['role'] = '';
                 $user['type'][] = '无系统关联关系';
            } else {
                if ($work) {
                    $user['name'] = $work['name'].'<br/>'.$mobile;
                    $user['type'][] = '客服系统用户';
                }
                if ($option) {
                    $user['name'] = $option['name'].'<br/>'.$mobile;
                    $user['type'][] = '期权账户';
                    $data['user']['option'] = Dever::url('project/database/list?project=option&table=member&search_option_id='.$option['id'], 'manage');
                    $data['user']['option'] = Dever::url('home?link=' . urlencode( $data['user']['option']) . '&group=8&parent_menu=menu_279&menu=menu_279.menu_291' , 'manage');
                }
                if ($passport) {
                    $user['name'] = $passport['username'].'<br/>'.$mobile;
                    $user['type'][] = '小程序用户';
                }
                if ($member) {
                    if ($member['role']) {
                        $role = Dever::db('setting/role')->find($member['role']);
                        if ($role['name']) {
                            $role_name = '<br/>'.$role['name'];
                        }
                        $user['role'] =  '/角色';
                    } else {
                        $role_name = '';
                        $user['role'] = '';
                    }
                    $user['name'] = $member['name'].'<br/>'.$mobile.$role_name;
                    $user['type'][] = '代理商';
                    

                    $data['user']['order'] = Dever::url('project/database/list?project=agent&table=order&p=1&search_option_mid='.$member['id'], 'manage');
                    $data['user']['order'] = Dever::url('home?link=' . urlencode($data['user']['order']) . '&group=7&parent_menu=menu_240&menu=agent.order', 'manage');

                    $data['user']['agent'] = Dever::url('project/database/list?project=agent&table=member_area&mid='.$member['id'].'&page_type=1&search_auth=1&page_type=1&jump=19','manage');
                    $data['user']['agent'] = Dever::url('home?link=' . urlencode($data['user']['agent']) . '&group=7&parent_menu=menu_240&menu=agent.member' , 'manage');

                    $data['user']['soft'] = Dever::url('project/database/list?project=agent&table=soft_cash&search_option_mid='.$member['id'], 'manage');
                    $data['user']['soft'] = Dever::url('home?link=' . urlencode($data['user']['soft']) . '&group=7&parent_menu=menu_240&menu=agent.soft_cash' , 'manage');
                }
                $data['user']['title'] = '名称/电话号码' . $user['role'];
            }
            
            $data['user']['type'] = implode('<br />', $user['type']);
            $data['user']['username'] = $user['name'];
            
            $data['user']['work'] = Dever::url('project/database/update?project=work&table=info&menu=work&search_option_mobile='.$mobile, 'manage');
            $data['user']['work'] = Dever::url('home?link=' . urlencode($data['user']['work']) . '&group=10&parent_menu=work&menu=work.add' , 'manage');

            $data['user']['work_list'] = Dever::url('project/database/list&project=work&table=info&menu=work&search_option_state=1&search_api_mobile='.$mobile, 'manage');
            $data['user']['work_list'] = Dever::url('home?link=' . urlencode($data['user']['work_list']) . '&group=10&parent_menu=work&menu=work.info' , 'manage');

             return Dever::render('callback', $data); 
        }else {
            $data = array();
            return Dever::render('callback', $data); 
        }
    } 
}