diff --git a/htdocs/core/ajax/row.php b/htdocs/core/ajax/row.php index 882a28f9c42..c7761cdfd27 100644 --- a/htdocs/core/ajax/row.php +++ b/htdocs/core/ajax/row.php @@ -1,5 +1,5 @@ +/* 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 @@ -35,11 +35,6 @@ require_once(DOL_DOCUMENT_ROOT."/core/class/genericobject.class.php"); * View */ -// Ajout directives pour resoudre bug IE -//header('Cache-Control: Public, must-revalidate'); -//header('Pragma: public'); - -//top_htmlhead("", "", 1); // Replaced with top_httphead. An ajax page does not need html header. top_httphead(); print ''."\n"; @@ -52,21 +47,16 @@ if((isset($_GET['roworder']) && !empty($_GET['roworder'])) && (isset($_GET['tabl foreach($roworder as $value) { - if (!empty($value)) - { - $newroworder[] = $value; - } + if (! empty($value)) $newroworder[] = $value; } - $roworder = implode(',',$newroworder); - - dol_syslog("AjaxRow roworder=".$_GET['roworder']." neworder=".$roworder." element=".$_GET['element'], LOG_DEBUG); + dol_syslog("AjaxRow roworder=".$_GET['roworder']." fk_element=".$_GET['fk_element'], LOG_DEBUG); $row=new GenericObject($db); $row->table_element_line = $_GET['table_element_line']; $row->fk_element = $_GET['fk_element']; $row->id = $_GET['element_id']; - $result=$row->line_ajaxorder($roworder); + $result=$row->line_ajaxorder($newroworder); $result=$row->line_order(true); } diff --git a/htdocs/core/class/commonobject.class.php b/htdocs/core/class/commonobject.class.php index 076cd861ddb..9549eaf371d 100644 --- a/htdocs/core/class/commonobject.class.php +++ b/htdocs/core/class/commonobject.class.php @@ -890,25 +890,75 @@ abstract class CommonObject } if ($nl > 0) { + $rows=array(); + $sql = 'SELECT rowid FROM '.MAIN_DB_PREFIX.$this->table_element_line; $sql.= ' WHERE '.$this->fk_element.' = '.$this->id; + $sql.= ' AND fk_parent_line IS NULL'; $sql.= ' ORDER BY rang ASC, rowid '.$rowidorder; dol_syslog(get_class($this)."::line_order sql=".$sql, LOG_DEBUG); $resql = $this->db->query($sql); if ($resql) { + $i=0; $num = $this->db->num_rows($resql); - $i = 0; while ($i < $num) { $row = $this->db->fetch_row($resql); - $this->updateRangOfLine($row[0], ($i+1)); + $rows[] = $row[0]; + $childrens = $this->getChildrensOfLine($row[0]); + if (! empty($childrens)) + { + foreach($childrens as $child) + { + array_push($rows, $child); + } + } $i++; } + + if (! empty($rows)) + { + foreach($rows as $key => $row) + { + $this->updateRangOfLine($row, ($key+1)); + } + } } } } + + /** + * Get childrens of line + * + * @param int $id Id of parent line + */ + function getChildrensOfLine($id) + { + $rows=array(); + + $sql = 'SELECT rowid FROM '.MAIN_DB_PREFIX.$this->table_element_line; + $sql.= ' WHERE '.$this->fk_element.' = '.$this->id; + $sql.= ' AND fk_parent_line = '.$id; + $sql.= ' ORDER BY rang ASC'; + + dol_syslog(get_class($this)."::getChildrenOfLines sql=".$sql, LOG_DEBUG); + $resql = $this->db->query($sql); + if ($resql) + { + $i=0; + $num = $this->db->num_rows($resql); + while ($i < $num) + { + $row = $this->db->fetch_row($resql); + $rows[$i] = $row[0]; + $i++; + } + } + + return $rows; + } /** * Update a line to have a lower rank @@ -966,13 +1016,11 @@ abstract class CommonObject /** * Update position of line with ajax (rang) * - * @param int $roworder + * @param array $rows Array of rows */ - function line_ajaxorder($roworder) + function line_ajaxorder($rows) { - $rows = explode(',',$roworder); $num = count($rows); - for ($i = 0 ; $i < $num ; $i++) { $this->updateRangOfLine($rows[$i], ($i+1)); diff --git a/htdocs/core/tpl/ajaxrow.tpl.php b/htdocs/core/tpl/ajaxrow.tpl.php index ca7dee493b2..59dc7b8ed78 100644 --- a/htdocs/core/tpl/ajaxrow.tpl.php +++ b/htdocs/core/tpl/ajaxrow.tpl.php @@ -1,5 +1,5 @@ +/* Copyright (C) 2010-2012 Regis Houssin * Copyright (C) 2010-2011 Laurent Destailleur * * This program is free software; you can redistribute it and/or modify @@ -21,22 +21,22 @@ lines) > 1 && $_GET['action'] != 'editline') { ?>