This topic is locked

Calendar Data Restricted to User

9/9/2009 11:32:27 AM
PHPRunner General questions
S
salus1 authorDevClub member

Does anyone know how to configure the Calendar template so that users can only see their own data? The security seems to work differently from regular PHPRunner templates.

Sergey Kornilov admin 9/9/2009

Calendar template is a bit more complicated than regular projects. Here are some suggestions.

  1. Add a new field (ownerid, int) to calcalendar table.
  2. Make sure ownerid field appears in SQL query for caldaily, calyearly, calweekly and calmonthly views
  3. Turn on Advanced security mode 'Users can see and edit their own data only' for caldaily, calyearly, calweekly and calmonthly views. Use

    id field from calusers table and ownerid field from the view to link tables.
  4. Modify SQL queries in the "Before display" events for calyearly, calweekly and calmonthly views and in the "Before SQL query" event for caldaily view adding a WHERE clause.
    For example see changes in "List page: Before SQL query" event of caldaily view (added code is in bold):


    $strWhereClause1=whereAdd($strWhereClause1,"ownerid=".$_SESSION["OwnerID"]."");

    $strWhereClause2=whereAdd($strWhereClause2,"ownerid=".$_SESSION["OwnerID"]."");

    $strWhereClause3=whereAdd($strWhereClause3,"ownerid=".$_SESSION["OwnerID"]."");

    $strWhereClause4=whereAdd($strWhereClause4,"ownerid=".$_SESSION["OwnerID"]."");

    $strWhereClause5=whereAdd($strWhereClause5,"ownerid=".$_SESSION["OwnerID"]."");



    if ($strWhereClause=="")

    $strWhereClause="1=1";


5. Also you need to edit SQL queries in the "Before display" event of calmonthly, calweekly views.

Here is the sample:



$strSQL = "select DateField from calcalendar where Recurrence=0 and Year(DateField)=".$yr." and Month(DateField)=".$mon." and (ownerid=".$_SESSION["OwnerID"].") group by DateField";