Ejemplo n.º 1
0
    /**
     *    Delete a third party from database and all its dependencies (contacts, rib...)
     *    @param      id      id of third party to delete
     */
    function delete($id)
    {
        global $user,$langs,$conf;
        require_once(DOL_DOCUMENT_ROOT."/lib/files.lib.php");

        dol_syslog("Societe::Delete", LOG_DEBUG);
        $sqr = 0;

        // Test if child exists
        $listtable=array("propal","commande","facture","contrat","facture_fourn","commande_fournisseur");
        $haschild=0;
        foreach($listtable as $table)
        {
            // Check if third party can be deleted
            $nb=0;
            $sql = "SELECT COUNT(*) as nb from ".MAIN_DB_PREFIX.$table;
            $sql.= " WHERE fk_soc = " . $id;
            $resql=$this->db->query($sql);
            if ($resql)
            {
                $obj=$this->db->fetch_object($resql);
                if ($obj->nb > 0)
                {
                    $haschild+=$obj->nb;
                }
            }
            else
            {
                $this->error .= $this->db->lasterror();
                dol_syslog("Societe::Delete erreur -1 ".$this->error, LOG_ERR);
                return -1;
            }
        }
        if ($haschild > 0)
        {
            $this->error="ErrorRecordHasChildren";
            return -1;
        }


        if ($this->db->begin())
        {
            // Added by Matelli (see http://matelli.fr/showcases/patchs-dolibarr/fix-third-party-deleting.html)
            // Removing every "categorie" link with this company
            require_once(DOL_DOCUMENT_ROOT."/categories/class/categorie.class.php");

            $static_cat = new Categorie($this->db);
            $toute_categs = array();

            // Fill $toute_categs array with an array of (type => array of ("Categorie" instance))
            if ($this->client || $this->prospect)
            {
                $toute_categs ['societe'] = $static_cat->containing($this->id,2);
            }
            if ($this->fournisseur)
            {
                $toute_categs ['fournisseur'] = $static_cat->containing($this->id,1);
            }

            // Remove each "Categorie"
            foreach ($toute_categs as $type => $categs_type)
            {
                foreach ($categs_type as $cat)
                {
                    $cat->del_type($this, $type);
                }
            }

            // Remove contacts
            $sql = "DELETE from ".MAIN_DB_PREFIX."socpeople";
            $sql.= " WHERE fk_soc = " . $id;
            dol_syslog("Societe::Delete sql=".$sql, LOG_DEBUG);
            if ($this->db->query($sql))
            {
                $sqr++;
            }
            else
            {
                $this->error .= $this->db->lasterror();
                dol_syslog("Societe::Delete erreur -1 ".$this->error, LOG_ERR);
            }

            // Update link in member table
            $sql = "UPDATE ".MAIN_DB_PREFIX."adherent";
            $sql.= " SET fk_soc = NULL WHERE fk_soc = " . $id;
            dol_syslog("Societe::Delete sql=".$sql, LOG_DEBUG);
            if ($this->db->query($sql))
            {
                $sqr++;
            }
            else
            {
                $this->error .= $this->db->lasterror();
                dol_syslog("Societe::Delete erreur -1 ".$this->error, LOG_ERR);
            }

            // Remove ban
            $sql = "DELETE from ".MAIN_DB_PREFIX."societe_rib";
            $sql.= " WHERE fk_soc = " . $id;
            dol_syslog("Societe::Delete sql=".$sql, LOG_DEBUG);
            if ($this->db->query($sql))
            {
                $sqr++;
            }
            else
            {
                $this->error = $this->db->lasterror();
                dol_syslog("Societe::Delete erreur -2 ".$this->error, LOG_ERR);
            }

            // Remove third party
            $sql = "DELETE from ".MAIN_DB_PREFIX."societe";
            $sql.= " WHERE rowid = " . $id;
            dol_syslog("Societe::Delete sql=".$sql, LOG_DEBUG);
            if ($this->db->query($sql))
            {
                $sqr++;
            }
            else
            {
                $this->error = $this->db->lasterror();
                dol_syslog("Societe::Delete erreur -3 ".$this->error, LOG_ERR);
            }

            if ($sqr == 4)
            {
                // Appel des triggers
                include_once(DOL_DOCUMENT_ROOT . "/core/class/interfaces.class.php");
                $interface=new Interfaces($this->db);
                $result=$interface->run_triggers('COMPANY_DELETE',$this,$user,$langs,$conf);
                if ($result < 0) { $error++; $this->errors=$interface->errors; }
                // Fin appel triggers

                $this->db->commit();

                // Suppression du repertoire document
                $docdir = $conf->societe->dir_output . "/" . $id;
                if (file_exists ($docdir))
                {
                    dol_delete_dir_recursive($docdir);
                }

                return 1;
            }
            else
            {
                $this->db->rollback();
                return -1;
            }
        }

    }
Ejemplo n.º 2
0
/**
 *  Return line description translated in outputlangs and encoded into htmlentities and with <br>
 *
 *  @param  Object		$object              Object
 *  @param  int			$i                   Current line number (0 = first line, 1 = second line, ...)
 *  @param  Translate	$outputlangs         Object langs for output
 *  @param  int			$hideref             Hide reference
 *  @param  int			$hidedesc            Hide description
 *  @param  int			$issupplierline      Is it a line for a supplier object ?
 *  @return string       				     String with line
 */
