function __construct($warningLevelFile = './tmp/errorLevel.csv', $mailSettings = false, $cronSettings = false, $libPath = './lib/')
 {
     //=== includes and parameter validation ===//
     if (@(include_once $libPath . 'class.fileManager.inc.php')) {
         $pathValidator = new fileManager();
         if (!$pathValidator->validPath($warningLevelFile, false)) {
             throw new Exception('Invalid constructor - first parameter must be a valid file path.');
         } else {
             $this->warningLevelFile = $warningLevelFile;
         }
     } else {
         trigger_error('Unable to include fileManager for path validation.', E_USER_WARNING);
         if (!is_string($warningLevelFile)) {
             throw new Exception('Invalid constructor - first parameter must be a string (file path expected).');
         } else {
             $this->warningLevelFile = $warningLevelFile;
         }
     }
     if ($mailSettings != false) {
         if (!isset($mailSettings['server']) || !isset($mailSettings['subject']) || !isset($mailSettings['title']) || !isset($mailSettings['from']) || !isset($mailSettings['recipientsByLevel'])) {
             return false;
         } else {
             $this->mailSettings = $mailSettings;
         }
     } else {
         trigger_error('No valid mail settings found.', E_USER_NOTICE);
         $this->mailSettings = false;
     }
     if ($cronSettings != false) {
         if (!isset($cronSettings['computer']) || !isset($cronSettings['user']) || !isset($cronSettings['password'])) {
             return false;
         }
         if (@(include_once $libPath . 'class.cronManager.inc.php')) {
             $isWin = strpos(PHP_OS, 'WIN') === 0;
             //0, not false!;
             if ($isWin) {
                 $this->cronManager = new cronManager($cronSettings['password'], $cronSettings['computer'], $cronSettings['user']);
             } else {
                 if (empty($this->cronSettings['tmpFile'])) {
                     $this->cronSettings['tmpFile'] = '/tmp/.crontabTemp.txt';
                 }
                 $this->cronManager = new cronManager($cronSettings['tmpFile']);
             }
         }
     } else {
         trigger_error('No valid cron settings found.', E_USER_WARNING);
         $this->cronManager = false;
     }
     //=== includes only ===//
     if (!@(include_once $libPath . 'class.sensor.inc.php')) {
         throw new Exception('Unable to include class sensor for sensorCarer.');
     }
     //=== variable initialisation ===//
     $this->values = array();
     $this->libPath = $libPath;
     $this->internalErrorIdentifier = 'internalError';
 }
Ejemplo n.º 2
0
 /**
  * @covers chromephpManager::_getConfigPath
  */
 public function testGetConfigPath()
 {
     $oFileManeger = new fileManager();
     $oTestObj = $this->getProxyClass('chromephpManager');
     $sResult = $oFileManeger->getTmpPath() . 'config.json';
     $this->assertNull($oTestObj->getNonPublicVar('_sConfigPath'));
     $this->assertSame($sResult, $oTestObj->UNITgetConfigPath());
     $this->assertSame($sResult, $oTestObj->getNonPublicVar('_sConfigPath'));
 }
 function __construct($sensorListPath, $phpLocation = 'php', $libPath = './lib/', $settings = array())
 {
     //=== include libraries and validate parameter ===//
     if (!@(include_once $libPath . 'class.csvManager.inc.php')) {
         throw new Exception('Unable to include csvNabager for sensorManager.');
     }
     $this->csvManager = new csvManager();
     if (@(include_once $libPath . 'class.fileManager.inc.php')) {
         $pathValidator = new fileManager();
         if (!$pathValidator->validPath($sensorListPath, false)) {
             throw new Exception('Invalid constructor - first parameter must be a valid file path.');
         } else {
             $this->sensorListPath = $sensorListPath;
         }
     } else {
         trigger_error('Unable to include fileManager for path validation.', E_USER_WARNING);
         if (!is_string($sensorListPath)) {
             throw new Exception('Invalid constructor - first parameter must be a string (file path expected).');
         }
     }
     $this->isWin = strpos(PHP_OS, 'WIN') === 0;
     //0, not false!
     if (@(include_once $libPath . 'class.cronManager.inc.php')) {
         if ($this->isWin) {
             $this->cronManager = new cronManager($settings['password'], $settings['computer'], $settings['user']);
         } else {
             if (empty($settings['tmpFile'])) {
                 $settings['tmpFile'] = '/tmp/.crontabTemp.txt';
             }
             $this->cronManager = new cronManager($settings['tmpFile']);
         }
     } else {
         throw new Exception('Unable to include cronManager for path validation.');
     }
     //=== define attributes ===//
     $this->mandatoryColumns = array('id', 'type', 'target', 'green-rec-min', 'orange-rec-min', 'yellow-trigger-ms', 'orange-trigger-ms');
     $this->optionalColumns = array('source', 'user', 'pass', 'subpath', 'yellow-rec-min', 'red-rec-min', 'red-trigger-min');
     $this->idCol = $this->mandatoryColumns[0];
     $this->phpLocation = $phpLocation;
 }
