Forum Moderators: coopster

Message Too Old, No Replies

Multiple Insert Functions Problem

         

amwd07

11:19 am on Jul 2, 2008 (gmt 0)

10+ Year Member



Hello I have the following issue.

I have recently created a bespoke admin script, eveything works except when my client comes to insert more than 1 PDF
here's my script, which I will try & expalin step by step how this works so someone is either going to help me or poin tout the ovious :-[

First off instead of having the standard browse & upload method to insert pdf into the DB I have created a media Library, which allows my client to select an image or in this case a PDF to insert in to the venue's listing.

the problem is when I select a PDF which displays in the dropdown options if I select the file from the dropdown this then updates the DB, everything is OK up to this point but as soon as I select another PDF ie. a venue listing has the option for 2 for each section tab.
without going in to to much detail I will get right down to explining my problem.

I have included a seperate file in my venue update page with all the pdf fuctions in, this is called select-pdf.php

contents of select-pdf.php

<?php
$dine = $_GET['dine_id'];
$dirname = "/usr/home/virtuals/web/comedinewithus/outlet/id/$dine/";
$actpath = $dirname;

///// Offers PDF 1 /////
function offerPDF1($path){
echo "<div class=library_files>";
echo "<select name='special_offer_pdf1' id='special_offer_pdf1'>";
echo "<option value='' selected='selected'>None</option>";
if ($handle = opendir($path)){
while (false !== ($file = readdir($handle))){
if (strpos($file, '.pdf',1)){
$dine = $_GET['dine_id'];
$fName = $file;
$file = $path.'/'.$file;
if(is_file($file)) {
echo "<option value='$fName'>$fName</option>";}}}
closedir($handle);}}echo "</select></div>";

///// Offers PDF 2 /////
function offerPDF2($path){
echo "<div class=library_files>";
echo "<select name='special_offer_pdf2' id='special_offer_pdf2'>";
echo "<option value='' selected='selected'>None</option>";
if ($handle = opendir($path)){
while (false !== ($file = readdir($handle))){
if (strpos($file, '.pdf',1)){
$dine = $_GET['dine_id'];
$fName = $file;
$file = $path.'/'.$file;
if(is_file($file)) {
echo "<option value='$fName'>$fName</option>";}}}
closedir($handle);}}echo "</select></div>";

///// Events PDF 1 /////
function eventPDF1($path){
echo "<div class=library_files>";
echo "<select name='event_pdf1' id='event_pdf1'>";
echo "<option value='' selected='selected'>None</option>";
if ($handle = opendir($path)){
while (false !== ($file = readdir($handle))){
if (strpos($file, '.pdf',1)){
$dine = $_GET['dine_id'];
$fName = $file;
$file = $path.'/'.$file;
if(is_file($file)) {
echo "<option value='$fName'>$fName</option>";}}}
closedir($handle);}}echo "</select></div>";

///// Events PDF 2 /////
function eventPDF2($path){
echo "<div class=library_files>";
echo "<select name='event_pdf2' id='event_pdf2'>";
echo "<option value='' selected='selected'>None</option>";
if ($handle = opendir($path)){
while (false !== ($file = readdir($handle))){
if (strpos($file, '.pdf',1)){
$dine = $_GET['dine_id'];
$fName = $file;
$file = $path.'/'.$file;
if(is_file($file)) {
echo "<option value='$fName'>$fName</option>";}}}
closedir($handle);}}echo "</select></div>";

///// Menus PDF 1 /////
function menuPDF1($path){
echo "<div class=library_files>";
echo "<select name='menu_pdf1' id='menu_pdf1'>";
echo "<option value='' selected='selected'>None</option>";
if ($handle = opendir($path)){
while (false !== ($file = readdir($handle))){
if (strpos($file, '.pdf',1)){
$dine = $_GET['dine_id'];
$fName = $file;
$file = $path.'/'.$file;
if(is_file($file)) {
echo "<option value='$fName'>$fName</option>";}}}
closedir($handle);}}echo "</select></div>";

///// Menus PDF 2 /////
function menuPDF2($path){
echo "<div class=library_files>";
echo "<select name='menu_pdf2' id=menu_pdf2'>";
echo "<option value='' selected='selected'>None</option>";
if ($handle = opendir($path)){
while (false !== ($file = readdir($handle))){
if (strpos($file, '.pdf',1)){
$dine = $_GET['dine_id'];
$fName = $file;
$file = $path.'/'.$file;
if(is_file($file)) {
echo "<option value='$fName'>$fName</option>";}}}
closedir($handle);}}echo "</select></div>";

