Esempio n. 1
0
function tpl_datepicker($name, $label = '', $value = 0)
{
    global $user, $page;
    $date = '';
    if ($value) {
        if (!is_numeric($value)) {
            $value = strtotime($value);
        }
        if (!$user->isAnon()) {
            $st = date('Z') / 3600;
            // server GMT timezone
            $value += ($user->infos['time_zone'] - $st) * 60 * 60;
        }
        $date = date('Y-m-d', intval($value));
        /* It must "look" as a date..
         * XXX : do not blindly copy this code to validate other dates
         * this is mostly a tongue-in-cheek validation
         * 1. it will fail on 32 bit systems on dates < 1970
         * 2. it will produce different results bewteen 32 and 64 bit systems for years < 1970
         * 3. it will not work when year > 2038 on 32 bit systems (see http://en.wikipedia.org/wiki/Year_2038_problem)
         *
         * Fortunately tasks are never opened to be dated on 1970 and maybe our sons or the future flyspray
         * coders may be willing to fix the 2038 issue ( in the strange case 32 bit systems are still used by that year) :-)
         */
    } elseif (Req::has($name) && strlen(Req::val($name))) {
        //strtotime sadly returns -1 on faliure in php < 5.1 instead of false
        $ts = strtotime(Req::val($name));
        foreach (array('m', 'd', 'Y') as $period) {
            //checkdate only accepts arguments of type integer
            ${$period} = intval(date($period, $ts));
        }
        // $ts has to be > 0 to get around php behavior change
        // false is casted to 0 by the ZE
        $date = $ts > 0 && checkdate($m, $d, $Y) ? Req::val($name) : '';
    }
    $subPage = new FSTpl();
    $subPage->setTheme($page->getTheme());
    $subPage->assign('name', $name);
    $subPage->assign('date', $date);
    $subPage->assign('label', $label);
    $subPage->assign('dateformat', '%Y-%m-%d');
    $subPage->display('common.datepicker.tpl');
}
Esempio n. 2
0
 function show()
 {
     global $db, $page, $fs, $proj, $do;
     $page = new FSTpl();
     $page->setTheme($proj->prefs['theme_style']);
     $page->assign('do', $do);
     $page->pushTpl('baseheader.tpl');
     $assignees = '';
     if (Get::val('onlyassignees')) {
         $assignees = 'AND (g.show_as_assignees = 1 OR g.is_admin = 1)';
     }
     $query = 'SELECT g.group_id, g.group_name, g.group_desc,
                      g.group_open, count(u.user_id) AS num_users
                 FROM {groups} g
            LEFT JOIN {users_in_groups} uig ON uig.group_id = g.group_id
            LEFT JOIN {users} u ON (uig.user_id = u.user_id ' . $assignees . ')
                WHERE g.project_id = ?
             GROUP BY g.group_id';
     $page->assign('groups', $db->x->getAll($query, null, $proj->id));
     $page->assign('globalgroups', $db->x->getAll($query, null, 0));
     // Search conditions
     $where = array();
     $params = array();
     foreach (array('user_name', 'real_name') as $key) {
         if (Post::val($key)) {
             $where[] = ' ' . $key . ' LIKE ? ';
             $params[] = '%' . Post::val($key) . '%';
         }
     }
     $where = count($where) ? implode(' OR ', $where) : '1=1';
     // fill the table with users
     if (Get::val('group_id', -1) > 0) {
         $order_keys = array('username' => 'user_name', 'realname' => 'real_name');
         $order_column = $order_keys[Filters::enum(Get::val('order', 'username'), array_keys($order_keys))];
         $sortorder = sprintf('ORDER BY %s %s, u.user_id ASC', $order_column, Filters::enum(Get::val('sort', 'desc'), array('asc', 'desc')));
         $users = $db->x->getAll('SELECT u.user_id, user_name, real_name, email_address
                                    FROM {users} u
                               LEFT JOIN {users_in_groups} uig ON uig.user_id = u.user_id
                               LEFT JOIN {groups} g ON uig.group_id = g.group_id
                                   WHERE uig.group_id = ? ' . $assignees . ' AND ( ' . $where . ' )' . $sortorder, null, array_merge(array(Get::val('group_id')), $params));
         // Offset and limit
         $user_list = array();
         $offset = max(Get::num('pagenum') - 1, 0) * 20;
         for ($i = $offset; $i < $offset + 20 && $i < count($users); $i++) {
             $user_list[] = $users[$i];
         }
         $page->assign('users', $user_list);
     } else {
         // be tricky ^^: show most assigned users
         $db->setLimit(20);
         $users = $db->x->getAll('SELECT a.user_id, u.user_name, u.real_name, email_address,
                                         count(a.user_id) AS a_count, CASE WHEN t.project_id = ? THEN 1 ELSE 0 END AS my_project
                                    FROM {assigned} a
                               LEFT JOIN {users} u ON a.user_id = u.user_id
                               LEFT JOIN {tasks} t ON a.task_id = t.task_id
                                   WHERE ( ' . $where . ' )' . ' AND u.account_enabled = 1
                                GROUP BY a.user_id
                                ORDER BY my_project DESC, a_count DESC', null, array_merge(array($proj->id), $params));
         $page->assign('users', $users);
     }
     $page->assign('usercount', count($users));
     $page->setTitle($fs->prefs['page_title'] . L('userselect'));
     $page->pushTpl('userselect.tpl');
     $page->finish();
 }
Esempio n. 3
0
$fs->projects = array_filter($prs, array($user, 'can_view_project'));
// Get e-mail addresses of the admins
if ($user->isAnon() && !$fs->prefs['user_notify']) {
    $sql = $db->Query('SELECT email_address
                         FROM {users} u
                    LEFT JOIN {users_in_groups} g ON u.user_id = g.user_id
                        WHERE g.group_id = 1');
    $page->assign('admin_emails', array_map(create_function('$x', 'return str_replace("@", "#", $x);'), $db->fetchCol($sql)));
}
// default title
$page->setTitle($fs->prefs['page_title'] . $proj->prefs['project_title']);
$page->assign('do', $do);
$page->assign('supertask_id', $supertask_id);
$page->pushTpl('header.tpl');
if (!defined('NO_DO')) {
    require_once BASEDIR . "/scripts/{$do}.php";
} else {
    # not nicest solution, NO_DO currently only used on register actions
    $page->pushTpl('register.ok.tpl');
}
$page->pushTpl('footer.tpl');
$page->setTheme($proj->prefs['theme_style']);
$page->render();
if (isset($_SESSION)) {
    // remove dupe data on error, since no submission happened
    if (isset($_SESSION['ERROR']) && isset($_SESSION['requests_hash'])) {
        $currentrequest = md5(serialize($_POST));
        unset($_SESSION['requests_hash'][$currentrequest]);
    }
    unset($_SESSION['ERROR'], $_SESSION['SUCCESS']);
}
Esempio n. 4
0
 function error($errno, $errstr = '', $errfile = '', $errline = 0)
 {
     global $db, $proj, $fs;
     $page = new FSTpl();
     $page->pushTpl('header.tpl');
     $page->assign('do', 'index');
     $page->setTheme(isset($proj) ? $proj->prefs['theme_style'] : $fs->prefs['global_theme']);
     if (is_array($errno)) {
         list($errno, $errstr, $url) = array_pad($errno, 3, '');
     } else {
         // ignore E_STRICT and @
         if (($errno > E_ALL || !ini_get('error_reporting')) && (isset($errstr) && strpos($errstr, 'by reference') === false)) {
             return;
         }
         $errno = ERROR_INTERNAL;
     }
     if (isset($db) && is_object($db) && $db->inTransaction()) {
         $db->rollback();
         // if possible, undo database queries
     }
     switch ($errno) {
         case ERROR_INTERNAL:
             $page->assign('file', str_replace(BASEDIR . DIRECTORY_SEPARATOR, '', $errfile));
             $page->assign('line', $errline);
         case ERROR_PERMS:
         case ERROR_INPUT:
             @ob_clean();
             // make sure that previous output is erased
             $page->assign('type', $errno);
             $page->assign('message', $errstr);
             $page->pushTpl('error.tpl');
             $page->finish('footer.tpl');
         case ERROR_RECOVER:
             if ($errstr) {
                 $_SESSION['ERROR'] = $errstr;
             }
             if ($url) {
                 Flyspray::Redirect($url);
             }
             break;
         case SUBMIT_OK:
             if ($errstr) {
                 $_SESSION['SUCCESS'] = $errstr;
             }
             if ($url) {
                 Flyspray::Redirect($url);
             }
             break;
     }
 }