Caravel CMS PHP Cross Reference Content Management Systems

Source: /apps/FolderViewer/FolderViewer.php - 2405 lines - 113415 bytes - Summary - Text - Print

   1  <?php
   2  
   3  require_once(T_CODE_BASE . 'File/FileTypeTable.php');
   4  require_once (T_CODE_BASE . 'File/oFile.php');
   5  require_once(T_APP_BASE . 'Comments/Comments.php');
   6  
   7  class FolderViewer extends App
   8      {
   9      /*
  10      * get HTML contents of this page
  11          *
  12          * @param    boolean in preview mode?
  13          * @return   string  HTML page contents
  14          * @access   public
  15      */
  16  	function getContent($preview = false)
  17          {
  18          if(T_SINGLE_BLOCK && $_SESSION['folderviewerfileedit'] == $this->ldapDN)
  19              {
  20              $this->httpVars['alreadyloaded'] = true;
  21              $this->edit = true;
  22              unset($_SESSION['folderviewerfileedit']);
  23              return FolderViewer::getConfig();
  24              }
  25       
  26          $this->folderDN = $this->settingsVars['folderDN'];
  27  
  28          if ($preview)
  29              $this->set =& $_SESSION['folderSettings'];
  30          else
  31              $this->set =& $this->settingsVars;
  32  
  33          if($this->folderDN == "")
  34            $this->folderDN = $this->set['folderDN'];
  35          if (!$this->ldap->dnExists($this->folderDN)) return '';
  36  
  37          //determines whether the calendar will be shown or a list of filtered files
  38          $calendarMode = $this->set['listType'] == 'calendar' || $this->set['listTemplate'] == 'calendar~';
  39          $blogcalendarMode = ($this->set['blogcalendar'] == 'on') && !$this->dynamic_content;
  40  
  41          if (($this->dynamic_content or @$this->httpVars['dn']) && !$calendarMode && !$blogcalendarMode) {
  42              $dynamic_params = @$GLOBALS['caravel']['dynamic_info']['params'];
  43              if ($dynamic_params[0] == '&') {
  44                  $this->category = substr($dynamic_params, 1);
  45              } else if (preg_match('/^\d{4}$/', $dynamic_params)) {
  46                  $this->set['limitType'] = 'daterange';
  47                  $this->set['limit'] = mktime(0, 0, 0, 1, 1, $dynamic_params) . '..' . mktime(0, 0, 0, 12, 32, $dynamic_params);
  48              } else if (preg_match('!^(\d{1,2})/(\d{4})$!', $dynamic_params, $tmp)) {
  49                  $this->set['limitType'] = 'daterange';
  50                  $this->set['limit'] = mktime(0, 0, 0, $tmp[1], 1, $tmp[2]) . '..' . mktime(0, 0, 0, $tmp[1] + 1, 1, $tmp[2]);
  51              } else {
  52                  if (@$this->httpVars['dn'])
  53                      $dn = $this->httpVars['dn'];
  54                  else
  55                      $dn = 'mnF=' . $GLOBALS['caravel']['dynamic_info']['params'] . ',' . $this->folderDN;
  56                  $contents = $this->ldap->search('(objectclass=*)', array('dn', 'mennoattributes'), $dn, LDAP_SCOPE_BASE);
  57                  if (mnError::isError($contents))
  58                      return new mnError('FolderViewer::getContent: ' . $contents->getMessage(), __FILE__, __LINE__);
  59                  $artmp = Utility::processParams($contents[0]['mennoattributes']);
  60                  $this->attrs[$dn] = $artmp[$GLOBALS['CV_CURR_LANG']];
  61                  $attrs = explode('~', $this->set['fileTemplate']);
  62                  if(T_SINGLE_NAV || T_SINGLE_BLOCK)
  63                      return "<div style='padding: 10px;'>".FolderViewer::viewListFile($dn, $attrs)."</div>";
  64                  else
  65                      return FolderViewer::viewListFile($dn, $attrs);  
  66              }
  67          } else if (isset($_REQUEST['cv_dnsdate']) && ($this->blockID == $GLOBALS['caravel']['dynamic_info']['dest_block'] || !isset($GLOBALS['caravel']['dynamic_info']['dest_block']))  )
  68          //this is set when a calendar date with items on it is selected and should be displayed
  69          {
  70            //the date by which all associated files should be displayed
  71            $date = isset($GLOBALS['caravel']['dynamic_info']['params']) ? $GLOBALS['caravel']['dynamic_info']['params'] : $_REQUEST['cv_dnsdate'];
  72            $load = date('Y-n-j', strtotime($date) );
  73            $attrs = explode('~', $this->set['fileTemplate']);
  74            
  75            FolderViewer::loadFileList();
  76            foreach ($this->files as $f)
  77                {
  78                $calendar[] = FolderViewer::viewListFile($f, $attrs, false, 1);
  79                }
  80  
  81            $calendarDates = array();
  82            foreach ($calendar as $i => $v)
  83              {
  84              if (count($calendarDates[key($v)]) == 0)
  85                  {
  86                  $calendarDates[key($v)] = $v[key($v)];
  87                  }
  88              else
  89                  {
  90                  $calendarDates[key($v)] = $calendarDates[key($v)] + $v[key($v)];
  91                  }
  92              }
  93            $contentString = '';
  94            
  95            if (is_array($calendarDates[$load]))
  96            foreach ($calendarDates[$load] as $filename => $contents)
  97              {
  98              $contentString .= FolderViewer::viewListFile($filename, $attrs, false) .'<br>' ;
  99              }
 100            return $contentString;
 101            }
 102          
 103          FolderViewer::loadFileList();
 104          // now we should be narrowed down to the files that are supposed to be visible
 105          // but we need to sort them
 106          FolderViewer::sortFileList($this->set['sortStyle']);
 107          
 108          // now we can actually display the list!
 109          $tpl = new Template_PHPLIB(T_APP_BASE .'FolderViewer');
 110          $tpl->setFile(array('main' => 'list.tpl.html',
 111                      'doc' => 'document.tpl.html'));
 112          $tpl->setVar( 'relativeTop', $this->paramName('relativeTop') );
 113  
 114          // add RSS auto-discovery link in header
 115          $this->addHeader($this->link_to_feed());
 116  
 117          // intialize blocks
 118          $tpl->setBlock( 'main',              'titleBlock',           'titleB'        );
 119          $tpl->setBlock( 'main',              'descBlock',            'descB'         );
 120          $tpl->setBlock( 'main',              'pagedView',            'pagedV'        );
 121          $tpl->setBlock( 'pagedView',         'populateBlock',        'populateB'     );
 122          $tpl->setBlock( 'pagedView',         'pageBlock',            'pageB'         );
 123          $tpl->setBlock( 'pageBlock',         'pageHeaderBlock',      'pageHeaderB'   );
 124          $tpl->setBlock( 'pagedView',         'navBlock',             'navB'          );
 125          $tpl->setBlock( 'main',              'selectListView',       'selectListV'   );
 126          $tpl->setBlock( 'selectListView',    'sbOptionsBlock',       'sbOptionsB'    );
 127          $tpl->setBlock( 'selectListView',    'sbButtonBlock',        'sbButtonB'     );
 128          $tpl->setVar( 'titleB', '' );
 129          $tpl->setVar( 'descB', '' );
 130          $tpl->setVar( 'pagedV', '' );
 131          $tpl->setVar( 'populateB', '' );
 132          $tpl->setVar( 'pageB',  '' );
 133          $tpl->setVar( 'pageHeaderB', '' );
 134          $tpl->setVar( 'navB', '' );
 135          $tpl->setVar( 'selectListV', '' );
 136          $tpl->setVar( 'sbOptionsB', '' );
 137          $tpl->setVar( 'sbButtonB', '' );
 138          $tpl->setVar( 'files', '' );
 139          $blocks = array('title', 'link', 'author', 'date', 'content', 'separator', 'return');
 140          foreach ($blocks as $block)
 141              {
 142              $tpl->setBlock('doc', $block . 'Block', $block . 'B');
 143              $tpl->setVar($block . 'B', '');
 144              }
 145                  if($this->set['displayTitle'] != '')
 146                      {
 147              if ($this->set['title'] != '')
 148                  {
 149                  $tpl->setVar('title', $this->set['title']);
 150                  $tpl->parse('titleB','titleBlock');
 151                  }
 152              if ($this->set['description'] != '')
 153                  {
 154                  $tpl->setVar('desc', $this->set['description'] . '<br>');
 155                  $tpl->parse('descB','descBlock');
 156                  }
 157              }
 158  
 159              $firstDN = $this->paramName('firstDN');
 160              $tpl->setVar('firstDN', isset($this->files[0]) ? "<script type=\"text/javascript\" language=\"Javascript\">var $firstDN = '" . $this->files[0] . "'</script>" : '');
 161  
 162          if ($this->set['listType'] == 'select' or $this->set['listType'] == 'dropdown')
 163              {
 164              $dropdown = $this->set['listType'] == 'dropdown';
 165  
 166              $formName = 'FVSB_' . $this->blockID;
 167              $tpl->setVar('sbFormName', $formName);
 168  
 169              $url = '';
 170              $js = "var val=document.getElementById('" . $this->paramName('dn') . "').value;";
 171              $link = $this->link_to_file_view('FILE');
 172              $js = "val=document.getElementById('" . $this->paramName('dn') . "').value; var url = '$link';";
 173              if ($this->set['linkTarget'] == '_blank')
 174                  $js .= "popup(url.replace('FILE', val), this.options[this.selectedIndex].text, 800, 700);";
 175              else
 176                  $js .= "window.location.href = url.replace('FILE', val);";
 177              $js .= "return false;";
 178              $tpl->setVar('sbFormAction', $url);
 179  
 180              $tpl->setVar('sbName', $this->paramName('dn'));
 181              $tpl->setVar('sbSize', $dropdown ? 1 : 10);
 182  
 183              if ($dropdown)
 184              {
 185              $tpl->setVar('val', '');
 186              $tpl->setVar('desc', '[ select one ]');
 187              $tpl->parse('sbOptionsB', 'sbOptionsBlock', true);
 188              $js = $preview ? "return false;" : $js;              
 189              $tpl->setVar('sbOnchange', 'onchange="' . ( $js ? $js : 'this.form.submit();' ) . '"');
 190              }
 191              else
 192              {
 193              $tpl->setVar('sbSubmit', $this->paramName('submit'));
 194              $js = $preview ? "return false;" : $js;
 195              $tpl->setVar('sbSubmitOnclick', $js ? 'onclick="' . $js . '"' : '');
 196              $tpl->parse('sbButtonB', 'sbButtonBlock');
 197              }
 198  
 199              foreach ($this->files as $f)
 200              {
 201              $fileAttrs =& $this->attrs[$f];
 202              if (@$fileYAttrs['title'])
 203                  $title = $fileAttrs['title'];
 204              else
 205                  $title = DN::dnToName($f);
 206              $tpl->setVar('val', $title);
 207              $tpl->setVar('desc', $title);
 208              $tpl->parse('sbOptionsB','sbOptionsBlock', true);
 209              }
 210  
 211              $tpl->parse('selectListV','selectListView');
 212              }
 213          else
 214              {
 215              $req_height = 80;
 216              $count = count($this->files);
 217              if (!isset($this->set['perpage']) || $this->set['perpage'] == "") $this->set['perpage'] = 1000;
 218              if (!isset($this->set['cols'])) $this->set['cols'] = "";
 219  
 220              $pages = ceil( $count / $this->set['perpage'] );
 221              $i = 0; $columnc = 0; $x = 0; $filesHtml = '';
 222              foreach ($this->files as $f)
 223                {
 224                $i++;
 225            
 226                if(T_USER != "" && $this->set['editlink'] != "")
 227                    $templatetmp = "adminlink~" . $this->set['listTemplate'];
 228                else
 229                    $templatetmp = $this->set['listTemplate'];
 230  
 231                $attrs = explode('~', $templatetmp);
 232                
 233                if ($calendarMode)
 234                  $calendar[] = FolderViewer::viewListFile($f, $attrs, $preview, 1);
 235                  
 236                if($blogcalendarMode)
 237                    {
 238                    $fAttrs =& $this->attrs[$f];
 239                    if ($this->set['blogcalendartype'] == 'month')
 240                        $dates[strtotime(date('m/1/Y', $fAttrs['createdate']))] = array('link' => date('n/Y', $fAttrs['createdate']), 'label' => str_replace(' ' . date('Y'), '', date('F Y', $fAttrs['createdate'])));
 241                    else
 242                        $dates[strtotime(date('1/1/Y', $fAttrs['createdate']))] = array('link' => date('Y', $fAttrs['createdate']), 'label' => date('Y', $fAttrs['createdate']));
 243                    }                
 244                
 245                // check for thumbnails in the template, if so then center vertical -- yes this is kind of a hack, tell me how you would do it --reuvenmh
 246                if(strpos($this->set['listTemplate'], 'thumb') !== false)
 247                  $newfilesHtml = "\n<div><table style='width: 100%;height: 90px;'><tr style='width: 100%;height: 90px;'><td style='vertical-align: middle;width: 100%;height: 90px;'>".FolderViewer::viewListFile($f, $attrs, $preview)."</td></tr></table></div>\n";
 248                else
 249                  $newfilesHtml = "\n<div>".FolderViewer::viewListFile($f, $attrs, $preview)."</div>\n";
 250                
 251                if($this->set['cols'] != "")
 252                  {
 253                  if($columnc == 0)
 254                    $filesHtml = "<div style='width: 100%;height:auto;clear: both;'>\n";
 255     
 256                  if(($columnc % $this->set['cols']) == 0)
 257                    $filesHtml .= "<div style='text-align: ".((strpos($this->set['listTemplate'], "thumb") === false) ? "left" : "center").";clear: both;margin-top:5px;float:left;width:".(floor(100/$this->set['cols']))."%;'>".$newfilesHtml."</div>\n";
 258                  else 
 259                    $filesHtml .= "<div style='text-align: ".((strpos($this->set['listTemplate'], "thumb") === false) ? "left" : "center").";float:left;margin-top: 5px;width:".(floor(100/$this->set['cols']))."%;'>".$newfilesHtml."</div>\n";  
 260                  }
 261                else
 262                  $filesHtml .= $newfilesHtml;  
 263                
 264                  if ($i % $this->set['perpage'] == 0 or $i == $count)
 265                  {
 266                  if($this->set['cols'] != "")
 267                    {
 268                    $filesHtml .= "</div><div style='clear: both;'>&nbsp;</div>";
 269                    $columnc = -1;
 270                    }
 271                  $tpl->setVar('files', $filesHtml);
 272                  $filesHtml = '';
 273  
 274                  $range = $x == 0 ? 1 : $x * $this->set['perpage'] + 1;
 275                  $range .= "-";
 276                  $range .= ( $x + 1 ) * $this->set['perpage'];
 277  
 278                  $tpl->setVar('visibility', $x == 0 ? 'block' : 'none' );
 279                  $tpl->setVar('id', $range);
 280                  if ($pages > 1) $tpl->parse('pageHeaderB', 'pageHeaderBlock');
 281                  $tpl->parse('pageB', 'pageBlock', true);
 282  
 283                  if ($count > $this->set['perpage'])
 284                  {
 285                  $tpl->setVar('range', $range);
 286                  $tpl->parse('navB', 'navBlock', true);
 287                  }
 288  
 289                  $tpl->setVar('arrayIndex', $x);
 290                  $tpl->setVar('arrayValue', $range);
 291                  $tpl->parse('populateB', 'populateBlock', true);
 292  
 293                  $x++;
 294                  }
 295                $columnc++;  
 296                }
 297              $tpl->parse('pagedV', 'pagedView');
 298              }
 299          
 300          //for calendar
 301          if ($calendarMode)
 302              {
 303              $calendarDates = array();
 304              foreach ($calendar as $i => $v)
 305                  {
 306                  if (count($calendarDates[key($v)]) == 0)
 307                      {
 308                      $calendarDates[key($v)] = $v[key($v)];
 309                      }
 310                  else
 311                      {
 312                      $calendarDates[key($v)] = $calendarDates[key($v)] + $v[key($v)];
 313                      }
 314                  }
 315              $contentString = '';
 316              if (is_array($calendarDates[$load]))
 317              foreach ($calendarDates[$load] as $filename => $contents)
 318                  {
 319                  $contentString .= $contents . "<br>" ;
 320                  }
 321  
 322              $field = '';
 323              $tpl = new Template_PHPLIB(T_APP_BASE . 'FolderViewer/');
 324              $tpl->setFile(array('main' => 'calendar.tpl.html'));
 325              $tpl->setVar('tWebInc', T_WEB_INC);
 326              
 327              $tpl->setVar('js_self', "document.cv_calendar.submit();");
 328              
 329              $popup = str_replace("&amp;", "&", Utility::link($this->sectionPathArray, array('cv_dnsdate' => 'DATE_VALUE', '_single' => $this->blockID)));
 330              $tpl->setVar('js_blank', $popup);
 331              
 332              //cb should be made to appear in a different blocks
 333              $dynamic_info = array('params' => 'DATE_VALUE', 'src_block' => $this->blockID);
 334              if (preg_match('/^CB\d+$/', $this->set['linkTarget'])) {
 335                  $dynamic_info['dest_block'] = $this->set['linkTarget'];
 336                  $sectionPathArray = $this->sectionPathArray;
 337              } else {
 338                  $dynamic_info['dest_block'] = DN::dnToName($this->set['linkTarget']);
 339                  $dynamic_info['src_page'] = DN::dnToPageID($this->pageDN);
 340                  $sectionPathArray = DN::dnToSectionArray(DN::dnToBase($this->set['linkTarget']));
 341              }           
 342              $url = str_replace("&amp;", "&", Utility::link($sectionPathArray, array( '_dynamic' => $dynamic_info)));
 343              $tpl->setVar('js_cb', $url );
 344              
 345              //one block
 346              $url = str_replace("&amp;", "&", Utility::link($this->sectionPathArray, array('_single' => $this->blockID, '_singleNav' => 1, $this->paramName('preview') => $preview )));
 347              $tpl->setVar('js_top', $url);
 348              
 349              $field .= $tpl->subst('main');
 350              //load css style sheet
 351              
 352  
 353              $mode = FormWidget::hidden("cv_display_mode", $this->settingsVars["linkTarget"],  array( 'id' =>"cv_display_mode") );
 354              
 355              return FolderViewer::jarray($calendarDates) . "<form name='cv_calendar' style='vertical-align:top;' method='post' action=''>"
 356                    . $mode
 357                    . "<input type='hidden' name='cv_dnsdate' value='' id='cv_dnsdate'>" 
 358                    . $field 
 359                    . '</form>';
 360              }
 361          else if($blogcalendarMode)
 362              {
 363              $this->set['linkTarget'] = $this->set['blogcalendarlocation'];
 364              $o = '';
 365              foreach ($dates as $date) {
 366                  $link = FolderViewer::link_to_file_view($date['link']);
 367                  $o .= '<a class="cv_fv_archive" href="' . $link . '">' . $date['label'] . '</a><br/>';
 368              }
 369  
 370              return $o;            
 371              }
 372          else
 373              {
 374              return $tpl->subst('main');
 375              }
 376          }
 377          
 378      //helper function for getContent method
 379      //must remain outside of the method to avoid breaking pages when
 380      //multiple folderviewers appear on the same page
 381  	function jarray($var)
 382              {
 383                $javastr = "";
 384                foreach ($var as $key =>  $val)
 385                  {
 386                  $javastr .= "<input type='hidden'  id='".$key ."' value='1'>";
 387                  }
 388                return $javastr;
 389              }
 390  
 391  	function getRSS() {
 392          $this->folderDN = $this->settingsVars['folderDN'];
 393          $this->set =& $this->settingsVars;
 394          $this->set['limitType'] = 
 395          $this->loadFileList();
 396          $items = array();
 397          foreach($this->files as $dn) {
 398              $attrs =& $this->attrs[$dn];
 399  
 400              // get the (brief) contents
 401              require_once(T_APP_BASE . 'FileViewer/FileViewer.php');
 402              // make sure file viewer knows not to display a close link, even in single block mode
 403              unset($this->settingsVars['title']);
 404              $this->fvVars['short'] = 1;
 405              $contents = FileViewer::getHtml($dn);
 406  
 407              $items[] = array(
 408                  'title' => (@$attrs['title'] ? $attrs['title'] : DN::dnToName($dn)),
 409                  'author' => $attrs['author'],
 410                  'target' => $this->link_to_file_view(DN::dnToName($dn), array(), true),
 411                  'info' => $contents, 
 412                  'created' => date($attrs['createdate']),
 413              );
 414          }
 415          return $items;
 416      }
 417      
 418      /**
 419      * gets all the files in the current directory and stores them in $this->files,
 420      * this function also does sorting for the dateCount, XdateCount, and random limitTypes
 421      *
 422      * @param    boolean  if this is false then filters will be applied (like not loading hidden files)
 423      * @return   none
 424      * @access   public
 425      **/
 426  	function loadFileList($filter = true)
 427          {
 428          // fetch the folder contents
 429          $contents = $this->ldap->search('(|(objectclass=' . C_LDAP_SHORTCUT_OBJECT . ')(objectclass=' . C_LDAP_FILE_OBJECT . '))',
 430              array('dn', 'mennoattributes'), $this->folderDN, LDAP_SCOPE_ONELEVEL);
 431  
 432          if (mnError::isError($contents) && ereg('No such object', $contents->getMessage()))
 433              $contents = array();
 434          else if (mnError::isError($contents))
 435              return new mnError('FolderViewer::loadFileList: Error loading folder contents: ' . $contents->getMessage());
 436          unset($contents['count']);
 437  
 438          $this->files = array();
 439          $this->attrs = array();
 440          if ($this->set['limitType'] == 'date' or $this->set['limitType'] == 'Xdate')
 441              $dateLimit = strtotime($this->set['limit']);
 442          if ($this->set['limitType'] == 'daterange')
 443              $dateLimit = explode('..', $this->set['limit']);
 444          foreach($contents as $file)
 445              {
 446              $name = DN::dnToName($file['dn']);
 447              // skip temporary files
 448              if (ereg('^tmp\.', $name))
 449                  continue;
 450                  
 451              // skip hidden files
 452              if ($filter && strpos($this->set['hidden'], $name . ":;:off") !== false)
 453                            continue;
 454  
 455              $artmp = Utility::processParams($file['mennoattributes']);
 456              $this->attrs[$file['dn']] = $artmp[$GLOBALS['CV_CURR_LANG']];
 457  
 458              // skip expired files
 459              if ($filter && $this->attrs[$file['dn']]['expDate'])
 460                  {
 461                  $file_expires = $this->attrs[$file['dn']]['expDate'];
 462                  $expDate = @strtotime($this->attrs[$file['dn']]['expDate']);
 463                  if ($expDate && $expDate !== -1)
 464                      {
 465                      $now = mktime(0,0,0,date('m'),date('d'),date('Y'));
 466                      $expDate = mktime(0,0,0,date('m',$expDate),date('d',$expDate),date('Y',$expDate));
 467                      if ($now > $expDate)
 468                          continue;
 469                      }
 470                  }
 471                  
 472              // skip files not in the specified category
 473              if (isset($this->category)) {
 474                  $cats = array_map('trim', explode(',', $this->attrs[$file['dn']]['keywords']));
 475                  if ($this->category == 'uncategorized' and @$this->attrs[$file['dn']]['keywords'] and !in_array('uncategorized', $cats))
 476                      continue;
 477                  if ($this->category != 'uncategorized' and !in_array($this->category, $cats))
 478                      continue;
 479              }
 480  
 481              // handle the simple limitTypes
 482              switch($this->set['limitType'])
 483                  {
 484                  case 'date':
 485                      if ($this->attrs[$file['dn']]['createdate'] >= $dateLimit)
 486                          $this->files[] = $file['dn'];
 487                      break;
 488                  case 'Xdate':
 489                      if ($this->attrs[$file['dn']]['createdate'] < $dateLimit)
 490                          $this->files[] = $file['dn'];
 491                      break;
 492                  case 'daterange':
 493                      if ($this->attrs[$file['dn']]['createdate'] > $dateLimit[0] and $this->attrs[$file['dn']]['createdate'] < $dateLimit[1])
 494                          $this->files[] = $file['dn'];                    
 495                      break;
 496                  case 'metadata':
 497                      if ($filter)
 498                          {
 499                          $params =& $this->attrs[$file['dn']];
 500                          $requireAll = $this->set['metadataRequireAll'] == 'on';
 501                          if ($requireAll)
 502                              {
 503                              $test = true;
 504                              }
 505                          else
 506                              {
 507                              $test = false;
 508                              }
 509                          
 510                          if ($this->set['metadatacriteria'] != null)
 511                              {
 512                              foreach ( $this->set['metadatacriteria'] as $i => $values)
 513                                  {
 514                                  if ($values[0] == 'filename')
 515                                      {
 516                                      $params[$values[0]] = DN::dnToName($file['dn']);
 517                                      }
 518                                  else if ($values[0] == 'createdate')
 519                                      {
 520                                      $params[$values[0]] = date('d M Y',$params['createdate']);
 521                                      }
 522                                  $values[2] = Utility::substituteVariables($values[2]);
 523                                  switch ($values[1])
 524                                      {
 525                                      case '=';
 526                                          if ( $params[$values[0]] == $values[2] )
 527                                              {
 528                                              if (!$requireAll)
 529                                                $test = true;
 530                                              }
 531                                          else
 532                                              {
 533                                              if ($requireAll)
 534                                                $test = false;
 535                                              }
 536                                          break;
 537                                      case 'contains';
 538                                          if ( strstr($params[$values[0]], $values[2] ) != false )
 539                                              {
 540                                              if (!$requireAll)
 541                                                $test = true;
 542                                              }
 543                                          else
 544                                              {
 545  
 546                                              if ($requireAll)
 547                                                $test = false;
 548                                              }
 549                                          break;
 550                                      case 'does not contain';
 551                                          if (  strstr($params[$values[0]], $values[2] ) == false )
 552                                              {
 553                                              if (!$requireAll)
 554                                                $test = true;
 555                                              }
 556                                          else
 557                                              {
 558                                              if ($requireAll)
 559                                                $test = false;
 560                                              }
 561                                          break;
 562                                      case ' !=';
 563                                          if ( $params[$values[0]] != $values[2] )
 564                                              {
 565                                              if (!$requireAll)
 566                                                $test = true;
 567                                              }
 568                                          else
 569                                              {
 570                                              if ($requireAll)
 571                                                $test = false;
 572                                              }
 573                                          break;
 574                                      case 'before(date)';
 575                                          if ( strtotime($params[$values[0]]) < strtotime($values[2]) )
 576                                              {
 577                                              if (!$requireAll)
 578                                                $test = true;
 579                                              }
 580                                          else
 581                                              {
 582                                              if ($requireAll)
 583                                                $test = false;
 584                                              }
 585                                          break; 
 586                                      case 'after(date)';
 587                                          if ( strtotime($params[$values[0]]) > strtotime($values[2]) )
 588                                              {
 589                                              if (!$requireAll)
 590                                                $test = true;
 591                                              }
 592                                          else
 593                                              {
 594                                              if ($requireAll)
 595                                                $test = false;
 596                                              }
 597                                          break;
 598                                      }
 599                                  }    
 600                              }    
 601                              if ($test)
 602                                $this->files[] = $file['dn'];
 603                          }
 604                      else
 605                          {
 606                          $this->files[] = $file['dn'];
 607                          }
 608                      break;
 609                  default:
 610                      $this->files[] = $file['dn'];
 611                  }
 612              
 613              }
 614  
 615          // handle the limitTypes that require a sort first
 616          if ($filter)
 617              {
 618              if ($this->set['limitType'] == 'dateCount' or $this->set['limitType'] == 'XdateCount')
 619                  {
 620                  FolderViewer::sortFileList('date'); 
 621                  if ($this->set['limitType'] == 'dateCount')
 622                      $this->files = array_splice($this->files, 0, $this->set['limit']);
 623                  else
 624                      array_splice($this->files, 0, $this->set['limit']);
 625                  }
 626                          if ($this->set['limitType'] == 'count' or $this->set['limitType'] == 'Xcount')
 627                                  {
 628                                  FolderViewer::sortFileList($this->set['sortStyle']);
 629                                  if ($this->set['limitType'] == 'count')
 630                                          $this->files = array_splice($this->files, 0, $this->set['limit']);
 631                                  else
 632                                          array_splice($this->files, 0, $this->set['limit']);
 633                                  }
 634              else if ($this->set['limitType'] == 'random')
 635                  {
 636                  if(count($this->files) < $this->set['limit'])
 637                    $this->set['limit'] = count($this->files);
 638                  if($this->set['limit'] > 0)
 639                    {  
 640                      $keys = array_rand($this->files, $this->set['limit']);
 641  
 642                    $newFiles = array();
 643                    if(is_array($keys))
 644                      {
 645                      foreach($keys as $key)
 646                      $newFiles[] = $this->files[$key];
 647                      }
 648                    else
 649                      $newFiles[0] = $this->files[$keys];  
 650  
 651                    $this->files =& $newFiles;
 652                    }
 653                  }
 654              }
 655          }
 656  
 657      /**
 658      * this sorts the $this->files array based on what settings have been applied to the FolderViewer
 659      *
 660      * pre-condition: $this->files must be loaded by loadFileList() before calling this function
 661      *
 662      * @param    string  the sort type that is being used
 663      * @return   none
 664      * @access   public
 665      **/
 666  	function sortFileList($sortOrder)
 667          {
 668          if($sortOrder == "custom")
 669            {
 670            $file_temp = explode(":;:", $this->set['customOrder']);
 671            
 672            for($i = 0; $i < count($file_temp); $i=$i+2)
 673              {
 674              $filearr["mnF=".$file_temp[$i].",".$this->set['folderDN']] = $file_temp[$i+1];
 675              }
 676              
 677            foreach($this->files as $i => $fileDN)
 678                      {
 679                      if(!isset($filearr[$fileDN]))
 680                        $filearr[$fileDN] = count($filearr); 
 681                        
 682                      $newfilearr[$fileDN] = $filearr[$fileDN];
 683                      }
 684                
 685                    $newfilearr = array_flip($newfilearr);
 686                    ksort($newfilearr);
 687                    $this->files = array_values($newfilearr);
 688                    return '';
 689            }
 690            
 691          if ($sortOrder == '')
 692              return;
 693  
 694          // sort the list
 695          $orderKey = array();
 696          foreach($this->files as $i => $fileDN)
 697              {
 698              if ($sortOrder == 'date' or $sortOrder == 'Rdate')
 699                  $orderKey[$i] = strtolower($this->attrs[$fileDN]['createdate']);
 700              if ($sortOrder == 'name' or $sortOrder == 'Rname')
 701                  $orderKey[$i] = strtolower(DN::dnToName($fileDN));    
 702              //$orderKey[$i] = strtolower(@$this->attrs[$fileDN]['title'] ? $this->attrs[$fileDN]['title'] : DN::dnToName($fileDN));
 703              }
 704  
 705          if ($sortOrder == 'date' or $sortOrder == 'name')
 706              arsort($orderKey);
 707          if ($sortOrder == 'Rdate' or $sortOrder == 'Rname')
 708              asort($orderKey);
 709  
 710          $newFiles = array();
 711          foreach(array_keys($orderKey) as $key)
 712              $newFiles[] = $this->files[$key];
 713          $this->files =& $newFiles;
 714          }
 715          
 716      /**
 717      * gets the header data for this application
 718      *
 719      * @return   string  data that goes in the html header
 720      * @access   public
 721      **/
 722      function getHeader()
 723          {
 724          $calendarMode = $this->settingsVars['listType'] == 'calendar' || $this->settingsVars['listTemplate'] == 'calendar~';
 725          $calendarcss = '';
 726          if ($calendarMode)
 727            {
 728            //css class to overwrite the normal ones when viewing a calendar view
 729            $calendarcss .= '<link rel="StyleSheet" href="' . T_WEB_TOOLS . '/css/calendar_viewer.css' . '" type="text/css">' 
 730                  . "<style type='text/css'>
 731                  .calview_weekday{width: 15px; font: ".$this->settingsVars['dayofweekfontsize']."px Arial; color: " . $this->settingsVars['dayofweekcolor']."; text-align: right; background-color: ". $this->settingsVars['dayofweekbgcolor']."; } 
 732                  .calview_cur_month{border:solid 1px #cccccc;width:15px;background-color:".$this->settingsVars['currentmonthweekdaybgcolor'].";font:".$this->settingsVars['currentmonthweekdayfontsize']."px Arial;color:".$this->settingsVars['currentmonthweekdaycolor'].";cursor:pointer;text-align:right;}
 733                  .calview_weekend{border:solid 1px #cccccc;width:15px;background-color:".$this->settingsVars['currentmonthweekendbgcolor'].";font:".$this->settingsVars['currentmonthweekendfontsize']."px Arial;color:".$this->settingsVars['currentmonthweekendcolor'].";cursor:pointer;text-align:right;}
 734                  .calview_not_cur_month{width:15px;background-color: ".$this->settingsVars['noncurrentmonthbgcolor'].";font:".$this->settingsVars['noncurrentmonthfontsize']."px Arial;color:".$this->settingsVars['noncurrentmonthcolor'].";text-align:right;border:solid 1px #cccccc;}
 735                  .calview_cur_date_not_cur_month{font:19px Arial;text-align:right;width:".$this->settingsVars['currentdatenotmonthfontsize']."px;background-color:".$this->settingsVars['currentdatenotmonthbgcolor'].";color:".$this->settingsVars['currentdatenotmonthcolor'].";border:solid 1px transparent;}
 736                  .calview_cur_date{font:".$this->settingsVars['currentdatemonthcolor']."px Arial;text-align:right;width:15px;cursor:pointer;color:".$this->settingsVars['currentdatemonthcolor'].";border:solid 1px #0000ff;background-color:".$this->settingsVars['currentdatemonthbgcolor'].";}
 737                  .calview_background{background-color:".$this->settingsVars['calendarbackground'].";}
 738                  .calview_month{font: ".$this->settingsVars['monthofyearfontsize']."px Arial; color: ".$this->settingsVars['monthofyearcolor']."; text-align: center; border: none; background-color: ".$this->settingsVars['monthofyearbgcolor'].";}
 739                  .calview_cur_month:hover, .weekend:hover, .cur_date:hover, .never:hover, .never_selected:hover, .cal_button:hover{color:".$this->settingsVars['calendarhover'].";border:solid 1px #cccccc;}
 740                  .calview_cal_button{font:bold ".$this->settingsVars['calendarnavsize']."px Arial;color:".$this->settingsVars['calendarnavcolor'].";text-align:center;cursor:pointer;border:solid 1px #000000;background-color:".$this->settingsVars['calendarnavbgcolor'].";}
 741                  .calview_highlight{font:bold ".$this->settingsVars['calendarhighlightfontsize']."px Arial; text-decoration:underline; color: ".$this->settingsVars['calendarhighlightcolor']."; background-color:".$this->settingsVars['calendarhighlightbgcolor'].";}
 742                  </style>";
 743            }
 744          
 745          if($this->mode == 'nonCB' or $this->mode == 'fileNew' or $this->mode == 'fileEdit' or $this->mode == 'fileEditNoRefresh')
 746            {
 747            require_once(T_APP_BASE . 'Editor/Editor.php');
 748            return $calendarcss . App::getAllHeaders('Editor') . App::getAllHeaders('Comments');
 749            }
 750          else if($this->settingsVars['listType'] == 'buttons') 
 751            {
 752            // this has to be done to get the correct style for the buttons
 753            $this->settingsVars['style'] = "vbuttons";
 754            return $calendarcss . Navigator::getHeader() . App::getAllHeaders('Comments');
 755            }
 756          else if ($calendarMode)
 757            {
 758            return $calendarcss;
 759            }
 760  
 761          return App::getAllHeaders('Comments');
 762          }
 763      
 764      /**
 765      * this is here to provide compatability with the editor
 766      *
 767      * @access   public
 768      **/    
 769      function onInit()
 770          {
 771          $this->mode = isset($this->httpVars['mode']) ? $this->httpVars['mode'] : 'normal';
 772          }
 773          
 774      /**
 775      * this is here to provide compatability with the editor and make sure that edit mode is not left after 
 776      * saving a file
 777      *
 778      * @access   public
 779      **/
 780      function onSave()
 781          {
 782          // we dont want to leave edit mode
 783          define('T_DONT_LEAVE_EDIT', 1);
 784          $this->mode = 'nonCB';
 785          require_once(T_APP_BASE . 'Editor/Editor.php');
 786          Editor::onSave();
 787          }    
 788  
 789      /**
 790      * gets a url for an icon based on the given mime type
 791      *
 792      * @param    string  this is the mime type that needs an icon
 793      * @return   string  url for the icon
 794      * @access   public
 795      **/
 796      function getIcon($mime) {
 797          if(strpos($mime, "img") !== false || strpos($mime, "image") !== false) {
 798              $icon = '/icons/picts_16.png';
 799          } else if(strpos($mime, "text") !== false || strpos($mime, "txt")) {
 800              $icon = '/icons/docs_16.png';
 801          } else if(strpos($mime, "flash")) {
 802              $icon = '/icons/flash_16.png';
 803          } else if(strpos($mime, "mpeg")) {
 804              $icon = '/icons/music_16.png';
 805          } else if(strpos($mime, "quicktime")) {
 806              $icon = '/icons/qt_16.png';
 807          } else if(strpos($mime, "wmv")) {
 808              $icon = '/icons/wmv_16.png';
 809          } else if(strpos($mime, "m4a")) {
 810              $icon = '/icons/qt_16.png';
 811          } else if(strpos($mime, "pdf")) {
 812              $icon = '/icons/iconPDF.gif';
 813          } else if(strpos($mime, "msword")) {
 814              $icon = '/icons/iconDOC.gif';
 815          } else if(strpos($mime, 'zip')) {
 816              $icon = '/icons/foldr_16.png';
 817          } else {
 818              $icon = '/icons/docs_16.png';
 819          }
 820          return $icon;  
 821      }
 822  
 823      /**
 824      * 
 825      * This function automatically creates thumbnails for picture files in the folder. It checks if the
 826      * thumbnail exists and if it doesnt then it creates it. The thumbs are stored in My Documents/Temp/Thumbs
 827      * We could eventually have this be part of an app that creates thumbnails, but for now it just auto does it
 828      *
 829      * @param    string   dn of the file that should have its thumbnail url returned
 830      * @return   string   url of the thumbnail, or '' if a thumbnail can not be made
 831      * @access   public
 832      **/ 
 833      function checkGetThumbnail($dn)
 834          {
 835          // return if php is not compiled with gd support
 836          if(!function_exists('imagetypes'))
 837            return '';
 838  
 839          $thumbdn = DN::dnToThumbDn($dn);
 840          
 841          // if the thumbnail already exists then just return it -- otherwise we need to create the thumbnail
 842          if($this->ldap->dnExists($thumbdn))
 843            return DN::dnToUrl($thumbdn);
 844          else
 845            {
 846            // make sure the directory exists for this file
 847            $top = substr($thumbdn, strpos($thumbdn, ',')+1);
 848            $iterator = substr_count($top, ",");
 849            $dir_arr = array();
 850            for($i=0; $i<$iterator; $i++)
 851              {
 852              if(strpos($top, "mnOD") === 0)
 853                $dir_arr[] = $top;
 854   
 855              $top = substr($top, strpos($top, ',')+1);  
 856              }
 857            
 858            // now make sure all these directories exist and if they dont create them
 859            if(count($dir_arr) >= 1)  
 860              {
 861              krsort($dir_arr);
 862              foreach($dir_arr as $dirdn)
 863                { 
 864                if(!$this->ldap->dnExists($dirdn))
 865                  oDirectory::create($this->ldap, $dirdn);
 866                }         
 867              }
 868           }
 869          
 870          // for now just assume gd2, if it would be useful to someone we can figure out how to make this work with gd1     
 871          $gd2 = true; 
 872          $filename = DN::dnToFullFileName($dn);
 873          $thumbfilename = DN::dnToFullFileName($thumbdn);
 874          // Get new dimensions
 875          $img_info = getimagesize($filename);
 876          
 877          $width = 80;
 878          $height = 80;
 879          $width_orig  = $img_info[0];
 880          $height_orig = $img_info[1];
 881  
 882          if($height && ($height_orig < $width_orig))
 883            $height = ($width / $width_orig) * $height_orig;
 884          else
 885            $width = ($height / $height_orig) * $width_orig;
 886          
 887          // open the source image 
 888          if(preg_match("/jpg|jpeg/", $img_info['mime']) && (imagetypes() & IMG_JPG))
 889            $src_img = imagecreatefromjpeg($filename);
 890          else if(preg_match("/png/", $img_info['mime']) && (imagetypes() & IMG_PNG))  
 891            $src_img = imagecreatefrompng($filename);
 892          else if(preg_match("/gif/", $img_info['mime']) && (imagetypes() & IMG_GIF))  
 893            $src_img = imagecreatefromgif($filename);
 894          else if(preg_match("/bmp/", $img_info['mime']) && (imagetypes() & IMG_WBMP))
 895            $src_img = imagecreatefromwbmp($filename);  
 896          else
 897            return '';  
 898          
 899          // create the image in memory
 900          if($gd2 == "")
 901            {
 902            $dst_img = ImageCreate($width, $height);
 903            imagecopyresized($dst_img, $src_img, 0, 0, 0, 0, $width, $height, $width_orig, $height_orig);
 904            }
 905          else
 906            {
 907            $dst_img=ImageCreateTrueColor($width, $height);
 908            imagecopyresampled($dst_img, $src_img, 0, 0, 0, 0, $width, $height, $width_orig, $height_orig);
 909            } 
 910          
 911           if(preg_match("/jpg|jpeg/", $img_info['mime'])) 
 912            imagejpeg($dst_img, T_DOC_BASE . T_ORG_DN . "/" . DN::dnToName($thumbdn));
 913          else if(preg_match("/png/", $img_info['mime']))
 914            imagepng($dst_img, T_DOC_BASE . T_ORG_DN . "/" . DN::dnToName($thumbdn));
 915          else if(preg_match("/gif/", $img_info['mime']))
 916            imagegif($dst_img, T_DOC_BASE . T_ORG_DN . "/" . DN::dnToName($thumbdn));  
 917          else if(preg_match("/bmp/", $img_info['mime']))
 918            imagewbmp($dst_img, T_DOC_BASE . T_ORG_DN . "/" . DN::dnToName($thumbdn));  
 919          
 920          // this if is for the -very rare- condition that this is being done by two parallel processes
 921          if(!$this->ldap->dnExists($thumbdn))
 922            oFile::create($this->ldap, $thumbdn, T_DOC_BASE . T_ORG_DN . "/" . DN::dnToName($thumbdn), $img_info['mime'], array(), 1);
 923          return DN::dnToUrl($thumbdn);
 924          }
 925  
 926      /**
 927      * This function really embodies the core functionality of the FolderViewer. This takes a file from the
 928      * list of files and displays it based on the attributes given. It also can display a single file with all 
 929      * of its given attributes. This function can be called statically if the pre-conditions are met.
 930      *
 931      * pre-conditions: $this->attrs[$dn] is set to the $dns file attributes
 932      *                 $this->set is set to the blocks folderviewer settings(this is only needed for displaying pats of the list, not single files)
 933      *
 934      * @param    string  dn of the file to be displayed
 935      * @return   none
 936      * @access   public
 937      **/
 938      function viewListFile($dn, $attrs, $preview = false, $calendarMode = false)
 939          {
 940          if ($calendarMode)
 941            $calendar = array();
 942  
 943          // get the file's attributes
 944          $fileAttrs =& $this->attrs[$dn];
 945          if (@$fileAttrs['title'])
 946              $title = $fileAttrs['title'];
 947          else
 948              $title = DN::dnToName($dn);
 949          
 950          $link = '<a ';
 951          $mime = FileTypeTable::extensionToType($dn);
 952          if($preview) {
 953              $link = $link2 = '<a href="#" onclick="return false;">';
 954          } else {    
 955              $url = $this->link_to_file_view(DN::dnToName($dn));
 956              if ($this->set['linkTarget'] == '_blank') {
 957                  $link .= "href=\"#\" onclick=\"popup('$url', 'cv_file', 800, 700); return false;\">";
 958              } else {
 959                  if (@$GLOBALS['CV_PUBLISHING'])
 960                      $url = '#';
 961                  $link .= "href=\"$url\">";
 962              }
 963  
 964              // for binary file types, use the link generated above only for displaying comments,
 965              // and create a new link just for downloading the file
 966              if (!FileTypeTable::type_is_embeddable($mime)) {
 967                  $link2 = $link;
 968                  $url = DN::dnToUrl($dn);
 969                  if ($this->set['linkTarget'] == '_blank')
 970                      $link = "<a href=\"#\" onclick=\"popup('$url', 'cv_file', 800, 700); return false;\">";
 971                  else
 972                      $link = "<a href=\"$url\">";
 973              }
 974          }
 975              
 976          $f = '';
 977          $nobr = false;
 978          if (!is_array($attrs) )
 979            $attrs = array($attrs);
 980  
 981          foreach ($attrs as $attr) {
 982              $attr_settings = array();
 983              if(strpos($attr, "[") !== false)
 984                {
 985                $option = substr($attr, strpos($attr, "[") + 1, strlen($attr) - strpos($attr, "[") - 2);
 986                $optionarr = explode("][", $option);
 987                foreach($optionarr as $statement)
 988                  {
 989                  $tmp = explode("=", $statement);
 990                  $attr_settings[$tmp[0]][] = $tmp[1];                
 991                  }
 992                $attr = substr($attr, 0, strpos($attr, "["));
 993                }
 994                
 995              $cssPrefix = isset($this->httpVars['dn']) ? 'cvDoc' : 'cvDir';
 996              if ($this->mode == 'blog')
 997                  $cssPrefix = 'cvBlogPost';
 998                
 999              switch ($attr) {
1000                  case 'title':
1001                      $f .= '<span class="' . $cssPrefix . 'Title">' . $title . '</span>';
1002                      break;
1003                  case 'comments':
1004                      $this->httpVars['dn'] = $dn;
1005                      $this->commentsVars['title'] = $title;
1006                      $f .= '<span class="' . $cssPrefix . 'Comments">'.Comments::getContent('FolderViewer').'</span>';
1007                      unset($this->httpVars['dn']);
1008                      break;
1009                  case 'commentslink':
1010                      $this->httpVars['dn'] = $dn;
1011                      $this->commentsVars['title'] = $title;
1012                      $real_link = isset($link2) ? $link2 : $link;
1013                      $real_link = str_replace("#block_" . $this->blockID . "_a", "#cvcomments_" . $this->blockID, $real_link);
1014                      $real_link = str_replace('<a ', '<a class="' . $cssPrefix . 'Comments" ', $real_link);
1015                      $f .= $real_link . Comments::getContent('FolderViewerMain') . '</a>';
1016                      $f .= '</span>';
1017                      unset($this->httpVars['dn']);
1018                      break;    
1019                  case 'filename':
1020                      $f .= '<span class="' . $cssPrefix . 'Filename">' . DN::dnToName($dn) . '</span>';
1021                      break;
1022                  case 'a':
1023                      if(isset($attr_settings['class'])) {
1024                          if($_REQUEST['fileDN'] == $dn)
1025                              $id = 'id="active"';
1026                          $class_string = 'class="'.implode(" ", $attr_settings['class']).'"';
1027                          if(strpos($class_string, "navButton") !== false)
1028                              $nobr = true; 
1029                          $f .= str_replace("<a ", "<a " . $class_string . " style='border-bottom: solid 1px #000;' $id ", $link);
1030                      } else {
1031                          $f .= $link;
1032                      }
1033                      break;
1034                  case 'aend':
1035                      $f .= '</a>';
1036                      break;
1037                  case 'author':
1038                      if (@$fileAttrs['author'])
1039                          $f .= '<span class="' . $cssPrefix . 'Author">' . $fileAttrs['author'] . '</span>';
1040                      break;  
1041                  case 'description':
1042                      if (@$fileAttrs['description'])
1043                          $f .= '<span class="' . $cssPrefix . 'Description">' . $fileAttrs['description'] . '</span>';
1044                      break;                  
1045                  case 'list': 
1046                      if($this->set['linkTarget'] == '_blank') {
1047                          $f .= '<a href="#" onclick="self.close(); return false;">Return</a>';
1048                      } else {  
1049                          $link = Utility::link(DN::dnToSectionArray($this->ldapDN));
1050                          $f .= '&nbsp;<a href="' . $link . '">Return</a>&nbsp;';
1051                      }
1052                      break;
1053                  case 'prev':
1054                      if(!isset($this->files)) {
1055                          FolderViewer::loadFileList();
1056                          FolderViewer::sortFileList($this->set['sortStyle']);
1057                      }
1058                      $key = array_search($dn, $this->files);
1059                      if(isset($this->files[$key - 1]) && $this->set['linkTarget'] != 'none') {
1060                          $link = $this->link_to_file_view(DN::dnToName($this->files[$key - 1]));
1061                          $f .= '&nbsp;&nbsp;<a href="' . $link . '">Previous</a>&nbsp;&nbsp;';
1062                      }
1063                      break;    
1064                  case 'next':
1065                      if(!isset($this->files)) {
1066                          FolderViewer::loadFileList();
1067                          FolderViewer::sortFileList($this->set['sortStyle']);
1068                      }
1069                      $key = array_search($dn, $this->files);
1070                      if(isset($this->files[$key + 1]) && $this->set['linkTarget'] != 'none') {
1071                          $link = $this->link_to_file_view(DN::dnToName($this->files[$key + 1]));
1072                          $f .= '&nbsp;&nbsp;<a href="' . $link . '">Next</a>&nbsp;&nbsp;';
1073                      }
1074                      break;
1075                  case 'date':
1076                      if (isset($fileAttrs['createdate']))
1077                          $f .= '<span class="' . $cssPrefix . 'Date">' . date('l, F d, Y', $fileAttrs['createdate']) . '</span>';
1078                      break;
1079                  case 'sdate':
1080                      if (isset($fileAttrs['createdate']))
1081                          $f .= '<span class="' . $cssPrefix . 'Date">' . date('M d, Y', $fileAttrs['createdate']) . '</span>';
1082                      break;
1083                  case 'time':
1084                      if (isset($fileAttrs['createdate']))
1085                          $f .= '<span class="' . $cssPrefix . 'Time">' . date('g:i a', $fileAttrs['createdate']) . '</span>';
1086                      break;
1087                  case 'moddate':
1088                      if (isset($fileAttrs['lastmod']))
1089                          $f .= '<span class="' . $cssPrefix . 'Date">' . date('l, F d, Y', $fileAttrs['lastmod']) . '</span>';
1090                      break;
1091                  case 'smoddate':
1092                      if (isset($fileAttrs['lastmod']))
1093                          $f .= '<span class="' . $cssPrefix . 'Date">' . date('M d, Y', $fileAttrs['lastmod']) . '</span>';
1094                      break;
1095                  case 'size':
1096                      $f .= '<span class="' . $cssPrefix . 'Size">' . Utility::human_format_size(filesize(DN::dnToFullFileName($dn))) . '</span>';
1097                      break;
1098                  case 'icon':
1099                      if($attr_settings['align'][0] == "left")
1100                        $iconstyle = "style='float: left;'";
1101                      else if($attr_settings['align'][0] == "right")  
1102                        $iconstyle = "style='float: right;'";
1103                      $icon = FolderViewer::getIcon($mime);
1104                      $f .= "<img $iconstyle border=0 src='/.cWimg/".$icon."'>";
1105                      break;    
1106                  case 'thumb':
1107                      $file = oFile::load($this->ldap, $dn);
1108                      $img = $file->getThumbnail(80);
1109                      $f .= "<img style='border: none;' src='".$img."'>";
1110                      break;        
1111                  case 'contents':
1112                  case 'brief':
1113                      require_once(T_APP_BASE . 'FileViewer/FileViewer.php');
1114                      // make sure file viewer knows not to display a close link, even in single block mode
1115                      $tmp = $this->settingsVars['title'];
1116                                      unset($this->settingsVars['title']);
1117                      if (T_SINGLE_BLOCK) $this->mode = 'FolderEditorPreview';
1118                          $this->fvVars['short'] = $attr == 'brief';
1119                      $f .= '<div class="' . $cssPrefix . 'Contents">' . FileViewer::getHtml($dn) . '</div>';
1120                      if($this->shortened)
1121                          $f .= $link . 'Read more</a>';
1122                        
1123                      $this->settingsVars['title'] = $tmp;
1124                      break;
1125                  case 'br':
1126                      $f .= '<br>';
1127                      break;
1128                  case 'adminlink':
1129                      $file = oFile::load($this->ldap, $dn, false);
1130                      if ($file->perms >= 2) {
1131                          unset($file);
1132                          unset($_SESSION['folderviewerfileedit']);
1133                          $mode = ($this->mode == 'blog' ? 'blog_post' : 'fileEditNoRefresh');
1134                          $filelink = $this->linkToSelf(array('mode' => $mode, 'fileDN' => $dn, 'edit' => 1));
1135                          $filelink = substr($filelink, 0, strpos($filelink, "#"));
1136                          $filelink .= '&_single=' . $this->blockID;
1137                          $f .= "<a href=\"#\" onClick=\"popup('$filelink', 'Editor', 700, 600); return false;\"><img src=\"/.cWimg/icons/edit_16.png\" width=16 height=16 border=0 align=\"absmiddle\" title=\"Edit this file...\">Edit...</a>";
1138                      }
1139                      break;
1140                  case 'categories':
1141                      $f .= '<div class="' . $cssPrefix . 'Categories">in ';
1142                      $keywords = explode(',', $fileAttrs['keywords']);
1143                      $i = 0; $count = count($keywords);
1144                      if (!$count or ($count == 1 and !$keywords[0]))
1145                          $keywords = array('uncategorized');
1146                      foreach($keywords as $category) {
1147                          $c_url = $this->link_to_file_view('&' . $category);
1148                          $c_link = '<a ';
1149                          if ($this->set['linkTarget'] == '_blank' && !$this->dynamic_content) {
1150                              $c_link .= "href=\"#\" onclick=\"popup('$c_url', 'cv_file', 800, 700); return false;\">";
1151                          } else {
1152                              if (@$GLOBALS['CV_PUBLISHING'])
1153                                  $c_url = '#';
1154                              $c_link .= "href=\"$c_url\">";
1155                          }
1156                          $c_link .= $category . '</a>';
1157                          $f .= $c_link . (++$i == $count ? '' : ', ');
1158                      }
1159                      $f .= '</div>';
1160                      break;
1161                  case ' ':
1162                      $f .= '&nbsp;';
1163                      break;
1164                  case 'calendar':
1165  
1166                      break;
1167                  case '': break;
1168                                       
1169                  default: 
1170                      $f .= $attr;
1171              }
1172          }
1173  
1174          if ($calendarMode) {
1175              $obj = $this->ldap->search('(objectclass=*)', array(), $dn, LDAP_SCOPE_BASE);
1176              $attrs = Utility::processParams($obj[0]['mennoattributes']);
1177              $attrs = $attrs[$GLOBALS['CV_CURR_LANG']];
1178              $calendar[date('Y-n-j'  , $attrs['createdate'])][$dn] = $f ;
1179              return $calendar;
1180          }
1181  
1182          return $f . "\n";
1183      }
1184  
1185  
1186  
1187      /**
1188      * All folder settings are set up through this function. This is the wizard that guides users
1189      * through setting up the FolderViewer. It also is where the New Document and Upload File commands are
1190      * passed through
1191      *
1192      * @return   none
1193      * @access   public
1194      **/
1195  	function getConfig()
1196          {
1197          if($this->httpVars['mode'] == 'nonCB')
1198            {
1199            require_once(T_APP_BASE . 'Editor/Editor.php');
1200            unset($this->settingsVars['title']);
1201            unset($this->settingsVars['description']);
1202            $this->mode = 'nonCB';
1203            $this->forceSingle = true;
1204            return Editor::dispatch();
1205            }
1206          else if($this->httpVars['mode'] == 'fileNew')
1207            {
1208            require_once(T_APP_BASE . 'Editor/Editor.php');
1209            unset($this->settingsVars['title']);
1210            unset($this->settingsVars['description']);
1211            $this->mode = 'nonCB';
1212            if($this->settingsVars['fvTemplate'] != '' && $this->ldap->dnExists($this->settingsVars['fvTemplate']))
1213                {
1214                $templatefile = oFile::load($this->ldap, $this->settingsVars['fvTemplate']);
1215                $this->templateText = $templatefile->read();
1216                }
1217            $this->editorVars['defaultFolder'] = substr($this->settingsVars['folderDN'], 0, -strlen(','.T_ORG_DN));
1218            $this->editorVars['defaultExtension'] = 'html';
1219            Editor::onInit();
1220            return Editor::dispatch();
1221            }
1222          else if($this->httpVars['mode'] == 'fileUpload')
1223            {
1224            require_once(T_APP_BASE . 'Uploader/Uploader.php');
1225            unset($this->settingsVars['title']);
1226            unset($this->settingsVars['description']);
1227            $this->linkVars['mode'] = 'fileUpload';
1228            $this->mode = 'nonCB';
1229            $this->uploadVars['defaultFolder'] = substr($this->settingsVars['folderDN'], 0, -strlen(','.T_ORG_DN));
1230            return Uploader::getContent($this->perms);
1231            }
1232          else if($this->httpVars['mode'] == 'fileEdit')
1233            {
1234            require_once(T_APP_BASE . 'Editor/Editor.php');
1235            $_SESSION['folderviewerfileedit'] = $this->ldapDN;
1236            $this->mode = 'nonCB';
1237            $this->forceSingle = true;
1238            unset($this->settingsVars['title']);
1239            unset($this->settingsVars['description']);
1240            return Editor::dispatch();
1241            }
1242          else if($this->httpVars['mode'] == 'fileEditNoRefresh')
1243            {
1244            require_once(T_APP_BASE . 'Editor/Editor.php');
1245            $this->mode = 'nonCB';
1246            unset($this->settingsVars['title']);
1247            unset($this->settingsVars['description']);
1248            return Editor::dispatch();
1249            }   
1250             
1251          if(T_SINGLE_BLOCK && $_SESSION['folderviewerfileedit'] == $this->ldapDN)
1252              {
1253              $this->edit = true;
1254              unset($_SESSION['folderviewerfileedit']);
1255              $this->httpVars['alreadyloaded'] = true;
1256              }
1257          
1258          if(!isset($this->httpVars['page']) && isset($this->httpVars['alreadyloaded']))
1259              $this->httpVars['page'] = 3;
1260          
1261          $tpl = new Template_PHPLIB(T_APP_BASE . 'FolderViewer');
1262          $tpl->setFile(array('main' => 'wizard_base.tpl.html', 'picker' => 'wizard_picker.tpl.html'));
1263          $tpl->setVar('formlook_beginning', Widget::form_look('', '', 'beginning'));
1264          $tpl->setVar('formlook_end', Widget::form_look('', '', 'end'));
1265          $tpl->setBlock('main', 'errorBlock', 'errorB');
1266          $tpl->setBlock('errorB', '');
1267          $tpl->setVar('listType', $this->paramName('listType'));
1268  
1269  		function raiseError(&$tpl, $page, $msg)
1270              {
1271              $tpl->setVar('error', $msg);
1272              $tpl->parse('errorB', 'errorBlock');
1273              return $page;
1274              }
1275          
1276          // load saved settings vars into the user's session if this is the first page loaded
1277          if (!isset($this->httpVars['page']))
1278            {
1279            unset($_SESSION['folderSettings']);
1280            $_SESSION['folderSettings'] =& $this->settingsVars;
1281            if($this->httpVars['mode'] == 'fileViewer')
1282              $this->httpVars['page'] = 1;
1283            else if($this->httpVars['mode'] == 'fileEditList')
1284              $this->httpVars['page'] = 3;  
1285            }
1286  
1287          $curSettings =& $_SESSION['folderSettings'];
1288          $oldPage = isset($this->httpVars['lastPage']) ? $this->httpVars['lastPage'] : -1;
1289          switch($oldPage)
1290              {
1291              case 0:
1292                  if (isset($this->httpVars['folderDN']))
1293                      $curSettings['folderDN'] = $this->httpVars['folderDN'];
1294                  else
1295                      $curPage = raiseError($tpl, 0, 'You must select a folder before continuing.');
1296                  break;
1297              case 1:
1298                  $curSettings['listType'] = array_shift(explode('~',$this->httpVars['listType']));
1299                  $curSettings['listTemplate'] = $this->httpVars['listTemplate'];
1300                  $curSettings['cols'] = $this->httpVars['cols'];
1301                  $curSettings['perpage'] = $this->httpVars['perpage'];
1302                  $curSettings['editlink'] = $this->httpVars['editlink'];
1303                  $curSettings['dategroup'] = $this->httpVars['dategroup'];
1304                  ///calendar appearance settings
1305                  $curSettings['noncurrentmonthfontsize'] = $this->httpVars['noncurrentmonthfontsize'];
1306                  $curSettings['currentmonthweekdaycolor'] = $this->httpVars['currentmonthweekdaycolor'];
1307                  $curSettings['currentmonthweekdaybgcolor'] = $this->httpVars['currentmonthweekdaybgcolor'];
1308                  $curSettings['currentmonthweekdayfontsize'] = $this->httpVars['currentmonthweekdayfontsize'];
1309                  $curSettings['currentmonthweekendcolor'] = $this->httpVars['currentmonthweekendcolor'];
1310                  $curSettings['currentmonthweekendbgcolor'] = $this->httpVars['currentmonthweekendbgcolor'];
1311                  $curSettings['currentmonthweekendfontsize'] = $this->httpVars['currentmonthweekendfontsize'];
1312                  $curSettings['currentdatemonthcolor'] = $this->httpVars['currentdatemonthcolor'];
1313                  $curSettings['currentdatemonthbgcolor'] = $this->httpVars['currentdatemonthbgcolor'];
1314                  $curSettings['currentdatemonthfontsize'] = $this->httpVars['currentdatemonthfontsize'];
1315                  $curSettings['currentdatenotmonthcolor'] = $this->httpVars['currentdatenotmonthcolor'];
1316                  $curSettings['currentdatenotmonthbgcolor'] = $this->httpVars['currentdatenotmonthbgcolor'];
1317                  $curSettings['currentdatenotmonthfontsize'] = $this->httpVars['currentdatenotmonthfontsize'];
1318                  $curSettings['noncurrentmonthcolor'] = $this->httpVars['noncurrentmonthcolor'];
1319                  $curSettings['noncurrentmonthbgcolor'] = $this->httpVars['noncurrentmonthbgcolor'];
1320                  $curSettings['noncurrentmonthfontsize'] = $this->httpVars['noncurrentmonthfontsize'];
1321                  $curSettings['dayofweekcolor'] = $this->httpVars['dayofweekcolor'];
1322                  $curSettings['dayofweekbgcolor'] = $this->httpVars['dayofweekbgcolor'];
1323                  $curSettings['dayofweekfontsize'] = $this->httpVars['dayofweekfontsize'];
1324                  $curSettings['monthofyearcolor'] = $this->httpVars['monthofyearcolor'];
1325                  $curSettings['monthofyearbgcolor'] = $this->httpVars['monthofyearbgcolor'];
1326                  $curSettings['monthofyearfontsize'] = $this->httpVars['monthofyearfontsize'];
1327                  $curSettings['calendarbackground'] = $this->httpVars['calendarbackground'];
1328                  $curSettings['calendarhover'] = $this->httpVars['calendarhover'];
1329                  $curSettings['calendarnavcolor'] = $this->httpVars['calendarnavcolor'];
1330                  $curSettings['calendarnavbgcolor'] = $this->httpVars['calendarnavbgcolor'];
1331                  $curSettings['calendarnavsize'] = $this->httpVars['calendarnavsize'];
1332                  $curSettings['calendarhighlightcolor'] = $this->httpVars['calendarhighlightcolor'];
1333                  $curSettings['calendarhighlightbgcolor'] = $this->httpVars['calendarhighlightbgcolor'];
1334                  $curSettings['calendarhighlightfontsize'] = $this->httpVars['calendarhighlightfontsize'];
1335  
1336                  $curSettings['blogcalendar'] = $this->httpVars['blogcalendar'];
1337                  $curSettings['blogcalendartype'] = $this->httpVars['blogcalendartype'];
1338                  $curSettings['blogcalendarlocation'] = $this->httpVars['blogcalendarlocation'];
1339                  
1340                  if ($curSettings['listType'] == 'random')
1341                      {
1342                      $curSettings['limitType'] = 'random';
1343                      if(!isset($curSettings['limit']))
1344                        $curSettings['limit'] = 1;
1345                      }
1346                  break;
1347              case 2:
1348                  // this is after the first screen of step 1
1349                  if ($this->httpVars['limitType'] != $curSettings['limitType'])
1350                      unset($curSettings['limit']);
1351                  $curSettings['limitType'] = $this->httpVars['limitType'];
1352                  if ($curSettings['limitType'] == '' && $this->httpVars['page'] == 2.5)
1353                      $curPage = 3;
1354                  else if ($curSettings['limitType'] && !@$curSettings['limit'])
1355                      $curPage = 2.5;
1356                  break;
1357              case 2.5:
1358                  // this is after the second screen
1359                  switch($curSettings['limitType'])
1360                      {
1361                      case '':
1362                          // all files; shouldn't get here
1363                          break;
1364                      case 'count':
1365                              $curSettings['limitType'] = 'count';
1366                                                  $curSettings['limit'] = $this->httpVars['count'];
1367                                                  if (!is_numeric($this->httpVars['count']))
1368                                                     $curPage = raiseError($tpl, 2.5, 'Sorry, you did not enter a valid number.');
1369                                                  else
1370                                                     {
1371                                                     if ($curSettings['limit'] == 1 && isset($this->httpVars['next']))
1372                                                        $curPage = 4;
1373                                                     }
1374                              break;
1375                                          case 'Xcount':    
1376                          $curSettings['limitType'] = 'Xcount';
1377                                                  $curSettings['limit'] = $this->httpVars['count'];
1378                                                  if (!is_numeric($this->httpVars['count']))
1379                                                     $curPage = raiseError($tpl, 2.5, 'Sorry, you did not enter a valid number.');
1380                                                  else
1381                                                     {
1382                                                     if ($curSettings['limit'] == 1 && isset($this->httpVars['next']))
1383                                                        $curPage = 4;
1384                                                     }
1385                               break;
1386                      case 'date':
1387                      case 'dateCount':
1388                          if ($this->httpVars['limit'] == 'dateCount')
1389                              {
1390                              $curSettings['limitType'] = 'dateCount';
1391                              $curSettings['limit'] = $this->httpVars['count'];
1392                              if (!is_numeric($this->httpVars['count']))
1393                                  $curPage = raiseError($tpl, 2.5, 'Sorry, you did not enter a valid number.');
1394                              else
1395                                  {
1396                                  if ($curSettings['limit'] == 1 && isset($this->httpVars['next']))
1397                                      $curPage = 4;
1398                                  }
1399                              }
1400                          else
1401                              {
1402                              $curSettings['limitType'] = 'date';
1403                              $curSettings['limit'] = $this->httpVars['date'];
1404                              $date = strtotime($this->httpVars['date']);
1405                              if (!$date or $date === -1)
1406                                  $curPage = raiseError($tpl, 2.5, 'Sorry, you did not enter a valid date.');
1407                              }
1408                          break;
1409                      case 'Xdate':
1410                      case 'XdateCount':
1411                          if ($this->httpVars['limit'] == 'XdateCount')
1412                              {
1413                              $curSettings['limitType'] = 'XdateCount';
1414                              $curSettings['limit'] = $this->httpVars['count'];
1415                              if (!is_numeric($this->httpVars['count']))
1416                                  $curPage = raiseError($tpl, 2.5, 'Sorry, you did not enter a valid number.');
1417                              else
1418                                  {
1419                                  if ($curSettings['limit'] == 1 && isset($this->httpVars['next']))
1420                                      $curPage = 4;
1421                                  }
1422                              }
1423                          else
1424                              {
1425                              $curSettings['limitType'] = 'Xdate';
1426                              $curSettings['limit'] = $this->httpVars['date'];
1427                              $date = strtotime($this->httpVars['date']);
1428                              if (!$date or $date === -1)
1429                                  $curPage = raiseError($tpl, 2.5, 'Sorry, you did not enter a valid date.');
1430                              }
1431                          break;
1432                      case 'metadata':
1433                          $curSettings['metadataRequireAll'] = $this->httpVars['cv_requireAll'];
1434                          break;
1435                      case 'random':
1436                          $curSettings['limit'] = $this->httpVars['count'];
1437                          if (!is_numeric($this->httpVars['count']))
1438                              $curPage = raiseError($tpl, 2.5, 'Sorry, you did not enter a valid number.');
1439                          else
1440                              {
1441                              if (isset($this->httpVars['next']))
1442                                  $curPage = 4;
1443                              }
1444                          break;
1445                      default:
1446                          break;
1447                      }
1448                  break;
1449              case 3:
1450                  $curSettings['sortStyle'] = $this->httpVars['sortStyle'];
1451                  $curSettings['customOrder'] = $this->httpVars['customOrder'];
1452                  $this->folderDN = $curSettings['folderDN'];
1453                  $this->set =& $curSettings;
1454                  FolderViewer::loadFileList(false);
1455                  $curSettings['hidden'] = FolderViewer::createVisibleString($this->httpVars['visible']);
1456                  break;
1457              case 4:
1458                  $curSettings['linkTarget'] = $this->httpVars['linkTarget'] == '_custom' ? $this->httpVars['linkTarget_custom'] : $this->httpVars['linkTarget'];
1459                  $curSettings['fileTemplate'] = $this->httpVars['fileTemplate'];
1460                  break;
1461              case 5:
1462                  $curSettings['anonPosting'] = isset($this->httpVars['anonPosting']) ? $this->httpVars['anonPosting'] : '';;
1463                  $curSettings['arrangeComments'] = isset($this->httpVars['arrangeComments']) ? $this->httpVars['arrangeComments'] : '';
1464                  $curSettings['noRating'] = isset($this->httpVars['noRating']) ? $this->httpVars['noRating'] : '';
1465                  $curSettings['advanced'] = isset($this->httpVars['advanced']) ? $this->httpVars['advanced'] : '';
1466                  $curSettings['reportNotify'] = isset($this->httpVars['reportNotify']) ? $this->httpVars['reportNotify'] : '';
1467                              $curSettings['clipComm'] = isset($this->httpVars['clipComm']) ? $this->httpVars['clipComm'] : '';
1468                              $curSettings['clipLen'] = $this->httpVars['clipLen'];
1469                  $curSettings['FileAttach'] = 'on';
1470                  $curSettings['postingGroups'] = array();
1471                  
1472                  foreach($this->httpVars as $k => $v)
1473                      {
1474                      if(preg_match('/option(.*)/', $k))
1475                          $curSettings['postingGroups'][substr($k, 6)] = "cn=" . substr($k, 6) . ",ou=cvgroups," . DN::dnToOrg($this->ldapDN);
1476                      }
1477  
1478                  break;
1479              case 6:
1480                  $curSettings['title'] = $this->httpVars['title'];
1481                  $curSettings['description'] = $this->httpVars['description'];
1482                  $curSettings['displayTitle'] = $this->httpVars['displayTitle'];
1483                  $curSettings['fvTemplate'] = $this->httpVars['fvTemplate'];
1484                  break;
1485              case 7:
1486                  $curSettings['rssFeedImage'] = $this->httpVars['rssFeedImage'];
1487                  if($this->httpVars['generate'] == 'generate')
1488                      {
1489                      require_once(T_APP_BASE . 'RSS/Channel.php');
1490                      $obj = new Channel;
1491                      $obj->file = DN::folderDnToRSSFile($this->ldapDN);
1492                      $tmpfolder = substr($obj->file, 0, strrpos($obj->file, "/"));
1493                      if (!file_exists($tmpfolder))
1494                          @mkdir($tmpfolder);
1495                      $obj->dn = T_ORG_DN;
1496                      $this->folderDN = $curSettings['folderDN'];
1497                      $this->set =& $_SESSION['folderSettings'];
1498                      FolderViewer::loadFileList();
1499                      
1500                      // now we should be narrowed down to the files that are supposed to be visible
1501                      // but we need to sort them
1502                      if($this->set['limitType'] == 'dateCount' || $this->set['limitType'] == 'XdateCount')
1503                          $this->set['sortStyle'] = 'date';
1504                      FolderViewer::sortFileList($this->set['sortStyle']);
1505  
1506                      $obj->name = $curSettings['title'];
1507                      $obj->description = $curSettings['description'];
1508                      
1509                      $GLOBALS['CV_PUBLISHING'] = true;
1510                      
1511                      if($curSettings['rssFeedImage'] != "")
1512                          $obj->imageURL = T_BASE_LINK . DN::dnToUrl($curSettings['rssFeedImage']);
1513                      
1514                      $articles = array();
1515                      $i = 0;
1516                      foreach ($this->files as $f)
1517                         {
1518                         $ofile = oFile::load($this->ldap, $f);
1519                         $attrs = $ofile->getAttr("");
1520  
1521                         $articles[$i]['title'] = $attrs['title'];
1522                         $articles[$i]['created'] = date('Y-m-j H:i:s', $attrs['createdate']). ".18979-05";
1523                         $articles[$i]['author'] = $attrs['author'];
1524                         
1525                         //$articles[$i]['target'] = T_BASE_LINK . DN::dnToUrl($f);
1526                         //new links
1527                         $url = Utility::link($this->sectionPathArray,
1528                              array($this->paramName('submit') => 'File', $this->paramName('dn') => $f, '_single' => $this->blockID, '_singleNav' => 1, $this->paramName('preview') => $preview ), 0);
1529                         $articles[$i]['target'] = str_replace('&amp;', '&', $url) ;
1530                         
1531                         //if($curSettings['rssDescFrom'] == 'content')
1532                         //    $articles[$i]['info'] = FolderViewer::viewListFile($f, explode('~', $curSettings['listTemplate']), 0);
1533                         $articles[$i]['info'] = $attrs['description'];    
1534                         $i++;
1535                         }
1536  
1537                      $obj->_write($articles);
1538                      $GLOBALS['CV_PUBLISHING'] = false;
1539                      }
1540                  break;
1541              default:
1542                  break;
1543              }
1544              
1545              
1546          // now build the next page...but if there was an error above (which sets $curPage to the error-bearing page)
1547          // then we need to reload the old page instead
1548          if (!isset($curPage))
1549              {
1550              if (isset($this->httpVars['finish']))
1551                  {
1552                  // if the user clicked finish, then take the temporary settings (stored in the user's session)
1553                  // and save them to ldap; then refresh the main window
1554                  
1555                  // TODO here:
1556                  // 1. fill in any required settings from later pages with reasonable defaults (or else have this happen
1557                  //         in the viewer)
1558                  
1559                  // if this block was just "created" and we need to actually add the ldap entry...
1560                  // NB $_SESSION['newFolderCol'] is set in Section::execAdminParams when a new folder is opened
1561                  if (isset($_SESSION['newFolderCol']))
1562                      {
1563                      $res = $this->section->blockAdd($_SESSION['newFolderCol'], 'FolderViewer', array());
1564                      if (mnError::isError($res))
1565                          return new mnError('FolderViewer: Error saving new folder block to LDAP: ' . $res->getMessage());
1566                          
1567                      // turn ourselves into the new block, dn-wise, so that we save to the right place
1568                      $this->ldapDN = $this->section->blocks[$this->section->newBlockID]->ldapDN;
1569                      unset($_SESSION['newFolderCol']);
1570                      }
1571                      
1572                  $this->saveSettings($curSettings);
1573                  return Utility::getCloseRefreshJavascript();
1574                  }
1575              
1576              $curPage = isset($this->httpVars['page']) ? $this->httpVars['page'] : 0;
1577              }
1578          $tpl->setVar('linkToSelf', $this->linkToSelf(array('alreadyloaded' => 'true')));
1579          $folderID = DN::dnToFolderId($curSettings['folderDN']);
1580          $tpl->setVar('folderID', isset($curSettings['folderDN']) ? $folderID : 'Not yet selected.');
1581          $tpl->setVar('lastPage', FormWidget::hidden('lastPage', $curPage));
1582          if ($this->httpVars['page'] == 5)
1583             $pageNum = '5';
1584          else
1585             $pageNum = '';
1586          $tpl->setVar('curPage', FormWidget::hidden('page', $pageNum , array('id' => 'curPage')));
1587          $tpl->setVar('pageNum', floor($curPage) + 1);
1588          $id = $this->paramName('');
1589          if ($curPage == 2.5 && $curSettings['limitType'] == '')
1590            $curPage = 2;
1591          switch ($curPage)
1592              {
1593              case 0:
1594                  // choose folder
1595                  $pageTitle = 'Selecting folder...';
1596                  $help = 'Select the folder you want to view
1597                      in this block.  <br>Then press the Next button.';
1598                  $f = '<div class="wizardHelp" style="background:none;"><img class="wizardImg" src="/.cWimg/icons/foldr_24.png">';
1599                  $f .= str_replace('size="1"', 'size="10"', FormWidget::folderList('folderDN', $curSettings['folderDN']));
1600                  $f .= '</div>';
1601                  break;
1602              case 1:
1603                  // choose list type
1604                  $pageTitle = "Choosing list type...";
1605                  $help = 'What style of file list do you want?';
1606                  $listTypes = array(
1607                      'simple~a~title~aend'
1608                          => '<span style="font-weight: bold;">Basic list</span><div class="in">The simplest list.  File names/titles only, one per line.</div>',
1609                      'buttons~a[class=navButton]~title~aend'
1610                          => '<span style="font-weight: bold;">Navigation buttons</span><div class="in">Similar to the basic list, but recreates a "navigation menu" feel.</div>',
1611                      'contents~a~title~aend~br~&lt;div class=in&gt;~author~, ~sdate~</div>'
1612                          => '<span style="font-weight: bold;">Table of contents</span><div class="in">This list includes file names/titles, authors, and creation dates.</div>',
1613                      'thumbnails~a~thumb~aend'
1614                          => '<span style="font-weight: bold;">Photo album</span><div class="in">Intended for viewing folders containing many images.</div>',
1615                      'download~&lt;div style=&quot;clear: left;&quot;&gt;~icon[align=left]~&nbsp;~a~title~aend~ (~size~)</div>'
1616                          => '<span style="font-weight: bold;">Download list</span><div class="in">Intended for a list of files that will be downloaded.  Includes file size and an icon indicating file type.</div>',
1617                      'dropdown~&lt;option value=&quot;~name~&quot;&gt;title'
1618                          => '<span style="font-weight: bold;">Dropdown list</span><div class="in">A simple list of file names/titles in a dropdown menu.</div>',
1619                      'brief~&lt;H1&gt;~a~title~aend~&lt;/H1&gt;~&lt;i&gt;~Posted By:~ ~author~, ~sdate~&lt;/i&gt;~br~br~brief'
1620                          => '<span style="font-weight: bold;">Blog</span><div class="in">Intended for presenting multiple shortened files along with their author and title.  If you
1621                              wish to have only a preview appear then include &lt;cvmore&gt; as a marker of the cutoff point in the documents. </div>',
1622                      'fullfile~contents'
1623                          => '<span style="font-weight: bold;">Full file</span><div class="in">Displays the full file contents.</div>',
1624                      'calendar~calendar'
1625                          => '<span style="font-weight: bold;">Calendar View:</span><div class="in">Displays a calendar that has links to all files on a given day.</div>',
1626                      'custom'
1627                          => '<span style="font-weight: bold;">Custom list</span>:'
1628                      );
1629                  $f = <<<END
1630  <script type="text/javascript" language="Javascript">
1631  </script>
1632  END;
1633                  if($curSettings['listType'] != "")
1634                      {
1635                      $selected = 'custom';
1636                      foreach(array_keys($listTypes) as $type)
1637                          if (ereg($curSettings['listType'] . '~', $type)) $selected = $type;
1638                      }
1639                  else
1640                      {
1641                      $selected = 'fullfile~contents';
1642                      }        
1643                  
1644                  //hide and show the calendar options and format options depending on the mode
1645                  $f = FormWidget::radio('listType', $listTypes, $selected, 'custom', '', array('onclick' => "fillTemplate(this.value);
1646                  if (this.value == 'calendar~calendar')
1647                      {
1648                      document.getElementById('" .$this->paramName('noncalendardiv') ."').style.display = 'none';
1649                      document.getElementById('" .$this->paramName('calendardiv') . "').style.display = 'block';
1650                      document.getElementById('" .$this->paramName('blogcalendardiv') . "').style.display = 'none';
1651                      }
1652                  else
1653                      {
1654                      document.getElementById('" .$this->paramName('noncalendardiv') ."').style.display = 'block';
1655                      document.getElementById('" .$this->paramName('calendardiv') . "').style.display = 'none';
1656                      document.getElementById('" .$this->paramName('blogcalendardiv') . "').style.display = 'block';
1657                      }
1658                  "));
1659                      
1660                  $f .= '<div style="padding-left: 3em;">';
1661                  //calendar options hiding div
1662                  if ($selected == 'calendar~calendar')
1663                    $f.= "<div style='display:none;' id='".$this->paramName('noncalendardiv')."'>";
1664                  else
1665                    $f.= "<div style='display:block;' id='".$this->paramName('noncalendardiv')."'>";
1666                  
1667                  $f .= '<div class="wizardHelp">
1668                      <img class="wizardImg" src="/.cWimg/icons/sinfo_24.png">
1669                      <b>Creating your custom list:</b>
1670                      <br>The list at right is a template of what will be shown for each file.<br>Use the > button to move
1671                      items from the list of available elements at left.<br>Use the &and; and &or; buttons to re-order
1672                      elements in the list.<br>Double-click on an entry in the Selected Items list to modify it.<br>
1673                      Be careful with custom elements unless you know what you are doing; it is
1674                      possible to make a broken page.
1675                      </div>';
1676                  $listTemplateOpts = array(
1677                      'title'        => 'title',
1678                      'filename'    => 'filename',
1679                      'author'    => 'author',
1680                      'description' => 'description',
1681                      'contents'    => 'file contents',
1682                      'brief'        => 'brief contents',
1683                      'date'        => 'date created',
1684                      'sdate'        => 'date created, short',
1685                      'moddate'    => 'date modified',
1686                      'smoddate'    => 'date modified, short',
1687                      'size'        => 'size',
1688                      'icon'        => 'icon',
1689                      'thumb'        => 'thumbnail',
1690                      'commentslink'  => 'comments',
1691                      'br'        => '[line break]',
1692                      ' '            => '[space]',
1693                      'a'            => '[begin link]',
1694                      'aend'        => '[end link]',
1695                      'calendar'  => '[calendar]',
1696                      'custom'    => '[custom text...]'
1697                      );
1698                  $curTemplate = isset($curSettings['listTemplate']) ? htmlspecialchars($curSettings['listTemplate']) : 'contents';
1699                  $tpl->setVar('hiddenInputName', $this->paramName('listTemplate'));
1700                  $tpl->setVar('setToCustom', 'setToCustom();');
1701                  $tpl->setVar('hiddenInput', FormWidget::hidden('listTemplate', $curTemplate));
1702                  $tpl->setVar('optionListName', $this->paramName('optList'));
1703                  $tpl->setVar('optionList', FormWidget::select('optList', $listTemplateOpts, null, null, 10));
1704                  $tpl->setVar('selectedListName', $this->paramName('selList'));
1705                  $curTemplate = explode('~', $curTemplate);
1706                  $selList = '<select name="' . $this->paramName('selList') . '" size=10 style="width:150px;">';
1707                  foreach($curTemplate as $value)
1708                      {
1709                      if ($value == '')
1710                          continue;
1711                      $text = isset($listTemplateOpts[$value]) ? $listTemplateOpts[$value] : $value;
1712                      $selList .= '<option ondblclick="changeCustom(this);" value="' . $value . '">' . $text . "\n";
1713                      }
1714                  $selList .= '</select>';
1715                  $tpl->setVar('selectedList', $selList);
1716                  $f .= $tpl->subst('picker') . '</div>';
1717  
1718                  $f .= '<p><b>Extra list style options:</b><div class="in">';
1719                  $f .= 'Number of columns: ' . FormWidget::text('cols', isset($curSettings['cols']) ? $curSettings['cols'] : '', 1);
1720                  $f .= '<br>Group by: ' . FormWidget::text('perpage', isset($curSettings['perpage']) ? $curSettings['perpage'] : '', 2);
1721                  $f .= '<br>Add an edit link: ' . FormWidget::checkbox('editlink', isset($curSettings['editlink']) ? $curSettings['editlink'] : '');
1722  
1723  
1724                  if ($selected == 'calendar~calendar')
1725                    $f .= "</div><div style='display:none;' id='".$this->paramName('blogcalendardiv')."'>";
1726                  else
1727                    $f .= "</div><div style='display:block;' id='".$this->paramName('blogcalendardiv')."'>";
1728  
1729                  $f .= '&nbsp;<br />' . FormWidget::checkbox('blogcalendar', $curSettings['blogcalendar'], '') . '<b>Group the folder contents?</b>&nbsp;&nbsp;' ;
1730                  $f .= FormWidget::radio('blogcalendartype', array('month' => 'Month', 'year' => 'Year'), $curSettings['blogcalendartype'], 'custom', '&nbsp;');
1731                  $curSettings['blogcalendarlocation'] = isset($curSettings['blogcalendarlocation']) ? $curSettings['blogcalendarlocation'] : DN::dnToName($this->ldapDN);
1732                  $f .= '<div style="padding-left: 212px;">' . FormWidget::blockList('blogcalendarlocation', DN::dnToParent($this->ldapDN), $curSettings['blogcalendarlocation']) . '</div>';
1733  
1734                  $f .= "</div>";
1735                  
1736                  if ($selected == 'calendar~calendar')
1737                    $f .= "</div><div style='display:block;' id='".$this->paramName('calendardiv')."'>";
1738                  else
1739                    $f .= "</div><div style='display:none;' id='".$this->paramName('calendardiv')."'>";
1740  
1741                  $fontsizes = array();
1742                  for ($i = 8; $i < 51; $i++)
1743                    {
1744                    $fontsizes[$i] = $i;
1745                    }
1746                  //special section for calendar appearance optimization
1747                  $j = FormWidget::init('form.noformtag.tpl.html');
1748                  $j->name('main');
1749                  $j->section('test');
1750                  $j->field('<b>Calendar Appearance Configuration<br>First Column is font color<br>Second column is background color<br>Third column is font size</b>');
1751                  $j->field('<b>Day of Week</b>');
1752                  $j->color( 'dayofweekcolor', isset($curSettings['dayofweekcolor']) ? $curSettings['dayofweekcolor'] : '#ffffff', 'Select a color.' );
1753                  $j->color( 'dayofweekbgcolor', isset($curSettings['dayofweekbgcolor'])? $curSettings['dayofweekbgcolor'] : '#cccccc', 'Select a color.' );
1754                  $j->dropdown( 'dayofweekfontsize', $fontsizes, isset($curSettings['dayofweekfontsize']) ? $curSettings['dayofweekfontsize'] : 19);
1755                  $j->field('<b>Current Month\' weekdays</b>');
1756                  $j->color( 'currentmonthweekdaycolor', isset($curSettings['currentmonthweekdaycolor']) ? $curSettings['currentmonthweekdaycolor'] : '#000000', 'Select a color.' );
1757                  $j->color( 'currentmonthweekdaybgcolor', isset($curSettings['currentmonthweekdaybgcolor']) ? $curSettings['currentmonthweekdaybgcolor'] : '#ffffff', 'Select a color.' );
1758                  $j->dropdown( 'currentmonthweekdayfontsize', $fontsizes, isset($curSettings['currentmonthweekdayfontsize']) ? $curSettings['currentmonthweekdayfontsize']: 19);
1759                  $j->field('<b>Current Month\'s weekends</b>');
1760                  $j->color( 'currentmonthweekendcolor', isset($curSettings['currentmonthweekendcolor']) ? $curSettings['currentmonthweekendcolor'] : '#000000', 'Select a color.' );
1761                  $j->color( 'currentmonthweekendbgcolor', isset($curSettings['currentmonthweekendbgcolor']) ? $curSettings['currentmonthweekendbgcolor'] : '#ffffcc', 'Select a color.' );
1762                  $j->dropdown( 'currentmonthweekendfontsize', $fontsizes, isset($curSettings['currentmonthweekendfontsize']) ? $curSettings['currentmonthweekendfontsize'] : 19);
1763                  $j->field('<b>Current day when current month is selected</b>');
1764                  $j->color( 'currentdatemonthcolor', isset($curSettings['currentdatemonthcolor']) ? $curSettings['currentdatemonthcolor'] : '#0000ff', 'Select a color.' );
1765                  $j->color( 'currentdatemonthbgcolor',  isset($curSettings['currentdatemonthbgcolor']) ? $curSettings['currentdatemonthbgcolor'] : '#ccccff','Select a color.' );
1766                  $j->dropdown( 'currentdatemonthfontsize', $fontsizes, isset($curSettings['currentdatemonthfontsize']) ? $curSettings['currentdatemonthfontsize'] : 19);
1767                  $j->field('<b>Current day when current month is not selected</b>');
1768                  $j->color( 'currentdatenotmonthcolor', isset($curSettings['currentdatenotmonthcolor']) ? $curSettings['currentdatenotmonthcolor'] : '#999999', 'Select a color.' );
1769                  $j->color( 'currentdatenotmonthbgcolor', isset($curSettings['currentdatenotmonthbgcolor']) ? $curSettings['currentdatenotmonthbgcolor'] : '#ccccff', 'Select a color.' );
1770                  $j->dropdown( 'currentdatenotmonthfontsize', $fontsizes, isset($curSettings['currentdatenotmonthfontsize']) ? $curSettings['currentdatenotmonthfontsize'] : 19);
1771                  $j->field('<b>days not in current month</b>');
1772                  $j->color( 'noncurrentmonthcolor', isset($curSettings['noncurrentmonthcolor']) ? $curSettings['noncurrentmonthcolor'] : '#999999', 'Select a color.' );
1773                  $j->color( 'noncurrentmonthbgcolor', isset($curSettings['noncurrentmonthbgcolor']) ? $curSettings['noncurrentmonthbgcolor'] : '#cccccc', 'Select a color.' );
1774                  $j->dropdown( 'noncurrentmonthfontsize', $fontsizes, isset($curSettings['noncurrentmonthfontsize']) ? $curSettings['noncurrentmonthfontsize'] : 19);
1775                  $j->field('<b>Month of Year</b>');
1776                  $j->color( 'monthofyearcolor', isset($curSettings['monthofyearcolor']) ? $curSettings['monthofyearcolor'] : '#000000', 'Select a color.' );
1777                  $j->color( 'monthofyearbgcolor', isset($curSettings['monthofyearbgcolor']) ? $curSettings['monthofyearbgcolor'] : '#cccccc', 'Select a color.' );
1778                  $j->dropdown( 'monthofyearfontsize', $fontsizes, isset($curSettings['monthofyearfontsize']) ? $curSettings['monthofyearfontsize'] : 19);
1779                  $j->field('<b>Dates with Items</b>');
1780                  $j->color( 'calendarhighlightcolor', isset($curSettings['calendarhighlightcolor']) ? $curSettings['calendarhighlightcolor'] : '#000000', 'Select a color.');
1781                  $j->color( 'calendarhighlightbgcolor', isset($curSettings['calendarhighlightbgcolor']) ? $curSettings['calendarhighlightbgcolor'] : '#ffffff', 'Select a color.');
1782                    $j->dropdown( 'calendarhighlightfontsize', $fontsizes, isset($curSettings['calendarhighlightfontsize']) ? $curSettings['calendarhighlightfontsize'] : '19' );
1783                  $j->field('<b>Navigation Buttons</b>');
1784                  $j->color( 'calendarnavcolor', isset($curSettings['calendarnavcolor']) ? $curSettings['calendarnavcolor'] : '#000000', 'Select a color.' );
1785                  $j->color( 'calendarnavbgcolor', isset($curSettings['calendarnavbgcolor']) ? $curSettings['calendarnavbgcolor'] : '#ffffff', 'Select a color.' );
1786                  $j->dropdown( 'calendarnavsize', $fontsizes, isset($curSettings['calendarnavsize']) ? $curSettings['calendarnavsize'] : 19);
1787                  $j->field('<b>Calendar Background</b>');
1788                  $j->color( 'calendarbackground', isset($curSettings['calendarbackground']) ? $curSettings['calendarbackground'] : '#cccccc', 'Select a color.');
1789                  $j->field('<b>Calendar Hover Colors</b>');
1790                  $j->color( 'calendarhover', isset($curSettings['calendarhover']) ? $curSettings['calendarhover'] : '#ff9933', 'Select a color.' );
1791                  $j->field('');
1792                  $j->button('resetToDefault', 'Reset to Default Settings', "
1793                    document.getElementById('".$this->paramName('dayofweekcolor')."').value = '#ffffff';
1794                    document.getElementById('".$this->paramName('dayofweekbgcolor')."').value = '#cccccc';
1795                    document.getElementById('".$this->paramName('dayofweekfontsize')."').value = '19';
1796                    document.getElementById('".$this->paramName('currentmonthweekdaycolor')."').value = '#000000';
1797                    document.getElementById('".$this->paramName('currentmonthweekdaybgcolor')."').value = '#ffffff';
1798                    document.getElementById('".$this->paramName('currentmonthweekdayfontsize')."').value = '19';
1799                    document.getElementById('".$this->paramName('currentmonthweekendcolor')."').value = '#000000';
1800                    document.getElementById('".$this->paramName('currentmonthweekendbgcolor')."').value = '#ffffcc';
1801                    document.getElementById('".$this->paramName('currentmonthweekendfontsize')."').value = '19';
1802                    document.getElementById('".$this->paramName('currentdatemonthcolor')."').value = '#0000ff';
1803                    document.getElementById('".$this->paramName('currentdatemonthbgcolor')."').value = '#ccccff';
1804                    document.getElementById('".$this->paramName('currentdatemonthfontsize')."').value = '19';
1805                    document.getElementById('".$this->paramName('currentdatenotmonthcolor')."').value = '#999999';
1806                    document.getElementById('".$this->paramName('currentdatenotmonthbgcolor')."').value = '#ccccff';
1807                    document.getElementById('".$this->paramName('currentdatenotmonthfontsize')."').value = '19';
1808                    document.getElementById('".$this->paramName('noncurrentmonthcolor')."').value = '#999999';
1809                    document.getElementById('".$this->paramName('noncurrentmonthbgcolor')."').value = '#cccccc';
1810                    document.getElementById('".$this->paramName('noncurrentmonthfontsize')."').value = '19';
1811                    document.getElementById('".$this->paramName('monthofyearcolor')."').value = '#000000';
1812                    document.getElementById('".$this->paramName('monthofyearbgcolor')."').value = '#cccccc';
1813                    document.getElementById('".$this->paramName('monthofyearfontsize')."').value = '19';
1814                    document.getElementById('".$this->paramName('calendarnavcolor')."').value = '#000000';
1815                    document.getElementById('".$this->paramName('calendarnavbgcolor')."').value = '#ffffff';
1816                    document.getElementById('".$this->paramName('calendarnavsize')."').value = '19';
1817                    document.getElementById('".$this->paramName('calendarbackground')."').value = '#cccccc';
1818                    document.getElementById('".$this->paramName('calendarhover')."').value = '#ff9933';
1819                    document.getElementById('".$this->paramName('calendarhighlightcolor')."').value = '#000000';
1820                    document.getElementById('".$this->paramName('calendarhighlightbgcolor')."').value = '#ffffff';
1821                    document.getElementById('".$this->paramName('calendarhighlightfontsize')."').value = '19';
1822                    document.getElementById('curPage').value = '1'; document.main.submit();
1823                    ");
1824                  $f .= $j->get();
1825                  $f .= '</div></div>';
1826                  break;
1827              case 2:
1828                  // choose which files
1829                  $pageTitle = 'Selecting which files to display... (part 1)';
1830                  $help = "You may display all of the files that are located in the $folderID folder, or you may
1831                      choose to display only a few, such as the most recent files, or even a single random file.
1832                      <p>Choose one of the following options. Then press the Next button to clarify details about your choice.</p>";
1833                  $limitType = $curSettings['limitType'];
1834                  $limitTypes = array(
1835                      '' => 'all the files in the folder<br>',
1836                      ($limitType == 'date' ? 'date' : 'dateCount') => 'the most recent files',
1837                      ($limitType == 'Xdate' ? 'Xdate' : 'XdateCount') => 'all except the most recent files<br>',
1838                      'count' => 'the top visible files in the file list',
1839                      'Xcount' => 'all except the top visible files in the file list<br>',
1840                      'random' => 'one or more random files',
1841                      'metadata' => 'files matching metadata criteria'
1842                      );
1843                  $f = FormWidget::radio('limitType', $limitTypes, $curSettings['limitType'], '', '<br>');
1844                  break;
1845              case 2.5:
1846                  // Choose which files, part 2
1847                  $pageTitle = 'Selecting which files to display... (part 2)';
1848                  $prevPage = 2;
1849                  $limitType = $curSettings['limitType'];
1850                  $dateHelp = <<<END
1851    <div class="wizardHelp">
1852     <img class="wizardImg" align="middle" src="/.cWimg/icons/cal_24.png">
1853     <b>Entering dates:</b>
1854     <br>Enter a date in any common format.  Dates can be absolute or relative.  Examples:
1855     <blockquote>12/25/2004
1856     <br>Sept. 30
1857     <br>1 month ago</blockquote>
1858    </div>
1859  END;
1860                  switch ($limitType)
1861                      {
1862                      case '':
1863                          // all files; shouldn't get here
1864                          break;
1865                      case 'date':
1866                      case 'dateCount':
1867                          $help = 'You chose to display <b>the most recent files</b> in this folder.
1868                          <p>How do you want to choose which recent files are shown?</p>';
1869                          $limits = array(
1870                              'dateCount' => 'Show a certain number of the most recent files.
1871                                  <div style="padding-left:3em;">How many? ' . FormWidget::text('count', ($limitType == 'dateCount' ? $curSettings['limit'] : ''), 2, array('onclick' => "document.main.{$id}limit[0].checked = true;")) . '</div><p>',
1872                              'date' => 'Show all files created since a certain date.
1873                                  <div style="padding-left:3em;">Which date? ' . FormWidget::text('date', ($limitType == 'date' ? $curSettings['limit'] : ''), 10, array('onclick' => "document.main.{$id}limit[1].checked = true;")) . "$dateHelp</div>"
1874                              );
1875                          $f = FormWidget::radio('limit', $limits, $limitType, '', '<br>');
1876                          break;
1877                      case 'Xdate':
1878                      case 'metadata':
1879                          $metadata = array('author' => 'Author', 'title' => 'Title', 'description' => 'Description', 'keywords' => 'Keywords', 'caption' => 'Caption', 'filename' =>'Filename', 'createdate' => 'Creation date' );
1880                          $compare = array('='=>'=', 'contains'=>'contains', ' !=' => ' !=', 'does not contain'=>'does not contain', 'before(date)' => 'before(date)', 'after(date)'=> 'after(date)');
1881                          $help = 'You chose to display <b>files matching metadata criteria</b> in this folder.
1882                          <p>Add a criteria by selecting metadata field, comparison function, and entering criteria to be matched.</p>';
1883                          
1884                          if ($this->httpVars['cv_remove_index'] != '')
1885                              {
1886                              unset($curSettings['metadatacriteria'][$this->httpVars['cv_remove_index']] );
1887                              }
1888                          
1889                          if ($this->httpVars['cv_criteria'] != '')
1890                              {
1891                              $vals = array( $this->httpVars['cv_metadata'], $this->httpVars['cv_compare'], $this->httpVars['cv_criteria']);
1892                              $curSettings['metadatacriteria'][] = $vals;
1893                              }
1894                          
1895                          $f = Widget::getWizardHelp('<b>Entering dates:</b>
1896                           <br>When using before(date) and after(date) compare functions, you can enter a date in any common format.  Dates can be absolute or relative.  Examples:
1897                           <blockquote>12/25/2004
1898                           <br>Sept. 30
1899                           <br>1 month ago</blockquote>');
1900                          $f .= FormWidget::dropdown('cv_metadata',$metadata, '', '' ) . FormWidget::dropdown('cv_compare',$compare, '') . FormWidget::text('cv_criteria', '', 30) 
1901                                . FormWidget::hidden('cv_remove_index','',  array('id' => 'cv_hidden_index_remove')  ) 
1902                                . '<br>  <div id="cv_metadata_textarea_div">'
1903                                . FormWidget::checkbox('cv_requireAll', isset($this->httpVars['cv_requireAll']) ? $this->httpVars['cv_requireAll'] : $curSettings['metadataRequireAll'], '') . "Require all criteria to be met?";
1904  
1905                          if(is_array($curSettings['metadatacriteria']))
1906                              {       
1907                              foreach ($curSettings['metadatacriteria'] as $index => $values)
1908                                  {
1909                                  $f .=  '<br>' .  FormWidget::button('cv_delete_criteria', 'Remove Criteria', "document.getElementById('cv_hidden_index_remove').value='" .$index . "'; document.getElementById('curPage').value = '2.5'; document.main.submit();" );
1910                                  $f .=  " '" . $values[0] . "' <i>" . $values[1] . "</i> '" . $values[2] ."'" ;
1911                                  }
1912                              }
1913                                 
1914                          $f .=   '</div>  ';
1915                                 
1916                          $f .=  FormWidget::button('Add', 'Add', "document.getElementById('curPage').value = '2.5'; document.main.submit();");
1917                          break;
1918                      case 'XdateCount':
1919                          $help = 'You chose to display <b>all except the most recent files</b> in this folder.
1920                          <p>How do you want to choose which recent files are excluded?</p>';
1921                          $limits = array(
1922                              'XdateCount' => 'Show all except a certain number of the most recent files.
1923                                  <div style="padding-left:3em;">How many? ' . FormWidget::text('count', ($limitType == 'XdateCount' ? $curSettings['limit'] : ''), 2, array('onclick' => "document.main.{$id}limit[0].checked = true;")) . '</div><p>',
1924                              'Xdate' => 'Show all files created before a certain date.
1925                                  <div style="padding-left:3em;">Which date? ' . FormWidget::text('date', ($limitType == 'Xdate' ? $curSettings['limit'] : ''), 10, array('onclick' => "document.main.{$id}limit[1].checked = true;")) . "$dateHelp</div>"
1926                              );
1927                          $f = FormWidget::radio('limit', $limits, $limitType, '', '<br>');
1928                          break;
1929                      case 'random':
1930                          $help = 'You chose to display <b>random files</b> from this folder.';
1931                          $f = 'How many do you want to display? ';
1932                          $f .= FormWidget::text('count', isset($curSettings['limit']) ? $curSettings['limit'] : 1, 2);
1933                          break;
1934                                          case 'count':
1935                                                  $help = 'You chose to display <b>the top visible files in the list</b> of this folder.';
1936                                                  $f = 'How many do you want to display? ';
1937                                                  $f .= FormWidget::text('count', isset($curSettings['limit']) ? $curSettings['limit'] : 1, 2);
1938                                                  break;    
1939                                          case 'Xcount':
1940                                                  $help = 'You chose to display <b>all except the visible top files in the list</b> of this folder.';
1941                                                  $f = 'How many files should be skipped? ';
1942                                                  $f .= FormWidget::text('count', isset($curSettings['limit']) ? $curSettings['limit'] : 1, 2);
1943                                                  break;                    
1944                      }
1945                  break;
1946              case 3:
1947                  // refine file list
1948                  $pageTitle = 'Editing file list...';
1949                  $help = 'This is a list of the files in this folder.
1950                      <br><span style="font-weight: bold;">Hide a file</span> from being displayed in this block by unchecking its checkbox at left.
1951                      <br><span style="font-weight: bold;">Sort the list</span> by clicking on a column heading, or use the arrow buttons to create a custom order.
1952                      <br>When you are satisfied with the list, click Next.';
1953                  
1954                  $cmdName = $this->paramName('cmd');
1955                  $fileDNName = $this->paramName('fileDN');
1956                                  $switchname = $this->httpVars['cmd'] == 'name' ? "Rname" : "name";
1957                                  $switchdate = $this->httpVars['cmd'] == 'date' ? "Rdate" : "date";
1958                  $f = <<<END
1959  <table cellpadding=2 cellspacing=0 width="100%"><tr>
1960  <td class="tableTitleCell">#</td>
1961  <td class="tableTitleCell">Visible?</td>
1962  <td class="tableTitleCell"><span style="text-decoration: underline; cursor: pointer;"
1963                                   onclick="document.main.$cmdName.value = '$switchname'; document.getElementById('curPage').value = '3'; document.main.submit();" 
1964                                   title="Order by Title/filename">Name</span></td>
1965  <td class="tableTitleCell"><span style="text-decoration: underline; cursor: pointer;"
1966                                   onclick="document.main.$cmdName.value = '$switchdate'; document.getElementById('curPage').value = '3'; document.main.submit();"
1967                                   title="Order by Creation date">Created</span></td>
1968  </tr>
1969  END;
1970                  $this->folderDN = $curSettings['folderDN'];
1971                  $this->set =& $curSettings;
1972  
1973                  FolderViewer::loadFileList(false);
1974                  if(!isset($this->httpVars['visible']) && $this->set['hidden'] != "")
1975                    {
1976                    $this->httpVars['visible'] = FolderViewer::decodeVisibleString($this->set['hidden']);
1977                    }
1978                  else if($this->set['hidden'] != "")
1979                    {
1980                    foreach($this->files as $val)
1981                      {
1982                      if(!isset($this->httpVars['visible'][$val]))
1983                        $this->httpVars['visible'][$val] = "off";
1984                      }
1985                    }  
1986                          
1987                          
1988                          
1989                  if($this->httpVars['cmd'] == "name")
1990                    {
1991                    FolderViewer::sortFileList('name');
1992                    $sStyle = "name";
1993                    $cOrder = $curSettings['customOrder'];
1994                    }
1995                  else if($this->httpVars['cmd'] == "date") 
1996                    {
1997                    FolderViewer::sortFileList('date');
1998                    $sStyle = "date";
1999                    $cOrder = $curSettings['customOrder'];
2000                    }
2001                  else if($this->httpVars['cmd'] == "Rname")
2002                    {
2003                    FolderViewer::sortFileList('Rname');
2004                    $sStyle = "Rname";
2005                    $cOrder = $curSettings['customOrder'];
2006                    }
2007                  else if($this->httpVars['cmd'] == "Rdate")
2008                    {
2009                    FolderViewer::sortFileList('Rdate');
2010                    $sStyle = "Rdate";
2011                    $cOrder = $curSettings['customOrder'];
2012                    }  
2013                  else if($this->httpVars['cmd'] == "")
2014                    {
2015                    FolderViewer::sortFileList($curSettings['sortStyle']);
2016                    $sStyle = $curSettings['sortStyle'];
2017                    $cOrder = $curSettings['customOrder'];
2018                    }
2019                  else
2020                    {
2021                    // if it was already ordered at all then use this order to start with
2022                    if($curSettings['sortStyle'] != "")
2023                      FolderViewer::sortFileList($curSettings['sortStyle']);
2024  
2025                    $file_op = array_flip($this->files);
2026                    
2027                    // process the diferent up/down commands
2028                    if($this->httpVars['cmd'] == "up")
2029                      {
2030                      $temp = $this->files[$file_op[$this->httpVars['fileDN']]-1];
2031                      $this->files[$file_op[$this->httpVars['fileDN']]-1] = $this->httpVars['fileDN'];
2032                      $this->files[$file_op[$this->httpVars['fileDN']]] = $temp;
2033                      }
2034                    else if($this->httpVars['cmd'] == "upup")  
2035                      {
2036                      array_splice($this->files, $file_op[$this->httpVars['fileDN']], 1);
2037                      array_splice($this->files, 0, 0, $this->httpVars['fileDN']);
2038                      }
2039                    else if($this->httpVars['cmd'] == "down")
2040                      {
2041                      $temp = $this->files[$file_op[$this->httpVars['fileDN']]+1];
2042                      $this->files[$file_op[$this->httpVars['fileDN']]+1] = $this->httpVars['fileDN'];
2043                      $this->files[$file_op[$this->httpVars['fileDN']]] = $temp;
2044                      }
2045                    else if($this->httpVars['cmd'] == "downdown")
2046                      {
2047                      array_splice($this->files, $file_op[$this->httpVars['fileDN']], 1);
2048                      array_splice($this->files, count($this->files), 0, $this->httpVars['fileDN']);
2049                      }  
2050  
2051                    // create the final string for the order and then make sure that it will be stored
2052                    $customOrder = FolderViewer::createCustomOrder($this->files);
2053  
2054                    $sStyle = "custom";
2055                    $cOrder = $customOrder;                  
2056                    }  
2057                      
2058                  $n = 1; $count = count($this->files);
2059                  $f .= FormWidget::hidden('sortStyle', $sStyle);
2060                  $f .= FormWidget::hidden('customOrder', $cOrder);
2061                  $f .= FormWidget::hidden('fileDN', '');
2062                  $f .= FormWidget::hidden('cmd', '');
2063                  foreach($this->files as $fileDN)
2064                      {
2065                      $f .= "<tr><td>$n. ";
2066                      if ($n != 1)
2067                          {
2068                          $f .= "<span style='cursor: pointer;'
2069                                       onclick=\"document.main.$cmdName.value = 'upup';
2070                                                 document.getElementById('curPage').value = '3';
2071                                                                         document.main.$fileDNName.value = '$fileDN';
2072                                                                         document.main.submit();\"><img alt='top' title='Move to top.' border=0 src='/.cWimg/toolbar/toolbar_button_upup.jpg'></span>";
2073                                                  $f .= "<span style='cursor: pointer;'
2074                                                               onclick=\"document.main.$cmdName.value = 'up';
2075                                                 document.getElementById('curPage').value = '3';
2076                                                                         document.main.$fileDNName.value = '$fileDN';
2077                                                                         document.main.submit();\"><img alt='top' title='Move up.' border=0 src='/.cWimg/toolbar/toolbar_button_up.jpg'>
2078                                                         </span>";
2079                          }
2080                      if ($n != $count)
2081                          {
2082                                                  $f .= "<span style='cursor: pointer;'
2083                                                               onclick=\"document.main.$cmdName.value = 'downdown';
2084                                                 document.getElementById('curPage').value = '3';
2085                                                                         document.main.$fileDNName.value = '$fileDN';
2086                                                                         document.main.submit();\"><img alt='top' title='Move to bottom.' border=0 src='/.cWimg/toolbar/toolbar_button_downdown.jpg'></span>";
2087                                                  $f .= "<span style='cursor: pointer;'
2088                                                               onclick=\"document.main.$cmdName.value = 'down';
2089                                                 document.getElementById('curPage').value = '3';
2090                                                                         document.main.$fileDNName.value = '$fileDN';
2091                                                                         document.main.submit();\"><img alt='top' title='Move down.' border=0 src='/.cWimg/toolbar/toolbar_button_down.jpg'>
2092                                                         </span>";
2093                          }
2094                      $f .= '</td><td>';
2095                      $visibleName = $this->paramName('visible['.$fileDN.']');
2096                      $f .= '<input type="checkbox" name="'.$visibleName.'" ' . (isset($this->httpVars['visible']) ? (($this->httpVars['visible'][$fileDN] == "off") ? "" : "checked") : "checked") . '>';
2097                      $filelink = $this->linkToSelf(array('mode' => 'fileEdit', 'fileDN' => $fileDN));
2098                      $fullfilelink = "<a href=\"#\" onClick=\"popup('$filelink', 'Editor', 700, 500); return false;\">".DN::dnToName($fileDN);
2099                      $f .= '</td><td>' . $fullfilelink . '</td>';
2100                      $f .= '<td>' . date('M. j, Y', $this->attrs[$fileDN]['createdate']) . '</td>';
2101                      $f .= "</tr>";
2102                      $n++;
2103                      }
2104                  $f .= '</table>';
2105                  break;
2106              case 4:
2107                  // file display style
2108                  $pageTitle = 'Edit file display style...';
2109                  $help = 'You selected a list style which shows links for viewing the files in this folder.
2110                      <br><b>Where do you want files to be displayed when the links are clicked?</b>';
2111                  if($curSettings['linkTarget'] == '' && $curSettings['listType'] == 'download')    
2112                      $curSettings['linkTarget'] == '_direct';
2113                      
2114                  $f = FormWidget::radio('linkTarget', array('_direct' => 'direct to the file'), $curSettings['linkTarget']);    
2115                  $default = $curSettings['linkTarget'] == '_direct';
2116                  $f .= FormWidget::link_target_selector('linkTarget', $curSettings['linkTarget'], $default);
2117                  $f .= '<p><div class="wizardHelp"><img class="wizardImg" src="/.cWimg/icons/sinfo_24.png">
2118                      <b>Please also specify what information you want to see after clicking on a link to a file.</b>
2119                      <p>The list at right is a template of what will be shown for each file.<br>Use the > button to move
2120                      items from the list of available elements at left.<br>Use the &and; and &or; buttons to re-order
2121                      elements in the list.</p>
2122                      </div>';
2123                  $fileTemplateOpts = array(
2124                      'title'        => 'title',
2125                      'filename'    => 'filename',
2126                      'author'    => 'author',
2127                      'description' => 'description',
2128                      'contents'    => 'file contents',
2129                      'date'        => 'date created',
2130                      'sdate'        => 'date created, short',
2131                      'moddate'    => 'date modified',
2132                      'smoddate'    => 'date modified, short',
2133                      'size'        => 'size',
2134                      'comments'  => 'comments',
2135                      'br'        => '[line break]',
2136                      ' '            => '[space]',
2137                      'list'        => '[link to return to list]',
2138                      'prev'        => '[link to previous file]',
2139                      'next'        => '[link to next file]',
2140                      'adminlink' => '[link to editor]',
2141                      'custom'    => '[custom text...]'
2142                      );
2143                  $curTemplate = isset($curSettings['fileTemplate']) ? htmlspecialchars($curSettings['fileTemplate']) : 'title~br~author~br~date~br~br~contents~br~list';
2144                  $tpl->setVar('hiddenInputName', $this->paramName('fileTemplate'));
2145                  $tpl->setVar('hiddenInput', FormWidget::hidden('fileTemplate', $curTemplate));
2146                  $tpl->setVar('optionListName', $this->paramName('optList'));
2147                  $tpl->setVar('optionList', FormWidget::select('optList', $fileTemplateOpts, null, null, 10));
2148                  $tpl->setVar('selectedListName', $this->paramName('selList'));
2149                  $curTemplate = explode('~', $curTemplate);
2150                  $selList = '<select name="' . $this->paramName('selList') . '" size=10 style="width:150px;">';
2151                  foreach($curTemplate as $value)
2152                      {
2153                      if ($value == '')
2154                          continue;
2155                      $text = isset($fileTemplateOpts[$value]) ? $fileTemplateOpts[$value] : $value;
2156                      $selList .= '<option ondblclick="changeCustom(this);" value="' . $value . '">' . $text . "\n";
2157                      }
2158                  $selList .= '</select>';
2159                  $tpl->setVar('selectedList', $selList);
2160                  $f .= $tpl->subst('picker') . '</div>';
2161                  break;
2162              case 5:
2163                  $pageTitle = "Comment Settings";
2164                  $help = 'Comment settings  for each item in folder viewer.';
2165                  $this->settingsVars['anonPosting'] = isset($curSettings['anonPosting']) ? $curSettings['anonPosting'] : $this->settingsVars['anonPosting'];
2166                  $this->settingsVars['arrangeComments'] = isset($curSettings['arrangeComments']) ? $curSettings['arrangeComments'] : $this->settingsVars['arrangeComments'];
2167                  $this->settingsVars['noRating'] = isset($curSettings['noRating']) ? $curSettings['noRating'] : $this->settingsVars['noRating'];
2168                  $this->settingsVars['advanced'] = isset($curSettings['advanced']) ? $curSettings['advanced'] : $this->settingsVars['advanced'];
2169                  $this->settingsVars['reportNotify'] = isset($curSettings['reportNotify']) ? $curSettings['reportNotify'] : $this->settingsVars['reportNotify'];
2170                  $this->settingsVars['FileAttach'] = isset($curSettings['FileAttach']) ? $curSettings['FileAttach'] : $this->settingsVars['FileAttach'];
2171                  $this->settingsVars['clipComm'] = isset($curSettings['clipComm']) ? $curSettings['clipComm'] : $this->settingsVars['clipComm'];
2172                  $this->settingsVars['clipLen'] = isset($curSettings['clipLen']) ? $curSettings['clipLen'] : $this->settingsVars['clipLen'];
2173                  $this->settingsVars['postingGroups'] = isset($curSettings['postingGroups']) ? $curSettings['postingGroups'] : $this->settingsVars['postingGroups'];
2174  
2175                  $f = Comments::getConfig('FolderViewer', $this);
2176                  break;
2177              case 6:
2178                  $pageTitle = "Setting block title and description...";
2179                  $help = "You may give this folder viewer block a title and a description, or you may leave them blank.";
2180                  $f = 'Title: ' . FormWidget::text('title', $curSettings['title'], 25);
2181                  $f .= '<br>Description:<br>' . FormWidget::textarea('description', $curSettings['description']);
2182                  $f .= 'Display title and description? ' . FormWidget::checkbox('displayTitle', isset($curSettings['displayTitle']) ? $curSettings['displayTitle'] : '');
2183                  $f .= '<br />&nbsp;<br />Set a default template for new files created in this folder:' . FormWidget::filePicker('fvTemplate', $curSettings['fvTemplate'], '', 'html', '', 1, '', 1); 
2184                  break;
2185              case 7:
2186                  $rssdir = T_DATA_BASE . T_ORG_DN . '/rss';
2187                  if(!is_dir($rssdir))
2188                      mkdir(T_DATA_BASE . T_ORG_DN . '/rss');
2189                  $pageTitle = "RSS Options...";
2190                  $help = "Here you can manage the rss feed for this Folder Viewer.";
2191                  $f = 'When you are ready to publish your RSS you may ' . FormWidget::button('generateRSS', 'Generate feed', "document.getElementById('curPage').value = 7;document.getElementById('" . $this->paramName('generate') . "').value = 'generate';document.main.submit();");
2192                  $f .= FormWidget::hidden('generate', '', array('id' => $this->paramName('generate')));
2193                  //$f .= '<br /><br />Generate the description from: ' . FormWidget::dropdown('rssDescFrom', array('metadata' => 'Metadata', 'content' => 'FolderViewer Content'), $curSettings['rssDescFrom']);
2194                  $f .= '<br />Choose a picture to be associated with this feed: ' . FormWidget::filePicker('rssFeedImage', $curSettings['rssFeedImage'], '', 'jpg', '', 1, '');
2195                  
2196                  if(file_exists(DN::folderDnToRSSFile($this->ldapDN)))
2197                      $f .= '<br /><br />Link to this <a href="' . str_replace('https://', 'http://', DN::folderDnToRSSUrl($this->ldapDN)) . '">feed</a>';
2198                  else
2199                      $f .= '<br /><br />Please click the generate feed button to create a feed for this Folder Viewer';    
2200  
2201                  break;    
2202              case 8:
2203                  //    $this->set =& $curSettings;
2204                  $pageTitle = "Previewing...";
2205                  $help = "Please review the preview below and make sure that this is the list you expect.  If not,
2206                      you may use the Previous button or the links at the left to correct the settings.";
2207                  $f = $this->getContent(1);
2208                  break;
2209                  
2210              }
2211              $tpl->setVar('pageTitle', $pageTitle);
2212              $tpl->setVar('help', $help);
2213              $tpl->setVar('page', $f);
2214          
2215          // build the page list at left
2216          $tpl->setBlock('main', 'linkBlock', 'linkB');
2217          $tpl->setVar('linkB', '');
2218          $pages = array(
2219              'Select folder',
2220              'Choose list type',
2221              'Choose which files',
2222              'Edit Files - Refine list',
2223              'Set file display style',
2224              'Comments settings',
2225              'Block Options',
2226              'RSS Options',
2227              'Preview'
2228              );
2229          $lastPage = 8;
2230          foreach ($pages as $pageId => $pageName)
2231              {
2232              $tpl->setVar('pageId', $pageId);
2233              $tpl->setVar('pageNumber', $pageId + 1);
2234              $tpl->setVar('pageName', $pageName);
2235              $tpl->setVar('linkClass', $pageId == floor($curPage) ? 'wizardLinkActive' : 'wizardLink');
2236              $tpl->parse('linkB', 'linkBlock', 'true');
2237              }
2238          // build the buttons
2239          $prevPage = $curPage == 3 ? 2 : ceil($curPage) - 1;
2240          $tpl->setVar('prevButton', FormWidget::button('prev', '< Previous', "document.getElementById('curPage').value = $prevPage;document.main.submit();", ($curPage > 0 ? array() : array('disabled'))));
2241          $nextPage = $curPage == 2 ? 2.5 : floor($curPage) + 1;
2242          $tpl->setVar('nextPage', $nextPage);
2243          $tpl->setVar('nextButton', FormWidget::submit('next', 'Next >', ($curPage < $lastPage ? array() : array('disabled'))));
2244          $tpl->setVar('finishButton', FormWidget::submit('finish', 'Finish'));
2245          $tpl->setVar('cancelButton', FormWidget::button('cancel', 'Cancel', 'destroyChild();'));
2246          return $tpl->subst('main');
2247          } // end getConfig
2248      
2249      /**
2250      * creates a custom order string that should be put in LDAP to store the custom order selected for the block  
2251      *
2252      * @param    array   array of files with thier position as the keys
2253      * @return   string  string representing the custom order
2254      * @access   public
2255      **/
2256  	function createCustomOrder($files)
2257        {
2258        if(is_array($files))
2259          {
2260          foreach($files as $key => $val)
2261            {    
2262            $customString .= DN::dnToName($val) . ":;:" . $key . ":;:";            
2263            }
2264          $customString = substr($customString, 0, strlen($customString) - 3);
2265          return $customString;
2266          }
2267        else
2268          return '';  
2269        }
2270  
2271      /**
2272      * creates a string that should be put in LDAP to store the visibility status of files for this block
2273      *
2274      * pre-condition: $this->files must be set and be an array of files in this folder
2275      *
2276      * @param    array   array of files with thier status set to off or on
2277      * @return   string  string representing the visibility status -- use decodeVisibleString() to decode
2278      * @access   public
2279      **/
2280      function createVisibleString($files)
2281        {
2282        if(is_array($this->files))
2283          {
2284          foreach($this->files as $key => $val)
2285            {
2286            $v = $files[$val] == "" ? "off" : $files[$val];
2287            $customString .= DN::dnToName($val) . ":;:" . $v . ":;:";
2288            }
2289          $customString = substr($customString, 0, strlen($customString) - 3);
2290          return $customString;
2291          }
2292        else
2293          return "";  
2294        }
2295  
2296      /**
2297      * returns a hashed array with the dns as keys, the visibility values are either "on" or "off"
2298      *
2299      * @param    string  string representing the visibility status
2300      * @return   array   array of files with thier status set to off or on
2301      * @access   public
2302      **/
2303      function decodeVisibleString($string)
2304        {
2305        $file_temp = explode(":;:", $string);
2306  
2307        for($i = 0; $i < count($file_temp); $i=$i+2)
2308          {
2309          $filearr["mnF=".$file_temp[$i].",".$this->set['folderDN']] = $file_temp[$i+1];
2310          }
2311        return $filearr;  
2312        }    
2313        
2314      function getKeywords()
2315         {
2316            return Utility::getKeywords($this->settingsVars['folderDN']);
2317         }    
2318  
2319  	function copySite(&$ldap, $srcdn, $destdn, &$cbs, $init = 0, $olddn)
2320          {
2321          foreach ($cbs as $cb)
2322              {
2323              $res = $ldap->search('objectclass=*', array('mnappparam'), $cb, LDAP_SCOPE_BASE);
2324              if(mnError::isError($res))
2325                  { return new mnError('FolderViewer::copySite(): ' . $res->getMessage(), __FILE__, __LINE__); }
2326              $param = Utility::processParams($res[0]['mnappparam']);
2327              $param['folderDN'] = str_replace(($olddn ? $olddn : $srcdn), $destdn, $param['folderDN']);
2328              $attrs = array('mnappparam' => Utility::packageParams($param));
2329              $res = $ldap->replace($cb, $attrs);
2330              if(mnError::isError($res))
2331                  { return new mnError('FolderViewer::copySite(): ' . $res->getMessage(), __FILE__, __LINE__); }
2332              }
2333          }
2334          
2335  	function export($ldap, $blockdn, $blockattrs, $mode) {
2336          $mnappparams = Utility::processparams($blockattrs[0]['mnappparam']);
2337  
2338          switch($mode)
2339              {
2340              case 'files':
2341              $folder = $mnappparams['folderDN'];
2342              // fetch the folder contents
2343              $contents = $ldap->search('(|(objectclass=' . C_LDAP_SHORTCUT_OBJECT . ')(objectclass=' . C_LDAP_FILE_OBJECT . '))',
2344                  array('dn'), $folder, LDAP_SCOPE_ONELEVEL);
2345  
2346              if (mnError::isError($contents))
2347                  return new mnAlert('FolderViewer::export: Error loading folder contents: ' . $contents->getMessage());
2348              unset($contents['count']);
2349  
2350              $files = array();
2351  
2352              foreach($contents as $file)
2353                  $files[] = $file['dn'];
2354  
2355              $ret = $files;
2356              break;
2357              case 'sql':
2358              $ret = "";
2359              break;
2360              }
2361  
2362          return $ret;
2363      }
2364      
2365      /**
2366      * create a link to the view of a given file, taking into account
2367      * the current linkTarget setting
2368      *
2369      * Note: The caller must still determine whether to use an <a href=""> [usually]
2370      * or a Javascript popup() [when linkTarget == '_blank'].
2371      *
2372      * @param    string    $filename    name of the file to view (relative to this FV's folderDN)
2373      * @param    array    $link_attrs    extra parameters that should be passed in the URL
2374      * @return    string                the URL to use for linking to the block
2375      */ 
2376      function link_to_file_view($filename, $link_attrs = array()) {
2377          $dynamic_info = array(
2378              'params' => $filename,
2379              'src_block' => DN::dnToName($this->ldapDN),
2380              );
2381          $sectionPathArray = DN::dnToSectionArray($this->ldapDN);
2382          $dynamic_info['dest_block'] = DN::dnToName($this->ldapDN);
2383          $link_attrs['_dynamic'] =& $dynamic_info;
2384          if ($this->set['linkTarget'] == '_self') {
2385              // use defaults
2386          } else if ($this->set['linkTarget'] == '_top') {
2387              $dynamic_info['dest_block'] = 'CA';
2388          } else if ($this->set['linkTarget'] == '_blank') {
2389              $link_attrs['_single'] = $dynamic_info['dest_block'];
2390          } else if ($this->set['linkTarget'] == '_direct') {
2391            return DN::dnToUrl('mnF=' . $filename . ',' . $this->folderDN, true);  
2392          } else {
2393              if (preg_match('/^CB\d+$/', $this->set['linkTarget'])) {
2394                  $dynamic_info['dest_block'] = $this->set['linkTarget'];
2395              } else {
2396                  $dynamic_info['dest_block'] = DN::dnToName($this->set['linkTarget']);
2397                  $dynamic_info['src_page'] = DN::dnToPageID(DN::dnToBase($this->ldapDN));
2398                  $sectionPathArray = DN::dnToSectionArray(DN::dnToBase($this->set['linkTarget']));
2399              }
2400          }
2401          return Utility::link($sectionPathArray, $link_attrs);
2402      }
2403      
2404  } // end class
2405  ?>

title

Description

title

Description

title

Description

title

title

Body