Skip to content

Commit

Permalink
Merge pull request #9506 from frederic34/printing
Browse files Browse the repository at this point in the history
printing remove no camelcaps function
  • Loading branch information
eldy committed Sep 15, 2018
2 parents e9159dd + 5862a5e commit 75f3dd9
Show file tree
Hide file tree
Showing 7 changed files with 110 additions and 132 deletions.
2 changes: 1 addition & 1 deletion htdocs/admin/oauthlogintokens.php
Expand Up @@ -342,7 +342,7 @@
$langs->load($driver);
$printer = new $classname($db);
//print '<pre>'.print_r($printer, true).'</pre>';
if (count($printer->getlist_available_printers())) {
if (count($printer->getlistAvailablePrinters())) {
if ($printer->listAvailablePrinters()==0) {
print $printer->resprint;
} else {
Expand Down
5 changes: 2 additions & 3 deletions htdocs/core/actions_printing.inc.php
Expand Up @@ -28,8 +28,7 @@
// Filename to print must be provided into 'file' parameter

// Print file
if ($action == 'print_file' && $user->rights->printing->read)
{
if ($action == 'print_file' && $user->rights->printing->read) {
$langs->load("printing");
require_once DOL_DOCUMENT_ROOT . '/core/modules/printing/modules_printing.php';
$objectprint = new PrintingDriver($db);
Expand All @@ -55,7 +54,7 @@
$subdir = 'commande';
}
try {
$ret = $printer->print_file(GETPOST('file', 'alpha'), $module, $subdir);
$ret = $printer->printFile(GETPOST('file', 'alpha'), $module, $subdir);
if ($ret > 0) {
//print '<pre>'.print_r($printer->errors, true).'</pre>';
setEventMessages($printer->error, $printer->errors, 'errors');
Expand Down
73 changes: 35 additions & 38 deletions htdocs/core/modules/printing/printgcp.modules.php
Expand Up @@ -44,14 +44,14 @@ class printing_printgcp extends PrintingDriver
public $google_secret = '';

/**
* @var string Error code (or message)
*/
public $error='';
* @var string Error code (or message)
*/
public $error = '';

/**
* @var string[] Error codes (or messages)
*/
public $errors = array();
* @var string[] Error codes (or messages)
*/
public $errors = array();

/**
* @var DoliDB Database handler.
Expand All @@ -75,8 +75,8 @@ function __construct($db)
global $conf, $langs, $dolibarr_main_url_root;

// Define $urlwithroot
$urlwithouturlroot=preg_replace('/'.preg_quote(DOL_URL_ROOT,'/').'$/i','',trim($dolibarr_main_url_root));
$urlwithroot=$urlwithouturlroot.DOL_URL_ROOT; // This is to use external domain name found into config file
$urlwithouturlroot = preg_replace('/'.preg_quote(DOL_URL_ROOT,'/').'$/i','',trim($dolibarr_main_url_root));
$urlwithroot = $urlwithouturlroot.DOL_URL_ROOT; // This is to use external domain name found into config file
//$urlwithroot=DOL_MAIN_URL_ROOT; // This is to use same domain name than current

$this->db = $db;
Expand All @@ -85,7 +85,7 @@ function __construct($db)
$this->conf[] = array(
'varname'=>'PRINTGCP_INFO',
'info'=>$langs->transnoentitiesnoconv("WarningModuleNotActive", "OAuth"),
'type'=>'info'
'type'=>'info',
);
} else {

Expand Down Expand Up @@ -144,7 +144,7 @@ function __construct($db)

$refreshtoken = $token->getRefreshToken();

$endoflife=$token->getEndOfLife();
$endoflife = $token->getEndOfLife();

if ($endoflife == $token::EOL_NEVER_EXPIRES)
{
Expand Down Expand Up @@ -183,9 +183,9 @@ function __construct($db)
*
* @return int 0 if OK, >0 if KO
*/
function listAvailablePrinters()
public function listAvailablePrinters()
{
global $bc, $conf, $langs;
global $conf, $langs;
$error = 0;
$langs->load('printing');

Expand All @@ -199,7 +199,7 @@ function listAvailablePrinters()
$html.= '<td>'.$langs->trans('GCP_Type').'</td>';
$html.= '<td align="center">'.$langs->trans("Select").'</td>';
$html.= '</tr>'."\n";
$list = $this->getlist_available_printers();
$list = $this->getlistAvailablePrinters();
//$html.= '<td><pre>'.print_r($list,true).'</pre></td>';
foreach ($list['available'] as $printer_det)
{
Expand Down Expand Up @@ -227,15 +227,13 @@ function listAvailablePrinters()
}


// phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps
/**
* Return list of available printers
*
* @return array list of printers
*/
function getlist_available_printers()
public function getlistAvailablePrinters()
{
// phpcs:enable
// Token storage
$storage = new DoliStorage($this->db, $this->conf);
// Setup the credentials for the requests
Expand Down Expand Up @@ -293,7 +291,6 @@ function getlist_available_printers()
return $ret;
}

// phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps
/**
* Print selected file
*
Expand All @@ -302,16 +299,17 @@ function getlist_available_printers()
* @param string $subdir subdir for file
* @return int 0 if OK, >0 if KO
*/
function print_file($file, $module, $subdir='')
public function printFile($file, $module, $subdir='')
{
// phpcs:enable
require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';

global $conf, $user;
$error = 0;

$fileprint=$conf->{$module}->dir_output;
if ($subdir!='') $fileprint.='/'.$subdir;
$fileprint = $conf->{$module}->dir_output;
if ($subdir!='') {
$fileprint.='/'.$subdir;
}
$fileprint.='/'.$file;
$mimetype = dol_mimetype($fileprint);
// select printer uri for module order, propal,...
Expand Down Expand Up @@ -342,7 +340,9 @@ function print_file($file, $module, $subdir='')

$ret = $this->sendPrintToPrinter($printer_id, $file, $fileprint, $mimetype);
$this->error = 'PRINTGCP: '.$ret['errormessage'];
if ($ret['status']!=1) $error++;
if ($ret['status']!=1) {
$error++;
}
return $error;
}

Expand Down Expand Up @@ -370,12 +370,13 @@ public function sendPrintToPrinter($printerid, $printjobtitle, $filepath, $conte
$contents = fread($handle, filesize($filepath));
fclose($handle);
// Prepare post fields for sending print
$post_fields = array('printerid' => $printerid,
'title' => $printjobtitle,
'contentTransferEncoding' => 'base64',
'content' => base64_encode($contents), // encode file content as base64
'contentType' => $contenttype
);
$post_fields = array(
'printerid' => $printerid,
'title' => $printjobtitle,
'contentTransferEncoding' => 'base64',
'content' => base64_encode($contents), // encode file content as base64
'contentType' => $contenttype,
);
// Dolibarr Token storage
$storage = new DoliStorage($this->db, $this->conf);
// Setup the credentials for the requests
Expand Down Expand Up @@ -410,20 +411,18 @@ public function sendPrintToPrinter($printerid, $printjobtitle, $filepath, $conte
// Send a request with api
$response = json_decode($apiService->request(self::PRINT_URL, 'POST', $post_fields), true);
//print '<tr><td><pre>'.print_r($response, true).'</pre></td></tr>';
return array('status' =>$response['success'],'errorcode' =>$response['errorCode'],'errormessage'=>$response['message']);
return array('status' => $response['success'], 'errorcode' => $response['errorCode'], 'errormessage' => $response['message']);
}


// phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps
/**
* List jobs print
*
* @return int 0 if OK, >0 if KO
*/
function list_jobs()
public function listJobs()
{
// phpcs:enable
global $conf, $db, $langs, $bc;
global $conf, $langs;

$error = 0;
$html = '';
Expand Down Expand Up @@ -489,13 +488,11 @@ function list_jobs()

$jobs = $responsedata['jobs'];
//$html .= '<pre>'.print_r($jobs['0'],true).'</pre>';
if (is_array($jobs))
{
foreach ($jobs as $value)
{
if (is_array($jobs)) {
foreach ($jobs as $value) {
$html .= '<tr class="oddeven">';
$html .= '<td>'.$value['id'].'</td>';
$dates=dol_print_date((int) substr($value['createTime'], 0, 10), 'dayhour');
$dates = dol_print_date((int) substr($value['createTime'], 0, 10), 'dayhour');
$html .= '<td>'.$dates.'</td>';
$html .= '<td>'.$value['ownerId'].'</td>';
$html .= '<td>'.$value['printerName'].'</td>';
Expand Down

0 comments on commit 75f3dd9

Please sign in to comment.