/**
  * Return project messages
  *
  * @access public
  * @param void
  * @return array
  */
 function index()
 {
     $this->addHelper('textile');
     $page = (int) array_var($_GET, 'page', 1);
     if ($page < 0) {
         $page = 1;
     }
     $this->canGoOn();
     // Gets desired view 'detail' or 'list'
     // $view_type is from URL, Cookie or set to default: 'list'
     $view_type = array_var($_GET, 'view', Cookie::getValue('messagesViewType', 'list'));
     $expiration = Cookie::getValue('remember' . TOKEN_COOKIE_NAME) ? REMEMBER_LOGIN_LIFETIME : null;
     Cookie::setValue('messagesViewType', $view_type, $expiration);
     $period_type = array_var($_GET, 'period', Cookie::getValue('messagesPeriodType', 'fresh'));
     $expiration = Cookie::getValue('remember' . TOKEN_COOKIE_NAME) ? REMEMBER_LOGIN_LIFETIME : null;
     Cookie::setValue('messagesPeriodType', $period_type, $expiration);
     /* 
     	  
     	extended the time that project pier auto archives  
     */
     $archive_condition = ' AND `updated_on` >= (now() - interval 990 day)';
     if ($period_type == 'archive') {
         $archive_condition = ' AND `updated_on` < (now() - interval 990 day)';
     }
     $conditions = logged_user()->isMemberOfOwnerCompany() ? array('`project_id` = ?' . $archive_condition, active_project()->getId()) : array('`project_id` = ? AND `is_private` = ?' . $archive_condition, active_project()->getId(), 0);
     list($messages, $pagination) = ProjectMessages::paginate(array('conditions' => $conditions, 'order' => '`created_on` DESC'), config_option('messages_per_page', 10), $page);
     // paginate
     tpl_assign('view_type', $view_type);
     tpl_assign('period_type', $period_type);
     tpl_assign('messages', $messages);
     tpl_assign('messages_pagination', $pagination);
     tpl_assign('important_messages', active_project()->getImportantMessages());
     $this->setSidebar(get_template_path('index_sidebar', 'message'));
 }
