From 9795f48046079fa4417af1d7b57efb50afa46ed4 Mon Sep 17 00:00:00 2001 From: arnaud Date: Mon, 18 Sep 2017 17:27:29 +0200 Subject: [PATCH 01/46] NEW comment system working with all objects --- htdocs/core/actions_comments.inc.php | 76 ++++ htdocs/core/class/comment.class.php | 322 +++++++++++++++++ htdocs/core/class/commonobject.class.php | 29 ++ htdocs/core/lib/project.lib.php | 18 +- htdocs/core/tpl/bloc_comment.tpl.php | 105 ++++++ .../install/mysql/migration/6.0.0-7.0.0.sql | 9 +- htdocs/langs/en_US/main.lang | 5 + htdocs/langs/en_US/projects.lang | 6 +- htdocs/langs/fr_FR/main.lang | 5 + htdocs/langs/fr_FR/projects.lang | 6 +- htdocs/projet/admin/project.php | 9 + htdocs/projet/class/project.class.php | 1 + htdocs/projet/class/task.class.php | 328 ------------------ htdocs/projet/comment.php | 189 ++++++++++ htdocs/projet/tasks/comment.php | 186 ++-------- 15 files changed, 787 insertions(+), 507 deletions(-) create mode 100644 htdocs/core/actions_comments.inc.php create mode 100644 htdocs/core/class/comment.class.php create mode 100644 htdocs/core/tpl/bloc_comment.tpl.php create mode 100644 htdocs/projet/comment.php diff --git a/htdocs/core/actions_comments.inc.php b/htdocs/core/actions_comments.inc.php new file mode 100644 index 00000000000..185973cb258 --- /dev/null +++ b/htdocs/core/actions_comments.inc.php @@ -0,0 +1,76 @@ + + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * or see http://www.gnu.org/ + * + * $elementype must be defined. + */ + +/** + * \file htdocs/core/actions_comments.inc.php + * \brief Code for actions on comments pages + */ + + +require_once DOL_DOCUMENT_ROOT.'/core/class/comment.class.php'; + +$varpage=empty($contextpage)?$_SERVER["PHP_SELF"]:$contextpage; +$comment = new Comment($db); + +/* + * Actions + */ + +if ($action == 'addcomment') +{ + $description = GETPOST('comment_description'); + if (!empty($description)) + { + $comment->description = $description; + $comment->datec = time(); + $comment->fk_element = GETPOST('id'); + $comment->element_type = GETPOST('comment_element_type'); + $comment->fk_user_author = $user->id; + $comment->entity = $conf->entity; + if ($comment->create($user) > 0) + { + setEventMessages($langs->trans("CommentAdded"), null, 'mesgs'); + header('Location: '.$varpage.'?id='.$id.($withproject?'&withproject=1':'')); + exit; + } + else + { + setEventMessages($comment->error, $comment->errors,'errors'); + $action=''; + } + } +} +if ($action == 'deletecomment') +{ + if ($comment->fetch($idcomment) >= 0) + { + if ($comment->delete($user) > 0) + { + setEventMessages($langs->trans("CommentDeleted"), null, 'mesgs'); + header('Location: '.$varpage.'?id='.$id.($withproject?'&withproject=1':'')); + exit; + } + else + { + setEventMessages($comment->error, $comment->errors,'errors'); + $action=''; + } + } +} \ No newline at end of file diff --git a/htdocs/core/class/comment.class.php b/htdocs/core/class/comment.class.php new file mode 100644 index 00000000000..0ec77405721 --- /dev/null +++ b/htdocs/core/class/comment.class.php @@ -0,0 +1,322 @@ +db = $db; + } + + + /** + * Create into database + * + * @param User $user User that create + * @param int $notrigger 0=launch triggers after, 1=disable triggers + * @return int <0 if KO, Id of created object if OK + */ + function create($user, $notrigger=0) + { + global $conf, $langs; + + $error=0; + + // Insert request + $sql = "INSERT INTO ".MAIN_DB_PREFIX."comment ("; + $sql.= "description"; + $sql.= ", datec"; + $sql.= ", fk_element"; + $sql.= ", element_type"; + $sql.= ", fk_user_author"; + $sql.= ", entity"; + $sql.= ", import_key"; + $sql.= ") VALUES ("; + $sql.= "'".$this->db->escape($this->description)."'"; + $sql.= ", ".($this->datec!=''?"'".$this->db->idate($this->datec)."'":'null'); + $sql.= ", '".(isset($this->fk_element)?$this->fk_element:"null")."'"; + $sql.= ", '".$this->db->escape($this->element_type)."'"; + $sql.= ", '".(isset($this->fk_user_author)?$this->fk_user_author:"null")."'"; + $sql.= ", ".(!empty($this->entity)?$this->entity:'1'); + $sql.= ", ".(!empty($this->import_key)?"'".$this->db->escape($this->import_key)."'":"null"); + $sql.= ")"; + + //var_dump($this->db); + //echo $sql; + + $this->db->begin(); + + dol_syslog(get_class($this)."::create", LOG_DEBUG); + $resql=$this->db->query($sql); + if (! $resql) { $error++; $this->errors[]="Error ".$this->db->lasterror(); } + + if (! $error) + { + $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX."projet_task_comment"); + + if (! $notrigger) + { + // Call trigger + $result=$this->call_trigger('TASK_COMMENT_CREATE',$user); + if ($result < 0) { $error++; } + // End call triggers + } + } + + // Commit or rollback + if ($error) + { + foreach($this->errors as $errmsg) + { + dol_syslog(get_class($this)."::create ".$errmsg, LOG_ERR); + $this->error.=($this->error?', '.$errmsg:$errmsg); + } + $this->db->rollback(); + return -1*$error; + } + else + { + $this->db->commit(); + return $this->id; + } + } + + + /** + * Load object in memory from database + * + * @param int $id Id object + * @param int $ref ref object + * @return int <0 if KO, 0 if not found, >0 if OK + */ + function fetch($id, $ref='') + { + global $langs; + + $sql = "SELECT"; + $sql.= " c.rowid,"; + $sql.= " c.description,"; + $sql.= " c.datec,"; + $sql.= " c.tms,"; + $sql.= " c.fk_element,"; + $sql.= " c.element_type,"; + $sql.= " c.fk_user_author,"; + $sql.= " c.entity,"; + $sql.= " c.import_key"; + $sql.= " FROM ".MAIN_DB_PREFIX."comment as c"; + $sql.= " WHERE c.rowid = ".$id; + + dol_syslog(get_class($this)."::fetch", LOG_DEBUG); + $resql=$this->db->query($sql); + if ($resql) + { + $num_rows = $this->db->num_rows($resql); + + if ($num_rows) + { + $obj = $this->db->fetch_object($resql); + + $this->id = $obj->rowid; + $this->description = $obj->description; + $this->element_type = $obj->element_type; + $this->datec = $this->db->jdate($obj->datec); + $this->tms = $obj->tms; + $this->fk_user_author = $obj->fk_user_author; + $this->fk_element = $obj->fk_element; + $this->entity = $obj->entity; + $this->import_key = $obj->import_key; + } + + $this->db->free($resql); + + if ($num_rows) return 1; + else return 0; + } + else + { + $this->error="Error ".$this->db->lasterror(); + return -1; + } + } + + + /** + * Update database + * + * @param User $user User that modify + * @param int $notrigger 0=launch triggers after, 1=disable triggers + * @return int <=0 if KO, >0 if OK + */ + function update(User $user, $notrigger=0) + { + global $conf, $langs; + $error=0; + + // Clean parameters + if (isset($this->fk_element)) $this->fk_project=(int) trim($this->fk_element); + if (isset($this->fk_user_author)) $this->fk_user_author=(int) trim($this->fk_user_author); + if (isset($this->description)) $this->description=trim($this->description); + + + // Update request + $sql = "UPDATE ".MAIN_DB_PREFIX."projet_task_comment SET"; + $sql.= " description=".(isset($this->description)?"'".$this->db->escape($this->description)."'":"null").","; + $sql.= " datec=".($this->datec!=''?"'".$this->db->idate($this->datec)."'":'null').","; + $sql.= " fk_element=".(isset($this->fk_element)?$this->fk_element:"null").","; + $sql.= " element_type='".$this->element_type."',"; + $sql.= " fk_user_author=".(isset($this->fk_user_author)?$this->fk_user_author:"null").","; + $sql.= " entity=".(!empty($this->entity)?$this->entity:'1').","; + $sql.= " import_key=".(!empty($this->import_key)?"'".$this->db->escape($this->import_key)."'":"null"); + $sql.= " WHERE rowid=".$this->id; + + $this->db->begin(); + + dol_syslog(get_class($this)."::update", LOG_DEBUG); + $resql = $this->db->query($sql); + if (! $resql) { $error++; $this->errors[]="Error ".$this->db->lasterror(); } + + if (! $error) + { + if (! $notrigger) + { + // Call trigger + $result=$this->call_trigger('TASK_COMMENT_MODIFY',$user); + if ($result < 0) { $error++; } + // End call triggers + } + } + + // Commit or rollback + if ($error) + { + foreach($this->errors as $errmsg) + { + dol_syslog(get_class($this)."::update ".$errmsg, LOG_ERR); + $this->error.=($this->error?', '.$errmsg:$errmsg); + } + $this->db->rollback(); + return -1*$error; + } + else + { + $this->db->commit(); + return 1; + } + } + + + /** + * Delete task from database + * + * @param User $user User that delete + * @param int $notrigger 0=launch triggers after, 1=disable triggers + * @return int <0 if KO, >0 if OK + */ + function delete($user, $notrigger=0) + { + global $conf, $langs; + require_once DOL_DOCUMENT_ROOT . '/core/lib/files.lib.php'; + + $error=0; + + $this->db->begin(); + + $sql = "DELETE FROM ".MAIN_DB_PREFIX."comment"; + $sql.= " WHERE rowid=".$this->id; + + $resql = $this->db->query($sql); + if (! $resql) { $error++; $this->errors[]="Error ".$this->db->lasterror(); } + + if (! $error) + { + if (! $notrigger) + { + // Call trigger + $result=$this->call_trigger('TASK_COMMENT_DELETE',$user); + if ($result < 0) { $error++; } + // End call triggers + } + } + + // Commit or rollback + if ($error) + { + foreach($this->errors as $errmsg) + { + dol_syslog(get_class($this)."::delete ".$errmsg, LOG_ERR); + $this->error.=($this->error?', '.$errmsg:$errmsg); + } + $this->db->rollback(); + return -1*$error; + }else{ + $this->db->commit(); + return 1; + } + } + + + /** + * Load comments linked with current task + * + * @return array Comment array + */ + public static function fetchAllFor($element_type, $fk_element) + { + global $db,$conf; + $TComments = array(); + if(!empty($element_type) && !empty($fk_element)) { + $sql = "SELECT"; + $sql.= " c.rowid"; + $sql.= " FROM ".MAIN_DB_PREFIX."comment as c"; + $sql.= " WHERE c.fk_element = ".$fk_element; + $sql.= " AND c.element_type = '".$element_type."'"; + $sql.= " AND c.entity = ".$conf->entity; + $sql.= " ORDER BY c.tms DESC"; + + dol_syslog("Comment::fetchAllFor", LOG_DEBUG); + $resql=$db->query($sql); + if ($resql) + { + $num_rows = $db->num_rows($resql); + if ($num_rows > 0) + { + while($obj = $db->fetch_object($resql)) + { + $comment = new self($db); + $comment->fetch($obj->rowid); + $TComments[] = $comment; + } + } + $db->free($resql); + } + } + return $TComments; + } +} \ No newline at end of file diff --git a/htdocs/core/class/commonobject.class.php b/htdocs/core/class/commonobject.class.php index 54a907a3c0f..d7037ba5d2c 100644 --- a/htdocs/core/class/commonobject.class.php +++ b/htdocs/core/class/commonobject.class.php @@ -308,6 +308,12 @@ abstract class CommonObject * @var CommonObjectLine[] */ public $lines; + + /** + * @var mixed Contains comments + * @see fetchComments() + */ + public $comments=array(); /** * @var int @@ -5283,5 +5289,28 @@ abstract class CommonObject // TODO... } + + /** + * Load comments linked with current task + * @return boolean 1 if ok + */ + public function fetchComments() + { + require_once DOL_DOCUMENT_ROOT.'/core/class/comment.class.php'; + + $comment = new Comment($this->db); + $this->comments = Comment::fetchAllFor($this->element, $this->id); + return 1; + } + + /** + * Return nb comments already posted + * + * @return int + */ + public function getNbComments() + { + return count($this->comments); + } } diff --git a/htdocs/core/lib/project.lib.php b/htdocs/core/lib/project.lib.php index 0395f9f17ff..ec6be594ac3 100644 --- a/htdocs/core/lib/project.lib.php +++ b/htdocs/core/lib/project.lib.php @@ -66,7 +66,19 @@ function project_prepare_head($object) // $this->tabs = array('entity:+tabname:Title:@mymodule:/mymodule/mypage.php?id=__ID__'); to add new tab // $this->tabs = array('entity:-tabname); to remove a tab complete_head_from_modules($conf,$langs,$object,$head,$h,'project'); - + + + // Manage discussion + if (!empty($conf->global->PROJECT_ALLOW_COMMENT_ON_PROJECT)) + { + $nbComments = $object->getNbComments(); + $head[$h][0] = DOL_URL_ROOT.'/projet/comment.php?id='.$object->id; + $head[$h][1] = $langs->trans("CommentLink"); + if ($nbComments > 0) $head[$h][1].= ' '.$nbComments.''; + $head[$h][2] = 'project_comment'; + $h++; + } + if (empty($conf->global->MAIN_DISABLE_NOTES_TAB)) { $nbNote = 0; @@ -179,9 +191,9 @@ function task_prepare_head($object) // Manage discussion if (!empty($conf->global->PROJECT_ALLOW_COMMENT_ON_TASK)) { - $nbComments= $object->getNbComments(); + $nbComments = $object->getNbComments(); $head[$h][0] = DOL_URL_ROOT.'/projet/tasks/comment.php?id='.$object->id.(GETPOST('withproject')?'&withproject=1':''); - $head[$h][1] = $langs->trans("TaskCommentLinks"); + $head[$h][1] = $langs->trans("CommentLink"); if ($nbComments > 0) $head[$h][1].= ' '.$nbComments.''; $head[$h][2] = 'task_comment'; $h++; diff --git a/htdocs/core/tpl/bloc_comment.tpl.php b/htdocs/core/tpl/bloc_comment.tpl.php new file mode 100644 index 00000000000..b28699744d2 --- /dev/null +++ b/htdocs/core/tpl/bloc_comment.tpl.php @@ -0,0 +1,105 @@ +'; +print '
'; +print '
'; +print ''; +print ''; +print ''; +print ''; +print ''; + +print ''; + +print ''; +print ''; +print ''; +print ''; +print ''; +print "\n"; + +print ''; +print ''; + +// Description +print ''; + +print ''; +print '
'.$langs->trans("Comments").'
'; + +$desc = GETPOST('comment_description'); + +$doleditor = new DolEditor('comment_description', $desc, '', 80, 'dolibarr_notes', 'In', 0, false, true, ROWS_3, '100%'); +print $doleditor->Create(1); + +print ''; +print ''; +print '
'; + +// List of comments +if(!empty($object->comments)) { + // Default color for current user + $TColors = array($user->id => array('bgcolor'=>'efefef','color'=>'555')); + $first = true; + foreach($object->comments as $comment) { + $fk_user = $comment->fk_user_author; + $userstatic->fetch($fk_user); + if(empty($TColors[$fk_user])) { + $bgcolor = random_color(180,240); + if(!empty($userstatic->color)) { + $bgcolor = $userstatic->color; + } + $color = (colorIsLight($bgcolor))?'555':'fff'; + $TColors[$fk_user] = array('bgcolor'=>$bgcolor,'color'=>$color); + } + print '
'; + if($fk_user == $user->id) { + print '
 
'; + } + + print '
'; + print '
'; + if (! empty($user->photo)) + { + print Form::showphoto('userphoto', $userstatic, 80, 0, 0, '', 'small', 0, 1).'
'; + } + print $langs->trans('User').' : '.$userstatic->getNomUrl().'
'; + print $langs->trans('Date').' : '.dol_print_date($comment->datec,'dayhoursec'); + print '
'; // End comment-info + + print '
'; + print '
'; + print '
'; + print $comment->description; + print '
'; // End comment-description + if(($first && $fk_user == $user->id) || $user->admin == 1) { + print ''; + print img_picto('', 'delete.png'); + print ''; + } + print '
'; // End comment-table + print '
'; // End comment-right + print '
'; // End comment + + if($fk_user != $user->id) { + print '
 
'; + } + print '
'; + print '
'; // end 100p + + $first = false; + } +} + +print '
'; +print '
'; diff --git a/htdocs/install/mysql/migration/6.0.0-7.0.0.sql b/htdocs/install/mysql/migration/6.0.0-7.0.0.sql index d4e78720abf..80d2e7cb292 100644 --- a/htdocs/install/mysql/migration/6.0.0-7.0.0.sql +++ b/htdocs/install/mysql/migration/6.0.0-7.0.0.sql @@ -273,14 +273,15 @@ insert into llx_c_action_trigger (code,label,description,elementtype,rang) value insert into llx_c_action_trigger (code,label,description,elementtype,rang) values ('PROPOSAL_SUPPLIER_CLOSE_SIGNED','Price request closed signed','Executed when a customer proposal is closed signed','proposal_supplier',10); insert into llx_c_action_trigger (code,label,description,elementtype,rang) values ('PROPOSAL_SUPPLIER_CLOSE_REFUSED','Price request closed refused','Executed when a customer proposal is closed refused','proposal_supplier',10); - -CREATE TABLE llx_projet_task_comment ( +DROP TABLE `llx_projet_task_comment`; +CREATE TABLE IF NOT EXISTS llx_comment ( rowid integer AUTO_INCREMENT PRIMARY KEY, datec datetime DEFAULT NULL, tms timestamp, description text NOT NULL, - fk_user integer DEFAULT NULL, - fk_task integer DEFAULT NULL, + fk_user_author integer DEFAULT NULL, + fk_element integer DEFAULT NULL, + element_type varchar(50) DEFAULT NULL, entity integer DEFAULT 1, import_key varchar(125) DEFAULT NULL )ENGINE=innodb; diff --git a/htdocs/langs/en_US/main.lang b/htdocs/langs/en_US/main.lang index 1b92d87e9ba..39df55e02ce 100644 --- a/htdocs/langs/en_US/main.lang +++ b/htdocs/langs/en_US/main.lang @@ -866,3 +866,8 @@ SearchIntoContracts=Contracts SearchIntoCustomerShipments=Customer shipments SearchIntoExpenseReports=Expense reports SearchIntoLeaves=Leaves +CommentLink=Comments +NbComments=Number of comments +CommentPage=Comments space +CommentAdded=Comment added +CommentDeleted=Comment deleted diff --git a/htdocs/langs/en_US/projects.lang b/htdocs/langs/en_US/projects.lang index 408c3db5e7a..f9eb6c00477 100644 --- a/htdocs/langs/en_US/projects.lang +++ b/htdocs/langs/en_US/projects.lang @@ -210,8 +210,4 @@ OppStatusLOST=Lost Budget=Budget # Comments trans AllowCommentOnTask=Allow user comments on tasks -TaskCommentLinks=Comments -TaskNbComments=Number of comments -TaskComment=Task's comments space -CommentAdded=Comment added -CommentDeleted=Comment deleted +AllowCommentOnProject=Allow user comments on projects diff --git a/htdocs/langs/fr_FR/main.lang b/htdocs/langs/fr_FR/main.lang index 6a6c80a78bf..7a47c934a80 100644 --- a/htdocs/langs/fr_FR/main.lang +++ b/htdocs/langs/fr_FR/main.lang @@ -842,3 +842,8 @@ SearchIntoContracts=Contrats SearchIntoCustomerShipments=Expéditions clients SearchIntoExpenseReports=Notes de frais SearchIntoLeaves=Congés +CommentLink=Commentaires +NbComments=Nombre de commentaires +CommentPage=Espace commentaires +CommentAdded=Commentaire ajouté avec succès +CommentDeleted=Commentaire supprimé avec succès diff --git a/htdocs/langs/fr_FR/projects.lang b/htdocs/langs/fr_FR/projects.lang index 154c1138ab9..c235230eb2f 100644 --- a/htdocs/langs/fr_FR/projects.lang +++ b/htdocs/langs/fr_FR/projects.lang @@ -209,8 +209,4 @@ OppStatusLOST=Perdu Budget=Budget #Comments trans AllowCommentOnTask=Autoriser les commentaires entre utilisateurs sur les tâches -TaskCommentLinks=Commentaires -TaskNbComments=Nombre de commentaires -TaskComment=Tâches espace commentaires -CommentAdded=Commentaire ajouté avec succès -CommentDeleted=Commentaire supprimé avec succès +AllowCommentOnProject=Autoriser les commentaires entre utilisateurs sur les projets diff --git a/htdocs/projet/admin/project.php b/htdocs/projet/admin/project.php index 0c0da27457e..54e864e1bf6 100644 --- a/htdocs/projet/admin/project.php +++ b/htdocs/projet/admin/project.php @@ -918,6 +918,15 @@ print ''; print ' '; print ''; +print ''; +print ''.$langs->trans("AllowCommentOnProject").''; + +print ''; +echo ajax_constantonoff('PROJECT_ALLOW_COMMENT_ON_PROJECT'); +print ''; +print ' '; +print ''; + print ''; print ''.$langs->trans("AllowCommentOnTask").''; diff --git a/htdocs/projet/class/project.class.php b/htdocs/projet/class/project.class.php index af55063c66a..18aa3fe1f52 100644 --- a/htdocs/projet/class/project.class.php +++ b/htdocs/projet/class/project.class.php @@ -441,6 +441,7 @@ class Project extends CommonObject // Retreive all extrafield for thirdparty $this->fetch_optionals(); + $this->fetchComments(); return 1; } diff --git a/htdocs/projet/class/task.class.php b/htdocs/projet/class/task.class.php index 10a78e017c8..2fc849f9fe7 100644 --- a/htdocs/projet/class/task.class.php +++ b/htdocs/projet/class/task.class.php @@ -1783,332 +1783,4 @@ class Task extends CommonObject return ($datetouse > 0 && ($datetouse < ($now - $conf->projet->task->warning_delay))); } - - /** - * Return nb comments already posted - * - * @return int - */ - public function getNbComments() - { - return count($this->comments); - } - - /** - * Load comments linked with current task - * - * @return int <0 if KO, 0 if not found, >0 if OK - */ - public function fetchComments() - { - $this->comments = array(); - $sql = "SELECT"; - $sql.= " c.rowid"; - $sql.= " FROM ".MAIN_DB_PREFIX."projet_task_comment as c"; - $sql.= " WHERE c.fk_task = ".$this->id; - $sql.= " ORDER BY c.tms DESC"; - - dol_syslog(get_class($this)."::fetchComments", LOG_DEBUG); - $resql=$this->db->query($sql); - if ($resql) - { - $num_rows = $this->db->num_rows($resql); - if ($num_rows > 0) - { - while($obj = $this->db->fetch_object($resql)) - { - $comment = new TaskComment($this->db); - $comment->fetch($obj->rowid); - $this->comments[] = $comment; - } - return $num_rows; - }else{ - return 0; - } - } - else - { - $this->error="Error ".$this->db->lasterror(); - return -1; - } - } -} - -/** - * Class to manage tasks - */ -class TaskComment extends CommonObject -{ - public $element='project_task_comment'; //!< Id that identify managed objects - public $table_element='projet_task_comment'; //!< Name of table without prefix where object is stored - public $fk_element='fk_task'; - public $picto = 'task'; - - var $fk_task; - - var $description; - - var $tms; - - var $datec; - - var $fk_user; - - var $entity; - - var $import_key; - - public $oldcopy; - - - /** - * Constructor - * - * @param DoliDB $db Database handler - */ - function __construct($db) - { - $this->db = $db; - } - - - /** - * Create into database - * - * @param User $user User that create - * @param int $notrigger 0=launch triggers after, 1=disable triggers - * @return int <0 if KO, Id of created object if OK - */ - function create($user, $notrigger=0) - { - global $conf, $langs; - - $error=0; - - // Insert request - $sql = "INSERT INTO ".MAIN_DB_PREFIX."projet_task_comment ("; - $sql.= "description"; - $sql.= ", datec"; - $sql.= ", fk_task"; - $sql.= ", fk_user"; - $sql.= ", entity"; - $sql.= ", import_key"; - $sql.= ") VALUES ("; - $sql.= "'".$this->db->escape($this->description)."'"; - $sql.= ", ".($this->datec!=''?"'".$this->db->idate($this->datec)."'":'null'); - $sql.= ", '".(isset($this->fk_task)?$this->fk_task:"null")."'"; - $sql.= ", '".(isset($this->fk_user)?$this->fk_user:"null")."'"; - $sql.= ", ".(!empty($this->entity)?$this->entity:'1'); - $sql.= ", ".(!empty($this->import_key)?"'".$this->db->escape($this->import_key)."'":"null"); - $sql.= ")"; - - //var_dump($this->db); - //echo $sql; - - $this->db->begin(); - - dol_syslog(get_class($this)."::create", LOG_DEBUG); - $resql=$this->db->query($sql); - if (! $resql) { $error++; $this->errors[]="Error ".$this->db->lasterror(); } - - if (! $error) - { - $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX."projet_task_comment"); - - if (! $notrigger) - { - // Call trigger - $result=$this->call_trigger('TASK_COMMENT_CREATE',$user); - if ($result < 0) { $error++; } - // End call triggers - } - } - - // Commit or rollback - if ($error) - { - foreach($this->errors as $errmsg) - { - dol_syslog(get_class($this)."::create ".$errmsg, LOG_ERR); - $this->error.=($this->error?', '.$errmsg:$errmsg); - } - $this->db->rollback(); - return -1*$error; - } - else - { - $this->db->commit(); - return $this->id; - } - } - - - /** - * Load object in memory from database - * - * @param int $id Id object - * @param int $ref ref object - * @return int <0 if KO, 0 if not found, >0 if OK - */ - function fetch($id, $ref='') - { - global $langs; - - $sql = "SELECT"; - $sql.= " c.rowid,"; - $sql.= " c.description,"; - $sql.= " c.datec,"; - $sql.= " c.tms,"; - $sql.= " c.fk_task,"; - $sql.= " c.fk_user,"; - $sql.= " c.entity,"; - $sql.= " c.import_key"; - $sql.= " FROM ".MAIN_DB_PREFIX."projet_task_comment as c"; - $sql.= " WHERE c.rowid = ".$id; - - dol_syslog(get_class($this)."::fetch", LOG_DEBUG); - $resql=$this->db->query($sql); - if ($resql) - { - $num_rows = $this->db->num_rows($resql); - - if ($num_rows) - { - $obj = $this->db->fetch_object($resql); - - $this->id = $obj->rowid; - $this->description = $obj->description; - $this->datec = $this->db->jdate($obj->datec); - $this->tms = $obj->tms; - $this->fk_user = $obj->fk_user; - $this->fk_task = $obj->fk_task; - $this->entity = $obj->entity; - $this->import_key = $obj->import_key; - } - - $this->db->free($resql); - - if ($num_rows) return 1; - else return 0; - } - else - { - $this->error="Error ".$this->db->lasterror(); - return -1; - } - } - - - /** - * Update database - * - * @param User $user User that modify - * @param int $notrigger 0=launch triggers after, 1=disable triggers - * @return int <=0 if KO, >0 if OK - */ - function update(User $user, $notrigger=0) - { - global $conf, $langs; - $error=0; - - // Clean parameters - if (isset($this->fk_task)) $this->fk_project=(int) trim($this->fk_task); - if (isset($this->fk_user)) $this->fk_user=(int) trim($this->fk_user); - if (isset($this->description)) $this->description=trim($this->description); - - - // Update request - $sql = "UPDATE ".MAIN_DB_PREFIX."projet_task_comment SET"; - $sql.= " description=".(isset($this->description)?"'".$this->db->escape($this->description)."'":"null").","; - $sql.= " datec=".($this->datec!=''?"'".$this->db->idate($this->datec)."'":'null').","; - $sql.= " fk_task=".(isset($this->fk_task)?$this->fk_task:"null").","; - $sql.= " fk_user=".(isset($this->fk_user)?$this->fk_user:"null").","; - $sql.= " entity=".(!empty($this->entity)?$this->entity:'1').","; - $sql.= " import_key=".(!empty($this->import_key)?"'".$this->db->escape($this->import_key)."'":"null"); - $sql.= " WHERE rowid=".$this->id; - - $this->db->begin(); - - dol_syslog(get_class($this)."::update", LOG_DEBUG); - $resql = $this->db->query($sql); - if (! $resql) { $error++; $this->errors[]="Error ".$this->db->lasterror(); } - - if (! $error) - { - if (! $notrigger) - { - // Call trigger - $result=$this->call_trigger('TASK_COMMENT_MODIFY',$user); - if ($result < 0) { $error++; } - // End call triggers - } - } - - // Commit or rollback - if ($error) - { - foreach($this->errors as $errmsg) - { - dol_syslog(get_class($this)."::update ".$errmsg, LOG_ERR); - $this->error.=($this->error?', '.$errmsg:$errmsg); - } - $this->db->rollback(); - return -1*$error; - } - else - { - $this->db->commit(); - return 1; - } - } - - - /** - * Delete task from database - * - * @param User $user User that delete - * @param int $notrigger 0=launch triggers after, 1=disable triggers - * @return int <0 if KO, >0 if OK - */ - function delete($user, $notrigger=0) - { - global $conf, $langs; - require_once DOL_DOCUMENT_ROOT . '/core/lib/files.lib.php'; - - $error=0; - - $this->db->begin(); - - $sql = "DELETE FROM ".MAIN_DB_PREFIX."projet_task_comment"; - $sql.= " WHERE rowid=".$this->id; - - $resql = $this->db->query($sql); - if (! $resql) { $error++; $this->errors[]="Error ".$this->db->lasterror(); } - - if (! $error) - { - if (! $notrigger) - { - // Call trigger - $result=$this->call_trigger('TASK_COMMENT_DELETE',$user); - if ($result < 0) { $error++; } - // End call triggers - } - } - - // Commit or rollback - if ($error) - { - foreach($this->errors as $errmsg) - { - dol_syslog(get_class($this)."::delete ".$errmsg, LOG_ERR); - $this->error.=($this->error?', '.$errmsg:$errmsg); - } - $this->db->rollback(); - return -1*$error; - }else{ - $this->db->commit(); - return 1; - } - } } \ No newline at end of file diff --git a/htdocs/projet/comment.php b/htdocs/projet/comment.php new file mode 100644 index 00000000000..4e3d52a2f37 --- /dev/null +++ b/htdocs/projet/comment.php @@ -0,0 +1,189 @@ + + * Copyright (C) 2006-2017 Laurent Destailleur + * Copyright (C) 2010-2012 Regis Houssin + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +/** + * \file htdocs/projet/tasks/task.php + * \ingroup project + * \brief Page of a project task + */ + +require '../main.inc.php'; +require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php'; +require_once DOL_DOCUMENT_ROOT.'/projet/class/task.class.php'; +require_once DOL_DOCUMENT_ROOT.'/core/lib/project.lib.php'; +require_once DOL_DOCUMENT_ROOT.'/core/class/html.formprojet.class.php'; +require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php'; +require_once DOL_DOCUMENT_ROOT.'/core/class/html.formother.class.php'; +require_once DOL_DOCUMENT_ROOT.'/core/modules/project/modules_project.php'; +require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php'; +require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php'; + +$langs->load("projects"); +$langs->load("companies"); + +$id=GETPOST('id','int'); +$idcomment=GETPOST('idcomment','int'); +$ref=GETPOST("ref",'alpha',1); // task ref +$objectref=GETPOST("taskref",'alpha'); // task ref +$action=GETPOST('action','alpha'); +$confirm=GETPOST('confirm','alpha'); +$withproject=GETPOST('withproject','int'); +$project_ref=GETPOST('project_ref','alpha'); +$planned_workload=((GETPOST('planned_workloadhour','int')!='' || GETPOST('planned_workloadmin','int')!='') ? (GETPOST('planned_workloadhour','int')>0?GETPOST('planned_workloadhour','int')*3600:0) + (GETPOST('planned_workloadmin','int')>0?GETPOST('planned_workloadmin','int')*60:0) : ''); + +// Security check +$socid=0; +//if ($user->societe_id > 0) $socid = $user->societe_id; // For external user, no check is done on company because readability is managed by public status of project and assignement. +if (! $user->rights->projet->lire) accessforbidden(); + +// Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context +$hookmanager->initHooks(array('projectcard','globalcard')); + +$object = new Project($db); +$extrafields = new ExtraFields($db); +$object = new Project($db); + +// fetch optionals attributes and labels +$extralabels=$extrafields->fetch_name_optionals_label($object->table_element); + +// Load object +if ($id > 0 || ! empty($ref)) +{ + $ret = $object->fetch($id,$ref); // If we create project, ref may be defined into POST but record does not yet exists into database + if ($ret > 0) { + $object->fetch_thirdparty(); + $id=$object->id; + } +} + +// include comment actions +include DOL_DOCUMENT_ROOT . '/core/actions_comments.inc.php'; + +/* + * View +*/ + + +llxHeader('', $langs->trans("CommentPage")); + +$form = new Form($db); +$formother = new FormOther($db); +$formfile = new FormFile($db); + +// Tabs for project +$tab = 'project_comment'; +$head = project_prepare_head($object); +dol_fiche_head($head, $tab, $langs->trans("Project"), - 1, ($object->public ? 'projectpub' : 'project')); + +$param = ($mode == 'mine' ? '&mode=mine' : ''); + +// Project card + +$linkback = '' . $langs->trans("BackToList") . ''; + +$morehtmlref = '
'; +// Title +$morehtmlref .= $object->title; +// Thirdparty +if ($object->thirdparty->id > 0) { + $morehtmlref .= '
' . $langs->trans('ThirdParty') . ' : ' . $object->thirdparty->getNomUrl(1, 'project'); +} +$morehtmlref .= '
'; + +// Define a complementary filter for search of next/prev ref. +if (! $user->rights->projet->all->lire) { + $objectsListId = $object->getProjectsAuthorizedForUser($user, 0, 0); + $object->next_prev_filter = " rowid in (" . (count($objectsListId) ? join(',', array_keys($objectsListId)) : '0') . ")"; +} + +dol_banner_tab($object, 'project_ref', $linkback, 1, 'ref', 'ref', $morehtmlref); + +print '
'; +print '
'; +print '
'; + +print ''; + +// Visibility +print ''; + +// Date start - end +print ''; + +// Budget +print ''; + +// Other attributes +$cols = 2; +// include DOL_DOCUMENT_ROOT . '/core/tpl/extrafields_view.tpl.php'; + +print '
' . $langs->trans("Visibility") . ''; +if ($object->public) print $langs->trans('SharedProject'); +else + print $langs->trans('PrivateProject'); +print '
' . $langs->trans("DateStart") . ' - ' . $langs->trans("DateEnd") . ''; +print dol_print_date($object->date_start, 'day'); +$end = dol_print_date($object->date_end, 'day'); +if ($end) print ' - ' . $end; +print '
' . $langs->trans("Budget") . ''; +if (strcmp($object->budget_amount, '')) print price($object->budget_amount, '', $langs, 1, 0, 0, $conf->currency); +print '
'; + +print '
'; +print '
'; +print '
'; +print '
'; + +print ''; + +// Description +print ''; + +// Categories +if ($conf->categorie->enabled) { + print '"; +} + +// Nb comments +print ''; + +print '
' . $langs->trans("Description") . ''; +print nl2br($object->description); +print '
' . $langs->trans("Categories") . ''; + print $form->showCategories($object->id, 'project', 1); + print "
'.$langs->trans("NbComments").''; +print $object->getNbComments(); +print '
'; + +print '
'; +print '
'; +print '
'; + +print '
'; + +dol_fiche_end(); + +print '
'; + +// Include comment tpl view +include DOL_DOCUMENT_ROOT . '/core/tpl/bloc_comment.tpl.php'; + + +llxFooter(); +$db->close(); diff --git a/htdocs/projet/tasks/comment.php b/htdocs/projet/tasks/comment.php index a36337c324d..e4250bad062 100644 --- a/htdocs/projet/tasks/comment.php +++ b/htdocs/projet/tasks/comment.php @@ -33,7 +33,6 @@ require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php'; require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php'; require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php'; require_once DOL_DOCUMENT_ROOT.'/core/modules/project/task/modules_task.php'; -require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php'; $langs->load("projects"); $langs->load("companies"); @@ -41,7 +40,7 @@ $langs->load("companies"); $id=GETPOST('id','int'); $idcomment=GETPOST('idcomment','int'); $ref=GETPOST("ref",'alpha',1); // task ref -$taskref=GETPOST("taskref",'alpha'); // task ref +$objectref=GETPOST("taskref",'alpha'); // task ref $action=GETPOST('action','alpha'); $confirm=GETPOST('confirm','alpha'); $withproject=GETPOST('withproject','int'); @@ -56,69 +55,25 @@ if (! $user->rights->projet->lire) accessforbidden(); // Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context $hookmanager->initHooks(array('projecttaskcard','globalcard')); -$task = new Task($db); -$object = new TaskComment($db); +$object = new Task($db); $extrafields = new ExtraFields($db); $projectstatic = new Project($db); -$userstatic = new User($db); // fetch optionals attributes and labels -$extralabels=$extrafields->fetch_name_optionals_label($task->table_element); +$extralabels=$extrafields->fetch_name_optionals_label($object->table_element); - -/* - * Actions - */ - -if ($action == 'addcomment') -{ - if (!empty($_POST['comment_description'])) - { - $object->description = GETPOST('comment_description'); - $object->datec = time(); - $object->fk_task = $id; - $object->fk_user = $user->id; - $object->entity = $conf->entity; - if ($object->create($user) > 0) - { - setEventMessages($langs->trans("CommentAdded"), null, 'mesgs'); - header('Location: '.DOL_URL_ROOT.'/projet/tasks/comment.php?id='.$id.($withproject?'&withproject=1':'')); - exit; - } - else - { - setEventMessages($task->error,$task->errors,'errors'); - $action=''; - } - } -} -if ($action == 'deletecomment') -{ - if ($object->fetch($idcomment) >= 0) - { - if ($object->delete($user) > 0) - { - setEventMessages($langs->trans("CommentDeleted"), null, 'mesgs'); - header('Location: '.DOL_URL_ROOT.'/projet/tasks/comment.php?id='.$id.($withproject?'&withproject=1':'')); - exit; - } - else - { - setEventMessages($task->error,$task->errors,'errors'); - $action=''; - } - } -} +// include comment actions +include DOL_DOCUMENT_ROOT . '/core/actions_comments.inc.php'; // Retreive First Task ID of Project if withprojet is on to allow project prev next to work if (! empty($project_ref) && ! empty($withproject)) { if ($projectstatic->fetch('',$project_ref) > 0) { - $tasksarray=$task->getTasksArray(0, 0, $projectstatic->id, $socid, 0); - if (count($tasksarray) > 0) + $objectsarray=$object->getTasksArray(0, 0, $projectstatic->id, $socid, 0); + if (count($objectsarray) > 0) { - $id=$tasksarray[0]->id; + $id=$objectsarray[0]->id; } else { @@ -132,7 +87,7 @@ if (! empty($project_ref) && ! empty($withproject)) */ -llxHeader('', $langs->trans("TaskComment")); +llxHeader('', $langs->trans("CommentPage")); $form = new Form($db); $formother = new FormOther($db); @@ -140,14 +95,14 @@ $formfile = new FormFile($db); if ($id > 0 || ! empty($ref)) { - if ($task->fetch($id,$ref) > 0) + if ($object->fetch($id,$ref) > 0) { - $res=$task->fetch_optionals($task->id,$extralabels); + $res=$object->fetch_optionals($object->id,$extralabels); - $result=$projectstatic->fetch($task->fk_project); + $result=$projectstatic->fetch($object->fk_project); if (! empty($projectstatic->socid)) $projectstatic->fetch_thirdparty(); - $task->project = clone $projectstatic; + $object->project = clone $projectstatic; $userWrite = $projectstatic->restrictedProjectArea($user,'write'); @@ -177,8 +132,8 @@ if ($id > 0 || ! empty($ref)) // Define a complementary filter for search of next/prev ref. if (! $user->rights->projet->all->lire) { - $tasksListId = $projectstatic->getProjectsAuthorizedForUser($user,0,0); - $projectstatic->next_prev_filter=" rowid in (".(count($tasksListId)?join(',',array_keys($tasksListId)):'0').")"; + $objectsListId = $projectstatic->getProjectsAuthorizedForUser($user,0,0); + $projectstatic->next_prev_filter=" rowid in (".(count($objectsListId)?join(',',array_keys($objectsListId)):'0').")"; } dol_banner_tab($projectstatic, 'project_ref', $linkback, 1, 'ref', 'ref', $morehtmlref); @@ -245,7 +200,7 @@ if ($id > 0 || ! empty($ref)) print '
'; } - $head=task_prepare_head($task); + $head=task_prepare_head($object); /* * Fiche tache en mode visu @@ -263,9 +218,9 @@ if ($id > 0 || ! empty($ref)) if (! GETPOST('withproject') || empty($projectstatic->id)) { $projectsListId = $projectstatic->getProjectsAuthorizedForUser($user,0,1); - $task->next_prev_filter=" fk_projet in (".$projectsListId.")"; + $object->next_prev_filter=" fk_projet in (".$projectsListId.")"; } - else $task->next_prev_filter=" fk_projet = ".$projectstatic->id; + else $object->next_prev_filter=" fk_projet = ".$projectstatic->id; $morehtmlref=''; @@ -285,7 +240,7 @@ if ($id > 0 || ! empty($ref)) $morehtmlref.=''; } - dol_banner_tab($task, 'ref', $linkback, 1, 'ref', 'ref', $morehtmlref, $param); + dol_banner_tab($object, 'ref', $linkback, 1, 'ref', 'ref', $morehtmlref, $param); print '
'; @@ -293,8 +248,8 @@ if ($id > 0 || ! empty($ref)) print ''; // Nb comments - print ''; // Other attributes @@ -308,102 +263,9 @@ if ($id > 0 || ! empty($ref)) dol_fiche_end(); - - print '
'; - print '
'; - - // Add comment - - print '
'; - print ''; - print ''; - print ''; - print ''; - - print '
'.$langs->trans("TaskNbComments").''; - print $task->getNbComments(); + print ''.$langs->trans("NbComments").''; + print $object->getNbComments(); print '
'; - - print ''; - print ''; - print ''; - print ''; - print ''; - print "\n"; - - print ''; - print ''; - - // Description - print ''; - - print ''; - print '
'.$langs->trans("Comments").'
'; - - $desc = ($_POST['comment_description']?$_POST['comment_description']:''); - - $doleditor = new DolEditor('comment_description', $desc, '', 80, 'dolibarr_notes', 'In', 0, false, true, ROWS_3, '100%'); - print $doleditor->Create(1); - - print ''; - print ''; - print '
'; - - // List of comments - if(!empty($task->comments)) { - // Default color for current user - $TColors = array($user->id => array('bgcolor'=>'efefef','color'=>'555')); - $first = true; - foreach($task->comments as $comment) { - $fk_user = $comment->fk_user; - $userstatic->fetch($fk_user); - if(empty($TColors[$fk_user])) { - $bgcolor = random_color(180,240); - if(!empty($userstatic->color)) { - $bgcolor = $userstatic->color; - } - $color = (colorIsLight($bgcolor))?'555':'fff'; - $TColors[$fk_user] = array('bgcolor'=>$bgcolor,'color'=>$color); - } - print '
'; - if($comment->fk_user == $user->id) { - print '
 
