* Copyright (C) 2005-2009 Regis Houssin * Copyright (C) 2011 Juanjo Menent * * 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 . * or see http://www.gnu.org/ */ /** * \file htdocs/core/lib/agenda.lib.php * \brief Set of function for the agenda module */ /** * Show filter form in agenda view * * @param Object $form Form object * @param int $canedit Can edit filter fields * @param int $status Status * @param int $year Year * @param int $month Month * @param int $day Day * @param int $showbirthday Show birthday * @param string $filtera Filter on create by user * @param string $filtert Filter on assigned to user * @param string $filterd Filter of done by user * @param int $pid Product id * @param int $socid Third party id * @param array $showextcals Array with list of external calendars, or -1 to show no legend * @param string $actioncode Preselected value of actioncode for filter on type * @return void */ function print_actions_filter($form,$canedit,$status,$year,$month,$day,$showbirthday,$filtera,$filtert,$filterd,$pid,$socid,$showextcals=array(),$actioncode='') { global $conf,$user,$langs,$db; // Filters if ($canedit || ! empty($conf->projet->enabled)) { print '
'; print ''; print ''; print ''; print ''; print ''; print ''; print ''; if ($canedit || ! empty($conf->projet->enabled)) { print ''; // Buttons print ''; // Legend if ($conf->use_javascript_ajax && is_array($showextcals)) { print ''; } print ''; } print '
'; print ''; if ($canedit) { print ''; print ''; print ''; print ''; print ''; print ''; print ''; include_once DOL_DOCUMENT_ROOT.'/core/class/html.formactions.class.php'; $formactions=new FormActions($db); print ''; print ''; } if (! empty($conf->projet->enabled) && $user->rights->projet->lire) { print ''; print ''; } print '
'; print $langs->trans("ActionsAskedBy"); print '  '; print $form->select_dolusers($filtera,'userasked',1,'',!$canedit); print '
'; print $langs->trans("or").' '.$langs->trans("ActionsToDoBy"); print '  '; print $form->select_dolusers($filtert,'usertodo',1,'',!$canedit); print '
'; print $langs->trans("or").' '.$langs->trans("ActionsDoneBy"); print '  '; print $form->select_dolusers($filterd,'userdone',1,'',!$canedit); print '
'; print $langs->trans("Type"); print '  '; print $formactions->select_type_actions($actioncode, "actioncode", '', (empty($conf->global->AGENDA_USE_EVENT_TYPE)?1:0)); print '
'; print $langs->trans("Project").'   '; print ''; select_projects($socid?$socid:-1, $pid, 'projectid', 64); print '
'; print '
'; print img_picto($langs->trans("ViewCal"),'object_calendar','class="hideonsmartphone"').' '; print '
'; print img_picto($langs->trans("ViewWeek"),'object_calendarweek','class="hideonsmartphone"').' '; print '
'; print img_picto($langs->trans("ViewDay"),'object_calendarday','class="hideonsmartphone"').' '; print '
'; print img_picto($langs->trans("ViewList"),'object_list','class="hideonsmartphone"').' '; print '
'; print ''."\n"; print ''; if (! empty($conf->global->MAIN_JS_SWITCH_AGENDA)) { if (count($showextcals) > 0) { print ''; foreach($showextcals as $val) { $htmlname=dol_string_nospecial($val['name']); print ''."\n"; print ''; } } } print ''; print '
'.$langs->trans("LocalAgenda").'
'.$val['name'].'
'.$langs->trans("AgendaShowBirthdayEvents").'
'; print '
'; print '
'; } } /** * Show actions to do array * * @param int $max Max nb of records * @return void */ function show_array_actions_to_do($max=5) { global $langs, $conf, $user, $db, $bc, $socid; $now=dol_now(); include_once DOL_DOCUMENT_ROOT.'/comm/action/class/actioncomm.class.php'; include_once DOL_DOCUMENT_ROOT.'/societe/class/client.class.php'; $sql = "SELECT a.id, a.label, a.datep as dp, a.datep2 as dp2, a.fk_user_author, a.percent,"; $sql.= " c.code, c.libelle,"; $sql.= " s.nom as sname, s.rowid, s.client"; $sql.= " FROM ".MAIN_DB_PREFIX."c_actioncomm as c LEFT JOIN "; $sql.= " ".MAIN_DB_PREFIX."actioncomm as a ON c.id = a.fk_action"; $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s ON a.fk_soc = s.rowid"; if (!$user->rights->societe->client->voir && !$socid) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; $sql.= " WHERE a.entity = ".$conf->entity; $sql.= " AND ((a.percent >= 0 AND a.percent < 100) OR (a.percent = -1 AND a.datep2 > '".$db->idate($now)."'))"; if (!$user->rights->societe->client->voir && !$socid) $sql.= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id; if ($socid) $sql.= " AND s.rowid = ".$socid; $sql.= " ORDER BY a.datep DESC, a.id DESC"; $sql.= $db->plimit($max, 0); $resql=$db->query($sql); if ($resql) { $num = $db->num_rows($resql); print ''; print ''; print ''; $var = true; $i = 0; $staticaction=new ActionComm($db); $customerstatic=new Client($db); while ($i < $num) { $obj = $db->fetch_object($resql); $var=!$var; print ''; $staticaction->type_code=$obj->code; $staticaction->libelle=$obj->label; $staticaction->id=$obj->id; print ''; // print ''; print ''; $datep=$db->jdate($obj->dp); $datep2=$db->jdate($obj->dp2); // Date print '"; // Statut print "\n"; print "\n"; $i++; } print "
'.$langs->trans("LastActionsToDo",$max).''.$langs->trans("FullList").''; print '
'.$staticaction->getNomUrl(1,34).''.dol_trunc($obj->label,22).''; if ($obj->rowid > 0) { $customerstatic->id=$obj->rowid; $customerstatic->name=$obj->sname; $customerstatic->client=$obj->client; print $customerstatic->getNomUrl(1,'',16); } print ''.dol_print_date($datep,'day').' '; $late=0; if ($obj->percent == 0 && $datep && $datep < time()) $late=1; if ($obj->percent == 0 && ! $datep && $datep2 && $datep2 < time()) $late=1; if ($obj->percent > 0 && $obj->percent < 100 && $datep2 && $datep2 < time()) $late=1; if ($obj->percent > 0 && $obj->percent < 100 && ! $datep2 && $datep && $datep < time()) $late=1; if ($late) print img_warning($langs->trans("Late")); print "".$staticaction->LibStatut($obj->percent,3)."

