+ * Copyright (C) 2005-2009 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, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ */
+
+/**
+ * \file htdocs/comm/action/class/actioncomm.class.php
+ * \ingroup commercial
+ * \brief File of class to manage agenda events (actions)
+ * \version $Id: actioncomm.class.php,v 1.21.2.1 2011/01/26 22:33:14 eldy Exp $
+ */
+require_once(DOL_DOCUMENT_ROOT.'/comm/action/class/cactioncomm.class.php');
+require_once(DOL_DOCUMENT_ROOT.'/core/class/commonAgenda.class.php');
+require_once(DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php');
+require_once(DOL_DOCUMENT_ROOT.'/societe/class/societe.class.php');
+
+
+/** \class ActionComm
+ * \brief Class to manage agenda events (actions)
+ */
+class ActionAgenda extends CommonAgenda
+{
+ var $db;
+
+ var $offset = 3600;
+ var $summertime = 1;
+
+ /**
+ * \brief Constructeur
+ * \param db Handler d'acces base de donnee
+ */
+ function ActionAgenda($db)
+ {
+ $this->db = $db;
+ }
+
+
+ /**
+ * Format Actions into events array
+ * @param format 'vcal', 'ical/ics', 'rss'
+ * @param type 'event' or 'journal'
+ * @param cachedelay Do not rebuild file if date older than cachedelay seconds
+ * @param filename Force filename
+ * @param filters Array of filters
+ * @return array empty array if error
+ */
+ function getEvent($id,$options= array()){
+ global $conf,$langs,$dolibarr_main_url_root,$mysoc,$user;
+
+ $actionComm = new ActionComm($this->db);
+ $showbirthday = (isset($options['showbirthday'])) ? $options['showbirthday'] : null;
+ $status = (isset($options['status'])) ? $options['status'] : null;
+ $filtera = (isset($options['userasked'])) ? $options['userasked'] : -1;
+ $filtert = (isset($options['usertodo'])) ? $options['usertodo'] : -1;
+ $filterd = (isset($options['userdone'])) ? $options['userdone'] : -1;
+ $pid = (isset($options['projectid'])) ? $options['projectid'] : 0;
+
+
+ $data = array();
+
+ //Setting dates
+ $start = date('Y-m-d H:i:s',substr($start,0,10));
+ $end = date('Y-m-d H:i:s',substr($end,0,10));
+
+ $sql = ' SELECT a.id,a.label,';
+ $sql.= ' concat(unix_timestamp(datep)) as datep,
+ concat(unix_timestamp(datep2)) as datep2,
+ concat(unix_timestamp(datea)) as datea,
+ concat(unix_timestamp(datea2)) as datea2,';
+ $sql.= ' a.percent,';
+ $sql.= ' a.fk_user_author,a.fk_user_action,a.fk_user_done,';
+ $sql.= ' a.priority, a.fulldayevent, a.location,';
+ $sql.= ' a.fk_soc, a.fk_contact,';
+ $sql.= ' ca.code';
+ $sql.= ' FROM '.MAIN_DB_PREFIX.'actioncomm as a';
+ $sql.= ', '.MAIN_DB_PREFIX.'c_actioncomm as ca';
+ $sql.= ', '.MAIN_DB_PREFIX.'user as u';
+ $sql.= ' WHERE a.fk_action = ca.id';
+ $sql.= ' AND a.fk_user_author = u.rowid';
+ $sql.= " AND a.id = {$id}";
+
+ $resql = $this->db->query($sql);
+ $obj = $this->db->fetch_object($resql);
+
+ $i= 0;
+ $data[$i]['eventid'] = $obj->id;
+
+
+ $data[$i]['readonly'] = 0;
+ $data[$i]['draggable'] = 1;
+ $data[$i]['resizable'] = 1;
+ $data[$i]['multiday'] = 0;
+
+ $data[$i]['eventstart'] = $obj->datep;
+ $data[$i]['eventend'] = $obj->datep2;
+ $data[$i]['eventmessage'] = $obj->note;
+
+ $data[$i]['color'] = "#666677";
+
+ //Formating the title
+ $langs->load("companies");
+ $langs->load("commercial");
+ $langs->load("other");
+
+ $actionComm->fetch($obj->id);
+
+
+
+ $title = "";
+ $data[$i]['type'] = $actionComm->type;
+
+
+ //Getting company name for title
+
+ $langs->load('companies');
+ if($actionComm->societe->id):
+ $company = new Societe($actionComm->db);
+ $company->fetch($actionComm->societe->id);
+
+ $actionComm->societe = $company;
+ $data[$i]['company'] = "
{$actionComm->societe->getNomUrl(0)}
";
+ else:
+ $data[$i]['company'] = "";
+ endif;
+
+ //Getting contact name for title
+
+ if($actionComm->contact->id):
+ $contact = new Contact($actionComm->db);
+ $contact->fetch($actionComm->contact->id,$user);
+ $actionComm->contact = $contact;
+ $data[$i]['contact'] = "
{$actionComm->contact->getNomUrl(0)}
";
+ if ($actionComm->contact->id && $actionComm->type_code == 'AC_TEL'):
+
+ $data[$i]['extraInfo'] = "(".dol_print_phone($actionComm->contact->phone_pro).")";
+ endif;
+ else:
+ $data[$i]['contact'] = '';
+ $data[$i]['extraInfo'] = '';
+ endif;
+
+
+
+ //Getting Project name for title
+ if ($conf->projet->enabled)
+ {
+ if ($actionComm->fk_project)
+ {
+ $project=new Project($actionComm->db);
+ $project->fetch($actionComm->fk_project);
+ $data[$i]['project'] = $project->getNomUrl(0);
+ }
+ }
+
+ $data[$i]['icon'] = $actionComm->getLibStatut(3);
+
+ $data[$i]['eventtitle'] = "{$data[$i]['company']}{$data[$i]['contact']} {$actionComm->label} {$data[$i]['extraInfo']}";
+
+
+
+
+
+
+
+ return $data;
+
+ }
+
+
+ /**
+ * Format Actions into events array
+ * @param format 'vcal', 'ical/ics', 'rss'
+ * @param type 'event' or 'journal'
+ * @param cachedelay Do not rebuild file if date older than cachedelay seconds
+ * @param filename Force filename
+ * @param filters Array of filters
+ * @return array empty array if error
+ */
+ function getEvents($start,$end,$options){
+ global $conf,$langs,$dolibarr_main_url_root,$mysoc,$user;
+
+ $actionComm = new ActionComm($this->db);
+ $showbirthday = (isset($options['showbirthday'])) ? $options['showbirthday'] : null;
+ $status = (isset($options['status'])) ? $options['status'] : null;
+ $filtera = (isset($options['userasked'])) ? $options['userasked'] : -1;
+ $filtert = (isset($options['usertodo'])) ? $options['usertodo'] : -1;
+ $filterd = (isset($options['userdone'])) ? $options['userdone'] : -1;
+ $pid = (isset($options['projectid'])) ? $options['projectid'] : 0;
+
+
+ $data = array();
+
+ //Setting dates
+ $start = date('Y-m-d H:i:s',substr($start,0,10));
+ $end = date('Y-m-d H:i:s',substr($end,0,10));
+
+ $sql = ' SELECT a.id,a.label,';
+ $sql.= ' concat(unix_timestamp(datep)) as datep,
+ concat(unix_timestamp(datep2)) as datep2,
+ concat(unix_timestamp(datea)) as datea,
+ concat(unix_timestamp(datea2)) as datea2,';
+ $sql.= ' a.percent,';
+ $sql.= ' a.fk_user_author,a.fk_user_action,a.fk_user_done,';
+ $sql.= ' a.priority, a.fulldayevent, a.location,';
+ $sql.= ' a.fk_soc, a.fk_contact,';
+ $sql.= ' ca.code';
+ $sql.= ' FROM '.MAIN_DB_PREFIX.'actioncomm as a';
+ $sql.= ', '.MAIN_DB_PREFIX.'c_actioncomm as ca';
+ $sql.= ', '.MAIN_DB_PREFIX.'user as u';
+ $sql.= ' WHERE a.fk_action = ca.id';
+ $sql.= ' AND a.fk_user_author = u.rowid';
+ $sql.= ' AND u.entity in (0,'.$conf->entity.')'; // To limit to entity
+ if ($user->societe_id) $sql.= ' AND a.fk_soc = '.$user->societe_id; // To limit to external user company
+ if ($pid) $sql.=" AND a.fk_project=".addslashes($pid);
+ $sql.= " AND (
+ (datep BETWEEN '{$start}' AND '{$end}')
+ OR (datep2 BETWEEN '{$start}' AND '{$end}')
+ OR (datep < '{$start}' AND datep2 > '{$end}')
+ )";
+ if ($filtera > 0 || $filtert > 0 || $filterd > 0)
+ {
+ $sql.= " AND (";
+ if ($filtera > 0) $sql.= " a.fk_user_author = ".$filtera;
+ if ($filtert > 0) $sql.= ($filtera>0?" OR ":"")." a.fk_user_action = ".$filtert;
+ if ($filterd > 0) $sql.= ($filtera>0||$filtert>0?" OR ":"")." a.fk_user_done = ".$filterd;
+ $sql.= ")";
+ }
+ if ($status == 'done') { $sql.= " AND a.percent = 100"; }
+ if ($status == 'todo') { $sql.= " AND a.percent < 100"; }
+ // Sort on date
+ $sql.= ' ORDER BY datep';
+ $resql = $this->db->query($sql);
+ while ($obj = $this->db->fetch_object($resql)):
+ $data[$i]['eventid'] = $obj->id;
+
+
+ $data[$i]['readonly'] = 0;
+ $data[$i]['draggable'] = 1;
+ $data[$i]['resizable'] = 1;
+ $data[$i]['multiday'] = 0;
+ // + 3600 to be GMT!
+ $data[$i]['eventstart'] = $obj->datep;
+ $data[$i]['eventend'] = $obj->datep2;
+ $data[$i]['eventmessage'] = $obj->note;
+
+ $data[$i]['color'] = "#666677";
+
+ //Formating the title
+ $langs->load("companies");
+ $langs->load("commercial");
+ $langs->load("other");
+
+ $actionComm->fetch($obj->id);
+
+
+
+ $title = "";
+ $data[$i]['type'] = $actionComm->type;
+
+
+ //Getting company name for title
+
+ $langs->load('companies');
+ if($actionComm->societe->id):
+ $company = new Societe($actionComm->db);
+ $company->fetch($actionComm->societe->id);
+
+ $actionComm->societe = $company;
+ $data[$i]['company'] = "
{$actionComm->societe->getNomUrl(0)}
";
+ else:
+ $data[$i]['company'] = "";
+ endif;
+
+ //Getting contact name for title
+
+ if($actionComm->contact->id):
+ $contact = new Contact($actionComm->db);
+ $contact->fetch($actionComm->contact->id,$user);
+ $actionComm->contact = $contact;
+ $data[$i]['contact'] = "
{$actionComm->contact->getNomUrl(0)}
";
+ if ($actionComm->contact->id && $actionComm->type_code == 'AC_TEL'):
+
+ $data[$i]['extraInfo'] = "(".dol_print_phone($actionComm->contact->phone_pro).")";
+ endif;
+ else:
+ $data[$i]['contact'] = '';
+ $data[$i]['extraInfo'] = '';
+ endif;
+
+
+
+ //Getting Project name for title
+ if ($conf->projet->enabled)
+ {
+ if ($actionComm->fk_project)
+ {
+ $project=new Project($actionComm->db);
+ $project->fetch($actionComm->fk_project);
+ $data[$i]['project'] = $project->getNomUrl(0);
+ }
+ }
+
+ $data[$i]['icon'] = $actionComm->getLibStatut(3);
+
+ $data[$i]['eventtitle'] = "{$data[$i]['company']}{$data[$i]['contact']} {$actionComm->label} {$data[$i]['extraInfo']}";
+
+
+
+ $i++;
+ endwhile;
+
+
+ //Getting Birthdays
+
+
+ if($showbirthday):
+ $sql = 'SELECT sp.rowid, sp.name, sp.firstname, unix_timestamp(sp.birthday) as birthday';
+ $sql.= ' FROM '.MAIN_DB_PREFIX.'socpeople as sp';
+ $sql.= ' WHERE (priv=0 OR (priv=1 AND fk_user_creat='.$user->id.'))';
+ $sql.= ' AND sp.entity = '.$conf->entity;
+ $sql.= " AND (birthday BETWEEN '{$start}' AND '{$end}') ";
+ $sql.= ' ORDER BY birthday';
+
+ dol_syslog("comm/action/index.php sql=".$sql, LOG_DEBUG);
+ $resql=$actionComm->db->query($sql);
+ if ($resql)
+ {
+ $num = $actionComm->db->num_rows($resql);
+ $j=0;
+ $i++;
+ while ($j < $num)
+ {
+ $obj = $actionComm->db->fetch_object($resql);
+
+ $data[$i]['eventid'] = "birthday_{$obj->rowid}";
+ $data[$i]['multiday'] = 0;
+ $data[$i]['readonly'] = 1;
+
+ //We set all the birthdays to One hour at 12 am.
+ //and, +3600 to be GMT!
+ $data[$i]['eventstart'] = $obj->birthday + (3600 * 12);
+ $data[$i]['eventend'] = $obj->birthday + (3600 * 13);
+ $data[$i]['type'] = $langs->trans('Birthday');
+ $actionComm->percentage = 100;
+ $data[$i]['icon'] = $actionComm->getLibStatut(3);
+
+
+ $contact->fetch($obj->rowid,$user);
+ $actionComm->contact = $contact;
+ $data[$i]['contact'] = "
\n";
+// Is there an already selected tab?
+if(isset($_GET['selectedTab'])):
+$HTML[] = <<
+ $(function() {
+ var param = '{$_GET['selectedTab']}';
+ $('#tabs').tabs('select', param);
+ });
+
+JS;
- // In loops, tmpday contains day nb in current month (can be zero or negative for days of previous month)
- //var_dump($eventarray);
- //print $tmpday;
- for($iter_week = 0; $iter_week < 6 ; $iter_week++)
- {
- echo "
\n";
- for($iter_day = 0; $iter_day < 7; $iter_day++)
- {
- /* Show days before the beginning of the current month (previous month) */
- if($tmpday <= 0)
- {
- $style='cal_other_month';
- echo '
\n";
+endif;
- // In loops, tmpday contains day nb in current month (can be zero or negative for days of previous month)
- //var_dump($eventarray);
- //print $tmpday;
- echo "
\n";
- for($iter_day = 0; $iter_day < 7; $iter_day++)
- {
- if(($tmpday <= $max_day_in_month))
- {
- // Show days of the current week
- $curtime = dol_mktime (0, 0, 0, $month, $tmpday, $year);
-
- if($curtime == $now)
- $style='cal_today';
- else
- $style='cal_current_month';
-
- echo '
\n";
-}
-else // View by day
-{
- $newparam=$param; // newparam is for birthday links
- $newparam=preg_replace('/action=show_month&?/i','',$newparam);
- $newparam=preg_replace('/action=show_week&?/i','',$newparam);
- $newparam=preg_replace('/day=[0-9][0-9]&?/i','',$newparam);
- $newparam=preg_replace('/month=[0-9][0-9]&?/i','',$newparam);
- $newparam=preg_replace('/year=[0-9]+&?/i','',$newparam);
- // Code to show just one day
- $style='cal_current_month';
- $timestamp=dol_mktime(12,0,0,$month,$day,$year);
- $arraytimestamp=adodb_getdate(dol_mktime(12,0,0,$month,$day,$year));
- echo '
';
-}
+$selectedTab = (isset($_GET['selectedTab'])) ? "&selectedTab={$_GET['selectedTab']}" : '';
+ $HTML[] = "";
+ $HTML[] = "";
-$db->close();
-llxFooter('$Date: 2011/04/17 22:57:12 $ - $Revision: 1.160 $');
-/**
- * Show event of a particular day
- * @param $db Database handler
- * @param $day Day
- * @param $month Month
- * @param $year Year
- * @param $monthshown Current month shown in calendar view
- * @param $style Style to use for this day
- * @param $eventarray Array of events
- * @param $maxPrint Nb of actions to show each day on month view (0 means non limit)
- * @param $maxnbofchar Nb of characters to show for event line
- * @param $newparam Parameters on current URL
- * @param $showinfo Add extended information (used by day view)
- * @param $minheight Minimum height for each event. 60px by default.
- */
-function show_day_events($db, $day, $month, $year, $monthshown, $style, &$eventarray, $maxPrint=0, $maxnbofchar=14, $newparam='', $showinfo=0, $minheight=60)
-{
- global $user, $conf, $langs;
- global $filter, $filtera, $filtert, $filterd, $status;
- global $theme_datacolor;
- global $cachethirdparties, $cachecontacts;
-
- if ($_GET["maxprint"] == 'on') $maxPrint=0; // Force to remove limits
-
- $curtime = dol_mktime (0, 0, 0, $month, $day, $year);
- print '
';
+}
+
+
+/**
+ * Show left menu bar
+ * @param menu_array_before Table of menu entries to show before entries of menu handler
+ * @param helppagename Name of wiki page for help ('' by default).
+ * Syntax is: For a wiki page: EN:EnglishPage|FR:FrenchPage|ES:SpanishPage
+ * For other external page: http://server/url
+ * @param moresearchform Search Form Permanent Supplemental
+ * @param menu_array_after Table of menu entries to show after entries of menu handler
+ * @param leftmenuwithoutmainarea Must be set to 1. 0 by default for backward compatibility with old modules.
+ */
+function left_menu($menu_array_before, $helppagename='', $moresearchform='', $menu_array_after='', $leftmenuwithoutmainarea=0)
+{
+ global $user, $conf, $langs, $db;
+
+ $searchform='';
+ $bookmarks='';
+
+ // print '
'."\n";
+
+ if ($conf->use_javascript_ajax && $conf->global->MAIN_MENU_USE_JQUERY_LAYOUT) print "\n".'
'."\n";
+
+ $menuleft=new MenuLeft($db,$menu_array_before,$menu_array_after);
+ $menuleft->showmenu(); // output menu_array and menu found in database
+
+
+ // Show other forms
+ if ($searchform)
+ {
+ print "\n";
+ print "\n";
+ print '
'."\n";
+ print $searchform;
+ print '
'."\n";
+ print "\n";
+ }
+
+ // More search form
+ if ($moresearchform)
+ {
+ print $moresearchform;
+ }
+
+ // Bookmarks
+ if ($bookmarks)
+ {
+ print "\n";
+ print "\n";
+ print '
'."\n";
+ print $bookmarks;
+ print '
'."\n";
+ print "\n";
+ }
+
+ // Link to Dolibarr wiki pages
+ if ($helppagename && empty($conf->global->MAIN_HELP_DISABLELINK))
+ {
+ $langs->load("help");
+
+ $helpbaseurl='';
+ $helppage='';
+ $mode='';
+
+ // Get helpbaseurl, helppage and mode from helppagename and langs
+ $arrayres=getHelpParamFor($helppagename,$langs);
+ $helpbaseurl=$arrayres['helpbaseurl'];
+ $helppage=$arrayres['helppage'];
+ $mode=$arrayres['mode'];
+
+ // Link to help pages
+ if ($helpbaseurl && $helppage)
+ {
+ print '