/**
  * @Override FC_Document_Manager::postDocumentUpload().
  *
  * This is a copy and past of the overriden function except
  * that we now create a new Intern_Document object
  * and save it to databse.
  */
 public function postDocumentUpload()
 {
     // importPost in File_Common
     $result = $this->document->importPost('file_name');
     if (PEAR::isError($result) || !$result) {
         PHPWS_Error::log($result);
         $vars['timeout'] = '3';
         $vars['refresh'] = 0;
         javascript('close_refresh', $vars);
         return dgettext('filecabinet', 'An error occurred when trying to save your document.');
     } elseif ($result) {
         $result = $this->document->save();
         if (PHPWS_Error::logIfError($result)) {
             $content = dgettext('filecabinet', '<p>Could not upload file to folder. Please check your directory permissions.</p>');
             $content .= sprintf('<a href="#" onclick="window.close(); return false">%s</a>', dgettext('filecabinet', 'Close this window'));
             Layout::nakedDisplay($content);
             exit;
         }
         PHPWS_Core::initModClass('filecabinet', 'File_Assoc.php');
         FC_File_Assoc::updateTag(FC_DOCUMENT, $this->document->id, $this->document->getTag());
         $this->document->moveToFolder();
         // If the document's id is set in the request
         // then we are updating a file. Not need to insert
         // it into database.
         if (!isset($_REQUEST['document_id'])) {
             // Save Intern_Document in database.
             PHPWS_Core::initModClass('intern', 'Intern_Document.php');
             $doc = new Intern_Document();
             $doc->internship_id = $_REQUEST['internship'];
             $doc->document_fc_id = $this->document->id;
             $result = $doc->save();
         }
         // Choose the proper notification text...
         if (isset($_REQUEST['document_id']) && $_REQUEST['document_id'] && $result) {
             NQ::simple('intern', INTERN_SUCCESS, "File saved.");
         } else {
             if ($result) {
                 NQ::simple('intern', INTERN_SUCCESS, "File added.");
             } else {
                 if (PHPWS_Error::logIfError($result)) {
                     NQ::simple('intern', INTERN_ERROR, $result->toString());
                 }
             }
         }
         NQ::close();
         if (!isset($_POST['im'])) {
             javascript('close_refresh');
         } else {
             javascript('/filecabinet/refresh_manager', array('document_id' => $this->document->id));
         }
     } else {
         return $this->edit();
     }
 }
Esempio n. 2
0
 public function convertToFileAssoc($table, $column, $type)
 {
     $db = new PHPWS_DB('fc_convert');
     $db->addWhere('table_name', $table);
     $db->addWhere('column_name', $column);
     $result = $db->select();
     if (PHPWS_Error::logIfError($result)) {
         return false;
     } elseif ($result) {
         return true;
     }
     PHPWS_Core::initModClass('filecabinet', 'File_Assoc.php');
     $db = new PHPWS_DB($table);
     $db->addColumn('id');
     $db->addColumn($column);
     $db->setIndexBy('id');
     $item = $db->select('col');
     if (empty($item)) {
         return true;
     }
     foreach ($item as $id => $item_id) {
         $db->reset();
         if (isset($item_converted[$item_id])) {
             $file_assoc_id = $item_converted[$item_id];
             $db->addValue($column, $file_assoc_id);
             $db->addWhere('id', $id);
             PHPWS_Error::logIfError($db->update());
         } else {
             $file_assoc = new FC_File_Assoc();
             $file_assoc->file_type = $type;
             $file_assoc->file_id = $item_id;
             if (!PHPWS_Error::logIfError($file_assoc->save())) {
                 $db->addValue($column, $file_assoc->id);
                 $db->addWhere('id', $id);
                 if (PHPWS_Error::logIfError($db->update())) {
                     continue;
                 }
             }
             $item_converted[$item_id] = $file_assoc->id;
         }
     }
     $db->reset();
     $db->addValue('table_name', $table);
     $db->addValue('column_name', $column);
     PHPWS_Error::logIfError($db->insert());
     return true;
 }
Esempio n. 3
0
function moveBlockImages()
{
    require_once PHPWS_SOURCE_DIR . 'core/class/Form.php';
    require_once PHPWS_SOURCE_DIR . 'mod/block/class/Block_Item.php';
    require_once PHPWS_SOURCE_DIR . 'mod/filecabinet/class/File_Assoc.php';
    require_once PHPWS_SOURCE_DIR . 'mod/filecabinet/class/Cabinet.php';
    $db = Database::newDB();
    $block = $db->addTable('block');
    $db->setConditional($block->getFieldConditional('file_id', 0, '>'));
    $db->loadSelectStatement();
    while ($block = $db->fetchObject('Block_Item')) {
        $file = new FC_File_Assoc($block->file_id);
        $file->_use_style = false;
        $tag = $file->getTag();
        $old_content = $block->getContent();
        $new_content = "<div>{$tag}</div>" . $old_content;
        $block->setContent($new_content);
        $block->save();
    }
}