include(HTML2PDF_locale.php): failed to open stream in YII - yii-extensions

Trying to Use html to pdf extension in YII . After placing all the required files in its places and including the following code in config:
'ePdf' => array(
'class' => 'ext.yii-pdf.EYiiPdf',
'params' => array(
'mpdf' => array(
'librarySourcePath' => 'application.vendor.mpdf.*',
'constants' => array(
'_MPDF_TEMP_PATH' => Yii::getPathOfAlias('application.runtime'),
),
'class'=>'mpdf', // the literal class filename to be loaded from the vendors folder
/*'defaultParams' => array( // More info: http://mpdf1.com/manual/index.php?tid=184
'mode' => '', // This parameter specifies the mode of the new document.
'format' => 'A4', // format A4, A5, ...
'default_font_size' => 0, // Sets the default document font size in points (pt)
'default_font' => '', // Sets the default font-family for the new document.
'mgl' => 15, // margin_left. Sets the page margins for the new document.
'mgr' => 15, // margin_right
'mgt' => 16, // margin_top
'mgb' => 16, // margin_bottom
'mgh' => 9, // margin_header
'mgf' => 9, // margin_footer
'orientation' => 'P', // landscape or portrait orientation
)*/
),
'HTML2PDF' => array(
'librarySourcePath' => 'application.vendor.html2pdf.*',
'classFile' => 'html2pdf.class.php', // For adding to Yii::$classMap
/*'defaultParams' => array( // More info: http://wiki.spipu.net/doku.php?id=html2pdf:en:v4:accueil
'orientation' => 'P', // landscape or portrait orientation
'format' => 'A4', // format A4, A5, ...
'language' => 'en', // language: fr, en, it ...
'unicode' => true, // TRUE means clustering the input text IS unicode (default = true)
'encoding' => 'UTF-8', // charset encoding; Default is UTF-8
'marges' => array(5, 5, 5, 8), // margins by default, in order (left, top, right, bottom)
)*/
)
),
),
I get the following error
ERROR: include(HTML2PDF_locale.php): failed to open stream: No such
file or directory

It could be a namespace issue, add namespace app/ext .

Related

How to remove validation lastname from prestashop 1.7.8.3 backoffice

