CMS  Version 3.9
event_edit.inc
Go to the documentation of this file.
1 <?php
2 /**************************************************************
3 
4  Copyright (c) 2010 Sonjara, Inc
5 
6  Permission is hereby granted, free of charge, to any person
7  obtaining a copy of this software and associated documentation
8  files (the "Software"), to deal in the Software without
9  restriction, including without limitation the rights to use,
10  copy, modify, merge, publish, distribute, sublicense, and/or sell
11  copies of the Software, and to permit persons to whom the
12  Software is furnished to do so, subject to the following
13  conditions:
14 
15  The above copyright notice and this permission notice shall be
16  included in all copies or substantial portions of the Software.
17 
18  Except as contained in this notice, the name(s) of the above
19  copyright holders shall not be used in advertising or otherwise
20  to promote the sale, use or other dealings in this Software
21  without prior written authorization.
22 
23  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
24  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
25  OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
26  NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
27  HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
28  WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
29  FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
30  OTHER DEALINGS IN THE SOFTWARE.
31 
32 *****************************************************************/
33 
34 Fakoli::using("calendar", "taxonomy");
35 Fakoli::using("site");
36 Fakoli::usingFeature("auto_form");
37 
38 $menu_item = "Events";
39 
40 $event_id = checkNumeric($_GET["event_id"]);
41 $calendar_id = checkNumeric($_REQUEST["calendar_id"]);
42 
43 if (!$event_id)
44 {
45  $event = new Event();
47  $event->published = true;
48 }
49 else
50 {
51  $event = new Event($event_id);
52  $calendar = $event->Calendar();
53 }
54 
55 if (!checkRole($calendar->writeAccess))
56 {
57  Fakoli::end("Access Denied");
58 }
59 
60 $form = new AutoForm($event, "POST", "/action/calendar/event_edit?event_id=$event_id");
61 //$event->filter = new ExclusionFilter("description");
62 $desc = $form->getRenderer("description");
63 $desc->width = "450px";
64 $desc->height = "100px";
65 $form->required("title", "start_date", "end_date");
66 $form->hide("composite_class", "event_invitation_id", "allow_access", "time_zone_id", "owner_id");
67 
69 
70 if (!checkRole("admin"))
71 {
72  $form->hide("published");
73 }
74 
75 if(!checkRole("admin"))
76 {
77  $form->hide("owner_id");
78 }
79 
80 $form->allowDelete = true;
81 $form->ajaxSubmit("function(result) {editEventResult(result);}", "function() {document.id('{$form->id}_error').set('text','Failed to communicate with server'); }");
82 
83 $sites = query(Site, "ORDER BY site_name");
84 
85 $event_types = $calendar->EventTypes();
86 
87 if (count($sites) > 1)
88 {
89  $siteSelect = new CrossReferenceSelectFieldRenderer($form, "sites", "Publish to Sites", $sites, "site_name", EventSiteXref);
90 }
91 
92 $calendarSelect = new RelatedItemSelectFieldRenderer($form, "calendar_id", "Calendar", Calendar, "ORDER BY name", "{name}", "calendar_id", false, false, 80);
93 
94 $eventTypes = $calendar->EventTypes();
95 
96 if($eventTypes >0)
97 {
98  $eventTypeList = array();
99 
100  foreach($eventTypes as $eventType)
101  {
102  $eventTypeList[$eventType->name] = $eventType->name;
103  }
104 
105  $eventTypeSelect = new SelectFieldRenderer($form, "event_type", "Event Type", $eventTypeList);
106 }
107 else
108 {
109  $eventTypeSelect = new SelectFieldRenderer($form, "event_type", "Event Type");
110 }
111 //$eventTypeSelect->allowAddEntry();
112 
113 if ($method == "POST")
114 {
115  if ($form->save())
116  {
117  Fakoli::end("1");
118  }
119  else
120  {
121  echo $form->msg;
122  }
123 }
124 else
125 {
126  if ($event_id)
127  {
128  $form->load($event_id);
129  }
130  else
131  {
132  $event->calendar_id = $calendar_id;
133  $event->setOwner();
134  }
135 }
136 
137 echo $form->writeScript();
138 
139 $form->drawForm();
140 
141 
142 ?>
$event
Definition: event_form.inc:46
$eventType
Defines the Event class.
Definition: calendar.inc:43
Defines the Event class.
Definition: event.inc:43
static usingFeature()
Uses the specified framework feature(s).
Definition: core.inc:388
static using()
Import the datamodels, views and manifest for the specified component(s).
Definition: core.inc:116
static end($message="")
Use this method to terminate execution of a script instead of using the php keywords exit() or die().
Definition: core.inc:1149
Definition: site.inc:40
static addTaxonomyFieldRenderers($form, $showSelectAll=true, $group=null, $limitTo=null)
$method
Pull out a simple reference to the request method.
Definition: core.inc:1573
$sites
Definition: event_edit.inc:83
$calendar_id
Definition: event_edit.inc:41
if(count($sites) > 1) $calendarSelect
Definition: event_edit.inc:92
$eventTypes
Definition: event_edit.inc:94
$desc
Definition: event_edit.inc:62
$calendar
Definition: event_edit.inc:52
$menu_item
Definition: event_edit.inc:38
if(!checkRole($calendar->writeAccess)) $form
Definition: event_edit.inc:60
$event_id
Definition: event_edit.inc:40
$event_types
Definition: event_edit.inc:85