Jump to content

Help w/ adding to a function.


djhamer

Recommended Posts

Hi guys!  I need to add another "method" (#21) to my code to allow for an external link to open in full screen.  I have created the necessary javascript for this.  However, I keep breaking the PHP when attempting to adjust the syntax.  Below is the code for the function:

/* ----- Function createLink -----
				Creates the links for the Courses and Downloads.
				The different methods require different destinations
			   ------------------------------- */
			function createLink ($method, $capfilename, $text) {
				if ($method == 1) {
					echo '<li><a href="javascript:launchwin(\'viewer.php?capfilename='.$capfilename.'\', \'newwindow\',\'width=\'+(screen.width - 10)+\',height=\'+(screen.height - 30)+\',screenX=0,screenY=0,directories=0,fullscreen=1,location=0,menubar=0,scrollbars=0,status=0,toolbar=0\')">'.trim($text).'</a>    ';

					echo '<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=5,0,0,0" id="detection" width="10" height="10" align="middle">';
					echo '<param name="allowScriptAccess" value="sameDomain" /><param name="movie" value="detection.swf" /><param name="quality" value="high" /><param NAME="wmode" VALUE="transparent"><param name="bgcolor" value="#ffffff" />';
					echo '<embed src="detection.swf" quality="high" bgcolor="#ffffff" width="10" height="10" swLiveConnect=true id="detection" name="detection" align="middle" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" /></object>';

					echo '</li>';
				} elseif ($method == 19) {
					echo '<li><a href="javascript:launchwin(\'viewer1000.php?capfilename='.$capfilename.'\', \'newwindow\',\'width=\'+(screen.width - 10)+\',height=\'+(screen.height - 30)+\',screenX=0,screenY=0,directories=0,fullscreen=1,location=0,menubar=0,scrollbars=0,status=0,toolbar=0\')">'.trim($text).'</a>    ';

					echo '<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=5,0,0,0" id="detection" width="10" height="10" align="middle">';
					echo '<param name="allowScriptAccess" value="sameDomain" /><param name="movie" value="detection.swf" /><param name="quality" value="high" /><param NAME="wmode" VALUE="transparent"><param name="bgcolor" value="#ffffff" />';
					echo '<embed src="detection.swf" quality="high" bgcolor="#ffffff" width="10" height="10" swLiveConnect=true id="detection" name="detection" align="middle" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" /></object>';

					echo '</li>';
				} else {
					echo '<li><a href="docs/'.$capfilename.'" target="_blank">'.trim($text).'</a></li>';
				}
			}

			/* ----- end Function createLink ----- */

 

The javascript link that I will need that "delivery method" to display is:

"javascript:void(0);" onClick="fullScreen('http://url.com");"

 

I could really really use some help with this, as I have a deadline of today.

 

Thanks so much in advance!

Link to comment
https://forums.phpfreaks.com/topic/111142-help-w-adding-to-a-function/
Share on other sites

I'm very very new to this and I didn't write this script. So, sorry if these questions seem silly.

Would this be the proper code?

	elseif ($method == 21) {
					echo '<li><a href="javascript:void(0);" onClick="fullscreen('$url');">'.trim($text).'</a></li>';

 

If that is correct.  How would I go about defining $url?

You need to escape the rest of the ' inside the echo:

 

<a href="javascript:void(0);" onClick="fullscreen('$url');">'

 

Should be:

 

<a href="javascript:void(0);" onClick="fullscreen(\'$url\');">'

 

And you define $url however you want...

 

$url = "http://www.somepage.com";

 

 

Thank you so much for your help!!!  I have defined the variable like so:

$URL = $_GET['plid'];

It's pulling from a database.  I'm pretty sure that's the right setup.

 

I have the syntax still wrong just a touch.  It gave me errors upon uploading.

		echo '</li>';
				} else {
					echo '<li><a href="docs/'.$capfilename.'" target="_blank">'.trim($text).'</a></li>';

				} elseif ($method == 21) {
					echo '<li><a href="javascript:void(0);" onClick="fullscreen(\'$url\');">'.trim($text).'</a></li>';

				}

			/* ----- end Function createLink ----- */

I have moved the else if to above the else.  Did I get it correct?  Here is the entire function code:

