Friendica Communications Platform (please note that this is a clone of the repository at github, issues are handled there) https://friendi.ca
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

333 lines
10 KiB

10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
  1. <?php
  2. require_once('include/datetime.php');
  3. require_once('include/event.php');
  4. require_once('include/items.php');
  5. function events_post(&$a) {
  6. if(! local_user())
  7. return;
  8. $event_id = ((x($_POST,'event_id')) ? intval($_POST['event_id']) : 0);
  9. $cid = ((x($_POST,'cid')) ? intval($_POST['cid']) : 0);
  10. $uid = local_user();
  11. $startyear = intval($_POST['startyear']);
  12. $startmonth = intval($_POST['startmonth']);
  13. $startday = intval($_POST['startday']);
  14. $starthour = intval($_POST['starthour']);
  15. $startminute = intval($_POST['startminute']);
  16. $finishyear = intval($_POST['finishyear']);
  17. $finishmonth = intval($_POST['finishmonth']);
  18. $finishday = intval($_POST['finishday']);
  19. $finishhour = intval($_POST['finishhour']);
  20. $finishminute = intval($_POST['finishminute']);
  21. $adjust = intval($_POST['adjust']);
  22. $nofinish = intval($_POST['nofinish']);
  23. $start = sprintf('%d-%d-%d %d:%d:0',$startyear,$startmonth,$startday,$starthour,$startminute);
  24. if($nofinish)
  25. $finish = '0000-00-00 00:00:00';
  26. else
  27. $finish = sprintf('%d-%d-%d %d:%d:0',$finishyear,$finishmonth,$finishday,$finishhour,$finishminute);
  28. if($adjust) {
  29. $start = datetime_convert(date_default_timezone_get(),'UTC',$start);
  30. if(! $nofinish)
  31. $finish = datetime_convert(date_default_timezone_get(),'UTC',$finish);
  32. }
  33. else {
  34. $start = datetime_convert('UTC','UTC',$start);
  35. if(! $nofinish)
  36. $finish = datetime_convert('UTC','UTC',$finish);
  37. }
  38. $desc = escape_tags(trim($_POST['desc']));
  39. $location = escape_tags(trim($_POST['location']));
  40. $type = 'event';
  41. if((! $desc) || (! $start)) {
  42. notice('Event description and start time are required.');
  43. goaway($a->get_baseurl() . '/events/new');
  44. }
  45. $share = ((intval($_POST['share'])) ? intval($_POST['share']) : 0);
  46. if($share) {
  47. $str_group_allow = perms2str($_POST['group_allow']);
  48. $str_contact_allow = perms2str($_POST['contact_allow']);
  49. $str_group_deny = perms2str($_POST['group_deny']);
  50. $str_contact_deny = perms2str($_POST['contact_deny']);
  51. }
  52. else {
  53. $str_contact_allow = '<' . local_user() . '>';
  54. $str_group_allow = $str_contact_deny = $str_group_deny = '';
  55. }
  56. $datarray = array();
  57. $datarray['start'] = $start;
  58. $datarray['finish'] = $finish;
  59. $datarray['desc'] = $desc;
  60. $datarray['location'] = $location;
  61. $datarray['type'] = $type;
  62. $datarray['adjust'] = $adjust;
  63. $datarray['nofinish'] = $nofinish;
  64. $datarray['uid'] = $uid;
  65. $datarray['cid'] = $cid;
  66. $datarray['allow_cid'] = $str_contact_allow;
  67. $datarray['allow_gid'] = $str_group_allow;
  68. $datarray['deny_cid'] = $str_contact_deny;
  69. $datarray['deny_gid'] = $str_group_deny;
  70. $datarray['id'] = $event_id;
  71. $datarray['created'] = $created;
  72. $datarray['edited'] = $edited;
  73. $item_id = event_store($datarray);
  74. if(! $cid)
  75. proc_run('php',"include/notifier.php","event","$item_id");
  76. }
  77. function events_content(&$a) {
  78. if(! local_user()) {
  79. notice( t('Permission denied.') . EOL);
  80. return;
  81. }
  82. $o ="";
  83. // tabs
  84. $tpl = get_markup_template('profile_tabs.tpl');
  85. $o .= replace_macros($tpl,array(
  86. '$url' => $a->get_baseurl() . '/profile/' . $a->user['nickname'],
  87. '$phototab' => $a->get_baseurl() . '/photos/' . $a->user['nickname'],
  88. '$status' => t('Status'),
  89. '$profile' => t('Profile'),
  90. '$photos' => t('Photos'),
  91. '$events' => t('Events') ,
  92. '$notes' => t('Personal Notes'),
  93. '$activetab' => "events",
  94. ));
  95. $o .= '<h2>' . t('Events') . '</h2>';
  96. $mode = 'view';
  97. $y = 0;
  98. $m = 0;
  99. if($a->argc > 1) {
  100. if($a->argc > 2 && $a->argv[1] == 'event') {
  101. $mode = 'edit';
  102. $event_id = intval($a->argv[2]);
  103. }
  104. if($a->argv[1] === 'new') {
  105. $mode = 'new';
  106. $event_id = 0;
  107. }
  108. if($a->argc > 2 && intval($a->argv[1]) && intval($a->argv[2])) {
  109. $mode = 'view';
  110. $y = intval($a->argv[1]);
  111. $m = intval($a->argv[2]);
  112. }
  113. }
  114. if($mode == 'view') {
  115. $thisyear = datetime_convert('UTC',date_default_timezone_get(),'now','Y');
  116. $thismonth = datetime_convert('UTC',date_default_timezone_get(),'now','m');
  117. if(! $y)
  118. $y = intval($thisyear);
  119. if(! $m)
  120. $m = intval($thismonth);
  121. // Put some limits on dates. The PHP date functions don't seem to do so well before 1900.
  122. // An upper limit was chosen to keep search engines from exploring links millions of years in the future.
  123. if($y < 1901)
  124. $y = 1900;
  125. if($y > 2099)
  126. $y = 2100;
  127. $nextyear = $y;
  128. $nextmonth = $m + 1;
  129. if($nextmonth > 12) {
  130. $nextmonth = 1;
  131. $nextyear ++;
  132. }
  133. $prevyear = $y;
  134. if($m > 1)
  135. $prevmonth = $m - 1;
  136. else {
  137. $prevmonth = 12;
  138. $prevyear --;
  139. }
  140. $dim = get_dim($y,$m);
  141. $start = sprintf('%d-%d-%d %d:%d:%d',$y,$m,1,0,0,0);
  142. $finish = sprintf('%d-%d-%d %d:%d:%d',$y,$m,$dim,23,59,59);
  143. $start = datetime_convert('UTC','UTC',$start);
  144. $finish = datetime_convert('UTC','UTC',$finish);
  145. $adjust_start = datetime_convert('UTC', date_default_timezone_get(), $start);
  146. $adjust_finish = datetime_convert('UTC', date_default_timezone_get(), $finish);
  147. $r = q("SELECT `event`.*, `item`.`id` AS `itemid`,`item`.`plink`,
  148. `item`.`author-name`, `item`.`author-avatar`, `item`.`author-link` FROM `event` LEFT JOIN `item` ON `item`.`event-id` = `event`.`id`
  149. WHERE `event`.`uid` = %d
  150. AND (( `adjust` = 0 AND `start` >= '%s' AND `start` <= '%s' )
  151. OR ( `adjust` = 1 AND `start` >= '%s' AND `start` <= '%s' )) ",
  152. intval(local_user()),
  153. dbesc($start),
  154. dbesc($finish),
  155. dbesc($adjust_start),
  156. dbesc($adjust_finish)
  157. );
  158. $links = array();
  159. if(count($r)) {
  160. $r = sort_by_date($r);
  161. foreach($r as $rr) {
  162. $j = (($rr['adjust']) ? datetime_convert('UTC',date_default_timezone_get(),$rr['start'], 'j') : datetime_convert('UTC','UTC',$rr['start'],'j'));
  163. if(! x($links,$j))
  164. $links[$j] = $a->get_baseurl() . '/' . $a->cmd . '#link-' . $j;
  165. }
  166. }
  167. $o .= '<div id="new-event-link"><a href="' . $a->get_baseurl() . '/events/new' . '" >' . t('Create New Event') . '</a></div>';
  168. $o .= '<div id="event-calendar-wrapper">';
  169. $o .= '<a href="' . $a->get_baseurl() . '/events/' . $prevyear . '/' . $prevmonth . '" class="prevcal"><div id="event-calendar-prev" class="icon prev" title="' . t('Previous') . '"></div></a>';
  170. $o .= cal($y,$m,$links, ' eventcal');
  171. $o .= '<a href="' . $a->get_baseurl() . '/events/' . $nextyear . '/' . $nextmonth . '" class="nextcal"><div id="event-calendar-next" class="icon next" title="' . t('Next') . '"></div></a>';
  172. $o .= '</div>';
  173. $o .= '<div class="event-calendar-end"></div>';
  174. $last_date = '';
  175. $fmt = t('l, F j');
  176. if(count($r)) {
  177. $r = sort_by_date($r);
  178. foreach($r as $rr) {
  179. $j = (($rr['adjust']) ? datetime_convert('UTC',date_default_timezone_get(),$rr['start'], 'j') : datetime_convert('UTC','UTC',$rr['start'],'j'));
  180. $d = (($rr['adjust']) ? datetime_convert('UTC',date_default_timezone_get(),$rr['start'], $fmt) : datetime_convert('UTC','UTC',$rr['start'],$fmt));
  181. $d = day_translate($d);
  182. if($d !== $last_date)
  183. $o .= '<hr /><a name="link-' . $j . '" ><div class="event-list-date">' . $d . '</div></a>';
  184. $last_date = $d;
  185. $o .= format_event_html($rr);
  186. $o .= ((! $rr['cid']) ? '<a href="' . $a->get_baseurl() . '/events/event/' . $rr['id'] . '" title="' . t('Edit event') . '" class="edit-event-link icon pencil"></a>' : '');
  187. if($rr['plink'])
  188. $o .= '<a href="' . $rr['plink'] . '" title="' . t('link to source') . '" target="external-link" class="plink-event-link icon remote-link"></a></div>';
  189. $o .= '<div class="clear"></div>';
  190. }
  191. }
  192. return $o;
  193. }
  194. if($mode === 'edit' && $event_id) {
  195. $r = q("SELECT * FROM `event` WHERE `id` = %d AND `uid` = %d LIMIT 1",
  196. intval($event_id),
  197. intval(local_user())
  198. );
  199. if(count($r))
  200. $orig_event = $r[0];
  201. }
  202. if($mode === 'edit' || $mode === 'new') {
  203. $n_checked = ((x($orig_event) && $orig_event['nofinish']) ? ' checked="checked" ' : '');
  204. $a_checked = ((x($orig_event) && $orig_event['adjust']) ? ' checked="checked" ' : '');
  205. $d_orig = ((x($orig_event)) ? $orig_event['desc'] : '');
  206. $l_orig = ((x($orig_event)) ? $orig_event['location'] : '');
  207. $eid = ((x($orig_event)) ? $orig_event['id'] : 0);
  208. $cid = ((x($orig_event)) ? $orig_event['cid'] : 0);
  209. $uri = ((x($orig_event)) ? $orig_event['uri'] : '');
  210. if(! x($orig_event))
  211. $sh_checked = '';
  212. else
  213. $sh_checked = (($orig_event['allow_cid'] === '<' . local_user() . '>' && (! $orig_event['allow_gid']) && (! $orig_event['deny_cid']) && (! $orig_event['deny_gid'])) ? '' : ' checked="checked" ' );
  214. if($cid)
  215. $sh_checked .= ' disabled="disabled" ';
  216. $htpl = get_markup_template('event_head.tpl');
  217. $a->page['htmlhead'] .= replace_macros($htpl,array('$baseurl' => $a->get_baseurl()));
  218. $tpl = get_markup_template('event_form.tpl');
  219. $sdt = ((x($orig_event)) ? $orig_event['start'] : 'now');
  220. $fdt = ((x($orig_event)) ? $orig_event['finish'] : 'now');
  221. $tz = ((x($orig_event) && $orig_event['adjust']) ? date_default_timezone_get() : 'UTC');
  222. $syear = datetime_convert('UTC', $tz, $sdt, 'Y');
  223. $smonth = datetime_convert('UTC', $tz, $sdt, 'm');
  224. $sday = datetime_convert('UTC', $tz, $sdt, 'd');
  225. $shour = ((x($orig_event)) ? datetime_convert('UTC', $tz, $sdt, 'H') : 0);
  226. $sminute = ((x($orig_event)) ? datetime_convert('UTC', $tz, $sdt, 'i') : 0);
  227. $fyear = datetime_convert('UTC', $tz, $fdt, 'Y');
  228. $fmonth = datetime_convert('UTC', $tz, $fdt, 'm');
  229. $fday = datetime_convert('UTC', $tz, $fdt, 'd');
  230. $fhour = ((x($orig_event)) ? datetime_convert('UTC', $tz, $fdt, 'H') : 0);
  231. $fminute = ((x($orig_event)) ? datetime_convert('UTC', $tz, $fdt, 'i') : 0);
  232. require_once('include/acl_selectors.php');
  233. $o .= replace_macros($tpl,array(
  234. '$post' => $a->get_baseurl() . '/events',
  235. '$eid' => $eid,
  236. '$cid' => $cid,
  237. '$uri' => $uri,
  238. '$e_text' => t('Event details'),
  239. '$e_desc' => t('Format is year-month-day hour:minute. Starting date and Description are required.'),
  240. '$s_text' => t('Event Starts:') . ' <span class="required">*</span> ',
  241. '$s_dsel' => datesel('start',$syear+5,$syear,false,$syear,$smonth,$sday),
  242. '$s_tsel' => timesel('start',$shour,$sminute),
  243. '$n_text' => t('Finish date/time is not known or not relevant'),
  244. '$n_checked' => $n_checked,
  245. '$f_text' => t('Event Finishes:'),
  246. '$f_dsel' => datesel('finish',$fyear+5,$fyear,false,$fyear,$fmonth,$fday),
  247. '$f_tsel' => timesel('finish',$fhour,$fminute),
  248. '$a_text' => t('Adjust for viewer timezone'),
  249. '$a_checked' => $a_checked,
  250. '$d_text' => t('Description:') . ' <span class="required">*</span>',
  251. '$d_orig' => $d_orig,
  252. '$l_text' => t('Location:'),
  253. '$l_orig' => $l_orig,
  254. '$sh_text' => t('Share this event'),
  255. '$sh_checked' => $sh_checked,
  256. '$acl' => (($cid) ? '' : populate_acl(((x($orig_event)) ? $orig_event : $a->user),false)),
  257. '$submit' => t('Submit')
  258. ));
  259. return $o;
  260. }
  261. }