I have a question how to remove validation from LastName inside client address edit. I need to allow numbers inside this field.
I found here thread Prestashop : Remove Lastname Field Rules Validation From B.O, but this solution is not working.
Finally, I have caught the issue. You are editing in admin panel and I was sharing code for front end. Please try below steps for admin:
Step 1 - file classes/Address.php
'lastname' => ['type' => self::TYPE_STRING, 'validate' => 'isAnything', 'required' => true, 'size' => 255],
Change this to isAnything
Step 2 - src\PrestaShopBundle\Form\Admin\Sell\Address/CustomerAddressType.php
Change your code to below code:
line 209: add('last_name', TextType::class, [
'label' => $this->trans('Last name', 'Admin.Global'),
'help' => $genericInvalidCharsMessage,
'required' => true,
'constraints' => [
new NotBlank([
'message' => $this->trans(
'This field cannot be empty.', 'Admin.Notifications.Error'
),
]),
new CleanHtml(),
new TypedRegex([
'type' => TypedRegex::TYPE_GENERIC_NAME,
]),
new Length([
'max' => AddressConstraint::MAX_LAST_NAME_LENGTH,
'maxMessage' => $this->trans(
'This field cannot be longer than %limit% characters',
'Admin.Notifications.Error',
['%limit%' => AddressConstraint::MAX_LAST_NAME_LENGTH]
),
]),
],
])
Now, you are ready to go and check.
Go to the file classes/Address.php file:
'lastname' =>array('type' => self::TYPE_STRING, 'validate' => 'isCustomerName', 'required' => true, 'size' => 32),
to :
'lastname' =>array('type' => self::TYPE_STRING, 'validate' => 'isAnything', 'required' => true, 'size' => 32),
validate to isAnything.
I think you were modifying in customer class. Please try with Address.php.
Thanks for sharing the files.
I have resolved the case. You need to modify the classes/form/CustomerAddressForm.php
line 229
$isValid &= $this->validateField('lastname', 'isName', $this->translator->trans(
'Invalid name',
[],
'Shop.Forms.Errors'
));
Change to:
$isValid &= $this->validateField('lastname', 'isAnything', $this->translator->trans(
'Invalid name',
[],
'Shop.Forms.Errors'
));
I want to do this good with override. I have an issue with override this class. I have created module to override but it is not working. There is a way to override this without editing core files?
services:
_defaults:
public: true
form.type.customer_address:
class: 'Playdev\PrestaShopBundle\Form\Admin\Sell\Address\CustomCustomerAddressType'
public: true
arguments:
- '#prestashop.adapter.form.choice_provider.country_state_by_id'
- '#=service("prestashop.adapter.legacy.context").getContext().country.id'
- '#router'
tags:
- { name: form.type }
https://ibb.co/VVjnJYr
There is a file class override:
\modules\pd_overridemodule\src\PrestaShopBundle\Form\Admin\Sell\Address\CustomCustomerAddressType.php
https://ibb.co/7QPHrqx
And I have an error when I am inside Edit Address Form Backoffice
Type error: Too few arguments to function PrestaShopBundle\Form\Admin\Sell\Address\CustomerAddressType::__construct(), 0 passed in C:\laragon\www\prestabiolab\vendor\symfony\symfony\src\Symfony\Component\Form\FormRegistry.php on line 92 and exactly 5 expected
[Symfony\Component\Debug\Exception\FatalThrowableError 0]
https://ibb.co/YfwhtKq
I have found a solution
Need to create module and call hookactionCustomerAddressFormBuilderModifier.
public function hookactionCustomerAddressFormBuilderModifier(array $params)
{
/** #var $formBuilder \Symfony\Component\Form */
$formBuilder = $params['form_builder'];
// remove lastname field
$formBuilder->remove('last_name');
// get all fields without removed
$allFields = $formBuilder->all();
// remove all fields
foreach ($allFields as $inputField => $input) {
$formBuilder->remove($inputField);
}
foreach ($allFields as $inputField => $input) {
// normally add fields
$formBuilder->add($input);
// add fields after firstname
if ($inputField == 'first_name') {
$formBuilder->add('last_name', TextType::class, [
'label' => $this->trans('Last name', [], 'Admin.Global'),
'help' => $this->trans(
'Invalid characters:',
[],
'Admin.Notifications.Info'
) . ' ' . TypedRegexValidator::GENERIC_NAME_CHARS,
'required' => true,
'constraints' => [
new NotBlank([
'message' => $this->trans(
'This field cannot be empty.', [], 'Admin.Notifications.Error'
),
]),
new CleanHtml(),
new TypedRegex([
'type' => TypedRegex::TYPE_GENERIC_NAME,
]),
new Length([
'max' => AddressConstraint::MAX_LAST_NAME_LENGTH,
'maxMessage' => $this->trans(
'This field cannot be longer than %limit% characters',
['%limit%' => AddressConstraint::MAX_LAST_NAME_LENGTH],
'Admin.Notifications.Error',
),
]),
],
]);
}
}
}
Now I think it works okey with override :)

Pdf encryption in cakePdf using dompdf

