Example #1
0
 /**
  * Delete category
  *
  * @param int $id   Category ID
  * @return array
  * 
  * @url	DELETE category/{id}
  */
 function delete($id)
 {
     if (!DolibarrApiAccess::$user->rights->categorie->supprimer) {
         throw new RestException(401);
     }
     $result = $this->category->fetch($id);
     if (!$result) {
         throw new RestException(404, 'category not found');
     }
     if (!DolibarrApi::_checkAccessToResource('category', $this->category->id)) {
         throw new RestException(401, 'Access not allowed for login ' . DolibarrApiAccess::$user->login);
     }
     if (!$this->category->delete(DolibarrApiAccess::$user)) {
         throw new RestException(401, 'error when delete category');
     }
     return array('success' => array('code' => 200, 'message' => 'Category deleted'));
 }
function _categories($fk_parent = 0, $keyword = '')
{
    global $db, $conf;
    $TFille = array();
    if (!empty($keyword)) {
        $resultset = $db->query("SELECT rowid FROM " . MAIN_DB_PREFIX . "categorie WHERE label LIKE '%" . addslashes($keyword) . "%' ORDER BY label");
        while ($obj = $db->fetch_object($resultset)) {
            $cat = new Categorie($db);
            $cat->fetch($obj->rowid);
            $TFille[] = $cat;
        }
    } else {
        $parent = new Categorie($db);
        if (empty($fk_parent)) {
            if (empty($conf->global->SPC_DO_NOT_LOAD_PARENT_CAT)) {
                $TFille = $parent->get_all_categories(0, true);
            }
        } else {
            $parent->fetch($fk_parent);
            $TFille = $parent->get_filles();
        }
    }
    return $TFille;
}
 /**
  * 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;
 }
Example #4
0
    /**
     * @depends	testCategorieOther
     * The depends says test is run only if previous is ok
     */
    public function testCategorieDelete($id)
    {
    	global $conf,$user,$langs,$db;
		$conf=$this->savconf;
		$user=$this->savuser;
		$langs=$this->savlangs;
		$db=$this->savdb;

		$localobject=new Categorie($this->savdb);
    	$result=$localobject->fetch($id);
		$result=$localobject->delete($id);

		print __METHOD__." id=".$id." result=".$result."\n";
    	$this->assertLessThan($result, 0);
    	return $result;
    }
Example #5
0
         $texte = $langs->trans("Products");
     }
 } else {
     $texte = $langs->trans("ProductsAndServices");
 }
 $texte .= ' (' . $langs->trans("Stocks") . ')';
 llxHeader("", $texte, $helpurl);
 if ($sref || $snom || $sall || GETPOST('search')) {
     print_barre_liste($texte, $page, $_SERVER["PHP_SELF"], "&sref=" . $sref . "&snom=" . $snom . "&sall=" . $sall . "&tosell=" . $tosell . "&tobuy=" . $tobuy . (!empty($search_categ) ? '&search_categ=' . $search_categ : '') . (!empty($toolowstock) ? '&toolowstock=' . $toolowstock : ''), $sortfield, $sortorder, '', $num);
 } else {
     print_barre_liste($texte, $page, $_SERVER["PHP_SELF"], "&sref={$sref}&snom={$snom}&fourn_id={$fourn_id}" . (isset($type) ? "&type={$type}" : "") . (!empty($search_categ) ? '&search_categ=' . $search_categ : '') . (!empty($toolowstock) ? '&toolowstock=' . $toolowstock : ''), $sortfield, $sortorder, '', $num);
 }
 if (!empty($catid)) {
     print "<div id='ways'>";
     $c = new Categorie($db);
     $c->fetch($catid);
     $ways = $c->print_all_ways(' &gt; ', 'product/reassort.php');
     print " &gt; " . $ways[0] . "<br>\n";
     print "</div><br>";
 }
 print '<form action="' . $_SERVER["PHP_SELF"] . '" method="post" name="formulaire">';
 print '<input type="hidden" name="token" value="' . $_SESSION['newtoken'] . '">';
 print '<input type="hidden" name="sortfield" value="' . $sortfield . '">';
 print '<input type="hidden" name="sortorder" value="' . $sortorder . '">';
 print '<input type="hidden" name="type" value="' . $type . '">';
 print '<table class="liste" width="100%">';
 // Filter on categories
 $moreforfilter = '';
 if (!empty($conf->categorie->enabled)) {
     $moreforfilter .= $langs->trans('Categories') . ': ';
     $moreforfilter .= $htmlother->select_categories(Categorie::TYPE_PRODUCT, $search_categ, 'search_categ');
Example #6
0
        if ($categorie->update($user) > 0) {
            header('Location: ' . DOL_URL_ROOT . '/categories/viewcat.php?id=' . $categorie->id . '&type=' . $type);
            exit;
        } else {
            setEventMessage($categorie->error, 'errors');
        }
    } else {
        setEventMessage($categorie->error, 'errors');
    }
}
/*
 * View
 */
