/class.xmodcalendar.inc
PHP | 2827 lines | 2613 code | 117 blank | 97 comment | 227 complexity | a97078b6b85fa0f0cbf8d4064248fd95 MD5 | raw file
Possible License(s): LGPL-2.0, LGPL-2.1, GPL-3.0, Apache-2.0, BSD-3-Clause
Large files files are truncated, but you can click here to view the full file
- <?php
- /// Module de gestion des Agenda
- class XModCalendar extends XModule {
- public $prefs; /* Preferences du module */
- public $day;
- public $month;
- public $year;
- public $week;
- public $date;
- public $paques;
- public $ascencion;
- public $pentecote;
- public $request; /* tableau avec les elements de base pour les requetes sur les evenements */
- public $diary; /* resulset de l'agenda selectionne */
- public $group_of_diary;
- public $tcolors='#a3d0f2,#ef6464,#77c26d,#eb815d,#a794f0,#d5c128,#b4aeb0,#83d9ff,#e8879e,#98e057,#f68f3d,#c5a3e4,#e8da3f,#c9c1cd,#9fdbf3,#f19999,#c1ec4b,#efaf6a,#b3b8ef,#f4f078,#bac9cd';
- public $synchro=false; /* Indique si on est sur une synchronisation ou non (par defaut non) */
- public $sendToUser=false; /* Indique si les mails doivent etre envoyes a l'utilisateur loge */
- public $defcal='';
- public $categories;
- public $display_begin;
- public $display_end;
- public $cal_content;
- public $tagenda; /* liste des agendas connus */
- public $tevt; /* evenements */
- public $tlinks; /* liens entre agendas et evenements */
- public $tcatevt; /* categories d'evenements */
- public $tcatagenda; /* categories d'agendas */
- public $tplan; /* liste des planifications en cours de traitement */
- public $tplaninv; /* liste des invités pour les planification */
- public $tplandates; /* liste des dates pour les planification */
- public $xsetevt; /* xset sur la table de evenement */
- public $catperso; /* oid de la categorie d'agenda perso */
- /* ensemble des variables a passer aux templates (_fieldlist : liste des champs de base de l'agenda) */
- public $bloc=array('_fieldlist'=>array('text','begin','end','allday','cat','place','descr','visib','repet','end_rep','except','recall',
- 'isrecal','attext','rrule','UIDI','KOIDD','KOIDS','KOIDIT'));
- function __construct($ar=NULL) {
- parent::__construct($ar);
- XLabels::loadLabels('xmodcalendar');
- $this->colors=explode(',',$this->tcolors);
- $p=new XParam($ar,array());
- $oid=$p->get('oid');
- $now=$p->get('now');
-
- // Dans la cas du traitement d'une planification, on ne construit pas les infos de l'agenda
- if(Kernel::getTable($oid)==$this->tplaninv) return;
- // Recupere la date a visualiser
- if(isset($_REQUEST['now']) || !empty($now)){
- $this->day=date('j');
- $this->month=date('n');
- $this->year=date('Y');
- }else{
- $this->day=$p->get('day');
- $this->month=ltrim($p->get('month'),'0');
- $this->year=ltrim($p->get('year'),'0');
- }
- $this->date=$this->year.'-'.str_pad($this->month,2,'0',STR_PAD_LEFT).'-'.str_pad($this->day,2,'0',STR_PAD_LEFT);
- $this->bloc['day']=$this->day;
- $this->bloc['month']=$this->month;
- $this->bloc['year']=$this->year;
- // S'authentifie a la connexion pour une synchro par PUT
- if(!empty($_REQUEST['_function'])) $f=$_REQUEST['_function'];
- elseif(!empty($_REQUEST['function'])) $f=$_REQUEST['function'];
- if($f=='synchro'){
- if(empty($_REQUEST['oid'])){
- die('nok');
- }
- if(!XUser::authentified()){
- $sess=new XSession();
- $ret=$sess->procTmpAuth();
- if(!$ret){
- header("HTTP/1.0 401 Authorization Required");
- die('Authorization Required');
- }
- }
- }
- $this->xsetevt=XDataSource::objectFactoryHelper8('BCLASS=XDSTable&SPECS='.$this->tevt);
- $this->xsetevt->desc['begin']->display_format=$this->xsetevt->desc['end']->display_format='H:M';
-
- // Si pas d'utilisateur, ca ne sert à rien de continuer car on est dans un upgrade
- if(empty($GLOBALS['XUSER'])) return;
- // Recupere les preferences, l'agenda courant
- $this->getPrefs();
- if(empty($this->defcal) && !empty($this->prefs['defaultcal'])) $this->defcal=$this->prefs['defaultcal'];
- if(empty($oid)){
- if(!empty($this->prefs['defaultcal'])) $oid=$this->prefs['defaultcal'];
- else $oid=$this->defcal;
- }
-
- // Dans le cas ou il n'y a ni oid ni agenda par defaut on prend le premier des agendas autorises
- if(empty($oid)) {
- $oids=$this->getAuthorizedDiaries();
- if(!empty($oids)) {
- reset($oids);
- $oid=current($oids);
- }
- }
- // Vue par défaut
- if(!empty($this->prefs['defview'])) $this->defview=$this->prefs['defview'];
-
- // Verifications de securite
- $params_to_check=array('day','week','year','month');
- foreach($params_to_check as $t) {
- $t1=$p->get($t);
- if(!empty($t1) && !is_numeric($t1)) {
- $this->$t=$t1;
- }
- }
- if($oid!='') {
- if(!strpos($oid,' ')) {
-
- }
- }
- if($p->get('koid')!='') {
- if(!strpos($p->get('koid'),' ')) {
-
- }
- }
- // Recupere les renseignements sur les categories d'evenement
- $rs=selectQuery('SELECT * FROM '.$this->tcatevt.' WHERE commun=1 OR OWN="'.XUser::get_current_user_uid().'" ORDER BY name');
- while($rs && $cat=$rs->fetch()) $this->categories[$cat['KOID']]=array('name'=>$cat['name'],'color'=>@$cat['color']);
- $this->bloc['categories']=$this->categories;
- $this->initialize($oid);
- date_default_timezone_set($this->diary['tz']);
- }
-
- /// Initialise le module pour un agenda donné : Recupere les données de l'agenda et prepare les composants de base pour les requetes SQL
- function initialize($oid){
- $rs=selectQuery('SELECT * FROM '.$this->tagenda.' where KOID="'.$oid.'"');
- if($this->diary=$rs->fetch()){
- if(empty($this->diary['defvisi']) || !in_array($this->diary['defvisi'],array('PU','OC','PR'))) $this->diary['defvisi']='PR';
- $this->bloc['diary']=&$this->diary;
- $ar=explode(':',$this->diary['begin']);
- $this->diary['beginnum']=$ar[0]+$ar[1]/60;
- $ar=explode(':',$this->diary['end']);
- $this->diary['endnum']=$ar[0]+$ar[1]/60;
- if($this->diary['cons']==1) {
- $ar=explode('||',$this->diary['agcons']);
- $br=array($this->diary['KOID']);
- foreach($ar as $i=>$oid){
- if(!empty($oid)){
- $br[]=$oid;
- $this->bloc['diariesprop'][$oid]['color']=$this->colors[$i];
- }
- }
- $this->bloc['group_of_diary']=$this->group_of_diary=true;
- } else {
- $this->diary['rwsecure']=$this->secure($this->diary['KOID'],'saveEvt');
- $this->bloc['diariesprop'][$this->diary['KOID']]['rwsecure']=$this->diary['rwsecure'];
- $this->bloc['group_of_diary']=$this->group_of_diary=false;
- $this->bloc['diariesprop'][$this->diary['KOID']]['color']=$this->colors[0];
- $br=array($this->diary['KOID']);
- }
- $all=$br;
- // Ajoute les consolidations
- $cons=$this->getDiariesForConsolidation();
- if(!empty($cons['active'])){
- $list=array_keys($cons['active']);
- $br=array_merge($br,$list);
- }
- if(!empty($cons['list'])){
- $all=array_merge($all,array_keys($cons['list']));
- }
- // Récupère les noms des differentes consolidations
- $rs=selectQuery('select KOID,name from '.$this->tagenda.' where KOID in ("'.implode('","',$all).'")');
- while($rs && ($ors=$rs->fetch())){
- $this->bloc['diariesprop'][$ors['KOID']]['name']=$ors['name'];
- }
- foreach($cons['list'] as $oid=>$foo){
- $this->bloc['diariesprop'][$oid]['color']=$foo['color'];
- if(is_numeric($oid)){
- $mod=&XModule::objectfactory(array('moid'=>$oid,'tplentry'=>TZR_RETURN_DATA));
- if(!is_object($mod)) continue;
- $this->bloc['diariesprop'][$oid]['name']=$mod->modulename;
- $this->bloc['diariesprop'][$oid]['url']=$mod->XCalGetUrl('display');
- $this->bloc['diariesprop'][$oid]['generalurl']=$mod->XCalGetUrl('browse');
- }
- }
- // Supprime les consolidations erronées (qui n'ont pas de nom) et met à jour le cache
- foreach($cons['list'] as $oid=>&$foo){
- if(empty($this->bloc['diariesprop'][$oid]['name'])){
- unset($cons['list'][$oid]);
- unset($cons['active'][$oid]);
- }
- }
- $this->bloc['consolidation']=$this->cache['consolidations']=$cons;
- $rw=$this->getAuthorizedDiaries('rw');
- $this->bloc['privatediaries']=$rw;
- // Champs dans les request (+ KOID et LANG qui ne sont pas dans le tableau) (ordre important dans un union en sql)
- $this->request['selectedfields']=array('begin','end','allday','visib','DOWNER','DNAME','DKOID','cat');
- // Requete
- $this->request['select']='select '.$this->tevt.'.KOID,'.$this->tevt.'.LANG,'.$this->tevt.'.begin,'.$this->tevt.'.end,'.
- $this->tevt.'.allday,'.$this->tevt.'.visib,'.$this->tagenda.'.OWN as DOWNER,'.$this->tagenda.'.name as DNAME,'.
- $this->tagenda.'.KOID as DKOID,'.$this->tevt.'.cat,"'.$this->_moid.'" as MOID';
- $this->request['from']='from '.$this->tevt.','.$this->tlinks.','.$this->tagenda;
- $this->request['where']='where '.$this->tagenda.'.KOID in ("'.implode('","',$br).'") AND '.
- $this->tagenda.'.KOID='.$this->tlinks.'.KOIDD AND '.$this->tevt.'.KOID='.$this->tlinks.'.KOIDE AND '.
- '('.$this->tagenda.'.KOID in ("'.implode('","',$rw).'") OR '.$this->tevt.'.visib!="PR")';
- }
- }
- /// Recupere les evenements en rappel et envoie un mail de rappel
- function _daemon($period) {
- $rs=selectQuery('select '.$this->tevt.'.*, '.$this->tagenda.'.tz, USERS.email '.
- 'from '.$this->tevt.','.$this->tlinks.','.$this->tagenda.',USERS '.
- 'where '.$this->tagenda.'.KOID='.$this->tlinks.'.KOIDD AND '.$this->tlinks.'.KOIDE='.$this->tevt.'.KOID AND '.
- 'USERS.KOID='.$this->tagenda.'.OWN AND '.
- 'UNIX_TIMESTAMP('.$this->tevt.'.begin)<=UNIX_TIMESTAMP("'.gmdate('Y-m-d H:i:s',time()).'")+'.$this->tevt.'.recall*60'.
- ' AND recall!=0');
- while($rs && $ev=$rs->fetch()) {
- date_default_timezone_set($ev['tz']);
- $rs2=&updateQuery('update '.$this->tevt.' set recall=0 where KOID="'.$ev['KOID'].'"');
- $mail=new XMail();
- $mail->_moid=$this->_moid;
- $mail->FromName='';
- $mail->From='noreply@xsalto.com';
- $mail->Subject='Rappel évènement';
- $mail->IsHTML(true);
- $mail->Body = 'Du '.date('d/m/Y H:i',strtotime($ev['begin'].' GMT')).' au '.
- date('d/m/Y H:i',strtotime($ev['end'].' GMT')).' : '.$ev['text'];
- $mail->AddAddress($ev['email']);
- $mail->Send();
- }
- return true;
- }
- /// suppression du module
- function delete($ar=NULL) {
- parent::delete($ar);
- }
- /// initialisation des proprietes
- public function initOptions() {
- parent::initOptions();
- $this->_options->setOpt('Vue par defaut', 'defview', 'list',
- array('values'=>array('displayDay', 'displayWeek', 'displayMonth', 'displayYear'),
- 'labels'=>array('Jour', 'Semaine','Mois', 'Annee')));
- $this->_options->setOpt('Alerte mail a la personne connectee','sendToUser', 'boolean', NULL ,false);
- $this->_options->setOpt('Agenda : table des agendas', 'tagenda', 'table');
- $this->_options->setOpt('Agenda : table des évènements', 'tevt', 'table');
- $this->_options->setOpt('Agenda : table des liens', 'tlinks', 'table');
- $this->_options->setOpt('Agenda : table des catégories d\'evenements', 'tcatevt', 'table');
- $this->_options->setOpt('Agenda : table des catégories d\'agendas', 'tcatagenda', 'table');
- $this->_options->setOpt('Planification : table des planifications', 'tplan', 'table');
- $this->_options->setOpt('Planification : table des paticipants', 'tplaninv', 'table');
- $this->_options->setOpt('Planification : table des dates', 'tplandates', 'table');
- $p1=XModule::findParam($this->_moid);
- $this->_options->setOpt('Categorie "agenda personnel"', 'catperso', 'object', array('table'=>$p1['MPARAM']['tcatagenda']));
- $this->_options->setOpt('Couleurs des agendas', 'tcolors', 'text',array('rows'=>5,'cols'=>50));
- }
- /// securite des fonctions accessibles par le web
- function secGroups($function, $group=NULL) {
- $g=array('index' =>array('ro','rw','rwv','admin'),
- 'displayDay' =>array('ro','rw','rwv','admin'),
- 'displayWeek' =>array('ro','rw','rwv','admin'),
- 'displayMonth' =>array('ro','rw','rwv','admin'),
- 'displayYear' =>array('ro','rw','rwv','admin'),
- 'addEvt' =>array('ro','rw','rwv','admin'),
- 'insertPlanif' =>array('rwv','admin'),
- 'procInsertPlanif' =>array('rwv','admin'),
- 'confirmPlanif' =>array('none','ro','rw','rwv','admin'),
- 'procConfirmPlanif' =>array('none','ro','rw','rwv','admin'),
- 'browsePlanif' =>array('rwv','admin'),
- 'displayPlanif' =>array('rwv','admin'),
- 'editPlanif' =>array('rwv','admin'),
- 'procEditPlanif' =>array('rwv','admin'),
- 'delPlanif' =>array('rwv','admin'),
- 'getEmails' =>array('ro','rw','rwv','admin'),
- 'saveEvt' =>array('rwv','admin'),
- 'saveFastEvt' =>array('rwv','admin'),
- 'editDiary' =>array('ro','rw','rwv','admin'),
- 'saveDiary' =>array('rwv','admin'),
- 'delEvt' =>array('rwv','admin'),
- 'exportEvt' =>array('ro','rw','rwv','admin'),
- 'saveExport' =>array('ro','rw','rwv','admin'),
- 'importEvt' =>array('rwv','admin'),
- 'saveImportTable' =>array('rwv','admin'),
- 'synchro' =>array('ro','rw','rwv','admin'),
- 'setDefault' =>array('ro','rw','rwv','admin'),
- 'addConsolidation' =>array('ro','rw','rwv','admin'),
- 'updateConsolidation' =>array('ro','rw','rwv','admin'),
- 'paramsConsolidation' =>array('ro','rw','rwv','admin'),
- 'ajaxEdit' =>array('rwv','admin'),
- 'ajaxDel' =>array('rwv','admin')
- );
- if(isset($g[$function])) {
- if(!empty($group)) return in_array($group, $g[$function]);
- return $g[$function];
- }
- return parent::secGroups($function,$group);
- }
- function ajaxEdit($ar=NULL){
- $p=new XParam($ar,NULL);
- $oid=$p->get('koid');
- $ar['oid']=$oid;
- $daybegin=$p->get('daybegin');
- $dayend=$p->get('dayend');
- $allday=$p->get('allday');
- if(!$allday) $ar['options']['begin']['togmt']=$ar['options']['end']['togmt']=true;
- if(!empty($oid)){
- $ors=selectQueryGetOne('select begin,KOIDS from '.$this->tevt.' where KOID="'.$oid.'" LIMIT 1');
- // L'evenement fait parti d"une repetition et n'est pas l'evenement de base : on ajoute une exception à l'evenement de base et on le rend independant
- if(!empty($ors['KOIDS'])){
- $ar['KOIDS']='';
- $date=substr($ors['begin'],0,10);
- $ors2=selectQueryGetOne('select except from '.$this->tevt.' where KOID="'.$ors['KOIDS'].'" LIMIT 1');
- if(empty($ors2['except'])) $except=$date;
- else $except=$ors2['except'].';'.$date;
- updateQuery('update '.$this->tevt.' set UPD=UPD, except="'.$except.'" where KOID="'.$ors['KOIDS'].'"');
- }else{
- $ors2=selectQueryGetOne('select KOID from '.$this->tevt.' where KOIDS="'.$oid.'" order by begin limit 1');
- // L'evenement fait parti d"une repetition et est pas l'evenement de base : la premiere repet devient l'evenement de base
- if(!empty($ors2)){
- updateQuery('update '.$this->tevt.' set KOIDS="'.$ors2['KOID'].'" where KOIDS="'.$oid.'"');
- updateQuery('update '.$this->tevt.' set KOIDS=NULL where KOID="'.$ors2['KOID'].'"');
- }
- }
- $ret=$this->xsetevt->procEdit($ar);
- }else{
- $text=$p->get('text');
- $begin=$p->get('begin');
- $end=$p->get('end');
- $ar1=array('text'=>$text,
- 'begindate'=>$begin['date'],
- 'beginhour'=>$begin['hour'],
- 'enddate'=>$end['date'],
- 'endhour'=>$end['hour'],
- 'visib'=>'PU',
- 'repet'=>'NO',
- 'recalltime'=>'',
- 'recalltype'=>'1',
- 'tplentry'=>TZR_RETURN_DATA);
- if($allday) $ar1['allday']=$ar1['allday_HID']=1;
- $ret=$this->saveEvt($ar1);
- $oid=$ret['oid'];
- }
- $ors=selectQueryGetAll($this->request['select'].' '.$this->request['from'].' where '.$this->tagenda.'.KOID='.$this->tlinks.'.KOIDD AND '.
- $this->tevt.'.KOID='.$this->tlinks.'.KOIDE AND '.$this->tevt.'.KOID="'.$oid.'" LIMIT 1');
- $this->convertEventTime($ors[0]);
- $this->cutEvents($ors,$daybegin,$dayend);
- $ors=$ors[0];
- die(json_encode(array('_isod'=>substr($ors['begin'],0,10),'_bd'=>$ors['_begindate'],'_bh'=>$ors['_beginhour'],
- '_ed'=>$ors['_enddate'],'_eh'=>$ors['_endhour'],
- '_obd'=>$ors['_cbegindate'],'_obh'=>$ors['_cbeginhour'],
- '_oed'=>$ors['_cenddate'],'_oeh'=>$ors['_cendhour'],
- 'oid'=>$ors['oid'],'text'=>$ors['otext']->html,'descr'=>$ors['odescr']->html,'place'=>$ors['oplace']->html,
- 'allday'=>($ors['allday']==1?'1':'0'),'color'=>$this->bloc['diariesprop'][$this->diary['KOID']]['color'],
- 'rw'=>1,'cat'=>$this->bloc['categories'][$ors['cat']]['color'],'url'=>$ors['_url'],'dname'=>$ors['DNAME']
- )));
- }
- function ajaxDel($ar=NULL){
- $ret=$this->delEvt($ar);
- if($ret) die(json_encode("ok"));
- else die(json_encode("nok"));
- }
- /// Action principale du menu
- public function getMainAction(){
- return $GLOBALS['TZR_SESSION_MANAGER']::complete_self().'moid='.$this->_moid.'&function='.$this->defview.'&oid='.$this->diary['KOID'].
- '&tplentry=br&template=xmodcalendar/'.$this->defview.'.html&now=1';
- }
-
- function secure($oid,$func,$user=NULL,$lang=TZR_DEFAULT_LANG){
- $evoid=@$_REQUEST['koid'];
- if($func=='addEvt' && empty($evoid) && !parent::secure($oid,'saveEvt',$user,$lang)){
- return false;
- }
- if($func=='saveEvt' && !empty($evoid)){
- $cnt=countSelectQuery('select COUNT(KOID) from '.$this->tevt.' where KOID="'.$evoid.'" and KOIDD="'.$this->diary['KOID'].'"');
- if($cnt==0) return false;
- }
- $table=Kernel::getTable($oid);
- if($table==$this->tplaninv){
- $ors=selectQueryGetOne('select who from '.$this->tplaninv.' where KOID="'.$oid.'" LIMIT 1');
- $who=$ors['who'];
- if(Kernel::getTable($who)==$this->tagenda){
- $ors=selectQueryGetOne('select OWN from '.$this->tagenda.' where KOID="'.$who.'" LIMIT 1');
- $who=$ors['OWN'];
- }
- if($who==XUser::get_current_user_uid()) return true;
- else return false;
- }
- return parent::secure($oid,$func,$user,$lang);
- }
- /// Recupere tous les notes et evenements du jour
- function &getTasklet(){
- $txt='';
- $date=date('Y-m-d');
- $display_begin_gmt=gmdate('Y-m-d H:i:s',strtotime($date.' 00:00:00'));
- $display_end_gmt=gmdate('Y-m-d H:i:s',strtotime($date.' 23:59:00'));
- $rs=$this->getAlls($display_begin_gmt,$display_end_gmt,$date.' 00:00:00',$date.' 23:59:59',
- 'where '.$this->tagenda.'.KOID='.$this->tlinks.'.KOIDD AND '.$this->tlinks.'.KOIDE='.$this->tevt.'.KOID AND '.
- '('.$this->tagenda.'.OWN="'.XUser::get_current_user_uid().'" OR '.$this->tagenda.'.KOID="'.$this->defcal.'")');
- while($rs && ($ors=$rs->fetch())){
- $this->getCompleteEvent($ors);
- $date=explode('-',$ors['begin']);
- $url=$GLOBALS['TZR_SESSION_MANAGER']::complete_self().'&oid='.$ors['DKOID'].'&moid='.$this->_moid.'&_function=displayDay&'.
- 'template=xmodcalendar/displayDay.html&tplentry=br&day='.substr($date[2],0,2).'&month='.$date[1].'&year='.$date[0];
- $txt.='<p><a href="'.$url.'">'.$ors['text'].'</a> se déroule aujourd\'hui';
- if($ors['allday']!=1){
- $txt.=' (de '.date('H\hi',strtotime($ors['begin']. 'GMT')).' à '.date('H\hi',strtotime($ors['end'].' GMT')).')';
- }
- $txt.='.</p>';
- }
- return $txt;
- }
- function getShortTasklet(){
- return $this->getTasklet();
- }
- /// synchronisation des agendas
- function synchro($ar=NULL){
- $p=new XParam($ar,array());
- $this->synchro=true;
- $rw=$this->secure($p->get('oid'), 'importEvt');
- if($_SERVER["REQUEST_METHOD"]=='PROPFIND'){
- die();
- }
- if(!empty($_REQUEST['phpputdata'])) {
- if($rw){
- $_FILES['filetoimp']['tmp_name']=$_REQUEST['phpputdata'];
- $_FILES['filetoimp']['size']=filesize($filename);
- $_FILES['filetoimp']['name']='Importics.ics';
- $this->importEvt($ar);
- }else{
- header("HTTP/1.0 404 Not Found");
- }
- }else{
- $ar['period']='all';
- $this->saveExport($ar);
- }
- $id=session_id();
- session_destroy();
- die();
- }
- function index($ar=NULL) {
- $p=new XParam($ar,array());
- $tplentry=$p->get('tplentry');
- $r=array();
- if($tplentry=='*return*') {
- return $r;
- } else {
- $this->setTplCommons();
- XShell::toScreen1($tplentry,$r);
- }
- }
- /// cette fonction est appliquee pour afficher l'ensemble des methodes de ce module
- protected function _actionlist(&$my=NULL) {
- if(!$this->day) $date='now';
- else $date='day='.$this->day.'&month='.$this->month.'&year='.$this->year;
- $uniqid=XShell::uniqid();
- $moid=$this->_moid;
- $dir='xmodcalendar';
- $oidcal=@$this->diary['KOID'];
- parent::_actionlist($my);
-
- if($this->interactive) {
- $o1=new XModuleAction($this,'def',$this->modulename,
- '&moid='.$moid.'&_function='.$this->defview.'&tplentry=br&template='.$dir.'/'.$this->defview.'.html&now','display');
- $my['stack'][]=$o1;
-
- if(!empty($oidcal)){
- $o1=new XModuleAction($this,'diary',$this->diary['name'],
- '&moid='.$moid.'&oid='.$oidcal.'&_function='.$this->defview.'&tplentry=br&template='.$dir.'/'.$this->defview.'.html&now',
- 'display');
- $my['stack'][]=$o1;
- }
- }
- if(empty($oidcal)) return;
- // Liste des agendas
- if(!empty($this->bloc['diary_list']['lines_oid']) && count($this->bloc['diary_list']['lines_oid'])>1){
- $o1=new XModuleAction($this,'chooseag', XLabels::getSysLabel('xmodcalendar','diary','text'),'#');
- $o1->newgroup='chooseag';
- $o1->menuable=true;
- $my['chooseag']=$o1;
- foreach($this->bloc['diary_list']['lines_oid'] as $i=>$oid){
- $o1=new XModuleAction($this,'chooseag', $this->bloc['diary_list']['lines_oname'][$i]->html,
- '&moid='.$this->_moid.'&oid='.$oid.'&function='.$this->defview.'&tplentry=br&template=xmodcalendar/'.$this->defview.'.html&now','chooseag');
- $o1->menuable=true;
- $my['chooseag'.$i]=$o1;
- }
- }
- // Assigner agenda par defaut
- $o1=new XModuleAction($this, 'setDefault', XLabels::getSysLabel('xmodcalendar','default','text'),
- '&moid='.$moid.'&oid='.$oidcal.'&display='.XShell::_function().'&_function=setDefault','edit');
- $o1->menuable=true;
- $my['setDefault']=$o1;
- // Aujourd'hui
- $o1=new XModuleAction($this, 'displayToday', XLabels::getSysLabel('xmodcalendar','today','text'),
- '&moid='.$moid.'&oid='.$oidcal.
- '&_function='.$this->defview.'&tplentry=br&template='.$dir.'/'.$this->defview.'.html&now','display');
- $o1->setToolbar('xmodcalendar','today');
- $my['displaytoday']=$o1;
- // Affichage quotidien
- $o1=new XModuleAction($this, 'displayDay', XLabels::getSysLabel('xmodcalendar','displayday','text'),
- '&moid='.$moid.'&oid='.$oidcal.
- '&_function=displayDay&tplentry=br&template='.$dir.'/displayDay.html&'.$date,'display');
- $o1->setToolbar('xmodcalendar','displayday');
- $my['displayday']=$o1;
- // Affichage hebdo
- $o1=new XModuleAction($this, 'displayWeek', XLabels::getSysLabel('xmodcalendar','displayweek','text'),
- '&moid='.$moid.'&oid='.$oidcal.
- '&_function=displayWeek&tplentry=br&template='.$dir.'/displayWeek.html&'.$date,'display');
- $o1->setToolbar('xmodcalendar','displayweek');
- $my['displayweek']=$o1;
- // Affichage mensuel
- $o1=new XModuleAction($this, 'displayMonth', XLabels::getSysLabel('xmodcalendar','displaymonth','text'),
- '&moid='.$moid.'&oid='.$oidcal.
- '&_function=displayMonth&tplentry=br&template='.$dir.'/displayMonth.html&'.$date,'display');
- $o1->setToolbar('xmodcalendar','displaymonth');
- $my['displaymonth']=$o1;
- // Affichage annuel
- $o1=new XModuleAction($this, 'displayYear', XLabels::getSysLabel('xmodcalendar','displayyear','text'),
- '&moid='.$moid.'&oid='.$oidcal.
- '&_function=displayYear&tplentry=br&template='.$dir.'/displayYear.html&'.$date,'display');
- $o1->setToolbar('xmodcalendar','displayyear');
- $my['displayyear']=$o1;
- // Parcourir planification en cours
- if($this->secure($this->diary['KOID'],'browsePlanif')){
- $o1=new XModuleAction($this, 'browsePlanif', XLabels::getSysLabel('xmodcalendar','browseplanif','text'),
- '&moid='.$moid.'&oid='.$oidcal.'&_function=browsePlanif&template=xmodcalendar/browsePlanif.html&tplentry=br',
- 'edit');
- $o1->menuable=true;
- $o1->separator=true;
- $my['browsePlanif']=$o1;
- }
- // Ajouter planification
- if($this->secure($this->diary['KOID'],'insertPlanif')){
- $o1=new XModuleAction($this, 'insertPlanif', XLabels::getSysLabel('xmodcalendar','insertplanif','text'),
- '&moid='.$moid.'&oid='.$oidcal.'&_function=insertPlanif&template=xmodcalendar/newPlanif.html&tplentry=br',
- 'edit');
- $o1->menuable=true;
- $my['insertPlanif']=$o1;
- }
- // Next et prev dans la toolbar
- $tb=XShell::from_screen('br','toolbar');
- if(!empty($tb['prev'])) {
- $o1=new XModuleAction($this, 'next', XLabels::getSysLabel('general','previous','text'),
- '&moid='.$moid.'&oid='.$oidcal.
- '&_function='.XShell::_function().'&tplentry=br&template='.$_REQUEST['template'].'&'.$tb['prev'],'display');
- $o1->setToolbar('general','previous');
- $my['previous']=$o1;
- }
- if(!empty($tb['next'])) {
- $o1=new XModuleAction($this, 'next', XLabels::getSysLabel('general','next','text'),
- '&moid='.$moid.'&oid='.$oidcal.
- '&_function='.XShell::_function().'&tplentry=br&template='.$_REQUEST['template'].'&'.$tb['next'],'display');
- $o1->setToolbar('general','next');
- $my['next']=$o1;
- }
-
- // Edition de l'agenda courant
- if(!empty($oidcal)){
- $o1=new XModuleAction($this,'edit',XLabels::getSysLabel('xmodcalendar','editdiary','text'),
- '&moid='.$moid.'&oid='.$oidcal.'&_function=editDiary&tplentry=br&'.
- 'template=xmodcalendar/editDiary.html&day='.$this->day.'&month='.$this->month.'&year='.$this->year,'edit');
- $o1->order=2;
- $o1->setToolbar('general','edit');
- $my['edit']=$o1;
- }
- // Abonnement
- $modsubmoid=XModule::getMoid(XMODSUB_TOID);
- if(!empty($modsubmoid)){
- $o1=new XModuleAction($this, 'subscribe', XLabels::getSysLabel('xmodsub','subadd','text'),
- 'javascript:v'.$uniqid.'.addSub("'.$modsubmoid.'","'.$oidcal.'");','more');
- $o1->menuable=true;
- $my['subscribe']=$o1;
- }
- }
- protected function _lasttimestamp() {
- $rs=selectQueryByNum('select MAX(UPD) from '.$this->tlinks);
- if($ors=$rs->fetch()) {
- $rs->closeCursor();
- return $ors[0];
- }
- return 0;
- }
- function _whatsNew($ts,$user,$group=NULL,$specs=NULL,$timestamp) {
- list($oid)=explode(';',$specs);
- if($oid){
- $lvl=XUser::secure8maxlevel($this,$oid);
- if(in_array($lvl,array('rw','rwv','admin'))){
- $rs=selectQuery('select '.$this->tlinks.'.* from '.$this->tlinks.' left outer join '.$this->tevt.' on '.
- $this->tevt.'.KOID='.$this->tlinks.'.KOIDE where '.$this->tlinks.'.UPD>="'.$ts.'" and '.
- $this->tlinks.'.KOIDD="'.$oid.'"');
- }elseif($lvl=='ro'){
- $rs=selectQuery('select '.$this->tlinks.'.* from '.$this->tlinks.' left outer join '.$this->tevt.' on '.
- $this->tevt.'.KOID='.$this->tlinks.'.KOIDE where '.$this->tlinks.'.UPD>="'.$ts.'" and '.
- $this->tlinks.'.KOIDD="'.$oid.'" and '.$this->tevt.'.visib="PU"');
- }
- }else{
- $prcals=$this->getAuthorizedDiaries('ro','array',true);
- $pucals=$this->getAuthorizedDiaries('rw','array',true);
- $prcals=implode('","',array_diff($prcals,$pucals));
- $pucals=implode('","',$pucals);
- $rs=selectQuery('select '.$this->tlinks.'.* from '.$this->tlinks.' left outer join '.$this->tevt.' on '.
- $this->tevt.'.KOID='.$this->tlinks.'.KOIDE where '.$this->tlinks.'.UPD>="'.$ts.'" and '.
- '((visib="PU" and '.$this->tlinks.'.KOIDD in ("'.$prcals.'")) or ('.$this->tlinks.'.KOIDD in ("'.$pucals.'"))) '.
- 'order by '.$this->tlinks.'.KOIDE');
- }
- $txt='';
- $prevoid='';
- $rs2=selectQuery('select KOID,name from '.$this->tagenda);
- $diaries=array();
- while($rs2 && ($ors2=$rs2->fetch())){
- $diaries[$ors2['KOID']]=$ors2['name'];
- }
- while($rs && ($ors=$rs->fetch())){
- if($prevoid!=$ors['KOIDE']){
- $d=$this->xsetevt->display(array('oid'=>$ors['KOIDE'],'tplentry'=>TZR_RETURN_DATA));
- $when=$d['oUPD']->html;
- $who=$d['lst_upd']['usernam'];
- $prevoid=$ors['KOIDE'];
- }
- $txt.='<li><a href="'.$GLOBALS['TZR_SESSION_MANAGER']::admin_url(true,false).'moid='.$this->_moid.'&function=addEvt&mode=view&oid='.$ors['KOIDD'].
- '&koid='.$d['oid'].'&tplentry=br&template=xmodcalendar/addEvt.html&_direct=1">"'.$d['otext']->html.'"</a> sur "'.$diaries[$ors['KOIDD']].'" '.
- '('.$when.', '.$who.')</li>';
- }
- return $txt;
- }
- function actionListAdd(&$my,$f){
- if(!$this->group_of_diary && $this->diary['rwsecure']){
- $o1=new XModuleAction($this,'addevt',XLabels::getSysLabel('xmodcalendar','addevt','text'),
- '&moid='.$this->_moid.'&_function=addEvt&tplentry=br&template=xmodcalendar/addEvt.html&oid='.$this->diary['KOID'].
- '&day='.$this->day.'&month='.$this->month.'&year='.$this->year.'&display='.$f,'edit');
- $o1->setToolbar('xmodcalendar','addevt');
- $my['addevt']=$o1;
- $o1=new XModuleAction($this,'import',XLabels::getSysLabel('xmodcalendar','importevt','text'),
- '&moid='.$this->_moid.'&_function=importEvt&tplentry=br&template=xmodcalendar/importEvt.html&oid='.$this->diary['KOID'].
- '&day='.$this->day.'&month='.$this->month.'&year='.$this->year.'&display='.$f,'edit');
- $o1->menuable=true;
- $my['importevt']=$o1;
- }
- $o1=new XModuleAction($this,'export',XLabels::getSysLabel('xmodcalendar','exportevt','text'),
- '&moid='.$this->_moid.'&_function=exportEvt&tplentry=br&template=xmodcalendar/exportEvt.html&oid='.$this->diary['KOID'].
- '&day='.$this->day.'&month='.$this->month.'&year='.$this->year.'&display='.$f,'edit');
- $o1->menuable=true;
- $my['exportevt']=$o1;
- }
- function al_displayDay(&$my){
- // Si pas d'utilisateur, ca ne sert à rien de continuer car on est dans un upgrade
- if(empty($GLOBALS['XUSER']) || XUser::isNobody()) return;
- $uniqid=XShell::uniqid();
- $moid=$this->_moid;
- $oidcal=@$this->diary['KOID'];
- $cons=$this->getDiariesForConsolidation();
- $f=XShell::_function();
- $this->actionListAdd($my,$f);
- $o1=new XModuleAction($this, 'cons', XLabels::getSysLabel('xmodcalendar','consolidation','text'),'#','edit');
- $o1->newgroup='cons_index';
- $o1->menuable=true;
- $my['cons']=$o1;
- $auths=$this->getAuthorizedDiaries();
- foreach($auths as $oid){
- if($oid==$this->diary['KOID'] || !empty($cons['list'][$oid])) continue;
- if(empty($my['consag'])){
- $o1=new XModuleAction($this, 'consag', XLabels::getSysLabel('xmodcalendar','diary','text'),'#');
- $o1->group='cons_index';
- $o1->newgroup='consag_index';
- $o1->menuable=true;
- $my['consag']=$o1;
- }
- $ors=selectQueryGetAll('select name from '.$this->tagenda.' where KOID="'.$oid.'"');
- $o1=new XModuleAction($this, 'consag', $ors[0]['name'],'javascript:v'.$uniqid.'.addConsolidation("'.$oid.'");');
- $o1->group='consag_index';
- $o1->menuable=true;
- $my['consag'.$oid]=$o1;
- }
- $o1=new XModuleAction($this, 'consmod', XLabels::getSysLabel('general','module','text'),'#');
- $o1->group='cons_index';
- $o1->newgroup='consmod_index';
- $o1->menuable=true;
- $my['consmod']=$o1;
- $mods=XModule::authorizedModules();
- $rs=&cacheSelectQuery('select MOID,MODULE from MODULES where TOID in("'.XMODTABLE_TOID.'") order by MODULE');
- while($rs && ($ors=$rs->fetch())){
- $moid=$ors['MOID'];
- if(!in_array($moid,$mods) || !empty($cons['list'][$moid])) continue;
- $o1=new XModuleAction($this, 'consag', $ors['MODULE'],'javascript:v'.$uniqid.'.addConsolidation("'.$moid.'");');
- $o1->group='consmod_index';
- $o1->menuable=true;
- $my['consmod'.$ors['MODULE']]=$o1;
- }
- }
- function al_displayWeek(&$my){
- $this->al_displayDay($my);
- }
- function al_displayMonth(&$my){
- $this->al_displayDay($my);
- }
- function al_displayYear(&$my){
- $this->al_displayDay($my);
- }
- function al_addEvt(&$my){
- $this->actionListAdd($my,$_REQUEST['display']);
- }
- function al_editDiary(&$my){
- $this->actionListAdd($my,$_REQUEST['display']);
- }
- function al_exportEvt(&$my){
- $this->actionListAdd($my,$_REQUEST['display']);
- }
- function al_importEvt(&$my){
- }
- function al_browsePlanif(&$my){
- $uniqid=XShell::uniqid();
- $o1=new XModuleAction($this,'delPlan',XLabels::getSysLabel('general','delete','text'),'javascript:v'.$uniqid.'.deleteselected();','edit');
- $o1->order=3;
- $o1->setToolbar('general','delete');
- $my['delPlan']=$o1;
- }
- function al_displayPlanif(&$my){
- $o1=new XModuleAction($this,'editPlan',XLabels::getSysLabel('general','edit','text'),str_replace('function=displayPlanif','function=editPlanif',$_SERVER['REQUEST_URI']),'edit');
- $o1->menuable=true;
- $my['editPlan']=$o1;
- }
- /// Afficher les infos sur une journee
- function displayDay($ar=NULL) {
- $p=new XParam($ar,array());
- $this->bloc['calendar_mode']='';
- $this->createCalendar($p);
- $display_begin_gmt=gmdate('Y-m-d H:i:s',strtotime($this->date.' 00:00:00'));
- $display_end_gmt=gmdate('Y-m-d H:i:s',strtotime($this->date.' 23:59:00'));
- $this->display_begin=date('Y-m-d H:i:s',strtotime($this->date.' 00:00:00'));
- $this->display_end=date('Y-m-d H:i:s',strtotime($this->date.' 23:59:00'));
- $day_begin=$this->diary['beginnum'];
- $day_end=$this->diary['endnum'];
- // Recupere les notes et evenements
- $notes=$this->getNotes($this->display_begin,$this->display_end,false,true);
- $events=$this->getEvents($display_begin_gmt,$display_end_gmt,false,true);
- $this->getDisplayHours($events,$day_begin,$day_end);
- $this->cutNotes($notes);
- $this->cutEvents($events,$day_begin,$day_end);
- // Construit les infos a envoyer au template
- $this->bloc['daybegin']=$day_begin;
- $this->bloc['dayend']=$day_end;
- $this->bloc['dates']=array($this->date);
- $this->bloc['events']=$events;
- $this->bloc['notes']=$notes;
- $this->bloc['toolbar']=array('prev'=>date('\d\a\y=j&\m\o\n\t\h=n&\y\e\a\r=Y',strtotime($this->date.' -1 day')),
- 'next'=>date('\d\a\y=j&\m\o\n\t\h=n&\y\e\a\r=Y',strtotime($this->date.' +1 day')));
- return XShell::toScreen1('br',$this->bloc);
- }
- /// Afficher les infos sur une semaine
- function displayWeek($ar=NULL) {
- $p=new XParam($ar,array());
- $first_day_week=$this->calculateWeekDetails($p);
- $this->createCalendar($p);
- $display_begin_gmt=gmdate('Y-m-d H:i:s',$first_day_week);
- $display_end_gmt=gmdate('Y-m-d H:i:s',strtotime('+7 day -1 minute',$first_day_week));
- $this->display_begin=date('Y-m-d H:i:s',$first_day_week);
- $this->display_end=date('Y-m-d H:i:s',strtotime('+7 day -1 minute',$first_day_week));
- $day_begin=$this->diary['beginnum'];
- $day_end=$this->diary['endnum'];
- // Recupere les notes et evenements
- $notes=$this->getNotes($this->display_begin,$this->display_end,false,true);
- $events=$this->getEvents($display_begin_gmt,$display_end_gmt,false,true);
- $this->getDisplayHours($events,$day_begin,$day_end);
- $this->cutNotes($notes);
- $this->cutEvents($events,$day_begin,$day_end);
- // Construit les infos a envoyer au template
- $this->bloc['daybegin']=$day_begin;
- $this->bloc['dayend']=$day_end;
- $this->bloc['dates']=array();
- for($i=0;$i<7;$i++) $this->bloc['dates'][]=date('Y-m-d',strtotime('+'.$i.' day',$first_day_week));
- $this->bloc['events']=$events;
- $this->bloc['notes']=$notes;
- $this->bloc['toolbar']=array('prev'=>date('\w\e\e\k=W&\y\e\a\r=o',strtotime('-1 week '.$this->date)),
- 'next'=>date('\w\e\e\k=W&\y\e\a\r=o',strtotime('+1 week '.$this->date))
- );
- return XShell::toScreen1('br',$this->bloc);
- }
-
- /// Afficher les infos sur un mois
- function displayMonth($ar=NULL) {
- $p=new XParam($ar,array());
- $events=$table=array();
- $this->day=1;
-
- $this->createCalendar($p);
-
- $month_list_label=XLabels::getSysLabel('xmodcalendar','monthlist','text');
- $this->bloc['header']=$month_list_label[$this->month-1].' '.$this->year;
- // Les infos a afficher sont deja calculer pour le mini calendrier du bas. On les recupere donc pour les afficher en entier
- $this->bloc['body']=$this->cal_content;
- $this->bloc['toolbar']=array('prev'=>date('\d\a\y=1&\m\o\n\t\h=n&\y\e\a\r=Y',strtotime($this->date.' -1 month')),
- 'next'=>date('\d\a\y=1&\m\o\n\t\h=n&\y\e\a\r=Y',strtotime($this->date.' +1 month'))
- );
- return XShell::toScreen1('br',$this->bloc);
- }
- /// Afficher les infos sur une annee
- function displayYear($ar=NULL) {
- $p=new XParam($ar,array());
- $month_list_label=XLabels::getSysLabel('xmodcalendar','monthlist','text');
- $this->createCalendar($p);
- $display_begin_gmt=gmdate('Y-m-d H:i:s',strtotime($this->year.'-01-01 00:00:00'));
- $display_end_gmt=gmdate('Y-m-t H:i:s',strtotime($this->year.'-12-31 23:59:00'));
- $this->display_begin=date('Y-m-d H:i:s',strtotime($this->year.'-01-01 00:00:00'));
- $this->display_end=date('Y-m-t H:i:s',strtotime($this->year.'-12-31 23:59:00'));
-
- // Recupere les notes et les evenements
- $rs=$this->getAlls($display_begin_gmt,$display_end_gmt,$this->display_begin,$this->display_end);
- while($rs && ($event=$rs->fetch())) {
- $this->convertEventTime($event);
- $begin=date('z',strtotime($event['begin']));
- $end=date('z',strtotime($event['end']));
- for($i=$begin;$i<=$end;$i++) $events[$i]=1;
- }
-
- for($j=1;$j<13;$j++) {
- $nb_day_prev_month=date('t', mktime(12,0,0,$j-1,1,$this->year));
- $nb_day_month=date('t', mktime(12,0,0,$j,1,$this->year));
- $first_day=date('N',mktime(12,00,00,$j,1,$this->year));
- $last_day=date('N',mktime(12,00,00,$j+1,0,$this->year));
- $day_of_year=date('z',mktime(12,00,00,$j,1,$this->year));
- $prev_month=date('n',mktime(12,00,00,$j-1,1,$this->year));
- $next_month=date('n',mktime(12,00,00,$j+1,1,$this->year));
- $prev_year=date('Y',mktime(12,00,00,$j-1,1,$this->year));
- $next_year=date('Y',mktime(12,00,00,$j+1,1,$this->year));
-
- $month_content=array();
-
- for($i=$first_day-2;$i>-1;$i--) {
- $month_content[]=array('day'=>$nb_day_prev_month-$i,'month'=>$prev_month,'year'=>$prev_year,'event'=>false,'style'=>'out');
- }
- for($i=1;$i<=$nb_day_month;$i++) {
- $month_content[]=array('day'=>$i,'month'=>$j,'year'=>$this->year,'event'=>(isset($events[$day_of_year+$i-1]))?true:false,
- 'style'=>'in');
- }
- for($i=1;$i<8-$last_day;$i++) {
- $month_content[]=array('day'=>$i,'month'=>$next_month,'year'=>$next_year,'event'=>false,'style'=>'out');
- }
-
- $content[$j]=array('header'=>$month_list_label[$j-1].' '.$this->year,'content'=>$month_content);
- }
-
- $this->bloc['body']=$content;
- $this->bloc['toolbar']=array('prev'=>'day=1&month1=n&year='.($this->year-1),'next'=>'day=1&month1=n&year='.($this->year+1));
- return XShell::toScreen1('br',$this->bloc);
- }
- /// Retourne une liste d'evenements/notes/tous sur une periode
- function browsePeriod($ar=NULL){
- $p=new XParam($ar,array('type'=>'all','begin'=>'1970-01-01','end'=>'2037-12-31'));
- $type=$p->get('type');
- $begin=$p->get('begin');
- $end=$p->get('end');
- $tplentry=$p->get('tplentry');
- $getrsonly=$p->get('getrsonly');
- if($type=='all') $rs=$this->getAlls(gmdate('Y-m-d H:i:s',strtotime($begin.' 00:00:00')),
- gmdate('Y-m-d H:i:s',strtotime($end.' 23:59:00')),
- $begin.' 00:00:00',$end.' 23:59:59');
- if($getrsonly) return $rs;
- $result=array();
- while($rs && ($ors=$rs->fetch())){
- $this->getCompleteEvent($ors);
- $ors['_begindate']=date('d/m/Y',strtotime($ors['begin'].' GMT'));
- $ors['_beginhour']=date('H:i',strtotime($ors['begin'].' GMT'));
- $ors['_enddate']=date('d/m/Y',strtotime($ors['end'].' GMT'));
- $ors['_endhour']=date('H:i',strtotime($ors['end'].' GMT'));
- $result[]=$ors;
- }
- return XShell::toScreen2($tplentry,'list',$result);
- }
- /// rend les emails d'un user ou des users d'un groupe
- function getEmails($ar=NULL) {
- $p=new XParam($ar, array());
- $doid=$p->get("doid");
- if(Kernel::getTable($doid)=='GRP') {
- $users = XModGroup::users(array($doid));
- } else {
- $users=array($doid);
- }
- $emails=array();
- foreach($users as $oid) {
- $xuser=new XUser(array("UID"=>$oid));
- $emails[]=$xuser->email();
- unset($xuser);
- }
- echo json_encode($emails);
- exit(0);
- }
- /// Ajout/edition/consultation d'un evenement
- function addEvt($ar=NULL) {
- $p=new XParam($ar,array('getintattendees'=>true,'hour'=>'08:00:00'));
- $mode=$p->get('mode');
- $oid=$p->get('oid');
- $koid=$p->get('koid');
- $hour=$p->get('hour');
- $allday=$p->get('allday');
- $getintattendees=$p->get('getintattendees');
- // Definit la fonction a executer
- if($mode=='view'){
- $function='display';
- $secure=false;
- }else{
- $secure=$this->secure($oid,'saveEvt');
- if(empty($koid) && $secure) $function="input";
- elseif($secure) $function="edit";
- else $function="display";
- }
- if(!empty($koid)){
- $ors=selectQueryGetOne('select * from '.$this->tevt.' where KOID="'.$koid.'" LIMIT 1');
- if(!empty($ors['KOIDS'])) $ar['oid']=$ors['KOIDS'];
- else $ar['oid']=$koid;
- if($ors['allday']!=1){
- $ar['options']['begin']['tz']='GMT';
- $ar['options']['end']['tz']='GMT';
- }
- }else{
- $ar['options']['begin']['value']=$this->date.' '.$hour;
- $ar['options']['end']['value']=date('Y-m-d H:i:s',strtotime($this->date.' '.$hour.' +1 hour'));
- }
- $ar['tplentry']=TZR_RETURN_DATA;
- $this->xsetevt->desc['end_rep']->compulsory=true;
- $ev=$this->xsetevt->$function($ar);
- $ev['secure']=$secure;
- // Formate les donnees dans le cas d'une edition
- if(!empty($koid)) {
- if(!empty($ev['oexcept']->raw)) {
- $datedef=new XDateDef();
- $tab_except=explode(';',$ev['oexcept']->raw);
- foreach($tab_except as $tmp) $this->bloc['except'][$tmp]=$datedef->dateFormat($tmp);
- }
- $rs=selectQuery('SELECT KOIDD from '.$this->tlinks.' where KOIDE="'.$koid.'" and KOIDD!="'.$this->diary['KOID'].'"');
- while($rs && ($attendee=$rs->fetch())) $all_attendees[$attendee['KOIDD']]='';
- }
- // Liste des differents mode de repetition et champ date except
- $this->bloc['repetition']=array('NO'=>XLabels::getSysLabel('xmodcalendar','repetition','text'),
- 'DAILY'=>XLabels::getSysLabel('xmodcalendar','daily','text'),
- 'WEEKLY'=>XLabels::getSysLabel('xmodcalendar','weekly','text'),
- 'MONTHLY'=>XLabels::getSysLabel('xmodcalendar','monthly','text'),
- 'YEARLY'=>XLabels::getSysLabel('xmodcalendar','annual','text'));
- $xdatedef=clone($this->xsetevt->desc['end_rep']);
- $xdatedef->compulsory=false;
- $ev['oexcepttmp']=$xdatedef->edit($v='',$opt=array('fieldname'=>'excepttmp'));
- // Prepare la liste des invites possible (par defaut, liste des agendas non consolides)
- if($getintattendees){
- if(!defined('TZR_ALTERNATIVE_SENDTO_DIRECTORY') && !defined('TZR_ALTERNATIVE_CALINTERNE_DIRECTORY')){
- if($this->object_sec){
- if($function=='display') $cplt=' AND KOID IN ('.$this->getAuthorizedDiaries('ro','sql').')';
- else $cplt=' AND KOID IN ('.$this->getAuthorizedDiaries('rwv','sql').')';
- }else{
- $cplt='';
- }
- $xset=XDataSource::objectFactoryHelper8('BCLASS=XDSTable&SPECS='.$this->tagenda);
- $vals=implode('||',array_keys($all_attendees));
- $opts=array('filter'=>'(cons IS NULL OR cons!=1) and KOID!="'.$this->diary['KOID'].'"'.$cplt);
- if($function=='display') $ev['oattendees']=&$xset->desc['agcons']->display($vals,$opts);
- else $ev['oattendees']=&$xset->desc['agcons']->edit($vals,$opts);
- }else{
- if(defined('TZR_ALTERNATIVE_CALINTERNE_DIRECTORY')) $altmoid=TZR_ALTERNATIVE_CALINTERNE_DIRECTORY;
- else $altmoid=TZR_ALTERNATIVE_SENDTO_DIRECTORY;
- $mod=XModule::objectFactory($altmoid);
- $list=&$mod->browse(array('tplentry'=>TZR_RETURN_DATA,'pagesize'=>999,'_options'=>array('local'=>true),'tlink'=>true));
- foreach($list['lines_oid'] as $i=>$oid){
- if(isset($all_attendees[$oid])) {
- $attendees[$oid]=$list['lines_tlink'][$i];
- } else {
- $users_unselected[$oid]=$list['lines_tlink'][$i];
- }
- }
- $this->bloc['attendees']=$attendees;
- $this->bloc['users_unselected']=$users_unselected;
- }
- $ev['oattendees']->sys=false;
- }else{
- $ev['oattendees']->sys=true;
- }
- if(!empty($ev['oattext'])){
- list($acl_user, $acl_grp)=XUser::getUsersAndGroups();
- XShell::toScreen1('users',$acl_user);
- XShell::toScreen1('grps',$acl_grp);
- }
- XShell::toScreen1('ev',$ev);
- return XShell::toScreen1('br',$this->bloc);
- }
- /// Sauvegarde un evenement
- public function saveEvt($ar=NULL) {
- $p=new XParam($ar,array());
- $koid=$p->get('koid');
- $text=$p->get('text');
- $cat=$p->get('cat');
- $place=$p->get('place');
- $descr=$p->get('descr');
- $visib=$p->get('visib');
- if(empty($visib)) $visib='PU';
- $repet=$p->get('repetition');
- $recalltime=$p->get('recalltime');
- $recalltype=$p->get('recalltype');
- $allday=$p->get('allday');
- $allday_HID=$p->get('allday_HID');
- $attext=$p->get('attext');
- $excepttab=$p->get('except');
- $xset_link=XDataSource::objectFactoryHelper8('BCLASS=XDSTable&SPECS='.$this->tlinks);
- $allday=$this->xsetevt->desc['allday']->post_edit($allday,array('allday_HID'=>$allday_HID));
- $allday=$allday->raw;
- $datedef=new XDateDef();
- $ar1=array();
- $except=$except_mail=null;
- $list_mail_text='';
- $attselected=$p->get('selected');
- // Recupere l'agenda de l'evenement (si modifiation sur un agenda consolide, recupere l'agenda de l'evenement, sinon agenda courant)
- if($this->group_of_diary && !empty($koid)) {
- $rs=selectQuery('SELECT KOIDD FROM '.$this->tevt.' where KOID="'.$koid.'"');
- $tmp=$rs->fetch();
- $diary=$tmp['KOIDD'];
- } else {
- $diary=$this->diary['KOID'];
- }
- // Formatage des dates/heures
- $foo=$p->get('begin');
- if(!empty($foo) && is_array($foo)){
- $begindate=$foo['date'];
- $beginhour=$foo['hour'];
- }else{
- $begindate=$p->get('begindate');
- $beginhour=$p->get('beginhour');
- }
- $foo=$p->get('end');
- if(!empty($foo) && is_array($foo)){
- $enddate=$foo['date'];
- $endhour=$foo['hour'];
- }else{
- $enddate=$p->get('enddate');
- $endhour=$p->get('endhour');
- }
- if($allday=='1') {
- $beginhour='00:00:00';
- $endhour='23:59:00';
- } else {
- $beginhour=$beginhour.':00';
- $endhour=$endhour.':00';
- }
- $begin=$this->xsetevt->desc['begin']->post_edit(array('date'=>$begindate,'hour'=>$beginhour));
- $end=$this->xsetevt->desc['end']->post_edit(array('date'=>$enddate,'hour'=>$endhour));
- if($begin->raw>$end->raw) return array();
- $dbegin=$this->xsetevt->desc['begin']->display($begin->raw);
- $dend=$this->xsetevt->desc['end']->display($end->raw);
- $date_begin_tsp=strtotime($begin->raw);
- $date_end_tsp=strtotime($end->raw);
- // Preparation de la repetition
- if($repet=='NO') {
- $until=null;
- $until_tsp=0;
- } else {
- if($repet=='DAILY') $add_repetition='DAY';
- elseif($repet=='WEEKLY') $add_repetition='WEEK';
- elseif($repet=='MONTHLY') $add_repetition='MONTH';
- else $add_repetition='YEAR';
- $tmp=$datedef->post_edit($p->get('end_rep'));
- $until=$tmp->raw;
- $until_tsp=strtotime($until.' 23:59:00');
- // Preparation des exceptions
- if(!empty($excepttab)) {
- foreach($excepttab as $tmp) {
- $tmp2=$datedef->post_edit($tmp);
- $except.=$tmp2->raw.';';
- $except_mail.=$tmp.';';
- }
- $except=substr($except,0,(strlen($except)-1));
- $except_mail=substr($except_mail,0,(strlen($except_mail)-1));
- }
- }
- // Preparation du tableau de donnees
- $ar1=$ar;
- $ar1['repet']=$repet;
- $ar1['end_rep']=$until;
- $ar1['except']=$except;
- $ar1['recall']=($recalltime*$recalltype);
- $ar1['KOIDD']=$diary;
- $ar1['UIDI']=null;
- $ar1['tplentry']=TZR_RETURN_DATA;
- $ar1['visib']=$visib;
- $ar1['rrule']='';
- // Si on est dans une modification, on efface les evenements lies a la source mais on garde l'evenement d'origine pour le modifier
- if(!empty($koid)) {
- $this->delEvt(array('koid'=>$koid,'noalert'=>true,'nodelsource'=>true));
- $ar1['oid']=$koid;
- $function='procEdit';
- }else{
- $function='procInput';
- }
- // Tant que l'on est dans l'intervale de repetition, on insere des entrees
- $repet=false;
- $koids=NULL;
- do {
- $date_begin=date('Y-m-d',$date_begin_tsp);
- // Si la date n'est pas dans les exceptions
- if(strpos($except,$date_begin)===FALSE) {
- $ar1['begin']=($allday!='1') ? gmdate('Y-m-d H:i:s',$date_begin_tsp) : date('Y-m-d H:i:s',$date_begin_tsp);
- $ar1['end']=($allday!='1') ? gmdate('Y-m-d H:i:s',$date_end_tsp) : date('Y-m-d H:i:s',$date_end_tsp);
- $ar1['KOIDS']=$koids;
- $ret=$this->xsetevt->$function($ar1);
- if($function=='procEdit') $ret['oid']=$koid;
- $xset_link->procInput(array('KOIDE'=>$ret['oid'],'KOIDD'=>$diary));
- foreach($attselected as $att) {
- // On ne copie pas l'événement dans l'agenda à l'origine de cet événement
- if ($att == $diary) continue;
- $ar2=array('KOIDD'=>$att,'KOIDE'=>$ret['oid']);
- $xset_link->procInput($ar2);
- }
- if(!$repet) $koids=$ret['oid'];
- }
- $repet=true;
- $function='procInput';
- $date_begin_tsp=strtotime('+1 '.$add_repetition,$date_begin_tsp);
- $date_end_tsp=strtotime('+1 '.$add_repetition,$date_end_tsp);
- } while($date_begin_tsp<$until_tsp+1);
- // Env…
Large files files are truncated, but you can click here to view the full file