コード例 #1
0
ファイル: event.php プロジェクト: rair/yacs
 /**
  * remember an action once it's done
  *
  * To be overloaded into derived class
  *
  * @param string the action 'insert', 'update' or 'delete'
  * @param array the hosting record
  * @param string reference of the hosting record (e.g., 'article:123')
  * @return FALSE on error, TRUE otherwise
  */
 function remember($action, $host, $reference)
 {
     global $context;
     // remember the id of the master record
     $id = $host['id'];
     // set default values for this editor
     Surfer::check_default_editor($this->attributes);
     // we use the existing back-end for dates
     include_once $context['path_to_root'] . 'dates/dates.php';
     // build the update query
     switch ($action) {
         case 'delete':
             // no need to notify participants after the date planned for the event, nor if the event has been initiated
             if (isset($this->attributes['date_stamp']) && $this->attributes['date_stamp'] > gmstrftime('%Y-%m-%d %H:%M') && isset($this->attributes['status']) && $this->attributes['status'] != 'started' && $this->attributes['status'] != 'stopped') {
                 // send a cancellation message to participants
                 $query = "SELECT user_email FROM " . SQL::table_name('enrolments') . " WHERE (anchor LIKE '" . $reference . "') AND (approved LIKE 'Y')";
                 $result = SQL::query($query);
                 while ($item = SQL::fetch($result)) {
                     // sanity check
                     if (!preg_match(VALID_RECIPIENT, $item['user_email'])) {
                         continue;
                     }
                     // message title
                     $subject = sprintf('%s: %s', i18n::c('Cancellation'), strip_tags($this->anchor->get_title()));
                     // headline
                     $headline = sprintf(i18n::c('%s has cancelled %s'), Surfer::get_link(), $this->anchor->get_title());
                     // message to reader
                     $message = $this->get_invite_default_message('CANCEL');
                     // assemble main content of this message
                     $message = Skin::build_mail_content($headline, $message);
                     // threads messages
                     $headers = Mailer::set_thread($this->anchor->get_reference());
                     // get attachment from the overlay
                     $attachments = $this->get_invite_attachments('CANCEL');
                     // post it
                     Mailer::notify(Surfer::from(), $item['user_email'], $subject, $message, $headers, $attachments);
                 }
             }
             // delete dates for this anchor
             Dates::delete_for_anchor($reference);
             // also delete related enrolment records
             $query = "DELETE FROM " . SQL::table_name('enrolments') . " WHERE anchor LIKE '" . $reference . "'";
             SQL::query($query);
             break;
         case 'insert':
             // bind one date to this record
             if (isset($this->attributes['date_stamp']) && $this->attributes['date_stamp']) {
                 $fields = array();
                 $fields['anchor'] = $reference;
                 $fields['date_stamp'] = $this->attributes['date_stamp'];
                 // update the database
                 if (!($fields['id'] = Dates::post($fields))) {
                     Logger::error(i18n::s('Impossible to add an item.'));
                     return FALSE;
                 }
             }
             // enroll page creator
             include_once $context['path_to_root'] . 'shared/enrolments.php';
             enrolments::confirm($reference);
             // reload the anchor through the cache to reflect the update
             if ($reference) {
                 $this->anchor = Anchors::get($reference, TRUE);
             }
             // send a confirmation message to event creator
             $query = "SELECT * FROM " . SQL::table_name('enrolments') . " WHERE (anchor LIKE '" . $reference . "')";
             $result = SQL::query($query);
             while ($item = SQL::fetch($result)) {
                 // a user registered on this server
                 if ($item['user_id'] && ($watcher = Users::get($item['user_id']))) {
                     // sanity check
                     if (!preg_match(VALID_RECIPIENT, $item['user_email'])) {
                         continue;
                     }
                     // use this email address
                     if ($watcher['full_name']) {
                         $recipient = Mailer::encode_recipient($watcher['email'], $watcher['full_name']);
                     } else {
                         $recipient = Mailer::encode_recipient($watcher['email'], $watcher['nick_name']);
                     }
                     // message title
                     $subject = sprintf(i18n::c('Meeting: %s'), strip_tags($this->anchor->get_title()));
                     // headline
                     $headline = sprintf(i18n::c('you have arranged %s'), '<a href="' . $context['url_to_home'] . $context['url_to_root'] . $this->anchor->get_url() . '">' . $this->anchor->get_title() . '</a>');
                     // message to reader
                     $message = $this->get_invite_default_message('PUBLISH');
                     // assemble main content of this message
                     $message = Skin::build_mail_content($headline, $message);
                     // a set of links
                     $menu = array();
                     // call for action
                     $link = $context['url_to_home'] . $context['url_to_root'] . $this->anchor->get_url();
                     $menu[] = Skin::build_mail_button($link, i18n::c('View event details'), TRUE);
                     // finalize links
                     $message .= Skin::build_mail_menu($menu);
                     // threads messages
                     $headers = Mailer::set_thread($this->anchor->get_reference());
                     // get attachment from the overlay
                     $attachments = $this->get_invite_attachments('PUBLISH');
                     // post it
                     Mailer::notify(Surfer::from(), $recipient, $subject, $message, $headers, $attachments);
                 }
             }
             break;
         case 'update':
             // reload the anchor through the cache to reflect the update
             if ($reference) {
                 $this->anchor = Anchors::get($reference, TRUE);
             }
             // no need to notify watchers after the date planned for the event, nor if the event has been initiated
             if (isset($this->attributes['date_stamp']) && $this->attributes['date_stamp'] > gmstrftime('%Y-%m-%d %H:%M') && isset($this->attributes['status']) && $this->attributes['status'] != 'started' && $this->attributes['status'] != 'stopped' && isset($_REQUEST['notify_watchers']) && $_REQUEST['notify_watchers'] == 'Y') {
                 // send a confirmation message to participants
                 $query = "SELECT * FROM " . SQL::table_name('enrolments') . " WHERE (anchor LIKE '" . $reference . "')";
                 $result = SQL::query($query);
                 while ($item = SQL::fetch($result)) {
                     // skip current surfer
                     if (Surfer::get_id() && Surfer::get_id() == $item['user_id']) {
                         continue;
                     }
                     // a user registered on this server
                     if ($item['user_id'] && ($watcher = Users::get($item['user_id']))) {
                         // skip banned users
                         if ($watcher['capability'] == '?') {
                             continue;
                         }
                         // ensure this surfer wants to be alerted
                         if ($watcher['without_alerts'] == 'Y') {
                             continue;
                         }
                         // sanity check
                         if (!preg_match(VALID_RECIPIENT, $item['user_email'])) {
                             continue;
                         }
                         // use this email address
                         if ($watcher['full_name']) {
                             $recipient = Mailer::encode_recipient($watcher['email'], $watcher['full_name']);
                         } else {
                             $recipient = Mailer::encode_recipient($watcher['email'], $watcher['nick_name']);
                         }
                         // message title
                         $subject = sprintf(i18n::c('Updated: %s'), strip_tags($this->anchor->get_title()));
                         // headline
                         $headline = sprintf(i18n::c('%s has updated %s'), Surfer::get_link(), '<a href="' . $context['url_to_home'] . $context['url_to_root'] . $this->anchor->get_url() . '">' . $this->anchor->get_title() . '</a>');
                         // message to reader
                         $message = $this->get_invite_default_message('PUBLISH');
                         // assemble main content of this message
                         $message = Skin::build_mail_content($headline, $message);
                         // a set of links
                         $menu = array();
                         // call for action
                         $link = $context['url_to_home'] . $context['url_to_root'] . $this->anchor->get_url();
                         $menu[] = Skin::build_mail_button($link, i18n::c('View event details'), TRUE);
                         // finalize links
                         $message .= Skin::build_mail_menu($menu);
                         // threads messages
                         $headers = Mailer::set_thread($this->anchor->get_reference());
                         // get attachment from the overlay
                         $attachments = $this->get_invite_attachments('PUBLISH');
                         // post it
                         Mailer::notify(Surfer::from(), $recipient, $subject, $message, $headers, $attachments);
                     }
                 }
             }
             // bind one date to this record
             if (isset($this->attributes['date_stamp']) && $this->attributes['date_stamp']) {
                 $fields = array();
                 $fields['anchor'] = $reference;
                 $fields['date_stamp'] = $this->attributes['date_stamp'];
                 // there is an existing record
                 if ($date =& Dates::get_for_anchor($reference)) {
                     // update the record
                     $fields['id'] = $date['id'];
                     if (!($id = Dates::post($fields))) {
                         Logger::error(sprintf(i18n::s('Impossible to update date %s'), $this->attributes['date_stamp']));
                         return FALSE;
                     }
                     // create a record instead of raising an error, we are smart y'a'know
                 } else {
                     if (!($fields['id'] = Dates::post($fields))) {
                         Logger::error(i18n::s('Impossible to add an item.'));
                         return FALSE;
                     }
                 }
             }
             break;
     }
     // job done
     return TRUE;
 }