///// Reviews PDF 1 /////
function reviewsPDF1($path){
echo "<div class=library_files>";
echo "<select name='reviews_pdf1' id='reviews_pdf1'>";
echo "<option value='' selected='selected'>None</option>";
if ($handle = opendir($path)){
while (false !== ($file = readdir($handle))){
if (strpos($file, '.pdf',1)){
$dine = $_GET['dine_id'];
$fName = $file;
$file = $path.'/'.$file;
if(is_file($file)) {
echo "<option value='$fName'>$fName</option>";}}}
closedir($handle);}}echo "</select></div>";

///// Reviews PDF 2 /////
function reviewsPDF2($path){
echo "<div class=library_files>";
echo "<select name='reviews_pdf2' id='reviews_pdf2'>";
echo "<option value='' selected='selected'>None</option>";
if ($handle = opendir($path)){
while (false !== ($file = readdir($handle))){
if (strpos($file, '.pdf',1)){
$dine = $_GET['dine_id'];
$fName = $file;
$file = $path.'/'.$file;
if(is_file($file)) {
echo "<option value='$fName'>$fName</option>";}}}
closedir($handle);}}echo "</select></div>";

///// News PDF 1 /////
function newsPDF1($path){
echo "<div class=library_files>";
echo "<select name='news_pdf1' id='news_pdf1'>";
echo "<option value='' selected='selected'>None</option>";
if ($handle = opendir($path)){
while (false !== ($file = readdir($handle))){
if (strpos($file, '.pdf',1)){
$dine = $_GET['dine_id'];
$fName = $file;
$file = $path.'/'.$file;
if(is_file($file)) {
echo "<option value='$fName'>$fName</option>";}}}
closedir($handle);}}echo "</select></div>";

///// News PDF 2 /////
function newsPDF2($path){
echo "<div class=library_files>";
echo "<select name='news_pdf2' id='news_pdf2'>";
echo "<option value='' selected='selected'>None</option>";
if ($handle = opendir($path)){
while (false !== ($file = readdir($handle))){
if (strpos($file, '.pdf',1)){
$dine = $_GET['dine_id'];
$fName = $file;
$file = $path.'/'.$file;
if(is_file($file)) {
echo "<option value='$fName'>$fName</option>";}}}
closedir($handle);}}echo "</select></div>";
?>

now on the venue update page I have the following lines which inserts into the DB, I know this part works as this is addon the dreamweaver CS3

