New: Ajout gestionnaire d'arbre HTML

Look: Mise au norme affiche fiche categorie
This commit is contained in:
Laurent Destailleur 2006-08-15 18:52:02 +00:00
parent 72f24f51c1
commit 14840849d3
7 changed files with 198 additions and 141 deletions

View File

@ -874,23 +874,29 @@ class Categorie
}
/**
* Retourne les catégories dont le nom correspond à $nom
* ajoute des wildcards sauf si $exact = true
* \brief Retourne les catégories dont l'id ou le nom correspond
* ajoute des wildcards au nom sauf si $exact = true
*/
function rechercher_par_nom ($nom, $exact = false)
function rechercher($id, $nom, $exact = false)
{
$cats = array ();
if (!$exact)
// Generation requete recherche
$sql = "SELECT rowid FROM ".MAIN_DB_PREFIX."categorie ";
if ($nom)
{
$nom = '%'.str_replace ('*', '%', $nom).'%';
if (! $exact)
{
$nom = '%'.str_replace ('*', '%', $nom).'%';
}
$sql.= "WHERE label LIKE '".$nom."'";
}
if ($id)
{
$sql.="WHERE rowid = '".$id."'";
}
$sql = "SELECT rowid FROM ".MAIN_DB_PREFIX."categorie ";
$sql .= "WHERE label LIKE '".$nom."'";
$res = $this->db->query ($sql);
if ($res)
{
while ($id = $this->db->fetch_array ($res))
@ -902,7 +908,10 @@ class Categorie
}
else
{
return 0;
$this->error=$this->db->error().' sql='.$sql;
//dolibarr_syslog($this->error);
dolibarr_print_error('',$this->error);
return -1;
}
}
}

View File

@ -31,26 +31,11 @@ $user->getrights();
if (!$user->rights->categorie->lire)
accessforbidden();
/*
* Affichage fiche
*/
llxHeader("","",$langs->trans("Categories"));
print_titre($langs->trans("ModifCat"));
print '<table border="0" width="100%">';
print '<tr><td valign="top" width="30%">';
$categorie = new Categorie ($db, $_REQUEST['id']);
$html = new Form($db);
// Action mise à jour d'une catégorie
if ($_POST["action"] == 'update' && $user->rights->categorie->creer)
{
$categorie = new Categorie ($db, $_REQUEST['id']);
$categorie->label = $_POST["nom"];
$categorie->description = $_POST["description"];
$categorie->visible = $_POST["visible"];
@ -69,22 +54,43 @@ if ($_POST["action"] == 'update' && $user->rights->categorie->creer)
{
if ($categorie->update() > 0)
{
$_GET["action"] = 'confirmed';
$_POST["addcat"] = '';
header('Location: '.DOL_URL_ROOT.'/categories/viewcat.php?id='.$categorie->id);
exit;
}
}
}
/*
* Affichage fiche
*/
llxHeader("","",$langs->trans("Categories"));
print_titre($langs->trans("ModifCat"));
print "<br>";
if ($categorie->error)
{
print '<div class="error">';
print $categorie->error;
print '</div>';
}
print '<tr><td valign="top" width="30%">';
$categorie = new Categorie ($db, $_REQUEST['id']);
$html = new Form($db);
print '<table class="notopnoleft" border="0" width="100%">';
print '<tr><td class="notopnoleft" valign="top" width="30%">';
print "\n";
print '<form method="post" action="'.$_SERVER['PHP_SELF'].'">';
print '<input type="hidden" name="action" value="update">';
print '<input type="hidden" name="id" value="'.$categorie->id.'">';
?>
<form method="post" action="<?php print $_SERVER['REQUEST_URI']; ?>">
<input type="hidden" name="action" value="update">
<table class="border" width="100%">
<tr>
<td><?php print $langs->trans("Label"); ?>&nbsp;:</td>
@ -101,7 +107,7 @@ print '<tr><td valign="top" width="30%">';
if ($conf->fckeditor->enabled && $conf->global->FCKEDITOR_ENABLE_PRODUCTDESC)
{
require_once(DOL_DOCUMENT_ROOT."/lib/doleditor.class.php");
$doleditor=new DolEditor('description',$categorie->description,240,'dolibarr_notes');
$doleditor=new DolEditor('description',$categorie->description,200,'dolibarr_notes');
$doleditor->Create();
}
else

