PageRenderTime 67ms CodeModel.GetById 25ms RepoModel.GetById 0ms app.codeStats 1ms

/src/system/application/controllers/event.php

https://github.com/davemee/joind.in
PHP | 1491 lines | 1145 code | 181 blank | 165 comment | 123 complexity | 073e9237700549b8f88f188c67031d0c MD5 | raw file
Possible License(s): BSD-3-Clause
  1. <?php
  2. class Event extends Controller {
  3. function Event(){
  4. parent::Controller();
  5. $this->user_model->logStatus();
  6. // Check to see if they need a custom CSS layout
  7. $this->load->model('event_themes_model','eventThemes');
  8. $ret = explode('/',$_SERVER['REQUEST_URI']);
  9. $event_id = (isset($ret[3]) && is_numeric($ret[3])) ? $ret[3] : null;
  10. $theme = $this->eventThemes->getActiveTheme($event_id);
  11. if($event_id && $theme){
  12. // has active theme...use it!
  13. $this->template->write('css','/inc/css/event/'.$theme[0]->css_file);
  14. }
  15. }
  16. function cust($in){
  17. $this->load->helper('url');
  18. $this->load->model('event_model');
  19. $id=$this->event_model->getEventIdByName($in);
  20. //print_r($id); echo $id[0]->ID;
  21. if(isset($id[0]->ID)){
  22. redirect('event/view/'.$id[0]->ID);
  23. }else{ echo 'error'; }
  24. }
  25. //--------------------
  26. function _runList($type, $pending = false)
  27. {
  28. $prefs = array (
  29. 'show_next_prev' => TRUE,
  30. 'next_prev_url' => '/event'
  31. );
  32. $this->load->helper('form');
  33. $this->load->helper('reqkey');
  34. $this->load->library('timezone');
  35. //$this->load->library('calendar',$prefs);
  36. $this->load->model('event_model');
  37. $this->load->model('user_attend_model');
  38. $this->load->helper('mycal');
  39. switch ($type) {
  40. case 'hot':
  41. $events = $this->event_model->getHotEvents(null);
  42. break;
  43. case 'upcoming':
  44. $events = $this->event_model->getUpcomingEvents(null);
  45. break;
  46. case 'past':
  47. $events = $this->event_model->getPastEvents(null);
  48. break;
  49. default:
  50. $events = $this->event_model->getEventDetail(null,null,null,$pending);
  51. break;
  52. }
  53. // now add the attendance data
  54. $uid = $this->user_model->getID();
  55. foreach($events as $e) {
  56. if($uid) {
  57. $e->user_attending = $this->user_attend_model->chkAttend($uid, $e->ID);
  58. }else{ $e->user_attending=false; }
  59. }
  60. $reqkey = buildReqKey();
  61. $arr=array(
  62. 'type' => $type,
  63. 'events' =>$events,
  64. //'admin' =>($this->user_model->isAdminEvent($id)) ? true : false
  65. 'month' => null,
  66. 'day' => null,
  67. 'year' => null,
  68. 'all' => true,
  69. 'reqkey' => $reqkey,
  70. 'seckey' => buildSecFile($reqkey)
  71. );
  72. //$this->template->write_view('info_block','msg_info',array('msg'=>'test'),TRUE);
  73. $this->template->write_view('content','event/main',$arr,TRUE);
  74. $this->template->render();
  75. //$this->load->view('event/main',array('events'=>$events));
  76. }
  77. function index($pending=false){
  78. if(apache_getenv('USE_EID')){
  79. $this->view(apache_getenv('USE_EID'));
  80. return true;
  81. }
  82. $type=($pending) ? 'pending' : 'upcoming';
  83. $this->_runList($type, $pending);
  84. }
  85. function all($pending=false){
  86. $this->_runList('index', $pending);
  87. }
  88. function hot($pending=false){
  89. $this->_runList('hot', $pending);
  90. }
  91. function upcoming($pending=false){
  92. $this->_runList('upcoming', $pending);
  93. }
  94. function past($pending=false){
  95. $this->_runList('past', $pending);
  96. }
  97. function calendar($year = null, $month = null, $day = null){
  98. $this->load->model('event_model');
  99. $this->load->model('user_attend_model');
  100. $this->load->helper('reqkey');
  101. $this->load->helper('mycal');
  102. $this->load->library('timezone');
  103. if (!$year) {
  104. $year = date('Y');
  105. }
  106. if (!$month) {
  107. $month = date('m');
  108. }
  109. $checkDay = $day === null ? 1 : $day;
  110. if (!checkdate((int)$month, (int)$checkDay, (int)$year)) {
  111. $day = null;
  112. $month = date('m');
  113. $year = date('Y');
  114. }
  115. $start = mktime(0, 0, 0, $month, $day === null ? 1 : $day, $year);
  116. $end = mktime(23, 59, 59, $month, $day === null ? date('t', $start) : $day, $year);
  117. $events = $this->event_model->getEventDetail(null, $start, $end);
  118. // now add the attendance information
  119. $uid = $this->user_model->getID();
  120. foreach($events as $e) {
  121. if($uid) {
  122. $e->user_attending = $this->user_attend_model->chkAttend($uid, $e->ID);
  123. } else {
  124. $e->user_attending = false;
  125. }
  126. }
  127. $reqkey = buildReqKey();
  128. $arr=array(
  129. 'events' => $events,
  130. 'month' => $month,
  131. 'day' => $day,
  132. 'year' => $year,
  133. 'reqkey' => $reqkey,
  134. 'seckey' => buildSecFile($reqkey)
  135. );
  136. $this->template->write_view('content','event/main',$arr,TRUE);
  137. $this->template->render();
  138. }
  139. // Note that add() actually does edit, and submit() does add
  140. function add($id=null){
  141. //check for admin
  142. if($id){
  143. if(!$this->user_model->isAdminEvent($id)){ redirect(); }
  144. }else{
  145. if(!$this->user_model->isSiteAdmin()){ redirect(); }
  146. }
  147. if($id){ $this->edit_id=$id; }
  148. $this->load->helper('form');
  149. $this->load->helper('custom_timezone');
  150. $this->load->library('validation');
  151. $this->load->library('timezone');
  152. $this->load->model('event_model');
  153. $config['upload_path'] = $_SERVER['DOCUMENT_ROOT'].'/inc/img/event_icons';
  154. $config['allowed_types']= 'gif|jpg|png';
  155. $config['max_size'] = '100';
  156. $config['max_width'] = '90';
  157. $config['max_height'] = '90';
  158. $this->load->library('upload', $config);
  159. $rules=array(
  160. 'event_name' => 'required',
  161. 'event_loc' => 'required',
  162. 'event_tz_cont' => 'required',
  163. 'event_tz_place' => 'required',
  164. 'start_mo' => 'callback_start_mo_check',
  165. 'end_mo' => 'callback_end_mo_check',
  166. 'event_stub' => 'callback_stub_check'
  167. );
  168. $this->validation->set_rules($rules);
  169. $fields=array(
  170. 'event_name'=>'Event Name',
  171. 'start_mo' =>'Start Month',
  172. 'start_day' =>'Start Day',
  173. 'start_yr' =>'Start Year',
  174. 'end_mo' =>'End Month',
  175. 'end_day' =>'End Day',
  176. 'end_yr' =>'End Year',
  177. 'event_loc' =>'Event Location',
  178. 'event_lat' =>'Latitude',
  179. 'event_long' =>'Longitude',
  180. 'event_desc'=>'Event Description',
  181. 'event_tz_cont' =>'Event Timezone (Continent)',
  182. 'event_tz_place' =>'Event Timezone (Place)',
  183. 'event_href'=>'Event Link(s)',
  184. 'event_hashtag'=>'Event Hashtag',
  185. 'event_private'=>'Private Event',
  186. 'event_stub'=>'Event Stub'
  187. );
  188. $this->validation->set_fields($fields);
  189. $event_detail = array();
  190. $min_start_yr = date('Y');
  191. $min_end_yr = date('Y');
  192. if($this->validation->run()==FALSE){
  193. if($id){
  194. //we're editing here...
  195. $event_detail=$this->event_model->getEventDetail($id);
  196. if(date('Y',$event_detail[0]->event_start)<$min_start_yr){
  197. $min_start_yr=date('Y',$event_detail[0]->event_start);
  198. }
  199. if(date('Y',$event_detail[0]->event_end)<$min_end_yr){
  200. $min_end_yr=date('Y',$event_detail[0]->event_end);
  201. }
  202. foreach($event_detail[0] as $k=>$v){
  203. if($k=='event_start'){
  204. $this->validation->start_mo = $this->timezone->formattedEventDatetimeFromUnixtime($v, $event_detail[0]->event_tz_cont.'/'.$event_detail[0]->event_tz_place, 'm');
  205. $this->validation->start_day = $this->timezone->formattedEventDatetimeFromUnixtime($v, $event_detail[0]->event_tz_cont.'/'.$event_detail[0]->event_tz_place, 'd');
  206. $this->validation->start_yr = $this->timezone->formattedEventDatetimeFromUnixtime($v, $event_detail[0]->event_tz_cont.'/'.$event_detail[0]->event_tz_place, 'Y');
  207. }elseif($k=='event_end'){
  208. $this->validation->end_mo = $this->timezone->formattedEventDatetimeFromUnixtime($v, $event_detail[0]->event_tz_cont.'/'.$event_detail[0]->event_tz_place, 'm');
  209. $this->validation->end_day = $this->timezone->formattedEventDatetimeFromUnixtime($v, $event_detail[0]->event_tz_cont.'/'.$event_detail[0]->event_tz_place, 'd');
  210. $this->validation->end_yr = $this->timezone->formattedEventDatetimeFromUnixtime($v, $event_detail[0]->event_tz_cont.'/'.$event_detail[0]->event_tz_place, 'Y');
  211. }else{ $this->validation->$k=$v; }
  212. }
  213. $this->validation->event_private=$event_detail[0]->private;
  214. }
  215. $arr=array(
  216. 'detail' => $event_detail,
  217. 'min_start_yr' => $min_start_yr,
  218. 'min_end_yr' => $min_end_yr
  219. );
  220. $this->template->write_view('content','event/add',$arr);
  221. $this->template->render();
  222. }else{
  223. //success...
  224. $arr=array(
  225. 'event_name' =>$this->input->post('event_name'),
  226. 'event_start' =>$this->timezone->UnixtimeForTimeInTimezone(
  227. $this->input->post('event_tz_cont').'/'.$this->input->post('event_tz_place'),
  228. $this->input->post('start_yr'),
  229. $this->input->post('start_mo'),
  230. $this->input->post('start_day'),
  231. 0,0,0
  232. ),
  233. 'event_end' =>$this->timezone->UnixtimeForTimeInTimezone(
  234. $this->input->post('event_tz_cont').'/'.$this->input->post('event_tz_place'),
  235. $this->input->post('end_yr'),
  236. $this->input->post('end_mo'),
  237. $this->input->post('end_day'),
  238. 23,59,59
  239. ),
  240. 'event_loc' =>$this->input->post('event_loc'),
  241. 'event_lat' =>$this->input->post('event_lat'),
  242. 'event_long' =>$this->input->post('event_long'),
  243. 'event_desc' =>$this->input->post('event_desc'),
  244. 'active' =>'1',
  245. 'event_tz_cont' =>$this->input->post('event_tz_cont'),
  246. 'event_tz_place' =>$this->input->post('event_tz_place'),
  247. 'event_href' =>$this->input->post('event_href'),
  248. 'event_hashtag' =>$this->input->post('event_hashtag'),
  249. 'private' =>$this->input->post('event_private'),
  250. 'event_tz_cont' =>$this->input->post('event_tz_cont'),
  251. 'event_tz_place' =>$this->input->post('event_tz_place'),
  252. 'event_stub' =>$this->input->post('event_stub')
  253. );
  254. if($this->upload->do_upload('event_icon')){
  255. $updata=$this->upload->data();
  256. $arr['event_icon']=$updata['file_name'];
  257. }
  258. if($id){
  259. //edit...
  260. $this->db->where('id',$this->edit_id);
  261. $this->db->update('events',$arr);
  262. $event_detail=$this->event_model->getEventDetail($id);
  263. }else{
  264. $this->db->insert('events',$arr);
  265. $id=$this->db->insert_id();
  266. }
  267. $arr=array(
  268. 'msg' => 'Data saved! <a href="/event/view/'.$id.'">View event</a>',
  269. 'min_start_yr' => $min_start_yr,
  270. 'min_end_yr' => $min_end_yr,
  271. 'detail'=> $event_detail
  272. );
  273. $this->template->write_view('content','event/add',$arr);
  274. $this->template->render();
  275. }
  276. }
  277. function edit($id){
  278. if(!$this->user_model->isAdminEvent($id)){ redirect(); }
  279. $this->add($id);
  280. }
  281. function view($id,$opt=null,$opt_id=null){
  282. $this->load->helper('form');
  283. $this->load->helper('reqkey');
  284. $this->load->helper('events');
  285. $this->load->library('validation');
  286. $this->load->library('defensio');
  287. $this->load->library('spam');
  288. $this->load->library('twitter');
  289. $this->load->library('timezone');
  290. $this->load->model('event_model');
  291. $this->load->model('event_comments_model');
  292. $this->load->model('user_attend_model','uam');
  293. $this->load->model('event_blog_posts_model','ebp');
  294. $this->load->model('talk_track_model','ttm');
  295. $this->load->model('event_track_model','etm');
  296. $this->load->model('talk_comments_model','tcm');
  297. $this->load->model('user_admin_model','uadm');
  298. $this->load->model('talks_model');
  299. $events = $this->event_model->getEventDetail($id);
  300. $evt_admins = $this->event_model->getEventAdmins($id);
  301. if($events[0]->private=='Y'){
  302. $this->load->model('invite_list_model','ilm');
  303. // Private event! Check to see if they're on the invite list!
  304. $is_auth = $this->user_model->isAuth();
  305. $priv_admin = ($this->user_model->isSiteAdmin() || $this->user_model->isAdminEvent($id)) ? true : false;
  306. if($is_auth){
  307. $udata=$this->user_model->getUser($is_auth);
  308. $is_invite=$this->ilm->isInvited($id,$udata[0]->ID);
  309. //If they're invited, accept if they haven't already
  310. if($is_invite){ $this->ilm->acceptInvite($id,$udata[0]->ID); }
  311. if(!$is_invite && !$priv_admin){
  312. $arr=array('detail'=>$events,'is_auth'=>$is_auth,'admins'=>$evt_admins);
  313. $this->template->write_view('content','event/private',$arr,TRUE);
  314. // Render the page
  315. $this->template->render();
  316. return true;
  317. }
  318. }else{
  319. $arr=array('detail'=>$events,'is_auth'=>$is_auth,'admins'=>$evt_admins);
  320. $this->template->write_view('content','event/private',$arr,TRUE);
  321. // Render the page
  322. $this->template->render();
  323. return true;
  324. }
  325. }
  326. $talks = $this->event_model->getEventTalks($id, false);
  327. $is_auth= $this->user_model->isAuth();
  328. foreach($talks as $k=>$v){
  329. $codes=array();
  330. /*
  331. $p=explode(',',$v->speaker);
  332. foreach($p as $ik=>$iv){
  333. $val=trim($iv);
  334. $talks[$k]->codes[$val]=buildCode($v->ID,$v->event_id,$v->talk_title,$val);
  335. }
  336. */
  337. $talks[$k]->tracks=$this->ttm->getSessionTrackInfo($v->ID);
  338. //If we have a track filter, check it!
  339. if(strtolower($opt)=='track' && isset($opt_id)){
  340. $has_track=false;
  341. foreach($talks[$k]->tracks as $track){
  342. if($track->ID==$opt_id){ $has_track=true; }
  343. }
  344. if(!$has_track){ unset($talks[$k]); }
  345. }
  346. }
  347. if($is_auth){
  348. $uid=$this->session->userdata('ID');
  349. $chk_attend=($this->uam->chkAttend($uid,$id)) ? true : false;
  350. }else{ $chk_attend=false; }
  351. if(empty($events)){ redirect('event'); }
  352. if($events[0]->pending==1 && !$this->user_model->isSiteAdmin()){
  353. $parr=array('detail'=>$events);
  354. $this->template->write_view('content','event/pending',$parr,true);
  355. echo $this->template->render();
  356. return true;
  357. }
  358. $talk_stats = buildTalkStats($this->tcm->getEventComments($id));
  359. $reqkey = buildReqKey();
  360. $attend = $this->uam->getAttendUsers($id);
  361. $talks = $this->talks_model->setDisplayFields($talks);
  362. $claimed_talks = $this->event_model->getClaimedTalks($id, $talks);
  363. $claim_detail = buildClaimDetail($claimed_talks);
  364. $event_related_sessions = $this->event_model->getEventRelatedSessions($id);
  365. $arr=array(
  366. 'event_detail' =>$events[0],
  367. 'talks' => $talks,
  368. 'evt_sessions' => $event_related_sessions,
  369. 'slides_list' =>buildSlidesList($talks),
  370. 'admin' =>($this->user_model->isAdminEvent($id)) ? true : false,
  371. 'claimed' =>$claimed_talks,
  372. 'user_id' =>($is_auth) ? $this->session->userdata('ID') : '0',
  373. 'attend' =>$chk_attend,
  374. 'attend_ct' =>count($attend),
  375. 'reqkey' =>$reqkey,
  376. 'seckey' =>buildSecFile($reqkey),
  377. 'attending' =>$attend,
  378. 'latest_comment'=>$this->event_model->getLatestComment($id),
  379. 'admins' =>$evt_admins,
  380. 'tracks' =>$this->etm->getEventTracks($id),
  381. 'times_claimed' =>$claim_detail['claim_count'],
  382. 'claimed_uids' =>$claim_detail['uids'],
  383. 'claims' =>buildClaims($this->event_model->getEventClaims($id)),
  384. 'talk_stats' =>$talk_stats
  385. //'attend' =>$this->uam->getAttendCount($id)
  386. //'started'=>$this->tz->hasEvtStarted($id),
  387. );
  388. if($opt=='track'){
  389. $arr['track_filter'] = $opt_id;
  390. $arr['track_data'] = null;
  391. foreach($arr['tracks'] as $tr){
  392. if($tr->ID==$opt_id){ $arr['track_data']=$tr; }
  393. }
  394. }
  395. //our event comment form
  396. $rules=array(
  397. 'event_comment' => 'required'
  398. );
  399. $fields=array(
  400. 'event_comment' =>'Event Comment'
  401. );
  402. $this->validation->set_fields($fields);
  403. $this->validation->set_rules($rules);
  404. if($this->validation->run()!=FALSE){
  405. $ec=array(
  406. 'event_id' => $id,
  407. 'comment' => $this->input->post('event_comment'),
  408. 'date_made' => time(),
  409. 'active' => 1
  410. );
  411. if($is_auth){
  412. $ec['user_id'] = $this->session->userdata('ID');
  413. $ec['cname'] = $this->session->userdata('username');
  414. }else{
  415. $ec['user_id'] = 0;
  416. }
  417. // If they're logged in, dont bother with the spam check
  418. if(!$is_auth){
  419. $def_ret=$this->defensio->check('Anonymous',$ec['comment'],$is_auth,'/event/view/'.$id);
  420. $is_spam=(string)$def_ret->spam;
  421. }else{ $is_spam='false'; }
  422. //$this->spam->check('regex',$ec['comment']);
  423. if($is_spam=='false'){
  424. $this->db->insert('event_comments',$ec);
  425. $arr['msg']='Comment inserted successfully!';
  426. if(isset($def_ret)){
  427. $ec['def_resp_spamn']=(string)$def_ret->spaminess;
  428. $ec['def_resp_spamr']=(string)$def_ret->spam;
  429. }
  430. //print_r($ec);
  431. $to=array();
  432. $admin_emails=$this->user_model->getSiteAdminEmail();
  433. foreach($admin_emails as $user){ $to[]=$user->email; }
  434. // Get whatever email addresses there are for the event
  435. $admins=$this->event_model->getEventAdmins($id);
  436. foreach($admins as $ak=>$av){ $to[]=$av->email; }
  437. $subj = $this->config->site_url() . ': Event feedback - '.$id;
  438. $content='';
  439. foreach($ec as $k=>$v){ $content.='['.$k.'] => '.$v."\n\n"; }
  440. foreach($to as $tk=>$tv){
  441. @mail($tv,$subj,$content,'From: ' . $this->config->item('email_feedback'));
  442. }
  443. $this->session->set_flashdata('msg', 'Comment inserted successfully!');
  444. }
  445. redirect('event/view/'.$events[0]->ID . '#comments', 'location', 302);
  446. }
  447. $arr['comments'] = $this->event_comments_model->getEventComments($id);
  448. //$t=$this->twitter->querySearchAPI(explode(',',$arr['events'][0]->event_hashtag));
  449. // @tood for testing
  450. $t=array();
  451. $other_data=array('title'=>'Tagged on Twitter');
  452. if(!empty($t)){
  453. $other_data=array(
  454. 'title' => 'Tagged on Twitter',
  455. 'results' => $t,
  456. );
  457. }
  458. if(!$is_auth){
  459. $info=array('msg'=>sprintf('
  460. <h4 style="color:#3A74C5">New to ' . $this->config->item('site_name') . '?</h4> Find out how we can help you make connections
  461. whether you\'re attending or putting on the show. <a href="/about">Click here</a> to learn more!
  462. '));
  463. $this->template->write_view('info_block','msg_info',$info,TRUE);
  464. }
  465. $this->template->write('feedurl','/feed/event/'.$id);
  466. // Only show if they're an admin...
  467. $this->template->write_view('sidebar3','event/_event_blog',array(
  468. 'entries' => $this->ebp->getPosts($id,true),
  469. 'eid' => $id
  470. ));
  471. if($arr['admin']){ $this->template->write_view('sidebar2','event/_sidebar-admin',
  472. array(
  473. 'eid' => $id,
  474. 'is_private' => $events[0]->private,
  475. 'evt_admin' => $this->event_model->getEventAdmins($id),
  476. 'claim_count' => count($this->uadm->getPendingClaims_Talks($id))
  477. ));
  478. }
  479. $this->template->write_view('content','event/detail',$arr,TRUE);
  480. if(!empty($t)){
  481. // If there's no twitter results, don't show this sidebar
  482. $this->template->write_view('sidebar2','event/_twitter-search',$other_data);
  483. }
  484. $this->template->write_view('sidebar2','event/_event_contact',array('eid'=>$id));
  485. $this->template->render();
  486. //$this->load->view('event/detail',$arr);
  487. }
  488. function attendees($id){
  489. $this->load->model('user_attend_model');
  490. $users = $this->user_attend_model->getAttendees($id);
  491. $arr = array(
  492. 'users' => $users
  493. );
  494. $this->template->write_view('content','event/attendees',$arr,true);
  495. echo $this->template->render('content');
  496. }
  497. function ical($id){
  498. header('Content-type: text/calendar');
  499. header('Content-disposition: filename="ical.ics"');
  500. $this->load->model('event_model');
  501. $arr=$this->event_model->getEventDetail($id);
  502. $this->load->view('event/ical',array('data'=>$arr));
  503. }
  504. function delete($id){
  505. if($this->user_model->isSiteAdmin() || $this->user_model->isAdminEvent($id)){
  506. $this->load->helper('form');
  507. $this->load->library('validation');
  508. $this->load->model('event_model');
  509. $arr=array(
  510. 'eid' => $id,
  511. 'details' => $this->event_model->getEventDetail($id)
  512. );
  513. $ans=$this->input->post('answer');
  514. if(isset($ans) && $ans =='yes'){
  515. $this->event_model->deleteEvent($id);
  516. $arr=array();
  517. }
  518. $this->template->write_view('content','event/delete',$arr,TRUE);
  519. $this->template->render();
  520. //$this->load->view('event/delete',$arr);
  521. }else{ redirect(); }
  522. }
  523. function codes($id){
  524. $this->load->helper('form');
  525. $this->load->library('validation');
  526. $this->load->library('events');
  527. $this->load->helper('url');
  528. $this->load->helper('events');
  529. if($this->user_model->isSiteAdmin() || $this->user_model->isAdminEvent($id)){
  530. //they're okay
  531. }else{ redirect(); }
  532. $rules=array();
  533. $fields=array();
  534. //make our code list for the talks
  535. $this->load->model('event_model');
  536. $codes = array();
  537. $full_talks = array();
  538. $talks=$this->event_model->getEventTalks($id);
  539. foreach($talks as $k=>$v){
  540. $sp=explode(',',$v->speaker); //echo '<pre>'; print_r($sp); echo '</pre>';
  541. foreach($sp as $sk=>$sv){
  542. //$str='ec'.str_pad(substr($v->ID,0,2),2,0,STR_PAD_LEFT).str_pad($v->event_id,2,0,STR_PAD_LEFT);
  543. //$str.=substr(md5($v->talk_title.$sk),5,5);
  544. $str=buildCode($v->ID,$v->event_id,$v->talk_title,trim($sv));
  545. $codes[] = $str;
  546. $obj=clone $v;
  547. $obj->code = $str;
  548. $obj->speaker = trim($sv);
  549. $full_talks[] = $obj;
  550. //$rules['email_'.$v->ID]='trim|valid_email';
  551. $rules['email_'.$v->ID] ='callback_chk_email_check';
  552. $fields['email_'.$v->ID]='speaker email';
  553. }
  554. }
  555. //echo '<pre>'; print_r($full_talks); echo '</pre>';
  556. $this->validation->set_rules($rules);
  557. $this->validation->set_fields($fields);
  558. $claimed=array();
  559. $cl=$this->event_model->getClaimedTalks($id, $talks); //echo '<pre>'; print_r($cl); echo '</pre>';
  560. foreach($cl as $k=>$v){
  561. //$cstr='ec'.str_pad(substr($v->rid,0,2),2,0,STR_PAD_LEFT).str_pad($v->tdata['event_id'],2,0,STR_PAD_LEFT);
  562. //$cstr.=substr(md5($v->tdata['talk_title'].$sk),5,5);
  563. $cds=array();
  564. $sp=explode(',',$v->tdata['speaker']); //print_r($sp);
  565. foreach($sp as $spk=>$spv){
  566. $code=buildCode($v->rid,$v->tdata['event_id'],$v->tdata['talk_title'],trim($spv));
  567. if($code==$v->rcode){ $cl[$k]->code=$code; }
  568. }
  569. //$cl[$k]->codes=$cds;
  570. }
  571. //echo '<pre>'; print_r($cl); echo '</pre>';
  572. $arr=array(
  573. 'talks' => $talks,
  574. 'full_talks'=> $full_talks,
  575. 'codes' => $codes,
  576. 'details' => $this->event_model->getEventDetail($id),
  577. 'claimed' => $cl
  578. );
  579. if($this->validation->run()!=FALSE){
  580. foreach($talks as $k=>$v){
  581. $pv=$this->input->post('email_'.$v->ID);
  582. $chk=$this->input->post('email_chk_'.$v->ID);
  583. if(!empty($pv) && $chk==1){
  584. //these are the ones we need to send the email to these
  585. $this->events->sendCodeEmail($pv,$codes[$k],$arr['details'],$v->ID);
  586. }
  587. }
  588. }else{ /*echo 'fail';*/ }
  589. $this->template->write_view('content','event/codes',$arr,TRUE);
  590. $this->template->render();
  591. }
  592. /**
  593. * Handle the user submission of a new event
  594. */
  595. function submit(){
  596. $arr=array();
  597. $this->load->library('validation');
  598. $this->load->plugin('captcha');
  599. $this->load->helper('custom_timezone');
  600. //$this->load->library('akismet');
  601. $this->load->library('defensio');
  602. $this->load->library('timezone');
  603. $this->load->model('user_admin_model');
  604. $cap_arr=array(
  605. 'img_path' =>$_SERVER['DOCUMENT_ROOT'].'/inc/img/captcha/',
  606. 'img_url' =>'/inc/img/captcha/',
  607. 'img_width' =>'130',
  608. 'img_height' =>'30'
  609. );
  610. $fields=array(
  611. 'event_title' => 'Event Title',
  612. 'event_contact_name' => 'Event Contact Name',
  613. 'event_contact_email' => 'Event Contact Email',
  614. 'event_desc' => 'Event Description',
  615. 'start_mo' => 'Event Start Month',
  616. 'start_day' => 'Event Start Day',
  617. 'start_yr' => 'Event Start Year',
  618. 'is_cfp' => 'Is CfP',
  619. 'cfp_start_day' => 'CfP Start Day',
  620. 'cfp_start_mo' => 'CfP Start Month',
  621. 'cfp_start_yr' => 'CfP Start Year',
  622. 'cfp_end_day' => 'CfP End Day',
  623. 'cfp_end_mo' => 'CfP End Month',
  624. 'cfp_end_yr' => 'CfP End Year',
  625. 'end_mo' => 'Event End Month',
  626. 'end_day' => 'Event End Day',
  627. 'end_yr' => 'Event End Year',
  628. 'event_loc' => 'Event Location',
  629. 'event_tz_cont' => 'Event Timezone (Continent)',
  630. 'event_tz_place' => 'Event Timezone (Place)',
  631. 'event_stub' => 'Event Stub'
  632. // 'cinput' => 'Captcha'
  633. );
  634. $rules=array(
  635. 'event_title' => 'required|callback_event_title_check',
  636. 'event_loc' => 'required',
  637. 'event_contact_name' => 'required',
  638. 'event_contact_email' => 'required|valid_email',
  639. 'event_tz_cont' => 'required',
  640. 'event_tz_place' => 'required',
  641. 'start_mo' => 'callback_start_mo_check',
  642. 'end_mo' => 'callback_end_mo_check',
  643. 'cfp_start_mo' => 'callback_cfp_start_mo_check',
  644. 'cfp_end_mo' => 'callback_cfp_end_mo_check',
  645. 'event_stub' => 'callback_stub_check',
  646. 'event_desc' => 'required',
  647. // 'cinput' => 'required|callback_cinput_check'
  648. );
  649. $this->validation->set_rules($rules);
  650. $this->validation->set_fields($fields);
  651. //if we're just loading, give the dates some default values
  652. if(empty($this->validation->start_mo)){
  653. $sel_fields=array(
  654. 'start_mo'=>'m','start_day'=>'d','start_yr'=>'Y','end_mo'=>'m',
  655. 'end_day'=>'d','end_yr'=>'Y','cfp_start_mo'=>'m','cfp_start_day'=>'d',
  656. 'cfp_start_yr'=>'Y','cfp_end_mo'=>'m','cfp_end_day'=>'d','cfp_end_yr'=>'Y'
  657. );
  658. foreach($sel_fields as $k=>$v){ $this->validation->$k=date($v); }
  659. $this->validation->cfp_checked = false;
  660. $this->validation->is_private = 'n';
  661. }else{
  662. $this->validation->cfp_checked = $this->validation->is_cfp;
  663. }
  664. if($this->validation->run()!=FALSE){
  665. //TODO: add it to our database, but mark it pending
  666. $tz = $this->input->post('event_tz_cont').'/'.$this->input->post('event_tz_place');
  667. // Get offset unix timestamp for start of event
  668. $startUnixTimestamp = $this->timezone->UnixtimeForTimeInTimezone(
  669. $tz,
  670. $this->input->post('start_yr'),
  671. $this->input->post('start_mo'),
  672. $this->input->post('start_day'),
  673. 0,
  674. 0,
  675. 0
  676. );
  677. // Get offset unix timestamp for end of event
  678. $endUnixTimestamp = $this->timezone->UnixtimeForTimeInTimezone(
  679. $tz,
  680. $this->input->post('end_yr'),
  681. $this->input->post('end_mo'),
  682. $this->input->post('end_day'),
  683. 23,
  684. 59,
  685. 59
  686. );
  687. $sub_arr=array(
  688. 'event_name' =>$this->input->post('event_title'),
  689. 'event_start' =>$startUnixTimestamp,
  690. 'event_end' =>$endUnixTimestamp,
  691. 'event_loc' =>$this->input->post('event_loc'),
  692. 'event_lat' =>$this->input->post('event_lat'),
  693. 'event_long' =>$this->input->post('event_long'),
  694. 'event_desc' =>$this->input->post('event_desc'),
  695. 'active' =>0,
  696. 'event_stub' =>$this->input->post('event_stub'),
  697. 'event_tz_cont' =>$this->input->post('event_tz_cont'),
  698. 'event_tz_place' =>$this->input->post('event_tz_place'),
  699. 'pending' =>1,
  700. 'private' =>($this->input->post('is_private')=='n') ? null : $this->input->post('is_private')
  701. );
  702. // Check to see if our Call for Papers dates are set...
  703. $cfp_check=$this->input->post('cfp_start_mo');
  704. if(!empty($cfp_check)){
  705. // Get offset unix timestamp for start of CFP
  706. $sub_arr['event_cfp_start'] = $this->timezone->UnixtimeForTimeInTimezone(
  707. $tz,
  708. $this->input->post('cfp_start_yr'),
  709. $this->input->post('cfp_start_mo'),
  710. $this->input->post('cfp_start_day'),
  711. 0,
  712. 0,
  713. 0
  714. );
  715. // Get offset unix timestamp for end of CFP
  716. $sub_arr['event_cfp_end'] = $this->timezone->UnixtimeForTimeInTimezone(
  717. $tz,
  718. $this->input->post('cfp_end_yr'),
  719. $this->input->post('cfp_end_mo'),
  720. $this->input->post('cfp_end_day'),
  721. 23,
  722. 59,
  723. 59
  724. );
  725. }
  726. //echo '<pre>'; print_r($sub_arr); echo '</pre>';
  727. //----------------------
  728. $is_auth = $this->user_model->isAuth();
  729. $cname = $this->input->post('event_contact_name');
  730. $ccomment = $this->input->post('event_desc');
  731. $def = $this->defensio->check($cname,$ccomment,$is_auth,'/event/submit');
  732. $is_spam = (string)$def->spam;
  733. //-----------------------
  734. if($is_spam!='true'){
  735. //send the information via email...
  736. $subj = 'Event submission from ' . $this->config->item('site_name');
  737. $msg= 'Event Title: '.$this->input->post('event_title')."\n\n";
  738. $msg.='Event Description: '.$this->input->post('event_desc')."\n\n";
  739. $msg.='Event Date: '.date('m.d.Y H:i:s',$sub_arr['event_start'])."\n\n";
  740. $msg.='Event Contact Name: '.$this->input->post('event_contact_name')."\n\n";
  741. $msg.='Event Contact Email: '.$this->input->post('event_contact_email')."\n\n";
  742. $msg.='Spam check: '.($is_spam=='false') ? 'not spam' : 'spam';
  743. //echo $msg.'<br/><br/>';
  744. $admin_emails=$this->user_model->getSiteAdminEmail();
  745. foreach($admin_emails as $user){
  746. mail($user->email,$subj,$msg,'From: ' . $this->config->item('email_submissions'));
  747. }
  748. $arr['msg']=sprintf('
  749. <style="font-size:16px;font-weight:bold">Event successfully submitted!</span><br/>
  750. <style="font-size:14px;">
  751. Once your event is approved, you (or the contact person for the event) will
  752. receive an email letting you know it\'s been accepted.
  753. <br/><br/>
  754. We\'ll get back with you soon!
  755. </span>
  756. </span>
  757. ');
  758. //put it into the database
  759. $this->db->insert('events',$sub_arr);
  760. // Check to see if we need to make them an admin of this event
  761. if($this->input->post('is_admin') && $this->input->post('is_admin')==1){
  762. $uid = $this->session->userdata('ID');
  763. $rid = $this->db->insert_id();
  764. $type = 'event';
  765. $this->user_admin_model->addPerm($uid,$rid,$type);
  766. }
  767. }else{
  768. $arr['msg']='There was an error submitting your event! Please <a href="' . $this->config->item('email_submissions') . '">send us an email</a> with all the details!';
  769. }
  770. }else{ $this->validation->is_admin=0; }
  771. $arr['is_auth']=$this->user_model->isAuth();
  772. $this->template->write_view('content','event/submit',$arr);
  773. $this->template->write_view('sidebar2','event/_submit-sidebar',array());
  774. $this->template->render();
  775. }
  776. /**
  777. * Export the full event information as a CSV including:
  778. * - Speakers
  779. * - Sessions
  780. * - Session ratings/comments
  781. */
  782. function export($eid){
  783. $this->load->model('event_model');
  784. $talks=$this->event_model->getEventFeedback($eid);
  785. $fp=fopen('php://memory','w+');
  786. foreach($talks as $k=>$v){
  787. fputcsv($fp,(array)$v);
  788. }
  789. //print_r($talks);
  790. rewind($fp);
  791. $out=stream_get_contents($fp);
  792. fclose($fp);
  793. header('Content-type: application/octet-stream');
  794. header('Content-Disposition: attachment; filename="Event_Comments_'.$eid.'.csv"');
  795. echo $out;
  796. }
  797. /**
  798. * Get the list of pending events
  799. */
  800. function pending(){
  801. if(!$this->user_model->isSiteAdmin()){ redirect(); }
  802. $this->index(true);
  803. }
  804. /**
  805. * Approve a pending event and send emails to the admins (if there are any)
  806. */
  807. function approve($eid){
  808. if(!$this->user_model->isSiteAdmin()){ redirect(); }
  809. $this->load->model('event_model');
  810. $this->load->library('sendemail');
  811. $this->load->library('twitter');
  812. $this->event_model->approvePendingEvent($eid);
  813. //print_r($this->event_model->getEventDetail($eid));
  814. // If we have admins for the event, send them an email to let them know
  815. $admin_list = $this->event_model->getEventAdmins($eid);
  816. if($admin_list && count($admin_list)>0){
  817. $evt_detail = $this->event_model->getEventDetail($eid);
  818. $this->sendemail->sendEventApproved($eid,$evt_detail,$admin_list);
  819. }
  820. // @todo get this and twitter class working with short URL
  821. /*echo '<pre>';
  822. $link=$this->twitter->short_bitly($this->config->site_url() . 'event/view/'.$eid);
  823. echo '</pre>';*/
  824. // Send the new approved event to Twitter
  825. //$this->twitter->sendMsg($msg);
  826. // Finally, redirect back to the event!
  827. redirect('event/view/'.$eid);
  828. }
  829. /**
  830. * Allows a user to claim an event - adds a pending row to the admin table
  831. * for the site admins to go in and approve
  832. */
  833. function claim($eid){
  834. if($this->user_model->isSiteAdmin() || $this->user_model->isAdminEvent($eid)){
  835. //they're okay
  836. }else{ redirect('event/view/'.$eid); }
  837. $this->load->model('user_admin_model','uam');
  838. $this->load->helper('events_helper');
  839. $this->load->library('sendemail');
  840. $claim = $this->input->post('claim');
  841. $sub = $this->input->post('sub');
  842. $msg = array();
  843. $claims = array();
  844. foreach($this->uam->getPendingClaims('talk',$eid) as $claim_data){
  845. $claims[$claim_data->ua_id]=$claim_data;
  846. }
  847. $approved = 0;
  848. $denied = 0;
  849. // If we have claims to process...
  850. if($claim && count($claim)>0 && isset($sub)){
  851. foreach($claim as $k=>$v){
  852. // be sure it's still a valid claim
  853. $this->uam->isPendingClaim($k);
  854. switch(strtolower($v)){
  855. case 'approve':
  856. $this->db->where('ID',$k);
  857. $this->db->update('user_admin',array('rcode'=>''));
  858. $email = $claims[$k]->email;
  859. $evt_name = $claims[$k]->event_name;
  860. $talk_title = $claims[$k]->talk_title;
  861. $this->sendemail->claimSuccess($email,$talk_title,$evt_name);
  862. $approved++;
  863. break;
  864. case 'deny':
  865. $this->db->delete('user_admin',array('ID'=>$k));
  866. $denied++;
  867. break;
  868. default:
  869. /* do nothing, no action taken */
  870. }
  871. echo '<br/>';
  872. }
  873. }
  874. if($approved>0){ $msg[]=$approved.' approved'; }
  875. if($denied>0){ $msg[]=$denied.' denied'; }
  876. $msg=implode(',',$msg);
  877. // Data to pass out to the view
  878. $arr=array(
  879. 'claims' => $this->uam->getPendingClaims('talk',$eid),
  880. 'eid' => $eid,
  881. 'msg' => $msg
  882. );
  883. $this->template->write_view('content','event/claim',$arr);
  884. $this->template->render();
  885. }
  886. /**
  887. * Manage the claims that have been made on events
  888. * Not the same as the claims on talks in an event
  889. */
  890. function claims(){
  891. if($this->user_model->isSiteAdmin()){
  892. //they're okay
  893. }else{ redirect('event'); }
  894. $this->load->model('user_admin_model','uam');
  895. $claims = $this->uam->getPendingClaims('event');
  896. $posted_claims = $this->input->post('claim');
  897. $sub = $this->input->post('sub');
  898. if(isset($sub) && !empty($posted_claims)){
  899. echo 'sub!';
  900. foreach($posted_claims as $uam_key => $claim){
  901. switch(strtolower($claim)){
  902. case 'approve':
  903. //Approve the claim
  904. echo 'approve';
  905. $this->uam->updatePerm($uam_key,array('rcode'=>''));
  906. break;
  907. case 'deny':
  908. //Deny the claim - delete it!
  909. echo 'deny';
  910. $this->uam->removePerm($uam_key);
  911. break;
  912. }
  913. }
  914. }
  915. $claims = $this->uam->getPendingClaims('event');
  916. $arr = array(
  917. 'claims' => $claims
  918. );
  919. $this->template->write_view('content','event/claims',$arr);
  920. $this->template->render();
  921. }
  922. /**
  923. * Import an XML file and push the test information into the table
  924. * XML is validated against a document structure in the /inc/xml directory
  925. */
  926. function import($eid){
  927. // Be sure they're supposed to be here...
  928. if($this->user_model->isSiteAdmin() || $this->user_model->isAdminEvent($eid)){
  929. //they're okay
  930. }else{ redirect(); }
  931. $this->load->library('validation');
  932. $this->load->library('xmlimport');
  933. $this->load->library('sendemail');
  934. $this->load->model('event_model','em');
  935. $config['upload_path'] = $_SERVER['DOCUMENT_ROOT'].'/inc/tmp';
  936. $config['allowed_types']= 'xml';
  937. $this->load->library('upload', $config);
  938. // Allow them to upload the XML or pull it from another resource
  939. //$rules = array('xml_file'=>'required');
  940. $rules = array();
  941. $fields = array('xml_file'=>'XML File');
  942. $this->validation->set_rules($rules);
  943. $this->validation->set_fields($fields);
  944. $msg = null;
  945. $evt_detail = $this->em->getEventDetail($eid);
  946. if($this->upload->do_upload('xml_file')){
  947. // The file's there, lets run our import
  948. $updata = $this->upload->data(); //print_r($updata);
  949. $p = $config['upload_path'].'/'.$updata['file_name'];
  950. try{
  951. $data=file_get_contents($p);
  952. $this->xmlimport->import($data,'event',$eid);
  953. $msg='Import Successful! <a href="/event/view/'.$eid.'">View event</a>';
  954. //send an email to the site admins when it's successful
  955. $this->sendemail->sendSuccessfulImport($eid,$evt_detail);
  956. }catch(Exception $e){
  957. $msg='Error: '.$e->getMessage();
  958. }
  959. unlink($p);
  960. }else{
  961. //print_r($this->upload->display_errors());
  962. $msg=$this->upload->display_errors();
  963. }
  964. $arr=array(
  965. 'details' => $evt_detail,
  966. 'msg' => $msg
  967. );
  968. $this->template->write_view('content','event/import',$arr);
  969. $this->template->render();
  970. }
  971. /**
  972. * Allows the event/site admins to send and manage invites to their invite-only
  973. * event. They can see the status of the invites (pending, accepted, requested).
  974. */
  975. function invite($eid,$resp=null){
  976. $this->load->model('invite_list_model','ilm');
  977. $this->load->library('sendemail');
  978. $this->load->model('event_model');
  979. //$this->load->library('validation');
  980. $msg=null;
  981. $detail=$this->event_model->getEventDetail($eid);
  982. $is_auth= $this->user_model->isAuth();
  983. $user = ($is_auth) ? $this->user_model->getUser($is_auth) : false;
  984. $admins = $this->event_model->getEventAdmins($eid);
  985. if($resp && $user){
  986. switch(strtolower($resp)){
  987. case "respond":
  988. // Check their invite, be sure it's an empty status
  989. $inv=$this->ilm->getInvite($eid,$user[0]->ID);
  990. if(empty($inv[0]->accepted)){
  991. // They're respondng to an invite - update the database
  992. $this->ilm->acceptInvite($eid,$user[0]->ID);
  993. redirect('event/view/'.$eid);
  994. }else{ redirect('event/view/'.$eid); }
  995. break;
  996. case "request":
  997. // They're requesting an invite, let the admin know!
  998. $evt_title = $detail[0]->event_name;
  999. $evt_id = $detail[0]->ID;
  1000. $this->sendemail->sendInviteRequest($evt_id,$evt_title,$user,$admins);
  1001. $this->ilm->addInvite($eid,$user[0]->ID,'A');
  1002. $arr=array('detail'=>$detail);
  1003. $this->template->write_view('content','event/request',$arr);
  1004. $this->template->render();
  1005. return;
  1006. break;
  1007. }
  1008. }
  1009. // Be sure they're supposed to be here...the rest of this is for admins
  1010. if($this->user_model->isSiteAdmin() || $this->user_model->isAdminEvent($eid)){
  1011. //they're okay
  1012. }else{ redirect(); }
  1013. $invites=$this->ilm->getEventInvites($eid);
  1014. if($this->input->post('sub') && $this->input->post('sub')=='Send Invite'){
  1015. // See if they're adding a username and check to see if it's valid
  1016. $u=$this->input->post('user');
  1017. if(!empty($u)){
  1018. $ret=$this->user_model->getUser($u);
  1019. if(empty($ret)){
  1020. $msg='Invalid user <b>'.$u.'</b>!';
  1021. }else{
  1022. // Good user, lets add them to the list (if they're not there already)
  1023. $is_invited=$this->ilm->isInvited($eid,$ret[0]->ID);
  1024. if(!$is_invited){
  1025. $this->ilm->addInvite($eid,$ret[0]->ID);
  1026. $this->sendemail->sendInvite($ret[0]->email,$eid,$detail[0]->event_name);
  1027. $msg='User <b>'.$u.'</b> has been sent an invite!';
  1028. }else{
  1029. $msg='User <b>'.$u.'</b> has already been invited to this event!';
  1030. }
  1031. }
  1032. }
  1033. }
  1034. if($this->input->post('attend_list')){
  1035. //Managing the list...
  1036. foreach($invites as $k=>$v){
  1037. //check for... *pending*
  1038. //check to see if we have a delete action
  1039. $del=$this->input->post('del_'.$v->uid);
  1040. if($del && $del=='delete'){ $this->ilm->removeInvite($eid,$v->uid); }
  1041. //check to see if there's an "approve" action
  1042. $del=$this->input->post('approve_'.$v->uid);
  1043. if($del && $del=='approve'){ $this->ilm->updateInviteStatus($eid,$v->uid,'Y'); }
  1044. //check to see if there's a decline action
  1045. $del=$this->input->post('decline_'.$v->uid);
  1046. if($del && $del=='decline'){ $this->ilm->removeInvite($eid,$v->uid); }
  1047. }
  1048. // Refresh the invite list
  1049. $invites=$this->ilm->getEventInvites($eid);
  1050. $msg='Invite list changes saved!';
  1051. }
  1052. // Finally, we send it out to the view....
  1053. $arr=array(
  1054. 'eid' => $eid,
  1055. 'invites' => $invites,
  1056. 'msg' => $msg,
  1057. 'evt_detail'=> $detail
  1058. );
  1059. $this->template->write_view('content','event/invite',$arr);
  1060. $this->template->render();
  1061. }
  1062. /**
  1063. * Allow logged in users to send a message to the event admins
  1064. * if any are assigned. Will always send to site admins regardless
  1065. */
  1066. function contact($eid){
  1067. // They need to be logged in...
  1068. $is_auth=$this->user_model->isAuth();
  1069. if(!$is_auth){ redirect('event/view/'.$eid); }
  1070. $this->load->model('event_model');
  1071. $this->load->library('validation');
  1072. $this->load->library('sendemail');
  1073. $rules=array(
  1074. 'subject' => 'required',
  1075. 'comments' => 'required'
  1076. );
  1077. $this->validation->set_rules($rules);
  1078. $fields=array(
  1079. 'subject' => 'Subject',
  1080. 'comments' => 'Comments'
  1081. );
  1082. $this->validation->set_fields($fields);
  1083. $arr=array(
  1084. 'detail'=>$this->event_model->getEventDetail($eid)
  1085. );
  1086. if($this->validation->run()!=FALSE){
  1087. $user = $this->user_model->getUser($is_auth);
  1088. // Grab the event admins
  1089. $admins = $this->event_model->getEventAdmins($eid);
  1090. //If there's no event admins, we send it to the site admins
  1091. if(empty($admins)){ $admins=$this->user_model->getSiteAdminEmail(); }
  1092. // Push the emails over to the mailer class
  1093. $evt_name = $arr['detail'][0]->event_name;
  1094. $msg = 'Subject: '.$this->input->post('subject')."\n\n";
  1095. $msg .= $this->input->post('comments');
  1096. $this->sendemail->sendEventContact($eid,$evt_name,$msg,$user,$admins);
  1097. $arr['msg']='Your comments have been sent to the event administrators! They\'ll
  1098. get back in touch with you soon!';
  1099. }else{
  1100. $arr['msg']=$this->validation->error_string;
  1101. }
  1102. $this->template->write_view('content','event/contact',$arr);
  1103. $this->template->render();
  1104. }
  1105. function blog($act='view',$eid,$pid=null){
  1106. $this->load->model('event_model');
  1107. $this->load->library('validation');
  1108. $this->load->library('twitter');
  1109. $this->load->model('event_blog_posts_model','ebp');
  1110. $msg = '';
  1111. $rules = array(
  1112. 'title' => 'required',
  1113. 'content' => 'required'
  1114. );
  1115. $fields = array(
  1116. 'title' => 'Post Title',
  1117. 'content' => 'Post Content'
  1118. );
  1119. $this->validation->set_rules($rules);
  1120. $this->validation->set_fields($fields);
  1121. $posts=$this->ebp->getPosts($eid);
  1122. if($act=='add' || $act=='edit'){
  1123. $this->template->write('feedurl', $this->config->site_url() . 'event/blog/feed/'.$eid);
  1124. // Be sure they're either a site admin or event admin
  1125. if($this->user_model->isSiteAdmin() || $this->user_model->isAdminEvent($eid)){
  1126. //they're okay
  1127. }else{ redirect('event/blog/view/'.$eid); }
  1128. if($act=='edit'){
  1129. $detail=$this->ebp->getPostDetail($pid); //print_r($detail);
  1130. $this->validation->title = $detail[0]->title;
  1131. $this->validation->content = $detail[0]->content;
  1132. }
  1133. if($this->validation->run()!=FALSE){
  1134. $data=array(
  1135. 'title' => $this->input->post('title'),
  1136. 'content' => $this->input->post('content')
  1137. );
  1138. if($pid){
  1139. $this->ebp->updatePost($pid,$data);
  1140. $msg='Post updated!';
  1141. }else{
  1142. $id=$this->ebp->addPost($eid,$data);
  1143. $msg='New post added!';
  1144. //Sent it out to twitter
  1145. $msg='Event Update: '.$data['title']. $this->config->site_url() . 'event/blog/view/'.$eid;
  1146. $resp=$this->twitter->sendMsg($msg);
  1147. }
  1148. }else{
  1149. $msg=$this->validation->error_string;
  1150. }
  1151. }elseif($act=='feed'){
  1152. $items=array();
  1153. foreach($posts as $k=>$v){
  1154. $items[]=array(
  1155. 'title' => $v->title,
  1156. 'guid' => $this->config->site_url() . 'event/blog/view/'.$eid.'#'.$v->ID,
  1157. 'link' => $this->config->site_url() . 'event/blog/view/'.$eid.'#'.$v->ID,
  1158. 'description' => $v->content,
  1159. 'pubDate' => date('t')
  1160. );
  1161. }
  1162. $arr=array(
  1163. 'title'=>'Event Feed '.$eid,
  1164. 'items'=>$items
  1165. );
  1166. $this->load->view('feed/feed',$arr);
  1167. return;
  1168. }else{
  1169. $this->template->write('feedurl', $this->config->site_url() . 'event/blog/feed/'.$eid);
  1170. }
  1171. $arr=array(
  1172. 'evt_detail'=>$this->event_model->getEventDetail($eid),
  1173. 'action' =>$act,
  1174. 'posts' =>$posts,
  1175. 'pid' =>$pid,
  1176. 'msg' =>$msg
  1177. );
  1178. $this->template->write_view('content','event/blog',$arr);
  1179. $this->template->render();
  1180. }
  1181. function tracks($eid){
  1182. if($this->user_model->isSiteAdmin() || $this->user_model->isAdminEvent($eid)){
  1183. //they're okay
  1184. }else{ redirect(); }
  1185. $this->load->model('event_track_model','etm');
  1186. $this->load->model('event_model');
  1187. $this->load->helper('reqkey');
  1188. $reqkey=buildReqKey();
  1189. $arr=array(
  1190. 'detail' => $this->event_model->getEventDetail($eid),
  1191. 'tracks' => $this->etm->getEventTracks($eid),
  1192. 'admin' => ($this->user_model->isAdminEvent($eid)) ? true : false,
  1193. 'reqkey' => $reqkey,
  1194. 'seckey' => buildSecFile($reqkey)
  1195. );
  1196. $this->template->write_view('content','event/tracks',$arr);
  1197. $this->template->render();
  1198. }
  1199. //----------------------
  1200. /**
  1201. * Check the database to be sure we don't have another event by this name, pending or not
  1202. */
  1203. function event_title_check($str){
  1204. $this->load->model('event_model');
  1205. $ret=$this->event_model->getEventIdByTitle($str);
  1206. if(isset($ret[0]->id)){
  1207. $this->validation->set_message('event_title_check','There is already an event by that name!');
  1208. return false;
  1209. }
  1210. return true;
  1211. }
  1212. function start_mo_check($str){
  1213. //be sure it's before the end date
  1214. $t=mktime(
  1215. 0,0,0,$this->validation->start_mo,$this->validation->start_day,$this->validation->start_yr
  1216. );
  1217. $e=mktime(
  1218. 0,0,0,$this->validation->end_mo,$this->validation->end_day,$this->validation->end_yr
  1219. );
  1220. if($t>$e){
  1221. $this->validation->set_message('start_mo_check','Start date must be prior to the end date!');
  1222. return false;
  1223. }else{ return true; }
  1224. }
  1225. function end_mo_check($str){
  1226. $st=mktime(
  1227. 0,0,0,
  1228. $this->validation->start_mo,
  1229. $this->validation->start_day,
  1230. $this->validation->start_yr
  1231. );
  1232. $et=mktime(
  1233. 23,59,59,
  1234. $this->validation->end_mo,
  1235. $this->validation->end_day,
  1236. $this->validation->end_yr
  1237. );
  1238. if($et<$st){
  1239. $this->validation->set_message('end_mo_check','End month must be past the start date!');
  1240. return false;
  1241. }else{ return true; }
  1242. }
  1243. /**
  1244. * Ensure that the date given for the CFP start is before the event date's
  1245. * and that it's before the cfp_end dates
  1246. */
  1247. function cfp_start_mo_check(){
  1248. $cfp_st=mktime(0,0,0,
  1249. $this->validation->cfp_start_mo,$this->validation->cfp_start_day,$this->validation->cfp_start_yr
  1250. );
  1251. $cfp_end=mktime(0,0,0,
  1252. $this->validation->cfp_end_mo,$this->validation->cfp_end_day,$this->validation->cfp_end_yr
  1253. );
  1254. $evt_st=mktime(0,0,0,
  1255. $this->validation->start_mo,$this->validation->start_day,$this->validation->start_yr
  1256. );
  1257. if($cfp_st>=$evt_st){
  1258. $this->validation->set_message('cfp_start_mo_check','Call for Papers must start before the event!');
  1259. return false;
  1260. }
  1261. if($cfp_st>=$cfp_end){
  1262. $this->validation->set_message('cfp_start_mo_check','Invalid Call for Papers start date!');
  1263. return false;
  1264. }
  1265. return true;
  1266. }
  1267. /**
  1268. * Ensure that the date given for the CFP's end is before the start of the event
  1269. * and that the end date is after the CFP start date
  1270. */
  1271. function cfp_end_mo_check(){
  1272. $cfp_end=mktime(0,0,0,
  1273. $this->validation->cfp_end_mo,$this->validation->cfp_end_day,$this->validation->cfp_end_yr
  1274. );
  1275. $evt_st=mktime(0,0,0,
  1276. $this->validation->start_mo,$this->validation->start_day,$this->validation->start_yr
  1277. );
  1278. if($cfp_end>=$evt_st){
  1279. $this->validation->set_message('cfp_start_mo_check','Invalid Call for Papers end date! CfP must end before event start!');
  1280. return false;
  1281. }
  1282. }
  1283. function chk_email_check($str){
  1284. $chk_str=str_replace('_','_chk_',$this->validation->_current_field);
  1285. $val=$this->input->post($chk_str);
  1286. if($val==1 && !$this->validation->valid_email($str)){
  1287. $this->validation->set_message('chk_email_check','Email address invalid!');
  1288. return false;
  1289. }else{ return true; }
  1290. }
  1291. function cinput_check($str){
  1292. if($this->input->post('cinput') != $this->session->userdata('cinput')){
  1293. $this->validation->_error_messages['cinput_check'] = 'Incorrect Captcha characters.';
  1294. return FALSE;
  1295. }else{ return TRUE; }
  1296. }
  1297. function stub_check($str){
  1298. if(!empty($str)){
  1299. $this->load->model('event_model');
  1300. $id=($this->uri->segment(3)===false) ? null : $this->uri->segment(3);
  1301. $ret=$this->event_model->isUniqueStub($str,$id);
  1302. if(!$ret){
  1303. $this->validation->set_message('stub_check','Please choose another stub - this one\'s already in use!');
  1304. return false;
  1305. }else{ return true; }
  1306. }else{ return true; }
  1307. }
  1308. //----------------------
  1309. }
  1310. ?>