// Make an update transaction instance
$upd_restaurant_extras = new tNG_update($conn_connDW);
$tNGs->addTransaction($upd_restaurant_extras);
// Register triggers
$upd_restaurant_extras->registerTrigger("STARTER", "Trigger_Default_Starter", 1, "POST", "KT_Update1");
// Add columns
$upd_restaurant_extras->setTable("restaurant_extras");
$upd_restaurant_extras->addColumn("special_offer_url", "STRING_TYPE", "POST", "special_offer_url");
$upd_restaurant_extras->addColumn("special_offer_pdf1", "STRING_TYPE", "POST", "special_offer_pdf1");
$upd_restaurant_extras->addColumn("special_offer_pdf1_title", "STRING_TYPE", "POST", "special_offer_pdf1_title");
$upd_restaurant_extras->addColumn("special_offer_pdf2", "STRING_TYPE", "POST", "special_offer_pdf2");
$upd_restaurant_extras->addColumn("special_offer_pdf2_title", "STRING_TYPE", "POST", "special_offer_pdf2_title");
$upd_restaurant_extras->addColumn("event_url", "STRING_TYPE", "POST", "event_url");
$upd_restaurant_extras->addColumn("event_pdf1_title", "STRING_TYPE", "POST", "event_pdf1_title");
$upd_restaurant_extras->addColumn("event_pdf2_title", "STRING_TYPE", "POST", "event_pdf2_title");
$upd_restaurant_extras->addColumn("event_pdf1", "STRING_TYPE", "POST", "event_pdf1");
$upd_restaurant_extras->addColumn("event_pdf2", "STRING_TYPE", "POST", "event_pdf2");
$upd_restaurant_extras->addColumn("menu_url", "STRING_TYPE", "POST", "menu_url");
$upd_restaurant_extras->addColumn("menu_pdf1", "STRING_TYPE", "POST", "menu_pdf1");
$upd_restaurant_extras->addColumn("menu_pdf1_title", "STRING_TYPE", "POST", "menu_pdf1_title");
$upd_restaurant_extras->addColumn("menu_pdf2", "STRING_TYPE", "POST", "menu_pdf2");
$upd_restaurant_extras->addColumn("menu_pdf2_title", "STRING_TYPE", "POST", "menu_pdf2_title");
$upd_restaurant_extras->addColumn("reviews_url", "STRING_TYPE", "POST", "reviews_url");
$upd_restaurant_extras->addColumn("reviews_pdf1", "STRING_TYPE", "POST", "reviews_pdf1");
$upd_restaurant_extras->addColumn("reviews_pdf1_title", "STRING_TYPE", "POST", "reviews_pdf1_title");
$upd_restaurant_extras->addColumn("reviews_pdf2", "STRING_TYPE", "POST", "reviews_pdf2");
$upd_restaurant_extras->addColumn("reviews_pdf2_title", "STRING_TYPE", "POST", "reviews_pdf2_title");
$upd_restaurant_extras->addColumn("news_url", "STRING_TYPE", "POST", "news_url");
$upd_restaurant_extras->addColumn("news_pdf1", "STRING_TYPE", "POST", "news_pdf1");
$upd_restaurant_extras->addColumn("news_pdf1_title", "STRING_TYPE", "POST", "news_pdf1_title");
$upd_restaurant_extras->addColumn("news_pdf2", "STRING_TYPE", "POST", "news_pdf2");
$upd_restaurant_extras->addColumn("news_pdf2_title", "STRING_TYPE", "POST", "news_pdf2_title");
$upd_restaurant_extras->setPrimaryKey("dine_id", "NUMERIC_TYPE", "GET", "dine_id");
[/code]

