PageRenderTime 61ms CodeModel.GetById 21ms RepoModel.GetById 0ms app.codeStats 1ms

/class.xmodcalendar.inc

https://github.com/jcplat/console-seolan
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

  1. <?php
  2. /// Module de gestion des Agenda
  3. class XModCalendar extends XModule {
  4. public $prefs; /* Preferences du module */
  5. public $day;
  6. public $month;
  7. public $year;
  8. public $week;
  9. public $date;
  10. public $paques;
  11. public $ascencion;
  12. public $pentecote;
  13. public $request; /* tableau avec les elements de base pour les requetes sur les evenements */
  14. public $diary; /* resulset de l'agenda selectionne */
  15. public $group_of_diary;
  16. public $tcolors='#a3d0f2,#ef6464,#77c26d,#eb815d,#a794f0,#d5c128,#b4aeb0,#83d9ff,#e8879e,#98e057,#f68f3d,#c5a3e4,#e8da3f,#c9c1cd,#9fdbf3,#f19999,#c1ec4b,#efaf6a,#b3b8ef,#f4f078,#bac9cd';
  17. public $synchro=false; /* Indique si on est sur une synchronisation ou non (par defaut non) */
  18. public $sendToUser=false; /* Indique si les mails doivent etre envoyes a  l'utilisateur loge */
  19. public $defcal='';
  20. public $categories;
  21. public $display_begin;
  22. public $display_end;
  23. public $cal_content;
  24. public $tagenda; /* liste des agendas connus */
  25. public $tevt; /* evenements */
  26. public $tlinks; /* liens entre agendas et evenements */
  27. public $tcatevt; /* categories d'evenements */
  28. public $tcatagenda; /* categories d'agendas */
  29. public $tplan; /* liste des planifications en cours de traitement */
  30. public $tplaninv; /* liste des invités pour les planification */
  31. public $tplandates; /* liste des dates pour les planification */
  32. public $xsetevt; /* xset sur la table de evenement */
  33. public $catperso; /* oid de la categorie d'agenda perso */
  34. /* ensemble des variables a passer aux templates (_fieldlist : liste des champs de base de l'agenda) */
  35. public $bloc=array('_fieldlist'=>array('text','begin','end','allday','cat','place','descr','visib','repet','end_rep','except','recall',
  36. 'isrecal','attext','rrule','UIDI','KOIDD','KOIDS','KOIDIT'));
  37. function __construct($ar=NULL) {
  38. parent::__construct($ar);
  39. XLabels::loadLabels('xmodcalendar');
  40. $this->colors=explode(',',$this->tcolors);
  41. $p=new XParam($ar,array());
  42. $oid=$p->get('oid');
  43. $now=$p->get('now');
  44. // Dans la cas du traitement d'une planification, on ne construit pas les infos de l'agenda
  45. if(Kernel::getTable($oid)==$this->tplaninv) return;
  46. // Recupere la date a visualiser
  47. if(isset($_REQUEST['now']) || !empty($now)){
  48. $this->day=date('j');
  49. $this->month=date('n');
  50. $this->year=date('Y');
  51. }else{
  52. $this->day=$p->get('day');
  53. $this->month=ltrim($p->get('month'),'0');
  54. $this->year=ltrim($p->get('year'),'0');
  55. }
  56. $this->date=$this->year.'-'.str_pad($this->month,2,'0',STR_PAD_LEFT).'-'.str_pad($this->day,2,'0',STR_PAD_LEFT);
  57. $this->bloc['day']=$this->day;
  58. $this->bloc['month']=$this->month;
  59. $this->bloc['year']=$this->year;
  60. // S'authentifie a la connexion pour une synchro par PUT
  61. if(!empty($_REQUEST['_function'])) $f=$_REQUEST['_function'];
  62. elseif(!empty($_REQUEST['function'])) $f=$_REQUEST['function'];
  63. if($f=='synchro'){
  64. if(empty($_REQUEST['oid'])){
  65. die('nok');
  66. }
  67. if(!XUser::authentified()){
  68. $sess=new XSession();
  69. $ret=$sess->procTmpAuth();
  70. if(!$ret){
  71. header("HTTP/1.0 401 Authorization Required");
  72. die('Authorization Required');
  73. }
  74. }
  75. }
  76. $this->xsetevt=XDataSource::objectFactoryHelper8('BCLASS=XDSTable&SPECS='.$this->tevt);
  77. $this->xsetevt->desc['begin']->display_format=$this->xsetevt->desc['end']->display_format='H:M';
  78. // Si pas d'utilisateur, ca ne sert à rien de continuer car on est dans un upgrade
  79. if(empty($GLOBALS['XUSER'])) return;
  80. // Recupere les preferences, l'agenda courant
  81. $this->getPrefs();
  82. if(empty($this->defcal) && !empty($this->prefs['defaultcal'])) $this->defcal=$this->prefs['defaultcal'];
  83. if(empty($oid)){
  84. if(!empty($this->prefs['defaultcal'])) $oid=$this->prefs['defaultcal'];
  85. else $oid=$this->defcal;
  86. }
  87. // Dans le cas ou il n'y a ni oid ni agenda par defaut on prend le premier des agendas autorises
  88. if(empty($oid)) {
  89. $oids=$this->getAuthorizedDiaries();
  90. if(!empty($oids)) {
  91. reset($oids);
  92. $oid=current($oids);
  93. }
  94. }
  95. // Vue par défaut
  96. if(!empty($this->prefs['defview'])) $this->defview=$this->prefs['defview'];
  97. // Verifications de securite
  98. $params_to_check=array('day','week','year','month');
  99. foreach($params_to_check as $t) {
  100. $t1=$p->get($t);
  101. if(!empty($t1) && !is_numeric($t1)) {
  102. $this->$t=$t1;
  103. }
  104. }
  105. if($oid!='') {
  106. if(!strpos($oid,' ')) {
  107. }
  108. }
  109. if($p->get('koid')!='') {
  110. if(!strpos($p->get('koid'),' ')) {
  111. }
  112. }
  113. // Recupere les renseignements sur les categories d'evenement
  114. $rs=selectQuery('SELECT * FROM '.$this->tcatevt.' WHERE commun=1 OR OWN="'.XUser::get_current_user_uid().'" ORDER BY name');
  115. while($rs && $cat=$rs->fetch()) $this->categories[$cat['KOID']]=array('name'=>$cat['name'],'color'=>@$cat['color']);
  116. $this->bloc['categories']=$this->categories;
  117. $this->initialize($oid);
  118. date_default_timezone_set($this->diary['tz']);
  119. }
  120. /// Initialise le module pour un agenda donné : Recupere les données de l'agenda et prepare les composants de base pour les requetes SQL
  121. function initialize($oid){
  122. $rs=selectQuery('SELECT * FROM '.$this->tagenda.' where KOID="'.$oid.'"');
  123. if($this->diary=$rs->fetch()){
  124. if(empty($this->diary['defvisi']) || !in_array($this->diary['defvisi'],array('PU','OC','PR'))) $this->diary['defvisi']='PR';
  125. $this->bloc['diary']=&$this->diary;
  126. $ar=explode(':',$this->diary['begin']);
  127. $this->diary['beginnum']=$ar[0]+$ar[1]/60;
  128. $ar=explode(':',$this->diary['end']);
  129. $this->diary['endnum']=$ar[0]+$ar[1]/60;
  130. if($this->diary['cons']==1) {
  131. $ar=explode('||',$this->diary['agcons']);
  132. $br=array($this->diary['KOID']);
  133. foreach($ar as $i=>$oid){
  134. if(!empty($oid)){
  135. $br[]=$oid;
  136. $this->bloc['diariesprop'][$oid]['color']=$this->colors[$i];
  137. }
  138. }
  139. $this->bloc['group_of_diary']=$this->group_of_diary=true;
  140. } else {
  141. $this->diary['rwsecure']=$this->secure($this->diary['KOID'],'saveEvt');
  142. $this->bloc['diariesprop'][$this->diary['KOID']]['rwsecure']=$this->diary['rwsecure'];
  143. $this->bloc['group_of_diary']=$this->group_of_diary=false;
  144. $this->bloc['diariesprop'][$this->diary['KOID']]['color']=$this->colors[0];
  145. $br=array($this->diary['KOID']);
  146. }
  147. $all=$br;
  148. // Ajoute les consolidations
  149. $cons=$this->getDiariesForConsolidation();
  150. if(!empty($cons['active'])){
  151. $list=array_keys($cons['active']);
  152. $br=array_merge($br,$list);
  153. }
  154. if(!empty($cons['list'])){
  155. $all=array_merge($all,array_keys($cons['list']));
  156. }
  157. // Récupère les noms des differentes consolidations
  158. $rs=selectQuery('select KOID,name from '.$this->tagenda.' where KOID in ("'.implode('","',$all).'")');
  159. while($rs && ($ors=$rs->fetch())){
  160. $this->bloc['diariesprop'][$ors['KOID']]['name']=$ors['name'];
  161. }
  162. foreach($cons['list'] as $oid=>$foo){
  163. $this->bloc['diariesprop'][$oid]['color']=$foo['color'];
  164. if(is_numeric($oid)){
  165. $mod=&XModule::objectfactory(array('moid'=>$oid,'tplentry'=>TZR_RETURN_DATA));
  166. if(!is_object($mod)) continue;
  167. $this->bloc['diariesprop'][$oid]['name']=$mod->modulename;
  168. $this->bloc['diariesprop'][$oid]['url']=$mod->XCalGetUrl('display');
  169. $this->bloc['diariesprop'][$oid]['generalurl']=$mod->XCalGetUrl('browse');
  170. }
  171. }
  172. // Supprime les consolidations erronées (qui n'ont pas de nom) et met à jour le cache
  173. foreach($cons['list'] as $oid=>&$foo){
  174. if(empty($this->bloc['diariesprop'][$oid]['name'])){
  175. unset($cons['list'][$oid]);
  176. unset($cons['active'][$oid]);
  177. }
  178. }
  179. $this->bloc['consolidation']=$this->cache['consolidations']=$cons;
  180. $rw=$this->getAuthorizedDiaries('rw');
  181. $this->bloc['privatediaries']=$rw;
  182. // Champs dans les request (+ KOID et LANG qui ne sont pas dans le tableau) (ordre important dans un union en sql)
  183. $this->request['selectedfields']=array('begin','end','allday','visib','DOWNER','DNAME','DKOID','cat');
  184. // Requete
  185. $this->request['select']='select '.$this->tevt.'.KOID,'.$this->tevt.'.LANG,'.$this->tevt.'.begin,'.$this->tevt.'.end,'.
  186. $this->tevt.'.allday,'.$this->tevt.'.visib,'.$this->tagenda.'.OWN as DOWNER,'.$this->tagenda.'.name as DNAME,'.
  187. $this->tagenda.'.KOID as DKOID,'.$this->tevt.'.cat,"'.$this->_moid.'" as MOID';
  188. $this->request['from']='from '.$this->tevt.','.$this->tlinks.','.$this->tagenda;
  189. $this->request['where']='where '.$this->tagenda.'.KOID in ("'.implode('","',$br).'") AND '.
  190. $this->tagenda.'.KOID='.$this->tlinks.'.KOIDD AND '.$this->tevt.'.KOID='.$this->tlinks.'.KOIDE AND '.
  191. '('.$this->tagenda.'.KOID in ("'.implode('","',$rw).'") OR '.$this->tevt.'.visib!="PR")';
  192. }
  193. }
  194. /// Recupere les evenements en rappel et envoie un mail de rappel
  195. function _daemon($period) {
  196. $rs=selectQuery('select '.$this->tevt.'.*, '.$this->tagenda.'.tz, USERS.email '.
  197. 'from '.$this->tevt.','.$this->tlinks.','.$this->tagenda.',USERS '.
  198. 'where '.$this->tagenda.'.KOID='.$this->tlinks.'.KOIDD AND '.$this->tlinks.'.KOIDE='.$this->tevt.'.KOID AND '.
  199. 'USERS.KOID='.$this->tagenda.'.OWN AND '.
  200. 'UNIX_TIMESTAMP('.$this->tevt.'.begin)<=UNIX_TIMESTAMP("'.gmdate('Y-m-d H:i:s',time()).'")+'.$this->tevt.'.recall*60'.
  201. ' AND recall!=0');
  202. while($rs && $ev=$rs->fetch()) {
  203. date_default_timezone_set($ev['tz']);
  204. $rs2=&updateQuery('update '.$this->tevt.' set recall=0 where KOID="'.$ev['KOID'].'"');
  205. $mail=new XMail();
  206. $mail->_moid=$this->_moid;
  207. $mail->FromName='';
  208. $mail->From='noreply@xsalto.com';
  209. $mail->Subject='Rappel évènement';
  210. $mail->IsHTML(true);
  211. $mail->Body = 'Du '.date('d/m/Y H:i',strtotime($ev['begin'].' GMT')).' au '.
  212. date('d/m/Y H:i',strtotime($ev['end'].' GMT')).' : '.$ev['text'];
  213. $mail->AddAddress($ev['email']);
  214. $mail->Send();
  215. }
  216. return true;
  217. }
  218. /// suppression du module
  219. function delete($ar=NULL) {
  220. parent::delete($ar);
  221. }
  222. /// initialisation des proprietes
  223. public function initOptions() {
  224. parent::initOptions();
  225. $this->_options->setOpt('Vue par defaut', 'defview', 'list',
  226. array('values'=>array('displayDay', 'displayWeek', 'displayMonth', 'displayYear'),
  227. 'labels'=>array('Jour', 'Semaine','Mois', 'Annee')));
  228. $this->_options->setOpt('Alerte mail a la personne connectee','sendToUser', 'boolean', NULL ,false);
  229. $this->_options->setOpt('Agenda : table des agendas', 'tagenda', 'table');
  230. $this->_options->setOpt('Agenda : table des évènements', 'tevt', 'table');
  231. $this->_options->setOpt('Agenda : table des liens', 'tlinks', 'table');
  232. $this->_options->setOpt('Agenda : table des catégories d\'evenements', 'tcatevt', 'table');
  233. $this->_options->setOpt('Agenda : table des catégories d\'agendas', 'tcatagenda', 'table');
  234. $this->_options->setOpt('Planification : table des planifications', 'tplan', 'table');
  235. $this->_options->setOpt('Planification : table des paticipants', 'tplaninv', 'table');
  236. $this->_options->setOpt('Planification : table des dates', 'tplandates', 'table');
  237. $p1=XModule::findParam($this->_moid);
  238. $this->_options->setOpt('Categorie "agenda personnel"', 'catperso', 'object', array('table'=>$p1['MPARAM']['tcatagenda']));
  239. $this->_options->setOpt('Couleurs des agendas', 'tcolors', 'text',array('rows'=>5,'cols'=>50));
  240. }
  241. /// securite des fonctions accessibles par le web
  242. function secGroups($function, $group=NULL) {
  243. $g=array('index' =>array('ro','rw','rwv','admin'),
  244. 'displayDay' =>array('ro','rw','rwv','admin'),
  245. 'displayWeek' =>array('ro','rw','rwv','admin'),
  246. 'displayMonth' =>array('ro','rw','rwv','admin'),
  247. 'displayYear' =>array('ro','rw','rwv','admin'),
  248. 'addEvt' =>array('ro','rw','rwv','admin'),
  249. 'insertPlanif' =>array('rwv','admin'),
  250. 'procInsertPlanif' =>array('rwv','admin'),
  251. 'confirmPlanif' =>array('none','ro','rw','rwv','admin'),
  252. 'procConfirmPlanif' =>array('none','ro','rw','rwv','admin'),
  253. 'browsePlanif' =>array('rwv','admin'),
  254. 'displayPlanif' =>array('rwv','admin'),
  255. 'editPlanif' =>array('rwv','admin'),
  256. 'procEditPlanif' =>array('rwv','admin'),
  257. 'delPlanif' =>array('rwv','admin'),
  258. 'getEmails' =>array('ro','rw','rwv','admin'),
  259. 'saveEvt' =>array('rwv','admin'),
  260. 'saveFastEvt' =>array('rwv','admin'),
  261. 'editDiary' =>array('ro','rw','rwv','admin'),
  262. 'saveDiary' =>array('rwv','admin'),
  263. 'delEvt' =>array('rwv','admin'),
  264. 'exportEvt' =>array('ro','rw','rwv','admin'),
  265. 'saveExport' =>array('ro','rw','rwv','admin'),
  266. 'importEvt' =>array('rwv','admin'),
  267. 'saveImportTable' =>array('rwv','admin'),
  268. 'synchro' =>array('ro','rw','rwv','admin'),
  269. 'setDefault' =>array('ro','rw','rwv','admin'),
  270. 'addConsolidation' =>array('ro','rw','rwv','admin'),
  271. 'updateConsolidation' =>array('ro','rw','rwv','admin'),
  272. 'paramsConsolidation' =>array('ro','rw','rwv','admin'),
  273. 'ajaxEdit' =>array('rwv','admin'),
  274. 'ajaxDel' =>array('rwv','admin')
  275. );
  276. if(isset($g[$function])) {
  277. if(!empty($group)) return in_array($group, $g[$function]);
  278. return $g[$function];
  279. }
  280. return parent::secGroups($function,$group);
  281. }
  282. function ajaxEdit($ar=NULL){
  283. $p=new XParam($ar,NULL);
  284. $oid=$p->get('koid');
  285. $ar['oid']=$oid;
  286. $daybegin=$p->get('daybegin');
  287. $dayend=$p->get('dayend');
  288. $allday=$p->get('allday');
  289. if(!$allday) $ar['options']['begin']['togmt']=$ar['options']['end']['togmt']=true;
  290. if(!empty($oid)){
  291. $ors=selectQueryGetOne('select begin,KOIDS from '.$this->tevt.' where KOID="'.$oid.'" LIMIT 1');
  292. // 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
  293. if(!empty($ors['KOIDS'])){
  294. $ar['KOIDS']='';
  295. $date=substr($ors['begin'],0,10);
  296. $ors2=selectQueryGetOne('select except from '.$this->tevt.' where KOID="'.$ors['KOIDS'].'" LIMIT 1');
  297. if(empty($ors2['except'])) $except=$date;
  298. else $except=$ors2['except'].';'.$date;
  299. updateQuery('update '.$this->tevt.' set UPD=UPD, except="'.$except.'" where KOID="'.$ors['KOIDS'].'"');
  300. }else{
  301. $ors2=selectQueryGetOne('select KOID from '.$this->tevt.' where KOIDS="'.$oid.'" order by begin limit 1');
  302. // L'evenement fait parti d"une repetition et est pas l'evenement de base : la premiere repet devient l'evenement de base
  303. if(!empty($ors2)){
  304. updateQuery('update '.$this->tevt.' set KOIDS="'.$ors2['KOID'].'" where KOIDS="'.$oid.'"');
  305. updateQuery('update '.$this->tevt.' set KOIDS=NULL where KOID="'.$ors2['KOID'].'"');
  306. }
  307. }
  308. $ret=$this->xsetevt->procEdit($ar);
  309. }else{
  310. $text=$p->get('text');
  311. $begin=$p->get('begin');
  312. $end=$p->get('end');
  313. $ar1=array('text'=>$text,
  314. 'begindate'=>$begin['date'],
  315. 'beginhour'=>$begin['hour'],
  316. 'enddate'=>$end['date'],
  317. 'endhour'=>$end['hour'],
  318. 'visib'=>'PU',
  319. 'repet'=>'NO',
  320. 'recalltime'=>'',
  321. 'recalltype'=>'1',
  322. 'tplentry'=>TZR_RETURN_DATA);
  323. if($allday) $ar1['allday']=$ar1['allday_HID']=1;
  324. $ret=$this->saveEvt($ar1);
  325. $oid=$ret['oid'];
  326. }
  327. $ors=selectQueryGetAll($this->request['select'].' '.$this->request['from'].' where '.$this->tagenda.'.KOID='.$this->tlinks.'.KOIDD AND '.
  328. $this->tevt.'.KOID='.$this->tlinks.'.KOIDE AND '.$this->tevt.'.KOID="'.$oid.'" LIMIT 1');
  329. $this->convertEventTime($ors[0]);
  330. $this->cutEvents($ors,$daybegin,$dayend);
  331. $ors=$ors[0];
  332. die(json_encode(array('_isod'=>substr($ors['begin'],0,10),'_bd'=>$ors['_begindate'],'_bh'=>$ors['_beginhour'],
  333. '_ed'=>$ors['_enddate'],'_eh'=>$ors['_endhour'],
  334. '_obd'=>$ors['_cbegindate'],'_obh'=>$ors['_cbeginhour'],
  335. '_oed'=>$ors['_cenddate'],'_oeh'=>$ors['_cendhour'],
  336. 'oid'=>$ors['oid'],'text'=>$ors['otext']->html,'descr'=>$ors['odescr']->html,'place'=>$ors['oplace']->html,
  337. 'allday'=>($ors['allday']==1?'1':'0'),'color'=>$this->bloc['diariesprop'][$this->diary['KOID']]['color'],
  338. 'rw'=>1,'cat'=>$this->bloc['categories'][$ors['cat']]['color'],'url'=>$ors['_url'],'dname'=>$ors['DNAME']
  339. )));
  340. }
  341. function ajaxDel($ar=NULL){
  342. $ret=$this->delEvt($ar);
  343. if($ret) die(json_encode("ok"));
  344. else die(json_encode("nok"));
  345. }
  346. /// Action principale du menu
  347. public function getMainAction(){
  348. return $GLOBALS['TZR_SESSION_MANAGER']::complete_self().'moid='.$this->_moid.'&function='.$this->defview.'&oid='.$this->diary['KOID'].
  349. '&tplentry=br&template=xmodcalendar/'.$this->defview.'.html&now=1';
  350. }
  351. function secure($oid,$func,$user=NULL,$lang=TZR_DEFAULT_LANG){
  352. $evoid=@$_REQUEST['koid'];
  353. if($func=='addEvt' && empty($evoid) && !parent::secure($oid,'saveEvt',$user,$lang)){
  354. return false;
  355. }
  356. if($func=='saveEvt' && !empty($evoid)){
  357. $cnt=countSelectQuery('select COUNT(KOID) from '.$this->tevt.' where KOID="'.$evoid.'" and KOIDD="'.$this->diary['KOID'].'"');
  358. if($cnt==0) return false;
  359. }
  360. $table=Kernel::getTable($oid);
  361. if($table==$this->tplaninv){
  362. $ors=selectQueryGetOne('select who from '.$this->tplaninv.' where KOID="'.$oid.'" LIMIT 1');
  363. $who=$ors['who'];
  364. if(Kernel::getTable($who)==$this->tagenda){
  365. $ors=selectQueryGetOne('select OWN from '.$this->tagenda.' where KOID="'.$who.'" LIMIT 1');
  366. $who=$ors['OWN'];
  367. }
  368. if($who==XUser::get_current_user_uid()) return true;
  369. else return false;
  370. }
  371. return parent::secure($oid,$func,$user,$lang);
  372. }
  373. /// Recupere tous les notes et evenements du jour
  374. function &getTasklet(){
  375. $txt='';
  376. $date=date('Y-m-d');
  377. $display_begin_gmt=gmdate('Y-m-d H:i:s',strtotime($date.' 00:00:00'));
  378. $display_end_gmt=gmdate('Y-m-d H:i:s',strtotime($date.' 23:59:00'));
  379. $rs=$this->getAlls($display_begin_gmt,$display_end_gmt,$date.' 00:00:00',$date.' 23:59:59',
  380. 'where '.$this->tagenda.'.KOID='.$this->tlinks.'.KOIDD AND '.$this->tlinks.'.KOIDE='.$this->tevt.'.KOID AND '.
  381. '('.$this->tagenda.'.OWN="'.XUser::get_current_user_uid().'" OR '.$this->tagenda.'.KOID="'.$this->defcal.'")');
  382. while($rs && ($ors=$rs->fetch())){
  383. $this->getCompleteEvent($ors);
  384. $date=explode('-',$ors['begin']);
  385. $url=$GLOBALS['TZR_SESSION_MANAGER']::complete_self().'&oid='.$ors['DKOID'].'&moid='.$this->_moid.'&_function=displayDay&'.
  386. 'template=xmodcalendar/displayDay.html&tplentry=br&day='.substr($date[2],0,2).'&month='.$date[1].'&year='.$date[0];
  387. $txt.='<p><a href="'.$url.'">'.$ors['text'].'</a> se d&eacute;roule aujourd\'hui';
  388. if($ors['allday']!=1){
  389. $txt.=' (de '.date('H\hi',strtotime($ors['begin']. 'GMT')).' &agrave; '.date('H\hi',strtotime($ors['end'].' GMT')).')';
  390. }
  391. $txt.='.</p>';
  392. }
  393. return $txt;
  394. }
  395. function getShortTasklet(){
  396. return $this->getTasklet();
  397. }
  398. /// synchronisation des agendas
  399. function synchro($ar=NULL){
  400. $p=new XParam($ar,array());
  401. $this->synchro=true;
  402. $rw=$this->secure($p->get('oid'), 'importEvt');
  403. if($_SERVER["REQUEST_METHOD"]=='PROPFIND'){
  404. die();
  405. }
  406. if(!empty($_REQUEST['phpputdata'])) {
  407. if($rw){
  408. $_FILES['filetoimp']['tmp_name']=$_REQUEST['phpputdata'];
  409. $_FILES['filetoimp']['size']=filesize($filename);
  410. $_FILES['filetoimp']['name']='Importics.ics';
  411. $this->importEvt($ar);
  412. }else{
  413. header("HTTP/1.0 404 Not Found");
  414. }
  415. }else{
  416. $ar['period']='all';
  417. $this->saveExport($ar);
  418. }
  419. $id=session_id();
  420. session_destroy();
  421. die();
  422. }
  423. function index($ar=NULL) {
  424. $p=new XParam($ar,array());
  425. $tplentry=$p->get('tplentry');
  426. $r=array();
  427. if($tplentry=='*return*') {
  428. return $r;
  429. } else {
  430. $this->setTplCommons();
  431. XShell::toScreen1($tplentry,$r);
  432. }
  433. }
  434. /// cette fonction est appliquee pour afficher l'ensemble des methodes de ce module
  435. protected function _actionlist(&$my=NULL) {
  436. if(!$this->day) $date='now';
  437. else $date='day='.$this->day.'&month='.$this->month.'&year='.$this->year;
  438. $uniqid=XShell::uniqid();
  439. $moid=$this->_moid;
  440. $dir='xmodcalendar';
  441. $oidcal=@$this->diary['KOID'];
  442. parent::_actionlist($my);
  443. if($this->interactive) {
  444. $o1=new XModuleAction($this,'def',$this->modulename,
  445. '&moid='.$moid.'&_function='.$this->defview.'&tplentry=br&template='.$dir.'/'.$this->defview.'.html&now','display');
  446. $my['stack'][]=$o1;
  447. if(!empty($oidcal)){
  448. $o1=new XModuleAction($this,'diary',$this->diary['name'],
  449. '&moid='.$moid.'&oid='.$oidcal.'&_function='.$this->defview.'&tplentry=br&template='.$dir.'/'.$this->defview.'.html&now',
  450. 'display');
  451. $my['stack'][]=$o1;
  452. }
  453. }
  454. if(empty($oidcal)) return;
  455. // Liste des agendas
  456. if(!empty($this->bloc['diary_list']['lines_oid']) && count($this->bloc['diary_list']['lines_oid'])>1){
  457. $o1=new XModuleAction($this,'chooseag', XLabels::getSysLabel('xmodcalendar','diary','text'),'#');
  458. $o1->newgroup='chooseag';
  459. $o1->menuable=true;
  460. $my['chooseag']=$o1;
  461. foreach($this->bloc['diary_list']['lines_oid'] as $i=>$oid){
  462. $o1=new XModuleAction($this,'chooseag', $this->bloc['diary_list']['lines_oname'][$i]->html,
  463. '&moid='.$this->_moid.'&oid='.$oid.'&function='.$this->defview.'&tplentry=br&template=xmodcalendar/'.$this->defview.'.html&now','chooseag');
  464. $o1->menuable=true;
  465. $my['chooseag'.$i]=$o1;
  466. }
  467. }
  468. // Assigner agenda par defaut
  469. $o1=new XModuleAction($this, 'setDefault', XLabels::getSysLabel('xmodcalendar','default','text'),
  470. '&moid='.$moid.'&oid='.$oidcal.'&display='.XShell::_function().'&_function=setDefault','edit');
  471. $o1->menuable=true;
  472. $my['setDefault']=$o1;
  473. // Aujourd'hui
  474. $o1=new XModuleAction($this, 'displayToday', XLabels::getSysLabel('xmodcalendar','today','text'),
  475. '&moid='.$moid.'&oid='.$oidcal.
  476. '&_function='.$this->defview.'&tplentry=br&template='.$dir.'/'.$this->defview.'.html&now','display');
  477. $o1->setToolbar('xmodcalendar','today');
  478. $my['displaytoday']=$o1;
  479. // Affichage quotidien
  480. $o1=new XModuleAction($this, 'displayDay', XLabels::getSysLabel('xmodcalendar','displayday','text'),
  481. '&moid='.$moid.'&oid='.$oidcal.
  482. '&_function=displayDay&tplentry=br&template='.$dir.'/displayDay.html&'.$date,'display');
  483. $o1->setToolbar('xmodcalendar','displayday');
  484. $my['displayday']=$o1;
  485. // Affichage hebdo
  486. $o1=new XModuleAction($this, 'displayWeek', XLabels::getSysLabel('xmodcalendar','displayweek','text'),
  487. '&moid='.$moid.'&oid='.$oidcal.
  488. '&_function=displayWeek&tplentry=br&template='.$dir.'/displayWeek.html&'.$date,'display');
  489. $o1->setToolbar('xmodcalendar','displayweek');
  490. $my['displayweek']=$o1;
  491. // Affichage mensuel
  492. $o1=new XModuleAction($this, 'displayMonth', XLabels::getSysLabel('xmodcalendar','displaymonth','text'),
  493. '&moid='.$moid.'&oid='.$oidcal.
  494. '&_function=displayMonth&tplentry=br&template='.$dir.'/displayMonth.html&'.$date,'display');
  495. $o1->setToolbar('xmodcalendar','displaymonth');
  496. $my['displaymonth']=$o1;
  497. // Affichage annuel
  498. $o1=new XModuleAction($this, 'displayYear', XLabels::getSysLabel('xmodcalendar','displayyear','text'),
  499. '&moid='.$moid.'&oid='.$oidcal.
  500. '&_function=displayYear&tplentry=br&template='.$dir.'/displayYear.html&'.$date,'display');
  501. $o1->setToolbar('xmodcalendar','displayyear');
  502. $my['displayyear']=$o1;
  503. // Parcourir planification en cours
  504. if($this->secure($this->diary['KOID'],'browsePlanif')){
  505. $o1=new XModuleAction($this, 'browsePlanif', XLabels::getSysLabel('xmodcalendar','browseplanif','text'),
  506. '&moid='.$moid.'&oid='.$oidcal.'&_function=browsePlanif&template=xmodcalendar/browsePlanif.html&tplentry=br',
  507. 'edit');
  508. $o1->menuable=true;
  509. $o1->separator=true;
  510. $my['browsePlanif']=$o1;
  511. }
  512. // Ajouter planification
  513. if($this->secure($this->diary['KOID'],'insertPlanif')){
  514. $o1=new XModuleAction($this, 'insertPlanif', XLabels::getSysLabel('xmodcalendar','insertplanif','text'),
  515. '&moid='.$moid.'&oid='.$oidcal.'&_function=insertPlanif&template=xmodcalendar/newPlanif.html&tplentry=br',
  516. 'edit');
  517. $o1->menuable=true;
  518. $my['insertPlanif']=$o1;
  519. }
  520. // Next et prev dans la toolbar
  521. $tb=XShell::from_screen('br','toolbar');
  522. if(!empty($tb['prev'])) {
  523. $o1=new XModuleAction($this, 'next', XLabels::getSysLabel('general','previous','text'),
  524. '&moid='.$moid.'&oid='.$oidcal.
  525. '&_function='.XShell::_function().'&tplentry=br&template='.$_REQUEST['template'].'&'.$tb['prev'],'display');
  526. $o1->setToolbar('general','previous');
  527. $my['previous']=$o1;
  528. }
  529. if(!empty($tb['next'])) {
  530. $o1=new XModuleAction($this, 'next', XLabels::getSysLabel('general','next','text'),
  531. '&moid='.$moid.'&oid='.$oidcal.
  532. '&_function='.XShell::_function().'&tplentry=br&template='.$_REQUEST['template'].'&'.$tb['next'],'display');
  533. $o1->setToolbar('general','next');
  534. $my['next']=$o1;
  535. }
  536. // Edition de l'agenda courant
  537. if(!empty($oidcal)){
  538. $o1=new XModuleAction($this,'edit',XLabels::getSysLabel('xmodcalendar','editdiary','text'),
  539. '&moid='.$moid.'&oid='.$oidcal.'&_function=editDiary&tplentry=br&'.
  540. 'template=xmodcalendar/editDiary.html&day='.$this->day.'&month='.$this->month.'&year='.$this->year,'edit');
  541. $o1->order=2;
  542. $o1->setToolbar('general','edit');
  543. $my['edit']=$o1;
  544. }
  545. // Abonnement
  546. $modsubmoid=XModule::getMoid(XMODSUB_TOID);
  547. if(!empty($modsubmoid)){
  548. $o1=new XModuleAction($this, 'subscribe', XLabels::getSysLabel('xmodsub','subadd','text'),
  549. 'javascript:v'.$uniqid.'.addSub("'.$modsubmoid.'","'.$oidcal.'");','more');
  550. $o1->menuable=true;
  551. $my['subscribe']=$o1;
  552. }
  553. }
  554. protected function _lasttimestamp() {
  555. $rs=selectQueryByNum('select MAX(UPD) from '.$this->tlinks);
  556. if($ors=$rs->fetch()) {
  557. $rs->closeCursor();
  558. return $ors[0];
  559. }
  560. return 0;
  561. }
  562. function _whatsNew($ts,$user,$group=NULL,$specs=NULL,$timestamp) {
  563. list($oid)=explode(';',$specs);
  564. if($oid){
  565. $lvl=XUser::secure8maxlevel($this,$oid);
  566. if(in_array($lvl,array('rw','rwv','admin'))){
  567. $rs=selectQuery('select '.$this->tlinks.'.* from '.$this->tlinks.' left outer join '.$this->tevt.' on '.
  568. $this->tevt.'.KOID='.$this->tlinks.'.KOIDE where '.$this->tlinks.'.UPD>="'.$ts.'" and '.
  569. $this->tlinks.'.KOIDD="'.$oid.'"');
  570. }elseif($lvl=='ro'){
  571. $rs=selectQuery('select '.$this->tlinks.'.* from '.$this->tlinks.' left outer join '.$this->tevt.' on '.
  572. $this->tevt.'.KOID='.$this->tlinks.'.KOIDE where '.$this->tlinks.'.UPD>="'.$ts.'" and '.
  573. $this->tlinks.'.KOIDD="'.$oid.'" and '.$this->tevt.'.visib="PU"');
  574. }
  575. }else{
  576. $prcals=$this->getAuthorizedDiaries('ro','array',true);
  577. $pucals=$this->getAuthorizedDiaries('rw','array',true);
  578. $prcals=implode('","',array_diff($prcals,$pucals));
  579. $pucals=implode('","',$pucals);
  580. $rs=selectQuery('select '.$this->tlinks.'.* from '.$this->tlinks.' left outer join '.$this->tevt.' on '.
  581. $this->tevt.'.KOID='.$this->tlinks.'.KOIDE where '.$this->tlinks.'.UPD>="'.$ts.'" and '.
  582. '((visib="PU" and '.$this->tlinks.'.KOIDD in ("'.$prcals.'")) or ('.$this->tlinks.'.KOIDD in ("'.$pucals.'"))) '.
  583. 'order by '.$this->tlinks.'.KOIDE');
  584. }
  585. $txt='';
  586. $prevoid='';
  587. $rs2=selectQuery('select KOID,name from '.$this->tagenda);
  588. $diaries=array();
  589. while($rs2 && ($ors2=$rs2->fetch())){
  590. $diaries[$ors2['KOID']]=$ors2['name'];
  591. }
  592. while($rs && ($ors=$rs->fetch())){
  593. if($prevoid!=$ors['KOIDE']){
  594. $d=$this->xsetevt->display(array('oid'=>$ors['KOIDE'],'tplentry'=>TZR_RETURN_DATA));
  595. $when=$d['oUPD']->html;
  596. $who=$d['lst_upd']['usernam'];
  597. $prevoid=$ors['KOIDE'];
  598. }
  599. $txt.='<li><a href="'.$GLOBALS['TZR_SESSION_MANAGER']::admin_url(true,false).'moid='.$this->_moid.'&function=addEvt&mode=view&oid='.$ors['KOIDD'].
  600. '&koid='.$d['oid'].'&tplentry=br&template=xmodcalendar/addEvt.html&_direct=1">"'.$d['otext']->html.'"</a> sur "'.$diaries[$ors['KOIDD']].'" '.
  601. '('.$when.', '.$who.')</li>';
  602. }
  603. return $txt;
  604. }
  605. function actionListAdd(&$my,$f){
  606. if(!$this->group_of_diary && $this->diary['rwsecure']){
  607. $o1=new XModuleAction($this,'addevt',XLabels::getSysLabel('xmodcalendar','addevt','text'),
  608. '&moid='.$this->_moid.'&_function=addEvt&tplentry=br&template=xmodcalendar/addEvt.html&oid='.$this->diary['KOID'].
  609. '&day='.$this->day.'&month='.$this->month.'&year='.$this->year.'&display='.$f,'edit');
  610. $o1->setToolbar('xmodcalendar','addevt');
  611. $my['addevt']=$o1;
  612. $o1=new XModuleAction($this,'import',XLabels::getSysLabel('xmodcalendar','importevt','text'),
  613. '&moid='.$this->_moid.'&_function=importEvt&tplentry=br&template=xmodcalendar/importEvt.html&oid='.$this->diary['KOID'].
  614. '&day='.$this->day.'&month='.$this->month.'&year='.$this->year.'&display='.$f,'edit');
  615. $o1->menuable=true;
  616. $my['importevt']=$o1;
  617. }
  618. $o1=new XModuleAction($this,'export',XLabels::getSysLabel('xmodcalendar','exportevt','text'),
  619. '&moid='.$this->_moid.'&_function=exportEvt&tplentry=br&template=xmodcalendar/exportEvt.html&oid='.$this->diary['KOID'].
  620. '&day='.$this->day.'&month='.$this->month.'&year='.$this->year.'&display='.$f,'edit');
  621. $o1->menuable=true;
  622. $my['exportevt']=$o1;
  623. }
  624. function al_displayDay(&$my){
  625. // Si pas d'utilisateur, ca ne sert à rien de continuer car on est dans un upgrade
  626. if(empty($GLOBALS['XUSER']) || XUser::isNobody()) return;
  627. $uniqid=XShell::uniqid();
  628. $moid=$this->_moid;
  629. $oidcal=@$this->diary['KOID'];
  630. $cons=$this->getDiariesForConsolidation();
  631. $f=XShell::_function();
  632. $this->actionListAdd($my,$f);
  633. $o1=new XModuleAction($this, 'cons', XLabels::getSysLabel('xmodcalendar','consolidation','text'),'#','edit');
  634. $o1->newgroup='cons_index';
  635. $o1->menuable=true;
  636. $my['cons']=$o1;
  637. $auths=$this->getAuthorizedDiaries();
  638. foreach($auths as $oid){
  639. if($oid==$this->diary['KOID'] || !empty($cons['list'][$oid])) continue;
  640. if(empty($my['consag'])){
  641. $o1=new XModuleAction($this, 'consag', XLabels::getSysLabel('xmodcalendar','diary','text'),'#');
  642. $o1->group='cons_index';
  643. $o1->newgroup='consag_index';
  644. $o1->menuable=true;
  645. $my['consag']=$o1;
  646. }
  647. $ors=selectQueryGetAll('select name from '.$this->tagenda.' where KOID="'.$oid.'"');
  648. $o1=new XModuleAction($this, 'consag', $ors[0]['name'],'javascript:v'.$uniqid.'.addConsolidation("'.$oid.'");');
  649. $o1->group='consag_index';
  650. $o1->menuable=true;
  651. $my['consag'.$oid]=$o1;
  652. }
  653. $o1=new XModuleAction($this, 'consmod', XLabels::getSysLabel('general','module','text'),'#');
  654. $o1->group='cons_index';
  655. $o1->newgroup='consmod_index';
  656. $o1->menuable=true;
  657. $my['consmod']=$o1;
  658. $mods=XModule::authorizedModules();
  659. $rs=&cacheSelectQuery('select MOID,MODULE from MODULES where TOID in("'.XMODTABLE_TOID.'") order by MODULE');
  660. while($rs && ($ors=$rs->fetch())){
  661. $moid=$ors['MOID'];
  662. if(!in_array($moid,$mods) || !empty($cons['list'][$moid])) continue;
  663. $o1=new XModuleAction($this, 'consag', $ors['MODULE'],'javascript:v'.$uniqid.'.addConsolidation("'.$moid.'");');
  664. $o1->group='consmod_index';
  665. $o1->menuable=true;
  666. $my['consmod'.$ors['MODULE']]=$o1;
  667. }
  668. }
  669. function al_displayWeek(&$my){
  670. $this->al_displayDay($my);
  671. }
  672. function al_displayMonth(&$my){
  673. $this->al_displayDay($my);
  674. }
  675. function al_displayYear(&$my){
  676. $this->al_displayDay($my);
  677. }
  678. function al_addEvt(&$my){
  679. $this->actionListAdd($my,$_REQUEST['display']);
  680. }
  681. function al_editDiary(&$my){
  682. $this->actionListAdd($my,$_REQUEST['display']);
  683. }
  684. function al_exportEvt(&$my){
  685. $this->actionListAdd($my,$_REQUEST['display']);
  686. }
  687. function al_importEvt(&$my){
  688. }
  689. function al_browsePlanif(&$my){
  690. $uniqid=XShell::uniqid();
  691. $o1=new XModuleAction($this,'delPlan',XLabels::getSysLabel('general','delete','text'),'javascript:v'.$uniqid.'.deleteselected();','edit');
  692. $o1->order=3;
  693. $o1->setToolbar('general','delete');
  694. $my['delPlan']=$o1;
  695. }
  696. function al_displayPlanif(&$my){
  697. $o1=new XModuleAction($this,'editPlan',XLabels::getSysLabel('general','edit','text'),str_replace('function=displayPlanif','function=editPlanif',$_SERVER['REQUEST_URI']),'edit');
  698. $o1->menuable=true;
  699. $my['editPlan']=$o1;
  700. }
  701. /// Afficher les infos sur une journee
  702. function displayDay($ar=NULL) {
  703. $p=new XParam($ar,array());
  704. $this->bloc['calendar_mode']='';
  705. $this->createCalendar($p);
  706. $display_begin_gmt=gmdate('Y-m-d H:i:s',strtotime($this->date.' 00:00:00'));
  707. $display_end_gmt=gmdate('Y-m-d H:i:s',strtotime($this->date.' 23:59:00'));
  708. $this->display_begin=date('Y-m-d H:i:s',strtotime($this->date.' 00:00:00'));
  709. $this->display_end=date('Y-m-d H:i:s',strtotime($this->date.' 23:59:00'));
  710. $day_begin=$this->diary['beginnum'];
  711. $day_end=$this->diary['endnum'];
  712. // Recupere les notes et evenements
  713. $notes=$this->getNotes($this->display_begin,$this->display_end,false,true);
  714. $events=$this->getEvents($display_begin_gmt,$display_end_gmt,false,true);
  715. $this->getDisplayHours($events,$day_begin,$day_end);
  716. $this->cutNotes($notes);
  717. $this->cutEvents($events,$day_begin,$day_end);
  718. // Construit les infos a envoyer au template
  719. $this->bloc['daybegin']=$day_begin;
  720. $this->bloc['dayend']=$day_end;
  721. $this->bloc['dates']=array($this->date);
  722. $this->bloc['events']=$events;
  723. $this->bloc['notes']=$notes;
  724. $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')),
  725. 'next'=>date('\d\a\y=j&\m\o\n\t\h=n&\y\e\a\r=Y',strtotime($this->date.' +1 day')));
  726. return XShell::toScreen1('br',$this->bloc);
  727. }
  728. /// Afficher les infos sur une semaine
  729. function displayWeek($ar=NULL) {
  730. $p=new XParam($ar,array());
  731. $first_day_week=$this->calculateWeekDetails($p);
  732. $this->createCalendar($p);
  733. $display_begin_gmt=gmdate('Y-m-d H:i:s',$first_day_week);
  734. $display_end_gmt=gmdate('Y-m-d H:i:s',strtotime('+7 day -1 minute',$first_day_week));
  735. $this->display_begin=date('Y-m-d H:i:s',$first_day_week);
  736. $this->display_end=date('Y-m-d H:i:s',strtotime('+7 day -1 minute',$first_day_week));
  737. $day_begin=$this->diary['beginnum'];
  738. $day_end=$this->diary['endnum'];
  739. // Recupere les notes et evenements
  740. $notes=$this->getNotes($this->display_begin,$this->display_end,false,true);
  741. $events=$this->getEvents($display_begin_gmt,$display_end_gmt,false,true);
  742. $this->getDisplayHours($events,$day_begin,$day_end);
  743. $this->cutNotes($notes);
  744. $this->cutEvents($events,$day_begin,$day_end);
  745. // Construit les infos a envoyer au template
  746. $this->bloc['daybegin']=$day_begin;
  747. $this->bloc['dayend']=$day_end;
  748. $this->bloc['dates']=array();
  749. for($i=0;$i<7;$i++) $this->bloc['dates'][]=date('Y-m-d',strtotime('+'.$i.' day',$first_day_week));
  750. $this->bloc['events']=$events;
  751. $this->bloc['notes']=$notes;
  752. $this->bloc['toolbar']=array('prev'=>date('\w\e\e\k=W&\y\e\a\r=o',strtotime('-1 week '.$this->date)),
  753. 'next'=>date('\w\e\e\k=W&\y\e\a\r=o',strtotime('+1 week '.$this->date))
  754. );
  755. return XShell::toScreen1('br',$this->bloc);
  756. }
  757. /// Afficher les infos sur un mois
  758. function displayMonth($ar=NULL) {
  759. $p=new XParam($ar,array());
  760. $events=$table=array();
  761. $this->day=1;
  762. $this->createCalendar($p);
  763. $month_list_label=XLabels::getSysLabel('xmodcalendar','monthlist','text');
  764. $this->bloc['header']=$month_list_label[$this->month-1].' '.$this->year;
  765. // Les infos a afficher sont deja calculer pour le mini calendrier du bas. On les recupere donc pour les afficher en entier
  766. $this->bloc['body']=$this->cal_content;
  767. $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')),
  768. 'next'=>date('\d\a\y=1&\m\o\n\t\h=n&\y\e\a\r=Y',strtotime($this->date.' +1 month'))
  769. );
  770. return XShell::toScreen1('br',$this->bloc);
  771. }
  772. /// Afficher les infos sur une annee
  773. function displayYear($ar=NULL) {
  774. $p=new XParam($ar,array());
  775. $month_list_label=XLabels::getSysLabel('xmodcalendar','monthlist','text');
  776. $this->createCalendar($p);
  777. $display_begin_gmt=gmdate('Y-m-d H:i:s',strtotime($this->year.'-01-01 00:00:00'));
  778. $display_end_gmt=gmdate('Y-m-t H:i:s',strtotime($this->year.'-12-31 23:59:00'));
  779. $this->display_begin=date('Y-m-d H:i:s',strtotime($this->year.'-01-01 00:00:00'));
  780. $this->display_end=date('Y-m-t H:i:s',strtotime($this->year.'-12-31 23:59:00'));
  781. // Recupere les notes et les evenements
  782. $rs=$this->getAlls($display_begin_gmt,$display_end_gmt,$this->display_begin,$this->display_end);
  783. while($rs && ($event=$rs->fetch())) {
  784. $this->convertEventTime($event);
  785. $begin=date('z',strtotime($event['begin']));
  786. $end=date('z',strtotime($event['end']));
  787. for($i=$begin;$i<=$end;$i++) $events[$i]=1;
  788. }
  789. for($j=1;$j<13;$j++) {
  790. $nb_day_prev_month=date('t', mktime(12,0,0,$j-1,1,$this->year));
  791. $nb_day_month=date('t', mktime(12,0,0,$j,1,$this->year));
  792. $first_day=date('N',mktime(12,00,00,$j,1,$this->year));
  793. $last_day=date('N',mktime(12,00,00,$j+1,0,$this->year));
  794. $day_of_year=date('z',mktime(12,00,00,$j,1,$this->year));
  795. $prev_month=date('n',mktime(12,00,00,$j-1,1,$this->year));
  796. $next_month=date('n',mktime(12,00,00,$j+1,1,$this->year));
  797. $prev_year=date('Y',mktime(12,00,00,$j-1,1,$this->year));
  798. $next_year=date('Y',mktime(12,00,00,$j+1,1,$this->year));
  799. $month_content=array();
  800. for($i=$first_day-2;$i>-1;$i--) {
  801. $month_content[]=array('day'=>$nb_day_prev_month-$i,'month'=>$prev_month,'year'=>$prev_year,'event'=>false,'style'=>'out');
  802. }
  803. for($i=1;$i<=$nb_day_month;$i++) {
  804. $month_content[]=array('day'=>$i,'month'=>$j,'year'=>$this->year,'event'=>(isset($events[$day_of_year+$i-1]))?true:false,
  805. 'style'=>'in');
  806. }
  807. for($i=1;$i<8-$last_day;$i++) {
  808. $month_content[]=array('day'=>$i,'month'=>$next_month,'year'=>$next_year,'event'=>false,'style'=>'out');
  809. }
  810. $content[$j]=array('header'=>$month_list_label[$j-1].' '.$this->year,'content'=>$month_content);
  811. }
  812. $this->bloc['body']=$content;
  813. $this->bloc['toolbar']=array('prev'=>'day=1&month1=n&year='.($this->year-1),'next'=>'day=1&month1=n&year='.($this->year+1));
  814. return XShell::toScreen1('br',$this->bloc);
  815. }
  816. /// Retourne une liste d'evenements/notes/tous sur une periode
  817. function browsePeriod($ar=NULL){
  818. $p=new XParam($ar,array('type'=>'all','begin'=>'1970-01-01','end'=>'2037-12-31'));
  819. $type=$p->get('type');
  820. $begin=$p->get('begin');
  821. $end=$p->get('end');
  822. $tplentry=$p->get('tplentry');
  823. $getrsonly=$p->get('getrsonly');
  824. if($type=='all') $rs=$this->getAlls(gmdate('Y-m-d H:i:s',strtotime($begin.' 00:00:00')),
  825. gmdate('Y-m-d H:i:s',strtotime($end.' 23:59:00')),
  826. $begin.' 00:00:00',$end.' 23:59:59');
  827. if($getrsonly) return $rs;
  828. $result=array();
  829. while($rs && ($ors=$rs->fetch())){
  830. $this->getCompleteEvent($ors);
  831. $ors['_begindate']=date('d/m/Y',strtotime($ors['begin'].' GMT'));
  832. $ors['_beginhour']=date('H:i',strtotime($ors['begin'].' GMT'));
  833. $ors['_enddate']=date('d/m/Y',strtotime($ors['end'].' GMT'));
  834. $ors['_endhour']=date('H:i',strtotime($ors['end'].' GMT'));
  835. $result[]=$ors;
  836. }
  837. return XShell::toScreen2($tplentry,'list',$result);
  838. }
  839. /// rend les emails d'un user ou des users d'un groupe
  840. function getEmails($ar=NULL) {
  841. $p=new XParam($ar, array());
  842. $doid=$p->get("doid");
  843. if(Kernel::getTable($doid)=='GRP') {
  844. $users = XModGroup::users(array($doid));
  845. } else {
  846. $users=array($doid);
  847. }
  848. $emails=array();
  849. foreach($users as $oid) {
  850. $xuser=new XUser(array("UID"=>$oid));
  851. $emails[]=$xuser->email();
  852. unset($xuser);
  853. }
  854. echo json_encode($emails);
  855. exit(0);
  856. }
  857. /// Ajout/edition/consultation d'un evenement
  858. function addEvt($ar=NULL) {
  859. $p=new XParam($ar,array('getintattendees'=>true,'hour'=>'08:00:00'));
  860. $mode=$p->get('mode');
  861. $oid=$p->get('oid');
  862. $koid=$p->get('koid');
  863. $hour=$p->get('hour');
  864. $allday=$p->get('allday');
  865. $getintattendees=$p->get('getintattendees');
  866. // Definit la fonction a executer
  867. if($mode=='view'){
  868. $function='display';
  869. $secure=false;
  870. }else{
  871. $secure=$this->secure($oid,'saveEvt');
  872. if(empty($koid) && $secure) $function="input";
  873. elseif($secure) $function="edit";
  874. else $function="display";
  875. }
  876. if(!empty($koid)){
  877. $ors=selectQueryGetOne('select * from '.$this->tevt.' where KOID="'.$koid.'" LIMIT 1');
  878. if(!empty($ors['KOIDS'])) $ar['oid']=$ors['KOIDS'];
  879. else $ar['oid']=$koid;
  880. if($ors['allday']!=1){
  881. $ar['options']['begin']['tz']='GMT';
  882. $ar['options']['end']['tz']='GMT';
  883. }
  884. }else{
  885. $ar['options']['begin']['value']=$this->date.' '.$hour;
  886. $ar['options']['end']['value']=date('Y-m-d H:i:s',strtotime($this->date.' '.$hour.' +1 hour'));
  887. }
  888. $ar['tplentry']=TZR_RETURN_DATA;
  889. $this->xsetevt->desc['end_rep']->compulsory=true;
  890. $ev=$this->xsetevt->$function($ar);
  891. $ev['secure']=$secure;
  892. // Formate les donnees dans le cas d'une edition
  893. if(!empty($koid)) {
  894. if(!empty($ev['oexcept']->raw)) {
  895. $datedef=new XDateDef();
  896. $tab_except=explode(';',$ev['oexcept']->raw);
  897. foreach($tab_except as $tmp) $this->bloc['except'][$tmp]=$datedef->dateFormat($tmp);
  898. }
  899. $rs=selectQuery('SELECT KOIDD from '.$this->tlinks.' where KOIDE="'.$koid.'" and KOIDD!="'.$this->diary['KOID'].'"');
  900. while($rs && ($attendee=$rs->fetch())) $all_attendees[$attendee['KOIDD']]='';
  901. }
  902. // Liste des differents mode de repetition et champ date except
  903. $this->bloc['repetition']=array('NO'=>XLabels::getSysLabel('xmodcalendar','repetition','text'),
  904. 'DAILY'=>XLabels::getSysLabel('xmodcalendar','daily','text'),
  905. 'WEEKLY'=>XLabels::getSysLabel('xmodcalendar','weekly','text'),
  906. 'MONTHLY'=>XLabels::getSysLabel('xmodcalendar','monthly','text'),
  907. 'YEARLY'=>XLabels::getSysLabel('xmodcalendar','annual','text'));
  908. $xdatedef=clone($this->xsetevt->desc['end_rep']);
  909. $xdatedef->compulsory=false;
  910. $ev['oexcepttmp']=$xdatedef->edit($v='',$opt=array('fieldname'=>'excepttmp'));
  911. // Prepare la liste des invites possible (par defaut, liste des agendas non consolides)
  912. if($getintattendees){
  913. if(!defined('TZR_ALTERNATIVE_SENDTO_DIRECTORY') && !defined('TZR_ALTERNATIVE_CALINTERNE_DIRECTORY')){
  914. if($this->object_sec){
  915. if($function=='display') $cplt=' AND KOID IN ('.$this->getAuthorizedDiaries('ro','sql').')';
  916. else $cplt=' AND KOID IN ('.$this->getAuthorizedDiaries('rwv','sql').')';
  917. }else{
  918. $cplt='';
  919. }
  920. $xset=XDataSource::objectFactoryHelper8('BCLASS=XDSTable&SPECS='.$this->tagenda);
  921. $vals=implode('||',array_keys($all_attendees));
  922. $opts=array('filter'=>'(cons IS NULL OR cons!=1) and KOID!="'.$this->diary['KOID'].'"'.$cplt);
  923. if($function=='display') $ev['oattendees']=&$xset->desc['agcons']->display($vals,$opts);
  924. else $ev['oattendees']=&$xset->desc['agcons']->edit($vals,$opts);
  925. }else{
  926. if(defined('TZR_ALTERNATIVE_CALINTERNE_DIRECTORY')) $altmoid=TZR_ALTERNATIVE_CALINTERNE_DIRECTORY;
  927. else $altmoid=TZR_ALTERNATIVE_SENDTO_DIRECTORY;
  928. $mod=XModule::objectFactory($altmoid);
  929. $list=&$mod->browse(array('tplentry'=>TZR_RETURN_DATA,'pagesize'=>999,'_options'=>array('local'=>true),'tlink'=>true));
  930. foreach($list['lines_oid'] as $i=>$oid){
  931. if(isset($all_attendees[$oid])) {
  932. $attendees[$oid]=$list['lines_tlink'][$i];
  933. } else {
  934. $users_unselected[$oid]=$list['lines_tlink'][$i];
  935. }
  936. }
  937. $this->bloc['attendees']=$attendees;
  938. $this->bloc['users_unselected']=$users_unselected;
  939. }
  940. $ev['oattendees']->sys=false;
  941. }else{
  942. $ev['oattendees']->sys=true;
  943. }
  944. if(!empty($ev['oattext'])){
  945. list($acl_user, $acl_grp)=XUser::getUsersAndGroups();
  946. XShell::toScreen1('users',$acl_user);
  947. XShell::toScreen1('grps',$acl_grp);
  948. }
  949. XShell::toScreen1('ev',$ev);
  950. return XShell::toScreen1('br',$this->bloc);
  951. }
  952. /// Sauvegarde un evenement
  953. public function saveEvt($ar=NULL) {
  954. $p=new XParam($ar,array());
  955. $koid=$p->get('koid');
  956. $text=$p->get('text');
  957. $cat=$p->get('cat');
  958. $place=$p->get('place');
  959. $descr=$p->get('descr');
  960. $visib=$p->get('visib');
  961. if(empty($visib)) $visib='PU';
  962. $repet=$p->get('repetition');
  963. $recalltime=$p->get('recalltime');
  964. $recalltype=$p->get('recalltype');
  965. $allday=$p->get('allday');
  966. $allday_HID=$p->get('allday_HID');
  967. $attext=$p->get('attext');
  968. $excepttab=$p->get('except');
  969. $xset_link=XDataSource::objectFactoryHelper8('BCLASS=XDSTable&SPECS='.$this->tlinks);
  970. $allday=$this->xsetevt->desc['allday']->post_edit($allday,array('allday_HID'=>$allday_HID));
  971. $allday=$allday->raw;
  972. $datedef=new XDateDef();
  973. $ar1=array();
  974. $except=$except_mail=null;
  975. $list_mail_text='';
  976. $attselected=$p->get('selected');
  977. // Recupere l'agenda de l'evenement (si modifiation sur un agenda consolide, recupere l'agenda de l'evenement, sinon agenda courant)
  978. if($this->group_of_diary && !empty($koid)) {
  979. $rs=selectQuery('SELECT KOIDD FROM '.$this->tevt.' where KOID="'.$koid.'"');
  980. $tmp=$rs->fetch();
  981. $diary=$tmp['KOIDD'];
  982. } else {
  983. $diary=$this->diary['KOID'];
  984. }
  985. // Formatage des dates/heures
  986. $foo=$p->get('begin');
  987. if(!empty($foo) && is_array($foo)){
  988. $begindate=$foo['date'];
  989. $beginhour=$foo['hour'];
  990. }else{
  991. $begindate=$p->get('begindate');
  992. $beginhour=$p->get('beginhour');
  993. }
  994. $foo=$p->get('end');
  995. if(!empty($foo) && is_array($foo)){
  996. $enddate=$foo['date'];
  997. $endhour=$foo['hour'];
  998. }else{
  999. $enddate=$p->get('enddate');
  1000. $endhour=$p->get('endhour');
  1001. }
  1002. if($allday=='1') {
  1003. $beginhour='00:00:00';
  1004. $endhour='23:59:00';
  1005. } else {
  1006. $beginhour=$beginhour.':00';
  1007. $endhour=$endhour.':00';
  1008. }
  1009. $begin=$this->xsetevt->desc['begin']->post_edit(array('date'=>$begindate,'hour'=>$beginhour));
  1010. $end=$this->xsetevt->desc['end']->post_edit(array('date'=>$enddate,'hour'=>$endhour));
  1011. if($begin->raw>$end->raw) return array();
  1012. $dbegin=$this->xsetevt->desc['begin']->display($begin->raw);
  1013. $dend=$this->xsetevt->desc['end']->display($end->raw);
  1014. $date_begin_tsp=strtotime($begin->raw);
  1015. $date_end_tsp=strtotime($end->raw);
  1016. // Preparation de la repetition
  1017. if($repet=='NO') {
  1018. $until=null;
  1019. $until_tsp=0;
  1020. } else {
  1021. if($repet=='DAILY') $add_repetition='DAY';
  1022. elseif($repet=='WEEKLY') $add_repetition='WEEK';
  1023. elseif($repet=='MONTHLY') $add_repetition='MONTH';
  1024. else $add_repetition='YEAR';
  1025. $tmp=$datedef->post_edit($p->get('end_rep'));
  1026. $until=$tmp->raw;
  1027. $until_tsp=strtotime($until.' 23:59:00');
  1028. // Preparation des exceptions
  1029. if(!empty($excepttab)) {
  1030. foreach($excepttab as $tmp) {
  1031. $tmp2=$datedef->post_edit($tmp);
  1032. $except.=$tmp2->raw.';';
  1033. $except_mail.=$tmp.';';
  1034. }
  1035. $except=substr($except,0,(strlen($except)-1));
  1036. $except_mail=substr($except_mail,0,(strlen($except_mail)-1));
  1037. }
  1038. }
  1039. // Preparation du tableau de donnees
  1040. $ar1=$ar;
  1041. $ar1['repet']=$repet;
  1042. $ar1['end_rep']=$until;
  1043. $ar1['except']=$except;
  1044. $ar1['recall']=($recalltime*$recalltype);
  1045. $ar1['KOIDD']=$diary;
  1046. $ar1['UIDI']=null;
  1047. $ar1['tplentry']=TZR_RETURN_DATA;
  1048. $ar1['visib']=$visib;
  1049. $ar1['rrule']='';
  1050. // Si on est dans une modification, on efface les evenements lies a la source mais on garde l'evenement d'origine pour le modifier
  1051. if(!empty($koid)) {
  1052. $this->delEvt(array('koid'=>$koid,'noalert'=>true,'nodelsource'=>true));
  1053. $ar1['oid']=$koid;
  1054. $function='procEdit';
  1055. }else{
  1056. $function='procInput';
  1057. }
  1058. // Tant que l'on est dans l'intervale de repetition, on insere des entrees
  1059. $repet=false;
  1060. $koids=NULL;
  1061. do {
  1062. $date_begin=date('Y-m-d',$date_begin_tsp);
  1063. // Si la date n'est pas dans les exceptions
  1064. if(strpos($except,$date_begin)===FALSE) {
  1065. $ar1['begin']=($allday!='1') ? gmdate('Y-m-d H:i:s',$date_begin_tsp) : date('Y-m-d H:i:s',$date_begin_tsp);
  1066. $ar1['end']=($allday!='1') ? gmdate('Y-m-d H:i:s',$date_end_tsp) : date('Y-m-d H:i:s',$date_end_tsp);
  1067. $ar1['KOIDS']=$koids;
  1068. $ret=$this->xsetevt->$function($ar1);
  1069. if($function=='procEdit') $ret['oid']=$koid;
  1070. $xset_link->procInput(array('KOIDE'=>$ret['oid'],'KOIDD'=>$diary));
  1071. foreach($attselected as $att) {
  1072. // On ne copie pas l'événement dans l'agenda à l'origine de cet événement
  1073. if ($att == $diary) continue;
  1074. $ar2=array('KOIDD'=>$att,'KOIDE'=>$ret['oid']);
  1075. $xset_link->procInput($ar2);
  1076. }
  1077. if(!$repet) $koids=$ret['oid'];
  1078. }
  1079. $repet=true;
  1080. $function='procInput';
  1081. $date_begin_tsp=strtotime('+1 '.$add_repetition,$date_begin_tsp);
  1082. $date_end_tsp=strtotime('+1 '.$add_repetition,$date_end_tsp);
  1083. } while($date_begin_tsp<$until_tsp+1);
  1084. // Env…

Large files files are truncated, but you can click here to view the full file