- $o = '<table class="calendar">';
- $o .= "<caption>$str_month $y</caption><tr>";
- for($a = 0; $a < 7; $a ++)
- $o .= '<th>' . mb_substr(day_translate($dn[$a]),0,3,'UTF-8') . '</th>';
- $o .= '</tr><tr>';
-
- while($d <= $l) {
- if(($dow == $f) && (! $started))
- $started = true;
- $today = (((isset($tddate)) && ($tddate == $d)) ? "class=\"today\" " : '');
- $o .= "<td $today>";
- $day = str_replace(' ',' ',sprintf('%2.2d', $d));
- if($started) {
- if(is_array($links) && isset($links[$d]))
- $o .= "<a href=\"{$links[$d]}\">$day</a>";
- else
- $o .= $day;
- $d ++;
- }
- else
- $o .= ' ';
- $o .= '</td>';
- $dow ++;
- if(($dow == 7) && ($d <= $l)) {
- $dow = 0;
- $o .= '</tr><tr>';
- }
- }
- if($dow)
- for($a = $dow; $a < 7; $a ++)
- $o .= '<td> </td>';
- $o .= '</tr></table>'."\r\n";
-
- return $o;
-}}
+ $o = '<table class="calendar' . $class . '">';
+ $o .= "<caption>$str_month $y</caption><tr>";
+ for($a = 0; $a < 7; $a ++)
+ $o .= '<th>' . mb_substr(day_translate($dn[$a]),0,3,'UTF-8') . '</th>';
+
+ $o .= '</tr><tr>';
+
+ while($d <= $l) {
+ if(($dow == $f) && (! $started))
+ $started = true;
+
+ $today = (((isset($tddate)) && ($tddate == $d)) ? "class=\"today\" " : '');
+ $o .= "<td $today>";
+ $day = str_replace(' ',' ',sprintf('%2.2d', $d));
+ if($started) {
+ if(is_array($links) && isset($links[$d]))
+ $o .= "<a href=\"{$links[$d]}\">$day</a>";
+ else
+ $o .= $day;
+
+ $d ++;
+ } else {
+ $o .= ' ';
+ }
+
+ $o .= '</td>';
+ $dow ++;
+ if(($dow == 7) && ($d <= $l)) {
+ $dow = 0;
+ $o .= '</tr><tr>';
+ }
+ }
+ if($dow)
+ for($a = $dow; $a < 7; $a ++)
+ $o .= '<td> </td>';
+
+ $o .= '</tr></table>'."\r\n";
+
+ return $o;
+}
+
+/**
+ * @brief Create a birthday event.
+ *
+ * Update the year and the birthday.
+ */
+function update_contact_birthdays() {
+
+ // This only handles foreign or alien networks where a birthday has been provided.
+ // In-network birthdays are handled within local_delivery
+
+ $r = q("SELECT * FROM contact WHERE `bd` != '' AND `bd` != '0000-00-00' AND SUBSTRING(`bd`,1,4) != `bdyear` ");
+ if (dbm::is_result($r)) {
+ foreach ($r as $rr) {
+
+ logger('update_contact_birthday: ' . $rr['bd']);
+
+ $nextbd = datetime_convert('UTC','UTC','now','Y') . substr($rr['bd'],4);
+
+ /**
+ *
+ * Add new birthday event for this person
+ *
+ * $bdtext is just a readable placeholder in case the event is shared
+ * with others. We will replace it during presentation to our $importer
+ * to contain a sparkle link and perhaps a photo.
+ *
+ */
+
+ $bdtext = sprintf( t('%s\'s birthday'), $rr['name']);
+ $bdtext2 = sprintf( t('Happy Birthday %s'), ' [url=' . $rr['url'] . ']' . $rr['name'] . '[/url]') ;
+
+ $r = q("INSERT INTO `event` (`uid`,`cid`,`created`,`edited`,`start`,`finish`,`summary`,`desc`,`type`,`adjust`)
+ VALUES ( %d, %d, '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%d' ) ",
+ intval($rr['uid']),
+ intval($rr['id']),
+ dbesc(datetime_convert()),
+ dbesc(datetime_convert()),
+ dbesc(datetime_convert('UTC','UTC', $nextbd)),
+ dbesc(datetime_convert('UTC','UTC', $nextbd . ' + 1 day ')),
+ dbesc($bdtext),
+ dbesc($bdtext2),
+ dbesc('birthday'),
+ intval(0)
+ );
+
+
+ // update bdyear
+
+ q("UPDATE `contact` SET `bdyear` = '%s', `bd` = '%s' WHERE `uid` = %d AND `id` = %d",
+ dbesc(substr($nextbd,0,4)),
+ dbesc($nextbd),
+ intval($rr['uid']),
+ intval($rr['id'])
+ );
+
+ }
+ }
+}