How to Display Tabs after form is saved in YII Framework - yii

I want to display tabs after the header form is saved, Please see attached image,

You can add parameter in to redirect URL after save method. Then in your view, add code like;
$activeTab= null;
if(isset($_GET['tab'])){
$activeTab = $_GET['tab'];
}
and in your tabs class control the value of the $activeTab variable
if($activeTab == 'Reflists'){
echo "<li class = "blabla active">Reflist</li>";
}
else {
echo "<li class = "blabla">Reflist</li>";
}
this is example of the tab code.

Here some working example
from Controller.
$activeTab = 0;
if(isset($_POST['WorPerformance']))
{
$activeTab = 2; //set the selected tabs here
$worperfm->attributes=$_POST['WorPerformance'];
if($worperfm->save()){
$msg2 = CHtml::link('View Details',array('view','id'=>$worperfm->WOR_ID));
Yii::app()->user->setFlash('success','You data have been saved successfully. '.$msg2);
}
}
$this->render('view',array(
'model'=>$this->loadModel($id),
'endorsp'=>$endorsp, //variable tabs 0
'enddetail'=>$enddetail, //variable tabs 1
'worperfm'=>$worperfm, //variable tabs 2
'activeTab'=>$activeTab,//pass the variable here
));
from View :
<?php
$this->widget('zii.widgets.jui.CJuiTabs',array(
'tabs'=>array(
'PF Log Details'=>array('id'=>'endetails-id','content'=>$this->renderPartial(
'/enddetail/_formpf',
array('model'=>$model),TRUE
)),
'Endorsement Species'=>array('id'=>'endorsespecies-id','content'=>$this->renderPartial(
'/endorspecies/_formClone2',
array('model'=>$model),TRUE
)),
'Work Performance'=>array('id'=>'worperform-id','content'=>$this->renderPartial(
'/worPerformance/_formpf',array('worPerformance'=>$worperfm
),TRUE)),
),
'options'=>array(
'collapsible'=>true,
'selected'=>$activeTab,//get from controller variable 'activeTab'=>$activeTab
),
'id'=>'MyTab-Menu',
));
?>

Related

Why Laravel only saves 1 image out of multiple images uploaded?