'; - } - - print '
'; - print '
'; - if (! empty($user->photo)) - { - print Form::showphoto('userphoto', $userstatic, 80, 0, 0, '', 'small', 0, 1).'
'; - } - print $langs->trans('User').' : '.$userstatic->getNomUrl().'
'; - print $langs->trans('Date').' : '.dol_print_date($comment->datec,'dayhoursec'); - print '
'; // End comment-info - - print '
'; - print '
'; - print '
'; - print $comment->description; - print '
'; // End comment-description - if(($first && $fk_user == $user->id) || $user->admin == 1) { - print ''; - print img_picto('', 'delete.png'); - print ''; - } - print '
'; // End comment-table - print '
'; // End comment-right - print '
'; // End comment - - if($comment->fk_user != $user->id) { - print '
 
'; - } - print '
'; - print '
'; // end 100p - - $first = false; - } - } - - print '
'; - print '
'; + + // Include comment tpl view + include DOL_DOCUMENT_ROOT . '/core/tpl/bloc_comment.tpl.php'; } } From 7f807986d7b1de8cd5ad7762f190f57444b6465a Mon Sep 17 00:00:00 2001 From: arnaud Date: Wed, 27 Sep 2017 10:53:29 +0200 Subject: [PATCH 02/46] FIX replenish if line test GETPOST on line 0 --- htdocs/product/stock/replenish.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/htdocs/product/stock/replenish.php b/htdocs/product/stock/replenish.php index 55fe5908c7f..28786f0d324 100644 --- a/htdocs/product/stock/replenish.php +++ b/htdocs/product/stock/replenish.php @@ -115,7 +115,7 @@ if ($action == 'order' && isset($_POST['valid'])) $suppliers = array(); for ($i = 0; $i < $linecount; $i++) { - if (GETPOST($i, 'alpha') === 'on' && GETPOST('fourn' . $i, 'int') > 0) + if (GETPOST('choose' . $i, 'alpha') === 'on' && GETPOST('fourn' . $i, 'int') > 0) { //one line $box = $i; @@ -616,7 +616,7 @@ while ($i < ($limit ? min($num, $limit) : $num)) // Select field //print ''; - print ''; + print ''; print ''.$prod->getNomUrl(1, '').''; From 537a551bb5972cd2d413ea3f453a499951c924e6 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Wed, 27 Sep 2017 21:58:42 +0200 Subject: [PATCH 03/46] Fix vat visiblity on pdf --- htdocs/core/lib/functions.lib.php | 4 ++-- htdocs/core/lib/pdf.lib.php | 7 ++++--- htdocs/core/modules/commande/doc/pdf_einstein.modules.php | 6 +++--- htdocs/core/modules/facture/doc/pdf_crabe.modules.php | 6 +++--- htdocs/core/modules/propale/doc/pdf_azur.modules.php | 7 ++++--- 5 files changed, 16 insertions(+), 14 deletions(-) diff --git a/htdocs/core/lib/functions.lib.php b/htdocs/core/lib/functions.lib.php index bfddc4b4921..e87f46ad2bf 100644 --- a/htdocs/core/lib/functions.lib.php +++ b/htdocs/core/lib/functions.lib.php @@ -3684,7 +3684,7 @@ function print_fleche_navigation($page, $file, $options='', $nextpage=0, $betwee * @param string $rate Rate value to format ('19.6', '19,6', '19.6%', '19,6%', '19.6 (CODEX)', ...) * @param boolean $addpercent Add a percent % sign in output * @param int $info_bits Miscellaneous information on vat (0=Default, 1=French NPR vat) - * @param int $usestarfornpr 1=Use '*' for NPR vat rate intead of MAIN_LABEL_MENTION_NPR + * @param int $usestarfornpr -1=Never show, 0 or 1=Use '*' for NPR vat rates * @return string String with formated amounts ('19,6' or '19,6%' or '8.5% (NPR)' or '8.5% *' or '19,6 (CODEX)') */ function vatrate($rate, $addpercent=false, $info_bits=0, $usestarfornpr=0) @@ -3714,7 +3714,7 @@ function vatrate($rate, $addpercent=false, $info_bits=0, $usestarfornpr=0) // TODO Split on / and output with a price2num to have clean numbers without ton of 000. $ret=$rate.($addpercent?'%':''); } - if ($info_bits & 1) $ret.=' *'; + if (($info_bits & 1) && $usestarfornpr >= 0) $ret.=' *'; $ret.=$morelabel; return $ret; } diff --git a/htdocs/core/lib/pdf.lib.php b/htdocs/core/lib/pdf.lib.php index 8a445625022..698ba131ca6 100644 --- a/htdocs/core/lib/pdf.lib.php +++ b/htdocs/core/lib/pdf.lib.php @@ -1491,14 +1491,14 @@ function pdf_getlinevatrate($object,$i,$outputlangs,$hidedetails=0) { $tmpresult=''; - $tmpresult.=vatrate($object->lines[$i]->tva_tx, 1, $object->lines[$i]->info_bits, 1); + $tmpresult.=vatrate($object->lines[$i]->tva_tx, 0, $object->lines[$i]->info_bits, -1); if (empty($conf->global->MAIN_PDF_MAIN_HIDE_SECOND_TAX)) { if ($object->lines[$i]->total_localtax1 != 0) { if (preg_replace('/[\s0%]/','',$tmpresult)) $tmpresult.='/'; else $tmpresult=''; - $tmpresult.=vatrate(abs($object->lines[$i]->localtax1_tx),1); + $tmpresult.=vatrate(abs($object->lines[$i]->localtax1_tx), 0); } } if (empty($conf->global->MAIN_PDF_MAIN_HIDE_THIRD_TAX)) @@ -1507,9 +1507,10 @@ function pdf_getlinevatrate($object,$i,$outputlangs,$hidedetails=0) { if (preg_replace('/[\s0%]/','',$tmpresult)) $tmpresult.='/'; else $tmpresult=''; - $tmpresult.=vatrate(abs($object->lines[$i]->localtax2_tx),1); + $tmpresult.=vatrate(abs($object->lines[$i]->localtax2_tx), 0); } } + $tmpresult.= '%'; $result.=$tmpresult; } diff --git a/htdocs/core/modules/commande/doc/pdf_einstein.modules.php b/htdocs/core/modules/commande/doc/pdf_einstein.modules.php index 74a72b36581..80c6e6680b2 100644 --- a/htdocs/core/modules/commande/doc/pdf_einstein.modules.php +++ b/htdocs/core/modules/commande/doc/pdf_einstein.modules.php @@ -140,7 +140,7 @@ class pdf_einstein extends ModelePDFCommandes } else { - $this->posxtva=112; + $this->posxtva=110; $this->posxup=126; $this->posxqty=145; } @@ -431,8 +431,8 @@ class pdf_einstein extends ModelePDFCommandes if (empty($conf->global->MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT) && empty($conf->global->MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT_COLUMN)) { $vat_rate = pdf_getlinevatrate($object, $i, $outputlangs, $hidedetails); - $pdf->SetXY($this->posxtva, $curY); - $pdf->MultiCell($this->posxup-$this->posxtva-0.8, 3, $vat_rate, 0, 'R'); + $pdf->SetXY($this->posxtva-5, $curY); + $pdf->MultiCell($this->posxup-$this->posxtva+4, 3, $vat_rate, 0, 'R'); } // Unit price before discount diff --git a/htdocs/core/modules/facture/doc/pdf_crabe.modules.php b/htdocs/core/modules/facture/doc/pdf_crabe.modules.php index 338a6019b56..98b2367db32 100644 --- a/htdocs/core/modules/facture/doc/pdf_crabe.modules.php +++ b/htdocs/core/modules/facture/doc/pdf_crabe.modules.php @@ -125,7 +125,7 @@ class pdf_crabe extends ModelePDFFactures } else { - $this->posxtva=112; + $this->posxtva=110; $this->posxup=126; $this->posxqty=145; } @@ -496,8 +496,8 @@ class pdf_crabe extends ModelePDFFactures if (empty($conf->global->MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT) && empty($conf->global->MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT_COLUMN)) { $vat_rate = pdf_getlinevatrate($object, $i, $outputlangs, $hidedetails); - $pdf->SetXY($this->posxtva, $curY); - $pdf->MultiCell($this->posxup-$this->posxtva-0.8, 3, $vat_rate, 0, 'R'); + $pdf->SetXY($this->posxtva-5, $curY); + $pdf->MultiCell($this->posxup-$this->posxtva+4, 3, $vat_rate, 0, 'R'); } // Unit price before discount diff --git a/htdocs/core/modules/propale/doc/pdf_azur.modules.php b/htdocs/core/modules/propale/doc/pdf_azur.modules.php index 8b9929f2880..9105a82b0d4 100644 --- a/htdocs/core/modules/propale/doc/pdf_azur.modules.php +++ b/htdocs/core/modules/propale/doc/pdf_azur.modules.php @@ -114,7 +114,7 @@ class pdf_azur extends ModelePDFPropales } else { - $this->posxtva=112; + $this->posxtva=110; $this->posxup=126; $this->posxqty=145; } @@ -505,8 +505,8 @@ class pdf_azur extends ModelePDFPropales if (empty($conf->global->MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT) && empty($conf->global->MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT_COLUMN)) { $vat_rate = pdf_getlinevatrate($object, $i, $outputlangs, $hidedetails); - $pdf->SetXY($this->posxtva, $curY); - $pdf->MultiCell($this->posxup-$this->posxtva-0.8, 3, $vat_rate, 0, 'R'); + $pdf->SetXY($this->posxtva-5, $curY); + $pdf->MultiCell($this->posxup-$this->posxtva+4, 3, $vat_rate, 0, 'R'); } // Unit price before discount @@ -1310,6 +1310,7 @@ class pdf_azur extends ModelePDFPropales $pdf->line($this->posxtva-1, $tab_top, $this->posxtva-1, $tab_top + $tab_height); if (empty($hidetop)) { + // Not do -3 and +3 instead of -1 -1 to have more space for text 'Sales tax' $pdf->SetXY($this->posxtva-3, $tab_top+1); $pdf->MultiCell($this->posxup-$this->posxtva+3,2, $outputlangs->transnoentities("VAT"),'','C'); } From 93cf135d5e459595bf36ae5bea608c89d34ccb30 Mon Sep 17 00:00:00 2001 From: Juanjo Menent Date: Thu, 28 Sep 2017 12:05:41 +0200 Subject: [PATCH 04/46] FIX: #7510 Bug: extrafield content disappear when generate pdf within intervention --- htdocs/fichinter/card.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/htdocs/fichinter/card.php b/htdocs/fichinter/card.php index 4ed3ecb7cef..213e4cc4d2b 100644 --- a/htdocs/fichinter/card.php +++ b/htdocs/fichinter/card.php @@ -2,7 +2,7 @@ /* Copyright (C) 2002-2007 Rodolphe Quiedeville * Copyright (C) 2004-2016 Laurent Destailleur * Copyright (C) 2005-2015 Regis Houssin - * Copyright (C) 2011-2013 Juanjo Menent + * Copyright (C) 2011-2017 Juanjo Menent * Copyright (C) 2013 Florian Henry * Copyright (C) 2014-2015 Ferran Marcet * Copyright (C) 2014-2015 Charlie Benke @@ -785,7 +785,8 @@ if (empty($reshook)) $parameters=array('id'=>$object->id); $reshook=$hookmanager->executeHooks('insertExtraFields',$parameters,$object,$action); // Note that $action and $object may have been modified by some hooks if (empty($reshook)) - { $result=$object->updateExtraField($_POST["attribute"]); + { + $result=$object->insertExtraFields(); if ($result < 0) { $error++; From 7ba2dd8397f638b07ac7d8e4e8b3506c8b9aa538 Mon Sep 17 00:00:00 2001 From: atm-ph Date: Thu, 28 Sep 2017 15:25:51 +0200 Subject: [PATCH 05/46] Fix the pdf_getlineprogress hook isn't use because hookmanager is null --- htdocs/core/lib/pdf.lib.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/htdocs/core/lib/pdf.lib.php b/htdocs/core/lib/pdf.lib.php index 1b79cc9163d..89c4ceaa137 100644 --- a/htdocs/core/lib/pdf.lib.php +++ b/htdocs/core/lib/pdf.lib.php @@ -1753,6 +1753,8 @@ function pdf_getlineremisepercent($object,$i,$outputlangs,$hidedetails=0) */ function pdf_getlineprogress($object, $i, $outputlangs, $hidedetails = 0, $hookmanager = null) { + if (empty($hookmanager)) global $hookmanager; + $reshook=0; $result=''; //if (is_object($hookmanager) && ( (isset($object->lines[$i]->product_type) && $object->lines[$i]->product_type == 9 && ! empty($object->lines[$i]->special_code)) || ! empty($object->lines[$i]->fk_parent_line) ) ) From 30a9e40f4ed0ebd4c0b8c6eb0b6c2c3674e17f6f Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Thu, 28 Sep 2017 17:29:37 +0200 Subject: [PATCH 06/46] Fix position of fields --- htdocs/api/class/api.class.php | 3 ++ .../comm/propal/class/api_proposals.class.php | 44 ++++++++++++++----- 2 files changed, 35 insertions(+), 12 deletions(-) diff --git a/htdocs/api/class/api.class.php b/htdocs/api/class/api.class.php index dcda8255e7c..10d03acef8e 100644 --- a/htdocs/api/class/api.class.php +++ b/htdocs/api/class/api.class.php @@ -131,6 +131,9 @@ class DolibarrApi unset($object->table_element_line); unset($object->picto); + unset($object->skip_update_total); + unset($object->context); + // Remove the $oldcopy property because it is not supported by the JSON // encoder. The following error is generated when trying to serialize // it: "Error encoding/decoding JSON: Type is not supported" diff --git a/htdocs/comm/propal/class/api_proposals.class.php b/htdocs/comm/propal/class/api_proposals.class.php index 42dbdbf9d2c..46ac4cf0327 100644 --- a/htdocs/comm/propal/class/api_proposals.class.php +++ b/htdocs/comm/propal/class/api_proposals.class.php @@ -278,7 +278,7 @@ class Proposals extends DolibarrApi $request_data->fk_unit, $this->element, $request_data->id, - $request_data->pu_ht_devise, + $request_data->multicurrency_subprice, $request_data->fk_remise_except ); @@ -316,26 +316,27 @@ class Proposals extends DolibarrApi $request_data = (object) $request_data; $updateRes = $this->propal->updateline( $lineid, - $request_data->desc, $request_data->subprice, $request_data->qty, $request_data->remise_percent, $request_data->tva_tx, $request_data->localtax1_tx, $request_data->localtax2_tx, - 'HT', + $request_data->desc, + 'HT', $request_data->info_bits, - $request_data->date_start, - $request_data->date_end, - $request_data->product_type, - $request_data->fk_parent_line, - 0, - $request_data->fk_fournprice, - $request_data->pa_ht, - $request_data->label, $request_data->special_code, + $request_data->fk_parent_line, + 0, + $request_data->fk_fournprice, + $request_data->pa_ht, + $request_data->label, + $request_data->product_type, + $request_data->date_start, + $request_data->date_end, $request_data->array_options, - $request_data->fk_unit + $request_data->fk_unit, + $request_data->multicurrency_subprice ); if ($updateRes > 0) { @@ -508,4 +509,23 @@ class Proposals extends DolibarrApi } return $propal; } + + /** + * Clean sensible object datas + * + * @param object $object Object to clean + * @return array Array of cleaned object properties + */ + function _cleanObjectDatas($object) { + + $object = parent::_cleanObjectDatas($object); + + unset($object->name); + unset($object->lastname); + unset($object->firstname); + unset($object->civility_id); + unset($object->address); + + return $object; + } } From f510f3062bd17552b8d101f0520e23b697674fc7 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Thu, 28 Sep 2017 17:41:18 +0200 Subject: [PATCH 07/46] Clean param type --- htdocs/comm/propal/class/propal.class.php | 1 + 1 file changed, 1 insertion(+) diff --git a/htdocs/comm/propal/class/propal.class.php b/htdocs/comm/propal/class/propal.class.php index f2ecb877a9a..ce56e1386ef 100644 --- a/htdocs/comm/propal/class/propal.class.php +++ b/htdocs/comm/propal/class/propal.class.php @@ -639,6 +639,7 @@ class Propal extends CommonObject $pa_ht=price2num($pa_ht); if (empty($qty) && empty($special_code)) $special_code=3; // Set option tag if (! empty($qty) && $special_code == 3) $special_code=0; // Remove option tag + if (empty($type)) $type=0; if ($this->statut == self::STATUS_DRAFT) { From 4a63e6b6ec256e3ff4bb7ea0c9773a3e8f0d12ee Mon Sep 17 00:00:00 2001 From: Regis Houssin Date: Fri, 29 Sep 2017 19:07:13 +0200 Subject: [PATCH 08/46] Fix: two errors when you create invoice from shipping --- htdocs/compta/facture/class/facture.class.php | 2 +- htdocs/install/mysql/data/llx_c_type_contact.sql | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/htdocs/compta/facture/class/facture.class.php b/htdocs/compta/facture/class/facture.class.php index 6c73746d9af..3c4bfec6a45 100644 --- a/htdocs/compta/facture/class/facture.class.php +++ b/htdocs/compta/facture/class/facture.class.php @@ -486,7 +486,7 @@ class Facture extends CommonInvoice foreach ($exp->linkedObjectsIds['commande'] as $key => $value) { $originforcontact = 'commande'; - $originidforcontact = $value->id; + $originidforcontact = $value; break; // We take first one } } diff --git a/htdocs/install/mysql/data/llx_c_type_contact.sql b/htdocs/install/mysql/data/llx_c_type_contact.sql index a0b36634ce1..ce51eb20ca5 100644 --- a/htdocs/install/mysql/data/llx_c_type_contact.sql +++ b/htdocs/install/mysql/data/llx_c_type_contact.sql @@ -43,6 +43,7 @@ insert into llx_c_type_contact(rowid, element, source, code, libelle, active ) v insert into llx_c_type_contact(rowid, element, source, code, libelle, active ) values (60, 'facture', 'external', 'BILLING', 'Contact client facturation', 1); insert into llx_c_type_contact(rowid, element, source, code, libelle, active ) values (61, 'facture', 'external', 'SHIPPING', 'Contact client livraison', 1); insert into llx_c_type_contact(rowid, element, source, code, libelle, active ) values (62, 'facture', 'external', 'SERVICE', 'Contact client prestation', 1); +insert into llx_c_type_contact(rowid, element, source, code, libelle, active ) values (63, 'facture', 'external', 'CUSTOMER', 'Contact client suivi facturation', 1) insert into llx_c_type_contact(rowid, element, source, code, libelle, active ) values (70, 'invoice_supplier', 'internal', 'SALESREPFOLL', 'Responsable suivi du paiement', 1); insert into llx_c_type_contact(rowid, element, source, code, libelle, active ) values (71, 'invoice_supplier', 'external', 'BILLING', 'Contact fournisseur facturation', 1); From 6a05645295f77f558d00e5191eb1dd216277dda3 Mon Sep 17 00:00:00 2001 From: Alexandre SPANGARO Date: Sat, 30 Sep 2017 06:58:31 +0200 Subject: [PATCH 09/46] Fix : Accountancy export model for Agiris Isacompta --- .../class/accountancyexport.class.php | 21 +++++++------------ 1 file changed, 7 insertions(+), 14 deletions(-) diff --git a/htdocs/accountancy/class/accountancyexport.class.php b/htdocs/accountancy/class/accountancyexport.class.php index e9ad42858aa..ac92dcab195 100644 --- a/htdocs/accountancy/class/accountancyexport.class.php +++ b/htdocs/accountancy/class/accountancyexport.class.php @@ -419,7 +419,7 @@ class AccountancyExport /** - * Export format : Agiris + * Export format : Agiris Isacompta * * @param array $objectLines data * @@ -433,30 +433,23 @@ class AccountancyExport $date = dol_print_date($line->doc_date, '%d%m%Y'); - print $line->id . $this->separator; - print '"'.dol_trunc($line->piece_num,15,'right','UTF-8',1).'"'.$this->separator; + print $line->piece_num . $this->separator; + print $line->label_operation . $this->separator; print $date . $this->separator; - print '"'.dol_trunc($line->piece_num,15,'right','UTF-8',1).'"'.$this->separator; + print $line->label_operation . $this->separator; if (empty($line->subledger_account)) { print length_accountg($line->numero_compte) . $this->separator; } else { - // FIXME Because the subledger_account is already an accounting account, does we really need - // to concat 4011 or 401 to it ? - if (substr($line->numero_compte, 0, 1) == 'C' || substr($line->numero_compte, 0, 1) == '9') { - print '411' . substr(str_replace(" ", "", $line->subledger_account), 0, 5) . $this->separator; - } - if (substr($line->numero_compte, 0, 1) == 'F' || substr($line->numero_compte, 0, 1) == '0') { - print '401' . substr(str_replace(" ", "", $line->subledger_account), 0, 5) . $this->separator; - } + print length_accounta($line->subledger_account) . $this->separator; } - print length_accounta($line->subledger_account) . $this->separator; + print $line->doc_ref . $this->separator; print price($line->debit) . $this->separator; print price($line->credit) . $this->separator; print price($line->montant).$this->separator; print $line->sens.$this->separator; - print $line->code_journal . $this->separator; + print $line->code_journal; print $this->end_line; } } From 884fc5d249ac28a8c3216635ee32071aab5231ce Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Mon, 2 Oct 2017 01:25:00 +0200 Subject: [PATCH 10/46] Update facture.class.php --- htdocs/compta/facture/class/facture.class.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/htdocs/compta/facture/class/facture.class.php b/htdocs/compta/facture/class/facture.class.php index 3c4bfec6a45..60970b5b1e2 100644 --- a/htdocs/compta/facture/class/facture.class.php +++ b/htdocs/compta/facture/class/facture.class.php @@ -486,7 +486,8 @@ class Facture extends CommonInvoice foreach ($exp->linkedObjectsIds['commande'] as $key => $value) { $originforcontact = 'commande'; - $originidforcontact = $value; + if (is_object($value)) $originidforcontact = $value->id; + else $originidforcontact = $value; break; // We take first one } } From ec8db116f80f3b9ee0967f028a3d032b7df1a3f7 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Mon, 2 Oct 2017 01:25:28 +0200 Subject: [PATCH 11/46] Update llx_c_type_contact.sql --- htdocs/install/mysql/data/llx_c_type_contact.sql | 1 - 1 file changed, 1 deletion(-) diff --git a/htdocs/install/mysql/data/llx_c_type_contact.sql b/htdocs/install/mysql/data/llx_c_type_contact.sql index ce51eb20ca5..a0b36634ce1 100644 --- a/htdocs/install/mysql/data/llx_c_type_contact.sql +++ b/htdocs/install/mysql/data/llx_c_type_contact.sql @@ -43,7 +43,6 @@ insert into llx_c_type_contact(rowid, element, source, code, libelle, active ) v insert into llx_c_type_contact(rowid, element, source, code, libelle, active ) values (60, 'facture', 'external', 'BILLING', 'Contact client facturation', 1); insert into llx_c_type_contact(rowid, element, source, code, libelle, active ) values (61, 'facture', 'external', 'SHIPPING', 'Contact client livraison', 1); insert into llx_c_type_contact(rowid, element, source, code, libelle, active ) values (62, 'facture', 'external', 'SERVICE', 'Contact client prestation', 1); -insert into llx_c_type_contact(rowid, element, source, code, libelle, active ) values (63, 'facture', 'external', 'CUSTOMER', 'Contact client suivi facturation', 1) insert into llx_c_type_contact(rowid, element, source, code, libelle, active ) values (70, 'invoice_supplier', 'internal', 'SALESREPFOLL', 'Responsable suivi du paiement', 1); insert into llx_c_type_contact(rowid, element, source, code, libelle, active ) values (71, 'invoice_supplier', 'external', 'BILLING', 'Contact fournisseur facturation', 1); From 90964d25cea26b4b0e4148dd209538ed7b52a00e Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Mon, 2 Oct 2017 17:52:20 +0200 Subject: [PATCH 12/46] Fix css --- htdocs/theme/eldy/style.css.php | 2 +- htdocs/theme/md/style.css.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/htdocs/theme/eldy/style.css.php b/htdocs/theme/eldy/style.css.php index 28e4e9e0ca9..96c7c91de2b 100644 --- a/htdocs/theme/eldy/style.css.php +++ b/htdocs/theme/eldy/style.css.php @@ -269,7 +269,7 @@ input.select2-input { .liste_titre input[name=monthvalid], .liste_titre input[name=search_ordermonth], .liste_titre input[name=search_deliverymonth], .liste_titre input[name=search_smonth], .liste_titre input[name=search_month], .liste_titre input[name=search_emonth], .liste_titre input[name=smonth], .liste_titre input[name=month], .liste_titre select[name=month], -.liste_titre input[name=month_lim] { +.liste_titre input[name=month_lim], .liste_titre input[name=month_create] { margin-right: 4px; } input[type=submit] { diff --git a/htdocs/theme/md/style.css.php b/htdocs/theme/md/style.css.php index 66fd3c20925..f4966a105b7 100644 --- a/htdocs/theme/md/style.css.php +++ b/htdocs/theme/md/style.css.php @@ -284,7 +284,7 @@ textarea.cke_source:focus .liste_titre input[name=monthvalid], .liste_titre input[name=search_ordermonth], .liste_titre input[name=search_deliverymonth], .liste_titre input[name=search_smonth], .liste_titre input[name=search_month], .liste_titre input[name=search_emonth], .liste_titre input[name=smonth], .liste_titre input[name=month], -.liste_titre input[name=month_lim] { +.liste_titre input[name=month_lim], .liste_titre input[name=month_create] { margin-right: 4px; } input, input.flat, textarea, textarea.flat, form.flat select, select, select.flat, .dataTables_length label select { From 0acb391b361fcbc0889db9806e804af6b6a8a0ea Mon Sep 17 00:00:00 2001 From: Alexandre SPANGARO Date: Tue, 3 Oct 2017 05:27:08 +0200 Subject: [PATCH 13/46] Fix : label_operation on general ledger --- htdocs/accountancy/bookkeeping/list.php | 130 ++++++++++----------- htdocs/accountancy/journal/bankjournal.php | 37 +++--- 2 files changed, 86 insertions(+), 81 deletions(-) diff --git a/htdocs/accountancy/bookkeeping/list.php b/htdocs/accountancy/bookkeeping/list.php index c87b906f45e..30db29db927 100644 --- a/htdocs/accountancy/bookkeeping/list.php +++ b/htdocs/accountancy/bookkeeping/list.php @@ -98,8 +98,8 @@ $form = new Form($db); if ($action != 'export_file' && ! isset($_POST['begin']) && ! isset($_GET['begin']) && ! isset($_POST['formfilteraction']) && empty($page)) { - $search_date_start = dol_mktime(0, 0, 0, 1, 1, dol_print_date(dol_now(), '%Y')); - $search_date_end = dol_mktime(0, 0, 0, 12, 31, dol_print_date(dol_now(), '%Y')); + $search_date_start = dol_mktime(0, 0, 0, 1, 1, dol_print_date(dol_now(), '%Y')); + $search_date_end = dol_mktime(0, 0, 0, 12, 31, dol_print_date(dol_now(), '%Y')); } @@ -134,67 +134,67 @@ if (GETPOST('button_removefilter_x','alpha') || GETPOST('button_removefilter.x', $param = ''; $filter = array (); if (! empty($search_date_start)) { - $filter['t.doc_date>='] = $search_date_start; - $tmp=dol_getdate($search_date_start); - $param .= '&date_startmonth=' . $tmp['mon'] . '&date_startday=' . $tmp['mday'] . '&date_startyear=' . $tmp['year']; + $filter['t.doc_date>='] = $search_date_start; + $tmp=dol_getdate($search_date_start); + $param .= '&date_startmonth=' . $tmp['mon'] . '&date_startday=' . $tmp['mday'] . '&date_startyear=' . $tmp['year']; } if (! empty($search_date_end)) { - $filter['t.doc_date<='] = $search_date_end; - $tmp=dol_getdate($search_date_end); - $param .= '&date_endmonth=' . $tmp['mon'] . '&date_endday=' . $tmp['mday'] . '&date_endyear=' . $tmp['year']; + $filter['t.doc_date<='] = $search_date_end; + $tmp=dol_getdate($search_date_end); + $param .= '&date_endmonth=' . $tmp['mon'] . '&date_endday=' . $tmp['mday'] . '&date_endyear=' . $tmp['year']; } if (! empty($search_doc_date)) { - $filter['t.doc_date'] = $search_doc_date; - $tmp=dol_getdate($search_doc_date); - $param .= '&doc_datemonth=' . $tmp['mon'] . '&doc_dateday=' . $tmp['mday'] . '&doc_dateyear=' . $tmp['year']; + $filter['t.doc_date'] = $search_doc_date; + $tmp=dol_getdate($search_doc_date); + $param .= '&doc_datemonth=' . $tmp['mon'] . '&doc_dateday=' . $tmp['mday'] . '&doc_dateyear=' . $tmp['year']; } if (! empty($search_doc_type)) { - $filter['t.doc_type'] = $search_doc_type; - $param .= '&search_doc_type=' . $search_doc_type; + $filter['t.doc_type'] = $search_doc_type; + $param .= '&search_doc_type=' . $search_doc_type; } if (! empty($search_doc_ref)) { - $filter['t.doc_ref'] = $search_doc_ref; - $param .= '&search_doc_ref=' . $search_doc_ref; + $filter['t.doc_ref'] = $search_doc_ref; + $param .= '&search_doc_ref=' . $search_doc_ref; } if (! empty($search_accountancy_code)) { - $filter['t.numero_compte'] = $search_accountancy_code; - $param .= '&search_accountancy_code=' . $search_accountancy_code; + $filter['t.numero_compte'] = $search_accountancy_code; + $param .= '&search_accountancy_code=' . $search_accountancy_code; } if (! empty($search_accountancy_code_start)) { - $filter['t.numero_compte>='] = $search_accountancy_code_start; - $param .= '&search_accountancy_code_start=' . $search_accountancy_code_start; + $filter['t.numero_compte>='] = $search_accountancy_code_start; + $param .= '&search_accountancy_code_start=' . $search_accountancy_code_start; } if (! empty($search_accountancy_code_end)) { - $filter['t.numero_compte<='] = $search_accountancy_code_end; - $param .= '&search_accountancy_code_end=' . $search_accountancy_code_end; + $filter['t.numero_compte<='] = $search_accountancy_code_end; + $param .= '&search_accountancy_code_end=' . $search_accountancy_code_end; } if (! empty($search_accountancy_aux_code)) { - $filter['t.subledger_account'] = $search_accountancy_aux_code; - $param .= '&search_accountancy_aux_code=' . $search_accountancy_aux_code; + $filter['t.subledger_account'] = $search_accountancy_aux_code; + $param .= '&search_accountancy_aux_code=' . $search_accountancy_aux_code; } if (! empty($search_accountancy_aux_code_start)) { - $filter['t.subledger_account>='] = $search_accountancy_aux_code_start; - $param .= '&search_accountancy_aux_code_start=' . $search_accountancy_aux_code_start; + $filter['t.subledger_account>='] = $search_accountancy_aux_code_start; + $param .= '&search_accountancy_aux_code_start=' . $search_accountancy_aux_code_start; } if (! empty($search_accountancy_aux_code_end)) { - $filter['t.subledger_account<='] = $search_accountancy_aux_code_end; - $param .= '&search_accountancy_aux_code_end=' . $search_accountancy_aux_code_end; + $filter['t.subledger_account<='] = $search_accountancy_aux_code_end; + $param .= '&search_accountancy_aux_code_end=' . $search_accountancy_aux_code_end; } if (! empty($search_mvt_label)) { - $filter['t.label_operation'] = $search_mvt_label; - $param .= '&search_mvt_label=' . $search_mvt_label; + $filter['t.label_operation'] = $search_mvt_label; + $param .= '&search_mvt_label=' . $search_mvt_label; } if (! empty($search_direction)) { - $filter['t.sens'] = $search_direction; - $param .= '&search_direction=' . $search_direction; + $filter['t.sens'] = $search_direction; + $param .= '&search_direction=' . $search_direction; } if (! empty($search_ledger_code)) { - $filter['t.code_journal'] = $search_ledger_code; - $param .= '&search_ledger_code=' . $search_ledger_code; + $filter['t.code_journal'] = $search_ledger_code; + $param .= '&search_ledger_code=' . $search_ledger_code; } if (! empty($search_mvt_num)) { - $filter['t.piece_num'] = $search_mvt_num; - $param .= '&search_mvt_num=' . $search_mvt_num; + $filter['t.piece_num'] = $search_mvt_num; + $param .= '&search_mvt_num=' . $search_mvt_num; } if ($action == 'delbookkeeping') { @@ -229,16 +229,16 @@ if ($action == 'delbookkeepingyearconfirm') { } else { - setEventMessages("RecordDeleted", null, 'mesgs'); + setEventMessages("RecordDeleted", null, 'mesgs'); } Header("Location: list.php"); exit; } else { - setEventMessages("NoRecordDeleted", null, 'warnings'); - Header("Location: list.php"); - exit; + setEventMessages("NoRecordDeleted", null, 'warnings'); + Header("Location: list.php"); + exit; } } if ($action == 'delmouvconfirm') { @@ -248,11 +248,11 @@ if ($action == 'delmouvconfirm') { if (! empty($mvt_num)) { $result = $object->deleteMvtNum($mvt_num); if ($result < 0) { - setEventMessages($object->error, $object->errors, 'errors'); + setEventMessages($object->error, $object->errors, 'errors'); } else { - setEventMessages($langs->trans("RecordDeleted"), null, 'mesgs'); + setEventMessages($langs->trans("RecordDeleted"), null, 'mesgs'); } Header("Location: list.php"); exit; @@ -262,21 +262,21 @@ if ($action == 'delmouvconfirm') { // Export into a file with format defined into setup if ($action == 'export_file') { - $result = $object->fetchAll($sortorder, $sortfield, 0, 0, $filter); + $result = $object->fetchAll($sortorder, $sortfield, 0, 0, $filter); - if ($result < 0) - { - setEventMessages($object->error, $object->errors, 'errors'); - } - else - { - $accountancyexport = new AccountancyExport($db); - $accountancyexport->export($object->lines); - if (!empty($accountancyexport->errors)) { - setEventMessages('', $accountancyexport->errors, 'errors'); - } - exit; - } + if ($result < 0) + { + setEventMessages($object->error, $object->errors, 'errors'); + } + else + { + $accountancyexport = new AccountancyExport($db); + $accountancyexport->export($object->lines); + if (!empty($accountancyexport->errors)) { + setEventMessages('', $accountancyexport->errors, 'errors'); + } + exit; + } } @@ -330,7 +330,7 @@ if ($action == 'delbookkeepingyear') { ); $form_question['deljournal'] = array ( 'name' => 'deljournal', - 'type' => 'other', // We don't use select here, the journal_array is already a select html component + 'type' => 'other', // We don't use select here, the journal_array is already a select html component 'label' => $langs->trans('DelJournal'), 'value' => $journal_array, 'default' => $deljournal @@ -340,7 +340,7 @@ if ($action == 'delbookkeepingyear') { print $formconfirm; } -//$param=''; param started before +//$param=''; param started before if (! empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) $param.='&contextpage='.$contextpage; if ($limit > 0 && $limit != $conf->liste_limit) $param.='&limit='.$limit; @@ -399,28 +399,28 @@ print ''; print ''; print '
'; print $langs->trans('From').' '; -// TODO For the moment we keep a fre input text instead of a combo. The select_auxaccount has problem because it does not +// TODO For the moment we keep a free input text instead of a combo. The select_auxaccount has problem because it does not // use setup of keypress to select thirdparty and this hang browser on large database. if (! empty($conf->global->ACCOUNTANCY_COMBO_FOR_AUX)) { - print $formaccounting->select_auxaccount($search_accountancy_aux_code_start, 'search_accountancy_aux_code_start', 1); + print $formaccounting->select_auxaccount($search_accountancy_aux_code_start, 'search_accountancy_aux_code_start', 1); } else { - print ''; + print ''; } print '
'; print '
'; print $langs->trans('to').' '; -// TODO For the moment we keep a fre input text instead of a combo. The select_auxaccount has problem because it does not +// TODO For the moment we keep a free input text instead of a combo. The select_auxaccount has problem because it does not // use setup of keypress to select thirdparty and this hang browser on large database. if (! empty($conf->global->ACCOUNTANCY_COMBO_FOR_AUX)) { - print $formaccounting->select_auxaccount($search_accountancy_aux_code_end, 'search_accountancy_aux_code_end', 1); + print $formaccounting->select_auxaccount($search_accountancy_aux_code_end, 'search_accountancy_aux_code_end', 1); } else { - print ''; + print ''; } print '
'; print ''; @@ -489,8 +489,8 @@ while ($i < min($num, $limit)) } print ''; -if ($num < $limit) print ''.$langs->trans("Total").''; -else print ''.$langs->trans("Totalforthispage").''; +if ($num < $limit) print ''.$langs->trans("Total").''; +else print ''.$langs->trans("Totalforthispage").''; print ''; print ''; print price($total_debit); diff --git a/htdocs/accountancy/journal/bankjournal.php b/htdocs/accountancy/journal/bankjournal.php index bfa0c342245..0470fe83cb1 100644 --- a/htdocs/accountancy/journal/bankjournal.php +++ b/htdocs/accountancy/journal/bankjournal.php @@ -422,7 +422,6 @@ if (! $error && $action == 'writebookkeeping') { $bookkeeping->fk_doc = $key; $bookkeeping->fk_docdet = $val["fk_bank"]; $bookkeeping->numero_compte = $k; - $bookkeeping->label_operation = $val["label"]; $bookkeeping->label_compte = $langs->trans("Bank"); $bookkeeping->montant = $mt; $bookkeeping->sens = ($mt >= 0) ? 'D' : 'C'; @@ -433,21 +432,28 @@ if (! $error && $action == 'writebookkeeping') { $bookkeeping->fk_user_author = $user->id; $bookkeeping->date_create = $now; - // No subledger_account value for the bank line + // No subledger_account value for the bank line but add a specific label_operation if ($tabtype[$key] == 'payment') { $bookkeeping->subledger_account = ''; + $bookkeeping->label_operation = $tabcompany[$key]['name'] . ' - ' . $ref; } else if ($tabtype[$key] == 'payment_supplier') { $bookkeeping->subledger_account = ''; + $bookkeeping->label_operation = $tabcompany[$key]['name'] . ' - ' . $ref; } else if ($tabtype[$key] == 'payment_expensereport') { $bookkeeping->subledger_account = ''; + $bookkeeping->label_operation = $tabuser[$key]['name'] . ' - ' . $ref; } else if ($tabtype[$key] == 'payment_salary') { $bookkeeping->subledger_account = ''; + $bookkeeping->label_operation = $tabuser[$key]['name'] . ' - ' . $ref; } else if ($tabtype[$key] == 'payment_vat') { $bookkeeping->subledger_account = ''; + $bookkeeping->label_operation = $ref; } else if ($tabtype[$key] == 'payment_donation') { $bookkeeping->subledger_account = ''; + $bookkeeping->label_operation = $ref; } else if ($tabtype[$key] == 'payment_various') { $bookkeeping->subledger_account = ''; + $bookkeeping->label_operation = $ref; } else if ($tabtype[$key] == 'unknown') { // ??? $bookkeeping->subledger_account = ''; @@ -484,7 +490,6 @@ if (! $error && $action == 'writebookkeeping') { $bookkeeping->doc_type = 'bank'; $bookkeeping->fk_doc = $key; $bookkeeping->fk_docdet = $val["fk_bank"]; - $bookkeeping->label_operation = $tabcompany[$key]['name']; $bookkeeping->montant = $mt; $bookkeeping->sens = ($mt < 0) ? 'D' : 'C'; $bookkeeping->debit = ($mt < 0 ? - $mt : 0); @@ -495,55 +500,55 @@ if (! $error && $action == 'writebookkeeping') { $bookkeeping->date_create = $now; if ($tabtype[$key] == 'payment') { // If payment is payment of customer invoice, we get ref of invoice - $bookkeeping->label_operation = ''; + $bookkeeping->label_operation = $tabcompany[$key]['name'] . ' - ' . $ref; $bookkeeping->subledger_account = $tabcompany[$key]['code_compta']; $bookkeeping->subledger_label = $tabcompany[$key]['name']; $bookkeeping->numero_compte = $conf->global->ACCOUNTING_ACCOUNT_CUSTOMER; $bookkeeping->label_compte = ''; } else if ($tabtype[$key] == 'payment_supplier') { // If payment is payment of supplier invoice, we get ref of invoice - $bookkeeping->label_operation = ''; + $bookkeeping->label_operation = $tabcompany[$key]['name'] . ' - ' . $ref; $bookkeeping->subledger_account = $tabcompany[$key]['code_compta']; $bookkeeping->subledger_label = $tabcompany[$key]['name']; $bookkeeping->numero_compte = $conf->global->ACCOUNTING_ACCOUNT_SUPPLIER; $bookkeeping->label_compte = ''; } else if ($tabtype[$key] == 'payment_expensereport') { - $bookkeeping->label_operation = $tabuser[$key]['name']; + $bookkeeping->label_operation = $tabuser[$key]['name'] . ' - ' . $ref; $bookkeeping->subledger_account = $tabuser[$key]['accountancy_code']; $bookkeeping->subledger_label = $tabuser[$key]['name']; $bookkeeping->numero_compte = $conf->global->SALARIES_ACCOUNTING_ACCOUNT_PAYMENT; $bookkeeping->label_compte = ''; } else if ($tabtype[$key] == 'payment_salary') { - $bookkeeping->label_operation = $tabuser[$key]['name']; + $bookkeeping->label_operation = $tabuser[$key]['name'] . ' - ' . $ref; $bookkeeping->subledger_account = $tabuser[$key]['accountancy_code']; $bookkeeping->subledger_label = $tabuser[$key]['name']; $bookkeeping->numero_compte = $conf->global->SALARIES_ACCOUNTING_ACCOUNT_PAYMENT; $bookkeeping->label_compte = ''; } else if (in_array($tabtype[$key], array('sc', 'payment_sc'))) { // If payment is payment of social contribution - $bookkeeping->label_operation = ''; + $bookkeeping->label_operation = $ref; $bookkeeping->subledger_account = ''; $bookkeeping->subledger_label = ''; $bookkeeping->numero_compte = $k; $bookkeeping->label_compte = $objmid->labelc; } else if ($tabtype[$key] == 'payment_vat') { - $bookkeeping->label_operation = ''; + $bookkeeping->label_operation = $ref; $bookkeeping->subledger_account = ''; $bookkeeping->subledger_label = ''; $bookkeeping->numero_compte = $k; $bookkeeping->label_compte = ''; } else if ($tabtype[$key] == 'payment_donation') { - $bookkeeping->label_operation = ''; + $bookkeeping->label_operation = $ref; $bookkeeping->subledger_account = ''; $bookkeeping->subledger_label = ''; $bookkeeping->numero_compte = $k; $bookkeeping->label_compte = ''; } else if ($tabtype[$key] == 'payment_various') { - $bookkeeping->label_operation = ''; + $bookkeeping->label_operation = $ref; $bookkeeping->subledger_account = ''; $bookkeeping->subledger_label = ''; $bookkeeping->numero_compte = $k; $bookkeeping->label_compte = ''; } else if ($tabtype[$key] == 'banktransfert') { - $bookkeeping->label_operation = ''; + $bookkeeping->label_operation = $ref; $bookkeeping->subledger_account = ''; $bookkeeping->subledger_label = ''; $bookkeeping->numero_compte = $k; @@ -676,9 +681,9 @@ if ($action == 'exportcsv') { // ISO and not UTF8 ! print '"' . length_accountg(html_entity_decode($k)) . '"' . $sep; print " " . $sep; if ($companystatic->name == '') { - print '"' . $langs->trans('Bank') . " - " . utf8_decode($reflabel) . '"' . $sep; + print '"' . $val['bank_account_ref'] . " - " . utf8_decode($reflabel) . '"' . $sep; } else { - print '"' . $langs->trans("Bank") . ' - ' . utf8_decode($companystatic->name) . '"' . $sep; + print '"' . $val['bank_account_ref'] . ' - ' . utf8_decode($companystatic->name) . '"' . $sep; } print '"' . ($mt >= 0 ? price($mt) : '') . '"' . $sep; print '"' . ($mt < 0 ? price(- $mt) : '') . '"'; @@ -720,9 +725,9 @@ if ($action == 'exportcsv') { // ISO and not UTF8 ! print '"' . length_accountg($conf->global->ACCOUNTING_ACCOUNT_SUSPENSE) . '"' . $sep; print " " . $sep; if ($companystatic->name == '') { - print '"' . $langs->trans("Bank") . ' - ' . utf8_decode($reflabel) . '"' . $sep; + print '"' . $val['bank_account_ref'] . ' - ' . utf8_decode($reflabel) . '"' . $sep; } else { - print '"' . $langs->trans("Bank") . ' - ' . utf8_decode($companystatic->name) . '"' . $sep; + print '"' . $val['bank_account_ref'] . ' - ' . utf8_decode($companystatic->name) . '"' . $sep; } print '"' . ($mt < 0 ? price(- $mt) : '') . '"' . $sep; print '"' . ($mt >= 0 ? price($mt) : '') . '"'; From 888e5ed2c5b9f50732679b542f801c1b91748269 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Tue, 3 Oct 2017 09:35:45 +0200 Subject: [PATCH 14/46] Fix sanitize uploaded filename --- htdocs/core/actions_linkedfiles.inc.php | 12 ++++++------ htdocs/core/lib/files.lib.php | 8 +++----- 2 files changed, 9 insertions(+), 11 deletions(-) diff --git a/htdocs/core/actions_linkedfiles.inc.php b/htdocs/core/actions_linkedfiles.inc.php index 981de037c13..1f47a94f6d2 100644 --- a/htdocs/core/actions_linkedfiles.inc.php +++ b/htdocs/core/actions_linkedfiles.inc.php @@ -30,9 +30,9 @@ if (GETPOST('sendit') && ! empty($conf->global->MAIN_UPLOAD_DOC)) if ($object->id) { if (! empty($upload_dirold) && ! empty($conf->global->PRODUCT_USE_OLD_PATH_FOR_PHOTO)) - $result = dol_add_file_process($upload_dirold, 0, 1, 'userfile', GETPOST('savingdocmask')); + $result = dol_add_file_process($upload_dirold, 0, 1, 'userfile', GETPOST('savingdocmask', 'alpha')); else - $result = dol_add_file_process($upload_dir, 0, 1, 'userfile', GETPOST('savingdocmask')); + $result = dol_add_file_process($upload_dir, 0, 1, 'userfile', GETPOST('savingdocmask', 'alpha')); } } elseif (GETPOST('linkit') && ! empty($conf->global->MAIN_UPLOAD_DOC)) @@ -57,7 +57,7 @@ if ($action == 'confirm_deletefile' && $confirm == 'yes') if ($object->id) { $urlfile = GETPOST('urlfile', 'alpha'); // Do not use urldecode here ($_GET and $_REQUEST are already decoded by PHP). - if (GETPOST('section')) $file = $upload_dir . "/" . $urlfile; // For a delete of GED module urlfile contains full path from upload_dir + if (GETPOST('section', 'alpha')) $file = $upload_dir . "/" . $urlfile; // For a delete of GED module urlfile contains full path from upload_dir else // For documents pages, upload_dir contains already path to file from module dir, so we clean path into urlfile. { $urlfile=basename($urlfile); @@ -116,7 +116,7 @@ if ($action == 'confirm_deletefile' && $confirm == 'yes') exit; } } -elseif ($action == 'confirm_updateline' && GETPOST('save') && GETPOST('link', 'alpha')) +elseif ($action == 'confirm_updateline' && GETPOST('save','alpha') && GETPOST('link', 'alpha')) { require_once DOL_DOCUMENT_ROOT . '/core/class/link.class.php'; $langs->load('link'); @@ -150,8 +150,8 @@ elseif ($action == 'renamefile' && GETPOST('renamefilesave')) //var_dump($upload_dir);exit; if (! empty($upload_dir)) { - $filenamefrom=dol_sanitizeFileName(GETPOST('renamefilefrom')); - $filenameto=dol_sanitizeFileName(GETPOST('renamefileto')); + $filenamefrom=dol_sanitizeFileName(GETPOST('renamefilefrom','alpha')); + $filenameto=dol_sanitizeFileName(GETPOST('renamefileto','alpha')); // Security: // Disallow file with some extensions. We rename them. diff --git a/htdocs/core/lib/files.lib.php b/htdocs/core/lib/files.lib.php index b1031153507..38e8f09a3d8 100644 --- a/htdocs/core/lib/files.lib.php +++ b/htdocs/core/lib/files.lib.php @@ -1386,19 +1386,17 @@ function dol_add_file_process($upload_dir, $allowoverwrite=0, $donotupdatesessio $destfull=$upload_dir . "/" . $TFile['name'][$i]; $destfile=$TFile['name'][$i]; - $savingdocmask = dol_sanitizeFileName($savingdocmask); - if ($savingdocmask) { $destfull=$upload_dir . "/" . preg_replace('/__file__/',$TFile['name'][$i],$savingdocmask); $destfile=preg_replace('/__file__/',$TFile['name'][$i],$savingdocmask); } - // lowercase extension + // dol_sanitizeFileName the file name and lowercase extension $info = pathinfo($destfull); - $destfull = $info['dirname'].'/'.$info['filename'].'.'.strtolower($info['extension']); + $destfull = $info['dirname'].'/'.dol_sanitizeFileName($info['filename'].'.'.strtolower($info['extension'])); $info = pathinfo($destfile); - $destfile = $info['filename'].'.'.strtolower($info['extension']); + $destfile = dol_sanitizeFileName($info['filename'].'.'.strtolower($info['extension'])); $resupload = dol_move_uploaded_file($TFile['tmp_name'][$i], $destfull, $allowoverwrite, 0, $TFile['error'][$i], 0, $varfiles); From c4b3dc40c316f5fb85c56ac3fffeae7306186177 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Mon, 2 Oct 2017 20:38:15 +0200 Subject: [PATCH 15/46] Allow : into file names --- htdocs/core/lib/functions.lib.php | 2 +- htdocs/holiday/document.php | 24 ++++++++++++------------ 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/htdocs/core/lib/functions.lib.php b/htdocs/core/lib/functions.lib.php index e87f46ad2bf..288badf6285 100644 --- a/htdocs/core/lib/functions.lib.php +++ b/htdocs/core/lib/functions.lib.php @@ -680,7 +680,7 @@ function dol_size($size,$type='') */ function dol_sanitizeFileName($str,$newstr='_',$unaccent=1) { - $filesystem_forbidden_chars = array('<','>',':','/','\\','?','*','|','"','°'); + $filesystem_forbidden_chars = array('<','>','/','\\','?','*','|','"','°'); return dol_string_nospecial($unaccent?dol_string_unaccent($str):$str, $newstr, $filesystem_forbidden_chars); } diff --git a/htdocs/holiday/document.php b/htdocs/holiday/document.php index 38f68e58937..c468fcd7272 100644 --- a/htdocs/holiday/document.php +++ b/htdocs/holiday/document.php @@ -97,7 +97,7 @@ if ($object->id) $head=holiday_prepare_head($object); - dol_fiche_head($head, 'documents',$langs->trans("CPTitreMenu"),0,'holiday'); + dol_fiche_head($head, 'documents', $langs->trans("CPTitreMenu"), -1,'holiday'); // Construit liste des fichiers @@ -110,16 +110,16 @@ if ($object->id) $linkback=''.$langs->trans("BackToList").''; - + dol_banner_tab($object, 'id', $linkback, 1, 'rowid', 'ref'); - - + + print '
'; //print '
'; print '
'; - + print ''; - + print ''; print ''; print ''; print ''; - + print ''; print '
'.$langs->trans("User").''; @@ -212,16 +212,16 @@ if ($object->id) print '
'.$langs->trans("NbOfAttachedFiles").''.count($filearray).'
'.$langs->trans("TotalSizeOfAttachedFiles").''.$totalsize.' '.$langs->trans("bytes").'
'."\n"; /* print '
'; print '
'; print '
'; - + print '
'; - + // Info workflow print ''."\n"; print ''; @@ -278,11 +278,11 @@ if ($object->id) print ''; print ''; */ print ''; - + print '
'; - + dol_fiche_end(); - + $modulepart = 'holiday'; From 0b808fa2aaa85c28eda9628140eab81a945ae2a1 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Tue, 3 Oct 2017 10:11:03 +0200 Subject: [PATCH 16/46] FIX Bad preview on scroping when special file names --- htdocs/core/photos_resize.php | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/htdocs/core/photos_resize.php b/htdocs/core/photos_resize.php index 5b29d25202e..df734e70235 100644 --- a/htdocs/core/photos_resize.php +++ b/htdocs/core/photos_resize.php @@ -170,7 +170,7 @@ if ($action == 'confirm_resize' && (isset($_POST["file"]) != "") && (isset($_POS { $fullpath=$dir."/".$original_file; $result=dol_imageResizeOrCrop($fullpath,0,$_POST['sizex'],$_POST['sizey']); - + if ($result == $fullpath) { $object->addThumbs($fullpath); @@ -178,7 +178,7 @@ if ($action == 'confirm_resize' && (isset($_POST["file"]) != "") && (isset($_POS // Update/create database for file $fullpath $rel_filename = preg_replace('/^'.preg_quote(DOL_DATA_ROOT,'/').'/', '', $fullpath); $rel_filename = preg_replace('/^[\\/]/','',$rel_filename); - + include_once DOL_DOCUMENT_ROOT.'/ecm/class/ecmfiles.class.php'; $ecmfile=new EcmFiles($db); $result = $ecmfile->fetch(0, '', $rel_filename); @@ -188,7 +188,7 @@ if ($action == 'confirm_resize' && (isset($_POST["file"]) != "") && (isset($_POS $rel_dir = dirname($rel_filename); $rel_dir = preg_replace('/[\\/]$/', '', $rel_dir); $rel_dir = preg_replace('/^[\\/]/', '', $rel_dir); - + $ecmfile->label = md5_file(dol_osencode($fullpath)); $result = $ecmfile->update($user); } @@ -198,7 +198,7 @@ if ($action == 'confirm_resize' && (isset($_POST["file"]) != "") && (isset($_POS $rel_dir = dirname($rel_filename); $rel_dir = preg_replace('/[\\/]$/', '', $rel_dir); $rel_dir = preg_replace('/^[\\/]/', '', $rel_dir); - + $ecmfile->filepath = $rel_dir; $ecmfile->filename = $filename; $ecmfile->label = md5_file(dol_osencode($fullpath)); // $fullpath is a full path to file @@ -213,7 +213,7 @@ if ($action == 'confirm_resize' && (isset($_POST["file"]) != "") && (isset($_POS } $result = $ecmfile->create($user); } - + if ($backtourl) { header("Location: ".$backtourl); @@ -246,7 +246,7 @@ if ($action == 'confirm_crop') // Update/create database for file $fullpath $rel_filename = preg_replace('/^'.preg_quote(DOL_DATA_ROOT,'/').'/', '', $fullpath); $rel_filename = preg_replace('/^[\\/]/','',$rel_filename); - + include_once DOL_DOCUMENT_ROOT.'/ecm/class/ecmfiles.class.php'; $ecmfile=new EcmFiles($db); $result = $ecmfile->fetch(0, '', $rel_filename); @@ -256,7 +256,7 @@ if ($action == 'confirm_crop') $rel_dir = dirname($rel_filename); $rel_dir = preg_replace('/[\\/]$/', '', $rel_dir); $rel_dir = preg_replace('/^[\\/]/', '', $rel_dir); - + $ecmfile->label = md5_file(dol_osencode($fullpath)); $result = $ecmfile->update($user); } @@ -266,7 +266,7 @@ if ($action == 'confirm_crop') $rel_dir = dirname($rel_filename); $rel_dir = preg_replace('/[\\/]$/', '', $rel_dir); $rel_dir = preg_replace('/^[\\/]/', '', $rel_dir); - + $ecmfile->filepath = $rel_dir; $ecmfile->filename = $filename; $ecmfile->label = md5_file(dol_osencode($fullpath)); // $fullpath is a full path to file @@ -281,7 +281,7 @@ if ($action == 'confirm_crop') } $result = $ecmfile->create($user); } - + if ($backtourl) { header("Location: ".$backtourl); @@ -311,7 +311,7 @@ llxHeader($head, $langs->trans("Image"), '', '', 0, 0, array('/includes/jquery/p print load_fiche_titre($langs->trans("ImageEditor")); -$infoarray=dol_getImageSize($dir."/".GETPOST("file")); +$infoarray=dol_getImageSize($dir."/".GETPOST("file",'alpha')); $height=$infoarray['height']; $width=$infoarray['width']; print $langs->trans("CurrentInformationOnImage").': '; @@ -373,7 +373,7 @@ if (! empty($conf->use_javascript_ajax)) print $langs->trans("DefineNewAreaToPick").'...
'; print '
'; print '
'; - print ''; + print ''; print '
'; print '

'; print '
From db8d27f0fe89821cc99d20fbfc88710def29471c Mon Sep 17 00:00:00 2001 From: Regis Houssin Date: Tue, 3 Oct 2017 12:08:25 +0200 Subject: [PATCH 17/46] Fix: wrong type value --- htdocs/categories/viewcat.php | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/htdocs/categories/viewcat.php b/htdocs/categories/viewcat.php index 75a9215e18d..a3ca8053281 100644 --- a/htdocs/categories/viewcat.php +++ b/htdocs/categories/viewcat.php @@ -319,7 +319,7 @@ else // List of products or services (type is type of category) -if ($object->type == Categorie::TYPE_PRODUCT) +if ($type == Categorie::TYPE_PRODUCT) { $prods = $object->getObjectsInCateg("product"); if ($prods < 0) @@ -391,7 +391,7 @@ if ($object->type == Categorie::TYPE_PRODUCT) } } -if ($object->type == Categorie::TYPE_SUPPLIER) +if ($type == Categorie::TYPE_SUPPLIER) { $socs = $object->getObjectsInCateg("supplier"); if ($socs < 0) @@ -440,7 +440,7 @@ if ($object->type == Categorie::TYPE_SUPPLIER) } } -if($object->type == Categorie::TYPE_CUSTOMER) +if($type == Categorie::TYPE_CUSTOMER) { $socs = $object->getObjectsInCateg("customer"); if ($socs < 0) @@ -494,7 +494,7 @@ if($object->type == Categorie::TYPE_CUSTOMER) } // List of members -if ($object->type == Categorie::TYPE_MEMBER) +if ($type == Categorie::TYPE_MEMBER) { require_once DOL_DOCUMENT_ROOT.'/adherents/class/adherent.class.php'; @@ -547,7 +547,7 @@ if ($object->type == Categorie::TYPE_MEMBER) } // Categorie contact -if($object->type == Categorie::TYPE_CONTACT) +if ($type == Categorie::TYPE_CONTACT) { $contacts = $object->getObjectsInCateg("contact"); if ($contacts < 0) @@ -600,7 +600,7 @@ if($object->type == Categorie::TYPE_CONTACT) } // List of accounts -if ($object->type == Categorie::TYPE_ACCOUNT) +if ($type == Categorie::TYPE_ACCOUNT) { require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php'; @@ -653,7 +653,7 @@ if ($object->type == Categorie::TYPE_ACCOUNT) } // List of Project -if ($object->type == Categorie::TYPE_PROJECT) +if ($type == Categorie::TYPE_PROJECT) { require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php'; From f8f4ff6d2149a63b1c08601024fca7402d03506f Mon Sep 17 00:00:00 2001 From: Regis Houssin Date: Tue, 3 Oct 2017 13:07:07 +0200 Subject: [PATCH 18/46] Fix: missing include api_categories class --- htdocs/adherents/class/api_members.class.php | 25 +++++- .../categories/class/api_categories.class.php | 76 ++++++++--------- htdocs/product/class/api_products.class.php | 84 ++++++++++--------- htdocs/societe/class/api_contacts.class.php | 6 +- .../societe/class/api_thirdparties.class.php | 76 +++++++++-------- 5 files changed, 151 insertions(+), 116 deletions(-) diff --git a/htdocs/adherents/class/api_members.class.php b/htdocs/adherents/class/api_members.class.php index 4d13b6347ec..571c77d91f7 100644 --- a/htdocs/adherents/class/api_members.class.php +++ b/htdocs/adherents/class/api_members.class.php @@ -1,5 +1,6 @@ +/* Copyright (C) 2016 Xebax Christy + * Copyright (C) 2017 Regis Houssin * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -357,4 +358,26 @@ class Members extends DolibarrApi return $member->subscription($start_date, $amount, 0, '', $label, '', '', '', $end_date); } + /** + * Get categories for a member + * + * @param int $id ID of member + * @param string $sortfield Sort field + * @param string $sortorder Sort order + * @param int $limit Limit for list + * @param int $page Page number + * + * @return mixed + * + * @url GET {id}/categories + */ + function getCategories($id, $sortfield = "s.rowid", $sortorder = 'ASC', $limit = 0, $page = 0) + { + require_once DOL_DOCUMENT_ROOT.'/categories/class/api_categories.class.php'; + + $categories = new Categories(); + + return $categories->getListForItem($sortfield, $sortorder, $limit, $page, 'member', $id); + } + } diff --git a/htdocs/categories/class/api_categories.class.php b/htdocs/categories/class/api_categories.class.php index ed10e337f7b..a43ccbd180b 100644 --- a/htdocs/categories/class/api_categories.class.php +++ b/htdocs/categories/class/api_categories.class.php @@ -23,13 +23,13 @@ /** * API class for categories * - * @access protected + * @access protected * @class DolibarrApiAccess {@requires user,external} */ class Categories extends DolibarrApi { /** - * @var array $FIELDS Mandatory fields, checked when create and update object + * @var array $FIELDS Mandatory fields, checked when create and update object */ static $FIELDS = array( 'label', @@ -44,7 +44,7 @@ class Categories extends DolibarrApi 4 => 'contact', 5 => 'account', ); - + /** * @var Categorie $category {@type Categorie} */ @@ -67,20 +67,20 @@ class Categories extends DolibarrApi * * @param int $id ID of category * @return array|mixed data without useless information - * + * * @throws RestException */ function get($id) - { + { if(! DolibarrApiAccess::$user->rights->categorie->lire) { throw new RestException(401); } - + $result = $this->category->fetch($id); if( ! $result ) { throw new RestException(404, 'category not found'); } - + if( ! DolibarrApi::_checkAccessToResource('category',$this->category->id)) { throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login); } @@ -90,7 +90,7 @@ class Categories extends DolibarrApi /** * List categories - * + * * Get a list of categories * * @param string $sortfield Sort field @@ -105,13 +105,13 @@ class Categories extends DolibarrApi */ function index($sortfield = "t.rowid", $sortorder = 'ASC', $limit = 0, $page = 0, $type = '', $sqlfilters = '') { global $db, $conf; - + $obj_ret = array(); - + if(! DolibarrApiAccess::$user->rights->categorie->lire) { throw new RestException(401); } - + $sql = "SELECT t.rowid"; $sql.= " FROM ".MAIN_DB_PREFIX."categorie as t"; $sql.= ' WHERE t.entity IN ('.getEntity('category').')'; @@ -120,7 +120,7 @@ class Categories extends DolibarrApi $sql.= ' AND t.type='.array_search($type,Categories::$TYPES); } // Add sql filters - if ($sqlfilters) + if ($sqlfilters) { if (! DolibarrApi::_checkFilters($sqlfilters)) { @@ -129,7 +129,7 @@ class Categories extends DolibarrApi $regexstring='\(([^:\'\(\)]+:[^:\'\(\)]+:[^:\(\)]+)\)'; $sql.=" AND (".preg_replace_callback('/'.$regexstring.'/', 'DolibarrApi::_forge_criteria_callback', $sqlfilters).")"; } - + $sql.= $db->order($sortfield, $sortorder); if ($limit) { if ($page < 0) @@ -168,7 +168,7 @@ class Categories extends DolibarrApi /** * List categories of an entity - * + * * Note: This method is not directly exposed in the API, it is used * in the GET /xxx/{id}/categories requests. * @@ -184,9 +184,9 @@ class Categories extends DolibarrApi */ function getListForItem($sortfield = "s.rowid", $sortorder = 'ASC', $limit = 0, $page = 0, $type='customer', $item = 0) { global $db, $conf; - + $obj_ret = array(); - + if(! DolibarrApiAccess::$user->rights->categorie->lire) { throw new RestException(401); } @@ -250,13 +250,13 @@ class Categories extends DolibarrApi if( ! count($obj_ret)) { throw new RestException(404, 'No category found'); } - + return $obj_ret; } /** * Create category object - * + * * @param array $request_data Request data * @return int ID of category */ @@ -268,7 +268,7 @@ class Categories extends DolibarrApi // Check mandatory fields $result = $this->_validate($request_data); - + foreach($request_data as $field => $value) { $this->category->$field = $value; } @@ -280,22 +280,22 @@ class Categories extends DolibarrApi /** * Update category - * + * * @param int $id Id of category to update - * @param array $request_data Datas - * @return int + * @param array $request_data Datas + * @return int */ function put($id, $request_data = NULL) { if(! DolibarrApiAccess::$user->rights->categorie->creer) { throw new RestException(401); } - + $result = $this->category->fetch($id); if( ! $result ) { throw new RestException(404, 'category not found'); } - + if( ! DolibarrApi::_checkAccessToResource('category',$this->category->id)) { throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login); } @@ -304,13 +304,13 @@ class Categories extends DolibarrApi if ($field == 'id') continue; $this->category->$field = $value; } - + if($this->category->update(DolibarrApiAccess::$user)) return $this->get ($id); - + return false; } - + /** * Delete category * @@ -326,15 +326,15 @@ class Categories extends DolibarrApi if( ! $result ) { throw new RestException(404, 'category not found'); } - + if( ! DolibarrApi::_checkAccessToResource('category',$this->category->id)) { throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login); } - + if (! $this->category->delete(DolibarrApiAccess::$user)) { throw new RestException(401,'error when delete category'); } - + return array( 'success' => array( 'code' => 200, @@ -342,8 +342,8 @@ class Categories extends DolibarrApi ) ); } - - + + /** * Clean sensible object datas * @@ -351,9 +351,9 @@ class Categories extends DolibarrApi * @return array Array of cleaned object properties */ function _cleanObjectDatas($object) { - + $object = parent::_cleanObjectDatas($object); - + // Remove fields not relevent to categories unset($object->country); unset($object->country_id); @@ -394,16 +394,16 @@ class Categories extends DolibarrApi unset($object->fk_project); unset($object->note); unset($object->statut); - + return $object; } - + /** * Validate fields before create or update object - * + * * @param array|null $data Data to validate * @return array - * + * * @throws RestException */ function _validate($data) diff --git a/htdocs/product/class/api_products.class.php b/htdocs/product/class/api_products.class.php index 0d6694ac569..a16022ea047 100644 --- a/htdocs/product/class/api_products.class.php +++ b/htdocs/product/class/api_products.class.php @@ -16,24 +16,24 @@ */ use Luracast\Restler\RestException; - + require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php'; require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php'; /** * API class for products * - * @access protected + * @access protected * @class DolibarrApiAccess {@requires user,external} */ class Products extends DolibarrApi { /** - * @var array $FIELDS Mandatory fields, checked when create and update object + * @var array $FIELDS Mandatory fields, checked when create and update object */ static $FIELDS = array( 'ref', - 'label' + 'label' ); /** @@ -53,30 +53,30 @@ class Products extends DolibarrApi /** * Get properties of a product object - * + * * Return an array with product informations * * @param int $id ID of product * @return array|mixed data without useless information - * + * * @throws RestException * TODO implement getting a product by ref or by $ref_ext */ function get($id) - { + { if(! DolibarrApiAccess::$user->rights->produit->lire) { throw new RestException(401); } - + $result = $this->product->fetch($id); if( ! $result ) { throw new RestException(404, 'Product not found'); } - + if( ! DolibarrApi::_checkAccessToResource('product',$this->product->id)) { throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login); } - + $this->product->load_stock(); return $this->_cleanObjectDatas($this->product); @@ -84,9 +84,9 @@ class Products extends DolibarrApi /** * List products - * + * * Get a list of products - * + * * @param string $sortfield Sort field * @param string $sortorder Sort order * @param int $limit Limit for list @@ -98,9 +98,9 @@ class Products extends DolibarrApi */ function index($sortfield = "t.ref", $sortorder = 'ASC', $limit = 0, $page = 0, $mode=0, $category=0, $sqlfilters = '') { global $db, $conf; - + $obj_ret = array(); - + $socid = DolibarrApiAccess::$user->societe_id ? DolibarrApiAccess::$user->societe_id : ''; $sql = "SELECT t.rowid, t.ref, t.ref_ext"; @@ -121,7 +121,7 @@ class Products extends DolibarrApi // Show services if ($mode == 2) $sql.= " AND t.fk_product_type = 1"; // Add sql filters - if ($sqlfilters) + if ($sqlfilters) { if (! DolibarrApi::_checkFilters($sqlfilters)) { @@ -130,7 +130,7 @@ class Products extends DolibarrApi $regexstring='\(([^:\'\(\)]+:[^:\'\(\)]+:[^:\(\)]+)\)'; $sql.=" AND (".preg_replace_callback('/'.$regexstring.'/', 'DolibarrApi::_forge_criteria_callback', $sqlfilters).")"; } - + $sql.= $db->order($sortfield, $sortorder); if ($limit) { if ($page < 0) @@ -165,10 +165,10 @@ class Products extends DolibarrApi } return $obj_ret; } - + /** * Create product object - * + * * @param array $request_data Request data * @return int ID of product */ @@ -179,35 +179,35 @@ class Products extends DolibarrApi } // Check mandatory fields $result = $this->_validate($request_data); - + foreach($request_data as $field => $value) { $this->product->$field = $value; } if ($this->product->create(DolibarrApiAccess::$user) < 0) { throw new RestException(500, "Error creating product", array_merge(array($this->product->error), $this->product->errors)); } - + return $this->product->id; } /** * Update product - * + * * @param int $id Id of product to update - * @param array $request_data Datas - * @return int + * @param array $request_data Datas + * @return int */ function put($id, $request_data = NULL) { if(! DolibarrApiAccess::$user->rights->produit->creer) { throw new RestException(401); } - + $result = $this->product->fetch($id); if( ! $result ) { throw new RestException(404, 'Product not found'); } - + if( ! DolibarrApi::_checkAccessToResource('product',$this->product->id)) { throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login); } @@ -216,16 +216,16 @@ class Products extends DolibarrApi if ($field == 'id') continue; $this->product->$field = $value; } - + if($this->product->update($id, DolibarrApiAccess::$user,1,'update')) return $this->get ($id); - + return false; } - + /** * Delete product - * + * * @param int $id Product ID * @return array */ @@ -238,18 +238,18 @@ class Products extends DolibarrApi if( ! $result ) { throw new RestException(404, 'Product not found'); } - + if( ! DolibarrApi::_checkAccessToResource('product',$this->product->id)) { throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login); } - + // The Product::delete() method uses the global variable $user. global $user; $user = DolibarrApiAccess::$user; return $this->product->delete(DolibarrApiAccess::$user); } - + /** * Get categories for a product * @@ -263,9 +263,13 @@ class Products extends DolibarrApi * * @url GET {id}/categories */ - function getCategories($id, $sortfield = "s.rowid", $sortorder = 'ASC', $limit = 0, $page = 0) { - $categories = new Categories(); - return $categories->getListForItem($sortfield, $sortorder, $limit, $page, 'product', $id); + function getCategories($id, $sortfield = "s.rowid", $sortorder = 'ASC', $limit = 0, $page = 0) + { + require_once DOL_DOCUMENT_ROOT.'/categories/class/api_categories.class.php'; + + $categories = new Categories(); + + return $categories->getListForItem($sortfield, $sortorder, $limit, $page, 'product', $id); } /** @@ -275,17 +279,17 @@ class Products extends DolibarrApi * @return array Array of cleaned object properties */ function _cleanObjectDatas($object) { - + $object = parent::_cleanObjectDatas($object); - + unset($object->regeximgext); - + return $object; } - + /** * Validate fields before create or update object - * + * * @param array $data Datas to validate * @return array * @throws RestException diff --git a/htdocs/societe/class/api_contacts.class.php b/htdocs/societe/class/api_contacts.class.php index fcfdf4ad084..6d3a5970c9b 100644 --- a/htdocs/societe/class/api_contacts.class.php +++ b/htdocs/societe/class/api_contacts.class.php @@ -333,8 +333,12 @@ class Contacts extends DolibarrApi * * @url GET {id}/categories */ - function getCategories($id, $sortfield = "s.rowid", $sortorder = 'ASC', $limit = 0, $page = 0) { + function getCategories($id, $sortfield = "s.rowid", $sortorder = 'ASC', $limit = 0, $page = 0) + { + require_once DOL_DOCUMENT_ROOT.'/categories/class/api_categories.class.php'; + $categories = new Categories(); + return $categories->getListForItem($sortfield, $sortorder, $limit, $page, 'contact', $id); } diff --git a/htdocs/societe/class/api_thirdparties.class.php b/htdocs/societe/class/api_thirdparties.class.php index f25fda9a5fb..88492779bda 100644 --- a/htdocs/societe/class/api_thirdparties.class.php +++ b/htdocs/societe/class/api_thirdparties.class.php @@ -21,15 +21,15 @@ /** * API class for thirdparties * - * @access protected + * @access protected * @class DolibarrApiAccess {@requires user,external} - * + * */ class Thirdparties extends DolibarrApi { /** * - * @var array $FIELDS Mandatory fields, checked when create and update object + * @var array $FIELDS Mandatory fields, checked when create and update object */ static $FIELDS = array( 'name' @@ -48,7 +48,7 @@ class Thirdparties extends DolibarrApi global $db, $conf; $this->db = $db; $this->company = new Societe($this->db); - + if (! empty($conf->global->SOCIETE_EMAIL_MANDATORY)) { static::$FIELDS[] = 'email'; } @@ -61,20 +61,20 @@ class Thirdparties extends DolibarrApi * * @param int $id ID of thirdparty * @return array|mixed data without useless information - * + * * @throws RestException */ function get($id) - { + { if(! DolibarrApiAccess::$user->rights->societe->lire) { throw new RestException(401); } - + $result = $this->company->fetch($id); if( ! $result ) { throw new RestException(404, 'Thirdparty not found'); } - + if( ! DolibarrApi::_checkAccessToResource('societe',$this->company->id)) { throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login); } @@ -84,14 +84,14 @@ class Thirdparties extends DolibarrApi /** * List thirdparties - * + * * Get a list of thirdparties - * + * * @param string $sortfield Sort field * @param string $sortorder Sort order * @param int $limit Limit for list * @param int $page Page number - * @param int $mode Set to 1 to show only customers + * @param int $mode Set to 1 to show only customers * Set to 2 to show only prospects * Set to 3 to show only those are not customer neither prospect * @param string $sqlfilters Other criteria to filter answers separated by a comma. Syntax example "(t.ref:like:'SO-%') and (t.date_creation:<:'20160101')" @@ -99,12 +99,12 @@ class Thirdparties extends DolibarrApi */ function index($sortfield = "t.rowid", $sortorder = 'ASC', $limit = 0, $page = 0, $mode=0, $sqlfilters = '') { global $db, $conf; - + $obj_ret = array(); - + // case of external user, we force socids $socids = DolibarrApiAccess::$user->societe_id ? DolibarrApiAccess::$user->societe_id : ''; - + // If the internal user must only see his customers, force searching by him $search_sale = 0; if (! DolibarrApiAccess::$user->rights->societe->client->voir && !$socids) $search_sale = DolibarrApiAccess::$user->id; @@ -112,7 +112,7 @@ class Thirdparties extends DolibarrApi $sql = "SELECT t.rowid"; if ((!DolibarrApiAccess::$user->rights->societe->client->voir && !$socids) || $search_sale > 0) $sql .= ", sc.fk_soc, sc.fk_user"; // We need these fields in order to filter by sale (including the case where the user can only see his prospects) $sql.= " FROM ".MAIN_DB_PREFIX."societe as t"; - + if ((!DolibarrApiAccess::$user->rights->societe->client->voir && !$socids) || $search_sale > 0) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; // We need this table joined to the select in order to filter by sale $sql.= ", ".MAIN_DB_PREFIX."c_stcomm as st"; $sql.= " WHERE t.fk_stcomm = st.id"; @@ -130,7 +130,7 @@ class Thirdparties extends DolibarrApi $sql .= " AND sc.fk_user = ".$search_sale; } // Add sql filters - if ($sqlfilters) + if ($sqlfilters) { if (! DolibarrApi::_checkFilters($sqlfilters)) { @@ -139,7 +139,7 @@ class Thirdparties extends DolibarrApi $regexstring='\(([^:\'\(\)]+:[^:\'\(\)]+:[^:\(\)]+)\)'; $sql.=" AND (".preg_replace_callback('/'.$regexstring.'/', 'DolibarrApi::_forge_criteria_callback', $sqlfilters).")"; } - + $sql.= $db->order($sortfield, $sortorder); if ($limit) { @@ -175,7 +175,7 @@ class Thirdparties extends DolibarrApi } return $obj_ret; } - + /** * Create thirdparty object * @@ -189,13 +189,13 @@ class Thirdparties extends DolibarrApi } // Check mandatory fields $result = $this->_validate($request_data); - + foreach($request_data as $field => $value) { $this->company->$field = $value; } if ($this->company->create(DolibarrApiAccess::$user) < 0) throw new RestException(500, 'Error creating thirdparty', array_merge(array($this->company->error), $this->company->errors)); - + return $this->company->id; } @@ -203,20 +203,20 @@ class Thirdparties extends DolibarrApi * Update thirdparty * * @param int $id Id of thirdparty to update - * @param array $request_data Datas - * @return int + * @param array $request_data Datas + * @return int */ function put($id, $request_data = NULL) { if(! DolibarrApiAccess::$user->rights->societe->creer) { throw new RestException(401); } - + $result = $this->company->fetch($id); if( ! $result ) { throw new RestException(404, 'Thirdparty not found'); } - + if( ! DolibarrApi::_checkAccessToResource('societe',$this->company->id)) { throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login); } @@ -225,13 +225,13 @@ class Thirdparties extends DolibarrApi if ($field == 'id') continue; $this->company->$field = $value; } - + if($this->company->update($id, DolibarrApiAccess::$user,1,'','','update')) return $this->get ($id); - + return false; } - + /** * Delete thirdparty * @@ -252,7 +252,7 @@ class Thirdparties extends DolibarrApi } return $this->company->delete($id); } - + /** * Get categories for a thirdparty * @@ -266,8 +266,12 @@ class Thirdparties extends DolibarrApi * * @url GET {id}/categories */ - function getCategories($id, $sortfield = "s.rowid", $sortorder = 'ASC', $limit = 0, $page = 0) { + function getCategories($id, $sortfield = "s.rowid", $sortorder = 'ASC', $limit = 0, $page = 0) + { + require_once DOL_DOCUMENT_ROOT.'/categories/class/api_categories.class.php'; + $categories = new Categories(); + return $categories->getListForItem($sortfield, $sortorder, $limit, $page, 'customer', $id); } @@ -318,24 +322,24 @@ class Thirdparties extends DolibarrApi * @return array Array of cleaned object properties */ function _cleanObjectDatas($object) { - + $object = parent::_cleanObjectDatas($object); - + unset($object->total_ht); unset($object->total_tva); unset($object->total_localtax1); unset($object->total_localtax2); unset($object->total_ttc); - + return $object; - } - + } + /** * Validate fields before create or update object - * + * * @param array $data Datas to validate * @return array - * + * * @throws RestException */ function _validate($data) From fef6440ff25cdc60192e951bfa76ca248d40f73b Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Tue, 3 Oct 2017 16:23:30 +0200 Subject: [PATCH 19/46] FIX #7541 --- htdocs/install/mysql/tables/llx_holiday.sql | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/install/mysql/tables/llx_holiday.sql b/htdocs/install/mysql/tables/llx_holiday.sql index 35982525853..f6994810021 100644 --- a/htdocs/install/mysql/tables/llx_holiday.sql +++ b/htdocs/install/mysql/tables/llx_holiday.sql @@ -19,7 +19,7 @@ CREATE TABLE llx_holiday ( rowid integer NOT NULL AUTO_INCREMENT PRIMARY KEY, -ref varchar(30) NOT NULL, -- number +ref varchar(30) NULL, -- number ref_ext varchar(255), entity integer DEFAULT 1 NOT NULL, -- Multi company id fk_user integer NOT NULL, From 4537e5472b0bd7172476e7dfb7943483840aee3e Mon Sep 17 00:00:00 2001 From: Regis Houssin Date: Tue, 3 Oct 2017 19:01:54 +0200 Subject: [PATCH 20/46] Fix: refactorization of "getListForItem" function --- htdocs/adherents/class/api_members.class.php | 19 +++- .../categories/class/api_categories.class.php | 88 ----------------- htdocs/categories/class/categorie.class.php | 94 +++++++++++++++++++ htdocs/product/class/api_products.class.php | 14 ++- htdocs/societe/class/api_contacts.class.php | 15 ++- .../societe/class/api_thirdparties.class.php | 15 ++- 6 files changed, 143 insertions(+), 102 deletions(-) diff --git a/htdocs/adherents/class/api_members.class.php b/htdocs/adherents/class/api_members.class.php index 571c77d91f7..a4a888ae9a5 100644 --- a/htdocs/adherents/class/api_members.class.php +++ b/htdocs/adherents/class/api_members.class.php @@ -20,6 +20,7 @@ use Luracast\Restler\RestException; require_once DOL_DOCUMENT_ROOT.'/adherents/class/adherent.class.php'; require_once DOL_DOCUMENT_ROOT.'/adherents/class/subscription.class.php'; +require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php'; /** * API class for members @@ -362,8 +363,8 @@ class Members extends DolibarrApi * Get categories for a member * * @param int $id ID of member - * @param string $sortfield Sort field - * @param string $sortorder Sort order + * @param string $sortfield Sort field + * @param string $sortorder Sort order * @param int $limit Limit for list * @param int $page Page number * @@ -373,11 +374,19 @@ class Members extends DolibarrApi */ function getCategories($id, $sortfield = "s.rowid", $sortorder = 'ASC', $limit = 0, $page = 0) { - require_once DOL_DOCUMENT_ROOT.'/categories/class/api_categories.class.php'; + $categories = new Categorie($this->db); - $categories = new Categories(); + $result = $categories->getListForItem($id, 'member', $sortfield, $sortorder, $limit, $page); - return $categories->getListForItem($sortfield, $sortorder, $limit, $page, 'member', $id); + if (empty($result)) { + throw new RestException(404, 'No category found'); + } + + if ($result < 0) { + throw new RestException(503, 'Error when retrieve category list : '.$categories->error); + } + + return $result; } } diff --git a/htdocs/categories/class/api_categories.class.php b/htdocs/categories/class/api_categories.class.php index a43ccbd180b..1c8d9fcfe50 100644 --- a/htdocs/categories/class/api_categories.class.php +++ b/htdocs/categories/class/api_categories.class.php @@ -166,94 +166,6 @@ class Categories extends DolibarrApi return $obj_ret; } - /** - * List categories of an entity - * - * Note: This method is not directly exposed in the API, it is used - * in the GET /xxx/{id}/categories requests. - * - * @param string $sortfield Sort field - * @param string $sortorder Sort order - * @param int $limit Limit for list - * @param int $page Page number - * @param string $type Type of category ('member', 'customer', 'supplier', 'product', 'contact') - * @param int $item Id of the item to get categories for - * @return array Array of category objects - * - * @access private - */ - function getListForItem($sortfield = "s.rowid", $sortorder = 'ASC', $limit = 0, $page = 0, $type='customer', $item = 0) { - global $db, $conf; - - $obj_ret = array(); - - if(! DolibarrApiAccess::$user->rights->categorie->lire) { - throw new RestException(401); - } - //if ($type == "") { - //$type="product"; - //} - $sub_type = $type; - $subcol_name = "fk_".$type; - if ($type=="customer" || $type=="supplier") { - $sub_type="societe"; - $subcol_name="fk_soc"; - } - if ($type=="contact") { - $subcol_name="fk_socpeople"; - } - $sql = "SELECT s.rowid"; - $sql.= " FROM ".MAIN_DB_PREFIX."categorie as s"; - $sql.= " , ".MAIN_DB_PREFIX."categorie_".$sub_type." as sub "; - $sql.= ' WHERE s.entity IN ('.getEntity('category').')'; - $sql.= ' AND s.type='.array_search($type,Categories::$TYPES); - $sql.= ' AND s.rowid = sub.fk_categorie'; - $sql.= ' AND sub.'.$subcol_name.' = '.$item; - - $nbtotalofrecords = ''; - if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST)) - { - $result = $db->query($sql); - $nbtotalofrecords = $db->num_rows($result); - } - - $sql.= $db->order($sortfield, $sortorder); - if ($limit) { - if ($page < 0) - { - $page = 0; - } - $offset = $limit * $page; - - $sql.= $db->plimit($limit + 1, $offset); - } - - $result = $db->query($sql); - if ($result) - { - $i=0; - $num = $db->num_rows($result); - $min = min($num, ($limit <= 0 ? $num : $limit)); - while ($i < $min) - { - $obj = $db->fetch_object($result); - $category_static = new Categorie($db); - if($category_static->fetch($obj->rowid)) { - $obj_ret[] = $this->_cleanObjectDatas($category_static); - } - $i++; - } - } - else { - throw new RestException(503, 'Error when retrieve category list : '.$db->lasterror()); - } - if( ! count($obj_ret)) { - throw new RestException(404, 'No category found'); - } - - return $obj_ret; - } - /** * Create category object * diff --git a/htdocs/categories/class/categorie.class.php b/htdocs/categories/class/categorie.class.php index 5cbe56554dd..6027f76ec58 100644 --- a/htdocs/categories/class/categorie.class.php +++ b/htdocs/categories/class/categorie.class.php @@ -879,6 +879,100 @@ class Categorie extends CommonObject } } + /** + * List categories of an element id + * + * @param int $item Id of element + * @param string $type Type of category ('member', 'customer', 'supplier', 'product', 'contact') + * @param string $sortfield Sort field + * @param string $sortorder Sort order + * @param int $limit Limit for list + * @param int $page Page number + * @return array Array of categories + */ + function getListForItem($id, $type='customer', $sortfield = "s.rowid", $sortorder = 'ASC', $limit = 0, $page = 0) + { + global $conf; + + $categories = array(); + + $sub_type = $type; + $subcol_name = "fk_".$type; + if ($type=="customer" || $type=="supplier") { + $sub_type="societe"; + $subcol_name="fk_soc"; + } + if ($type=="contact") { + $subcol_name="fk_socpeople"; + } + $sql = "SELECT s.rowid"; + $sql.= " FROM ".MAIN_DB_PREFIX."categorie as s"; + $sql.= " , ".MAIN_DB_PREFIX."categorie_".$sub_type." as sub "; + $sql.= ' WHERE s.entity IN ('.getEntity('category').')'; + $sql.= ' AND s.type='.array_search($type, self::$MAP_ID_TO_CODE); + $sql.= ' AND s.rowid = sub.fk_categorie'; + $sql.= ' AND sub.'.$subcol_name.' = '.$id; + + $nbtotalofrecords = ''; + if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST)) + { + $result = $this->db->query($sql); + $nbtotalofrecords = $this->db->num_rows($result); + } + + $sql.= $this->db->order($sortfield, $sortorder); + if ($limit) { + if ($page < 0) + { + $page = 0; + } + $offset = $limit * $page; + + $sql.= $this->db->plimit($limit + 1, $offset); + } + + $result = $this->db->query($sql); + if ($result) + { + $i=0; + $num = $this->db->num_rows($result); + $min = min($num, ($limit <= 0 ? $num : $limit)); + while ($i < $min) + { + $obj = $this->db->fetch_object($result); + $category_static = new Categorie($this->db); + if ($category_static->fetch($obj->rowid)) + { + $categories[$i]['id'] = $category_static->id; + $categories[$i]['fk_parent'] = $category_static->fk_parent; + $categories[$i]['label'] = $category_static->label; + $categories[$i]['description'] = $category_static->description; + $categories[$i]['color'] = $category_static->color; + $categories[$i]['socid'] = $category_static->socid; + $categories[$i]['visible'] = $category_static->visible; + $categories[$i]['type'] = $category_static->type; + $categories[$i]['entity'] = $category_static->entity; + $categories[$i]['array_options'] = $category_static->array_options; + + // multilangs + if (! empty($conf->global->MAIN_MULTILANGS)) { + $categories[$i]['multilangs'] = $category_static->multilangs; + } + } + $i++; + } + } + else { + $this->error = $this->db->lasterror(); + return -1; + } + if ( ! count($categories)) { + return 0; + } + + return $categories; + } + /** * Return childs of a category * diff --git a/htdocs/product/class/api_products.class.php b/htdocs/product/class/api_products.class.php index a16022ea047..809b8b160c3 100644 --- a/htdocs/product/class/api_products.class.php +++ b/htdocs/product/class/api_products.class.php @@ -265,11 +265,19 @@ class Products extends DolibarrApi */ function getCategories($id, $sortfield = "s.rowid", $sortorder = 'ASC', $limit = 0, $page = 0) { - require_once DOL_DOCUMENT_ROOT.'/categories/class/api_categories.class.php'; + $categories = new Categorie($this->db); - $categories = new Categories(); + $result = $categories->getListForItem($id, 'product', $sortfield, $sortorder, $limit, $page); - return $categories->getListForItem($sortfield, $sortorder, $limit, $page, 'product', $id); + if (empty($result)) { + throw new RestException(404, 'No category found'); + } + + if ($result < 0) { + throw new RestException(503, 'Error when retrieve category list : '.$categories->error); + } + + return $result; } /** diff --git a/htdocs/societe/class/api_contacts.class.php b/htdocs/societe/class/api_contacts.class.php index 6d3a5970c9b..29bb43d211d 100644 --- a/htdocs/societe/class/api_contacts.class.php +++ b/htdocs/societe/class/api_contacts.class.php @@ -18,6 +18,7 @@ use Luracast\Restler\RestException; //require_once DOL_DOCUMENT_ROOT . '/contact/class/contact.class.php'; +require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php'; /** * API class for contacts @@ -335,11 +336,19 @@ class Contacts extends DolibarrApi */ function getCategories($id, $sortfield = "s.rowid", $sortorder = 'ASC', $limit = 0, $page = 0) { - require_once DOL_DOCUMENT_ROOT.'/categories/class/api_categories.class.php'; + $categories = new Categorie($this->db); - $categories = new Categories(); + $result = $categories->getListForItem($id, 'contact', $sortfield, $sortorder, $limit, $page); - return $categories->getListForItem($sortfield, $sortorder, $limit, $page, 'contact', $id); + if (empty($result)) { + throw new RestException(404, 'No category found'); + } + + if ($result < 0) { + throw new RestException(503, 'Error when retrieve category list : '.$categories->error); + } + + return $result; } /** diff --git a/htdocs/societe/class/api_thirdparties.class.php b/htdocs/societe/class/api_thirdparties.class.php index 88492779bda..0fe5d5e706e 100644 --- a/htdocs/societe/class/api_thirdparties.class.php +++ b/htdocs/societe/class/api_thirdparties.class.php @@ -17,6 +17,7 @@ use Luracast\Restler\RestException; + require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php'; /** * API class for thirdparties @@ -268,11 +269,19 @@ class Thirdparties extends DolibarrApi */ function getCategories($id, $sortfield = "s.rowid", $sortorder = 'ASC', $limit = 0, $page = 0) { - require_once DOL_DOCUMENT_ROOT.'/categories/class/api_categories.class.php'; + $categories = new Categorie($this->db); - $categories = new Categories(); + $result = $categories->getListForItem($id, 'customer', $sortfield, $sortorder, $limit, $page); - return $categories->getListForItem($sortfield, $sortorder, $limit, $page, 'customer', $id); + if (empty($result)) { + throw new RestException(404, 'No category found'); + } + + if ($result < 0) { + throw new RestException(503, 'Error when retrieve category list : '.$categories->error); + } + + return $result; } /** From 45de1ca21efdfc061ef931c8ad863fedd6bda90a Mon Sep 17 00:00:00 2001 From: Regis Houssin Date: Tue, 3 Oct 2017 19:09:46 +0200 Subject: [PATCH 21/46] Fix: check security --- htdocs/adherents/class/api_members.class.php | 4 ++++ htdocs/product/class/api_products.class.php | 4 ++++ htdocs/societe/class/api_contacts.class.php | 4 ++++ htdocs/societe/class/api_thirdparties.class.php | 4 ++++ 4 files changed, 16 insertions(+) diff --git a/htdocs/adherents/class/api_members.class.php b/htdocs/adherents/class/api_members.class.php index a4a888ae9a5..99a4f401171 100644 --- a/htdocs/adherents/class/api_members.class.php +++ b/htdocs/adherents/class/api_members.class.php @@ -374,6 +374,10 @@ class Members extends DolibarrApi */ function getCategories($id, $sortfield = "s.rowid", $sortorder = 'ASC', $limit = 0, $page = 0) { + if (! DolibarrApiAccess::$user->rights->categorie->lire) { + throw new RestException(401); + } + $categories = new Categorie($this->db); $result = $categories->getListForItem($id, 'member', $sortfield, $sortorder, $limit, $page); diff --git a/htdocs/product/class/api_products.class.php b/htdocs/product/class/api_products.class.php index 809b8b160c3..25071801fe3 100644 --- a/htdocs/product/class/api_products.class.php +++ b/htdocs/product/class/api_products.class.php @@ -265,6 +265,10 @@ class Products extends DolibarrApi */ function getCategories($id, $sortfield = "s.rowid", $sortorder = 'ASC', $limit = 0, $page = 0) { + if (! DolibarrApiAccess::$user->rights->categorie->lire) { + throw new RestException(401); + } + $categories = new Categorie($this->db); $result = $categories->getListForItem($id, 'product', $sortfield, $sortorder, $limit, $page); diff --git a/htdocs/societe/class/api_contacts.class.php b/htdocs/societe/class/api_contacts.class.php index 29bb43d211d..0e3c10ce726 100644 --- a/htdocs/societe/class/api_contacts.class.php +++ b/htdocs/societe/class/api_contacts.class.php @@ -336,6 +336,10 @@ class Contacts extends DolibarrApi */ function getCategories($id, $sortfield = "s.rowid", $sortorder = 'ASC', $limit = 0, $page = 0) { + if (! DolibarrApiAccess::$user->rights->categorie->lire) { + throw new RestException(401); + } + $categories = new Categorie($this->db); $result = $categories->getListForItem($id, 'contact', $sortfield, $sortorder, $limit, $page); diff --git a/htdocs/societe/class/api_thirdparties.class.php b/htdocs/societe/class/api_thirdparties.class.php index 0fe5d5e706e..ab38f62b2ed 100644 --- a/htdocs/societe/class/api_thirdparties.class.php +++ b/htdocs/societe/class/api_thirdparties.class.php @@ -269,6 +269,10 @@ class Thirdparties extends DolibarrApi */ function getCategories($id, $sortfield = "s.rowid", $sortorder = 'ASC', $limit = 0, $page = 0) { + if (! DolibarrApiAccess::$user->rights->categorie->lire) { + throw new RestException(401); + } + $categories = new Categorie($this->db); $result = $categories->getListForItem($id, 'customer', $sortfield, $sortorder, $limit, $page); From 69314e08aca32cd0497a1903125ec5c7805d450c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20FRANCE?= Date: Wed, 4 Oct 2017 10:12:51 +0200 Subject: [PATCH 22/46] can't clean search_type in holiday list --- htdocs/holiday/list.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/holiday/list.php b/htdocs/holiday/list.php index 2e63793cbfd..e4c5437028b 100644 --- a/htdocs/holiday/list.php +++ b/htdocs/holiday/list.php @@ -418,7 +418,7 @@ foreach($typeleaves as $key => $val) //$labeltoshow .= ($val['delay'] > 0 ? ' ('.$langs->trans("NoticePeriod").': '.$val['delay'].' '.$langs->trans("days").')':''); $arraytypeleaves[$val['rowid']]=$labeltoshow; } -print $form->selectarray('search_type', $arraytypeleaves, (GETPOST('search_type')?GETPOST('search_type'):''), 1); +print $form->selectarray('search_type', $arraytypeleaves, $search_type, 1); print ''; // Duration From 2dee81125a53bbbd898c35937f8250e4ce9e46d9 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Wed, 4 Oct 2017 11:18:31 +0200 Subject: [PATCH 23/46] Hide comment feature for the moment --- htdocs/projet/admin/project.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/htdocs/projet/admin/project.php b/htdocs/projet/admin/project.php index 54e864e1bf6..53444a7580c 100644 --- a/htdocs/projet/admin/project.php +++ b/htdocs/projet/admin/project.php @@ -918,6 +918,8 @@ print ''; print '
'; print ''; +/* Kept as hidden feature because this will be "probaly be supported by standard event feature in a future + print ''; print ''; @@ -935,6 +937,7 @@ echo ajax_constantonoff('PROJECT_ALLOW_COMMENT_ON_TASK'); print ''; print ''; print ''; +*/ print '
 
'.$langs->trans("AllowCommentOnProject").' 
'; From 85606126a9180cc8a992d39a83ffaf1e6bca3b89 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Wed, 4 Oct 2017 12:58:13 +0200 Subject: [PATCH 24/46] Standardize code for events --- htdocs/adherents/agenda.php | 71 +++++++++++++++++--- htdocs/adherents/card.php | 8 ++- htdocs/comm/action/listactions.php | 20 +++--- htdocs/comm/action/rapport/index.php | 2 +- htdocs/contact/agenda.php | 15 +++-- htdocs/core/class/html.formactions.class.php | 27 ++++---- htdocs/core/lib/company.lib.php | 44 ++++++------ htdocs/core/lib/functions.lib.php | 10 ++- htdocs/langs/en_US/agenda.lang | 1 + htdocs/langs/en_US/main.lang | 1 + htdocs/projet/card.php | 10 ++- htdocs/projet/class/project.class.php | 4 +- htdocs/projet/info.php | 30 +++------ htdocs/projet/tasks.php | 2 +- htdocs/societe/agenda.php | 16 +++-- htdocs/societe/card.php | 8 ++- 16 files changed, 169 insertions(+), 100 deletions(-) diff --git a/htdocs/adherents/agenda.php b/htdocs/adherents/agenda.php index 007ce92a4d5..1228dc92bf9 100644 --- a/htdocs/adherents/agenda.php +++ b/htdocs/adherents/agenda.php @@ -38,6 +38,28 @@ $langs->load("members"); $id = GETPOST('id','int')?GETPOST('id','int'):GETPOST('rowid','int'); +$limit = GETPOST('limit','int')?GETPOST('limit','int'):$conf->liste_limit; +$sortfield = GETPOST("sortfield",'alpha'); +$sortorder = GETPOST("sortorder",'alpha'); +$page = GETPOST("page",'int'); +if (empty($page) || $page == -1) { $page = 0; } // If $page is not defined, or '' or -1 +$offset = $limit * $page; +$pageprev = $page - 1; +$pagenext = $page + 1; +if (! $sortfield) $sortfield='a.datep,a.id'; +if (! $sortorder) $sortorder='DESC'; + +if (GETPOST('actioncode','array')) +{ + $actioncode=GETPOST('actioncode','array',3); + if (! count($actioncode)) $actioncode='0'; +} +else +{ + $actioncode=GETPOST("actioncode","alpha",3)?GETPOST("actioncode","alpha",3):(GETPOST("actioncode")=='0'?'0':(empty($conf->global->AGENDA_DEFAULT_FILTER_TYPE_FOR_OBJECT)?'':$conf->global->AGENDA_DEFAULT_FILTER_TYPE_FOR_OBJECT)); +} +$search_agenda_label=GETPOST('search_agenda_label'); + // Security check $result=restrictedArea($user,'adherent',$id); @@ -56,7 +78,26 @@ if ($result > 0) * Actions */ -// None +$parameters=array('id'=>$id, 'objcanvas'=>$objcanvas); +$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)) +{ + // Cancel + if (GETPOST('cancel','alpha') && ! empty($backtopage)) + { + header("Location: ".$backtopage); + exit; + } + + // Purge search criteria + if (GETPOST('button_removefilter_x','alpha') || GETPOST('button_removefilter.x','alpha') || GETPOST('button_removefilter','alpha')) // All test are required to be compatible with all browsers + { + $actioncode=''; + $search_agenda_label=''; + } +} @@ -103,25 +144,33 @@ if ($object->id > 0) dol_fiche_end(); - /* - * Barre d'action - */ + //print '
'; + //print '
'; - print '
'; + $morehtmlcenter = ''; if (! empty($conf->agenda->enabled)) { - print ''; + $morehtmlcenter.=''.$langs->trans("AddAction").''; } - print '
'; + if (! empty($conf->agenda->enabled) && (!empty($user->rights->agenda->myactions->read) || !empty($user->rights->agenda->allactions->read) )) + { + print '
'; - $out=''; + $param='&id='.$id; + if (! empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) $param.='&contextpage='.$contextpage; + if ($limit > 0 && $limit != $conf->liste_limit) $param.='&limit='.$limit; - print load_fiche_titre($langs->trans("ActionsOnMember"),$out,''); + print_barre_liste($langs->trans("ActionsOnMember"), 0, $_SERVER["PHP_SELF"], '', $sortfield, $sortorder, $morehtmlcenter, 0, -1, '', '', '', '', 0, 1, 1); - // List of actions - show_actions_done($conf,$langs,$db,$object,null,0,'',''); + // List of all actions + $filters=array(); + $filters['search_agenda_label']=$search_agenda_label; + + // TODO Replace this with same code than into listactions.php + show_actions_done($conf,$langs,$db,$object,null,0,$actioncode, '', $filters, $sortfield, $sortorder); + } } diff --git a/htdocs/adherents/card.php b/htdocs/adherents/card.php index 9f8ea7ea2f0..5ab8ff1cc99 100644 --- a/htdocs/adherents/card.php +++ b/htdocs/adherents/card.php @@ -1799,10 +1799,16 @@ else print '
'; + $MAX = 10; + + $morehtmlright = ''; + $morehtmlright.= $langs->trans("SeeAll"); + $morehtmlright.= ''; + // List of actions on element include_once DOL_DOCUMENT_ROOT . '/core/class/html.formactions.class.php'; $formactions = new FormActions($db); - $somethingshown = $formactions->showactions($object, 'member', $socid, 1, 'listactions', 10); + $somethingshown = $formactions->showactions($object, 'member', $socid, 1, 'listactions', $MAX, '', $morehtmlright); print '
'; } diff --git a/htdocs/comm/action/listactions.php b/htdocs/comm/action/listactions.php index 78e73fe0717..982974b3d7a 100644 --- a/htdocs/comm/action/listactions.php +++ b/htdocs/comm/action/listactions.php @@ -357,7 +357,7 @@ if ($resql) //$param='month='.$monthshown.'&year='.$year; $hourminsec='100000'; $link = ''; - $link.= $langs->trans("NewAction"); + $link.= $langs->trans("AddAction"); $link.= ''; } @@ -372,9 +372,9 @@ if ($resql) print ''; print ''; print ''; + print ''; print ''; - print ''; - print ''; + print ''; print $form->select_date($datestart, 'datestart', 0, 0, 1, '', 1, 0, 1); print ''; print ''; @@ -396,9 +396,9 @@ if ($resql) print ''; print_liste_field_titre("Ref",$_SERVER["PHP_SELF"],"a.id",$param,"","",$sortfield,$sortorder); print_liste_field_titre("ActionsOwnedByShort",$_SERVER["PHP_SELF"],"",$param,"","",$sortfield,$sortorder); - print_liste_field_titre("Label",$_SERVER["PHP_SELF"],"a.label",$param,"","",$sortfield,$sortorder); //if (! empty($conf->global->AGENDA_USE_EVENT_TYPE)) - print_liste_field_titre("Type",$_SERVER["PHP_SELF"],"c.libelle",$param,"","",$sortfield,$sortorder); + print_liste_field_titre("Type",$_SERVER["PHP_SELF"],"c.libelle",$param,"","",$sortfield,$sortorder); + print_liste_field_titre("Label",$_SERVER["PHP_SELF"],"a.label",$param,"","",$sortfield,$sortorder); print_liste_field_titre("DateStart",$_SERVER["PHP_SELF"],"a.datep",$param,'','align="center"',$sortfield,$sortorder); print_liste_field_titre("DateEnd",$_SERVER["PHP_SELF"],"a.datep2",$param,'','align="center"',$sortfield,$sortorder); print_liste_field_titre("ThirdParty",$_SERVER["PHP_SELF"],"s.nom",$param,"","",$sortfield,$sortorder); @@ -452,11 +452,6 @@ if ($resql) else print ' '; print ''; - // Label - print ''; - print $actionstatic->label; - print ''; - // Type print ''; if (! empty($conf->global->AGENDA_USE_EVENT_TYPE)) @@ -475,6 +470,11 @@ if ($resql) print dol_trunc($labeltype,28); print ''; + // Label + print ''; + print $actionstatic->label; + print ''; + // Start date print ''; print dol_print_date($db->jdate($obj->dp),"dayhour"); diff --git a/htdocs/comm/action/rapport/index.php b/htdocs/comm/action/rapport/index.php index dcda4e0cf04..5994f692cc8 100644 --- a/htdocs/comm/action/rapport/index.php +++ b/htdocs/comm/action/rapport/index.php @@ -116,7 +116,7 @@ if ($resql) print ''; print ''; - print_barre_liste($langs->trans("Actions"), $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, '', $num, $nbtotalofrecords, 'title_agenda', 0, '', '', $limit); + print_barre_liste($langs->trans("EventReports"), $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, '', $num, $nbtotalofrecords, 'title_agenda', 0, '', '', $limit); $moreforfilter=''; diff --git a/htdocs/contact/agenda.php b/htdocs/contact/agenda.php index a4412082ead..c885f0869de 100644 --- a/htdocs/contact/agenda.php +++ b/htdocs/contact/agenda.php @@ -257,30 +257,33 @@ else } - print '
'; + //print '
'; + //print '
'; + + $morehtmlcenter=''; if (! empty($conf->agenda->enabled)) { if (! empty($user->rights->agenda->myactions->create) || ! empty($user->rights->agenda->allactions->create)) { - print ''.$langs->trans("AddAction").''; + $morehtmlcenter.= ''.$langs->trans("AddAction").''; } else { - print ''.$langs->trans("AddAction").''; + $morehtmlcenter.= ''.$langs->trans("AddAction").''; } } - print '
'; if (! empty($conf->agenda->enabled) && (!empty($user->rights->agenda->myactions->read) || !empty($user->rights->agenda->allactions->read) )) { + print '
'; + $param='&id='.$id; if (! empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) $param.='&contextpage='.$contextpage; if ($limit > 0 && $limit != $conf->liste_limit) $param.='&limit='.$limit; - - print load_fiche_titre($langs->trans("TasksHistoryForThisContact"),'',''); + print_barre_liste($langs->trans("ActionsOnCompany"), 0, $_SERVER["PHP_SELF"], '', $sortfield, $sortorder, $morehtmlcenter, 0, -1, '', '', '', '', 0, 1, 1); // List of all actions $filters=array(); diff --git a/htdocs/core/class/html.formactions.class.php b/htdocs/core/class/html.formactions.class.php index 84c7ab389f3..adf5f4c340b 100644 --- a/htdocs/core/class/html.formactions.class.php +++ b/htdocs/core/class/html.formactions.class.php @@ -157,9 +157,10 @@ class FormActions * @param string $morecss More css on table * @param int $max Max number of record * @param string $moreparambacktopage More param for the backtopage + * @param string $morehtmlright More html text on right of title line * @return int <0 if KO, >=0 if OK */ - function showactions($object, $typeelement, $socid=0, $forceshowtitle=0, $morecss='listactions', $max=0, $moreparambacktopage='') + function showactions($object, $typeelement, $socid=0, $forceshowtitle=0, $morecss='listactions', $max=0, $moreparambacktopage='', $morehtmlright='') { global $langs,$conf,$user; global $bc; @@ -196,7 +197,7 @@ class FormActions $buttontoaddnewevent.= ''; print ''."\n"; - print load_fiche_titre($title, $buttontoaddnewevent, ''); + print load_fiche_titre($title, $morehtmlright, '', 0, 0, '', $buttontoaddnewevent); $page=0; $param=''; @@ -206,10 +207,10 @@ class FormActions print ''; print ''; print getTitleFieldOfList('Ref', 0, $_SERVER["PHP_SELF"], '', $page, $param, '', $sortfield, $sortorder, '', 1); - print getTitleFieldOfList('Action', 0, $_SERVER["PHP_SELF"], '', $page, $param, '', $sortfield, $sortorder, '', 1); - print getTitleFieldOfList('Type', 0, $_SERVER["PHP_SELF"], '', $page, $param, '', $sortfield, $sortorder, '', 1); - print getTitleFieldOfList('Date', 0, $_SERVER["PHP_SELF"], 'a.datep', $page, $param, 'align="center"', $sortfield, $sortorder, '', 1); print getTitleFieldOfList('By', 0, $_SERVER["PHP_SELF"], '', $page, $param, '', $sortfield, $sortorder, '', 1); + print getTitleFieldOfList('Type', 0, $_SERVER["PHP_SELF"], '', $page, $param, '', $sortfield, $sortorder, '', 1); + print getTitleFieldOfList('Action', 0, $_SERVER["PHP_SELF"], '', $page, $param, '', $sortfield, $sortorder, '', 1); + print getTitleFieldOfList('Date', 0, $_SERVER["PHP_SELF"], 'a.datep', $page, $param, 'align="center"', $sortfield, $sortorder, '', 1); print getTitleFieldOfList('', 0, $_SERVER["PHP_SELF"], '', $page, $param, 'align="right"', $sortfield, $sortorder, '', 1); print ''; print "\n"; @@ -228,8 +229,14 @@ class FormActions print ''; print ''; - print ''; print ''; + print ''; + print ''; print ''; - print ''; print ''; $out.=''; - $out.=''; - $out.=''; $out.=''; + $out.=''; + $out.=''; $out.=''; $out.=''; $out.=''; @@ -1316,9 +1316,9 @@ function show_actions_done($conf, $langs, $db, $filterobj, $objcon='', $noprint= } $out.=getTitleFieldOfList($langs->trans("Ref"), 0, $_SERVER["PHP_SELF"], 'a.id', '', $param, '', $sortfield, $sortorder); $out.=getTitleFieldOfList($langs->trans("Owner")); + $out.=getTitleFieldOfList($langs->trans("Type")); $out.=getTitleFieldOfList($langs->trans("Label"), 0, $_SERVER["PHP_SELF"], '', '', $param, '', $sortfield, $sortorder); $out.=getTitleFieldOfList($langs->trans("Date"), 0, $_SERVER["PHP_SELF"], 'a.datep,a.id', '', $param, 'align="center"', $sortfield, $sortorder); - $out.=getTitleFieldOfList($langs->trans("Type")); $out.=getTitleFieldOfList(''); $out.=getTitleFieldOfList(''); $out.=getTitleFieldOfList($langs->trans("Status"), 0, $_SERVER["PHP_SELF"], 'a.percent', '', $param, 'align="center"', $sortfield, $sortorder); @@ -1353,6 +1353,25 @@ function show_actions_done($conf, $langs, $db, $filterobj, $objcon='', $noprint= $out.=$userstatic->getNomUrl(-1); $out.=''; + // Type + $out.=''; + // Title $out.='\n"; - // Type - $out.=''; - // Title of event //$out.=''; diff --git a/htdocs/core/lib/functions.lib.php b/htdocs/core/lib/functions.lib.php index 230d023e7aa..dbd1832aeb4 100644 --- a/htdocs/core/lib/functions.lib.php +++ b/htdocs/core/lib/functions.lib.php @@ -3540,10 +3540,11 @@ function print_fiche_titre($title, $mesg='', $picto='title_generic.png', $pictoi * @param int $pictoisfullpath 1=Icon name is a full absolute url of image * @param int $id To force an id on html objects * @param string $morecssontable More css on table + * @param string $morehtmlcenter Added message to show on center * @return string * @see print_barre_liste */ -function load_fiche_titre($titre, $morehtmlright='', $picto='title_generic.png', $pictoisfullpath=0, $id=0, $morecssontable='') +function load_fiche_titre($titre, $morehtmlright='', $picto='title_generic.png', $pictoisfullpath=0, $id=0, $morecssontable='', $morehtmlcenter='') { global $conf; @@ -3558,6 +3559,10 @@ function load_fiche_titre($titre, $morehtmlright='', $picto='title_generic.png', $return.= ''; + if (dol_strlen($morehtmlcenter)) + { + $return.= ''; + } if (dol_strlen($morehtmlright)) { $return.= ''; @@ -3585,9 +3590,10 @@ function load_fiche_titre($titre, $morehtmlright='', $picto='title_generic.png', * @param string $morecss More css to the table * @param int $limit Max number of lines (-1 = use default, 0 = no limit, > 0 = limit). * @param int $hideselectlimit Force to hide select limit + * @param int $hidenavigation Force to hide all navigation tools * @return void */ -function print_barre_liste($titre, $page, $file, $options='', $sortfield='', $sortorder='', $center='', $num=-1, $totalnboflines='', $picto='title_generic.png', $pictoisfullpath=0, $morehtml='', $morecss='', $limit=-1, $hideselectlimit=0) +function print_barre_liste($titre, $page, $file, $options='', $sortfield='', $sortorder='', $center='', $num=-1, $totalnboflines='', $picto='title_generic.png', $pictoisfullpath=0, $morehtml='', $morecss='', $limit=-1, $hideselectlimit=0, $hidenavigation=0) { global $conf,$langs; diff --git a/htdocs/langs/en_US/agenda.lang b/htdocs/langs/en_US/agenda.lang index 88c6bbc54f5..116fc189732 100644 --- a/htdocs/langs/en_US/agenda.lang +++ b/htdocs/langs/en_US/agenda.lang @@ -12,6 +12,7 @@ Event=Event Events=Events EventsNb=Number of events ListOfActions=List of events +EventReports=Event reports Location=Location ToUserOfGroup=To any user in group EventOnFullDay=Event on all day(s) diff --git a/htdocs/langs/en_US/main.lang b/htdocs/langs/en_US/main.lang index fbbd8dbaabd..7383cdea931 100644 --- a/htdocs/langs/en_US/main.lang +++ b/htdocs/langs/en_US/main.lang @@ -597,6 +597,7 @@ Undo=Undo Redo=Redo ExpandAll=Expand all UndoExpandAll=Undo expand +SeeAll=See all Reason=Reason FeatureNotYetSupported=Feature not yet supported CloseWindow=Close window diff --git a/htdocs/projet/card.php b/htdocs/projet/card.php index 1146ba49b80..6fc06b3e51a 100644 --- a/htdocs/projet/card.php +++ b/htdocs/projet/card.php @@ -1192,16 +1192,20 @@ elseif ($object->id > 0) $genallowed=($user->rights->projet->lire && $userAccess > 0); $delallowed=($user->rights->projet->creer && $userWrite > 0); - $var=true; - print $formfile->showdocuments('project',$filename,$filedir,$urlsource,$genallowed,$delallowed,$object->modelpdf); print '
'; + $MAX = 10; + + $morehtmlright = ''; + $morehtmlright.= $langs->trans("SeeAll"); + $morehtmlright.= ''; + // List of actions on element include_once DOL_DOCUMENT_ROOT . '/core/class/html.formactions.class.php'; $formactions = new FormActions($db); - $somethingshown = $formactions->showactions($object, 'project', $socid, 1, '', 10); + $somethingshown = $formactions->showactions($object, 'project', $socid, 1, '', $MAX, '', $morehtmlright); print '
'; } diff --git a/htdocs/projet/class/project.class.php b/htdocs/projet/class/project.class.php index 18aa3fe1f52..4ade2a31f41 100644 --- a/htdocs/projet/class/project.class.php +++ b/htdocs/projet/class/project.class.php @@ -296,6 +296,7 @@ class Project extends CommonObject $sql.= ", fk_user_close=" . ($this->fk_user_close > 0 ? $this->fk_user_close : "null"); $sql.= ", opp_amount = " . (strcmp($this->opp_amount, '') ? price2num($this->opp_amount) : "null"); $sql.= ", budget_amount = " . (strcmp($this->budget_amount, '') ? price2num($this->budget_amount) : "null"); + $sql.= ", fk_user_modif = " . $user->id; $sql.= " WHERE rowid = " . $this->id; dol_syslog(get_class($this)."::update", LOG_DEBUG); @@ -390,7 +391,7 @@ class Project extends CommonObject if (empty($id) && empty($ref)) return -1; $sql = "SELECT rowid, ref, title, description, public, datec, opp_amount, budget_amount,"; - $sql.= " tms, dateo, datee, date_close, fk_soc, fk_user_creat, fk_user_close, fk_statut, fk_opp_status, opp_percent, note_private, note_public, model_pdf"; + $sql.= " tms, dateo, datee, date_close, fk_soc, fk_user_creat, fk_user_modif, fk_user_close, fk_statut, fk_opp_status, opp_percent, note_private, note_public, model_pdf"; $sql.= " FROM " . MAIN_DB_PREFIX . "projet"; if (! empty($id)) { @@ -428,6 +429,7 @@ class Project extends CommonObject $this->note_public = $obj->note_public; $this->socid = $obj->fk_soc; $this->user_author_id = $obj->fk_user_creat; + $this->user_modification_id = $obj->fk_user_modif; $this->user_close_id = $obj->fk_user_close; $this->public = $obj->public; $this->statut = $obj->fk_statut; diff --git a/htdocs/projet/info.php b/htdocs/projet/info.php index 3c21d9e0ced..124371e299b 100644 --- a/htdocs/projet/info.php +++ b/htdocs/projet/info.php @@ -156,42 +156,32 @@ if ($permok) } -print '
'; - +//print '
'; +$morehtmlcenter=''; if (! empty($conf->agenda->enabled)) { if (! empty($user->rights->agenda->myactions->create) || ! empty($user->rights->agenda->allactions->create)) { - print ''.$langs->trans("AddAction").''; + $morehtmlcenter.=''.$langs->trans("AddAction").''; } else { - print ''.$langs->trans("AddAction").''; + $morehtmlcenter.=''.$langs->trans("AddAction").''; } } -print '
'; - +//print '
'; if (!empty($object->id)) { - $param='&id='.$object->id; + print '
'; + + $param='&id='.$object->id; if (! empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) $param.='&contextpage='.$contextpage; if ($limit > 0 && $limit != $conf->liste_limit) $param.='&limit='.$limit; - print load_fiche_titre($langs->trans("ActionsOnProject"),'',''); - - // List of actions on element - /*include_once DOL_DOCUMENT_ROOT.'/core/class/html.formactions.class.php'; - $formactions=new FormActions($db); - $somethingshown = $formactions->showactions($object,'project',0);*/ - - // List of todo actions - //show_actions_todo($conf,$langs,$db,$object,null,0,$actioncode); - - // List of done actions - //show_actions_done($conf,$langs,$db,$object,null,0,$actioncode); - + print_barre_liste($langs->trans("ActionsOnProject"), 0, $_SERVER["PHP_SELF"], '', $sortfield, $sortorder, $morehtmlcenter, 0, -1, '', '', '', '', 0, 1, 1); + // List of all actions $filters=array(); $filters['search_agenda_label']=$search_agenda_label; diff --git a/htdocs/projet/tasks.php b/htdocs/projet/tasks.php index 41413645906..12da09053cd 100644 --- a/htdocs/projet/tasks.php +++ b/htdocs/projet/tasks.php @@ -366,7 +366,7 @@ if ($action == 'create' && $user->rights->projet->creer && (empty($object->third print ''; print ''; // List of projects diff --git a/htdocs/societe/agenda.php b/htdocs/societe/agenda.php index 0dea66946ec..73b662741cd 100644 --- a/htdocs/societe/agenda.php +++ b/htdocs/societe/agenda.php @@ -155,30 +155,32 @@ if ($socid > 0) } - print '
'; + //print '
'; + //print '
'; + + $morehtmlcenter=''; if (! empty($conf->agenda->enabled)) { if (! empty($user->rights->agenda->myactions->create) || ! empty($user->rights->agenda->allactions->create)) { - print ''.$langs->trans("AddAction").''; + $morehtmlcenter.=''.$langs->trans("AddAction").''; } else { - print ''.$langs->trans("AddAction").''; + $morehtmlcenter.=''.$langs->trans("AddAction").''; } } - print '
'; - if (! empty($conf->agenda->enabled) && (!empty($user->rights->agenda->myactions->read) || !empty($user->rights->agenda->allactions->read) )) { + print '
'; + $param='&socid='.$socid; if (! empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) $param.='&contextpage='.$contextpage; if ($limit > 0 && $limit != $conf->liste_limit) $param.='&limit='.$limit; - - print load_fiche_titre($langs->trans("ActionsOnCompany"),'',''); + print_barre_liste($langs->trans("ActionsOnCompany"), 0, $_SERVER["PHP_SELF"], '', $sortfield, $sortorder, $morehtmlcenter, 0, -1, '', '', '', '', 0, 1, 1); // List of all actions $filters=array(); diff --git a/htdocs/societe/card.php b/htdocs/societe/card.php index dc02303e3bb..1d447a9ad0f 100644 --- a/htdocs/societe/card.php +++ b/htdocs/societe/card.php @@ -2532,12 +2532,16 @@ else print '
'; - $MAX = 5; + $MAX = 10; + + $morehtmlright = ''; + $morehtmlright.= $langs->trans("SeeAll"); + $morehtmlright.= ''; // List of actions on element include_once DOL_DOCUMENT_ROOT . '/core/class/html.formactions.class.php'; $formactions = new FormActions($db); - $somethingshown = $formactions->showactions($object, '', $socid, 1, '', $MAX); // Show all action for thirdparty + $somethingshown = $formactions->showactions($object, '', $socid, 1, '', $MAX, '', $morehtmlright); // Show all action for thirdparty print '
'; } From 9b3826a54c97338aa243e87173573feb64d5b473 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Wed, 4 Oct 2017 13:17:16 +0200 Subject: [PATCH 25/46] Invert left and right (my own comment on left) --- htdocs/core/actions_comments.inc.php | 6 ++-- htdocs/core/lib/project.lib.php | 48 ++++++++++++++-------------- htdocs/core/tpl/bloc_comment.tpl.php | 22 +++++++------ 3 files changed, 39 insertions(+), 37 deletions(-) diff --git a/htdocs/core/actions_comments.inc.php b/htdocs/core/actions_comments.inc.php index 185973cb258..ee45a035043 100644 --- a/htdocs/core/actions_comments.inc.php +++ b/htdocs/core/actions_comments.inc.php @@ -35,13 +35,13 @@ $comment = new Comment($db); if ($action == 'addcomment') { - $description = GETPOST('comment_description'); + $description = GETPOST('comment_description', 'none'); if (!empty($description)) { $comment->description = $description; $comment->datec = time(); - $comment->fk_element = GETPOST('id'); - $comment->element_type = GETPOST('comment_element_type'); + $comment->fk_element = GETPOST('id','int'); + $comment->element_type = GETPOST('comment_element_type','alpha'); $comment->fk_user_author = $user->id; $comment->entity = $conf->entity; if ($comment->create($user) > 0) diff --git a/htdocs/core/lib/project.lib.php b/htdocs/core/lib/project.lib.php index 7f809fadd77..c33ae364a2b 100644 --- a/htdocs/core/lib/project.lib.php +++ b/htdocs/core/lib/project.lib.php @@ -66,19 +66,8 @@ function project_prepare_head($object) // $this->tabs = array('entity:+tabname:Title:@mymodule:/mymodule/mypage.php?id=__ID__'); to add new tab // $this->tabs = array('entity:-tabname); to remove a tab complete_head_from_modules($conf,$langs,$object,$head,$h,'project'); - - - // Manage discussion - if (!empty($conf->global->PROJECT_ALLOW_COMMENT_ON_PROJECT)) - { - $nbComments = $object->getNbComments(); - $head[$h][0] = DOL_URL_ROOT.'/projet/comment.php?id='.$object->id; - $head[$h][1] = $langs->trans("CommentLink"); - if ($nbComments > 0) $head[$h][1].= ' '.$nbComments.''; - $head[$h][2] = 'project_comment'; - $h++; - } - + + if (empty($conf->global->MAIN_DISABLE_NOTES_TAB)) { $nbNote = 0; @@ -122,6 +111,17 @@ function project_prepare_head($object) $h++; } + // Manage discussion + if (!empty($conf->global->PROJECT_ALLOW_COMMENT_ON_PROJECT)) + { + $nbComments = $object->getNbComments(); + $head[$h][0] = DOL_URL_ROOT.'/projet/comment.php?id='.$object->id; + $head[$h][1] = $langs->trans("CommentLink"); + if ($nbComments > 0) $head[$h][1].= ' '.$nbComments.''; + $head[$h][2] = 'project_comment'; + $h++; + } + $head[$h][0] = DOL_URL_ROOT.'/projet/info.php?id='.$object->id; $head[$h][1].= $langs->trans("Events"); if (! empty($conf->agenda->enabled) && (!empty($user->rights->agenda->myactions->read) || !empty($user->rights->agenda->allactions->read) )) @@ -188,17 +188,6 @@ function task_prepare_head($object) // $this->tabs = array('entity:-tabname); to remove a tab complete_head_from_modules($conf,$langs,$object,$head,$h,'task'); - // Manage discussion - if (!empty($conf->global->PROJECT_ALLOW_COMMENT_ON_TASK)) - { - $nbComments = $object->getNbComments(); - $head[$h][0] = DOL_URL_ROOT.'/projet/tasks/comment.php?id='.$object->id.(GETPOST('withproject')?'&withproject=1':''); - $head[$h][1] = $langs->trans("CommentLink"); - if ($nbComments > 0) $head[$h][1].= ' '.$nbComments.''; - $head[$h][2] = 'task_comment'; - $h++; - } - if (empty($conf->global->MAIN_DISABLE_NOTES_TAB)) { $nbNote = 0; @@ -222,6 +211,17 @@ function task_prepare_head($object) $head[$h][2] = 'task_document'; $h++; + // Manage discussion + if (!empty($conf->global->PROJECT_ALLOW_COMMENT_ON_TASK)) + { + $nbComments = $object->getNbComments(); + $head[$h][0] = DOL_URL_ROOT.'/projet/tasks/comment.php?id='.$object->id.(GETPOST('withproject')?'&withproject=1':''); + $head[$h][1] = $langs->trans("CommentLink"); + if ($nbComments > 0) $head[$h][1].= ' '.$nbComments.''; + $head[$h][2] = 'task_comment'; + $h++; + } + complete_head_from_modules($conf,$langs,$object,$head,$h,'task','remove'); return $head; diff --git a/htdocs/core/tpl/bloc_comment.tpl.php b/htdocs/core/tpl/bloc_comment.tpl.php index b28699744d2..48b0e0c990f 100644 --- a/htdocs/core/tpl/bloc_comment.tpl.php +++ b/htdocs/core/tpl/bloc_comment.tpl.php @@ -29,10 +29,9 @@ print ''; print "\n"; print ''; -print ''; // Description -print ''; print '
'.$ref.''.$label.''; + if (! empty($action->userownerid)) + { + $userstatic->fetch($action->userownerid); // TODO Introduce a cache on users fetched + print $userstatic->getNomUrl(-1, '', 0, 0, 16, 0, '', ''); + } + print ''; if (! empty($conf->global->AGENDA_USE_EVENT_TYPE)) { if ($action->type_picto) print img_picto('', $action->type_picto); @@ -242,6 +249,7 @@ class FormActions } print $action->type; print ''.$label.''.dol_print_date($action->datep,'dayhour'); if ($action->datef) { @@ -254,13 +262,6 @@ class FormActions else print '-'.dol_print_date($action->datef,'dayhour'); } print ''; - if (! empty($action->userownerid)) - { - $userstatic->fetch($action->userownerid); // TODO Introduce a cache on users fetched - print $userstatic->getNomUrl(-1, '', 0, 0, 16, 0, '', ''); - } - print ''; if (! empty($action->author->id)) { diff --git a/htdocs/core/lib/company.lib.php b/htdocs/core/lib/company.lib.php index f22da301ec4..b269a9c1e42 100644 --- a/htdocs/core/lib/company.lib.php +++ b/htdocs/core/lib/company.lib.php @@ -1287,11 +1287,11 @@ function show_actions_done($conf, $langs, $db, $filterobj, $objcon='', $noprint= } $out.=''; $out.=$formactions->select_type_actions($actioncode, "actioncode", '', empty($conf->global->AGENDA_USE_EVENT_TYPE)?1:-1, 0, 0, 1); $out.=''; + if (! empty($conf->global->AGENDA_USE_EVENT_TYPE)) + { + if ($histo[$key]['apicto']) $out.=img_picto('', $histo[$key]['apicto']); + else { + if ($histo[$key]['acode'] == 'AC_TEL') $out.=img_picto('', 'object_phoning').' '; + if ($histo[$key]['acode'] == 'AC_FAX') $out.=img_picto('', 'object_phoning_fax').' '; + if ($histo[$key]['acode'] == 'AC_EMAIL') $out.=img_picto('', 'object_email').' '; + } + $out.=$actionstatic->type; + } + else { + $typelabel = $actionstatic->type; + if ($histo[$key]['acode'] != 'AC_OTH_AUTO') $typelabel = $langs->trans("ActionAC_MANUAL"); + $out.=$typelabel; + } + $out.=''; if (isset($histo[$key]['type']) && $histo[$key]['type']=='action') @@ -1392,25 +1411,6 @@ function show_actions_done($conf, $langs, $db, $filterobj, $objcon='', $noprint= if ($late) $out.=img_warning($langs->trans("Late")).' '; $out.="'; - if (! empty($conf->global->AGENDA_USE_EVENT_TYPE)) - { - if ($histo[$key]['apicto']) $out.=img_picto('', $histo[$key]['apicto']); - else { - if ($histo[$key]['acode'] == 'AC_TEL') $out.=img_picto('', 'object_phoning').' '; - if ($histo[$key]['acode'] == 'AC_FAX') $out.=img_picto('', 'object_phoning_fax').' '; - if ($histo[$key]['acode'] == 'AC_EMAIL') $out.=img_picto('', 'object_email').' '; - } - $out.=$actionstatic->type; - } - else { - $typelabel = $actionstatic->type; - if ($histo[$key]['acode'] != 'AC_OTH_AUTO') $typelabel = $langs->trans("ActionAC_MANUAL"); - $out.=$typelabel; - } - $out.=''.dol_trunc($histo[$key]['note'], 40).''; $return.= '
'.$titre.'
'; $return.= '
'.$morehtmlcenter.''.$morehtmlright.'
'.$langs->trans("Label").''; - print ''; + print ''; print '
'; +print ''; $desc = GETPOST('comment_description'); @@ -47,13 +46,16 @@ print '
'; // List of comments -if(!empty($object->comments)) { +if (!empty($object->comments)) +{ // Default color for current user $TColors = array($user->id => array('bgcolor'=>'efefef','color'=>'555')); $first = true; - foreach($object->comments as $comment) { + foreach($object->comments as $comment) + { $fk_user = $comment->fk_user_author; $userstatic->fetch($fk_user); + if(empty($TColors[$fk_user])) { $bgcolor = random_color(180,240); if(!empty($userstatic->color)) { @@ -63,10 +65,10 @@ if(!empty($object->comments)) { $TColors[$fk_user] = array('bgcolor'=>$bgcolor,'color'=>$color); } print '
'; - if($fk_user == $user->id) { + if ($fk_user != $user->id) { print '
 
