Scrutinizer Auto-Fixes

This commit consists of patches automatically generated for this project on https://scrutinizer-ci.com
This commit is contained in:
Scrutinizer Auto-Fixer 2019-11-11 22:59:36 +00:00
parent 8c1bba5a60
commit 038bda254d
10 changed files with 2227 additions and 2227 deletions

View File

@ -30,27 +30,27 @@ require_once DOL_DOCUMENT_ROOT.'/core/class/ldap.class.php';
require_once DOL_DOCUMENT_ROOT.'/core/lib/ldap.lib.php';
// Load translation files required by the page
$langs->loadLangs(array("admin","members","ldap"));
$langs->loadLangs(array("admin", "members", "ldap"));
$id = GETPOST('rowid', 'int');
$action = GETPOST('action', 'alpha');
// Security check
$result=restrictedArea($user, 'adherent', $id, 'adherent_type');
$result = restrictedArea($user, 'adherent', $id, 'adherent_type');
$object = new AdherentType($db);
$object->fetch($id);
// Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context
$hookmanager->initHooks(array('membertypeldapcard','globalcard'));
$hookmanager->initHooks(array('membertypeldapcard', 'globalcard'));
/*
* Actions
*/
$parameters=array();
$reshook=$hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
$parameters = array();
$reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
if (empty($reshook))
@ -148,12 +148,12 @@ print '<td>'.$langs->trans("Value").'</td>';
print '</tr>';
// LDAP reading
$ldap=new Ldap();
$result=$ldap->connect_bind();
$ldap = new Ldap();
$result = $ldap->connect_bind();
if ($result > 0)
{
$info=$object->_load_ldap_info();
$dn=$object->_load_ldap_dn($info, 1);
$info = $object->_load_ldap_info();
$dn = $object->_load_ldap_dn($info, 1);
$search = "(".$object->_load_ldap_dn($info, 2).")";
$records = $ldap->getAttribute($dn, $search);
@ -161,15 +161,15 @@ if ($result > 0)
//print_r($records);
// Show tree
if (((! is_numeric($records)) || $records != 0) && (! isset($records['count']) || $records['count'] > 0))
if (((!is_numeric($records)) || $records != 0) && (!isset($records['count']) || $records['count'] > 0))
{
if (! is_array($records))
if (!is_array($records))
{
print '<tr class="oddeven"><td colspan="2"><font class="error">'.$langs->trans("ErrorFailedToReadLDAP").'</font></td></tr>';
}
else
{
$result=show_ldap_content($records, 0, $records['count'], true);
$result = show_ldap_content($records, 0, $records['count'], true);
}
}
else

View File

@ -22,7 +22,7 @@
*/
// Put here all includes required by your class file
require_once DOL_DOCUMENT_ROOT . '/core/class/commonobject.class.php';
require_once DOL_DOCUMENT_ROOT.'/core/class/commonobject.class.php';
//require_once DOL_DOCUMENT_ROOT . '/societe/class/societe.class.php';
//require_once DOL_DOCUMENT_ROOT . '/product/class/product.class.php';
@ -86,7 +86,7 @@ class BOM extends CommonObject
/**
* @var array Array with all fields and their property. Do not use it as a static var. It may be modified by constructor.
*/
public $fields=array(
public $fields = array(
'rowid' => array('type'=>'integer', 'label'=>'TechnicalID', 'enabled'=>1, 'visible'=>-1, 'position'=>1, 'notnull'=>1, 'index'=>1, 'comment'=>"Id",),
'entity' => array('type'=>'integer', 'label'=>'Entity', 'enabled'=>1, 'visible'=>0, 'notnull'=> 1, 'default'=>1, 'index'=>1, 'position'=>5),
'ref' => array('type'=>'varchar(128)', 'label'=>'Ref', 'enabled'=>1, 'noteditable'=>1, 'visible'=>4, 'position'=>10, 'notnull'=>1, 'default'=>'(PROV)', 'index'=>1, 'searchall'=>1, 'comment'=>"Reference of BOM", 'showoncombobox'=>'1',),
@ -158,7 +158,7 @@ class BOM extends CommonObject
/**
* @var array List of child tables. To know object to delete on cascade.
*/
protected $childtablesoncascade=array('bom_bomline');
protected $childtablesoncascade = array('bom_bomline');
/**
* @var BOMLine[] Array of subtable lines
@ -178,11 +178,11 @@ class BOM extends CommonObject
$this->db = $db;
if (empty($conf->global->MAIN_SHOW_TECHNICAL_ID) && isset($this->fields['rowid'])) $this->fields['rowid']['visible']=0;
if (empty($conf->multicompany->enabled) && isset($this->fields['entity'])) $this->fields['entity']['enabled']=0;
if (empty($conf->global->MAIN_SHOW_TECHNICAL_ID) && isset($this->fields['rowid'])) $this->fields['rowid']['visible'] = 0;
if (empty($conf->multicompany->enabled) && isset($this->fields['entity'])) $this->fields['entity']['enabled'] = 0;
// Unset fields that are disabled
foreach($this->fields as $key => $val)
foreach ($this->fields as $key => $val)
{
if (isset($val['enabled']) && empty($val['enabled']))
{
@ -191,13 +191,13 @@ class BOM extends CommonObject
}
// Translate some data of arrayofkeyval
foreach($this->fields as $key => $val)
foreach ($this->fields as $key => $val)
{
if (is_array($val['arrayofkeyval']))
{
foreach($val['arrayofkeyval'] as $key2 => $val2)
foreach ($val['arrayofkeyval'] as $key2 => $val2)
{
$this->fields[$key]['arrayofkeyval'][$key2]=$langs->trans($val2);
$this->fields[$key]['arrayofkeyval'][$key2] = $langs->trans($val2);
}
}
}
@ -237,7 +237,7 @@ class BOM extends CommonObject
// Load source object
$result = $object->fetchCommon($fromid);
if ($result > 0 && ! empty($object->table_element_line)) $object->fetchLines();
if ($result > 0 && !empty($object->table_element_line)) $object->fetchLines();
// Get lines so they will be clone
//foreach($object->lines as $line)
@ -249,18 +249,18 @@ class BOM extends CommonObject
unset($object->import_key);
// Clear fields
$object->ref = empty($this->fields['ref']['default']) ? $langs->trans("copy_of_").$object->ref: $this->fields['ref']['default'];
$object->label = empty($this->fields['label']['default']) ? $langs->trans("CopyOf")." ".$object->label: $this->fields['label']['default'];
$object->ref = empty($this->fields['ref']['default']) ? $langs->trans("copy_of_").$object->ref : $this->fields['ref']['default'];
$object->label = empty($this->fields['label']['default']) ? $langs->trans("CopyOf")." ".$object->label : $this->fields['label']['default'];
$object->status = self::STATUS_DRAFT;
// ...
// Clear extrafields that are unique
if (is_array($object->array_options) && count($object->array_options) > 0)
{
$extrafields->fetch_name_optionals_label($object->table_element);
foreach($object->array_options as $key => $option)
foreach ($object->array_options as $key => $option)
{
$shortkey = preg_replace('/options_/', '', $key);
if (! empty($extrafields->attributes[$this->element]['unique'][$shortkey]))
if (!empty($extrafields->attributes[$this->element]['unique'][$shortkey]))
{
//var_dump($key); var_dump($clonedObj->array_options[$key]); exit;
unset($object->array_options[$key]);
@ -277,7 +277,7 @@ class BOM extends CommonObject
$this->errors = $object->errors;
}
if (! $error)
if (!$error)
{
// copy internal contacts
if ($this->copy_linked_contact($object, 'internal') < 0)
@ -286,7 +286,7 @@ class BOM extends CommonObject
}
}
if (! $error)
if (!$error)
{
// copy external contacts if same company
if (property_exists($this, 'socid') && $this->socid == $object->socid)
@ -322,7 +322,7 @@ class BOM extends CommonObject
public function fetch($id, $ref = null)
{
$result = $this->fetchCommon($id, $ref);
if ($result > 0 && ! empty($this->table_element_line)) $this->fetchLines();
if ($result > 0 && !empty($this->table_element_line)) $this->fetchLines();
return $result;
}
@ -333,7 +333,7 @@ class BOM extends CommonObject
*/
public function fetchLines()
{
$this->lines=array();
$this->lines = array();
$result = $this->fetchLinesCommon();
return $result;
@ -356,40 +356,40 @@ class BOM extends CommonObject
dol_syslog(__METHOD__, LOG_DEBUG);
$records=array();
$records = array();
$sql = 'SELECT ';
$sql .= $this->getFieldList();
$sql .= ' FROM ' . MAIN_DB_PREFIX . $this->table_element. ' as t';
$sql .= ' FROM '.MAIN_DB_PREFIX.$this->table_element.' as t';
if ($this->ismultientitymanaged) $sql .= ' WHERE t.entity IN ('.getEntity($this->table_element).')';
else $sql .= ' WHERE 1 = 1';
// Manage filter
$sqlwhere = array();
if (count($filter) > 0) {
foreach ($filter as $key => $value) {
if ($key=='t.rowid') {
$sqlwhere[] = $key . '='. $value;
if ($key == 't.rowid') {
$sqlwhere[] = $key.'='.$value;
}
elseif (strpos($key, 'date') !== false) {
$sqlwhere[] = $key.' = \''.$this->db->idate($value).'\'';
}
elseif ($key=='customsql') {
elseif ($key == 'customsql') {
$sqlwhere[] = $value;
}
else {
$sqlwhere[] = $key . ' LIKE \'%' . $this->db->escape($value) . '%\'';
$sqlwhere[] = $key.' LIKE \'%'.$this->db->escape($value).'%\'';
}
}
}
if (count($sqlwhere) > 0) {
$sql .= ' AND (' . implode(' '.$filtermode.' ', $sqlwhere).')';
$sql .= ' AND ('.implode(' '.$filtermode.' ', $sqlwhere).')';
}
if (!empty($sortfield)) {
$sql .= $this->db->order($sortfield, $sortorder);
}
if (!empty($limit)) {
$sql .= ' ' . $this->db->plimit($limit, $offset);
$sql .= ' '.$this->db->plimit($limit, $offset);
}
$resql = $this->db->query($sql);
@ -407,8 +407,8 @@ class BOM extends CommonObject
return $records;
} else {
$this->errors[] = 'Error ' . $this->db->lasterror();
dol_syslog(__METHOD__ . ' ' . join(',', $this->errors), LOG_ERR);
$this->errors[] = 'Error '.$this->db->lasterror();
dol_syslog(__METHOD__.' '.join(',', $this->errors), LOG_ERR);
return -1;
}
@ -472,21 +472,21 @@ class BOM extends CommonObject
global $langs, $conf;
$langs->load("mrp");
if (! empty($conf->global->BOM_ADDON))
if (!empty($conf->global->BOM_ADDON))
{
$mybool=false;
$mybool = false;
$file = $conf->global->BOM_ADDON.".php";
$classname = $conf->global->BOM_ADDON;
// Include file with class
$dirmodels=array_merge(array('/'), (array) $conf->modules_parts['models']);
$dirmodels = array_merge(array('/'), (array) $conf->modules_parts['models']);
foreach ($dirmodels as $reldir)
{
$dir = dol_buildpath($reldir."core/modules/bom/");
// Load file with numbering class (if found)
$mybool|=@include_once $dir.$file;
$mybool |= @include_once $dir.$file;
}
if ($mybool === false)
@ -504,7 +504,7 @@ class BOM extends CommonObject
}
else
{
$this->error=$obj->error;
$this->error = $obj->error;
//dol_print_error($this->db,get_class($this)."::getNextNumRef ".$obj->error);
return "";
}
@ -529,7 +529,7 @@ class BOM extends CommonObject
require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
$error=0;
$error = 0;
// Protection
if ($this->statut == self::STATUS_VALIDATED)
@ -546,12 +546,12 @@ class BOM extends CommonObject
return -1;
}*/
$now=dol_now();
$now = dol_now();
$this->db->begin();
// Define new ref
if (! $error && (preg_match('/^[\(]?PROV/i', $this->ref) || empty($this->ref))) // empty should not happened, but when it occurs, the test save life
if (!$error && (preg_match('/^[\(]?PROV/i', $this->ref) || empty($this->ref))) // empty should not happened, but when it occurs, the test save life
{
$this->fetch_product();
$num = $this->getNextNumRef($this->product);
@ -564,30 +564,30 @@ class BOM extends CommonObject
// Validate
$sql = "UPDATE ".MAIN_DB_PREFIX.$this->table_element;
$sql.= " SET ref = '".$this->db->escape($num)."',";
$sql.= " status = ".self::STATUS_VALIDATED.",";
$sql.= " date_valid='".$this->db->idate($now)."',";
$sql.= " fk_user_valid = ".$user->id;
$sql.= " WHERE rowid = ".$this->id;
$sql .= " SET ref = '".$this->db->escape($num)."',";
$sql .= " status = ".self::STATUS_VALIDATED.",";
$sql .= " date_valid='".$this->db->idate($now)."',";
$sql .= " fk_user_valid = ".$user->id;
$sql .= " WHERE rowid = ".$this->id;
dol_syslog(get_class($this)."::validate()", LOG_DEBUG);
$resql=$this->db->query($sql);
if (! $resql)
$resql = $this->db->query($sql);
if (!$resql)
{
dol_print_error($this->db);
$this->error=$this->db->lasterror();
$this->error = $this->db->lasterror();
$error++;
}
if (! $error && ! $notrigger)
if (!$error && !$notrigger)
{
// Call trigger
$result=$this->call_trigger('BOM_VALIDATE', $user);
$result = $this->call_trigger('BOM_VALIDATE', $user);
if ($result < 0) $error++;
// End call triggers
}
if (! $error)
if (!$error)
{
$this->oldref = $this->ref;
@ -595,17 +595,17 @@ class BOM extends CommonObject
if (preg_match('/^[\(]?PROV/i', $this->ref))
{
// Now we rename also files into index
$sql = 'UPDATE '.MAIN_DB_PREFIX."ecm_files set filename = CONCAT('".$this->db->escape($this->newref)."', SUBSTR(filename, ".(strlen($this->ref)+1).")), filepath = 'bom/".$this->db->escape($this->newref)."'";
$sql.= " WHERE filename LIKE '".$this->db->escape($this->ref)."%' AND filepath = 'bom/".$this->db->escape($this->ref)."' and entity = ".$conf->entity;
$sql = 'UPDATE '.MAIN_DB_PREFIX."ecm_files set filename = CONCAT('".$this->db->escape($this->newref)."', SUBSTR(filename, ".(strlen($this->ref) + 1).")), filepath = 'bom/".$this->db->escape($this->newref)."'";
$sql .= " WHERE filename LIKE '".$this->db->escape($this->ref)."%' AND filepath = 'bom/".$this->db->escape($this->ref)."' and entity = ".$conf->entity;
$resql = $this->db->query($sql);
if (! $resql) { $error++; $this->error = $this->db->lasterror(); }
if (!$resql) { $error++; $this->error = $this->db->lasterror(); }
// We rename directory ($this->ref = old ref, $num = new ref) in order not to lose the attachments
$oldref = dol_sanitizeFileName($this->ref);
$newref = dol_sanitizeFileName($num);
$dirsource = $conf->bom->dir_output.'/'.$oldref;
$dirdest = $conf->bom->dir_output.'/'.$newref;
if (! $error && file_exists($dirsource))
if (!$error && file_exists($dirsource))
{
dol_syslog(get_class($this)."::validate() rename dir ".$dirsource." into ".$dirdest);
@ -613,13 +613,13 @@ class BOM extends CommonObject
{
dol_syslog("Rename ok");
// Rename docs starting with $oldref with $newref
$listoffiles=dol_dir_list($conf->bom->dir_output.'/'.$newref, 'files', 1, '^'.preg_quote($oldref, '/'));
foreach($listoffiles as $fileentry)
$listoffiles = dol_dir_list($conf->bom->dir_output.'/'.$newref, 'files', 1, '^'.preg_quote($oldref, '/'));
foreach ($listoffiles as $fileentry)
{
$dirsource=$fileentry['name'];
$dirdest=preg_replace('/^'.preg_quote($oldref, '/').'/', $newref, $dirsource);
$dirsource=$fileentry['path'].'/'.$dirsource;
$dirdest=$fileentry['path'].'/'.$dirdest;
$dirsource = $fileentry['name'];
$dirdest = preg_replace('/^'.preg_quote($oldref, '/').'/', $newref, $dirsource);
$dirsource = $fileentry['path'].'/'.$dirsource;
$dirdest = $fileentry['path'].'/'.$dirdest;
@rename($dirsource, $dirdest);
}
}
@ -628,13 +628,13 @@ class BOM extends CommonObject
}
// Set new ref and current status
if (! $error)
if (!$error)
{
$this->ref = $num;
$this->status = self::STATUS_VALIDATED;
}
if (! $error)
if (!$error)
{
$this->db->commit();
return 1;
@ -738,34 +738,34 @@ class BOM extends CommonObject
global $dolibarr_main_authentication, $dolibarr_main_demo;
global $menumanager;
if (! empty($conf->dol_no_mouse_hover)) $notooltip=1; // Force disable tooltips
if (!empty($conf->dol_no_mouse_hover)) $notooltip = 1; // Force disable tooltips
$result = '';
$label = '<u>' . $langs->trans("BillOfMaterials") . '</u>';
$label.= '<br>';
$label.= '<b>' . $langs->trans('Ref') . ':</b> ' . $this->ref;
$label = '<u>'.$langs->trans("BillOfMaterials").'</u>';
$label .= '<br>';
$label .= '<b>'.$langs->trans('Ref').':</b> '.$this->ref;
$url = dol_buildpath('/bom/bom_card.php', 1).'?id='.$this->id;
if ($option != 'nolink')
{
// Add param to save lastsearch_values or not
$add_save_lastsearch_values=($save_lastsearch_value == 1 ? 1 : 0);
if ($save_lastsearch_value == -1 && preg_match('/list\.php/', $_SERVER["PHP_SELF"])) $add_save_lastsearch_values=1;
if ($add_save_lastsearch_values) $url.='&save_lastsearch_values=1';
$add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
if ($save_lastsearch_value == -1 && preg_match('/list\.php/', $_SERVER["PHP_SELF"])) $add_save_lastsearch_values = 1;
if ($add_save_lastsearch_values) $url .= '&save_lastsearch_values=1';
}
$linkclose='';
$linkclose = '';
if (empty($notooltip))
{
if (! empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER))
if (!empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER))
{
$label=$langs->trans("ShowBillOfMaterials");
$linkclose.=' alt="'.dol_escape_htmltag($label, 1).'"';
$label = $langs->trans("ShowBillOfMaterials");
$linkclose .= ' alt="'.dol_escape_htmltag($label, 1).'"';
}
$linkclose.=' title="'.dol_escape_htmltag($label, 1).'"';
$linkclose.=' class="classfortooltip'.($morecss?' '.$morecss:'').'"';
$linkclose .= ' title="'.dol_escape_htmltag($label, 1).'"';
$linkclose .= ' class="classfortooltip'.($morecss ? ' '.$morecss : '').'"';
/*
$hookmanager->initHooks(array('bomdao'));
@ -774,22 +774,22 @@ class BOM extends CommonObject
if ($reshook > 0) $linkclose = $hookmanager->resPrint;
*/
}
else $linkclose = ($morecss?' class="'.$morecss.'"':'');
else $linkclose = ($morecss ? ' class="'.$morecss.'"' : '');
$linkstart = '<a href="'.$url.'"';
$linkstart.=$linkclose.'>';
$linkend='</a>';
$linkstart .= $linkclose.'>';
$linkend = '</a>';
$result .= $linkstart;
if ($withpicto) $result.=img_object(($notooltip?'':$label), ($this->picto?$this->picto:'generic'), ($notooltip?(($withpicto != 2) ? 'class="paddingright"' : ''):'class="'.(($withpicto != 2) ? 'paddingright ' : '').'classfortooltip"'), 0, 0, $notooltip?0:1);
if ($withpicto != 2) $result.= $this->ref;
if ($withpicto) $result .= img_object(($notooltip ? '' : $label), ($this->picto ? $this->picto : 'generic'), ($notooltip ? (($withpicto != 2) ? 'class="paddingright"' : '') : 'class="'.(($withpicto != 2) ? 'paddingright ' : '').'classfortooltip"'), 0, 0, $notooltip ? 0 : 1);
if ($withpicto != 2) $result .= $this->ref;
$result .= $linkend;
//if ($withpicto != 2) $result.=(($addlabel && $this->label) ? $sep . dol_trunc($this->label, ($addlabel > 1 ? $addlabel : 0)) : '');
global $action,$hookmanager;
global $action, $hookmanager;
$hookmanager->initHooks(array('bomdao'));
$parameters=array('id'=>$this->id, 'getnomurl'=>$result);
$reshook=$hookmanager->executeHooks('getNomUrl', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
$parameters = array('id'=>$this->id, 'getnomurl'=>$result);
$reshook = $hookmanager->executeHooks('getNomUrl', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
if ($reshook > 0) $result = $hookmanager->resPrint;
else $result .= $hookmanager->resPrint;
@ -842,10 +842,10 @@ class BOM extends CommonObject
public function info($id)
{
$sql = 'SELECT rowid, date_creation as datec, tms as datem,';
$sql.= ' fk_user_creat, fk_user_modif';
$sql.= ' FROM '.MAIN_DB_PREFIX.$this->table_element.' as t';
$sql.= ' WHERE t.rowid = '.$id;
$result=$this->db->query($sql);
$sql .= ' fk_user_creat, fk_user_modif';
$sql .= ' FROM '.MAIN_DB_PREFIX.$this->table_element.' as t';
$sql .= ' WHERE t.rowid = '.$id;
$result = $this->db->query($sql);
if ($result)
{
if ($this->db->num_rows($result))
@ -893,7 +893,7 @@ class BOM extends CommonObject
*/
public function getLinesArray()
{
$this->lines=array();
$this->lines = array();
$objectline = new BOMLine($this->db);
$result = $objectline->fetchAll('ASC', 'position', 0, 0, array('customsql'=>'fk_bom = '.$this->id));
@ -924,16 +924,16 @@ class BOM extends CommonObject
*/
public function generateDocument($modele, $outputlangs, $hidedetails = 0, $hidedesc = 0, $hideref = 0, $moreparams = null)
{
global $conf,$langs;
global $conf, $langs;
$langs->load("mrp");
if (! dol_strlen($modele)) {
if (!dol_strlen($modele)) {
$modele = 'standard';
if ($this->modelpdf) {
$modele = $this->modelpdf;
} elseif (! empty($conf->global->BOM_ADDON_PDF)) {
} elseif (!empty($conf->global->BOM_ADDON_PDF)) {
$modele = $conf->global->BOM_ADDON_PDF;
}
}
@ -972,7 +972,7 @@ class BOM extends CommonObject
$error = 0;
$this->output = '';
$this->error='';
$this->error = '';
dol_syslog(__METHOD__, LOG_DEBUG);
@ -1043,7 +1043,7 @@ class BOMLine extends CommonObject
/**
* @var array Array with all fields and their property. Do not use it as a static var. It may be modified by constructor.
*/
public $fields=array(
public $fields = array(
'rowid' => array('type'=>'integer', 'label'=>'LineID', 'enabled'=>1, 'visible'=>-1, 'position'=>1, 'notnull'=>1, 'index'=>1, 'comment'=>"Id",),
'fk_bom' => array('type'=>'integer:BillOfMaterials:societe/class/bom.class.php', 'label'=>'BillOfMaterials', 'enabled'=>1, 'visible'=>1, 'position'=>10, 'notnull'=>1, 'index'=>1,),
'fk_product' => array('type'=>'integer:Product:product/class/product.class.php', 'label'=>'Product', 'enabled'=>1, 'visible'=>1, 'position'=>20, 'notnull'=>1, 'index'=>1,),
@ -1079,11 +1079,11 @@ class BOMLine extends CommonObject
$this->db = $db;
if (empty($conf->global->MAIN_SHOW_TECHNICAL_ID) && isset($this->fields['rowid'])) $this->fields['rowid']['visible']=0;
if (empty($conf->multicompany->enabled) && isset($this->fields['entity'])) $this->fields['entity']['enabled']=0;
if (empty($conf->global->MAIN_SHOW_TECHNICAL_ID) && isset($this->fields['rowid'])) $this->fields['rowid']['visible'] = 0;
if (empty($conf->multicompany->enabled) && isset($this->fields['entity'])) $this->fields['entity']['enabled'] = 0;
// Unset fields that are disabled
foreach($this->fields as $key => $val)
foreach ($this->fields as $key => $val)
{
if (isset($val['enabled']) && empty($val['enabled']))
{
@ -1092,13 +1092,13 @@ class BOMLine extends CommonObject
}
// Translate some data of arrayofkeyval
foreach($this->fields as $key => $val)
foreach ($this->fields as $key => $val)
{
if (is_array($val['arrayofkeyval']))
{
foreach($val['arrayofkeyval'] as $key2 => $val2)
foreach ($val['arrayofkeyval'] as $key2 => $val2)
{
$this->fields[$key]['arrayofkeyval'][$key2]=$langs->trans($val2);
$this->fields[$key]['arrayofkeyval'][$key2] = $langs->trans($val2);
}
}
}
@ -1149,40 +1149,40 @@ class BOMLine extends CommonObject
dol_syslog(__METHOD__, LOG_DEBUG);
$records=array();
$records = array();
$sql = 'SELECT ';
$sql .= $this->getFieldList();
$sql .= ' FROM ' . MAIN_DB_PREFIX . $this->table_element. ' as t';
$sql .= ' FROM '.MAIN_DB_PREFIX.$this->table_element.' as t';
if ($this->ismultientitymanaged) $sql .= ' WHERE t.entity IN ('.getEntity($this->table_element).')';
else $sql .= ' WHERE 1 = 1';
// Manage filter
$sqlwhere = array();
if (count($filter) > 0) {
foreach ($filter as $key => $value) {
if ($key=='t.rowid') {
$sqlwhere[] = $key . '='. $value;
if ($key == 't.rowid') {
$sqlwhere[] = $key.'='.$value;
}
elseif (strpos($key, 'date') !== false) {
$sqlwhere[] = $key.' = \''.$this->db->idate($value).'\'';
}
elseif ($key=='customsql') {
elseif ($key == 'customsql') {
$sqlwhere[] = $value;
}
else {
$sqlwhere[] = $key . ' LIKE \'%' . $this->db->escape($value) . '%\'';
$sqlwhere[] = $key.' LIKE \'%'.$this->db->escape($value).'%\'';
}
}
}
if (count($sqlwhere) > 0) {
$sql .= ' AND (' . implode(' '.$filtermode.' ', $sqlwhere).')';
$sql .= ' AND ('.implode(' '.$filtermode.' ', $sqlwhere).')';
}
if (!empty($sortfield)) {
$sql .= $this->db->order($sortfield, $sortorder);
}
if (!empty($limit)) {
$sql .= ' ' . $this->db->plimit($limit, $offset);
$sql .= ' '.$this->db->plimit($limit, $offset);
}
$resql = $this->db->query($sql);
@ -1200,8 +1200,8 @@ class BOMLine extends CommonObject
return $records;
} else {
$this->errors[] = 'Error ' . $this->db->lasterror();
dol_syslog(__METHOD__ . ' ' . join(',', $this->errors), LOG_ERR);
$this->errors[] = 'Error '.$this->db->lasterror();
dol_syslog(__METHOD__.' '.join(',', $this->errors), LOG_ERR);
return -1;
}
@ -1248,34 +1248,34 @@ class BOMLine extends CommonObject
{
global $db, $conf, $langs, $hookmanager;
if (! empty($conf->dol_no_mouse_hover)) $notooltip=1; // Force disable tooltips
if (!empty($conf->dol_no_mouse_hover)) $notooltip = 1; // Force disable tooltips
$result = '';
$label = '<u>' . $langs->trans("BillOfMaterialsLine") . '</u>';
$label.= '<br>';
$label.= '<b>' . $langs->trans('Ref') . ':</b> ' . $this->ref;
$label = '<u>'.$langs->trans("BillOfMaterialsLine").'</u>';
$label .= '<br>';
$label .= '<b>'.$langs->trans('Ref').':</b> '.$this->ref;
$url = dol_buildpath('/bom/bomline_card.php', 1).'?id='.$this->id;
if ($option != 'nolink')
{
// Add param to save lastsearch_values or not
$add_save_lastsearch_values=($save_lastsearch_value == 1 ? 1 : 0);
if ($save_lastsearch_value == -1 && preg_match('/list\.php/', $_SERVER["PHP_SELF"])) $add_save_lastsearch_values=1;
if ($add_save_lastsearch_values) $url.='&save_lastsearch_values=1';
$add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
if ($save_lastsearch_value == -1 && preg_match('/list\.php/', $_SERVER["PHP_SELF"])) $add_save_lastsearch_values = 1;
if ($add_save_lastsearch_values) $url .= '&save_lastsearch_values=1';
}
$linkclose='';
$linkclose = '';
if (empty($notooltip))
{
if (! empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER))
if (!empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER))
{
$label=$langs->trans("ShowBillOfMaterialsLine");
$linkclose.=' alt="'.dol_escape_htmltag($label, 1).'"';
$label = $langs->trans("ShowBillOfMaterialsLine");
$linkclose .= ' alt="'.dol_escape_htmltag($label, 1).'"';
}
$linkclose.=' title="'.dol_escape_htmltag($label, 1).'"';
$linkclose.=' class="classfortooltip'.($morecss?' '.$morecss:'').'"';
$linkclose .= ' title="'.dol_escape_htmltag($label, 1).'"';
$linkclose .= ' class="classfortooltip'.($morecss ? ' '.$morecss : '').'"';
/*
$hookmanager->initHooks(array('bomlinedao'));
@ -1284,22 +1284,22 @@ class BOMLine extends CommonObject
if ($reshook > 0) $linkclose = $hookmanager->resPrint;
*/
}
else $linkclose = ($morecss?' class="'.$morecss.'"':'');
else $linkclose = ($morecss ? ' class="'.$morecss.'"' : '');
$linkstart = '<a href="'.$url.'"';
$linkstart.=$linkclose.'>';
$linkend='</a>';
$linkstart .= $linkclose.'>';
$linkend = '</a>';
$result .= $linkstart;
if ($withpicto) $result.=img_object(($notooltip?'':$label), ($this->picto?$this->picto:'generic'), ($notooltip?(($withpicto != 2) ? 'class="paddingright"' : ''):'class="'.(($withpicto != 2) ? 'paddingright ' : '').'classfortooltip"'), 0, 0, $notooltip?0:1);
if ($withpicto != 2) $result.= $this->ref;
if ($withpicto) $result .= img_object(($notooltip ? '' : $label), ($this->picto ? $this->picto : 'generic'), ($notooltip ? (($withpicto != 2) ? 'class="paddingright"' : '') : 'class="'.(($withpicto != 2) ? 'paddingright ' : '').'classfortooltip"'), 0, 0, $notooltip ? 0 : 1);
if ($withpicto != 2) $result .= $this->ref;
$result .= $linkend;
//if ($withpicto != 2) $result.=(($addlabel && $this->label) ? $sep . dol_trunc($this->label, ($addlabel > 1 ? $addlabel : 0)) : '');
global $action,$hookmanager;
global $action, $hookmanager;
$hookmanager->initHooks(array('bomlinedao'));
$parameters=array('id'=>$this->id, 'getnomurl'=>$result);
$reshook=$hookmanager->executeHooks('getNomUrl', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
$parameters = array('id'=>$this->id, 'getnomurl'=>$result);
$reshook = $hookmanager->executeHooks('getNomUrl', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
if ($reshook > 0) $result = $hookmanager->resPrint;
else $result .= $hookmanager->resPrint;
@ -1340,10 +1340,10 @@ class BOMLine extends CommonObject
public function info($id)
{
$sql = 'SELECT rowid, date_creation as datec, tms as datem,';
$sql.= ' fk_user_creat, fk_user_modif';
$sql.= ' FROM '.MAIN_DB_PREFIX.$this->table_element.' as t';
$sql.= ' WHERE t.rowid = '.$id;
$result=$this->db->query($sql);
$sql .= ' fk_user_creat, fk_user_modif';
$sql .= ' FROM '.MAIN_DB_PREFIX.$this->table_element.' as t';
$sql .= ' WHERE t.rowid = '.$id;
$result = $this->db->query($sql);
if ($result)
{
if ($this->db->num_rows($result))

View File

@ -36,7 +36,7 @@ if ($action == 'builddoc' && $permissiontoadd)
{
if (is_numeric(GETPOST('model', 'alpha')))
{
$error=$langs->trans("ErrorFieldRequired", $langs->transnoentities("Model"));
$error = $langs->trans("ErrorFieldRequired", $langs->transnoentities("Model"));
}
else
{
@ -61,34 +61,34 @@ if ($action == 'builddoc' && $permissiontoadd)
if (GETPOST('fk_bank', 'int')) {
// this field may come from an external module
$object->fk_bank = GETPOST('fk_bank', 'int');
} elseif (! empty($object->fk_account)) {
} elseif (!empty($object->fk_account)) {
$object->fk_bank = $object->fk_account;
}
//}
$outputlangs = $langs;
$newlang='';
$newlang = '';
if ($conf->global->MAIN_MULTILANGS && empty($newlang) && GETPOST('lang_id', 'aZ09')) $newlang=GETPOST('lang_id', 'aZ09');
if ($conf->global->MAIN_MULTILANGS && empty($newlang) && isset($object->thirdparty->default_lang)) $newlang=$object->thirdparty->default_lang; // for proposal, order, invoice, ...
if ($conf->global->MAIN_MULTILANGS && empty($newlang) && isset($object->default_lang)) $newlang=$object->default_lang; // for thirdparty
if (! empty($newlang))
if ($conf->global->MAIN_MULTILANGS && empty($newlang) && GETPOST('lang_id', 'aZ09')) $newlang = GETPOST('lang_id', 'aZ09');
if ($conf->global->MAIN_MULTILANGS && empty($newlang) && isset($object->thirdparty->default_lang)) $newlang = $object->thirdparty->default_lang; // for proposal, order, invoice, ...
if ($conf->global->MAIN_MULTILANGS && empty($newlang) && isset($object->default_lang)) $newlang = $object->default_lang; // for thirdparty
if (!empty($newlang))
{
$outputlangs = new Translate("", $conf);
$outputlangs->setDefaultLang($newlang);
}
// To be sure vars is defined
if (empty($hidedetails)) $hidedetails=0;
if (empty($hidedesc)) $hidedesc=0;
if (empty($hideref)) $hideref=0;
if (empty($moreparams)) $moreparams=null;
if (empty($hidedetails)) $hidedetails = 0;
if (empty($hidedesc)) $hidedesc = 0;
if (empty($hideref)) $hideref = 0;
if (empty($moreparams)) $moreparams = null;
$result= $object->generateDocument($object->modelpdf, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams);
$result = $object->generateDocument($object->modelpdf, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams);
if ($result <= 0)
{
setEventMessages($object->error, $object->errors, 'errors');
$action='';
$action = '';
}
else
{
@ -110,10 +110,10 @@ if ($action == 'builddoc' && $permissiontoadd)
// Delete file in doc form
if ($action == 'remove_file' && $permissiontoadd)
{
if (! empty($upload_dir)) {
if (!empty($upload_dir)) {
require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
if (empty($object->id) || ! $object->id > 0)
if (empty($object->id) || !$object->id > 0)
{
// Reload to get all modified line records and be ready for hooks
$ret = $object->fetch($id);
@ -121,9 +121,9 @@ if ($action == 'remove_file' && $permissiontoadd)
}
$langs->load("other");
$filetodelete=GETPOST('file', 'alpha');
$file = $upload_dir . '/' . $filetodelete;
$ret=dol_delete_file($file, 0, 0, 0, $object);
$filetodelete = GETPOST('file', 'alpha');
$file = $upload_dir.'/'.$filetodelete;
$ret = dol_delete_file($file, 0, 0, 0, $object);
if ($ret) setEventMessages($langs->trans("FileWasRemoved", $filetodelete), null, 'mesgs');
else setEventMessages($langs->trans("ErrorFailToDeleteFile", $filetodelete), null, 'errors');

File diff suppressed because it is too large Load Diff

View File

@ -68,7 +68,7 @@ class doc_generic_bom_odt extends ModelePDFBom
global $conf, $langs, $mysoc;
// Load translation files required by the page
$langs->loadLangs(array("main","companies"));
$langs->loadLangs(array("main", "companies"));
$this->db = $db;
$this->name = "ODT templates";
@ -79,19 +79,19 @@ class doc_generic_bom_odt extends ModelePDFBom
$this->type = 'odt';
$this->page_largeur = 0;
$this->page_hauteur = 0;
$this->format = array($this->page_largeur,$this->page_hauteur);
$this->marge_gauche=0;
$this->marge_droite=0;
$this->marge_haute=0;
$this->marge_basse=0;
$this->format = array($this->page_largeur, $this->page_hauteur);
$this->marge_gauche = 0;
$this->marge_droite = 0;
$this->marge_haute = 0;
$this->marge_basse = 0;
$this->option_multilang = 1; // Dispo en plusieurs langues
$this->option_freetext = 1; // Support add of a personalised text
$this->option_draft_watermark = 0; // Support add of a watermark on drafts
// Recupere emetteur
$this->emetteur=$mysoc;
if (! $this->emetteur->country_code) $this->emetteur->country_code=substr($langs->defaultlang, -2); // By default if not defined
$this->emetteur = $mysoc;
if (!$this->emetteur->country_code) $this->emetteur->country_code = substr($langs->defaultlang, -2); // By default if not defined
}
@ -103,83 +103,83 @@ class doc_generic_bom_odt extends ModelePDFBom
*/
public function info($langs)
{
global $conf,$langs;
global $conf, $langs;
// Load translation files required by the page
$langs->loadLangs(array("errors","companies"));
$langs->loadLangs(array("errors", "companies"));
$form = new Form($this->db);
$texte = $this->description.".<br>\n";
$texte.= '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
$texte.= '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
$texte.= '<input type="hidden" name="action" value="setModuleOptions">';
$texte.= '<input type="hidden" name="param1" value="BOM_ADDON_PDF_ODT_PATH">';
$texte.= '<table class="nobordernopadding" width="100%">';
$texte .= '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
$texte .= '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
$texte .= '<input type="hidden" name="action" value="setModuleOptions">';
$texte .= '<input type="hidden" name="param1" value="BOM_ADDON_PDF_ODT_PATH">';
$texte .= '<table class="nobordernopadding" width="100%">';
// List of directories area
$texte.= '<tr><td>';
$texttitle=$langs->trans("ListOfDirectories");
$listofdir=explode(',', preg_replace('/[\r\n]+/', ',', trim($conf->global->BOM_ADDON_PDF_ODT_PATH)));
$listoffiles=array();
foreach($listofdir as $key=>$tmpdir)
$texte .= '<tr><td>';
$texttitle = $langs->trans("ListOfDirectories");
$listofdir = explode(',', preg_replace('/[\r\n]+/', ',', trim($conf->global->BOM_ADDON_PDF_ODT_PATH)));
$listoffiles = array();
foreach ($listofdir as $key=>$tmpdir)
{
$tmpdir=trim($tmpdir);
$tmpdir=preg_replace('/DOL_DATA_ROOT/', DOL_DATA_ROOT, $tmpdir);
if (! $tmpdir) {
$tmpdir = trim($tmpdir);
$tmpdir = preg_replace('/DOL_DATA_ROOT/', DOL_DATA_ROOT, $tmpdir);
if (!$tmpdir) {
unset($listofdir[$key]); continue;
}
if (! is_dir($tmpdir)) $texttitle.=img_warning($langs->trans("ErrorDirNotFound", $tmpdir), 0);
if (!is_dir($tmpdir)) $texttitle .= img_warning($langs->trans("ErrorDirNotFound", $tmpdir), 0);
else
{
$tmpfiles=dol_dir_list($tmpdir, 'files', 0, '\.(ods|odt)');
if (count($tmpfiles)) $listoffiles=array_merge($listoffiles, $tmpfiles);
$tmpfiles = dol_dir_list($tmpdir, 'files', 0, '\.(ods|odt)');
if (count($tmpfiles)) $listoffiles = array_merge($listoffiles, $tmpfiles);
}
}
$texthelp=$langs->trans("ListOfDirectoriesForModelGenODT");
$texthelp = $langs->trans("ListOfDirectoriesForModelGenODT");
// Add list of substitution keys
$texthelp.='<br>'.$langs->trans("FollowingSubstitutionKeysCanBeUsed").'<br>';
$texthelp.=$langs->transnoentitiesnoconv("FullListOnOnlineDocumentation"); // This contains an url, we don't modify it
$texthelp .= '<br>'.$langs->trans("FollowingSubstitutionKeysCanBeUsed").'<br>';
$texthelp .= $langs->transnoentitiesnoconv("FullListOnOnlineDocumentation"); // This contains an url, we don't modify it
$texte.= $form->textwithpicto($texttitle, $texthelp, 1, 'help', '', 1);
$texte.= '<div><div style="display: inline-block; min-width: 100px; vertical-align: middle;">';
$texte.= '<textarea class="flat" cols="60" name="value1">';
$texte.=$conf->global->BOM_ADDON_PDF_ODT_PATH;
$texte.= '</textarea>';
$texte.= '</div><div style="display: inline-block; vertical-align: middle;">';
$texte.= '<input type="submit" class="button" value="'.$langs->trans("Modify").'" name="Button">';
$texte.= '<br></div></div>';
$texte .= $form->textwithpicto($texttitle, $texthelp, 1, 'help', '', 1);
$texte .= '<div><div style="display: inline-block; min-width: 100px; vertical-align: middle;">';
$texte .= '<textarea class="flat" cols="60" name="value1">';
$texte .= $conf->global->BOM_ADDON_PDF_ODT_PATH;
$texte .= '</textarea>';
$texte .= '</div><div style="display: inline-block; vertical-align: middle;">';
$texte .= '<input type="submit" class="button" value="'.$langs->trans("Modify").'" name="Button">';
$texte .= '<br></div></div>';
// Scan directories
$nbofiles=count($listoffiles);
if (! empty($conf->global->BOM_ADDON_PDF_ODT_PATH))
$nbofiles = count($listoffiles);
if (!empty($conf->global->BOM_ADDON_PDF_ODT_PATH))
{
$texte.=$langs->trans("NumberOfModelFilesFound").': <b>';
$texte .= $langs->trans("NumberOfModelFilesFound").': <b>';
//$texte.=$nbofiles?'<a id="a_'.get_class($this).'" href="#">':'';
$texte.=count($listoffiles);
$texte .= count($listoffiles);
//$texte.=$nbofiles?'</a>':'';
$texte.='</b>';
$texte .= '</b>';
}
if ($nbofiles)
{
$texte.='<div id="div_'.get_class($this).'" class="hidden">';
foreach($listoffiles as $file)
$texte .= '<div id="div_'.get_class($this).'" class="hidden">';
foreach ($listoffiles as $file)
{
$texte.=$file['name'].'<br>';
$texte .= $file['name'].'<br>';
}
$texte.='<div id="div_'.get_class($this).'">';
$texte .= '<div id="div_'.get_class($this).'">';
}
$texte.= '</td>';
$texte .= '</td>';
$texte.= '<td valign="top" rowspan="2" class="hideonsmartphone">';
$texte.= $langs->trans("ExampleOfDirectoriesForModelGen");
$texte.= '</td>';
$texte.= '</tr>';
$texte .= '<td valign="top" rowspan="2" class="hideonsmartphone">';
$texte .= $langs->trans("ExampleOfDirectoriesForModelGen");
$texte .= '</td>';
$texte .= '</tr>';
$texte.= '</table>';
$texte.= '</form>';
$texte .= '</table>';
$texte .= '</form>';
return $texte;
}
@ -199,7 +199,7 @@ class doc_generic_bom_odt extends ModelePDFBom
public function write_file($object, $outputlangs, $srctemplatepath, $hidedetails = 0, $hidedesc = 0, $hideref = 0)
{
// phpcs:enable
global $user,$langs,$conf,$mysoc,$hookmanager;
global $user, $langs, $conf, $mysoc, $hookmanager;
if (empty($srctemplatepath))
{
@ -208,28 +208,28 @@ class doc_generic_bom_odt extends ModelePDFBom
}
// Add odtgeneration hook
if (! is_object($hookmanager))
if (!is_object($hookmanager))
{
include_once DOL_DOCUMENT_ROOT.'/core/class/hookmanager.class.php';
$hookmanager=new HookManager($this->db);
$hookmanager = new HookManager($this->db);
}
$hookmanager->initHooks(array('odtgeneration'));
global $action;
if (! is_object($outputlangs)) $outputlangs=$langs;
$sav_charset_output=$outputlangs->charset_output;
$outputlangs->charset_output='UTF-8';
if (!is_object($outputlangs)) $outputlangs = $langs;
$sav_charset_output = $outputlangs->charset_output;
$outputlangs->charset_output = 'UTF-8';
$outputlangs->loadLangs(array("main", "dict", "companies", "bills"));
if ($conf->bom->dir_output)
{
// If $object is id instead of object
if (! is_object($object))
if (!is_object($object))
{
$id = $object;
$object = new Bom($this->db);
$result=$object->fetch($id);
$result = $object->fetch($id);
if ($result < 0)
{
dol_print_error($this->db, $object->error);
@ -237,16 +237,16 @@ class doc_generic_bom_odt extends ModelePDFBom
}
}
$dir = $conf->bom->multidir_output[isset($object->entity)?$object->entity:1];
$dir = $conf->bom->multidir_output[isset($object->entity) ? $object->entity : 1];
$objectref = dol_sanitizeFileName($object->ref);
if (! preg_match('/specimen/i', $objectref)) $dir.= "/" . $objectref;
$file = $dir . "/" . $objectref . ".odt";
if (!preg_match('/specimen/i', $objectref)) $dir .= "/".$objectref;
$file = $dir."/".$objectref.".odt";
if (! file_exists($dir))
if (!file_exists($dir))
{
if (dol_mkdir($dir) < 0)
{
$this->error=$langs->transnoentities("ErrorCanNotCreateDir", $dir);
$this->error = $langs->transnoentities("ErrorCanNotCreateDir", $dir);
return -1;
}
}
@ -254,25 +254,25 @@ class doc_generic_bom_odt extends ModelePDFBom
if (file_exists($dir))
{
//print "srctemplatepath=".$srctemplatepath; // Src filename
$newfile=basename($srctemplatepath);
$newfiletmp=preg_replace('/\.od(t|s)/i', '', $newfile);
$newfiletmp=preg_replace('/template_/i', '', $newfiletmp);
$newfiletmp=preg_replace('/modele_/i', '', $newfiletmp);
$newfiletmp=$objectref.'_'.$newfiletmp;
$newfile = basename($srctemplatepath);
$newfiletmp = preg_replace('/\.od(t|s)/i', '', $newfile);
$newfiletmp = preg_replace('/template_/i', '', $newfiletmp);
$newfiletmp = preg_replace('/modele_/i', '', $newfiletmp);
$newfiletmp = $objectref.'_'.$newfiletmp;
//$file=$dir.'/'.$newfiletmp.'.'.dol_print_date(dol_now(),'%Y%m%d%H%M%S').'.odt';
// Get extension (ods or odt)
$newfileformat=substr($newfile, strrpos($newfile, '.')+1);
if ( ! empty($conf->global->MAIN_DOC_USE_TIMING))
$newfileformat = substr($newfile, strrpos($newfile, '.') + 1);
if (!empty($conf->global->MAIN_DOC_USE_TIMING))
{
$format=$conf->global->MAIN_DOC_USE_TIMING;
if ($format == '1') $format='%Y%m%d%H%M%S';
$filename=$newfiletmp.'-'.dol_print_date(dol_now(), $format).'.'.$newfileformat;
$format = $conf->global->MAIN_DOC_USE_TIMING;
if ($format == '1') $format = '%Y%m%d%H%M%S';
$filename = $newfiletmp.'-'.dol_print_date(dol_now(), $format).'.'.$newfileformat;
}
else
{
$filename=$newfiletmp.'.'.$newfileformat;
$filename = $newfiletmp.'.'.$newfileformat;
}
$file=$dir.'/'.$filename;
$file = $dir.'/'.$filename;
//print "newdir=".$dir;
//print "newfile=".$newfile;
//print "file=".$file;
@ -282,20 +282,20 @@ class doc_generic_bom_odt extends ModelePDFBom
// If CUSTOMER contact defined on order, we use it
$usecontact=false;
$arrayidcontact=$object->getIdContact('external', 'CUSTOMER');
$usecontact = false;
$arrayidcontact = $object->getIdContact('external', 'CUSTOMER');
if (count($arrayidcontact) > 0)
{
$usecontact=true;
$result=$object->fetch_contact($arrayidcontact[0]);
$usecontact = true;
$result = $object->fetch_contact($arrayidcontact[0]);
}
// Recipient name
$contactobject=null;
if (! empty($usecontact))
$contactobject = null;
if (!empty($usecontact))
{
// On peut utiliser le nom de la societe du contact
if (! empty($conf->global->MAIN_USE_COMPANY_NAME_OF_CONTACT)) $socobject = $object->contact;
if (!empty($conf->global->MAIN_USE_COMPANY_NAME_OF_CONTACT)) $socobject = $object->contact;
else {
$socobject = $object->thirdparty;
// if we have a CUSTOMER contact and we dont use it as recipient we store the contact object for later use
@ -304,24 +304,24 @@ class doc_generic_bom_odt extends ModelePDFBom
}
else
{
$socobject=$object->thirdparty;
$socobject = $object->thirdparty;
}
// Make substitution
$substitutionarray=array(
$substitutionarray = array(
'__QTY_TO_PRODUCE__' => $object->qty,
);
complete_substitutions_array($substitutionarray, $langs, $object);
// Call the ODTSubstitution hook
$parameters=array('file'=>$file,'object'=>$object,'outputlangs'=>$outputlangs,'substitutionarray'=>&$substitutionarray);
$reshook=$hookmanager->executeHooks('ODTSubstitution', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
$parameters = array('file'=>$file, 'object'=>$object, 'outputlangs'=>$outputlangs, 'substitutionarray'=>&$substitutionarray);
$reshook = $hookmanager->executeHooks('ODTSubstitution', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
// Line of free text
$newfreetext='';
$paramfreetext='BOM_FREE_TEXT';
if (! empty($conf->global->$paramfreetext))
$newfreetext = '';
$paramfreetext = 'BOM_FREE_TEXT';
if (!empty($conf->global->$paramfreetext))
{
$newfreetext=make_substitutions($conf->global->$paramfreetext, $substitutionarray);
$newfreetext = make_substitutions($conf->global->$paramfreetext, $substitutionarray);
}
// Open and load template
@ -337,9 +337,9 @@ class doc_generic_bom_odt extends ModelePDFBom
)
);
}
catch(Exception $e)
catch (Exception $e)
{
$this->error=$e->getMessage();
$this->error = $e->getMessage();
dol_syslog($e->getMessage(), LOG_INFO);
return -1;
}
@ -354,31 +354,31 @@ class doc_generic_bom_odt extends ModelePDFBom
try {
$odfHandler->setVars('free_text', $newfreetext, true, 'UTF-8');
}
catch(OdfException $e)
catch (OdfException $e)
{
dol_syslog($e->getMessage(), LOG_INFO);
}
// Define substitution array
$substitutionarray = getCommonSubstitutionArray($outputlangs, 0, null, $object);
$array_object_from_properties=$this->get_substitutionarray_each_var_object($object, $outputlangs);
$array_objet=$this->get_substitutionarray_object($object, $outputlangs);
$array_user=$this->get_substitutionarray_user($user, $outputlangs);
$array_soc=$this->get_substitutionarray_mysoc($mysoc, $outputlangs);
$array_thirdparty=$this->get_substitutionarray_thirdparty($socobject, $outputlangs);
$array_other=$this->get_substitutionarray_other($outputlangs);
$array_object_from_properties = $this->get_substitutionarray_each_var_object($object, $outputlangs);
$array_objet = $this->get_substitutionarray_object($object, $outputlangs);
$array_user = $this->get_substitutionarray_user($user, $outputlangs);
$array_soc = $this->get_substitutionarray_mysoc($mysoc, $outputlangs);
$array_thirdparty = $this->get_substitutionarray_thirdparty($socobject, $outputlangs);
$array_other = $this->get_substitutionarray_other($outputlangs);
// retrieve contact information for use in object as contact_xxx tags
$array_thirdparty_contact = array();
if ($usecontact && is_object($contactobject)) $array_thirdparty_contact=$this->get_substitutionarray_contact($contactobject, $outputlangs, 'contact');
if ($usecontact && is_object($contactobject)) $array_thirdparty_contact = $this->get_substitutionarray_contact($contactobject, $outputlangs, 'contact');
$tmparray = array_merge($substitutionarray, $array_object_from_properties, $array_user, $array_soc, $array_thirdparty, $array_objet, $array_other, $array_thirdparty_contact);
complete_substitutions_array($tmparray, $outputlangs, $object);
// Call the ODTSubstitution hook
$parameters=array('odfHandler'=>&$odfHandler,'file'=>$file,'object'=>$object,'outputlangs'=>$outputlangs,'substitutionarray'=>&$tmparray);
$reshook=$hookmanager->executeHooks('ODTSubstitution', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
$parameters = array('odfHandler'=>&$odfHandler, 'file'=>$file, 'object'=>$object, 'outputlangs'=>$outputlangs, 'substitutionarray'=>&$tmparray);
$reshook = $hookmanager->executeHooks('ODTSubstitution', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
foreach($tmparray as $key=>$value)
foreach ($tmparray as $key=>$value)
{
try {
if (preg_match('/logo$/', $key)) // Image
@ -391,7 +391,7 @@ class doc_generic_bom_odt extends ModelePDFBom
$odfHandler->setVars($key, $value, true, 'UTF-8');
}
}
catch(OdfException $e)
catch (OdfException $e)
{
dol_syslog($e->getMessage(), LOG_INFO);
}
@ -403,7 +403,7 @@ class doc_generic_bom_odt extends ModelePDFBom
try {
$listlines = $odfHandler->setSegment('lines');
}
catch(OdfException $e)
catch (OdfException $e)
{
// We may arrive here if tags for lines not present into template
$foundtagforlines = 0;
@ -413,22 +413,22 @@ class doc_generic_bom_odt extends ModelePDFBom
{
foreach ($object->lines as $line)
{
$tmparray=$this->get_substitutionarray_lines($line, $outputlangs);
$tmparray = $this->get_substitutionarray_lines($line, $outputlangs);
complete_substitutions_array($tmparray, $outputlangs, $object, $line, "completesubstitutionarray_lines");
// Call the ODTSubstitutionLine hook
$parameters=array('odfHandler'=>&$odfHandler,'file'=>$file,'object'=>$object,'outputlangs'=>$outputlangs,'substitutionarray'=>&$tmparray,'line'=>$line);
$reshook=$hookmanager->executeHooks('ODTSubstitutionLine', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
foreach($tmparray as $key => $val)
$parameters = array('odfHandler'=>&$odfHandler, 'file'=>$file, 'object'=>$object, 'outputlangs'=>$outputlangs, 'substitutionarray'=>&$tmparray, 'line'=>$line);
$reshook = $hookmanager->executeHooks('ODTSubstitutionLine', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
foreach ($tmparray as $key => $val)
{
try
{
$listlines->setVars($key, $val, true, 'UTF-8');
}
catch(OdfException $e)
catch (OdfException $e)
{
dol_syslog($e->getMessage(), LOG_INFO);
}
catch(SegmentException $e)
catch (SegmentException $e)
{
dol_syslog($e->getMessage(), LOG_INFO);
}
@ -438,21 +438,21 @@ class doc_generic_bom_odt extends ModelePDFBom
$odfHandler->mergeSegment($listlines);
}
}
catch(OdfException $e)
catch (OdfException $e)
{
$this->error=$e->getMessage();
$this->error = $e->getMessage();
dol_syslog($this->error, LOG_WARNING);
return -1;
}
// Replace labels translated
$tmparray=$outputlangs->get_translations_for_substitutions();
foreach($tmparray as $key=>$value)
$tmparray = $outputlangs->get_translations_for_substitutions();
foreach ($tmparray as $key=>$value)
{
try {
$odfHandler->setVars($key, $value, true, 'UTF-8');
}
catch(OdfException $e)
catch (OdfException $e)
{
dol_syslog($e->getMessage(), LOG_INFO);
}
@ -460,15 +460,15 @@ class doc_generic_bom_odt extends ModelePDFBom
// Call the beforeODTSave hook
$parameters=array('odfHandler'=>&$odfHandler,'file'=>$file,'object'=>$object,'outputlangs'=>$outputlangs,'substitutionarray'=>&$tmparray);
$reshook=$hookmanager->executeHooks('beforeODTSave', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
$parameters = array('odfHandler'=>&$odfHandler, 'file'=>$file, 'object'=>$object, 'outputlangs'=>$outputlangs, 'substitutionarray'=>&$tmparray);
$reshook = $hookmanager->executeHooks('beforeODTSave', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
// Write new file
if (!empty($conf->global->MAIN_ODT_AS_PDF)) {
try {
$odfHandler->exportAsAttachedPDF($file);
}catch (Exception $e){
$this->error=$e->getMessage();
} catch (Exception $e) {
$this->error = $e->getMessage();
dol_syslog($e->getMessage(), LOG_INFO);
return -1;
}
@ -477,19 +477,19 @@ class doc_generic_bom_odt extends ModelePDFBom
try {
$odfHandler->saveToDisk($file);
} catch (Exception $e) {
$this->error=$e->getMessage();
$this->error = $e->getMessage();
dol_syslog($e->getMessage(), LOG_INFO);
return -1;
}
}
$parameters=array('odfHandler'=>&$odfHandler,'file'=>$file,'object'=>$object,'outputlangs'=>$outputlangs,'substitutionarray'=>&$tmparray);
$reshook=$hookmanager->executeHooks('afterODTCreation', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
$parameters = array('odfHandler'=>&$odfHandler, 'file'=>$file, 'object'=>$object, 'outputlangs'=>$outputlangs, 'substitutionarray'=>&$tmparray);
$reshook = $hookmanager->executeHooks('afterODTCreation', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
if (! empty($conf->global->MAIN_UMASK))
if (!empty($conf->global->MAIN_UMASK))
@chmod($file, octdec($conf->global->MAIN_UMASK));
$odfHandler=null; // Destroy object
$odfHandler = null; // Destroy object
$this->result = array('fullpath'=>$file);
@ -497,7 +497,7 @@ class doc_generic_bom_odt extends ModelePDFBom
}
else
{
$this->error=$langs->transnoentities("ErrorCanNotCreateDir", $dir);
$this->error = $langs->transnoentities("ErrorCanNotCreateDir", $dir);
return -1;
}
}

View File

@ -68,7 +68,7 @@ class doc_generic_mo_odt extends ModelePDFMo
global $conf, $langs, $mysoc;
// Load translation files required by the page
$langs->loadLangs(array("main","companies"));
$langs->loadLangs(array("main", "companies"));
$this->db = $db;
$this->name = "ODT templates";
@ -79,11 +79,11 @@ class doc_generic_mo_odt extends ModelePDFMo
$this->type = 'odt';
$this->page_largeur = 0;
$this->page_hauteur = 0;
$this->format = array($this->page_largeur,$this->page_hauteur);
$this->marge_gauche=0;
$this->marge_droite=0;
$this->marge_haute=0;
$this->marge_basse=0;
$this->format = array($this->page_largeur, $this->page_hauteur);
$this->marge_gauche = 0;
$this->marge_droite = 0;
$this->marge_haute = 0;
$this->marge_basse = 0;
$this->option_logo = 1; // Affiche logo
$this->option_tva = 0; // Gere option tva
@ -97,8 +97,8 @@ class doc_generic_mo_odt extends ModelePDFMo
$this->option_draft_watermark = 0; // Support add of a watermark on drafts
// Recupere emetteur
$this->emetteur=$mysoc;
if (! $this->emetteur->country_code) $this->emetteur->country_code=substr($langs->defaultlang, -2); // By default if not defined
$this->emetteur = $mysoc;
if (!$this->emetteur->country_code) $this->emetteur->country_code = substr($langs->defaultlang, -2); // By default if not defined
}
@ -110,83 +110,83 @@ class doc_generic_mo_odt extends ModelePDFMo
*/
public function info($langs)
{
global $conf,$langs;
global $conf, $langs;
// Load translation files required by the page
$langs->loadLangs(array("errors","companies"));
$langs->loadLangs(array("errors", "companies"));
$form = new Form($this->db);
$texte = $this->description.".<br>\n";
$texte.= '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
$texte.= '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
$texte.= '<input type="hidden" name="action" value="setModuleOptions">';
$texte.= '<input type="hidden" name="param1" value="MRP_MO_ADDON_PDF_ODT_PATH">';
$texte.= '<table class="nobordernopadding" width="100%">';
$texte .= '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
$texte .= '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
$texte .= '<input type="hidden" name="action" value="setModuleOptions">';
$texte .= '<input type="hidden" name="param1" value="MRP_MO_ADDON_PDF_ODT_PATH">';
$texte .= '<table class="nobordernopadding" width="100%">';
// List of directories area
$texte.= '<tr><td>';
$texttitle=$langs->trans("ListOfDirectories");
$listofdir=explode(',', preg_replace('/[\r\n]+/', ',', trim($conf->global->MRP_MO_ADDON_PDF_ODT_PATH)));
$listoffiles=array();
foreach($listofdir as $key=>$tmpdir)
$texte .= '<tr><td>';
$texttitle = $langs->trans("ListOfDirectories");
$listofdir = explode(',', preg_replace('/[\r\n]+/', ',', trim($conf->global->MRP_MO_ADDON_PDF_ODT_PATH)));
$listoffiles = array();
foreach ($listofdir as $key=>$tmpdir)
{
$tmpdir=trim($tmpdir);
$tmpdir=preg_replace('/DOL_DATA_ROOT/', DOL_DATA_ROOT, $tmpdir);
if (! $tmpdir) {
$tmpdir = trim($tmpdir);
$tmpdir = preg_replace('/DOL_DATA_ROOT/', DOL_DATA_ROOT, $tmpdir);
if (!$tmpdir) {
unset($listofdir[$key]); continue;
}
if (! is_dir($tmpdir)) $texttitle.=img_warning($langs->trans("ErrorDirNotFound", $tmpdir), 0);
if (!is_dir($tmpdir)) $texttitle .= img_warning($langs->trans("ErrorDirNotFound", $tmpdir), 0);
else
{
$tmpfiles=dol_dir_list($tmpdir, 'files', 0, '\.(ods|odt)');
if (count($tmpfiles)) $listoffiles=array_merge($listoffiles, $tmpfiles);
$tmpfiles = dol_dir_list($tmpdir, 'files', 0, '\.(ods|odt)');
if (count($tmpfiles)) $listoffiles = array_merge($listoffiles, $tmpfiles);
}
}
$texthelp=$langs->trans("ListOfDirectoriesForModelGenODT");
$texthelp = $langs->trans("ListOfDirectoriesForModelGenODT");
// Add list of substitution keys
$texthelp.='<br>'.$langs->trans("FollowingSubstitutionKeysCanBeUsed").'<br>';
$texthelp.=$langs->transnoentitiesnoconv("FullListOnOnlineDocumentation"); // This contains an url, we don't modify it
$texthelp .= '<br>'.$langs->trans("FollowingSubstitutionKeysCanBeUsed").'<br>';
$texthelp .= $langs->transnoentitiesnoconv("FullListOnOnlineDocumentation"); // This contains an url, we don't modify it
$texte.= $form->textwithpicto($texttitle, $texthelp, 1, 'help', '', 1);
$texte.= '<div><div style="display: inline-block; min-width: 100px; vertical-align: middle;">';
$texte.= '<textarea class="flat" cols="60" name="value1">';
$texte.=$conf->global->MRP_MO_ADDON_PDF_ODT_PATH;
$texte.= '</textarea>';
$texte.= '</div><div style="display: inline-block; vertical-align: middle;">';
$texte.= '<input type="submit" class="button" value="'.$langs->trans("Modify").'" name="Button">';
$texte.= '<br></div></div>';
$texte .= $form->textwithpicto($texttitle, $texthelp, 1, 'help', '', 1);
$texte .= '<div><div style="display: inline-block; min-width: 100px; vertical-align: middle;">';
$texte .= '<textarea class="flat" cols="60" name="value1">';
$texte .= $conf->global->MRP_MO_ADDON_PDF_ODT_PATH;
$texte .= '</textarea>';
$texte .= '</div><div style="display: inline-block; vertical-align: middle;">';
$texte .= '<input type="submit" class="button" value="'.$langs->trans("Modify").'" name="Button">';
$texte .= '<br></div></div>';
// Scan directories
$nbofiles=count($listoffiles);
if (! empty($conf->global->MRP_MO_ADDON_PDF_ODT_PATH))
$nbofiles = count($listoffiles);
if (!empty($conf->global->MRP_MO_ADDON_PDF_ODT_PATH))
{
$texte.=$langs->trans("NumberOfModelFilesFound").': <b>';
$texte .= $langs->trans("NumberOfModelFilesFound").': <b>';
//$texte.=$nbofiles?'<a id="a_'.get_class($this).'" href="#">':'';
$texte.=count($listoffiles);
$texte .= count($listoffiles);
//$texte.=$nbofiles?'</a>':'';
$texte.='</b>';
$texte .= '</b>';
}
if ($nbofiles)
{
$texte.='<div id="div_'.get_class($this).'" class="hidden">';
foreach($listoffiles as $file)
$texte .= '<div id="div_'.get_class($this).'" class="hidden">';
foreach ($listoffiles as $file)
{
$texte.=$file['name'].'<br>';
$texte .= $file['name'].'<br>';
}
$texte.='<div id="div_'.get_class($this).'">';
$texte .= '<div id="div_'.get_class($this).'">';
}
$texte.= '</td>';
$texte .= '</td>';
$texte.= '<td valign="top" rowspan="2" class="hideonsmartphone">';
$texte.= $langs->trans("ExampleOfDirectoriesForModelGen");
$texte.= '</td>';
$texte.= '</tr>';
$texte .= '<td valign="top" rowspan="2" class="hideonsmartphone">';
$texte .= $langs->trans("ExampleOfDirectoriesForModelGen");
$texte .= '</td>';
$texte .= '</tr>';
$texte.= '</table>';
$texte.= '</form>';
$texte .= '</table>';
$texte .= '</form>';
return $texte;
}
@ -206,7 +206,7 @@ class doc_generic_mo_odt extends ModelePDFMo
public function write_file($object, $outputlangs, $srctemplatepath, $hidedetails = 0, $hidedesc = 0, $hideref = 0)
{
// phpcs:enable
global $user,$langs,$conf,$mysoc,$hookmanager;
global $user, $langs, $conf, $mysoc, $hookmanager;
if (empty($srctemplatepath))
{
@ -215,28 +215,28 @@ class doc_generic_mo_odt extends ModelePDFMo
}
// Add odtgeneration hook
if (! is_object($hookmanager))
if (!is_object($hookmanager))
{
include_once DOL_DOCUMENT_ROOT.'/core/class/hookmanager.class.php';
$hookmanager=new HookManager($this->db);
$hookmanager = new HookManager($this->db);
}
$hookmanager->initHooks(array('odtgeneration'));
global $action;
if (! is_object($outputlangs)) $outputlangs=$langs;
$sav_charset_output=$outputlangs->charset_output;
$outputlangs->charset_output='UTF-8';
if (!is_object($outputlangs)) $outputlangs = $langs;
$sav_charset_output = $outputlangs->charset_output;
$outputlangs->charset_output = 'UTF-8';
$outputlangs->loadLangs(array("main", "dict", "companies", "bills"));
if ($conf->mrp->dir_output)
{
// If $object is id instead of object
if (! is_object($object))
if (!is_object($object))
{
$id = $object;
$object = new MO($this->db);
$result=$object->fetch($id);
$result = $object->fetch($id);
if ($result < 0)
{
dol_print_error($this->db, $object->error);
@ -244,16 +244,16 @@ class doc_generic_mo_odt extends ModelePDFMo
}
}
$dir = $conf->mrp->multidir_output[isset($object->entity)?$object->entity:1];
$dir = $conf->mrp->multidir_output[isset($object->entity) ? $object->entity : 1];
$objectref = dol_sanitizeFileName($object->ref);
if (! preg_match('/specimen/i', $objectref)) $dir.= "/" . $objectref;
$file = $dir . "/" . $objectref . ".odt";
if (!preg_match('/specimen/i', $objectref)) $dir .= "/".$objectref;
$file = $dir."/".$objectref.".odt";
if (! file_exists($dir))
if (!file_exists($dir))
{
if (dol_mkdir($dir) < 0)
{
$this->error=$langs->transnoentities("ErrorCanNotCreateDir", $dir);
$this->error = $langs->transnoentities("ErrorCanNotCreateDir", $dir);
return -1;
}
}
@ -261,25 +261,25 @@ class doc_generic_mo_odt extends ModelePDFMo
if (file_exists($dir))
{
//print "srctemplatepath=".$srctemplatepath; // Src filename
$newfile=basename($srctemplatepath);
$newfiletmp=preg_replace('/\.od(t|s)/i', '', $newfile);
$newfiletmp=preg_replace('/template_/i', '', $newfiletmp);
$newfiletmp=preg_replace('/modele_/i', '', $newfiletmp);
$newfiletmp=$objectref.'_'.$newfiletmp;
$newfile = basename($srctemplatepath);
$newfiletmp = preg_replace('/\.od(t|s)/i', '', $newfile);
$newfiletmp = preg_replace('/template_/i', '', $newfiletmp);
$newfiletmp = preg_replace('/modele_/i', '', $newfiletmp);
$newfiletmp = $objectref.'_'.$newfiletmp;
//$file=$dir.'/'.$newfiletmp.'.'.dol_print_date(dol_now(),'%Y%m%d%H%M%S').'.odt';
// Get extension (ods or odt)
$newfileformat=substr($newfile, strrpos($newfile, '.')+1);
if ( ! empty($conf->global->MAIN_DOC_USE_TIMING))
$newfileformat = substr($newfile, strrpos($newfile, '.') + 1);
if (!empty($conf->global->MAIN_DOC_USE_TIMING))
{
$format=$conf->global->MAIN_DOC_USE_TIMING;
if ($format == '1') $format='%Y%m%d%H%M%S';
$filename=$newfiletmp.'-'.dol_print_date(dol_now(), $format).'.'.$newfileformat;
$format = $conf->global->MAIN_DOC_USE_TIMING;
if ($format == '1') $format = '%Y%m%d%H%M%S';
$filename = $newfiletmp.'-'.dol_print_date(dol_now(), $format).'.'.$newfileformat;
}
else
{
$filename=$newfiletmp.'.'.$newfileformat;
$filename = $newfiletmp.'.'.$newfileformat;
}
$file=$dir.'/'.$filename;
$file = $dir.'/'.$filename;
//print "newdir=".$dir;
//print "newfile=".$newfile;
//print "file=".$file;
@ -289,20 +289,20 @@ class doc_generic_mo_odt extends ModelePDFMo
// If CUSTOMER contact defined on order, we use it
$usecontact=false;
$arrayidcontact=$object->getIdContact('external', 'CUSTOMER');
$usecontact = false;
$arrayidcontact = $object->getIdContact('external', 'CUSTOMER');
if (count($arrayidcontact) > 0)
{
$usecontact=true;
$result=$object->fetch_contact($arrayidcontact[0]);
$usecontact = true;
$result = $object->fetch_contact($arrayidcontact[0]);
}
// Recipient name
$contactobject=null;
if (! empty($usecontact))
$contactobject = null;
if (!empty($usecontact))
{
// On peut utiliser le nom de la societe du contact
if (! empty($conf->global->MAIN_USE_COMPANY_NAME_OF_CONTACT)) $socobject = $object->contact;
if (!empty($conf->global->MAIN_USE_COMPANY_NAME_OF_CONTACT)) $socobject = $object->contact;
else {
$socobject = $object->thirdparty;
// if we have a CUSTOMER contact and we dont use it as recipient we store the contact object for later use
@ -311,24 +311,24 @@ class doc_generic_mo_odt extends ModelePDFMo
}
else
{
$socobject=$object->thirdparty;
$socobject = $object->thirdparty;
}
// Make substitution
$substitutionarray=array(
$substitutionarray = array(
'__QTY_TO_PRODUCE__' => $object->qty,
);
complete_substitutions_array($substitutionarray, $langs, $object);
// Call the ODTSubstitution hook
$parameters=array('file'=>$file,'object'=>$object,'outputlangs'=>$outputlangs,'substitutionarray'=>&$substitutionarray);
$reshook=$hookmanager->executeHooks('ODTSubstitution', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
$parameters = array('file'=>$file, 'object'=>$object, 'outputlangs'=>$outputlangs, 'substitutionarray'=>&$substitutionarray);
$reshook = $hookmanager->executeHooks('ODTSubstitution', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
// Line of free text
$newfreetext='';
$paramfreetext='MRP_MO_FREE_TEXT';
if (! empty($conf->global->$paramfreetext))
$newfreetext = '';
$paramfreetext = 'MRP_MO_FREE_TEXT';
if (!empty($conf->global->$paramfreetext))
{
$newfreetext=make_substitutions($conf->global->$paramfreetext, $substitutionarray);
$newfreetext = make_substitutions($conf->global->$paramfreetext, $substitutionarray);
}
// Open and load template
@ -344,9 +344,9 @@ class doc_generic_mo_odt extends ModelePDFMo
)
);
}
catch(Exception $e)
catch (Exception $e)
{
$this->error=$e->getMessage();
$this->error = $e->getMessage();
dol_syslog($e->getMessage(), LOG_INFO);
return -1;
}
@ -361,31 +361,31 @@ class doc_generic_mo_odt extends ModelePDFMo
try {
$odfHandler->setVars('free_text', $newfreetext, true, 'UTF-8');
}
catch(OdfException $e)
catch (OdfException $e)
{
dol_syslog($e->getMessage(), LOG_INFO);
}
// Define substitution array
$substitutionarray = getCommonSubstitutionArray($outputlangs, 0, null, $object);
$array_object_from_properties=$this->get_substitutionarray_each_var_object($object, $outputlangs);
$array_objet=$this->get_substitutionarray_object($object, $outputlangs);
$array_user=$this->get_substitutionarray_user($user, $outputlangs);
$array_soc=$this->get_substitutionarray_mysoc($mysoc, $outputlangs);
$array_thirdparty=$this->get_substitutionarray_thirdparty($socobject, $outputlangs);
$array_other=$this->get_substitutionarray_other($outputlangs);
$array_object_from_properties = $this->get_substitutionarray_each_var_object($object, $outputlangs);
$array_objet = $this->get_substitutionarray_object($object, $outputlangs);
$array_user = $this->get_substitutionarray_user($user, $outputlangs);
$array_soc = $this->get_substitutionarray_mysoc($mysoc, $outputlangs);
$array_thirdparty = $this->get_substitutionarray_thirdparty($socobject, $outputlangs);
$array_other = $this->get_substitutionarray_other($outputlangs);
// retrieve contact information for use in object as contact_xxx tags
$array_thirdparty_contact = array();
if ($usecontact && is_object($contactobject)) $array_thirdparty_contact=$this->get_substitutionarray_contact($contactobject, $outputlangs, 'contact');
if ($usecontact && is_object($contactobject)) $array_thirdparty_contact = $this->get_substitutionarray_contact($contactobject, $outputlangs, 'contact');
$tmparray = array_merge($substitutionarray, $array_object_from_properties, $array_user, $array_soc, $array_thirdparty, $array_objet, $array_other, $array_thirdparty_contact);
complete_substitutions_array($tmparray, $outputlangs, $object);
// Call the ODTSubstitution hook
$parameters=array('odfHandler'=>&$odfHandler,'file'=>$file,'object'=>$object,'outputlangs'=>$outputlangs,'substitutionarray'=>&$tmparray);
$reshook=$hookmanager->executeHooks('ODTSubstitution', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
$parameters = array('odfHandler'=>&$odfHandler, 'file'=>$file, 'object'=>$object, 'outputlangs'=>$outputlangs, 'substitutionarray'=>&$tmparray);
$reshook = $hookmanager->executeHooks('ODTSubstitution', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
foreach($tmparray as $key=>$value)
foreach ($tmparray as $key=>$value)
{
try {
if (preg_match('/logo$/', $key)) // Image
@ -398,7 +398,7 @@ class doc_generic_mo_odt extends ModelePDFMo
$odfHandler->setVars($key, $value, true, 'UTF-8');
}
}
catch(OdfException $e)
catch (OdfException $e)
{
dol_syslog($e->getMessage(), LOG_INFO);
}
@ -410,7 +410,7 @@ class doc_generic_mo_odt extends ModelePDFMo
try {
$listlines = $odfHandler->setSegment('lines');
}
catch(OdfException $e)
catch (OdfException $e)
{
// We may arrive here if tags for lines not present into template
$foundtagforlines = 0;
@ -420,22 +420,22 @@ class doc_generic_mo_odt extends ModelePDFMo
{
foreach ($object->lines as $line)
{
$tmparray=$this->get_substitutionarray_lines($line, $outputlangs);
$tmparray = $this->get_substitutionarray_lines($line, $outputlangs);
complete_substitutions_array($tmparray, $outputlangs, $object, $line, "completesubstitutionarray_lines");
// Call the ODTSubstitutionLine hook
$parameters=array('odfHandler'=>&$odfHandler,'file'=>$file,'object'=>$object,'outputlangs'=>$outputlangs,'substitutionarray'=>&$tmparray,'line'=>$line);
$reshook=$hookmanager->executeHooks('ODTSubstitutionLine', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
foreach($tmparray as $key => $val)
$parameters = array('odfHandler'=>&$odfHandler, 'file'=>$file, 'object'=>$object, 'outputlangs'=>$outputlangs, 'substitutionarray'=>&$tmparray, 'line'=>$line);
$reshook = $hookmanager->executeHooks('ODTSubstitutionLine', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
foreach ($tmparray as $key => $val)
{
try
{
$listlines->setVars($key, $val, true, 'UTF-8');
}
catch(OdfException $e)
catch (OdfException $e)
{
dol_syslog($e->getMessage(), LOG_INFO);
}
catch(SegmentException $e)
catch (SegmentException $e)
{
dol_syslog($e->getMessage(), LOG_INFO);
}
@ -445,21 +445,21 @@ class doc_generic_mo_odt extends ModelePDFMo
$odfHandler->mergeSegment($listlines);
}
}
catch(OdfException $e)
catch (OdfException $e)
{
$this->error=$e->getMessage();
$this->error = $e->getMessage();
dol_syslog($this->error, LOG_WARNING);
return -1;
}
// Replace labels translated
$tmparray=$outputlangs->get_translations_for_substitutions();
foreach($tmparray as $key=>$value)
$tmparray = $outputlangs->get_translations_for_substitutions();
foreach ($tmparray as $key=>$value)
{
try {
$odfHandler->setVars($key, $value, true, 'UTF-8');
}
catch(OdfException $e)
catch (OdfException $e)
{
dol_syslog($e->getMessage(), LOG_INFO);
}
@ -467,15 +467,15 @@ class doc_generic_mo_odt extends ModelePDFMo
// Call the beforeODTSave hook
$parameters=array('odfHandler'=>&$odfHandler,'file'=>$file,'object'=>$object,'outputlangs'=>$outputlangs,'substitutionarray'=>&$tmparray);
$reshook=$hookmanager->executeHooks('beforeODTSave', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
$parameters = array('odfHandler'=>&$odfHandler, 'file'=>$file, 'object'=>$object, 'outputlangs'=>$outputlangs, 'substitutionarray'=>&$tmparray);
$reshook = $hookmanager->executeHooks('beforeODTSave', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
// Write new file
if (!empty($conf->global->MAIN_ODT_AS_PDF)) {
try {
$odfHandler->exportAsAttachedPDF($file);
}catch (Exception $e){
$this->error=$e->getMessage();
} catch (Exception $e) {
$this->error = $e->getMessage();
dol_syslog($e->getMessage(), LOG_INFO);
return -1;
}
@ -484,19 +484,19 @@ class doc_generic_mo_odt extends ModelePDFMo
try {
$odfHandler->saveToDisk($file);
} catch (Exception $e) {
$this->error=$e->getMessage();
$this->error = $e->getMessage();
dol_syslog($e->getMessage(), LOG_INFO);
return -1;
}
}
$parameters=array('odfHandler'=>&$odfHandler,'file'=>$file,'object'=>$object,'outputlangs'=>$outputlangs,'substitutionarray'=>&$tmparray);
$reshook=$hookmanager->executeHooks('afterODTCreation', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
$parameters = array('odfHandler'=>&$odfHandler, 'file'=>$file, 'object'=>$object, 'outputlangs'=>$outputlangs, 'substitutionarray'=>&$tmparray);
$reshook = $hookmanager->executeHooks('afterODTCreation', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
if (! empty($conf->global->MAIN_UMASK))
if (!empty($conf->global->MAIN_UMASK))
@chmod($file, octdec($conf->global->MAIN_UMASK));
$odfHandler=null; // Destroy object
$odfHandler = null; // Destroy object
$this->result = array('fullpath'=>$file);
@ -504,7 +504,7 @@ class doc_generic_mo_odt extends ModelePDFMo
}
else
{
$this->error=$langs->transnoentities("ErrorCanNotCreateDir", $dir);
$this->error = $langs->transnoentities("ErrorCanNotCreateDir", $dir);
return -1;
}
}

View File

@ -26,7 +26,7 @@
* \brief File containing class for numbering model of MOs advanced
*/
require_once DOL_DOCUMENT_ROOT .'/core/modules/mrp/modules_mo.php';
require_once DOL_DOCUMENT_ROOT.'/core/modules/mrp/modules_mo.php';
/**
@ -48,7 +48,7 @@ class mod_mo_advanced extends ModeleNumRefMos
/**
* @var string name
*/
public $name='advanced';
public $name = 'advanced';
/**
@ -65,28 +65,28 @@ class mod_mo_advanced extends ModeleNumRefMos
$form = new Form($db);
$texte = $langs->trans('GenericNumRefModelDesc')."<br>\n";
$texte.= '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
$texte.= '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
$texte.= '<input type="hidden" name="action" value="updateMask">';
$texte.= '<input type="hidden" name="maskconstBom" value="MRP_MO_ADVANCED_MASK">';
$texte.= '<table class="nobordernopadding" width="100%">';
$texte .= '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
$texte .= '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
$texte .= '<input type="hidden" name="action" value="updateMask">';
$texte .= '<input type="hidden" name="maskconstBom" value="MRP_MO_ADVANCED_MASK">';
$texte .= '<table class="nobordernopadding" width="100%">';
$tooltip=$langs->trans("GenericMaskCodes", $langs->transnoentities("Mo"), $langs->transnoentities("Mo"));
$tooltip.=$langs->trans("GenericMaskCodes2");
$tooltip.=$langs->trans("GenericMaskCodes3");
$tooltip.=$langs->trans("GenericMaskCodes4a", $langs->transnoentities("Mo"), $langs->transnoentities("Mo"));
$tooltip.=$langs->trans("GenericMaskCodes5");
$tooltip = $langs->trans("GenericMaskCodes", $langs->transnoentities("Mo"), $langs->transnoentities("Mo"));
$tooltip .= $langs->trans("GenericMaskCodes2");
$tooltip .= $langs->trans("GenericMaskCodes3");
$tooltip .= $langs->trans("GenericMaskCodes4a", $langs->transnoentities("Mo"), $langs->transnoentities("Mo"));
$tooltip .= $langs->trans("GenericMaskCodes5");
// Parametrage du prefix
$texte.= '<tr><td>'.$langs->trans("Mask").':</td>';
$texte.= '<td class="right">'.$form->textwithpicto('<input type="text" class="flat" size="24" name="maskMo" value="'.$conf->global->MRP_MO_ADVANCED_MASK.'">', $tooltip, 1, 1).'</td>';
$texte .= '<tr><td>'.$langs->trans("Mask").':</td>';
$texte .= '<td class="right">'.$form->textwithpicto('<input type="text" class="flat" size="24" name="maskMo" value="'.$conf->global->MRP_MO_ADVANCED_MASK.'">', $tooltip, 1, 1).'</td>';
$texte.= '<td class="left" rowspan="2">&nbsp; <input type="submit" class="button" value="'.$langs->trans("Modify").'" name="Button"></td>';
$texte .= '<td class="left" rowspan="2">&nbsp; <input type="submit" class="button" value="'.$langs->trans("Modify").'" name="Button"></td>';
$texte.= '</tr>';
$texte .= '</tr>';
$texte.= '</table>';
$texte.= '</form>';
$texte .= '</table>';
$texte .= '</form>';
return $texte;
}
@ -98,17 +98,17 @@ class mod_mo_advanced extends ModeleNumRefMos
*/
public function getExample()
{
global $conf,$langs,$mysoc;
global $conf, $langs, $mysoc;
$old_code_client=$mysoc->code_client;
$old_code_type=$mysoc->typent_code;
$mysoc->code_client='CCCCCCCCCC';
$mysoc->typent_code='TTTTTTTTTT';
$old_code_client = $mysoc->code_client;
$old_code_type = $mysoc->typent_code;
$mysoc->code_client = 'CCCCCCCCCC';
$mysoc->typent_code = 'TTTTTTTTTT';
$numExample = $this->getNextValue($mysoc, '');
$mysoc->code_client=$old_code_client;
$mysoc->typent_code=$old_code_type;
$mysoc->code_client = $old_code_client;
$mysoc->typent_code = $old_code_type;
if (! $numExample)
if (!$numExample)
{
$numExample = $langs->trans('NotConfigured');
}
@ -124,22 +124,22 @@ class mod_mo_advanced extends ModeleNumRefMos
*/
public function getNextValue($objprod, $object)
{
global $db,$conf;
global $db, $conf;
require_once DOL_DOCUMENT_ROOT .'/core/lib/functions2.lib.php';
require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
// We get cursor rule
$mask=$conf->global->MRP_MO_ADVANCED_MASK;
$mask = $conf->global->MRP_MO_ADVANCED_MASK;
if (! $mask)
if (!$mask)
{
$this->error='NotConfigured';
$this->error = 'NotConfigured';
return 0;
}
$date = ($object->date_mo ? $object->date_mo : $object->date);
$numFinal=get_next_value($db, $mask, 'mrp_mo', 'ref', '', null, $date);
$numFinal = get_next_value($db, $mask, 'mrp_mo', 'ref', '', null, $date);
return $numFinal;
}

View File

@ -22,7 +22,7 @@
* \ingroup mrp
* \brief File of class to manage MO numbering rules standard
*/
require_once DOL_DOCUMENT_ROOT .'/core/modules/mrp/modules_mo.php';
require_once DOL_DOCUMENT_ROOT.'/core/modules/mrp/modules_mo.php';
/**
* Class to manage MO numbering rules standard
@ -35,17 +35,17 @@ class mod_mo_standard extends ModeleNumRefMos
*/
public $version = 'dolibarr'; // 'development', 'experimental', 'dolibarr'
public $prefix='MO';
public $prefix = 'MO';
/**
* @var string Error code (or message)
*/
public $error='';
public $error = '';
/**
* @var string name
*/
public $name='standard';
public $name = 'standard';
/**
@ -79,26 +79,26 @@ class mod_mo_standard extends ModeleNumRefMos
*/
public function canBeActivated()
{
global $conf,$langs,$db;
global $conf, $langs, $db;
$coyymm=''; $max='';
$coyymm = ''; $max = '';
$posindice=8;
$posindice = 8;
$sql = "SELECT MAX(CAST(SUBSTRING(ref FROM ".$posindice.") AS SIGNED)) as max";
$sql.= " FROM ".MAIN_DB_PREFIX."mrp_mo";
$sql.= " WHERE ref LIKE '".$db->escape($this->prefix)."____-%'";
$sql.= " AND entity = ".$conf->entity;
$sql .= " FROM ".MAIN_DB_PREFIX."mrp_mo";
$sql .= " WHERE ref LIKE '".$db->escape($this->prefix)."____-%'";
$sql .= " AND entity = ".$conf->entity;
$resql=$db->query($sql);
$resql = $db->query($sql);
if ($resql)
{
$row = $db->fetch_row($resql);
if ($row) { $coyymm = substr($row[0], 0, 6); $max=$row[0]; }
if ($row) { $coyymm = substr($row[0], 0, 6); $max = $row[0]; }
}
if ($coyymm && ! preg_match('/'.$this->prefix.'[0-9][0-9][0-9][0-9]/i', $coyymm))
if ($coyymm && !preg_match('/'.$this->prefix.'[0-9][0-9][0-9][0-9]/i', $coyymm))
{
$langs->load("errors");
$this->error=$langs->trans('ErrorNumRefModel', $max);
$this->error = $langs->trans('ErrorNumRefModel', $max);
return false;
}
@ -114,21 +114,21 @@ class mod_mo_standard extends ModeleNumRefMos
*/
public function getNextValue($objprod, $object)
{
global $db,$conf;
global $db, $conf;
// D'abord on recupere la valeur max
$posindice=9;
$posindice = 9;
$sql = "SELECT MAX(CAST(SUBSTRING(ref FROM ".$posindice.") AS SIGNED)) as max";
$sql.= " FROM ".MAIN_DB_PREFIX."mrp_mo";
$sql.= " WHERE ref LIKE '".$db->escape($this->prefix)."____-%'";
$sql.= " AND entity = ".$conf->entity;
$sql .= " FROM ".MAIN_DB_PREFIX."mrp_mo";
$sql .= " WHERE ref LIKE '".$db->escape($this->prefix)."____-%'";
$sql .= " AND entity = ".$conf->entity;
$resql=$db->query($sql);
$resql = $db->query($sql);
if ($resql)
{
$obj = $db->fetch_object($resql);
if ($obj) $max = intval($obj->max);
else $max=0;
else $max = 0;
}
else
{
@ -137,11 +137,11 @@ class mod_mo_standard extends ModeleNumRefMos
}
//$date=time();
$date=$object->date_creation;
$date = $object->date_creation;
$yymm = strftime("%y%m", $date);
if ($max >= (pow(10, 4) - 1)) $num=$max+1; // If counter > 9999, we do not format on 4 chars, we take number as it is
else $num = sprintf("%04s", $max+1);
if ($max >= (pow(10, 4) - 1)) $num = $max + 1; // If counter > 9999, we do not format on 4 chars, we take number as it is
else $num = sprintf("%04s", $max + 1);
dol_syslog("mod_mo_standard::getNextValue return ".$this->prefix.$yymm."-".$num);
return $this->prefix.$yymm."-".$num;

View File

@ -24,12 +24,12 @@
*/
// Protection to avoid direct call of template
if (empty($conf) || ! is_object($conf))
if (empty($conf) || !is_object($conf))
{
print "Error, template page can't be called as URL";
exit;
}
if (! is_object($form)) $form=new Form($db);
if (!is_object($form)) $form = new Form($db);
?>
<!-- BEGIN PHP TEMPLATE commonfields_view.tpl.php -->
@ -37,22 +37,22 @@ if (! is_object($form)) $form=new Form($db);
$object->fields = dol_sort_array($object->fields, 'position');
foreach($object->fields as $key => $val)
foreach ($object->fields as $key => $val)
{
// Discard if extrafield is a hidden field on form
if (abs($val['visible']) != 1 && abs($val['visible']) != 3 && abs($val['visible']) != 4) continue;
if (array_key_exists('enabled', $val) && isset($val['enabled']) && ! verifCond($val['enabled'])) continue; // We don't want this field
if (in_array($key, array('ref','status'))) continue; // Ref and status are already in dol_banner
if (array_key_exists('enabled', $val) && isset($val['enabled']) && !verifCond($val['enabled'])) continue; // We don't want this field
if (in_array($key, array('ref', 'status'))) continue; // Ref and status are already in dol_banner
$value=$object->$key;
$value = $object->$key;
print '<tr><td';
print ' class="titlefield fieldname_'.$key;
//if ($val['notnull'] > 0) print ' fieldrequired'; // No fieldrequired on the view output
if ($val['type'] == 'text' || $val['type'] == 'html') print ' tdtop';
print '">';
if (! empty($val['help'])) print $form->textwithpicto($langs->trans($val['label']), $langs->trans($val['help']));
if (!empty($val['help'])) print $form->textwithpicto($langs->trans($val['label']), $langs->trans($val['help']));
else print $langs->trans($val['label']);
print '</td>';
print '<td class="valuefield fieldname_'.$key;
@ -63,7 +63,7 @@ foreach($object->fields as $key => $val)
print '</td>';
print '</tr>';
if (! empty($keyforbreak) && $key == $keyforbreak) break; // key used for break on second column
if (!empty($keyforbreak) && $key == $keyforbreak) break; // key used for break on second column
}
print '</table>';
@ -76,26 +76,26 @@ print '<div class="underbanner clearboth"></div>';
print '<table class="border centpercent tableforfield">';
$alreadyoutput = 1;
foreach($object->fields as $key => $val)
foreach ($object->fields as $key => $val)
{
if ($alreadyoutput)
{
if (! empty($keyforbreak) && $key == $keyforbreak) $alreadyoutput = 0; // key used for break on second column
if (!empty($keyforbreak) && $key == $keyforbreak) $alreadyoutput = 0; // key used for break on second column
continue;
}
if (abs($val['visible']) != 1) continue; // Discard such field from form
if (array_key_exists('enabled', $val) && isset($val['enabled']) && ! $val['enabled']) continue; // We don't want this field
if (in_array($key, array('ref','status'))) continue; // Ref and status are already in dol_banner
if (array_key_exists('enabled', $val) && isset($val['enabled']) && !$val['enabled']) continue; // We don't want this field
if (in_array($key, array('ref', 'status'))) continue; // Ref and status are already in dol_banner
$value=$object->$key;
$value = $object->$key;
print '<tr><td';
print ' class="titlefield fieldname_'.$key;
//if ($val['notnull'] > 0) print ' fieldrequired'; // No fieldrequired inthe view output
if ($val['type'] == 'text' || $val['type'] == 'html') print ' tdtop';
print '">';
if (! empty($val['help'])) print $form->textwithpicto($langs->trans($val['label']), $langs->trans($val['help']));
if (!empty($val['help'])) print $form->textwithpicto($langs->trans($val['label']), $langs->trans($val['help']));
else print $langs->trans($val['label']);
print '</td>';
print '<td>';

View File

@ -23,7 +23,7 @@
*/
// Put here all includes required by your class file
require_once DOL_DOCUMENT_ROOT . '/core/class/commonobject.class.php';
require_once DOL_DOCUMENT_ROOT.'/core/class/commonobject.class.php';
//require_once DOL_DOCUMENT_ROOT . '/societe/class/societe.class.php';
//require_once DOL_DOCUMENT_ROOT . '/product/class/product.class.php';
@ -90,7 +90,7 @@ class Mo extends CommonObject
/**
* @var array Array with all fields and their property. Do not use it as a static var. It may be modified by constructor.
*/
public $fields=array(
public $fields = array(
'rowid' => array('type'=>'integer', 'label'=>'TechnicalID', 'enabled'=>1, 'visible'=>-1, 'position'=>1, 'notnull'=>1, 'index'=>1, 'comment'=>"Id",),
'entity' => array('type'=>'integer', 'label'=>'Entity', 'enabled'=>1, 'visible'=>0, 'position'=>5, 'notnull'=>1, 'default'=>'1', 'index'=>1,),
'ref' => array('type'=>'varchar(128)', 'label'=>'Ref', 'enabled'=>1, 'visible'=>4, 'position'=>10, 'notnull'=>1, 'default'=>'(PROV)', 'index'=>1, 'searchall'=>1, 'comment'=>"Reference of object", 'showoncombobox'=>'1',),
@ -197,11 +197,11 @@ class Mo extends CommonObject
$this->db = $db;
if (empty($conf->global->MAIN_SHOW_TECHNICAL_ID) && isset($this->fields['rowid'])) $this->fields['rowid']['visible']=0;
if (empty($conf->multicompany->enabled) && isset($this->fields['entity'])) $this->fields['entity']['enabled']=0;
if (empty($conf->global->MAIN_SHOW_TECHNICAL_ID) && isset($this->fields['rowid'])) $this->fields['rowid']['visible'] = 0;
if (empty($conf->multicompany->enabled) && isset($this->fields['entity'])) $this->fields['entity']['enabled'] = 0;
// Unset fields that are disabled
foreach($this->fields as $key => $val)
foreach ($this->fields as $key => $val)
{
if (isset($val['enabled']) && empty($val['enabled']))
{
@ -210,13 +210,13 @@ class Mo extends CommonObject
}
// Translate some data of arrayofkeyval
foreach($this->fields as $key => $val)
foreach ($this->fields as $key => $val)
{
if (is_array($val['arrayofkeyval']))
{
foreach($val['arrayofkeyval'] as $key2 => $val2)
foreach ($val['arrayofkeyval'] as $key2 => $val2)
{
$this->fields[$key]['arrayofkeyval'][$key2]=$langs->trans($val2);
$this->fields[$key]['arrayofkeyval'][$key2] = $langs->trans($val2);
}
}
}
@ -254,7 +254,7 @@ class Mo extends CommonObject
// Load source object
$result = $object->fetchCommon($fromid);
if ($result > 0 && ! empty($object->table_element_line)) $object->fetchLines();
if ($result > 0 && !empty($object->table_element_line)) $object->fetchLines();
// get lines so they will be clone
//foreach($this->lines as $line)
@ -266,18 +266,18 @@ class Mo extends CommonObject
unset($object->import_key);
// Clear fields
$object->ref = empty($this->fields['ref']['default']) ? "copy_of_".$object->ref: $this->fields['ref']['default'];
$object->label = empty($this->fields['label']['default']) ? $langs->trans("CopyOf")." ".$object->label: $this->fields['label']['default'];
$object->ref = empty($this->fields['ref']['default']) ? "copy_of_".$object->ref : $this->fields['ref']['default'];
$object->label = empty($this->fields['label']['default']) ? $langs->trans("CopyOf")." ".$object->label : $this->fields['label']['default'];
$object->status = self::STATUS_DRAFT;
// ...
// Clear extrafields that are unique
if (is_array($object->array_options) && count($object->array_options) > 0)
{
$extrafields->fetch_name_optionals_label($this->table_element);
foreach($object->array_options as $key => $option)
foreach ($object->array_options as $key => $option)
{
$shortkey = preg_replace('/options_/', '', $key);
if (! empty($extrafields->attributes[$this->element]['unique'][$shortkey]))
if (!empty($extrafields->attributes[$this->element]['unique'][$shortkey]))
{
//var_dump($key); var_dump($clonedObj->array_options[$key]); exit;
unset($object->array_options[$key]);
@ -294,7 +294,7 @@ class Mo extends CommonObject
$this->errors = $object->errors;
}
if (! $error)
if (!$error)
{
// copy internal contacts
if ($this->copy_linked_contact($object, 'internal') < 0)
@ -303,7 +303,7 @@ class Mo extends CommonObject
}
}
if (! $error)
if (!$error)
{
// copy external contacts if same company
if (property_exists($this, 'socid') && $this->socid == $object->socid)
@ -335,7 +335,7 @@ class Mo extends CommonObject
public function fetch($id, $ref = null)
{
$result = $this->fetchCommon($id, $ref);
if ($result > 0 && ! empty($this->table_element_line)) $this->fetchLines();
if ($result > 0 && !empty($this->table_element_line)) $this->fetchLines();
return $result;
}
@ -346,7 +346,7 @@ class Mo extends CommonObject
*/
public function fetchLines()
{
$this->lines=array();
$this->lines = array();
$result = $this->fetchLinesCommon();
return $result;
@ -370,40 +370,40 @@ class Mo extends CommonObject
dol_syslog(__METHOD__, LOG_DEBUG);
$records=array();
$records = array();
$sql = 'SELECT ';
$sql .= $this->getFieldList();
$sql .= ' FROM ' . MAIN_DB_PREFIX . $this->table_element. ' as t';
$sql .= ' FROM '.MAIN_DB_PREFIX.$this->table_element.' as t';
if (isset($this->ismultientitymanaged) && $this->ismultientitymanaged == 1) $sql .= ' WHERE t.entity IN ('.getEntity($this->table_element).')';
else $sql .= ' WHERE 1 = 1';
// Manage filter
$sqlwhere = array();
if (count($filter) > 0) {
foreach ($filter as $key => $value) {
if ($key=='t.rowid') {
$sqlwhere[] = $key . '='. $value;
if ($key == 't.rowid') {
$sqlwhere[] = $key.'='.$value;
}
elseif (strpos($key, 'date') !== false) {
$sqlwhere[] = $key.' = \''.$this->db->idate($value).'\'';
}
elseif ($key=='customsql') {
elseif ($key == 'customsql') {
$sqlwhere[] = $value;
}
else {
$sqlwhere[] = $key . ' LIKE \'%' . $this->db->escape($value) . '%\'';
$sqlwhere[] = $key.' LIKE \'%'.$this->db->escape($value).'%\'';
}
}
}
if (count($sqlwhere) > 0) {
$sql .= ' AND (' . implode(' '.$filtermode.' ', $sqlwhere).')';
$sql .= ' AND ('.implode(' '.$filtermode.' ', $sqlwhere).')';
}
if (!empty($sortfield)) {
$sql .= $this->db->order($sortfield, $sortorder);
}
if (!empty($limit)) {
$sql .= ' ' . $this->db->plimit($limit, $offset);
$sql .= ' '.$this->db->plimit($limit, $offset);
}
$resql = $this->db->query($sql);
@ -425,8 +425,8 @@ class Mo extends CommonObject
return $records;
} else {
$this->errors[] = 'Error ' . $this->db->lasterror();
dol_syslog(__METHOD__ . ' ' . join(',', $this->errors), LOG_ERR);
$this->errors[] = 'Error '.$this->db->lasterror();
dol_syslog(__METHOD__.' '.join(',', $this->errors), LOG_ERR);
return -1;
}
@ -490,51 +490,51 @@ class Mo extends CommonObject
{
global $conf, $langs, $hookmanager;
if (! empty($conf->dol_no_mouse_hover)) $notooltip=1; // Force disable tooltips
if (!empty($conf->dol_no_mouse_hover)) $notooltip = 1; // Force disable tooltips
$result = '';
$label = '<u>' . $langs->trans("MO") . '</u>';
$label.= '<br>';
$label.= '<b>' . $langs->trans('Ref') . ':</b> ' . $this->ref;
$label = '<u>'.$langs->trans("MO").'</u>';
$label .= '<br>';
$label .= '<b>'.$langs->trans('Ref').':</b> '.$this->ref;
$url = dol_buildpath('/mrp/mo_card.php', 1).'?id='.$this->id;
if ($option != 'nolink')
{
// Add param to save lastsearch_values or not
$add_save_lastsearch_values=($save_lastsearch_value == 1 ? 1 : 0);
if ($save_lastsearch_value == -1 && preg_match('/list\.php/', $_SERVER["PHP_SELF"])) $add_save_lastsearch_values=1;
if ($add_save_lastsearch_values) $url.='&save_lastsearch_values=1';
$add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
if ($save_lastsearch_value == -1 && preg_match('/list\.php/', $_SERVER["PHP_SELF"])) $add_save_lastsearch_values = 1;
if ($add_save_lastsearch_values) $url .= '&save_lastsearch_values=1';
}
$linkclose='';
$linkclose = '';
if (empty($notooltip))
{
if (! empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER))
if (!empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER))
{
$label=$langs->trans("ShowMo");
$linkclose.=' alt="'.dol_escape_htmltag($label, 1).'"';
$label = $langs->trans("ShowMo");
$linkclose .= ' alt="'.dol_escape_htmltag($label, 1).'"';
}
$linkclose.=' title="'.dol_escape_htmltag($label, 1).'"';
$linkclose.=' class="classfortooltip'.($morecss?' '.$morecss:'').'"';
$linkclose .= ' title="'.dol_escape_htmltag($label, 1).'"';
$linkclose .= ' class="classfortooltip'.($morecss ? ' '.$morecss : '').'"';
}
else $linkclose = ($morecss?' class="'.$morecss.'"':'');
else $linkclose = ($morecss ? ' class="'.$morecss.'"' : '');
$linkstart = '<a href="'.$url.'"';
$linkstart.=$linkclose.'>';
$linkend='</a>';
$linkstart .= $linkclose.'>';
$linkend = '</a>';
$result .= $linkstart;
if ($withpicto) $result.=img_object(($notooltip?'':$label), ($this->picto?$this->picto:'generic'), ($notooltip?(($withpicto != 2) ? 'class="paddingright"' : ''):'class="'.(($withpicto != 2) ? 'paddingright ' : '').'classfortooltip"'), 0, 0, $notooltip?0:1);
if ($withpicto != 2) $result.= $this->ref;
if ($withpicto) $result .= img_object(($notooltip ? '' : $label), ($this->picto ? $this->picto : 'generic'), ($notooltip ? (($withpicto != 2) ? 'class="paddingright"' : '') : 'class="'.(($withpicto != 2) ? 'paddingright ' : '').'classfortooltip"'), 0, 0, $notooltip ? 0 : 1);
if ($withpicto != 2) $result .= $this->ref;
$result .= $linkend;
//if ($withpicto != 2) $result.=(($addlabel && $this->label) ? $sep . dol_trunc($this->label, ($addlabel > 1 ? $addlabel : 0)) : '');
global $action,$hookmanager;
global $action, $hookmanager;
$hookmanager->initHooks(array('modao'));
$parameters=array('id'=>$this->id, 'getnomurl'=>$result);
$reshook=$hookmanager->executeHooks('getNomUrl', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
$parameters = array('id'=>$this->id, 'getnomurl'=>$result);
$reshook = $hookmanager->executeHooks('getNomUrl', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
if ($reshook > 0) $result = $hookmanager->resPrint;
else $result .= $hookmanager->resPrint;
@ -589,10 +589,10 @@ class Mo extends CommonObject
public function info($id)
{
$sql = 'SELECT rowid, date_creation as datec, tms as datem,';
$sql.= ' fk_user_creat, fk_user_modif';
$sql.= ' FROM '.MAIN_DB_PREFIX.$this->table_element.' as t';
$sql.= ' WHERE t.rowid = '.$id;
$result=$this->db->query($sql);
$sql .= ' fk_user_creat, fk_user_modif';
$sql .= ' FROM '.MAIN_DB_PREFIX.$this->table_element.' as t';
$sql .= ' WHERE t.rowid = '.$id;
$result = $this->db->query($sql);
if ($result)
{
if ($this->db->num_rows($result))
@ -651,7 +651,7 @@ class Mo extends CommonObject
*/
public function getLinesArray()
{
$this->lines=array();
$this->lines = array();
$objectline = new MoLine($this->db);
$result = $objectline->fetchAll('ASC', 'position', 0, 0, array('customsql'=>'fk_mo = '.$this->id));
@ -682,16 +682,16 @@ class Mo extends CommonObject
*/
public function generateDocument($modele, $outputlangs, $hidedetails = 0, $hidedesc = 0, $hideref = 0, $moreparams = null)
{
global $conf,$langs;
global $conf, $langs;
$langs->load("mrp");
if (! dol_strlen($modele)) {
if (!dol_strlen($modele)) {
$modele = 'standard';
if ($this->modelpdf) {
$modele = $this->modelpdf;
} elseif (! empty($conf->global->MO_ADDON_PDF)) {
} elseif (!empty($conf->global->MO_ADDON_PDF)) {
$modele = $conf->global->MO_ADDON_PDF;
}
}
@ -716,7 +716,7 @@ class Mo extends CommonObject
$error = 0;
$this->output = '';
$this->error='';
$this->error = '';
dol_syslog(__METHOD__, LOG_DEBUG);