public function setup_metadata()
 {
     $mf = new DocmanWatermark_MetadataFactory();
     $md_id = $this->_controler->_actionParams['md_id'];
     $group_id = $this->_controler->_actionParams['group_id'];
     $wmd = new DocmanWatermark_Metadata();
     $wmd->setGroupId($group_id);
     $wmd->setId($md_id);
     $mf->setField($wmd);
 }
 function _dispatch($view)
 {
     $user = $this->getUser();
     $dpm = Docman_PermissionsManager::instance($this->getGroupId());
     switch ($view) {
         case 'admin_watermark':
             $group_id = $this->request->get('group_id');
             $dwmdf = new DocmanWatermark_MetadataFactory();
             $md_id = $dwmdf->getMetadataIdFromGroupId($group_id);
             $this->_viewParams['md_id'] = $md_id;
             $this->_viewParams['group_id'] = $group_id;
             $md_arr = array();
             $dmf = new Docman_MetadataFactory($group_id);
             $mdIter = $dmf->getMetadataForGroup(true);
             $mdIter->rewind();
             while ($mdIter->valid()) {
                 $md = $mdIter->current();
                 $md_arr[] = $md->getId();
                 $mdIter->next();
             }
             if ($md_id != 0 && !in_array($md_id, $md_arr)) {
                 $this->feedback->log('warning', $GLOBALS['Language']->getText('plugin_docmanwatermark', 'admin_metadata_deleted'));
             }
             $this->view = 'AdminWatermark';
             break;
         case 'admin_set_watermark_metadata':
             $group_id = $this->request->get('group_id');
             $id = $this->request->get('md_id');
             $this->_actionParams['group_id'] = $group_id;
             $this->_actionParams['md_id'] = $id;
             $dwm = new DocmanWatermark_Metadata();
             $dwm->setId($id);
             $dwm->setGroupId($group_id);
             $this->action = 'setup_metadata';
             $this->feedback->log('info', $GLOBALS['Language']->getText('plugin_docmanwatermark', 'admin_update_metadata'));
             $this->_viewParams['redirect_to'] = '?group_id=' . $group_id . '&action=admin_watermark';
             $this->view = 'RedirectAfterCrud';
             break;
         case 'admin_set_watermark_metadata_values':
             $mdf = new Docman_MetadataFactory($this->request->get('group_id'));
             $dwmf = new DocmanWatermark_MetadataFactory();
             $md_id = $dwmf->getMetadataIdFromGroupId($this->request->get('group_id'));
             $mdLabel = $mdf->getLabelFromId($md_id);
             $mlvef = new Docman_MetadataListOfValuesElementFactory($md_id);
             $mlveIter = $mlvef->getIteratorByFieldId($md_id, $mdLabel, true);
             $mlveIter->rewind();
             $arrValues = array();
             $arrVals = array();
             while ($mlveIter->valid()) {
                 $dmv = $mlveIter->current();
                 $dwmv = new DocmanWatermark_MetadataValue();
                 if ($this->request->exist('chk_' . $dmv->getId())) {
                     $watermark = 1;
                 } else {
                     $watermark = 0;
                 }
                 $dwmv->setValueId($dmv->getId());
                 $dwmv->setWatermark($watermark);
                 $arrValues[] = $dwmv;
                 $arrVals['value_id'][] = $dmv->getId();
                 $arrVals['watermark'][] = $watermark;
                 $mlveIter->next();
             }
             $iterValues = new ArrayIterator($arrValues);
             $this->_actionParams['group_id'] = $this->request->get('group_id');
             $this->_actionParams['md_values'] = $iterValues;
             $this->action = 'setup_metadata_values';
             $this->feedback->log('info', $GLOBALS['Language']->getText('plugin_docmanwatermark', 'admin_update_metadata_values'));
             $this->_viewParams['redirect_to'] = '?group_id=' . $this->request->get('group_id') . '&action=admin_watermark';
             $this->view = 'RedirectAfterCrud';
             break;
         case 'admin_import_from_project':
             $this->_actionParams['src_group_id'] = $this->request->get('project');
             $this->_actionParams['target_group_id'] = $this->request->get('group_id');
             $dwmif = new DocmanWatermark_MetadataImportFactory();
             $dwmif->setSrcProjectId($this->request->get('project'));
             $dwmif->setTargetProjectId($this->request->get('group_id'));
             $dmf = new Docman_MetadataFactory($this->request->get('project'));
             $dwmf = new DocmanWatermark_MetadataFactory();
             $md_id = $dwmf->getMetadataIdFromGroupId($dwmif->getSrcProjectId());
             $mdIter = $dmf->findByName($dwmf->getMetadataNameFromId($md_id));
             $mdIter->rewind();
             $md = $mdIter->current();
             $this->_actionParams['md'] = $md;
             $mdMap = $dwmif->getWatermarkMetadataMap($md);
             if ($mdMap['md'] != 0) {
                 $this->action = 'import_from_project';
                 $this->feedback->log('info', $GLOBALS['Language']->getText('plugin_docmanwatermark', 'admin_imported_from_project'));
                 $this->_viewParams['md_id'] = $md_id;
                 $this->_viewParams['redirect_to'] = '?group_id=' . $this->request->get('group_id') . '&action=admin_watermark';
             } else {
                 $this->feedback->log('info', $GLOBALS['Language']->getText('plugin_docmanwatermark', 'admin_import_from_project_not_match'));
                 $this->_viewParams['redirect_to'] = '?group_id=' . $this->request->get('group_id') . '&action=admin_import_metadata_check&import_group_id=' . $this->request->get('project');
             }
             $this->view = 'RedirectAfterCrud';
             break;
         case 'docmanwatermark_toggle_item':
             $this->action = 'docmanwatermark_toggle_item';
             break;
         default:
             die(htmlspecialchars($view) . ' is not supported');
             break;
     }
 }
 /**
  * Private Method to copy the watermarkmetadata setup from the src project to target project
  * @param  int md_id: the metadata id to insert in the table plugin_docman_watermark_md_extension
  * @return void
  */
 private function copyWatermarkMetadata($md_id)
 {
     $dwmd = new DocmanWatermark_Metadata();
     $dwmd->setGroupId($this->targetProjectId);
     $dwmd->setId($md_id);
     $dwmf = new DocmanWatermark_MetadataFactory();
     $dwmf->setField($dwmd);
 }