';
-
$parameters = array();
$reshook = $hookmanager->executeHooks('addMoreActionsButtons', $parameters, $object, $action); // Note that $action and $object may have been
// modified by hook
diff --git a/htdocs/resource/class/resource.class.php b/htdocs/resource/class/resource.class.php
index ee60393323e..8c83ba46142 100644
--- a/htdocs/resource/class/resource.class.php
+++ b/htdocs/resource/class/resource.class.php
@@ -34,11 +34,12 @@ class Resource extends CommonObject
var $db; //!< To store db handler
var $error; //!< To return error code (or message)
var $errors=array(); //!< To return several error codes (or messages)
- //var $element='resource'; //!< Id that identify managed objects
- //var $table_element='llx_resource'; //!< Name of table without prefix where object is stored
+ var $element='resource'; //!< Id that identify managed objects
+ var $table_element='resource'; //!< Name of table without prefix where object is stored
var $id;
+
var $resource_id;
var $resource_type;
var $element_id;
@@ -317,6 +318,78 @@ class Resource extends CommonObject
dol_syslog(get_class($this)."::fetch ".$this->error, LOG_ERR);
return -1;
}
+ }
+
+ /**
+ * Load resource objects into $this->lines
+ *
+ * @param string $sortorder sort order
+ * @param string $sortfield sort field
+ * @param int $limit limit page
+ * @param int $offset page
+ * @param array $filter filter output
+ * @return int <0 if KO, >0 if OK
+ */
+ function fetch_all($sortorder, $sortfield, $limit, $offset, $filter='')
+ {
+ global $conf;
+ $sql="SELECT ";
+ $sql.= " t.rowid,";
+ $sql.= " t.entity,";
+ $sql.= " t.ref,";
+ $sql.= " t.description,";
+ $sql.= " t.fk_code_type_resource,";
+ $sql.= " t.tms,";
+ $sql.= " ty.label as type_label";
+ $sql.= " FROM ".MAIN_DB_PREFIX."resource as t";
+ $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."c_type_resource as ty ON ty.code=t.fk_code_type_resource";
+ //$sql.= " WHERE t.entity IN (".getEntity('resource').")";
+
+ //Manage filter
+ if (!empty($filter)){
+ foreach($filter as $key => $value) {
+ if (strpos($key,'date')) {
+ $sql.= ' AND '.$key.' = \''.$this->db->idate($value).'\'';
+ }
+ else {
+ $sql.= ' AND '.$key.' LIKE \'%'.$value.'%\'';
+ }
+ }
+ }
+ $sql.= " GROUP BY t.rowid";
+ $sql.= " ORDER BY $sortfield $sortorder " . $this->db->plimit($limit+1,$offset);
+ dol_syslog(get_class($this)."::fetch_all sql=".$sql, LOG_DEBUG);
+
+ $resql=$this->db->query($sql);
+ if ($resql)
+ {
+ $num = $this->db->num_rows($resql);
+ if ($num)
+ {
+ $i = 0;
+ while ($i < $num)
+ {
+ $obj = $this->db->fetch_object($resql);
+ $line = new Resource($this->db);
+ $line->id = $obj->rowid;
+ $line->ref = $obj->ref;
+ $line->description = $obj->description;
+ $line->fk_code_type_resource = $obj->fk_code_type_resource;
+ $line->type_label = $obj->type_label;
+
+ $this->lines[$i] = $line;
+ $i++;
+ }
+ $this->db->free($resql);
+ }
+ return $num;
+ }
+ else
+ {
+ $this->error = $this->db->lasterror();
+ return -1;
+ }
+
}
/**
@@ -329,7 +402,7 @@ class Resource extends CommonObject
* @param array $filter filter output
* @return int <0 if KO, >0 if OK
*/
- function fetch_all($sortorder, $sortfield, $limit, $offset, $filter='')
+ function fetch_all_resources($sortorder, $sortfield, $limit, $offset, $filter='')
{
global $conf;
$sql="SELECT ";
@@ -498,6 +571,73 @@ class Resource extends CommonObject
}
return 0;
}
+
+ /**
+ * Load properties id_previous and id_next
+ *
+ * @param string $filter Optional filter
+ * @param int $fieldid Name of field to use for the select MAX and MIN
+ * @return int <0 if KO, >0 if OK
+ */
+ function load_previous_next_ref($filter,$fieldid)
+ {
+ global $conf, $user;
+
+ if (! $this->table_element)
+ {
+ dol_print_error('',get_class($this)."::load_previous_next_ref was called on objet with property table_element not defined", LOG_ERR);
+ return -1;
+ }
+
+ // this->ismultientitymanaged contains
+ // 0=No test on entity, 1=Test with field entity, 2=Test with link by societe
+ $alias = 's';
+
+
+ $sql = "SELECT MAX(te.".$fieldid.")";
+ $sql.= " FROM ".MAIN_DB_PREFIX.$this->table_element." as te";
+ if (isset($this->ismultientitymanaged) && $this->ismultientitymanaged == 2 || ($this->element != 'societe' && empty($this->isnolinkedbythird) && empty($user->rights->societe->client->voir))) $sql.= ", ".MAIN_DB_PREFIX."societe as s"; // If we need to link to societe to limit select to entity
+ if (empty($this->isnolinkedbythird) && !$user->rights->societe->client->voir) $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."societe_commerciaux as sc ON ".$alias.".rowid = sc.fk_soc";
+ $sql.= " WHERE te.".$fieldid." < '".$this->db->escape($this->id)."'";
+ if (empty($this->isnolinkedbythird) && !$user->rights->societe->client->voir) $sql.= " AND sc.fk_user = " .$user->id;
+ if (! empty($filter)) $sql.=" AND ".$filter;
+ if (isset($this->ismultientitymanaged) && $this->ismultientitymanaged == 2 || ($this->element != 'societe' && empty($this->isnolinkedbythird) && !$user->rights->societe->client->voir)) $sql.= ' AND te.fk_soc = s.rowid'; // If we need to link to societe to limit select to entity
+ if (isset($this->ismultientitymanaged) && $this->ismultientitymanaged == 1) $sql.= ' AND te.entity IN ('.getEntity($this->element, 1).')';
+
+ //print $sql."
";
+ $result = $this->db->query($sql);
+ if (! $result)
+ {
+ $this->error=$this->db->error();
+ return -1;
+ }
+ $row = $this->db->fetch_row($result);
+ $this->ref_previous = $row[0];
+
+
+ $sql = "SELECT MIN(te.".$fieldid.")";
+ $sql.= " FROM ".MAIN_DB_PREFIX.$this->table_element." as te";
+ if (isset($this->ismultientitymanaged) && $this->ismultientitymanaged == 2 || ($this->element != 'societe' && empty($this->isnolinkedbythird) && !$user->rights->societe->client->voir)) $sql.= ", ".MAIN_DB_PREFIX."societe as s"; // If we need to link to societe to limit select to entity
+ if (empty($this->isnolinkedbythird) && !$user->rights->societe->client->voir) $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."societe_commerciaux as sc ON ".$alias.".rowid = sc.fk_soc";
+ $sql.= " WHERE te.".$fieldid." > '".$this->db->escape($this->id)."'";
+ if (empty($this->isnolinkedbythird) && !$user->rights->societe->client->voir) $sql.= " AND sc.fk_user = " .$user->id;
+ if (! empty($filter)) $sql.=" AND ".$filter;
+ if (isset($this->ismultientitymanaged) && $this->ismultientitymanaged == 2 || ($this->element != 'societe' && empty($this->isnolinkedbythird) && !$user->rights->societe->client->voir)) $sql.= ' AND te.fk_soc = s.rowid'; // If we need to link to societe to limit select to entity
+ if (isset($this->ismultientitymanaged) && $this->ismultientitymanaged == 1) $sql.= ' AND te.entity IN ('.getEntity($this->element, 1).')';
+ // Rem: Bug in some mysql version: SELECT MIN(rowid) FROM llx_socpeople WHERE rowid > 1 when one row in database with rowid=1, returns 1 instead of null
+
+ //print $sql."
";
+ $result = $this->db->query($sql);
+ if (! $result)
+ {
+ $this->error=$this->db->error();
+ return -2;
+ }
+ $row = $this->db->fetch_row($result);
+ $this->ref_next = $row[0];
+
+ return 1;
+ }
/**
diff --git a/htdocs/resource/index.php b/htdocs/resource/list.php
similarity index 62%
rename from htdocs/resource/index.php
rename to htdocs/resource/list.php
index d0641af5d4a..847b46383e9 100644
--- a/htdocs/resource/index.php
+++ b/htdocs/resource/list.php
@@ -1,6 +1,6 @@
+/* Module to manage resources into Dolibarr ERP/CRM
+ * Copyright (C) 2013-2014 Jean-François Ferry
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -17,9 +17,9 @@
*/
/**
- * \file place/index.php
- * \ingroup place
- * \brief Page to manage place object
+ * \file resource/index.php
+ * \ingroup resource
+ * \brief Page to manage resource objects
*/
@@ -51,13 +51,11 @@ $page = GETPOST('page','int');
$object = new Resource($db);
-$hookmanager->initHooks(array('element_resource'));
+$hookmanager->initHooks(array('resource_list'));
$parameters=array();
$reshook=$hookmanager->executeHooks('doActions',$parameters,$object,$action); // Note that $action and $object may have been modified by some hooks
-
-
if (empty($sortorder)) $sortorder="DESC";
if (empty($sortfield)) $sortfield="t.rowid";
if (empty($arch)) $arch = 0;
@@ -87,13 +85,13 @@ llxHeader('',$pagetitle,'');
$form=new Form($db);
-print_fiche_titre($pagetitle,'','resource_32.png@resource');
+print_fiche_titre($pagetitle,'','resource.png@resource');
- // Confirmation suppression resource line
- if ($action == 'delete_resource')
- {
- print $form->formconfirm($_SERVER['PHP_SELF']."?element=".$element."&element_id=".$element_id."&lineid=".$lineid,$langs->trans("DeleteResource"),$langs->trans("ConfirmDeleteResourceElement"),"confirm_delete_resource",'','',1);
- }
+// Confirmation suppression resource line
+if ($action == 'delete_resource')
+{
+ print $form->formconfirm($_SERVER['PHP_SELF']."?element=".$element."&element_id=".$element_id."&lineid=".$lineid,$langs->trans("DeleteResource"),$langs->trans("ConfirmDeleteResourceElement"),"confirm_delete_resource",'','',1);
+}
// Load object list
$ret = $object->fetch_all($sortorder, $sortfield, $limit, $offset);
@@ -111,8 +109,9 @@ else
print ''."\n";
print '';
- print_liste_field_titre($langs->trans('Resource'),$_SERVER['PHP_SELF'],'t.resource_id','',$param,'',$sortfield,$sortorder);
- print_liste_field_titre($langs->trans('Element'),$_SERVER['PHP_SELF'],'t.element_id','',$param,'',$sortfield,$sortorder);
+ print_liste_field_titre($langs->trans('Id'),$_SERVER['PHP_SELF'],'t.rowid','',$param,'',$sortfield,$sortorder);
+ print_liste_field_titre($langs->trans('Ref'),$_SERVER['PHP_SELF'],'t.ref','',$param,'',$sortfield,$sortorder);
+ print_liste_field_titre($langs->trans('ResourceType'),$_SERVER['PHP_SELF'],'ty.code','',$param,'',$sortfield,$sortorder);
print_liste_field_titre($langs->trans('Edit'));
print '
';
@@ -125,18 +124,20 @@ else
$style='style="background: orange;"';
print '| ';
- //print $resource->getNomUrl(1);
- if(is_object($resource->objresource))
- print $resource->objresource->getNomUrl(1);
+ print $resource->id;
print ' | ';
print '';
- if(is_object($resource->objelement))
- print $resource->objelement->getNomUrl(1);
+ print $resource->ref;
+ print ' | ';
+
+ print '';
+ print $resource->type_label;
print ' | ';
print '';
- print ''.$langs->trans('Delete').'';
+ print ''.$langs->trans('View').' ';
+ print ''.$langs->trans('Edit').'';
print ' | ';
print '
';
@@ -146,6 +147,28 @@ else
}
+/*
+ * Boutons actions
+*/
+print '';
+$parameters = array();
+$reshook = $hookmanager->executeHooks('addMoreActionsButtons', $parameters, $object, $action); // Note that $action and $object may have been
+// modified by hook
+if (empty($reshook))
+{
+ if ($action != "edit" )
+ {
+ // Edit resource
+ if($user->rights->resource->write)
+ {
+ print '
';
+ }
+ }
+}
+print '
';
+
llxFooter();
$db->close();