<?php 
include("lib/config.php");
// Load library 
include_once 'lib/HtmlToDoc.class.php';  
 
// Initialize class 
$htd = new HTML_TO_DOC();

//------------------- Patient Info ---------------------

$host = 'http://'.$_SERVER['HTTP_HOST'].'/shmap-online/'; 

$shid = isset($_GET['shid'])?$_GET['shid']:'';


$selSH_Query = "SELECT ".TBL_CATEGORIES.".category_title,".TBL_STAKEHOLDERS.".* FROM ".TBL_STAKEHOLDERS." 
	INNER JOIN ".TBL_CATEGORIES." ON (".TBL_STAKEHOLDERS.".category_id=".TBL_CATEGORIES.".category_id)
	WHERE ".TBL_STAKEHOLDERS.".id = '".$shid."' ";
$shInfo = $con->getSingleRow($selSH_Query);	

$shName = isset($shInfo['name'])?$shInfo['name']:'';
//-----------------------------------------------------

$htmlContent = '
<style>
.tblCard{
	border: 1px solid #CCCCCC;
}
.tblCard tr th{
}
.tblCard tr td {
  height:20px;
  vertical-align: middle;
  text-align: center;
}
.tblCard tr th {
  background-color: #e7e6e6;
  border-right: 1px solid #CCCCCC;
  border-bottom: 1px solid #CCCCCC;
  border-left: 1px solid #CCCCCC;
  border-top: 1px solid #CCCCCC;
  height:20px;
  vertical-align: middle;
  text-align: left;
}
</style>';
$htmlContent .= '<div class="admin-dashone-data-table-area mg-b-40">
  <div class="container">   
            <div class="view-mail-ov-mg-t-30">
              <div id="" class="shadow-reset">
                <div class="row">
                  <div class="col-lg-12 col-md-12 col-sm-12 col-xs-12" style="background:#FFFFFF;">';