'; } - + print '
'; print '
'; if (! empty($user->photo)) @@ -76,7 +78,7 @@ if(!empty($object->comments)) { print $langs->trans('User').' : '.$userstatic->getNomUrl().'
'; print $langs->trans('Date').' : '.dol_print_date($comment->datec,'dayhoursec'); print '
'; // End comment-info - + print '
'; print '
'; print '
'; @@ -90,13 +92,13 @@ if(!empty($object->comments)) { print '
'; // End comment-table print '
'; // End comment-right print '
'; // End comment - - if($fk_user != $user->id) { + + if($fk_user == $user->id) { print '
 
'; } print '
'; print '
'; // end 100p - + $first = false; } } From 10142522e07f58ac91e101d8e6504311e11ed0ab Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Wed, 4 Oct 2017 13:30:43 +0200 Subject: [PATCH 26/46] Fix typo --- htdocs/langs/en_US/admin.lang | 2 +- htdocs/theme/eldy/style.css.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/htdocs/langs/en_US/admin.lang b/htdocs/langs/en_US/admin.lang index bd868cf4e9e..a531186beff 100644 --- a/htdocs/langs/en_US/admin.lang +++ b/htdocs/langs/en_US/admin.lang @@ -584,7 +584,7 @@ Module3100Desc=Add a Skype button into users / third parties / contacts / member Module3200Name=Non Reversible Logs Module3200Desc=Activate log of some business events into a non reversible log. Events are archived in real-time. The log is a table of chained event that can be then read and exported. This module may be mandatory for some countries. Module4000Name=HRM -Module4000Desc=Human resources management (mangement of department, employee contracts and feelings) +Module4000Desc=Human resources management (management of department, employee contracts and feelings) Module5000Name=Multi-company Module5000Desc=Allows you to manage multiple companies Module6000Name=Workflow diff --git a/htdocs/theme/eldy/style.css.php b/htdocs/theme/eldy/style.css.php index 36a92396d3e..e7a3480b992 100644 --- a/htdocs/theme/eldy/style.css.php +++ b/htdocs/theme/eldy/style.css.php @@ -2063,7 +2063,7 @@ div.tabBar { background: rgb(); } div.tabBar div.titre { - padding-top: 10px; + padding-top: 20px; } div.tabBarWithBottom { From a74d6074a351628907eaa4320313910290b381a6 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Wed, 4 Oct 2017 14:27:10 +0200 Subject: [PATCH 27/46] FIX Generation of invoice from bulk action "Bill Orders" --- htdocs/commande/list.php | 248 +++++++++--------- htdocs/compta/facture/class/facture.class.php | 7 +- htdocs/core/actions_builddoc.inc.php | 9 +- .../fourn/class/fournisseur.facture.class.php | 4 + htdocs/fourn/commande/list.php | 238 ++++++++--------- 5 files changed, 256 insertions(+), 250 deletions(-) diff --git a/htdocs/commande/list.php b/htdocs/commande/list.php index fed61c1fc17..c5cc5f9b715 100644 --- a/htdocs/commande/list.php +++ b/htdocs/commande/list.php @@ -213,7 +213,7 @@ if (empty($reshook)) // TODO Move this into mass action include if ($massaction == 'confirm_createbills') { - $orders = GETPOST('toselect'); + $orders = GETPOST('toselect','array'); $createbills_onebythird = GETPOST('createbills_onebythird', 'int'); $validate_invoices = GETPOST('valdate_invoices', 'int'); @@ -224,13 +224,13 @@ if (empty($reshook)) $db->begin(); - foreach($orders as $id_order) { - + foreach($orders as $id_order) + { $cmd = new Commande($db); - if($cmd->fetch($id_order) <= 0) continue; + if ($cmd->fetch($id_order) <= 0) continue; $object = new Facture($db); - if(!empty($createbills_onebythird) && !empty($TFactThird[$cmd->socid])) $object = $TFactThird[$cmd->socid]; // If option "one bill per third" is set, we use already created order. + if (!empty($createbills_onebythird) && !empty($TFactThird[$cmd->socid])) $object = $TFactThird[$cmd->socid]; // If option "one bill per third" is set, we use already created order. else { $object->socid = $cmd->socid; @@ -252,12 +252,10 @@ if (empty($reshook)) $res = $object->create($user); if($res > 0) $nb_bills_created++; - } - if($object->id > 0) { - - $db->begin(); + if ($object->id > 0) + { $sql = "INSERT INTO ".MAIN_DB_PREFIX."element_element ("; $sql.= "fk_source"; $sql.= ", sourcetype"; @@ -270,115 +268,113 @@ if (empty($reshook)) $sql.= ", '".$object->element."'"; $sql.= ")"; - if ($db->query($sql)) + if (! $db->query($sql)) { - $db->commit(); - } - else - { - $db->rollback(); + $error++; } - $lines = $cmd->lines; - if (empty($lines) && method_exists($cmd, 'fetch_lines')) + if (! $error) { - $cmd->fetch_lines(); - $lines = $cmd->lines; + $lines = $cmd->lines; + if (empty($lines) && method_exists($cmd, 'fetch_lines')) + { + $cmd->fetch_lines(); + $lines = $cmd->lines; + } + + $fk_parent_line=0; + $num=count($lines); + + for ($i=0;$i<$num;$i++) + { + $desc=($lines[$i]->desc?$lines[$i]->desc:$lines[$i]->libelle); + if ($lines[$i]->subprice < 0) + { + // Negative line, we create a discount line + $discount = new DiscountAbsolute($db); + $discount->fk_soc=$object->socid; + $discount->amount_ht=abs($lines[$i]->total_ht); + $discount->amount_tva=abs($lines[$i]->total_tva); + $discount->amount_ttc=abs($lines[$i]->total_ttc); + $discount->tva_tx=$lines[$i]->tva_tx; + $discount->fk_user=$user->id; + $discount->description=$desc; + $discountid=$discount->create($user); + if ($discountid > 0) + { + $result=$object->insert_discount($discountid); + //$result=$discount->link_to_invoice($lineid,$id); + } + else + { + setEventMessages($discount->error, $discount->errors, 'errors'); + $error++; + break; + } + } + else + { + // Positive line + $product_type=($lines[$i]->product_type?$lines[$i]->product_type:0); + // Date start + $date_start=false; + if ($lines[$i]->date_debut_prevue) $date_start=$lines[$i]->date_debut_prevue; + if ($lines[$i]->date_debut_reel) $date_start=$lines[$i]->date_debut_reel; + if ($lines[$i]->date_start) $date_start=$lines[$i]->date_start; + //Date end + $date_end=false; + if ($lines[$i]->date_fin_prevue) $date_end=$lines[$i]->date_fin_prevue; + if ($lines[$i]->date_fin_reel) $date_end=$lines[$i]->date_fin_reel; + if ($lines[$i]->date_end) $date_end=$lines[$i]->date_end; + // Reset fk_parent_line for no child products and special product + if (($lines[$i]->product_type != 9 && empty($lines[$i]->fk_parent_line)) || $lines[$i]->product_type == 9) + { + $fk_parent_line = 0; + } + $result = $object->addline( + $desc, + $lines[$i]->subprice, + $lines[$i]->qty, + $lines[$i]->tva_tx, + $lines[$i]->localtax1_tx, + $lines[$i]->localtax2_tx, + $lines[$i]->fk_product, + $lines[$i]->remise_percent, + $date_start, + $date_end, + 0, + $lines[$i]->info_bits, + $lines[$i]->fk_remise_except, + 'HT', + 0, + $product_type, + $ii, + $lines[$i]->special_code, + $object->origin, + $lines[$i]->rowid, + $fk_parent_line, + $lines[$i]->fk_fournprice, + $lines[$i]->pa_ht, + $lines[$i]->label + ); + if ($result > 0) + { + $lineid=$result; + } + else + { + $lineid=0; + $error++; + break; + } + // Defined the new fk_parent_line + if ($result > 0 && $lines[$i]->product_type == 9) + { + $fk_parent_line = $result; + } + } + } } - - $fk_parent_line=0; - $num=count($lines); - - for ($i=0;$i<$num;$i++) - { - $desc=($lines[$i]->desc?$lines[$i]->desc:$lines[$i]->libelle); - if ($lines[$i]->subprice < 0) - { - // Negative line, we create a discount line - $discount = new DiscountAbsolute($db); - $discount->fk_soc=$object->socid; - $discount->amount_ht=abs($lines[$i]->total_ht); - $discount->amount_tva=abs($lines[$i]->total_tva); - $discount->amount_ttc=abs($lines[$i]->total_ttc); - $discount->tva_tx=$lines[$i]->tva_tx; - $discount->fk_user=$user->id; - $discount->description=$desc; - $discountid=$discount->create($user); - if ($discountid > 0) - { - $result=$object->insert_discount($discountid); - //$result=$discount->link_to_invoice($lineid,$id); - } - else - { - setEventMessages($discount->error, $discount->errors, 'errors'); - $error++; - break; - } - } - else - { - // Positive line - $product_type=($lines[$i]->product_type?$lines[$i]->product_type:0); - // Date start - $date_start=false; - if ($lines[$i]->date_debut_prevue) $date_start=$lines[$i]->date_debut_prevue; - if ($lines[$i]->date_debut_reel) $date_start=$lines[$i]->date_debut_reel; - if ($lines[$i]->date_start) $date_start=$lines[$i]->date_start; - //Date end - $date_end=false; - if ($lines[$i]->date_fin_prevue) $date_end=$lines[$i]->date_fin_prevue; - if ($lines[$i]->date_fin_reel) $date_end=$lines[$i]->date_fin_reel; - if ($lines[$i]->date_end) $date_end=$lines[$i]->date_end; - // Reset fk_parent_line for no child products and special product - if (($lines[$i]->product_type != 9 && empty($lines[$i]->fk_parent_line)) || $lines[$i]->product_type == 9) - { - $fk_parent_line = 0; - } - $result = $object->addline( - $desc, - $lines[$i]->subprice, - $lines[$i]->qty, - $lines[$i]->tva_tx, - $lines[$i]->localtax1_tx, - $lines[$i]->localtax2_tx, - $lines[$i]->fk_product, - $lines[$i]->remise_percent, - $date_start, - $date_end, - 0, - $lines[$i]->info_bits, - $lines[$i]->fk_remise_except, - 'HT', - 0, - $product_type, - $ii, - $lines[$i]->special_code, - $object->origin, - $lines[$i]->rowid, - $fk_parent_line, - $lines[$i]->fk_fournprice, - $lines[$i]->pa_ht, - $lines[$i]->label - ); - if ($result > 0) - { - $lineid=$result; - } - else - { - $lineid=0; - $error++; - break; - } - // Defined the new fk_parent_line - if ($result > 0 && $lines[$i]->product_type == 9) - { - $fk_parent_line = $result; - } - } - } - } //$cmd->classifyBilled($user); // Disabled. This behavior must be set or not using the workflow module. @@ -391,27 +387,29 @@ if (empty($reshook)) $TAllFact = empty($createbills_onebythird) ? $TFact : $TFactThird; $toselect = array(); - if(!empty($validate_invoices)) { - + if (! $error && $validate_invoices) + { $massaction = $action = 'builddoc'; + foreach($TAllFact as &$object) + { + $result = $object->validate($user); + if ($result <= 0) + { + $error++; + setEventMessages($object->error, $object->errors, 'errors'); + break; + } - foreach($TAllFact as &$object) { - $object->validate($user); - $toselect[] = $object->id; // For builddoc action + $id = $object->id; // For builddoc action // Fac builddoc + $donotredirect = 1; $upload_dir = $conf->facture->dir_output; $permissioncreate=$user->rights->facture->creer; include DOL_DOCUMENT_ROOT.'/core/actions_builddoc.inc.php'; } - $objectclass='Facture'; - $objectlabel='Invoice'; - $permtoread = $user->rights->facture->lire; - $permtodelete = $user->rights->facture->supprimer; - $uploaddir = $conf->facture->dir_output; - include DOL_DOCUMENT_ROOT.'/core/actions_massactions.inc.php'; - + $massaction = $action = 'confirm_createbills'; } if (! $error) diff --git a/htdocs/compta/facture/class/facture.class.php b/htdocs/compta/facture/class/facture.class.php index d853ea03138..fcf41e090cc 100644 --- a/htdocs/compta/facture/class/facture.class.php +++ b/htdocs/compta/facture/class/facture.class.php @@ -2097,6 +2097,10 @@ class Facture extends CommonInvoice $error=0; dol_syslog(get_class($this).'::validate user='.$user->id.', force_number='.$force_number.', idwarehouse='.$idwarehouse); + // Force to have object complete for checks + $this->fetch_thirdparty(); + $this->fetch_lines(); + // Check parameters if (! $this->brouillon) { @@ -2119,9 +2123,6 @@ class Facture extends CommonInvoice $this->db->begin(); - $this->fetch_thirdparty(); - $this->fetch_lines(); - // Check parameters if ($this->type == self::TYPE_REPLACEMENT) // si facture de remplacement { diff --git a/htdocs/core/actions_builddoc.inc.php b/htdocs/core/actions_builddoc.inc.php index a1ff6417f92..bd86c5cb80c 100644 --- a/htdocs/core/actions_builddoc.inc.php +++ b/htdocs/core/actions_builddoc.inc.php @@ -91,10 +91,13 @@ if ($action == 'builddoc' && $permissioncreate) } else { - setEventMessages($langs->trans("FileGenerated"), null); + if (empty($donotredirect)) // This is se when include is done by bulk action "Bill Orders" + { + setEventMessages($langs->trans("FileGenerated"), null); - header('Location: '.$_SERVER['REQUEST_URI'].'#builddoc'); - exit; + header('Location: '.$_SERVER['REQUEST_URI'].'#builddoc'); + exit; + } } } } diff --git a/htdocs/fourn/class/fournisseur.facture.class.php b/htdocs/fourn/class/fournisseur.facture.class.php index 5e9974b26d5..72d1d232eca 100644 --- a/htdocs/fourn/class/fournisseur.facture.class.php +++ b/htdocs/fourn/class/fournisseur.facture.class.php @@ -1090,6 +1090,10 @@ class FactureFournisseur extends CommonInvoice $error=0; dol_syslog(get_class($this).'::validate user='.$user->id.', force_number='.$force_number.', idwarehouse='.$idwarehouse); + // Force to have object complete for checks + $this->fetch_thirdparty(); + $this->fetch_lines(); + // Check parameters if ($this->statut > self::STATUS_DRAFT) // This is to avoid to validate twice (avoid errors on logs and stock management) { diff --git a/htdocs/fourn/commande/list.php b/htdocs/fourn/commande/list.php index 4b7bcb454cd..ace85e8a3e8 100644 --- a/htdocs/fourn/commande/list.php +++ b/htdocs/fourn/commande/list.php @@ -232,7 +232,7 @@ if (empty($reshook)) // TODO Move this into mass action include if ($massaction == 'confirm_createbills') { - $orders = GETPOST('toselect'); + $orders = GETPOST('toselect','array'); $createbills_onebythird = GETPOST('createbills_onebythird', 'int'); $validate_invoices = GETPOST('valdate_invoices', 'int'); @@ -274,9 +274,8 @@ if (empty($reshook)) } - if($object->id > 0) { - - $db->begin(); + if ($object->id > 0) + { $sql = "INSERT INTO ".MAIN_DB_PREFIX."element_element ("; $sql.= "fk_source"; $sql.= ", sourcetype"; @@ -289,118 +288,116 @@ if (empty($reshook)) $sql.= ", '".$object->element."'"; $sql.= ")"; - if ($db->query($sql)) + if (! $db->query($sql)) { - $db->commit(); - } - else - { - $db->rollback(); + $erorr++; } - $lines = $cmd->lines; - if (empty($lines) && method_exists($cmd, 'fetch_lines')) + if (! $error) { - $cmd->fetch_lines(); - $lines = $cmd->lines; + $lines = $cmd->lines; + if (empty($lines) && method_exists($cmd, 'fetch_lines')) + { + $cmd->fetch_lines(); + $lines = $cmd->lines; + } + + $fk_parent_line=0; + $num=count($lines); + + for ($i=0;$i<$num;$i++) + { + $desc=($lines[$i]->desc?$lines[$i]->desc:$lines[$i]->libelle); + if ($lines[$i]->subprice < 0) + { + // Negative line, we create a discount line + $discount = new DiscountAbsolute($db); + $discount->fk_soc=$object->socid; + $discount->amount_ht=abs($lines[$i]->total_ht); + $discount->amount_tva=abs($lines[$i]->total_tva); + $discount->amount_ttc=abs($lines[$i]->total_ttc); + $discount->tva_tx=$lines[$i]->tva_tx; + $discount->fk_user=$user->id; + $discount->description=$desc; + $discountid=$discount->create($user); + if ($discountid > 0) + { + $result=$object->insert_discount($discountid); + //$result=$discount->link_to_invoice($lineid,$id); + } + else + { + setEventMessages($discount->error, $discount->errors, 'errors'); + $error++; + break; + } + } + else + { + // Positive line + $product_type=($lines[$i]->product_type?$lines[$i]->product_type:0); + // Date start + $date_start=false; + if ($lines[$i]->date_debut_prevue) $date_start=$lines[$i]->date_debut_prevue; + if ($lines[$i]->date_debut_reel) $date_start=$lines[$i]->date_debut_reel; + if ($lines[$i]->date_start) $date_start=$lines[$i]->date_start; + //Date end + $date_end=false; + if ($lines[$i]->date_fin_prevue) $date_end=$lines[$i]->date_fin_prevue; + if ($lines[$i]->date_fin_reel) $date_end=$lines[$i]->date_fin_reel; + if ($lines[$i]->date_end) $date_end=$lines[$i]->date_end; + // Reset fk_parent_line for no child products and special product + if (($lines[$i]->product_type != 9 && empty($lines[$i]->fk_parent_line)) || $lines[$i]->product_type == 9) + { + $fk_parent_line = 0; + } + $result = $object->addline( + $desc, + $lines[$i]->subprice, + $lines[$i]->qty, + $lines[$i]->tva_tx, + $lines[$i]->localtax1_tx, + $lines[$i]->localtax2_tx, + $lines[$i]->fk_product, + $lines[$i]->remise_percent, + $date_start, + $date_end, + 0, + $lines[$i]->info_bits, + $lines[$i]->fk_remise_except, + 'HT', + 0, + $product_type, + $ii, + $lines[$i]->special_code, + $object->origin, + $lines[$i]->rowid, + $fk_parent_line, + $lines[$i]->fk_fournprice, + $lines[$i]->pa_ht, + $lines[$i]->label + ); + if ($result > 0) + { + $lineid=$result; + } + else + { + $lineid=0; + $error++; + break; + } + // Defined the new fk_parent_line + if ($result > 0 && $lines[$i]->product_type == 9) + { + $fk_parent_line = $result; + } + } + } } - - $fk_parent_line=0; - $num=count($lines); - - for ($i=0;$i<$num;$i++) - { - $desc=($lines[$i]->desc?$lines[$i]->desc:$lines[$i]->libelle); - if ($lines[$i]->subprice < 0) - { - // Negative line, we create a discount line - $discount = new DiscountAbsolute($db); - $discount->fk_soc=$object->socid; - $discount->amount_ht=abs($lines[$i]->total_ht); - $discount->amount_tva=abs($lines[$i]->total_tva); - $discount->amount_ttc=abs($lines[$i]->total_ttc); - $discount->tva_tx=$lines[$i]->tva_tx; - $discount->fk_user=$user->id; - $discount->description=$desc; - $discountid=$discount->create($user); - if ($discountid > 0) - { - $result=$object->insert_discount($discountid); - //$result=$discount->link_to_invoice($lineid,$id); - } - else - { - setEventMessages($discount->error, $discount->errors, 'errors'); - $error++; - break; - } - } - else - { - // Positive line - $product_type=($lines[$i]->product_type?$lines[$i]->product_type:0); - // Date start - $date_start=false; - if ($lines[$i]->date_debut_prevue) $date_start=$lines[$i]->date_debut_prevue; - if ($lines[$i]->date_debut_reel) $date_start=$lines[$i]->date_debut_reel; - if ($lines[$i]->date_start) $date_start=$lines[$i]->date_start; - //Date end - $date_end=false; - if ($lines[$i]->date_fin_prevue) $date_end=$lines[$i]->date_fin_prevue; - if ($lines[$i]->date_fin_reel) $date_end=$lines[$i]->date_fin_reel; - if ($lines[$i]->date_end) $date_end=$lines[$i]->date_end; - // Reset fk_parent_line for no child products and special product - if (($lines[$i]->product_type != 9 && empty($lines[$i]->fk_parent_line)) || $lines[$i]->product_type == 9) - { - $fk_parent_line = 0; - } - $result = $object->addline( - $desc, - $lines[$i]->subprice, - $lines[$i]->qty, - $lines[$i]->tva_tx, - $lines[$i]->localtax1_tx, - $lines[$i]->localtax2_tx, - $lines[$i]->fk_product, - $lines[$i]->remise_percent, - $date_start, - $date_end, - 0, - $lines[$i]->info_bits, - $lines[$i]->fk_remise_except, - 'HT', - 0, - $product_type, - $ii, - $lines[$i]->special_code, - $object->origin, - $lines[$i]->rowid, - $fk_parent_line, - $lines[$i]->fk_fournprice, - $lines[$i]->pa_ht, - $lines[$i]->label - ); - if ($result > 0) - { - $lineid=$result; - } - else - { - $lineid=0; - $error++; - break; - } - // Defined the new fk_parent_line - if ($result > 0 && $lines[$i]->product_type == 9) - { - $fk_parent_line = $result; - } - } - } - } - $cmd->classifyBilled($user); + $cmd->classifyBilled($user); // TODO Move this in workflow like done for customer orders if(!empty($createbills_onebythird) && empty($TFactThird[$cmd->socid])) $TFactThird[$cmd->socid] = $object; else $TFact[$object->id] = $object; @@ -410,27 +407,30 @@ if (empty($reshook)) $TAllFact = empty($createbills_onebythird) ? $TFact : $TFactThird; $toselect = array(); - if(!empty($validate_invoices)) { + if (! $error && $validate_invoices) { $massaction = $action = 'builddoc'; - foreach($TAllFact as &$object) { + foreach($TAllFact as &$object) + { $object->validate($user); - $toselect[] = $object->id; // For builddoc action + if ($result <= 0) + { + $error++; + setEventMessages($object->error, $object->errors, 'errors'); + break; + } + + $id = $object->id; // For builddoc action // Fac builddoc + $donotredirect = 1; $upload_dir = $conf->facture->dir_output; $permissioncreate=$user->rights->facture->creer; include DOL_DOCUMENT_ROOT.'/core/actions_builddoc.inc.php'; } - $objectclass='Facture'; - $objectlabel='Invoice'; - $permtoread = $user->rights->facture->lire; - $permtodelete = $user->rights->facture->supprimer; - $uploaddir = $conf->facture->dir_output; - include DOL_DOCUMENT_ROOT.'/core/actions_massactions.inc.php'; - + $massaction = $action = 'confirm_createbills'; } if (! $error) From d28188d19ddaf57290a854518f829f53e0be5bad Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Wed, 4 Oct 2017 14:27:10 +0200 Subject: [PATCH 28/46] FIX Generation of invoice from bulk action "Bill Orders" Conflicts: htdocs/fourn/class/fournisseur.facture.class.php --- htdocs/commande/list.php | 248 +++++++++--------- htdocs/compta/facture/class/facture.class.php | 7 +- htdocs/core/actions_builddoc.inc.php | 9 +- .../fourn/class/fournisseur.facture.class.php | 6 +- htdocs/fourn/commande/list.php | 238 ++++++++--------- 5 files changed, 257 insertions(+), 251 deletions(-) diff --git a/htdocs/commande/list.php b/htdocs/commande/list.php index 8810a1be986..1efd428159a 100644 --- a/htdocs/commande/list.php +++ b/htdocs/commande/list.php @@ -208,7 +208,7 @@ if (empty($reshook)) // TODO Move this into mass action include if ($massaction == 'confirm_createbills') { - $orders = GETPOST('toselect'); + $orders = GETPOST('toselect','array'); $createbills_onebythird = GETPOST('createbills_onebythird', 'int'); $validate_invoices = GETPOST('valdate_invoices', 'int'); @@ -219,13 +219,13 @@ if (empty($reshook)) $db->begin(); - foreach($orders as $id_order) { - + foreach($orders as $id_order) + { $cmd = new Commande($db); - if($cmd->fetch($id_order) <= 0) continue; + if ($cmd->fetch($id_order) <= 0) continue; $object = new Facture($db); - if(!empty($createbills_onebythird) && !empty($TFactThird[$cmd->socid])) $object = $TFactThird[$cmd->socid]; // If option "one bill per third" is set, we use already created order. + if (!empty($createbills_onebythird) && !empty($TFactThird[$cmd->socid])) $object = $TFactThird[$cmd->socid]; // If option "one bill per third" is set, we use already created order. else { $object->socid = $cmd->socid; @@ -247,12 +247,10 @@ if (empty($reshook)) $res = $object->create($user); if($res > 0) $nb_bills_created++; - } - if($object->id > 0) { - - $db->begin(); + if ($object->id > 0) + { $sql = "INSERT INTO ".MAIN_DB_PREFIX."element_element ("; $sql.= "fk_source"; $sql.= ", sourcetype"; @@ -265,115 +263,113 @@ if (empty($reshook)) $sql.= ", '".$object->element."'"; $sql.= ")"; - if ($db->query($sql)) + if (! $db->query($sql)) { - $db->commit(); - } - else - { - $db->rollback(); + $error++; } - $lines = $cmd->lines; - if (empty($lines) && method_exists($cmd, 'fetch_lines')) + if (! $error) { - $cmd->fetch_lines(); - $lines = $cmd->lines; + $lines = $cmd->lines; + if (empty($lines) && method_exists($cmd, 'fetch_lines')) + { + $cmd->fetch_lines(); + $lines = $cmd->lines; + } + + $fk_parent_line=0; + $num=count($lines); + + for ($i=0;$i<$num;$i++) + { + $desc=($lines[$i]->desc?$lines[$i]->desc:$lines[$i]->libelle); + if ($lines[$i]->subprice < 0) + { + // Negative line, we create a discount line + $discount = new DiscountAbsolute($db); + $discount->fk_soc=$object->socid; + $discount->amount_ht=abs($lines[$i]->total_ht); + $discount->amount_tva=abs($lines[$i]->total_tva); + $discount->amount_ttc=abs($lines[$i]->total_ttc); + $discount->tva_tx=$lines[$i]->tva_tx; + $discount->fk_user=$user->id; + $discount->description=$desc; + $discountid=$discount->create($user); + if ($discountid > 0) + { + $result=$object->insert_discount($discountid); + //$result=$discount->link_to_invoice($lineid,$id); + } + else + { + setEventMessages($discount->error, $discount->errors, 'errors'); + $error++; + break; + } + } + else + { + // Positive line + $product_type=($lines[$i]->product_type?$lines[$i]->product_type:0); + // Date start + $date_start=false; + if ($lines[$i]->date_debut_prevue) $date_start=$lines[$i]->date_debut_prevue; + if ($lines[$i]->date_debut_reel) $date_start=$lines[$i]->date_debut_reel; + if ($lines[$i]->date_start) $date_start=$lines[$i]->date_start; + //Date end + $date_end=false; + if ($lines[$i]->date_fin_prevue) $date_end=$lines[$i]->date_fin_prevue; + if ($lines[$i]->date_fin_reel) $date_end=$lines[$i]->date_fin_reel; + if ($lines[$i]->date_end) $date_end=$lines[$i]->date_end; + // Reset fk_parent_line for no child products and special product + if (($lines[$i]->product_type != 9 && empty($lines[$i]->fk_parent_line)) || $lines[$i]->product_type == 9) + { + $fk_parent_line = 0; + } + $result = $object->addline( + $desc, + $lines[$i]->subprice, + $lines[$i]->qty, + $lines[$i]->tva_tx, + $lines[$i]->localtax1_tx, + $lines[$i]->localtax2_tx, + $lines[$i]->fk_product, + $lines[$i]->remise_percent, + $date_start, + $date_end, + 0, + $lines[$i]->info_bits, + $lines[$i]->fk_remise_except, + 'HT', + 0, + $product_type, + $ii, + $lines[$i]->special_code, + $object->origin, + $lines[$i]->rowid, + $fk_parent_line, + $lines[$i]->fk_fournprice, + $lines[$i]->pa_ht, + $lines[$i]->label + ); + if ($result > 0) + { + $lineid=$result; + } + else + { + $lineid=0; + $error++; + break; + } + // Defined the new fk_parent_line + if ($result > 0 && $lines[$i]->product_type == 9) + { + $fk_parent_line = $result; + } + } + } } - - $fk_parent_line=0; - $num=count($lines); - - for ($i=0;$i<$num;$i++) - { - $desc=($lines[$i]->desc?$lines[$i]->desc:$lines[$i]->libelle); - if ($lines[$i]->subprice < 0) - { - // Negative line, we create a discount line - $discount = new DiscountAbsolute($db); - $discount->fk_soc=$object->socid; - $discount->amount_ht=abs($lines[$i]->total_ht); - $discount->amount_tva=abs($lines[$i]->total_tva); - $discount->amount_ttc=abs($lines[$i]->total_ttc); - $discount->tva_tx=$lines[$i]->tva_tx; - $discount->fk_user=$user->id; - $discount->description=$desc; - $discountid=$discount->create($user); - if ($discountid > 0) - { - $result=$object->insert_discount($discountid); - //$result=$discount->link_to_invoice($lineid,$id); - } - else - { - setEventMessages($discount->error, $discount->errors, 'errors'); - $error++; - break; - } - } - else - { - // Positive line - $product_type=($lines[$i]->product_type?$lines[$i]->product_type:0); - // Date start - $date_start=false; - if ($lines[$i]->date_debut_prevue) $date_start=$lines[$i]->date_debut_prevue; - if ($lines[$i]->date_debut_reel) $date_start=$lines[$i]->date_debut_reel; - if ($lines[$i]->date_start) $date_start=$lines[$i]->date_start; - //Date end - $date_end=false; - if ($lines[$i]->date_fin_prevue) $date_end=$lines[$i]->date_fin_prevue; - if ($lines[$i]->date_fin_reel) $date_end=$lines[$i]->date_fin_reel; - if ($lines[$i]->date_end) $date_end=$lines[$i]->date_end; - // Reset fk_parent_line for no child products and special product - if (($lines[$i]->product_type != 9 && empty($lines[$i]->fk_parent_line)) || $lines[$i]->product_type == 9) - { - $fk_parent_line = 0; - } - $result = $object->addline( - $desc, - $lines[$i]->subprice, - $lines[$i]->qty, - $lines[$i]->tva_tx, - $lines[$i]->localtax1_tx, - $lines[$i]->localtax2_tx, - $lines[$i]->fk_product, - $lines[$i]->remise_percent, - $date_start, - $date_end, - 0, - $lines[$i]->info_bits, - $lines[$i]->fk_remise_except, - 'HT', - 0, - $product_type, - $ii, - $lines[$i]->special_code, - $object->origin, - $lines[$i]->rowid, - $fk_parent_line, - $lines[$i]->fk_fournprice, - $lines[$i]->pa_ht, - $lines[$i]->label - ); - if ($result > 0) - { - $lineid=$result; - } - else - { - $lineid=0; - $error++; - break; - } - // Defined the new fk_parent_line - if ($result > 0 && $lines[$i]->product_type == 9) - { - $fk_parent_line = $result; - } - } - } - } //$cmd->classifyBilled($user); // Disabled. This behavior must be set or not using the workflow module. @@ -386,27 +382,29 @@ if (empty($reshook)) $TAllFact = empty($createbills_onebythird) ? $TFact : $TFactThird; $toselect = array(); - if(!empty($validate_invoices)) { - + if (! $error && $validate_invoices) + { $massaction = $action = 'builddoc'; + foreach($TAllFact as &$object) + { + $result = $object->validate($user); + if ($result <= 0) + { + $error++; + setEventMessages($object->error, $object->errors, 'errors'); + break; + } - foreach($TAllFact as &$object) { - $object->validate($user); - $toselect[] = $object->id; // For builddoc action + $id = $object->id; // For builddoc action // Fac builddoc + $donotredirect = 1; $upload_dir = $conf->facture->dir_output; $permissioncreate=$user->rights->facture->creer; include DOL_DOCUMENT_ROOT.'/core/actions_builddoc.inc.php'; } - $objectclass='Facture'; - $objectlabel='Invoice'; - $permtoread = $user->rights->facture->lire; - $permtodelete = $user->rights->facture->supprimer; - $uploaddir = $conf->facture->dir_output; - include DOL_DOCUMENT_ROOT.'/core/actions_massactions.inc.php'; - + $massaction = $action = 'confirm_createbills'; } if (! $error) diff --git a/htdocs/compta/facture/class/facture.class.php b/htdocs/compta/facture/class/facture.class.php index c3b58117dd7..fc019d92eea 100644 --- a/htdocs/compta/facture/class/facture.class.php +++ b/htdocs/compta/facture/class/facture.class.php @@ -2051,6 +2051,10 @@ class Facture extends CommonInvoice $error=0; dol_syslog(get_class($this).'::validate user='.$user->id.', force_number='.$force_number.', idwarehouse='.$idwarehouse); + // Force to have object complete for checks + $this->fetch_thirdparty(); + $this->fetch_lines(); + // Check parameters if (! $this->brouillon) { @@ -2068,9 +2072,6 @@ class Facture extends CommonInvoice $this->db->begin(); - $this->fetch_thirdparty(); - $this->fetch_lines(); - // Check parameters if ($this->type == self::TYPE_REPLACEMENT) // si facture de remplacement { diff --git a/htdocs/core/actions_builddoc.inc.php b/htdocs/core/actions_builddoc.inc.php index 076a7a6a035..70876d4bf9a 100644 --- a/htdocs/core/actions_builddoc.inc.php +++ b/htdocs/core/actions_builddoc.inc.php @@ -91,10 +91,13 @@ if ($action == 'builddoc' && $permissioncreate) } else { - setEventMessages($langs->trans("FileGenerated"), null); + if (empty($donotredirect)) // This is se when include is done by bulk action "Bill Orders" + { + setEventMessages($langs->trans("FileGenerated"), null); - header('Location: '.$_SERVER['REQUEST_URI'].'#builddoc'); - exit; + header('Location: '.$_SERVER['REQUEST_URI'].'#builddoc'); + exit; + } } } } diff --git a/htdocs/fourn/class/fournisseur.facture.class.php b/htdocs/fourn/class/fournisseur.facture.class.php index 8b573679f82..143d2cd5f36 100644 --- a/htdocs/fourn/class/fournisseur.facture.class.php +++ b/htdocs/fourn/class/fournisseur.facture.class.php @@ -1086,7 +1086,11 @@ class FactureFournisseur extends CommonInvoice $error=0; - // Protection + // Force to have object complete for checks + $this->fetch_thirdparty(); + $this->fetch_lines(); + + // Check parameters if ($this->statut > self::STATUS_DRAFT) // This is to avoid to validate twice (avoid errors on logs and stock management) { dol_syslog(get_class($this)."::validate no draft status", LOG_WARNING); diff --git a/htdocs/fourn/commande/list.php b/htdocs/fourn/commande/list.php index ac67d256824..706e7e22024 100644 --- a/htdocs/fourn/commande/list.php +++ b/htdocs/fourn/commande/list.php @@ -239,7 +239,7 @@ if (empty($reshook)) // TODO Move this into mass action include if ($massaction == 'confirm_createbills') { - $orders = GETPOST('toselect'); + $orders = GETPOST('toselect','array'); $createbills_onebythird = GETPOST('createbills_onebythird', 'int'); $validate_invoices = GETPOST('valdate_invoices', 'int'); @@ -281,9 +281,8 @@ if (empty($reshook)) } - if($object->id > 0) { - - $db->begin(); + if ($object->id > 0) + { $sql = "INSERT INTO ".MAIN_DB_PREFIX."element_element ("; $sql.= "fk_source"; $sql.= ", sourcetype"; @@ -296,118 +295,116 @@ if (empty($reshook)) $sql.= ", '".$object->element."'"; $sql.= ")"; - if ($db->query($sql)) + if (! $db->query($sql)) { - $db->commit(); - } - else - { - $db->rollback(); + $erorr++; } - $lines = $cmd->lines; - if (empty($lines) && method_exists($cmd, 'fetch_lines')) + if (! $error) { - $cmd->fetch_lines(); - $lines = $cmd->lines; + $lines = $cmd->lines; + if (empty($lines) && method_exists($cmd, 'fetch_lines')) + { + $cmd->fetch_lines(); + $lines = $cmd->lines; + } + + $fk_parent_line=0; + $num=count($lines); + + for ($i=0;$i<$num;$i++) + { + $desc=($lines[$i]->desc?$lines[$i]->desc:$lines[$i]->libelle); + if ($lines[$i]->subprice < 0) + { + // Negative line, we create a discount line + $discount = new DiscountAbsolute($db); + $discount->fk_soc=$object->socid; + $discount->amount_ht=abs($lines[$i]->total_ht); + $discount->amount_tva=abs($lines[$i]->total_tva); + $discount->amount_ttc=abs($lines[$i]->total_ttc); + $discount->tva_tx=$lines[$i]->tva_tx; + $discount->fk_user=$user->id; + $discount->description=$desc; + $discountid=$discount->create($user); + if ($discountid > 0) + { + $result=$object->insert_discount($discountid); + //$result=$discount->link_to_invoice($lineid,$id); + } + else + { + setEventMessages($discount->error, $discount->errors, 'errors'); + $error++; + break; + } + } + else + { + // Positive line + $product_type=($lines[$i]->product_type?$lines[$i]->product_type:0); + // Date start + $date_start=false; + if ($lines[$i]->date_debut_prevue) $date_start=$lines[$i]->date_debut_prevue; + if ($lines[$i]->date_debut_reel) $date_start=$lines[$i]->date_debut_reel; + if ($lines[$i]->date_start) $date_start=$lines[$i]->date_start; + //Date end + $date_end=false; + if ($lines[$i]->date_fin_prevue) $date_end=$lines[$i]->date_fin_prevue; + if ($lines[$i]->date_fin_reel) $date_end=$lines[$i]->date_fin_reel; + if ($lines[$i]->date_end) $date_end=$lines[$i]->date_end; + // Reset fk_parent_line for no child products and special product + if (($lines[$i]->product_type != 9 && empty($lines[$i]->fk_parent_line)) || $lines[$i]->product_type == 9) + { + $fk_parent_line = 0; + } + $result = $object->addline( + $desc, + $lines[$i]->subprice, + $lines[$i]->qty, + $lines[$i]->tva_tx, + $lines[$i]->localtax1_tx, + $lines[$i]->localtax2_tx, + $lines[$i]->fk_product, + $lines[$i]->remise_percent, + $date_start, + $date_end, + 0, + $lines[$i]->info_bits, + $lines[$i]->fk_remise_except, + 'HT', + 0, + $product_type, + $ii, + $lines[$i]->special_code, + $object->origin, + $lines[$i]->rowid, + $fk_parent_line, + $lines[$i]->fk_fournprice, + $lines[$i]->pa_ht, + $lines[$i]->label + ); + if ($result > 0) + { + $lineid=$result; + } + else + { + $lineid=0; + $error++; + break; + } + // Defined the new fk_parent_line + if ($result > 0 && $lines[$i]->product_type == 9) + { + $fk_parent_line = $result; + } + } + } } - - $fk_parent_line=0; - $num=count($lines); - - for ($i=0;$i<$num;$i++) - { - $desc=($lines[$i]->desc?$lines[$i]->desc:$lines[$i]->libelle); - if ($lines[$i]->subprice < 0) - { - // Negative line, we create a discount line - $discount = new DiscountAbsolute($db); - $discount->fk_soc=$object->socid; - $discount->amount_ht=abs($lines[$i]->total_ht); - $discount->amount_tva=abs($lines[$i]->total_tva); - $discount->amount_ttc=abs($lines[$i]->total_ttc); - $discount->tva_tx=$lines[$i]->tva_tx; - $discount->fk_user=$user->id; - $discount->description=$desc; - $discountid=$discount->create($user); - if ($discountid > 0) - { - $result=$object->insert_discount($discountid); - //$result=$discount->link_to_invoice($lineid,$id); - } - else - { - setEventMessages($discount->error, $discount->errors, 'errors'); - $error++; - break; - } - } - else - { - // Positive line - $product_type=($lines[$i]->product_type?$lines[$i]->product_type:0); - // Date start - $date_start=false; - if ($lines[$i]->date_debut_prevue) $date_start=$lines[$i]->date_debut_prevue; - if ($lines[$i]->date_debut_reel) $date_start=$lines[$i]->date_debut_reel; - if ($lines[$i]->date_start) $date_start=$lines[$i]->date_start; - //Date end - $date_end=false; - if ($lines[$i]->date_fin_prevue) $date_end=$lines[$i]->date_fin_prevue; - if ($lines[$i]->date_fin_reel) $date_end=$lines[$i]->date_fin_reel; - if ($lines[$i]->date_end) $date_end=$lines[$i]->date_end; - // Reset fk_parent_line for no child products and special product - if (($lines[$i]->product_type != 9 && empty($lines[$i]->fk_parent_line)) || $lines[$i]->product_type == 9) - { - $fk_parent_line = 0; - } - $result = $object->addline( - $desc, - $lines[$i]->subprice, - $lines[$i]->qty, - $lines[$i]->tva_tx, - $lines[$i]->localtax1_tx, - $lines[$i]->localtax2_tx, - $lines[$i]->fk_product, - $lines[$i]->remise_percent, - $date_start, - $date_end, - 0, - $lines[$i]->info_bits, - $lines[$i]->fk_remise_except, - 'HT', - 0, - $product_type, - $ii, - $lines[$i]->special_code, - $object->origin, - $lines[$i]->rowid, - $fk_parent_line, - $lines[$i]->fk_fournprice, - $lines[$i]->pa_ht, - $lines[$i]->label - ); - if ($result > 0) - { - $lineid=$result; - } - else - { - $lineid=0; - $error++; - break; - } - // Defined the new fk_parent_line - if ($result > 0 && $lines[$i]->product_type == 9) - { - $fk_parent_line = $result; - } - } - } - } - $cmd->classifyBilled($user); + $cmd->classifyBilled($user); // TODO Move this in workflow like done for customer orders if(!empty($createbills_onebythird) && empty($TFactThird[$cmd->socid])) $TFactThird[$cmd->socid] = $object; else $TFact[$object->id] = $object; @@ -417,27 +414,30 @@ if (empty($reshook)) $TAllFact = empty($createbills_onebythird) ? $TFact : $TFactThird; $toselect = array(); - if(!empty($validate_invoices)) { + if (! $error && $validate_invoices) { $massaction = $action = 'builddoc'; - foreach($TAllFact as &$object) { + foreach($TAllFact as &$object) + { $object->validate($user); - $toselect[] = $object->id; // For builddoc action + if ($result <= 0) + { + $error++; + setEventMessages($object->error, $object->errors, 'errors'); + break; + } + + $id = $object->id; // For builddoc action // Fac builddoc + $donotredirect = 1; $upload_dir = $conf->facture->dir_output; $permissioncreate=$user->rights->facture->creer; include DOL_DOCUMENT_ROOT.'/core/actions_builddoc.inc.php'; } - $objectclass='Facture'; - $objectlabel='Invoice'; - $permtoread = $user->rights->facture->lire; - $permtodelete = $user->rights->facture->supprimer; - $uploaddir = $conf->facture->dir_output; - include DOL_DOCUMENT_ROOT.'/core/actions_massactions.inc.php'; - + $massaction = $action = 'confirm_createbills'; } if (! $error) From 13cb8064363635aec034646fa8a16ce5b9fe0539 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Wed, 4 Oct 2017 15:17:20 +0200 Subject: [PATCH 29/46] FIX #7531 #7537 --- htdocs/core/class/commonobject.class.php | 8 ++++++-- htdocs/core/class/extrafields.class.php | 9 ++++++--- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/htdocs/core/class/commonobject.class.php b/htdocs/core/class/commonobject.class.php index f1002d86f80..a97b553aed4 100644 --- a/htdocs/core/class/commonobject.class.php +++ b/htdocs/core/class/commonobject.class.php @@ -4559,12 +4559,16 @@ abstract class CommonObject { $out .= ''; } - // Convert date into timestamp format + // Convert date into timestamp format (value in memory must be a timestamp) if (in_array($extrafields->attribute_type[$key],array('date','datetime'))) { $value = isset($_POST["options_".$key])?dol_mktime($_POST["options_".$key."hour"], $_POST["options_".$key."min"], 0, $_POST["options_".$key."month"], $_POST["options_".$key."day"], $_POST["options_".$key."year"]):$this->db->jdate($this->array_options['options_'.$key]); } - + // Convert float submited string into real php numeric (value in memory must be a php numeric) + if (in_array($extrafields->attribute_type[$key],array('price','double'))) + { + $value = isset($_POST["options_".$key])?price2num($_POST["options_".$key]):$this->array_options['options_'.$key]; + } if($extrafields->attribute_required[$key]) $label = ''.$label.''; diff --git a/htdocs/core/class/extrafields.class.php b/htdocs/core/class/extrafields.class.php index b539a02654f..f6f0006a6d6 100644 --- a/htdocs/core/class/extrafields.class.php +++ b/htdocs/core/class/extrafields.class.php @@ -738,7 +738,7 @@ class ExtraFields * Return HTML string to put an input field into a page * * @param string $key Key of attribute - * @param string $value Preselected value to show (for date type it must be in timestamp format) + * @param string $value Preselected value to show (for date type it must be in timestamp format, for amount or price it must be a php numeric value) * @param string $moreparam To add more parametes on html input tag * @param string $keyprefix Prefix string to add into name and id of field (can be used to avoid duplicate names) * @param string $keysuffix Suffix string to add into name and id of field (can be used to avoid duplicate names) @@ -861,11 +861,14 @@ class ExtraFields } elseif ($type == 'price') { - $out=' '.$langs->getCurrencySymbol($conf->currency); + if (!empty($value)) { // $value in memory is a php numeric, we format it into user number format. + $value=price($value); + } + $out.=' '.$langs->getCurrencySymbol($conf->currency); } elseif ($type == 'double') { - if (!empty($value)) { + if (!empty($value)) { // $value in memory is a php numeric, we format it into user number format. $value=price($value); } $out=' '; From 69c47aa7d9f44ccca40b09973621271ce69ffdbe Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Wed, 4 Oct 2017 15:22:55 +0200 Subject: [PATCH 30/46] Fix sql error --- htdocs/fourn/class/fournisseur.facture.class.php | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/htdocs/fourn/class/fournisseur.facture.class.php b/htdocs/fourn/class/fournisseur.facture.class.php index 143d2cd5f36..d4edc4a01cd 100644 --- a/htdocs/fourn/class/fournisseur.facture.class.php +++ b/htdocs/fourn/class/fournisseur.facture.class.php @@ -2531,15 +2531,10 @@ class SupplierInvoiceLine extends CommonObjectLine } // Clean parameters - if (empty($this->tva_tx)) { - $this->tva_tx = 0; - } - if (empty($this->localtax1_tx)) { - $this->localtax1_tx = 0; - } - if (empty($this->localtax2_tx)) { - $this->localtax2_tx = 0; - } + if (empty($this->remise_percent)) $this->remise_percent = 0; + if (empty($this->tva_tx)) $this->tva_tx = 0; + if (empty($this->localtax1_tx)) $this->localtax1_tx = 0; + if (empty($this->localtax2_tx)) $this->localtax2_tx = 0; $this->db->begin(); From a3096b4e9daabed148baa54a075dcfeb60fd0f40 Mon Sep 17 00:00:00 2001 From: Neil Orley Date: Wed, 4 Oct 2017 15:59:54 +0200 Subject: [PATCH 31/46] NEW Generates the document before downloading using REST API Generates the document before downloading using REST API --- htdocs/api/class/api_documents.class.php | 26 +++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/htdocs/api/class/api_documents.class.php b/htdocs/api/class/api_documents.class.php index 4d0efb63d62..d1c544d4cb8 100644 --- a/htdocs/api/class/api_documents.class.php +++ b/htdocs/api/class/api_documents.class.php @@ -23,6 +23,7 @@ use Luracast\Restler\Format\UploadFormat; require_once DOL_DOCUMENT_ROOT.'/main.inc.php'; require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php'; +require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php'; /** * API class for receive files @@ -51,19 +52,22 @@ class Documents extends DolibarrApi /** - * Return list of documents. + * Returns a document. * * @param string $module_part Name of module or area concerned by file download ('facture', ...) * @param string $ref Reference of object (This will define subdir automatically) * @param string $subdir NOT YET AVAILABLE : Subdirectory (Only if ref not provided) * @return array List of documents * + * @throws 500 + * @throws 501 * @throws 400 * @throws 401 - * @throws 200 OK + * @throws 200 */ public function index($module_part, $ref='', $subdir='') { global $conf; + $this->invoice = new Facture($this->db); if (empty($module_part)) { throw new RestException(400, 'bad value for parameter modulepart'); @@ -72,12 +76,28 @@ class Documents extends DolibarrApi throw new RestException(400, 'bad value for parameter ref or subdir'); } if (empty($ref)) { - throw new RestException(404, 'FeatureNotYetAvailable'); + throw new RestException(501, 'FeatureNotYetAvailable'); } if (!DolibarrApiAccess::$user->rights->ecm->read) { throw new RestException(401); } + + //--- Generates the document + $hidedetails = empty($conf->global->MAIN_GENERATE_DOCUMENTS_HIDE_DETAILS) ? 0 : 1; + $hidedesc = empty($conf->global->MAIN_GENERATE_DOCUMENTS_HIDE_DESC) ? 0 : 1; + $hideref = empty($conf->global->MAIN_GENERATE_DOCUMENTS_HIDE_REF) ? 0 : 1; + $result = $this->invoice->fetch(0, $ref); + if( ! $result ) { + throw new RestException(404, 'Invoice not found'); + } + $result = $this->invoice->generateDocument($this->invoice->modelpdf, $outputlangs, $hidedetails, $hidedesc, $hideref); + if( $result <= 0 ) { + throw new RestException(500, 'Error generating document'); + } + + + //--- Finds and returns the document $original_file = str_replace("../","/", $ref.'/'.$ref.'.pdf'); $refname=basename(dirname($original_file)."/"); $entity=$conf->entity; From 1cee16a8021860c4f2bb7d24d07bb035a9a8d3c6 Mon Sep 17 00:00:00 2001 From: Regis Houssin Date: Wed, 4 Oct 2017 18:32:52 +0200 Subject: [PATCH 32/46] Fix: minimal num, maj and special character with value 0 not work --- .../security/generate/modGeneratePassPerso.class.php | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/htdocs/core/modules/security/generate/modGeneratePassPerso.class.php b/htdocs/core/modules/security/generate/modGeneratePassPerso.class.php index af08ae53392..96041bcac2c 100644 --- a/htdocs/core/modules/security/generate/modGeneratePassPerso.class.php +++ b/htdocs/core/modules/security/generate/modGeneratePassPerso.class.php @@ -1,6 +1,7 @@ - * Copyright (C) 2014 Teddy Andreotti <125155@supinfo.com> +/* Copyright (C) 2006-2011 Laurent Destailleur + * Copyright (C) 2014 Teddy Andreotti <125155@supinfo.com> + * Copyright (C) 2017 Regis Houssin * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -98,7 +99,10 @@ class modGeneratePassPerso extends ModeleGenPassword $this->Spe = str_replace($this->Ambi,"",$this->Spe); } - $this->All = str_shuffle($this->Maj. $this->Min. $this->Nb. $this->Spe); + $pattern = $this->Min . (! empty($this->NbMaj)?$this->Maj:'') . (! empty($this->NbNum)?$this->Nb:'') . (! empty($this->NbSpe)?$this->Spe:''); + $this->All = str_shuffle($pattern); + + //$this->All = str_shuffle($this->Maj. $this->Min. $this->Nb. $this->Spe); //$this->All = $this->Maj. $this->Min. $this->Nb. $this->Spe; //$this->All = $this->Spe; From 6540bc0061761e2a96ae5782b90aee822ee39da1 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Wed, 4 Oct 2017 19:48:11 +0200 Subject: [PATCH 33/46] Fix doxygen --- htdocs/categories/class/categorie.class.php | 2 +- htdocs/core/class/comment.class.php | 16 +++++++++------- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/htdocs/categories/class/categorie.class.php b/htdocs/categories/class/categorie.class.php index 6027f76ec58..6242691d1f1 100644 --- a/htdocs/categories/class/categorie.class.php +++ b/htdocs/categories/class/categorie.class.php @@ -882,7 +882,7 @@ class Categorie extends CommonObject /** * List categories of an element id * - * @param int $item Id of element + * @param int $id Id of element * @param string $type Type of category ('member', 'customer', 'supplier', 'product', 'contact') * @param string $sortfield Sort field * @param string $sortorder Sort order diff --git a/htdocs/core/class/comment.class.php b/htdocs/core/class/comment.class.php index 0ec77405721..4a0f4154844 100644 --- a/htdocs/core/class/comment.class.php +++ b/htdocs/core/class/comment.class.php @@ -1,4 +1,4 @@ -db = $db; } - + /** * Create into database @@ -280,12 +280,14 @@ class Comment extends CommonObject return 1; } } - - + + /** * Load comments linked with current task * - * @return array Comment array + * @param string $element_type Element type + * @param int $fk_element Id of element + * @return array Comment array */ public static function fetchAllFor($element_type, $fk_element) { @@ -299,7 +301,7 @@ class Comment extends CommonObject $sql.= " AND c.element_type = '".$element_type."'"; $sql.= " AND c.entity = ".$conf->entity; $sql.= " ORDER BY c.tms DESC"; - + dol_syslog("Comment::fetchAllFor", LOG_DEBUG); $resql=$db->query($sql); if ($resql) From f1b7b36a11a6abf55a3a1f418dd638914bd83b3c Mon Sep 17 00:00:00 2001 From: Alexandre SPANGARO Date: Thu, 5 Oct 2017 05:38:02 +0200 Subject: [PATCH 34/46] Fix : problem on column in customer to bind index --- htdocs/accountancy/customer/index.php | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/htdocs/accountancy/customer/index.php b/htdocs/accountancy/customer/index.php index 4aad88df54d..86327b27636 100644 --- a/htdocs/accountancy/customer/index.php +++ b/htdocs/accountancy/customer/index.php @@ -1,9 +1,9 @@ - * Copyright (C) 2013-2014 Florian Henry - * Copyright (C) 2013-2016 Alexandre Spangaro - * Copyright (C) 2014 Juanjo Menent - * Copyright (C) 2015 Jean-François Ferry +/* Copyright (C) 2013 Olivier Geffroy + * Copyright (C) 2013-2014 Florian Henry + * Copyright (C) 2013-2017 Alexandre Spangaro + * Copyright (C) 2014 Juanjo Menent + * Copyright (C) 2015 Jean-François Ferry * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -310,6 +310,7 @@ if ($resql) { } else print length_accountg($row[0]); print ''; + print ''; if ($row[0] == 'tobind') { @@ -317,7 +318,7 @@ if ($resql) { } else print $row[1]; print ''; - print '' . $row[1] . ''; + for($i = 2; $i <= 12; $i ++) { print '' . price($row[$i]) . ''; } From 2f49b00f6c42017acc9f8f909afe6a289e9d111c Mon Sep 17 00:00:00 2001 From: Alexandre SPANGARO Date: Thu, 5 Oct 2017 06:56:13 +0200 Subject: [PATCH 35/46] Fix : some small problems on accountancy --- htdocs/accountancy/bookkeeping/card.php | 2 +- .../bookkeeping/thirdparty_lettrage.php | 2 +- .../thirdparty_lettrage_supplier.php | 2 +- htdocs/accountancy/journal/bankjournal.php | 18 ++++---- .../journal/expensereportsjournal.php | 20 ++++----- .../accountancy/journal/purchasesjournal.php | 45 ++++++++++--------- htdocs/accountancy/journal/sellsjournal.php | 27 ++++++----- htdocs/langs/en_US/accountancy.lang | 3 +- 8 files changed, 60 insertions(+), 59 deletions(-) diff --git a/htdocs/accountancy/bookkeeping/card.php b/htdocs/accountancy/bookkeeping/card.php index d3252b01a18..81adbcb266b 100644 --- a/htdocs/accountancy/bookkeeping/card.php +++ b/htdocs/accountancy/bookkeeping/card.php @@ -569,7 +569,7 @@ if ($action == 'create') { print_liste_field_titre("AccountAccountingShort"); print_liste_field_titre("SubledgerAccount"); - print_liste_field_titre("Labelcompte"); + print_liste_field_titre("LabelAccount"); print_liste_field_titre("Label"); print_liste_field_titre("Debit", "", "", "", "", 'align="right"'); print_liste_field_titre("Credit", "", "", "", "", 'align="right"'); diff --git a/htdocs/accountancy/bookkeeping/thirdparty_lettrage.php b/htdocs/accountancy/bookkeeping/thirdparty_lettrage.php index 5f621a55186..f2cce5bee91 100644 --- a/htdocs/accountancy/bookkeeping/thirdparty_lettrage.php +++ b/htdocs/accountancy/bookkeeping/thirdparty_lettrage.php @@ -196,7 +196,7 @@ llxHeader ( '', 'Compta - Grand Livre' ); print_liste_field_titre("Docref", "liste.php", "bk.doc_ref" ); // print_liste_field_titre("Numerocompte", "liste.php", "bk.numero_compte" ); // print_liste_field_titre("Code_tiers", "liste.php", "bk.code_tiers" ); - print_liste_field_titre("Labelcompte", "liste.php", "bk_label_compte" ); + print_liste_field_titre("LabelAccount", "liste.php", "bk_label_compte" ); print_liste_field_titre("Debit", "liste.php", "bk.debit" ); print_liste_field_titre("Credit", "liste.php", "bk.credit" ); // print_liste_field_titre("Amount", "liste.php", "bk.montant" ); diff --git a/htdocs/accountancy/bookkeeping/thirdparty_lettrage_supplier.php b/htdocs/accountancy/bookkeeping/thirdparty_lettrage_supplier.php index 623e54f71fb..f98cb74a456 100644 --- a/htdocs/accountancy/bookkeeping/thirdparty_lettrage_supplier.php +++ b/htdocs/accountancy/bookkeeping/thirdparty_lettrage_supplier.php @@ -205,7 +205,7 @@ llxHeader ( '', 'Compta - Grand Livre' ); print_liste_field_titre("Docref", "liste.php", "bk.doc_ref" ); // print_liste_field_titre("Numerocompte", "liste.php", "bk.numero_compte" ); // print_liste_field_titre("Code_tiers", "liste.php", "bk.code_tiers" ); - print_liste_field_titre("Labelcompte", "liste.php", "bk_label_compte" ); + print_liste_field_titre("LabelAccount", "liste.php", "bk_label_compte" ); print_liste_field_titre("Debit", "liste.php", "bk.debit" ); print_liste_field_titre("Credit", "liste.php", "bk.credit" ); print_liste_field_titre("Amount", "liste.php", "bk.montant" ); diff --git a/htdocs/accountancy/journal/bankjournal.php b/htdocs/accountancy/journal/bankjournal.php index 0470fe83cb1..8f17fad4e17 100644 --- a/htdocs/accountancy/journal/bankjournal.php +++ b/htdocs/accountancy/journal/bankjournal.php @@ -1,12 +1,12 @@ - * Copyright (C) 2007-2010 Jean Heimburger - * Copyright (C) 2011 Juanjo Menent - * Copyright (C) 2012 Regis Houssin - * Copyright (C) 2013 Christophe Battarel - * Copyright (C) 2013-2017 Alexandre Spangaro - * Copyright (C) 2013-2014 Florian Henry - * Copyright (C) 2013-2014 Olivier Geffroy +/* Copyright (C) 2007-2010 Laurent Destailleur + * Copyright (C) 2007-2010 Jean Heimburger + * Copyright (C) 2011 Juanjo Menent + * Copyright (C) 2012 Regis Houssin + * Copyright (C) 2013 Christophe Battarel + * Copyright (C) 2013-2017 Alexandre Spangaro + * Copyright (C) 2013-2014 Florian Henry + * Copyright (C) 2013-2014 Olivier Geffroy * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -828,7 +828,7 @@ if (empty($action) || $action == 'view') { print "" . $langs->trans("Piece") . ' (' . $langs->trans("ObjectsRef") . ")"; print "" . $langs->trans("AccountAccounting") . ""; print "" . $langs->trans("SubledgerAccount") . ""; - print "" . $langs->trans("Label") . ""; + print "" . $langs->trans("LabelOperation") . ""; print "" . $langs->trans("PaymentMode") . ""; print "" . $langs->trans("Debit") . ""; print "" . $langs->trans("Credit") . ""; diff --git a/htdocs/accountancy/journal/expensereportsjournal.php b/htdocs/accountancy/journal/expensereportsjournal.php index f5ad584399e..c73286a8bdd 100644 --- a/htdocs/accountancy/journal/expensereportsjournal.php +++ b/htdocs/accountancy/journal/expensereportsjournal.php @@ -1,11 +1,11 @@ - * Copyright (C) 2007-2010 Jean Heimburger - * Copyright (C) 2011 Juanjo Menent - * Copyright (C) 2012 Regis Houssin - * Copyright (C) 2013-2017 Alexandre Spangaro - * Copyright (C) 2013-2016 Olivier Geffroy - * Copyright (C) 2013-2016 Florian Henry +/* Copyright (C) 2007-2010 Laurent Destailleur + * Copyright (C) 2007-2010 Jean Heimburger + * Copyright (C) 2011 Juanjo Menent + * Copyright (C) 2012 Regis Houssin + * Copyright (C) 2013-2017 Alexandre Spangaro + * Copyright (C) 2013-2016 Olivier Geffroy + * Copyright (C) 2013-2016 Florian Henry * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -298,7 +298,7 @@ if ($action == 'writebookkeeping') { $bookkeeping->subledger_account = ''; $bookkeeping->subledger_label = ''; $bookkeeping->numero_compte = $k; - $bookkeeping->label_operation = $langs->trans("VAT"). ' '.join(', ',$def_tva[$key][$k]); + $bookkeeping->label_operation = $langs->trans("VAT"). ' '.join(', ',$def_tva[$key][$k]).' %'; $bookkeeping->montant = $mt; $bookkeeping->sens = ($mt < 0) ? 'C' : 'D'; $bookkeeping->debit = ($mt > 0) ? $mt : 0; @@ -552,7 +552,7 @@ if (empty($action) || $action == 'view') { print "" . $langs->trans("Piece") . ' (' . $langs->trans("ExpenseReportRef") . ")"; print "" . $langs->trans("AccountAccounting") . ""; print "" . $langs->trans("SubledgerAccount") . ""; - print "" . $langs->trans("Label") . ""; + print "" . $langs->trans("LabelOperation") . ""; print "" . $langs->trans("Debit") . ""; print "" . $langs->trans("Credit") . ""; print "\n"; @@ -659,7 +659,7 @@ if (empty($action) || $action == 'view') { // Subledger account print ""; print ''; - print "" . $userstatic->getNomUrl(0, 'user', 16) . ' - ' . $langs->trans("VAT"). ' '.join(', ',$def_tva[$key][$k]).($numtax?' - Localtax '.$numtax:''); + print "" . $userstatic->getNomUrl(0, 'user', 16) . ' - ' . $langs->trans("VAT"). ' '.join(', ',$def_tva[$key][$k]).' %'.($numtax?' - Localtax '.$numtax:''); print ""; print '' . ($mt >= 0 ? price($mt) : '') . ""; print '' . ($mt < 0 ? price(- $mt) : '') . ""; diff --git a/htdocs/accountancy/journal/purchasesjournal.php b/htdocs/accountancy/journal/purchasesjournal.php index 4838e1814bd..8a1c704f87b 100644 --- a/htdocs/accountancy/journal/purchasesjournal.php +++ b/htdocs/accountancy/journal/purchasesjournal.php @@ -151,7 +151,7 @@ if ($result) { // Define array to display all VAT rates that use this accounting account $compta_tva if (price2num($obj->tva_tx) || ! empty($obj->vat_src_code)) { - $def_tva[$obj->rowid][$compta_tva][vatrate($obj->tva_tx).($obj->vat_src_code?' ('.$obj->vat_src_code.')':'')]=(vatrate($obj->tva_tx).($obj->vat_src_code?' ('.$obj->vat_src_code.')':'')); + $def_tva[$obj->rowid][$compta_tva][vatrate($obj->tva_tx).($obj->vat_src_code?' ('.$obj->vat_src_code.')':'')]=(vatrate($obj->tva_tx).($obj->vat_src_code?' ('.$obj->vat_src_code.')':'')); } $tabfac[$obj->rowid]["date"] = $db->jdate($obj->df); @@ -224,7 +224,7 @@ if ($action == 'writebookkeeping') { $bookkeeping = new BookKeeping($db); $bookkeeping->doc_date = $val["date"]; $bookkeeping->date_lim_reglement = $val["datereg"]; - $bookkeeping->doc_ref = $val["ref"]; + $bookkeeping->doc_ref = $val["refsologest"]; $bookkeeping->date_create = $now; $bookkeeping->doc_type = 'supplier_invoice'; $bookkeeping->fk_doc = $key; @@ -272,7 +272,7 @@ if ($action == 'writebookkeeping') { $bookkeeping = new BookKeeping($db); $bookkeeping->doc_date = $val["date"]; $bookkeeping->date_lim_reglement = $val["datereg"]; - $bookkeeping->doc_ref = $val["ref"]; + $bookkeeping->doc_ref = $val["refsologest"]; $bookkeeping->date_create = $now; $bookkeeping->doc_type = 'supplier_invoice'; $bookkeeping->fk_doc = $key; @@ -326,7 +326,7 @@ if ($action == 'writebookkeeping') { $bookkeeping = new BookKeeping($db); $bookkeeping->doc_date = $val["date"]; $bookkeeping->date_lim_reglement = $val["datereg"]; - $bookkeeping->doc_ref = $val["ref"]; + $bookkeeping->doc_ref = $val["refsologest"]; $bookkeeping->date_create = $now; $bookkeeping->doc_type = 'supplier_invoice'; $bookkeeping->fk_doc = $key; @@ -335,7 +335,7 @@ if ($action == 'writebookkeeping') { $bookkeeping->subledger_account = ''; $bookkeeping->subledger_label = ''; $bookkeeping->numero_compte = $k; - $bookkeeping->label_operation = dol_trunc($companystatic->name, 16) . ' - ' . $invoicestatic->refsupplier . ' - ' . $langs->trans("VAT").' '.join(', ',$def_tva[$key][$k]) . ($numtax?' - Localtax '.$numtax:''); + $bookkeeping->label_operation = dol_trunc($companystatic->name, 16) . ' - ' . $invoicestatic->refsupplier . ' - ' . $langs->trans("VAT").' '.join(', ',$def_tva[$key][$k]) .' %' . ($numtax?' - Localtax '.$numtax:''); $bookkeeping->montant = $mt; $bookkeeping->sens = ($mt < 0) ? 'C' : 'D'; $bookkeeping->debit = ($mt > 0) ? $mt : 0; @@ -374,8 +374,8 @@ if ($action == 'writebookkeeping') { if ($error >= 10) { - setEventMessages($langs->trans("ErrorTooManyErrorsProcessStopped"), null, 'errors'); - break; // Break in the foreach + setEventMessages($langs->trans("ErrorTooManyErrorsProcessStopped"), null, 'errors'); + break; // Break in the foreach } } } @@ -419,7 +419,6 @@ $form = new Form($db); // Export if ($action == 'exportcsv') { $sep = $conf->global->ACCOUNTING_EXPORT_SEPARATORCSV; - $journal = $conf->global->ACCOUNTING_PURCHASE_JOURNAL; include DOL_DOCUMENT_ROOT . '/accountancy/tpl/export_journal.tpl.php'; @@ -445,7 +444,7 @@ if ($action == 'exportcsv') { foreach ( $tabttc[$key] as $k => $mt ) { print '"' . $key . '"' . $sep; print '"' . $date . '"' . $sep; - print '"' . $val["refsuppliersologest"] . '"' . $sep; + print '"' . $val["refsologest"] . '"' . $sep; print '"' . utf8_decode ( dol_trunc($companystatic->name, 32) ). '"' . $sep; print '"' . length_accounta(html_entity_decode($k)) . '"' . $sep; print '"' . $conf->global->ACCOUNTING_ACCOUNT_SUPPLIER . '"' . $sep; @@ -465,11 +464,11 @@ if ($action == 'exportcsv') { if ($mt) { print '"' . $key . '"' . $sep; print '"' . $date . '"' . $sep; - print '"' . $val["refsuppliersologest"] . '"' . $sep; + print '"' . $val["refsologest"] . '"' . $sep; print '"' . utf8_decode ( dol_trunc($companystatic->name, 32) ) . '"' . $sep; print '"' . length_accountg(html_entity_decode($k)) . '"' . $sep; print '"' . length_accountg(html_entity_decode($k)) . '"' . $sep; - print " " . $sep; + print '""' . $sep; print '"' . utf8_decode ( dol_trunc($accountingaccount->label, 32) ) . '"' . $sep; print '"' . utf8_decode ( dol_trunc($companystatic->name, 16) ) . ' - ' . $val["refsuppliersologest"] . ' - ' . dol_trunc($accountingaccount->label, 32) . '"' . $sep; print '"' . ($mt >= 0 ? price($mt) : '') . '"' . $sep; @@ -478,6 +477,7 @@ if ($action == 'exportcsv') { print "\n"; } } + // VAT $listoftax = array(0, 1, 2); foreach ($listoftax as $numtax) { @@ -489,13 +489,13 @@ if ($action == 'exportcsv') { if ($mt) { print '"' . $key . '"' . $sep; print '"' . $date . '"' . $sep; - print '"' . $val["refsuppliersologest"] . '"' . $sep; + print '"' . $val["refsologest"] . '"' . $sep; print '"' . utf8_decode ( dol_trunc($companystatic->name, 32) ) . '"' . $sep; print '"' . length_accountg(html_entity_decode($k)) . '"' . $sep; print '"' . length_accountg(html_entity_decode($k)) . '"' . $sep; - print " " . $sep; + print '""' . $sep; print '"' . $langs->trans("VAT") . ' - ' . $def_tva[$key] . '"' . $sep; - print '"' . utf8_decode(dol_trunc($companystatic->name, 16) ) . ' - ' . $val["refsuppliersologest"] . ' - ' . $langs->trans("VAT") . join(', ',$def_tva[$key][$k]) . ($numtax?' - Localtax '.$numtax:'') . '"' . $sep; + print '"' . utf8_decode(dol_trunc($companystatic->name, 16) ) . ' - ' . $val["refsuppliersologest"] . ' - ' . $langs->trans("VAT") . join(', ',$def_tva[$key][$k]) .' %' . ($numtax?' - Localtax '.$numtax:'') . '"' . $sep; print '"' . ($mt >= 0 ? price($mt) : '') . '"' . $sep; print '"' . ($mt < 0 ? price(- $mt) : '') . '"'. $sep; print '"' . $journal . '"' ; @@ -531,15 +531,15 @@ if (empty($action) || $action == 'view') { // Button to write into Ledger if (empty($conf->global->ACCOUNTING_ACCOUNT_SUPPLIER) || $conf->global->ACCOUNTING_ACCOUNT_SUPPLIER == '-1') { - print img_warning().' '.$langs->trans("SomeMandatoryStepsOfSetupWereNotDone"); - print ' : '.$langs->trans("AccountancyAreaDescMisc", 4, ''.$langs->transnoentitiesnoconv("MenuAccountancy").'-'.$langs->transnoentitiesnoconv("MenuAccountancy").'-'.$langs->transnoentitiesnoconv("Setup")."-".$langs->transnoentitiesnoconv("MenuDefaultAccounts").''); + print img_warning().' '.$langs->trans("SomeMandatoryStepsOfSetupWereNotDone"); + print ' : '.$langs->trans("AccountancyAreaDescMisc", 4, ''.$langs->transnoentitiesnoconv("MenuAccountancy").'-'.$langs->transnoentitiesnoconv("MenuAccountancy").'-'.$langs->transnoentitiesnoconv("Setup")."-".$langs->transnoentitiesnoconv("MenuDefaultAccounts").''); } print '
'; if (empty($conf->global->ACCOUNTING_ACCOUNT_CUSTOMER) || $conf->global->ACCOUNTING_ACCOUNT_CUSTOMER == '-1') { - print ''; + print ''; } else { - print ''; + print ''; } print ''; print '
'; @@ -565,7 +565,7 @@ if (empty($action) || $action == 'view') { print '
'; $i = 0; - print '
'; + print '
'; print ""; print ""; print ""; @@ -573,7 +573,7 @@ if (empty($action) || $action == 'view') { print ""; print ""; print ""; - print ""; + print ""; print ""; print ""; print "\n"; @@ -625,8 +625,9 @@ if (empty($action) || $action == 'view') { print ""; print '"; print '"; - print ""; + print ""; } + // Product / Service foreach ( $tabht[$key] as $k => $mt ) { $accountingaccount = new AccountingAccount($db); @@ -683,7 +684,7 @@ if (empty($action) || $action == 'view') { // Subledger account print "'; - print ""; print '"; print '"; diff --git a/htdocs/accountancy/journal/sellsjournal.php b/htdocs/accountancy/journal/sellsjournal.php index c5cd4f53910..32a29177a37 100644 --- a/htdocs/accountancy/journal/sellsjournal.php +++ b/htdocs/accountancy/journal/sellsjournal.php @@ -156,7 +156,7 @@ if ($result) { $compta_localtax2 = (! empty($vatdata['accountancy_code_sell']) ? $vatdata['accountancy_code_sell'] : $cpttva); // Define array to display all VAT rates that use this accounting account $compta_tva - if (price2num($obj->tva_tx) || ! empty($obj->vat_src_code)) + if (price2num($obj->tva_tx) || ! empty($obj->vat_src_code)) { $def_tva[$obj->rowid][$compta_tva][vatrate($obj->tva_tx).($obj->vat_src_code?' ('.$obj->vat_src_code.')':'')]=(vatrate($obj->tva_tx).($obj->vat_src_code?' ('.$obj->vat_src_code.')':'')); } @@ -353,7 +353,7 @@ if ($action == 'writebookkeeping') { $bookkeeping->subledger_account = ''; $bookkeeping->subledger_label = ''; $bookkeeping->numero_compte = $k; - $bookkeeping->label_operation = dol_trunc($companystatic->name, 16) . ' - ' . $invoicestatic->ref . ' - ' . $langs->trans("VAT").' '.join(', ',$def_tva[$key][$k]) . ($numtax?' - Localtax '.$numtax:''); + $bookkeeping->label_operation = dol_trunc($companystatic->name, 16) . ' - ' . $invoicestatic->ref . ' - ' . $langs->trans("VAT").' '.join(', ',$def_tva[$key][$k]) .' %' . ($numtax?' - Localtax '.$numtax:''); $bookkeeping->montant = $mt; $bookkeeping->sens = ($mt < 0) ? 'D' : 'C'; $bookkeeping->debit = ($mt < 0) ? -$mt : 0; @@ -392,8 +392,8 @@ if ($action == 'writebookkeeping') { if ($error >= 10) { - setEventMessages($langs->trans("ErrorTooManyErrorsProcessStopped"), null, 'errors'); - break; // Break in the foreach + setEventMessages($langs->trans("ErrorTooManyErrorsProcessStopped"), null, 'errors'); + break; // Break in the foreach } } @@ -441,7 +441,6 @@ $form = new Form($db); if ($action == 'exportcsv') { $sep = $conf->global->ACCOUNTING_EXPORT_SEPARATORCSV; - $sell_journal = $conf->global->ACCOUNTING_SELL_JOURNAL; include DOL_DOCUMENT_ROOT . '/accountancy/tpl/export_journal.tpl.php'; @@ -472,7 +471,7 @@ if ($action == 'exportcsv') { print '"' . utf8_decode(dol_trunc($companystatic->name, 16)) . ' - ' . $invoicestatic->ref . ' - ' . $langs->trans("Code_tiers") . '"' . $sep; print '"' . ($mt >= 0 ? price($mt) : '') . '"' . $sep; print '"' . ($mt < 0 ? price(- $mt) : '') . '"' . $sep; - print '"' . $sell_journal . '"'; + print '"' . $journal . '"'; print "\n"; } @@ -487,12 +486,12 @@ if ($action == 'exportcsv') { print '"' . utf8_decode(dol_trunc($companystatic->name, 32)) . '"' . $sep; print '"' . length_accountg(html_entity_decode($k)) . '"' . $sep; print '"' . length_accountg(html_entity_decode($k)) . '"' . $sep; - print " " . $sep; + print '""' . $sep; print '"' . utf8_decode(dol_trunc($accountingaccount->label, 32)) . '"' . $sep; print '"' . utf8_decode(dol_trunc($companystatic->name, 16)) . ' - ' . dol_trunc($accountingaccount->label, 32) . '"' . $sep; print '"' . ($mt < 0 ? price(- $mt) : '') . '"' . $sep; print '"' . ($mt >= 0 ? price($mt) : '') . '"' . $sep; - print '"' . $sell_journal . '"'; + print '"' . $journal . '"'; print "\n"; } } @@ -512,12 +511,12 @@ if ($action == 'exportcsv') { print '"' . utf8_decode(dol_trunc($companystatic->name, 32)) . '"' . $sep; print '"' . length_accountg(html_entity_decode($k)) . '"' . $sep; print '"' . length_accountg(html_entity_decode($k)) . '"' . $sep; - print " " . $sep; - print '"' . $langs->trans("VAT") . ' - ' . $def_tva[$key] . '"' . $sep; - print '"' . utf8_decode(dol_trunc($companystatic->name, 16)) . ' - ' . $invoicestatic->ref . ' - ' . $langs->trans("VAT") . join(', ',$def_tva[$key][$k]) . ($numtax?' - Localtax '.$numtax:'') . '"' . $sep; + print '""' . $sep; + print '"' . $langs->trans("VAT") . ' - ' . $def_tva[$key] . ' %"' . $sep; + print '"' . utf8_decode(dol_trunc($companystatic->name, 16)) . ' - ' . $invoicestatic->ref . ' - ' . $langs->trans("VAT") . join(', ',$def_tva[$key][$k]) .' %' . ($numtax?' - Localtax '.$numtax:'') . '"' . $sep; print '"' . ($mt < 0 ? price(- $mt) : '') . '"' . $sep; print '"' . ($mt >= 0 ? price($mt) : '') . '"' . $sep; - print '"' . $sell_journal . '"'; + print '"' . $journal . '"'; print "\n"; } } @@ -593,7 +592,7 @@ if (empty($action) || $action == 'view') { print ""; print ""; print ""; - print ""; + print ""; print ""; print ""; print "\n"; @@ -699,7 +698,7 @@ if (empty($action) || $action == 'view') { // Subledger account print "'; - print ""; print '"; print '"; diff --git a/htdocs/langs/en_US/accountancy.lang b/htdocs/langs/en_US/accountancy.lang index 8ab0ddc018c..eacfe4fc2aa 100644 --- a/htdocs/langs/en_US/accountancy.lang +++ b/htdocs/langs/en_US/accountancy.lang @@ -148,7 +148,8 @@ Doctype=Type of document Docdate=Date Docref=Reference Code_tiers=Thirdparty -Labelcompte=Label account +LabelAccount=Label account +LabelOperation=Label operation Sens=Sens Codejournal=Journal NumPiece=Piece number From 04a56d4bd9ce8d7ed8a4ce4d6543e7836ea91466 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Thu, 5 Oct 2017 09:34:09 +0200 Subject: [PATCH 36/46] Fix phpunit --- htdocs/install/mysql/migration/6.0.0-7.0.0.sql | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/htdocs/install/mysql/migration/6.0.0-7.0.0.sql b/htdocs/install/mysql/migration/6.0.0-7.0.0.sql index fb9e5f8749f..5d87f42faed 100644 --- a/htdocs/install/mysql/migration/6.0.0-7.0.0.sql +++ b/htdocs/install/mysql/migration/6.0.0-7.0.0.sql @@ -253,7 +253,7 @@ CREATE TABLE llx_expensereport_rules ( code_expense_rules_type varchar(50) NOT NULL, is_for_all tinyint DEFAULT '0', entity integer DEFAULT 1 -); +)ENGINE=innodb; ALTER TABLE llx_expensereport_det ADD COLUMN rule_warning_message text; ALTER TABLE llx_expensereport_det ADD COLUMN fk_c_exp_tax_cat integer; @@ -302,8 +302,9 @@ insert into llx_c_action_trigger (code,label,description,elementtype,rang) value insert into llx_c_action_trigger (code,label,description,elementtype,rang) values ('PROPOSAL_SUPPLIER_CLOSE_SIGNED','Price request closed signed','Executed when a customer proposal is closed signed','proposal_supplier',10); insert into llx_c_action_trigger (code,label,description,elementtype,rang) values ('PROPOSAL_SUPPLIER_CLOSE_REFUSED','Price request closed refused','Executed when a customer proposal is closed refused','proposal_supplier',10); -DROP TABLE `llx_projet_task_comment`; -CREATE TABLE IF NOT EXISTS llx_comment ( +DROP TABLE llx_projet_task_comment; + +CREATE TABLE llx_comment ( rowid integer AUTO_INCREMENT PRIMARY KEY, datec datetime DEFAULT NULL, tms timestamp, From 47306113331448283e24bedd8fd814b07f59b178 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Thu, 5 Oct 2017 09:54:48 +0200 Subject: [PATCH 37/46] Add language file button --- htdocs/langs/en_US/modulebuilder.lang | 6 +++--- htdocs/modulebuilder/index.php | 16 ++++++++++++++++ 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/htdocs/langs/en_US/modulebuilder.lang b/htdocs/langs/en_US/modulebuilder.lang index 73ff04221ef..233e4339bca 100644 --- a/htdocs/langs/en_US/modulebuilder.lang +++ b/htdocs/langs/en_US/modulebuilder.lang @@ -12,7 +12,7 @@ ObjectKey=Object key ModuleInitialized=Module initialized FilesForObjectInitialized=Files for new object '%s' initialized FilesForObjectUpdated=Files for object '%s' updated (.sql files and .class.php file) -ModuleBuilderDescdescription=Enter here all general information that describe your module +ModuleBuilderDescdescription=Enter here all general information that describe your module. ModuleBuilderDescspecifications=You can enter here a long text to describe the specifications of your module that is not already structured into other tabs. So you have within easy reach all the rules to develop. Also this text content will be included into the generated documentation (see last tab). You can use Markdown format, but it is recommanded to use Asciidoc format (Comparison between .md and .asciidoc: http://asciidoctor.org/docs/user-manual/#compared-to-markdown) ModuleBuilderDescobjects=Define here the objects you want to manage with your module. A CRUD DAO class, SQL files, page to list record of objects, to create/edit/view a record and an API will be generated. ModuleBuilderDescmenus=This tab is dedicated to define menu entries provided by your module. @@ -77,7 +77,7 @@ SpecDefDesc=Enter here all documentation you want to provide with your module th LanguageDefDesc=Enter in this files, all the key and the translation for each language file. MenusDefDesc=Define here the menus provided by your module (once defined, they are visible into the menu editor %s) PermissionsDefDesc=Define here the new permissions provided by your module (once defined, they are visible into the default permissions setup %s) -HooksDefDesc=Define in the module_parts['hooks'] property in the module descriptor the context of hooks you want to manage (list of contexts can be found by a search on 'initHooks(' in core code).
Edit the hook file to add code of your hooked functions (hookable functions can be found by a search on 'executeHooks' in core code). -TriggerDefDesc=Define in the trigger file the code you want to execute for each business event executed +HooksDefDesc=Define in the module_parts['hooks'] property, in the module descriptor, the context of hooks you want to manage (list of contexts can be found by a search on 'initHooks(' in core code).
Edit the hook file to add code of your hooked functions (hookable functions can be found by a search on 'executeHooks' in core code). +TriggerDefDesc=Define in the trigger file the code you want to execute for each business event executed. SeeIDsInUse=See IDs in use in your installation SeeReservedIDsRangeHere=See range of reserved IDs \ No newline at end of file diff --git a/htdocs/modulebuilder/index.php b/htdocs/modulebuilder/index.php index 1e7826ebf16..767370786c1 100644 --- a/htdocs/modulebuilder/index.php +++ b/htdocs/modulebuilder/index.php @@ -28,6 +28,7 @@ if (! defined('NOSCANPOSTFORINJECTION')) define('NOSCANPOSTFORINJECTION','1'); require '../main.inc.php'; require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php'; require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php'; +require_once DOL_DOCUMENT_ROOT.'/core/class/html.formadmin.class.php'; require_once DOL_DOCUMENT_ROOT.'/core/lib/modulebuilder.lib.php'; require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php'; @@ -764,6 +765,7 @@ if ($action == 'reset' && $user->admin) */ $form = new Form($db); +$formadmin = new FormAdmin($db); // Set dir where external modules are installed if (! dol_is_dir($dirins)) @@ -1252,6 +1254,20 @@ elseif (! empty($module)) print $langs->trans("LanguageDefDesc").'
'; print '
'; + + print '
'; + print ''; + print ''; + print ''; + print ''; + print ''; + print $formadmin->select_language($conf->global->MAIN_LANG_DEFAULT, 'MAIN_LANG_DEFAULT', 1, 0, 0, 0, 0, 'minwidth300', 1); + print '
'; + print ''; + + print '
'; + print '
'; + $langfiles=dol_dir_list(dol_buildpath($modulelowercase.'/langs', 0), 'files', 1, '\.lang$'); foreach ($langfiles as $langfile) From 2a2cd30e1950edb20195b17863c669c172393d2c Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Thu, 5 Oct 2017 10:00:43 +0200 Subject: [PATCH 38/46] Fix code --- htdocs/core/class/comment.class.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/core/class/comment.class.php b/htdocs/core/class/comment.class.php index 4a0f4154844..870c4f4bccd 100644 --- a/htdocs/core/class/comment.class.php +++ b/htdocs/core/class/comment.class.php @@ -190,7 +190,7 @@ class Comment extends CommonObject $sql.= " description=".(isset($this->description)?"'".$this->db->escape($this->description)."'":"null").","; $sql.= " datec=".($this->datec!=''?"'".$this->db->idate($this->datec)."'":'null').","; $sql.= " fk_element=".(isset($this->fk_element)?$this->fk_element:"null").","; - $sql.= " element_type='".$this->element_type."',"; + $sql.= " element_type='".$this->db->escape($this->element_type)."',"; $sql.= " fk_user_author=".(isset($this->fk_user_author)?$this->fk_user_author:"null").","; $sql.= " entity=".(!empty($this->entity)?$this->entity:'1').","; $sql.= " import_key=".(!empty($this->import_key)?"'".$this->db->escape($this->import_key)."'":"null"); From f0b314dfd721a237dc9364fc1a1a7d5545f8e8d1 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Thu, 5 Oct 2017 10:21:52 +0200 Subject: [PATCH 39/46] Change signature of file to match other urls to link/download files. --- htdocs/api/class/api_documents.class.php | 149 +++++++++++------------ htdocs/document.php | 1 + 2 files changed, 75 insertions(+), 75 deletions(-) diff --git a/htdocs/api/class/api_documents.class.php b/htdocs/api/class/api_documents.class.php index d1c544d4cb8..670d47ba3ee 100644 --- a/htdocs/api/class/api_documents.class.php +++ b/htdocs/api/class/api_documents.class.php @@ -23,7 +23,6 @@ use Luracast\Restler\Format\UploadFormat; require_once DOL_DOCUMENT_ROOT.'/main.inc.php'; require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php'; -require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php'; /** * API class for receive files @@ -50,13 +49,15 @@ class Documents extends DolibarrApi $this->db = $db; } - + /** - * Returns a document. + * Returns a document. Note that, this API is similar to using the wrapper link "documents.php" to download + * a file (used for internal HTML links of documents into application), but with no need to be into a logged session (no need to post the session cookie). * * @param string $module_part Name of module or area concerned by file download ('facture', ...) - * @param string $ref Reference of object (This will define subdir automatically) - * @param string $subdir NOT YET AVAILABLE : Subdirectory (Only if ref not provided) + * @param string $original_file Relative path with filename, relative to modulepart (for example: IN201701-999/IN201701-999.pdf) + * @param int $regeneratedoc If requested document is the main document of an object, setting this to 1 ask API to regenerate document before returning it (supported for some module_part only). It is no effect in other cases. + * Also, note that setting this to 1 nead write access on object. * @return array List of documents * * @throws 500 @@ -65,70 +66,68 @@ class Documents extends DolibarrApi * @throws 401 * @throws 200 */ - public function index($module_part, $ref='', $subdir='') { - global $conf; - $this->invoice = new Facture($this->db); + public function index($module_part, $original_file='', $regeneratedoc=0) + { + global $conf; - if (empty($module_part)) { - throw new RestException(400, 'bad value for parameter modulepart'); - } - if (empty($ref) && empty($subdir)) { + if (empty($module_part)) { + throw new RestException(400, 'bad value for parameter modulepart'); + } + if (empty($original_file)) { throw new RestException(400, 'bad value for parameter ref or subdir'); } - if (empty($ref)) { - throw new RestException(501, 'FeatureNotYetAvailable'); - } - if (!DolibarrApiAccess::$user->rights->ecm->read) { - throw new RestException(401); - } - - //--- Generates the document - $hidedetails = empty($conf->global->MAIN_GENERATE_DOCUMENTS_HIDE_DETAILS) ? 0 : 1; - $hidedesc = empty($conf->global->MAIN_GENERATE_DOCUMENTS_HIDE_DESC) ? 0 : 1; - $hideref = empty($conf->global->MAIN_GENERATE_DOCUMENTS_HIDE_REF) ? 0 : 1; - $result = $this->invoice->fetch(0, $ref); - if( ! $result ) { - throw new RestException(404, 'Invoice not found'); - } - $result = $this->invoice->generateDocument($this->invoice->modelpdf, $outputlangs, $hidedetails, $hidedesc, $hideref); - if( $result <= 0 ) { - throw new RestException(500, 'Error generating document'); + + //--- Finds and returns the document + $entity=$conf->entity; + + $check_access = dol_check_secure_access_document($module_part, $original_file, $entity, DolibarrApiAccess::$user, '', ($regeneratedoc ? 'write' : 'read')); + $accessallowed = $check_access['accessallowed']; + $sqlprotectagainstexternals = $check_access['sqlprotectagainstexternals']; + $original_file = $check_access['original_file']; + + if (preg_match('/\.\./',$original_file) || preg_match('/[<>|]/',$original_file)) + { + throw new RestException(401); + } + if (!$accessallowed) { + throw new RestException(401); + } + + // --- Generates the document + if ($regeneratedoc) + { + $hidedetails = empty($conf->global->MAIN_GENERATE_DOCUMENTS_HIDE_DETAILS) ? 0 : 1; + $hidedesc = empty($conf->global->MAIN_GENERATE_DOCUMENTS_HIDE_DESC) ? 0 : 1; + $hideref = empty($conf->global->MAIN_GENERATE_DOCUMENTS_HIDE_REF) ? 0 : 1; + + if ($module_part == 'facture' || $module_part == 'invoice') + { + require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php'; + $this->invoice = new Facture($this->db); + $result = $this->invoice->fetch(0, $ref); + if( ! $result ) { + throw new RestException(404, 'Invoice not found'); + } + $result = $this->invoice->generateDocument($this->invoice->modelpdf, $outputlangs, $hidedetails, $hidedesc, $hideref); + if( $result <= 0 ) { + throw new RestException(500, 'Error generating document'); + } + } } + $filename = basename($original_file); + $original_file_osencoded=dol_osencode($original_file); // New file name encoded in OS encoding charset + if (! file_exists($original_file_osencoded)) + { + throw new RestException(404, 'File not found'); + } - //--- Finds and returns the document - $original_file = str_replace("../","/", $ref.'/'.$ref.'.pdf'); - $refname=basename(dirname($original_file)."/"); - $entity=$conf->entity; - - $check_access = dol_check_secure_access_document($module_part,$original_file,$entity,DolibarrApiAccess::$user); - $accessallowed = $check_access['accessallowed']; - $sqlprotectagainstexternals = $check_access['sqlprotectagainstexternals']; - $original_file = $check_access['original_file']; - - if (preg_match('/\.\./',$original_file) || preg_match('/[<>|]/',$original_file)) - { - throw new RestException(401); - } - if (!$accessallowed) { - throw new RestException(401); - } - - - $filename = basename($original_file); - $original_file_osencoded=dol_osencode($original_file); // New file name encoded in OS encoding charset - - if (! file_exists($original_file_osencoded)) - { - throw new RestException(404, 'File not found'); - } - - $file_content=file_get_contents($original_file_osencoded); + $file_content=file_get_contents($original_file_osencoded); return array('filename'=>$filename, 'content'=>base64_encode($file_content), 'encoding'=>'MIME base64 (base64_encode php function, http://php.net/manual/en/function.base64-encode.php)' ); } - - + + /** * Return a document. * @@ -141,10 +140,10 @@ class Documents extends DolibarrApi public function get($id) { return array('note'=>'xxx'); }*/ - - + + /** - * Push a file. + * Push a file. * Test sample 1: { "filename": "mynewfile.txt", "modulepart": "facture", "ref": "FA1701-001", "subdir": "", "filecontent": "content text", "fileencoding": "", "overwriteifexists": "0" }. * Test sample 2: { "filename": "mynewfile.txt", "modulepart": "medias", "ref": "", "subdir": "mysubdir1/mysubdir2", "filecontent": "content text", "fileencoding": "", "overwriteifexists": "0" }. * @@ -161,12 +160,12 @@ class Documents extends DolibarrApi public function post($filename, $modulepart, $ref='', $subdir='', $filecontent='', $fileencoding='', $overwriteifexists=0) { global $db, $conf; - + /*var_dump($modulepart); var_dump($filename); var_dump($filecontent); exit;*/ - + require_once DOL_DOCUMENT_ROOT . '/core/lib/files.lib.php'; if (!DolibarrApiAccess::$user->rights->ecm->upload) { @@ -190,7 +189,7 @@ class Documents extends DolibarrApi $object=new Facture($db); $result = $object->fetch('', $ref); } - + if (! ($object->id > 0)) { throw new RestException(500, 'The object '.$modulepart." with ref '".$ref."' was not found."); @@ -198,7 +197,7 @@ class Documents extends DolibarrApi $tmp = dol_check_secure_access_document($modulepart, $tmpreldir.$object->ref, $entity, DolibarrApiAccess::$user, $ref, 'write'); $upload_dir = $tmp['original_file']; - + if (empty($upload_dir) || $upload_dir == '/') { throw new RestException(500, 'This value of modulepart does not support yet usage of ref. Check modulepart parameter or try to use subdir parameter instead of ref.'); @@ -207,7 +206,7 @@ class Documents extends DolibarrApi else { if ($modulepart == 'invoice') $modulepart ='facture'; - + $tmp = dol_check_secure_access_document($modulepart, $subdir, $entity, DolibarrApiAccess::$user, '', 'write'); $upload_dir = $tmp['original_file']; @@ -216,14 +215,14 @@ class Documents extends DolibarrApi throw new RestException(500, 'This value of modulepart does not support yet usage of ref. Check modulepart parameter or try to use subdir parameter instead of ref.'); } } - - + + $upload_dir = dol_sanitizePathName($upload_dir); - + $destfile = $upload_dir . '/' . $original_file; $destfiletmp = DOL_DATA_ROOT.'/admin/temp/' . $original_file; dol_delete_file($destfiletmp); - + if (!dol_is_dir($upload_dir)) { throw new RestException(401,'Directory not exists : '.$upload_dir); } @@ -232,7 +231,7 @@ class Documents extends DolibarrApi { throw new RestException(500, "File with name '".$original_file."' already exists."); } - + $fhandle = @fopen($destfiletmp, 'w'); if ($fhandle) { @@ -244,9 +243,9 @@ class Documents extends DolibarrApi { throw new RestException(500, "Failed to open file '".$destfiletmp."' for write"); } - + $result = dol_move($destfiletmp, $destfile, 0, $overwriteifexists, 1); - + return $result; } diff --git a/htdocs/document.php b/htdocs/document.php index 0b2db2323cd..a0b764882f8 100644 --- a/htdocs/document.php +++ b/htdocs/document.php @@ -27,6 +27,7 @@ * \remarks Call of this wrapper is made with URL: * document.php?modulepart=repfichierconcerne&file=relativepathoffile * document.php?modulepart=logs&file=dolibarr.log + * document.php?modulepart=logs&hashp=sharekey */ define('NOTOKENRENEWAL',1); // Disables token renewal From 801a5180d64bd4d9e38db9c962c161d9cf802b24 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Fri, 6 Oct 2017 00:26:24 +0200 Subject: [PATCH 40/46] Fix scrutinizer bug reports --- htdocs/adherents/class/adherent.class.php | 7 ++----- htdocs/adherents/class/adherent_type.class.php | 4 ++-- htdocs/admin/dict.php | 4 ++-- htdocs/api/class/api_documents.class.php | 2 +- htdocs/core/class/extrafields.class.php | 2 +- htdocs/core/modules/DolibarrModules.class.php | 4 ++-- htdocs/ecm/class/ecmfiles.class.php | 11 +++++------ htdocs/expedition/class/expedition.class.php | 4 ++-- htdocs/fichinter/class/fichinter.class.php | 10 +++++----- htdocs/holiday/class/holiday.class.php | 3 ++- htdocs/user/class/user.class.php | 4 ++-- htdocs/websites/index.php | 16 ++++++---------- 12 files changed, 32 insertions(+), 39 deletions(-) diff --git a/htdocs/adherents/class/adherent.class.php b/htdocs/adherents/class/adherent.class.php index 513a99d843f..037d27ea852 100644 --- a/htdocs/adherents/class/adherent.class.php +++ b/htdocs/adherents/class/adherent.class.php @@ -1562,7 +1562,7 @@ class Adherent extends CommonObject * * @param int $withpictoimg 0=No picto, 1=Include picto into link, 2=Only picto, -1=Include photo into link, -2=Only picto photo, -3=Only photo very small) * @param int $maxlen length max label - * @param string $option Page for link + * @param string $option Page for link ('card', 'category', 'subscription', ...) * @param string $mode ''=Show firstname and lastname, 'firstname'=Show only firstname, 'login'=Show login, 'ref'=Show ref * @param string $morecss Add more css on link * @param int $save_lastsearch_value -1=Auto, 0=No save of lastsearch_values when clicking, 1=Save lastsearch_values whenclicking @@ -1592,10 +1592,7 @@ class Adherent extends CommonObject $label.= '
' . $langs->trans('Name') . ': ' . $this->getFullName($langs); $label.=''; - if (empty($option) || $option == 'card' || $option == 'category') - { - $url = DOL_URL_ROOT.'/adherents/card.php?rowid='.$this->id; - } + $url = DOL_URL_ROOT.'/adherents/card.php?rowid='.$this->id; if ($option == 'subscription') { $url = DOL_URL_ROOT.'/adherents/subscription.php?rowid='.$this->id; diff --git a/htdocs/adherents/class/adherent_type.class.php b/htdocs/adherents/class/adherent_type.class.php index 30c85618bfa..5537730e678 100644 --- a/htdocs/adherents/class/adherent_type.class.php +++ b/htdocs/adherents/class/adherent_type.class.php @@ -59,7 +59,7 @@ class AdherentType extends CommonObject public $note; /** @var bool Can vote*/ public $vote; - /** @var bool Email sent during validation */ + /** @var string Email sent during validation */ public $mail_valid; /** @var array Array of members */ public $members=array(); @@ -481,7 +481,7 @@ class AdherentType extends CommonObject // Initialise parametres $this->id = 0; - $this->ref = 0; + $this->ref = 'MTSPEC'; $this->specimen=1; $this->label='MEMBERS TYPE SPECIMEN'; diff --git a/htdocs/admin/dict.php b/htdocs/admin/dict.php index 673ce2f2d24..068513b245c 100644 --- a/htdocs/admin/dict.php +++ b/htdocs/admin/dict.php @@ -1749,7 +1749,7 @@ $db->close(); * @param Object $obj If we show a particular record, obj is filled with record fields * @param string $tabname Name of SQL table * @param string $context 'add'=Output field for the "add form", 'edit'=Output field for the "edit form", 'hide'=Output field for the "add form" but we dont want it to be rendered - * @return void + * @return string '' or value of entity into table */ function fieldList($fieldlist, $obj='', $tabname='', $context='') { @@ -1763,7 +1763,7 @@ function fieldList($fieldlist, $obj='', $tabname='', $context='') $formcompany = new FormCompany($db); if (! empty($conf->accounting->enabled)) $formaccounting = new FormAccounting($db); - $withentity=null; + $withentity=''; foreach ($fieldlist as $field => $value) { diff --git a/htdocs/api/class/api_documents.class.php b/htdocs/api/class/api_documents.class.php index 670d47ba3ee..123b5f50bd8 100644 --- a/htdocs/api/class/api_documents.class.php +++ b/htdocs/api/class/api_documents.class.php @@ -104,7 +104,7 @@ class Documents extends DolibarrApi { require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php'; $this->invoice = new Facture($this->db); - $result = $this->invoice->fetch(0, $ref); + $result = $this->invoice->fetch(0, preg_replace('/\.[^\.]+$/', '', basename($original_file))); if( ! $result ) { throw new RestException(404, 'Invoice not found'); } diff --git a/htdocs/core/class/extrafields.class.php b/htdocs/core/class/extrafields.class.php index b4381349aec..73634f0d5e8 100644 --- a/htdocs/core/class/extrafields.class.php +++ b/htdocs/core/class/extrafields.class.php @@ -930,7 +930,7 @@ class ExtraFields if (!empty($value)) { // $value in memory is a php numeric, we format it into user number format. $value=price($value); } - $out.=' '.$langs->getCurrencySymbol($conf->currency); + $out=' '.$langs->getCurrencySymbol($conf->currency); } elseif ($type == 'double') { diff --git a/htdocs/core/modules/DolibarrModules.class.php b/htdocs/core/modules/DolibarrModules.class.php index b11389905a4..11f8b70f26b 100644 --- a/htdocs/core/modules/DolibarrModules.class.php +++ b/htdocs/core/modules/DolibarrModules.class.php @@ -328,14 +328,14 @@ class DolibarrModules // Can not be abstract, because we need to insta public $langfiles; /** - * @var string[] Array of warnings to show when we activate the module + * @var array Array of warnings to show when we activate the module * * array('always'='text') or array('FR'='text') */ public $warnings_activation; /** - * @var string[] Array of warnings to show when we activate an external module + * @var array Array of warnings to show when we activate an external module * * array('always'='text') or array('FR'='text') */ diff --git a/htdocs/ecm/class/ecmfiles.class.php b/htdocs/ecm/class/ecmfiles.class.php index 0035b18d3c7..7af07c8675b 100644 --- a/htdocs/ecm/class/ecmfiles.class.php +++ b/htdocs/ecm/class/ecmfiles.class.php @@ -82,10 +82,9 @@ class EcmFiles //extends CommonObject /** * Create object into database * - * @param User $user User that creates - * @param bool $notrigger false=launch triggers after, true=disable triggers - * - * @return int <0 if KO, Id of created object if OK + * @param User $user User that creates + * @param bool $notrigger false=launch triggers after, true=disable triggers + * @return int <0 if KO, Id of created object if OK */ public function create(User $user, $notrigger = false) { @@ -144,8 +143,8 @@ class EcmFiles //extends CommonObject if (empty($this->date_c)) $this->date_c = dol_now(); // If ref not defined - if (empty($ref)) $ref = dol_hash($this->filepath.'/'.$this->filename, 3); - + $ref = dol_hash($this->filepath.'/'.$this->filename, 3); + if (! empty($this->ref)) $ref=$this->ref; $maxposition=0; if (empty($this->position)) // Get max used diff --git a/htdocs/expedition/class/expedition.class.php b/htdocs/expedition/class/expedition.class.php index 014c9de3a19..f26efeadc4a 100644 --- a/htdocs/expedition/class/expedition.class.php +++ b/htdocs/expedition/class/expedition.class.php @@ -1487,14 +1487,14 @@ class Expedition extends CommonObject * Return clicable link of object (with eventually picto) * * @param int $withpicto Add picto into link - * @param int $option Where point the link + * @param string $option Where the link point to * @param int $max Max length to show * @param int $short Use short labels * @param int $notooltip 1=No tooltip * @param int $save_lastsearch_value -1=Auto, 0=No save of lastsearch_values when clicking, 1=Save lastsearch_values whenclicking * @return string String with URL */ - function getNomUrl($withpicto=0, $option=0, $max=0, $short=0, $notooltip=0, $save_lastsearch_value=-1) + function getNomUrl($withpicto=0, $option='', $max=0, $short=0, $notooltip=0, $save_lastsearch_value=-1) { global $langs; diff --git a/htdocs/fichinter/class/fichinter.class.php b/htdocs/fichinter/class/fichinter.class.php index bdbb03492f7..b67e5073144 100644 --- a/htdocs/fichinter/class/fichinter.class.php +++ b/htdocs/fichinter/class/fichinter.class.php @@ -663,7 +663,7 @@ class Fichinter extends CommonObject */ function getNomUrl($withpicto=0, $option='', $notooltip=0, $save_lastsearch_value=-1) { - global $langs; + global $conf, $langs; $result=''; @@ -674,13 +674,13 @@ class Fichinter extends CommonObject $picto='intervention'; $url = DOL_URL_ROOT.'/fichinter/card.php?id='.$this->id; - //if ($option !== 'nolink') - //{ - // Add param to save lastsearch_values or not + 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'; - //} + } $linkclose=''; if (empty($notooltip)) diff --git a/htdocs/holiday/class/holiday.class.php b/htdocs/holiday/class/holiday.class.php index 70d00bd2f01..382530225fd 100644 --- a/htdocs/holiday/class/holiday.class.php +++ b/htdocs/holiday/class/holiday.class.php @@ -781,12 +781,13 @@ class Holiday extends CommonObject $num_rows = $this->db->num_rows($resql); // Note, we can have 2 records if on is morning and the other one is afternoon if ($num_rows > 0) { + $arrayofrecord=array(); $i=0; while ($i < $num_rows) { $obj = $this->db->fetch_object($resql); - // Note: $obj->halday is 0:Full days, 2:Sart afternoon end morning, -1:Start afternoon, 1:End morning + // Note: $obj->halfday is 0:Full days, 2:Sart afternoon end morning, -1:Start afternoon, 1:End morning $arrayofrecord[$obj->rowid]=array('date_start'=>$this->db->jdate($obj->date_start), 'date_end'=>$this->db->jdate($obj->date_end), 'halfday'=>$obj->halfday); $i++; } diff --git a/htdocs/user/class/user.class.php b/htdocs/user/class/user.class.php index a7c2d0f1a6b..980faafc028 100644 --- a/htdocs/user/class/user.class.php +++ b/htdocs/user/class/user.class.php @@ -2109,8 +2109,8 @@ class User extends CommonObject if (! empty($_SESSION["disablemodules"])) $label.= '
'.$langs->trans("DisabledModules").':
'.join(', ',explode(',',$_SESSION["disablemodules"])); } - if ($option == 'leave') $url.= DOL_URL_ROOT.'/holiday/list.php?id='.$this->id; - else $link.= $url.= DOL_URL_ROOT.'/user/card.php?id='.$this->id; + $url = DOL_URL_ROOT.'/user/card.php?id='.$this->id; + if ($option == 'leave') $url = DOL_URL_ROOT.'/holiday/list.php?id='.$this->id; if ($option != 'nolink') { diff --git a/htdocs/websites/index.php b/htdocs/websites/index.php index a6de8c15c65..f2b94ff5705 100644 --- a/htdocs/websites/index.php +++ b/htdocs/websites/index.php @@ -1861,7 +1861,6 @@ function dolSaveHtmlHeader($filehtmlheader, $htmlheadercontent) if (! $result) { - $error++; setEventMessages('Failed to write file '.$filehtmlheader, null, 'errors'); return false; } @@ -1887,14 +1886,13 @@ function dolSaveCssFile($filecss, $csscontent) if (! empty($conf->global->MAIN_UMASK)) @chmod($filecss, octdec($conf->global->MAIN_UMASK)); - if (! $result) - { - $error++; - setEventMessages('Failed to write file '.$filecss, null, 'errors'); - return false; - } + if (! $result) + { + setEventMessages('Failed to write file '.$filecss, null, 'errors'); + return false; + } - return true; + return true; } /** @@ -1917,7 +1915,6 @@ function dolSaveRobotFile($filerobot, $robotcontent) if (! $result) { - $error++; setEventMessages('Failed to write file '.$filerobot, null, 'errors'); return false; } @@ -1945,7 +1942,6 @@ function dolSaveHtaccessFile($filehtaccess, $htaccess) if (! $result) { - $error++; setEventMessages('Failed to write file '.$filehtaccess, null, 'errors'); return false; } From c06a78145cedb8d74fe4c7f0b3a3700f5e49cc11 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Fri, 6 Oct 2017 01:27:41 +0200 Subject: [PATCH 41/46] Rename function to avoid duplicate --- scripts/members/sync_members_types_ldap2dolibarr.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/members/sync_members_types_ldap2dolibarr.php b/scripts/members/sync_members_types_ldap2dolibarr.php index fb8fb160d36..55d5606cd30 100755 --- a/scripts/members/sync_members_types_ldap2dolibarr.php +++ b/scripts/members/sync_members_types_ldap2dolibarr.php @@ -69,7 +69,7 @@ $required_fields = array( ); // Remove from required_fields all entries not configured in LDAP (empty) and duplicated -$required_fields=array_unique(array_values(array_filter($required_fields, "dolValidElement"))); +$required_fields=array_unique(array_values(array_filter($required_fields, "dolValidElementType"))); if (! isset($argv[1])) { @@ -214,7 +214,7 @@ exit($error); * @param string $element Value to test * @return boolean True of false */ -function dolValidElement($element) +function dolValidElementType($element) { return (trim($element) != ''); } From e644d9d53f59e5443f292f9bfd91c91a1168ad9e Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Fri, 6 Oct 2017 01:46:48 +0200 Subject: [PATCH 42/46] Fix syntax code --- htdocs/core/login/functions_ldap.php | 2 +- htdocs/core/modules/dons/html_cerfafr.modules.php | 14 +++++++------- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/htdocs/core/login/functions_ldap.php b/htdocs/core/login/functions_ldap.php index 129bbcedf38..247dc4ac6ae 100644 --- a/htdocs/core/login/functions_ldap.php +++ b/htdocs/core/login/functions_ldap.php @@ -138,7 +138,7 @@ function check_user_password_ldap($usertotest,$passwordtotest,$entitytotest) $ldap->searchUser=$ldapuserattr."=".$usertotest.",".$ldapdn; // Default dn (will work if LDAP accept a dn with login value inside) // But if LDAP need a dn with name like "cn=Jhon Bloggs,ou=People,dc=foo,dc=com", previous part must have been executed to have // dn detected into ldapUserDN. - if ($resultFetchLdapUser AND !empty($ldap->ldapUserDN)) $ldap->searchUser = $ldap->ldapUserDN; + if ($resultFetchLdapUser && !empty($ldap->ldapUserDN)) $ldap->searchUser = $ldap->ldapUserDN; $ldap->searchPassword=$passwordtotest; // Test with this->seachUser and this->searchPassword diff --git a/htdocs/core/modules/dons/html_cerfafr.modules.php b/htdocs/core/modules/dons/html_cerfafr.modules.php index 24027375528..f3e0146a719 100644 --- a/htdocs/core/modules/dons/html_cerfafr.modules.php +++ b/htdocs/core/modules/dons/html_cerfafr.modules.php @@ -136,27 +136,27 @@ class html_cerfafr extends ModeleDon else $paymentmode = ''; if ($don->modepaiementid==7){ - $ModePaiement = '
'; + $ModePaiement = ''; } else if ($don->modepaiementid==4){ - $ModePaiement = ''; + $ModePaiement = ''; } - else if ($don->modepaiementid==2 OR $don->modepaiementid==3 OR $don->modepaiementid==6){ - $ModePaiement = ''; + else if ($don->modepaiementid==2 || $don->modepaiementid==3 || $don->modepaiementid==6){ + $ModePaiement = ''; } else { - $ModePaiement = ''; + $ModePaiement = ''; } /* if (empty($don->societe)) { - $CodeDon = ''; + $CodeDon = ''; } else { - $CodeDon = ''; + $CodeDon = ''; } */ From 67c571f9527fc80f6569748a35ee52181205965b Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Fri, 6 Oct 2017 01:59:26 +0200 Subject: [PATCH 43/46] Increase cyclomatic complexity threshold --- dev/setup/codesniffer/ruleset.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dev/setup/codesniffer/ruleset.xml b/dev/setup/codesniffer/ruleset.xml index 32a938662e6..b8cb751fe9e 100644 --- a/dev/setup/codesniffer/ruleset.xml +++ b/dev/setup/codesniffer/ruleset.xml @@ -126,7 +126,7 @@ - + From 848aadb48a74cafd019cf34d88d63a9f72fced49 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Fri, 6 Oct 2017 10:46:45 +0200 Subject: [PATCH 44/46] FIX Do not lose selected id after ENTER the TAB on autocomplete --- htdocs/core/lib/ajax.lib.php | 11 +++++++---- htdocs/core/lib/functions.lib.php | 2 +- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/htdocs/core/lib/ajax.lib.php b/htdocs/core/lib/ajax.lib.php index 3cc767c1592..5e9ca5582b5 100644 --- a/htdocs/core/lib/ajax.lib.php +++ b/htdocs/core/lib/ajax.lib.php @@ -63,10 +63,13 @@ function ajax_autocompleter($selected, $htmlname, $url, $urloption='', $minLengt var autoselect = '.$autoselect.'; var options = '.json_encode($ajaxoptions).'; - /* Remove product id before select another product use keyup instead of change to avoid loosing the product id. This is needed only for select of predefined product */ - /* TODO Check if we can remove this */ - $("input#search_'.$htmlname.'").keydown(function() { - $("#'.$htmlname.'").val(""); + /* Remove selected id as soon as we type or delete a char (it means old selection is wrong). Use keyup/down instead of change to avoid loosing the product id. This is needed only for select of predefined product */ + $("input#search_'.$htmlname.'").keydown(function(e) { + if (e.keyCode != 9) /* If not "Tab" key */ + { + console.log("Clear id previously selected for field '.$htmlname.'"); + $("#'.$htmlname.'").val(""); + } }); /* I disable this. A call to trigger is already done later into the select action of the autocomplete code diff --git a/htdocs/core/lib/functions.lib.php b/htdocs/core/lib/functions.lib.php index c43ecf9d038..151a9abd057 100644 --- a/htdocs/core/lib/functions.lib.php +++ b/htdocs/core/lib/functions.lib.php @@ -6378,7 +6378,7 @@ function dolExplodeIntoArray($string, $delimiter = ';', $kv = '=') /** - * Set focus onto field with selector + * Set focus onto field with selector (similar behaviour of 'autofocus' HTML5 tag) * * @param string $selector Selector ('#id' or 'input[name="ref"]') to use to find the HTML input field that must get the autofocus. You must use a CSS selector, so unique id preceding with the '#' char. * @return string HTML code to set focus From edacf6789bb23e3e5e1b4a9eff0104148dab459c Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Fri, 6 Oct 2017 10:47:58 +0200 Subject: [PATCH 45/46] Remove dead code --- htdocs/core/lib/ajax.lib.php | 6 ------ 1 file changed, 6 deletions(-) diff --git a/htdocs/core/lib/ajax.lib.php b/htdocs/core/lib/ajax.lib.php index 5e9ca5582b5..500bbbb3ffb 100644 --- a/htdocs/core/lib/ajax.lib.php +++ b/htdocs/core/lib/ajax.lib.php @@ -72,12 +72,6 @@ function ajax_autocompleter($selected, $htmlname, $url, $urloption='', $minLengt } }); - /* I disable this. A call to trigger is already done later into the select action of the autocomplete code - $("input#search_'.$htmlname.'").change(function() { - console.log("Call the change trigger on input '.$htmlname.' because of a change on search_'.$htmlname.' was triggered"); - $("#'.$htmlname.'").trigger("change"); - });*/ - // Check options for secondary actions when keyup $("input#search_'.$htmlname.'").keyup(function() { if ($(this).val().length == 0) From 7b1fe6e5af0a0bfe1fe44de03f031ffa3ce1b41a Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Fri, 6 Oct 2017 11:02:44 +0200 Subject: [PATCH 46/46] Look and feel v6 --- htdocs/accountancy/admin/accountmodel.php | 206 ++++----------------- htdocs/accountancy/admin/journals_list.php | 37 ++-- htdocs/compta/sociales/card.php | 6 +- 3 files changed, 53 insertions(+), 196 deletions(-) diff --git a/htdocs/accountancy/admin/accountmodel.php b/htdocs/accountancy/admin/accountmodel.php index 5c17f07183e..66f2e156b4c 100644 --- a/htdocs/accountancy/admin/accountmodel.php +++ b/htdocs/accountancy/admin/accountmodel.php @@ -87,9 +87,6 @@ $hookmanager->initHooks(array('admin')); // This page is a generic page to edit dictionaries // Put here declaration of dictionaries properties -// Sort order to show dictionary (0 is space). All other dictionaries (added by modules) will be at end of this. -$taborder=array(9,0,4,3,2,0,1,8,19,16,27,0,5,11,0,33,34,0,6,0,29,0,7,17,24,28,0,10,23,12,13,0,14,0,22,20,18,21,0,15,30,0,25,0,26,0,31,32,0); - // Name of SQL tables of dictionaries $tabname=array(); @@ -148,75 +145,10 @@ $tabfieldcheck=array(); $tabfieldcheck[31] = array(); $tabfieldcheck[32] = array(); -// Complete all arrays with entries found into modules -complete_dictionary_with_modules($taborder,$tabname,$tablib,$tabsql,$tabsqlsort,$tabfield,$tabfieldvalue,$tabfieldinsert,$tabrowid,$tabcond,$tabhelp,$tabfieldcheck); - // Define elementList and sourceList (used for dictionary type of contacts "llx_c_type_contact") $elementList = array(); $sourceList=array(); -if ($id == 11) -{ - $langs->load("orders"); - $langs->load("contracts"); - $langs->load("projects"); - $langs->load("propal"); - $langs->load("bills"); - $langs->load("interventions"); - $elementList = array( - '' => '', - 'societe' => $langs->trans('ThirdParty'), -// 'proposal' => $langs->trans('Proposal'), -// 'order' => $langs->trans('Order'), -// 'invoice' => $langs->trans('Bill'), - 'invoice_supplier' => $langs->trans('SupplierBill'), - 'order_supplier' => $langs->trans('SupplierOrder'), -// 'intervention' => $langs->trans('InterventionCard'), -// 'contract' => $langs->trans('Contract'), - 'project' => $langs->trans('Project'), - 'project_task' => $langs->trans('Task'), - 'agenda' => $langs->trans('Agenda'), - // old deprecated - 'contrat' => $langs->trans('Contract'), - 'propal' => $langs->trans('Proposal'), - 'commande' => $langs->trans('Order'), - 'facture' => $langs->trans('Bill'), - 'resource' => $langs->trans('Resource'), -// 'facture_fourn' => $langs->trans('SupplierBill'), - 'fichinter' => $langs->trans('InterventionCard') - ); - if (! empty($conf->global->MAIN_SUPPORT_SHARED_CONTACT_BETWEEN_THIRDPARTIES)) $elementList["societe"] = $langs->trans('ThirdParty'); - - complete_elementList_with_modules($elementList); - - asort($elementList); - $sourceList = array( - 'internal' => $langs->trans('Internal'), - 'external' => $langs->trans('External') - ); -} -if ($id == 25) -{ - // We save list of template email Dolibarr can manage. This list can found by a grep into code on "->param['models']" - $elementList = array(); - if ($conf->propal->enabled) $elementList['propal_send']=$langs->trans('MailToSendProposal'); - if ($conf->commande->enabled) $elementList['order_send']=$langs->trans('MailToSendOrder'); - if ($conf->facture->enabled) $elementList['facture_send']=$langs->trans('MailToSendInvoice'); - if ($conf->expedition->enabled) $elementList['shipping_send']=$langs->trans('MailToSendShipment'); - if ($conf->ficheinter->enabled) $elementList['fichinter_send']=$langs->trans('MailToSendIntervention'); - if ($conf->supplier_proposal->enabled) $elementList['supplier_proposal_send']=$langs->trans('MailToSendSupplierRequestForQuotation'); - if ($conf->fournisseur->enabled) $elementList['order_supplier_send']=$langs->trans('MailToSendSupplierOrder'); - if ($conf->fournisseur->enabled) $elementList['invoice_supplier_send']=$langs->trans('MailToSendSupplierInvoice'); - if ($conf->societe->enabled) $elementList['thirdparty']=$langs->trans('MailToThirdparty'); - - $parameters=array('elementList'=>$elementList); - $reshook=$hookmanager->executeHooks('emailElementlist',$parameters); // Note that $action and $object may have been modified by some hooks - if ($reshook == 0) { - foreach ($hookmanager->resArray as $item => $value) { - $elementList[$item] = $value; - } - } -} @@ -690,7 +622,6 @@ if ($id) if ($fieldlist[$field]=='libelle' || $fieldlist[$field]=='label') $alabelisused=1; } - if ($id == 4) print ''; print ''; @@ -731,7 +662,6 @@ if ($id) } } - if ($id == 4) print ''; print '"; $colspan=count($fieldlist)+3; - if ($id == 4) $colspan++; - if (! empty($alabelisused) && $id != 25) // If there is one label among fields, we show legend of * + if (! empty($alabelisused)) // If there is one label among fields, we show legend of * { print ''; } @@ -775,9 +704,38 @@ if ($id) print ''; } - // Title of lines + // Title line with search boxes print ''; foreach ($fieldlist as $field => $value) + { + $showfield=1; // By defaut + + if ($fieldlist[$field]=='region_id' || $fieldlist[$field]=='country_id') { $showfield=0; } + + if ($showfield) + { + if ($value == 'country') + { + print ''; + } + else + { + print ''; + } + } + } + print ''; + print ''; + print ''; + + // Title of lines + print ''; + foreach ($fieldlist as $field => $value) { // Determine le nom du champ par rapport aux noms possibles // dans les dictionnaires de donnees @@ -845,44 +803,11 @@ if ($id) print getTitleFieldOfList($valuetoshow, 0, $_SERVER["PHP_SELF"], ($sortable?$fieldlist[$field]:''), ($page?'page='.$page.'&':''), $param, "align=".$align, $sortfield, $sortorder); } } - // Favorite - Only activated on country dictionary - if ($id == 4) print getTitleFieldOfList($langs->trans("Favorite"), 0, $_SERVER["PHP_SELF"], "favorite", ($page?'page='.$page.'&':''), $param, 'align="center"', $sortfield, $sortorder); - print getTitleFieldOfList($langs->trans("Status"), 0, $_SERVER["PHP_SELF"], "active", ($page?'page='.$page.'&':''), $param, 'align="center"', $sortfield, $sortorder); print getTitleFieldOfList(''); print getTitleFieldOfList(''); print ''; - // Title line with search boxes - print ''; - foreach ($fieldlist as $field => $value) - { - $showfield=1; // By defaut - - if ($fieldlist[$field]=='region_id' || $fieldlist[$field]=='country_id') { $showfield=0; } - - if ($showfield) - { - if ($value == 'country') - { - print ''; - } - else - { - print ''; - } - } - } - if ($id == 4) print ''; - print ''; - print ''; - print ''; - if ($num) { // Lines with values @@ -1090,16 +1015,6 @@ if ($id) if ($param) $url .= '&'.$param; $url.='&'; - // Favorite - // Only activated on country dictionary - if ($id == 4) - { - print ''; - } - // Active print ''; } + // Title line with search boxes + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + // Title of lines - print ''; + print ''; foreach ($fieldlist as $field => $value) { // Determine le nom du champ par rapport aux noms possibles @@ -562,23 +580,6 @@ if ($id) print getTitleFieldOfList(''); print ''; - // Title line with search boxes - print ''; - print ''; - print ''; - print ''; - print ''; - print ''; - print ''; - print ''; - print ''; - if ($num) { // Lines with values diff --git a/htdocs/compta/sociales/card.php b/htdocs/compta/sociales/card.php index a8f795115c4..7dff138f849 100644 --- a/htdocs/compta/sociales/card.php +++ b/htdocs/compta/sociales/card.php @@ -308,7 +308,7 @@ if ($action == 'create') print ''; - print ''; + print ''; print ''; print ''; @@ -317,7 +317,7 @@ if ($action == 'create') print $langs->trans("Type"); print ''; print ''; print ''; @@ -336,7 +336,7 @@ if ($action == 'create') print ''; - print ''; + print ''; print ''; // Project
" . $langs->trans("Piece") . ' (' . $langs->trans("InvoiceRef") . ")" . $langs->trans("AccountAccounting") . "" . $langs->trans("SubledgerAccount") . "" . $langs->trans("Label") . "" . $langs->trans("LabelOperation") . "" . $langs->trans("Debit") . "" . $langs->trans("Credit") . "
" . $companystatic->getNomUrl(0, 'supplier', 16) . ' - ' . $invoicestatic->refsupplier . ' - ' . $langs->trans("SubledgerAccount") . "' . ($mt < 0 ? - price(- $mt) : '') . "' . ($mt >= 0 ? price($mt) : '') . "
"; print '" . $companystatic->getNomUrl(0, 'supplier', 16) . ' - ' . $invoicestatic->refsupplier . ' - ' . $langs->trans("VAT"). ' '.join(', ',$def_tva[$key][$k]).($numtax?' - Localtax '.$numtax:''); + print "" . $companystatic->getNomUrl(0, 'supplier', 16) . ' - ' . $invoicestatic->refsupplier . ' - ' . $langs->trans("VAT"). ' '.join(', ',$def_tva[$key][$k]).' %'.($numtax?' - Localtax '.$numtax:''); print "' . ($mt >= 0 ? price($mt) : '') . "' . ($mt < 0 ? price(- $mt) : '') . "" . $langs->trans("Piece") . ' (' . $langs->trans("InvoiceRef") . ")" . $langs->trans("AccountAccounting") . "" . $langs->trans("SubledgerAccount") . "" . $langs->trans("Label") . "" . $langs->trans("LabelOperation") . "" . $langs->trans("Debit") . "" . $langs->trans("Credit") . "
"; print '" . $companystatic->getNomUrl(0, 'customer', 16) . ' - ' . $invoicestatic->ref . ' - ' . $langs->trans("VAT"). ' '.join(', ',$def_tva[$key][$k]).($numtax?' - Localtax '.$numtax:''); + print "" . $companystatic->getNomUrl(0, 'customer', 16) . ' - ' . $invoicestatic->ref . ' - ' . $langs->trans("VAT"). ' '.join(', ',$def_tva[$key][$k]).' %'.($numtax?' - Localtax '.$numtax:''); print "' . ($mt < 0 ? price(- $mt) : '') . "' . ($mt >= 0 ? price($mt) : '') . " Remise d\'espèces Chèque Virement, prélèvement, carte bancaire Remise d\'espèces Chèque Virement, prélèvement, carte bancaire Remise d\'espèces Chèque Virement, prélèvement, carte bancaire Remise d\'espèces Chèque Virement, prélèvement, carte bancaire Remise d\'espèces Chèque Virement, prélèvement, carte bancaire Remise d\'espèces Chèque Virement, prélèvement, carte bancaire Remise d\'espèces Chèque Virement, prélèvement, carte bancaire Remise d\'espèces Chèque Virement, prélèvement, carte bancaire 200 du CGI 238 bis du CGI 885-0 V bis A du CGI 200 du CGI 238 bis du CGI 885-0 V bis A du CGI 200 du CGI 238 bis du CGI 885-0 V bis A du CGI 200 du CGI 238 bis du CGI 885-0 V bis A du CGI'; print ''; print ''; if ($tabname[$id] != MAIN_DB_PREFIX.'c_email_templates' || $action != 'edit') { @@ -741,9 +671,8 @@ if ($id) print "
* '.$langs->trans("LabelUsedByDefault").'.
'; + print $form->select_country($search_country_id, 'search_country_id', '', 28, 'maxwidth200 maxwidthonsmartphone'); + print ''; + $searchpicto=$form->showFilterAndCheckAddButtons(0); + print $searchpicto; + print '
'; - print $form->select_country($search_country_id, 'search_country_id', '', 28, 'maxwidth200 maxwidthonsmartphone'); - print ''; - $searchpicto=$form->showFilterAndCheckAddButtons(0); - print $searchpicto; - print '
'; - if ($iserasable) print ''.$actl[$obj->favorite].''; - else print $langs->trans("AlwaysActive"); - print ''; if ($canbedisabled) print ''.$actl[$obj->active].''; @@ -1135,65 +1050,6 @@ if ($id) print ''; } -else -{ - /* - * Show list of dictionary to show - */ - - $lastlineisempty=false; - print ''; - print ''; - //print ''; - print ''; - print ''; - print ''; - - $showemptyline=''; - foreach ($taborder as $i) - { - if (isset($tabname[$i]) && empty($tabcond[$i])) continue; - - if ($i) - { - if ($showemptyline) - { - print ''; - $showemptyline=0; - } - - - $value=$tabname[$i]; - print ''; - print ''; - print ''; - $lastlineisempty=false; - } - else - { - if (! $lastlineisempty) - { - $showemptyline=1; - $lastlineisempty=true; - } - } - } - print '
'.$langs->trans("Module").''.$langs->trans("Dictionary").''.$langs->trans("Table").'
   
'; - if (! empty($tabcond[$i])) - { - print ''.$langs->trans($tablib[$i]).''; - } - else - { - print $langs->trans($tablib[$i]); - } - print ''; - /*if (empty($tabcond[$i])) - { - print info_admin($langs->trans("DictionaryDisabledSinceNoModuleNeedIt"),1); - }*/ - print ''.$tabname[$i].'
'; -} print '
'; diff --git a/htdocs/accountancy/admin/journals_list.php b/htdocs/accountancy/admin/journals_list.php index 2271fa73c0b..9bbd37449be 100644 --- a/htdocs/accountancy/admin/journals_list.php +++ b/htdocs/accountancy/admin/journals_list.php @@ -354,6 +354,7 @@ if ($action == $acts[1]) } } + /* * View */ @@ -527,8 +528,25 @@ if ($id) print '
'; + if ($filterfound) + { + $searchpicto=$form->showFilterAndCheckAddButtons(0); + print $searchpicto; + } + print '
'; - if ($filterfound) - { - $searchpicto=$form->showFilterAndCheckAddButtons(0); - print $searchpicto; - } - print '
'; print $langs->trans("Label"); print '
'; - $formsocialcontrib->select_type_socialcontrib(GETPOST("actioncode")?GETPOST("actioncode"):'','actioncode',1); + $formsocialcontrib->select_type_socialcontrib(GETPOST("actioncode",'alpha')?GETPOST("actioncode",'alpha'):'','actioncode',1); print '
'; print $langs->trans("Amount"); print '