$imgUploader = new fileManager();
$imgUploader->setDestination($_SERVER['DOCUMENT_ROOT'] . '/images/profiles/');
$imgUploader->setAllowedExtensions('jpg');
$imgUploader->setFileName('user_profile.jpg');
$imgUploader->upload($_FILES['profileimage']);
$imgUploader->setDestination($_SERVER['DOCUMENT_ROOT'] . '/images/thumbs/');
$imgUploader->setAllowedExtensions(array('jpg', 'gif', 'png'));
$imgUploader->setFileName($_FILES['thumbnailimage']['tmp_name'][0]);
$imgUploader->upload($_FILES['thumbnailimage']);
//Notice, I didn't set $imgUploader->setPrintError to false, so it will automatically print errors on screen if they occur. If you wanted to handle your own error messages, you could do the following using the same above example:
//form data
//$_FILES['profileimage']
//$_FILES['thumbnailimage']
//include the code above
include 'filemanager.php';
$imgUploader = new fileManager();
$imgUploader->setPrintError(FALSE);
//store errors
$errors = '';
$imgUploader->setDestination($_SERVER['DOCUMENT_ROOT'] . '/images/profiles/');
$imgUploader->setAllowedExtensions('jpg');
$imgUploader->setFileName('user_profile.jpg');
$imgUploader->upload($_FILES['profileimage']);
$errors .= $imgUploader->error;
$imgUploader->setDestination($_SERVER['DOCUMENT_ROOT'] . '/images/thumbs/');
$imgUploader->setAllowedExtensions(array('jpg', 'gif', 'png'));
$imgUploader->setFileName($_FILES['thumbnailimage']['tmp_name'][0]);
$imgUploader->upload($_FILES['thumbnailimage']);
$errors .= $imgUploader->error;
if ($errors) {
    print $errors;
 function _exec_by_status($status, $folder_id, $user_id, $user_profile_id, $course_id)
 {
     /*
      * We have success by default ;-)
      */
     $this->SetViewVariable('opstat', 'success');
     /*
      * Select the action given by status
      */
     switch ($status) {
         case 'list':
             /*
              * First, we must check our permissions
              */
             if (!$this->obj_data->checkFolderPerms("r", $course_id, $user_profile_id, $folder_id)) {
                 $this->giveControl('main', 'miguel_CMain');
             }
             /*
              * Get/set order list:
              */
             /*
              * Relation among fileds of tables folder and document about order
              */
             $fdOrderRelations = array("id" => array("folder_id", "document.document_id"), "name" => array("folder_name", "document.document_name"), "date" => array("folder_date", "document.date_publish,\r\n\t\t\t\t\t\tdocument.document_name"), "comment" => array("folder_comment", "document.document_comment"), "user_alias" => array("folder_name", "user.user_alias,\r\n\t\t\t\t\t\tdocument.document_name"), "accepted" => array("folder_name", "document.document_accepted,\r\n\t\t\t\t\t\tdocument.document_name"), "mime" => array("folder_name", "document.document_mime,\r\n\t\t\t\t\t\tdocument.document_name"), "actions" => array("folder_perms, foldeer_name", "document.document_name"));
             /*
              * This is somewhat a "hack" but it works and doesn't overload the server.
              * The problem is that we cannot use in_array('orderby', $fdOrderRelations)
              * because..??.. in_array sucks! 
              */
             $fdOrderbyArray = array("id", "name", "date", "comment", "user_alias", "accepted", "mime", "actions");
             $this->setViewVariable('fdOrderbyArray', $fdOrderbyArray);
             if ($this->IsSetVar('orderby', 'orderhow') && in_array($this->getViewVariable('orderby'), $fdOrderbyArray) && ($this->getViewVariable('orderhow') == 0 || $this->getViewVariable('orderhow') == 1)) {
                 $orderby = $this->getViewVariable('orderby');
                 $orderhow = $this->getViewVariable('orderhow');
             } else {
                 $orderby = 'name';
                 $this->setViewVariable('orderby', $orderby);
                 $orderhow = 0;
                 $this->setViewVariable('orderhow', $orderhow);
             }
             /*
              * No real action to execute,
              * but we'll get some data that we'll need in View class
              */
             $this->setViewVariable('FolderList', $this->obj_data->getFolderList($course_id, $folder_id, $user_profile_id, $fdOrderRelations[$orderby][0], $orderhow));
             $this->setViewVariable('FileList', $this->obj_data->getFileList($course_id, $folder_id, $user_profile_id, $user_id, $fdOrderRelations[$orderby][1], $orderhow));
             $this->setViewVariable('FolderProperties', $this->obj_data->getFolderProperties($course_id, $folder_id, $user_profile_id, $user_id));
             $this->setViewVariable('FolderDeeps', $this->obj_data->getFolderDeeps($course_id, $folder_id));
             break;
         case 'send_file':
             /*
              * First, we must check our permissions
              */
             if (!$this->obj_data->checkFilePerms("w", $course_id, $user_id, $user_profile_id, $this->getViewVariable('document_id'))) {
                 $this->giveControl('main', 'miguel_CMain');
             }
             /*
              * We get the junk var of actual file from the BBDD if we're updating
              * instead of creating one
              */
             if ($this->IsSetVar('document_id')) {
                 $this->setViewVariable('document_junk', $this->obj_data->getFileJunk($course_id, $this->getViewVariable('document_id')));
             }
             /*
              * Send a file
              */
             if ($this->IsSetVar('submit') && $_FILES['filename']['tmp_name'] != NULL) {
                 include_once Util::app_Path("filemanager/include/classes/filemanager.class.php");
                 $md5 = md5_file($_FILES['filename']['tmp_name']);
                 if (!$this->getViewVariable('filezip')) {
                     if (!($file_properties = fileManager::uploadFile($_FILES['filename'], $this->getViewVariable('document_junk')))) {
                         $this->SetViewVariable('opstat', 'fserror');
                     }
                     if (!$this->obj_data->insertFile($file_properties['name'], $file_properties['type'], $file_properties['size'], $file_properties['junk'], $md5, $this->getViewVariable('document_comment'), $course_id, $user_id, $folder_id, NULL, $this->getViewVariable('document_id'), $this->getViewVariable('document_accepted'))) {
                         $this->SetViewVariable('opstat', 'dberror');
                     }
                 } else {
                     /*
                      * ZIP files: 
                      */
                     if (!($listUploadFiles = fileManager::uploadFileZip($_FILES['filename']))) {
                         $this->SetViewVariable('opstat', 'fserror');
                     }
                     $listCount = count($listUploadFiles);
                     if (!($folder_zip_id = $this->obj_data->insertFolder($_FILES['filename']['name'], $course_id, $folder_id, $ZipElement['comment'], $this->getViewVariable('shared'), $this->getViewVariable('folder_perms'), NULL))) {
                         $this->SetViewVariable('opstat', 'dberror');
                     }
                     foreach ($listUploadFiles as $ZipElement) {
                         if (!$ZipElement['folder']) {
                             /*
                              * Upload the zip files in the folders they belong to
                              *
                              * $folder_parent_id -> find dirname() in 
                              * $listFolder[ruta_completa] and obtain name and id
                              */
                             $search_folder_name = basename(dirname($ZipElement['stored_filename']));
                             $search_folder_dir = dirname(dirname($ZipElement['stored_filename']));
                             $j = 0;
                             $countList = count($listFolder);
                             $find = false;
                             $folder_parent_id = $folder_zip_id;
                             while ($j < $countList && !$find) {
                                 if ($listFolder[$j][0] == $search_folder_name && $listFolder[$j][1] == $search_folder_dir) {
                                     $folder_parent_id = $listFolder[$j][2];
                                     $find = true;
                                 }
                                 $j++;
                             }
                             $fileJunk = substr(md5(time()), 10, 20);
                             $fileFullPath = Util::app_Path("../var/data/") . basename($ZipElement['stored_filename'] . "-{$fileJunk}");
                             if (!copy($ZipElement['filename'], $fileFullPath)) {
                                 $this->SetViewVariable('opstat', 'fserror');
                             }
                             if (!$this->obj_data->insertFile(basename($ZipElement['stored_filename']), "application/download", $ZipElement['size'], md5_file($fileFullPath), $fileJunk, $ZipElement['comment'], $user_id, $course_id, $folder_id, NULL, NULL, $this->getViewVariable('document_accepted'), 1)) {
                                 $this->SetViewVariable('opstat', 'zipdirdberror');
                             }
                         } else {
                             /*
                              * Recreate the zip dirs structure
                              *
                              * Create a folder list (id, folder_name, folder_full_path)
                              * needed to know the path deepness:
                              * folder_name -> basename(path)
                              * parent_folder_name -> basename(dirname(ruta))
                              */
                             $folder_name = basename($ZipElement['stored_filename']);
                             $folder_dir = dirname($ZipElement['stored_filename']);
                             $folder_parent_id = $folder_zip_id;
                             if ($folder_dir != '.') {
                                 /*
                                  * Find in listFolder if current element
                                  * is contained into other folder.
                                  * In order to do that, it looks for
                                  * folder_name & folder_dir in current
                                  * folder_dir and obtains the id.
                                  */
                                 $search_folder_name = basename($folder_dir);
                                 $search_folder_dir = dirname($folder_dir);
                                 $j = 0;
                                 $countList = count($listFolder);
                                 $find = false;
                                 while ($j < $countList && !$find) {
                                     if ($listFolder[$j][0] == $search_folder_name && $listFolder[$j][1] == $search_folder_dir) {
                                         $folder_parent_id = $listFolder[$j][2];
                                         $find = true;
                                     }
                                     $j++;
                                 }
                             }
                             /*
                              * Finally insert the folder and create a new
                              * element in $listFolder for it
                              */
                             if (!($_folder_id = $this->obj_data->insertFolder($folder_name, $course_id, $folder_parent_id, $ZipElement['comment'], $this->getViewVariable('shared'), $this->getViewVariable('folder_perms'), NULL))) {
                                 $this->SetViewVariable('zipdir', 'error');
                                 $this->SetViewVariable('opstat', 'dberror');
                             }
                             $listFolder[] = array($folder_name, $folder_dir, $_folder_id);
                         }
                     }
                 }
             } else {
                 /*
                  * If form is not being submitted but we're editing a file
                  * then we'll get document vars that we'll need in View
                  */
                 if ($this->IsSetVar('document_id')) {
                     $this->setViewVariable("FileProperties", $this->obj_data->getFileProperties($this->getViewVariable('document_id'), $course_id, $user_profile_id, $user_id));
                 }
             }
             break;
         case 'send_folder':
             /*
              * First, we must check our permissions
              */
             if (!$this->obj_data->checkFolderPerms("w", $course_id, $user_profile_id, $this->getViewVariable('folder_id'))) {
                 $this->giveControl('main', 'miguel_CMain');
             }
             /*
              * Submit a folder (this means either update or create one).
              */
             if ($this->IsSetVar('submit', 'folder_name')) {
                 if (!$this->obj_data->insertFolder($this->getViewVariable('folder_name'), $course_id, $folder_id, $this->getViewVariable('folder_comment'), $this->getViewVariable('shared'), $this->getViewVariable('folder_perms'), $this->getViewVariable('folder_id'))) {
                     $this->SetViewVariable('opstat', 'dberror');
                 }
             } else {
                 /*
                  * If form is not being submitted but we're editing a folder
                  * then we'll get document vars that we'll need in View
                  */
                 if ($this->IsSetVar('folder_id')) {
                     $this->setViewVariable("FolderProperties", $this->obj_data->getFolderProperties($this->getViewVariable('folder_id'), $course_id, $user_profile_id));
                 }
             }
             break;
         case 'send_document':
             /*
              * First, we must check our permissions
              */
             if (!$this->obj_data->checkFilePerms("w", $course_id, $user_id, $user_profile_id, $this->getViewVariable('document_id'))) {
                 $this->giveControl('main', 'miguel_CMain');
             }
             /*
              * We get the junk var of actual file from the BBDD if we're updating
              * instead of creating one
              */
             if ($this->IsSetVar('document_id')) {
                 $this->setViewVariable('document_junk', $this->obj_data->getFileJunk($course_id, $this->getViewVariable('document_id')));
             }
             /*
              * Send a document (that means either create or update a document)
              */
             if ($this->IsSetVar('submit', 'name', 'content', 'type')) {
                 include_once Util::app_Path("filemanager/include/classes/filemanager.class.php");
                 $md5 = md5($this->getViewVariable('document_content'));
                 if (!($file_properties = fileManager::uploadDocument($this->getViewVariable('document_name'), $this->getViewVariable('document_content'), $this->getViewVariable('document_junk')))) {
                     $this->SetViewVariable('opstat', 'fserror');
                 }
                 if (!$this->obj_data->insertFile($file_properties['name'], $file_properties['type'], $file_properties['size'], $file_properties['junk'], $md5, $this->getViewVariable('document_comment'), $course_id, $user_id, $folder_id, $this->getViewVariable('authortool_editable'), $this->getViewVariable('document_id'), $this->getViewVariable('document_accepted'))) {
                     $this->SetViewVariable('opstat', 'dberror');
                 }
             } else {
                 /*
                  * If form is not being submitted but we're editing a file
                  * then we'll get document vars that we'll need in View
                  */
                 if ($this->IsSetVar('document_id')) {
                     $this->setViewVariable("FileProperties", $this->obj_data->getFileProperties($this->getViewVariable('document_id'), $course_id, $user_profile_id, $user_id));
                 }
             }
             break;
         case 'delete':
             /*
              * First we check we have the most inmediate needed var
              */
             if (!$this->IsSetVar('what')) {
                 $this->giveControl('main', 'miguel_CMain');
             } else {
                 switch ($this->getViewVariable('what')) {
                     case 'folder':
                         /*
                          * First, we must check needed var
                          */
                         if (!$this->IsSetVar('folder_id')) {
                             $this->giveControl('main', 'miguel_CMain');
                         }
                         /*
                          * Delete folder
                          */
                         if (!$this->obj_data->deleteFolder($this->getViewVariable('folder_id'), $course_id, $user_profile_id, $user_id)) {
                             $this->SetViewVariable('opstat', 'foldererror');
                         }
                         break;
                     case 'document':
                         /*
                          * First, we must check our permissions
                          */
                         if (!$this->IsSetVar('document_id')) {
                             $this->giveControl('main', 'miguel_CMain');
                         }
                         /*
                          * Delete folder
                          */
                         if (!$this->obj_data->deleteFile($this->getViewVariable('document_id'), $course_id, $user_profile_id, $user_id)) {
                             $this->SetViewVariable('opstat', 'fileerror');
                         }
                         break;
                 }
             }
             break;
     }
 }
Ejemplo n.º 6
0
 /**
  * @covert fileManager::createDir
  */
 public function testCreateDir()
 {
     $sTestDir = __DIR__ . DIRECTORY_SEPARATOR . 'unit';
     $oClass = new fileManager();
     $this->assertNull($oClass->createDir($sTestDir));
     $this->assertTrue(is_dir($sTestDir));
     rmdir($sTestDir);
 }
 function processPetition()
 {
     /* ----------------- COMPRUEBA EL ACCESO AL MODULO E INICIALIZA --------------- */
     //Se controla que el usuario no tenga acceso.
     $bol_hasaccess = false;
     //Primero comprueba si estamos identificados y si no es asi entonces vamos a ver si es una peticion de autenticacion
     $user_id = $this->getSessionElement('userinfo', 'user_id');
     $course_id = $this->getSessionElement('courseinfo', 'course_id');
     //Para maqueta
     if (empty($course_id)) {
         $course_id = 7;
     }
     if (isset($user_id) && $user_id != '') {
         $bol_hasaccess = true;
         $user = $this->getSessionElement('userinfo', 'user_alias');
     }
     $this->clearNavBarr();
     if ($bol_hasaccess) {
         /* --------------- EXEC FILEMANAGER ACTIONS ----------------- */
         if ($this->issetViewVariable('submit')) {
             /* ----------- NEW FOLDER  -------------- */
             if ($this->issetViewVariable('foldername')) {
                 $this->setViewVariable('folder_id', $this->obj_data->insertFolder($this->getViewVariable('folder_id'), $course_id, $this->getViewVariable('foldername'), $user_id));
             }
             /* -----------  SUBMIT FILE  -------------- */
             if ($_FILES['filename']['tmp_name'] != null) {
                 include_once Util::app_Path("filemanager/include/classes/filemanager.class.php");
                 if (!$this->getViewVariable('filezip')) {
                     fileManager::uploadFile($_FILES['filename']);
                     $this->obj_data->insertFile($_FILES['filename']['name'], $_FILES['filename']['type'], $course_id, $this->getViewVariable('folder_id'), $user_id, $_FILES['filename']['size']);
                 } else {
                     $listUploadFiles = fileManager::uploadFileZip($_FILES['filename']);
                     $listCount = count($listUploadFiles);
                     for ($i = 0; $i < $listCount; $i++) {
                         if (!$listUploadFiles[$i]['folder']) {
                             //$parent_folder_id -> se busca dirname() en $listFolder[ruta_completa] y obtenemos el id y el nombre
                             $this->obj_data->insertFile(basename($listUploadFiles[$i]['stored_filename']), '', $course_id, $this->getViewVariable('folder_id'), $user_id);
                         } else {
                             $this->obj_data->insertFolder($this->getViewVariable('folder_id'), $course_id, $this->getViewVariable('foldername'), $user_id);
                             //Creamos una lista folder - (id - folder_name - folder_ruta_completa), necesaria para mantener la profundidad
                             //folder_name -> basename( ruta ), parent_folder_name -> basename( dirname(ruta) )
                             $listFolder[] = array(basename(dirname($listUploadFiles[$i]['stored_filename'])), $lastIdFolder);
                         }
                     }
                 }
             }
             /* ------------ OTRAS OPERACIONES ARCHIVOS Y DIRECTORIOS CON FORMULARIO INTERMEDIO-------------- */
             /* Eliminar, Renombrar, Comentar, Mover, Hacer visible, Bloquear, Compartir, ¿Actualizar y guardar un log de cambios o control de versiones? */
             if ($this->issetViewVariable('status')) {
                 $status = $this->getViewVariable('status');
                 switch ($status) {
                     case 'rename':
                         if ($this->getViewVariable('tp') == 'f') {
                             $this->obj_data->renameFolder($this->getViewVariable('id'), $this->getViewVariable('newname'));
                         } else {
                             $this->obj_data->renameFile($this->getViewVariable('id'), $this->getViewVariable('newname'));
                         }
                         break;
                     case 'move':
                         if ($this->getViewVariable('tp') == 'f') {
                             $folder_id = $this->getViewVariable('id');
                             $nuevo_destino = $this->getViewVariable('nuevo_destino');
                             if ($folder_id != $nuevo_destino) {
                                 $this->obj_data->moveFolder($folder_id, $nuevo_destino);
                             }
                             $folder_id = null;
                             unset($folder_id);
                             $nuevo_destino = null;
                             unset($nuevo_destino);
                         } else {
                             $this->obj_data->moveFile($course_id, $this->getViewVariable('id'), $this->getViewVariable('folder_id'), $this->getViewVariable('nuevo_destino'));
                         }
                         break;
                 }
                 $status = null;
                 unset($status);
             }
             /* Debería retornar un valor error o estado de la operación y notificarlo en la carga del módulo */
         }
         /* ------------------ OPERACIONES REALIZADAS DIRECTAMENTE ---------*/
         if ($this->issetViewVariable('status')) {
             $status = $this->getViewVariable('status');
             switch ($status) {
                 case 'del':
                     if ($this->getViewVariable('tp') == 'f') {
                         $this->obj_data->deleteFolder($course_id, $this->getViewVariable('id'));
                     } else {
                         $this->obj_data->deleteFile($this->getViewVariable('id'), $this->getViewVariable('folder_id'), $course_id);
                     }
                     break;
                 case 'visible':
                     if ($this->getViewVariable('tp') == 'f') {
                         $this->obj_data->visibleElement($this->getViewVariable('id'), 1, 'folder');
                     } else {
                         $this->obj_data->visibleElement($this->getViewVariable('id'), 1, 'document');
                     }
                     break;
                 case 'invisible':
                     if ($this->getViewVariable('tp') == 'f') {
                         $this->obj_data->visibleElement($this->getViewVariable('id'), 0, 'folder');
                     } else {
                         $this->obj_data->visibleElement($this->getViewVariable('id'), 0, 'document');
                     }
                     break;
                 case 'lock':
                     $this->obj_data->lockDocument($this->getViewVariable('id'), 1);
                     break;
                 case 'unlock':
                     $this->obj_data->lockDocument($this->getViewVariable('id'), 0);
                     break;
                 case 'share':
                     $this->obj_data->shareDocument($this->getViewVariable('id'), 1);
                     break;
                 case 'unshare':
                     $this->obj_data->shareDocument($this->getViewVariable('id'), 0);
                     break;
             }
         }
         /* -------- SET CURRENT FOLDER, IF EMPTY BY DEFAULT FOLDER_ID = 0 ------------- */
         if ($this->issetViewVariable("folder_id") != "") {
             $current_folder_id = $this->getViewVariable("folder_id");
         } else {
             //$current_folder_id = $this->obj_data->getFolderId($course_id);//0;
             $current_folder_id = 0;
         }
         /* ----------- DISPLAY FOLDER CONTENT --------------- */
         $current_folder_info = $this->obj_data->getFolderName($current_folder_id);
         $this->setViewVariable('current_folder_name', $current_folder_info[0]['folder_name']);
         $this->setViewVariable('folder_parent_id', $current_folder_info[0]['folder_parent_id']);
         $this->setViewVariable('arr_files', $this->obj_data->getFileList($course_id, $current_folder_id));
         $this->setViewVariable('arr_folders', $this->obj_data->getFolderList($course_id, $current_folder_id));
         $this->setViewVariable('folder_id', $current_folder_id);
         $operation_id = $this->getViewVariable('operation_id');
         $this->setViewVariable('operation_id', $operation_id);
         if ($operation_id == 'move') {
             $this->obj_data->getFolderTree($course_id, $result, 0, 0);
             $this->setViewVariable('folderTree', $result);
         }
         $this->setViewVariable('user_id', $user_id);
         $this->setViewVariable('profile_id', $this->getSessionElement('userinfo', 'profile_id'));
         $this->setCacheFile("miguel_VFileManager" . $this->getSessionElement("userinfo", "user_id"));
         //$this->setMessage(agt("miguel_fileManager"));
         $this->setPageTitle("miguel_fileManager");
     } else {
         $this->giveControl('main', 'miguel_CMain');
     }
     $this->addNavElement(Util::format_URLPath('filemanager/index.php'), agt("Mis documentos"));
     $this->setCacheFlag(true);
     $this->setHelp("EducFileManager");
 }
Ejemplo n.º 8
0
     */
    public function getConfigParam($sName = null)
    {
        $sResult = '';
        if ($sName == 'sShopDir') {
            $sResult = substr(__DIR__, 0, -19);
        }
        return $sResult;
    }
    /**
     * Returns singleton oxConfig object instance or create new if needed
     *
     * @return oxConfig
     */
    public static function getInstance()
    {
        if (!self::$_instance instanceof oxConfig) {
            //exceptions from here go directly to global exception handler
            //if no init is possible whole application has to die!
            self::$_instance = new oxConfig();
        }
        return self::$_instance;
    }
}
require_once substr(__DIR__, 0, -3) . 'core' . DIRECTORY_SEPARATOR . 'filemanager.php';
$oFileManager = new fileManager();
$sFileConfigPath = substr(__DIR__, 0, -3) . 'tmp' . DIRECTORY_SEPARATOR . 'config.json';
$aConfig = json_decode(file_get_contents($sFileConfigPath), true);
$aConfig['debugActive'] = 0;
file_put_contents($sFileConfigPath, json_encode($aConfig));
var_export($oFileManager->getBackup());
 function write($file, $values, $keyCol = false)
 {
     if (empty($file)) {
         return false;
     }
     if (empty($values)) {
         return false;
     }
     //--- calculate 3rd parameter ---//
     $assoc = $this->forceAssoc || count(array_filter(array_keys($values), 'is_string'));
     //--- get name of temporary copy ---//
     $newFile = '';
     if (is_string($this->tmpFile)) {
         include_once $this->fileManagerPath;
         if (class_exists('fileManager')) {
             if (fileManager::validPath($this->tmpFile, false)) {
                 $newFile = $this->tmpFile;
             }
         }
     }
     if (empty($newFile)) {
         $newFile = $file . $this->tmpFileExt;
     }
     //--- initialize variables ---//
     $anyChanges = false;
     //In this context file appends are no changes: "$anyChanges" will stay "false".
     $overwrite = 0;
     //overwrite in this context means not only a line will be overwritten, but the key value matched.
     $error = false;
     //--- copy first row ---//
     //... read first row ...//
     if (!file_exists($file)) {
         $rowAsIs = array();
         $oldFileHandle = false;
         $newFileHandle = fopen($file, 'w');
     } else {
         $oldFileHandle = fopen($file, 'r+');
         $newFileHandle = false;
         if ($oldFileHandle) {
             $rowAsIs = fgetcsv($oldFileHandle, $this->rowLength, $this->delimiter, $this->enclosure, $this->escape);
             if ($rowAsIs === false) {
                 $rowAsIs = array();
             }
         } else {
             return false;
         }
     }
     //... calculate and write first row ...//
     $rowAsIsCount = count($rowAsIs);
     if ($assoc) {
         // assoc //
         $columnsToAdd = array();
         foreach (array_keys($values) as $colFromValues) {
             if (!in_array($colFromValues, $rowAsIs)) {
                 $columnsToAdd[] = $colFromValues;
             }
         }
         $anyChanges = (bool) count($columnsToAdd);
         $oldHead = $rowAsIs;
         $columns = array_merge($rowAsIs, $columnsToAdd);
         //copy/write head:
         try {
             $newFileHandle = $this->openHandleOnLastChance($newFileHandle, $newFile);
             $error = !$this->writeBuffered($columns, $newFileHandle);
         } catch (Exception $e) {
             $error = true;
         }
     } else {
         // not assoc //
         $valueCount = count($values);
         ksort($values, SORT_NUMERIC);
         if ($rowAsIsCount !== 0) {
             $anyChanges = $valueCount >= $rowAsIsCount;
             $colCount = max($valueCount, $rowAsIsCount);
             $firstKey = key($values);
             end($values);
             $lastKey = key($values);
             if ($firstKey < 0 || $lastKey >= $colCount) {
                 $valuesWithInvalidKeys = $values;
                 $values = array();
                 foreach ($valuesWithInvalidKeys as $value) {
                     $values[] = $value;
                 }
                 unset($valuesWithInvalidKeys);
             }
             $oldHead = range(0, $rowAsIsCount - 1);
             $columns = range(0, $colCount - 1);
             $rowToBe = $rowAsIs;
             for ($i = 0; $i < $valueCount - $rowAsIsCount; $i++) {
                 if (!isset($rowToBe[$i])) {
                     $rowToBe[$i] = $this->emptyContent;
                 }
                 if ($keyCol !== false && $i === $keyCol) {
                     $overwrite = -1;
                     break;
                 }
             }
             if ($overwrite === -1) {
                 $rowToBe = $values;
                 $lineIsEmpty = true;
                 for ($i = 0; $i < $valueCount - $rowAsIsCount; $i++) {
                     if (!isset($rowToBe[$i])) {
                         $rowToBe[$i] = $this->emptyContent;
                     } else {
                         if ($keyCol === false || $i !== $keyCol) {
                             $lineIsEmpty = false;
                         }
                     }
                 }
             } else {
                 $lineIsEmpty = false;
             }
             //copy/write first row:
             if (!$lineIsEmpty) {
                 try {
                     $newFileHandle = $this->openHandleOnLastChance($newFileHandle, $newFile);
                     $error = !$this->writeBufferedAssoc($rowToBe, $columns, $newFileHandle);
                 } catch (Exception $e) {
                     $error = true;
                 }
             } else {
                 $error = false;
             }
             if ($overwrite === -1) {
                 if ($error) {
                     $overwrite = 0;
                 } else {
                     $overwrite = 1;
                 }
             }
         }
     }
     //--- Copy old lines ---//
     $colCount = count($columns);
     while ($rowAsIsCount != 0 && !$error) {
         //... read next line ...//
         if ($assoc) {
             $rowAsIs = $this->fgetcsv_assoc($oldFileHandle, $oldHead);
         } else {
             $rowAsIs = fgetcsv($oldFileHandle, $this->rowLength, $this->delimiter, $this->enclosure, $this->escape);
         }
         if (!is_array($rowAsIs)) {
             $rowAsIs = array();
             $rowAsIsCount = 0;
         } else {
             $rowAsIsCount = count($rowAsIs);
         }
         if ($rowAsIsCount !== 0) {
             //... write (copy) line ...//
             $lineIsEmpty = false;
             $rowToWrite =& $rowAsIs;
             if ($keyCol !== false && $overwrite != 1 && isset($rowAsIs[$keyCol]) && $rowAsIs[$keyCol] === $values[$keyCol]) {
                 $rowToWrite = $this->overwriteEmpty($values, $rowAsIs);
                 $overwrite = -1;
                 //Check if this overwrite makes any changes on the file:
                 $lineIsEmpty = true;
                 foreach ($values as $key => &$value) {
                     if ($key != $keyCol && isset($rowAsIs[$key])) {
                         $lineIsEmpty = false;
                     }
                     if (!isset($rowAsIs[$key]) || $rowAsIs[$key] != $value) {
                         $anyChanges = true;
                         break;
                     }
                 }
             }
             if (!$lineIsEmpty) {
                 try {
                     $newFileHandle = $this->openHandleOnLastChance($newFileHandle, $newFile);
                     $error = !$this->writeBufferedAssoc($rowToWrite, $columns, $newFileHandle);
                 } catch (Exception $e) {
                     $error = true;
                 }
             }
             if ($overwrite === -1) {
                 if ($error) {
                     $overwrite = 0;
                 } else {
                     $overwrite = 1;
                 }
             }
             $anyChanges = $anyChanges || $colCount != $rowAsIsCount || $lineIsEmpty && $overwrite;
         } else {
             break;
         }
     }
     //--- Attach values --- //
     if (!$error) {
         if ($anyChanges) {
             if (!$overwrite) {
                 //Attach line to new file:
                 try {
                     $newFileHandle = $this->openHandleOnLastChance($newFileHandle, $newFile);
                     $error = !$this->writeBufferedAssoc($values, $columns, $newFileHandle);
                 } catch (Exception $e) {
                     $error = true;
                 }
             }
             if (!$error) {
                 //Write buffer now:
                 try {
                     $newFileHandle = $this->openHandleOnLastChance($newFileHandle, $newFile, true);
                     //force to open handle
                     $error = !$this->writeBuffered(true, $newFileHandle);
                     //force to write
                 } catch (Exception $e) {
                     $error = true;
                 }
             }
         } else {
             if (!$overwrite) {
                 //Now "overwrite" means it is overwritten or in this case: It isn't.
                 if (count($values) != 0 + ($keyCol !== false)) {
                     // line is not empty
                     //Write buffer now:
                     try {
                         $newFileHandle = $this->openHandleOnLastChance($newFileHandle, $newFile, true);
                         //force to open handle
                         $error = !$this->writeBuffered(true, $newFileHandle);
                         //force to write
                     } catch (Exception $e) {
                         $error = true;
                     }
                     if (!$error) {
                         //Attach new line
                         $this->fputcsv_assoc($oldFileHandle ?: $newFileHandle, $columns, $values);
                     }
                 }
             }
         }
     }
     //--- close & clean ---//
     if ($oldFileHandle) {
         fclose($oldFileHandle);
         if ($newFileHandle) {
             fclose($newFileHandle);
             if ($anyChanges && !$error) {
                 unlink($file);
                 rename($newFile, $file);
             } else {
                 unlink($newFile);
             }
         }
     } else {
         if ($newFileHandle) {
             //newFileHandle points on primary file path
             fclose($newFileHandle);
         }
     }
     return !$error;
 }
 private function _linConstruct($tempCronTablePath)
 {
     if (empty($tempCronTablePath)) {
         throw new Exception('This is no windows server, parameter 1 must be a path for a valid file.');
     }
     if (!(include $this->csvManagerPath)) {
         throw new Exception('Unable to include csvManager. csvManager is required because it\'s no windows server.');
     }
     if (@(include $this->fileManagerPath)) {
         if (class_exists('fileManager')) {
             if (!fileManager::validPath($tempCronTablePath, false, false)) {
                 //if its no valid file path
                 if (!fileManager::validPath($tempCronTablePath, true, false)) {
                     //and no valid directory
                     throw new Exception('This is no windows server, parameter 1 must a valid path of the cron table.');
                 } else {
                     $tempCronTablePath .= 'cronTemp.txt';
                     if (!fileManager::validPath($tempCronTablePath, false, false)) {
                         //if still no valid file path
                         throw new Exception('This is no windows server, parameter 1 must a valid path. Found directory path but an error occured.');
                     }
                 }
             }
         }
     }
     $this->tempCronTablePath = $tempCronTablePath;
     $this->csvManager = new csvManager('#', chr(219));
     $this->cronTableDelimiter = '~~~cronId:';
 }
 function getSummarizationState($timeStamp, $timeSpanType, $today = false, $file = false)
 {
     if (is_bool($timeStamp)) {
         $timeStamp = false;
     }
     if (!is_string($file)) {
         $file = $this->getIOFile($timeStamp, $timeSpanType);
     }
     switch ($timeSpanType) {
         case 'day':
             if (strcmp(date('Y-m-d', $timeStamp), date('Y-m-d', $today)) < 0) {
                 //timeStamp is in past
                 //--- Check for flowFiles ---//
                 include_once $this->fileManagerPath;
                 if (!class_exists('fileManager')) {
                     throw new Exception('Unable to include "fileManager".');
                     return;
                 }
                 if (!file_exists($file)) {
                     return -1;
                 }
                 if ($this->maxFlowFiles) {
                     $firstFlowFile = fileManager::preExtendFile($file, '#' . '1');
                     if (!file_exists($firstFlowFile)) {
                         //no flow file found
                         return 1;
                         //no futher flow files expected
                     } else {
                         return 0;
                     }
                 } else {
                     return 1;
                 }
             } else {
                 return 0;
             }
             break;
         case 'month':
             if (strcmp(date('Y-m', $timeStamp), date('Y-m', $today)) < 0) {
                 //timeStamp is in past
                 if (file_exists($file)) {
                     $summarizationStates = $this->getSummarizationStatesFromFile($file);
                     if ($summarizationStates === false) {
                         throw new Exception('Unable to get summarization states from file "' . $file . '".');
                         return;
                     }
                 }
                 $completeLogExists = false;
                 $daysInMonth = date('t', $timeStamp);
                 $monthString = date('Y-m-', $timeStamp);
                 for ($day = 1; $day < $daysInMonth; $day++) {
                     $dayString = ($day < 10 ? '0' : '') . $day;
                     //attach leading zero
                     $dateString = $monthString . $dayString;
                     if (!file_exists($file)) {
                         $dateFile = $this->getIOFile(strtotime($dateString, 'day'));
                         if (file_exists($dateFile)) {
                             return 0;
                         }
                     } else {
                         if (!isset($summarizationStates[$dateString]) || $summarizationStates[$dateString] == 0) {
                             return 0;
                         } else {
                             if ($summarizationStates[$dateString] == 1) {
                                 $completeLogExists = true;
                             }
                         }
                     }
                 }
                 if ($completeLogExists) {
                     return 1;
                 } else {
                     return -1;
                 }
             } else {
                 return 0;
             }
             break;
         case 'year':
             if (strcmp(date('Y', $timeStamp), date('Y', $today)) < 0) {
                 //timeStamp is in past
                 if (file_exists($file)) {
                     $summarizationStates = $this->getSummarizationStatesFromFile($file);
                     if ($summarizationStates === false) {
                         throw new Exception('Unable to get summarization states from file "' . $file . '".');
                         return;
                     }
                 }
                 $completeLogExists = false;
                 $yearString = date('Y ', $timeStamp);
                 for ($month = 1; $month <= 12; $month++) {
                     $monthString = date('M', ($month - 1) * 31 * 24 * 3600);
                     $dateString = $yearString . $monthString;
                     if (!file_exists($file)) {
                         $dateFile = $this->getIOFile(strtotime($dateString, 'day'));
                         if (file_exists($dateFile)) {
                             return 0;
                         }
                     } else {
                         if (!isset($summarizationStates[$dateString]) || $summarizationStates[$dateString] == 0) {
                             return 0;
                         } else {
                             if ($summarizationStates[$dateString] == 1) {
                                 $completeLogExists = true;
                             }
                         }
                     }
                 }
                 if ($completeLogExists) {
                     return 1;
                 } else {
                     return -1;
                 }
             } else {
                 return 0;
             }
             break;
         case 'all':
             return 0;
             //This summary can never be expected as complete.
             break;
     }
 }