Caravel CMS PHP Cross Reference Content Management Systems

Source: /apps/PageHelp/PageHelp.php - 228 lines - 9548 bytes - Summary - Text - Print

   1  <?php
   2  
   3  require_once(T_APP_BASE . 'Editor/Editor.php');
   4  require_once(T_CODE_BASE . 'mnUtility.php');
   5  
   6  class PageHelp extends App
   7      {
   8      function setDocument($fDN)
   9          {
  10          $this->mode = 'nonCB';
  11          $this->params['fileDN'] = $fDN;
  12          $this->settingsVars['fileDN'] = $fDN;
  13          }
  14      
  15  	function getContent()
  16          {
  17          $res = $this->ldap->search('(objectClass=*)',array('mnparams'),$this->ldapDN, LDAP_SCOPE_BASE);
  18          $params = unserialize($res[0]['mnparams'][0]);
  19          $num = count($params['helpfiles']);
  20          $content .= '<div style="font-size:9px;">';
  21          if ($num == 1)
  22              {
  23              foreach ($params['helpfiles'] as $file)
  24                  {
  25                  if ($this->ldap->dnExists($file))
  26                      {
  27                      PageHelp::setDocument($file);
  28                      $ofile = oFile::Load($this->ldap, $file);
  29                      $content .= '<b>'.$ofile->getAttr('title').'</b><br />';
  30                      $content .= '<div style="display:block;">'.Editor::dispatch().'</div><br /><br />';
  31                      }
  32                  }
  33              return $content .'</div>';
  34              }
  35          if ($num > 0)
  36              {
  37              foreach ($params['helpfiles'] as $key => $file)
  38                  {
  39                  if ($this->ldap->dnExists($file))
  40                      {
  41                      PageHelp::setDocument($file);
  42                      $ofile = oFile::Load($this->ldap, $file);
  43                      if (strpos($ofile->file->mimeType, 'image') !== false)
  44                          {
  45                          $url = DN::dnToUrl($file);
  46                          $popup = "popup('$url','Page Help',640,480); return false;";
  47                          $view = '<img onclick="'. $popup .';return false;" src="'.$ofile->getThumbnail(135).'">';
  48                          }
  49                      else
  50                          $view = Editor::dispatch();
  51                      $title = $ofile->getAttr('title');
  52                      if ($title == '')
  53                          $title = DN::dnToName($file);
  54                      $content .= '<div style="cursor:pointer;" 
  55                                             onclick="var img = document.getElementById(\''.$this->paramName($key).'\');
  56                                                      var content = document.getElementById(\''. $this->paramName($key .'content')  .'\');
  57                                                      var desc = document.getElementById(\''. $this->paramName($key .'desc')  .'\');
  58                                             if (content.style.display == \'block\')
  59                                                 {
  60                                                 img.src = \'/.cWimg/icons/folder_tree_+.gif\';
  61                                                 content.style.display = \'none\';
  62                                                 desc.style.display = \'block\';
  63                                                 }
  64                                             else
  65                                                 {
  66                                                 img.src = \'/.cWimg/icons/folder_tree_-.gif\';
  67                                                 content.style.display = \'block\';
  68                                                 desc.style.display = \'none\'; 
  69                                                 }"
  70                                             ><b><img id=\''. $this->paramName($key) .'\' style="border:1px solid #555555;margin-right:2px;" src="/.cWimg/icons/folder_tree_+.gif"><span style="vertical-align:center;">'. $title .'</span></b><br />';
  71                      $content .= '<div id=\''.$this->paramName($key .'desc').'\'>'.$ofile->getAttr('description').'</div>';
  72                      $content .= '<div id=\''.$this->paramName($key .'content').'\' style="display:none;">'. $view .'</div></div><br />'; 
  73                      } 
  74                  }
  75                  return $content .'</div>';
  76              }
  77          else return '';
  78          } 
  79                  
  80      function onSave($submit = '')
  81          {
  82           if ($this->httpVars['fileDN'] != '')
  83               {
  84               $filename = 'mnF='.$this->httpVars['filename'].'.'.DN::dnToExtension($this->httpVars['fileDN']).','.$this->httpVars['folderDN'];
  85               define('T_DONT_LEAVE_EDIT', 1);
  86               if (!$this->ldap->dnExists($filename))
  87                   {
  88                   $res = $this->ldap->search('(objectClass=*)',array('mnparams'),$this->ldapDN, LDAP_SCOPE_BASE);
  89                   $params = unserialize($res[0]['mnparams'][0]);
  90                   $params['helpfiles'][] = $filename;
  91                   $params['helpfiles'] = array_diff($params['helpfiles'], array($this->httpVars['fileDN']));                 
  92                   $params = serialize($params);
  93                   $res = $this->ldap->replace($this->ldapDN, array('mnparams' => $params));
  94                   }
  95               Editor::onSave();
  96               
  97               }
  98           else
  99                 {
 100                 $res = $this->ldap->search('(objectClass=*)',array('mnparams'),$this->ldapDN, LDAP_SCOPE_BASE);
 101                  $params = unserialize($res[0]['mnparams'][0]);
 102                  $params['helpfiles'] = array_diff(explode(';',$this->httpVars['helpList']), array(''));
 103                  $params = serialize($params);
 104                  $res = $this->ldap->replace($this->ldapDN, array('mnparams' => $params)); 
 105              }
 106          } 
 107  
 108      function getHeader()
 109          {
 110            if($this->params['submit'] == 'editfile' || $this->params['submit'] == 'newfile')
 111            $header = '<script type="text/javascript" language="JavaScript" src="/.cWinc/tinymce/jscripts/tiny_mce/tiny_mce.js"></script>
 112             <script type="text/javascript" language="JavaScript" src="/.cWinc/load_editor.js"></script>';
 113            $header .= '<script>function removeHelpFile(list, hidden)
 114                            {
 115                            var value = hidden.value;
 116                            value = value.replace(list.value+";", "");
 117                            hidden.value = value;
 118                            list.remove(list.selectedIndex);
 119                            self.document.getElementById(\'block__tmpPageHelp__addNewHelp\').value = \'added\';
 120                            self.document.forms[0].submit();
 121                            }
 122  						  function editHelpFile(link, list, block)
 123                            {
 124                            link = link+\'&\'+block+\'=\'+list.value;
 125                            popup(link, \'Help Editor\', 800, 650);
 126                            }</script>';
 127            return $header;
 128          }
 129              
 130      function getConfig()
 131          {
 132          if(str_replace("dc=", "", T_LDAP_DEFAULT_NAME) == DN::dnToName(T_ORG_DN))
 133              {
 134              if(!$this->ldap->dnExists('mnOD=Page Help,mnOD=Caravel Public Folders,' . T_LDAP_BASE))
 135                  $directory = oDirectory::create($this->ldap, 'mnOD=Page Help,mnOD=Caravel Public Folders,' . T_LDAP_BASE);
 136                  
 137              $ondefault = true;    
 138              }
 139          else            
 140              {
 141              if(!$this->ldap->dnExists('mnOD=Page Help,mnOD=My Documents,'.T_ORG_DN))
 142                  $directory = oDirectory::create($this->ldap, 'mnOD=Page Help,mnOD=My Documents,'.T_ORG_DN);
 143              $ondefault = false;    
 144              }
 145                  
 146          if (isset($this->httpVars['addNewHelp']))
 147              {
 148              $res = $this->ldap->search('(objectClass=*)',array('mnparams'),$this->ldapDN, LDAP_SCOPE_BASE);
 149                 $params = unserialize($res[0]['mnparams'][0]);
 150                 $params['helpfiles'] = array_diff(explode(';',$this->httpVars['helpList']), array(''));
 151                 $params = serialize($params);
 152                 $res = $this->ldap->replace($this->ldapDN, array('mnparams' => $params)); 
 153              }
 154          if ($this->httpVars['submit'] == 'editfile' || $this->httpVars['submit'] == 'newfile')
 155              {
 156              $this->mode = 'nonCB';
 157              $this->forceSingle = true;
 158              return Editor::dispatch();
 159              }
 160          $res = $this->ldap->search('(objectClass=*)',array('mnparams'),$this->ldapDN, LDAP_SCOPE_BASE);
 161          $params = unserialize($res[0]['mnparams'][0]);
 162          if (count($params['helpfiles']) > 0)
 163              {
 164              $params['helpfiles'] = array_unique($params['helpfiles']);
 165              $helpFiles = array();
 166              foreach ($params['helpfiles'] as $file)
 167                  {
 168                  if ($this->ldap->dnExists($file))
 169                      {
 170                      $helpFiles[$file] = DN::dnToFileId($file);
 171                      $helpList .= $file .';';
 172                      }
 173                  }
 174              }
 175          
 176          $name = 'selectedFile';
 177          $fieldName = $this->paramName($name);
 178          $f = FormWidget::init();
 179          $f->name('PageHelpSettings');
 180          $f->section();
 181          $f->field('Help Files:');
 182          if (count($helpFiles) > 0)
 183              $f->select($name, $helpFiles, '', '' , count($helpFiles), array('style' => 'width:100%;'));
 184          else
 185              $f->select($name, array(), '', '' , count($helpFiles), array('style' => 'width:100%;'));
 186              
 187          $f->field('');
 188          $f->hidden('helpList', $helpList , array('id' => $this->paramName('helpList')));
 189          $f->hidden('addNewHelp', '' , array('id' => $this->paramName('addNewHelp')));
 190          $helpName = $this->paramName('helpList');
 191          
 192          if($ondefault)
 193              $newLink = $this->linkToSelf(array('submit' => 'newfile', 'folderDn' => 'mnOD=Page Help,mnOD=Caravel Public Folders,' . T_LDAP_BASE), true, true);
 194          else    
 195              $newLink = $this->linkToSelf(array('submit' => 'newfile', 'folderDn' => 'mnOD=Page Help,mnOD=My Documents,'.T_ORG_DN), true, true);
 196          $newLink = "popup('" . $newLink . "', 'Help Editor', 800, 650);";
 197          $f->button('newHelp','New File', '' , array('onclick' => $newLink));
 198          $editLink = $this->linkToSelf(array('submit' => 'editfile'), true, true);
 199  
 200          $this->linkVars['cv_widget'] = 'PageHelpSelector';
 201          $this->linkVars['dest'] = $fieldName;
 202          if($ondefault)
 203              {
 204              $this->linkVars['defaultFolder'] = 'mnOD=Page Help,mnOD=Caravel Public Folders,' . T_LDAP_BASE;
 205              $this->linkVars['defaultExtension'] = 'html';
 206              $this->linkVars['defaultContents'] = 'mnOD=Page Help,mnOD=Caravel Public Folders,' . T_LDAP_BASE;
 207              }
 208          else
 209              {
 210              $this->linkVars['defaultFolder'] = 'mnOD=Page Help,mnOD=My Documents,'.T_ORG_DN;
 211              $this->linkVars['defaultExtension'] = 'html';
 212              $this->linkVars['defaultContents'] = 'mnOD=Page Help,mnOD=My Documents,'.T_ORG_DN;         
 213              }    
 214          $this->linkVars['mode'] = 'filePicker';
 215          $link = $this->linkToSelf(array(), 1, array('select', 1000, 550));
 216          $f->button('addHelp','Add File', $link);
 217          $f->button('removeHelp','Remove File', 'var list=document.getElementById(\''. $fieldName .'\');if (list.selectedIndex != \'-1\'){removeHelpFile(' .$fieldName .', ' .$helpName .');}');
 218          $file = $this->paramName('fileDN');
 219          $f->button('editHelp','Edit File','editHelpFile(\''. $editLink .'\','. $fieldName .',\''. $file .'\');');
 220          $f->html('<br /><br /><br />');
 221          $f->field('');
 222          $f->defaultButtons();
 223          $f->endSection();
 224          return $f->get();
 225          }
 226  
 227      }   
 228  ?>

title

Description

title

Description

title

Description

title

title

Body