<?php

if (!isset($gCms)) {
    exit;
}
$categories = \CGCalendar\category::get_categories();
if (count($categories)) {
    $smarty->assign('categories', $categories);
}
$out = $this->ProcessTemplate('admin_ajax_getcategories.tpl');
echo $out;
exit;
<?php

if (!isset($gCms)) {
    exit;
}
if (!$this->CheckPermission('Manage Calendar Attributes')) {
    return;
}
$this->SetCurrentTab('admin_manage_categories');
$catid = (int) cge_utils::get_param($params, 'catid');
if ($catid < 1) {
    $this->SetError($this->Lang('error_insufficientparams'));
}
try {
    \CGCalendar\category::delete($catid);
    $this->SetMessage($this->Lang('categorydeleted'));
} catch (Exception $e) {
    $this->SetError($e->GetMessage());
}
$this->RedirectToTab();
 public function get_events()
 {
     $gCms = cmsms();
     $sorting = $this->_reverse ? 'DESC' : 'ASC';
     $query = 'SELECT * FROM ' . cms_db_prefix() . 'module_cgcalendar_events WHERE event_id IN (';
     $query .= implode(',', $this->_idlist) . ')';
     $query .= " ORDER BY event_date_start {$sorting}";
     $db = cmsms()->GetDb();
     // get the parent ids and events.
     $events = $db->GetArray($query);
     $parent_ids = $this->_idlist;
     if (!is_array($events) || count($events) == 0) {
         return;
     }
     foreach ($events as $row) {
         if ($row['event_parent_id'] > 0) {
             $parent_ids[] = $row['event_parent_id'];
         }
     }
     $parent_ids = array_unique($parent_ids);
     $customfields = array();
     $query = 'SELECT * FROM ' . cms_db_prefix() . 'module_cgcalendar_event_field_values
             WHERE event_id IN (' . implode(',', $parent_ids) . ') ORDER BY event_id';
     $frs = $db->GetArray($query);
     foreach ($frs as $row) {
         $customfields[$row['event_id']][] = $row;
     }
     $allcategories = array();
     $query = 'SELECT * FROM ' . cms_db_prefix() . 'module_cgcalendar_events_to_categories
                    WHERE event_id IN (' . implode(',', $this->_idlist) . ') ORDER BY event_id';
     $crs = $db->Execute($query);
     while ($crs && !$crs->EOF()) {
         $row = $crs->fields;
         $allcategories[$row['event_id']][] = $row;
         $crs->MoveNext();
     }
     if (count($allcategories)) {
         \CGCalendar\category::get_categories();
     }
     // forces preload.
     $users = array();
     $userops = $gCms->GetUserOperations();
     $userlist = $userops->LoadUsers();
     foreach ($userlist as $oneuser) {
         $users[$oneuser->id] = $oneuser;
     }
     $module = cms_utils::get_module('CGCalendar');
     foreach ($events as &$row) {
         $titleSEO = munge_string_to_url($row['event_title']);
         $prettyurl = sprintf($this->_url_prefix . '/%d/%d-%s', $this->_destpage, $row['event_id'], $titleSEO);
         $parms = array();
         $parms['event_id'] = $row['event_id'];
         $parms['display'] = 'event';
         if ($this->_eventtemplate) {
             $parms['eventtemplate'] = $this->_eventtemplate;
         }
         $row['url'] = $module->create_url($this->_actionid, 'default', $this->_destpage, $parms, false, false, $prettyurl);
         $ptr = null;
         if (isset($allcategories[$row['event_id']])) {
             $ptr = $allcategories[$row['event_id']];
         } else {
             if ($row['event_parent_id'] > 0 && isset($allcategories[$row['event_parent_id']])) {
                 $ptr = $allcategories[$row['event_parent_id']];
             }
         }
         $row['bgcolor'] = $row['fgcolor'] = null;
         if ($ptr) {
             $categories = array();
             foreach ($ptr as $cat) {
                 $categories[] = $cat['category_id'];
                 if (!$row['bgcolor']) {
                     // get colors for this event...
                     $cat_obj = \CGCalendar\category::load($cat['category_id']);
                     $row['fgcolor'] = $cat_obj['fgcolor'];
                     $row['bgcolor'] = $cat_obj['bgcolor'];
                 }
             }
             $row['categories'] = $categories;
             $row['category_names'] = $module->GetCategoryNames($categories);
         }
         $ptr = null;
         if (isset($customfields[$row['event_id']])) {
             $ptr = $customfields[$row['event_id']];
         } else {
             if ($row['event_parent_id'] > 0 && isset($customfields[$row['event_parent_id']])) {
                 $ptr = $customfields[$row['event_parent_id']];
             }
         }
         if ($ptr) {
             $fields = array();
             $fieldinfo = array();
             foreach ($ptr as $key => $rec) {
                 $fields[$rec['field_name']] = $rec['field_value'];
                 $fieldinfo[$rec['field_name']] = $rec;
             }
             $row['fields'] = $fields;
             // deprecated
             $row['fieldinfo'] = $fieldinfo;
         }
         if ($row['event_created_by'] < 0) {
             // negative values (smaller than -100) indicate an admin user account
             $uid = $row['event_created_by'] + 100 * -1;
             $row['admin_uid'] = $uid;
             if (isset($users[$uid])) {
                 $row['author'] = $users[$uid]->username;
             }
         }
         $row['is_parent'] = $row['event_recur_interval'] != 'none' && $row['event_recur_interval'] != '';
     }
     return $events;
 }
     }
 }
 // now convert this into something compatible with fullcalendar
 $outlist = array();
 foreach ($list1 as $rec) {
     try {
         $out = new stdClass();
         $out->id = $rec['event_id'];
         $out->title = $rec['event_title'];
         $out->summary = $rec['event_summary'];
         $out->canedit = 1;
         $out->candelete = 0;
         if (isset($category_list[$out->id]) && count($category_list[$out->id]) >= 1) {
             // this event is in only one category
             // we can set the color and textcolor
             $category = \CGCalendar\category::load($category_list[$out->id][0]);
             $out->color = $category['bgcolor'];
             $out->textColor = $category['fgcolor'];
         }
         if ($rec['event_parent_id'] > 1) {
             // is a child event
             $out->title .= " (" . $this->Lang('child') . ")";
             $out->child = $rec['event_parent_id'];
             $out->candelete = 1;
         } else {
             if ($rec['event_recur_period'] && $rec['event_recur_period'] != 'none') {
                 // is a parent event of a recurring event
                 $out->title .= " (" . $this->Lang('repeats') . ')';
                 $out->recurs = 1;
             } else {
                 $out->candelete = 1;
Esempio n. 5
0
 function GetCategories()
 {
     return \CGCalendar\category::get_categories();
 }
    return;
}
$this->SetCurrentTab('admin_manage_categories');
// handle cancel
if (isset($params['cancel'])) {
    $this->RedirectToTab($id);
}
// setup
$catid = (int) cge_utils::get_param($params, 'catid');
$category = null;
try {
    // create/get initial empty category (for adding)
    $category = new \CGCalendar\category();
    // if we have a category load it.
    if ($catid > 0) {
        $category = \CGCalendar\category::load($catid);
    }
    // handle submit
    if (isset($params['submit'])) {
        // merge the form data into the category
        $category['name'] = $params['name'];
        $category['bgcolor'] = $params['bgcolor'];
        $category['fgcolor'] = $params['fgcolor'];
        // save
        $category->save();
        // redirect outa here.
        $this->SetMessage($this->Lang('categoryupdated'));
        $this->RedirectToTab();
    }
} catch (Exception $e) {
    echo $this->ShowErrors($e->GetMessage());