hasPermission() public method

Encapsulates permissions checking.
public hasPermission ( integer $permission, string $user = null ) : boolean
$permission integer The permission to check for.
$user string The user to check permissions for.
return boolean
Esempio n. 1
0
 public function html($active = true)
 {
     if (!$this->_event) {
         echo '<h3>' . _("Event not found") . '</h3>';
         exit;
     }
     if (is_string($this->_event)) {
         echo '<h3>' . $this->_event . '</h3>';
         exit;
     }
     global $conf, $prefs;
     $this->_event->loadHistory();
     $creatorId = $this->_event->creator;
     $description = $this->_event->description;
     $location = $this->_event->location;
     $eventurl = $this->_event->url;
     $private = $this->_event->isPrivate();
     $owner = Kronolith::getUserName($creatorId);
     $status = Kronolith::statusToString($this->_event->status);
     $attendees = $this->_event->attendees;
     $resources = $this->_event->getResources();
     if ($datetime = Horde_Util::getFormData('datetime')) {
         $datetime = new Horde_Date($datetime);
         $month = $datetime->month;
         $year = $datetime->year;
     } else {
         $month = (int) Horde_Util::getFormData('month', date('n'));
         $year = (int) Horde_Util::getFormData('year', date('Y'));
     }
     $dateFormat = $prefs->getValue('date_format');
     $timeFormat = $prefs->getValue('twentyFour') ? 'G:i' : 'g:ia';
     // Tags
     $tags = implode(', ', $this->_event->tags);
     echo '<div id="Event"' . ($active ? '' : ' style="display:none"') . '>';
     require KRONOLITH_TEMPLATES . '/view/view.inc';
     echo '</div>';
     if ($active && $GLOBALS['browser']->hasFeature('dom')) {
         /* We check for read permissions, because we can always save a
          * copy if we can read the event. */
         if ($this->_event->hasPermission(Horde_Perms::READ) && Kronolith::getDefaultCalendar(Horde_Perms::EDIT)) {
             $edit = new Kronolith_View_EditEvent($this->_event);
             $edit->html(false);
         }
         if ($this->_event->hasPermission(Horde_Perms::DELETE)) {
             $delete = new Kronolith_View_DeleteEvent($this->_event);
             $delete->html(false);
         }
     }
 }
Esempio n. 2
0
 public function html($active = true)
 {
     if (!$this->_event) {
         echo '<h3>' . _("Event not found") . '</h3>';
         exit;
     }
     if (is_string($this->_event)) {
         echo '<h3>' . $this->_event . '</h3>';
         exit;
     }
     if ($datetime = Horde_Util::getFormData('datetime')) {
         $datetime = new Horde_Date($datetime);
         $month = $datetime->month;
         $year = $datetime->year;
         $day = $datetime->mday;
     } else {
         $month = Horde_Util::getFormData('month', date('n'));
         $day = Horde_Util::getFormData('mday', date('j'));
         $year = Horde_Util::getFormData('year', date('Y'));
     }
     $url = Horde_Util::getFormData('url');
     echo '<div id="DeleteEvent"' . ($active ? '' : ' style="display:none"') . '>';
     if (!$this->_event->recurs()) {
         require KRONOLITH_TEMPLATES . '/delete/one.inc';
     } else {
         require KRONOLITH_TEMPLATES . '/delete/delete.inc';
     }
     echo '</div>';
     if ($active && $GLOBALS['browser']->hasFeature('dom')) {
         if ($this->_event->hasPermission(Horde_Perms::READ)) {
             $view = new Kronolith_View_Event($this->_event);
             $view->html(false);
         }
         if ($this->_event->hasPermission(Horde_Perms::READ) && Kronolith::getDefaultCalendar(Horde_Perms::EDIT)) {
             $edit = new Kronolith_View_EditEvent($this->_event);
             $edit->html(false);
         }
     }
 }
