mirror of
https://github.com/Dolibarr/dolibarr.git
synced 2025-12-05 09:08:09 +01:00
Merge pull request #1053 from FHenry/dev_projecthtmlform
Start normalize project module : create html.formprojet.class.php with … selec_project
This commit is contained in:
@@ -4,6 +4,7 @@
|
||||
* Copyright (C) 2005 Simon TOSSER <simon@kornog-computing.com>
|
||||
* Copyright (C) 2005-2012 Regis Houssin <regis.houssin@capnetworks.com>
|
||||
* Copyright (C) 2010 Juanjo Menent <jmenent@2byte.es>
|
||||
* Copyright (C) 2013 Florian Henry <florian.henry@open-concept.pro>
|
||||
*
|
||||
* 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
|
||||
@@ -27,14 +28,16 @@
|
||||
|
||||
require '../../main.inc.php';
|
||||
require_once DOL_DOCUMENT_ROOT.'/core/lib/agenda.lib.php';
|
||||
require_once DOL_DOCUMENT_ROOT.'/core/lib/project.lib.php';
|
||||
require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
|
||||
require_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php';
|
||||
require_once DOL_DOCUMENT_ROOT.'/user/class/user.class.php';
|
||||
require_once DOL_DOCUMENT_ROOT.'/comm/action/class/cactioncomm.class.php';
|
||||
require_once DOL_DOCUMENT_ROOT.'/comm/action/class/actioncomm.class.php';
|
||||
require_once DOL_DOCUMENT_ROOT.'/core/class/html.formactions.class.php';
|
||||
require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';
|
||||
if (! empty($conf->projet->enabled)) {
|
||||
require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';
|
||||
require_once DOL_DOCUMENT_ROOT.'/core/class/html.formprojet.class.php';
|
||||
}
|
||||
require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php';
|
||||
|
||||
$langs->load("companies");
|
||||
@@ -574,11 +577,15 @@ if ($action == 'create')
|
||||
// Project
|
||||
if (! empty($conf->projet->enabled))
|
||||
{
|
||||
|
||||
$formproject=new FormProjets($db);
|
||||
|
||||
// Projet associe
|
||||
$langs->load("project");
|
||||
|
||||
print '<tr><td valign="top">'.$langs->trans("Project").'</td><td>';
|
||||
$numproject=select_projects((! empty($societe->id)?$societe->id:0),GETPOST("projectid")?GETPOST("projectid"):'','projectid');
|
||||
|
||||
$numproject=$formproject->select_projects((! empty($societe->id)?$societe->id:0),GETPOST("projectid")?GETPOST("projectid"):'','projectid');
|
||||
if ($numproject==0)
|
||||
{
|
||||
print ' <a href="'.DOL_URL_ROOT.'/projet/fiche.php?socid='.$societe->id.'&action=create">'.$langs->trans("AddProject").'</a>';
|
||||
@@ -801,11 +808,14 @@ if ($id > 0)
|
||||
// Project
|
||||
if (! empty($conf->projet->enabled))
|
||||
{
|
||||
|
||||
$formproject=new FormProjets($db);
|
||||
|
||||
// Projet associe
|
||||
$langs->load("project");
|
||||
|
||||
print '<tr><td width="30%" valign="top">'.$langs->trans("Project").'</td><td colspan="3">';
|
||||
$numprojet=select_projects($act->societe->id,$act->fk_project,'projectid');
|
||||
$numprojet=$formproject->select_projects($act->societe->id,$act->fk_project,'projectid');
|
||||
if ($numprojet==0)
|
||||
{
|
||||
print ' <a href="../../projet/fiche.php?socid='.$societe->id.'&action=create">'.$langs->trans("AddProject").'</a>';
|
||||
|
||||
@@ -19,6 +19,10 @@
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
error_reporting(E_ALL);
|
||||
ini_set('display_errors', true);
|
||||
ini_set('html_errors', false);
|
||||
|
||||
/**
|
||||
* \file htdocs/comm/action/index.php
|
||||
* \ingroup agenda
|
||||
@@ -31,7 +35,9 @@ require_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php';
|
||||
require_once DOL_DOCUMENT_ROOT.'/comm/action/class/actioncomm.class.php';
|
||||
require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
|
||||
require_once DOL_DOCUMENT_ROOT.'/core/lib/agenda.lib.php';
|
||||
if (! empty($conf->projet->enabled)) require_once DOL_DOCUMENT_ROOT.'/core/lib/project.lib.php';
|
||||
if (! empty($conf->projet->enabled)) {
|
||||
require_once DOL_DOCUMENT_ROOT.'/core/class/html.formprojet.class.php';
|
||||
}
|
||||
|
||||
if (! isset($conf->global->AGENDA_MAX_EVENTS_DAY_VIEW)) $conf->global->AGENDA_MAX_EVENTS_DAY_VIEW=3;
|
||||
|
||||
|
||||
@@ -29,7 +29,6 @@ require_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php';
|
||||
require_once DOL_DOCUMENT_ROOT.'/comm/action/class/actioncomm.class.php';
|
||||
require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
|
||||
require_once DOL_DOCUMENT_ROOT.'/core/lib/agenda.lib.php';
|
||||
if (! empty($conf->projet->enabled)) require_once DOL_DOCUMENT_ROOT.'/core/lib/project.lib.php';
|
||||
|
||||
$langs->load("companies");
|
||||
$langs->load("agenda");
|
||||
|
||||
@@ -43,7 +43,7 @@ require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php';
|
||||
if (! empty($conf->projet->enabled))
|
||||
{
|
||||
require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';
|
||||
require_once DOL_DOCUMENT_ROOT.'/core/lib/project.lib.php';
|
||||
require_once DOL_DOCUMENT_ROOT.'/core/class/html.formprojet.class.php';
|
||||
}
|
||||
|
||||
$langs->load('companies');
|
||||
@@ -1369,13 +1369,16 @@ if ($action == 'create')
|
||||
// Project
|
||||
if (! empty($conf->projet->enabled) && $socid>0)
|
||||
{
|
||||
|
||||
$formproject=new FormProjets($db);
|
||||
|
||||
$projectid = 0;
|
||||
if ($origin == 'project') $projectid = ($originid?$originid:0);
|
||||
|
||||
print '<tr>';
|
||||
print '<td valign="top">'.$langs->trans("Project").'</td><td colspan="2">';
|
||||
|
||||
$numprojet=select_projects($soc->id,$projectid);
|
||||
$numprojet=$formproject->select_projects($soc->id,$projectid);
|
||||
if ($numprojet==0)
|
||||
{
|
||||
$langs->load("projects");
|
||||
|
||||
@@ -43,7 +43,7 @@ if (! empty($conf->propal->enabled))
|
||||
require DOL_DOCUMENT_ROOT.'/comm/propal/class/propal.class.php';
|
||||
if (! empty($conf->projet->enabled)) {
|
||||
require DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';
|
||||
require DOL_DOCUMENT_ROOT.'/core/lib/project.lib.php';
|
||||
require_once DOL_DOCUMENT_ROOT.'/core/class/html.formprojet.class.php';
|
||||
}
|
||||
require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
|
||||
|
||||
@@ -1626,8 +1626,10 @@ if ($action == 'create' && $user->rights->commande->creer)
|
||||
// Project
|
||||
if (! empty($conf->projet->enabled) && $socid>0)
|
||||
{
|
||||
$formproject=new FormProjets($db);
|
||||
|
||||
print '<tr><td>'.$langs->trans('Project').'</td><td colspan="2">';
|
||||
$numprojet=select_projects($soc->id,$projectid);
|
||||
$numprojet=$formproject->select_projects($soc->id,$projectid);
|
||||
if ($numprojet==0)
|
||||
{
|
||||
print ' <a href="'.DOL_URL_ROOT.'/projet/fiche.php?socid='.$soc->id.'&action=create">'.$langs->trans("AddProject").'</a>';
|
||||
|
||||
@@ -34,7 +34,9 @@ require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
|
||||
require_once DOL_DOCUMENT_ROOT.'/core/class/html.formother.class.php';
|
||||
require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
|
||||
require_once DOL_DOCUMENT_ROOT.'/core/lib/report.lib.php';
|
||||
if (! empty($conf->projet->enabled)) require_once DOL_DOCUMENT_ROOT.'/core/lib/project.lib.php';
|
||||
if (! empty($conf->projet->enabled)) {
|
||||
require_once DOL_DOCUMENT_ROOT.'/core/class/html.formprojet.class.php';
|
||||
}
|
||||
|
||||
$langs->load('orders');
|
||||
$langs->load('deliveries');
|
||||
@@ -425,9 +427,11 @@ if ($action == 'create' && empty($mesgs))
|
||||
// Project
|
||||
if (! empty($conf->projet->enabled))
|
||||
{
|
||||
$formproject=new FormProjets($db);
|
||||
|
||||
$langs->load('projects');
|
||||
print '<tr><td>'.$langs->trans('Project').'</td><td colspan="2">';
|
||||
select_projects($soc->id, $projectid, 'projectid');
|
||||
$formproject->select_projects($soc->id, $projectid, 'projectid');
|
||||
print '</td></tr>';
|
||||
}
|
||||
|
||||
|
||||
@@ -30,7 +30,6 @@ require_once DOL_DOCUMENT_ROOT.'/compta/deplacement/class/deplacement.class.php'
|
||||
require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
|
||||
if (! empty($conf->projet->enabled))
|
||||
{
|
||||
require_once DOL_DOCUMENT_ROOT.'/core/lib/project.lib.php';
|
||||
require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';
|
||||
}
|
||||
|
||||
|
||||
@@ -30,7 +30,9 @@ require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
|
||||
require_once DOL_DOCUMENT_ROOT.'/core/class/html.formcompany.class.php';
|
||||
require_once DOL_DOCUMENT_ROOT.'/compta/dons/class/don.class.php';
|
||||
require_once DOL_DOCUMENT_ROOT.'/compta/paiement/class/paiement.class.php';
|
||||
if (! empty($conf->projet->enabled)) require_once DOL_DOCUMENT_ROOT.'/core/lib/project.lib.php';
|
||||
if (! empty($conf->projet->enabled)) {
|
||||
require_once DOL_DOCUMENT_ROOT.'/core/class/html.formprojet.class.php';
|
||||
}
|
||||
|
||||
$langs->load("companies");
|
||||
$langs->load("donations");
|
||||
@@ -317,9 +319,12 @@ if ($action == 'create')
|
||||
|
||||
if (! empty($conf->projet->enabled))
|
||||
{
|
||||
|
||||
$formproject=new FormProjets($db);
|
||||
|
||||
// Si module projet actif
|
||||
print "<tr><td>".$langs->trans("Project")."</td><td>";
|
||||
select_projects('',$_POST["projectid"],"projectid");
|
||||
$formproject->select_projects('',$_POST["projectid"],"projectid");
|
||||
print "</td></tr>\n";
|
||||
}
|
||||
|
||||
@@ -414,9 +419,11 @@ if (! empty($id) && $action == 'edit')
|
||||
// Project
|
||||
if (! empty($conf->projet->enabled))
|
||||
{
|
||||
$formproject=new FormProjets($db);
|
||||
|
||||
$langs->load('projects');
|
||||
print '<tr><td>'.$langs->trans('Project').'</td><td>';
|
||||
select_projects(-1, (isset($_POST["projectid"])?$_POST["projectid"]:$don->fk_project), 'projectid');
|
||||
$formproject->select_projects(-1, (isset($_POST["projectid"])?$_POST["projectid"]:$don->fk_project), 'projectid');
|
||||
print '</td></tr>';
|
||||
}
|
||||
|
||||
|
||||
@@ -42,8 +42,10 @@ require_once DOL_DOCUMENT_ROOT . '/core/lib/functions2.lib.php';
|
||||
require_once DOL_DOCUMENT_ROOT . '/core/lib/date.lib.php';
|
||||
require_once DOL_DOCUMENT_ROOT . '/core/class/extrafields.class.php';
|
||||
if (! empty($conf->commande->enabled)) require_once DOL_DOCUMENT_ROOT . '/commande/class/commande.class.php';
|
||||
if (! empty($conf->projet->enabled)) require_once DOL_DOCUMENT_ROOT . '/projet/class/project.class.php';
|
||||
if (! empty($conf->projet->enabled)) require_once DOL_DOCUMENT_ROOT . '/core/lib/project.lib.php';
|
||||
if (! empty($conf->projet->enabled)) {
|
||||
require_once DOL_DOCUMENT_ROOT . '/projet/class/project.class.php';
|
||||
require_once DOL_DOCUMENT_ROOT.'/core/class/html.formprojet.class.php';
|
||||
}
|
||||
require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
|
||||
|
||||
$langs->load('bills');
|
||||
@@ -2266,9 +2268,11 @@ if ($action == 'create')
|
||||
// Project
|
||||
if (! empty($conf->projet->enabled) && $socid>0)
|
||||
{
|
||||
$formproject=new FormProjets($db);
|
||||
|
||||
$langs->load('projects');
|
||||
print '<tr><td>'.$langs->trans('Project').'</td><td colspan="2">';
|
||||
select_projects($soc->id, $projectid, 'projectid');
|
||||
$formproject->select_projects($soc->id, $projectid, 'projectid');
|
||||
print '</td></tr>';
|
||||
}
|
||||
|
||||
|
||||
@@ -43,7 +43,6 @@ if (! empty($conf->commande->enabled)) require_once DOL_DOCUMENT_ROOT.'/commande
|
||||
if (! empty($conf->projet->enabled))
|
||||
{
|
||||
require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';
|
||||
require_once DOL_DOCUMENT_ROOT.'/core/lib/project.lib.php';
|
||||
}
|
||||
|
||||
$langs->load('bills');
|
||||
|
||||
@@ -38,7 +38,7 @@ if (! empty($conf->produit->enabled) || ! empty($conf->service->enabled)) requi
|
||||
if (! empty($conf->propal->enabled)) require_once DOL_DOCUMENT_ROOT.'/comm/propal/class/propal.class.php';
|
||||
if (! empty($conf->projet->enabled)) {
|
||||
require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';
|
||||
require_once DOL_DOCUMENT_ROOT.'/core/lib/project.lib.php';
|
||||
require_once DOL_DOCUMENT_ROOT.'/core/class/html.formprojet.class.php';
|
||||
}
|
||||
|
||||
$langs->load("contracts");
|
||||
@@ -864,8 +864,10 @@ if ($action == 'create')
|
||||
|
||||
if (! empty($conf->projet->enabled))
|
||||
{
|
||||
$formproject=new FormProjets($db);
|
||||
|
||||
print '<tr><td>'.$langs->trans("Project").'</td><td>';
|
||||
select_projects($soc->id,$projectid,"projectid");
|
||||
$formproject->select_projects($soc->id,$projectid,"projectid");
|
||||
print "</td></tr>";
|
||||
}
|
||||
|
||||
|
||||
@@ -2695,6 +2695,9 @@ class Form
|
||||
global $langs;
|
||||
|
||||
require_once DOL_DOCUMENT_ROOT.'/core/lib/project.lib.php';
|
||||
require_once DOL_DOCUMENT_ROOT.'/core/class/html.formprojet.class.php';
|
||||
|
||||
$formproject=new FormProjets($this->db);
|
||||
|
||||
$langs->load("project");
|
||||
if ($htmlname != "none")
|
||||
@@ -2705,7 +2708,7 @@ class Form
|
||||
print '<table class="nobordernopadding" cellpadding="0" cellspacing="0">';
|
||||
print '<tr><td>';
|
||||
//print "$socid,$selected,$htmlname";
|
||||
select_projects($socid,$selected,$htmlname);
|
||||
$formproject->select_projects($socid,$selected,$htmlname);
|
||||
print '</td>';
|
||||
print '<td align="left"><input type="submit" class="button" value="'.$langs->trans("Modify").'"></td>';
|
||||
print '</tr></table></form>';
|
||||
|
||||
160
htdocs/core/class/html.formprojet.class.php
Normal file
160
htdocs/core/class/html.formprojet.class.php
Normal file
@@ -0,0 +1,160 @@
|
||||
<?php
|
||||
/* Copyright (c) 2013 Florian Henry <florian.henry@open-concept.pro>
|
||||
*
|
||||
* 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
|
||||
* the Free Software Foundation; either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
/**
|
||||
* \file htdocs/core/class/html.formprojet.class.php
|
||||
* \ingroup core
|
||||
* \brief Class file for html component project
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* Class to manage building of HTML components
|
||||
*/
|
||||
class FormProjets
|
||||
{
|
||||
var $db;
|
||||
var $error;
|
||||
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param DoliDB $db Database handler
|
||||
*/
|
||||
function __construct($db)
|
||||
{
|
||||
$this->db = $db;
|
||||
return 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Show a combo list with projects qualified for a third party
|
||||
*
|
||||
* @param int $socid Id third party (-1=all, 0=only projects not linked to a third party, id=projects not linked or linked to third party id)
|
||||
* @param int $selected Id project preselected
|
||||
* @param string $htmlname Nom de la zone html
|
||||
* @param int $maxlength Maximum length of label
|
||||
* @return int Nbre of project if OK, <0 if KO
|
||||
*/
|
||||
function select_projects($socid=-1, $selected='', $htmlname='projectid', $maxlength=16, $option_only=0, $show_empty=1)
|
||||
{
|
||||
global $user,$conf,$langs;
|
||||
|
||||
require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';
|
||||
|
||||
$out='';
|
||||
|
||||
$hideunselectables = false;
|
||||
if (! empty($conf->global->PROJECT_HIDE_UNSELECTABLES)) $hideunselectables = true;
|
||||
|
||||
$projectsListId = false;
|
||||
if (empty($user->rights->projet->all->lire))
|
||||
{
|
||||
$projectstatic=new Project($this->db);
|
||||
$projectsListId = $projectstatic->getProjectsAuthorizedForUser($user,0,1);
|
||||
}
|
||||
|
||||
// Search all projects
|
||||
$sql = 'SELECT p.rowid, p.ref, p.title, p.fk_soc, p.fk_statut, p.public';
|
||||
$sql.= ' FROM '.MAIN_DB_PREFIX .'projet as p';
|
||||
$sql.= " WHERE p.entity = ".$conf->entity;
|
||||
if ($projectsListId !== false) $sql.= " AND p.rowid IN (".$projectsListId.")";
|
||||
if ($socid == 0) $sql.= " AND (p.fk_soc=0 OR p.fk_soc IS NULL)";
|
||||
$sql.= " ORDER BY p.title ASC";
|
||||
|
||||
dol_syslog(get_class($this)."::select_projects sql=".$sql,LOG_DEBUG);
|
||||
$resql=$this->db->query($sql);
|
||||
if ($resql)
|
||||
{
|
||||
if (empty($option_only)) {
|
||||
$out.= '<select class="flat" name="'.$htmlname.'">';
|
||||
}
|
||||
if (!empty($show_empty)) {
|
||||
$out.= '<option value="0"> </option>';
|
||||
}
|
||||
$num = $this->db->num_rows($resql);
|
||||
$i = 0;
|
||||
if ($num)
|
||||
{
|
||||
while ($i < $num)
|
||||
{
|
||||
$obj = $this->db->fetch_object($resql);
|
||||
// If we ask to filter on a company and user has no permission to see all companies and project is linked to another company, we hide project.
|
||||
if ($socid > 0 && (empty($obj->fk_soc) || $obj->fk_soc == $socid) && ! $user->rights->societe->lire)
|
||||
{
|
||||
// Do nothing
|
||||
}
|
||||
else
|
||||
{
|
||||
$labeltoshow=dol_trunc($obj->ref,18);
|
||||
//if ($obj->public) $labeltoshow.=' ('.$langs->trans("SharedProject").')';
|
||||
//else $labeltoshow.=' ('.$langs->trans("Private").')';
|
||||
if (!empty($selected) && $selected == $obj->rowid && $obj->fk_statut > 0)
|
||||
{
|
||||
$out.= '<option value="'.$obj->rowid.'" selected="selected">'.$labeltoshow.' - '.dol_trunc($obj->title,$maxlength).'</option>';
|
||||
}
|
||||
else
|
||||
{
|
||||
$disabled=0;
|
||||
if (! $obj->fk_statut > 0)
|
||||
{
|
||||
$disabled=1;
|
||||
$labeltoshow.=' - '.$langs->trans("Draft");
|
||||
}
|
||||
if ($socid > 0 && (! empty($obj->fk_soc) && $obj->fk_soc != $socid))
|
||||
{
|
||||
$disabled=1;
|
||||
$labeltoshow.=' - '.$langs->trans("LinkedToAnotherCompany");
|
||||
}
|
||||
|
||||
if ($hideunselectables && $disabled)
|
||||
{
|
||||
$resultat='';
|
||||
}
|
||||
else
|
||||
{
|
||||
$resultat='<option value="'.$obj->rowid.'"';
|
||||
if ($disabled) $resultat.=' disabled="disabled"';
|
||||
//if ($obj->public) $labeltoshow.=' ('.$langs->trans("Public").')';
|
||||
//else $labeltoshow.=' ('.$langs->trans("Private").')';
|
||||
$resultat.='>'.$labeltoshow;
|
||||
if (! $disabled) $resultat.=' - '.dol_trunc($obj->title,$maxlength);
|
||||
$resultat.='</option>';
|
||||
}
|
||||
$out.= $resultat;
|
||||
}
|
||||
}
|
||||
$i++;
|
||||
}
|
||||
}
|
||||
if (empty($option_only)) {
|
||||
$out.= '</select>';
|
||||
}
|
||||
print $out;
|
||||
|
||||
$this->db->free($resql);
|
||||
return $num;
|
||||
}
|
||||
else
|
||||
{
|
||||
dol_print_error($this->db);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -102,11 +102,14 @@ function print_actions_filter($form,$canedit,$status,$year,$month,$day,$showbirt
|
||||
|
||||
if (! empty($conf->projet->enabled) && $user->rights->projet->lire)
|
||||
{
|
||||
require_once DOL_DOCUMENT_ROOT.'/core/class/html.formprojet.class.php';
|
||||
$formproject=new FormProjets($db);
|
||||
|
||||
print '<tr>';
|
||||
print '<td class="nowrap">';
|
||||
print $langs->trans("Project").' ';
|
||||
print '</td><td class="nowrap">';
|
||||
select_projects($socid?$socid:-1, $pid, 'projectid', 64);
|
||||
$formproject->select_projects($socid?$socid:-1, $pid, 'projectid', 64);
|
||||
print '</td></tr>';
|
||||
}
|
||||
|
||||
|
||||
@@ -190,111 +190,6 @@ function project_admin_prepare_head()
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Show a combo list with projects qualified for a third party
|
||||
*
|
||||
* @param int $socid Id third party (-1=all, 0=only projects not linked to a third party, id=projects not linked or linked to third party id)
|
||||
* @param int $selected Id project preselected
|
||||
* @param string $htmlname Nom de la zone html
|
||||
* @param int $maxlength Maximum length of label
|
||||
* @return int Nbre of project if OK, <0 if KO
|
||||
*/
|
||||
function select_projects($socid=-1, $selected='', $htmlname='projectid', $maxlength=16)
|
||||
{
|
||||
global $db,$user,$conf,$langs;
|
||||
|
||||
$hideunselectables = false;
|
||||
if (! empty($conf->global->PROJECT_HIDE_UNSELECTABLES)) $hideunselectables = true;
|
||||
|
||||
$projectsListId = false;
|
||||
if (empty($user->rights->projet->all->lire))
|
||||
{
|
||||
$projectstatic=new Project($db);
|
||||
$projectsListId = $projectstatic->getProjectsAuthorizedForUser($user,0,1);
|
||||
}
|
||||
|
||||
// Search all projects
|
||||
$sql = 'SELECT p.rowid, p.ref, p.title, p.fk_soc, p.fk_statut, p.public';
|
||||
$sql.= ' FROM '.MAIN_DB_PREFIX .'projet as p';
|
||||
$sql.= " WHERE p.entity = ".$conf->entity;
|
||||
if ($projectsListId !== false) $sql.= " AND p.rowid IN (".$projectsListId.")";
|
||||
if ($socid == 0) $sql.= " AND (p.fk_soc=0 OR p.fk_soc IS NULL)";
|
||||
$sql.= " ORDER BY p.title ASC";
|
||||
|
||||
dol_syslog("project.lib::select_projects sql=".$sql);
|
||||
$resql=$db->query($sql);
|
||||
if ($resql)
|
||||
{
|
||||
print '<select class="flat" name="'.$htmlname.'">';
|
||||
print '<option value="0"> </option>';
|
||||
$num = $db->num_rows($resql);
|
||||
$i = 0;
|
||||
if ($num)
|
||||
{
|
||||
while ($i < $num)
|
||||
{
|
||||
$obj = $db->fetch_object($resql);
|
||||
// If we ask to filter on a company and user has no permission to see all companies and project is linked to another company, we hide project.
|
||||
if ($socid > 0 && (empty($obj->fk_soc) || $obj->fk_soc == $socid) && ! $user->rights->societe->lire)
|
||||
{
|
||||
// Do nothing
|
||||
}
|
||||
else
|
||||
{
|
||||
$labeltoshow=dol_trunc($obj->ref,18);
|
||||
//if ($obj->public) $labeltoshow.=' ('.$langs->trans("SharedProject").')';
|
||||
//else $labeltoshow.=' ('.$langs->trans("Private").')';
|
||||
if (!empty($selected) && $selected == $obj->rowid && $obj->fk_statut > 0)
|
||||
{
|
||||
print '<option value="'.$obj->rowid.'" selected="selected">'.$labeltoshow.' - '.dol_trunc($obj->title,$maxlength).'</option>';
|
||||
}
|
||||
else
|
||||
{
|
||||
$disabled=0;
|
||||
if (! $obj->fk_statut > 0)
|
||||
{
|
||||
$disabled=1;
|
||||
$labeltoshow.=' - '.$langs->trans("Draft");
|
||||
}
|
||||
if ($socid > 0 && (! empty($obj->fk_soc) && $obj->fk_soc != $socid))
|
||||
{
|
||||
$disabled=1;
|
||||
$labeltoshow.=' - '.$langs->trans("LinkedToAnotherCompany");
|
||||
}
|
||||
|
||||
if ($hideunselectables && $disabled)
|
||||
{
|
||||
$resultat='';
|
||||
}
|
||||
else
|
||||
{
|
||||
$resultat='<option value="'.$obj->rowid.'"';
|
||||
if ($disabled) $resultat.=' disabled="disabled"';
|
||||
//if ($obj->public) $labeltoshow.=' ('.$langs->trans("Public").')';
|
||||
//else $labeltoshow.=' ('.$langs->trans("Private").')';
|
||||
$resultat.='>'.$labeltoshow;
|
||||
if (! $disabled) $resultat.=' - '.dol_trunc($obj->title,$maxlength);
|
||||
$resultat.='</option>';
|
||||
}
|
||||
print $resultat;
|
||||
}
|
||||
}
|
||||
$i++;
|
||||
}
|
||||
}
|
||||
print '</select>';
|
||||
$db->free($resql);
|
||||
return $num;
|
||||
}
|
||||
else
|
||||
{
|
||||
dol_print_error($db);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Show task lines with a particular parent
|
||||
*
|
||||
@@ -653,64 +548,6 @@ function searchTaskInChild(&$inc, $parent, &$lines, &$taskrole)
|
||||
return $inc;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Clean task not linked to a parent
|
||||
*
|
||||
* @param DoliDB $db Database handler
|
||||
* @return int Nb of records deleted
|
||||
*/
|
||||
function clean_orphelins($db)
|
||||
{
|
||||
$nb=0;
|
||||
|
||||
// There is orphelins. We clean that
|
||||
$listofid=array();
|
||||
|
||||
// Get list of id in array listofid
|
||||
$sql='SELECT rowid FROM '.MAIN_DB_PREFIX.'projet_task';
|
||||
$resql = $db->query($sql);
|
||||
if ($resql)
|
||||
{
|
||||
$num = $db->num_rows($resql);
|
||||
$i = 0;
|
||||
while ($i < $num && $i < 100)
|
||||
{
|
||||
$obj = $db->fetch_object($resql);
|
||||
$listofid[]=$obj->rowid;
|
||||
$i++;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
dol_print_error($db);
|
||||
}
|
||||
|
||||
if (count($listofid))
|
||||
{
|
||||
// Removed orphelins records
|
||||
print 'Some orphelins were found and restored to be parents so records are visible again: ';
|
||||
print join(',',$listofid);
|
||||
|
||||
$sql = "UPDATE ".MAIN_DB_PREFIX."projet_task";
|
||||
$sql.= " SET fk_task_parent = 0";
|
||||
$sql.= " WHERE fk_task_parent NOT IN (".join(',',$listofid).")";
|
||||
|
||||
$resql = $db->query($sql);
|
||||
if ($resql)
|
||||
{
|
||||
$nb=$db->affected_rows($sql);
|
||||
|
||||
return $nb;
|
||||
}
|
||||
else
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Return HTML table with list of projects and number of opened tasks
|
||||
*
|
||||
|
||||
@@ -34,8 +34,8 @@ require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
|
||||
|
||||
if (! empty($conf->projet->enabled))
|
||||
{
|
||||
require_once DOL_DOCUMENT_ROOT.'/core/lib/project.lib.php';
|
||||
require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';
|
||||
require_once DOL_DOCUMENT_ROOT.'/core/class/html.formprojet.class.php';
|
||||
}
|
||||
|
||||
if ($conf->contrat->enabled)
|
||||
@@ -1006,6 +1006,8 @@ if ($action == 'create')
|
||||
// Project
|
||||
if (! empty($conf->projet->enabled))
|
||||
{
|
||||
$formproject=new FormProjets($db);
|
||||
|
||||
$langs->load("project");
|
||||
|
||||
print '<tr><td valign="top">'.$langs->trans("Project").'</td><td>';
|
||||
@@ -1015,7 +1017,7 @@ if ($action == 'create')
|
||||
else
|
||||
$numprojet=select_projects($societe->id,$_POST["projectid"],'projectid');
|
||||
*/
|
||||
$numprojet=select_projects($soc->id,GETPOST('projectid','int'),'projectid');
|
||||
$numprojet=$formproject->select_projects($soc->id,GETPOST('projectid','int'),'projectid');
|
||||
if ($numprojet==0)
|
||||
{
|
||||
print ' <a href="'.DOL_DOCUMENT_ROOT.'/projet/fiche.php?socid='.$soc->id.'&action=create">'.$langs->trans("AddProject").'</a>';
|
||||
|
||||
@@ -39,10 +39,10 @@ require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
|
||||
require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
|
||||
if (!empty($conf->produit->enabled))
|
||||
require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php';
|
||||
if (!empty($conf->projet->enabled))
|
||||
if (!empty($conf->projet->enabled)) {
|
||||
require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';
|
||||
if (! empty($conf->projet->enabled))
|
||||
require_once DOL_DOCUMENT_ROOT.'/core/lib/project.lib.php';
|
||||
require_once DOL_DOCUMENT_ROOT.'/core/class/html.formprojet.class.php';
|
||||
}
|
||||
|
||||
|
||||
$langs->load('bills');
|
||||
@@ -1172,9 +1172,11 @@ if ($action == 'create')
|
||||
// Project
|
||||
if (! empty($conf->projet->enabled))
|
||||
{
|
||||
$formproject=new FormProjets($db);
|
||||
|
||||
$langs->load('projects');
|
||||
print '<tr><td>'.$langs->trans('Project').'</td><td colspan="2">';
|
||||
select_projects(-1, $projectid, 'projectid');
|
||||
$formproject->select_projects(-1, $projectid, 'projectid');
|
||||
print '</td></tr>';
|
||||
}
|
||||
|
||||
|
||||
@@ -1278,6 +1278,63 @@ class Project extends CommonObject
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Clean task not linked to a parent
|
||||
*
|
||||
* @param DoliDB $db Database handler
|
||||
* @return int Nb of records deleted
|
||||
*/
|
||||
function clean_orphelins()
|
||||
{
|
||||
$nb=0;
|
||||
|
||||
// There is orphelins. We clean that
|
||||
$listofid=array();
|
||||
|
||||
// Get list of id in array listofid
|
||||
$sql='SELECT rowid FROM '.MAIN_DB_PREFIX.'projet_task';
|
||||
$resql = $this->db->query($sql);
|
||||
if ($resql)
|
||||
{
|
||||
$num = $this->db->num_rows($resql);
|
||||
$i = 0;
|
||||
while ($i < $num && $i < 100)
|
||||
{
|
||||
$obj = $this->db->fetch_object($resql);
|
||||
$listofid[]=$obj->rowid;
|
||||
$i++;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
dol_print_error($this->db);
|
||||
}
|
||||
|
||||
if (count($listofid))
|
||||
{
|
||||
// Removed orphelins records
|
||||
print 'Some orphelins were found and restored to be parents so records are visible again: ';
|
||||
print join(',',$listofid);
|
||||
|
||||
$sql = "UPDATE ".MAIN_DB_PREFIX."projet_task";
|
||||
$sql.= " SET fk_task_parent = 0";
|
||||
$sql.= " WHERE fk_task_parent NOT IN (".join(',',$listofid).")";
|
||||
|
||||
$resql = $this->db->query($sql);
|
||||
if ($resql)
|
||||
{
|
||||
$nb=$this->db->affected_rows($sql);
|
||||
|
||||
return $nb;
|
||||
}
|
||||
else
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Build Select List of element associable to a project
|
||||
*
|
||||
|
||||
@@ -420,11 +420,11 @@ else
|
||||
//print 'mode='.$_REQUEST["mode"].' $nboftaskshown='.$nboftaskshown.' count($tasksarray)='.count($tasksarray).' count($tasksrole)='.count($tasksrole).'<br>';
|
||||
if ($mode=='mine')
|
||||
{
|
||||
if ($nboftaskshown < count($tasksrole)) clean_orphelins($db);
|
||||
if ($nboftaskshown < count($tasksrole)) $object->clean_orphelins();
|
||||
}
|
||||
else
|
||||
{
|
||||
if ($nboftaskshown < count($tasksarray)) clean_orphelins($db);
|
||||
if ($nboftaskshown < count($tasksarray)) $object->clean_orphelins();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user