Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
<?php
// create database connection
include("includes/connection.php");
// call data to be viewed
$id=$_GET[id];
$sql="SELECT * FROM tblProfileList WHERE ID = $id";
// submit the query
$rs=odbc_exec($conn,$sql);
// if query is invalid do this
if (!$rs)
{exit("Error in SQL");}
// if query is valid do this
if (FALSE === odbc_fetch_row($rs)){
die ('no records found');
}
$id=odbc_result($rs,"ID");
$compName=odbc_result($rs,"companyName");
$compContact=odbc_result($rs,"companyContact");
$nsContacts=odbc_result($rs,"nsContacts");
$personal=odbc_result($rs,"personal");
$overview=odbc_result($rs,"overview");
$majorLocations=odbc_result($rs,"majorLocations");
$systemTraffic=odbc_result($rs,"systemTraffic");
$mjrIssOpps=odbc_result($rs,"mjrIssOpps");
$notes=odbc_result($rs,"notes");
$compInfoUpdated=odbc_result($rs,"compInfoUpdated");
$persInfoUpdated=odbc_result($rs,"persInfoUpdated");
odbc_close($conn);
// create a reference to a new COM component (Word)
$word = new COM("word.application") or die("Can't start Word!");
// set the visibility of the application to 0 (false)
// to open the application in the forefront, use 1 (true)
$word->Visible = false;
// print the version of Word that's now in use
/*
* reinstated for debugging
*/
echo "Loading Word, v. {$word->Version}<br/>";
// specify the MS Word template document ( with bookmarks inside )
$template_file = "G:/Grpratt/Profiles/profileTemplate08.doc";
/*
* create an instance of a new document based on the template
* if it exists
*/
if (file_exists($template_file)){
$document = $word->Documents->Open(realpath($template_file));
} else {
$document = $word->Documents->Add();
}
// set the margins
$word->Selection->PageSetup->LeftMargin = '1"'; //1 inch
$word->Selection->PageSetup->TopMargin = '1"';
$word->Selection->PageSetup->RightMargin = '1"';
$word->Selection->PageSetup->BottomMargin = '1"';
// set the font
$word->Selection->Font->Name = 'Arial';
$word->Selection->Font->Size = 10;
// add text to the new document
$string = <<<TEXT
$compName
$compLoc
$compContact
NS CONTACT:
$nsContacts
PERSONAL:
$personal
OVERVIEW:
$overview
MAJOR LOCATIONS:
$majorLocations
SYSTEM TRAFFIC:
$systemTraffic
MAJOR ISSUES AND OPPORTUNITIES:
$mjrIssOpps
Notes:
$notes
TEXT;
$word->Selection->TypeText($string);
//save the document in the web directory
$outputFile = realpath("/xampp/htdocs/profiles/" . $compName . ".doc");
$word->Documents[1]->SaveAs($outputFile);
// close the connection to the COM component
$word->Quit();
$word->Release();
echo "document has been created<br/>";
?>
Loading Word, v. 11.0
Fatal error: Uncaught exception 'com_exception' with message 'Parameter 0: Type mismatch. ' in C:\xampp\htdocs\profiles\view_word_profile.php:107 Stack trace: #0 C:\xampp\htdocs\profiles\view_word_profile.php(107): variant->SaveAs(false) #1 {main} thrown in C:\xampp\htdocs\profiles\view_word_profile.php on line 107
<?php
// create database connection
include("includes/connection.php");
// call data to be viewed
$id=$_GET[id];
$sql="SELECT * FROM tblProfileList WHERE ID = $id";
// submit the query
$rs=odbc_exec($conn,$sql);
// if query is invalid do this
if (!$rs)
{exit("Error in SQL");}
// if query is valid do this
while (odbc_fetch_row($rs))
{
$id=odbc_result($rs,"ID");
$compName=odbc_result($rs,"companyName");
$compLoc=odbc_result($rs,"compLoc");
$compContact=odbc_result($rs,"companyContact");
$nsContacts=odbc_result($rs,"nsContacts");
$personal=odbc_result($rs,"personal");
$overview=odbc_result($rs,"overview");
$majorLocations=odbc_result($rs,"majorLocations");
$systemTraffic=odbc_result($rs,"systemTraffic");
$mjrIssOpps=odbc_result($rs,"mjrIssOpps");
$notes=odbc_result($rs,"notes");
$compInfoUpdated=odbc_result($rs,"compInfoUpdated");
$persInfoUpdated=odbc_result($rs,"persInfoUpdated");
}
odbc_close($conn);
//1. Instanciate Word
$word = new COM("word.application") or die("Unable to instantiate Word");
//2. specify the MS Word template document (with Bookmark TODAYDATE inside)
$template_file = "G:/Grpratt/Profiles/profileTemplate08.doc";
//3. open the template document
$word->Documents->Open($template_file);
//get the current date MM/DD/YYYY
//$current_date = date("m/d/Y");
//4. get the bookmark and create a new MS Word Range (to enable text substitution)
$bookmarkname = "personal";
$objBookmark = $word->ActiveDocument->Bookmarks($bookmarkname);
$range = $objBookmark->Range;
//5. now substitute the bookmark with actual value
$range->Text = $personal;
//6. save the template as a new document (c:/reminder_new.doc)
$new_file = "G:/Grpratt/Profiles/generated-Word-Profiles/$compName.doc";
$word->Documents[1]->SaveAs($new_file);
//7. free the object
$word->Quit();
// Redirect browser
header("location:[URL unfurl="true"]http://localhost/profiles/profilelist.php");[/URL]
?>
$bookmarknames = array ("personal", 'compName', 'compLoc', 'compContact', 'nsContact'); //make sure the bookmark names are the same as the variables that hold the relevant information
foreach ($bookmarknames as $mark){
$objBookmark = $word->ActiveDocument->Bookmarks($mark);
$range = $objBookmark->Range;
$range->Text = ${$mark}; //note the use of a variable variable
}