<?php
/*
    สำหรับตรวจสอบการทำงานของฟังก์ชั่น
    1.curl
    2.simpleXML
*/
?>
<head>
<title>สำหรับตรวจสอบการทำงานของฟังก์ชั่น curl และ simpleXML</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
</head>
<?php
    
echo "สำหรับตรวจสอบการทำงานของฟังก์ชั่น curl และ simpleXML <br /><br />";
/* curl info http_code
    http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html
    [Informational 1xx]
    [Successful 2xx]
    [Redirection 3xx]
    [Client Error 4xx]
    [Server Error 5xx]
*/
$http_code = array(
'100'=>"Continue",
'101'=>"Switching Protocols",
'200'=>"OK",
'201'=>"Created",
'202'=>"Accepted",
'203'=>"Non-Authoritative Information",
'204'=>"No Content",
'205'=>"Reset Content",
'206'=>"Partial Content",
'300'=>"Multiple Choices",
'301'=>"Moved Permanently",
'302'=>"Found",
'303'=>"See Other",
'304'=>"Not Modified",
'305'=>"Use Proxy",
'306'=>"(Unused)",
'307'=>"Temporary Redirect",
'400'=>"Bad Request",
'401'=>"Unauthorized",
'402'=>"Payment Required",
'403'=>"Forbidden",
'404'=>"Not Found",
'405'=>"Method Not Allowed",
'406'=>"Not Acceptable",
'407'=>"Proxy Authentication Required",
'408'=>"Request Timeout",
'409'=>"Conflict",
'410'=>"Gone",
'411'=>"Length Required",
'412'=>"Precondition Failed",
'413'=>"Request Entity Too Large",
'414'=>"Request-URI Too Long",
'415'=>"Unsupported Media Type",
'416'=>"Requested Range Not Satisfiable",
'417'=>"Expectation Failed",
'500'=>"Internal Server Error",
'501'=>"Not Implemented",
'502'=>"Bad Gateway",
'503'=>"Service Unavailable",
'504'=>"Gateway Timeout"
);
        
//----[]--- ฟังก์ชั่น check curl
        
function iscurlinstalled() {
            if  (
in_array('curl'get_loaded_extensions())) {
                return 
true;
            }
            else{
                return 
false;
            }
        }
        
//---[]--- ฟังก์ชั่น check  xml
        
function isxmlinstalled() {
            if  (
in_array('xml'get_loaded_extensions())) {
                return 
true;
            }
            else{
                return 
false;
            }
        }
        function 
simplexmlexists(){
            if (
function_exists('simplexml_load_string')) {
                return  
true;
            }else{
                return 
false;
            }
        }
        if(
iscurlinstalled() and isxmlinstalled() and simplexmlexists()) {
            if  (
in_array('curl'get_loaded_extensions())) {
                echo 
'curl OK <br />';
            }
            if  (
in_array('xml'get_loaded_extensions())) {
                echo 
'xml OK <br />';
            }
            echo 
'<br />';
            
/* receive_data   */
                //---[]--- start curl function
                //$url = $this->config->item('url_reg2ea')."curl_curriculum";
                //$url = "http://10.16.65.95/mis/index_codeigniter.php/eregis/export/curl_curriculum";
                
$url "http://localhost/check_server/export_xml.php";
                
$xmlStr "";
                
$ch curl_init();
                
curl_setopt($chCURLOPT_URL$url);
                
curl_setopt($chCURLOPT_RETURNTRANSFERtrue);
                
curl_setopt($chCURLOPT_POSTtrue);
                
curl_setopt($chCURLOPT_POSTFIELDS$xmlStr);
                
curl_setopt($chCURLOPT_HTTPHEADER, array('Expect:'));
                
$rs curl_exec($ch);
                
$httpcode curl_getinfo($chCURLINFO_HTTP_CODE);
                
$info curl_getinfo($ch);
                
curl_close ($ch);
                
//---[]--- end curl function
                
if (empty($info['http_code'])) {
                    die(
"No HTTP code was returned");
                } else {
                   
                    
// echo results
                    
echo "The server responded: ";
                    echo 
$info['http_code'] . " (" $http_code[$info['http_code']]." )<br />";
                }
                
                
$rs_cur simplexml_load_string($rs);
                echo 
'<br /> Receive data :<br />';
                
print_r($rs);
                echo 
'<br /><br />';
                
//print_r($curl_getinfo);
                //echo $rs_cur;
            /* end receive_data   */
        
// end if($this->iscurlinstalled() && $this->isxmlinstalled())
        
else {
            echo 
"<br />ไม่สามารถอัพเดทข้อมูลนักศึกษาจากระบบทะเบียนได้ <br />กรุณาตรวจสอบการติดตั้ง cURL และ SimpleXML<br />ติดต่อผู้ดูแลระบบ <br />";
            if (
function_exists('simplexml_load_string')) {
                return  
true;
            }else{
                echo 
"ไม่พบ ฟังก์ชั่น simplexml_load_string <br />";
            }
        }
    echo 
"<br />สิ้นสุดการทดสอบ<br />";
?>