Now further down the page this is how I call the function please excuse the messy table layout not had time to tidy this up :(

<table border="1" align="center" cellpadding="4" cellspacing="0" bordercolor="#FFFFFF" bgcolor="#F4F4F4">
<?php if (@$totalRows_offerstab != 0 ) { ?>
<tr>
<td bgcolor="#FFCC00"><label for="hometab_featured"><strong>Activate:</strong></label></td>
<td bgcolor="#FFFFFF"><input <?php if (!(strcmp(KT_escapeAttribute($row_rsrestaurants['hometab_special_offer']),"1"))) {echo "checked";} ?> type="checkbox" name="hometab_special_offer" id="label" value="1" />
<?php echo $tNGs->displayFieldError("restaurants", "hometab_special_offer"); ?></td>
</tr>
<?php } ?>
<tr bordercolor="#FFFFFF" bgcolor="#F4F4F4">
<td bgcolor="#FFEEAA"><strong>Offer Teaser: </strong></td>
<td bgcolor="#FFEEAA"><input type="text" name="special_offer_text" id="special_offer_text" value="<?php echo KT_escapeAttribute($row_rsrestaurants['special_offer_text']); ?>" size="60" />
<?php echo $tNGs->displayFieldHint("special_offer_text");?> <?php echo $tNGs->displayFieldError("restaurants", "special_offer_text"); ?></td>
</tr>
<tr>
<td><label for="special_offer_url">Offer Web link:</label></td>
<td><input type="text" name="special_offer_url" id="special_offer_url" value="<?php echo KT_escapeAttribute($row_rsrestaurant_extras['special_offer_url']); ?>" size="50" />
<?php echo $tNGs->displayFieldHint("special_offer_url");?> <?php echo $tNGs->displayFieldError("restaurant_extras", "special_offer_url"); ?> </td>
</tr>

<tr>
<td><label for="special_offer_pdf1_title">Offer PDF Title 1:</label></td>
<td><input type="text" name="special_offer_pdf1_title" id="special_offer_pdf1_title" value="<?php echo KT_escapeAttribute($row_rsrestaurant_extras['special_offer_pdf1_title']); ?>" size="50" />
<?php echo $tNGs->displayFieldHint("special_offer_pdf1_title");?> <?php echo $tNGs->displayFieldError("restaurant_extras", "special_offer_pdf1_title"); ?> </td>
</tr>
<tr>
<td><label for="special_offer_pdf2_title">Offer PDF Title 2:</label></td>
<td><input type="text" name="special_offer_pdf2_title" id="special_offer_pdf2_title" value="<?php echo KT_escapeAttribute($row_rsrestaurant_extras['special_offer_pdf2_title']); ?>" size="50" />
<?php echo $tNGs->displayFieldHint("special_offer_pdf2_title");?> <?php echo $tNGs->displayFieldError("restaurant_extras", "special_offer_pdf2_title"); ?> </td>
</tr>
<tr>
<td><label for="offer_pdf1">Select PDF 1:</label></td>
<?php if (@$offerpdf1 != "") {
echo "<td>";
echo "<a href='/outlet/id/$dine/$offerpdf1' target='_blank'>"."<b>".$offerpdf1."</b></a>";
echo "<span class='delete'>";
echo "<input name='offer_pdf1' type='checkbox' value=''/>";
echo "&nbsp;"."Delete PDF";
echo "</span>";
echo "</td>";
} else {
echo "<td>";
offerPDF1($actpath);
echo "</td>";
} ?>
</tr>
<tr>
<td><label for="offer_pdf2">Select PDF 2:</label></td>
<?php if (@$offerpdf2 != "") {
echo "<td>";
echo "<a href='/outlet/id/$dine/$offerpdf2' target='_blank'>"."<b>".$offerpdf2."</b></a>";
echo "<span class='delete'>";
echo "<input name='offer_pdf2' type='checkbox' value=''/>";
echo "&nbsp;"."Delete PDF";
echo "</span>";
echo "</td>";
} else {
echo "<td>";
offerPDF2($actpath);
echo "</td>";
} ?>
</tr>
<tr>
<td>&nbsp;</td>
<td><div align="right">
<input type="submit" name="KT_Update1" id="KT_Update1" value="Update" />
</div></td>
</tr>
</table>

rather than posting the above several times i will just show you snipets of code for each venues section

<?php if (@$eventpdf1 != "") {
echo "<td>";
echo "<a href='/outlet/id/$dine/$eventpdf1' target='_blank'>"."<b>".$eventpdf1."</b></a>";
echo "<span class='delete'>";
echo "<input name='event_pdf1' type='checkbox' value=''/>";
echo "&nbsp;"."Delete PDF";
echo "</span>";
echo "</td>";
} else {
echo "<td>";
eventPDF1($actpath);
echo "</td>";
} ?>

<?php if (@$eventpdf2 != "") {
echo "<td>";
echo "<a href='/outlet/id/$dine/$eventpdf2' target='_blank'>"."<b>".$eventpdf2."</b></a>";
echo "<span class='delete'>";
echo "<input name='event_pdf2' type='checkbox' value=''/>";
echo "&nbsp;"."Delete PDF";
echo "</span>";
echo "</td>";
} else {
echo "<td>";
eventPDF2($actpath);
echo "</td>";
} ?>

<?php if (@$menupdf1 != "") {
echo "<td>";
echo "<a href='/outlet/id/$dine/$menupdf1' target='_blank'>"."<b>".$menupdf1."</b></a>";
echo "<span class='delete'>";
echo "<input name='menu_pdf1' type='checkbox' value=''/>";
echo "&nbsp;"."Delete PDF";
echo "</span>";
echo "</td>";
} else {
echo "<td>";
menuPDF1($actpath);
echo "</td>";
} ?>

<?php if (@$menupdf2 != "") {
echo "<td>";
echo "<a href='/outlet/id/$dine/$menupdf2' target='_blank'>"."<b>".$menupdf2."</b></a>";
echo "<span class='delete'>";
echo "<input name='menu_pdf2' type='checkbox' value=''/>";
echo "&nbsp;"."Delete PDF";
echo "</span>";
echo "</td>";
} else {
echo "<td>";
menuPDF2($actpath);
echo "</td>";
} ?>

and it goes on you get the idea, these functions seem to overide each other for example if I update menus 1 pdf this is Ok but when I add pdf 2 this overides this, also it overides the others section PDF, there must be soemthing wrong in the function coding.
Please I really hope someone has a good idea to what I am talking about.

Thank you in advanced ;)

