Going one step further, getting pop up onclick to reply back to host page

Discussion in 'PHP' started by Negative, Aug 2, 2007.

  1. #1
    Hello again, another brickwall here.

    I have a form with a link to a popup. When the link is click a little pop up shows up with images inside. What I am trying to do is use the coding of the forum for these "smileys" as well as my new pop up code to make it where you click the "smiley" and it's filename or some shortcut code is inserted into the form...

    here is my current php forum:

    
    <?php
    
    //  Define  the  full  path  to  your  folder,  shouldn't  need  changing
    $path  =  "./";
    
    //  Open  the  folder
    $dir_handle  =  @opendir($path)  or  die("Unable  to  open  folder");
    
    ?>
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    <meta http-equiv=Content-Type content="text/html;  charset=ISO-8859-1">
    <title>Adult Smileys</title>
    <link rel="stylesheet" type="text/css" href="http://outsidetheurl.com/includes/outside.css">
    </head>
    
    <body>
    <table border="1">
    <tr>
    
    <?php
    global $context, $settings, $options, $txt, $scripturl, $modSettings;
    $imagecount = 0;
    
    //  Loop  through  the  files
    while (false  !==  ($file  =  readdir($dir_handle)))
    {
        //  Prevent  this  file  itself  being  shown
        //  If  you  want  it  to  not  display  any  other  files
        //  enter  more  of  these
        if(!in_array($file, array("./", ".", "..", "index.php")))
        {
            $fullpath = $path . basename($file);
            
            //  Display  the  results
            echo "\t" . '<td><a href="javascript:void(0);" onclick="window.opener.replaceText(&quot; \' + $file + \'&quot;, window.opener.document.forms.', $context['post_form'], '.', $context['post_box_name'], '); window.focus(); return false;"><img src="' . $fullpath .'" border="0" /></a> </td>' . "\n";
        
            if (++$imagecount % 3 == 0) // 3 for 3 columns
            {
                echo "</tr>\n<tr>\n";
            }
        }
    }
    
    //  Close  it
    closedir($dir_handle);
    
    ?>
    </tr>
    </table>
    </body>
    </html>
    
    PHP:
    Here is the code (php/JS mix) that make the functions work in other places:

    
    		// If the smileys popup is to be shown... show it!
    		if (!empty($context['smileys']['popup']))
    			echo '
    					<a href="javascript:moreSmileys();">[', $txt['more_smileys'], ']</a>';
    
    
    	// If there are additional smileys then ensure we provide the javascript for them.
    	if (!empty($context['smileys']['popup']))
    	{
    		echo '
    			<script language="JavaScript" type="text/javascript"><!-- // --><![CDATA[
    				var smileys = [';
    
    		foreach ($context['smileys']['popup'] as $smiley_row)
    		{
    			echo '
    					[';
    			foreach ($smiley_row['smileys'] as $smiley)
    			{
    				echo '
    						["', $smiley['code'], '","', $smiley['filename'], '","', $smiley['js_description'], '"]';
    				if (empty($smiley['last']))
    					echo ',';
    			}
    
    			echo ']';
    			if (empty($smiley_row['last']))
    				echo ',';
    		}
    
    		echo '];
    				var smileyPopupWindow;
    
    				function moreSmileys()
    				{
    					var row, i;
    
    					if (smileyPopupWindow)
    						smileyPopupWindow.close();
    
    					smileyPopupWindow = window.open("", "add_smileys", "toolbar=no,location=no,status=no,menubar=no,scrollbars=yes,width=480,height=220,resizable=yes");
    					smileyPopupWindow.document.write(\'<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">\n<html>\');
    					smileyPopupWindow.document.write(\'\n\t<head>\n\t\t<title>', $txt['more_smileys_title'], '</title>\n\t\t<link rel="stylesheet" type="text/css" href="', $settings['theme_url'], '/style.css" />\n\t</head>\');
    					smileyPopupWindow.document.write(\'\n\t<body style="margin: 1ex;">\n\t\t<table width="100%" cellpadding="5" cellspacing="0" border="0" class="tborder">\n\t\t\t<tr class="titlebg"><td align="left">', $txt['more_smileys_pick'], '</td></tr>\n\t\t\t<tr class="windowbg"><td align="left">\');
    
    					for (row = 0; row < smileys.length; row++)
    					{
    						for (i = 0; i < smileys[row].length; i++)
    						{
    							smileys[row][i][2] = smileys[row][i][2].replace(/"/g, \'&quot;\');
    							smileyPopupWindow.document.write(\'<a href="javascript:void(0);" onclick="window.opener.replaceText(&quot; \' + smileys[row][i][0] + \'&quot;, window.opener.document.forms.', $context['post_form'], '.', $context['post_box_name'], '); window.focus(); return false;"><img src="', $settings['smileys_url'], '/\' + smileys[row][i][1] + \'" alt="\' + smileys[row][i][2] + \'" title="\' + smileys[row][i][2] + \'" style="padding: 4px;" border="0" /></a> \');
    						}
    						smileyPopupWindow.document.write("<br />");
    					}
    
    					smileyPopupWindow.document.write(\'</td></tr>\n\t\t\t<tr><td align="center" class="windowbg"><a href="javascript:window.close();\\">', $txt['more_smileys_close_window'], '</a></td></tr>\n\t\t</table>\n\t</body>\n</html>\');
    					smileyPopupWindow.document.close();
    				}
    			// ]]></script>';
    
    PHP:
    Now that code is the original code, which I have changed a bit to get my pop up to show the directory the link it pointed too (basically I took out all the document.write's etc.

    What I have now is the pop up comes up, shows all the images in the table and they are all clickable (javascript:void(); )but nothing happens when you click on them.

    I just want SOMETHING to be entered into the form. If I can get that I am sure I could tweak it to where I need it to be.

    Any ideas?
     
    Negative, Aug 2, 2007 IP