I have researched on how to create a pdf using cakepdf. I have been able to successfully generated the pdf and attached to an email using using ceeram/CakePdf on GitHub. Now i want to encrypt the pdf sent by email. I have spent two days researching without any success. I tried the encryption tutorial on ceeram/CakePdf but it didn't work for me. I don't know what am doing wrong.
In my bootstrape i have:
CakePlugin::load('CakePdf', array('bootstrap' => true, 'routes' => true));
Configure::write('CakePdf', array(
'engine' => 'CakePdf.DomPdf',
'options' => array(
'print-media-type' => false,
'outline' => true,
'dpi' => 96
),
'margin' => array(
'bottom' => 15,
'left' => 50,
'right' => 30,
'top' => 45
),
'paperSize' => 'A4',
'orientation' => 'landscape',
'download' => false,
));
Configure::write('CakePdf.crypto', 'CakePdf.Pdftk');
In my action, i have:
$this->pdfConfig = array(
'orientation' => 'portrait',
'filename' => 'Invoice_'. 3,
'options' => array(
'protect' => true,
'userPassword' => '123'
),
'permissions'=>array('print','screen_readers','copy_contents')
);
$CakePdf = new CakePdf();
$CakePdf->template('confirmpdf', 'default');
//get the pdf string returned
$pdf = $CakePdf->output();
//or write it to file directly
$pdf = $CakePdf->write(APP . 'webroot'. DS .'files' . DS . 'userdetail.pdf');
$pdf = APP . 'webroot'. DS .'files' . DS . 'userdetail.pdf';
The pdf is generating fine as expected but its not been encrypted. What am i doing wrong?
Thanks in advance for your help.

install.php is not being run during installation

My install.php is not being run during installation.I checked everywhere.To be sure,I ran the code in install.php elsewhere and it worked well. But during installation only the install.php is being skipped somehow.My module name is Hotelreservation, hence the code in install.php is as below. Why is there no error display during installation ?
<?php
class Hotelreservation_Installer extends Engine_Package_Installer_Module
{
public function onInstall()
{
$this->_hotelroomsBrowsePage();
parent::onInstall();
}
protected function _hotelroomsBrowsePage()
{
$db = $this->getDb();
// profile page
$page_id = $db->select()
->from('engine4_core_pages', 'page_id')
->where('name = ?', 'hotelreservation_index_browse')
->limit(1)
->query()
->fetchColumn();
if (!$page_id) {
// Insert page
$db->insert('engine4_core_pages', array(
'name' => 'hotelreservation_index_browse',
'displayname' => 'HotelRooms Browse Page',
'title' => 'Browse Rooms',
'description' => 'this page displays rooms',
'custom' => 0,
));
$page_id = $db->lastInsertId();
// Insert main
$db->insert('engine4_core_content', array(
'type' => 'container',
'name' => 'main',
'page_id' => $page_id,
));
$main_id = $db->lastInsertId();
// Insert middle
$db->insert('engine4_core_content', array(
'type' => 'container',
'name' => 'middle',
'page_id' => $page_id,
'parent_content_id' => $main_id,
'order' => 2,
));
$middle_id = $db->lastInsertId();
// Insert hotelreservation.browse-menu
$db->insert('engine4_core_content', array(
'type' => 'widget',
'name' => 'hotelreservation.browse-menu',
'page_id' => $page_id,
'parent_content_id' => $middle_id,
'order' => 1,
));
// Insert core content
$db->insert('engine4_core_content', array(
'type' => 'widget',
'name' => 'core.content',
'page_id' => $page_id,
'parent_content_id' => $middle_id,
'order' => 2,
));
// Insert left
$db->insert('engine4_core_content', array(
'type' => 'container',
'name' => 'left',
'page_id' => $page_id,
'parent_content_id' => $main_id,
'order' => 3,
));
$left_id = $db->lastInsertId();
}
return $this;
}
}// end class
Did you add info to mainfest file like this in packages array
'callback' => array(
'path' => 'Your path to php file',
'class' => 'Hotelreservation_Installer',
),
I agree with Arif. Check the file manifest.php inside of //settings:
(info of module Album)
'callback' => array(
'path' => 'application/modules/Album/settings/install.php',
'class' => 'Album_Installer',
),
I had this same issue and got it to work.
It turns out that the installer looks in application/packages/module-yourmodule-x.x.x.json first. around line 35 you'll find:
"callback": {
"path": null,
"class": "Engine_Package_Installer_Module",
"priority": 100
},
change that to:
"callback": {
"path": "application/modules/Yourmodule/settings/install.php",
"class": "Yourmodule_Installer",
"priority": 100
},
now, when you run the installer, your install.php will be called.

