* Copyright (C) 2004-2012 Laurent Destailleur * Copyright (C) 2005-2012 Regis Houssin * * 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 2 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 . */ /** * \file htdocs/projet/fiche.php * \ingroup projet * \brief Project card */ require("../main.inc.php"); require_once(DOL_DOCUMENT_ROOT."/projet/class/project.class.php"); require_once(DOL_DOCUMENT_ROOT."/projet/class/task.class.php"); require_once(DOL_DOCUMENT_ROOT."/core/lib/project.lib.php"); require_once(DOL_DOCUMENT_ROOT."/core/class/html.formfile.class.php"); require_once(DOL_DOCUMENT_ROOT."/core/modules/project/modules_project.php"); $langs->load("projects"); $langs->load('companies'); $id=GETPOST('id','int'); $ref = GETPOST('ref','alpha'); $action=GETPOST('action','alpha'); $backtopage=GETPOST('backtopage','alpha'); if ($id == '' && $ref == '' && ($action != "create" && $action != "add" && $action != "update" && ! $_POST["cancel"])) accessforbidden(); $mine = GETPOST('mode')=='mine' ? 1 : 0; //if (! $user->rights->projet->all->lire) $mine=1; // Special for projects $object = new Project($db); if ($ref) { $object->fetch(0,$ref); $id=$object->id; } // Security check $socid=0; if ($user->societe_id > 0) $socid=$user->societe_id; $result = restrictedArea($user, 'projet', $id); /* * Actions */ // Cancel if (GETPOST("cancel") && ! empty($backtopage)) { header("Location: ".$backtopage); exit; } if ($action == 'add' && $user->rights->projet->creer) { $error=0; if (empty($_POST["ref"])) { $mesg='
'.$langs->trans("ErrorFieldRequired",$langs->transnoentities("Ref")).'
'; $error++; } if (empty($_POST["title"])) { $mesg='
'.$langs->trans("ErrorFieldRequired",$langs->transnoentities("Label")).'
'; $error++; } if (! $error) { $error=0; $db->begin(); $object->ref = GETPOST('ref','alpha'); $object->title = GETPOST('title','alpha'); $object->socid = GETPOST('socid','int'); $object->description = GETPOST('description','alpha'); $object->public = GETPOST('public','alpha'); $object->datec=dol_now(); $object->date_start=dol_mktime(0,0,0,GETPOST('projectmonth','int'),GETPOST('projectday','int'),GETPOST('projectyear','int')); $object->date_end=dol_mktime(0,0,0,GETPOST('projectendmonth','int'),GETPOST('projectendday','int'),GETPOST('projectendyear','int')); $result = $object->create($user); if ($result > 0) { // Add myself as project leader $result = $object->add_contact($user->id, 'PROJECTLEADER', 'internal'); if ($result < 0) { $langs->load("errors"); $mesg='
'.$langs->trans($object->error).'
'; $error++; } } else { $langs->load("errors"); $mesg='
'.$langs->trans($object->error).'
'; $error++; } if (! $error) { $db->commit(); Header("Location:fiche.php?id=".$object->id); exit; } else { $db->rollback(); $action = 'create'; } } else { $action = 'create'; } } if ($action == 'update' && ! $_POST["cancel"] && $user->rights->projet->creer) { $error=0; if (empty($ref)) { $error++; //$_GET["id"]=$_POST["id"]; // On retourne sur la fiche projet $mesg='
'.$langs->trans("ErrorFieldRequired",$langs->transnoentities("Ref")).'
'; } if (empty($_POST["title"])) { $error++; //$_GET["id"]=$_POST["id"]; // On retourne sur la fiche projet $mesg='
'.$langs->trans("ErrorFieldRequired",$langs->transnoentities("Label")).'
'; } if (! $error) { $object->fetch($id); $old_start_date = $object->date_start; $object->ref = GETPOST('ref','alpha'); $object->title = GETPOST('title','alpha'); $object->socid = GETPOST('socid','int'); $object->description = GETPOST('description','alpha'); $object->public = GETPOST('public','alpha'); $object->date_start = empty($_POST["project"])?'':dol_mktime(0,0,0,GETPOST('projectmonth'),GETPOST('projectday'),GETPOST('projectyear')); $object->date_end = empty($_POST["projectend"])?'':dol_mktime(0,0,0,GETPOST('projectendmonth'),GETPOST('projectendday'),GETPOST('projectendyear')); $result=$object->update($user); $id=$project->id; // On retourne sur la fiche projet } else { $action='edit'; } } // Build doc if ($action == 'builddoc' && $user->rights->projet->creer) { $object->fetch($id); if (GETPOST('model')) { $object->setDocModel($user, GETPOST('model')); } $outputlangs = $langs; if (GETPOST('lang_id')) { $outputlangs = new Translate("",$conf); $outputlangs->setDefaultLang(GETPOST('lang_id')); } $result=project_pdf_create($db, $object, $object->modelpdf, $outputlangs); if ($result <= 0) { dol_print_error($db,$result); exit; } else { Header('Location: '.$_SERVER["PHP_SELF"].'?id='.$object->id.(empty($conf->global->MAIN_JUMP_TAG)?'':'#builddoc')); exit; } } // Delete file in doc form if ($action == 'remove_file' && $user->rights->projet->creer) { require_once(DOL_DOCUMENT_ROOT."/core/lib/files.lib.php"); if ($object->fetch($id)) { $langs->load("other"); $upload_dir = $conf->projet->dir_output . "/"; $file = $upload_dir . '/' . GETPOST('file'); dol_delete_file($file); $mesg = '
'.$langs->trans("FileWasRemoved",GETPOST('file')).'
'; } } if ($action == 'confirm_validate' && GETPOST('confirm') == 'yes') { $object->fetch($id); $result = $object->setValid($user); if ($result <= 0) { $mesg='
'.$object->error.'
'; } } if ($action == 'confirm_close' && GETPOST('confirm') == 'yes') { $object->fetch($id); $result = $object->setClose($user); if ($result <= 0) { $mesg='
'.$object->error.'
'; } } if ($action == 'confirm_reopen' && GETPOST('confirm') == 'yes') { $object->fetch($id); $result = $object->setValid($user); if ($result <= 0) { $mesg='
'.$object->error.'
'; } } if ($action == 'confirm_delete' && GETPOST("confirm") == "yes" && $user->rights->projet->supprimer) { $object->fetch($id); $result=$object->delete($user); if ($result > 0) { Header("Location: index.php"); exit; } else { dol_syslog($object->error,LOG_DEBUG); $mesg='
'.$langs->trans("CantRemoveProject").'
'; } } /* * View */ $form = new Form($db); $formfile = new FormFile($db); $userstatic = new User($db); $help_url="EN:Module_Projects|FR:Module_Projets|ES:Módulo_Proyectos"; llxHeader("",$langs->trans("Projects"),$help_url); if ($action == 'create' && $user->rights->projet->creer) { /* * Create */ print_fiche_titre($langs->trans("NewProject")); dol_htmloutput_mesg($mesg); print '
'; print ''; print ''; print ''; print ''; $defaultref=''; $obj = empty($conf->global->PROJECT_ADDON)?'mod_project_simple':$conf->global->PROJECT_ADDON; if (! empty($conf->global->PROJECT_ADDON) && is_readable(DOL_DOCUMENT_ROOT ."/core/modules/project/".$conf->global->PROJECT_ADDON.".php")) { require_once(DOL_DOCUMENT_ROOT ."/core/modules/project/".$conf->global->PROJECT_ADDON.".php"); $modProject = new $obj; $defaultref = $modProject->getNextValue($soc,$object); } if (is_numeric($defaultref) && $defaultref <= 0) $defaultref=''; // Ref print ''; // Label print ''; // Customer print ''; // Public print ''; // Date start print ''; // Date end print ''; // Description print ''; print ''; print '
'.$langs->trans("Ref").'
'.$langs->trans("Label").'
'.$langs->trans("ThirdParty").''; $text=$form->select_company(GETPOST('socid','int'),'socid','',1,1); $texthelp=$langs->trans("IfNeedToUseOhterObjectKeepEmpty"); print $form->textwithtooltip($text.' '.img_help(),$texthelp,1); print '
'.$langs->trans("Visibility").''; $array=array(0 => $langs->trans("PrivateProject"),1 => $langs->trans("SharedProject")); print $form->selectarray('public',$array,$object->public); print '
'.$langs->trans("DateStart").''; print $form->select_date('','project'); print '
'.$langs->trans("DateEnd").''; print $form->select_date(-1,'projectend'); print '
'.$langs->trans("Description").''; print ''; print '
'; print '
'; print ''; if (! empty($backtopage)) { print '     '; print ''; } print '
'; print '
'; } else { /* * Show or edit */ dol_htmloutput_mesg($mesg); $object->fetch($id,$ref); if ($object->societe->id > 0) $result=$object->societe->fetch($object->societe->id); // To verify role of users $userAccess = $object->restrictedProjectArea($user,'read'); $userWrite = $object->restrictedProjectArea($user,'write'); $userDelete = $object->restrictedProjectArea($user,'delete'); //print "userAccess=".$userAccess." userWrite=".$userWrite." userDelete=".$userDelete; $head=project_prepare_head($object); dol_fiche_head($head, 'project', $langs->trans("Project"),0,($object->public?'projectpub':'project')); // Confirmation validation if ($action == 'validate') { $ret=$form->form_confirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('ValidateProject'), $langs->trans('ConfirmValidateProject'), 'confirm_validate','',0,1); if ($ret == 'html') print '
'; } // Confirmation close if ($action == 'close') { $ret=$form->form_confirm($_SERVER["PHP_SELF"]."?id=".$object->id,$langs->trans("CloseAProject"),$langs->trans("ConfirmCloseAProject"),"confirm_close",'','',1); if ($ret == 'html') print '
'; } // Confirmation reopen if ($action == 'reopen') { $ret=$form->form_confirm($_SERVER["PHP_SELF"]."?id=".$object->id,$langs->trans("ReOpenAProject"),$langs->trans("ConfirmReOpenAProject"),"confirm_reopen",'','',1); if ($ret == 'html') print '
'; } // Confirmation delete if ($action == 'delete') { $text=$langs->trans("ConfirmDeleteAProject"); $task=new Task($db); $taskarray=$task->getTasksArray(0,0,$object->id,0,0); $nboftask=count($taskarray); if ($nboftask) $text.='
'.img_warning().' '.$langs->trans("ThisWillAlsoRemoveTasks",$nboftask); $ret=$form->form_confirm($_SERVER["PHP_SELF"]."?id=".$object->id,$langs->trans("DeleteAProject"),$text,"confirm_delete",'','',1); if ($ret == 'html') print '
'; } if ($action == 'edit' && $userWrite > 0) { print '
'; print ''; print ''; print ''; print ''; // Ref print ''; print ''; // Label print ''; print ''; // Customer print ''; // Visibility print ''; // Statut print ''; // Date start print ''; // Date end print ''; // Description print ''; print ''; print '
'.$langs->trans("Ref").'
'.$langs->trans("Label").'
'.$langs->trans("Company").''; $text=$form->select_company($project->societe->id,'socid','',1,1); $texthelp=$langs->trans("IfNeedToUseOhterObjectKeepEmpty"); print $form->textwithtooltip($text.' '.img_help(),$texthelp,1); print '
'.$langs->trans("Visibility").''; $array=array(0 => $langs->trans("PrivateProject"),1 => $langs->trans("SharedProject")); print $form->selectarray('public',$array,$object->public); print '
'.$langs->trans("Status").''.$object->getLibStatut(4).'
'.$langs->trans("DateStart").''; print $form->select_date($project->date_start,'project'); print '
'.$langs->trans("DateEnd").''; print $form->select_date($object->date_end?$object->date_end:-1,'projectend'); print '
'.$langs->trans("Description").''; print ''; print '
'; print '