function pdf_getlinedesc($object, $i, $outputlangs, $hideref = 0, $hidedesc = 0, $issupplierline = 0)
{
    global $db, $conf, $langs;
    $idprod = !empty($object->lines[$i]->fk_product) ? $object->lines[$i]->fk_product : false;
    $label = !empty($object->lines[$i]->label) ? $object->lines[$i]->label : (!empty($object->lines[$i]->product_label) ? $object->lines[$i]->product_label : '');
    $desc = !empty($object->lines[$i]->desc) ? $object->lines[$i]->desc : (!empty($object->lines[$i]->description) ? $object->lines[$i]->description : '');
    $ref_supplier = !empty($object->lines[$i]->ref_supplier) ? $object->lines[$i]->ref_supplier : (!empty($object->lines[$i]->ref_fourn) ? $object->lines[$i]->ref_fourn : '');
    // TODO Not yet saved for supplier invoices, only supplier orders
    $note = !empty($object->lines[$i]->note) ? $object->lines[$i]->note : '';
    $dbatch = !empty($object->lines[$i]->detail_batch) ? $object->lines[$i]->detail_batch : false;
    if ($issupplierline) {
        $prodser = new ProductFournisseur($db);
    } else {
        $prodser = new Product($db);
    }
    if ($idprod) {
        $prodser->fetch($idprod);
        // If a predefined product and multilang and on other lang, we renamed label with label translated
        if (!empty($conf->global->MAIN_MULTILANGS) && $outputlangs->defaultlang != $langs->defaultlang) {
            $translatealsoifmodified = !empty($conf->global->MAIN_MULTILANG_TRANSLATE_EVEN_IF_MODIFIED);
            // By default if value was modified manually, we keep it (no translation because we don't have it)
            // TODO Instead of making a compare to see if param was modified, check that content contains reference translation. If yes, add the added part to the new translation
            // ($textwasmodified is replaced with $textwasmodifiedorcompleted and we add completion).
            // Set label
            // If we want another language, and if label is same than default language (we did force it to a specific value), we can use translation.
            //var_dump($outputlangs->defaultlang.' - '.$langs->defaultlang.' - '.$label.' - '.$prodser->label);exit;
            $textwasmodified = $label == $prodser->label;
            if (!empty($prodser->multilangs[$outputlangs->defaultlang]["label"]) && ($textwasmodified || $translatealsoifmodified)) {
                $label = $prodser->multilangs[$outputlangs->defaultlang]["label"];
            }
            // Set desc
            // Manage HTML entities description test because $prodser->description is store with htmlentities but $desc no
            $textwasmodified = false;
            if (!empty($desc) && dol_textishtml($desc) && !empty($prodser->description) && dol_textishtml($prodser->description)) {
                $textwasmodified = strpos(dol_html_entity_decode($desc, ENT_QUOTES | ENT_HTML401), dol_html_entity_decode($prodser->description, ENT_QUOTES | ENT_HTML401)) !== false;
            } else {
                $textwasmodified = $desc == $prodser->description;
            }
            if (!empty($prodser->multilangs[$outputlangs->defaultlang]["description"]) && ($textwasmodified || $translatealsoifmodified)) {
                $desc = $prodser->multilangs[$outputlangs->defaultlang]["description"];
            }
            // Set note
            $textwasmodified = $note == $prodser->note;
            if (!empty($prodser->multilangs[$outputlangs->defaultlang]["note"]) && ($textwasmodified || $translatealsoifmodified)) {
                $note = $prodser->multilangs[$outputlangs->defaultlang]["note"];
            }
        }
    }
    // Description short of product line
    $libelleproduitservice = $label;
    // Description long of product line
    if (!empty($desc) && $desc != $label) {
        if ($libelleproduitservice && empty($hidedesc)) {
            $libelleproduitservice .= '__N__';
        }
        if ($desc == '(CREDIT_NOTE)' && $object->lines[$i]->fk_remise_except) {
            $discount = new DiscountAbsolute($db);
            $discount->fetch($object->lines[$i]->fk_remise_except);
            $libelleproduitservice = $outputlangs->transnoentitiesnoconv("DiscountFromCreditNote", $discount->ref_facture_source);
        } elseif ($desc == '(DEPOSIT)' && $object->lines[$i]->fk_remise_except) {
            $discount = new DiscountAbsolute($db);
            $discount->fetch($object->lines[$i]->fk_remise_except);
            $libelleproduitservice = $outputlangs->transnoentitiesnoconv("DiscountFromDeposit", $discount->ref_facture_source);
            // Add date of deposit
            if (!empty($conf->global->INVOICE_ADD_DEPOSIT_DATE)) {
                echo ' (' . dol_print_date($discount->datec, 'day', '', $outputlangs) . ')';
            }
        } else {
            if ($idprod) {
                if (empty($hidedesc)) {
                    $libelleproduitservice .= $desc;
                }
            } else {
                $libelleproduitservice .= $desc;
            }
        }
    }
    // If line linked to a product
    if ($idprod) {
        // We add ref
        if ($prodser->ref) {
            $prefix_prodserv = "";
            $ref_prodserv = "";
            if (!empty($conf->global->PRODUCT_ADD_TYPE_IN_DOCUMENTS)) {
                if ($prodser->isService()) {
                    $prefix_prodserv = $outputlangs->transnoentitiesnoconv("Service") . " ";
                } else {
                    $prefix_prodserv = $outputlangs->transnoentitiesnoconv("Product") . " ";
                }
            }
            if (empty($hideref)) {
                if ($issupplierline) {
                    $ref_prodserv = $prodser->ref . ($ref_supplier ? ' (' . $outputlangs->transnoentitiesnoconv("SupplierRef") . ' ' . $ref_supplier . ')' : '');
                } else {
                    $ref_prodserv = $prodser->ref;
                }
                // Show local ref only
                if (!empty($libelleproduitservice)) {
                    $ref_prodserv .= " - ";
                }
            }
            $libelleproduitservice = $prefix_prodserv . $ref_prodserv . $libelleproduitservice;
        }
    }
    // Add an additional description for the category products
    if (!empty($conf->global->CATEGORY_ADD_DESC_INTO_DOC) && $idprod && !empty($conf->categorie->enabled)) {
        include_once DOL_DOCUMENT_ROOT . '/categories/class/categorie.class.php';
        $categstatic = new Categorie($db);
        // recovering the list of all the categories linked to product
        $tblcateg = $categstatic->containing($idprod, Categorie::TYPE_PRODUCT);
        foreach ($tblcateg as $cate) {
            // Adding the descriptions if they are filled
            $desccateg = $cate->add_description;
            if ($desccateg) {
                $libelleproduitservice .= '__N__' . $desccateg;
            }
        }
    }
    if (!empty($object->lines[$i]->date_start) || !empty($object->lines[$i]->date_end)) {
        $format = 'day';
        // Show duration if exists
        if ($object->lines[$i]->date_start && $object->lines[$i]->date_end) {
            $period = '(' . $outputlangs->transnoentitiesnoconv('DateFromTo', dol_print_date($object->lines[$i]->date_start, $format, false, $outputlangs), dol_print_date($object->lines[$i]->date_end, $format, false, $outputlangs)) . ')';
        }
        if ($object->lines[$i]->date_start && !$object->lines[$i]->date_end) {
            $period = '(' . $outputlangs->transnoentitiesnoconv('DateFrom', dol_print_date($object->lines[$i]->date_start, $format, false, $outputlangs)) . ')';
        }
        if (!$object->lines[$i]->date_start && $object->lines[$i]->date_end) {
            $period = '(' . $outputlangs->transnoentitiesnoconv('DateUntil', dol_print_date($object->lines[$i]->date_end, $format, false, $outputlangs)) . ')';
        }
        //print '>'.$outputlangs->charset_output.','.$period;
        $libelleproduitservice .= "__N__" . $period;
        //print $libelleproduitservice;
    }
    if ($dbatch) {
        $format = 'day';
        foreach ($dbatch as $detail) {
            $dte = array();
            if ($detail->eatby) {
                $dte[] = $outputlangs->transnoentitiesnoconv('printEatby', dol_print_date($detail->eatby, $format, false, $outputlangs));
            }
            if ($detail->sellby) {
                $dte[] = $outputlangs->transnoentitiesnoconv('printSellby', dol_print_date($detail->sellby, $format, false, $outputlangs));
            }
            if ($detail->batch) {
                $dte[] = $outputlangs->transnoentitiesnoconv('printBatch', $detail->batch);
            }
            $dte[] = $outputlangs->transnoentitiesnoconv('printQty', $detail->dluo_qty);
            $libelleproduitservice .= "__N__  " . implode($dte, "-");
        }
    }
    // Now we convert \n into br
    if (dol_textishtml($libelleproduitservice)) {
        $libelleproduitservice = preg_replace('/__N__/', '<br>', $libelleproduitservice);
    } else {
        $libelleproduitservice = preg_replace('/__N__/', "\n", $libelleproduitservice);
    }
    $libelleproduitservice = dol_htmlentitiesbr($libelleproduitservice, 1);
    return $libelleproduitservice;
}
Ejemplo n.º 3
0
	/**
	 *    Delete a third party from database and all its dependencies (contacts, rib...)
	 *
	 *    @param	int		$id     Id of third party to delete
	 *    @return	int				<0 if KO, 0 if nothing done, >0 if OK
	 */
	function delete($id) {
		global $user, $langs, $conf;
		require_once(DOL_DOCUMENT_ROOT . "/core/lib/files.lib.php");

		dol_syslog(get_class($this) . "::delete", LOG_DEBUG);
		$error = 0;

		// Test if child exists
		//$objectisused = $this->isObjectUsed($this->rowid); // TODO A reactivier
		if (empty($objectisused)) {


			require_once(DOL_DOCUMENT_ROOT . "/categories/class/categorie.class.php");
			$static_cat = new Categorie($this->db);
			$toute_categs = array();

			// Fill $toute_categs array with an array of (type => array of ("Categorie" instance))
			if ($this->client || $this->prospect) {
				$toute_categs ['societe'] = $static_cat->containing($this->id, 2);
			}
			if ($this->fournisseur) {
				$toute_categs ['fournisseur'] = $static_cat->containing($this->id, 1);
			}

			// Remove each "Categorie"
			foreach ($toute_categs as $type => $categs_type) {
				foreach ($categs_type as $cat) {
					$cat->del_type($this, $type);
				}
			}

			return parent::delete();

			// TODO Supprimer les contacts
			// Remove contacts
			if (!$error) {
				$sql = "DELETE FROM " . MAIN_DB_PREFIX . "socpeople";
				$sql.= " WHERE fk_soc = " . $id;
				dol_syslog(get_class($this) . "::delete sql=" . $sql, LOG_DEBUG);
				if (!$this->db->query($sql)) {
					$error++;
					$this->error .= $this->db->lasterror();
					dol_syslog(get_class($this) . "::delete erreur -1 " . $this->error, LOG_ERR);
				}
			}

			// Update link in member table
			if (!$error) {
				$sql = "UPDATE " . MAIN_DB_PREFIX . "adherent";
				$sql.= " SET fk_soc = NULL WHERE fk_soc = " . $id;
				dol_syslog(get_class($this) . "::delete sql=" . $sql, LOG_DEBUG);
				if (!$this->db->query($sql)) {
					$error++;
					$this->error .= $this->db->lasterror();
					dol_syslog(get_class($this) . "::delete erreur -1 " . $this->error, LOG_ERR);
				}
			}

			// Remove ban
			if (!$error) {
				$sql = "DELETE FROM " . MAIN_DB_PREFIX . "societe_rib";
				$sql.= " WHERE fk_soc = " . $id;
				dol_syslog(get_class($this) . "::Delete sql=" . $sql, LOG_DEBUG);
				if (!$this->db->query($sql)) {
					$error++;
					$this->error = $this->db->lasterror();
					dol_syslog(get_class($this) . "::Delete erreur -2 " . $this->error, LOG_ERR);
				}
			}

			// Removed extrafields
			//$result=$this->deleteExtraFields($this);
			//if ($result < 0) $error++;

			if (!$error) {
				// Additionnal action by hooks
				include_once(DOL_DOCUMENT_ROOT . '/core/class/hookmanager.class.php');
				$hookmanager = new HookManager($this->db);
				$hookmanager->initHooks(array('thirdparty_extrafields'));
				$parameters = array();
				$action = 'delete';
				$reshook = $hookmanager->executeHooks('deleteThirdparty', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
				if (!empty($hookmanager->error)) {
					$error++;
					$this->error = $hookmanager->error;
				}
			}

			// Remove third party
			if (!$error) {
				$sql = "DELETE FROM " . MAIN_DB_PREFIX . "societe";
				$sql.= " WHERE rowid = " . $id;
				dol_syslog(get_class($this) . "::delete sql=" . $sql, LOG_DEBUG);
				if (!$this->db->query($sql)) {
					$error++;
					$this->error = $this->db->lasterror();
					dol_syslog(get_class($this) . "::delete erreur -3 " . $this->error, LOG_ERR);
				}
			}

			if (!$error) {
				// Appel des triggers
				include_once(DOL_DOCUMENT_ROOT . "/core/class/interfaces.class.php");
				$interface = new Interfaces($this->db);
				$result = $interface->run_triggers('COMPANY_DELETE', $this, $user, $langs, $conf);
				if ($result < 0) {
					$error++;
					$this->errors = $interface->errors;
				}
				// Fin appel triggers
			}

			if (!$error) {
				$this->db->commit();

				// Delete directory
				$docdir = $conf->societe->multidir_output[$this->entity] . "/" . $id;
				if (file_exists($docdir)) {
					dol_delete_dir_recursive($docdir);
				}

				return 1;
			} else {
				$this->db->rollback();
				return -1;
			}
		}
	}
Ejemplo n.º 4
0
     }
     print '</td></tr>';
 }
 // Other attributes
 $parameters = array('colspan' => ' colspan="2"');
 $reshook = $hookmanager->executeHooks('formObjectOptions', $parameters, $object, $action);
 // Note that $action and $object may have been modified by hook
 if (empty($reshook) && !empty($extrafields->attribute_label)) {
     print $object->showOptionals($extrafields, 'edit');
 }
 // Tags-Categories
 if ($conf->categorie->enabled) {
     print '<tr><td class="tdtop">' . $langs->trans("Categories") . '</td><td colspan="3">';
     $cate_arbo = $form->select_all_categories(Categorie::TYPE_PRODUCT, '', 'parent', 64, 0, 1);
     $c = new Categorie($db);
     $cats = $c->containing($object->id, Categorie::TYPE_PRODUCT);
     foreach ($cats as $cat) {
         $arrayselected[] = $cat->id;
     }
     print $form->multiselectarray('categories', $cate_arbo, $arrayselected, '', 0, '', 0, '100%');
     print "</td></tr>";
 }
 // Note
 print '<tr><td class="tdtop">' . $langs->trans("NoteNotVisibleOnBill") . '</td><td colspan="3">';
 $doleditor = new DolEditor('note', $object->note, '', 140, 'dolibarr_notes', '', false, true, $conf->global->FCKEDITOR_ENABLE_PRODUCTDESC, 4, 80);
 $doleditor->Create();
 print "</td></tr>";
 print '</table>';
 print '<br>';
 /*if (empty($conf->accounting->enabled) && empty($conf->comptabilite->enabled) && empty($conf->accountingexpert->enabled))
   {
Ejemplo n.º 5
0
 /**
  *  Unsubscribe an email from all mailing-lists
  *  Used when a user is resiliated
  *
  *	@param	Adherent	$object		Object with data (->email, ->pass, ->element, ->type)
  *  @param	array	$listes     To force mailing-list (string separated with ,)
  *  @return int         		<0 if KO, >=0 if OK
  */
 function del_to_mailman($object, $listes = '')
 {
     global $conf, $langs, $user;
     dol_syslog(get_class($this) . "::del_to_mailman");
     $this->mlremoved_ok = array();
     $this->mlremoved_ko = array();
     if (!function_exists("curl_init")) {
         $langs->load("errors");
         $this->error = $langs->trans("ErrorFunctionNotAvailableInPHP", "curl_init");
         return -1;
     }
     if ($conf->adherent->enabled) {
         if (!empty($conf->global->ADHERENT_MAILMAN_UNSUB_URL)) {
             if ($listes == '' && !empty($conf->global->ADHERENT_MAILMAN_LISTS)) {
                 $lists = explode(',', $conf->global->ADHERENT_MAILMAN_LISTS);
             } else {
                 $lists = explode(',', $listes);
             }
             $categstatic = new Categorie($this->db);
             foreach ($lists as $list) {
                 // Filter on type something (ADHERENT_MAILMAN_LISTS = "mailinglist0,TYPE:typevalue:mailinglist1,CATEG:categvalue:mailinglist2")
                 $tmp = explode(':', $list);
                 if (!empty($tmp[2])) {
                     $list = $tmp[2];
                     if ($object->element == 'member' && $tmp[0] == 'TYPE' && $object->type != $tmp[1]) {
                         dol_syslog("We ignore list " . $list . " because object member type " . $object->type . " does not match " . $tmp[1], LOG_DEBUG);
                         continue;
                     }
                     if ($object->element == 'member' && $tmp[0] == 'CATEG' && !in_array($tmp[1], $categstatic->containing($object->id, 'member', 'label'))) {
                         dol_syslog("We ignore list " . $list . " because object member is not into category " . $tmp[1], LOG_DEBUG);
                         continue;
                     }
                 }
                 //We call Mailman to unsubscribe the user
                 $result = $this->callMailman($object, $conf->global->ADHERENT_MAILMAN_UNSUB_URL, $list);
                 if ($result === false) {
                     $this->mlremoved_ko[$list] = $object->email;
                     return -2;
                 } else {
                     $this->mlremoved_ok[$list] = $object->email;
                 }
             }
             return count($lists);
         } else {
             $this->error = "ADHERENT_MAILMAN_UNSUB_URL not defined";
             return -1;
         }
     }
 }