Ejemplo n.º 2
0
function doRun()
{
    $msg = '';
    $username = mysql_real_escape_string($_POST['name']);
    $pass = mysql_real_escape_string($_POST['pass']);
    try {
        $db = new PDO('mysql:host=localhost;dbname=testData', 'root', 'root');
        $db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
        $stmt = $db->prepare('	SELECT 
													username, pass 
											FROM 	
													testTable
											WHERE
													username = :name
											AND 	
													pass = :pass

										');
        $stmt->bindParam(':name', $username, PDO::PARAM_STR);
        $stmt->bindParam(':pass', $pass, PDO::PARAM_STR);
        $stmt->execute();
        $result = $stmt->fetchAll(PDO::FETCH_ASSOC);
        if ($result == false) {
            $msg = 'sorry could not connect';
        } else {
            //$_SESSION['name'] = $username;
            /**
             * Create a cookie with the name "myCookieName" and value "testing cookie value"
             */
            $cookie = new Cookie();
            // Set cookie name
            $cookie->setName('Login');
            // Set cookie value
            $cookie->setValue("testing cookie value");
            // Set cookie expiration time
            $cookie->setTime("+1 hour");
            // Create the cookie
            $cookie->create();
            // Delete the cookie.
            //$cookie->delete();
            $msg = 'logged in as ' . $username . '<br>';
        }
    } catch (PDOException $e) {
        echo "Error:" . $e;
    }
    echo $msg;
    $db = NULL;
}
Ejemplo n.º 3
0
 public static function setCookie($user, $name, $value, $expires)
 {
     //self::cleanCookies();
     $cookie = self::getCookieObject($user, $name);
     if ($cookie) {
         $cookie->setValue($value);
         $cookie->setExpires(date("Y-m-d H:i:s", $expires));
         $cookie->save();
     } else {
         $cookie = new Cookie();
         $cookie->setUserId($user->getId());
         $cookie->setName($name);
         $cookie->setValue($value);
         $cookie->setExpires(date("Y-m-d H:i:s", $expires));
         $cookie->save();
     }
 }
Ejemplo n.º 4
0
 /**
  * Set logged_user value
  *
  * @access public
  * @param User $value
  * @param boolean $remember Remember this user for 2 weeks (configurable)
  * @param DateTimeValue $set_last_activity_time Set last activity time. This property is turned off in case of feed 
  *   login for instance
  * @return null
  * @throws DBQueryError
  */
 function setLoggedUser(User $user, $remember = false, $set_last_activity_time = true)
 {
     if ($set_last_activity_time) {
         $user->setLastActivity(DateTimeValueLib::now());
         $user->save();
     }
     // if
     $expiration = $remember ? REMEMBER_LOGIN_LIFETIME : SESSION_LIFETIME;
     Cookie::setValue('id' . TOKEN_COOKIE_NAME, $user->getId(), $expiration);
     Cookie::setValue(TOKEN_COOKIE_NAME, $user->getTwistedToken(), $expiration);
     if ($remember) {
         Cookie::setValue('remember' . TOKEN_COOKIE_NAME, 1, $expiration);
     } else {
         Cookie::unsetValue('remember' . TOKEN_COOKIE_NAME);
     }
     // if
     $this->logged_user = $user;
 }
Ejemplo n.º 5
0
 /**
  * Deletes a cookie.
  * 
  * @param  Cookie $cookie
  * @return void
  */
 public function deleteCookie(Cookie $cookie)
 {
     $cookie->setValue('');
     $cookie->setMaxAge(-1);
     $this->cookies[$cookie->getName()] = $cookie;
 }
Ejemplo n.º 6
0
 /**
  * Set logged_user value
  *
  * @access public
  * @param Contact $value
  * @param boolean $remember Remember this user for 2 weeks (configurable)
  * @param DateTimeValue $set_last_activity_time Set last activity time. This property is turned off in case of feed
  *   login for instance
  * @return null
  * @throws DBQueryError
  */
 function setLoggedUser(Contact $user, $remember = false, $set_last_activity_time = true, $set_cookies = true)
 {
     if ($set_last_activity_time) {
         $last_activity_mod_timestamp = array_var($_SESSION, 'last_activity_mod_timestamp', null);
         if (!$last_activity_mod_timestamp || $last_activity_mod_timestamp < time() - 60 * 10) {
             $sql = "UPDATE " . TABLE_PREFIX . "contacts SET last_activity = '" . DateTimeValueLib::now()->toMySQL() . "' WHERE object_id = " . $user->getId();
             DB::execute($sql);
             $_SESSION['last_activity_mod_timestamp'] = time();
         }
     }
     if ($set_cookies) {
         $expiration = $remember ? REMEMBER_LOGIN_LIFETIME : SESSION_LIFETIME;
         Cookie::setValue('id', $user->getId(), $expiration);
         Cookie::setValue('token', $user->getTwistedToken(), $expiration);
         if ($remember) {
             Cookie::setValue('remember', 1, $expiration);
         } else {
             Cookie::unsetValue('remember');
         }
         // if
     }
     $this->logged_user = $user;
 }
Ejemplo n.º 7
0
 /**
  * Set logged_user value
  *
  * @access public
  * @param Contact $value
  * @param boolean $remember Remember this user for 2 weeks (configurable)
  * @param DateTimeValue $set_last_activity_time Set last activity time. This property is turned off in case of feed
  *   login for instance
  * @return null
  * @throws DBQueryError
  */
 function setLoggedUser(Contact $user, $remember = false, $set_last_activity_time = true, $set_cookies = true)
 {
     if ($set_last_activity_time) {
         $last_activity_mod_timestamp = array_var($_SESSION, 'last_activity_mod_timestamp', null);
         if (!isset($_SESSION['last_activity_updating']) && (!$last_activity_mod_timestamp || $last_activity_mod_timestamp < time() - 60 * 10)) {
             $_SESSION['last_activity_updating'] = true;
             $now = DateTimeValueLib::now();
             if (is_null($user->getLastActivity())) {
                 $last_visit = $now;
             } else {
                 $last_visit = $user->getLastActivity();
             }
             $sql = "UPDATE " . TABLE_PREFIX . "contacts SET last_activity = '" . $now->toMySQL() . "',\r\n\t\t\t\t \t\tlast_visit = '" . ($last_visit instanceof DateTimeValue ? $last_visit->toMySQL() : EMPTY_DATETIME) . "', last_login='******'\r\n\t\t\t\t \t\tWHERE object_id = " . $user->getId();
             DB::execute($sql);
             $_SESSION['last_activity_mod_timestamp'] = time();
             unset($_SESSION['last_activity_updating']);
         }
     }
     if ($set_cookies) {
         $expiration = $remember ? REMEMBER_LOGIN_LIFETIME : SESSION_LIFETIME;
         Cookie::setValue('id', $user->getId(), $expiration);
         Cookie::setValue('token', $user->getTwistedToken(), $expiration);
         if ($remember) {
             Cookie::setValue('remember', 1, $expiration);
         } else {
             Cookie::unsetValue('remember');
         }
         // if
     }
     $this->logged_user = $user;
 }
 /**
  * Shows weekly schedule in a calendar view
  * 
  * @param void
  * @return null
  */
 function weekly_schedule()
 {
     $this->addHelper('textile');
     // Gets desired view 'detail', 'list' or 'calendar'
     // $view_type is from URL, Cookie or set to default: 'calendar'
     $view_type = array_var($_GET, 'view', Cookie::getValue('weeklyScheduleViewType', 'calendar'));
     $expiration = Cookie::getValue('remember' . TOKEN_COOKIE_NAME) ? REMEMBER_LOGIN_LIFETIME : null;
     Cookie::setValue('weeklyScheduleViewType', $view_type, $expiration);
     $monthYear = array_var($_GET, 'month');
     if (!isset($monthYear) || trim($monthYear) == '' || preg_match('/^(\\d{4})(\\d{2})$/', $monthYear, $matches) == 0) {
         $year = gmdate('Y');
         $month = gmdate('m');
     } else {
         list(, $year, $month) = $matches;
     }
     // TODO make first day of week configurable
     $from_date = DateTimeValueLib::makeFromString('monday' . (date('w') == 1 ? '' : ' last week'));
     $to_date = $from_date->advance(60 * 60 * 24 * 7 * 3, false);
     // +3 weeks
     $upcoming_milestones = ProjectMilestones::getActiveMilestonesInPeriodByUser(logged_user(), $from_date, $to_date);
     $upcoming_tickets = array();
     if (plugin_active('tickets')) {
         $upcoming_tickets = ProjectTickets::getOpenTicketsInPeriodByUser(logged_user(), $from_date, $to_date);
     }
     $active_projects = array();
     $projects_index = array();
     $counter = 1;
     if (is_array($upcoming_milestones)) {
         foreach ($upcoming_milestones as $milestone) {
             if (!isset($projects_index[$milestone->getProjectId()])) {
                 $projects_index[$milestone->getProjectId()] = $counter;
                 $active_projects[] = $milestone->getProject();
                 $counter++;
             }
             // if
         }
         // foreach
     }
     // if
     if (is_array($upcoming_tickets)) {
         foreach ($upcoming_tickets as $ticket) {
             if (!isset($projects_index[$ticket->getProjectId()])) {
                 $projects_index[$ticket->getProjectId()] = $counter;
                 $active_projects[] = $ticket->getProject();
                 $counter++;
             }
             // if
         }
         // foreach
     }
     // if
     tpl_assign('from_date', $from_date);
     tpl_assign('to_date', $to_date);
     tpl_assign('view_type', $view_type);
     tpl_assign('upcoming_tickets', $upcoming_tickets);
     tpl_assign('late_tickets', array());
     // logged_user()->getLateTickets());
     tpl_assign('upcoming_milestones', $upcoming_milestones);
     tpl_assign('late_milestones', array());
     // logged_user()->getLateMilestones());
     tpl_assign('projects', $active_projects);
     tpl_assign('projects_index', $projects_index);
 }
Ejemplo n.º 9
0
 /**
  * Set logged_user value
  *
  * @access public
  * @param User $value
  * @param boolean $remember Remember this user 
  * @param boolean $set_last_activity_time Turned off in case of feed login
  * @return null
  * @throws DBQueryError
  */
 function setLoggedUser(User $user, $remember = false, $set_last_activity_time = true, $set_cookies = true)
 {
     trace(__FILE__, 'setLoggedUser():begin');
     if ($set_last_activity_time) {
         $user->setLastActivity(DateTimeValueLib::now());
         trace(__FILE__, 'setLoggedUser():user->save()');
         $user->save();
     }
     // if
     if ($set_cookies) {
         $expiration = $remember ? config_option('remember_login_lifetime', 3600) : 3600;
         Cookie::setValue('id' . TOKEN_COOKIE_NAME, $user->getId(), $expiration);
         Cookie::setValue(TOKEN_COOKIE_NAME, $user->getTwistedToken(), $expiration);
         if ($remember) {
             Cookie::setValue('remember' . TOKEN_COOKIE_NAME, 1, $expiration);
         } else {
             Cookie::unsetValue('remember' . TOKEN_COOKIE_NAME);
         }
         // if
     }
     // if
     trace(__FILE__, 'setLoggedUser():end');
     $this->logged_user = $user;
 }
 /**
  * Return project tickets
  *
  * @access public
  * @param void
  * @return array
  */
 function index()
 {
     $page = (int) array_var($_GET, 'page', 1);
     if ($page < 0) {
         $page = 1;
     }
     $this->canGoOn();
     $params = array();
     $params['sort_by'] = array_var($_GET, 'sort_by', Cookie::getValue('ticketsSortBy', 'id'));
     $expiration = Cookie::getValue('remember' . TOKEN_COOKIE_NAME) ? REMEMBER_LOGIN_LIFETIME : null;
     Cookie::setValue('ticketsSortBy', $params['sort_by'], $expiration);
     $conditions = DB::prepareString('`project_id` = ?', array(active_project()->getId()));
     if ($params['status'] = array_var($_GET, 'status')) {
         $conditions .= DB::prepareString(' AND `state` IN (?)', array(explode(',', $params['status'])));
     }
     // if
     if ($params['priority'] = array_var($_GET, 'priority')) {
         $conditions .= DB::prepareString(' AND `priority` IN (?)', array(explode(',', $params['priority'])));
     }
     // if
     if ($params['type'] = array_var($_GET, 'type')) {
         $conditions .= DB::prepareString(' AND `type` IN (?)', array(explode(',', $params['type'])));
     }
     // if
     if ($params['category_id'] = array_var($_GET, 'category_id')) {
         $conditions .= DB::prepareString(' AND `category_id` IN (?)', array(explode(',', $params['category_id'])));
     }
     // if
     if ($params['assigned_to_user_id'] = array_var($_GET, 'assigned_to_user_id')) {
         $conditions .= DB::prepareString(' AND `assigned_to_user_id` IN (?)', array(explode(',', $params['assigned_to_user_id'])));
     }
     // if
     if ($params['created_by_id'] = array_var($_GET, 'created_by_id')) {
         $conditions .= DB::prepareString(' AND `created_by_id` IN (?)', array(explode(',', $params['created_by_id'])));
     }
     // if
     $params['order'] = array_var($_GET, 'order') != 'DESC' ? 'ASC' : 'DESC';
     $filtered = $params['status'] != "" || $params['priority'] != "" || $params['type'] != "" || $params['category_id'] != "" || $params['assigned_to_user_id'] != "" || $params['created_by_id'] != "";
     // Clean up empty and malformed parameters
     foreach ($params as $key => $value) {
         $value = preg_replace("/,+/", ",", $value);
         // removes multiple commas
         $value = preg_replace("/^,?(.*),?\$/", "\$1", $value);
         // removes commas at both ends
         $params[$key] = $value;
         if ($value == "") {
             unset($params[$key]);
             // deletes empty keys
         }
         // if
     }
     // foreach
     $order = '`' . $params['sort_by'] . '` ' . $params['order'] . '';
     if (!logged_user()->isMemberOfOwnerCompany()) {
         $conditions .= DB::prepareString(' AND `is_private` = ?', array(0));
     }
     // if
     list($tickets, $pagination) = ProjectTickets::paginate(array('conditions' => $conditions, 'order' => $order), config_option('tickets_per_page', 25), $page);
     // paginate
     tpl_assign('filtered', $filtered);
     tpl_assign('params', $params);
     tpl_assign('grouped_users', active_project()->getUsers(true));
     tpl_assign('categories', ProjectCategories::getProjectCategories(active_project()));
     tpl_assign('tickets', $tickets);
     tpl_assign('tickets_pagination', $pagination);
     $this->setSidebar(get_template_path('index_sidebar', 'tickets'));
 }
 /**
  * Show calendar view milestone page
  *
  * @access public
  * @param void
  * @return null
  */
 function calendar()
 {
     $this->addHelper('textile');
     $project = active_project();
     $id = get_id();
     if (strlen($id) == 0) {
         $id = gmdate('Ym');
     }
     if (preg_match('/^(\\d{4})(\\d{2})$/', $id, $matches)) {
         list(, $year, $month) = $matches;
         tpl_assign('year', $year);
         tpl_assign('month', $month);
     } else {
         flash_error(lang('id missing'));
         $this->redirectToReferer(get_url('milestone', 'index'));
     }
     $view_type = array_var($_GET, 'view', Cookie::getValue('milestonesViewType', 'list'));
     $expiration = Cookie::getValue('remember' . TOKEN_COOKIE_NAME) ? REMEMBER_LOGIN_LIFETIME : null;
     Cookie::setValue('milestonesViewType', $view_type, $expiration);
     tpl_assign('view_type', $view_type);
     tpl_assign('milestones', $project->getMilestonesByMonth($year, $month));
     tpl_assign('task_lists', $project->getTaskListsByMonth($year, $month));
 }
Ejemplo n.º 12
0
 /**
  * Set logged_user value
  *
  * @access public
  * @param User $value
  * @param boolean $remember Remember this user for 2 weeks (configurable)
  * @param DateTimeValue $set_last_activity_time Set last activity time. This property is turned off in case of feed
  *   login for instance
  * @return null
  * @throws DBQueryError
  */
 function setLoggedUser(User $user, $remember = false, $set_last_activity_time = true, $set_cookies = true)
 {
     if ($set_last_activity_time) {
         $last_activity_mod_timestamp = array_var($_SESSION, 'last_activity_mod_timestamp', null);
         if (!$last_activity_mod_timestamp || $last_activity_mod_timestamp < time() - 60 * 10) {
             $user->setLastActivity(DateTimeValueLib::now());
             // Disable updating user info
             $old_updated_on = $user->getUpdatedOn();
             $user->setUpdatedOn(DateTimeValueLib::now());
             $user->setUpdatedOn($old_updated_on);
             $user->save();
             $_SESSION['last_activity_mod_timestamp'] = time();
         }
     }
     // if
     if ($set_cookies) {
         $expiration = $remember ? REMEMBER_LOGIN_LIFETIME : SESSION_LIFETIME;
         Cookie::setValue('id', $user->getId(), $expiration);
         Cookie::setValue('token', $user->getTwistedToken(), $expiration);
         Cookie::setValue('cn', md5(array_var($_SERVER, 'REMOTE_ADDR', "")));
         if ($remember) {
             Cookie::setValue('remember', 1, $expiration);
         } else {
             Cookie::unsetValue('remember');
         }
         // if
     }
     $this->logged_user = $user;
 }