{source}<?php
$formid=$_GET['frmid'];
$userid=$_GET['usid'];
$db = JFactory::getDBO();
if(isset($_POST['submit']))
{
$comment=$_POST['comment'];
$status=$_POST['status'];
$db = JFactory::getDBO();
$query = $db->getQuery(true);
$fields = array(
$db->quoteName('appcomment') .'='. $db->q($comment),
$db->quoteName('approved') .'='. $db->q($status)
);
$conditions = array(
$db->quoteName('form') .'='. $db->q($formid),
$db->quoteName('user_id') .'='. $db->q($userid)
);
$query->update($db->quoteName('#__facileforms_records'))
->set($fields)
->where($conditions);
$db->setQuery($query)
->execute();
$db->setQuery("Select * From #__facileforms_records where form='".$formid."' AND user_id='".$userid."'");
$formrecords = $db->loadAssocList();
if($formrecords)
{
echo "<span style='color:green;font-size:16px;'>Comment added successfully</span>";
$useremails=$db->getQuery(true);
$queryuserdetails = $db->getQuery(true);
$queryuserdetails = "SELECT * FROM `#__users` WHERE id='".$userid."'";
$db->setQuery($queryuserdetails);
$resultusers = $db->loadAssocList();
$usertoemail=$resultusers[0]['email'];
$queryrecord = $db->getQuery(true);
$queryrecord = "SELECT * FROM `#__facileforms_records` WHERE form = '".$formid."' AND user_id='".$userid."'";
$db->setQuery($queryrecord);
$resultrecords = $db->loadAssocList();
$entryid=$resultrecords[0]['id'];
$username=$resultrecords[0]['user_full_name'];
$querypageheading = $db->getQuery(true);
$querypageheading = "SELECT `id`,`title`,`name`,`value` FROM `#__facileforms_subrecords` WHERE record = '".$entryid."' AND type!='Hidden Input'";
$db->setQuery($querypageheading);
$resultpage = $db->loadAssocList();
/* Customer Email Code start here */
if($status=="true")
{
$status="Approved";
}
else
{
$status=$status;
}
$body = "<p>Hi <strong>".$username."</strong>,</p>";
$body .="<h3>".$formrecords[0]['title']." <strong>".$status."</strong></h3>";
$body .="<p><strong>Admin Comment:</strong>".$comment."</p>";
$body .='<table style="border-color: #000000; background-color: #eeeeee;" cellpadding="10" border="1"><tbody><tr>
<td style="text-align: left;"><b>Name</b></td>
<td style="text-align: center;"><b>Value</b></td>
</tr>';
for($k=0;$k<count($resultpage);$k++)
{
$body .='<tr>
<td style="text-align: left;">'.$resultpage[$k]['title'].'</td>
<td style="text-align: left;">'.$resultpage[$k]['value'].'</td>
</tr>';
}
echo '</tbody></table>';
$to = $usertoemail;
$from =
$fromName = 'Anglo-Suisse Capital Limited';
$subject = "".$formrecords[0]['title']."";
$htmlContent = $body;
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=UTF-8" . "\r\n";
// Additional headers
$headers .= 'From: '.$fromName.'<'.$from.'>' . "\r\n";
// Send email
if(mail($to, $subject, $htmlContent, $headers)){
//echo 'Email has sent successfully.';
}else{
//echo 'Email sending failed.';
}
}
} //if submit button condition end
$queryrecord = "SELECT * FROM `#__facileforms_records` WHERE form = '".$formid."' AND user_id='".$userid."'";
$db->setQuery($queryrecord);
$resultrecords = $db->loadAssocList();
$entryid=$resultrecords[0]['id'];
if(isset($_GET['status'])) //if click on decline button this code will be run from email
{
$statusheader=$_GET['status'];
$db = JFactory::getDBO();
$query = $db->getQuery(true);
$fields = array(
$db->quoteName('appcomment') .'='. $db->q($comment),
$db->quoteName('approved') .'='. $db->q($statusheader)
);
$conditions = array(
$db->quoteName('form') .'='. $db->q($formid),
$db->quoteName('user_id') .'='. $db->q($userid)
);
$query->update($db->quoteName('#__facileforms_records'))
->set($fields)
->where($conditions);
$db->setQuery($query)
->execute();
$useremails=$db->getQuery(true);
$queryuserdetails = $db->getQuery(true);
$queryuserdetails = "SELECT * FROM `#__users` WHERE id='".$userid."'";
$db->setQuery($queryuserdetails);
$resultusers = $db->loadAssocList();
$usertoemail=$resultusers[0]['email'];
$queryrecord = $db->getQuery(true);
$queryrecord = "SELECT * FROM `#__facileforms_records` WHERE form = '".$formid."' AND user_id='".$userid."'";
$db->setQuery($queryrecord);
$resultrecords = $db->loadAssocList();
$entryid=$resultrecords[0]['id'];
$querypageheading = $db->getQuery(true);
$querypageheading = "SELECT `id`,`title`,`name`,`value` FROM `#__facileforms_subrecords` WHERE record = '".$entryid."' AND type!='Hidden Input'";
$db->setQuery($querypageheading);
$resultpage = $db->loadAssocList();
$body ="<h3>".$resultrecords[0]['title']." <strong>".$status."</strong></h3>";
$body .='<table style="border-color: #000000; background-color: #eeeeee;" cellpadding="10" border="1"><tbody><tr>
<td style="text-align: left;"><b>Name</b></td>
<td style="text-align: center;"><b>Value</b></td>
</tr>';
for($k=0;$k<count($resultpage);$k++)
{
$body .='<tr>
<td style="text-align: left;">'.$resultpage[$k]['title'].'</td>
<td style="text-align: left;">'.$resultpage[$k]['value'].'</td>
</tr>';
}
echo '</tbody></table>';
$to = $usertoemail;
$from =
$fromName = 'Anglo-Suisse Capital Limited';
$subject = "".$resultrecords[0]['title']."";
$htmlContent = $body;
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=UTF-8" . "\r\n";
// Additional headers
$headers .= 'From: '.$fromName.'<'.$from.'>' . "\r\n";
// Send email
if(mail($to, $subject, $htmlContent, $headers)){
echo "Your Request has been Decliend";
}else{
echo 'something is wrong';
}
}
else
{
?>
<h3>Approve request</h3>
<form method="post" name="comment" action="" >
<div class="form-group">
<label for="exampleInputEmail1">Request Number</label>
<input type="text" class="form-control" name="entryid" value="<?php echo $entryid;?>" disabled>
</div>
<div class="form-check form-check-inline">
<input class="form-check-input" type="radio" name="status" id="inlineRadio1" value="true">
<label class="form-check-label" for="inlineRadio1">Approve</label>
</div>
<div class="form-check form-check-inline">
<input class="form-check-input" type="radio" name="status" id="inlineRadio2" value="Decline">
<label class="form-check-label" for="inlineRadio2">Decline</label>
</div>
<div class="form-group">
<label for="exampleInputPassword1">Comments</label>
<textarea type="textarea" name="comment" class="form-control"></textarea>
</div>
<button type="submit" name="submit" class="btn btn-primary">Submit</button>
</form>
<?php
}
?>{/source}
- Details
- Written by: Rakesh Chaudhary-Upwork
- Category: Uncategorised
- Read Time: 7 mins
- Hits: 2