llxHeader("", "", $langs->trans("Categories"));
print_fiche_titre($langs->trans("ModifCat"));
$object->fetch($id);
$form = 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="token" value="' . $_SESSION['newtoken'] . '">';
print '<input type="hidden" name="action" value="update">';
print '<input type="hidden" name="id" value="' . $object->id . '">';
print '<input type="hidden" name="type" value="' . $type . '">';
print '<table class="border" width="100%">';
// Ref
print '<tr><td class="fieldrequired">';
print $langs->trans("Ref") . '</td>';
print '<td><input type="text" size="25" id="nom" name ="nom" value="' . $object->label . '" />';
print '</tr>';
Example #7
0
 /**
  * 	Retourne les categories dont l'id ou le nom correspond
  * 	ajoute des wildcards au nom sauf si $exact = true
  *
  * 	@param		int			$id			Id
  * 	@param		string		$nom		Name
  * 	@param		string		$type		Type
  * 	@param		boolean		$exact		Ture or false
  * 	@return		array		Array of category id
  */
 function rechercher($id, $nom, $type, $exact = false)
 {
     $cats = array();
     // Generation requete recherche
     $sql = "SELECT rowid FROM " . MAIN_DB_PREFIX . "categorie";
     $sql .= " WHERE type = " . $type . " ";
     $sql .= " AND entity IN (" . getEntity('category', 1) . ")";
     if ($nom) {
         if (!$exact) {
             $nom = '%' . str_replace('*', '%', $nom) . '%';
         }
         $sql .= "AND label LIKE '" . $nom . "'";
     }
     if ($id) {
         $sql .= "AND rowid = '" . $id . "'";
     }
     $res = $this->db->query($sql);
     if ($res) {
         while ($rec = $this->db->fetch_array($res)) {
             $cat = new Categorie($this->db);
             $cat->fetch($rec['rowid']);
             $cats[] = $cat;
         }
         return $cats;
     } else {
         $this->error = $this->db->error() . ' sql=' . $sql;
         dol_syslog("Categorie::rechercher " . $this->error, LOG_ERR);
         return -1;
     }
 }
Example #8
0
	}
	if ($_REQUEST["type"]==2 && $user->rights->societe->creer)
	{
		$object = new Societe($db);
		$result = $object->fetch($objectid);
		$type = 'societe';
	}
	if ($_REQUEST["type"]==3 && $user->rights->adherent->creer)
	{
		require_once(DOL_DOCUMENT_ROOT."/adherents/class/adherent.class.php");
		$object = new Adherent($db);
		$result = $object->fetch($objectid);
		$type = 'member';
	}
	$cat = new Categorie($db);
	$result=$cat->fetch($_REQUEST["catMere"]);

	$result=$cat->add_type($object,$type);
	if ($result >= 0)
	{
		$mesg='<div class="ok">'.$langs->trans("WasAddedSuccessfully",$cat->label).'</div>';
	}
	else
	{
		if ($cat->error == 'DB_ERROR_RECORD_ALREADY_EXISTS') $mesg='<div class="warning">'.$langs->trans("ObjectAlreadyLinkedToCategory").'</div>';
		else $mesg='<div class="error">'.$langs->trans("Error").' '.$cat->error.'</div>';
	}

}

