2005-04-13 14:04:02 +02:00
< ? php
2015-05-23 18:52:31 +02:00
/* Copyright ( C ) 2005 Matthieu Valleton < mv @ seeschloss . org >
* Copyright ( C ) 2005 Eric Seigne < eric . seigne @ ryxeo . com >
2016-07-30 14:05:39 +02:00
* Copyright ( C ) 2006 - 2016 Laurent Destailleur < eldy @ users . sourceforge . net >
2015-05-23 18:52:31 +02:00
* Copyright ( C ) 2007 Patrick Raguin < patrick . raguin @ gmail . com >
* Copyright ( C ) 2005 - 2012 Regis Houssin < regis . houssin @ capnetworks . com >
* Copyright ( C ) 2015 Raphaël Doursenaud < rdoursenaud @ gpcsolutions . fr >
2005-04-13 14:04:02 +02:00
*
* 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
2013-01-16 15:36:08 +01:00
* the Free Software Foundation ; either version 3 of the License , or
2005-04-13 14:04:02 +02:00
* ( 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
2011-08-03 02:45:22 +02:00
* along with this program . If not , see < http :// www . gnu . org / licenses />.
2005-04-13 14:04:02 +02:00
*/
2006-02-21 00:43:46 +01:00
/**
2009-01-30 22:21:22 +01:00
* \file htdocs / categories / index . php
* \ingroup category
2009-07-22 19:02:49 +02:00
* \brief Home page of category area
2009-01-30 22:21:22 +01:00
*/
2006-02-21 00:43:46 +01:00
2012-08-22 23:24:21 +02:00
require '../main.inc.php' ;
2012-08-22 23:11:24 +02:00
require_once DOL_DOCUMENT_ROOT . '/categories/class/categorie.class.php' ;
require_once DOL_DOCUMENT_ROOT . '/core/lib/treeview.lib.php' ;
2015-05-19 00:44:05 +02:00
require_once DOL_DOCUMENT_ROOT . '/core/lib/functions2.lib.php' ;
2005-04-13 14:04:02 +02:00
2018-05-27 09:58:23 +02:00
// Load translation files required by the page
2012-03-20 12:26:02 +01:00
$langs -> load ( " categories " );
2007-05-14 02:41:35 +02:00
2012-03-20 12:26:02 +01:00
if ( ! $user -> rights -> categorie -> lire ) accessforbidden ();
2005-04-13 14:04:02 +02:00
2012-03-20 12:26:02 +01:00
$id = GETPOST ( 'id' , 'int' );
2017-06-22 11:04:29 +02:00
$type = ( GETPOST ( 'type' , 'aZ09' ) ? GETPOST ( 'type' , 'aZ09' ) : Categorie :: TYPE_PRODUCT );
2012-07-28 11:28:37 +02:00
$catname = GETPOST ( 'catname' , 'alpha' );
2007-04-30 12:53:58 +02:00
2017-07-25 19:57:51 +02:00
if ( is_numeric ( $type )) $type = Categorie :: $MAP_ID_TO_CODE [ $type ]; // For backward compatibility
2009-01-12 16:35:06 +01:00
/*
* View
2005-04-13 14:04:02 +02:00
*/
2009-01-30 22:21:22 +01:00
$categstatic = new Categorie ( $db );
2011-11-08 10:18:45 +01:00
$form = new Form ( $db );
2006-08-15 20:52:02 +02:00
2017-06-22 11:04:29 +02:00
if ( $type == Categorie :: TYPE_PRODUCT ) { $title = $langs -> trans ( " ProductsCategoriesArea " ); $typetext = 'product' ; }
elseif ( $type == Categorie :: TYPE_SUPPLIER ) { $title = $langs -> trans ( " SuppliersCategoriesArea " ); $typetext = 'supplier' ; }
elseif ( $type == Categorie :: TYPE_CUSTOMER ) { $title = $langs -> trans ( " CustomersCategoriesArea " ); $typetext = 'customer' ; }
elseif ( $type == Categorie :: TYPE_MEMBER ) { $title = $langs -> trans ( " MembersCategoriesArea " ); $typetext = 'member' ; }
elseif ( $type == Categorie :: TYPE_CONTACT ) { $title = $langs -> trans ( " ContactsCategoriesArea " ); $typetext = 'contact' ; }
2017-08-27 12:28:59 +02:00
elseif ( $type == Categorie :: TYPE_ACCOUNT ) { $title = $langs -> trans ( " AccountsCategoriesArea " ); $typetext = 'bank_account' ; }
2017-06-22 11:04:29 +02:00
elseif ( $type == Categorie :: TYPE_PROJECT ) { $title = $langs -> trans ( " ProjectsCategoriesArea " ); $typetext = 'project' ; }
2017-07-25 19:57:51 +02:00
elseif ( $type == Categorie :: TYPE_USER ) { $title = $langs -> trans ( " UsersCategoriesArea " ); $typetext = 'user' ; }
2017-06-22 11:04:29 +02:00
else { $title = $langs -> trans ( " CategoriesArea " ); $typetext = 'unknown' ; }
2007-05-14 02:41:35 +02:00
2013-02-20 21:16:31 +01:00
$arrayofjs = array ( '/includes/jquery/plugins/jquerytreeview/jquery.treeview.js' , '/includes/jquery/plugins/jquerytreeview/lib/jquery.cookie.js' );
$arrayofcss = array ( '/includes/jquery/plugins/jquerytreeview/jquery.treeview.css' );
llxHeader ( '' , $title , '' , '' , 0 , 0 , $arrayofjs , $arrayofcss );
2018-10-09 14:34:25 +02:00
$newcardbutton = '<a class="butActionNew" href="' . DOL_URL_ROOT . '/categories/card.php?action=create&type=' . $type . '&backtopage=' . urlencode ( $_SERVER [ " PHP_SELF " ] . '?type=' . $type ) . '"><span class="valignmiddle">' . $langs -> trans ( " NewCategory " ) . '</span>' ;
$newcardbutton .= '<span class="fa fa-plus-circle valignmiddle"></span>' ;
$newcardbutton .= '</a>' ;
2007-05-14 02:41:35 +02:00
2018-10-09 14:34:25 +02:00
print load_fiche_titre ( $title , $newcardbutton );
2005-04-13 14:04:02 +02:00
2013-03-16 14:53:15 +01:00
//print '<table border="0" width="100%" class="notopnoleftnoright">';
//print '<tr><td valign="top" width="30%" class="notopnoleft">';
2013-03-30 14:27:13 +01:00
print '<div class="fichecenter"><div class="fichethirdleft">' ;
2005-04-13 14:04:02 +02:00
/*
* Zone recherche produit / service
*/
2009-01-12 16:35:06 +01:00
print '<form method="post" action="index.php?type=' . $type . '">' ;
2009-05-17 10:01:54 +02:00
print '<input type="hidden" name="token" value="' . $_SESSION [ 'newtoken' ] . '">' ;
2009-01-12 16:35:06 +01:00
print '<input type="hidden" name="type" value="' . $type . '">' ;
2012-09-09 13:13:24 +02:00
print '<table class="noborder nohover" width="100%">' ;
2005-04-13 14:04:02 +02:00
print '<tr class="liste_titre">' ;
print '<td colspan="3">' . $langs -> trans ( " Search " ) . '</td>' ;
print '</tr>' ;
2018-05-12 10:46:17 +02:00
print '<tr class="oddeven"><td>' ;
2016-04-22 11:11:08 +02:00
print $langs -> trans ( " Name " ) . ':</td><td><input class="flat inputsearch" type="text" name="catname" value="' . $catname . '"/></td><td><input type="submit" class="button" value="' . $langs -> trans ( " Search " ) . '"></td></tr>' ;
2006-03-14 07:34:40 +01:00
/*
2009-07-22 22:06:45 +02:00
// faire une rech dans une sous categorie uniquement
2005-04-13 14:04:02 +02:00
print '<tr ' . $bc [ 0 ] . '><td>' ;
2006-03-14 07:34:40 +01:00
print $langs -> trans ( " SubCatOf " ) . ':</td><td>' ;
2005-04-13 14:04:02 +02:00
2011-11-08 10:18:45 +01:00
print $form -> select_all_categories ( '' , 'subcatof' );
2006-03-14 07:34:40 +01:00
print '</td>' ;
print '<td><input type="submit" class="button" value="' . $langs -> trans ( " Search " ) . '"></td></tr>' ;
*/
2005-04-13 14:04:02 +02:00
print '</table></form>' ;
2013-03-16 14:53:15 +01:00
//print '</td><td valign="top" width="70%">';
2013-03-30 14:27:13 +01:00
print '</div><div class="fichetwothirdright"><div class="ficheaddleft">' ;
2005-04-13 14:04:02 +02:00
2005-06-13 22:54:14 +02:00
/*
2009-05-22 17:00:40 +02:00
* Categories found
2005-06-13 22:54:14 +02:00
*/
2012-07-28 11:28:37 +02:00
if ( $catname || $id > 0 )
2006-07-30 02:37:31 +02:00
{
2017-06-22 11:04:29 +02:00
$cats = $categstatic -> rechercher ( $id , $catname , $typetext );
2006-08-15 20:52:02 +02:00
2006-07-30 02:37:31 +02:00
print '<table class="noborder" width="100%">' ;
print '<tr class="liste_titre"><td colspan="2">' . $langs -> trans ( " FoundCats " ) . '</td></tr>' ;
foreach ( $cats as $cat )
{
2017-05-06 10:54:28 +02:00
print " \t " . '<tr class="oddeven">' . " \n " ;
2010-03-20 01:07:47 +01:00
print " \t \t <td> " ;
$categstatic -> id = $cat -> id ;
$categstatic -> ref = $cat -> label ;
$categstatic -> label = $cat -> label ;
$categstatic -> type = $cat -> type ;
2016-07-30 14:05:39 +02:00
$categstatic -> color = $cat -> color ;
print '<span class="noborderoncategories" ' . ( $categstatic -> color ? ' style="background: #' . $categstatic -> color . ';"' : ' style="background: #aaa"' ) . '>' ;
2010-03-20 01:07:47 +01:00
print $categstatic -> getNomUrl ( 1 , '' );
2016-07-30 14:05:39 +02:00
print '</span>' ;
print " </td> \n " ;
print " \t \t <td> " ;
2017-05-05 12:33:49 +02:00
print dolGetFirstLineOfText ( $cat -> description );
2010-03-20 01:07:47 +01:00
print " </td> \n " ;
2006-07-30 02:37:31 +02:00
print " \t </tr> \n " ;
}
print " </table> " ;
2005-06-13 22:54:14 +02:00
}
2013-03-30 19:37:09 +01:00
else print ' ' ;
2005-06-13 22:54:14 +02:00
2006-08-15 19:33:56 +02:00
2013-03-16 14:53:15 +01:00
//print '</td></tr></table>';
2013-03-30 19:37:09 +01:00
print '</div></div></div>' ;
2006-08-15 19:33:56 +02:00
2013-06-05 16:24:32 +02:00
print '<div class="fichecenter"><br>' ;
2006-08-15 19:33:56 +02:00
// Charge tableau des categories
2017-06-22 11:04:29 +02:00
$cate_arbo = $categstatic -> get_full_arbo ( $typetext );
2010-07-29 15:13:41 +02:00
// Define fulltree array
$fulltree = $cate_arbo ;
2006-08-15 19:33:56 +02:00
2013-02-20 21:16:31 +01:00
// Define data (format for treeview)
2013-03-30 14:27:13 +01:00
$data = array ();
$data [] = array ( 'rowid' => 0 , 'fk_menu' =>- 1 , 'title' => " racine " , 'mainmenu' => '' , 'leftmenu' => '' , 'fk_mainmenu' => '' , 'fk_leftmenu' => '' );
foreach ( $fulltree as $key => $val )
2009-01-30 22:21:22 +01:00
{
2013-03-30 14:27:13 +01:00
$categstatic -> id = $val [ 'id' ];
$categstatic -> ref = $val [ 'label' ];
2015-12-19 13:55:27 +01:00
$categstatic -> color = $val [ 'color' ];
2013-03-30 14:27:13 +01:00
$categstatic -> type = $type ;
$li = $categstatic -> getNomUrl ( 1 , '' , 60 );
2015-08-13 01:26:25 +02:00
$desc = dol_htmlcleanlastbr ( $val [ 'description' ]);
2013-03-30 14:27:13 +01:00
$data [] = array (
'rowid' => $val [ 'rowid' ],
'fk_menu' => $val [ 'fk_parent' ],
2015-12-19 13:55:27 +01:00
'entry' => '<table class="nobordernopadding centpercent"><tr><td><span class="noborderoncategories" ' . ( $categstatic -> color ? ' style="background: #' . $categstatic -> color . ';"' : ' style="background: #aaa"' ) . '>' . $li . '</span></td>' .
2017-05-05 12:33:49 +02:00
//'<td width="50%">'.dolGetFirstLineOfText($desc).'</td>'.
2013-03-30 14:27:13 +01:00
'<td align="right" width="20px;"><a href="' . DOL_URL_ROOT . '/categories/viewcat.php?id=' . $val [ 'id' ] . '&type=' . $type . '">' . img_view () . '</a></td>' .
'</tr></table>'
);
}
2009-01-29 22:04:00 +01:00
2009-01-30 22:21:22 +01:00
2015-06-22 22:31:44 +02:00
print '<table class="liste nohover" width="100%">' ;
2015-05-19 00:44:05 +02:00
print '<tr class="liste_titre"><td>' . $langs -> trans ( " Categories " ) . '</td><td></td><td align="right">' ;
2013-03-11 10:18:25 +01:00
if ( ! empty ( $conf -> use_javascript_ajax ))
{
2016-09-18 13:58:17 +02:00
print '<div id="iddivjstreecontrol"><a class="notasortlink" href="#">' . img_picto ( '' , 'object_category' ) . ' ' . $langs -> trans ( " UndoExpandAll " ) . '</a> | <a class="notasortlink" href="#">' . img_picto ( '' , 'object_category-expanded' ) . ' ' . $langs -> trans ( " ExpandAll " ) . '</a></div>' ;
2013-03-11 10:18:25 +01:00
}
print '</td></tr>' ;
2009-01-30 22:21:22 +01:00
2013-02-20 21:16:31 +01:00
$nbofentries = ( count ( $data ) - 1 );
2009-01-30 22:21:22 +01:00
2013-02-20 21:16:31 +01:00
if ( $nbofentries > 0 )
2006-08-15 19:33:56 +02:00
{
2017-05-05 12:33:49 +02:00
print '<tr class="pair"><td colspan="3">' ;
2013-03-30 14:27:13 +01:00
tree_recur ( $data , $data [ 0 ], 0 );
2013-02-20 21:16:31 +01:00
print '</td></tr>' ;
2009-01-30 22:21:22 +01:00
}
2013-02-20 21:16:31 +01:00
else
{
2017-05-05 12:33:49 +02:00
print '<tr class="pair">' ;
2013-03-30 14:27:13 +01:00
print '<td colspan="3"><table class="nobordernopadding"><tr class="nobordernopadding"><td>' . img_picto_common ( '' , 'treemenu/branchbottom.gif' ) . '</td>' ;
print '<td valign="middle">' ;
print $langs -> trans ( " NoCategoryYet " );
print '</td>' ;
print '<td> </td>' ;
print '</table></td>' ;
print '</tr>' ;
}
2009-01-30 22:21:22 +01:00
print " </table> " ;
2006-08-15 20:52:02 +02:00
2013-03-30 19:37:09 +01:00
print '</div>' ;
2005-04-13 14:04:02 +02:00
2011-08-27 16:24:16 +02:00
llxFooter ();
2013-02-20 21:16:31 +01:00
2012-03-20 12:26:02 +01:00
$db -> close ();