Esempio n. 3
0
 public function html($active = true)
 {
     if (!$this->_event) {
         echo '<h3>' . _("Event not found") . '</h3>';
         exit;
     }
     if (is_string($this->_event)) {
         echo '<h3>' . $this->_event . '</h3>';
         exit;
     }
     $identity = $GLOBALS['injector']->getInstance('Horde_Core_Factory_Identity')->create();
     if ($this->_event->hasPermission(Horde_Perms::EDIT)) {
         $calendar_id = $this->_event->calendarType . '_' . $this->_event->calendar;
     } else {
         $calendar_id = 'internal_' . Kronolith::getDefaultCalendar(Horde_Perms::EDIT);
     }
     if (!$this->_event->hasPermission(Horde_Perms::EDIT)) {
         try {
             $calendar_id .= '\\' . $this->_event->getShare()->get('owner');
         } catch (Exception $e) {
         }
     }
     $GLOBALS['session']->set('kronolith', 'attendees', $this->_event->attendees);
     $GLOBALS['session']->set('kronolith', 'resources', $this->_event->getResources());
     if ($datetime = Horde_Util::getFormData('datetime')) {
         $datetime = new Horde_Date($datetime);
         $month = $datetime->month;
         $year = $datetime->year;
     } else {
         $month = Horde_Util::getFormData('month', date('n'));
         $year = Horde_Util::getFormData('year', date('Y'));
     }
     $url = Horde_Util::getFormData('url');
     $perms = Horde_Perms::EDIT;
     if ($this->_event->creator == $GLOBALS['registry']->getAuth()) {
         $perms |= Kronolith::PERMS_DELEGATE;
     }
     $calendars = Kronolith::listCalendars($perms, true);
     $buttons = array();
     if (!$this->_event->hasPermission(Horde_Perms::EDIT) && ($GLOBALS['injector']->getInstance('Horde_Core_Perms')->hasAppPermission('max_events') === true || $GLOBALS['injector']->getInstance('Horde_Core_Perms')->hasAppPermission('max_events') > Kronolith::countEvents())) {
         $buttons[] = '<input type="submit" class="horde-create" name="saveAsNew" value="' . _("Save As New") . '" />';
     } else {
         if ($this->_event->hasPermission(Horde_Perms::EDIT)) {
             $buttons[] = '<input type="submit" class="horde-default" name="save" value="' . _("Save Event") . '" />';
         }
         if ($this->_event->initialized) {
             if (!$this->_event->recurs() && ($GLOBALS['injector']->getInstance('Horde_Core_Perms')->hasAppPermission('max_events') === true || $GLOBALS['injector']->getInstance('Horde_Core_Perms')->hasAppPermission('max_events') > Kronolith::countEvents())) {
                 $buttons[] = '<input type="submit" class="horde-create" name="saveAsNew" value="' . _("Save As New") . '" />';
             }
         }
     }
     if (isset($url)) {
         $cancelurl = new Horde_Url($url);
     } else {
         $cancelurl = Horde::url('month.php', true)->add(array('month' => $month, 'year' => $year));
     }
     $event =& $this->_event;
     $tags = implode(',', array_values($event->tags));
     Horde_Core_Ui_JsCalendar::init(array('full_weekdays' => true));
     global $page_output;
     $page_output->addScriptFile('hordecore.js', 'horde');
     $page_output->addScriptFile('edit.js');
     $page_output->addScriptFile('popup.js', 'horde');
     echo '<div id="EditEvent"' . ($active ? '' : ' style="display:none"') . '>';
     require KRONOLITH_TEMPLATES . '/edit/edit.inc';
     echo '</div>';
     if ($active && $GLOBALS['browser']->hasFeature('dom')) {
         if ($this->_event->hasPermission(Horde_Perms::READ)) {
             $view = new Kronolith_View_Event($this->_event);
             $view->html(false);
         }
         if ($this->_event->hasPermission(Horde_Perms::DELETE)) {
             $delete = new Kronolith_View_DeleteEvent($this->_event);
             $delete->html(false);
         }
     }
 }
Esempio n. 4
0
 /**
  * @param string $tabname
  * @param Kronolith_Event $event
  */
 public static function eventTabs($tabname, $event)
 {
     if (!$event->initialized) {
         return;
     }
     $GLOBALS['page_output']->addScriptFile('views.js');
     $tabs = new Horde_Core_Ui_Tabs('event', Horde_Variables::getDefaultVariables());
     $date = self::currentDate();
     $tabs->preserve('datetime', $date->dateString());
     $tabs->addTab(htmlspecialchars($event->getTitle()), $event->getViewUrl(), array('tabname' => 'Event', 'id' => 'tabEvent', 'onclick' => 'return ShowTab(\'Event\');'));
     /* We check for read permissions, because we can always save a copy if
      * we can read the event. */
     if ((!$event->private || $event->creator == $GLOBALS['registry']->getAuth()) && $event->hasPermission(Horde_Perms::READ) && self::getDefaultCalendar(Horde_Perms::EDIT)) {
         $tabs->addTab($event->hasPermission(Horde_Perms::EDIT) ? _("_Edit") : _("Save As New"), $event->getEditUrl(), array('tabname' => 'EditEvent', 'id' => 'tabEditEvent', 'onclick' => 'return ShowTab(\'EditEvent\');'));
     }
     if ($event->hasPermission(Horde_Perms::DELETE)) {
         $tabs->addTab(_("De_lete"), $event->getDeleteUrl(array('confirm' => 1)), array('tabname' => 'DeleteEvent', 'id' => 'tabDeleteEvent', 'onclick' => 'return ShowTab(\'DeleteEvent\');'));
     }
     $tabs->addTab(_("Export"), $event->getExportUrl(), array('tabname' => 'ExportEvent', 'id' => 'tabExportEvent'));
     echo $tabs->render($tabname);
 }