/**
  *  Return Categories list
  *  @param		int		$idCat		Id of Category, if 0 return Principal cats
  *  @return      array				Array with categories
  */
 public static function getCategories($idCat = 0)
 {
     global $db;
     switch ($idCat) {
         case 0:
             //devolver las categorias con nivel 1
             $objCat = new Categorie($db);
             //$cats=$objCat->get_full_arbo(0);
             $cats = $objCat->get_full_arbo($idCat);
             if (sizeof($cats) > 0) {
                 $retarray = array();
                 foreach ($cats as $key => $val) {
                     if ($val['level'] < 2) {
                         $val['image'] = self::getImageCategory($val['id']);
                         $val['thumb'] = self::getImageCategory($val['id']);
                         $retarray[] = $val;
                     }
                 }
                 return $retarray;
             }
             break;
         case $idCat > 0:
             $objCat = new Categorie($db);
             $result = $objCat->fetch($idCat);
             if ($result > 0) {
                 $cats = $objCat->get_filles($idCat);
                 //$cats = self::get_filles($idCat);
                 if (sizeof($cats) > 0) {
                     $retarray = array();
                     foreach ($cats as $val) {
                         $cat['id'] = $val->id;
                         $cat['label'] = $val->label;
                         $cat['fulllabel'] = $val->label;
                         $cat['fullpath'] = '_' . $val->id;
                         $cat['image'] = self::getImageCategory($val->id);
                         $cat['thumb'] = self::getImageCategory($val->id);
                         $retarray[] = $cat;
                     }
                     return $retarray;
                 }
             }
             break;
         default:
             return -1;
             break;
     }
 }
Ejemplo n.º 2
0
        $categstatic->label = $cat->label;
        $categstatic->type = $cat->type;
        print $categstatic->getNomUrl(1, '');
        print "</td>\n";
        print "\t\t<td>" . $cat->description . "</td>\n";
        print "\t</tr>\n";
    }
    print "</table>";
} else {
    print '&nbsp;';
}
//print '</td></tr></table>';
print '</div></div></div>';
print '<div class="fichecenter"><br>';
// Charge tableau des categories
$cate_arbo = $categstatic->get_full_arbo($type);
// Define fulltree array
$fulltree = $cate_arbo;
// Define data (format for treeview)
$data = array();
$data[] = array('rowid' => 0, 'fk_menu' => -1, 'title' => "racine", 'mainmenu' => '', 'leftmenu' => '', 'fk_mainmenu' => '', 'fk_leftmenu' => '');
foreach ($fulltree as $key => $val) {
    $categstatic->id = $val['id'];
    $categstatic->ref = $val['label'];
    $categstatic->type = $type;
    $li = $categstatic->getNomUrl(1, '', 60);
    $desc = dol_htmlcleanlastbr($val['description']);
    $data[] = array('rowid' => $val['rowid'], 'fk_menu' => $val['fk_parent'], 'entry' => '<table class="nobordernopadding centpercent"><tr><td>' . $li . '</td><td width="50%">' . dolGetFirstLineOfText($desc) . '</td>' . '<td align="right" width="20px;"><a href="' . DOL_URL_ROOT . '/categories/viewcat.php?id=' . $val['id'] . '&type=' . $type . '">' . img_view() . '</a></td>' . '</tr></table>');
}
print '<table class="liste nohover" width="100%">';
print '<tr class="liste_titre"><td>' . $langs->trans("Categories") . '</td><td></td><td align="right">';
Ejemplo n.º 3
0
 /**
  * Return select list for categories (to use in form search selectors)
  *
  * @param	int		$type			Type of categories (0=product, 1=supplier, 2=customer, 3=member, 4=contact)
  * @param   integer	$selected     	Preselected value
  * @param   string	$htmlname      	Name of combo list
  * @param	int		$nocateg		Show also an entry "Not categorized"
  * @param   int     $showempty      Add also an empty line
  * @return string		        	Html combo list code
  * @see	select_all_categories
  */
 function select_categories($type, $selected = 0, $htmlname = 'search_categ', $nocateg = 0, $showempty = 1)
 {
     global $conf, $langs;
     require_once DOL_DOCUMENT_ROOT . '/categories/class/categorie.class.php';
     // Load list of "categories"
     $static_categs = new Categorie($this->db);
     $tab_categs = $static_categs->get_full_arbo($type);
     $moreforfilter = '';
     $nodatarole = '';
     // Enhance with select2
     if ($conf->use_javascript_ajax) {
         include_once DOL_DOCUMENT_ROOT . '/core/lib/ajax.lib.php';
         $comboenhancement = ajax_combobox('select_categ_' . $htmlname);
         $moreforfilter .= $comboenhancement;
         $nodatarole = $comboenhancement ? ' data-role="none"' : '';
     }
     // Print a select with each of them
     $moreforfilter .= '<select class="flat minwidth100" id="select_categ_' . $htmlname . '" name="' . $htmlname . '"' . $nodatarole . '>';
     if ($showempty) {
         $moreforfilter .= '<option value="0">&nbsp;</option>';
     }
     // Should use -1 to say nothing
     if (is_array($tab_categs)) {
         foreach ($tab_categs as $categ) {
             $moreforfilter .= '<option value="' . $categ['id'] . '"';
             if ($categ['id'] == $selected) {
                 $moreforfilter .= ' selected';
             }
             $moreforfilter .= '>' . dol_trunc($categ['fulllabel'], 50, 'middle') . '</option>';
         }
     }
     if ($nocateg) {
         $langs->load("categories");
         $moreforfilter .= '<option value="-2"' . ($selected == -2 ? ' selected' : '') . '>- ' . $langs->trans("NotCategorized") . ' -</option>';
     }
     $moreforfilter .= '</select>';
     return $moreforfilter;
 }