'; print '   '; print '
'; print '
'; } else { print ''; // Ref print ''; // Label print ''; // Third party print ''; // Visibility print ''; // Statut print ''; // Date start print ''; // Date end print ''; // Description print ''; print '
'.$langs->trans("Ref").''; // Define a complementary filter for search of next/prev ref. if (! $user->rights->projet->all->lire) { $objectsListId = $object->getProjectsAuthorizedForUser($user,$mine,0); $object->next_prev_filter=" rowid in (".(count($objectsListId)?join(',',array_keys($objectsListId)):'0').")"; } print $form->showrefnav($object,'ref','',1,'ref','ref'); print '
'.$langs->trans("Label").''.$object->title.'
'.$langs->trans("Company").''; if ($object->societe->id > 0) print $object->societe->getNomUrl(1); else print' '; print '
'.$langs->trans("Visibility").''; if ($object->public) print $langs->trans('SharedProject'); else print $langs->trans('PrivateProject'); print '
'.$langs->trans("Status").''.$object->getLibStatut(4).'
'.$langs->trans("DateStart").''; print dol_print_date($object->date_start,'day'); print '
'.$langs->trans("DateEnd").''; print dol_print_date($object->date_end,'day'); print '
'.$langs->trans("Description").''; print nl2br($object->description); print '
'; } dol_fiche_end(); /* * Boutons actions */ print '
'; if ($action != "edit" ) { // Validate if ($project->statut == 0 && $user->rights->projet->creer) { if ($userWrite > 0) { print ''.$langs->trans("Valid").''; } else { print ''.$langs->trans('Valid').''; } } // Modify if ($object->statut != 2 && $user->rights->projet->creer) { if ($userWrite > 0) { print ''.$langs->trans("Modify").''; } else { print ''.$langs->trans('Modify').''; } } // Close if ($object->statut == 1 && $user->rights->projet->creer) { if ($userWrite > 0) { print ''.$langs->trans("Close").''; } else { print ''.$langs->trans('Close').''; } } // Reopen if ($object->statut == 2 && $user->rights->projet->creer) { if ($userWrite > 0) { print ''.$langs->trans("ReOpen").''; } else { print ''.$langs->trans('ReOpen').''; } } // Delete if ($user->rights->projet->supprimer) { if ($userDelete > 0) { print ''.$langs->trans("Delete").''; } else { print ''.$langs->trans('Delete').''; } } } print "
"; print "
\n"; if ($action != 'presend') { print '
'; print ''; // ancre /* * Documents generes */ $filename=dol_sanitizeFileName($object->ref); $filedir=$conf->projet->dir_output . "/" . dol_sanitizeFileName($object->ref); $urlsource=$_SERVER["PHP_SELF"]."?id=".$object->id; $genallowed=($user->rights->projet->lire && $userAccess > 0); $delallowed=($user->rights->projet->creer && $userWrite > 0); $var=true; $somethingshown=$formfile->show_documents('project',$filename,$filedir,$urlsource,$genallowed,$delallowed,$object->modelpdf); print ''; // List of actions on element include_once(DOL_DOCUMENT_ROOT.'/core/class/html.formactions.class.php'); $formactions=new FormActions($db); $somethingshown=$formactions->showactions($object,'project',$socid); print '
'; } } llxFooter(); $db->close(); ?>