We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 18397
    • 3,250 Posts
    UPDATE:
    Wow! I did it. It isn’t perfect by any means but it works. You create a folder for the calendar and and then put that id as the resource parent. Then any children documents in this folder with the alias in the yyyymmdd format will be shown with the longtitle displaying underneath the date.

    # START ---- Variables You Should Change ----- #
    #
    $resourceparent = 65; # ID of Folder for processing ()
    $day_heading_length = 1;  # Size of weekday abbr in calendar (0-4) 4=full day name
    #
    # END ---- Variables You Should Change ----- #
    
    # START ---- CSS elements which can optionally be customized ----- #
    #            Element names are pretty much self-explanatory
    #
    $calendar_css = "	background-color: #ffffdd; width:100%;";
    $month_css = "background-image: url(/resources/images/txtheader.png); background-repeat: repeat-x; text-align:center; font-weight:bold";
    $day_heading_css = "background-image: url(/resources/images/txtheader.png); background-repeat: repeat-x; text-align:center; width:14%";
    $day_css = "text-align:center; border:1px solid #F0F8FF; height=55px;";
    $today_css = "color: red; background-color:#EAEAEA; text-align:center; font-weight:bold; border:1px solid red;";
    $blogday_css = "color:#003799; background-color:#EAEAEA; text-align:center; font-weight:bold; border:1px solid #003799;";
    $empty_day_css = "";
    #
    # END ---- CSS elements which can optionally be customized ----- #
    
    # ----- You should not need to modify code below this point ----- #
    #
    # Calculate required time & date related variables
    #
    $time = time();  # Grab the current timestamp
    $blogdate=$_GET['blogdate'];  # Assign $blogdate variable if sent
    if($blogdate != "") $Ym=$blogdate;  # If $blogdate sent, use it for $Ym
    else $Ym=$_GET['Ym'];  # Else extract $Ym variable if sent
    
    if($Ym != "") {  # If $Ym exists, get $year and $month
      $year=substr($Ym, 0, 4);  # Get year part
      $month=substr($Ym, 4, 2);  # Get month part
    }
    else {  # If $Ym is empty, assign variables from current date
      $year=date('Y', $time);
      $month=date('m', $time);
      $today=date('j', $time);
    }
    
    if(($month == date('m', $time)) && ($year == date('Y', $time))) {
      $today=date('j', $time);  # If this month and this year, assign $today
    }
    
    $first_of_month = mktime(0,0,0,$month,1,$year);  # Always start with current month
    $lastmonth = strftime("%Y%m%d",mktime(0,0,0,$month-1,1,$year));  # Previous month
    $nextmonth = strftime("%Y%m%d",mktime(0,0,0,$month+1,1,$year));  # Next month
    
    # Query for dates of documents which were published this month
    $tbl = $etomite->dbConfig['dbase'].".".$etomite->dbConfig['table_prefix'];
    $site_content = $tbl."site_content";  # DB.Prefix_Table Variable
    $resource = $etomite->getAllChildren($resourceparent, 'alias', 'ASC', $fields='id, longtitle, alias, createdby');
    $limit=count($resource);
    $datelist = array();
    for ($y = 0; $y < $limit; $y++) {
    $value = $resource[$y]['alias'];
    $othervalue = $resource[$y]['longtitle'];
    $datelist[]= $value;
    $aliaslist[$value]= $othervalue;
    $idlist[$value]= $resource[$y]['id'];
    
    }
    # Generate all the day headings according to the current locale
    $day_headings = array();
    for($n=0,$t=3*86400; $n<7; $n++,$t+=86400)   # January 4, 1970 was a Sunday
      $day_headings[$n] = gmstrftime('%A',$t);  # %A means full textual day name
    
    $day_headings = array_map('ucfirst',$day_headings);  # Some locales don't capitalize day names
    list($month, $year, $month_name, $weekday) = explode(',',strftime('%m,%Y,%B,%w',$first_of_month));
    # $weekday %= 7;  # strftime gives Monday as 1, Sunday as 7. Adjust so Sunday is 0
    $month_name = ucfirst($month_name);  # Some locales don't capitalize month names
    $maxdays = date('t', $first_of_month);  # Number of days in the month
    $day = 1;  # starting day of the month
    
    $BC_Calendar = "<table style='$calendar_css'>\n";  # Begin actual calendar generation
    $BC_Calendar .= "<tr><th colspan='1' style='$month_css'>\n";  # Create previous month link
    $BC_Calendar .= "<a href='[~".$etomite->documentObject[id]."~]&Ym=$lastmonth'>&laq"."uo;</a>\n"; # Use << for link
    $BC_Calendar .= "</th>\n";
    $BC_Calendar .= "<th colspan='5' style='$month_css'>\n";  # Display calendar month and year
    $BC_Calendar .= "$month_name, $year";
    $BC_Calendar .= "</th>\n";
    $BC_Calendar .= "<th colspan='1' style='$month_css'>\n";  # Create next month link
    $BC_Calendar .= "<a href='[~".$etomite->documentObject[id]."~]&Ym=$nextmonth'>&raq"."uo;</a>\n"; # Use >> for link
    $BC_Calendar .= "</th></tr>\n";
    
    $BC_Calendar .= "<tr>\n";  # Display weekday heading abbreviations
    if($day_heading_length > 0 and $day_heading_length <= 4){  # if day_heading_length is allowed value
      #  if day_heading_length is 4, the full name of the day will be printed
      #  otherwise, just the first n characters
      foreach($day_headings as $day_heading){
        $d = ($day_heading_length != 4) ? substr($day_heading,0,$day_heading_length) : $day_heading;
        $BC_Calendar .= "<th style='$day_heading_css' abbr='$day_heading'>$d</th>\n";
      }
      $BC_Calendar .= "</tr>\n<tr>\n";  # Close weekday heading and prepare to print days
    }
    
    # Take care of the first "empty" days of the month
    if($weekday > 0) $BC_Calendar .= "<td style='$empty_day_css' colspan='$weekday'> </td>\n";
    
    # Print all days of the month
    while($day <= $maxdays){
      if($weekday == 7){  # Start a new week - end table row and start a new one
        $BC_Calendar .= "</tr>\n<tr>\n";
        $weekday = 0;
      }
      # Create the $Ymd variable to compare against the list of days with content
      $Ymd = $year.$month.str_pad($day,2,"0", STR_PAD_LEFT);
    
      $this_day = "";
      $this_css = $day_css;
    
      # If a day has content documents associated with it, create a link to the appropriate blog
      if(in_array($Ymd,$datelist)){
       $this_css .= " ".$blogday_css;
     
      }
    
      # If the day is today, give it special CSS formatting
      if ($day==$today){
        $this_day .= $day;
     $this_day .=""; $this_day .="";
        $this_css .= " ".$today_css;
      }
    
      else {$this_day .= "$day";  $this_day .=""; $this_day .="";}  # Otherwise just display the day
      $BC_Calendar .="<td style='".$this_css."'>".$this_day;  # Use CSS formatting of days
        # Close up the hyperlink to the blog
      if(in_array($Ymd,$datelist)) $BC_Calendar .= "<br/><a href='[~".$idlist[$Ymd]."~]'>\n".$aliaslist[$Ymd]."</a>";
    
      # Close up the CSS formatting of days
      $BC_Calendar .=" </td>\n";
      $day++; $weekday++;  # Goto the next day and weekday
    }
    
    # Take care of the remaining "empty" days of the month
    if($weekday != 7) $BC_Calendar .= "<td style='$empty_day_css' colspan='".(7-$weekday)."'> </td>\n";
    # Close the calendar and finish
    $BC_Calendar .="</tr>\n</table>\n";
    
    return $BC_Calendar;
    #
    # END of Code #
    
    


    ORIGIONAL POST:

    Anyone know how to modify this snippet to use a tv for the date (so if the article is posted a week early the event displays on the correct date and not the date the post was made) and the document title or summary (introtext) under the date (for a brief title)? For an example of the type of calendar look (not admin) I am trying to imitate see http://www.maroctour.com/cal/calendar.php.

    CODE REMOVED (no longer necessary)
      • 32963
      • 1,732 Posts
      Hmmmm,

      You might want to have a look at these http://www.modxcms.com/api-quick-reference.html. See the following APIs

      getTemplateVar
      getTemplateVarOutput
      getTemplateVars

        xWisdom
        www.xwisdomhtml.com
        The fear of the Lord is the beginning of wisdom:
        MODx Co-Founder - Create and do more with less.
        • 4095
        • 372 Posts
        Quote from: Mark at Aug 01, 2005, 02:10 AM

        For an example of the type of calendar look (not admin) I am trying to imitate see http://www.maroctour.com/cal/calendar.php.

        Hey Mark, can’t help with this as I’m a newbie myslef, however I wuld be really keen to see it / beta it if you mange to get it working. I was looking for a Calander that had catagories and colours assigned to them.

        The only feature that needs improvement that I could see from a quick tour of it was the search. Be nice to search just inside one or more catagories, not all of them.

        Good luck and look forward to seeing it in MODx.

        Briggsy
          [img]http://www.emanz.ac.nz/assets/images/logo/emanz-icon_16x16.gif[/img] Emergency Management Academy of New Zealand [br] http://www.emanz.ac.nz[br][br]MODx Sandbox Login: sandbox Password: castle [br]
          Admin Sandbox Login: sandbox Password: castle
          • 4673
          • 577 Posts
          Anybody see a calendar that allows mulitple user postings? Or even better yet, a wiki type of thing were the user can log there own events based on a work day type of idea?
            Tangent-Warrior smiley
            • 18397
            • 3,250 Posts
            Wow! I did it. It isn’t perfect by any means but it works. You create a folder for the calendar and and then put that id as the resource parent. Then any children documents in this folder with the alias in the yyyymmdd format will be shown with the longtitle displaying underneath the date.

            # START ---- Variables You Should Change ----- #
            #
            $resourceparent = 65; # ID of Folder for processing ()
            $day_heading_length = 1;  # Size of weekday abbr in calendar (0-4) 4=full day name
            #
            # END ---- Variables You Should Change ----- #
            
            # START ---- CSS elements which can optionally be customized ----- #
            #            Element names are pretty much self-explanatory
            #
            $calendar_css = "	background-color: #ffffdd; width:100%;";
            $month_css = "background-image: url(/resources/images/txtheader.png); background-repeat: repeat-x; text-align:center; font-weight:bold";
            $day_heading_css = "background-image: url(/resources/images/txtheader.png); background-repeat: repeat-x; text-align:center; width:14%";
            $day_css = "text-align:center; border:1px solid #F0F8FF; height=55px;";
            $today_css = "color: red; background-color:#EAEAEA; text-align:center; font-weight:bold; border:1px solid red;";
            $blogday_css = "color:#003799; background-color:#EAEAEA; text-align:center; font-weight:bold; border:1px solid #003799;";
            $empty_day_css = "";
            #
            # END ---- CSS elements which can optionally be customized ----- #
            
            # ----- You should not need to modify code below this point ----- #
            #
            # Calculate required time & date related variables
            #
            $time = time();  # Grab the current timestamp
            $blogdate=$_GET['blogdate'];  # Assign $blogdate variable if sent
            if($blogdate != "") $Ym=$blogdate;  # If $blogdate sent, use it for $Ym
            else $Ym=$_GET['Ym'];  # Else extract $Ym variable if sent
            
            if($Ym != "") {  # If $Ym exists, get $year and $month
              $year=substr($Ym, 0, 4);  # Get year part
              $month=substr($Ym, 4, 2);  # Get month part
            }
            else {  # If $Ym is empty, assign variables from current date
              $year=date('Y', $time);
              $month=date('m', $time);
              $today=date('j', $time);
            }
            
            if(($month == date('m', $time)) && ($year == date('Y', $time))) {
              $today=date('j', $time);  # If this month and this year, assign $today
            }
            
            $first_of_month = mktime(0,0,0,$month,1,$year);  # Always start with current month
            $lastmonth = strftime("%Y%m%d",mktime(0,0,0,$month-1,1,$year));  # Previous month
            $nextmonth = strftime("%Y%m%d",mktime(0,0,0,$month+1,1,$year));  # Next month
            
            # Query for dates of documents which were published this month
            $tbl = $etomite->dbConfig['dbase'].".".$etomite->dbConfig['table_prefix'];
            $site_content = $tbl."site_content";  # DB.Prefix_Table Variable
            $resource = $etomite->getAllChildren($resourceparent, 'alias', 'ASC', $fields='id, longtitle, alias, createdby');
            $limit=count($resource);
            $datelist = array();
            for ($y = 0; $y < $limit; $y++) {
            $value = $resource[$y]['alias'];
            $othervalue = $resource[$y]['longtitle'];
            $datelist[]= $value;
            $aliaslist[$value]= $othervalue;
            $idlist[$value]= $resource[$y]['id'];
            
            }
            # Generate all the day headings according to the current locale
            $day_headings = array();
            for($n=0,$t=3*86400; $n<7; $n++,$t+=86400)   # January 4, 1970 was a Sunday
              $day_headings[$n] = gmstrftime('%A',$t);  # %A means full textual day name
            
            $day_headings = array_map('ucfirst',$day_headings);  # Some locales don't capitalize day names
            list($month, $year, $month_name, $weekday) = explode(',',strftime('%m,%Y,%B,%w',$first_of_month));
            # $weekday %= 7;  # strftime gives Monday as 1, Sunday as 7. Adjust so Sunday is 0
            $month_name = ucfirst($month_name);  # Some locales don't capitalize month names
            $maxdays = date('t', $first_of_month);  # Number of days in the month
            $day = 1;  # starting day of the month
            
            $BC_Calendar = "<table style='$calendar_css'>\n";  # Begin actual calendar generation
            $BC_Calendar .= "<tr><th colspan='1' style='$month_css'>\n";  # Create previous month link
            $BC_Calendar .= "<a href='[~".$etomite->documentObject[id]."~]&Ym=$lastmonth'>&laq"."uo;</a>\n"; # Use << for link
            $BC_Calendar .= "</th>\n";
            $BC_Calendar .= "<th colspan='5' style='$month_css'>\n";  # Display calendar month and year
            $BC_Calendar .= "$month_name, $year";
            $BC_Calendar .= "</th>\n";
            $BC_Calendar .= "<th colspan='1' style='$month_css'>\n";  # Create next month link
            $BC_Calendar .= "<a href='[~".$etomite->documentObject[id]."~]&Ym=$nextmonth'>&raq"."uo;</a>\n"; # Use >> for link
            $BC_Calendar .= "</th></tr>\n";
            
            $BC_Calendar .= "<tr>\n";  # Display weekday heading abbreviations
            if($day_heading_length > 0 and $day_heading_length <= 4){  # if day_heading_length is allowed value
              #  if day_heading_length is 4, the full name of the day will be printed
              #  otherwise, just the first n characters
              foreach($day_headings as $day_heading){
                $d = ($day_heading_length != 4) ? substr($day_heading,0,$day_heading_length) : $day_heading;
                $BC_Calendar .= "<th style='$day_heading_css' abbr='$day_heading'>$d</th>\n";
              }
              $BC_Calendar .= "</tr>\n<tr>\n";  # Close weekday heading and prepare to print days
            }
            
            # Take care of the first "empty" days of the month
            if($weekday > 0) $BC_Calendar .= "<td style='$empty_day_css' colspan='$weekday'> </td>\n";
            
            # Print all days of the month
            while($day <= $maxdays){
              if($weekday == 7){  # Start a new week - end table row and start a new one
                $BC_Calendar .= "</tr>\n<tr>\n";
                $weekday = 0;
              }
              # Create the $Ymd variable to compare against the list of days with content
              $Ymd = $year.$month.str_pad($day,2,"0", STR_PAD_LEFT);
            
              $this_day = "";
              $this_css = $day_css;
            
              # If a day has content documents associated with it, create a link to the appropriate blog
              if(in_array($Ymd,$datelist)){
               $this_css .= " ".$blogday_css;
             
              }
            
              # If the day is today, give it special CSS formatting
              if ($day==$today){
                $this_day .= $day;
             $this_day .=""; $this_day .="";
                $this_css .= " ".$today_css;
              }
            
              else {$this_day .= "$day";  $this_day .=""; $this_day .="";}  # Otherwise just display the day
              $BC_Calendar .="<td style='".$this_css."'>".$this_day;  # Use CSS formatting of days
                # Close up the hyperlink to the blog
              if(in_array($Ymd,$datelist)) $BC_Calendar .= "<br/><a href='[~".$idlist[$Ymd]."~]'>\n".$aliaslist[$Ymd]."</a>";
            
              # Close up the CSS formatting of days
              $BC_Calendar .=" </td>\n";
              $day++; $weekday++;  # Goto the next day and weekday
            }
            
            # Take care of the remaining "empty" days of the month
            if($weekday != 7) $BC_Calendar .= "<td style='$empty_day_css' colspan='".(7-$weekday)."'> </td>\n";
            # Close the calendar and finish
            $BC_Calendar .="</tr>\n</table>\n";
            
            return $BC_Calendar;
            #
            # END of Code #
            
            
              • 7455
              • 2,204 Posts
              demo url?
                follow me on twitter: @dimmy01
                • 18397
                • 3,250 Posts
                Working on it.
                  • 22097
                  • 37 Posts
                  Looks nice, but a few remarks.

                  Why use the alias for a date? That sounds like a Template Variable to me.
                  Also nice is to have the resourceparent filled in automatically to for instance modx->documentIdentifier when not given as parameter to the snippet. Check the default news snippet for an example.
                    • 18397
                    • 3,250 Posts

                    That sounds like a Template Variable to me.

                    I am still working on that...........
                      • 23260
                      • 30 Posts
                      Any More work done on this?

                      I’m asking because I’m working on a site and an events calender will be a central part of it. I’ll probably need something a little more robust than this, but it looks like a good start.

                      Cheers,

                      Phil