<?php 
               $user =& JFactory::getUser()->get('id');

               $c_id = JRequest::getVar('c_id');
              
                $database = &JFactory::getDBO();

	      
	
		$query	= "SELECT text_0,text_1,text_9,text_5,text_6,text_4,sradio,notes FROM #__chronoforms_freetrialEdit  WHERE cf_id = '$c_id'";
		$database->setQuery($query);
		$check = $database->loadobjectlist();
		
              
		foreach($check as $result)
                { 
                $ck = $result->text_0;
                $name= explode(" ",$ck); 
                $workphone = $result->text_6;
                $work = explode("-",$workphone);
                $workph = '('.$work[0].')'."$work[1]-$work[2]";
                $data = new stdClass;
                $data->cf_user_id = $user;
                $data->freetrial_id = $c_id;
		$data->firstname = $name[0];
                $data->lastname = $name[1];
		$data->address= $result->text_1;
		$data->city	= $result->text_9;
		//$data->postalcode = $result->text_5;
		$data->workphone = $workph;
		$data->email = $result->text_4;
                $data->status = $result->sradio;
                $data->notes = $result->notes;
                

                $query= "SELECT firstname, lastname FROM jos_chronoforms_Memberform  WHERE firstname ='$name[0]' AND lastname='$name[1]'"; 
		$database->setQuery($query);
		$check = $database->loadresult();
		
		if ($check){
	        echo "<font color ='red'><strong>User already a Member</storng></font>";
		}
                else
                {
  
               if($database->insertObject('jos_chronoforms_Memberform', $data ))
			 {
				echo "<font color ='green'><strong>$result->text_0 successfully converted to a Member</storng></font>";
			 }
			 else
			 {
				echo "error with conversion";
			 }	   
                }

               
    }
?>