Yii file CFormInputElement won't display unless explicitly marked "safe"

I'm trying to use Form Builder to build a simple file upload prompt. I want to specify the rule for the file to be similar to
array('formFile', 'file', 'allowEmpty' => false, 'types' => 'html'),
but something is wrong. The file upload element only appears if I explicitly mark the element as 'safe' (and remove the 'file' rule). What am I missing?
models/UploadForm.php
class UploadForm extends CFormModel
{
public $year;
public $formFile;
public function rules ()
{
return array(
array('year', 'required'),
array('year', 'date', 'format'=>'yyyy'),
// array('formFile', 'safe'),
array('formFile', 'file', 'allowEmpty' => false, 'types' => 'html'),
);
}
static public function getYearOptions () {...}
}
views/extranet/uploadForm.php
return array(
'title' => 'Select year',
'method' => 'post',
'enctype' => 'multipart/form-data',
'elements' => array(
'year' => array(
'type' => 'dropdownlist',
'items' => UploadForm::getYearOptions(),
),
'formFile' => array(
'type' => 'file',
'label' => 'form source file',
),
),
'buttons' => array(
'upload' => array(
'type' => 'submit',
'label' => 'upload',
),
),
);
controllers/ExtranetController.php
class ExtranetController extends CController
{
public function actionIndex ()
{
$form = new CForm('application.views.extranet.uploadForm', new UploadForm());
if ($form->submitted('upload') && $form->validate()) {...}
$this->render('index', array('form' => $form));
}
}
The reason for this is very simple.
The form builder only renders input elements which are considered safe (I.E. have a validation rule). What you have done is perfectly fine, except CFileValidator isn't "safe" by default, whereas other validators are safe.
The quickest way to solve this is the following:
// In your model::rules() function
return array(
array('formFile', 'file', 'allowEmpty' => false, 'types' => 'html', 'safe' => true),
);
Refer to these two links for more information: the CFileValidator#safe documentation, and the Github issue for a problem very similar to yours.

Yii Boilerplate and user management module

