Example #1
0
 /**
  * Creates an array containing the rows given in the csv-file
  *
  * @return bool
  * @throws class_exception
  */
 public function createArrayFromFile()
 {
     //all needed params given?
     if ($this->arrMapping != "" && $this->strFilename != "") {
         //init final array
         $this->arrData = array();
         $arrFinalArray = array();
         //open pointer on file
         $objFilesystem = new class_filesystem();
         $objFilesystem->openFilePointer($this->strFilename, "r");
         $strRow = $objFilesystem->readLineFromFile();
         if ($strRow === false) {
             return false;
         }
         if ($this->intImportRowOffset > 0) {
             for ($intI = 0; $intI < $this->intImportRowOffset; $intI++) {
                 $strRow = $objFilesystem->readLineFromFile();
             }
         }
         //first row are the headers
         $arrHeader = explode($this->strDelimiter, $strRow);
         $strRow = $objFilesystem->readLineFromFile();
         while ($strRow !== false) {
             if (uniStrlen($strRow) > 0) {
                 $arrOneRow = explode($this->strDelimiter, $strRow);
                 $arrCSVRow = array();
                 foreach ($arrHeader as $intKey => $strHeader) {
                     $strHeader = trim($strHeader);
                     //include the mapping specified
                     //add an encloser?
                     if ($this->strTextEncloser != null) {
                         $strHeader = uniStrReplace($this->strTextEncloser, "", trim($strHeader));
                     }
                     $strRowKey = $this->arrMapping[$strHeader];
                     $strValue = $arrOneRow[$intKey];
                     //remove an encloser?
                     if ($this->strTextEncloser != null) {
                         $strValue = uniStrReplace($this->strTextEncloser, "", trim($strValue));
                     }
                     $arrCSVRow[$strRowKey] = $strValue;
                 }
                 //add to final array
                 $arrFinalArray[] = $arrCSVRow;
             }
             $strRow = $objFilesystem->readLineFromFile();
         }
         $objFilesystem->closeFilePointer();
         $this->setArrData($arrFinalArray);
         return true;
     } else {
         throw new class_exception("cannot proceed, needed values (mapping or filename) missing", class_exception::$level_ERROR);
     }
 }
 /**
  * Fetches the latest entries from the current systemlog.
  * The entries can be limited by the optional param latestEntry.
  * If given, only entries created after the passed date will be returned.
  * The format of latestEntry is similar to the date returned, so YYYY-MM-DD HH:MM:SS
  * The structure is returned like:
  * <entries>
  *   <entry>
  *      <level></level>
  *      <date></date>
  *      <session></session>
  *      <content></content>
  *   </entry>
  * </entries>
  *
  * @return string
  * @permissions right3
  */
 protected function actionSystemLog()
 {
     $strReturn = "";
     $intStartDate = false;
     if ($this->getParam("latestEntry") != "") {
         $intStartDate = strtotime($this->getParam("latestEntry"));
     }
     //read the last few lines
     $objFile = new class_filesystem();
     $arrDetails = $objFile->getFileDetails("/system/debug/systemlog.log");
     $intOffset = 0;
     $bitSkip = false;
     if ($arrDetails["filesize"] > 20000) {
         $intOffset = $arrDetails["filesize"] - 20000;
         $bitSkip = true;
     }
     $objFile->openFilePointer("/system/debug/systemlog.log", "r");
     //forward to the new offset, skip entry
     if ($intOffset > 0) {
         $objFile->setFilePointerOffset($intOffset);
     }
     $arrRows = array();
     $strRow = $objFile->readLineFromFile();
     while ($strRow !== false) {
         if (!$bitSkip && trim($strRow) > 0) {
             $arrRows[] = $strRow;
         }
         $bitSkip = false;
         $strRow = $objFile->readLineFromFile();
     }
     $objFile->closeFilePointer();
     $strReturn .= "<entries>\n";
     $arrRows = array_reverse($arrRows);
     foreach ($arrRows as $strSingleRow) {
         //parse entry
         $strDate = uniSubstr($strSingleRow, 0, 19);
         $strSingleRow = uniSubstr($strSingleRow, 20);
         $intTempPos = uniStrpos($strSingleRow, " ");
         $strLevel = uniSubstr($strSingleRow, 0, $intTempPos);
         $strSingleRow = uniSubstr($strSingleRow, $intTempPos + 1);
         $intTempPos = uniStrpos($strSingleRow, ")") + 1;
         $strSession = uniSubstr($strSingleRow, 0, $intTempPos);
         $strLogEntry = uniSubstr($strSingleRow, $intTempPos);
         if ($intStartDate !== false) {
             $intCurDate = strtotime($strDate);
             if ($intStartDate >= $intCurDate) {
                 continue;
             }
         }
         $strReturn .= "\t<entry>\n";
         $strReturn .= "\t\t<level>" . $strLevel . "</level>\n";
         $strReturn .= "\t\t<date>" . $strDate . "</date>\n";
         $strReturn .= "\t\t<session>" . $strSession . "</session>\n";
         $strReturn .= "\t\t<content>" . xmlSafeString(strip_tags($strLogEntry)) . "</content>\n";
         $strReturn .= "\t</entry>\n";
     }
     $strReturn .= "</entries>";
     return $strReturn;
 }