/**
 * Render attach file to an object control
 * 
 * @param array $params
 * @param Smarty $smarty
 * @return string
 */
function smarty_function_attach_files($params, &$smarty)
{
    static $ids = array();
    $id = array_var($params, 'id');
    if (empty($id)) {
        $counter = 1;
        do {
            $id = 'attach_files_' . $id++;
        } while (in_array($id, $ids));
    }
    // if
    $ids[] = $id;
    $max_files = (int) array_var($params, 'max_files', 1, true);
    if ($max_files < 1) {
        $max_files = 1;
    }
    // if
    require_once SMARTY_PATH . '/plugins/modifier.filesize.php';
    if ($max_files == 1) {
        $max_upload_size_message = lang('Max size of file that you can upload is :size', array('size' => smarty_modifier_filesize(get_max_upload_size())));
    } else {
        $max_upload_size_message = lang('Max total size of files you can upload is :size', array('size' => smarty_modifier_filesize(get_max_upload_size())));
    }
    // if
    return '<div class="attach_files" id="' . $id . '" max_files="' . $max_files . '"><p class="attach_files_max_size details">' . $max_upload_size_message . '</p></div><script type="text/javascript">App.resources.AttachFiles.init("' . $id . '")</script>';
}
 /**
  * Render log details
  * 
  * @param ProjectObject $object
  * @param boolean $in_project
  * @return string
  */
 function renderBody($object = null, $in_project = false)
 {
     if ($object === null) {
         $object = $this->getObject();
     }
     // if
     require_once SMARTY_PATH . '/plugins/modifier.filesize.php';
     $result = '<div class="file_details">';
     $result .= '<div class="file_thumbnail"><a href="' . $object->getViewUrl() . '"><img src="' . $object->getThumbnailUrl() . '" alt="" /></a></div>';
     $result .= '<div class="file_name"><a href="' . $object->getViewUrl() . '">' . clean($object->getName()) . '</a>, ' . smarty_modifier_filesize($object->getSize()) . '</div>';
     if ($object->getBody()) {
         $result .= '<div class="file_description">' . nl2br(str_excerpt(strip_tags($object->getBody()), 250)) . '</div>';
     }
     // if
     $result .= '</div>';
     return $result;
 }