Ejemplo n.º 4
0
    /**
     * @depends  testCategorieDelete
     */
    public function testCategorieStatic()
    {
    	global $conf,$user,$langs,$db;
		$conf=$this->savconf;
		$user=$this->savuser;
		$langs=$this->savlangs;
		$db=$this->savdb;

		$localobject=new Categorie($this->savdb);
        $retarray=$localobject->get_full_arbo(3);

		print __METHOD__." retarray size=".sizeof($retarray)."\n";
    	$this->assertTrue(is_array($retarray));
    	return $result;
    }
Ejemplo n.º 5
0
 /**
  *    Return list of categories having choosed type
  *    @param    type			Type de categories (0=product, 1=supplier, 2=customer, 3=member)
  *    @param    selected    	Id of category preselected
  *    @param    select_name		HTML field name
  *    @param    maxlength       Maximum length for labels
  *    @param    excludeafterid  Exclude all categories after this leaf in category tree.
  */
 function select_all_categories($type, $selected = '', $select_name = "", $maxlength = 64, $excludeafterid = 0)
 {
     global $langs;
     $langs->load("categories");
     if ($select_name == "") {
         $select_name = "catMere";
     }
     $cat = new Categorie($this->db);
     $cate_arbo = $cat->get_full_arbo($type, $excludeafterid);
     $output = '<select class="flat" name="' . $select_name . '">';
     if (is_array($cate_arbo)) {
         if (!sizeof($cate_arbo)) {
             $output .= '<option value="-1" disabled="true">' . $langs->trans("NoCategoriesDefined") . '</option>';
         } else {
             $output .= '<option value="-1">&nbsp;</option>';
             foreach ($cate_arbo as $key => $value) {
                 if ($cate_arbo[$key]['id'] == $selected) {
                     $add = 'selected="selected" ';
                 } else {
                     $add = '';
                 }
                 $output .= '<option ' . $add . 'value="' . $cate_arbo[$key]['id'] . '">' . dol_trunc($cate_arbo[$key]['fulllabel'], $maxlength, 'middle') . '</option>';
             }
         }
     }
     $output .= '</select>';
     $output .= "\n";
     return $output;
 }
Ejemplo n.º 6
0
 /**
  * Return select list for categories (to use in form search selectors)
  *
  * @param	int		$type			Type of categories (0=product, 1=suppliers, 2=customers, 3=members)
  * @param  string	$selected     	Preselected value
  * @param  string	$htmlname      	Name of combo list
  * @param	int		$nocateg		Show also an entry "Not categorized"
  * @return string		        	Html combo list code
  * @see	select_all_categories
  */
 function select_categories($type, $selected = 0, $htmlname = 'search_categ', $nocateg = 0)
 {
     global $langs;
     require_once DOL_DOCUMENT_ROOT . '/categories/class/categorie.class.php';
     // Load list of "categories"
     $static_categs = new Categorie($this->db);
     $tab_categs = $static_categs->get_full_arbo($type);
     // Print a select with each of them
     $moreforfilter = '<select class="flat" id="select_categ_' . $htmlname . '" name="' . $htmlname . '">';
     $moreforfilter .= '<option value="">&nbsp;</option>';
     // Should use -1 to say nothing
     if (is_array($tab_categs)) {
         foreach ($tab_categs as $categ) {
             $moreforfilter .= '<option value="' . $categ['id'] . '"';
             if ($categ['id'] == $selected) {
                 $moreforfilter .= ' selected="selected"';
             }
             $moreforfilter .= '>' . dol_trunc($categ['fulllabel'], 50, 'middle') . '</option>';
         }
     }
     if ($nocateg) {
         $langs->load("categories");
         $moreforfilter .= '<option value="-2"' . ($selected == -2 ? ' selected="selected"' : '') . '>- ' . $langs->trans("NotCategorized") . ' -</option>';
     }
     $moreforfilter .= '</select>';
     return $moreforfilter;
 }
