wasimshaikh / php-calendar

Automatically exported from code.google.com/p/php-calendar
1 stars 0 forks source link

Make the default calendar dynamic #29

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
Am having an issue when trying to set the default calendar dynamically.
I amended the structure of the table "user" by adding a field default_CID and 
also added an interface to set it bby user; to know which calendar is the 
default for a specific user.

During the connexion process, i added a new session var "default_CID" that i 
want to retrieve and use to set the default phpc_cid.
Field also added in the function get_user_by_name within PhpcDatabase.class  

When trying to retrieve the session later on index.php for example, it doesn't 
come.

I also tried to set it as an hidden field during connexion process, just to see 
the value and eventually get it later on. Not working

Can somebody let me know where am wrong? I'll really appreciate it.

Thanks,

What version of the product are you using? On what operating system?

Please provide any additional information below.

Original issue reported on code.google.com by opasca...@gmail.com on 8 Jul 2010 at 7:31

GoogleCodeExporter commented 9 years ago
phpcid is propagated outside of the session (for better or worse). Check 
setup.php around line 79. You should leave the first condition, so the user can 
switch to view another calendar (unless you don't want them to be able to view 
other calendars). set $phpcid to your default_CID. 

Something like:

$user = get_user($_SESSION['phpc_uid']);
if(!empty($vars['phpcid']) && is_numeric($vars['phpcid'])) {
        $phpcid = $vars['phpcid'];
} elseif(!empty($user->get_default_cid())) {
        $phpcid = $user->get_default_cid();
} elseif(!empty($default_calendar_id)) {
        $phpcid = $default_calendar_id;
} else {
        $phpcid = 1;
}

You would need to implement PhpcUser::get_default_cid() and make sure it gets 
passed in through get_user(), etc. None of this is tested. I may decide to 
implement it for the next beta, but I have a lot of stuff that is higher 
priority to me.

Original comment by sproctor@gmail.com on 8 Jul 2010 at 6:16

GoogleCodeExporter commented 9 years ago

Hello Sean,

Thanks for your quick feedback.
I tested a similar solution before the post. 

1. Define a new function get_user_dcid($uid) within "phpcdatabase.class.php" 
like this:

function get_user_dcid($uid)
    {
    //retrieve the new field dcid
        $query = "SELECT  `dcid`\n"
            ."FROM ".SQL_PREFIX."users\n"
            ."WHERE `uid`='$uid'";

        $sth = $this->dbh->query($query)
            or $this->db_error(_("Error getting user default cid."), $query);

        $result = $sth->fetch_assoc();
        if($result)
            //return new PhpcUser($result);
            return $this->dbh->dcid;

        else
            return false;
    }

2. Initialize a var with the result of this action. var to be used for the 
empty check. (because using an object like empty($user->get_default_cid()) will 
return a fatal error...) 

if (isset($_SESSION['phpc_uid']))
$tmpval = get_user_dcid($_SESSION['phpc_uid']);

3. and later on : $phpcid = $tmpval;

I experienced a problem with this call get_user_dcid($_SESSION['phpc_uid']). A 
situation with the session: Undefined variable: _SESSION. 
Connected as an admin and this error till appears.

Do you have any idea?

Thanks for your feedback.
Pascal

Original comment by opasca...@gmail.com on 9 Jul 2010 at 9:16

GoogleCodeExporter commented 9 years ago
Hi Sean,

Just took few moment yesterday to see again my problem and I think it's fixed. 
What I did:

1. I've amended the function PhpcUser($result) in PhpcUser.class.php
 by adding the new field added in the users table "dcid" 

2. amend the function get_user_by_name($username) and get_user($uid) in 
phpcdatabase.class.php by adding a new field dcid within the query to have the 
following:
    $query = "SELECT `uid`, `dcid`, `username`, `password`, `admin` \n"

        ."FROM ".SQL_PREFIX."users\n"

        ."WHERE username='$username'";

3. In calendar.php, I've amended the function login_user($username, $password) 
by setting a new cookie :
    setcookie("phpc_dcid", "$user->dcid");  

    session_write_close();
    Why in calendar.php? because session and cookie are initialized there after the connection

4. To follow the user who is connecting, I've changed the initialisation of the 
cookie phpc_user, also available in calendar.php:
    setcookie("phpc_user", "1"); BY this : setcookie("phpc_user", "$user->uid");

5. In Setup.php rond line 79 replace existing code by this:

//Thanks Sean for this contribution
    if (isset($_COOKIE['phpc_user']))
        $udcid = $phpcdb->get_user($_COOKIE['phpc_user']);
    if(!empty($vars['phpcid']) && is_numeric($vars['phpcid'])) {
        $phpcid = $vars['phpcid'];
    } elseif(!empty($udcid->dcid)) {
    $phpcid = $udcid->dcid;
    } elseif(!empty($default_calendar_id)) {
       $phpcid = $default_calendar_id;
    } else {
     $phpcid = 1;
    }

6. As results : after connexion the calendar set for each user as default is 
displayed.

6'. of course, an user interface is also created for the admin just set the 
default calendar per user.

If it can help for futures....or if a better way exists feel free let me know.

Thank you Sean for your good Calendar!!

Pascal

Original comment by opasca...@gmail.com on 14 Jul 2010 at 2:49

GoogleCodeExporter commented 9 years ago

Original comment by sproctor@gmail.com on 24 Jul 2012 at 2:18

GoogleCodeExporter commented 9 years ago

Original comment by sproctor@gmail.com on 24 Jul 2012 at 2:31

GoogleCodeExporter commented 9 years ago
I've moved this to github. https://github.com/sproctor/php-calendar/issues/37 
I'm closing all of the issues on google code and moving away from it.

Original comment by sproctor@gmail.com on 5 Apr 2013 at 12:50