示例#3
0
function smarty_function_attach($params, &$smarty)
{
    if (empty($params['file'])) {
        return '';
    }
    require_once $smarty->_get_plugin_filepath('modifier', 'filesize');
    if ($params['scv']) {
        list($file, $size, $ext) = explode(';', $params['file']);
    }
    if (in_array($ext, array('jpg', 'gif', 'png'))) {
        list($w, $h) = getimagesize($params['url'] . $file);
        if ($w <= 615 && $h <= 500) {
            $sResult = "<div align=\"center\"><img src=\"{$params['url']}{$file}\" alt=\"{$file}\" title=\"{$file}\" /></div>";
        } else {
            $sResult = '<div class="attachment"><a href="' . $params['url'] . $file . '"  alt="' . $file . '" title="' . $file . '" ' . 'onclick="return utils.popupMsg(\'\',{img:\'' . $params['url'] . $file . '\',eschide:true});"' . '>Посмотреть</a> (' . $ext . '; ' . smarty_modifier_filesize($size) . ')</div>';
        }
    } else {
        $sResult = '<div class="attachment"><a href="' . $params['url'] . $file . '" alt="' . $file . '" title="' . $file . '">Загрузить</a> (' . $ext . '; ' . smarty_modifier_filesize($size) . ')</div>';
    }
    return $sResult;
}
 /**
  * Show upload form
  *
  * @param void
  * @return null
  */
 function upload()
 {
     $this->wireframe->page_actions = array();
     // clear page actions
     if (!File::canAdd($this->logged_user, $this->active_project)) {
         $this->httpError(HTTP_ERR_FORBIDDEN);
     }
     // if
     $file_data = array('milestone_id' => $this->request->get('milestone_id'), 'visibility' => $this->active_project->getDefaultVisibility());
     if (instance_of($this->active_category, 'Category')) {
         $file_data['parent_id'] = $this->active_category->getId();
     }
     // if
     js_assign('files_section_url', files_module_url($this->active_project));
     require_once SMARTY_PATH . '/plugins/modifier.filesize.php';
     $this->smarty->assign(array('file_data' => $file_data, 'max_upload_size' => smarty_modifier_filesize(get_max_upload_size()), 'upload_single_file_url' => assemble_url('project_files_upload_single', array('project_id' => $this->active_project->getId()))));
 }
 /**
  * Render log details
  * 
  * @param ProjectObject $object
  * @param boolean $in_project
  * @return string
  */
 function renderBody($object = null, $in_project = false)
 {
     $attachment = $this->getAttachment();
     if (instance_of($attachment, 'Attachment')) {
         if ($object === null) {
             $object = $this->getObject();
         }
         // if
         require_once SMARTY_PATH . '/plugins/modifier.filesize.php';
         $result = '<div class="file_details">';
         $result .= '<div class="file_thumbnail"><img src="' . $attachment->getThumbnailUrl() . '" alt="" /></div>';
         $result .= '<div class="file_name"><a href="' . $attachment->getViewUrl() . '">' . clean($object->getName()) . '</a>, ' . smarty_modifier_filesize($attachment->getSize()) . '</div>';
         $result .= '</div>';
         return $result;
     } else {
         return '';
     }
     // if
 }
 /**
  * Upload file document page action
  * 
  * @param void
  * @return void
  */
 function upload_file()
 {
     $this->wireframe->print_button = false;
     if (!Document::canAdd($this->logged_user)) {
         $this->httpError(HTTP_ERR_FORBIDDEN);
     }
     // if
     $file = $_FILES['file'];
     $file_data = $this->request->post('file');
     if (!is_array($file_data)) {
         $file_data = array('category_id' => $this->active_document_category->getId());
     }
     // if
     require_once SMARTY_PATH . '/plugins/modifier.filesize.php';
     $this->smarty->assign(array('file_data' => $file_data, 'max_upload_size' => smarty_modifier_filesize(get_max_upload_size())));
     if ($this->request->isSubmitted()) {
         db_begin_work();
         $this->active_document->setAttributes($file_data);
         if (is_array($file)) {
             $destination_file = get_available_uploads_filename();
             if (move_uploaded_file($file['tmp_name'], $destination_file)) {
                 if (FIX_UPLOAD_PERMISSION !== false) {
                     @chmod($destination_file, FIX_UPLOAD_PERMISSION);
                 }
                 // if
                 $this->active_document->setName($file['name']);
                 $this->active_document->setBody(basename($destination_file));
                 $this->active_document->setMimeType($file['type']);
             }
             // if
         }
         // if
         $this->active_document->setCreatedBy($this->logged_user);
         $this->active_document->setType('file');
         $save = $this->active_document->save();
         if ($save && !is_error($save)) {
             $notify_user_ids = $this->request->post('notify_users');
             if (is_foreachable($notify_user_ids)) {
                 $notify_users = Users::findByIds($notify_user_ids);
                 $owner_company = get_owner_company();
                 if (is_foreachable($notify_users)) {
                     ApplicationMailer::send($notify_users, 'documents/new_upload_file_document', array('document_name' => $this->active_document->getName(), 'created_by_name' => $this->active_document->getCreatedByName(), 'created_by_url' => $this->logged_user->getViewUrl(), 'document_url' => $this->active_document->getViewUrl(), 'owner_company_name' => $owner_company->getName()), $this->active_document);
                 }
                 // if
             }
             // if
             db_commit();
             flash_success('Document ":document_name" has been uploaded', array('document_name' => $this->active_document->getName()));
             $this->redirectTo('documents');
         } else {
             db_rollback();
             $this->smarty->assign('errors', $save);
         }
         // if
     }
     // if
 }