Ejemplo n.º 7
0
	/**
	 *  Return select list for categories (to use in form search selectors)
	 *	@param    	type			Type of categories (0=product, 1=suppliers, 2=customers, 3=members)
	 *  @param     	selected     	Preselected value
	 *  @param     	htmlname      	Name of combo list
	 *  @return    	return        	Html combo list code
	 */
	function select_categories($type,$selected=0,$htmlname='search_categ')
	{
		global $langs;
	 	require_once(DOL_DOCUMENT_ROOT."/categories/class/categorie.class.php");

	 	// Load list of "categories"
	 	$static_categs = new Categorie($this->db);
	 	$tab_categs = $static_categs->get_full_arbo($type);

	 	// Print a select with each of them
	 	$moreforfilter ='<select class="flat" name="'.$htmlname.'">';
	 	$moreforfilter.='<option value="">&nbsp;</option>';

	 	if (is_array($tab_categs))
	 	{
	 		foreach ($tab_categs as $categ)
	 		{
	 			$moreforfilter.='<option value="'.$categ['id'].'"';
	 			if ($categ['id'] == $selected) $moreforfilter.=' selected="selected"';
	 			$moreforfilter.='>'.dol_trunc($categ['fulllabel'],50,'middle').'</option>';
	 		}
	 	}
	 	$moreforfilter.='</select>';

		return $moreforfilter;
	}
Ejemplo n.º 8
0
 /**
  *    Return list of categories having choosed type
  *
  *    @param	int		$type				Type de categories (0=product, 1=supplier, 2=customer, 3=member)
  *    @param    string	$selected    		Id of category preselected or 'auto' (autoselect category if there is only one element)
  *    @param    string	$htmlname			HTML field name
  *    @param    int		$maxlength      	Maximum length for labels
  *    @param    int		$excludeafterid 	Exclude all categories after this leaf in category tree.
  *    @param	int		$outputmode			0=HTML select string, 1=Array
  *    @return	string
  *    @see select_categories
  */
 function select_all_categories($type, $selected = '', $htmlname = "parent", $maxlength = 64, $excludeafterid = 0, $outputmode = 0)
 {
     global $langs;
     $langs->load("categories");
     include_once DOL_DOCUMENT_ROOT . '/categories/class/categorie.class.php';
     $cat = new Categorie($this->db);
     $cate_arbo = $cat->get_full_arbo($type, $excludeafterid);
     $output = '<select class="flat" name="' . $htmlname . '">';
     $outarray = array();
     if (is_array($cate_arbo)) {
         if (!count($cate_arbo)) {
             $output .= '<option value="-1" disabled>' . $langs->trans("NoCategoriesDefined") . '</option>';
         } else {
             $output .= '<option value="-1">&nbsp;</option>';
             foreach ($cate_arbo as $key => $value) {
                 if ($cate_arbo[$key]['id'] == $selected || $selected == 'auto' && count($cate_arbo) == 1) {
                     $add = 'selected ';
                 } else {
                     $add = '';
                 }
                 $output .= '<option ' . $add . 'value="' . $cate_arbo[$key]['id'] . '">' . dol_trunc($cate_arbo[$key]['fulllabel'], $maxlength, 'middle') . '</option>';
                 $outarray[$cate_arbo[$key]['id']] = $cate_arbo[$key]['fulllabel'];
             }
         }
     }
     $output .= '</select>';
     $output .= "\n";
     if ($outputmode) {
         return $outarray;
     }
     return $output;
 }
        while ($i < $num) {
            $objp = $db->fetch_object($resql);
            $val["id"] = $objp->id;
            $val["label"] = $objp->label;
            $val["price"] = $objp->price;
            $val["price"] = round($val["price"] * 100) / 100;
            $val["barcode"] = $objp->barcode;
            $val["type"] = "pro";
            echo "INSERT INTO products  values (" . $val["id"] . ", " . $id . ", '" . $val["label"] . "', " . $val["price"] . ")@@";
            //echo "<br>";
            $i++;
        }
    }
}
$objCat = new Categorie($db);
$cats = $objCat->get_full_arbo(0);
$retarray = array();
foreach ($cats as $key => $val) {
    echo "INSERT INTO cats  values (" . $val["rowid"] . ", " . $val["fk_parent"] . ", '" . $val["label"] . "')@@";
    //echo "<br>";
    getitems($val["rowid"]);
}
$resql = $db->query("SELECT DISTINCT p.rowid as id, p.price_ttc as price, p.label as label, p.barcode as barcode FROM " . MAIN_DB_PREFIX . "product as p LEFT JOIN llx_categorie_product as cp ON p.rowid = cp.fk_product LEFT JOIN llx_product_fournisseur_price as pfp ON p.rowid = pfp.fk_product WHERE p.entity IN ({$entity}) AND p.fk_product_type <> '1' AND cp.fk_categorie IS NULL GROUP BY p.rowid, p.ref, p.label, p.barcode, p.price, p.price_ttc, p.price_base_type, p.fk_product_type, p.tms, p.duration, p.tosell, p.tobuy, p.seuil_stock_alerte, p.desiredstock ORDER BY p.ref");
if ($resql) {
    $num = $db->num_rows($resql);
    $i = 0;
    while ($i < $num) {
        $objp = $db->fetch_object($resql);
        $val["id"] = $objp->id;
        $val["label"] = $objp->label;
        $val["price"] = $objp->price;