Location: PHPKode > projects > Private Movie Database > pmdb_V_B_0.3.0/code/pmdb/forum/newpost.inc
<?
/* filename: newpost.inc
 * project: movie database
 * author: lex alexander
 * originally coded: 11.07.2003
 * last modified: 14.07.2003
 * version V0.2
 * usage: write new post
 */
$uid=$_COOKIE["pmdb_uid"];

if(!empty($_POST))
{
  $ptitle = $_POST["ptitle"];
  $ptext = $_POST["ptext"];
  $tid = $_POST["tid"];
  $pnr = $_POST["pnr"];
  $fid = $_POST["fid"];
  $edit = $_POST["edit"];
  $pid = $_POST["pid"];

  $ptitle=str_replace("'", "\'", $ptitle);
  $ptext=str_replace("'", "\'", $ptext);

  $time = date("H:i d.m.Y ");

  if($tid == false)
  {
    //start new thread
    $get_future_pnr="SELECT MAX(pid) as fpid FROM tb_post";
    $result_future_pnr = doQuery($get_future_pnr);
    extract(mysql_fetch_array($result_future_pnr));
    $fpid++;

    $insert_thread="INSERT INTO tb_thread (r_pid, r_lpid, r_fid) VALUES ('$fpid','$fpid','$fid')";
    mysql_query($insert_thread)
      or die(INSERT_FAIL);
    //get thread id
    $get_thread_id="SELECT tid as r_tid, faq FROM tb_thread, tb_forum WHERE r_pid = '$fpid' AND r_fid = '$fid'";
    $result_thread_id = doQuery($get_thread_id);
    extract(mysql_fetch_array($result_thread_id));

    if($faq == "0")
      $ptext=nl2br($ptext);

    //insert post
    $insert_post="INSERT INTO tb_post (ptitle, ptext, pnr, time, r_tid, r_uid) VALUES ('$ptitle', '$ptext', '1', '$time', '$r_tid', '$uid')";
    mysql_query($insert_post)
      or die (INSERT_FAIL.$insert_post);

    //check post id
    $get_pid="SELECT pid FROM tb_post WHERE ptitle = '$ptitle' AND ptext = '$ptext' AND pnr = 1 AND r_tid = '$r_tid'";
    $result_pid = doQuery($get_pid);
    extract(mysql_fetch_array($result_pid));

    if($fpid != $pid)
    {
      //update thread
      $update_thread = "UPDATE tb_thread SET r_pid = '$pid', r_lpid = '$pid' WHERE tid = '$tid'";
      mysql_query($update_thread)
        or die(UPDATE_FAIL);
    }
    refresh("index.php?page=thread&amp;fid=$fid&amp;tid=$r_tid");
  }
  else if($edit != "true")
  {
     $get_faq="SELECT faq from tb_forum WHERE fid = '$fid'";
     $result_faq=doQuery($get_faq);
     extract(mysql_fetch_array($result_faq));

     if($faq == "0")
      $ptext=nl2br($ptext);
    //post follwo up
    $pnr++;
    $insert_post="INSERT INTO tb_post (ptitle, ptext, pnr, time, r_tid, r_uid) VALUES ('$ptitle', '$ptext', '$pnr', '$time', '$tid', '$uid')";
    mysql_query($insert_post)
      or die(INSERT_FAIL.$insert_post);

    $get_pid="SELECT pid FROM tb_post WHERE ptitle = '$ptitle' AND ptext = '$ptext' AND pnr = '$pnr' AND r_tid = '$tid'";
    $result_pid = doQuery($get_pid);
    extract(mysql_fetch_array($result_pid));

    $update_thread="Update tb_thread SET r_lpid = '$pid' WHERE tid = '$tid'";
    print($update_thread);
    mysql_query($update_thread)
      or die(UPDATE_FAIL);
    refresh("index.php?page=thread&amp;fid=$fid&amp;tid=$tid");
  }
  else
  {
    //$ptext .= "<br /> <i>".EDIT_MESSAGE."</i>";
    $update_post="UPDATE tb_post SET ptext = '$ptext', ptitle='$ptitle' WHERE pid = '$pid'";
    print($update_post);
    mysql_query($update_post)
      or die (UPDATE_FAIL);
    refresh("index.php?page=thread&amp;fid=$fid&amp;tid=$tid");

  }
}
else
{
  if(REGISTER_GLOBALS == "off");
  {
    $tid = $_GET["tid"];
    $pnr = $_GET["pnr"];
    $fid = $_GET["fid"];
    $edit = $_GET["edit"];
    $pid = $_GET["pid"];
  }
  if($edit == true)
  {
    $get_post_data = "SELECT * FROM tb_post WHERE pid = '$pid'";
    $result_post_data = doQuery($get_post_data);
    extract(mysql_fetch_array($result_post_data));
  }
  ?>
  <h1><?=PMDB_FORUM;?></h1>

  <form action = "index.php?page=newpost" method = "post">
  <table>
  <tr>
    <td><?=THREAD_TITLE;?></td>
    <td><input type = "text" name = "ptitle" value = "<?=$ptitle;?>""/></td>
  </tr>
  <tr>
    <td><?=THREAD_TEXT;?></td>
    <td><textarea name = "ptext" rows = "10" cols = "60"/><?=$ptext;?></textarea></td>
  </tr>
  <tr>
    <td></td>
    <td><input type = "hidden" value = "<?=$tid;?>" name = "tid"/>
        <input type = "hidden" value = "<?=$fid;?>" name = "fid"/>
        <input type = "hidden" value = "<?=$pnr;?>" name = "pnr"/>
        <input type = "hidden" value = "<?=$edit;?>" name = "edit"/>
        <input type = "hidden" value = "<?=$pid;?>" name = "pid" />
        <input type = "submit" value = "<?=SUBMIT;?>"/></td>
  </tr>
  </table>
  </form>

  <?
  if($tid != false)
  {
    $get_post = "SELECT uname, ptitle, ptext FROM tb_post as p, tb_user as u WHERE p.r_tid = '$tid' and p.r_uid = u.uid order by pnr";
    $result_post = mysql_query($get_post)
      or die(QUERY_FAIL);

    $rows_post = mysql_num_rows($result_post);
    ?>
    <table>
    <tr>
      <td class = "movie-head"><?=POST_AUTHOR;?></td>
      <td class = "movie-head"><?=THREAD;?></td>
    </tr>

    <?
    while($rows_post = mysql_fetch_array($result_post))
    {
      if($data_count % 2 == 0)
      {
        $data = "movie-data1";
        $data_title = "movie-title1";
      }
      else
      {
        $data = "movie-data2";
        $data_title = "movie-title2";
      }
      $data_count++;
      ?>
      <tr>
        <td class = "<?=$data;?>">

           <?=$rows_post["uname"];?>

        </td>
        <td class = "<?=$data;?>">

        <h3><?=$rows_post["ptitle"];?></h3>
        <?=$rows_post["ptext"];?>

        </td>
        <td class = "<?=$data;?>"><?=$avg ;?></td>
      </tr>
      <?
    }
    ?>
    </table>
    <?
  }
}
Return current item: Private Movie Database