Page 1 of 1

Merge Functions ??

Posted: Wed Jun 29, 2005 3:27 am
by facets
Any idea on how I could merge the following functions ?

Code: Select all

function view($stockId) {

    if (!$stockId) { echo "<script language=\"javascript\">alert('Selection required')</script>"; }
    else {

echo "<script language=\"javascript\">var newWindow = window.open
('".$_SERVER['PHP_SELF']."?action=viewFaceStock&stockId=".$stockId."','','scrollbars=yes,status=yes,windowX=10,windowY=10,width=440,height=550')</script>";
}
}

function viewLiners($linerId) {
        if (!$linerId) { echo "<script language=\"javascript\">alert('Selection required')</script>"; }
    else {

echo "<script language=\"javascript\">var newWindow = window.open
('".$_SERVER['PHP_SELF']."?action=viewLiner&linerId=".$linerId."','','scrollbars=yes,status=yes,windowX=10,windowY=10,width=440,height=550')</script>";
}
}

function viewAdhesives($adhesiveId) {
        if (!$adhesiveId) { echo "<script language=\"javascript\">alert('Selection required')</script>"; }
    else {

echo "<script language=\"javascript\">var newWindow = window.open
('".$_SERVER['PHP_SELF']."?action=viewAdhesive&adhesiveId=".$adhesiveId."','','scrollbars=yes,status=yes,windowX=10,windowY=10,width=440,height=550')</script>";
}
}
tia, Will./

Posted: Wed Jun 29, 2005 3:54 am
by djot

Code: Select all

function ($action, $data)
{
  if ( (empty($action) OR (empty($data) )
  {
      echo "<script language=\"javascript\">alert('Selection required')</script>";
  }
  else
  {
      switch ($action)
      {
          case "viewFaceStock": $url_data="&stockId=".$data;
          case "viewLiner": $url_data="&linerId=".$data;
          case "viewAdhesive": $url_data="&adhesiveId=".$data;
      }
      echo "<script language=\"javascript\">var newWindow = window.open ('".$_SERVER['PHP_SELF']."?action=".$action.$url_data."','','scrollbars=yes,status=yes,windowX=10,windowY=10,width=440,height=550')</script>";
  }

  // or return
}

call it like

Code: Select all

MergedFunctions ('viewFaceStock', '1234');
djot
-

Posted: Wed Jun 29, 2005 6:47 am
by facets
I'm getting the following error from this code.. Any ideas, it's correct to me..

line 28 :

Code: Select all

if (isset($_POST['viewFaceStock'])) {mergedFunctions($_POST['viewFaceStock','stockId']);}
Parse error: parse error, expecting `']'' in c:\program files\easyphp1-8\www\materialsregister\auaddsummary.php on line 28

Here's the function (slightly tweaked) :

Code: Select all

function mergedFunctions($actioned, $data)
{
  if ( (empty($action)) || (empty($data)) )
  {
      echo "<script language=\"javascript\">alert('Selection required')</script>";
  }
  else
  {
      switch ($actioned)
      {
          case "viewFaceStock": $url_data="&stockId=".$data;
          case "viewLiner": $url_data="&linerId=".$data;
          case "viewAdhesive": $url_data="&adhesiveId=".$data;
      }
      echo "<script language=\"javascript\">var newWindow = window.open ('".$_SERVER['PHP_SELF']."?action=".$actioned.$url_data."','','scrollbars=yes,status=yes,windowX=10,windowY=10,width=440,height=550')</script>";
  }
 
  // or return
}
tia, will

Posted: Wed Jun 29, 2005 6:52 am
by CoderGoblin

Code: Select all

if (isset($_POST['viewFaceStock'])) {mergedFunctions($_POST['viewFaceStock'],$_POST['stockId']);}
You need to have the variables separate ... $_POST['var1','var2'] is not valid php.

Posted: Wed Jun 29, 2005 7:35 am
by facets
excellent.. thanks that corrected the 'calling' of the function..
now the stockId isn't being passed to the popup.

Code: Select all

function popupFunctions($action, $data)
{

    $url_data = isset($_GET['url_data']) ? $_GET['url_data'] : '';
    
  if ( (empty($action)) || (empty($data)) )
  {
      echo "<script language=\"javascript\">alert('Selection required')</script>";
  }
  else
  {
      switch ($action)
      {
          case "viewFaceStock": $url_data="&stockId=".$data;
          case "viewLiner": $url_data="&linerId=".$data;
          case "viewAdhesive": $url_data="&adhesiveId=".$data;
      }
    echo "<script language=\"javascript\">var newWindow = window.open ('".$_SERVER['PHP_SELF']."?action=".$action."&".$url_data."=".$data."','','scrollbars=yes,status=yes,windowX=10,windowY=10,width=440,height=550')</script>";       
  }
 
  // or return
}

Code: Select all

if (isset($_REQUEST['viewFaceStock'])) {popupFunctions($_REQUEST['viewFaceStock'],$_REQUEST['stockId']);}
Post on the main page :
["stockId"]=>
string(1) "2"
["viewFaceStock"]=>
string(21) "View Face Stock Specs"

Get on the popup (shows the main page again.)
array(1) {
["action"]=>
string(21) "View Face Stock Specs"
}
any ideas? tia, will.