View File

@ -67,7 +67,7 @@ if ($_POST["action"] == 'add' && $user->rights->categorie->creer)
if (!$categorie->label || !$categorie->description)
{
$_GET["action"] = 'create';
$categorie->error = $langs->trans(ErrForgotField);
$categorie->error = $langs->trans("ErrForgotField");
}
if ($categorie->error =="")
{
@ -84,11 +84,13 @@ if ($_POST["action"] == 'add' && $user->rights->categorie->creer)
if ($_GET["action"] == 'confirmed')
{
print_titre($langs->trans("CatCreated"));
print '<table border="0" width="100%">';
print '<tr><td valign="top" width="30%">';
print $langs->trans("TheCategorie").' '.$categorie->label.' '.$langs->trans("WasAddedSuccessfully");
print_titre($langs->trans("NewCategory"));
print '<br>';
print '<table class="notopnoleft" width="100%">';
print '<tr><td valign="top" class="notopnoleft" width="30%">';
print '<div class="ok">'.$langs->trans("CategorySuccessfullyCreated",$categorie->label).'</div>';
if ($_REQUEST['idprodorigin'])
{
@ -134,7 +136,7 @@ if ($user->rights->categorie->creer)
if ($conf->fckeditor->enabled && $conf->global->FCKEDITOR_ENABLE_PRODUCTDESC)
{
require_once(DOL_DOCUMENT_ROOT."/lib/doleditor.class.php");
$doleditor=new DolEditor('description',$categorie->description,240,'dolibarr_notes');
$doleditor=new DolEditor('description',$categorie->description,200,'dolibarr_notes');
$doleditor->Create();
}
else

View File

@ -36,15 +36,16 @@ if (!$user->rights->categorie->lire) accessforbidden();
* Affichage page accueil
*/
llxHeader("","",$langs->trans("ProductsCategoriesArea"));
$c = new Categorie($db);
$html = new Form($db);
llxHeader("","",$langs->trans("ProductsCategoriesArea"));
print_fiche_titre($langs->trans("ProductsCategoriesArea"));
print '<table border="0" width="100%" class="notopnoleftnoright">';
print '<tr><td valign="top" width="30%" class="notopnoleft">';
$c = new Categorie ($db);
/*
* Zone recherche produit/service
@ -74,10 +75,10 @@ print '</td><td valign="top" width="70%">';
/*
* Catégories trouvées
*/
if($_POST['catname'])
if($_POST['catname'] || $_REQUEST['id'])
{
$cats = $c->rechercher_par_nom ($_POST['catname']);
$cats = $c->rechercher($_REQUEST['id'],$_POST['catname']);
print '<table class="noborder" width="100%">';
print '<tr class="liste_titre"><td colspan="2">'.$langs->trans("FoundCats").'</td></tr>';
@ -107,91 +108,97 @@ $cate_arbo = $c->get_full_arbo();
* Catégories en javascript
*/
/*
if ($conf->use_javascript)
{
print '<table class="noborder" width="100%">';
print '<tr class="liste_titre"><td>'.$langs->trans("AllCats").'</td></tr>';
print '<tr class="liste_titre"><td>'.$langs->trans("CategoriesTree").'</td></tr>';
print '<tr><td>';
require_once(DOL_DOCUMENT_ROOT.'/includes/treemenu/TreeMenu.php');
$menu = new HTML_TreeMenu();
$icon = 'folder.gif';
$expandedIcon = 'folder-expanded.gif';
// Création noeud racine
$node=array();
$currentnode=-1;
$node[$currentnode] = new HTML_TreeNode(
array('text' => $langs->trans("AllCats"), 'link' => '', 'icon' => $icon, 'expandedIcon' => $expandedIcon, 'expanded' => true)
//,array('onclick' => "alert('foo'); return false", 'onexpand' => "alert('Expanded')")
);
$node1 = new HTML_TreeNode(
array('text' => $langs->trans("AllCats"), 'link' => '', 'icon' => $icon, 'expandedIcon' => $expandedIcon, 'expanded' => true)
//,array('onclick' => "alert('foo'); return false", 'onexpand' => "alert('Expanded')")
);
// Ajoute id_mere sur tableau cate_arbo
foreach ($cate_arbo as $key => $val)
if (sizeof($cate_arbo))
{
print 'x '.$cate_arbo[$key]['id'].' '.$cate_arbo[$key]['level'].' '.$cate_arbo[$key]['id_mere'].'<br>';
require_once(DOL_DOCUMENT_ROOT.'/includes/treemenu/TreeMenu.php');
$menu = new HTML_TreeMenu();
$icon = 'folder.gif';
$expandedIcon = 'folder-expanded.gif';
// Création noeud racine
$node=array();
$rootnode='-1';
$node[$rootnode] = new HTML_TreeNode(
array('text' => $langs->trans("AllCats"), 'link' => '', 'icon' => $icon, 'expandedIcon' => $expandedIcon, 'expanded' => true)
//,array('onclick' => "alert('foo'); return false", 'onexpand' => "alert('Expanded')")
);
// Ajoute id_mere sur tableau cate_arbo
$i=0;
foreach ($cate_arbo as $key => $val)
{
$i++;
$nodeparent=ereg_replace('_[0-9]+$','',$cate_arbo[$key]['fullpath']);
if (! $nodeparent) $nodeparent=$rootnode;
//print "Ajout noeud sur noeud ".$nodeparent.' pour categorie '.$cate_arbo[$key]['fulllabel']."<br>\n";
$node[$cate_arbo[$key]['fullpath']]=$node[$nodeparent]->addItem(new HTML_TreeNode(array(
'text' => $cate_arbo[$key]['label'],
//'link' => $_SERVER["PHP_SELF"].'?id='.$cate_arbo[$key]['id'],
'link' => DOL_URL_ROOT.'/categories/viewcat.php?id='.$cate_arbo[$key]['id'],
'icon' => $icon, 'expandedIcon' => $expandedIcon)));
//print 'Resultat: noeud '.$cate_arbo[$key]['fullpath']." créé<br>\n";
}
$menu->addItem($node[$rootnode]);
// Affiche arbre
print '<script src="'.DOL_URL_ROOT.'/includes/treemenu/TreeMenu.js" language="JavaScript" type="text/javascript"></script>';
$treeMenu = new HTML_TreeMenu_DHTML($menu, array('images' => DOL_URL_ROOT.'/includes/treemenu/images', 'defaultClass' => 'treeMenuDefault', false));
$treeMenu->printMenu();
//$listBox = new HTML_TreeMenu_Listbox($menu, array('linkTarget' => '_self'));
//$listBox->printMenu();
}
else
{
print $langs->trans("NoneCategory");
}
$node1->addItem(new HTML_TreeNode(array('text' => "Second level, item y", 'link' => $_SERVER["PHP_SELF"], 'icon' => $icon, 'expandedIcon' => $expandedIcon)));
$node1_1 = $node1->addItem(new HTML_TreeNode(array('text' => "Second level", 'link' => $_SERVER["PHP_SELF"], 'icon' => $icon, 'expandedIcon' => $expandedIcon)));
$node1_1_1 = $node1_1->addItem(new HTML_TreeNode(array('text' => "Third level", 'link' => $_SERVER["PHP_SELF"], 'icon' => $icon, 'expandedIcon' => $expandedIcon)));
$node1_1_1_1 = $node1_1_1->addItem(new HTML_TreeNode(array('text' => "Fourth level", 'link' => $_SERVER["PHP_SELF"], 'icon' => $icon, 'expandedIcon' => $expandedIcon)));
$node1_1_1_1->addItem(new HTML_TreeNode(array('text' => "Fifth level", 'link' => $_SERVER["PHP_SELF"], 'icon' => $icon, 'expandedIcon' => $expandedIcon, 'cssClass' => 'treeMenuBold')));
$node1_1->addItem(new HTML_TreeNode(array('text' => "Third Level, item 2", 'link' => $_SERVER["PHP_SELF"], 'icon' => $icon, 'expandedIcon' => $expandedIcon)));
$node1->addItem(new HTML_TreeNode(array('text' => "Second level, item 3", 'link' => $_SERVER["PHP_SELF"], 'icon' => $icon, 'expandedIcon' => $expandedIcon)));
$menu->addItem($node1);
// Affiche arbre
print '<script src="'.DOL_URL_ROOT.'/includes/treemenu/TreeMenu.js" language="JavaScript" type="text/javascript"></script>';
$treeMenu = new HTML_TreeMenu_DHTML($menu, array('images' => DOL_URL_ROOT.'/includes/treemenu/images', 'defaultClass' => 'treeMenuDefault', false));
$treeMenu->printMenu();
//$listBox = new HTML_TreeMenu_Listbox($menu, array('linkTarget' => '_self'));
//$listBox->printMenu();
print '</td></tr>';
print "</table>";
print '<br>';
}
*/
/*
* Catégories principales en HTML pure
*/
if (1 == 1)
else
{
/*
* Catégories principales en HTML pure
*/
print '<table class="noborder" width="100%">';
print '<tr class="liste_titre"><td>'.$langs->trans("AllCats").'</td><td>'.$langs->trans("Desc").'</td></tr>';
if (is_array($cate_arbo))
print '<tr class="liste_titre"><td>'.$langs->trans("AllCats").'</td><td>'.$langs->trans("Description").'</td></tr>';
if (sizeof($cate_arbo))
{
$var=true;
foreach($cate_arbo as $key => $value)
if (is_array($cate_arbo))
{
$var = ! $var;
print "\t<tr ".$bc[$var].">\n";
print '<td><a href="viewcat.php?id='.$cate_arbo[$key]['id'].'">'.$cate_arbo[$key]['fulllabel'].'</a></td>';
print '<td>'.$c->get_desc($cate_arbo[$key]['id']).'</td>';
print "\t</td>\n";
print "\t</tr>\n";
$var=true;
foreach($cate_arbo as $key => $value)
{
$var = ! $var;
print "\t<tr ".$bc[$var].">\n";
print '<td><a href="viewcat.php?id='.$cate_arbo[$key]['id'].'">'.$cate_arbo[$key]['fulllabel'].'</a></td>';
print '<td>'.$c->get_desc($cate_arbo[$key]['id']).'</td>';
print "\t</tr>\n";
}
}
}
print "</table>";
}
$db->close();
llxFooter('$Date$ - $Revision$');

View File

@ -17,6 +17,13 @@
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
/**
\file htdocs/categories/edit.php
\ingroup categories
\brief Page de visualisation de categorie produit
\version $Revision$
*/
require "./pre.inc.php";
$user->getrights('categorie');
@ -28,35 +35,74 @@ if (! $user->rights->categorie->lire)
if ($_REQUEST['id'] == "")
{
dolibarr_print_error ();
exit ();
dolibarr_print_error('','Missing parameter id');
exit();
}
$c = new Categorie ($db, $_REQUEST['id']);
/*
* Affichage fiche categorie
*/
llxHeader ("","",$langs->trans("Categories"));
print_fiche_titre($langs->trans("Category"));
$c = new Categorie ($db, $_REQUEST['id']);
print '<table border="0" width="100%" class="notopnoleftnoright">';
print '<tr><td valign="top" width="30%" class="notopnoleft">';
$h = 0;
$head = array();
$head[$h][0] = DOL_URL_ROOT.'/categories/viewcat.php?id='.$c->id;
$head[$h][1] = $langs->trans("Card");
$head[$h][2] = 'card';
$h++;
dolibarr_fiche_head($head, 'card', $langs->trans("Category"));
print '<table border="0" width="100%" class="border">';
print '<tr><td width="20%" class="notopnoleft">';
$ways = $c->print_all_ways ();
print "<div id='ways'>";
print $langs->trans("Ref").': ';
print $langs->trans("Ref").'</td><td>';
foreach ($ways as $way)
{
print $way."<br />\n";
}
print '</td></tr>';
print '<tr><td width="20%" class="notopnoleft">';
print $langs->trans("Description").'</td><td>';
print nl2br($c->description);
print '</td></tr>';
print '</table>';
print '</div>';
/*
* Boutons actions
*/
print "<div class='tabsAction'>\n";
if ($user->rights->categorie->creer)
{
print "<a class='butAction' href='edit.php?id=".$c->id."'>".$langs->trans("Edit")."</a>";
}
if ($user->rights->categorie->supprimer)
{
print "<a class='butActionDelete' href='delete.php?id=".$c->id."'>".$langs->trans("Delete")."</a>";
}
print "</div>";
$cats = $c->get_filles ();
$cats = $c->get_filles ();
if ($cats < 0)
{
dolibarr_print_error();
@ -96,10 +142,8 @@ else
print "</table>\n";
}
$i = 0;
$prods = $c->get_products ();
if ($prods < 0)
{
dolibarr_print_error();
@ -112,6 +156,7 @@ else
if (sizeof ($prods) > 0)
{
$i = 0;
$var=true;
foreach ($prods as $prod)
{
@ -134,25 +179,6 @@ else
print "</table>\n";
}
/*
* Boutons actions
*/
print "<div class='tabsAction'>\n";
if ($user->rights->categorie->creer)
{
print "<a class='butAction' href='edit.php?id=".$c->id."'>".$langs->trans("Edit")."</a>";
}
if ($user->rights->categorie->supprimer)
{
print "<a class='butActionDelete' href='delete.php?id=".$c->id."'>".$langs->trans("Delete")."</a>";
}
print "</div>";
print '</td></tr></table>';
$db->close();

View File

@ -7,6 +7,7 @@ In=In
AddIn=Add in
modify=modify
CategoriesArea=Categories area
ProductsCategoriesArea=Products/Services' categories Area
MainCats=Main categories
SubCats=Subcategories
CatStatistics=Statistics
@ -14,6 +15,7 @@ CatList=List of cat
AllCats=All categories
ViewCat=View category
NewCat=Add category
NewCategory=New product/services category
ModifCat=Modify category
CatCreated=Category added
CreateCat=Create category
@ -33,10 +35,14 @@ AddProductToCat=Add this product to a category?
ImpossibleAddCat=Impossible to add the category
ImpossibleAssociateCategory=Impossible to associate the category to
WasAddedSuccessfully=was added successfully.
CategorySuccessfullyCreated=La catégorie %s a été ajouté avec succčs.
ProductIsInCategories=Product/service owns to categories
ProductHasNoCategory=This product/service is not in any categories
ClassifyInCategory=Classify in category
NoneCategory=None
CategoryExistsAtSameLevel=This category already exists at same place
ReturnInProduct=Back to product/service card
ContentsVisibleByAll=The contents will be visible by all
ContentsVisibleByAllShort=Contents visible by all
ContentsNotVisibleByAllShort=Contents not visible by all
ContentsNotVisibleByAllShort=Contents not visible by all
CategoriesTree=Categories tree

View File

@ -15,6 +15,7 @@ CatList=Liste des cat
AllCats=Toutes les catégories
ViewCat=Visualisation de la catégorie
NewCat=Nouvelle catégorie
NewCategory=Nouvelle catégorie de produits/services
ModifCat=Modifier une catégorie
CatCreated=Catégorie ajoutée
CreateCat=Ajouter une catégorie
@ -34,6 +35,7 @@ AddProductToCat=Ajouter ce produit
ImpossibleAddCat=Impossible d'ajouter la catégorie
ImpossibleAssociateCategory=Impossible d'associer la catégorie
WasAddedSuccessfully=a été ajoutée avec succès.
CategorySuccessfullyCreated=La catégorie %s a été ajouté avec succčs.
ProductIsInCategories=Ce produit/service est dans les catégorie suivantes
ProductHasNoCategory=Ce produit/service n'est dans aucune catégorie en particulier
ClassifyInCategory=Classer dans la catégorie
@ -43,5 +45,4 @@ ReturnInProduct=Retour sur la fiche produit/service
ContentsVisibleByAll=Le contenu sera visible par tous
ContentsVisibleByAllShort=Contenu visible par tous
ContentsNotVisibleByAllShort=Contenu non visible par tous
Desc=Description
CategoriesTree=Arbre des catégories