My code is about In-Place Editing.  Originally, I have got several
posts.  And each post is within a fieldset.  The post title is
included in the <legend></legend> and the post content is in the
field.  And the code is like this.

// test.php---In-Place Editing
<head>
<title>Edit in place</title>
<script type="text/javascript"
   src="javascript/prototype.js"></script>
<script type="text/javascript"
   src="javascript/scriptaculous.js?load=effects,controls"></script>
<script type="text/javascript">
window.onload = function() {

        for(var i=0;;i++)
        {
                if($('theTitle'+i) && $('postid'+i)){
                   new Ajax.InPlaceEditor(
                      'theTitle'+i,
                      'answer.php?ident='+i+'&postid='+$('postid'+i).value,
                      {
                         formId: 'whatever',
                         okText: 'Edit !',
                         cancelText: 'Cancel'
                      }
                   );
           }
           if($('theCont'+i) && $('postid'+i)){
                   new Ajax.InPlaceEditor(
                      'theCont'+i,
                      'answer.php?ident='+i+'&postid='+ $('postid'+i).value,
                      {
                         formId: 'whatever',
                         okText: 'Edit!',
                         cancelText: 'Cancel'
                      }
                   );
           }
           if(!$('theTitle'+i) && !$('theCont'+i)){ break;}

   }

}
</script>
</head>
<body>
<p>Click over the "Click me!" text and then change text
and click OK.</p>
<p></p>
    <?php
        $v...@file_get_contents("http://xxx.edu/getPost.py?
author=1234&type=html");
        $var=explode("</li>", $var);

        $varLen = count($var);

                for($i = $varLen-2; $i>=0;$i--){

                                echo '<fieldset>';

                                #finding title:
                                if(preg_match("/Title:/",$var[$i])){
                                        $tlen =strpos($var[$i],'Title:')+11;
                                        $clen = strpos($var[$i],'Content:')-10;

                                        $tname = 
substr($var[$i],$tlen,($clen-$tlen));
                                        echo '<legend 
id="theTitle'.$i.'">'.$tname.'</legend>';
                                        echo '<p></p>';
                            }

                                #finding Content:
                                if(preg_match("/Content:/",$var[$i])){
                                        $ctlen = strpos($var[$i],'Content:')+13;
                                        $ctlast = strripos($var[$i],'<br />');

                                        $cont = 
substr($var[$i],$ctlen,($ctlast-$ctlen));
                                        $cont = html_entity_decode($cont);
                                        echo '<p 
id="theCont'.$i.'">'.$cont.'</p>';
                            }

                                #finding Updated:
                                if(preg_match("/Updated:/",$var[$i])){
                                        $uppos =strpos($var[$i],'Updated:')+13;
                                        $uplen = strpos($var[$i],'Title:')-4;

                                        #date
                                        $up = 
substr($var[$i],$uppos,($uplen-$uppos));
                                        $upfinal = 
substr($up,0,(strpos($up,'T')));

                                        #time
                                        $upT = strpos($up,'T');
                                        $upDot = strripos($up,'.');
                                        $uptime = 
substr($up,$upT+1,($upDot-1)-$upT);

                                        echo 'updated on'.$upfinal.' '.$uptime;
                                        echo '<p></p>';
                            }

                                #finding post id
                                if(preg_match("/Id:/",$var[$i])){

                                        $idpos = strpos($var[$i],'Id:')+9;
                                        $idlast = strpos($var[$i],'Updated')-10;

                                        $idis = 
substr($var[$i],$idpos,($idlast-$idpos));

                            }

                        echo '</fieldset>';
                        echo '<label for="id"><input type="hidden" 
id="postid'.$i.'"
value="'.$idis.'"'.' /></label>';
                        echo '<a href="edpost.php?id='.$idis.'">Edit</a>';
                        echo '<hr width="100%" size="1" />';
                        echo '<p></p>';

                }

                        #find id;
                        function searchID($var){
                                $idpos = strpos($var,'Id:')+9;
                                $idlast = strpos($var,'Updated')-10;
                                $idis = substr($var,$idpos,($idlast-$idpos));
                                return $idis;
                        }
        ?>
</body>
</html>

/* For the above code, it is getting posts from the Server and I make
each post into order.  What I am trying to do is that the user can
either edit the Title or the Content, then the post title or content
will be modified and display immediately by using Ajax. (postid is
need to pass to answer.php in order to modify the post title or
content
The post html code is like:
<ul>
   <li>Student id: XXX <br />Title: XXX  <br /> Content: XXX <br />
ID: XXX<br /> Updated: XXX<br /></li>
   <li>Student id: XXX <br />Title: XXX  <br /> Content: XXX <br />
ID: XXX<br /> Updated: XXX<br /></li>
   <li>Student id: XXX <br />Title: XXX  <br /> Content: XXX <br />
ID: XXX<br /> Updated: XXX<br /></li>
</ul>

and I get the Title and insert it wihtin <legend>Title</legend> and
the content is following it .
*/

For the answer.php, it is like:

// answer.php
<?php

  if( isset($_REQUEST["value"]) )
  {
         if($_GET["ident"]){
                $getVal = $_REQUEST["value"];

                $geti = $HTTP_GET_VARS["ident"];

                if($geti%2 ==0){
            //$getTitle = $_REQUEST["title"];
                        $getPostId = $HTTP_GET_VARS["postid"];
                        echo $getPostId;

                        $pid = $_REQUEST["postid"];
                        echo $pid;
                //echo $getTitle;

                # Edit the post and get the new id
                        
$newpostid=file_get_contents("http://xxx.edu/editPost.py?id=
$getPostId&title=$getVal");

                        //echo $newpostid;
                        $getnewpost = 
file_get_contents("http://xxx.edu/getPost.py?
author=1234&id=$newpostid&type=html");
                        //echo $getnewpost;
                        $tname = searchTitle($getnewpost);

                        echo $tname;
                }
                else{
                    $getPostId = $HTTP_GET_VARS["postid"];

                        
$newpostid=file_get_contents("http://xxx.edu/editPost.py?id=
$getPostId&title=$getVal");

                        //echo $newpostid;
                        $getnewpost = 
file_get_contents("http://xxx.edu/getPost.py?
author=1234&id=$newpostid&type=html");

                        $tcont = searchCont($getnewpost);


                        echo $tcont;

                }
        }
  }

        #find title
        function searchTitle($var){
                        $tlen =strpos($var,'Title:')+11;
                        $clen = strpos($var,'Content:')-10;
                        $tname = substr($var,$tlen,($clen-$tlen));
                        return $tname;
        }

        #finding student id:
        function searchSID($var){
                        $tlen =strpos($var,'Author:')+13;
                        $clen = strpos($var,'Id:')-10;
                        $sid = substr($var,$tlen,($clen-$tlen));
                        return $sid;
        }

        #finding Content:
        function searchCont($var){
                        $ctlen = strpos($var,'Content:')+13;
                        $ctlast = strripos($var,'<br />');
                        $cont = substr($var,$ctlen,($ctlast-$ctlen));
                        $cont = html_entity_decode($cont);
                        return $cont;
        }


        #finding id
        function searchID($var){
                        $idpos = strpos($var,'Id:')+9;
                        $idlast = strpos($var,'Updated')-10;
                        $idis = substr($var,$idpos,($idlast-$idpos));
                        return $idis;
        }
?>

The above code is to get the post id with either title or content.
However, when the program is run, it will always return the title
changed or undefined.  Because in test.php, the element id theTitle1
will be with the element id theCont1.

My question is, how can I check whether the user click the title or
the content?  If he clicks the content, modify it, the new content
will be sent and updated.  And if he clicks the title, modify it, the
new title will be sent and updated.

I know that my code is tedious and may not be friendly.  I am a newbie
to Ajax and have known little about PHP.  Are there any better way to
change to program?  Actually, there are samples when user click over
the div, he can modify both Title and Content.  But I don't know how
can do that in this way.  Any help would be appreciated!  Thanks.

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Prototype & script.aculo.us" group.
To post to this group, send email to prototype-scriptaculous@googlegroups.com
To unsubscribe from this group, send email to 
prototype-scriptaculous+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/prototype-scriptaculous?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to