[ PHPXref.com ] [ Generated: Sun Jul 20 19:05:01 2008 ] [ OneOrZero 1.6.3 ]
[ Index ]     [ Variables ]     [ Functions ]     [ Classes ]     [ Constants ]     [ Statistics ]

title

Body

[close]

/kbase/ -> edit.php (source)

   1  <?php
   2  
   3  /**

   4  * file:    edit.php

   5  * 

   6  *         This file is used for editing existing entries in the knowledge base provided an id number.

   7  * 

   8  /***************************************************************************

   9  *  This program is free software; you can redistribute it and/or

  10  *  modify it under the terms of the GNU General Public

  11  *  License as published by the Free Software Foundation; either

  12  *  version 2.1 of the License, or (at your option) any later version.

  13  *

  14  *  This program is distributed in the hope that it will be useful,

  15  *  but WITHOUT ANY WARRANTY; without even the implied warranty of

  16  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU

  17  *  General Public License for more details.

  18  *

  19  *  You should have received a copy of the GNU General Public

  20  *  License along with This program; if not, write to:

  21  *    Free Software Foundation, Inc.

  22  *    59 Temple Place

  23  *    Suite 330

  24  *    Boston, MA  02111-1307  USA

  25  *

  26  * Copyright 2005 One or Zero

  27  * info@oneorzero.com

  28  * http://www.oneorzero.com

  29  * Developers: OneOrZero Team / Contributors: OneOrZero Community

  30  ****************************************************************************/ 
  31  
  32  $time = time();
  33  
  34      if ($_POST[delete] == "$lang_delete $lang_entry" && !isset($_POST[ok])) {
  35          switch ($kpurge) {
  36              case ("Always"):
  37                  $ok = $lang_delete;
  38                  break;
  39              case ("Never"):
  40                  $ok = $lang_save;
  41                  break;
  42              case ("Prompt"): 
  43                  // prompt user to delete any associated files:

  44                  $sql = "SELECT id, filename from $attachments_table where kid='$_POST[id]'";
  45                  $result = $db->query($sql);
  46                  $attach = $db->fetch_array($result);
  47                  if ($attach && !isset($ok)) { // if we're here, then there are attachments associated with this entry.
  48                      echo "<form action=\"?t=kbase&act=kedit\" method=post>";
  49                      startTable("$lang_delete $lang_attachment", "left", 100, 1);
  50                      echo "<tr><td class=back><br>";
  51                      echo $lang_deletekattachment1 . "&nbsp; <b> " . substr($attach[filename], 14) . " </b> " . $lang_deletekattachment2;
  52                      echo "<br><br>";
  53                      echo "<input type=hidden name=delete value=\"$lang_delete $lang_entry\">";
  54                      echo "<input type=hidden name=id value=$_POST[id]>";
  55                      echo "<input type=submit name=ok value=\"$lang_delete\"> &nbsp;&nbsp; ";
  56                      echo "<input type=submit name=ok value=\"$lang_save\">";
  57                      echo "</form></td></tr>";
  58                      endTable();
  59                      $break = 'yes';
  60                  } else {
  61                      $sql = "DELETE from $kbase_table where id='$_POST[id]'";
  62                      $db->query($sql);
  63                      $break = 'yes';
  64                      //if from control.php then route users to the kbase edit page, else back to index

  65                         if (eregi("control.php",$_SERVER[PHP_SELF])) {
  66                             printSuccess($lang_action_completed, 100, 'control.php?t=kbase&act=kedit'); }
  67                         else {
  68                             printSuccess($lang_action_completed, 100, $_SERVER[PHP_SELF].'?t=kbase'); }
  69                      exit;                  
  70                  } 
  71                  break;
  72          }
  73      }
  74          
  75  if (!isset($_GET[id]) && $_POST[edit] == '' && !isset($_POST[delete]) && $message !=1) {
  76      // lets display all of the questions first.

  77      switch ($_GET[order]){
  78          default:
  79              $sql = "SELECT id, platform, category, question from $kbase_table order by platform, category, question asc";
  80              break;
  81          case("category"):
  82              $sql = "SELECT id, platform, category, question from $kbase_table order by category, question, popularity asc";
  83              break;
  84          case("question"):
  85              $sql = "SELECT id, platform, category, question from $kbase_table order by question, popularity asc";
  86              break;
  87      } 
  88      echo '<table class=border cellSpacing=0 cellPadding=0 width="100%" align=center border=0>
  89              <tr> 
  90               <td> 
  91                                  <table cellSpacing=1 cellPadding=5 width="100%" border=0><tr><td class=hf >';
  92  
  93      echo "<form action=\"control.php?t=kbase&act=kdel\" method=post>";
  94      $location = $_SERVER[HTTP_REFERER] . "&act=kedit";
  95      echo "<input type=hidden name=location value=\"" . $location . "\">";
  96  
  97      echo "<b><a href=\"control.php?t=kbase&act=kedit&order=platform\" class=hf>$lang_platform</a></b></td>";
  98      echo "<td class=hf ><b><a href=\"control.php?t=kbase&act=kedit&order=category\" class=hf>$lang_category</a></b></td>";
  99      echo "<td class=hf ><b><a href=\"control.php?t=kbase&act=kedit&order=question\" class=hf>$lang_question</a></b></td></tr>";
 100  
 101      $result = $db->query($sql);
 102      $i = 0;
 103      while ($row = $db->fetch_array($result)) {
 104          if ($i % 2 == 0) {
 105              echo '<tr><td class=back>' . htmlspecialchars($row['platform']) . '</td><td class=back>' . htmlspecialchars($row['category']);
 106              echo '</td><td class=back><a href="control.php?t=kbase&act=kedit&id=' . $row['id'] . '">';
 107              echo $row['question'] . '</a></td></tr>';
 108          } else {
 109              echo '<tr><td class=back2>' . htmlspecialchars($row['platform']) . '</td><td class=back2>' . htmlspecialchars($row['category']);
 110              echo '</td><td class=back2><a href="control.php?t=kbase&act=kedit&id=' . $row['id'] . '">';
 111              echo htmlspecialchars($row['question']) . '</td></tr>';
 112          } 
 113          $i++;
 114      } 
 115  
 116      echo "</td></tr></table></table>";
 117   $break = 'yes';
 118  } else { // if id is set, we are already editing an entry.
 119      if ($_POST[edit] == "$lang_edit $lang_entry") {
 120  
 121          // update the database according to the id

 122          $question = stripScripts($_POST[question]);
 123          $answer = stripScripts($_POST[answer]);
 124          $keywords = stripScripts($_POST[keywords]);
 125          $platform = stripScripts($_POST[platform]);
 126          $category = stripScripts($_POST[category]);
 127          $sql = "UPDATE $kbase_table set platform='$platform', category='$category', question='$question', answer='$answer', keywords='$keywords', viewable_by='$_POST[view]', edited_by='$_SESSION[user]', last_edited='$time' where id='$_POST[id]'";
 128          $db->query($sql); 
 129          // if a file is attached...

 130          if ($enable_kattachments == 'On') {
 131              if ($_FILES[SelectedFile][name] != "none" && $_FILES[SelectedFile][name]) { // we have a file so we need to do something with it
 132              $mtime = explode(" ", microtime());
 133              $mtime = $mtime[1].substr($mtime[0],5,3);
 134              //Upload file and return new file name

 135              $file_name = uploadAttachment($max_attachment_size, 'SelectedFile',$mtime);
 136              $file_type = $_FILES['SelectedFile']['type'];
 137              $file_size = $_FILES['SelectedFile']['size'];
 138  
 139  
 140  //                $attachment = addslashes(fread(fopen($attach, "rb"), filesize($attach)));

 141  //                if ($attach_type == "application/x-gzip-compressed") {

 142  //                    $attachment = base64_decode($attachment);

 143  //                } 

 144                   $sql = "INSERT into $attachments_table VALUES(NULL, $_POST[id], NULL" .
 145                           ", '$file_name', '$file_upload_directory', '$file_type', '$file_size', NULL, 0, '$_SESSION[user]', $time)";
 146                  $db->query($sql); //insert all info about the attachment into the database.

 147              } 
 148          } 
 149          //if from control.php then route users to the kbase edit page, else back to index

 150             if (eregi("control.php",$_SERVER[PHP_SELF])) {
 151                 printSuccess($lang_action_completed, 100, 'control.php?t=kbase&act=kedit'); }
 152             else {
 153                 printSuccess($lang_action_completed, 100, $_SERVER[PHP_SELF].'?t=kbase'); }
 154          exit;
 155      } 
 156  
 157      if ($_GET[delete] == "attachment") {
 158          //delete physical file, warn if error

 159          $sql = "SELECT * FROM $attachments_table where kid=$_GET[id]";
 160          $result = $db->query($sql);
 161          $row = $db->fetch_array($result);
 162          if (!unlink($row[filelocation] . $row[filename])){
 163              printSuccess($lang_attachment_deleted_nofile, 100, '');
 164          }
 165          //delete attachment from kbase

 166          $sql = "DELETE from $attachments_table where kid=$_GET[id]";
 167          $db->query($sql);
 168      } 
 169  
 170      if ($ok == $lang_delete || $_POST[ok] == $lang_delete) {
 171              //delete attach if there is one, warn if error

 172              $sql = "SELECT * FROM $attachments_table where kid=$_POST[id]";
 173              $result = $db->query($sql);
 174              if ($row = $db->fetch_array($result)) {
 175                  if (!unlink($row[filelocation] . $row[filename])){
 176                      $delete_message= "$lang_attachment_deleted_nofile<br>";
 177                  }
 178              }
 179              $sql = "DELETE from $attachments_table where kid='$_POST[id]'";
 180              $db->query($sql); //delete the attachment associated with the kb entry.

 181              $sql = "DELETE from $kbase_table where id='$_POST[id]'";
 182              $db->query($sql);
 183              unset($_POST[id]);
 184                //if from control.php then route users to the kbase edit page, else back to index

 185                 if (eregi("control.php",$_SERVER[PHP_SELF])) {
 186                     printSuccess($delete_message . $lang_action_completed, 100, 'control.php?t=kbase&act=kedit'); }
 187                 else {
 188                     printSuccess($delete_message . $lang_action_completed, 100, $_SERVER[PHP_SELF].'?t=kbase'); }
 189              exit;
 190              } 
 191      if ($ok == $lang_save || $_POST[ok] == $lang_save) {
 192              $sql = "DELETE from $kbase_table where id='$_POST[id]'";
 193              $db->query($sql);
 194              unset($_POST[id]);
 195              //if from control.php then route users to the kbase edit page, else back to index

 196                 if (eregi("control.php",$_SERVER[PHP_SELF])) {
 197                     printSuccess("$lang_action_completed", 100, 'control.php?t=kbase&act=kedit'); }
 198                 else {
 199                     printSuccess("$lang_action_completed", 100, $_SERVER[PHP_SELF].'?t=kbase'); }
 200              exit;
 201                  } 
 202      } 
 203  
 204      if ($break != 'yes' && $message !=1) {
 205  
 206          $sql = "SELECT * from $kbase_table where id=$_GET[id]";
 207  
 208          $result = $db->query($sql);
 209          $info = $db->fetch_array($result);
 210  
 211          echo "<form action=\"?t=kbase&act=kedit\" method=post enctype=\"multipart/form-data\">";
 212  
 213          startTable("$lang_edit $lang_entry", "center", 100, 4);
 214          echo '<tr><td class=back2 align=right width=27%>' . $lang_platform . ':</td> <td class=back>';
 215          echo '<select name=platform>';
 216          createPlatformMenu();
 217          echo '</select></td>';
 218          echo '<td align=right class=back2 width=27%>' . $lang_category . ': </td> <td class=back>';
 219          echo '<select name=category>';
 220          createKCategoryMenu();
 221          echo '</select></td></tr>';
 222          echo '<tr><td class=back2 align=right width=27%>
 223              ' . $lang_question . ': </td><td colspan=3 class=back><input type=text size=60 name=question value="' . $info['question'] . '"></input></td></tr>';
 224          echo '<tr valign=top><td align=right class=back2 width=27%>
 225              ' . $lang_answer . ': </td><td colspan=3 class=back> <textarea name=answer rows=15 cols=60>' . $info['answer'] . '</textarea><br></td></tr>';
 226          echo '</td></tr>';
 227          echo '<tr><td class=back2 align=right width=27%>' . $lang_keywords . ': <font size=1>(' . $lang_sepbycomma . ')</font></td> <td colspan=3 class=back>';
 228          echo '<input type=text size=60 name=keywords value=' . $info['keywords'] . '></input></td></tr>';
 229          echo '<tr><td class=back2 align=right width=27%>' . $lang_viewableby . ':</td> <td colspan=3 class=back>';
 230          echo '<select name=view>';
 231          createViewableByMenu();
 232          echo '</select></td></tr>';
 233          if ($enable_kattachments == 'On') {
 234              if ($_GET[id] != '') {
 235                  $sql = "SELECT filename from $attachments_table where kid=$_GET[id]";
 236              } else {
 237                  $sql = "SELECT filename from $attachments_table where kid=$_POST[id]";    
 238              }
 239              $result = $db->query($sql);
 240              $row = $db->fetch_array($result);
 241              if ($row[filename] != '') {
 242                  echo '<tr><td class=back2 align=right width=27%>' . $lang_attachment . ':</td><td colspan=3 class=back>';
 243                  echo substr($row[filename], 14) . "&nbsp;&nbsp;&nbsp;&nbsp; ";
 244                  if (eregi("admin", $_SERVER[PHP_SELF]))
 245                      echo "<a href=\"$admin_site_url/control.php?t=kbase&act=kedit&delete=attachment&id=$_GET[id]\"> $lang_delete</a>?";
 246                  else
 247                      echo "<a href=\"$supporter_site_url/index.php?t=kbase&act=kedit&delete=attachment&id=$_GET[id]\"> $lang_delete</a>?";
 248  
 249                  echo "</td></tr>";
 250              } else {
 251                  echo '<input type=hidden name="MAX_FILE_SIZE" value=' . $max_attachment_size . '>';
 252                  echo '<tr><td class=back2 align=right width=27%>' . $lang_addattachment . ':</td>';
 253                  echo '<td colspan=3 class=back> <input type="file" name="SelectedFile" size=35>';
 254                  echo "</td></tr>";
 255              } 
 256          } 
 257  
 258          endTable();
 259  
 260          echo "<input type=hidden name=id value=$_GET[id]>";
 261          echo "<center> <input type=submit name=edit value=\"$lang_edit $lang_entry\"> &nbsp;&nbsp;";
 262          echo "<input type=submit name=delete value=\"$lang_delete $lang_entry\"></center></form>";
 263      } 
 264  //} 

 265  
 266  ?>


[ Powered by PHPXref - Served by Debian GNU/Linux ]