/**
  * Saves the file into folders and create the folders if they do not exist
  *
  * @param $tags String all the folders name separated by a comma
  * @param $fid The file ID
  * @return void
  */
 private function saveFolders($tags, $fid)
 {
     $cor = new FilfoldersFilfiles();
     $cor->delete("filfiles_id = '" . $fid . "'");
     foreach (preg_split('/,/', $tags) as $tag) {
         if (trim($tag) != '') {
             $folderLabel = ucfirst(strtolower(trim($tag)));
             $folderDb = new Filfolders();
             $where = "safinstances_id = '" . $this->safinstancesId . "' AND label LIKE '" . addslashes($folderLabel) . "' ";
             $rows = $folderDb->fetchAll($where);
             if (count($rows) == 1) {
                 $folderRow = $rows[0];
             } elseif (count($rows) == 0) {
                 // create the folder
                 $folderRow = $folderDb->createRow();
                 $folderRow->label = $folderLabel;
                 $folderRow->safinstances_id = $this->safinstancesId;
                 $folderRow->save();
             } else {
                 break;
             }
             // add data in the correspondance table
             $cor = new FilfoldersFilfiles();
             $rows2 = $cor->fetchAll("filfolders_id = '" . $folderRow->id . "' AND filfiles_id = '" . $fid . "' ");
             if (count($rows2) == 0) {
                 $corrE = $cor->createRow();
                 $corrE->filfolders_id = $folderRow->id;
                 $corrE->filfiles_id = $fid;
                 $corrE->save();
             }
         }
     }
 }
 /**
  *
  * @return void
  */
 public function editprocessAction()
 {
     $this->view->jsdisp = false;
     $this->view->msg = 'ERROR: Undefined error';
     $r = $this->getRequest();
     if ($r->layout == 'out') {
         $this->_helper->layout->disableLayout();
     }
     if (isset($r->id)) {
         $eDB = new Filfolders();
         $e = $eDB->find($r->id);
         if (count($e) == 1) {
             if ($r->duplicate == 1) {
                 $e2 = $eDB->createRow();
                 $e2->desc = $r->desc;
                 $e2->isnode = $r->isnode;
                 $e2->isparam = $r->isparam;
                 $e2->label = $r->label;
                 $e2->relevance = $r->relevance;
                 $e2->parent_id = $e[0]->parent_id;
                 $e2->safinstances_id = $e[0]->safinstances_id;
                 $e2->save();
                 $this->view->msg = 'Entity duplicated';
             } else {
                 $e[0]->desc = $r->desc;
                 $e[0]->isnode = $r->isnode;
                 $e[0]->isparam = $r->isparam;
                 $e[0]->label = $r->label;
                 $e[0]->relevance = $r->relevance;
                 $this->view->label = $r->label;
                 $this->view->id = $r->id;
                 if ($e[0]->save()) {
                     $this->view->jsdisp = true;
                     $this->view->msg = 'Data saved, thanks.';
                 } else {
                     $this->view->msg = 'ERROR: error while saving the data';
                 }
             }
         } else {
             $this->view->msg = 'ERROR: we could not find an entry in our DB...';
         }
     } else {
         $this->view->msg = 'ERROR: Could not save the data';
     }
 }