Example #9
0
$langs->load("categories");
$id = GETPOST('id', 'int');
$ref = GETPOST('ref');
$type = GETPOST('type');
$action = GETPOST('action');
$confirm = GETPOST('confirm');
$removeelem = GETPOST('removeelem', 'int');
$elemid = GETPOST('elemid');
if ($id == "") {
    dol_print_error('', 'Missing parameter id');
    exit;
}
// Security check
$result = restrictedArea($user, 'categorie', $id, '&category');
$object = new Categorie($db);
$result = $object->fetch($id);
$object->fetch_optionals($id, $extralabels);
if ($result <= 0) {
    dol_print_error($db, $object->error);
    exit;
}
$type = $object->type;
$extrafields = new ExtraFields($db);
$extralabels = $extrafields->fetch_name_optionals_label($object->table_element);
// Initialize technical object to manage hooks. Note that conf->hooks_modules contains array array
$hookmanager->initHooks(array('categorycard'));
/*
 *	Actions
 */
// Remove element from category
if ($id > 0 && $removeelem > 0) {
 /**
  * 	Retourne les categories dont l'id ou le nom correspond
  * 	ajoute des wildcards au nom sauf si $exact = true
  *
  * 	@param		int			$id			Id
  * 	@param		string		$nom		Name
  * 	@param		string		$type		Type of category ('member', 'customer', 'supplier', 'product', 'contact'). Old mode (0, 1, 2, ...) is deprecated.
  * 	@param		boolean		$exact		Exact string search (true/false)
  * 	@param		boolean		$case		Case sensitive (true/false)
  * 	@return		array					Array of category id
  */
 function rechercher($id, $nom, $type, $exact = false, $case = false)
 {
     // Deprecation warning
     if (is_numeric($type)) {
         dol_syslog(__METHOD__ . ': using numeric types is deprecated.', LOG_WARNING);
     }
     $cats = array();
     // For backward compatibility
     if (is_numeric($type)) {
         // We want to reverse lookup
         $map_type = array_flip($this->MAP_ID);
         $type = $map_type;
         dol_syslog(get_class($this) . "::rechercher(): numeric types are deprecated, please use string instead", LOG_WARNING);
     }
     // Generation requete recherche
     $sql = "SELECT rowid FROM " . MAIN_DB_PREFIX . "categorie";
     $sql .= " WHERE type = " . $this->MAP_ID[$type];
     $sql .= " AND entity IN (" . getEntity('category', 1) . ")";
     if ($nom) {
         if (!$exact) {
             $nom = '%' . str_replace('*', '%', $nom) . '%';
         }
         if (!$case) {
             $sql .= " AND label LIKE '" . $this->db->escape($nom) . "'";
         } else {
             $sql .= " AND label LIKE BINARY '" . $this->db->escape($nom) . "'";
         }
     }
     if ($id) {
         $sql .= " AND rowid = '" . $id . "'";
     }
     $res = $this->db->query($sql);
     if ($res) {
         while ($rec = $this->db->fetch_array($res)) {
             $cat = new Categorie($this->db);
             $cat->fetch($rec['rowid']);
             $cats[] = $cat;
         }
         return $cats;
     } else {
         $this->error = $this->db->error() . ' sql=' . $sql;
         return -1;
     }
 }
	/**
	 * 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;
	}
Example #12
0
 /**
  * 	Retourne les categories dont l'id ou le nom correspond
  * 	ajoute des wildcards au nom sauf si $exact = true
  *
  * 	@param		int			$id			Id
  * 	@param		string		$nom		Name
  * 	@param		string		$type		Type of category ('member', 'customer', 'supplier', 'product', 'contact'). Old mode (0, 1, 2, ...) is deprecated.
  * 	@param		boolean		$exact		Exact string search (true/false)
  * 	@param		boolean		$case		Case sensitive (true/false)
  * 	@return		array					Array of category id
  */
 function rechercher($id, $nom, $type, $exact = false, $case = false)
 {
     $cats = array();
     $typeid = -1;
     if ($type == 0 || $type == 'product') {
         $typeid = 0;
     } else {
         if ($type == 1 || $type == 'supplier') {
             $typeid = 1;
         } else {
             if ($type == 2 || $type == 'customer') {
                 $typeid = 2;
             } else {
                 if ($type == 3 || $type == 'member') {
                     $typeid = 3;
                 } else {
                     if ($type == 4 || $type == 'contact') {
                         $typeid = 4;
                     }
                 }
             }
         }
     }
     // Generation requete recherche
     $sql = "SELECT rowid FROM " . MAIN_DB_PREFIX . "categorie";
     $sql .= " WHERE type = " . $typeid;
     $sql .= " AND entity IN (" . getEntity('category', 1) . ")";
     if ($nom) {
         if (!$exact) {
             $nom = '%' . str_replace('*', '%', $nom) . '%';
         }
         if (!$case) {
             $sql .= " AND label LIKE '" . $this->db->escape($nom) . "'";
         } else {
             $sql .= " AND label LIKE BINARY '" . $this->db->escape($nom) . "'";
         }
     }
     if ($id) {
         $sql .= " AND rowid = '" . $id . "'";
     }
     $res = $this->db->query($sql);
     if ($res) {
         while ($rec = $this->db->fetch_array($res)) {
             $cat = new Categorie($this->db);
             $cat->fetch($rec['rowid']);
             $cats[] = $cat;
         }
         return $cats;
     } else {
         $this->error = $this->db->error() . ' sql=' . $sql;
         return -1;
     }
 }
Example #13
0
            $elementtype = 'societe';
        }
        if ($type == Categorie::TYPE_MEMBER && $user->rights->adherent->creer) {
            require_once DOL_DOCUMENT_ROOT . '/adherents/class/adherent.class.php';
            $object = new Adherent($db);
            $result = $object->fetch($objectid);
            $elementtype = 'member';
        }
        if ($type == Categorie::TYPE_CONTACT && $user->rights->societe->creer) {
            require_once DOL_DOCUMENT_ROOT . '/contact/class/contact.class.php';
            $object = new Contact($db);
            $result = $object->fetch($objectid);
            $elementtype = 'contact';
        }
        $cat = new Categorie($db);
        $result = $cat->fetch($parent);
        $result = $cat->add_type($object, $elementtype);
        if ($result >= 0) {
            setEventMessages($langs->trans("WasAddedSuccessfully", $cat->label), null, 'mesgs');
        } else {
            if ($cat->error == 'DB_ERROR_RECORD_ALREADY_EXISTS') {
                setEventMessages($langs->trans("ObjectAlreadyLinkedToCategory"), null, 'warnings');
            } else {
                setEventMessages($cat->error, $cat->errors, 'errors');
            }
        }
    }
}
/*
 *	View
 */
