Caravel CMS PHP Cross Reference Content Management Systems

Source: /apps/EmailFeedback/EmailFeedback.php - 1283 lines - 65892 bytes - Summary - Text - Print

   1  <?php
   2  define('T_EMAILER_DEFAULT_FROM', 'nobody@' . T_ROOT_DOMAIN);
   3  define('T_EMAILER_DEFAULT_SUBJECT', '[Caravel E-mail Feedback Form] ');
   4  define('T_EMAILER_MAX_ATTACHMENT_SIZE', 300000); // in bytes
   5  require_once(T_WIDGET_BASE . 'FormBuilderOptionWidget.php');
   6  require_once (T_CODE_BASE . 'File/oFile.php');
   7  require_once(T_APP_BASE . 'Workflow/Workflow.php');
   8  
   9  
  10  /**
  11  * Name:      EmailFeedback.php
  12  * App:       EmailFeedback
  13  * Modified:  6-2006  Jason Yoder
  14  *            Edit Mode is now multi-page based and includes options for specifying exact formatting
  15  *            of emails sent. Additionally, a customizable form and filename allow a user to store
  16  *            a copy of the data on the server to a specified folder location.
  17  *            Users can choose also submit the page to a non-Caravel site
  18  */
  19  
  20  class EmailFeedback extends App
  21      {
  22      var $inputTypes = array('text', 'text area');
  23      function getHeader()
  24          {
  25          if(T_USER == '')
  26              {
  27              return '<script type="text/javascript" language="Javascript1.2" src="/.cWinc/popupDiv.js"></script>';
  28              }        
  29          }
  30  
  31      function onInit()
  32          {
  33          if (!isset($this->settingsVars['fields'])) $this->settingsVars['fields'] = array();
  34          if (!isset($this->settingsVars['showReset'])) $this->settingsVars['showReset'] = 0;
  35          $this->mode = isset($this->httpVars['mode']) ? $this->httpVars['mode'] : '';
  36          }
  37  
  38      function onSave()
  39          {
  40          //
  41          if ($this->mode == '')
  42              {
  43              $maxpage = $this->settingsVars['maxpage'];
  44              //load all settings vars into $this->settingsVarss to be saved and then overwrite
  45              //those https vars that should be set as determined by the previous page
  46              //print Utility::getVal($_SESSION);
  47              //print Utility::getVal($_SESSION[$this->paramName('builderID')]);
  48              switch ( $this->httpVars['cv_prevpage'] )
  49                  {
  50                  case '0': 
  51                      $oldcount = count($this->settingsVars['fields']);
  52                      
  53                      if(!isset($_SESSION[$this->paramName('builderID')]) && isset($this->settingsVars['fields']))
  54                          {
  55                          // this means an error has occured and this cant be saved
  56                          //new mnAlert("An error occured saving your changes.");
  57                          new mnAlert('An error occured saving your changes.');
  58                          $_SESSION[$this->paramName('builderID')] = $this->settingsVars['fields'];
  59                          $this->settingsVars['fields'] = FormBuilderOptionWidget::coreProcessFields('builderID', $this->settingsVars['fields']);
  60                          }
  61                      else    
  62                          $this->settingsVars['fields'] = FormBuilderOptionWidget::coreProcessFields('builderID', $this->settingsVars['fields']);
  63  
  64                      $this->settingsVars['submitToDifferentPage'] = @$this->httpVars['submitToDifferentPage'];
  65                      $this->settingsVars['alternateSite'] = $this->httpVars['alternateSite'];
  66                      $this->settingsVars['noBlockPrefix'] = $this->httpVars['noBlockPrefix'];
  67                      $this->settingsVars['cvcustomjs'] = $this->httpVars['cvcustomjs'];
  68                  break;
  69                  case '1':
  70                      $oldcount = count($this->settingsVars['fields']);
  71                      if(!isset($_SESSION[$this->paramName('builderID')]) && isset($this->settingsVars['fields']))
  72                          {
  73                          // this means an error has occured and this cant be saved
  74                          new mnAlert("An error occured saving your changes.");
  75                          $_SESSION[$this->paramName('builderID')] = $this->settingsVars['fields'];
  76                          $this->settingsVars['fields'] = FormBuilderOptionWidget::coreProcessFields('builderID', $this->settingsVars['fields']);
  77                          }
  78                      else
  79                          $this->settingsVars['fields'] = FormBuilderOptionWidget::coreProcessFields('builderID', $this->settingsVars['fields']);
  80                  break;
  81                  case '2':
  82                      $this->settingsVars['emailAddress'] = @$this->httpVars['emailAddress'];
  83                      $this->settingsVars['emailSubject'] = @$this->httpVars['emailSubject'];
  84                      $this->settingsVars['emailFrom'] = @$this->httpVars['emailFrom'];
  85                      $this->settingsVars['getEmailFromField'] = @$this->httpVars['getEmailFromField'];
  86                      $this->settingsVars['emailFromField'] = @$this->httpVars['emailFromField'];
  87                      $this->settingsVars['emailFormat'] = $this->httpVars['cv_emailFormat'] ;
  88                  break;
  89                  case '3':
  90                      $this->settingsVars['saveMetadata'] = $this->httpVars['saveMetadata'] ;
  91                      $this->settingsVars['saveFilename'] = $this->httpVars['cv_saveFilename'] ;
  92                      $this->settingsVars['saveFormat'] = $this->httpVars['cv_saveFormat'] ;
  93                      $this->settingsVars['saveToFile'] = isset($this->httpVars['saveToFile']) ? 1 : 0;
  94                      $this->settingsVars['saveToFileDirectory'] = @$this->httpVars['saveToFileDirectory'];
  95                      
  96                      $this->settingsVars['savemetatitle'] = $this->httpVars['cv_title'];
  97                      $this->settingsVars['savemetaauthor'] = $this->httpVars['cv_author'];
  98                      $this->settingsVars['savemetadesc'] = $this->httpVars['cv_desc'];
  99                      $this->settingsVars['savemetakeywords'] = $this->httpVars['cv_keywords'];
 100                      $this->settingsVars['metadate'] = $this->httpVars['metadate'];
 101                      $this->settingsVars['metadatedrop'] = $this->httpVars['metadatedrop'];
 102                      $this->settingsVars['literalKeywords'] = $this->httpVars['literalKeywords'];
 103                  break;
 104                    case '4':
 105                        $this->settingsVars['workflowApprover'] = $this->httpVars['workflowApprover'];
 106                      $this->settingsVars['workflowApproverQuery'] = $this->httpVars['workflowApproverQuery'];
 107                      $this->settingsVars['saveToWorkflow'] = isset($this->httpVars['saveToWorkflow']) ? 1 : 0;
 108                      $this->settingsVars['workflowQueryWait'] = isset($this->httpVars['workflowQueryWait']) ? 1 : 0;
 109                      if($this->settingsVars['saveToWorkflow'] == 1 && $this->settingsVars['workflowID'] == "") 
 110                          {
 111                           $charset = "abcdefghijklmnopqrstuvwxyz";
 112                           $charset .= "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
 113                           $charset .= "0123456789";
 114                           $length = 10;
 115                           $kee = "";
 116                           for ($i=0; $i<$length; $i++)
 117                               $kee .= $charset[(mt_rand(0,(strlen($charset)-1)))];
 118                           $this->settingsVars['workflowID'] = $kee;
 119                          }
 120                    break;
 121                  case '5':
 122                      $this->settingsVars['showReset']    = isset($this->httpVars['showReset']) ? 1 : 0;
 123                      $this->settingsVars['displayThank']    = isset($this->httpVars['displayThank']) ? 1 : 0;
 124                      $this->settingsVars['forceUnique']    = isset($this->httpVars['forceUnique']) ? 1 : 0;
 125                      $this->settingsVars['finalMessage'] = @$this->httpVars['finalMessage'];
 126                      $this->settingsVars['submitJavascript'] = $this->httpVars['submitJavascript'];
 127                  break;
 128                  }
 129               if ($this->httpVars['cv_curpage'] + 1 > $maxpage)
 130                  {
 131                  $maxpage = $this->httpVars['cv_curpage'] + 1;
 132                  }   
 133              $this->settingsVars['maxpage'] = $maxpage;
 134              $this->settingsVars['submitTitle'] = ($this->params['submitTitle']!='') ? $this->params['submitTitle'] : 'Send';
 135              $this->saveSettings($this->settingsVars);
 136              }
 137          }
 138      
 139      function getContent()
 140          {
 141          if($this->settingsVars['forceUnique'] == 1)
 142              {
 143              if(!is_array($this->settingsVars['submitters']))
 144                  $this->settingsVars['submitters'] = array();
 145              
 146              if(array_search(T_USER, $this->settingsVars['submitters']) !== false)
 147                  {
 148                  return (@$this->params['finalMessage'] ? $this->params['finalMessage'] : 'Successfully sent form.') . '<br>';
 149                  }
 150              
 151              if (isset($this->httpVars['send']))
 152                  {
 153                  if(!is_array($this->settingsVars['submitters']))
 154                      $this->settingsVars['submitters'] = array();
 155                  $this->settingsVars['submitters'][] = T_USER;
 156                  $this->saveSettings($this->settingsVars);
 157                  }        
 158              }
 159  
 160          $this->settingsVars['fields'] = FormBuilderOptionWidget::generateQueries($this->settingsVars['fields']);
 161          $this->settingsVars['fields'] = FormBuilderOptionWidget::executeRetrieveQueries($this->settingsVars['fields'], T_APP_BASE . "EmailFeedback/.dbrc");
 162          if (isset($this->httpVars['send']))
 163              {
 164              if(!isset($this->settingsVars['displayThank']))
 165                  $this->settingsVars['displayThank'] = 1;
 166                  
 167              // do the associated storing queries, unless the workflow indicates they should wait
 168              if(($this->settingsVars['saveToWorkflow'] == 1 && $this->settingsVars['workflowQueryWait'] != 1) || $this->settingsVars['saveToWorkflow'] == 0 || $this->settingsVars['saveToWorkflow'] == "")
 169                  FormBuilderOptionWidget::executeStoreQueries($this->settingsVars['fields'], $this->httpVars, T_APP_BASE . "EmailFeedback/.dbrc");
 170  
 171              // do the workflow storage
 172              if($this->settingsVars['saveToWorkflow'])    
 173                  {
 174                  //build up an array of the fields and their values
 175                  foreach($this->settingsVars['fields'] as $key => $field)
 176                      {
 177                      if ($field['type'] == 'radio' && $this->httpVars[str_replace(" ", "__", $field['name'])] == 'custom')
 178                          $value = $this->httpVars[$field['name'] . '_custom' ];
 179                      else if($field['type'] == 'checkbox')
 180                          $value = implode(", ", $this->httpVars[str_replace(" ", "__", $field['name'])]);
 181                      else
 182                          $value = $this->httpVars[str_replace(" ", "__", $field['name'])];
 183                      
 184                      $this->settingsVars['fields'][$key]['value'] = $value;
 185                      }
 186                  $workflow_data = serialize($this->settingsVars['fields']);
 187                  $workflow_data = str_replace("'", "''", $workflow_data);
 188                  if($this->settingsVars['workflowApprover'] != "")
 189                      $workflow_approver = $this->settingsVars['workflowApprover'];
 190                  else
 191                      {
 192                      $sqry = $this->settingsVars['workflowApproverQuery'];
 193                      if ( !is_array($_SESSION['caravel_variables'] ) )
 194                          $_SESSION['caravel_variables'] = array($_SESSION['caravel_variables']);
 195                      foreach($_SESSION['caravel_variables'] as $m => $b)
 196                          $sqry = str_replace("|" . $m . "|", "'" . $b . "'", $sqry);
 197  
 198                      foreach($this->httpVars as $htvar => $htval)
 199                          $sqry = str_replace("|" . $htvar . "|", "'" . $htval . "'", $sqry);
 200  
 201                      $res = $this->stodb->query($sqry);
 202                      $row = $res->fetchrow(DB_FETCHMODE_ASSOC);
 203                      $row = array_change_key_case($row, CASE_LOWER);
 204                      foreach($row as $k => $v)
 205                          $workflow_approver = $row[$k];
 206                      }
 207                  $workflow_id = $this->settingsVars['workflowID'];    
 208  
 209                  Workflow::_connect();
 210                  $query = "INSERT into workflow (workflow_id, data, approver, date)
 211                            VALUES ('$workflow_id', '$workflow_data', '$workflow_approver', now())";
 212  
 213                  $res = $this->db->query($query);
 214  
 215                  if(mnDB::isError($res))
 216                      new mnAlert("Emailfeedback::getContent(): ". $res->getMessage(), __FILE__, __LINE__);
 217                  }
 218              
 219              // do any emails
 220              return $this->processForm();
 221              }
 222          else
 223              return $this->getUserForm();
 224          }
 225          
 226      function getUserForm()
 227          {
 228          $count = 0;
 229          //so, it will get next value from the database after form is submitted
 230          //theodoreb, Jul 18, 2006
 231          if (isset($this->httpVars['send']))
 232              {
 233              $this->settingsVars['fields'] = FormBuilderOptionWidget::generateQueries($this->settingsVars['fields']);
 234              $this->settingsVars['fields'] = FormBuilderOptionWidget::executeRetrieveQueries($this->settingsVars['fields'], T_APP_BASE . "EmailFeedback/.dbrc");
 235              }
 236  
 237          //make sure fields exist before creating send button, give message if there are no fields
 238          foreach ( $this->settingsVars['fields'] as $k => $field   )
 239              {
 240              if ($field['type'] == 'html' || $field['type'] == 'newsection' || $field['type'] == 'linebreak' || $field['type'] == '')
 241                  {
 242                  }
 243              else
 244                  { $count++;}
 245                  
 246              if($field['type'] == 'checkbox')
 247                  {
 248                  if($field['label'] == "")
 249                      $this->settingsVars['fields'][$k]['label'] = $this->settingsVars['fields'][$k]['name'];
 250                  $this->settingsVars['fields'][$k]['name'] = $this->settingsVars['fields'][$k]['name'] . "[]";
 251                  }
 252      
 253              }
 254          if ( $count == 0)
 255              return "Feedback Form error: This form has no fields!";
 256              
 257          $qf = FormWidget::quickFormGenerator($this->settingsVars['fields']) ;
 258  
 259          if ($this->settingsVars['submitToDifferentPage'] != 'on' )
 260              {
 261              $f .= '<form style="font: 10px Verdana,sans-serif;" name="cv_EmailFeedback" action="' . $this->linkToSelf() . '" method="POST" enctype="multipart/form-data">';
 262              }
 263          else
 264              {
 265              if ( substr($this->settingsVars['alternateSite'], 0, 4) == 'http')
 266                  {
 267                  $f .= '<form style="font: 10px Verdana,sans-serif;" name="cv_EmailFeedback" action="' . $this->settingsVars['alternateSite'] . '" method="POST" enctype="multipart/form-data">';
 268                  }
 269              else
 270                  {
 271                  $f .= '<form style="font: 10px Verdana,sans-serif;" name="cv_EmailFeedback" action="http://' . $this->settingsVars['alternateSite'] . '" method="POST" enctype="multipart/form-data">';
 272                  }
 273              }
 274          
 275          if(isset($this->settingsVars['cvcustomjs']) && $this->settingsVars['cvcustomjs'] != "")
 276              $this->addHeader('<script type="text/javascript">' . $this->settingsVars['cvcustomjs'] . '</script>');
 277          $f .= FormWidget::quickForm($qf, '', 'form.noformtagnonsettings.tpl.html');
 278          $f .= '<div style="text-align: center; float: right; width: 100%">';
 279          $javascript = "var errorArray = new Array(0);";
 280          foreach($this->settingsVars['fields'] as $i => $field)
 281              {
 282              if($field['reqd'] )
 283                  {
 284                  $javascript .= " if ( document.cv_EmailFeedback.". str_replace(' ', '__', $this->paramName($field['name'])) . ".value == '')
 285                                   {
 286                                   errorArray.push('". $field['label'] ."');
 287                                   }";
 288                  if($field['type'] == "radio")
 289                      {
 290                      $javascript .= "
 291                                    var checked = false;
 292                                   for(var i=0; i < document.cv_EmailFeedback.".str_replace(' ', '__', $this->paramName($field['name'])).".length; i++)
 293                                       {                                     
 294                                       if(document.cv_EmailFeedback.".str_replace(' ', '__', $this->paramName($field['name']))."[i].checked == true)
 295                                         checked = true;
 296                                      }
 297                                      //meaning, single radio button
 298                                      if(document.cv_EmailFeedback.".str_replace(' ', '__', $this->paramName($field['name'])).".length == null)
 299                                          {
 300                                          if(document.cv_EmailFeedback.".str_replace(' ', '__', $this->paramName($field['name'])).".checked == true)
 301                                              checked = true;
 302                                          }
 303                                      if (!checked)
 304                                          errorArray.push('". $field['label'] ."');";
 305                      }                                        
 306                   }
 307              }
 308          $javascript .= "if (errorArray.length == 0)
 309                              {
 310                              }
 311                          else if (errorArray.length == 1)
 312                              {
 313                              alert('Error: You must fill out the '+errorArray[0]+' field.');
 314                              return false;
 315                              }
 316                          else if (errorArray.length > 1)
 317                              {
 318                              for (var i =0; i < errorArray.length; i++)
 319                                  {
 320                                  if (i == 0)
 321                                      {
 322                                      var errorList = errorArray[0] ;
 323                                      }
 324                                  else if ( (i+1) < errorArray.length )
 325                                      {
 326                                      errorList = errorList + ', ' + errorArray[i] ;
 327                                      }
 328                                  else if ( (i+1) == errorArray.length )
 329                                      {
 330                                      errorList = errorList + ' and ' + errorArray[i]
 331                                      }
 332                                  }
 333                              alert('Error: You must fill out the ' + errorList + ' fields.');
 334                              return false;
 335                              }
 336                         ";
 337          $js = array('onclick' => $javascript . $this->settingsVars['submitJavascript'] );
 338          $f .= FormWidget::submit('send', $this->params['submitTitle'], $js );
 339          if (@$this->settingsVars['showReset'])
 340              $f .= ' ' . FormWidget::reset('reset', 'Clear');
 341          $f .= '</div><div style="clear:both;font-size: 1px;line-height: 1px;">&nbsp;</div></form>';
 342          if ($this->settingsVars['noBlockPrefix'])
 343            return str_replace($this->paramName(''), '', $f);
 344          else
 345            return $f;
 346          }
 347          
 348      function processForm()
 349          {
 350          $error = false; $out = '';
 351          if (@$this->params['emailAddress'])
 352              {
 353              $message = '';
 354              $from = T_EMAILER_DEFAULT_FROM;
 355              $subject = @$this->params['emailSubject'] ? $this->params['emailSubject'] : T_EMAILER_DEFAULT_SUBJECT;
 356              $attach = array();
 357  
 358              foreach($this->settingsVars['fields'] as $i => $field)
 359                  {
 360                  if ($field['type'] == 'html' || $field['type'] == 'newsection' || $field['type'] == 'linebreak' || $field['type'] == '' )
 361                      continue;
 362                      
 363                  $name = $field['label'] == '' ? $field['name'] : $field['label'];
 364                  if ($field['type'] == 'radio' && $this->httpVars[str_replace(" ", "__", $field['name'])] == 'custom')
 365                    $value = $this->httpVars[$field['name'] . '_custom' ];
 366                  else if($field['type'] == 'checkbox')
 367                    $value = ($this->httpVars[str_replace(" ", "__", $field['name'])] != "") ? implode(", ", $this->httpVars[str_replace(" ", "__", $field['name'])]) : '';
 368                  else
 369                    $value = $this->httpVars[str_replace(" ", "__", $field['name'])];
 370  
 371                  if (is_array($value))
 372                      $value = implode("\n\t", $value);
 373  
 374                  if ($field['type'] == 'file')
 375                      {
 376                      //<-- jasonay 10/30/2007
 377                      //create fileName from settings with replaces
 378                      $f_id = $this->paramName($field['name']);
 379                      $orgFileName = $_FILES[$f_id]['name'];
 380                      $fileName = str_replace('|T_USER|',T_USER, $field['custom']);
 381                      $fileName = str_replace('|_fileName_|',$orgFileName, $fileName);
 382                      $uploadDN = "mnF=".$fileName. ",". $field['customTitle'];
 383                      //print Utility::getval($uploadDN);
 384                      
 385                      //Delete the existing file if the same file alredy exist
 386                      if ($this->ldap->dnExists($uploadDN))
 387                        $this->ldap->delete($uploadDN);
 388  
 389                      //uploading file
 390                      $upload = oFile::create($this->ldap, $uploadDN, $fileName, $_FILES[$this->paramName('upload_file')]['type']);
 391                      
 392                      if (mnError::isError($upload))
 393                        return new mnError('Error uploading project file: ' . $upload->getMessage(), __FILE__, __LINE__);
 394                      
 395                      if (is_uploaded_file($_FILES[$f_id]['tmp_name']))
 396                          {
 397                          $attach[$_FILES[$f_id]['name']] = $_FILES[$f_id]['tmp_name'];
 398                          $value = 'See ' . $_FILES[$f_id]['name'] . ' (attached).';
 399                          }
 400                      else
 401                          $value = 'Invalid file.';
 402                      }
 403                  
 404                  if($field['reqd'] && !$value)
 405                      {
 406                      $out .= "Error: You must fill out the <b>$name</b> field.<br>";
 407                      $error = true;
 408                      }
 409                      
 410                  // spam check
 411                  if (Utility::looks_like_form_spam($value)) {
 412                      $out .= "Error: Your message has been rejected because it appears to be spam.  (E-mail headers and HTML links are not allowed.)<br />";
 413                      $error = true;
 414                  }
 415                  
 416                  if(preg_match('/subject/i', $name))
 417                      $subject .= $value;
 418                  
 419                  if(preg_match('/email/i', $name) or preg_match('/e-mail/i', $name))
 420                      $from = $value;
 421                  //checks if the email from is based on a field and then specifies appropriately
 422                  if ( $this->settingsVars['getEmailFromField'] == 'on')
 423                      {
 424                      $from = $this->httpVars[ $this->settingsVars['emailFromField'] ];
 425                      }
 426                  else
 427                      {
 428                      $from = $this->settingsVars['emailFrom'] == '' ? $from : $this->settingsVars['emailFrom'];
 429                      }
 430                  }
 431              if (!$error)
 432                  {
 433                  if ($this->settingsVars['emailFormat'] != '')
 434                      {
 435                      $message = $this->settingsVars['emailFormat'];
 436                      }
 437                  else
 438                      {
 439                      $message = '';
 440                      foreach($this->settingsVars['fields'] as $i => $field)
 441                          {
 442                          if ($field['type'] == 'html' || $field['type'] == 'newsection' || $field['type'] == 'linebreak' || $field['type'] == '' || $field['type'] == 'file')
 443                              continue;
 444                              
 445                          $name = $field['label'] == '' ? $field['name'] : $field['label'];
 446                          
 447                          $value = "|" . $field['name']  . "|";
 448                          if (is_array($value))
 449                              $value = implode("\n\t", $value);
 450  
 451                          $message .= $name . ":\n\t" . $value . "\n";
 452                          }
 453                      }
 454                  //searches through each field unique name and replaces all values that would have been inserted by the buttons on the edit page
 455                  foreach($this->settingsVars['fields'] as $i => $field)
 456                      {
 457                      if ($field['type'] == 'html' || $field['type'] == 'newsection' || $field['type'] == 'linebreak' || $field['type'] == '' )
 458                           continue;
 459                      
 460                      if ($field['type'] == 'radio' && $this->httpVars[str_replace(" ", "__", $field['name'])] == 'custom')
 461                        $value = $this->httpVars[$field['name'] . '_custom' ];
 462                      else if($field['type'] == 'checkbox')
 463                        $value = ($this->httpVars[str_replace(" ", "__", $field['name'])] != "") ? implode(", ", $this->httpVars[str_replace(" ", "__", $field['name'])]) : '';
 464                      else
 465                        $value = $this->httpVars[str_replace(" ", "__", $field['name'])];
 466                      
 467                      if (is_array($value))
 468                              $value = implode("\n\t", $value);
 469                      $message = str_replace("|" . $field['name']  . "|", $value , $message);
 470                      $subject= str_replace("|" . $field['name']  . "|", $value , $subject);
 471                      }
 472                  $matches =array();
 473                  preg_match_all('/<[^>]+>/s', $message, $matches);
 474                  if(count($matches[0]) > 1)
 475                      {
 476                      $mime = "text/html; charset=iso-8859-1";
 477                      $message = str_replace("\n", "<br />", $message);
 478                      }
 479                  else
 480                      $mime = "text/plain; charset=iso-8859-1";        
 481                      
 482                  $res = Utility::send_email($this->params['emailAddress'], $from, $subject, $message, count($attach) ? $attach : '', "\n", $mime);
 483  
 484                  //if the file directory has been selected and the file is supposed to be saved, save it as specified
 485                  if ( $this->settingsVars['saveToFile'] && isset($this->settingsVars['saveToFileDirectory']) )
 486                      {
 487                      $message = $this->settingsVars['saveFormat'];
 488                      $filename =  $this->settingsVars['saveFilename'];
 489                      
 490                      $metadata = array();
 491                       $metadata['author'] = $this->settingsVars['savemetaauthor'];
 492                       $metadata['title'] = $this->settingsVars['savemetatitle'];
 493                      $metadata['description'] = $this->settingsVars['savemetadesc'];
 494                      $metadata['keywords'] = $this->settingsVars['savemetakeywords'];
 495                      if ($this->settingsVars['metadate'] == 'on')
 496                          $metadata['createdate'] = $this->settingsVars['metadatedrop'];
 497                      
 498                      //for each field check the fileformat and metadata items and replace the field names with their values when found
 499                      foreach($this->settingsVars['fields'] as $i => $field)
 500                          {
 501                          if ($field['type'] == 'html' || $field['type'] == 'newsection' || $field['type'] == 'linebreak' || $field['type'] == '' )
 502                               continue;
 503                           
 504                          if ($field['type'] == 'radio' && $this->httpVars[str_replace(" ", "__", $field['name'])] == 'custom')
 505                            $value = $this->httpVars[$field['name'] . '_custom' ];
 506                          else if($field['type'] == 'checkbox')
 507                            $value = implode(", ", $this->httpVars[str_replace(" ", "__", $field['name'])]);
 508                          else
 509                            $value = $this->httpVars[str_replace(" ", "__", $field['name'])];
 510  
 511                          if (is_array($value))
 512                                  $value = implode("\n\t", $value);
 513                                  
 514                          $message = str_replace("|" . $field['name']  . "|", $value , $message);
 515                          $filename = str_replace("|" . $field['name']  . "|", $value , $filename);
 516                          $metadata['author'] = str_replace("|" . $field['name']  . "|", $value , $metadata['author']);
 517                          $metadata['title'] = str_replace("|" . $field['name']  . "|", $value , $metadata['title']);
 518                          $metadata['description'] = str_replace("|" . $field['name']  . "|", $value , $metadata['description']);
 519                          $metadata['keywords'] = str_replace("|" . $field['name']  . "|", $value , $metadata['keywords']);
 520                          if ($this->settingsVars['metadate'] == 'on')
 521                              $metadata['createdate'] = str_replace( $field['name'] , $value , $metadata['createdate']);
 522                          }
 523                      
 524                      if ($this->settingsVars['metadate'] == 'on')
 525                          $metadata['createdate'] = strtotime($metadata['createdate']);
 526                      
 527                      //define time to be appended to end of filename
 528                      $time = date("Y-m-d:H-i-s");
 529                      
 530                      $message = str_replace("|timestamp|", $time , $message);
 531                      $filename = str_replace("|timestamp|", $time , $filename);
 532                      $metadata['author'] = str_replace("|timestamp|", $time , $metadata['author']);
 533                      $metadata['title'] = str_replace("|timestamp|", $time , $metadata['title']);
 534                      $metadata['description'] = str_replace("|timestamp|", $time , $metadata['description']);
 535                      $metadata['keywords'] = str_replace("|timestamp|", $time , $metadata['keywords']);
 536  
 537                      $ldap = $this->ldap;
 538                      //do not allow creation of two identical files... 
 539                      //one second apart will make the code try over and over again until 
 540                      //the the filename/path in question has not been created
 541                      $filename = str_replace( '.', ' ', $filename) ;
 542                      $filename = mnLDAP::dnSafe ( $filename);
 543                      $fullpath = "mnF=" . $filename . ".html,". $this->settingsVars['saveToFileDirectory'] ;
 544                      //first get the new file dn
 545                      $newfiledn = $fullpath;
 546  
 547                      //make sure the dir exists - this is painful
 548                      $top = substr($newfiledn, strpos($newfiledn, ',')+1);
 549                      $iterator = substr_count($top, ",");
 550                      $dir_arr = array();
 551                      for($i=0; $i<$iterator; $i++)
 552                        {
 553                        if(strpos($top, "mnOD") === 0)
 554                           $dir_arr[] = $top;
 555  
 556                        $top = substr($top, strpos($top, ',')+1);
 557                        }
 558                      // now make sure all these directories exist and if they dont create them
 559                      if(count($dir_arr) >= 1)
 560                        {
 561                        krsort($dir_arr);
 562                        foreach($dir_arr as $dirdn)
 563                           {
 564                           if(!$ldap->dnExists($dirdn))
 565                               {
 566                               oDirectory::create($ldap, $dirdn);
 567                               //$array_val = array('cvFileOwner' => '', 'cvFileGroup' => '', 'cvFilePriv' => '222');
 568                               //$ldap->replace($dirdn, $array_val);
 569                               }
 570                           }
 571                        }
 572                       $num = 1;
 573                      $orignewfiledn = $newfiledn;
 574                      while(($ldap->dnExists($newfiledn) || (strpos(DN::dnToName($newfiledn), DN::dnToName($orignewfiledn)) !== false)) && $num < 25)
 575                          {
 576                          $newfiledn = $orignewfiledn;
 577                          $tmpnme = substr(DN::dnToName($newfiledn), 0, strpos(DN::dnToName($newfiledn), "."));
 578                          $tmpext = substr(DN::dnToName($newfiledn), strpos(DN::dnToName($newfiledn), "."));
 579                          $tmpnme .= $num;
 580  
 581                          $newfiledn = "mnF=" . $tmpnme . $tmpext . "," . DN::dnToParent($newfiledn);
 582                          $num++;
 583                          }
 584                      $fullpath = $newfiledn;
 585                      //pull out keywords from fields and edit text
 586                      if ($this->settingsVars['literalKeywords'] != 'on')
 587                          {
 588                          $keywords = Utility::getKeywordsFromString($metadata['keywords']);
 589                          $generic = array_keys ( $keywords['Generic'] ) ;
 590                          $highrank =  array_keys ( $keywords['HighRank'] ) ;
 591                          
 592                          foreach ($generic as $index => $value) 
 593                              {
 594                              if (empty($value)) 
 595                                unset($generic[$index]);
 596                              }
 597                          foreach ($highrank as $index => $value)
 598                              {
 599                              if (empty($value))
 600                                unset($highrank[$index]);
 601                              }
 602                          if (count($generic) != 0)
 603                              {
 604                              $metadata['keywords'] = implode("\r\n ",  $generic );
 605                              if (count($highrank) != 0)
 606                                  {
 607                                  $metadata['keywords'] .= implode("\r\n ",  $highRank )  ;
 608                                  }
 609                              }
 610                          else if (count($rank) != 0)
 611                              {
 612                              $metadata['keywords'] = implode("\r\n ",  $highrank );
 613                              }
 614                          }
 615                      //create the savefile
 616                      oFile::create($this->ldap, $fullpath, $message, 'text/html' , $metadata);
 617                      }
 618                  
 619                  if($res && $this->settingsVars['displayThank'] == 1)
 620                      {
 621                      $out .= (@$this->params['finalMessage'] ? $this->params['finalMessage'] : 'Successfully sent form.') . '<br>';
 622                      return $out;
 623                      }
 624                  else if($res) 
 625                      {
 626                      $out .= (@$this->params['finalMessage'] ? $this->params['finalMessage'] : 'Successfully sent form.') . '<br>';
 627                      }   
 628                  else
 629                      $out .= 'Error sending form.<br>';
 630                  }
 631              }
 632          else
 633              {
 634              $out .= 'Error: No destination e-mail address specified for this form.';
 635              $error = true;
 636              }
 637  
 638          $out .= $this->getUserForm();
 639          return $out;
 640          }
 641      
 642      function getConfig()
 643          {
 644          //max_page is whatever is greatest from the following
 645          $maxpage = 0;
 646          if ($this->httpVars['cv_curpage'] > $maxpage)
 647              $maxpage = $this->httpVars['cv_curpage'];
 648          if ($this->httpVars['cv_maxpage'] > $maxpage)
 649              $maxpage = $this->httpVars['cv_maxpage'];
 650          if ($this->settingsVars['maxpage'] > $maxpage)
 651              $maxpage = $this->settingsVars['maxpage'];
 652          //save as jumping from one page to the next
 653          EmailFeedback::onSave();
 654  
 655          $tpl = new Template_PHPLib($this->appBase);
 656          $tpl->setFile('main', 'emailfeedbackform.tpl.html');
 657          
 658          //possibly needs to be literal wait to see if it really does 
 659          // 8-1-2006 jasonay
 660          $tpl->setVar('save', FormWidget::_simple('hidden', 'save', 'true', array('id' => 'save') ));
 661          $tpl->setVar('linktoself', $this->linktoself());
 662          $tpl->setVar('appName', $this->paramName('appName'));
 663          $tpl->setBlock('main', 'categoryBlock', 'cB');
 664          $tpl->setVar('cB', '');
 665          $tpl->setBlock('categoryBlock', 'categoryEntryBlock', 'ceB');
 666          
 667          //number of pages of edit selection
 668          $numpages = 6;
 669          
 670          $f = FormWidget::init('', 'form.noformtag.tpl.html');
 671          $f->name('menu0');
 672          $f->section('p1');
 673          $f->hidden('cv_curpage','', array('id' => 'cv_curpage') );
 674          $f->hidden('cv_submit' ,'', array('id' => $this->paramName('cv_submit') ) );
 675          
 676          if ($this->httpVars['cv_curpage'] + 1 > $maxpage)
 677              $maxpage = $this->httpVars['cv_curpage'] + 1;
 678          
 679          $f->hidden('cv_maxpage', $maxpage);
 680          $anum = 0;
 681          
 682          //javascript for jumping to pages
 683          for ($i = 0; $i < $maxpage+1; $i++) 
 684              {
 685              $listonclick[$i] = "document.getElementById('cv_curpage').value = " . $i . " ;    document.EmailFeedback.submit(); ";
 686              }
 687          //for finalize button to save and preview
 688          $app =& $this;
 689          
 690          $previewParams =  array('admin[block;' . $app->blockID . ']' => 'preview');
 691          $link = Utility::link($app->sectionPathArray, $previewParams);
 692          
 693          $finalizeJS = '';
 694          if ($maxpage > ($numpages - 1))
 695             {
 696             if ( T_SINGLE_BLOCK )
 697                 {
 698                 $previewtext = 'Save &amp; Close';
 699                 $finalizeJS = "document.getElementById('".$this->paramName('cv_submit')."').value = '" . $previewtext . "'; document.EmailFeedback.submit(); ";
 700                 }
 701             else
 702                 {
 703                 $previewtext = 'Save &amp; Preview';
 704                 $finalizeJS = "EmailFeedback.action='$link'; document.getElementById('".$this->paramName('cv_submit')."').value = '" . $previewtext . "'; document.EmailFeedback.submit(); ";
 705                 }
 706             }
 707  
 708             $finalizeButton =  '<div style="float:right;">'. Widget::button('primary', 'Finalize', 'final_button', $finalizeJS ).'</div>';
 709             if ($maxpage <= ($numpages - 1))
 710                 {
 711                 $finalizeButton = '';
 712                 }
 713          
 714          $listitems[$anum] = "Form Setup";
 715          $listattrs[$anum] = array('id' => $this->paramName('menu'.$anum), 'class' => '');
 716          $anum++;
 717          $listitems[$anum] = "Query Management";
 718          $listattrs[$anum] = array('id' => $this->paramName('menu'.$anum), 'class' => '');
 719          $anum++;
 720          $listitems[$anum] = "Email Options";
 721          $listattrs[$anum] = array('id' => $this->paramName('menu'.$anum), 'class' => '');
 722          $anum++;
 723          $listitems[$anum] = "Text Save";
 724          $listattrs[$anum] = array('id' => $this->paramName('menu'.$anum), 'class' => '');
 725          $anum++;
 726          $listitems[$anum] = "Workflow Options";
 727          $listattrs[$anum] = array('id' => $this->paramName('menu'.$anum), 'class' => '');
 728          $anum++;
 729          $listitems[$anum] = "Overall Options";
 730          $listattrs[$anum] = array('id' => $this->paramName('menu'.$anum), 'class' => '');
 731          //the current page is set on the previous page before submitting so that correct page can load
 732          switch ( $this->httpVars['cv_curpage'] )
 733          {
 734          case '':
 735          //form fields
 736          case '0':
 737              $_SESSION[$this->paramName('builderID')] = $this->settingsVars['fields'];
 738              $f->field('Form fields:');
 739              $f->formbuilder( $_SESSION[$this->paramName('builderID')], "bare", "builderID" , '', 0);
 740              $f->hidden('cv_prevpage', '0' );
 741              $f->field('Submit Page to<br>non-Caravel site?');
 742              //disable text field when not in use
 743              $f->checkbox('submitToDifferentPage', $this->settingsVars['submitToDifferentPage'], "" , 
 744              array('onclick' => " if (document.getElementById('" . $this->paramName('submitToDifferentPage') . "').checked )
 745                                       {
 746                                       document.getElementById('" . $this->paramName('alternateSite') . "').disabled =  false;
 747                                       } 
 748                                   else
 749                                       {
 750                                       document.getElementById('" . $this->paramName('alternateSite') . "').disabled = true;
 751                                       }
 752                                 " ,  
 753              'id' => $this->paramName('submitToDifferentPage') )   );
 754              if ( $this->settingsVars['submitToDifferentPage'] != 'on' )
 755                  {
 756                  $f->text('alternateSite', $this->settingsVars['alternateSite'], '', array('id' => $this->paramName('alternateSite'), 0 => 'disabled', 'style' => 'width:90%;')  );
 757                  }    
 758              else
 759                  {
 760                  $f->text('alternateSite', $this->settingsVars['alternateSite'], '', array('id' => $this->paramName('alternateSite'), 0 => 'enabled', 'style' => 'width:90%;')  );
 761                  }
 762              $f->field('Remove unique blockname prefixes for input fields?');
 763              $f->checkbox('noBlockPrefix', $this->settingsVars['noBlockPrefix'], "");
 764              
 765              $f->field('Custom Javascript:');
 766              $f->textarea('cvcustomjs' , $this->settingsVars['cvcustomjs'], 6, 43);
 767              
 768              
 769              $f->endSection();
 770              $anum = 0;
 771              $tpl->setVar('selectorinitpage', 'display: block;');
 772              $tpl->setVar('wizhelp', Widget::getWizardHelp('This page allows you to setup your form fields and place them on separate pages if you desire. You can also choose to submit the form'
 773                                  .' to a non-Caravel site.') );
 774              $tpl->setVar('ceB','');
 775              //if the page is going to be submitted to a non-caravel site, then skip all pages when clicking on the next button
 776  
 777              
 778              $tpl->setVar('buttons', '<br>'.$finalizeButton. '<div style="float:right;">'
 779              .Widget::button('primary', 'Next', 'next_button', " if(document.getElementById('" . $this->paramName('alternateSite') . "').disabled == false) 
 780                                                                      {  document.getElementById('cv_curpage').value = 4; }
 781                                                                  else
 782                                                                      {  document.getElementById('cv_curpage').value = 1; }
 783                                                                  document.EmailFeedback.submit(); ")
 784              .'</div>'
 785              );
 786              
 787              //$tpl->setVar('entrytitle', 'Add, modify, or remove fields from this page.');
 788              $tpl->setVar('entrydesc',$f->get());
 789              $tpl->setVar('divpageid', $this->paramName('page'.$anum));
 790              $tpl->parse('cB', 'categoryBlock', true);
 791              $tpl->setVar('blockCB','');
 792          break;
 793          //query manager
 794          case '1':
 795              $att_vertical = array('style' => 'vertical-align:top;');
 796              $anum = 1;
 797              $tpl->setVar('selectorinitpage', 'display: block;');
 798              $tpl->setVar('wizhelp', Widget::getWizardHelp('This page allows you to enter the query manager which allows you to auto-fill and save fields to a database.') );
 799              $tpl->setVar('ceB','');
 800              
 801              $finalizeButton =  '<div style="float:right;">'. Widget::button('primary', 'Finalize', 'final_button', $finalizeJS ).'</div>';
 802              if ($maxpage <= 4)
 803                  {
 804                  $finalizeButton = '';
 805                  }
 806              
 807              $tpl->setVar('buttons', '<br>'.$finalizeButton. '<div style="float:right;">'
 808              .Widget::button('primary', 'Next', 'next_button', "document.getElementById('cv_curpage').value = 2;     document.EmailFeedback.submit(); ")
 809              .'</div><div style="float:right;">' .Widget::button('primary', 'Previous', 'previous_button', "document.getElementById('cv_curpage').value = 0;     document.EmailFeedback.submit(); ") 
 810              ."</div>");
 811              if ($this->settingsVars['submitToDifferentPage'] != 'on')
 812                  {
 813                  $f->field('Query manager:', '', '', array('style'=> 'width:40%;') );
 814                  $f->hidden('cv_prevpage', '1' );
 815                  
 816                  //if (T_SUPERUSER )
 817                  if (true)
 818                      {
 819                      $_SESSION[$this->paramName('builderID')] = $this->settingsVars['fields'];
 820                      $f->formbuilder( $_SESSION[$this->paramName('builderID')], "bare", "builderID" , '',  1 );
 821                      }
 822                  else
 823                      {
 824                      $f->html(Widget::getWizardHelp('Database interactivity requires administrator privileges. If you wish to use this feature please contact your Caravel administrator.') );
 825                      }
 826                  }
 827              else
 828                  {
 829                  $f->html('This page is not usable because you have chosen to submit to a non-Caravel site. 
 830                  If you wish to use this item please go back to the <b>Form Setup</b> page and uncheck the checkbox indicating you want to submit to a non-Caravel site.');
 831                  }
 832  
 833              $tpl->setVar('entrydesc',$f->get());
 834              $tpl->setVar('entrytitle', '');
 835              $tpl->parse('ceB', 'categoryEntryBlock', true);
 836  
 837              $tpl->setVar('divpageid', $this->paramName('page'.$anum));
 838              $tpl->parse('cB', 'categoryBlock', true);
 839          break;
 840          //email options
 841          case '2':                                                                                                    
 842              $att_vertical = array('style' => 'vertical-align:top;');
 843              $anum = 2;
 844              $tpl->setVar('selectorinitpage', 'display: block;');
 845              $tpl->setVar('wizhelp', Widget::getWizardHelp('From this page you can specify the destination, from address, subject, and format of the email sent when a form is submitted.') );
 846              $tpl->setVar('ceB','');
 847              
 848  
 849              $tpl->setVar('buttons', '<br>'.$finalizeButton. '<div style="float:right;">'
 850              .Widget::button('primary', 'Next', 'next_button', "document.getElementById('cv_curpage').value = 3;     document.EmailFeedback.submit(); ")
 851              .'</div><div style="float:right;">' 
 852              .Widget::button('primary', 'Previous', 'previous_button', "document.getElementById('cv_curpage').value = 1;     document.EmailFeedback.submit(); ")
 853              ."</div>");
 854              
 855              if ($this->settingsVars['submitToDifferentPage'] != 'on')
 856                  {
 857                  $dropdown = array();
 858                  foreach ($this->settingsVars['fields'] as $i => $attr)
 859                      {
 860                      if ($attr['type'] != 'newsection' && $attr['type'] != 'linebreak' && $attr['type'] !='file' )
 861                          {
 862                          if ($attr['label'] != '')
 863                              {
 864                              $dropdown[$attr['name']] = $attr['name'] . "(" . htmlentities($attr['label']) . ")";
 865                              }
 866                          else
 867                              {
 868                              $dropdown[$attr['name']] = $attr['name'];
 869                              }
 870                          }
 871                      }
 872                  $f->field('Destination<br> E-mail Address:', '', '', array('style' => 'width:10%;') );
 873                  $f->text('emailAddress', @$this->settingsVars['emailAddress']);
 874                  
 875                  
 876                  $f->field('From:', '', '', array('style' => 'width:10%;') );
 877                  $f->html('<div style="float:left; width:30%;">');
 878                  $f->text('emailFrom', @$this->settingsVars['emailFrom'], '' ,  array('style' =>'width:100%;') );
 879                  $f->html('</div>');
 880                  $f->html('<div style="float:left; text-align:center;width:20%;">');
 881                  //disable text field when it wont be used
 882                  $f->checkbox('getEmailFromField', @$this->settingsVars['getEmailFromField'],'Define <br> \'from\' address<br>using a field', 
 883                  array( 'onclick' => "if (document.getElementById('" . $this->paramName('getEmailFromField') . "').checked )
 884                                           {
 885                                           document.getElementById('" . $this->paramName('emailFromField') . "').disabled =  false;
 886                                           } 
 887                                       else
 888                                           {
 889                                           document.getElementById('" . $this->paramName('emailFromField') . "').disabled = true;
 890                                           }    
 891                  ",  'id' => $this->paramName('getEmailFromField')
 892                  ) );
 893                  $f->html('</div>');
 894                  $f->html('<div style="float:left; width:50%;">');
 895                  if ( $this->settingsVars['getEmailFromField'] != 'on' )
 896                      {
 897                      $f->dropdown('emailFromField', $dropdown, @$this->settingsVars['emailFromField'], "", array('id' => $this->paramName('emailFromField'),  0 => 'disabled'  ) );
 898                      }    
 899                  else
 900                      {
 901                      $f->dropdown('emailFromField', $dropdown, @$this->settingsVars['emailFromField'], "", array('id' => $this->paramName('emailFromField')   ) );
 902                      }
 903                  $f->html('</div>');
 904                  
 905                  $f->field('Subject:', '', '', array('style' => 'width:10%;') );
 906                  $f->html('<div style="float:left; width:30%;">');
 907                  $f->select('cv_fieldoptionsSubject', $dropdown, '', '', 8, array('style' =>'width:100%;')  );
 908                  $f->html('</div>');
 909                  $f->html('<div style="float:left; text-align:center;width:20%;">');
 910                  $f->button('movefieldsSubject', '>', "
 911                  var val = document.getElementById('" . $this->paramName('cv_fieldoptionsSubject') . "').value;
 912                  var field = document.getElementById('" . $this->paramName('emailSubject') . "');
 913                  if (val != '')
 914                    cv_insertAtCursor( field, '|' + val + '|' );
 915                  "  );
 916                  $f->html('</div>');
 917                  $f->html('<div style="float:left; width:40%;">');
 918                  $f->text('emailSubject' , isset($this->settingsVars['emailSubject']) ? $this->settingsVars['emailSubject'] : "none", 30,   array('id' => $this->paramName('emailSubject') )  );
 919                  $f->html('</div>');
 920                  
 921  
 922                  $f->field('' );
 923                  $f->html(Widget::getWizardHelp('The default email format will provide all fields and their data, so it is not necessary to change it unless you want it in a specific format') );
 924                  $f->field('Email<br>Format', '', '', array('style' => 'width:10%;' ) );
 925                  $f->hidden('cv_prevpage', '2' );
 926                  
 927                  $f->html('<div style="float:left; width:30%;">');
 928                  $f->select('cv_fieldoptions', $dropdown, '', '', 8, array('style' =>'width:100%;')  );
 929                  $f->html('</div>');            
 930  
 931                  $f->html('<div style="float:left; text-align:center;width:20%;">');            
 932                  $f->button('movefields', '>', "
 933                  var val = document.getElementById('" . $this->paramName('cv_fieldoptions') . "').value;
 934                  var field = document.getElementById('" . $this->paramName('cv_emailFormat') . "');  
 935                  if (val != '')          
 936                    cv_insertAtCursor( field, '|' + val + '|' );
 937                  "  );
 938                  //build default format for email format
 939                  $message = '';
 940                  foreach($this->settingsVars['fields'] as $i => $field)
 941                      {
 942                      if ($field['type'] == 'html' || $field['type'] == 'newsection' || $field['type'] == 'linebreak' || $field['type'] == '' || $field['type'] == 'file')
 943                          continue;
 944                          
 945                      $name = $field['label'] == '' ? $field['name'] : htmlentities($field['label']);
 946                      $value = "|" . $field['name']  . "|"; 
 947                      if (is_array($value))
 948                          $value = implode("\n\t", $value);
 949  
 950                      $message .= $name . ":\n\t" . $value . "\n";
 951                      }
 952                  $defaultSaveFormat = $message;
 953                  $f->html('<br>');
 954                  $f->button('restoredefault', 'Default', " confirm('Restoring to the default format will cause you to lose any work you have done on the current format. Are you sure you wish to continue?');  document.getElementById('" . $this->paramName('cv_emailFormat') . "').value = '" .  str_replace("\n", "\\n", $defaultSaveFormat) . "'  ;"); 
 955                  $f->html('</div>');
 956                  $f->html('<div style="float:left; width:50%;">');
 957                  $f->textarea('cv_emailFormat' , isset($this->settingsVars['emailFormat']) ? $this->settingsVars['emailFormat'] : $defaultSaveFormat, 8, 20, array('id' => $this->paramName('cv_emailFormat') )  );
 958                  $f->html('</div>');
 959                  
 960                  $f->endSection();
 961                  }
 962              else
 963                  {
 964                  $f->html('This page is not usable because you have chosen to submit to a non-Caravel site.
 965                  If you wish to use this item please go back to the <b>Form Setup</b> page and uncheck the checkbox indicating you want to submit to a
 966                  non-Caravel site.');
 967                  }
 968              $tpl->setVar('entrydesc',$f->get());
 969              $tpl->setVar('entrytitle', '');
 970              $tpl->parse('ceB', 'categoryEntryBlock', true);
 971              $tpl->setVar('divpageid', $this->paramName('page'.$anum));
 972              $tpl->parse('cB', 'categoryBlock', true);
 973          break;
 974          //save to file
 975          case '3':
 976              $att_vertical = array('style' => 'vertical-align:top;');
 977              $anum = 3;
 978              $tpl->setVar('selectorinitpage', 'display: block;');
 979              $tpl->setVar('wizhelp', Widget::getWizardHelp('Allows you to choose to save a copy of the data sent in the email to file as well. You can specify the location where the information will be '
 980              .'stored, the format of the information saved, and the name that the file will be given. In addition, you can specify metadata to be associated with the file.') );
 981              $tpl->setVar('ceB','');
 982              
 983              
 984              $tpl->setVar('buttons', '<br>'.$finalizeButton .'<div style="float:right;">'
 985              .Widget::button('primary', 'Next', 'next_button', "document.getElementById('cv_curpage').value = 4;     document.EmailFeedback.submit(); ")
 986              .'</div><div style="float:right;">' 
 987              .Widget::button('primary', 'Previous', 'previous_button', "document.getElementById('cv_curpage').value = 2;     document.EmailFeedback.submit(); ")
 988              ."</div>");
 989              
 990              if ($this->settingsVars['submitToDifferentPage'] != 'on')
 991                  {
 992                  $f->field('Save <br>Submission<br> to File?');  
 993                  $f->checkbox('saveToFile', @$this->settingsVars['saveToFile'], '' );
 994                  $f->field('Select Folder', '', '', array('style' => 'width:10%;'));
 995                  $f->folderPicker( 'saveToFileDirectory', @$this->settingsVars['saveToFileDirectory'], '', '', '', 1, ''  );
 996                  //create dropdwon from all fields using their unique names
 997                  $dropdown = array();
 998                  $datedropdown = array();
 999                  foreach ($this->settingsVars['fields'] as $i => $attr)
1000                      {
1001                      if ($attr['type'] != 'newsection' && $attr['type'] != 'linebreak' && $attr['type'] !='file' )
1002                          {
1003                          if ($attr['label'] != '')
1004                              {
1005                              if ($attr['type'] == 'date')
1006                                  {  
1007                                  $datedropdown[$attr['name']] = $attr['name'] . "(" . htmlentities($attr['label']) . ")";
1008                                  }
1009                              $dropdown[$attr['name']] = $attr['name'] . "(" . htmlentities($attr['label']) . ")";
1010                              }
1011                          else
1012                              {
1013                              if ($attr['type'] == 'date')
1014                                  {
1015                                  $datedropdown[$attr['name']] = $attr['name'];
1016                                  }
1017                              $dropdown[$attr['name']] = $attr['name'];
1018                              }
1019                          
1020                          }
1021                      }
1022                  $dropdown['timestamp'] = 'timestamp';
1023                  
1024                  $f->field('File<br>save<br>format', '', '', array('style' => 'width:10%;'));
1025                  $f->hidden('cv_prevpage', '3' );
1026                  $f->html('<div style="float:left; width:30%;">');
1027                  $f->select('cv_fieldoptions', $dropdown, '', '', 9, array('style' =>'width:100%;') );
1028                  $f->html('</div>');
1029                  $f->html('<div style="float:left; text-align:center; width:20%;"><br><br><br>');
1030                  $f->button('movefields', '>', "
1031                  var val = document.getElementById('" . $this->paramName('cv_fieldoptions') . "').value;
1032                  var field = document.getElementById('" . $this->paramName('cv_saveFormat') . "');  
1033                  if (val != '')          
1034                    cv_insertAtCursor( field, '|' + val + '|' );
1035                  "  );
1036                  //default save format is based on the code from the original default email configuration
1037                  $message = '';
1038                  foreach($this->settingsVars['fields'] as $i => $field)
1039                      {
1040                      if ($field['type'] == 'html' || $field['type'] == 'newsection' || $field['type'] == 'linebreak' || $field['type'] == '' || $field['type'] == 'file')
1041                          continue;
1042                      $name = $field['label'] == '' ? $field['name'] : htmlentities($field['label']);
1043                      $value = "|" . $field['name']  . "|"; 
1044                      if (is_array($value))
1045                          $value = implode("\n\t", $value);
1046                      $message .= $name . ":\n\t" . $value . "\n";
1047                      }
1048                  $defaultSaveFormat = $message;
1049                  $f->html('<br>');
1050                  $f->button('restoredefault', 'Default', " confirm('Restoring to the default format will cause you to lose any work you have done on the current format. Are you sure you wish to continue?');  document.getElementById('" . $this->paramName('cv_saveFormat') . "').value = '" .  str_replace("\n", "\\n", $defaultSaveFormat) . "'  ;");            
1051                  $f->html('</div>');
1052                  $f->html('<div style="float:left; width:50%;">');
1053                  $f->textarea('cv_saveFormat' , isset($this->settingsVars['saveFormat']) ? $this->settingsVars['saveFormat'] : $defaultSaveFormat, 8, 20, array('id' => $this->paramName('cv_saveFormat') )  );
1054                  $f->html('</div>');
1055                  $f->field('');
1056                  $f->html(Widget::getWizardHelp('In addition to your specifications here, the filename will have a time appended onto the end of it to ensure uniqueness.'));
1057                  $f->field('Filename<br>Format', '', '', array('style' => 'width:10%;'));
1058                  $f->html('<div style="float:left; width:30%;">');
1059                  $f->select('cv_fieldoptionsFilename', $dropdown, '', '', '', array('style' => 'width:100%;')  );
1060                  $f->html('</div>');
1061                  $f->html('<div style="float:left; text-align:center; width:20%;">');
1062                  $f->button('movefields', '>', "
1063                  var val2 = document.getElementById('"  . $this->paramName('cv_fieldoptionsFilename') . "').value;
1064                  var field2 = document.getElementById('" . $this->paramName('cv_saveFilename') . "');
1065                  if (val2 != '')
1066                    cv_insertAtCursor( field2, '|' + val2 + '|' );
1067                  "   );
1068                  $f->html('</div>');
1069                  $f->html('<div style="float:left; width:50%;">');
1070                  $f->text('cv_saveFilename' , isset($this->settingsVars['saveFilename']) ? $this->settingsVars['saveFilename'] : "file:|timestamp|", '', array( 'id' => $this->paramName('cv_saveFilename'), 'style' => 'width:100%;' )  );
1071                  $f->html('</div>');
1072                  //hide and show metadata
1073                  $f->field('', '', '', array('style' => 'width:10%;'));
1074                  $f->checkbox('saveMetadata',$this->settingsVars['saveMetadata'], 'Show Metadata',
1075                  array('onclick' => " if (document.getElementById('" . $this->paramName('saveMetadata') . "').checked  )
1076                                           {
1077                                           document.getElementById('cv_showhidemetadata').style.display = 'block';
1078                                           }
1079                                       else
1080                                           {
1081                                           document.getElementById('cv_showhidemetadata').style.display = 'none';
1082                                           } ;  ", 'id' => $this->paramName('saveMetadata') )  );
1083                  $f->endSection();
1084                  
1085                  if ($this->settingsVars['saveMetadata'] == 'on')
1086                      {
1087                      $f->html('<div style="display:block;" id="cv_showhidemetadata" >');
1088                      }
1089                  else
1090                      $f->html('<div style="display:none;" id="cv_showhidemetadata" >'); 
1091                  $f->section('p2');                         
1092                  
1093                  $f->field('<b>Metadata<br>Options</b>', '', '', array('style' => 'width:10%;') );
1094                  $f->html('<div style="float:left; width:30%;">');
1095                  $f->select('cv_fieldoptionsmetadata', $dropdown, '', '', 8, array('style' =>'width:100%;') );
1096                  $f->html('</div>');            
1097                  $f->html('<div style="float:left; text-align:center; width:20%;">');
1098                  $f->button('movefields', 'Title >', "
1099                  var val = document.getElementById('" . $this->paramName('cv_fieldoptionsmetadata') . "').value;
1100                  var field = document.getElementById('" . $this->paramName('cv_title') . "');
1101                  if (val != '')
1102                    cv_insertAtCursor( field, '|' + val + '|' );
1103                  "  )  ;
1104                  $f->html('<br>');
1105                  $f->button('movefields', 'Author >', "
1106                  var val = document.getElementById('" . $this->paramName('cv_fieldoptionsmetadata') . "').value;
1107                  var field = document.getElementById('" . $this->paramName('cv_author') . "');
1108                  if (val != '')
1109                  cv_insertAtCursor( field, '|' + val + '|' );
1110                  "  )  ;
1111                  $f->html('<br><br><br>');
1112                  $f->button('movefields', 'Description >', "
1113                  var val = document.getElementById('" . $this->paramName('cv_fieldoptionsmetadata') . "').value;
1114                  var field = document.getElementById('" . $this->paramName('cv_desc') . "');
1115                  if (val != '')
1116                  cv_insertAtCursor( field, '|' + val + '|' );
1117                  "  ) ;
1118                  $f->html('<br><br><br>');
1119                  $f->checkbox('literalKeywords',$this->settingsVars['literalKeywords'], 'Save keywords to field without filtering.');
1120                  $f->button('movefields', 'Keywords >', "
1121                  var val = document.getElementById('" . $this->paramName('cv_fieldoptionsmetadata') . "').value;
1122                  var field = document.getElementById('" . $this->paramName('cv_keywords') . "');
1123                  if (val != '')
1124                  cv_insertAtCursor( field, '|' + val + '|' );
1125                  "  ) ;
1126                  $f->html('<br><br><br>');
1127                  //disable text field when it wont be used
1128                  $f->html('Define creation date from a date field.');
1129                  
1130                  $f->html('</div>');
1131                  $f->html('<div style="float:left; width:50%;">');
1132                  $f->text('cv_title', $this->settingsVars['savemetatitle'], 20, array('id' => $this->paramName('cv_title') ) );
1133                  $f->html('<br>');
1134                  $f->text('cv_author', $this->settingsVars['savemetaauthor'], 20, array('id' => $this->paramName('cv_author') ) );
1135                  $f->html('<br>');
1136                  $f->textarea('cv_desc', $this->settingsVars['savemetadesc'], 4, 20, array('id' => $this->paramName('cv_desc') ) );
1137                  $f->html('<br>');
1138                  $f->textarea('cv_keywords', $this->settingsVars['savemetakeywords'], 4, 20, array('id' => $this->paramName('cv_keywords') ) );
1139                  $f->html('<br>');
1140                  $f->checkbox('metadate', @$this->settingsVars['metadate'],'', 
1141                  array( 'onclick' => "if (document.getElementById('" . $this->paramName('metadate') . "').checked )
1142                                           {
1143                                           document.getElementById('" . $this->paramName('metadatedrop') . "').disabled =  false;
1144                                           } 
1145                                       else
1146                                           {
1147                                           document.getElementById('" . $this->paramName('metadatedrop') . "').disabled = true;
1148                                           }    
1149                  ",  'id' => $this->paramName('metadate')
1150                  ) );
1151                  if ( $this->settingsVars['metadate'] != 'on' )
1152                      {
1153                      $f->dropdown('metadatedrop', $datedropdown, @$this->settingsVars['metadatedrop'], "", array('id' => $this->paramName('metadatedrop'),  0 => 'disabled'  ) );
1154                      }    
1155                  else
1156                      {
1157                      $f->dropdown('metadatedrop', $datedropdown, @$this->settingsVars['metadatedrop'], "", array('id' => $this->paramName('metadatedrop')   ) );
1158                      }
1159                  $f->endSection();
1160                  $f->html('</div>');
1161                  }
1162              else
1163                  {
1164                  $f->html('This page is not usable because you have chosen to submit to a non-Caravel site.
1165                  If you wish to use this item please go back to the <b>Form Setup</b> page and uncheck the checkbox indicating you want to submit to a
1166                  non-Caravel site.');
1167                  }
1168              $tpl->setVar('entrydesc',$f->get());
1169              $tpl->setVar('entrytitle', '');
1170              $tpl->parse('ceB', 'categoryEntryBlock', true);
1171              $tpl->setVar('divpageid', $this->paramName('page'.$anum));
1172              $tpl->parse('cB', 'categoryBlock', true);
1173          break;
1174          case '4':
1175              $anum = 4;
1176              $tpl->setVar('selectorinitpage', 'display: block;');
1177              $tpl->setVar('wizhelp', Widget::getWizardHelp('From this page you can set options for creating simple workflow with form data'));
1178              $tpl->setVar('ceB','');
1179  
1180              $f->field('Upon submission make this a workflow?');
1181              $f->checkbox('saveToWorkflow', @$this->settingsVars['saveToWorkflow'], '' );
1182              $f->field('Workflow ID');
1183              $f->html("<span style='font-weight:bold;'>" . ((isset($this->settingsVars['workflowID'])) ? $this->settingsVars['workflowID'] : 'Unset') . "</span>");
1184              $f->hidden('cv_prevpage', '4' );
1185              $f->field('Approver\'s username.');
1186              $f->text('workflowApprover', $this->settingsVars['workflowApprover']);
1187              $f->field('Approver query (optionally select the approver using a query).');
1188              $f->textarea('workflowApproverQuery', $this->settingsVars['workflowApproverQuery'], 3, 15);
1189              $f->field('Wait to perform data storage queries till approval?');
1190              $f->checkbox('workflowQueryWait', @$this->settingsVars['workflowQueryWait'], '' );
1191  
1192              $tpl->setVar('buttons', '<br>'.$finalizeButton. '<div style="float:right;">'
1193              . Widget::button('primary', 'Next', 'next_button', "document.getElementById('cv_curpage').value = 5; document.EmailFeedback.submit(); ")
1194              . '</div><div style="float:right;">' .Widget::button('primary', 'Previous', 'previous_button', "document.getElementById('cv_curpage').value = 3; document.EmailFeedback.submit(); ")
1195              . "</div><div style='clear:both;'>&nbsp;</div>");
1196              $tpl->setVar('entrydesc',$f->get());
1197              $tpl->setVar('entrytitle', '');
1198              $tpl->parse('ceB', 'categoryEntryBlock', true);
1199              $tpl->setVar('divpageid', $this->paramName('page'.$anum));
1200              $tpl->parse('cB', 'categoryBlock', true);
1201          break;
1202          case '5':
1203              $att_vertical = array('style' => 'vertical-align:top;');
1204              $anum = 5;
1205              $tpl->setVar('selectorinitpage', 'display: block;');
1206              $tpl->setVar('wizhelp', Widget::getWizardHelp('From this page you can set options for the functionality of the form as'
1207              .' well as provide a message to display to users after the form has been submitted.') );
1208              $tpl->setVar('ceB','');
1209              //change page submitted to based on whether form is submitted to a noncaravel site or not
1210              if ( $this->settingsVars['submitToDifferentPage'] != 'on')
1211                  {
1212                  $tpl->setVar('buttons', '<br>' . $finalizeButton . '<div style="float:right;">'
1213                  .'</div><div style="float:right;">' 
1214                  .Widget::button('primary', 'Previous', 'previous_button', "document.getElementById('cv_curpage').value = 4;     document.EmailFeedback.submit(); ")
1215                  ."</div>");
1216                  }
1217              else
1218                  {
1219                  $tpl->setVar('buttons', '<br>' . $finalizeButton . '<div style="float:right;">'
1220                  .Widget::button('primary', 'Previous', 'previous_button', "document.getElementById('cv_curpage').value = 0;     document.EmailFeedback.submit(); ")
1221                  .'</div>');
1222                  }
1223              $f->field('Make submissions unique (only one per user, requires the form be login only)');
1224              $f->hidden('cv_prevpage', '5' );
1225              $f->checkbox('forceUnique', @$this->settingsVars['forceUnique'], 'Force uniqueness');    
1226              $f->field('Reset Button?');
1227              $f->checkbox('showReset', @$this->settingsVars['showReset'], 'Show the reset button.');
1228              $f->field('Allow immediate resubmit?');
1229              $f->checkbox('displayThank', isset($this->settingsVars['displayThank']) ? $this->settingsVars['displayThank'] : 1, '');
1230              $f->field('Thank You Message:');
1231              $f->textarea('finalMessage', @$this->params['finalMessage']);
1232              $f->field('Submit Button Title:');
1233              $f->text('submitTitle', @$this->settingsVars['submitTitle'],20);
1234              $f->field('Custom Javascript for Submit Button:');
1235              $f->text('submitJavascript', $this->settingsVars['submitJavascript'] );
1236              
1237              
1238              $f->endSection();
1239              $tpl->setVar('entrydesc',$f->get());
1240              $tpl->setVar('entrytitle', '');
1241              $tpl->parse('ceB', 'categoryEntryBlock', true);
1242              $tpl->setVar('divpageid', $this->paramName('page'.$anum));
1243              $tpl->parse('cB', 'categoryBlock', true);
1244          break;
1245          }
1246          $menu = Widget::getWizardMenu($listitems, 1, $this->httpVars['cv_curpage'], $listonclick, $listattrs);
1247          $tpl->setVar('menu', $menu);
1248          $tpl->setVar('formlookbegin', Widget::form_look('', '', 'beginning'));
1249          $tpl->setVar('formlookend', Widget::form_look('', '', 'end'));
1250          return $tpl->subst('main');
1251  
1252          }        
1253          
1254  	function copySite($ldap, $srcdn, $destdn, &$cbs, $init = 0, $olddn) {
1255          // update saveToFileDirectory for the new site
1256          foreach ($cbs as $cb) {
1257              $res = $ldap->search('(objectclass=*)', array('mnappparam'), $cb, LDAP_SCOPE_BASE);
1258              if(mnError::isError($res))
1259                  { return new mnError('EmailFeedback::copySite(): ' . $res->getMessage(), __FILE__, __LINE__); }
1260              $param = isset($res[0]['mnappparam']) ? $res[0]['mnappparam'] : array();
1261              array_shift($param);
1262              $param = @Utility::processParams($param);
1263              if (isset($param['saveToFileDirectory'])) {
1264                  if ($olddn)
1265                      $param['saveToFileDirectory'] = str_replace($olddn, $destdn, $param['saveToFileDirectory']);
1266                  else
1267                      $param['saveToFileDirectory'] = str_replace($srcdn, $destdn, $param['saveToFileDirectory']);
1268                  if (!$ldap->dnExists($param['saveToFileDirectory'])) {
1269                      mnDebug("EmailFeedback::copySite(): NOTICE! ". $param['saveToFileDirectory'] ." doesn't exist.  Content Block ($cb) set to nothing.");
1270                      $param['saveToFileDirectory'] = '';
1271                  }
1272              }     
1273              mnDebug("EmailFeedback::copySite(): param now : ". Utility::getVal($param));
1274              $attrs = array();
1275              $attrs['mnappparam'] = Utility::packageParams($param);
1276              $res = $ldap->replace($cb, $attrs);
1277              if(mnError::isError($res))
1278                  { return new mnError('EmailFeedback::copySite(): ' . $res->getMessage(), __FILE__, __LINE__); }
1279          }
1280      }
1281          
1282  } // end class EmailFeedback
1283  ?>

title

Description

title

Description

title

Description

title

title

Body