KTColumns.inc.php.tmp
Upload User: wlgs5050
Upload Date: 2016-06-11
Package Size: 30961k
Code Size: 20k
Category:

Linux Network

Development Platform:

PHP

  1. <?php
  2. /**
  3.  * $Id$
  4.  *
  5.  * KnowledgeTree Community Edition
  6.  * Document Management Made Simple
  7.  * Copyright (C) 2008 KnowledgeTree Inc.
  8.  * Portions copyright The Jam Warehouse Software (Pty) Limited
  9.  * 
  10.  * This program is free software; you can redistribute it and/or modify it under
  11.  * the terms of the GNU General Public License version 3 as published by the
  12.  * Free Software Foundation.
  13.  * 
  14.  * This program is distributed in the hope that it will be useful, but WITHOUT
  15.  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  16.  * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
  17.  * details.
  18.  * 
  19.  * You should have received a copy of the GNU General Public License
  20.  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  21.  * 
  22.  * You can contact KnowledgeTree Inc., PO Box 7775 #87847, San Francisco, 
  23.  * California 94120-7775, or email info@knowledgetree.com.
  24.  * 
  25.  * The interactive user interfaces in modified source and object code versions
  26.  * of this program must display Appropriate Legal Notices, as required under
  27.  * Section 5 of the GNU General Public License version 3.
  28.  * 
  29.  * In accordance with Section 7(b) of the GNU General Public License version 3,
  30.  * these Appropriate Legal Notices must retain the display of the "Powered by
  31.  * KnowledgeTree" logo and retain the original copyright notice. If the display of the 
  32.  * logo is not reasonably feasible for technical reasons, the Appropriate Legal Notices
  33.  * must display the words "Powered by KnowledgeTree" and retain the original 
  34.  * copyright notice.
  35.  * Contributor( s): ______________________________________
  36.  */
  37. // more advanced, intelligent columns.
  38. require_once(KT_LIB_DIR . '/browse/advancedcolumns.inc.php');
  39. class AdvancedTitleColumn extends AdvancedColumn {
  40.     var $name = 'title';
  41.     var $namespace = 'ktcore.columns.title';
  42.     var $sortable = true;
  43.     var $aOptions = array();
  44.     var $aIconPaths = array();
  45.     var $link_folders = true;
  46.     var $link_documents = true;
  47.     function setOptions($aOptions) {
  48.         $this->link_folders = KTUtil::arrayGet($aOptions, 'link_folders', $this->link_folders, false);
  49.         $this->link_documents = KTUtil::arrayGet($aOptions, 'link_documents', $this->link_documents, false);
  50.         parent::setOptions($aOptions);
  51.     }
  52.     function AdvancedTitleColumn() {
  53.         $this->label = _kt("Title");
  54.     }
  55.     // what is used for sorting
  56.     // query addition is:
  57.     //    [0] => join claus
  58.     //    [1] => join params
  59.     //    [2] => ORDER
  60.     function addToFolderQuery() {
  61.         return array(null,
  62.             null,
  63.             "F.name",
  64.         );
  65.     }
  66.     function addToDocumentQuery() {
  67.             return array(null,
  68.             null,
  69.             "DM.name"
  70.         );
  71.     }
  72.     function renderFolderLink($aDataRow) {
  73.         /* this check has to be done so that any titles longer than 40 characters is not displayed incorrectly.
  74.          as mozilla cannot wrap text without white spaces */
  75.         if (mb_strlen($aDataRow["folder"]->getName(), 'UTF-8') > 40) {
  76.          mb_internal_encoding("UTF-8");
  77.             $outStr = htmlentities(mb_substr($aDataRow["folder"]->getName(), 0, 40, 'UTF-8')."...", ENT_NOQUOTES, 'UTF-8');
  78.         }else{
  79.             $outStr = htmlentities($aDataRow["folder"]->getName(), ENT_NOQUOTES, 'UTF-8');
  80.         }
  81.         if($this->link_folders) {
  82.             $outStr = '<a class="contenttype_href" href="' . $this->buildFolderLink($aDataRow) . '">' . $outStr . '</a>';
  83.         }
  84.         return $outStr;
  85.     }
  86.     function renderDocumentLink($aDataRow) {
  87.         /* this check has to be done so that any titles longer than 40 characters is not displayed incorrectly.
  88.          as mozilla cannot wrap text without white spaces */
  89.         if (mb_strlen($aDataRow["document"]->getName(), 'UTF-8') > 40) {
  90.          mb_internal_encoding("UTF-8");
  91.             $outStr = htmlentities(mb_substr($aDataRow["document"]->getName(), 0, 40, 'UTF-8')."...", ENT_NOQUOTES, 'UTF-8');
  92.         }else{
  93.             $outStr = htmlentities($aDataRow["document"]->getName(), ENT_NOQUOTES, 'UTF-8');
  94.         }
  95.         if($this->link_documents) {
  96.             $outStr = '<a href="' . $this->buildDocumentLink($aDataRow) . '" title="' . htmlentities($aDataRow["document"]->getFilename(), ENT_QUOTES, 'UTF-8').'">' .
  97.                 $outStr . '</a>';
  98.         }
  99.         return $outStr;
  100.     }
  101.     function buildDocumentLink($aDataRow) {
  102.      if($aDataRow['document']->isSymbolicLink()){
  103.      $iDocId = $aDataRow['document']->getRealDocumentId();
  104.      }else{
  105.      $iDocId = $aDataRow["document"]->getId();
  106.      }
  107.         $url = KTBrowseUtil::getUrlForDocument($iDocId);
  108.         if($aDataRow['document']->isSymbolicLink()){
  109.          $aDataRow['document']->switchToRealCore();
  110.          $url .= "&fShortcutFolder=".$aDataRow['document']->getFolderId();
  111.         }
  112.         return $url;
  113.     }
  114.     // 'folder_link' allows you to link to a different URL when you're connecting, instead of addQueryStringSelf
  115.     // 'direct_folder' means that you want to go to 'browse folder'
  116.     // 'qs_params' is an array (or string!) of params to add to the link
  117.     function buildFolderLink($aDataRow) {
  118.         if (is_null(KTUtil::arrayGet($this->aOptions, 'direct_folder'))) {
  119.            $dest = KTUtil::arrayGet($this->aOptions, 'folder_link');
  120.            if($aDataRow['folder']->isSymbolicLink()){
  121.             $params = array('fFolderId' => $aDataRow['folder']->getLinkedFolderId(),
  122.      'fShortcutFolder' => $aDataRow['folder']->getParentID());
  123.            }else{
  124.            $params = array('fFolderId' => $aDataRow['folder']->getId());
  125.            }
  126.     $params = kt_array_merge(KTUtil::arrayGet($this->aOptions, 'qs_params', array()),
  127.      $params);
  128.             if (empty($dest)) {
  129.                 return KTUtil::addQueryStringSelf($params);
  130.             } else {
  131.                 return KTUtil::addQueryString($dest, $params);
  132.             }
  133.         } else {
  134.          if($aDataRow['folder']->isSymbolicLink()){
  135.          return KTBrowseUtil::getUrlForFolder($aDataRow['folder']->getLinkedFolder())."&fShortcutFolder=".$aDataRow['folder']->getParentID();
  136.          }else{
  137.              return KTBrowseUtil::getUrlForFolder($aDataRow['folder']);
  138.          }
  139.         }
  140.     }
  141.     // use inline, since its just too heavy to even _think_ about using smarty.
  142.     function renderData($aDataRow) {
  143.        if ($aDataRow["type"] == "folder") {
  144.            $contenttype = 'folder';
  145.            $link = $this->renderFolderLink($aDataRow);
  146.            if($aDataRow['folder']->isSymbolicLink()){
  147.             return sprintf('<span class="contenttype %s">%s<img src="resources/tango-icons/shortcut.png" /></span>', $contenttype, $link);
  148.            }else{
  149.             return sprintf('<span class="contenttype %s">%s</span>', $contenttype, $link);
  150.            }
  151.         } else {
  152.          $contenttype = $this->_mimeHelper($aDataRow["document"]->getMimeTypeId());
  153.             $link = $this->renderDocumentLink($aDataRow);
  154.            
  155.             //Render an image instead of the size in case of a shortcut
  156.            if($aDataRow['document']->isSymbolicLink()){           
  157.             return sprintf('<span class="contenttype %s">%s <img src="resources/tango-icons/shortcut.png" /></span>', $contenttype, $link);
  158.            }else{
  159.             $size = $this->prettySize($aDataRow["document"]->getSize());
  160.             return sprintf('<span class="contenttype %s">%s (%s)</span>', $contenttype, $link, $size);
  161.            }
  162.         }
  163.     }
  164.     function prettySize($size) {
  165.         $finalSize = $size;
  166.         $label = 'b';
  167.         if ($finalSize > 1000) { $label='Kb'; $finalSize = floor($finalSize/1000); }
  168.         if ($finalSize > 1000) { $label='Mb'; $finalSize = floor($finalSize/1000); }
  169.         return $finalSize . $label;
  170.     }
  171.     function _mimeHelper($iMimeTypeId) {
  172.         require_once(KT_LIB_DIR . '/mime.inc.php');
  173.         return KTMime::getIconPath($iMimeTypeId);
  174.     }
  175. }
  176. /*
  177.  * Column to handle dates
  178.  */
  179. class AdvancedDateColumn extends AdvancedColumn {
  180.     var $name = 'datecolumn';
  181.     var $document_field_function;
  182.     var $folder_field_function;
  183.     var $sortable = true;
  184.     var $document_sort_column;
  185.     var $folder_sort_column;
  186.     var $namespace = 'ktcore.columns.genericdate';
  187.     function AdvancedDateColumn() {
  188.         $this->label = _kt('Generic Date Function');
  189.     }
  190.     // use inline, since its just too heavy to even _think_ about using smarty.
  191.     function renderData($aDataRow) {
  192.         $outStr = '';
  193.         if (($aDataRow["type"] == "folder") && (!is_null($this->folder_field_function))) {
  194.             $res = call_user_func(array($aDataRow["folder"],  $this->folder_field_function));
  195.             $dColumnDate = strtotime($res);
  196.             // now reformat this into something "pretty"
  197.             return date("Y-m-d H:i", $dColumnDate);
  198.         } else if (($aDataRow["type"] == "document") && (!is_null($this->document_field_function))) {
  199.             $res = call_user_func(array($aDataRow["document"],  $this->document_field_function));
  200.             $dColumnDate = strtotime($res);
  201.             // now reformat this into something "pretty"
  202.             return date("Y-m-d H:i", $dColumnDate);
  203.         } else {
  204.             return '&mdash;';
  205.         }
  206.         return $outStr;
  207.     }
  208.     function addToFolderQuery() {
  209.         return array(null, null, null);
  210.     }
  211.     function addToDocumentQuery() {
  212.         return array(null, null, $this->document_sort_column);
  213.     }
  214. }
  215. class CreationDateColumn extends AdvancedDateColumn {
  216.     var $document_field_function = 'getCreatedDateTime';
  217.     var $folder_field_function = null;
  218.     var $document_sort_column = "D.created";
  219.     var $folder_sort_column = null;
  220.     var $namespace = 'ktcore.columns.creationdate';
  221.     function CreationDateColumn() {
  222.         $this->label = _kt('Created');
  223.     }
  224. }
  225. class ModificationDateColumn extends AdvancedDateColumn {
  226.     var $document_field_function = 'getLastModifiedDate';
  227.     var $folder_field_function = null;
  228.     var $document_sort_column = "D.modified";
  229.     var $folder_sort_column = null;
  230.     var $namespace = 'ktcore.columns.modificationdate';
  231.     function ModificationDateColumn() {
  232.         $this->label = _kt('Modified');
  233.     }
  234. }
  235. class AdvancedUserColumn extends AdvancedColumn {
  236.     var $document_field_function;
  237.     var $folder_field_function;
  238.     var $sortable = false; // by default
  239.     var $document_sort_column;
  240.     var $folder_sort_column;
  241.     var $namespace = 'ktcore.columns.genericuser';
  242.     function AdvancedUserColumn() {
  243.         $this->label = null; // abstract.
  244.     }
  245.     // use inline, since its just too heavy to even _think_ about using smarty.
  246.     function renderData($aDataRow) {
  247.         $iUserId = null;
  248.         if (($aDataRow["type"] == "folder") && (!is_null($this->folder_field_function))) {
  249.             if (method_exists($aDataRow['folder'], $this->folder_field_function)) {
  250.                 $iUserId = call_user_func(array($aDataRow['folder'], $this->folder_field_function));
  251.             }
  252.         } else if (($aDataRow["type"] == "document") && (!is_null($this->document_field_function))) {
  253.             if (method_exists($aDataRow['document'], $this->document_field_function)) {
  254.                 $iUserId = call_user_func(array($aDataRow['document'], $this->document_field_function));
  255.             }
  256.         }
  257.         if (is_null($iUserId)) {
  258.             return '&mdash;';
  259.         }
  260.         $oUser = User::get($iUserId);
  261.         if (PEAR::isError($oUser) || $oUser == false) {
  262.             return '&mdash;';
  263.         } else {
  264.             return htmlentities($oUser->getName(), ENT_NOQUOTES, 'UTF-8');
  265.         }
  266.     }
  267.     function addToFolderQuery() {
  268.         return array(null, null, null);
  269.     }
  270.     function addToDocumentQuery() {
  271.         return array(null, null, null);
  272.     }
  273. }
  274. class CreatorColumn extends AdvancedUserColumn {
  275.     var $document_field_function = "getCreatorID";
  276.     var $folder_field_function = "getCreatorID";
  277.     var $sortable = true; // by default
  278.     var $namespace = 'ktcore.columns.creator';
  279.     function CreatorColumn() {
  280.         $this->label = _kt("Creator"); // abstract.
  281.     }
  282. }
  283. class AdvancedSelectionColumn extends AdvancedColumn {
  284.     var $rangename = null;
  285.     var $show_folders = true;
  286.     var $show_documents = true;
  287.     var $namespace = "ktcore.columns.selection";
  288.     function AdvancedSelectionColumn() {
  289.         $this->label = '';
  290.     }
  291.     function setOptions($aOptions) {
  292.         AdvancedColumn::setOptions($aOptions);
  293.         $this->rangename = KTUtil::arrayGet($this->aOptions, 'rangename', $this->rangename);
  294.         $this->show_folders = KTUtil::arrayGet($this->aOptions, 'show_folders', $this->show_folders, false);
  295.         $this->show_documents = KTUtil::arrayGet($this->aOptions, 'show_documents', $this->show_documents, false);
  296.     }
  297.     function renderHeader($sReturnURL) {
  298.         global $main;
  299.         $main->requireJSResource("resources/js/toggleselect.js");
  300.         return sprintf('<input type="checkbox" title="toggle all" onclick="toggleSelectFor(this, '%s')" />', $this->rangename);
  301.     }
  302.     // only include the _f or _d IF WE HAVE THE OTHER TYPE.
  303.     function renderData($aDataRow) {
  304.         $localname = htmlentities($this->rangename,ENT_QUOTES,'UTF-8');
  305.         if (($aDataRow["type"] === "folder") && ($this->show_folders)) {
  306.             if ($this->show_documents) {
  307.                 $localname .= "_f[]";
  308.             }
  309.             $v = $aDataRow["folderid"];
  310.         } else if (($aDataRow["type"] === "document") && $this->show_documents) {
  311.             if ($this->show_folders) {
  312.                 $localname .= "_d[]";
  313.             }
  314.             $v = $aDataRow["docid"];
  315.         } else {
  316.             return '&nbsp;';
  317.         }
  318.         return sprintf('<input type="checkbox" name="%s" onclick="activateRow(this)" value="%s"/>', $localname, $v);
  319.     }
  320.     // no label, but we do have a title
  321.     function getName() {
  322.         return _kt("Multiple Selection");
  323.     }
  324. }
  325. class AdvancedSingleSelectionColumn extends AdvancedSelectionColumn {
  326.     var $namespace = 'ktcore.columns.singleselection';
  327.     function AdvancedSingleSelectionColumn() {
  328.         parent::AdvancedSelectionColumn();
  329.         $this->label = null;
  330.     }
  331.     function renderHeader() {
  332.      global $main;
  333.         //include some javascript to force real single selections
  334.         if($this->show_folders && $this->show_documents){
  335.          $main->requireJSResource("resources/js/singleselect.js");
  336.         }
  337.         return '&nbsp;';
  338.     }
  339.     // only include the _f or _d IF WE HAVE THE OTHER TYPE.
  340.     function renderData($aDataRow) {
  341.         $localname = $this->rangename;
  342.         if (($aDataRow["type"] === "folder") && ($this->show_folders)) {
  343.             if ($this->show_documents) {
  344.                 $localname .= "_f";
  345.             }
  346.             $v = $aDataRow["folderid"];
  347.         } else if (($aDataRow["type"] === "document") && $this->show_documents) {
  348.             if ($this->show_folders) {
  349.                 $localname .= "_d";
  350.             }
  351.             $v = $aDataRow["docid"];
  352.         } else {
  353.             return '&nbsp;';
  354.         }
  355.         $return =  '<input type="radio" name="' . $localname . '" value="' . $v . '" ';  
  356.         if($this->show_folders && $this->show_documents){
  357.          $return .= 'onClick="forceSingleSelect(this)" ';
  358.         }
  359.         $return .='/>';
  360.         return $return;
  361.     }
  362.     // no label, but we do have a title
  363.     function getName() {
  364.         return _kt("Single Selection");
  365.     }
  366. }
  367. class AdvancedWorkflowColumn extends AdvancedColumn {
  368.     var $namespace = 'ktcore.columns.workflow_state';
  369.     var $sortable = false;
  370.     function AdvancedWorkflowColumn() {
  371.         $this->label = _kt("Workflow State");
  372.         $this->sortable = false;
  373.     }
  374.     // use inline, since its just too heavy to even _think_ about using smarty.
  375.     function renderData($aDataRow) {
  376.         // only _ever_ show this for documents.
  377.         if ($aDataRow["type"] === "folder") {
  378.             return '&nbsp;';
  379.         }
  380.         $oWorkflow = KTWorkflowUtil::getWorkflowForDocument($aDataRow['document']);
  381.         $oState = KTWorkflowUtil::getWorkflowStateForDocument($aDataRow['document']);
  382.         if (($oState == null) || ($oWorkflow == null)) {
  383.             return '&mdash;';
  384.         } else {
  385.             return sprintf('%s <span class="descriptive">%s</span>',
  386.                 htmlentities($oState->getName(), ENT_NOQUOTES, 'UTF-8'),
  387.                 htmlentities($oWorkflow->getName(), ENT_NOQUOTES, 'UTF-8')
  388.             );
  389.         }
  390.     }
  391. }
  392. class CheckedOutByColumn extends AdvancedColumn {
  393.     var $namespace = 'ktcore.columns.checkedout_by';
  394.     var $sortable = false;
  395.     function CheckedOutByColumn() {
  396.         $this->label = _kt('Checked Out By');
  397.         $this->sortable = false;
  398.     }
  399.     function renderData($aDataRow) {
  400.         // only show this for documents.
  401.         if ($aDataRow['type'] === 'folder') {
  402.             return '&nbsp;';
  403.         }
  404.         // Check if document is checked out
  405.         $bIsCheckedOut = $aDataRow['document']->getIsCheckedOut();
  406.         if($bIsCheckedOut){
  407.             // Get the user id
  408.             $iUserId = $aDataRow['document']->getCheckedOutUserID();
  409.             $oUser = User::get($iUserId);
  410.             $sUser = $oUser->getName();
  411.             return '<span class="descriptive">'.htmlentities($sUser, ENT_NOQUOTES, 'UTF-8').'</span>';
  412.         }
  413.         return '&mdash;';
  414.     }
  415. }
  416. class DocumentTypeColumn extends AdvancedColumn {
  417.     var $namespace = 'ktcore.columns.document_type';
  418.     var $sortable = false;
  419.     function DocumentTypeColumn() {
  420.         $this->label = _kt('Document Type');
  421.         $this->sortable = false;
  422.     }
  423.     function renderData($aDataRow) {
  424.         // only show this for documents.
  425.         if ($aDataRow['type'] === 'folder') {
  426.             return '&nbsp;';
  427.         }
  428.         // Check if document is checked out
  429.         $iDocTypeId = $aDataRow['document']->getDocumentTypeID();
  430.         if(!empty($iDocTypeId)){
  431.             $oDocumentType = DocumentType::get($iDocTypeId);
  432.             $sType = $oDocumentType->getName();
  433.             return '<span class="descriptive">'.htmlentities($sType, ENT_NOQUOTES, 'UTF-8').'</span>';
  434.         }
  435.         return '&mdash;';
  436.     }
  437. }
  438. class AdvancedDownloadColumn extends AdvancedColumn {
  439.     var $namespace = 'ktcore.columns.download';
  440.     function AdvancedDownloadColumn() {
  441.         $this->label = null;
  442.     }
  443.     function renderHeader($sReturnURL) {
  444.         return '&nbsp;';
  445.     }
  446.     function renderData($aDataRow) {
  447.         // only _ever_ show this for documents.
  448.         if ($aDataRow["type"] === "folder") {
  449.             return '&nbsp;';
  450.         }
  451.         $link = KTUtil::ktLink('action.php','ktcore.actions.document.view', 'fDocumentId=' . $aDataRow['document']->getId());
  452.         return sprintf('<a href="%s" class="ktAction ktDownload" title="%s">%s</a>', $link, _kt('Download Document'), _kt('Download Document'));
  453.     }
  454.     function getName() { return _kt('Download'); }
  455. }
  456. class DocumentIDColumn extends AdvancedColumn {
  457.     var $bSortable = false;
  458.     var $namespace = 'ktcore.columns.docid';
  459.     function DocumentIDColumn() {
  460.         $this->label = _kt("Document ID");
  461.     }
  462.     function renderData($aDataRow) {
  463.         // only _ever_ show this for documents.
  464.         if ($aDataRow["type"] === "folder") {
  465.             return '&nbsp;';
  466.         }
  467.         return htmlentities($aDataRow['document']->getId(), ENT_NOQUOTES, 'UTF-8');
  468.     }
  469. }
  470. class ContainingFolderColumn extends AdvancedColumn {
  471.     var $namespace = 'ktcore.columns.containing_folder';
  472.     function ContainingFolderColumn() {
  473.         $this->label = _kt("View Folder");
  474.     }
  475.     function renderData($aDataRow) {
  476.         // only _ever_ show this for documents.
  477.         if ($aDataRow["type"] === "folder") {
  478.             return '&nbsp;';
  479.         }
  480.         $link = KTBrowseUtil::getUrlForFolder($aDataRow['document']->getFolderId());
  481.         return sprintf('<a href="%s" class="ktAction ktMoveUp" title="%s">%s</a>', $link, _kt('View Folder'), _kt('View Folder'));
  482.     }
  483.     function getName() { return _kt('Opening Containing Folder'); }
  484. }
  485. ?>