Caravel CMS PHP Cross Reference Content Management Systems

Source: /apps/FileExplorer/FileExplorer.php - 469 lines - 23677 bytes - Summary - Text - Print

   1  <?php
   2  /**
   3  *
   4  * @author   mosheeh, reuvenmh Jun 3, 2005
   5  *
   6  **/
   7  require_once (T_BASE . 'core/HTTPRequest.php');
   8  require_once (T_CODE_BASE . 'File/oFile.php');
   9  require_once(T_WIDGET_BASE . 'CaravelNavigator/CaravelNavigator.php');
  10  
  11  class FileExplorer extends App
  12      {
  13      function retrieveInfo()
  14          {
  15          if(!isset($_SESSION))
  16              Session::startSession();
  17          $_SESSION['auth']->loadPrivs();  
  18          if (isset($_REQUEST['select']))
  19              {
  20              $ldap = mnLDAP::create(T_LDAP_URI);
  21              $res = $ldap->bind(T_LDAP_ROOT_UID, T_LDAP_ROOT_PASSWD);
  22              if(mnError::isError($res))
  23                die($res->getMessage());
  24              if($_REQUEST['select'] == 'site')
  25                  {
  26                  $sites = $ldap->search("objectclass=dcObject", array('dc'), T_LDAP_BASE, LDAP_SCOPE_SUBTREE);
  27                  $result = '<select style="width:130px" id="sites_list" name=\'sites\' onChange="getGroups(this.options[this.selectedIndex].value, this.selectedIndex);">';
  28                  $result .= '<option value="..">..</option>';
  29                  
  30                  //comparator for sorting sites
  31                  function cmpSiteDn($a, $b)
  32                      {
  33                      if ($a['dn'] == $b) 
  34                          return 0;
  35  
  36                      return ($a['dn'] < $b['dn'] ) ? -1 : 1;
  37                      }
  38                  
  39                  //put in alphabetical order
  40                  usort($sites, "cmpSiteDn");
  41                  $sites['count'] = array_shift($sites);
  42                  
  43                  for($i = 0; $i < $sites['count']; $i++)
  44                       {
  45                       if ($sites[$i]['dn'] != T_LDAP_BASE)
  46                            {
  47                            $result .= '<option value="'.$sites[$i]['dn'].'">';
  48                            $result .= DN::dnToNameWithParents($sites[$i]['dn']);
  49                            //set the default site....
  50                            $result .= '</option>' ;
  51                            }
  52                       }
  53                  $result .= '</select>';
  54                  }
  55              else
  56                  {
  57                  $result = '<select style="width:130px" id="groups_list" name=\'groups\'>';
  58                  $groups = Security::getSiteGroups($_REQUEST['select'], $ldap);
  59                
  60                  if (count($groups) > 0)
  61                      {
  62                      foreach($groups as $group)
  63                          $result .= '<option value="cn='. $group . ',ou=cvgroups,'. $_REQUEST['select'].'">' . $group . '</option>';
  64                      }
  65                  $result .= '</select>';
  66                  }
  67              return $result;
  68              }         
  69          if (!isset($_REQUEST['element']) && !isset($_REQUEST['search']) && !isset($_REQUEST['update']) && $_REQUEST['q'] != 'dc=Other Sites,'.T_LDAP_BASE && $_REQUEST['q'] != 'mnOD=Public Folders,'.T_LDAP_BASE && DN::dnToType($_REQUEST['q']) != 'dc')
  70              {
  71              $ajax_url = App::httpRequestUrl('FileExplorer');
  72              define(T_ORG_DN, $_REQUEST['odn']);
  73              $dn =  $_REQUEST['q'];
  74               //Display mode for meta data information 
  75              if($_SESSION['meta_data'] != '' || !isset($_SESSION['meta_data']))
  76                  {
  77                  $meta_data_img = '/.cWimg/icons/minus_node.gif';  
  78                  $meta_data_display = 'block';
  79                  }
  80              else
  81                  {
  82                  $meta_data_img = '/.cWimg/icons/plus_node.gif';
  83                  $meta_data_display = 'none';
  84                  }
  85                  
  86              //Display mode for permissions data information
  87              if($_SESSION['permission_data'] != '' || !isset($_SESSION['permission_data']))
  88                  {
  89                  $permission_data_img = '/.cWimg/icons/minus_node.gif';
  90                  $permission_data_display = 'block';
  91                  }
  92              else
  93                  {
  94                  $permission_data_img = '/.cWimg/icons/plus_node.gif';
  95                  $permission_data_display = 'none';
  96                  }
  97                  
  98              //Display mode for preview data information
  99              if($_SESSION['preview_data'] != '' || !isset($_SESSION['preview_data']))
 100                  {
 101                  $preview_data_img = '/.cWimg/icons/minus_node.gif';
 102                  $preview_data_display = 'block';
 103                  }
 104              else
 105                  {
 106                  $preview_data_img = '/.cWimg/icons/plus_node.gif';
 107                  $preview_data_display = 'none';
 108                  }
 109  
 110              $type = DN::dnToType($dn);
 111              $ldap = mnLDAP::create(T_LDAP_URI);
 112              $res = $ldap->bind(T_LDAP_ROOT_UID, T_LDAP_ROOT_PASSWD);
 113              if(mnError::isError($res))
 114                  die($res->getMessage());
 115              if ($type == 'mnF')
 116                  {
 117                  $file = oFile::load($ldap, $dn);
 118                  $thumb = $file->getThumbnail('100');
 119                  $file_data = $file->getAttr('');
 120                  }
 121              else
 122                  {
 123                  $file = oDirectory::load($ldap, $dn);
 124                  $thumb = '';
 125                  }
 126              $search_result = $ldap->search("objectclass=*", array('mennoLinks', 'cvFileGroup', 'cvFileOwner', 'cvFilePriv'), $dn, LDAP_SCOPE_BASE);
 127              $group_string = '';
 128              for ($i=0; $i < $search_result[0]['cvfilegroup']['count'];$i++)
 129                  {
 130                  $group_string .= $search_result[0]['cvfilegroup'][$i].';';
 131                  }
 132              $ownerEdit = '';$groupEdit = '';$privEdit = '';
 133              if ($file->perms >= 2)
 134                  {
 135                  $ownerEdit = '<input class="adminButton" type="button" style="width:30px;" value="edit" onclick="editPerm(\''.DN::dnToName($search_result[0]['cvfileowner'][0]).'\', \'Owner\');">';
 136  
 137                  $url = DN::dnToUrl($dn);
 138  
 139                  $groupEdit = '<input class="adminButton" type="button" style="width:30px;" value="edit" onclick="editPerm(\'' . $group_string . '\', \'Groups\');">'; // . '   doHttpRequest(\'  $url  \', {\'q\': \'' . $dn . '\' ,\'odn\' : \'' . T_ORG_DN . '\' }, \'setInformation\',  0 ); ">';
 140                  
 141                  //httprequest here                                                                                                                                                                              //doHttpRequest('".$url."', { 'q' : '".$$i]['dn']."' , 'odn':'".T_ORG_DN."'}, 'setInformation', 0);})");
 142                  $privEdit  = '<input class="adminButton" type="button" style="width:30px;" value="edit" onclick="editPerm(\''.$search_result[0]['cvfilepriv'][0].'\', \'Privileges\');">';
 143                  $editLink = $_REQUEST['editLink'];
 144                  $editLink = 'popup(\'' . $editLink . '\', \'File Manager Editor\', 800, 650);';
 145                  $editLink = str_replace('&amp;', '&', $editLink);
 146                  $editLink = '<img class="pointer_hand" src="/.cWimg/icons/edit_16.gif" onclick="' .$editLink. '">';
 147                     
 148                  }
 149              $result .= '<tr><td style="height:12px;font-weight:bold;width:10%;">Owner:</td><td><div style="float:left;">'.DN::dnToName($search_result[0]['cvfileowner'][0]).'</div><div style="float:right;">' . $ownerEdit . '</div></td></tr>';             
 150              $result .= '<tr><td style="height:12px;font-weight:bold;width:10%;">Groups:</td><td><div style="float:right;">' . $groupEdit . '</div></td></tr>';                
 151              for ($i=0; $i < $search_result[0]['cvfilegroup']['count'];$i++)
 152                  {
 153                  $pos1 = strpos($search_result[0]['cvfilegroup'][$i], 'dc=')+3;
 154                  $pos2 = strpos($search_result[0]['cvfilegroup'][$i], ',', $pos1);
 155                  $result .= '<tr><td colspan=2 style="padding-left:10px;">'.DN::dnToName($search_result[0]['cvfilegroup'][$i]).'(<span style="color:#C28D91;">'.substr($search_result[0]['cvfilegroup'][$i], $pos1, $pos2-$pos1).'</span>)</td></tr>';                
 156                  }
 157  
 158              $perms = $search_result[0]['cvfilepriv'][0];
 159              $perm_string = 'Owner: <b>' . ($perms[0] == '2' ? 'rw' : ($perms[0] == '1' ? 'r' : '-' ));
 160              $perm_string .= '</b><br />Group: <b>' . ($perms[1] == '2' ? 'rw' : ($perms[1] == '1' ? 'r' : '-'));
 161              $perm_string .= '</b><br />Others: <b>' . ($perms[2] == '2' ? 'rw' : ($perms[2] == '1' ? 'r' : '-')) . '</b>';
 162              $result .= '<tr><td style="height:12px;font-weight:bold;width:10%;">Privileges:</td><td><div style="float:right;">' . $privEdit . '</div></td></tr>'; 
 163              $result .= '<tr><td colspan=2><div style="padding-left:10px;">' . $perm_string . '</div></td><td></td></tr>';
 164  
 165              if (trim($search_result[0]['mennolinks']['count']) != '')
 166                  {
 167                  unset($search_result[0]['mennolinks']['count']);
 168                  $links = Utility::processParams($search_result[0]['mennolinks']);
 169                  $i=0;
 170                  foreach($links as $link)
 171                      {
 172                      if($i == 0)
 173                          {
 174                          $title = 'Linked:';
 175                          $result .= '<tr><td style="height:12px;font-weight:bold;width:10%;">' . $title . '</td><td>&nbsp;</td></tr>';
 176                          }
 177                      else
 178                          {
 179                          $title = '';
 180                          }
 181                      if (trim($link) != '')
 182                          {
 183                          $name = substr($link, strpos($link, 'dc='));
 184                          $name = Widget::format_text(DN::dnToSiteId($name), 26, '');
 185                          $pos = strpos($link, 'mnTB=')+5;
 186                          $cb = substr($link, $pos, strpos($link, ',')-$pos);
 187                          $link = '<a target="_blank" href="http://'.DN::dnToPageUrl($link).'#'.$cb.'">'.$name.'</a>' ;
 188                          }
 189                      $result .= '<tr><td style="height:12px;" colspan=2>'.$link.'</td></tr>';
 190                      $i++;
 191                      }
 192                  }
 193  
 194              
 195  
 196            
 197              if ($type == 'mnF')
 198                  {     
 199                  if ($thumb != '')
 200                      {
 201                      $img_line =  '<tr><td class="greyWBorderSmall" colspan=2><img style="float:left;" id="preview_data_img" src="' . $preview_data_img . '" onclick="open_close(\'preview_data_img\', \'preview_data\');doHttpRequest(\''.$ajax_url.'\', { \'element\' : \'preview_data\'},\'setNothing\',0);">Preview</td></tr>';
 202                      $img_line .= '<tr><td>
 203                                     <div id="preview_data" style="display:' . $preview_data_display . ';">
 204                                       <table style="width:100%;">
 205                                         <tr><td style="text-align:center;height:12px;font-weight:bold;" colspan=2><img src="' . $thumb . '"></td></tr>
 206                                       </table>
 207                                     </div>
 208                                 </td><td></td></tr>';
 209                      }
 210                  else
 211                      $img_line = '';
 212   
 213                  return '<table style="padding-top:2px;width:100%;">
 214                            ' . $img_line . '
 215                            <tr><td class="greyWBorderSmall" colspan=2><div style="float:left;"><img style="float:left;" id=\'meta_data_img\' src="' . $meta_data_img . '" onclick="open_close(\'meta_data_img\', \'meta_data\');doHttpRequest(\''.$ajax_url.'\', { \'element\' : \'meta_data\'},\'setNothing\',0);">Meta Data</div><div style="float:right;padding-top:1px;">' .$editLink. '</div></td></tr>
 216                            <tr><td>
 217                             <div id="meta_data" style="display:' . $meta_data_display . ';">
 218                              <table>
 219                                <tr><td style="height:12px;font-weight:bold;width:10%;">Name: </td><td>'.Widget::format_text(DN::dnToName($dn), 15, '').'</td></tr>                         
 220                                <tr><td style="height:12px;font-weight:bold;width:10%;">Title: </td><td>'.Widget::format_text($file_data['title'], 15, '').'</td></tr>
 221                                <tr><td style="height:12px;font-weight:bold;width:10%;">Author: </td><td>'.Widget::format_text($file_data['author'], 15, '').'</td></tr>
 222                                <tr><td style="height:12px;font-weight:bold;width:10%;">Desc: </td><td>'.Widget::format_text($file_data['description'], 15, '').'</td></tr>
 223                                <tr><td style="height:12px;font-weight:bold;width:10%;">Created: </td><td>'.strftime("%m/%d/%Y",$file_data['createdate']).'</td></tr>
 224                                <tr><td style="height:12px;font-weight:bold;width:10%;">Modified: </td><td>'.strftime("%m/%d/%Y",$file_data['lastmod']).'</td></tr>
 225                              </table>
 226                             </div>
 227                            </td><td></td></tr>
 228                            <tr><td class="greyWBorderSmall" colspan=2><img style="float:left;" id="permission_data_img" src="' . $permission_data_img . '" onclick="open_close(\'permission_data_img\', \'permission_data_edit\');doHttpRequest(\''.$ajax_url.'\', { \'element\' : \'permission_data\'},\'setNothing\',0);">Permissions</td></tr>
 229                            <tr><td>
 230                                 <div id="permission_data_edit" style="display:' . $permission_data_display . ';">
 231                                
 232                                   <table style="width:100%;">
 233                                       ' . $result . '
 234                                   </table>
 235                                
 236                                 </div>
 237                            </td><td></td></tr>
 238                            </table>'; 
 239                  }
 240              else
 241                  {
 242                  $dirFiles = $file->getContents('onlineFile', array('dn'));
 243                  $dirDirs = $file->getContents('onlineDirectory', array('dn'));
 244                  foreach($dirFiles as $k => $v)
 245                      if(substr($v['dn'], 0, 8) == 'mnF=tmp.')
 246                          unset($dirFiles[$k]);
 247                  $num1 = (count($dirFiles));
 248                  $num2 = (count($dirDirs));
 249                  if($_SESSION['folder_data'] != '' || !isset($_SESSION['folder_data']))
 250                      {
 251                      $folder_data_img = '/.cWimg/icons/minus_node.gif';
 252                      $folder_data_display = 'block';
 253                      }
 254                  else
 255                      {
 256                      $folder_data_img = '/.cWimg/icons/plus_node.gif';
 257                      $folder_data_display = 'none';
 258                      }
 259                  unset($dirFiles);
 260                  unset($dirDirs);
 261               
 262                  return '<table style="padding-top:2px;width:100%;">
 263                            <tr><td class="greyWBorderSmall"  colspan=2><img style="float:left;" id="folder_data_img" src="' . $folder_data_img . '" onclick="open_close(\'folder_data_img\', \'folder_data\');doHttpRequest(\''.$ajax_url.'\', { \'element\' : \'folder_data\'},\'setNothing\',0);">'.DN::dnToName($dn).'</td></tr>
 264                            <tr><td colspan=2>
 265                            <div id="folder_data" style="display:' . $folder_data_display . ';">
 266                             <table style="width:100%;">
 267                               <tr><td style="height:12px;font-weight:bold;width:80%;">Files:</td><td>' . $num1 . '</td></tr>
 268                               <tr><td style="height:12px;font-weight:bold;width:80%;">Folders:</td><td>' . $num2 . '</td></tr>
 269                             </table>
 270                            </div>
 271                            </td></tr>
 272                            <tr><td class="greyWBorderSmall" colspan=2><img style="float:left;" id="permission_data_img" src="' . $permission_data_img . '" onclick="open_close(\'permission_data_img\', \'permission_data_edit\');doHttpRequest(\''.$ajax_url.'\', { \'element\' : \'permission_data\'},\'setNothing\',0);">Permissions</td></tr>
 273                            <tr><td>
 274                                 <div id="permission_data_edit" style="display:' . $permission_data_display . ';">
 275                                   <table>
 276                                       ' . $result . '
 277                                   </table>
 278                                 </div>
 279                            </td><td></td></tr>
 280                            </table>';  
 281                  }      
 282              }
 283          else if(isset($_REQUEST['element']))
 284              {
 285              if(!isset($_SESSION[$_REQUEST['element']]))
 286                  $_SESSION[$_REQUEST['element']] = '';
 287              else if ($_SESSION[$_REQUEST['element']] == '')
 288                  $_SESSION[$_REQUEST['element']] = $_REQUEST['element'];
 289              else
 290                  $_SESSION[$_REQUEST['element']] = '';   
 291              return '';
 292              }
 293          else if(isset($_REQUEST['search']))
 294              {
 295              if(T_EXTERNAL_AUTH)
 296                  {
 297                  $search_ldap = mnLDAP::create(T_LDAP_AUTH_URI);
 298                  $search_ldap->bind("", "");
 299                  $search_base = T_LDAP_AUTH_USER_BASE;
 300                  $search_attr = T_LDAP_AUTH_USER_ATTR;
 301                  }
 302              else
 303                  {
 304                  $ldap = mnLDAP::create(T_LDAP_URI);
 305                  $res = $ldap->bind(T_LDAP_ROOT_UID, T_LDAP_ROOT_PASSWD);
 306                  $search_ldap = $ldap;
 307                  $search_base = T_LDAP_USER_BASE;
 308                  $search_attr = T_LDAP_USER_ATTR;
 309                  }
 310              $_REQUEST['search'] = str_replace(" ", "*", $_REQUEST['search']);
 311              $search = "(|(cn=*".$_REQUEST['search']."*)(" . $search_attr . "=*" . $_REQUEST['search'] . "*))";
 312              $res = $search_ldap->search($search, array('uid', 'cn'), $search_base, 2);
 313              if($res['count'] > 24)
 314                  {
 315                  $res['count'] = 24;
 316                  $too_many = true;
 317                  }
 318  
 319              for($i = 0; $i < $res['count']; $i++)
 320                  {
 321                  $search_result[$res[$i]['uid'][0]] = $res[$i]['cn'][0];
 322                  }
 323  
 324              if($too_many)
 325                  $search_result['toomany'] = "There were more than 24 results, please narrow your search.";
 326  
 327  
 328              $result = " <div id='search_popup'>
 329  
 330                <table cellpadding=0 cellspacing=0 style=\"width: 100%; background-color: #ffffff;
 331                                                          border: solid 1px #000000;\">
 332                <tr>
 333                <td colspan=2 style=\"color: #000000; border-bottom: solid 1px #000000;
 334                                   background-color: #EEE;text-align: center;\">
 335                Search results
 336                </td>
 337                </tr> ";
 338              $count = 0;
 339              if ($res['count'] > 0) 
 340                  {
 341                  foreach($search_result as $key => $value)
 342                      {
 343                      if($count%2 != 0)
 344                          $row_color = "background-color: #f2f2f2;";
 345                      else
 346                          $row_color = "background-color: #ffffff;";
 347  
 348                      $result.= "<tr><td align=left style=\"padding: 2px; ".$row_color."\">".$value."";
 349                      if ($key != 'toomany')
 350                          {           
 351                          $result .= "(<span style=\"color: #660099; text-decoration: underline; cursor: pointer;\"
 352                                onclick=\"document.getElementById('searchValue').value='" .$key. "'\">" .$key. "</span>)
 353                                </td></tr>";
 354                          }
 355                      $count++;
 356                      }
 357                  }
 358              if ($count == 0)
 359                  $result .= '<tr><td style="padding: 2px; background-color: #ffffff;">No result</td></tr>';
 360  
 361              $result .=   "</table>
 362                            </div>";
 363  
 364              return $result;
 365              }
 366          else if(isset($_REQUEST['update']))
 367              {
 368              define(T_LDAP_BASE, $_REQUEST['ldap_base']);
 369              $ldap = mnLDAP::create(T_LDAP_URI);
 370              $res = $ldap->bind(T_LDAP_ROOT_UID, T_LDAP_ROOT_PASSWD);
 371              if(mnError::isError($res))
 372                  die($res->getMessage());
 373              if ($_REQUEST['type'] == 'Owner')
 374                  {
 375                  $updating = 'cvFileOwner';
 376                  if(T_EXTERNAL_AUTH)
 377                      $userDN = T_LDAP_AUTH_USER_ATTR.'='.$_REQUEST['update'].','.T_LDAP_AUTH_USER_BASE;
 378                  else
 379                      $userDN = T_LDAP_USER_ATTR.'='.$_REQUEST['update'].','.T_LDAP_USER_BASE;
 380                  }
 381              else if ($_REQUEST['type'] == 'Privileges')
 382                  {
 383                  $updating = 'cvFilePriv';
 384                  $userDN = $_REQUEST['update'];
 385                  $length = strlen($userDN);
 386                  if($length < 3)
 387                      {
 388                      $extra = 3-$length;
 389                      for ($i=0; $i < $extra; $i++)
 390                          {
 391                          $userDN .= '0';
 392                          }
 393                      }
 394                  $userDN = substr($userDN, 0, 3);
 395                  }
 396              else if ($_REQUEST['type'] == 'Groups')
 397                  {
 398                  $updating = 'cvFileGroup';
 399                  if($_REQUEST['update'] != '')
 400                      $userDN = explode(';', trim($_REQUEST['update'], ';'));
 401                  else
 402                      $userDN = '';
 403                  }
 404              $temp_files = explode(T_LDAP_BASE, $_REQUEST['q']);         
 405              $current_folder = '';
 406              for($i=0;$i<count($temp_files);$i++)
 407                  {
 408                  if (trim($temp_files[$i]) == '')
 409                      continue;
 410                  
 411                  $temp_files[$i] = trim($temp_files[$i], ',');
 412                  if (trim($temp_files[$i]) != '')
 413                      $temp_files[$i] = $temp_files[$i].','.T_LDAP_BASE;
 414                  $type = DN::dnToType($temp_files[$i]);
 415  
 416                  if($type == 'mnOD')
 417                      $file = oDirectory::load($ldap, $temp_files[$i]);
 418                  else           
 419                      $file = oFile::load($ldap, $temp_files[$i]);
 420  
 421                  if($_REQUEST['recursive'] == 'true')
 422                      $file->permissionUpdate(array($updating => $userDN), $_REQUEST['recursive']);
 423                  else
 424                      $file->permissionUpdate(array($updating => $userDN));
 425                  }
 426              return '';
 427              }
 428          }
 429  
 430      function getContent()
 431          {
 432          // FILE_SECURITY
 433          if(!$this->can('file')) return "You do not have sufficient privileges to access the File Manager.";
 434  
 435          $this->fmVars['defaultDirectory'] = C_LDAP_BASE_FOLDER .','. T_ORG_DN;
 436          $this->fmVars['hrefArray'] = array('submit' => 'Edit File');
 437          $this->fmVars['fileLinks'] = true;
 438          $this->fmVars['hrefPopup'] = array('editor', T_SECTION_WIDTH, 500);
 439  
 440          return CaravelNavigator::create($this->fmVars['defaultDirectory'], array($this->fmVars['defaultDirectory'] => 1), 0, 1);
 441          }
 442  
 443      function getHeader()
 444          {
 445          return CaravelNavigator::getHeader();
 446          }
 447          
 448  	function onSave()
 449          {
 450          require_once(T_APP_BASE . 'Editor/Editor.php');        
 451          $this->mode = 'nonCB';
 452          Editor::onSave();
 453          $submit = str_replace('&amp;', '&', $this->httpVars['cv_submit']);
 454          
 455          if ( isset($this->httpVars['cv_submit']) && ($submit == 'Save & Preview' or $submit == 'Save & Close'))
 456              {
 457              $url = str_replace('&amp;', '&', $this->linkToSelf(array('navigator_click' => DN::dnToBase($this->httpVars['fileDN']), 'selected_files' => $this->httpVars['fileDN']), 1));
 458              print "This window should automatically close.<script type=\"text/javascript\">window.onload=function() {self.close();}</script>";
 459              exit;
 460              }
 461          else
 462              {
 463              return Editor::getConfig();            
 464              }      
 465          }    
 466  
 467      } // end class
 468      
 469  ?>

title

Description

title

Description

title

Description

title

title

Body