Ejemplo n.º 6
0
 print '<tr><td class="tdtop"><label for="note_private">' . $langs->trans("NotePrivate") . '</label></td><td colspan="3">';
 $doleditor = new DolEditor('note_private', $object->note_private, '', 80, 'dolibarr_notes', 'In', 0, false, true, ROWS_3, 70);
 print $doleditor->Create(1);
 print '</td></tr>';
 // Statut
 print '<tr><td>' . $langs->trans("Status") . '</td>';
 print '<td>';
 print $object->getLibStatut(4);
 print '</td></tr>';
 // Categories
 if (!empty($conf->categorie->enabled) && !empty($user->rights->categorie->lire)) {
     print '<tr><td>' . fieldLabel('Categories', 'contcats') . '</td>';
     print '<td colspan="3">';
     $cate_arbo = $form->select_all_categories(Categorie::TYPE_CONTACT, null, null, null, null, 1);
     $c = new Categorie($db);
     $cats = $c->containing($object->id, Categorie::TYPE_CONTACT);
     foreach ($cats as $cat) {
         $arrayselected[] = $cat->id;
     }
     print $form->multiselectarray('contcats', $cate_arbo, $arrayselected, '', 0, '', 0, '90%');
     print "</td></tr>";
 }
 // Other attributes
 $parameters = array('colspan' => ' colspan="3"');
 $reshook = $hookmanager->executeHooks('formObjectOptions', $parameters, $object, $action);
 // Note that $action and $object may have been modified by hook
 if (empty($reshook) && !empty($extrafields->attribute_label)) {
     print $object->showOptionals($extrafields, 'edit');
 }
 $object->load_ref_elements();
 if (!empty($conf->commande->enabled)) {
Ejemplo n.º 7
0
 /**
  * Sets object to supplied categories.
  *
  * Deletes object from existing categories not supplied.
  * Adds it to non existing supplied categories.
  * Existing categories are left untouch.
  *
  * @param int[]|int $categories Category or categories IDs
  */
 public function setCategories($categories)
 {
     // Handle single category
     if (!is_array($categories)) {
         $categories = array($categories);
     }
     // Get current categories
     require_once DOL_DOCUMENT_ROOT . '/categories/class/categorie.class.php';
     $c = new Categorie($this->db);
     $existing = $c->containing($this->id, Categorie::TYPE_PRODUCT, 'id');
     // Diff
     if (is_array($existing)) {
         $to_del = array_diff($existing, $categories);
         $to_add = array_diff($categories, $existing);
     } else {
         $to_del = array();
         // Nothing to delete
         $to_add = $categories;
     }
     // Process
     foreach ($to_del as $del) {
         $c->fetch($del);
         $c->del_type($this, 'product');
     }
     foreach ($to_add as $add) {
         $c->fetch($add);
         $c->add_type($this, 'product');
     }
     return;
 }
Ejemplo n.º 8
0
	/**
	 * Sets object to supplied categories.
	 *
	 * Deletes object from existing categories not supplied.
	 * Adds it to non existing supplied categories.
	 * Existing categories are left untouch.
	 *
	 * @param int[]|int $categories Category or categories IDs
	 * @param string $type Category type (customer or supplier)
	 */
	public function setCategories($categories, $type)
	{
		// Decode type
		if ($type == 'customer') {
			$type_id = Categorie::TYPE_CUSTOMER;
			$type_text = 'customer';
		} elseif ($type == 'supplier') {
			$type_id = Categorie::TYPE_SUPPLIER;
			$type_text = 'supplier';
		} else {
			dol_syslog(__METHOD__ . ': Type ' . $type .  'is an unknown company category type. Done nothing.', LOG_ERR);
			return;
		}

		// Handle single category
		if (!is_array($categories)) {
			$categories = array($categories);
		}

		// Get current categories
		require_once DOL_DOCUMENT_ROOT . '/categories/class/categorie.class.php';
		$c = new Categorie($this->db);
		$existing = $c->containing($this->id, $type_id, 'id');

		// Diff
		if (is_array($existing)) {
			$to_del = array_diff($existing, $categories);
			$to_add = array_diff($categories, $existing);
		} else {
			$to_del = array(); // Nothing to delete
			$to_add = $categories;
		}

		// Process
		foreach ($to_del as $del) {
			if ($c->fetch($del) > 0) {
				$c->del_type($this, $type_text);
			}
		}
		foreach ($to_add as $add) {
			if ($c->fetch($add) > 0) {
				$c->add_type($this, $type_text);
			}
		}

		return;
	}
Ejemplo n.º 9
0
 //affichage onglet cat�gorie
 if (!empty($conf->categorie->enabled)) {
     $head[$h][0] = DOL_URL_ROOT . "/fourn/product/categorie.php?id=" . $product->id;
     $head[$h][1] = $langs->trans('Categories');
     $hselected = $h;
     $h++;
 }
 dol_fiche_head($head, $hselected, $langs->trans("CardProduct" . $product->type) . ' : ' . $product->ref);
 print $mesg;
 print '<table class="border" width="100%">';
 print "<tr>";
 print '<td>' . $langs->trans("Ref") . '</td><td>' . $product->ref . '</td>';
 print '<tr><td>' . $langs->trans("Label") . '</td><td>' . $product->libelle . '</td>';
 print "</table><br>\n";
 $c = new Categorie($db);
 $cats = $c->containing($_REQUEST['id'], 0);
 if (count($cats) > 0) {
     print "Vous avez stock� le produit dans les cat�gorie suivantes:<br/><br/>";
     print '<table class="noborder" width="100%">';
     print '<tr class="liste_titre"><td colspan="2">' . $langs->trans("AllWays") . '</td></tr>';
     foreach ($cats as $cat) {
         $ways = $cat->print_all_ways();
         foreach ($ways as $way) {
             $i = !$i;
             print "<tr " . $bc[$i] . "><td>" . $way . "</td>";
             print "<td><a href= '" . DOL_URL_ROOT . "/fourn/product/categorie.php?id=" . $product->id . "&amp;cat=" . $cat->id . "'>" . $langs->trans("DeleteFromCat") . "</a></td></tr>\n";
         }
     }
     print "</table><br/><br/>\n";
 } else {
     if ($cats < 0) {
Ejemplo n.º 10
0
/**
 * 	Function to output a form to add object into a category
 *
 * 	@param		DoliDb		$db					Database handler
 * 	@param		Object		$object				Object we want to see categories it can be classified into
 * 	@param		int			$typeid				Type of category (0, 1, 2, 3)
 *  @param		int			$socid				Id thirdparty
 *  @param		int		$showclassifyform	1=Add form to 'Classify', 0=Do not show form to 'Classify'
 *  @return		int			0
 */
function formCategory($db, $object, $typeid, $socid = 0, $showclassifyform = 1)
{
    global $user, $langs, $form, $bc;
    if ($typeid == Categorie::TYPE_PRODUCT) {
        $title = $langs->trans("ProductsCategoriesShort");
    }
    if ($typeid == Categorie::TYPE_SUPPLIER) {
        $title = $langs->trans("SuppliersCategoriesShort");
    }
    if ($typeid == Categorie::TYPE_CUSTOMER) {
        $title = $langs->trans("CustomersProspectsCategoriesShort");
    }
    if ($typeid == Categorie::TYPE_MEMBER) {
        $title = $langs->trans("MembersCategoriesShort");
    }
    if ($typeid == Categorie::TYPE_CONTACT) {
        $title = $langs->trans("ContactCategoriesShort");
    }
    $linktocreate = '';
    if ($showclassifyform && $user->rights->categorie->creer) {
        $linktocreate = '<a href="' . DOL_URL_ROOT . '/categories/card.php?action=create&amp;origin=' . $object->id . '&type=' . $typeid . '&urlfrom=' . urlencode($_SERVER["PHP_SELF"] . '?' . ($typeid == Categorie::TYPE_SUPPLIER || $typeid == Categorie::TYPE_CUSTOMER ? 'socid' : 'id') . '=' . $object->id . '&type=' . $typeid) . '">';
        $linktocreate .= $langs->trans("CreateCat") . ' ';
        $linktocreate .= img_picto($langs->trans("Create"), 'filenew');
        $linktocreate .= "</a>";
    }
    print '<br>';
    print load_fiche_titre($title, $linktocreate, '');
    // Form to add record into a category
    if ($showclassifyform) {
        print '<form method="post" action="' . $_SERVER["PHP_SELF"] . '">';
        print '<input type="hidden" name="token" value="' . $_SESSION['newtoken'] . '">';
        print '<input type="hidden" name="typeid" value="' . $typeid . '">';
        print '<input type="hidden" name="type" value="' . $typeid . '">';
        print '<input type="hidden" name="id" value="' . $object->id . '">';
        print '<table class="noborder" width="100%">';
        print '<tr class="liste_titre"><td width="40%">';
        print '<span class="hideonsmartphone">' . $langs->trans("ClassifyInCategory") . ' &nbsp;</span>';
        print $form->select_all_categories($typeid, 'auto');
        print '</td>';
        print '<td><input type="submit" class="button" value="' . $langs->trans("Classify") . '"></td>';
        print '</tr>';
        print '</table>';
        print '</form>';
        print '<br>';
    }
    $c = new Categorie($db);
    $cats = $c->containing($object->id, $typeid);
    if (count($cats) > 0) {
        if ($typeid == Categorie::TYPE_PRODUCT) {
            $title = $langs->trans("ProductIsInCategories");
        }
        if ($typeid == Categorie::TYPE_SUPPLIER) {
            $title = $langs->trans("CompanyIsInSuppliersCategories");
        }
        if ($typeid == Categorie::TYPE_CUSTOMER) {
            $title = $langs->trans("CompanyIsInCustomersCategories");
        }
        if ($typeid == Categorie::TYPE_MEMBER) {
            $title = $langs->trans("MemberIsInCategories");
        }
        if ($typeid == Categorie::TYPE_CONTACT) {
            $title = $langs->trans("ContactIsInCategories");
        }
        print "\n";
        print '<table class="noborder" width="100%">';
        print '<tr class="liste_titre"><td colspan="2">' . $title . ':</td></tr>';
        $var = true;
        foreach ($cats as $cat) {
            $ways = $cat->print_all_ways();
            foreach ($ways as $way) {
                $var = !$var;
                print "<tr " . $bc[$var] . ">";
                // Categorie
                print "<td>" . img_object('', 'category') . ' ' . $way . "</td>";
                // Link to delete from category
                print '<td align="right">';
                $permission = 0;
                if ($typeid == Categorie::TYPE_PRODUCT) {
                    $permission = $user->rights->produit->creer || $user->rights->service->creer;
                }
                if ($typeid == Categorie::TYPE_SUPPLIER) {
                    $permission = $user->rights->societe->creer;
                }
                if ($typeid == Categorie::TYPE_CUSTOMER) {
                    $permission = $user->rights->societe->creer;
                }
                if ($typeid == Categorie::TYPE_MEMBER) {
                    $permission = $user->rights->adherent->creer;
                }
                if ($typeid == Categorie::TYPE_CONTACT) {
                    $permission = $user->rights->societe->creer;
                }
                if ($permission) {
                    print "<a href= '" . $_SERVER['PHP_SELF'] . "?" . (empty($socid) ? 'id' : 'socid') . "=" . $object->id . "&amp;type=" . $typeid . "&amp;removecat=" . $cat->id . "'>";
                    print img_delete($langs->trans("DeleteFromCat")) . ' ';
                    print $langs->trans("DeleteFromCat") . "</a>";
                } else {
                    print '&nbsp;';
                }
                print "</td>";
                print "</tr>\n";
            }
        }
        print "</table>\n";
    } else {
        if ($cats < 0) {
            print $langs->trans("ErrorUnknown");
        } else {
            if ($typeid == Categorie::TYPE_PRODUCT) {
                $title = $langs->trans("ProductHasNoCategory");
            }
            if ($typeid == Categorie::TYPE_SUPPLIER) {
                $title = $langs->trans("CompanyHasNoCategory");
            }
            if ($typeid == Categorie::TYPE_CUSTOMER) {
                $title = $langs->trans("CompanyHasNoCategory");
            }
            if ($typeid == Categorie::TYPE_MEMBER) {
                $title = $langs->trans("MemberHasNoCategory");
            }
            if ($typeid == Categorie::TYPE_CONTACT) {
                $title = $langs->trans("ContactHasNoCategory");
            }
            print $title;
            print "<br/>";
        }
    }
    return 0;
}
Ejemplo n.º 11
0
         $cate_arbo = $form->select_all_categories(Categorie::TYPE_CUSTOMER, null, null, null, null, 1);
         $c = new Categorie($db);
         $cats = $c->containing($object->id, Categorie::TYPE_CUSTOMER);
         foreach ($cats as $cat) {
             $arrayselected[] = $cat->id;
         }
         print $form->multiselectarray('custcats', $cate_arbo, $arrayselected, '', 0, '', 0, '90%');
         print "</td></tr>";
     }
     // Supplier
     if ($object->fournisseur) {
         print '<tr><td>' . fieldLabel('SuppliersCategoriesShort', 'suppcats') . '</td>';
         print '<td colspan="3">';
         $cate_arbo = $form->select_all_categories(Categorie::TYPE_SUPPLIER, null, null, null, null, 1);
         $c = new Categorie($db);
         $cats = $c->containing($object->id, Categorie::TYPE_SUPPLIER);
         foreach ($cats as $cat) {
             $arrayselected[] = $cat->id;
         }
         print $form->multiselectarray('suppcats', $cate_arbo, $arrayselected, '', 0, '', 0, '90%');
         print "</td></tr>";
     }
 }
 // Other attributes
 $parameters = array('colspan' => ' colspan="3"', 'colspanvalue' => '3');
 $reshook = $hookmanager->executeHooks('formObjectOptions', $parameters, $object, $action);
 // Note that $action and $object may have been modified by hook
 print $hookmanager->resPrint;
 if (empty($reshook) && !empty($extrafields->attribute_label)) {
     print $object->showOptionals($extrafields, 'edit');
 }
Ejemplo n.º 12
0
 /**
  * testCategorieProduct
  *
  * @param   int $id     Id of category
  * @return  int
  *
  * @depends testCategorieCreate
  * The depends says test is run only if previous is ok
  */
 public function testCategorieProduct($id)
 {
     global $conf, $user, $langs, $db;
     $conf = $this->savconf;
     $user = $this->savuser;
     $langs = $this->savlangs;
     $db = $this->savdb;
     $localobjecttmp = new Categorie($this->savdb);
     $localobjecttmp->initAsSpecimen();
     $localobjecttmp->label = 'Specimen Category for product';
     $localobjecttmp->type = 0;
     // product category
     $catid = $localobjecttmp->create($user);
     print __METHOD__ . " catid=" . $catid . "\n";
     $this->assertGreaterThan(0, $catid);
     // Try to create product linked to category
     $localobject2 = new Product($this->savdb);
     $localobject2->initAsSpecimen();
     $localobject2->ref .= '-CATEG';
     $localobject2->tva_npr = 1;
     $result = $localobject2->create($user);
     $cat = new Categorie($this->savdb);
     $cat->id = $catid;
     $result = $cat->add_type($localobject2, "product");
     print __METHOD__ . " result=" . $result . "\n";
     $this->assertGreaterThan(0, $result);
     // Get list of categories for product
     $localcateg = new Categorie($this->savdb);
     $listofcateg = $localcateg->containing($localobject2->id, 'product', 'label');
     $this->assertTrue(in_array('Specimen Category for product', $listofcateg), 'Categ not found linked to product when it should');
     return $id;
 }
Ejemplo n.º 13
0
 }
 // Birthday
 print "<tr><td>" . $langs->trans("Birthday") . "</td><td>\n";
 $form->select_date($object->birth ? $object->birth : -1, 'birth', '', '', 1, 'formsoc');
 print "</td></tr>\n";
 // Public profil
 print "<tr><td>" . $langs->trans("Public") . "</td><td>\n";
 print $form->selectyesno("public", isset($_POST["public"]) ? $_POST["public"] : $object->public, 1);
 print "</td></tr>\n";
 // Categories
 if (!empty($conf->categorie->enabled) && !empty($user->rights->categorie->lire)) {
     print '<tr><td>' . fieldLabel('Categories', 'memcats') . '</td>';
     print '<td colspan="2">';
     $cate_arbo = $form->select_all_categories(Categorie::TYPE_MEMBER, null, null, null, null, 1);
     $c = new Categorie($db);
     $cats = $c->containing($object->id, Categorie::TYPE_MEMBER);
     foreach ($cats as $cat) {
         $arrayselected[] = $cat->id;
     }
     print $form->multiselectarray('memcats', $cate_arbo, $arrayselected, '', 0, '', 0, '100%');
     print "</td></tr>";
 }
 // Other attributes
 $parameters = array("colspan" => 2);
 $reshook = $hookmanager->executeHooks('formObjectOptions', $parameters, $object, $action);
 // Note that $action and $object may have been modified by hook
 if (empty($reshook) && !empty($extrafields->attribute_label)) {
     print $object->showOptionals($extrafields, 'edit', $parameters);
 }
 // Third party Dolibarr
 if (!empty($conf->societe->enabled)) {
Ejemplo n.º 14
0
 /**
  * 	Render list of categories linked to object with id $id and type $type
  *
  * 	@param		int		$id				Id of object
  * 	@param		string	$type			Type of category ('member', 'customer', 'supplier', 'product', 'contact'). Old mode (0, 1, 2, ...) is deprecated.
  *  @param		int		$rendermode		0=Default, use multiselect. 1=Emulate multiselect (recommended)
  * 	@return		mixed					Array of category objects or < 0 if KO
  */
 function showCategories($id, $type, $rendermode = 0)
 {
     global $db;
     include_once DOL_DOCUMENT_ROOT . '/categories/class/categorie.class.php';
     $cat = new Categorie($db);
     $categories = $cat->containing($id, $type);
     if ($rendermode == 1) {
         $toprint = array();
         foreach ($categories as $c) {
             $ways = $c->print_all_ways();
             // $ways[0] = "ccc2 >> ccc2a >> ccc2a1" with html formated text
             foreach ($ways as $way) {
                 $toprint[] = '<li class="select2-search-choice-dolibarr noborderoncategories"' . ($c->color ? ' style="background: #' . $c->color . ';"' : ' style="background: #aaa"') . '>' . img_object('', 'category') . ' ' . $way . '</li>';
             }
         }
         return '<div class="select2-container-multi-dolibarr" style="width: 90%;"><ul class="select2-choices-dolibarr">' . implode(' ', $toprint) . '</ul></div>';
     }
     if ($rendermode == 0) {
         $cate_arbo = $this->select_all_categories($type, '', 'parent', 64, 0, 1);
         foreach ($categories as $c) {
             $arrayselected[] = $c->id;
         }
         return $this->multiselectarray('categories', $cate_arbo, $arrayselected, '', 0, '', 0, '100%', 'disabled', 'category');
     }
     return 'ErrorBadValueForParameterRenderMode';
     // Should not happened
 }
 /**
  *    Delete a third party from database and all its dependencies (contacts, rib...)
  *
  *    @param	int		$id     Id of third party to delete
  *    @return	int				<0 if KO, 0 if nothing done, >0 if OK
  */
 function delete($id)
 {
     global $user, $langs, $conf;
     require_once DOL_DOCUMENT_ROOT . '/core/lib/files.lib.php';
     $entity = isset($this->entity) ? $this->entity : $conf->entity;
     dol_syslog(get_class($this) . "::delete", LOG_DEBUG);
     $error = 0;
     // Test if child exists
     $objectisused = $this->isObjectUsed($id);
     if (empty($objectisused)) {
         $this->db->begin();
         if (!$error) {
             // Appel des triggers
             include_once DOL_DOCUMENT_ROOT . '/core/class/interfaces.class.php';
             $interface = new Interfaces($this->db);
             $result = $interface->run_triggers('COMPANY_DELETE', $this, $user, $langs, $conf);
             if ($result < 0) {
                 $error++;
                 $this->errors = $interface->errors;
             }
             // Fin appel triggers
         }
         if (!$error) {
             require_once DOL_DOCUMENT_ROOT . '/categories/class/categorie.class.php';
             $static_cat = new Categorie($this->db);
             $toute_categs = array();
             // Fill $toute_categs array with an array of (type => array of ("Categorie" instance))
             if ($this->client || $this->prospect) {
                 $toute_categs['societe'] = $static_cat->containing($this->id, 2);
             }
             if ($this->fournisseur) {
                 $toute_categs['fournisseur'] = $static_cat->containing($this->id, 1);
             }
             // Remove each "Categorie"
             foreach ($toute_categs as $type => $categs_type) {
                 foreach ($categs_type as $cat) {
                     $cat->del_type($this, $type);
                 }
             }
         }
         // Remove contacts
         if (!$error) {
             $sql = "DELETE FROM " . MAIN_DB_PREFIX . "socpeople";
             $sql .= " WHERE fk_soc = " . $id;
             dol_syslog(get_class($this) . "::delete sql=" . $sql, LOG_DEBUG);
             if (!$this->db->query($sql)) {
                 $error++;
                 $this->error .= $this->db->lasterror();
                 dol_syslog(get_class($this) . "::delete erreur -1 " . $this->error, LOG_ERR);
             }
         }
         // Update link in member table
         if (!$error) {
             $sql = "UPDATE " . MAIN_DB_PREFIX . "adherent";
             $sql .= " SET fk_soc = NULL WHERE fk_soc = " . $id;
             dol_syslog(get_class($this) . "::delete sql=" . $sql, LOG_DEBUG);
             if (!$this->db->query($sql)) {
                 $error++;
                 $this->error .= $this->db->lasterror();
                 dol_syslog(get_class($this) . "::delete erreur -1 " . $this->error, LOG_ERR);
             }
         }
         // Remove ban
         if (!$error) {
             $sql = "DELETE FROM " . MAIN_DB_PREFIX . "societe_rib";
             $sql .= " WHERE fk_soc = " . $id;
             dol_syslog(get_class($this) . "::Delete sql=" . $sql, LOG_DEBUG);
             if (!$this->db->query($sql)) {
                 $error++;
                 $this->error = $this->db->lasterror();
                 dol_syslog(get_class($this) . "::delete erreur -2 " . $this->error, LOG_ERR);
             }
         }
         // Removed extrafields
         if (!$error && empty($conf->global->MAIN_EXTRAFIELDS_DISABLED)) {
             $result = $this->deleteExtraFields();
             if ($result < 0) {
                 $error++;
                 dol_syslog(get_class($this) . "::delete error -3 " . $this->error, LOG_ERR);
             }
         }
         // Remove third party
         if (!$error) {
             $sql = "DELETE FROM " . MAIN_DB_PREFIX . "societe";
             $sql .= " WHERE rowid = " . $id;
             dol_syslog(get_class($this) . "::delete sql=" . $sql, LOG_DEBUG);
             if (!$this->db->query($sql)) {
                 $error++;
                 $this->error = $this->db->lasterror();
                 dol_syslog(get_class($this) . "::delete error -4 " . $this->error, LOG_ERR);
             }
         }
         if (!$error) {
             $this->db->commit();
             // Delete directory
             if (!empty($conf->societe->multidir_output[$entity])) {
                 $docdir = $conf->societe->multidir_output[$entity] . "/" . $id;
                 if (dol_is_dir($docdir)) {
                     dol_delete_dir_recursive($docdir);
                 }
             }
             return 1;
         } else {
             $this->db->rollback();
             return -1;
         }
     } else {
         dol_syslog("Can't remove thirdparty with id " . $id . ". There is " . $objectisused . " childs", LOG_WARNING);
     }
     return 0;
 }
Ejemplo n.º 16
0
/**
 * 	Function to output a HTML select for a category
 *
 * 	@param		DoliDb		$db			Database handler
 * 	@param		Object		$object		Object we want to see categories it can be classified into
 * 	@param		int			$typeid		Type of category (0, 1, 2, 3)
 *  @param		int			$socid		Id thirdparty
 *  @return		int			0
 */
function formCategory($db, $object, $typeid, $socid = 0)
{
    global $user, $langs, $form, $bc;
    if ($typeid == 0) {
        $title = $langs->trans("ProductsCategoriesShort");
    }
    if ($typeid == 1) {
        $title = $langs->trans("SuppliersCategoriesShort");
    }
    if ($typeid == 2) {
        $title = $langs->trans("CustomersProspectsCategoriesShort");
    }
    if ($typeid == 3) {
        $title = $langs->trans("MembersCategoriesShort");
    }
    if ($typeid == 4) {
        $title = $langs->trans("ProductsCategoriesShort");
    }
    if ($typeid == 5) {
        $title = $langs->trans("ContactsCategoriesShort");
    }
    // Formulaire ajout dans une categorie
    print '<br>';
    print_fiche_titre($title, '', '');
    print '<form method="post" action="' . DOL_URL_ROOT . '/categories/categorie.php">';
    print '<input type="hidden" name="token" value="' . $_SESSION['newtoken'] . '">';
    print '<input type="hidden" name="typeid" value="' . $typeid . '">';
    print '<input type="hidden" name="type" value="' . $typeid . '">';
    print '<input type="hidden" name="id" value="' . $object->id . '">';
    print '<table class="noborder" width="100%">';
    print '<tr class="liste_titre"><td class="liste_titre" width="25%">';
    print $langs->trans("ClassifyInCategory") . '</td><td>';
    if ($typeid == 4) {
        print $form->select_all_categories(0);
    } else {
        print $form->select_all_categories($typeid);
    }
    print '<input type="submit" class="button" value="' . $langs->trans("Classify") . '"></td>';
    if ($user->rights->categorie->creer) {
        print '<td align="right">';
        print '<a href="' . DOL_URL_ROOT . '/categories/fiche.php?action=create&amp;origin=' . $object->id . '&type=' . $typeid . '&urlfrom=' . urlencode($_SERVER["PHP_SELF"] . '?' . ($typeid == 1 || $typeid == 2 ? 'socid' : 'id') . '=' . $object->id . '&type=' . $typeid) . '">';
        print $langs->trans("CreateCat") . ' ';
        print img_picto($langs->trans("Create"), 'filenew');
        print "</a>";
        print '</td>';
    }
    print '</tr>';
    print '</table>';
    print '</form>';
    print '<br/>';
    $c = new Categorie($db);
    $cats = $c->containing($object->id, $typeid);
    if (count($cats) > 0) {
        if ($typeid == 0) {
            $title = $langs->trans("ProductIsInCategories");
        }
        if ($typeid == 1) {
            $title = $langs->trans("CompanyIsInSuppliersCategories");
        }
        if ($typeid == 2) {
            $title = $langs->trans("CompanyIsInCustomersCategories");
        }
        if ($typeid == 3) {
            $title = $langs->trans("MemberIsInCategories");
        }
        if ($typeid == 4) {
            $title = $langs->trans("LeadProductIsInCategories");
        }
        if ($typeid == 5) {
            $title = $langs->trans("ContactIsInCategories");
        }
        print "\n";
        print '<table class="noborder" width="100%">';
        print '<tr class="liste_titre"><td colspan="2">' . $title . ':</td></tr>';
        $var = true;
        foreach ($cats as $cat) {
            $ways = $cat->print_all_ways();
            foreach ($ways as $way) {
                $var = !$var;
                print "<tr " . $bc[$var] . ">";
                // Categorie
                print "<td>";
                //$c->id=;
                //print $c->getNomUrl(1);
                print img_object('', 'category') . ' ' . $way . "</td>";
                // Lien supprimer
                print '<td align="right">';
                $permission = 0;
                if ($typeid == 0) {
                    $permission = $user->rights->produit->creer || $user->rights->service->creer;
                }
                if ($typeid == 1) {
                    $permission = $user->rights->societe->creer;
                }
                if ($typeid == 2) {
                    $permission = $user->rights->societe->creer;
                }
                if ($typeid == 3) {
                    $permission = $user->rights->adherent->creer;
                }
                if ($typeid == 4) {
                    $permission = $user->rights->lead->creer;
                }
                if ($typeid == 5) {
                    $permission = $user->rights->societe->creer;
                }
                if ($permission) {
                    print "<a href= '" . $_SERVER['PHP_SELF'] . "?" . (empty($socid) ? 'id' : 'socid') . "=" . $object->id . "&amp;type=" . $typeid . "&amp;removecat=" . $cat->id . "'>";
                    print img_delete($langs->trans("DeleteFromCat")) . ' ';
                    print $langs->trans("DeleteFromCat") . "</a>";
                } else {
                    print '&nbsp;';
                }
                print "</td>";
                print "</tr>\n";
            }
        }
        print "</table>\n";
    } else {
        if ($cats < 0) {
            print $langs->trans("ErrorUnknown");
        } else {
            if ($typeid == 0) {
                $title = $langs->trans("ProductHasNoCategory");
            }
            if ($typeid == 1) {
                $title = $langs->trans("CompanyHasNoCategory");
            }
            if ($typeid == 2) {
                $title = $langs->trans("CompanyHasNoCategory");
            }
            if ($typeid == 3) {
                $title = $langs->trans("MemberHasNoCategory");
            }
            if ($typeid == 4) {
                $title = $langs->trans("LeadHasNoCategory");
            }
            if ($typeid == 5) {
                $title = $langs->trans("ContactHasNoCategory");
            }
            print $title;
            print "<br/>";
        }
    }
    return 0;
}