I have a <input type="file" id="uploadfiles" name="uploadfiles[]"> set my form enctype='multipart/form-data' and I don't know why I can only save the first image selected even I select multiple images. Here says I have selected 2 files:
But in the controller, it only saves the 1st image.
This is my controller
if ($request->hasFile('uploadfiles')) {
$cntr = 0;
$images = $request->uploadfiles;
foreach ($images as $key => $file) {
$tstamp = '_' . now()->format('YmdHis'). $cntr ;
$orgnlname = $file->getClientOriginalName();
$tempext = $file->getClientOriginalExtension();
$tempfilename = pathinfo($orgnlname)['filename']. $tstamp. '.' . $tempext;
if ($key==2) {
return 123;
}
$img = Image::make($file)->encode($tempext, 50);
Storage::disk('local')->put('/private/uploads/'.$modulename.'/'. $tempfilename, $img, 'private');
$cntr++;
}
}
It's been 3 days since I started to fix this issue. but I think now I need help.
It might be the cause of foreach with $key attribute;
You can directly start with;
if ( isset($request->uploadfiles) ) {
foreach(request()->file('uploadfiles') as $file){
//yourcodehere
}

Drupal 8: When I update the node field to a specific value, how to call my module (managefinishdate.module) to update another field?

I am having a node type with machine name to_do_item, and I want to create a module called managefinishdate to update the node: when a user edit the node's field (field_status) to "completed" and click "save", then the module will auto update the field_date_finished to current date.
I have tried to create the module and already success to install in "Extend":
function managefinishdate_todolist_update(\Drupal\Core\Entity\EntityInterface $entity) {
...
}
however, I am not sure is this module being called, because whatever I echo inside, seems nothing appeared.
<?php
use Drupal\Core\Entity\EntityInterface;
use Drupal\node\Entity\Node;
/** * Implements hook_ENTITY_TYPE_update().
* If a user update status to Completed,
* update the finished date as save date
*/
function managefinishdate_todolist_update(\Drupal\Core\Entity\EntityInterface $entity) {
$node = \Drupal::routeMatch()->getParameter('node');
print_r($node);
//$entity_type = 'node';
//$bundles = ['to_do_item'];
//$fld_finishdate = 'field_date_finished';
//if ($entity->getEntityTypeId() != $entity_type || !in_array($entity->bundle(), $bundles)) {
//return;
//}
//$current_date=date("Y-m-d");
//$entity->{$fld_finishdate}->setValue($current_date);
}
Following Drupal convention, your module named 'manage_finish_date' should contain a 'manage_finish_date.module file that sits in the root directory that should look like this:
<?php
use Drupal\node\Entity\Node;
/**
* Implements hook_ENTITY_TYPE_insert().
*/
function manage_finish_date_node_insert(Node $node) {
ManageFinishDate::update_time();
}
/**
* Implements hook_ENTITY_TYPE_update().
*/
function manage_finish_date_node_update(Node $node) {
ManageFinishDate::update_time();
}
You should also have another file called 'src/ManageFinishDate.php' that should look like this:
<?php
namespace Drupal\manage_finish_date;
use Drupal;
use Drupal\node\Entity\Node;
class ManageFinishDate {
public static function update_time($node, $action = 'create') {
// Entity bundles to act on
$bundles = array('to_do_item');
if (in_array($node->bundle(), $bundles)) {
// Load the node and update
$status = $node->field_status->value;
$node_to_update = Node::load($node);
if ($status == 'completed') {
$request_time = Drupal::time();
$node_to_update->set('field_date_finished', $request_time);
$node_to_update->save();
}
}
}
}
The code is untested, but should work. Make sure that the module name, and namespace match as well as the class filename and class name match for it to work. Also, clear you cache once uploaded.
This will handle newly created and updated nodes alike.
Please look after this sample code which may help you:
function YOUR_MODULE_entity_presave(Drupal\Core\Entity\EntityInterface $entity) {
switch ($entity->bundle()) {
//Replace CONTENT_TYPE with your actual content type
case 'CONTENT_TYPE':
$node = \Drupal::routeMatch()->getParameter('node');
if ($node instanceof \Drupal\node\NodeInterface) {
// Set the current date
}
break;
}
}

fix footer image in tcpdf

$path = Yii::app()->basePath;
require_once($path . '/extensions/tcpdf/tcpdf.php');
$pdf = new TCPDF();
$pdf->setPrintHeader(false);
$pdf->setPrintFooter(true);
$pdf->SetAutoPageBreak(TRUE, 0);
$pdf->AddPage();
$pdf->SetLineWidth(0.1);
$pdf->SetFont('times', '', 10);
$pdf->SetMargins(20, 20, 20, true);
$footer_image_file = Yii::app()->request->baseUrl.'/images/logo.jpg';
$content = '<div> $content </div>';
$pdf->writeHTML($content, true, false, true, false, '');
ob_end_clean();
$pdf->Output("Reports.pdf", "D");
I want to add image in fooder for every new pages.. please anyone help me...
Simply put the code displaying the image within the Footer() base method. This base method is called for any new page by either the AddPage() method and Close().
Important : The Footer method should not be called directly.
This method is supposed to be implemented in your class, so override it like this :
function Footer()
{
.... /* Put your code here (see a working example below) */
$logoX = 186; // 186mm. The logo will be displayed on the right side close to the border of the page
$logoFileName = "/images/myLogo.jpg";
$logoWidth = 15; // 15mm
$logo = $this->PageNo() . ' | '. $this->Image($logoFileName, $logoX, $this->GetY()+2, $logoWidth);
$this->SetX($this->w - $this->documentRightMargin - $logoWidth); // documentRightMargin = 18
$this->Cell(10,10, $logo, 0, 0, 'R');
}
I hope this helps and I've well understood your question.
function Footer()
{
.... /* Put your code here (see a working example below) */
$logoX = 40; //
$logoFileName = "/images/myLogo.jpg";
$logoWidth = 130; // 15mm
$logoY = 280;
$logo = $this->PageNo() . ' | '. $this->Image($logoFileName, $logoX, $logoY, $logoWidth);
$this->SetX($this->w - $this->documentRightMargin - $logoWidth); // documentRightMargin = 18
$this->Cell(10,10, $logo, 0, 0, 'C');
}
This codes are perfectly placed a image in the center of page footer.Thanks a lot pti_jul.:-)))))

How to show the custom PDF template while clicking the button