"; $db->free($resql); } else { dol_print_error($db); } } /** * Show last actions array * * @param int $max Max nb of records * @return void */ function show_array_last_actions_done($max=5) { global $langs, $conf, $user, $db, $bc, $socid; $now=dol_now(); $sql = "SELECT a.id, a.percent, a.datep as da, a.datep2 as da2, a.fk_user_author, a.label,"; $sql.= " c.code, c.libelle,"; $sql.= " s.rowid, s.nom as sname, s.client"; $sql.= " FROM ".MAIN_DB_PREFIX."c_actioncomm as c LEFT JOIN "; $sql.= " ".MAIN_DB_PREFIX."actioncomm as a ON c.id = a.fk_action "; $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s ON a.fk_soc = s.rowid"; if (!$user->rights->societe->client->voir && !$socid) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; $sql.= " WHERE a.entity = ".$conf->entity; $sql.= " AND (a.percent >= 100 OR (a.percent = -1 AND a.datep2 <= '".$db->idate($now)."'))"; if (!$user->rights->societe->client->voir && !$socid) $sql.= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id; if ($socid) $sql.= " AND s.rowid = ".$socid; $sql .= " ORDER BY a.datep2 DESC"; $sql .= $db->plimit($max, 0); $resql=$db->query($sql); if ($resql) { $num = $db->num_rows($resql); print ''; print ''; print ''; $var = true; $i = 0; $staticaction=new ActionComm($db); $customerstatic=new Societe($db); while ($i < $num) { $obj = $db->fetch_object($resql); $var=!$var; print ''; $staticaction->type_code=$obj->code; $staticaction->libelle=$obj->label; $staticaction->id=$obj->id; print ''; //print ''; print ''; // Date print '"; // Statut print "\n"; print "\n"; $i++; } // TODO Ajouter rappel pour "il y a des contrats a mettre en service" // TODO Ajouter rappel pour "il y a des contrats qui arrivent a expiration" print "
'.$langs->trans("LastDoneTasks",$max).''.$langs->trans("FullList").''; print '
'.$staticaction->getNomUrl(1,34).''.dol_trunc($obj->label,24).''; if ($obj->rowid > 0) { $customerstatic->id=$obj->rowid; $customerstatic->name=$obj->sname; $customerstatic->client=$obj->client; print $customerstatic->getNomUrl(1,'',24); } print ''.dol_print_date($db->jdate($obj->da2),'day'); print "".$staticaction->LibStatut($obj->percent,3)."

"; $db->free($resql); } else { dol_print_error($db); } } /** * Prepare array with list of tabs * * @return array Array of tabs to shoc */ function agenda_prepare_head() { global $langs, $conf, $user; $h = 0; $head = array(); $head[$h][0] = DOL_URL_ROOT."/admin/agenda.php"; $head[$h][1] = $langs->trans("AutoActions"); $head[$h][2] = 'autoactions'; $h++; $head[$h][0] = DOL_URL_ROOT."/admin/agenda_xcal.php"; $head[$h][1] = $langs->trans("ExportCal"); $head[$h][2] = 'xcal'; $h++; $head[$h][0] = DOL_URL_ROOT."/admin/agenda_extsites.php"; $head[$h][1] = $langs->trans("ExtSites"); $head[$h][2] = 'extsites'; $h++; $head[$h][0] = DOL_URL_ROOT."/admin/agenda_other.php"; $head[$h][1] = $langs->trans("Other"); $head[$h][2] = 'other'; $h++; complete_head_from_modules($conf,$langs,$object,$head,$h,'agenda_admin'); $head[$h][0] = DOL_URL_ROOT."/admin/agenda_extrafields.php"; $head[$h][1] = $langs->trans("ExtraFields"); $head[$h][2] = 'attributes'; $h++; complete_head_from_modules($conf,$langs,$object,$head,$h,'agenda_admin','remove'); return $head; } /** * Prepare array with list of tabs * * @param Object $object Object related to tabs * @return array Array of tabs to shoc */ function actions_prepare_head($object) { global $langs, $conf, $user; $h = 0; $head = array(); $head[$h][0] = DOL_URL_ROOT.'/comm/action/fiche.php?id='.$object->id; $head[$h][1] = $langs->trans("CardAction"); $head[$h][2] = 'card'; $h++; if (! empty($conf->global->AGENDA_USE_SEVERAL_CONTACTS)) { $head[$h][0] = DOL_URL_ROOT.'/comm/action/contact.php?id='.$object->id; $head[$h][1] = $langs->trans("Contacts"); $head[$h][2] = 'contact'; $h++; } $head[$h][0] = DOL_URL_ROOT.'/comm/action/document.php?id='.$object->id; $head[$h][1] = $langs->trans('Documents'); $head[$h][2] = 'documents'; $h++; $head[$h][0] = DOL_URL_ROOT.'/comm/action/info.php?id='.$object->id; $head[$h][1] = $langs->trans('Info'); $head[$h][2] = 'info'; $h++; return $head; } /** * Define head array for tabs of agenda setup pages * * @param string $param Parameters to add to url * @return array Array of head */ function calendars_prepare_head($param) { global $langs, $conf, $user; $h = 0; $head = array(); $head[$h][0] = DOL_URL_ROOT.'/comm/action/index.php'.($param?'?'.$param:''); $head[$h][1] = $langs->trans("Agenda"); $head[$h][2] = 'card'; $h++; $object=new stdClass(); // Show more tabs from modules // Entries must be declared in modules descriptor with line // $this->tabs = array('entity:+tabname:Title:@mymodule:/mymodule/mypage.php?id=__ID__'); to add new tab // $this->tabs = array('entity:-tabname); to remove a tab complete_head_from_modules($conf,$langs,$object,$head,$h,'agenda'); complete_head_from_modules($conf,$langs,$object,$head,$h,'agenda','remove'); return $head; } ?>