Can anyone please help and advice how to install yii user management module into yii boilerplate?
I downloaded auth module and place in common/modules folder, and edit backend/config/main.php as below:
$backendConfigDir = dirname(__FILE__);
$root = $backendConfigDir . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . '..';
$params = require_once($backendConfigDir . DIRECTORY_SEPARATOR . 'params.php');
// Setup some default path aliases. These alias may vary from projects.
Yii::setPathOfAlias('root', $root);
Yii::setPathOfAlias('common', $root . DIRECTORY_SEPARATOR . 'common');
Yii::setPathOfAlias('backend', $root . DIRECTORY_SEPARATOR . 'backend');
Yii::setPathOfAlias('www', $root . DIRECTORY_SEPARATOR . 'backend' . DIRECTORY_SEPARATOR . 'www');
/* uncomment if you need to use frontend folders */
/* Yii::setPathOfAlias('frontend', $root . DIRECTORY_SEPARATOR . 'frontend'); */
$mainLocalFile = $backendConfigDir . DIRECTORY_SEPARATOR . 'main-local.php';
$mainLocalConfiguration = file_exists($mainLocalFile) ? require($mainLocalFile) : array();
$mainEnvFile = $backendConfigDir . DIRECTORY_SEPARATOR . 'main-env.php';
$mainEnvConfiguration = file_exists($mainEnvFile) ? require($mainEnvFile) : array();
return CMap::mergeArray(
array(
'name' => '',
'basePath' => 'backend',
// set parameters
'params' => $params,
// preload components required before running applications
'preload' => array('bootstrap', 'log'),
'language' => 'en',
'import' => array(
'common.components.*',
'common.extensions.*',
/* uncomment if required */
/* 'common.extensions.behaviors.*', */
/* 'common.extensions.validators.*', */
'common.models.*',
// uncomment if behaviors are required
// you can also import a specific one
/* 'common.extensions.behaviors.*', */
// uncomment if validators on common folder are required
/* 'common.extensions.validators.*', */
'application.components.*',
'application.controllers.*',
'application.models.*',
'application.helpers.*',
),
/* uncomment and set if required */
'modules' => array(
'gii' => array(
'class' => 'system.gii.GiiModule',
'password' => 'clevertech',
'generatorPaths' => array(
'bootstrap.gii'
)
),
'auth' => array(
'strictMode' => true, // when enabled authorization items cannot be assigned children of the same type.
'userClass' => 'User', // the name of the user model class.
'userIdColumn' => 'id', // the name of the user id column.
'userNameColumn' => 'username', // the name of the user name column.
'appLayout' => 'application.views.layouts.main', // the layout used by the module.
),
),
'components' => array(
'clientScript' => array(
'class' => 'application.extensions.minify.EClientScript',
'combineScriptFiles' => !YII_DEBUG, // By default this is set to true, set this to true if you'd like to combine the script files
'combineCssFiles' => !YII_DEBUG, // By default this is set to true, set this to true if you'd like to combine the css files
'optimizeScriptFiles' => !YII_DEBUG, // #since: 1.1
'optimizeCssFiles' => !YII_DEBUG, // #since: 1.1
),
'request' => array(
'enableCsrfValidation' => true,
'enableCookieValidation' => true,
),
'authManager' => array(
'class' => 'CDbAuthManager',
'connectionID' => 'db',
'itemTable' => 'AuthItem',
'itemChildTable' => 'AuthItemChild',
'assignmentTable' => 'AuthAssignment',
'behaviors' => array(
'auth' => array(
'class' => 'auth.components.AuthBehavior',
'admins' => array('admin', 'foo', 'bar'), // users with full access
),
),
// 'behaviors' => array(
// 'auth' => array(
// 'class' => 'auth.components.AuthBehavior',
// ),
// ),
),
'image' => array(
'class' => 'application.extensions.image.CImageComponent',
// GD or ImageMagick
'driver' => 'GD',
// ImageMagick setup path
//'params' => array('directory' => '/opt/local/bin'),
),
'email' => array(
'class' => 'application.extensions.email.Email',
'delivery' => 'php', //Will use the php mailing function.
//May also be set to 'debug' to instead dump the contents of the email into the view
),
'user' => array(
// 'class' => 'WebUser',
'class' => 'auth.components.AuthWebUser',
// 'admins' => array('admin', 'foo', 'bar'), // users with full access
'allowAutoLogin' => true,
),
/* load bootstrap components */
'bootstrap' => array(
'class' => 'common.extensions.bootstrap.components.Bootstrap',
'responsiveCss' => true,
),
'cache' => array(
'class' => 'CApcCache',
// 'class' => 'CFileCache',
),
'errorHandler' => array(
'errorAction' => 'site/error'
),
'urlManager' => array(
'urlFormat' => 'path',
'showScriptName' => false,
'urlSuffix' => '/',
'rules' => $params['url.rules']
),
/* make sure you have your cache set correctly before uncommenting */
'cache' => $params['cache.core'],
'contentCache' => $params['cache.content']
),
), CMap::mergeArray($mainEnvConfiguration, $mainLocalConfiguration)
);
but it doesn't work error msg says:
Alias "auth.AuthModule" is invalid. Make sure it points to an existing PHP file and the file is readable.
Also, i have no idea what is the perfect path for uploaded files from both frontend and backend?
Change code as following under module
auth' => array(
'strictMode' => true, // when enabled authorization items cannot be assigned children of the same type.
'class'=>'common.modules.auth.AuthModule', // add this line.. and change AuthModule according to the auth module class name
'userClass' => 'User', // the name of the user model class.
'userIdColumn' => 'id', // the name of the user id column.
'userNameColumn' => 'username', // the name of the user name column.
'appLayout' => 'application.views.layouts.main', // the layout used by the module.
),
Hope this will work..