I want to show the PDF Template in new window while clicking the button in Sales Order. I created the button in sales order process using user event script. after that i'm unable to proceed it. It is possible to show the custom PDF template in new window while clicking the sales order?
My CODE:
USER EVENT SCRIPT:
// creating button in user event script before load event in view mode
unction userEventBeforeLoad(type, form, request){
if(type == 'view'){
var internalId = nlapiGetRecordId();
if (internalId != null) {
var createPdfUrl = nlapiResolveURL('SUITELET', 'customscript_back0rdered_itm_pdf', 'customdeploy_backord_itm_pdf_dep', false);
createPdfUrl += '&id=' + internalId;
//---add a button and call suitelet on click that button and it will open a new window
var addButton = form.addButton('custpage_printpdf', 'Print PDF', "window.open('" + createPdfUrl + "');");
}
else {
nlapiLogExecution('DEBUG', 'Error', 'Internaal id of the record is null');
}
}
}
SUITELET SCRIPT:
function suitelet(request, response){
var xml = "<?xml version=\"1.0\"?>\n<!DOCTYPE pdf PUBLIC \"-//big.faceless.org//report\" \"report-1.1.dtd\">\n";
xml += "<pdf>";
xml += "<head><macrolist><macro id=\"myfooter\"><p align=\"center\"><pagenumber /></p></macro></macrolist></head>";
xml += "<body size= \"A4\" footer=\"myfooter\" footer-height=\"0.5in\">";
var record = request.getParameter('internalId');
xml +="record"; //Add values(in string format) what you want to show in pdf
xml += "</body></pdf>";
var file = nlapiXMLToPDF(xml);
response.setContentType('PDF', 'Print.pdf ', 'inline');
response.write(file.getValue());
}
thanks in advance
The way I did it recently:
User Event Adds the Button that calls a suitelet (window.open('suitelet URL'))
Suitelet Renders the custom template
You can do the rendering like this insise a Suitelet (params: request, response), the custscript_pdf_template points to an html file on the cabinet using the NetSuite Advanced HTML syntax
var template = nlapiGetContext().getSetting('SCRIPT', 'custscript_pdf_template');
var purchaseOrder = nlapiLoadRecord('purchaseorder', tranId);
var xmlTemplate = nlapiLoadFile(template);
var renderer = nlapiCreateTemplateRenderer();
var file;
xmlTemplate = xmlTemplate.getValue();
renderer.setTemplate(xmlTemplate);
renderer.addRecord('record', purchaseOrder);
xmlTemplate = renderer.renderToString();
file = nlapiXMLToPDF(xmlTemplate);
resObj = file.getValue();
response.setContentType('PDF', 'printOut.pdf', 'inline');
response.write(resObj)

Manual Page Break in TCPDF

