Location: PHPKode > projects > phlyMail Lite > phlymail/handlers/calendar/folderprops.php
<?php
/**
 * Edit the properties of a given folder
 *
 * @package phlyMail Nahariya 4.0+
 * @subpackage hanlder Calendar
 * @author  Matthias Sommerfeld
 * @copyright 2004-2010 phlyLabs, Berlin http://phlylabs.de
 * @version 0.2.9 2010-11-08
 */
// Only valid within phlyMail
if (!defined('_IN_PHM_')) die();

require_once($_PM_['path']['handler'].'/calendar/driver.mysql.php');
$cDB = new calendar_driver($_SESSION['phM_uid']);
$error = false;
$update_folderlist = false;
$foldertypes = array
        (0 => $WP_msg['SystemFolder']
        ,1 => $WP_msg['UserFolder']
        ,2 => $WP_msg['CalExternalCalendar']
        ,-1 => $WP_msg['notdef']
        );
$fid = (isset($_REQUEST['fid']) && $_REQUEST['fid']) ? $_REQUEST['fid'] : 0;
if (0 == $fid) {
    $fname = $WP_msg['CalMyEvents'];
    $ftype = 0;
} else {
    $myGrp = $cDB->get_group($fid);
    $fname = phm_entities($myGrp['name']);
    $ftype = 1;
    if ($myGrp['type'] == 1) $ftype = 2;
}
$validfields = array
        ('starts' => $WP_msg['CalStart']
        ,'ends' => $WP_msg['CalEnd']
        ,'title' => $WP_msg['CalTitle']
        ,'location' => $WP_msg['CalLocation']
        ,'description' => $WP_msg['CalDescription']
        ,'repetitions' => $WP_msg['CalListRep']
        ,'reminders' => $WP_msg['CalListRem']
        ,'reminders_sms' => $WP_msg['CalListRemSMS']
        ,'reminders_email' => $WP_msg['CalListRemEmail']
        );
$choices = (isset($_PM_['calendar']) && $_PM_['calendar']) ? $_PM_['calendar'] : array();

if (isset($_REQUEST['save']) && $_REQUEST['save']) {
    if ($ftype > 0) {
        $cDB->update_group($fid, null, isset($_REQUEST['show_in_sync']) ? 1 : 0, isset($_REQUEST['show_in_root']) ? 1 : 0);
        $myGrp = $cDB->get_group($fid);
    }
    $fieldcount = 0;
    $showfields = array();
    if (isset($_REQUEST['show_field'])) {
        foreach ($_REQUEST['show_field'] as $k => $v) {
            $showfields[$k] = true;
            ++$fieldcount;
        }
    }
    foreach ($validfields as $k => $v) {
        if (isset($_REQUEST['show_field'][$k]) && $_REQUEST['show_field'][$k]) continue;
        $showfields[$k] = false;
    }
    $choices['show_fields'] = $showfields;
    $GlChFile = $DB->get_usr_choices($_SESSION['phM_uid']);
    $GlChFile['calendar']['show_fields'] = $showfields;
    $GlChFile['calendar']['use_default_fields'] = (isset($_REQUEST['view_default']) && $_REQUEST['view_default']);
    if (0 == $fieldcount) $GlChFile['calendar']['use_default_fields'] = true;
    $GlChFile['calendar']['orderby'] = isset($_REQUEST['orderby']) ? $_REQUEST['orderby'] : 'starts';
    $GlChFile['calendar']['orderdir'] = isset($_REQUEST['orderdir']) ? $_REQUEST['orderdir'] : 'ASC';
    $DB->set_usr_choices($_SESSION['phM_uid'], $GlChFile);
    $choices = $GlChFile['calendar'];
}

$tpl = new fxl_cached_template($_PM_['path']['frontend'].'/templates/folderproperties.tpl', $_PM_['path']['tplcache'].'tpl_folderproperties.tpl');

$icon_path = $_PM_['path']['theme'].'/icons/';
$data['big_icon'] = $icon_path.'calendar_big.gif';
$data['icon'] = $icon_path.'calendar.png';
// System folder: No rename, no other icon
$tpl->assign_block('html_norename');
$tpl->assign_block('js_norename');
$tpl->assign_block('html_noicon');
$tpl->assign_block('js_noicon');

if (!isset($choices['show_fields']) || empty($choices['show_fields'])) {
    $choices['show_fields'] = array('starts' => 1, 'ends' => 1, 'title' => 1, 'location' => 1, 'repetitions' => 1, 'reminders' => 1);
}
$t_d = $tpl->get_block('display');
$td_f = $t_d->get_block('dbline');
// Show currently selected fields first, in order of appearance
foreach ($choices['show_fields'] as $k => $v) {
    if (!$v) continue;
    if (!isset($validfields[$k])) continue;
    $td_f->assign(array('id' => $k, 'value' => $validfields[$k]));
    $td_f->assign_block('checked');
    $t_d->assign('dbline', $td_f);
    $td_f->clear();
}
// Now the rest of the fields currently not selected
foreach ($validfields as $name => $text) {
    if (isset($choices['show_fields'][$name]) && $choices['show_fields'][$name]) continue;
    if (isset($choices['show_fields']['meta_'.$name]) && $choices['show_fields']['meta_'.$name]) continue;
    $td_f->assign(array('id' => $name, 'value' => $text));
    $t_d->assign('dbline', $td_f);
    $td_f->clear();
}
$t_d->assign('sel_size', sizeof($validfields));