PHP_Chimp

5:34 pm on Jul 2, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



As there is a huge amount of code there I have not looked through everything throughly, however there are a few things that I think that you should look at.

You have lots of

<?php if (@$totalRows_offerstab != 0 ) { ?>
Or similar.

The @ will suppress any errors that this line of code is causing. So if you remove those @ symbols you may well find that you have the reason for your code not working.

You also have

<?php if (!(strcmp(KT_escapeAttribute($row_rsrestaurants['hometab_special_offer']),"1"))) {echo "checked";} ?>

KT_escapeAttribute is not a standard PHP function. Is this one of your functions (maybe I missed it in the code) or should this be a variable?
Although this is unlikely to be the problem you may need to share this function.

I would suggest first removing all of the @'s and see what errors that throws for you. As hopefully that will give you a better idea of the problem.

amwd07

9:00 pm on Jul 3, 2008 (gmt 0)

10+ Year Member



I have tried taking out all the @'s which made no difference
so with getting no further on this I ahave merged all the code in to one readable php file <snip>

i really hope some one can help & I know messy coding in places especially when using tables :(

[edited by: dreamcatcher at 7:01 am (utc) on July 4, 2008]
[edit reason] No urls please! [/edit]

PHP_Chimp

5:44 am on Jul 4, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



OK, shame that didnt throw any light on the problem.

Do you want people to be able to select more than one option from your drop down menus? As at the moment they should only accept a single option, not multiple options.

You may also want to change your code so that you are not using raw data. As from a quick flick through you have

$dine = $_GET['dine_id'];
$dirname = "/usr/home/virtuals/web/comedinewithus/outlet/id/$dine/";

Line 392,393 from your code.

You may want to use array_walk [php.net] and pass all of the $_GET variable through your cleaning function.

amwd07

10:34 am on Jul 4, 2008 (gmt 0)

10+ Year Member



OK thankyou for your reply.
I would only like to select a single option from the dropdown

the way it works is:

there are 5 sections for each venue, where the client can add there inforamtion 2 & in each section which I have placed within tabs they can also choose 2 pdf's to display on there venues listing

I have a seperate venue upload link to upload all extension types ie. jpg, gif, doc, pdf, etc.

the uploaded PDF files appear in all the venue dropdowns ie. if 6 PDF's are uplaoded in each tab there will be 6 options in each dropdown, where the cleint would select one of them & update the trouble is when they select another dropdown this overides the frist one.

so this is 1 of the function which returns the dropdown options


///// Offers PDF 1 /////
function offerPDF1($path){
echo "<div class=library_files>";
echo "<select name='special_offer_pdf1' id='special_offer_pdf1'>";
echo "<option value='' selected='selected'>None</option>";
if ($handle = opendir($path)){
while (false !== ($file = readdir($handle))){
if (strpos($file, '.pdf',1)){
$dine = $_GET['dine_id'];
$fName = $file;
$file = $path.'/'.$file;
if(is_file($file)) {
echo "<option value='$fName'>$fName</option>";}}}
closedir($handle);}}echo "</select></div>";

how it's entered into the DB I don't think is the problem maybe the issue is having these multiple fuctions?

And this is then how the function is called


<?php if (@$offerpdf1 != "") { /// this would display the file in the DB & have the option to remove this
echo "<td>";
echo "<a href='/outlet/id/$dine/$offerpdf1' target='_blank'>"."<b>".$offerpdf1."</b></a>";
echo "<span class='delete'>";
echo "<input name='offer_pdf1' type='checkbox' value=''/>";
echo "&nbsp;"."Delete PDF";
echo "</span>";
echo "</td>";
} else {
echo "<td>";
offerPDF1($actpath); /// this would would display the dropdown for the above function
echo "</td>";
} ?>

I understand it may not be best way to do this using $dine = $_GET['dine_id']; but there are over 800 listings on this site which each one havin g it's own unique ID, idealy there should be a login but at this point it is only administrator access who can make these changes that why this was easier to pass the url.

Have I provided enough information or would it be possible to email you & maybe provide a workin gexample which would take me an hour or so to setup.

thanks for all your help with this :)

PHP_Chimp

5:02 pm on Jul 4, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



If you are calling that function using
<?php if (@$offerpdf1 != "")

then that may well be your problem.
As your original offerPDF1 doesnt return any value, and offerpdf1 and offerPDF1 are different things and $offerpdf1 is a variable not calling a function.

So I have changed the function to return a value, so you can test this return value.
You would call it as:


<?php
if (offerPDF1('something') !== '') {


///// Offers PDF 1 /////
function offerPDF1($path){
$out = '';
if ($handle = opendir($path)){
$out.= "<div class=library_files>";
$out.= "<select name='special_offer_pdf1' id='special_offer_pdf1'>";
$out.= "<option value='' selected='selected'>None</option>";
while (false !== ($file = readdir($handle))){
if (strpos($file, '.pdf',1)){
$dine = $_GET['dine_id'];
$fName = $file;
$file = $path.'/'.$file;
if(is_file($file)) {
$out.= "<option value='$fName'>$fName</option>";
}
}
}
closedir($handle);
$out.= "</select></div>";
}
else {
$out.= 'Error.<br />';
$out.= "Handle: $handle <br />Path: $path<br />;
}
return $out;
}

From the link that you posted (before it was removed) you have
// line 356
$offerpdf1 = $row_rsrestaurant_extras['special_offer_pdf1'];

So this is not calling the function that you have posted in your reply above.

I'm still a little confused about what you are trying to achieve, as I havent run your code. However hopefully that will put you in a better direction.

amwd07

10:33 pm on Jul 4, 2008 (gmt 0)

10+ Year Member



Hello
once again thankyou for all your help butI am still lost on this one

here are the changes I have made, but now the dropdown options have disapeared ?

I am only using <?php if (@$offerpdf1 != "") so if there is an pdf in the DB the dropdown won't appear instead it will show th name for the PDF then a checkbox to delete if necesary.

these functions are only called when there is no entry in the DB

} else {
echo "<td>";
offerPDF1($actpath);
echo "</td>";
} ?>

going back to my variable $offerpdf1, this is the special offer field in the DB so line 356 is important to the recordset.

///// Offers PDF 1 /////
function offerPDF1($path){
$out = ''; /// Is there suppose to be any value here ?
if ($handle = opendir($path)){
$out.= "<div class=library_files>";
$out.= "<select name='special_offer_pdf1' id='special_offer_pdf1'>";
$out.= "<option value='' selected='selected'>None</option>";
while (false !== ($file = readdir($handle))){
if (strpos($file, '.pdf',1)){
$dine = $_GET['dine_id'];
$fName = $file;
$file = $path.'/'.$file;
if(is_file($file)) {
$out.= "<option value='$fName'>$fName</option>";
}
}
}
closedir($handle);
$out.= "</select></div>";
}
else {
$out.= 'Error.<br />';
$out.= "Handle: $handle <br />Path: $path<br />";
}
return $out;
}

amwd07

10:42 pm on Jul 4, 2008 (gmt 0)

10+ Year Member



just to take <?php if (@$offerpdf1 != "") out of the equation for a minute I have now just called the functions using the following

<?php
echo "<td>";
offerPDF1($actpath);
echo "</td>";
?>

<?php
echo "<td>";
offerPDF2($actpath);
echo "</td>";
?>

amwd07

9:44 am on Jul 5, 2008 (gmt 0)

10+ Year Member



just to be clearer I tested this function on it's own using

<?php offerPDF1($actpath); ?>
<?php offerPDF2($actpath); ?>

I am not sure if these functions work now using $out.= ?

PHP_Chimp

8:37 pm on Jul 8, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



The $out variable is initialized as a blank string as we are building the output on top of this.
I only altered the code that you already had. I havent looked through the code to see if there was anything that needed changing.

I would suggest that you remove all @'s, as these suppress errors and seeing as something isnt working you dont want errors suppressed...yet. You can put them back in for production, although you should think about logging errors, not just hiding them.

The $out.= 'something' means add 'something' to the $out variable.

As offerPDF1 is a function that will return a string (or an error, if it isnt correct). So you could either echo the result of that function or stick that into a variable and echo that.
<?php offerPDF1($actpath); ?> will not get you anything as you need to echo the result. Try:


<?php
echo offerPDF1($actpath);
// or
$html = offerPDF1($actpath);
echo $html;
?>

If the function isnt working then I would add in an else element for each of the if's. So that you can see where the function is breaking.