浏览代码

Work on resource list / navbar into card

Jean-François Ferry 11 年之前
父节点
当前提交
a76fef5f35
共有 3 个文件被更改,包括 196 次插入35 次删除
  1. 8 10
      htdocs/resource/card.php
  2. 143 3
      htdocs/resource/class/resource.class.php
  3. 45 22
      htdocs/resource/list.php

+ 8 - 10
htdocs/resource/card.php

@@ -57,6 +57,7 @@ if( ! $user->rights->resource->read)
 
 $object = new Resource($db);
 
+$hookmanager->initHooks(array('resource_card'));
 
 /*******************************************************************
 * ACTIONS
@@ -172,26 +173,24 @@ if ( $object->fetch($id) > 0 )
 		 */
 		print '<table width="100%" class="border">';
 
-		// Ref
-		print '<tr>';
-		print '<td  width="20%">' . $langs->trans("ResourceName") . '</td>';
-		print '<td   width="30%">';
-		print $object->ref;
+		print '<tr><td style="width:35%">'.$langs->trans("ResourceName").'</td><td>';
+		$linkback = $objet->ref.' <a href="list.php">'.$langs->trans("BackToList").'</a>';
+		print $form->showrefnav($object, 'id', $linkback,1,"rowid");
 		print '</td>';
 		print '</tr>';
 
 		// Resource type
 		print '<tr>';
-		print '<td  width="20%">' . $langs->trans("ResourceType") . '</td>';
-		print '<td   width="30%">';
+		print '<td>' . $langs->trans("ResourceType") . '</td>';
+		print '<td>';
 		print $object->type_label;
 		print '</td>';
 		print '</tr>';
 		
 		// Description
 		print '<tr>';
-		print '<td  width="20%">' . $langs->trans("Description") . '</td>';
-		print '<td   width="30%">';
+		print '<td>' . $langs->trans("Description") . '</td>';
+		print '<td>';
 		print $object->description;
 		print '</td>';
 		print '</tr>';
@@ -205,7 +204,6 @@ if ( $object->fetch($id) > 0 )
 	 * Boutons actions
 	*/
 	print '<div class="tabsAction">';
-	
 	$parameters = array();
 	$reshook = $hookmanager->executeHooks('addMoreActionsButtons', $parameters, $object, $action); // Note that $action and $object may have been
 	// modified by hook

+ 143 - 3
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."<br>";
+    	$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."<br>";
+    	$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;
+    }
 
 
     /**

+ 45 - 22
htdocs/resource/index.php → htdocs/resource/list.php

@@ -1,6 +1,6 @@
 <?php
-/* Module to manage locations, buildings, floors and rooms into Dolibarr ERP/CRM
- * Copyright (C) 2013	Jean-François Ferry	<jfefe@aternatik.fr>
+/* Module to manage resources into Dolibarr ERP/CRM
+ * Copyright (C) 2013-2014	Jean-François Ferry	<jfefe@aternatik.fr>
  *
  * 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 '<table class="noborder" width="100%">'."\n";
 	print '<tr class="liste_titre">';
-	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 '</tr>';
 
@@ -125,18 +124,20 @@ else
 			$style='style="background: orange;"';
 
 		print '<tr '.$bc[$var].' '.$style.'><td>';
-		//print $resource->getNomUrl(1);
-		if(is_object($resource->objresource))
-			print $resource->objresource->getNomUrl(1);
+		print $resource->id;
 		print '</td>';
 
 		print '<td>';
-		if(is_object($resource->objelement))
-			print $resource->objelement->getNomUrl(1);
+		print $resource->ref;
+		print '</td>';
+		
+		print '<td>';
+		print $resource->type_label;
 		print '</td>';
 
 		print '<td>';
-		print '<a href="'.$_SERVER['PHP_SELF'].'?action=delete_resource&element='.$resource->element_type.'&element_id='.$resource->element_id.'&lineid='.$resource->id.'">'.$langs->trans('Delete').'</a>';
+		print '<a href="card.php?id='.$resource->id.'">'.$langs->trans('View').'</a> ';
+		print '<a href="card.php?action=edit&id='.$resource->id.'">'.$langs->trans('Edit').'</a>';
 		print '</td>';
 
 		print '</tr>';
@@ -146,6 +147,28 @@ else
 
 }
 
+/*
+ * Boutons actions
+*/
+print '<div class="tabsAction">';
+$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 '<div class="inline-block divButAction">';
+			print '<a href="add.php" class="butAction">'.$langs->trans('AddResource').'</a>';
+			print '</div>';
+		}
+	}
+}
+print '</div>';
+
 llxFooter();
 
 $db->close();