if (!isset($choices['show_fields']) || (isset($choices['use_default_fields']) && $choices['use_default_fields'])) {
    $t_d->assign_block('view_default');
}
// Define orderby / orderdir
$t_ob = $t_d->get_block('has_orderby');
$t_ol = $t_ob->get_block('orderline');
// Preset should be matching the default behaviour of phlyMail
if (!isset($choices['orderby'])) {
    $choices['orderby'] = 'lastname';
    $choices['orderdir'] = 'ASC';
}
foreach ($validfields as $name => $text) {
    $t_ol->assign(array('val' => $name, 'name' => $text));
    if ($choices['orderby'] == $name) $t_ol->assign_block('sel');
    $t_ob->assign('orderline', $t_ol);
    $t_ol->clear();
}
$t_ob->assign_block((isset($choices['orderdir']) && $choices['orderdir'] == 'DESC') ? 'seldesc' : 'selasc');
$t_ob->assign(array
        ('msg_orderby' => $WP_msg['OrderBy']
        ,'msg_asc' => $WP_msg['OrderDirAsc']
        ,'msg_desc' => $WP_msg['OrderDirDesc']
        ));
$t_d->assign('has_orderby', $t_ob);
$t_d->assign_block('nopreview');
// End orderby
// Allow to set, whether the folder should appear in main folder and be included in syncs
if ($ftype != 0) {
    $t_hss = $t_d->get_block('has_show_in_sync');
    $t_hss->assign('msg_show_in_sync', $WP_msg['ShowInSync']);
    if (isset($myGrp['show_in_sync']) && $myGrp['show_in_sync']) {
        $t_hss->assign_block('show_in_sync');
    }
    $t_d->assign('has_show_in_sync', $t_hss);
    $t_hsr = $t_d->get_block('has_show_in_root');
    $t_hsr->assign('msg_show_in_root', $WP_msg['ShowInRoot']);
    if (isset($myGrp['show_in_root']) && $myGrp['show_in_root']) {
        $t_hsr->assign_block('show_in_root');
    }
    $t_d->assign('has_show_in_root', $t_hsr);
}
$tpl->assign('display', $t_d);
// Quotas
$t_qu = $tpl->get_block('quotas');
$t_ql = $t_qu->get_block('quotaline');
$num_quotas = 0;
foreach (array
        ('number_appointments' => array( 'type' => 'int', 'method' => 'quota_getnumberofrecords', 'name' => $WP_msg['QuotaNumberAppointments'])
        ,'number_tasks' => array('type' => 'int', 'method' => 'quota_getnumberoftasks', 'name' => $WP_msg['ConfigQuotaNumberTasks'])
        ,'number_groups' => array('type' => 'int', 'method' => 'quota_groupsnum', 'name' => $WP_msg['QuotaNumberGroups'])
        ) as $k => $v) {
    $v['limit'] = $DB->quota_get($_SESSION['phM_uid'], 'calendar', $k);
    if (false === $v['limit']) continue;
    $num_quotas++;
    $v['use'] = $cDB->{$v['method']}();
    if ($v['type'] == 'filesize') {
        $use = $v['use'];
        $limit = $v['limit'];
        $v['use'] = size_format($v['use']);
        $v['limit'] = size_format($v['limit']);
    } else {
        $use = $v['use'];
        $limit = $v['limit'];
    }
    $t_ql->assign(array('crit_id' => $k, 'msg_crit' => $v['name'], 'msg_use' => $v['use'], 'msg_limit' => $v['limit'], 'use' => $use, 'limit' => $limit));
    $t_qu->assign('quotaline', $t_ql);
    $t_ql->clear();
}
if ($num_quotas) {
    $tpl->assign('quotas', $t_qu);
    $tpl->assign('leg_quotas', $WP_msg['QuotaLegend']);
}
// Ende Qutoas
$tpl->assign(array
        ('big_icon' => $data['big_icon']
        ,'foldername' => $fname
        ,'msg_name'  => $WP_msg['FolderName']
        ,'msg_type' => $WP_msg['FolderType']
        ,'msg_properties' => $WP_msg['properties']
        ,'msg_has_folders' => $WP_msg['FolderHasFolders']
        ,'msg_has_items' => $WP_msg['FolderHasItems']
        ,'leg_display' => $WP_msg['LegDisplayAndFields']
        ,'msg_use_preview' => $WP_msg['FolderUsePrevie']
        ,'msg_showfields' => $WP_msg['FolderShowFields']
        ,'msg_use_default' => $WP_msg['FolderUseDefFields']
        ,'has_folders' => $ftype == 0 ? $WP_msg['yes'] : $WP_msg['no']
        ,'has_items' => $WP_msg['yes']
        ,'type' => $foldertypes[$ftype]
        ,'msg_save' => $WP_msg['save']
        ,'form_target' => htmlspecialchars(PHP_SELF.'?'.give_passthrough(1).'&load=folderprops&handler=calendar&save=1&fid='.$fid)
        ));
if ($ftype < 2) { // Prepared for later inclusion of external calendars
    $tpl->fill_block('webapi', array
            ('leg_api' => $PW_msg['APILegend']
            ,'about_webapi' => $WP_msg['APIAbout']
            ,'url' => 'http://'.$_SERVER['SERVER_NAME'].(dirname(PHP_SELF) == '/' ? '' : dirname(PHP_SELF))
                    .'/api.php?handler=calendar&amp;f=ICS'.($fid != 0 ? '&amp;g='.intval($fid) : '')
            ));
}
?>
Return current item: phlyMail Lite