Example #14
0
     $result = $object->fetch($objectid);
     $elementtype = 'member';
 }
 if ($_REQUEST["type"] == 4 && $user->rights->lead->creer) {
     require_once DOL_DOCUMENT_ROOT . "/lead/class/lead.class.php";
     $object = new lead($db);
     $result = $object->fetch($objectid);
     $type = 'lead';
 }
 if ($_REQUEST["type"] == 5 && $user->rights->societe->creer) {
     require_once DOL_DOCUMENT_ROOT . "/contact/class/contact.class.php";
     $object = new Contact($db);
     $result = $object->fetch($objectid);
 }
 $cat = new Categorie($db);
 $result = $cat->fetch($catMere);
 $result = $cat->add_type($object, $elementtype);
 if ($result >= 0) {
     $mesg = '<div class="ok">' . $langs->trans("WasAddedSuccessfully", $cat->label) . '</div>';
     if ($_REQUEST["type"] == 2) {
         $actioncomm = new ActionComm($db);
         $actioncomm->addAutoTask('AC_QUALIF', "Qualification prospect/client/contact : " . $cat->label, $_GET["socid"], '', '');
     }
     if ($_REQUEST["type"] == 5) {
         $actioncomm = new ActionComm($db);
         $actioncomm->addAutoTask('AC_QUALIF', "Qualification prospect/client/contact : " . $cat->label, $object->socid, '', '', $object->id);
     }
 } else {
     if ($cat->error == 'DB_ERROR_RECORD_ALREADY_EXISTS') {
         $mesg = '<div class="error">' . $langs->trans("ObjectAlreadyLinkedToCategory") . '</div>';
     } else {
 /**
  *  Return a catergory 
  *  @param 		int		$idCat		Id of Category
  *  @return      array				Category info
  */
 public static function getCategorybyId($idCat)
 {
     global $db;
     $objCat = new Categorie($db);
     $result = $objCat->fetch($idCat);
     if ($result > 0) {
         return $objCat;
     }
     return -1;
 }
Example #16
0
/**
 * Get category infos and children
 *
 * @param	array		$authentication		Array of authentication information
 * @param	int			$id					Id of object
 * @return	mixed
 */
function getCategory($authentication, $id)
{
    global $db, $conf, $langs;
    dol_syslog("Function: getCategory login="******" id=" . $id);
    if ($authentication['entity']) {
        $conf->entity = $authentication['entity'];
    }
    $objectresp = array();
    $errorcode = '';
    $errorlabel = '';
    $error = 0;
    $fuser = check_authentication($authentication, $error, $errorcode, $errorlabel);
    if (!$error && !$id) {
        $error++;
        $errorcode = 'BAD_PARAMETERS';
        $errorlabel = "Parameter id must be provided.";
    }
    if (!$error) {
        $fuser->getrights();
        if ($fuser->rights->categorie->lire) {
            $categorie = new Categorie($db);
            $result = $categorie->fetch($id);
            if ($result > 0) {
                $dir = !empty($conf->categorie->dir_output) ? $conf->categorie->dir_output : $conf->service->dir_output;
                $pdir = get_exdir($categorie->id, 2, 0, 0, $categorie, 'category') . $categorie->id . "/photos/";
                $dir = $dir . '/' . $pdir;
                $cat = array('id' => $categorie->id, 'id_mere' => $categorie->id_mere, 'label' => $categorie->label, 'description' => $categorie->description, 'socid' => $categorie->socid, 'type' => $categorie->type, 'dir' => $pdir, 'photos' => $categorie->liste_photos($dir, $nbmax = 10));
                $cats = $categorie->get_filles();
                if (count($cats) > 0) {
                    foreach ($cats as $fille) {
                        $dir = !empty($conf->categorie->dir_output) ? $conf->categorie->dir_output : $conf->service->dir_output;
                        $pdir = get_exdir($fille->id, 2, 0, 0, $categorie, 'category') . $fille->id . "/photos/";
                        $dir = $dir . '/' . $pdir;
                        $cat['filles'][] = array('id' => $fille->id, 'id_mere' => $categorie->id_mere, 'label' => $fille->label, 'description' => $fille->description, 'socid' => $fille->socid, 'type' => $fille->type, 'dir' => $pdir, 'photos' => $fille->liste_photos($dir, $nbmax = 10));
                    }
                }
                // Create
                $objectresp = array('result' => array('result_code' => 'OK', 'result_label' => ''), 'categorie' => $cat);
            } else {
                $error++;
                $errorcode = 'NOT_FOUND';
                $errorlabel = 'Object not found for id=' . $id;
            }
        } else {
            $error++;
            $errorcode = 'PERMISSION_DENIED';
            $errorlabel = 'User does not have permission for this request';
        }
    }
    if ($error) {
        $objectresp = array('result' => array('result_code' => $errorcode, 'result_label' => $errorlabel));
    }
    return $objectresp;
}
Example #17
0
    dol_print_error('', 'Missing parameter id');
    exit;
}
// Security check
$result = restrictedArea($user, 'categorie', $id, '&category');
$object = new Categorie($db);
/*
 * Actions
 */
// retour a l'affichage des traduction si annulation
if ($cancel == $langs->trans("Cancel")) {
    $action = '';
}
// Validation de l'ajout
if ($action == 'vadd' && $cancel != $langs->trans("Cancel") && $user->rights->categorie->creer) {
    $object->fetch($id);
    $current_lang = $langs->getDefaultLang();
    // update de l'objet
    if ($_POST["forcelangprod"] == $current_lang) {
        $object->label = $_POST["libelle"];
        $object->description = dol_htmlcleanlastbr($_POST["desc"]);
    } else {
        $object->multilangs[$_POST["forcelangprod"]]["label"] = $_POST["libelle"];
        $object->multilangs[$_POST["forcelangprod"]]["description"] = dol_htmlcleanlastbr($_POST["desc"]);
    }
    // sauvegarde en base
    if ($object->setMultiLangs() > 0) {
        $action = '';
    } else {
        $action = 'add';
        setEventMessage($object->error, 'errors');
function _fiche(&$PDOdb, $id)
{
    global $conf, $db, $langs, $user, $form;
    $object = new Categorie($db);
    $result = $object->fetch($id);
    $object->fetch_optionals($id, $extralabels);
    if ($result <= 0) {
        dol_print_error($db, $object->error);
        exit;
    }
    llxHeader("", "", $langs->trans("Categories"));
    $title = $langs->trans("CustomersCategoryShort");
    $head = categories_prepare_head($object, Categorie::TYPE_CUSTOMER);
    dol_fiche_head($head, 'commercial', $title, 0, 'category');
    print '<table class="border" width="100%">';
    print '<tr><td width="20%" class="notopnoleft">';
    $ways = $object->print_all_ways();
    print $langs->trans("Ref") . '</td><td>';
    print '<a href="' . DOL_URL_ROOT . '/categories/index.php?leftmenu=cat&type=' . $type . '">' . $langs->trans("Root") . '</a> >> ';
    foreach ($ways as $way) {
        print $way . "<br>\n";
    }
    print '</td></tr>';
    // Description
    print '<tr><td width="20%" class="notopnoleft">';
    print $langs->trans("Description") . '</td><td>';
    print dol_htmlentitiesbr($object->description);
    print '</td></tr>';
    print '<tr><td>' . $langs->trans("SalesRepresentatives") . '</td>';
    print '<td>';
    $TUser = TCommercialCategory::getUser($PDOdb, $object->id);
    if (!empty($TUser)) {
        foreach ($TUser as &$u) {
            echo $u->getNomUrl(1);
            if ($user->rights->societe->creer) {
                print '<a href="?id=' . $object->id . '&commid=' . $u->id . '&action=delete">';
                print img_delete();
                print '</a>';
            }
            print '<br />';
        }
    }
    print '</td></tr>';
    print '</table>';
    dol_fiche_end();
    if ($user->rights->societe->creer && $user->rights->societe->client->voir) {
        /*
         * Copier... Coller... Jobi... Joba...
         */
        $langs->load("users");
        $title = $langs->trans("ListOfUsers");
        $sql = "SELECT u.rowid, u.lastname, u.firstname, u.login";
        $sql .= " FROM " . MAIN_DB_PREFIX . "user as u LEFT JOIN " . MAIN_DB_PREFIX . "commercial_category cc ON (cc.fk_user = u .rowid AND cc.fk_category=" . $object->id . ")";
        $sql .= " WHERE u.entity IN (0," . $conf->entity . ")";
        if (!empty($conf->global->USER_HIDE_INACTIVE_IN_COMBOBOX)) {
            $sql .= " AND u.statut<>0 ";
        }
        $sql .= " AND cc.rowid IS NULL ";
        $sql .= " ORDER BY u.lastname ASC ";
        //var_dump($sql);
        $resql = $db->query($sql);
        if ($resql) {
            $num = $db->num_rows($resql);
            $i = 0;
            print load_fiche_titre($title);
            // Lignes des titres
            print '<table class="noborder" width="100%">';
            print '<tr class="liste_titre">';
            print '<td>' . $langs->trans("Name") . '</td>';
            print '<td>' . $langs->trans("Login") . '</td>';
            print '<td>&nbsp;</td>';
            print "</tr>\n";
            $var = True;
            while ($i < $num) {
                $obj = $db->fetch_object($resql);
                $var = !$var;
                print "<tr " . $bc[$var] . "><td>";
                print '<a href="' . DOL_URL_ROOT . '/user/card.php?id=' . $obj->rowid . '">';
                print img_object($langs->trans("ShowUser"), "user") . ' ';
                print dolGetFirstLastname($obj->firstname, $obj->lastname) . "\n";
                print '</a>';
                print '</td><td>' . $obj->login . '</td>';
                print '<td><a href="?id=' . $object->id . '&commid=' . $obj->rowid . '&action=add">' . $langs->trans("Add") . '</a></td>';
                print '</tr>' . "\n";
                $i++;
            }
            print "</table>";
            $db->free($resql);
        } else {
            dol_print_error($db);
        }
    }
    llxFooter();
}
/**
 * Get list of products for a category
 *
 * @param	array		$authentication		Array of authentication information
 * @param	array		$id					Category id
 * @param	$lang		$lang				Force lang
 * @return	array							Array result
 */
function getProductsForCategory($authentication, $id, $lang = '')
{
    global $db, $conf, $langs;
    $langcode = $lang ? $lang : (empty($conf->global->MAIN_LANG_DEFAULT) ? 'auto' : $conf->global->MAIN_LANG_DEFAULT);
    $langs->setDefaultLang($langcode);
    dol_syslog("Function: getProductsForCategory login="******" id=" . $id);
    if ($authentication['entity']) {
        $conf->entity = $authentication['entity'];
    }
    $objectresp = array();
    $errorcode = '';
    $errorlabel = '';
    $error = 0;
    $fuser = check_authentication($authentication, $error, $errorcode, $errorlabel);
    if (!$error && !$id) {
        $error++;
        $errorcode = 'BAD_PARAMETERS';
        $errorlabel = "Parameter id must be provided.";
    }
    if (!$error) {
        $langcode = $lang ? $lang : (empty($conf->global->MAIN_LANG_DEFAULT) ? 'auto' : $conf->global->MAIN_LANG_DEFAULT);
        $langs->setDefaultLang($langcode);
        $fuser->getrights();
        if ($fuser->rights->produit->lire) {
            $categorie = new Categorie($db);
            $result = $categorie->fetch($id);
            if ($result > 0) {
                $table = "product";
                $field = "product";
                $sql = "SELECT fk_" . $field . " FROM " . MAIN_DB_PREFIX . "categorie_" . $table;
                $sql .= " WHERE fk_categorie = " . $id;
                $sql .= " ORDER BY fk_" . $field . " ASC";
                dol_syslog("getProductsForCategory get id of product into category", LOG_DEBUG);
                $res = $db->query($sql);
                if ($res) {
                    while ($rec = $db->fetch_array($res)) {
                        $obj = new Product($db);
                        $obj->fetch($rec['fk_' . $field]);
                        $iProduct = 0;
                        if ($obj->status > 0) {
                            $dir = !empty($conf->product->dir_output) ? $conf->product->dir_output : $conf->service->dir_output;
                            $pdir = get_exdir($obj->id, 2) . $obj->id . "/photos/";
                            $dir = $dir . '/' . $pdir;
                            $products[] = array('id' => $obj->id, 'ref' => $obj->ref, 'ref_ext' => $obj->ref_ext, 'label' => !empty($obj->multilangs[$langs->defaultlang]["label"]) ? $obj->multilangs[$langs->defaultlang]["label"] : $obj->label, 'description' => !empty($obj->multilangs[$langs->defaultlang]["description"]) ? $obj->multilangs[$langs->defaultlang]["description"] : $obj->description, 'date_creation' => dol_print_date($obj->date_creation, 'dayhourrfc'), 'date_modification' => dol_print_date($obj->date_modification, 'dayhourrfc'), 'note' => !empty($obj->multilangs[$langs->defaultlang]["note"]) ? $obj->multilangs[$langs->defaultlang]["note"] : $obj->note, 'status_tosell' => $obj->status, 'status_tobuy' => $obj->status_buy, 'type' => $obj->type, 'barcode' => $obj->barcode, 'barcode_type' => $obj->barcode_type, 'country_id' => $obj->country_id > 0 ? $obj->country_id : '', 'country_code' => $obj->country_code, 'custom_code' => $obj->customcode, 'price_net' => $obj->price, 'price' => $obj->price_ttc, 'vat_rate' => $obj->tva_tx, 'price_base_type' => $obj->price_base_type, 'stock_real' => $obj->stock_reel, 'stock_alert' => $obj->seuil_stock_alerte, 'pmp' => $obj->pmp, 'import_key' => $obj->import_key, 'dir' => $pdir, 'images' => $obj->liste_photos($dir, $nbmax = 10));
                            //Retreive all extrafield for thirdsparty
                            // fetch optionals attributes and labels
                            $extrafields = new ExtraFields($db);
                            $extralabels = $extrafields->fetch_name_optionals_label('product', true);
                            //Get extrafield values
                            $product->fetch_optionals($obj->id, $extralabels);
                            foreach ($extrafields->attribute_label as $key => $label) {
                                $products[$iProduct] = array_merge($products[$iProduct], array('options_' . $key => $product->array_options['options_' . $key]));
                            }
                            $iProduct++;
                        }
                    }
                    // Retour
                    $objectresp = array('result' => array('result_code' => 'OK', 'result_label' => ''), 'products' => $products);
                } else {
                    $errorcode = 'NORECORDS_FOR_ASSOCIATION';
                    $errorlabel = 'No products associated' . $sql;
                    $objectresp = array('result' => array('result_code' => $errorcode, 'result_label' => $errorlabel));
                    dol_syslog("getProductsForCategory:: " . $c->error, LOG_DEBUG);
                }
            } else {
                $error++;
                $errorcode = 'NOT_FOUND';
                $errorlabel = 'Object not found for id=' . $id;
            }
        } else {
            $error++;
            $errorcode = 'PERMISSION_DENIED';
            $errorlabel = 'User does not have permission for this request';
        }
    }
    if ($error) {
        $objectresp = array('result' => array('result_code' => $errorcode, 'result_label' => $errorlabel));
    }
    return $objectresp;
}
Example #20
0
// Security check
if (!$user->rights->categorie->lire)
  accessforbidden();

$type=$_REQUEST['type'];


/*
 * Actions
 */

// Action mise a jour d'une categorie
if ($_POST["action"] == 'update' && $user->rights->categorie->creer)
{
	$categorie = new Categorie ($db);
	$result=$categorie->fetch($_REQUEST['id']);

	$categorie->label          = $_POST["nom"];
	$categorie->description    = $_POST["description"];
	$categorie->socid          = ($_POST["socid"] ? $_POST["socid"] : 'null');
	$categorie->visible        = $_POST["visible"];

	if($_POST['catMere'] != "-1")
		$categorie->id_mere = $_POST['catMere'];
	else
		$categorie->id_mere = "";


	if (! $categorie->label)
	{
		$_GET["action"] = 'create';