<?php
			/* ----- Function createLink -----
				Creates the links for the Courses and Downloads.
				The different methods require different destinations
			   ------------------------------- */
			function createLink ($method, $capfilename, $text) {
				if ($method == 1) {
					echo '<li><a href="javascript:launchwin(\'viewer.php?capfilename='.$capfilename.'\', \'newwindow\',\'width=\'+(screen.width - 10)+\',height=\'+(screen.height - 30)+\',screenX=0,screenY=0,directories=0,fullscreen=1,location=0,menubar=0,scrollbars=0,status=0,toolbar=0\')">'.trim($text).'</a>    ';

					echo '<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=5,0,0,0" id="detection" width="10" height="10" align="middle">';
					echo '<param name="allowScriptAccess" value="sameDomain" /><param name="movie" value="detection.swf" /><param name="quality" value="high" /><param NAME="wmode" VALUE="transparent"><param name="bgcolor" value="#ffffff" />';
					echo '<embed src="detection.swf" quality="high" bgcolor="#ffffff" width="10" height="10" swLiveConnect=true id="detection" name="detection" align="middle" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" /></object>';

					echo '</li>';
				} elseif ($method == 19) {
					echo '<li><a href="javascript:launchwin(\'viewer1000.php?capfilename='.$capfilename.'\', \'newwindow\',\'width=\'+(screen.width - 10)+\',height=\'+(screen.height - 30)+\',screenX=0,screenY=0,directories=0,fullscreen=1,location=0,menubar=0,scrollbars=0,status=0,toolbar=0\')">'.trim($text).'</a>    ';

					echo '<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=5,0,0,0" id="detection" width="10" height="10" align="middle">';
					echo '<param name="allowScriptAccess" value="sameDomain" /><param name="movie" value="detection.swf" /><param name="quality" value="high" /><param NAME="wmode" VALUE="transparent"><param name="bgcolor" value="#ffffff" />';
					echo '<embed src="detection.swf" quality="high" bgcolor="#ffffff" width="10" height="10" swLiveConnect=true id="detection" name="detection" align="middle" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" /></object>';

					echo '</li>';

				} elseif ($method == 21) {
					echo '<li><a href="javascript:void(0);" onClick="fullscreen(\'$url\');">'.trim($text).'</a></li>';

				} else {
					echo '<li><a href="docs/'.$capfilename.'" target="_blank">'.trim($text).'</a></li>';

				}

			/* ----- end Function createLink ----- */

No more coding errors.  However, my javascript isn't working...doesn't open the link.  Do you mind having one more look at how I defined the variable?  I'm sure I've done something wrong there.  It's not understanding where to look for the link.  However, it's pulling the URL from the database.

<?php include 'sessioncontrol.php'; ?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Practice - Physician Education</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<script language="JavaScript"> var javascript_version = 1.0;</script>
<script language="JavaScript1.1"> javascript_version = 1.1;</script>
<script language="JavaScript">
var newwin;
function launchwin(winurl,winname,winfeatures) { //This launches a new window and then //focuses it if window.focus() is supported. 
newwin = window.open(winurl,winname,winfeatures); 
if(javascript_version > 1.0) { //delay a bit here because IE4 encounters errors //when trying to focus a recently opened window 
setTimeout('newwin.focus();',250); }}
</SCRIPT>
<script type="text/javascript">
<!-- Begin
function fullScreen(theURL) {
window.open(theURL, '', 'fullscreen=yes, scrollbars=auto');
}
//  End -->
</script>

<link rel="stylesheet" href="caduceus.css" type="text/css">

<script language="JavaScript">
<!--
var isInternetExplorer = navigator.appName.indexOf("Microsoft") != -1;
// Handle all the FSCommand messages in a Flash movie.
function detection_DoFSCommand(command, args) {
var detectionObj = isInternetExplorer ? document.all.detection : document.detection;
if (command == "curVars") {
	query = window.location.search;
	var vars = query.split("=");
	userid = vars[1].split("&");
	/*sid = vars[2].split("&");
	tid = vars[3].split("&");
	pid = vars[4].split("&");*/
	//alert(userid[0]+" "+sid[0]+" "+tid[0]+" "+pid[0]);
	//window.document.detection.SetVariable('userid', userid);
} else if (command == "needFlash") {
	var goto = "info.php?iid=1&userid="+userid[0]; //+"&sid="+sid[0]+"&tid="+tid[0]+"&pid="+pid[0];
	window.location = goto; 
}
}
// Hook for Internet Explorer.
if (navigator.appName && navigator.appName.indexOf("Microsoft") != -1 && navigator.userAgent.indexOf("Windows") != -1 && navigator.userAgent.indexOf("Windows 3.1") == -1) {
document.write('<script language=\"VBScript\"\>\n');
document.write('On Error Resume Next\n');
document.write('Sub detection_FSCommand(ByVal command, ByVal args)\n');
document.write('	Call detection_DoFSCommand(command, args)\n');
document.write('End Sub\n');
document.write('</script\>\n');
}
//-->
</script>
<script language="JavaScript" type="text/JavaScript">
<!--
function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
//-->
</script>
</HEAD>
<BODY onLoad="MM_preloadImages('images/btn_phys_on.gif','images/btn_ext_on.gif','images/btn_medstud_on.gif')">

<div id="crust">
<div id="filling">
<?php
	include 'physed_dbcnx.inc.php'; // database connection code - ** variable $dbcnx ** 
	$todayis = date('n/j/Y');

	$userid = $_GET['userid'];
	$thissid = $_GET['sid'];
	$thistid = $_GET['tid'];
	$thispid = $_GET['pid'];
	$thisplid = $_GET['plid'];
?>
<div id="images_top"><img src="images/top12.jpg" width="204" height="82" class="left"><img src="images/top24.gif" width="518" height="82" class="left"><img src="images/top32.gif" width="178" height="82" class="right"></div>
<div id="images_row2"><?php
						// ----  Image Row 2 with Title links  ----
						include 'titlerow.inc.php';
					?></div>

<table border="0" cellpadding="0" cellspacing="0" id="middle">
 <tr>
 	<td id="navArea">
		<?php
			// ----  NAV  ----
			include 'nav.inc.php';
		?>
	</td>

	<td id="content">
			<div id="PracticeItem">
			<?php
				if (!isset($userid)){
					echo '<p>Your session has either timed out or an error has occurred. <a href="index.php">Click here</a> to return to the Home page.</p>';
				} else {
					$qry_practice = "SELECT System.name AS sname, Topic.name AS tname, Practice.name AS pname, Practice.descrip AS pdesc FROM Practice INNER JOIN Topic ON Practice.topicid = Topic.id INNER JOIN System ON Topic.systemid = System.id WHERE Practice.id = '$thispid'";

					$result_practice = odbc_exec($dbcnx, $qry_practice);
					if(!$result_practice) {
						echo '<p class="error">Error in query of database - Practice</p>';
					}
					while (odbc_fetch_row($result_practice)){
						$sname = odbc_result($result_practice, 'sname');
						$tname = odbc_result($result_practice, 'tname');
						$pname = odbc_result($result_practice, 'pname');
						$pdesc = odbc_result($result_practice, 'pdesc');
						echo '<div id="breadcrumb"><a href="index.php?userid='.$userid.'">Home</a> > '.trim($sname).' > <a href="topic.php?userid='.$userid.'&sid='.$thissid.'&tid='.$thistid.'">'.trim($tname).'</a> > '.trim($pname).'</div>';
						echo '<h3>'.$tname.'</h3>';
						echo '<h1>'.$pname.'</h1>';
						echo nl2br($pdesc);
						echo '<p> </p><p><div id="breadcrumb">< <a href="topic.php?userid='.$userid.'&sid='.$thissid.'&tid='.$thistid.'">Back to the '.trim($tname).' list</a></div></p>';
					}
				}
			?>
			</div>
	</td>
	<td id="rightcol">
		<img src="images/row3_right-3.gif" width="89" height="27" class="top">
		<form method="post"  action="search.php?userid=<?php echo $userid ?>">
			<input type="text" name="search_text" size="15" title="Single keywords only.">
			<input type="image" src="images/btn_search.gif" height="23" width="63" border="0" alt="Search" align="absmiddle">  
		</form>
		<ul id="rightList"><div class="boldtext">Courses and Downloads</div>
			<span class="aboutLinks">As available, links below may include: 
							online guided practices, printable detailed instruction 
							guides, downloadable cheat-sheets for your Clarian-standard 
							Dell PDA, and more.</span>
		<?php
			/* ----- Function createLink -----
				Creates the links for the Courses and Downloads.
				The different methods require different destinations
			   ------------------------------- */
			function createLink ($method, $capfilename, $text, $URL) {
				if ($method == 1) {
					echo '<li><a href="javascript:launchwin(\'viewer.php?capfilename='.$capfilename.'\', \'newwindow\',\'width=\'+(screen.width - 10)+\',height=\'+(screen.height - 30)+\',screenX=0,screenY=0,directories=0,fullscreen=1,location=0,menubar=0,scrollbars=0,status=0,toolbar=0\')">'.trim($text).'</a>    ';

					echo '<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=5,0,0,0" id="detection" width="10" height="10" align="middle">';
					echo '<param name="allowScriptAccess" value="sameDomain" /><param name="movie" value="detection.swf" /><param name="quality" value="high" /><param NAME="wmode" VALUE="transparent"><param name="bgcolor" value="#ffffff" />';
					echo '<embed src="detection.swf" quality="high" bgcolor="#ffffff" width="10" height="10" swLiveConnect=true id="detection" name="detection" align="middle" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" /></object>';

					echo '</li>';
				} elseif ($method == 19) {
					echo '<li><a href="javascript:launchwin(\'viewer1000.php?capfilename='.$capfilename.'\', \'newwindow\',\'width=\'+(screen.width - 10)+\',height=\'+(screen.height - 30)+\',screenX=0,screenY=0,directories=0,fullscreen=1,location=0,menubar=0,scrollbars=0,status=0,toolbar=0\')">'.trim($text).'</a>    ';

					echo '<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=5,0,0,0" id="detection" width="10" height="10" align="middle">';
					echo '<param name="allowScriptAccess" value="sameDomain" /><param name="movie" value="detection.swf" /><param name="quality" value="high" /><param NAME="wmode" VALUE="transparent"><param name="bgcolor" value="#ffffff" />';
					echo '<embed src="detection.swf" quality="high" bgcolor="#ffffff" width="10" height="10" swLiveConnect=true id="detection" name="detection" align="middle" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" /></object>';

					echo '</li>';

				} elseif ($method == 22) {
					echo '<li><a href="javascript:void(0);" onClick="fullscreen(\'$thisplid\');">'.trim($text).'</a></li>';

				} else {
					echo '<li><a href="docs/'.$capfilename.'" target="_blank">'.trim($text).'</a></li>';

				}
			}
			/* ----- end Function createLink ----- */


			/* ----- Number of Hospital Locations ----- */
			/* ----- if a link is used by all hospitals, the topic will be the link ----- */
			$qry_numlocations = "SELECT Count(id) AS numrec FROM Locations";
			$result_numlocations = odbc_exec($dbcnx, $qry_numlocations);
			if (!$result_numlocations) {
				echo '<p class="error">Error in query of database - Num Locations</p>';
			}
			while (odbc_fetch_row($result_numlocations)){
				$numhosp = odbc_result($result_numlocations, 'numrec');
			}

			/* ----- Delivery Methods ----- */
			$qry_method = "SELECT Delivery.id AS did, Delivery.type AS dtype FROM PracticeLinks INNER JOIN PracticeLinksUser ON PracticeLinks.id = PracticeLinksUser.linkid INNER JOIN Delivery ON PracticeLinks.deliverid = Delivery.id WHERE PracticeLinksUser.userid = '$userid' AND PracticeLinks.practiceid = '$thispid' GROUP BY Delivery.id, Delivery.type";
			$result_method = odbc_exec($dbcnx, $qry_method);
			if(!$result_method) {
				echo '<p class="error">Error in query of database - Practice Method</p>';
			}
			while (odbc_fetch_row($result_method)){
				$did = odbc_result($result_method, 'did');
				$dtype = odbc_result($result_method, 'dtype');

				/* ----- Links for Locations ----- */
				$qry_hospital = "SELECT PracticeLinks.filename AS lfilename, Locations.abbrev AS hospital, PracticeLinks.id AS lid FROM PracticeLinks INNER JOIN PracticeLinksLocation ON PracticeLinks.id = PracticeLinksLocation.linkid INNER JOIN PracticeLinksUser ON PracticeLinks.id = PracticeLinksUser.linkid INNER JOIN Locations ON PracticeLinksLocation.locationid = Locations.id WHERE PracticeLinksUser.userid = '$userid' AND PracticeLinks.practiceid = '$thispid' AND PracticeLinks.deliverid = '$did' ORDER BY PracticeLinks.id";
				$result_hospital = odbc_exec($dbcnx, $qry_hospital);
				if(!$result_hospital) {
					echo '<p class="error">Error in query of database - Practice Hospital</p>';
				}
				while (odbc_fetch_row($result_hospital)){
					$lid = odbc_result($result_hospital, 'lid');
					$lfilename = odbc_result($result_hospital, 'lfilename');
					$hospital = substr(odbc_result($result_hospital, 'hospital'), 0, 2);

					$marray[$lid]['filename'] = trim($lfilename); /* multi-dimensional array for storing the filename and hospital info. per link ID */
					$marray[$lid][] = $hospital;
				}
				$concat = "";
				foreach($marray as $key => $value){
					$howmanyhosp = count($marray[$key])-1; /* counts the number of hospitals that this link is used for -- minus 1 because the array also has the filename */
					if ($howmanyhosp == $numhosp){
						createLink($did,$marray[$key]['filename'],$dtype);
					} else {
						$count = 0;
						while($count < $howmanyhosp){
							$concat .= $marray[$key][$count].' / ';
							$count++;
						}
						echo '<li>'.$dtype.'</li><ul class="sublist">';
						$trim = strlen($concat) - 3;
						$concat = substr($concat, 0, $trim);
						createLink($did,$marray[$key]['filename'],$concat);
						echo '</ul>';		
					}
				}
				unset($marray); /* delete the data in the array so it will be empty before the next pass in the while statement */
			}
		?>
		</ul>
	</td>
 </tr>
</table>
<?php
	// Close Connection
	odbc_close($dbcnx);
?>
</div><!-- filling -->

<img src="images/bottom.gif" width="900" height="17" class="btm">
<p class="leftfootwhite">© 2006-2008 Clarian Health</p>
<p class="rightfootwhite">Created by Clarian Health - Informatics Education</p>
</div><!-- crust -->

</body>
</html>

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.