summaryrefslogtreecommitdiff
path: root/forum/utils/events.php
blob: 737c03c904588066a2309458cabe24a016a0beb2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
<?php

include_once($UTIL_DIR . "/convert.php");

class Event {
  public $eid;
  public $title;
  public $starttime;
  public $duration;
  public $description;
  public $user;

  public function show()
  {
    global $users, $date, $client_is_mobile_device;

    $user = $users->getUser($this->user);

    echo "      <div class=\"event\">\n";
    echo "        <div class=\"title\">". $this->title . "\n";
		//    echo "          <a class=\"button\" href=\"\">Edit</a>\n";
    echo "        </div>\n";
    echo "        <div class=\"time\">" . date("G:i", $this->starttime) . " - " . 
      date("G:i", $this->starttime + $this->duration) .  "</div>\n";
    if(!$client_is_mobile_device) {
      echo "        <div class=\"description\">". $this->description . "</div>\n";
    } else {
      echo "        <div class=\"mobiledescription\">". $this->description . "</div>\n";
    }
    echo "        <div class=\"user\">By: ".$user->name . "</div>\n";
		//    echo "  <a href=\"?mode=calendar&amp;date=" . $date . "&amp;eid=" . $this->eid . "&amp;action=edit\">Edit</a>";
    echo "      </div>\n";
  }
  
  public function Event($eid, $title, $starttime, $duration, $description, $user)
  {
    $this->eid = $eid;
    $this->title = $title;
    $this->starttime = $starttime;
    $this->duration = $duration;
    $this->description = $description;
    $this->user = $user;
  }
}

class Events {

  private $file;
  public $events = array();
	
  public function add($event) {
    $key = $event->eid;
    $this->events[$key] = $event;
  }
	
  public function write()
  {
    $fp = fopen($this->file, "w");
    
    $block = TRUE;
    flock($fp, LOCK_EX, $block); // do an exclusive lock
    
    fwrite($fp, "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n");
    
    fwrite($fp, "<events>\n");
    foreach($this->events as $event) {
      fwrite($fp, "  <event eid=\"" .
	     htmlspecialchars($event->eid, ENT_QUOTES, "UTF-8") . "\"\n");
      fwrite($fp, "         title=\"" . 
	     htmlspecialchars($event->title, ENT_QUOTES, "UTF-8") . "\"\n");
      fwrite($fp, "         starttime=\"" . 
	     htmlspecialchars($event->starttime, ENT_QUOTES, "UTF-8") . "\"\n");
      fwrite($fp, "         duration=\"" . 
	     htmlspecialchars($event->duration, ENT_QUOTES, "UTF-8") . "\"\n");
      fwrite($fp, "         description=\"" . 
	     htmlspecialchars($event->description, ENT_QUOTES, "UTF-8") . "\"\n");
      fwrite($fp, "         user=\"" . 
	     htmlspecialchars($event->user, ENT_QUOTES, "UTF-8") . "\">\n");
      fwrite($fp, "  </event>\n");
    }
    fwrite($fp, "</events>\n");
    
    fclose($fp);
  }

  /*
	public function deleteForumUser($id)
	{
		if($this->members[$id]) {
			unset($this->members[$id]); 
			//			$this->write();
		} else {
			echo "<p>ERROR: User! <em>".$id."</em> does not exist!</p>\n";
			return false;
		}
		return true;
	}
  */

  public function show($starttime, $endtime)
  {
    foreach($this->events as $event) {
      if($event->starttime > $starttime && $event->starttime < $endtime)
	$event->show();
    }
  }

  public function getEvent($eid)
  {
    $event = $this->events[$eid]; 
    return $event;
  }

  private function read()
  {
    $dom = new DomDocument;
    $dom->preserveWhiteSpace = FALSE;
    $dom->load($this->file);
    $events = $dom->getElementsByTagName('event');
    
    foreach ($events as $e) {
      $event = new Event($e->getAttribute('eid'),
			 $e->getAttribute('title'),
			 $e->getAttribute('starttime'),
			 $e->getAttribute('duration'),
			 $e->getAttribute('description'),
			 $e->getAttribute('user'));
      
      $this->add($event);
    }
    
  }

  public function Events($file)
  {
    $this->file = $file;
    $this->read();
  }

}
?>