Can use a cache for xcal exports

This commit is contained in:
Laurent Destailleur 2009-05-04 20:39:17 +00:00
parent 3705cd5ba0
commit 2e2b3b4be4
2 changed files with 59 additions and 53 deletions

View File

@ -5,7 +5,8 @@ English Dolibarr changelog
For users: For users:
- New: Can export commercial proposals - New: Can export commercial proposals
- New: Can use a cache for xcal exports.
For translators: For translators:
- Update some language files. - Update some language files.

View File

@ -34,11 +34,11 @@ class ActionComm
{ {
var $db; var $db;
var $error; var $error;
var $type_id; var $type_id;
var $type_code; var $type_code;
var $type; var $type;
var $id; var $id;
var $label; var $label;
@ -55,16 +55,16 @@ class ActionComm
//var $durationa = -1; // deprecated //var $durationa = -1; // deprecated
var $priority; var $priority;
var $punctual = 1; var $punctual = 1;
var $usertodo; // Object user that must do action var $usertodo; // Object user that must do action
var $userdone; // Object user that did action var $userdone; // Object user that did action
var $societe; // Company linked to action (optionnal) var $societe; // Company linked to action (optionnal)
var $contact; // Contact linked tot action (optionnal) var $contact; // Contact linked tot action (optionnal)
var $note; var $note;
var $percentage; var $percentage;
/** /**
* \brief Constructeur * \brief Constructeur
* \param db Handler d'acc<EFBFBD>s base de donn<EFBFBD>e * \param db Handler d'acc<EFBFBD>s base de donn<EFBFBD>e
@ -132,8 +132,8 @@ class ActionComm
$this->error="ErrorWrongParameters"; $this->error="ErrorWrongParameters";
return -1; return -1;
} }
$this->db->begin("ActionComm::add"); $this->db->begin("ActionComm::add");
$sql = "INSERT INTO ".MAIN_DB_PREFIX."actioncomm"; $sql = "INSERT INTO ".MAIN_DB_PREFIX."actioncomm";
@ -173,13 +173,13 @@ class ActionComm
$sql.= ($this->propalrowid?$this->propalrowid:"null").","; $sql.= ($this->propalrowid?$this->propalrowid:"null").",";
$sql.= ($this->orderrowid?$this->orderrowid:"null"); $sql.= ($this->orderrowid?$this->orderrowid:"null");
$sql.= ")"; $sql.= ")";
dol_syslog("ActionComm::add sql=".$sql); dol_syslog("ActionComm::add sql=".$sql);
$resql=$this->db->query($sql); $resql=$this->db->query($sql);
if ($resql) if ($resql)
{ {
$this->id = $this->db->last_insert_id(MAIN_DB_PREFIX."actioncomm"); $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX."actioncomm");
if (! $notrigger) if (! $notrigger)
{ {
// Appel des triggers // Appel des triggers
@ -189,7 +189,7 @@ class ActionComm
if ($result < 0) { $error++; $this->errors=$interface->errors; } if ($result < 0) { $error++; $this->errors=$interface->errors; }
// Fin appel triggers // Fin appel triggers
} }
$this->db->commit("ActionComm::add"); $this->db->commit("ActionComm::add");
return $this->id; return $this->id;
} }
@ -199,7 +199,7 @@ class ActionComm
$this->db->rollback("ActionComm::add"); $this->db->rollback("ActionComm::add");
return -1; return -1;
} }
} }
/** /**
@ -209,7 +209,7 @@ class ActionComm
function fetch($id) function fetch($id)
{ {
global $langs; global $langs;
$sql = "SELECT a.id,"; $sql = "SELECT a.id,";
$sql.= " datep,"; $sql.= " datep,";
$sql.= " datep2,"; $sql.= " datep2,";
@ -226,7 +226,7 @@ class ActionComm
$sql.= " c.id as type_id, c.code as type_code, c.libelle"; $sql.= " c.id as type_id, c.code as type_code, c.libelle";
$sql.= " FROM ".MAIN_DB_PREFIX."actioncomm as a, ".MAIN_DB_PREFIX."c_actioncomm as c"; $sql.= " FROM ".MAIN_DB_PREFIX."actioncomm as a, ".MAIN_DB_PREFIX."c_actioncomm as c";
$sql.= " WHERE a.id=".$id." AND a.fk_action=c.id"; $sql.= " WHERE a.id=".$id." AND a.fk_action=c.id";
dol_syslog("ActionComm::fetch sql=".$sql); dol_syslog("ActionComm::fetch sql=".$sql);
$resql=$this->db->query($sql); $resql=$this->db->query($sql);
if ($resql) if ($resql)
@ -234,25 +234,25 @@ class ActionComm
if ($this->db->num_rows($resql)) if ($this->db->num_rows($resql))
{ {
$obj = $this->db->fetch_object($resql); $obj = $this->db->fetch_object($resql);
$this->id = $obj->id; $this->id = $obj->id;
$this->ref = $obj->id; $this->ref = $obj->id;
$this->type_id = $obj->type_id; $this->type_id = $obj->type_id;
$this->type_code = $obj->type_code; $this->type_code = $obj->type_code;
$transcode=$langs->trans("Action".$obj->type_code); $transcode=$langs->trans("Action".$obj->type_code);
$type_libelle=($transcode!="Action".$obj->type_code?$transcode:$obj->libelle); $type_libelle=($transcode!="Action".$obj->type_code?$transcode:$obj->libelle);
$this->type = $type_libelle; $this->type = $type_libelle;
$this->label = $obj->label; $this->label = $obj->label;
$this->datep = $this->db->jdate($obj->datep); $this->datep = $this->db->jdate($obj->datep);
$this->datef = $this->db->jdate($obj->datep2); $this->datef = $this->db->jdate($obj->datep2);
//$this->date = $this->db->jdate($obj->datea); //$this->date = $this->db->jdate($obj->datea);
//$this->dateend = $this->db->jdate($obj->datea2); //$this->dateend = $this->db->jdate($obj->datea2);
$this->datec = $this->db->jdate($obj->datec); $this->datec = $this->db->jdate($obj->datec);
$this->datem = $this->db->jdate($obj->datem); $this->datem = $this->db->jdate($obj->datem);
$this->note =$obj->note; $this->note =$obj->note;
$this->percentage =$obj->percentage; $this->percentage =$obj->percentage;
@ -263,7 +263,7 @@ class ActionComm
$this->userdone->id = $obj->fk_user_done; $this->userdone->id = $obj->fk_user_done;
$this->priority = $obj->priority; $this->priority = $obj->priority;
$this->location = $obj->location; $this->location = $obj->location;
$this->societe->id = $obj->fk_soc; $this->societe->id = $obj->fk_soc;
$this->contact->id = $obj->fk_contact; $this->contact->id = $obj->fk_contact;
@ -287,7 +287,7 @@ class ActionComm
$this->objet_url = img_object($langs->trans("ShowOrder"),'order').' '.'<a href="'. DOL_URL_ROOT . '/commande/fiche.php?id='.$this->fk_commande.'">'.$langs->trans("Order").'</a>'; $this->objet_url = img_object($langs->trans("ShowOrder"),'order').' '.'<a href="'. DOL_URL_ROOT . '/commande/fiche.php?id='.$this->fk_commande.'">'.$langs->trans("Order").'</a>';
$this->objet_url_type = 'order'; $this->objet_url_type = 'order';
} }
} }
$this->db->free($resql); $this->db->free($resql);
return 1; return 1;
@ -304,7 +304,7 @@ class ActionComm
* \return int <0 si ko, >0 si ok * \return int <0 si ko, >0 si ok
*/ */
function delete() function delete()
{ {
$sql = "DELETE FROM ".MAIN_DB_PREFIX."actioncomm"; $sql = "DELETE FROM ".MAIN_DB_PREFIX."actioncomm";
$sql.= " WHERE id=".$this->id; $sql.= " WHERE id=".$this->id;
@ -338,14 +338,14 @@ class ActionComm
if ($this->date && $this->dateend) $this->durationa=($this->dateend - $this->date); if ($this->date && $this->dateend) $this->durationa=($this->dateend - $this->date);
if ($this->datep && $this->datef && $this->datep > $this->datef) $this->datef=$this->datep; if ($this->datep && $this->datef && $this->datep > $this->datef) $this->datef=$this->datep;
if ($this->date && $this->dateend && $this->date > $this->dateend) $this->dateend=$this->date; if ($this->date && $this->dateend && $this->date > $this->dateend) $this->dateend=$this->date;
// Check parameters // Check parameters
if ($this->percentage == 0 && $this->userdone->id > 0) if ($this->percentage == 0 && $this->userdone->id > 0)
{ {
$this->error="ErrorCantSaveADoneUserWithZeroPercentage"; $this->error="ErrorCantSaveADoneUserWithZeroPercentage";
return -1; return -1;
} }
//print 'eeea'.$this->datep.'-'.(strval($this->datep) != '').'-'.$this->db->idate($this->datep); //print 'eeea'.$this->datep.'-'.(strval($this->datep) != '').'-'.$this->db->idate($this->datep);
$sql = "UPDATE ".MAIN_DB_PREFIX."actioncomm "; $sql = "UPDATE ".MAIN_DB_PREFIX."actioncomm ";
$sql.= " SET percent='".$this->percentage."'"; $sql.= " SET percent='".$this->percentage."'";
@ -363,7 +363,7 @@ class ActionComm
$sql.= ", fk_user_action=".($this->usertodo->id > 0 ? "'".$this->usertodo->id."'":"null"); $sql.= ", fk_user_action=".($this->usertodo->id > 0 ? "'".$this->usertodo->id."'":"null");
$sql.= ", fk_user_done=".($this->userdone->id > 0 ? "'".$this->userdone->id."'":"null"); $sql.= ", fk_user_done=".($this->userdone->id > 0 ? "'".$this->userdone->id."'":"null");
$sql.= " WHERE id=".$this->id; $sql.= " WHERE id=".$this->id;
dol_syslog("ActionComm::update sql=".$sql); dol_syslog("ActionComm::update sql=".$sql);
if ($this->db->query($sql)) if ($this->db->query($sql))
{ {
@ -376,8 +376,8 @@ class ActionComm
return -1; return -1;
} }
} }
/** /**
* \brief Charge indicateurs this->nbtodo et this->nbtodolate de tableau de bord * \brief Charge indicateurs this->nbtodo et this->nbtodolate de tableau de bord
* \param user Objet user * \param user Objet user
@ -386,7 +386,7 @@ class ActionComm
function load_board($user) function load_board($user)
{ {
global $conf, $user; global $conf, $user;
$now=gmmktime(); // gmmktime(0,0,0,1,1,1970) -> 0, mktime(0,0,0,1,1,1970) -> -3600; $now=gmmktime(); // gmmktime(0,0,0,1,1,1970) -> 0, mktime(0,0,0,1,1,1970) -> -3600;
$this->nbtodo=$this->nbtodolate=0; $this->nbtodo=$this->nbtodolate=0;
@ -399,7 +399,7 @@ class ActionComm
$sql.= " AND s.entity = ".$conf->entity; $sql.= " AND s.entity = ".$conf->entity;
if ($user->societe_id) $sql.=" AND a.fk_soc = ".$user->societe_id; if ($user->societe_id) $sql.=" AND a.fk_soc = ".$user->societe_id;
if (!$user->rights->societe->client->voir && !$user->societe_id) $sql.= " AND a.fk_soc = sc.fk_soc AND sc.fk_user = " .$user->id; if (!$user->rights->societe->client->voir && !$user->societe_id) $sql.= " AND a.fk_soc = sc.fk_soc AND sc.fk_user = " .$user->id;
$resql=$this->db->query($sql); $resql=$this->db->query($sql);
if ($resql) if ($resql)
{ {
@ -410,7 +410,7 @@ class ActionComm
} }
return 1; return 1;
} }
else else
{ {
$this->error=$this->db->error(); $this->error=$this->db->error();
return -1; return -1;
@ -485,7 +485,7 @@ class ActionComm
function LibStatut($percent,$mode) function LibStatut($percent,$mode)
{ {
global $langs; global $langs;
if ($mode == 0) if ($mode == 0)
{ {
if ($percent==0) return $langs->trans('StatusActionToDo'); if ($percent==0) return $langs->trans('StatusActionToDo');
@ -536,7 +536,7 @@ class ActionComm
function getNomUrl($withpicto=0,$maxlength,$class='',$option='') function getNomUrl($withpicto=0,$maxlength,$class='',$option='')
{ {
global $langs; global $langs;
$result=''; $result='';
if ($option=='birthday') $lien = '<a '.($class?'class="'.$class.'" ':'').'href="'.DOL_URL_ROOT.'/contact/perso.php?id='.$this->id.'">'; if ($option=='birthday') $lien = '<a '.($class?'class="'.$class.'" ':'').'href="'.DOL_URL_ROOT.'/contact/perso.php?id='.$this->id.'">';
else $lien = '<a '.($class?'class="'.$class.'" ':'').'href="'.DOL_URL_ROOT.'/comm/action/fiche.php?id='.$this->id.'">'; else $lien = '<a '.($class?'class="'.$class.'" ':'').'href="'.DOL_URL_ROOT.'/comm/action/fiche.php?id='.$this->id.'">';
@ -552,19 +552,19 @@ class ActionComm
$libelle=$this->libelle; $libelle=$this->libelle;
$libelleshort=dol_trunc($this->libelle,$maxlength); $libelleshort=dol_trunc($this->libelle,$maxlength);
} }
if ($withpicto) $result.=($lien.img_object($langs->trans("ShowAction").': '.$libelle,'task').$lienfin); if ($withpicto) $result.=($lien.img_object($langs->trans("ShowAction").': '.$libelle,'task').$lienfin);
if ($withpicto==1) $result.=' '; if ($withpicto==1) $result.=' ';
$result.=$lien.$libelleshort.$lienfin; $result.=$lien.$libelleshort.$lienfin;
return $result; return $result;
} }
/** /**
* \brief Export events from database into a cal file. * \brief Export events from database into a cal file.
* \param format 'ical' or 'vcal' * \param format 'ical' or 'vcal'
* \param type 'event' or 'journal' * \param type 'event' or 'journal'
* \param cachedelay Do not rebuild file if date older than cachedelay seconds * \param cachedelay Do not rebuild file if date older than cachedelay seconds
* \param filename Force filename * \param filename Force filename
* \param filters Array of filters * \param filters Array of filters
* \return int <0 if error, nb of events in new file if ok * \return int <0 if error, nb of events in new file if ok
@ -587,24 +587,29 @@ class ActionComm
if ($format == 'ical') $extension='ics'; if ($format == 'ical') $extension='ics';
$filename=$format.'.'.$extension; $filename=$format.'.'.$extension;
} }
$result=create_exdir($conf->agenda->dir_temp); $result=create_exdir($conf->agenda->dir_temp);
$outputfile=$conf->agenda->dir_temp.'/'.$filename; $outputfile=$conf->agenda->dir_temp.'/'.$filename;
$result=0; $result=0;
$buildfile=true; $buildfile=true;
$login='';$logina='';$logind='';$logint=''; $login='';$logina='';$logind='';$logint='';
if ($cachedelay) if ($cachedelay)
{ {
// \TODO Check cache $now = gmmktime();
if (filemtime($outputfile) > ($now - $cachedelay))
{
dol_syslog("ActionComm::build_exportfile file ".$outputfile." not older than now - cachedelay (".$now." - ".$cachedelay."). Build is canceled");
$buildfile = false;
}
} }
if ($buildfile) if ($buildfile)
{ {
// Build event array // Build event array
$eventarray=array(); $eventarray=array();
$sql = "SELECT a.id,"; $sql = "SELECT a.id,";
$sql.= " a.datep,"; $sql.= " a.datep,";
$sql.= " a.datep2,"; $sql.= " a.datep2,";
@ -625,7 +630,7 @@ class ActionComm
{ {
if ($key == 'year') $sql.=' AND '; if ($key == 'year') $sql.=' AND ';
if ($key == 'idaction') $sql.=' AND a.id='.$value; if ($key == 'idaction') $sql.=' AND a.id='.$value;
if ($key == 'login') if ($key == 'login')
{ {
$login=$value; $login=$value;
$userforfilter=new User($this->db); $userforfilter=new User($this->db);
@ -636,21 +641,21 @@ class ActionComm
$sql.= " OR a.fk_user_done = ".$userforfilter->id; $sql.= " OR a.fk_user_done = ".$userforfilter->id;
$sql.= ")"; $sql.= ")";
} }
if ($key == 'logina') if ($key == 'logina')
{ {
$logina=$value; $logina=$value;
$userforfilter=new User($this->db); $userforfilter=new User($this->db);
$userforfilter->fetch($value); $userforfilter->fetch($value);
$sql.= " AND a.fk_user_author = ".$userforfilter->id; $sql.= " AND a.fk_user_author = ".$userforfilter->id;
} }
if ($key == 'logint') if ($key == 'logint')
{ {
$logint=$value; $logint=$value;
$userforfilter=new User($this->db); $userforfilter=new User($this->db);
$userforfilter->fetch($value); $userforfilter->fetch($value);
$sql.= " AND a.fk_user_action = ".$userforfilter->id; $sql.= " AND a.fk_user_action = ".$userforfilter->id;
} }
if ($key == 'logind') if ($key == 'logind')
{ {
$logind=$value; $logind=$value;
$userforfilter=new User($this->db); $userforfilter=new User($this->db);
@ -670,7 +675,7 @@ class ActionComm
while ($obj=$this->db->fetch_object($resql)) while ($obj=$this->db->fetch_object($resql))
{ {
$qualified=true; $qualified=true;
// 'eid','startdate','duration','enddate','title','summary','category','email','url','desc','author' // 'eid','startdate','duration','enddate','title','summary','category','email','url','desc','author'
$event=array(); $event=array();
$event['uid']='dolibarragenda-'.$this->db->database_name.'-'.$obj->id."@".$_SERVER["SERVER_NAME"]; $event['uid']='dolibarragenda-'.$this->db->database_name.'-'.$obj->id."@".$_SERVER["SERVER_NAME"];
@ -696,7 +701,7 @@ class ActionComm
if (! eregi('\/$',$url)) $url.='/'; if (! eregi('\/$',$url)) $url.='/';
$url.='comm/action/fiche.php?id='.$obj->id; $url.='comm/action/fiche.php?id='.$obj->id;
$event['url']=$url; $event['url']=$url;
if ($qualified && $datestart) if ($qualified && $datestart)
{ {
$eventarray[$datestart]=$event; $eventarray[$datestart]=$event;
@ -709,9 +714,9 @@ class ActionComm
dol_syslog("ActionComm::build_exportfile ".$this->db->lasterror(), LOG_ERR); dol_syslog("ActionComm::build_exportfile ".$this->db->lasterror(), LOG_ERR);
return -1; return -1;
} }
$langs->load("agenda"); $langs->load("agenda");
// Define title and desc // Define title and desc
$more=''; $more='';
if ($login) $more=$langs->transnoentities("User").' '.$langs->convToOutputCharset($login); if ($login) $more=$langs->transnoentities("User").' '.$langs->convToOutputCharset($login);
@ -719,7 +724,7 @@ class ActionComm
if ($logint) $more=$langs->transnoentities("ActionsToDoBy").' '.$langs->convToOutputCharset($logint); if ($logint) $more=$langs->transnoentities("ActionsToDoBy").' '.$langs->convToOutputCharset($logint);
if ($logind) $more=$langs->transnoentities("ActionsDoneBy").' '.$langs->convToOutputCharset($logind); if ($logind) $more=$langs->transnoentities("ActionsDoneBy").' '.$langs->convToOutputCharset($logind);
if ($more) if ($more)
{ {
$title=$langs->convToOutputCharset('Dolibarr actions - ').$more; $title=$langs->convToOutputCharset('Dolibarr actions - ').$more;
$desc=$more.$langs->convToOutputCharset(' - built by Dolibarr'); $desc=$more.$langs->convToOutputCharset(' - built by Dolibarr');
} }
@ -728,13 +733,13 @@ class ActionComm
$title=$langs->convToOutputCharset('Dolibarr actions'); $title=$langs->convToOutputCharset('Dolibarr actions');
$desc=$langs->transnoentities('ListOfActions').$langs->convToOutputCharset(' - built by Dolibarr'); $desc=$langs->transnoentities('ListOfActions').$langs->convToOutputCharset(' - built by Dolibarr');
} }
// Write file // Write file
if ($format == 'ical') $result=build_calfile($format,$title,$desc,$eventarray,$outputfile); if ($format == 'ical') $result=build_calfile($format,$title,$desc,$eventarray,$outputfile);
if ($format == 'vcal') $result=build_calfile($format,$title,$desc,$eventarray,$outputfile); if ($format == 'vcal') $result=build_calfile($format,$title,$desc,$eventarray,$outputfile);
if ($format == 'rss') $result=build_rssfile($format,$title,$desc,$eventarray,$outputfile); if ($format == 'rss') $result=build_rssfile($format,$title,$desc,$eventarray,$outputfile);
} }
return $result; return $result;
} }