コード例 #2
0
ファイル: edit.php プロジェクト: rair/yacs
    Safe::header('Status: 404 Not Found', TRUE, 404);
    Logger::error(i18n::s('No anchor has been found.'));
    // maybe posts are not allowed here
} elseif (!isset($item['id']) && is_object($anchor) && $anchor->has_option('locked') && !Surfer::is_empowered()) {
    Safe::header('Status: 401 Unauthorized', TRUE, 401);
    Logger::error(i18n::s('This page has been locked.'));
    // an error occured
} elseif (count($context['error'])) {
    $item = $_REQUEST;
    $with_form = TRUE;
    // process uploaded data
} elseif (isset($_SERVER['REQUEST_METHOD']) && $_SERVER['REQUEST_METHOD'] == 'POST') {
    // the follow-up page
    $next = $context['url_to_home'] . $context['url_to_root'] . $anchor->get_url();
    // display the form on error
    if (!($_REQUEST['id'] = Dates::post($_REQUEST))) {
        $item = $_REQUEST;
        $with_form = TRUE;
        // reward the poster for new posts
    } elseif (!isset($item['id'])) {
        // increment the post counter of the surfer
        Users::increment_posts(Surfer::get_id());
        // thanks
        $context['page_title'] = i18n::s('Thank you for your contribution');
        // the date
        $context['text'] .= '<p>' . sprintf(i18n::s('%s: %s'), i18n::s('Target date'), Skin::build_date($item['date_stamp'], 'full')) . '</p>';
        // the action
        $context['text'] .= '<p>' . i18n::s('The date has been saved.') . '</p>';
        // touch the related anchor
        $anchor->touch('date:create', $_REQUEST['id'], isset($_REQUEST['silent']) && $_REQUEST['silent'] == 'Y');
        // clear cache