if(!empty($shInfo))
{
    $filename=$shInfo['name'];
  $htmlContent .= '                            
                          <div style=">
                      <div class="mail-title" style="margin-top:10px; margin-left:21px; text-align:right; font-size:31px; float:left; padding-left:126px;"> <strong>Individual Stakeholder Card</strong> </div>
                      <div style="float:right;" id="shName"><img src="'.$host.'uploads/stake-holders/'.$shInfo['sh_logo'].'" width="50" height="50" id="Logo">&nbsp; <strong>'.$shInfo['name'].'</strong></div>
                    </div>
						  
						  
						  <div class="view-mail-wrap">
                          <div class="sparkline8-graph" style="margin-top:30px;">
                            <div class="static-table-list">
                              <table class="tblCard" width="100%">
                                <thead>
                                  <tr>
                                    <th>Category</th>
                                    <th>Abbreviation</th>
                                    <th>Interest</th>
                                    <th>Influence</th>
                                    <th>Current Orientation</th>
                                    <th>Desired Orientation</th>
                                  </tr>
                                </thead>
                                <tbody>
                                  <tr>
                                    <td id="shCatTitle">'.$shInfo['category_title'].'</td>
                                    <td id="shAbbreviation">'.$shInfo['abbreviation'].'</td>
                                    <td id="shInterest">'.$shInfo['orientation_sh_interest'].'</td>
                                    <td id="shInfluence">';
                                  
									if(isset($shInfo['orientation_sh_influence']) &&  $shInfo['orientation_sh_influence']== '7')
									{
										$htmlContent .= 'Low';
									}
									elseif(isset($shInfo['orientation_sh_influence']) &&  $shInfo['orientation_sh_influence']== '14')
									{
										$htmlContent .= 'Medium';
									}
									elseif(isset($shInfo['orientation_sh_influence']) &&  $shInfo['orientation_sh_influence']== '20')
									{
										$htmlContent .= 'High';
									}
									
                          $htmlContent .= '</td>
                                    <td id="shCurrentOrientation">';
							
									if(isset($shInfo['sh_current_orientation']) &&  $shInfo['sh_current_orientation']== 'green')
									{
										$htmlContent .= 'Supportive';
									}
									elseif(isset($shInfo['sh_current_orientation']) &&  $shInfo['sh_current_orientation']== 'red')
									{
										$htmlContent .= 'Resistant';
									}
									elseif(isset($shInfo['sh_current_orientation']) &&  $shInfo['sh_current_orientation']== 'orange')
									{
										$htmlContent .= 'Neutral';
									}
							
                             $htmlContent .= '</td>
                                    <td id="shDesiredOrientation">';
							 	
									if(isset($shInfo['sh_desired_orientation']) &&  $shInfo['sh_desired_orientation']== 'green')
									{
										$htmlContent .= 'Supportive';
									}
									elseif(isset($shInfo['sh_desired_orientation']) &&  $shInfo['sh_desired_orientation']== 'red')
									{
										$htmlContent .= 'Resistant';
									}
									elseif(isset($shInfo['sh_desired_orientation']) &&  $shInfo['sh_desired_orientation']== 'orange')
									{
										$htmlContent .= 'Neutral';
									}
							
                               $htmlContent .= '</td>
                                  </tr>
                                </tbody>
                              </table>
                            </div>
                          </div>
                          <div class="view-mail-content">
                            <div class="sparkline8-graph">
                              <div class="static-table-list">
                                <table class="tblCard" width="100%">
                                  <thead>
                                    <tr>
                                      <th style="text-align:center;">Analysis</th>
                                    </tr>
                                  </thead>
                                  <tbody>
                                    <tr>
                                      <td><div id="canvas"><img src="'.$host.'uploads/svgs/'.$shInfo['sh_ranking_svg_img'].'"></div></td> 
                                    </tr>
                                  </tbody>
                                </table>
                              </div>
                            </div>
                          </div>
                          <div class="view-mail-content">
                            <div class="sparkline8-graph">
                              <div class="static-table-list">
                                <table class="tblCard" width="100%">
                                  <thead>
                                    <tr>
                                      <th style="text-align:center;">Stakeholder Introduction&nbsp;</th>
                                    </tr>
                                  </thead>
                                  <tbody>
                                    <tr>
                                      <td>
									  <div id="sh_intro">'.$shInfo['description'].' </div>
                                      <input for="clear" id="clear" name="clear" title="Erase all names from the grid" type="button" value="Clear" style="display:none;"></td>
                                    </tr>
                                  </tbody>
                                </table>
                              </div>
                            </div>
                          </div>
                          <div class="view-mail-content">
                            <div class="sparkline8-graph">
                              <div class="static-table-list">
                                <table class="tblCard" width="100%">
                                  <tbody>                                    
                                    <tr>
                                      <th width="40%">Summary of RI interaction with stakeholder.</th>
                                      <td width="60%" id="sh_summary_interaction">'.$shInfo['sh_summary_interaction'].'</td>
                                    </tr>
                                    <tr>
                                      <th>What is important for Stakeholder?</th>
                                      <td id="important_for_sh">'.$shInfo['important_for_sh'].'</td>
                                    </tr>
                                    <tr>
                                      <th>How could SH contribute to RI.</th>
                                      <td id="sh_contribute">'.$shInfo['sh_contribute'].'</td>
                                    </tr>
                                    <tr>
                                      <th>How could the stakeholder block RI?</th>
                                      <td id="sh_block">'.$shInfo['sh_block'].'</td>
                                    </tr>
                                    <tr>
                                      <th>Key Issues/Concerns of stakeholder.</th>
                                      <td id="sh_issues_concerns">'.$shInfo['sh_issues_concerns'].'</td>
                                    </tr>
                                  </tbody>
                                </table>
                              </div>
                            </div>
                          </div>
                          <div class="sparkline8-graph">
                            <div class="static-table-list">
                              <table class="tblCard" width="100%">
                                <thead>
                                  <tr>
                                    <th colspan="3" style="text-align:center;">Analysis Updates</th>
                                  </tr>
                                  <tr>
                                    <th width="4%">Sr#</th>
                                    <th width="40%">Update</th>
                                    <th width="56%">Timestamp</th>
                                  </tr>
                                </thead>
                                <tbody>';
                             
									$counter_rankupd = 0;
									$selQuery_rank_upd = "SELECT * FROM  ".TBL_RANKING_HISTORY." WHERE sh_id='".$shid."' ORDER BY id desc;";
									$rankupdInfo = $con->getMultiRow($selQuery_rank_upd);
									$tot_mappingsInfo = count($rankupdInfo);
									if($tot_mappingsInfo > 0){
										 for($ru=0;$ru<$tot_mappingsInfo;$ru++)
										 {
											$counter_rankupd++;
							
                             $htmlContent .= '<tr>
                                      <td>"'.$counter_rankupd.'".</td>
                                      <td>"'.isset($rankupdInfo[$ru]['update_detail'])?$rankupdInfo[$ru]['update_detail']:''.'"</td>
                                      <td>"'.isset($rankupdInfo[$ru]['date_modified'])?date("d-m-Y",strtotime($rankupdInfo[$ru]['date_modified'])):date("d-m-Y",strtotime($rankupdInfo[$ru]['date_added'])).'"</td>
                                    </tr>';
									 }
                                    }
                                $htmlContent .= '</tbody>
                              </table>
                            </div>
                          </div>
                          <div class="sparkline8-graph">
                            <div class="static-table-list">
                              <table class="tblCard" width="100%">
                                <thead>
                                  <tr>
                                    <th colspan="6" style="text-align:center;">RI strategy, Responsibilities, execution, milestones achieved.</th>
                                  </tr>
                                  <tr>
                                    <th width="10%">Sr#</th>
                                    <th width="30%">Strategy</th>
                                    <th width="30%">Responsibility</th>
                                    <th width="30%">Key milestones</th>
                                  </tr>
                                </thead>
                                <tbody id="shRISREMA">';
                                 
									$counter_str = 0;
									$selQuery_str = "SELECT * FROM  ".TBL_STRATEGIES." WHERE sh_id='".$shid."' ORDER BY id desc;";
									$strInfo = $con->getMultiRow($selQuery_str);
									$tot_mappingsInfo = count($strInfo);
									if($tot_mappingsInfo > 0){
										 for($ru=0;$ru<$tot_mappingsInfo;$ru++)
										 {
											$counter_str++;
								
                                  $htmlContent .= '<tr>
                                      <td>"'.$counter_str.'".</td>
                                      <td id="strategy_"'.$shInfo['id'].'"_"'.$strInfo[$ru]['id'].'"">"'.isset($strInfo[$ru]['strategy'])?$strInfo[$ru]['strategy']:''.'"</td>
                                      <td id="responsibility_"'.$shInfo['id'].'"_"'.$strInfo[$ru]['id'].'"">"'.isset($strInfo[$ru]['responsibility'])?$strInfo[$ru]['responsibility']:''.'"</td>
                                      <td id="key_milestones_"'.$shInfo['id'].'"_"'.$strInfo[$ru]['id'].'"">"'.isset($strInfo[$ru]['key_milestones'])?$strInfo[$ru]['key_milestones']:''.'"</td> 
                                    </tr>';
									 }
                                    }
                                 $htmlContent .= ' <tr>
                                      <td colspan="6"></td>
                                  </tr>    
                                </tbody>
                              </table>
                            </div>
                          </div>';
}
$htmlContent .= '</div>
          </div>
        </div>
      </div>
    </div>
  </div>';				  
	
//$htd->createDoc($htmlContent, "my-document");
$htd->createDoc($htmlContent, $filename, 1);//download

//$htd->createDoc("source.html", "my-document");//Create Word Document from HTML File

//$htd->createDoc($htmlContent, "my-document.docx");//
?>