<?php

    class SVALog {

        public $logPath;
        public $logFile;
        public $logDebugLevel;


        public function __construct($logPath,$logFile,$logDebugLevel){

            $this->logPath = $logPath;
            $this->logFile = $logFile;
            $this->logDebugLevel = $logDebugLevel;


        }

        public function writeSystemLog($content){

            $currentDate = date("Y-m-d H:i:s");
            $content= $currentDate."  ".$content."\n";
            $logTarget = $this->logPath."/".$this->logFile;

            $fp= fopen($logTarget,"a+");
            fputs($fp,$content);
            fclose($fp);   
        } 


        public function writeBasicSystemLog($content){

            $content= $content."\n";
            $logTarget = $this->logPath."/".$this->logFile;

            $fp= fopen($logTarget,"a+");
            fputs($fp,$content);
            fclose($fp);
        }

        public function writeXmlFile($xmlPath,$xmlContent,$msisdn){
            $status = true;

            $directory = $xmlPath.date("Ymd");
            //echo $directory;
            $file = "/".$msisdn.".xml";
            $logTarget = $directory.$file;

            if(is_dir($directory)){

                $fp= fopen($logTarget,"a+");
                fputs($fp,$xmlContent);
                fclose($fp); 

            }
            else {

                if(mkdir($directory, "0755")){

                    $fp= fopen($logTarget,"a+");
                    fputs($fp,$xmlContent);
                    fclose($fp);         


                }
                else {
                    $status = false;
                    $this->writeSystemLog("Impossible de creer le dossier!!");

                }
            }

            return $status;

        }



        
         public function writeInputFile($content, $mode){

            //$content= $content."\n";
            $logTarget = $this->logPath."/".$this->logFile;

            $fp= fopen($logTarget,$mode);
            fputs($fp,$content);
            fclose($fp);
        }




    }

?>
