Caravel CMS PHP Cross Reference Content Management Systems

Source: /apps/PublicUploader/PublicUploader.php - 151 lines - 8310 bytes - Summary - Text - Print

   1  <?
   2  
   3  class PublicUploader extends App
   4    {
   5    function onSave()
   6      {
   7      foreach($this->settingsVars['possFolderDN'] as $k => $v)
   8          {
   9          $this->settingsVars['possFolderDN'][$k]['folderDN'] = $this->httpVars['list_folderDN' . $k];
  10          $this->settingsVars['possFolderDN'][$k]['label'] = $this->httpVars['list_label' . $k];
  11          }
  12          
  13      $this->settingsVars['multiple'] = $this->httpVars['miltimode'];
  14      $res = $this->saveSettings($this->settingsVars);    
  15      }
  16    
  17    function getContent()
  18      { 
  19      return  PublicUploader::create("preview");
  20      }
  21    function getConfig()
  22      {
  23      return PublicUploader::create("edit");                                 
  24      }  
  25    function create($mode="preview")
  26      {
  27      $tpl = new Template_PHPLIB($this->appBase);
  28      $tpl->setFile(array('main' => 'public_uploader.tpl.html'));
  29      $linktoself = $this->linkToSelf();
  30      $tpl->setVar('linktoself', $linktoself);
  31      $tpl->subst('main');
  32      $tpl->setBlock('main', 'fileBlock', 'fileB');
  33      $tpl->setVar('fileB', '');
  34      $tpl->setVar('form_look_start', Widget::form_look('', '', 'beginning'));
  35      $tpl->setVar('form_look_end', Widget::form_look('', '', 'end'));
  36      $tpl->setVar('folderDN', $this->paramName('folder'));
  37      
  38      if(isset($this->params['set_default']))
  39          {
  40          $this->settingsVars['multiple'] = $this->httpVars['miltimode'];
  41          $this->settingsVars['folderDN'] = $this->httpVars['folderDN'];
  42          $res = $this->saveSettings($this->settingsVars);
  43  
  44          if(mnError::isError($res))
  45              return new mnError('CLASS::FUNCTION(): ' . $res->getMessage(), __FILE__, __LINE__);
  46          }
  47      else if(isset($this->params['add_default']))
  48          {
  49          $this->settingsVars['multiple'] = $this->httpVars['miltimode']; 
  50          $place = count($this->settingsVars['possFolderDN']);
  51          $this->settingsVars['possFolderDN'][$place]['folderDN'] = $this->httpVars['addFolderDN'];
  52          $this->settingsVars['possFolderDN'][$place]['label'] = $this->httpVars['upload_label'];
  53          $res = $this->saveSettings($this->settingsVars);
  54          }
  55  
  56      if($this->httpVars['faction'] == 'remove')
  57          {
  58          array_splice($this->settingsVars['possFolderDN'], $this->httpVars['findex'], 1);
  59          $res = $this->saveSettings($this->settingsVars);
  60          }
  61      if($this->httpVars['faction'] == 'up')
  62          {
  63          $temp = $this->settingsVars['possFolderDN'][$this->httpVars['findex']];     
  64          $this->settingsVars['possFolderDN'][$this->httpVars['findex']] = $this->settingsVars['possFolderDN'][$this->httpVars['findex'] - 1];
  65          $this->settingsVars['possFolderDN'][$this->httpVars['findex'] - 1] = $temp;
  66          $res = $this->saveSettings($this->settingsVars);
  67          } 
  68      if($this->httpVars['faction'] == 'down')
  69          {
  70          $temp = $this->settingsVars['possFolderDN'][$this->httpVars['findex']];
  71          $this->settingsVars['possFolderDN'][$this->httpVars['findex']] = $this->settingsVars['possFolderDN'][$this->httpVars['findex'] + 1];
  72          $this->settingsVars['possFolderDN'][$this->httpVars['findex'] + 1] = $temp;
  73          $res = $this->saveSettings($this->settingsVars);
  74          }
  75         
  76      
  77      if(T_USER && $mode=="edit")
  78          {
  79          $tpl->setVar('button_set_default', FormWidget::submit('set_default', 'Set Destination', array('class' => 'adminButton')));
  80          $tpl->setVar('folderList', '<div id="singleSet" style="display: ' . (($this->settingsVars['multiple'] != '') ? 'none;' : 'block;') . '">' . FormWidget::folderList('folderDN',$this->settingsVars['folderDN'],'-- select folder --'));
  81          $tpl->setVar('script', '');
  82          $extra = "&nbsp;<br />&nbsp;<br /></div>";
  83          $extra .= FormWidget::checkbox('miltimode', $this->settingsVars['multiple'], 'Allow the user to chose the folder from a dropdown.', array('onclick' => 'if(this.checked){ document.getElementById(\'singleSet\').style.display = \'none\'; document.getElementById(\'multipleSet\').style.display = \'block\'; } else{ document.getElementById(\'singleSet\').style.display = \'block\'; document.getElementById(\'multipleSet\').style.display = \'none\';}')) . "<br />" .
  84                    '<div id="multipleSet" style="display: ' . (($this->settingsVars['multiple'] != '') ? 'block;' : 'none;') . '">' .
  85                    FormWidget::folderList('addFolderDN','','-- select folder --') .
  86                    FormWidget::text('upload_label', '', '') .
  87                    FormWidget::hidden('faction', '') . FormWidget::hidden('findex', '') .
  88                    FormWidget::submit('add_default', 'Add Destination', array('class' => 'adminButton')) . "<br />&nbsp;<br />";
  89  
  90          
  91          $total = count($this->settingsVars['possFolderDN']);
  92          $pn = 1;
  93          foreach($this->settingsVars['possFolderDN'] as $k => $v)
  94              {
  95              $extra .= FormWidget::submit('list_remove' . $k, 'X', array('class' => 'adminButton', 'onclick' => 'this.form.' . $this->paramName('faction') . '.value = \'remove\'; this.form.' . $this->paramName('findex') . '.value = \'' . $k . '\';'));
  96              
  97              if($pn !== 1)
  98                  $extra .= '<span style="cursor: pointer; margin: 3px;"><img onclick="document.project_main.' . $this->paramName('faction') . '.value = \'up\'; document.project_main.' . $this->paramName('findex') . '.value = \'' . $k . '\'; document.project_main.submit();" alt="top" title="Move up." border=0 src="/.cWimg/toolbar/toolbar_button_up.jpg"></span>';
  99              else
 100                  $extra .= '<span style="cursor: pointer; margin: 3px;visibility: hidden;"><img alt="top" title="Move up." border=0 src="/.cWimg/toolbar/toolbar_button_up.jpg"></span>';
 101              if($pn !== $total)    
 102                  $extra .= '<span style="cursor: pointer; margin: 3px;"><img onclick="document.project_main.' . $this->paramName('faction') . '.value = \'down\'; document.project_main.' . $this->paramName('findex') . '.value = \'' . $k . '\'; document.project_main.submit();" alt="top" title="Move up." border=0 src="/.cWimg/toolbar/toolbar_button_down.jpg"></span>';
 103              else
 104                  $extra .= '<span style="cursor: pointer; margin: 3px;visibility: hidden;"><img alt="top" title="Move up." border=0 src="/.cWimg/toolbar/toolbar_button_down.jpg"></span>';     
 105              
 106              $extra .= FormWidget::folderList('list_folderDN' . $k, $v['folderDN'], '-- select folder --') .
 107                        FormWidget::text('list_label' . $k, $v['label'], '') . "<br />";
 108              $pn++;          
 109              }
 110  
 111          $extra .= "</div><div style='float:right;margin-top: 10px;'>" . FormWidget::defaultButtons() . "</div>";
 112          $tpl->setVar('extra_opts', $extra);  
 113          }    
 114      else
 115          {
 116          if($this->settingsVars['multiple'] != '')
 117              {
 118              foreach($this->settingsVars['possFolderDN'] as $k => $v)
 119                  $tmpFolder[$v['folderDN']] = $v['label'];
 120  
 121              $extra = FormWidget::dropdown('folderDropdown', $tmpFolder, '');
 122              }
 123  
 124          $tpl->setVar('upload_text', 'Upload File:');
 125          $tpl->setVar('upload_file',  $extra . FormWidget::file('upload_file', ''));
 126  
 127          if($_FILES[$this->paramName('upload_file')]['name'] != "")
 128              {
 129              if(isset($this->httpVars['folderDropdown']) && $this->httpVars['folderDropdown'] != "")
 130                  $uploadDN = "mnF=".$_FILES[$this->paramName('upload_file')]['name'].",".$this->httpVars['folderDropdown'];
 131              else
 132                  $uploadDN = "mnF=".$_FILES[$this->paramName('upload_file')]['name'].",".$this->settingsVars['folderDN'];
 133  
 134              //Delete the existing file if the same file alredy exist 
 135              if ($this->ldap->dnExists($uploadDN))
 136                $this->ldap->delete($uploadDN);
 137            
 138              //uploading file
 139              $upload = oFile::create($this->ldap, $uploadDN, $_FILES[$this->paramName('upload_file')]['tmp_name'], $_FILES[$this->paramName('upload_file')]['type']);
 140              if (mnError::isError($upload))
 141                return new mnError('Error uploading project file: ' . $upload->getMessage(), __FILE__, __LINE__);
 142                
 143              $tpl->setVar('success_msg', 'File successfully uploaded to <span style="font-weight: bold;">' . DN::dnToFolderId(DN::dnToParent($uploadDN)) . '</span><br />&nbsp;<br />');  
 144              }
 145  
 146          $tpl->setVar('button_upload', FormWidget::submit('upload_file', 'Upload'));
 147          }        
 148      return $tpl->subst('main');
 149      }
 150    }
 151  ?>

title

Description

title

Description

title

Description

title

title

Body