123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910 |
- <?php
- /* Copyright (C) 2001-2005 Rodolphe Quiedeville <rodolphe@quiedeville.org>
- * Copyright (C) 2004-2016 Laurent Destailleur <eldy@users.sourceforge.net>
- * Copyright (C) 2005 Marc Bariley / Ocebo <marc@ocebo.com>
- * Copyright (C) 2005-2010 Regis Houssin <regis.houssin@capnetworks.com>
- * Copyright (C) 2013 Cédric Salvador <csalvador@gpcsolutions.fr>
- * Copyright (C) 2015 Claudio Aschieri <c.aschieri@19.coop>
- *
- * 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/projet/list.php
- * \ingroup projet
- * \brief Page to list projects
- */
- require '../main.inc.php';
- require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';
- require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
- require_once DOL_DOCUMENT_ROOT.'/core/class/html.formother.class.php';
- require_once DOL_DOCUMENT_ROOT.'/core/class/html.formprojet.class.php';
- $langs->loadLangs(array('projects', 'companies', 'commercial'));
- $action=GETPOST('action','alpha');
- $massaction=GETPOST('massaction','alpha');
- $show_files=GETPOST('show_files','int');
- $confirm=GETPOST('confirm','alpha');
- $toselect = GETPOST('toselect', 'array');
- $title = $langs->trans("Projects");
- // Security check
- $socid = (is_numeric($_GET["socid"]) ? $_GET["socid"] : 0 );
- //if ($user->societe_id > 0) $socid = $user->societe_id; // For external user, no check is done on company because readability is managed by public status of project and assignement.
- if ($socid > 0)
- {
- $soc = new Societe($db);
- $soc->fetch($socid);
- $title .= ' (<a href="list.php">'.$soc->name.'</a>)';
- }
- if (!$user->rights->projet->lire) accessforbidden();
- $diroutputmassaction=$conf->projet->dir_output . '/temp/massgeneration/'.$user->id;
- $limit = GETPOST("limit")?GETPOST("limit","int"):$conf->liste_limit;
- $sortfield = GETPOST("sortfield","alpha");
- $sortorder = GETPOST("sortorder");
- $page = GETPOST("page");
- $page = is_numeric($page) ? $page : 0;
- $page = $page == -1 ? 0 : $page;
- if (! $sortfield) $sortfield="p.ref";
- if (! $sortorder) $sortorder="ASC";
- $offset = $limit * $page ;
- $pageprev = $page - 1;
- $pagenext = $page + 1;
- $search_all=GETPOST('search_all', 'alphanohtml');
- $search_categ=GETPOST("search_categ",'alpha');
- $search_ref=GETPOST("search_ref");
- $search_label=GETPOST("search_label");
- $search_societe=GETPOST("search_societe");
- $search_year=GETPOST("search_year");
- $search_status=GETPOST("search_status",'int');
- $search_opp_status=GETPOST("search_opp_status",'alpha');
- $search_opp_percent=GETPOST("search_opp_percent",'alpha');
- $search_opp_amount=GETPOST("search_opp_amount",'alpha');
- $search_budget_amount=GETPOST("search_budget_amount",'alpha');
- $search_public=GETPOST("search_public",'int');
- $search_project_user=GETPOST('search_project_user','int');
- $search_sale=GETPOST('search_sale','int');
- $optioncss = GETPOST('optioncss','alpha');
- $mine = $_REQUEST['mode']=='mine' ? 1 : 0;
- if ($mine) { $search_project_user = $user->id; $mine=0; }
- $search_sday = GETPOST('search_sday','int');
- $search_smonth = GETPOST('search_smonth','int');
- $search_syear = GETPOST('search_syear','int');
- $search_eday = GETPOST('search_eday','int');
- $search_emonth = GETPOST('search_emonth','int');
- $search_eyear = GETPOST('search_eyear','int');
- if ($search_status == '') $search_status=-1; // -1 or 1
- // Initialize context for list
- $contextpage=GETPOST('contextpage','aZ')?GETPOST('contextpage','aZ'):'projectlist';
- // Initialize technical object to manage hooks of thirdparties. Note that conf->hooks_modules contains array array
- $hookmanager->initHooks(array($contextpage));
- $extrafields = new ExtraFields($db);
- // fetch optionals attributes and labels
- $extralabels = $extrafields->fetch_name_optionals_label('projet');
- $search_array_options=$extrafields->getOptionalsFromPost($extralabels,'','search_');
- // List of fields to search into when doing a "search in all"
- $fieldstosearchall = array(
- 'p.ref'=>"Ref",
- 'p.title'=>"Label",
- 's.nom'=>"ThirdPartyName",
- "p.note_public"=>"NotePublic"
- );
- if (empty($user->socid)) $fieldstosearchall["p.note_private"]="NotePrivate";
- $arrayfields=array(
- 'p.ref'=>array('label'=>$langs->trans("Ref"), 'checked'=>1),
- 'p.title'=>array('label'=>$langs->trans("Label"), 'checked'=>1),
- 's.nom'=>array('label'=>$langs->trans("ThirdParty"), 'checked'=>1, 'enabled'=>$conf->societe->enabled),
- 'commercial'=>array('label'=>$langs->trans("SaleRepresentativesOfThirdParty"), 'checked'=>1),
- 'p.dateo'=>array('label'=>$langs->trans("DateStart"), 'checked'=>1, 'position'=>100),
- 'p.datee'=>array('label'=>$langs->trans("DateEnd"), 'checked'=>1, 'position'=>101),
- 'p.public'=>array('label'=>$langs->trans("Visibility"), 'checked'=>1, 'position'=>102),
- 'p.opp_amount'=>array('label'=>$langs->trans("OpportunityAmountShort"), 'checked'=>1, 'enabled'=>($conf->global->PROJECT_USE_OPPORTUNITIES?1:0), 'position'=>103),
- 'p.fk_opp_status'=>array('label'=>$langs->trans("OpportunityStatusShort"), 'checked'=>1, 'enabled'=>($conf->global->PROJECT_USE_OPPORTUNITIES?1:0), 'position'=>104),
- 'p.opp_percent'=>array('label'=>$langs->trans("OpportunityProbabilityShort"), 'checked'=>1, 'enabled'=>($conf->global->PROJECT_USE_OPPORTUNITIES?1:0), 'position'=>105),
- 'p.budget_amount'=>array('label'=>$langs->trans("Budget"), 'checked'=>0, 'position'=>110),
- 'p.datec'=>array('label'=>$langs->trans("DateCreationShort"), 'checked'=>0, 'position'=>500),
- 'p.tms'=>array('label'=>$langs->trans("DateModificationShort"), 'checked'=>0, 'position'=>500),
- 'p.fk_statut'=>array('label'=>$langs->trans("Status"), 'checked'=>1, 'position'=>1000),
- );
- // Extra fields
- if (is_array($extrafields->attribute_label) && count($extrafields->attribute_label))
- {
- foreach($extrafields->attribute_label as $key => $val)
- {
- $arrayfields["ef.".$key]=array('label'=>$extrafields->attribute_label[$key], 'checked'=>$extrafields->attribute_list[$key], 'position'=>$extrafields->attribute_pos[$key], 'enabled'=>$extrafields->attribute_perms[$key]);
- }
- }
- $object = new Project($db);
- /*
- * Actions
- */
- if (GETPOST('cancel')) { $action='list'; $massaction=''; }
- if (! GETPOST('confirmmassaction') && $massaction != 'presend' && $massaction != 'confirm_presend' && $massaction != 'confirm_createbills') { $massaction=''; }
- $parameters=array('socid'=>$socid);
- $reshook=$hookmanager->executeHooks('doActions',$parameters,$object,$action); // Note that $action and $object may have been modified by some hooks
- if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
- if (empty($reshook))
- {
- // Selection of new fields
- include DOL_DOCUMENT_ROOT.'/core/actions_changeselectedfields.inc.php';
- // Purge search criteria
- if (GETPOST("button_removefilter_x") || GETPOST("button_removefilter.x") || GETPOST("button_removefilter")) // All tests are required to be compatible with all browsers
- {
- $search_all='';
- $search_categ='';
- $search_ref="";
- $search_label="";
- $search_societe="";
- $search_year="";
- $search_status=-1;
- $search_opp_status=-1;
- $search_opp_amount='';
- $search_opp_percent='';
- $search_budget_amount='';
- $search_public="";
- $search_sale="";
- $search_project_user='';
- $search_sday="";
- $search_smonth="";
- $search_syear="";
- $search_eday="";
- $search_emonth="";
- $search_eyear="";
- $toselect='';
- $search_array_options=array();
- }
-
- // Mass actions
- $objectclass='Project';
- $objectlabel='Project';
- $permtoread = $user->rights->projet->lire;
- $permtodelete = $user->rights->projet->supprimer;
- $uploaddir = $conf->projet->dir_output;
- include DOL_DOCUMENT_ROOT.'/core/actions_massactions.inc.php';
- }
- /*
- * View
- */
- $socstatic = new Societe($db);
- $form = new Form($db);
- $formother = new FormOther($db);
- $formproject = new FormProjets($db);
- $title=$langs->trans("Projects");
- //if ($search_project_user == $user->id) $title=$langs->trans("MyProjects");
- // Get list of project id allowed to user (in a string list separated by coma)
- $projectsListId='';
- if (! $user->rights->projet->all->lire) $projectsListId = $object->getProjectsAuthorizedForUser($user,0,1,$socid);
- // Get id of types of contacts for projects (This list never contains a lot of elements)
- $listofprojectcontacttype=array();
- $sql = "SELECT ctc.rowid, ctc.code FROM ".MAIN_DB_PREFIX."c_type_contact as ctc";
- $sql.= " WHERE ctc.element = '" . $object->element . "'";
- $sql.= " AND ctc.source = 'internal'";
- $resql = $db->query($sql);
- if ($resql)
- {
- while($obj = $db->fetch_object($resql))
- {
- $listofprojectcontacttype[$obj->rowid]=$obj->code;
- }
- }
- else dol_print_error($db);
- if (count($listofprojectcontacttype) == 0) $listofprojectcontacttype[0]='0'; // To avoid sql syntax error if not found
- $distinct='DISTINCT'; // We add distinct until we are added a protection to be sure a contact of a project and task is only once.
- $sql = "SELECT ".$distinct." p.rowid as id, p.ref, p.title, p.fk_statut, p.fk_opp_status, p.public, p.fk_user_creat";
- $sql.= ", p.datec as date_creation, p.dateo as date_start, p.datee as date_end, p.opp_amount, p.opp_percent, p.tms as date_update, p.budget_amount";
- $sql.= ", s.nom as name, s.rowid as socid";
- $sql.= ", cls.code as opp_status_code";
- // We'll need these fields in order to filter by categ
- if ($search_categ) $sql .= ", cs.fk_categorie, cs.fk_project";
- // Add fields for extrafields
- foreach ($extrafields->attribute_label as $key => $val) $sql.=($extrafields->attribute_type[$key] != 'separate' ? ",ef.".$key.' as options_'.$key : '');
- // Add fields from hooks
- $parameters=array();
- $reshook=$hookmanager->executeHooks('printFieldListSelect',$parameters); // Note that $action and $object may have been modified by hook
- $sql.=$hookmanager->resPrint;
- $sql.= " FROM ".MAIN_DB_PREFIX."projet as p";
- if (is_array($extrafields->attribute_label) && count($extrafields->attribute_label)) $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."projet_extrafields as ef on (p.rowid = ef.fk_object)";
- $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s on p.fk_soc = s.rowid";
- $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."c_lead_status as cls on p.fk_opp_status = cls.rowid";
- // We'll need this table joined to the select in order to filter by categ
- if (! empty($search_categ)) $sql.= ' LEFT JOIN '.MAIN_DB_PREFIX."categorie_project as cs ON p.rowid = cs.fk_project"; // We'll need this table joined to the select in order to filter by categ
- // We'll need this table joined to the select in order to filter by sale
- // For external user, no check is done on company permission because readability is managed by public status of project and assignement.
- //if ($search_sale > 0 || (! $user->rights->societe->client->voir && ! $socid)) $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe_commerciaux as sc ON sc.fk_soc = s.rowid";
- if ($search_sale > 0) $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe_commerciaux as sc ON sc.fk_soc = s.rowid";
- if ($search_project_user > 0)
- {
- $sql.=", ".MAIN_DB_PREFIX."element_contact as ecp";
- }
- $sql.= " WHERE p.entity IN (".getEntity('project',1).')';
- if (! $user->rights->projet->all->lire) $sql.= " AND p.rowid IN (".$projectsListId.")"; // public and assigned to, or restricted to company for external users
- // No need to check company, as filtering of projects must be done by getProjectsAuthorizedForUser
- if ($socid) $sql.= " AND (p.fk_soc IS NULL OR p.fk_soc = 0 OR p.fk_soc = ".$socid.")";
- if ($search_categ > 0) $sql.= " AND cs.fk_categorie = ".$db->escape($search_categ);
- if ($search_categ == -2) $sql.= " AND cs.fk_categorie IS NULL";
- if ($search_ref) $sql .= natural_search('p.ref', $search_ref);
- if ($search_label) $sql .= natural_search('p.title', $search_label);
- if ($search_societe) $sql .= natural_search('s.nom', $search_societe);
- if ($search_opp_amount) $sql .= natural_search('p.opp_amount', $search_opp_amount, 1);
- if ($search_opp_percent) $sql .= natural_search('p.opp_percent', $search_opp_percent, 1);
- if ($search_smonth > 0)
- {
- if ($search_syear > 0 && empty($search_sday))
- $sql.= " AND p.dateo BETWEEN '".$db->idate(dol_get_first_day($search_syear,$search_smonth,false))."' AND '".$db->idate(dol_get_last_day($search_syear,$search_smonth,false))."'";
- else if ($search_syear > 0 && ! empty($search_sday))
- $sql.= " AND p.dateo BETWEEN '".$db->idate(dol_mktime(0, 0, 0, $search_smonth, $search_sday, $search_syear))."' AND '".$db->idate(dol_mktime(23, 59, 59, $search_smonth, $search_sday, $search_syear))."'";
- else
- $sql.= " AND date_format(p.dateo, '%m') = '".$search_smonth."'";
- }
- else if ($search_syear > 0)
- {
- $sql.= " AND p.dateo BETWEEN '".$db->idate(dol_get_first_day($search_syear,1,false))."' AND '".$db->idate(dol_get_last_day($search_syear,12,false))."'";
- }
- if ($search_emonth > 0)
- {
- if ($search_eyear > 0 && empty($search_eday))
- $sql.= " AND p.datee BETWEEN '".$db->idate(dol_get_first_day($search_eyear,$search_emonth,false))."' AND '".$db->idate(dol_get_last_day($search_eyear,$search_emonth,false))."'";
- else if ($search_eyear > 0 && ! empty($search_eday))
- $sql.= " AND p.datee BETWEEN '".$db->idate(dol_mktime(0, 0, 0, $search_emonth, $search_eday, $search_eyear))."' AND '".$db->idate(dol_mktime(23, 59, 59, $search_emonth, $search_eday, $search_eyear))."'";
- else
- $sql.= " AND date_format(p.datee, '%m') = '".$search_emonth."'";
- }
- else if ($search_eyear > 0)
- {
- $sql.= " AND p.datee BETWEEN '".$db->idate(dol_get_first_day($search_eyear,1,false))."' AND '".$db->idate(dol_get_last_day($search_eyear,12,false))."'";
- }
- if ($search_all) $sql .= natural_search(array_keys($fieldstosearchall), $search_all);
- if ($search_status >= 0)
- {
- if ($search_status == 99) $sql .= " AND p.fk_statut <> 2";
- else $sql .= " AND p.fk_statut = ".$db->escape($search_status);
- }
- if ($search_opp_status)
- {
- if (is_numeric($search_opp_status) && $search_opp_status > 0) $sql .= " AND p.fk_opp_status = ".$db->escape($search_opp_status);
- if ($search_opp_status == 'all') $sql .= " AND p.fk_opp_status IS NOT NULL";
- if ($search_opp_status == 'openedopp') $sql .= " AND p.fk_opp_status IS NOT NULL AND p.fk_opp_status NOT IN (SELECT rowid FROM ".MAIN_DB_PREFIX."c_lead_status WHERE code IN ('WON','LOST'))";
- if ($search_opp_status == 'none') $sql .= " AND p.fk_opp_status IS NULL";
- }
- if ($search_public!='') $sql .= " AND p.public = ".$db->escape($search_public);
- if ($search_sale > 0) $sql.= " AND sc.fk_user = " .$search_sale;
- // For external user, no check is done on company permission because readability is managed by public status of project and assignement.
- //if (! $user->rights->societe->client->voir && ! $socid) $sql.= " AND ((s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id.") OR (s.rowid IS NULL))";
- if ($search_project_user > 0) $sql.= " AND ecp.fk_c_type_contact IN (".join(',',array_keys($listofprojectcontacttype)).") AND ecp.element_id = p.rowid AND ecp.fk_socpeople = ".$search_project_user;
- if ($search_opp_amount != '') $sql .= natural_search('p.opp_amount', $search_opp_amount, 1);
- if ($search_budget_amount != '') $sql .= natural_search('p.budget_amount', $search_budget_amount, 1);
- // Add where from extra fields
- foreach ($search_array_options as $key => $val)
- {
- $crit=$val;
- $tmpkey=preg_replace('/search_options_/','',$key);
- $typ=$extrafields->attribute_type[$tmpkey];
- $mode=0;
- if (in_array($typ, array('int','double'))) $mode=1; // Search on a numeric
- if ($val && ( ($crit != '' && ! in_array($typ, array('select'))) || ! empty($crit)))
- {
- $sql .= natural_search('ef.'.$tmpkey, $crit, $mode);
- }
- }
- // Add where from hooks
- $parameters=array();
- $reshook=$hookmanager->executeHooks('printFieldListWhere',$parameters); // Note that $action and $object may have been modified by hook
- $sql.=$hookmanager->resPrint;
- $sql.= $db->order($sortfield,$sortorder);
- $nbtotalofrecords = '';
- if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST))
- {
- $result = $db->query($sql);
- $nbtotalofrecords = $db->num_rows($result);
- }
- $sql.= $db->plimit($limit + 1,$offset);
- //print $sql;
- dol_syslog("list allowed project", LOG_DEBUG);
- //print $sql;
- $resql = $db->query($sql);
- if (! $resql)
- {
- dol_print_error($db);
- exit;
- }
- $num = $db->num_rows($resql);
- $arrayofselected=is_array($toselect)?$toselect:array();
- if ($num == 1 && ! empty($conf->global->MAIN_SEARCH_DIRECT_OPEN_IF_ONLY_ONE) && $search_all)
- {
- $obj = $db->fetch_object($resql);
- header("Location: ".DOL_URL_ROOT.'/projet/card.php?id='.$obj->id);
- exit;
- }
- $help_url="EN:Module_Projects|FR:Module_Projets|ES:Módulo_Proyectos";
- llxHeader("", $title, $help_url);
- $param='';
- if (! empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) $param.='&contextpage='.$contextpage;
- if ($limit > 0 && $limit != $conf->liste_limit) $param.='&limit='.$limit;
- if ($search_sday) $param.='&search_sday='.$search_sday;
- if ($search_smonth) $param.='&search_smonth='.$search_smonth;
- if ($search_syear) $param.='&search_syear=' .$search_syear;
- if ($search_eday) $param.='&search_eday='.$search_eday;
- if ($search_emonth) $param.='&search_emonth='.$search_emonth;
- if ($search_eyear) $param.='&search_eyear=' .$search_eyear;
- if ($socid) $param.='&socid='.$socid;
- if ($search_all != '') $param.='&search_all='.$search_all;
- if ($search_ref != '') $param.='&search_ref='.$search_ref;
- if ($search_label != '') $param.='&search_label='.$search_label;
- if ($search_societe != '') $param.='&search_societe='.$search_societe;
- if ($search_status >= 0) $param.='&search_status='.$search_status;
- if ((is_numeric($search_opp_status) && $search_opp_status >= 0) || in_array($search_opp_status, array('all','openedopp','none'))) $param.='&search_opp_status='.urlencode($search_opp_status);
- if ((is_numeric($search_opp_percent) && $search_opp_percent >= 0) || in_array($search_opp_percent, array('all','openedopp','none'))) $param.='&search_opp_percent='.urlencode($search_opp_percent);
- if ($search_public != '') $param.='&search_public='.$search_public;
- if ($search_project_user != '') $param.='&search_project_user='.$search_project_user;
- if ($search_sale > 0) $param.='&search_sale='.$search_sale;
- if ($search_opp_amount != '') $param.='&search_opp_amount='.$search_opp_amount;
- if ($search_budget_amount != '') $param.='&search_budget_amount='.$search_budget_amount;
- if ($optioncss != '') $param.='&optioncss='.$optioncss;
- // Add $param from extra fields
- foreach ($search_array_options as $key => $val)
- {
- $crit=$val;
- $tmpkey=preg_replace('/search_options_/','',$key);
- if ($val != '') $param.='&search_options_'.$tmpkey.'='.urlencode($val);
- }
- // List of mass actions available
- $arrayofmassactions = array(
- // 'presend'=>$langs->trans("SendByMail"),
- // 'builddoc'=>$langs->trans("PDFMerge"),
- );
- //if($user->rights->societe->creer) $arrayofmassactions['createbills']=$langs->trans("CreateInvoiceForThisCustomer");
- if ($user->rights->societe->supprimer) $arrayofmassactions['delete']=$langs->trans("Delete");
- if ($massaction == 'presend') $arrayofmassactions=array();
- $massactionbutton=$form->selectMassAction('', $arrayofmassactions);
- print '<form method="POST" id="searchFormList" action="'.$_SERVER["PHP_SELF"].'">';
- if ($optioncss != '') print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
- print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
- print '<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">';
- print '<input type="hidden" name="action" value="list">';
- print '<input type="hidden" name="sortfield" value="'.$sortfield.'">';
- print '<input type="hidden" name="sortorder" value="'.$sortorder.'">';
- print '<input type="hidden" name="page" value="'.$page.'">';
- print '<input type="hidden" name="type" value="'.$type.'">';
- print '<input type="hidden" name="contextpage" value="'.$contextpage.'">';
- print_barre_liste($title, $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, $massactionbutton, $num, $nbtotalofrecords, 'title_project', 0, '', '', $limit);
- // Show description of content
- if ($search_project_user == $user->id) print $langs->trans("MyProjectsDesc").'<br><br>';
- else
- {
- if ($user->rights->projet->all->lire && ! $socid) print $langs->trans("ProjectsDesc").'<br><br>';
- else print $langs->trans("ProjectsPublicDesc").'<br><br>';
- }
- if ($search_all)
- {
- foreach($fieldstosearchall as $key => $val) $fieldstosearchall[$key]=$langs->trans($val);
- print $langs->trans("FilterOnInto", $search_all) . join(', ',$fieldstosearchall);
- }
- $moreforfilter='';
- // Filter on categories
- if (! empty($conf->categorie->enabled))
- {
- require_once DOL_DOCUMENT_ROOT . '/categories/class/categorie.class.php';
- $moreforfilter.='<div class="divsearchfield">';
- $moreforfilter.=$langs->trans('ProjectCategories'). ': ';
- $moreforfilter.=$formother->select_categories('project',$search_categ,'search_categ',1);
- $moreforfilter.='</div>';
- }
- // If the user can view user other than himself
- $moreforfilter.='<div class="divsearchfield">';
- $moreforfilter.=$langs->trans('ProjectsWithThisUserAsContact'). ': ';
- $includeonly='';
- if (empty($user->rights->user->user->lire)) $includeonly=array($user->id);
- $moreforfilter.=$form->select_dolusers($search_project_user?$search_project_user:'', 'search_project_user', 1, '', 0, $includeonly, '', 0, 0, 0, '', 0, '', 'maxwidth300');
- $moreforfilter.='</div>';
- // If the user can view thirdparties other than his'
- if ($user->rights->societe->client->voir || $socid)
- {
- $langs->load("commercial");
- $moreforfilter.='<div class="divsearchfield">';
- $moreforfilter.=$langs->trans('ThirdPartiesOfSaleRepresentative'). ': ';
- $moreforfilter.=$formother->select_salesrepresentatives($search_sale, 'search_sale', $user, 0, 1, 'maxwidth300');
- $moreforfilter.='</div>';
- }
- if (! empty($moreforfilter))
- {
- print '<div class="liste_titre liste_titre_bydiv centpercent">';
- print $moreforfilter;
- $parameters=array();
- $reshook=$hookmanager->executeHooks('printFieldPreListTitle',$parameters); // Note that $action and $object may have been modified by hook
- print $hookmanager->resPrint;
- print '</div>';
- }
- $varpage=empty($contextpage)?$_SERVER["PHP_SELF"]:$contextpage;
- $selectedfields=$form->multiSelectArrayWithCheckbox('selectedfields', $arrayfields, $varpage); // This also change content of $arrayfields
- if ($massactionbutton) $selectedfields.=$form->showCheckAddButtons('checkforselect', 1);
- print '<div class="div-table-responsive">';
- print '<table class="tagtable liste'.($moreforfilter?" listwithfilterbefore":"").'">'."\n";
- print '<tr class="liste_titre_filter">';
- if (! empty($arrayfields['p.ref']['checked']))
- {
- print '<td class="liste_titre">';
- print '<input type="text" class="flat" name="search_ref" value="'.$search_ref.'" size="6">';
- print '</td>';
- }
- if (! empty($arrayfields['p.title']['checked']))
- {
- print '<td class="liste_titre">';
- print '<input type="text" class="flat" name="search_label" size="8" value="'.$search_label.'">';
- print '</td>';
- }
- if (! empty($arrayfields['s.nom']['checked']))
- {
- print '<td class="liste_titre">';
- print '<input type="text" class="flat" name="search_societe" size="8" value="'.$search_societe.'">';
- print '</td>';
- }
- // Sale representative
- if (! empty($arrayfields['commercial']['checked']))
- {
- print '<td class="liste_titre"> </td>';
- }
- // Start date
- if (! empty($arrayfields['p.dateo']['checked']))
- {
- print '<td class="liste_titre center">';
- if (! empty($conf->global->MAIN_LIST_FILTER_ON_DAY)) print '<input class="flat" type="text" size="1" maxlength="2" name="search_sday" value="'.$search_sday.'">';
- print '<input class="flat" type="text" size="1" maxlength="2" name="search_smonth" value="'.$search_smonth.'">';
- $formother->select_year($search_syear?$search_syear:-1,'search_syear',1, 20, 5);
- print '</td>';
- }
- // End date
- if (! empty($arrayfields['p.datee']['checked']))
- {
- print '<td class="liste_titre center">';
- if (! empty($conf->global->MAIN_LIST_FILTER_ON_DAY)) print '<input class="flat" type="text" size="1" maxlength="2" name="search_eday" value="'.$search_eday.'">';
- print '<input class="flat" type="text" size="1" maxlength="2" name="search_emonth" value="'.$search_emonth.'">';
- $formother->select_year($search_eyear?$search_eyear:-1,'search_eyear',1, 20, 5);
- print '</td>';
- }
- if (! empty($arrayfields['p.public']['checked']))
- {
- print '<td class="liste_titre">';
- $array=array(''=>'',0 => $langs->trans("PrivateProject"),1 => $langs->trans("SharedProject"));
- print $form->selectarray('search_public',$array,$search_public);
- print '</td>';
- }
- if (! empty($arrayfields['p.opp_amount']['checked']))
- {
- print '<td class="liste_titre nowrap right">';
- print '<input type="text" class="flat" name="search_opp_amount" size="3" value="'.$search_opp_amount.'">';
- print '</td>';
- }
- if (! empty($arrayfields['p.fk_opp_status']['checked']))
- {
- print '<td class="liste_titre nowrap center">';
- print $formproject->selectOpportunityStatus('search_opp_status', $search_opp_status, 1, 1, 1, 0, 'maxwidth100');
- print '</td>';
- }
- if (! empty($arrayfields['p.opp_percent']['checked']))
- {
- print '<td class="liste_titre nowrap right">';
- print '<input type="text" class="flat" name="search_opp_percent" size="2" value="'.$search_opp_percent.'">';
- print '</td>';
- }
- if (! empty($arrayfields['p.budget_amount']['checked']))
- {
- print '<td class="liste_titre nowrap" align="right">';
- print '<input type="text" class="flat" name="search_budget_amount" size="4" value="'.$search_budget_amount.'">';
- print '</td>';
- }
- // Extra fields
- if (is_array($extrafields->attribute_label) && count($extrafields->attribute_label))
- {
- foreach($extrafields->attribute_label as $key => $val)
- {
- if (! empty($arrayfields["ef.".$key]['checked']))
- {
- $align=$extrafields->getAlignFlag($key);
- $typeofextrafield=$extrafields->attribute_type[$key];
- print '<td class="liste_titre'.($align?' '.$align:'').'">';
- if (in_array($typeofextrafield, array('varchar', 'int', 'double', 'select')) && empty($extrafields->attribute_computed[$key]))
- {
- $crit=$val;
- $tmpkey=preg_replace('/search_options_/','',$key);
- $searchclass='';
- if (in_array($typeofextrafield, array('varchar', 'select'))) $searchclass='searchstring';
- if (in_array($typeofextrafield, array('int', 'double'))) $searchclass='searchnum';
- print '<input class="flat'.($searchclass?' '.$searchclass:'').'" size="4" type="text" name="search_options_'.$tmpkey.'" value="'.dol_escape_htmltag($search_array_options['search_options_'.$tmpkey]).'">';
- }
- print '</td>';
- }
- }
- }
- // Fields from hook
- $parameters=array('arrayfields'=>$arrayfields);
- $reshook=$hookmanager->executeHooks('printFieldListOption',$parameters); // Note that $action and $object may have been modified by hook
- print $hookmanager->resPrint;
- if (! empty($arrayfields['p.datec']['checked']))
- {
- // Date creation
- print '<td class="liste_titre">';
- print '</td>';
- }
- if (! empty($arrayfields['p.tms']['checked']))
- {
- // Date modification
- print '<td class="liste_titre">';
- print '</td>';
- }
- if (! empty($arrayfields['p.fk_statut']['checked']))
- {
- print '<td class="liste_titre nowrap" align="right">';
- $arrayofstatus = array();
- foreach($object->statuts_short as $key => $val) $arrayofstatus[$key]=$langs->trans($val);
- $arrayofstatus['99']=$langs->trans("NotClosed").' ('.$langs->trans('Draft').'+'.$langs->trans('Opened').')';
- print $form->selectarray('search_status', $arrayofstatus, $search_status, 1, 0, 0, '', 0, 0, 0, '', 'maxwidth100');
- print '</td>';
- }
- // Action column
- print '<td class="liste_titre" align="right">';
- $searchpicto=$form->showFilterButtons();
- print $searchpicto;
- print '</td>';
- print '</tr>'."\n";
- print '<tr class="liste_titre">';
- if (! empty($arrayfields['p.ref']['checked'])) print_liste_field_titre($arrayfields['p.ref']['label'],$_SERVER["PHP_SELF"],"p.ref","",$param,"",$sortfield,$sortorder);
- if (! empty($arrayfields['p.title']['checked'])) print_liste_field_titre($arrayfields['p.title']['label'],$_SERVER["PHP_SELF"],"p.title","",$param,"",$sortfield,$sortorder);
- if (! empty($arrayfields['s.nom']['checked'])) print_liste_field_titre($arrayfields['s.nom']['label'],$_SERVER["PHP_SELF"],"s.nom","",$param,"",$sortfield,$sortorder);
- if (! empty($arrayfields['commercial']['checked'])) print_liste_field_titre($arrayfields['commercial']['label'],$_SERVER["PHP_SELF"],"","",$param,"",$sortfield,$sortorder);
- if (! empty($arrayfields['p.dateo']['checked'])) print_liste_field_titre($arrayfields['p.dateo']['label'],$_SERVER["PHP_SELF"],"p.dateo","",$param,'align="center"',$sortfield,$sortorder);
- if (! empty($arrayfields['p.datee']['checked'])) print_liste_field_titre($arrayfields['p.datee']['label'],$_SERVER["PHP_SELF"],"p.datee","",$param,'align="center"',$sortfield,$sortorder);
- if (! empty($arrayfields['p.public']['checked'])) print_liste_field_titre($arrayfields['p.public']['label'],$_SERVER["PHP_SELF"],"p.public","",$param,"",$sortfield,$sortorder);
- if (! empty($arrayfields['p.opp_amount']['checked'])) print_liste_field_titre($arrayfields['p.opp_amount']['label'],$_SERVER["PHP_SELF"],'p.opp_amount',"",$param,'align="right"',$sortfield,$sortorder);
- if (! empty($arrayfields['p.fk_opp_status']['checked'])) print_liste_field_titre($arrayfields['p.fk_opp_status']['label'],$_SERVER["PHP_SELF"],'p.fk_opp_status',"",$param,'align="center"',$sortfield,$sortorder);
- if (! empty($arrayfields['p.opp_percent']['checked'])) print_liste_field_titre($arrayfields['p.opp_percent']['label'],$_SERVER["PHP_SELF"],'p.opp_percent',"",$param,'align="right"',$sortfield,$sortorder);
- if (! empty($arrayfields['p.budget_amount']['checked'])) print_liste_field_titre($arrayfields['p.budget_amount']['label'],$_SERVER["PHP_SELF"],'p.budget_amount',"",$param,'align="right"',$sortfield,$sortorder);
- // Extra fields
- if (is_array($extrafields->attribute_label) && count($extrafields->attribute_label))
- {
- foreach($extrafields->attribute_label as $key => $val)
- {
- if (! empty($arrayfields["ef.".$key]['checked']))
- {
- $align=$extrafields->getAlignFlag($key);
- $sortonfield = "ef.".$key;
- if (! empty($extrafields->attribute_computed[$key])) $sortonfield='';
- print_liste_field_titre($langs->trans($extralabels[$key]),$_SERVER["PHP_SELF"],$sortonfield,"",$param,($align?'align="'.$align.'"':''),$sortfield,$sortorder);
- }
- }
- }
- // Hook fields
- $parameters=array('arrayfields'=>$arrayfields);
- $reshook=$hookmanager->executeHooks('printFieldListTitle',$parameters); // Note that $action and $object may have been modified by hook
- print $hookmanager->resPrint;
- if (! empty($arrayfields['p.datec']['checked'])) print_liste_field_titre($arrayfields['p.datec']['label'],$_SERVER["PHP_SELF"],"p.datec","",$param,'align="center" class="nowrap"',$sortfield,$sortorder);
- if (! empty($arrayfields['p.tms']['checked'])) print_liste_field_titre($arrayfields['p.tms']['label'],$_SERVER["PHP_SELF"],"p.tms","",$param,'align="center" class="nowrap"',$sortfield,$sortorder);
- if (! empty($arrayfields['p.fk_statut']['checked'])) print_liste_field_titre($arrayfields['p.fk_statut']['label'],$_SERVER["PHP_SELF"],"p.fk_statut","",$param,'align="right"',$sortfield,$sortorder);
- print_liste_field_titre($selectedfields, $_SERVER["PHP_SELF"],"",'','','align="center"',$sortfield,$sortorder,'maxwidthsearch ');
- print "</tr>\n";
- $i=0;
- $totalarray=array();
- while ($i < min($num,$limit))
- {
- $obj = $db->fetch_object($resql);
- $object->id = $obj->id;
- $object->user_author_id = $obj->fk_user_creat;
- $object->public = $obj->public;
- $object->ref = $obj->ref;
- $object->datee = $db->jdate($obj->date_end);
- $object->statut = $obj->fk_statut;
- $object->opp_status = $obj->fk_opp_status;
-
- $userAccess = $object->restrictedProjectArea($user); // why this ?
- if ($userAccess >= 0)
- {
- print '<tr class="oddeven">';
- // Project url
- if (! empty($arrayfields['p.ref']['checked']))
- {
- print '<td class="nowrap">';
- print $object->getNomUrl(1);
- if ($object->hasDelay()) print img_warning($langs->trans('Late'));
- print '</td>';
- if (! $i) $totalarray['nbfield']++;
- }
- // Title
- if (! empty($arrayfields['p.title']['checked']))
- {
- print '<td class="tdoverflowmax100">';
- print dol_trunc($obj->title,80);
- print '</td>';
- if (! $i) $totalarray['nbfield']++;
- }
- // Company
- if (! empty($arrayfields['s.nom']['checked']))
- {
- print '<td class="tdoverflowmax100">';
- if ($obj->socid)
- {
- $socstatic->id=$obj->socid;
- $socstatic->name=$obj->name;
- print $socstatic->getNomUrl(1);
- }
- else
- {
- print ' ';
- }
- print '</td>';
- if (! $i) $totalarray['nbfield']++;
- }
- // Sales Representatives
- if (! empty($arrayfields['commercial']['checked']))
- {
- print '<td>';
- if ($obj->socid)
- {
- $socstatic->id=$obj->socid;
- $socstatic->name=$obj->name;
- $listsalesrepresentatives=$socstatic->getSalesRepresentatives($user);
- $nbofsalesrepresentative=count($listsalesrepresentatives);
- if ($nbofsalesrepresentative > 3) // We print only number
- {
- print '<a href="'.DOL_URL_ROOT.'/societe/commerciaux.php?socid='.$socstatic->id.'">';
- print $nbofsalesrepresentative;
- print '</a>';
- }
- else if ($nbofsalesrepresentative > 0)
- {
- $userstatic=new User($db);
- $j=0;
- foreach($listsalesrepresentatives as $val)
- {
- $userstatic->id=$val['id'];
- $userstatic->lastname=$val['lastname'];
- $userstatic->firstname=$val['firstname'];
- $userstatic->email=$val['email'];
- $userstatic->statut=$val['statut'];
- $userstatic->entity=$val['entity'];
- $userstatic->photo=$val['photo'];
- //print $userstatic->getNomUrl(1, '', 0, 0, 12);
- print $userstatic->getNomUrl(-2);
- $j++;
- if ($j < $nbofsalesrepresentative) print ' ';
- }
- }
- //else print $langs->trans("NoSalesRepresentativeAffected");
- }
- else
- {
- print ' ';
- }
- print '</td>';
- if (! $i) $totalarray['nbfield']++;
- }
- // Date start
- if (! empty($arrayfields['p.dateo']['checked']))
- {
- print '<td class="center">';
- print dol_print_date($db->jdate($obj->date_start),'day');
- print '</td>';
- if (! $i) $totalarray['nbfield']++;
- }
- // Date end
- if (! empty($arrayfields['p.datee']['checked']))
- {
- print '<td class="center">';
- print dol_print_date($db->jdate($obj->date_end),'day');
- print '</td>';
- if (! $i) $totalarray['nbfield']++;
- }
- // Visibility
- if (! empty($arrayfields['p.public']['checked']))
- {
- print '<td align="left">';
- if ($obj->public) print $langs->trans('SharedProject');
- else print $langs->trans('PrivateProject');
- print '</td>';
- if (! $i) $totalarray['nbfield']++;
- }
- // Opp Amount
- if (! empty($arrayfields['p.opp_amount']['checked']))
- {
- print '<td align="right">';
- if ($obj->opp_status_code)
- {
- print price($obj->opp_amount, 1, '', 1, -1, -1, '');
- $totalarray['totalopp'] += $obj->opp_amount;
- }
- print '</td>';
- if (! $i) $totalarray['nbfield']++;
- if (! $i) $totalarray['totaloppfield']=$totalarray['nbfield'];
- }
- // Opp Status
- if (! empty($arrayfields['p.fk_opp_status']['checked']))
- {
- print '<td class="center">';
- if ($obj->opp_status_code) print $langs->trans("OppStatusShort".$obj->opp_status_code);
- print '</td>';
- if (! $i) $totalarray['nbfield']++;
- }
- // Opp percent
- if (! empty($arrayfields['p.opp_percent']['checked']))
- {
- print '<td align="right">';
- if ($obj->opp_percent) print price($obj->opp_percent, 1, '', 1, 0).'%';
- print '</td>';
- if (! $i) $totalarray['nbfield']++;
- }
- // Budget
- if (! empty($arrayfields['p.budget_amount']['checked']))
- {
- print '<td align="right">';
- if ($obj->budget_amount != '')
- {
- print price($obj->budget_amount, 1, '', 1, -1, -1);
- $totalarray['totalbudget'] += $obj->budget_amount;
- }
- print '</td>';
- if (! $i) $totalarray['nbfield']++;
- if (! $i) $totalarray['totalbudgetfield']=$totalarray['nbfield'];
- }
- // Extra fields
- if (is_array($extrafields->attribute_label) && count($extrafields->attribute_label))
- {
- foreach($extrafields->attribute_label as $key => $val)
- {
- if (! empty($arrayfields["ef.".$key]['checked']))
- {
- print '<td';
- $align=$extrafields->getAlignFlag($key);
- if ($align) print ' align="'.$align.'"';
- print '>';
- $tmpkey='options_'.$key;
- print $extrafields->showOutputField($key, $obj->$tmpkey, '', 1);
- print '</td>';
- }
- }
- if (! $i) $totalarray['nbfield']++;
- }
- // Fields from hook
- $parameters=array('arrayfields'=>$arrayfields, 'obj'=>$obj);
- $reshook=$hookmanager->executeHooks('printFieldListValue',$parameters); // Note that $action and $object may have been modified by hook
- print $hookmanager->resPrint;
- // Date creation
- if (! empty($arrayfields['p.datec']['checked']))
- {
- print '<td align="center">';
- print dol_print_date($db->jdate($obj->date_creation), 'dayhour');
- print '</td>';
- if (! $i) $totalarray['nbfield']++;
- }
- // Date modification
- if (! empty($arrayfields['p.tms']['checked']))
- {
- print '<td align="center">';
- print dol_print_date($db->jdate($obj->date_update), 'dayhour');
- print '</td>';
- if (! $i) $totalarray['nbfield']++;
- }
- // Status
- if (! empty($arrayfields['p.fk_statut']['checked']))
- {
- print '<td align="right">'.$object->getLibStatut(5).'</td>';
- if (! $i) $totalarray['nbfield']++;
- }
- // Action column
- print '<td class="nowrap" align="center">';
- if ($massactionbutton || $massaction) // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined
- {
- $selected=0;
- if (in_array($obj->id, $arrayofselected)) $selected=1;
- print '<input id="cb'.$obj->id.'" class="flat checkforselect" type="checkbox" name="toselect[]" value="'.$obj->id.'"'.($selected?' checked="checked"':'').'>';
- }
- print '</td>';
- if (! $i) $totalarray['nbfield']++;
-
- print "</tr>\n";
- }
- $i++;
- }
- // Show total line
- if (isset($totalarray['totaloppfield']) || isset($totalarray['totalbudgetfield']))
- {
- print '<tr class="liste_total">';
- $i=0;
- while ($i < $totalarray['nbfield'])
- {
- $i++;
- if ($i == 1)
- {
- if ($num < $limit && empty($offset)) print '<td align="left">'.$langs->trans("Total").'</td>';
- else print '<td align="left">'.$langs->trans("Totalforthispage").'</td>';
- }
- elseif ($totalarray['totaloppfield'] == $i) print '<td align="right">'.price($totalarray['totalopp']).'</td>';
- elseif ($totalarray['totalbudgetfield'] == $i) print '<td align="right">'.price($totalarray['totalbudget']).'</td>';
- else print '<td></td>';
- }
- print '</tr>';
- }
- $db->free($resql);
- $parameters=array('sql' => $sql);
- $reshook=$hookmanager->executeHooks('printFieldListFooter',$parameters); // Note that $action and $object may have been modified by hook
- print $hookmanager->resPrint;
- print "</table>\n";
- print '</div>';
- print "</form>\n";
- llxFooter();
- $db->close();
|