function createItem()
 {
     $request =& $this->_controler->request;
     $item_factory =& $this->_getItemFactory();
     if ($request->exist('item')) {
         $item = $request->get('item');
         $fs =& $this->_getFileStorage();
         if ($item['item_type'] != PLUGIN_DOCMAN_ITEM_TYPE_EMBEDDEDFILE || $this->_controler->getProperty('embedded_are_allowed') && $request->exist('content')) {
             // Special handling of obsolescence date
             if (isset($item['obsolescence_date']) && $item['obsolescence_date'] != 0) {
                 if (preg_match('/^([0-9]+)-([0-9]+)-([0-9]+)$/', $item['obsolescence_date'], $d)) {
                     $item['obsolescence_date'] = mktime(0, 0, 0, $d[2], $d[3], $d[1]);
                 } else {
                     if (!preg_match('/^[0-9]*$/', $item['obsolescence_date'])) {
                         $item['obsolescence_date'] = 0;
                     }
                 }
             } else {
                 $item['obsolescence_date'] = 0;
             }
             $user =& $this->_controler->getUser();
             // Change owner
             $userId = $user->getId();
             if (isset($item['owner'])) {
                 $um = $this->_getUserManagerInstance();
                 $new_owner = $um->getUserByUserName($item['owner']);
                 if ($new_owner !== null) {
                     $owner = $new_owner->getId();
                 } else {
                     $owner = $userId;
                 }
             } else {
                 $owner = $userId;
             }
             $item['user_id'] = $owner;
             // Change creation date
             if (isset($item['create_date']) && $item['create_date'] != '') {
                 $create_date_changed = true;
             } else {
                 $create_date_changed = false;
             }
             // Change update date
             if (isset($item['update_date']) && $item['update_date'] != '') {
                 $update_date_changed = true;
             } else {
                 $update_date_changed = false;
             }
             $item['group_id'] = $request->get('group_id');
             $id = $item_factory->create($item, $request->get('ordering'));
             if ($id) {
                 $this->_controler->_viewParams['action_result'] = $id;
                 $this->_controler->_viewParams['redirect_anchor'] = "#item_{$id}";
                 $new_item = $item_factory->getItemFromDb($id);
                 $parent = $item_factory->getItemFromDb($item['parent_id']);
                 if ($request->exist('permissions') && $this->_controler->userCanManage($parent->getId())) {
                     $force = true;
                     $this->setPermissionsOnItem($new_item, $force, $user);
                 } else {
                     $pm = $this->_getPermissionsManagerInstance();
                     $pm->clonePermissions($item['parent_id'], $id, array('PLUGIN_DOCMAN_READ', 'PLUGIN_DOCMAN_WRITE', 'PLUGIN_DOCMAN_MANAGE'));
                 }
                 $new_item->fireEvent('plugin_docman_event_add', $user, $parent);
                 // Log change owner
                 if ($owner != $userId) {
                     $this->_raiseMetadataChangeEvent($user, $new_item, $request->get('group_id'), null, $item['owner'], 'owner');
                 }
                 // Log change creation date
                 if ($create_date_changed) {
                     $this->_raiseMetadataChangeEvent($user, $new_item, $request->get('group_id'), null, $item['create_date'], 'create_date');
                 }
                 // Log change update date
                 if ($update_date_changed) {
                     $this->_raiseMetadataChangeEvent($user, $new_item, $request->get('group_id'), null, $item['update_date'], 'update_date');
                 }
                 $info_item_created = 'info_document_created';
                 if ($item['item_type'] == PLUGIN_DOCMAN_ITEM_TYPE_FOLDER) {
                     $info_item_created = 'info_folder_created';
                 }
                 $this->_controler->feedback->log('info', $GLOBALS['Language']->getText('plugin_docman', 'info_document_created'));
                 $new_version = null;
                 if ($item['item_type'] == PLUGIN_DOCMAN_ITEM_TYPE_FILE || $item['item_type'] == PLUGIN_DOCMAN_ITEM_TYPE_EMBEDDEDFILE) {
                     $new_version = $this->_storeFile($new_item);
                 }
                 if ($item['item_type'] == PLUGIN_DOCMAN_ITEM_TYPE_LINK) {
                     $link_version_factory = new Docman_LinkVersionFactory();
                     $link_version_factory->create($new_item, $GLOBALS['Language']->getText('plugin_docman', 'initversion'), $GLOBALS['Language']->getText('plugin_docman', 'initversion'), $_SERVER['REQUEST_TIME']);
                 }
                 // Create metatata
                 if ($request->exist('metadata')) {
                     $metadata_array = $request->get('metadata');
                     $mdvFactory = new Docman_MetadataValueFactory($request->get('group_id'));
                     $mdvFactory->createFromRow($id, $metadata_array);
                     if ($mdvFactory->isError()) {
                         $this->_controler->feedback->log('error', $mdvFactory->getErrorMessage());
                     }
                 }
                 //Submit News about this document
                 if ($request->exist('news')) {
                     if ($user->isMember($request->get('group_id'), 'A') || $user->isMember($request->get('group_id'), 'N1') || $user->isMember($request->get('group_id'), 'N2')) {
                         //only for allowed people
                         $news = $request->get('news');
                         if (isset($news['summary']) && trim($news['summary']) && isset($news['details']) && trim($news['details']) && isset($news['is_private'])) {
                             news_submit($request->get('group_id'), $news['summary'], $news['details'], $news['is_private']);
                             $this->_controler->feedback->log('info', $GLOBALS['Language']->getText('plugin_docman', 'info_news_created'));
                         }
                     } else {
                         $this->_controler->feedback->log('error', $GLOBALS['Language']->getText('plugin_docman', 'error_create_news'));
                     }
                 }
                 $folderFactory = $this->_getFolderFactory();
                 $folderFactory->expand($parent);
                 $item_type = $item_factory->getItemTypeForItem($new_item);
                 switch ($item_type) {
                     case PLUGIN_DOCMAN_ITEM_TYPE_EMBEDDEDFILE:
                     case PLUGIN_DOCMAN_ITEM_TYPE_FILE:
                         // Warn users about watermarking
                         $this->event_manager->processEvent('plugin_docman_after_new_document', array('item' => $new_item, 'user' => $user, 'version' => $new_version, 'docmanControler' => $this->_controler));
                         break;
                     case PLUGIN_DOCMAN_ITEM_TYPE_WIKI:
                         $this->event_manager->processEvent('plugin_docman_event_new_wikipage', array('item' => $new_item, 'group_id' => $new_item->getGroupId(), 'wiki_page' => $new_item->getPagename()));
                         break;
                     case PLUGIN_DOCMAN_ITEM_TYPE_EMPTY:
                         $this->event_manager->processEvent(PLUGIN_DOCMAN_EVENT_NEW_EMPTY, array('item' => $new_item));
                         break;
                     case PLUGIN_DOCMAN_ITEM_TYPE_LINK:
                         $this->event_manager->processEvent(PLUGIN_DOCMAN_EVENT_NEW_LINK, array('item' => $new_item));
                         break;
                     case PLUGIN_DOCMAN_ITEM_TYPE_FOLDER:
                         $this->event_manager->processEvent(PLUGIN_DOCMAN_EVENT_NEW_FOLDER, array('item' => $new_item));
                         break;
                     default:
                         break;
                 }
             }
         }
     }
     $this->event_manager->processEvent('send_notifications', array());
 }
 public function updateLink(Docman_Link $link, array $version_data)
 {
     $update = $this->update(array('id' => $link->getId(), 'group_id' => $link->getGroupId(), 'title' => $link->getTitle(), 'user_id' => $link->getOwnerId(), 'item_type' => PLUGIN_DOCMAN_ITEM_TYPE_LINK, 'link_url' => $link->getUrl()));
     $link_version_factory = new Docman_LinkVersionFactory();
     $create = $link_version_factory->create($link, $version_data['label'], $version_data['changelog'], $_SERVER['REQUEST_TIME']);
     return $update && $create;
 }