I am using TCPDF to generate the PDF in one of my projects. I simply create a HTML file and give it to the TCPDF to handle the PDF generation. But now I have some HTML where multiple certificates are added one after the other and I want to have a page break in it. Page Break should be decided by HTML i.e. I want to know if there is any identifier in HTML which TCPDF understands and then accordingly adds a page break into the generated PDF.
How could I do this?
I'm using <br pagebreak="true"/>.
Find method writeHTML and code
if ($dom[$key]['tag'] AND isset($dom[$key]['attribute']['pagebreak'])) {
// check for pagebreak
if (($dom[$key]['attribute']['pagebreak'] == 'true') OR ($dom[$key]['attribute']['pagebreak'] == 'left') OR ($dom[$key]['attribute']['pagebreak'] == 'right')) {
// add a page (or trig AcceptPageBreak() for multicolumn mode)
$this->checkPageBreak($this->PageBreakTrigger + 1);
}
if ((($dom[$key]['attribute']['pagebreak'] == 'left') AND (((!$this->rtl) AND (($this->page % 2) == 0)) OR (($this->rtl) AND (($this->page % 2) != 0))))
OR (($dom[$key]['attribute']['pagebreak'] == 'right') AND (((!$this->rtl) AND (($this->page % 2) != 0)) OR (($this->rtl) AND (($this->page % 2) == 0))))) {
// add a page (or trig AcceptPageBreak() for multicolumn mode)
$this->checkPageBreak($this->PageBreakTrigger + 1);
}
}
You might use TCPDF's AddPage() method in combination with explode() and a suitable delimiter:
$pdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8',
false);
// TCPDF initialization code (...)
$delimiter = '<h1>';
$html = file_get_contents('./test.html');
$chunks = explode($delimiter, $html);
$cnt = count($chunks);
for ($i = 0; $i < $cnt; $i++) {
$pdf->writeHTML($delimiter . $chunks[$i], true, 0, true, 0);
if ($i < $cnt - 1) {
$pdf->AddPage();
}
}
// Reset pointer to the last page
$pdf->lastPage();
// Close and output PDF document
$pdf->Output('test.pdf', 'I');
I tried using
<br pagebreak="true" />
or
<tcpdf method="AddPage" />
each of them resulted not in starting new page at the top of the page but adding the full A4-page empty space in between HTML text. So if text ended in the middle of the page and then page break was inserted, the new text was written from the middle of the next page. Which I didn't want.
What worked was this (found it here TCPDF forcing a new page):
$pdf->writeHTML($content, true, 0, true, 0);
$pdf->AddPage();
$pdf->setPage($pdf->getPage());
This now starts with writing text on top of the page.
TCPDF support the 'pagebreak' attribute for HTML tags and CSS properties 'page-break-before' and 'page-break-after'.
For example you can use <br pagebreak="true" />.
Check the official http://www.tcpdf.org website and forums for further information.
With version 5.9.142 from 2011-12-23 we could use the page-break-before, page-break-inside css properties, like this:
<div style="page-break-inside:avoid;">
some non breakable text
</div>
For someone who still has the same problem with page-break TCPDF library
You can use <div style="page-break-before:always"></div> OR <br pagebreak="true"/>
to break page manually in your HTML content.
Use $tcpdf->AddPage() to break page manually in your code.
When you set SetAutoPageBreak(TRUE, 10); that means: when the height of document reach to (bottom - 10) then move the cursor to new page. So if you want to have more space, just reduce the number into 0. It will draw until the end of the document without any margin from bottom.
Remember that TCPDF only accept the double quote (") for attributes of tags. Don't use single quote (') for your tag.
<div style='page-break-before:always' => WRONG
<div style="page-break-before:always" => RIGHT
It takes 8 hours from me because this issue :(
According to http://www.tcpdf.org/examples/example_049.phps you can use something like this
$html .= '<tcpdf method="AddPage" /><h2>Graphic Functions</h2>';
You need to verify that parameter K_TCPDF_CALLS_IN_HTML in TCPDF configuration file is true.
You can also follow this method to accomplish your needs:
$htmlcontent1="CERTIFICATE NUMBER 1 IMAGE HERE";
// output the HTML content
$pdf->writeHTML($htmlcontent1, true, 0, true, 0);
// reset pointer to the last page
$pdf->lastPage();
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
// Print a table
// add a page
$pdf->AddPage();
$htmlcontent1="CERTIFICATE NUMBER 1 IMAGE HERE";
// output the HTML content
$pdf->writeHTML($htmlcontent1, true, 0, true, 0);
// reset pointer to the last page
$pdf->lastPage();
// ---------------------------------------------------------
//Close and output PDF document
$pdf->Output('textcertificate.pdf', 'D');
Hopes it helps someone :)
Thanks
Giving your element the page-break-after, page-break-before or page-break-inside property via CSS will apply the attribute pagebreak or pagebreakafter to the html tag during TCPDF runtime.
// page-break-inside
if (isset($dom[$key]['style']['page-break-inside']) AND ($dom[$key]['style']['page-break-inside'] == 'avoid')) {
$dom[$key]['attribute']['nobr'] = 'true';
}
// page-break-before
if (isset($dom[$key]['style']['page-break-before'])) {
if ($dom[$key]['style']['page-break-before'] == 'always') {
$dom[$key]['attribute']['pagebreak'] = 'true';
} elseif ($dom[$key]['style']['page-break-before'] == 'left') {
$dom[$key]['attribute']['pagebreak'] = 'left';
} elseif ($dom[$key]['style']['page-break-before'] == 'right') {
$dom[$key]['attribute']['pagebreak'] = 'right';
}
}
// page-break-after
if (isset($dom[$key]['style']['page-break-after'])) {
if ($dom[$key]['style']['page-break-after'] == 'always') {
$dom[$key]['attribute']['pagebreakafter'] = 'true';
} elseif ($dom[$key]['style']['page-break-after'] == 'left') {
$dom[$key]['attribute']['pagebreakafter'] = 'left';
} elseif ($dom[$key]['style']['page-break-after'] == 'right') {
$dom[$key]['attribute']['pagebreakafter'] = 'right';
}
}